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