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