Created
July 19, 2022 05:49
-
-
Save iamsardorbek/4f73181e04f965ab326e8348bfe65490 to your computer and use it in GitHub Desktop.
MFGs with Input with 0 amount, >= 2 outputs
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 Input_Item_Amount as | |
(select case t.Coa_Id | |
when 101336 then | |
'M' | |
when 101356 then | |
'P' | |
when 101360 then | |
'G' | |
end Inventory_Kind, | |
k.Source_Id Manufacture_Id, | |
Mk_Util.Find_Ref_Id(t.Ref_Set, 1014) Product_Id, | |
sum(Mk_Util.Calc_Amount(i_Company_Id => t.Company_Id, | |
i_Filial_Id => t.Filial_Id, | |
i_From_Currency_Id => t.Currency_Id, | |
i_To_Currency_Id => (select w.Currency_Id | |
from Mfg_Manufactures w | |
where w.Company_Id = k.Company_Id | |
and w.Manufacture_Id = k.Source_Id), | |
i_Rate_Date => t.Trans_Date, | |
i_Amount => t.Amount)) Amount | |
from Mk_Ledger t | |
join Mk_Journals k | |
on k.Company_Id = t.Company_Id | |
and k.Journal_Id = t.Journal_Id | |
where t.Company_Id = 1081 | |
and t.Dc_Sign = -1 | |
and Mk_Util.Find_Ref_Id(t.Ref_Set, 1014) is not null | |
and k.Source_Table = 'MFG_MANUFACTURES' | |
group by t.Coa_Id, k.Source_Id, Mk_Util.Find_Ref_Id(t.Ref_Set, 1014)) | |
select t.Manufacture_Id | |
from Mfg_Manufactures t | |
where t.Company_Id = 1081 | |
and exists (select 1 | |
from Mfg_Manufacture_Outputs k | |
where k.Company_Id = t.Company_Id | |
and k.Manufacture_Id = t.Manufacture_Id | |
group by Manufacture_Id | |
having count(*) >= 2) | |
and exists (select 1 | |
from Mfg_Manufacture_Inputs k | |
where k.Company_Id = t.Company_Id | |
and k.Manufacture_Id = t.Manufacture_Id | |
and exists (select 1 | |
from Input_Item_Amount w | |
where w.Manufacture_Id = k.Manufacture_Id | |
and w.Inventory_Kind = k.Inventory_Kind | |
and w.Product_Id = k.Product_Id | |
and w.Amount = 0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment