Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 17c7ec97

Von Moritz Bunkus vor mehr als 2 Jahren hinzugefügt

  • ID 17c7ec975d27f24146d8c72f09ec21c87c148166
  • Vorgänger 81cafff7
  • Nachfolger 5a6857e5

Zusätzliche Rechnungsadressen: in Kundenstammdaten bearbeiten

Unterschiede anzeigen:

SL/Controller/CustomerVendor.pm
61 61
    'delete',
62 62
    'delete_contact',
63 63
    'delete_shipto',
64
    'delete_additional_billing_address',
64 65
  ]
65 66
);
66 67

  
......
71 72
    'show',
72 73
    'update',
73 74
    'ajaj_get_shipto',
75
    'ajaj_get_additional_billing_address',
74 76
    'ajaj_get_contact',
75 77
    'ajax_list_prices',
76 78
  ]
......
88 90

  
89 91
__PACKAGE__->run_before('normalize_name');
90 92

  
93
my @ADDITIONAL_BILLING_ADDRESS_COLUMNS = qw(name department_1 department_2 contact street zipcode city country gln email phone fax default_address);
91 94

  
92 95
sub action_add {
93 96
  my ($self) = @_;
......
280 283
      $self->{shipto}->save(cascade => 1);
281 284
    }
282 285

  
286
    if ($self->is_customer && any { $self->{additional_billing_address}->$_ ne '' } @ADDITIONAL_BILLING_ADDRESS_COLUMNS) {
287
      $self->{additional_billing_address}->customer_id($self->{cv}->id);
288
      $self->{additional_billing_address}->save(cascade => 1);
289

  
290
      # Make sure only one address per customer has "default address" set.
291
      if ($self->{additional_billing_address}->default_address) {
292
        SL::DB::Manager::AdditionalBillingAddress->update_all(
293
          set   => { default_address => 0, },
294
          where => [
295
            customer_id => $self->{cv}->id,
296
            '!id'       => $self->{additional_billing_address}->id,
297
          ]);
298
      }
299
    }
300

  
283 301
    my $snumbers = $self->is_vendor() ? 'vendornumber_'. $self->{cv}->vendornumber : 'customernumber_'. $self->{cv}->customernumber;
284 302
    SL::DB::History->new(
285 303
      trans_id => $self->{cv}->id,
......
325 343
    push(@redirect_params, shipto_id => $self->{shipto}->shipto_id);
326 344
  }
327 345

  
346
  if ( $self->is_customer && $self->{additional_billing_address}->id ) {
347
    push(@redirect_params, additional_billing_address_id => $self->{additional_billing_address}->id);
348
  }
349

  
328 350
  $self->redirect_to(@redirect_params);
329 351
}
330 352

  
......
512 534
  $self->action_edit();
513 535
}
514 536

  
537
sub action_delete_additional_billing_address {
538
  my ($self) = @_;
539

  
540
  my $db = $self->{additional_billing_address}->db;
541

  
542
  if ( !$self->{additional_billing_address}->id ) {
543
    SL::Helper::Flash::flash('error', $::locale->text('No address selected to delete'));
544
  } else {
545
    $db->with_transaction(sub {
546
      if ( $self->{additional_billing_address}->used ) {
547
        $self->{additional_billing_address}->detach;
548
        $self->{additional_billing_address}->save(cascade => 1);
549
        SL::Helper::Flash::flash('info', $::locale->text('Address is in use and was flagged invalid.'));
550
      } else {
551
        $self->{additional_billing_address}->delete(cascade => 1);
552
        SL::Helper::Flash::flash('info', $::locale->text('Address deleted.'));
553
      }
554

  
555
      1;
556
    }) || die($db->error);
557

  
558
    $self->{additional_billing_address} = SL::DB::AdditionalBillingAddress->new;
559
  }
560

  
561
  $self->action_edit;
562
}
515 563

  
516 564
sub action_search {
517 565
  my ($self) = @_;
......
637 685
  $self->render(\SL::JSON::to_json($data), { type => 'json', process => 0 });
638 686
}
639 687

  
688
sub action_ajaj_get_additional_billing_address {
689
  my ($self) = @_;
690

  
691
  my $data = {
692
    additional_billing_address => {
693
      map { ($_ => $self->{additional_billing_address}->$_) } ('id', @ADDITIONAL_BILLING_ADDRESS_COLUMNS)
694
    },
695
  };
696

  
697
  $self->render(\SL::JSON::to_json($data), { type => 'json', process => 0 });
698
}
699

  
640 700
sub action_ajaj_get_contact {
641 701
  my ($self) = @_;
642 702

  
......
899 959
  $self->{shipto}->assign_attributes(%{$::form->{shipto}});
900 960
  $self->{shipto}->module('CT');
901 961

  
962
  if ($self->is_customer) {
963
    if ( $::form->{additional_billing_address}->{id} ) {
964
      $self->{additional_billing_address} = SL::DB::AdditionalBillingAddress->new(id => $::form->{additional_billing_address}->{id})->load;
965
    } else {
966
      $self->{additional_billing_address} = SL::DB::AdditionalBillingAddress->new;
967
    }
968
    $self->{additional_billing_address}->assign_attributes(%{ $::form->{additional_billing_address} });
969
  }
970

  
902 971
  if ( $::form->{contact}->{cp_id} ) {
903 972
    $self->{contact} = SL::DB::Contact->new(cp_id => $::form->{contact}->{cp_id})->load();
904 973
  } else {
......
940 1009
    $self->{shipto} = SL::DB::Shipto->new();
941 1010
  }
942 1011

  
1012
  if ($self->is_customer) {
1013
    if ( $::form->{additional_billing_address_id} ) {
1014
      $self->{additional_billing_address} = SL::DB::AdditionalBillingAddress->new(id => $::form->{additional_billing_address_id})->load;
1015
      die($::locale->text('Error')) if $self->{additional_billing_address}->customer_id != $self->{cv}->id;
1016

  
1017
    } else {
1018
      $self->{additional_billing_address} = SL::DB::AdditionalBillingAddress->new;
1019
    }
1020
  }
1021

  
943 1022
  if ( $::form->{contact_id} ) {
944 1023
    $self->{contact} = SL::DB::Contact->new(cp_id => $::form->{contact_id})->load();
945 1024

  
......
988 1067
  $self->{note_followup} = SL::DB::FollowUp->new();
989 1068

  
990 1069
  $self->{shipto} = SL::DB::Shipto->new();
1070
  $self->{additional_billing_address} = SL::DB::AdditionalBillingAddress->new if $self->is_customer;
991 1071

  
992 1072
  $self->{contact} = $self->_new_contact_object;
993 1073
}
......
1064 1144
  $self->{shiptos} = $self->{cv}->shipto;
1065 1145
  $self->{shiptos} ||= [];
1066 1146

  
1147
  if ($self->is_customer) {
1148
    $self->{additional_billing_addresses} = $self->{cv}->additional_billing_addresses;
1149
    $self->{additional_billing_addresses} ||= [];
1150
  }
1151

  
1067 1152
  $self->{notes} = SL::DB::Manager::Note->get_all(
1068 1153
    query => [
1069 1154
      trans_id => $self->{cv}->id,
......
1311 1396
  my ($self) = @_;
1312 1397

  
1313 1398
  my $class  = 'SL::DB::' . ($self->is_vendor ? 'Vendor' : 'Customer');
1314
  return $class->new(
1399
  my $object = $class->new(
1315 1400
    contacts         => [],
1316 1401
    shipto           => [],
1317 1402
    custom_variables => [],
1318 1403
  );
1404

  
1405
  $object->additional_billing_addresses([]) if $self->is_customer;
1406

  
1407
  return $object;
1319 1408
}
1320 1409

  
1321 1410
sub _new_contact_object {

Auch abrufbar als: Unified diff