[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb:[4787] trunk



Revision: 4787
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4787&view=rev
Author:   einhverfr
Date:     2012-05-27 09:13:01 +0000 (Sun, 27 May 2012)
Log Message:
-----------
Month/year/interval selection now works for GL report on 1.4

Modified Paths:
--------------
    trunk/LedgerSMB/App_State.pm
    trunk/LedgerSMB/DBObject/Report/GL.pm
    trunk/LedgerSMB/DBObject/Report.pm
    trunk/LedgerSMB/DBObject_Moose.pm
    trunk/LedgerSMB/Scripts/reports.pm
    trunk/UI/Reports/display_report.html
    trunk/UI/Reports/filters/gl.html
    trunk/UI/lib/report_base.html
    trunk/sql/modules/Report.sql

Modified: trunk/LedgerSMB/App_State.pm
===================================================================
--- trunk/LedgerSMB/App_State.pm	2012-05-27 03:07:23 UTC (rev 4786)
+++ trunk/LedgerSMB/App_State.pm	2012-05-27 09:13:01 UTC (rev 4787)
@@ -152,8 +152,65 @@
     return "$ENV{SCRIPT_NAME}?$ENV{QUERY_STRING}";
 }
 
+=item all_months(is_short $bool)
+
+Returns hashref of localized date data with following members:
+
+If $is_short is set and true, returns short names (Jan, Feb, etc) instead of 
+long names (January, February, etc).
+
+=over
+
+=item dropdown
+
+Month information in drop down format.
+
+=item hashref
+
+Month info in hashref format in 01 => January format
+
 =back
 
+=cut
+
+sub all_months {
+    my ($self, $is_short) = @_;
+    my $i18n = $Locale;
+    my $months = {
+     '01' => {long => $i18n->text('January'),   short => $i18n->text('Jan'), },
+     '02' => {long => $i18n->text('February'),  short => $i18n->text('Feb'), },
+     '03' => {long => $i18n->text('March'),     short => $i18n->text('Mar'), },
+     '04' => {long => $i18n->text('April'),     short => $i18n->text('Apr'), },
+           # XXX That's asking for trouble below.  Need to update .po files
+           # before changing however. --CT
+     '05' => {long => $i18n->text('May'),       short => $i18n->text('May'), },
+     '06' => {long => $i18n->text('June'),      short => $i18n->text('Jun'), },
+     '07' => {long => $i18n->text('July'),      short => $i18n->text('Jul'), },
+     '08' => {long => $i18n->text('August'),    short => $i18n->text('Aug'), },
+     '09' => {long => $i18n->text('September'), short => $i18n->text('Sep'), },
+     '10' => {long => $i18n->text('October'),   short => $i18n->text('Oct'), },
+     '11' => {long => $i18n->text('November'),  short => $i18n->text('Nov'), },
+     '12' => {long => $i18n->text('December'),  short => $i18n->text('Dec'), },
+    };
+
+    my $for_dropdown = [];
+    my $as_hashref = {};
+    for my $key (sort {$a cmp $b} keys %$months){
+        my $mname;
+        if ($is_short){
+           $mname = $months->{$key}->{short};
+        } else {
+           $mname = $months->{$key}->{long};
+        }
+        $as_hashref->{$key} = $mname;
+        push @$for_dropdown, {text => $mname, value => $key};
+    }
+    return { as_hashref => $as_hashref, dropdown=> $for_dropdown };
+}
+
+=back
+
+
 =head1 COPYRIGHT
 
 Copyright (C) 2009 LedgerSMB Core Team.  This file is licensed under the GNU 

Modified: trunk/LedgerSMB/DBObject/Report/GL.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Report/GL.pm	2012-05-27 03:07:23 UTC (rev 4786)
+++ trunk/LedgerSMB/DBObject/Report/GL.pm	2012-05-27 09:13:01 UTC (rev 4787)
@@ -193,9 +193,9 @@
 =cut
 
 sub header_lines {
-    return [{name => 'date_from',
+    return [{name => 'from_date',
              text => $locale->text('Start Date')},
-            {name => 'date_to',
+            {name => 'to_date',
              text => $locale->text('End Date')},
             {name => 'accno',
              text => $locale->text('Account Number')},
@@ -270,21 +270,21 @@
 
 has 'description' => (is => 'rw', isa => 'Maybe[Str]');
 
-=item date_from
+=item from_date
 
 Earliest date which matches the search
 
 =cut
 
-has 'date_from' => (is => 'rw', isa => 'Maybe[LedgerSMB::PGDate]');
+has 'from_date' => (is => 'rw', isa => 'Maybe[LedgerSMB::PGDate]');
 
-=item date_to
+=item to_date
 
 Last date that matches the search
 
 =cut
 
-has 'date_to' => (is => 'rw', isa => 'Maybe[LedgerSMB::PGDate]');
+has 'to_date' => (is => 'rw', isa => 'Maybe[LedgerSMB::PGDate]');
 
 =item approved
 
@@ -329,16 +329,7 @@
 
 sub prepare_criteria{
     my ($self, $request) = @_;
-    $request->{date_from} = LedgerSMB::PGDate->from_input(
-                               $request->{date_from}
-    );
-    $request->{date_to} = LedgerSMB::PGDate->from_input($request->{date_to});
-    $request->{amount_from} = LedgerSMB::PGNumber->from_input(
-                               $request->{amount_from}
-    );
-    $request->{amount_to} = LedgerSMB::PGNumber->from_input(
-                               $request->{amount_to}
-    );
+    $self->prepare_input($request);
     $request->{accno} =~ s/--.*$//;
 }
 

Modified: trunk/LedgerSMB/DBObject/Report.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Report.pm	2012-05-27 03:07:23 UTC (rev 4786)
+++ trunk/LedgerSMB/DBObject/Report.pm	2012-05-27 09:13:01 UTC (rev 4787)
@@ -254,8 +254,64 @@
     return ..hidden..;
 }
 
+=item prepare_input
+
+Handles from_date and to_date fields, as well as from_month, from_year, and 
+interval, setting from_date and to_date to LedgerSMB::PGDate types, and setting
+from_amount and to_amount to LedgerSMB::PGNumber types.
+
+Valid values for interval are:
+
+=over
+
+=item none 
+
+No start date, end date as first of the month
+
+=item month
+
+Valid for the month selected
+
+=item quarter
+
+Valid for the month selected and the two proceeding ones.
+
+=item year
+
+Valid for a year starting with the month selected.
+
 =back
 
+=cut
+
+sub prepare_input {
+    my ($self, $request) = @_;
+    if ($request->{from_month} and $request->{year}){
+        my $interval = $self->get_interval_dates(
+                                                  $request->{year}, 
+                                                  $request->{from_month}, 
+                                                  $request->{interval}
+        );
+        $request->{from_date} = $interval->{start};
+        $request->{to_date} = $interval->{end};
+    } else {
+        $request->{from_date} = LedgerSMB::PGDate->from_input(
+                                   $request->{from_date}
+        );
+        $request->{date_to} = LedgerSMB::PGDate->from_input(
+                                   $request->{date_to}
+        );
+    }
+    $request->{from_amount} = LedgerSMB::PGNumber->from_input(
+                               $request->{from_amount}
+    );
+    $request->{to_amount} = LedgerSMB::PGNumber->from_input(
+                               $request->{to_amount}
+    );
+}
+
+=back
+
 =head1 COPYRIGHT
 
 COPYRIGHT (C) 2012 The LedgerSMB Core Team.  This file may be re-used under the

Modified: trunk/LedgerSMB/DBObject_Moose.pm
===================================================================
--- trunk/LedgerSMB/DBObject_Moose.pm	2012-05-27 03:07:23 UTC (rev 4786)
+++ trunk/LedgerSMB/DBObject_Moose.pm	2012-05-27 09:13:01 UTC (rev 4787)
@@ -109,6 +109,28 @@
     return $dbo->is_allowed_role(@_);
 }
 
+sub get_interval_dates {
+    my ($self, $year, $month, $type) = @_;
+    my $start = "$year-$month-01"; 
+    return {start => undef, end => LedgerSMB::PGDate->from_db($start, 'date')}
+      if $type eq 'none';
+    my $dbh = $LedgerSMB::App_State::DBH;
+    my $intervals = {
+          year => '1 year',
+          month => '1 month',
+          quarter => '3 months'
+    };
+
+    my $sth = $dbh->prepare(
+           "SELECT (?::date + ?::interval - '1 day'::interval)::date"
+    );
+
+    $sth->execute($start, $intervals->{$type});
+    my ($end) = $sth->fetchrow_array();
+    return { start => LedgerSMB::PGDate->from_db($start, 'date'), 
+               end => LedgerSMB::PGDate->from_db($end, 'date') };   
+}
+
 __PACKAGE__->meta->make_immutable;
 
 1;

Modified: trunk/LedgerSMB/Scripts/reports.pm
===================================================================
--- trunk/LedgerSMB/Scripts/reports.pm	2012-05-27 03:07:23 UTC (rev 4786)
+++ trunk/LedgerSMB/Scripts/reports.pm	2012-05-27 09:13:01 UTC (rev 4787)
@@ -59,6 +59,11 @@
             }
         }
     }
+    @{$request->{all_years}} = $request->call_procedure(
+              procname => 'date_get_all_years'
+    );
+    my $months = LedgerSMB::App_State::all_months();
+    $request->{all_months} = $months->{dropdown};
     if (!$request->{report_name}){
         die $request->{_locale}->text('No report specified');
     }

Modified: trunk/UI/Reports/display_report.html
===================================================================
--- trunk/UI/Reports/display_report.html	2012-05-27 03:07:23 UTC (rev 4786)
+++ trunk/UI/Reports/display_report.html	2012-05-27 09:13:01 UTC (rev 4787)
@@ -21,7 +21,7 @@
 </div>
 <?lsmb FOREACH LINE IN hlines ?>
 <div class="report_header"><label><?lsmb LINE.text ?>:</label>
-<span class="report_header"><?lsmb request.${LINE.name} ?><?lsmb report ?></span>
+<span class="report_header"><?lsmb request.${LINE.name} ?></span>
 </div>
 <?lsmb END ?>
 <?lsmb PROCESS dynatable tbody = {rows => rows } 

Modified: trunk/UI/Reports/filters/gl.html
===================================================================
--- trunk/UI/Reports/filters/gl.html	2012-05-27 03:07:23 UTC (rev 4786)
+++ trunk/UI/Reports/filters/gl.html	2012-05-27 09:13:01 UTC (rev 4787)
@@ -1,7 +1,8 @@
 <?lsmb INCLUDE 'ui-header.html' 
        	include_script = ["UI/ajax/scriptaculous/lib/prototype.js","UI/ajax/scriptaculous/src/scriptaculous.js?load=builder,effects,dragdrop,controls","UI/ajax/helpers.js"]
 ?>
-<?lsmb PROCESS 'elements.html' ?>
+<?lsmb PROCESS 'elements.html';
+       PROCESS 'report_base.html' ?>
 <body>
 
 <form method="get" action="journal.pl">
@@ -68,79 +69,10 @@
                               size='60'
                               type='text' } ?></td>
 	</tr>
-        <?lsmb FOREACH BUC IN bu_classes ?>
-        <tr>
-          <th align="right"><?lsmb text(BUC.label) ?></th>
-          <?lsmb b_units.${BUC.id}.unshift({}) ?>
-          <td><?lsmb PROCESS select element_data = {
-                   name = 'business_unit_' _ loop.count
-                options = b_units.${BUC.id}
-              text_attr = 'text'
-             value_attr = 'id'
-                  class = 'business_unit'
-              } ?></td>
-        </tr>
-        <?lsmb END; # FOREACH BUC
-        PROCESS input element_data = {
-             type = 'hidden'
-             name = 'bc_count'
-             value = bu_classes.size
-        } ?>
+        <?lsmb PROCESS business_classes;
+               PROCESS date_row ?>
 	<tr>
 
-	  <th align="right"><?lsmb text('From') ?></th>
-	  <td><?lsmb PROCESS input element_data = {
-               class="date" 
-               name="date_from" 
-               size="11" 
-               title=datestyle } ?></td>
-	  <th align="right"><?lsmb text('To') ?></th>
-	  <td><?lsmb PROCESS input element_data = {
-                 class="date" 
-                 name="date_to" 
-                 size="11" 
-                 title=datestyle } ?></td>
-	</tr>
-	
-        <tr>
-	<th align="right"><?lsmb text('Period') ?></th>
-
-	<td colspan="5">
-        <?lsmb PROCESS select element_data = {
-               name = "month"
-               options = accountingmonths
-               text_attr = "month"
-               value_attr = "id"
-        } ?>
-
-	<?lsmb PROCESS select element_data = {
-               name="year"
-               options = all_years
-               text_attr = "year"
-               value_attr = "year"
-        } ?>
-	<?lsmb PROCESS input element_data = {
-               name="interval"
-               class="radio"
-               type="radio"
-               value="0" 
-               checked="checked" } ?>&nbsp;<?lsmb text('Current') ?>
-	<?lsmb PROCESS input element_data = { 
-               name="interval" 
-               class="radio" 
-               type="radio" 
-               value="1" } ?>&nbsp;<?lsmb text('Month') ?>
-	<?lsmb PROCESS input element_data = {
-               name="interval"
-               class="radio"
-               type="radio"
-               value="3" } ?>&nbsp;<?lsmb text('Quarter') ?>
-	<input name=interval class=radio type=radio value=12>&nbsp;Year
-	</td>
-      </tr>
-
-	<tr>
-
 	  <th align="right"><?lsmb text('Amount') ?> &gt;=</th>
 	  <td><?lsmb PROCESS input element_data = {
                      name="amountfrom" 

Modified: trunk/UI/lib/report_base.html
===================================================================
--- trunk/UI/lib/report_base.html	2012-05-27 03:07:23 UTC (rev 4786)
+++ trunk/UI/lib/report_base.html	2012-05-27 09:13:01 UTC (rev 4787)
@@ -11,7 +11,12 @@
                   class = 'business_unit'
               } ?></td>
         </tr>
-        <?lsmb END; # FOREACH BUC
+        <?lsmb END; # FOREACH BUC;
+        PROCESS input element_data = {
+             type = 'hidden'
+             name = 'bc_count'
+             value = bu_classes.size
+        }; 
 END # BLOCK -?>
 
 <?lsmb- BLOCK gifi_or_standard ?>
@@ -49,3 +54,64 @@
        </td>
 	</tr>
 <?lsmb END # BLOCK -?>
+
+<?lsmb BLOCK date_row ?>
+	<tr>
+
+	  <th align="right"><?lsmb text('From') ?></th>
+	  <td><?lsmb PROCESS input element_data = {
+               class="date" 
+               name="from_date" 
+               size="11" 
+               title=datestyle } ?></td>
+	  <th align="right"><?lsmb text('To') ?></th>
+	  <td><?lsmb PROCESS input element_data = {
+                 class="date" 
+                 name="to_date" 
+                 size="11" 
+                 title=datestyle } ?></td>
+	</tr>
+	
+        <tr>
+	<th align="right"><?lsmb text('Period') ?></th>
+
+	<td colspan="5">
+        <?lsmb 
+        all_months.unshift({});
+        all_years.unshift({}); 
+        PROCESS select element_data = {
+               name = "from_month"
+               options = all_months
+        } ?>
+
+	<?lsmb PROCESS select element_data = {
+               name="year"
+               options = all_years
+               text_attr = "date_get_all_years"
+               value_attr = "date_get_all_years"
+        } ?>
+	<?lsmb PROCESS input element_data = {
+               name="interval"
+               class="radio"
+               type="radio"
+               value="none" 
+               checked="checked" } ?>&nbsp;<?lsmb text('Current') ?>
+	<?lsmb PROCESS input element_data = { 
+               name="interval" 
+               class="radio" 
+               type="radio" 
+               value="month" } ?>&nbsp;<?lsmb text('Month') ?>
+	<?lsmb PROCESS input element_data = {
+               name="interval"
+               class="radio"
+               type="radio"
+               value="quarter" } ?>&nbsp;<?lsmb text('Quarter') ?>
+        <?lsmb PROCESS input element_data = {
+               name="interval"
+               class="radio"
+               type="radio"
+               value="year" } ?>&nbsp;<?lsmb text('Year') ?>
+              
+	</td>
+      </tr>
+<?lsmb END #BLOCK ?>

Modified: trunk/sql/modules/Report.sql
===================================================================
--- trunk/sql/modules/Report.sql	2012-05-27 03:07:23 UTC (rev 4786)
+++ trunk/sql/modules/Report.sql	2012-05-27 09:13:01 UTC (rev 4787)
@@ -176,8 +176,8 @@
 
 CREATE OR REPLACE FUNCTION report__gl
 (in_reference text, in_accno text, in_category char(1),
-in_source text, in_memo text,  in_description text, in_date_from date, 
-in_date_to date, in_approved bool, in_amount_from numeric, in_amount_to numeric,
+in_source text, in_memo text,  in_description text, in_from_date date, 
+in_to_date date, in_approved bool, in_from_amount numeric, in_to_amount numeric,
 in_business_units int[])
 RETURNS SETOF gl_report_item AS
 $$
@@ -187,11 +187,11 @@
          t_chart_id int;
 BEGIN
 
-IF in_date_from IS NULL THEN
+IF in_from_date IS NULL THEN
    t_balance := 0;
 ELSIF in_accno IS NOT NULL THEN
    SELECT id INTO t_chart_id FROM account WHERE accno  = in_accno;
-   t_balance := account__obtain_balance(in_date_from, t_accno);
+   t_balance := account__obtain_balance(in_from_date , t_accno);
 ELSE
    t_balance := null;
 END IF;
@@ -243,13 +243,13 @@
                   to_tsvector(get_default_lang()::name, g.description)
                   @@
                   plainto_tsquery(get_default_lang()::name, in_description))
-              AND (transdate BETWEEN in_date_from AND in_date_to
-                   OR (transdate >= in_date_from AND in_date_to IS NULL)
-                   OR (transdate <= in_date_to AND in_date_from IS NULL)
-                   OR (in_date_to IS NULL AND in_date_from IS NULL))
+              AND (transdate BETWEEN in_from_date AND in_to_date
+                   OR (transdate >= in_from_date AND  in_to_date IS NULL)
+                   OR (transdate <= in_to_date AND in_from_date IS NULL)
+                   OR (in_to_date IS NULL AND in_from_date IS NULL))
               AND (in_approved is false OR (g.approved AND ac.approved))
-              AND (in_amount_from IS NULL OR ac.amount >= in_amount_from)
-              AND (in_amount_to IS NULL OR ac.amount <= in_amount_to)
+              AND (in_from_amount IS NULL OR ac.amount >= in_from_amount)
+              AND (in_to_amount IS NULL OR ac.amount <= in_to_amount)
               AND (in_category = c.category OR in_category IS NULL)
      GROUP BY g.id, g.type, g.invoice, g.reference, g.description, ac.transdate,
               ac.source, ac.amount, c.accno, c.gifi_accno,

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.