summaryrefslogtreecommitdiff
path: root/bin/mozilla/gl.pl
blob: 9a83675a528090671b770fa3dc9eccdc5b3e86b1 (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:
  22. #
  23. #
  24. # Author: DWS Systems Inc.
  25. # Web: http://www.ledgersmb.org/
  26. #
  27. # Contributors:
  28. #
  29. # This program is free software; you can redistribute it and/or modify
  30. # it under the terms of the GNU General Public License as published by
  31. # the Free Software Foundation; either version 2 of the License, or
  32. # (at your option) any later version.
  33. #
  34. # This program is distributed in the hope that it will be useful,
  35. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  36. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  37. # GNU General Public License for more details.
  38. # You should have received a copy of the GNU General Public License
  39. # along with this program; if not, write to the Free Software
  40. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  41. #======================================================================
  42. #
  43. # Genereal Ledger
  44. #
  45. #======================================================================
  46. use LedgerSMB::GL;
  47. use LedgerSMB::PE;
  48. require "$form->{path}/arap.pl";
  49. 1;
  50. # end of main
  51. # this is for our long dates
  52. # $locale->text('January')
  53. # $locale->text('February')
  54. # $locale->text('March')
  55. # $locale->text('April')
  56. # $locale->text('May ')
  57. # $locale->text('June')
  58. # $locale->text('July')
  59. # $locale->text('August')
  60. # $locale->text('September')
  61. # $locale->text('October')
  62. # $locale->text('November')
  63. # $locale->text('December')
  64. # this is for our short month
  65. # $locale->text('Jan')
  66. # $locale->text('Feb')
  67. # $locale->text('Mar')
  68. # $locale->text('Apr')
  69. # $locale->text('May')
  70. # $locale->text('Jun')
  71. # $locale->text('Jul')
  72. # $locale->text('Aug')
  73. # $locale->text('Sep')
  74. # $locale->text('Oct')
  75. # $locale->text('Nov')
  76. # $locale->text('Dec')
  77. sub pos_adjust {
  78. $form->{rowcount} = 3;
  79. require "pos.conf.pl";
  80. $form->{accno_1} = $pos_config{'close_cash_accno'};
  81. $form->{accno_2} = $pos_config{'coa_prefix'};
  82. $form->{accno_3} = $pos_config{'coa_prefix'};
  83. }
  84. sub add_pos_adjust {
  85. $form->{pos_adjust} = 1;
  86. $form->{reference} = $locale->text("Adjusting Till: (till) Source: (source)");
  87. $form->{description} =
  88. $locale->text("Adjusting till due to data entry error.");
  89. $form->{callback} = "$form->{script}?action=add_pos_adjust&transfer=$form->{transfer}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};
  90. &add;
  91. }
  92. sub add {
  93. $form->{title} = "Add";
  94. $form->{callback} = "$form->{script}?action=add&transfer=$form->{transfer}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};
  95. &create_links;
  96. $form->{rowcount} = ($form->{transfer}) ? 3 : 9;
  97. if ($form->{pos_adjust}){
  98. &pos_adjust;
  99. }
  100. $form->{oldtransdate} = $form->{transdate};
  101. $form->{focus} = "reference";
  102. # departments
  103. if (@{ $form->{all_department} }) {
  104. $form->{selectdepartment} = "<option>\n";
  105. for (@{ $form->{all_department} }) { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
  106. }
  107. &display_form(1);
  108. }
  109. sub edit {
  110. &create_links;
  111. $form->{locked} = ($form->{revtrans}) ? '1' : ($form->datetonum(\%myconfig, $form->{transdate}) <= $form->datetonum(\%myconfig, $form->{closedto}));
  112. # readonly
  113. if (! $form->{readonly}) {
  114. $form->{readonly} = 1 if $myconfig{acs} =~ /General Ledger--Add Transaction/;
  115. }
  116. $form->{title} = "Edit";
  117. $i = 1;
  118. foreach $ref (@{ $form->{GL} }) {
  119. $form->{"accno_$i"} = "$ref->{accno}--$ref->{description}";
  120. $form->{"projectnumber_$i"} = "$ref->{projectnumber}--$ref->{project_id}";
  121. for (qw(fx_transaction source memo)) { $form->{"${_}_$i"} = $ref->{$_} }
  122. if ($ref->{amount} < 0) {
  123. $form->{totaldebit} -= $ref->{amount};
  124. $form->{"debit_$i"} = $ref->{amount} * -1;
  125. } else {
  126. $form->{totalcredit} += $ref->{amount};
  127. $form->{"credit_$i"} = $ref->{amount};
  128. }
  129. $i++;
  130. }
  131. $form->{rowcount} = $i;
  132. $form->{focus} = "debit_$i";
  133. &form_header;
  134. &display_rows;
  135. &form_footer;
  136. }
  137. sub create_links {
  138. GL->transaction(\%myconfig, \%$form);
  139. for (@{ $form->{all_accno} }) { $form->{selectaccno} .= "<option>$_->{accno}--$_->{description}\n" }
  140. # projects
  141. if (@{ $form->{all_project} }) {
  142. $form->{selectprojectnumber} = "<option>\n";
  143. for (@{ $form->{all_project} }) { $form->{selectprojectnumber} .= qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n| }
  144. }
  145. # departments
  146. if (@{ $form->{all_department} }) {
  147. $form->{department} = "$form->{department}--$form->{department_id}";
  148. $form->{selectdepartment} = "<option>\n";
  149. for (@{ $form->{all_department} }) { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
  150. }
  151. }
  152. sub search {
  153. $form->{title} = $locale->text('General Ledger')." ".$locale->text('Reports');
  154. $colspan = 5;
  155. $form->all_departments(\%myconfig);
  156. # departments
  157. if (@{ $form->{all_department} }) {
  158. $form->{selectdepartment} = "<option>\n";
  159. for (@{ $form->{all_department} }) { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
  160. $l_department = qq|<input name="l_department" class=checkbox type=checkbox value=Y> |.$locale->text('Department');
  161. $department = qq|
  162. <tr>
  163. <th align=right nowrap>|.$locale->text('Department').qq|</th>
  164. <td colspan=$colspan><select name=department>$form->{selectdepartment}</select></td>
  165. </tr>
  166. |;
  167. }
  168. if (@{ $form->{all_years} }) {
  169. # accounting years
  170. $form->{selectaccountingyear} = "<option>\n";
  171. for (@{ $form->{all_years} }) { $form->{selectaccountingyear} .= qq|<option>$_\n| }
  172. $form->{selectaccountingmonth} = "<option>\n";
  173. for (sort keys %{ $form->{all_month} }) { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n| }
  174. $selectfrom = qq|
  175. <tr>
  176. <th align=right>|.$locale->text('Period').qq|</th>
  177. <td colspan=$colspan>
  178. <select name=month>$form->{selectaccountingmonth}</select>
  179. <select name=year>$form->{selectaccountingyear}</select>
  180. <input name=interval class=radio type=radio value=0 checked>&nbsp;|.$locale->text('Current').qq|
  181. <input name=interval class=radio type=radio value=1>&nbsp;|.$locale->text('Month').qq|
  182. <input name=interval class=radio type=radio value=3>&nbsp;|.$locale->text('Quarter').qq|
  183. <input name=interval class=radio type=radio value=12>&nbsp;|.$locale->text('Year').qq|
  184. </td>
  185. </tr>
  186. |;
  187. }
  188. @a = ();
  189. push @a, qq|<input name="l_id" class=checkbox type=checkbox value=Y> |.$locale->text('ID');
  190. push @a, qq|<input name="l_transdate" class=checkbox type=checkbox value=Y checked> |.$locale->text('Date');
  191. push @a, qq|<input name="l_reference" class=checkbox type=checkbox value=Y checked> |.$locale->text('Reference');
  192. push @a, qq|<input name="l_description" class=checkbox type=checkbox value=Y checked> |.$locale->text('Description');
  193. push @a, qq|<input name="l_notes" class=checkbox type=checkbox value=Y> |.$locale->text('Notes');
  194. push @a, $l_department if $l_department;
  195. push @a, qq|<input name="l_debit" class=checkbox type=checkbox value=Y checked> |.$locale->text('Debit');
  196. push @a, qq|<input name="l_credit" class=checkbox type=checkbox value=Y checked> |.$locale->text('Credit');
  197. push @a, qq|<input name="l_source" class=checkbox type=checkbox value=Y checked> |.$locale->text('Source');
  198. push @a, qq|<input name="l_memo" class=checkbox type=checkbox value=Y> |.$locale->text('Memo');
  199. push @a, qq|<input name="l_accno" class=checkbox type=checkbox value=Y checked> |.$locale->text('Account');
  200. push @a, qq|<input name="l_gifi_accno" class=checkbox type=checkbox value=Y> |.$locale->text('GIFI');
  201. $form->header;
  202. print qq|
  203. <body>
  204. <form method=post action=$form->{script}>
  205. <input type=hidden name=sort value=transdate>
  206. <table width=100%>
  207. <tr>
  208. <th class=listtop>$form->{title}</th>
  209. </tr>
  210. <tr height="5"></tr>
  211. <tr>
  212. <td>
  213. <table>
  214. <tr>
  215. <th align=right>|.$locale->text('Reference').qq|</th>
  216. <td><input name=reference size=20></td>
  217. </tr>
  218. <tr>
  219. <th align=right>|.$locale->text('Source').qq|</th>
  220. <td><input name=source size=20></td>
  221. <th align=right>|.$locale->text('Memo').qq|</th>
  222. <td><input name=memo size=20></td>
  223. </tr>
  224. $department
  225. <tr>
  226. <th align=right>|.$locale->text('Description').qq|</th>
  227. <td colspan=$colspan><input name=description size=60></td>
  228. </tr>
  229. <tr>
  230. <th align=right>|.$locale->text('Notes').qq|</th>
  231. <td colspan=$colspan><input name=notes size=60></td>
  232. </tr>
  233. <tr>
  234. <th align=right>|.$locale->text('From').qq|</th>
  235. <td><input name=datefrom size=11 title="$myconfig{dateformat}"></td>
  236. <th align=right>|.$locale->text('To').qq|</th>
  237. <td><input name=dateto size=11 title="$myconfig{dateformat}"></td>
  238. </tr>
  239. $selectfrom
  240. <tr>
  241. <th align=right>|.$locale->text('Amount').qq| >=</th>
  242. <td><input name=amountfrom size=11></td>
  243. <th align=right>|.$locale->text('Amount').qq| <=</th>
  244. <td><input name=amountto size=11></td>
  245. </tr>
  246. <tr>
  247. <th align=right>|.$locale->text('Include in Report').qq|</th>
  248. <td colspan=$colspan>
  249. <table>
  250. <tr>
  251. <td>
  252. <input name="category" class=radio type=radio value=X checked>&nbsp;|.$locale->text('All').qq|
  253. <input name="category" class=radio type=radio value=A>&nbsp;|.$locale->text('Asset').qq|
  254. <input name="category" class=radio type=radio value=L>&nbsp;|.$locale->text('Liability').qq|
  255. <input name="category" class=radio type=radio value=Q>&nbsp;|.$locale->text('Equity').qq|
  256. <input name="category" class=radio type=radio value=I>&nbsp;|.$locale->text('Income').qq|
  257. <input name="category" class=radio type=radio value=E>&nbsp;|.$locale->text('Expense').qq|
  258. </td>
  259. </tr>
  260. <tr>
  261. <table>
  262. |;
  263. while (@a) {
  264. print qq|<tr>\n|;
  265. for (1 .. 5) {
  266. print qq|<td nowrap>|. shift @a;
  267. print qq|</td>\n|;
  268. }
  269. print qq|</tr>\n|;
  270. }
  271. print qq|
  272. <tr>
  273. <td nowrap><input name="l_subtotal" class=checkbox type=checkbox value=Y> |.$locale->text('Subtotal').qq|</td>
  274. </tr>
  275. </table>
  276. </tr>
  277. </table>
  278. </tr>
  279. </table>
  280. </td>
  281. </tr>
  282. <tr>
  283. <td><hr size=3 noshade></td>
  284. </tr>
  285. </table>
  286. <input type=hidden name=nextsub value=generate_report>
  287. |;
  288. $form->hide_form(qw(path login sessionid));
  289. print qq|
  290. <br>
  291. <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
  292. </form>
  293. |;
  294. if ($form->{menubar}) {
  295. require "$form->{path}/menu.pl";
  296. &menubar;
  297. }
  298. print qq|
  299. </body>
  300. </html>
  301. |;
  302. }
  303. sub generate_report {
  304. $form->{sort} = "transdate" unless $form->{sort};
  305. GL->all_transactions(\%myconfig, \%$form);
  306. $href = "$form->{script}?action=generate_report&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  307. $form->sort_order();
  308. $callback = "$form->{script}?action=generate_report&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  309. %acctype = ( 'A' => $locale->text('Asset'),
  310. 'L' => $locale->text('Liability'),
  311. 'Q' => $locale->text('Equity'),
  312. 'I' => $locale->text('Income'),
  313. 'E' => $locale->text('Expense'),
  314. );
  315. $form->{title} = $locale->text('General Ledger');
  316. $ml = ($form->{category} =~ /(A|E)/) ? -1 : 1;
  317. unless ($form->{category} eq 'X') {
  318. $form->{title} .= " : ".$locale->text($acctype{$form->{category}});
  319. }
  320. if ($form->{accno}) {
  321. $href .= "&accno=".$form->escape($form->{accno});
  322. $callback .= "&accno=".$form->escape($form->{accno},1);
  323. $option = $locale->text('Account')." : $form->{accno} $form->{account_description}";
  324. }
  325. if ($form->{gifi_accno}) {
  326. $href .= "&gifi_accno=".$form->escape($form->{gifi_accno});
  327. $callback .= "&gifi_accno=".$form->escape($form->{gifi_accno},1);
  328. $option .= "\n<br>" if $option;
  329. $option .= $locale->text('GIFI')." : $form->{gifi_accno} $form->{gifi_account_description}";
  330. }
  331. if ($form->{source}) {
  332. $href .= "&source=".$form->escape($form->{source});
  333. $callback .= "&source=".$form->escape($form->{source},1);
  334. $option .= "\n<br>" if $option;
  335. $option .= $locale->text('Source')." : $form->{source}";
  336. }
  337. if ($form->{memo}) {
  338. $href .= "&memo=".$form->escape($form->{memo});
  339. $callback .= "&memo=".$form->escape($form->{memo},1);
  340. $option .= "\n<br>" if $option;
  341. $option .= $locale->text('Memo')." : $form->{memo}";
  342. }
  343. if ($form->{reference}) {
  344. $href .= "&reference=".$form->escape($form->{reference});
  345. $callback .= "&reference=".$form->escape($form->{reference},1);
  346. $option .= "\n<br>" if $option;
  347. $option .= $locale->text('Reference')." : $form->{reference}";
  348. }
  349. if ($form->{department}) {
  350. $href .= "&department=".$form->escape($form->{department});
  351. $callback .= "&department=".$form->escape($form->{department},1);
  352. ($department) = split /--/, $form->{department};
  353. $option .= "\n<br>" if $option;
  354. $option .= $locale->text('Department')." : $department";
  355. }
  356. if ($form->{description}) {
  357. $href .= "&description=".$form->escape($form->{description});
  358. $callback .= "&description=".$form->escape($form->{description},1);
  359. $option .= "\n<br>" if $option;
  360. $option .= $locale->text('Description')." : $form->{description}";
  361. }
  362. if ($form->{notes}) {
  363. $href .= "&notes=".$form->escape($form->{notes});
  364. $callback .= "&notes=".$form->escape($form->{notes},1);
  365. $option .= "\n<br>" if $option;
  366. $option .= $locale->text('Notes')." : $form->{notes}";
  367. }
  368. if ($form->{datefrom}) {
  369. $href .= "&datefrom=$form->{datefrom}";
  370. $callback .= "&datefrom=$form->{datefrom}";
  371. $option .= "\n<br>" if $option;
  372. $option .= $locale->text('From')." ".$locale->date(\%myconfig, $form->{datefrom}, 1);
  373. }
  374. if ($form->{dateto}) {
  375. $href .= "&dateto=$form->{dateto}";
  376. $callback .= "&dateto=$form->{dateto}";
  377. if ($form->{datefrom}) {
  378. $option .= " ";
  379. } else {
  380. $option .= "\n<br>" if $option;
  381. }
  382. $option .= $locale->text('To')." ".$locale->date(\%myconfig, $form->{dateto}, 1);
  383. }
  384. if ($form->{amountfrom}) {
  385. $href .= "&amountfrom=$form->{amountfrom}";
  386. $callback .= "&amountfrom=$form->{amountfrom}";
  387. $option .= "\n<br>" if $option;
  388. $option .= $locale->text('Amount')." >= ".$form->format_amount(\%myconfig, $form->{amountfrom}, 2);
  389. }
  390. if ($form->{amountto}) {
  391. $href .= "&amountto=$form->{amountto}";
  392. $callback .= "&amountto=$form->{amountto}";
  393. if ($form->{amountfrom}) {
  394. $option .= " <= ";
  395. } else {
  396. $option .= "\n<br>" if $option;
  397. $option .= $locale->text('Amount')." <= ";
  398. }
  399. $option .= $form->format_amount(\%myconfig, $form->{amountto}, 2);
  400. }
  401. @columns = $form->sort_columns(qw(transdate id reference description notes source memo debit credit accno gifi_accno department));
  402. pop @columns if $form->{department};
  403. if ($form->{link} =~ /_paid/) {
  404. @columns = $form->sort_columns(qw(transdate id reference description notes source memo cleared debit credit accno gifi_accno));
  405. $form->{l_cleared} = "Y";
  406. }
  407. if ($form->{accno} || $form->{gifi_accno}) {
  408. @columns = grep !/(accno|gifi_accno)/, @columns;
  409. push @columns, "balance";
  410. $form->{l_balance} = "Y";
  411. }
  412. foreach $item (@columns) {
  413. if ($form->{"l_$item"} eq "Y") {
  414. push @column_index, $item;
  415. # add column to href and callback
  416. $callback .= "&l_$item=Y";
  417. $href .= "&l_$item=Y";
  418. }
  419. }
  420. if ($form->{l_subtotal} eq 'Y') {
  421. $callback .= "&l_subtotal=Y";
  422. $href .= "&l_subtotal=Y";
  423. }
  424. $callback .= "&category=$form->{category}";
  425. $href .= "&category=$form->{category}";
  426. $column_header{id} = "<th><a class=listheading href=$href&sort=id>".$locale->text('ID')."</a></th>";
  427. $column_header{transdate} = "<th><a class=listheading href=$href&sort=transdate>".$locale->text('Date')."</a></th>";
  428. $column_header{reference} = "<th><a class=listheading href=$href&sort=reference>".$locale->text('Reference')."</a></th>";
  429. $column_header{source} = "<th><a class=listheading href=$href&sort=source>".$locale->text('Source')."</a></th>";
  430. $column_header{memo} = "<th><a class=listheading href=$href&sort=memo>".$locale->text('Memo')."</a></th>";
  431. $column_header{description} = "<th><a class=listheading href=$href&sort=description>".$locale->text('Description')."</a></th>";
  432. $column_header{department} = "<th><a class=listheading href=$href&sort=department>".$locale->text('Department')."</a></th>";
  433. $column_header{notes} = "<th class=listheading>".$locale->text('Notes')."</th>";
  434. $column_header{debit} = "<th class=listheading>".$locale->text('Debit')."</th>";
  435. $column_header{credit} = "<th class=listheading>".$locale->text('Credit')."</th>";
  436. $column_header{accno} = "<th><a class=listheading href=$href&sort=accno>".$locale->text('Account')."</a></th>";
  437. $column_header{gifi_accno} = "<th><a class=listheading href=$href&sort=gifi_accno>".$locale->text('GIFI')."</a></th>";
  438. $column_header{balance} = "<th>".$locale->text('Balance')."</th>";
  439. $column_header{cleared} = qq|<th>|.$locale->text('R').qq|</th>|;
  440. $form->header;
  441. print qq|
  442. <body>
  443. <table width=100%>
  444. <tr>
  445. <th class=listtop>$form->{title}</th>
  446. </tr>
  447. <tr height="5"></tr>
  448. <tr>
  449. <td>$option</td>
  450. </tr>
  451. <tr>
  452. <td>
  453. <table width=100%>
  454. <tr class=listheading>
  455. |;
  456. for (@column_index) { print "$column_header{$_}\n" }
  457. print "
  458. </tr>
  459. ";
  460. # add sort to callback
  461. $form->{callback} = "$callback&sort=$form->{sort}";
  462. $callback = $form->escape($form->{callback});
  463. $cml = 1;
  464. # initial item for subtotals
  465. if (@{ $form->{GL} }) {
  466. $sameitem = $form->{GL}->[0]->{$form->{sort}};
  467. $cml = -1 if $form->{contra};
  468. }
  469. if (($form->{accno} || $form->{gifi_accno}) && $form->{balance}) {
  470. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  471. $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $form->{balance} * $ml * $cml, 2, 0)."</td>";
  472. $i++; $i %= 2;
  473. print qq|
  474. <tr class=listrow$i>
  475. |;
  476. for (@column_index) { print "$column_data{$_}\n" }
  477. print qq|
  478. </tr>
  479. |;
  480. }
  481. # reverse href
  482. $direction = ($form->{direction} eq 'ASC') ? "ASC" : "DESC";
  483. $form->sort_order();
  484. $href =~ s/direction=$form->{direction}/direction=$direction/;
  485. $i = 0;
  486. foreach $ref (@{ $form->{GL} }) {
  487. # if item ne sort print subtotal
  488. if ($form->{l_subtotal} eq 'Y') {
  489. if ($sameitem ne $ref->{$form->{sort}}) {
  490. &gl_subtotal;
  491. }
  492. }
  493. $form->{balance} += $ref->{amount};
  494. $subtotaldebit += $ref->{debit};
  495. $subtotalcredit += $ref->{credit};
  496. $totaldebit += $ref->{debit};
  497. $totalcredit += $ref->{credit};
  498. $ref->{debit} = $form->format_amount(\%myconfig, $ref->{debit}, 2, "&nbsp;");
  499. $ref->{credit} = $form->format_amount(\%myconfig, $ref->{credit}, 2, "&nbsp;");
  500. for (qw(id transdate)) { $column_data{$_} = "<td>$ref->{$_}</td>" }
  501. $column_data{reference} = "<td><a href=$ref->{module}.pl?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{reference}</td>";
  502. $ref->{notes} =~ s/\r?\n/<br>/g;
  503. for (qw(description source memo notes department)) { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
  504. $column_data{debit} = "<td align=right>$ref->{debit}</td>";
  505. $column_data{credit} = "<td align=right>$ref->{credit}</td>";
  506. $column_data{accno} = "<td><a href=$href&accno=$ref->{accno}&callback=$callback>$ref->{accno}</a></td>";
  507. $column_data{gifi_accno} = "<td><a href=$href&gifi_accno=$ref->{gifi_accno}&callback=$callback>$ref->{gifi_accno}</a>&nbsp;</td>";
  508. $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $form->{balance} * $ml * $cml, 2, 0)."</td>";
  509. $column_data{cleared} = ($ref->{cleared}) ? "<td>*</td>" : "<td>&nbsp;</td>";
  510. if ($ref->{id} != $sameid) {
  511. $i++; $i %= 2;
  512. }
  513. print "
  514. <tr class=listrow$i>";
  515. for (@column_index) { print "$column_data{$_}\n" }
  516. print "</tr>";
  517. $sameid = $ref->{id};
  518. }
  519. &gl_subtotal if ($form->{l_subtotal} eq 'Y');
  520. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  521. $column_data{debit} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $totaldebit, 2, "&nbsp;")."</th>";
  522. $column_data{credit} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $totalcredit, 2, "&nbsp;")."</th>";
  523. $column_data{balance} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $form->{balance} * $ml * $cml, 2, 0)."</th>";
  524. print qq|
  525. <tr class=listtotal>
  526. |;
  527. for (@column_index) { print "$column_data{$_}\n" }
  528. $i = 1;
  529. if ($myconfig{acs} !~ /General Ledger--General Ledger/) {
  530. $button{'General Ledger--Add Transaction'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('GL Transaction').qq|"> |;
  531. $button{'General Ledger--Add Transaction'}{order} = $i++;
  532. }
  533. if ($myconfig{acs} !~ /AR--AR/) {
  534. $button{'AR--Add Transaction'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('AR Transaction').qq|"> |;
  535. $button{'AR--Add Transaction'}{order} = $i++;
  536. $button{'AR--Sales Invoice'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Sales Invoice ').qq|"> |;
  537. $button{'AR--Sales Invoice'}{order} = $i++;
  538. }
  539. if ($myconfig{acs} !~ /AP--AP/) {
  540. $button{'AP--Add Transaction'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('AP Transaction').qq|"> |;
  541. $button{'AP--Add Transaction'}{order} = $i++;
  542. $button{'AP--Vendor Invoice'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Vendor Invoice ').qq|"> |;
  543. $button{'AP--Vendor Invoice'}{order} = $i++;
  544. }
  545. foreach $item (split /;/, $myconfig{acs}) {
  546. delete $button{$item};
  547. }
  548. print qq|
  549. </tr>
  550. </table>
  551. </td>
  552. </tr>
  553. <tr>
  554. <td><hr size=3 noshade></td>
  555. </tr>
  556. </table>
  557. <br>
  558. <form method=post action=$form->{script}>
  559. |;
  560. $form->hide_form(qw(callback path login sessionid));
  561. foreach $item (sort { $a->{order} <=> $b->{order} } %button) {
  562. print $item->{code};
  563. }
  564. if ($form->{menubar}) {
  565. require "$form->{path}/menu.pl";
  566. &menubar;
  567. }
  568. print qq|
  569. </form>
  570. </body>
  571. </html>
  572. |;
  573. }
  574. sub gl_subtotal {
  575. $subtotaldebit = $form->format_amount(\%myconfig, $subtotaldebit, 2, "&nbsp;");
  576. $subtotalcredit = $form->format_amount(\%myconfig, $subtotalcredit, 2, "&nbsp;");
  577. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  578. $column_data{debit} = "<th align=right class=listsubtotal>$subtotaldebit</td>";
  579. $column_data{credit} = "<th align=right class=listsubtotal>$subtotalcredit</td>";
  580. print "<tr class=listsubtotal>";
  581. for (@column_index) { print "$column_data{$_}\n" }
  582. print "</tr>";
  583. $subtotaldebit = 0;
  584. $subtotalcredit = 0;
  585. $sameitem = $ref->{$form->{sort}};
  586. }
  587. sub update {
  588. if ($form->{transdate} ne $form->{oldtransdate}) {
  589. if ($form->{selectprojectnumber}) {
  590. $form->all_projects(\%myconfig, undef, $form->{transdate});
  591. if (@{ $form->{all_project} }) {
  592. $form->{selectprojectnumber} = "<option>\n";
  593. for (@{ $form->{all_project} }) { $form->{selectprojectnumber} .= qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n| }
  594. $form->{selectprojectnumber} = $form->escape($form->{selectprojectnumber},1);
  595. }
  596. }
  597. $form->{oldtransdate} = $form->{transdate};
  598. }
  599. @a = ();
  600. $count = 0;
  601. @flds = qw(accno debit credit projectnumber fx_transaction source memo);
  602. for $i (1 .. $form->{rowcount}) {
  603. unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) {
  604. for (qw(debit credit)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
  605. push @a, {};
  606. $j = $#a;
  607. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  608. $count++;
  609. }
  610. }
  611. for $i (1 .. $count) {
  612. $j = $i - 1;
  613. for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
  614. }
  615. for $i ($count + 1 .. $form->{rowcount}) {
  616. for (@flds) { delete $form->{"${_}_$i"} }
  617. }
  618. $form->{rowcount} = $count + 1;
  619. &display_form;
  620. }
  621. sub display_form {
  622. my ($init) = @_;
  623. &form_header;
  624. &display_rows($init);
  625. &form_footer;
  626. }
  627. sub display_rows {
  628. my ($init) = @_;
  629. $form->{selectprojectnumber} = $form->unescape($form->{selectprojectnumber}) if $form->{selectprojectnumber};
  630. $form->{totaldebit} = 0;
  631. $form->{totalcredit} = 0;
  632. for $i (1 .. $form->{rowcount}) {
  633. $source = qq|
  634. <td><input name="source_$i" size=10 value="$form->{"source_$i"}"></td>|;
  635. $memo = qq|
  636. <td><input name="memo_$i" value="$form->{"memo_$i"}"></td>|;
  637. if ($init) {
  638. $accno = qq|
  639. <td><select name="accno_$i">$form->{selectaccno}</select></td>|;
  640. if ($form->{selectprojectnumber}) {
  641. $project = qq|
  642. <td><select name="projectnumber_$i">$form->{selectprojectnumber}</select></td>|;
  643. }
  644. if ($form->{transfer}) {
  645. $fx_transaction = qq|
  646. <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
  647. |;
  648. }
  649. } else {
  650. $form->{totaldebit} += $form->{"debit_$i"};
  651. $form->{totalcredit} += $form->{"credit_$i"};
  652. for (qw(debit credit)) { $form->{"${_}_$i"} = ($form->{"${_}_$i"}) ? $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) : "" }
  653. if ($i < $form->{rowcount}) {
  654. $accno = qq|<td>$form->{"accno_$i"}</td>|;
  655. if ($form->{selectprojectnumber}) {
  656. $form->{"projectnumber_$i"} = "" if $form->{selectprojectnumber} !~ /$form->{"projectnumber_$i"}/;
  657. $project = $form->{"projectnumber_$i"};
  658. $project =~ s/--.*//;
  659. $project = qq|<td>$project</td>|;
  660. }
  661. if ($form->{transfer}) {
  662. $checked = ($form->{"fx_transaction_$i"}) ? "1" : "";
  663. $x = ($checked) ? "x" : "";
  664. $fx_transaction = qq|
  665. <td><input type=hidden name="fx_transaction_$i" value="$checked">$x</td>
  666. |;
  667. }
  668. $form->hide_form("accno_$i", "projectnumber_$i");
  669. } else {
  670. $accno = qq|
  671. <td><select name="accno_$i">$form->{selectaccno}</select></td>|;
  672. if ($form->{selectprojectnumber}) {
  673. $project = qq|
  674. <td><select name="projectnumber_$i">$form->{selectprojectnumber}</select></td>|;
  675. }
  676. if ($form->{transfer}) {
  677. $fx_transaction = qq|
  678. <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
  679. |;
  680. }
  681. }
  682. }
  683. print qq|<tr valign=top>
  684. $accno
  685. $fx_transaction
  686. <td><input name="debit_$i" size=12 value="$form->{"debit_$i"}" accesskey=$i></td>
  687. <td><input name="credit_$i" size=12 value=$form->{"credit_$i"}></td>
  688. $source
  689. $memo
  690. $project
  691. </tr>
  692. |;
  693. }
  694. $form->hide_form(qw(rowcount selectaccno pos_adjust));
  695. print qq|
  696. <input type=hidden name=selectprojectnumber value="|.$form->escape($form->{selectprojectnumber},1).qq|">|;
  697. }
  698. sub form_header {
  699. $title = $form->{title};
  700. if ($form->{transfer}) {
  701. $form->{title} = $locale->text("$title Cash Transfer Transaction");
  702. } else {
  703. $form->{title} = $locale->text("$title General Ledger Transaction");
  704. }
  705. # $locale->text('Add Cash Transfer Transaction')
  706. # $locale->text('Edit Cash Transfer Transaction')
  707. # $locale->text('Add General Ledger Transaction')
  708. # $locale->text('Edit General Ledger Transaction')
  709. $form->{selectdepartment} = $form->unescape($form->{selectdepartment});
  710. $form->{selectdepartment} =~ s/ selected//;
  711. $form->{selectdepartment} =~ s/(<option value="\Q$form->{department}\E")/$1 selected/;
  712. for (qw(reference description notes)) { $form->{$_} = $form->quote($form->{$_}) }
  713. if (($rows = $form->numtextrows($form->{description}, 50)) > 1) {
  714. $description = qq|<textarea name=description rows=$rows cols=50 wrap=soft>$form->{description}</textarea>|;
  715. } else {
  716. $description = qq|<input name=description size=50 value="$form->{description}">|;
  717. }
  718. if (($rows = $form->numtextrows($form->{notes}, 50)) > 1) {
  719. $notes = qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|;
  720. } else {
  721. $notes = qq|<input name=notes size=50 value="$form->{notes}">|;
  722. }
  723. $department = qq|
  724. <tr>
  725. <th align=right nowrap>|.$locale->text('Department').qq|</th>
  726. <td><select name=department>$form->{selectdepartment}</select></td>
  727. <input type=hidden name=selectdepartment value="|.$form->escape($form->{selectdepartment},1).qq|">
  728. </tr>
  729. | if $form->{selectdepartment};
  730. $project = qq|
  731. <th class=listheading>|.$locale->text('Project').qq|</th>
  732. | if $form->{selectprojectnumber};
  733. if ($form->{transfer}) {
  734. $fx_transaction = qq|
  735. <th class=listheading>|.$locale->text('FX').qq|</th>
  736. |;
  737. }
  738. $focus = ($form->{focus}) ? $form->{focus} : "debit_$form->{rowcount}";
  739. $form->header;
  740. print qq|
  741. <body onload="document.forms[0].${focus}.focus()" />
  742. <form method=post action=$form->{script}>
  743. |;
  744. $form->hide_form(qw(id transfer selectaccno closedto locked oldtransdate recurring));
  745. print qq|
  746. <input type=hidden name=title value="$title">
  747. <table width=100%>
  748. <tr>
  749. <th class=listtop>$form->{title}</th>
  750. </tr>
  751. <tr height="5"></tr>
  752. <tr>
  753. <td>
  754. <table>
  755. <tr>
  756. <th align=right>|.$locale->text('Reference').qq|</th>
  757. <td><input name=reference size=20 value="$form->{reference}"></td>
  758. <th align=right>|.$locale->text('Date').qq|</th>
  759. <td><input name=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>
  760. </tr>
  761. $department
  762. <tr>
  763. <th align=right>|.$locale->text('Description').qq|</th>
  764. <td colspan=3>$description</td>
  765. </tr>
  766. <tr>
  767. <th align=right>|.$locale->text('Notes').qq|</th>
  768. <td colspan=3>$notes</td>
  769. </tr>
  770. </table>
  771. </td>
  772. </tr>
  773. <tr>
  774. <td>
  775. <table width=100%>
  776. <tr class=listheading>
  777. <th class=listheading>|.$locale->text('Account').qq|</th>
  778. $fx_transaction
  779. <th class=listheading>|.$locale->text('Debit').qq|</th>
  780. <th class=listheading>|.$locale->text('Credit').qq|</th>
  781. <th class=listheading>|.$locale->text('Source').qq|</th>
  782. <th class=listheading>|.$locale->text('Memo').qq|</th>
  783. $project
  784. </tr>
  785. |;
  786. }
  787. sub form_footer {
  788. for (qw(totaldebit totalcredit)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 2, "&nbsp;") }
  789. $project = qq|
  790. <th>&nbsp;</th>
  791. | if $form->{selectprojectnumber};
  792. if ($form->{transfer}) {
  793. $fx_transaction = qq|
  794. <th>&nbsp;</th>
  795. |;
  796. }
  797. print qq|
  798. <tr class=listtotal>
  799. <th>&nbsp;</th>
  800. $fx_transaction
  801. <th class=listtotal align=right>$form->{totaldebit}</th>
  802. <th class=listtotal align=right>$form->{totalcredit}</th>
  803. <th>&nbsp;</th>
  804. <th>&nbsp;</th>
  805. $project
  806. </tr>
  807. </table>
  808. </td>
  809. </tr>
  810. <tr>
  811. <td><hr size=3 noshade></td>
  812. </tr>
  813. </table>
  814. |;
  815. $form->hide_form(qw(path login sessionid callback));
  816. $transdate = $form->datetonum(\%myconfig, $form->{transdate});
  817. $closedto = $form->datetonum(\%myconfig, $form->{closedto});
  818. # type=submit $locale->text('Update')
  819. # type=submit $locale->text('Post')
  820. # type=submit $locale->text('Schedule')
  821. # type=submit $locale->text('Post as new')
  822. # type=submit $locale->text('Delete')
  823. if (! $form->{readonly}) {
  824. %button = ('Update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
  825. 'Post' => { ndx => 3, key => 'O', value => $locale->text('Post') },
  826. 'Post as new' => { ndx => 6, key => 'N', value => $locale->text('Post as new') },
  827. 'Schedule' => { ndx => 7, key => 'H', value => $locale->text('Schedule') },
  828. 'Delete' => { ndx => 8, key => 'D', value => $locale->text('Delete') },
  829. );
  830. %a = ();
  831. if ($form->{id}) {
  832. for ('Update', 'Post as new', 'Schedule') { $a{$_} = 1 }
  833. if (! $form->{locked}) {
  834. if ($transdate > $closedto) {
  835. for ('Post', 'Delete') { $a{$_} = 1 }
  836. }
  837. }
  838. } else {
  839. if ($transdate > $closedto) {
  840. for ("Update", "Post", "Schedule") { $a{$_} = 1 }
  841. }
  842. }
  843. for (keys %button) { delete $button{$_} if ! $a{$_} }
  844. for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
  845. }
  846. if ($form->{recurring}) {
  847. print qq|<div align=right>|.$locale->text('Scheduled').qq|</div>|;
  848. }
  849. if ($form->{menubar}) {
  850. require "$form->{path}/menu.pl";
  851. &menubar;
  852. }
  853. print qq|
  854. </form>
  855. </body>
  856. </html>
  857. |;
  858. }
  859. sub delete {
  860. $form->header;
  861. print qq|
  862. <body>
  863. <form method=post action=$form->{script}>
  864. |;
  865. delete $form->{action};
  866. $form->hide_form;
  867. print qq|
  868. <h2 class=confirm>|.$locale->text('Confirm!').qq|</h2>
  869. <h4>|.$locale->text('Are you sure you want to delete Transaction').qq| $form->{reference}</h4>
  870. <input name=action class=submit type=submit value="|.$locale->text('Yes').qq|">
  871. </form>
  872. |;
  873. }
  874. sub yes {
  875. if (GL->delete_transaction(\%myconfig, \%$form)) {
  876. $form->redirect($locale->text('Transaction deleted!'));
  877. } else {
  878. $form->error($locale->text('Cannot delete transaction!'));
  879. }
  880. }
  881. sub post {
  882. $form->isblank("transdate", $locale->text('Transaction Date missing!'));
  883. $transdate = $form->datetonum(\%myconfig, $form->{transdate});
  884. $closedto = $form->datetonum(\%myconfig, $form->{closedto});
  885. $form->error($locale->text('Cannot post transaction for a closed period!')) if ($transdate <= $closedto);
  886. # add up debits and credits
  887. for $i (1 .. $form->{rowcount}) {
  888. $dr = $form->parse_amount(\%myconfig, $form->{"debit_$i"});
  889. $cr = $form->parse_amount(\%myconfig, $form->{"credit_$i"});
  890. if ($dr && $cr) {
  891. $form->error($locale->text('Cannot post transaction with a debit and credit entry for the same account!'));
  892. }
  893. $debit += $dr;
  894. $credit += $cr;
  895. }
  896. if ($form->round_amount($debit, 2) != $form->round_amount($credit, 2)) {
  897. $form->error($locale->text('Out of balance transaction!'));
  898. }
  899. if (! $form->{repost}) {
  900. if ($form->{id}) {
  901. &repost;
  902. exit;
  903. }
  904. }
  905. if (GL->post_transaction(\%myconfig, \%$form)) {
  906. $form->redirect($locale->text('Transaction posted!'));
  907. } else {
  908. $form->error($locale->text('Cannot post transaction!'));
  909. }
  910. }