summaryrefslogtreecommitdiff
path: root/bin/ca.pl
blob: fba81cab7d417d5c044e728d2c5d1ce8ceeb768c (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. # module for Chart of Accounts, Income Statement and Balance Sheet
  44. # search and edit transactions posted by the GL, AR and AP
  45. #
  46. #======================================================================
  47. use LedgerSMB::CA;
  48. use LedgerSMB::Template;
  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 chart_of_accounts {
  78. CA->all_accounts( \%myconfig, \%$form );
  79. my %hiddens;
  80. @column_index = qw(accno gifi_accno description debit credit);
  81. $column_header{accno} = $locale->text('Account');
  82. $column_header{gifi_accno} = $locale->text('GIFI');
  83. $column_header{description} = $locale->text('Description');
  84. $column_header{debit} = $locale->text('Debit');
  85. $column_header{credit} = $locale->text('Credit');
  86. $form->{title} = $locale->text('Chart of Accounts');
  87. $form->{callback} =
  88. qq|$form->{script}?path=$form->{path}&action=chart_of_accounts&login=$form->{login}&sessionid=$form->{sessionid}|;
  89. $hiddens{callback} = $form->{callback};
  90. $hiddens{path} = $form->{path};
  91. $hiddens{action} = 'chart_of_accounts';
  92. $hiddens{login} = $form->{login};
  93. $hiddens{sessionid} = $form->{sessionid};
  94. my @rows;
  95. my $totaldebit = 0;
  96. my $totalcredit = 0;
  97. foreach my $ca ( @{ $form->{CA} } ) {
  98. my %column_data;
  99. my $description = $form->escape( $ca->{description} );
  100. my $gifi_description = $form->escape( $ca->{gifi_description} );
  101. my $href =
  102. qq|$form->{script}?path=$form->{path}&action=list&accno=$ca->{accno}&login=$form->{login}&sessionid=$form->{sessionid}&description=$description&gifi_accno=$ca->{gifi_accno}&gifi_description=$gifi_description|;
  103. if ( $ca->{charttype} eq "H" ) {
  104. $column_data{class} = 'heading';
  105. for (qw(accno description)) {
  106. $column_data{$_} = $ca->{$_};
  107. }
  108. $column_data{gifi_accno} = $ca->{gifi_accno};
  109. }
  110. else {
  111. $i++;
  112. $i %= 2;
  113. $column_data{i} = $i;
  114. $column_data{accno} = {
  115. text => $ca->{accno},
  116. href => $href};
  117. $column_data{gifi_accno} = {
  118. text => $ca->{gifi_accno},
  119. href => "$href&accounttype=gifi"};
  120. $column_data{description} = $ca->{description};
  121. }
  122. $column_data{debit} =
  123. $form->format_amount( \%myconfig, $ca->{debit}, 2, " " );
  124. $column_data{credit} =
  125. $form->format_amount( \%myconfig, $ca->{credit}, 2, " " );
  126. $totaldebit += $ca->{debit};
  127. $totalcredit += $ca->{credit};
  128. push @rows, \%column_data;
  129. }
  130. for (qw(accno gifi_accno description)) {
  131. $column_data{$_} = " ";
  132. }
  133. $column_data{debit} = $form->format_amount( \%myconfig, $totaldebit, 2, 0 );
  134. $column_data{credit} = $form->format_amount(\%myconfig, $totalcredit, 2, 0);
  135. my @buttons;
  136. push @buttons, {
  137. name => 'action',
  138. value => 'csv_chart_of_accounts',
  139. text => $locale->text('CSV Report'),
  140. type => 'submit',
  141. class => 'submit',
  142. };
  143. my $template = LedgerSMB::Template->new(
  144. user => \%myconfig,
  145. locale => $locale,
  146. path => 'UI',
  147. template => 'form-dynatable',
  148. format => ($form->{action} =~ /^csv/)? 'CSV': 'HTML');
  149. $template->render({
  150. form => \%$form,
  151. buttons => \@buttons,
  152. hiddens => \%hiddens,
  153. columns => \@column_index,
  154. heading => \%column_header,
  155. totals => \%column_data,
  156. rows => \@rows,
  157. row_alignment => {'credit' => 'right', 'debit' => 'right'},
  158. });
  159. }
  160. sub csv_chart_of_accounts { &chart_of_accounts }
  161. sub list {
  162. $form->{title} = $locale->text('List Transactions');
  163. if ( $form->{accounttype} eq 'gifi' ) {
  164. $form->{title} .= " - "
  165. . $locale->text('GIFI')
  166. . " $form->{gifi_accno} - $form->{gifi_description}";
  167. }
  168. else {
  169. $form->{title} .= " - "
  170. . $locale->text('Account')
  171. . " $form->{accno} - $form->{description}";
  172. }
  173. # get departments
  174. $form->all_departments( \%myconfig );
  175. my $selectdepartment;
  176. if ( @{ $form->{all_department} } ) {
  177. $selectdepartment = {name => 'department', options => []};
  178. for ( @{ $form->{all_department} } ) {
  179. push @{$selectdepartment->{options}}, {
  180. value => "$_->{description}--$_->{id}",
  181. text => $_->{description}};
  182. }
  183. }
  184. my $selectmonth;
  185. my $selectyear;
  186. my $interval;
  187. if ( @{ $form->{all_years} } ) {
  188. # accounting years
  189. $selectyear = {name => 'year', options => []};
  190. for ( @{ $form->{all_years} } ) {
  191. push @{$selectyear->{options}}, {value => $_, text => $_};
  192. }
  193. $selectmonth = {name => 'month', options => []};
  194. for ( sort keys %{ $form->{all_month} } ) {
  195. push @{$selectmonth->{options}}, {value => $_,
  196. text => $locale->text($form->{all_month}{$_})};
  197. }
  198. $intervals = [
  199. {type => 'radio', name => 'interval', value => '0',
  200. checked => 'checked', text => $locale->text('Current')},
  201. {type => 'radio', name => 'interval', value => '1',
  202. text => $locale->text('Month')},
  203. {type => 'radio', name => 'interval', value => '3',
  204. text => $locale->text('Quarter')},
  205. {type => 'radio', name => 'interval', value => '12',
  206. text => $locale->text('Year')}];
  207. }
  208. my @includes = ({
  209. type => 'checkbox',
  210. name => 'l_accno',
  211. value => 'Y',
  212. text => $locale->text('AR/AP'),
  213. },{
  214. type => 'checkbox',
  215. name => 'l_subtotal',
  216. value => 'Y',
  217. text => $locale->text('Subtotal'),
  218. });
  219. my $template = LedgerSMB::Template->new_UI(
  220. user => \%myconfig,
  221. locale => $locale,
  222. template => 'ca-list-selector');
  223. $template->render({
  224. form => $form,
  225. includes => \@includes,
  226. selectmonth => $selectmonth,
  227. selectyear => $selectyear,
  228. selectdepartment => $selectdepartment,
  229. intervals => $intervals,
  230. });
  231. }
  232. sub ca_subtotal {
  233. my %column_data;
  234. for (@column_index) { $column_data{$_} = " " }
  235. $column_data{debit} =
  236. $form->format_amount( \%myconfig, $subtotaldebit, 2, " " );
  237. $column_data{credit} =
  238. $form->format_amount( \%myconfig, $subtotalcredit, 2, " " );
  239. $subtotaldebit = 0;
  240. $subtotalcredit = 0;
  241. $sameitem = $ca->{ $form->{sort} };
  242. $column_data{is_subtotal} = 1;
  243. return \%column_data;
  244. }