DECLARE @ZoneId int = (select ZoneID from tbZone with (nolock) where [Zone] = 'Food Donations Pilot')


-- 1. Biscuit, Plain
IF NOT EXISTS(SELECT 1 FROM tbFoodDonationItem fdi INNER JOIN tbSalesItem si ON si.SalesItemID = fdi.SalesItemID WHERE si.ItemCode = '10010' AND fdi.ZoneID = @ZoneId)
BEGIN
   INSERT INTO [dbo].[tbFoodDonationItem] ([ItemID], [SalesItemID], [DonationUomId], [WasteUomId], [ExportUomId], [DonationToWaste], [DonationToExport], [SortOrder], [ZoneId])
   SELECT NULL, SalesItemID, 1, 1, 1, 1, 1, 0, @ZoneId FROM tbSalesItem WITH (NOLOCK) WHERE ItemCode = '10010'
END

-- 2. Bacon 
IF NOT EXISTS(SELECT 1 FROM tbFoodDonationItem fdi INNER JOIN tbItem i ON i.ItemID = fdi.ItemID WHERE i.ItemCode = '11561' AND fdi.ZoneID = @ZoneId)
BEGIN
   INSERT INTO [dbo].[tbFoodDonationItem] ([ItemID], [SalesItemID], [DonationUomId], [WasteUomId], [ExportUomId], [DonationToWaste], [DonationToExport], [SortOrder], [ZoneId])
   SELECT ItemID, NULL, 10, 1, 10, 44.2478, 1, 0, @ZoneId FROM tbItem WITH (NOLOCK) WHERE ItemCode = '11561'
END

-- 3. Bagel, Plain
IF NOT EXISTS(SELECT 1 FROM tbFoodDonationItem fdi INNER JOIN tbSalesItem si ON si.SalesItemID = fdi.SalesItemID WHERE si.ItemCode = '10048' AND fdi.ZoneID = @ZoneId)
BEGIN
   INSERT INTO [dbo].[tbFoodDonationItem] ([ItemID], [SalesItemID], [DonationUomId], [WasteUomId], [ExportUomId], [DonationToWaste], [DonationToExport], [SortOrder], [ZoneId])
   SELECT NULL, SalesItemID, 1, 1, 1, 1, 1, 0, @ZoneId FROM tbSalesItem WITH (NOLOCK) WHERE ItemCode = '10048'
END

-- 4. Hash Browns
IF NOT EXISTS(SELECT 1 FROM tbFoodDonationItem fdi INNER JOIN tbItem i ON i.ItemID = fdi.ItemID WHERE i.ItemCode = '1261' AND fdi.ZoneID = @ZoneId)
BEGIN
   INSERT INTO [dbo].[tbFoodDonationItem] ([ItemID], [SalesItemID], [DonationUomId], [WasteUomId], [ExportUomId], [DonationToWaste], [DonationToExport], [SortOrder], [ZoneId])
   SELECT ItemID, NULL, 10, 10, 10, 1, 1, 0, @ZoneId FROM tbItem WITH (NOLOCK) WHERE ItemCode = '1261'
END


-- 5. Minis (per mini)

IF NOT EXISTS(SELECT 1 FROM tbFoodDonationItem WHERE SalesItemID = 10040)
BEGIN
   INSERT INTO [dbo].[tbFoodDonationItem] ([ItemID], [SalesItemID], [DonationUomId], [WasteUomId], [ExportUomId], [DonationToWaste], [DonationToExport], [SortOrder], [ZoneId])
   SELECT NULL, SalesItemID, 1, 1, 1, 1, 1, 0, @ZoneId FROM tbSalesItem WITH (NOLOCK) WHERE ItemCode = '10040'
END

-- 6.Parfait 
IF NOT EXISTS(SELECT 1 FROM tbFoodDonationItem fdi INNER JOIN tbSalesItem si ON si.SalesItemID = fdi.SalesItemID WHERE si.ItemCode = '30066' AND fdi.ZoneID = @ZoneId)
BEGIN
   INSERT INTO [dbo].[tbFoodDonationItem] ([ItemID], [SalesItemID], [DonationUomId], [WasteUomId], [ExportUomId], [DonationToWaste], [DonationToExport], [SortOrder], [ZoneId])
   SELECT NULL, SalesItemID, 1, 1, 1, 1, 1, 0, @ZoneId FROM tbSalesItem WITH (NOLOCK) WHERE ItemCode = '30066'
END

-- 7.Sausage 
IF NOT EXISTS(SELECT 1 FROM tbFoodDonationItem fdi INNER JOIN tbItem i ON i.ItemID = fdi.ItemID WHERE i.ItemCode = '1909' AND fdi.ZoneID = @ZoneId)
BEGIN
   INSERT INTO [dbo].[tbFoodDonationItem] ([ItemID], [SalesItemID], [DonationUomId], [WasteUomId], [ExportUomId], [DonationToWaste], [DonationToExport], [SortOrder], [ZoneId])
   SELECT ItemID, NULL, 1, 10, 1, 0.1124, 1, 0, @ZoneId FROM tbItem WITH (NOLOCK) WHERE ItemCode = '1909'
END


--8.Scrambled Eggs
IF NOT EXISTS(SELECT 1 FROM tbFoodDonationItem fdi INNER JOIN tbItem i ON i.ItemID = fdi.ItemID WHERE i.ItemCode = '69' AND fdi.ZoneID = @ZoneId)
BEGIN
   INSERT INTO [dbo].[tbFoodDonationItem] ([ItemID], [SalesItemID], [DonationUomId], [WasteUomId], [ExportUomId], [DonationToWaste], [DonationToExport], [SortOrder], [ZoneId])
   SELECT ItemID, NULL, 10, 173, 10, 16, 1, 0, @ZoneId FROM tbItem WITH (NOLOCK) WHERE ItemCode = '69'
END

-- 9.English Muffins
IF NOT EXISTS(SELECT 1 FROM tbFoodDonationItem fdi INNER JOIN tbItem i ON i.ItemID = fdi.ItemID WHERE i.ItemCode = '9641' AND fdi.ZoneID = @ZoneId)
BEGIN
   INSERT INTO [dbo].[tbFoodDonationItem] ([ItemID], [SalesItemID], [DonationUomId], [WasteUomId], [ExportUomId], [DonationToWaste], [DonationToExport], [SortOrder], [ZoneId])
   SELECT ItemID, NULL, 1, 1, 1, 1, 1, 0, @ZoneId FROM tbItem WITH (NOLOCK) WHERE ItemCode = '9641'
END

-- 10.Tortilla Shell
IF NOT EXISTS(SELECT 1 FROM tbFoodDonationItem fdi INNER JOIN tbItem i ON i.ItemID = fdi.ItemID WHERE i.ItemCode = '13141' AND fdi.ZoneID = @ZoneId)
BEGIN
   INSERT INTO [dbo].[tbFoodDonationItem] ([ItemID], [SalesItemID], [DonationUomId], [WasteUomId], [ExportUomId], [DonationToWaste], [DonationToExport], [SortOrder], [ZoneId])
   SELECT ItemID, NULL, 1, 1, 1, 1, 1, 0, @ZoneId FROM tbItem WITH (NOLOCK) WHERE ItemCode = '13141'
END

-- 11.CFA Chicken
IF NOT EXISTS(SELECT 1 FROM tbFoodDonationItem fdi INNER JOIN tbItem i ON i.ItemID = fdi.ItemID WHERE i.ItemCode = '1' AND fdi.ZoneID = @ZoneId)
BEGIN
   INSERT INTO [dbo].[tbFoodDonationItem] ([ItemID], [SalesItemID], [DonationUomId], [WasteUomId], [ExportUomId], [DonationToWaste], [DonationToExport], [SortOrder], [ZoneId])
   SELECT ItemID, NULL, 10, 10, 10, 1, 1, 0, @ZoneId FROM tbItem WITH (NOLOCK) WHERE ItemCode = '1'
END

-- 12.Grilled Chicken
IF NOT EXISTS(SELECT 1 FROM tbFoodDonationItem fdi INNER JOIN tbItem i ON i.ItemID = fdi.ItemID WHERE i.ItemCode = '9884' AND fdi.ZoneID = @ZoneId)
BEGIN
   INSERT INTO [dbo].[tbFoodDonationItem] ([ItemID], [SalesItemID], [DonationUomId], [WasteUomId], [ExportUomId], [DonationToWaste], [DonationToExport], [SortOrder], [ZoneId])
   SELECT ItemID, NULL, 10, 10, 10, 1, 1, 0, @ZoneId FROM tbItem WITH (NOLOCK) WHERE ItemCode = '9884'
END

-- 13.Spicy Chicken 
IF NOT EXISTS(SELECT 1 FROM tbFoodDonationItem fdi INNER JOIN tbItem i ON i.ItemID = fdi.ItemID WHERE i.ItemCode = '3581' AND fdi.ZoneID = @ZoneId)
BEGIN
   INSERT INTO [dbo].[tbFoodDonationItem] ([ItemID], [SalesItemID], [DonationUomId], [WasteUomId], [ExportUomId], [DonationToWaste], [DonationToExport], [SortOrder], [ZoneId])
   SELECT ItemID, NULL, 10, 10, 10, 1, 1, 0, @ZoneId FROM tbItem WITH (NOLOCK) WHERE ItemCode = '3581'
END


-- 14.Salad - Cobb 
IF NOT EXISTS(SELECT 1 FROM tbFoodDonationItem fdi INNER JOIN tbSalesItem si ON si.SalesItemID = fdi.SalesItemID WHERE si.ItemCode = '150030' AND fdi.ZoneID = @ZoneId)
BEGIN
   INSERT INTO [dbo].[tbFoodDonationItem] ([ItemID], [SalesItemID], [DonationUomId], [WasteUomId], [ExportUomId], [DonationToWaste], [DonationToExport], [SortOrder], [ZoneId])
   SELECT NULL, SalesItemID, 1, 1, 1, 1, 1, 0, @ZoneId FROM tbSalesItem WITH (NOLOCK) WHERE ItemCode = '150030'
END

-- 15.Salad - Market 
IF NOT EXISTS(SELECT 1 FROM tbFoodDonationItem fdi INNER JOIN tbSalesItem si ON si.SalesItemID = fdi.SalesItemID WHERE si.ItemCode = '150022' AND fdi.ZoneID = @ZoneId)
BEGIN
   INSERT INTO [dbo].[tbFoodDonationItem] ([ItemID], [SalesItemID], [DonationUomId], [WasteUomId], [ExportUomId], [DonationToWaste], [DonationToExport], [SortOrder], [ZoneId])
   SELECT NULL, SalesItemID, 1, 1, 1, 1, 1, 0, @ZoneId FROM tbSalesItem WITH (NOLOCK) WHERE ItemCode = '150022'
END

-- 16.Salad - Spicy Southwest
IF NOT EXISTS(SELECT 1 FROM tbFoodDonationItem fdi INNER JOIN tbSalesItem si ON si.SalesItemID = fdi.SalesItemID WHERE si.ItemCode = '150057' AND fdi.ZoneID = @ZoneId)
BEGIN
   INSERT INTO [dbo].[tbFoodDonationItem] ([ItemID], [SalesItemID], [DonationUomId], [WasteUomId], [ExportUomId], [DonationToWaste], [DonationToExport], [SortOrder], [ZoneId])
   SELECT NULL, SalesItemID, 1, 1, 1, 1, 1, 0, @ZoneId FROM tbSalesItem WITH (NOLOCK) WHERE ItemCode = '150057'
END

-- 17.Side Salad 
IF NOT EXISTS(SELECT 1 FROM tbFoodDonationItem fdi INNER JOIN tbSalesItem si ON si.SalesItemID = fdi.SalesItemID WHERE si.ItemCode = '4430' AND fdi.ZoneID = @ZoneId)
BEGIN
   INSERT INTO [dbo].[tbFoodDonationItem] ([ItemID], [SalesItemID], [DonationUomId], [WasteUomId], [ExportUomId], [DonationToWaste], [DonationToExport], [SortOrder], [ZoneId])
   SELECT NULL, SalesItemID, 1, 1, 1, 1, 1, 0, @ZoneId FROM tbSalesItem WITH (NOLOCK) WHERE ItemCode = '4430'
END

-- 18.Chicken Soup, Large
IF NOT EXISTS(SELECT 1 FROM tbFoodDonationItem fdi INNER JOIN tbItem i ON i.ItemID = fdi.ItemID WHERE i.ItemCode = '11981' AND fdi.ZoneID = @ZoneId)
BEGIN
   INSERT INTO [dbo].[tbFoodDonationItem] ([ItemID], [SalesItemID], [DonationUomId], [WasteUomId], [ExportUomId], [DonationToWaste], [DonationToExport], [SortOrder], [ZoneId])
   SELECT ItemID, NULL, 10, 173, 10, 16, 1, 0, @ZoneId FROM tbItem WITH (NOLOCK) WHERE ItemCode = '11981'
END

-- 19.Chicken Tortilla Soup, Large 
IF NOT EXISTS(SELECT 1 FROM tbFoodDonationItem fdi INNER JOIN tbItem i ON i.ItemID = fdi.ItemID WHERE i.ItemCode = '7841' AND fdi.ZoneID = @ZoneId)
BEGIN
   INSERT INTO [dbo].[tbFoodDonationItem] ([ItemID], [SalesItemID], [DonationUomId], [WasteUomId], [ExportUomId], [DonationToWaste], [DonationToExport], [SortOrder], [ZoneId])
   SELECT ItemID, NULL, 10, 166, 10, 0.2, 1, 0, @ZoneId FROM tbItem WITH (NOLOCK) WHERE ItemCode = '7841'
END

-- 20.Wrap, Grilled Chicken
IF NOT EXISTS(SELECT 1 FROM tbFoodDonationItem fdi INNER JOIN tbSalesItem si ON si.SalesItemID = fdi.SalesItemID WHERE si.ItemCode = '200013' AND fdi.ZoneID = @ZoneId)
BEGIN
   INSERT INTO [dbo].[tbFoodDonationItem] ([ItemID], [SalesItemID], [DonationUomId], [WasteUomId], [ExportUomId], [DonationToWaste], [DonationToExport], [SortOrder], [ZoneId])
   SELECT NULL, SalesItemID, 1, 1, 1, 1, 1, 0, @ZoneId FROM tbSalesItem WITH (NOLOCK) WHERE ItemCode = '200013'
END

-- 21.Fruit - Sm 
IF NOT EXISTS(SELECT 1 FROM tbFoodDonationItem fdi INNER JOIN tbSalesItem si ON si.SalesItemID = fdi.SalesItemID WHERE si.ItemCode = '30084' AND fdi.ZoneID = @ZoneId)
BEGIN
   INSERT INTO [dbo].[tbFoodDonationItem] ([ItemID], [SalesItemID], [DonationUomId], [WasteUomId], [ExportUomId], [DonationToWaste], [DonationToExport], [SortOrder], [ZoneId])
   SELECT NULL, SalesItemID, 1, 1, 1, 1, 1, 0, @ZoneId FROM tbSalesItem WITH (NOLOCK) WHERE ItemCode = '30084'
END

-- 22.Fruit - Med 
IF NOT EXISTS(SELECT 1 FROM tbFoodDonationItem fdi INNER JOIN tbSalesItem si ON si.SalesItemID = fdi.SalesItemID WHERE si.ItemCode = '30085' AND fdi.ZoneID = @ZoneId)
BEGIN
   INSERT INTO [dbo].[tbFoodDonationItem] ([ItemID], [SalesItemID], [DonationUomId], [WasteUomId], [ExportUomId], [DonationToWaste], [DonationToExport], [SortOrder], [ZoneId])
   SELECT NULL, SalesItemID, 1, 1, 1, 1, 1, 0, @ZoneId FROM tbSalesItem WITH (NOLOCK) WHERE ItemCode = '30085'
END

-- 23.Fruit - Large
IF NOT EXISTS(SELECT 1 FROM tbFoodDonationItem fdi INNER JOIN tbSalesItem si ON si.SalesItemID = fdi.SalesItemID WHERE si.ItemCode = '30086' AND fdi.ZoneID = @ZoneId)
BEGIN
   INSERT INTO [dbo].[tbFoodDonationItem] ([ItemID], [SalesItemID], [DonationUomId], [WasteUomId], [ExportUomId], [DonationToWaste], [DonationToExport], [SortOrder], [ZoneId])
   SELECT NULL, SalesItemID, 1, 1, 1, 1, 1, 0, @ZoneId FROM tbSalesItem WITH (NOLOCK) WHERE ItemCode = '30086'
END

-- 24.Superfood Side, Small
IF NOT EXISTS(SELECT 1 FROM tbFoodDonationItem fdi INNER JOIN tbSalesItem si ON si.SalesItemID = fdi.SalesItemID WHERE si.ItemCode = '30067' AND fdi.ZoneID = @ZoneId)
BEGIN
   INSERT INTO [dbo].[tbFoodDonationItem] ([ItemID], [SalesItemID], [DonationUomId], [WasteUomId], [ExportUomId], [DonationToWaste], [DonationToExport], [SortOrder], [ZoneId])
   SELECT NULL, SalesItemID, 1, 1, 1, 1, 1, 0, @ZoneId FROM tbSalesItem WITH (NOLOCK) WHERE ItemCode = '30067'
END

-- 25.Superfood Side, Large 
IF NOT EXISTS(SELECT 1 FROM tbFoodDonationItem fdi INNER JOIN tbSalesItem si ON si.SalesItemID = fdi.SalesItemID WHERE si.ItemCode = '30068' AND fdi.ZoneID = @ZoneId)
BEGIN
   INSERT INTO [dbo].[tbFoodDonationItem] ([ItemID], [SalesItemID], [DonationUomId], [WasteUomId], [ExportUomId], [DonationToWaste], [DonationToExport], [SortOrder], [ZoneId])
   SELECT NULL, SalesItemID, 1, 1, 1, 1, 1, 0, @ZoneId FROM tbSalesItem WITH (NOLOCK) WHERE ItemCode = '30068'
END

-- 26.Waffle Fries
IF NOT EXISTS(SELECT 1 FROM tbFoodDonationItem fdi INNER JOIN tbItem i ON i.ItemID = fdi.ItemID WHERE i.ItemCode = '1241' AND fdi.ZoneID = @ZoneId)
BEGIN
   INSERT INTO [dbo].[tbFoodDonationItem] ([ItemID], [SalesItemID], [DonationUomId], [WasteUomId], [ExportUomId], [DonationToWaste], [DonationToExport], [SortOrder], [ZoneId])
   SELECT ItemID, NULL, 10, 10, 10, 1, 1, 0, @ZoneId FROM tbItem WITH (NOLOCK) WHERE ItemCode = '1241'
END

-- 27.Mac n Cheese
IF NOT EXISTS(SELECT 1 FROM tbFoodDonationItem fdi INNER JOIN tbSalesItem si ON si.SalesItemID = fdi.SalesItemID WHERE si.ItemCode = '30083' AND fdi.ZoneID = @ZoneId)
BEGIN
   INSERT INTO [dbo].[tbFoodDonationItem] ([ItemID], [SalesItemID], [DonationUomId], [WasteUomId], [ExportUomId], [DonationToWaste], [DonationToExport], [SortOrder], [ZoneId])
   SELECT NULL, SalesItemID, 10, 1, 10, 0.4, 1, 0, @ZoneId FROM tbSalesItem WITH (NOLOCK) WHERE ItemCode = '30083'
END

-- 28.Cookies
IF NOT EXISTS(SELECT 1 FROM tbFoodDonationItem fdi INNER JOIN tbItem i ON i.ItemID = fdi.ItemID WHERE i.ItemCode = '11961' AND fdi.ZoneID = @ZoneId)
BEGIN
   INSERT INTO [dbo].[tbFoodDonationItem] ([ItemID], [SalesItemID], [DonationUomId], [WasteUomId], [ExportUomId], [DonationToWaste], [DonationToExport], [SortOrder], [ZoneId])
   SELECT ItemID, NULL, 1, 1, 1, 1, 1, 0, @ZoneId FROM tbItem WITH (NOLOCK) WHERE ItemCode = '11961'
END


-- 29.Lemonade (Gal)
IF NOT EXISTS(SELECT 1 FROM tbFoodDonationItem fdi INNER JOIN tbSalesItem si ON si.SalesItemID = fdi.SalesItemID WHERE si.ItemCode = '120011' AND fdi.ZoneID = @ZoneId)
BEGIN
   INSERT INTO [dbo].[tbFoodDonationItem] ([ItemID], [SalesItemID], [DonationUomId], [WasteUomId], [ExportUomId], [DonationToWaste], [DonationToExport], [SortOrder], [ZoneId])
   SELECT NULL, SalesItemID, 8, 1, 8, 1, 1, 0, @ZoneId FROM tbSalesItem WITH (NOLOCK) WHERE ItemCode = '120011'
END

-- 30.Tea (Gal)
IF NOT EXISTS(SELECT 1 FROM tbFoodDonationItem fdi INNER JOIN tbSalesItem si ON si.SalesItemID = fdi.SalesItemID WHERE si.ItemCode = '120013' AND fdi.ZoneID = @ZoneId)
BEGIN
   INSERT INTO [dbo].[tbFoodDonationItem] ([ItemID], [SalesItemID], [DonationUomId], [WasteUomId], [ExportUomId], [DonationToWaste], [DonationToExport], [SortOrder], [ZoneId])
   SELECT NULL, SalesItemID, 8, 1, 8, 1, 1, 0, @ZoneId FROM tbSalesItem WITH (NOLOCK) WHERE ItemCode = '120013'
END

-- 31.Fish - Cod
IF NOT EXISTS(SELECT 1 FROM tbFoodDonationItem fdi INNER JOIN tbItem i ON i.ItemID = fdi.ItemID WHERE i.ItemCode = '6321' AND fdi.ZoneID = @ZoneId)
BEGIN
   INSERT INTO [dbo].[tbFoodDonationItem] ([ItemID], [SalesItemID], [DonationUomId], [WasteUomId], [ExportUomId], [DonationToWaste], [DonationToExport], [SortOrder], [ZoneId])
   SELECT ItemID, NULL, 10, 10, 10, 1, 1, 0, @ZoneId FROM tbItem WITH (NOLOCK) WHERE ItemCode = '6321'
END