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

SF.net SVN: ledger-smb:[2780] addons/1.3/templatetrans/trunk



Revision: 2780
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=2780&view=rev
Author:   einhverfr
Date:     2009-11-05 20:45:26 +0000 (Thu, 05 Nov 2009)

Log Message:
-----------
Correcting a few more versioning issues with template transactions

Modified Paths:
--------------
    addons/1.3/templatetrans/trunk/LedgerSMB/DBObject/TransTemplate.pm
    addons/1.3/templatetrans/trunk/patches/aa_gl.patch
    addons/1.3/templatetrans/trunk/scripts/transtemplate.pl
    addons/1.3/templatetrans/trunk/sql/modules/trans-functions.sql

Modified: addons/1.3/templatetrans/trunk/LedgerSMB/DBObject/TransTemplate.pm
===================================================================
--- addons/1.3/templatetrans/trunk/LedgerSMB/DBObject/TransTemplate.pm	2009-11-05 20:43:24 UTC (rev 2779)
+++ addons/1.3/templatetrans/trunk/LedgerSMB/DBObject/TransTemplate.pm	2009-11-05 20:45:26 UTC (rev 2780)
@@ -4,15 +4,29 @@
 
 sub save {
    my $self = shift @_;
-   $self->exec_method(funcname => 'journal__add');
+   $self->{is_template} = '1';
+   $self->{approved} = 0;
+   my ($ref) = $self->exec_method(funcname => 'journal__add');
+   $self->merge($ref);
+   $self->{journal_id} = $self->{id};
+   $self->debug({file => '/tmp/temptrans'});
    for my $line (@{$self->{journal_lines}}){
-       my $l = $line, 'LedgerSMB::DBObject';
+       my $l = bless $line, 'LedgerSMB::DBObject';
+       $l->{_locale} = $self->{_locale};
+       $l->{dbh} = $self->{dbh};
+       $l->{journal_id} = $self->{id};
+       my ($ref) = $l->exec_method(funcname => 'account__get_from_accno');
+       $l->{account_id} = $ref->{id};
+       print STDERR "$l->{accno}\n";
+       if (!$ref->{id}){
+           $self->error($self->{_locale}->text('No Account id for [_1]', $l->{accno}));
+       }
        $l->exec_method(funcname=> 'journal__add_line');
    } 
    if ($self->{is_invoice}){
        $self->exec_method(funcname => 'journal__make_invoice');
    }
-   $self->commit;
+   $self->{dbh}->commit;
 }
 
 sub search {

Modified: addons/1.3/templatetrans/trunk/patches/aa_gl.patch
===================================================================
--- addons/1.3/templatetrans/trunk/patches/aa_gl.patch	2009-11-05 20:43:24 UTC (rev 2779)
+++ addons/1.3/templatetrans/trunk/patches/aa_gl.patch	2009-11-05 20:45:26 UTC (rev 2780)
@@ -1,6 +1,6 @@
 Index: bin/aa.pl
 ===================================================================
---- bin/aa.pl	(revision 2770)
+--- bin/aa.pl	(revision 2777)
 +++ bin/aa.pl	(working copy)
 @@ -959,6 +959,8 @@
  
@@ -11,7 +11,7 @@
          );
          if (!$form->{approved} && !$form->{batch_id}){
             $button{approve} = { 
-@@ -1028,6 +1030,22 @@
+@@ -1028,6 +1030,42 @@
  |;
  }
  
@@ -21,11 +21,31 @@
 +    my $lsmb = LedgerSMB->new();
 +    $lsmb->merge($form);
 +    $lsmb->{is_invoice} = 1;
++    my ($department_name, $department_id) = split/--/, $form->{department};
++     if (!$lsmb->{language_code}){
++        delete $lsmb->{language_code};
++    }
++    $lsmb->{credit_id} = $form->{"$form->{vc}_id"};
++    $lsmb->{department_id} = $department_id;
 +    if ($form->{arap} eq 'ar'){
 +        $lsmb->{entity_class} = 2;
 +    } else {
 +        $lsmb->{entity_class} = 1;
 +    }
++    $lsmb->{transaction_date} = $form->{transdate}; 
++    for my $iter (0 .. $form->{rowcount}){
++        if ($form->{"accno_$iter"} and 
++                  ($form->{"amount_$iter"} != 0)){
++             my ($acc_id, $acc_name) = split /--/, $form->{"accno_$iter"};
++             my $amount = $form->{"credit_$iter"} || ( $form->{"debit_$iter"} 
++                                                     * -1 );
++             push @{$lsmb->{journal_lines}}, 
++                  {accno => $acc_id,
++                   amount => $amount, 
++                   cleared => false,
++                  };
++        }
++    }
 +    $template = LedgerSMB::DBObject::TransTemplate->new(base => $lsmb);
 +    $template->save;
 +    $form->redirect( $locale->text('Template Saved!') );
@@ -36,7 +56,7 @@
      use LedgerSMB;
 Index: bin/gl.pl
 ===================================================================
---- bin/gl.pl	(revision 2770)
+--- bin/gl.pl	(revision 2777)
 +++ bin/gl.pl	(working copy)
 @@ -241,6 +241,10 @@
  		  'update' =>
@@ -57,15 +77,7 @@
  	      if ( $form->{id} ) {
  
  		  for ( 'update', 'post_as_new', 'schedule' ) { $a{$_} = 1 }
-@@ -301,6 +306,7 @@
- 				  accesskey => $button{$_}->{key},
- 				  order => $i
- 						};
-+				 print STDERR $button{$_}->{value};
- 				  $i++;
- 	      }
- 
-@@ -334,7 +340,17 @@
+@@ -334,7 +339,37 @@
  }
   
  
@@ -73,7 +85,27 @@
 +    use LedgerSMB;
 +    use LedgerSMB::DBObject::TransTemplate;
 +    my $lsmb = LedgerSMB->new();
++    my ($department_name, $department_id) = split/--/, $form->{department};
++    $lsmb->{department_id} = $department_id;
++    $lsmb->{source} = $form->{reference};
++    $lsmb->{description} = $form->{description};
++    $lsmb->{department_id} = $department_id;
++    $lsmb->{transaction_date} = $form->{transdate};
 +    $lsmb->{type} = 'gl';
++    $lsmb->{journal_lines} = [];
++    for my $iter (0 .. $form->{rowcount}){
++        if ($form->{"accno_$iter"} and 
++                  (($form->{"credit_$iter"} != 0) or ($form->{"debit_$iter"} != 0))){
++             my ($acc_id, $acc_name) = split /--/, $form->{"accno_$iter"};
++             my $amount = $form->{"credit_$iter"} || ( $form->{"debit_$iter"} 
++                                                     * -1 );
++             push @{$lsmb->{journal_lines}}, 
++                  {accno => $acc_id,
++                   amount => $amount, 
++                   cleared => false,
++                  };
++        }
++    }
 +    $template = LedgerSMB::DBObject::TransTemplate->new(base => $lsmb);
 +    $template->save;
 +    $form->redirect( $locale->text('Template Saved!') );

Modified: addons/1.3/templatetrans/trunk/scripts/transtemplate.pl
===================================================================
--- addons/1.3/templatetrans/trunk/scripts/transtemplate.pl	2009-11-05 20:43:24 UTC (rev 2779)
+++ addons/1.3/templatetrans/trunk/scripts/transtemplate.pl	2009-11-05 20:45:26 UTC (rev 2780)
@@ -1,9 +1,12 @@
 
 package LedgerSMB::Scripts::transtemplate;
 use LedgerSMB::DBObject::TransTemplate;
+use LedgerSMB::Template;
 our $VERSION = '0.1';
 
 sub view {
+    my $request = shift @_;
+    use LedgerSMB::Form;
     our $template_dispatch = 
     {
         ap         => {script => 'bin/ap.pl', function => sub {edit()}},
@@ -12,19 +15,27 @@
     };
 
     our $form = new Form;
+    $form->{dbh} = $request->{dbh};
+    our $locale = $request->{_locale};
+    our %myconfig = %{$request->{_user}};
     our %myconfig = ();
     %myconfig = %{$request->{_user}};
     our $locale = $request->{_locale};
+    my $script = $template_dispatch->{$request->{entry_type}}->{script};
     if ($script =~ /^bin/){
 	# I hate this old code!
-        { no strict; no warnings 'redefine'; do $script; }
+        {
+             no strict; 
+             no warnings 'redefine'; 
+             do $script; 
+        }
 
     } elsif ($script =~ /scripts/) {
          { do $script } 
 
     }
 
-    $vouchers_dispatch->{$request->{entry_type}}{function}($request);
+    $template_dispatch->{$request->{entry_type}}->{function}($form);
 
 }
 
@@ -43,36 +54,49 @@
 sub display_results {
     my ($request) = @_;
     my $transtemplate = LedgerSMB::DBObject::TransTemplate->new(base => $request);
-    $transtemplate->search;
-    my $template = LedgeSMB::Template->new(
+    my $template = LedgerSMB::Template->new(
         user     => $request->{_user},
         locale   => $request->{_locale},
         path     => 'UI',
         template => 'form-dynatable',
         format   => 'HTML', 
    );
-   my @cols = qw(id entry_type source description meta_number entity_name class);
+   my @cols = qw(id entry_type source description meta_number entity_name entity_class);
    my $column_headers = {
       id          => 'ID',
       source      => 'Reference',
       description => 'Description',
       meta_number => 'Account Number',
       entity_name => 'Name',
-      class       => 'Type of Account',
+      entity_class       => 'Type of Account',
    };
    my $rows = [];
    $base_url = $request->{script} . "?action=view";
-   for my $line (@{$templatetrans->{search_resuts}}){
+    $transtemplate->search;
+   for my $line (@{$transtemplate->{search_results}}){
+       if (!$line->{source}){
+           $line->{source} = '[none]';
+       }
+       if (lc($line->{entity_class}) eq 'vendor'){
+           $line->{entry_type} = 'ap';
+       }
+       elsif (lc($line->{entity_class}) eq 'customer'){
+           $line->{entry_type} = 'ar';
+       }
+       else {
+           $line->{entry_type} = 'gl';
+       }
        $line->{source} = {
             text => $line->{source}, 
 	    href => "$base_url&entry_type=$line->{entry_type}&id=$line->{id}",
        };
        push @$rows, $line;
+       print STDERR "row added \n";
    }
    $template->render({
       columns => ..hidden..,
-      headers => $column_headers,
-      title   => $request->locale->text('Memorized Transaction List'),
+      heading => $column_headers,
+      title   => $request->{_locale}->text('Memorized Transaction List'),
       rows    => $rows,
       form    => $request,
    });

Modified: addons/1.3/templatetrans/trunk/sql/modules/trans-functions.sql
===================================================================
--- addons/1.3/templatetrans/trunk/sql/modules/trans-functions.sql	2009-11-05 20:43:24 UTC (rev 2779)
+++ addons/1.3/templatetrans/trunk/sql/modules/trans-functions.sql	2009-11-05 20:45:26 UTC (rev 2780)
@@ -44,14 +44,14 @@
 
 CREATE OR REPLACE FUNCTION journal__make_invoice(
 in_order_id int,  in_journal_id int, in_on_hold bool, in_reverse bool,
-in_credit_id int, in_language_id int
+in_credit_id int, in_language_code int
 ) returns t_invoice AS $$
 DECLARE retval t_invoice;
 BEGIN	
 	INSERT INTO t_invoice (order_id, journal_id, on_hold, reverse,
-		credit_id, language_id)
+		credit_id, language_code)
 	VALUES (in_order_id, in_journal_id, coalesce(in_on_hold, false), 
-		in_reverse, in_credit_id, in_language_id);
+		in_reverse, in_credit_id, in_language_code);
 
 	SELECT * INTO retval FROM t_invoice WHERE journal_id = in_journal_id;
 
@@ -87,7 +87,8 @@
 BEGIN
 	FOR retval IN 
 		SELECT j.id, j.source, j.description, j.entry_type, 
-			j.transaction_date, j.is_template, eca.meta_number, 
+			j.transaction_date, j.approved, 
+			j.is_template, eca.meta_number, 
 			e.name, ec.class
 		FROM journal j
 		LEFT JOIN t_invoice i ON (i.journal_id = j.id)
@@ -96,7 +97,7 @@
 		LEFT JOIN entity_class ec ON (eca.entity_class = ec.id)
 		WHERE (in_source IS NULL OR in_source = j.source) AND
 			(in_description IS NULL 
-				or in_descripition = j.description) AND
+				or in_description = j.description) AND
 			(in_entry_type is null or in_entry_type = j.entry_type)
 			and (in_transaction_date is null 
 				or in_transaction_date = j.transaction_date) and


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