Declare @OrderBookingID bigint, @BuyerID int, @OrderFullNo varchar(150), @DepartmentNo varchar(255), @OrderReceivedDate date, @GarmentsItem int, @GarmentsQty int, @ShipmentDate date, @ReferenceMarchandiserID int, @BillingAccountID int, @SampleType int, @budApvDate datetime
if not exists(Select 1 from OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB. dbo.tblOrderBookingHead where OrderfullNo=@OrderNo)
BEGIN
Select top (1) @HeadID=H.HeadID, @buyerName=case when H.BookingType in(4,5) then C1.CompanyName else B.BuyerName end, @OrderFullNo=H.OrderNo, @BillAcc= C.CompanyName , @DepartmentNo=Department, @OrderReceivedDate=FabOrderDate, @GarmentsQty=isnull(A.AssortmentQty,0), @ShipmentDate=case when BookingType=1 then DATEADD(dd,2,FabOrderDate) else H.ShipDate end, @merchandiser=H.Merchandiser, @bookType=H.BookingType, @descrip=H.Description, @Season=H.Phase, @budApvDate=H.BudgetApproveDate
from tbl_OrderHead_Temp H inner join tbl_Buyer B on H.BuyerID=B.BuyerID left join tblCompany C on C.SlNo=H.BillingAccount left join(Select Head_ID, sum(AssortmentQty)AssortmentQty from tbl_Assortment_Qty where Revised=0 group by Head_ID
)A on H.HeadID=A.Head_ID left join tblCompany C1 on C1.SlNo=H.FSOrderBy
where H.OrderNo=@OrderNo and H.RevisedNo=0 order by Head_ID desc
if(@BillAcc is NULL)
Set @BillAcc=(Select top(1) ReportHead from(Select ReportHead, 0 SL from tblYarnDeliveryChallanHead
where BuyerName=@buyerName UNION ALL Select 'FLAMINGO FASHIONS LTD.', 1)A order by SL)
--CHECK BUYER
if exists(Select * from OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblBuyerList where BuyerFullName =@buyerName)
BEGIN
Set @BuyerID=(Select top(1) ID from OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblBuyerList where BuyerFullName =@buyerName)
END
Else
BEGIN
Insert into OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblBuyerList(BuyerShortName, BuyerFullName, Billing)
values(@buyerName, @buyerName, 'm')
Set @BuyerID=(Select top(1) ID from OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblBuyerList where BuyerFullName =@buyerName )
END
--CHECK GARMENTS ITEM
if (@bookType=2)
BEGIN
Set @SampleType=1
if exists(Select * from OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblGMTItem where Item =@descrip )
BEGIN
Set @GarmentsItem=(Select top(1) ID from OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblGMTItem where Item =@descrip)
END
Else
BEGIN
Insert into OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblGMTItem(Item)
values(@descrip)
Set @GarmentsItem=(Select top(1) ID from OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblGMTItem where Item =@descrip)
END
END
else if(@bookType=1 or @bookType=4)
BEGIN
Set @GarmentsItem=138
if exists(Select * from OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblSampleTypeList where SampleTypeName =@descrip )
BEGIN
Insert into OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblSampleTypeList(SampleTypeName)
values(@descrip)
Set @SampleType=(Select top(1) SampleTypeList from OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblSampleTypeList where SampleTypeName =@descrip)
END
END
else
BEGIN
Set @GarmentsItem=2457
Set @SampleType=1
END
--CHECK MERCHANDISER
if exists(Select * from OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblMerchandiserList where MerchandiserListName =@merchandiser)
BEGIN
Set @ReferenceMarchandiserID=(Select top(1) MerchandiserListID from OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblMerchandiserList where MerchandiserListName =@merchandiser)
END
Else
BEGIN
Insert into OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblMerchandiserList(MerchandiserListName, MerchandiserListSinID)
values(@merchandiser, '49')
Set @ReferenceMarchandiserID=(Select top(1) MerchandiserListID from OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblMerchandiserList where MerchandiserListName =@merchandiser)
END
--CHECK BILLING ACCOUNT
if exists(Select * from OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblBillingAC where BillingACName =@BillAcc)
BEGIN
Set @BillingAccountID=(Select top(1) BillingACID from OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblBillingAC where BillingACName =@BillAcc)
END
Else
BEGIN
Insert into OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblBillingAC(BillingACName, Company)
values(@BillAcc, 'DBL Group')
Set @BillingAccountID=(Select top(1) BillingACID from OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblBillingAC where BillingACName =@BillAcc)
END
Insert into OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblOrderBookingHead(BuyerID, OrderFullNo, OrderShortNo, OrderIndex, DepartmentNo, OrderReceivedDate, GarmentsItem, GarmentsQty, ShipmentDate, ReferenceMarchandiserID, ReferenceOrders ,BillingAccountID, OrderCurrentStatus, RevisedNo, SampleType, BudegtDates, Season, OrderType,OrderCustomerType)
values(@BuyerID, @OrderFullNo, @OrderFullNo, @OrderFullNo, @DepartmentNo, @OrderReceivedDate, @GarmentsItem, @GarmentsQty, @ShipmentDate, @ReferenceMarchandiserID, '', @BillingAccountID, '1', '0', isnull(@SampleType,1), @budApvDate, @Season, Case when @bookType in(1,4) then 'S' else NULL end,Case when @bookType in(1,2) then 'OWN' else 'FABRIC SELL' end)
Set @OrderBookingID=(Select top(1) OrderBookingID from OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblOrderBookingHead where OrderfullNo=@OrderNo)
--DETAIL SECTION
Declare @Color varchar(250), @FiberCons varchar(128), @fabricType varchar(50), @FabDia varchar(50), @Gsm varchar(50), @UseOfFabric varchar(128), @fldGryQty decimal(18,2),@fldFinishQty decimal(18,2), @SpecialNote varchar(512), @Remarks varchar(512), @UOM int, @LabDipStatus varchar(256), @fldStyleName varchar(128), @FabricGroup varchar(20), @FabricGroupID int, @fldStyleNo varchar(128),@JALDETID bigint, @orderRowNo int, @AOPOrderQty decimal(18,2),@PLMCode varchar(100),@PONo varchar(100),@HeadID_JAL bigint,@fldID_JAL varchar(50)
Declare @ColorID bigint, @YarnTypeID bigint, @FabricTypeID bigint, @FabricFormID bigint, @MeasureUnitID int
DECLARE @Data CURSOR
SET @Data = CURSOR FOR
Select
case when D.ProcessType LIKE '%AOP%' then ltrim(D.Color +' '+ ISNULL(D.ProcessType , ''))
ELSE D.Color END as Color
, ltrim(D.FiberCons)FiberCons,
ltrim(D.fabricType)fabricType, CASE WHEN D.FabricWidth IS NOT NULL THEN ( CASE WHEN dbo.getFirstNumeric(D.FabricWidth)=0 THEN REPLACE( D.FinishType,' ','"')
ELSE CONVERT(VARCHAR(50), (dbo.getFirstNumeric(D.FabricWidth))) +'"' + isnull(D.FinishType, '') END) ELSE '00' + '"' + 'Open' END AS FabDia,
ltrim(D.Gsm)Gsm, ltrim(isnull(D.UseOfFabric, ''))UseOfFabric, D.fldGryQty + isnull(D.GoldSealFabQty, 0) + isnull(D.labtestFabQty, 0)fldGryQty, D.fldFinishQty + isnull(D.GoldSealFabQty, 0) + isnull(D.labtestFabQty, 0)fldFinishQty, ltrim(isnull(D.fldSpecialNote, ''))SpecialNote,ltrim(isnull(D.Remarks, ''))Remarks,case when isnull(UOM,'') like '%YD%' then 7 else 5 end UOM, D.LabDipStatus, D.fldStyleName , case when fabricType like '%lycra%' or fabricType like '%l rib%' or fabricType like '%l s/j%' or fabricType like '%ls/j%' then 'LYCRA' when fabricType like '%rib%' then 'RIB' when fabricType like '%s/j%' then 'S/J'
when fabricType like '%FLEECE%' then 'FLEECE' when fabricType like '%WAFFLE%' then 'WAFFLE' when fabricType like '%TERRY%' then 'TERRY' when fabricType like '%BRUSH%' then 'BRUSH' when fabricType like '%INTERLOCK%' then 'PIQUE' else 'OTHERS'
END FabricGroup, case when fabricType like '%lycra%' or fabricType like '%l rib%' or fabricType like '%l s/j%' or fabricType like '%ls/j%' then 7 when fabricType like '%rib%' then 10 when fabricType like '%s/j%' then 11 when fabricType like '%FLEECE%' then 2 when fabricType like '%WAFFLE%' then 13 when fabricType like '%TERRY%' then 12 when fabricType like '%BRUSH%' then 1
when fabricType like '%INTERLOCK%' then 9 else 8 END FabricGroupID, ltrim( D.knitStatus) fldStyleNo, ltrim(D.fldrowid)fldrowid, ltrim(D.orderRowNo)orderRowNo, case when AOP = 1 then isnull(round((ConsumTion / 12) * AssortmentQty, 2), 0) else 0 end AOPOrderQty, ltrim(Fabric_Code)PLMCode,
(select top(1) PODetails from tbl_OrderHead_Temp where HeadID = @HeadID)PONo,Head_ID AS HeadID_JAL ,cast(D.Head_ID as varchar)+'?'+ cast(D.orderRowNo as varchar) fldID_JAL
from tbl_OrderDetails_Temp D where Head_ID = @HeadID and D.DeleteBy is null and D.RevisedNo = 0
OPEN @Data
FETCH NEXT FROM @Data INTO @Color, @FiberCons, @fabricType, @FabDia, @Gsm, @UseOfFabric, @fldGryQty, @fldFinishQty, @SpecialNote, @Remarks, @UOM, @LabDipStatus, @fldStyleName, @FabricGroup, @FabricGroupID, @fldStyleNo, @JALDETID, @orderRowNo, @AOPOrderQty, @PLMCode, @PONo, @HeadID_JAL, @fldID_JAL
WHILE @@FETCH_STATUS = 0
BEGIN
--CHECK COLOR
if exists(Select * from OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblColorList where ColorName = @Color)
BEGIN
Set @ColorID = (Select top(1) ColorID from OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblColorList where ColorName = @Color)
END
Else
BEGIN
Insert into OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblColorList(ColorName, ColorCode)
values(@Color, '')
Set @ColorID = (Select top(1) ColorID from OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblColorList where ColorName = @Color)
END
--CHECK YARN TYPE
if exists(Select * from OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblYarnTypeList where YarnTypeName = @FiberCons)
BEGIN
Set @YarnTypeID = (Select top(1) YarnTypeID from OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblYarnTypeList where YarnTypeName = @FiberCons)
END
Else
BEGIN
Insert into OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblYarnTypeList(YarnTypeName)
values(@FiberCons)
Set @YarnTypeID = (Select top(1) YarnTypeID from OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblYarnTypeList where YarnTypeName = @FiberCons)
END
--CHECK FABRIC TYPE
if exists(Select * from OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblFabricsTypeList where FabricTypeName = @fabricType)
BEGIN
Set @FabricTypeID = (Select top(1) FabricTypeID from OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblFabricsTypeList where FabricTypeName = @fabricType)
END
Else
BEGIN
Insert into OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblFabricsTypeList(FabricTypeName, FabricTypeGroup, FabricTypeDesc, FabricType, FabricTypeGroupID)
values(@fabricType, @FabricGroup, @fabricType, @FabricGroup, @FabricGroupID)
Set @FabricTypeID = (Select top(1) FabricTypeID from OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblFabricsTypeList where FabricTypeName = @fabricType)
END
--CHECK FABRIC FORM
if exists(Select * from OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblFabricFormList where FabricFormName =case when len(@UseOfFabric) = 0 then '-' else @UseOfFabric end)
BEGIN
Set @FabricFormID = (Select top(1) FabricFormID from OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblFabricFormList where FabricFormName =case when len(@UseOfFabric) = 0 then '-' else @UseOfFabric end)
END
Else
BEGIN
Insert into OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblFabricFormList(FabricFormName)
values(@UseOfFabric)
Set @FabricFormID = (Select top(1) FabricFormID from OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblFabricFormList where FabricFormName = @UseOfFabric)
END
--INSERT DETAIL ROW
INSERT into OpenDataSource('SQLOLEDB','Data Source=192.168.153.208;User ID=sa;Password=123').ProjectInfoDB.dbo.tblOrderBookingDetailBody(OrderBookingID, ColorID, YarnTypeID, FabricTypeID, FabricDia, FabricGSM, FabricFormID, KnittingOrderQty, DyeingOrderQty, MeasureUnitID, GreyOthersQty, FinshOthersQty, Sec_MeasureUnitID, SpecialNote, LabDip, Remarks, StyleName, StyleNo, BookingDetailsID_JAL, InsertedBy, orderRowNo, AOPOrderQty, PLMCode,PONo,HeadID_JAL,fldID_JAL)
values(@OrderBookingID, @ColorID, @YarnTypeID, @FabricTypeID, @FabDia, @Gsm, @FabricFormID, @fldGryQty, @fldFinishQty, @UOM, 0, 0, '7', @SpecialNote, @LabDipStatus, @Remarks, @fldStyleName, @fldStyleNo, @JALDETID, 'MIS', @orderRowNo, @AOPOrderQty, @PLMCode, @PONo, @HeadID_JAL, @fldID_JAL)
--Select @OrderBookingID, @ColorID, @YarnTypeID, @FabricTypeID, @FabDia, @Gsm, @FabricFormID, @fldGryQty, @fldFinishQty, @UOM, 0, 0, '7', @SpecialNote, @LabDipStatus, @Remarks, @fldStyleName,,@JALDETID,'MIS'
FETCH NEXT FROM @Data INTO @Color, @FiberCons, @fabricType, @FabDia, @Gsm, @UseOfFabric, @fldGryQty, @fldFinishQty, @SpecialNote, @Remarks, @UOM, @LabDipStatus, @fldStyleName, @FabricGroup, @FabricGroupID, @fldStyleNo, @JALDETID, @orderRowNo, @AOPOrderQty,@PLMCode, @PONo, @HeadID_JAL, @fldID_JAL
END
END
No comments:
Post a Comment
I am Safiqul Islam Tuhin