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