X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FOE.pm;h=aaf0faece67a361fec4e57f157b9d542f80eeacb;hb=09619b3bc445ac9872ed0776293bc673f5b6f68d;hp=d90b6aa000fd1dd35b4291504cd070fc4f23d9c4;hpb=a4d740099476b4383a40a21ab5472e75806f3f4f;p=kivitendo-erp.git diff --git a/SL/OE.pm b/SL/OE.pm index d90b6aa00..aaf0faece 100644 --- a/SL/OE.pm +++ b/SL/OE.pm @@ -40,7 +40,10 @@ use YAML; use SL::AM; use SL::Common; use SL::CVar; +use SL::DB::Order; use SL::DB::PeriodicInvoicesConfig; +use SL::DB::Status; +use SL::DB::Tax; use SL::DBUtils; use SL::IC; @@ -85,7 +88,8 @@ sub transactions { qq| ex.$rate AS exchangerate, | . qq| pr.projectnumber AS globalprojectnumber, | . qq| e.name AS employee, s.name AS salesman, | . - qq| ct.${vc}number AS vcnumber, ct.country, ct.ustid | . + qq| ct.${vc}number AS vcnumber, ct.country, ct.ustid, ct.business_id, | . + qq| tz.description AS taxzone | . $periodic_invoices_columns . qq|FROM oe o | . qq|JOIN $vc ct ON (o.${vc}_id = ct.id) | . @@ -94,6 +98,7 @@ sub transactions { qq|LEFT JOIN exchangerate ex ON (ex.currency_id = o.currency_id | . qq| AND ex.transdate = o.transdate) | . qq|LEFT JOIN project pr ON (o.globalproject_id = pr.id) | . + qq|LEFT JOIN tax_zones tz ON (o.taxzone_id = tz.id) | . qq|$periodic_invoices_joins | . qq|WHERE (o.quotation = ?) |; push(@values, $quotation); @@ -124,6 +129,11 @@ SQL push @values, "%" . $form->{"projectnumber"} . "%", "%" . $form->{"projectnumber"} . "%" ; } + if ($form->{"business_id"}) { + $query .= " AND ct.business_id = ?"; + push(@values, $form->{"business_id"}); + } + if ($form->{"${vc}_id"}) { $query .= " AND o.${vc}_id = ?"; push(@values, $form->{"${vc}_id"}); @@ -184,6 +194,16 @@ SQL push(@values, conv_date($form->{reqdateto})); } + if ($form->{shippingpoint}) { + $query .= qq| AND o.shippingpoint ILIKE ?|; + push(@values, '%' . $form->{shippingpoint} . '%'); + } + + if ($form->{taxzone_id} ne '') { # taxzone_id could be 0 + $query .= qq| AND tz.id = ?|; + push(@values, $form->{taxzone_id}); + } + if ($form->{transaction_description}) { $query .= qq| AND o.transaction_description ILIKE ?|; push(@values, '%' . $form->{transaction_description} . '%'); @@ -206,7 +226,9 @@ SQL "employee" => "e.name", "salesman" => "s.name", "shipvia" => "o.shipvia", - "transaction_description" => "o.transaction_description" + "transaction_description" => "o.transaction_description", + "shippingpoint" => "o.shippingpoint", + "taxzone" => "tz.description", ); if ($form->{sort} && grep($form->{sort}, keys(%allowed_sort_columns))) { $sortorder = $allowed_sort_columns{$form->{sort}} . " ${sortdir}"; @@ -660,59 +682,16 @@ sub delete { my ($self, $myconfig, $form) = @_; - # connect to database - my $dbh = $form->get_standard_dbh; - $dbh->begin_work; - - # delete spool files - my $query = qq|SELECT s.spoolfile FROM status s | . - qq|WHERE s.trans_id = ?|; - my @values = (conv_i($form->{id})); - my $sth = $dbh->prepare($query); - $sth->execute(@values) || $self->dberror($query); - - my $spoolfile; - my @spoolfiles = (); - - while (($spoolfile) = $sth->fetchrow_array) { - push @spoolfiles, $spoolfile; - } - $sth->finish; - - # delete-values - @values = (conv_i($form->{id})); - - # periodic invoices and their configuration - do_query($form, $dbh, qq|DELETE FROM periodic_invoices WHERE config_id IN (SELECT id FROM periodic_invoices_configs WHERE oe_id = ?)|, @values); - do_query($form, $dbh, qq|DELETE FROM periodic_invoices_configs WHERE oe_id = ?|, @values); - - # delete status entries - $query = qq|DELETE FROM status | . - qq|WHERE trans_id = ?|; - do_query($form, $dbh, $query, @values); + my $rc = SL::DB::Order->new->db->with_transaction(sub { + my @spoolfiles = grep { $_ } map { $_->spoolfile } @{ SL::DB::Manager::Status->get_all(where => [ trans_id => $form->{id} ]) }; - # delete individual entries - $query = qq|DELETE FROM orderitems | . - qq|WHERE trans_id = ?|; - do_query($form, $dbh, $query, @values); + SL::DB::Order->new(id => $form->{id})->delete; - $query = qq|DELETE FROM shipto | . - qq|WHERE trans_id = ? AND module = 'OE'|; - do_query($form, $dbh, $query, @values); - - # delete OE record - $query = qq|DELETE FROM oe | . - qq|WHERE id = ?|; - do_query($form, $dbh, $query, @values); - - my $rc = $dbh->commit; - - if ($rc) { my $spool = $::lx_office_conf{paths}->{spool}; - foreach $spoolfile (@spoolfiles) { - unlink "$spool/$spoolfile" if $spoolfile; - } - } + unlink map { "$spool/$_" } @spoolfiles if $spool; + + 1; + }); $main::lxdebug->leave_sub(); @@ -853,9 +832,6 @@ sub retrieve { map { $form->{$_} =~ s/ +$//g } qw(printed emailed queued); } # if !@ids - my %oid = ('Pg' => 'oid', - 'Oracle' => 'rowid'); - my $transdate = $form->{transdate} ? $dbh->quote($form->{transdate}) : "current_date"; $form->{taxzone_id} = 0 unless ($form->{taxzone_id}); @@ -870,7 +846,7 @@ sub retrieve { c3.accno AS expense_accno, c3.new_chart_id AS expense_new_chart, date($transdate) - c3.valid_from as expense_valid, oe.ordnumber AS ordnumber_oe, oe.transdate AS transdate_oe, oe.cusordnumber AS cusordnumber_oe, p.partnumber, p.assembly, p.listprice, o.description, o.qty, - o.sellprice, o.parts_id AS id, o.unit, o.discount, p.bin, p.notes AS partnotes, p.inventory_accno_id AS part_inventory_accno_id, + o.sellprice, o.parts_id AS id, o.unit, o.discount, p.notes AS partnotes, p.inventory_accno_id AS part_inventory_accno_id, o.reqdate, o.project_id, o.serialnumber, o.ship, o.lastcost, o.ordnumber, o.transdate, o.cusordnumber, o.subtotal, o.longdescription, o.price_factor_id, o.price_factor, o.marge_price_factor, @@ -887,7 +863,7 @@ sub retrieve { ($form->{id} ? qq|WHERE o.trans_id = ?| : qq|WHERE o.trans_id IN (| . join(", ", map("?", @ids)) . qq|)|) . - qq|ORDER BY o.$oid{$myconfig->{dbdriver}}|; + qq|ORDER BY o.oid|; @ids = $form->{id} ? ($form->{id}) : @ids; $sth = prepare_execute_query($form, $dbh, $query, @values); @@ -1055,10 +1031,6 @@ sub order_details { my $tax_rate; my $taxamount; - - my %oid = ('Pg' => 'oid', - 'Oracle' => 'rowid'); - my (@project_ids, %projectnumbers, %projectdescriptions); push(@project_ids, $form->{"globalproject_id"}) if ($form->{"globalproject_id"}); @@ -1116,7 +1088,7 @@ sub order_details { partnotes serialnumber reqdate sellprice listprice netprice discount p_discount discount_sub nodiscount_sub linetotal nodiscount_linetotal tax_rate projectnumber projectdescription - price_factor price_factor_name partsgroup); + price_factor price_factor_name partsgroup weight lineweight); push @arrays, map { "ic_cvar_$_->{name}" } @{ $ic_cvar_configs }; @@ -1124,6 +1096,7 @@ sub order_details { map { $form->{TEMPLATE_ARRAYS}->{$_} = [] } (@arrays, @tax_arrays); + my $totalweight = 0; my $sameitem = ""; foreach $item (sort { $a->[1] cmp $b->[1] } @partsgroup) { $i = $item->[0]; @@ -1238,6 +1211,13 @@ sub order_details { push(@{ $form->{TEMPLATE_ARRAYS}->{projectnumber} }, $projectnumbers{$form->{"project_id_$i"}}); push(@{ $form->{TEMPLATE_ARRAYS}->{projectdescription} }, $projectdescriptions{$form->{"project_id_$i"}}); + my $lineweight = $form->{"qty_$i"} * $form->{"weight_$i"}; + $totalweight += $lineweight; + push @{ $form->{TEMPLATE_ARRAYS}->{weight} }, $form->format_amount($myconfig, $form->{"weight_$i"}, 3); + push @{ $form->{TEMPLATE_ARRAYS}->{weight_nofmt} }, $form->{"weight_$i"}; + push @{ $form->{TEMPLATE_ARRAYS}->{lineweight} }, $form->format_amount($myconfig, $lineweight, 3); + push @{ $form->{TEMPLATE_ARRAYS}->{lineweight_nofmt} }, $lineweight; + my ($taxamount, $taxbase); my $taxrate = 0; @@ -1269,9 +1249,9 @@ sub order_details { # 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|; } else { - $sortorder = qq|ORDER BY a.$oid{$myconfig->{dbdriver}}|; + $sortorder = qq|ORDER BY a.oid|; } $query = qq|SELECT p.partnumber, p.description, p.unit, a.qty, | . @@ -1304,6 +1284,11 @@ sub order_details { } } + $form->{totalweight} = $form->format_amount($myconfig, $totalweight, 3); + $form->{totalweight_nofmt} = $totalweight; + my $defaults = AM->get_defaults(); + $form->{weightunit} = $defaults->{weightunit}; + my $tax = 0; foreach $item (sort keys %taxaccounts) { $tax += $taxamount = $form->round_amount($taxaccounts{$item}, 2); @@ -1314,8 +1299,11 @@ sub order_details { push(@{ $form->{TEMPLATE_ARRAYS}->{tax_nofmt} }, $taxamount); push(@{ $form->{TEMPLATE_ARRAYS}->{taxrate} }, $form->format_amount($myconfig, $form->{"${item}_rate"} * 100)); push(@{ $form->{TEMPLATE_ARRAYS}->{taxrate_nofmt} }, $form->{"${item}_rate"} * 100); - push(@{ $form->{TEMPLATE_ARRAYS}->{taxdescription} }, $form->{"${item}_description"} . q{ } . 100 * $form->{"${item}_rate"} . q{%}); push(@{ $form->{TEMPLATE_ARRAYS}->{taxnumber} }, $form->{"${item}_taxnumber"}); + + my $tax_obj = SL::DB::Manager::Tax->find_by(taxnumber => $form->{"${item}_taxnumber"}); + my $description = $tax_obj->translated_attribute('taxdescription', $form->{language_id}, 0) if $tax_obj; + push(@{ $form->{TEMPLATE_ARRAYS}->{taxdescription} }, $description . q{ } . 100 * $form->{"${item}_rate"} . q{%}); } $form->{nodiscount_subtotal} = $form->format_amount($myconfig, $form->{nodiscount_total}, 2);