summaryrefslogtreecommitdiff
path: root/bin/gl.pl
blob: 5581259cae72bdb3815e408a706faa7742d5307a (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. my ($totaldebit, $totalcredit) = (0, 0);
  394. GL->all_transactions( \%myconfig, \%$form );
  395. $href =
  396. "$form->{script}?action=generate_report&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  397. $form->sort_order();
  398. $callback =
  399. "$form->{script}?action=generate_report&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  400. my %hiddens = (
  401. 'action' => 'generate_report',
  402. 'direction' => $form->{direction},
  403. 'oldsort' => $form->{oldsort},
  404. 'path' => $form->{path},
  405. 'login' => $form->{login},
  406. 'sessionid' => $form->{sessionid},
  407. );
  408. %acctype = (
  409. 'A' => $locale->text('Asset'),
  410. 'L' => $locale->text('Liability'),
  411. 'Q' => $locale->text('Equity'),
  412. 'I' => $locale->text('Income'),
  413. 'E' => $locale->text('Expense'),
  414. );
  415. my @options;
  416. $form->{title} = $locale->text('General Ledger');
  417. $ml = ( $form->{category} =~ /(A|E)/ ) ? -1 : 1;
  418. if (defined $form->{category} and $form->{category} ne 'X' ) {
  419. $form->{title} .=
  420. " : " . $locale->text( $acctype{ $form->{category} } );
  421. }
  422. if ( $form->{accno} ) {
  423. $href .= "&accno=" . $form->escape( $form->{accno} );
  424. $callback .= "&accno=" . $form->escape( $form->{accno}, 1 );
  425. $hiddens{accno} = $form->{accno};
  426. push @options, $locale->text('Account')
  427. . " : $form->{accno} $form->{account_description}";
  428. }
  429. if ( $form->{gifi_accno} ) {
  430. $href .= "&gifi_accno=" . $form->escape( $form->{gifi_accno} );
  431. $callback .= "&gifi_accno=" . $form->escape( $form->{gifi_accno}, 1 );
  432. $hiddens{gifi_accno} = $form->{gifi_accno};
  433. push @options, $locale->text('GIFI')
  434. . " : $form->{gifi_accno} $form->{gifi_account_description}";
  435. }
  436. if ( $form->{source} ) {
  437. $href .= "&source=" . $form->escape( $form->{source} );
  438. $callback .= "&source=" . $form->escape( $form->{source}, 1 );
  439. $hiddens{source} = $form->{source};
  440. push @options, $locale->text('Source') . " : $form->{source}";
  441. }
  442. if ( $form->{memo} ) {
  443. $href .= "&memo=" . $form->escape( $form->{memo} );
  444. $callback .= "&memo=" . $form->escape( $form->{memo}, 1 );
  445. $hiddens{memo} = $form->{memo};
  446. push @options, $locale->text('Memo') . " : $form->{memo}";
  447. }
  448. if ( $form->{reference} ) {
  449. $href .= "&reference=" . $form->escape( $form->{reference} );
  450. $callback .= "&reference=" . $form->escape( $form->{reference}, 1 );
  451. $hiddens{reference} = $form->{reference};
  452. push @options, $locale->text('Reference') . " : $form->{reference}";
  453. }
  454. if ( $form->{department} ) {
  455. $href .= "&department=" . $form->escape( $form->{department} );
  456. $callback .= "&department=" . $form->escape( $form->{department}, 1 );
  457. $hiddens{department} = $form->{department};
  458. ($department) = split /--/, $form->{department};
  459. push @options, $locale->text('Department') . " : $department";
  460. }
  461. if ( $form->{description} ) {
  462. $href .= "&description=" . $form->escape( $form->{description} );
  463. $callback .= "&description=" . $form->escape( $form->{description}, 1 );
  464. $hiddens{description} = $form->{description};
  465. push @options, $locale->text('Description') . " : $form->{description}";
  466. }
  467. if ( $form->{notes} ) {
  468. $href .= "&notes=" . $form->escape( $form->{notes} );
  469. $callback .= "&notes=" . $form->escape( $form->{notes}, 1 );
  470. $hiddens{notes} = $form->{notes};
  471. push @options, $locale->text('Notes') . " : $form->{notes}";
  472. }
  473. if ( $form->{datefrom} ) {
  474. $href .= "&datefrom=$form->{datefrom}";
  475. $callback .= "&datefrom=$form->{datefrom}";
  476. $hiddens{datefrom} = $form->{datefrom};
  477. push @options, $locale->text('From') . " "
  478. . $locale->date( \%myconfig, $form->{datefrom}, 1 );
  479. }
  480. if ( $form->{dateto} ) {
  481. $href .= "&dateto=$form->{dateto}";
  482. $callback .= "&dateto=$form->{dateto}";
  483. $hiddens{dateto} = $form->{dateto};
  484. my $option = $locale->text('To') . " "
  485. . $locale->date( \%myconfig, $form->{dateto}, 1 );
  486. if ( $form->{datefrom} ) {
  487. $options[$#options] .= " $option";
  488. }
  489. else {
  490. push @options, $option;
  491. }
  492. }
  493. if ( $form->{amountfrom} ) {
  494. $href .= "&amountfrom=$form->{amountfrom}";
  495. $callback .= "&amountfrom=$form->{amountfrom}";
  496. $hiddens{amountfrom} = $form->{amountfrom};
  497. push @options, $locale->text('Amount') . " >= "
  498. . $form->format_amount( \%myconfig, $form->{amountfrom}, 2 );
  499. }
  500. if ( $form->{amountto} ) {
  501. $href .= "&amountto=$form->{amountto}";
  502. $callback .= "&amountto=$form->{amountto}";
  503. $hiddens{amountto} = $form->{amountto};
  504. my $option .= $form->format_amount( \%myconfig, $form->{amountto}, 2 );
  505. if ( $form->{amountfrom} ) {
  506. $options[$#options] .= " <= $option";
  507. }
  508. else {
  509. push @options, $locale->text('Amount') . " <= $option";
  510. }
  511. }
  512. @columns =
  513. $form->sort_columns(
  514. qw(transdate id reference description notes source memo debit credit accno gifi_accno department)
  515. );
  516. pop @columns if $form->{department};
  517. if ( $form->{link} =~ /_paid/ ) {
  518. @columns =
  519. $form->sort_columns(
  520. qw(transdate id reference description notes source memo cleared debit credit accno gifi_accno)
  521. );
  522. $form->{l_cleared} = "Y";
  523. }
  524. if ( $form->{chart_id} || $form->{gifi_accno} ) {
  525. @columns = grep !/(accno|gifi_accno)/, @columns;
  526. push @columns, "balance";
  527. $form->{l_balance} = "Y";
  528. }
  529. foreach $item (@columns) {
  530. if ( $form->{"l_$item"} eq "Y" ) {
  531. push @column_index, $item;
  532. # add column to href and callback
  533. $callback .= "&l_$item=Y";
  534. $href .= "&l_$item=Y";
  535. $hiddens{"l_$item"} = 'Y';
  536. }
  537. }
  538. if ( $form->{l_subtotal} eq 'Y' ) {
  539. $callback .= "&l_subtotal=Y";
  540. $href .= "&l_subtotal=Y";
  541. $hiddens{l_subtotal} = 'Y';
  542. }
  543. $callback .= "&category=$form->{category}";
  544. $href .= "&category=$form->{category}";
  545. $hiddens{category} = $form->{category};
  546. $column_header{id} =
  547. {text => $locale->text('ID'), href=> "$href&sort=id"};
  548. $column_header{transdate} =
  549. {text => $locale->text('Date'), href=> "$href&sort=transdate"};
  550. $column_header{reference} =
  551. {text => $locale->text('Reference'), href=> "$href&sort=reference"};
  552. $column_header{source} =
  553. {text => $locale->text('Source'), href=> "$href&sort=source"};
  554. $column_header{memo} =
  555. {text => $locale->text('Memo'), href=> "$href&sort=memo"};
  556. $column_header{description} =
  557. {text => $locale->text('Description'), href=> "$href&sort=description"};
  558. $column_header{department} =
  559. {text => $locale->text('Department'), href=> "$href&sort=department"};
  560. $column_header{notes} = $locale->text('Notes');
  561. $column_header{debit} = $locale->text('Debit');
  562. $column_header{credit} = $locale->text('Credit');
  563. $column_header{accno} =
  564. {text => $locale->text('Account'), href=> "$href&sort=accno"};
  565. $column_header{gifi_accno} =
  566. {text => $locale->text('GIFI'), href=> "$href&sort=gifi_accno"};
  567. $column_header{balance} = $locale->text('Balance');
  568. $column_header{cleared} = $locale->text('R');
  569. # add sort to callback
  570. $form->{callback} = "$callback&sort=$form->{sort}";
  571. $callback = $form->escape( $form->{callback} );
  572. $hiddens{sort} = $form->{sort};
  573. $hiddens{callback} = $form->{callback};
  574. $cml = 1;
  575. # initial item for subtotals
  576. if ( @{ $form->{GL} } ) {
  577. $sameitem = $form->{GL}->[0]->{ $form->{sort} };
  578. $cml = -1 if $form->{contra};
  579. }
  580. my @rows;
  581. if ( ( $form->{accno} || $form->{gifi_accno} ) && $form->{balance} ) {
  582. my %column_data;
  583. for (@column_index) { $column_data{$_} = " " }
  584. $column_data{balance} =
  585. $form->format_amount( \%myconfig, $form->{balance} * $ml * $cml,
  586. 2, 0 );
  587. $column_data{i} = 1;
  588. push @rows, \%column_data;
  589. }
  590. # reverse href
  591. $direction = ( $form->{direction} eq 'ASC' ) ? "ASC" : "DESC";
  592. $form->sort_order();
  593. $href =~ s/direction=$form->{direction}/direction=$direction/;
  594. my $i = 0;
  595. foreach $ref ( @{ $form->{GL} } ) {
  596. my %column_data;
  597. # if item ne sort print subtotal
  598. if ( $form->{l_subtotal} eq 'Y' ) {
  599. if ( $sameitem ne $ref->{ $form->{sort} } ) {
  600. push @rows, &gl_subtotal_tt();
  601. }
  602. }
  603. $form->{balance} += $ref->{amount};
  604. $subtotaldebit += $ref->{debit};
  605. $subtotalcredit += $ref->{credit};
  606. $totaldebit += $ref->{debit};
  607. $totalcredit += $ref->{credit};
  608. $ref->{debit} =
  609. $form->format_amount( \%myconfig, $ref->{debit}, 2);
  610. $ref->{credit} =
  611. $form->format_amount( \%myconfig, $ref->{credit}, 2);
  612. for (qw(id transdate)) { $column_data{$_} = "$ref->{$_}" }
  613. $column_data{reference} =
  614. {href => "$ref->{module}.pl?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback",
  615. text => $ref->{reference}};
  616. #$ref->{notes} =~ s/\r?\n/<br>/g;
  617. for (qw(description source memo notes department)) {
  618. $column_data{$_} = "$ref->{$_} ";
  619. }
  620. $column_data{debit} = "$ref->{debit}";
  621. $column_data{credit} = "$ref->{credit}";
  622. $column_data{accno} =
  623. {href => "$href&accno=$ref->{accno}&callback=$callback",
  624. text => "$ref->{accno} $ref->{accname}"};
  625. $column_data{gifi_accno} =
  626. {href => "$href&gifi_accno=$ref->{gifi_accno}&callback=$callback",
  627. text => $ref->{gifi_accno}};
  628. $column_data{balance} = $form->format_amount( \%myconfig, $form->{balance} * $ml * $cml,
  629. 2, 0 );
  630. $column_data{cleared} =
  631. ( $ref->{cleared} ) ? "*" : " ";
  632. if ( $ref->{id} != $sameid ) {
  633. $i++;
  634. $i %= 2;
  635. }
  636. $column_data{'i'} = $i;
  637. push @rows, \%column_data;
  638. $sameid = $ref->{id};
  639. }
  640. push @rows, &gl_subtotal_tt() if ( $form->{l_subtotal} eq 'Y' );
  641. for (@column_index) { $column_data{$_} = " " }
  642. $column_data{debit} = $form->format_amount( \%myconfig, $totaldebit, 2, " " );
  643. $column_data{credit} = $form->format_amount( \%myconfig, $totalcredit, 2, " " );
  644. $column_data{balance} = $form->format_amount( \%myconfig, $form->{balance} * $ml * $cml, 2, 0 );
  645. $i = 1;
  646. my %button;
  647. if ( $myconfig{acs} !~ /General Ledger--General Ledger/ ) {
  648. $button{'General Ledger--Add Transaction'} = {
  649. name => 'action',
  650. value => 'gl_transaction',
  651. text => $locale->text('GL Transaction'),
  652. type => 'submit',
  653. class => 'submit',
  654. order => $i++};
  655. }
  656. if ( $myconfig{acs} !~ /AR--AR/ ) {
  657. $button{'AR--Add Transaction'} = {
  658. name => 'action',
  659. value => 'ar_transaction',
  660. text => $locale->text('AR Transaction'),
  661. type => 'submit',
  662. class => 'submit',
  663. order => $i++};
  664. $button{'AR--Sales Invoice'} = {
  665. name => 'action',
  666. value => 'sales_invoice_',
  667. text => $locale->text('Sales Invoice'),
  668. type => 'submit',
  669. class => 'submit',
  670. order => $i++};
  671. }
  672. if ( $myconfig{acs} !~ /AP--AP/ ) {
  673. $button{'AP--Add Transaction'} = {
  674. name => 'action',
  675. value => 'ap_transaction',
  676. text => $locale->text('AP Transaction'),
  677. type => 'submit',
  678. class => 'submit',
  679. order => $i++};
  680. $button{'AP--Vendor Invoice'} = {
  681. name => 'action',
  682. value => 'vendor_invoice_',
  683. text => $locale->text('Vendor Invoice'),
  684. type => 'submit',
  685. class => 'submit',
  686. order => $i++};
  687. }
  688. foreach $item ( split /;/, $myconfig{acs} ) {
  689. delete $button{$item};
  690. }
  691. my @buttons;
  692. foreach my $item ( sort { $a->{order} <=> $b->{order} } %button ) {
  693. push @buttons, $item if ref $item;
  694. }
  695. push @buttons, {
  696. name => 'action',
  697. value => 'csv_gl_report',
  698. text => $locale->text('CSV Report'),
  699. type => 'submit',
  700. class => 'submit',
  701. };
  702. push @buttons, {
  703. name => 'action',
  704. value => 'csv_email_gl_report',
  705. text => $locale->text('Email CSV Report'),
  706. type => 'submit',
  707. class => 'submit',
  708. };
  709. ##SC: Taking this out for now...
  710. ## if ( $form->{lynx} ) {
  711. ## require "bin/menu.pl";
  712. ## &menubar;
  713. ## }
  714. my %row_alignment = (
  715. 'balance' => 'right',
  716. 'debit' => 'right',
  717. 'credit' => 'right'
  718. );
  719. my $template;
  720. my $format = uc substr($form->{action}, 0, 3);
  721. my $template = LedgerSMB::Template->new(
  722. user => \%myconfig,
  723. locale => $locale,
  724. path => 'UI',
  725. template => 'form-dynatable',
  726. format => ($format ne 'CSV')? 'HTML': 'CSV',
  727. output_options => $output_options,
  728. );
  729. $template->{method} = 'email' if $output_options;
  730. $template->render({
  731. form => \%$form,
  732. buttons => \@buttons,
  733. hiddens => \%hiddens,
  734. options => \@options,
  735. columns => \@column_index,
  736. heading => \%column_header,
  737. rows => \@rows,
  738. row_alignment => \%row_alignment,
  739. totals => \%column_data,
  740. });
  741. $form->info($locale->text('GL report sent to [_1]', $form->{login}));
  742. }
  743. sub csv_gl_report { &generate_report }
  744. sub csv_email_gl_report {
  745. ##SC: XXX hardcoded test values
  746. &generate_report({
  747. to => 'seneca@localhost',
  748. from => 'seneca@localhost',
  749. subject => 'CSV GL report',
  750. });
  751. }
  752. sub gl_subtotal_tt {
  753. my %column_data;
  754. $subtotaldebit =
  755. $form->format_amount( \%myconfig, $subtotaldebit, 2, " " );
  756. $subtotalcredit =
  757. $form->format_amount( \%myconfig, $subtotalcredit, 2, " " );
  758. for (@column_index) { $column_data{$_} = " " }
  759. $column_data{class} = 'subtotal';
  760. $column_data{debit} = $subtotaldebit;
  761. $column_data{credit} = $subtotalcredit;
  762. $subtotaldebit = 0;
  763. $subtotalcredit = 0;
  764. $sameitem = $ref->{ $form->{sort} };
  765. return \%column_data;
  766. }
  767. sub gl_subtotal {
  768. $subtotaldebit =
  769. $form->format_amount( \%myconfig, $subtotaldebit, 2, "&nbsp;" );
  770. $subtotalcredit =
  771. $form->format_amount( \%myconfig, $subtotalcredit, 2, "&nbsp;" );
  772. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  773. $column_data{debit} =
  774. "<th align=right class=listsubtotal>$subtotaldebit</td>";
  775. $column_data{credit} =
  776. "<th align=right class=listsubtotal>$subtotalcredit</td>";
  777. print "<tr class=listsubtotal>";
  778. for (@column_index) { print "$column_data{$_}\n" }
  779. print "</tr>";
  780. $subtotaldebit = 0;
  781. $subtotalcredit = 0;
  782. $sameitem = $ref->{ $form->{sort} };
  783. }
  784. sub update {
  785. if ( $form->{transdate} ne $form->{oldtransdate} ) {
  786. if ( $form->{selectprojectnumber} ) {
  787. $form->all_projects( \%myconfig, undef, $form->{transdate} );
  788. if ( @{ $form->{all_project} } ) {
  789. $form->{selectprojectnumber} = "<option>\n";
  790. for ( @{ $form->{all_project} } ) {
  791. $form->{selectprojectnumber} .=
  792. qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n|;
  793. }
  794. $form->{selectprojectnumber} =
  795. $form->escape( $form->{selectprojectnumber}, 1 );
  796. }
  797. }
  798. $form->{oldtransdate} = $form->{transdate};
  799. }
  800. @a = ();
  801. $count = 0;
  802. @flds = qw(accno debit credit projectnumber fx_transaction source memo);
  803. for $i ( 1 .. $form->{rowcount} ) {
  804. unless ( ( $form->{"debit_$i"} eq "" )
  805. && ( $form->{"credit_$i"} eq "" ) )
  806. {
  807. for (qw(debit credit)) {
  808. $form->{"${_}_$i"} =
  809. $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
  810. }
  811. push @a, {};
  812. $j = $#a;
  813. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  814. $count++;
  815. }
  816. }
  817. for $i ( 1 .. $count ) {
  818. $j = $i - 1;
  819. for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
  820. }
  821. for $i ( $count + 1 .. $form->{rowcount} ) {
  822. for (@flds) { delete $form->{"${_}_$i"} }
  823. }
  824. $form->{rowcount} = $count + 1;
  825. display_form();
  826. }
  827. sub display_form {
  828. my ($init) = @_;
  829. &form_header;
  830. &display_rows($init);
  831. &form_footer;
  832. }
  833. sub display_rows {
  834. my ($init) = @_;
  835. $form->{selectprojectnumber} =
  836. $form->unescape( $form->{selectprojectnumber} )
  837. if $form->{selectprojectnumber};
  838. $form->{totaldebit} = 0;
  839. $form->{totalcredit} = 0;
  840. for $i ( 1 .. $form->{rowcount} ) {
  841. $source = qq|
  842. <td><input name="source_$i" size=10 value="$form->{"source_$i"}"></td>|;
  843. $memo = qq|
  844. <td><input name="memo_$i" value="$form->{"memo_$i"}"></td>|;
  845. if ($init) {
  846. $accno = qq|
  847. <td><select name="accno_$i">$form->{selectaccno}</select></td>|;
  848. if ( $form->{selectprojectnumber} ) {
  849. $project = qq|
  850. <td><select name="projectnumber_$i">$form->{selectprojectnumber}</select></td>|;
  851. }
  852. if ( $form->{transfer} ) {
  853. $fx_transaction = qq|
  854. <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
  855. |;
  856. }
  857. }
  858. else {
  859. $form->{totaldebit} += $form->{"debit_$i"};
  860. $form->{totalcredit} += $form->{"credit_$i"};
  861. for (qw(debit credit)) {
  862. $form->{"${_}_$i"} =
  863. ( $form->{"${_}_$i"} )
  864. ? $form->format_amount( \%myconfig, $form->{"${_}_$i"}, 2 )
  865. : "";
  866. }
  867. if ( $i < $form->{rowcount} ) {
  868. $accno = qq|<td>$form->{"accno_$i"}</td>|;
  869. if ( $form->{selectprojectnumber} ) {
  870. $form->{"projectnumber_$i"} = ""
  871. if $form->{selectprojectnumber} !~
  872. /$form->{"projectnumber_$i"}/;
  873. $project = $form->{"projectnumber_$i"};
  874. $project =~ s/--.*//;
  875. $project = qq|<td>$project</td>|;
  876. }
  877. if ( $form->{transfer} ) {
  878. $checked = ( $form->{"fx_transaction_$i"} ) ? "1" : "";
  879. $x = ($checked) ? "x" : "";
  880. $fx_transaction = qq|
  881. <td><input type=hidden name="fx_transaction_$i" value="$checked">$x</td>
  882. |;
  883. }
  884. $form->hide_form( "accno_$i", "projectnumber_$i" );
  885. }
  886. else {
  887. $accno = qq|
  888. <td><select name="accno_$i">$form->{selectaccno}</select></td>|;
  889. if ( $form->{selectprojectnumber} ) {
  890. $project = qq|
  891. <td><select name="projectnumber_$i">$form->{selectprojectnumber}</select></td>|;
  892. }
  893. if ( $form->{transfer} ) {
  894. $fx_transaction = qq|
  895. <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
  896. |;
  897. }
  898. }
  899. }
  900. print qq|<tr valign=top>
  901. $accno
  902. $fx_transaction
  903. <td><input name="debit_$i" size=12 value="$form->{"debit_$i"}" accesskey=$i></td>
  904. <td><input name="credit_$i" size=12 value=$form->{"credit_$i"}></td>
  905. $source
  906. $memo
  907. $project
  908. </tr>
  909. |;
  910. }
  911. $form->hide_form(qw(rowcount selectaccno pos_adjust));
  912. print qq|
  913. <input type=hidden name=selectprojectnumber value="|
  914. . $form->escape( $form->{selectprojectnumber}, 1 ) . qq|">|;
  915. }
  916. sub form_header {
  917. $title = $form->{title};
  918. if ( $form->{transfer} ) {
  919. $form->{title} = $locale->text("$title Cash Transfer Transaction");
  920. }
  921. else {
  922. $form->{title} = $locale->text("$title General Ledger Transaction");
  923. }
  924. # $locale->text('Add Cash Transfer Transaction')
  925. # $locale->text('Edit Cash Transfer Transaction')
  926. # $locale->text('Add General Ledger Transaction')
  927. # $locale->text('Edit General Ledger Transaction')
  928. $form->{selectdepartment} = $form->unescape( $form->{selectdepartment} );
  929. $form->{selectdepartment} =~ s/ selected//;
  930. $form->{selectdepartment} =~
  931. s/(<option value="\Q$form->{department}\E")/$1 selected/;
  932. for (qw(reference description notes)) {
  933. $form->{$_} = $form->quote( $form->{$_} );
  934. }
  935. if ( ( $rows = $form->numtextrows( $form->{description}, 50 ) ) > 1 ) {
  936. $description =
  937. qq|<textarea name=description rows=$rows cols=50 wrap=soft>$form->{description}</textarea>|;
  938. }
  939. else {
  940. $description =
  941. qq|<input name=description size=50 value="$form->{description}">|;
  942. }
  943. if ( ( $rows = $form->numtextrows( $form->{notes}, 50 ) ) > 1 ) {
  944. $notes =
  945. qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|;
  946. }
  947. else {
  948. $notes = qq|<input name=notes size=50 value="$form->{notes}">|;
  949. }
  950. if (!defined $form->{approved}){
  951. $form->{approved} = '1';
  952. }
  953. $department = qq|
  954. <tr>
  955. <th align=right nowrap>| . $locale->text('Department') . qq|</th>
  956. <td><select name=department>$form->{selectdepartment}</select></td>
  957. <input type=hidden name=selectdepartment value="|
  958. . $form->escape( $form->{selectdepartment}, 1 ) . qq|">
  959. </tr>
  960. | if $form->{selectdepartment};
  961. $project = qq|
  962. <th class=listheading>| . $locale->text('Project') . qq|</th>
  963. | if $form->{selectprojectnumber};
  964. if ( $form->{transfer} ) {
  965. $fx_transaction = qq|
  966. <th class=listheading>| . $locale->text('FX') . qq|</th>
  967. |;
  968. }
  969. $focus = ( $form->{focus} ) ? $form->{focus} : "debit_$form->{rowcount}";
  970. $form->header;
  971. print qq|
  972. <body onload="document.forms[0].${focus}.focus()" />
  973. <form method=post action=$form->{script}>
  974. <input type="hidden" name="approved" value="$form->{approved}" />
  975. |;
  976. $form->hide_form(
  977. qw(batch_id id transfer selectaccno closedto locked oldtransdate recurring));
  978. print qq|
  979. <input type=hidden name=title value="$title">
  980. <table width=100%>
  981. <tr>
  982. <th class=listtop>$form->{title}</th>
  983. </tr>
  984. <tr height="5"></tr>
  985. <tr>
  986. <td>
  987. <table>
  988. <tr>
  989. <th align=right>| . $locale->text('Reference') . qq|</th>
  990. <td><input name=reference size=20 value="$form->{reference}"></td>
  991. <th align=right>| . $locale->text('Date') . qq|</th>
  992. <td><input class="date" name=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>
  993. </tr>
  994. $department
  995. <tr>
  996. <th align=right>| . $locale->text('Description') . qq|</th>
  997. <td colspan=3>$description</td>
  998. </tr>
  999. <tr>
  1000. <th align=right>| . $locale->text('Notes') . qq|</th>
  1001. <td colspan=3>$notes</td>
  1002. </tr>
  1003. </table>
  1004. </td>
  1005. </tr>
  1006. <tr>
  1007. <td>
  1008. <table width=100%>
  1009. <tr class=listheading>
  1010. <th class=listheading>| . $locale->text('Account') . qq|</th>
  1011. $fx_transaction
  1012. <th class=listheading>| . $locale->text('Debit') . qq|</th>
  1013. <th class=listheading>| . $locale->text('Credit') . qq|</th>
  1014. <th class=listheading>| . $locale->text('Source') . qq|</th>
  1015. <th class=listheading>| . $locale->text('Memo') . qq|</th>
  1016. $project
  1017. </tr>
  1018. |;
  1019. }
  1020. sub form_footer {
  1021. for (qw(totaldebit totalcredit)) {
  1022. $form->{$_} =
  1023. $form->format_amount( \%myconfig, $form->{$_}, 2, "&nbsp;" );
  1024. }
  1025. $project = qq|
  1026. <th>&nbsp;</th>
  1027. | if $form->{selectprojectnumber};
  1028. if ( $form->{transfer} ) {
  1029. $fx_transaction = qq|
  1030. <th>&nbsp;</th>
  1031. |;
  1032. }
  1033. print qq|
  1034. <tr class=listtotal>
  1035. <th>&nbsp;</th>
  1036. $fx_transaction
  1037. <th class=listtotal align=right>$form->{totaldebit}</th>
  1038. <th class=listtotal align=right>$form->{totalcredit}</th>
  1039. <th>&nbsp;</th>
  1040. <th>&nbsp;</th>
  1041. $project
  1042. </tr>
  1043. </table>
  1044. </td>
  1045. </tr>
  1046. <tr>
  1047. <td><hr size=3 noshade></td>
  1048. </tr>
  1049. </table>
  1050. |;
  1051. $form->hide_form(qw(path login sessionid callback));
  1052. $transdate = $form->datetonum( \%myconfig, $form->{transdate} );
  1053. $closedto = $form->datetonum( \%myconfig, $form->{closedto} );
  1054. # type=submit $locale->text('Update')
  1055. # type=submit $locale->text('Post')
  1056. # type=submit $locale->text('Schedule')
  1057. # type=submit $locale->text('Post as new')
  1058. # type=submit $locale->text('Delete')
  1059. if ( !$form->{readonly} ) {
  1060. %button = (
  1061. 'update' =>
  1062. { ndx => 1, key => 'U', value => $locale->text('Update') },
  1063. 'post' => { ndx => 3, key => 'O', value => $locale->text('Post') },
  1064. 'post_as_new' =>
  1065. { ndx => 6, key => 'N', value => $locale->text('Post as new') },
  1066. 'schedule' =>
  1067. { ndx => 7, key => 'H', value => $locale->text('Schedule') },
  1068. 'delete' =>
  1069. { ndx => 8, key => 'D', value => $locale->text('Delete') },
  1070. );
  1071. if ($form->{separate_duties}){
  1072. $form->hide_form('separate_duties');
  1073. $button{post}->{value} = $locale->text('Save');
  1074. }
  1075. %a = ();
  1076. if ( $form->{id} ) {
  1077. for ( 'update', 'post_as_new', 'schedule' ) { $a{$_} = 1 }
  1078. if ( !$form->{locked} ) {
  1079. if ( $transdate > $closedto ) {
  1080. for ( 'post', 'delete' ) { $a{$_} = 1 }
  1081. }
  1082. }
  1083. }
  1084. else {
  1085. if ( $transdate > $closedto ) {
  1086. for ( "update", "post", "schedule" ) { $a{$_} = 1 }
  1087. }
  1088. }
  1089. for ( keys %button ) { delete $button{$_} if !$a{$_} }
  1090. for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button )
  1091. {
  1092. $form->print_button( \%button, $_ );
  1093. }
  1094. }
  1095. if ( $form->{recurring} ) {
  1096. print qq|<div align=right>| . $locale->text('Scheduled') . qq|</div>|;
  1097. }
  1098. if ( $form->{lynx} ) {
  1099. require "bin/menu.pl";
  1100. &menubar;
  1101. }
  1102. print qq|
  1103. </form>
  1104. </body>
  1105. </html>
  1106. |;
  1107. }
  1108. sub delete {
  1109. my %hiddens;
  1110. delete $form->{action};
  1111. foreach (keys %$form) {
  1112. $hiddens{$_} = $form->{$_} unless ref $form->{$_};
  1113. }
  1114. $form->{title} = $locale->text('Confirm!');
  1115. my $query = $locale->text(
  1116. 'Are you sure you want to delete Transaction [_1]',
  1117. $form->{reference} );
  1118. my @buttons = ({
  1119. name => 'action',
  1120. value => 'delete_transaction',
  1121. text => $locale->text('Yes'),
  1122. });
  1123. my $template = LedgerSMB::Template->new_UI(
  1124. user => \%myconfig,
  1125. locale => $locale,
  1126. template => 'form-confirmation',
  1127. );
  1128. $template->render({
  1129. form => $form,
  1130. query => $query,
  1131. hiddens => \%hiddens,
  1132. buttons => \@buttons,
  1133. });
  1134. }
  1135. sub delete_transaction {
  1136. if ( GL->delete_transaction( \%myconfig, \%$form ) ) {
  1137. $form->redirect( $locale->text('Transaction deleted!') );
  1138. }
  1139. else {
  1140. $form->error( $locale->text('Cannot delete transaction!') );
  1141. }
  1142. }
  1143. sub post {
  1144. $form->isblank( "transdate", $locale->text('Transaction Date missing!') );
  1145. $transdate = $form->datetonum( \%myconfig, $form->{transdate} );
  1146. $closedto = $form->datetonum( \%myconfig, $form->{closedto} );
  1147. $form->error(
  1148. $locale->text('Cannot post transaction for a closed period!') )
  1149. if ( $transdate <= $closedto );
  1150. # add up debits and credits
  1151. for $i ( 1 .. $form->{rowcount} ) {
  1152. $dr = $form->parse_amount( \%myconfig, $form->{"debit_$i"} );
  1153. $cr = $form->parse_amount( \%myconfig, $form->{"credit_$i"} );
  1154. if ( $dr && $cr ) {
  1155. $form->error(
  1156. $locale->text(
  1157. 'Cannot post transaction with a debit and credit entry for the same account!'
  1158. )
  1159. );
  1160. }
  1161. $debit += $dr;
  1162. $credit += $cr;
  1163. }
  1164. if ( $form->round_amount( $debit, 2 ) != $form->round_amount( $credit, 2 ) )
  1165. {
  1166. $form->error( $locale->text('Out of balance transaction!') );
  1167. }
  1168. if ( !$form->{repost} ) {
  1169. if ( $form->{id} ) {
  1170. &repost;
  1171. exit;
  1172. }
  1173. }
  1174. if ( GL->post_transaction( \%myconfig, \%$form ) ) {
  1175. $form->redirect( $locale->text('Transaction posted!') );
  1176. }
  1177. else {
  1178. $form->error( $locale->text('Cannot post transaction!') );
  1179. }
  1180. }