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

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



Revision: 157
          http://svn.sourceforge.net/ledger-smb/?rev=157&view=rev
Author:   einhverfr
Date:     2006-09-26 21:01:44 -0700 (Tue, 26 Sep 2006)

Log Message:
-----------
Fixed update_defaults which was broken when I added the new template system.
Got OE working again, for now....

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

Modified: trunk/LedgerSMB/Form.pm
===================================================================
--- trunk/LedgerSMB/Form.pm	2006-09-26 22:26:11 UTC (rev 156)
+++ trunk/LedgerSMB/Form.pm	2006-09-27 04:01:44 UTC (rev 157)
@@ -2651,111 +2651,117 @@
 	# <?lsmb DESCRIPTION 1 1 3 ?>, <?lsmb ITEM 1 1 3 ?>, <?lsmb PARTSGROUP 1 1 3 ?> only for parts
 	# <?lsmb PHONE ?> for customer and vendors
 
-	#my $num = $_;
-#	$num =~ s/.*?<\?lsmb\s.*?\?>//g;
-#	($num) = $num =~ /(\d+)/;
-#
-#	if (defined $num) {
-#		my $incnum;
-#		# if we have leading zeros check how long it is
-#
-#		if ($num =~ /^0/) {
-#			my $l = length $num;
-#			$incnum = $num + 1;
-#			$l -= length $incnum;
-#
-#			# pad it out with zeros
-#			my $padzero = "0" x $l;
-#			$incnum = ("0" x $l) . $incnum;
-#		} else {
-#			$incnum = $num + 1;
-#		}
-#
-#		s/$num/$incnum/;
-#	}
-#
-#	my $dbvar = $_;
-#	my $var = $_;
-#	my $str;
-#	my $param;
-#
-#	if (/<\?lsmb /) {
-#
-#		while (/<\?lsmb /) {
-#
-#			s/<\?lsmb .*? ?>//;
-#			last unless $&;
-#			$param = $&;
-#			$str = "";
-#
-#			if ($param =~ /<\?lsmb date ?>/i) {
-#				$str = ($self->split_date($myconfig->{dateformat}, $self->{transdate}))[0];
-#				$var =~ s/$param/$str/;
-#			}
-#
-#			if ($param =~ /<\?lsmb (name|business|description|item|partsgroup|phone|custom)/i) {
+	my $num = $_;
+	($num) = $num =~ /(\d+)/;
 
-#				my $fld = lc $&;
-#				$fld =~ s/<\?lsmb //;
+	if (defined $num) {
+		my $incnum;
+		# if we have leading zeros check how long it is
 
-#				if ($fld =~ /name/) {
-#					if ($self->{type}) {
-#						$fld = $self->{vc};
-#					}
-#				}
-#
-#				my $p = $param;
-#				$p =~ s/(<|>|%)//g;
-#				my @p = split / /, $p;
-#				my @n = split / /, uc $self->{$fld};
-#
-#				if ($#p > 0) {
-#
-#					for (my $i = 1; $i <= $#p; $i++) {
-#						$str .= substr($n[$i-1], 0, $p[$i]);
-#					}
-#
-#				} else {
-#					($str) = split /--/, $self->{$fld};
-#				}
-#
-#				$var =~ s/$param/$str/;
-#				$var =~ s/\W//g if $fld eq 'phone';
-#			}
-#
-#			if ($param =~ /<\?lsmb (yy|mm|dd)/i) {
-#
-#				my $p = $param;
-#				$p =~ s/(<|>|%)//g;
-#				my $spc = $p;
-#				$spc =~ s/\w//g;
-#				$spc = substr($spc, 0, 1);
-#				my %d = ( yy => 1, mm => 2, dd => 3 );
-#				my @p = ();
-#
-#				my @a = $self->split_date($myconfig->{dateformat}, $self->{transdate});
-#				for (sort keys %d) { push @p, $a[$d{$_}] if ($p =~ /$_/) }
-#				$str = join $spc, @p;
-#				$var =~ s/$param/$str/;
-#			}
-#
-#			if ($param =~ /<\?lsmb curr/i) {
-#				$var =~ s/$param/$self->{currency}/;
-#			}
-#		}
-#	}
+		if ($num =~ /^0/) {
+			my $l = length $num;
+			$incnum = $num + 1;
+			$l -= length $incnum;
 
+			# pad it out with zeros
+			my $padzero = "0" x $l;
+			$incnum = ("0" x $l) . $incnum;
+		} else {
+			$incnum = $num + 1;
+		}
+
+		s/$num/$incnum/;
+	}
+
+	my $dbvar = $_;
+	my $var = $_;
+	my $str;
+	my $param;
+
+	if (/<\?lsmb /) {
+
+		while (/<\?lsmb /) {
+
+			s/<\?lsmb .*? \?>//;
+			last unless $&;
+		$param = $&;
+			$str = "";
+
+			if ($param =~ /<\?lsmb date \?>/i) {
+				$str = ($self->split_date($myconfig->{dateformat}, $self->{transdate}))[0];
+				$var =~ s/$param/$str/;
+			}
+
+			if ($param =~ /<\?lsmb (name|business|description|item|partsgroup|phone|custom)/i) {
+
+				my $fld = lc $&;
+				$fld =~ s/<\?lsmb //;
+
+				if ($fld =~ /name/) {
+					if ($self->{type}) {
+						$fld = $self->{vc};
+					}
+				}
+
+				my $p = $param;
+				$p =~ s/(<|>|%)//g;
+				my @p = split / /, $p;
+				my @n = split / /, uc $self->{$fld};
+
+				if ($#p > 0) {
+
+					for (my $i = 1; $i <= $#p; $i++) {
+						$str .= substr($n[$i-1], 0, $p[$i]);
+					}
+
+				} else {
+					($str) = split /--/, $self->{$fld};
+				}
+
+				$var =~ s/$param/$str/;
+				$var =~ s/\W//g if $fld eq 'phone';
+			}
+
+			if ($param =~ /<\?lsmb (yy|mm|dd)/i) {
+
+				my $p = $param;
+				$p =~ s/(<|>|%)//g;
+				my $spc = $p;
+				$spc =~ s/\w//g;
+				$spc = substr($spc, 0, 1);
+				my %d = ( yy => 1, mm => 2, dd => 3 );
+				my @p = ();
+
+				my @a = $self->split_date($myconfig->{dateformat}, $self->{transdate});
+				for (sort keys %d) { push @p, $a[$d{$_}] if ($p =~ /$_/) }
+				$str = join $spc, @p;
+				$var =~ s/$param/$str/;
+			}
+
+			if ($param =~ /<\?lsmb curr/i) {
+				$var =~ s/$param/$self->{currency}/;
+			}
+		}
+	}
+
 	$query = qq|UPDATE defaults
 				   SET $fld = ?|;
 
 	$sth = $dbh->prepare($query); 
-	$sth->execute($dbvar) || $form->dberror($query);
+	$sth->execute($dbvar) || $self->dberror($query);
 
 	$dbh->commit;
 
 	$var;
 }
 
+sub db_prepare_vars {
+	for (@_){
+		if (!$self->{$_} and $self->{$_} != 0){
+			$self->{$_} = undef;
+		}
+	}
+}
 
 sub split_date {
 

Modified: trunk/LedgerSMB/OE.pm
===================================================================
--- trunk/LedgerSMB/OE.pm	2006-09-26 22:26:11 UTC (rev 156)
+++ trunk/LedgerSMB/OE.pm	2006-09-27 04:01:44 UTC (rev 157)
@@ -247,7 +247,26 @@
   
 	# connect to database, turn off autocommit
 	my $dbh = $form->{dbh};
+	my $quotation;
+	my $ordnumber;
+	my $numberfld;
+	if ($form->{type} =~ /_order$/) {
+		$quotation = "0";
+		$ordnumber = "ordnumber";
+		$numberfld = ($form->{vc} eq 'customer') ? "sonumber" : 
+			"ponumber";
+	} else {
+		$quotation = "1";
+		$ordnumber = "quonumber";
+		$numberfld = ($form->{vc} eq 'customer') ? "sqnumber" : 
+			"rfqnumber";
+	}
 
+
+	$form->{ordnumber} = $form->update_defaults(
+		$myconfig, $numberfld, $dbh) 
+			unless $form->{ordnumber}; 
+
 	my $query;
 	my $sth;
 	my $null;
@@ -331,8 +350,10 @@
 	my %taxaccounts;
 	my $netamount = 0;
 
- 
-	for my $i (1 .. $form->{rowcount}) {
+	my $rowcount = $form->{rowcount} - 1;
+	for my $i (1 .. $rowcount) {
+		$form->db_prepare_vars("orderitems_id_$i", "id_$i", 
+			"description_$i", "project_id_$i", "ship_$i");
 
 		for (qw(qty ship)) { 
 			$form->{"${_}_$i"} = $form->parse_amount(
@@ -438,7 +459,6 @@
 			$netamount += $form->{"sellprice_$i"} 
 				* $form->{"qty_$i"};
       
-			$project_id = 'NULL';
 			if ($form->{"projectnumber_$i"} ne "") {
 				($null, $project_id) 
 					= split /--/, 
@@ -446,27 +466,37 @@
       			}
 			$project_id = $form->{"project_id_$i"} 
 				if $form->{"project_id_$i"};
-      
+
+			if (!$form->{"reqdate_$i"}){
+				$form->{"reqdate_$i"} = undef;
+			}
+
+			@queryargs = ();
 			# save detail record in orderitems table
 			$query = qq|INSERT INTO orderitems (|;
-			$query .= "id, " if $form->{"orderitems_id_$i"};
+			if ($form->{"orderitems_id_$i"}){
+				$query .= "id, ";
+			}
 			$query .= qq|
 				trans_id, parts_id, description, qty, sellprice,
 				discount, unit, reqdate, project_id, ship, 
 				serialnumber, notes)
                    		VALUES (|;
-			$query .= qq|$dbh->quote($form->{"orderitems_id_$i"}),| 
-				if $form->{"orderitems_id_$i"};
+			if ($form->{"orderitems_id_$i"}){
+				$query .= "?, ";
+				push @queryargs, $form->{"orderitems_id_$i"};
+			}
       			$query .= qq| ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|;
 			$sth = $dbh->prepare($query);
-			$sth->execute(
+			push (@queryargs, 
 				$form->{id}, $form->{"id_$i"},
 				$form->{"description_$i"}, $form->{"qty_$i"},
 				$fxsellprice, $form->{"discount_$i"},
 				$form->{"unit_$i"}, $form->{"reqdate_$i"},
 				$project_id, $form->{"ship_$i"}, 
-				$form->{"serialnumber_$i"}, $form->{"notes_$i"}
-				) || $form->dberror($query);
+				$form->{"serialnumber_$i"}, 
+				$form->{"notes_$i"});
+			$sth->execute(@queryargs) || $form->dberror($query);
 
 			$form->{"sellprice_$i"} = $fxsellprice;
 		}
@@ -496,24 +526,6 @@
 	$form->{exchangerate} = ($exchangerate) ? $exchangerate : 
 		$form->parse_amount($myconfig, $form->{exchangerate});
   
-	my $quotation;
-	my $ordnumber;
-	my $numberfld;
-	if ($form->{type} =~ /_order$/) {
-		$quotation = "0";
-		$ordnumber = "ordnumber";
-		$numberfld = ($form->{vc} eq 'customer') ? "sonumber" : 
-			"ponumber";
-	} else {
-		$quotation = "1";
-		$ordnumber = "quonumber";
-		$numberfld = ($form->{vc} eq 'customer') ? "sqnumber" : 
-			"rfqnumber";
-	}
-
-	$form->{$ordnumber} = $form->update_defaults(
-		$myconfig, $numberfld, $dbh) 
-			unless $form->{$ordnumber}; 
   
 	($null, $form->{department_id}) = split(/--/, $form->{department});
 	for (qw(department_id terms)) { $form->{$_} *= 1 }
@@ -543,9 +555,16 @@
 			ponumber = ?, 
 			terms = ?
 		WHERE id = ?|;
-	$sth = $dbh->prepare($query);
-	$sth->execute(
-		$form->{ordnumber},
+	$form->db_prepare_vars("quonumber", "transdate", "vendor_id",
+		"customer_id", "reqdate", "taxincluded", "shippingpoint",
+		"shipvia", "currency", "closed", "department_id",
+		"employee_id", "language_code", "ponumber", "terms");
+
+	if (!$form->{reqdate}){
+		$form->{reqdate} = undef;
+	}
+	
+	@queryargs = ($form->{ordnumber},
 		$form->{quonumber}, 
 		$form->{transdate}, 
 		$form->{vendor_id},
@@ -566,8 +585,9 @@
 		$form->{language_code},
 		$form->{ponumber}, 
 		$form->{terms}, 
-		$form->{id}	
-	) || $form->dberror($query);
+		$form->{id});
+	$sth = $dbh->prepare($query);
+	$sth->execute(@queryargs) || $form->dberror($query);
 
 	if (!$did_insert){
 		@queries = $form->get_custom_queries('oe', 'UPDATE');


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