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