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

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



Revision: 4831
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4831&view=rev
Author:   einhverfr
Date:     2012-06-04 07:48:58 +0000 (Mon, 04 Jun 2012)
Log Message:
-----------
Moving purchase history report to 1.4 framework

Modified Paths:
--------------
    trunk/Changelog
    trunk/LedgerSMB/DBObject/Report/Contact/Search.pm
    trunk/LedgerSMB/Scripts/contact_reports.pm
    trunk/LedgerSMB/Scripts/reports.pm
    trunk/UI/Reports/filters/contact_search.html
    trunk/UI/lib/report_base.html
    trunk/sql/modules/Company.sql

Added Paths:
-----------
    trunk/LedgerSMB/DBObject/Report/Contact/History.pm

Modified: trunk/Changelog
===================================================================
--- trunk/Changelog	2012-06-04 00:32:12 UTC (rev 4830)
+++ trunk/Changelog	2012-06-04 07:48:58 UTC (rev 4831)
@@ -5,8 +5,6 @@
 * scripts/* files moved to make inheritance possible (Chris T)
 * PostgreSQL contrib dependencies removed, now require Pg 8.4 (Chris T)
 * Performance enhancements on menu routines (Chris T and Steven M)
-* Projects and Departments can now have subprojects and Departments (Chris T)
-* Project/department mechanism generalized to support funds, etc (Chris T)
 * Removed the Config::Std dependency and moved to Config::General (Chris T)
 * Improved error handling using Try::Tiny and die (Chris T)
 * Added +/- selection indicators to menu CSS (Chris T)
@@ -17,6 +15,7 @@
 * Changing all auth calls to hit postgres db instead of template1 (Chris T)
 * Centralized database commit for new code (Chris T)
 * invoice.unit is now unbounded numeric to reduce errors (Chris T, 3516235)
+* Invoices with inventory subject to draft/vouchers workflows (Chris T)
 
 New Reporting Framework
 * Easy bridge between SQL and display (Chris T)

Added: trunk/LedgerSMB/DBObject/Report/Contact/History.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Report/Contact/History.pm	                        (rev 0)
+++ trunk/LedgerSMB/DBObject/Report/Contact/History.pm	2012-06-04 07:48:58 UTC (rev 4831)
@@ -0,0 +1,371 @@
+=head1 NAME
+
+LedgerSMB::DBObject::Report::Contact::History - Purchase history reports
+and more.
+
+=head1 SYNPOSIS
+
+  my $report = LedgerSMB::DBObject::Report::Contact::History->new(%$request);
+  $report->run;
+  $report->render($request, $format);
+
+=head1 DESCRIPTION
+
+This report provides purchase history reports.  It can be used to search for 
+both customers and vendors.
+
+=head1 INHERITS
+
+=over
+
+=item LedgerSMB::DBObject::Report;
+
+=back
+
+=cut
+
+package LedgerSMB::DBObject::Report::Contact::Search;
+use Moose;
+extends 'LedgerSMB::DBObject::Report';
+use LedgerSMB::App_State;
+use LedgerSMB::PGDate;
+
+my $locale = $LedgerSMB::App_State::Locale;
+
+=head1 PROPERTIES
+
+=over
+
+=item columns
+
+Read-only accessor, returns a list of columns.
+
+=over
+
+=back
+
+=cut
+
+sub columns {
+    my ($self) = @_;
+    my $script = 'contacts.pl';
+    return [
+         {col_id => 'name',
+            type => 'text',
+            name => $locale->text('Name') },
+
+         {col_id => 'meta_number',
+            type => 'text',
+            name => $locale->text('Account Number') },
+
+         {col_id => 'invnumber',
+            type => 'href',
+       href_base => 'is.pl?action=edit&id=',
+            name => $locale->text('Account Number') },
+
+         {col_id => 'curr',
+            type => 'text',
+            name => $locale->text('Currency') },
+
+         {col_id => 'partnumber',
+            type => 'text',
+            name => $locale->text('Part Number') },
+
+         {col_id => 'description',
+            type => 'text',
+            name => $locale->text('Description') },
+
+         {col_id => 'qty',
+            type => 'text',
+            name => $locale->text('Qty') },
+
+         {col_id => 'unit',
+            type => 'text',
+            name => $locale->text('Unit') },
+
+         {col_id => 'sellprice',
+            type => 'text',
+            name => $locale->text('Sell Price') },
+
+         {col_id => 'discount',
+            type => 'text',
+            name => $locale->text('Disc') },
+
+         {col_id => 'delivery_date',
+            type => 'text',
+            name => $locale->text('Delivery Date') },
+
+         {col_id => 'serialnumber',
+            type => 'text',
+            name => $locale->text('Serial Number') },
+
+         {col_id => 'exchangerate',
+            type => 'text',
+            name => $locale->text('Exchange Rate') },
+
+         {col_id => 'salesperson_name',
+            type => 'text',
+            name => $locale->text('Salesperson') },
+
+    ];
+}
+
+=item name
+
+=cut
+
+sub name { return $locale->text('Purchase History') }
+
+=item header_lines
+
+=cut
+
+sub header_lines {
+     return [
+            {name => 'name',
+             text => $locale->text('Name')},
+      
+            {name => 'meta_number',
+             text => $locale->text('Account Number')},
+            {name => 'from_date',
+             text => $locale->text('Start Date')},
+
+            {name => 'to_date',
+             text => $locale->text('End Date')},
+
+      
+      ];
+}
+
+=back
+
+=head1 CRITERIA PROPERTIES
+
+=over
+
+=item account_class
+
+The account/entity class of the contact.  Required and an exact match.
+
+=cut
+
+has account_class => (is => 'ro', isa => 'Int');
+
+=item name
+
+This is the name of the customer or vendor.  It is an exact match.
+
+=cut
+
+has name => (is => 'ro', isa => 'Maybe[Str]');
+
+=item meta_number
+
+Partial match on account number
+
+=cut
+
+has meta_number => (is => 'ro', isa => 'Maybe[Str]');
+
+=item contact_info
+
+Phone, email, etc to select on.  Partial match
+
+=cut
+
+has contact_info => (is => 'ro', isa => 'Maybe[Str]');
+
+=item address_line
+
+Partial match on any address line
+
+=cut
+
+has address_line => (is => 'ro', isa => 'Maybe[Str]');
+
+=item city
+
+Partial match on city name
+
+=cut
+
+has city => (is => 'ro', isa => 'Maybe[Str]');
+
+=item state
+
+Partial match on name of state or probince 
+
+=cut
+
+has state => (is => 'ro', isa => 'Maybe[Str]');
+
+=item zip
+
+Partial match on zip/mail_code
+
+=cut
+
+has zip => (is => 'ro', isa => 'Maybe[Str]');
+
+=item salesperson
+
+Partial match on salesperson name
+
+=cut
+
+has salesperson => (is => 'ro', isa => 'Maybe[Str]');
+
+=item notes
+
+Full text search on notes
+
+=cut
+
+has notes => (is => 'ro', isa => 'Maybe[Str]');
+
+=item country_id
+
+country id of customer
+
+=cut
+
+has country_id => (is => 'ro', isa => 'Maybe[Int]');
+
+=item from_date
+
+Include only invoices starting on this date
+
+=cut
+
+has from_date => (is => 'ro', isa => 'Maybe[LedgerSMB::PGDate]');
+
+=item to_date
+
+Include only invoices before this date
+
+=cut
+
+has to_date => (is => 'ro', isa => 'Maybe[LedgerSMB::PGDate]');
+
+=item type
+
+This is the type of document to be returned:
+
+=over
+
+=item i
+
+Invoices
+
+=item o
+
+Orders
+
+=item q
+
+Quotations
+
+=back
+
+=cut
+
+has type => (is => 'ro', isa =>'Str');
+
+=item start_from
+
+Include only customers active starting this date.
+
+=cut
+
+has start_from => (is => 'ro', isa => 'Maybe[LedgerSMB::PGDate]');
+
+=item start_to
+
+Include only customers becoming active no later than this date
+
+=cut
+
+has start_to => (is => 'ro', isa => 'Maybe[LedgerSMB::PGDate]');
+
+=item inc_open
+
+Include open invoices/orders/etc.
+
+=cut
+
+has inc_open => (is => 'ro', isa => 'Bool');
+
+=item inc_closed
+
+Include closed invoices/orders/etc.
+
+=cut
+
+has inc_closed => (is => 'ro', isa => 'Bool');
+
+
+=item is_summary
+
+If this is true it is a summary report.  Otherwise full details shown.
+
+=cut
+
+has is_summary => (is => 'ro', isa => 'Bool');
+
+=back
+
+=head1 METHODS
+
+=over 
+
+=item prepare_criteria
+
+Converts inputs to PgDate where needed
+
+=cut
+
+sub prepare_criteria {
+    my ($self, $request) = @_;
+    $request->{start_from} = LedgerSMB::PGDate->from_input(
+               $request->{start_from}
+    );
+    $request->{start_to} = LedgerSMB::PGDate->from_input(
+               $request->{start_to}
+    );
+    $request->{from_date} = LedgerSMB::PGDate->from_input(
+               $request->{from_date}
+    );
+    $request->{to_date} = LedgerSMB::PGDate->from_input(
+               $request->{to_date}
+    );
+}
+
+=item run_report
+
+Runs the report, populates rows.
+
+=cut
+
+sub run_report {
+    my ($self) = @_;
+    my $proc = 'company__history';
+    $proc .= '_summary' if $self->is_summary; 
+    my @rows = $self->exec_method({funcname => $proc});
+    for my $r(@rows){
+        $r->{invnumber_href_suffix} = $r->{invoice_id};
+    }
+    $self->rows(..hidden..);
+}
+
+=back
+
+=head1 COPYRIGHT
+
+COPYRIGHT (C) 2012 The LedgerSMB Core Team.  This file may be re-used following
+the terms of the GNU General Public License version 2 or at your option any
+later version.  Please see included LICENSE.TXT for details.
+
+=cut
+
+__PACKAGE__->meta->make_immutable;
+return 1;

Modified: trunk/LedgerSMB/DBObject/Report/Contact/Search.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Report/Contact/Search.pm	2012-06-04 00:32:12 UTC (rev 4830)
+++ trunk/LedgerSMB/DBObject/Report/Contact/Search.pm	2012-06-04 07:48:58 UTC (rev 4831)
@@ -58,12 +58,12 @@
 
        {col_id => 'entity_control_code',
             type => 'href',
-       href_base =>"contact.pl?action=get&account_class=".$self->account_class,
+       href_base =>"contact.pl?action=get&entity_class=".$self->entity_class,
             name => $locale->text('Control Code') },
 
        {col_id => 'meta_number',
             type => 'href',
-       href_base =>"contact.pl?action=get&account_class=".$self->account_class,
+       href_base =>"contact.pl?action=get&entity_class=".$self->entity_class,
             name => $locale->text('Credit Account Number') },
 
        {col_id => 'credit_description',
@@ -100,13 +100,13 @@
 
 =over
 
-=item account_class
+=item entity_class
 
 The account/entity class of the contact.  Required and an exact match.
 
 =cut
 
-has account_class => (is => 'ro', isa => 'Int');
+has entity_class => (is => 'ro', isa => 'Int');
 
 =item name_part
 

Modified: trunk/LedgerSMB/Scripts/contact_reports.pm
===================================================================
--- trunk/LedgerSMB/Scripts/contact_reports.pm	2012-06-04 00:32:12 UTC (rev 4830)
+++ trunk/LedgerSMB/Scripts/contact_reports.pm	2012-06-04 07:48:58 UTC (rev 4831)
@@ -16,9 +16,9 @@
 use LedgerSMB;
 use LedgerSMB::Template;
 use LedgerSMB::DBObject::Report::Contact::Search;
+use LedgerSMB::DBObject::Report::Contact::History;
 use strict;
 
-=pod
 
 =item search
 
@@ -35,4 +35,19 @@
     $report->render($request);
 }
 
+=item history
+
+Runs the purchase history report and displays it
+
+=cut
+
+sub history {
+    my ($request) = @_;
+
+    LedgerSMB::DBObject::Report::Contact::History->prepare_criteria($request);
+    my $report = LedgerSMB::DBObject::Report::Contact::History->new(%$request);
+    $report->run_report;
+    $report->render($request);
+}
+
 return 1;

Modified: trunk/LedgerSMB/Scripts/reports.pm
===================================================================
--- trunk/LedgerSMB/Scripts/reports.pm	2012-06-04 00:32:12 UTC (rev 4830)
+++ trunk/LedgerSMB/Scripts/reports.pm	2012-06-04 07:48:58 UTC (rev 4831)
@@ -59,6 +59,9 @@
             }
         }
     }
+    @{$request->{entity_classes}} = $request->call_procedure(
+                      procname => 'entity__list_classes'
+    );
     @{$request->{all_years}} = $request->call_procedure(
               procname => 'date_get_all_years'
     );

Modified: trunk/UI/Reports/filters/contact_search.html
===================================================================
--- trunk/UI/Reports/filters/contact_search.html	2012-06-04 00:32:12 UTC (rev 4830)
+++ trunk/UI/Reports/filters/contact_search.html	2012-06-04 07:48:58 UTC (rev 4831)
@@ -1,5 +1,6 @@
 <?lsmb INCLUDE 'ui-header.html' ?> 
-<?lsmb PROCESS elements.html ?> 
+<?lsmb PROCESS elements.html;
+       PROCESS report_base.html ?> 
 <body>
 <?lsmb 
 IF account_class == 0;
@@ -14,11 +15,6 @@
    title = text('Unsupported.  Expect errors'); #'
 END -?>
 <form method="get" action="contact_reports.pl">
-<?lsmb INCLUDE input element_data = {
-	type = "hidden"
-	name = "account_class"
-	value = account_class
-} -?>
 <table width="100%">
   <tr><th class="listtop"><?lsmb title ?></th></tr>
 
@@ -29,6 +25,7 @@
         <tr valign="top">
           <td>
             <table>
+              <?lsmb PROCESS entity_class ?>
               <tr>
                 <th align="right"><?lsmb text('Name') ?></th>
                 <td><?lsmb INCLUDE input element_data={

Modified: trunk/UI/lib/report_base.html
===================================================================
--- trunk/UI/lib/report_base.html	2012-06-04 00:32:12 UTC (rev 4830)
+++ trunk/UI/lib/report_base.html	2012-06-04 07:48:58 UTC (rev 4831)
@@ -19,6 +19,20 @@
         }; 
 END # BLOCK -?>
 
+<?lsmb- BLOCK entity_class ?>
+      <tr>
+      <th align="right"><?lsmb text('Entity Class') ?></th>
+      <td><?lsmb
+        PROCESS select element_data = {
+		name = "entity_class"
+		options = entity_classes
+		default_values = [company_entity_class]
+		text_attr = 'class'
+		value_attr = 'id'
+	} ?></td>
+       </tr>
+<?lsmb END # BLOCK -?>
+
 <?lsmb- BLOCK gifi_or_standard ?>
         <tr>
           <th align="right"><?lsmb text('Accounts') ?></th>

Modified: trunk/sql/modules/Company.sql
===================================================================
--- trunk/sql/modules/Company.sql	2012-06-04 00:32:12 UTC (rev 4830)
+++ trunk/sql/modules/Company.sql	2012-06-04 07:48:58 UTC (rev 4831)
@@ -188,6 +188,7 @@
           and (a.transdate <= $12 or $12 is null)
           and (eca.startdate >= $14 or $14 is null)
           and (eca.startdate <= $15 or $15 is null)
+          and (a.notes @@ plainto_tsquery(in_notes) or in_notes is null)
  ORDER BY eca.meta_number;
 $$ LANGUAGE SQL;
 
@@ -235,7 +236,7 @@
 
 --HV coalesce(ec.entity_class,e.entity_class) in case entity but not yet entity_credit_account
 CREATE OR REPLACE FUNCTION contact__search
-(in_account_class int, in_contact text, in_contact_info text[], 
+(in_entity_class int, in_contact text, in_contact_info text[], 
 	in_meta_number text, in_address text, in_city text, in_state text, 
 	in_mail_code text, in_country text, in_active_date_from date, 
         in_active_date_to date,
@@ -281,7 +282,7 @@
                        WHERE in_name_part IS NULL) c ON (e.id = c.entity_id)
 		LEFT JOIN entity_credit_account ec ON (ec.entity_id = e.id)
 		LEFT JOIN business b ON (ec.business_id = b.id)
-		WHERE coalesce(ec.entity_class,e.entity_class) = in_account_class
+		WHERE coalesce(ec.entity_class,e.entity_class) = in_entity_class
 			AND (c.entity_id IN (select entity_id 
                                                FROM entity_to_contact
                                               WHERE contact ILIKE 

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