summaryrefslogtreecommitdiff
path: root/bin/rp.pl
blob: 34d43438d798de1449fc59c24fc71f09daef65dd (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) 2001
  17. #
  18. # Author: DWS Systems Inc.
  19. # Web: http://www.sql-ledger.org
  20. #
  21. # Contributors: Antonio Gallardo <agssa@ibw.com.ni>
  22. # Benjamin Lee <benjaminlee@consultant.com>
  23. #
  24. #
  25. # This program is free software; you can redistribute it and/or modify
  26. # it under the terms of the GNU General Public License as published by
  27. # the Free Software Foundation; either version 2 of the License, or
  28. # (at your option) any later version.
  29. #
  30. # This program is distributed in the hope that it will be useful,
  31. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  32. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  33. # GNU General Public License for more details.
  34. # You should have received a copy of the GNU General Public License
  35. # along with this program; if not, write to the Free Software
  36. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  37. #======================================================================
  38. #
  39. # module for preparing Income Statement and Balance Sheet
  40. #
  41. #======================================================================
  42. require "bin/arap.pl";
  43. use LedgerSMB::PE;
  44. use LedgerSMB::RP;
  45. 1;
  46. # end of main
  47. # this is for our long dates
  48. # $locale->text('January')
  49. # $locale->text('February')
  50. # $locale->text('March')
  51. # $locale->text('April')
  52. # $locale->text('May ')
  53. # $locale->text('June')
  54. # $locale->text('July')
  55. # $locale->text('August')
  56. # $locale->text('September')
  57. # $locale->text('October')
  58. # $locale->text('November')
  59. # $locale->text('December')
  60. # this is for our short month
  61. # $locale->text('Jan')
  62. # $locale->text('Feb')
  63. # $locale->text('Mar')
  64. # $locale->text('Apr')
  65. # $locale->text('May')
  66. # $locale->text('Jun')
  67. # $locale->text('Jul')
  68. # $locale->text('Aug')
  69. # $locale->text('Sep')
  70. # $locale->text('Oct')
  71. # $locale->text('Nov')
  72. # $locale->text('Dec')
  73. # $locale->text('Balance Sheet')
  74. # $locale->text('Income Statement')
  75. # $locale->text('Trial Balance')
  76. # $locale->text('AR Aging')
  77. # $locale->text('AP Aging')
  78. # $locale->text('Tax collected')
  79. # $locale->text('Tax paid')
  80. # $locale->text('Receipts')
  81. # $locale->text('Payments')
  82. # $locale->text('Project Transactions')
  83. # $locale->text('Non-taxable Sales')
  84. # $locale->text('Non-taxable Purchases')
  85. sub report {
  86. %report = ( balance_sheet => { title => 'Balance Sheet' },
  87. income_statement => { title => 'Income Statement' },
  88. trial_balance => { title => 'Trial Balance' },
  89. ar_aging => { title => 'AR Aging', vc => 'customer' },
  90. ap_aging => { title => 'AP Aging', vc => 'vendor' },
  91. tax_collected => { title => 'Tax collected', vc => 'customer' },
  92. tax_paid => { title => 'Tax paid' },
  93. nontaxable_sales => { title => 'Non-taxable Sales', vc => 'customer' },
  94. nontaxable_purchases => { title => 'Non-taxable Purchases' },
  95. receipts => { title => 'Receipts', vc => 'customer' },
  96. payments => { title => 'Payments' },
  97. projects => { title => 'Project Transactions' },
  98. inv_activity => { title => 'Inventory Activity'},
  99. );
  100. $form->{title} = $locale->text($report{$form->{report}}->{title});
  101. $gifi = qq|
  102. <tr>
  103. <th align=right>|.$locale->text('Accounts').qq|</th>
  104. <td><input name=accounttype class=radio type=radio value=standard checked> |.$locale->text('Standard').qq|
  105. <input name=accounttype class=radio type=radio value=gifi> |.$locale->text('GIFI').qq|
  106. </td>
  107. </tr>
  108. |;
  109. # get departments
  110. $form->all_departments(\%myconfig, undef, $report{$form->{report}}->{vc});
  111. if (@{ $form->{all_department} }) {
  112. $form->{selectdepartment} = "<option>\n";
  113. for (@{ $form->{all_department} }) { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
  114. }
  115. $department = qq|
  116. <tr>
  117. <th align=right nowrap>|.$locale->text('Department').qq|</th>
  118. <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
  119. </tr>
  120. | if $form->{selectdepartment};
  121. if (@{ $form->{all_years} }) {
  122. # accounting years
  123. $form->{selectaccountingyear} = "<option>\n";
  124. for (@{ $form->{all_years} }) { $form->{selectaccountingyear} .= qq|<option>$_\n| }
  125. $form->{selectaccountingmonth} = "<option>\n";
  126. for (sort keys %{ $form->{all_month} }) { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n| }
  127. $selectfrom = qq|
  128. <tr>
  129. <th align=right>|.$locale->text('Period').qq|</th>
  130. <td colspan=3>
  131. <select name=month>$form->{selectaccountingmonth}</select>
  132. <select name=year>$form->{selectaccountingyear}</select>
  133. <input name=interval class=radio type=radio value=0 checked>&nbsp;|.$locale->text('Current').qq|
  134. <input name=interval class=radio type=radio value=1>&nbsp;|.$locale->text('Month').qq|
  135. <input name=interval class=radio type=radio value=3>&nbsp;|.$locale->text('Quarter').qq|
  136. <input name=interval class=radio type=radio value=12>&nbsp;|.$locale->text('Year').qq|
  137. </td>
  138. </tr>
  139. |;
  140. $selectto = qq|
  141. <tr>
  142. <th align=right></th>
  143. <td>
  144. <select name=month>$form->{selectaccountingmonth}</select>
  145. <select name=year>$form->{selectaccountingyear}</select>
  146. </td>
  147. </tr>
  148. |;
  149. }
  150. $summary = qq|
  151. <tr>
  152. <th></th>
  153. <td><input name=summary type=radio class=radio value=1 checked> |.$locale->text('Summary').qq|
  154. <input name=summary type=radio class=radio value=0> |.$locale->text('Detail').qq|
  155. </td>
  156. </tr>
  157. |;
  158. # get projects
  159. $form->all_projects(\%myconfig);
  160. if (@{ $form->{all_project} }) {
  161. $form->{selectproject} = "<option>\n";
  162. for (@{ $form->{all_project} }) { $form->{selectproject} .= qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n| }
  163. $project = qq|
  164. <tr>
  165. <th align=right nowrap>|.$locale->text('Project').qq|</th>
  166. <td colspan=3><select name=projectnumber>$form->{selectproject}</select></td>
  167. </tr>|;
  168. }
  169. $form->header;
  170. print qq|
  171. <body>
  172. <form method=post action=$form->{script}>
  173. <input type=hidden name=title value="$form->{title}">
  174. <table width=100%>
  175. <tr>
  176. <th class=listtop>$form->{title}</th>
  177. </tr>
  178. <tr height="5"></tr>
  179. <tr>
  180. <td>
  181. <table>
  182. $department
  183. |;
  184. if ($form->{report} eq "projects") {
  185. print qq|
  186. $project
  187. <input type=hidden name=nextsub value=generate_projects>
  188. <tr>
  189. <th align=right>|.$locale->text('From').qq|</th>
  190. <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
  191. <th align=right>|.$locale->text('To').qq|</th>
  192. <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
  193. </tr>
  194. $selectfrom
  195. </table>
  196. </td>
  197. </tr>
  198. <tr>
  199. <td>
  200. <table>
  201. <tr>
  202. <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
  203. <td><input name=l_heading class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Heading').qq|
  204. <input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Subtotal').qq|</td>
  205. </tr>
  206. |;
  207. }
  208. if ($form->{report} eq "inv_activity"){
  209. $gifi = '';
  210. print qq|
  211. <input type=hidden name=nextsub value=generate_inv_activity>
  212. <tr>
  213. <th align=right>|.$locale->text('From').qq|</th>
  214. <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
  215. <th align=right>|.$locale->text('To').qq|</th>
  216. <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
  217. </tr>
  218. <tr>
  219. <th align=right>|.$locale->text('Period').qq|</th>
  220. <td colspan=3>
  221. <select name=frommonth>$form->{selectaccountingmonth}</select>
  222. <select name=fromyear>$form->{selectaccountingyear}</select>
  223. <input name=interval class=radio type=radio value=0 checked>|.$locale->text('Current').qq|
  224. <input name=interval class=radio type=radio value=1>|.$locale->text('Month').qq|
  225. <input name=interval class=radio type=radio value=3>|.$locale->text('Quarter').qq|
  226. <input name=interval class=radio type=radio value=12>|.$locale->text('Year').qq|
  227. </td>
  228. </tr>
  229. </table>
  230. <table>
  231. <tr>
  232. <th>|.$locale->text("Part Number").qq|</th>
  233. <td><input name=partnumber></td>
  234. <th>|.$locale->text('Description').qq|</th>
  235. <td><input type=text name=description></td>
  236. </tr>|;
  237. }
  238. if ($form->{report} eq "income_statement") {
  239. print qq|
  240. $project
  241. <input type=hidden name=nextsub value=generate_income_statement>
  242. <tr>
  243. <th align=right>|.$locale->text('From').qq|</th>
  244. <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
  245. <th align=right>|.$locale->text('To').qq|</th>
  246. <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
  247. </tr>
  248. |;
  249. if ($selectfrom) {
  250. print qq|
  251. <tr>
  252. <th align=right>|.$locale->text('Period').qq|</th>
  253. <td colspan=3>
  254. <select name=frommonth>$form->{selectaccountingmonth}</select>
  255. <select name=fromyear>$form->{selectaccountingyear}</select>
  256. <input name=interval class=radio type=radio value=0 checked>&nbsp;|.$locale->text('Current').qq|
  257. <input name=interval class=radio type=radio value=1>&nbsp;|.$locale->text('Month').qq|
  258. <input name=interval class=radio type=radio value=3>&nbsp;|.$locale->text('Quarter').qq|
  259. <input name=interval class=radio type=radio value=12>&nbsp;|.$locale->text('Year').qq|
  260. </td>
  261. </tr>
  262. |;
  263. }
  264. print qq|
  265. <tr>
  266. <th align=right>|.$locale->text('Compare to').qq|</th>
  267. </tr>
  268. <tr>
  269. <th align=right>|.$locale->text('From').qq|</th>
  270. <td><input name=comparefromdate size=11 title="$myconfig{dateformat}"></td>
  271. <th align=right>|.$locale->text('To').qq|</th>
  272. <td><input name=comparetodate size=11 title="$myconfig{dateformat}"></td>
  273. </tr>
  274. |;
  275. if ($selectto) {
  276. print qq|
  277. <tr>
  278. <th align=right>|.$locale->text('Period').qq|</th>
  279. <td>
  280. <select name=comparemonth>$form->{selectaccountingmonth}</select>
  281. <select name=compareyear>$form->{selectaccountingyear}</select>
  282. </td>
  283. </tr>
  284. |;
  285. }
  286. print qq|
  287. <tr>
  288. <th align=right>|.$locale->text('Decimalplaces').qq|</th>
  289. <td><input name=decimalplaces size=3 value=2></td>
  290. </tr>
  291. </table>
  292. </td>
  293. </tr>
  294. <tr>
  295. <td>
  296. <table>
  297. <tr>
  298. <th align=right>|.$locale->text('Method').qq|</th>
  299. <td colspan=3><input name=method class=radio type=radio value=accrual checked>|.$locale->text('Accrual').qq|
  300. &nbsp;<input name=method class=radio type=radio value=cash>|.$locale->text('Cash').qq|</td>
  301. </tr>
  302. <tr>
  303. <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
  304. <td colspan=3><input name=l_heading class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Heading').qq|
  305. <input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Subtotal').qq|
  306. <input name=l_accno class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Account Number').qq|</td>
  307. </tr>
  308. |;
  309. }
  310. if ($form->{report} eq "balance_sheet") {
  311. print qq|
  312. <input type=hidden name=nextsub value=generate_balance_sheet>
  313. <tr>
  314. <th align=right>|.$locale->text('as at').qq|</th>
  315. <td><input name=asofdate size=11 title="$myconfig{dateformat}" value=$form->{asofdate}></td>
  316. |;
  317. if ($selectfrom) {
  318. print qq|
  319. <td>
  320. <select name=asofmonth>$form->{selectaccountingmonth}</select>
  321. <select name=asofyear>$form->{selectaccountingyear}</select>
  322. </td>
  323. |;
  324. }
  325. print qq|
  326. </tr>
  327. <th align=right nowrap>|.$locale->text('Compare to').qq|</th>
  328. <td><input name=compareasofdate size=11 title="$myconfig{dateformat}"></td>
  329. <td>
  330. |;
  331. if ($selectto) {
  332. print qq|
  333. <select name=compareasofmonth>$form->{selectaccountingmonth}</select>
  334. <select name=compareasofyear>$form->{selectaccountingyear}</select>
  335. </td>
  336. |;
  337. }
  338. print qq|
  339. </tr>
  340. <tr>
  341. <th align=right>|.$locale->text('Decimalplaces').qq|</th>
  342. <td><input name=decimalplaces size=3 value=2></td>
  343. </tr>
  344. </table>
  345. </td>
  346. </tr>
  347. <tr>
  348. <td>
  349. <table>
  350. <tr>
  351. <th align=right>|.$locale->text('Method').qq|</th>
  352. <td colspan=3><input name=method class=radio type=radio value=accrual checked>|.$locale->text('Accrual').qq|
  353. &nbsp;<input name=method class=radio type=radio value=cash>|.$locale->text('Cash').qq|</td>
  354. </tr>
  355. <tr>
  356. <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
  357. <td><input name=l_heading class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Heading').qq|
  358. <input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Subtotal').qq|
  359. <input name=l_accno class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Account Number').qq|</td>
  360. </tr>
  361. |;
  362. }
  363. if ($form->{report} eq "trial_balance") {
  364. print qq|
  365. <input type=hidden name=nextsub value=generate_trial_balance>
  366. <tr>
  367. <th align=right>|.$locale->text('From').qq|</th>
  368. <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
  369. <th align=right>|.$locale->text('To').qq|</th>
  370. <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
  371. </tr>
  372. $selectfrom
  373. </table>
  374. </td>
  375. </tr>
  376. <tr>
  377. <td>
  378. <table>
  379. <tr>
  380. <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
  381. <td><input name=l_heading class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Heading').qq|
  382. <input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Subtotal').qq|
  383. <input name=all_accounts class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('All Accounts').qq|</td>
  384. </tr>
  385. |;
  386. }
  387. if ($form->{report} =~ /^tax_/) {
  388. $gifi = "";
  389. $form->{db} = ($form->{report} =~ /_collected/) ? "ar" : "ap";
  390. RP->get_taxaccounts(\%myconfig, \%$form);
  391. print qq|
  392. <input type=hidden name=nextsub value=generate_tax_report>
  393. <tr>
  394. <th align=right>|.$locale->text('From').qq|</th>
  395. <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
  396. <th align=right>|.$locale->text('To').qq|</th>
  397. <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
  398. </tr>
  399. $selectfrom
  400. $summary
  401. <tr>
  402. <th align=right>|.$locale->text('Report for').qq|</th>
  403. <td colspan=3>
  404. |;
  405. $checked = "checked";
  406. foreach $ref (@{ $form->{taxaccounts} }) {
  407. print qq|<input name=accno class=radio type=radio value=$ref->{accno} $checked>&nbsp;$ref->{description}
  408. <input name="$ref->{accno}_description" type=hidden value="$ref->{description}">
  409. <input name="$ref->{accno}_rate" type=hidden value="$ref->{rate}">|;
  410. $checked = "";
  411. }
  412. print qq|
  413. <input type=hidden name=db value=$form->{db}>
  414. <input type=hidden name=sort value=transdate>
  415. </td>
  416. </tr>
  417. |;
  418. if (@{ $form->{gifi_taxaccounts} }) {
  419. print qq|
  420. <tr>
  421. <th align=right>|.$locale->text('GIFI').qq|</th>
  422. <td colspan=3>
  423. |;
  424. foreach $ref (@{ $form->{gifi_taxaccounts} }) {
  425. print qq|<input name=accno class=radio type=radio value="gifi_$ref->{accno}">&nbsp;$ref->{description}
  426. <input name="gifi_$ref->{accno}_description" type=hidden value="$ref->{description}">
  427. <input name="gifi_$ref->{accno}_rate" type=hidden value="$ref->{rate}">|;
  428. }
  429. print qq|
  430. </td>
  431. </tr>
  432. |;
  433. }
  434. print qq|
  435. <tr>
  436. <th align=right>|.$locale->text('Method').qq|</th>
  437. <td colspan=3><input name=method class=radio type=radio value=accrual checked>|.$locale->text('Accrual').qq|
  438. &nbsp;<input name=method class=radio type=radio value=cash>|.$locale->text('Cash').qq|</td>
  439. </tr>
  440. </table>
  441. </td>
  442. </tr>
  443. <tr>
  444. <td>
  445. <table>
  446. <tr>
  447. <th align=right>|.$locale->text('Include in Report').qq|</th>
  448. <td>
  449. <table>
  450. <tr>
  451. <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
  452. <td>|.$locale->text('ID').qq|</td>
  453. <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
  454. <td>|.$locale->text('Invoice').qq|</td>
  455. <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
  456. <td>|.$locale->text('Date').qq|</td>
  457. </tr>
  458. <tr>
  459. <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
  460. |;
  461. if ($form->{db} eq 'ar') {
  462. print qq|<td>|.$locale->text('Customer').qq|</td>|;
  463. }
  464. if ($form->{db} eq 'ap') {
  465. print qq|<td>|.$locale->text('Vendor').qq|</td>|;
  466. }
  467. print qq|
  468. <td><input name="l_description" class=checkbox type=checkbox value=Y checked></td>
  469. <td>|.$locale->text('Description').qq|</td>
  470. <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
  471. <td>|.$locale->text('Amount').qq|</td>
  472. <td><input name="l_tax" class=checkbox type=checkbox value=Y checked></td>
  473. <td>|.$locale->text('Tax').qq|</td>
  474. <td><input name="l_total" class=checkbox type=checkbox value=Y checked></td>
  475. <td>|.$locale->text('Total').qq|</td>
  476. </tr>
  477. <tr>
  478. </tr>
  479. <tr>
  480. <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
  481. <td>|.$locale->text('Subtotal').qq|</td>
  482. </tr>
  483. </table>
  484. </td>
  485. </tr>
  486. |;
  487. }
  488. if ($form->{report} =~ /^nontaxable_/) {
  489. $gifi = "";
  490. $form->{db} = ($form->{report} =~ /_sales/) ? "ar" : "ap";
  491. print qq|
  492. <input type=hidden name=nextsub value=generate_tax_report>
  493. <input type=hidden name=db value=$form->{db}>
  494. <input type=hidden name=sort value=transdate>
  495. <input type=hidden name=report value=$form->{report}>
  496. <tr>
  497. <th align=right>|.$locale->text('From').qq|</th>
  498. <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
  499. <th align=right>|.$locale->text('To').qq|</th>
  500. <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
  501. </tr>
  502. $selectfrom
  503. $summary
  504. <tr>
  505. <th align=right>|.$locale->text('Method').qq|</th>
  506. <td colspan=3><input name=method class=radio type=radio value=accrual checked>|.$locale->text('Accrual').qq|
  507. &nbsp;<input name=method class=radio type=radio value=cash>|.$locale->text('Cash').qq|</td>
  508. </tr>
  509. <tr>
  510. <th align=right>|.$locale->text('Include in Report').qq|</th>
  511. <td colspan=3>
  512. <table>
  513. <tr>
  514. <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
  515. <td>|.$locale->text('ID').qq|</td>
  516. <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
  517. <td>|.$locale->text('Invoice').qq|</td>
  518. <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
  519. <td>|.$locale->text('Date').qq|</td>
  520. </tr>
  521. <tr>
  522. <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
  523. |;
  524. if ($form->{db} eq 'ar') {
  525. print qq|<td>|.$locale->text('Customer').qq|</td>|;
  526. }
  527. if ($form->{db} eq 'ap') {
  528. print qq|<td>|.$locale->text('Vendor').qq|</td>|;
  529. }
  530. print qq|
  531. <td><input name="l_description" class=checkbox type=checkbox value=Y checked></td>
  532. <td>|.$locale->text('Description').qq|</td>
  533. <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
  534. <td>|.$locale->text('Amount').qq|</td>
  535. </tr>
  536. <tr>
  537. <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
  538. <td>|.$locale->text('Subtotal').qq|</td>
  539. </tr>
  540. </table>
  541. </td>
  542. </tr>
  543. |;
  544. }
  545. if (($form->{report} eq "ar_aging") || ($form->{report} eq "ap_aging")) {
  546. $gifi = "";
  547. if ($form->{report} eq 'ar_aging') {
  548. $label = $locale->text('Customer');
  549. $form->{vc} = 'customer';
  550. } else {
  551. $label = $locale->text('Vendor');
  552. $form->{vc} = 'vendor';
  553. }
  554. $nextsub = "generate_$form->{report}";
  555. # setup vc selection
  556. $form->all_vc(\%myconfig, $form->{vc}, ($form->{vc} eq 'customer') ? "AR" : "AP");
  557. for (@{ $form->{"all_$form->{vc}"} }) { $vc .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
  558. $vc = ($vc) ? qq|<select name=$form->{vc}><option>\n$vc</select>| : qq|<input name=$form->{vc} size=35>|;
  559. $postscript = "postscript" if $myconfig{printer};
  560. print qq|
  561. <tr>
  562. <th align=right>|.$locale->text($label).qq|</th>
  563. <td>$vc</td>
  564. </tr>
  565. <tr>
  566. <th align=right>|.$locale->text('To').qq|</th>
  567. <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
  568. </tr>
  569. $selectto
  570. <input type=hidden name=type value=statement>
  571. <input type=hidden name=format value=$postscript>
  572. <input type=hidden name=media value="$myconfig{printer}">
  573. <input type=hidden name=nextsub value=$nextsub>
  574. <input type=hidden name=action value=$nextsub>
  575. $summary
  576. <tr>
  577. <table>
  578. <tr>
  579. <th>|.$locale->text('Include in Report').qq|</th>
  580. <td>
  581. <table>
  582. <tr>
  583. <td nowrap><input name=overdue type=radio class=radio value=0 checked> |.$locale->text('Aged').qq|</td>
  584. <td nowrap><input name=overdue type=radio class=radio value=1> |.$locale->text('Overdue').qq|</td>
  585. </tr>
  586. <tr>
  587. <td nowrap width=70><input name=c0 type=checkbox class=checkbox value=1 checked> |.$locale->text('Current').qq|</td>
  588. <td nowrap width=70><input name=c30 type=checkbox class=checkbox value=1 checked> 30</td>
  589. <td nowrap width=70><input name=c60 type=checkbox class=checkbox value=1 checked> 60</td>
  590. <td nowrap width=70><input name=c90 type=checkbox class=checkbox value=1 checked> 90</td>
  591. </td>
  592. </tr>
  593. </table>
  594. </td>
  595. </tr>
  596. </table>
  597. </tr>
  598. |;
  599. }
  600. # above action can be removed if there is more than one input field
  601. if ($form->{report} =~ /(receipts|payments)$/) {
  602. $gifi = "";
  603. $form->{db} = ($form->{report} =~ /payments$/) ? "ap" : "ar";
  604. RP->paymentaccounts(\%myconfig, \%$form);
  605. $selection = "<option>\n";
  606. foreach $ref (@{ $form->{PR} }) {
  607. $paymentaccounts .= "$ref->{accno} ";
  608. $selection .= "<option>$ref->{accno}--$ref->{description}\n";
  609. }
  610. chop $paymentaccounts;
  611. print qq|
  612. <input type=hidden name=nextsub value=list_payments>
  613. <tr>
  614. <th align=right nowrap>|.$locale->text('Account').qq|</th>
  615. <td colspan=3><select name=account>$selection</select>
  616. <input type=hidden name=paymentaccounts value="$paymentaccounts">
  617. </td>
  618. </tr>
  619. <tr>
  620. <th align=right nowrap>|.$locale->text('Description').qq|</th>
  621. <td colspan=3><input name=description size=35></td>
  622. </tr>
  623. <tr>
  624. <th align=right nowrap>|.$locale->text('Source').qq|</th>
  625. <td colspan=3><input name=source></td>
  626. </tr>
  627. <tr>
  628. <th align=right nowrap>|.$locale->text('Memo').qq|</th>
  629. <td colspan=3><input name=memo size=30></td>
  630. </tr>
  631. <tr>
  632. <th align=right>|.$locale->text('From').qq|</th>
  633. <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
  634. <th align=right>|.$locale->text('To').qq|</th>
  635. <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
  636. </tr>
  637. $selectfrom
  638. <tr>
  639. <td align=right><input type=checkbox class=checkbox name=fx_transaction value=1 checked></td>
  640. <td colspan=3>|.$locale->text('Include Exchange Rate Difference').qq|</td>
  641. </tr>
  642. <tr>
  643. <td align=right><input name=l_subtotal class=checkbox type=checkbox value=Y></td>
  644. <td align=left colspan=3>|.$locale->text('Subtotal').qq|</th>
  645. </tr>
  646. <input type=hidden name=db value=$form->{db}>
  647. <input type=hidden name=sort value=transdate>
  648. |;
  649. }
  650. print qq|
  651. $gifi
  652. </table>
  653. </td>
  654. </tr>
  655. <tr>
  656. <td><hr size=3 noshade></td>
  657. </tr>
  658. </table>
  659. <br>
  660. <input type="hidden" name="path" value="$form->{path}">
  661. <input type="hidden" name="login" value="$form->{login}">
  662. <input type="hidden" name="sessionid" value="$form->{sessionid}">
  663. <button type="submit" class="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
  664. </form>
  665. |;
  666. if ($form->{lynx}) {
  667. require "bin/menu.pl";
  668. &menubar;
  669. }
  670. print qq|
  671. </body>
  672. </html>
  673. |;
  674. }
  675. sub continue { &{$form->{nextsub}} };
  676. sub generate_inv_activity {
  677. $form->header;
  678. RP->inventory_activity(\%myconfig, \%$form);
  679. $title = $form->escape($form->{title});
  680. # if ($form->{department}) {
  681. # ($department) = split /--/, $form->{department};
  682. # $options = $locale->text('Department')." : $department<br>";
  683. # $department = $form->escape($form->{department});
  684. # }
  685. ## if ($form->{projectnumber}) {
  686. # ($projectnumber) = split /--/, $form->{projectnumber};
  687. # $options .= $locale->text('Project Number')." : $projectnumber<br>";
  688. # $projectnumber = $form->escape($form->{projectnumber});
  689. # }
  690. # if there are any dates
  691. if ($form->{fromdate} || $form->{todate}) {
  692. if ($form->{fromdate}) {
  693. $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
  694. }
  695. if ($form->{todate}) {
  696. $todate = $locale->date(\%myconfig, $form->{todate}, 1);
  697. }
  698. $form->{period} = "$fromdate - $todate";
  699. } else {
  700. $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
  701. }
  702. $options .= $form->{period};
  703. @column_index = qw(partnumber description sold revenue received expense);
  704. $href = qq|rp.pl?path=$form->{path}&action=continue&accounttype=$form->{accounttype}&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&l_heading=$form->{l_heading}&l_subtotal=$form->{l_subtotal}&department=$department&projectnumber=$projectnumber&project_id=$form->{project_id}&title=$title&nextsub=$form->{nextsub}|;
  705. $column_header{partnumber} = qq|
  706. <th class=listheading><a class=listheading href="$href&sort_col=partnumber">|
  707. .$locale->text('Part Number').qq|</a></th>|;
  708. $column_header{description} = qq|
  709. <th class=listheading><a class=listheading href="$href&sort_col=description">|
  710. .$locale->text('Description').qq|</a></th>|;
  711. $column_header{sold} = qq|
  712. <th class=listheading><a class=listheading href="$href&sort_col=sold">|
  713. .$locale->text('Sold').qq|</a></th>|;
  714. $column_header{revenue} = qq|
  715. <th class=listheading><a class=listheading href="$href&sort_col=revenue">|
  716. .$locale->text('Revenue').qq|</a></th>|;
  717. $column_header{received} = qq|
  718. <th class=listheading><a class=listheading href="$href&sort_col=received">|
  719. .$locale->text('Received').qq|</a></th>|;
  720. $column_header{expense} = qq|
  721. <th class=listheading><a class=listheading href="$href&sort_col=expense">|
  722. .$locale->text('Expense').qq|</a></th>|;
  723. print qq|
  724. <body>
  725. <table width=100%>
  726. <tr>
  727. <th class=listtop>$form->{title}</th>
  728. </tr>
  729. <tr height="5"></tr>
  730. <tr>
  731. <td>$options</td>
  732. </tr>
  733. <tr>
  734. <td>
  735. <table width=100%>
  736. <tr>|;
  737. map { print "$column_header{$_}\n" } @column_index;
  738. print qq|
  739. </tr>
  740. |;
  741. if ($form->{sort_col} eq 'qty' || $form->{sort_col} eq 'revenue'){
  742. $form->{sort_type} = 'numeric';
  743. }
  744. $i = 0;
  745. $cols = "l_transdate=Y&l_name=Y&l_invnumber=Y&summary=1";
  746. $dates= "transdatefrom=$form->{fromdate}&transdateto=$form->{todate}&year=$form->{fromyear}&month=$form->{frommonth}&interval=$form->{interval}";
  747. $base="path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  748. $form->{callback} = "rp.pl?action=continue&$base";
  749. $form->{callback} = $form->escape($form->{callback});
  750. $callback = "callback=$form->{callback}";
  751. # sort the whole thing by account numbers and display
  752. foreach $ref (@{ $form->{TB} }) {
  753. $description = $form->escape($ref->{description});
  754. $i = $i % 2;
  755. $pnumhref="ic.pl?action=edit&id=$ref->{id}&$base&callback=$form->{callback}";
  756. $soldhref="ar.pl?action=transactions&partsid=$ref->{id}&$base&$cols&$dates&$callback";
  757. $rechref="ap.pl?action=transactions&partsid=$ref->{id}&$base&$cols&$dates&callback=$form->{callback}";
  758. $ml = ($ref->{category} =~ /(A|E)/) ? -1 : 1;
  759. $debit = $form->format_amount(\%myconfig, $ref->{debit}, 2, "&nbsp;");
  760. $credit = $form->format_amount(\%myconfig, $ref->{credit}, 2, "&nbsp;");
  761. $begbalance = $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2, "&nbsp;");
  762. $endbalance = $form->format_amount(\%myconfig, ($ref->{balance} + $ref->{amount}) * $ml, 2, "&nbsp;");
  763. $ref->{partnumber} = qq|<a href="$pnumhref">$ref->{partnumber}</a>|;
  764. $ref->{sold} = qq|<a href="$soldhref">$ref->{sold}</a>|;
  765. $ref->{received} = qq|<a href="$rechref">$ref->{received}<a/>|;
  766. map { $column_data{$_} = "<td>&nbsp;</td>" }
  767. @column_index;
  768. print qq|
  769. <tr class=listrow$i>
  770. |;
  771. map { print "<td>$ref->{$_}</td>\n" } @column_index;
  772. print qq|
  773. </tr>
  774. |;
  775. ++$i;
  776. }
  777. print qq|
  778. </tr>
  779. </table>
  780. </td>
  781. </tr>
  782. <tr>
  783. <td><hr size=3 noshade></td>
  784. </tr>
  785. </table>
  786. </body>
  787. </html>
  788. |;
  789. }
  790. sub generate_income_statement {
  791. $form->{padding} = "&nbsp;&nbsp;";
  792. $form->{bold} = "<b>";
  793. $form->{endbold} = "</b>";
  794. $form->{br} = "<br>";
  795. RP->income_statement(\%myconfig, \%$form);
  796. ($form->{department}) = split /--/, $form->{department};
  797. ($form->{projectnumber}) = split /--/, $form->{projectnumber};
  798. $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
  799. $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
  800. # if there are any dates construct a where
  801. if ($form->{fromdate} || $form->{todate}) {
  802. unless ($form->{todate}) {
  803. $form->{todate} = $form->current_date(\%myconfig);
  804. }
  805. $longtodate = $locale->date(\%myconfig, $form->{todate}, 1);
  806. $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
  807. $longfromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
  808. $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
  809. $form->{this_period} = "$shortfromdate<br>\n$shorttodate";
  810. $form->{period} = $locale->text('for Period').qq|<br>\n$longfromdate |.$locale->text('To').qq| $longtodate|;
  811. }
  812. if ($form->{comparefromdate} || $form->{comparetodate}) {
  813. $longcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 1);
  814. $shortcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 0);
  815. $longcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 1);
  816. $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
  817. $form->{last_period} = "$shortcomparefromdate<br>\n$shortcomparetodate";
  818. $form->{period} .= "<br>\n$longcomparefromdate ".$locale->text('To').qq| $longcomparetodate|;
  819. }
  820. # setup variables for the form
  821. @a = qw(company address businessnumber);
  822. for (@a) { $form->{$_} = $myconfig{$_} }
  823. $form->{address} =~ s/\\n/<br>/g;
  824. $form->{templates} = $myconfig{templates};
  825. $form->{IN} = "income_statement.html";
  826. $form->parse_template;
  827. }
  828. sub generate_balance_sheet {
  829. $form->{padding} = "&nbsp;&nbsp;";
  830. $form->{bold} = "<b>";
  831. $form->{endbold} = "</b>";
  832. $form->{br} = "<br>";
  833. RP->balance_sheet(\%myconfig, \%$form);
  834. $form->{asofdate} = $form->current_date(\%myconfig) unless $form->{asofdate};
  835. $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
  836. ($form->{department}) = split /--/, $form->{department};
  837. # define Current Earnings account
  838. $padding = ($form->{l_heading}) ? $form->{padding} : "";
  839. push(@{$form->{equity_account}}, $padding.$locale->text('Current Earnings'));
  840. $form->{this_period} = $locale->date(\%myconfig, $form->{asofdate}, 0);
  841. $form->{last_period} = $locale->date(\%myconfig, $form->{compareasofdate}, 0);
  842. $form->{IN} = "balance_sheet.html";
  843. # setup company variables for the form
  844. for (qw(company address businessnumber nativecurr)) { $form->{$_} = $myconfig{$_} }
  845. $form->{address} =~ s/\\n/<br>/g;
  846. $form->{templates} = $myconfig{templates};
  847. $form->parse_template;
  848. }
  849. sub generate_projects {
  850. $form->{nextsub} = "generate_projects";
  851. $form->{title} = $locale->text('Project Transactions');
  852. RP->trial_balance(\%myconfig, \%$form);
  853. &list_accounts;
  854. }
  855. # Antonio Gallardo
  856. #
  857. # D.S. Feb 16, 2001
  858. # included links to display transactions for period entered
  859. # added headers and subtotals
  860. #
  861. sub generate_trial_balance {
  862. # get for each account initial balance, debits and credits
  863. RP->trial_balance(\%myconfig, \%$form);
  864. $form->{nextsub} = "generate_trial_balance";
  865. $form->{title} = $locale->text('Trial Balance');
  866. $form->{callback} = "$form->{script}?action=generate_trial_balance";
  867. for (qw(login path sessionid nextsub fromdate todate month year interval l_heading l_subtotal all_accounts accounttype title)) { $form->{callback} .= "&$_=$form->{$_}" }
  868. $form->{callback} = $form->escape($form->{callback});
  869. &list_accounts;
  870. }
  871. sub list_accounts {
  872. $title = $form->escape($form->{title});
  873. if ($form->{department}) {
  874. ($department) = split /--/, $form->{department};
  875. $options = $locale->text('Department')." : $department<br>";
  876. $department = $form->escape($form->{department});
  877. }
  878. if ($form->{projectnumber}) {
  879. ($projectnumber) = split /--/, $form->{projectnumber};
  880. $options .= $locale->text('Project Number')." : $projectnumber<br>";
  881. $projectnumber = $form->escape($form->{projectnumber});
  882. }
  883. # if there are any dates
  884. if ($form->{fromdate} || $form->{todate}) {
  885. if ($form->{fromdate}) {
  886. $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
  887. }
  888. if ($form->{todate}) {
  889. $todate = $locale->date(\%myconfig, $form->{todate}, 1);
  890. }
  891. $form->{period} = "$fromdate - $todate";
  892. } else {
  893. $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
  894. }
  895. $options .= $form->{period};
  896. @column_index = qw(accno description begbalance debit credit endbalance);
  897. $column_header{accno} = qq|<th class=listheading>|.$locale->text('Account').qq|</th>|;
  898. $column_header{description} = qq|<th class=listheading>|.$locale->text('Description').qq|</th>|;
  899. $column_header{debit} = qq|<th class=listheading>|.$locale->text('Debit').qq|</th>|;
  900. $column_header{credit} = qq|<th class=listheading>|.$locale->text('Credit').qq|</th>|;
  901. $column_header{begbalance} = qq|<th class=listheading>|.$locale->text('Balance').qq|</th>|;
  902. $column_header{endbalance} = qq|<th class=listheading>|.$locale->text('Balance').qq|</th>|;
  903. if ($form->{accounttype} eq 'gifi') {
  904. $column_header{accno} = qq|<th class=listheading>|.$locale->text('GIFI').qq|</th>|;
  905. }
  906. $form->header;
  907. print qq|
  908. <body>
  909. <table width=100%>
  910. <tr>
  911. <th class=listtop>$form->{title}</th>
  912. </tr>
  913. <tr height="5"></tr>
  914. <tr>
  915. <td>$options</td>
  916. </tr>
  917. <tr>
  918. <td>
  919. <table width=100%>
  920. <tr>|;
  921. for (@column_index) { print "$column_header{$_}\n" }
  922. print qq|
  923. </tr>
  924. |;
  925. # sort the whole thing by account numbers and display
  926. foreach $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} }) {
  927. $description = $form->escape($ref->{description});
  928. $href = qq|ca.pl?path=$form->{path}&action=list_transactions&accounttype=$form->{accounttype}&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&sort=transdate&l_heading=$form->{l_heading}&l_subtotal=$form->{l_subtotal}&department=$department&projectnumber=$projectnumber&project_id=$form->{project_id}&title=$title&nextsub=$form->{nextsub}&prevreport=$form->{callback}|;
  929. if ($form->{accounttype} eq 'gifi') {
  930. $href .= "&gifi_accno=$ref->{accno}&gifi_description=$description";
  931. $na = $locale->text('N/A');
  932. if (!$ref->{accno}) {
  933. for (qw(accno description)) { $ref->{$_} = $na }
  934. }
  935. } else {
  936. $href .= "&accno=$ref->{accno}&description=$description";
  937. }
  938. $ml = ($ref->{category} =~ /(A|E)/) ? -1 : 1;
  939. $ml *= -1 if $ref->{contra};
  940. $debit = $form->format_amount(\%myconfig, $ref->{debit}, 2, "&nbsp;");
  941. $credit = $form->format_amount(\%myconfig, $ref->{credit}, 2, "&nbsp;");
  942. $begbalance = $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2, "&nbsp;");
  943. $endbalance = $form->format_amount(\%myconfig, ($ref->{balance} + $ref->{amount}) * $ml, 2, "&nbsp;");
  944. if ($ref->{charttype} eq "H" && $subtotal && $form->{l_subtotal}) {
  945. if ($subtotal) {
  946. for (qw(accno begbalance endbalance)) { $column_data{$_} = "<th>&nbsp;</th>" }
  947. $subtotalbegbalance = $form->format_amount(\%myconfig, $subtotalbegbalance, 2, "&nbsp;");
  948. $subtotalendbalance = $form->format_amount(\%myconfig, $subtotalendbalance, 2, "&nbsp;");
  949. $subtotaldebit = $form->format_amount(\%myconfig, $subtotaldebit, 2, "&nbsp;");
  950. $subtotalcredit = $form->format_amount(\%myconfig, $subtotalcredit, 2, "&nbsp;");
  951. $column_data{description} = "<th class=listsubtotal>$subtotaldescription</th>";
  952. $column_data{begbalance} = "<th align=right class=listsubtotal>$subtotalbegbalance</th>";
  953. $column_data{endbalance} = "<th align=right class=listsubtotal>$subtotalendbalance</th>";
  954. $column_data{debit} = "<th align=right class=listsubtotal>$subtotaldebit</th>";
  955. $column_data{credit} = "<th align=right class=listsubtotal>$subtotalcredit</th>";
  956. print qq|
  957. <tr class=listsubtotal>
  958. |;
  959. for (@column_index) { print "$column_data{$_}\n" }
  960. print qq|
  961. </tr>
  962. |;
  963. }
  964. }
  965. if ($ref->{charttype} eq "H") {
  966. $subtotal = 1;
  967. $subtotaldescription = $ref->{description};
  968. $subtotaldebit = $ref->{debit};
  969. $subtotalcredit = $ref->{credit};
  970. $subtotalbegbalance = 0;
  971. $subtotalendbalance = 0;
  972. if ($form->{l_heading}) {
  973. if (! $form->{all_accounts}) {
  974. if (($subtotaldebit + $subtotalcredit) == 0) {
  975. $subtotal = 0;
  976. next;
  977. }
  978. }
  979. } else {
  980. $subtotal = 0;
  981. if ($form->{all_accounts} || ($form->{l_subtotal} && (($subtotaldebit + $subtotalcredit) != 0))) {
  982. $subtotal = 1;
  983. }
  984. next;
  985. }
  986. for (qw(accno debit credit begbalance endbalance)) { $column_data{$_} = "<th>&nbsp;</th>" }
  987. $column_data{description} = "<th class=listheading>$ref->{description}</th>";
  988. }
  989. if ($ref->{charttype} eq "A") {
  990. $column_data{accno} = "<td><a href=$href>$ref->{accno}</a></td>";
  991. $column_data{description} = "<td>$ref->{description}</td>";
  992. $column_data{debit} = "<td align=right>$debit</td>";
  993. $column_data{credit} = "<td align=right>$credit</td>";
  994. $column_data{begbalance} = "<td align=right>$begbalance</td>";
  995. $column_data{endbalance} = "<td align=right>$endbalance</td>";
  996. $totaldebit += $ref->{debit};
  997. $totalcredit += $ref->{credit};
  998. $cml = ($ref->{contra}) ? -1 : 1;
  999. $subtotalbegbalance += $ref->{balance} * $ml * $cml;
  1000. $subtotalendbalance += ($ref->{balance} + $ref->{amount}) * $ml * $cml;
  1001. }
  1002. if ($ref->{charttype} eq "H") {
  1003. print qq|
  1004. <tr class=listheading>
  1005. |;
  1006. }
  1007. if ($ref->{charttype} eq "A") {
  1008. $i++; $i %= 2;
  1009. print qq|
  1010. <tr class=listrow$i>
  1011. |;
  1012. }
  1013. for (@column_index) { print "$column_data{$_}\n" }
  1014. print qq|
  1015. </tr>
  1016. |;
  1017. }
  1018. # print last subtotal
  1019. if ($subtotal && $form->{l_subtotal}) {
  1020. for (qw(accno begbalance endbalance)) { $column_data{$_} = "<th>&nbsp;</th>" }
  1021. $subtotalbegbalance = $form->format_amount(\%myconfig, $subtotalbegbalance, 2, "&nbsp;");
  1022. $subtotalendbalance = $form->format_amount(\%myconfig, $subtotalendbalance, 2, "&nbsp;");
  1023. $subtotaldebit = $form->format_amount(\%myconfig, $subtotaldebit, 2, "&nbsp;");
  1024. $subtotalcredit = $form->format_amount(\%myconfig, $subtotalcredit, 2, "&nbsp;");
  1025. $column_data{description} = "<th class=listsubtotal>$subtotaldescription</th>";
  1026. $column_data{begbalance} = "<th align=right class=listsubtotal>$subtotalbegbalance</th>";
  1027. $column_data{endbalance} = "<th align=right class=listsubtotal>$subtotalendbalance</th>";
  1028. $column_data{debit} = "<th align=right class=listsubtotal>$subtotaldebit</th>";
  1029. $column_data{credit} = "<th align=right class=listsubtotal>$subtotalcredit</th>";
  1030. print qq|
  1031. <tr class=listsubtotal>
  1032. |;
  1033. for (@column_index) { print "$column_data{$_}\n" }
  1034. print qq|
  1035. </tr>
  1036. |;
  1037. }
  1038. $totaldebit = $form->format_amount(\%myconfig, $totaldebit, 2, "&nbsp;");
  1039. $totalcredit = $form->format_amount(\%myconfig, $totalcredit, 2, "&nbsp;");
  1040. for (qw(accno description begbalance endbalance)) { $column_data{$_} = "<th>&nbsp;</th>" }
  1041. $column_data{debit} = qq|<th align=right class=listtotal>$totaldebit</th>|;
  1042. $column_data{credit} = qq|<th align=right class=listtotal>$totalcredit</th>|;
  1043. print qq|
  1044. <tr class=listtotal>
  1045. |;
  1046. for (@column_index) { print "$column_data{$_}\n" }
  1047. print qq|
  1048. </tr>
  1049. </table>
  1050. </td>
  1051. </tr>
  1052. <tr>
  1053. <td><hr size=3 noshade></td>
  1054. </tr>
  1055. </table>
  1056. </body>
  1057. </html>
  1058. |;
  1059. }
  1060. sub generate_ar_aging {
  1061. # split customer
  1062. ($form->{customer}) = split(/--/, $form->{customer});
  1063. $customer = $form->escape($form->{customer},1);
  1064. $title = $form->escape($form->{title},1);
  1065. $media = $form->escape($form->{media},1);
  1066. $form->{ct} = "customer";
  1067. $form->{arap} = "ar";
  1068. RP->aging(\%myconfig, \%$form);
  1069. $form->{callback} = qq|$form->{script}?path=$form->{path}&action=generate_ar_aging&login=$form->{login}&sessionid=$form->{sessionid}&todate=$form->{todate}&customer=$customer&title=$title&type=$form->{type}&format=$form->{format}&media=$media&summary=$form->{summary}|;
  1070. &aging;
  1071. }
  1072. sub generate_ap_aging {
  1073. # split vendor
  1074. ($form->{vendor}) = split(/--/, $form->{vendor});
  1075. $vendor = $form->escape($form->{vendor},1);
  1076. $title = $form->escape($form->{title},1);
  1077. $media = $form->escape($form->{media},1);
  1078. $form->{ct} = "vendor";
  1079. $form->{arap} = "ap";
  1080. RP->aging(\%myconfig, \%$form);
  1081. $form->{callback} = qq|$form->{script}?path=$form->{path}&action=generate_ap_aging&login=$form->{login}&sessionid=$form->{sessionid}&todate=$form->{todate}&vendor=$vendor&title=$title&type=$form->{type}&format=$form->{format}&media=$media&summary=$form->{summary}|;
  1082. &aging;
  1083. }
  1084. sub aging {
  1085. $form->header;
  1086. $column_header{statement} = qq|<th class=listheading width=1%>&nbsp;</th>|;
  1087. $column_header{ct} = qq|<th class=listheading width=60%>|.$locale->text(ucfirst $form->{ct}).qq|</th>|;
  1088. $column_header{language} = qq|<th class=listheading>|.$locale->text('Language').qq|</th>|;
  1089. $column_header{invnumber} = qq|<th class=listheading>|.$locale->text('Invoice').qq|</th>|;
  1090. $column_header{ordnumber} = qq|<th class=listheading>|.$locale->text('Order').qq|</th>|;
  1091. $column_header{transdate} = qq|<th class=listheading nowrap>|.$locale->text('Date').qq|</th>|;
  1092. $column_header{duedate} = qq|<th class=listheading nowrap>|.$locale->text('Due Date').qq|</th>|;
  1093. $column_header{c0} = qq|<th class=listheading width=10% nowrap>|.$locale->text('Current').qq|</th>|;
  1094. $column_header{c30} = qq|<th class=listheading width=10% nowrap>30</th>|;
  1095. $column_header{c60} = qq|<th class=listheading width=10% nowrap>60</th>|;
  1096. $column_header{c90} = qq|<th class=listheading width=10% nowrap>90</th>|;
  1097. $column_header{total} = qq|<th class=listheading width=10% nowrap>|.$locale->text('Total').qq|</th>|;
  1098. @column_index = qw(statement ct);
  1099. if (@{ $form->{all_language} } && $form->{arap} eq 'ar') {
  1100. push @column_index, "language";
  1101. $form->{selectlanguage} = qq|<option>\n|;
  1102. for (@{ $form->{all_language} }) { $form->{selectlanguage} .= qq|<option value="$_->{code}">$_->{description}\n| }
  1103. }
  1104. @c = ();
  1105. for (qw(c0 c30 c60 c90)) {
  1106. if ($form->{$_}) {
  1107. push @c, $_;
  1108. $form->{callback} .= "&$_=$form->{$_}";
  1109. }
  1110. }
  1111. if (!$form->{summary}) {
  1112. push @column_index, qw(invnumber ordnumber transdate duedate);
  1113. }
  1114. push @column_index, @c;
  1115. push @column_index, "total";
  1116. $option = $locale->text('Aged');
  1117. if ($form->{overdue}) {
  1118. $option= $locale->text('Aged Overdue');
  1119. $form->{callback} .= "&overdue=$form->{overdue}";
  1120. }
  1121. if ($form->{department}) {
  1122. $option .= "\n<br>" if $option;
  1123. ($department) = split /--/, $form->{department};
  1124. $option .= $locale->text('Department')." : $department";
  1125. $department = $form->escape($form->{department},1);
  1126. $form->{callback} .= "&department=$department";
  1127. }
  1128. if ($form->{arap} eq 'ar') {
  1129. if ($form->{customer}) {
  1130. $option .= "\n<br>" if $option;
  1131. $option .= $form->{customer};
  1132. }
  1133. }
  1134. if ($form->{arap} eq 'ap') {
  1135. shift @column_index;
  1136. if ($form->{vendor}) {
  1137. $option .= "\n<br>" if $option;
  1138. $option .= $form->{vendor};
  1139. }
  1140. }
  1141. $todate = $locale->date(\%myconfig, $form->{todate}, 1);
  1142. $option .= "\n<br>" if $option;
  1143. $option .= $locale->text('for Period')." ".$locale->text('To')." $todate";
  1144. print qq|
  1145. <body>
  1146. <form method=post action=$form->{script}>
  1147. <table width=100%>
  1148. <tr>
  1149. <th class=listtop>$form->{title}</th>
  1150. </tr>
  1151. <tr height="5"></tr>
  1152. <tr>
  1153. <td>$option</td>
  1154. </tr>
  1155. <tr>
  1156. <td>
  1157. <table width=100%>
  1158. |;
  1159. $ctid = 0;
  1160. $i = 0;
  1161. $k = 0;
  1162. $l = $#{ $form->{AG} };
  1163. foreach $ref (@{ $form->{AG} }) {
  1164. if ($curr ne $ref->{curr}) {
  1165. $ctid = 0;
  1166. for (@column_index) { $column_data{$_} = qq|<th>&nbsp;</th>| }
  1167. if ($curr) {
  1168. $c0total = $form->format_amount(\%myconfig, $c0total, 2, "&nbsp");
  1169. $c30total = $form->format_amount(\%myconfig, $c30total, 2, "&nbsp");
  1170. $c60total = $form->format_amount(\%myconfig, $c60total, 2, "&nbsp");
  1171. $c90total = $form->format_amount(\%myconfig, $c90total, 2, "&nbsp");
  1172. $total = $form->format_amount(\%myconfig, $total, 2, "&nbsp");
  1173. for (qw(ct statement language)) { $column_data{$_} = qq|<td>&nbsp;</td>| }
  1174. $column_data{c0} = qq|<th align=right>$c0total</th>|;
  1175. $column_data{c30} = qq|<th align=right>$c30total</th>|;
  1176. $column_data{c60} = qq|<th align=right>$c60total</th>|;
  1177. $column_data{c90} = qq|<th align=right>$c90total</th>|;
  1178. $column_data{total} = qq|<th align=right>$total</th>|;
  1179. print qq|
  1180. <tr class=listtotal>
  1181. |;
  1182. for (@column_index) { print "$column_data{$_}\n" }
  1183. print qq|
  1184. </tr>
  1185. |;
  1186. $c0subtotal = 0;
  1187. $c30subtotal = 0;
  1188. $c60subtotal = 0;
  1189. $c90subtotal = 0;
  1190. $subtotal = 0;
  1191. $c0total = 0;
  1192. $c30total = 0;
  1193. $c60total = 0;
  1194. $c90total = 0;
  1195. $total = 0;
  1196. }
  1197. $curr = $ref->{curr};
  1198. print qq|
  1199. <tr>
  1200. <td></td>
  1201. <th>$curr</th>
  1202. </tr>
  1203. <tr class=listheading>
  1204. |;
  1205. for (@column_index) { print "$column_header{$_}\n" }
  1206. print qq|
  1207. </tr>
  1208. |;
  1209. }
  1210. $k++;
  1211. if ($ctid != $ref->{ctid}) {
  1212. $i++;
  1213. $column_data{ct} = qq|<td>$ref->{name}</td>|;
  1214. if ($form->{selectlanguage}) {
  1215. $form->{"selectlanguage_$i"} = $form->{selectlanguage};
  1216. $form->{"selectlanguage_$i"} =~ s/(<option value="\Q$ref->{language_code}\E")/$1 selected/;
  1217. $column_data{language} = qq|<td><select name="language_code_$i">$form->{"selectlanguage_$i"}</select></td>|;
  1218. }
  1219. $column_data{statement} = qq|<td><input name="statement_$i" type=checkbox class=checkbox value=1 $ref->{checked}>
  1220. <input type=hidden name="$form->{ct}_id_$i" value=$ref->{ctid}>
  1221. <input type=hidden name="curr_$i" value=$ref->{curr}>
  1222. </td>|;
  1223. }
  1224. $ctid = $ref->{ctid};
  1225. for (qw(c0 c30 c60 c90)) { $ref->{$_} = $form->round_amount($ref->{$_} / $ref->{exchangerate}, 2) }
  1226. $c0subtotal += $ref->{c0};
  1227. $c30subtotal += $ref->{c30};
  1228. $c60subtotal += $ref->{c60};
  1229. $c90subtotal += $ref->{c90};
  1230. $c0total += $ref->{c0};
  1231. $c30total += $ref->{c30};
  1232. $c60total += $ref->{c60};
  1233. $c90total += $ref->{c90};
  1234. $ref->{total} = ($ref->{c0} + $ref->{c30} + $ref->{c60} + $ref->{c90});
  1235. $subtotal += $ref->{total};
  1236. $total += $ref->{total};
  1237. $ref->{c0} = $form->format_amount(\%myconfig, $ref->{c0}, 2, "&nbsp;");
  1238. $ref->{c30} = $form->format_amount(\%myconfig, $ref->{c30}, 2, "&nbsp;");
  1239. $ref->{c60} = $form->format_amount(\%myconfig, $ref->{c60}, 2, "&nbsp;");
  1240. $ref->{c90} = $form->format_amount(\%myconfig, $ref->{c90}, 2, "&nbsp;");
  1241. $ref->{total} = $form->format_amount(\%myconfig, $ref->{total}, 2, "&nbsp;");
  1242. $href = qq|$ref->{module}.pl?path=$form->{path}&action=edit&id=$ref->{id}&login=$form->{login}&sessionid=$form->{sessionid}&callback=|.$form->escape($form->{callback});
  1243. $column_data{invnumber} = qq|<td><a href=$href>$ref->{invnumber}</a></td>|;
  1244. for (qw(ordnumber transdate duedate)) { $column_data{$_} = qq|<td>$ref->{$_}</td>| }
  1245. for (qw(c0 c30 c60 c90 total)) { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| }
  1246. if (!$form->{summary}) {
  1247. $j++; $j %= 2;
  1248. print qq|
  1249. <tr class=listrow$j>
  1250. |;
  1251. for (@column_index) { print "$column_data{$_}\n" }
  1252. print qq|
  1253. </tr>
  1254. |;
  1255. for (qw(ct statement language)) { $column_data{$_} = qq|<td>&nbsp;</td>| }
  1256. }
  1257. # print subtotal
  1258. $nextid = ($k <= $l) ? $form->{AG}->[$k]->{ctid} : 0;
  1259. if ($ctid != $nextid) {
  1260. $c0subtotal = $form->format_amount(\%myconfig, $c0subtotal, 2, "&nbsp");
  1261. $c30subtotal = $form->format_amount(\%myconfig, $c30subtotal, 2, "&nbsp");
  1262. $c60subtotal = $form->format_amount(\%myconfig, $c60subtotal, 2, "&nbsp");
  1263. $c90subtotal = $form->format_amount(\%myconfig, $c90subtotal, 2, "&nbsp");
  1264. $subtotal = $form->format_amount(\%myconfig, $subtotal, 2, "&nbsp");
  1265. if ($form->{summary}) {
  1266. $column_data{c0} = qq|<td align=right>$c0subtotal</th>|;
  1267. $column_data{c30} = qq|<td align=right>$c30subtotal</th>|;
  1268. $column_data{c60} = qq|<td align=right>$c60subtotal</th>|;
  1269. $column_data{c90} = qq|<td align=right>$c90subtotal</th>|;
  1270. $column_data{total} = qq|<td align=right>$subtotal</th>|;
  1271. $j++; $j %= 2;
  1272. print qq|
  1273. <tr class=listrow$j>
  1274. |;
  1275. for (@column_index) { print "$column_data{$_}\n" }
  1276. print qq|
  1277. </tr>
  1278. |;
  1279. } else {
  1280. for (@column_index) { $column_data{$_} = qq|<th>&nbsp;</th>| }
  1281. $column_data{c0} = qq|<th class=listsubtotal align=right>$c0subtotal</th>|;
  1282. $column_data{c30} = qq|<th class=listsubtotal align=right>$c30subtotal</th>|;
  1283. $column_data{c60} = qq|<th class=listsubtotal align=right>$c60subtotal</th>|;
  1284. $column_data{c90} = qq|<th class=listsubtotal align=right>$c90subtotal</th>|;
  1285. $column_data{total} = qq|<th class=listsubtotal align=right>$subtotal</th>|;
  1286. # print subtotals
  1287. print qq|
  1288. <tr class=listsubtotal>
  1289. |;
  1290. for (@column_index) { print "$column_data{$_}\n" }
  1291. print qq|
  1292. </tr>
  1293. |;
  1294. }
  1295. $c0subtotal = 0;
  1296. $c30subtotal = 0;
  1297. $c60subtotal = 0;
  1298. $c90subtotal = 0;
  1299. $subtotal = 0;
  1300. }
  1301. }
  1302. print qq|
  1303. </tr>
  1304. <tr class=listtotal>
  1305. |;
  1306. for (@column_index) { $column_data{$_} = qq|<th>&nbsp;</th>| }
  1307. $c0total = $form->format_amount(\%myconfig, $c0total, 2, "&nbsp;");
  1308. $c30total = $form->format_amount(\%myconfig, $c30total, 2, "&nbsp;");
  1309. $c60total = $form->format_amount(\%myconfig, $c60total, 2, "&nbsp;");
  1310. $c90total = $form->format_amount(\%myconfig, $c90total, 2, "&nbsp;");
  1311. $total = $form->format_amount(\%myconfig, $total, 2, "&nbsp;");
  1312. $column_data{c0} = qq|<th align=right class=listtotal>$c0total</th>|;
  1313. $column_data{c30} = qq|<th align=right class=listtotal>$c30total</th>|;
  1314. $column_data{c60} = qq|<th align=right class=listtotal>$c60total</th>|;
  1315. $column_data{c90} = qq|<th align=right class=listtotal>$c90total</th>|;
  1316. $column_data{total} = qq|<th align=right class=listtotal>$total</th>|;
  1317. for (@column_index) { print "$column_data{$_}\n" }
  1318. print qq|
  1319. </tr>
  1320. <input type=hidden name=rowcount value=$i>
  1321. </table>
  1322. </td>
  1323. </tr>
  1324. <tr>
  1325. <td>
  1326. |;
  1327. &print_options if ($form->{arap} eq 'ar');
  1328. print qq|
  1329. </td>
  1330. </tr>
  1331. <tr>
  1332. <td><hr size=3 noshade></td>
  1333. </tr>
  1334. </table>
  1335. |;
  1336. if ($form->{arap} eq 'ar') {
  1337. $form->hide_form(qw(todate title summary overdue c0 c30 c60 c90 callback arap ct department path login sessionid));
  1338. print qq|
  1339. <input type=hidden name=$form->{ct} value="$form->{$form->{ct}}">
  1340. |;
  1341. # type=submit $locale->text('Select all')
  1342. # type=submit $locale->text('Print')
  1343. # type=submit $locale->text('E-mail')
  1344. %button = ('Select all' => { ndx => 1, key => 'A', value => $locale->text('Select all') },
  1345. 'Print' => { ndx => 2, key => 'P', value => $locale->text('Print') },
  1346. 'E-mail' => { ndx => 5, key => 'E', value => $locale->text('E-mail') },
  1347. );
  1348. for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
  1349. }
  1350. if ($form->{lynx}) {
  1351. require "bin/menu.pl";
  1352. &menubar;
  1353. }
  1354. print qq|
  1355. </form>
  1356. </body>
  1357. </html>
  1358. |;
  1359. }
  1360. sub select_all {
  1361. RP->aging(\%myconfig, \%$form);
  1362. for (@{ $form->{AG} }) { $_->{checked} = "checked" }
  1363. &aging;
  1364. }
  1365. sub print_options {
  1366. $form->{sendmode} = "attachment";
  1367. $form->{copies} = 1 unless $form->{copies};
  1368. $form->{PD}{$form->{type}} = "selected";
  1369. $form->{DF}{$form->{format}} = "selected";
  1370. $form->{SM}{$form->{sendmode}} = "selected";
  1371. $format = qq|
  1372. <option value=html $form->{PD}{format}>html|;
  1373. $type = qq|
  1374. <option value=statement $form->{PD}{statement}>|.$locale->text('Statement');
  1375. if ($form->{media} eq 'email') {
  1376. $media = qq|
  1377. <td><select name=sendmode>
  1378. <option value=attachment $form->{SM}{attachment}>|.$locale->text('Attachment').qq|
  1379. <option value=inline $form->{SM}{inline}>|.$locale->text('In-line');
  1380. } else {
  1381. $media = qq|
  1382. <td><select name=media>
  1383. <option value=screen>|.$locale->text('Screen');
  1384. if (%printer && $latex) {
  1385. for (sort keys %printer) { $media .= qq|
  1386. <option value="$_">$_| }
  1387. }
  1388. }
  1389. $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/;
  1390. $media .= qq|</select></td>|;
  1391. if ($latex) {
  1392. $format .= qq|
  1393. <option value=postscript $form->{DF}{postscript}>|.$locale->text('Postscript').qq|
  1394. <option value=pdf $form->{DF}{pdf}>|.$locale->text('PDF');
  1395. }
  1396. print qq|
  1397. <table>
  1398. <tr>
  1399. <td><select name=type>$type</select></td>
  1400. <td><select name=format>$format</select></td>
  1401. $media
  1402. |;
  1403. if (%printer && $latex && $form->{media} ne 'email') {
  1404. print qq|
  1405. <td>|.$locale->text('Copies').qq|
  1406. <input name=copies size=2 value=$form->{copies}></td>
  1407. |;
  1408. }
  1409. print qq|
  1410. </tr>
  1411. </table>
  1412. |;
  1413. }
  1414. sub e_mail {
  1415. # get name and email addresses
  1416. for $i (1 .. $form->{rowcount}) {
  1417. if ($form->{"statement_$i"}) {
  1418. $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
  1419. $form->{"statement_1"} = 1;
  1420. $form->{"language_code_1"} = $form->{"language_code_$i"};
  1421. $form->{"curr_1"} = $form->{"curr_$i"};
  1422. RP->get_customer(\%myconfig, \%$form);
  1423. $selected = 1;
  1424. last;
  1425. }
  1426. }
  1427. $form->error($locale->text('Nothing selected!')) unless $selected;
  1428. if ($myconfig{role} =~ /(admin|manager)/) {
  1429. $bcc = qq|
  1430. <th align=right nowrap=true>|.$locale->text('Bcc').qq|</th>
  1431. <td><input name=bcc size=30 value="$form->{bcc}"></td>
  1432. |;
  1433. }
  1434. $title = $locale->text('E-mail Statement to')." $form->{$form->{ct}}";
  1435. $form->{media} = "email";
  1436. $form->header;
  1437. print qq|
  1438. <body>
  1439. <form method=post action=$form->{script}>
  1440. <table width=100%>
  1441. <tr class=listtop>
  1442. <th>$title</th>
  1443. </tr>
  1444. <tr height="5"></tr>
  1445. <tr>
  1446. <td>
  1447. <table width=100%>
  1448. <tr>
  1449. <th align=right nowrap>|.$locale->text('E-mail').qq|</th>
  1450. <td><input name=email size=30 value="$form->{email}"></td>
  1451. <th align=right nowrap>|.$locale->text('Cc').qq|</th>
  1452. <td><input name=cc size=30 value="$form->{cc}"></td>
  1453. </tr>
  1454. <tr>
  1455. <th align=right nowrap>|.$locale->text('Subject').qq|</th>
  1456. <td><input name=subject size=30 value="$form->{subject}"></td>
  1457. $bcc
  1458. </tr>
  1459. </table>
  1460. </td>
  1461. </tr>
  1462. <tr>
  1463. <td>
  1464. <table width=100%>
  1465. <tr>
  1466. <th align=left nowrap>|.$locale->text('Message').qq|</th>
  1467. </tr>
  1468. <tr>
  1469. <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
  1470. </tr>
  1471. </table>
  1472. </td>
  1473. </tr>
  1474. <tr>
  1475. <td>
  1476. |;
  1477. &print_options;
  1478. for (qw(email cc bcc subject message type sendmode format action nextsub)) { delete $form->{$_} }
  1479. $form->hide_form;
  1480. print qq|
  1481. </td>
  1482. </tr>
  1483. <tr>
  1484. <td><hr size=3 noshade></td>
  1485. </tr>
  1486. </table>
  1487. <input type="hidden" name="nextsub" value="send_email">
  1488. <br>
  1489. <button name="action" class="submit" type="submit" value="continue">|.$locale->text('Continue').qq|</button>
  1490. </form>
  1491. </body>
  1492. </html>
  1493. |;
  1494. }
  1495. sub send_email {
  1496. $form->{OUT} = "$sendmail";
  1497. $form->{subject} = $locale->text('Statement').qq| - $form->{todate}| unless $form->{subject};
  1498. $form->isblank("email", $locale->text('E-mail address missing!'));
  1499. RP->aging(\%myconfig, \%$form);
  1500. &print_form;
  1501. $form->redirect($locale->text('Statement sent to')." $form->{$form->{ct}}");
  1502. }
  1503. sub print {
  1504. if ($form->{media} !~ /(screen|email)/) {
  1505. $form->error($locale->text('Select postscript or PDF!')) if ($form->{format} !~ /(postscript|pdf)/);
  1506. }
  1507. for $i (1 .. $form->{rowcount}) {
  1508. if ($form->{"statement_$i"}) {
  1509. $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
  1510. $language_code = $form->{"language_code_$i"};
  1511. $curr = $form->{"curr_$i"};
  1512. $selected = 1;
  1513. last;
  1514. }
  1515. }
  1516. $form->error($locale->text('Nothing selected!')) unless $selected;
  1517. if ($form->{media} !~ /(screen|email)/) {
  1518. $form->{OUT} = "| $printer{$form->{media}}";
  1519. $form->{"$form->{ct}_id"} = "";
  1520. $SIG{INT} = 'IGNORE';
  1521. } else {
  1522. $form->{"statement_1"} = 1;
  1523. $form->{"language_code_1"} = $language_code;
  1524. $form->{"curr_1"} = $curr;
  1525. }
  1526. RP->aging(\%myconfig, \%$form);
  1527. &print_form;
  1528. $form->redirect($locale->text('Statements sent to printer!')) if ($form->{media} !~ /(screen|email)/);
  1529. }
  1530. sub print_form {
  1531. $form->{statementdate} = $locale->date(\%myconfig, $form->{todate}, 1);
  1532. $form->{templates} = "$myconfig{templates}";
  1533. # setup variables for the form
  1534. @a = qw(company address businessnumber tel fax);
  1535. for (@a) { $form->{$_} = $myconfig{$_} }
  1536. $form->{address} =~ s/\\n/\n/g;
  1537. $form->format_string(@a);
  1538. $form->{IN} = "$form->{type}.html";
  1539. if ($form->{format} eq 'postscript') {
  1540. $form->{IN} =~ s/html$/tex/;
  1541. }
  1542. if ($form->{format} eq 'pdf') {
  1543. $form->{IN} =~ s/html$/tex/;
  1544. }
  1545. @a = qw(name address1 address2 city state zipcode country contact);
  1546. push @a, "$form->{ct}phone", "$form->{ct}fax", "$form->{ct}taxnumber";
  1547. push @a, 'email' if ! $form->{media} eq 'email';
  1548. $i = 0;
  1549. while (@{ $form->{AG} }) {
  1550. $ref = shift @{ $form->{AG} };
  1551. if ($ctid != $ref->{ctid}) {
  1552. $ctid = $ref->{ctid};
  1553. $i++;
  1554. if ($form->{"statement_$i"}) {
  1555. for (@a) { $form->{$_} = $ref->{$_} }
  1556. $form->format_string(@a);
  1557. $form->{$form->{ct}} = $form->{name};
  1558. $form->{"$form->{ct}_id"} = $ref->{ctid};
  1559. $form->{language_code} = $form->{"language_code_$i"};
  1560. $form->{currency} = $form->{"curr_$i"};
  1561. for (qw(invnumber ordnumber ponumber notes invdate duedate)) { $form->{$_} = () }
  1562. $form->{total} = 0;
  1563. foreach $item (qw(c0 c30 c60 c90)) {
  1564. $form->{$item} = ();
  1565. $form->{"${item}total"} = 0;
  1566. }
  1567. &statement_details($ref) if $ref->{curr} eq $form->{currency};
  1568. while ($ref) {
  1569. if (scalar (@{ $form->{AG} }) > 0) {
  1570. # one or more left to go
  1571. if ($ctid == $form->{AG}->[0]->{ctid}) {
  1572. $ref = shift @{ $form->{AG} };
  1573. &statement_details($ref) if $ref->{curr} eq $form->{currency};
  1574. # any more?
  1575. $ref = scalar (@{ $form->{AG} });
  1576. } else {
  1577. $ref = 0;
  1578. }
  1579. } else {
  1580. # set initial ref to 0
  1581. $ref = 0;
  1582. }
  1583. }
  1584. for ("c0", "c30", "c60", "c90", "") { $form->{"${_}total"} = $form->format_amount(\%myconfig, $form->{"${_}total"}, 2) }
  1585. $form->parse_template(\%myconfig, $userspath);
  1586. }
  1587. }
  1588. }
  1589. }
  1590. sub statement_details {
  1591. my ($ref) = @_;
  1592. $ref->{invdate} = $ref->{transdate};
  1593. my @a = qw(invnumber ordnumber ponumber notes invdate duedate);
  1594. for (@a) { $form->{"${_}_1"} = $ref->{$_} }
  1595. $form->format_string(qw(invnumber_1 ordnumber_1 ponumber_1 notes_1));
  1596. for (@a) { push @{ $form->{$_} }, $form->{"${_}_1"} }
  1597. foreach $item (qw(c0 c30 c60 c90)) {
  1598. eval { $ref->{$item} = $form->round_amount($ref->{$item} / $ref->{exchangerate}, 2) };
  1599. $form->{"${item}total"} += $ref->{$item};
  1600. $form->{total} += $ref->{$item};
  1601. push @{ $form->{$item} }, $form->format_amount(\%myconfig, $ref->{$item}, 2);
  1602. }
  1603. }
  1604. sub generate_tax_report {
  1605. RP->tax_report(\%myconfig, \%$form);
  1606. $descvar = "$form->{accno}_description";
  1607. $description = $form->escape($form->{$descvar});
  1608. $ratevar = "$form->{accno}_rate";
  1609. $taxrate = $form->{"$form->{accno}_rate"};
  1610. if ($form->{accno} =~ /^gifi_/) {
  1611. $descvar = "gifi_$form->{accno}_description";
  1612. $description = $form->escape($form->{$descvar});
  1613. $ratevar = "gifi_$form->{accno}_rate";
  1614. $taxrate = $form->{"gifi_$form->{accno}_rate"};
  1615. }
  1616. $department = $form->escape($form->{department});
  1617. # construct href
  1618. $href = "$form->{script}?path=$form->{path}&direction=$form->{direction}&oldsort=$form->{oldsort}&action=generate_tax_report&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&method=$form->{method}&summary=$form->{summary}&accno=$form->{accno}&$descvar=$description&department=$department&$ratevar=$taxrate&report=$form->{report}";
  1619. # construct callback
  1620. $description = $form->escape($form->{$descvar},1);
  1621. $department = $form->escape($form->{department},1);
  1622. $form->sort_order();
  1623. $callback = "$form->{script}?path=$form->{path}&direction=$form->{direction}&oldsort=$form->{oldsort}&action=generate_tax_report&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&method=$form->{method}&summary=$form->{summary}&accno=$form->{accno}&$descvar=$description&department=$department&$ratevar=$taxrate&report=$form->{report}";
  1624. $form->{title} = $locale->text('GIFI')." - " if ($form->{accno} =~ /^gifi_/);
  1625. $title = $form->escape($form->{title});
  1626. $href .= "&title=$title";
  1627. $title = $form->escape($form->{title},1);
  1628. $callback .= "&title=$title";
  1629. $form->{title} = qq|$form->{title} $form->{"$form->{accno}_description"} |;
  1630. @columns = $form->sort_columns(qw(id transdate invnumber name description netamount tax total));
  1631. $form->{"l_description"} = "" if $form->{summary};
  1632. foreach $item (@columns) {
  1633. if ($form->{"l_$item"} eq "Y") {
  1634. push @column_index, $item;
  1635. # add column to href and callback
  1636. $callback .= "&l_$item=Y";
  1637. $href .= "&l_$item=Y";
  1638. }
  1639. }
  1640. if ($form->{l_subtotal} eq 'Y') {
  1641. $callback .= "&l_subtotal=Y";
  1642. $href .= "&l_subtotal=Y";
  1643. }
  1644. if ($form->{department}) {
  1645. ($department) = split /--/, $form->{department};
  1646. $option = $locale->text('Department')." : $department";
  1647. }
  1648. # if there are any dates
  1649. if ($form->{fromdate} || $form->{todate}) {
  1650. if ($form->{fromdate}) {
  1651. $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
  1652. }
  1653. if ($form->{todate}) {
  1654. $todate = $locale->date(\%myconfig, $form->{todate}, 1);
  1655. }
  1656. $form->{period} = "$fromdate - $todate";
  1657. } else {
  1658. $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
  1659. }
  1660. if ($form->{db} eq 'ar') {
  1661. $name = $locale->text('Customer');
  1662. $invoice = 'is.pl';
  1663. $arap = 'ar.pl';
  1664. }
  1665. if ($form->{db} eq 'ap') {
  1666. $name = $locale->text('Vendor');
  1667. $invoice = 'ir.pl';
  1668. $arap = 'ap.pl';
  1669. }
  1670. $option .= "<br>" if $option;
  1671. $option .= "$form->{period}";
  1672. $column_header{id} = qq|<th><a class=listheading href=$href&sort=id>|.$locale->text('ID').qq|</th>|;
  1673. $column_header{invnumber} = qq|<th><a class=listheading href=$href&sort=invnumber>|.$locale->text('Invoice').qq|</th>|;
  1674. $column_header{transdate} = qq|<th><a class=listheading href=$href&sort=transdate>|.$locale->text('Date').qq|</th>|;
  1675. $column_header{netamount} = qq|<th class=listheading>|.$locale->text('Amount').qq|</th>|;
  1676. $column_header{tax} = qq|<th class=listheading>|.$locale->text('Tax').qq|</th>|;
  1677. $column_header{total} = qq|<th class=listheading>|.$locale->text('Total').qq|</th>|;
  1678. $column_header{name} = qq|<th><a class=listheading href=$href&sort=name>$name</th>|;
  1679. $column_header{description} = qq|<th><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</th>|;
  1680. $form->header;
  1681. print qq|
  1682. <body>
  1683. <table width=100%>
  1684. <tr>
  1685. <th class=listtop colspan=$colspan>$form->{title}</th>
  1686. </tr>
  1687. <tr height="5"></tr>
  1688. <tr>
  1689. <td>$option</td>
  1690. </tr>
  1691. <tr>
  1692. <td>
  1693. <table width=100%>
  1694. <tr class=listheading>
  1695. |;
  1696. for (@column_index) { print "$column_header{$_}\n" }
  1697. print qq|
  1698. </tr>
  1699. |;
  1700. # add sort and escape callback
  1701. $callback = $form->escape($callback . "&sort=$form->{sort}");
  1702. if (@{ $form->{TR} }) {
  1703. $sameitem = $form->{TR}->[0]->{$form->{sort}};
  1704. }
  1705. foreach $ref (@{ $form->{TR} }) {
  1706. $module = ($ref->{invoice}) ? $invoice : $arap;
  1707. $module = 'ps.pl' if $ref->{till};
  1708. if ($form->{l_subtotal} eq 'Y') {
  1709. if ($sameitem ne $ref->{$form->{sort}}) {
  1710. &tax_subtotal;
  1711. $sameitem = $ref->{$form->{sort}};
  1712. }
  1713. }
  1714. $totalnetamount += $ref->{netamount};
  1715. $totaltax += $ref->{tax};
  1716. $ref->{total} = $ref->{netamount} + $ref->{tax};
  1717. $subtotalnetamount += $ref->{netamount};
  1718. $subtotaltax += $ref->{tax};
  1719. for (qw(netamount tax total)) { $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}, 2, "&nbsp;"); }
  1720. $column_data{id} = qq|<td>$ref->{id}</td>|;
  1721. $column_data{invnumber} = qq|<td><a href=$module?path=$form->{path}&action=edit&id=$ref->{id}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{invnumber}</a></td>|;
  1722. for (qw(id transdate name partnumber description)) { $column_data{$_} = qq|<td>$ref->{$_}</td>| }
  1723. for (qw(netamount tax total)) { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| }
  1724. $i++; $i %= 2;
  1725. print qq|
  1726. <tr class=listrow$i>
  1727. |;
  1728. for (@column_index) { print "$column_data{$_}\n" }
  1729. print qq|
  1730. </tr>
  1731. |;
  1732. }
  1733. if ($form->{l_subtotal} eq 'Y') {
  1734. &tax_subtotal;
  1735. }
  1736. for (@column_index) { $column_data{$_} = qq|<th>&nbsp;</th>| }
  1737. print qq|
  1738. </tr>
  1739. <tr class=listtotal>
  1740. |;
  1741. $total = $form->format_amount(\%myconfig, $totalnetamount + $totaltax, 2, "&nbsp;");
  1742. $totalnetamount = $form->format_amount(\%myconfig, $totalnetamount, 2, "&nbsp;");
  1743. $totaltax = $form->format_amount(\%myconfig, $totaltax, 2, "&nbsp;");
  1744. $column_data{netamount} = qq|<th class=listtotal align=right>$totalnetamount</th>|;
  1745. $column_data{tax} = qq|<th class=listtotal align=right>$totaltax</th>|;
  1746. $column_data{total} = qq|<th class=listtotal align=right>$total</th>|;
  1747. for (@column_index) { print "$column_data{$_}\n" }
  1748. print qq|
  1749. </tr>
  1750. </table>
  1751. </td>
  1752. </tr>
  1753. <tr>
  1754. <td><hr size=3 noshade></td>
  1755. </tr>
  1756. </table>
  1757. </body>
  1758. </html>
  1759. |;
  1760. }
  1761. sub tax_subtotal {
  1762. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  1763. $subtotal = $form->format_amount(\%myconfig, $subtotalnetamount + $subtotaltax, 2, "&nbsp;");
  1764. $subtotalnetamount = $form->format_amount(\%myconfig, $subtotalnetamount, 2, "&nbsp;");
  1765. $subtotaltax = $form->format_amount(\%myconfig, $subtotaltax, 2, "&nbsp;");
  1766. $column_data{netamount} = "<th class=listsubtotal align=right>$subtotalnetamount</th>";
  1767. $column_data{tax} = "<th class=listsubtotal align=right>$subtotaltax</th>";
  1768. $column_data{total} = "<th class=listsubtotal align=right>$subtotal</th>";
  1769. $subtotalnetamount = 0;
  1770. $subtotaltax = 0;
  1771. print qq|
  1772. <tr class=listsubtotal>
  1773. |;
  1774. for (@column_index) { print "\n$column_data{$_}" }
  1775. print qq|
  1776. </tr>
  1777. |;
  1778. }
  1779. sub list_payments {
  1780. if ($form->{account}) {
  1781. ($form->{paymentaccounts}) = split /--/, $form->{account};
  1782. }
  1783. if ($form->{department}) {
  1784. ($department, $form->{department_id}) = split /--/, $form->{department};
  1785. $option = $locale->text('Department')." : $department";
  1786. }
  1787. RP->payments(\%myconfig, \%$form);
  1788. @columns = $form->sort_columns(qw(transdate name paid source memo));
  1789. if ($form->{till}) {
  1790. @columns = $form->sort_columns(qw(transdate name paid curr source till));
  1791. if ($myconfig{role} ne 'user') {
  1792. @columns = $form->sort_columns(qw(transdate name paid curr source till employee));
  1793. }
  1794. }
  1795. # construct href
  1796. $title = $form->escape($form->{title});
  1797. $form->{paymentaccounts} =~ s/ /%20/g;
  1798. $href = "$form->{script}?path=$form->{path}&direction=$form->{direction}&sort=$form->{sort}&oldsort=$form->{oldsort}&action=list_payments&till=$form->{till}&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&fx_transaction=$form->{fx_transaction}&db=$form->{db}&l_subtotal=$form->{l_subtotal}&prepayment=$form->{prepayment}&paymentaccounts=$form->{paymentaccounts}&title=".$form->escape($form->{title});
  1799. $form->sort_order();
  1800. $form->{callback} = "$form->{script}?path=$form->{path}&direction=$form->{direction}&sort=$form->{sort}&oldsort=$form->{oldsort}&action=list_payments&till=$form->{till}&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&fx_transaction=$form->{fx_transaction}&db=$form->{db}&l_subtotal=$form->{l_subtotal}&prepayment=$form->{prepayment}&paymentaccounts=$form->{paymentaccounts}&title=".$form->escape($form->{title},1);
  1801. if ($form->{account}) {
  1802. $callback .= "&account=".$form->escape($form->{account},1);
  1803. $href .= "&account=".$form->escape($form->{account});
  1804. $option .= "\n<br>" if ($option);
  1805. $option .= $locale->text('Account')." : $form->{account}";
  1806. }
  1807. if ($form->{department}) {
  1808. $callback .= "&department=".$form->escape($form->{department},1);
  1809. $href .= "&department=".$form->escape($form->{department});
  1810. $option .= "\n<br>" if ($option);
  1811. $option .= $locale->text('Department')." : $form->{department}";
  1812. }
  1813. if ($form->{description}) {
  1814. $callback .= "&description=".$form->escape($form->{description},1);
  1815. $href .= "&description=".$form->escape($form->{description});
  1816. $option .= "\n<br>" if ($option);
  1817. $option .= $locale->text('Description')." : $form->{description}";
  1818. }
  1819. if ($form->{source}) {
  1820. $callback .= "&source=".$form->escape($form->{source},1);
  1821. $href .= "&source=".$form->escape($form->{source});
  1822. $option .= "\n<br>" if ($option);
  1823. $option .= $locale->text('Source')." : $form->{source}";
  1824. }
  1825. if ($form->{memo}) {
  1826. $callback .= "&memo=".$form->escape($form->{memo},1);
  1827. $href .= "&memo=".$form->escape($form->{memo});
  1828. $option .= "\n<br>" if ($option);
  1829. $option .= $locale->text('Memo')." : $form->{memo}";
  1830. }
  1831. if ($form->{fromdate}) {
  1832. $option .= "\n<br>" if ($option);
  1833. $option .= $locale->text('From')."&nbsp;".$locale->date(\%myconfig, $form->{fromdate}, 1);
  1834. }
  1835. if ($form->{todate}) {
  1836. $option .= "\n<br>" if ($option);
  1837. $option .= $locale->text('To')."&nbsp;".$locale->date(\%myconfig, $form->{todate}, 1);
  1838. }
  1839. $callback = $form->escape($form->{callback});
  1840. $column_header{name} = "<th><a class=listheading href=$href&sort=name>".$locale->text('Description')."</a></th>";
  1841. $column_header{transdate} = "<th><a class=listheading href=$href&sort=transdate>".$locale->text('Date')."</a></th>";
  1842. $column_header{paid} = "<th class=listheading>".$locale->text('Amount')."</a></th>";
  1843. $column_header{curr} = "<th class=listheading>".$locale->text('Curr')."</a></th>";
  1844. $column_header{source} = "<th><a class=listheading href=$href&sort=source>".$locale->text('Source')."</a></th>";
  1845. $column_header{memo} = "<th><a class=listheading href=$href&sort=memo>".$locale->text('Memo')."</a></th>";
  1846. $column_header{employee} = "<th><a class=listheading href=$href&sort=employee>".$locale->text('Salesperson')."</a></th>";
  1847. $column_header{till} = "<th><a class=listheading href=$href&sort=till>".$locale->text('Till')."</a></th>";
  1848. @column_index = @columns;
  1849. $colspan = $#column_index + 1;
  1850. $form->header;
  1851. print qq|
  1852. <body>
  1853. <table width=100%>
  1854. <tr>
  1855. <th class=listtop>$form->{title}</th>
  1856. </tr>
  1857. <tr height="5"></tr>
  1858. <tr>
  1859. <td>$option</td>
  1860. </tr>
  1861. <tr>
  1862. <td>
  1863. <table width=100%>
  1864. <tr class=listheading>
  1865. |;
  1866. for (@column_index) { print "\n$column_header{$_}" }
  1867. print qq|
  1868. </tr>
  1869. |;
  1870. foreach $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} }) {
  1871. next unless @{ $form->{$ref->{id}} };
  1872. print qq|
  1873. <tr>
  1874. <th colspan=$colspan align=left>$ref->{accno}--$ref->{description}</th>
  1875. </tr>
  1876. |;
  1877. if (@{ $form->{$ref->{id}} }) {
  1878. $sameitem = $form->{$ref->{id}}[0]->{$form->{sort}};
  1879. }
  1880. foreach $payment (@{ $form->{$ref->{id}} }) {
  1881. if ($form->{l_subtotal}) {
  1882. if ($payment->{$form->{sort}} ne $sameitem) {
  1883. # print subtotal
  1884. &payment_subtotal;
  1885. }
  1886. }
  1887. next if ($form->{till} && ! $payment->{till});
  1888. $column_data{name} = "<td>$payment->{name}&nbsp;</td>";
  1889. $column_data{transdate} = "<td>$payment->{transdate}&nbsp;</td>";
  1890. $column_data{paid} = "<td align=right>".$form->format_amount(\%myconfig, $payment->{paid}, 2, "&nbsp;")."</td>";
  1891. $column_data{curr} = "<td>$payment->{curr}</td>";
  1892. $column_data{source} = "<td>$payment->{source}&nbsp;</td>";
  1893. $column_data{memo} = "<td>$payment->{memo}&nbsp;</td>";
  1894. $column_data{employee} = "<td>$payment->{employee}&nbsp;</td>";
  1895. $column_data{till} = "<td>$payment->{till}&nbsp;</td>";
  1896. $subtotalpaid += $payment->{paid};
  1897. $accounttotalpaid += $payment->{paid};
  1898. $totalpaid += $payment->{paid};
  1899. $i++; $i %= 2;
  1900. print qq|
  1901. <tr class=listrow$i>
  1902. |;
  1903. for (@column_index) { print "\n$column_data{$_}" }
  1904. print qq|
  1905. </tr>
  1906. |;
  1907. $sameitem = $payment->{$form->{sort}};
  1908. }
  1909. &payment_subtotal if $form->{l_subtotal};
  1910. # print account totals
  1911. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  1912. $column_data{paid} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $accounttotalpaid, 2, "&nbsp;")."</th>";
  1913. print qq|
  1914. <tr class=listtotal>
  1915. |;
  1916. for (@column_index) { print "\n$column_data{$_}" }
  1917. print qq|
  1918. </tr>
  1919. |;
  1920. $accounttotalpaid = 0;
  1921. }
  1922. # print total
  1923. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  1924. $column_data{paid} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalpaid, 2, "&nbsp;")."</th>";
  1925. print qq|
  1926. <tr class=listtotal>
  1927. |;
  1928. for (@column_index) { print "\n$column_data{$_}" }
  1929. print qq|
  1930. </tr>
  1931. </table>
  1932. </td>
  1933. </tr>
  1934. <tr>
  1935. <td><hr size=3 noshade></td>
  1936. </tr>
  1937. </table>
  1938. |;
  1939. if ($form->{lynx}) {
  1940. require "bin/menu.pl";
  1941. &menubar;
  1942. }
  1943. print qq|
  1944. </body>
  1945. </html>
  1946. |;
  1947. }
  1948. sub payment_subtotal {
  1949. if ($subtotalpaid != 0) {
  1950. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  1951. $column_data{paid} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalpaid, 2, "&nbsp;")."</th>";
  1952. print qq|
  1953. <tr class=listsubtotal>
  1954. |;
  1955. for (@column_index) { print "\n$column_data{$_}" }
  1956. print qq|
  1957. </tr>
  1958. |;
  1959. }
  1960. $subtotalpaid = 0;
  1961. }