CustomerVendor: Auskommentierten Code gelöscht
[kivitendo-erp.git] / SL / Controller / CustomerVendor.pm
index 2d4bd6c..b8672f1 100644 (file)
@@ -39,6 +39,7 @@ __PACKAGE__->run_before(
     'save_and_order',
     'save_and_quotation',
     'save_and_rfq',
+    'delete',
     'delete_contact',
     'delete_shipto',
   ]
@@ -93,8 +94,7 @@ sub _save {
       if ( $self->{cv}->vendornumber ) {
         $cvs_by_nr = SL::DB::Manager::Vendor->get_all(query => [vendornumber => $self->{cv}->vendornumber]);
       }
-    }
-    else {
+    } else {
       if ( $self->{cv}->customernumber ) {
         $cvs_by_nr = SL::DB::Manager::Customer->get_all(query => [customernumber => $self->{cv}->customernumber]);
       }
@@ -249,11 +249,10 @@ sub action_delete {
 
   if( !$self->is_orphaned() ) {
     $self->action_edit();
-  }
-  else {
+  } else {
 
     $db->do_transaction(sub {
-      $self->{cv}->delete();
+      $self->{cv}->delete(cascade => 1);
 
       my $snumbers = $self->is_vendor() ? 'vendornumber_'. $self->{cv}->vendornumber : 'customernumber_'. $self->{cv}->customernumber;
       SL::DB::History->new(
@@ -286,7 +285,7 @@ sub action_delete_contact {
         $self->{contact}->save();
         SL::Helper::Flash::flash('info', $::locale->text('Contact is in use and was flagged invalid.'));
       } else {
-        $self->{contact}->delete();
+        $self->{contact}->delete(cascade => 1);
         SL::Helper::Flash::flash('info', $::locale->text('Contact deleted.'));
       }
     }) || die($db->error);
@@ -309,10 +308,10 @@ sub action_delete_shipto {
     $db->do_transaction(sub {
       if ( $self->{shipto}->used ) {
         $self->{shipto}->detach();
-        $self->{shipto}->save();
+        $self->{shipto}->save(cascade => 1);
         SL::Helper::Flash::flash('info', $::locale->text('Shipto is in use and was flagged invalid.'));
       } else {
-        $self->{shipto}->delete();
+        $self->{shipto}->delete(cascade => 1);
         SL::Helper::Flash::flash('info', $::locale->text('Shipto deleted.'));
       }
     }) || die($db->error);
@@ -360,8 +359,7 @@ sub action_get_delivery {
     $arap = 'ap';
     $db = 'vendor';
     $qty_sign = ' * -1 AS qty';
-  }
-  else {
+  } else {
     $arap = 'ar';
     $db = 'customer';
     $qty_sign = '';
@@ -448,8 +446,7 @@ sub action_ajaj_get_contact {
 
         if ( $_ eq 'birthday' && $self->{contact}->$name ) {
           $name => $self->{contact}->$name->to_lxoffice;
-        }
-        else {
+        } else {
           $name => $self->{contact}->$name;
         }
       }
@@ -465,8 +462,7 @@ sub action_ajaj_get_contact {
       {
         if ( $_->config->type eq 'number' ) {
           $_->config->name => $::form->format_amount(\%::myconfig, $_->value, -2);
-        }
-        else {
+        } else {
           $_->config->name => $_->value;
         }
       }
@@ -568,16 +564,13 @@ sub _instantiate_args {
   if ( $::form->{cv}->{id} ) {
     if ( $self->is_vendor() ) {
       $self->{cv} = SL::DB::Vendor->new(id => $::form->{cv}->{id})->load();
-    }
-    else {
+    } else {
       $self->{cv} = SL::DB::Customer->new(id => $::form->{cv}->{id})->load();
     }
-  }
-  else {
+  } else {
     if ( $self->is_vendor() ) {
       $self->{cv} = SL::DB::Vendor->new();
-    }
-    else {
+    } else {
       $self->{cv} = SL::DB::Customer->new();
     }
   }
@@ -593,25 +586,14 @@ sub _instantiate_args {
     $cvar->value($value);
   }
 
-#  foreach my $cvar_key (keys(%{$::form->{cv_cvars}})) {
-#    my $cvar_value = $::form->{cv_cvars}->{$cvar_key};
-#    my $cvar = $self->{cv}->cvar_by_name($cvar_key);
-#    $cvar->value($cvar_value);
-#  }
-
   if ( $::form->{note}->{id} ) {
     $self->{note} = SL::DB::Note->new(id => $::form->{note}->{id})->load();
-  }
-  else {
+  } else {
     $self->{note} = SL::DB::Note->new();
   }
   $self->{note}->assign_attributes(%{$::form->{note}});
   $self->{note}->created_by($curr_employee->id);
   $self->{note}->trans_module('ct');
-  #  if ( $self->{note}->trans_id != $self->{cv}->id ) {
-  #    die($::locale->text('Error'));
-  #  }
-
 
   $self->{note_followup} = SL::DB::FollowUp->new();
   $self->{note_followup}->assign_attributes(%{$::form->{note_followup}});
@@ -620,26 +602,18 @@ sub _instantiate_args {
 
   if ( $::form->{shipto}->{shipto_id} ) {
     $self->{shipto} = SL::DB::Shipto->new(shipto_id => $::form->{shipto}->{shipto_id})->load();
-  }
-  else {
+  } else {
     $self->{shipto} = SL::DB::Shipto->new();
   }
   $self->{shipto}->assign_attributes(%{$::form->{shipto}});
   $self->{shipto}->module('CT');
-#  if ( $self->{shipto}->trans_id != $self->{cv}->id ) {
-#    die($::locale->text('Error'));
-#  }
 
   if ( $::form->{contact}->{cp_id} ) {
     $self->{contact} = SL::DB::Contact->new(cp_id => $::form->{contact}->{cp_id})->load();
-  }
-  else {
+  } else {
     $self->{contact} = SL::DB::Contact->new();
   }
   $self->{contact}->assign_attributes(%{$::form->{contact}});
-#  if ( $self->{contact}->cp_cv_id != $self->{cv}->id ) {
-#    die($::locale->text('Error'));
-#  }
 
   foreach my $cvar (@{$self->{contact}->cvars_by_config()}) {
     my $value = $::form->{contact_cvars}->{$cvar->config->name};
@@ -657,8 +631,7 @@ sub _load_customer_vendor {
 
   if ( $self->is_vendor() ) {
     $self->{cv} = SL::DB::Vendor->new(id => $::form->{id})->load();
-  }
-  else {
+  } else {
     $self->{cv} = SL::DB::Customer->new(id => $::form->{id})->load();
   }
 
@@ -671,8 +644,7 @@ sub _load_customer_vendor {
     if ( $self->{shipto}->trans_id != $self->{cv}->id ) {
       die($::locale->text('Error'));
     }
-  }
-  else {
+  } else {
     $self->{shipto} = SL::DB::Shipto->new();
   }
 
@@ -682,8 +654,7 @@ sub _load_customer_vendor {
     if ( $self->{contact}->cp_cv_id != $self->{cv}->id ) {
       die($::locale->text('Error'));
     }
-  }
-  else {
+  } else {
     $self->{contact} = SL::DB::Contact->new();
   }
 }
@@ -693,8 +664,7 @@ sub _create_customer_vendor {
 
   if ( $self->is_vendor() ) {
     $self->{cv} = SL::DB::Vendor->new();
-  }
-  else {
+  } else {
     $self->{cv} = SL::DB::Customer->new();
   }