Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 95a9f8b9

Von Tamino Steinert vor mehr als 2 Jahren hinzugefügt

  • ID 95a9f8b99d7ef7c3150f1b7ebb3c66704ff3565e
  • Vorgänger bd92ddf5
  • Nachfolger 468eee22

Workflow: order ↔ reclamation

Unterschiede anzeigen:

SL/Controller/Order.pm
62 62
                        except => [ qw(edit show_customer_vendor_details_dialog price_popup load_second_rows) ]);
63 63

  
64 64
__PACKAGE__->run_before('recalc',
65
                        only => [ qw(save save_as_new save_and_delivery_order save_and_invoice save_and_invoice_for_advance_payment save_and_final_invoice save_and_ap_transaction
65
                        only => [ qw(save save_as_new
66
                                     save_and_delivery_order
67
                                     save_and_reclamation
68
                                     save_and_invoice save_and_invoice_for_advance_payment save_and_final_invoice save_and_ap_transaction
66 69
                                     print send_email) ]);
67 70

  
68 71
__PACKAGE__->run_before('get_unalterable_data',
69
                        only => [ qw(save save_as_new save_and_delivery_order save_and_invoice save_and_invoice_for_advance_payment save_and_final_invoice save_and_ap_transaction
72
                        only => [ qw(save save_as_new
73
                                     save_and_delivery_order
74
                                     save_and_reclamation
75
                                     save_and_invoice save_and_invoice_for_advance_payment save_and_final_invoice save_and_ap_transaction
70 76
                                     print send_email) ]);
71 77

  
72 78
#
......
96 102
  );
97 103
}
98 104

  
105
sub action_add_from_reclamation {
106
  my ($self) = @_;
107

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

  
112
  $self->order($order);
113

  
114
  $self->recalc();
115
  $self->pre_render();
116
  $self->render(
117
    'order/form',
118
    title => $self->get_title_for('edit'),
119
    %{$self->{template_args}}
120
  );
121
}
122

  
99 123
# edit an existing order
100 124
sub action_edit {
101 125
  my ($self) = @_;
......
740 764
  );
741 765
}
742 766

  
767
# save the order and redirect to the frontend subroutine for a new reclamation
768
sub action_save_and_reclamation {
769
  my ($self) = @_;
770

  
771
  # cann't use save_and_redirect_to, because id is set!
772
  my $errors = $self->save();
773
  if (scalar @{ $errors }) {
774
    $self->js->flash('error', $_) foreach @{ $errors };
775
    return $self->js->render();
776
  }
777

  
778
  my $to_type = $self->order->is_sales ? 'sales_reclamation'
779
                                       : 'purchase_reclamation';
780
  $self->redirect_to(
781
    controller => 'Reclamation',
782
    action     => 'add_from_order',
783
    type       => $to_type,
784
    from_id    => $self->order->id,
785
  );
786
}
787

  
743 788
# save the order and redirect to the frontend subroutine for a new
744 789
# invoice
745 790
sub action_save_and_invoice {
......
2247 2292
          only_if   => (any { $self->type eq $_ } (purchase_order_type())),
2248 2293
          disabled  => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
2249 2294
        ],
2295
        action => [
2296
          t8('Save and Reclamation'),
2297
          call      => [ 'kivi.Order.save', 'save_and_reclamation', $::instance_conf->get_order_warn_duplicate_parts ],
2298
          only_if   => (any { $self->type eq $_ } (sales_order_type(), purchase_order_type()))
2299
        ],
2250 2300
        action => [
2251 2301
          t8('Save and Invoice'),
2252 2302
          call      => [ 'kivi.Order.save', 'save_and_invoice', $::instance_conf->get_order_warn_duplicate_parts ],
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
309 309
  return $delivery_order;
310 310
}
311 311

  
312
sub convert_to_reclamation {
313
  my ($self, %params) = @_;
314
  $params{destination_type} = $self->is_sales ? 'sales_reclamation'
315
                                              : 'purchase_reclamation';
316

  
317
  require SL::DB::Reclamation;
318
  my $reclamation = SL::DB::Reclamation->new_from($self, %params);
319

  
320
  return $reclamation;
321
}
322

  
312 323
sub _clone_orderitem_cvar {
313 324
  my ($cvar) = @_;
314 325

  
......
321 332
sub new_from {
322 333
  my ($class, $source, %params) = @_;
323 334

  
324
  croak("Unsupported source object type '" . ref($source) . "'") unless ref($source) eq 'SL::DB::Order';
335
  unless (any {ref($source) eq $_} qw(
336
    SL::DB::Order
337
    SL::DB::Reclamation
338
  )) {
339
    croak("Unsupported source object type '" . ref($source) . "'");
340
  }
325 341
  croak("A destination type must be given as parameter")         unless $params{destination_type};
326 342

  
327 343
  my $destination_type  = delete $params{destination_type};
......
337 353
    { from => 'purchase_order',    to => 'sales_order',       abbr => 'poso' },
338 354
    { from => 'sales_order',       to => 'sales_quotation',   abbr => 'sosq' },
339 355
    { from => 'purchase_order',    to => 'request_quotation', abbr => 'porq' },
356
    { from => 'sales_reclamation', to => 'sales_order',       abbr => 'srso' },
357
    { from => 'purchase_reclamation', to => 'purchase_order', abbr => 'prpo' },
340 358
  );
341 359
  my $from_to = (grep { $_->{from} eq $source->type && $_->{to} eq $destination_type} @from_tos)[0];
342 360
  croak("Cannot convert from '" . $source->type . "' to '" . $destination_type . "'") if !$from_to;
......
350 368
  if (ref($source) eq 'SL::DB::Order') {
351 369
    $item_parent_id_column = 'trans_id';
352 370
    $item_parent_column    = 'order';
371
  } elsif ( ref($source) eq 'SL::DB::Reclamation') {
372
    $item_parent_id_column = 'reclamation_id';
373
    $item_parent_column    = 'reclamation';
353 374
  }
354 375

  
355
  my %args = ( map({ ( $_ => $source->$_ ) } qw(amount cp_id currency_id cusordnumber customer_id delivery_customer_id delivery_term_id delivery_vendor_id
356
                                                department_id exchangerate globalproject_id intnotes marge_percent marge_total language_id netamount notes
357
                                                ordnumber payment_id quonumber reqdate salesman_id shippingpoint shipvia taxincluded tax_point taxzone_id
358
                                                transaction_description vendor_id billing_address_id
359
                                             )),
360
               quotation => !!($destination_type =~ m{quotation$}),
361
               closed    => 0,
362
               delivered => 0,
363
               transdate => DateTime->today_local,
364
               employee  => SL::DB::Manager::Employee->current,
365
            );
376
  my %args;
377
  if (ref($source) eq 'SL::DB::Order') {
378
    %args = ( map({ ( $_ => $source->$_ ) } qw(amount cp_id currency_id cusordnumber customer_id delivery_customer_id delivery_term_id delivery_vendor_id
379
                                                  department_id exchangerate globalproject_id intnotes marge_percent marge_total language_id netamount notes
380
                                                  ordnumber payment_id quonumber reqdate salesman_id shippingpoint shipvia taxincluded tax_point taxzone_id
381
                                                  transaction_description vendor_id billing_address_id
382
                                               )),
383
                 quotation => !!($destination_type =~ m{quotation$}),
384
                 closed    => 0,
385
                 delivered => 0,
386
                 transdate => DateTime->today_local,
387
                 employee  => SL::DB::Manager::Employee->current,
388
              );
389
  } elsif ( ref($source) eq 'SL::DB::Reclamation') {
390
    #TODO(Tamino): add billing_address_id to reclamation
391
    %args = ( map({ ( $_ => $source->$_ ) } qw(
392
        amount currency_id customer_id delivery_term_id department_id
393
        exchangerate globalproject_id intnotes language_id netamount
394
        notes payment_id  reqdate salesman_id shippingpoint shipvia taxincluded
395
        tax_point taxzone_id transaction_description vendor_id
396
      )),
397
      cp_id     => $source->{contact_id},
398
      closed    => 0,
399
      delivered => 0,
400
      transdate => DateTime->today_local,
401
      employee  => SL::DB::Manager::Employee->current,
402
   );
403
  }
366 404

  
367 405
  if ( $is_abbr_any->(qw(sopo poso)) ) {
368 406
    $args{ordnumber} = undef;
......
412 450
    $item_parents{$source_item_id} ||= $source_item->$item_parent_column;
413 451
    my $item_parent                  = $item_parents{$source_item_id};
414 452

  
415
    my $current_oe_item = SL::DB::OrderItem->new(map({ ( $_ => $source_item->$_ ) }
416
                                                     qw(active_discount_source active_price_source base_qty cusordnumber
417
                                                        description discount lastcost longdescription
418
                                                        marge_percent marge_price_factor marge_total
419
                                                        ordnumber parts_id price_factor price_factor_id pricegroup_id
420
                                                        project_id qty reqdate sellprice serialnumber ship subtotal transdate unit
421
                                                        optional
422
                                                     )),
423
                                                 custom_variables => \@custom_variables,
424
    );
453
    my $current_oe_item;
454
    if (ref($source) eq 'SL::DB::Order') {
455
      $current_oe_item = SL::DB::OrderItem->new(map({ ( $_ => $source_item->$_ ) }
456
                                                       qw(active_discount_source active_price_source base_qty cusordnumber
457
                                                          description discount lastcost longdescription
458
                                                          marge_percent marge_price_factor marge_total
459
                                                          ordnumber parts_id price_factor price_factor_id pricegroup_id
460
                                                          project_id qty reqdate sellprice serialnumber ship subtotal transdate unit
461
                                                          optional
462
                                                       )),
463
                                                   custom_variables => \@custom_variables,
464
      );
465
    } elsif (ref($source) eq 'SL::DB::Reclamation') {
466
      $current_oe_item = SL::DB::OrderItem->new(
467
        map({ ( $_ => $source_item->$_ ) } qw(
468
          active_discount_source active_price_source base_qty description
469
          discount lastcost longdescription parts_id price_factor
470
          price_factor_id pricegroup_id project_id qty reqdate sellprice
471
          serialnumber unit
472
        )),
473
        custom_variables => \@custom_variables,
474
      );
475
    }
425 476
    if ( $is_abbr_any->(qw(sopo)) ) {
426 477
      $current_oe_item->sellprice($source_item->lastcost);
427 478
      $current_oe_item->discount(0);
......
430 481
      $current_oe_item->lastcost($source_item->sellprice);
431 482
    }
432 483
    $current_oe_item->{"converted_from_orderitems_id"} = $_->{id} if ref($item_parent) eq 'SL::DB::Order';
484
    $current_oe_item->{"converted_from_reclamation_item_id"} = $_->{id} if ref($item_parent) eq 'SL::DB::Reclamation';
433 485
    $current_oe_item;
434 486
  } @{ $items };
435 487

  
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