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