CREATE OR REPLACE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `vn`.`awbVolume` AS SELECT `t`.`awbFk` AS `awbFk`, `b`.`stickers` * `i`.`density` * IF( `p`.`volume` > 0, `p`.`volume`, `p`.`width` * `p`.`depth` * IF(`p`.`height` = 0, `i`.`size` + 10, `p`.`height`) ) / (`vc`.`aerealVolumetricDensity` * 1000) AS `volume`, `b`.`id` AS `buyFk` FROM ( ( ( ( ( ( `vn`.`buy` `b` JOIN `vn`.`item` `i` ON(`b`.`itemFk` = `i`.`id`) ) JOIN `vn`.`itemType` `it` ON(`i`.`typeFk` = `it`.`id`) ) JOIN `vn`.`packaging` `p` ON(`p`.`id` = `b`.`packagingFk`) ) JOIN `vn`.`entry` `e` ON(`b`.`entryFk` = `e`.`id`) ) JOIN `vn`.`travel` `t` ON(`t`.`id` = `e`.`travelFk`) ) JOIN `vn`.`volumeConfig` `vc` ) WHERE `t`.`shipped` > makedate(year(`util`.`VN_CURDATE`()) - 1, 1) AND t.awbFk