X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FOE.pm;h=3d92746b55db2bfcf5beb45bc65a4dd2bc5eb427;hb=284470c116a0f1a73f82797160b0170e55a58652;hp=0e5c05b467843c884db8dc20882795107e2f1f1f;hpb=e0e3eee4eb59b7d6fbe17fe9ad12167b6b8a388b;p=kivitendo-erp.git diff --git a/SL/OE.pm b/SL/OE.pm index 0e5c05b46..3d92746b5 100644 --- a/SL/OE.pm +++ b/SL/OE.pm @@ -46,6 +46,7 @@ use SL::DB::Status; use SL::DB::Tax; use SL::DBUtils; use SL::IC; +use SL::TransNumber; use strict; @@ -314,6 +315,10 @@ sub save { my $ml = ($form->{type} eq 'sales_order') ? 1 : -1; + my $number_field = $form->{type} =~ m{order} ? 'ordnumber' : 'quonumber'; + my $trans_number = SL::TransNumber->new(type => $form->{type}, dbh => $dbh, number => $form->{$number_field}, id => $form->{id}); + $form->{$number_field} ||= $trans_number->create_unique; + if ($form->{id}) { $query = qq|DELETE FROM custom_variables WHERE (config_id IN (SELECT id FROM custom_variable_configs WHERE module = 'IC')) @@ -1032,7 +1037,7 @@ sub order_details { my $tax_rate; my $taxamount; - my (@project_ids, %projectnumbers, %projectdescriptions); + my (@project_ids); push(@project_ids, $form->{"globalproject_id"}) if ($form->{"globalproject_id"}); @@ -1063,19 +1068,21 @@ sub order_details { push(@project_ids, $form->{"project_id_$i"}) if ($form->{"project_id_$i"}); } + my $projects = []; + my %projects_by_id; if (@project_ids) { - $query = "SELECT id, projectnumber, description FROM project WHERE id IN (" . - join(", ", map("?", @project_ids)) . ")"; - $sth = prepare_execute_query($form, $dbh, $query, @project_ids); - while (my $ref = $sth->fetchrow_hashref()) { - $projectnumbers{$ref->{id}} = $ref->{projectnumber}; - $projectdescriptions{$ref->{id}} = $ref->{description}; - } - $sth->finish(); + $projects = SL::DB::Manager::Project->get_all(query => [ id => \@project_ids ]); + %projects_by_id = map { $_->id => $_ } @$projects; } - $form->{"globalprojectnumber"} = $projectnumbers{$form->{"globalproject_id"}}; - $form->{"globalprojectdescription"} = $projectdescriptions{$form->{"globalproject_id"}}; + if ($projects_by_id{$form->{"globalproject_id"}}) { + $form->{globalprojectnumber} = $projects_by_id{$form->{"globalproject_id"}}->projectnumber; + $form->{globalprojectdescription} = $projects_by_id{$form->{"globalproject_id"}}->description; + + for (@{ $projects_by_id{$form->{"globalproject_id"}}->cvars_by_config }) { + $form->{"project_cvar_" . $_->config->name} = $_->value_as_text; + } + } $form->{discount} = []; @@ -1083,6 +1090,7 @@ sub order_details { IC->prepare_parts_for_printing(myconfig => $myconfig, form => $form); my $ic_cvar_configs = CVar->get_configs(module => 'IC'); + my $project_cvar_configs = CVar->get_configs(module => 'Projects'); my @arrays = qw(runningnumber number description longdescription qty ship unit bin @@ -1092,6 +1100,7 @@ sub order_details { price_factor price_factor_name partsgroup weight lineweight); push @arrays, map { "ic_cvar_$_->{name}" } @{ $ic_cvar_configs }; + push @arrays, map { "project_cvar_$_->{name}" } @{ $project_cvar_configs }; my @tax_arrays = qw(taxbase tax taxdescription taxrate taxnumber); @@ -1205,12 +1214,14 @@ sub order_details { $nodiscount += $linetotal; } + my $project = $projects_by_id{$form->{"project_id_$i"}} || SL::DB::Project->new; + push @{ $form->{TEMPLATE_ARRAYS}->{linetotal} }, $form->format_amount($myconfig, $linetotal, 2); push @{ $form->{TEMPLATE_ARRAYS}->{linetotal_nofmt} }, $linetotal_exact; push @{ $form->{TEMPLATE_ARRAYS}->{nodiscount_linetotal} }, $form->format_amount($myconfig, $nodiscount_linetotal, 2); push @{ $form->{TEMPLATE_ARRAYS}->{nodiscount_linetotal_nofmt} }, $nodiscount_linetotal; - push(@{ $form->{TEMPLATE_ARRAYS}->{projectnumber} }, $projectnumbers{$form->{"project_id_$i"}}); - push(@{ $form->{TEMPLATE_ARRAYS}->{projectdescription} }, $projectdescriptions{$form->{"project_id_$i"}}); + push @{ $form->{TEMPLATE_ARRAYS}->{projectnumber} }, $project->projectnumber; + push @{ $form->{TEMPLATE_ARRAYS}->{projectdescription} }, $project->description; my $lineweight = $form->{"qty_$i"} * $form->{"weight_$i"}; $totalweight += $lineweight; @@ -1282,6 +1293,8 @@ sub order_details { push @{ $form->{TEMPLATE_ARRAYS}->{"ic_cvar_$_->{name}"} }, CVar->format_to_template(CVar->parse($form->{"ic_cvar_$_->{name}_$i"}, $_), $_) for @{ $ic_cvar_configs }; + + push @{ $form->{TEMPLATE_ARRAYS}->{"project_cvar_" . $_->config->name} }, $_->value_as_text for @{ $project->cvars_by_config }; } }