Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 19fda876

Von Tamino Steinert vor mehr als 1 Jahr hinzugefügt

  • ID 19fda8760d825977284e0b01ed32558bd7c0032d
  • Vorgänger eeec1d5e
  • Nachfolger 9cf4a1e5

Order: nutze TypeData

Unterschiede anzeigen:

SL/Controller/Order.pm
90 90

  
91 91
  $self->render(
92 92
    'order/form',
93
    title => $self->get_title_for('add'),
93
    title => $self->type_data->text('add'),
94 94
    %{$self->{template_args}}
95 95
  );
96 96
}
......
118 118

  
119 119
  $self->render(
120 120
    'order/form',
121
    title => $self->get_title_for('edit'),
121
    title => $self->type_data->text('edit'),
122 122
    %{$self->{template_args}}
123 123
  );
124 124
}
......
151 151
  $self->pre_render();
152 152
  $self->render(
153 153
    'order/form',
154
    title => $self->get_title_for('edit'),
154
    title => $self->type_data->text('edit'),
155 155
    %{$self->{template_args}}
156 156
  );
157 157
}
......
480 480
                                  email_form    => $email_form,
481 481
                                  show_bcc      => $::auth->assert('email_bcc', 'may fail'),
482 482
                                  FILES         => \%files,
483
                                  is_customer   => $self->cv eq 'customer',
483
                                  is_customer   => $self->type_data->properties('is_customer'),
484 484
                                  ALL_EMPLOYEES => \@employees_with_email,
485 485
                                  ALL_PARTNER_EMAIL_ADDRESSES => $all_partner_email_addresses,
486 486
                                  is_final_version => $self->is_final_version,
......
907 907

  
908 908
  $self->render(
909 909
    'order/form',
910
    title => $self->get_title_for('edit'),
910
    title => $self->type_data->text('edit'),
911 911
    %{$self->{template_args}}
912 912
  );
913 913
}
......
967 967
sub action_show_customer_vendor_details_dialog {
968 968
  my ($self) = @_;
969 969

  
970
  my $is_customer = 'customer' eq $::form->{vc};
970
  my $is_customer = $self->type_data->properties('is_customer');
971 971
  my $cv;
972 972
  if ($is_customer) {
973 973
    $cv = SL::DB::Customer->new(id => $::form->{vc_id})->load;
......
1307 1307

  
1308 1308
  $self->render(
1309 1309
    'order/form',
1310
    title => $self->get_title_for('edit'),
1310
    title => $self->type_data->text('edit'),
1311 1311
    %{$self->{template_args}}
1312 1312
  );
1313 1313

  
......
1597 1597
sub init_cv {
1598 1598
  my ($self) = @_;
1599 1599

  
1600
  my $cv = (any { $self->type eq $_ } (SALES_ORDER_TYPE(),    SALES_QUOTATION_TYPE()))   ? 'customer'
1601
         : (any { $self->type eq $_ } (PURCHASE_ORDER_TYPE(), REQUEST_QUOTATION_TYPE())) ? 'vendor'
1602
         : die "Not a valid type for order";
1603

  
1604
  return $cv;
1600
  return $self->type_data->properties('customervendor');
1605 1601
}
1606 1602

  
1607 1603
sub init_search_cvpartnumber {
......
1635 1631

  
1636 1632
sub init_part_picker_classification_ids {
1637 1633
  my ($self)    = @_;
1638
  my $attribute = 'used_for_' . ($self->type =~ m{sales} ? 'sale' : 'purchase');
1639 1634

  
1640
  return [ map { $_->id } @{ SL::DB::Manager::PartClassification->get_all(where => [ $attribute => 1 ]) } ];
1635
  return [ map { $_->id } @{ SL::DB::Manager::PartClassification->get_all(
1636
    where => $self->type_data->part_classification_query()) } ];
1641 1637
}
1642 1638

  
1643 1639
sub init_is_final_version {
......
1656 1652

  
1657 1653
sub check_auth {
1658 1654
  my ($self) = @_;
1659

  
1660
  my $right_for = { map { $_ => $_.'_edit' . ' | ' . $_.'_view' } @{$self->valid_types} };
1661

  
1662
  my $right   = $right_for->{ $self->type };
1663
  $right    ||= 'DOES_NOT_EXIST';
1664

  
1665
  $::auth->assert($right);
1655
  $::auth->assert($self->type_data->rights('view'));
1666 1656
}
1667 1657

  
1668 1658
sub check_auth_for_edit {
1669 1659
  my ($self) = @_;
1670

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

  
1673
  my $right   = $right_for->{ $self->type };
1674
  $right    ||= 'DOES_NOT_EXIST';
1675

  
1676
  $::auth->assert($right);
1660
  $::auth->assert($self->type_data->rights('edit'));
1677 1661
}
1678 1662

  
1679 1663
# build the selection box for contacts
......
2173 2157
sub setup_edit_action_bar {
2174 2158
  my ($self, %params) = @_;
2175 2159

  
2176
  my $deletion_allowed = (any { $self->type eq $_ } (SALES_QUOTATION_TYPE(), REQUEST_QUOTATION_TYPE()))
2177
                      || (($self->type eq SALES_ORDER_TYPE())    && $::instance_conf->get_sales_order_show_delete)
2178
                      || (($self->type eq PURCHASE_ORDER_TYPE()) && $::instance_conf->get_purchase_order_show_delete);
2179

  
2180 2160
  my @req_trans_cost_art = qw(kivi.Order.check_transport_cost_article_presence) x!!$::instance_conf->get_transport_cost_reminder_article_number_id;
2181 2161
  my @req_cusordnumber   = qw(kivi.Order.check_cusordnumber_presence)           x($self->type eq SALES_ORDER_TYPE() && $::instance_conf->get_order_warn_no_cusordnumber);
2182 2162

  
......
2192 2172
    $has_final_invoice               = any {'SL::DB::Invoice' eq ref $_ && "final_invoice" eq $_->type} @$lr;
2193 2173
  }
2194 2174

  
2195
  my $right_for         = { map { $_ => $_.'_edit' } @{$self->valid_types} };
2196
  my $right             = $right_for->{ $self->type };
2197
  $right              ||= 'DOES_NOT_EXIST';
2198
  my $may_edit_create   = $::auth->assert($right, 'may fail');
2175
  my $may_edit_create   = $::auth->assert($self->type_data->rights('edit'), 'may fail');
2199 2176

  
2200 2177
  my $is_final_version = $self->is_final_version;
2201 2178

  
......
2257 2234
          t8('Save and Quotation'),
2258 2235
          call     => [ 'kivi.submit_ajax_form', $self->url_for(action => "save_and_order_workflow", to_type => SALES_QUOTATION_TYPE()), '#order_form' ],
2259 2236
          checks   => [ @req_trans_cost_art, @req_cusordnumber ],
2260
          only_if  => (any { $self->type eq $_ } (SALES_ORDER_TYPE(), REQUEST_QUOTATION_TYPE())),
2237
          only_if  => $self->type_data->show_menu('save_and_quotation'),
2261 2238
          disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
2262 2239
        ],
2263 2240
        action => [
2264 2241
          t8('Save and RFQ'),
2265 2242
          call     => [ 'kivi.Order.purchase_check_for_direct_delivery', { to_type => REQUEST_QUOTATION_TYPE() } ],
2266
          only_if  => (any { $self->type eq $_ } (SALES_ORDER_TYPE(), SALES_QUOTATION_TYPE(), PURCHASE_ORDER_TYPE())),
2243
          only_if  => $self->type_data->show_menu('save_and_rfq'),
2267 2244
          disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
2268 2245
        ],
2269 2246
        action => [
2270 2247
          t8('Save and Sales Order'),
2271 2248
          call     => [ 'kivi.submit_ajax_form', $self->url_for(action => "save_and_order_workflow", to_type => SALES_ORDER_TYPE()), '#order_form' ],
2272 2249
          checks   => [ @req_trans_cost_art ],
2273
          only_if  => (any { $self->type eq $_ } (SALES_QUOTATION_TYPE(), REQUEST_QUOTATION_TYPE(), PURCHASE_ORDER_TYPE())),
2250
          only_if  => $self->type_data->show_menu('save_and_sales_order'),
2274 2251
          disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
2275 2252
        ],
2276 2253
        action => [
2277 2254
          t8('Save and Purchase Order'),
2278 2255
          call      => [ 'kivi.Order.purchase_check_for_direct_delivery', { to_type => PURCHASE_ORDER_TYPE() } ],
2279 2256
          checks    => [ @req_trans_cost_art, @req_cusordnumber ],
2280
          only_if   => (any { $self->type eq $_ } (SALES_ORDER_TYPE(), REQUEST_QUOTATION_TYPE())),
2257
          only_if   => $self->type_data->show_menu('save_and_purchase_order'),
2281 2258
          disabled  => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
2282 2259
        ],
2283 2260
        action => [
......
2289 2266
          checks    => [ 'kivi.Order.check_save_active_periodic_invoices',
2290 2267
                         @req_trans_cost_art, @req_cusordnumber,
2291 2268
          ],
2292
          only_if   => (any { $self->type eq $_ } (SALES_ORDER_TYPE(), PURCHASE_ORDER_TYPE())),
2269
          only_if   => $self->type_data->show_menu('save_and_delivery_order'),
2293 2270
          disabled  => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
2294 2271
        ],
2295 2272
        action => [
......
2301 2278
          checks    => [ 'kivi.Order.check_save_active_periodic_invoices',
2302 2279
                         @req_trans_cost_art, @req_cusordnumber,
2303 2280
          ],
2304
          only_if   => (any { $self->type eq $_ } (PURCHASE_ORDER_TYPE())),
2281
          only_if   => $self->type_data->show_menu('save_and_supplier_delivery_order'),
2305 2282
          disabled  => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
2306 2283
        ],
2307 2284
        action => [
......
2309 2286
          call      => [ 'kivi.Order.save', { action             => 'save_and_reclamation',
2310 2287
                                              warn_on_duplicates => $::instance_conf->get_order_warn_duplicate_parts },
2311 2288
          ],
2312
          only_if   => (any { $self->type eq $_ } (SALES_ORDER_TYPE(), PURCHASE_ORDER_TYPE()))
2289
          only_if   =>$self->type_data->show_menu('save_and_reclamation')
2313 2290
        ],
2314 2291
        action => [
2315 2292
          t8('Save and Invoice'),
......
2320 2297
                         @req_trans_cost_art, @req_cusordnumber,
2321 2298
          ],
2322 2299
          disabled  => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
2300
          only_if   => $self->type_data->show_menu('save_and_invoice'),
2323 2301
        ],
2324 2302
        action => [
2325 2303
          ($has_invoice_for_advance_payment ? t8('Save and Further Invoice for Advance Payment') : t8('Save and Invoice for Advance Payment')),
......
2332 2310
          disabled  => !$may_edit_create  ? t8('You do not have the permissions to access this function.')
2333 2311
                     : $has_final_invoice ? t8('This order has already a final invoice.')
2334 2312
                     :                      undef,
2335
          only_if   => (any { $self->type eq $_ } (SALES_ORDER_TYPE())),
2313
          only_if   => $self->type_data->show_menu('save_and_invoice_for_advance_payment'),
2336 2314
        ],
2337 2315
        action => [
2338 2316
          t8('Save and Final Invoice'),
......
2345 2323
          disabled  => !$may_edit_create  ? t8('You do not have the permissions to access this function.')
2346 2324
                     : $has_final_invoice ? t8('This order has already a final invoice.')
2347 2325
                     :                      undef,
2348
          only_if   => (any { $self->type eq $_ } (SALES_ORDER_TYPE())) && $has_invoice_for_advance_payment,
2326
          only_if   => $self->type_data->show_menu('save_and_final_invoice') && $has_invoice_for_advance_payment,
2349 2327
        ],
2350 2328
        action => [
2351 2329
          t8('Save and AP Transaction'),
2352 2330
          call      => [ 'kivi.Order.save', { action             => 'save_and_ap_transaction',
2353 2331
                                              warn_on_duplicates => $::instance_conf->get_order_warn_duplicate_parts },
2354 2332
          ],
2355
          only_if   => (any { $self->type eq $_ } (PURCHASE_ORDER_TYPE())),
2333
          only_if   => $self->type_data->show_menu('save_and_ap_transaction'),
2356 2334
          disabled  => !$may_edit_create  ? t8('You do not have the permissions to access this function.') : undef,
2357 2335
        ],
2358 2336

  
......
2407 2385
        disabled => !$may_edit_create  ? t8('You do not have the permissions to access this function.')
2408 2386
                  : !$self->order->id  ? t8('This object has not been saved yet.')
2409 2387
                  :                      undef,
2410
        only_if  => $deletion_allowed,
2388
        only_if  => $self->type_data->show_menu('delete'),
2411 2389
      ],
2412 2390

  
2413 2391
      combobox => [
......
2552 2530
  return $active ? t8('active') : t8('inactive');
2553 2531
}
2554 2532

  
2555
sub get_title_for {
2556
  my ($self, $action) = @_;
2557

  
2558
  return '' if none { lc($action)} qw(add edit);
2559

  
2560
  # for locales:
2561
  # $::locale->text("Add Sales Order");
2562
  # $::locale->text("Add Purchase Order");
2563
  # $::locale->text("Add Quotation");
2564
  # $::locale->text("Add Request for Quotation");
2565
  # $::locale->text("Edit Sales Order");
2566
  # $::locale->text("Edit Purchase Order");
2567
  # $::locale->text("Edit Quotation");
2568
  # $::locale->text("Edit Request for Quotation");
2569

  
2570
  $action = ucfirst(lc($action));
2571
  return $self->type eq SALES_ORDER_TYPE()       ? $::locale->text("$action Sales Order")
2572
       : $self->type eq PURCHASE_ORDER_TYPE()    ? $::locale->text("$action Purchase Order")
2573
       : $self->type eq SALES_QUOTATION_TYPE()   ? $::locale->text("$action Quotation")
2574
       : $self->type eq REQUEST_QUOTATION_TYPE() ? $::locale->text("$action Request for Quotation")
2575
       : '';
2576
}
2577

  
2578 2533
sub get_item_cvpartnumber {
2579 2534
  my ($self, $item) = @_;
2580 2535

  
......
2650 2605
}
2651 2606

  
2652 2607
sub nr_key {
2653
  return $_[0]->type eq SALES_ORDER_TYPE()       ? 'ordnumber'
2654
       : $_[0]->type eq PURCHASE_ORDER_TYPE()    ? 'ordnumber'
2655
       : $_[0]->type eq SALES_QUOTATION_TYPE()   ? 'quonumber'
2656
       : $_[0]->type eq REQUEST_QUOTATION_TYPE() ? 'quonumber'
2657
       : '';
2608
  my ($self) = @_;
2609

  
2610
  return $self->type_data->properties('nr_key');
2658 2611
}
2659 2612

  
2660 2613
sub save_and_redirect_to {
......
2662 2615

  
2663 2616
  $self->save();
2664 2617

  
2665
  my $text = $self->type eq SALES_ORDER_TYPE()       ? $::locale->text('The order has been saved')
2666
           : $self->type eq PURCHASE_ORDER_TYPE()    ? $::locale->text('The order has been saved')
2667
           : $self->type eq SALES_QUOTATION_TYPE()   ? $::locale->text('The quotation has been saved')
2668
           : $self->type eq REQUEST_QUOTATION_TYPE() ? $::locale->text('The rfq has been saved')
2669
           : '';
2670
  flash_later('info', $text);
2618
  flash_later('info', $self->type_data->text('saved'));
2671 2619

  
2672 2620
  $self->redirect_to(%params, id => $self->order->id);
2673 2621
}

Auch abrufbar als: Unified diff