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