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