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