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