summaryrefslogtreecommitdiff
path: root/bin/mozilla/gl.pl
blob: 0acfbb65140b845f0923e99b3553fa3147c03cf9 (plain)
  1. #=====================================================================
  2. # LedgerSMB
  3. # Small Medium Business Accounting software
  4. #
  5. # See COPYRIGHT file for copyright information
  6. #======================================================================
  7. #
  8. # This file has NOT undergone whitespace cleanup.
  9. #
  10. #======================================================================
  11. #
  12. # Genereal Ledger
  13. #
  14. #======================================================================
  15. use LedgerSMB::GL;
  16. use LedgerSMB::PE;
  17. require "$form->{path}/arap.pl";
  18. 1;
  19. # end of main
  20. # this is for our long dates
  21. # $locale->text('January')
  22. # $locale->text('February')
  23. # $locale->text('March')
  24. # $locale->text('April')
  25. # $locale->text('May ')
  26. # $locale->text('June')
  27. # $locale->text('July')
  28. # $locale->text('August')
  29. # $locale->text('September')
  30. # $locale->text('October')
  31. # $locale->text('November')
  32. # $locale->text('December')
  33. # this is for our short month
  34. # $locale->text('Jan')
  35. # $locale->text('Feb')
  36. # $locale->text('Mar')
  37. # $locale->text('Apr')
  38. # $locale->text('May')
  39. # $locale->text('Jun')
  40. # $locale->text('Jul')
  41. # $locale->text('Aug')
  42. # $locale->text('Sep')
  43. # $locale->text('Oct')
  44. # $locale->text('Nov')
  45. # $locale->text('Dec')
  46. sub add {
  47. $form->{title} = "Add";
  48. $form->{callback} = "$form->{script}?action=add&transfer=$form->{transfer}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};
  49. &create_links;
  50. $form->{rowcount} = ($form->{transfer}) ? 3 : 9;
  51. $form->{oldtransdate} = $form->{transdate};
  52. $form->{focus} = "reference";
  53. # departments
  54. if (@{ $form->{all_department} }) {
  55. $form->{selectdepartment} = "<option>\n";
  56. for (@{ $form->{all_department} }) { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
  57. }
  58. &display_form(1);
  59. }
  60. sub edit {
  61. &create_links;
  62. $form->{locked} = ($form->{revtrans}) ? '1' : ($form->datetonum(\%myconfig, $form->{transdate}) <= $form->datetonum(\%myconfig, $form->{closedto}));
  63. # readonly
  64. if (! $form->{readonly}) {
  65. $form->{readonly} = 1 if $myconfig{acs} =~ /General Ledger--Add Transaction/;
  66. }
  67. $form->{title} = "Edit";
  68. $i = 1;
  69. foreach $ref (@{ $form->{GL} }) {
  70. $form->{"accno_$i"} = "$ref->{accno}--$ref->{description}";
  71. $form->{"projectnumber_$i"} = "$ref->{projectnumber}--$ref->{project_id}";
  72. for (qw(fx_transaction source memo)) { $form->{"${_}_$i"} = $ref->{$_} }
  73. if ($ref->{amount} < 0) {
  74. $form->{totaldebit} -= $ref->{amount};
  75. $form->{"debit_$i"} = $ref->{amount} * -1;
  76. } else {
  77. $form->{totalcredit} += $ref->{amount};
  78. $form->{"credit_$i"} = $ref->{amount};
  79. }
  80. $i++;
  81. }
  82. $form->{rowcount} = $i;
  83. $form->{focus} = "debit_$i";
  84. &form_header;
  85. &display_rows;
  86. &form_footer;
  87. }
  88. sub create_links {
  89. GL->transaction(\%myconfig, \%$form);
  90. for (@{ $form->{all_accno} }) { $form->{selectaccno} .= "<option>$_->{accno}--$_->{description}\n" }
  91. # projects
  92. if (@{ $form->{all_project} }) {
  93. $form->{selectprojectnumber} = "<option>\n";
  94. for (@{ $form->{all_project} }) { $form->{selectprojectnumber} .= qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n| }
  95. }
  96. # departments
  97. if (@{ $form->{all_department} }) {
  98. $form->{department} = "$form->{department}--$form->{department_id}";
  99. $form->{selectdepartment} = "<option>\n";
  100. for (@{ $form->{all_department} }) { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
  101. }
  102. }
  103. sub search {
  104. $form->{title} = $locale->text('General Ledger')." ".$locale->text('Reports');
  105. $colspan = 5;
  106. $form->all_departments(\%myconfig);
  107. # departments
  108. if (@{ $form->{all_department} }) {
  109. $form->{selectdepartment} = "<option>\n";
  110. for (@{ $form->{all_department} }) { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
  111. $l_department = qq|<input name="l_department" class=checkbox type=checkbox value=Y> |.$locale->text('Department');
  112. $department = qq|
  113. <tr>
  114. <th align=right nowrap>|.$locale->text('Department').qq|</th>
  115. <td colspan=$colspan><select name=department>$form->{selectdepartment}</select></td>
  116. </tr>
  117. |;
  118. }
  119. if (@{ $form->{all_years} }) {
  120. # accounting years
  121. $form->{selectaccountingyear} = "<option>\n";
  122. for (@{ $form->{all_years} }) { $form->{selectaccountingyear} .= qq|<option>$_\n| }
  123. $form->{selectaccountingmonth} = "<option>\n";
  124. for (sort keys %{ $form->{all_month} }) { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n| }
  125. $selectfrom = qq|
  126. <tr>
  127. <th align=right>|.$locale->text('Period').qq|</th>
  128. <td colspan=$colspan>
  129. <select name=month>$form->{selectaccountingmonth}</select>
  130. <select name=year>$form->{selectaccountingyear}</select>
  131. <input name=interval class=radio type=radio value=0 checked>&nbsp;|.$locale->text('Current').qq|
  132. <input name=interval class=radio type=radio value=1>&nbsp;|.$locale->text('Month').qq|
  133. <input name=interval class=radio type=radio value=3>&nbsp;|.$locale->text('Quarter').qq|
  134. <input name=interval class=radio type=radio value=12>&nbsp;|.$locale->text('Year').qq|
  135. </td>
  136. </tr>
  137. |;
  138. }
  139. @a = ();
  140. push @a, qq|<input name="l_id" class=checkbox type=checkbox value=Y> |.$locale->text('ID');
  141. push @a, qq|<input name="l_transdate" class=checkbox type=checkbox value=Y checked> |.$locale->text('Date');
  142. push @a, qq|<input name="l_reference" class=checkbox type=checkbox value=Y checked> |.$locale->text('Reference');
  143. push @a, qq|<input name="l_description" class=checkbox type=checkbox value=Y checked> |.$locale->text('Description');
  144. push @a, qq|<input name="l_notes" class=checkbox type=checkbox value=Y> |.$locale->text('Notes');
  145. push @a, $l_department if $l_department;
  146. push @a, qq|<input name="l_debit" class=checkbox type=checkbox value=Y checked> |.$locale->text('Debit');
  147. push @a, qq|<input name="l_credit" class=checkbox type=checkbox value=Y checked> |.$locale->text('Credit');
  148. push @a, qq|<input name="l_source" class=checkbox type=checkbox value=Y checked> |.$locale->text('Source');
  149. push @a, qq|<input name="l_memo" class=checkbox type=checkbox value=Y> |.$locale->text('Memo');
  150. push @a, qq|<input name="l_accno" class=checkbox type=checkbox value=Y checked> |.$locale->text('Account');
  151. push @a, qq|<input name="l_gifi_accno" class=checkbox type=checkbox value=Y> |.$locale->text('GIFI');
  152. $form->header;
  153. print qq|
  154. <body>
  155. <form method=post action=$form->{script}>
  156. <input type=hidden name=sort value=transdate>
  157. <table width=100%>
  158. <tr>
  159. <th class=listtop>$form->{title}</th>
  160. </tr>
  161. <tr height="5"></tr>
  162. <tr>
  163. <td>
  164. <table>
  165. <tr>
  166. <th align=right>|.$locale->text('Reference').qq|</th>
  167. <td><input name=reference size=20></td>
  168. </tr>
  169. <tr>
  170. <th align=right>|.$locale->text('Source').qq|</th>
  171. <td><input name=source size=20></td>
  172. <th align=right>|.$locale->text('Memo').qq|</th>
  173. <td><input name=memo size=20></td>
  174. </tr>
  175. $department
  176. <tr>
  177. <th align=right>|.$locale->text('Description').qq|</th>
  178. <td colspan=$colspan><input name=description size=60></td>
  179. </tr>
  180. <tr>
  181. <th align=right>|.$locale->text('Notes').qq|</th>
  182. <td colspan=$colspan><input name=notes size=60></td>
  183. </tr>
  184. <tr>
  185. <th align=right>|.$locale->text('From').qq|</th>
  186. <td><input name=datefrom size=11 title="$myconfig{dateformat}"></td>
  187. <th align=right>|.$locale->text('To').qq|</th>
  188. <td><input name=dateto size=11 title="$myconfig{dateformat}"></td>
  189. </tr>
  190. $selectfrom
  191. <tr>
  192. <th align=right>|.$locale->text('Amount').qq| >=</th>
  193. <td><input name=amountfrom size=11></td>
  194. <th align=right>|.$locale->text('Amount').qq| <=</th>
  195. <td><input name=amountto size=11></td>
  196. </tr>
  197. <tr>
  198. <th align=right>|.$locale->text('Include in Report').qq|</th>
  199. <td colspan=$colspan>
  200. <table>
  201. <tr>
  202. <td>
  203. <input name="category" class=radio type=radio value=X checked>&nbsp;|.$locale->text('All').qq|
  204. <input name="category" class=radio type=radio value=A>&nbsp;|.$locale->text('Asset').qq|
  205. <input name="category" class=radio type=radio value=L>&nbsp;|.$locale->text('Liability').qq|
  206. <input name="category" class=radio type=radio value=Q>&nbsp;|.$locale->text('Equity').qq|
  207. <input name="category" class=radio type=radio value=I>&nbsp;|.$locale->text('Income').qq|
  208. <input name="category" class=radio type=radio value=E>&nbsp;|.$locale->text('Expense').qq|
  209. </td>
  210. </tr>
  211. <tr>
  212. <table>
  213. |;
  214. while (@a) {
  215. print qq|<tr>\n|;
  216. for (1 .. 5) {
  217. print qq|<td nowrap>|. shift @a;
  218. print qq|</td>\n|;
  219. }
  220. print qq|</tr>\n|;
  221. }
  222. print qq|
  223. <tr>
  224. <td nowrap><input name="l_subtotal" class=checkbox type=checkbox value=Y> |.$locale->text('Subtotal').qq|</td>
  225. </tr>
  226. </table>
  227. </tr>
  228. </table>
  229. </tr>
  230. </table>
  231. </td>
  232. </tr>
  233. <tr>
  234. <td><hr size=3 noshade></td>
  235. </tr>
  236. </table>
  237. <input type=hidden name=nextsub value=generate_report>
  238. |;
  239. $form->hide_form(qw(path login sessionid));
  240. print qq|
  241. <br>
  242. <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
  243. </form>
  244. |;
  245. if ($form->{menubar}) {
  246. require "$form->{path}/menu.pl";
  247. &menubar;
  248. }
  249. print qq|
  250. </body>
  251. </html>
  252. |;
  253. }
  254. sub generate_report {
  255. $form->{sort} = "transdate" unless $form->{sort};
  256. GL->all_transactions(\%myconfig, \%$form);
  257. $href = "$form->{script}?action=generate_report&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  258. $form->sort_order();
  259. $callback = "$form->{script}?action=generate_report&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  260. %acctype = ( 'A' => $locale->text('Asset'),
  261. 'L' => $locale->text('Liability'),
  262. 'Q' => $locale->text('Equity'),
  263. 'I' => $locale->text('Income'),
  264. 'E' => $locale->text('Expense'),
  265. );
  266. $form->{title} = $locale->text('General Ledger');
  267. $ml = ($form->{category} =~ /(A|E)/) ? -1 : 1;
  268. unless ($form->{category} eq 'X') {
  269. $form->{title} .= " : ".$locale->text($acctype{$form->{category}});
  270. }
  271. if ($form->{accno}) {
  272. $href .= "&accno=".$form->escape($form->{accno});
  273. $callback .= "&accno=".$form->escape($form->{accno},1);
  274. $option = $locale->text('Account')." : $form->{accno} $form->{account_description}";
  275. }
  276. if ($form->{gifi_accno}) {
  277. $href .= "&gifi_accno=".$form->escape($form->{gifi_accno});
  278. $callback .= "&gifi_accno=".$form->escape($form->{gifi_accno},1);
  279. $option .= "\n<br>" if $option;
  280. $option .= $locale->text('GIFI')." : $form->{gifi_accno} $form->{gifi_account_description}";
  281. }
  282. if ($form->{source}) {
  283. $href .= "&source=".$form->escape($form->{source});
  284. $callback .= "&source=".$form->escape($form->{source},1);
  285. $option .= "\n<br>" if $option;
  286. $option .= $locale->text('Source')." : $form->{source}";
  287. }
  288. if ($form->{memo}) {
  289. $href .= "&memo=".$form->escape($form->{memo});
  290. $callback .= "&memo=".$form->escape($form->{memo},1);
  291. $option .= "\n<br>" if $option;
  292. $option .= $locale->text('Memo')." : $form->{memo}";
  293. }
  294. if ($form->{reference}) {
  295. $href .= "&reference=".$form->escape($form->{reference});
  296. $callback .= "&reference=".$form->escape($form->{reference},1);
  297. $option .= "\n<br>" if $option;
  298. $option .= $locale->text('Reference')." : $form->{reference}";
  299. }
  300. if ($form->{department}) {
  301. $href .= "&department=".$form->escape($form->{department});
  302. $callback .= "&department=".$form->escape($form->{department},1);
  303. ($department) = split /--/, $form->{department};
  304. $option .= "\n<br>" if $option;
  305. $option .= $locale->text('Department')." : $department";
  306. }
  307. if ($form->{description}) {
  308. $href .= "&description=".$form->escape($form->{description});
  309. $callback .= "&description=".$form->escape($form->{description},1);
  310. $option .= "\n<br>" if $option;
  311. $option .= $locale->text('Description')." : $form->{description}";
  312. }
  313. if ($form->{notes}) {
  314. $href .= "&notes=".$form->escape($form->{notes});
  315. $callback .= "&notes=".$form->escape($form->{notes},1);
  316. $option .= "\n<br>" if $option;
  317. $option .= $locale->text('Notes')." : $form->{notes}";
  318. }
  319. if ($form->{datefrom}) {
  320. $href .= "&datefrom=$form->{datefrom}";
  321. $callback .= "&datefrom=$form->{datefrom}";
  322. $option .= "\n<br>" if $option;
  323. $option .= $locale->text('From')." ".$locale->date(\%myconfig, $form->{datefrom}, 1);
  324. }
  325. if ($form->{dateto}) {
  326. $href .= "&dateto=$form->{dateto}";
  327. $callback .= "&dateto=$form->{dateto}";
  328. if ($form->{datefrom}) {
  329. $option .= " ";
  330. } else {
  331. $option .= "\n<br>" if $option;
  332. }
  333. $option .= $locale->text('To')." ".$locale->date(\%myconfig, $form->{dateto}, 1);
  334. }
  335. if ($form->{amountfrom}) {
  336. $href .= "&amountfrom=$form->{amountfrom}";
  337. $callback .= "&amountfrom=$form->{amountfrom}";
  338. $option .= "\n<br>" if $option;
  339. $option .= $locale->text('Amount')." >= ".$form->format_amount(\%myconfig, $form->{amountfrom}, 2);
  340. }
  341. if ($form->{amountto}) {
  342. $href .= "&amountto=$form->{amountto}";
  343. $callback .= "&amountto=$form->{amountto}";
  344. if ($form->{amountfrom}) {
  345. $option .= " <= ";
  346. } else {
  347. $option .= "\n<br>" if $option;
  348. $option .= $locale->text('Amount')." <= ";
  349. }
  350. $option .= $form->format_amount(\%myconfig, $form->{amountto}, 2);
  351. }
  352. @columns = $form->sort_columns(qw(transdate id reference description notes source memo debit credit accno gifi_accno department));
  353. pop @columns if $form->{department};
  354. if ($form->{link} =~ /_paid/) {
  355. @columns = $form->sort_columns(qw(transdate id reference description notes source memo cleared debit credit accno gifi_accno));
  356. $form->{l_cleared} = "Y";
  357. }
  358. if ($form->{accno} || $form->{gifi_accno}) {
  359. @columns = grep !/(accno|gifi_accno)/, @columns;
  360. push @columns, "balance";
  361. $form->{l_balance} = "Y";
  362. }
  363. foreach $item (@columns) {
  364. if ($form->{"l_$item"} eq "Y") {
  365. push @column_index, $item;
  366. # add column to href and callback
  367. $callback .= "&l_$item=Y";
  368. $href .= "&l_$item=Y";
  369. }
  370. }
  371. if ($form->{l_subtotal} eq 'Y') {
  372. $callback .= "&l_subtotal=Y";
  373. $href .= "&l_subtotal=Y";
  374. }
  375. $callback .= "&category=$form->{category}";
  376. $href .= "&category=$form->{category}";
  377. $column_header{id} = "<th><a class=listheading href=$href&sort=id>".$locale->text('ID')."</a></th>";
  378. $column_header{transdate} = "<th><a class=listheading href=$href&sort=transdate>".$locale->text('Date')."</a></th>";
  379. $column_header{reference} = "<th><a class=listheading href=$href&sort=reference>".$locale->text('Reference')."</a></th>";
  380. $column_header{source} = "<th><a class=listheading href=$href&sort=source>".$locale->text('Source')."</a></th>";
  381. $column_header{memo} = "<th><a class=listheading href=$href&sort=memo>".$locale->text('Memo')."</a></th>";
  382. $column_header{description} = "<th><a class=listheading href=$href&sort=description>".$locale->text('Description')."</a></th>";
  383. $column_header{department} = "<th><a class=listheading href=$href&sort=department>".$locale->text('Department')."</a></th>";
  384. $column_header{notes} = "<th class=listheading>".$locale->text('Notes')."</th>";
  385. $column_header{debit} = "<th class=listheading>".$locale->text('Debit')."</th>";
  386. $column_header{credit} = "<th class=listheading>".$locale->text('Credit')."</th>";
  387. $column_header{accno} = "<th><a class=listheading href=$href&sort=accno>".$locale->text('Account')."</a></th>";
  388. $column_header{gifi_accno} = "<th><a class=listheading href=$href&sort=gifi_accno>".$locale->text('GIFI')."</a></th>";
  389. $column_header{balance} = "<th>".$locale->text('Balance')."</th>";
  390. $column_header{cleared} = qq|<th>|.$locale->text('R').qq|</th>|;
  391. $form->header;
  392. print qq|
  393. <body>
  394. <table width=100%>
  395. <tr>
  396. <th class=listtop>$form->{title}</th>
  397. </tr>
  398. <tr height="5"></tr>
  399. <tr>
  400. <td>$option</td>
  401. </tr>
  402. <tr>
  403. <td>
  404. <table width=100%>
  405. <tr class=listheading>
  406. |;
  407. for (@column_index) { print "$column_header{$_}\n" }
  408. print "
  409. </tr>
  410. ";
  411. # add sort to callback
  412. $form->{callback} = "$callback&sort=$form->{sort}";
  413. $callback = $form->escape($form->{callback});
  414. $cml = 1;
  415. # initial item for subtotals
  416. if (@{ $form->{GL} }) {
  417. $sameitem = $form->{GL}->[0]->{$form->{sort}};
  418. $cml = -1 if $form->{contra};
  419. }
  420. if (($form->{accno} || $form->{gifi_accno}) && $form->{balance}) {
  421. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  422. $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $form->{balance} * $ml * $cml, 2, 0)."</td>";
  423. $i++; $i %= 2;
  424. print qq|
  425. <tr class=listrow$i>
  426. |;
  427. for (@column_index) { print "$column_data{$_}\n" }
  428. print qq|
  429. </tr>
  430. |;
  431. }
  432. # reverse href
  433. $direction = ($form->{direction} eq 'ASC') ? "ASC" : "DESC";
  434. $form->sort_order();
  435. $href =~ s/direction=$form->{direction}/direction=$direction/;
  436. $i = 0;
  437. foreach $ref (@{ $form->{GL} }) {
  438. # if item ne sort print subtotal
  439. if ($form->{l_subtotal} eq 'Y') {
  440. if ($sameitem ne $ref->{$form->{sort}}) {
  441. &gl_subtotal;
  442. }
  443. }
  444. $form->{balance} += $ref->{amount};
  445. $subtotaldebit += $ref->{debit};
  446. $subtotalcredit += $ref->{credit};
  447. $totaldebit += $ref->{debit};
  448. $totalcredit += $ref->{credit};
  449. $ref->{debit} = $form->format_amount(\%myconfig, $ref->{debit}, 2, "&nbsp;");
  450. $ref->{credit} = $form->format_amount(\%myconfig, $ref->{credit}, 2, "&nbsp;");
  451. for (qw(id transdate)) { $column_data{$_} = "<td>$ref->{$_}</td>" }
  452. $column_data{reference} = "<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>";
  453. $ref->{notes} =~ s/\r?\n/<br>/g;
  454. for (qw(description source memo notes department)) { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
  455. $column_data{debit} = "<td align=right>$ref->{debit}</td>";
  456. $column_data{credit} = "<td align=right>$ref->{credit}</td>";
  457. $column_data{accno} = "<td><a href=$href&accno=$ref->{accno}&callback=$callback>$ref->{accno}</a></td>";
  458. $column_data{gifi_accno} = "<td><a href=$href&gifi_accno=$ref->{gifi_accno}&callback=$callback>$ref->{gifi_accno}</a>&nbsp;</td>";
  459. $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $form->{balance} * $ml * $cml, 2, 0)."</td>";
  460. $column_data{cleared} = ($ref->{cleared}) ? "<td>*</td>" : "<td>&nbsp;</td>";
  461. if ($ref->{id} != $sameid) {
  462. $i++; $i %= 2;
  463. }
  464. print "
  465. <tr class=listrow$i>";
  466. for (@column_index) { print "$column_data{$_}\n" }
  467. print "</tr>";
  468. $sameid = $ref->{id};
  469. }
  470. &gl_subtotal if ($form->{l_subtotal} eq 'Y');
  471. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  472. $column_data{debit} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $totaldebit, 2, "&nbsp;")."</th>";
  473. $column_data{credit} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $totalcredit, 2, "&nbsp;")."</th>";
  474. $column_data{balance} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $form->{balance} * $ml * $cml, 2, 0)."</th>";
  475. print qq|
  476. <tr class=listtotal>
  477. |;
  478. for (@column_index) { print "$column_data{$_}\n" }
  479. $i = 1;
  480. if ($myconfig{acs} !~ /General Ledger--General Ledger/) {
  481. $button{'General Ledger--Add Transaction'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('GL Transaction').qq|"> |;
  482. $button{'General Ledger--Add Transaction'}{order} = $i++;
  483. }
  484. if ($myconfig{acs} !~ /AR--AR/) {
  485. $button{'AR--Add Transaction'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('AR Transaction').qq|"> |;
  486. $button{'AR--Add Transaction'}{order} = $i++;
  487. $button{'AR--Sales Invoice'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Sales Invoice ').qq|"> |;
  488. $button{'AR--Sales Invoice'}{order} = $i++;
  489. }
  490. if ($myconfig{acs} !~ /AP--AP/) {
  491. $button{'AP--Add Transaction'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('AP Transaction').qq|"> |;
  492. $button{'AP--Add Transaction'}{order} = $i++;
  493. $button{'AP--Vendor Invoice'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Vendor Invoice ').qq|"> |;
  494. $button{'AP--Vendor Invoice'}{order} = $i++;
  495. }
  496. foreach $item (split /;/, $myconfig{acs}) {
  497. delete $button{$item};
  498. }
  499. print qq|
  500. </tr>
  501. </table>
  502. </td>
  503. </tr>
  504. <tr>
  505. <td><hr size=3 noshade></td>
  506. </tr>
  507. </table>
  508. <br>
  509. <form method=post action=$form->{script}>
  510. |;
  511. $form->hide_form(qw(callback path login sessionid));
  512. foreach $item (sort { $a->{order} <=> $b->{order} } %button) {
  513. print $item->{code};
  514. }
  515. if ($form->{menubar}) {
  516. require "$form->{path}/menu.pl";
  517. &menubar;
  518. }
  519. print qq|
  520. </form>
  521. </body>
  522. </html>
  523. |;
  524. }
  525. sub gl_subtotal {
  526. $subtotaldebit = $form->format_amount(\%myconfig, $subtotaldebit, 2, "&nbsp;");
  527. $subtotalcredit = $form->format_amount(\%myconfig, $subtotalcredit, 2, "&nbsp;");
  528. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  529. $column_data{debit} = "<th align=right class=listsubtotal>$subtotaldebit</td>";
  530. $column_data{credit} = "<th align=right class=listsubtotal>$subtotalcredit</td>";
  531. print "<tr class=listsubtotal>";
  532. for (@column_index) { print "$column_data{$_}\n" }
  533. print "</tr>";
  534. $subtotaldebit = 0;
  535. $subtotalcredit = 0;
  536. $sameitem = $ref->{$form->{sort}};
  537. }
  538. sub update {
  539. if ($form->{transdate} ne $form->{oldtransdate}) {
  540. if ($form->{selectprojectnumber}) {
  541. $form->all_projects(\%myconfig, undef, $form->{transdate});
  542. if (@{ $form->{all_project} }) {
  543. $form->{selectprojectnumber} = "<option>\n";
  544. for (@{ $form->{all_project} }) { $form->{selectprojectnumber} .= qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n| }
  545. $form->{selectprojectnumber} = $form->escape($form->{selectprojectnumber},1);
  546. }
  547. }
  548. $form->{oldtransdate} = $form->{transdate};
  549. }
  550. @a = ();
  551. $count = 0;
  552. @flds = qw(accno debit credit projectnumber fx_transaction source memo);
  553. for $i (1 .. $form->{rowcount}) {
  554. unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) {
  555. for (qw(debit credit)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
  556. push @a, {};
  557. $j = $#a;
  558. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  559. $count++;
  560. }
  561. }
  562. for $i (1 .. $count) {
  563. $j = $i - 1;
  564. for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
  565. }
  566. for $i ($count + 1 .. $form->{rowcount}) {
  567. for (@flds) { delete $form->{"${_}_$i"} }
  568. }
  569. $form->{rowcount} = $count + 1;
  570. &display_form;
  571. }
  572. sub display_form {
  573. my ($init) = @_;
  574. &form_header;
  575. &display_rows($init);
  576. &form_footer;
  577. }
  578. sub display_rows {
  579. my ($init) = @_;
  580. $form->{selectprojectnumber} = $form->unescape($form->{selectprojectnumber}) if $form->{selectprojectnumber};
  581. $form->{totaldebit} = 0;
  582. $form->{totalcredit} = 0;
  583. for $i (1 .. $form->{rowcount}) {
  584. $source = qq|
  585. <td><input name="source_$i" size=10 value="$form->{"source_$i"}"></td>|;
  586. $memo = qq|
  587. <td><input name="memo_$i" value="$form->{"memo_$i"}"></td>|;
  588. if ($init) {
  589. $accno = qq|
  590. <td><select name="accno_$i">$form->{selectaccno}</select></td>|;
  591. if ($form->{selectprojectnumber}) {
  592. $project = qq|
  593. <td><select name="projectnumber_$i">$form->{selectprojectnumber}</select></td>|;
  594. }
  595. if ($form->{transfer}) {
  596. $fx_transaction = qq|
  597. <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
  598. |;
  599. }
  600. } else {
  601. $form->{totaldebit} += $form->{"debit_$i"};
  602. $form->{totalcredit} += $form->{"credit_$i"};
  603. for (qw(debit credit)) { $form->{"${_}_$i"} = ($form->{"${_}_$i"}) ? $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) : "" }
  604. if ($i < $form->{rowcount}) {
  605. $accno = qq|<td>$form->{"accno_$i"}</td>|;
  606. if ($form->{selectprojectnumber}) {
  607. $form->{"projectnumber_$i"} = "" if $form->{selectprojectnumber} !~ /$form->{"projectnumber_$i"}/;
  608. $project = $form->{"projectnumber_$i"};
  609. $project =~ s/--.*//;
  610. $project = qq|<td>$project</td>|;
  611. }
  612. if ($form->{transfer}) {
  613. $checked = ($form->{"fx_transaction_$i"}) ? "1" : "";
  614. $x = ($checked) ? "x" : "";
  615. $fx_transaction = qq|
  616. <td><input type=hidden name="fx_transaction_$i" value="$checked">$x</td>
  617. |;
  618. }
  619. $form->hide_form("accno_$i", "projectnumber_$i");
  620. } else {
  621. $accno = qq|
  622. <td><select name="accno_$i">$form->{selectaccno}</select></td>|;
  623. if ($form->{selectprojectnumber}) {
  624. $project = qq|
  625. <td><select name="projectnumber_$i">$form->{selectprojectnumber}</select></td>|;
  626. }
  627. if ($form->{transfer}) {
  628. $fx_transaction = qq|
  629. <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
  630. |;
  631. }
  632. }
  633. }
  634. print qq|<tr valign=top>
  635. $accno
  636. $fx_transaction
  637. <td><input name="debit_$i" size=12 value="$form->{"debit_$i"}" accesskey=$i></td>
  638. <td><input name="credit_$i" size=12 value=$form->{"credit_$i"}></td>
  639. $source
  640. $memo
  641. $project
  642. </tr>
  643. |;
  644. }
  645. $form->hide_form(qw(rowcount selectaccno));
  646. print qq|
  647. <input type=hidden name=selectprojectnumber value="|.$form->escape($form->{selectprojectnumber},1).qq|">|;
  648. }
  649. sub form_header {
  650. $title = $form->{title};
  651. if ($form->{transfer}) {
  652. $form->{title} = $locale->text("$title Cash Transfer Transaction");
  653. } else {
  654. $form->{title} = $locale->text("$title General Ledger Transaction");
  655. }
  656. # $locale->text('Add Cash Transfer Transaction')
  657. # $locale->text('Edit Cash Transfer Transaction')
  658. # $locale->text('Add General Ledger Transaction')
  659. # $locale->text('Edit General Ledger Transaction')
  660. $form->{selectdepartment} = $form->unescape($form->{selectdepartment});
  661. $form->{selectdepartment} =~ s/ selected//;
  662. $form->{selectdepartment} =~ s/(<option value="\Q$form->{department}\E")/$1 selected/;
  663. for (qw(reference description notes)) { $form->{$_} = $form->quote($form->{$_}) }
  664. if (($rows = $form->numtextrows($form->{description}, 50)) > 1) {
  665. $description = qq|<textarea name=description rows=$rows cols=50 wrap=soft>$form->{description}</textarea>|;
  666. } else {
  667. $description = qq|<input name=description size=50 value="$form->{description}">|;
  668. }
  669. if (($rows = $form->numtextrows($form->{notes}, 50)) > 1) {
  670. $notes = qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|;
  671. } else {
  672. $notes = qq|<input name=notes size=50 value="$form->{notes}">|;
  673. }
  674. $department = qq|
  675. <tr>
  676. <th align=right nowrap>|.$locale->text('Department').qq|</th>
  677. <td><select name=department>$form->{selectdepartment}</select></td>
  678. <input type=hidden name=selectdepartment value="|.$form->escape($form->{selectdepartment},1).qq|">
  679. </tr>
  680. | if $form->{selectdepartment};
  681. $project = qq|
  682. <th class=listheading>|.$locale->text('Project').qq|</th>
  683. | if $form->{selectprojectnumber};
  684. if ($form->{transfer}) {
  685. $fx_transaction = qq|
  686. <th class=listheading>|.$locale->text('FX').qq|</th>
  687. |;
  688. }
  689. $focus = ($form->{focus}) ? $form->{focus} : "debit_$form->{rowcount}";
  690. $form->header;
  691. print qq|
  692. <body onload="document.forms[0].${focus}.focus()" />
  693. <form method=post action=$form->{script}>
  694. |;
  695. $form->hide_form(qw(id transfer selectaccno closedto locked oldtransdate recurring));
  696. print qq|
  697. <input type=hidden name=title value="$title">
  698. <table width=100%>
  699. <tr>
  700. <th class=listtop>$form->{title}</th>
  701. </tr>
  702. <tr height="5"></tr>
  703. <tr>
  704. <td>
  705. <table>
  706. <tr>
  707. <th align=right>|.$locale->text('Reference').qq|</th>
  708. <td><input name=reference size=20 value="$form->{reference}"></td>
  709. <th align=right>|.$locale->text('Date').qq|</th>
  710. <td><input name=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>
  711. </tr>
  712. $department
  713. <tr>
  714. <th align=right>|.$locale->text('Description').qq|</th>
  715. <td colspan=3>$description</td>
  716. </tr>
  717. <tr>
  718. <th align=right>|.$locale->text('Notes').qq|</th>
  719. <td colspan=3>$notes</td>
  720. </tr>
  721. </table>
  722. </td>
  723. </tr>
  724. <tr>
  725. <td>
  726. <table width=100%>
  727. <tr class=listheading>
  728. <th class=listheading>|.$locale->text('Account').qq|</th>
  729. $fx_transaction
  730. <th class=listheading>|.$locale->text('Debit').qq|</th>
  731. <th class=listheading>|.$locale->text('Credit').qq|</th>
  732. <th class=listheading>|.$locale->text('Source').qq|</th>
  733. <th class=listheading>|.$locale->text('Memo').qq|</th>
  734. $project
  735. </tr>
  736. |;
  737. }
  738. sub form_footer {
  739. for (qw(totaldebit totalcredit)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 2, "&nbsp;") }
  740. $project = qq|
  741. <th>&nbsp;</th>
  742. | if $form->{selectprojectnumber};
  743. if ($form->{transfer}) {
  744. $fx_transaction = qq|
  745. <th>&nbsp;</th>
  746. |;
  747. }
  748. print qq|
  749. <tr class=listtotal>
  750. <th>&nbsp;</th>
  751. $fx_transaction
  752. <th class=listtotal align=right>$form->{totaldebit}</th>
  753. <th class=listtotal align=right>$form->{totalcredit}</th>
  754. <th>&nbsp;</th>
  755. <th>&nbsp;</th>
  756. $project
  757. </tr>
  758. </table>
  759. </td>
  760. </tr>
  761. <tr>
  762. <td><hr size=3 noshade></td>
  763. </tr>
  764. </table>
  765. |;
  766. $form->hide_form(qw(path login sessionid callback));
  767. $transdate = $form->datetonum(\%myconfig, $form->{transdate});
  768. $closedto = $form->datetonum(\%myconfig, $form->{closedto});
  769. # type=submit $locale->text('Update')
  770. # type=submit $locale->text('Post')
  771. # type=submit $locale->text('Schedule')
  772. # type=submit $locale->text('Post as new')
  773. # type=submit $locale->text('Delete')
  774. if (! $form->{readonly}) {
  775. %button = ('Update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
  776. 'Post' => { ndx => 3, key => 'O', value => $locale->text('Post') },
  777. 'Post as new' => { ndx => 6, key => 'N', value => $locale->text('Post as new') },
  778. 'Schedule' => { ndx => 7, key => 'H', value => $locale->text('Schedule') },
  779. 'Delete' => { ndx => 8, key => 'D', value => $locale->text('Delete') },
  780. );
  781. %a = ();
  782. if ($form->{id}) {
  783. for ('Update', 'Post as new', 'Schedule') { $a{$_} = 1 }
  784. if (! $form->{locked}) {
  785. if ($transdate > $closedto) {
  786. for ('Post', 'Delete') { $a{$_} = 1 }
  787. }
  788. }
  789. } else {
  790. if ($transdate > $closedto) {
  791. for ("Update", "Post", "Schedule") { $a{$_} = 1 }
  792. }
  793. }
  794. for (keys %button) { delete $button{$_} if ! $a{$_} }
  795. for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
  796. }
  797. if ($form->{recurring}) {
  798. print qq|<div align=right>|.$locale->text('Scheduled').qq|</div>|;
  799. }
  800. if ($form->{menubar}) {
  801. require "$form->{path}/menu.pl";
  802. &menubar;
  803. }
  804. print qq|
  805. </form>
  806. </body>
  807. </html>
  808. |;
  809. }
  810. sub delete {
  811. $form->header;
  812. print qq|
  813. <body>
  814. <form method=post action=$form->{script}>
  815. |;
  816. delete $form->{action};
  817. $form->hide_form;
  818. print qq|
  819. <h2 class=confirm>|.$locale->text('Confirm!').qq|</h2>
  820. <h4>|.$locale->text('Are you sure you want to delete Transaction').qq| $form->{reference}</h4>
  821. <input name=action class=submit type=submit value="|.$locale->text('Yes').qq|">
  822. </form>
  823. |;
  824. }
  825. sub yes {
  826. if (GL->delete_transaction(\%myconfig, \%$form)) {
  827. $form->redirect($locale->text('Transaction deleted!'));
  828. } else {
  829. $form->error($locale->text('Cannot delete transaction!'));
  830. }
  831. }
  832. sub post {
  833. $form->isblank("transdate", $locale->text('Transaction Date missing!'));
  834. $transdate = $form->datetonum(\%myconfig, $form->{transdate});
  835. $closedto = $form->datetonum(\%myconfig, $form->{closedto});
  836. $form->error($locale->text('Cannot post transaction for a closed period!')) if ($transdate <= $closedto);
  837. # add up debits and credits
  838. for $i (1 .. $form->{rowcount}) {
  839. $dr = $form->parse_amount(\%myconfig, $form->{"debit_$i"});
  840. $cr = $form->parse_amount(\%myconfig, $form->{"credit_$i"});
  841. if ($dr && $cr) {
  842. $form->error($locale->text('Cannot post transaction with a debit and credit entry for the same account!'));
  843. }
  844. $debit += $dr;
  845. $credit += $cr;
  846. }
  847. if ($form->round_amount($debit, 2) != $form->round_amount($credit, 2)) {
  848. $form->error($locale->text('Out of balance transaction!'));
  849. }
  850. if (! $form->{repost}) {
  851. if ($form->{id}) {
  852. &repost;
  853. exit;
  854. }
  855. }
  856. if (GL->post_transaction(\%myconfig, \%$form)) {
  857. $form->redirect($locale->text('Transaction posted!'));
  858. } else {
  859. $form->error($locale->text('Cannot post transaction!'));
  860. }
  861. }