summaryrefslogtreecommitdiff
path: root/bin/mozilla/arapprn.pl
blob: 792b01afe2585bcf21ba76e945b6b478648e7dd3 (plain)
  1. #=====================================================================
  2. # LedgerSMB Small Medium Business Accounting
  3. # http://sourceforge.net/projects/ledger-smb/
  4. #
  5. # Copyright (C) 2006
  6. # This work contains copyrighted information from a number of sources all used
  7. # with permission.
  8. #
  9. # This file contains source code included with or based on SQL-Ledger which
  10. # is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
  11. # under the GNU General Public License version 2 or, at your option, any later
  12. # version. For a full list including contact information of contributors,
  13. # maintainers, and copyright holders, see the CONTRIBUTORS file.
  14. #
  15. # Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
  16. # Copyright (c) 2003
  17. #
  18. # Author: DWS Systems Inc.
  19. # Web: http://www.sql-ledger.org
  20. #
  21. #
  22. # This program is free software; you can redistribute it and/or modify
  23. # it under the terms of the GNU General Public License as published by
  24. # the Free Software Foundation; either version 2 of the License, or
  25. # (at your option) any later version.
  26. #
  27. # This program is distributed in the hope that it will be useful,
  28. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  30. # GNU General Public License for more details.
  31. # You should have received a copy of the GNU General Public License
  32. # along with this program; if not, write to the Free Software
  33. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  34. #======================================================================
  35. #
  36. # This file has not undergone any whitespace cleanup.
  37. #
  38. # printing routines for ar, ap
  39. #
  40. # any custom scripts for this one
  41. if (-f "$form->{path}/custom_arapprn.pl") {
  42. eval { require "$form->{path}/custom_arapprn.pl"; };
  43. }
  44. if (-f "$form->{path}/$form->{login}_arapprn.pl") {
  45. eval { require "$form->{path}/$form->{login}_arapprn.pl"; };
  46. }
  47. 1;
  48. # end of main
  49. sub print {
  50. if ($form->{media} !~ /screen/) {
  51. $form->error($locale->text('Select postscript or PDF!')) if $form->{format} !~ /(postscript|pdf)/;
  52. $old_form = new Form;
  53. for (keys %$form) { $old_form->{$_} = $form->{$_} }
  54. }
  55. if ($form->{formname} =~ /(check|receipt)/) {
  56. if ($form->{media} eq 'screen') {
  57. $form->error($locale->text('Select postscript or PDF!')) if $form->{format} !~ /(postscript|pdf)/;
  58. }
  59. }
  60. if (! $form->{invnumber}) {
  61. $invfld = 'sinumber';
  62. $invfld = 'vinumber' if $form->{ARAP} eq 'AP';
  63. $form->{invnumber} = $form->update_defaults(\%myconfig, $invfld);
  64. if ($form->{media} eq 'screen') {
  65. if ($form->{media} eq 'screen') {
  66. &update;
  67. exit;
  68. }
  69. }
  70. }
  71. if ($form->{formname} =~ /(check|receipt)/) {
  72. if ($form->{media} ne 'screen') {
  73. for (qw(action header)) { delete $form->{$_} }
  74. $form->{invtotal} = $form->{oldinvtotal};
  75. foreach $key (keys %$form) {
  76. $form->{$key} =~ s/&/%26/g;
  77. $form->{previousform} .= qq|$key=$form->{$key}&|;
  78. }
  79. chop $form->{previousform};
  80. $form->{previousform} = $form->escape($form->{previousform}, 1);
  81. }
  82. if ($form->{paidaccounts} > 1) {
  83. if ($form->{"paid_$form->{paidaccounts}"}) {
  84. &update;
  85. exit;
  86. } elsif ($form->{paidaccounts} > 2) {
  87. # select payment
  88. &select_payment;
  89. exit;
  90. }
  91. } else {
  92. $form->error($locale->text('Nothing to print!'));
  93. }
  94. }
  95. &{ "print_$form->{formname}" }($old_form, 1);
  96. }
  97. sub print_check {
  98. my ($old_form, $i) = @_;
  99. $display_form = ($form->{display_form}) ? $form->{display_form} : "display_form";
  100. if ($form->{"paid_$i"}) {
  101. @a = ();
  102. if (exists $form->{longformat}) {
  103. $form->{"datepaid_$i"} = $locale->date(\%myconfig, $form->{"datepaid_$i"}, $form->{longformat});
  104. }
  105. push @a, "source_$i", "memo_$i";
  106. $form->format_string(@a);
  107. }
  108. $form->{amount} = $form->{"paid_$i"};
  109. if (($form->{formname} eq 'check' && $form->{vc} eq 'customer') ||
  110. ($form->{formname} eq 'receipt' && $form->{vc} eq 'vendor')) {
  111. $form->{amount} =~ s/-//g;
  112. }
  113. for (qw(datepaid source memo)) { $form->{$_} = $form->{"${_}_$i"} }
  114. &{ "$form->{vc}_details" };
  115. @a = qw(name address1 address2 city state zipcode country);
  116. foreach $item (qw(invnumber ordnumber)) {
  117. $temp{$item} = $form->{$item};
  118. delete $form->{$item};
  119. push(@{ $form->{$item} }, $temp{$item});
  120. }
  121. push(@{ $form->{invdate} }, $form->{transdate});
  122. push(@{ $form->{due} }, $form->format_amount(\%myconfig, $form->{oldinvtotal}, 2));
  123. push(@{ $form->{paid} }, $form->{"paid_$i"});
  124. use LedgerSMB::CP;
  125. $c = CP->new(($form->{language_code}) ? $form->{language_code} : $myconfig{countrycode});
  126. $c->init;
  127. ($whole, $form->{decimal}) = split /\./, $form->parse_amount(\%myconfig, $form->{amount});
  128. $form->{decimal} .= "00";
  129. $form->{decimal} = substr($form->{decimal}, 0, 2);
  130. $form->{text_decimal} = $c->num2text($form->{decimal} * 1);
  131. $form->{text_amount} = $c->num2text($whole);
  132. $form->{integer_amount} = $form->format_amount($myconfig, $whole);
  133. ($form->{employee}) = split /--/, $form->{employee};
  134. $form->{notes} =~ s/^\s+//g;
  135. push @a, "notes";
  136. for (qw(company address tel fax businessnumber)) { $form->{$_} = $myconfig{$_} }
  137. $form->{address} =~ s/\\n/\n/g;
  138. push @a, qw(company address tel fax businessnumber text_amount text_decimal);
  139. $form->format_string(@a);
  140. $form->{templates} = "$myconfig{templates}";
  141. $form->{IN} = ($form->{formname} eq 'transaction') ? lc $form->{ARAP} . "_$form->{formname}.html" : "$form->{formname}.html";
  142. if ($form->{format} =~ /(postscript|pdf)/) {
  143. $form->{IN} =~ s/html$/tex/;
  144. }
  145. if ($form->{media} !~ /(screen)/) {
  146. $form->{OUT} = "| $printer{$form->{media}}";
  147. if ($form->{printed} !~ /$form->{formname}/) {
  148. $form->{printed} .= " $form->{formname}";
  149. $form->{printed} =~ s/^ //;
  150. $form->update_status(\%myconfig);
  151. }
  152. %audittrail = ( tablename => lc $form->{ARAP},
  153. reference => $form->{invnumber},
  154. formname => $form->{formname},
  155. action => 'printed',
  156. id => $form->{id} );
  157. %status = ();
  158. for (qw(printed audittrail)) { $status{$_} = $form->{$_} }
  159. $status{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail);
  160. }
  161. $form->{fileid} = $invnumber;
  162. $form->{fileid} =~ s/(\s|\W)+//g;
  163. $form->parse_template(\%myconfig, $userspath);
  164. if ($form->{previousform}) {
  165. $previousform = $form->unescape($form->{previousform});
  166. for (keys %$form) { delete $form->{$_} }
  167. foreach $item (split /&/, $previousform) {
  168. ($key, $value) = split /=/, $item, 2;
  169. $value =~ s/%26/&/g;
  170. $form->{$key} = $value;
  171. }
  172. for (qw(exchangerate creditlimit creditremaining)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
  173. for (1 .. $form->{rowcount}) { $form->{"amount_$_"} = $form->parse_amount(\%myconfig, $form->{"amount_$_"}) }
  174. for (split / /, $form->{taxaccounts}) { $form->{"tax_$_"} = $form->parse_amount(\%myconfig, $form->{"tax_$_"}) }
  175. for $i (1 .. $form->{paidaccounts}) {
  176. for (qw(paid exchangerate)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
  177. }
  178. for (qw(printed audittrail)) { $form->{$_} = $status{$_} }
  179. &{ "$display_form" };
  180. }
  181. }
  182. sub print_receipt {
  183. my ($old_form, $i) = @_;
  184. &print_check($old_form, $i);
  185. }
  186. sub print_transaction {
  187. my ($old_form) = @_;
  188. $display_form = ($form->{display_form}) ? $form->{display_form} : "display_form";
  189. &{ "$form->{vc}_details" };
  190. @a = qw(name address1 address2 city state zipcode country);
  191. $form->{invtotal} = 0;
  192. foreach $i (1 .. $form->{rowcount} - 1) {
  193. ($form->{tempaccno}, $form->{tempaccount}) = split /--/, $form->{"$form->{ARAP}_amount_$i"};
  194. ($form->{tempprojectnumber}) = split /--/, $form->{"projectnumber_$i"};
  195. $form->{tempdescription} = $form->{"description_$i"};
  196. $form->format_string(qw(tempaccno tempaccount tempprojectnumber tempdescription));
  197. push(@{ $form->{accno} }, $form->{tempaccno});
  198. push(@{ $form->{account} }, $form->{tempaccount});
  199. push(@{ $form->{description} }, $form->{tempdescription});
  200. push(@{ $form->{projectnumber} }, $form->{tempprojectnumber});
  201. push(@{ $form->{amount} }, $form->{"amount_$i"});
  202. $form->{subtotal} += $form->parse_amount(\%myconfig, $form->{"amount_$i"});
  203. }
  204. foreach $accno (split / /, $form->{taxaccounts}) {
  205. if ($form->{"tax_$accno"}) {
  206. $form->format_string("${accno}_description");
  207. $tax += $form->parse_amount(\%myconfig, $form->{"tax_$accno"});
  208. $form->{"${accno}_tax"} = $form->{"tax_$accno"};
  209. push(@{ $form->{tax} }, $form->{"tax_$accno"});
  210. push(@{ $form->{taxdescription} }, $form->{"${accno}_description"});
  211. $form->{"${accno}_taxrate"} = $form->format_amount($myconfig, $form->{"${accno}_rate"} * 100);
  212. push(@{ $form->{taxrate} }, $form->{"${accno}_taxrate"});
  213. push(@{ $form->{taxnumber} }, $form->{"${accno}_taxnumber"});
  214. }
  215. }
  216. $tax = 0 if $form->{taxincluded};
  217. push @a, $form->{ARAP};
  218. $form->format_string(@a);
  219. $form->{paid} = 0;
  220. for $i (1 .. $form->{paidaccounts} - 1) {
  221. if ($form->{"paid_$i"}) {
  222. @a = ();
  223. $form->{paid} += $form->parse_amount(\%myconfig, $form->{"paid_$i"});
  224. if (exists $form->{longformat}) {
  225. $form->{"datepaid_$i"} = $locale->date(\%myconfig, $form->{"datepaid_$i"}, $form->{longformat});
  226. }
  227. push @a, "$form->{ARAP}_paid_$i", "source_$i", "memo_$i";
  228. $form->format_string(@a);
  229. ($accno, $account) = split /--/, $form->{"$form->{ARAP}_paid_$i"};
  230. push(@{ $form->{payment} }, $form->{"paid_$i"});
  231. push(@{ $form->{paymentdate} }, $form->{"datepaid_$i"});
  232. push(@{ $form->{paymentaccount} }, $account);
  233. push(@{ $form->{paymentsource} }, $form->{"source_$i"});
  234. push(@{ $form->{paymentmemo} }, $form->{"memo_$i"});
  235. }
  236. }
  237. $form->{invtotal} = $form->{subtotal} + $tax;
  238. $form->{total} = $form->{invtotal} - $form->{paid};
  239. use LedgerSMB::CP;
  240. $c = CP->new(($form->{language_code}) ? $form->{language_code} : $myconfig{countrycode});
  241. $c->init;
  242. ($whole, $form->{decimal}) = split /\./, $form->{invtotal};
  243. $form->{decimal} .= "00";
  244. $form->{decimal} = substr($form->{decimal}, 0, 2);
  245. $form->{text_decimal} = $c->num2text($form->{decimal} * 1);
  246. $form->{text_amount} = $c->num2text($whole);
  247. $form->{integer_amount} = $form->format_amount($myconfig, $whole);
  248. for (qw(invtotal subtotal paid total)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 2) }
  249. ($form->{employee}) = split /--/, $form->{employee};
  250. if (exists $form->{longformat}) {
  251. for (qw(duedate transdate)) { $form->{$_} = $locale->date(\%myconfig, $form->{$_}, $form->{longformat}) }
  252. }
  253. $form->{notes} =~ s/^\s+//g;
  254. @a = ("invnumber", "transdate", "duedate", "notes");
  255. for (qw(company address tel fax businessnumber)) { $form->{$_} = $myconfig{$_} }
  256. $form->{address} =~ s/\\n/\n/g;
  257. push @a, qw(company address tel fax businessnumber text_amount text_decimal);
  258. $form->format_string(@a);
  259. $form->{invdate} = $form->{transdate};
  260. $form->{templates} = "$myconfig{templates}";
  261. $form->{IN} = ($form->{formname} eq 'transaction') ? lc $form->{ARAP} . "_$form->{formname}.html" : "$form->{formname}.html";
  262. if ($form->{format} =~ /(postscript|pdf)/) {
  263. $form->{IN} =~ s/html$/tex/;
  264. }
  265. if ($form->{media} !~ /(screen)/) {
  266. $form->{OUT} = "| $printer{$form->{media}}";
  267. if ($form->{printed} !~ /$form->{formname}/) {
  268. $form->{printed} .= " $form->{formname}";
  269. $form->{printed} =~ s/^ //;
  270. $form->update_status(\%myconfig);
  271. }
  272. $old_form->{printed} = $form->{printed} if %$old_form;
  273. %audittrail = ( tablename => lc $form->{ARAP},
  274. reference => $form->{"invnumber"},
  275. formname => $form->{formname},
  276. action => 'printed',
  277. id => $form->{id} );
  278. $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail) if %$old_form;
  279. }
  280. $form->{fileid} = $form->{invnumber};
  281. $form->{fileid} =~ s/(\s|\W)+//g;
  282. $form->parse_template(\%myconfig, $userspath);
  283. if (%$old_form) {
  284. $old_form->{invnumber} = $form->{invnumber};
  285. $old_form->{invtotal} = $form->{invtotal};
  286. for (keys %$form) { delete $form->{$_} }
  287. for (keys %$old_form) { $form->{$_} = $old_form->{$_} }
  288. if (! $form->{printandpost}) {
  289. for (qw(exchangerate creditlimit creditremaining)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
  290. for (1 .. $form->{rowcount}) { $form->{"amount_$_"} = $form->parse_amount(\%myconfig, $form->{"amount_$_"}) }
  291. for (split / /, $form->{taxaccounts}) { $form->{"tax_$_"} = $form->parse_amount(\%myconfig, $form->{"tax_$_"}) }
  292. for $i (1 .. $form->{paidaccounts}) {
  293. for (qw(paid exchangerate)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
  294. }
  295. }
  296. &{ "$display_form" };
  297. }
  298. }
  299. sub vendor_details { IR->vendor_details(\%myconfig, \%$form) };
  300. sub customer_details { IS->customer_details(\%myconfig, \%$form) };
  301. sub select_payment {
  302. @column_index = ("ndx", "datepaid", "source", "memo", "paid", "$form->{ARAP}_paid");
  303. # list payments with radio button on a form
  304. $form->header;
  305. $title = $locale->text('Select payment');
  306. $column_data{ndx} = qq|<th width=1%>&nbsp;</th>|;
  307. $column_data{datepaid} = qq|<th>|.$locale->text('Date').qq|</th>|;
  308. $column_data{source} = qq|<th>|.$locale->text('Source').qq|</th>|;
  309. $column_data{memo} = qq|<th>|.$locale->text('Memo').qq|</th>|;
  310. $column_data{paid} = qq|<th>|.$locale->text('Amount').qq|</th>|;
  311. $column_data{"$form->{ARAP}_paid"} = qq|<th>|.$locale->text('Account').qq|</th>|;
  312. print qq|
  313. <body>
  314. <form method=post action=$form->{script}>
  315. <table width=100%>
  316. <tr>
  317. <th class=listtop>$title</th>
  318. </tr>
  319. <tr space=5></tr>
  320. <tr>
  321. <td>
  322. <table width=100%>
  323. <tr class=listheading>|;
  324. for (@column_index) { print "\n$column_data{$_}" }
  325. print qq|
  326. </tr>
  327. |;
  328. $checked = "checked";
  329. foreach $i (1 .. $form->{paidaccounts} - 1) {
  330. for (@column_index) { $column_data{$_} = qq|<td>$form->{"${_}_$i"}</td>| }
  331. $paid = $form->{"paid_$i"};
  332. $ok = 1;
  333. $column_data{ndx} = qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
  334. $column_data{paid} = qq|<td align=right>$paid</td>|;
  335. $checked = "";
  336. $j++; $j %= 2;
  337. print qq|
  338. <tr class=listrow$j>|;
  339. for (@column_index) { print "\n$column_data{$_}" }
  340. print qq|
  341. </tr>
  342. |;
  343. }
  344. print qq|
  345. </table>
  346. </td>
  347. </tr>
  348. <tr>
  349. <td><hr size=3 noshade></td>
  350. </tr>
  351. </table>
  352. |;
  353. for (qw(action nextsub)) { delete $form->{$_} }
  354. $form->hide_form;
  355. print qq|
  356. <br>
  357. <input type=hidden name=nextsub value=payment_selected>
  358. |;
  359. if ($ok) {
  360. print qq|
  361. <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">|;
  362. }
  363. print qq|
  364. </form>
  365. </body>
  366. </html>
  367. |;
  368. }
  369. sub payment_selected {
  370. &{ "print_$form->{formname}" }($form->{oldform}, $form->{ndx});
  371. }
  372. sub print_options {
  373. if ($form->{selectlanguage}) {
  374. $form->{"selectlanguage"} = $form->unescape($form->{"selectlanguage"});
  375. $form->{"selectlanguage"} =~ s/ selected//;
  376. $form->{"selectlanguage"} =~ s/(<option value="\Q$form->{language_code}\E")/$1 selected/;
  377. $lang = qq|<select name=language_code>$form->{selectlanguage}</select>
  378. <input type=hidden name=selectlanguage value="|.
  379. $form->escape($form->{selectlanguage},1).qq|">|;
  380. }
  381. $form->{selectformname} = $form->unescape($form->{selectformname});
  382. $form->{selectformname} =~ s/ selected//;
  383. $form->{selectformname} =~ s/(<option value="\Q$form->{formname}\E")/$1 selected/;
  384. $type = qq|<select name=formname>$form->{selectformname}</select>
  385. <input type=hidden name=selectformname value="|.$form->escape($form->{selectformname},1).qq|">|;
  386. $media = qq|<select name=media>
  387. <option value="screen">|.$locale->text('Screen');
  388. $form->{selectformat} = qq|<option value="html">html\n|;
  389. if (%printer && $latex) {
  390. for (sort keys %printer) { $media .= qq|
  391. <option value="$_">$_| }
  392. }
  393. if ($latex) {
  394. $form->{selectformat} .= qq|
  395. <option value="postscript">|.$locale->text('Postscript').qq|
  396. <option value="pdf">|.$locale->text('PDF');
  397. }
  398. $format = qq|<select name=format>$form->{selectformat}</select>|;
  399. $format =~ s/(<option value="\Q$form->{format}\E")/$1 selected/;
  400. $format .= qq|
  401. <input type=hidden name=selectformat value="|.$form->escape($form->{selectformat},1).qq|">|;
  402. $media .= qq|</select>|;
  403. $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/;
  404. print qq|
  405. <table width=100%>
  406. <tr>
  407. <td>$type</td>
  408. <td>$lang</td>
  409. <td>$format</td>
  410. <td>$media</td>
  411. <td align=right width=90%>
  412. |;
  413. if ($form->{printed} =~ /$form->{formname}/) {
  414. print $locale->text('Printed').qq|<br>|;
  415. }
  416. if ($form->{recurring}) {
  417. print $locale->text('Scheduled');
  418. }
  419. print qq|
  420. </td>
  421. </tr>
  422. </table>
  423. |;
  424. }
  425. sub print_and_post {
  426. $form->error($locale->text('Select postscript or PDF!')) if $form->{format} !~ /(postscript|pdf)/;
  427. $form->error($locale->text('Select a Printer!')) if $form->{media} eq 'screen';
  428. $form->{printandpost} = 1;
  429. $form->{display_form} = "post";
  430. &print;
  431. }