
-- Belege
DELETE FROM ShopAccountJournalLine WHERE ShopAccountJournalLine.ShopAccountJournalLine_ID_Parent IS NOT NULL;
DELETE FROM ShopAccountJournalLine;
DELETE FROM ShopAccountJournal WHERE ShopAccountJournal.ShopAccountJournal_ID_Parent IS NOT NULL;
DELETE FROM ShopAccountJournal;
DELETE FROM ShopAccountJournalGroup;

-- Abos
DELETE FROM ShopAbo_ShopOrder;
DELETE FROM ShopAbo;

-- Tasks
DELETE FROM ShopTask_Person;
DELETE FROM ShopTask;

-- Bestellungen
DELETE FROM ShopOrderJournal;
DELETE FROM ShopOrder;

-- Gutscheine
DELETE FROM ShopVoucher;

-- Versionierung
DELETE FROM Version;

-- Produkt-Daten
UPDATE ShopWAWIProduct SET ShopWAWISupplier_ID = NULL;
UPDATE ShopArticle SET ShopWAWISupplier_ID = NULL;
DELETE FROM ShopWAWISupplier;

-- Preise
UPDATE ShopWAWIProduct SET ShopWAWIProduct.ShopWAWIProduct_Listenpreis = ROUND(ShopWAWIProduct.ShopWAWIProduct_Listenpreis * (1.0 + RAND() * 5.0), 2);
UPDATE ShopWAWIProduct SET ShopWAWIProduct.ShopWAWIProduct_Listenpreis_Supplier = ShopWAWIProduct.ShopWAWIProduct_Listenpreis;

UPDATE ShopWAWIProduct SET ShopWAWIProduct.ShopWAWIProduct_Einkaufspreis = ROUND(ShopWAWIProduct.ShopWAWIProduct_Listenpreis * 0.4, 2);
UPDATE ShopWAWIProduct SET ShopWAWIProduct.ShopWAWIProduct_Einkaufspreis_Supplier = ShopWAWIProduct.ShopWAWIProduct_Einkaufspreis;
UPDATE ShopWAWIProduct SET ShopWAWIProduct.ShopWAWIProduct_Einstandspreis = ShopWAWIProduct.ShopWAWIProduct_Einkaufspreis;
UPDATE ShopWAWIProduct SET ShopWAWIProduct.ShopWAWIProduct_Einstandspreis_Supplier = ShopWAWIProduct.ShopWAWIProduct_Einkaufspreis;

-- Kunden
DELETE FROM ShopUser;
DELETE FROM NewsletterRecipient;
DELETE FROM Person WHERE Person_ID > 4;

-- Demo-Zugang anlegen
INSERT INTO `Person` (`PersonGroup_ID`, `Person_Sex`, `Person_Lastname`, `Person_Firstname`, `Person_Email`, `Person_ID_Edit`, `Table_Edit`, `Person_ID_Create`, `Table_Create`) VALUES (1, 'male', 'User', 'Demo', 'demo@deinbedarf.com', 1, NOW(), 1, NOW());
SET @PERSONID = LAST_INSERT_ID();
INSERT INTO `Worker` (`Person_ID`, `Language_Code`, `Worker_Username`, `Worker_Password`, `Worker_Active`, `Person_ID_Edit`, `Table_Edit`, `Person_ID_Create`, `Table_Create`) VALUES (@PERSONID, 'de', 'demo', MD5('demo'), 'true', 1, NOW(), 1, NOW());
INSERT INTO `Language_Person` (`Language_Code`, `Person_ID`, `Person_ID_Edit`, `Table_Edit`, `Person_ID_Create`, `Table_Create`) VALUES ('de', @PERSONID, 1, NOW(), 1, NOW());
