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