summaryrefslogtreecommitdiff
path: root/bin/aa.pl
blob: 73550101678d40a4fd01513720b80e164f27d796 (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. if ( $form->{taxincluded} ) {
  806. $totaltax =
  807. Tax::calculate_taxes( \@taxaccounts, $form, $form->{invtotal}, 1 );
  808. }
  809. else {
  810. $totaltax =
  811. Tax::calculate_taxes( \@taxaccounts, $form, $form->{invtotal}, 0 );
  812. }
  813. foreach $item (@taxaccounts) {
  814. $taccno = $item->account;
  815. if ( $form->{calctax} ) {
  816. $form->{"calctax_$taccno"} = 1;
  817. $form->{"tax_$taccno"} = $form->round_amount( $item->value, 2 );
  818. }
  819. $form->{"select$form->{ARAP}_tax_$taccno"} =
  820. qq|<option>$taccno--$form->{"${taccno}_description"}|;
  821. }
  822. $form->{invtotal} =
  823. ( $form->{taxincluded} )
  824. ? $form->{invtotal}
  825. : $form->{invtotal} + $totaltax;
  826. $j = 1;
  827. for $i ( 1 .. $form->{paidaccounts} ) {
  828. if ( $form->{"paid_$i"} ) {
  829. for (qw(datepaid source memo cleared)) {
  830. $form->{"${_}_$j"} = $form->{"${_}_$i"};
  831. }
  832. for (qw(paid exchangerate)) {
  833. $form->{"${_}_$j"} =
  834. $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
  835. }
  836. $totalpaid += $form->{"paid_$j"};
  837. $form->{"exchangerate_$j"} = $exchangerate
  838. if (
  839. $form->{"forex_$j"} = (
  840. $exchangerate = $form->check_exchangerate(
  841. \%myconfig, $form->{currency},
  842. $form->{"datepaid_$j"},
  843. ( $form->{ARAP} eq 'AR' ) ? 'buy' : 'sell'
  844. )
  845. )
  846. );
  847. if ( $j++ != $i ) {
  848. for (qw(datepaid source memo paid exchangerate forex cleared)) {
  849. delete $form->{"${_}_$i"};
  850. }
  851. }
  852. }
  853. else {
  854. for (qw(datepaid source memo paid exchangerate forex cleared)) {
  855. delete $form->{"${_}_$i"};
  856. }
  857. }
  858. }
  859. $form->{paidaccounts} = $j;
  860. $form->{creditremaining} -=
  861. ( $form->{invtotal} - $totalpaid + $form->{oldtotalpaid} -
  862. $form->{oldinvtotal} );
  863. $form->{oldinvtotal} = $form->{invtotal};
  864. $form->{oldtotalpaid} = $totalpaid;
  865. &display_form;
  866. }
  867. sub post {
  868. $label =
  869. ( $form->{vc} eq 'customer' )
  870. ? $locale->text('Customer missing!')
  871. : $locale->text('Vendor missing!');
  872. # check if there is an invoice number, invoice and due date
  873. $form->isblank( "transdate", $locale->text('Invoice Date missing!') );
  874. $form->isblank( "duedate", $locale->text('Due Date missing!') );
  875. $form->isblank( $form->{vc}, $label );
  876. $closedto = $form->datetonum( \%myconfig, $form->{closedto} );
  877. $transdate = $form->datetonum( \%myconfig, $form->{transdate} );
  878. $form->error(
  879. $locale->text('Cannot post transaction for a closed period!') )
  880. if ( $transdate <= $closedto );
  881. $form->isblank( "exchangerate", $locale->text('Exchange rate missing!') )
  882. if ( $form->{currency} ne $form->{defaultcurrency} );
  883. for $i ( 1 .. $form->{paidaccounts} ) {
  884. if ( $form->{"paid_$i"} ) {
  885. $datepaid = $form->datetonum( \%myconfig, $form->{"datepaid_$i"} );
  886. $form->isblank( "datepaid_$i",
  887. $locale->text('Payment date missing!') );
  888. $form->error(
  889. $locale->text('Cannot post payment for a closed period!') )
  890. if ( $datepaid <= $closedto );
  891. if ( $form->{currency} ne $form->{defaultcurrency} ) {
  892. $form->{"exchangerate_$i"} = $form->{exchangerate}
  893. if ( $transdate == $datepaid );
  894. $form->isblank( "exchangerate_$i",
  895. $locale->text('Exchange rate for payment missing!') );
  896. }
  897. }
  898. }
  899. # if oldname ne name redo form
  900. ($name) = split /--/, $form->{ $form->{vc} };
  901. if ( $form->{"old$form->{vc}"} ne qq|$name--$form->{"$form->{vc}_id"}| ) {
  902. &update;
  903. exit;
  904. }
  905. if ( !$form->{repost} ) {
  906. if ( $form->{id} ) {
  907. &repost;
  908. exit;
  909. }
  910. }
  911. if ( AA->post_transaction( \%myconfig, \%$form ) ) {
  912. $form->update_status( \%myconfig );
  913. if ( $form->{printandpost} ) {
  914. &{"print_$form->{formname}"}( $old_form, 1 );
  915. }
  916. $form->redirect( $locale->text('Transaction posted!') );
  917. }
  918. else {
  919. $form->error( $locale->text('Cannot post transaction!') );
  920. }
  921. }
  922. sub delete {
  923. $form->{title} = $locale->text('Confirm!');
  924. $form->header;
  925. print qq|
  926. <body>
  927. <form method=post action=$form->{script}>
  928. |;
  929. $form->{action} = "yes";
  930. $form->hide_form;
  931. print qq|
  932. <h2 class=confirm>$form->{title}</h2>
  933. <h4>|
  934. . $locale->text('Are you sure you want to delete Transaction')
  935. . qq| $form->{invnumber}</h4>
  936. <button name="action" class="submit" type="submit" value="yes">|
  937. . $locale->text('Yes')
  938. . qq|</button>
  939. </form>
  940. </body>
  941. </html>
  942. |;
  943. }
  944. sub yes {
  945. if (
  946. AA->delete_transaction(
  947. \%myconfig, \%$form, ${LedgerSMB::Sysconfig::spool}
  948. )
  949. )
  950. {
  951. $form->redirect( $locale->text('Transaction deleted!') );
  952. }
  953. else {
  954. $form->error( $locale->text('Cannot delete transaction!') );
  955. }
  956. }
  957. sub search {
  958. $form->create_links( $form->{ARAP}, \%myconfig, $form->{vc} );
  959. $form->{"select$form->{ARAP}"} = "<option>\n";
  960. for ( @{ $form->{"$form->{ARAP}_links"}{ $form->{ARAP} } } ) {
  961. $form->{"select$form->{ARAP}"} .=
  962. "<option>$_->{accno}--$_->{description}\n";
  963. }
  964. if ( @{ $form->{"all_$form->{vc}"} } ) {
  965. $selectname = "";
  966. for ( @{ $form->{"all_$form->{vc}"} } ) {
  967. $selectname .=
  968. qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
  969. }
  970. $selectname =
  971. qq|<select name="$form->{vc}"><option>\n$selectname</select>|;
  972. }
  973. else {
  974. $selectname = qq|<input name=$form->{vc} size=35>|;
  975. }
  976. # departments
  977. if ( @{ $form->{all_department} } ) {
  978. $form->{selectdepartment} = "<option>\n";
  979. for ( @{ $form->{all_department} } ) {
  980. $form->{selectdepartment} .=
  981. qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
  982. }
  983. $l_department =
  984. qq|<input name="l_department" class=checkbox type=checkbox value=Y> |
  985. . $locale->text('Department');
  986. $department = qq|
  987. <tr>
  988. <th align=right nowrap>| . $locale->text('Department') . qq|</th>
  989. <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
  990. </tr>
  991. |;
  992. }
  993. if ( @{ $form->{all_employee} } ) {
  994. $form->{selectemployee} = "<option>\n";
  995. for ( @{ $form->{all_employee} } ) {
  996. $form->{selectemployee} .=
  997. qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
  998. }
  999. $employeelabel =
  1000. ( $form->{ARAP} eq 'AR' )
  1001. ? $locale->text('Salesperson')
  1002. : $locale->text('Employee');
  1003. $employee = qq|
  1004. <tr>
  1005. <th align=right nowrap>$employeelabel</th>
  1006. <td colspan=3><select name=employee>$form->{selectemployee}</select></td>
  1007. </tr>
  1008. |;
  1009. $l_employee =
  1010. qq|<input name="l_employee" class=checkbox type=checkbox value=Y> $employeelabel|;
  1011. $l_manager =
  1012. qq|<input name="l_manager" class=checkbox type=checkbox value=Y> |
  1013. . $locale->text('Manager');
  1014. }
  1015. $form->{title} =
  1016. ( $form->{ARAP} eq 'AR' )
  1017. ? $locale->text('AR Transactions')
  1018. : $locale->text('AP Transactions');
  1019. $invnumber = qq|
  1020. <tr>
  1021. <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
  1022. <td colspan=3><input name=invnumber size=20></td>
  1023. </tr>
  1024. <tr>
  1025. <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
  1026. <td colspan=3><input name=ordnumber size=20></td>
  1027. </tr>
  1028. <tr>
  1029. <th align=right nowrap>| . $locale->text('PO Number') . qq|</th>
  1030. <td colspan=3><input name=ponumber size=20></td>
  1031. </tr>
  1032. <tr>
  1033. <th align=right nowrap>| . $locale->text('Source') . qq|</th>
  1034. <td colspan=3><input name=source size=40></td>
  1035. </tr>
  1036. <tr>
  1037. <th align=right nowrap>| . $locale->text('Description') . qq|</th>
  1038. <td colspan=3><input name=description size=40></td>
  1039. </tr>
  1040. <tr>
  1041. <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
  1042. <td colspan=3><input name=notes size=40></td>
  1043. </tr>
  1044. |;
  1045. $openclosed = qq|
  1046. <tr>
  1047. <td nowrap><input name=open class=checkbox type=checkbox value=Y checked> |
  1048. . $locale->text('Open')
  1049. . qq|</td>
  1050. <td nowrap><input name=closed class=checkbox type=checkbox value=Y> |
  1051. . $locale->text('Closed')
  1052. . qq|</td>
  1053. </tr>
  1054. |;
  1055. $summary = qq|
  1056. <tr>
  1057. <td><input name=summary type=radio class=radio value=1 checked> |
  1058. . $locale->text('Summary')
  1059. . qq|</td>
  1060. <td><input name=summary type=radio class=radio value=0> |
  1061. . $locale->text('Detail') . qq|
  1062. </td>
  1063. </tr>
  1064. |;
  1065. if ( $form->{outstanding} ) {
  1066. $form->{title} =
  1067. ( $form->{ARAP} eq 'AR' )
  1068. ? $locale->text('AR Outstanding')
  1069. : $locale->text('AP Outstanding');
  1070. $invnumber = "";
  1071. $openclosed = "";
  1072. $summary = "";
  1073. }
  1074. if ( @{ $form->{all_years} } ) {
  1075. # accounting years
  1076. $form->{selectaccountingyear} = "<option>\n";
  1077. for ( @{ $form->{all_years} } ) {
  1078. $form->{selectaccountingyear} .= qq|<option>$_\n|;
  1079. }
  1080. $form->{selectaccountingmonth} = "<option>\n";
  1081. for ( sort keys %{ $form->{all_month} } ) {
  1082. $form->{selectaccountingmonth} .=
  1083. qq|<option value=$_>|
  1084. . $locale->text( $form->{all_month}{$_} ) . qq|\n|;
  1085. }
  1086. $selectfrom = qq|
  1087. <tr>
  1088. <th align=right>| . $locale->text('Period') . qq|</th>
  1089. <td colspan=3>
  1090. <select name=month>$form->{selectaccountingmonth}</select>
  1091. <select name=year>$form->{selectaccountingyear}</select>
  1092. <input name=interval class=radio type=radio value=0 checked>&nbsp;|
  1093. . $locale->text('Current') . qq|
  1094. <input name=interval class=radio type=radio value=1>&nbsp;|
  1095. . $locale->text('Month') . qq|
  1096. <input name=interval class=radio type=radio value=3>&nbsp;|
  1097. . $locale->text('Quarter') . qq|
  1098. <input name=interval class=radio type=radio value=12>&nbsp;|
  1099. . $locale->text('Year') . qq|
  1100. </td>
  1101. </tr>
  1102. |;
  1103. }
  1104. $name = $locale->text('Customer');
  1105. $l_name =
  1106. qq|<input name="l_name" class=checkbox type=checkbox value=Y checked> $name|;
  1107. $l_till =
  1108. qq|<input name="l_till" class=checkbox type=checkbox value=Y> |
  1109. . $locale->text('Till');
  1110. if ( $form->{vc} eq 'vendor' ) {
  1111. $name = $locale->text('Vendor');
  1112. $l_till = "";
  1113. $l_name =
  1114. qq|<input name="l_name" class=checkbox type=checkbox value=Y checked> $name|;
  1115. }
  1116. @a = ();
  1117. push @a,
  1118. qq|<input name="l_runningnumber" class=checkbox type=checkbox value=Y> |
  1119. . $locale->text('No.');
  1120. push @a, qq|<input name="l_id" class=checkbox type=checkbox value=Y> |
  1121. . $locale->text('ID');
  1122. push @a,
  1123. qq|<input name="l_invnumber" class=checkbox type=checkbox value=Y checked> |
  1124. . $locale->text('Invoice Number');
  1125. push @a,
  1126. qq|<input name="l_ordnumber" class=checkbox type=checkbox value=Y> |
  1127. . $locale->text('Order Number');
  1128. push @a, qq|<input name="l_ponumber" class=checkbox type=checkbox value=Y> |
  1129. . $locale->text('PO Number');
  1130. push @a,
  1131. qq|<input name="l_transdate" class=checkbox type=checkbox value=Y checked> |
  1132. . $locale->text('Invoice Date');
  1133. push @a, $l_name;
  1134. push @a, $l_employee if $l_employee;
  1135. push @a, $l_manager if $l_employee;
  1136. push @a, $l_department if $l_department;
  1137. push @a,
  1138. qq|<input name="l_netamount" class=checkbox type=checkbox value=Y> |
  1139. . $locale->text('Amount');
  1140. push @a, qq|<input name="l_tax" class=checkbox type=checkbox value=Y> |
  1141. . $locale->text('Tax');
  1142. push @a,
  1143. qq|<input name="l_amount" class=checkbox type=checkbox value=Y checked> |
  1144. . $locale->text('Total');
  1145. push @a, qq|<input name="l_curr" class=checkbox type=checkbox value=Y> |
  1146. . $locale->text('Currency');
  1147. push @a, qq|<input name="l_datepaid" class=checkbox type=checkbox value=Y> |
  1148. . $locale->text('Date Paid');
  1149. push @a,
  1150. qq|<input name="l_paid" class=checkbox type=checkbox value=Y checked> |
  1151. . $locale->text('Paid');
  1152. push @a, qq|<input name="l_duedate" class=checkbox type=checkbox value=Y> |
  1153. . $locale->text('Due Date');
  1154. push @a, qq|<input name="l_due" class=checkbox type=checkbox value=Y> |
  1155. . $locale->text('Amount Due');
  1156. push @a, qq|<input name="l_notes" class=checkbox type=checkbox value=Y> |
  1157. . $locale->text('Notes');
  1158. push @a, $l_till if $l_till;
  1159. push @a,
  1160. qq|<input name="l_shippingpoint" class=checkbox type=checkbox value=Y> |
  1161. . $locale->text('Shipping Point');
  1162. push @a, qq|<input name="l_shipvia" class=checkbox type=checkbox value=Y> |
  1163. . $locale->text('Ship via');
  1164. $form->header;
  1165. print qq|
  1166. <body>
  1167. <form method=post action=$form->{script}>
  1168. <table width=100%>
  1169. <tr><th class=listtop>$form->{title}</th></tr>
  1170. <tr height="5"></tr>
  1171. <tr>
  1172. <td>
  1173. <table>
  1174. <tr>
  1175. <th align=right>| . $locale->text('Account') . qq|</th>
  1176. <td colspan=3><select name=$form->{ARAP}>$form->{"select$form->{ARAP}"}</select></td>
  1177. </tr>
  1178. <tr>
  1179. <th align=right>$name</th>
  1180. <td colspan=3>$selectname</td>
  1181. </tr>
  1182. $employee
  1183. $department
  1184. $invnumber
  1185. <tr>
  1186. <th align=right>| . $locale->text('Ship via') . qq|</th>
  1187. <td colspan=3><input name=shipvia size=40></td>
  1188. </tr>
  1189. <tr>
  1190. <th align=right nowrap>| . $locale->text('From') . qq|</th>
  1191. <td><input name=transdatefrom size=11 title="$myconfig{dateformat}"></td>
  1192. <th align=right>| . $locale->text('To') . qq|</th>
  1193. <td><input name=transdateto size=11 title="$myconfig{dateformat}"></td>
  1194. </tr>
  1195. $selectfrom
  1196. </table>
  1197. </td>
  1198. </tr>
  1199. <tr>
  1200. <td>
  1201. |.$locale->text('All Invoices').qq|: <input type="radio" name="invoice_type" checked value="1">
  1202. |.$locale->text('Active').qq|: <input type="radio" name="invoice_type" value="2">
  1203. |.$locale->text('On Hold').qq|: <input type="radio" name="invoice_type" value="3">
  1204. <br/>
  1205. </td>
  1206. </tr>
  1207. <tr>
  1208. <td>
  1209. <table>
  1210. <tr>
  1211. <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
  1212. <td>
  1213. <table width=100%>
  1214. $openclosed
  1215. $summary
  1216. |;
  1217. $form->{sort} = "transdate";
  1218. $form->hide_form(qw(title outstanding sort));
  1219. while (@a) {
  1220. for ( 1 .. 5 ) {
  1221. print qq|<td nowrap>| . shift @a;
  1222. print qq|</td>\n|;
  1223. }
  1224. print qq|</tr>\n|;
  1225. }
  1226. print qq|
  1227. <tr>
  1228. <td nowrap><input name="l_subtotal" class=checkbox type=checkbox value=Y> |
  1229. . $locale->text('Subtotal')
  1230. . qq|</td>
  1231. </tr>
  1232. </table>
  1233. </td>
  1234. </tr>
  1235. </table>
  1236. </td>
  1237. </tr>
  1238. <tr>
  1239. <td><hr size=3 noshade></td>
  1240. </tr>
  1241. </table>
  1242. <br>
  1243. <input type="hidden" name="action" value="continue">
  1244. <button class="submit" type="submit" name="action" value="continue">|
  1245. . $locale->text('Continue')
  1246. . qq|</button>|;
  1247. $form->hide_form(qw(nextsub path login sessionid));
  1248. print qq|
  1249. </form>
  1250. |;
  1251. if ( $form->{lynx} ) {
  1252. require "bin/menu.pl";
  1253. &menubar;
  1254. }
  1255. print qq|
  1256. </body>
  1257. </html>
  1258. |;
  1259. }
  1260. sub transactions {
  1261. if ( $form->{ $form->{vc} } ) {
  1262. $form->{ $form->{vc} } = $form->unescape( $form->{ $form->{vc} } );
  1263. ( $form->{ $form->{vc} }, $form->{"$form->{vc}_id"} ) =
  1264. split( /--/, $form->{ $form->{vc} } );
  1265. }
  1266. @column_index;
  1267. AA->transactions( \%myconfig, \%$form );
  1268. $href = "$form->{script}?action=transactions";
  1269. for (qw(direction oldsort till outstanding path login sessionid summary)) {
  1270. $href .= qq|&$_=$form->{$_}|;
  1271. }
  1272. $href .= "&title=" . $form->escape( $form->{title} );
  1273. $form->sort_order();
  1274. $callback = "$form->{script}?action=transactions";
  1275. for (qw(direction oldsort till outstanding path login sessionid summary)) {
  1276. $callback .= qq|&$_=$form->{$_}|;
  1277. }
  1278. $callback .= "&title=" . $form->escape( $form->{title}, 1 );
  1279. if ( $form->{ $form->{ARAP} } ) {
  1280. $callback .=
  1281. "&$form->{ARAP}=" . $form->escape( $form->{ $form->{ARAP} }, 1 );
  1282. $href .= "&$form->{ARAP}=" . $form->escape( $form->{ $form->{ARAP} } );
  1283. $form->{ $form->{ARAP} } =~ s/--/ /;
  1284. $option = $locale->text('Account') . " : $form->{$form->{ARAP}}";
  1285. }
  1286. if ( $form->{ $form->{vc} } ) {
  1287. $callback .=
  1288. "&$form->{vc}="
  1289. . $form->escape( $form->{ $form->{vc} }, 1 )
  1290. . qq|--$form->{"$form->{vc}_id"}|;
  1291. $href .=
  1292. "&$form->{vc}="
  1293. . $form->escape( $form->{ $form->{vc} } )
  1294. . qq|--$form->{"$form->{vc}_id"}|;
  1295. $option .= "\n<br>" if ($option);
  1296. $name =
  1297. ( $form->{vc} eq 'customer' )
  1298. ? $locale->text('Customer')
  1299. : $locale->text('Vendor');
  1300. $option .= "$name : $form->{$form->{vc}}";
  1301. }
  1302. if ( $form->{department} ) {
  1303. $callback .= "&department=" . $form->escape( $form->{department}, 1 );
  1304. $href .= "&department=" . $form->escape( $form->{department} );
  1305. ($department) = split /--/, $form->{department};
  1306. $option .= "\n<br>" if ($option);
  1307. $option .= $locale->text('Department') . " : $department";
  1308. }
  1309. if ( $form->{employee} ) {
  1310. $callback .= "&employee=" . $form->escape( $form->{employee}, 1 );
  1311. $href .= "&employee=" . $form->escape( $form->{employee} );
  1312. ($employee) = split /--/, $form->{employee};
  1313. $option .= "\n<br>" if ($option);
  1314. if ( $form->{ARAP} eq 'AR' ) {
  1315. $option .= $locale->text('Salesperson');
  1316. }
  1317. else {
  1318. $option .= $locale->text('Employee');
  1319. }
  1320. $option .= " : $employee";
  1321. }
  1322. if ( $form->{invnumber} ) {
  1323. $callback .= "&invnumber=" . $form->escape( $form->{invnumber}, 1 );
  1324. $href .= "&invnumber=" . $form->escape( $form->{invnumber} );
  1325. $option .= "\n<br>" if ($option);
  1326. $option .= $locale->text('Invoice Number') . " : $form->{invnumber}";
  1327. }
  1328. if ( $form->{ordnumber} ) {
  1329. $callback .= "&ordnumber=" . $form->escape( $form->{ordnumber}, 1 );
  1330. $href .= "&ordnumber=" . $form->escape( $form->{ordnumber} );
  1331. $option .= "\n<br>" if ($option);
  1332. $option .= $locale->text('Order Number') . " : $form->{ordnumber}";
  1333. }
  1334. if ( $form->{ponumber} ) {
  1335. $callback .= "&ponumber=" . $form->escape( $form->{ponumber}, 1 );
  1336. $href .= "&ponumber=" . $form->escape( $form->{ponumber} );
  1337. $option .= "\n<br>" if ($option);
  1338. $option .= $locale->text('PO Number') . " : $form->{ponumber}";
  1339. }
  1340. if ( $form->{source} ) {
  1341. $callback .= "&source=" . $form->escape( $form->{source}, 1 );
  1342. $href .= "&source=" . $form->escape( $form->{source} );
  1343. $option .= "\n<br>" if $option;
  1344. $option .= $locale->text('Source') . " : $form->{source}";
  1345. }
  1346. if ( $form->{description} ) {
  1347. $callback .= "&description=" . $form->escape( $form->{description}, 1 );
  1348. $href .= "&description=" . $form->escape( $form->{description} );
  1349. $option .= "\n<br>" if $option;
  1350. $option .= $locale->text('Description') . " : $form->{description}";
  1351. }
  1352. if ( $form->{notes} ) {
  1353. $callback .= "&notes=" . $form->escape( $form->{notes}, 1 );
  1354. $href .= "&notes=" . $form->escape( $form->{notes} );
  1355. $option .= "\n<br>" if $option;
  1356. $option .= $locale->text('Notes') . " : $form->{notes}";
  1357. }
  1358. if ( $form->{shipvia} ) {
  1359. $callback .= "&shipvia=" . $form->escape( $form->{shipvia}, 1 );
  1360. $href .= "&shipvia=" . $form->escape( $form->{shipvia} );
  1361. $option .= "\n<br>" if $option;
  1362. $option .= $locale->text('Ship via') . " : $form->{shipvia}";
  1363. }
  1364. if ( $form->{transdatefrom} ) {
  1365. $callback .= "&transdatefrom=$form->{transdatefrom}";
  1366. $href .= "&transdatefrom=$form->{transdatefrom}";
  1367. $option .= "\n<br>" if ($option);
  1368. $option .=
  1369. $locale->text('From') . "&nbsp;"
  1370. . $locale->date( \%myconfig, $form->{transdatefrom}, 1 );
  1371. }
  1372. if ( $form->{transdateto} ) {
  1373. $callback .= "&transdateto=$form->{transdateto}";
  1374. $href .= "&transdateto=$form->{transdateto}";
  1375. $option .= "\n<br>" if ($option);
  1376. $option .=
  1377. $locale->text( 'To [_1]',
  1378. $locale->date( \%myconfig, $form->{transdateto}, 1 ) );
  1379. }
  1380. if ( $form->{open} ) {
  1381. $callback .= "&open=$form->{open}";
  1382. $href .= "&open=$form->{open}";
  1383. $option .= "\n<br>" if ($option);
  1384. $option .= $locale->text('Open');
  1385. }
  1386. if ( $form->{closed} ) {
  1387. $callback .= "&closed=$form->{closed}";
  1388. $href .= "&closed=$form->{closed}";
  1389. $option .= "\n<br>" if ($option);
  1390. $option .= $locale->text('Closed');
  1391. }
  1392. @columns =
  1393. $form->sort_columns(
  1394. qw(transdate id invnumber ordnumber ponumber name netamount tax amount paid due curr datepaid duedate notes till employee manager shippingpoint shipvia department)
  1395. );
  1396. pop @columns if $form->{department};
  1397. unshift @columns, "runningnumber";
  1398. foreach $item (@columns) {
  1399. if ( $form->{"l_$item"} eq "Y" ) {
  1400. push @column_index, $item;
  1401. if ( $form->{l_curr} && $item =~ /(amount|tax|paid|due)/ ) {
  1402. push @column_index, "fx_$item";
  1403. }
  1404. # add column to href and callback
  1405. $callback .= "&l_$item=Y";
  1406. $href .= "&l_$item=Y";
  1407. }
  1408. }
  1409. if ( !$form->{summary} ) {
  1410. foreach $item (qw(source debit credit accno description projectnumber))
  1411. {
  1412. push @column_index, $item;
  1413. }
  1414. }
  1415. if ( $form->{l_subtotal} eq 'Y' ) {
  1416. $callback .= "&l_subtotal=Y";
  1417. $href .= "&l_subtotal=Y";
  1418. }
  1419. $employee =
  1420. ( $form->{ARAP} eq 'AR' )
  1421. ? $locale->text('Salesperson')
  1422. : $locale->text('Employee');
  1423. $name =
  1424. ( $form->{vc} eq 'customer' )
  1425. ? $locale->text('Customer')
  1426. : $locale->text('Vendor');
  1427. $column_header{runningnumber} = qq|<th class=listheading>&nbsp;</th>|;
  1428. $column_header{id} =
  1429. "<th><a class=listheading href=$href&sort=id>"
  1430. . $locale->text('ID')
  1431. . "</a></th>";
  1432. $column_header{transdate} =
  1433. "<th><a class=listheading href=$href&sort=transdate>"
  1434. . $locale->text('Date')
  1435. . "</a></th>";
  1436. $column_header{duedate} =
  1437. "<th><a class=listheading href=$href&sort=duedate>"
  1438. . $locale->text('Due Date')
  1439. . "</a></th>";
  1440. $column_header{invnumber} =
  1441. "<th><a class=listheading href=$href&sort=invnumber>"
  1442. . $locale->text('Invoice')
  1443. . "</a></th>";
  1444. $column_header{ordnumber} =
  1445. "<th><a class=listheading href=$href&sort=ordnumber>"
  1446. . $locale->text('Order')
  1447. . "</a></th>";
  1448. $column_header{ponumber} =
  1449. "<th><a class=listheading href=$href&sort=ponumber>"
  1450. . $locale->text('PO Number')
  1451. . "</a></th>";
  1452. $column_header{name} =
  1453. "<th><a class=listheading href=$href&sort=name>$name</a></th>";
  1454. $column_header{netamount} =
  1455. "<th class=listheading>" . $locale->text('Amount') . "</th>";
  1456. $column_header{tax} =
  1457. "<th class=listheading>" . $locale->text('Tax') . "</th>";
  1458. $column_header{amount} =
  1459. "<th class=listheading>" . $locale->text('Total') . "</th>";
  1460. $column_header{paid} =
  1461. "<th class=listheading>" . $locale->text('Paid') . "</th>";
  1462. $column_header{datepaid} =
  1463. "<th><a class=listheading href=$href&sort=datepaid>"
  1464. . $locale->text('Date Paid')
  1465. . "</a></th>";
  1466. $column_header{due} =
  1467. "<th class=listheading>" . $locale->text('Amount Due') . "</th>";
  1468. $column_header{notes} =
  1469. "<th class=listheading>" . $locale->text('Notes') . "</th>";
  1470. $column_header{employee} =
  1471. "<th><a class=listheading href=$href&sort=employee>$employee</th>";
  1472. $column_header{manager} =
  1473. "<th><a class=listheading href=$href&sort=manager>"
  1474. . $locale->text('Manager') . "</th>";
  1475. $column_header{till} =
  1476. "<th class=listheading><a class=listheading href=$href&sort=till>"
  1477. . $locale->text('Till') . "</th>";
  1478. $column_header{shippingpoint} =
  1479. "<th><a class=listheading href=$href&sort=shippingpoint>"
  1480. . $locale->text('Shipping Point')
  1481. . "</a></th>";
  1482. $column_header{shipvia} =
  1483. "<th><a class=listheading href=$href&sort=shipvia>"
  1484. . $locale->text('Ship via')
  1485. . "</a></th>";
  1486. $column_header{curr} =
  1487. "<th><a class=listheading href=$href&sort=curr>"
  1488. . $locale->text('Curr')
  1489. . "</a></th>";
  1490. for (qw(amount tax netamount paid due)) {
  1491. $column_header{"fx_$_"} = "<th>&nbsp;</th>";
  1492. }
  1493. $column_header{department} =
  1494. "<th><a class=listheading href=$href&sort=department>"
  1495. . $locale->text('Department')
  1496. . "</a></th>";
  1497. $column_header{accno} =
  1498. "<th><a class=listheading href=$href&sort=accno>"
  1499. . $locale->text('Account')
  1500. . "</a></th>";
  1501. $column_header{source} =
  1502. "<th><a class=listheading href=$href&sort=source>"
  1503. . $locale->text('Source')
  1504. . "</a></th>";
  1505. $column_header{debit} =
  1506. "<th class=listheading>" . $locale->text('Debit') . "</th>";
  1507. $column_header{credit} =
  1508. "<th class=listheading>" . $locale->text('Credit') . "</th>";
  1509. $column_header{projectnumber} =
  1510. "<th><a class=listheading href=$href&sort=projectnumber>"
  1511. . $locale->text('Project')
  1512. . "</a></th>";
  1513. $column_header{description} =
  1514. "<th><a class=listheading href=$href&sort=linedescription>"
  1515. . $locale->text('Description')
  1516. . "</a></th>";
  1517. $form->{title} =
  1518. ( $form->{title} ) ? $form->{title} : $locale->text('AR Transactions');
  1519. $form->header;
  1520. print qq|
  1521. <body>
  1522. <table width=100%>
  1523. <tr>
  1524. <th class=listtop>$form->{title}</th>
  1525. </tr>
  1526. <tr height="5"></tr>
  1527. <tr>
  1528. <td>$option</td>
  1529. </tr>
  1530. <tr>
  1531. <td>
  1532. <table width=100%>
  1533. <tr class=listheading>
  1534. |;
  1535. for (@column_index) { print "\n$column_header{$_}" }
  1536. print qq|
  1537. </tr>
  1538. |;
  1539. # add sort and escape callback, this one we use for the add sub
  1540. $form->{callback} = $callback .= "&sort=$form->{sort}";
  1541. # escape callback for href
  1542. $callback = $form->escape($callback);
  1543. # flip direction
  1544. $direction = ( $form->{direction} eq 'ASC' ) ? "ASC" : "DESC";
  1545. $href =~ s/&direction=(\w+)&/&direction=$direction&/;
  1546. if ( @{ $form->{transactions} } ) {
  1547. $sameitem = $form->{transactions}->[0]->{ $form->{sort} };
  1548. }
  1549. # sums and tax on reports by Antonio Gallardo
  1550. #
  1551. $i = 0;
  1552. foreach $ref ( @{ $form->{transactions} } ) {
  1553. $i++;
  1554. if ( $form->{l_subtotal} eq 'Y' ) {
  1555. if ( $sameitem ne $ref->{ $form->{sort} } ) {
  1556. &subtotal;
  1557. $sameitem = $ref->{ $form->{sort} };
  1558. }
  1559. }
  1560. if ( $form->{l_curr} ) {
  1561. for (qw(netamount amount paid)) {
  1562. $ref->{"fx_$_"} = $ref->{$_} / $ref->{exchangerate};
  1563. }
  1564. for (qw(netamount amount paid)) {
  1565. $column_data{"fx_$_"} = "<td align=right>"
  1566. . $form->format_amount( \%myconfig, $ref->{"fx_$_"}, 2,
  1567. "&nbsp;" )
  1568. . "</td>";
  1569. }
  1570. $column_data{fx_tax} = "<td align=right>"
  1571. . $form->format_amount( \%myconfig,
  1572. $ref->{fx_amount} - $ref->{fx_netamount},
  1573. 2, "&nbsp;" )
  1574. . "</td>";
  1575. $column_data{fx_due} = "<td align=right>"
  1576. . $form->format_amount( \%myconfig,
  1577. $ref->{fx_amount} - $ref->{fx_paid},
  1578. 2, "&nbsp;" )
  1579. . "</td>";
  1580. $subtotalfxnetamount += $ref->{fx_netamount};
  1581. $subtotalfxamount += $ref->{fx_amount};
  1582. $subtotalfxpaid += $ref->{fx_paid};
  1583. $totalfxnetamount += $ref->{fx_netamount};
  1584. $totalfxamount += $ref->{fx_amount};
  1585. $totalfxpaid += $ref->{fx_paid};
  1586. }
  1587. $column_data{runningnumber} = "<td align=right>$i</td>";
  1588. for (qw(netamount amount paid debit credit)) {
  1589. $column_data{$_} =
  1590. "<td align=right>"
  1591. . $form->format_amount( \%myconfig, $ref->{$_}, 2, "&nbsp;" )
  1592. . "</td>";
  1593. }
  1594. $column_data{tax} = "<td align=right>"
  1595. . $form->format_amount( \%myconfig,
  1596. $ref->{amount} - $ref->{netamount},
  1597. 2, "&nbsp;" )
  1598. . "</td>";
  1599. $column_data{due} = "<td align=right>"
  1600. . $form->format_amount( \%myconfig, $ref->{amount} - $ref->{paid},
  1601. 2, "&nbsp;" )
  1602. . "</td>";
  1603. $subtotalnetamount += $ref->{netamount};
  1604. $subtotalamount += $ref->{amount};
  1605. $subtotalpaid += $ref->{paid};
  1606. $subtotaldebit += $ref->{debit};
  1607. $subtotalcredit += $ref->{credit};
  1608. $totalnetamount += $ref->{netamount};
  1609. $totalamount += $ref->{amount};
  1610. $totalpaid += $ref->{paid};
  1611. $totaldebit += $ref->{debit};
  1612. $totalcredit += $ref->{credit};
  1613. $module =
  1614. ( $ref->{invoice} )
  1615. ? ( $form->{ARAP} eq 'AR' ) ? "is.pl" : "ir.pl"
  1616. : $form->{script};
  1617. $module = ( $ref->{till} ) ? "ps.pl" : $module;
  1618. $column_data{invnumber} =
  1619. "<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>";
  1620. for (qw(notes description)) { $ref->{$_} =~ s/\r?\n/<br>/g }
  1621. for (
  1622. qw(transdate datepaid duedate department ordnumber ponumber notes shippingpoint shipvia employee manager till source description projectnumber)
  1623. )
  1624. {
  1625. $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>";
  1626. }
  1627. for (qw(id curr)) { $column_data{$_} = "<td>$ref->{$_}</td>" }
  1628. $column_data{accno} =
  1629. 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>|;
  1630. $column_data{name} =
  1631. 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>|;
  1632. if ( $ref->{id} != $sameid ) {
  1633. $j++;
  1634. $j %= 2;
  1635. }
  1636. print "
  1637. <tr class=listrow$j>
  1638. ";
  1639. for (@column_index) { print "\n$column_data{$_}" }
  1640. print qq|
  1641. </tr>
  1642. |;
  1643. $sameid = $ref->{id};
  1644. }
  1645. if ( $form->{l_subtotal} eq 'Y' ) {
  1646. &subtotal;
  1647. $sameitem = $ref->{ $form->{sort} };
  1648. }
  1649. # print totals
  1650. print qq|
  1651. <tr class=listtotal>
  1652. |;
  1653. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  1654. $column_data{netamount} =
  1655. "<th class=listtotal align=right>"
  1656. . $form->format_amount( \%myconfig, $totalnetamount, 2, "&nbsp;" )
  1657. . "</th>";
  1658. $column_data{tax} = "<th class=listtotal align=right>"
  1659. . $form->format_amount( \%myconfig, $totalamount - $totalnetamount,
  1660. 2, "&nbsp;" )
  1661. . "</th>";
  1662. $column_data{amount} =
  1663. "<th class=listtotal align=right>"
  1664. . $form->format_amount( \%myconfig, $totalamount, 2, "&nbsp;" ) . "</th>";
  1665. $column_data{paid} =
  1666. "<th class=listtotal align=right>"
  1667. . $form->format_amount( \%myconfig, $totalpaid, 2, "&nbsp;" ) . "</th>";
  1668. $column_data{due} =
  1669. "<th class=listtotal align=right>"
  1670. . $form->format_amount( \%myconfig, $totalamount - $totalpaid, 2,
  1671. "&nbsp;" )
  1672. . "</th>";
  1673. $column_data{debit} =
  1674. "<th class=listtotal align=right>"
  1675. . $form->format_amount( \%myconfig, $totaldebit, 2, "&nbsp;" ) . "</th>";
  1676. $column_data{credit} =
  1677. "<th class=listtotal align=right>"
  1678. . $form->format_amount( \%myconfig, $totalcredit, 2, "&nbsp;" ) . "</th>";
  1679. if ( $form->{l_curr} && $form->{sort} eq 'curr' && $form->{l_subtotal} ) {
  1680. $column_data{fx_netamount} =
  1681. "<th class=listtotal align=right>"
  1682. . $form->format_amount( \%myconfig, $totalfxnetamount, 2, "&nbsp;" )
  1683. . "</th>";
  1684. $column_data{fx_tax} = "<th class=listtotal align=right>"
  1685. . $form->format_amount( \%myconfig,
  1686. $totalfxamount - $totalfxnetamount,
  1687. 2, "&nbsp;" )
  1688. . "</th>";
  1689. $column_data{fx_amount} =
  1690. "<th class=listtotal align=right>"
  1691. . $form->format_amount( \%myconfig, $totalfxamount, 2, "&nbsp;" )
  1692. . "</th>";
  1693. $column_data{fx_paid} =
  1694. "<th class=listtotal align=right>"
  1695. . $form->format_amount( \%myconfig, $totalfxpaid, 2, "&nbsp;" )
  1696. . "</th>";
  1697. $column_data{fx_due} = "<th class=listtotal align=right>"
  1698. . $form->format_amount( \%myconfig, $totalfxamount - $totalfxpaid,
  1699. 2, "&nbsp;" )
  1700. . "</th>";
  1701. }
  1702. for (@column_index) { print "\n$column_data{$_}" }
  1703. if ( $myconfig{acs} !~ /$form->{ARAP}--$form->{ARAP}/ ) {
  1704. $i = 1;
  1705. if ( $form->{ARAP} eq 'AR' ) {
  1706. $button{'AR--Add Transaction'}{code} =
  1707. qq|<button class="submit" type="submit" name="action" value="ar_transaction">|
  1708. . $locale->text('AR Transaction')
  1709. . qq|</button> |;
  1710. $button{'AR--Add Transaction'}{order} = $i++;
  1711. $button{'AR--Sales Invoice'}{code} =
  1712. qq|<button class="submit" type="submit" name="action" value="sales_invoice_">|
  1713. . $locale->text('Sales Invoice.')
  1714. . qq|</button> |;
  1715. $button{'AR--Sales Invoice'}{order} = $i++;
  1716. }
  1717. else {
  1718. $button{'AP--Add Transaction'}{code} =
  1719. qq|<button class="submit" type="submit" name="action" value="ap_transaction">|
  1720. . $locale->text('AP Transaction')
  1721. . qq|</button> |;
  1722. $button{'AP--Add Transaction'}{order} = $i++;
  1723. $button{'AP--Vendor Invoice'}{code} =
  1724. qq|<button class="submit" type="submit" name="action" value="vendor_invoice_">|
  1725. . $locale->text('Vendor Invoice.')
  1726. . qq|</button> |;
  1727. $button{'AP--Vendor Invoice'}{order} = $i++;
  1728. }
  1729. foreach $item ( split /;/, $myconfig{acs} ) {
  1730. delete $button{$item};
  1731. }
  1732. }
  1733. print qq|
  1734. </tr>
  1735. </table>
  1736. </td>
  1737. </tr>
  1738. <tr>
  1739. <td><hr size=3 noshade></td>
  1740. </tr>
  1741. </table>
  1742. <br>
  1743. <form method=post action=$form->{script}>
  1744. |;
  1745. $form->hide_form(
  1746. "callback", "path", "login", "sessionid",
  1747. "$form->{vc}", "$form->{vc}_id"
  1748. );
  1749. if ( !$form->{till} ) {
  1750. foreach $item ( sort { $a->{order} <=> $b->{order} } %button ) {
  1751. print $item->{code};
  1752. }
  1753. }
  1754. if ( $form->{lynx} ) {
  1755. require "bin/menu.pl";
  1756. &menubar;
  1757. }
  1758. print qq|
  1759. </form>
  1760. </body>
  1761. </html>
  1762. |;
  1763. }
  1764. sub subtotal {
  1765. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  1766. $column_data{tax} = "<th class=listsubtotal align=right>"
  1767. . $form->format_amount( \%myconfig, $subtotalamount - $subtotalnetamount,
  1768. 2, "&nbsp;" )
  1769. . "</th>";
  1770. $column_data{amount} =
  1771. "<th class=listsubtotal align=right>"
  1772. . $form->format_amount( \%myconfig, $subtotalamount, 2, "&nbsp;" )
  1773. . "</th>";
  1774. $column_data{paid} =
  1775. "<th class=listsubtotal align=right>"
  1776. . $form->format_amount( \%myconfig, $subtotalpaid, 2, "&nbsp;" )
  1777. . "</th>";
  1778. $column_data{due} = "<th class=listsubtotal align=right>"
  1779. . $form->format_amount( \%myconfig, $subtotalamount - $subtotalpaid,
  1780. 2, "&nbsp;" )
  1781. . "</th>";
  1782. $column_data{debit} =
  1783. "<th class=listsubtotal align=right>"
  1784. . $form->format_amount( \%myconfig, $subtotaldebit, 2, "&nbsp;" )
  1785. . "</th>";
  1786. $column_data{credit} =
  1787. "<th class=listsubtotal align=right>"
  1788. . $form->format_amount( \%myconfig, $subtotalcredit, 2, "&nbsp;" )
  1789. . "</th>";
  1790. if ( $form->{l_curr} && $form->{sort} eq 'curr' && $form->{l_subtotal} ) {
  1791. $column_data{fx_tax} = "<th class=listsubtotal align=right>"
  1792. . $form->format_amount( \%myconfig,
  1793. $subtotalfxamount - $subtotalfxnetamount,
  1794. 2, "&nbsp;" )
  1795. . "</th>";
  1796. $column_data{fx_amount} =
  1797. "<th class=listsubtotal align=right>"
  1798. . $form->format_amount( \%myconfig, $subtotalfxamount, 2, "&nbsp;" )
  1799. . "</th>";
  1800. $column_data{fx_paid} =
  1801. "<th class=listsubtotal align=right>"
  1802. . $form->format_amount( \%myconfig, $subtotalfxpaid, 2, "&nbsp;" )
  1803. . "</th>";
  1804. $column_data{fx_due} = "<th class=listsubtotal align=right>"
  1805. . $form->format_amount( \%myconfig,
  1806. $subtotalfxmount - $subtotalfxpaid,
  1807. 2, "&nbsp;" )
  1808. . "</th>";
  1809. }
  1810. $subtotalnetamount = 0;
  1811. $subtotalamount = 0;
  1812. $subtotalpaid = 0;
  1813. $subtotaldebit = 0;
  1814. $subtotalcredit = 0;
  1815. $subtotalfxnetamount = 0;
  1816. $subtotalfxamount = 0;
  1817. $subtotalfxpaid = 0;
  1818. print "<tr class=listsubtotal>";
  1819. for (@column_index) { print "\n$column_data{$_}" }
  1820. print "
  1821. </tr>
  1822. ";
  1823. }