summaryrefslogtreecommitdiff
path: root/bin/aa.pl
blob: 3bdac046dab69843ff4f09ec50a1f85d6c14098a (plain)
  1. #=====================================================================
  2. # LedgerSMB Small Medium Business Accounting
  3. # http://www.ledgersmb.org/
  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) 2005
  17. #
  18. # Author: DWS Systems Inc.
  19. # Web: http://www.sql-ledger.org
  20. #
  21. # Contributors:
  22. #
  23. #
  24. # Author: DWS Systems Inc.
  25. # Web: http://www.ledgersmb.org/
  26. #
  27. # Contributors:
  28. #
  29. # This program is free software; you can redistribute it and/or modify
  30. # it under the terms of the GNU General Public License as published by
  31. # the Free Software Foundation; either version 2 of the License, or
  32. # (at your option) any later version.
  33. #
  34. # This program is distributed in the hope that it will be useful,
  35. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  36. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  37. # GNU General Public License for more details.
  38. # You should have received a copy of the GNU General Public License
  39. # along with this program; if not, write to the Free Software
  40. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  41. #======================================================================
  42. #
  43. # AR / AP
  44. #
  45. #======================================================================
  46. use LedgerSMB::Tax;
  47. # any custom scripts for this one
  48. if ( -f "bin/custom/aa.pl" ) {
  49. eval { require "bin/custom/aa.pl"; };
  50. }
  51. if ( -f "bin/custom/$form->{login}_aa.pl" ) {
  52. eval { require "bin/custom/$form->{login}_aa.pl"; };
  53. }
  54. my $is_update;
  55. 1;
  56. # end of main
  57. # this is for our long dates
  58. # $locale->text('January')
  59. # $locale->text('February')
  60. # $locale->text('March')
  61. # $locale->text('April')
  62. # $locale->text('May ')
  63. # $locale->text('June')
  64. # $locale->text('July')
  65. # $locale->text('August')
  66. # $locale->text('September')
  67. # $locale->text('October')
  68. # $locale->text('November')
  69. # $locale->text('December')
  70. # this is for our short month
  71. # $locale->text('Jan')
  72. # $locale->text('Feb')
  73. # $locale->text('Mar')
  74. # $locale->text('Apr')
  75. # $locale->text('May')
  76. # $locale->text('Jun')
  77. # $locale->text('Jul')
  78. # $locale->text('Aug')
  79. # $locale->text('Sep')
  80. # $locale->text('Oct')
  81. # $locale->text('Nov')
  82. # $locale->text('Dec')
  83. sub add {
  84. $form->{title} = "Add";
  85. $form->{callback} =
  86. "$form->{script}?action=add&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"
  87. unless $form->{callback};
  88. &create_links;
  89. $form->{focus} = "amount_1";
  90. &display_form;
  91. }
  92. sub edit {
  93. $form->{title} = "Edit";
  94. &create_links;
  95. &display_form;
  96. }
  97. sub display_form {
  98. &form_header;
  99. &form_footer;
  100. }
  101. sub create_links {
  102. if ( $form->{script} eq 'ap.pl' ) {
  103. $form->{ARAP} = 'AP';
  104. $form->{vc} = 'vendor';
  105. }
  106. elsif ( $form->{script} eq 'ar.pl' ) {
  107. $form->{ARAP} = 'AR';
  108. $form->{vc} = 'customer';
  109. }
  110. $form->create_links( $form->{ARAP}, \%myconfig, $form->{vc} );
  111. $duedate = $form->{duedate};
  112. $taxincluded = $form->{taxincluded};
  113. $form->{formname} = "transaction";
  114. $form->{format} = "postscript" if $myconfig{printer};
  115. $form->{media} = $myconfig{printer};
  116. $form->{selectformname} =
  117. qq|<option value="transaction">| . $locale->text('Transaction');
  118. if ( ${LedgerSMB::Sysconfig::latex} ) {
  119. if ( $form->{ARAP} eq 'AR' ) {
  120. $form->{selectformname} .= qq|
  121. <option value="receipt">| . $locale->text('Receipt');
  122. }
  123. else {
  124. $form->{selectformname} .= qq|
  125. <option value="check">| . $locale->text('Check');
  126. }
  127. }
  128. # currencies
  129. @curr = split /:/, $form->{currencies};
  130. $form->{defaultcurrency} = $curr[0];
  131. chomp $form->{defaultcurrency};
  132. for (@curr) { $form->{selectcurrency} .= "<option>$_\n" }
  133. AA->get_name( \%myconfig, \%$form );
  134. $form->{currency} =~ s/ //g;
  135. $form->{duedate} = $duedate if $duedate;
  136. $form->{taxincluded} = $taxincluded if $form->{id};
  137. $form->{notes} = $form->{intnotes} if !$form->{id};
  138. $form->{"old$form->{vc}"} =
  139. qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
  140. $form->{oldtransdate} = $form->{transdate};
  141. # customers/vendors
  142. $form->{"select$form->{vc}"} = "";
  143. if ( @{ $form->{"all_$form->{vc}"} } ) {
  144. $form->{ $form->{vc} } =
  145. qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
  146. for ( @{ $form->{"all_$form->{vc}"} } ) {
  147. $form->{"select$form->{vc}"} .=
  148. qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
  149. }
  150. }
  151. # departments
  152. if ( @{ $form->{all_department} } ) {
  153. $form->{selectdepartment} = "<option>\n";
  154. $form->{department} = "$form->{department}--$form->{department_id}"
  155. if $form->{department_id};
  156. for ( @{ $form->{all_department} } ) {
  157. $form->{selectdepartment} .=
  158. qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
  159. }
  160. }
  161. $form->{employee} = "$form->{employee}--$form->{employee_id}";
  162. # sales staff
  163. if ( @{ $form->{all_employee} } ) {
  164. $form->{selectemployee} = "";
  165. for ( @{ $form->{all_employee} } ) {
  166. $form->{selectemployee} .=
  167. qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
  168. }
  169. }
  170. # projects
  171. if ( @{ $form->{all_project} } ) {
  172. $form->{selectprojectnumber} = "<option>\n";
  173. for ( @{ $form->{all_project} } ) {
  174. $form->{selectprojectnumber} .=
  175. qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n|;
  176. }
  177. }
  178. if ( @{ $form->{all_language} } ) {
  179. $form->{selectlanguage} = "<option>\n";
  180. for ( @{ $form->{all_language} } ) {
  181. $form->{selectlanguage} .=
  182. qq|<option value="$_->{code}">$_->{description}\n|;
  183. }
  184. }
  185. # forex
  186. $form->{forex} = $form->{exchangerate};
  187. $exchangerate = ( $form->{exchangerate} ) ? $form->{exchangerate} : 1;
  188. $netamount = 0;
  189. $tax = 0;
  190. $taxrate = 0;
  191. $ml = ( $form->{ARAP} eq 'AR' ) ? 1 : -1;
  192. foreach $key ( keys %{ $form->{"$form->{ARAP}_links"} } ) {
  193. $form->{"select$key"} = "";
  194. foreach $ref ( @{ $form->{"$form->{ARAP}_links"}{$key} } ) {
  195. if ( $key eq "$form->{ARAP}_tax" ) {
  196. $form->{"select$form->{ARAP}_tax_$ref->{accno}"} =
  197. "<option>$ref->{accno}--$ref->{description}\n";
  198. next;
  199. }
  200. $form->{"select$key"} .=
  201. "<option>$ref->{accno}--$ref->{description}\n";
  202. }
  203. # if there is a value we have an old entry
  204. for $i ( 1 .. scalar @{ $form->{acc_trans}{$key} } ) {
  205. if ( $key eq "$form->{ARAP}_paid" ) {
  206. $form->{"$form->{ARAP}_paid_$i"} =
  207. "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
  208. $form->{"paid_$i"} =
  209. $form->{acc_trans}{$key}->[ $i - 1 ]->{amount} * -1 * $ml;
  210. $form->{"datepaid_$i"} =
  211. $form->{acc_trans}{$key}->[ $i - 1 ]->{transdate};
  212. $form->{"source_$i"} =
  213. $form->{acc_trans}{$key}->[ $i - 1 ]->{source};
  214. $form->{"memo_$i"} =
  215. $form->{acc_trans}{$key}->[ $i - 1 ]->{memo};
  216. $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
  217. $form->{acc_trans}{$key}->[ $i - 1 ]->{exchangerate};
  218. $form->{paidaccounts}++;
  219. }
  220. else {
  221. $akey = $key;
  222. $akey =~ s/$form->{ARAP}_//;
  223. if ( $key eq "$form->{ARAP}_tax" ) {
  224. $form->{"${key}_$form->{acc_trans}{$key}->[$i-1]->{accno}"}
  225. = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
  226. $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"}
  227. = $form->{acc_trans}{$key}->[ $i - 1 ]->{amount} * $ml;
  228. $tax +=
  229. $form->{
  230. "${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"};
  231. $taxrate +=
  232. $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"};
  233. }
  234. else {
  235. $form->{"${akey}_$i"} =
  236. $form->{acc_trans}{$key}->[ $i - 1 ]->{amount} * $ml;
  237. if ( $akey eq 'amount' ) {
  238. $form->{"description_$i"} =
  239. $form->{acc_trans}{$key}->[ $i - 1 ]->{memo};
  240. $form->{rowcount}++;
  241. $netamount += $form->{"${akey}_$i"};
  242. $form->{"projectnumber_$i"} =
  243. "$form->{acc_trans}{$key}->[$i-1]->{projectnumber}--$form->{acc_trans}{$key}->[$i-1]->{project_id}"
  244. if $form->{acc_trans}{$key}->[ $i - 1 ]->{project_id};
  245. }
  246. else {
  247. $form->{invtotal} =
  248. $form->{acc_trans}{$key}->[ $i - 1 ]->{amount} * -1 *
  249. $ml;
  250. }
  251. $form->{"${key}_$i"} =
  252. "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
  253. }
  254. }
  255. }
  256. }
  257. $form->{paidaccounts} = 1 if not defined $form->{paidaccounts};
  258. if ( $form->{taxincluded} ) {
  259. $diff = 0;
  260. # add tax to individual amounts
  261. # XXX needs alteration for conditional taxes
  262. for $i ( 1 .. $form->{rowcount} ) {
  263. if ($netamount) {
  264. $amount = $form->{"amount_$i"} * ( 1 + $tax / $netamount );
  265. $form->{"amount_$i"} = $form->round_amount( $amount, 2 );
  266. }
  267. }
  268. }
  269. $form->{invtotal} = $netamount + $tax;
  270. # check if calculated is equal to stored
  271. # taxincluded is terrible to calculate
  272. # this works only if all taxes are checked
  273. @taxaccounts = Tax::init_taxes( $form, $form->{taxaccounts} );
  274. if ( $form->{id} ) {
  275. if ( $form->{taxincluded} ) {
  276. $amount =
  277. Tax::calculate_taxes( \@taxaccounts, $form, $form->{invtotal},
  278. 1 );
  279. $tax = $form->round_amount( $amount, 2 );
  280. }
  281. else {
  282. $tax =
  283. $form->round_amount(
  284. Tax::calculate_taxes( \@taxaccounts, $form, $netamount, 0 ) );
  285. }
  286. foreach $item (@taxaccounts) {
  287. $tax{ $item->account } = $form->round_amount( $item->value, 2 );
  288. $form->{ "calctax_" . $item->account } = 1
  289. if $item->value
  290. and
  291. ( $tax{ $item->account } == $form->{ "tax_" . $item->account } );
  292. }
  293. }
  294. else {
  295. for (@taxaccounts) { $form->{ "calctax_" . $_->account } = 1 }
  296. }
  297. $form->{rowcount}++ if ( $form->{id} || !$form->{rowcount} );
  298. $form->{ $form->{ARAP} } = $form->{"$form->{ARAP}_1"};
  299. $form->{rowcount} = 1 unless $form->{"$form->{ARAP}_amount_1"};
  300. $form->{locked} =
  301. ( $form->{revtrans} )
  302. ? '1'
  303. : ( $form->datetonum( \%myconfig, $form->{transdate} ) <=
  304. $form->datetonum( \%myconfig, $form->{closedto} ) );
  305. # readonly
  306. if ( !$form->{readonly} ) {
  307. $form->{readonly} = 1
  308. if $myconfig{acs} =~ /$form->{ARAP}--Add Transaction/;
  309. }
  310. }
  311. sub form_header {
  312. $title = $form->{title};
  313. $form->{title} = $locale->text("$title $form->{ARAP} Transaction");
  314. $form->{taxincluded} = ( $form->{taxincluded} ) ? "checked" : "";
  315. # $locale->text('Add AR Transaction')
  316. # $locale->text('Edit AR Transaction')
  317. # $locale->text('Add AP Transaction')
  318. # $locale->text('Edit AP Transaction')
  319. # set option selected
  320. for ( "$form->{ARAP}", "currency" ) {
  321. $form->{"select$_"} =~ s/ selected//;
  322. $form->{"select$_"} =~
  323. s/<option>\Q$form->{$_}\E/<option selected>$form->{$_}/;
  324. }
  325. for ( "$form->{vc}", "department", "employee", "formname" ) {
  326. $form->{"select$_"} = $form->unescape( $form->{"select$_"} );
  327. $form->{"select$_"} =~ s/ selected//;
  328. $form->{"select$_"} =~ s/(<option value="\Q$form->{$_}\E")/$1 selected/;
  329. }
  330. $form->{selectprojectnumber} =
  331. $form->unescape( $form->{selectprojectnumber} );
  332. # format amounts
  333. $form->{exchangerate} =
  334. $form->format_amount( \%myconfig, $form->{exchangerate} );
  335. $exchangerate = qq|<tr>|;
  336. $exchangerate .= qq|
  337. <th align="right" nowrap>| . $locale->text('Currency') . qq|</th>
  338. <td><select name="currency">$form->{selectcurrency}</select></td> |
  339. if $form->{defaultcurrency};
  340. $exchangerate .= qq|
  341. <input type="hidden" name="selectcurrency" value="$form->{selectcurrency}">
  342. <input type="hidden" name="defaultcurrency" value="$form->{defaultcurrency}">
  343. |;
  344. if ( $form->{defaultcurrency}
  345. && $form->{currency} ne $form->{defaultcurrency} )
  346. {
  347. if ( $form->{forex} ) {
  348. $exchangerate .= qq|
  349. <th align="right">| . $locale->text('Exchange Rate') . qq|</th>
  350. <td><input type="hidden" name="exchangerate" value="$form->{exchangerate}">$form->{exchangerate}</td>
  351. |;
  352. }
  353. else {
  354. $exchangerate .= qq|
  355. <th align="right">| . $locale->text('Exchange Rate') . qq|</th>
  356. <td><input name="exchangerate" size="10" value="$form->{exchangerate}"></td>
  357. |;
  358. }
  359. }
  360. $exchangerate .= qq|
  361. <input type="hidden" name="forex" value="$form->{forex}">
  362. </tr>
  363. |;
  364. $taxincluded = "";
  365. if ( $form->{taxaccounts} ) {
  366. $taxincluded = qq|
  367. <tr>
  368. <td align="right"><input name="taxincluded" class="checkbox" type="checkbox" value="1" $form->{taxincluded}></td>
  369. <th align="left" nowrap>| . $locale->text('Tax Included') . qq|</th>
  370. </tr>
  371. |;
  372. }
  373. if ( ( $rows = $form->numtextrows( $form->{notes}, 50 ) - 1 ) < 2 ) {
  374. $rows = 2;
  375. }
  376. $notes =
  377. qq|<textarea name="notes" rows="$rows" cols="50" wrap="soft">$form->{notes}</textarea>|;
  378. $department = qq|
  379. <tr>
  380. <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
  381. <td colspan="3"><select name="department">$form->{selectdepartment}</select>
  382. <input type="hidden" name="selectdepartment" value="|
  383. . $form->escape( $form->{selectdepartment}, 1 ) . qq|">
  384. </td>
  385. </tr>
  386. | if $form->{selectdepartment};
  387. $n = ( $form->{creditremaining} < 0 ) ? "0" : "1";
  388. $name =
  389. ( $form->{"select$form->{vc}"} )
  390. ? qq|<select name="$form->{vc}">$form->{"select$form->{vc}"}</select>|
  391. : qq|<input name="$form->{vc}" value="$form->{$form->{vc}}" size="35">|;
  392. $employee = qq|
  393. <input type="hidden" name="employee" value="$form->{employee}">
  394. |;
  395. if ( $form->{selectemployee} ) {
  396. $label =
  397. ( $form->{ARAP} eq 'AR' )
  398. ? $locale->text('Salesperson')
  399. : $locale->text('Employee');
  400. $employee = qq|
  401. <tr>
  402. <th align="right" nowrap>$label</th>
  403. <td><select name="employee">$form->{selectemployee}</select></td>
  404. <input type="hidden" name="selectemployee" value="|
  405. . $form->escape( $form->{selectemployee}, 1 ) . qq|">
  406. </tr>
  407. |;
  408. }
  409. $focus = ( $form->{focus} ) ? $form->{focus} : "amount_$form->{rowcount}";
  410. $form->header;
  411. print qq|
  412. <body onload="document.forms[0].${focus}.focus()">
  413. <form method="post" action="$form->{script}">
  414. <input type="hidden" name="type" value="$form->{formname}">
  415. <input type="hidden" name="title" value="$title">
  416. |;
  417. $form->hide_form(
  418. qw(id printed emailed sort closedto locked oldtransdate audittrail recurring checktax)
  419. );
  420. if ( $form->{vc} eq 'customer' ) {
  421. $label = $locale->text('Customer');
  422. }
  423. else {
  424. $label = $locale->text('Vendor');
  425. }
  426. $form->hide_form(
  427. "old$form->{vc}", "$form->{vc}_id",
  428. "terms", "creditlimit",
  429. "creditremaining", "selectcurrency",
  430. "defaultcurrency", "select$form->{ARAP}_amount",
  431. "rowcount"
  432. );
  433. print qq|
  434. <table width="100%">
  435. <tr class="listtop">
  436. <th class="listtop">$form->{title}</th>
  437. </tr>
  438. <tr height="5"></tr>
  439. <tr valign="top">
  440. <td>
  441. <table width="100%">
  442. <tr valign="top">
  443. <td>
  444. <table>
  445. <tr>
  446. <th align="right" nowrap>$label</th>
  447. <td colspan="3">$name</td>
  448. <input type="hidden" name="select$form->{vc}" value="|
  449. . $form->escape( $form->{"select$form->{vc}"}, 1 ) . qq|">
  450. </tr>
  451. <tr>
  452. <td></td>
  453. <td colspan="3">
  454. <table width="100%">
  455. <tr>
  456. <th align="left" nowrap>| . $locale->text('Credit Limit') . qq|</th>
  457. <td>$form->{creditlimit}</td>
  458. <th align="left" nowrap>| . $locale->text('Remaining') . qq|</th>
  459. <td class="plus$n">|
  460. . $form->format_amount( \%myconfig, $form->{creditremaining}, 0, "0" )
  461. . qq|</td>
  462. </tr>
  463. </table>
  464. </td>
  465. </tr>
  466. $exchangerate
  467. $department
  468. $taxincluded
  469. </table>
  470. </td>
  471. <td align="right">
  472. <table>
  473. $employee
  474. <tr>
  475. <th align="right" nowrap>| . $locale->text('Invoice Number') . qq|</th>
  476. <td><input name="invnumber" size="20" value="$form->{invnumber}"></td>
  477. </tr>
  478. <tr>
  479. <th align="right" nowrap>| . $locale->text('Order Number') . qq|</th>
  480. <td><input name="ordnumber" size="20" value="$form->{ordnumber}"></td>
  481. </tr>
  482. <tr>
  483. <th align="right" nowrap>| . $locale->text('Invoice Date') . qq|</th>
  484. <td><input name="transdate" size="11" title="($myconfig{'dateformat'})" value="$form->{transdate}"></td>
  485. </tr>
  486. <tr>
  487. <th align="right" nowrap>| . $locale->text('Due Date') . qq|</th>
  488. <td><input name="duedate" size="11" title="$myconfig{'dateformat'}" value="$form->{duedate}"></td>
  489. </tr>
  490. <tr>
  491. <th align="right" nowrap>| . $locale->text('PO Number') . qq|</th>
  492. <td><input name="ponumber" size="20" value="$form->{ponumber}"></td>
  493. </tr>
  494. </table>
  495. </td>
  496. </tr>
  497. </table>
  498. </td>
  499. </tr>
  500. <input type="hidden" name="selectprojectnumber" value="|
  501. . $form->escape( $form->{selectprojectnumber}, 1 ) . qq|">
  502. <tr>
  503. <td>
  504. <table>
  505. |;
  506. $project = qq|
  507. <th>| . $locale->text('Project') . qq|</th>
  508. | if $form->{selectprojectnumber};
  509. print qq|
  510. <tr>
  511. <th>| . $locale->text('Amount') . qq|</th>
  512. <th></th>
  513. <th>| . $locale->text('Account') . qq|</th>
  514. <th>| . $locale->text('Description') . qq|</th>
  515. $project
  516. </tr>
  517. |;
  518. for $i ( 1 .. $form->{rowcount} ) {
  519. $selectamount = $form->{"select$form->{ARAP}_amount"};
  520. $selectamount =~
  521. s/option>\Q$form->{"$form->{ARAP}_amount_$i"}\E/option selected>$form->{"$form->{ARAP}_amount_$i"}/;
  522. $selectprojectnumber = $form->{selectprojectnumber};
  523. $selectprojectnumber =~
  524. s/(<option value="\Q$form->{"projectnumber_$i"}\E")/$1 selected/;
  525. # format amounts
  526. $form->{"amount_$i"} =
  527. $form->format_amount( \%myconfig, $form->{"amount_$i"}, 2 );
  528. $project = qq|
  529. <td align="right"><select name="projectnumber_$i">$selectprojectnumber</select></td>
  530. | if $form->{selectprojectnumber};
  531. if ( ( $rows = $form->numtextrows( $form->{"description_$i"}, 40 ) ) >
  532. 1 )
  533. {
  534. $description =
  535. qq|<td><textarea name="description_$i" rows="$rows" cols="40">$form->{"description_$i"}</textarea></td>|;
  536. }
  537. else {
  538. $description =
  539. qq|<td><input name="description_$i" size="40" value="$form->{"description_$i"}"></td>|;
  540. }
  541. print qq|
  542. <tr valign=top>
  543. <td><input name="amount_$i" size="10" value="$form->{"amount_$i"}" accesskey="$i"></td>
  544. <td></td>
  545. <td><select name="$form->{ARAP}_amount_$i">$selectamount</select></td>
  546. $description
  547. $project
  548. </tr>
  549. |;
  550. }
  551. foreach $item ( split / /, $form->{taxaccounts} ) {
  552. if($form->{"calctax_$item"} && $is_update){
  553. $form->{invtotal} += $form->{"tax_$item"};
  554. }
  555. $form->{"calctax_$item"} =
  556. ( $form->{"calctax_$item"} ) ? "checked" : "";
  557. $form->{"tax_$item"} =
  558. $form->format_amount( \%myconfig, $form->{"tax_$item"}, 2 );
  559. print qq|
  560. <tr>
  561. <td><input name="tax_$item" size="10" value="$form->{"tax_$item"}"></td>
  562. <td align="right"><input name="calctax_$item" class="checkbox" type="checkbox" value="1" $form->{"calctax_$item"}></td>
  563. <td><select name="$form->{ARAP}_tax_$item">
  564. <option value="$form->{ARAP}_tax_$item">$item--$form->{"${item}_description"}</option></select></td>
  565. </tr>
  566. |;
  567. $form->hide_form(
  568. "${item}_rate", "${item}_description",
  569. "${item}_taxnumber", "select$form->{ARAP}_tax_$item"
  570. );
  571. }
  572. $form->{invtotal} =
  573. $form->format_amount( \%myconfig, $form->{invtotal}, 2 );
  574. $form->hide_form( "oldinvtotal", "oldtotalpaid", "taxaccounts",
  575. "select$form->{ARAP}" );
  576. print qq|
  577. <tr>
  578. <th align="left">$form->{invtotal}</th>
  579. <td></td>
  580. <td><select name="$form->{ARAP}">$form->{"select$form->{ARAP}"}</select></td>
  581. </tr>
  582. <tr>
  583. <th align="right">| . $locale->text('Notes') . qq|</th>
  584. <td></td>
  585. <td colspan="3">$notes</td>
  586. </tr>
  587. </table>
  588. </td>
  589. </tr>
  590. <tr class="listheading">
  591. <th class="listheading">| . $locale->text('Payments') . qq|</th>
  592. </tr>
  593. <tr>
  594. <td>
  595. <table width="100%">
  596. |;
  597. if ( $form->{currency} eq $form->{defaultcurrency} ) {
  598. @column_index = qw(datepaid source memo paid ARAP_paid);
  599. }
  600. else {
  601. @column_index = qw(datepaid source memo paid exchangerate ARAP_paid);
  602. }
  603. $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
  604. $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
  605. $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
  606. $column_data{ARAP_paid} = "<th>" . $locale->text('Account') . "</th>";
  607. $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
  608. $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
  609. print "
  610. <tr>
  611. ";
  612. for (@column_index) { print "$column_data{$_}\n" }
  613. print "
  614. </tr>
  615. ";
  616. $form->{paidaccounts}++ if ( $form->{"paid_$form->{paidaccounts}"} );
  617. for $i ( 1 .. $form->{paidaccounts} ) {
  618. $form->hide_form("cleared_$i");
  619. print "
  620. <tr>
  621. ";
  622. $form->{"select$form->{ARAP}_paid_$i"} =
  623. $form->{"select$form->{ARAP}_paid"};
  624. $form->{"select$form->{ARAP}_paid_$i"} =~
  625. s/option>\Q$form->{"$form->{ARAP}_paid_$i"}\E/option selected>$form->{"$form->{ARAP}_paid_$i"}/;
  626. # format amounts
  627. $form->{"paid_$i"} =
  628. $form->format_amount( \%myconfig, $form->{"paid_$i"}, 2 );
  629. $form->{"exchangerate_$i"} =
  630. $form->format_amount( \%myconfig, $form->{"exchangerate_$i"} );
  631. $exchangerate = qq|&nbsp;|;
  632. if ( $form->{currency} ne $form->{defaultcurrency} ) {
  633. if ( $form->{"forex_$i"} ) {
  634. $form->hide_form("exchangerate_$i");
  635. $exchangerate = qq|$form->{"exchangerate_$i"}|;
  636. }
  637. else {
  638. $exchangerate =
  639. qq|<input name="exchangerate_$i" size="10" value=$form->{"exchangerate_$i"}>|;
  640. }
  641. }
  642. $form->hide_form("forex_$i");
  643. $column_data{paid} =
  644. qq|<td align="center"><input name="paid_$i" size="11" value="$form->{"paid_$i"}"></td>|;
  645. $column_data{ARAP_paid} =
  646. qq|<td align="center"><select name="$form->{ARAP}_paid_$i">$form->{"select$form->{ARAP}_paid_$i"}</select></td>|;
  647. $column_data{exchangerate} = qq|<td align="center">$exchangerate</td>|;
  648. $column_data{datepaid} =
  649. qq|<td align="center"><input name="datepaid_$i" size="11" value="$form->{"datepaid_$i"}"></td>|;
  650. $column_data{source} =
  651. qq|<td align="center"><input name="source_$i" size="11" value="$form->{"source_$i"}"></td>|;
  652. $column_data{memo} =
  653. qq|<td align="center"><input name="memo_$i" size="11" value="$form->{"memo_$i"}"></td>|;
  654. for (@column_index) { print qq|$column_data{$_}\n| }
  655. print "
  656. </tr>
  657. ";
  658. }
  659. $form->hide_form( "paidaccounts", "select$form->{ARAP}_paid" );
  660. print qq|
  661. </table>
  662. </td>
  663. </tr>
  664. <tr>
  665. <td><hr size="3" noshade></td>
  666. </tr>
  667. </table>
  668. |;
  669. }
  670. sub form_footer {
  671. $form->hide_form(qw(callback path login sessionid));
  672. $transdate = $form->datetonum( \%myconfig, $form->{transdate} );
  673. $closedto = $form->datetonum( \%myconfig, $form->{closedto} );
  674. # type=submit $locale->text('Update')
  675. # type=submit $locale->text('Print')
  676. # type=submit $locale->text('Post')
  677. # type=submit $locale->text('Print and Post')
  678. # type=submit $locale->text('Schedule')
  679. # type=submit $locale->text('Ship to')
  680. # type=submit $locale->text('Post as new')
  681. # type=submit $locale->text('Print and Post as new')
  682. # type=submit $locale->text('Delete')
  683. if ( !$form->{readonly} ) {
  684. &print_options;
  685. print "<br>";
  686. %button = (
  687. 'update' =>
  688. { ndx => 1, key => 'U', value => $locale->text('Update') },
  689. 'print' =>
  690. { ndx => 2, key => 'P', value => $locale->text('Print') },
  691. 'post' => { ndx => 3, key => 'O', value => $locale->text('Post') },
  692. 'print_and_post' => {
  693. ndx => 4,
  694. key => 'R',
  695. value => $locale->text('Print and Post')
  696. },
  697. 'post_as_new' =>
  698. { ndx => 5, key => 'N', value => $locale->text('Post as new') },
  699. 'print_and_post_as_new' => {
  700. ndx => 6,
  701. key => 'W',
  702. value => $locale->text('Print and Post as new')
  703. },
  704. 'schedule' =>
  705. { ndx => 7, key => 'H', value => $locale->text('Schedule') },
  706. 'delete' =>
  707. { ndx => 8, key => 'D', value => $locale->text('Delete') },
  708. );
  709. if ( $form->{id} ) {
  710. if ( $form->{locked} || ( $transdate && $transdate <= $closedto ) )
  711. {
  712. for ( "post", "print_and_post", "delete" ) {
  713. delete $button{$_};
  714. }
  715. }
  716. if ( !${LedgerSMB::Sysconfig::latex} ) {
  717. for ( "print_and_post", "print_and_post_as_new" ) {
  718. delete $button{$_};
  719. }
  720. }
  721. }
  722. else {
  723. for ( "post_as_new", "print_and_post_as_new", "delete" ) {
  724. delete $button{$_};
  725. }
  726. delete $button{"print_and_post"} if !${LedgerSMB::Sysconfig::latex};
  727. if ( $transdate && $transdate <= $closedto ) {
  728. for ( "post", "print_and_post" ) { delete $button{$_} }
  729. }
  730. }
  731. for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button )
  732. {
  733. $form->print_button( \%button, $_ );
  734. }
  735. }
  736. if ( $form->{lynx} ) {
  737. require "bin/menu.pl";
  738. &menubar;
  739. }
  740. print qq|
  741. </form>
  742. </body>
  743. </html>
  744. |;
  745. }
  746. sub update {
  747. my $display = shift;
  748. $is_update = 1;
  749. if ( !$display ) {
  750. $form->{invtotal} = 0;
  751. $form->{exchangerate} =
  752. $form->parse_amount( \%myconfig, $form->{exchangerate} );
  753. @flds =
  754. ( "amount", "$form->{ARAP}_amount", "projectnumber", "description" );
  755. $count = 0;
  756. @a = ();
  757. for $i ( 1 .. $form->{rowcount} ) {
  758. $form->{"amount_$i"} =
  759. $form->parse_amount( \%myconfig, $form->{"amount_$i"} );
  760. if ( $form->{"amount_$i"} ) {
  761. push @a, {};
  762. $j = $#a;
  763. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  764. $count++;
  765. }
  766. }
  767. $form->redo_rows( \@flds, \@a, $count, $form->{rowcount} );
  768. $form->{rowcount} = $count + 1;
  769. for ( 1 .. $form->{rowcount} ) {
  770. $form->{invtotal} += $form->{"amount_$_"};
  771. }
  772. $form->{exchangerate} = $exchangerate
  773. if (
  774. $form->{forex} = (
  775. $exchangerate = $form->check_exchangerate(
  776. \%myconfig, $form->{currency}, $form->{transdate},
  777. ( $form->{ARAP} eq 'AR' ) ? 'buy' : 'sell'
  778. )
  779. )
  780. );
  781. if ( $newname = &check_name( $form->{vc} ) ) {
  782. $form->{notes} = $form->{intnotes} unless $form->{id};
  783. &rebuild_vc( $form->{vc}, $form->{ARAP}, $form->{transdate} );
  784. }
  785. if ( $form->{transdate} ne $form->{oldtransdate} ) {
  786. $form->{duedate} =
  787. $form->current_date( \%myconfig, $form->{transdate},
  788. $form->{terms} * 1 );
  789. $form->{oldtransdate} = $form->{transdate};
  790. $newproj =
  791. &rebuild_vc( $form->{vc}, $form->{ARAP}, $form->{transdate} )
  792. if !$newname;
  793. $form->all_projects( \%myconfig, undef, $form->{transdate} )
  794. if !$newproj;
  795. $form->{selectemployee} = "";
  796. if ( @{ $form->{all_employee} } ) {
  797. for ( @{ $form->{all_employee} } ) {
  798. $form->{selectemployee} .=
  799. qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
  800. }
  801. }
  802. }
  803. }
  804. # recalculate taxes
  805. @taxaccounts = split / /, $form->{taxaccounts};
  806. for (@taxaccounts) {
  807. $form->{"tax_$_"} =
  808. $form->parse_amount( \%myconfig, $form->{"tax_$_"} );
  809. }
  810. @taxaccounts = Tax::init_taxes( $form, $form->{taxaccounts} );
  811. $j = 1;
  812. for $i ( 1 .. $form->{paidaccounts} ) {
  813. if ( $form->{"paid_$i"} ) {
  814. for (qw(datepaid source memo cleared)) {
  815. $form->{"${_}_$j"} = $form->{"${_}_$i"};
  816. }
  817. for (qw(paid exchangerate)) {
  818. $form->{"${_}_$j"} =
  819. $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
  820. }
  821. $totalpaid += $form->{"paid_$j"};
  822. $form->{"exchangerate_$j"} = $exchangerate
  823. if (
  824. $form->{"forex_$j"} = (
  825. $exchangerate = $form->check_exchangerate(
  826. \%myconfig, $form->{currency},
  827. $form->{"datepaid_$j"},
  828. ( $form->{ARAP} eq 'AR' ) ? 'buy' : 'sell'
  829. )
  830. )
  831. );
  832. if ( $j++ != $i ) {
  833. for (qw(datepaid source memo paid exchangerate forex cleared)) {
  834. delete $form->{"${_}_$i"};
  835. }
  836. }
  837. }
  838. else {
  839. for (qw(datepaid source memo paid exchangerate forex cleared)) {
  840. delete $form->{"${_}_$i"};
  841. }
  842. }
  843. }
  844. $form->{paidaccounts} = $j;
  845. $form->{creditremaining} -=
  846. ( $form->{invtotal} - $totalpaid + $form->{oldtotalpaid} -
  847. $form->{oldinvtotal} );
  848. $form->{oldinvtotal} = $form->{invtotal};
  849. $form->{oldtotalpaid} = $totalpaid;
  850. &display_form;
  851. }
  852. sub post {
  853. $label =
  854. ( $form->{vc} eq 'customer' )
  855. ? $locale->text('Customer missing!')
  856. : $locale->text('Vendor missing!');
  857. # check if there is an invoice number, invoice and due date
  858. $form->isblank( "transdate", $locale->text('Invoice Date missing!') );
  859. $form->isblank( "duedate", $locale->text('Due Date missing!') );
  860. $form->isblank( $form->{vc}, $label );
  861. $closedto = $form->datetonum( \%myconfig, $form->{closedto} );
  862. $transdate = $form->datetonum( \%myconfig, $form->{transdate} );
  863. $form->error(
  864. $locale->text('Cannot post transaction for a closed period!') )
  865. if ( $transdate <= $closedto );
  866. $form->isblank( "exchangerate", $locale->text('Exchange rate missing!') )
  867. if ( $form->{currency} ne $form->{defaultcurrency} );
  868. for $i ( 1 .. $form->{paidaccounts} ) {
  869. if ( $form->{"paid_$i"} ) {
  870. $datepaid = $form->datetonum( \%myconfig, $form->{"datepaid_$i"} );
  871. $form->isblank( "datepaid_$i",
  872. $locale->text('Payment date missing!') );
  873. $form->error(
  874. $locale->text('Cannot post payment for a closed period!') )
  875. if ( $datepaid <= $closedto );
  876. if ( $form->{currency} ne $form->{defaultcurrency} ) {
  877. $form->{"exchangerate_$i"} = $form->{exchangerate}
  878. if ( $transdate == $datepaid );
  879. $form->isblank( "exchangerate_$i",
  880. $locale->text('Exchange rate for payment missing!') );
  881. }
  882. }
  883. }
  884. # if oldname ne name redo form
  885. ($name) = split /--/, $form->{ $form->{vc} };
  886. if ( $form->{"old$form->{vc}"} ne qq|$name--$form->{"$form->{vc}_id"}| ) {
  887. &update;
  888. exit;
  889. }
  890. if ( !$form->{repost} ) {
  891. if ( $form->{id} ) {
  892. &repost;
  893. exit;
  894. }
  895. }
  896. if ( AA->post_transaction( \%myconfig, \%$form ) ) {
  897. $form->update_status( \%myconfig );
  898. if ( $form->{printandpost} ) {
  899. &{"print_$form->{formname}"}( $old_form, 1 );
  900. }
  901. $form->redirect( $locale->text('Transaction posted!') );
  902. }
  903. else {
  904. $form->error( $locale->text('Cannot post transaction!') );
  905. }
  906. }
  907. sub delete {
  908. $form->{title} = $locale->text('Confirm!');
  909. $form->header;
  910. print qq|
  911. <body>
  912. <form method="post" action="$form->{script}">
  913. |;
  914. $form->{action} = "yes";
  915. $form->hide_form;
  916. print qq|
  917. <h2 class="confirm">$form->{title}</h2>
  918. <h4>|
  919. . $locale->text('Are you sure you want to delete Transaction')
  920. . qq| $form->{invnumber}</h4>
  921. <button name="action" class="submit" type="submit" value="yes">|
  922. . $locale->text('Yes')
  923. . qq|</button>
  924. </form>
  925. </body>
  926. </html>
  927. |;
  928. }
  929. sub yes {
  930. if (
  931. AA->delete_transaction(
  932. \%myconfig, \%$form, ${LedgerSMB::Sysconfig::spool}
  933. )
  934. )
  935. {
  936. $form->redirect( $locale->text('Transaction deleted!') );
  937. }
  938. else {
  939. $form->error( $locale->text('Cannot delete transaction!') );
  940. }
  941. }
  942. sub search {
  943. $form->create_links( $form->{ARAP}, \%myconfig, $form->{vc} );
  944. $form->{"select$form->{ARAP}"} = "<option>\n";
  945. for ( @{ $form->{"$form->{ARAP}_links"}{ $form->{ARAP} } } ) {
  946. $form->{"select$form->{ARAP}"} .=
  947. "<option>$_->{accno}--$_->{description}\n";
  948. }
  949. if ( @{ $form->{"all_$form->{vc}"} } ) {
  950. $selectname = "";
  951. for ( @{ $form->{"all_$form->{vc}"} } ) {
  952. $selectname .=
  953. qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
  954. }
  955. $selectname =
  956. qq|<select name="$form->{vc}"><option>\n$selectname</select>|;
  957. }
  958. else {
  959. $selectname = qq|<input name="$form->{vc}" size="35">|;
  960. }
  961. # departments
  962. if ( @{ $form->{all_department} } ) {
  963. $form->{selectdepartment} = "<option>\n";
  964. for ( @{ $form->{all_department} } ) {
  965. $form->{selectdepartment} .=
  966. qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
  967. }
  968. $l_department =
  969. qq|<input name="l_department" class="checkbox" type="checkbox" value="Y"> |
  970. . $locale->text('Department');
  971. $department = qq|
  972. <tr>
  973. <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
  974. <td colspan="3"><select name="department">$form->{selectdepartment}</select></td>
  975. </tr>
  976. |;
  977. }
  978. if ( @{ $form->{all_employee} } ) {
  979. $form->{selectemployee} = "<option>\n";
  980. for ( @{ $form->{all_employee} } ) {
  981. $form->{selectemployee} .=
  982. qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
  983. }
  984. $employeelabel =
  985. ( $form->{ARAP} eq 'AR' )
  986. ? $locale->text('Salesperson')
  987. : $locale->text('Employee');
  988. $employee = qq|
  989. <tr>
  990. <th align="right" nowrap>$employeelabel</th>
  991. <td colspan="3"><select name="employee">$form->{selectemployee}</select></td>
  992. </tr>
  993. |;
  994. $l_employee =
  995. qq|<input name="l_employee" class="checkbox" type="checkbox" value=Y> $employeelabel|;
  996. $l_manager =
  997. qq|<input name="l_manager" class="checkbox" type="checkbox" value=Y> |
  998. . $locale->text('Manager');
  999. }
  1000. $form->{title} =
  1001. ( $form->{ARAP} eq 'AR' )
  1002. ? $locale->text('AR Transactions')
  1003. : $locale->text('AP Transactions');
  1004. $invnumber = qq|
  1005. <tr>
  1006. <th align="right" nowrap>| . $locale->text('Invoice Number') . qq|</th>
  1007. <td colspan="3"><input name="invnumber" size="20"></td>
  1008. </tr>
  1009. <tr>
  1010. <th align="right" nowrap>| . $locale->text('Order Number') . qq|</th>
  1011. <td colspan="3"><input name="ordnumber" size="20"></td>
  1012. </tr>
  1013. <tr>
  1014. <th align="right" nowrap>| . $locale->text('PO Number') . qq|</th>
  1015. <td colspan="3"><input name="ponumber" size="20"></td>
  1016. </tr>
  1017. <tr>
  1018. <th align="right" nowrap>| . $locale->text('Source') . qq|</th>
  1019. <td colspan="3"><input name="source" size="40"></td>
  1020. </tr>
  1021. <tr>
  1022. <th align="right" nowrap>| . $locale->text('Description') . qq|</th>
  1023. <td colspan="3"><input name="description" size="40"></td>
  1024. </tr>
  1025. <tr>
  1026. <th align="right" nowrap>| . $locale->text('Notes') . qq|</th>
  1027. <td colspan="3"><input name="notes" size="40"></td>
  1028. </tr>
  1029. |;
  1030. $openclosed = qq|
  1031. <tr>
  1032. <td nowrap><input name="open" class="checkbox" type="checkbox" value="Y" checked> |
  1033. . $locale->text('Open')
  1034. . qq|</td>
  1035. <td nowrap><input name="closed" class="checkbox" type="checkbox" value="Y"> |
  1036. . $locale->text('Closed')
  1037. . qq|</td>
  1038. </tr>
  1039. |;
  1040. $summary = qq|
  1041. <tr>
  1042. <td><input name="summary" type="radio" class="radio" value="1" checked> |
  1043. . $locale->text('Summary')
  1044. . qq|</td>
  1045. <td><input name=summary type="radio" class="radio" value="0"> |
  1046. . $locale->text('Detail') . qq|
  1047. </td>
  1048. </tr>
  1049. |;
  1050. if ( $form->{outstanding} ) {
  1051. $form->{title} =
  1052. ( $form->{ARAP} eq 'AR' )
  1053. ? $locale->text('AR Outstanding')
  1054. : $locale->text('AP Outstanding');
  1055. $invnumber = "";
  1056. $openclosed = "";
  1057. $summary = "";
  1058. }
  1059. if ( @{ $form->{all_years} } ) {
  1060. # accounting years
  1061. $form->{selectaccountingyear} = "<option>\n";
  1062. for ( @{ $form->{all_years} } ) {
  1063. $form->{selectaccountingyear} .= qq|<option>$_\n|;
  1064. }
  1065. $form->{selectaccountingmonth} = "<option>\n";
  1066. for ( sort keys %{ $form->{all_month} } ) {
  1067. $form->{selectaccountingmonth} .=
  1068. qq|<option value=$_>|
  1069. . $locale->text( $form->{all_month}{$_} ) . qq|\n|;
  1070. }
  1071. $selectfrom = qq|
  1072. <tr>
  1073. <th align="right">| . $locale->text('Period') . qq|</th>
  1074. <td colspan="3">
  1075. <select name="month">$form->{selectaccountingmonth}</select>
  1076. <select name="year">$form->{selectaccountingyear}</select>
  1077. <input name="interval" class="radio" type="radio" value="0" checked>&nbsp;|
  1078. . $locale->text('Current') . qq|
  1079. <input name="interval" class="radio" type="radio" value="1">&nbsp;|
  1080. . $locale->text('Month') . qq|
  1081. <input name="interval" class="radio" type="radio" value="3">&nbsp;|
  1082. . $locale->text('Quarter') . qq|
  1083. <input name="interval" class="radio" type="radio" value="12">&nbsp;|
  1084. . $locale->text('Year') . qq|
  1085. </td>
  1086. </tr>
  1087. |;
  1088. }
  1089. $name = $locale->text('Customer');
  1090. $l_name =
  1091. qq|<input name="l_name" class="checkbox" type="checkbox" value="Y" checked> $name|;
  1092. $l_till =
  1093. qq|<input name="l_till" class="checkbox" type="checkbox" value="Y"> |
  1094. . $locale->text('Till');
  1095. if ( $form->{vc} eq 'vendor' ) {
  1096. $name = $locale->text('Vendor');
  1097. $l_till = "";
  1098. $l_name =
  1099. qq|<input name="l_name" class="checkbox" type="checkbox" value="Y" checked> $name|;
  1100. }
  1101. @a = ();
  1102. push @a,
  1103. qq|<input name="l_runningnumber" class="checkbox" type="checkbox" value="Y"> |
  1104. . $locale->text('No.');
  1105. push @a, qq|<input name="l_id" class="checkbox" type="checkbox" value="Y"> |
  1106. . $locale->text('ID');
  1107. push @a,
  1108. qq|<input name="l_invnumber" class="checkbox" type="checkbox" value="Y" checked> |
  1109. . $locale->text('Invoice Number');
  1110. push @a,
  1111. qq|<input name="l_ordnumber" class="checkbox" type="checkbox" value="Y"> |
  1112. . $locale->text('Order Number');
  1113. push @a, qq|<input name="l_ponumber" class="checkbox" type="checkbox" value="Y"> |
  1114. . $locale->text('PO Number');
  1115. push @a,
  1116. qq|<input name="l_transdate" class="checkbox" type="checkbox" value="Y" checked> |
  1117. . $locale->text('Invoice Date');
  1118. push @a, $l_name;
  1119. push @a, $l_employee if $l_employee;
  1120. push @a, $l_manager if $l_employee;
  1121. push @a, $l_department if $l_department;
  1122. push @a,
  1123. qq|<input name="l_netamount" class="checkbox" type="checkbox" value="Y"> |
  1124. . $locale->text('Amount');
  1125. push @a, qq|<input name="l_tax" class="checkbox" type="checkbox" value="Y"> |
  1126. . $locale->text('Tax');
  1127. push @a,
  1128. qq|<input name="l_amount" class="checkbox" type="checkbox" value="Y" checked> |
  1129. . $locale->text('Total');
  1130. push @a, qq|<input name="l_curr" class="checkbox" type="checkbox" value="Y"> |
  1131. . $locale->text('Currency');
  1132. push @a, qq|<input name="l_datepaid" class="checkbox" type="checkbox" value="Y"> |
  1133. . $locale->text('Date Paid');
  1134. push @a,
  1135. qq|<input name="l_paid" class="checkbox" type="checkbox" value="Y" checked> |
  1136. . $locale->text('Paid');
  1137. push @a, qq|<input name="l_duedate" class="checkbox" type="checkbox" value="Y"> |
  1138. . $locale->text('Due Date');
  1139. push @a, qq|<input name="l_due" class="checkbox" type="checkbox" value="Y"> |
  1140. . $locale->text('Amount Due');
  1141. push @a, qq|<input name="l_notes" class="checkbox" type="checkbox" value="Y"> |
  1142. . $locale->text('Notes');
  1143. push @a, $l_till if $l_till;
  1144. push @a,
  1145. qq|<input name="l_shippingpoint" class="checkbox" type="checkbox" value="Y"> |
  1146. . $locale->text('Shipping Point');
  1147. push @a, qq|<input name="l_shipvia" class="checkbox" type="checkbox" value="Y"> |
  1148. . $locale->text('Ship via');
  1149. $form->header;
  1150. print qq|
  1151. <body>
  1152. <form method="post" action="$form->{script}">
  1153. <table width="100%">
  1154. <tr><th class="listtop">$form->{title}</th></tr>
  1155. <tr height="5"></tr>
  1156. <tr>
  1157. <td>
  1158. <table>
  1159. <tr>
  1160. <th align="right">| . $locale->text('Account') . qq|</th>
  1161. <td colspan="3"><select name="$form->{ARAP}">$form->{"select$form->{ARAP}"}</select></td>
  1162. </tr>
  1163. <tr>
  1164. <th align="right">$name</th>
  1165. <td colspan="3">$selectname</td>
  1166. </tr>
  1167. $employee
  1168. $department
  1169. $invnumber
  1170. <tr>
  1171. <th align="right">| . $locale->text('Ship via') . qq|</th>
  1172. <td colspan="3"><input name=shipvia size="40"></td>
  1173. </tr>
  1174. <tr>
  1175. <th align="right" nowrap>| . $locale->text('From') . qq|</th>
  1176. <td><input name="transdatefrom" size="11" title="$myconfig{dateformat}"></td>
  1177. <th align="right">| . $locale->text('To') . qq|</th>
  1178. <td><input name="transdateto" size="11" title="$myconfig{dateformat}"></td>
  1179. </tr>
  1180. $selectfrom
  1181. </table>
  1182. </td>
  1183. </tr>
  1184. <tr>
  1185. <td>
  1186. <table>
  1187. <tr>
  1188. <th align="right" nowrap>| . $locale->text('Include in Report') . qq|</th>
  1189. <td>
  1190. <table width="100%">
  1191. $openclosed
  1192. $summary
  1193. |;
  1194. $form->{sort} = "transdate";
  1195. $form->hide_form(qw(title outstanding sort));
  1196. while (@a) {
  1197. for ( 1 .. 5 ) {
  1198. print qq|<td nowrap>| . shift @a;
  1199. print qq|</td>\n|;
  1200. }
  1201. print qq|</tr>\n|;
  1202. }
  1203. print qq|
  1204. <tr>
  1205. <td nowrap><input name="l_subtotal" class="checkbox" type="checkbox" value="Y"> |
  1206. . $locale->text('Subtotal')
  1207. . qq|</td>
  1208. </tr>
  1209. </table>
  1210. </td>
  1211. </tr>
  1212. </table>
  1213. </td>
  1214. </tr>
  1215. <tr>
  1216. <td><hr size="3" noshade></td>
  1217. </tr>
  1218. </table>
  1219. <br>
  1220. <input type="hidden" name="action" value="continue">
  1221. <button class="submit" type="submit" name="action" value="continue">|
  1222. . $locale->text('Continue')
  1223. . qq|</button>|;
  1224. $form->hide_form(qw(nextsub path login sessionid));
  1225. print qq|
  1226. </form>
  1227. |;
  1228. if ( $form->{lynx} ) {
  1229. require "bin/menu.pl";
  1230. &menubar;
  1231. }
  1232. print qq|
  1233. </body>
  1234. </html>
  1235. |;
  1236. }
  1237. sub transactions {
  1238. if ( $form->{ $form->{vc} } ) {
  1239. $form->{ $form->{vc} } = $form->unescape( $form->{ $form->{vc} } );
  1240. ( $form->{ $form->{vc} }, $form->{"$form->{vc}_id"} ) =
  1241. split( /--/, $form->{ $form->{vc} } );
  1242. }
  1243. AA->transactions( \%myconfig, \%$form );
  1244. $href = "$form->{script}?action=transactions";
  1245. for (qw(direction oldsort till outstanding path login sessionid summary)) {
  1246. $href .= qq|&$_=$form->{$_}|;
  1247. }
  1248. $href .= "&title=" . $form->escape( $form->{title} );
  1249. $form->sort_order();
  1250. $callback = "$form->{script}?action=transactions";
  1251. for (qw(direction oldsort till outstanding path login sessionid summary)) {
  1252. $callback .= qq|&$_=$form->{$_}|;
  1253. }
  1254. $callback .= "&title=" . $form->escape( $form->{title}, 1 );
  1255. if ( $form->{ $form->{ARAP} } ) {
  1256. $callback .=
  1257. "&$form->{ARAP}=" . $form->escape( $form->{ $form->{ARAP} }, 1 );
  1258. $href .= "&$form->{ARAP}=" . $form->escape( $form->{ $form->{ARAP} } );
  1259. $form->{ $form->{ARAP} } =~ s/--/ /;
  1260. $option = $locale->text('Account') . " : $form->{$form->{ARAP}}";
  1261. }
  1262. if ( $form->{ $form->{vc} } ) {
  1263. $callback .=
  1264. "&$form->{vc}="
  1265. . $form->escape( $form->{ $form->{vc} }, 1 )
  1266. . qq|--$form->{"$form->{vc}_id"}|;
  1267. $href .=
  1268. "&$form->{vc}="
  1269. . $form->escape( $form->{ $form->{vc} } )
  1270. . qq|--$form->{"$form->{vc}_id"}|;
  1271. $option .= "\n<br>" if ($option);
  1272. $name =
  1273. ( $form->{vc} eq 'customer' )
  1274. ? $locale->text('Customer')
  1275. : $locale->text('Vendor');
  1276. $option .= "$name : $form->{$form->{vc}}";
  1277. }
  1278. if ( $form->{department} ) {
  1279. $callback .= "&department=" . $form->escape( $form->{department}, 1 );
  1280. $href .= "&department=" . $form->escape( $form->{department} );
  1281. ($department) = split /--/, $form->{department};
  1282. $option .= "\n<br>" if ($option);
  1283. $option .= $locale->text('Department') . " : $department";
  1284. }
  1285. if ( $form->{employee} ) {
  1286. $callback .= "&employee=" . $form->escape( $form->{employee}, 1 );
  1287. $href .= "&employee=" . $form->escape( $form->{employee} );
  1288. ($employee) = split /--/, $form->{employee};
  1289. $option .= "\n<br>" if ($option);
  1290. if ( $form->{ARAP} eq 'AR' ) {
  1291. $option .= $locale->text('Salesperson');
  1292. }
  1293. else {
  1294. $option .= $locale->text('Employee');
  1295. }
  1296. $option .= " : $employee";
  1297. }
  1298. if ( $form->{invnumber} ) {
  1299. $callback .= "&invnumber=" . $form->escape( $form->{invnumber}, 1 );
  1300. $href .= "&invnumber=" . $form->escape( $form->{invnumber} );
  1301. $option .= "\n<br>" if ($option);
  1302. $option .= $locale->text('Invoice Number') . " : $form->{invnumber}";
  1303. }
  1304. if ( $form->{ordnumber} ) {
  1305. $callback .= "&ordnumber=" . $form->escape( $form->{ordnumber}, 1 );
  1306. $href .= "&ordnumber=" . $form->escape( $form->{ordnumber} );
  1307. $option .= "\n<br>" if ($option);
  1308. $option .= $locale->text('Order Number') . " : $form->{ordnumber}";
  1309. }
  1310. if ( $form->{ponumber} ) {
  1311. $callback .= "&ponumber=" . $form->escape( $form->{ponumber}, 1 );
  1312. $href .= "&ponumber=" . $form->escape( $form->{ponumber} );
  1313. $option .= "\n<br>" if ($option);
  1314. $option .= $locale->text('PO Number') . " : $form->{ponumber}";
  1315. }
  1316. if ( $form->{source} ) {
  1317. $callback .= "&source=" . $form->escape( $form->{source}, 1 );
  1318. $href .= "&source=" . $form->escape( $form->{source} );
  1319. $option .= "\n<br>" if $option;
  1320. $option .= $locale->text('Source') . " : $form->{source}";
  1321. }
  1322. if ( $form->{description} ) {
  1323. $callback .= "&description=" . $form->escape( $form->{description}, 1 );
  1324. $href .= "&description=" . $form->escape( $form->{description} );
  1325. $option .= "\n<br>" if $option;
  1326. $option .= $locale->text('Description') . " : $form->{description}";
  1327. }
  1328. if ( $form->{notes} ) {
  1329. $callback .= "&notes=" . $form->escape( $form->{notes}, 1 );
  1330. $href .= "&notes=" . $form->escape( $form->{notes} );
  1331. $option .= "\n<br>" if $option;
  1332. $option .= $locale->text('Notes') . " : $form->{notes}";
  1333. }
  1334. if ( $form->{shipvia} ) {
  1335. $callback .= "&shipvia=" . $form->escape( $form->{shipvia}, 1 );
  1336. $href .= "&shipvia=" . $form->escape( $form->{shipvia} );
  1337. $option .= "\n<br>" if $option;
  1338. $option .= $locale->text('Ship via') . " : $form->{shipvia}";
  1339. }
  1340. if ( $form->{transdatefrom} ) {
  1341. $callback .= "&transdatefrom=$form->{transdatefrom}";
  1342. $href .= "&transdatefrom=$form->{transdatefrom}";
  1343. $option .= "\n<br>" if ($option);
  1344. $option .=
  1345. $locale->text('From') . "&nbsp;"
  1346. . $locale->date( \%myconfig, $form->{transdatefrom}, 1 );
  1347. }
  1348. if ( $form->{transdateto} ) {
  1349. $callback .= "&transdateto=$form->{transdateto}";
  1350. $href .= "&transdateto=$form->{transdateto}";
  1351. $option .= "\n<br>" if ($option);
  1352. $option .=
  1353. $locale->text( 'To [_1]',
  1354. $locale->date( \%myconfig, $form->{transdateto}, 1 ) );
  1355. }
  1356. if ( $form->{open} ) {
  1357. $callback .= "&open=$form->{open}";
  1358. $href .= "&open=$form->{open}";
  1359. $option .= "\n<br>" if ($option);
  1360. $option .= $locale->text('Open');
  1361. }
  1362. if ( $form->{closed} ) {
  1363. $callback .= "&closed=$form->{closed}";
  1364. $href .= "&closed=$form->{closed}";
  1365. $option .= "\n<br>" if ($option);
  1366. $option .= $locale->text('Closed');
  1367. }
  1368. @columns =
  1369. $form->sort_columns(
  1370. qw(transdate id invnumber ordnumber ponumber name netamount tax amount paid due curr datepaid duedate notes till employee manager shippingpoint shipvia department)
  1371. );
  1372. pop @columns if $form->{department};
  1373. unshift @columns, "runningnumber";
  1374. foreach $item (@columns) {
  1375. if ( $form->{"l_$item"} eq "Y" ) {
  1376. push @column_index, $item;
  1377. if ( $form->{l_curr} && $item =~ /(amount|tax|paid|due)/ ) {
  1378. push @column_index, "fx_$item";
  1379. }
  1380. # add column to href and callback
  1381. $callback .= "&l_$item=Y";
  1382. $href .= "&l_$item=Y";
  1383. }
  1384. }
  1385. if ( !$form->{summary} ) {
  1386. foreach $item (qw(source debit credit accno description projectnumber))
  1387. {
  1388. push @column_index, $item;
  1389. }
  1390. }
  1391. if ( $form->{l_subtotal} eq 'Y' ) {
  1392. $callback .= "&l_subtotal=Y";
  1393. $href .= "&l_subtotal=Y";
  1394. }
  1395. $employee =
  1396. ( $form->{ARAP} eq 'AR' )
  1397. ? $locale->text('Salesperson')
  1398. : $locale->text('Employee');
  1399. $name =
  1400. ( $form->{vc} eq 'customer' )
  1401. ? $locale->text('Customer')
  1402. : $locale->text('Vendor');
  1403. $column_header{runningnumber} = qq|<th class="listheading">&nbsp;</th>|;
  1404. $column_header{id} =
  1405. qq|<th><a class="listheading" href="$href&sort=id">|
  1406. . $locale->text('ID')
  1407. . "</a></th>";
  1408. $column_header{transdate} =
  1409. qq|<th><a class="listheading" href="$href&sort=transdate">|
  1410. . $locale->text('Date')
  1411. . "</a></th>";
  1412. $column_header{duedate} =
  1413. qq|<th><a class="listheading" href="$href&sort=duedate">|
  1414. . $locale->text('Due Date')
  1415. . "</a></th>";
  1416. $column_header{invnumber} =
  1417. qq|<th><a class="listheading" href="$href&sort=invnumber">|
  1418. . $locale->text('Invoice')
  1419. . "</a></th>";
  1420. $column_header{ordnumber} =
  1421. qq|<th><a class="listheading" href="$href&sort=ordnumber">|
  1422. . $locale->text('Order')
  1423. . "</a></th>";
  1424. $column_header{ponumber} =
  1425. qq|<th><a class="listheading" href="$href&sort=ponumber">|
  1426. . $locale->text('PO Number')
  1427. . "</a></th>";
  1428. $column_header{name} =
  1429. qq|<th><a class="listheading" href="$href&sort=name">$name</a></th>|;
  1430. $column_header{netamount} =
  1431. '<th class="listheading">' . $locale->text('Amount') . "</th>";
  1432. $column_header{tax} =
  1433. '<th class="listheading">' . $locale->text('Tax') . "</th>";
  1434. $column_header{amount} =
  1435. '<th class="listheading">' . $locale->text('Total') . "</th>";
  1436. $column_header{paid} =
  1437. '<th class="listheading">' . $locale->text('Paid') . "</th>";
  1438. $column_header{datepaid} =
  1439. qq|<th><a class="listheading" href="$href&sort=datepaid">|
  1440. . $locale->text('Date Paid')
  1441. . "</a></th>";
  1442. $column_header{due} =
  1443. '<th class="listheading">' . $locale->text('Amount Due') . "</th>";
  1444. $column_header{notes} =
  1445. '<th class="listheading">' . $locale->text('Notes') . "</th>";
  1446. $column_header{employee} =
  1447. qq|<th><a class="listheading" href="$href&sort=employee">$employee</th>|;
  1448. $column_header{manager} =
  1449. qq|<th><a class="listheading" href="$href&sort=manager">|
  1450. . $locale->text('Manager') . "</th>";
  1451. $column_header{till} =
  1452. qq|<th class="listheading"><a class="listheading" href="$href&sort=till">|
  1453. . $locale->text('Till') . "</th>";
  1454. $column_header{shippingpoint} =
  1455. qq|<th><a class="listheading" href="$href&sort=shippingpoint">|
  1456. . $locale->text('Shipping Point')
  1457. . "</a></th>";
  1458. $column_header{shipvia} =
  1459. qq|<th><a class="listheading" href="$href&sort=shipvia">|
  1460. . $locale->text('Ship via')
  1461. . "</a></th>";
  1462. $column_header{curr} =
  1463. qq|<th><a class="listheading" href="$href&sort=curr">|
  1464. . $locale->text('Curr')
  1465. . "</a></th>";
  1466. for (qw(amount tax netamount paid due)) {
  1467. $column_header{"fx_$_"} = "<th>&nbsp;</th>";
  1468. }
  1469. $column_header{department} =
  1470. qq|<th><a class="listheading" href="$href&sort=department">|
  1471. . $locale->text('Department')
  1472. . "</a></th>";
  1473. $column_header{accno} =
  1474. qq|<th><a class="listheading" href="$href&sort=accno">|
  1475. . $locale->text('Account')
  1476. . "</a></th>";
  1477. $column_header{source} =
  1478. qq|<th><a class="listheading" href="$href&sort=source">|
  1479. . $locale->text('Source')
  1480. . "</a></th>";
  1481. $column_header{debit} =
  1482. '<th class="listheading">' . $locale->text('Debit') . "</th>";
  1483. $column_header{credit} =
  1484. '<th class="listheading">' . $locale->text('Credit') . "</th>";
  1485. $column_header{projectnumber} =
  1486. qq|<th><a class="listheading" href="$href&sort=projectnumber">|
  1487. . $locale->text('Project')
  1488. . "</a></th>";
  1489. $column_header{description} =
  1490. qq|<th><a class="listheading" href="$href&sort=linedescription">|
  1491. . $locale->text('Description')
  1492. . "</a></th>";
  1493. $form->{title} =
  1494. ( $form->{title} ) ? $form->{title} : $locale->text('AR Transactions');
  1495. $form->header;
  1496. print qq|
  1497. <body>
  1498. <table width="100%">
  1499. <tr>
  1500. <th class="listtop">$form->{title}</th>
  1501. </tr>
  1502. <tr height="5"></tr>
  1503. <tr>
  1504. <td>$option</td>
  1505. </tr>
  1506. <tr>
  1507. <td>
  1508. <table width="100%">
  1509. <tr class="listheading">
  1510. |;
  1511. for (@column_index) { print "\n$column_header{$_}" }
  1512. print qq|
  1513. </tr>
  1514. |;
  1515. # add sort and escape callback, this one we use for the add sub
  1516. $form->{callback} = $callback .= "&sort=$form->{sort}";
  1517. # escape callback for href
  1518. $callback = $form->escape($callback);
  1519. # flip direction
  1520. $direction = ( $form->{direction} eq 'ASC' ) ? "ASC" : "DESC";
  1521. $href =~ s/&direction=(\w+)&/&direction=$direction&/;
  1522. if ( @{ $form->{transactions} } ) {
  1523. $sameitem = $form->{transactions}->[0]->{ $form->{sort} };
  1524. }
  1525. # sums and tax on reports by Antonio Gallardo
  1526. #
  1527. $i = 0;
  1528. foreach $ref ( @{ $form->{transactions} } ) {
  1529. $i++;
  1530. if ( $form->{l_subtotal} eq 'Y' ) {
  1531. if ( $sameitem ne $ref->{ $form->{sort} } ) {
  1532. &subtotal;
  1533. $sameitem = $ref->{ $form->{sort} };
  1534. }
  1535. }
  1536. if ( $form->{l_curr} ) {
  1537. for (qw(netamount amount paid)) {
  1538. $ref->{"fx_$_"} = $ref->{$_} / $ref->{exchangerate};
  1539. }
  1540. for (qw(netamount amount paid)) {
  1541. $column_data{"fx_$_"} = '<td align="right">'
  1542. . $form->format_amount( \%myconfig, $ref->{"fx_$_"}, 2,
  1543. "&nbsp;" )
  1544. . "</td>";
  1545. }
  1546. $column_data{fx_tax} = '<td align="right">'
  1547. . $form->format_amount( \%myconfig,
  1548. $ref->{fx_amount} - $ref->{fx_netamount},
  1549. 2, "&nbsp;" )
  1550. . "</td>";
  1551. $column_data{fx_due} = '<td align="right">'
  1552. . $form->format_amount( \%myconfig,
  1553. $ref->{fx_amount} - $ref->{fx_paid},
  1554. 2, "&nbsp;" )
  1555. . "</td>";
  1556. $subtotalfxnetamount += $ref->{fx_netamount};
  1557. $subtotalfxamount += $ref->{fx_amount};
  1558. $subtotalfxpaid += $ref->{fx_paid};
  1559. $totalfxnetamount += $ref->{fx_netamount};
  1560. $totalfxamount += $ref->{fx_amount};
  1561. $totalfxpaid += $ref->{fx_paid};
  1562. }
  1563. $column_data{runningnumber} = qq|<td align="right">$i</td>|;
  1564. for (qw(netamount amount paid debit credit)) {
  1565. $column_data{$_} =
  1566. '<td align="right">'
  1567. . $form->format_amount( \%myconfig, $ref->{$_}, 2, "&nbsp;" )
  1568. . "</td>";
  1569. }
  1570. $column_data{tax} = '<td align="right">'
  1571. . $form->format_amount( \%myconfig,
  1572. $ref->{amount} - $ref->{netamount},
  1573. 2, "&nbsp;" )
  1574. . "</td>";
  1575. $column_data{due} = '<td align="right">'
  1576. . $form->format_amount( \%myconfig, $ref->{amount} - $ref->{paid},
  1577. 2, "&nbsp;" )
  1578. . "</td>";
  1579. $subtotalnetamount += $ref->{netamount};
  1580. $subtotalamount += $ref->{amount};
  1581. $subtotalpaid += $ref->{paid};
  1582. $subtotaldebit += $ref->{debit};
  1583. $subtotalcredit += $ref->{credit};
  1584. $totalnetamount += $ref->{netamount};
  1585. $totalamount += $ref->{amount};
  1586. $totalpaid += $ref->{paid};
  1587. $totaldebit += $ref->{debit};
  1588. $totalcredit += $ref->{credit};
  1589. $module =
  1590. ( $ref->{invoice} )
  1591. ? ( $form->{ARAP} eq 'AR' ) ? "is.pl" : "ir.pl"
  1592. : $form->{script};
  1593. $module = ( $ref->{till} ) ? "ps.pl" : $module;
  1594. $column_data{invnumber} =
  1595. qq|<td><a href="$module?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback">$ref->{invnumber}&nbsp;</a></td>|;
  1596. for (qw(notes description)) { $ref->{$_} =~ s/\r?\n/<br>/g }
  1597. for (
  1598. qw(transdate datepaid duedate department ordnumber ponumber notes shippingpoint shipvia employee manager till source description projectnumber)
  1599. )
  1600. {
  1601. $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>";
  1602. }
  1603. for (qw(id curr)) { $column_data{$_} = "<td>$ref->{$_}</td>" }
  1604. $column_data{accno} =
  1605. qq|<td><a href="ca.pl?path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&action=list_transactions&accounttype=standard&accno=$ref->{accno}&fromdate=$form->{transdatefrom}&todate=$form->{transdateto}&sort=transdate&l_subtotal=$form->{l_subtotal}&prevreport=$callback">$ref->{accno}</a></td>|;
  1606. $column_data{name} =
  1607. qq|<td><a href="ct.pl?path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&action=edit&id=$ref->{"$form->{vc}_id"}&db=$form->{vc}&callback=$callback">$ref->{name}</a></td>|;
  1608. if ( $ref->{id} != $sameid ) {
  1609. $j++;
  1610. $j %= 2;
  1611. }
  1612. print qq|
  1613. <tr class="listrow$j">
  1614. |;
  1615. for (@column_index) { print "\n$column_data{$_}" }
  1616. print qq|
  1617. </tr>
  1618. |;
  1619. $sameid = $ref->{id};
  1620. }
  1621. if ( $form->{l_subtotal} eq 'Y' ) {
  1622. &subtotal;
  1623. $sameitem = $ref->{ $form->{sort} };
  1624. }
  1625. # print totals
  1626. print qq|
  1627. <tr class="listtotal">
  1628. |;
  1629. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  1630. $column_data{netamount} =
  1631. '<th class="listtotal" align="right">'
  1632. . $form->format_amount( \%myconfig, $totalnetamount, 2, "&nbsp;" )
  1633. . "</th>";
  1634. $column_data{tax} = '<th class="listtotal" align="right">'
  1635. . $form->format_amount( \%myconfig, $totalamount - $totalnetamount,
  1636. 2, "&nbsp;" )
  1637. . "</th>";
  1638. $column_data{amount} =
  1639. '<th class="listtotal" align="right">'
  1640. . $form->format_amount( \%myconfig, $totalamount, 2, "&nbsp;" ) . "</th>";
  1641. $column_data{paid} =
  1642. '<th class="listtotal" align="right">'
  1643. . $form->format_amount( \%myconfig, $totalpaid, 2, "&nbsp;" ) . "</th>";
  1644. $column_data{due} =
  1645. '<th class="listtotal" align="right">'
  1646. . $form->format_amount( \%myconfig, $totalamount - $totalpaid, 2,
  1647. "&nbsp;" )
  1648. . "</th>";
  1649. $column_data{debit} =
  1650. '<th class="listtotal" align="right">'
  1651. . $form->format_amount( \%myconfig, $totaldebit, 2, "&nbsp;" ) . "</th>";
  1652. $column_data{credit} =
  1653. '<th class="listtotal" align="right">'
  1654. . $form->format_amount( \%myconfig, $totalcredit, 2, "&nbsp;" ) . "</th>";
  1655. if ( $form->{l_curr} && $form->{sort} eq 'curr' && $form->{l_subtotal} ) {
  1656. $column_data{fx_netamount} =
  1657. '<th class="listtotal" align="right">'
  1658. . $form->format_amount( \%myconfig, $totalfxnetamount, 2, "&nbsp;" )
  1659. . "</th>";
  1660. $column_data{fx_tax} = '<th class="listtotal" align="right">'
  1661. . $form->format_amount( \%myconfig,
  1662. $totalfxamount - $totalfxnetamount,
  1663. 2, "&nbsp;" )
  1664. . "</th>";
  1665. $column_data{fx_amount} =
  1666. '<th class="listtotal" align="right">'
  1667. . $form->format_amount( \%myconfig, $totalfxamount, 2, "&nbsp;" )
  1668. . "</th>";
  1669. $column_data{fx_paid} =
  1670. '<th class="listtotal" align="right">'
  1671. . $form->format_amount( \%myconfig, $totalfxpaid, 2, "&nbsp;" )
  1672. . "</th>";
  1673. $column_data{fx_due} = '<th class="listtotal" align="right">'
  1674. . $form->format_amount( \%myconfig, $totalfxamount - $totalfxpaid,
  1675. 2, "&nbsp;" )
  1676. . "</th>";
  1677. }
  1678. for (@column_index) { print "\n$column_data{$_}" }
  1679. if ( $myconfig{acs} !~ /$form->{ARAP}--$form->{ARAP}/ ) {
  1680. $i = 1;
  1681. if ( $form->{ARAP} eq 'AR' ) {
  1682. $button{'AR--Add Transaction'}{code} =
  1683. qq|<button class="submit" type="submit" name="action" value="ar_transaction">|
  1684. . $locale->text('AR Transaction')
  1685. . qq|</button> |;
  1686. $button{'AR--Add Transaction'}{order} = $i++;
  1687. $button{'AR--Sales Invoice'}{code} =
  1688. qq|<button class="submit" type="submit" name="action" value="sales_invoice_">|
  1689. . $locale->text('Sales Invoice.')
  1690. . qq|</button> |;
  1691. $button{'AR--Sales Invoice'}{order} = $i++;
  1692. }
  1693. else {
  1694. $button{'AP--Add Transaction'}{code} =
  1695. qq|<button class="submit" type="submit" name="action" value="ap_transaction">|
  1696. . $locale->text('AP Transaction')
  1697. . qq|</button> |;
  1698. $button{'AP--Add Transaction'}{order} = $i++;
  1699. $button{'AP--Vendor Invoice'}{code} =
  1700. qq|<button class="submit" type="submit" name="action" value="vendor_invoice_">|
  1701. . $locale->text('Vendor Invoice.')
  1702. . qq|</button> |;
  1703. $button{'AP--Vendor Invoice'}{order} = $i++;
  1704. }
  1705. foreach $item ( split /;/, $myconfig{acs} ) {
  1706. delete $button{$item};
  1707. }
  1708. }
  1709. print qq|
  1710. </tr>
  1711. </table>
  1712. </td>
  1713. </tr>
  1714. <tr>
  1715. <td><hr size="3" noshade></td>
  1716. </tr>
  1717. </table>
  1718. <br>
  1719. <form method="post" action="$form->{script}">
  1720. |;
  1721. $form->hide_form(
  1722. "callback", "path", "login", "sessionid",
  1723. "$form->{vc}", "$form->{vc}_id"
  1724. );
  1725. if ( !$form->{till} ) {
  1726. foreach $item ( sort { $a->{order} <=> $b->{order} } %button ) {
  1727. print $item->{code};
  1728. }
  1729. }
  1730. if ( $form->{lynx} ) {
  1731. require "bin/menu.pl";
  1732. &menubar;
  1733. }
  1734. print qq|
  1735. </form>
  1736. </body>
  1737. </html>
  1738. |;
  1739. }
  1740. sub subtotal {
  1741. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  1742. $column_data{tax} = '<th class="listsubtotal" align="right">'
  1743. . $form->format_amount( \%myconfig, $subtotalamount - $subtotalnetamount,
  1744. 2, "&nbsp;" )
  1745. . "</th>";
  1746. $column_data{amount} =
  1747. '<th class="listsubtotal" align="right">'
  1748. . $form->format_amount( \%myconfig, $subtotalamount, 2, "&nbsp;" )
  1749. . "</th>";
  1750. $column_data{paid} =
  1751. '<th class="listsubtotal" align="right">'
  1752. . $form->format_amount( \%myconfig, $subtotalpaid, 2, "&nbsp;" )
  1753. . "</th>";
  1754. $column_data{due} = '<th class="listsubtotal" align="right">'
  1755. . $form->format_amount( \%myconfig, $subtotalamount - $subtotalpaid,
  1756. 2, "&nbsp;" )
  1757. . "</th>";
  1758. $column_data{debit} =
  1759. '<th class="listsubtotal" align="right">'
  1760. . $form->format_amount( \%myconfig, $subtotaldebit, 2, "&nbsp;" )
  1761. . "</th>";
  1762. $column_data{credit} =
  1763. '<th class="listsubtotal" align="right">'
  1764. . $form->format_amount( \%myconfig, $subtotalcredit, 2, "&nbsp;" )
  1765. . "</th>";
  1766. if ( $form->{l_curr} && $form->{sort} eq 'curr' && $form->{l_subtotal} ) {
  1767. $column_data{fx_tax} = '<th class="listsubtotal" align="right">'
  1768. . $form->format_amount( \%myconfig,
  1769. $subtotalfxamount - $subtotalfxnetamount,
  1770. 2, "&nbsp;" )
  1771. . "</th>";
  1772. $column_data{fx_amount} =
  1773. '<th class="listsubtotal" align="right">'
  1774. . $form->format_amount( \%myconfig, $subtotalfxamount, 2, "&nbsp;" )
  1775. . "</th>";
  1776. $column_data{fx_paid} =
  1777. '<th class="listsubtotal" align="right">'
  1778. . $form->format_amount( \%myconfig, $subtotalfxpaid, 2, "&nbsp;" )
  1779. . "</th>";
  1780. $column_data{fx_due} = '<th class="listsubtotal" align="right">'
  1781. . $form->format_amount( \%myconfig,
  1782. $subtotalfxmount - $subtotalfxpaid,
  1783. 2, "&nbsp;" )
  1784. . "</th>";
  1785. }
  1786. $subtotalnetamount = 0;
  1787. $subtotalamount = 0;
  1788. $subtotalpaid = 0;
  1789. $subtotaldebit = 0;
  1790. $subtotalcredit = 0;
  1791. $subtotalfxnetamount = 0;
  1792. $subtotalfxamount = 0;
  1793. $subtotalfxpaid = 0;
  1794. print '<tr class="listsubtotal">';
  1795. for (@column_index) { print "\n$column_data{$_}" }
  1796. print "
  1797. </tr>
  1798. ";
  1799. }