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