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