Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision d4cb86eb

Von Werner Hahn vor mehr als 6 Jahren hinzugefügt

  • ID d4cb86eb6fe5732c845f10f0158db160d7809368
  • Vorgänger 47a980b7
  • Nachfolger dd6f702e

Shopmodul: ShopOrders Massenübernahme

Conflicts:
SL/BackgroundJob/ShopOrderMassTransfer.pm
sql/Pg-upgrade2/shop_orders_2.sql

Unterschiede anzeigen:

SL/BackgroundJob/ShopOrderMassTransfer.pm
1
package SL::BackgroundJob::ShopOrderMassTransfer;
2
#BackgroundJob::ShopOrderMassTransfer
3
use strict;
4
use warnings;
5

  
6
use parent qw(SL::BackgroundJob::Base);
7

  
8
#
9
# Workflow Dreschflegel Shoporder import -> wo geht automatisch nach Order(Auftrag) und DeliveryOrder (Lieferschein) mit auslagern transferieren
10
#
11

  
12
use SL::DBUtils;
13
use SL::DB::ShopOrder;
14
use SL::DB::ShopOrderItem;
15
use SL::DB::Order;
16
use SL::DB::DeliveryOrder;
17
use SL::DB::Inventory;
18
use Sort::Naturally ();
19

  
20
use constant WAITING_FOR_EXECUTION        => 0;
21
use constant CONVERTING_TO_ORDER          => 1;
22
use constant CONVERTING_TO_DELIVERY_ORDER => 2;
23
use constant DONE                         => 3;
24

  
25
# Data format:
26
# my $data                  = {
27
#     shop_order_record_ids       => [ 603, 604, 605],
28
#     num_order_created           => 0,
29
#     num_delivery_order_created  => 0,
30
#     conversation_errors         => [ { id => 603 , item => 2, message => "Out of stock"}, ],
31
# };
32
#
33

  
34
sub create_order {
35
  my ( $self ) = @_;
36
  my $job_obj = $self->{job_obj};
37
  my $db      = $job_obj->db;
38

  
39
  $job_obj->set_data(CONVERTING_TO_DELIVERY_ORDER())->save;
40

  
41
  foreach my $shop_order_id (@{ $job_obj->data_as_hash->{shop_order_record_ids} }) {
42
    my $shop_order = SL::DB::ShopOrder->new(id => $shop_order_id)->load;
43
    die "can't find shoporder with id $shop_order_id" unless $shop_order;
44
    $::lxdebug->dump(0, 'WH: CREATE:I ', \$shop_order);
45
    #TODO Kundenabfrage so ändern, dass es nicht abricht
46
    my $customer = SL::DB::Manager::Customer->find_by(id => $shop_order->{kivi_customer_id});
47
    die "Can't find customer" unless $customer;
48
    my $employee = SL::DB::Manager::Employee->current;
49
    my $items = SL::DB::Manager::ShopOrderItem->get_all( where => [shop_order_id => $shop_order_id],
50
                                                          sort_by => 'partnumber::int' );
51
    $::lxdebug->dump(0, 'WH: CREATE:I ', \$shop_order);
52
    $::lxdebug->dump(0, 'WH: CREATE:II ', \$items);
53

  
54
    # check inventory onhand > 0
55
    my $onhand = 0;
56
    foreach my $item (@$items) {
57
      my $qty = SL::DB::Manager::Part->find_by(partnumber => $item->{partnumber})->onhand; # > 0 ? $onhand = 1 : 0;
58
      $qty >= $item->{quantity} ? $onhand = 1 : 0;
59
      $main::lxdebug->message(0, "WH: STOCK: $qty -- $onhand");
60
      last if $onhand == 0;
61
    }
62
    $main::lxdebug->message(0, "WH:ONHAND: $onhand ");
63
    if ($onhand == 1) {
64
      $shop_order->{shop_order_items} = $items;
65
      $main::lxdebug->dump(0, 'WH: TRANSFER SHOPORDER', \$shop_order);
66

  
67
      my $order = $shop_order->convert_to_sales_order(customer => $customer, employee => $employee);
68
      $order->save;
69
      $shop_order->transferred(1);
70
      $shop_order->transfer_date(DateTime->now_local);
71
      $shop_order->oe_transid($order->id);
72
      $shop_order->save;
73
      $shop_order->link_to_record($order);
74

  
75
      my $delivery_order = $order->convert_to_delivery_order(customer => $customer, employee => $employee);
76
      $delivery_order->save;
77
      $order->link_to_record($delivery_order);
78
      my $delivery_order_items = $delivery_order->{orderitems};
79
      # Lagerentnahme
80
      # entsprechende defaults holen, falls standardlagerplatz verwendet werden soll
81
      $main::lxdebug->dump(0, 'WH: LAGER: ', \$delivery_order_items);
82
      my $test = $::instance_conf->get_transfer_default_use_master_default_bin;
83
      $main::lxdebug->message(0, "WH: TEST $test ");
84
      $main::lxdebug->dump(0, 'WH: KONF ',$::instance_conf);
85
      $main::lxdebug->message(0, "WH:NACH ");
86
      require SL::DB::Inventory;
87
      my $rose_db = SL::DB::Inventory->new->db;
88
      my $dbh = $db->dbh;
89
      my $default_warehouse_id;
90
      my $default_bin_id;
91
      my @parts_ids;
92
      my @transfers;
93
      my @errors;
94
      my $qty;
95
      my $stock_out;
96
      require SL::WH;
97
      require SL::IS;
98
      require SL::DB::DeliveryOrderItemsStock;
99
      foreach my $item (@{$delivery_order_items}) {
100
        my ($err, $wh_id, $bin_id) = IS->_determine_wh_and_bin($dbh, $::instance_conf,
101
                                                           $item->{parts_id},
102
                                                           $item->{qty},
103
                                                           $item->{unit}
104
                                                           );
105
        if (!@{ $err } && $wh_id && $bin_id) {
106
          my $delivery_order_items_stock = SL::DB::DeliveryOrderItemsStock->new;
107
          $delivery_order_items_stock->assign_attributes (
108
            'delivery_order_item_id'  => $item->{id},
109
            'qty'                     => $item->{qty},
110
            'unit'                    => $item->{unit},
111
            'warehouse_id'            => $wh_id,
112
            'bin_id'                  => $bin_id,
113
          );
114
          $delivery_order_items_stock->save;
115

  
116
          my ($trans_id) = selectrow_query($::form, $::form->get_standard_dbh, qq|SELECT nextval('id')|);
117
          my $wh_transfer = SL::DB::Inventory->new;
118
          $wh_transfer->assign_attributes (
119
            'trans_id'                      => $trans_id,
120
            'employee'                      => $employee->{id},
121
            'bestbefore'                    => undef,
122
            'chargenumber'                  => '',
123
            'shippingdate'                  => DateTime->today,
124
            'delivery_order_items_stock_id' => $delivery_order_items_stock->id,
125
            'project_id'                    => '',
126
            'parts_id'                      => $item->{parts_id},
127
            'qty'                           => $item->{qty} * -1,
128
            'trans_type_id'              => 889,#hardcodiert
129
            'warehouse_id'                  => $wh_id,
130
            'bin_id'                        => $bin_id,
131
            'comment'                       => $main::locale->text("Default transfer delivery order"),
132
            'oe_id'                         => $delivery_order->{id},
133
          );
134
          $wh_transfer->save;
135
        }
136
        push @errors, @{ $err };
137
      }
138
      $main::lxdebug->dump(0, 'WH: LAGER II ', \@transfers);
139
      $main::lxdebug->dump(0, 'WH: LAGER III ', \@errors);
140
      if (!@errors) {
141
          $delivery_order->delivered(1);
142
          $delivery_order->save;
143
      }
144
    }
145
  }
146
}
147

  
148
sub create_delivery_order {
149
  my ( $self ) = @_;
150
}
151

  
152
sub run {
153
  my ($self, $job_obj) = @_;
154
  $::lxdebug->dump(0, 'WH: RUN: ', \$self);
155

  
156
  $self->{job_obj}         = $job_obj;
157
  $self->create_order;
158

  
159
  $job_obj->set_data(status => DONE())->save;
160

  
161
  return 1;
162
}
163
1;
SL/Controller/ShopOrder.pm
1 1
package SL::Controller::ShopOrder;
2
# Controller::ShopOrder
2 3

  
3 4
use strict;
4 5

  
SL/DB/ShopOrder.pm
2 2
# Feel free to modify it at will; it will not be overwritten automatically.
3 3

  
4 4
package SL::DB::ShopOrder;
5
# DB::ShopOrder
5 6

  
6 7
use strict;
7 8

  
SL/ShopConnector/Shopware.pm
1 1
package SL::ShopConnector::Shopware;
2
#package SL::ShopConnector::Shopware;
2 3

  
3 4
use strict;
4 5

  
sql/Pg-upgrade2/shop_orders_2.sql
1
-- @tag: shop_orders_2
2
-- @description: Hinzufügen der Spalte Position in der Tabelle shop_order_items
3
-- @depends: release_3_3_0
4
-- tmp
5
ALTER TABLE shop_order_items ADD COLUMN position integer;
templates/webpages/shop_order/list.html
1 1
[%- USE HTML -%][%- USE LxERP -%][%- USE L -%][%- USE T8 -%]
2 2
[% USE Dumper %]
3
<!-- TMP -->
3 4

  
4 5
<h1>[% title %]</h1>
5 6
[%- PROCESS 'shop_order/_filter.html' filter=SELF.models.filtered.laundered %]

Auch abrufbar als: Unified diff