]> wagnertech.de Git - mfinanz.git/blobdiff - SL/Controller/RequirementSpecOrder.pm
Merge branch 'master' of http://wagnertech.de/git/mfinanz
[mfinanz.git] / SL / Controller / RequirementSpecOrder.pm
index f695a510a648f59318d139443ce31fae5b5578b5..60f9b43ebc10950da15a8ce0196e1f6726220048 100644 (file)
@@ -10,6 +10,7 @@ use List::Util qw(first);
 
 use SL::DB::Customer;
 use SL::DB::Order;
+use SL::DB::Order::TypeData qw(:types);
 use SL::DB::Part;
 use SL::DB::RequirementSpec;
 use SL::DB::RequirementSpecOrder;
@@ -93,7 +94,7 @@ sub action_update {
   my $order    = $self->rs_order->order;
   my $sections = $self->requirement_spec->sections_sorted;
 
-  if (!$::auth->assert($order->quotation ? 'sales_quotation_edit' : 'sales_order_edit', 1)) {
+  if (!$::auth->assert($order->type_data->rights('edit'), 1)) {
     return $self->js->flash('error', t8("You do not have the permissions to access this function."))->render;
   }
 
@@ -318,8 +319,8 @@ sub create_order_item {
     longdescription => $longdescription,
     qty             => $is_time_based ? $section->time_estimation * 1 : 1,
     unit            => $is_time_based ? $self->h_unit_name            : $part->unit,
-    sellprice       => $::form->round_amount($self->requirement_spec->hourly_rate * ($is_time_based ? 1 : $section->time_estimation), 2),
-    lastcost        => $part->lastcost,
+    sellprice       => $::form->round_amount($self->requirement_spec->hourly_rate * ($is_time_based ? 1 : $section->time_estimation * $section->sellprice_factor), 2),
+    lastcost        => $part->lastcost * $section->sellprice_factor,
     discount        => 0,
     project_id      => $self->requirement_spec->project_id,
   );
@@ -365,11 +366,15 @@ sub create_order {
   my @orderitems = map { $self->create_order_item(                section => $_,         language_id => $customer->language_id) } @{ $params{sections} };
   my @add_items  = map { $self->create_additional_part_order_item(additional_part => $_, language_id => $customer->language_id) } @{ $params{additional_parts} };
   my $employee   = SL::DB::Manager::Employee->current;
+  my $reqdate    = !$::form->{quotation} ? undef
+                 : $customer->payment_id ? $customer->payment->calc_date
+                 :                         DateTime->today_local->next_workday(extra_days => $::instance_conf->get_reqdate_interval)->to_kivitendo;
+  my $record_type = $::form->{quotation} ? SALES_QUOTATION_TYPE() : SALES_ORDER_TYPE();
   my $order      = SL::DB::Order->new(
+    record_type             => $record_type,
     globalproject_id        => $self->requirement_spec->project_id,
     transdate               => DateTime->today_local,
-    reqdate                 => $::form->{quotation} && $customer->payment_id ? $customer->payment->calc_date : undef,
-    quotation               => !!$::form->{quotation},
+    reqdate                 => $reqdate,
     orderitems              => [ @orderitems, @add_items ],
     customer_id             => $customer->id,
     taxincluded             => $customer->taxincluded,