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