summaryrefslogtreecommitdiff
path: root/bin/mozilla/rc.pl
blob: 60dfc4a3561e274665c3f49ef70f6a7fab8715cc (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. # Account reconciliation module
  13. #
  14. #======================================================================
  15. use LedgerSMB::RC;
  16. 1;
  17. # end of main
  18. # this is for our long dates
  19. # $locale->text('January')
  20. # $locale->text('February')
  21. # $locale->text('March')
  22. # $locale->text('April')
  23. # $locale->text('May ')
  24. # $locale->text('June')
  25. # $locale->text('July')
  26. # $locale->text('August')
  27. # $locale->text('September')
  28. # $locale->text('October')
  29. # $locale->text('November')
  30. # $locale->text('December')
  31. # this is for our short month
  32. # $locale->text('Jan')
  33. # $locale->text('Feb')
  34. # $locale->text('Mar')
  35. # $locale->text('Apr')
  36. # $locale->text('May')
  37. # $locale->text('Jun')
  38. # $locale->text('Jul')
  39. # $locale->text('Aug')
  40. # $locale->text('Sep')
  41. # $locale->text('Oct')
  42. # $locale->text('Nov')
  43. # $locale->text('Dec')
  44. sub reconciliation {
  45. RC->paymentaccounts(\%myconfig, \%$form);
  46. $selection = "";
  47. for (@{ $form->{PR} }) { $selection .= "<option>$_->{accno}--$_->{description}\n" }
  48. $form->{title} = $locale->text('Reconciliation');
  49. if ($form->{report}) {
  50. $form->{title} = $locale->text('Reconciliation Report');
  51. $cleared = qq|
  52. <input type=hidden name=report value=1>
  53. <tr>
  54. <td align=right><input type=checkbox class=checkbox name=outstanding value=1 checked></td>
  55. <td>|.$locale->text('Outstanding').qq|</td>
  56. <td align=right><input type=checkbox class=checkbox name=cleared value=1></td>
  57. <td>|.$locale->text('Cleared').qq|</td>
  58. </tr>
  59. |;
  60. }
  61. if (@{ $form->{all_years} }) {
  62. # accounting years
  63. $form->{selectaccountingyear} = "<option>\n";
  64. for (@{ $form->{all_years} }) { $form->{selectaccountingyear} .= qq|<option>$_\n| }
  65. $form->{selectaccountingmonth} = "<option>\n";
  66. for (sort keys %{ $form->{all_month} }) { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n| }
  67. $selectfrom = qq|
  68. <tr>
  69. <th align=right>|.$locale->text('Period').qq|</th>
  70. <td colspan=3>
  71. <select name=month>$form->{selectaccountingmonth}</select>
  72. <select name=year>$form->{selectaccountingyear}</select>
  73. <input name=interval class=radio type=radio value=0 checked>&nbsp;|.$locale->text('Current').qq|
  74. <input name=interval class=radio type=radio value=1>&nbsp;|.$locale->text('Month').qq|
  75. <input name=interval class=radio type=radio value=3>&nbsp;|.$locale->text('Quarter').qq|
  76. <input name=interval class=radio type=radio value=12>&nbsp;|.$locale->text('Year').qq|
  77. </td>
  78. </tr>
  79. |;
  80. }
  81. $form->header;
  82. print qq|
  83. <body>
  84. <form method=post action=$form->{script}>
  85. <table width=100%>
  86. <tr>
  87. <th class=listtop>$form->{title}</th>
  88. </tr>
  89. <tr height="5"></tr>
  90. <tr>
  91. <td>
  92. <table>
  93. <tr>
  94. <th align=right nowrap>|.$locale->text('Account').qq|</th>
  95. <td colspan=3><select name=accno>$selection</select></td>
  96. </tr>
  97. <tr>
  98. <th align=right>|.$locale->text('From').qq|</th>
  99. <td colspan=3><input name=fromdate size=11 title="$myconfig{dateformat}"> <b>|.$locale->text('To').qq|</b> <input name=todate size=11 title="$myconfig{dateformat}"></td>
  100. </tr>
  101. $selectfrom
  102. $cleared
  103. <tr>
  104. <td></td>
  105. <td colspan=3><input type=radio style=radio name=summary value=1 checked> |.$locale->text('Summary').qq|
  106. <input type=radio style=radio name=summary value=0> |.$locale->text('Detail').qq|</td>
  107. </tr>
  108. <tr>
  109. <td></td>
  110. <td colspan=3><input type=checkbox class=checkbox name=fx_transaction value=1 checked> |.$locale->text('Include Exchange Rate Difference').qq|</td>
  111. </tr>
  112. </table>
  113. </td>
  114. </tr>
  115. <tr>
  116. <td><hr size=3 noshade></td>
  117. </tr>
  118. </table>
  119. <br>
  120. <input type=hidden name=nextsub value=get_payments>
  121. |;
  122. $form->hide_form(qw(path login sessionid));
  123. print qq|
  124. <input type=submit class=submit name=action value="|.$locale->text('Continue').qq|">
  125. </form>
  126. |;
  127. if ($form->{menubar}) {
  128. require "$form->{path}/menu.pl";
  129. &menubar;
  130. }
  131. print qq|
  132. </body>
  133. </html>
  134. |;
  135. }
  136. sub continue { &{ $form->{nextsub} } };
  137. sub get_payments {
  138. ($form->{accno}, $form->{account}) = split /--/, $form->{accno};
  139. RC->payment_transactions(\%myconfig, \%$form);
  140. $ml = ($form->{category} eq 'A') ? -1 : 1;
  141. $form->{statementbalance} = $form->{endingbalance} * $ml;
  142. if (! $form->{fx_transaction}) {
  143. $form->{statementbalance} = ($form->{endingbalance} - $form->{fx_endingbalance}) * $ml;
  144. }
  145. $form->{statementbalance} = $form->format_amount(\%myconfig, $form->{statementbalance}, 2, 0);
  146. &display_form;
  147. }
  148. sub display_form {
  149. if ($form->{report}) {
  150. @column_index = qw(transdate source name cleared debit credit);
  151. } else {
  152. @column_index = qw(transdate source name cleared debit credit balance);
  153. }
  154. $column_header{cleared} = qq|<th>|.$locale->text('R').qq|</th>|;
  155. $column_header{source} = "<th class=listheading>".$locale->text('Source')."</a></th>";
  156. $column_header{name} = "<th class=listheading>".$locale->text('Description')."</a></th>";
  157. $column_header{transdate} = "<th class=listheading>".$locale->text('Date')."</a></th>";
  158. $column_header{debit} = "<th class=listheading>".$locale->text('Debit')."</a></th>";
  159. $column_header{credit} = "<th class=listheading>".$locale->text('Credit')."</a></th>";
  160. $column_header{balance} = "<th class=listheading>".$locale->text('Balance')."</a></th>";
  161. if ($form->{fromdate}) {
  162. $option .= "\n<br>" if ($option);
  163. $option .= $locale->text('From')."&nbsp;".$locale->date(\%myconfig, $form->{fromdate}, 1);
  164. }
  165. if ($form->{todate}) {
  166. $option .= "\n<br>" if ($option);
  167. $option .= $locale->text('To')."&nbsp;".$locale->date(\%myconfig, $form->{todate}, 1);
  168. }
  169. $form->{title} = "$form->{accno}--$form->{account}";
  170. $form->header;
  171. print qq|
  172. <body>
  173. <form method=post action=$form->{script}>
  174. <table width=100%>
  175. <tr>
  176. <th class=listtop>$form->{title}</th>
  177. </tr>
  178. <tr height="5"></tr>
  179. <tr>
  180. <td>$option</td>
  181. </tr>
  182. <tr>
  183. <td>
  184. <table width=100%>
  185. <tr class=listheading>
  186. |;
  187. for (@column_index) { print "\n$column_header{$_}" }
  188. print qq|
  189. </tr>
  190. |;
  191. $ml = ($form->{category} eq 'A') ? -1 : 1;
  192. $form->{beginningbalance} *= $ml;
  193. $form->{fx_balance} *= $ml;
  194. if (! $form->{fx_transaction}) {
  195. $form->{beginningbalance} -= $form->{fx_balance};
  196. }
  197. $balance = $form->{beginningbalance};
  198. $i = 0;
  199. $j = 0;
  200. for (qw(cleared transdate source debit credit)) { $column_data{$_} = "<td>&nbsp;</td>" }
  201. if (! $form->{report}) {
  202. $column_data{name} = qq|<td>|.$locale->text('Beginning Balance').qq|</td>|;
  203. $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $balance, 2, 0)."</td>";
  204. print qq|
  205. <tr class=listrow$j>
  206. |;
  207. for (@column_index) { print "\n$column_data{$_}" }
  208. print qq|
  209. </tr>
  210. |;
  211. }
  212. foreach $ref (@{ $form->{PR} }) {
  213. $i++;
  214. if (! $form->{fx_transaction}) {
  215. next if $ref->{fx_transaction};
  216. }
  217. $checked = ($ref->{cleared}) ? "checked" : "";
  218. %temp = ();
  219. if (!$ref->{fx_transaction}) {
  220. for (qw(name source transdate)) { $temp{$_} = $ref->{$_} }
  221. }
  222. $column_data{name} = "<td>";
  223. for (@{ $temp{name} }) { $column_data{name} .= "$_<br>" }
  224. $column_data{name} .= "</td>";
  225. $column_data{source} = qq|<td>$temp{source}&nbsp;</td>
  226. <input type=hidden name="id_$i" value=$ref->{id}>|;
  227. $column_data{debit} = "<td>&nbsp;</td>";
  228. $column_data{credit} = "<td>&nbsp;</td>";
  229. $balance += $ref->{amount} * $ml;
  230. if ($ref->{amount} < 0) {
  231. $totaldebits += $ref->{amount} * -1;
  232. $column_data{debit} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount} * -1, 2, "&nbsp;")."</td>";
  233. } else {
  234. $totalcredits += $ref->{amount};
  235. $column_data{credit} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount}, 2, "&nbsp;")."</td>";
  236. }
  237. $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $balance, 2, 0)."</td>";
  238. if ($ref->{fx_transaction}) {
  239. $column_data{cleared} = ($clearfx) ? qq|<td align=center>*</td>| : qq|<td>&nbsp;</td>|;
  240. $cleared += $ref->{amount} * $ml if $clearfx;
  241. } else {
  242. if ($form->{report}) {
  243. if ($ref->{cleared}) {
  244. $column_data{cleared} = qq|<td align=center>*</td>|;
  245. $clearfx = 1;
  246. } else {
  247. $column_data{cleared} = qq|<td>&nbsp;</td>|;
  248. $clearfx = 0;
  249. }
  250. } else {
  251. if ($ref->{oldcleared}) {
  252. $cleared += $ref->{amount} * $ml;
  253. $clearfx = 1;
  254. $column_data{cleared} = qq|<td align=center>*</td>
  255. <input type=hidden name="cleared_$i" value=$ref->{cleared}>
  256. <input type=hidden name="oldcleared_$i" value=$ref->{oldcleared}>
  257. <input type=hidden name="source_$i" value="$ref->{source}">|;
  258. } else {
  259. $cleared += $ref->{amount} * $ml if $checked;
  260. $clearfx = ($checked) ? 1 : 0;
  261. $column_data{cleared} = qq|<td align=center><input name="cleared_$i" type=checkbox class=checkbox value=1 $checked>
  262. <input type=hidden name="source_$i" value="$ref->{source}"></td>|;
  263. }
  264. }
  265. }
  266. $column_data{transdate} = qq|<td>$temp{transdate}&nbsp;</td>
  267. <input type=hidden name="transdate_$i" value=$ref->{transdate}>|;
  268. $j++; $j %= 2;
  269. print qq|
  270. <tr class=listrow$j>
  271. |;
  272. for (@column_index) { print "\n$column_data{$_}" }
  273. print qq|
  274. </tr>
  275. |;
  276. }
  277. $form->{rowcount} = $i;
  278. # print totals
  279. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  280. $column_data{debit} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totaldebits, 2, "&nbsp;")."</th>";
  281. $column_data{credit} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalcredits, 2, "&nbsp;")."</th>";
  282. print qq|
  283. <tr class=listtotal>
  284. |;
  285. for (@column_index) { print "\n$column_data{$_}" }
  286. $form->{statementbalance} = $form->parse_amount(\%myconfig, $form->{statementbalance});
  287. $difference = $form->format_amount(\%myconfig, $form->{beginningbalance} + $cleared - $form->{statementbalance}, 2, 0);
  288. $form->{statementbalance} = $form->format_amount(\%myconfig, $form->{statementbalance}, 2, 0);
  289. print qq|
  290. </tr>
  291. </table>
  292. </td>
  293. </tr>
  294. |;
  295. if ($form->{report}) {
  296. print qq|
  297. </tr>
  298. </table>
  299. |;
  300. } else {
  301. print qq|
  302. <tr>
  303. <td>
  304. <table width=100%>
  305. <tr>
  306. <td align=right>
  307. <table>
  308. <tr>
  309. <th align=right nowrap>|.$locale->text('Statement Balance').qq|</th>
  310. <td width=10%></td>
  311. <td align=right><input name=statementbalance size=11 value=$form->{statementbalance}></td>
  312. </tr>
  313. <tr>
  314. <th align=right nowrap>|.$locale->text('Difference').qq|</th>
  315. <td width=10%></td>
  316. <td align=right><input name=null size=11 value=$difference></td>
  317. <input type=hidden name=difference value=$difference>
  318. </tr>
  319. </table>
  320. </td>
  321. </tr>
  322. </table>
  323. </td>
  324. </tr>
  325. <tr>
  326. <td><hr size=3 noshade></td>
  327. </tr>
  328. </table>
  329. |;
  330. $form->hide_form(qw(fx_transaction summary rowcount accno account fromdate todate path login sessionid));
  331. print qq|
  332. <br>
  333. <input type=submit class=submit name=action value="|.$locale->text('Update').qq|">
  334. <input type=submit class=submit name=action value="|.$locale->text('Select all').qq|">
  335. <input type=submit class=submit name=action value="|.$locale->text('Done').qq|">|;
  336. }
  337. if ($form->{menubar}) {
  338. require "$form->{path}/menu.pl";
  339. &menubar;
  340. }
  341. print qq|
  342. </form>
  343. </body>
  344. </html>
  345. |;
  346. }
  347. sub update {
  348. RC->payment_transactions(\%myconfig, \%$form);
  349. $i = 0;
  350. foreach $ref (@{ $form->{PR} }) {
  351. $i++;
  352. $ref->{cleared} = ($form->{"cleared_$i"}) ? 1 : 0;
  353. }
  354. &display_form;
  355. }
  356. sub select_all {
  357. RC->payment_transactions(\%myconfig, \%$form);
  358. for (@{ $form->{PR} }) { $_->{cleared} = 1 }
  359. &display_form;
  360. }
  361. sub done {
  362. $form->{callback} = "$form->{script}?path=$form->{path}&action=reconciliation&login=$form->{login}&sessionid=$form->{sessionid}";
  363. $form->error($locale->text('Out of balance!')) if ($form->{difference} *= 1);
  364. RC->reconcile(\%myconfig, \%$form);
  365. $form->redirect;
  366. }