summaryrefslogtreecommitdiff
path: root/bin/mozilla/arapprn.pl
blob: 6bb808cfde841f99dc3b2d80ba2073d6ddd3146d (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. if ($filename = $queued{$form->{formname}}) {
  96. $form->{queued} =~ s/$form->{formname} $filename//;
  97. unlink "$spool/$filename";
  98. $filename =~ s/\..*$//g;
  99. } else {
  100. $filename = time;
  101. $filename .= $$;
  102. }
  103. if ($form->{printandpost}){
  104. &post;
  105. } else {
  106. &{ "print_$form->{formname}" }($old_form, 1);
  107. }
  108. }
  109. sub print_check {
  110. my ($old_form, $i) = @_;
  111. $display_form = ($form->{display_form}) ? $form->{display_form} : "display_form";
  112. if ($form->{"paid_$i"}) {
  113. @a = ();
  114. if (exists $form->{longformat}) {
  115. $form->{"datepaid_$i"} = $locale->date(\%myconfig, $form->{"datepaid_$i"}, $form->{longformat});
  116. }
  117. push @a, "source_$i", "memo_$i";
  118. $form->format_string(@a);
  119. }
  120. $form->{amount} = $form->{"paid_$i"};
  121. if (($form->{formname} eq 'check' && $form->{vc} eq 'customer') ||
  122. ($form->{formname} eq 'receipt' && $form->{vc} eq 'vendor')) {
  123. $form->{amount} =~ s/-//g;
  124. }
  125. for (qw(datepaid source memo)) { $form->{$_} = $form->{"${_}_$i"} }
  126. &{ "$form->{vc}_details" };
  127. @a = qw(name address1 address2 city state zipcode country);
  128. foreach $item (qw(invnumber ordnumber)) {
  129. $temp{$item} = $form->{$item};
  130. delete $form->{$item};
  131. push(@{ $form->{$item} }, $temp{$item});
  132. }
  133. push(@{ $form->{invdate} }, $form->{transdate});
  134. push(@{ $form->{due} }, $form->format_amount(\%myconfig, $form->{oldinvtotal}, 2));
  135. push(@{ $form->{paid} }, $form->{"paid_$i"});
  136. use LedgerSMB::CP;
  137. $c = CP->new(($form->{language_code}) ? $form->{language_code} : $myconfig{countrycode});
  138. $c->init;
  139. ($whole, $form->{decimal}) = split /\./, $form->parse_amount(\%myconfig, $form->{amount});
  140. $form->{decimal} .= "00";
  141. $form->{decimal} = substr($form->{decimal}, 0, 2);
  142. $form->{text_decimal} = $c->num2text($form->{decimal} * 1);
  143. $form->{text_amount} = $c->num2text($whole);
  144. $form->{integer_amount} = $form->format_amount($myconfig, $whole);
  145. ($form->{employee}) = split /--/, $form->{employee};
  146. $form->{notes} =~ s/^\s+//g;
  147. push @a, "notes";
  148. for (qw(company address tel fax businessnumber)) { $form->{$_} = $myconfig{$_} }
  149. $form->{address} =~ s/\\n/\n/g;
  150. push @a, qw(company address tel fax businessnumber text_amount text_decimal);
  151. $form->format_string(@a);
  152. $form->{templates} = "$myconfig{templates}";
  153. $form->{IN} = ($form->{formname} eq 'transaction') ? lc $form->{ARAP} . "_$form->{formname}.html" : "$form->{formname}.html";
  154. if ($form->{format} =~ /(postscript|pdf)/) {
  155. $form->{IN} =~ s/html$/tex/;
  156. }
  157. if ($form->{media} eq 'queue') {
  158. # save status
  159. $form->update_status(\%myconfig);
  160. $old_form->{queued} = $form->{queued};
  161. %audittrail = ( tablename => ($order) ? 'oe' : lc $ARAP,
  162. reference => $form->{"${inv}number"},
  163. formname => $form->{formname},
  164. action => 'queued',
  165. id => $form->{id} );
  166. $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail);
  167. }
  168. if ($form->{media} !~ /(screen|queue)/) {
  169. %queued = split / /, $form->{queued};
  170. $form->{OUT} = "| $printer{$form->{media}}";
  171. if ($form->{printed} !~ /$form->{formname}/) {
  172. $form->{printed} .= " $form->{formname}";
  173. $form->{printed} =~ s/^ //;
  174. $form->update_status(\%myconfig);
  175. }
  176. %audittrail = ( tablename => lc $form->{ARAP},
  177. reference => $form->{invnumber},
  178. formname => $form->{formname},
  179. action => 'printed',
  180. id => $form->{id} );
  181. %status = ();
  182. for (qw(printed audittrail)) { $status{$_} = $form->{$_} }
  183. $status{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail);
  184. }
  185. $form->{fileid} = $invnumber;
  186. $form->{fileid} =~ s/(\s|\W)+//g;
  187. $form->parse_template(\%myconfig, $userspath);
  188. if ($form->{previousform}) {
  189. $previousform = $form->unescape($form->{previousform});
  190. for (keys %$form) { delete $form->{$_} }
  191. foreach $item (split /&/, $previousform) {
  192. ($key, $value) = split /=/, $item, 2;
  193. $value =~ s/%26/&/g;
  194. $form->{$key} = $value;
  195. }
  196. for (qw(exchangerate creditlimit creditremaining)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
  197. for (1 .. $form->{rowcount}) { $form->{"amount_$_"} = $form->parse_amount(\%myconfig, $form->{"amount_$_"}) }
  198. for (split / /, $form->{taxaccounts}) { $form->{"tax_$_"} = $form->parse_amount(\%myconfig, $form->{"tax_$_"}) }
  199. for $i (1 .. $form->{paidaccounts}) {
  200. for (qw(paid exchangerate)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
  201. }
  202. for (qw(printed audittrail)) { $form->{$_} = $status{$_} }
  203. &{ "$display_form" };
  204. }
  205. }
  206. sub print_receipt {
  207. my ($old_form, $i) = @_;
  208. &print_check($old_form, $i);
  209. }
  210. sub print_transaction {
  211. my ($old_form) = @_;
  212. $display_form = ($form->{display_form}) ? $form->{display_form} : "display_form";
  213. &{ "$form->{vc}_details" };
  214. @a = qw(name address1 address2 city state zipcode country);
  215. $form->{invtotal} = 0;
  216. foreach $i (1 .. $form->{rowcount} - 1) {
  217. ($form->{tempaccno}, $form->{tempaccount}) = split /--/, $form->{"$form->{ARAP}_amount_$i"};
  218. ($form->{tempprojectnumber}) = split /--/, $form->{"projectnumber_$i"};
  219. $form->{tempdescription} = $form->{"description_$i"};
  220. $form->format_string(qw(tempaccno tempaccount tempprojectnumber tempdescription));
  221. push(@{ $form->{accno} }, $form->{tempaccno});
  222. push(@{ $form->{account} }, $form->{tempaccount});
  223. push(@{ $form->{description} }, $form->{tempdescription});
  224. push(@{ $form->{projectnumber} }, $form->{tempprojectnumber});
  225. push(@{ $form->{amount} }, $form->{"amount_$i"});
  226. $form->{subtotal} += $form->parse_amount(\%myconfig, $form->{"amount_$i"});
  227. }
  228. foreach $accno (split / /, $form->{taxaccounts}) {
  229. if ($form->{"tax_$accno"}) {
  230. $form->format_string("${accno}_description");
  231. $tax += $form->parse_amount(\%myconfig, $form->{"tax_$accno"});
  232. $form->{"${accno}_tax"} = $form->{"tax_$accno"};
  233. push(@{ $form->{tax} }, $form->{"tax_$accno"});
  234. push(@{ $form->{taxdescription} }, $form->{"${accno}_description"});
  235. $form->{"${accno}_taxrate"} = $form->format_amount($myconfig, $form->{"${accno}_rate"} * 100);
  236. push(@{ $form->{taxrate} }, $form->{"${accno}_taxrate"});
  237. push(@{ $form->{taxnumber} }, $form->{"${accno}_taxnumber"});
  238. }
  239. }
  240. $tax = 0 if $form->{taxincluded};
  241. push @a, $form->{ARAP};
  242. $form->format_string(@a);
  243. $form->{paid} = 0;
  244. for $i (1 .. $form->{paidaccounts} - 1) {
  245. if ($form->{"paid_$i"}) {
  246. @a = ();
  247. $form->{paid} += $form->parse_amount(\%myconfig, $form->{"paid_$i"});
  248. if (exists $form->{longformat}) {
  249. $form->{"datepaid_$i"} = $locale->date(\%myconfig, $form->{"datepaid_$i"}, $form->{longformat});
  250. }
  251. push @a, "$form->{ARAP}_paid_$i", "source_$i", "memo_$i";
  252. $form->format_string(@a);
  253. ($accno, $account) = split /--/, $form->{"$form->{ARAP}_paid_$i"};
  254. push(@{ $form->{payment} }, $form->{"paid_$i"});
  255. push(@{ $form->{paymentdate} }, $form->{"datepaid_$i"});
  256. push(@{ $form->{paymentaccount} }, $account);
  257. push(@{ $form->{paymentsource} }, $form->{"source_$i"});
  258. push(@{ $form->{paymentmemo} }, $form->{"memo_$i"});
  259. }
  260. }
  261. $form->{invtotal} = $form->{subtotal} + $tax;
  262. $form->{total} = $form->{invtotal} - $form->{paid};
  263. use LedgerSMB::CP;
  264. $c = CP->new(($form->{language_code}) ? $form->{language_code} : $myconfig{countrycode});
  265. $c->init;
  266. ($whole, $form->{decimal}) = split /\./, $form->{invtotal};
  267. $form->{decimal} .= "00";
  268. $form->{decimal} = substr($form->{decimal}, 0, 2);
  269. $form->{text_decimal} = $c->num2text($form->{decimal} * 1);
  270. $form->{text_amount} = $c->num2text($whole);
  271. $form->{integer_amount} = $form->format_amount($myconfig, $whole);
  272. for (qw(invtotal subtotal paid total)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 2) }
  273. ($form->{employee}) = split /--/, $form->{employee};
  274. if (exists $form->{longformat}) {
  275. for (qw(duedate transdate)) { $form->{$_} = $locale->date(\%myconfig, $form->{$_}, $form->{longformat}) }
  276. }
  277. $form->{notes} =~ s/^\s+//g;
  278. @a = ("invnumber", "transdate", "duedate", "notes");
  279. for (qw(company address tel fax businessnumber)) { $form->{$_} = $myconfig{$_} }
  280. $form->{address} =~ s/\\n/\n/g;
  281. push @a, qw(company address tel fax businessnumber text_amount text_decimal);
  282. $form->format_string(@a);
  283. $form->{invdate} = $form->{transdate};
  284. $form->{templates} = "$myconfig{templates}";
  285. $form->{IN} = ($form->{formname} eq 'transaction') ? lc $form->{ARAP} . "_$form->{formname}.html" : "$form->{formname}.html";
  286. if ($form->{format} =~ /(postscript|pdf)/) {
  287. $form->{IN} =~ s/html$/tex/;
  288. }
  289. if ($form->{media} eq 'queue') {
  290. %queued = split / /, $form->{queued};
  291. if ($filename = $queued{$form->{formname}}) {
  292. $form->{queued} =~ s/$form->{formname} $filename//;
  293. unlink "$spool/$filename";
  294. $filename =~ s/\..*$//g;
  295. } else {
  296. $filename = time;
  297. $filename .= $$;
  298. }
  299. $filename .= ($form->{format} eq 'postscript') ? '.ps' : '.pdf';
  300. $form->{OUT} = ">$spool/$filename";
  301. $form->{queued} .= " $form->{formname} $filename";
  302. $form->{queued} =~ s/^ //;
  303. # save status
  304. $form->update_status(\%myconfig);
  305. $old_form->{queued} = $form->{queued};
  306. %audittrail = ( tablename => ($order) ? 'oe' : lc $ARAP,
  307. reference => $form->{"${inv}number"},
  308. formname => $form->{formname},
  309. action => 'queued',
  310. id => $form->{id} );
  311. $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail);
  312. }
  313. if ($form->{media} !~ /(queue|screen)/) {
  314. $form->{OUT} = "| $printer{$form->{media}}";
  315. if ($form->{printed} !~ /$form->{formname}/) {
  316. $form->{printed} .= " $form->{formname}";
  317. $form->{printed} =~ s/^ //;
  318. $form->update_status(\%myconfig);
  319. }
  320. $old_form->{printed} = $form->{printed} if %$old_form;
  321. %audittrail = ( tablename => lc $form->{ARAP},
  322. reference => $form->{"invnumber"},
  323. formname => $form->{formname},
  324. action => 'printed',
  325. id => $form->{id} );
  326. $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail) if %$old_form;
  327. }
  328. $form->{fileid} = $form->{invnumber};
  329. $form->{fileid} =~ s/(\s|\W)+//g;
  330. $form->parse_template(\%myconfig, $userspath);
  331. if (%$old_form) {
  332. $old_form->{invnumber} = $form->{invnumber};
  333. $old_form->{invtotal} = $form->{invtotal};
  334. for (keys %$form) { delete $form->{$_} }
  335. for (keys %$old_form) { $form->{$_} = $old_form->{$_} }
  336. if (! $form->{printandpost}) {
  337. for (qw(exchangerate creditlimit creditremaining)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
  338. for (1 .. $form->{rowcount}) { $form->{"amount_$_"} = $form->parse_amount(\%myconfig, $form->{"amount_$_"}) }
  339. for (split / /, $form->{taxaccounts}) { $form->{"tax_$_"} = $form->parse_amount(\%myconfig, $form->{"tax_$_"}) }
  340. for $i (1 .. $form->{paidaccounts}) {
  341. for (qw(paid exchangerate)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
  342. }
  343. }
  344. &{ "$display_form" };
  345. }
  346. }
  347. sub vendor_details { IR->vendor_details(\%myconfig, \%$form) };
  348. sub customer_details { IS->customer_details(\%myconfig, \%$form) };
  349. sub select_payment {
  350. @column_index = ("ndx", "datepaid", "source", "memo", "paid", "$form->{ARAP}_paid");
  351. # list payments with radio button on a form
  352. $form->header;
  353. $title = $locale->text('Select payment');
  354. $column_data{ndx} = qq|<th width=1%>&nbsp;</th>|;
  355. $column_data{datepaid} = qq|<th>|.$locale->text('Date').qq|</th>|;
  356. $column_data{source} = qq|<th>|.$locale->text('Source').qq|</th>|;
  357. $column_data{memo} = qq|<th>|.$locale->text('Memo').qq|</th>|;
  358. $column_data{paid} = qq|<th>|.$locale->text('Amount').qq|</th>|;
  359. $column_data{"$form->{ARAP}_paid"} = qq|<th>|.$locale->text('Account').qq|</th>|;
  360. print qq|
  361. <body>
  362. <form method=post action=$form->{script}>
  363. <table width=100%>
  364. <tr>
  365. <th class=listtop>$title</th>
  366. </tr>
  367. <tr space=5></tr>
  368. <tr>
  369. <td>
  370. <table width=100%>
  371. <tr class=listheading>|;
  372. for (@column_index) { print "\n$column_data{$_}" }
  373. print qq|
  374. </tr>
  375. |;
  376. $checked = "checked";
  377. foreach $i (1 .. $form->{paidaccounts} - 1) {
  378. for (@column_index) { $column_data{$_} = qq|<td>$form->{"${_}_$i"}</td>| }
  379. $paid = $form->{"paid_$i"};
  380. $ok = 1;
  381. $column_data{ndx} = qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
  382. $column_data{paid} = qq|<td align=right>$paid</td>|;
  383. $checked = "";
  384. $j++; $j %= 2;
  385. print qq|
  386. <tr class=listrow$j>|;
  387. for (@column_index) { print "\n$column_data{$_}" }
  388. print qq|
  389. </tr>
  390. |;
  391. }
  392. print qq|
  393. </table>
  394. </td>
  395. </tr>
  396. <tr>
  397. <td><hr size=3 noshade></td>
  398. </tr>
  399. </table>
  400. |;
  401. for (qw(action nextsub)) { delete $form->{$_} }
  402. $form->hide_form;
  403. print qq|
  404. <br>
  405. <input type=hidden name=nextsub value=payment_selected>
  406. |;
  407. if ($ok) {
  408. print qq|
  409. <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">|;
  410. }
  411. print qq|
  412. </form>
  413. </body>
  414. </html>
  415. |;
  416. }
  417. sub payment_selected {
  418. &{ "print_$form->{formname}" }($form->{oldform}, $form->{ndx});
  419. }
  420. sub print_options {
  421. if ($form->{selectlanguage}) {
  422. $form->{"selectlanguage"} = $form->unescape($form->{"selectlanguage"});
  423. $form->{"selectlanguage"} =~ s/ selected//;
  424. $form->{"selectlanguage"} =~ s/(<option value="\Q$form->{language_code}\E")/$1 selected/;
  425. $lang = qq|<select name=language_code>$form->{selectlanguage}</select>
  426. <input type=hidden name=selectlanguage value="|.
  427. $form->escape($form->{selectlanguage},1).qq|">|;
  428. }
  429. $form->{selectformname} = $form->unescape($form->{selectformname});
  430. $form->{selectformname} =~ s/ selected//;
  431. $form->{selectformname} =~ s/(<option value="\Q$form->{formname}\E")/$1 selected/;
  432. $type = qq|<select name=formname>$form->{selectformname}</select>
  433. <input type=hidden name=selectformname value="|.$form->escape($form->{selectformname},1).qq|">|;
  434. $media = qq|<select name=media>
  435. <option value="screen">|.$locale->text('Screen');
  436. $form->{selectformat} = qq|<option value="html">html\n|;
  437. if (%printer && $latex) {
  438. for (sort keys %printer) { $media .= qq|
  439. <option value="$_">$_| }
  440. }
  441. if ($latex) {
  442. $form->{selectformat} .= qq|
  443. <option value="postscript">|.$locale->text('Postscript').qq|
  444. <option value="pdf">|.$locale->text('PDF');
  445. $media .= qq|<option value="queue">|.$locale->text('Queue');
  446. }
  447. $format = qq|<select name=format>$form->{selectformat}</select>|;
  448. $format =~ s/(<option value="\Q$form->{format}\E")/$1 selected/;
  449. $format .= qq|
  450. <input type=hidden name=selectformat value="|.$form->escape($form->{selectformat},1).qq|">|;
  451. $media .= qq|</select>|;
  452. $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/;
  453. print qq|
  454. <table width=100%>
  455. <tr>
  456. <td>$type</td>
  457. <td>$lang</td>
  458. <td>$format</td>
  459. <td>$media</td>
  460. <td align=right width=90%>
  461. |;
  462. if ($form->{printed} =~ /$form->{formname}/) {
  463. print $locale->text('Printed').qq|<br>|;
  464. }
  465. if ($form->{recurring}) {
  466. print $locale->text('Scheduled');
  467. }
  468. print qq|
  469. </td>
  470. </tr>
  471. </table>
  472. |;
  473. }
  474. sub print_and_post {
  475. $form->error($locale->text('Select postscript or PDF!')) if $form->{format} !~ /(postscript|pdf)/;
  476. $form->error($locale->text('Select a Printer!')) if $form->{media} eq 'screen';
  477. $form->{printandpost} = 1;
  478. $form->{display_form} = "post";
  479. &print;
  480. }