summaryrefslogtreecommitdiff
path: root/bin/aa.pl
blob: da60e1b4cf1662ea4e4e55bb722a1a76139c36af (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->{approved} && !$form->{batch_id}){
  755. $button{approve} = { ndx => 3, key => 'O', value => $locale->text('Post') };
  756. delete $button{post_as_new};
  757. delete $button{print_and_post_as_new};
  758. delete $button{post};
  759. delete $button{print_and_post};
  760. }
  761. if ($form->{separate_duties} || $form->{batch_id}){
  762. $button{post}->{value} = $locale->text('Save');
  763. $form->hide_form('separate_duties');
  764. }
  765. if ( $form->{id} ) {
  766. if ( $form->{locked} || ( $transdate && $transdate <= $closedto ) )
  767. {
  768. for ( "post", "print_and_post", "delete" ) {
  769. delete $button{$_};
  770. }
  771. }
  772. if ( !${LedgerSMB::Sysconfig::latex} ) {
  773. for ( "print_and_post", "print_and_post_as_new" ) {
  774. delete $button{$_};
  775. }
  776. }
  777. }
  778. else {
  779. for ( "post_as_new", "print_and_post_as_new", "delete" ) {
  780. delete $button{$_};
  781. }
  782. delete $button{"print_and_post"} if !${LedgerSMB::Sysconfig::latex};
  783. if ( $transdate && ($transdate <= $closedto) ) {
  784. for ( "post", "print_and_post" ) { delete $button{$_} }
  785. }
  786. }
  787. for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button )
  788. {
  789. $form->print_button( \%button, $_ );
  790. }
  791. }
  792. if ( $form->{lynx} ) {
  793. require "bin/menu.pl";
  794. &menubar;
  795. }
  796. print qq|
  797. </form>
  798. </body>
  799. </html>
  800. |;
  801. }
  802. sub approve {
  803. use LedgerSMB::DBObject::Draft;
  804. use LedgerSMB;
  805. my $lsmb = LedgerSMB->new();
  806. $lsmb->merge($form);
  807. my $draft = LedgerSMB::DBObject::Draft->new({base => $lsmb});
  808. $draft->approve();
  809. if ($form->{callback}){
  810. print "Location: $form->{callback}\n";
  811. print "Status: 302 Found\n\n";
  812. print "<html><body>";
  813. my $url = $form->{callback};
  814. print qq|If you are not redirected automatically, click <a href="$url">|
  815. . qq|here</a>.</body></html>|;
  816. } else {
  817. $form->info($locale->text('Draft Posted'));
  818. }
  819. }
  820. sub update {
  821. my $display = shift;
  822. $is_update = 1;
  823. if ( !$display ) {
  824. $form->{invtotal} = 0;
  825. $form->{exchangerate} =
  826. $form->parse_amount( \%myconfig, $form->{exchangerate} );
  827. @flds =
  828. ( "amount", "$form->{ARAP}_amount", "projectnumber", "description" );
  829. $count = 0;
  830. @a = ();
  831. for $i ( 1 .. $form->{rowcount} ) {
  832. $form->{"amount_$i"} =
  833. $form->parse_amount( \%myconfig, $form->{"amount_$i"} );
  834. if ( $form->{"amount_$i"} ) {
  835. push @a, {};
  836. $j = $#a;
  837. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  838. $count++;
  839. }
  840. }
  841. $form->redo_rows( \@flds, \@a, $count, $form->{rowcount} );
  842. $form->{rowcount} = $count + 1;
  843. for ( 1 .. $form->{rowcount} ) {
  844. $form->{invtotal} += $form->{"amount_$_"};
  845. }
  846. $form->{exchangerate} = $exchangerate
  847. if (
  848. $form->{forex} = (
  849. $exchangerate = $form->check_exchangerate(
  850. \%myconfig, $form->{currency}, $form->{transdate},
  851. ( $form->{ARAP} eq 'AR' ) ? 'buy' : 'sell'
  852. )
  853. )
  854. );
  855. if ( $newname = &check_name( $form->{vc} ) ) {
  856. $form->{notes} = $form->{intnotes} unless $form->{id};
  857. &rebuild_vc( $form->{vc}, $form->{ARAP}, $form->{transdate} );
  858. }
  859. if ( $form->{transdate} ne $form->{oldtransdate} ) {
  860. $form->{duedate} =
  861. $form->current_date( \%myconfig, $form->{transdate},
  862. $form->{terms} * 1 );
  863. $form->{oldtransdate} = $form->{transdate};
  864. $newproj =
  865. &rebuild_vc( $form->{vc}, $form->{ARAP}, $form->{transdate} )
  866. if !$newname;
  867. $form->all_projects( \%myconfig, undef, $form->{transdate} )
  868. if !$newproj;
  869. $form->{selectemployee} = "";
  870. if ( @{ $form->{all_employee} } ) {
  871. for ( @{ $form->{all_employee} } ) {
  872. $form->{selectemployee} .=
  873. qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
  874. }
  875. }
  876. }
  877. }
  878. @taxaccounts = split / /, $form->{taxaccounts};
  879. for (@taxaccounts) {
  880. $form->{"tax_$_"} =
  881. $form->parse_amount( \%myconfig, $form->{"tax_$_"} );
  882. }
  883. @taxaccounts = Tax::init_taxes( $form, $form->{taxaccounts} );
  884. $j = 1;
  885. for $i ( 1 .. $form->{paidaccounts} ) {
  886. if ( $form->{"paid_$i"} ) {
  887. for (qw(datepaid source memo cleared)) {
  888. $form->{"${_}_$j"} = $form->{"${_}_$i"};
  889. }
  890. for (qw(paid exchangerate)) {
  891. $form->{"${_}_$j"} =
  892. $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
  893. }
  894. $totalpaid += $form->{"paid_$j"};
  895. $form->{"exchangerate_$j"} = $exchangerate
  896. if (
  897. $form->{"forex_$j"} = (
  898. $exchangerate = $form->check_exchangerate(
  899. \%myconfig, $form->{currency},
  900. $form->{"datepaid_$j"},
  901. ( $form->{ARAP} eq 'AR' ) ? 'buy' : 'sell'
  902. )
  903. )
  904. );
  905. if ( $j++ != $i ) {
  906. for (qw(datepaid source memo paid exchangerate forex cleared)) {
  907. delete $form->{"${_}_$i"};
  908. }
  909. }
  910. }
  911. else {
  912. for (qw(datepaid source memo paid exchangerate forex cleared)) {
  913. delete $form->{"${_}_$i"};
  914. }
  915. }
  916. }
  917. $form->{paidaccounts} = $j;
  918. $form->{creditremaining} -=
  919. ( $form->{invtotal} - $totalpaid + $form->{oldtotalpaid} -
  920. $form->{oldinvtotal} );
  921. $form->{oldinvtotal} = $form->{invtotal};
  922. $form->{oldtotalpaid} = $totalpaid;
  923. &display_form;
  924. }
  925. sub post {
  926. $label =
  927. ( $form->{vc} eq 'customer' )
  928. ? $locale->text('Customer missing!')
  929. : $locale->text('Vendor missing!');
  930. # check if there is an invoice number, invoice and due date
  931. $form->isblank( "transdate", $locale->text('Invoice Date missing!') );
  932. $form->isblank( "duedate", $locale->text('Due Date missing!') );
  933. $form->isblank( $form->{vc}, $label );
  934. $closedto = $form->datetonum( \%myconfig, $form->{closedto} );
  935. $transdate = $form->datetonum( \%myconfig, $form->{transdate} );
  936. $form->error(
  937. $locale->text('Cannot post transaction for a closed period!') )
  938. if ( $transdate <= $closedto );
  939. $form->isblank( "exchangerate", $locale->text('Exchange rate missing!') )
  940. if ( $form->{currency} ne $form->{defaultcurrency} );
  941. for $i ( 1 .. $form->{paidaccounts} ) {
  942. if ( $form->{"paid_$i"} ) {
  943. $datepaid = $form->datetonum( \%myconfig, $form->{"datepaid_$i"} );
  944. $form->isblank( "datepaid_$i",
  945. $locale->text('Payment date missing!') );
  946. $form->error(
  947. $locale->text('Cannot post payment for a closed period!') )
  948. if ( $datepaid <= $closedto );
  949. if ( $form->{currency} ne $form->{defaultcurrency} ) {
  950. $form->{"exchangerate_$i"} = $form->{exchangerate}
  951. if ( $transdate == $datepaid );
  952. $form->isblank( "exchangerate_$i",
  953. $locale->text('Exchange rate for payment missing!') );
  954. }
  955. }
  956. }
  957. # if oldname ne name redo form
  958. ($name) = split /--/, $form->{ $form->{vc} };
  959. if ( $form->{"old$form->{vc}"} ne qq|$name--$form->{"$form->{vc}_id"}| ) {
  960. &update;
  961. exit;
  962. }
  963. if ( !$form->{repost} ) {
  964. if ( $form->{id} ) {
  965. &repost;
  966. exit;
  967. }
  968. }
  969. if ( AA->post_transaction( \%myconfig, \%$form ) ) {
  970. $form->update_status( \%myconfig );
  971. if ( $form->{printandpost} ) {
  972. &{"print_$form->{formname}"}( $old_form, 1 );
  973. }
  974. $form->redirect( $locale->text('Transaction posted!') );
  975. }
  976. else {
  977. $form->error( $locale->text('Cannot post transaction!') );
  978. }
  979. }
  980. sub delete {
  981. $form->{title} = $locale->text('Confirm!');
  982. $form->header;
  983. print qq|
  984. <body>
  985. <form method=post action=$form->{script}>
  986. |;
  987. $form->{action} = "yes";
  988. $form->hide_form;
  989. print qq|
  990. <h2 class=confirm>$form->{title}</h2>
  991. <h4>|
  992. . $locale->text('Are you sure you want to delete Transaction')
  993. . qq| $form->{invnumber}</h4>
  994. <button name="action" class="submit" type="submit" value="yes">|
  995. . $locale->text('Yes')
  996. . qq|</button>
  997. </form>
  998. </body>
  999. </html>
  1000. |;
  1001. }
  1002. sub yes {
  1003. if (
  1004. AA->delete_transaction(
  1005. \%myconfig, \%$form, ${LedgerSMB::Sysconfig::spool}
  1006. )
  1007. )
  1008. {
  1009. $form->redirect( $locale->text('Transaction deleted!') );
  1010. }
  1011. else {
  1012. $form->error( $locale->text('Cannot delete transaction!') );
  1013. }
  1014. }
  1015. sub search {
  1016. $form->create_links( $form->{ARAP}, \%myconfig, $form->{vc} );
  1017. $form->{"select$form->{ARAP}"} = "<option>\n";
  1018. for ( @{ $form->{"$form->{ARAP}_links"}{ $form->{ARAP} } } ) {
  1019. $form->{"select$form->{ARAP}"} .=
  1020. "<option>$_->{accno}--$_->{description}\n";
  1021. }
  1022. if ( @{ $form->{"all_$form->{vc}"} } ) {
  1023. $selectname = "";
  1024. for ( @{ $form->{"all_$form->{vc}"} } ) {
  1025. $selectname .=
  1026. qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
  1027. }
  1028. $selectname =
  1029. qq|<select name="$form->{vc}"><option>\n$selectname</select>|;
  1030. }
  1031. else {
  1032. $selectname = qq|<input name=$form->{vc} size=35>|;
  1033. }
  1034. # departments
  1035. if ( @{ $form->{all_department} } ) {
  1036. $form->{selectdepartment} = "<option>\n";
  1037. for ( @{ $form->{all_department} } ) {
  1038. $form->{selectdepartment} .=
  1039. qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
  1040. }
  1041. $l_department =
  1042. qq|<input name="l_department" class=checkbox type=checkbox value=Y> |
  1043. . $locale->text('Department');
  1044. $department = qq|
  1045. <tr>
  1046. <th align=right nowrap>| . $locale->text('Department') . qq|</th>
  1047. <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
  1048. </tr>
  1049. |;
  1050. }
  1051. if ( @{ $form->{all_employee} } ) {
  1052. $form->{selectemployee} = "<option>\n";
  1053. for ( @{ $form->{all_employee} } ) {
  1054. $form->{selectemployee} .=
  1055. qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
  1056. }
  1057. $employeelabel =
  1058. ( $form->{ARAP} eq 'AR' )
  1059. ? $locale->text('Salesperson')
  1060. : $locale->text('Employee');
  1061. $employee = qq|
  1062. <tr>
  1063. <th align=right nowrap>$employeelabel</th>
  1064. <td colspan=3><select name=employee>$form->{selectemployee}</select></td>
  1065. </tr>
  1066. |;
  1067. $l_employee =
  1068. qq|<input name="l_employee" class=checkbox type=checkbox value=Y> $employeelabel|;
  1069. $l_manager =
  1070. qq|<input name="l_manager" class=checkbox type=checkbox value=Y> |
  1071. . $locale->text('Manager');
  1072. }
  1073. $form->{title} =
  1074. ( $form->{ARAP} eq 'AR' )
  1075. ? $locale->text('AR Transactions')
  1076. : $locale->text('AP Transactions');
  1077. $invnumber = qq|
  1078. <tr>
  1079. <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
  1080. <td colspan=3><input name=invnumber size=20></td>
  1081. </tr>
  1082. <tr>
  1083. <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
  1084. <td colspan=3><input name=ordnumber size=20></td>
  1085. </tr>
  1086. <tr>
  1087. <th align=right nowrap>| . $locale->text('PO Number') . qq|</th>
  1088. <td colspan=3><input name=ponumber size=20></td>
  1089. </tr>
  1090. <tr>
  1091. <th align=right nowrap>| . $locale->text('Source') . qq|</th>
  1092. <td colspan=3><input name=source size=40></td>
  1093. </tr>
  1094. <tr>
  1095. <th align=right nowrap>| . $locale->text('Description') . qq|</th>
  1096. <td colspan=3><input name=description size=40></td>
  1097. </tr>
  1098. <tr>
  1099. <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
  1100. <td colspan=3><input name=notes size=40></td>
  1101. </tr>
  1102. |;
  1103. $openclosed = qq|
  1104. <tr>
  1105. <td nowrap><input name=open class=checkbox type=checkbox value=Y checked> |
  1106. . $locale->text('Open')
  1107. . qq|</td>
  1108. <td nowrap><input name=closed class=checkbox type=checkbox value=Y> |
  1109. . $locale->text('Closed')
  1110. . qq|</td>
  1111. </tr>
  1112. |;
  1113. $summary = qq|
  1114. <tr>
  1115. <td><input name=summary type=radio class=radio value=1 checked> |
  1116. . $locale->text('Summary')
  1117. . qq|</td>
  1118. <td><input name=summary type=radio class=radio value=0> |
  1119. . $locale->text('Detail') . qq|
  1120. </td>
  1121. </tr>
  1122. |;
  1123. if ( $form->{outstanding} ) {
  1124. $form->{title} =
  1125. ( $form->{ARAP} eq 'AR' )
  1126. ? $locale->text('AR Outstanding')
  1127. : $locale->text('AP Outstanding');
  1128. $invnumber = "";
  1129. $openclosed = "";
  1130. $summary = "";
  1131. }
  1132. if ( @{ $form->{all_years} } ) {
  1133. # accounting years
  1134. $form->{selectaccountingyear} = "<option>\n";
  1135. for ( @{ $form->{all_years} } ) {
  1136. $form->{selectaccountingyear} .= qq|<option>$_\n|;
  1137. }
  1138. $form->{selectaccountingmonth} = "<option>\n";
  1139. for ( sort keys %{ $form->{all_month} } ) {
  1140. $form->{selectaccountingmonth} .=
  1141. qq|<option value=$_>|
  1142. . $locale->text( $form->{all_month}{$_} ) . qq|\n|;
  1143. }
  1144. $selectfrom = qq|
  1145. <tr>
  1146. <th align=right>| . $locale->text('Period') . qq|</th>
  1147. <td colspan=3>
  1148. <select name=month>$form->{selectaccountingmonth}</select>
  1149. <select name=year>$form->{selectaccountingyear}</select>
  1150. <input name=interval class=radio type=radio value=0 checked>&nbsp;|
  1151. . $locale->text('Current') . qq|
  1152. <input name=interval class=radio type=radio value=1>&nbsp;|
  1153. . $locale->text('Month') . qq|
  1154. <input name=interval class=radio type=radio value=3>&nbsp;|
  1155. . $locale->text('Quarter') . qq|
  1156. <input name=interval class=radio type=radio value=12>&nbsp;|
  1157. . $locale->text('Year') . qq|
  1158. </td>
  1159. </tr>
  1160. |;
  1161. }
  1162. $name = $locale->text('Customer');
  1163. $l_name =
  1164. qq|<input name="l_name" class=checkbox type=checkbox value=Y checked> $name|;
  1165. $l_till =
  1166. qq|<input name="l_till" class=checkbox type=checkbox value=Y> |
  1167. . $locale->text('Till');
  1168. if ( $form->{vc} eq 'vendor' ) {
  1169. $name = $locale->text('Vendor');
  1170. $l_till = "";
  1171. $l_name =
  1172. qq|<input name="l_name" class=checkbox type=checkbox value=Y checked> $name|;
  1173. }
  1174. @a = ();
  1175. push @a,
  1176. qq|<input name="l_runningnumber" class=checkbox type=checkbox value=Y> |
  1177. . $locale->text('No.');
  1178. push @a, qq|<input name="l_id" class=checkbox type=checkbox value=Y> |
  1179. . $locale->text('ID');
  1180. push @a,
  1181. qq|<input name="l_invnumber" class=checkbox type=checkbox value=Y checked> |
  1182. . $locale->text('Invoice Number');
  1183. push @a,
  1184. qq|<input name="l_ordnumber" class=checkbox type=checkbox value=Y> |
  1185. . $locale->text('Order Number');
  1186. push @a, qq|<input name="l_ponumber" class=checkbox type=checkbox value=Y> |
  1187. . $locale->text('PO Number');
  1188. push @a,
  1189. qq|<input name="l_transdate" class=checkbox type=checkbox value=Y checked> |
  1190. . $locale->text('Invoice Date');
  1191. push @a, $l_name;
  1192. push @a, $l_employee if $l_employee;
  1193. push @a, $l_manager if $l_employee;
  1194. push @a, $l_department if $l_department;
  1195. push @a,
  1196. qq|<input name="l_netamount" class=checkbox type=checkbox value=Y> |
  1197. . $locale->text('Amount');
  1198. push @a, qq|<input name="l_tax" class=checkbox type=checkbox value=Y> |
  1199. . $locale->text('Tax');
  1200. push @a,
  1201. qq|<input name="l_amount" class=checkbox type=checkbox value=Y checked> |
  1202. . $locale->text('Total');
  1203. push @a, qq|<input name="l_curr" class=checkbox type=checkbox value=Y> |
  1204. . $locale->text('Currency');
  1205. push @a, qq|<input name="l_datepaid" class=checkbox type=checkbox value=Y> |
  1206. . $locale->text('Date Paid');
  1207. push @a,
  1208. qq|<input name="l_paid" class=checkbox type=checkbox value=Y checked> |
  1209. . $locale->text('Paid');
  1210. push @a, qq|<input name="l_duedate" class=checkbox type=checkbox value=Y> |
  1211. . $locale->text('Due Date');
  1212. push @a, qq|<input name="l_due" class=checkbox type=checkbox value=Y> |
  1213. . $locale->text('Amount Due');
  1214. push @a, qq|<input name="l_notes" class=checkbox type=checkbox value=Y> |
  1215. . $locale->text('Notes');
  1216. push @a, $l_till if $l_till;
  1217. push @a,
  1218. qq|<input name="l_shippingpoint" class=checkbox type=checkbox value=Y> |
  1219. . $locale->text('Shipping Point');
  1220. push @a, qq|<input name="l_shipvia" class=checkbox type=checkbox value=Y> |
  1221. . $locale->text('Ship via');
  1222. $form->header;
  1223. print qq|
  1224. <body>
  1225. <form method=post action=$form->{script}>
  1226. <table width=100%>
  1227. <tr><th class=listtop>$form->{title}</th></tr>
  1228. <tr height="5"></tr>
  1229. <tr>
  1230. <td>
  1231. <table>
  1232. <tr>
  1233. <th align=right>| . $locale->text('Account') . qq|</th>
  1234. <td colspan=3><select name=$form->{ARAP}>$form->{"select$form->{ARAP}"}</select></td>
  1235. </tr>
  1236. <tr>
  1237. <th align=right>$name</th>
  1238. <td colspan=3>$selectname</td>
  1239. </tr>
  1240. <tr><th align="right">|.$locale->text('Number').qq|</th>
  1241. <td colspan="3"><input name="meta_number" size="36">
  1242. </tr>
  1243. $employee
  1244. $department
  1245. $invnumber
  1246. <tr>
  1247. <th align=right>| . $locale->text('Ship via') . qq|</th>
  1248. <td colspan=3><input name=shipvia size=40></td>
  1249. </tr>
  1250. <tr>
  1251. <th align=right nowrap>| . $locale->text('From') . qq|</th>
  1252. <td><input class="date" name=transdatefrom size=11 title="$myconfig{dateformat}"></td>
  1253. <th align=right>| . $locale->text('To') . qq|</th>
  1254. <td><input class="date" name=transdateto size=11 title="$myconfig{dateformat}"></td>
  1255. </tr>
  1256. $selectfrom
  1257. </table>
  1258. </td>
  1259. </tr>
  1260. <tr>
  1261. <td>
  1262. |.$locale->text('All Invoices').qq|: <input type="radio" name="invoice_type" checked value="1">
  1263. |.$locale->text('Active').qq|: <input type="radio" name="invoice_type" value="2">
  1264. |.$locale->text('On Hold').qq|: <input type="radio" name="invoice_type" value="3">
  1265. <br/>
  1266. </td>
  1267. </tr>
  1268. <tr>
  1269. <td>
  1270. <table>
  1271. <tr>
  1272. <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
  1273. <td>
  1274. <table width=100%>
  1275. $openclosed
  1276. $summary
  1277. |;
  1278. $form->{sort} = "transdate";
  1279. $form->hide_form(qw(title outstanding sort));
  1280. while (@a) {
  1281. for ( 1 .. 5 ) {
  1282. print qq|<td nowrap>| . shift @a;
  1283. print qq|</td>\n|;
  1284. }
  1285. print qq|</tr>\n|;
  1286. }
  1287. print qq|
  1288. <tr>
  1289. <td nowrap><input name="l_subtotal" class=checkbox type=checkbox value=Y> |
  1290. . $locale->text('Subtotal')
  1291. . qq|</td>
  1292. </tr>
  1293. </table>
  1294. </td>
  1295. </tr>
  1296. </table>
  1297. </td>
  1298. </tr>
  1299. <tr>
  1300. <td><hr size=3 noshade></td>
  1301. </tr>
  1302. </table>
  1303. <br>
  1304. <input type="hidden" name="action" value="continue">
  1305. <button class="submit" type="submit" name="action" value="continue">|
  1306. . $locale->text('Continue')
  1307. . qq|</button>|;
  1308. $form->hide_form(qw(nextsub path login sessionid));
  1309. print qq|
  1310. </form>
  1311. |;
  1312. if ( $form->{lynx} ) {
  1313. require "bin/menu.pl";
  1314. &menubar;
  1315. }
  1316. print qq|
  1317. </body>
  1318. </html>
  1319. |;
  1320. }
  1321. sub transactions {
  1322. # it shouldn't be putting it into vendor_id or customer_id, but into
  1323. # entity_id, conforming to the new entity tables.
  1324. if ( $form->{ $form->{vc} } ) {
  1325. $form->{ $form->{vc} } = $form->unescape( $form->{ $form->{vc} } );
  1326. ( $form->{ $form->{vc} }, $form->{"$form->{vc}_id"} ) =
  1327. split( /--/, $form->{ $form->{vc} } );
  1328. }
  1329. @column_index;
  1330. AA->transactions( \%myconfig, \%$form );
  1331. $href = "$form->{script}?action=transactions";
  1332. for (qw(direction oldsort till outstanding path login sessionid summary)) {
  1333. $href .= qq|&$_=$form->{$_}|;
  1334. }
  1335. $href .= "&title=" . $form->escape( $form->{title} );
  1336. $form->sort_order();
  1337. $callback = "$form->{script}?action=transactions";
  1338. for (qw(direction oldsort till outstanding path login sessionid summary)) {
  1339. $callback .= qq|&$_=$form->{$_}|;
  1340. }
  1341. $callback .= "&title=" . $form->escape( $form->{title}, 1 );
  1342. if ( $form->{ $form->{ARAP} } ) {
  1343. $callback .=
  1344. "&$form->{ARAP}=" . $form->escape( $form->{ $form->{ARAP} }, 1 );
  1345. $href .= "&$form->{ARAP}=" . $form->escape( $form->{ $form->{ARAP} } );
  1346. $form->{ $form->{ARAP} } =~ s/--/ /;
  1347. $option = $locale->text('Account') . " : $form->{$form->{ARAP}}";
  1348. }
  1349. if ( $form->{ $form->{vc} } ) {
  1350. $callback .=
  1351. "&$form->{vc}="
  1352. . $form->escape( $form->{ $form->{vc} }, 1 )
  1353. . qq|--$form->{"$form->{vc}_id"}|;
  1354. $href .=
  1355. "&$form->{vc}="
  1356. . $form->escape( $form->{ $form->{vc} } )
  1357. . qq|--$form->{"$form->{vc}_id"}|;
  1358. $option .= "\n<br>" if ($option);
  1359. $name =
  1360. ( $form->{vc} eq 'customer' )
  1361. ? $locale->text('Customer')
  1362. : $locale->text('Vendor');
  1363. $option .= "$name : $form->{$form->{vc}}";
  1364. }
  1365. if ( $form->{department} ) {
  1366. $callback .= "&department=" . $form->escape( $form->{department}, 1 );
  1367. $href .= "&department=" . $form->escape( $form->{department} );
  1368. ($department) = split /--/, $form->{department};
  1369. $option .= "\n<br>" if ($option);
  1370. $option .= $locale->text('Department') . " : $department";
  1371. }
  1372. if ( $form->{employee} ) {
  1373. $callback .= "&employee=" . $form->escape( $form->{employee}, 1 );
  1374. $href .= "&employee=" . $form->escape( $form->{employee} );
  1375. ($employee) = split /--/, $form->{employee};
  1376. $option .= "\n<br>" if ($option);
  1377. if ( $form->{ARAP} eq 'AR' ) {
  1378. $option .= $locale->text('Salesperson');
  1379. }
  1380. else {
  1381. $option .= $locale->text('Employee');
  1382. }
  1383. $option .= " : $employee";
  1384. }
  1385. if ( $form->{invnumber} ) {
  1386. $callback .= "&invnumber=" . $form->escape( $form->{invnumber}, 1 );
  1387. $href .= "&invnumber=" . $form->escape( $form->{invnumber} );
  1388. $option .= "\n<br>" if ($option);
  1389. $option .= $locale->text('Invoice Number') . " : $form->{invnumber}";
  1390. }
  1391. if ( $form->{ordnumber} ) {
  1392. $callback .= "&ordnumber=" . $form->escape( $form->{ordnumber}, 1 );
  1393. $href .= "&ordnumber=" . $form->escape( $form->{ordnumber} );
  1394. $option .= "\n<br>" if ($option);
  1395. $option .= $locale->text('Order Number') . " : $form->{ordnumber}";
  1396. }
  1397. if ( $form->{ponumber} ) {
  1398. $callback .= "&ponumber=" . $form->escape( $form->{ponumber}, 1 );
  1399. $href .= "&ponumber=" . $form->escape( $form->{ponumber} );
  1400. $option .= "\n<br>" if ($option);
  1401. $option .= $locale->text('PO Number') . " : $form->{ponumber}";
  1402. }
  1403. if ( $form->{source} ) {
  1404. $callback .= "&source=" . $form->escape( $form->{source}, 1 );
  1405. $href .= "&source=" . $form->escape( $form->{source} );
  1406. $option .= "\n<br>" if $option;
  1407. $option .= $locale->text('Source') . " : $form->{source}";
  1408. }
  1409. if ( $form->{description} ) {
  1410. $callback .= "&description=" . $form->escape( $form->{description}, 1 );
  1411. $href .= "&description=" . $form->escape( $form->{description} );
  1412. $option .= "\n<br>" if $option;
  1413. $option .= $locale->text('Description') . " : $form->{description}";
  1414. }
  1415. if ( $form->{notes} ) {
  1416. $callback .= "&notes=" . $form->escape( $form->{notes}, 1 );
  1417. $href .= "&notes=" . $form->escape( $form->{notes} );
  1418. $option .= "\n<br>" if $option;
  1419. $option .= $locale->text('Notes') . " : $form->{notes}";
  1420. }
  1421. if ( $form->{shipvia} ) {
  1422. $callback .= "&shipvia=" . $form->escape( $form->{shipvia}, 1 );
  1423. $href .= "&shipvia=" . $form->escape( $form->{shipvia} );
  1424. $option .= "\n<br>" if $option;
  1425. $option .= $locale->text('Ship via') . " : $form->{shipvia}";
  1426. }
  1427. if ( $form->{transdatefrom} ) {
  1428. $callback .= "&transdatefrom=$form->{transdatefrom}";
  1429. $href .= "&transdatefrom=$form->{transdatefrom}";
  1430. $option .= "\n<br>" if ($option);
  1431. $option .=
  1432. $locale->text('From') . "&nbsp;"
  1433. . $locale->date( \%myconfig, $form->{transdatefrom}, 1 );
  1434. }
  1435. if ( $form->{transdateto} ) {
  1436. $callback .= "&transdateto=$form->{transdateto}";
  1437. $href .= "&transdateto=$form->{transdateto}";
  1438. $option .= "\n<br>" if ($option);
  1439. $option .=
  1440. $locale->text( 'To [_1]',
  1441. $locale->date( \%myconfig, $form->{transdateto}, 1 ) );
  1442. }
  1443. if ( $form->{open} ) {
  1444. $callback .= "&open=$form->{open}";
  1445. $href .= "&open=$form->{open}";
  1446. $option .= "\n<br>" if ($option);
  1447. $option .= $locale->text('Open');
  1448. }
  1449. if ( $form->{closed} ) {
  1450. $callback .= "&closed=$form->{closed}";
  1451. $href .= "&closed=$form->{closed}";
  1452. $option .= "\n<br>" if ($option);
  1453. $option .= $locale->text('Closed');
  1454. }
  1455. @columns =
  1456. $form->sort_columns(
  1457. qw(transdate id invnumber ordnumber ponumber name netamount tax amount paid due curr datepaid duedate notes till employee manager shippingpoint shipvia department)
  1458. );
  1459. pop @columns if $form->{department};
  1460. unshift @columns, "runningnumber";
  1461. foreach $item (@columns) {
  1462. if ( $form->{"l_$item"} eq "Y" ) {
  1463. push @column_index, $item;
  1464. if ( $form->{l_curr} && $item =~ /(amount|tax|paid|due)/ ) {
  1465. push @column_index, "fx_$item";
  1466. }
  1467. # add column to href and callback
  1468. $callback .= "&l_$item=Y";
  1469. $href .= "&l_$item=Y";
  1470. }
  1471. }
  1472. if ( !$form->{summary} ) {
  1473. foreach $item (qw(source debit credit accno description projectnumber))
  1474. {
  1475. push @column_index, $item;
  1476. }
  1477. }
  1478. if ( $form->{l_subtotal} eq 'Y' ) {
  1479. $callback .= "&l_subtotal=Y";
  1480. $href .= "&l_subtotal=Y";
  1481. }
  1482. $employee =
  1483. ( $form->{ARAP} eq 'AR' )
  1484. ? $locale->text('Salesperson')
  1485. : $locale->text('Employee');
  1486. $name =
  1487. ( $form->{vc} eq 'customer' )
  1488. ? $locale->text('Customer')
  1489. : $locale->text('Vendor');
  1490. $column_header{runningnumber} = qq|<th class=listheading>&nbsp;</th>|;
  1491. $column_header{id} =
  1492. "<th><a class=listheading href=$href&sort=id>"
  1493. . $locale->text('ID')
  1494. . "</a></th>";
  1495. $column_header{transdate} =
  1496. "<th><a class=listheading href=$href&sort=transdate>"
  1497. . $locale->text('Date')
  1498. . "</a></th>";
  1499. $column_header{duedate} =
  1500. "<th><a class=listheading href=$href&sort=duedate>"
  1501. . $locale->text('Due Date')
  1502. . "</a></th>";
  1503. $column_header{invnumber} =
  1504. "<th><a class=listheading href=$href&sort=invnumber>"
  1505. . $locale->text('Invoice')
  1506. . "</a></th>";
  1507. $column_header{ordnumber} =
  1508. "<th><a class=listheading href=$href&sort=ordnumber>"
  1509. . $locale->text('Order')
  1510. . "</a></th>";
  1511. $column_header{ponumber} =
  1512. "<th><a class=listheading href=$href&sort=ponumber>"
  1513. . $locale->text('PO Number')
  1514. . "</a></th>";
  1515. $column_header{name} =
  1516. "<th>".$locale->text('Account')."</th><th><a class=listheading href=$href&sort=name>$name</a></th>";
  1517. $column_header{netamount} =
  1518. "<th class=listheading>" . $locale->text('Amount') . "</th>";
  1519. $column_header{tax} =
  1520. "<th class=listheading>" . $locale->text('Tax') . "</th>";
  1521. $column_header{amount} =
  1522. "<th class=listheading>" . $locale->text('Total') . "</th>";
  1523. $column_header{paid} =
  1524. "<th class=listheading>" . $locale->text('Paid') . "</th>";
  1525. $column_header{datepaid} =
  1526. "<th><a class=listheading href=$href&sort=datepaid>"
  1527. . $locale->text('Date Paid')
  1528. . "</a></th>";
  1529. $column_header{due} =
  1530. "<th class=listheading>" . $locale->text('Amount Due') . "</th>";
  1531. $column_header{notes} =
  1532. "<th class=listheading>" . $locale->text('Notes') . "</th>";
  1533. $column_header{employee} =
  1534. "<th><a class=listheading href=$href&sort=employee>$employee</th>";
  1535. $column_header{manager} =
  1536. "<th><a class=listheading href=$href&sort=manager>"
  1537. . $locale->text('Manager') . "</th>";
  1538. $column_header{till} =
  1539. "<th class=listheading><a class=listheading href=$href&sort=till>"
  1540. . $locale->text('Till') . "</th>";
  1541. $column_header{shippingpoint} =
  1542. "<th><a class=listheading href=$href&sort=shippingpoint>"
  1543. . $locale->text('Shipping Point')
  1544. . "</a></th>";
  1545. $column_header{shipvia} =
  1546. "<th><a class=listheading href=$href&sort=shipvia>"
  1547. . $locale->text('Ship via')
  1548. . "</a></th>";
  1549. $column_header{curr} =
  1550. "<th><a class=listheading href=$href&sort=curr>"
  1551. . $locale->text('Curr')
  1552. . "</a></th>";
  1553. for (qw(amount tax netamount paid due)) {
  1554. $column_header{"fx_$_"} = "<th>&nbsp;</th>";
  1555. }
  1556. $column_header{department} =
  1557. "<th><a class=listheading href=$href&sort=department>"
  1558. . $locale->text('Department')
  1559. . "</a></th>";
  1560. $column_header{accno} =
  1561. "<th><a class=listheading href=$href&sort=accno>"
  1562. . $locale->text('Account')
  1563. . "</a></th>";
  1564. $column_header{source} =
  1565. "<th><a class=listheading href=$href&sort=source>"
  1566. . $locale->text('Source')
  1567. . "</a></th>";
  1568. $column_header{debit} =
  1569. "<th class=listheading>" . $locale->text('Debit') . "</th>";
  1570. $column_header{credit} =
  1571. "<th class=listheading>" . $locale->text('Credit') . "</th>";
  1572. $column_header{projectnumber} =
  1573. "<th><a class=listheading href=$href&sort=projectnumber>"
  1574. . $locale->text('Project')
  1575. . "</a></th>";
  1576. $column_header{description} =
  1577. "<th><a class=listheading href=$href&sort=linedescription>"
  1578. . $locale->text('Description')
  1579. . "</a></th>";
  1580. $form->{title} =
  1581. ( $form->{title} ) ? $form->{title} : $locale->text('AR Transactions');
  1582. $form->header;
  1583. print qq|
  1584. <body>
  1585. <table width=100%>
  1586. <tr>
  1587. <th class=listtop>$form->{title}</th>
  1588. </tr>
  1589. <tr height="5"></tr>
  1590. <tr>
  1591. <td>$option</td>
  1592. </tr>
  1593. <tr>
  1594. <td>
  1595. <table width=100%>
  1596. <tr class=listheading>
  1597. |;
  1598. for (@column_index) { print "\n$column_header{$_}" }
  1599. print qq|
  1600. </tr>
  1601. |;
  1602. # add sort and escape callback, this one we use for the add sub
  1603. $form->{callback} = $callback .= "&sort=$form->{sort}";
  1604. # escape callback for href
  1605. $callback = $form->escape($callback);
  1606. # flip direction
  1607. $direction = ( $form->{direction} eq 'ASC' ) ? "ASC" : "DESC";
  1608. $href =~ s/&direction=(\w+)&/&direction=$direction&/;
  1609. if ( @{ $form->{transactions} } ) {
  1610. $sameitem = $form->{transactions}->[0]->{ $form->{sort} };
  1611. }
  1612. # sums and tax on reports by Antonio Gallardo
  1613. #
  1614. $i = 0;
  1615. foreach $ref ( @{ $form->{transactions} } ) {
  1616. $i++;
  1617. if ( $form->{l_subtotal} eq 'Y' ) {
  1618. if ( $sameitem ne $ref->{ $form->{sort} } ) {
  1619. &subtotal;
  1620. $sameitem = $ref->{ $form->{sort} };
  1621. }
  1622. }
  1623. if ( $form->{l_curr} ) {
  1624. for (qw(netamount amount paid)) {
  1625. $ref->{"fx_$_"} = $ref->{$_} / $ref->{exchangerate};
  1626. }
  1627. for (qw(netamount amount paid)) {
  1628. $column_data{"fx_$_"} = "<td align=right>"
  1629. . $form->format_amount( \%myconfig, $ref->{"fx_$_"}, 2,
  1630. "&nbsp;" )
  1631. . "</td>";
  1632. }
  1633. $column_data{fx_tax} = "<td align=right>"
  1634. . $form->format_amount( \%myconfig,
  1635. $ref->{fx_amount} - $ref->{fx_netamount},
  1636. 2, "&nbsp;" )
  1637. . "</td>";
  1638. $column_data{fx_due} = "<td align=right>"
  1639. . $form->format_amount( \%myconfig,
  1640. $ref->{fx_amount} - $ref->{fx_paid},
  1641. 2, "&nbsp;" )
  1642. . "</td>";
  1643. $subtotalfxnetamount += $ref->{fx_netamount};
  1644. $subtotalfxamount += $ref->{fx_amount};
  1645. $subtotalfxpaid += $ref->{fx_paid};
  1646. $totalfxnetamount += $ref->{fx_netamount};
  1647. $totalfxamount += $ref->{fx_amount};
  1648. $totalfxpaid += $ref->{fx_paid};
  1649. }
  1650. $column_data{runningnumber} = "<td align=right>$i</td>";
  1651. for (qw(netamount amount paid debit credit)) {
  1652. $column_data{$_} =
  1653. "<td align=right>"
  1654. . $form->format_amount( \%myconfig, $ref->{$_}, 2, "&nbsp;" )
  1655. . "</td>";
  1656. }
  1657. $column_data{tax} = "<td align=right>"
  1658. . $form->format_amount( \%myconfig,
  1659. $ref->{amount} - $ref->{netamount},
  1660. 2, "&nbsp;" )
  1661. . "</td>";
  1662. $column_data{due} = "<td align=right>"
  1663. . $form->format_amount( \%myconfig, $ref->{amount} - $ref->{paid},
  1664. 2, "&nbsp;" )
  1665. . "</td>";
  1666. $subtotalnetamount += $ref->{netamount};
  1667. $subtotalamount += $ref->{amount};
  1668. $subtotalpaid += $ref->{paid};
  1669. $subtotaldebit += $ref->{debit};
  1670. $subtotalcredit += $ref->{credit};
  1671. $totalnetamount += $ref->{netamount};
  1672. $totalamount += $ref->{amount};
  1673. $totalpaid += $ref->{paid};
  1674. $totaldebit += $ref->{debit};
  1675. $totalcredit += $ref->{credit};
  1676. $module =
  1677. ( $ref->{invoice} )
  1678. ? ( $form->{ARAP} eq 'AR' ) ? "is.pl" : "ir.pl"
  1679. : $form->{script};
  1680. $module = ( $ref->{till} ) ? "ps.pl" : $module;
  1681. $column_data{invnumber} =
  1682. "<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>";
  1683. for (qw(notes description)) { $ref->{$_} =~ s/\r?\n/<br>/g }
  1684. for (
  1685. qw(transdate datepaid duedate department ordnumber ponumber notes shippingpoint shipvia employee manager till source description projectnumber)
  1686. )
  1687. {
  1688. $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>";
  1689. }
  1690. for (qw(id curr)) { $column_data{$_} = "<td>$ref->{$_}</td>" }
  1691. $column_data{accno} =
  1692. 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>|;
  1693. $column_data{name} =
  1694. 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>|;
  1695. if ( $ref->{id} != $sameid ) {
  1696. $j++;
  1697. $j %= 2;
  1698. }
  1699. print "
  1700. <tr class=listrow$j>
  1701. ";
  1702. for (@column_index) { print "\n$column_data{$_}" }
  1703. print qq|
  1704. </tr>
  1705. |;
  1706. $sameid = $ref->{id};
  1707. }
  1708. if ( $form->{l_subtotal} eq 'Y' ) {
  1709. &subtotal;
  1710. $sameitem = $ref->{ $form->{sort} };
  1711. }
  1712. # print totals
  1713. print qq|
  1714. <tr class=listtotal>
  1715. |;
  1716. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  1717. $column_data{netamount} =
  1718. "<th class=listtotal align=right>"
  1719. . $form->format_amount( \%myconfig, $totalnetamount, 2, "&nbsp;" )
  1720. . "</th>";
  1721. $column_data{tax} = "<th class=listtotal align=right>"
  1722. . $form->format_amount( \%myconfig, $totalamount - $totalnetamount,
  1723. 2, "&nbsp;" )
  1724. . "</th>";
  1725. $column_data{amount} =
  1726. "<th class=listtotal align=right>"
  1727. . $form->format_amount( \%myconfig, $totalamount, 2, "&nbsp;" ) . "</th>";
  1728. $column_data{paid} =
  1729. "<th class=listtotal align=right>"
  1730. . $form->format_amount( \%myconfig, $totalpaid, 2, "&nbsp;" ) . "</th>";
  1731. $column_data{due} =
  1732. "<th class=listtotal align=right>"
  1733. . $form->format_amount( \%myconfig, $totalamount - $totalpaid, 2,
  1734. "&nbsp;" )
  1735. . "</th>";
  1736. $column_data{debit} =
  1737. "<th class=listtotal align=right>"
  1738. . $form->format_amount( \%myconfig, $totaldebit, 2, "&nbsp;" ) . "</th>";
  1739. $column_data{credit} =
  1740. "<th class=listtotal align=right>"
  1741. . $form->format_amount( \%myconfig, $totalcredit, 2, "&nbsp;" ) . "</th>";
  1742. if ( $form->{l_curr} && $form->{sort} eq 'curr' && $form->{l_subtotal} ) {
  1743. $column_data{fx_netamount} =
  1744. "<th class=listtotal align=right>"
  1745. . $form->format_amount( \%myconfig, $totalfxnetamount, 2, "&nbsp;" )
  1746. . "</th>";
  1747. $column_data{fx_tax} = "<th class=listtotal align=right>"
  1748. . $form->format_amount( \%myconfig,
  1749. $totalfxamount - $totalfxnetamount,
  1750. 2, "&nbsp;" )
  1751. . "</th>";
  1752. $column_data{fx_amount} =
  1753. "<th class=listtotal align=right>"
  1754. . $form->format_amount( \%myconfig, $totalfxamount, 2, "&nbsp;" )
  1755. . "</th>";
  1756. $column_data{fx_paid} =
  1757. "<th class=listtotal align=right>"
  1758. . $form->format_amount( \%myconfig, $totalfxpaid, 2, "&nbsp;" )
  1759. . "</th>";
  1760. $column_data{fx_due} = "<th class=listtotal align=right>"
  1761. . $form->format_amount( \%myconfig, $totalfxamount - $totalfxpaid,
  1762. 2, "&nbsp;" )
  1763. . "</th>";
  1764. }
  1765. for (@column_index) { print "\n$column_data{$_}" }
  1766. if ( $myconfig{acs} !~ /$form->{ARAP}--$form->{ARAP}/ ) {
  1767. $i = 1;
  1768. if ( $form->{ARAP} eq 'AR' ) {
  1769. $button{'AR--Add Transaction'}{code} =
  1770. qq|<button class="submit" type="submit" name="action" value="ar_transaction">|
  1771. . $locale->text('AR Transaction')
  1772. . qq|</button> |;
  1773. $button{'AR--Add Transaction'}{order} = $i++;
  1774. $button{'AR--Sales Invoice'}{code} =
  1775. qq|<button class="submit" type="submit" name="action" value="sales_invoice_">|
  1776. . $locale->text('Sales Invoice.')
  1777. . qq|</button> |;
  1778. $button{'AR--Sales Invoice'}{order} = $i++;
  1779. }
  1780. else {
  1781. $button{'AP--Add Transaction'}{code} =
  1782. qq|<button class="submit" type="submit" name="action" value="ap_transaction">|
  1783. . $locale->text('AP Transaction')
  1784. . qq|</button> |;
  1785. $button{'AP--Add Transaction'}{order} = $i++;
  1786. $button{'AP--Vendor Invoice'}{code} =
  1787. qq|<button class="submit" type="submit" name="action" value="vendor_invoice_">|
  1788. . $locale->text('Vendor Invoice.')
  1789. . qq|</button> |;
  1790. $button{'AP--Vendor Invoice'}{order} = $i++;
  1791. }
  1792. foreach $item ( split /;/, $myconfig{acs} ) {
  1793. delete $button{$item};
  1794. }
  1795. }
  1796. print qq|
  1797. </tr>
  1798. </table>
  1799. </td>
  1800. </tr>
  1801. <tr>
  1802. <td><hr size=3 noshade></td>
  1803. </tr>
  1804. </table>
  1805. <br>
  1806. <form method=post action=$form->{script}>
  1807. |;
  1808. $form->hide_form(
  1809. "callback", "path", "login", "sessionid",
  1810. "$form->{vc}", "$form->{vc}_id"
  1811. );
  1812. if ( !$form->{till} ) {
  1813. foreach $item ( sort { $a->{order} <=> $b->{order} } %button ) {
  1814. print $item->{code};
  1815. }
  1816. }
  1817. if ( $form->{lynx} ) {
  1818. require "bin/menu.pl";
  1819. &menubar;
  1820. }
  1821. print qq|
  1822. </form>
  1823. </body>
  1824. </html>
  1825. |;
  1826. }
  1827. sub subtotal {
  1828. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  1829. $column_data{tax} = "<th class=listsubtotal align=right>"
  1830. . $form->format_amount( \%myconfig, $subtotalamount - $subtotalnetamount,
  1831. 2, "&nbsp;" )
  1832. . "</th>";
  1833. $column_data{amount} =
  1834. "<th class=listsubtotal align=right>"
  1835. . $form->format_amount( \%myconfig, $subtotalamount, 2, "&nbsp;" )
  1836. . "</th>";
  1837. $column_data{paid} =
  1838. "<th class=listsubtotal align=right>"
  1839. . $form->format_amount( \%myconfig, $subtotalpaid, 2, "&nbsp;" )
  1840. . "</th>";
  1841. $column_data{due} = "<th class=listsubtotal align=right>"
  1842. . $form->format_amount( \%myconfig, $subtotalamount - $subtotalpaid,
  1843. 2, "&nbsp;" )
  1844. . "</th>";
  1845. $column_data{debit} =
  1846. "<th class=listsubtotal align=right>"
  1847. . $form->format_amount( \%myconfig, $subtotaldebit, 2, "&nbsp;" )
  1848. . "</th>";
  1849. $column_data{credit} =
  1850. "<th class=listsubtotal align=right>"
  1851. . $form->format_amount( \%myconfig, $subtotalcredit, 2, "&nbsp;" )
  1852. . "</th>";
  1853. if ( $form->{l_curr} && $form->{sort} eq 'curr' && $form->{l_subtotal} ) {
  1854. $column_data{fx_tax} = "<th class=listsubtotal align=right>"
  1855. . $form->format_amount( \%myconfig,
  1856. $subtotalfxamount - $subtotalfxnetamount,
  1857. 2, "&nbsp;" )
  1858. . "</th>";
  1859. $column_data{fx_amount} =
  1860. "<th class=listsubtotal align=right>"
  1861. . $form->format_amount( \%myconfig, $subtotalfxamount, 2, "&nbsp;" )
  1862. . "</th>";
  1863. $column_data{fx_paid} =
  1864. "<th class=listsubtotal align=right>"
  1865. . $form->format_amount( \%myconfig, $subtotalfxpaid, 2, "&nbsp;" )
  1866. . "</th>";
  1867. $column_data{fx_due} = "<th class=listsubtotal align=right>"
  1868. . $form->format_amount( \%myconfig,
  1869. $subtotalfxmount - $subtotalfxpaid,
  1870. 2, "&nbsp;" )
  1871. . "</th>";
  1872. }
  1873. $subtotalnetamount = 0;
  1874. $subtotalamount = 0;
  1875. $subtotalpaid = 0;
  1876. $subtotaldebit = 0;
  1877. $subtotalcredit = 0;
  1878. $subtotalfxnetamount = 0;
  1879. $subtotalfxamount = 0;
  1880. $subtotalfxpaid = 0;
  1881. print "<tr class=listsubtotal>";
  1882. for (@column_index) { print "\n$column_data{$_}" }
  1883. print "
  1884. </tr>
  1885. ";
  1886. }