salix/db/routines/vn2008/views/v_compres.sql

90 lines
2.7 KiB
SQL

CREATE OR REPLACE DEFINER=`root`@`localhost`
SQL SECURITY DEFINER
VIEW `vn2008`.`v_compres`
AS SELECT `TP`.`Id_Tipo` AS `Familia`,
`RN`.`id` AS `reino_id`,
`C`.`Id_Compra` AS `Id_Compra`,
`C`.`Id_Entrada` AS `Id_Entrada`,
`C`.`Id_Article` AS `Id_Article`,
`C`.`Cantidad` AS `Cantidad`,
`C`.`Costefijo` AS `Costefijo`,
`C`.`Portefijo` AS `Portefijo`,
`C`.`Novincular` AS `Novincular`,
`C`.`Etiquetas` AS `Etiquetas`,
`C`.`Packing` AS `Packing`,
`C`.`grouping` AS `grouping`,
`C`.`Comisionfija` AS `Comisionfija`,
`C`.`Embalajefijo` AS `Embalajefijo`,
`C`.`Id_Cubo` AS `Id_Cubo`,
`C`.`Tarifa1` AS `Tarifa1`,
`C`.`Tarifa2` AS `Tarifa2`,
`C`.`Tarifa3` AS `Tarifa3`,
`C`.`PVP` AS `PVP`,
`C`.`Vida` AS `Vida`,
`C`.`Id_Trabajador` AS `Id_Trabajador`,
`C`.`punteo` AS `punteo`,
`C`.`odbc_date` AS `odbc_date`,
`E`.`Inventario` AS `Inventario`,
`E`.`Id_Proveedor` AS `Id_Proveedor`,
`E`.`Fecha` AS `Fecha`,
`E`.`Confirmada` AS `Confirmada`,
`E`.`empresa_id` AS `empresa_id`,
`E`.`travel_id` AS `travel_id`,
`E`.`Pedida` AS `Pedida`,
`E`.`recibida_id` AS `recibida_id`,
`TR`.`id` AS `id`,
`TR`.`shipment` AS `shipment`,
`TR`.`landing` AS `landing`,
`TR`.`warehouse_id` AS `warehouse_id`,
`TR`.`warehouse_id_out` AS `warehouse_id_out`,
`TR`.`agency_id` AS `agency_id`,
`TR`.`ref` AS `ref`,
`TR`.`delivered` AS `delivered`,
`TR`.`received` AS `received`,
`A`.`Article` AS `Article`,
`A`.`Medida` AS `Medida`,
`A`.`Tallos` AS `Tallos`,
`C`.`caja` AS `caja`,
`A`.`Categoria` AS `Categoria`,
`A`.`id_origen` AS `id_origen`,
`TP`.`Id_Tipo` AS `Tipo`,
`A`.`tipo_id` AS `tipo_id`,
`A`.`Color` AS `Color`,
`A`.`Min` AS `Min`,
`C`.`Costefijo` + `C`.`Embalajefijo` + `C`.`Comisionfija` + `C`.`Portefijo` AS `Coste`,
`W_OUT`.`isFeedStock` AS `fuente`,
IF(
`cb`.`Volumen` > 0,
`cb`.`Volumen`,
`cb`.`X` * `cb`.`Y` * IF(`cb`.`Z` = 0, `A`.`Medida` + 10, `cb`.`Z`)
) * `C`.`Etiquetas` AS `cm3`,
`A`.`producer_id` AS `producer_id`
FROM (
(
(
(
(
(
(
(
`vn2008`.`Compres` `C`
JOIN `vn2008`.`Entradas` `E` ON(`C`.`Id_Entrada` = `E`.`Id_Entrada`)
)
JOIN `vn2008`.`travel` `TR` ON(`TR`.`id` = `E`.`travel_id`)
)
JOIN `vn`.`warehouse` `W_IN` ON(`W_IN`.`id` = `TR`.`warehouse_id`)
)
JOIN `vn`.`warehouse` `W_OUT` ON(`W_OUT`.`id` = `TR`.`warehouse_id_out`)
)
JOIN `vn2008`.`Articles` `A` ON(`C`.`Id_Article` = `A`.`Id_Article`)
)
JOIN `vn2008`.`Tipos` `TP` ON(`A`.`tipo_id` = `TP`.`tipo_id`)
)
JOIN `vn2008`.`reinos` `RN` ON(`RN`.`id` = `TP`.`reino_id`)
)
JOIN `vn2008`.`Cubos` `cb` ON(`cb`.`Id_Cubo` = `C`.`Id_Cubo`)
)
WHERE NOT `W_IN`.`isFeedStock`
AND NOT `E`.`Inventario`
AND NOT `TR`.`isRaid`