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