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