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