ALTER TABLE `Product`
  DROP COLUMN `sheetName`;
ALTER TABLE `Product`
  DROP COLUMN `status`;

ALTER VIEW `vBluesealProductActive` AS SELECT
                                         `Product`.`id`                                            AS `id`,
                                         `Product`.`productVariantId`                              AS `productVariantId`,
                                         concat(`Product`.`id`, '-', `Product`.`productVariantId`) AS `code`,
                                         group_concat(DISTINCT `Shop`.`title` SEPARATOR ',')       AS `shops`,
                                         `Tag`.`id`                                                AS `tag`,
                                         `ProductStatus`.`name`                                    AS `status`,
                                         `Product`.`sortingPriorityId`                             AS `productPriority`,
                                         min(`Tag`.`sortingPriorityId`)                            AS `tagPriority`,
                                         `ProductBrand`.`name`                                     AS `brand`,
                                         sum(`ProductSku`.`stockQty`)                              AS `totalQty`,
                                         `Product`.`creationDate`                                  AS `creation`
                                       FROM (((((((`Product`
                                         JOIN `Tag`) JOIN `ProductSku`) JOIN `ProductHasTag`) JOIN `ProductBrand`) JOIN
                                         `ProductStatus`) JOIN `Shop`) JOIN
                                         `ProductHasProductPhoto`)
                                       WHERE ((`ProductHasTag`.`productId` = `Product`.`id`) AND
                                              (`ProductSku`.`shopId` = `Shop`.`id`) AND
                                              (`ProductHasTag`.`productVariantId` = `Product`.`productVariantId`) AND
                                              (`ProductStatus`.`id`) = `Product`.`productStatusId`) AND
                                             (`ProductStatus`.`code` IN ('A', 'P', 'N')) AND
                                             (`ProductHasTag`.`tagId` = `Tag`.`id`) AND
                                             (`Product`.`id` = `ProductSku`.`productId`) AND
                                             (`ProductSku`.`price` > 0)
                                             AND (`Product`.`id` =
                                                  `ProductHasProductPhoto`.`productId`) AND
                                             (`Product`.`productVariantId` =
                                              `ProductHasProductPhoto`.`productVariantId`) AND
                                             (`Product`.`productVariantId` =
                                              `ProductSku`.`productVariantId`) AND
                                             (`ProductBrand`.`id` = `Product`.`productBrandId`)
                                       GROUP BY `Product`.`id`, `Product`.`productVariantId`,
                                         `ProductSku`.`price`
                                       HAVING (`totalQty` >= 0)
                                       ORDER BY `Product`.`creationDate` DESC

ALTER VIEW `vBluesealProductIncomplete` AS
SELECT
  `p`.`id`                                              AS `id`,
  `p`.`productVariantId`                                AS `productVariantId`,
  `sp`.`shopId`                                         AS `shopId`,
  `s`.`name`                                            AS `shop`,
  concat(`p`.`itemno`, ' # ', `pv`.`name`)              AS `code`,
  `p`.`productSeasonId`                                 AS `season`,
  `p`.`externalId`                                      AS `externalId`,
  `pb`.`name`                                           AS `brand`,
  sum(`pk`.`stockQty`)                                  AS `totalQty`,
  `ps`.`name`                                           AS `status`,
  `p`.`creationDate`                                    AS `creationDate`,
  concat_ws(' ', if(isnull(`p`.`productSizeGroupId`), 'E400', NULL), if(isnull(`p`.`productSeasonId`), 'E410', NULL),
            if((`p`.`productBrandId` = 1), 'E420', NULL), if(isnull(`p`.`productSheetPrototypeId`), 'E430', NULL),
            if(isnull(`pc`.`productColorGroupId`), 'E440', NULL), if(isnull(`pp`.`productId`), 'E450', NULL),
            if(isnull(`pk`.`productId`), 'E460', NULL), if(isnull(`pn`.`name`), 'E470', NULL),
            if(isnull(`pd`.`productId`), 'E480', NULL)) AS `problems`
FROM ((((((((((`Product` `p` LEFT JOIN `ShopHasProduct` `sp`
    ON (((`p`.`id` = `sp`.`productId`) AND (`p`.`productVariantId` = `sp`.`productVariantId`)))) LEFT JOIN
  `ProductHasProductColorGroup` `pc`
    ON (((`pc`.`productId` = `p`.`id`) AND (`pc`.`productVariantId` = `p`.`productVariantId`)))) LEFT JOIN
  `ProductName` `pn`
    ON (((`pn`.`productId` = `p`.`id`) AND (`pn`.`productVariantId` = `p`.`productVariantId`)))) LEFT JOIN
  `ProductBrand` `pb` ON ((`p`.`productBrandId` = `pb`.`id`))) LEFT JOIN `Shop` `s`
    ON ((`s`.`id` = `sp`.`shopId`))) LEFT JOIN `ProductVariant` `pv`
    ON ((`p`.`productVariantId` = `pv`.`id`))) LEFT JOIN `ProductStatus` `ps`
    ON ((convert(`ps`.`id` USING utf8) = `p`.`productStatusId`))) LEFT JOIN `ProductSku` `pk`
    ON (((`p`.`id` = `pk`.`productId`) AND (`p`.`productVariantId` = `pk`.`productVariantId`)))) LEFT JOIN
  `ProductHasProductPhoto` `pp`
    ON (((`p`.`id` = `pp`.`productId`) AND (`p`.`productVariantId` = `pp`.`productVariantId`)))) LEFT JOIN
  `ProductDescription` `pd` ON (((`p`.`id` = `pd`.`productId`) AND (`p`.`productVariantId` = `pd`.`productVariantId`))))
WHERE ((`ps`.`code` NOT IN ('C', 'N')) AND (`pn`.`langId` = 1) AND (`pn`.`name` = '') AND (
  isnull(`pc`.`productColorGroupId`) OR isnull(`p`.`productSizeGroupId`) OR isnull(`p`.`productSeasonId`) OR
  (`p`.`productBrandId` = 1) OR isnull(`p`.`productSheetPrototypeId`) OR
  ((`ps`.`code` IN ('W', 'G')) AND (`p`.`dummyPicture` <> '0000000000.jpg'))))
GROUP BY `p`.`id`, `p`.`productVariantId`
HAVING (`totalQty` > 0)
ORDER BY `p`.`creationDate` DESC;

ALTER VIEW vBluesealProductImporter AS
SELECT
  `p`.`id`                                 AS `id`,
  `p`.`productVariantId`                   AS `productVariantId`,
  concat(`p`.`itemno`, ' # ', `pv`.`name`) AS `code`,
  `s`.`name`                               AS `shop`,
  `s`.`id`                                 AS `shopId`,
  `pb`.`name`                              AS `brand`,
  `p`.`externalId`                         AS `externalId`,
  `ps`.`name`                              AS `status`,
  `p`.`creationDate`                       AS `creationDate`
FROM (((((((`Product` `p`
  JOIN `ProductVariant` `pv` ON ((`pv`.`id` = `p`.`productVariantId`))) JOIN `ProductBrand` `pb`
    ON ((`p`.`productBrandId` = `pb`.`id`))) JOIN `ProductStatus` `ps` ON ((`p`.`productStatusId` = `ps`.`id`))) JOIN
  `DirtyProduct` `dp` ON (((`p`.`id` = `dp`.`productId`) AND (`p`.`productVariantId` = `dp`.`productVariantId`)))) JOIN
  `DirtySku` `ds` ON ((`dp`.`id` = `ds`.`dirtyProductId`))) LEFT JOIN `ShopHasProduct` `sp`
    ON (((`dp`.`productId` = `sp`.`productId`) AND (`dp`.`productVariantId` = `sp`.`productVariantId`) AND
         (`dp`.`shopId` = `sp`.`shopId`)))) JOIN `Shop` `s` ON ((`sp`.`shopId` = `s`.`id`)))
WHERE ((`ps`.`code` NOT IN ('N', 'C')) AND (`s`.`importer` IS NOT NULL) AND (`ds`.`status` <> 'ok'))
GROUP BY `dp`.`productId`, `dp`.`productVariantId`, `dp`.`shopId`
HAVING (sum(`ds`.`qty`) > 0);