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

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



Revision: 4419
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4419&view=rev
Author:   einhverfr
Date:     2012-03-09 04:21:31 +0000 (Fri, 09 Mar 2012)
Log Message:
-----------
Shipped invoices now save/retrieve business reporting units properly

Modified Paths:
--------------
    trunk/LedgerSMB/IS.pm
    trunk/old-handler.pl
    trunk/sql/Pg-database.sql

Modified: trunk/LedgerSMB/IS.pm
===================================================================
--- trunk/LedgerSMB/IS.pm	2012-03-09 03:24:56 UTC (rev 4418)
+++ trunk/LedgerSMB/IS.pm	2012-03-09 04:21:31 UTC (rev 4419)
@@ -35,7 +35,10 @@
 use LedgerSMB::Tax;
 use LedgerSMB::PriceMatrix;
 use LedgerSMB::Sysconfig;
+use Log::Log4perl;
 
+my $logger = Log::Log4perl->get_logger('LedgerSMB::IS');
+
 sub getposlines {
     my ( $self, $myconfig, $form ) = @_;
     %pos_config  = %{ $form->{pos_config} };
@@ -903,6 +906,7 @@
 sub post_invoice {
 
     my ( $self, $myconfig, $form ) = @_;
+    $form->all_business_units;
     $form->{invnumber} = $form->update_defaults( $myconfig, "sinumber", $dbh )
       unless $form->{invnumber};
 
@@ -940,7 +944,7 @@
 
     $query = qq|
 		SELECT p.assembly, p.inventory_accno_id,
-		       p.income_accno_id, p.expense_accno_id, p.project_id
+		       p.income_accno_id, p.expense_accno_id 
 		  FROM parts p
 		 WHERE p.id = ?|;
     my $pth = $dbh->prepare($query) || $form->dberror($query);
@@ -1029,6 +1033,10 @@
 
     my $taxformfound=IS->taxform_exist($form,$form->{"customer_id"});
 
+    my $b_unit_sth = $dbh->prepare(
+         "INSERT INTO business_unit_inv (entry_id, class_id, bu_id)
+          VALUES (currval('invoice_id_seq'), ?, ?)"
+    );
 
     foreach $i ( 1 .. $form->{rowcount} ) {
         my $allocated = 0;
@@ -1131,6 +1139,7 @@
 
             push @{ $form->{acc_trans}{lineitems} },
               {
+                row_num       => $i,
                 chart_id      => $form->{"income_accno_id_$i"},
                 amount        => $amount,
                 fxgrossamount => $fxlinetotal + $fxtax,
@@ -1224,7 +1233,6 @@
 				       allocated = ?,
 				       unit = ?,
 				       deliverydate = ?,
-				       project_id = ?,
 				       serialnumber = ?,
 				       notes = ?
 				      WHERE id = ?|;
@@ -1236,11 +1244,16 @@
                 $form->{"sellprice_$i"},   $form->{"precision_$i"},
                 $fxsellprice,              $form->{"discount_$i"},
                 $allocated,                $form->{"unit_$i"},        
-                $form->{"deliverydate_$i"}, $project_id,               
+                $form->{"deliverydate_$i"}, 
                 $form->{"serialnumber_$i"}, $form->{"notes_$i"},       
                 $invoice_id
             ) || $form->dberror($query);
 
+            for my $cls(@{$form->{bu_class}}){
+                if ($form->{"b_unit_$cls->{id}_$i"}){
+                 $b_unit_sth->execute($cls->{id}, $form->{"b_unit_$cls->{id}_$i"});
+                }
+            }
 	   my $report=($taxformfound and $form->{"taxformcheck_$i"})?"true":"false";
 
 	   IS->update_invoice_tax_form($form,$dbh,$invoice_id,$report);
@@ -1316,6 +1329,11 @@
           $form->round_amount( $form->{paid} * $form->{exchangerate}, 2 );
     }
 
+    $b_unit_sth = $dbh->prepare(
+         "INSERT INTO business_unit_ac (entry_id, class_id, bu_id)
+          VALUES (currval('acc_trans_entry_id_seq'), ?, ?)"
+    );
+
     foreach $ref ( sort { $b->{amount} <=> $a->{amount} }
         @{ $form->{acc_trans}{lineitems} } )
     {
@@ -1324,14 +1342,19 @@
         $query  = qq|
 			INSERT INTO acc_trans 
 			            (trans_id, chart_id, amount,
-			            transdate, project_id, invoice_id)
-			     VALUES (?, ?, ?, ?, ?, ?)|;
+			            transdate, invoice_id)
+			     VALUES (?, ?, ?, ?, ?)|;
         $sth = $dbh->prepare($query);
         $sth->execute( $form->{id}, $ref->{chart_id}, $amount,
-            $form->{transdate}, $ref->{project_id}, $ref->{invoice_id} )
+            $form->{transdate}, $ref->{invoice_id} )
           || $form->dberror($query);
         $diff   = 0;
         $fxdiff = 0;
+        for my $cls(@{$form->{bu_class}}){
+            if ($form->{"b_unit_$cls->{id}_$i"}){
+               $b_unit_sth->execute($cls->{id}, $form->{"b_unit_$cls->{id}_$i"});
+            }
+        }
     }
 
     $form->{receivables} = $invamount * -1;
@@ -1382,7 +1405,7 @@
         $query = qq|
 			INSERT INTO acc_trans 
 			            (trans_id, chart_id, amount, transdate)
-			     VALUES (?, (SELECT id FROM chart WHERE accno = ?), 
+			     VALUES (?, (SELECT id FROM account WHERE accno = ?), 
 			            ?, ?)|;
 
         $sth = $dbh->prepare($query);
@@ -1402,7 +1425,7 @@
 					INSERT INTO acc_trans 
 					            (trans_id, chart_id, amount,
 					            transdate)
-					VALUES (?, (SELECT id FROM chart
+					VALUES (?, (SELECT id FROM account
 					             WHERE accno = ?),
 					       ?, ?)|;
 
@@ -1585,7 +1608,6 @@
 		       intnotes = ?,
 		       taxincluded = ?,
 		       curr = ?,
-		       department_id = ?,
 		       person_id = ?,
 		       till = ?,
 		       language_code = ?,
@@ -1602,7 +1624,7 @@
         $form->{shippingpoint}, $form->{shipvia},
         $form->{terms},         $form->{notes},
         $form->{intnotes},      $form->{taxincluded},
-        $form->{currency},      $form->{department_id},
+        $form->{currency},
         $form->{employee_id},   $form->{till},
         $form->{language_code}, $form->{ponumber},
         $form->{id}
@@ -2130,8 +2152,8 @@
 			   SELECT i.id as invoice_id,i.description, i.qty, i.fxsellprice, 
 			          i.sellprice, i.precision, i.discount, 
                                   i.parts_id AS id, 
-			          i.unit, i.deliverydate, i.project_id, 
-			          pr.projectnumber, i.serialnumber, i.notes,
+			          i.unit, i.deliverydate, 
+			          i.serialnumber, i.notes,
 			          p.partnumber, p.assembly, p.bin,
 			          pg.partsgroup, p.partsgroup_id, 
 			          p.partnumber AS sku, p.listprice, p.lastcost,
@@ -2140,7 +2162,6 @@
 			          t.description AS partsgrouptranslation
 			     FROM invoice i
 		             JOIN parts p ON (i.parts_id = p.id)
-			LEFT JOIN project pr ON (i.project_id = pr.id)
 			LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id)
 			LEFT JOIN translation t 
 			          ON (t.trans_id = p.partsgroup_id 
@@ -2153,6 +2174,12 @@
         $sth->execute( $form->{language_code}, $form->{id} )
           || $form->dberror($query);
 
+
+        my $bu_sth = $dbh->prepare(
+            qq|SELECT * FROM business_unit_inv
+                WHERE entry_id = ?  |
+        );
+
         
         # foreign currency
         &exchangerate_defaults( $dbh, $form );
@@ -2180,6 +2207,11 @@
             $dec = length $dec;
             my $decimalplaces = ( $dec > 2 ) ? $dec : 2;
 
+            $bu_sth->execute($ref->{invoice_id});
+            while ( $buref = $bu_sth->fetchrow_hashref(NAME_lc) ) {
+                $ref->{"b_unit_$buref->{class_id}"} = $buref->{bu_id};
+            }
+
             $tth->execute( $ref->{id} );
 
             $ref->{taxaccounts} = "";

Modified: trunk/old-handler.pl
===================================================================
--- trunk/old-handler.pl	2012-03-09 03:24:56 UTC (rev 4418)
+++ trunk/old-handler.pl	2012-03-09 04:21:31 UTC (rev 4419)
@@ -139,17 +139,17 @@
 try {
   require "bin/$form->{script}";
 
-# customized scripts
-if ( -f "bin/custom/$form->{script}" ) {
+  # customized scripts
+  if ( -f "bin/custom/$form->{script}" ) {
     eval { require "bin/custom/$form->{script}"; };
-}
+  }
 
-# customized scripts for login
-if ( -f "bin/custom/$form->{login}_$form->{script}" ) {
+  # customized scripts for login
+  if ( -f "bin/custom/$form->{login}_$form->{script}" ) {
     eval { require "bin/custom/$form->{login}_$form->{script}"; };
-}
+  }
 
-if ( $form->{action} ) {
+  if ( $form->{action} ) {
 
     binmode STDOUT, ':utf8';
     binmode STDERR, ':utf8';
@@ -161,11 +161,11 @@
 
     &{ $form->{action} };
 
-}
-else {
+  }
+  else {
     $form->error( __FILE__ . ':' . __LINE__ . ': '
           . $locale->text('action not defined!'));
-}
+  }
 
 }
 catch {

Modified: trunk/sql/Pg-database.sql
===================================================================
--- trunk/sql/Pg-database.sql	2012-03-09 03:24:56 UTC (rev 4418)
+++ trunk/sql/Pg-database.sql	2012-03-09 04:21:31 UTC (rev 4419)
@@ -1410,7 +1410,7 @@
 WHERE obsolete is false;
 CREATE TABLE invoice (
   id serial PRIMARY KEY,
-  trans_id int REFERENCES journal_entry(id),
+  trans_id int REFERENCES transactions(id),
   parts_id int REFERENCES parts(id),
   description text,
   qty NUMERIC,

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