summaryrefslogtreecommitdiff
path: root/bin/aa.pl
blob: 85324570eecba1e9e476fb145234eb527fe78b7f (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. <tr><th align="right">|.$locale->text('Number').qq|</th>
  1205. <td colspan="3"><input name="meta_number" size="36">
  1206. </tr>
  1207. $employee
  1208. $department
  1209. $invnumber
  1210. <tr>
  1211. <th align=right>| . $locale->text('Ship via') . qq|</th>
  1212. <td colspan=3><input name=shipvia size=40></td>
  1213. </tr>
  1214. <tr>
  1215. <th align=right nowrap>| . $locale->text('From') . qq|</th>
  1216. <td><input class="date" name=transdatefrom size=11 title="$myconfig{dateformat}"></td>
  1217. <th align=right>| . $locale->text('To') . qq|</th>
  1218. <td><input class="date" name=transdateto size=11 title="$myconfig{dateformat}"></td>
  1219. </tr>
  1220. $selectfrom
  1221. </table>
  1222. </td>
  1223. </tr>
  1224. <tr>
  1225. <td>
  1226. |.$locale->text('All Invoices').qq|: <input type="radio" name="invoice_type" checked value="1">
  1227. |.$locale->text('Active').qq|: <input type="radio" name="invoice_type" value="2">
  1228. |.$locale->text('On Hold').qq|: <input type="radio" name="invoice_type" value="3">
  1229. <br/>
  1230. </td>
  1231. </tr>
  1232. <tr>
  1233. <td>
  1234. <table>
  1235. <tr>
  1236. <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
  1237. <td>
  1238. <table width=100%>
  1239. $openclosed
  1240. $summary
  1241. |;
  1242. $form->{sort} = "transdate";
  1243. $form->hide_form(qw(title outstanding sort));
  1244. while (@a) {
  1245. for ( 1 .. 5 ) {
  1246. print qq|<td nowrap>| . shift @a;
  1247. print qq|</td>\n|;
  1248. }
  1249. print qq|</tr>\n|;
  1250. }
  1251. print qq|
  1252. <tr>
  1253. <td nowrap><input name="l_subtotal" class=checkbox type=checkbox value=Y> |
  1254. . $locale->text('Subtotal')
  1255. . qq|</td>
  1256. </tr>
  1257. </table>
  1258. </td>
  1259. </tr>
  1260. </table>
  1261. </td>
  1262. </tr>
  1263. <tr>
  1264. <td><hr size=3 noshade></td>
  1265. </tr>
  1266. </table>
  1267. <br>
  1268. <input type="hidden" name="action" value="continue">
  1269. <button class="submit" type="submit" name="action" value="continue">|
  1270. . $locale->text('Continue')
  1271. . qq|</button>|;
  1272. $form->hide_form(qw(nextsub path login sessionid));
  1273. print qq|
  1274. </form>
  1275. |;
  1276. if ( $form->{lynx} ) {
  1277. require "bin/menu.pl";
  1278. &menubar;
  1279. }
  1280. print qq|
  1281. </body>
  1282. </html>
  1283. |;
  1284. }
  1285. sub transactions {
  1286. # it shouldn't be putting it into vendor_id or customer_id, but into
  1287. # entity_id, conforming to the new entity tables.
  1288. if ( $form->{ $form->{vc} } ) {
  1289. $form->{ $form->{vc} } = $form->unescape( $form->{ $form->{vc} } );
  1290. ( $form->{ $form->{vc} }, $form->{"$form->{vc}_id"} ) =
  1291. split( /--/, $form->{ $form->{vc} } );
  1292. }
  1293. @column_index;
  1294. AA->transactions( \%myconfig, \%$form );
  1295. $href = "$form->{script}?action=transactions";
  1296. for (qw(direction oldsort till outstanding path login sessionid summary)) {
  1297. $href .= qq|&$_=$form->{$_}|;
  1298. }
  1299. $href .= "&title=" . $form->escape( $form->{title} );
  1300. $form->sort_order();
  1301. $callback = "$form->{script}?action=transactions";
  1302. for (qw(direction oldsort till outstanding path login sessionid summary)) {
  1303. $callback .= qq|&$_=$form->{$_}|;
  1304. }
  1305. $callback .= "&title=" . $form->escape( $form->{title}, 1 );
  1306. if ( $form->{ $form->{ARAP} } ) {
  1307. $callback .=
  1308. "&$form->{ARAP}=" . $form->escape( $form->{ $form->{ARAP} }, 1 );
  1309. $href .= "&$form->{ARAP}=" . $form->escape( $form->{ $form->{ARAP} } );
  1310. $form->{ $form->{ARAP} } =~ s/--/ /;
  1311. $option = $locale->text('Account') . " : $form->{$form->{ARAP}}";
  1312. }
  1313. if ( $form->{ $form->{vc} } ) {
  1314. $callback .=
  1315. "&$form->{vc}="
  1316. . $form->escape( $form->{ $form->{vc} }, 1 )
  1317. . qq|--$form->{"$form->{vc}_id"}|;
  1318. $href .=
  1319. "&$form->{vc}="
  1320. . $form->escape( $form->{ $form->{vc} } )
  1321. . qq|--$form->{"$form->{vc}_id"}|;
  1322. $option .= "\n<br>" if ($option);
  1323. $name =
  1324. ( $form->{vc} eq 'customer' )
  1325. ? $locale->text('Customer')
  1326. : $locale->text('Vendor');
  1327. $option .= "$name : $form->{$form->{vc}}";
  1328. }
  1329. if ( $form->{department} ) {
  1330. $callback .= "&department=" . $form->escape( $form->{department}, 1 );
  1331. $href .= "&department=" . $form->escape( $form->{department} );
  1332. ($department) = split /--/, $form->{department};
  1333. $option .= "\n<br>" if ($option);
  1334. $option .= $locale->text('Department') . " : $department";
  1335. }
  1336. if ( $form->{employee} ) {
  1337. $callback .= "&employee=" . $form->escape( $form->{employee}, 1 );
  1338. $href .= "&employee=" . $form->escape( $form->{employee} );
  1339. ($employee) = split /--/, $form->{employee};
  1340. $option .= "\n<br>" if ($option);
  1341. if ( $form->{ARAP} eq 'AR' ) {
  1342. $option .= $locale->text('Salesperson');
  1343. }
  1344. else {
  1345. $option .= $locale->text('Employee');
  1346. }
  1347. $option .= " : $employee";
  1348. }
  1349. if ( $form->{invnumber} ) {
  1350. $callback .= "&invnumber=" . $form->escape( $form->{invnumber}, 1 );
  1351. $href .= "&invnumber=" . $form->escape( $form->{invnumber} );
  1352. $option .= "\n<br>" if ($option);
  1353. $option .= $locale->text('Invoice Number') . " : $form->{invnumber}";
  1354. }
  1355. if ( $form->{ordnumber} ) {
  1356. $callback .= "&ordnumber=" . $form->escape( $form->{ordnumber}, 1 );
  1357. $href .= "&ordnumber=" . $form->escape( $form->{ordnumber} );
  1358. $option .= "\n<br>" if ($option);
  1359. $option .= $locale->text('Order Number') . " : $form->{ordnumber}";
  1360. }
  1361. if ( $form->{ponumber} ) {
  1362. $callback .= "&ponumber=" . $form->escape( $form->{ponumber}, 1 );
  1363. $href .= "&ponumber=" . $form->escape( $form->{ponumber} );
  1364. $option .= "\n<br>" if ($option);
  1365. $option .= $locale->text('PO Number') . " : $form->{ponumber}";
  1366. }
  1367. if ( $form->{source} ) {
  1368. $callback .= "&source=" . $form->escape( $form->{source}, 1 );
  1369. $href .= "&source=" . $form->escape( $form->{source} );
  1370. $option .= "\n<br>" if $option;
  1371. $option .= $locale->text('Source') . " : $form->{source}";
  1372. }
  1373. if ( $form->{description} ) {
  1374. $callback .= "&description=" . $form->escape( $form->{description}, 1 );
  1375. $href .= "&description=" . $form->escape( $form->{description} );
  1376. $option .= "\n<br>" if $option;
  1377. $option .= $locale->text('Description') . " : $form->{description}";
  1378. }
  1379. if ( $form->{notes} ) {
  1380. $callback .= "&notes=" . $form->escape( $form->{notes}, 1 );
  1381. $href .= "&notes=" . $form->escape( $form->{notes} );
  1382. $option .= "\n<br>" if $option;
  1383. $option .= $locale->text('Notes') . " : $form->{notes}";
  1384. }
  1385. if ( $form->{shipvia} ) {
  1386. $callback .= "&shipvia=" . $form->escape( $form->{shipvia}, 1 );
  1387. $href .= "&shipvia=" . $form->escape( $form->{shipvia} );
  1388. $option .= "\n<br>" if $option;
  1389. $option .= $locale->text('Ship via') . " : $form->{shipvia}";
  1390. }
  1391. if ( $form->{transdatefrom} ) {
  1392. $callback .= "&transdatefrom=$form->{transdatefrom}";
  1393. $href .= "&transdatefrom=$form->{transdatefrom}";
  1394. $option .= "\n<br>" if ($option);
  1395. $option .=
  1396. $locale->text('From') . "&nbsp;"
  1397. . $locale->date( \%myconfig, $form->{transdatefrom}, 1 );
  1398. }
  1399. if ( $form->{transdateto} ) {
  1400. $callback .= "&transdateto=$form->{transdateto}";
  1401. $href .= "&transdateto=$form->{transdateto}";
  1402. $option .= "\n<br>" if ($option);
  1403. $option .=
  1404. $locale->text( 'To [_1]',
  1405. $locale->date( \%myconfig, $form->{transdateto}, 1 ) );
  1406. }
  1407. if ( $form->{open} ) {
  1408. $callback .= "&open=$form->{open}";
  1409. $href .= "&open=$form->{open}";
  1410. $option .= "\n<br>" if ($option);
  1411. $option .= $locale->text('Open');
  1412. }
  1413. if ( $form->{closed} ) {
  1414. $callback .= "&closed=$form->{closed}";
  1415. $href .= "&closed=$form->{closed}";
  1416. $option .= "\n<br>" if ($option);
  1417. $option .= $locale->text('Closed');
  1418. }
  1419. @columns =
  1420. $form->sort_columns(
  1421. qw(transdate id invnumber ordnumber ponumber name netamount tax amount paid due curr datepaid duedate notes till employee manager shippingpoint shipvia department)
  1422. );
  1423. pop @columns if $form->{department};
  1424. unshift @columns, "runningnumber";
  1425. foreach $item (@columns) {
  1426. if ( $form->{"l_$item"} eq "Y" ) {
  1427. push @column_index, $item;
  1428. if ( $form->{l_curr} && $item =~ /(amount|tax|paid|due)/ ) {
  1429. push @column_index, "fx_$item";
  1430. }
  1431. # add column to href and callback
  1432. $callback .= "&l_$item=Y";
  1433. $href .= "&l_$item=Y";
  1434. }
  1435. }
  1436. if ( !$form->{summary} ) {
  1437. foreach $item (qw(source debit credit accno description projectnumber))
  1438. {
  1439. push @column_index, $item;
  1440. }
  1441. }
  1442. if ( $form->{l_subtotal} eq 'Y' ) {
  1443. $callback .= "&l_subtotal=Y";
  1444. $href .= "&l_subtotal=Y";
  1445. }
  1446. $employee =
  1447. ( $form->{ARAP} eq 'AR' )
  1448. ? $locale->text('Salesperson')
  1449. : $locale->text('Employee');
  1450. $name =
  1451. ( $form->{vc} eq 'customer' )
  1452. ? $locale->text('Customer')
  1453. : $locale->text('Vendor');
  1454. $column_header{runningnumber} = qq|<th class=listheading>&nbsp;</th>|;
  1455. $column_header{id} =
  1456. "<th><a class=listheading href=$href&sort=id>"
  1457. . $locale->text('ID')
  1458. . "</a></th>";
  1459. $column_header{transdate} =
  1460. "<th><a class=listheading href=$href&sort=transdate>"
  1461. . $locale->text('Date')
  1462. . "</a></th>";
  1463. $column_header{duedate} =
  1464. "<th><a class=listheading href=$href&sort=duedate>"
  1465. . $locale->text('Due Date')
  1466. . "</a></th>";
  1467. $column_header{invnumber} =
  1468. "<th><a class=listheading href=$href&sort=invnumber>"
  1469. . $locale->text('Invoice')
  1470. . "</a></th>";
  1471. $column_header{ordnumber} =
  1472. "<th><a class=listheading href=$href&sort=ordnumber>"
  1473. . $locale->text('Order')
  1474. . "</a></th>";
  1475. $column_header{ponumber} =
  1476. "<th><a class=listheading href=$href&sort=ponumber>"
  1477. . $locale->text('PO Number')
  1478. . "</a></th>";
  1479. $column_header{name} =
  1480. "<th>".$locale->text('Account')."</th><th><a class=listheading href=$href&sort=name>$name</a></th>";
  1481. $column_header{netamount} =
  1482. "<th class=listheading>" . $locale->text('Amount') . "</th>";
  1483. $column_header{tax} =
  1484. "<th class=listheading>" . $locale->text('Tax') . "</th>";
  1485. $column_header{amount} =
  1486. "<th class=listheading>" . $locale->text('Total') . "</th>";
  1487. $column_header{paid} =
  1488. "<th class=listheading>" . $locale->text('Paid') . "</th>";
  1489. $column_header{datepaid} =
  1490. "<th><a class=listheading href=$href&sort=datepaid>"
  1491. . $locale->text('Date Paid')
  1492. . "</a></th>";
  1493. $column_header{due} =
  1494. "<th class=listheading>" . $locale->text('Amount Due') . "</th>";
  1495. $column_header{notes} =
  1496. "<th class=listheading>" . $locale->text('Notes') . "</th>";
  1497. $column_header{employee} =
  1498. "<th><a class=listheading href=$href&sort=employee>$employee</th>";
  1499. $column_header{manager} =
  1500. "<th><a class=listheading href=$href&sort=manager>"
  1501. . $locale->text('Manager') . "</th>";
  1502. $column_header{till} =
  1503. "<th class=listheading><a class=listheading href=$href&sort=till>"
  1504. . $locale->text('Till') . "</th>";
  1505. $column_header{shippingpoint} =
  1506. "<th><a class=listheading href=$href&sort=shippingpoint>"
  1507. . $locale->text('Shipping Point')
  1508. . "</a></th>";
  1509. $column_header{shipvia} =
  1510. "<th><a class=listheading href=$href&sort=shipvia>"
  1511. . $locale->text('Ship via')
  1512. . "</a></th>";
  1513. $column_header{curr} =
  1514. "<th><a class=listheading href=$href&sort=curr>"
  1515. . $locale->text('Curr')
  1516. . "</a></th>";
  1517. for (qw(amount tax netamount paid due)) {
  1518. $column_header{"fx_$_"} = "<th>&nbsp;</th>";
  1519. }
  1520. $column_header{department} =
  1521. "<th><a class=listheading href=$href&sort=department>"
  1522. . $locale->text('Department')
  1523. . "</a></th>";
  1524. $column_header{accno} =
  1525. "<th><a class=listheading href=$href&sort=accno>"
  1526. . $locale->text('Account')
  1527. . "</a></th>";
  1528. $column_header{source} =
  1529. "<th><a class=listheading href=$href&sort=source>"
  1530. . $locale->text('Source')
  1531. . "</a></th>";
  1532. $column_header{debit} =
  1533. "<th class=listheading>" . $locale->text('Debit') . "</th>";
  1534. $column_header{credit} =
  1535. "<th class=listheading>" . $locale->text('Credit') . "</th>";
  1536. $column_header{projectnumber} =
  1537. "<th><a class=listheading href=$href&sort=projectnumber>"
  1538. . $locale->text('Project')
  1539. . "</a></th>";
  1540. $column_header{description} =
  1541. "<th><a class=listheading href=$href&sort=linedescription>"
  1542. . $locale->text('Description')
  1543. . "</a></th>";
  1544. $form->{title} =
  1545. ( $form->{title} ) ? $form->{title} : $locale->text('AR Transactions');
  1546. $form->header;
  1547. print qq|
  1548. <body>
  1549. <table width=100%>
  1550. <tr>
  1551. <th class=listtop>$form->{title}</th>
  1552. </tr>
  1553. <tr height="5"></tr>
  1554. <tr>
  1555. <td>$option</td>
  1556. </tr>
  1557. <tr>
  1558. <td>
  1559. <table width=100%>
  1560. <tr class=listheading>
  1561. |;
  1562. for (@column_index) { print "\n$column_header{$_}" }
  1563. print qq|
  1564. </tr>
  1565. |;
  1566. # add sort and escape callback, this one we use for the add sub
  1567. $form->{callback} = $callback .= "&sort=$form->{sort}";
  1568. # escape callback for href
  1569. $callback = $form->escape($callback);
  1570. # flip direction
  1571. $direction = ( $form->{direction} eq 'ASC' ) ? "ASC" : "DESC";
  1572. $href =~ s/&direction=(\w+)&/&direction=$direction&/;
  1573. if ( @{ $form->{transactions} } ) {
  1574. $sameitem = $form->{transactions}->[0]->{ $form->{sort} };
  1575. }
  1576. # sums and tax on reports by Antonio Gallardo
  1577. #
  1578. $i = 0;
  1579. foreach $ref ( @{ $form->{transactions} } ) {
  1580. $i++;
  1581. if ( $form->{l_subtotal} eq 'Y' ) {
  1582. if ( $sameitem ne $ref->{ $form->{sort} } ) {
  1583. &subtotal;
  1584. $sameitem = $ref->{ $form->{sort} };
  1585. }
  1586. }
  1587. if ( $form->{l_curr} ) {
  1588. for (qw(netamount amount paid)) {
  1589. $ref->{"fx_$_"} = $ref->{$_} / $ref->{exchangerate};
  1590. }
  1591. for (qw(netamount amount paid)) {
  1592. $column_data{"fx_$_"} = "<td align=right>"
  1593. . $form->format_amount( \%myconfig, $ref->{"fx_$_"}, 2,
  1594. "&nbsp;" )
  1595. . "</td>";
  1596. }
  1597. $column_data{fx_tax} = "<td align=right>"
  1598. . $form->format_amount( \%myconfig,
  1599. $ref->{fx_amount} - $ref->{fx_netamount},
  1600. 2, "&nbsp;" )
  1601. . "</td>";
  1602. $column_data{fx_due} = "<td align=right>"
  1603. . $form->format_amount( \%myconfig,
  1604. $ref->{fx_amount} - $ref->{fx_paid},
  1605. 2, "&nbsp;" )
  1606. . "</td>";
  1607. $subtotalfxnetamount += $ref->{fx_netamount};
  1608. $subtotalfxamount += $ref->{fx_amount};
  1609. $subtotalfxpaid += $ref->{fx_paid};
  1610. $totalfxnetamount += $ref->{fx_netamount};
  1611. $totalfxamount += $ref->{fx_amount};
  1612. $totalfxpaid += $ref->{fx_paid};
  1613. }
  1614. $column_data{runningnumber} = "<td align=right>$i</td>";
  1615. for (qw(netamount amount paid debit credit)) {
  1616. $column_data{$_} =
  1617. "<td align=right>"
  1618. . $form->format_amount( \%myconfig, $ref->{$_}, 2, "&nbsp;" )
  1619. . "</td>";
  1620. }
  1621. $column_data{tax} = "<td align=right>"
  1622. . $form->format_amount( \%myconfig,
  1623. $ref->{amount} - $ref->{netamount},
  1624. 2, "&nbsp;" )
  1625. . "</td>";
  1626. $column_data{due} = "<td align=right>"
  1627. . $form->format_amount( \%myconfig, $ref->{amount} - $ref->{paid},
  1628. 2, "&nbsp;" )
  1629. . "</td>";
  1630. $subtotalnetamount += $ref->{netamount};
  1631. $subtotalamount += $ref->{amount};
  1632. $subtotalpaid += $ref->{paid};
  1633. $subtotaldebit += $ref->{debit};
  1634. $subtotalcredit += $ref->{credit};
  1635. $totalnetamount += $ref->{netamount};
  1636. $totalamount += $ref->{amount};
  1637. $totalpaid += $ref->{paid};
  1638. $totaldebit += $ref->{debit};
  1639. $totalcredit += $ref->{credit};
  1640. $module =
  1641. ( $ref->{invoice} )
  1642. ? ( $form->{ARAP} eq 'AR' ) ? "is.pl" : "ir.pl"
  1643. : $form->{script};
  1644. $module = ( $ref->{till} ) ? "ps.pl" : $module;
  1645. $column_data{invnumber} =
  1646. "<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>";
  1647. for (qw(notes description)) { $ref->{$_} =~ s/\r?\n/<br>/g }
  1648. for (
  1649. qw(transdate datepaid duedate department ordnumber ponumber notes shippingpoint shipvia employee manager till source description projectnumber)
  1650. )
  1651. {
  1652. $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>";
  1653. }
  1654. for (qw(id curr)) { $column_data{$_} = "<td>$ref->{$_}</td>" }
  1655. $column_data{accno} =
  1656. 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>|;
  1657. $column_data{name} =
  1658. 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>|;
  1659. if ( $ref->{id} != $sameid ) {
  1660. $j++;
  1661. $j %= 2;
  1662. }
  1663. print "
  1664. <tr class=listrow$j>
  1665. ";
  1666. for (@column_index) { print "\n$column_data{$_}" }
  1667. print qq|
  1668. </tr>
  1669. |;
  1670. $sameid = $ref->{id};
  1671. }
  1672. if ( $form->{l_subtotal} eq 'Y' ) {
  1673. &subtotal;
  1674. $sameitem = $ref->{ $form->{sort} };
  1675. }
  1676. # print totals
  1677. print qq|
  1678. <tr class=listtotal>
  1679. |;
  1680. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  1681. $column_data{netamount} =
  1682. "<th class=listtotal align=right>"
  1683. . $form->format_amount( \%myconfig, $totalnetamount, 2, "&nbsp;" )
  1684. . "</th>";
  1685. $column_data{tax} = "<th class=listtotal align=right>"
  1686. . $form->format_amount( \%myconfig, $totalamount - $totalnetamount,
  1687. 2, "&nbsp;" )
  1688. . "</th>";
  1689. $column_data{amount} =
  1690. "<th class=listtotal align=right>"
  1691. . $form->format_amount( \%myconfig, $totalamount, 2, "&nbsp;" ) . "</th>";
  1692. $column_data{paid} =
  1693. "<th class=listtotal align=right>"
  1694. . $form->format_amount( \%myconfig, $totalpaid, 2, "&nbsp;" ) . "</th>";
  1695. $column_data{due} =
  1696. "<th class=listtotal align=right>"
  1697. . $form->format_amount( \%myconfig, $totalamount - $totalpaid, 2,
  1698. "&nbsp;" )
  1699. . "</th>";
  1700. $column_data{debit} =
  1701. "<th class=listtotal align=right>"
  1702. . $form->format_amount( \%myconfig, $totaldebit, 2, "&nbsp;" ) . "</th>";
  1703. $column_data{credit} =
  1704. "<th class=listtotal align=right>"
  1705. . $form->format_amount( \%myconfig, $totalcredit, 2, "&nbsp;" ) . "</th>";
  1706. if ( $form->{l_curr} && $form->{sort} eq 'curr' && $form->{l_subtotal} ) {
  1707. $column_data{fx_netamount} =
  1708. "<th class=listtotal align=right>"
  1709. . $form->format_amount( \%myconfig, $totalfxnetamount, 2, "&nbsp;" )
  1710. . "</th>";
  1711. $column_data{fx_tax} = "<th class=listtotal align=right>"
  1712. . $form->format_amount( \%myconfig,
  1713. $totalfxamount - $totalfxnetamount,
  1714. 2, "&nbsp;" )
  1715. . "</th>";
  1716. $column_data{fx_amount} =
  1717. "<th class=listtotal align=right>"
  1718. . $form->format_amount( \%myconfig, $totalfxamount, 2, "&nbsp;" )
  1719. . "</th>";
  1720. $column_data{fx_paid} =
  1721. "<th class=listtotal align=right>"
  1722. . $form->format_amount( \%myconfig, $totalfxpaid, 2, "&nbsp;" )
  1723. . "</th>";
  1724. $column_data{fx_due} = "<th class=listtotal align=right>"
  1725. . $form->format_amount( \%myconfig, $totalfxamount - $totalfxpaid,
  1726. 2, "&nbsp;" )
  1727. . "</th>";
  1728. }
  1729. for (@column_index) { print "\n$column_data{$_}" }
  1730. if ( $myconfig{acs} !~ /$form->{ARAP}--$form->{ARAP}/ ) {
  1731. $i = 1;
  1732. if ( $form->{ARAP} eq 'AR' ) {
  1733. $button{'AR--Add Transaction'}{code} =
  1734. qq|<button class="submit" type="submit" name="action" value="ar_transaction">|
  1735. . $locale->text('AR Transaction')
  1736. . qq|</button> |;
  1737. $button{'AR--Add Transaction'}{order} = $i++;
  1738. $button{'AR--Sales Invoice'}{code} =
  1739. qq|<button class="submit" type="submit" name="action" value="sales_invoice_">|
  1740. . $locale->text('Sales Invoice.')
  1741. . qq|</button> |;
  1742. $button{'AR--Sales Invoice'}{order} = $i++;
  1743. }
  1744. else {
  1745. $button{'AP--Add Transaction'}{code} =
  1746. qq|<button class="submit" type="submit" name="action" value="ap_transaction">|
  1747. . $locale->text('AP Transaction')
  1748. . qq|</button> |;
  1749. $button{'AP--Add Transaction'}{order} = $i++;
  1750. $button{'AP--Vendor Invoice'}{code} =
  1751. qq|<button class="submit" type="submit" name="action" value="vendor_invoice_">|
  1752. . $locale->text('Vendor Invoice.')
  1753. . qq|</button> |;
  1754. $button{'AP--Vendor Invoice'}{order} = $i++;
  1755. }
  1756. foreach $item ( split /;/, $myconfig{acs} ) {
  1757. delete $button{$item};
  1758. }
  1759. }
  1760. print qq|
  1761. </tr>
  1762. </table>
  1763. </td>
  1764. </tr>
  1765. <tr>
  1766. <td><hr size=3 noshade></td>
  1767. </tr>
  1768. </table>
  1769. <br>
  1770. <form method=post action=$form->{script}>
  1771. |;
  1772. $form->hide_form(
  1773. "callback", "path", "login", "sessionid",
  1774. "$form->{vc}", "$form->{vc}_id"
  1775. );
  1776. if ( !$form->{till} ) {
  1777. foreach $item ( sort { $a->{order} <=> $b->{order} } %button ) {
  1778. print $item->{code};
  1779. }
  1780. }
  1781. if ( $form->{lynx} ) {
  1782. require "bin/menu.pl";
  1783. &menubar;
  1784. }
  1785. print qq|
  1786. </form>
  1787. </body>
  1788. </html>
  1789. |;
  1790. }
  1791. sub subtotal {
  1792. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  1793. $column_data{tax} = "<th class=listsubtotal align=right>"
  1794. . $form->format_amount( \%myconfig, $subtotalamount - $subtotalnetamount,
  1795. 2, "&nbsp;" )
  1796. . "</th>";
  1797. $column_data{amount} =
  1798. "<th class=listsubtotal align=right>"
  1799. . $form->format_amount( \%myconfig, $subtotalamount, 2, "&nbsp;" )
  1800. . "</th>";
  1801. $column_data{paid} =
  1802. "<th class=listsubtotal align=right>"
  1803. . $form->format_amount( \%myconfig, $subtotalpaid, 2, "&nbsp;" )
  1804. . "</th>";
  1805. $column_data{due} = "<th class=listsubtotal align=right>"
  1806. . $form->format_amount( \%myconfig, $subtotalamount - $subtotalpaid,
  1807. 2, "&nbsp;" )
  1808. . "</th>";
  1809. $column_data{debit} =
  1810. "<th class=listsubtotal align=right>"
  1811. . $form->format_amount( \%myconfig, $subtotaldebit, 2, "&nbsp;" )
  1812. . "</th>";
  1813. $column_data{credit} =
  1814. "<th class=listsubtotal align=right>"
  1815. . $form->format_amount( \%myconfig, $subtotalcredit, 2, "&nbsp;" )
  1816. . "</th>";
  1817. if ( $form->{l_curr} && $form->{sort} eq 'curr' && $form->{l_subtotal} ) {
  1818. $column_data{fx_tax} = "<th class=listsubtotal align=right>"
  1819. . $form->format_amount( \%myconfig,
  1820. $subtotalfxamount - $subtotalfxnetamount,
  1821. 2, "&nbsp;" )
  1822. . "</th>";
  1823. $column_data{fx_amount} =
  1824. "<th class=listsubtotal align=right>"
  1825. . $form->format_amount( \%myconfig, $subtotalfxamount, 2, "&nbsp;" )
  1826. . "</th>";
  1827. $column_data{fx_paid} =
  1828. "<th class=listsubtotal align=right>"
  1829. . $form->format_amount( \%myconfig, $subtotalfxpaid, 2, "&nbsp;" )
  1830. . "</th>";
  1831. $column_data{fx_due} = "<th class=listsubtotal align=right>"
  1832. . $form->format_amount( \%myconfig,
  1833. $subtotalfxmount - $subtotalfxpaid,
  1834. 2, "&nbsp;" )
  1835. . "</th>";
  1836. }
  1837. $subtotalnetamount = 0;
  1838. $subtotalamount = 0;
  1839. $subtotalpaid = 0;
  1840. $subtotaldebit = 0;
  1841. $subtotalcredit = 0;
  1842. $subtotalfxnetamount = 0;
  1843. $subtotalfxamount = 0;
  1844. $subtotalfxpaid = 0;
  1845. print "<tr class=listsubtotal>";
  1846. for (@column_index) { print "\n$column_data{$_}" }
  1847. print "
  1848. </tr>
  1849. ";
  1850. }