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