Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision f3842deb

Von Tamino Steinert vor etwa 1 Jahr hinzugefügt

  • ID f3842debb17a887b210cd16ae6311d0270ef25a8
  • Vorgänger 48243bb3
  • Nachfolger 7ec7edbc

TypeData: nutzte Konstanten anstatt String für Typen

Unterschiede anzeigen:

SL/Controller/DeliveryOrder.pm
182 182
  # make new order from given orders
183 183
  my @multi_orders = map { SL::DB::DeliveryOrder->new(id => $_)->load } @multi_ids;
184 184
  $self->{converted_from_oe_id} = join ' ', map { $_->id } @multi_orders;
185
  my $target_type = "sales_delivery_order";
185
  my $target_type = SALES_DELIVERY_ORDER_TYPE();
186 186
  my $delivery_order = SL::Model::Record->new_from_workflow_multi(\@multi_orders, $target_type, sort_sources_by => 'transdate');
187 187
  $self->order($delivery_order);
188 188

  
SL/Controller/Order.pm
36 36
use SL::DB::Helper::RecordLink qw(set_record_link_conversions);
37 37
use SL::DB::Helper::TypeDataProxy;
38 38
use SL::Model::Record;
39
use SL::DB::Order::TypeData qw(:types);
40
use SL::DB::Reclamation::TypeData qw(:types);
39 41

  
40 42
use SL::Helper::CreatePDF qw(:all);
41 43
use SL::Helper::PrintOptions;
......
99 101

  
100 102
  my $reclamation = SL::DB::Reclamation->new(id => $::form->{from_id})->load;
101 103
  my %params;
102
  my $target_type = $reclamation->is_sales ? 'sales_order'
103
                                           : 'purchase_order';
104
  my $target_type = $reclamation->is_sales ? SALES_ORDER_TYPE()
105
                                           : PURCHASE_ORDER_TYPE();
104 106
  my $order = SL::Model::Record->new_from_workflow($reclamation, $target_type);
105 107
  $self->{converted_from_reclamation_id} = $::form->{from_id};
106 108

  
......
197 199
  my ($self) = @_;
198 200

  
199 201
  SL::Model::Record->delete($self->order);
200
  my $text = $self->type eq sales_order_intake_type()        ? $::locale->text('The order intake has been deleted')
201
           : $self->type eq sales_order_type()               ? $::locale->text('The order confirmation has been deleted')
202
           : $self->type eq purchase_order_type()            ? $::locale->text('The order has been deleted')
203
           : $self->type eq sales_quotation_type()           ? $::locale->text('The quotation has been deleted')
204
           : $self->type eq request_quotation_type()         ? $::locale->text('The rfq has been deleted')
205
           : $self->type eq purchase_quotation_intake_type() ? $::locale->text('The quotation intake has been deleted')
202
  my $text = $self->type eq SALES_ORDER_INTAKE_TYPE()        ? $::locale->text('The order intake has been deleted')
203
           : $self->type eq SALES_ORDER_TYPE()               ? $::locale->text('The order confirmation has been deleted')
204
           : $self->type eq PURCHASE_ORDER_TYPE()            ? $::locale->text('The order has been deleted')
205
           : $self->type eq SALES_QUOTATION_TYPE()           ? $::locale->text('The quotation has been deleted')
206
           : $self->type eq REQUEST_QUOTATION_TYPE()         ? $::locale->text('The rfq has been deleted')
207
           : $self->type eq PURCHASE_QUOTATION_INTAKE_TYPE() ? $::locale->text('The quotation intake has been deleted')
206 208
           : '';
207 209
  flash_later('info', $text);
208 210

  
......
220 222

  
221 223
  $self->save();
222 224

  
223
  my $text = $self->type eq sales_order_intake_type()         ? $::locale->text('The order intake has been saved')
224
           : $self->type eq sales_order_type()                ? $::locale->text('The order confirmation has been saved')
225
           : $self->type eq purchase_order_type()             ? $::locale->text('The order has been saved')
226
           : $self->type eq sales_quotation_type()            ? $::locale->text('The quotation has been saved')
227
           : $self->type eq request_quotation_type()          ? $::locale->text('The rfq has been saved')
228
           : $self->type eq purchase_quotation_intake_type()  ? $::locale->text('The quotation intake has been saved')
225
  my $text = $self->type eq SALES_ORDER_INTAKE_TYPE()         ? $::locale->text('The order intake has been saved')
226
           : $self->type eq SALES_ORDER_TYPE()                ? $::locale->text('The order confirmation has been saved')
227
           : $self->type eq PURCHASE_ORDER_TYPE()             ? $::locale->text('The order has been saved')
228
           : $self->type eq SALES_QUOTATION_TYPE()            ? $::locale->text('The quotation has been saved')
229
           : $self->type eq REQUEST_QUOTATION_TYPE()          ? $::locale->text('The rfq has been saved')
230
           : $self->type eq PURCHASE_QUOTATION_INTAKE_TYPE()  ? $::locale->text('The quotation intake has been saved')
229 231
           : '';
230 232
  flash_later('info', $text);
231 233

  
......
752 754
  $config  ||= SL::DB::Manager::PeriodicInvoicesConfig->find_by(oe_id => $::form->{id}) if $::form->{id};
753 755

  
754 756
  my $has_active_periodic_invoices =
755
       $self->type eq sales_order_type()
757
       $self->type eq SALES_ORDER_TYPE()
756 758
    && $config
757 759
    && $config->active
758 760
    && (!$config->end_date || ($config->end_date > DateTime->today_local))
......
796 798
  # can't use save_and_redirect_to, because id is set!
797 799
  $self->save();
798 800

  
799
  my $to_type = $self->order->is_sales ? 'sales_reclamation'
800
                                       : 'purchase_reclamation';
801
  my $to_type = $self->order->is_sales ? SALES_RECLAMATION_TYPE()
802
                                       : PURCHASE_RECLAMATION_TYPE();
801 803
  $self->redirect_to(
802 804
    controller => 'Reclamation',
803 805
    action     => 'add_from_order',
......
865 867
  my $destination_type = $::form->{to_type} ? $::form->{to_type} : '';
866 868

  
867 869
  my $from_side        = $self->order->is_sales ? 'sales' : 'purchase';
868
  my $to_side          = (any { $destination_type eq $_ } (sales_order_intake_type(), sales_order_type(), sales_quotation_type())) ? 'sales' : 'purchase';
870
  my $to_side          = (any { $destination_type eq $_ } (SALES_ORDER_INTAKE_TYPE(), SALES_ORDER_TYPE(), SALES_QUOTATION_TYPE())) ? 'sales' : 'purchase';
869 871

  
870 872
  # check for direct delivery
871 873
  # copy shipto in custom shipto (custom shipto will be copied by new_from() in case)
......
878 880
  $self->order(SL::DB::Order->new_from($self->order, destination_type => $destination_type));
879 881

  
880 882
  # no linked records to quotations from the same side (sales -> sales or purchase -> purchase)
881
  if (    (any { $destination_type eq $_ } (sales_quotation_type(), request_quotation_type()))
883
  if (    (any { $destination_type eq $_ } (SALES_QUOTATION_TYPE(), REQUEST_QUOTATION_TYPE()))
882 884
       && $from_side eq $to_side) {
883 885
    delete $::form->{id};
884 886
    delete $::form->{$_} for qw(converted_from_oe_id converted_from_orderitems_ids);
......
1630 1632
#
1631 1633

  
1632 1634
sub init_valid_types {
1633
  [ sales_order_intake_type(), sales_order_type(), purchase_order_type(), sales_quotation_type(), request_quotation_type(), purchase_quotation_intake_type() ];
1635
  $_[0]->type_data->valid_types;
1634 1636
}
1635 1637

  
1636 1638
sub init_type {
......
1646 1648
sub init_cv {
1647 1649
  my ($self) = @_;
1648 1650

  
1649
  my $cv = (any { $self->type eq $_ } (sales_order_intake_type(), sales_order_type(),       sales_quotation_type()))           ? 'customer'
1650
         : (any { $self->type eq $_ } (purchase_order_type(),     request_quotation_type(), purchase_quotation_intake_type())) ? 'vendor'
1651
  my $cv = (any { $self->type eq $_ } (SALES_ORDER_INTAKE_TYPE(), SALES_ORDER_TYPE(),       SALES_QUOTATION_TYPE()))           ? 'customer'
1652
         : (any { $self->type eq $_ } (PURCHASE_ORDER_TYPE(),     REQUEST_QUOTATION_TYPE(), PURCHASE_QUOTATION_INTAKE_TYPE())) ? 'vendor'
1651 1653
         : die "Not a valid type for order";
1652 1654

  
1653 1655
  return $cv;
......
1707 1709
  my ($self) = @_;
1708 1710

  
1709 1711
  my $right_for = { map { $_ => $_.'_edit' . ' | ' . $_.'_view' } @{$self->valid_types} };
1710
  $right_for->{ sales_order_intake_type()        } = 'sales_order_edit | sales_order_view';
1711
  $right_for->{ purchase_quotation_intake_type() } = 'request_quotation_edit | request_quotation_view';
1712
  $right_for->{ SALES_ORDER_INTAKE_TYPE()        } = 'sales_order_edit | sales_order_view';
1713
  $right_for->{ PURCHASE_QUOTATION_INTAKE_TYPE() } = 'request_quotation_edit | request_quotation_view';
1712 1714

  
1713 1715
  my $right   = $right_for->{ $self->type };
1714 1716
  $right    ||= 'DOES_NOT_EXIST';
......
1720 1722
  my ($self) = @_;
1721 1723

  
1722 1724
  my $right_for = { map { $_ => $_.'_edit' } @{$self->valid_types} };
1723
  $right_for->{ sales_order_intake_type()        } = 'sales_order_edit';
1724
  $right_for->{ purchase_quotation_intake_type() } = 'request_quotation_edit';
1725
  $right_for->{ SALES_ORDER_INTAKE_TYPE()        } = 'sales_order_edit';
1726
  $right_for->{ PURCHASE_QUOTATION_INTAKE_TYPE() } = 'request_quotation_edit';
1725 1727

  
1726 1728
  my $right   = $right_for->{ $self->type };
1727 1729
  $right    ||= 'DOES_NOT_EXIST';
......
1871 1873
  my $order;
1872 1874
  $order   = SL::DB::Order->new(id => $::form->{id})->load(with => [ 'orderitems', 'orderitems.part' ]) if $::form->{id};
1873 1875
  $order ||= SL::DB::Order->new(orderitems  => [],
1874
                                quotation   => (any { $self->type eq $_ } (sales_quotation_type(), request_quotation_type(), purchase_quotation_intake_type())),
1875
                                intake      => (any { $self->type eq $_ } (sales_order_intake_type(), purchase_quotation_intake_type())),
1876
                                quotation   => (any { $self->type eq $_ } (SALES_QUOTATION_TYPE(), REQUEST_QUOTATION_TYPE(), PURCHASE_QUOTATION_INTAKE_TYPE())),
1877
                                intake      => (any { $self->type eq $_ } (SALES_ORDER_INTAKE_TYPE(), PURCHASE_QUOTATION_INTAKE_TYPE())),
1876 1878
                                currency_id => $::instance_conf->get_currency_id(),);
1877 1879

  
1878 1880
  my $cv_id_method = $self->cv . '_id';
......
2199 2201
    $item->active_discount_source($price_source->discount_from_source($item->active_discount_source));
2200 2202
  }
2201 2203

  
2202
  if (any { $self->type eq $_ } (sales_order_intake_type(), sales_order_type(), purchase_order_type())) {
2204
  if (any { $self->type eq $_ } (SALES_ORDER_INTAKE_TYPE(), SALES_ORDER_TYPE(), PURCHASE_ORDER_TYPE())) {
2203 2205
    # Calculate shipped qtys here to prevent calling calculate for every item via the items method.
2204 2206
    # Do not use write_to_objects to prevent order->delivered to be set, because this should be
2205 2207
    # the value from db, which can be set manually or is set when linked delivery orders are saved.
......
2218 2220
                                                } } @all_objects;
2219 2221
  }
2220 2222

  
2221
  if (   (any { $self->type eq $_ } (sales_quotation_type(), sales_order_intake_type(), sales_order_type()))
2223
  if (   (any { $self->type eq $_ } (SALES_QUOTATION_TYPE(), SALES_ORDER_INTAKE_TYPE(), SALES_ORDER_TYPE()))
2222 2224
      && $::instance_conf->get_transport_cost_reminder_article_number_id ) {
2223 2225
    $self->{template_args}->{transport_cost_reminder_article} = SL::DB::Part->new(id => $::instance_conf->get_transport_cost_reminder_article_number_id)->load;
2224 2226
  }
......
2236 2238
sub setup_edit_action_bar {
2237 2239
  my ($self, %params) = @_;
2238 2240

  
2239
  my $deletion_allowed = (any { $self->type eq $_ } (sales_quotation_type(), request_quotation_type(), purchase_quotation_intake_type()))
2240
                      || (($self->type eq sales_order_type())        && $::instance_conf->get_sales_order_show_delete)
2241
                      || (($self->type eq sales_order_intake_type()) && $::instance_conf->get_sales_order_show_delete)
2242
                      || (($self->type eq purchase_order_type())     && $::instance_conf->get_purchase_order_show_delete);
2241
  my $deletion_allowed = (any { $self->type eq $_ } (SALES_QUOTATION_TYPE(), REQUEST_QUOTATION_TYPE(), PURCHASE_QUOTATION_INTAKE_TYPE()))
2242
                      || (($self->type eq SALES_ORDER_TYPE())        && $::instance_conf->get_sales_order_show_delete)
2243
                      || (($self->type eq SALES_ORDER_INTAKE_TYPE()) && $::instance_conf->get_sales_order_show_delete)
2244
                      || (($self->type eq PURCHASE_ORDER_TYPE())     && $::instance_conf->get_purchase_order_show_delete);
2243 2245

  
2244 2246
  my @req_trans_cost_art = qw(kivi.Order.check_transport_cost_article_presence) x!!$::instance_conf->get_transport_cost_reminder_article_number_id;
2245
  my @req_cusordnumber   = qw(kivi.Order.check_cusordnumber_presence)           x(( any {$self->type eq $_} (sales_order_intake_type(), sales_order_type()) ) && $::instance_conf->get_order_warn_no_cusordnumber);
2247
  my @req_cusordnumber   = qw(kivi.Order.check_cusordnumber_presence)           x(( any {$self->type eq $_} (SALES_ORDER_INTAKE_TYPE(), SALES_ORDER_TYPE()) ) && $::instance_conf->get_order_warn_no_cusordnumber);
2246 2248

  
2247 2249
  my $has_invoice_for_advance_payment;
2248
  if ($self->order->id && $self->type eq sales_order_type()) {
2250
  if ($self->order->id && $self->type eq SALES_ORDER_TYPE()) {
2249 2251
    my $lr = $self->order->linked_records(direction => 'to', to => ['Invoice']);
2250 2252
    $has_invoice_for_advance_payment = any {'SL::DB::Invoice' eq ref $_ && "invoice_for_advance_payment" eq $_->type} @$lr;
2251 2253
  }
2252 2254

  
2253 2255
  my $has_final_invoice;
2254
  if ($self->order->id && $self->type eq sales_order_type()) {
2256
  if ($self->order->id && $self->type eq SALES_ORDER_TYPE()) {
2255 2257
    my $lr = $self->order->linked_records(direction => 'to', to => ['Invoice']);
2256 2258
    $has_final_invoice               = any {'SL::DB::Invoice' eq ref $_ && "final_invoice" eq $_->type} @$lr;
2257 2259
  }
2258 2260

  
2259 2261
  my $right_for         = { map { $_ => $_.'_edit' } @{$self->valid_types} };
2260
  $right_for->{ sales_order_intake_type() } = 'sales_order_edit';
2261
  $right_for->{ purchase_quotation_intake_type() } = 'request_quotation_edit';
2262
  $right_for->{ SALES_ORDER_INTAKE_TYPE() } = 'sales_order_edit';
2263
  $right_for->{ PURCHASE_QUOTATION_INTAKE_TYPE() } = 'request_quotation_edit';
2262 2264
  my $right             = $right_for->{ $self->type };
2263 2265
  $right              ||= 'DOES_NOT_EXIST';
2264 2266
  my $may_edit_create   = $::auth->assert($right, 'may fail');
......
2321 2323
        ],
2322 2324
        action => [
2323 2325
          t8('Save and Quotation'),
2324
          call     => [ 'kivi.submit_ajax_form', $self->url_for(action => "save_and_order_workflow", to_type => sales_quotation_type()), '#order_form' ],
2326
          call     => [ 'kivi.submit_ajax_form', $self->url_for(action => "save_and_order_workflow", to_type => SALES_QUOTATION_TYPE()), '#order_form' ],
2325 2327
          checks   => [ @req_trans_cost_art, @req_cusordnumber ],
2326
          only_if  => (any { $self->type eq $_ } (sales_order_intake_type(), sales_order_type(), request_quotation_type(), purchase_quotation_intake_type())),
2328
          only_if  => (any { $self->type eq $_ } (SALES_ORDER_INTAKE_TYPE(), SALES_ORDER_TYPE(), REQUEST_QUOTATION_TYPE(), PURCHASE_QUOTATION_INTAKE_TYPE())),
2327 2329
          disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
2328 2330
        ],
2329 2331
        action => [
2330 2332
          t8('Save and RFQ'),
2331
          call     => [ 'kivi.Order.purchase_check_for_direct_delivery', { to_type => request_quotation_type() } ],
2332
          only_if  => (any { $self->type eq $_ } (sales_order_intake_type(), sales_order_type(), sales_quotation_type(), purchase_order_type())),
2333
          call     => [ 'kivi.Order.purchase_check_for_direct_delivery', { to_type => REQUEST_QUOTATION_TYPE() } ],
2334
          only_if  => (any { $self->type eq $_ } (SALES_ORDER_INTAKE_TYPE(), SALES_ORDER_TYPE(), SALES_QUOTATION_TYPE(), PURCHASE_ORDER_TYPE())),
2333 2335
          disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
2334 2336
        ],
2335 2337
        action => [
2336 2338
          t8('Save and Purchase Quotation Intake'),
2337
          call     => [ 'kivi.submit_ajax_form', $self->url_for(action => "save_and_order_workflow", to_type => purchase_quotation_intake_type()), '#order_form' ],
2338
          only_if  => (any { $self->type eq $_ } (request_quotation_type())),
2339
          call     => [ 'kivi.submit_ajax_form', $self->url_for(action => "save_and_order_workflow", to_type => PURCHASE_QUOTATION_INTAKE_TYPE()), '#order_form' ],
2340
          only_if  => (any { $self->type eq $_ } (REQUEST_QUOTATION_TYPE())),
2339 2341
          disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
2340 2342
        ],
2341 2343
        action => [
2342 2344
          t8('Save and Sales Order Intake'),
2343
          call     => [ 'kivi.submit_ajax_form', $self->url_for(action => "save_and_order_workflow", to_type => sales_order_intake_type()), '#order_form' ],
2344
          only_if  => (any { $self->type eq $_ } (sales_quotation_type())),
2345
          call     => [ 'kivi.submit_ajax_form', $self->url_for(action => "save_and_order_workflow", to_type => SALES_ORDER_INTAKE_TYPE()), '#order_form' ],
2346
          only_if  => (any { $self->type eq $_ } (SALES_QUOTATION_TYPE())),
2345 2347
          disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
2346 2348
        ],
2347 2349
        action => [
2348 2350
          t8('Save and Sales Order Confirmation'),
2349
          call     => [ 'kivi.submit_ajax_form', $self->url_for(action => "save_and_order_workflow", to_type => sales_order_type()), '#order_form' ],
2351
          call     => [ 'kivi.submit_ajax_form', $self->url_for(action => "save_and_order_workflow", to_type => SALES_ORDER_TYPE()), '#order_form' ],
2350 2352
          checks   => [ @req_trans_cost_art ],
2351
          only_if  => (any { $self->type eq $_ } (sales_quotation_type(), sales_order_intake_type(), request_quotation_type(), purchase_order_type(), purchase_quotation_intake_type())),
2353
          only_if  => (any { $self->type eq $_ } (SALES_QUOTATION_TYPE(), SALES_ORDER_INTAKE_TYPE(), REQUEST_QUOTATION_TYPE(), PURCHASE_ORDER_TYPE(), PURCHASE_QUOTATION_INTAKE_TYPE())),
2352 2354
          disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
2353 2355
        ],
2354 2356
        action => [
2355 2357
          t8('Save and Purchase Order'),
2356
          call      => [ 'kivi.Order.purchase_check_for_direct_delivery', { to_type => purchase_order_type() } ],
2358
          call      => [ 'kivi.Order.purchase_check_for_direct_delivery', { to_type => PURCHASE_ORDER_TYPE() } ],
2357 2359
          checks    => [ @req_trans_cost_art, @req_cusordnumber ],
2358
          only_if   => (any { $self->type eq $_ } (sales_order_intake_type(), sales_order_type(), request_quotation_type(), purchase_quotation_intake_type())),
2360
          only_if   => (any { $self->type eq $_ } (SALES_ORDER_INTAKE_TYPE(), SALES_ORDER_TYPE(), REQUEST_QUOTATION_TYPE(), PURCHASE_QUOTATION_INTAKE_TYPE())),
2359 2361
          disabled  => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
2360 2362
        ],
2361 2363
        action => [
......
2367 2369
          checks    => [ 'kivi.Order.check_save_active_periodic_invoices',
2368 2370
                         @req_trans_cost_art, @req_cusordnumber,
2369 2371
          ],
2370
          only_if   => (any { $self->type eq $_ } (sales_order_type(), purchase_order_type())),
2372
          only_if   => (any { $self->type eq $_ } (SALES_ORDER_TYPE(), PURCHASE_ORDER_TYPE())),
2371 2373
          disabled  => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
2372 2374
        ],
2373 2375
        action => [
......
2390 2392
          checks    => [ 'kivi.Order.check_save_active_periodic_invoices',
2391 2393
                         @req_trans_cost_art, @req_cusordnumber,
2392 2394
          ],
2393
          only_if   => (any { $self->type eq $_ } (purchase_order_type())),
2395
          only_if   => (any { $self->type eq $_ } (PURCHASE_ORDER_TYPE())),
2394 2396
          disabled  => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
2395 2397
        ],
2396 2398
        action => [
......
2398 2400
          call      => [ 'kivi.Order.save', { action             => 'save_and_reclamation',
2399 2401
                                              warn_on_duplicates => $::instance_conf->get_order_warn_duplicate_parts },
2400 2402
          ],
2401
          only_if   => (any { $self->type eq $_ } (sales_order_type(), purchase_order_type()))
2403
          only_if   => (any { $self->type eq $_ } (SALES_ORDER_TYPE(), PURCHASE_ORDER_TYPE()))
2402 2404
        ],
2403 2405
        action => [
2404 2406
          t8('Save and Invoice'),
......
2409 2411
                         @req_trans_cost_art, @req_cusordnumber,
2410 2412
          ],
2411 2413
          disabled  => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
2412
          not_if    => (any { $self->type eq $_ } (sales_order_intake_type(), purchase_quotation_intake_type())),
2414
          not_if    => (any { $self->type eq $_ } (SALES_ORDER_INTAKE_TYPE(), PURCHASE_QUOTATION_INTAKE_TYPE())),
2413 2415
        ],
2414 2416
        action => [
2415 2417
          ($has_invoice_for_advance_payment ? t8('Save and Further Invoice for Advance Payment') : t8('Save and Invoice for Advance Payment')),
......
2422 2424
          disabled  => !$may_edit_create  ? t8('You do not have the permissions to access this function.')
2423 2425
                     : $has_final_invoice ? t8('This order has already a final invoice.')
2424 2426
                     :                      undef,
2425
          only_if   => (any { $self->type eq $_ } (sales_order_type())),
2427
          only_if   => (any { $self->type eq $_ } (SALES_ORDER_TYPE())),
2426 2428
        ],
2427 2429
        action => [
2428 2430
          t8('Save and Final Invoice'),
......
2435 2437
          disabled  => !$may_edit_create  ? t8('You do not have the permissions to access this function.')
2436 2438
                     : $has_final_invoice ? t8('This order has already a final invoice.')
2437 2439
                     :                      undef,
2438
          only_if   => (any { $self->type eq $_ } (sales_order_type())) && $has_invoice_for_advance_payment,
2440
          only_if   => (any { $self->type eq $_ } (SALES_ORDER_TYPE())) && $has_invoice_for_advance_payment,
2439 2441
        ],
2440 2442
        action => [
2441 2443
          t8('Save and AP Transaction'),
2442 2444
          call      => [ 'kivi.Order.save', { action             => 'save_and_ap_transaction',
2443 2445
                                              warn_on_duplicates => $::instance_conf->get_order_warn_duplicate_parts },
2444 2446
          ],
2445
          only_if   => (any { $self->type eq $_ } (purchase_order_type())),
2447
          only_if   => (any { $self->type eq $_ } (PURCHASE_ORDER_TYPE())),
2446 2448
          disabled  => !$may_edit_create  ? t8('You do not have the permissions to access this function.') : undef,
2447 2449
        ],
2448 2450

  
......
2632 2634
sub get_periodic_invoices_status {
2633 2635
  my ($self, $config) = @_;
2634 2636

  
2635
  return                      if $self->type ne sales_order_type();
2637
  return                      if $self->type ne SALES_ORDER_TYPE();
2636 2638
  return t8('not configured') if !$config;
2637 2639

  
2638 2640
  my $active = ('HASH' eq ref $config)                           ? $config->{active}
......
2662 2664
  # $::locale->text("Edit Purchase Quotation Intake");
2663 2665

  
2664 2666
  $action = ucfirst(lc($action));
2665
  return $self->type eq sales_order_intake_type()        ? $::locale->text("$action Sales Order Intake")
2666
       : $self->type eq sales_order_type()               ? $::locale->text("$action Sales Order")
2667
       : $self->type eq purchase_order_type()            ? $::locale->text("$action Purchase Order")
2668
       : $self->type eq sales_quotation_type()           ? $::locale->text("$action Quotation")
2669
       : $self->type eq request_quotation_type()         ? $::locale->text("$action Request for Quotation")
2670
       : $self->type eq purchase_quotation_intake_type() ? $::locale->text("$action Purchase Quotation Intake")
2667
  return $self->type eq SALES_ORDER_INTAKE_TYPE()        ? $::locale->text("$action Sales Order Intake")
2668
       : $self->type eq SALES_ORDER_TYPE()               ? $::locale->text("$action Sales Order")
2669
       : $self->type eq PURCHASE_ORDER_TYPE()            ? $::locale->text("$action Purchase Order")
2670
       : $self->type eq SALES_QUOTATION_TYPE()           ? $::locale->text("$action Quotation")
2671
       : $self->type eq REQUEST_QUOTATION_TYPE()         ? $::locale->text("$action Request for Quotation")
2672
       : $self->type eq PURCHASE_QUOTATION_INTAKE_TYPE() ? $::locale->text("$action Purchase Quotation Intake")
2671 2673
       : '';
2672 2674
}
2673 2675

  
......
2745 2747
  return ($price_src, $discount_src);
2746 2748
}
2747 2749

  
2748
sub sales_order_intake_type {
2749
  'sales_order_intake';
2750
}
2751

  
2752
sub sales_order_type {
2753
  'sales_order';
2754
}
2755

  
2756
sub purchase_order_type {
2757
  'purchase_order';
2758
}
2759

  
2760
sub sales_quotation_type {
2761
  'sales_quotation';
2762
}
2763

  
2764
sub request_quotation_type {
2765
  'request_quotation';
2766
}
2767

  
2768
sub purchase_quotation_intake_type {
2769
  'purchase_quotation_intake';
2770
}
2771

  
2772 2750
sub nr_key {
2773
  return $_[0]->type eq sales_order_intake_type()        ? 'ordnumber'
2774
       : $_[0]->type eq sales_order_type()               ? 'ordnumber'
2775
       : $_[0]->type eq purchase_order_type()            ? 'ordnumber'
2776
       : $_[0]->type eq sales_quotation_type()           ? 'quonumber'
2777
       : $_[0]->type eq request_quotation_type()         ? 'quonumber'
2778
       : $_[0]->type eq purchase_quotation_intake_type() ? 'quonumber'
2751
  return $_[0]->type eq SALES_ORDER_INTAKE_TYPE()        ? 'ordnumber'
2752
       : $_[0]->type eq SALES_ORDER_TYPE()               ? 'ordnumber'
2753
       : $_[0]->type eq PURCHASE_ORDER_TYPE()            ? 'ordnumber'
2754
       : $_[0]->type eq SALES_QUOTATION_TYPE()           ? 'quonumber'
2755
       : $_[0]->type eq REQUEST_QUOTATION_TYPE()         ? 'quonumber'
2756
       : $_[0]->type eq PURCHASE_QUOTATION_INTAKE_TYPE() ? 'quonumber'
2779 2757
       : '';
2780 2758
}
2781 2759

  
......
2784 2762

  
2785 2763
  $self->save();
2786 2764

  
2787
  my $text = $self->type eq sales_order_intake_type()        ? $::locale->text('The order intake has been saved')
2788
           : $self->type eq sales_order_type()               ? $::locale->text('The order confirmation has been saved')
2789
           : $self->type eq purchase_order_type()            ? $::locale->text('The order has been saved')
2790
           : $self->type eq sales_quotation_type()           ? $::locale->text('The quotation has been saved')
2791
           : $self->type eq request_quotation_type()         ? $::locale->text('The rfq has been saved')
2792
           : $self->type eq purchase_quotation_intake_type() ? $::locale->text('The quotation intake has been saved')
2765
  my $text = $self->type eq SALES_ORDER_INTAKE_TYPE()        ? $::locale->text('The order intake has been saved')
2766
           : $self->type eq SALES_ORDER_TYPE()               ? $::locale->text('The order confirmation has been saved')
2767
           : $self->type eq PURCHASE_ORDER_TYPE()            ? $::locale->text('The order has been saved')
2768
           : $self->type eq SALES_QUOTATION_TYPE()           ? $::locale->text('The quotation has been saved')
2769
           : $self->type eq REQUEST_QUOTATION_TYPE()         ? $::locale->text('The rfq has been saved')
2770
           : $self->type eq PURCHASE_QUOTATION_INTAKE_TYPE() ? $::locale->text('The quotation intake has been saved')
2793 2771
           : '';
2794 2772
  flash_later('info', $text);
2795 2773

  
SL/Controller/Reclamation.pm
39 39
use SL::DB::DeliveryOrder;
40 40
use SL::DB::Invoice;
41 41
use SL::Model::Record;
42
use SL::DB::Order::TypeData qw(:types);
43
use SL::DB::Reclamation::TypeData qw(:types);
42 44

  
43 45
use List::Util qw(first sum0);
44 46
use List::UtilsBy qw(sort_by uniq_by);
......
123 125
  }
124 126

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

  
130 132
  $self->reclamation($reclamation);
......
151 153
  }
152 154

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

  
158 160
  $self->reclamation($reclamation);
......
179 181
  }
180 182

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

  
185 187
  $self->reclamation($reclamation);
......
208 210
  require SL::DB::PurchaseInvoice;
209 211
  my $invoice = SL::DB::PurchaseInvoice->new(id => $::form->{from_id})->load;
210 212
  $invoice->{type} = $invoice->invoice_type; #can't add type → invoice_type in SL/DB/PurchaseInvoice
211
  my $target_type = 'purchase_reclamation';
213
  my $target_type = PURCHASE_RECLAMATION_TYPE();
212 214
  my $reclamation = SL::Model::Record->new_from_workflow($invoice, $target_type);
213 215

  
214 216
  $self->reclamation($reclamation);
......
583 585
sub action_save_and_order {
584 586
  my ($self) = @_;
585 587

  
586
  my $to_type = $self->reclamation->is_sales ? 'sales_order'
587
                                             : 'purchase_order';
588
  my $to_type = $self->reclamation->is_sales ? SALES_ORDER_TYPE()
589
                                             : PURCHASE_ORDER_TYPE();
588 590

  
589 591
  $self->save_with_render_error();
590 592
  flash_later('info', t8('The reclamation has been saved'));
......
606 608
    controller => 'Reclamation',
607 609
    action     => 'add_from_reclamation',
608 610
    from_id => $self->reclamation->id,
609
    type => sales_reclamation_type(),
611
    type => SALES_RECLAMATION_TYPE(),
610 612
  );
611 613
}
612 614

  
......
620 622
    controller => 'Reclamation',
621 623
    action     => 'add_from_reclamation',
622 624
    from_id => $self->reclamation->id,
623
    type => purchase_reclamation_type(),
625
    type => PURCHASE_RECLAMATION_TYPE(),
624 626
  );
625 627
}
626 628

  
......
1213 1215
#
1214 1216

  
1215 1217
sub init_valid_types {
1216
  [ sales_reclamation_type(), purchase_reclamation_type() ];
1218
  $_[0]->type_data->valid_types;
1217 1219
}
1218 1220

  
1219 1221
sub init_type {
......
1229 1231
sub init_cv {
1230 1232
  my ($self) = @_;
1231 1233

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

  
1236 1238
  return $cv;
......
1273 1275
      language                => t8('Language'),
1274 1276
      department              => t8('Department'),
1275 1277
      globalproject           => t8('Project Number'),
1276
      cv_record_number        => ($self->type eq 'sales_reclamation' ? t8('Customer Record Number') : t8('Vendor Record Number')),
1278
      cv_record_number        => ($self->type eq SALES_RECLAMATION_TYPE() ? t8('Customer Record Number') : t8('Vendor Record Number')),
1277 1279
      transaction_description => t8('Description'),
1278 1280
      notes                   => t8('Notes'),
1279 1281
      intnotes                => t8('Internal Notes'),
......
1325 1327

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

  
1330 1332
  return [ map { $_->id } @{ SL::DB::Manager::PartClassification->get_all(where => [ $attribute => 1 ]) } ];
1331 1333
}
......
1778 1780

  
1779 1781
  # check for direct delivery
1780 1782
  # copy shipto in custom shipto (custom shipto will be copied by new_from() in case)
1781
  if ($::form->{type} eq purchase_reclamation_type()) {
1783
  if ($::form->{type} eq PURCHASE_RECLAMATION_TYPE()) {
1782 1784
    if ($::form->{use_shipto}) {
1783 1785
      my $custom_shipto = $source_reclamation->shipto->clone('SL::DB::Reclamation');
1784 1786
      $self->reclamation->custom_shipto($custom_shipto) if $custom_shipto;
......
2074 2076
      sub      => sub { $_[0]->closed ? t8('Yes') : t8('No') },
2075 2077
    },
2076 2078
  );
2077
  if ($self->type eq sales_reclamation_type()) {
2079
  if ($self->type eq SALES_RECLAMATION_TYPE()) {
2078 2080
    $column_defs{customer} = ({
2079 2081
      raw_data => sub { $_[0]->customervendor->presenter->customer(display => 'table-cell', callback => $callback) },
2080 2082
      sub      => sub { $_[0]->customervendor->name },
......
2089 2091
      },
2090 2092
      sub      => sub { $_[0]->contact ? $_[0]->contact->cp_name : '' },
2091 2093
    });
2092
  } elsif ($self->type eq purchase_reclamation_type()) {
2094
  } elsif ($self->type eq PURCHASE_RECLAMATION_TYPE()) {
2093 2095
    $column_defs{vendor} = ({
2094 2096
      raw_data => sub { $_[0]->customervendor->presenter->vendor(display => 'table-cell', callback => $callback) },
2095 2097
      sub      => sub { $_[0]->customervendor->name },
......
2151 2153
     { output => 0 },
2152 2154
     models => $self->models
2153 2155
    ),
2154
    title                 => $self->type eq sales_reclamation_type() ? t8('Sales Reclamations') : t8('Purchase Reclamations'),
2156
    title                 => $self->type eq SALES_RECLAMATION_TYPE() ? t8('Sales Reclamations') : t8('Purchase Reclamations'),
2155 2157
    allow_pdf_export      => 1,
2156 2158
    allow_csv_export      => 1,
2157 2159
  );
......
2166 2168
sub _setup_edit_action_bar {
2167 2169
  my ($self, %params) = @_;
2168 2170

  
2169
  my $deletion_allowed = ($self->type eq sales_reclamation_type()
2171
  my $deletion_allowed = ($self->type eq SALES_RECLAMATION_TYPE()
2170 2172
                          && $::instance_conf->get_sales_reclamation_show_delete)
2171
                      || ($self->type eq purchase_reclamation_type()
2173
                      || ($self->type eq PURCHASE_RECLAMATION_TYPE()
2172 2174
                          && $::instance_conf->get_purchase_reclamation_show_delete);
2173 2175

  
2174 2176
  for my $bar ($::request->layout->get('actionbar')) {
......
2206 2208
            $::instance_conf->get_reclamation_warn_duplicate_parts,
2207 2209
            $::instance_conf->get_reclamation_warn_no_reqdate,
2208 2210
          ],
2209
          only_if  => (any { $self->type eq $_ } (purchase_reclamation_type())),
2211
          only_if  => (any { $self->type eq $_ } (PURCHASE_RECLAMATION_TYPE())),
2210 2212
        ],
2211 2213
        action => [
2212 2214
          t8('Save and Purchase Reclamation'),
2213 2215
          call      => [ 'kivi.Reclamation.purchase_reclamation_check_for_direct_delivery' ],
2214
          only_if   => (any { $self->type eq $_ } (sales_reclamation_type())),
2216
          only_if   => (any { $self->type eq $_ } (SALES_RECLAMATION_TYPE())),
2215 2217
        ],
2216 2218
        action => [
2217 2219
          t8('Save and Order'),
......
2228 2230
            $::instance_conf->get_reclamation_warn_duplicate_parts,
2229 2231
            $::instance_conf->get_reclamation_warn_no_reqdate,
2230 2232
          ],
2231
          only_if   => (any { $self->type eq $_ } (sales_reclamation_type())),
2233
          only_if   => (any { $self->type eq $_ } (SALES_RECLAMATION_TYPE())),
2232 2234
        ],
2233 2235
        action => [
2234 2236
          t8('Save and Supplier Delivery Order'),
......
2237 2239
            $::instance_conf->get_reclamation_warn_duplicate_parts,
2238 2240
            $::instance_conf->get_reclamation_warn_no_reqdate,
2239 2241
          ],
2240
          only_if   => (any { $self->type eq $_ } (purchase_reclamation_type())),
2242
          only_if   => (any { $self->type eq $_ } (PURCHASE_RECLAMATION_TYPE())),
2241 2243
        ],
2242 2244
        action => [
2243 2245
          t8('Save and Credit Note'),
......
2246 2248
            $::instance_conf->get_reclamation_warn_duplicate_parts,
2247 2249
            $::instance_conf->get_reclamation_warn_no_reqdate,
2248 2250
          ],
2249
          only_if   => (any { $self->type eq $_ } (sales_reclamation_type())),
2251
          only_if   => (any { $self->type eq $_ } (SALES_RECLAMATION_TYPE())),
2250 2252
        ],
2251 2253
      ], # end of combobox "Workflow"
2252 2254

  
......
2462 2464
  # t8("Edit Purchase Reclamation");
2463 2465

  
2464 2466
  $action = ucfirst(lc($action));
2465
  return $self->type eq sales_reclamation_type()    ? t8("$action Sales Reclamation")
2466
       : $self->type eq purchase_reclamation_type() ? t8("$action Purchase Reclamation")
2467
  return $self->type eq SALES_RECLAMATION_TYPE()    ? t8("$action Sales Reclamation")
2468
       : $self->type eq PURCHASE_RECLAMATION_TYPE() ? t8("$action Purchase Reclamation")
2467 2469
       : '';
2468 2470
}
2469 2471

  
......
2506 2508
  return $texts;
2507 2509
}
2508 2510

  
2509
sub sales_reclamation_type {
2510
  'sales_reclamation';
2511
}
2512

  
2513
sub purchase_reclamation_type {
2514
  'purchase_reclamation';
2515
}
2516

  
2517 2511
sub save_history {
2518 2512
  my ($self, $addition) = @_;
2519 2513

  
......
2567 2561
}
2568 2562

  
2569 2563
sub init_type_data {
2570
  SL::DB::Helper::TypeDataProxy->new('SL::DB::Reclamation', $_[0]->type);
2564
  SL::DB::Helper::TypeDataProxy->new('SL::DB::Reclamation', $::form->{type});
2571 2565
}
2572 2566

  
2573 2567
1;
SL/DB/DeliveryOrder.pm
20 20
use SL::DB::Unit;
21 21

  
22 22
use SL::DB::DeliveryOrder::TypeData qw(:types);
23
use SL::DB::Reclamation::TypeData qw(:types);
23 24

  
24 25
use SL::Helper::Number qw(_format_total _round_total);
25 26

  
......
93 94
    ],
94 95
  );
95 96

  
96
  return first { $_->is_type('sales_order') } @{ $orders };
97
  return first { $_->is_type(SALES_ORDER_TYPE()) } @{ $orders };
97 98
}
98 99

  
99 100
sub type {
......
107 108
sub displayable_type {
108 109
  my $type = shift->type;
109 110

  
110
  return $::locale->text('Sales Delivery Order')    if $type eq 'sales_delivery_order';
111
  return $::locale->text('Purchase Delivery Order') if $type eq 'purchase_delivery_order';
111
  return $::locale->text('Sales Delivery Order')    if $type eq SALES_DELIVERY_ORDER_TYPE();
112
  return $::locale->text('Purchase Delivery Order') if $type eq PURCHASE_DELIVERY_ORDER_TYPE();
112 113

  
113 114
  die 'invalid type';
114 115
}
......
145 146
sub convert_to_reclamation {
146 147
  my ($self, %params) = @_;
147 148

  
148
  $params{destination_type} = $self->is_sales ? 'sales_reclamation'
149
                                              : 'purchase_reclamation';
149
  $params{destination_type} = $self->is_sales ? SALES_RECLAMATION_TYPE()
150
                                              : PURCHASE_RECLAMATION_TYPE();
150 151

  
151 152
  my $reclamation = SL::DB::Reclamation->new_from($self, %params);
152 153

  
......
238 239
  }
239 240

  
240 241
  # infer type from legacy fields if not given
241
  $record_args{order_type} //= $source->customer_id ? 'sales_delivery_order'
242
                      : $source->vendor_id   ? 'purchase_delivery_order'
243
                      : $source->is_sales    ? 'sales_delivery_order'
242
  $record_args{order_type} //= $source->customer_id ? SALES_DELIVERY_ORDER_TYPE()
243
                      : $source->vendor_id   ? PURCHASE_DELIVERY_ORDER_TYPE()
244
                      : $source->is_sales    ? SALES_DELIVERY_ORDER_TYPE()
244 245
                      : croak "need some way to set delivery order type from source";
245 246

  
246 247
  my $delivery_order = $class->new(%record_args);
247 248
  $delivery_order->assign_attributes(%{ $params{attributes} }) if $params{attributes};
248 249

  
249 250
  my $items = delete($params{items}) || $source->items_sorted;
250
  my @items = ( $delivery_order->is_type(SUPPLIER_DELIVERY_ORDER_TYPE) && ref($source) ne 'SL::DB::Reclamation' ) ?
251
  my @items = ( $delivery_order->is_type(SUPPLIER_DELIVERY_ORDER_TYPE()) && ref($source) ne 'SL::DB::Reclamation' ) ?
251 252
                ()
252 253
              : map { SL::DB::DeliveryOrderItem->new_from($_, %params) } @{ $items };
253 254

  
SL/DB/Order.pm
26 26
use SL::RecordLinks;
27 27
use Rose::DB::Object::Helpers qw(as_tree strip);
28 28

  
29
use SL::DB::Order::TypeData qw(:types);
30
use SL::DB::Reclamation::TypeData qw(:types);
31

  
29 32
__PACKAGE__->meta->add_relationship(
30 33
  orderitems => {
31 34
    type         => 'one to many',
......
99 102
  my ($self) = @_;
100 103

  
101 104
  # force new project, if not set yet
102
  if ($::instance_conf->get_order_always_project && !$self->globalproject_id && ($self->type eq 'sales_order')) {
105
  if ($::instance_conf->get_order_always_project && !$self->globalproject_id && ($self->type eq SALES_ORDER_TYPE())) {
103 106

  
104 107
    die t8("Error while creating project with project number of new order number, project number #1 already exists!", $self->ordnumber)
105 108
      if SL::DB::Manager::Project->find_by(projectnumber => $self->ordnumber);
......
161 164
sub type {
162 165
  my $self = shift;
163 166

  
164
  return 'sales_order_intake'        if $self->customer_id &&   $self->intake;
165
  return 'sales_order'               if $self->customer_id && ! $self->quotation;
166
  return 'purchase_order'            if $self->vendor_id   && ! $self->quotation;
167
  return 'sales_quotation'           if $self->customer_id &&   $self->quotation;
168
  return 'request_quotation'         if $self->vendor_id   &&   $self->quotation  && ! $self->intake;
169
  return 'purchase_quotation_intake' if $self->vendor_id   &&   $self->quotation  &&   $self->intake;
167
  return SALES_ORDER_INTAKE_TYPE()        if $self->customer_id &&   $self->intake;
168
  return SALES_ORDER_TYPE()               if $self->customer_id && ! $self->quotation;
169
  return PURCHASE_ORDER_TYPE()            if $self->vendor_id   && ! $self->quotation;
170
  return SALES_QUOTATION_TYPE()           if $self->customer_id &&   $self->quotation;
171
  return REQUEST_QUOTATION_TYPE()         if $self->vendor_id   &&   $self->quotation  && ! $self->intake;
172
  return PURCHASE_QUOTATION_INTAKE_TYPE() if $self->vendor_id   &&   $self->quotation  &&   $self->intake;
170 173

  
171 174
  return;
172 175
}
......
180 183
  # But this has a different meaning for sales quotations.
181 184
  # deliverydate can be used to determine tax if tax_point isn't set.
182 185

  
183
  return $_[0]->reqdate if $_[0]->type ne 'sales_quotation';
186
  return $_[0]->reqdate if $_[0]->type ne SALES_QUOTATION_TYPE();
184 187
}
185 188

  
186 189
sub effective_tax_point {
......
192 195
sub displayable_type {
193 196
  my $type = shift->type;
194 197

  
195
  return $::locale->text('Sales quotation')   if $type eq 'sales_quotation';
196
  return $::locale->text('Request quotation') if $type eq 'request_quotation';
197
  return $::locale->text('Sales Order')       if $type eq 'sales_order';
198
  return $::locale->text('Purchase Order')    if $type eq 'purchase_order';
198
  return $::locale->text('Sales quotation')   if $type eq SALES_QUOTATION_TYPE();
199
  return $::locale->text('Request quotation') if $type eq REQUEST_QUOTATION_TYPE();
200
  return $::locale->text('Sales Order')       if $type eq SALES_ORDER_TYPE();
201
  return $::locale->text('Purchase Order')    if $type eq PURCHASE_ORDER_TYPE();
199 202

  
200 203
  die 'invalid type';
201 204
}
......
214 217

  
215 218
  return 1 if $self->currency_id == $::instance_conf->get_currency_id;
216 219

  
217
  my $rate = (any { $self->is_type($_) } qw(sales_quotation sales_order))      ? 'buy'
218
           : (any { $self->is_type($_) } qw(request_quotation purchase_order)) ? 'sell'
220
  my $rate = (any { $self->is_type($_) } (SALES_QUOTATION_TYPE(), SALES_ORDER_TYPE()))      ? 'buy'
221
           : (any { $self->is_type($_) } (REQUEST_QUOTATION_TYPE(), PURCHASE_ORDER_TYPE())) ? 'sell'
219 222
           : undef;
220 223
  return if !$rate;
221 224

  
......
305 308

  
306 309
sub convert_to_reclamation {
307 310
  my ($self, %params) = @_;
308
  $params{destination_type} = $self->is_sales ? 'sales_reclamation'
309
                                              : 'purchase_reclamation';
311
  $params{destination_type} = $self->is_sales ? SALES_RECLAMATION_TYPE()
312
                                              : PURCHASE_RECLAMATION_TYPE();
310 313

  
311 314
  require SL::DB::Reclamation;
312 315
  my $reclamation = SL::DB::Reclamation->new_from($self, %params);
......
337 340
  my $destination_type  = delete $params{destination_type};
338 341

  
339 342
  my @from_tos = (
340
    { from => 'sales_quotation',           to => 'sales_order',               abbr => 'sqso'   },
341
    { from => 'request_quotation',         to => 'purchase_order',            abbr => 'rqpo'   },
342
    { from => 'sales_quotation',           to => 'sales_quotation',           abbr => 'sqsq'   },
343
    { from => 'sales_order',               to => 'sales_order',               abbr => 'soso'   },
344
    { from => 'request_quotation',         to => 'request_quotation',         abbr => 'rqrq'   },
345
    { from => 'purchase_order',            to => 'purchase_order',            abbr => 'popo'   },
346
    { from => 'sales_order',               to => 'purchase_order',            abbr => 'sopo'   },
347
    { from => 'purchase_order',            to => 'sales_order',               abbr => 'poso'   },
348
    { from => 'sales_order',               to => 'sales_quotation',           abbr => 'sosq'   },
349
    { from => 'purchase_order',            to => 'request_quotation',         abbr => 'porq'   },
350
    { from => 'request_quotation',         to => 'sales_quotation',           abbr => 'rqsq'   },
351
    { from => 'request_quotation',         to => 'sales_order',               abbr => 'rqso'   },
352
    { from => 'sales_quotation',           to => 'request_quotation',         abbr => 'sqrq'   },
353
    { from => 'sales_order',               to => 'request_quotation',         abbr => 'sorq'   },
354
    { from => 'sales_reclamation',         to => 'sales_order',               abbr => 'srso'   },
355
    { from => 'purchase_reclamation',      to => 'purchase_order',            abbr => 'prpo'   },
356
    { from => 'sales_order_intake',        to => 'sales_order_intake',        abbr => 'soisoi' },
357
    { from => 'sales_order_intake',        to => 'sales_quotation',           abbr => 'soisq'  },
358
    { from => 'sales_order_intake',        to => 'request_quotation',         abbr => 'soirq'  },
359
    { from => 'sales_order_intake',        to => 'sales_order',               abbr => 'soiso'  },
360
    { from => 'sales_order_intake',        to => 'purchase_order',            abbr => 'soipo'  },
361
    { from => 'sales_quotation',           to => 'sales_order_intake',        abbr => 'sqsoi'  },
362
    { from => 'purchase_quotation_intake', to => 'purchase_quotation_intake', abbr => 'pqipqi' },
363
    { from => 'purchase_quotation_intake', to => 'sales_quotation',           abbr => 'pqisq'  },
364
    { from => 'purchase_quotation_intake', to => 'sales_order',               abbr => 'pqiso'  },
365
    { from => 'purchase_quotation_intake', to => 'purchase_order',            abbr => 'pqipo'  },
366
    { from => 'request_quotation',         to => 'purchase_quotation_intake', abbr => 'rqpqi'  },
343
    { from => SALES_QUOTATION_TYPE(),           to => SALES_ORDER_TYPE(),               abbr => 'sqso'   },
344
    { from => REQUEST_QUOTATION_TYPE(),         to => PURCHASE_ORDER_TYPE(),            abbr => 'rqpo'   },
345
    { from => SALES_QUOTATION_TYPE(),           to => SALES_QUOTATION_TYPE(),           abbr => 'sqsq'   },
346
    { from => SALES_ORDER_TYPE(),               to => SALES_ORDER_TYPE(),               abbr => 'soso'   },
347
    { from => REQUEST_QUOTATION_TYPE(),         to => REQUEST_QUOTATION_TYPE(),         abbr => 'rqrq'   },
348
    { from => PURCHASE_ORDER_TYPE(),            to => PURCHASE_ORDER_TYPE(),            abbr => 'popo'   },
349
    { from => SALES_ORDER_TYPE(),               to => PURCHASE_ORDER_TYPE(),            abbr => 'sopo'   },
350
    { from => PURCHASE_ORDER_TYPE(),            to => SALES_ORDER_TYPE(),               abbr => 'poso'   },
351
    { from => SALES_ORDER_TYPE(),               to => SALES_QUOTATION_TYPE(),           abbr => 'sosq'   },
352
    { from => PURCHASE_ORDER_TYPE(),            to => REQUEST_QUOTATION_TYPE(),         abbr => 'porq'   },
353
    { from => REQUEST_QUOTATION_TYPE(),         to => SALES_QUOTATION_TYPE(),           abbr => 'rqsq'   },
354
    { from => REQUEST_QUOTATION_TYPE(),         to => SALES_ORDER_TYPE(),               abbr => 'rqso'   },
355
    { from => SALES_QUOTATION_TYPE(),           to => REQUEST_QUOTATION_TYPE(),         abbr => 'sqrq'   },
356
    { from => SALES_ORDER_TYPE(),               to => REQUEST_QUOTATION_TYPE(),         abbr => 'sorq'   },
357
    { from => SALES_RECLAMATION_TYPE(),         to => SALES_ORDER_TYPE(),               abbr => 'srso'   },
358
    { from => PURCHASE_RECLAMATION_TYPE(),      to => PURCHASE_ORDER_TYPE(),            abbr => 'prpo'   },
359
    { from => SALES_ORDER_INTAKE_TYPE(),        to => SALES_ORDER_INTAKE_TYPE(),        abbr => 'soisoi' },
360
    { from => SALES_ORDER_INTAKE_TYPE(),        to => SALES_QUOTATION_TYPE(),           abbr => 'soisq'  },
361
    { from => SALES_ORDER_INTAKE_TYPE(),        to => REQUEST_QUOTATION_TYPE(),         abbr => 'soirq'  },
362
    { from => SALES_ORDER_INTAKE_TYPE(),        to => SALES_ORDER_TYPE(),               abbr => 'soiso'  },
363
    { from => SALES_ORDER_INTAKE_TYPE(),        to => PURCHASE_ORDER_TYPE(),            abbr => 'soipo'  },
364
    { from => SALES_QUOTATION_TYPE(),           to => SALES_ORDER_INTAKE_TYPE(),        abbr => 'sqsoi'  },
365
    { from => PURCHASE_QUOTATION_INTAKE_TYPE(), to => PURCHASE_QUOTATION_INTAKE_TYPE(), abbr => 'pqipqi' },
366
    { from => PURCHASE_QUOTATION_INTAKE_TYPE(), to => SALES_QUOTATION_TYPE(),           abbr => 'pqisq'  },
367
    { from => PURCHASE_QUOTATION_INTAKE_TYPE(), to => SALES_ORDER_TYPE(),               abbr => 'pqiso'  },
368
    { from => PURCHASE_QUOTATION_INTAKE_TYPE(), to => PURCHASE_ORDER_TYPE(),            abbr => 'pqipo'  },
369
    { from => REQUEST_QUOTATION_TYPE(),         to => PURCHASE_QUOTATION_INTAKE_TYPE(), abbr => 'rqpqi'  },
367 370
  );
368 371
  my $from_to = (grep { $_->{from} eq $source->type && $_->{to} eq $destination_type} @from_tos)[0];
369 372
  croak("Cannot convert from '" . $source->type . "' to '" . $destination_type . "'") if !$from_to;
......
596 599
  push @items, @{$_->items_sorted} for @$sources;
597 600
  # make order from first source and all items
598 601
  my $order = $class->new_from($sources->[0],
599
                               destination_type => 'sales_order',
602
                               destination_type => SALES_ORDER_TYPE(),
600 603
                               attributes       => \%attributes,
601 604
                               items            => \@items,
602 605
                               %params);
......
610 613
  return if !$self->type;
611 614

  
612 615
  my %number_method = (
613
    sales_order_intake        => 'ordnumber',
614
    sales_order               => 'ordnumber',
615
    sales_quotation           => 'quonumber',
616
    purchase_order            => 'ordnumber',
617
    request_quotation         => 'quonumber',
618
    purchase_quotation_intake => 'quonumber',
616
    SALES_ORDER_INTAKE_TYPE()        => 'ordnumber',
617
    SALES_ORDER_TYPE()               => 'ordnumber',
618
    SALES_QUOTATION_TYPE()           => 'quonumber',
619
    PURCHASE_ORDER_TYPE()            => 'ordnumber',
620
    REQUEST_QUOTATION_TYPE()         => 'quonumber',
621
    PURCHASE_QUOTATION_INTAKE_TYPE() => 'quonumber',
619 622
  );
620 623

  
621 624
  return $self->${ \ $number_method{$self->type} }(@_);
SL/DB/Reclamation.pm
8 8
use List::Util qw(max sum0);
9 9
use List::MoreUtils qw(any);
10 10

  
11
use SL::DB::DeliveryOrder::TypeData qw(:types);
12
use SL::DB::Reclamation::TypeData qw(:types);
11 13
use SL::DB::MetaSetup::Reclamation;
12 14
use SL::DB::Manager::Reclamation;
13 15
use SL::DB::Helper::Attr;
......
107 109
sub type {
108 110
  my ($self) = @_;
109 111

  
110
  return 'sales_reclamation'    if $self->customer_id;
111
  return 'purchase_reclamation' if $self->vendor_id;
112
  return SALES_RECLAMATION_TYPE()    if $self->customer_id;
113
  return PURCHASE_RECLAMATION_TYPE() if $self->vendor_id;
112 114

  
113 115
  return;
114 116
}
......
127 129
sub displayable_type {
128 130
  my $type = shift->type;
129 131

  
130
  return $::locale->text('Sales Reclamation')    if $type eq 'sales_reclamation';
131
  return $::locale->text('Purchase Reclamation') if $type eq 'purchase_reclamation';
132
  return $::locale->text('Sales Reclamation')    if $type eq SALES_RECLAMATION_TYPE();
133
  return $::locale->text('Purchase Reclamation') if $type eq PURCHASE_RECLAMATION_TYPE();
132 134

  
133 135
  die 'invalid type';
134 136
}
......
147 149

  
148 150
  return 1 if $self->currency_id == $::instance_conf->get_currency_id;
149 151

  
150
  my $rate = (any { $self->is_type($_) } qw(sales_reclamation))    ? 'buy'
151
           : (any { $self->is_type($_) } qw(purchase_reclamation)) ? 'sell'
152
  my $rate = (any { $self->is_type($_) } (SALES_RECLAMATION_TYPE()))    ? 'buy'
153
           : (any { $self->is_type($_) } (PURCHASE_RECLAMATION_TYPE())) ? 'sell'
152 154
           : undef;
153 155
  return if !$rate;
154 156

  
......
201 203
  my ($self, %params) = @_;
202 204

  
203 205
  my $order;
204
  $params{destination_type} = $self->is_sales ? 'sales_order'
205
                                              : 'purchase_order';
206
  $params{destination_type} = $self->is_sales ? SALES_ORDER_TYPE()
207
                                              : PURCHASE_ORDER_TYPE();
206 208
  if (!$self->db->with_transaction(sub {
207 209
    require SL::DB::Order;
208 210
    $order = SL::DB::Order->new_from($self, %params);
......
253 255

  
254 256
  my @from_tos = (
255 257
    #Reclamation
256
    { from => 'sales_reclamation',       to => 'sales_reclamation',    abbr => 'srsr', },
257
    { from => 'purchase_reclamation',    to => 'purchase_reclamation', abbr => 'prpr', },
258
    { from => 'sales_reclamation',       to => 'purchase_reclamation', abbr => 'srpr', },
259
    { from => 'purchase_reclamation',    to => 'sales_reclamation',    abbr => 'prsr', },
258
    { from => SALES_RECLAMATION_TYPE(),       to => SALES_RECLAMATION_TYPE(),    abbr => 'srsr', },
259
    { from => PURCHASE_RECLAMATION_TYPE(),    to => PURCHASE_RECLAMATION_TYPE(), abbr => 'prpr', },
260
    { from => SALES_RECLAMATION_TYPE(),       to => PURCHASE_RECLAMATION_TYPE(), abbr => 'srpr', },
261
    { from => PURCHASE_RECLAMATION_TYPE(),    to => SALES_RECLAMATION_TYPE(),    abbr => 'prsr', },
260 262
    #Order
261
    { from => 'sales_order',             to => 'sales_reclamation',    abbr => 'sosr', },
262
    { from => 'purchase_order',          to => 'purchase_reclamation', abbr => 'popr', },
263
    { from => SALES_ORDER_TYPE(),             to => SALES_RECLAMATION_TYPE(),    abbr => 'sosr', },
264
    { from => PURCHASE_ORDER_TYPE(),          to => PURCHASE_RECLAMATION_TYPE(), abbr => 'popr', },
263 265
    #Delivery Order
264
    { from => 'sales_delivery_order',    to => 'sales_reclamation',    abbr => 'sdsr', },
265
    { from => 'purchase_delivery_order', to => 'purchase_reclamation', abbr => 'pdpr', },
266
    { from => SALES_DELIVERY_ORDER_TYPE(),    to => SALES_RECLAMATION_TYPE(),    abbr => 'sdsr', },
267
    { from => PURCHASE_DELIVERY_ORDER_TYPE(), to => PURCHASE_RECLAMATION_TYPE(), abbr => 'pdpr', },
266 268
    #Invoice
267
    { from => 'invoice',                 to => 'sales_reclamation',    abbr => 'sisr', },
268
    { from => 'purchase_invoice',        to => 'purchase_reclamation', abbr => 'pipr', },
269
    { from => 'invoice',                 to => SALES_RECLAMATION_TYPE(),    abbr => 'sisr', },
270
    { from => 'purchase_invoice',        to => PURCHASE_RECLAMATION_TYPE(), abbr => 'pipr', },
269 271
  );
270 272
  my $from_to = (grep { $_->{from} eq $source->type && $_->{to} eq $destination_type} @from_tos)[0];
271 273
  if (!$from_to) {
SL/Model/Record.pm
14 14
use SL::DB::Status;
15 15
use SL::DB::ValidityToken;
16 16
use SL::DB::Helper::TypeDataProxy;
17
use SL::DB::Order::TypeData qw(:types);
18
use SL::DB::DeliveryOrder::TypeData qw(:types);
19
use SL::DB::Reclamation::TypeData qw(:types);
17 20

  
18 21
use SL::Util qw(trim);
19 22
use SL::Locale::String qw(t8);
......
63 66

  
64 67
  my %subtype_to_type = (
65 68
    # Order
66
    "request_quotation" => "SL::DB::Order",
67
    "purchase_order"    => "SL::DB::Order",
68
    "sales_quotation"   => "SL::DB::Order",
69
    "sales_order"       => "SL::DB::Order",
69
    REQUEST_QUOTATION_TYPE() => "SL::DB::Order",
70
    PURCHASE_ORDER_TYPE()    => "SL::DB::Order",
71
    SALES_QUOTATION_TYPE()   => "SL::DB::Order",
72
    SALES_ORDER_TYPE()       => "SL::DB::Order",
70 73
    # DeliveryOrder
71
    "sales_delivery_order"    => "SL::DB::DeliveryOrder",
72
    "purchase_delivery_order" => "SL::DB::DeliveryOrder",
73
    "rma_delivery_order"      => "SL::DB::DeliveryOrder",
74
    "supplier_delivery_order" => "SL::DB::DeliveryOrder",
74
    SALES_DELIVERY_ORDER_TYPE()    => "SL::DB::DeliveryOrder",
75
    PURCHASE_DELIVERY_ORDER_TYPE() => "SL::DB::DeliveryOrder",
76
    RMA_DELIVERY_ORDER_TYPE()      => "SL::DB::DeliveryOrder",
77
    SUPPLIER_DELIVERY_ORDER_TYPE() => "SL::DB::DeliveryOrder",
75 78
    # Reclamation
76
    "sales_reclamation"    => "SL::DB::Reclamation",
77
    "purchase_reclamation" => "SL::DB::Reclamation",
79
    SALES_RECLAMATION_TYPE()    => "SL::DB::Reclamation",
80
    PURCHASE_RECLAMATION_TYPE() => "SL::DB::Reclamation",
78 81
  );
79 82
  my $target_type = $subtype_to_type{$target_subtype};
80 83
  unless ($target_type) {
......
102 105

  
103 106
  my %subtype_to_type = (
104 107
    # Order
105
    "sales_order" => "SL::DB::Order",
108
    SALES_ORDER_TYPE() => "SL::DB::Order",
106 109
  );
107 110
  my $target_type = $subtype_to_type{$target_subtype};
108 111
  unless ($target_type) {

Auch abrufbar als: Unified diff