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

SF.net SVN: ledger-smb: [139] trunk/LedgerSMB



Revision: 139
          http://svn.sourceforge.net/ledger-smb/?rev=139&view=rev
Author:   einhverfr
Date:     2006-09-23 23:22:23 -0700 (Sat, 23 Sep 2006)

Log Message:
-----------
Added support for custom fields to IS, OE, and corrected API bugs in Form.
Also AA now partially supports the custom fields.

Modified Paths:
--------------
    trunk/LedgerSMB/AA.pm
    trunk/LedgerSMB/Form.pm
    trunk/LedgerSMB/IS.pm
    trunk/LedgerSMB/OE.pm

Modified: trunk/LedgerSMB/AA.pm
===================================================================
--- trunk/LedgerSMB/AA.pm	2006-09-24 02:11:06 UTC (rev 138)
+++ trunk/LedgerSMB/AA.pm	2006-09-24 06:22:23 UTC (rev 139)
@@ -250,25 +250,36 @@
 
 	$form->{invnumber} = $form->update_defaults($myconfig, $invnumber) unless $form->{invnumber};
 
-	$query = qq|UPDATE $table SET invnumber = |.$dbh->quote($form->{invnumber}).qq|,
-								  ordnumber = |.$dbh->quote($form->{ordnumber}).qq|,
-								  transdate = '$form->{transdate}',
-								  $form->{vc}_id = $form->{"$form->{vc}_id"},
-								  taxincluded = '$form->{taxincluded}',
-								  amount = $invamount,
-								  duedate = '$form->{duedate}',
-								  paid = $paid,
-								  datepaid = $datepaid,
-								  netamount = $invnetamount,
-								  curr = '$form->{currency}',
-								  notes = |.$dbh->quote($form->{notes}).qq|,
-								  department_id = $form->{department_id},
-								  employee_id = $form->{employee_id},
-								  ponumber = |.$dbh->quote($form->{ponumber}).qq|
-							WHERE id = $form->{id}|;
+	$query = qq|
+		UPDATE $table 
+		SET invnumber = |.$dbh->quote($form->{invnumber}).qq|,
+			ordnumber = |.$dbh->quote($form->{ordnumber}).qq|,
+			transdate = '$form->{transdate}',
+			$form->{vc}_id = $form->{"$form->{vc}_id"},
+			taxincluded = '$form->{taxincluded}',
+			amount = $invamount,
+			duedate = '$form->{duedate}',
+			paid = $paid,
+			datepaid = $datepaid,
+			netamount = $invnetamount,
+			curr = '$form->{currency}',
+			notes = |.$dbh->quote($form->{notes}).qq|,
+			department_id = $form->{department_id},
+			employee_id = $form->{employee_id},
+			ponumber = |.$dbh->quote($form->{ponumber}).qq|
+		WHERE id = $form->{id}
+	|;
 
 	$dbh->do($query) || $form->dberror($query);
 
+	@queries = $form->get_custom_queries($table, 'INSERT');
+	for (@queries){
+		$query = shift (@{$_});
+		$sth = $dbh->prepare($query) || $form->db_error($query);
+		$sth->execute(@{$_}, $form->{id})|| $form->dberror($query);;
+		$sth->finish;
+		$did_insert = 1;
+	}
 	# update exchangerate
 	my $buy = $form->{exchangerate};
 	my $sell = 0;

Modified: trunk/LedgerSMB/Form.pm
===================================================================
--- trunk/LedgerSMB/Form.pm	2006-09-24 02:11:06 UTC (rev 138)
+++ trunk/LedgerSMB/Form.pm	2006-09-24 06:22:23 UTC (rev 139)
@@ -1304,6 +1304,7 @@
 	}
 	for (keys %temphash){
 		my @data;
+		my $ins_values;
 		$query = "$query_type ";
 		if ($query_type eq 'UPDATE'){
 			$query .= " $_ SET ";
@@ -1316,21 +1317,25 @@
 			if ($query_type eq 'UPDATE'){
 				$query .= '= ?';
 			}	
-			my $ins_values .= "?, ";
-			if ($first == 0){
-				$query .= ", ";
-			}
+			$ins_values .= "?, ";
+			$query .= ", ";
 			$first = 0;
-			if ($query_type eq 'UPDATE' or $query_type eq 'INERT'){
-				push @data, $form->{$_ . $linenum}; 
+			if ($query_type eq 'UPDATE' or $query_type eq 'INSERT'){
+				push @data, $self->{"$_$linenum"}; 
 			}
 		}
+		if ($query_type ne 'INSERT'){
+			$query =~ s/, $//;
+		}
 		if ($query_type eq 'SELECT'){
 			$query .= " FROM $_";
 		}
 		if ($query_type eq 'SELECT' or $query_type eq 'UPDATE'){
 			$query .= " WHERE field_id = ?";
 		}
+		if ($query_type eq 'INSERT'){
+			$query .= " field_id) VALUES ($ins_values ?)";
+		}
 		if ($query_type eq 'SELECT'){
 			push @rc, [ $query ];
 		} else {

Modified: trunk/LedgerSMB/IS.pm
===================================================================
--- trunk/LedgerSMB/IS.pm	2006-09-24 02:11:06 UTC (rev 138)
+++ trunk/LedgerSMB/IS.pm	2006-09-24 06:22:23 UTC (rev 139)
@@ -633,6 +633,15 @@
 
     ($form->{id}) = $sth->fetchrow_array;
     $sth->finish;
+
+    @queries = $form->get_custom_queries('ar', 'INSERT');
+    for (@queries){
+	$query = shift (@{$_});
+	$sth = $dbh->prepare($query) || $form->db_error($query);
+	$sth->execute(@{$_}, $form->{id})|| $form->dberror($query);;
+	$sth->finish;
+	$did_insert = 1;
+    }
   }
 
 
@@ -1421,6 +1430,17 @@
   my $rc = $dbh->commit;
   $dbh->disconnect;
   
+  @queries = $form->get_custom_queries('ar', 'SELECT');
+  for (@queries){
+	$query = shift @{$_};
+	$sth = $form->{dbh}->prepare($query);
+	$sth->execute($form->{id});
+	$ref = $sth->fetchrow_hashref(NAME_lc);
+	for (keys %{$ref}){
+		$form->{$_} = $ref->{$_};
+	}
+  }
+  $form->{dbh}->commit;
   $rc;
 
 }

Modified: trunk/LedgerSMB/OE.pm
===================================================================
--- trunk/LedgerSMB/OE.pm	2006-09-24 02:11:06 UTC (rev 138)
+++ trunk/LedgerSMB/OE.pm	2006-09-24 06:22:23 UTC (rev 139)
@@ -261,6 +261,7 @@
     }
   }
  
+  my $did_insert = 0;
   if (! $form->{id}) {
     
     my $uid = localtime;
@@ -276,7 +277,15 @@
     $sth->execute || $form->dberror($query);
     ($form->{id}) = $sth->fetchrow_array;
     $sth->finish;
-    
+    @queries = $form->get_custom_queries('oe', 'INSERT');
+
+    for (@queries){
+	$query = shift (@{$_});
+	$sth = $dbh->prepare($query) || $form->db_error($query);
+	$sth->execute(@{$_}, $form->{id})|| $form->dberror($query);;
+	$sth->finish;
+	$did_insert = 1;
+    }
   }
 
   my $amount;
@@ -451,6 +460,18 @@
               WHERE id = $form->{id}|;
   $dbh->do($query) || $form->dberror($query);
 
+  if (!$did_insert){
+	@queries = $form->get_custom_queries('oe', 'UPDATE');
+	for (@queries){
+		my $query = shift @{$_};
+		$sth = $dbh->prepare($query);
+		$sth->execute (@{$_}, $form->{id});
+		$sth->finish;
+	}
+  }
+
+
+
   $form->{ordtotal} = $amount;
 
   # add shipto
@@ -644,10 +665,6 @@
     $sth->finish;
     for (qw(printed emailed queued)) { $form->{$_} =~ s/ +$//g }
 
-    my %oid = ( 'Pg'		=> 'id',
-                'Oracle'	=> 'rowid',
-		'DB2'		=> '1=1'
-	      );
 
     # retrieve individual items
     $query = qq|SELECT o.id AS orderitems_id,
@@ -665,7 +682,7 @@
 		LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id)
 		LEFT JOIN translation t ON (t.trans_id = p.partsgroup_id AND t.language_code = '$form->{language_code}')
 		WHERE o.trans_id = $form->{id}
-                ORDER BY o.$oid{$myconfig->{dbdriver}}|;
+                ORDER BY o.id|;
     $sth = $dbh->prepare($query);
     $sth->execute || $form->dberror($query);
 
@@ -727,6 +744,17 @@
     # get recurring transaction
     $form->get_recurring($dbh);
 
+    @queries = $form->get_custom_queries('oe', 'SELECT');
+    for (@queries){
+	$query = shift @{$_};
+	$sth = $form->{dbh}->prepare($query);
+	$sth->execute($form->{id});
+	$ref = $sth->fetchrow_hashref(NAME_lc);
+	for (keys %{$ref}){
+		$form->{$_} = $ref->{$_};
+	}
+    }
+    $form->{dbh}->commit;
   } else {
 
     # get last name used


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