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