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