Revision 14574a93
Von Werner Hahn vor mehr als 7 Jahren hinzugefügt
SL/BackgroundJob/ShopOrderMassTransfer.pm | ||
---|---|---|
17 | 17 |
use SL::DB::DeliveryOrder; |
18 | 18 |
use SL::DB::Inventory; |
19 | 19 |
use Sort::Naturally (); |
20 |
use SL::Locale::String qw(t8); |
|
20 | 21 |
|
21 | 22 |
use constant WAITING_FOR_EXECUTION => 0; |
22 |
#use constant CONVERTING_TO_ORDER => 1; |
|
23 |
use constant CONVERTING_TO_DELIVERY_ORDER => 1; |
|
23 |
use constant CONVERTING_TO_ORDER => 1; |
|
24 | 24 |
use constant DONE => 2; |
25 | 25 |
|
26 | 26 |
# Data format: |
... | ... | |
28 | 28 |
# shop_order_record_ids => [ 603, 604, 605], |
29 | 29 |
# num_order_created => 0, |
30 | 30 |
# orders_ids => [1,2,3] |
31 |
# conversation_errors => [ { id => 603 , item => 2, message => "Out of stock"}, ],
|
|
31 |
# conversion_errors => [ { id => 603 , item => 2, message => "Out of stock"}, ], |
|
32 | 32 |
# }; |
33 | 33 |
# |
34 | 34 |
|
... | ... | |
36 | 36 |
my ( $self ) = @_; |
37 | 37 |
my $job_obj = $self->{job_obj}; |
38 | 38 |
my $db = $job_obj->db; |
39 |
my %error_report; |
|
40 |
$job_obj->set_data(CONVERTING_TO_DELIVERY_ORDER())->save; |
|
39 |
$job_obj->set_data(CONVERTING_TO_ORDER())->save; |
|
41 | 40 |
|
42 |
foreach my $shop_order_id (@{ $job_obj->data_as_hash->{shop_order_record_ids} }) {
|
|
43 |
my $data = $job_obj->data_as_hash;
|
|
41 |
my $data = $job_obj->data_as_hash;
|
|
42 |
foreach my $shop_order_id (@{ $data->{shop_order_record_ids} }) {
|
|
44 | 43 |
my $shop_order = SL::DB::ShopOrder->new(id => $shop_order_id)->load; |
45 | 44 |
unless($shop_order){ |
46 |
push @{ $error_report{$shop_order_id} }, 'Shoporder not found'; |
|
45 |
push @{ $data->{conversion_errors} }, { id => $shop_order->id, number => $shop_order->shop_ordernumber, message => t8('Shoporder not found') }; |
|
46 |
$job_obj->update_attributes(data_as_hash => $data); |
|
47 | 47 |
} |
48 | 48 |
my $customer = SL::DB::Manager::Customer->find_by(id => $shop_order->{kivi_customer_id}); |
49 |
die "Can't find customer" unless $customer; |
|
49 |
unless($customer){ |
|
50 |
push @{ $data->{conversion_errors} }, { id => $shop_order->id, number => $shop_order->shop_ordernumber, message => t8('Customer not found') }; |
|
51 |
$job_obj->update_attributes(data_as_hash => $data); |
|
52 |
} |
|
50 | 53 |
my $employee = SL::DB::Manager::Employee->current; |
51 |
my $items = SL::DB::Manager::ShopOrderItem->get_all( where => [shop_order_id => $shop_order_id], |
|
52 |
sort_by => 'partnumber::int' ); |
|
54 |
my $items = SL::DB::Manager::ShopOrderItem->get_all( where => [shop_order_id => $shop_order_id], );
|
|
55 |
|
|
53 | 56 |
if ($customer->{order_lock} == 0) { |
54 | 57 |
$shop_order->{shop_order_items} = $items; |
55 | 58 |
|
56 |
my $order = $shop_order->convert_to_sales_order(customer => $customer, employee => $employee); |
|
57 |
$order->save; |
|
58 |
my $snumbers = "ordernumber_" . $order->ordnumber; |
|
59 |
SL::DB::History->new( |
|
60 |
trans_id => $order->id, |
|
61 |
snumbers => $snumbers, |
|
62 |
employee_id => SL::DB::Manager::Employee->current->id, |
|
63 |
addition => 'SAVED', |
|
64 |
what_done => 'Shopimport->Order(MassTransfer)', |
|
65 |
)->save(); |
|
66 |
$shop_order->transferred(1); |
|
67 |
$shop_order->transfer_date(DateTime->now_local); |
|
68 |
$shop_order->oe_transid($order->id); |
|
69 |
$shop_order->save; |
|
70 |
$shop_order->link_to_record($order); |
|
71 |
$data->{num_order_created} ++; |
|
72 |
push @{ $data->{orders_ids} }, $order->id; |
|
73 |
push @{ $data->{shop_orders_ids} }, $shop_order->id; |
|
59 |
$db->with_transaction( sub { |
|
60 |
my $order = $shop_order->convert_to_sales_order(customer => $customer, employee => $employee); |
|
61 |
|
|
62 |
if ($order->{error}){ |
|
63 |
push @{ $data->{conversion_errors} }, { id => $shop_order->id, number => $shop_order->shop_ordernumber, message => \@{$order->{errors}} }; |
|
64 |
$job_obj->update_attributes(data_as_hash => $data); |
|
65 |
}else{ |
|
66 |
$order->save; |
|
67 |
my $snumbers = "ordernumber_" . $order->ordnumber; |
|
68 |
SL::DB::History->new( |
|
69 |
trans_id => $order->id, |
|
70 |
snumbers => $snumbers, |
|
71 |
employee_id => SL::DB::Manager::Employee->current->id, |
|
72 |
addition => 'SAVED', |
|
73 |
what_done => 'Shopimport->Order(MassTransfer)', |
|
74 |
)->save(); |
|
75 |
$shop_order->transferred(1); |
|
76 |
$shop_order->transfer_date(DateTime->now_local); |
|
77 |
$shop_order->oe_transid($order->id); |
|
78 |
$shop_order->save; |
|
79 |
$shop_order->link_to_record($order); |
|
80 |
$data->{num_order_created} ++; |
|
81 |
push @{ $data->{orders_ids} }, $order->id; |
|
82 |
push @{ $data->{shop_orders_ids} }, $shop_order->id; |
|
74 | 83 |
|
84 |
$job_obj->update_attributes(data_as_hash => $data); |
|
85 |
} |
|
86 |
1; |
|
87 |
})or do { |
|
88 |
push @{ $data->{conversion_errors} }, { id => $shop_order->id, number => $shop_order->shop_ordernumber, message => $@ }; |
|
89 |
$job_obj->update_attributes(data_as_hash => $data); |
|
90 |
} |
|
91 |
}else{ |
|
92 |
push @{ $data->{conversion_errors} }, { id => $shop_order->id, number => $shop_order->shop_ordernumber, message => t8('Customerorderlock') }; |
|
75 | 93 |
$job_obj->update_attributes(data_as_hash => $data); |
76 | 94 |
} |
77 | 95 |
} |
SL/Controller/ShopOrder.pm | ||
---|---|---|
153 | 153 |
die "Can't load shop_order form form->import_id" unless $self->shop_order; |
154 | 154 |
|
155 | 155 |
my $order = $self->shop_order->convert_to_sales_order(customer => $customer, employee => $employee); |
156 |
$order->save;
|
|
156 |
$main::lxdebug->dump(0, 'WH:OOO ',$order);
|
|
157 | 157 |
|
158 |
my $snumbers = "ordernumber_" . $order->ordnumber; |
|
159 |
SL::DB::History->new( |
|
160 |
trans_id => $order->id, |
|
161 |
snumbers => $snumbers, |
|
162 |
employee_id => SL::DB::Manager::Employee->current->id, |
|
163 |
addition => 'SAVED', |
|
164 |
what_done => 'Shopimport -> Order', |
|
165 |
)->save(); |
|
166 |
foreach my $item(@{ $order->orderitems }){ |
|
167 |
$item->parse_custom_variable_values->save; |
|
168 |
$item->{custom_variables} = \@{ $item->cvars_by_config }; |
|
169 |
$item->save; |
|
158 |
if ($order->{error}){ |
|
159 |
flash_later('error',@{$order->{errors}}); |
|
160 |
$self->redirect_to(controller => "ShopOrder", action => 'show', id => $self->shop_order->id); |
|
161 |
}else{ |
|
162 |
$order->save; |
|
163 |
|
|
164 |
my $snumbers = "ordernumber_" . $order->ordnumber; |
|
165 |
SL::DB::History->new( |
|
166 |
trans_id => $order->id, |
|
167 |
snumbers => $snumbers, |
|
168 |
employee_id => SL::DB::Manager::Employee->current->id, |
|
169 |
addition => 'SAVED', |
|
170 |
what_done => 'Shopimport -> Order', |
|
171 |
)->save(); |
|
172 |
foreach my $item(@{ $order->orderitems }){ |
|
173 |
$item->parse_custom_variable_values->save; |
|
174 |
$item->{custom_variables} = \@{ $item->cvars_by_config }; |
|
175 |
$item->save; |
|
176 |
} |
|
177 |
|
|
178 |
$self->shop_order->transferred(1); |
|
179 |
$self->shop_order->transfer_date(DateTime->now_local); |
|
180 |
$self->shop_order->oe_transid($order->id); |
|
181 |
$self->shop_order->save; |
|
182 |
$self->shop_order->link_to_record($order); |
|
183 |
$self->redirect_to(controller => "oe.pl", action => 'edit', type => 'sales_order', vc => 'customer', id => $order->id); |
|
170 | 184 |
} |
171 |
|
|
172 |
$self->shop_order->transferred(1); |
|
173 |
$self->shop_order->transfer_date(DateTime->now_local); |
|
174 |
$self->shop_order->oe_transid($order->id); |
|
175 |
$self->shop_order->save; |
|
176 |
$self->shop_order->link_to_record($order); |
|
177 |
$self->redirect_to(controller => "oe.pl", action => 'edit', type => 'sales_order', vc => 'customer', id => $order->id); |
|
178 | 185 |
} |
179 | 186 |
|
180 | 187 |
sub action_mass_transfer { |
... | ... | |
190 | 197 |
num_order_created => 0, |
191 | 198 |
num_delivery_order_created => 0, |
192 | 199 |
status => SL::BackgroundJob::ShopOrderMassTransfer->WAITING_FOR_EXECUTION(), |
193 |
conversation_errors => [ ],
|
|
200 |
conversion_errors => [ ], |
|
194 | 201 |
)->update_next_run_at; |
195 | 202 |
|
196 | 203 |
SL::System::TaskServer->new->wake_up; |
SL/DB/ShopOrder.pm | ||
---|---|---|
8 | 8 |
use SL::DB::MetaSetup::ShopOrder; |
9 | 9 |
use SL::DB::Manager::ShopOrder; |
10 | 10 |
use SL::DB::Helper::LinkedRecords; |
11 |
use SL::Locale::String qw(t8); |
|
11 | 12 |
|
12 | 13 |
__PACKAGE__->meta->add_relationships( |
13 | 14 |
shop_order_items => { |
... | ... | |
41 | 42 |
require SL::DB::OrderItem; |
42 | 43 |
require SL::DB::Part; |
43 | 44 |
require SL::DB::Shipto; |
45 |
my @error_report; |
|
44 | 46 |
|
45 | 47 |
my @items = map{ |
48 |
|
|
46 | 49 |
# TODO Flash and exit if part not found |
47 |
my $part = SL::DB::Part->new( partnumber => $_->partnumber )->load; |
|
48 |
my $shop_part = SL::DB::Manager::ShopPart->get_all( where => [ shop_id => $self->shop_id, part_id => $part->id] )->[0]; |
|
49 |
|
|
50 |
my @cvars = map { ($_->config->name => { value => $_->value_as_text, is_valid => $_->is_valid }) } @{ $part->cvars_by_config } ; |
|
51 |
my $current_order_item = |
|
52 |
SL::DB::OrderItem->new(parts_id => $part->id, |
|
53 |
description => $part->description, |
|
54 |
qty => $_->quantity, |
|
55 |
sellprice => $_->price, |
|
56 |
unit => $part->unit, |
|
57 |
position => $_->position, |
|
58 |
active_price_source => $shop_part->active_price_source, |
|
59 |
); |
|
50 |
my $part = SL::DB::Manager::Part->get_first( query => [ partnumber => $_->partnumber, ], ); |
|
51 |
|
|
52 |
unless($part){ |
|
53 |
push @error_report, t8('Part with Partnumber: ') . $_->partnumber . t8(' not found'); |
|
54 |
}else{ |
|
55 |
my $shop_part = SL::DB::Manager::ShopPart->get_all( where => [ shop_id => $self->shop_id, part_id => $part->id] )->[0]; |
|
56 |
|
|
57 |
my @cvars = map { ($_->config->name => { value => $_->value_as_text, is_valid => $_->is_valid }) } @{ $part->cvars_by_config } ; |
|
58 |
my $current_order_item = |
|
59 |
SL::DB::OrderItem->new(parts_id => $part->id, |
|
60 |
description => $part->description, |
|
61 |
qty => $_->quantity, |
|
62 |
sellprice => $_->price, |
|
63 |
unit => $part->unit, |
|
64 |
position => $_->position, |
|
65 |
active_price_source => $shop_part->active_price_source, |
|
66 |
); |
|
67 |
} |
|
60 | 68 |
}@{ $self->shop_order_items }; |
61 | 69 |
|
62 |
my $shipto_id; |
|
63 |
if ($self->{billing_firstname} ne $self->{delivery_firstname} || $self->{billing_lastname} ne $self->{delivery_lastname} || $self->{billing_city} ne $self->{delivery_city} || $self->{billing_street} ne $self->{delivery_street}) { |
|
64 |
if(my $address = SL::DB::Manager::Shipto->find_by( shiptoname => $self->{delivery_firstname} . " " . $self->{delivery_lastname}, |
|
65 |
shiptostreet => $self->{delivery_street}, |
|
66 |
shiptocity => $self->{delivery_city}, |
|
67 |
)) { |
|
68 |
$shipto_id = $address->{shipto_id}; |
|
69 |
} else { |
|
70 |
my $gender = $self->{delivery_greeting} eq "Frau" ? 'f' : 'm'; |
|
71 |
my $deliveryaddress = SL::DB::Shipto->new; |
|
72 |
$deliveryaddress->assign_attributes( |
|
73 |
shiptoname => $self->{delivery_firstname} . " " . $self->{delivery_lastname}, |
|
74 |
shiptodepartment_1 => $self->{delivery_company}, |
|
75 |
shiptodepartment_2 => $self->{delivery_department}, |
|
76 |
shiptocp_gender => $gender, |
|
77 |
shiptostreet => $self->{delivery_street}, |
|
78 |
shiptozipcode => $self->{delivery_zipcode}, |
|
79 |
shiptocity => $self->{delivery_city}, |
|
80 |
shiptocountry => $self->{delivery_country}, |
|
81 |
trans_id => $customer->id, |
|
82 |
module => "CT", |
|
83 |
); |
|
84 |
$deliveryaddress->save; |
|
85 |
$shipto_id = $deliveryaddress->{shipto_id}; |
|
70 |
if(!scalar(@error_report)){ |
|
71 |
|
|
72 |
my $shipto_id; |
|
73 |
if ($self->{billing_firstname} ne $self->{delivery_firstname} || $self->{billing_lastname} ne $self->{delivery_lastname} || $self->{billing_city} ne $self->{delivery_city} || $self->{billing_street} ne $self->{delivery_street}) { |
|
74 |
if(my $address = SL::DB::Manager::Shipto->find_by( shiptoname => $self->{delivery_firstname} . " " . $self->{delivery_lastname}, |
|
75 |
shiptostreet => $self->{delivery_street}, |
|
76 |
shiptocity => $self->{delivery_city}, |
|
77 |
)) { |
|
78 |
$shipto_id = $address->{shipto_id}; |
|
79 |
} else { |
|
80 |
my $gender = $self->{delivery_greeting} eq "Frau" ? 'f' : 'm'; |
|
81 |
my $deliveryaddress = SL::DB::Shipto->new; |
|
82 |
$deliveryaddress->assign_attributes( |
|
83 |
shiptoname => $self->{delivery_firstname} . " " . $self->{delivery_lastname}, |
|
84 |
shiptodepartment_1 => $self->{delivery_company}, |
|
85 |
shiptodepartment_2 => $self->{delivery_department}, |
|
86 |
shiptocp_gender => $gender, |
|
87 |
shiptostreet => $self->{delivery_street}, |
|
88 |
shiptozipcode => $self->{delivery_zipcode}, |
|
89 |
shiptocity => $self->{delivery_city}, |
|
90 |
shiptocountry => $self->{delivery_country}, |
|
91 |
trans_id => $customer->id, |
|
92 |
module => "CT", |
|
93 |
); |
|
94 |
$deliveryaddress->save; |
|
95 |
$shipto_id = $deliveryaddress->{shipto_id}; |
|
96 |
} |
|
86 | 97 |
} |
87 |
} |
|
88 |
|
|
89 |
my $order = SL::DB::Order->new( |
|
90 |
amount => $self->amount, |
|
91 |
cusordnumber => $self->shop_ordernumber, |
|
92 |
customer_id => $customer->id, |
|
93 |
shipto_id => $shipto_id, |
|
94 |
orderitems => [ @items ], |
|
95 |
employee_id => $employee->id, |
|
96 |
intnotes => ($customer->notes ne "" ? "\n[Kundestammdaten]\n" . $customer->notes : ""), |
|
97 |
salesman_id => $employee->id, |
|
98 |
taxincluded => $self->tax_included, |
|
99 |
payment_id => $customer->payment_id, |
|
100 |
taxzone_id => $customer->taxzone_id, |
|
101 |
currency_id => $customer->currency_id, |
|
102 |
transaction_description => 'Shop Import', |
|
103 |
transdate => DateTime->today_local |
|
98 |
|
|
99 |
my $order = SL::DB::Order->new( |
|
100 |
amount => $self->amount, |
|
101 |
cusordnumber => $self->shop_ordernumber, |
|
102 |
customer_id => $customer->id, |
|
103 |
shipto_id => $shipto_id, |
|
104 |
orderitems => [ @items ], |
|
105 |
employee_id => $employee->id, |
|
106 |
intnotes => ($customer->notes ne "" ? "\n[Kundestammdaten]\n" . $customer->notes : ""), |
|
107 |
salesman_id => $employee->id, |
|
108 |
taxincluded => $self->tax_included, |
|
109 |
payment_id => $customer->payment_id, |
|
110 |
taxzone_id => $customer->taxzone_id, |
|
111 |
currency_id => $customer->currency_id, |
|
112 |
transaction_description => 'Shop Import', |
|
113 |
transdate => DateTime->today_local |
|
114 |
); |
|
115 |
return $order; |
|
116 |
}else{ |
|
117 |
my %error_order = (error => 1, |
|
118 |
errors => [ @error_report ], |
|
104 | 119 |
); |
105 |
return $order; |
|
120 |
return \%error_order; |
|
121 |
} |
|
106 | 122 |
}; |
107 | 123 |
|
108 | 124 |
sub compare_to { |
templates/webpages/shop_order/_transfer_status.html | ||
---|---|---|
11 | 11 |
[% LxERP.t8("This status output will be refreshed every five seconds.") %] |
12 | 12 |
</p> |
13 | 13 |
<p> |
14 |
[% # Dumper.dump_html(data) %]
|
|
14 |
[% Dumper.dump_html(data) %] |
|
15 | 15 |
</p> |
16 | 16 |
<p> |
17 | 17 |
[% L.link("#", LxERP.t8("Close window"), onclick="kivi.ShopOrder.processClose();") %] |
... | ... | |
44 | 44 |
[% ELSE %] |
45 | 45 |
<table> |
46 | 46 |
<tr class="listheader"> |
47 |
<th>[% LxERP.t8("Delivery Order") %]</th>
|
|
47 |
<th>[% LxERP.t8("Shoporder") %]</th>
|
|
48 | 48 |
<th>[% LxERP.t8("Error") %]</th> |
49 | 49 |
</tr> |
50 | 50 |
|
51 | 51 |
[% FOREACH error = data.conversion_errors %] |
52 | 52 |
<tr> |
53 |
<td valign="top">[% IF error.id %][% L.link(SELF.url_for(controller='do.pl', action='edit', type='sales_delivery_order', id=error.id), HTML.escape(error.number), target="_blank") %][% ELSE %]–[% END %]</td>
|
|
54 |
<td valign="top">[% HTML.escape(error.message) %]</td>
|
|
53 |
<td valign="top">[% HTML.escape(error.number) %]</td>
|
|
54 |
<td valign="top">[% FOREACH message = error.message %][% HTML.escape(message) %]<br>[% END %]</td>
|
|
55 | 55 |
</tr> |
56 | 56 |
[% END %] |
57 | 57 |
</table> |
templates/webpages/shop_order/show.html | ||
---|---|---|
1 | 1 |
[%- USE HTML -%][%- USE LxERP -%][%- USE L -%][%- USE T8 -%] |
2 | 2 |
[% L.stylesheet_tag('webshop') %] |
3 |
|
|
3 |
[%- INCLUDE 'common/flash.html' %] |
|
4 | 4 |
<h1>[% title %]</h1> |
5 | 5 |
|
6 | 6 |
<div class="shop_table shop_main"> |
Auch abrufbar als: Unified diff
Shopmodul: Fehlermeldung beim Übernehmen; Kunde nicht gefunden, Shopbestellung nicht gefunden, Artikel nicht gefunden, DB fehler beim Einfügen