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