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