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