X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDO.pm;h=b51fc0f1bf15ee199d7003cdf54f53d902b3c7db;hb=0e04ddd7e3ff23d051838617844698a39f680969;hp=f73d0a39462a178657494ace7db05133773621ba;hpb=79ece53cee7f15d7ba1c6621860ae33053f2da54;p=kivitendo-erp.git diff --git a/SL/DO.pm b/SL/DO.pm index f73d0a394..b51fc0f1b 100644 --- a/SL/DO.pm +++ b/SL/DO.pm @@ -25,7 +25,8 @@ # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1335, USA. #====================================================================== # # Delivery Order entry module @@ -33,6 +34,7 @@ package DO; +use Carp; use List::Util qw(max); use YAML; @@ -46,6 +48,7 @@ use SL::HTML::Restrict; use SL::RecordLinks; use SL::IC; use SL::TransNumber; +use SL::DB; use SL::Util qw(trim); use strict; @@ -180,6 +183,33 @@ sub transactions { push @values, conv_date($form->{insertdateto}); } + if ($form->{parts_partnumber}) { + push @where, <{parts_partnumber}); + } + + if ($form->{parts_description}) { + push @where, <{parts_description}); + } + if (@where) { $query .= " WHERE " . join(" AND ", map { "($_)" } @where); } @@ -232,6 +262,16 @@ sub transactions { } sub save { + my ($self) = @_; + $main::lxdebug->enter_sub(); + + my $rc = SL::DB->client->with_transaction(\&_save, $self); + + $main::lxdebug->leave_sub(); + return $rc; +} + +sub _save { $main::lxdebug->enter_sub(); my ($self) = @_; @@ -239,8 +279,7 @@ sub save { my $myconfig = \%main::myconfig; my $form = $main::form; - # connect to database, turn off autocommit - my $dbh = $form->get_standard_dbh($myconfig); + my $dbh = SL::DB->client->dbh; my $restricter = SL::HTML::Restrict->create; my ($query, @values, $sth, $null); @@ -284,7 +323,7 @@ sub save { my $items_reqdate; $form->get_lists('price_factors' => 'ALL_PRICE_FACTORS'); - my %price_factors = map { $_->{id} => $_->{factor} } @{ $form->{ALL_PRICE_FACTORS} }; + my %price_factors = map { $_->{id} => $_->{factor} *1 } @{ $form->{ALL_PRICE_FACTORS} }; my $price_factor; my %part_id_map = map { $_ => 1 } grep { $_ } map { $form->{"id_$_"} } (1 .. $form->{rowcount}); @@ -510,8 +549,6 @@ SQL 'type' => $form->{type} eq 'sales_delivery_order' ? 'sales' : 'purchase', 'dbh' => $dbh,); - my $rc = $dbh->commit(); - $form->{saved_donumber} = $form->{donumber}; $form->{saved_ordnumber} = $form->{ordnumber}; $form->{saved_cusordnumber} = $form->{cusordnumber}; @@ -520,7 +557,7 @@ SQL $main::lxdebug->leave_sub(); - return $rc; + return 1; } sub mark_orders_if_delivered { @@ -534,14 +571,16 @@ sub mark_orders_if_delivered { my $myconfig = \%main::myconfig; my $form = $main::form; - my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig); + SL::DB->client->with_transaction(sub { + my $dbh = $params{dbh} || SL::DB->client->dbh; - my %ship = $self->get_shipped_qty('dbh' => $dbh, 'do_id' => $form->{id}, 'delivered' => 1); + my %ship = $self->get_shipped_qty('dbh' => $dbh, 'do_id' => $form->{id}, 'delivered' => 1); - foreach my $oe_id (keys %ship) { - do_query($form, $dbh,"UPDATE oe SET delivered = ".($ship{$oe_id}->{delivered}?"TRUE":"FALSE")." WHERE id = ?", $oe_id); - } - $dbh->commit() if (!$params{dbh}); + foreach my $oe_id (keys %ship) { + do_query($form, $dbh,"UPDATE oe SET delivered = ".($ship{$oe_id}->{delivered}?"TRUE":"FALSE")." WHERE id = ?", $oe_id); + } + 1; + }) or do { die SL::DB->client->error }; $main::lxdebug->leave_sub(); } @@ -562,13 +601,15 @@ sub close_orders { my $myconfig = \%main::myconfig; my $form = $main::form; - my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig); + SL::DB->client->with_transaction(sub { + my $dbh = $params{dbh} || SL::DB->client->dbh; - my $query = qq|UPDATE delivery_orders SET closed = TRUE WHERE id IN (| . join(', ', ('?') x scalar(@{ $params{ids} })) . qq|)|; + my $query = qq|UPDATE delivery_orders SET closed = TRUE WHERE id IN (| . join(', ', ('?') x scalar(@{ $params{ids} })) . qq|)|; - do_query($form, $dbh, $query, map { conv_i($_) } @{ $params{ids} }); + do_query($form, $dbh, $query, map { conv_i($_) } @{ $params{ids} }); + 1; + }) or die { SL::DB->client->error }; - $dbh->commit() unless ($params{dbh}); $form->new_lastmtime('delivery_orders'); $main::lxdebug->leave_sub(); @@ -705,15 +746,14 @@ sub retrieve { $sth = prepare_execute_query($form, $dbh, $query, $form->{id}); $ref = $sth->fetchrow_hashref("NAME_lc"); - delete $ref->{id}; - map { $form->{$_} = $ref->{$_} } keys %$ref; + $form->{$_} = $ref->{$_} for grep { m{^shipto(?!_id$)} } keys %$ref; $sth->finish(); - if ($form->{shipto_id}) { + if ($ref->{shipto_id}) { my $cvars = CVar->get_custom_variables( dbh => $dbh, module => 'ShipTo', - trans_id => $form->{shipto_id}, + trans_id => $ref->{shipto_id}, ); $form->{"shiptocvar_$_->{name}"} = $_->{value} for @{ $cvars }; } @@ -739,7 +779,7 @@ sub retrieve { # stuff different from the whole will not be overwritten, but saved with a suffix. $query = qq|SELECT doi.id AS delivery_order_items_id, - p.partnumber, p.assembly, p.listprice, doi.description, doi.qty, + p.partnumber, p.part_type, p.listprice, doi.description, doi.qty, doi.sellprice, doi.parts_id AS id, doi.unit, doi.discount, p.notes AS partnotes, doi.reqdate, doi.project_id, doi.serialnumber, doi.lastcost, doi.ordnumber, doi.transdate, doi.cusordnumber, doi.longdescription, @@ -886,7 +926,7 @@ sub order_details { push @arrays, map { "project_cvar_$_->{name}" } @{ $project_cvar_configs }; $form->get_lists('price_factors' => 'ALL_PRICE_FACTORS'); - my %price_factors = map { $_->{id} => $_->{factor} } @{ $form->{ALL_PRICE_FACTORS} }; + my %price_factors = map { $_->{id} => $_->{factor} *1 } @{ $form->{ALL_PRICE_FACTORS} }; my $totalweight = 0; my $sameitem = ""; @@ -1027,9 +1067,9 @@ sub order_details { $h_pg->finish(); $h_bin_wh->finish(); + $form->{department} = SL::DB::Manager::Department->find_by(id => $form->{department_id})->description if $form->{department_id}; $form->{delivery_term} = SL::DB::Manager::DeliveryTerm->find_by(id => $form->{delivery_term_id} || undef); $form->{delivery_term}->description_long($form->{delivery_term}->translated_attribute('description_long', $form->{language_id})) if $form->{delivery_term} && $form->{language_id}; - $form->{department} = SL::DB::Manager::Department->find_by(id => $form->{department_id})->description if $form->{department_id}; $form->{username} = $myconfig->{name}; @@ -1262,7 +1302,7 @@ sub get_shipped_qty { my @dolinks = RecordLinks->get_links('dbh' => $dbh, 'from_table' => 'oe', 'to_table' => 'delivery_orders', - 'from_id' => @oe_ids); + 'from_id' => \@oe_ids); my @do_ids = map { $_->{to_id} } @dolinks ; if (scalar (@do_ids) == 0) {