Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision e86dee01

Von Tamino Steinert vor mehr als 2 Jahren hinzugefügt

  • ID e86dee01b81d70ec4e958425d3db18a231633d72
  • Vorgänger 5bd0eb99
  • Nachfolger b5cf30e7

Workflow: order ↔ reclamation

Unterschiede anzeigen:

SL/Controller/Order.pm
92 92
  );
93 93
}
94 94

  
95
sub action_add_from_reclamation {
96
  my ($self) = @_;
97

  
98
  require SL::DB::Reclamation;
99
  my $reclamation = SL::DB::Reclamation->new(id => $::form->{from_id})->load;
100
  my $order = $reclamation->convert_to_order();
101

  
102
  $self->order($order);
103

  
104
  $self->recalc();
105
  $self->pre_render();
106
  $self->render(
107
    'order/form',
108
    title => $self->get_title_for('edit'),
109
    %{$self->{template_args}}
110
  );
111
}
112

  
95 113
# edit an existing order
96 114
sub action_edit {
97 115
  my ($self) = @_;
......
793 811
  );
794 812
}
795 813

  
814
# save the order and redirect to the frontend subroutine for a new reclamation
815
sub action_save_and_reclamation {
816
  my ($self) = @_;
817

  
818
  # cann't use save_and_redirect_to, because id is set!
819
  my $errors = $self->save();
820
  if (scalar @{ $errors }) {
821
    $self->js->flash('error', $_) foreach @{ $errors };
822
    return $self->js->render();
823
  }
824

  
825
  my $to_type = $self->order->is_sales ? 'sales_reclamation'
826
                                       : 'purchase_reclamation';
827
  $self->redirect_to(
828
    controller => 'Reclamation',
829
    action     => 'add_from_order',
830
    type       => $to_type,
831
    from_id    => $self->order->id,
832
  );
833
}
834

  
796 835
# save the order and redirect to the frontend subroutine for a new
797 836
# invoice
798 837
sub action_save_and_invoice {
......
2336 2375
          only_if   => (any { $self->type eq $_ } (purchase_order_type())),
2337 2376
          disabled  => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
2338 2377
        ],
2378
        action => [
2379
          t8('Save and Reclamation'),
2380
          call      => [ 'kivi.Order.save', 'save_and_reclamation', $::instance_conf->get_order_warn_duplicate_parts ],
2381
          only_if   => (any { $self->type eq $_ } (sales_order_type(), purchase_order_type()))
2382
        ],
2339 2383
        action => [
2340 2384
          t8('Save and Invoice'),
2341 2385
          call      => [ 'kivi.Order.save', { action             => 'save_and_invoice',
SL/Controller/Reclamation.pm
68 68
                          save save_as_new print preview_pdf send_email
69 69
                          save_and_show_email_dialog
70 70
                          workflow_save_and_sales_or_purchase_reclamation
71
                          save_and_order
71 72
                       )]);
72 73

  
73 74
__PACKAGE__->run_before('get_unalterable_data',
......
75 76
                          save save_as_new print preview_pdf send_email
76 77
                          save_and_show_email_dialog
77 78
                          workflow_save_and_sales_or_purchase_reclamation
79
                          save_and_order
78 80
                        )]);
79 81

  
80 82
#
......
96 98
  );
97 99
}
98 100

  
101
sub action_add_from_order {
102
  my ($self) = @_;
103

  
104
  unless ($::form->{from_id}) {
105
    $self->js->flash('error', t8("Can't create new reclamation. No 'from_id' was given."));
106
    return $self->js->render();
107
  }
108

  
109
  require SL::DB::Order;
110
  my $order = SL::DB::Order->new(id => $::form->{from_id})->load;
111
  my $reclamation = $order->convert_to_reclamation();
112

  
113
  $self->reclamation($reclamation);
114

  
115
  $self->reinit_after_new_reclamation();
116

  
117
  $self->render(
118
    'reclamation/form',
119
    title => $self->get_title_for('add'),
120
    %{$self->{template_args}},
121
  );
122
}
123

  
99 124
# edit an existing reclamation
100 125
sub action_edit {
101 126
  my ($self) = @_;
......
467 492
  $self->redirect_to(@redirect_params);
468 493
}
469 494

  
495
sub action_save_and_order {
496
  my ($self) = @_;
497

  
498
  my $to_type = $self->reclamation->is_sales ? 'sales_order'
499
                                             : 'purchase_order';
500
  $self->save_and_redirect_to(
501
    controller => 'Order',
502
    action     => 'add_from_reclamation',
503
    type       => $to_type,
504
    from_id    => $self->reclamation->id,
505
  );
506
}
507

  
470 508
# workflow from purchase to sales reclamation
471 509
sub action_save_and_sales_reclamation {
472 510
  $_[0]->workflow_save_and_sales_or_purchase_reclamation();
......
1578 1616
  my ($self) = @_;
1579 1617
  my %allowed_linked_records = map {$_ => 1} qw(
1580 1618
    SL::DB::Reclamation
1619
    SL::DB::Order
1581 1620
  );
1582 1621
  my %allowed_linked_record_items = map {$_ => 1} qw(
1583 1622
    SL::DB::ReclamationItem
1623
    SL::DB::OrderItem
1584 1624
  );
1585 1625

  
1586 1626
  my $from_record_id = delete $::form->{converted_from_record_id};
......
2085 2125
          call      => [ 'kivi.Reclamation.purchase_reclamation_check_for_direct_delivery' ],
2086 2126
          only_if   => (any { $self->type eq $_ } (sales_reclamation_type())),
2087 2127
        ],
2128
        action => [
2129
          t8('Save and Order'),
2130
          call      => [
2131
            'kivi.Reclamation.save', 'save_and_order',
2132
            $::instance_conf->get_reclamation_warn_duplicate_parts,
2133
            $::instance_conf->get_reclamation_warn_no_reqdate,
2134
          ],
2135
        ],
2088 2136
      ], # end of combobox "Workflow"
2089 2137

  
2090 2138
      combobox => [
SL/DB/Order.pm
315 315
  return $delivery_order;
316 316
}
317 317

  
318
sub convert_to_reclamation {
319
  my ($self, %params) = @_;
320
  $params{destination_type} = $self->is_sales ? 'sales_reclamation'
321
                                              : 'purchase_reclamation';
322

  
323
  require SL::DB::Reclamation;
324
  my $reclamation = SL::DB::Reclamation->new_from($self, %params);
325

  
326
  return $reclamation;
327
}
328

  
318 329
sub _clone_orderitem_cvar {
319 330
  my ($cvar) = @_;
320 331

  
......
327 338
sub new_from {
328 339
  my ($class, $source, %params) = @_;
329 340

  
330
  croak("Unsupported source object type '" . ref($source) . "'") unless ref($source) eq 'SL::DB::Order';
341
  unless (any {ref($source) eq $_} qw(
342
    SL::DB::Order
343
    SL::DB::Reclamation
344
  )) {
345
    croak("Unsupported source object type '" . ref($source) . "'");
346
  }
331 347
  croak("A destination type must be given as parameter")         unless $params{destination_type};
332 348

  
333 349
  my $destination_type  = delete $params{destination_type};
......
347 363
    { from => 'request_quotation', to => 'sales_order',       abbr => 'rqso' },
348 364
    { from => 'sales_quotation',   to => 'request_quotation', abbr => 'sqrq' },
349 365
    { from => 'sales_order',       to => 'request_quotation', abbr => 'sorq' },
366
    { from => 'sales_reclamation', to => 'sales_order',       abbr => 'srso' },
367
    { from => 'purchase_reclamation', to => 'purchase_order', abbr => 'prpo' },
350 368
  );
351 369
  my $from_to = (grep { $_->{from} eq $source->type && $_->{to} eq $destination_type} @from_tos)[0];
352 370
  croak("Cannot convert from '" . $source->type . "' to '" . $destination_type . "'") if !$from_to;
......
360 378
  if (ref($source) eq 'SL::DB::Order') {
361 379
    $item_parent_id_column = 'trans_id';
362 380
    $item_parent_column    = 'order';
381
  } elsif ( ref($source) eq 'SL::DB::Reclamation') {
382
    $item_parent_id_column = 'reclamation_id';
383
    $item_parent_column    = 'reclamation';
363 384
  }
364 385

  
365
  my %args = ( map({ ( $_ => $source->$_ ) } qw(amount cp_id currency_id cusordnumber customer_id delivery_customer_id delivery_term_id delivery_vendor_id
366
                                                department_id exchangerate globalproject_id intnotes marge_percent marge_total language_id netamount notes
367
                                                ordnumber payment_id quonumber reqdate salesman_id shippingpoint shipvia taxincluded tax_point taxzone_id
368
                                                transaction_description vendor_id billing_address_id
369
                                             )),
370
               quotation => !!($destination_type =~ m{quotation$}),
371
               closed    => 0,
372
               delivered => 0,
373
               transdate => DateTime->today_local,
374
               employee  => SL::DB::Manager::Employee->current,
375
            );
386
  my %args;
387
  if (ref($source) eq 'SL::DB::Order') {
388
    %args = ( map({ ( $_ => $source->$_ ) } qw(amount cp_id currency_id cusordnumber customer_id delivery_customer_id delivery_term_id delivery_vendor_id
389
                                                  department_id exchangerate globalproject_id intnotes marge_percent marge_total language_id netamount notes
390
                                                  ordnumber payment_id quonumber reqdate salesman_id shippingpoint shipvia taxincluded tax_point taxzone_id
391
                                                  transaction_description vendor_id billing_address_id
392
                                               )),
393
                 quotation => !!($destination_type =~ m{quotation$}),
394
                 closed    => 0,
395
                 delivered => 0,
396
                 transdate => DateTime->today_local,
397
                 employee  => SL::DB::Manager::Employee->current,
398
              );
399
  } elsif ( ref($source) eq 'SL::DB::Reclamation') {
400
    #TODO(Tamino): add billing_address_id to reclamation
401
    %args = ( map({ ( $_ => $source->$_ ) } qw(
402
        amount currency_id customer_id delivery_term_id department_id
403
        exchangerate globalproject_id intnotes language_id netamount
404
        notes payment_id  reqdate salesman_id shippingpoint shipvia taxincluded
405
        tax_point taxzone_id transaction_description vendor_id
406
      )),
407
      cp_id     => $source->{contact_id},
408
      closed    => 0,
409
      delivered => 0,
410
      transdate => DateTime->today_local,
411
      employee  => SL::DB::Manager::Employee->current,
412
   );
413
  }
376 414

  
377 415
  if ( $is_abbr_any->(qw(sopo poso rqso sosq porq rqsq sqrq sorq)) ) {
378 416
    $args{ordnumber} = undef;
......
420 458
    $item_parents{$source_item_id} ||= $source_item->$item_parent_column;
421 459
    my $item_parent                  = $item_parents{$source_item_id};
422 460

  
423
    my $current_oe_item = SL::DB::OrderItem->new(map({ ( $_ => $source_item->$_ ) }
424
                                                     qw(active_discount_source active_price_source base_qty cusordnumber
425
                                                        description discount lastcost longdescription
426
                                                        marge_percent marge_price_factor marge_total
427
                                                        ordnumber parts_id price_factor price_factor_id pricegroup_id
428
                                                        project_id qty reqdate sellprice serialnumber ship subtotal transdate unit
429
                                                        optional
430
                                                     )),
431
                                                 custom_variables => \@custom_variables,
432
    );
461
    my $current_oe_item;
462
    if (ref($source) eq 'SL::DB::Order') {
463
      $current_oe_item = SL::DB::OrderItem->new(map({ ( $_ => $source_item->$_ ) }
464
                                                       qw(active_discount_source active_price_source base_qty cusordnumber
465
                                                          description discount lastcost longdescription
466
                                                          marge_percent marge_price_factor marge_total
467
                                                          ordnumber parts_id price_factor price_factor_id pricegroup_id
468
                                                          project_id qty reqdate sellprice serialnumber ship subtotal transdate unit
469
                                                          optional
470
                                                       )),
471
                                                   custom_variables => \@custom_variables,
472
      );
473
    } elsif (ref($source) eq 'SL::DB::Reclamation') {
474
      $current_oe_item = SL::DB::OrderItem->new(
475
        map({ ( $_ => $source_item->$_ ) } qw(
476
          active_discount_source active_price_source base_qty description
477
          discount lastcost longdescription parts_id price_factor
478
          price_factor_id pricegroup_id project_id qty reqdate sellprice
479
          serialnumber unit
480
        )),
481
        custom_variables => \@custom_variables,
482
      );
483
    }
433 484
    if ( $is_abbr_any->(qw(sopo)) ) {
434 485
      $current_oe_item->sellprice($source_item->lastcost);
435 486
      $current_oe_item->discount(0);
......
438 489
      $current_oe_item->lastcost($source_item->sellprice);
439 490
    }
440 491
    $current_oe_item->{"converted_from_orderitems_id"} = $_->{id} if ref($item_parent) eq 'SL::DB::Order';
492
    $current_oe_item->{"converted_from_reclamation_item_id"} = $_->{id} if ref($item_parent) eq 'SL::DB::Reclamation';
441 493
    $current_oe_item;
442 494
  } @{ $items };
443 495

  
SL/DB/Reclamation.pm
181 181
      where => [  $valid_for_type => 1 ]);
182 182
}
183 183

  
184
sub convert_to_order {
185
  my ($self, %params) = @_;
186

  
187
  my $order;
188
  $params{destination_type} = $self->is_sales ? 'sales_order'
189
                                              : 'purchase_order';
190
  if (!$self->db->with_transaction(sub {
191
    require SL::DB::Order;
192
    $order = SL::DB::Order->new_from($self, %params);
193
    $order->save;
194
    $self->link_to_record($order);
195
    foreach my $item (@{ $order->items }) {
196
      foreach (qw(reclamation_item)) {
197
        if ($item->{"converted_from_${_}_id"}) {
198
          die unless $item->{id};
199
          RecordLinks->create_links('dbh'        => $self->db->dbh,
200
                                    'mode'       => 'ids',
201
                                    'from_table' => 'reclamation_items',
202
                                    'from_ids'   => $item->{"converted_from_${_}_id"},
203
                                    'to_table'   => 'orderitems',
204
                                    'to_id'      => $item->{id},
205
          ) || die;
206
          delete $item->{"converted_from_${_}_id"};
207
        }
208
      }
209
    }
210

  
211
    1;
212
  })) {
213
    return undef;
214
  }
215

  
216
  return $order;
217
}
218

  
184 219
#TODO(Werner): überprüfen ob alle Felder richtig gestetzt werden
185 220
sub new_from {
186 221
  my ($class, $source, %params) = @_;
187 222
  my %allowed_sources = map { $_ => 1 } qw(
188 223
    SL::DB::Reclamation
224
    SL::DB::Order
189 225
  );
190 226
  unless( $allowed_sources{ref $source} ) {
191 227
    croak("Unsupported source object type '" . ref($source) . "'");
......
200 236
    { from => 'purchase_reclamation',    to => 'purchase_reclamation', abbr => 'prpr', },
201 237
    { from => 'sales_reclamation',       to => 'purchase_reclamation', abbr => 'srpr', },
202 238
    { from => 'purchase_reclamation',    to => 'sales_reclamation',    abbr => 'prsr', },
239
    #Order
240
    { from => 'sales_order',             to => 'sales_reclamation',    abbr => 'sosr', },
241
    { from => 'purchase_order',          to => 'purchase_reclamation', abbr => 'popr', },
203 242
  );
204 243
  my $from_to = (grep { $_->{from} eq $source->type && $_->{to} eq $destination_type} @from_tos)[0];
205 244
  if (!$from_to) {
......
244 283
      transaction_description
245 284
      vendor_id
246 285
    ); # }}} for vim folds
286
  } elsif ( $is_abbr_any->(qw(sosr popr)) ) { #Order
287
    map { $record_args{$_} = $source->$_ } # {{{ for vim folds
288
    qw(
289
      amount
290
      currency_id
291
      customer_id
292
      delivery_term_id
293
      department_id
294
      exchangerate
295
      globalproject_id
296
      intnotes
297
      language_id
298
      netamount
299
      notes
300
      payment_id
301
      salesman_id
302
      shippingpoint
303
      shipvia
304
      tax_point
305
      taxincluded
306
      taxzone_id
307
      transaction_description
308
      vendor_id
309
    );
310
    $record_args{contact_id} = $source->cp_id;
311
    $record_args{cv_record_number} = $source->cusordnumber;
312
    # }}} for vim folds
247 313
  }
248 314

  
249 315
  if ( ($from_to->{from} =~ m{sales}) && ($from_to->{to} =~ m{purchase}) ) {
SL/DB/ReclamationItem.pm
53 53
  unless (any {ref($source) eq $_}
54 54
    qw(
55 55
      SL::DB::ReclamationItem
56
      SL::DB::OrderItem
56 57
    )
57 58
  ) {
58 59
    croak("Unsupported source object type '" . ref($source) . "'");
......
70 71
      unit
71 72
    );
72 73
    $item_args{custom_variables} = \@custom_variables;
74
  } elsif (ref($source) eq 'SL::DB::OrderItem') {
75
    map { $item_args{$_} = $source->$_ } qw(
76
      active_discount_source active_price_source base_qty description discount
77
      lastcost longdescription parts_id position price_factor price_factor_id
78
      pricegroup_id project_id qty reqdate sellprice serialnumber unit
79
    );
80
    $item_args{custom_variables} = \@custom_variables;
73 81
  }
74 82

  
75 83
  my $item = $class->new(%item_args);

Auch abrufbar als: Unified diff