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