Friday, July 28, 2017

Dynamics GP - Manufacturing - Order-MOPSOP Link-MO-Received-Invoice View

/****** Object:  View [dbo].[BI_Mfg_MOSOLink]    Script Date: 9/21/2017 3:42:01 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[BI_Mfg_MOSOLink]
AS
SELECT        SOPNUMBE, SOPTYPE, LNITMSEQ, CMPNTSEQ, MANUFACTUREORDER_I, ITEMNMBR, USERID, QtyProcess AS MOQty, QtyMatch AS QtyAllocatedToSO, InHouseDueDt, PromiseDate
FROM            (SELECT        SOPNUMBE, SOPTYPE, LNITMSEQ, CMPNTSEQ, MANUFACTUREORDER_I, ITEMNMBR, USERID, 0 AS QtyProcess, 0 AS QtyMatch, SOITEMDUEDATE_I AS InHouseDueDt,
                                                    SOITEMPROMISEDATE_I AS PromiseDate
                          FROM            dbo.IS030001
                          UNION
                          SELECT        SOPNUMBE, SOPTYPE, LNITMSEQ, CMPNTSEQ, MANUFACTUREORDER_I, ITEMNMBR, USERID, QTYProcess, QTYMATCH, SOITEMDUEDATE_I AS InHouseDueDt,
                                                   SOITEMPROMISEDATE_I AS PromiseDate
                          FROM            dbo.IS010001) AS MOSO
WHERE        (MANUFACTUREORDER_I > '')
GO
/****** Object:  View [dbo].[BI_SOP_Hist]    Script Date: 9/21/2017 3:42:01 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[BI_SOP_Hist]
AS
SELECT        TOP (100) PERCENT dbo.SOP30200.DOCID, dbo.SOP30200.ORIGNUMB, dbo.SOP30200.SOPNUMBE AS [SOP Number], dbo.SOP30200.DOCDATE AS [Document Date], dbo.SOP30200.GLPOSTDT AS [GL Post Date],
                          CASE WHEN sop30200.soptype = 4 THEN (sop30300.XTNDPRCE - SOP30300.TRDISAMT) * - 1 ELSE (sop30300.xtndprce - SOP30300.TRDISAMT) END AS Sales,
                         CASE WHEN sop30200.soptype = 4 THEN sop30300.EXTDCOST * - 1 ELSE sop30300.extdcost END AS Costs, CASE WHEN sop30200.soptype = 4 THEN sop30300.quantity * - 1 ELSE sop30300.quantity END AS Qty,
                          dbo.SOP30200.CUSTNMBR AS [Customer Number],
                         CASE WHEN sop30200.soptype = 1 THEN 'Quote' WHEN sop30200.soptype = 2 THEN 'Order' WHEN sop30200.soptype = 3 THEN 'Invoice' WHEN sop30200.soptype = 4 THEN 'Return' WHEN sop30200.soptype =
                          5 THEN 'BackOrder' WHEN sop30200.soptype = 6 THEN 'FulfilmentOrder' END AS [SOP Type], dbo.IV40400.ITMCLSDC AS [Item Class Description], dbo.IV40400.ITMCLSCD AS [Item Class Code],
                         dbo.RM00101.CUSTNAME AS [Customer Name], dbo.RM00101.CUSTCLAS AS [Customer Class], dbo.SOP30300.QTYBSUOM AS [Base Unit Of Measure],
                         (CASE WHEN sop30200.soptype = 4 THEN sop30300.quantity * - 1 ELSE sop30300.quantity END) * dbo.SOP30300.QTYBSUOM AS [Units Sold], dbo.SOP30300.STATE, dbo.SOP30300.PRSTADCD,
                         ISNULL(dbo.SOP30200.SLPRSNID, '(none)') AS [Salesperson ID], dbo.IV00101.USCATVLS_1, dbo.IV00101.USCATVLS_2, dbo.IV00101.USCATVLS_3, dbo.IV00101.ITEMNMBR AS [Item Number],
                         dbo.IV00101.ITEMDESC AS [Item Description], dbo.SOP30200.ShipToName, dbo.IV00101.USCATVLS_2 AS Category, dbo.SOP30300.UNITCOST, dbo.RM00101.CREATDDT, LEFT(dbo.SOP30300.ITEMNMBR, 2)
                         AS AB, dbo.SOP30300.UNITPRCE, dbo.RM00301.ZIP AS [Sales Person Department], dbo.RM00301.SLPRSNFN AS [Sales Person First Name], dbo.RM00301.SPRSNSLN AS [Sales Person Last Name],
                         YEAR(dbo.SOP30200.DOCDATE) AS DocYear, RIGHT('00' + CAST(MONTH(dbo.SOP30200.DOCDATE) AS VARCHAR), 2) AS DocMonth, CAST(YEAR(dbo.SOP30200.DOCDATE) AS VARCHAR)
                         + '-' + CAST(RIGHT('00' + CAST(MONTH(dbo.SOP30200.DOCDATE) AS VARCHAR), 2) AS VARCHAR) AS DocYrMonth, RTRIM(dbo.SOP30200.CUSTNMBR) + ' | ' + RTRIM(dbo.SOP30200.CUSTNAME) AS CusIdName,
                         RTRIM(dbo.SOP30300.ITEMNMBR) + ' | ' + RTRIM(dbo.SOP30300.ITEMDESC) AS ItemIdName, dbo.SOP30300.UOFM, CASE LEFT(dbo.SOP30200.CUSTNMBR, 1) WHEN '2' THEN LEFT(rm00101.Custclas, 4)
                         WHEN '4' THEN 'MP' WHEN '6' THEN 'MABELS' WHEN '8' THEN 'FROZEN' WHEN 'E' THEN dbo.RM00201.CLASDSCR ELSE LEFT(dbo.SOP30200.CUSTNMBR, 1) END AS Div, ISNULL(dbo.RM00301.SALSTERR,
                         '(none)') AS Salsterr, RTRIM(dbo.RM00301.SLPRSNFN) + ' ' + RTRIM(dbo.RM00301.SPRSNSLN) AS SRNm, LEFT(dbo.RM00201.CLASDSCR, 3) AS CusClassDiv, dbo.RM00201.CLASDSCR, dbo.IV00101.MODIFDT,
                         DATEDIFF(d, dbo.IV00101.CREATDDT, GETDATE()) AS ItemAge, dbo.RM00101.COUNTRY, 0 AS BQty, CASE WHEN rm00101.CPRCSTNM = '' THEN rm00101.custname ELSE rm00101_1.custname END AS NatCusNm,
                          CASE WHEN rm00101.CPRCSTNM = '' THEN rm00101.custnmbr ELSE rm00101.cprcstnm END AS NatCus, CASE WHEN rm00101.CURNCYID NOT IN ('TTD', '') THEN 'Export' ELSE 'Local' END AS LocExpCus,
                         dbo.SOP30200.SOPTYPE, dbo.SOP30300.QTYTBAOR AS QtytoBackOrder, dbo.SOP30300.LNITMSEQ, dbo.SOP30300.ReqShipDate, dbo.SOP30300.QTYTOINV AS QtyToInvoice, dbo.SOP30200.NOTEINDX,
                         dbo.SOP30200.PCKSLPNO AS PackNo, dbo.SOP30200.PICTICNU AS PickNo
FROM            dbo.RM00101 INNER JOIN
                         dbo.SOP30200 INNER JOIN
                         dbo.SOP30300 ON dbo.SOP30200.SOPTYPE = dbo.SOP30300.SOPTYPE AND dbo.SOP30200.SOPNUMBE = dbo.SOP30300.SOPNUMBE ON
                         dbo.RM00101.CUSTNMBR = dbo.SOP30200.CUSTNMBR LEFT OUTER JOIN
                         dbo.IV40400 INNER JOIN
                         dbo.IV00101 ON dbo.IV40400.ITMCLSCD = dbo.IV00101.ITMCLSCD ON dbo.SOP30300.ITEMNMBR = dbo.IV00101.ITEMNMBR LEFT OUTER JOIN
                         dbo.RM00301 ON dbo.SOP30200.SLPRSNID = dbo.RM00301.SLPRSNID AND dbo.SOP30300.SLPRSNID = dbo.RM00301.SLPRSNID LEFT OUTER JOIN
                         dbo.RM00101 AS RM00101_1 ON dbo.RM00101.CPRCSTNM = RM00101_1.CUSTNMBR LEFT OUTER JOIN
                         dbo.RM00201 ON dbo.RM00101.CUSTCLAS = dbo.RM00201.CLASSID
WHERE        (dbo.SOP30200.VOIDSTTS = 0) AND (dbo.SOP30300.CMPNTSEQ = 0)
ORDER BY [GL Post Date] DESC
GO
/****** Object:  View [dbo].[BI_SOP_Open]    Script Date: 9/21/2017 3:42:01 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[BI_SOP_Open]
AS
SELECT        TOP (100) PERCENT dbo.SOP10100.DOCID, dbo.SOP10100.ORIGNUMB, dbo.SOP10100.SOPNUMBE AS [SOP Number], dbo.SOP10100.DOCDATE AS [Document Date], dbo.SOP10100.GLPOSTDT AS [GL Post Date],
                          CASE WHEN SOP10100.soptype = 4 THEN (SOP10200.XTNDPRCE - SOP10200.TRDISAMT) * - 1 ELSE (SOP10200.xtndprce - SOP10200.TRDISAMT) END AS Sales,
                         CASE WHEN SOP10100.soptype = 4 THEN SOP10200.EXTDCOST * - 1 ELSE SOP10200.extdcost END AS Costs,
                         CASE WHEN SOP10100.soptype = 4 THEN SOP10200.quantity * - 1 ELSE SOP10200.quantity END AS Qty, dbo.SOP10100.CUSTNMBR AS [Customer Number],
                         CASE WHEN SOP10100.soptype = 1 THEN 'Quote' WHEN SOP10100.soptype = 2 THEN 'Order' WHEN SOP10100.soptype = 3 THEN 'Invoice' WHEN SOP10100.soptype = 4 THEN 'Return' WHEN SOP10100.soptype
                          = 5 THEN 'BackOrder' WHEN SOP10100.soptype = 6 THEN 'FulfilmentOrder' END AS [SOP Type], dbo.IV40400.ITMCLSDC AS [Item Class Description], dbo.IV40400.ITMCLSCD AS [Item Class Code],
                         dbo.RM00101.CUSTNAME AS [Customer Name], dbo.RM00101.CUSTCLAS AS [Customer Class], dbo.SOP10200.QTYBSUOM AS [Base Unit Of Measure],
                         (CASE WHEN SOP10100.soptype = 4 THEN SOP10200.quantity * - 1 ELSE SOP10200.quantity END) * dbo.SOP10200.QTYBSUOM AS [Units Sold], dbo.SOP10200.STATE, dbo.SOP10200.PRSTADCD,
                         ISNULL(dbo.SOP10100.SLPRSNID, '(none)') AS [Salesperson ID], dbo.IV00101.USCATVLS_1, dbo.IV00101.USCATVLS_2, dbo.IV00101.USCATVLS_3, dbo.IV00101.ITEMNMBR AS [Item Number],
                         dbo.IV00101.ITEMDESC AS [Item Description], dbo.SOP10100.ShipToName, dbo.IV00101.USCATVLS_2 AS Category, dbo.SOP10200.UNITCOST, dbo.RM00101.CREATDDT, LEFT(dbo.SOP10200.ITEMNMBR, 2)
                         AS AB, dbo.SOP10200.UNITPRCE, dbo.RM00301.ZIP AS [Sales Person Department], dbo.RM00301.SLPRSNFN AS [Sales Person First Name], dbo.RM00301.SPRSNSLN AS [Sales Person Last Name],
                         YEAR(dbo.SOP10100.DOCDATE) AS DocYear, RIGHT('00' + CAST(MONTH(dbo.SOP10100.DOCDATE) AS VARCHAR), 2) AS DocMonth, CAST(YEAR(dbo.SOP10100.DOCDATE) AS VARCHAR)
                         + '-' + CAST(RIGHT('00' + CAST(MONTH(dbo.SOP10100.DOCDATE) AS VARCHAR), 2) AS VARCHAR) AS DocYrMonth, RTRIM(dbo.SOP10100.CUSTNMBR) + ' | ' + RTRIM(dbo.SOP10100.CUSTNAME) AS CusIdName,
                         RTRIM(dbo.SOP10200.ITEMNMBR) + ' | ' + RTRIM(dbo.SOP10200.ITEMDESC) AS ItemIdName, dbo.SOP10200.UOFM, CASE LEFT(dbo.SOP10100.CUSTNMBR, 1) WHEN '2' THEN LEFT(rm00101.Custclas, 4)
                         WHEN '4' THEN 'MP' WHEN '6' THEN 'MABELS' WHEN '8' THEN 'FROZEN' WHEN 'E' THEN dbo.RM00201.CLASDSCR ELSE LEFT(dbo.SOP10100.CUSTNMBR, 1) END AS Div, ISNULL(dbo.RM00301.SALSTERR,
                         '(none)') AS Salsterr, RTRIM(dbo.RM00301.SLPRSNFN) + ' ' + RTRIM(dbo.RM00301.SPRSNSLN) AS SRNm, LEFT(dbo.RM00201.CLASDSCR, 3) AS CusClassDiv, dbo.RM00201.CLASDSCR, dbo.IV00101.MODIFDT,
                         DATEDIFF(d, dbo.IV00101.CREATDDT, GETDATE()) AS ItemAge, dbo.RM00101.COUNTRY, 0 AS BQty, CASE WHEN rm00101.CPRCSTNM = '' THEN rm00101.custname ELSE rm00101_1.custname END AS NatCusNm,
                          CASE WHEN rm00101.CPRCSTNM = '' THEN rm00101.custnmbr ELSE rm00101.cprcstnm END AS NatCus, CASE WHEN rm00101.CURNCYID NOT IN ('TTD', '') THEN 'Export' ELSE 'Local' END AS LocExpCus,
                         dbo.SOP10100.SOPTYPE, dbo.SOP10200.QTYTBAOR AS QtytoBackOrder, dbo.SOP10200.LNITMSEQ, dbo.SOP10200.ReqShipDate, dbo.SOP10200.QTYTOINV AS QtyToInvoice, dbo.SOP10100.NOTEINDX,
                         dbo.SOP10100.PCKSLPNO AS PackNo, dbo.SOP10100.PICTICNU AS PickNo
FROM            dbo.RM00101 INNER JOIN
                         dbo.SOP10100 INNER JOIN
                         dbo.SOP10200 ON dbo.SOP10100.SOPTYPE = dbo.SOP10200.SOPTYPE AND dbo.SOP10100.SOPNUMBE = dbo.SOP10200.SOPNUMBE ON
                         dbo.RM00101.CUSTNMBR = dbo.SOP10100.CUSTNMBR LEFT OUTER JOIN
                         dbo.IV40400 INNER JOIN
                         dbo.IV00101 ON dbo.IV40400.ITMCLSCD = dbo.IV00101.ITMCLSCD ON dbo.SOP10200.ITEMNMBR = dbo.IV00101.ITEMNMBR LEFT OUTER JOIN
                         dbo.RM00301 ON dbo.SOP10100.SLPRSNID = dbo.RM00301.SLPRSNID AND dbo.SOP10200.SLPRSNID = dbo.RM00301.SLPRSNID LEFT OUTER JOIN
                         dbo.RM00101 AS RM00101_1 ON dbo.RM00101.CPRCSTNM = RM00101_1.CUSTNMBR LEFT OUTER JOIN
                         dbo.RM00201 ON dbo.RM00101.CUSTCLAS = dbo.RM00201.CLASSID
WHERE        (dbo.SOP10100.VOIDSTTS = 0) AND (dbo.SOP10200.CMPNTSEQ = 0)
ORDER BY [GL Post Date] DESC
GO
/****** Object:  View [dbo].[BI_SOP_ALLSOP]    Script Date: 9/21/2017 3:42:01 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[BI_SOP_ALLSOP]
AS
SELECT        ALLSOP.DOCID, ALLSOP.ORIGNUMB, ALLSOP.[SOP Number], ALLSOP.[Document Date], ALLSOP.[GL Post Date], ALLSOP.Sales, ALLSOP.Costs, ALLSOP.Qty, ALLSOP.[Customer Number], ALLSOP.[SOP Type],
                         ALLSOP.[Item Class Description], ALLSOP.[Item Class Code], ALLSOP.[Customer Name], ALLSOP.[Customer Class], ALLSOP.[Base Unit Of Measure], ALLSOP.[Units Sold], ALLSOP.STATE, ALLSOP.PRSTADCD,
                         ALLSOP.[Salesperson ID], ALLSOP.USCATVLS_1, ALLSOP.USCATVLS_2, ALLSOP.USCATVLS_3, ALLSOP.[Item Number], ALLSOP.[Item Description], ALLSOP.ShipToName, ALLSOP.Category, ALLSOP.UNITCOST,
                         ALLSOP.CREATDDT, ALLSOP.AB, ALLSOP.UNITPRCE, ALLSOP.[Sales Person Department], ALLSOP.[Sales Person First Name], ALLSOP.[Sales Person Last Name], ALLSOP.DocYear, ALLSOP.DocMonth,
                         ALLSOP.DocYrMonth, ALLSOP.CusIdName, ALLSOP.ItemIdName, ALLSOP.UOFM, ALLSOP.Div, ALLSOP.Salsterr, ALLSOP.SRNm, ALLSOP.CusClassDiv, ALLSOP.CLASDSCR, ALLSOP.MODIFDT, ALLSOP.ItemAge,
                         ALLSOP.COUNTRY, ALLSOP.BQty, ALLSOP.NatCusNm, ALLSOP.NatCus, ALLSOP.LocExpCus, ALLSOP.SOPTYPE, ALLSOP.QtytoBackOrder, ALLSOP.LNITMSEQ, ALLSOP.ReqShipDate, ALLSOP.QtyToInvoice,
                         RTRIM(CAST(dbo.SY03900.TXTFIELD AS varchar)) AS SOPNote, dbo.SOP10106.USRDAT01, dbo.SOP10106.USRDAT02, dbo.SOP10106.USRTAB01, dbo.SOP10106.USRTAB09, dbo.SOP10106.USRTAB03,
                         dbo.SOP10106.USERDEF1, dbo.SOP10106.USERDEF2, dbo.SOP10106.USRDEF03, dbo.SOP10106.USRDEF04, dbo.SOP10106.USRDEF05, dbo.SOP10106.COMMENT_1, dbo.SOP10106.COMMENT_2,
                         dbo.SOP10106.COMMENT_3, dbo.SOP10106.COMMENT_4, dbo.SOP10106.CMMTTEXT, ALLSOP.PackNo AS PackingSlip, ALLSOP.PickNo AS PickTicket
FROM            (SELECT        DOCID, ORIGNUMB, [SOP Number], [Document Date], [GL Post Date], Sales, Costs, Qty, QtytoBackOrder, QtyToInvoice, [Customer Number], [SOP Type], [Item Class Description], [Item Class Code],
                                                    [Customer Name], [Customer Class], [Base Unit Of Measure], [Units Sold], STATE, PRSTADCD, [Salesperson ID], USCATVLS_1, USCATVLS_2, USCATVLS_3, LNITMSEQ, [Item Number],
                                                    [Item Description], ShipToName, Category, UNITCOST, CREATDDT, AB, UNITPRCE, [Sales Person Department], [Sales Person First Name], [Sales Person Last Name], DocYear, DocMonth,
                                                    DocYrMonth, CusIdName, ItemIdName, UOFM, Div, Salsterr, SRNm, CusClassDiv, CLASDSCR, MODIFDT, ItemAge, COUNTRY, BQty, NatCusNm, NatCus, LocExpCus, SOPTYPE, ReqShipDate,
                                                    NOTEINDX, PackNo, PickNo
                          FROM            dbo.BI_SOP_Open
                          UNION
                          SELECT        DOCID, ORIGNUMB, [SOP Number], [Document Date], [GL Post Date], Sales, Costs, Qty, QtytoBackOrder, QtyToInvoice, [Customer Number], [SOP Type], [Item Class Description], [Item Class Code],
                                                   [Customer Name], [Customer Class], [Base Unit Of Measure], [Units Sold], STATE, PRSTADCD, [Salesperson ID], USCATVLS_1, USCATVLS_2, USCATVLS_3, LNITMSEQ, [Item Number],
                                                   [Item Description], ShipToName, Category, UNITCOST, CREATDDT, AB, UNITPRCE, [Sales Person Department], [Sales Person First Name], [Sales Person Last Name], DocYear, DocMonth,
                                                   DocYrMonth, CusIdName, ItemIdName, UOFM, Div, Salsterr, SRNm, CusClassDiv, CLASDSCR, MODIFDT, ItemAge, COUNTRY, BQty, NatCusNm, NatCus, LocExpCus, SOPTYPE, ReqShipDate,
                                                   NOTEINDX, PackNo, PickNo
                          FROM            dbo.BI_SOP_Hist) AS ALLSOP LEFT OUTER JOIN
                         dbo.SOP10106 ON ALLSOP.SOPTYPE = dbo.SOP10106.SOPTYPE AND ALLSOP.[SOP Number] = dbo.SOP10106.SOPNUMBE LEFT OUTER JOIN
                         dbo.SY03900 ON ALLSOP.NOTEINDX = dbo.SY03900.NOTEINDX
GO
/****** Object:  View [dbo].[BI_Mfg_SO]    Script Date: 9/21/2017 3:42:01 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[BI_Mfg_SO]
AS
SELECT        dbo.BI_SOP_ALLSOP.SRNm, dbo.BI_SOP_ALLSOP.DOCID AS SODocID, dbo.BI_SOP_ALLSOP.ORIGNUMB AS SOOrigNum, dbo.BI_SOP_ALLSOP.[SOP Number] AS SODocNum,
                         dbo.BI_SOP_ALLSOP.[Document Date] AS SODate, dbo.BI_SOP_ALLSOP.Qty AS SOQty, dbo.BI_SOP_ALLSOP.[Item Number], dbo.BI_SOP_ALLSOP.[Item Description],
                         dbo.BI_SOP_ALLSOP.SOPTYPE AS SODocType, dbo.BI_SOP_ALLSOP.Sales AS SOSls, dbo.BI_SOP_ALLSOP.Costs AS SOCost, dbo.BI_SOP_ALLSOP.QtytoBackOrder, dbo.BI_SOP_ALLSOP.LNITMSEQ,
                         dbo.BI_SOP_ALLSOP.ReqShipDate AS SOReqShipDate, dbo.BI_SOP_ALLSOP.[Customer Number] AS SOCusNum, dbo.BI_SOP_ALLSOP.[Customer Name] AS SOCusName, dbo.BI_SOP_ALLSOP.QtyToInvoice,
                         dbo.BI_SOP_ALLSOP.SOPNote, dbo.BI_Mfg_MOSOLink.MANUFACTUREORDER_I, dbo.BI_SOP_ALLSOP.USERDEF1 AS SOUD1, dbo.BI_SOP_ALLSOP.USERDEF2 AS SOUD2,
                         dbo.BI_SOP_ALLSOP.USRDEF03 AS SOUD3, dbo.BI_SOP_ALLSOP.CMMTTEXT AS SOCMT
FROM            dbo.BI_SOP_ALLSOP INNER JOIN
                         dbo.BI_Mfg_MOSOLink ON dbo.BI_SOP_ALLSOP.[SOP Number] = dbo.BI_Mfg_MOSOLink.SOPNUMBE
WHERE        (dbo.BI_SOP_ALLSOP.SOPTYPE = 2)
GO
/****** Object:  View [dbo].[BI_Mfg_SI]    Script Date: 9/21/2017 3:42:01 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[BI_Mfg_SI]
AS
SELECT        DOCID AS SIDocID, ORIGNUMB AS SIOrigNum, [SOP Number] AS SIDocNum, SOPNote AS SINote, [Document Date] AS SIDocDate, Qty AS SIQty, [Item Number], [Item Description], SOPTYPE AS SIDocType,
                         Sales AS SISls, Costs AS SICost, LNITMSEQ, USERDEF1 AS SIUD1, USERDEF2 AS SIUD2, USRDEF03 AS SIUD3, CMMTTEXT AS SICMT, PackingSlip, PickTicket, PackingSlip AS DeliveryNote
FROM            dbo.BI_SOP_ALLSOP
WHERE        (SOPTYPE = 3) AND (Qty <> 0)
GO
/****** Object:  View [dbo].[BI_Mfg_MO]    Script Date: 9/21/2017 3:42:01 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[BI_Mfg_MO]
AS
SELECT        dbo.WO010032.MANUFACTUREORDER_I, dbo.WO010032.DSCRIPTN, dbo.WO010032.MANUFACTUREORDERST_I AS MOStatus, dbo.WO010032.ITEMNMBR, dbo.WO010032.ARCHIVED_MO_I,
                         dbo.WO010032.BOMCAT_I, dbo.WO010032.BOMNAME_I, dbo.WO010032.ROUTINGNAME_I, dbo.WO010032.ENDQTY_I, dbo.WO010032.STARTQTY_I, dbo.WO010032.STRTDATE, dbo.WO010032.STARTTIME_I,
                         dbo.WO010032.ENDDATE, dbo.WO010032.DRAWFROMSITE_I, dbo.WO010032.CHANGEDATE_I, dbo.WO010032.USERID, dbo.WO010032.SCHEDULEMETHOD_I, dbo.WO010032.PROJEMPLOYEEHRSSUM_I,
                         dbo.WO010032.PROJMACHINEHRSSUM_I, dbo.WO010032.MATPROJCOSTI_1, dbo.WO010032.MATPROJCOSTI_2, dbo.WO010032.MATFIXOHDPROJCOSTI_1, dbo.WO010032.MATFIXOHDPROJCOSTI_2,
                         dbo.WO010032.MATVAROHDPROJCOST_1, dbo.WO010032.MATVAROHDPROJCOST_2, dbo.WO010032.LABPROJCOSTI_1, dbo.WO010032.LABPROJCOSTI_2, dbo.WO010032.LABFIXOHDPROJCOSTI_1,
                         dbo.WO010032.LABFIXOHDPROJCOSTI_2, dbo.WO010032.LABVAROHDPROJCOSTI_1, dbo.WO010032.LABVAROHDPROJCOSTI_2, dbo.WO010032.MACHPROJCOSTI_1, dbo.WO010032.MACHPROJCOSTI_2,
                         dbo.WO010032.MACHFIXOHDPROJCOSTI_1, dbo.WO010032.MACHFIXOHDPROJCOSTI_2, dbo.WO010032.MACHVAROHDPROJCOSTI_1, dbo.WO010032.MACHVAROHDPROJCOSTI_2,
                         dbo.WO010032.POSTTOSITE_I, dbo.WO010032.LOTNUMBR, dbo.WO010032.SCHEDULINGPREFEREN_I, dbo.WO010032.PLANNAME_I, dbo.WO010032.ACTUALDEMAND_I,
                         dbo.WO010032.MANUFACTUREORDPRI_I, dbo.WO010032.Partial_Purge_Date, dbo.WO010032.NOTEINDX, dbo.WO010032.OUTSOURCED_I, dbo.WO010032.COMPCALCOPTION,
                         dbo.WO010032.COMPLETECLOSEDATE, dbo.WO010032.PSTGDATE, dbo.WO010032.PLNNDSPPLID, dbo.WO010032.PICKNUMBER, dbo.WO010032.QUICK_MO_I, dbo.WO010032.ROUTING_REVISION_LEVEL,
                         dbo.WO010032.BOM_REVISION_LEVEL, dbo.WO010032.DEX_ROW_ID, ISNULL(MORctQty.MOQtyRecvd, 0) AS MOQtyRecvd,
                         CASE WHEN MANUFACTUREORDERST_I = 1 THEN 'Quote,' WHEN MANUFACTUREORDERST_I = 2 THEN 'Open' WHEN MANUFACTUREORDERST_I = 3 THEN 'Released' WHEN MANUFACTUREORDERST_I = 4 THEN
                          'Hold' WHEN MANUFACTUREORDERST_I = 5 THEN 'Cancelled' WHEN MANUFACTUREORDERST_I = 6 THEN 'Complete' WHEN MANUFACTUREORDERST_I = 7 THEN 'Partial Receipt' WHEN MANUFACTUREORDERST_I
                          = 8 THEN 'Closed' ELSE 'Now Being Entered by ' + wo010032.userid END AS MOStatusDesc, dbo.MN010000.NOTETEXT_I AS MONote
FROM            dbo.WO010032 LEFT OUTER JOIN
                         dbo.MN010000 ON dbo.WO010032.NOTEINDX = dbo.MN010000.NOTEINDX LEFT OUTER JOIN
                             (SELECT        MANUFACTUREORDER_I, SUM(QTYRECVD) AS MOQtyRecvd
                               FROM            dbo.MOP1100
                               GROUP BY MANUFACTUREORDER_I
                               HAVING         (MANUFACTUREORDER_I > '')) AS MORctQty ON dbo.WO010032.MANUFACTUREORDER_I = MORctQty.MANUFACTUREORDER_I
WHERE        (dbo.WO010032.MANUFACTUREORDER_I > '')
GO
/****** Object:  View [dbo].[BI_Mfg_AllDocs]    Script Date: 9/21/2017 3:42:01 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[BI_Mfg_AllDocs]
AS
SELECT        TOP (100) PERCENT dbo.BI_Mfg_SO.SODocID, dbo.BI_Mfg_SO.SODocType, dbo.BI_Mfg_SI.SIDocID, dbo.BI_Mfg_SI.SIDocType, dbo.BI_Mfg_SO.SRNm, dbo.BI_Mfg_SO.SODocNum,
                         dbo.BI_Mfg_SO.SOPNote AS SONote, dbo.BI_Mfg_SO.SOReqShipDate, dbo.BI_Mfg_SO.SOCusNum, dbo.BI_Mfg_SO.SOCusName, dbo.BI_Mfg_SO.SOQty, dbo.BI_Mfg_SO.QtytoBackOrder,
                         dbo.BI_Mfg_SO.QtyToInvoice, ISNULL(dbo.BI_Mfg_MOSOLink.MANUFACTUREORDER_I, '') AS MODocNo, dbo.BI_Mfg_SI.SIDocNum, dbo.BI_Mfg_SI.SINote, dbo.BI_Mfg_SI.SIQty,
                         dbo.BI_Mfg_SO.LNITMSEQ AS SOLine, dbo.BI_Mfg_MOSOLink.QtyAllocatedToSO, dbo.BI_Mfg_MOSOLink.MOQty, dbo.BI_Mfg_MO.MOStatus, dbo.BI_Mfg_MO.MOQtyRecvd, dbo.BI_Mfg_MO.MOStatusDesc,
                         dbo.BI_Mfg_MO.MONote, dbo.BI_Mfg_MO.ITEMNMBR AS MOItem, dbo.BI_ItemMaster.ITEMDESC AS MOItemDesc, dbo.BI_Mfg_MOSOLink.InHouseDueDt, dbo.BI_Mfg_MOSOLink.PromiseDate,
                         dbo.BI_Mfg_MO.ENDDATE AS MOEndDate, dbo.BI_Mfg_MO.STRTDATE AS MOStartDate, dbo.BI_Mfg_MOSOLink.MOQty AS MOQtyRem, dbo.BI_Mfg_SI.SIDocDate, CASE WHEN siud1 IS NULL
                         THEN soud1 ELSE siud1 END AS MainSalesOrd, CASE WHEN siud2 IS NULL THEN soud2 ELSE siud2 END AS OrderedBy, CASE WHEN siud3 IS NULL THEN soud3 ELSE siud3 END AS TypeID,
                         CASE WHEN sicmt IS NULL THEN socmt ELSE sicmt END AS Comment, dbo.BI_Mfg_SI.PackingSlip, dbo.BI_Mfg_SI.PickTicket, dbo.BI_Mfg_SI.DeliveryNote, dbo.BI_Mfg_SO.SODate,
                         CASE WHEN SIDOCNUM IS NOT NULL THEN '7 In Dispatch' WHEN DeliveryNote IS NOT NULL THEN '8 Dispatched' ELSE CAST(mostatus AS varchar) + ' MO ' + mostatusdesc END AS ProcessStatus
FROM            dbo.BI_Mfg_SI RIGHT OUTER JOIN
                         dbo.BI_ItemMaster INNER JOIN
                         dbo.BI_Mfg_MO ON dbo.BI_ItemMaster.ITEMNMBR = dbo.BI_Mfg_MO.ITEMNMBR RIGHT OUTER JOIN
                         dbo.BI_Mfg_SO LEFT OUTER JOIN
                         dbo.BI_Mfg_MOSOLink ON dbo.BI_Mfg_SO.MANUFACTUREORDER_I = dbo.BI_Mfg_MOSOLink.MANUFACTUREORDER_I AND dbo.BI_Mfg_SO.SODocNum = dbo.BI_Mfg_MOSOLink.SOPNUMBE AND
                         dbo.BI_Mfg_SO.LNITMSEQ = dbo.BI_Mfg_MOSOLink.LNITMSEQ AND dbo.BI_Mfg_SO.[Item Number] = dbo.BI_Mfg_MOSOLink.ITEMNMBR ON
                         dbo.BI_Mfg_MO.ITEMNMBR = dbo.BI_Mfg_MOSOLink.ITEMNMBR AND dbo.BI_Mfg_MO.MANUFACTUREORDER_I = dbo.BI_Mfg_MOSOLink.MANUFACTUREORDER_I ON
                         dbo.BI_Mfg_SI.SIOrigNum = dbo.BI_Mfg_SO.SODocNum AND dbo.BI_Mfg_SI.[Item Number] = dbo.BI_Mfg_SO.[Item Number] AND dbo.BI_Mfg_SI.LNITMSEQ = dbo.BI_Mfg_SO.LNITMSEQ
WHERE        (ISNULL(dbo.BI_Mfg_MOSOLink.MANUFACTUREORDER_I, '') > '')
GO
/****** Object:  View [dbo].[BI_Mfg_Picklist]    Script Date: 9/21/2017 3:42:01 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[BI_Mfg_Picklist]
AS
SELECT        dbo.PK010033.ITEMNMBR AS RMNumber, dbo.BI_ItemMaster.ITEMDESC AS RMDescription, dbo.PK010033.SUGGESTEDQTY_I AS RMQty, dbo.BI_ItemMaster.BASEUOFM AS UofM, dbo.PK010033.ALTERNATE_I,
                         dbo.PK010033.QTY_BACKFLUSHED_I AS RMQtyAllocatedtoMO, dbo.BI_ItemQty_ByLoc.TotalQtyAvlbl, dbo.BI_ItemQty_ByLoc.MacoyaQtyAvlbl, dbo.BI_ItemQty_ByLoc.WIPQtyAvlbl,
                         dbo.BI_ItemQty_ByLoc.TotalOnOrd, dbo.BI_ItemMaster.ITMCLSCD AS ItemClass, dbo.BI_ItemMaster.USCATVLS_6 AS Origin, dbo.BI_Mfg_AllDocs.SODocID, dbo.BI_Mfg_AllDocs.SODocType,
                         dbo.BI_Mfg_AllDocs.SIDocID, dbo.BI_Mfg_AllDocs.SIDocType, dbo.BI_Mfg_AllDocs.SRNm, dbo.BI_Mfg_AllDocs.SODocNum, dbo.BI_Mfg_AllDocs.SONote, dbo.BI_Mfg_AllDocs.SOReqShipDate,
                         dbo.BI_Mfg_AllDocs.SOCusNum, dbo.BI_Mfg_AllDocs.SOCusName, dbo.BI_Mfg_AllDocs.SOQty, dbo.BI_Mfg_AllDocs.QtytoBackOrder, dbo.BI_Mfg_AllDocs.QtyToInvoice, RTRIM(dbo.BI_Mfg_AllDocs.MODocNo)
                         AS MODocNo, dbo.BI_Mfg_AllDocs.SIDocNum, dbo.BI_Mfg_AllDocs.SINote, dbo.BI_Mfg_AllDocs.SIQty, dbo.BI_Mfg_AllDocs.SOLine, dbo.BI_Mfg_AllDocs.QtyAllocatedToSO, dbo.BI_Mfg_AllDocs.MOQty,
                         dbo.BI_Mfg_AllDocs.MOStatus, dbo.BI_Mfg_AllDocs.MOQtyRecvd, dbo.BI_Mfg_AllDocs.MOStatusDesc, dbo.BI_Mfg_AllDocs.MONote, dbo.BI_Mfg_AllDocs.MOItem, dbo.BI_Mfg_AllDocs.MOItemDesc,
                         CASE WHEN dbo.PK010033.SUGGESTEDQTY_I - dbo.BI_ItemQty_ByLoc.TotalQtyAvlbl - dbo.BI_ItemQty_ByLoc.TotalOnOrd > 0 THEN dbo.PK010033.SUGGESTEDQTY_I - dbo.BI_ItemQty_ByLoc.TotalQtyAvlbl - dbo.BI_ItemQty_ByLoc.TotalOnOrd
                          ELSE 0 END AS SuggestedPurchaseQty, dbo.BI_Mfg_AllDocs.InHouseDueDt, dbo.BI_Mfg_AllDocs.PromiseDate, dbo.BI_Mfg_AllDocs.MOStartDate, dbo.BI_Mfg_AllDocs.MOEndDate,
                         dbo.BI_Mfg_AllDocs.MOQtyRem, CASE WHEN dbo.PK010033.SUGGESTEDQTY_I > dbo.BI_ItemQty_ByLoc.TotalQtyAvlbl THEN 'Insufficient Raw Materials' ELSE '' END AS RMCheck,
                         RTRIM(dbo.PK010033.ITEMNMBR) + ' | ' + RTRIM(dbo.BI_ItemMaster.ITEMDESC) AS RMItemLbl, dbo.BI_Mfg_AllDocs.MODocNo AS RlMODocNo
FROM            dbo.PK010033 LEFT OUTER JOIN
                         dbo.BI_Mfg_AllDocs ON dbo.PK010033.MANUFACTUREORDER_I = dbo.BI_Mfg_AllDocs.MODocNo LEFT OUTER JOIN
                         dbo.BI_ItemQty_ByLoc ON dbo.PK010033.ITEMNMBR = dbo.BI_ItemQty_ByLoc.ITEMNMBR LEFT OUTER JOIN
                         dbo.BI_ItemMaster ON dbo.PK010033.ITEMNMBR = dbo.BI_ItemMaster.ITEMNMBR
GO
/****** Object:  View [dbo].[BI_Mfg_WorkOrder]    Script Date: 9/21/2017 3:42:01 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[BI_Mfg_WorkOrder]
AS
SELECT        Origin, MOStatus, MOStatusDesc, MONote, RMNumber, RMDescription, RMQty, UofM, SODocNum, SONote, SOCusNum, SOCusName, SRNm, MODocNo, MOQtyRem, RMCheck, PromiseDate, MOStartDate,
                         MOEndDate, MOItem, MOItemDesc
FROM            dbo.BI_Mfg_Picklist
WHERE        (MOStatus IN (3, 7))
GO
/****** Object:  View [dbo].[BI_Mfg_MORcts]    Script Date: 9/21/2017 3:42:01 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[BI_Mfg_MORcts]
AS
SELECT        dbo.MOP1100.MANUFACTUREORDER_I AS MONum, dbo.WO010032.DSCRIPTN, dbo.MOP1100.MOPRCTNM, dbo.IV00101.ITEMNMBR, dbo.IV00101.ITEMDESC, dbo.MOP1100.DATERECD,
                         dbo.MOP1100.QTYRECVD, dbo.MOP1100.TO_SITE_I, dbo.MOP1100.USERID, dbo.MOP1100.RECEIPTCOSTSARRAY_10 AS BackflushCost, dbo.MOP1100.POSTED
FROM            dbo.IV00101 RIGHT OUTER JOIN
                         dbo.WO010032 ON dbo.IV00101.ITEMNMBR = dbo.WO010032.ITEMNMBR RIGHT OUTER JOIN
                         dbo.MOP1100 ON dbo.WO010032.MANUFACTUREORDER_I = dbo.MOP1100.MANUFACTUREORDER_I
GO

No comments:

Post a Comment