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

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



Revision: 5540
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=5540&view=rev
Author:   einhverfr
Date:     2013-01-11 10:16:53 +0000 (Fri, 11 Jan 2013)
Log Message:
-----------
Fixing date dropdown handling

Modified Paths:
--------------
    trunk/LedgerSMB/PGDate.pm
    trunk/LedgerSMB/Report/Dates.pm
    trunk/UI/lib/report_base.html
    trunk/sql/modules/Report.sql
    trunk/sql/modules/Util.sql

Modified: trunk/LedgerSMB/PGDate.pm
===================================================================
--- trunk/LedgerSMB/PGDate.pm	2013-01-11 08:17:39 UTC (rev 5539)
+++ trunk/LedgerSMB/PGDate.pm	2013-01-11 10:16:53 UTC (rev 5540)
@@ -7,6 +7,7 @@
 use Moose;
 use DateTime::Format::Strptime;
 use Carp;
+use DateTime::Duration;
 
 BEGIN {
    use LedgerSMB::SODA;

Modified: trunk/LedgerSMB/Report/Dates.pm
===================================================================
--- trunk/LedgerSMB/Report/Dates.pm	2013-01-11 08:17:39 UTC (rev 5539)
+++ trunk/LedgerSMB/Report/Dates.pm	2013-01-11 10:16:53 UTC (rev 5540)
@@ -25,18 +25,85 @@
 
 =cut 
 
-has from_date => (is => 'ro', isa => 'LedgerSMB::Moose::Date', coerce => 1);
+has from_date => (is => 'ro', isa => 'LedgerSMB::Moose::Date', coerce => 1, 
+                lazy => 1, builder => '_get_from_date');
 
 =item to_date
 
 =cut 
 
-has to_date => (is => 'ro', isa => 'LedgerSMB::Moose::Date', coerce => 1);
+has to_date => (is => 'ro', isa => 'LedgerSMB::Moose::Date', coerce => 1,
+              lazy => 1, builder => '_get_to_date');
 
-=item ...
+=item interval string
 
+Either 'none', 'month', 'quarter', or 'year'
+
+=cut
+
+has interval => (is => 'ro', isa => 'Str', required => 0);
+
+=item from_month int
+
+1 - 12
+
+=cut
+
+has from_month => (is => 'ro', isa => 'Int', required => 0);
+
+=item from_year int
+
+=cut
+
+has from_year => (is => 'ro', isa => 'Int', required => 0);
+
+=back
+
+=cut
+
+sub _get_from_date {
+    my ($self) = @_;
+    if ($self->from_month and $self->from_year){
+        my $date_string = $self->from_year . "-" .  $self->from_month . '-01';
+        return LedgerSMB::PGDate->from_db($date_string, 'date');
+    } else {
+        my ($ref) = $self->exec_method({funcname => 'lsmb__min_date'});
+        return $ref->{lsmb__min_date};
+    }
+}
+
+sub _get_to_date {
+    my ($self) = @_;
+    if (!$self->from_month or !$self->from_year or $self->interval eq 'none'){
+        my ($ref) = $self->exec_method({funcname => 'lsmb__max_date'});
+        return $ref->{lsmb__max_date};
+    }
+    my $dateobj = $self->from_date;
+    my $date = $dateobj->from_db($dateobj->to_db, 'date'); # copy, round trip
+    if ($self->interval eq 'month'){
+       $date->date->add(months => 1);
+    } elsif ($self->interval eq 'quarter'){
+       $date->date->add(months => 3);
+    } elsif ($self->interval eq 'year'){
+       $date->date->add(years => 1);
+    }
+    $date->date->subtract(days => 1); # dates are inclusive
+    return $date;
+}
+
+before 'render' => sub { 
+              my ($self) = @_;
+              $self->from_date;
+              $self->to_date;
+};
+
+
 =head1 COPYRIGHT
 
+COPYRIGHT (C) 2012 The LedgerSMB Core Team.  This file may be re-used under the
+terms of the LedgerSMB General Public License version 2 or at your option any
+later version.  Please see enclosed LICENSE file for details.
+
 =cut
 
 1;

Modified: trunk/UI/lib/report_base.html
===================================================================
--- trunk/UI/lib/report_base.html	2013-01-11 08:17:39 UTC (rev 5539)
+++ trunk/UI/lib/report_base.html	2013-01-11 10:16:53 UTC (rev 5540)
@@ -114,7 +114,7 @@
         } ?>
 
 	<?lsmb PROCESS select element_data = {
-               name="year"
+               name="from_year"
                options = all_years
                text_attr = "date_get_all_years"
                value_attr = "date_get_all_years"

Modified: trunk/sql/modules/Report.sql
===================================================================
--- trunk/sql/modules/Report.sql	2013-01-11 08:17:39 UTC (rev 5539)
+++ trunk/sql/modules/Report.sql	2013-01-11 10:16:53 UTC (rev 5540)
@@ -280,7 +280,7 @@
 );
 
 CREATE OR REPLACE FUNCTION report__cash_summary
-(in_date_from date, in_date_to date, in_from_accno text, in_to_accno text)
+(in_from_date date, in_to_date date, in_from_accno text, in_to_accno text)
 RETURNS SETOF cash_summary_item AS 
 $$
 SELECT a.id, a.accno, a.is_heading, a.description, t.label, 
@@ -317,7 +317,7 @@
 );
 
 CREATE OR REPLACE FUNCTION report__general_balance 
-(in_date_from date, in_date_to date)
+(in_from_date date, in_to_date date)
 RETURNS SETOF general_balance_line AS
 $$
 
@@ -372,7 +372,7 @@
 (in_entity_class int, in_account_id int, in_entity_name text, 
  in_meta_number text,
  in_employee_id int, in_business_units int[], in_ship_via text, in_on_hold bool,
- in_date_from date, in_date_to date, in_partnumber text, in_parts_id int)
+ in_from_date date, in_to_date date, in_partnumber text, in_parts_id int)
 RETURNS SETOF aa_transactions_line LANGUAGE PLPGSQL AS $$
 DECLARE retval aa_transactions_line;
 
@@ -401,7 +401,7 @@
           FROM acc_trans ac
           JOIN account_link al ON ac.chart_id = al.account_id
          WHERE approved AND al.description IN ('AR', 'AP')
-               AND (in_date_to is null or transdate <= in_date_to)
+               AND (in_to_date is null or transdate <= in_to_date)
       GROUP BY trans_id) p ON p.trans_id = a.id
   JOIN entity_credit_account eca ON a.entity_credit_account = eca.id
   JOIN entity eeca ON eca.entity_id = eeca.id
@@ -420,8 +420,8 @@
        AND (in_ship_via IS NULL
           OR a.shipvia @@ plainto_tsquery(in_ship_via))
        AND (in_on_hold IS NULL OR in_on_hold = a.on_hold)
-       AND (in_date_from IS NULL OR a.transdate >= in_date_from)
-       AND (in_date_to IS NULL OR a.transdate <= in_date_to)
+       AND (in_from_date IS NULL OR a.transdate >= in_from_date)
+       AND (in_to_date IS NULL OR a.transdate <= in_to_date)
        AND p.due::numeric(100,2) <> 0
        AND (in_partnumber IS NULL 
           OR EXISTS(SELECT 1 FROM invoice inv 
@@ -441,7 +441,7 @@
 (in_entity_class int, in_account_id int, in_entity_name text, 
  in_meta_number text,
  in_employee_id int, in_business_units int[], in_ship_via text, in_on_hold bool,
- in_date_from date, in_date_to date)
+ in_from_date date, in_to_date date, in_partnumber text, in_parts_id int)
 RETURNS SETOF aa_transactions_line LANGUAGE SQL AS $$
 
 SELECT null::int as id, null::bool as invoice, entity_id, meta_number, 
@@ -452,7 +452,8 @@
        null::text as salesperson, null::text as manager, 
        null::text as shipping_point, null::text as ship_via, 
        null::text[] as business_units
-  FROM report__aa_outstanding_details($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
+  FROM report__aa_outstanding_details($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, 
+    $11, $12)
  GROUP BY meta_number, entity_name, entity_id;
 
 $$;
@@ -462,7 +463,7 @@
  in_meta_number text,
  in_employee_id int, in_manager_id int, in_invnumber text, in_ordnumber text,
  in_ponumber text, in_source text, in_description text, in_notes text, 
- in_shipvia text, in_date_from date, in_date_to date, in_on_hold bool,
+ in_shipvia text, in_from_date date, in_to_date date, in_on_hold bool,
  in_taxable bool, in_tax_account_id int)
 RETURNS SETOF aa_transactions_line LANGUAGE PLPGSQL AS $$
 
@@ -523,8 +524,8 @@
               OR a.description @@ plainto_tsquery(in_description))
        AND (in_notes IS NULL OR a.notes @@ plainto_tsquery(in_notes))
        AND (in_shipvia IS NULL OR a.shipvia @@ plainto_tsquery(in_shipvia))
-       AND (in_date_from IS NULL OR a.transdate >= in_date_from)
-       AND (in_date_to IS NULL OR a.transdate <= in_date_to)
+       AND (in_from_date IS NULL OR a.transdate >= in_from_date)
+       AND (in_to_date IS NULL OR a.transdate <= in_to_date)
        AND (in_on_hold IS NULL OR in_on_hold = a.on_hold)
        AND (in_taxable IS NULL 
             OR (in_taxable 

Modified: trunk/sql/modules/Util.sql
===================================================================
--- trunk/sql/modules/Util.sql	2013-01-11 08:17:39 UTC (rev 5539)
+++ trunk/sql/modules/Util.sql	2013-01-11 10:16:53 UTC (rev 5540)
@@ -113,4 +113,12 @@
   FROM unnest($1) e;
 $$;
 
+CREATE OR REPLACE FUNCTION lsmb__min_date() RETURNS date
+LANGUAGE SQL AS
+$$ SELECT min(transdate) from acc_trans; $$;
+
+CREATE OR REPLACE FUNCTION lsmb__max_date() RETURNS date
+LANGUAGE SQL AS
+$$ SELECT max(transdate) FROM acc_trans; $$;
+
 COMMIT;

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