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