Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 4cff1777

Von Tamino Steinert vor etwa 1 Jahr hinzugefügt

  • ID 4cff1777d726529cc833c5b0cf579a86ed008847
  • Vorgänger 7da8047a
  • Nachfolger c8e91c4e

Records: Workflow-Methoden angepasst und vereinheitlicht

Unterschiede anzeigen:

SL/Controller/DeliveryOrder.pm
33 33
use SL::DB::Warehouse;
34 34
use SL::DB::Helper::RecordLink qw(set_record_link_conversions);
35 35
use SL::DB::Helper::TypeDataProxy;
36
use SL::DB::Helper::Record qw(get_object_name_from_type get_class_from_type);
36 37
use SL::DB::DeliveryOrder;
37 38
use SL::DB::DeliveryOrder::TypeData qw(:types);
38 39
use SL::DB::Order::TypeData qw(:types);
......
98 99
  );
99 100
}
100 101

  
101
sub action_add_from_order {
102
sub action_add_from_record {
102 103
  my ($self) = @_;
103
  # this interfers with init_order
104
  $self->{converted_from_oe_id} = delete $::form->{id};
105

  
106
  $self->type_data->validate;
107

  
108
  my $order = SL::DB::Order->new(id => $self->{converted_from_oe_id})->load;
109

  
110
  my $target_type = $::form->{type};
111
  my $delivery_order = SL::Model::Record->new_from_workflow($order, $target_type);
112
  $self->order($delivery_order);
104
  my $from_type = $::form->{from_type};
105
  my $from_id   = $::form->{from_id};
113 106

  
114
  $self->action_add;
115
}
116

  
117
sub action_add_from_reclamation {
118
  my ($self) = @_;
107
  unless ($from_type && $from_id) {
108
    $self->js->flash('error', t8("Can't create new record."));
109
    $self->js->flash('error', t8("No 'from_type' was given.")) unless ($from_type);
110
    $self->js->flash('error', t8("No 'from_id' was given."))   unless ($from_id);
111
    return $self->js->render();
112
  }
119 113

  
120
  my $reclamation = SL::DB::Reclamation->new(id => $::form->{from_id})->load;
121
  my $target_type = $reclamation->is_sales ? 'rma_delivery_order'
122
                                           : 'supplier_delivery_order';
123
  my $delivery_order = SL::Model::Record->new_from_workflow($reclamation, $target_type);
124
  $self->{converted_from_reclamation_id} = $::form->{from_id};
114
  my $record = SL::Model::Record->get_record($from_type, $from_id);
115
  my $delivery_order = SL::Model::Record->new_from_workflow($record, $self->type);
125 116
  $self->order($delivery_order);
126 117

  
127 118
  $self->action_add;
......
507 498
  $self->redirect_to(@redirect_params);
508 499
}
509 500

  
501
sub action_save_and_new_record {
502
  my ($self) = @_;
503
  my $to_type = $::form->{to_type};
504
  my $to_controller = get_object_name_from_type($to_type);
505

  
506
  $self->save();
507
  flash_later('info', $self->type_data->text('saved'));
508

  
509
  $self->redirect_to(
510
    controller => $to_controller,
511
    action     => 'add_from_record',
512
    type       => $to_type,
513
    from_id    => $self->order->id,
514
    from_type  => $self->order->type,
515
  );
516
}
517

  
510 518
# save the order and redirect to the frontend subroutine for a new
511 519
# delivery order
512 520
sub action_save_and_delivery_order {
SL/Controller/Order.pm
35 35
use SL::DB::ValidityToken;
36 36
use SL::DB::Helper::RecordLink qw(set_record_link_conversions RECORD_ID RECORD_ITEM_ID);
37 37
use SL::DB::Helper::TypeDataProxy;
38
use SL::DB::Helper::Record qw(get_object_name_from_type get_class_from_type);
38 39
use SL::Model::Record;
39 40
use SL::DB::Order::TypeData qw(:types);
40 41
use SL::DB::Reclamation::TypeData qw(:types);
......
96 97
  );
97 98
}
98 99

  
99
sub action_add_from_reclamation {
100
sub action_add_from_record {
100 101
  my ($self) = @_;
102
  my $from_type = $::form->{from_type};
103
  my $from_id   = $::form->{from_id};
101 104

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

  
108
  $self->{converted_from_reclamation_id}       = $order->{ RECORD_ID()      };
109
  $_   ->{converted_from_reclamation_items_id} = $_    ->{ RECORD_ITEM_ID() } for @{ $order->items_sorted };
105
  unless ($from_type && $from_id) {
106
    $self->js->flash('error', t8("Can't create new record."));
107
    $self->js->flash('error', t8("No 'from_type' was given.")) unless ($from_type);
108
    $self->js->flash('error', t8("No 'from_id' was given."))   unless ($from_id);
109
    return $self->js->render();
110
  }
110 111

  
112
  my $record = SL::Model::Record->get_record($from_type, $from_id);
113
  my $order = SL::Model::Record->new_from_workflow($record, $self->type);
111 114
  $self->order($order);
112 115

  
116
  if (ref($record) eq 'SL::DB::Reclamation') {
117
    $self->{converted_from_reclamation_id}       = $order->{ RECORD_ID()      };
118
    $_   ->{converted_from_reclamation_items_id} = $_    ->{ RECORD_ITEM_ID() } for @{ $order->items_sorted };
119
  }
120

  
121

  
113 122
  $self->recalc();
114 123
  $self->pre_render();
115 124

  
......
119 128

  
120 129
  $self->render(
121 130
    'order/form',
122
    title => $self->type_data->text('edit'),
131
    title => $self->type_data->text('add'),
123 132
    %{$self->{template_args}}
124 133
  );
125 134
}
......
765 774
  $_[0]->render(\ !!$has_active_periodic_invoices, { type => 'text' });
766 775
}
767 776

  
777
sub action_save_and_new_record {
778
  my ($self) = @_;
779
  my $to_type = $::form->{to_type};
780
  my $to_controller = get_object_name_from_type($to_type);
781

  
782
  $self->save();
783
  flash_later('info', $self->type_data->text('saved'));
784

  
785
  $self->redirect_to(
786
    controller => $to_controller,
787
    action     => 'add_from_record',
788
    type       => $to_type,
789
    from_id    => $self->order->id,
790
    from_type  => $self->order->type,
791
  );
792
}
793

  
768 794
# save the order and redirect to the frontend subroutine for a new
769 795
# delivery order
770 796
sub action_save_and_delivery_order {
......
783 809
  );
784 810
}
785 811

  
786
sub action_save_and_supplier_delivery_order {
787
  my ($self) = @_;
788

  
789
  $self->save_and_redirect_to(
790
    controller => 'controller.pl',
791
    action     => 'DeliveryOrder/add_from_order',
792
    type       => 'supplier_delivery_order',
793
  );
794
}
795

  
796
# save the order and redirect to the frontend subroutine for a new reclamation
797
sub action_save_and_reclamation {
798
  my ($self) = @_;
799

  
800
  # can't use save_and_redirect_to, because id is set!
801
  $self->save();
802

  
803
  my $to_type = $self->order->is_sales ? SALES_RECLAMATION_TYPE()
804
                                       : PURCHASE_RECLAMATION_TYPE();
805
  $self->redirect_to(
806
    controller => 'Reclamation',
807
    action     => 'add_from_order',
808
    type       => $to_type,
809
    from_id    => $self->order->id,
810
  );
811
}
812

  
813 812
# save the order and redirect to the frontend subroutine for a new
814 813
# invoice
815 814
sub action_save_and_invoice {
SL/Controller/Reclamation.pm
27 27
use SL::DB::ValidityToken;
28 28
use SL::DB::Helper::RecordLink qw(RECORD_ID RECORD_TYPE_REF RECORD_ITEM_ID RECORD_ITEM_TYPE_REF);
29 29
use SL::DB::Helper::TypeDataProxy;
30
use SL::DB::Helper::Record qw(get_object_name_from_type get_class_from_type);
30 31

  
31 32
use SL::Helper::CreatePDF qw(:all);
32 33
use SL::Helper::PrintOptions;
......
67 68
                        only => [qw(
68 69
                          save save_as_new print preview_pdf send_email
69 70
                          save_and_show_email_dialog
70
                          workflow_save_and_sales_or_purchase_reclamation
71
                          save_and_order
72
                          save_and_delivery_order
71
                          save_and_new_record
73 72
                          save_and_credit_note
74 73
                       )]);
75 74

  
......
77 76
                        only => [qw(
78 77
                          save save_as_new print preview_pdf send_email
79 78
                          save_and_show_email_dialog
80
                          workflow_save_and_sales_or_purchase_reclamation
81
                          save_and_order
82
                          save_and_delivery_order
79
                          save_and_new_record
83 80
                          save_and_credit_note
84 81
                        )]);
85 82

  
......
87 84
                        only => [qw(
88 85
                          save save_as_new print preview_pdf send_email
89 86
                          save_and_show_email_dialog
90
                          workflow_save_and_sales_or_purchase_reclamation
91
                          save_and_order
92
                          save_and_delivery_order
87
                          save_and_new_record
93 88
                          save_and_credit_note
94 89
                        )]);
95 90

  
......
116 111
  );
117 112
}
118 113

  
119
sub action_add_from_order {
114
sub action_add_from_record {
120 115
  my ($self) = @_;
116
  my $from_type = $::form->{from_type};
117
  my $from_id   = $::form->{from_id};
121 118

  
122
  unless ($::form->{from_id}) {
123
    $self->js->flash('error', t8("Can't create new reclamation. No 'from_id' was given."));
119
  unless ($from_type && $from_id) {
120
    $self->js->flash('error', t8("Can't create new record."));
121
    $self->js->flash('error', t8("No 'from_type' was given.")) unless ($from_type);
122
    $self->js->flash('error', t8("No 'from_id' was given."))   unless ($from_id);
124 123
    return $self->js->render();
125 124
  }
126 125

  
127
  my $order = SL::DB::Order->new(id => $::form->{from_id})->load;
128
  my $reclamation = SL::Model::Record->new_from_workflow($order, $self->type);
129

  
130
  $self->reclamation($reclamation);
131

  
132
  $self->reinit_after_new_reclamation();
133

  
134
  if (!$::form->{form_validity_token}) {
135
    $::form->{form_validity_token} = SL::DB::ValidityToken->create(scope => SL::DB::ValidityToken::SCOPE_RECLAMATION_SAVE())->token;
136
  }
137

  
138
  $self->render(
139
    'reclamation/form',
140
    title => $self->type_data->text('add'),
141
    %{$self->{template_args}},
142
  );
143
}
144

  
145
sub action_add_from_delivery_order {
146
  my ($self) = @_;
147

  
148
  unless ($::form->{from_id}) {
149
    $self->js->flash('error', t8("Can't create new reclamation. No 'from_id' was given."));
150
    return $self->js->render();
151
  }
152

  
153
  my $delivery_order = SL::DB::DeliveryOrder->new(id => $::form->{from_id})->load;
154
  my $reclamation = SL::Model::Record->new_from_workflow($delivery_order, $self->type);
155

  
126
  my $record = SL::Model::Record->get_record($from_type, $from_id);
127
  my $reclamation = SL::Model::Record->new_from_workflow($record, $self->type);
156 128
  $self->reclamation($reclamation);
157 129

  
158
  $self->reinit_after_new_reclamation();
159

  
160
  if (!$::form->{form_validity_token}) {
161
    $::form->{form_validity_token} = SL::DB::ValidityToken->create(scope => SL::DB::ValidityToken::SCOPE_RECLAMATION_SAVE())->token;
162
  }
163

  
164
  $self->render(
165
    'reclamation/form',
166
    title => $self->type_data->text('add'),
167
    %{$self->{template_args}},
168
  );
169
}
170

  
171
sub action_add_from_sales_invoice {
172
  my ($self) = @_;
173

  
174
  unless ($::form->{from_id}) {
175
    $self->js->flash('error', t8("Can't create new reclamation. No 'from_id' was given."));
176
    return $self->js->render();
177
  }
178

  
179
  my $invoice = SL::DB::Invoice->new(id => $::form->{from_id})->load;
180
  my $reclamation = SL::Model::Record->new_from_workflow($invoice, $self->type);
181

  
182
  $self->reclamation($reclamation);
183

  
184
  $self->reinit_after_new_reclamation();
185

  
186
  if (!$::form->{form_validity_token}) {
187
    $::form->{form_validity_token} = SL::DB::ValidityToken->create(scope => SL::DB::ValidityToken::SCOPE_RECLAMATION_SAVE())->token;
188
  }
189

  
190
  $self->render(
191
    'reclamation/form',
192
    title => $self->type_data->text('add'),
193
    %{$self->{template_args}},
194
  );
195
}
196

  
197
sub action_add_from_purchase_invoice {
198
  my ($self) = @_;
199

  
200
  unless ($::form->{from_id}) {
201
    $self->js->flash('error', t8("Can't create new reclamation. No 'from_id' was given."));
202
    return $self->js->render();
130
  if ($record->type eq SALES_RECLAMATION_TYPE()) { # check for direct delivery
131
    # copy shipto in custom shipto (custom shipto will be copied by new_from() in case)
132
    if ($::form->{use_shipto}) {
133
      my $custom_shipto = $record->shipto->clone('SL::DB::Reclamation');
134
      $self->reclamation->custom_shipto($custom_shipto) if $custom_shipto;
135
    } else {
136
      # remove any custom shipto if not wanted
137
      $self->reclamation->custom_shipto(SL::DB::Shipto->new(module => 'RC', custom_variables => []));
138
    }
203 139
  }
204 140

  
205
  require SL::DB::PurchaseInvoice;
206
  my $invoice = SL::DB::PurchaseInvoice->new(id => $::form->{from_id})->load;
207
  $invoice->{type} = $invoice->invoice_type; #can't add type → invoice_type in SL/DB/PurchaseInvoice
208
  my $reclamation = SL::Model::Record->new_from_workflow($invoice, ref($self->reclamaiton), $self->type);
209

  
210
  $self->reclamation($reclamation);
211

  
212 141
  $self->reinit_after_new_reclamation();
213 142

  
214 143
  if (!$::form->{form_validity_token}) {
......
573 502
  $self->redirect_to(@redirect_params);
574 503
}
575 504

  
576
sub action_save_and_order {
577
  my ($self) = @_;
578

  
579
  my $to_type = $self->reclamation->is_sales ? SALES_ORDER_TYPE()
580
                                             : PURCHASE_ORDER_TYPE();
581

  
582
  $self->save();
583

  
584
  flash_later('info', t8('The reclamation has been saved'));
585
  $self->redirect_to(
586
    controller => 'Order',
587
    action     => 'add_from_reclamation',
588
    type       => $to_type,
589
    from_id    => $self->reclamation->id,
590
  );
591
}
592

  
593
# workflow from purchase to sales reclamation
594
sub action_save_and_sales_reclamation {
505
sub action_save_and_new_record {
595 506
  my ($self) = @_;
507
  my $to_type = $::form->{to_type};
508
  my $to_controller = get_object_name_from_type($to_type);
596 509

  
597 510
  $self->save();
598

  
599 511
  flash_later('info', t8('The reclamation has been saved'));
600
  $self->redirect_to(
601
    controller => 'Reclamation',
602
    action     => 'add_from_reclamation',
603
    from_id => $self->reclamation->id,
604
    type => SALES_RECLAMATION_TYPE(),
605
  );
606
}
607

  
608
# workflow from sales to purchase reclamation
609
sub action_save_and_purchase_reclamation {
610
  my ($self) = @_;
611

  
612
  $self->save();
613 512

  
614
  flash_later('info', t8('The reclamation has been saved'));
615 513
  $self->redirect_to(
616
    controller => 'Reclamation',
617
    action     => 'add_from_reclamation',
618
    from_id => $self->reclamation->id,
619
    type => PURCHASE_RECLAMATION_TYPE(),
620
  );
621
}
622

  
623
# save the reclamation and redirect to the frontend subroutine for a new
624
# delivery order
625

  
626
sub action_save_and_delivery_order {
627
  my ($self) = @_;
628

  
629
  my $to_type = $self->reclamation->is_sales ? 'rma_delivery_order'
630
                                             : 'supplier_delivery_order';
631
  $self->save();
632

  
633
  flash_later('info', t8('The reclamation has been saved'));
634
  $self->redirect_to(
635
    controller => 'controller.pl',
636
    action     => 'DeliveryOrder/add_from_reclamation',
514
    controller => $to_controller,
515
    action     => 'add_from_record',
637 516
    type       => $to_type,
638 517
    from_id    => $self->reclamation->id,
518
    from_type  => $self->reclamation->type,
639 519
  );
640 520
}
641 521

  
......
1718 1598
  delete $::form->{form_validity_token};
1719 1599
}
1720 1600

  
1721
# sales → purchase or purchase → sales
1722
sub action_add_from_reclamation {
1723
  my ($self) = @_;
1724

  
1725
  my $destination_type = $::form->{destination_type};
1726

  
1727
  my $source_reclamation = SL::DB::Reclamation->new(id => $::form->{from_id})->load;
1728

  
1729
  $self->reclamation(
1730
    SL::DB::Reclamation->new_from(
1731
      $source_reclamation,
1732
      destination_type => $::form->{type},
1733
  ));
1734

  
1735
  # check for direct delivery
1736
  # copy shipto in custom shipto (custom shipto will be copied by new_from() in case)
1737
  if (!$self->type_data->properties('is_customer')) {
1738
    if ($::form->{use_shipto}) {
1739
      my $custom_shipto = $source_reclamation->shipto->clone('SL::DB::Reclamation');
1740
      $self->reclamation->custom_shipto($custom_shipto) if $custom_shipto;
1741
    } else {
1742
      # remove any custom shipto if not wanted
1743
      $self->reclamation->custom_shipto(SL::DB::Shipto->new(module => 'RC', custom_variables => []));
1744
    }
1745
  }
1746

  
1747
  $self->reinit_after_new_reclamation();
1748

  
1749
  if (!$::form->{form_validity_token}) {
1750
    $::form->{form_validity_token} = SL::DB::ValidityToken->create(scope => SL::DB::ValidityToken::SCOPE_RECLAMATION_SAVE())->token;
1751
  }
1752

  
1753
  $self->render(
1754
    'reclamation/form',
1755
    title => $self->type_data->text('add'),
1756
    %{$self->{template_args}}
1757
  );
1758
}
1759

  
1760 1601
sub reinit_after_new_reclamation {
1761 1602
  my ($self) = @_;
1762 1603

  
bin/mozilla/do.pl
1366 1366

  
1367 1367
sub save_and_reclamation {
1368 1368
  my $form     = $main::form;
1369
  my $id       = $form->{id};
1369 1370
  my $type     = $form->{type};
1370 1371

  
1371 1372
  # save the delivery order
......
1375 1376
    $type eq 'sales_delivery_order' ? 'sales_reclamation'
1376 1377
                                    : 'purchase_reclamation';
1377 1378
  $form->{callback} =
1378
    'controller.pl?action=Reclamation/add_from_delivery_order' .
1379
    '&type=' . $to_reclamation_type .
1380
    '&from_id=' . $form->escape($form->{id});
1379
    'controller.pl?action=Reclamation/add_from_record'
1380
    . '&type='      . $to_reclamation_type
1381
    . '&from_id='   . $form->escape($id)
1382
    . '&from_type=' . $form->escape($type)
1383
    ;
1381 1384
  $form->redirect;
1382 1385
}
1383 1386

  
bin/mozilla/io.pl
1206 1206

  
1207 1207
sub sales_reclamation {
1208 1208
  my $id = $::form->{id};
1209
  my $type = $::form->{type};
1209 1210

  
1210 1211
  require SL::Controller::Reclamation;
1211 1212
  my $c = SL::Controller::Reclamation->new();
1212 1213
  $c->redirect_to(
1213 1214
    controller => 'Reclamation',
1214
    action => 'add_from_sales_invoice',
1215
    from_id => $id,
1216
    type => 'sales_reclamation',
1215
    action     => 'add_from_record',
1216
    type       => 'sales_reclamation',
1217
    from_id    => $id,
1218
    from_type  => $type,
1217 1219
  );
1218 1220
}
1219 1221

  
1220 1222
sub purchase_reclamation {
1221 1223
  my $id = $::form->{id};
1224
  my $type = $::form->{type};
1222 1225

  
1223 1226
  require SL::Controller::Reclamation;
1224 1227
  my $c = SL::Controller::Reclamation->new();
1225 1228
  $c->redirect_to(
1226 1229
    controller => 'Reclamation',
1227
    action => 'add_from_purchase_invoice',
1228
    from_id => $id,
1229
    type => 'purchase_reclamation',
1230
    action     => 'add_from_record',
1231
    type       => 'purchase_reclamation',
1232
    from_id    => $id,
1233
    from_type  => $type,
1230 1234
  );
1231 1235
}
1232 1236

  

Auch abrufbar als: Unified diff