-- =============================================
-- Author:		Anatoliy Pokus
-- Create date: 2026-03
-- Description:	Заполнение элемента накладной
-- =============================================
DROP PROCEDURE IF EXISTS stor.sp_fillinvoiceitem;
CREATE PROCEDURE stor.sp_fillinvoiceitem
(
	"InvoiceItem" uuid
)
    language plpgsql
as
$$
Begin 

	update STOR.T_INVOICE_ITEM ii
	set BillOfGoods = iiDonor.BillOfGoods, 
		PackageType = iiDonor.PackageType,
		TotalPackageType = iiDonor.PackageType,
		TotalApplicationCount = iiDonor.TotalApplicationCount,
		QuantityInPackage = iiDonor.QuantityInPackage
	from STOR.T_INVOICE_ITEM iiDonor
	where		iiDonor.ElementID = "InvoiceItem" 
			and ii.StorageInvoice = iiDonor.StorageInvoice 
			and ii.ElementID <> iiDonor.ElementID
			and SubString(ii.GTINSerialNumber, 3, 14) = SubString(iiDonor.GTINSerialNumber, 3, 14);

End;
$$;