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