summaryrefslogtreecommitdiff
path: root/bin/aa.pl
blob: aa6f8d673de289172c04955ab360e632dd0a1ca0 (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} = "$form->{script}?action=add&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};
  85. &create_links;
  86. $form->{focus} = "amount_1";
  87. &display_form;
  88. }
  89. sub edit {
  90. $form->{title} = "Edit";
  91. &create_links;
  92. &display_form;
  93. }
  94. sub display_form {
  95. &form_header;
  96. &form_footer;
  97. }
  98. sub create_links {
  99. $form->create_links($form->{ARAP}, \%myconfig, $form->{vc});
  100. $duedate = $form->{duedate};
  101. $taxincluded = $form->{taxincluded};
  102. $form->{formname} = "transaction";
  103. $form->{format} = "postscript" if $myconfig{printer};
  104. $form->{media} = $myconfig{printer};
  105. $form->{selectformname} = qq|<option value="transaction">|.$locale->text('Transaction');
  106. if ($latex) {
  107. if ($form->{ARAP} eq 'AR') {
  108. $form->{selectformname} .= qq|
  109. <option value="receipt">|.$locale->text('Receipt');
  110. } else {
  111. $form->{selectformname} .= qq|
  112. <option value="check">|.$locale->text('Check');
  113. }
  114. }
  115. # currencies
  116. @curr = split /:/, $form->{currencies};
  117. $form->{defaultcurrency} = $curr[0];
  118. chomp $form->{defaultcurrency};
  119. for (@curr) { $form->{selectcurrency} .= "<option>$_\n" }
  120. AA->get_name(\%myconfig, \%$form);
  121. $form->{currency} =~ s/ //g;
  122. $form->{duedate} = $duedate if $duedate;
  123. $form->{taxincluded} = $taxincluded if $form->{id};
  124. $form->{notes} = $form->{intnotes} if !$form->{id};
  125. $form->{"old$form->{vc}"} = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
  126. $form->{oldtransdate} = $form->{transdate};
  127. # customers/vendors
  128. $form->{"select$form->{vc}"} = "";
  129. if (@{ $form->{"all_$form->{vc}"} }) {
  130. $form->{$form->{vc}} = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
  131. for (@{ $form->{"all_$form->{vc}"} }) { $form->{"select$form->{vc}"} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
  132. }
  133. # departments
  134. if (@{ $form->{all_department} }) {
  135. $form->{selectdepartment} = "<option>\n";
  136. $form->{department} = "$form->{department}--$form->{department_id}" if $form->{department_id};
  137. for (@{ $form->{all_department} }) { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
  138. }
  139. $form->{employee} = "$form->{employee}--$form->{employee_id}";
  140. # sales staff
  141. if (@{ $form->{all_employee} }) {
  142. $form->{selectemployee} = "";
  143. for (@{ $form->{all_employee} }) { $form->{selectemployee} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
  144. }
  145. # projects
  146. if (@{ $form->{all_project} }) {
  147. $form->{selectprojectnumber} = "<option>\n";
  148. for (@{ $form->{all_project} }) { $form->{selectprojectnumber} .= qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n| }
  149. }
  150. if (@{ $form->{all_language} }) {
  151. $form->{selectlanguage} = "<option>\n";
  152. for (@{ $form->{all_language} }) { $form->{selectlanguage} .= qq|<option value="$_->{code}">$_->{description}\n| }
  153. }
  154. # forex
  155. $form->{forex} = $form->{exchangerate};
  156. $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
  157. $netamount = 0;
  158. $tax = 0;
  159. $taxrate = 0;
  160. $ml = ($form->{ARAP} eq 'AR') ? 1 : -1;
  161. foreach $key (keys %{ $form->{"$form->{ARAP}_links"} }) {
  162. $form->{"select$key"} = "";
  163. foreach $ref (@{ $form->{"$form->{ARAP}_links"}{$key} }) {
  164. if ($key eq "$form->{ARAP}_tax") {
  165. $form->{"select$form->{ARAP}_tax_$ref->{accno}"} = "<option>$ref->{accno}--$ref->{description}\n";
  166. next;
  167. }
  168. $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
  169. }
  170. # if there is a value we have an old entry
  171. for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
  172. if ($key eq "$form->{ARAP}_paid") {
  173. $form->{"$form->{ARAP}_paid_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
  174. $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i-1]->{amount} * -1 * $ml;
  175. $form->{"datepaid_$i"} = $form->{acc_trans}{$key}->[$i-1]->{transdate};
  176. $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i-1]->{source};
  177. $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i-1]->{memo};
  178. $form->{"forex_$i"} = $form->{"exchangerate_$i"} = $form->{acc_trans}{$key}->[$i-1]->{exchangerate};
  179. $form->{paidaccounts}++;
  180. } else {
  181. $akey = $key;
  182. $akey =~ s/$form->{ARAP}_//;
  183. if ($key eq "$form->{ARAP}_tax") {
  184. $form->{"${key}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
  185. $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} = $form->{acc_trans}{$key}->[$i-1]->{amount} * $ml;
  186. $tax += $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"};
  187. $taxrate += $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"};
  188. } else {
  189. $form->{"${akey}_$i"} = $form->{acc_trans}{$key}->[$i-1]->{amount} * $ml;
  190. if ($akey eq 'amount') {
  191. $form->{"description_$i"} = $form->{acc_trans}{$key}->[$i-1]->{memo};
  192. $form->{rowcount}++;
  193. $netamount += $form->{"${akey}_$i"};
  194. $form->{"projectnumber_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{projectnumber}--$form->{acc_trans}{$key}->[$i-1]->{project_id}" if $form->{acc_trans}{$key}->[$i-1]->{project_id};
  195. } else {
  196. $form->{invtotal} = $form->{acc_trans}{$key}->[$i-1]->{amount} * -1 * $ml;
  197. }
  198. $form->{"${key}_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
  199. }
  200. }
  201. }
  202. }
  203. $form->{paidaccounts} = 1 if not defined $form->{paidaccounts};
  204. if ($form->{taxincluded}) {
  205. $diff = 0;
  206. # add tax to individual amounts
  207. # XXX needs alteration for conditional taxes
  208. for $i (1 .. $form->{rowcount}) {
  209. if ($netamount) {
  210. $amount = $form->{"amount_$i"} * (1 + $tax / $netamount);
  211. $form->{"amount_$i"} = $form->round_amount($amount, 2);
  212. }
  213. }
  214. }
  215. $form->{invtotal} = $netamount + $tax;
  216. # check if calculated is equal to stored
  217. # taxincluded is terrible to calculate
  218. # this works only if all taxes are checked
  219. @taxaccounts = Tax::init_taxes($form, $form->{taxaccounts});
  220. if ($form->{id}) {
  221. if ($form->{taxincluded}) {
  222. $amount = Tax::calculate_taxes(\@taxaccounts, $form,
  223. $form->{invtotal}, 1);
  224. $tax = $form->round_amount($amount, 2);
  225. } else {
  226. $tax = $form->round_amount(Tax::calculate_taxes(\@taxaccounts,
  227. $form, $netamount, 0));
  228. }
  229. foreach $item (@taxaccounts) {
  230. $tax{$item->account} = $form->round_amount($item->value, 2);
  231. $form->{"calctax_".$item->account} = 1 if $item->value and (
  232. $tax{$item->account} == $form->{"tax_".$item->account});
  233. }
  234. } else {
  235. for (@taxaccounts) { $form->{"calctax_".$_->account} = 1 }
  236. }
  237. $form->{rowcount}++ if ($form->{id} || !$form->{rowcount});
  238. $form->{$form->{ARAP}} = $form->{"$form->{ARAP}_1"};
  239. $form->{rowcount} = 1 unless $form->{"$form->{ARAP}_amount_1"};
  240. $form->{locked} = ($form->{revtrans}) ? '1' : ($form->datetonum(\%myconfig, $form->{transdate}) <= $form->datetonum(\%myconfig, $form->{closedto}));
  241. # readonly
  242. if (! $form->{readonly}) {
  243. $form->{readonly} = 1 if $myconfig{acs} =~ /$form->{ARAP}--Add Transaction/;
  244. }
  245. }
  246. sub form_header {
  247. $title = $form->{title};
  248. $form->{title} = $locale->text("$title $form->{ARAP} Transaction");
  249. $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
  250. # $locale->text('Add AR Transaction')
  251. # $locale->text('Edit AR Transaction')
  252. # $locale->text('Add AP Transaction')
  253. # $locale->text('Edit AP Transaction')
  254. # set option selected
  255. for ("$form->{ARAP}", "currency") {
  256. $form->{"select$_"} =~ s/ selected//;
  257. $form->{"select$_"} =~ s/<option>\Q$form->{$_}\E/<option selected>$form->{$_}/;
  258. }
  259. for ("$form->{vc}", "department", "employee", "formname") {
  260. $form->{"select$_"} = $form->unescape($form->{"select$_"});
  261. $form->{"select$_"} =~ s/ selected//;
  262. $form->{"select$_"} =~ s/(<option value="\Q$form->{$_}\E")/$1 selected/;
  263. }
  264. $form->{selectprojectnumber} = $form->unescape($form->{selectprojectnumber});
  265. # format amounts
  266. $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
  267. $exchangerate = qq|<tr>|;
  268. $exchangerate .= qq|
  269. <th align=right nowrap>|.$locale->text('Currency').qq|</th>
  270. <td><select name=currency>$form->{selectcurrency}</select></td> | if $form->{defaultcurrency};
  271. $exchangerate .= qq|
  272. <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
  273. <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
  274. |;
  275. if ($form->{defaultcurrency} && $form->{currency} ne $form->{defaultcurrency}) {
  276. if ($form->{forex}) {
  277. $exchangerate .= qq|
  278. <th align=right>|.$locale->text('Exchange Rate').qq|</th>
  279. <td><input type=hidden name=exchangerate value=$form->{exchangerate}>$form->{exchangerate}</td>
  280. |;
  281. } else {
  282. $exchangerate .= qq|
  283. <th align=right>|.$locale->text('Exchange Rate').qq|</th>
  284. <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
  285. |;
  286. }
  287. }
  288. $exchangerate .= qq|
  289. <input type=hidden name=forex value=$form->{forex}>
  290. </tr>
  291. |;
  292. $taxincluded = "";
  293. if ($form->{taxaccounts}) {
  294. $taxincluded = qq|
  295. <tr>
  296. <td align=right><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
  297. <th align=left nowrap>|.$locale->text('Tax Included').qq|</th>
  298. </tr>
  299. |;
  300. }
  301. if (($rows = $form->numtextrows($form->{notes}, 50) - 1) < 2) {
  302. $rows = 2;
  303. }
  304. $notes = qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|;
  305. $department = qq|
  306. <tr>
  307. <th align="right" nowrap>|.$locale->text('Department').qq|</th>
  308. <td colspan=3><select name=department>$form->{selectdepartment}</select>
  309. <input type=hidden name=selectdepartment value="|.$form->escape($form->{selectdepartment},1).qq|">
  310. </td>
  311. </tr>
  312. | if $form->{selectdepartment};
  313. $n = ($form->{creditremaining} < 0) ? "0" : "1";
  314. $name = ($form->{"select$form->{vc}"}) ? qq|<select name="$form->{vc}">$form->{"select$form->{vc}"}</select>| : qq|<input name="$form->{vc}" value="$form->{$form->{vc}}" size=35>|;
  315. $employee = qq|
  316. <input type=hidden name=employee value="$form->{employee}">
  317. |;
  318. if ($form->{selectemployee}) {
  319. $label = ($form->{ARAP} eq 'AR') ? $locale->text('Salesperson') : $locale->text('Employee');
  320. $employee = qq|
  321. <tr>
  322. <th align=right nowrap>$label</th>
  323. <td><select name=employee>$form->{selectemployee}</select></td>
  324. <input type=hidden name=selectemployee value="|.$form->escape($form->{selectemployee},1).qq|">
  325. </tr>
  326. |;
  327. }
  328. $focus = ($form->{focus}) ? $form->{focus} : "amount_$form->{rowcount}";
  329. $form->header;
  330. print qq|
  331. <body onload="document.forms[0].${focus}.focus()" />
  332. <form method=post action=$form->{script}>
  333. <input type=hidden name=type value="$form->{formname}">
  334. <input type=hidden name=title value="$title">
  335. |;
  336. $form->hide_form(qw(id printed emailed sort closedto locked oldtransdate audittrail recurring checktax));
  337. if ($form->{vc} eq 'customer') {
  338. $label = $locale->text('Customer');
  339. } else {
  340. $label = $locale->text('Vendor');
  341. }
  342. $form->hide_form("old$form->{vc}", "$form->{vc}_id", "terms", "creditlimit", "creditremaining", "selectcurrency", "defaultcurrency", "select$form->{ARAP}_amount", "rowcount");
  343. print qq|
  344. <table width=100%>
  345. <tr class=listtop>
  346. <th class=listtop>$form->{title}</th>
  347. </tr>
  348. <tr height="5"></tr>
  349. <tr valign=top>
  350. <td>
  351. <table width=100%>
  352. <tr valign=top>
  353. <td>
  354. <table>
  355. <tr>
  356. <th align="right" nowrap>$label</th>
  357. <td colspan=3>$name</td>
  358. <input type=hidden name="select$form->{vc}" value="|.$form->escape($form->{"select$form->{vc}"},1).qq|">
  359. </tr>
  360. <tr>
  361. <td></td>
  362. <td colspan=3>
  363. <table width=100%>
  364. <tr>
  365. <th align=left nowrap>|.$locale->text('Credit Limit').qq|</th>
  366. <td>$form->{creditlimit}</td>
  367. <th align=left nowrap>|.$locale->text('Remaining').qq|</th>
  368. <td class="plus$n">|.$form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0").qq|</td>
  369. </tr>
  370. </table>
  371. </td>
  372. </tr>
  373. $exchangerate
  374. $department
  375. $taxincluded
  376. </table>
  377. </td>
  378. <td align=right>
  379. <table>
  380. $employee
  381. <tr>
  382. <th align=right nowrap>|.$locale->text('Invoice Number').qq|</th>
  383. <td><input name=invnumber size=20 value="$form->{invnumber}"></td>
  384. </tr>
  385. <tr>
  386. <th align=right nowrap>|.$locale->text('Order Number').qq|</th>
  387. <td><input name=ordnumber size=20 value="$form->{ordnumber}"></td>
  388. </tr>
  389. <tr>
  390. <th align=right nowrap>|.$locale->text('Invoice Date').qq|</th>
  391. <td><input name=transdate size=11 title="($myconfig{'dateformat'})" value=$form->{transdate}></td>
  392. </tr>
  393. <tr>
  394. <th align=right nowrap>|.$locale->text('Due Date').qq|</th>
  395. <td><input name=duedate size=11 title="$myconfig{'dateformat'}" value=$form->{duedate}></td>
  396. </tr>
  397. <tr>
  398. <th align=right nowrap>|.$locale->text('PO Number').qq|</th>
  399. <td><input name=ponumber size=20 value="$form->{ponumber}"></td>
  400. </tr>
  401. </table>
  402. </td>
  403. </tr>
  404. </table>
  405. </td>
  406. </tr>
  407. <input type=hidden name=selectprojectnumber value="|.$form->escape($form->{selectprojectnumber},1).qq|">
  408. <tr>
  409. <td>
  410. <table>
  411. |;
  412. $project = qq|
  413. <th>|.$locale->text('Project').qq|</th>
  414. | if $form->{selectprojectnumber};
  415. print qq|
  416. <tr>
  417. <th>|.$locale->text('Amount').qq|</th>
  418. <th></th>
  419. <th>|.$locale->text('Account').qq|</th>
  420. <th>|.$locale->text('Description').qq|</th>
  421. $project
  422. </tr>
  423. |;
  424. for $i (1 .. $form->{rowcount}) {
  425. $selectamount = $form->{"select$form->{ARAP}_amount"};
  426. $selectamount =~ s/option>\Q$form->{"$form->{ARAP}_amount_$i"}\E/option selected>$form->{"$form->{ARAP}_amount_$i"}/;
  427. $selectprojectnumber = $form->{selectprojectnumber};
  428. $selectprojectnumber =~ s/(<option value="\Q$form->{"projectnumber_$i"}\E")/$1 selected/;
  429. # format amounts
  430. $form->{"amount_$i"} = $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
  431. $project = qq|
  432. <td align=right><select name="projectnumber_$i">$selectprojectnumber</select></td>
  433. | if $form->{selectprojectnumber};
  434. if (($rows = $form->numtextrows($form->{"description_$i"}, 40)) > 1) {
  435. $description = qq|<td><textarea name="description_$i" rows=$rows cols=40>$form->{"description_$i"}</textarea></td>|;
  436. } else {
  437. $description = qq|<td><input name="description_$i" size=40 value="$form->{"description_$i"}"></td>|;
  438. }
  439. print qq|
  440. <tr valign=top>
  441. <td><input name="amount_$i" size=10 value="$form->{"amount_$i"}" accesskey="$i"></td>
  442. <td></td>
  443. <td><select name="$form->{ARAP}_amount_$i">$selectamount</select></td>
  444. $description
  445. $project
  446. </tr>
  447. |;
  448. }
  449. foreach $item (split / /, $form->{taxaccounts}) {
  450. $form->{"calctax_$item"} = ($form->{"calctax_$item"}) ? "checked" : "";
  451. $form->{"tax_$item"} = $form->format_amount(\%myconfig, $form->{"tax_$item"}, 2);
  452. print qq|
  453. <tr>
  454. <td><input name="tax_$item" size=10 value=$form->{"tax_$item"}></td>
  455. <td align=right><input name="calctax_$item" class=checkbox type=checkbox value=1 $form->{"calctax_$item"}></td>
  456. <td><select name="$form->{ARAP}_tax_$item">$form->{"select$form->{ARAP}_tax_$item"}</select></td>
  457. </tr>
  458. |;
  459. $form->hide_form("${item}_rate", "${item}_description", "${item}_taxnumber", "select$form->{ARAP}_tax_$item");
  460. }
  461. $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
  462. $form->hide_form("oldinvtotal", "oldtotalpaid", "taxaccounts", "select$form->{ARAP}");
  463. print qq|
  464. <tr>
  465. <th align=left>$form->{invtotal}</th>
  466. <td></td>
  467. <td><select name=$form->{ARAP}>$form->{"select$form->{ARAP}"}</select></td>
  468. </tr>
  469. <tr>
  470. <th align=right>|.$locale->text('Notes').qq|</th>
  471. <td></td>
  472. <td colspan=3>$notes</td>
  473. </tr>
  474. </table>
  475. </td>
  476. </tr>
  477. <tr class=listheading>
  478. <th class=listheading>|.$locale->text('Payments').qq|</th>
  479. </tr>
  480. <tr>
  481. <td>
  482. <table width=100%>
  483. |;
  484. if ($form->{currency} eq $form->{defaultcurrency}) {
  485. @column_index = qw(datepaid source memo paid ARAP_paid);
  486. } else {
  487. @column_index = qw(datepaid source memo paid exchangerate ARAP_paid);
  488. }
  489. $column_data{datepaid} = "<th>".$locale->text('Date')."</th>";
  490. $column_data{paid} = "<th>".$locale->text('Amount')."</th>";
  491. $column_data{exchangerate} = "<th>".$locale->text('Exch')."</th>";
  492. $column_data{ARAP_paid} = "<th>".$locale->text('Account')."</th>";
  493. $column_data{source} = "<th>".$locale->text('Source')."</th>";
  494. $column_data{memo} = "<th>".$locale->text('Memo')."</th>";
  495. print "
  496. <tr>
  497. ";
  498. for (@column_index) { print "$column_data{$_}\n" }
  499. print "
  500. </tr>
  501. ";
  502. $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
  503. for $i (1 .. $form->{paidaccounts}) {
  504. $form->hide_form("cleared_$i");
  505. print "
  506. <tr>
  507. ";
  508. $form->{"select$form->{ARAP}_paid_$i"} = $form->{"select$form->{ARAP}_paid"};
  509. $form->{"select$form->{ARAP}_paid_$i"} =~ s/option>\Q$form->{"$form->{ARAP}_paid_$i"}\E/option selected>$form->{"$form->{ARAP}_paid_$i"}/;
  510. # format amounts
  511. $form->{"paid_$i"} = $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
  512. $form->{"exchangerate_$i"} = $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
  513. $exchangerate = qq|&nbsp;|;
  514. if ($form->{currency} ne $form->{defaultcurrency}) {
  515. if ($form->{"forex_$i"}) {
  516. $form->hide_form("exchangerate_$i");
  517. $exchangerate = qq|$form->{"exchangerate_$i"}|;
  518. } else {
  519. $exchangerate = qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
  520. }
  521. }
  522. $form->hide_form("forex_$i");
  523. $column_data{paid} = qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
  524. $column_data{ARAP_paid} = qq|<td align=center><select name="$form->{ARAP}_paid_$i">$form->{"select$form->{ARAP}_paid_$i"}</select></td>|;
  525. $column_data{exchangerate} = qq|<td align=center>$exchangerate</td>|;
  526. $column_data{datepaid} = qq|<td align=center><input name="datepaid_$i" size=11 value=$form->{"datepaid_$i"}></td>|;
  527. $column_data{source} = qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
  528. $column_data{memo} = qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
  529. for (@column_index) { print qq|$column_data{$_}\n| }
  530. print "
  531. </tr>
  532. ";
  533. }
  534. $form->hide_form("paidaccounts", "select$form->{ARAP}_paid");
  535. print qq|
  536. </table>
  537. </td>
  538. </tr>
  539. <tr>
  540. <td><hr size=3 noshade></td>
  541. </tr>
  542. </table>
  543. |;
  544. }
  545. sub form_footer {
  546. $form->hide_form(qw(callback path login sessionid));
  547. $transdate = $form->datetonum(\%myconfig, $form->{transdate});
  548. $closedto = $form->datetonum(\%myconfig, $form->{closedto});
  549. # type=submit $locale->text('Update')
  550. # type=submit $locale->text('Print')
  551. # type=submit $locale->text('Post')
  552. # type=submit $locale->text('Print and Post')
  553. # type=submit $locale->text('Schedule')
  554. # type=submit $locale->text('Ship to')
  555. # type=submit $locale->text('Post as new')
  556. # type=submit $locale->text('Print and Post as new')
  557. # type=submit $locale->text('Delete')
  558. if (! $form->{readonly}) {
  559. &print_options;
  560. print "<br>";
  561. %button = ('Update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
  562. 'Print' => { ndx => 2, key => 'P', value => $locale->text('Print') },
  563. 'Post' => { ndx => 3, key => 'O', value => $locale->text('Post') },
  564. 'Print and Post' => { ndx => 4, key => 'R', value => $locale->text('Print and Post') },
  565. 'Post as new' => { ndx => 5, key => 'N', value => $locale->text('Post as new') },
  566. 'Print and Post as new' => { ndx => 6, key => 'W', value => $locale->text('Print and Post as new') },
  567. 'Schedule' => { ndx => 7, key => 'H', value => $locale->text('Schedule') },
  568. 'Delete' => { ndx => 8, key => 'D', value => $locale->text('Delete') },
  569. );
  570. if ($form->{id}) {
  571. if ($form->{locked} || $transdate <= $closedto) {
  572. for ("Post", "Print and Post", "Delete") { delete $button{$_} }
  573. }
  574. if (!$latex) {
  575. for ("Print and Post", "Print and Post as new") { delete $button{$_} }
  576. }
  577. } else {
  578. for ("Post as new", "Print and Post as new", "Delete") { delete $button{$_} }
  579. delete $button{"Print and Post"} if ! $latex;
  580. if ($transdate <= $closedto) {
  581. for ("Post", "Print and Post") { delete $button{$_} }
  582. }
  583. }
  584. for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
  585. }
  586. if ($form->{lynx}) {
  587. require "bin/menu.pl";
  588. &menubar;
  589. }
  590. print qq|
  591. </form>
  592. </body>
  593. </html>
  594. |;
  595. }
  596. sub update {
  597. my $display = shift;
  598. if (!$display) {
  599. $form->{invtotal} = 0;
  600. $form->{exchangerate} = $form->parse_amount(\%myconfig, $form->{exchangerate});
  601. @flds = ("amount", "$form->{ARAP}_amount", "projectnumber", "description");
  602. $count = 0;
  603. @a = ();
  604. for $i (1 .. $form->{rowcount}) {
  605. $form->{"amount_$i"} = $form->parse_amount(\%myconfig, $form->{"amount_$i"});
  606. if ($form->{"amount_$i"}) {
  607. push @a, {};
  608. $j = $#a;
  609. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  610. $count++;
  611. }
  612. }
  613. $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
  614. $form->{rowcount} = $count + 1;
  615. for (1 .. $form->{rowcount}) { $form->{invtotal} += $form->{"amount_$_"} }
  616. $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, ($form->{ARAP} eq 'AR') ? 'buy' : 'sell')));
  617. if ($newname = &check_name($form->{vc})) {
  618. $form->{notes} = $form->{intnotes} unless $form->{id};
  619. &rebuild_vc($form->{vc}, $form->{ARAP}, $form->{transdate});
  620. }
  621. if ($form->{transdate} ne $form->{oldtransdate}) {
  622. $form->{duedate} = $form->current_date(\%myconfig, $form->{transdate}, $form->{terms} * 1);
  623. $form->{oldtransdate} = $form->{transdate};
  624. $newproj = &rebuild_vc($form->{vc}, $form->{ARAP}, $form->{transdate}) if ! $newname;
  625. $form->all_projects(\%myconfig, undef, $form->{transdate}) if ! $newproj;
  626. $form->{selectemployee} = "";
  627. if (@{ $form->{all_employee} }) {
  628. for (@{ $form->{all_employee} }) { $form->{selectemployee} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
  629. }
  630. }
  631. }
  632. # recalculate taxes
  633. @taxaccounts = split / /, $form->{taxaccounts};
  634. for (@taxaccounts) { $form->{"tax_$_"} = $form->parse_amount(\%myconfig, $form->{"tax_$_"}) }
  635. @taxaccounts = Tax::init_taxes($form, $form->{taxaccounts});
  636. if ($form->{taxincluded}) {
  637. $totaltax = Tax::calculate_taxes(\@taxaccounts, $form,
  638. $form->{invtotal}, 1);
  639. } else {
  640. $totaltax = Tax::calculate_taxes(\@taxaccounts, $form,
  641. $form->{invtotal}, 0);
  642. }
  643. foreach $item (@taxaccounts) {
  644. $taccno = $item->account;
  645. if ($form->{calctax}) {
  646. $form->{"calctax_$taccno"} = 1;
  647. $form->{"tax_$taccno"} = $form->round_amount($item->value, 2);
  648. }
  649. $form->{"select$form->{ARAP}_tax_$taccno"} = qq|<option>$taccno--$form->{"${taccno}_description"}|;
  650. }
  651. $form->{invtotal} = ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
  652. $j = 1;
  653. for $i (1 .. $form->{paidaccounts}) {
  654. if ($form->{"paid_$i"}) {
  655. for (qw(datepaid source memo cleared)) { $form->{"${_}_$j"} = $form->{"${_}_$i"} }
  656. for (qw(paid exchangerate)) { $form->{"${_}_$j"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
  657. $totalpaid += $form->{"paid_$j"};
  658. $form->{"exchangerate_$j"} = $exchangerate if ($form->{"forex_$j"} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$j"}, ($form->{ARAP} eq 'AR') ? 'buy' : 'sell')));
  659. if ($j++ != $i) {
  660. for (qw(datepaid source memo paid exchangerate forex cleared)) { delete $form->{"${_}_$i"} }
  661. }
  662. } else {
  663. for (qw(datepaid source memo paid exchangerate forex cleared)) { delete $form->{"${_}_$i"} }
  664. }
  665. }
  666. $form->{paidaccounts} = $j;
  667. $form->{creditremaining} -= ($form->{invtotal} - $totalpaid + $form->{oldtotalpaid} - $form->{oldinvtotal});
  668. $form->{oldinvtotal} = $form->{invtotal};
  669. $form->{oldtotalpaid} = $totalpaid;
  670. &display_form;
  671. }
  672. sub post {
  673. $label = ($form->{vc} eq 'customer') ? $locale->text('Customer missing!') : $locale->text('Vendor missing!');
  674. # check if there is an invoice number, invoice and due date
  675. $form->isblank("transdate", $locale->text('Invoice Date missing!'));
  676. $form->isblank("duedate", $locale->text('Due Date missing!'));
  677. $form->isblank($form->{vc}, $label);
  678. $closedto = $form->datetonum(\%myconfig, $form->{closedto});
  679. $transdate = $form->datetonum(\%myconfig, $form->{transdate});
  680. $form->error($locale->text('Cannot post transaction for a closed period!')) if ($transdate <= $closedto);
  681. $form->isblank("exchangerate", $locale->text('Exchange rate missing!')) if ($form->{currency} ne $form->{defaultcurrency});
  682. for $i (1 .. $form->{paidaccounts}) {
  683. if ($form->{"paid_$i"}) {
  684. $datepaid = $form->datetonum(\%myconfig, $form->{"datepaid_$i"});
  685. $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
  686. $form->error($locale->text('Cannot post payment for a closed period!')) if ($datepaid <= $closedto);
  687. if ($form->{currency} ne $form->{defaultcurrency}) {
  688. $form->{"exchangerate_$i"} = $form->{exchangerate} if ($transdate == $datepaid);
  689. $form->isblank("exchangerate_$i", $locale->text('Exchange rate for payment missing!'));
  690. }
  691. }
  692. }
  693. # if oldname ne name redo form
  694. ($name) = split /--/, $form->{$form->{vc}};
  695. if ($form->{"old$form->{vc}"} ne qq|$name--$form->{"$form->{vc}_id"}|) {
  696. &update;
  697. exit;
  698. }
  699. if (! $form->{repost}) {
  700. if ($form->{id}) {
  701. &repost;
  702. exit;
  703. }
  704. }
  705. if (AA->post_transaction(\%myconfig, \%$form)) {
  706. $form->update_status(\%myconfig);
  707. if ($form->{printandpost}){
  708. &{ "print_$form->{formname}" }($old_form, 1);
  709. }
  710. $form->redirect($locale->text('Transaction posted!'));
  711. } else {
  712. $form->error($locale->text('Cannot post transaction!'));
  713. }
  714. }
  715. sub delete {
  716. $form->{title} = $locale->text('Confirm!');
  717. $form->header;
  718. print qq|
  719. <body>
  720. <form method=post action=$form->{script}>
  721. |;
  722. $form->{action} = "yes";
  723. $form->hide_form;
  724. print qq|
  725. <h2 class=confirm>$form->{title}</h2>
  726. <h4>|.$locale->text('Are you sure you want to delete Transaction').qq| $form->{invnumber}</h4>
  727. <input name=action class=submit type=submit value="|.$locale->text('Yes').qq|">
  728. </form>
  729. </body>
  730. </html>
  731. |;
  732. }
  733. sub yes {
  734. if (AA->delete_transaction(\%myconfig, \%$form, $spool)) {
  735. $form->redirect($locale->text('Transaction deleted!'));
  736. } else {
  737. $form->error($locale->text('Cannot delete transaction!'));
  738. }
  739. }
  740. sub search {
  741. $form->create_links($form->{ARAP}, \%myconfig, $form->{vc});
  742. $form->{"select$form->{ARAP}"} = "<option>\n";
  743. for (@{ $form->{"$form->{ARAP}_links"}{$form->{ARAP}} }) { $form->{"select$form->{ARAP}"} .= "<option>$_->{accno}--$_->{description}\n" }
  744. if (@{ $form->{"all_$form->{vc}"} }) {
  745. $selectname = "";
  746. for (@{ $form->{"all_$form->{vc}"} }) { $selectname .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
  747. $selectname = qq|<select name="$form->{vc}"><option>\n$selectname</select>|;
  748. } else {
  749. $selectname = qq|<input name=$form->{vc} size=35>|;
  750. }
  751. # departments
  752. if (@{ $form->{all_department} }) {
  753. $form->{selectdepartment} = "<option>\n";
  754. for (@{ $form->{all_department} }) { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
  755. $l_department = qq|<input name="l_department" class=checkbox type=checkbox value=Y> |.$locale->text('Department');
  756. $department = qq|
  757. <tr>
  758. <th align=right nowrap>|.$locale->text('Department').qq|</th>
  759. <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
  760. </tr>
  761. |;
  762. }
  763. if (@{ $form->{all_employee} }) {
  764. $form->{selectemployee} = "<option>\n";
  765. for (@{ $form->{all_employee} }) { $form->{selectemployee} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
  766. $employeelabel = ($form->{ARAP} eq 'AR') ? $locale->text('Salesperson') : $locale->text('Employee');
  767. $employee = qq|
  768. <tr>
  769. <th align=right nowrap>$employeelabel</th>
  770. <td colspan=3><select name=employee>$form->{selectemployee}</select></td>
  771. </tr>
  772. |;
  773. $l_employee = qq|<input name="l_employee" class=checkbox type=checkbox value=Y> $employeelabel|;
  774. $l_manager = qq|<input name="l_manager" class=checkbox type=checkbox value=Y> |.$locale->text('Manager');
  775. }
  776. $form->{title} = ($form->{ARAP} eq 'AR') ? $locale->text('AR Transactions') : $locale->text('AP Transactions');
  777. $invnumber = qq|
  778. <tr>
  779. <th align=right nowrap>|.$locale->text('Invoice Number').qq|</th>
  780. <td colspan=3><input name=invnumber size=20></td>
  781. </tr>
  782. <tr>
  783. <th align=right nowrap>|.$locale->text('Order Number').qq|</th>
  784. <td colspan=3><input name=ordnumber size=20></td>
  785. </tr>
  786. <tr>
  787. <th align=right nowrap>|.$locale->text('PO Number').qq|</th>
  788. <td colspan=3><input name=ponumber size=20></td>
  789. </tr>
  790. <tr>
  791. <th align=right nowrap>|.$locale->text('Source').qq|</th>
  792. <td colspan=3><input name=source size=40></td>
  793. </tr>
  794. <tr>
  795. <th align=right nowrap>|.$locale->text('Description').qq|</th>
  796. <td colspan=3><input name=description size=40></td>
  797. </tr>
  798. <tr>
  799. <th align=right nowrap>|.$locale->text('Notes').qq|</th>
  800. <td colspan=3><input name=notes size=40></td>
  801. </tr>
  802. |;
  803. $openclosed = qq|
  804. <tr>
  805. <td nowrap><input name=open class=checkbox type=checkbox value=Y checked> |.$locale->text('Open').qq|</td>
  806. <td nowrap><input name=closed class=checkbox type=checkbox value=Y> |.$locale->text('Closed').qq|</td>
  807. </tr>
  808. |;
  809. $summary = qq|
  810. <tr>
  811. <td><input name=summary type=radio class=radio value=1 checked> |.$locale->text('Summary').qq|</td>
  812. <td><input name=summary type=radio class=radio value=0> |.$locale->text('Detail').qq|
  813. </td>
  814. </tr>
  815. |;
  816. if ($form->{outstanding}) {
  817. $form->{title} = ($form->{ARAP} eq 'AR') ? $locale->text('AR Outstanding') : $locale->text('AP Outstanding');
  818. $invnumber = "";
  819. $openclosed = "";
  820. $summary = "";
  821. }
  822. if (@{ $form->{all_years} }) {
  823. # accounting years
  824. $form->{selectaccountingyear} = "<option>\n";
  825. for (@{ $form->{all_years} }) { $form->{selectaccountingyear} .= qq|<option>$_\n| }
  826. $form->{selectaccountingmonth} = "<option>\n";
  827. for (sort keys %{ $form->{all_month} }) { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n| }
  828. $selectfrom = qq|
  829. <tr>
  830. <th align=right>|.$locale->text('Period').qq|</th>
  831. <td colspan=3>
  832. <select name=month>$form->{selectaccountingmonth}</select>
  833. <select name=year>$form->{selectaccountingyear}</select>
  834. <input name=interval class=radio type=radio value=0 checked>&nbsp;|.$locale->text('Current').qq|
  835. <input name=interval class=radio type=radio value=1>&nbsp;|.$locale->text('Month').qq|
  836. <input name=interval class=radio type=radio value=3>&nbsp;|.$locale->text('Quarter').qq|
  837. <input name=interval class=radio type=radio value=12>&nbsp;|.$locale->text('Year').qq|
  838. </td>
  839. </tr>
  840. |;
  841. }
  842. $name = $locale->text('Customer');
  843. $l_name = qq|<input name="l_name" class=checkbox type=checkbox value=Y checked> $name|;
  844. $l_till = qq|<input name="l_till" class=checkbox type=checkbox value=Y> |.$locale->text('Till');
  845. if ($form->{vc} eq 'vendor') {
  846. $name = $locale->text('Vendor');
  847. $l_till = "";
  848. $l_name = qq|<input name="l_name" class=checkbox type=checkbox value=Y checked> $name|;
  849. }
  850. @a = ();
  851. push @a, qq|<input name="l_runningnumber" class=checkbox type=checkbox value=Y> |.$locale->text('No.');
  852. push @a, qq|<input name="l_id" class=checkbox type=checkbox value=Y> |.$locale->text('ID');
  853. push @a, qq|<input name="l_invnumber" class=checkbox type=checkbox value=Y checked> |.$locale->text('Invoice Number');
  854. push @a, qq|<input name="l_ordnumber" class=checkbox type=checkbox value=Y> |.$locale->text('Order Number');
  855. push @a, qq|<input name="l_ponumber" class=checkbox type=checkbox value=Y> |.$locale->text('PO Number');
  856. push @a, qq|<input name="l_transdate" class=checkbox type=checkbox value=Y checked> |.$locale->text('Invoice Date');
  857. push @a, $l_name;
  858. push @a, $l_employee if $l_employee;
  859. push @a, $l_manager if $l_employee;
  860. push @a, $l_department if $l_department;
  861. push @a, qq|<input name="l_netamount" class=checkbox type=checkbox value=Y> |.$locale->text('Amount');
  862. push @a, qq|<input name="l_tax" class=checkbox type=checkbox value=Y> |.$locale->text('Tax');
  863. push @a, qq|<input name="l_amount" class=checkbox type=checkbox value=Y checked> |.$locale->text('Total');
  864. push @a, qq|<input name="l_curr" class=checkbox type=checkbox value=Y> |.$locale->text('Currency');
  865. push @a, qq|<input name="l_datepaid" class=checkbox type=checkbox value=Y> |.$locale->text('Date Paid');
  866. push @a, qq|<input name="l_paid" class=checkbox type=checkbox value=Y checked> |.$locale->text('Paid');
  867. push @a, qq|<input name="l_duedate" class=checkbox type=checkbox value=Y> |.$locale->text('Due Date');
  868. push @a, qq|<input name="l_due" class=checkbox type=checkbox value=Y> |.$locale->text('Amount Due');
  869. push @a, qq|<input name="l_notes" class=checkbox type=checkbox value=Y> |.$locale->text('Notes');
  870. push @a, $l_till if $l_till;
  871. push @a, qq|<input name="l_shippingpoint" class=checkbox type=checkbox value=Y> |.$locale->text('Shipping Point');
  872. push @a, qq|<input name="l_shipvia" class=checkbox type=checkbox value=Y> |.$locale->text('Ship via');
  873. $form->header;
  874. print qq|
  875. <body>
  876. <form method=post action=$form->{script}>
  877. <table width=100%>
  878. <tr><th class=listtop>$form->{title}</th></tr>
  879. <tr height="5"></tr>
  880. <tr>
  881. <td>
  882. <table>
  883. <tr>
  884. <th align=right>|.$locale->text('Account').qq|</th>
  885. <td colspan=3><select name=$form->{ARAP}>$form->{"select$form->{ARAP}"}</select></td>
  886. </tr>
  887. <tr>
  888. <th align=right>$name</th>
  889. <td colspan=3>$selectname</td>
  890. </tr>
  891. $employee
  892. $department
  893. $invnumber
  894. <tr>
  895. <th align=right>|.$locale->text('Ship via').qq|</th>
  896. <td colspan=3><input name=shipvia size=40></td>
  897. </tr>
  898. <tr>
  899. <th align=right nowrap>|.$locale->text('From').qq|</th>
  900. <td><input name=transdatefrom size=11 title="$myconfig{dateformat}"></td>
  901. <th align=right>|.$locale->text('To').qq|</th>
  902. <td><input name=transdateto size=11 title="$myconfig{dateformat}"></td>
  903. </tr>
  904. $selectfrom
  905. </table>
  906. </td>
  907. </tr>
  908. <tr>
  909. <td>
  910. <table>
  911. <tr>
  912. <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
  913. <td>
  914. <table width=100%>
  915. $openclosed
  916. $summary
  917. |;
  918. $form->{sort} = "transdate";
  919. $form->hide_form(qw(title outstanding sort));
  920. while (@a) {
  921. for (1 .. 5) {
  922. print qq|<td nowrap>|. shift @a;
  923. print qq|</td>\n|;
  924. }
  925. print qq|</tr>\n|;
  926. }
  927. print qq|
  928. <tr>
  929. <td nowrap><input name="l_subtotal" class=checkbox type=checkbox value=Y> |.$locale->text('Subtotal').qq|</td>
  930. </tr>
  931. </table>
  932. </td>
  933. </tr>
  934. </table>
  935. </td>
  936. </tr>
  937. <tr>
  938. <td><hr size=3 noshade></td>
  939. </tr>
  940. </table>
  941. <br>
  942. <input type=hidden name=action value=continue>
  943. <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">|;
  944. $form->hide_form(qw(nextsub path login sessionid));
  945. print qq|
  946. </form>
  947. |;
  948. if ($form->{lynx}) {
  949. require "bin/menu.pl";
  950. &menubar;
  951. }
  952. print qq|
  953. </body>
  954. </html>
  955. |;
  956. }
  957. sub transactions {
  958. if ($form->{$form->{vc}}) {
  959. $form->{$form->{vc}} = $form->unescape($form->{$form->{vc}});
  960. ($form->{$form->{vc}}, $form->{"$form->{vc}_id"}) = split(/--/, $form->{$form->{vc}});
  961. }
  962. AA->transactions(\%myconfig, \%$form);
  963. $href = "$form->{script}?action=transactions";
  964. for (qw(direction oldsort till outstanding path login sessionid summary)) { $href .= qq|&$_=$form->{$_}| }
  965. $href .= "&title=".$form->escape($form->{title});
  966. $form->sort_order();
  967. $callback = "$form->{script}?action=transactions";
  968. for (qw(direction oldsort till outstanding path login sessionid summary)) { $callback .= qq|&$_=$form->{$_}| }
  969. $callback .= "&title=".$form->escape($form->{title},1);
  970. if ($form->{$form->{ARAP}}) {
  971. $callback .= "&$form->{ARAP}=".$form->escape($form->{$form->{ARAP}},1);
  972. $href .= "&$form->{ARAP}=".$form->escape($form->{$form->{ARAP}});
  973. $form->{$form->{ARAP}} =~ s/--/ /;
  974. $option = $locale->text('Account')." : $form->{$form->{ARAP}}";
  975. }
  976. if ($form->{$form->{vc}}) {
  977. $callback .= "&$form->{vc}=".$form->escape($form->{$form->{vc}},1).qq|--$form->{"$form->{vc}_id"}|;
  978. $href .= "&$form->{vc}=".$form->escape($form->{$form->{vc}}).qq|--$form->{"$form->{vc}_id"}|;
  979. $option .= "\n<br>" if ($option);
  980. $name = ($form->{vc} eq 'customer') ? $locale->text('Customer') : $locale->text('Vendor');
  981. $option .= "$name : $form->{$form->{vc}}";
  982. }
  983. if ($form->{department}) {
  984. $callback .= "&department=".$form->escape($form->{department},1);
  985. $href .= "&department=".$form->escape($form->{department});
  986. ($department) = split /--/, $form->{department};
  987. $option .= "\n<br>" if ($option);
  988. $option .= $locale->text('Department')." : $department";
  989. }
  990. if ($form->{employee}) {
  991. $callback .= "&employee=".$form->escape($form->{employee},1);
  992. $href .= "&employee=".$form->escape($form->{employee});
  993. ($employee) = split /--/, $form->{employee};
  994. $option .= "\n<br>" if ($option);
  995. if ($form->{ARAP} eq 'AR') {
  996. $option .= $locale->text('Salesperson');
  997. } else {
  998. $option .= $locale->text('Employee');
  999. }
  1000. $option .= " : $employee";
  1001. }
  1002. if ($form->{invnumber}) {
  1003. $callback .= "&invnumber=".$form->escape($form->{invnumber},1);
  1004. $href .= "&invnumber=".$form->escape($form->{invnumber});
  1005. $option .= "\n<br>" if ($option);
  1006. $option .= $locale->text('Invoice Number')." : $form->{invnumber}";
  1007. }
  1008. if ($form->{ordnumber}) {
  1009. $callback .= "&ordnumber=".$form->escape($form->{ordnumber},1);
  1010. $href .= "&ordnumber=".$form->escape($form->{ordnumber});
  1011. $option .= "\n<br>" if ($option);
  1012. $option .= $locale->text('Order Number')." : $form->{ordnumber}";
  1013. }
  1014. if ($form->{ponumber}) {
  1015. $callback .= "&ponumber=".$form->escape($form->{ponumber},1);
  1016. $href .= "&ponumber=".$form->escape($form->{ponumber});
  1017. $option .= "\n<br>" if ($option);
  1018. $option .= $locale->text('PO Number')." : $form->{ponumber}";
  1019. }
  1020. if ($form->{source}) {
  1021. $callback .= "&source=".$form->escape($form->{source},1);
  1022. $href .= "&source=".$form->escape($form->{source});
  1023. $option .= "\n<br>" if $option;
  1024. $option .= $locale->text('Source')." : $form->{source}";
  1025. }
  1026. if ($form->{description}) {
  1027. $callback .= "&description=".$form->escape($form->{description},1);
  1028. $href .= "&description=".$form->escape($form->{description});
  1029. $option .= "\n<br>" if $option;
  1030. $option .= $locale->text('Description')." : $form->{description}";
  1031. }
  1032. if ($form->{notes}) {
  1033. $callback .= "&notes=".$form->escape($form->{notes},1);
  1034. $href .= "&notes=".$form->escape($form->{notes});
  1035. $option .= "\n<br>" if $option;
  1036. $option .= $locale->text('Notes')." : $form->{notes}";
  1037. }
  1038. if ($form->{shipvia}) {
  1039. $callback .= "&shipvia=".$form->escape($form->{shipvia},1);
  1040. $href .= "&shipvia=".$form->escape($form->{shipvia});
  1041. $option .= "\n<br>" if $option;
  1042. $option .= $locale->text('Ship via')." : $form->{shipvia}";
  1043. }
  1044. if ($form->{transdatefrom}) {
  1045. $callback .= "&transdatefrom=$form->{transdatefrom}";
  1046. $href .= "&transdatefrom=$form->{transdatefrom}";
  1047. $option .= "\n<br>" if ($option);
  1048. $option .= $locale->text('From')."&nbsp;".$locale->date(\%myconfig, $form->{transdatefrom}, 1);
  1049. }
  1050. if ($form->{transdateto}) {
  1051. $callback .= "&transdateto=$form->{transdateto}";
  1052. $href .= "&transdateto=$form->{transdateto}";
  1053. $option .= "\n<br>" if ($option);
  1054. $option .= $locale->text('To')."&nbsp;".$locale->date(\%myconfig, $form->{transdateto}, 1);
  1055. }
  1056. if ($form->{open}) {
  1057. $callback .= "&open=$form->{open}";
  1058. $href .= "&open=$form->{open}";
  1059. $option .= "\n<br>" if ($option);
  1060. $option .= $locale->text('Open');
  1061. }
  1062. if ($form->{closed}) {
  1063. $callback .= "&closed=$form->{closed}";
  1064. $href .= "&closed=$form->{closed}";
  1065. $option .= "\n<br>" if ($option);
  1066. $option .= $locale->text('Closed');
  1067. }
  1068. @columns = $form->sort_columns(qw(transdate id invnumber ordnumber ponumber name netamount tax amount paid due curr datepaid duedate notes till employee manager shippingpoint shipvia department));
  1069. pop @columns if $form->{department};
  1070. unshift @columns, "runningnumber";
  1071. foreach $item (@columns) {
  1072. if ($form->{"l_$item"} eq "Y") {
  1073. push @column_index, $item;
  1074. if ($form->{l_curr} && $item =~ /(amount|tax|paid|due)/) {
  1075. push @column_index, "fx_$item";
  1076. }
  1077. # add column to href and callback
  1078. $callback .= "&l_$item=Y";
  1079. $href .= "&l_$item=Y";
  1080. }
  1081. }
  1082. if (!$form->{summary}) {
  1083. foreach $item (qw(source debit credit accno description projectnumber)) {
  1084. push @column_index, $item;
  1085. }
  1086. }
  1087. if ($form->{l_subtotal} eq 'Y') {
  1088. $callback .= "&l_subtotal=Y";
  1089. $href .= "&l_subtotal=Y";
  1090. }
  1091. $employee = ($form->{ARAP} eq 'AR') ? $locale->text('Salesperson') : $locale->text('Employee');
  1092. $name = ($form->{vc} eq 'customer') ? $locale->text('Customer') : $locale->text('Vendor');
  1093. $column_header{runningnumber} = qq|<th class=listheading>&nbsp;</th>|;
  1094. $column_header{id} = "<th><a class=listheading href=$href&sort=id>".$locale->text('ID')."</a></th>";
  1095. $column_header{transdate} = "<th><a class=listheading href=$href&sort=transdate>".$locale->text('Date')."</a></th>";
  1096. $column_header{duedate} = "<th><a class=listheading href=$href&sort=duedate>".$locale->text('Due Date')."</a></th>";
  1097. $column_header{invnumber} = "<th><a class=listheading href=$href&sort=invnumber>".$locale->text('Invoice')."</a></th>";
  1098. $column_header{ordnumber} = "<th><a class=listheading href=$href&sort=ordnumber>".$locale->text('Order')."</a></th>";
  1099. $column_header{ponumber} = "<th><a class=listheading href=$href&sort=ponumber>".$locale->text('PO Number')."</a></th>";
  1100. $column_header{name} = "<th><a class=listheading href=$href&sort=name>$name</a></th>";
  1101. $column_header{netamount} = "<th class=listheading>" . $locale->text('Amount') . "</th>";
  1102. $column_header{tax} = "<th class=listheading>" . $locale->text('Tax') . "</th>";
  1103. $column_header{amount} = "<th class=listheading>" . $locale->text('Total') . "</th>";
  1104. $column_header{paid} = "<th class=listheading>" . $locale->text('Paid') . "</th>";
  1105. $column_header{datepaid} = "<th><a class=listheading href=$href&sort=datepaid>" . $locale->text('Date Paid') . "</a></th>";
  1106. $column_header{due} = "<th class=listheading>" . $locale->text('Amount Due') . "</th>";
  1107. $column_header{notes} = "<th class=listheading>".$locale->text('Notes')."</th>";
  1108. $column_header{employee} = "<th><a class=listheading href=$href&sort=employee>$employee</th>";
  1109. $column_header{manager} = "<th><a class=listheading href=$href&sort=manager>".$locale->text('Manager')."</th>";
  1110. $column_header{till} = "<th class=listheading><a class=listheading href=$href&sort=till>".$locale->text('Till')."</th>";
  1111. $column_header{shippingpoint} = "<th><a class=listheading href=$href&sort=shippingpoint>" . $locale->text('Shipping Point') . "</a></th>";
  1112. $column_header{shipvia} = "<th><a class=listheading href=$href&sort=shipvia>" . $locale->text('Ship via') . "</a></th>";
  1113. $column_header{curr} = "<th><a class=listheading href=$href&sort=curr>" . $locale->text('Curr') . "</a></th>";
  1114. for (qw(amount tax netamount paid due)) { $column_header{"fx_$_"} = "<th>&nbsp;</th>" }
  1115. $column_header{department} = "<th><a class=listheading href=$href&sort=department>" . $locale->text('Department') . "</a></th>";
  1116. $column_header{accno} = "<th><a class=listheading href=$href&sort=accno>" . $locale->text('Account') . "</a></th>";
  1117. $column_header{source} = "<th><a class=listheading href=$href&sort=source>" . $locale->text('Source') . "</a></th>";
  1118. $column_header{debit} = "<th class=listheading>" . $locale->text('Debit') . "</th>";
  1119. $column_header{credit} = "<th class=listheading>" . $locale->text('Credit') . "</th>";
  1120. $column_header{projectnumber} = "<th><a class=listheading href=$href&sort=projectnumber>" . $locale->text('Project') . "</a></th>";
  1121. $column_header{description} = "<th><a class=listheading href=$href&sort=linedescription>" . $locale->text('Description') . "</a></th>";
  1122. $form->{title} = ($form->{title}) ? $form->{title} : $locale->text('AR Transactions');
  1123. $form->header;
  1124. print qq|
  1125. <body>
  1126. <table width=100%>
  1127. <tr>
  1128. <th class=listtop>$form->{title}</th>
  1129. </tr>
  1130. <tr height="5"></tr>
  1131. <tr>
  1132. <td>$option</td>
  1133. </tr>
  1134. <tr>
  1135. <td>
  1136. <table width=100%>
  1137. <tr class=listheading>
  1138. |;
  1139. for (@column_index) { print "\n$column_header{$_}" }
  1140. print qq|
  1141. </tr>
  1142. |;
  1143. # add sort and escape callback, this one we use for the add sub
  1144. $form->{callback} = $callback .= "&sort=$form->{sort}";
  1145. # escape callback for href
  1146. $callback = $form->escape($callback);
  1147. # flip direction
  1148. $direction = ($form->{direction} eq 'ASC') ? "ASC" : "DESC";
  1149. $href =~ s/&direction=(\w+)&/&direction=$direction&/;
  1150. if (@{ $form->{transactions} }) {
  1151. $sameitem = $form->{transactions}->[0]->{$form->{sort}};
  1152. }
  1153. # sums and tax on reports by Antonio Gallardo
  1154. #
  1155. $i = 0;
  1156. foreach $ref (@{ $form->{transactions} }) {
  1157. $i++;
  1158. if ($form->{l_subtotal} eq 'Y') {
  1159. if ($sameitem ne $ref->{$form->{sort}}) {
  1160. &subtotal;
  1161. $sameitem = $ref->{$form->{sort}};
  1162. }
  1163. }
  1164. if ($form->{l_curr}) {
  1165. for (qw(netamount amount paid)) { $ref->{"fx_$_"} = $ref->{$_}/$ref->{exchangerate} }
  1166. for (qw(netamount amount paid)) { $column_data{"fx_$_"} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{"fx_$_"}, 2, "&nbsp;")."</td>" }
  1167. $column_data{fx_tax} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{fx_amount} - $ref->{fx_netamount}, 2, "&nbsp;")."</td>";
  1168. $column_data{fx_due} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{fx_amount} - $ref->{fx_paid}, 2, "&nbsp;")."</td>";
  1169. $subtotalfxnetamount += $ref->{fx_netamount};
  1170. $subtotalfxamount += $ref->{fx_amount};
  1171. $subtotalfxpaid += $ref->{fx_paid};
  1172. $totalfxnetamount += $ref->{fx_netamount};
  1173. $totalfxamount += $ref->{fx_amount};
  1174. $totalfxpaid += $ref->{fx_paid};
  1175. }
  1176. $column_data{runningnumber} = "<td align=right>$i</td>";
  1177. for (qw(netamount amount paid debit credit)) { $column_data{$_} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{$_}, 2, "&nbsp;")."</td>" }
  1178. $column_data{tax} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount} - $ref->{netamount}, 2, "&nbsp;")."</td>";
  1179. $column_data{due} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount} - $ref->{paid}, 2, "&nbsp;")."</td>";
  1180. $subtotalnetamount += $ref->{netamount};
  1181. $subtotalamount += $ref->{amount};
  1182. $subtotalpaid += $ref->{paid};
  1183. $subtotaldebit += $ref->{debit};
  1184. $subtotalcredit += $ref->{credit};
  1185. $totalnetamount += $ref->{netamount};
  1186. $totalamount += $ref->{amount};
  1187. $totalpaid += $ref->{paid};
  1188. $totaldebit += $ref->{debit};
  1189. $totalcredit += $ref->{credit};
  1190. $module = ($ref->{invoice}) ? ($form->{ARAP} eq 'AR') ? "is.pl" : "ir.pl" : $form->{script};
  1191. $module = ($ref->{till}) ? "ps.pl" : $module;
  1192. $column_data{invnumber} = "<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>";
  1193. for (qw(notes description)) { $ref->{$_} =~ s/\r?\n/<br>/g }
  1194. for (qw(transdate datepaid duedate department ordnumber ponumber notes shippingpoint shipvia employee manager till source description projectnumber)) { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
  1195. for (qw(id curr)) { $column_data{$_} = "<td>$ref->{$_}</td>" }
  1196. $column_data{accno} = 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>|;
  1197. $column_data{name} = 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>|;
  1198. if ($ref->{id} != $sameid) {
  1199. $j++; $j %= 2;
  1200. }
  1201. print "
  1202. <tr class=listrow$j>
  1203. ";
  1204. for (@column_index) { print "\n$column_data{$_}" }
  1205. print qq|
  1206. </tr>
  1207. |;
  1208. $sameid = $ref->{id};
  1209. }
  1210. if ($form->{l_subtotal} eq 'Y') {
  1211. &subtotal;
  1212. $sameitem = $ref->{$form->{sort}};
  1213. }
  1214. # print totals
  1215. print qq|
  1216. <tr class=listtotal>
  1217. |;
  1218. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  1219. $column_data{netamount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalnetamount, 2, "&nbsp;")."</th>";
  1220. $column_data{tax} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalamount - $totalnetamount, 2, "&nbsp;")."</th>";
  1221. $column_data{amount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalamount, 2, "&nbsp;")."</th>";
  1222. $column_data{paid} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalpaid, 2, "&nbsp;")."</th>";
  1223. $column_data{due} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalamount - $totalpaid, 2, "&nbsp;")."</th>";
  1224. $column_data{debit} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totaldebit, 2, "&nbsp;")."</th>";
  1225. $column_data{credit} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalcredit, 2, "&nbsp;")."</th>";
  1226. if ($form->{l_curr} && $form->{sort} eq 'curr' && $form->{l_subtotal}) {
  1227. $column_data{fx_netamount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalfxnetamount, 2, "&nbsp;")."</th>";
  1228. $column_data{fx_tax} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalfxamount - $totalfxnetamount, 2, "&nbsp;")."</th>";
  1229. $column_data{fx_amount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalfxamount, 2, "&nbsp;")."</th>";
  1230. $column_data{fx_paid} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalfxpaid, 2, "&nbsp;")."</th>";
  1231. $column_data{fx_due} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalfxamount - $totalfxpaid, 2, "&nbsp;")."</th>";
  1232. }
  1233. for (@column_index) { print "\n$column_data{$_}" }
  1234. if ($myconfig{acs} !~ /$form->{ARAP}--$form->{ARAP}/) {
  1235. $i = 1;
  1236. if ($form->{ARAP} eq 'AR') {
  1237. $button{'AR--Add Transaction'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('AR Transaction').qq|"> |;
  1238. $button{'AR--Add Transaction'}{order} = $i++;
  1239. $button{'AR--Sales Invoice'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Sales Invoice.').qq|"> |;
  1240. $button{'AR--Sales Invoice'}{order} = $i++;
  1241. } else {
  1242. $button{'AP--Add Transaction'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('AP Transaction').qq|"> |;
  1243. $button{'AP--Add Transaction'}{order} = $i++;
  1244. $button{'AP--Vendor Invoice'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Vendor Invoice.').qq|"> |;
  1245. $button{'AP--Vendor Invoice'}{order} = $i++;
  1246. }
  1247. foreach $item (split /;/, $myconfig{acs}) {
  1248. delete $button{$item};
  1249. }
  1250. }
  1251. print qq|
  1252. </tr>
  1253. </table>
  1254. </td>
  1255. </tr>
  1256. <tr>
  1257. <td><hr size=3 noshade></td>
  1258. </tr>
  1259. </table>
  1260. <br>
  1261. <form method=post action=$form->{script}>
  1262. |;
  1263. $form->hide_form("callback", "path", "login", "sessionid", "$form->{vc}", "$form->{vc}_id");
  1264. if (! $form->{till}) {
  1265. foreach $item (sort { $a->{order} <=> $b->{order} } %button) {
  1266. print $item->{code};
  1267. }
  1268. }
  1269. if ($form->{lynx}) {
  1270. require "bin/menu.pl";
  1271. &menubar;
  1272. }
  1273. print qq|
  1274. </form>
  1275. </body>
  1276. </html>
  1277. |;
  1278. }
  1279. sub subtotal {
  1280. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  1281. $column_data{tax} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount, 2, "&nbsp;")."</th>";
  1282. $column_data{amount} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalamount, 2, "&nbsp;")."</th>";
  1283. $column_data{paid} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalpaid, 2, "&nbsp;")."</th>";
  1284. $column_data{due} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalamount - $subtotalpaid, 2, "&nbsp;")."</th>";
  1285. $column_data{debit} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotaldebit, 2, "&nbsp;")."</th>";
  1286. $column_data{credit} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalcredit, 2, "&nbsp;")."</th>";
  1287. if ($form->{l_curr} && $form->{sort} eq 'curr' && $form->{l_subtotal}) {
  1288. $column_data{fx_tax} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalfxamount - $subtotalfxnetamount, 2, "&nbsp;")."</th>";
  1289. $column_data{fx_amount} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalfxamount, 2, "&nbsp;")."</th>";
  1290. $column_data{fx_paid} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalfxpaid, 2, "&nbsp;")."</th>";
  1291. $column_data{fx_due} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalfxmount - $subtotalfxpaid, 2, "&nbsp;")."</th>";
  1292. }
  1293. $subtotalnetamount = 0;
  1294. $subtotalamount = 0;
  1295. $subtotalpaid = 0;
  1296. $subtotaldebit = 0;
  1297. $subtotalcredit = 0;
  1298. $subtotalfxnetamount = 0;
  1299. $subtotalfxamount = 0;
  1300. $subtotalfxpaid = 0;
  1301. print "<tr class=listsubtotal>";
  1302. for (@column_index) { print "\n$column_data{$_}" }
  1303. print "
  1304. </tr>
  1305. ";
  1306. }