summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xLedgerSMB/Form.pm190
-rwxr-xr-xLedgerSMB/OE.pm86
2 files changed, 151 insertions, 125 deletions
diff --git a/LedgerSMB/Form.pm b/LedgerSMB/Form.pm
index d9c1fac2..9e24d4d3 100755
--- a/LedgerSMB/Form.pm
+++ b/LedgerSMB/Form.pm
@@ -2651,111 +2651,117 @@ sub update_defaults {
# <?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 {
diff --git a/LedgerSMB/OE.pm b/LedgerSMB/OE.pm
index 0d4a8dfe..f8759cc8 100755
--- a/LedgerSMB/OE.pm
+++ b/LedgerSMB/OE.pm
@@ -247,6 +247,25 @@ sub save {
# 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;
@@ -331,8 +350,10 @@ sub save {
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 @@ sub save {
$netamount += $form->{"sellprice_$i"}
* $form->{"qty_$i"};
- $project_id = 'NULL';
if ($form->{"projectnumber_$i"} ne "") {
($null, $project_id)
= split /--/,
@@ -446,27 +466,37 @@ sub save {
}
$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 @@ sub save {
$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 @@ sub save {
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 @@ sub save {
$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');