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