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

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



Revision: 2757
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=2757&view=rev
Author:   einhverfr
Date:     2009-08-24 04:45:19 +0000 (Mon, 24 Aug 2009)

Log Message:
-----------
Adding John Worsley's 1099 reporting patch

Modified Paths:
--------------
    trunk/LedgerSMB/DBObject/Date.pm
    trunk/LedgerSMB/DBObject/TaxForm.pm
    trunk/scripts/taxform.pl

Added Paths:
-----------
    trunk/sql/modules/1099_reports.sql

Modified: trunk/LedgerSMB/DBObject/Date.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Date.pm	2009-08-21 16:04:31 UTC (rev 2756)
+++ trunk/LedgerSMB/DBObject/Date.pm	2009-08-24 04:45:19 UTC (rev 2757)
@@ -40,9 +40,20 @@
 sub build_filter_by_period {
     my ($self, $locale) = @_; 
     my @all_years = $self->call_procedure(procname => 'date_get_all_years');
+    
+    for my $day (1 .. 31) {
+      ..hidden..>{daysOptions}} , { value => $day, text => $day }
+    }
+    
     for my $ref (0 .. $#all_years) {
+      if ($all_years[$ref]{year})
+      {
         push @{$self->{yearsOptions}} , { value => $all_years[$ref]{year},
                                           text  => $all_years[$ref]{year}}
+      } else {
+        push @{$self->{yearsOptions}} , { value => $all_years[$ref]{date_get_all_years},
+                                          text  => $all_years[$ref]{date_get_all_years}}
+      }
     }
     @{$self->{monthsOptions}} = (
           { value => '01', text => $locale->text('January')},

Modified: trunk/LedgerSMB/DBObject/TaxForm.pm
===================================================================
--- trunk/LedgerSMB/DBObject/TaxForm.pm	2009-08-21 16:04:31 UTC (rev 2756)
+++ trunk/LedgerSMB/DBObject/TaxForm.pm	2009-08-24 04:45:19 UTC (rev 2757)
@@ -14,8 +14,16 @@
     $self->{taxform_id} = $ref->{'tax_form__save'};
   
     $self->{dbh}->commit();
+}
 
+sub get_forms
+{
+    my ($self) = @_;
     
+    @{$self->{forms}} = $self->exec_method(
+                funcname => 'list_taxforms',
+                args => ['1'] # lx: Inquire as to the use of this argument in this sp; currently doesn't add up in the SQL for the SP.
+    );
 }
 
 sub get_metadata
@@ -31,7 +39,3 @@
 }
 
 1;
-   
-
-    
-1;

Modified: trunk/scripts/taxform.pl
===================================================================
--- trunk/scripts/taxform.pl	2009-08-21 16:04:31 UTC (rev 2756)
+++ trunk/scripts/taxform.pl	2009-08-24 04:45:19 UTC (rev 2757)
@@ -1,10 +1,86 @@
 #!/usr/bin/perl
 
+=head1 NAME
+
+LedgerSMB::Scripts::taxform - LedgerSMB handler for reports on tax forms.
+
+=head1 SYNOPSIS
+
+Implement the ability to do end-of-year reporting on vendors as to how
+much was recorded as reportable.
+
+1) A summary report vs a detail report. 2) On the summary report, clicking
+through brings you to a detail report for that vendor. 3) On the detail
+report, clicking through brings you to the contact/account or invoice
+information depending on what one clicks.
+
+=head1 METHODS
+
+=cut
+
 package LedgerSMB::Scripts::taxform;
+our $VERSION = '1.0';
+
+use strict;
+use LedgerSMB;
+use LedgerSMB::Template;
 use LedgerSMB::DBObject::TaxForm;
+use LedgerSMB::DBObject::Date;
 use LedgerSMB::Template;
 use LedgerSMB::Form;
 
+=pod
+
+=over
+
+=item __default
+
+Display the filter screen by default.
+
+=back
+
+=cut
+
+sub __default {
+    my ($request) = @_;
+    my $template;
+    my %hits = ();
+    
+    $template = LedgerSMB::Template->new(
+            path => 'UI/taxform',
+            template => 'filter',
+	    format => 'HTML',
+    );
+    
+    # Get tax forms.
+    my $taxform = LedgerSMB::DBObject::TaxForm->new({base => $request});
+    $taxform->get_forms();
+    $request->{forms} = $taxform->{forms};
+    
+    # Lets build filter by period
+    my $locale = $request->{_locale};
+    my $date = LedgerSMB::DBObject::Date->new({base => $request});
+    $date->build_filter_by_period($locale);
+    
+    $request->{all_years} = $date->{yearsOptions};
+    $request->{accountingmonths} = $date->{monthsOptions};
+    $request->{days} = $date->{daysOptions};
+    
+    $template->render($request);
+}
+
+=pod
+
+=over
+
+=item add_taxform
+
+Display the "add taxform" view.
+
+=back
+
+=cut
+
 sub add_taxform 
 {
     my ($request) = @_;
@@ -21,6 +97,40 @@
     $template->render($taxform);
 }
 
+sub generate_report
+{
+    my ($request) = @_;
+    
+    if ($request->{meta_number})
+    {
+      my @call_args = ($request->{'tax_form_id'}, $request->{begin_month}.' '.$request->{begin_day}.' '.$request->{begin_year}, $request->{end_month}.' '.$request->{end_day}.' '.$request->{end_year}, $request->{meta_number});
+      my @results = $request->call_procedure(procname => 'tax_form_details_report', args => ..hidden.., );
+      $request->{results} = ..hidden..;
+      
+      my $template = LedgerSMB::Template->new(
+          user => $request->{_user}, 
+          locale => $request->{_locale},
+          path => 'UI',
+          template => 'taxform/details_report',
+          format => 'HTML'
+      );
+      $template->render($request);
+    } else {
+      my @call_args = ($request->{'tax_form_id'}, $request->{begin_month}.' '.$request->{begin_day}.' '.$request->{begin_year}, $request->{end_month}.' '.$request->{end_day}.' '.$request->{end_year});
+      my @results = $request->call_procedure(procname => 'tax_form_summary_report', args => ..hidden.., );
+      $request->{results} = ..hidden..;
+      
+      my $template = LedgerSMB::Template->new(
+          user => $request->{_user}, 
+          locale => $request->{_locale},
+          path => 'UI',
+          template => 'taxform/summary_report',
+          format => 'HTML'
+      );
+      $template->render($request);
+    }
+}
+
 sub save
 {
     my ($request) = @_;
@@ -38,6 +148,13 @@
     $template->render($taxform);
 }
 
+=head1 Copyright (C) 2007 The LedgerSMB Core Team
 
+Licensed under the GNU General Public License version 2 or later (at your 
+option).  For more information please see the included LICENSE and COPYRIGHT 
+files.
 
+=cut
+
+eval { do "scripts/custom/taxform.pl"};
 1;

Added: trunk/sql/modules/1099_reports.sql
===================================================================
--- trunk/sql/modules/1099_reports.sql	                        (rev 0)
+++ trunk/sql/modules/1099_reports.sql	2009-08-24 04:45:19 UTC (rev 2757)
@@ -0,0 +1,48 @@
+CREATE TYPE tax_form_report_item AS (legal_name text, entity_id integer, entity_class integer, control_code text, meta_number character varying(32), acc_sum numeric, invoice_sum numeric, total_sum numeric);
+CREATE TYPE tax_form_report_detail_item AS (legal_name text, entity_id integer, entity_class integer, control_code text, meta_number character varying(32), acc_sum numeric, invoice_sum numeric, total_sum numeric, invnumber text, duedate text);
+
+CREATE OR REPLACE FUNCTION tax_form_summary_report(in_tax_form_id int, in_begin date, in_end date) RETURNS setof tax_form_report_item AS $$
+DECLARE
+	out_row tax_form_report_item;
+BEGIN
+	FOR out_row IN SELECT company.legal_name, company.entity_id, entity_credit_account.entity_class, entity.control_code, entity_credit_account.meta_number, sum(CASE WHEN ac_tax_form.reportable THEN acc_trans.amount ELSE 0 END), sum(CASE WHEN invoice_tax_form.reportable THEN invoice.sellprice * invoice.qty ELSE 0 END), sum(CASE WHEN ac_tax_form.reportable THEN acc_trans.amount ELSE 0 END) + sum(CASE WHEN invoice_tax_form.reportable THEN invoice.sellprice * invoice.qty ELSE 0 END)
+		FROM acc_trans
+		JOIN (select id, entity_credit_account FROM ar UNION select id, entity_credit_account from ap) gl ON (gl.id = acc_trans.trans_id)
+		LEFT JOIN ac_tax_form ON (acc_trans.entry_id = ac_tax_form.entry_id AND ac_tax_form.reportable)
+		LEFT JOIN invoice ON (invoice.id = acc_trans.invoice_id) 
+		LEFT JOIN invoice_tax_form ON (invoice.id = invoice_tax_form.invoice_id AND invoice_tax_form.reportable)  
+		JOIN entity_credit_account ON (gl.entity_credit_account = entity_credit_account.id) 
+		JOIN entity ON (entity.id = entity_credit_account.entity_id) 
+		JOIN company ON (entity.id = company.entity_id)
+		JOIN country_tax_form ON (entity_credit_account.taxform_id = country_tax_form.id)
+		WHERE country_tax_form.id = in_tax_form_id
+		AND transdate BETWEEN in_begin AND in_end
+		GROUP BY legal_name, meta_number, company.entity_id, entity_credit_account.entity_class, entity.control_code
+	LOOP
+		RETURN NEXT out_row;
+	END LOOP;
+END;
+$$ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION tax_form_details_report(in_tax_form_id int, in_begin date, in_end date, in_meta_number integer) RETURNS setof tax_form_report_detail_item AS $$
+DECLARE
+	out_row tax_form_report_detail_item;
+BEGIN
+	FOR out_row IN SELECT company.legal_name, company.entity_id, entity_credit_account.entity_class, entity.control_code, entity_credit_account.meta_number, sum(CASE WHEN ac_tax_form.reportable THEN acc_trans.amount ELSE 0 END), sum(CASE WHEN invoice_tax_form.reportable THEN invoice.sellprice * invoice.qty ELSE 0 END), sum(CASE WHEN ac_tax_form.reportable THEN acc_trans.amount ELSE 0 END) + sum(CASE WHEN invoice_tax_form.reportable THEN invoice.sellprice * invoice.qty ELSE 0 END), gl.invnumber, gl.duedate::text
+		FROM acc_trans
+                JOIN (select id, entity_credit_account, invnumber, duedate FROM ar UNION select id, entity_credit_account, invnumber, duedate FROM ap) gl ON (gl.id = acc_trans.trans_id)
+		LEFT JOIN ac_tax_form ON (acc_trans.entry_id = ac_tax_form.entry_id AND ac_tax_form.reportable)
+		LEFT JOIN invoice ON (invoice.id = acc_trans.invoice_id) 
+		LEFT JOIN invoice_tax_form ON (invoice.id = invoice_tax_form.invoice_id AND invoice_tax_form.reportable)  
+		JOIN entity_credit_account ON (gl.entity_credit_account = entity_credit_account.id) 
+		JOIN entity ON (entity.id = entity_credit_account.entity_id) 
+		JOIN company ON (entity.id = company.entity_id)
+		JOIN country_tax_form ON (entity_credit_account.taxform_id = country_tax_form.id)
+		WHERE country_tax_form.id = in_tax_form_id AND meta_number = in_meta_number
+		AND transdate BETWEEN in_begin AND in_end
+		GROUP BY legal_name, meta_number, company.entity_id, entity_credit_account.entity_class, entity.control_code, gl.invnumber, gl.duedate
+	LOOP
+		RETURN NEXT out_row;
+	END LOOP;
+END;
+$$ LANGUAGE plpgsql;


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