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