Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 71c189e9

Von Tamino Steinert vor etwa 1 Jahr hinzugefügt

  • ID 71c189e921adce25bd8dcbf15b14fcc4f0981814
  • Vorgänger e5657f46
  • Nachfolger b08e9707

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
}
......
2040 2020
      sub      => sub { $_[0]->closed ? t8('Yes') : t8('No') },
2041 2021
    },
2042 2022
  );
2043
  if ($self->type eq SALES_RECLAMATION_TYPE()) {
2023
  if ($self->type_data->properties('is_customer')) {
2044 2024
    $column_defs{customer} = ({
2045 2025
      raw_data => sub { $_[0]->customervendor->presenter->customer(display => 'table-cell', callback => $callback) },
2046 2026
      sub      => sub { $_[0]->customervendor->name },
......
2055 2035
      },
2056 2036
      sub      => sub { $_[0]->contact ? $_[0]->contact->cp_name : '' },
2057 2037
    });
2058
  } elsif ($self->type eq PURCHASE_RECLAMATION_TYPE()) {
2038
  } else {
2059 2039
    $column_defs{vendor} = ({
2060 2040
      raw_data => sub { $_[0]->customervendor->presenter->vendor(display => 'table-cell', callback => $callback) },
2061 2041
      sub      => sub { $_[0]->customervendor->name },
......
2117 2097
     { output => 0 },
2118 2098
     models => $self->models
2119 2099
    ),
2120
    title                 => $self->type eq SALES_RECLAMATION_TYPE() ? t8('Sales Reclamations') : t8('Purchase Reclamations'),
2100
    title                 => $self->type_data->text('list'),
2121 2101
    allow_pdf_export      => 1,
2122 2102
    allow_csv_export      => 1,
2123 2103
  );
......
2132 2112
sub _setup_edit_action_bar {
2133 2113
  my ($self, %params) = @_;
2134 2114

  
2135
  my $deletion_allowed = ($self->type eq SALES_RECLAMATION_TYPE()
2136
                          && $::instance_conf->get_sales_reclamation_show_delete)
2137
                      || ($self->type eq PURCHASE_RECLAMATION_TYPE()
2138
                          && $::instance_conf->get_purchase_reclamation_show_delete);
2139

  
2140 2115
  for my $bar ($::request->layout->get('actionbar')) {
2141 2116
    $bar->add(
2142 2117
      combobox => [
......
2172 2147
            $::instance_conf->get_reclamation_warn_duplicate_parts,
2173 2148
            $::instance_conf->get_reclamation_warn_no_reqdate,
2174 2149
          ],
2175
          only_if  => (any { $self->type eq $_ } (PURCHASE_RECLAMATION_TYPE())),
2150
          only_if  => $self->type_data->show_menu('save_and_sales_reclamation'),
2176 2151
        ],
2177 2152
        action => [
2178 2153
          t8('Save and Purchase Reclamation'),
2179 2154
          call      => [ 'kivi.Reclamation.purchase_reclamation_check_for_direct_delivery' ],
2180
          only_if   => (any { $self->type eq $_ } (SALES_RECLAMATION_TYPE())),
2155
          only_if  => $self->type_data->show_menu('save_and_purchase_reclamation'),
2181 2156
        ],
2182 2157
        action => [
2183 2158
          t8('Save and Order'),
......
2194 2169
            $::instance_conf->get_reclamation_warn_duplicate_parts,
2195 2170
            $::instance_conf->get_reclamation_warn_no_reqdate,
2196 2171
          ],
2197
          only_if   => (any { $self->type eq $_ } (SALES_RECLAMATION_TYPE())),
2172
          only_if  => $self->type_data->show_menu('save_and_rma_delivery_order'),
2198 2173
        ],
2199 2174
        action => [
2200 2175
          t8('Save and Supplier Delivery Order'),
......
2203 2178
            $::instance_conf->get_reclamation_warn_duplicate_parts,
2204 2179
            $::instance_conf->get_reclamation_warn_no_reqdate,
2205 2180
          ],
2206
          only_if   => (any { $self->type eq $_ } (PURCHASE_RECLAMATION_TYPE())),
2181
          only_if  => $self->type_data->show_menu('save_and_supplier_delivery_order'),
2207 2182
        ],
2208 2183
        action => [
2209 2184
          t8('Save and Credit Note'),
......
2212 2187
            $::instance_conf->get_reclamation_warn_duplicate_parts,
2213 2188
            $::instance_conf->get_reclamation_warn_no_reqdate,
2214 2189
          ],
2215
          only_if   => (any { $self->type eq $_ } (SALES_RECLAMATION_TYPE())),
2190
          only_if  => $self->type_data->show_menu('save_and_credit_note'),
2216 2191
        ],
2217 2192
      ], # end of combobox "Workflow"
2218 2193

  
......
2259 2234
        call     => [ 'kivi.Reclamation.delete_reclamation' ],
2260 2235
        confirm  => t8('Do you really want to delete this object?'),
2261 2236
        disabled => !$self->reclamation->id ? t8('This object has not been saved yet.') : undef,
2262
        only_if  => $deletion_allowed,
2237
        only_if  => $self->type_data->show_menu('delete'),
2263 2238
      ],
2264 2239

  
2265 2240
      combobox => [
......
2416 2391
  return %files;
2417 2392
}
2418 2393

  
2419
sub get_title_for {
2420
  my ($self, $action) = @_;
2421

  
2422
  return '' if none { lc($action)} qw(add edit);
2423

  
2424
  # for locales:
2425
  # t8("Add Sales Reclamation");
2426
  # t8("Add Purchase Reclamation");
2427
  # t8("Edit Sales Reclamation");
2428
  # t8("Edit Purchase Reclamation");
2429

  
2430
  $action = ucfirst(lc($action));
2431
  return $self->type eq SALES_RECLAMATION_TYPE()    ? t8("$action Sales Reclamation")
2432
       : $self->type eq PURCHASE_RECLAMATION_TYPE() ? t8("$action Purchase Reclamation")
2433
       : '';
2434
}
2435

  
2436 2394
sub get_item_cvpartnumber {
2437 2395
  my ($self, $item) = @_;
2438 2396

  
2439 2397
  return if !$self->search_cvpartnumber;
2440 2398
  return if !$self->reclamation->customervendor;
2441 2399

  
2442
  if ($self->cv eq 'vendor') {
2400
  if (!$self->reclamation->is_sales) {
2443 2401
    my @mms = grep { $_->make eq $self->reclamation->customervendor->id } @{$item->part->makemodels};
2444 2402
    $item->{cvpartnumber} = $mms[0]->model if scalar @mms;
2445
  } elsif ($self->cv eq 'customer') {
2403
  } elsif ($self->reclamation->is_sales) {
2446 2404
    my @cps = grep { $_->customer_id eq $self->reclamation->customervendor->id } @{$item->part->customerprices};
2447 2405
    $item->{cvpartnumber} = $cps[0]->customer_partnumber if scalar @cps;
2448 2406
  }

Auch abrufbar als: Unified diff