summaryrefslogtreecommitdiff
path: root/bin/gl.pl
blob: 95e9a438ebe5feed6e0c90f1a9d2f4a4e1fe0ec8 (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. use LedgerSMB::Template;
  49. require "bin/arap.pl";
  50. $form->{login} = 'test';
  51. 1;
  52. # end of main
  53. # this is for our long dates
  54. # $locale->text('January')
  55. # $locale->text('February')
  56. # $locale->text('March')
  57. # $locale->text('April')
  58. # $locale->text('May ')
  59. # $locale->text('June')
  60. # $locale->text('July')
  61. # $locale->text('August')
  62. # $locale->text('September')
  63. # $locale->text('October')
  64. # $locale->text('November')
  65. # $locale->text('December')
  66. # this is for our short month
  67. # $locale->text('Jan')
  68. # $locale->text('Feb')
  69. # $locale->text('Mar')
  70. # $locale->text('Apr')
  71. # $locale->text('May')
  72. # $locale->text('Jun')
  73. # $locale->text('Jul')
  74. # $locale->text('Aug')
  75. # $locale->text('Sep')
  76. # $locale->text('Oct')
  77. # $locale->text('Nov')
  78. # $locale->text('Dec')
  79. sub pos_adjust {
  80. $form->{rowcount} = 3;
  81. require "pos.conf.pl";
  82. $form->{accno_1} = $pos_config{'close_cash_accno'};
  83. $form->{accno_2} = $pos_config{'coa_prefix'};
  84. $form->{accno_3} = $pos_config{'coa_prefix'};
  85. }
  86. sub add_pos_adjust {
  87. $form->{pos_adjust} = 1;
  88. $form->{reference} =
  89. $locale->text("Adjusting Till: (till) Source: (source)");
  90. $form->{description} =
  91. $locale->text("Adjusting till due to data entry error.");
  92. $form->{callback} =
  93. "$form->{script}?action=add_pos_adjust&transfer=$form->{transfer}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"
  94. unless $form->{callback};
  95. &add;
  96. }
  97. sub add {
  98. $form->{title} = "Add";
  99. $form->{callback} =
  100. "$form->{script}?action=add&transfer=$form->{transfer}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"
  101. unless $form->{callback};
  102. &create_links;
  103. $form->{reference} = $form->update_defaults(\%myconfig, 'glnumber');
  104. $form->{rowcount} = ( $form->{transfer} ) ? 3 : 9;
  105. if ( $form->{pos_adjust} ) {
  106. &pos_adjust;
  107. }
  108. $form->{oldtransdate} = $form->{transdate};
  109. $form->{focus} = "reference";
  110. # departments
  111. if ( @{ $form->{all_department} } ) {
  112. $form->{selectdepartment} = "<option>\n";
  113. for ( @{ $form->{all_department} } ) {
  114. $form->{selectdepartment} .=
  115. qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
  116. }
  117. }
  118. display_form(1);
  119. }
  120. sub edit {
  121. &create_links;
  122. $form->{locked} =
  123. ( $form->{revtrans} )
  124. ? '1'
  125. : ( $form->datetonum( \%myconfig, $form->{transdate} ) <=
  126. $form->datetonum( \%myconfig, $form->{closedto} ) );
  127. # readonly
  128. if ( !$form->{readonly} ) {
  129. $form->{readonly} = 1
  130. if $myconfig{acs} =~ /General Ledger--Add Transaction/;
  131. }
  132. $form->{title} = "Edit";
  133. $i = 1;
  134. foreach $ref ( @{ $form->{GL} } ) {
  135. $form->{"accno_$i"} = "$ref->{accno}--$ref->{description}";
  136. $form->{"projectnumber_$i"} =
  137. "$ref->{projectnumber}--$ref->{project_id}";
  138. for (qw(fx_transaction source memo)) { $form->{"${_}_$i"} = $ref->{$_} }
  139. if ( $ref->{amount} < 0 ) {
  140. $form->{totaldebit} -= $ref->{amount};
  141. $form->{"debit_$i"} = $ref->{amount} * -1;
  142. }
  143. else {
  144. $form->{totalcredit} += $ref->{amount};
  145. $form->{"credit_$i"} = $ref->{amount};
  146. }
  147. $i++;
  148. }
  149. $form->{rowcount} = $i;
  150. $form->{focus} = "debit_$i";
  151. &form_header;
  152. &display_rows;
  153. &form_footer;
  154. }
  155. sub create_links {
  156. GL->transaction( \%myconfig, \%$form );
  157. for ( @{ $form->{all_accno} } ) {
  158. $form->{selectaccno} .= "<option>$_->{accno}--$_->{description}\n";
  159. }
  160. # projects
  161. if ( @{ $form->{all_project} } ) {
  162. $form->{selectprojectnumber} = "<option>\n";
  163. for ( @{ $form->{all_project} } ) {
  164. $form->{selectprojectnumber} .=
  165. qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n|;
  166. }
  167. }
  168. # departments
  169. if ( @{ $form->{all_department} } ) {
  170. $form->{department} = "$form->{department}--$form->{department_id}";
  171. $form->{selectdepartment} = "<option>\n";
  172. for ( @{ $form->{all_department} } ) {
  173. $form->{selectdepartment} .=
  174. qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
  175. }
  176. }
  177. }
  178. sub search {
  179. $form->{title} = $locale->text('General Ledger Reports');
  180. $colspan = 5;
  181. $form->all_departments( \%myconfig );
  182. # departments
  183. if ( @{ $form->{all_department} } ) {
  184. $form->{selectdepartment} = "<option>\n";
  185. for ( @{ $form->{all_department} } ) {
  186. $form->{selectdepartment} .=
  187. qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
  188. }
  189. $l_department =
  190. qq|<input name="l_department" class=checkbox type=checkbox value=Y> |
  191. . $locale->text('Department');
  192. $department = qq|
  193. <tr>
  194. <th align=right nowrap>| . $locale->text('Department') . qq|</th>
  195. <td colspan=$colspan><select name=department>$form->{selectdepartment}</select></td>
  196. </tr>
  197. |;
  198. }
  199. my @accounts = $form->all_accounts;
  200. my $account_select = qq|<select name="chart_id" class="account>|;
  201. for my $act (@accounts){
  202. $account_select .= qq|<option value="$act->{id}">$act->{accno}--| .
  203. qq|$act->{description}</option>|;
  204. }
  205. if ( @{ $form->{all_years} } ) {
  206. # accounting years
  207. $form->{selectaccountingyear} = "<option>\n";
  208. for ( @{ $form->{all_years} } ) {
  209. $form->{selectaccountingyear} .= qq|<option>$_\n|;
  210. }
  211. $form->{selectaccountingmonth} = "<option>\n";
  212. for ( sort keys %{ $form->{all_month} } ) {
  213. $form->{selectaccountingmonth} .=
  214. qq|<option value=$_>|
  215. . $locale->text( $form->{all_month}{$_} ) . qq|\n|;
  216. }
  217. $selectfrom = qq|
  218. <tr>
  219. <th align=right>| . $locale->text('Period') . qq|</th>
  220. <td colspan=$colspan>
  221. <select name=month>$form->{selectaccountingmonth}</select>
  222. <select name=year>$form->{selectaccountingyear}</select>
  223. <input name=interval class=radio type=radio value=0 checked>&nbsp;|
  224. . $locale->text('Current') . qq|
  225. <input name=interval class=radio type=radio value=1>&nbsp;|
  226. . $locale->text('Month') . qq|
  227. <input name=interval class=radio type=radio value=3>&nbsp;|
  228. . $locale->text('Quarter') . qq|
  229. <input name=interval class=radio type=radio value=12>&nbsp;|
  230. . $locale->text('Year') . qq|
  231. </td>
  232. </tr>
  233. |;
  234. }
  235. @a = ();
  236. push @a, qq|<input name="l_id" class=checkbox type=checkbox value=Y> |
  237. . $locale->text('ID');
  238. push @a,
  239. qq|<input name="l_transdate" class=checkbox type=checkbox value=Y checked> |
  240. . $locale->text('Date');
  241. push @a,
  242. qq|<input name="l_reference" class=checkbox type=checkbox value=Y checked> |
  243. . $locale->text('Reference');
  244. push @a,
  245. qq|<input name="l_description" class=checkbox type=checkbox value=Y checked> |
  246. . $locale->text('Description');
  247. push @a, qq|<input name="l_notes" class=checkbox type=checkbox value=Y> |
  248. . $locale->text('Notes');
  249. push @a, $l_department if $l_department;
  250. push @a,
  251. qq|<input name="l_debit" class=checkbox type=checkbox value=Y checked> |
  252. . $locale->text('Debit');
  253. push @a,
  254. qq|<input name="l_credit" class=checkbox type=checkbox value=Y checked> |
  255. . $locale->text('Credit');
  256. push @a,
  257. qq|<input name="l_source" class=checkbox type=checkbox value=Y checked> |
  258. . $locale->text('Source');
  259. push @a, qq|<input name="l_memo" class=checkbox type=checkbox value=Y> |
  260. . $locale->text('Memo');
  261. push @a,
  262. qq|<input name="l_accno" class=checkbox type=checkbox value=Y checked> |
  263. . $locale->text('Account');
  264. push @a,
  265. qq|<input name="l_gifi_accno" class=checkbox type=checkbox value=Y> |
  266. . $locale->text('GIFI');
  267. $form->header;
  268. print qq|
  269. <body>
  270. <form method=post action=$form->{script}>
  271. <input type=hidden name=sort value=transdate>
  272. <table width=100%>
  273. <tr>
  274. <th class=listtop>$form->{title}</th>
  275. </tr>
  276. <tr height="5"></tr>
  277. <tr>
  278. <td>
  279. <table>
  280. <tr>
  281. <th align=right>| . $locale->text('Reference') . qq|</th>
  282. <td><input name=reference size=20></td>
  283. </tr>
  284. <tr>
  285. <th align="right">| . $locale->text('Account') . qq|</th>
  286. <td>$account_select</td>
  287. </tr>
  288. <tr>
  289. <th align=right>| . $locale->text('Source') . qq|</th>
  290. <td><input name=source size=20></td>
  291. <th align=right>| . $locale->text('Memo') . qq|</th>
  292. <td><input name=memo size=20></td>
  293. </tr>
  294. $department
  295. <tr>
  296. <th align=right>| . $locale->text('Description') . qq|</th>
  297. <td colspan=$colspan><input name=description size=60></td>
  298. </tr>
  299. <tr>
  300. <th align=right>| . $locale->text('Notes') . qq|</th>
  301. <td colspan=$colspan><input name=notes size=60></td>
  302. </tr>
  303. <tr>
  304. <th align=right>| . $locale->text('From') . qq|</th>
  305. <td><input class="date" name=datefrom size=11 title="$myconfig{dateformat}"></td>
  306. <th align=right>| . $locale->text('To') . qq|</th>
  307. <td><input class="date" name=dateto size=11 title="$myconfig{dateformat}"></td>
  308. </tr>
  309. $selectfrom
  310. <tr>
  311. <th align=right>| . $locale->text('Amount') . qq| >=</th>
  312. <td><input name=amountfrom size=11></td>
  313. <th align=right>| . $locale->text('Amount') . qq| <=</th>
  314. <td><input name=amountto size=11></td>
  315. </tr>
  316. <tr>
  317. <th align=right>| . $locale->text('Include in Report') . qq|</th>
  318. <td colspan=$colspan>
  319. <table>
  320. <tr>
  321. <td>
  322. <input name="category" class=radio type=radio value=X checked>&nbsp;|
  323. . $locale->text('All') . qq|
  324. <input name="category" class=radio type=radio value=A>&nbsp;|
  325. . $locale->text('Asset') . qq|
  326. <input name="category" class=radio type=radio value=L>&nbsp;|
  327. . $locale->text('Liability') . qq|
  328. <input name="category" class=radio type=radio value=Q>&nbsp;|
  329. . $locale->text('Equity') . qq|
  330. <input name="category" class=radio type=radio value=I>&nbsp;|
  331. . $locale->text('Income') . qq|
  332. <input name="category" class=radio type=radio value=E>&nbsp;|
  333. . $locale->text('Expense') . qq|
  334. </td>
  335. </tr>
  336. <tr>
  337. <table>
  338. |;
  339. while (@a) {
  340. print qq|<tr>\n|;
  341. for ( 1 .. 5 ) {
  342. print qq|<td nowrap>| . shift @a;
  343. print qq|</td>\n|;
  344. }
  345. print qq|</tr>\n|;
  346. }
  347. print qq|
  348. <tr>
  349. <td nowrap><input name="l_subtotal" class=checkbox type=checkbox value=Y> |
  350. . $locale->text('Subtotal')
  351. . qq|</td>
  352. </tr>
  353. <tr>
  354. <td nowrap><input name="l_balance" class=checkbox type=checkbox value=Y> |
  355. . $locale->text('Balance')
  356. . qq|</td>
  357. </tr>
  358. </table>
  359. </tr>
  360. </table>
  361. </tr>
  362. </table>
  363. </td>
  364. </tr>
  365. <tr>
  366. <td><hr size=3 noshade></td>
  367. </tr>
  368. </table>
  369. <input type=hidden name=nextsub value=generate_report>
  370. |;
  371. $form->hide_form(qw(path login sessionid));
  372. print qq|
  373. <br>
  374. <button class="submit" type="submit" name="action" value="continue">|
  375. . $locale->text('Continue')
  376. . qq|</button>
  377. </form>
  378. |;
  379. if ( $form->{lynx} ) {
  380. require "bin/menu.pl";
  381. &menubar;
  382. }
  383. print qq|
  384. </body>
  385. </html>
  386. |;
  387. }
  388. sub generate_report {
  389. my $output_options = shift;
  390. $form->{sort} = "transdate" unless $form->{sort};
  391. $form->{amountfrom} = $form->parse_amount(\%myconfig, $form->{amountfrom});
  392. $form->{amountto} = $form->parse_amount(\%myconfig, $form->{amountto});
  393. GL->all_transactions( \%myconfig, \%$form );
  394. $href =
  395. "$form->{script}?action=generate_report&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  396. $form->sort_order();
  397. $callback =
  398. "$form->{script}?action=generate_report&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  399. my %hiddens = (
  400. 'action' => 'generate_report',
  401. 'direction' => $form->{direction},
  402. 'oldsort' => $form->{oldsort},
  403. 'path' => $form->{path},
  404. 'login' => $form->{login},
  405. 'sessionid' => $form->{sessionid},
  406. );
  407. %acctype = (
  408. 'A' => $locale->text('Asset'),
  409. 'L' => $locale->text('Liability'),
  410. 'Q' => $locale->text('Equity'),
  411. 'I' => $locale->text('Income'),
  412. 'E' => $locale->text('Expense'),
  413. );
  414. my @options;
  415. $form->{title} = $locale->text('General Ledger');
  416. $ml = ( $form->{category} =~ /(A|E)/ ) ? -1 : 1;
  417. if (defined $form->{category} and $form->{category} ne 'X' ) {
  418. $form->{title} .=
  419. " : " . $locale->text( $acctype{ $form->{category} } );
  420. }
  421. if ( $form->{accno} ) {
  422. $href .= "&accno=" . $form->escape( $form->{accno} );
  423. $callback .= "&accno=" . $form->escape( $form->{accno}, 1 );
  424. $hiddens{accno} = $form->{accno};
  425. push @options, $locale->text('Account')
  426. . " : $form->{accno} $form->{account_description}";
  427. }
  428. if ( $form->{gifi_accno} ) {
  429. $href .= "&gifi_accno=" . $form->escape( $form->{gifi_accno} );
  430. $callback .= "&gifi_accno=" . $form->escape( $form->{gifi_accno}, 1 );
  431. $hiddens{gifi_accno} = $form->{gifi_accno};
  432. push @options, $locale->text('GIFI')
  433. . " : $form->{gifi_accno} $form->{gifi_account_description}";
  434. }
  435. if ( $form->{source} ) {
  436. $href .= "&source=" . $form->escape( $form->{source} );
  437. $callback .= "&source=" . $form->escape( $form->{source}, 1 );
  438. $hiddens{source} = $form->{source};
  439. push @options, $locale->text('Source') . " : $form->{source}";
  440. }
  441. if ( $form->{memo} ) {
  442. $href .= "&memo=" . $form->escape( $form->{memo} );
  443. $callback .= "&memo=" . $form->escape( $form->{memo}, 1 );
  444. $hiddens{memo} = $form->{memo};
  445. push @options, $locale->text('Memo') . " : $form->{memo}";
  446. }
  447. if ( $form->{reference} ) {
  448. $href .= "&reference=" . $form->escape( $form->{reference} );
  449. $callback .= "&reference=" . $form->escape( $form->{reference}, 1 );
  450. $hiddens{reference} = $form->{reference};
  451. push @options, $locale->text('Reference') . " : $form->{reference}";
  452. }
  453. if ( $form->{department} ) {
  454. $href .= "&department=" . $form->escape( $form->{department} );
  455. $callback .= "&department=" . $form->escape( $form->{department}, 1 );
  456. $hiddens{department} = $form->{department};
  457. ($department) = split /--/, $form->{department};
  458. push @options, $locale->text('Department') . " : $department";
  459. }
  460. if ( $form->{description} ) {
  461. $href .= "&description=" . $form->escape( $form->{description} );
  462. $callback .= "&description=" . $form->escape( $form->{description}, 1 );
  463. $hiddens{description} = $form->{description};
  464. push @options, $locale->text('Description') . " : $form->{description}";
  465. }
  466. if ( $form->{notes} ) {
  467. $href .= "&notes=" . $form->escape( $form->{notes} );
  468. $callback .= "&notes=" . $form->escape( $form->{notes}, 1 );
  469. $hiddens{notes} = $form->{notes};
  470. push @options, $locale->text('Notes') . " : $form->{notes}";
  471. }
  472. if ( $form->{datefrom} ) {
  473. $href .= "&datefrom=$form->{datefrom}";
  474. $callback .= "&datefrom=$form->{datefrom}";
  475. $hiddens{datefrom} = $form->{datefrom};
  476. push @options, $locale->text('From') . " "
  477. . $locale->date( \%myconfig, $form->{datefrom}, 1 );
  478. }
  479. if ( $form->{dateto} ) {
  480. $href .= "&dateto=$form->{dateto}";
  481. $callback .= "&dateto=$form->{dateto}";
  482. $hiddens{dateto} = $form->{dateto};
  483. my $option = $locale->text('To') . " "
  484. . $locale->date( \%myconfig, $form->{dateto}, 1 );
  485. if ( $form->{datefrom} ) {
  486. $options[$#options] .= " $option";
  487. }
  488. else {
  489. push @options, $option;
  490. }
  491. }
  492. if ( $form->{amountfrom} ) {
  493. $href .= "&amountfrom=$form->{amountfrom}";
  494. $callback .= "&amountfrom=$form->{amountfrom}";
  495. $hiddens{amountfrom} = $form->{amountfrom};
  496. push @options, $locale->text('Amount') . " >= "
  497. . $form->format_amount( \%myconfig, $form->{amountfrom}, 2 );
  498. }
  499. if ( $form->{amountto} ) {
  500. $href .= "&amountto=$form->{amountto}";
  501. $callback .= "&amountto=$form->{amountto}";
  502. $hiddens{amountto} = $form->{amountto};
  503. my $option .= $form->format_amount( \%myconfig, $form->{amountto}, 2 );
  504. if ( $form->{amountfrom} ) {
  505. $options[$#options] .= " <= $option";
  506. }
  507. else {
  508. push @options, $locale->text('Amount') . " <= $option";
  509. }
  510. }
  511. @columns =
  512. $form->sort_columns(
  513. qw(transdate id reference description notes source memo debit credit accno gifi_accno department)
  514. );
  515. pop @columns if $form->{department};
  516. if ( $form->{link} =~ /_paid/ ) {
  517. @columns =
  518. $form->sort_columns(
  519. qw(transdate id reference description notes source memo cleared debit credit accno gifi_accno)
  520. );
  521. $form->{l_cleared} = "Y";
  522. }
  523. if ( $form->{chart_id} || $form->{gifi_accno} ) {
  524. @columns = grep !/(accno|gifi_accno)/, @columns;
  525. push @columns, "balance";
  526. $form->{l_balance} = "Y";
  527. }
  528. foreach $item (@columns) {
  529. if ( $form->{"l_$item"} eq "Y" ) {
  530. push @column_index, $item;
  531. # add column to href and callback
  532. $callback .= "&l_$item=Y";
  533. $href .= "&l_$item=Y";
  534. $hiddens{"l_$item"} = 'Y';
  535. }
  536. }
  537. if ( $form->{l_subtotal} eq 'Y' ) {
  538. $callback .= "&l_subtotal=Y";
  539. $href .= "&l_subtotal=Y";
  540. $hiddens{l_subtotal} = 'Y';
  541. }
  542. $callback .= "&category=$form->{category}";
  543. $href .= "&category=$form->{category}";
  544. $hiddens{category} = $form->{category};
  545. $column_header{id} =
  546. {text => $locale->text('ID'), href=> "$href&sort=id"};
  547. $column_header{transdate} =
  548. {text => $locale->text('Date'), href=> "$href&sort=transdate"};
  549. $column_header{reference} =
  550. {text => $locale->text('Reference'), href=> "$href&sort=reference"};
  551. $column_header{source} =
  552. {text => $locale->text('Source'), href=> "$href&sort=source"};
  553. $column_header{memo} =
  554. {text => $locale->text('Memo'), href=> "$href&sort=memo"};
  555. $column_header{description} =
  556. {text => $locale->text('Description'), href=> "$href&sort=description"};
  557. $column_header{department} =
  558. {text => $locale->text('Department'), href=> "$href&sort=department"};
  559. $column_header{notes} = $locale->text('Notes');
  560. $column_header{debit} = $locale->text('Debit');
  561. $column_header{credit} = $locale->text('Credit');
  562. $column_header{accno} =
  563. {text => $locale->text('Account'), href=> "$href&sort=accno"};
  564. $column_header{gifi_accno} =
  565. {text => $locale->text('GIFI'), href=> "$href&sort=gifi_accno"};
  566. $column_header{balance} = $locale->text('Balance');
  567. $column_header{cleared} = $locale->text('R');
  568. # add sort to callback
  569. $form->{callback} = "$callback&sort=$form->{sort}";
  570. $callback = $form->escape( $form->{callback} );
  571. $hiddens{sort} = $form->{sort};
  572. $hiddens{callback} = $form->{callback};
  573. $cml = 1;
  574. # initial item for subtotals
  575. if ( @{ $form->{GL} } ) {
  576. $sameitem = $form->{GL}->[0]->{ $form->{sort} };
  577. $cml = -1 if $form->{contra};
  578. }
  579. my @rows;
  580. if ( ( $form->{accno} || $form->{gifi_accno} ) && $form->{balance} ) {
  581. my %column_data;
  582. for (@column_index) { $column_data{$_} = " " }
  583. $column_data{balance} =
  584. $form->format_amount( \%myconfig, $form->{balance} * $ml * $cml,
  585. 2, 0 );
  586. $column_data{i} = 1;
  587. push @rows, \%column_data;
  588. }
  589. # reverse href
  590. $direction = ( $form->{direction} eq 'ASC' ) ? "ASC" : "DESC";
  591. $form->sort_order();
  592. $href =~ s/direction=$form->{direction}/direction=$direction/;
  593. my $i = 0;
  594. foreach $ref ( @{ $form->{GL} } ) {
  595. my %column_data;
  596. # if item ne sort print subtotal
  597. if ( $form->{l_subtotal} eq 'Y' ) {
  598. if ( $sameitem ne $ref->{ $form->{sort} } ) {
  599. push @rows, &gl_subtotal_tt();
  600. }
  601. }
  602. $form->{balance} += $ref->{amount};
  603. $subtotaldebit += $ref->{debit};
  604. $subtotalcredit += $ref->{credit};
  605. $totaldebit += $ref->{debit};
  606. $totalcredit += $ref->{credit};
  607. $ref->{debit} =
  608. $form->format_amount( \%myconfig, $ref->{debit}, 2, " " );
  609. $ref->{credit} =
  610. $form->format_amount( \%myconfig, $ref->{credit}, 2, " " );
  611. for (qw(id transdate)) { $column_data{$_} = "$ref->{$_}" }
  612. $column_data{reference} =
  613. {href => "$ref->{module}.pl?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback",
  614. text => $ref->{reference}};
  615. #$ref->{notes} =~ s/\r?\n/<br>/g;
  616. for (qw(description source memo notes department)) {
  617. $column_data{$_} = "$ref->{$_} ";
  618. }
  619. $column_data{debit} = "$ref->{debit}";
  620. $column_data{credit} = "$ref->{credit}";
  621. $column_data{accno} =
  622. {href => "$href&accno=$ref->{accno}&callback=$callback",
  623. text => "$ref->{accno} $ref->{accname}"};
  624. $column_data{gifi_accno} =
  625. {href => "$href&gifi_accno=$ref->{gifi_accno}&callback=$callback",
  626. text => $ref->{gifi_accno}};
  627. $column_data{balance} = $form->format_amount( \%myconfig, $form->{balance} * $ml * $cml,
  628. 2, 0 );
  629. $column_data{cleared} =
  630. ( $ref->{cleared} ) ? "*" : " ";
  631. if ( $ref->{id} != $sameid ) {
  632. $i++;
  633. $i %= 2;
  634. }
  635. $column_data{'i'} = $i;
  636. push @rows, \%column_data;
  637. $sameid = $ref->{id};
  638. }
  639. push @rows, &gl_subtotal_tt() if ( $form->{l_subtotal} eq 'Y' );
  640. for (@column_index) { $column_data{$_} = " " }
  641. $column_data{debit} = $form->format_amount( \%myconfig, $totaldebit, 2, " " );
  642. $column_data{credit} = $form->format_amount( \%myconfig, $totalcredit, 2, " " );
  643. $column_data{balance} = $form->format_amount( \%myconfig, $form->{balance} * $ml * $cml, 2, 0 );
  644. $i = 1;
  645. my %button;
  646. if ( $myconfig{acs} !~ /General Ledger--General Ledger/ ) {
  647. $button{'General Ledger--Add Transaction'} = {
  648. name => 'action',
  649. value => 'gl_transaction',
  650. text => $locale->text('GL Transaction'),
  651. type => 'submit',
  652. class => 'submit',
  653. order => $i++};
  654. }
  655. if ( $myconfig{acs} !~ /AR--AR/ ) {
  656. $button{'AR--Add Transaction'} = {
  657. name => 'action',
  658. value => 'ar_transaction',
  659. text => $locale->text('AR Transaction'),
  660. type => 'submit',
  661. class => 'submit',
  662. order => $i++};
  663. $button{'AR--Sales Invoice'} = {
  664. name => 'action',
  665. value => 'sales_invoice_',
  666. text => $locale->text('Sales Invoice'),
  667. type => 'submit',
  668. class => 'submit',
  669. order => $i++};
  670. }
  671. if ( $myconfig{acs} !~ /AP--AP/ ) {
  672. $button{'AP--Add Transaction'} = {
  673. name => 'action',
  674. value => 'ap_transaction',
  675. text => $locale->text('AP Transaction'),
  676. type => 'submit',
  677. class => 'submit',
  678. order => $i++};
  679. $button{'AP--Vendor Invoice'} = {
  680. name => 'action',
  681. value => 'vendor_invoice_',
  682. text => $locale->text('Vendor Invoice'),
  683. type => 'submit',
  684. class => 'submit',
  685. order => $i++};
  686. }
  687. foreach $item ( split /;/, $myconfig{acs} ) {
  688. delete $button{$item};
  689. }
  690. my @buttons;
  691. foreach my $item ( sort { $a->{order} <=> $b->{order} } %button ) {
  692. push @buttons, $item if ref $item;
  693. }
  694. push @buttons, {
  695. name => 'action',
  696. value => 'csv_gl_report',
  697. text => $locale->text('CSV Report'),
  698. type => 'submit',
  699. class => 'submit',
  700. };
  701. push @buttons, {
  702. name => 'action',
  703. value => 'csv_email_gl_report',
  704. text => $locale->text('Email CSV Report'),
  705. type => 'submit',
  706. class => 'submit',
  707. };
  708. ##SC: Taking this out for now...
  709. ## if ( $form->{lynx} ) {
  710. ## require "bin/menu.pl";
  711. ## &menubar;
  712. ## }
  713. my %row_alignment = (
  714. 'balance' => 'right',
  715. 'debit' => 'right',
  716. 'credit' => 'right'
  717. );
  718. my $template;
  719. my $format = uc substr($form->{action}, 0, 3);
  720. my $template = LedgerSMB::Template->new(
  721. user => \%myconfig,
  722. locale => $locale,
  723. path => 'UI',
  724. template => 'form-dynatable',
  725. format => ($format ne 'CSV')? 'HTML': 'CSV',
  726. output_options => $output_options,
  727. );
  728. $template->{method} = 'email' if $output_options;
  729. $template->render({
  730. form => \%$form,
  731. buttons => \@buttons,
  732. hiddens => \%hiddens,
  733. options => \@options,
  734. columns => \@column_index,
  735. heading => \%column_header,
  736. rows => \@rows,
  737. row_alignment => \%row_alignment,
  738. totals => \%column_data,
  739. });
  740. $form->info($locale->text('GL report sent to [_1]', $form->{login}));
  741. }
  742. sub csv_gl_report { &generate_report }
  743. sub csv_email_gl_report {
  744. ##SC: XXX hardcoded test values
  745. &generate_report({
  746. to => 'seneca@localhost',
  747. from => 'seneca@localhost',
  748. subject => 'CSV GL report',
  749. });
  750. }
  751. sub gl_subtotal_tt {
  752. my %column_data;
  753. $subtotaldebit =
  754. $form->format_amount( \%myconfig, $subtotaldebit, 2, " " );
  755. $subtotalcredit =
  756. $form->format_amount( \%myconfig, $subtotalcredit, 2, " " );
  757. for (@column_index) { $column_data{$_} = " " }
  758. $column_data{class} = 'subtotal';
  759. $column_data{debit} = $subtotaldebit;
  760. $column_data{credit} = $subtotalcredit;
  761. $subtotaldebit = 0;
  762. $subtotalcredit = 0;
  763. $sameitem = $ref->{ $form->{sort} };
  764. return \%column_data;
  765. }
  766. sub gl_subtotal {
  767. $subtotaldebit =
  768. $form->format_amount( \%myconfig, $subtotaldebit, 2, "&nbsp;" );
  769. $subtotalcredit =
  770. $form->format_amount( \%myconfig, $subtotalcredit, 2, "&nbsp;" );
  771. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  772. $column_data{debit} =
  773. "<th align=right class=listsubtotal>$subtotaldebit</td>";
  774. $column_data{credit} =
  775. "<th align=right class=listsubtotal>$subtotalcredit</td>";
  776. print "<tr class=listsubtotal>";
  777. for (@column_index) { print "$column_data{$_}\n" }
  778. print "</tr>";
  779. $subtotaldebit = 0;
  780. $subtotalcredit = 0;
  781. $sameitem = $ref->{ $form->{sort} };
  782. }
  783. sub update {
  784. if ( $form->{transdate} ne $form->{oldtransdate} ) {
  785. if ( $form->{selectprojectnumber} ) {
  786. $form->all_projects( \%myconfig, undef, $form->{transdate} );
  787. if ( @{ $form->{all_project} } ) {
  788. $form->{selectprojectnumber} = "<option>\n";
  789. for ( @{ $form->{all_project} } ) {
  790. $form->{selectprojectnumber} .=
  791. qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n|;
  792. }
  793. $form->{selectprojectnumber} =
  794. $form->escape( $form->{selectprojectnumber}, 1 );
  795. }
  796. }
  797. $form->{oldtransdate} = $form->{transdate};
  798. }
  799. @a = ();
  800. $count = 0;
  801. @flds = qw(accno debit credit projectnumber fx_transaction source memo);
  802. for $i ( 1 .. $form->{rowcount} ) {
  803. unless ( ( $form->{"debit_$i"} eq "" )
  804. && ( $form->{"credit_$i"} eq "" ) )
  805. {
  806. for (qw(debit credit)) {
  807. $form->{"${_}_$i"} =
  808. $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
  809. }
  810. push @a, {};
  811. $j = $#a;
  812. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  813. $count++;
  814. }
  815. }
  816. for $i ( 1 .. $count ) {
  817. $j = $i - 1;
  818. for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
  819. }
  820. for $i ( $count + 1 .. $form->{rowcount} ) {
  821. for (@flds) { delete $form->{"${_}_$i"} }
  822. }
  823. $form->{rowcount} = $count + 1;
  824. display_form();
  825. }
  826. sub display_form {
  827. my ($init) = @_;
  828. &form_header;
  829. &display_rows($init);
  830. &form_footer;
  831. }
  832. sub display_rows {
  833. my ($init) = @_;
  834. $form->{selectprojectnumber} =
  835. $form->unescape( $form->{selectprojectnumber} )
  836. if $form->{selectprojectnumber};
  837. $form->{totaldebit} = 0;
  838. $form->{totalcredit} = 0;
  839. for $i ( 1 .. $form->{rowcount} ) {
  840. $source = qq|
  841. <td><input name="source_$i" size=10 value="$form->{"source_$i"}"></td>|;
  842. $memo = qq|
  843. <td><input name="memo_$i" value="$form->{"memo_$i"}"></td>|;
  844. if ($init) {
  845. $accno = qq|
  846. <td><select name="accno_$i">$form->{selectaccno}</select></td>|;
  847. if ( $form->{selectprojectnumber} ) {
  848. $project = qq|
  849. <td><select name="projectnumber_$i">$form->{selectprojectnumber}</select></td>|;
  850. }
  851. if ( $form->{transfer} ) {
  852. $fx_transaction = qq|
  853. <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
  854. |;
  855. }
  856. }
  857. else {
  858. $form->{totaldebit} += $form->{"debit_$i"};
  859. $form->{totalcredit} += $form->{"credit_$i"};
  860. for (qw(debit credit)) {
  861. $form->{"${_}_$i"} =
  862. ( $form->{"${_}_$i"} )
  863. ? $form->format_amount( \%myconfig, $form->{"${_}_$i"}, 2 )
  864. : "";
  865. }
  866. if ( $i < $form->{rowcount} ) {
  867. $accno = qq|<td>$form->{"accno_$i"}</td>|;
  868. if ( $form->{selectprojectnumber} ) {
  869. $form->{"projectnumber_$i"} = ""
  870. if $form->{selectprojectnumber} !~
  871. /$form->{"projectnumber_$i"}/;
  872. $project = $form->{"projectnumber_$i"};
  873. $project =~ s/--.*//;
  874. $project = qq|<td>$project</td>|;
  875. }
  876. if ( $form->{transfer} ) {
  877. $checked = ( $form->{"fx_transaction_$i"} ) ? "1" : "";
  878. $x = ($checked) ? "x" : "";
  879. $fx_transaction = qq|
  880. <td><input type=hidden name="fx_transaction_$i" value="$checked">$x</td>
  881. |;
  882. }
  883. $form->hide_form( "accno_$i", "projectnumber_$i" );
  884. }
  885. else {
  886. $accno = qq|
  887. <td><select name="accno_$i">$form->{selectaccno}</select></td>|;
  888. if ( $form->{selectprojectnumber} ) {
  889. $project = qq|
  890. <td><select name="projectnumber_$i">$form->{selectprojectnumber}</select></td>|;
  891. }
  892. if ( $form->{transfer} ) {
  893. $fx_transaction = qq|
  894. <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
  895. |;
  896. }
  897. }
  898. }
  899. print qq|<tr valign=top>
  900. $accno
  901. $fx_transaction
  902. <td><input name="debit_$i" size=12 value="$form->{"debit_$i"}" accesskey=$i></td>
  903. <td><input name="credit_$i" size=12 value=$form->{"credit_$i"}></td>
  904. $source
  905. $memo
  906. $project
  907. </tr>
  908. |;
  909. }
  910. $form->hide_form(qw(rowcount selectaccno pos_adjust));
  911. print qq|
  912. <input type=hidden name=selectprojectnumber value="|
  913. . $form->escape( $form->{selectprojectnumber}, 1 ) . qq|">|;
  914. }
  915. sub form_header {
  916. $title = $form->{title};
  917. if ( $form->{transfer} ) {
  918. $form->{title} = $locale->text("$title Cash Transfer Transaction");
  919. }
  920. else {
  921. $form->{title} = $locale->text("$title General Ledger Transaction");
  922. }
  923. # $locale->text('Add Cash Transfer Transaction')
  924. # $locale->text('Edit Cash Transfer Transaction')
  925. # $locale->text('Add General Ledger Transaction')
  926. # $locale->text('Edit General Ledger Transaction')
  927. $form->{selectdepartment} = $form->unescape( $form->{selectdepartment} );
  928. $form->{selectdepartment} =~ s/ selected//;
  929. $form->{selectdepartment} =~
  930. s/(<option value="\Q$form->{department}\E")/$1 selected/;
  931. for (qw(reference description notes)) {
  932. $form->{$_} = $form->quote( $form->{$_} );
  933. }
  934. if ( ( $rows = $form->numtextrows( $form->{description}, 50 ) ) > 1 ) {
  935. $description =
  936. qq|<textarea name=description rows=$rows cols=50 wrap=soft>$form->{description}</textarea>|;
  937. }
  938. else {
  939. $description =
  940. qq|<input name=description size=50 value="$form->{description}">|;
  941. }
  942. if ( ( $rows = $form->numtextrows( $form->{notes}, 50 ) ) > 1 ) {
  943. $notes =
  944. qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|;
  945. }
  946. else {
  947. $notes = qq|<input name=notes size=50 value="$form->{notes}">|;
  948. }
  949. if (!defined $form->{approved}){
  950. $form->{approved} = '1';
  951. }
  952. $department = qq|
  953. <tr>
  954. <th align=right nowrap>| . $locale->text('Department') . qq|</th>
  955. <td><select name=department>$form->{selectdepartment}</select></td>
  956. <input type=hidden name=selectdepartment value="|
  957. . $form->escape( $form->{selectdepartment}, 1 ) . qq|">
  958. </tr>
  959. | if $form->{selectdepartment};
  960. $project = qq|
  961. <th class=listheading>| . $locale->text('Project') . qq|</th>
  962. | if $form->{selectprojectnumber};
  963. if ( $form->{transfer} ) {
  964. $fx_transaction = qq|
  965. <th class=listheading>| . $locale->text('FX') . qq|</th>
  966. |;
  967. }
  968. $focus = ( $form->{focus} ) ? $form->{focus} : "debit_$form->{rowcount}";
  969. $form->header;
  970. print qq|
  971. <body onload="document.forms[0].${focus}.focus()" />
  972. <form method=post action=$form->{script}>
  973. <input type="hidden" name="approved" value="$form->{approved}" />
  974. |;
  975. $form->hide_form(
  976. qw(batch_id id transfer selectaccno closedto locked oldtransdate recurring));
  977. print qq|
  978. <input type=hidden name=title value="$title">
  979. <table width=100%>
  980. <tr>
  981. <th class=listtop>$form->{title}</th>
  982. </tr>
  983. <tr height="5"></tr>
  984. <tr>
  985. <td>
  986. <table>
  987. <tr>
  988. <th align=right>| . $locale->text('Reference') . qq|</th>
  989. <td><input name=reference size=20 value="$form->{reference}"></td>
  990. <th align=right>| . $locale->text('Date') . qq|</th>
  991. <td><input class="date" name=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>
  992. </tr>
  993. $department
  994. <tr>
  995. <th align=right>| . $locale->text('Description') . qq|</th>
  996. <td colspan=3>$description</td>
  997. </tr>
  998. <tr>
  999. <th align=right>| . $locale->text('Notes') . qq|</th>
  1000. <td colspan=3>$notes</td>
  1001. </tr>
  1002. </table>
  1003. </td>
  1004. </tr>
  1005. <tr>
  1006. <td>
  1007. <table width=100%>
  1008. <tr class=listheading>
  1009. <th class=listheading>| . $locale->text('Account') . qq|</th>
  1010. $fx_transaction
  1011. <th class=listheading>| . $locale->text('Debit') . qq|</th>
  1012. <th class=listheading>| . $locale->text('Credit') . qq|</th>
  1013. <th class=listheading>| . $locale->text('Source') . qq|</th>
  1014. <th class=listheading>| . $locale->text('Memo') . qq|</th>
  1015. $project
  1016. </tr>
  1017. |;
  1018. }
  1019. sub form_footer {
  1020. for (qw(totaldebit totalcredit)) {
  1021. $form->{$_} =
  1022. $form->format_amount( \%myconfig, $form->{$_}, 2, "&nbsp;" );
  1023. }
  1024. $project = qq|
  1025. <th>&nbsp;</th>
  1026. | if $form->{selectprojectnumber};
  1027. if ( $form->{transfer} ) {
  1028. $fx_transaction = qq|
  1029. <th>&nbsp;</th>
  1030. |;
  1031. }
  1032. print qq|
  1033. <tr class=listtotal>
  1034. <th>&nbsp;</th>
  1035. $fx_transaction
  1036. <th class=listtotal align=right>$form->{totaldebit}</th>
  1037. <th class=listtotal align=right>$form->{totalcredit}</th>
  1038. <th>&nbsp;</th>
  1039. <th>&nbsp;</th>
  1040. $project
  1041. </tr>
  1042. </table>
  1043. </td>
  1044. </tr>
  1045. <tr>
  1046. <td><hr size=3 noshade></td>
  1047. </tr>
  1048. </table>
  1049. |;
  1050. $form->hide_form(qw(path login sessionid callback));
  1051. $transdate = $form->datetonum( \%myconfig, $form->{transdate} );
  1052. $closedto = $form->datetonum( \%myconfig, $form->{closedto} );
  1053. # type=submit $locale->text('Update')
  1054. # type=submit $locale->text('Post')
  1055. # type=submit $locale->text('Schedule')
  1056. # type=submit $locale->text('Post as new')
  1057. # type=submit $locale->text('Delete')
  1058. if ( !$form->{readonly} ) {
  1059. %button = (
  1060. 'update' =>
  1061. { ndx => 1, key => 'U', value => $locale->text('Update') },
  1062. 'post' => { ndx => 3, key => 'O', value => $locale->text('Post') },
  1063. 'post_as_new' =>
  1064. { ndx => 6, key => 'N', value => $locale->text('Post as new') },
  1065. 'schedule' =>
  1066. { ndx => 7, key => 'H', value => $locale->text('Schedule') },
  1067. 'delete' =>
  1068. { ndx => 8, key => 'D', value => $locale->text('Delete') },
  1069. );
  1070. if ($form->{separate_duties}){
  1071. $form->hide_form('separate_duties');
  1072. $button{post}->{value} = $locale->text('Save');
  1073. }
  1074. %a = ();
  1075. if ( $form->{id} ) {
  1076. for ( 'update', 'post_as_new', 'schedule' ) { $a{$_} = 1 }
  1077. if ( !$form->{locked} ) {
  1078. if ( $transdate > $closedto ) {
  1079. for ( 'post', 'delete' ) { $a{$_} = 1 }
  1080. }
  1081. }
  1082. }
  1083. else {
  1084. if ( $transdate > $closedto ) {
  1085. for ( "update", "post", "schedule" ) { $a{$_} = 1 }
  1086. }
  1087. }
  1088. for ( keys %button ) { delete $button{$_} if !$a{$_} }
  1089. for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button )
  1090. {
  1091. $form->print_button( \%button, $_ );
  1092. }
  1093. }
  1094. if ( $form->{recurring} ) {
  1095. print qq|<div align=right>| . $locale->text('Scheduled') . qq|</div>|;
  1096. }
  1097. if ( $form->{lynx} ) {
  1098. require "bin/menu.pl";
  1099. &menubar;
  1100. }
  1101. print qq|
  1102. </form>
  1103. </body>
  1104. </html>
  1105. |;
  1106. }
  1107. sub delete {
  1108. my %hiddens;
  1109. delete $form->{action};
  1110. foreach (keys %$form) {
  1111. $hiddens{$_} = $form->{$_} unless ref $form->{$_};
  1112. }
  1113. $form->{title} = $locale->text('Confirm!');
  1114. my $query = $locale->text(
  1115. 'Are you sure you want to delete Transaction [_1]',
  1116. $form->{reference} );
  1117. my @buttons = ({
  1118. name => 'action',
  1119. value => 'delete_transaction',
  1120. text => $locale->text('Yes'),
  1121. });
  1122. my $template = LedgerSMB::Template->new_UI(
  1123. user => \%myconfig,
  1124. locale => $locale,
  1125. template => 'form-confirmation',
  1126. );
  1127. $template->render({
  1128. form => $form,
  1129. query => $query,
  1130. hiddens => \%hiddens,
  1131. buttons => \@buttons,
  1132. });
  1133. }
  1134. sub delete_transaction {
  1135. if ( GL->delete_transaction( \%myconfig, \%$form ) ) {
  1136. $form->redirect( $locale->text('Transaction deleted!') );
  1137. }
  1138. else {
  1139. $form->error( $locale->text('Cannot delete transaction!') );
  1140. }
  1141. }
  1142. sub post {
  1143. $form->isblank( "transdate", $locale->text('Transaction Date missing!') );
  1144. $transdate = $form->datetonum( \%myconfig, $form->{transdate} );
  1145. $closedto = $form->datetonum( \%myconfig, $form->{closedto} );
  1146. $form->error(
  1147. $locale->text('Cannot post transaction for a closed period!') )
  1148. if ( $transdate <= $closedto );
  1149. # add up debits and credits
  1150. for $i ( 1 .. $form->{rowcount} ) {
  1151. $dr = $form->parse_amount( \%myconfig, $form->{"debit_$i"} );
  1152. $cr = $form->parse_amount( \%myconfig, $form->{"credit_$i"} );
  1153. if ( $dr && $cr ) {
  1154. $form->error(
  1155. $locale->text(
  1156. 'Cannot post transaction with a debit and credit entry for the same account!'
  1157. )
  1158. );
  1159. }
  1160. $debit += $dr;
  1161. $credit += $cr;
  1162. }
  1163. if ( $form->round_amount( $debit, 2 ) != $form->round_amount( $credit, 2 ) )
  1164. {
  1165. $form->error( $locale->text('Out of balance transaction!') );
  1166. }
  1167. if ( !$form->{repost} ) {
  1168. if ( $form->{id} ) {
  1169. &repost;
  1170. exit;
  1171. }
  1172. }
  1173. if ( GL->post_transaction( \%myconfig, \%$form ) ) {
  1174. $form->redirect( $locale->text('Transaction posted!') );
  1175. }
  1176. else {
  1177. $form->error( $locale->text('Cannot post transaction!') );
  1178. }
  1179. }