qq| o.marge_total, o.marge_percent, | .
qq| ex.$rate AS exchangerate, | .
qq| pr.projectnumber AS globalprojectnumber, | .
- qq| e.name AS employee | .
+ qq| e.name AS employee, s.name AS salesman | .
qq|FROM oe o | .
qq|JOIN $vc ct ON (o.${vc}_id = ct.id) | .
qq|LEFT JOIN employee e ON (o.employee_id = e.id) | .
+ qq|LEFT JOIN employee s ON (o.salesman_id = s.id) | .
qq|LEFT JOIN exchangerate ex ON (ex.curr = o.curr | .
qq| AND ex.transdate = o.transdate) | .
qq|LEFT JOIN project pr ON (o.globalproject_id = pr.id) | .
$query .= " AND o.employee_id = ?";
push @values, conv_i($form->{employee_id});
}
+
+ if ($form->{salesman_id}) {
+ $query .= " AND o.salesman_id = ?";
+ push @values, conv_i($form->{salesman_id});
+ }
if (!$form->{open} && !$form->{closed}) {
$query .= " AND o.id = 0";
}
my $sortorder = join(', ', ("o.id", $form->sort_columns("transdate", $ordnumber, "name")));
- my %allowed_sort_columns =
- ("transdate" => "o.transdate",
- "reqdate" => "o.reqdate",
- "id" => "o.id",
- "ordnumber" => "o.ordnumber",
- "quonumber" => "o.quonumber",
- "name" => "ct.name",
- "employee" => "e.name",
- "shipvia" => "o.shipvia",
- "transaction_description" => "o.transaction_description");
+ my %allowed_sort_columns = (
+ "transdate" => "o.transdate",
+ "reqdate" => "o.reqdate",
+ "id" => "o.id",
+ "ordnumber" => "o.ordnumber",
+ "quonumber" => "o.quonumber",
+ "name" => "ct.name",
+ "employee" => "e.name",
+ "salesman" => "e.name",
+ "shipvia" => "o.shipvia",
+ "transaction_description" => "o.transaction_description"
+ );
if ($form->{sort} && grep($form->{sort}, keys(%allowed_sort_columns))) {
$sortorder = $allowed_sort_columns{$form->{sort}};
}
for my $i (1 .. $form->{rowcount}) {
- map({ $form->{"${_}_$i"} =
- $form->parse_amount($myconfig, $form->{"${_}_$i"}) } qw(qty ship));
+ map({ $form->{"${_}_$i"} = $form->parse_amount($myconfig, $form->{"${_}_$i"}) } qw(qty ship));
if ($form->{"id_$i"}) {
my $basefactor = 1;
if (defined($all_units->{$item_unit}->{factor}) &&
(($all_units->{$item_unit}->{factor} * 1) != 0)) {
- $basefactor = $all_units->{$form->{"unit_$i"}}->{factor} /
- $all_units->{$item_unit}->{factor};
+ $basefactor = $all_units->{$form->{"unit_$i"}}->{factor} / $all_units->{$item_unit}->{factor};
}
my $baseqty = $form->{"qty_$i"} * $basefactor;
$form->{"marge_percent_$i"} = $form->parse_amount($myconfig, $form->{"marge_percent_$i"}) * 1;
- $form->{"marge_absolut_$i"} = $form->parse_amount($myconfig, $form->{"marge_absolut_$i"}) * 1;
+ $form->{"marge_total_$i"} = $form->parse_amount($myconfig, $form->{"marge_total_$i"}) * 1;
$form->{"lastcost_$i"} = $form->{"lastcost_$i"} * 1;
# set values to 0 if nothing entered
- $form->{"discount_$i"} =
- $form->parse_amount($myconfig, $form->{"discount_$i"}) / 100;
+ $form->{"discount_$i"} = $form->parse_amount($myconfig, $form->{"discount_$i"}) / 100;
- $form->{"sellprice_$i"} =
- $form->parse_amount($myconfig, $form->{"sellprice_$i"});
+ $form->{"sellprice_$i"} = $form->parse_amount($myconfig, $form->{"sellprice_$i"});
$fxsellprice = $form->{"sellprice_$i"};
my ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
$dec = length($dec);
my $decimalplaces = ($dec > 2) ? $dec : 2;
- $discount =
- $form->round_amount($form->{"sellprice_$i"} * $form->{"discount_$i"},
- $decimalplaces);
- $form->{"sellprice_$i"} =
- $form->round_amount($form->{"sellprice_$i"} - $discount,
- $decimalplaces);
+ $discount = $form->round_amount($form->{"sellprice_$i"} * $form->{"discount_$i"}, $decimalplaces);
+ $form->{"sellprice_$i"} = $form->round_amount($form->{"sellprice_$i"} - $discount, $decimalplaces);
$form->{"inventory_accno_$i"} *= 1;
$form->{"expense_accno_$i"} *= 1;
if ($form->round_amount($taxrate, 7) == 0) {
if ($form->{taxincluded}) {
foreach $item (@taxaccounts) {
- $taxamount =
- $form->round_amount($linetotal * $form->{"${item}_rate"} /
- (1 + abs($form->{"${item}_rate"})),
- 2);
-
+ $taxamount = $form->round_amount($linetotal * $form->{"${item}_rate"} / (1 + abs($form->{"${item}_rate"})), 2);
$taxaccounts{$item} += $taxamount;
$taxdiff += $taxamount;
-
- $taxbase{$item} += $taxbase;
+ $taxbase{$item} += $taxbase;
}
$taxaccounts{ $taxaccounts[0] } += $taxdiff;
} else {
}
} else {
foreach $item (@taxaccounts) {
- $taxaccounts{$item} +=
- $taxamount * $form->{"${item}_rate"} / $taxrate;
+ $taxaccounts{$item} += $taxamount * $form->{"${item}_rate"} / $taxrate;
$taxbase{$item} += $taxbase;
}
}
$netamount += $form->{"sellprice_$i"} * $form->{"qty_$i"} / $price_factor;
- $reqdate =
- ($form->{"reqdate_$i"}) ? $form->{"reqdate_$i"} : undef;
+ $reqdate = ($form->{"reqdate_$i"}) ? $form->{"reqdate_$i"} : undef;
# get pricegroup_id and save ist
($null, my $pricegroup_id) = split(/--/, $form->{"sellprice_pg_$i"});
}
$query .= qq|?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
(SELECT factor FROM price_factors WHERE id = ?), ?)|;
- push(@values,
+ push(@values,
conv_i($form->{id}), conv_i($form->{"id_$i"}),
$form->{"description_$i"}, $form->{"longdescription_$i"},
$form->{"qty_$i"}, $baseqty,
$form->{"serialnumber_$i"}, $form->{"ship_$i"}, conv_i($pricegroup_id),
$form->{"ordnumber_$i"}, conv_date($form->{"transdate_$i"}),
$form->{"cusordnumber_$i"}, $form->{"subtotal_$i"} ? 't' : 'f',
- $form->{"marge_percent_$i"}, $form->{"marge_absolut_$i"},
+ $form->{"marge_percent_$i"}, $form->{"marge_total_$i"},
$form->{"lastcost_$i"},
conv_i($form->{"price_factor_id_$i"}), conv_i($form->{"price_factor_id_$i"}),
conv_i($form->{"marge_price_factor_$i"}));
if ($form->{currency} eq $form->{defaultcurrency}) {
$form->{exchangerate} = 1;
} else {
- $exchangerate =
- $form->check_exchangerate($myconfig,
- $form->{currency},
- $form->{transdate},
- ($form->{vc} eq 'customer') ? 'buy' : 'sell');
+ $exchangerate = $form->check_exchangerate($myconfig, $form->{currency}, $form->{transdate}, ($form->{vc} eq 'customer') ? 'buy' : 'sell');
}
- $form->{exchangerate} =
- ($exchangerate)
- ? $exchangerate
- : $form->parse_amount($myconfig, $form->{exchangerate});
+ $form->{exchangerate} = ($exchangerate) ? $exchangerate : $form->parse_amount($myconfig, $form->{exchangerate});
my $quotation = $form->{type} =~ /_order$/ ? 'f' : 't';
# add shipto
$form->{name} = $form->{ $form->{vc} };
- $form->{name} =~ s/--$form->{"$form->{vc}_id"}//;
+ $form->{name} =~ s/--\Q$form->{"$form->{vc}_id"}\E//;
if (!$form->{shipto_id}) {
$form->add_shipto($dbh, $form->{id}, "OE");
if (($form->{currency} ne $form->{defaultcurrency}) && !$exchangerate) {
if ($form->{vc} eq 'customer') {
- $form->update_exchangerate($dbh, $form->{currency}, $form->{transdate},
- $form->{exchangerate}, 0);
+ $form->update_exchangerate($dbh, $form->{currency}, $form->{transdate}, $form->{exchangerate}, 0);
}
if ($form->{vc} eq 'vendor') {
- $form->update_exchangerate($dbh, $form->{currency}, $form->{transdate},
- 0, $form->{exchangerate});
+ $form->update_exchangerate($dbh, $form->{currency}, $form->{transdate}, 0, $form->{exchangerate});
}
}
&adj_onhand($dbh, $form, $ml * -1);
}
- my $rc = $dbh->commit;
- $dbh->disconnect;
-
$form->{saved_xyznumber} = $form->{$form->{type} =~ /_quotation$/ ?
"quonumber" : "ordnumber"};
Common::webdav_folder($form) if ($main::webdav);
+ my $rc = $dbh->commit;
+ $dbh->disconnect;
+
$main::lxdebug->leave_sub();
return $rc;
my ($self, $myconfig, $form) = @_;
- $main::lxdebug->leave_sub() unless ($form->{"id"});
+ return $main::lxdebug->leave_sub() unless ($form->{"id"});
my $dbh = $form->dbconnect($myconfig);
do_query($form, $dbh, qq|UPDATE oe SET closed = TRUE where id = ?|,
$ptr->{accno} = $i;
}
$ref->{taxaccounts} .= "$ptr->{accno} ";
- if (!($form->{taxaccounts} =~ /$ptr->{accno}/)) {
+ if (!($form->{taxaccounts} =~ /\Q$ptr->{accno}\E/)) {
$form->{"$ptr->{accno}_rate"} = $ptr->{rate};
$form->{"$ptr->{accno}_description"} = $ptr->{taxdescription};
$form->{"$ptr->{accno}_taxnumber"} = $ptr->{taxnumber};
$sth->finish();
}
- $form->{"globalprojectnumber"} =
- $projectnumbers{$form->{"globalproject_id"}};
+ $form->{"globalprojectnumber"} = $projectnumbers{$form->{"globalproject_id"}};
my @arrays =
qw(runningnumber number description longdescription qty ship unit bin
if ($taxamount != 0) {
foreach my $item (split / /, $form->{"taxaccounts_$i"}) {
- $taxaccounts{$item} +=
- $taxamount * $form->{"${item}_rate"} / $taxrate;
- $taxbase{$item} += $taxbase;
+ $taxaccounts{$item} += $taxamount * $form->{"${item}_rate"} / $taxrate;
+ $taxbase{$item} += $taxbase;
}
}
# get parts and push them onto the stack
my $sortorder = "";
if ($form->{groupitems}) {
- $sortorder =
- qq|ORDER BY pg.partsgroup, a.$oid{$myconfig->{dbdriver}}|;
+ $sortorder = qq|ORDER BY pg.partsgroup, a.$oid{$myconfig->{dbdriver}}|;
} else {
$sortorder = qq|ORDER BY a.$oid{$myconfig->{dbdriver}}|;
}
while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
if ($form->{groupitems} && $ref->{partsgroup} ne $sameitem) {
- map({ push(@{ $form->{$_} }, "") }
- grep({ $_ ne "description" } @arrays));
+ map({ push(@{ $form->{$_} }, "") } grep({ $_ ne "description" } @arrays));
$sameitem = ($ref->{partsgroup}) ? $ref->{partsgroup} : "--";
push(@{ $form->{description} }, $sameitem);
}
- push(@{ $form->{description} },
- $form->format_amount($myconfig, $ref->{qty} * $form->{"qty_$i"}
- )
- . qq|, $ref->{partnumber}, $ref->{description}|);
-
- map({ push(@{ $form->{$_} }, "") }
- grep({ $_ ne "description" } @arrays));
+ push(@{ $form->{description} }, $form->format_amount($myconfig, $ref->{qty} * $form->{"qty_$i"}) . qq|, $ref->{partnumber}, $ref->{description}|);
+ map({ push(@{ $form->{$_} }, "") } grep({ $_ ne "description" } @arrays));
}
$sth->finish;
}
my ($item_unit) = selectrow_query($form, $dbh, $query, $ref->{parts_id});
my $basefactor = 1;
- if (defined($all_units->{$item_unit}->{factor}) &&
- (($all_units->{$item_unit}->{factor} * 1) != 0)) {
- $basefactor = $all_units->{$ref->{unit}}->{factor} /
- $all_units->{$item_unit}->{factor};
+ if (defined($all_units->{$item_unit}->{factor}) && (($all_units->{$item_unit}->{factor} * 1) != 0)) {
+ $basefactor = $all_units->{$ref->{unit}}->{factor} / $all_units->{$item_unit}->{factor};
}
my $baseqty = $ref->{ship} * $basefactor;
# adjust onhand in parts table
- $form->update_balance($dbh, "parts", "onhand",
- qq|id = $ref->{parts_id}|,
- $baseqty * $ml);
+ $form->update_balance($dbh, "parts", "onhand", qq|id = $ref->{parts_id}|, $baseqty * $ml);
}
}