DROP VIEW IF EXISTS `vn`.`saleFreight` ;
USE `vn`;
CREATE 
     OR REPLACE ALGORITHM = UNDEFINED 
    DEFINER = `root`@`%` 
    SQL SECURITY DEFINER
VIEW `saleFreight__` AS
    SELECT 
        `s`.`ticketFk` AS `ticketFk`,
        `t`.`clientFk` AS `clientFk`,
        `t`.`routeFk` AS `routeFk`,
        `s`.`id` AS `saleFk`,
        `t`.`zoneFk` AS `zoneFk`,
        `t`.`companyFk` AS `companyFk`,
        `t`.`shipped` AS `shipped`,
        `t`.`zonePrice` AS `price`,
        ((((`s`.`quantity` * `r`.`cm3`) * `t`.`zonePrice`) * `i`.`compression`) / `cb`.`volume`) AS `freight`
    FROM
        ((((`vn`.`sale` `s`
        JOIN `vn`.`item` `i` ON ((`i`.`id` = `s`.`itemFk`)))
        JOIN `vn`.`ticket` `t` ON ((`t`.`id` = `s`.`ticketFk`)))
        JOIN `vn`.`packaging` `cb` ON ((`cb`.`id` = '94')))
        JOIN `bi`.`rotacion` `r` ON (((`r`.`Id_Article` = `s`.`itemFk`)
            AND (`r`.`warehouse_id` = `t`.`warehouseFk`))));
