Last active
July 18, 2022 05:29
-
-
Save iamsardorbek/05cca9079efe86c89076adc6afd1e18a to your computer and use it in GitHub Desktop.
Query for CRG problematic manufacture items
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with Manufacture_Items as | |
(select 'I' Item_Kind, | |
Mi.Company_Id, | |
Mi.Input_Item_Id Item_Id, | |
Mi.Manufacture_Id, | |
Mi.Product_Id, | |
Mi.Inventory_Kind, | |
Mi.Quantity, | |
null Amount | |
from Mfg_Manufacture_Inputs Mi | |
where Mi.Company_Id = 1081 | |
union all | |
select 'O' Item_Kind, | |
Mo.Company_Id, | |
Mo.Output_Item_Id Item_Id, | |
Mo.Manufacture_Id, | |
Mo.Product_Id, | |
Mo.Inventory_Kind, | |
Mo.Quantity, | |
Mo.Amount | |
from Mfg_Manufacture_Outputs Mo | |
where Mo.Company_Id = 1081 | |
) | |
select t.Filial_Id, | |
t.Input_Date, | |
t.Output_Date, | |
t.Currency_Id, | |
(select w.Name | |
from Mk_Currencies w | |
where w.Company_Id = Mi.Company_Id | |
and w.Currency_Id = t.Currency_Id) Currency_Name, | |
t.Status, | |
case t.Status | |
when 'D' then | |
'Черновик' | |
when 'W' then | |
'В ожидании' | |
when 'C' then | |
'Завершено' | |
end Status_Name, | |
Mi.Item_Kind, | |
Mi.Product_Id, | |
(select w.Name | |
from Mr_Products w | |
where w.Company_Id = Mi.Company_Id | |
and w.Product_Id = Mi.Product_Id) Item_Name, | |
Mi.Inventory_Kind, | |
case Mi.Inventory_Kind | |
when 'G' then | |
'Товар' | |
when 'M' then | |
'Сырье' | |
when 'P' then | |
'Продукция' | |
when 'E' then | |
'Рекламное оборудование' | |
end Inventory_Kind_Name, | |
Mi.Item_Id, | |
Mi.Quantity, | |
t.Manufacture_Id, | |
t.c_Amount Total_Manufacture_Amount, | |
Mi.Amount | |
from Mfg_Manufactures t | |
join Manufacture_Items Mi | |
on Mi.Company_Id = t.Company_Id | |
and Mi.Manufacture_Id = t.Manufacture_Id | |
where t.Company_Id = 1081 | |
and t.Status = 'C' | |
and exists (select * | |
from Manufacture_Items w | |
where w.Company_Id = t.Company_Id | |
and w.Item_Kind = 'O' | |
and w.Manufacture_Id = t.Manufacture_Id | |
and w.Amount = 0) | |
order by Filial_Id, Manufacture_Id desc, Input_Date desc, Mi.Item_Kind desc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment