summaryrefslogtreecommitdiff
path: root/bin/aa.pl
blob: 7820af022500a72affd9fda5ead5b733649818de (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. if($form->{"calctax_$item"}){
  552. $form->{invtotal} += $form->{"tax_$item"};
  553. }
  554. $form->{"calctax_$item"} =
  555. ( $form->{"calctax_$item"} ) ? "checked" : "";
  556. $form->{"tax_$item"} =
  557. $form->format_amount( \%myconfig, $form->{"tax_$item"}, 2 );
  558. print qq|
  559. <tr>
  560. <td><input name="tax_$item" size="10" value="$form->{"tax_$item"}"></td>
  561. <td align="right"><input name="calctax_$item" class="checkbox" type="checkbox" value="1" $form->{"calctax_$item"}></td>
  562. <td><select name="$form->{ARAP}_tax_$item">
  563. <option value="$form->{ARAP}_tax_$item">$item--$form->{"${item}_description"}</option></select></td>
  564. </tr>
  565. |;
  566. $form->hide_form(
  567. "${item}_rate", "${item}_description",
  568. "${item}_taxnumber", "select$form->{ARAP}_tax_$item"
  569. );
  570. }
  571. $form->{invtotal} =
  572. $form->format_amount( \%myconfig, $form->{invtotal}, 2 );
  573. $form->hide_form( "oldinvtotal", "oldtotalpaid", "taxaccounts",
  574. "select$form->{ARAP}" );
  575. print qq|
  576. <tr>
  577. <th align="left">$form->{invtotal}</th>
  578. <td></td>
  579. <td><select name="$form->{ARAP}">$form->{"select$form->{ARAP}"}</select></td>
  580. </tr>
  581. <tr>
  582. <th align="right">| . $locale->text('Notes') . qq|</th>
  583. <td></td>
  584. <td colspan="3">$notes</td>
  585. </tr>
  586. </table>
  587. </td>
  588. </tr>
  589. <tr class="listheading">
  590. <th class="listheading">| . $locale->text('Payments') . qq|</th>
  591. </tr>
  592. <tr>
  593. <td>
  594. <table width="100%">
  595. |;
  596. if ( $form->{currency} eq $form->{defaultcurrency} ) {
  597. @column_index = qw(datepaid source memo paid ARAP_paid);
  598. }
  599. else {
  600. @column_index = qw(datepaid source memo paid exchangerate ARAP_paid);
  601. }
  602. $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
  603. $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
  604. $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
  605. $column_data{ARAP_paid} = "<th>" . $locale->text('Account') . "</th>";
  606. $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
  607. $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
  608. print "
  609. <tr>
  610. ";
  611. for (@column_index) { print "$column_data{$_}\n" }
  612. print "
  613. </tr>
  614. ";
  615. $form->{paidaccounts}++ if ( $form->{"paid_$form->{paidaccounts}"} );
  616. for $i ( 1 .. $form->{paidaccounts} ) {
  617. $form->hide_form("cleared_$i");
  618. print "
  619. <tr>
  620. ";
  621. $form->{"select$form->{ARAP}_paid_$i"} =
  622. $form->{"select$form->{ARAP}_paid"};
  623. $form->{"select$form->{ARAP}_paid_$i"} =~
  624. s/option>\Q$form->{"$form->{ARAP}_paid_$i"}\E/option selected>$form->{"$form->{ARAP}_paid_$i"}/;
  625. # format amounts
  626. $form->{"paid_$i"} =
  627. $form->format_amount( \%myconfig, $form->{"paid_$i"}, 2 );
  628. $form->{"exchangerate_$i"} =
  629. $form->format_amount( \%myconfig, $form->{"exchangerate_$i"} );
  630. $exchangerate = qq|&nbsp;|;
  631. if ( $form->{currency} ne $form->{defaultcurrency} ) {
  632. if ( $form->{"forex_$i"} ) {
  633. $form->hide_form("exchangerate_$i");
  634. $exchangerate = qq|$form->{"exchangerate_$i"}|;
  635. }
  636. else {
  637. $exchangerate =
  638. qq|<input name="exchangerate_$i" size="10" value=$form->{"exchangerate_$i"}>|;
  639. }
  640. }
  641. $form->hide_form("forex_$i");
  642. $column_data{paid} =
  643. qq|<td align="center"><input name="paid_$i" size="11" value="$form->{"paid_$i"}"></td>|;
  644. $column_data{ARAP_paid} =
  645. qq|<td align="center"><select name="$form->{ARAP}_paid_$i">$form->{"select$form->{ARAP}_paid_$i"}</select></td>|;
  646. $column_data{exchangerate} = qq|<td align="center">$exchangerate</td>|;
  647. $column_data{datepaid} =
  648. qq|<td align="center"><input name="datepaid_$i" size="11" value="$form->{"datepaid_$i"}"></td>|;
  649. $column_data{source} =
  650. qq|<td align="center"><input name="source_$i" size="11" value="$form->{"source_$i"}"></td>|;
  651. $column_data{memo} =
  652. qq|<td align="center"><input name="memo_$i" size="11" value="$form->{"memo_$i"}"></td>|;
  653. for (@column_index) { print qq|$column_data{$_}\n| }
  654. print "
  655. </tr>
  656. ";
  657. }
  658. $form->hide_form( "paidaccounts", "select$form->{ARAP}_paid" );
  659. print qq|
  660. </table>
  661. </td>
  662. </tr>
  663. <tr>
  664. <td><hr size="3" noshade></td>
  665. </tr>
  666. </table>
  667. |;
  668. }
  669. sub form_footer {
  670. $form->hide_form(qw(callback path login sessionid));
  671. $transdate = $form->datetonum( \%myconfig, $form->{transdate} );
  672. $closedto = $form->datetonum( \%myconfig, $form->{closedto} );
  673. # type=submit $locale->text('Update')
  674. # type=submit $locale->text('Print')
  675. # type=submit $locale->text('Post')
  676. # type=submit $locale->text('Print and Post')
  677. # type=submit $locale->text('Schedule')
  678. # type=submit $locale->text('Ship to')
  679. # type=submit $locale->text('Post as new')
  680. # type=submit $locale->text('Print and Post as new')
  681. # type=submit $locale->text('Delete')
  682. if ( !$form->{readonly} ) {
  683. &print_options;
  684. print "<br>";
  685. %button = (
  686. 'update' =>
  687. { ndx => 1, key => 'U', value => $locale->text('Update') },
  688. 'print' =>
  689. { ndx => 2, key => 'P', value => $locale->text('Print') },
  690. 'post' => { ndx => 3, key => 'O', value => $locale->text('Post') },
  691. 'print_and_post' => {
  692. ndx => 4,
  693. key => 'R',
  694. value => $locale->text('Print and Post')
  695. },
  696. 'post_as_new' =>
  697. { ndx => 5, key => 'N', value => $locale->text('Post as new') },
  698. 'print_and_post_as_new' => {
  699. ndx => 6,
  700. key => 'W',
  701. value => $locale->text('Print and Post as new')
  702. },
  703. 'schedule' =>
  704. { ndx => 7, key => 'H', value => $locale->text('Schedule') },
  705. 'delete' =>
  706. { ndx => 8, key => 'D', value => $locale->text('Delete') },
  707. );
  708. if ( $form->{id} ) {
  709. if ( $form->{locked} || ( $transdate && $transdate <= $closedto ) )
  710. {
  711. for ( "post", "print_and_post", "delete" ) {
  712. delete $button{$_};
  713. }
  714. }
  715. if ( !${LedgerSMB::Sysconfig::latex} ) {
  716. for ( "print_and_post", "print_and_post_as_new" ) {
  717. delete $button{$_};
  718. }
  719. }
  720. }
  721. else {
  722. for ( "post_as_new", "print_and_post_as_new", "delete" ) {
  723. delete $button{$_};
  724. }
  725. delete $button{"print_and_post"} if !${LedgerSMB::Sysconfig::latex};
  726. if ( $transdate && $transdate <= $closedto ) {
  727. for ( "post", "print_and_post" ) { delete $button{$_} }
  728. }
  729. }
  730. for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button )
  731. {
  732. $form->print_button( \%button, $_ );
  733. }
  734. }
  735. if ( $form->{lynx} ) {
  736. require "bin/menu.pl";
  737. &menubar;
  738. }
  739. print qq|
  740. </form>
  741. </body>
  742. </html>
  743. |;
  744. }
  745. sub update {
  746. my $display = shift;
  747. if ( !$display ) {
  748. $form->{invtotal} = 0;
  749. $form->{exchangerate} =
  750. $form->parse_amount( \%myconfig, $form->{exchangerate} );
  751. @flds =
  752. ( "amount", "$form->{ARAP}_amount", "projectnumber", "description" );
  753. $count = 0;
  754. @a = ();
  755. for $i ( 1 .. $form->{rowcount} ) {
  756. $form->{"amount_$i"} =
  757. $form->parse_amount( \%myconfig, $form->{"amount_$i"} );
  758. if ( $form->{"amount_$i"} ) {
  759. push @a, {};
  760. $j = $#a;
  761. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  762. $count++;
  763. }
  764. }
  765. $form->redo_rows( \@flds, \@a, $count, $form->{rowcount} );
  766. $form->{rowcount} = $count + 1;
  767. for ( 1 .. $form->{rowcount} ) {
  768. $form->{invtotal} += $form->{"amount_$_"};
  769. }
  770. $form->{exchangerate} = $exchangerate
  771. if (
  772. $form->{forex} = (
  773. $exchangerate = $form->check_exchangerate(
  774. \%myconfig, $form->{currency}, $form->{transdate},
  775. ( $form->{ARAP} eq 'AR' ) ? 'buy' : 'sell'
  776. )
  777. )
  778. );
  779. if ( $newname = &check_name( $form->{vc} ) ) {
  780. $form->{notes} = $form->{intnotes} unless $form->{id};
  781. &rebuild_vc( $form->{vc}, $form->{ARAP}, $form->{transdate} );
  782. }
  783. if ( $form->{transdate} ne $form->{oldtransdate} ) {
  784. $form->{duedate} =
  785. $form->current_date( \%myconfig, $form->{transdate},
  786. $form->{terms} * 1 );
  787. $form->{oldtransdate} = $form->{transdate};
  788. $newproj =
  789. &rebuild_vc( $form->{vc}, $form->{ARAP}, $form->{transdate} )
  790. if !$newname;
  791. $form->all_projects( \%myconfig, undef, $form->{transdate} )
  792. if !$newproj;
  793. $form->{selectemployee} = "";
  794. if ( @{ $form->{all_employee} } ) {
  795. for ( @{ $form->{all_employee} } ) {
  796. $form->{selectemployee} .=
  797. qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
  798. }
  799. }
  800. }
  801. }
  802. # recalculate taxes
  803. @taxaccounts = split / /, $form->{taxaccounts};
  804. for (@taxaccounts) {
  805. $form->{"tax_$_"} =
  806. $form->parse_amount( \%myconfig, $form->{"tax_$_"} );
  807. }
  808. @taxaccounts = Tax::init_taxes( $form, $form->{taxaccounts} );
  809. $j = 1;
  810. for $i ( 1 .. $form->{paidaccounts} ) {
  811. if ( $form->{"paid_$i"} ) {
  812. for (qw(datepaid source memo cleared)) {
  813. $form->{"${_}_$j"} = $form->{"${_}_$i"};
  814. }
  815. for (qw(paid exchangerate)) {
  816. $form->{"${_}_$j"} =
  817. $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
  818. }
  819. $totalpaid += $form->{"paid_$j"};
  820. $form->{"exchangerate_$j"} = $exchangerate
  821. if (
  822. $form->{"forex_$j"} = (
  823. $exchangerate = $form->check_exchangerate(
  824. \%myconfig, $form->{currency},
  825. $form->{"datepaid_$j"},
  826. ( $form->{ARAP} eq 'AR' ) ? 'buy' : 'sell'
  827. )
  828. )
  829. );
  830. if ( $j++ != $i ) {
  831. for (qw(datepaid source memo paid exchangerate forex cleared)) {
  832. delete $form->{"${_}_$i"};
  833. }
  834. }
  835. }
  836. else {
  837. for (qw(datepaid source memo paid exchangerate forex cleared)) {
  838. delete $form->{"${_}_$i"};
  839. }
  840. }
  841. }
  842. $form->{paidaccounts} = $j;
  843. $form->{creditremaining} -=
  844. ( $form->{invtotal} - $totalpaid + $form->{oldtotalpaid} -
  845. $form->{oldinvtotal} );
  846. $form->{oldinvtotal} = $form->{invtotal};
  847. $form->{oldtotalpaid} = $totalpaid;
  848. &display_form;
  849. }
  850. sub post {
  851. $label =
  852. ( $form->{vc} eq 'customer' )
  853. ? $locale->text('Customer missing!')
  854. : $locale->text('Vendor missing!');
  855. # check if there is an invoice number, invoice and due date
  856. $form->isblank( "transdate", $locale->text('Invoice Date missing!') );
  857. $form->isblank( "duedate", $locale->text('Due Date missing!') );
  858. $form->isblank( $form->{vc}, $label );
  859. $closedto = $form->datetonum( \%myconfig, $form->{closedto} );
  860. $transdate = $form->datetonum( \%myconfig, $form->{transdate} );
  861. $form->error(
  862. $locale->text('Cannot post transaction for a closed period!') )
  863. if ( $transdate <= $closedto );
  864. $form->isblank( "exchangerate", $locale->text('Exchange rate missing!') )
  865. if ( $form->{currency} ne $form->{defaultcurrency} );
  866. for $i ( 1 .. $form->{paidaccounts} ) {
  867. if ( $form->{"paid_$i"} ) {
  868. $datepaid = $form->datetonum( \%myconfig, $form->{"datepaid_$i"} );
  869. $form->isblank( "datepaid_$i",
  870. $locale->text('Payment date missing!') );
  871. $form->error(
  872. $locale->text('Cannot post payment for a closed period!') )
  873. if ( $datepaid <= $closedto );
  874. if ( $form->{currency} ne $form->{defaultcurrency} ) {
  875. $form->{"exchangerate_$i"} = $form->{exchangerate}
  876. if ( $transdate == $datepaid );
  877. $form->isblank( "exchangerate_$i",
  878. $locale->text('Exchange rate for payment missing!') );
  879. }
  880. }
  881. }
  882. # if oldname ne name redo form
  883. ($name) = split /--/, $form->{ $form->{vc} };
  884. if ( $form->{"old$form->{vc}"} ne qq|$name--$form->{"$form->{vc}_id"}| ) {
  885. &update;
  886. exit;
  887. }
  888. if ( !$form->{repost} ) {
  889. if ( $form->{id} ) {
  890. &repost;
  891. exit;
  892. }
  893. }
  894. if ( AA->post_transaction( \%myconfig, \%$form ) ) {
  895. $form->update_status( \%myconfig );
  896. if ( $form->{printandpost} ) {
  897. &{"print_$form->{formname}"}( $old_form, 1 );
  898. }
  899. $form->redirect( $locale->text('Transaction posted!') );
  900. }
  901. else {
  902. $form->error( $locale->text('Cannot post transaction!') );
  903. }
  904. }
  905. sub delete {
  906. $form->{title} = $locale->text('Confirm!');
  907. $form->header;
  908. print qq|
  909. <body>
  910. <form method="post" action="$form->{script}">
  911. |;
  912. $form->{action} = "yes";
  913. $form->hide_form;
  914. print qq|
  915. <h2 class="confirm">$form->{title}</h2>
  916. <h4>|
  917. . $locale->text('Are you sure you want to delete Transaction')
  918. . qq| $form->{invnumber}</h4>
  919. <button name="action" class="submit" type="submit" value="yes">|
  920. . $locale->text('Yes')
  921. . qq|</button>
  922. </form>
  923. </body>
  924. </html>
  925. |;
  926. }
  927. sub yes {
  928. if (
  929. AA->delete_transaction(
  930. \%myconfig, \%$form, ${LedgerSMB::Sysconfig::spool}
  931. )
  932. )
  933. {
  934. $form->redirect( $locale->text('Transaction deleted!') );
  935. }
  936. else {
  937. $form->error( $locale->text('Cannot delete transaction!') );
  938. }
  939. }
  940. sub search {
  941. $form->create_links( $form->{ARAP}, \%myconfig, $form->{vc} );
  942. $form->{"select$form->{ARAP}"} = "<option>\n";
  943. for ( @{ $form->{"$form->{ARAP}_links"}{ $form->{ARAP} } } ) {
  944. $form->{"select$form->{ARAP}"} .=
  945. "<option>$_->{accno}--$_->{description}\n";
  946. }
  947. if ( @{ $form->{"all_$form->{vc}"} } ) {
  948. $selectname = "";
  949. for ( @{ $form->{"all_$form->{vc}"} } ) {
  950. $selectname .=
  951. qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
  952. }
  953. $selectname =
  954. qq|<select name="$form->{vc}"><option>\n$selectname</select>|;
  955. }
  956. else {
  957. $selectname = qq|<input name="$form->{vc}" size="35">|;
  958. }
  959. # departments
  960. if ( @{ $form->{all_department} } ) {
  961. $form->{selectdepartment} = "<option>\n";
  962. for ( @{ $form->{all_department} } ) {
  963. $form->{selectdepartment} .=
  964. qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
  965. }
  966. $l_department =
  967. qq|<input name="l_department" class="checkbox" type="checkbox" value="Y"> |
  968. . $locale->text('Department');
  969. $department = qq|
  970. <tr>
  971. <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
  972. <td colspan="3"><select name="department">$form->{selectdepartment}</select></td>
  973. </tr>
  974. |;
  975. }
  976. if ( @{ $form->{all_employee} } ) {
  977. $form->{selectemployee} = "<option>\n";
  978. for ( @{ $form->{all_employee} } ) {
  979. $form->{selectemployee} .=
  980. qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
  981. }
  982. $employeelabel =
  983. ( $form->{ARAP} eq 'AR' )
  984. ? $locale->text('Salesperson')
  985. : $locale->text('Employee');
  986. $employee = qq|
  987. <tr>
  988. <th align="right" nowrap>$employeelabel</th>
  989. <td colspan="3"><select name="employee">$form->{selectemployee}</select></td>
  990. </tr>
  991. |;
  992. $l_employee =
  993. qq|<input name="l_employee" class="checkbox" type="checkbox" value=Y> $employeelabel|;
  994. $l_manager =
  995. qq|<input name="l_manager" class="checkbox" type="checkbox" value=Y> |
  996. . $locale->text('Manager');
  997. }
  998. $form->{title} =
  999. ( $form->{ARAP} eq 'AR' )
  1000. ? $locale->text('AR Transactions')
  1001. : $locale->text('AP Transactions');
  1002. $invnumber = qq|
  1003. <tr>
  1004. <th align="right" nowrap>| . $locale->text('Invoice Number') . qq|</th>
  1005. <td colspan="3"><input name="invnumber" size="20"></td>
  1006. </tr>
  1007. <tr>
  1008. <th align="right" nowrap>| . $locale->text('Order Number') . qq|</th>
  1009. <td colspan="3"><input name="ordnumber" size="20"></td>
  1010. </tr>
  1011. <tr>
  1012. <th align="right" nowrap>| . $locale->text('PO Number') . qq|</th>
  1013. <td colspan="3"><input name="ponumber" size="20"></td>
  1014. </tr>
  1015. <tr>
  1016. <th align="right" nowrap>| . $locale->text('Source') . qq|</th>
  1017. <td colspan="3"><input name="source" size="40"></td>
  1018. </tr>
  1019. <tr>
  1020. <th align="right" nowrap>| . $locale->text('Description') . qq|</th>
  1021. <td colspan="3"><input name="description" size="40"></td>
  1022. </tr>
  1023. <tr>
  1024. <th align="right" nowrap>| . $locale->text('Notes') . qq|</th>
  1025. <td colspan="3"><input name="notes" size="40"></td>
  1026. </tr>
  1027. |;
  1028. $openclosed = qq|
  1029. <tr>
  1030. <td nowrap><input name="open" class="checkbox" type="checkbox" value="Y" checked> |
  1031. . $locale->text('Open')
  1032. . qq|</td>
  1033. <td nowrap><input name="closed" class="checkbox" type="checkbox" value="Y"> |
  1034. . $locale->text('Closed')
  1035. . qq|</td>
  1036. </tr>
  1037. |;
  1038. $summary = qq|
  1039. <tr>
  1040. <td><input name="summary" type="radio" class="radio" value="1" checked> |
  1041. . $locale->text('Summary')
  1042. . qq|</td>
  1043. <td><input name=summary type="radio" class="radio" value="0"> |
  1044. . $locale->text('Detail') . qq|
  1045. </td>
  1046. </tr>
  1047. |;
  1048. if ( $form->{outstanding} ) {
  1049. $form->{title} =
  1050. ( $form->{ARAP} eq 'AR' )
  1051. ? $locale->text('AR Outstanding')
  1052. : $locale->text('AP Outstanding');
  1053. $invnumber = "";
  1054. $openclosed = "";
  1055. $summary = "";
  1056. }
  1057. if ( @{ $form->{all_years} } ) {
  1058. # accounting years
  1059. $form->{selectaccountingyear} = "<option>\n";
  1060. for ( @{ $form->{all_years} } ) {
  1061. $form->{selectaccountingyear} .= qq|<option>$_\n|;
  1062. }
  1063. $form->{selectaccountingmonth} = "<option>\n";
  1064. for ( sort keys %{ $form->{all_month} } ) {
  1065. $form->{selectaccountingmonth} .=
  1066. qq|<option value=$_>|
  1067. . $locale->text( $form->{all_month}{$_} ) . qq|\n|;
  1068. }
  1069. $selectfrom = qq|
  1070. <tr>
  1071. <th align="right">| . $locale->text('Period') . qq|</th>
  1072. <td colspan="3">
  1073. <select name="month">$form->{selectaccountingmonth}</select>
  1074. <select name="year">$form->{selectaccountingyear}</select>
  1075. <input name="interval" class="radio" type="radio" value="0" checked>&nbsp;|
  1076. . $locale->text('Current') . qq|
  1077. <input name="interval" class="radio" type="radio" value="1">&nbsp;|
  1078. . $locale->text('Month') . qq|
  1079. <input name="interval" class="radio" type="radio" value="3">&nbsp;|
  1080. . $locale->text('Quarter') . qq|
  1081. <input name="interval" class="radio" type="radio" value="12">&nbsp;|
  1082. . $locale->text('Year') . qq|
  1083. </td>
  1084. </tr>
  1085. |;
  1086. }
  1087. $name = $locale->text('Customer');
  1088. $l_name =
  1089. qq|<input name="l_name" class="checkbox" type="checkbox" value="Y" checked> $name|;
  1090. $l_till =
  1091. qq|<input name="l_till" class="checkbox" type="checkbox" value="Y"> |
  1092. . $locale->text('Till');
  1093. if ( $form->{vc} eq 'vendor' ) {
  1094. $name = $locale->text('Vendor');
  1095. $l_till = "";
  1096. $l_name =
  1097. qq|<input name="l_name" class="checkbox" type="checkbox" value="Y" checked> $name|;
  1098. }
  1099. @a = ();
  1100. push @a,
  1101. qq|<input name="l_runningnumber" class="checkbox" type="checkbox" value="Y"> |
  1102. . $locale->text('No.');
  1103. push @a, qq|<input name="l_id" class="checkbox" type="checkbox" value="Y"> |
  1104. . $locale->text('ID');
  1105. push @a,
  1106. qq|<input name="l_invnumber" class="checkbox" type="checkbox" value="Y" checked> |
  1107. . $locale->text('Invoice Number');
  1108. push @a,
  1109. qq|<input name="l_ordnumber" class="checkbox" type="checkbox" value="Y"> |
  1110. . $locale->text('Order Number');
  1111. push @a, qq|<input name="l_ponumber" class="checkbox" type="checkbox" value="Y"> |
  1112. . $locale->text('PO Number');
  1113. push @a,
  1114. qq|<input name="l_transdate" class="checkbox" type="checkbox" value="Y" checked> |
  1115. . $locale->text('Invoice Date');
  1116. push @a, $l_name;
  1117. push @a, $l_employee if $l_employee;
  1118. push @a, $l_manager if $l_employee;
  1119. push @a, $l_department if $l_department;
  1120. push @a,
  1121. qq|<input name="l_netamount" class="checkbox" type="checkbox" value="Y"> |
  1122. . $locale->text('Amount');
  1123. push @a, qq|<input name="l_tax" class="checkbox" type="checkbox" value="Y"> |
  1124. . $locale->text('Tax');
  1125. push @a,
  1126. qq|<input name="l_amount" class="checkbox" type="checkbox" value="Y" checked> |
  1127. . $locale->text('Total');
  1128. push @a, qq|<input name="l_curr" class="checkbox" type="checkbox" value="Y"> |
  1129. . $locale->text('Currency');
  1130. push @a, qq|<input name="l_datepaid" class="checkbox" type="checkbox" value="Y"> |
  1131. . $locale->text('Date Paid');
  1132. push @a,
  1133. qq|<input name="l_paid" class="checkbox" type="checkbox" value="Y" checked> |
  1134. . $locale->text('Paid');
  1135. push @a, qq|<input name="l_duedate" class="checkbox" type="checkbox" value="Y"> |
  1136. . $locale->text('Due Date');
  1137. push @a, qq|<input name="l_due" class="checkbox" type="checkbox" value="Y"> |
  1138. . $locale->text('Amount Due');
  1139. push @a, qq|<input name="l_notes" class="checkbox" type="checkbox" value="Y"> |
  1140. . $locale->text('Notes');
  1141. push @a, $l_till if $l_till;
  1142. push @a,
  1143. qq|<input name="l_shippingpoint" class="checkbox" type="checkbox" value="Y"> |
  1144. . $locale->text('Shipping Point');
  1145. push @a, qq|<input name="l_shipvia" class="checkbox" type="checkbox" value="Y"> |
  1146. . $locale->text('Ship via');
  1147. $form->header;
  1148. print qq|
  1149. <body>
  1150. <form method="post" action="$form->{script}">
  1151. <table width="100%">
  1152. <tr><th class="listtop">$form->{title}</th></tr>
  1153. <tr height="5"></tr>
  1154. <tr>
  1155. <td>
  1156. <table>
  1157. <tr>
  1158. <th align="right">| . $locale->text('Account') . qq|</th>
  1159. <td colspan="3"><select name="$form->{ARAP}">$form->{"select$form->{ARAP}"}</select></td>
  1160. </tr>
  1161. <tr>
  1162. <th align="right">$name</th>
  1163. <td colspan="3">$selectname</td>
  1164. </tr>
  1165. $employee
  1166. $department
  1167. $invnumber
  1168. <tr>
  1169. <th align="right">| . $locale->text('Ship via') . qq|</th>
  1170. <td colspan="3"><input name=shipvia size="40"></td>
  1171. </tr>
  1172. <tr>
  1173. <th align="right" nowrap>| . $locale->text('From') . qq|</th>
  1174. <td><input name="transdatefrom" size="11" title="$myconfig{dateformat}"></td>
  1175. <th align="right">| . $locale->text('To') . qq|</th>
  1176. <td><input name="transdateto" size="11" title="$myconfig{dateformat}"></td>
  1177. </tr>
  1178. $selectfrom
  1179. </table>
  1180. </td>
  1181. </tr>
  1182. <tr>
  1183. <td>
  1184. <table>
  1185. <tr>
  1186. <th align="right" nowrap>| . $locale->text('Include in Report') . qq|</th>
  1187. <td>
  1188. <table width="100%">
  1189. $openclosed
  1190. $summary
  1191. |;
  1192. $form->{sort} = "transdate";
  1193. $form->hide_form(qw(title outstanding sort));
  1194. while (@a) {
  1195. for ( 1 .. 5 ) {
  1196. print qq|<td nowrap>| . shift @a;
  1197. print qq|</td>\n|;
  1198. }
  1199. print qq|</tr>\n|;
  1200. }
  1201. print qq|
  1202. <tr>
  1203. <td nowrap><input name="l_subtotal" class="checkbox" type="checkbox" value="Y"> |
  1204. . $locale->text('Subtotal')
  1205. . qq|</td>
  1206. </tr>
  1207. </table>
  1208. </td>
  1209. </tr>
  1210. </table>
  1211. </td>
  1212. </tr>
  1213. <tr>
  1214. <td><hr size="3" noshade></td>
  1215. </tr>
  1216. </table>
  1217. <br>
  1218. <input type="hidden" name="action" value="continue">
  1219. <button class="submit" type="submit" name="action" value="continue">|
  1220. . $locale->text('Continue')
  1221. . qq|</button>|;
  1222. $form->hide_form(qw(nextsub path login sessionid));
  1223. print qq|
  1224. </form>
  1225. |;
  1226. if ( $form->{lynx} ) {
  1227. require "bin/menu.pl";
  1228. &menubar;
  1229. }
  1230. print qq|
  1231. </body>
  1232. </html>
  1233. |;
  1234. }
  1235. sub transactions {
  1236. if ( $form->{ $form->{vc} } ) {
  1237. $form->{ $form->{vc} } = $form->unescape( $form->{ $form->{vc} } );
  1238. ( $form->{ $form->{vc} }, $form->{"$form->{vc}_id"} ) =
  1239. split( /--/, $form->{ $form->{vc} } );
  1240. }
  1241. AA->transactions( \%myconfig, \%$form );
  1242. $href = "$form->{script}?action=transactions";
  1243. for (qw(direction oldsort till outstanding path login sessionid summary)) {
  1244. $href .= qq|&$_=$form->{$_}|;
  1245. }
  1246. $href .= "&title=" . $form->escape( $form->{title} );
  1247. $form->sort_order();
  1248. $callback = "$form->{script}?action=transactions";
  1249. for (qw(direction oldsort till outstanding path login sessionid summary)) {
  1250. $callback .= qq|&$_=$form->{$_}|;
  1251. }
  1252. $callback .= "&title=" . $form->escape( $form->{title}, 1 );
  1253. if ( $form->{ $form->{ARAP} } ) {
  1254. $callback .=
  1255. "&$form->{ARAP}=" . $form->escape( $form->{ $form->{ARAP} }, 1 );
  1256. $href .= "&$form->{ARAP}=" . $form->escape( $form->{ $form->{ARAP} } );
  1257. $form->{ $form->{ARAP} } =~ s/--/ /;
  1258. $option = $locale->text('Account') . " : $form->{$form->{ARAP}}";
  1259. }
  1260. if ( $form->{ $form->{vc} } ) {
  1261. $callback .=
  1262. "&$form->{vc}="
  1263. . $form->escape( $form->{ $form->{vc} }, 1 )
  1264. . qq|--$form->{"$form->{vc}_id"}|;
  1265. $href .=
  1266. "&$form->{vc}="
  1267. . $form->escape( $form->{ $form->{vc} } )
  1268. . qq|--$form->{"$form->{vc}_id"}|;
  1269. $option .= "\n<br>" if ($option);
  1270. $name =
  1271. ( $form->{vc} eq 'customer' )
  1272. ? $locale->text('Customer')
  1273. : $locale->text('Vendor');
  1274. $option .= "$name : $form->{$form->{vc}}";
  1275. }
  1276. if ( $form->{department} ) {
  1277. $callback .= "&department=" . $form->escape( $form->{department}, 1 );
  1278. $href .= "&department=" . $form->escape( $form->{department} );
  1279. ($department) = split /--/, $form->{department};
  1280. $option .= "\n<br>" if ($option);
  1281. $option .= $locale->text('Department') . " : $department";
  1282. }
  1283. if ( $form->{employee} ) {
  1284. $callback .= "&employee=" . $form->escape( $form->{employee}, 1 );
  1285. $href .= "&employee=" . $form->escape( $form->{employee} );
  1286. ($employee) = split /--/, $form->{employee};
  1287. $option .= "\n<br>" if ($option);
  1288. if ( $form->{ARAP} eq 'AR' ) {
  1289. $option .= $locale->text('Salesperson');
  1290. }
  1291. else {
  1292. $option .= $locale->text('Employee');
  1293. }
  1294. $option .= " : $employee";
  1295. }
  1296. if ( $form->{invnumber} ) {
  1297. $callback .= "&invnumber=" . $form->escape( $form->{invnumber}, 1 );
  1298. $href .= "&invnumber=" . $form->escape( $form->{invnumber} );
  1299. $option .= "\n<br>" if ($option);
  1300. $option .= $locale->text('Invoice Number') . " : $form->{invnumber}";
  1301. }
  1302. if ( $form->{ordnumber} ) {
  1303. $callback .= "&ordnumber=" . $form->escape( $form->{ordnumber}, 1 );
  1304. $href .= "&ordnumber=" . $form->escape( $form->{ordnumber} );
  1305. $option .= "\n<br>" if ($option);
  1306. $option .= $locale->text('Order Number') . " : $form->{ordnumber}";
  1307. }
  1308. if ( $form->{ponumber} ) {
  1309. $callback .= "&ponumber=" . $form->escape( $form->{ponumber}, 1 );
  1310. $href .= "&ponumber=" . $form->escape( $form->{ponumber} );
  1311. $option .= "\n<br>" if ($option);
  1312. $option .= $locale->text('PO Number') . " : $form->{ponumber}";
  1313. }
  1314. if ( $form->{source} ) {
  1315. $callback .= "&source=" . $form->escape( $form->{source}, 1 );
  1316. $href .= "&source=" . $form->escape( $form->{source} );
  1317. $option .= "\n<br>" if $option;
  1318. $option .= $locale->text('Source') . " : $form->{source}";
  1319. }
  1320. if ( $form->{description} ) {
  1321. $callback .= "&description=" . $form->escape( $form->{description}, 1 );
  1322. $href .= "&description=" . $form->escape( $form->{description} );
  1323. $option .= "\n<br>" if $option;
  1324. $option .= $locale->text('Description') . " : $form->{description}";
  1325. }
  1326. if ( $form->{notes} ) {
  1327. $callback .= "&notes=" . $form->escape( $form->{notes}, 1 );
  1328. $href .= "&notes=" . $form->escape( $form->{notes} );
  1329. $option .= "\n<br>" if $option;
  1330. $option .= $locale->text('Notes') . " : $form->{notes}";
  1331. }
  1332. if ( $form->{shipvia} ) {
  1333. $callback .= "&shipvia=" . $form->escape( $form->{shipvia}, 1 );
  1334. $href .= "&shipvia=" . $form->escape( $form->{shipvia} );
  1335. $option .= "\n<br>" if $option;
  1336. $option .= $locale->text('Ship via') . " : $form->{shipvia}";
  1337. }
  1338. if ( $form->{transdatefrom} ) {
  1339. $callback .= "&transdatefrom=$form->{transdatefrom}";
  1340. $href .= "&transdatefrom=$form->{transdatefrom}";
  1341. $option .= "\n<br>" if ($option);
  1342. $option .=
  1343. $locale->text('From') . "&nbsp;"
  1344. . $locale->date( \%myconfig, $form->{transdatefrom}, 1 );
  1345. }
  1346. if ( $form->{transdateto} ) {
  1347. $callback .= "&transdateto=$form->{transdateto}";
  1348. $href .= "&transdateto=$form->{transdateto}";
  1349. $option .= "\n<br>" if ($option);
  1350. $option .=
  1351. $locale->text( 'To [_1]',
  1352. $locale->date( \%myconfig, $form->{transdateto}, 1 ) );
  1353. }
  1354. if ( $form->{open} ) {
  1355. $callback .= "&open=$form->{open}";
  1356. $href .= "&open=$form->{open}";
  1357. $option .= "\n<br>" if ($option);
  1358. $option .= $locale->text('Open');
  1359. }
  1360. if ( $form->{closed} ) {
  1361. $callback .= "&closed=$form->{closed}";
  1362. $href .= "&closed=$form->{closed}";
  1363. $option .= "\n<br>" if ($option);
  1364. $option .= $locale->text('Closed');
  1365. }
  1366. @columns =
  1367. $form->sort_columns(
  1368. qw(transdate id invnumber ordnumber ponumber name netamount tax amount paid due curr datepaid duedate notes till employee manager shippingpoint shipvia department)
  1369. );
  1370. pop @columns if $form->{department};
  1371. unshift @columns, "runningnumber";
  1372. foreach $item (@columns) {
  1373. if ( $form->{"l_$item"} eq "Y" ) {
  1374. push @column_index, $item;
  1375. if ( $form->{l_curr} && $item =~ /(amount|tax|paid|due)/ ) {
  1376. push @column_index, "fx_$item";
  1377. }
  1378. # add column to href and callback
  1379. $callback .= "&l_$item=Y";
  1380. $href .= "&l_$item=Y";
  1381. }
  1382. }
  1383. if ( !$form->{summary} ) {
  1384. foreach $item (qw(source debit credit accno description projectnumber))
  1385. {
  1386. push @column_index, $item;
  1387. }
  1388. }
  1389. if ( $form->{l_subtotal} eq 'Y' ) {
  1390. $callback .= "&l_subtotal=Y";
  1391. $href .= "&l_subtotal=Y";
  1392. }
  1393. $employee =
  1394. ( $form->{ARAP} eq 'AR' )
  1395. ? $locale->text('Salesperson')
  1396. : $locale->text('Employee');
  1397. $name =
  1398. ( $form->{vc} eq 'customer' )
  1399. ? $locale->text('Customer')
  1400. : $locale->text('Vendor');
  1401. $column_header{runningnumber} = qq|<th class="listheading">&nbsp;</th>|;
  1402. $column_header{id} =
  1403. qq|<th><a class="listheading" href="$href&sort=id">|
  1404. . $locale->text('ID')
  1405. . "</a></th>";
  1406. $column_header{transdate} =
  1407. qq|<th><a class="listheading" href="$href&sort=transdate">|
  1408. . $locale->text('Date')
  1409. . "</a></th>";
  1410. $column_header{duedate} =
  1411. qq|<th><a class="listheading" href="$href&sort=duedate">|
  1412. . $locale->text('Due Date')
  1413. . "</a></th>";
  1414. $column_header{invnumber} =
  1415. qq|<th><a class="listheading" href="$href&sort=invnumber">|
  1416. . $locale->text('Invoice')
  1417. . "</a></th>";
  1418. $column_header{ordnumber} =
  1419. qq|<th><a class="listheading" href="$href&sort=ordnumber">|
  1420. . $locale->text('Order')
  1421. . "</a></th>";
  1422. $column_header{ponumber} =
  1423. qq|<th><a class="listheading" href="$href&sort=ponumber">|
  1424. . $locale->text('PO Number')
  1425. . "</a></th>";
  1426. $column_header{name} =
  1427. qq|<th><a class="listheading" href="$href&sort=name">$name</a></th>|;
  1428. $column_header{netamount} =
  1429. '<th class="listheading">' . $locale->text('Amount') . "</th>";
  1430. $column_header{tax} =
  1431. '<th class="listheading">' . $locale->text('Tax') . "</th>";
  1432. $column_header{amount} =
  1433. '<th class="listheading">' . $locale->text('Total') . "</th>";
  1434. $column_header{paid} =
  1435. '<th class="listheading">' . $locale->text('Paid') . "</th>";
  1436. $column_header{datepaid} =
  1437. qq|<th><a class="listheading" href="$href&sort=datepaid">|
  1438. . $locale->text('Date Paid')
  1439. . "</a></th>";
  1440. $column_header{due} =
  1441. '<th class="listheading">' . $locale->text('Amount Due') . "</th>";
  1442. $column_header{notes} =
  1443. '<th class="listheading">' . $locale->text('Notes') . "</th>";
  1444. $column_header{employee} =
  1445. qq|<th><a class="listheading" href="$href&sort=employee">$employee</th>|;
  1446. $column_header{manager} =
  1447. qq|<th><a class="listheading" href="$href&sort=manager">|
  1448. . $locale->text('Manager') . "</th>";
  1449. $column_header{till} =
  1450. qq|<th class="listheading"><a class="listheading" href="$href&sort=till">|
  1451. . $locale->text('Till') . "</th>";
  1452. $column_header{shippingpoint} =
  1453. qq|<th><a class="listheading" href="$href&sort=shippingpoint">|
  1454. . $locale->text('Shipping Point')
  1455. . "</a></th>";
  1456. $column_header{shipvia} =
  1457. qq|<th><a class="listheading" href="$href&sort=shipvia">|
  1458. . $locale->text('Ship via')
  1459. . "</a></th>";
  1460. $column_header{curr} =
  1461. qq|<th><a class="listheading" href="$href&sort=curr">|
  1462. . $locale->text('Curr')
  1463. . "</a></th>";
  1464. for (qw(amount tax netamount paid due)) {
  1465. $column_header{"fx_$_"} = "<th>&nbsp;</th>";
  1466. }
  1467. $column_header{department} =
  1468. qq|<th><a class="listheading" href="$href&sort=department">|
  1469. . $locale->text('Department')
  1470. . "</a></th>";
  1471. $column_header{accno} =
  1472. qq|<th><a class="listheading" href="$href&sort=accno">|
  1473. . $locale->text('Account')
  1474. . "</a></th>";
  1475. $column_header{source} =
  1476. qq|<th><a class="listheading" href="$href&sort=source">|
  1477. . $locale->text('Source')
  1478. . "</a></th>";
  1479. $column_header{debit} =
  1480. '<th class="listheading">' . $locale->text('Debit') . "</th>";
  1481. $column_header{credit} =
  1482. '<th class="listheading">' . $locale->text('Credit') . "</th>";
  1483. $column_header{projectnumber} =
  1484. qq|<th><a class="listheading" href="$href&sort=projectnumber">|
  1485. . $locale->text('Project')
  1486. . "</a></th>";
  1487. $column_header{description} =
  1488. qq|<th><a class="listheading" href="$href&sort=linedescription">|
  1489. . $locale->text('Description')
  1490. . "</a></th>";
  1491. $form->{title} =
  1492. ( $form->{title} ) ? $form->{title} : $locale->text('AR Transactions');
  1493. $form->header;
  1494. print qq|
  1495. <body>
  1496. <table width="100%">
  1497. <tr>
  1498. <th class="listtop">$form->{title}</th>
  1499. </tr>
  1500. <tr height="5"></tr>
  1501. <tr>
  1502. <td>$option</td>
  1503. </tr>
  1504. <tr>
  1505. <td>
  1506. <table width="100%">
  1507. <tr class="listheading">
  1508. |;
  1509. for (@column_index) { print "\n$column_header{$_}" }
  1510. print qq|
  1511. </tr>
  1512. |;
  1513. # add sort and escape callback, this one we use for the add sub
  1514. $form->{callback} = $callback .= "&sort=$form->{sort}";
  1515. # escape callback for href
  1516. $callback = $form->escape($callback);
  1517. # flip direction
  1518. $direction = ( $form->{direction} eq 'ASC' ) ? "ASC" : "DESC";
  1519. $href =~ s/&direction=(\w+)&/&direction=$direction&/;
  1520. if ( @{ $form->{transactions} } ) {
  1521. $sameitem = $form->{transactions}->[0]->{ $form->{sort} };
  1522. }
  1523. # sums and tax on reports by Antonio Gallardo
  1524. #
  1525. $i = 0;
  1526. foreach $ref ( @{ $form->{transactions} } ) {
  1527. $i++;
  1528. if ( $form->{l_subtotal} eq 'Y' ) {
  1529. if ( $sameitem ne $ref->{ $form->{sort} } ) {
  1530. &subtotal;
  1531. $sameitem = $ref->{ $form->{sort} };
  1532. }
  1533. }
  1534. if ( $form->{l_curr} ) {
  1535. for (qw(netamount amount paid)) {
  1536. $ref->{"fx_$_"} = $ref->{$_} / $ref->{exchangerate};
  1537. }
  1538. for (qw(netamount amount paid)) {
  1539. $column_data{"fx_$_"} = '<td align="right">'
  1540. . $form->format_amount( \%myconfig, $ref->{"fx_$_"}, 2,
  1541. "&nbsp;" )
  1542. . "</td>";
  1543. }
  1544. $column_data{fx_tax} = '<td align="right">'
  1545. . $form->format_amount( \%myconfig,
  1546. $ref->{fx_amount} - $ref->{fx_netamount},
  1547. 2, "&nbsp;" )
  1548. . "</td>";
  1549. $column_data{fx_due} = '<td align="right">'
  1550. . $form->format_amount( \%myconfig,
  1551. $ref->{fx_amount} - $ref->{fx_paid},
  1552. 2, "&nbsp;" )
  1553. . "</td>";
  1554. $subtotalfxnetamount += $ref->{fx_netamount};
  1555. $subtotalfxamount += $ref->{fx_amount};
  1556. $subtotalfxpaid += $ref->{fx_paid};
  1557. $totalfxnetamount += $ref->{fx_netamount};
  1558. $totalfxamount += $ref->{fx_amount};
  1559. $totalfxpaid += $ref->{fx_paid};
  1560. }
  1561. $column_data{runningnumber} = qq|<td align="right">$i</td>|;
  1562. for (qw(netamount amount paid debit credit)) {
  1563. $column_data{$_} =
  1564. '<td align="right">'
  1565. . $form->format_amount( \%myconfig, $ref->{$_}, 2, "&nbsp;" )
  1566. . "</td>";
  1567. }
  1568. $column_data{tax} = '<td align="right">'
  1569. . $form->format_amount( \%myconfig,
  1570. $ref->{amount} - $ref->{netamount},
  1571. 2, "&nbsp;" )
  1572. . "</td>";
  1573. $column_data{due} = '<td align="right">'
  1574. . $form->format_amount( \%myconfig, $ref->{amount} - $ref->{paid},
  1575. 2, "&nbsp;" )
  1576. . "</td>";
  1577. $subtotalnetamount += $ref->{netamount};
  1578. $subtotalamount += $ref->{amount};
  1579. $subtotalpaid += $ref->{paid};
  1580. $subtotaldebit += $ref->{debit};
  1581. $subtotalcredit += $ref->{credit};
  1582. $totalnetamount += $ref->{netamount};
  1583. $totalamount += $ref->{amount};
  1584. $totalpaid += $ref->{paid};
  1585. $totaldebit += $ref->{debit};
  1586. $totalcredit += $ref->{credit};
  1587. $module =
  1588. ( $ref->{invoice} )
  1589. ? ( $form->{ARAP} eq 'AR' ) ? "is.pl" : "ir.pl"
  1590. : $form->{script};
  1591. $module = ( $ref->{till} ) ? "ps.pl" : $module;
  1592. $column_data{invnumber} =
  1593. 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>|;
  1594. for (qw(notes description)) { $ref->{$_} =~ s/\r?\n/<br>/g }
  1595. for (
  1596. qw(transdate datepaid duedate department ordnumber ponumber notes shippingpoint shipvia employee manager till source description projectnumber)
  1597. )
  1598. {
  1599. $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>";
  1600. }
  1601. for (qw(id curr)) { $column_data{$_} = "<td>$ref->{$_}</td>" }
  1602. $column_data{accno} =
  1603. 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>|;
  1604. $column_data{name} =
  1605. 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>|;
  1606. if ( $ref->{id} != $sameid ) {
  1607. $j++;
  1608. $j %= 2;
  1609. }
  1610. print qq|
  1611. <tr class="listrow$j">
  1612. |;
  1613. for (@column_index) { print "\n$column_data{$_}" }
  1614. print qq|
  1615. </tr>
  1616. |;
  1617. $sameid = $ref->{id};
  1618. }
  1619. if ( $form->{l_subtotal} eq 'Y' ) {
  1620. &subtotal;
  1621. $sameitem = $ref->{ $form->{sort} };
  1622. }
  1623. # print totals
  1624. print qq|
  1625. <tr class="listtotal">
  1626. |;
  1627. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  1628. $column_data{netamount} =
  1629. '<th class="listtotal" align="right">'
  1630. . $form->format_amount( \%myconfig, $totalnetamount, 2, "&nbsp;" )
  1631. . "</th>";
  1632. $column_data{tax} = '<th class="listtotal" align="right">'
  1633. . $form->format_amount( \%myconfig, $totalamount - $totalnetamount,
  1634. 2, "&nbsp;" )
  1635. . "</th>";
  1636. $column_data{amount} =
  1637. '<th class="listtotal" align="right">'
  1638. . $form->format_amount( \%myconfig, $totalamount, 2, "&nbsp;" ) . "</th>";
  1639. $column_data{paid} =
  1640. '<th class="listtotal" align="right">'
  1641. . $form->format_amount( \%myconfig, $totalpaid, 2, "&nbsp;" ) . "</th>";
  1642. $column_data{due} =
  1643. '<th class="listtotal" align="right">'
  1644. . $form->format_amount( \%myconfig, $totalamount - $totalpaid, 2,
  1645. "&nbsp;" )
  1646. . "</th>";
  1647. $column_data{debit} =
  1648. '<th class="listtotal" align="right">'
  1649. . $form->format_amount( \%myconfig, $totaldebit, 2, "&nbsp;" ) . "</th>";
  1650. $column_data{credit} =
  1651. '<th class="listtotal" align="right">'
  1652. . $form->format_amount( \%myconfig, $totalcredit, 2, "&nbsp;" ) . "</th>";
  1653. if ( $form->{l_curr} && $form->{sort} eq 'curr' && $form->{l_subtotal} ) {
  1654. $column_data{fx_netamount} =
  1655. '<th class="listtotal" align="right">'
  1656. . $form->format_amount( \%myconfig, $totalfxnetamount, 2, "&nbsp;" )
  1657. . "</th>";
  1658. $column_data{fx_tax} = '<th class="listtotal" align="right">'
  1659. . $form->format_amount( \%myconfig,
  1660. $totalfxamount - $totalfxnetamount,
  1661. 2, "&nbsp;" )
  1662. . "</th>";
  1663. $column_data{fx_amount} =
  1664. '<th class="listtotal" align="right">'
  1665. . $form->format_amount( \%myconfig, $totalfxamount, 2, "&nbsp;" )
  1666. . "</th>";
  1667. $column_data{fx_paid} =
  1668. '<th class="listtotal" align="right">'
  1669. . $form->format_amount( \%myconfig, $totalfxpaid, 2, "&nbsp;" )
  1670. . "</th>";
  1671. $column_data{fx_due} = '<th class="listtotal" align="right">'
  1672. . $form->format_amount( \%myconfig, $totalfxamount - $totalfxpaid,
  1673. 2, "&nbsp;" )
  1674. . "</th>";
  1675. }
  1676. for (@column_index) { print "\n$column_data{$_}" }
  1677. if ( $myconfig{acs} !~ /$form->{ARAP}--$form->{ARAP}/ ) {
  1678. $i = 1;
  1679. if ( $form->{ARAP} eq 'AR' ) {
  1680. $button{'AR--Add Transaction'}{code} =
  1681. qq|<button class="submit" type="submit" name="action" value="ar_transaction">|
  1682. . $locale->text('AR Transaction')
  1683. . qq|</button> |;
  1684. $button{'AR--Add Transaction'}{order} = $i++;
  1685. $button{'AR--Sales Invoice'}{code} =
  1686. qq|<button class="submit" type="submit" name="action" value="sales_invoice_">|
  1687. . $locale->text('Sales Invoice.')
  1688. . qq|</button> |;
  1689. $button{'AR--Sales Invoice'}{order} = $i++;
  1690. }
  1691. else {
  1692. $button{'AP--Add Transaction'}{code} =
  1693. qq|<button class="submit" type="submit" name="action" value="ap_transaction">|
  1694. . $locale->text('AP Transaction')
  1695. . qq|</button> |;
  1696. $button{'AP--Add Transaction'}{order} = $i++;
  1697. $button{'AP--Vendor Invoice'}{code} =
  1698. qq|<button class="submit" type="submit" name="action" value="vendor_invoice_">|
  1699. . $locale->text('Vendor Invoice.')
  1700. . qq|</button> |;
  1701. $button{'AP--Vendor Invoice'}{order} = $i++;
  1702. }
  1703. foreach $item ( split /;/, $myconfig{acs} ) {
  1704. delete $button{$item};
  1705. }
  1706. }
  1707. print qq|
  1708. </tr>
  1709. </table>
  1710. </td>
  1711. </tr>
  1712. <tr>
  1713. <td><hr size="3" noshade></td>
  1714. </tr>
  1715. </table>
  1716. <br>
  1717. <form method="post" action="$form->{script}">
  1718. |;
  1719. $form->hide_form(
  1720. "callback", "path", "login", "sessionid",
  1721. "$form->{vc}", "$form->{vc}_id"
  1722. );
  1723. if ( !$form->{till} ) {
  1724. foreach $item ( sort { $a->{order} <=> $b->{order} } %button ) {
  1725. print $item->{code};
  1726. }
  1727. }
  1728. if ( $form->{lynx} ) {
  1729. require "bin/menu.pl";
  1730. &menubar;
  1731. }
  1732. print qq|
  1733. </form>
  1734. </body>
  1735. </html>
  1736. |;
  1737. }
  1738. sub subtotal {
  1739. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  1740. $column_data{tax} = '<th class="listsubtotal" align="right">'
  1741. . $form->format_amount( \%myconfig, $subtotalamount - $subtotalnetamount,
  1742. 2, "&nbsp;" )
  1743. . "</th>";
  1744. $column_data{amount} =
  1745. '<th class="listsubtotal" align="right">'
  1746. . $form->format_amount( \%myconfig, $subtotalamount, 2, "&nbsp;" )
  1747. . "</th>";
  1748. $column_data{paid} =
  1749. '<th class="listsubtotal" align="right">'
  1750. . $form->format_amount( \%myconfig, $subtotalpaid, 2, "&nbsp;" )
  1751. . "</th>";
  1752. $column_data{due} = '<th class="listsubtotal" align="right">'
  1753. . $form->format_amount( \%myconfig, $subtotalamount - $subtotalpaid,
  1754. 2, "&nbsp;" )
  1755. . "</th>";
  1756. $column_data{debit} =
  1757. '<th class="listsubtotal" align="right">'
  1758. . $form->format_amount( \%myconfig, $subtotaldebit, 2, "&nbsp;" )
  1759. . "</th>";
  1760. $column_data{credit} =
  1761. '<th class="listsubtotal" align="right">'
  1762. . $form->format_amount( \%myconfig, $subtotalcredit, 2, "&nbsp;" )
  1763. . "</th>";
  1764. if ( $form->{l_curr} && $form->{sort} eq 'curr' && $form->{l_subtotal} ) {
  1765. $column_data{fx_tax} = '<th class="listsubtotal" align="right">'
  1766. . $form->format_amount( \%myconfig,
  1767. $subtotalfxamount - $subtotalfxnetamount,
  1768. 2, "&nbsp;" )
  1769. . "</th>";
  1770. $column_data{fx_amount} =
  1771. '<th class="listsubtotal" align="right">'
  1772. . $form->format_amount( \%myconfig, $subtotalfxamount, 2, "&nbsp;" )
  1773. . "</th>";
  1774. $column_data{fx_paid} =
  1775. '<th class="listsubtotal" align="right">'
  1776. . $form->format_amount( \%myconfig, $subtotalfxpaid, 2, "&nbsp;" )
  1777. . "</th>";
  1778. $column_data{fx_due} = '<th class="listsubtotal" align="right">'
  1779. . $form->format_amount( \%myconfig,
  1780. $subtotalfxmount - $subtotalfxpaid,
  1781. 2, "&nbsp;" )
  1782. . "</th>";
  1783. }
  1784. $subtotalnetamount = 0;
  1785. $subtotalamount = 0;
  1786. $subtotalpaid = 0;
  1787. $subtotaldebit = 0;
  1788. $subtotalcredit = 0;
  1789. $subtotalfxnetamount = 0;
  1790. $subtotalfxamount = 0;
  1791. $subtotalfxpaid = 0;
  1792. print '<tr class="listsubtotal">';
  1793. for (@column_index) { print "\n$column_data{$_}" }
  1794. print "
  1795. </tr>
  1796. ";
  1797. }