summaryrefslogtreecommitdiff
path: root/bin/rp.pl
blob: a5c906d3ca64c7b28b2d4537974b23400fe877cb (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 name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
  215. <th align=right>| . $locale->text('To') . qq|</th>
  216. <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
  217. </tr>
  218. $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 name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
  242. <th align=right>| . $locale->text('To') . qq|</th>
  243. <td><input 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 name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
  276. <th align=right>| . $locale->text('To') . qq|</th>
  277. <td><input 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 name=comparefromdate size=11 title="$myconfig{dateformat}"></td>
  306. <th align=right>| . $locale->text('To') . qq|</th>
  307. <td><input 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 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 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 name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
  418. <th align=right>| . $locale->text('To') . qq|</th>
  419. <td><input 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 name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
  449. <th align=right>| . $locale->text('To') . qq|</th>
  450. <td><input 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 name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
  557. <th align=right>| . $locale->text('To') . qq|</th>
  558. <td><input 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 = "postscript" 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 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 name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
  710. <th align=right>| . $locale->text('To') . qq|</th>
  711. <td><input 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. print qq|
  729. $gifi
  730. </table>
  731. </td>
  732. </tr>
  733. <tr>
  734. <td><hr size=3 noshade></td>
  735. </tr>
  736. </table>
  737. <br>
  738. <input type="hidden" name="path" value="$form->{path}">
  739. <input type="hidden" name="login" value="$form->{login}">
  740. <input type="hidden" name="sessionid" value="$form->{sessionid}">
  741. <button type="submit" class="submit" name="action" value="continue">|
  742. . $locale->text('Continue')
  743. . qq|</button>
  744. </form>
  745. |;
  746. if ( $form->{lynx} ) {
  747. require "bin/menu.pl";
  748. &menubar;
  749. }
  750. print qq|
  751. </body>
  752. </html>
  753. |;
  754. }
  755. sub continue { &{ $form->{nextsub} } }
  756. sub generate_inv_activity {
  757. $form->header;
  758. RP->inventory_activity( \%myconfig, \%$form );
  759. $title = $form->escape( $form->{title} );
  760. # if ($form->{department}) {
  761. # ($department) = split /--/, $form->{department};
  762. # $options = $locale->text('Department')." : $department<br>";
  763. # $department = $form->escape($form->{department});
  764. # }
  765. ## if ($form->{projectnumber}) {
  766. # ($projectnumber) = split /--/, $form->{projectnumber};
  767. # $options .= $locale->text('Project Number')." : $projectnumber<br>";
  768. # $projectnumber = $form->escape($form->{projectnumber});
  769. # }
  770. # if there are any dates
  771. if ( $form->{fromdate} || $form->{todate} ) {
  772. if ( $form->{fromdate} ) {
  773. $fromdate = $locale->date( \%myconfig, $form->{fromdate}, 1 );
  774. }
  775. if ( $form->{todate} ) {
  776. $todate = $locale->date( \%myconfig, $form->{todate}, 1 );
  777. }
  778. $form->{period} = "$fromdate - $todate";
  779. }
  780. else {
  781. $form->{period} =
  782. $locale->date( \%myconfig, $form->current_date( \%myconfig ), 1 );
  783. }
  784. $options .= $form->{period};
  785. @column_index = qw(partnumber description sold revenue received expense);
  786. $href =
  787. 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}|;
  788. $column_header{partnumber} = qq|
  789. <th class=listheading><a class=listheading href="$href&sort_col=partnumber">|
  790. . $locale->text('Part Number') . qq|</a></th>|;
  791. $column_header{description} = qq|
  792. <th class=listheading><a class=listheading href="$href&sort_col=description">|
  793. . $locale->text('Description') . qq|</a></th>|;
  794. $column_header{sold} = qq|
  795. <th class=listheading><a class=listheading href="$href&sort_col=sold">|
  796. . $locale->text('Sold') . qq|</a></th>|;
  797. $column_header{revenue} = qq|
  798. <th class=listheading><a class=listheading href="$href&sort_col=revenue">|
  799. . $locale->text('Revenue') . qq|</a></th>|;
  800. $column_header{received} = qq|
  801. <th class=listheading><a class=listheading href="$href&sort_col=received">|
  802. . $locale->text('Received') . qq|</a></th>|;
  803. $column_header{expense} = qq|
  804. <th class=listheading><a class=listheading href="$href&sort_col=expense">|
  805. . $locale->text('Expense') . qq|</a></th>|;
  806. print qq|
  807. <body>
  808. <table width=100%>
  809. <tr>
  810. <th class=listtop>$form->{title}</th>
  811. </tr>
  812. <tr height="5"></tr>
  813. <tr>
  814. <td>$options</td>
  815. </tr>
  816. <tr>
  817. <td>
  818. <table width=100%>
  819. <tr>|;
  820. map { print "$column_header{$_}\n" } @column_index;
  821. print qq|
  822. </tr>
  823. |;
  824. if ( $form->{sort_col} eq 'qty' || $form->{sort_col} eq 'revenue' ) {
  825. $form->{sort_type} = 'numeric';
  826. }
  827. $i = 0;
  828. $cols = "l_transdate=Y&l_name=Y&l_invnumber=Y&summary=1";
  829. $dates =
  830. "transdatefrom=$form->{fromdate}&transdateto=$form->{todate}&year=$form->{fromyear}&month=$form->{frommonth}&interval=$form->{interval}";
  831. $base =
  832. "path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  833. $form->{callback} = "rp.pl?action=continue&$base";
  834. $form->{callback} = $form->escape( $form->{callback} );
  835. $callback = "callback=$form->{callback}";
  836. # sort the whole thing by account numbers and display
  837. foreach $ref ( @{ $form->{TB} } ) {
  838. $description = $form->escape( $ref->{description} );
  839. $i = $i % 2;
  840. $pnumhref =
  841. "ic.pl?action=edit&id=$ref->{id}&$base&callback=$form->{callback}";
  842. $soldhref =
  843. "ar.pl?action=transactions&partsid=$ref->{id}&$base&$cols&$dates&$callback";
  844. $rechref =
  845. "ap.pl?action=transactions&partsid=$ref->{id}&$base&$cols&$dates&callback=$form->{callback}";
  846. $ml = ( $ref->{category} =~ /(A|E)/ ) ? -1 : 1;
  847. $debit = $form->format_amount( \%myconfig, $ref->{debit}, 2, "&nbsp;" );
  848. $credit =
  849. $form->format_amount( \%myconfig, $ref->{credit}, 2, "&nbsp;" );
  850. $begbalance =
  851. $form->format_amount( \%myconfig, $ref->{balance} * $ml, 2,
  852. "&nbsp;" );
  853. $endbalance =
  854. $form->format_amount( \%myconfig,
  855. ( $ref->{balance} + $ref->{amount} ) * $ml,
  856. 2, "&nbsp;" );
  857. $ref->{partnumber} = qq|<a href="$pnumhref">$ref->{partnumber}</a>|;
  858. $ref->{sold} = qq|<a href="$soldhref">$ref->{sold}</a>|;
  859. $ref->{received} = qq|<a href="$rechref">$ref->{received}<a/>|;
  860. map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
  861. print qq|
  862. <tr class=listrow$i>
  863. |;
  864. map { print "<td>$ref->{$_}</td>\n" } @column_index;
  865. print qq|
  866. </tr>
  867. |;
  868. ++$i;
  869. }
  870. print qq|
  871. </tr>
  872. </table>
  873. </td>
  874. </tr>
  875. <tr>
  876. <td><hr size=3 noshade></td>
  877. </tr>
  878. </table>
  879. </body>
  880. </html>
  881. |;
  882. }
  883. sub generate_income_statement {
  884. $form->{padding} = "&nbsp;&nbsp;";
  885. $form->{bold} = "<b>";
  886. $form->{endbold} = "</b>";
  887. $form->{br} = "<br>";
  888. RP->income_statement( \%myconfig, \%$form );
  889. ( $form->{department} ) = split /--/, $form->{department};
  890. ( $form->{projectnumber} ) = split /--/, $form->{projectnumber};
  891. $form->{period} =
  892. $locale->date( \%myconfig, $form->current_date( \%myconfig ), 1 );
  893. $form->{todate} = $form->current_date( \%myconfig ) unless $form->{todate};
  894. # if there are any dates construct a where
  895. if ( $form->{fromdate} || $form->{todate} ) {
  896. unless ( $form->{todate} ) {
  897. $form->{todate} = $form->current_date( \%myconfig );
  898. }
  899. $longtodate = $locale->date( \%myconfig, $form->{todate}, 1 );
  900. $shorttodate = $locale->date( \%myconfig, $form->{todate}, 0 );
  901. $longfromdate = $locale->date( \%myconfig, $form->{fromdate}, 1 );
  902. $shortfromdate = $locale->date( \%myconfig, $form->{fromdate}, 0 );
  903. $form->{this_period} = "$shortfromdate<br>\n$shorttodate";
  904. $form->{period} =
  905. $locale->text('for Period')
  906. . qq|<br>\n$longfromdate |
  907. . $locale->text('To')
  908. . qq| $longtodate|;
  909. }
  910. if ( $form->{comparefromdate} || $form->{comparetodate} ) {
  911. $longcomparefromdate =
  912. $locale->date( \%myconfig, $form->{comparefromdate}, 1 );
  913. $shortcomparefromdate =
  914. $locale->date( \%myconfig, $form->{comparefromdate}, 0 );
  915. $longcomparetodate =
  916. $locale->date( \%myconfig, $form->{comparetodate}, 1 );
  917. $shortcomparetodate =
  918. $locale->date( \%myconfig, $form->{comparetodate}, 0 );
  919. $form->{last_period} = "$shortcomparefromdate<br>\n$shortcomparetodate";
  920. $form->{period} .=
  921. "<br>\n$longcomparefromdate "
  922. . $locale->text('To')
  923. . qq| $longcomparetodate|;
  924. }
  925. # setup variables for the form
  926. @a = qw(company address businessnumber);
  927. for (@a) { $form->{$_} = $myconfig{$_} }
  928. $form->{address} =~ s/\\n/<br>/g;
  929. $form->{templates} = $myconfig{templates};
  930. $form->{IN} = "income_statement.html";
  931. if ( ( $form->{'media'} eq 'screen' ) and ( $form->{'format'} eq 'html' ) )
  932. {
  933. my $template =
  934. LedgerSMB::Template->new( user => \%myconfig,
  935. template => $form->{'formname'}, format => 'HTML' );
  936. try {
  937. $template->render($form);
  938. $form->header;
  939. print $template->{'output'};
  940. exit;
  941. }
  942. catch Error::Simple with {
  943. my $E = shift;
  944. $form->error( $E->stacktrace );
  945. };
  946. }
  947. $form->parse_template;
  948. }
  949. sub generate_balance_sheet {
  950. $form->{padding} = "&nbsp;&nbsp;";
  951. $form->{bold} = "<b>";
  952. $form->{endbold} = "</b>";
  953. $form->{br} = "<br>";
  954. RP->balance_sheet( \%myconfig, \%$form );
  955. $form->{asofdate} = $form->current_date( \%myconfig )
  956. unless $form->{asofdate};
  957. $form->{period} =
  958. $locale->date( \%myconfig, $form->current_date( \%myconfig ), 1 );
  959. ( $form->{department} ) = split /--/, $form->{department};
  960. # define Current Earnings account
  961. $padding = ( $form->{l_heading} ) ? $form->{padding} : "";
  962. push(
  963. @{ $form->{equity_account} },
  964. $padding . $locale->text('Current Earnings')
  965. );
  966. $form->{this_period} = $locale->date( \%myconfig, $form->{asofdate}, 0 );
  967. $form->{last_period} =
  968. $locale->date( \%myconfig, $form->{compareasofdate}, 0 );
  969. $form->{IN} = "balance_sheet.html";
  970. # setup company variables for the form
  971. for (qw(company address businessnumber nativecurr)) {
  972. $form->{$_} = $myconfig{$_};
  973. }
  974. $form->{address} =~ s/\\n/<br>/g;
  975. $form->{templates} = $myconfig{templates};
  976. if ( ( $form->{'media'} eq 'screen' ) and ( $form->{'format'} eq 'html' ) )
  977. {
  978. my $template =
  979. LedgerSMB::Template->new( user => \%myconfig,
  980. template => $form->{'formname'}, format => 'HTML' );
  981. try {
  982. $template->render($form);
  983. $form->header;
  984. print $template->{'output'};
  985. exit;
  986. }
  987. catch Error::Simple with {
  988. my $E = shift;
  989. $form->error( $E->stacktrace );
  990. };
  991. }
  992. $form->parse_template;
  993. }
  994. sub generate_projects {
  995. $form->{nextsub} = "generate_projects";
  996. $form->{title} = $locale->text('Project Transactions');
  997. RP->trial_balance( \%myconfig, \%$form );
  998. &list_accounts;
  999. }
  1000. # Antonio Gallardo
  1001. #
  1002. # D.S. Feb 16, 2001
  1003. # included links to display transactions for period entered
  1004. # added headers and subtotals
  1005. #
  1006. sub generate_trial_balance {
  1007. # get for each account initial balance, debits and credits
  1008. RP->trial_balance( \%myconfig, \%$form );
  1009. $form->{nextsub} = "generate_trial_balance";
  1010. $form->{title} = $locale->text('Trial Balance');
  1011. $form->{callback} = "$form->{script}?action=generate_trial_balance";
  1012. for (
  1013. qw(login path sessionid nextsub fromdate todate month year interval l_heading l_subtotal all_accounts accounttype title)
  1014. )
  1015. {
  1016. $form->{callback} .= "&$_=$form->{$_}";
  1017. }
  1018. $form->{callback} = $form->escape( $form->{callback} );
  1019. &list_accounts;
  1020. }
  1021. sub list_accounts {
  1022. $title = $form->escape( $form->{title} );
  1023. if ( $form->{department} ) {
  1024. ($department) = split /--/, $form->{department};
  1025. $options = $locale->text('Department') . " : $department<br>";
  1026. $department = $form->escape( $form->{department} );
  1027. }
  1028. if ( $form->{projectnumber} ) {
  1029. ($projectnumber) = split /--/, $form->{projectnumber};
  1030. $options .= $locale->text('Project Number') . " : $projectnumber<br>";
  1031. $projectnumber = $form->escape( $form->{projectnumber} );
  1032. }
  1033. # if there are any dates
  1034. if ( $form->{fromdate} || $form->{todate} ) {
  1035. if ( $form->{fromdate} ) {
  1036. $fromdate = $locale->date( \%myconfig, $form->{fromdate}, 1 );
  1037. }
  1038. if ( $form->{todate} ) {
  1039. $todate = $locale->date( \%myconfig, $form->{todate}, 1 );
  1040. }
  1041. $form->{period} = "$fromdate - $todate";
  1042. }
  1043. else {
  1044. $form->{period} =
  1045. $locale->date( \%myconfig, $form->current_date( \%myconfig ), 1 );
  1046. }
  1047. $options .= $form->{period};
  1048. @column_index = qw(accno description begbalance debit credit endbalance);
  1049. $column_header{accno} =
  1050. qq|<th class=listheading>| . $locale->text('Account') . qq|</th>|;
  1051. $column_header{description} =
  1052. qq|<th class=listheading>| . $locale->text('Description') . qq|</th>|;
  1053. $column_header{debit} =
  1054. qq|<th class=listheading>| . $locale->text('Debit') . qq|</th>|;
  1055. $column_header{credit} =
  1056. qq|<th class=listheading>| . $locale->text('Credit') . qq|</th>|;
  1057. $column_header{begbalance} =
  1058. qq|<th class=listheading>| . $locale->text('Balance') . qq|</th>|;
  1059. $column_header{endbalance} =
  1060. qq|<th class=listheading>| . $locale->text('Balance') . qq|</th>|;
  1061. if ( $form->{accounttype} eq 'gifi' ) {
  1062. $column_header{accno} =
  1063. qq|<th class=listheading>| . $locale->text('GIFI') . qq|</th>|;
  1064. }
  1065. $form->header;
  1066. print qq|
  1067. <body>
  1068. <table width=100%>
  1069. <tr>
  1070. <th class=listtop>$form->{title}</th>
  1071. </tr>
  1072. <tr height="5"></tr>
  1073. <tr>
  1074. <td>$options</td>
  1075. </tr>
  1076. <tr>
  1077. <td>
  1078. <table width=100%>
  1079. <tr>|;
  1080. for (@column_index) { print "$column_header{$_}\n" }
  1081. print qq|
  1082. </tr>
  1083. |;
  1084. # sort the whole thing by account numbers and display
  1085. foreach $ref ( sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} } ) {
  1086. $description = $form->escape( $ref->{description} );
  1087. $href =
  1088. 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}|;
  1089. if ( $form->{accounttype} eq 'gifi' ) {
  1090. $href .= "&gifi_accno=$ref->{accno}&gifi_description=$description";
  1091. $na = $locale->text('N/A');
  1092. if ( !$ref->{accno} ) {
  1093. for (qw(accno description)) { $ref->{$_} = $na }
  1094. }
  1095. }
  1096. else {
  1097. $href .= "&accno=$ref->{accno}&description=$description";
  1098. }
  1099. $ml = ( $ref->{category} =~ /(A|E)/ ) ? -1 : 1;
  1100. $ml *= -1 if $ref->{contra};
  1101. $debit = $form->format_amount( \%myconfig, $ref->{debit}, 2, "&nbsp;" );
  1102. $credit =
  1103. $form->format_amount( \%myconfig, $ref->{credit}, 2, "&nbsp;" );
  1104. $begbalance =
  1105. $form->format_amount( \%myconfig, $ref->{balance} * $ml, 2,
  1106. "&nbsp;" );
  1107. $endbalance =
  1108. $form->format_amount( \%myconfig,
  1109. ( $ref->{balance} + $ref->{amount} ) * $ml,
  1110. 2, "&nbsp;" );
  1111. if ( $ref->{charttype} eq "H" && $subtotal && $form->{l_subtotal} ) {
  1112. if ($subtotal) {
  1113. for (qw(accno begbalance endbalance)) {
  1114. $column_data{$_} = "<th>&nbsp;</th>";
  1115. }
  1116. $subtotalbegbalance =
  1117. $form->format_amount( \%myconfig, $subtotalbegbalance, 2,
  1118. "&nbsp;" );
  1119. $subtotalendbalance =
  1120. $form->format_amount( \%myconfig, $subtotalendbalance, 2,
  1121. "&nbsp;" );
  1122. $subtotaldebit =
  1123. $form->format_amount( \%myconfig, $subtotaldebit, 2,
  1124. "&nbsp;" );
  1125. $subtotalcredit =
  1126. $form->format_amount( \%myconfig, $subtotalcredit, 2,
  1127. "&nbsp;" );
  1128. $column_data{description} =
  1129. "<th class=listsubtotal>$subtotaldescription</th>";
  1130. $column_data{begbalance} =
  1131. "<th align=right class=listsubtotal>$subtotalbegbalance</th>";
  1132. $column_data{endbalance} =
  1133. "<th align=right class=listsubtotal>$subtotalendbalance</th>";
  1134. $column_data{debit} =
  1135. "<th align=right class=listsubtotal>$subtotaldebit</th>";
  1136. $column_data{credit} =
  1137. "<th align=right class=listsubtotal>$subtotalcredit</th>";
  1138. print qq|
  1139. <tr class=listsubtotal>
  1140. |;
  1141. for (@column_index) { print "$column_data{$_}\n" }
  1142. print qq|
  1143. </tr>
  1144. |;
  1145. }
  1146. }
  1147. if ( $ref->{charttype} eq "H" ) {
  1148. $subtotal = 1;
  1149. $subtotaldescription = $ref->{description};
  1150. $subtotaldebit = $ref->{debit};
  1151. $subtotalcredit = $ref->{credit};
  1152. $subtotalbegbalance = 0;
  1153. $subtotalendbalance = 0;
  1154. if ( $form->{l_heading} ) {
  1155. if ( !$form->{all_accounts} ) {
  1156. if ( ( $subtotaldebit + $subtotalcredit ) == 0 ) {
  1157. $subtotal = 0;
  1158. next;
  1159. }
  1160. }
  1161. }
  1162. else {
  1163. $subtotal = 0;
  1164. if (
  1165. $form->{all_accounts}
  1166. || ( $form->{l_subtotal}
  1167. && ( ( $subtotaldebit + $subtotalcredit ) != 0 ) )
  1168. )
  1169. {
  1170. $subtotal = 1;
  1171. }
  1172. next;
  1173. }
  1174. for (qw(accno debit credit begbalance endbalance)) {
  1175. $column_data{$_} = "<th>&nbsp;</th>";
  1176. }
  1177. $column_data{description} =
  1178. "<th class=listheading>$ref->{description}</th>";
  1179. }
  1180. if ( $ref->{charttype} eq "A" ) {
  1181. $column_data{accno} = "<td><a href=$href>$ref->{accno}</a></td>";
  1182. $column_data{description} = "<td>$ref->{description}</td>";
  1183. $column_data{debit} = "<td align=right>$debit</td>";
  1184. $column_data{credit} = "<td align=right>$credit</td>";
  1185. $column_data{begbalance} = "<td align=right>$begbalance</td>";
  1186. $column_data{endbalance} = "<td align=right>$endbalance</td>";
  1187. $totaldebit += $ref->{debit};
  1188. $totalcredit += $ref->{credit};
  1189. $cml = ( $ref->{contra} ) ? -1 : 1;
  1190. $subtotalbegbalance += $ref->{balance} * $ml * $cml;
  1191. $subtotalendbalance +=
  1192. ( $ref->{balance} + $ref->{amount} ) * $ml * $cml;
  1193. }
  1194. if ( $ref->{charttype} eq "H" ) {
  1195. print qq|
  1196. <tr class=listheading>
  1197. |;
  1198. }
  1199. if ( $ref->{charttype} eq "A" ) {
  1200. $i++;
  1201. $i %= 2;
  1202. print qq|
  1203. <tr class=listrow$i>
  1204. |;
  1205. }
  1206. for (@column_index) { print "$column_data{$_}\n" }
  1207. print qq|
  1208. </tr>
  1209. |;
  1210. }
  1211. # print last subtotal
  1212. if ( $subtotal && $form->{l_subtotal} ) {
  1213. for (qw(accno begbalance endbalance)) {
  1214. $column_data{$_} = "<th>&nbsp;</th>";
  1215. }
  1216. $subtotalbegbalance =
  1217. $form->format_amount( \%myconfig, $subtotalbegbalance, 2, "&nbsp;" );
  1218. $subtotalendbalance =
  1219. $form->format_amount( \%myconfig, $subtotalendbalance, 2, "&nbsp;" );
  1220. $subtotaldebit =
  1221. $form->format_amount( \%myconfig, $subtotaldebit, 2, "&nbsp;" );
  1222. $subtotalcredit =
  1223. $form->format_amount( \%myconfig, $subtotalcredit, 2, "&nbsp;" );
  1224. $column_data{description} =
  1225. "<th class=listsubtotal>$subtotaldescription</th>";
  1226. $column_data{begbalance} =
  1227. "<th align=right class=listsubtotal>$subtotalbegbalance</th>";
  1228. $column_data{endbalance} =
  1229. "<th align=right class=listsubtotal>$subtotalendbalance</th>";
  1230. $column_data{debit} =
  1231. "<th align=right class=listsubtotal>$subtotaldebit</th>";
  1232. $column_data{credit} =
  1233. "<th align=right class=listsubtotal>$subtotalcredit</th>";
  1234. print qq|
  1235. <tr class=listsubtotal>
  1236. |;
  1237. for (@column_index) { print "$column_data{$_}\n" }
  1238. print qq|
  1239. </tr>
  1240. |;
  1241. }
  1242. $totaldebit = $form->format_amount( \%myconfig, $totaldebit, 2, "&nbsp;" );
  1243. $totalcredit =
  1244. $form->format_amount( \%myconfig, $totalcredit, 2, "&nbsp;" );
  1245. for (qw(accno description begbalance endbalance)) {
  1246. $column_data{$_} = "<th>&nbsp;</th>";
  1247. }
  1248. $column_data{debit} = qq|<th align=right class=listtotal>$totaldebit</th>|;
  1249. $column_data{credit} =
  1250. qq|<th align=right class=listtotal>$totalcredit</th>|;
  1251. print qq|
  1252. <tr class=listtotal>
  1253. |;
  1254. for (@column_index) { print "$column_data{$_}\n" }
  1255. print qq|
  1256. </tr>
  1257. </table>
  1258. </td>
  1259. </tr>
  1260. <tr>
  1261. <td><hr size=3 noshade></td>
  1262. </tr>
  1263. </table>
  1264. </body>
  1265. </html>
  1266. |;
  1267. }
  1268. sub generate_ar_aging {
  1269. # split customer
  1270. ( $form->{customer} ) = split( /--/, $form->{customer} );
  1271. $customer = $form->escape( $form->{customer}, 1 );
  1272. $title = $form->escape( $form->{title}, 1 );
  1273. $media = $form->escape( $form->{media}, 1 );
  1274. $form->{ct} = "customer";
  1275. $form->{arap} = "ar";
  1276. RP->aging( \%myconfig, \%$form );
  1277. $form->{callback} =
  1278. 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}|;
  1279. &aging;
  1280. }
  1281. sub generate_ap_aging {
  1282. # split vendor
  1283. ( $form->{vendor} ) = split( /--/, $form->{vendor} );
  1284. $vendor = $form->escape( $form->{vendor}, 1 );
  1285. $title = $form->escape( $form->{title}, 1 );
  1286. $media = $form->escape( $form->{media}, 1 );
  1287. $form->{ct} = "vendor";
  1288. $form->{arap} = "ap";
  1289. RP->aging( \%myconfig, \%$form );
  1290. $form->{callback} =
  1291. 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}|;
  1292. &aging;
  1293. }
  1294. sub aging {
  1295. $form->header;
  1296. $column_header{statement} = qq|<th class=listheading width=1%>&nbsp;</th>|;
  1297. $column_header{ct} =
  1298. qq|<th class=listheading width=60%>|
  1299. . $locale->text( ucfirst $form->{ct} )
  1300. . qq|</th>|;
  1301. $column_header{language} =
  1302. qq|<th class=listheading>| . $locale->text('Language') . qq|</th>|;
  1303. $column_header{invnumber} =
  1304. qq|<th class=listheading>| . $locale->text('Invoice') . qq|</th>|;
  1305. $column_header{ordnumber} =
  1306. qq|<th class=listheading>| . $locale->text('Order') . qq|</th>|;
  1307. $column_header{transdate} =
  1308. qq|<th class=listheading nowrap>| . $locale->text('Date') . qq|</th>|;
  1309. $column_header{duedate} =
  1310. qq|<th class=listheading nowrap>| . $locale->text('Due Date') . qq|</th>|;
  1311. $column_header{c0} =
  1312. qq|<th class=listheading width=10% nowrap>|
  1313. . $locale->text('Current')
  1314. . qq|</th>|;
  1315. $column_header{c30} = qq|<th class=listheading width=10% nowrap>30</th>|;
  1316. $column_header{c60} = qq|<th class=listheading width=10% nowrap>60</th>|;
  1317. $column_header{c90} = qq|<th class=listheading width=10% nowrap>90</th>|;
  1318. $column_header{total} =
  1319. qq|<th class=listheading width=10% nowrap>|
  1320. . $locale->text('Total')
  1321. . qq|</th>|;
  1322. @column_index = qw(statement ct);
  1323. if ( @{ $form->{all_language} } && $form->{arap} eq 'ar' ) {
  1324. push @column_index, "language";
  1325. $form->{selectlanguage} = qq|<option>\n|;
  1326. for ( @{ $form->{all_language} } ) {
  1327. $form->{selectlanguage} .=
  1328. qq|<option value="$_->{code}">$_->{description}\n|;
  1329. }
  1330. }
  1331. @c = ();
  1332. for (qw(c0 c30 c60 c90)) {
  1333. if ( $form->{$_} ) {
  1334. push @c, $_;
  1335. $form->{callback} .= "&$_=$form->{$_}";
  1336. }
  1337. }
  1338. if ( !$form->{summary} ) {
  1339. push @column_index, qw(invnumber ordnumber transdate duedate);
  1340. }
  1341. push @column_index, @c;
  1342. push @column_index, "total";
  1343. $option = $locale->text('Aged');
  1344. if ( $form->{overdue} ) {
  1345. $option = $locale->text('Aged Overdue');
  1346. $form->{callback} .= "&overdue=$form->{overdue}";
  1347. }
  1348. if ( $form->{department} ) {
  1349. $option .= "\n<br>" if $option;
  1350. ($department) = split /--/, $form->{department};
  1351. $option .= $locale->text('Department') . " : $department";
  1352. $department = $form->escape( $form->{department}, 1 );
  1353. $form->{callback} .= "&department=$department";
  1354. }
  1355. if ( $form->{arap} eq 'ar' ) {
  1356. if ( $form->{customer} ) {
  1357. $option .= "\n<br>" if $option;
  1358. $option .= $form->{customer};
  1359. }
  1360. }
  1361. if ( $form->{arap} eq 'ap' ) {
  1362. shift @column_index;
  1363. if ( $form->{vendor} ) {
  1364. $option .= "\n<br>" if $option;
  1365. $option .= $form->{vendor};
  1366. }
  1367. }
  1368. $todate = $locale->date( \%myconfig, $form->{todate}, 1 );
  1369. $option .= "\n<br>" if $option;
  1370. $option .=
  1371. $locale->text('for Period') . " " . $locale->text('To') . " $todate";
  1372. print qq|
  1373. <body>
  1374. <form method=post action=$form->{script}>
  1375. <table width=100%>
  1376. <tr>
  1377. <th class=listtop>$form->{title}</th>
  1378. </tr>
  1379. <tr height="5"></tr>
  1380. <tr>
  1381. <td>$option</td>
  1382. </tr>
  1383. <tr>
  1384. <td>
  1385. <table width=100%>
  1386. |;
  1387. $ctid = 0;
  1388. $i = 0;
  1389. $k = 0;
  1390. $l = $#{ $form->{AG} };
  1391. foreach $ref ( @{ $form->{AG} } ) {
  1392. if ( $curr ne $ref->{curr} ) {
  1393. $ctid = 0;
  1394. for (@column_index) { $column_data{$_} = qq|<th>&nbsp;</th>| }
  1395. if ($curr) {
  1396. $c0total =
  1397. $form->format_amount( \%myconfig, $c0total, 2, "&nbsp" );
  1398. $c30total =
  1399. $form->format_amount( \%myconfig, $c30total, 2, "&nbsp" );
  1400. $c60total =
  1401. $form->format_amount( \%myconfig, $c60total, 2, "&nbsp" );
  1402. $c90total =
  1403. $form->format_amount( \%myconfig, $c90total, 2, "&nbsp" );
  1404. $total = $form->format_amount( \%myconfig, $total, 2, "&nbsp" );
  1405. for (qw(ct statement language)) {
  1406. $column_data{$_} = qq|<td>&nbsp;</td>|;
  1407. }
  1408. $column_data{c0} = qq|<th align=right>$c0total</th>|;
  1409. $column_data{c30} = qq|<th align=right>$c30total</th>|;
  1410. $column_data{c60} = qq|<th align=right>$c60total</th>|;
  1411. $column_data{c90} = qq|<th align=right>$c90total</th>|;
  1412. $column_data{total} = qq|<th align=right>$total</th>|;
  1413. print qq|
  1414. <tr class=listtotal>
  1415. |;
  1416. for (@column_index) { print "$column_data{$_}\n" }
  1417. print qq|
  1418. </tr>
  1419. |;
  1420. $c0subtotal = 0;
  1421. $c30subtotal = 0;
  1422. $c60subtotal = 0;
  1423. $c90subtotal = 0;
  1424. $subtotal = 0;
  1425. $c0total = 0;
  1426. $c30total = 0;
  1427. $c60total = 0;
  1428. $c90total = 0;
  1429. $total = 0;
  1430. }
  1431. $curr = $ref->{curr};
  1432. print qq|
  1433. <tr>
  1434. <td></td>
  1435. <th>$curr</th>
  1436. </tr>
  1437. <tr class=listheading>
  1438. |;
  1439. for (@column_index) { print "$column_header{$_}\n" }
  1440. print qq|
  1441. </tr>
  1442. |;
  1443. }
  1444. $k++;
  1445. if ( $ctid != $ref->{ctid} ) {
  1446. $i++;
  1447. $column_data{ct} = qq|<td>$ref->{name}</td>|;
  1448. if ( $form->{selectlanguage} ) {
  1449. $form->{"selectlanguage_$i"} = $form->{selectlanguage};
  1450. $form->{"selectlanguage_$i"} =~
  1451. s/(<option value="\Q$ref->{language_code}\E")/$1 selected/;
  1452. $column_data{language} =
  1453. qq|<td><select name="language_code_$i">$form->{"selectlanguage_$i"}</select></td>|;
  1454. }
  1455. $column_data{statement} =
  1456. qq|<td><input name="statement_$i" type=checkbox class=checkbox value=1 $ref->{checked}>
  1457. <input type=hidden name="$form->{ct}_id_$i" value=$ref->{ctid}>
  1458. <input type=hidden name="curr_$i" value=$ref->{curr}>
  1459. </td>|;
  1460. }
  1461. $ctid = $ref->{ctid};
  1462. for (qw(c0 c30 c60 c90)) {
  1463. $ref->{$_} =
  1464. $form->round_amount( $ref->{$_} / $ref->{exchangerate}, 2 );
  1465. }
  1466. $c0subtotal += $ref->{c0};
  1467. $c30subtotal += $ref->{c30};
  1468. $c60subtotal += $ref->{c60};
  1469. $c90subtotal += $ref->{c90};
  1470. $c0total += $ref->{c0};
  1471. $c30total += $ref->{c30};
  1472. $c60total += $ref->{c60};
  1473. $c90total += $ref->{c90};
  1474. $ref->{total} =
  1475. ( $ref->{c0} + $ref->{c30} + $ref->{c60} + $ref->{c90} );
  1476. $subtotal += $ref->{total};
  1477. $total += $ref->{total};
  1478. $ref->{c0} =
  1479. $form->format_amount( \%myconfig, $ref->{c0}, 2, "&nbsp;" );
  1480. $ref->{c30} =
  1481. $form->format_amount( \%myconfig, $ref->{c30}, 2, "&nbsp;" );
  1482. $ref->{c60} =
  1483. $form->format_amount( \%myconfig, $ref->{c60}, 2, "&nbsp;" );
  1484. $ref->{c90} =
  1485. $form->format_amount( \%myconfig, $ref->{c90}, 2, "&nbsp;" );
  1486. $ref->{total} =
  1487. $form->format_amount( \%myconfig, $ref->{total}, 2, "&nbsp;" );
  1488. $href =
  1489. qq|$ref->{module}.pl?path=$form->{path}&action=edit&id=$ref->{id}&login=$form->{login}&sessionid=$form->{sessionid}&callback=|
  1490. . $form->escape( $form->{callback} );
  1491. $column_data{invnumber} =
  1492. qq|<td><a href=$href>$ref->{invnumber}</a></td>|;
  1493. for (qw(ordnumber transdate duedate)) {
  1494. $column_data{$_} = qq|<td>$ref->{$_}</td>|;
  1495. }
  1496. for (qw(c0 c30 c60 c90 total)) {
  1497. $column_data{$_} = qq|<td align=right>$ref->{$_}</td>|;
  1498. }
  1499. if ( !$form->{summary} ) {
  1500. $j++;
  1501. $j %= 2;
  1502. print qq|
  1503. <tr class=listrow$j>
  1504. |;
  1505. for (@column_index) { print "$column_data{$_}\n" }
  1506. print qq|
  1507. </tr>
  1508. |;
  1509. for (qw(ct statement language)) {
  1510. $column_data{$_} = qq|<td>&nbsp;</td>|;
  1511. }
  1512. }
  1513. # print subtotal
  1514. $nextid = ( $k <= $l ) ? $form->{AG}->[$k]->{ctid} : 0;
  1515. if ( $ctid != $nextid ) {
  1516. $c0subtotal =
  1517. $form->format_amount( \%myconfig, $c0subtotal, 2, "&nbsp" );
  1518. $c30subtotal =
  1519. $form->format_amount( \%myconfig, $c30subtotal, 2, "&nbsp" );
  1520. $c60subtotal =
  1521. $form->format_amount( \%myconfig, $c60subtotal, 2, "&nbsp" );
  1522. $c90subtotal =
  1523. $form->format_amount( \%myconfig, $c90subtotal, 2, "&nbsp" );
  1524. $subtotal =
  1525. $form->format_amount( \%myconfig, $subtotal, 2, "&nbsp" );
  1526. if ( $form->{summary} ) {
  1527. $column_data{c0} = qq|<td align=right>$c0subtotal</th>|;
  1528. $column_data{c30} = qq|<td align=right>$c30subtotal</th>|;
  1529. $column_data{c60} = qq|<td align=right>$c60subtotal</th>|;
  1530. $column_data{c90} = qq|<td align=right>$c90subtotal</th>|;
  1531. $column_data{total} = qq|<td align=right>$subtotal</th>|;
  1532. $j++;
  1533. $j %= 2;
  1534. print qq|
  1535. <tr class=listrow$j>
  1536. |;
  1537. for (@column_index) { print "$column_data{$_}\n" }
  1538. print qq|
  1539. </tr>
  1540. |;
  1541. }
  1542. else {
  1543. for (@column_index) { $column_data{$_} = qq|<th>&nbsp;</th>| }
  1544. $column_data{c0} =
  1545. qq|<th class=listsubtotal align=right>$c0subtotal</th>|;
  1546. $column_data{c30} =
  1547. qq|<th class=listsubtotal align=right>$c30subtotal</th>|;
  1548. $column_data{c60} =
  1549. qq|<th class=listsubtotal align=right>$c60subtotal</th>|;
  1550. $column_data{c90} =
  1551. qq|<th class=listsubtotal align=right>$c90subtotal</th>|;
  1552. $column_data{total} =
  1553. qq|<th class=listsubtotal align=right>$subtotal</th>|;
  1554. # print subtotals
  1555. print qq|
  1556. <tr class=listsubtotal>
  1557. |;
  1558. for (@column_index) { print "$column_data{$_}\n" }
  1559. print qq|
  1560. </tr>
  1561. |;
  1562. }
  1563. $c0subtotal = 0;
  1564. $c30subtotal = 0;
  1565. $c60subtotal = 0;
  1566. $c90subtotal = 0;
  1567. $subtotal = 0;
  1568. }
  1569. }
  1570. print qq|
  1571. </tr>
  1572. <tr class=listtotal>
  1573. |;
  1574. for (@column_index) { $column_data{$_} = qq|<th>&nbsp;</th>| }
  1575. $c0total = $form->format_amount( \%myconfig, $c0total, 2, "&nbsp;" );
  1576. $c30total = $form->format_amount( \%myconfig, $c30total, 2, "&nbsp;" );
  1577. $c60total = $form->format_amount( \%myconfig, $c60total, 2, "&nbsp;" );
  1578. $c90total = $form->format_amount( \%myconfig, $c90total, 2, "&nbsp;" );
  1579. $total = $form->format_amount( \%myconfig, $total, 2, "&nbsp;" );
  1580. $column_data{c0} = qq|<th align=right class=listtotal>$c0total</th>|;
  1581. $column_data{c30} = qq|<th align=right class=listtotal>$c30total</th>|;
  1582. $column_data{c60} = qq|<th align=right class=listtotal>$c60total</th>|;
  1583. $column_data{c90} = qq|<th align=right class=listtotal>$c90total</th>|;
  1584. $column_data{total} = qq|<th align=right class=listtotal>$total</th>|;
  1585. for (@column_index) { print "$column_data{$_}\n" }
  1586. print qq|
  1587. </tr>
  1588. <input type=hidden name=rowcount value=$i>
  1589. </table>
  1590. </td>
  1591. </tr>
  1592. <tr>
  1593. <td>
  1594. |;
  1595. &print_options if ( $form->{arap} eq 'ar' );
  1596. print qq|
  1597. </td>
  1598. </tr>
  1599. <tr>
  1600. <td><hr size=3 noshade></td>
  1601. </tr>
  1602. </table>
  1603. |;
  1604. if ( $form->{arap} eq 'ar' ) {
  1605. $form->hide_form(
  1606. qw(todate title summary overdue c0 c30 c60 c90 callback arap ct department path login sessionid)
  1607. );
  1608. print qq|
  1609. <input type=hidden name=$form->{ct} value="$form->{$form->{ct}}">
  1610. |;
  1611. # type=submit $locale->text('Select all')
  1612. # type=submit $locale->text('Print')
  1613. # type=submit $locale->text('E-mail')
  1614. %button = (
  1615. 'select_all' =>
  1616. { ndx => 1, key => 'A', value => $locale->text('Select all') },
  1617. 'print' =>
  1618. { ndx => 2, key => 'P', value => $locale->text('Print') },
  1619. 'e_mail' =>
  1620. { ndx => 5, key => 'E', value => $locale->text('E-mail') },
  1621. );
  1622. for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button )
  1623. {
  1624. $form->print_button( \%button, $_ );
  1625. }
  1626. }
  1627. if ( $form->{lynx} ) {
  1628. require "bin/menu.pl";
  1629. &menubar;
  1630. }
  1631. print qq|
  1632. </form>
  1633. </body>
  1634. </html>
  1635. |;
  1636. }
  1637. sub select_all {
  1638. RP->aging( \%myconfig, \%$form );
  1639. for ( @{ $form->{AG} } ) { $_->{checked} = "checked" }
  1640. &aging;
  1641. }
  1642. sub print_options {
  1643. $form->{sendmode} = "attachment";
  1644. $form->{copies} = 1 unless $form->{copies};
  1645. $form->{PD}{ $form->{type} } = "selected";
  1646. $form->{DF}{ $form->{format} } = "selected";
  1647. $form->{SM}{ $form->{sendmode} } = "selected";
  1648. $format = qq|
  1649. <option value=html $form->{PD}{format}>html|;
  1650. $type = qq|
  1651. <option value=statement $form->{PD}{statement}>|
  1652. . $locale->text('Statement');
  1653. if ( $form->{media} eq 'email' ) {
  1654. $media = qq|
  1655. <td><select name=sendmode>
  1656. <option value=attachment $form->{SM}{attachment}>|
  1657. . $locale->text('Attachment') . qq|
  1658. <option value=inline $form->{SM}{inline}>| . $locale->text('In-line');
  1659. }
  1660. else {
  1661. $media = qq|
  1662. <td><select name=media>
  1663. <option value=screen>| . $locale->text('Screen');
  1664. if ( %{LedgerSMB::Sysconfig::printer}
  1665. && ${LedgerSMB::Sysconfig::latex} )
  1666. {
  1667. for ( sort keys %{LedgerSMB::Sysconfig::printer} ) {
  1668. $media .= qq|
  1669. <option value="$_">$_|;
  1670. }
  1671. }
  1672. }
  1673. $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/;
  1674. $media .= qq|</select></td>|;
  1675. if ( ${LedgerSMB::Sysconfig::latex} ) {
  1676. $format .= qq|
  1677. <option value=postscript $form->{DF}{postscript}>|
  1678. . $locale->text('Postscript') . qq|
  1679. <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF');
  1680. }
  1681. print qq|
  1682. <table>
  1683. <tr>
  1684. <td><select name=type>$type</select></td>
  1685. <td><select name=format>$format</select></td>
  1686. $media
  1687. |;
  1688. if ( %{LedgerSMB::Sysconfig::printer}
  1689. && ${LedgerSMB::Sysconfig::latex}
  1690. && $form->{media} ne 'email' )
  1691. {
  1692. print qq|
  1693. <td>| . $locale->text('Copies') . qq|
  1694. <input name=copies size=2 value=$form->{copies}></td>
  1695. |;
  1696. }
  1697. print qq|
  1698. </tr>
  1699. </table>
  1700. |;
  1701. }
  1702. sub e_mail {
  1703. # get name and email addresses
  1704. for $i ( 1 .. $form->{rowcount} ) {
  1705. if ( $form->{"statement_$i"} ) {
  1706. $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
  1707. $form->{"statement_1"} = 1;
  1708. $form->{"language_code_1"} = $form->{"language_code_$i"};
  1709. $form->{"curr_1"} = $form->{"curr_$i"};
  1710. RP->get_customer( \%myconfig, \%$form );
  1711. $selected = 1;
  1712. last;
  1713. }
  1714. }
  1715. $form->error( $locale->text('Nothing selected!') ) unless $selected;
  1716. if ( $myconfig{role} =~ /(admin|manager)/ ) {
  1717. $bcc = qq|
  1718. <th align=right nowrap=true>| . $locale->text('Bcc') . qq|</th>
  1719. <td><input name=bcc size=30 value="$form->{bcc}"></td>
  1720. |;
  1721. }
  1722. $title =
  1723. $locale->text( 'E-mail Statement to [_1]', $form->{ $form->{ct} } );
  1724. $form->{media} = "email";
  1725. $form->header;
  1726. print qq|
  1727. <body>
  1728. <form method=post action=$form->{script}>
  1729. <table width=100%>
  1730. <tr class=listtop>
  1731. <th>$title</th>
  1732. </tr>
  1733. <tr height="5"></tr>
  1734. <tr>
  1735. <td>
  1736. <table width=100%>
  1737. <tr>
  1738. <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
  1739. <td><input name=email size=30 value="$form->{email}"></td>
  1740. <th align=right nowrap>| . $locale->text('Cc') . qq|</th>
  1741. <td><input name=cc size=30 value="$form->{cc}"></td>
  1742. </tr>
  1743. <tr>
  1744. <th align=right nowrap>| . $locale->text('Subject') . qq|</th>
  1745. <td><input name=subject size=30 value="$form->{subject}"></td>
  1746. $bcc
  1747. </tr>
  1748. </table>
  1749. </td>
  1750. </tr>
  1751. <tr>
  1752. <td>
  1753. <table width=100%>
  1754. <tr>
  1755. <th align=left nowrap>| . $locale->text('Message') . qq|</th>
  1756. </tr>
  1757. <tr>
  1758. <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
  1759. </tr>
  1760. </table>
  1761. </td>
  1762. </tr>
  1763. <tr>
  1764. <td>
  1765. |;
  1766. &print_options;
  1767. for (qw(email cc bcc subject message type sendmode format action nextsub)) {
  1768. delete $form->{$_};
  1769. }
  1770. $form->hide_form;
  1771. print qq|
  1772. </td>
  1773. </tr>
  1774. <tr>
  1775. <td><hr size=3 noshade></td>
  1776. </tr>
  1777. </table>
  1778. <input type="hidden" name="nextsub" value="send_email">
  1779. <br>
  1780. <button name="action" class="submit" type="submit" value="continue">|
  1781. . $locale->text('Continue')
  1782. . qq|</button>
  1783. </form>
  1784. </body>
  1785. </html>
  1786. |;
  1787. }
  1788. sub send_email {
  1789. $form->{OUT} = "${LedgerSMB::Sysconfig::sendmail}";
  1790. $form->{printmode} = '|-';
  1791. $form->{subject} = $locale->text( 'Statement - [_1]', $form->{todate} )
  1792. unless $form->{subject};
  1793. $form->isblank( "email", $locale->text('E-mail address missing!') );
  1794. RP->aging( \%myconfig, \%$form );
  1795. &print_form;
  1796. $form->redirect(
  1797. $locale->text( 'Statement sent to [_1]', $form->{ $form->{ct} } ) );
  1798. }
  1799. sub print {
  1800. if ( $form->{media} !~ /(screen|email)/ ) {
  1801. $form->error( $locale->text('Select postscript or PDF!') )
  1802. if ( $form->{format} !~ /(postscript|pdf)/ );
  1803. }
  1804. for $i ( 1 .. $form->{rowcount} ) {
  1805. if ( $form->{"statement_$i"} ) {
  1806. $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
  1807. $language_code = $form->{"language_code_$i"};
  1808. $curr = $form->{"curr_$i"};
  1809. $selected = 1;
  1810. last;
  1811. }
  1812. }
  1813. $form->error( $locale->text('Nothing selected!') ) unless $selected;
  1814. if ( $form->{media} !~ /(screen|email)/ ) {
  1815. $form->{OUT} = "${LedgerSMB::Sysconfig::printer}{$form->{media}}";
  1816. $form->{printmode} = '|-';
  1817. $form->{"$form->{ct}_id"} = "";
  1818. $SIG{INT} = 'IGNORE';
  1819. }
  1820. else {
  1821. $form->{"statement_1"} = 1;
  1822. $form->{"language_code_1"} = $language_code;
  1823. $form->{"curr_1"} = $curr;
  1824. }
  1825. RP->aging( \%myconfig, \%$form );
  1826. &print_form;
  1827. $form->redirect( $locale->text('Statements sent to printer!') )
  1828. if ( $form->{media} !~ /(screen|email)/ );
  1829. }
  1830. sub print_form {
  1831. $form->{statementdate} = $locale->date( \%myconfig, $form->{todate}, 1 );
  1832. $form->{templates} = "$myconfig{templates}";
  1833. # setup variables for the form
  1834. @a = qw(company address businessnumber tel fax);
  1835. for (@a) { $form->{$_} = $myconfig{$_} }
  1836. $form->{address} =~ s/\\n/\n/g;
  1837. $form->format_string(@a);
  1838. $form->{IN} = "$form->{type}.html";
  1839. if ( $form->{format} eq 'postscript' ) {
  1840. $form->{IN} =~ s/html$/tex/;
  1841. }
  1842. if ( $form->{format} eq 'pdf' ) {
  1843. $form->{IN} =~ s/html$/tex/;
  1844. }
  1845. @a = qw(name address1 address2 city state zipcode country contact);
  1846. push @a, "$form->{ct}phone", "$form->{ct}fax", "$form->{ct}taxnumber";
  1847. push @a, 'email' if !$form->{media} eq 'email';
  1848. $i = 0;
  1849. while ( @{ $form->{AG} } ) {
  1850. $ref = shift @{ $form->{AG} };
  1851. if ( $ctid != $ref->{ctid} ) {
  1852. $ctid = $ref->{ctid};
  1853. $i++;
  1854. if ( $form->{"statement_$i"} ) {
  1855. for (@a) { $form->{$_} = $ref->{$_} }
  1856. $form->format_string(@a);
  1857. $form->{ $form->{ct} } = $form->{name};
  1858. $form->{"$form->{ct}_id"} = $ref->{ctid};
  1859. $form->{language_code} = $form->{"language_code_$i"};
  1860. $form->{currency} = $form->{"curr_$i"};
  1861. for (qw(invnumber ordnumber ponumber notes invdate duedate)) {
  1862. $form->{$_} = ();
  1863. }
  1864. $form->{total} = 0;
  1865. foreach $item (qw(c0 c30 c60 c90)) {
  1866. $form->{$item} = ();
  1867. $form->{"${item}total"} = 0;
  1868. }
  1869. &statement_details($ref) if $ref->{curr} eq $form->{currency};
  1870. while ($ref) {
  1871. if ( scalar( @{ $form->{AG} } ) > 0 ) {
  1872. # one or more left to go
  1873. if ( $ctid == $form->{AG}->[0]->{ctid} ) {
  1874. $ref = shift @{ $form->{AG} };
  1875. &statement_details($ref)
  1876. if $ref->{curr} eq $form->{currency};
  1877. # any more?
  1878. $ref = scalar( @{ $form->{AG} } );
  1879. }
  1880. else {
  1881. $ref = 0;
  1882. }
  1883. }
  1884. else {
  1885. # set initial ref to 0
  1886. $ref = 0;
  1887. }
  1888. }
  1889. for ( "c0", "c30", "c60", "c90", "" ) {
  1890. $form->{"${_}total"} =
  1891. $form->format_amount( \%myconfig, $form->{"${_}total"},
  1892. 2 );
  1893. }
  1894. if ( ( $form->{'media'} eq 'screen' )
  1895. and ( $form->{'format'} eq 'html' ) )
  1896. {
  1897. my $template =
  1898. LedgerSMB::Template->new( user => \%myconfig,
  1899. template => $form->{'formname'},
  1900. format => 'HTML' );
  1901. try {
  1902. $template->render($form);
  1903. $form->header;
  1904. print $template->{'output'};
  1905. exit;
  1906. }
  1907. catch Error::Simple with {
  1908. my $E = shift;
  1909. $form->error( $E->stacktrace );
  1910. };
  1911. }
  1912. $form->parse_template( \%myconfig,
  1913. ${LedgerSMB::Sysconfig::userspath} );
  1914. }
  1915. }
  1916. }
  1917. }
  1918. sub statement_details {
  1919. my ($ref) = @_;
  1920. $ref->{invdate} = $ref->{transdate};
  1921. my @a = qw(invnumber ordnumber ponumber notes invdate duedate);
  1922. for (@a) { $form->{"${_}_1"} = $ref->{$_} }
  1923. $form->format_string(qw(invnumber_1 ordnumber_1 ponumber_1 notes_1));
  1924. for (@a) { push @{ $form->{$_} }, $form->{"${_}_1"} }
  1925. foreach $item (qw(c0 c30 c60 c90)) {
  1926. eval {
  1927. $ref->{$item} =
  1928. $form->round_amount( $ref->{$item} / $ref->{exchangerate}, 2 );
  1929. };
  1930. $form->{"${item}total"} += $ref->{$item};
  1931. $form->{total} += $ref->{$item};
  1932. push @{ $form->{$item} },
  1933. $form->format_amount( \%myconfig, $ref->{$item}, 2 );
  1934. }
  1935. }
  1936. sub generate_tax_report {
  1937. RP->tax_report( \%myconfig, \%$form );
  1938. $descvar = "$form->{accno}_description";
  1939. $description = $form->escape( $form->{$descvar} );
  1940. $ratevar = "$form->{accno}_rate";
  1941. $taxrate = $form->{"$form->{accno}_rate"};
  1942. if ( $form->{accno} =~ /^gifi_/ ) {
  1943. $descvar = "gifi_$form->{accno}_description";
  1944. $description = $form->escape( $form->{$descvar} );
  1945. $ratevar = "gifi_$form->{accno}_rate";
  1946. $taxrate = $form->{"gifi_$form->{accno}_rate"};
  1947. }
  1948. $department = $form->escape( $form->{department} );
  1949. # construct href
  1950. $href =
  1951. "$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}";
  1952. # construct callback
  1953. $description = $form->escape( $form->{$descvar}, 1 );
  1954. $department = $form->escape( $form->{department}, 1 );
  1955. $form->sort_order();
  1956. $callback =
  1957. "$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}";
  1958. $form->{title} = $locale->text('GIFI') . " - "
  1959. if ( $form->{accno} =~ /^gifi_/ );
  1960. $title = $form->escape( $form->{title} );
  1961. $href .= "&title=$title";
  1962. $title = $form->escape( $form->{title}, 1 );
  1963. $callback .= "&title=$title";
  1964. $form->{title} = qq|$form->{title} $form->{"$form->{accno}_description"} |;
  1965. @columns =
  1966. $form->sort_columns(
  1967. qw(id transdate invnumber name description netamount tax total));
  1968. $form->{"l_description"} = "" if $form->{summary};
  1969. foreach $item (@columns) {
  1970. if ( $form->{"l_$item"} eq "Y" ) {
  1971. push @column_index, $item;
  1972. # add column to href and callback
  1973. $callback .= "&l_$item=Y";
  1974. $href .= "&l_$item=Y";
  1975. }
  1976. }
  1977. if ( $form->{l_subtotal} eq 'Y' ) {
  1978. $callback .= "&l_subtotal=Y";
  1979. $href .= "&l_subtotal=Y";
  1980. }
  1981. if ( $form->{department} ) {
  1982. ($department) = split /--/, $form->{department};
  1983. $option = $locale->text('Department') . " : $department";
  1984. }
  1985. # if there are any dates
  1986. if ( $form->{fromdate} || $form->{todate} ) {
  1987. if ( $form->{fromdate} ) {
  1988. $fromdate = $locale->date( \%myconfig, $form->{fromdate}, 1 );
  1989. }
  1990. if ( $form->{todate} ) {
  1991. $todate = $locale->date( \%myconfig, $form->{todate}, 1 );
  1992. }
  1993. $form->{period} = "$fromdate - $todate";
  1994. }
  1995. else {
  1996. $form->{period} =
  1997. $locale->date( \%myconfig, $form->current_date( \%myconfig ), 1 );
  1998. }
  1999. if ( $form->{db} eq 'ar' ) {
  2000. $name = $locale->text('Customer');
  2001. $invoice = 'is.pl';
  2002. $arap = 'ar.pl';
  2003. }
  2004. if ( $form->{db} eq 'ap' ) {
  2005. $name = $locale->text('Vendor');
  2006. $invoice = 'ir.pl';
  2007. $arap = 'ap.pl';
  2008. }
  2009. $option .= "<br>" if $option;
  2010. $option .= "$form->{period}";
  2011. $column_header{id} =
  2012. qq|<th><a class=listheading href=$href&sort=id>|
  2013. . $locale->text('ID')
  2014. . qq|</th>|;
  2015. $column_header{invnumber} =
  2016. qq|<th><a class=listheading href=$href&sort=invnumber>|
  2017. . $locale->text('Invoice')
  2018. . qq|</th>|;
  2019. $column_header{transdate} =
  2020. qq|<th><a class=listheading href=$href&sort=transdate>|
  2021. . $locale->text('Date')
  2022. . qq|</th>|;
  2023. $column_header{netamount} =
  2024. qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
  2025. $column_header{tax} =
  2026. qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
  2027. $column_header{total} =
  2028. qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
  2029. $column_header{name} =
  2030. qq|<th><a class=listheading href=$href&sort=name>$name</th>|;
  2031. $column_header{description} =
  2032. qq|<th><a class=listheading href=$href&sort=description>|
  2033. . $locale->text('Description')
  2034. . qq|</th>|;
  2035. $form->header;
  2036. print qq|
  2037. <body>
  2038. <table width=100%>
  2039. <tr>
  2040. <th class=listtop colspan=$colspan>$form->{title}</th>
  2041. </tr>
  2042. <tr height="5"></tr>
  2043. <tr>
  2044. <td>$option</td>
  2045. </tr>
  2046. <tr>
  2047. <td>
  2048. <table width=100%>
  2049. <tr class=listheading>
  2050. |;
  2051. for (@column_index) { print "$column_header{$_}\n" }
  2052. print qq|
  2053. </tr>
  2054. |;
  2055. # add sort and escape callback
  2056. $callback = $form->escape( $callback . "&sort=$form->{sort}" );
  2057. if ( @{ $form->{TR} } ) {
  2058. $sameitem = $form->{TR}->[0]->{ $form->{sort} };
  2059. }
  2060. foreach $ref ( @{ $form->{TR} } ) {
  2061. $module = ( $ref->{invoice} ) ? $invoice : $arap;
  2062. $module = 'ps.pl' if $ref->{till};
  2063. if ( $form->{l_subtotal} eq 'Y' ) {
  2064. if ( $sameitem ne $ref->{ $form->{sort} } ) {
  2065. &tax_subtotal;
  2066. $sameitem = $ref->{ $form->{sort} };
  2067. }
  2068. }
  2069. $totalnetamount += $ref->{netamount};
  2070. $totaltax += $ref->{tax};
  2071. $ref->{total} = $ref->{netamount} + $ref->{tax};
  2072. $subtotalnetamount += $ref->{netamount};
  2073. $subtotaltax += $ref->{tax};
  2074. for (qw(netamount tax total)) {
  2075. $ref->{$_} =
  2076. $form->format_amount( \%myconfig, $ref->{$_}, 2, "&nbsp;" );
  2077. }
  2078. $column_data{id} = qq|<td>$ref->{id}</td>|;
  2079. $column_data{invnumber} =
  2080. 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>|;
  2081. for (qw(id transdate name partnumber description)) {
  2082. $column_data{$_} = qq|<td>$ref->{$_}</td>|;
  2083. }
  2084. for (qw(netamount tax total)) {
  2085. $column_data{$_} = qq|<td align=right>$ref->{$_}</td>|;
  2086. }
  2087. $i++;
  2088. $i %= 2;
  2089. print qq|
  2090. <tr class=listrow$i>
  2091. |;
  2092. for (@column_index) { print "$column_data{$_}\n" }
  2093. print qq|
  2094. </tr>
  2095. |;
  2096. }
  2097. if ( $form->{l_subtotal} eq 'Y' ) {
  2098. &tax_subtotal;
  2099. }
  2100. for (@column_index) { $column_data{$_} = qq|<th>&nbsp;</th>| }
  2101. print qq|
  2102. </tr>
  2103. <tr class=listtotal>
  2104. |;
  2105. $total = $form->format_amount( \%myconfig, $totalnetamount + $totaltax,
  2106. 2, "&nbsp;" );
  2107. $totalnetamount =
  2108. $form->format_amount( \%myconfig, $totalnetamount, 2, "&nbsp;" );
  2109. $totaltax = $form->format_amount( \%myconfig, $totaltax, 2, "&nbsp;" );
  2110. $column_data{netamount} =
  2111. qq|<th class=listtotal align=right>$totalnetamount</th>|;
  2112. $column_data{tax} = qq|<th class=listtotal align=right>$totaltax</th>|;
  2113. $column_data{total} = qq|<th class=listtotal align=right>$total</th>|;
  2114. for (@column_index) { print "$column_data{$_}\n" }
  2115. print qq|
  2116. </tr>
  2117. </table>
  2118. </td>
  2119. </tr>
  2120. <tr>
  2121. <td><hr size=3 noshade></td>
  2122. </tr>
  2123. </table>
  2124. </body>
  2125. </html>
  2126. |;
  2127. }
  2128. sub tax_subtotal {
  2129. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  2130. $subtotal =
  2131. $form->format_amount( \%myconfig, $subtotalnetamount + $subtotaltax,
  2132. 2, "&nbsp;" );
  2133. $subtotalnetamount =
  2134. $form->format_amount( \%myconfig, $subtotalnetamount, 2, "&nbsp;" );
  2135. $subtotaltax =
  2136. $form->format_amount( \%myconfig, $subtotaltax, 2, "&nbsp;" );
  2137. $column_data{netamount} =
  2138. "<th class=listsubtotal align=right>$subtotalnetamount</th>";
  2139. $column_data{tax} = "<th class=listsubtotal align=right>$subtotaltax</th>";
  2140. $column_data{total} = "<th class=listsubtotal align=right>$subtotal</th>";
  2141. $subtotalnetamount = 0;
  2142. $subtotaltax = 0;
  2143. print qq|
  2144. <tr class=listsubtotal>
  2145. |;
  2146. for (@column_index) { print "\n$column_data{$_}" }
  2147. print qq|
  2148. </tr>
  2149. |;
  2150. }
  2151. sub list_payments {
  2152. if ( $form->{account} ) {
  2153. ( $form->{paymentaccounts} ) = split /--/, $form->{account};
  2154. }
  2155. if ( $form->{department} ) {
  2156. ( $department, $form->{department_id} ) = split /--/,
  2157. $form->{department};
  2158. $option = $locale->text('Department') . " : $department";
  2159. }
  2160. RP->payments( \%myconfig, \%$form );
  2161. @columns = $form->sort_columns(qw(transdate name paid source memo));
  2162. if ( $form->{till} ) {
  2163. @columns =
  2164. $form->sort_columns(qw(transdate name paid curr source till));
  2165. if ( $myconfig{role} ne 'user' ) {
  2166. @columns =
  2167. $form->sort_columns(
  2168. qw(transdate name paid curr source till employee));
  2169. }
  2170. }
  2171. # construct href
  2172. $title = $form->escape( $form->{title} );
  2173. $form->{paymentaccounts} =~ s/ /%20/g;
  2174. $href =
  2175. "$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="
  2176. . $form->escape( $form->{title} );
  2177. $form->sort_order();
  2178. $form->{callback} =
  2179. "$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="
  2180. . $form->escape( $form->{title}, 1 );
  2181. if ( $form->{account} ) {
  2182. $callback .= "&account=" . $form->escape( $form->{account}, 1 );
  2183. $href .= "&account=" . $form->escape( $form->{account} );
  2184. $option .= "\n<br>" if ($option);
  2185. $option .= $locale->text('Account') . " : $form->{account}";
  2186. }
  2187. if ( $form->{department} ) {
  2188. $callback .= "&department=" . $form->escape( $form->{department}, 1 );
  2189. $href .= "&department=" . $form->escape( $form->{department} );
  2190. $option .= "\n<br>" if ($option);
  2191. $option .= $locale->text('Department') . " : $form->{department}";
  2192. }
  2193. if ( $form->{description} ) {
  2194. $callback .= "&description=" . $form->escape( $form->{description}, 1 );
  2195. $href .= "&description=" . $form->escape( $form->{description} );
  2196. $option .= "\n<br>" if ($option);
  2197. $option .= $locale->text('Description') . " : $form->{description}";
  2198. }
  2199. if ( $form->{source} ) {
  2200. $callback .= "&source=" . $form->escape( $form->{source}, 1 );
  2201. $href .= "&source=" . $form->escape( $form->{source} );
  2202. $option .= "\n<br>" if ($option);
  2203. $option .= $locale->text('Source') . " : $form->{source}";
  2204. }
  2205. if ( $form->{memo} ) {
  2206. $callback .= "&memo=" . $form->escape( $form->{memo}, 1 );
  2207. $href .= "&memo=" . $form->escape( $form->{memo} );
  2208. $option .= "\n<br>" if ($option);
  2209. $option .= $locale->text('Memo') . " : $form->{memo}";
  2210. }
  2211. if ( $form->{fromdate} ) {
  2212. $option .= "\n<br>" if ($option);
  2213. $option .=
  2214. $locale->text('From') . "&nbsp;"
  2215. . $locale->date( \%myconfig, $form->{fromdate}, 1 );
  2216. }
  2217. if ( $form->{todate} ) {
  2218. $option .= "\n<br>" if ($option);
  2219. $option .=
  2220. $locale->text('To') . "&nbsp;"
  2221. . $locale->date( \%myconfig, $form->{todate}, 1 );
  2222. }
  2223. $callback = $form->escape( $form->{callback} );
  2224. $column_header{name} =
  2225. "<th><a class=listheading href=$href&sort=name>"
  2226. . $locale->text('Description')
  2227. . "</a></th>";
  2228. $column_header{transdate} =
  2229. "<th><a class=listheading href=$href&sort=transdate>"
  2230. . $locale->text('Date')
  2231. . "</a></th>";
  2232. $column_header{paid} =
  2233. "<th class=listheading>" . $locale->text('Amount') . "</a></th>";
  2234. $column_header{curr} =
  2235. "<th class=listheading>" . $locale->text('Curr') . "</a></th>";
  2236. $column_header{source} =
  2237. "<th><a class=listheading href=$href&sort=source>"
  2238. . $locale->text('Source')
  2239. . "</a></th>";
  2240. $column_header{memo} =
  2241. "<th><a class=listheading href=$href&sort=memo>"
  2242. . $locale->text('Memo')
  2243. . "</a></th>";
  2244. $column_header{employee} =
  2245. "<th><a class=listheading href=$href&sort=employee>"
  2246. . $locale->text('Salesperson')
  2247. . "</a></th>";
  2248. $column_header{till} =
  2249. "<th><a class=listheading href=$href&sort=till>"
  2250. . $locale->text('Till')
  2251. . "</a></th>";
  2252. @column_index = @columns;
  2253. $colspan = $#column_index + 1;
  2254. $form->header;
  2255. print qq|
  2256. <body>
  2257. <table width=100%>
  2258. <tr>
  2259. <th class=listtop>$form->{title}</th>
  2260. </tr>
  2261. <tr height="5"></tr>
  2262. <tr>
  2263. <td>$option</td>
  2264. </tr>
  2265. <tr>
  2266. <td>
  2267. <table width=100%>
  2268. <tr class=listheading>
  2269. |;
  2270. for (@column_index) { print "\n$column_header{$_}" }
  2271. print qq|
  2272. </tr>
  2273. |;
  2274. foreach $ref ( sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} } ) {
  2275. next unless @{ $form->{ $ref->{id} } };
  2276. print qq|
  2277. <tr>
  2278. <th colspan=$colspan align=left>$ref->{accno}--$ref->{description}</th>
  2279. </tr>
  2280. |;
  2281. if ( @{ $form->{ $ref->{id} } } ) {
  2282. $sameitem = $form->{ $ref->{id} }[0]->{ $form->{sort} };
  2283. }
  2284. foreach $payment ( @{ $form->{ $ref->{id} } } ) {
  2285. if ( $form->{l_subtotal} ) {
  2286. if ( $payment->{ $form->{sort} } ne $sameitem ) {
  2287. # print subtotal
  2288. &payment_subtotal;
  2289. }
  2290. }
  2291. next if ( $form->{till} && !$payment->{till} );
  2292. $column_data{name} = "<td>$payment->{name}&nbsp;</td>";
  2293. $column_data{transdate} = "<td>$payment->{transdate}&nbsp;</td>";
  2294. $column_data{paid} =
  2295. "<td align=right>"
  2296. . $form->format_amount( \%myconfig, $payment->{paid}, 2,
  2297. "&nbsp;" )
  2298. . "</td>";
  2299. $column_data{curr} = "<td>$payment->{curr}</td>";
  2300. $column_data{source} = "<td>$payment->{source}&nbsp;</td>";
  2301. $column_data{memo} = "<td>$payment->{memo}&nbsp;</td>";
  2302. $column_data{employee} = "<td>$payment->{employee}&nbsp;</td>";
  2303. $column_data{till} = "<td>$payment->{till}&nbsp;</td>";
  2304. $subtotalpaid += $payment->{paid};
  2305. $accounttotalpaid += $payment->{paid};
  2306. $totalpaid += $payment->{paid};
  2307. $i++;
  2308. $i %= 2;
  2309. print qq|
  2310. <tr class=listrow$i>
  2311. |;
  2312. for (@column_index) { print "\n$column_data{$_}" }
  2313. print qq|
  2314. </tr>
  2315. |;
  2316. $sameitem = $payment->{ $form->{sort} };
  2317. }
  2318. &payment_subtotal if $form->{l_subtotal};
  2319. # print account totals
  2320. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  2321. $column_data{paid} =
  2322. "<th class=listtotal align=right>"
  2323. . $form->format_amount( \%myconfig, $accounttotalpaid, 2, "&nbsp;" )
  2324. . "</th>";
  2325. print qq|
  2326. <tr class=listtotal>
  2327. |;
  2328. for (@column_index) { print "\n$column_data{$_}" }
  2329. print qq|
  2330. </tr>
  2331. |;
  2332. $accounttotalpaid = 0;
  2333. }
  2334. # print total
  2335. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  2336. $column_data{paid} =
  2337. "<th class=listtotal align=right>"
  2338. . $form->format_amount( \%myconfig, $totalpaid, 2, "&nbsp;" ) . "</th>";
  2339. print qq|
  2340. <tr class=listtotal>
  2341. |;
  2342. for (@column_index) { print "\n$column_data{$_}" }
  2343. print qq|
  2344. </tr>
  2345. </table>
  2346. </td>
  2347. </tr>
  2348. <tr>
  2349. <td><hr size=3 noshade></td>
  2350. </tr>
  2351. </table>
  2352. |;
  2353. if ( $form->{lynx} ) {
  2354. require "bin/menu.pl";
  2355. &menubar;
  2356. }
  2357. print qq|
  2358. </body>
  2359. </html>
  2360. |;
  2361. }
  2362. sub payment_subtotal {
  2363. if ( $subtotalpaid != 0 ) {
  2364. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  2365. $column_data{paid} =
  2366. "<th class=listsubtotal align=right>"
  2367. . $form->format_amount( \%myconfig, $subtotalpaid, 2, "&nbsp;" )
  2368. . "</th>";
  2369. print qq|
  2370. <tr class=listsubtotal>
  2371. |;
  2372. for (@column_index) { print "\n$column_data{$_}" }
  2373. print qq|
  2374. </tr>
  2375. |;
  2376. }
  2377. $subtotalpaid = 0;
  2378. }