Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 5e2c22ef

Von Tamino Steinert vor mehr als 1 Jahr hinzugefügt

  • ID 5e2c22ef7eb017c73db5728b7f89b01aa5c0bb4d
  • Vorgänger e71331bd
  • Nachfolger 2e34a1e0

Controller::Reclamation: nutze TypeData

Unterschiede anzeigen:

SL/Controller/Reclamation.pm
111 111

  
112 112
  $self->render(
113 113
    'reclamation/form',
114
    title => $self->get_title_for('add'),
114
    title => $self->type_data->text('add'),
115 115
    %{$self->{template_args}},
116 116
  );
117 117
}
......
125 125
  }
126 126

  
127 127
  my $order = SL::DB::Order->new(id => $::form->{from_id})->load;
128
  my $target_type = $order->is_sales ? SALES_RECLAMATION_TYPE()
129
                                     : PURCHASE_RECLAMATION_TYPE();
130
  my $reclamation = SL::Model::Record->new_from_workflow($order, $target_type);
128
  my $reclamation = SL::Model::Record->new_from_workflow($order, $self->type);
131 129

  
132 130
  $self->reclamation($reclamation);
133 131

  
......
139 137

  
140 138
  $self->render(
141 139
    'reclamation/form',
142
    title => $self->get_title_for('add'),
140
    title => $self->type_data->text('add'),
143 141
    %{$self->{template_args}},
144 142
  );
145 143
}
......
153 151
  }
154 152

  
155 153
  my $delivery_order = SL::DB::DeliveryOrder->new(id => $::form->{from_id})->load;
156
  my $target_type = $delivery_order->is_sales ? SALES_RECLAMATION_TYPE()
157
                                              : PURCHASE_RECLAMATION_TYPE();
158
  my $reclamation = SL::Model::Record->new_from_workflow($delivery_order, $target_type);
154
  my $reclamation = SL::Model::Record->new_from_workflow($delivery_order, $self->type);
159 155

  
160 156
  $self->reclamation($reclamation);
161 157

  
......
167 163

  
168 164
  $self->render(
169 165
    'reclamation/form',
170
    title => $self->get_title_for('add'),
166
    title => $self->type_data->text('add'),
171 167
    %{$self->{template_args}},
172 168
  );
173 169
}
......
181 177
  }
182 178

  
183 179
  my $invoice = SL::DB::Invoice->new(id => $::form->{from_id})->load;
184
  my $target_type = SALES_RECLAMATION_TYPE();
185
  my $reclamation = SL::Model::Record->new_from_workflow($invoice, $target_type);
180
  my $reclamation = SL::Model::Record->new_from_workflow($invoice, $self->type);
186 181

  
187 182
  $self->reclamation($reclamation);
188 183

  
......
194 189

  
195 190
  $self->render(
196 191
    'reclamation/form',
197
    title => $self->get_title_for('add'),
192
    title => $self->type_data->text('add'),
198 193
    %{$self->{template_args}},
199 194
  );
200 195
}
......
210 205
  require SL::DB::PurchaseInvoice;
211 206
  my $invoice = SL::DB::PurchaseInvoice->new(id => $::form->{from_id})->load;
212 207
  $invoice->{type} = $invoice->invoice_type; #can't add type → invoice_type in SL/DB/PurchaseInvoice
213
  my $target_type = PURCHASE_RECLAMATION_TYPE();
214
  my $reclamation = SL::Model::Record->new_from_workflow($invoice, $target_type);
208
  my $reclamation = SL::Model::Record->new_from_workflow($invoice, $self->type);
215 209

  
216 210
  $self->reclamation($reclamation);
217 211

  
......
223 217

  
224 218
  $self->render(
225 219
    'reclamation/form',
226
    title => $self->get_title_for('add'),
220
    title => $self->type_data->text('add'),
227 221
    %{$self->{template_args}},
228 222
  );
229 223
}
......
244 238

  
245 239
  $self->render(
246 240
    'reclamation/form',
247
    title => $self->get_title_for('edit'),
241
    title => $self->type_data->text('edit'),
248 242
    %{$self->{template_args}},
249 243
  );
250 244
}
......
255 249

  
256 250

  
257 251
  SL::Model::Record->delete($self->reclamation);
258
  flash_later('info', t8('The reclamation has been deleted'));
252
  flash_later('info', $self->type_data->text('delete'));
259 253

  
260 254
  my @redirect_params = (
261 255
    action => 'add',
......
450 444

  
451 445
  unless ($self->reclamation->customervendor) {
452 446
    return $self->js->flash('error',
453
                            $self->cv eq 'customer' ?
454
                                t8('Cannot send E-mail without customer given')
455
                              : t8('Cannot send E-mail without vendor given'))
456
                    ->render($self);
447
      $self->type_data->properties('is_customer') ?
448
          t8('Cannot send E-mail without customer given')
449
        : t8('Cannot send E-mail without vendor given'))
450
      ->render($self);
457 451
  }
458 452

  
459 453
  my $form = Form->new;
......
483 477
                                  email_form  => $email_form,
484 478
                                  show_bcc    => $::auth->assert('email_bcc', 'may fail'),
485 479
                                  FILES       => \%files,
486
                                  is_customer => $self->cv eq 'customer',
480
                                  is_customer => $self->type_data->properties('is_customer'),
487 481
                                  ALL_EMPLOYEES => $self->{all_employees},
488 482
  );
489 483

  
......
674 668

  
675 669
  $self->recalc();
676 670

  
677
  my $cv_method = $self->cv;
678

  
679 671
  if ( $self->reclamation->customervendor->contacts
680 672
       && scalar @{ $self->reclamation->customervendor->contacts } > 0) {
681 673
    $self->js->show('#cp_row');
......
716 708
sub action_show_customer_vendor_details_dialog {
717 709
  my ($self) = @_;
718 710

  
719
  my $is_sales = ($self->cv eq 'customer');
711
  my $is_customer = ($self->type_data->properties('is_customer'));
720 712
  my $cv;
721
  if ($is_sales) {
713
  if ($is_customer) {
722 714
    $cv = SL::DB::Customer->new(id => $::form->{cv_id})->load;
723 715
  } else {
724 716
    $cv = SL::DB::Vendor->new(id => $::form->{cv_id})->load;
......
731 723
  $details{language}            = $cv->language_obj->description  if $cv->language_obj;
732 724
  $details{delivery_terms}      = $cv->delivery_term->description if $cv->delivery_term;
733 725
  $details{payment_terms}       = $cv->payment->description       if $cv->payment;
734
  $details{pricegroup}          = $cv->pricegroup->pricegroup     if !$is_sales && $cv->pricegroup;
726
  $details{pricegroup}          = $cv->pricegroup->pricegroup     if !$is_customer && $cv->pricegroup;
735 727

  
736 728
  foreach my $entry (@{ $cv->shipto }) {
737 729
    push @{ $details{SHIPTO} },   { map { $_ => $entry->$_ } @{$entry->meta->columns} };
......
741 733
  }
742 734

  
743 735
  $_[0]->render('common/show_vc_details', { layout => 0 },
744
                is_customer => !$is_sales,
736
                is_customer => $is_customer,
745 737
                %details);
746 738
}
747 739

  
......
1032 1024

  
1033 1025
  $self->render(
1034 1026
    'reclamation/form',
1035
    title => $self->get_title_for('edit'),
1027
    title => $self->type_data->text('edit'),
1036 1028
    %{$self->{template_args}}
1037 1029
  );
1038 1030
}
......
1231 1223
sub init_cv {
1232 1224
  my ($self) = @_;
1233 1225

  
1234
  my $cv = (any { $self->type eq $_ } (SALES_RECLAMATION_TYPE()))   ? 'customer'
1235
         : (any { $self->type eq $_ } (PURCHASE_RECLAMATION_TYPE())) ? 'vendor'
1236
         : die "Not a valid type for reclamation";
1237

  
1238
  return $cv;
1226
  $self->type_data->properties('customervendor');
1239 1227
}
1240 1228

  
1241 1229
sub init_search_cvpartnumber {
......
1243 1231

  
1244 1232
  my $user_prefs = SL::Helper::UserPreferences::PartPickerSearch->new();
1245 1233
  my $search_cvpartnumber;
1246
  $search_cvpartnumber = !!$user_prefs->get_sales_search_customer_partnumber() if $self->cv eq 'customer';
1247
  $search_cvpartnumber = !!$user_prefs->get_purchase_search_makemodel()        if $self->cv eq 'vendor';
1234
  if ($self->type_data->properties('is_customer')) {
1235
    $search_cvpartnumber = !!$user_prefs->get_sales_search_customer_partnumber()
1236
  } else {
1237
    $search_cvpartnumber = !!$user_prefs->get_purchase_search_makemodel();
1238
  }
1248 1239

  
1249 1240
  return $search_cvpartnumber;
1250 1241
}
......
1275 1266
      language                => t8('Language'),
1276 1267
      department              => t8('Department'),
1277 1268
      globalproject           => t8('Project Number'),
1278
      cv_record_number        => ($self->type eq SALES_RECLAMATION_TYPE() ? t8('Customer Record Number') : t8('Vendor Record Number')),
1269
      cv_record_number        => ($self->type_data->properties('is_customer') ? t8('Customer Record Number') : t8('Vendor Record Number')),
1279 1270
      transaction_description => t8('Description'),
1280 1271
      notes                   => t8('Notes'),
1281 1272
      intnotes                => t8('Internal Notes'),
......
1327 1318

  
1328 1319
sub init_part_picker_classification_ids {
1329 1320
  my ($self)    = @_;
1330
  my $attribute = 'used_for_' . ($self->type eq SALES_RECLAMATION_TYPE() ? 'sale' : 'purchase');
1331 1321

  
1332
  return [ map { $_->id } @{ SL::DB::Manager::PartClassification->get_all(where => [ $attribute => 1 ]) } ];
1322
  return [ map { $_->id } @{ SL::DB::Manager::PartClassification->get_all(where => $self->type_data->part_classification_query()) } ];
1333 1323
}
1334 1324

  
1335 1325
sub check_auth {
1336 1326
  my ($self) = @_;
1337

  
1338
  my $right_for = { map { $_ => $_.'_edit' } @{$self->valid_types} };
1339

  
1340
  my $right   = $right_for->{ $self->type };
1341
  $right    ||= 'DOES_NOT_EXIST';
1342

  
1343
  $::auth->assert($right);
1327
  $::auth->assert($self->type_data->rights('edit'));
1344 1328
}
1345 1329

  
1346 1330
# build the selection box for contacts
......
1484 1468
                     reclamation_items  => [],
1485 1469
                     currency_id => $::instance_conf->get_currency_id(),
1486 1470
                   );
1487
    my $cv_id_method = $self->cv . '_id';
1488
    if ($::form->{$cv_id_method}) {
1489
      $reclamation->$cv_id_method($::form->{$cv_id_method});
1490
    }
1491 1471
  }
1492 1472

  
1493 1473
  my $form_reclamation_items = delete $::form->{reclamation}->{reclamation_items};
......
1719 1699
                       ? SL::DB::Manager::ReclamationItem->get_all(where => [id => $self->item_ids_to_delete])
1720 1700
                       : undef;
1721 1701

  
1722
  SL::Model::Record->save($self->order,
1702
  SL::Model::Record->save($self->reclamation,
1723 1703
                          with_validity_token  => { scope => SL::DB::ValidityToken::SCOPE_RECLAMATION_SAVE(), token => $::form->{form_validity_token} },
1724 1704
                          delete_custom_shipto => $self->is_custom_shipto_to_delete || $self->reclamation->custom_shipto->is_empty,
1725 1705
                          items_to_delete      => $items_to_delete,
......
1744 1724

  
1745 1725
  # check for direct delivery
1746 1726
  # copy shipto in custom shipto (custom shipto will be copied by new_from() in case)
1747
  if ($::form->{type} eq PURCHASE_RECLAMATION_TYPE()) {
1727
  if (!$self->type_data->properties('is_customer')) {
1748 1728
    if ($::form->{use_shipto}) {
1749 1729
      my $custom_shipto = $source_reclamation->shipto->clone('SL::DB::Reclamation');
1750 1730
      $self->reclamation->custom_shipto($custom_shipto) if $custom_shipto;
......
1762 1742

  
1763 1743
  $self->render(
1764 1744
    'reclamation/form',
1765
    title => $self->get_title_for('add'),
1745
    title => $self->type_data->text('add'),
1766 1746
    %{$self->{template_args}}
1767 1747
  );
1768 1748
}
......
2036 2016
      sub      => sub { $_[0]->closed ? t8('Yes') : t8('No') },
2037 2017
    },
2038 2018
  );
2039
  if ($self->type eq SALES_RECLAMATION_TYPE()) {
2019
  if ($self->type_data->properties('is_customer')) {
2040 2020
    $column_defs{customer} = ({
2041 2021
      raw_data => sub { $_[0]->customervendor->presenter->customer(display => 'table-cell', callback => $callback) },
2042 2022
      sub      => sub { $_[0]->customervendor->name },
......
2051 2031
      },
2052 2032
      sub      => sub { $_[0]->contact ? $_[0]->contact->cp_name : '' },
2053 2033
    });
2054
  } elsif ($self->type eq PURCHASE_RECLAMATION_TYPE()) {
2034
  } else {
2055 2035
    $column_defs{vendor} = ({
2056 2036
      raw_data => sub { $_[0]->customervendor->presenter->vendor(display => 'table-cell', callback => $callback) },
2057 2037
      sub      => sub { $_[0]->customervendor->name },
......
2113 2093
     { output => 0 },
2114 2094
     models => $self->models
2115 2095
    ),
2116
    title                 => $self->type eq SALES_RECLAMATION_TYPE() ? t8('Sales Reclamations') : t8('Purchase Reclamations'),
2096
    title                 => $self->type_data->text('list'),
2117 2097
    allow_pdf_export      => 1,
2118 2098
    allow_csv_export      => 1,
2119 2099
  );
......
2128 2108
sub _setup_edit_action_bar {
2129 2109
  my ($self, %params) = @_;
2130 2110

  
2131
  my $deletion_allowed = ($self->type eq SALES_RECLAMATION_TYPE()
2132
                          && $::instance_conf->get_sales_reclamation_show_delete)
2133
                      || ($self->type eq PURCHASE_RECLAMATION_TYPE()
2134
                          && $::instance_conf->get_purchase_reclamation_show_delete);
2135

  
2136 2111
  for my $bar ($::request->layout->get('actionbar')) {
2137 2112
    $bar->add(
2138 2113
      combobox => [
......
2168 2143
            $::instance_conf->get_reclamation_warn_duplicate_parts,
2169 2144
            $::instance_conf->get_reclamation_warn_no_reqdate,
2170 2145
          ],
2171
          only_if  => (any { $self->type eq $_ } (PURCHASE_RECLAMATION_TYPE())),
2146
          only_if  => $self->type_data->show_menu('save_and_sales_reclamation'),
2172 2147
        ],
2173 2148
        action => [
2174 2149
          t8('Save and Purchase Reclamation'),
2175 2150
          call      => [ 'kivi.Reclamation.purchase_reclamation_check_for_direct_delivery' ],
2176
          only_if   => (any { $self->type eq $_ } (SALES_RECLAMATION_TYPE())),
2151
          only_if  => $self->type_data->show_menu('save_and_purchase_reclamation'),
2177 2152
        ],
2178 2153
        action => [
2179 2154
          t8('Save and Order'),
......
2190 2165
            $::instance_conf->get_reclamation_warn_duplicate_parts,
2191 2166
            $::instance_conf->get_reclamation_warn_no_reqdate,
2192 2167
          ],
2193
          only_if   => (any { $self->type eq $_ } (SALES_RECLAMATION_TYPE())),
2168
          only_if  => $self->type_data->show_menu('save_and_rma_delivery_order'),
2194 2169
        ],
2195 2170
        action => [
2196 2171
          t8('Save and Supplier Delivery Order'),
......
2199 2174
            $::instance_conf->get_reclamation_warn_duplicate_parts,
2200 2175
            $::instance_conf->get_reclamation_warn_no_reqdate,
2201 2176
          ],
2202
          only_if   => (any { $self->type eq $_ } (PURCHASE_RECLAMATION_TYPE())),
2177
          only_if  => $self->type_data->show_menu('save_and_supplier_delivery_order'),
2203 2178
        ],
2204 2179
        action => [
2205 2180
          t8('Save and Credit Note'),
......
2208 2183
            $::instance_conf->get_reclamation_warn_duplicate_parts,
2209 2184
            $::instance_conf->get_reclamation_warn_no_reqdate,
2210 2185
          ],
2211
          only_if   => (any { $self->type eq $_ } (SALES_RECLAMATION_TYPE())),
2186
          only_if  => $self->type_data->show_menu('save_and_credit_note'),
2212 2187
        ],
2213 2188
      ], # end of combobox "Workflow"
2214 2189

  
......
2255 2230
        call     => [ 'kivi.Reclamation.delete_reclamation' ],
2256 2231
        confirm  => t8('Do you really want to delete this object?'),
2257 2232
        disabled => !$self->reclamation->id ? t8('This object has not been saved yet.') : undef,
2258
        only_if  => $deletion_allowed,
2233
        only_if  => $self->type_data->show_menu('delete'),
2259 2234
      ],
2260 2235

  
2261 2236
      combobox => [
......
2412 2387
  return %files;
2413 2388
}
2414 2389

  
2415
sub get_title_for {
2416
  my ($self, $action) = @_;
2417

  
2418
  return '' if none { lc($action)} qw(add edit);
2419

  
2420
  # for locales:
2421
  # t8("Add Sales Reclamation");
2422
  # t8("Add Purchase Reclamation");
2423
  # t8("Edit Sales Reclamation");
2424
  # t8("Edit Purchase Reclamation");
2425

  
2426
  $action = ucfirst(lc($action));
2427
  return $self->type eq SALES_RECLAMATION_TYPE()    ? t8("$action Sales Reclamation")
2428
       : $self->type eq PURCHASE_RECLAMATION_TYPE() ? t8("$action Purchase Reclamation")
2429
       : '';
2430
}
2431

  
2432 2390
sub get_item_cvpartnumber {
2433 2391
  my ($self, $item) = @_;
2434 2392

  
2435 2393
  return if !$self->search_cvpartnumber;
2436 2394
  return if !$self->reclamation->customervendor;
2437 2395

  
2438
  if ($self->cv eq 'vendor') {
2396
  if (!$self->reclamation->is_sales) {
2439 2397
    my @mms = grep { $_->make eq $self->reclamation->customervendor->id } @{$item->part->makemodels};
2440 2398
    $item->{cvpartnumber} = $mms[0]->model if scalar @mms;
2441
  } elsif ($self->cv eq 'customer') {
2399
  } elsif ($self->reclamation->is_sales) {
2442 2400
    my @cps = grep { $_->customer_id eq $self->reclamation->customervendor->id } @{$item->part->customerprices};
2443 2401
    $item->{cvpartnumber} = $cps[0]->customer_partnumber if scalar @cps;
2444 2402
  }

Auch abrufbar als: Unified diff