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