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