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