Verkaufsauftrag immer mit neuem Projekt speichern
authorG. Richardson <information@kivitendo-premium.de>
Thu, 6 Aug 2015 15:06:18 +0000 (17:06 +0200)
committerJan Büren <jan@kivitendo-premium.de>
Tue, 24 Nov 2015 07:13:20 +0000 (08:13 +0100)
sofern kein Projekt angegeben wurde. Die Projektnummer entspricht der
Auftragsnummer.

SL/OE.pm

index 3bb6458..ceca51a 100644 (file)
--- a/SL/OE.pm
+++ b/SL/OE.pm
@@ -42,6 +42,8 @@ use SL::Common;
 use SL::CVar;
 use SL::DB::Order;
 use SL::DB::PeriodicInvoicesConfig;
+use SL::DB::Project;
+use SL::DB::ProjectType;
 use SL::DB::Status;
 use SL::DB::Tax;
 use SL::DBUtils;
@@ -402,7 +404,7 @@ sub save {
 
   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;
+  $form->{$number_field} ||= $trans_number->create_unique; # set $form->{ordnumber} or $form->{quonumber}
 
   if ($form->{id}) {
     $query = qq|DELETE FROM shipto | .
@@ -533,6 +535,19 @@ sub save {
       $pricegroup_id *= 1;
       $pricegroup_id  = undef if !$pricegroup_id;
 
+      if ( $::instance_conf->get_order_always_project && !$form->{"globalproject_id"} && ( $form->{type} eq 'sales_order' ) ) {
+        my $new_project = SL::DB::Project->new(
+          projectnumber => $form->{ordnumber},
+          description   => $form->{customer},
+          active        => 1,
+          project_type_id =>  $::instance_conf->get_project_type_id,
+          project_status_id => $::instance_conf->get_project_status_id,
+          # id            => $form->{globalproject_id}
+        );
+        $new_project->save;
+        $form->{"globalproject_id"} = $new_project->id;
+      };
+
       CVar->get_non_editable_ic_cvars(form               => $form,
                                       dbh                => $dbh,
                                       row                => $i,