summaryrefslogtreecommitdiff
path: root/bin/aa.pl
blob: ee2e510ef43b5d400660966fd5e88bedb5a782f7 (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. my @column_index;
  1259. AA->transactions( \%myconfig, \%$form );
  1260. $href = "$form->{script}?action=transactions";
  1261. for (qw(direction oldsort till outstanding path login sessionid summary)) {
  1262. $href .= qq|&$_=$form->{$_}|;
  1263. }
  1264. $href .= "&title=" . $form->escape( $form->{title} );
  1265. $form->sort_order();
  1266. $callback = "$form->{script}?action=transactions";
  1267. for (qw(direction oldsort till outstanding path login sessionid summary)) {
  1268. $callback .= qq|&$_=$form->{$_}|;
  1269. }
  1270. $callback .= "&title=" . $form->escape( $form->{title}, 1 );
  1271. if ( $form->{ $form->{ARAP} } ) {
  1272. $callback .=
  1273. "&$form->{ARAP}=" . $form->escape( $form->{ $form->{ARAP} }, 1 );
  1274. $href .= "&$form->{ARAP}=" . $form->escape( $form->{ $form->{ARAP} } );
  1275. $form->{ $form->{ARAP} } =~ s/--/ /;
  1276. $option = $locale->text('Account') . " : $form->{$form->{ARAP}}";
  1277. }
  1278. if ( $form->{ $form->{vc} } ) {
  1279. $callback .=
  1280. "&$form->{vc}="
  1281. . $form->escape( $form->{ $form->{vc} }, 1 )
  1282. . qq|--$form->{"$form->{vc}_id"}|;
  1283. $href .=
  1284. "&$form->{vc}="
  1285. . $form->escape( $form->{ $form->{vc} } )
  1286. . qq|--$form->{"$form->{vc}_id"}|;
  1287. $option .= "\n<br>" if ($option);
  1288. $name =
  1289. ( $form->{vc} eq 'customer' )
  1290. ? $locale->text('Customer')
  1291. : $locale->text('Vendor');
  1292. $option .= "$name : $form->{$form->{vc}}";
  1293. }
  1294. if ( $form->{department} ) {
  1295. $callback .= "&department=" . $form->escape( $form->{department}, 1 );
  1296. $href .= "&department=" . $form->escape( $form->{department} );
  1297. ($department) = split /--/, $form->{department};
  1298. $option .= "\n<br>" if ($option);
  1299. $option .= $locale->text('Department') . " : $department";
  1300. }
  1301. if ( $form->{employee} ) {
  1302. $callback .= "&employee=" . $form->escape( $form->{employee}, 1 );
  1303. $href .= "&employee=" . $form->escape( $form->{employee} );
  1304. ($employee) = split /--/, $form->{employee};
  1305. $option .= "\n<br>" if ($option);
  1306. if ( $form->{ARAP} eq 'AR' ) {
  1307. $option .= $locale->text('Salesperson');
  1308. }
  1309. else {
  1310. $option .= $locale->text('Employee');
  1311. }
  1312. $option .= " : $employee";
  1313. }
  1314. if ( $form->{invnumber} ) {
  1315. $callback .= "&invnumber=" . $form->escape( $form->{invnumber}, 1 );
  1316. $href .= "&invnumber=" . $form->escape( $form->{invnumber} );
  1317. $option .= "\n<br>" if ($option);
  1318. $option .= $locale->text('Invoice Number') . " : $form->{invnumber}";
  1319. }
  1320. if ( $form->{ordnumber} ) {
  1321. $callback .= "&ordnumber=" . $form->escape( $form->{ordnumber}, 1 );
  1322. $href .= "&ordnumber=" . $form->escape( $form->{ordnumber} );
  1323. $option .= "\n<br>" if ($option);
  1324. $option .= $locale->text('Order Number') . " : $form->{ordnumber}";
  1325. }
  1326. if ( $form->{ponumber} ) {
  1327. $callback .= "&ponumber=" . $form->escape( $form->{ponumber}, 1 );
  1328. $href .= "&ponumber=" . $form->escape( $form->{ponumber} );
  1329. $option .= "\n<br>" if ($option);
  1330. $option .= $locale->text('PO Number') . " : $form->{ponumber}";
  1331. }
  1332. if ( $form->{source} ) {
  1333. $callback .= "&source=" . $form->escape( $form->{source}, 1 );
  1334. $href .= "&source=" . $form->escape( $form->{source} );
  1335. $option .= "\n<br>" if $option;
  1336. $option .= $locale->text('Source') . " : $form->{source}";
  1337. }
  1338. if ( $form->{description} ) {
  1339. $callback .= "&description=" . $form->escape( $form->{description}, 1 );
  1340. $href .= "&description=" . $form->escape( $form->{description} );
  1341. $option .= "\n<br>" if $option;
  1342. $option .= $locale->text('Description') . " : $form->{description}";
  1343. }
  1344. if ( $form->{notes} ) {
  1345. $callback .= "&notes=" . $form->escape( $form->{notes}, 1 );
  1346. $href .= "&notes=" . $form->escape( $form->{notes} );
  1347. $option .= "\n<br>" if $option;
  1348. $option .= $locale->text('Notes') . " : $form->{notes}";
  1349. }
  1350. if ( $form->{shipvia} ) {
  1351. $callback .= "&shipvia=" . $form->escape( $form->{shipvia}, 1 );
  1352. $href .= "&shipvia=" . $form->escape( $form->{shipvia} );
  1353. $option .= "\n<br>" if $option;
  1354. $option .= $locale->text('Ship via') . " : $form->{shipvia}";
  1355. }
  1356. if ( $form->{transdatefrom} ) {
  1357. $callback .= "&transdatefrom=$form->{transdatefrom}";
  1358. $href .= "&transdatefrom=$form->{transdatefrom}";
  1359. $option .= "\n<br>" if ($option);
  1360. $option .=
  1361. $locale->text('From') . "&nbsp;"
  1362. . $locale->date( \%myconfig, $form->{transdatefrom}, 1 );
  1363. }
  1364. if ( $form->{transdateto} ) {
  1365. $callback .= "&transdateto=$form->{transdateto}";
  1366. $href .= "&transdateto=$form->{transdateto}";
  1367. $option .= "\n<br>" if ($option);
  1368. $option .=
  1369. $locale->text( 'To [_1]',
  1370. $locale->date( \%myconfig, $form->{transdateto}, 1 ) );
  1371. }
  1372. if ( $form->{open} ) {
  1373. $callback .= "&open=$form->{open}";
  1374. $href .= "&open=$form->{open}";
  1375. $option .= "\n<br>" if ($option);
  1376. $option .= $locale->text('Open');
  1377. }
  1378. if ( $form->{closed} ) {
  1379. $callback .= "&closed=$form->{closed}";
  1380. $href .= "&closed=$form->{closed}";
  1381. $option .= "\n<br>" if ($option);
  1382. $option .= $locale->text('Closed');
  1383. }
  1384. @columns =
  1385. $form->sort_columns(
  1386. qw(transdate id invnumber ordnumber ponumber name netamount tax amount paid due curr datepaid duedate notes till employee manager shippingpoint shipvia department)
  1387. );
  1388. pop @columns if $form->{department};
  1389. unshift @columns, "runningnumber";
  1390. foreach $item (@columns) {
  1391. if ( $form->{"l_$item"} eq "Y" ) {
  1392. push @column_index, $item;
  1393. if ( $form->{l_curr} && $item =~ /(amount|tax|paid|due)/ ) {
  1394. push @column_index, "fx_$item";
  1395. }
  1396. # add column to href and callback
  1397. $callback .= "&l_$item=Y";
  1398. $href .= "&l_$item=Y";
  1399. }
  1400. }
  1401. if ( !$form->{summary} ) {
  1402. foreach $item (qw(source debit credit accno description projectnumber))
  1403. {
  1404. push @column_index, $item;
  1405. }
  1406. }
  1407. if ( $form->{l_subtotal} eq 'Y' ) {
  1408. $callback .= "&l_subtotal=Y";
  1409. $href .= "&l_subtotal=Y";
  1410. }
  1411. $employee =
  1412. ( $form->{ARAP} eq 'AR' )
  1413. ? $locale->text('Salesperson')
  1414. : $locale->text('Employee');
  1415. $name =
  1416. ( $form->{vc} eq 'customer' )
  1417. ? $locale->text('Customer')
  1418. : $locale->text('Vendor');
  1419. $column_header{runningnumber} = qq|<th class=listheading>&nbsp;</th>|;
  1420. $column_header{id} =
  1421. "<th><a class=listheading href=$href&sort=id>"
  1422. . $locale->text('ID')
  1423. . "</a></th>";
  1424. $column_header{transdate} =
  1425. "<th><a class=listheading href=$href&sort=transdate>"
  1426. . $locale->text('Date')
  1427. . "</a></th>";
  1428. $column_header{duedate} =
  1429. "<th><a class=listheading href=$href&sort=duedate>"
  1430. . $locale->text('Due Date')
  1431. . "</a></th>";
  1432. $column_header{invnumber} =
  1433. "<th><a class=listheading href=$href&sort=invnumber>"
  1434. . $locale->text('Invoice')
  1435. . "</a></th>";
  1436. $column_header{ordnumber} =
  1437. "<th><a class=listheading href=$href&sort=ordnumber>"
  1438. . $locale->text('Order')
  1439. . "</a></th>";
  1440. $column_header{ponumber} =
  1441. "<th><a class=listheading href=$href&sort=ponumber>"
  1442. . $locale->text('PO Number')
  1443. . "</a></th>";
  1444. $column_header{name} =
  1445. "<th><a class=listheading href=$href&sort=name>$name</a></th>";
  1446. $column_header{netamount} =
  1447. "<th class=listheading>" . $locale->text('Amount') . "</th>";
  1448. $column_header{tax} =
  1449. "<th class=listheading>" . $locale->text('Tax') . "</th>";
  1450. $column_header{amount} =
  1451. "<th class=listheading>" . $locale->text('Total') . "</th>";
  1452. $column_header{paid} =
  1453. "<th class=listheading>" . $locale->text('Paid') . "</th>";
  1454. $column_header{datepaid} =
  1455. "<th><a class=listheading href=$href&sort=datepaid>"
  1456. . $locale->text('Date Paid')
  1457. . "</a></th>";
  1458. $column_header{due} =
  1459. "<th class=listheading>" . $locale->text('Amount Due') . "</th>";
  1460. $column_header{notes} =
  1461. "<th class=listheading>" . $locale->text('Notes') . "</th>";
  1462. $column_header{employee} =
  1463. "<th><a class=listheading href=$href&sort=employee>$employee</th>";
  1464. $column_header{manager} =
  1465. "<th><a class=listheading href=$href&sort=manager>"
  1466. . $locale->text('Manager') . "</th>";
  1467. $column_header{till} =
  1468. "<th class=listheading><a class=listheading href=$href&sort=till>"
  1469. . $locale->text('Till') . "</th>";
  1470. $column_header{shippingpoint} =
  1471. "<th><a class=listheading href=$href&sort=shippingpoint>"
  1472. . $locale->text('Shipping Point')
  1473. . "</a></th>";
  1474. $column_header{shipvia} =
  1475. "<th><a class=listheading href=$href&sort=shipvia>"
  1476. . $locale->text('Ship via')
  1477. . "</a></th>";
  1478. $column_header{curr} =
  1479. "<th><a class=listheading href=$href&sort=curr>"
  1480. . $locale->text('Curr')
  1481. . "</a></th>";
  1482. for (qw(amount tax netamount paid due)) {
  1483. $column_header{"fx_$_"} = "<th>&nbsp;</th>";
  1484. }
  1485. $column_header{department} =
  1486. "<th><a class=listheading href=$href&sort=department>"
  1487. . $locale->text('Department')
  1488. . "</a></th>";
  1489. $column_header{accno} =
  1490. "<th><a class=listheading href=$href&sort=accno>"
  1491. . $locale->text('Account')
  1492. . "</a></th>";
  1493. $column_header{source} =
  1494. "<th><a class=listheading href=$href&sort=source>"
  1495. . $locale->text('Source')
  1496. . "</a></th>";
  1497. $column_header{debit} =
  1498. "<th class=listheading>" . $locale->text('Debit') . "</th>";
  1499. $column_header{credit} =
  1500. "<th class=listheading>" . $locale->text('Credit') . "</th>";
  1501. $column_header{projectnumber} =
  1502. "<th><a class=listheading href=$href&sort=projectnumber>"
  1503. . $locale->text('Project')
  1504. . "</a></th>";
  1505. $column_header{description} =
  1506. "<th><a class=listheading href=$href&sort=linedescription>"
  1507. . $locale->text('Description')
  1508. . "</a></th>";
  1509. $form->{title} =
  1510. ( $form->{title} ) ? $form->{title} : $locale->text('AR Transactions');
  1511. $form->header;
  1512. print qq|
  1513. <body>
  1514. <table width=100%>
  1515. <tr>
  1516. <th class=listtop>$form->{title}</th>
  1517. </tr>
  1518. <tr height="5"></tr>
  1519. <tr>
  1520. <td>$option</td>
  1521. </tr>
  1522. <tr>
  1523. <td>
  1524. <table width=100%>
  1525. <tr class=listheading>
  1526. |;
  1527. for (@column_index) { print "\n$column_header{$_}" }
  1528. print qq|
  1529. </tr>
  1530. |;
  1531. # add sort and escape callback, this one we use for the add sub
  1532. $form->{callback} = $callback .= "&sort=$form->{sort}";
  1533. # escape callback for href
  1534. $callback = $form->escape($callback);
  1535. # flip direction
  1536. $direction = ( $form->{direction} eq 'ASC' ) ? "ASC" : "DESC";
  1537. $href =~ s/&direction=(\w+)&/&direction=$direction&/;
  1538. if ( @{ $form->{transactions} } ) {
  1539. $sameitem = $form->{transactions}->[0]->{ $form->{sort} };
  1540. }
  1541. # sums and tax on reports by Antonio Gallardo
  1542. #
  1543. $i = 0;
  1544. foreach $ref ( @{ $form->{transactions} } ) {
  1545. $i++;
  1546. if ( $form->{l_subtotal} eq 'Y' ) {
  1547. if ( $sameitem ne $ref->{ $form->{sort} } ) {
  1548. &subtotal;
  1549. $sameitem = $ref->{ $form->{sort} };
  1550. }
  1551. }
  1552. if ( $form->{l_curr} ) {
  1553. for (qw(netamount amount paid)) {
  1554. $ref->{"fx_$_"} = $ref->{$_} / $ref->{exchangerate};
  1555. }
  1556. for (qw(netamount amount paid)) {
  1557. $column_data{"fx_$_"} = "<td align=right>"
  1558. . $form->format_amount( \%myconfig, $ref->{"fx_$_"}, 2,
  1559. "&nbsp;" )
  1560. . "</td>";
  1561. }
  1562. $column_data{fx_tax} = "<td align=right>"
  1563. . $form->format_amount( \%myconfig,
  1564. $ref->{fx_amount} - $ref->{fx_netamount},
  1565. 2, "&nbsp;" )
  1566. . "</td>";
  1567. $column_data{fx_due} = "<td align=right>"
  1568. . $form->format_amount( \%myconfig,
  1569. $ref->{fx_amount} - $ref->{fx_paid},
  1570. 2, "&nbsp;" )
  1571. . "</td>";
  1572. $subtotalfxnetamount += $ref->{fx_netamount};
  1573. $subtotalfxamount += $ref->{fx_amount};
  1574. $subtotalfxpaid += $ref->{fx_paid};
  1575. $totalfxnetamount += $ref->{fx_netamount};
  1576. $totalfxamount += $ref->{fx_amount};
  1577. $totalfxpaid += $ref->{fx_paid};
  1578. }
  1579. $column_data{runningnumber} = "<td align=right>$i</td>";
  1580. for (qw(netamount amount paid debit credit)) {
  1581. $column_data{$_} =
  1582. "<td align=right>"
  1583. . $form->format_amount( \%myconfig, $ref->{$_}, 2, "&nbsp;" )
  1584. . "</td>";
  1585. }
  1586. $column_data{tax} = "<td align=right>"
  1587. . $form->format_amount( \%myconfig,
  1588. $ref->{amount} - $ref->{netamount},
  1589. 2, "&nbsp;" )
  1590. . "</td>";
  1591. $column_data{due} = "<td align=right>"
  1592. . $form->format_amount( \%myconfig, $ref->{amount} - $ref->{paid},
  1593. 2, "&nbsp;" )
  1594. . "</td>";
  1595. $subtotalnetamount += $ref->{netamount};
  1596. $subtotalamount += $ref->{amount};
  1597. $subtotalpaid += $ref->{paid};
  1598. $subtotaldebit += $ref->{debit};
  1599. $subtotalcredit += $ref->{credit};
  1600. $totalnetamount += $ref->{netamount};
  1601. $totalamount += $ref->{amount};
  1602. $totalpaid += $ref->{paid};
  1603. $totaldebit += $ref->{debit};
  1604. $totalcredit += $ref->{credit};
  1605. $module =
  1606. ( $ref->{invoice} )
  1607. ? ( $form->{ARAP} eq 'AR' ) ? "is.pl" : "ir.pl"
  1608. : $form->{script};
  1609. $module = ( $ref->{till} ) ? "ps.pl" : $module;
  1610. $column_data{invnumber} =
  1611. "<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>";
  1612. for (qw(notes description)) { $ref->{$_} =~ s/\r?\n/<br>/g }
  1613. for (
  1614. qw(transdate datepaid duedate department ordnumber ponumber notes shippingpoint shipvia employee manager till source description projectnumber)
  1615. )
  1616. {
  1617. $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>";
  1618. }
  1619. for (qw(id curr)) { $column_data{$_} = "<td>$ref->{$_}</td>" }
  1620. $column_data{accno} =
  1621. 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>|;
  1622. $column_data{name} =
  1623. 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>|;
  1624. if ( $ref->{id} != $sameid ) {
  1625. $j++;
  1626. $j %= 2;
  1627. }
  1628. print "
  1629. <tr class=listrow$j>
  1630. ";
  1631. for (@column_index) { print "\n$column_data{$_}" }
  1632. print qq|
  1633. </tr>
  1634. |;
  1635. $sameid = $ref->{id};
  1636. }
  1637. if ( $form->{l_subtotal} eq 'Y' ) {
  1638. &subtotal;
  1639. $sameitem = $ref->{ $form->{sort} };
  1640. }
  1641. # print totals
  1642. print qq|
  1643. <tr class=listtotal>
  1644. |;
  1645. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  1646. $column_data{netamount} =
  1647. "<th class=listtotal align=right>"
  1648. . $form->format_amount( \%myconfig, $totalnetamount, 2, "&nbsp;" )
  1649. . "</th>";
  1650. $column_data{tax} = "<th class=listtotal align=right>"
  1651. . $form->format_amount( \%myconfig, $totalamount - $totalnetamount,
  1652. 2, "&nbsp;" )
  1653. . "</th>";
  1654. $column_data{amount} =
  1655. "<th class=listtotal align=right>"
  1656. . $form->format_amount( \%myconfig, $totalamount, 2, "&nbsp;" ) . "</th>";
  1657. $column_data{paid} =
  1658. "<th class=listtotal align=right>"
  1659. . $form->format_amount( \%myconfig, $totalpaid, 2, "&nbsp;" ) . "</th>";
  1660. $column_data{due} =
  1661. "<th class=listtotal align=right>"
  1662. . $form->format_amount( \%myconfig, $totalamount - $totalpaid, 2,
  1663. "&nbsp;" )
  1664. . "</th>";
  1665. $column_data{debit} =
  1666. "<th class=listtotal align=right>"
  1667. . $form->format_amount( \%myconfig, $totaldebit, 2, "&nbsp;" ) . "</th>";
  1668. $column_data{credit} =
  1669. "<th class=listtotal align=right>"
  1670. . $form->format_amount( \%myconfig, $totalcredit, 2, "&nbsp;" ) . "</th>";
  1671. if ( $form->{l_curr} && $form->{sort} eq 'curr' && $form->{l_subtotal} ) {
  1672. $column_data{fx_netamount} =
  1673. "<th class=listtotal align=right>"
  1674. . $form->format_amount( \%myconfig, $totalfxnetamount, 2, "&nbsp;" )
  1675. . "</th>";
  1676. $column_data{fx_tax} = "<th class=listtotal align=right>"
  1677. . $form->format_amount( \%myconfig,
  1678. $totalfxamount - $totalfxnetamount,
  1679. 2, "&nbsp;" )
  1680. . "</th>";
  1681. $column_data{fx_amount} =
  1682. "<th class=listtotal align=right>"
  1683. . $form->format_amount( \%myconfig, $totalfxamount, 2, "&nbsp;" )
  1684. . "</th>";
  1685. $column_data{fx_paid} =
  1686. "<th class=listtotal align=right>"
  1687. . $form->format_amount( \%myconfig, $totalfxpaid, 2, "&nbsp;" )
  1688. . "</th>";
  1689. $column_data{fx_due} = "<th class=listtotal align=right>"
  1690. . $form->format_amount( \%myconfig, $totalfxamount - $totalfxpaid,
  1691. 2, "&nbsp;" )
  1692. . "</th>";
  1693. }
  1694. for (@column_index) { print "\n$column_data{$_}" }
  1695. if ( $myconfig{acs} !~ /$form->{ARAP}--$form->{ARAP}/ ) {
  1696. $i = 1;
  1697. if ( $form->{ARAP} eq 'AR' ) {
  1698. $button{'AR--Add Transaction'}{code} =
  1699. qq|<button class="submit" type="submit" name="action" value="ar_transaction">|
  1700. . $locale->text('AR Transaction')
  1701. . qq|</button> |;
  1702. $button{'AR--Add Transaction'}{order} = $i++;
  1703. $button{'AR--Sales Invoice'}{code} =
  1704. qq|<button class="submit" type="submit" name="action" value="sales_invoice_">|
  1705. . $locale->text('Sales Invoice.')
  1706. . qq|</button> |;
  1707. $button{'AR--Sales Invoice'}{order} = $i++;
  1708. }
  1709. else {
  1710. $button{'AP--Add Transaction'}{code} =
  1711. qq|<button class="submit" type="submit" name="action" value="ap_transaction">|
  1712. . $locale->text('AP Transaction')
  1713. . qq|</button> |;
  1714. $button{'AP--Add Transaction'}{order} = $i++;
  1715. $button{'AP--Vendor Invoice'}{code} =
  1716. qq|<button class="submit" type="submit" name="action" value="vendor_invoice_">|
  1717. . $locale->text('Vendor Invoice.')
  1718. . qq|</button> |;
  1719. $button{'AP--Vendor Invoice'}{order} = $i++;
  1720. }
  1721. foreach $item ( split /;/, $myconfig{acs} ) {
  1722. delete $button{$item};
  1723. }
  1724. }
  1725. print qq|
  1726. </tr>
  1727. </table>
  1728. </td>
  1729. </tr>
  1730. <tr>
  1731. <td><hr size=3 noshade></td>
  1732. </tr>
  1733. </table>
  1734. <br>
  1735. <form method=post action=$form->{script}>
  1736. |;
  1737. $form->hide_form(
  1738. "callback", "path", "login", "sessionid",
  1739. "$form->{vc}", "$form->{vc}_id"
  1740. );
  1741. if ( !$form->{till} ) {
  1742. foreach $item ( sort { $a->{order} <=> $b->{order} } %button ) {
  1743. print $item->{code};
  1744. }
  1745. }
  1746. if ( $form->{lynx} ) {
  1747. require "bin/menu.pl";
  1748. &menubar;
  1749. }
  1750. print qq|
  1751. </form>
  1752. </body>
  1753. </html>
  1754. |;
  1755. }
  1756. sub subtotal {
  1757. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  1758. $column_data{tax} = "<th class=listsubtotal align=right>"
  1759. . $form->format_amount( \%myconfig, $subtotalamount - $subtotalnetamount,
  1760. 2, "&nbsp;" )
  1761. . "</th>";
  1762. $column_data{amount} =
  1763. "<th class=listsubtotal align=right>"
  1764. . $form->format_amount( \%myconfig, $subtotalamount, 2, "&nbsp;" )
  1765. . "</th>";
  1766. $column_data{paid} =
  1767. "<th class=listsubtotal align=right>"
  1768. . $form->format_amount( \%myconfig, $subtotalpaid, 2, "&nbsp;" )
  1769. . "</th>";
  1770. $column_data{due} = "<th class=listsubtotal align=right>"
  1771. . $form->format_amount( \%myconfig, $subtotalamount - $subtotalpaid,
  1772. 2, "&nbsp;" )
  1773. . "</th>";
  1774. $column_data{debit} =
  1775. "<th class=listsubtotal align=right>"
  1776. . $form->format_amount( \%myconfig, $subtotaldebit, 2, "&nbsp;" )
  1777. . "</th>";
  1778. $column_data{credit} =
  1779. "<th class=listsubtotal align=right>"
  1780. . $form->format_amount( \%myconfig, $subtotalcredit, 2, "&nbsp;" )
  1781. . "</th>";
  1782. if ( $form->{l_curr} && $form->{sort} eq 'curr' && $form->{l_subtotal} ) {
  1783. $column_data{fx_tax} = "<th class=listsubtotal align=right>"
  1784. . $form->format_amount( \%myconfig,
  1785. $subtotalfxamount - $subtotalfxnetamount,
  1786. 2, "&nbsp;" )
  1787. . "</th>";
  1788. $column_data{fx_amount} =
  1789. "<th class=listsubtotal align=right>"
  1790. . $form->format_amount( \%myconfig, $subtotalfxamount, 2, "&nbsp;" )
  1791. . "</th>";
  1792. $column_data{fx_paid} =
  1793. "<th class=listsubtotal align=right>"
  1794. . $form->format_amount( \%myconfig, $subtotalfxpaid, 2, "&nbsp;" )
  1795. . "</th>";
  1796. $column_data{fx_due} = "<th class=listsubtotal align=right>"
  1797. . $form->format_amount( \%myconfig,
  1798. $subtotalfxmount - $subtotalfxpaid,
  1799. 2, "&nbsp;" )
  1800. . "</th>";
  1801. }
  1802. $subtotalnetamount = 0;
  1803. $subtotalamount = 0;
  1804. $subtotalpaid = 0;
  1805. $subtotaldebit = 0;
  1806. $subtotalcredit = 0;
  1807. $subtotalfxnetamount = 0;
  1808. $subtotalfxamount = 0;
  1809. $subtotalfxpaid = 0;
  1810. print "<tr class=listsubtotal>";
  1811. for (@column_index) { print "\n$column_data{$_}" }
  1812. print "
  1813. </tr>
  1814. ";
  1815. }