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