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