create view `sivir_products_list` as
select distinct `product`.`relative`                        AS `relative`,
                `product`.`users_sid`                       AS `users_sid`,
                `product`.`global_branch_office_id`         AS `global_branch_office_id`,
                `product`.`product_kind`                    AS `product_kind`,
                `product`.`fullname`                        AS `fullname`,
                `product`.`description`                     AS `description`,
                `product`.`code`                            AS `code`,
                `product`.`category_id`                     AS `category_id`,
                `product`.`subcategory_id`                  AS `subcategory_id`,
                `product`.`brand_id`                        AS `brand_id`,
                `product`.`images`                          AS `images`,
                `product`.`barcode`                         AS `barcode`,
                `product`.`enabled`                         AS `enabled`,
                `product`.`status`                          AS `status`,
                `product`.`created_at`                      AS `created_at`,
                `product`.`updated_at`                      AS `updated_at`,
                `price`.`price`                             AS `price`,
                `price`.`currency_id`                       AS `currency_id`,
                `currency`.`code`                           AS `currency`,
                `sivigefu_core_sivir`.`category`.`label`    AS `category`,
                `stock`.`quantity`                          AS `quantity`,
                `stock`.`measurement_id`                    AS `measurement_id`,
                `sivigefu_core_sivir`.`measurement`.`label` AS `measurement`
from (((((`sivigefu_core_sivir`.`sivir_products` `product` join `sivigefu_core_sivir`.`sivir_products_price` `price`) join `sivigefu_core`.`global_currency` `currency`) join `sivigefu_core_sivir`.`sivir_catalog_category` `category`) join `sivigefu_core_sivir`.`sivir_products_stock` `stock`)
         join `sivigefu_core_sivir`.`sivir_catalog_measurement` `measurement`)
where ((`product`.`product_kind` <> 'IAF') and (`product`.`relative` = `price`.`product_id`) and
       (`product`.`relative` = `stock`.`product_id`) and (`price`.`currency_id` = `currency`.`codigoClasificador`) and
       (`product`.`category_id` = `sivigefu_core_sivir`.`category`.`value`) and
       (`product`.`global_branch_office_id` = `sivigefu_core_sivir`.`category`.`global_branch_office_id`) and
       (`stock`.`measurement_id` = `sivigefu_core_sivir`.`measurement`.`value`) and
       (`product`.`global_branch_office_id` = `sivigefu_core_sivir`.`measurement`.`global_branch_office_id`))

create view `sivir_products_list_homologated` as
select `product`.`relative`                AS `relative`,
       `product`.`users_sid`               AS `users_sid`,
       `product`.`global_branch_office_id` AS `global_branch_office_id`,
       `product`.`product_kind`            AS `product_kind`,
       `product`.`fullname`                AS `fullname`,
       `product`.`description`             AS `description`,
       `product`.`code`                    AS `code`,
       `product`.`category_id`             AS `category_id`,
       `product`.`subcategory_id`          AS `subcategory_id`,
       `product`.`brand_id`                AS `brand_id`,
       `product`.`images`                  AS `images`,
       `product`.`barcode`                 AS `barcode`,
       `product`.`enabled`                 AS `enabled`,
       `product`.`status`                  AS `status`,
       `product`.`created_at`              AS `created_at`,
       `product`.`updated_at`              AS `updated_at`,
       `price`.`price`                     AS `price`,
       `price`.`currency_id`               AS `currency_id`,
       `currency`.`code`                   AS `currency`,
       `category`.`label`                  AS `category`,
       `stock`.`quantity`                  AS `quantity`,
       `stock`.`measurement_id`            AS `measurement_id`,
       `measurement`.`label`               AS `measurement`,
       `approved`.`sincode_id`             AS `sincode_id`,
       `approved`.`sin_code`               AS `sin_code`
from ((((((`sivigefu_core_sivir`.`sivir_products` `product` join `sivigefu_core_sivir`.`sivir_products_price` `price`) join `sivigefu_core`.`global_currency` `currency`) join `sivigefu_core_sivir`.`sivir_catalog_items` `category`) join `sivigefu_core_sivir`.`sivir_products_stock` `stock`) join `sivigefu_core_sivir`.`sivir_catalog_items` `measurement`)
         join `sivigefu_core_sivir`.`sivir_products_code_approved` `approved`)
where ((`product`.`product_kind` <> 'IAF') and (convert(`product`.`relative` using utf8mb3) = `price`.`product_id`) and
       (`product`.`relative` = `stock`.`product_id`) and (`price`.`currency_id` = `currency`.`codigoClasificador`) and
       (`product`.`category_id` = `category`.`value`) and (`category`.`catalog_code` = 'CATEGORY') and
       (`category`.`catalog_code_dep` = 0) and (`category`.`catalog_id_dep` = 0) and
       (`category`.`global_branch_office_id` = convert(`product`.`global_branch_office_id` using utf8mb3)) and
       (`stock`.`measurement_id` = `measurement`.`value`) and (`measurement`.`catalog_code` = 'MEASUREMENT') and
       (`measurement`.`catalog_code_dep` = 0) and (`measurement`.`catalog_id_dep` = 0) and
       (`measurement`.`global_branch_office_id` = convert(`product`.`global_branch_office_id` using utf8mb3)) and
       (`approved`.`product_id` = convert(`product`.`relative` using utf8mb3)))

create view `sivir_products_list_not_homologated` as
select `product`.`relative`                AS `relative`,
       `product`.`users_sid`               AS `users_sid`,
       `product`.`global_branch_office_id` AS `global_branch_office_id`,
       `product`.`product_kind`            AS `product_kind`,
       `product`.`fullname`                AS `fullname`,
       `product`.`description`             AS `description`,
       `product`.`code`                    AS `code`,
       `product`.`category_id`             AS `category_id`,
       `product`.`subcategory_id`          AS `subcategory_id`,
       `product`.`brand_id`                AS `brand_id`,
       `product`.`images`                  AS `images`,
       `product`.`barcode`                 AS `barcode`,
       `product`.`enabled`                 AS `enabled`,
       `product`.`status`                  AS `status`,
       `product`.`created_at`              AS `created_at`,
       `product`.`updated_at`              AS `updated_at`,
       `price`.`price`                     AS `price`,
       `price`.`currency_id`               AS `currency_id`,
       `currency`.`code`                   AS `currency`,
       `category`.`label`                  AS `category`,
       `stock`.`quantity`                  AS `quantity`,
       `stock`.`measurement_id`            AS `measurement_id`,
       `measurement`.`label`               AS `measurement`
from (((((`sivigefu_core_sivir`.`sivir_products` `product` join `sivigefu_core_sivir`.`sivir_products_price` `price`) join `sivigefu_core`.`global_currency` `currency`) join `sivigefu_core_sivir`.`sivir_catalog_items` `category`) join `sivigefu_core_sivir`.`sivir_products_stock` `stock`)
         join `sivigefu_core_sivir`.`sivir_catalog_items` `measurement`)
where ((`product`.`product_kind` <> 'IAF') and (convert(`product`.`relative` using utf8mb3) = `price`.`product_id`) and
       (`product`.`relative` = `stock`.`product_id`) and (`price`.`currency_id` = `currency`.`codigoClasificador`) and
       (`product`.`category_id` = `category`.`value`) and (`category`.`catalog_code` = 'CATEGORY') and
       (`category`.`catalog_code_dep` = 0) and (`category`.`catalog_id_dep` = 0) and
       (`category`.`global_branch_office_id` = convert(`product`.`global_branch_office_id` using utf8mb3)) and
       (`stock`.`measurement_id` = `measurement`.`value`) and (`measurement`.`catalog_code` = 'MEASUREMENT') and
       (`measurement`.`catalog_code_dep` = 0) and (`measurement`.`catalog_id_dep` = 0) and
       (`measurement`.`global_branch_office_id` = convert(`product`.`global_branch_office_id` using utf8mb3)) and
       `product`.`relative` in (select `sivigefu_core_sivir`.`sivir_products_code_approved`.`product_id`
                                from `sivigefu_core_sivir`.`sivir_products_code_approved`
                                where (`sivigefu_core_sivir`.`sivir_products_code_approved`.`status` = 'A')) is false)

create view `sivir_catalog_measurement` as
select `category`.`id`                      AS `id`,
       `category`.`catalogs_id`             AS `catalogs_id`,
       `category`.`users_sid`               AS `users_sid`,
       `category`.`global_branch_office_id` AS `global_branch_office_id`,
       `category`.`value`                   AS `value`,
       `category`.`label`                   AS `label`,
       `category`.`lang`                    AS `lang`,
       `category`.`orden`                   AS `orden`,
       `category`.`catalog_code`            AS `catalog_code`,
       `category`.`catalog_code_dep`        AS `catalog_code_dep`,
       `category`.`catalog_id_dep`          AS `catalog_id_dep`,
       `category`.`description`             AS `description`,
       `category`.`fob`                     AS `fob`,
       `category`.`svg_image`               AS `svg_image`,
       `category`.`status`                  AS `status`,
       `category`.`created_at`              AS `created_at`,
       `category`.`updated_at`              AS `updated_at`
from `sivigefu_core_sivir`.`sivir_catalog_items` `category`
where ((`category`.`catalog_code` = 'MEASUREMENT') and (`category`.`catalog_code_dep` = 0) and
       (`category`.`catalog_id_dep` = 0) and (`category`.`status` = 'A'))
