29 |
29 |
my ( $self ) = @_;
|
30 |
30 |
my $orders_fetched;
|
31 |
31 |
my $new_orders;
|
32 |
|
my %new_order;
|
33 |
|
my $active_shops = SL::DB::Manager::Shop->get_all(query => [ obsolete => 0 ]);
|
34 |
|
foreach my $shop_config ( @{ $active_shops } ) {
|
35 |
|
my $shop = SL::Shop->new( config => $shop_config );
|
36 |
|
my $connect = $shop->check_connectivity;
|
37 |
|
|
38 |
|
if( !$connect->{success} ){
|
39 |
|
%new_order = (
|
40 |
|
number_of_orders => $connect->{data}->{version},
|
41 |
|
shop_id => $shop->config->description,
|
42 |
|
error => 1,
|
43 |
|
);
|
44 |
|
$new_orders = \%new_order;
|
45 |
|
}else{
|
|
32 |
|
|
33 |
my $type = $::form->{type};
|
|
34 |
if ( $type eq "get_next" ) {
|
|
35 |
my $active_shops = SL::DB::Manager::Shop->get_all(query => [ obsolete => 0 ]);
|
|
36 |
foreach my $shop_config ( @{ $active_shops } ) {
|
|
37 |
my $shop = SL::Shop->new( config => $shop_config );
|
|
38 |
|
46 |
39 |
$new_orders = $shop->connector->get_new_orders;
|
|
40 |
push @{ $orders_fetched }, $new_orders ;
|
|
41 |
}
|
|
42 |
|
|
43 |
} elsif ( $type eq "get_one" ) {
|
|
44 |
my $shop_id = $::form->{shop_id};
|
|
45 |
my $shop_ordernumber = $::form->{shop_ordernumber};
|
|
46 |
|
|
47 |
if ( $shop_id && $shop_ordernumber ){
|
|
48 |
my $shop_config = SL::DB::Manager::Shop->get_first(query => [ id => $shop_id, obsolete => 0 ]);
|
|
49 |
my $shop = SL::Shop->new( config => $shop_config );
|
|
50 |
unless ( SL::DB::Manager::ShopOrder->get_all_count( query => [ shop_ordernumber => $shop_ordernumber, shop_id => $shop_id, obsolete => 'f' ] )) {
|
|
51 |
my $connect = $shop->check_connectivity;
|
|
52 |
$new_orders = $shop->connector->get_one_order($shop_ordernumber);
|
|
53 |
push @{ $orders_fetched }, $new_orders ;
|
|
54 |
} else {
|
|
55 |
flash_later('error', t8('From shop "#1" : Number: #2 #3 ', $shop->config->description, $shop_ordernumber, t8('Shoporder with this ordernumber is already fetched')));
|
|
56 |
}
|
|
57 |
} else {
|
|
58 |
flash_later('error', t8('Shop or ordernumber not selected.'));
|
47 |
59 |
}
|
48 |
|
push @{ $orders_fetched }, $new_orders ;
|
49 |
60 |
}
|
50 |
61 |
|
51 |
62 |
foreach my $shop_fetched(@{ $orders_fetched }) {
|
52 |
63 |
if($shop_fetched->{error}){
|
53 |
|
flash_later('error', t8('From shop "#1" : #2 ', $shop_fetched->{shop_id}, $shop_fetched->{number_of_orders},));
|
|
64 |
flash_later('error', t8('From shop "#1" : #2 ', $shop_fetched->{shop_description}, $shop_fetched->{message},));
|
54 |
65 |
}else{
|
55 |
|
flash_later('info', t8('From shop #1 : #2 shoporders have been fetched.', $shop_fetched->{shop_id}, $shop_fetched->{number_of_orders},));
|
|
66 |
flash_later('info', t8('From shop #1 : #2 shoporders have been fetched.', $shop_fetched->{description}, $shop_fetched->{number_of_orders},));
|
56 |
67 |
}
|
57 |
68 |
}
|
58 |
|
$self->redirect_to(controller => "ShopOrder", action => 'list');
|
|
69 |
|
|
70 |
$self->redirect_to(controller => "ShopOrder", action => 'list', filter => { 'transferred:eq_ignore_empty' => 0, obsolete => 0 });
|
59 |
71 |
}
|
60 |
72 |
|
61 |
73 |
sub action_list {
|
... | ... | |
70 |
82 |
);
|
71 |
83 |
|
72 |
84 |
foreach my $shop_order(@{ $shop_orders }){
|
73 |
|
|
74 |
|
my $open_invoices = SL::DB::Manager::Invoice->get_all_count(
|
75 |
|
query => [customer_id => $shop_order->{kivi_customer_id},
|
76 |
|
paid => {lt_sql => 'amount'},
|
77 |
|
],
|
78 |
|
);
|
79 |
|
$shop_order->{open_invoices} = $open_invoices;
|
|
85 |
$shop_order->{open_invoices} = $shop_order->check_for_open_invoices;
|
80 |
86 |
}
|
81 |
87 |
$self->_setup_list_action_bar;
|
82 |
88 |
$self->render('shop_order/list',
|
... | ... | |
102 |
108 |
|
103 |
109 |
}
|
104 |
110 |
|
|
111 |
sub action_customer_assign_to_shoporder {
|
|
112 |
my ($self) = @_;
|
|
113 |
|
|
114 |
$self->shop_order->assign_attributes( kivi_customer => $::form->{customer} );
|
|
115 |
$self->shop_order->save;
|
|
116 |
$self->redirect_to(controller => "ShopOrder", action => 'show', id => $self->shop_order->id);
|
|
117 |
}
|
|
118 |
|
105 |
119 |
sub action_delete_order {
|
106 |
120 |
my ( $self ) = @_;
|
107 |
121 |
|
... | ... | |
115 |
129 |
|
116 |
130 |
$self->shop_order->obsolete(0);
|
117 |
131 |
$self->shop_order->save;
|
118 |
|
$self->redirect_to(controller => "ShopOrder", action => 'show', id => $self->shop_order->id);
|
|
132 |
$self->redirect_to(controller => "ShopOrder", action => 'list', filter => { 'transferred:eq_ignore_empty' => 0, obsolete => 0 });
|
119 |
133 |
}
|
120 |
134 |
|
121 |
135 |
sub action_transfer {
|
... | ... | |
172 |
186 |
)->set_data(
|
173 |
187 |
shop_order_record_ids => [ @shop_orders ],
|
174 |
188 |
num_order_created => 0,
|
|
189 |
num_order_failed => 0,
|
175 |
190 |
num_delivery_order_created => 0,
|
176 |
191 |
status => SL::BackgroundJob::ShopOrderMassTransfer->WAITING_FOR_EXECUTION(),
|
177 |
|
conversion_errors => [ ],
|
|
192 |
conversion_errors => [],
|
178 |
193 |
)->update_next_run_at;
|
179 |
194 |
|
180 |
195 |
SL::System::TaskServer->new->wake_up;
|
... | ... | |
278 |
293 |
t8('Search'),
|
279 |
294 |
submit => [ '#shoporders', { action => "ShopOrder/list" } ],
|
280 |
295 |
],
|
281 |
|
link => [
|
282 |
|
t8('Shoporders'),
|
283 |
|
link => [ $self->url_for(action => 'get_orders') ],
|
284 |
|
tooltip => t8('New shop orders'),
|
|
296 |
combobox => [
|
|
297 |
link => [
|
|
298 |
t8('Shoporders'),
|
|
299 |
call => [ 'kivi.ShopOrder.get_orders_next' ],
|
|
300 |
tooltip => t8('New shop orders'),
|
|
301 |
],
|
|
302 |
action => [
|
|
303 |
t8('Get one order'),
|
|
304 |
call => [ 'kivi.ShopOrder.get_one_order_setup', id => "get_one" ],
|
|
305 |
tooltip => t8('Get one order by shopordernumber'),
|
|
306 |
],
|
285 |
307 |
],
|
286 |
308 |
'separator',
|
287 |
309 |
action => [
|
WebshopApi: Controller/ShopOrder.pm überarbeitet