commit 14a907f2e5661a779707180bf1474dcb0aeccf6b
Author: Werner Hahn <wh@futureworldsearch.net>
Date:   Thu Oct 20 15:59:59 2016 +0200

    Shopmodul: sql-Updatesfiles für das Shopmodul.
    Beinhaltet auch ein hinzufügen der Spalte Auftragssperre in der Tabelle customer sowie das webtemplate billing beim Kunden wo die Auftragssperre eingegeben werden kann

diff --git a/SL/BackgroundJob/ShopOrderMassTransfer.pm b/SL/BackgroundJob/ShopOrderMassTransfer.pm
index 0142b0ef8..dd2988a4c 100644
--- a/SL/BackgroundJob/ShopOrderMassTransfer.pm
+++ b/SL/BackgroundJob/ShopOrderMassTransfer.pm
@@ -42,8 +42,6 @@ sub create_order {
   foreach my $shop_order_id (@{ $job_obj->data_as_hash->{shop_order_record_ids} }) {
     my $data = $job_obj->data_as_hash;
     my $shop_order = SL::DB::ShopOrder->new(id => $shop_order_id)->load;
-    # die "can't find shoporder with id $shop_order_id" unless $shop_order;
-    #TODO Kundenabfrage so ändern, dass es nicht abricht
     unless($shop_order){
       push @{ $error_report{$shop_order_id} }, 'Shoporder not found';
     }
@@ -52,17 +50,7 @@ sub create_order {
     my $employee = SL::DB::Manager::Employee->current;
     my $items = SL::DB::Manager::ShopOrderItem->get_all( where => [shop_order_id => $shop_order_id],
                                                           sort_by => 'partnumber::int' );
-    # check inventory onhand > 0 and active = 1
-    my $transferable = 0;
-    foreach my $item (@$items) {
-      my $part = SL::DB::Manager::Part->find_by(partnumber => $item->{partnumber});
-      # TODO: qty direkt aus dem Lager holen und nicht von onhand
-      $transferable = $part->{onhand} >= $item->{quantity} ? 1 : 0;
-      $transferable = $part->{active} = 1 ? 1 : 0;
-
-      last if $transferable == 0;
-    }
-    if ($transferable == 1 && $customer->{order_lock} == 0) {
+    if ($customer->{order_lock} == 0) {
       $shop_order->{shop_order_items} = $items;
 
       my $order = $shop_order->convert_to_sales_order(customer => $customer, employee => $employee);
@@ -85,77 +73,6 @@ sub create_order {
       push @{ $data->{shop_orders_ids} }, $shop_order->id;
 
       $job_obj->update_attributes(data_as_hash => $data);
-      my $delivery_order = $order->convert_to_delivery_order(customer => $customer, employee => $employee);
-      $delivery_order->save;
-      my $snumbers = "deliveryordernumber_" . $delivery_order->donumber;
-      SL::DB::History->new(
-                        trans_id    => $delivery_order->id,
-                        snumbers    => $snumbers,
-                        employee_id => SL::DB::Manager::Employee->current->id,
-                        addition    => 'SAVED',
-                        what_done   => 'Shopimport->Order->Deliveryorder(MassTransfer)',
-                      )->save();
-      $order->link_to_record($delivery_order);
-      my $delivery_order_items = $delivery_order->{orderitems};
-      # Lagerentnahme
-      # entsprechende defaults holen, falls standardlagerplatz verwendet werden soll
-      my $test = $::instance_conf->get_transfer_default_use_master_default_bin;
-      require SL::DB::Inventory;
-      my $rose_db = SL::DB::Inventory->new->db;
-      my $dbh = $db->dbh;
-      my $default_warehouse_id;
-      my $default_bin_id;
-      my @parts_ids;
-      my @transfers;
-      my @errors;
-      my $qty;
-      my $stock_out;
-      require SL::WH;
-      require SL::IS;
-      require SL::DB::DeliveryOrderItemsStock;
-      foreach my $item (@{$delivery_order_items}) {
-        my ($err, $wh_id, $bin_id) = IS->_determine_wh_and_bin($dbh, $::instance_conf,
-                                                           $item->{parts_id},
-                                                           $item->{qty},
-                                                           $item->{unit}
-                                                           );
-        if (!@{ $err } && $wh_id && $bin_id) {
-          my $delivery_order_items_stock = SL::DB::DeliveryOrderItemsStock->new;
-          $delivery_order_items_stock->assign_attributes (
-            'delivery_order_item_id'  => $item->{id},
-            'qty'                     => $item->{qty},
-            'unit'                    => $item->{unit},
-            'warehouse_id'            => $wh_id,
-            'bin_id'                  => $bin_id,
-          );
-          $delivery_order_items_stock->save;
-
-          my ($trans_id) = selectrow_query($::form, $::form->get_standard_dbh, qq|SELECT nextval('id')|);
-          my $wh_transfer = SL::DB::Inventory->new;
-          $wh_transfer->assign_attributes (
-            'trans_id'                      => $trans_id,
-            'employee'                      => $employee->{id},
-            'bestbefore'                    => undef,
-            'chargenumber'                  => '',
-            'shippingdate'                  => DateTime->today,
-            'delivery_order_items_stock_id' => $delivery_order_items_stock->id,
-            'project_id'                    => '',
-            'parts_id'                      => $item->{parts_id},
-            'qty'                           => $item->{qty} * -1,
-            'trans_type_id'              => 889,#hardcodiert
-            'warehouse_id'                  => $wh_id,
-            'bin_id'                        => $bin_id,
-            'comment'                       => $main::locale->text("Default transfer delivery order"),
-            'oe_id'                         => $delivery_order->{id},
-          );
-          $wh_transfer->save;
-        }
-        push @errors, @{ $err };
-      }
-      if (!@errors) {
-          $delivery_order->delivered(1);
-          $delivery_order->save;
-      }
     }
   }
 }
diff --git a/sql/Pg-upgrade2/customer_orderlock.sql b/sql/Pg-upgrade2/customer_orderlock.sql
new file mode 100644
index 000000000..2a4324a76
--- /dev/null
+++ b/sql/Pg-upgrade2/customer_orderlock.sql
@@ -0,0 +1,5 @@
+-- @tag: customer_orderlock
+-- @description: Boolean Auftragssperre benötigt bei shoporders
+-- @depends: release_3_4_1 shops
+-- @ignore: 0
+ALTER TABLE customer ADD COLUMN order_lock boolean default 0;
diff --git a/sql/Pg-upgrade2/df_shoporder.sql b/sql/Pg-upgrade2/df_shoporder.sql
deleted file mode 100644
index e50203342..000000000
--- a/sql/Pg-upgrade2/df_shoporder.sql
+++ /dev/null
@@ -1,5 +0,0 @@
--- @tag: df_shoporder
--- @description: Feld Auftragssperre in der shoporder Tabelle
--- @depends: release_3_4_0
-
-ALTER TABLE shop_orders ADD COLUMN df_kivi_customer_order_lock boolean DEFAULT FALSE NOT NULL;
diff --git a/sql/Pg-upgrade2/df_shoporder3.sql b/sql/Pg-upgrade2/df_shoporder3.sql
deleted file mode 100644
index 3abbda9fc..000000000
--- a/sql/Pg-upgrade2/df_shoporder3.sql
+++ /dev/null
@@ -1,6 +0,0 @@
--- @tag: df_shoporder3
--- @description: Feld df_kivi_customer_order_lock in der shoporder Tabelle wieder gelösch da order_lock direkt aus den Kundendaten genommen wird. Tabellen customer und shop_order sind Verknüpft. Spalte obsolete hinzgefügt
--- @depends: release_3_4_0
-
-ALTER TABLE shop_orders DROP COLUMN df_kivi_customer_order_lock;
-ALTER TABLE shop_orders ADD COLUMN obsolete boolean DEFAULT FALSE NOT NULL;
diff --git a/sql/Pg-upgrade2/df_shoporder_2.sql b/sql/Pg-upgrade2/df_shoporder_2.sql
deleted file mode 100644
index 53c8de058..000000000
--- a/sql/Pg-upgrade2/df_shoporder_2.sql
+++ /dev/null
@@ -1,6 +0,0 @@
--- @tag: df_shoporder_2
--- @description: Feld Positionen in der shoporder Tabelle
--- @depends: release_3_4_0
-
-ALTER TABLE shop_orders ADD COLUMN positions integer;
-
diff --git a/sql/Pg-upgrade2/shop_orders.sql b/sql/Pg-upgrade2/shop_orders.sql
index 270f85bf6..b5127462c 100644
--- a/sql/Pg-upgrade2/shop_orders.sql
+++ b/sql/Pg-upgrade2/shop_orders.sql
@@ -1,6 +1,6 @@
 -- @tag: shop_orders
 -- @description: Erstellen der Tabellen shop_orders und shop_order_items
--- @depends: release_3_3_0
+-- @depends: release_3_4_1 shops
 
 CREATE TABLE shop_orders (
   id SERIAL PRIMARY KEY,
@@ -20,10 +20,10 @@ CREATE TABLE shop_orders (
   shop_id integer,               --welcher shop bei mehreren
   host TEXT,             --Hostname vom Shop
   remote_ip text,        --IP Besteller
-  transferred boolean DEFAULT FALSE,    -- übernommen 
+  transferred boolean DEFAULT FALSE,    -- übernommen
   transfer_date date, -- Zeit wann übernommen
   kivi_customer_id integer,  -- Kundenid von Tbl customer wenn übernommen
-  oe_transid integer,  -- id to 
+  oe_transid integer,  -- id to
 -- Bestell-, Rechnungs- und Lieferadresse. !!Manche Shops bieten sowas!!
 -- In der Regel ist aber die Rechnungsadresse die Kundenadresse
   -- Bestelldaten des Kunden
@@ -59,7 +59,7 @@ CREATE TABLE shop_orders (
   billing_phone TEXT,
   billing_fax TEXT,
   billing_email TEXT,
-  
+
   -- SEPA
   sepa_account_holder TEXT,
   sepa_iban TEXT,
@@ -82,6 +82,9 @@ CREATE TABLE shop_orders (
   delivery_fax TEXT,
   delivery_email TEXT,
 
+  obsolete boolean DEFAULT FALSE NOT NULL,
+  positions integer,
+
   itime timestamp DEFAULT now(),
   mtime timestamp
 );
@@ -92,7 +95,8 @@ CREATE TABLE shop_order_items (
   shop_order_id INTEGER REFERENCES shop_orders (id) ON DELETE CASCADE,
   description   TEXT,  -- Artikelbezeichnung
   partnumber    TEXT,
-  shop_id       INTEGER,  --kann als Sortorder benutzt werden
+  shop_id       INTEGER,
+  position      INTEGER,
   tax_rate      NUMERIC(15,2),
   quantity      NUMERIC(25,5),   -- qty in invoice and orderitems is real, doi is numeric(25,5)
   price         NUMERIC(15,5)
diff --git a/sql/Pg-upgrade2/shop_orders_2.sql b/sql/Pg-upgrade2/shop_orders_2.sql
deleted file mode 100644
index 37a7622a5..000000000
--- a/sql/Pg-upgrade2/shop_orders_2.sql
+++ /dev/null
@@ -1,4 +0,0 @@
--- @tag: shop_orders_2
--- @description: Hinzufügen der Spalte Position in der Tabelle shop_order_items
--- @depends: release_3_3_0
-ALTER TABLE shop_order_items ADD COLUMN position integer;
diff --git a/sql/Pg-upgrade2/shop_parts.sql b/sql/Pg-upgrade2/shop_parts.sql
index 273d32629..fa0f387a8 100644
--- a/sql/Pg-upgrade2/shop_parts.sql
+++ b/sql/Pg-upgrade2/shop_parts.sql
@@ -1,7 +1,7 @@
 -- @tag: shop_parts
 -- @description: Add tables for part information for shop
 -- @charset: UTF-8
--- @depends: release_3_3_0 shops
+-- @depends: release_3_4_1 shops
 -- @ignore: 0
 
 CREATE TABLE shop_parts (
@@ -16,18 +16,13 @@ CREATE TABLE shop_parts (
   sortorder        INTEGER,
   front_page       BOOLEAN NOT NULL DEFAULT false,
   active           BOOLEAN NOT NULL DEFAULT false,  -- rather than obsolete
-  shop_category    TEXT,
-  meta_tags        TEXT,
+  shop_category TYPE TEXT[] USING array[shop_category;
+  active_price_source TEXT,
+  metatag_keywords TEXT,
+  metatag_keywords TEXT,
+  metatag_title TEXT,
   UNIQUE (part_id, shop_id)  -- make sure a shop_part appears only once per shop and part
 );
 
 CREATE TRIGGER mtime_shop_parts BEFORE UPDATE ON shop_parts
     FOR EACH ROW EXECUTE PROCEDURE set_mtime();
-
--- CREATE TABLE shop_meta_tags (
--- id integer NOT NULL DEFAULT nextval('shop_parts_id'),
- --  description
--- );
-
--- CREATE TABLE shop_categories (
--- );
diff --git a/sql/Pg-upgrade2/shop_parts_2.sql b/sql/Pg-upgrade2/shop_parts_2.sql
deleted file mode 100644
index 988124192..000000000
--- a/sql/Pg-upgrade2/shop_parts_2.sql
+++ /dev/null
@@ -1,6 +0,0 @@
--- @tag: shop_parts_2
--- @description: Add tables for part information for shop
--- @charset: UTF-8
--- @depends: release_3_3_0 shops
--- @ignore: 0
-ALTER TABLE shop_parts ALTER COLUMN shop_category TYPE TEXT[] USING array[shop_category];
diff --git a/sql/Pg-upgrade2/shop_parts_4.sql b/sql/Pg-upgrade2/shop_parts_4.sql
deleted file mode 100644
index 093c41c94..000000000
--- a/sql/Pg-upgrade2/shop_parts_4.sql
+++ /dev/null
@@ -1,10 +0,0 @@
--- @tag: shop_parts_4
--- @description: Add tables for part information for shop
--- @charset: UTF-8
--- @depends: release_3_3_0 shops
--- @ignore: 0
-ALTER TABLE shop_parts ADD COLUMN active_price_source text;
-ALTER TABLE shop_parts ADD COLUMN metatag_keywords text;
-ALTER TABLE shop_parts ADD COLUMN metatag_description text;
-ALTER TABLE shop_parts ADD COLUMN metatag_title text;
-ALTER TABLE shop_parts DROP COLUMN meta_tags;
diff --git a/sql/Pg-upgrade2/shops.sql b/sql/Pg-upgrade2/shops.sql
index a1dbfc0e9..d6f3f7a9d 100644
--- a/sql/Pg-upgrade2/shops.sql
+++ b/sql/Pg-upgrade2/shops.sql
@@ -1,6 +1,6 @@
 -- @tag: shops
 -- @description: Tabelle für Shops
--- @depends: release_3_3_0
+-- @depends: release_3_4_1 customer_klass_rename_to_pricegroup_id_and_foreign_key
 -- @ignore: 0
 
 CREATE TABLE shops (
@@ -11,6 +11,9 @@ CREATE TABLE shops (
   connector text,     -- hardcoded options, e.g. xtcommerce, shopware
   pricetype text,     -- netto/brutto
   price_source text,  -- sellprice/listprice/lastcost or pricegroup id
+  taxzone_id INTEGER,
+  last_order_number INTEGER,
+  orders_to_fetch INTEGER,
   url text,
   port INTEGER,
   login text,  -- "user" is reserved
diff --git a/sql/Pg-upgrade2/shops2.sql b/sql/Pg-upgrade2/shops2.sql
deleted file mode 100644
index 2f39cc12d..000000000
--- a/sql/Pg-upgrade2/shops2.sql
+++ /dev/null
@@ -1,8 +0,0 @@
--- @tag: shops2
--- @description: Alter table shops more columns for configuration
--- @charset: UTF-8
--- @depends: release_3_4_0 shops
--- @ignore: 0
-
-ALTER TABLE shops ADD COLUMN last_order_number integer;
-ALTER TABLE shops ADD COLUMN orders_to_fetch integer;
diff --git a/sql/Pg-upgrade2/shops3.sql b/sql/Pg-upgrade2/shops3.sql
deleted file mode 100644
index 049f723a6..000000000
--- a/sql/Pg-upgrade2/shops3.sql
+++ /dev/null
@@ -1,7 +0,0 @@
--- @tag: shops3
--- @description: Alter table shops more columns for configuration
--- @charset: UTF-8
--- @depends: release_3_4_0 shops
--- @ignore: 0
-
-ALTER TABLE shops ADD COLUMN taxzone_id integer;
diff --git a/templates/webpages/customer_vendor/tabs/billing.html b/templates/webpages/customer_vendor/tabs/billing.html
index 0ba92d7e5..ff72fb6bb 100644
--- a/templates/webpages/customer_vendor/tabs/billing.html
+++ b/templates/webpages/customer_vendor/tabs/billing.html
@@ -8,6 +8,13 @@
   <table width="100%">
 
     <tr height="5"></tr>
+    <tr>
+      <th align="right" valign="top" nowrap>[% 'Orderlock' | $T8 %]</th>
+      <td>
+        [% L.checkbox_tag('cv.order_lock', checked = SELF.cv.order_lock, for_submit=1) %]
+      </td>
+    </tr>
+
 
     [% IF ( INSTANCE_CONF.get_vertreter ) %]
       <tr>
