erator' content='cgit v1.2.3'/>
summaryrefslogtreecommitdiff
path: root/bin/rp.pl
blob: d130859e6dc9822640bf378a58a82b04b9a47c66 (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});