summaryrefslogtreecommitdiff
path: root/bin/rp.pl
blob: 17854644777c6328e8261b69eb47547c7c361f5a (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. $form->header;
  759. RP->inventory_activity( \%myconfig, \%$form );
  760. $title = $form->escape( $form->{title} );
  761. # if ($form->{department}) {
  762. # ($department) = split /--/, $form->{department};
  763. # $options = $locale->text('Department')." : $department<br>";
  764. # $department = $form->escape($form->{department});
  765. # }
  766. ## if ($form->{projectnumber}) {
  767. # ($projectnumber) = split /--/, $form->{projectnumber};
  768. # $options .= $locale->text('Project Number')." : $projectnumber<br>";
  769. # $projectnumber = $form->escape($form->{projectnumber});
  770. # }
  771. # if there are any dates
  772. if ( $form->{fromdate} || $form->{todate} ) {
  773. if ( $form->{fromdate} ) {
  774. $fromdate = $locale->date( \%myconfig, $form->{fromdate}, 1 );
  775. }
  776. if ( $form->{todate} ) {
  777. $todate = $locale->date( \%myconfig, $form->{todate}, 1 );
  778. }
  779. $form->{period} = "$fromdate - $todate";
  780. }
  781. else {
  782. $form->{period} =
  783. $locale->date( \%myconfig, $form->current_date( \%myconfig ), 1 );
  784. }
  785. $options .= $form->{period};
  786. @column_index = qw(partnumber description sold revenue received expense);
  787. $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. $column_header{partnumber} = qq|
  790. <th class=listheading><a class=listheading href="$href&sort_col=partnumber">|
  791. . $locale->text('Part Number') . qq|</a></th>|;
  792. $column_header{description} = qq|
  793. <th class=listheading><a class=listheading href="$href&sort_col=description">|
  794. . $locale->text('Description') . qq|</a></th>|;
  795. $column_header{sold} = qq|
  796. <th class=listheading><a class=listheading href="$href&sort_col=sold">|
  797. . $locale->text('Sold') . qq|</a></th>|;
  798. $column_header{revenue} = qq|
  799. <th class=listheading><a class=listheading href="$href&sort_col=revenue">|
  800. . $locale->text('Revenue') . qq|</a></th>|;
  801. $column_header{received} = qq|
  802. <th class=listheading><a class=listheading href="$href&sort_col=received">|
  803. . $locale->text('Received') . qq|</a></th>|;
  804. $column_header{expense} = qq|
  805. <th class=listheading><a class=listheading href="$href&sort_col=expense">|
  806. . $locale->text('Expense') . qq|</a></th>|;
  807. print qq|
  808. <body>
  809. <table width=100%>
  810. <tr>
  811. <th class=listtop>$form->{title}</th>
  812. </tr>
  813. <tr height="5"></tr>
  814. <tr>
  815. <td>$options</td>
  816. </tr>
  817. <tr>
  818. <td>
  819. <table width=100%>
  820. <tr>|;
  821. map { print "$column_header{$_}\n" } @column_index;
  822. print qq|
  823. </tr>
  824. |;
  825. if ( $form->{sort_col} eq 'qty' || $form->{sort_col} eq 'revenue' ) {
  826. $form->{sort_type} = 'numeric';
  827. }
  828. $i = 0;
  829. $cols = "l_transdate=Y&l_name=Y&l_invnumber=Y&summary=1";
  830. $dates =
  831. "transdatefrom=$form->{fromdate}&transdateto=$form->{todate}&year=$form->{fromyear}&month=$form->{frommonth}&interval=$form->{interval}";
  832. $base =
  833. "path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  834. $form->{callback} = "rp.pl?action=continue&$base";
  835. $form->{callback} = $form->escape( $form->{callback} );
  836. $callback = "callback=$form->{callback}";
  837. # sort the whole thing by account numbers and display
  838. foreach $ref ( @{ $form->{TB} } ) {
  839. $description = $form->escape( $ref->{description} );
  840. $i = $i % 2;
  841. $pnumhref =
  842. "ic.pl?action=edit&id=$ref->{id}&$base&callback=$form->{callback}";
  843. $soldhref =
  844. "ar.pl?action=transactions&partsid=$ref->{id}&$base&$cols&$dates&$callback";
  845. $rechref =
  846. "ap.pl?action=transactions&partsid=$ref->{id}&$base&$cols&$dates&callback=$form->{callback}";
  847. $ml = ( $ref->{category} =~ /(A|E)/ ) ? -1 : 1;
  848. $debit = $form->format_amount( \%myconfig, $ref->{debit}, 2, "&nbsp;" );
  849. $credit =
  850. $form->format_amount( \%myconfig, $ref->{credit}, 2, "&nbsp;" );
  851. $begbalance =
  852. $form->format_amount( \%myconfig, $ref->{balance} * $ml, 2,
  853. "&nbsp;" );
  854. $endbalance =
  855. $form->format_amount( \%myconfig,
  856. ( $ref->{balance} + $ref->{amount} ) * $ml,
  857. 2, "&nbsp;" );
  858. $ref->{partnumber} = qq|<a href="$pnumhref">$ref->{partnumber}</a>|;
  859. $ref->{sold} = qq|<a href="$soldhref">$ref->{sold}</a>|;
  860. $ref->{received} = qq|<a href="$rechref">$ref->{received}<a/>|;
  861. map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
  862. print qq|
  863. <tr class=listrow$i>
  864. |;
  865. map { print "<td>$ref->{$_}</td>\n" } @column_index;
  866. print qq|
  867. </tr>
  868. |;
  869. ++$i;
  870. }
  871. print qq|
  872. </tr>
  873. </table>
  874. </td>
  875. </tr>
  876. <tr>
  877. <td><hr size=3 noshade></td>
  878. </tr>
  879. </table>
  880. </body>
  881. </html>
  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 generate_ap_aging {
  1257. # split vendor
  1258. ( $form->{vendor} ) = split( /--/, $form->{vendor} );
  1259. $vendor = $form->escape( $form->{vendor}, 1 );
  1260. $title = $form->escape( $form->{title}, 1 );
  1261. $media = $form->escape( $form->{media}, 1 );
  1262. $form->{ct} = "vendor";
  1263. $form->{arap} = "ap";
  1264. RP->aging( \%myconfig, \%$form );
  1265. $form->{callback} =
  1266. 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}|;
  1267. &aging;
  1268. }
  1269. sub aging {
  1270. $form->header;
  1271. $column_header{statement} = qq|<th class=listheading width=1%>&nbsp;</th>|;
  1272. $column_header{ct} =
  1273. qq|<th class=listheading width=60%>|
  1274. . $locale->text( ucfirst $form->{ct} )
  1275. . qq|</th>|;
  1276. $column_header{language} =
  1277. qq|<th class=listheading>| . $locale->text('Language') . qq|</th>|;
  1278. $column_header{invnumber} =
  1279. qq|<th class=listheading>| . $locale->text('Invoice') . qq|</th>|;
  1280. $column_header{ordnumber} =
  1281. qq|<th class=listheading>| . $locale->text('Order') . qq|</th>|;
  1282. $column_header{transdate} =
  1283. qq|<th class=listheading nowrap>| . $locale->text('Date') . qq|</th>|;
  1284. $column_header{duedate} =
  1285. qq|<th class=listheading nowrap>| . $locale->text('Due Date') . qq|</th>|;
  1286. $column_header{c0} =
  1287. qq|<th class=listheading width=10% nowrap>|
  1288. . $locale->text('Current')
  1289. . qq|</th>|;
  1290. $column_header{c30} = qq|<th class=listheading width=10% nowrap>30</th>|;
  1291. $column_header{c60} = qq|<th class=listheading width=10% nowrap>60</th>|;
  1292. $column_header{c90} = qq|<th class=listheading width=10% nowrap>90</th>|;
  1293. $column_header{total} =
  1294. qq|<th class=listheading width=10% nowrap>|
  1295. . $locale->text('Total')
  1296. . qq|</th>|;
  1297. @column_index = qw(statement ct);
  1298. if ( @{ $form->{all_language} } && $form->{arap} eq 'ar' ) {
  1299. push @column_index, "language";
  1300. $form->{selectlanguage} = qq|<option>\n|;
  1301. for ( @{ $form->{all_language} } ) {
  1302. $form->{selectlanguage} .=
  1303. qq|<option value="$_->{code}">$_->{description}\n|;
  1304. }
  1305. }
  1306. @c = ();
  1307. for (qw(c0 c30 c60 c90)) {
  1308. if ( $form->{$_} ) {
  1309. push @c, $_;
  1310. $form->{callback} .= "&$_=$form->{$_}";
  1311. }
  1312. }
  1313. if ( !$form->{summary} ) {
  1314. push @column_index, qw(invnumber ordnumber transdate duedate);
  1315. }
  1316. push @column_index, @c;
  1317. push @column_index, "total";
  1318. $option = $locale->text('Aged');
  1319. if ( $form->{overdue} ) {
  1320. $option = $locale->text('Aged Overdue');
  1321. $form->{callback} .= "&overdue=$form->{overdue}";
  1322. }
  1323. if ( $form->{department} ) {
  1324. $option .= "\n<br>" if $option;
  1325. ($department) = split /--/, $form->{department};
  1326. $option .= $locale->text('Department') . " : $department";
  1327. $department = $form->escape( $form->{department}, 1 );
  1328. $form->{callback} .= "&department=$department";
  1329. }
  1330. if ( $form->{arap} eq 'ar' ) {
  1331. if ( $form->{customer} ) {
  1332. $option .= "\n<br>" if $option;
  1333. $option .= $form->{customer};
  1334. }
  1335. }
  1336. if ( $form->{arap} eq 'ap' ) {
  1337. shift @column_index;
  1338. if ( $form->{vendor} ) {
  1339. $option .= "\n<br>" if $option;
  1340. $option .= $form->{vendor};
  1341. }
  1342. }
  1343. $todate = $locale->date( \%myconfig, $form->{todate}, 1 );
  1344. $option .= "\n<br>" if $option;
  1345. $option .=
  1346. $locale->text('for Period') . " " . $locale->text('To') . " $todate";
  1347. print qq|
  1348. <body>
  1349. <form method=post action=$form->{script}>
  1350. <table width=100%>
  1351. <tr>
  1352. <th class=listtop>$form->{title}</th>
  1353. </tr>
  1354. <tr height="5"></tr>
  1355. <tr>
  1356. <td>$option</td>
  1357. </tr>
  1358. <tr>
  1359. <td>
  1360. <table width=100%>
  1361. |;
  1362. $ctid = 0;
  1363. $i = 0;
  1364. $k = 0;
  1365. $l = $#{ $form->{AG} };
  1366. foreach $ref ( @{ $form->{AG} } ) {
  1367. if ( $curr ne $ref->{curr} ) {
  1368. $ctid = 0;
  1369. for (@column_index) { $column_data{$_} = qq|<th>&nbsp;</th>| }
  1370. if ($curr) {
  1371. $c0total =
  1372. $form->format_amount( \%myconfig, $c0total, 2, "&nbsp" );
  1373. $c30total =
  1374. $form->format_amount( \%myconfig, $c30total, 2, "&nbsp" );
  1375. $c60total =
  1376. $form->format_amount( \%myconfig, $c60total, 2, "&nbsp" );
  1377. $c90total =
  1378. $form->format_amount( \%myconfig, $c90total, 2, "&nbsp" );
  1379. $total = $form->format_amount( \%myconfig, $total, 2, "&nbsp" );
  1380. for (qw(ct statement language)) {
  1381. $column_data{$_} = qq|<td>&nbsp;</td>|;
  1382. }
  1383. $column_data{c0} = qq|<th align=right>$c0total</th>|;
  1384. $column_data{c30} = qq|<th align=right>$c30total</th>|;
  1385. $column_data{c60} = qq|<th align=right>$c60total</th>|;
  1386. $column_data{c90} = qq|<th align=right>$c90total</th>|;
  1387. $column_data{total} = qq|<th align=right>$total</th>|;
  1388. print qq|
  1389. <tr class=listtotal>
  1390. |;
  1391. for (@column_index) { print "$column_data{$_}\n" }
  1392. print qq|
  1393. </tr>
  1394. |;
  1395. $c0subtotal = 0;
  1396. $c30subtotal = 0;
  1397. $c60subtotal = 0;
  1398. $c90subtotal = 0;
  1399. $subtotal = 0;
  1400. $c0total = 0;
  1401. $c30total = 0;
  1402. $c60total = 0;
  1403. $c90total = 0;
  1404. $total = 0;
  1405. }
  1406. $curr = $ref->{curr};
  1407. print qq|
  1408. <tr>
  1409. <td></td>
  1410. <th>$curr</th>
  1411. </tr>
  1412. <tr class=listheading>
  1413. |;
  1414. for (@column_index) { print "$column_header{$_}\n" }
  1415. print qq|
  1416. </tr>
  1417. |;
  1418. }
  1419. $k++;
  1420. if ( $ctid != $ref->{ctid} ) {
  1421. $i++;
  1422. $column_data{ct} = qq|<td>$ref->{name}</td>|;
  1423. if ( $form->{selectlanguage} ) {
  1424. $form->{"selectlanguage_$i"} = $form->{selectlanguage};
  1425. $form->{"selectlanguage_$i"} =~
  1426. s/(<option value="\Q$ref->{language_code}\E")/$1 selected/;
  1427. $column_data{language} =
  1428. qq|<td><select name="language_code_$i">$form->{"selectlanguage_$i"}</select></td>|;
  1429. }
  1430. $column_data{statement} =
  1431. qq|<td><input name="statement_$i" type=checkbox class=checkbox value=1 $ref->{checked}>
  1432. <input type=hidden name="$form->{ct}_id_$i" value=$ref->{ctid}>
  1433. <input type=hidden name="curr_$i" value=$ref->{curr}>
  1434. </td>|;
  1435. }
  1436. $ctid = $ref->{ctid};
  1437. for (qw(c0 c30 c60 c90)) {
  1438. $ref->{$_} =
  1439. $form->round_amount( $ref->{$_} / $ref->{exchangerate}, 2 );
  1440. }
  1441. $c0subtotal += $ref->{c0};
  1442. $c30subtotal += $ref->{c30};
  1443. $c60subtotal += $ref->{c60};
  1444. $c90subtotal += $ref->{c90};
  1445. $c0total += $ref->{c0};
  1446. $c30total += $ref->{c30};
  1447. $c60total += $ref->{c60};
  1448. $c90total += $ref->{c90};
  1449. $ref->{total} =
  1450. ( $ref->{c0} + $ref->{c30} + $ref->{c60} + $ref->{c90} );
  1451. $subtotal += $ref->{total};
  1452. $total += $ref->{total};
  1453. $ref->{c0} =
  1454. $form->format_amount( \%myconfig, $ref->{c0}, 2, "&nbsp;" );
  1455. $ref->{c30} =
  1456. $form->format_amount( \%myconfig, $ref->{c30}, 2, "&nbsp;" );
  1457. $ref->{c60} =
  1458. $form->format_amount( \%myconfig, $ref->{c60}, 2, "&nbsp;" );
  1459. $ref->{c90} =
  1460. $form->format_amount( \%myconfig, $ref->{c90}, 2, "&nbsp;" );
  1461. $ref->{total} =
  1462. $form->format_amount( \%myconfig, $ref->{total}, 2, "&nbsp;" );
  1463. $href =
  1464. qq|$ref->{module}.pl?path=$form->{path}&action=edit&id=$ref->{id}&login=$form->{login}&sessionid=$form->{sessionid}&callback=|
  1465. . $form->escape( $form->{callback} );
  1466. $column_data{invnumber} =
  1467. qq|<td><a href=$href>$ref->{invnumber}</a></td>|;
  1468. for (qw(ordnumber transdate duedate)) {
  1469. $column_data{$_} = qq|<td>$ref->{$_}</td>|;
  1470. }
  1471. for (qw(c0 c30 c60 c90 total)) {
  1472. $column_data{$_} = qq|<td align=right>$ref->{$_}</td>|;
  1473. }
  1474. if ( !$form->{summary} ) {
  1475. $j++;
  1476. $j %= 2;
  1477. print qq|
  1478. <tr class=listrow$j>
  1479. |;
  1480. for (@column_index) { print "$column_data{$_}\n" }
  1481. print qq|
  1482. </tr>
  1483. |;
  1484. for (qw(ct statement language)) {
  1485. $column_data{$_} = qq|<td>&nbsp;</td>|;
  1486. }
  1487. }
  1488. # print subtotal
  1489. $nextid = ( $k <= $l ) ? $form->{AG}->[$k]->{ctid} : 0;
  1490. if ( $ctid != $nextid ) {
  1491. $c0subtotal =
  1492. $form->format_amount( \%myconfig, $c0subtotal, 2, "&nbsp" );
  1493. $c30subtotal =
  1494. $form->format_amount( \%myconfig, $c30subtotal, 2, "&nbsp" );
  1495. $c60subtotal =
  1496. $form->format_amount( \%myconfig, $c60subtotal, 2, "&nbsp" );
  1497. $c90subtotal =
  1498. $form->format_amount( \%myconfig, $c90subtotal, 2, "&nbsp" );
  1499. $subtotal =
  1500. $form->format_amount( \%myconfig, $subtotal, 2, "&nbsp" );
  1501. if ( $form->{summary} ) {
  1502. $column_data{c0} = qq|<td align=right>$c0subtotal</th>|;
  1503. $column_data{c30} = qq|<td align=right>$c30subtotal</th>|;
  1504. $column_data{c60} = qq|<td align=right>$c60subtotal</th>|;
  1505. $column_data{c90} = qq|<td align=right>$c90subtotal</th>|;
  1506. $column_data{total} = qq|<td align=right>$subtotal</th>|;
  1507. $j++;
  1508. $j %= 2;
  1509. print qq|
  1510. <tr class=listrow$j>
  1511. |;
  1512. for (@column_index) { print "$column_data{$_}\n" }
  1513. print qq|
  1514. </tr>
  1515. |;
  1516. }
  1517. else {
  1518. for (@column_index) { $column_data{$_} = qq|<th>&nbsp;</th>| }
  1519. $column_data{c0} =
  1520. qq|<th class=listsubtotal align=right>$c0subtotal</th>|;
  1521. $column_data{c30} =
  1522. qq|<th class=listsubtotal align=right>$c30subtotal</th>|;
  1523. $column_data{c60} =
  1524. qq|<th class=listsubtotal align=right>$c60subtotal</th>|;
  1525. $column_data{c90} =
  1526. qq|<th class=listsubtotal align=right>$c90subtotal</th>|;
  1527. $column_data{total} =
  1528. qq|<th class=listsubtotal align=right>$subtotal</th>|;
  1529. # print subtotals
  1530. print qq|
  1531. <tr class=listsubtotal>
  1532. |;
  1533. for (@column_index) { print "$column_data{$_}\n" }
  1534. print qq|
  1535. </tr>
  1536. |;
  1537. }
  1538. $c0subtotal = 0;
  1539. $c30subtotal = 0;
  1540. $c60subtotal = 0;
  1541. $c90subtotal = 0;
  1542. $subtotal = 0;
  1543. }
  1544. }
  1545. print qq|
  1546. </tr>
  1547. <tr class=listtotal>
  1548. |;
  1549. for (@column_index) { $column_data{$_} = qq|<th>&nbsp;</th>| }
  1550. $c0total = $form->format_amount( \%myconfig, $c0total, 2, "&nbsp;" );
  1551. $c30total = $form->format_amount( \%myconfig, $c30total, 2, "&nbsp;" );
  1552. $c60total = $form->format_amount( \%myconfig, $c60total, 2, "&nbsp;" );
  1553. $c90total = $form->format_amount( \%myconfig, $c90total, 2, "&nbsp;" );
  1554. $total = $form->format_amount( \%myconfig, $total, 2, "&nbsp;" );
  1555. $column_data{c0} = qq|<th align=right class=listtotal>$c0total</th>|;
  1556. $column_data{c30} = qq|<th align=right class=listtotal>$c30total</th>|;
  1557. $column_data{c60} = qq|<th align=right class=listtotal>$c60total</th>|;
  1558. $column_data{c90} = qq|<th align=right class=listtotal>$c90total</th>|;
  1559. $column_data{total} = qq|<th align=right class=listtotal>$total</th>|;
  1560. for (@column_index) { print "$column_data{$_}\n" }
  1561. print qq|
  1562. </tr>
  1563. <input type=hidden name=rowcount value=$i>
  1564. </table>
  1565. </td>
  1566. </tr>
  1567. <tr>
  1568. <td>
  1569. |;
  1570. &print_options if ( $form->{arap} eq 'ar' );
  1571. print qq|
  1572. </td>
  1573. </tr>
  1574. <tr>
  1575. <td><hr size=3 noshade></td>
  1576. </tr>
  1577. </table>
  1578. |;
  1579. if ( $form->{arap} eq 'ar' ) {
  1580. $form->hide_form(
  1581. qw(todate title summary overdue c0 c30 c60 c90 callback arap ct department path login sessionid)
  1582. );
  1583. print qq|
  1584. <input type=hidden name=$form->{ct} value="$form->{$form->{ct}}">
  1585. |;
  1586. # type=submit $locale->text('Select all')
  1587. # type=submit $locale->text('Print')
  1588. # type=submit $locale->text('E-mail')
  1589. %button = (
  1590. 'select_all' =>
  1591. { ndx => 1, key => 'A', value => $locale->text('Select all') },
  1592. 'print' =>
  1593. { ndx => 2, key => 'P', value => $locale->text('Print') },
  1594. 'e_mail' =>
  1595. { ndx => 5, key => 'E', value => $locale->text('E-mail') },
  1596. );
  1597. for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button )
  1598. {
  1599. $form->print_button( \%button, $_ );
  1600. }
  1601. }
  1602. if ( $form->{lynx} ) {
  1603. require "bin/menu.pl";
  1604. &menubar;
  1605. }
  1606. print qq|
  1607. </form>
  1608. </body>
  1609. </html>
  1610. |;
  1611. }
  1612. sub select_all {
  1613. RP->aging( \%myconfig, \%$form );
  1614. for ( @{ $form->{AG} } ) { $_->{checked} = "checked" }
  1615. &aging;
  1616. }
  1617. sub print_options {
  1618. $form->{sendmode} = "attachment";
  1619. $form->{copies} = 1 unless $form->{copies};
  1620. $form->{PD}{ $form->{type} } = "selected";
  1621. $form->{DF}{ $form->{format} } = "selected";
  1622. $form->{SM}{ $form->{sendmode} } = "selected";
  1623. $format = qq|
  1624. <option value=html $form->{PD}{format}>html|;
  1625. $type = qq|
  1626. <option value=statement $form->{PD}{statement}>|
  1627. . $locale->text('Statement');
  1628. if ( $form->{media} eq 'email' ) {
  1629. $media = qq|
  1630. <td><select name=sendmode>
  1631. <option value=attachment $form->{SM}{attachment}>|
  1632. . $locale->text('Attachment') . qq|
  1633. <option value=inline $form->{SM}{inline}>| . $locale->text('In-line');
  1634. }
  1635. else {
  1636. $media = qq|
  1637. <td><select name=media>
  1638. <option value=screen>| . $locale->text('Screen');
  1639. if ( %{LedgerSMB::Sysconfig::printer}
  1640. && ${LedgerSMB::Sysconfig::latex} )
  1641. {
  1642. for ( sort keys %{LedgerSMB::Sysconfig::printer} ) {
  1643. $media .= qq|
  1644. <option value="$_">$_|;
  1645. }
  1646. }
  1647. }
  1648. $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/;
  1649. $media .= qq|</select></td>|;
  1650. if ( ${LedgerSMB::Sysconfig::latex} ) {
  1651. $format .= qq|
  1652. <option value=ps $form->{DF}{postscript}>|
  1653. . $locale->text('Postscript') . qq|
  1654. <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF');
  1655. }
  1656. print qq|
  1657. <table>
  1658. <tr>
  1659. <td><select name=type>$type</select></td>
  1660. <td><select name=format>$format</select></td>
  1661. $media
  1662. |;
  1663. if ( %{LedgerSMB::Sysconfig::printer}
  1664. && ${LedgerSMB::Sysconfig::latex}
  1665. && $form->{media} ne 'email' )
  1666. {
  1667. print qq|
  1668. <td>| . $locale->text('Copies') . qq|
  1669. <input name=copies size=2 value=$form->{copies}></td>
  1670. |;
  1671. }
  1672. print qq|
  1673. </tr>
  1674. </table>
  1675. |;
  1676. }
  1677. sub e_mail {
  1678. # get name and email addresses
  1679. for $i ( 1 .. $form->{rowcount} ) {
  1680. if ( $form->{"statement_$i"} ) {
  1681. $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
  1682. $form->{"statement_1"} = 1;
  1683. $form->{"language_code_1"} = $form->{"language_code_$i"};
  1684. $form->{"curr_1"} = $form->{"curr_$i"};
  1685. RP->get_customer( \%myconfig, \%$form );
  1686. $selected = 1;
  1687. last;
  1688. }
  1689. }
  1690. $form->error( $locale->text('Nothing selected!') ) unless $selected;
  1691. if ( $myconfig{role} =~ /(admin|manager)/ ) {
  1692. $bcc = qq|
  1693. <th align=right nowrap=true>| . $locale->text('Bcc') . qq|</th>
  1694. <td><input name=bcc size=30 value="$form->{bcc}"></td>
  1695. |;
  1696. }
  1697. $title =
  1698. $locale->text( 'E-mail Statement to [_1]', $form->{ $form->{ct} } );
  1699. $form->{media} = "email";
  1700. $form->header;
  1701. print qq|
  1702. <body>
  1703. <form method=post action=$form->{script}>
  1704. <table width=100%>
  1705. <tr class=listtop>
  1706. <th>$title</th>
  1707. </tr>
  1708. <tr height="5"></tr>
  1709. <tr>
  1710. <td>
  1711. <table width=100%>
  1712. <tr>
  1713. <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
  1714. <td><input name=email size=30 value="$form->{email}"></td>
  1715. <th align=right nowrap>| . $locale->text('Cc') . qq|</th>
  1716. <td><input name=cc size=30 value="$form->{cc}"></td>
  1717. </tr>
  1718. <tr>
  1719. <th align=right nowrap>| . $locale->text('Subject') . qq|</th>
  1720. <td><input name=subject size=30 value="$form->{subject}"></td>
  1721. $bcc
  1722. </tr>
  1723. </table>
  1724. </td>
  1725. </tr>
  1726. <tr>
  1727. <td>
  1728. <table width=100%>
  1729. <tr>
  1730. <th align=left nowrap>| . $locale->text('Message') . qq|</th>
  1731. </tr>
  1732. <tr>
  1733. <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
  1734. </tr>
  1735. </table>
  1736. </td>
  1737. </tr>
  1738. <tr>
  1739. <td>
  1740. |;
  1741. &print_options;
  1742. for (qw(email cc bcc subject message type sendmode format action nextsub)) {
  1743. delete $form->{$_};
  1744. }
  1745. $form->hide_form;
  1746. print qq|
  1747. </td>
  1748. </tr>
  1749. <tr>
  1750. <td><hr size=3 noshade></td>
  1751. </tr>
  1752. </table>
  1753. <input type="hidden" name="nextsub" value="send_email">
  1754. <br>
  1755. <button name="action" class="submit" type="submit" value="continue">|
  1756. . $locale->text('Continue')
  1757. . qq|</button>
  1758. </form>
  1759. </body>
  1760. </html>
  1761. |;
  1762. }
  1763. sub send_email {
  1764. $form->{OUT} = "${LedgerSMB::Sysconfig::sendmail}";
  1765. $form->{printmode} = '|-';
  1766. $form->{subject} = $locale->text( 'Statement - [_1]', $form->{todate} )
  1767. unless $form->{subject};
  1768. $form->isblank( "email", $locale->text('E-mail address missing!') );
  1769. RP->aging( \%myconfig, \%$form );
  1770. &print_form;
  1771. $form->redirect(
  1772. $locale->text( 'Statement sent to [_1]', $form->{ $form->{ct} } ) );
  1773. }
  1774. sub print {
  1775. if ( $form->{media} !~ /(screen|email)/ ) {
  1776. $form->error( $locale->text('Select postscript or PDF!') )
  1777. if ( $form->{format} !~ /(postscript|pdf)/ );
  1778. }
  1779. my @batch_data = ();
  1780. for $i ( 1 .. $form->{rowcount} ) {
  1781. if ( $form->{"statement_$i"} ) {
  1782. $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
  1783. $language_code = $form->{"language_code_$i"};
  1784. $curr = $form->{"curr_$i"};
  1785. $selected = 1;
  1786. if ( $form->{media} !~ /(screen|email)/ ) {
  1787. # SC: I may not need this anymore...
  1788. # But I'll wait until lpr output is working before deciding
  1789. $form->{OUT} = "${LedgerSMB::Sysconfig::printer}{$form->{media}}";
  1790. $form->{"$form->{ct}_id"} = "";
  1791. $SIG{INT} = 'IGNORE';
  1792. }
  1793. else {
  1794. $form->{"statement_1"} = 1;
  1795. $form->{"language_code_1"} = $language_code;
  1796. $form->{"curr_1"} = $curr;
  1797. }
  1798. RP->aging( \%myconfig, \%$form );
  1799. $printhash = &print_form;
  1800. push @batch_data, $printhash;
  1801. }
  1802. }
  1803. $form->error( $locale->text('Nothing selected!') ) unless $selected;
  1804. my $template = LedgerSMB::Template->new(
  1805. user => \%myconfig,
  1806. template => $form->{'formname'} || $form->{'type'},
  1807. format => uc $form->{format}
  1808. );
  1809. try {
  1810. $template->render({data => \@batch_data});
  1811. $template->output($form);
  1812. }
  1813. catch Error::Simple with {
  1814. my $E = shift;
  1815. $form->error( $E->stacktrace );
  1816. };
  1817. $form->redirect( $locale->text('Statements sent to printer!') )
  1818. if ( $form->{media} !~ /(screen|email)/ );
  1819. }
  1820. sub print_form {
  1821. $form->{statementdate} = $locale->date( \%myconfig, $form->{todate}, 1 );
  1822. $form->{templates} = "$myconfig{templates}";
  1823. # setup variables for the form
  1824. @a = qw(company address businessnumber tel fax);
  1825. for (@a) { $form->{$_} = $myconfig{$_} }
  1826. $form->{address} =~ s/\\n/\n/g;
  1827. $form->format_string(@a);
  1828. $form->{IN} = "$form->{type}.html";
  1829. if ( $form->{format} eq 'postscript' ) {
  1830. $form->{IN} =~ s/html$/tex/;
  1831. }
  1832. if ( $form->{format} eq 'pdf' ) {
  1833. $form->{IN} =~ s/html$/tex/;
  1834. }
  1835. @a = qw(name address1 address2 city state zipcode country contact);
  1836. push @a, "$form->{ct}phone", "$form->{ct}fax", "$form->{ct}taxnumber";
  1837. push @a, 'email' if !$form->{media} eq 'email';
  1838. $i = 0;
  1839. while ( @{ $form->{AG} } ) {
  1840. $ref = shift @{ $form->{AG} };
  1841. if ( $ctid != $ref->{ctid} ) {
  1842. $ctid = $ref->{ctid};
  1843. $i++;
  1844. if ( $form->{"statement_$i"} ) {
  1845. for (@a) { $form->{$_} = $ref->{$_} }
  1846. $form->format_string(@a);
  1847. $form->{ $form->{ct} } = $form->{name};
  1848. $form->{"$form->{ct}_id"} = $ref->{ctid};
  1849. $form->{language_code} = $form->{"language_code_$i"};
  1850. $form->{currency} = $form->{"curr_$i"};
  1851. for (qw(invnumber ordnumber ponumber notes invdate duedate)) {
  1852. $form->{$_} = ();
  1853. }
  1854. $form->{total} = 0;
  1855. foreach $item (qw(c0 c30 c60 c90)) {
  1856. $form->{$item} = ();
  1857. $form->{"${item}total"} = 0;
  1858. }
  1859. &statement_details($ref) if $ref->{curr} eq $form->{currency};
  1860. while ($ref) {
  1861. if ( scalar( @{ $form->{AG} } ) > 0 ) {
  1862. # one or more left to go
  1863. if ( $ctid == $form->{AG}->[0]->{ctid} ) {
  1864. $ref = shift @{ $form->{AG} };
  1865. &statement_details($ref)
  1866. if $ref->{curr} eq $form->{currency};
  1867. # any more?
  1868. $ref = scalar( @{ $form->{AG} } );
  1869. }
  1870. else {
  1871. $ref = 0;
  1872. }
  1873. }
  1874. else {
  1875. # set initial ref to 0
  1876. $ref = 0;
  1877. }
  1878. }
  1879. for ( "c0", "c30", "c60", "c90", "" ) {
  1880. $form->{"${_}total"} =
  1881. $form->format_amount( \%myconfig, $form->{"${_}total"},
  1882. 2 );
  1883. }
  1884. my $printhash = {};
  1885. for (keys %$form) { $printhash->{$_} = $form->{$_}}
  1886. return $printhash;
  1887. }
  1888. }
  1889. }
  1890. }
  1891. sub statement_details {
  1892. my ($ref) = @_;
  1893. $ref->{invdate} = $ref->{transdate};
  1894. my @a = qw(invnumber ordnumber ponumber notes invdate duedate);
  1895. for (@a) { $form->{"${_}_1"} = $ref->{$_} }
  1896. $form->format_string(qw(invnumber_1 ordnumber_1 ponumber_1 notes_1));
  1897. for (@a) { push @{ $form->{$_} }, $form->{"${_}_1"} }
  1898. foreach $item (qw(c0 c30 c60 c90)) {
  1899. eval {
  1900. $ref->{$item} =
  1901. $form->round_amount( $ref->{$item} / $ref->{exchangerate}, 2 );
  1902. };
  1903. $form->{"${item}total"} += $ref->{$item};
  1904. $form->{total} += $ref->{$item};
  1905. push @{ $form->{$item} },
  1906. $form->format_amount( \%myconfig, $ref->{$item}, 2 );
  1907. }
  1908. }
  1909. sub generate_tax_report {
  1910. RP->tax_report( \%myconfig, \%$form );
  1911. $descvar = "$form->{accno}_description";
  1912. $description = $form->escape( $form->{$descvar} );
  1913. $ratevar = "$form->{accno}_rate";
  1914. $taxrate = $form->{"$form->{accno}_rate"};
  1915. if ( $form->{accno} =~ /^gifi_/ ) {
  1916. $descvar = "gifi_$form->{accno}_description";
  1917. $description = $form->escape( $form->{$descvar} );
  1918. $ratevar = "gifi_$form->{accno}_rate";
  1919. $taxrate = $form->{"gifi_$form->{accno}_rate"};
  1920. }
  1921. $department = $form->escape( $form->{department} );
  1922. # construct href
  1923. $href =
  1924. "$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}";
  1925. # construct callback
  1926. $description = $form->escape( $form->{$descvar}, 1 );
  1927. $department = $form->escape( $form->{department}, 1 );
  1928. $form->sort_order();
  1929. $callback =
  1930. "$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}";
  1931. $form->{title} = $locale->text('GIFI') . " - "
  1932. if ( $form->{accno} =~ /^gifi_/ );
  1933. $title = $form->escape( $form->{title} );
  1934. $href .= "&title=$title";
  1935. $title = $form->escape( $form->{title}, 1 );
  1936. $callback .= "&title=$title";
  1937. $form->{title} = qq|$form->{title} $form->{"$form->{accno}_description"} |;
  1938. @columns =
  1939. $form->sort_columns(
  1940. qw(id transdate invnumber name description netamount tax total));
  1941. $form->{"l_description"} = "" if $form->{summary};
  1942. foreach $item (@columns) {
  1943. if ( $form->{"l_$item"} eq "Y" ) {
  1944. push @column_index, $item;
  1945. # add column to href and callback
  1946. $callback .= "&l_$item=Y";
  1947. $href .= "&l_$item=Y";
  1948. }
  1949. }
  1950. if ( $form->{l_subtotal} eq 'Y' ) {
  1951. $callback .= "&l_subtotal=Y";
  1952. $href .= "&l_subtotal=Y";
  1953. }
  1954. if ( $form->{department} ) {
  1955. ($department) = split /--/, $form->{department};
  1956. $option = $locale->text('Department') . " : $department";
  1957. }
  1958. # if there are any dates
  1959. if ( $form->{fromdate} || $form->{todate} ) {
  1960. if ( $form->{fromdate} ) {
  1961. $fromdate = $locale->date( \%myconfig, $form->{fromdate}, 1 );
  1962. }
  1963. if ( $form->{todate} ) {
  1964. $todate = $locale->date( \%myconfig, $form->{todate}, 1 );
  1965. }
  1966. $form->{period} = "$fromdate - $todate";
  1967. }
  1968. else {
  1969. $form->{period} =
  1970. $locale->date( \%myconfig, $form->current_date( \%myconfig ), 1 );
  1971. }
  1972. if ( $form->{db} eq 'ar' ) {
  1973. $name = $locale->text('Customer');
  1974. $invoice = 'is.pl';
  1975. $arap = 'ar.pl';
  1976. }
  1977. if ( $form->{db} eq 'ap' ) {
  1978. $name = $locale->text('Vendor');
  1979. $invoice = 'ir.pl';
  1980. $arap = 'ap.pl';
  1981. }
  1982. $option .= "<br>" if $option;
  1983. $option .= "$form->{period}";
  1984. $column_header{id} =
  1985. qq|<th><a class=listheading href=$href&sort=id>|
  1986. . $locale->text('ID')
  1987. . qq|</th>|;
  1988. $column_header{invnumber} =
  1989. qq|<th><a class=listheading href=$href&sort=invnumber>|
  1990. . $locale->text('Invoice')
  1991. . qq|</th>|;
  1992. $column_header{transdate} =
  1993. qq|<th><a class=listheading href=$href&sort=transdate>|
  1994. . $locale->text('Date')
  1995. . qq|</th>|;
  1996. $column_header{netamount} =
  1997. qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
  1998. $column_header{tax} =
  1999. qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
  2000. $column_header{total} =
  2001. qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
  2002. $column_header{name} =
  2003. qq|<th><a class=listheading href=$href&sort=name>$name</th>|;
  2004. $column_header{description} =
  2005. qq|<th><a class=listheading href=$href&sort=description>|
  2006. . $locale->text('Description')
  2007. . qq|</th>|;
  2008. $form->header;
  2009. print qq|
  2010. <body>
  2011. <table width=100%>
  2012. <tr>
  2013. <th class=listtop colspan=$colspan>$form->{title}</th>
  2014. </tr>
  2015. <tr height="5"></tr>
  2016. <tr>
  2017. <td>$option</td>
  2018. </tr>
  2019. <tr>
  2020. <td>
  2021. <table width=100%>
  2022. <tr class=listheading>
  2023. |;
  2024. for (@column_index) { print "$column_header{$_}\n" }
  2025. print qq|
  2026. </tr>
  2027. |;
  2028. # add sort and escape callback
  2029. $callback = $form->escape( $callback . "&sort=$form->{sort}" );
  2030. if ( @{ $form->{TR} } ) {
  2031. $sameitem = $form->{TR}->[0]->{ $form->{sort} };
  2032. }
  2033. foreach $ref ( @{ $form->{TR} } ) {
  2034. $module = ( $ref->{invoice} ) ? $invoice : $arap;
  2035. $module = 'ps.pl' if $ref->{till};
  2036. if ( $form->{l_subtotal} eq 'Y' ) {
  2037. if ( $sameitem ne $ref->{ $form->{sort} } ) {
  2038. &tax_subtotal;
  2039. $sameitem = $ref->{ $form->{sort} };
  2040. }
  2041. }
  2042. $totalnetamount += $ref->{netamount};
  2043. $totaltax += $ref->{tax};
  2044. $ref->{total} = $ref->{netamount} + $ref->{tax};
  2045. $subtotalnetamount += $ref->{netamount};
  2046. $subtotaltax += $ref->{tax};
  2047. for (qw(netamount tax total)) {
  2048. $ref->{$_} =
  2049. $form->format_amount( \%myconfig, $ref->{$_}, 2, "&nbsp;" );
  2050. }
  2051. $column_data{id} = qq|<td>$ref->{id}</td>|;
  2052. $column_data{invnumber} =
  2053. 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>|;
  2054. for (qw(id transdate name partnumber description)) {
  2055. $column_data{$_} = qq|<td>$ref->{$_}</td>|;
  2056. }
  2057. for (qw(netamount tax total)) {
  2058. $column_data{$_} = qq|<td align=right>$ref->{$_}</td>|;
  2059. }
  2060. $i++;
  2061. $i %= 2;
  2062. print qq|
  2063. <tr class=listrow$i>
  2064. |;
  2065. for (@column_index) { print "$column_data{$_}\n" }
  2066. print qq|
  2067. </tr>
  2068. |;
  2069. }
  2070. if ( $form->{l_subtotal} eq 'Y' ) {
  2071. &tax_subtotal;
  2072. }
  2073. for (@column_index) { $column_data{$_} = qq|<th>&nbsp;</th>| }
  2074. print qq|
  2075. </tr>
  2076. <tr class=listtotal>
  2077. |;
  2078. $total = $form->format_amount( \%myconfig, $totalnetamount + $totaltax,
  2079. 2, "&nbsp;" );
  2080. $totalnetamount =
  2081. $form->format_amount( \%myconfig, $totalnetamount, 2, "&nbsp;" );
  2082. $totaltax = $form->format_amount( \%myconfig, $totaltax, 2, "&nbsp;" );
  2083. $column_data{netamount} =
  2084. qq|<th class=listtotal align=right>$totalnetamount</th>|;
  2085. $column_data{tax} = qq|<th class=listtotal align=right>$totaltax</th>|;
  2086. $column_data{total} = qq|<th class=listtotal align=right>$total</th>|;
  2087. for (@column_index) { print "$column_data{$_}\n" }
  2088. print qq|
  2089. </tr>
  2090. </table>
  2091. </td>
  2092. </tr>
  2093. <tr>
  2094. <td><hr size=3 noshade></td>
  2095. </tr>
  2096. </table>
  2097. </body>
  2098. </html>
  2099. |;
  2100. }
  2101. sub tax_subtotal {
  2102. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  2103. $subtotal =
  2104. $form->format_amount( \%myconfig, $subtotalnetamount + $subtotaltax,
  2105. 2, "&nbsp;" );
  2106. $subtotalnetamount =
  2107. $form->format_amount( \%myconfig, $subtotalnetamount, 2, "&nbsp;" );
  2108. $subtotaltax =
  2109. $form->format_amount( \%myconfig, $subtotaltax, 2, "&nbsp;" );
  2110. $column_data{netamount} =
  2111. "<th class=listsubtotal align=right>$subtotalnetamount</th>";
  2112. $column_data{tax} = "<th class=listsubtotal align=right>$subtotaltax</th>";
  2113. $column_data{total} = "<th class=listsubtotal align=right>$subtotal</th>";
  2114. $subtotalnetamount = 0;
  2115. $subtotaltax = 0;
  2116. print qq|
  2117. <tr class=listsubtotal>
  2118. |;
  2119. for (@column_index) { print "\n$column_data{$_}" }
  2120. print qq|
  2121. </tr>
  2122. |;
  2123. }
  2124. sub list_payments {
  2125. if ( $form->{account} ) {
  2126. ( $form->{paymentaccounts} ) = split /--/, $form->{account};
  2127. }
  2128. if ( $form->{department} ) {
  2129. ( $department, $form->{department_id} ) = split /--/,
  2130. $form->{department};
  2131. $option = $locale->text('Department') . " : $department";
  2132. }
  2133. RP->payments( \%myconfig, \%$form );
  2134. @columns = $form->sort_columns(qw(transdate name paid source memo));
  2135. if ( $form->{till} ) {
  2136. @columns =
  2137. $form->sort_columns(qw(transdate name paid curr source till));
  2138. if ( $myconfig{role} ne 'user' ) {
  2139. @columns =
  2140. $form->sort_columns(
  2141. qw(transdate name paid curr source till employee));
  2142. }
  2143. }
  2144. # construct href
  2145. $title = $form->escape( $form->{title} );
  2146. $form->{paymentaccounts} =~ s/ /%20/g;
  2147. $href =
  2148. "$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="
  2149. . $form->escape( $form->{title} );
  2150. $form->sort_order();
  2151. $form->{callback} =
  2152. "$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="
  2153. . $form->escape( $form->{title}, 1 );
  2154. if ( $form->{account} ) {
  2155. $callback .= "&account=" . $form->escape( $form->{account}, 1 );
  2156. $href .= "&account=" . $form->escape( $form->{account} );
  2157. $option .= "\n<br>" if ($option);
  2158. $option .= $locale->text('Account') . " : $form->{account}";
  2159. }
  2160. if ( $form->{department} ) {
  2161. $callback .= "&department=" . $form->escape( $form->{department}, 1 );
  2162. $href .= "&department=" . $form->escape( $form->{department} );
  2163. $option .= "\n<br>" if ($option);
  2164. $option .= $locale->text('Department') . " : $form->{department}";
  2165. }
  2166. if ( $form->{description} ) {
  2167. $callback .= "&description=" . $form->escape( $form->{description}, 1 );
  2168. $href .= "&description=" . $form->escape( $form->{description} );
  2169. $option .= "\n<br>" if ($option);
  2170. $option .= $locale->text('Description') . " : $form->{description}";
  2171. }
  2172. if ( $form->{source} ) {
  2173. $callback .= "&source=" . $form->escape( $form->{source}, 1 );
  2174. $href .= "&source=" . $form->escape( $form->{source} );
  2175. $option .= "\n<br>" if ($option);
  2176. $option .= $locale->text('Source') . " : $form->{source}";
  2177. }
  2178. if ( $form->{memo} ) {
  2179. $callback .= "&memo=" . $form->escape( $form->{memo}, 1 );
  2180. $href .= "&memo=" . $form->escape( $form->{memo} );
  2181. $option .= "\n<br>" if ($option);
  2182. $option .= $locale->text('Memo') . " : $form->{memo}";
  2183. }
  2184. if ( $form->{fromdate} ) {
  2185. $option .= "\n<br>" if ($option);
  2186. $option .=
  2187. $locale->text('From') . "&nbsp;"
  2188. . $locale->date( \%myconfig, $form->{fromdate}, 1 );
  2189. }
  2190. if ( $form->{todate} ) {
  2191. $option .= "\n<br>" if ($option);
  2192. $option .=
  2193. $locale->text('To') . "&nbsp;"
  2194. . $locale->date( \%myconfig, $form->{todate}, 1 );
  2195. }
  2196. $callback = $form->escape( $form->{callback} );
  2197. $column_header{name} =
  2198. "<th><a class=listheading href=$href&sort=name>"
  2199. . $locale->text('Description')
  2200. . "</a></th>";
  2201. $column_header{transdate} =
  2202. "<th><a class=listheading href=$href&sort=transdate>"
  2203. . $locale->text('Date')
  2204. . "</a></th>";
  2205. $column_header{paid} =
  2206. "<th class=listheading>" . $locale->text('Amount') . "</a></th>";
  2207. $column_header{curr} =
  2208. "<th class=listheading>" . $locale->text('Curr') . "</a></th>";
  2209. $column_header{source} =
  2210. "<th><a class=listheading href=$href&sort=source>"
  2211. . $locale->text('Source')
  2212. . "</a></th>";
  2213. $column_header{memo} =
  2214. "<th><a class=listheading href=$href&sort=memo>"
  2215. . $locale->text('Memo')
  2216. . "</a></th>";
  2217. $column_header{employee} =
  2218. "<th><a class=listheading href=$href&sort=employee>"
  2219. . $locale->text('Salesperson')
  2220. . "</a></th>";
  2221. $column_header{till} =
  2222. "<th><a class=listheading href=$href&sort=till>"
  2223. . $locale->text('Till')
  2224. . "</a></th>";
  2225. @column_index = @columns;
  2226. $colspan = $#column_index + 1;
  2227. $form->header;
  2228. print qq|
  2229. <body>
  2230. <table width=100%>
  2231. <tr>
  2232. <th class=listtop>$form->{title}</th>
  2233. </tr>
  2234. <tr height="5"></tr>
  2235. <tr>
  2236. <td>$option</td>
  2237. </tr>
  2238. <tr>
  2239. <td>
  2240. <table width=100%>
  2241. <tr class=listheading>
  2242. |;
  2243. for (@column_index) { print "\n$column_header{$_}" }
  2244. print qq|
  2245. </tr>
  2246. |;
  2247. foreach $ref ( sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} } ) {
  2248. next unless @{ $form->{ $ref->{id} } };
  2249. print qq|
  2250. <tr>
  2251. <th colspan=$colspan align=left>$ref->{accno}--$ref->{description}</th>
  2252. </tr>
  2253. |;
  2254. if ( @{ $form->{ $ref->{id} } } ) {
  2255. $sameitem = $form->{ $ref->{id} }[0]->{ $form->{sort} };
  2256. }
  2257. foreach $payment ( @{ $form->{ $ref->{id} } } ) {
  2258. if ( $form->{l_subtotal} ) {
  2259. if ( $payment->{ $form->{sort} } ne $sameitem ) {
  2260. # print subtotal
  2261. &payment_subtotal;
  2262. }
  2263. }
  2264. next if ( $form->{till} && !$payment->{till} );
  2265. $column_data{name} = "<td>$payment->{name}&nbsp;</td>";
  2266. $column_data{transdate} = "<td>$payment->{transdate}&nbsp;</td>";
  2267. $column_data{paid} =
  2268. "<td align=right>"
  2269. . $form->format_amount( \%myconfig, $payment->{paid}, 2,
  2270. "&nbsp;" )
  2271. . "</td>";
  2272. $column_data{curr} = "<td>$payment->{curr}</td>";
  2273. $column_data{source} = "<td>$payment->{source}&nbsp;</td>";
  2274. $column_data{memo} = "<td>$payment->{memo}&nbsp;</td>";
  2275. $column_data{employee} = "<td>$payment->{employee}&nbsp;</td>";
  2276. $column_data{till} = "<td>$payment->{till}&nbsp;</td>";
  2277. $subtotalpaid += $payment->{paid};
  2278. $accounttotalpaid += $payment->{paid};
  2279. $totalpaid += $payment->{paid};
  2280. $i++;
  2281. $i %= 2;
  2282. print qq|
  2283. <tr class=listrow$i>
  2284. |;
  2285. for (@column_index) { print "\n$column_data{$_}" }
  2286. print qq|
  2287. </tr>
  2288. |;
  2289. $sameitem = $payment->{ $form->{sort} };
  2290. }
  2291. &payment_subtotal if $form->{l_subtotal};
  2292. # print account totals
  2293. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  2294. $column_data{paid} =
  2295. "<th class=listtotal align=right>"
  2296. . $form->format_amount( \%myconfig, $accounttotalpaid, 2, "&nbsp;" )
  2297. . "</th>";
  2298. print qq|
  2299. <tr class=listtotal>
  2300. |;
  2301. for (@column_index) { print "\n$column_data{$_}" }
  2302. print qq|
  2303. </tr>
  2304. |;
  2305. $accounttotalpaid = 0;
  2306. }
  2307. # print total
  2308. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  2309. $column_data{paid} =
  2310. "<th class=listtotal align=right>"
  2311. . $form->format_amount( \%myconfig, $totalpaid, 2, "&nbsp;" ) . "</th>";
  2312. print qq|
  2313. <tr class=listtotal>
  2314. |;
  2315. for (@column_index) { print "\n$column_data{$_}" }
  2316. print qq|
  2317. </tr>
  2318. </table>
  2319. </td>
  2320. </tr>
  2321. <tr>
  2322. <td><hr size=3 noshade></td>
  2323. </tr>
  2324. </table>
  2325. |;
  2326. if ( $form->{lynx} ) {
  2327. require "bin/menu.pl";
  2328. &menubar;
  2329. }
  2330. print qq|
  2331. </body>
  2332. </html>
  2333. |;
  2334. }
  2335. sub payment_subtotal {
  2336. if ( $subtotalpaid != 0 ) {
  2337. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  2338. $column_data{paid} =
  2339. "<th class=listsubtotal align=right>"
  2340. . $form->format_amount( \%myconfig, $subtotalpaid, 2, "&nbsp;" )
  2341. . "</th>";
  2342. print qq|
  2343. <tr class=listsubtotal>
  2344. |;
  2345. for (@column_index) { print "\n$column_data{$_}" }
  2346. print qq|
  2347. </tr>
  2348. |;
  2349. }
  2350. $subtotalpaid = 0;
  2351. }