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