CREATE VIEW VS4VACChart
AS 
SELECT VS4TACChart.*, VS4TACGroupSub.*, VS4TACGroup.*, VS4TACGroupSub_1.TAGsName AS VACCTAGsName, VS4TACGroupSub_1.TAGsName2 AS VACCTAGsName2
FROM VS4TACGroup INNER JOIN (VS4TACGroupSub INNER JOIN (VS4TACChart INNER JOIN VS4TACGroupSub AS VS4TACGroupSub_1 ON VS4TACChart.TACCPLTAGsCode=VS4TACGroupSub_1.TAGsCode) ON VS4TACGroupSub.TAGsCode=VS4TACChart.TACCTAGsCode) ON VS4TACGroup.TACGCode=VS4TACGroupSub.TAGsTACGCode
GO

CREATE VIEW VS4VACCPaperWork
AS 
SELECT VS4TACChart.*, VS4TGLTransMove.*, VS4TBranch.TBraCode, VS4TBranch.TBraName, VS4TBranch.TBraName2
FROM VS4TBranch RIGHT JOIN (VS4TACChart LEFT JOIN VS4TGLTransMove ON VS4TACChart.TACCCode = VS4TGLTransMove.TGTMTACCCode) ON VS4TBranch.TBraCode = VS4TGLTransMove.TGTMTBraCode
GO

CREATE VIEW VS4VACGroupSub
AS 
SELECT VS4TACGroupSub.*, VS4TACGroup.*
FROM VS4TACGroup INNER JOIN VS4TACGroupSub ON VS4TACGroup.TACGCode=VS4TACGroupSub.TAGsTACGCode
GO

CREATE VIEW VS4VAP
AS 
SELECT VS4TAP.*, VS4TAPType.*, VS4TBusinessType.*, VS4TCountry.*, VS4TState.*, VS4TAPGroup.TAPGName
FROM VS4TCountry RIGHT JOIN (VS4TBusinessType RIGHT JOIN (VS4TAPType INNER JOIN (VS4TAPGroup RIGHT JOIN (VS4TAP LEFT JOIN VS4TState ON VS4TAP.TAPNStaCode=VS4TState.TStaCode) ON VS4TAPGroup.TAPGCode=VS4TAP.TAPNTAPGCode) ON VS4TAPType.TAPTCode=VS4TAP.TAPNTAPTCode) ON VS4TBusinessType.TBsTCode=VS4TAP.TAPNTBsTCode) ON VS4TCountry.TCouCode=VS4TAP.TAPNTCouCode
GO

CREATE VIEW VS4VAPBank
AS 
SELECT VS4TAP.*, VS4TAPBank.*, VS4TBank.*
FROM VS4TAP INNER JOIN (VS4TAPBank LEFT JOIN VS4TBank ON VS4TAPBank.TAPBTBnkCode=VS4TBank.TBnkCode) ON VS4TAP.TAPNCode=VS4TAPBank.TAPBTAPNCode
GO

CREATE VIEW VS4VAPBill
AS 
SELECT VS4TAPBill.*, VS4TAPBillMB.*, VS4TAP.TAPNName, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TBranch.TBraName, VS4TAP.TAPNTBsTCode, VS4TBusinessType.TBstName, VS4TAP.TAPNTAPGCode, VS4TAPGroup.TAPGName, VS4TAPInvoice.TIAPNo, VS4TAPInvoice.TIAPTaxBase, VS4TAPInvoice.TIAPVATRate, VS4TAPInvoice.TIAPVATTotal, VS4TAPInvoice.TIAPGrandTotal, VS4TAPCreditNote.TPCNNo, VS4TAPCreditNote.TPCNTIAPNo, VS4TAPCreditNote.TPCNTaxBase, VS4TAPCreditNote.TPCNVATType, VS4TAPCreditNote.TPCNVATRate, VS4TAPCreditNote.TPCNVATTotal, VS4TAPCreditNote.TPCNGrandTotal, VS4TAPDebitNote.TDENNo, VS4TAPDebitNote.TDENTIAPNo, VS4TAPDebitNote.TDENVATType, VS4TAPDebitNote.TDENVATRate, VS4TAPDebitNote.TDENTaxBase, VS4TAPDebitNote.TDENVATTotal, VS4TAPDebitNote.TDENGrandTotal
FROM (((((VS4TAPBill LEFT JOIN VS4TAP ON VS4TAPBill.TPBITAPNCode=VS4TAP.TAPNCode) LEFT JOIN VS4TProject ON VS4TAPBill.TPBITPrjCode=VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TAPBill.TPBITBraCode=VS4TBranch.TBraCode) LEFT JOIN VS4TBusinessType ON VS4TAP.TAPNTBsTCode=VS4TBusinessType.TBsTCode) LEFT JOIN VS4TAPGroup ON VS4TAP.TAPNTAPGCode=VS4TAPGroup.TAPGCode) INNER JOIN (((VS4TAPBillMB LEFT JOIN VS4TAPDebitNote ON VS4TAPBillMB.TPBMRefNo2=VS4TAPDebitNote.TDENNo) LEFT JOIN VS4TAPInvoice ON VS4TAPBillMB.TPBMRefNo2=VS4TAPInvoice.TIAPNo) LEFT JOIN VS4TAPCreditNote ON VS4TAPBillMB.TPBMRefNo2=VS4TAPCreditNote.TPCNNo) ON VS4TAPBill.TPBINo=VS4TAPBillMB.TPBMTPBINo
GO

CREATE VIEW VS4VAPCard
AS 
SELECT VS4TAP.TAPNCode, VS4TAP.TAPNName, VS4TAP.TAPNIntroName, VS4TAPCard.*, VS4TAPBalance.*, VS4TAccountPeriod.*, VS4TBranch.TBraName, VS4TAP.TAPNTBsTCode, VS4TBusinessType.TBstName, VS4TAP.TAPNTAPGCode, VS4TAPGroup.TAPGName, VS4TAP.TAPNTCouCode, VS4TCountry.TCouName
FROM (((VS4TAP LEFT JOIN VS4TAPGroup ON VS4TAP.TAPNTAPGCode = VS4TAPGroup.TAPGCode) LEFT JOIN VS4TCountry ON VS4TAP.TAPNTCouCode = VS4TCountry.TCouCode) LEFT JOIN VS4TBusinessType ON VS4TAP.TAPNTBsTCode = VS4TBusinessType.TBsTCode) INNER JOIN (VS4TAccountPeriod INNER JOIN ((VS4TAPCard INNER JOIN VS4TAPBalance ON (VS4TAPCard.TPICTAPNCode = VS4TAPBalance.TAPLTAPNCode) AND (VS4TAPCard.TPICTACPID = VS4TAPBalance.TAPLTACPID) AND (VS4TAPCard.TPICTACPTACYID = VS4TAPBalance.TAPLTACPTACYID)) LEFT JOIN VS4TBranch ON VS4TAPCard.TPICTBraCode = VS4TBranch.TBraCode) ON (VS4TAccountPeriod.TACPID = VS4TAPBalance.TAPLTACPID) AND (VS4TAccountPeriod.TACPTACYID = VS4TAPBalance.TAPLTACPTACYID)) ON VS4TAP.TAPNCode = VS4TAPCard.TPICTAPNCode
WHERE (((VS4TAPCard.TPICType)<>'O'))
GO

CREATE VIEW VS4VAPCardIVDBCN
AS 
SELECT VS4TAPCard.*, VS4TAPDebitNote.TDENNo, VS4TAPCreditNote.TPCNNo, VS4TAPInvoice.TIAPNo, VS4TAPInvoice.TIAPTaxBase, VS4TAPInvoice.TIAPVATTotal, VS4TAPInvoice.TIAPGrandTotal, VS4TAPCreditNote.TPCNTaxBase, VS4TAPCreditNote.TPCNVATTotal, VS4TAPCreditNote.TPCNGrandTotal, VS4TAPDebitNote.TDENTaxBase, VS4TAPDebitNote.TDENVATTotal, VS4TAPDebitNote.TDENGrandTotal, VS4TAPInvoice.TIAPExchangeRate, VS4TAP.TAPNName, VS4TAPDebitNote.TDENDate, VS4TAPCreditNote.TPCNDate, VS4TAPInvoice.TIAPDate, VS4TAPInvoice.TIAPType, VS4TAPInvoice.TIAPSubTotal, VS4TAPDebitNote.TDENSubTotal, VS4TAPCreditNote.TPCNSubTotal, VS4TAPDebitNote.TDENTIAPNo, VS4TAPCreditNote.TPCNTIAPNo, VS4TAPInvoice.TIAPRefNo, VS4TBranch.TBraName, VS4TProject.TPrjMode, VS4TProject.TPrjName, VS4TAP.TAPNTCouCode, VS4TCountry.TCouName, VS4TAP.TAPNTBsTCode, VS4TBusinessType.TBstName, VS4TAP.TAPNTAPGCode, VS4TAPGroup.TAPGName, VS4TAP.TAPNName2, VS4TAPInvoice.TIAPTCurCode, VS4TAPCreditNote.TPCNTCurCode, VS4TAPCreditNote.TPCNExchangeRate, VS4TAPDebitNote.TDENTCurCode, VS4TAPDebitNote.TDENExchangeRate
FROM (((VS4TAP LEFT JOIN VS4TCountry ON VS4TAP.TAPNTCouCode = VS4TCountry.TCouCode) LEFT JOIN VS4TBusinessType ON VS4TAP.TAPNTBsTCode = VS4TBusinessType.TBsTCode) LEFT JOIN VS4TAPGroup ON VS4TAP.TAPNTAPGCode = VS4TAPGroup.TAPGCode) INNER JOIN ((VS4TBranch RIGHT JOIN (((VS4TAPCard LEFT JOIN VS4TAPDebitNote ON VS4TAPCard.TPICDocNo = VS4TAPDebitNote.TDENNo) LEFT JOIN VS4TAPCreditNote ON VS4TAPCard.TPICDocNo = VS4TAPCreditNote.TPCNNo) LEFT JOIN VS4TAPInvoice ON VS4TAPCard.TPICDocNo = VS4TAPInvoice.TIAPNo) ON VS4TBranch.TBraCode = VS4TAPCard.TPICTBraCode) LEFT JOIN VS4TProject ON VS4TAPCard.TPICTPrjCode = VS4TProject.TPrjCode) ON VS4TAP.TAPNCode = VS4TAPCard.TPICTAPNCode
WHERE (((VS4TAPCard.TPICType)<>'O'))
GO

CREATE VIEW VS4VAPCardIVDBCNMB
AS 
SELECT VS4TAPCard.*, VS4TAPDebitNote.TDENNo, VS4TAPCreditNote.TPCNNo, VS4TAPInvoice.TIAPNo, VS4TAPInvoice.TIAPTaxBase, VS4TAPInvoice.TIAPVATTotal, VS4TAPInvoice.TIAPGrandTotal, VS4TAPCreditNote.TPCNTaxBase, VS4TAPCreditNote.TPCNVATTotal, VS4TAPCreditNote.TPCNGrandTotal, VS4TAPDebitNote.TDENTaxBase, VS4TAPDebitNote.TDENVATTotal, VS4TAPDebitNote.TDENGrandTotal, VS4TAPInvoice.TIAPExchangeRate, VS4TAP.TAPNName, VS4TAPDebitNote.TDENDate, VS4TAPCreditNote.TPCNDate, VS4TAPInvoice.TIAPDate, VS4TAPInvoice.TIAPType, VS4TAPInvoice.TIAPSubTotal, VS4TAPDebitNote.TDENSubTotal, VS4TAPCreditNote.TPCNSubTotal, VS4TAPDebitNote.TDENTIAPNo, VS4TAPCreditNote.TPCNTIAPNo, VS4TAPInvoice.TIAPRefNo, VS4TBranch.TBraName, VS4TProject.TPrjMode, VS4TProject.TPrjName, VS4TAP.TAPNTCouCode, VS4TCountry.TCouName, VS4TAP.TAPNTBsTCode, VS4TBusinessType.TBstName, VS4TAP.TAPNTAPGCode, VS4TAPGroup.TAPGName, VS4TAPInvoiceMB.TIPMTPdtCode, VS4TAPInvoiceMB.TIPMSerialNo, VS4TAPInvoiceMB.TIPMCustom1, VS4TAPInvoiceMB.TIPMCustom2, VS4TAPInvoiceMB.TIPMCustom3, VS4TAPInvoiceMB.TIPMProductName, VS4TAPInvoiceMB.TIPMCost, VS4TAPInvoiceMB.TIPMPrice, VS4TAPInvoiceMB.TIPMQuantity, VS4TAPInvoiceMB.TIPMQuantityCalc, VS4TAPInvoiceMB.TIPMTUntCode, VS4TAPInvoiceMB.TIPMAmountWTAX, VS4TAPInvoiceMB.TIPMAmountVAT, VS4TAPInvoiceMB.TIPMTaxType, VS4TAPInvoiceMB.TIPMCostAmount, VS4TAPCreditNoteMB.TPCMReturnFlag, VS4TAPCreditNoteMB.TPCMTPdtCode, VS4TAPCreditNoteMB.TPCMSerialNo, VS4TAPCreditNoteMB.TPCMCustom1, VS4TAPCreditNoteMB.TPCMCustom2, VS4TAPCreditNoteMB.TPCMCustom3, VS4TAPCreditNoteMB.TPCMProductName, VS4TAPCreditNoteMB.TPCMCost, VS4TAPCreditNoteMB.TPCMOldPrice, VS4TAPCreditNoteMB.TPCMNewPrice, VS4TAPCreditNoteMB.TPCMPrice, VS4TAPCreditNoteMB.TPCMQuantityCalc, VS4TAPCreditNoteMB.TPCMQuantity, VS4TAPCreditNoteMB.TPCMTUntCode, VS4TAPCreditNoteMB.TPCMTaxBase, VS4TAPCreditNoteMB.TPCMAmountVAT, VS4TAPCreditNoteMB.TPCMGrandTotal, VS4TAPDebitNoteMB.TDEBTPdtCode, VS4TAPDebitNoteMB.TDEBSerialNo, VS4TAPDebitNoteMB.TDEBCustom1, VS4TAPDebitNoteMB.TDEBCustom2, VS4TAPDebitNoteMB.TDEBCustom3, VS4TAPDebitNoteMB.TDEBProductName, VS4TAPDebitNoteMB.TDEBCost, VS4TAPDebitNoteMB.TDEBPrice, VS4TAPDebitNoteMB.TDEBOldPrice, VS4TAPDebitNoteMB.TDEBNewPrice, VS4TAPDebitNoteMB.TDEBQuantityCalc, VS4TAPDebitNoteMB.TDEBQuantity, VS4TAPDebitNoteMB.TDEBTUntCode, VS4TAPCreditNoteMB.TPCMCostAmount, VS4TAPDebitNoteMB.TDEBCostAmount, VS4TAPDebitNoteMB.TDEBTaxBase, VS4TAPDebitNoteMB.TDEBAmountVAT, VS4TAPDebitNoteMB.TDEBGrandTotal, VS4TProductSec2.TPS2Code, VS4TProductSec2.TPS2Name, VS4TAP.TAPNName2, VS4TAPInvoice.TIAPTCurCode, VS4TAPCreditNote.TPCNTCurCode, VS4TAPCreditNote.TPCNExchangeRate, VS4TAPDebitNote.TDENTCurCode, VS4TAPDebitNote.TDENExchangeRate
FROM (((VS4TAP LEFT JOIN VS4TCountry ON VS4TAP.TAPNTCouCode = VS4TCountry.TCouCode) LEFT JOIN VS4TBusinessType ON VS4TAP.TAPNTBsTCode = VS4TBusinessType.TBsTCode) LEFT JOIN VS4TAPGroup ON VS4TAP.TAPNTAPGCode = VS4TAPGroup.TAPGCode) INNER JOIN (((((VS4TBranch RIGHT JOIN (((VS4TAPCard LEFT JOIN VS4TAPDebitNote ON VS4TAPCard.TPICDocNo = VS4TAPDebitNote.TDENNo) LEFT JOIN VS4TAPCreditNote ON VS4TAPCard.TPICDocNo = VS4TAPCreditNote.TPCNNo) LEFT JOIN VS4TAPInvoice ON VS4TAPCard.TPICDocNo = VS4TAPInvoice.TIAPNo) ON VS4TBranch.TBraCode = VS4TAPCard.TPICTBraCode) LEFT JOIN VS4TProject ON VS4TAPCard.TPICTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TAPCreditNoteMB ON VS4TAPCreditNote.TPCNNo = VS4TAPCreditNoteMB.TPCMTPCNNo) LEFT JOIN VS4TAPDebitNoteMB ON VS4TAPDebitNote.TDENNo = VS4TAPDebitNoteMB.TDEBTDENNo) LEFT JOIN ((VS4TAPInvoiceMB LEFT JOIN VS4TProduct ON VS4TAPInvoiceMB.TIPMTPdtCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code) ON VS4TAPInvoice.TIAPNo = VS4TAPInvoiceMB.TIPMTIAPNo) ON VS4TAP.TAPNCode = VS4TAPCard.TPICTAPNCode
WHERE (((VS4TAPCard.TPICType)<>'O'))
GO

CREATE VIEW VS4VAPCodeFromBO
AS 
SELECT VS4TAP.TAPNCode, VS4TAP.TAPNName, VS4TAP.TAPNName2, VS4TAP.TAPNIntroName, VS4TAP.TAPNFlag1, VS4TAP.TAPNTCouCode, VS4TCountry.TCouName, VS4TCountry.TCouName2
FROM VS4TCountry INNER JOIN (VS4TAP INNER JOIN VS4TAPInvoice ON VS4TAP.TAPNCode=VS4TAPInvoice.TIAPTAPNCode) ON VS4TCountry.TCouCode=VS4TAP.TAPNTCouCode
GROUP BY VS4TAP.TAPNCode, VS4TAP.TAPNName, VS4TAP.TAPNName2, VS4TAP.TAPNIntroName, VS4TAP.TAPNFlag1, VS4TAP.TAPNTCouCode, VS4TCountry.TCouName, VS4TCountry.TCouName2, VS4TAPInvoice.TIAPConfirmStatus, VS4TAPInvoice.TIAPApproveStatus, VS4TAPInvoice.TIAPCancelStatus, VS4TAPInvoice.TIAPType
HAVING (((VS4TAPInvoice.TIAPConfirmStatus)=1) AND ((VS4TAPInvoice.TIAPApproveStatus)=1) AND ((VS4TAPInvoice.TIAPCancelStatus)<>1) AND ((VS4TAPInvoice.TIAPType)=5))
GO

CREATE VIEW VS4VAPCodeFromLOT
AS 
SELECT VS4TAP.TAPNCode, VS4TAP.TAPNName, VS4TAP.TAPNName2, VS4TAP.TAPNIntroName, VS4TAP.TAPNFlag1, VS4TAP.TAPNTCouCode, VS4TCountry.TCouName, VS4TCountry.TCouName2
FROM VS4TCountry INNER JOIN (VS4TInventory INNER JOIN VS4TAP ON VS4TInventory.TInvTARNCode=VS4TAP.TAPNCode) ON VS4TCountry.TCouCode=VS4TAP.TAPNTCouCode
WHERE (((VS4TInventory.TInvCancelStatus)<>1 And (VS4TInventory.TInvCancelStatus)<>1) AND ((VS4TInventory.TInvApproveStatus)=1 And (VS4TInventory.TInvApproveStatus)=1))
GO

CREATE VIEW VS4VPA
AS 
SELECT VS4TPA.*, VS4TPAMB.*, VS4TPS.*, VS4TAP.TAPNTotalScore, VS4TAP.TAPNTimeToOrder, VS4TAP.TAPNLastDueDate, VS4TAP.TAPNLastOrderDate, VS4TAP.TAPNCreditLimit, VS4TAP.TAPNCreditBalance
FROM (VS4TAP RIGHT JOIN VS4TPS ON VS4TAP.TAPNCode=VS4TPS.TPSDTAPNCode) INNER JOIN (VS4TPA INNER JOIN VS4TPAMB ON VS4TPA.TPADNo=VS4TPAMB.TPAMTPADNo) ON VS4TPS.TPSDNo=VS4TPAMB.TPAMTPSDNo
GO

CREATE VIEW VS4VAPCodeFromPO
AS 
SELECT VS4TAP.TAPNCode, VS4TAP.TAPNName, VS4TAP.TAPNName2, VS4TAP.TAPNIntroName, VS4TAP.TAPNFlag1, VS4TAP.TAPNTCouCode, VS4TCountry.TCouName, VS4TCountry.TCouName2
FROM VS4TCountry INNER JOIN (VS4TAP INNER JOIN VS4TPO ON VS4TAP.TAPNCode=VS4TPO.TPODTAPNCode) ON VS4TCountry.TCouCode=VS4TAP.TAPNTCouCode
GROUP BY VS4TAP.TAPNCode, VS4TAP.TAPNName, VS4TAP.TAPNName2, VS4TAP.TAPNIntroName, VS4TAP.TAPNFlag1, VS4TAP.TAPNTCouCode, VS4TCountry.TCouName, VS4TCountry.TCouName2, VS4TPO.TPODAPBODeposit, VS4TPO.TPODConfirmStatus, VS4TPO.TPODApproveStatus, VS4TPO.TPODCancelStatus
HAVING (((VS4TPO.TPODConfirmStatus)=1) AND ((VS4TPO.TPODApproveStatus)=1) AND ((VS4TPO.TPODCancelStatus)<>1))
GO

CREATE VIEW VS4VAPCodeFromPOP
AS 
SELECT VS4TAP.TAPNCode, VS4TAP.TAPNName, VS4TAP.TAPNName2, VS4TAP.TAPNIntroName, VS4TAP.TAPNFlag1, VS4TAP.TAPNTCouCode, VS4TCountry.TCouName, VS4TCountry.TCouName2
FROM VS4TCountry INNER JOIN (VS4TAP INNER JOIN VS4TPOPTrans ON VS4TAP.TAPNCode = VS4TPOPTrans.TPPDTAPNCode) ON VS4TCountry.TCouCode = VS4TAP.TAPNTCouCode
GROUP BY VS4TAP.TAPNCode, VS4TAP.TAPNName, VS4TAP.TAPNName2, VS4TAP.TAPNIntroName, VS4TAP.TAPNFlag1, VS4TAP.TAPNTCouCode, VS4TCountry.TCouName, VS4TCountry.TCouName2, VS4TPOPTrans.TPPDAPBODeposit, VS4TPOPTrans.TPPDConfirmStatus, VS4TPOPTrans.TPPDApproveStatus, VS4TPOPTrans.TPPDCancelStatus
HAVING (((VS4TPOPTrans.TPPDConfirmStatus)=1) AND ((VS4TPOPTrans.TPPDApproveStatus)=1) AND ((VS4TPOPTrans.TPPDCancelStatus)<>1))
GO

CREATE VIEW VS4VAPCodeFromPR
AS 
SELECT VS4TAP.TAPNCode, VS4TAP.TAPNName, VS4TAP.TAPNName2, VS4TAP.TAPNIntroName, VS4TAP.TAPNFlag1, VS4TAP.TAPNTCouCode, VS4TCountry.TCouName, VS4TCountry.TCouName2
FROM VS4TCountry RIGHT JOIN (VS4TAP LEFT JOIN VS4TPR ON VS4TAP.TAPNCode = VS4TPR.TPRDTAPNCode) ON VS4TCountry.TCouCode = VS4TAP.TAPNTCouCode
GROUP BY VS4TAP.TAPNCode, VS4TAP.TAPNName, VS4TAP.TAPNName2, VS4TAP.TAPNIntroName, VS4TAP.TAPNFlag1, VS4TAP.TAPNTCouCode, VS4TCountry.TCouName, VS4TCountry.TCouName2, VS4TPR.TPRDConfirmStatus, VS4TPR.TPRDApproveStatus, VS4TPR.TPRDCancelStatus
HAVING (((VS4TPR.TPRDConfirmStatus)=1) AND ((VS4TPR.TPRDApproveStatus)=1) AND ((VS4TPR.TPRDCancelStatus)<>1))
GO

CREATE VIEW VS4VAPCodeFromPS
AS 
SELECT VS4TAP.TAPNCode, VS4TAP.TAPNName, VS4TAP.TAPNName2, VS4TAP.TAPNIntroName, VS4TAP.TAPNFlag1, VS4TAP.TAPNTCouCode, VS4TCountry.TCouName, VS4TCountry.TCouName2
FROM VS4TCountry INNER JOIN (VS4TAP INNER JOIN VS4TPS ON VS4TAP.TAPNCode=VS4TPS.TPSDTAPNCode) ON VS4TCountry.TCouCode=VS4TAP.TAPNTCouCode
GROUP BY VS4TAP.TAPNCode, VS4TAP.TAPNName, VS4TAP.TAPNName2, VS4TAP.TAPNIntroName, VS4TAP.TAPNFlag1, VS4TAP.TAPNTCouCode, VS4TCountry.TCouName, VS4TCountry.TCouName2, VS4TPS.TPSDConfirmStatus, VS4TPS.TPSDCancelStatus
HAVING (((VS4TPS.TPSDConfirmStatus)=1) AND ((VS4TPS.TPSDCancelStatus)<>1))
GO

CREATE VIEW VS4VAPCreditNote
AS 
SELECT VS4TAPCreditNote.*, VS4TAPCreditNoteMB.*, VS4TAP.TAPNTaxNo, VS4TAP.TAPNPhone, VS4TAP.TAPNFax, VS4TProject.TPrjMode, VS4TProject.TPrjName, VS4TBranch.TBraName, VS4TCountry.TCouName, VS4TAP.TAPNTBsTCode, VS4TBusinessType.TBstName, VS4TAP.TAPNTAPGCode, VS4TAPGroup.TAPGName, VS4TAP.TAPNName, VS4TAPInvoice.TIAPNo, VS4TAPInvoice.TIAPBalanceFlag, VS4TAPInvoice.TIAPType, VS4TAPInvoice.TIAPDate, VS4TAPInvoice.TIAPDueDate, VS4TAPInvoice.TIAPRefNo, VS4TAPInvoice.TIAPPONo, VS4TAPInvoice.TIAPSOCode, VS4TAPInvoice.TIAPJobCode, VS4TAPInvoice.TIAPTJobNo, VS4TAPInvoice.TIAPTPrjCode, VS4TAPInvoice.TIAPTBraCode, VS4TAPInvoice.TIAPDeliveryDate, VS4TAPInvoice.TIAPTAPNCode, VS4TAPInvoice.TIAPSupplierName, VS4TAPInvoice.TIAPSupAddress, VS4TAPInvoice.TIAPPriceChannel, VS4TAPInvoice.TIAPSubTotal, VS4TAPInvoice.TIAPDiscountText, VS4TAPInvoice.TIAPDiscountTotal, VS4TAPInvoice.TIAPTaxBase, VS4TAPInvoice.TIAPVATRate, VS4TAPInvoice.TIAPVATTotal, VS4TAPInvoice.TIAPGrandTotal, VS4TAPInvoice.TIAPVATType, VS4TAPInvoice.TIAPDepositText, VS4TAPInvoice.TIAPDeposit, VS4TAPInvoice.TIAPCountryOrigin, VS4TProduct.TPdtCode, VS4TProduct.TPdtName, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtTPSECode, VS4TProduct.TPdtTPG1Code
FROM ((((((VS4TAPCreditNote LEFT JOIN VS4TAPInvoice ON VS4TAPCreditNote.TPCNTIAPNo = VS4TAPInvoice.TIAPNo) LEFT JOIN VS4TProject ON VS4TAPCreditNote.TPCNTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TAPCreditNote.TPCNTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TAPInvoiceADJ ON VS4TAPCreditNote.TPCNTIAPNo = VS4TAPInvoiceADJ.TIPJNo) LEFT JOIN ((VS4TAP LEFT JOIN VS4TBusinessType ON VS4TAP.TAPNTBsTCode = VS4TBusinessType.TBsTCode) LEFT JOIN VS4TAPGroup ON VS4TAP.TAPNTAPGCode = VS4TAPGroup.TAPGCode) ON VS4TAPCreditNote.TPCNTAPNCode = VS4TAP.TAPNCode) LEFT JOIN VS4TCountry ON VS4TAP.TAPNTCouCode = VS4TCountry.TCouCode) INNER JOIN (VS4TAPCreditNoteMB LEFT JOIN VS4TProduct ON VS4TAPCreditNoteMB.TPCMTPdtCode = VS4TProduct.TPdtCode) ON VS4TAPCreditNote.TPCNNo = VS4TAPCreditNoteMB.TPCMTPCNNo
GO

CREATE VIEW VS4VAPCreditNoteH
AS 
SELECT VS4TAPCreditNote.*, VS4TAPInvoice.*
FROM VS4TAP INNER JOIN ((VS4TAPCreditNote LEFT JOIN VS4TAPInvoice ON VS4TAPCreditNote.TPCNTIAPNo=VS4TAPInvoice.TIAPNo) LEFT JOIN VS4TAPInvoiceADJ ON VS4TAPCreditNote.TPCNTIAPNo=VS4TAPInvoiceADJ.TIPJNo) ON VS4TAP.TAPNCode=VS4TAPCreditNote.TPCNTAPNCode
GO

CREATE VIEW VS4VAPDebitNote
AS 
SELECT VS4TAPDebitNote.*, VS4TAPDebitNoteMB.*, VS4TAP.TAPNTaxNo, VS4TAP.TAPNPhone, VS4TAP.TAPNFax, VS4TAPInvoiceADJ.TIPJCountryOrigin, VS4TCountry.TCouName, VS4TBranch.TBraName, VS4TProject.TPrjMode, VS4TProject.TPrjName, VS4TAP.TAPNTBsTCode, VS4TBusinessType.TBstName, VS4TAP.TAPNName, VS4TAP.TAPNTAPGCode, VS4TAPGroup.TAPGName, VS4TAPInvoice.TIAPNo, VS4TAPInvoice.TIAPBalanceFlag, VS4TAPInvoice.TIAPType, VS4TAPInvoice.TIAPDate, VS4TAPInvoice.TIAPDueDate, VS4TAPInvoice.TIAPRefNo, VS4TAPInvoice.TIAPPONo, VS4TAPInvoice.TIAPSOCode, VS4TAPInvoice.TIAPJobCode, VS4TAPInvoice.TIAPTJobNo, VS4TAPInvoice.TIAPTPrjCode, VS4TAPInvoice.TIAPTBraCode, VS4TAPInvoice.TIAPDeliveryDate, VS4TAPInvoice.TIAPTAPNCode, VS4TAPInvoice.TIAPSupplierName, VS4TAPInvoice.TIAPSupAddress, VS4TAPInvoice.TIAPTaxBase, VS4TAPInvoice.TIAPSubTotal, VS4TAPInvoice.TIAPGrandTotal, VS4TAPInvoice.TIAPVATTotal, VS4TAPInvoice.TIAPVATType, VS4TAPInvoice.TIAPDiscountTotal, VS4TAPInvoice.TIAPPriceChannel, VS4TAPInvoice.TIAPTPOTCode, VS4TAPInvoice.TIAPDepositText, VS4TAPInvoice.TIAPDeposit
FROM (((VS4TAPDebitNote LEFT JOIN VS4TBranch ON VS4TAPDebitNote.TDENTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TProject ON VS4TAPDebitNote.TDENTPrjCode = VS4TProject.TPrjCode) LEFT JOIN (((VS4TAP LEFT JOIN VS4TBusinessType ON VS4TAP.TAPNTBsTCode = VS4TBusinessType.TBsTCode) LEFT JOIN VS4TAPGroup ON VS4TAP.TAPNTAPGCode = VS4TAPGroup.TAPGCode) LEFT JOIN VS4TCountry ON VS4TAP.TAPNTCouCode = VS4TCountry.TCouCode) ON VS4TAPDebitNote.TDENTAPNCode = VS4TAP.TAPNCode) INNER JOIN ((VS4TAPDebitNoteMB LEFT JOIN VS4TAPInvoiceADJ ON VS4TAPDebitNoteMB.TDEBSourceNo = VS4TAPInvoiceADJ.TIPJNo) LEFT JOIN VS4TAPInvoice ON VS4TAPDebitNoteMB.TDEBSourceNo = VS4TAPInvoice.TIAPNo) ON VS4TAPDebitNote.TDENNo = VS4TAPDebitNoteMB.TDEBTDENNo
GO

CREATE VIEW VS4VAPDebitNoteH
AS 
SELECT VS4TAPDebitNote.*, VS4TAPInvoice.*
FROM ((VS4TAPDebitNote LEFT JOIN VS4TAPInvoice ON VS4TAPDebitNote.TDENTIAPNo=VS4TAPInvoice.TIAPNo) LEFT JOIN VS4TAPInvoiceADJ ON VS4TAPDebitNote.TDENTIAPNo=VS4TAPInvoiceADJ.TIPJNo) LEFT JOIN VS4TAP ON VS4TAPDebitNote.TDENTAPNCode=VS4TAP.TAPNCode
GO

CREATE VIEW VS4VAPInvoice
AS 
SELECT VS4TAPInvoice.*, VS4TAPInvoiceMB.*, VS4TProject.TPrjName, VS4TAP.TAPNName, VS4TCountry.TCouName, VS4TAPGroup.TAPGCode, VS4TAPGroup.TAPGName, VS4TAP.TAPNPhone, VS4TAP.TAPNFax, VS4TAP.TAPNTaxNo, VS4TAP.TAPNImage1, VS4TCountry.TCouName2, VS4TBranch.TBraName, VS4TProject.TPrjMode, VS4TAP.TAPNTBsTCode, VS4TBusinessType.TBstName, VS4TAP.TAPNTAPGCode, VS4TPOS.TPOSPrice, VS4TProduct.TPdtTPG1Code, VS4TProduct.TPdtTPSECode, VS4TProduct.TPdtGroupReport, VS4TProduct.TPdtName, VS4TPO.TPODDate, VS4TPOPTrans.TPPDType
FROM (VS4TCountry INNER JOIN (((VS4TAP LEFT JOIN VS4TAPGroup ON VS4TAP.TAPNTAPGCode = VS4TAPGroup.TAPGCode) LEFT JOIN VS4TBusinessType ON VS4TAP.TAPNTBsTCode = VS4TBusinessType.TBsTCode) INNER JOIN ((((VS4TAPInvoice LEFT JOIN VS4TProject ON VS4TAPInvoice.TIAPTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TAPInvoice.TIAPTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TPO ON VS4TAPInvoice.TIAPPONo = VS4TPO.TPODNo) INNER JOIN ((VS4TAPInvoiceMB LEFT JOIN VS4TProduct ON VS4TAPInvoiceMB.TIPMTPdtCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) ON VS4TAPInvoice.TIAPNo = VS4TAPInvoiceMB.TIPMTIAPNo) ON VS4TAP.TAPNCode = VS4TAPInvoice.TIAPTAPNCode) ON VS4TCountry.TCouCode = VS4TAP.TAPNTCouCode) LEFT JOIN VS4TPOPTrans ON VS4TAPInvoiceMB.TIPMSourceNo = VS4TPOPTrans.TPPDNo
WHERE (((VS4TPOS.TPOSType)=0 Or (VS4TPOS.TPOSType) Is Null))
GO

CREATE VIEW VS4VAPInvoiceADJH
AS 
SELECT VS4TAPInvoiceADJ.*, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TAPBalance.*, VS4TAP.TAPNTAPGCode, VS4TAPGroup.TAPGName, VS4TBranch.TBraName, VS4TAP.TAPNTBsTCode, VS4TBusinessType.TBstName, VS4TCountry.TCouName, VS4TAP.TAPNName
FROM ((((((VS4TAPInvoiceADJ LEFT JOIN VS4TProject ON VS4TAPInvoiceADJ.TIPJTPrjCode=VS4TProject.TPrjCode) LEFT JOIN VS4TAPBalance ON (VS4TAPInvoiceADJ.TIPJTAPNCode=VS4TAPBalance.TAPLTAPNCode) AND (VS4TAPInvoiceADJ.TIPJTACPID=VS4TAPBalance.TAPLTACPID) AND (VS4TAPInvoiceADJ.TIPJTACPTACYID=VS4TAPBalance.TAPLTACPTACYID)) INNER JOIN VS4TAPInvoice ON VS4TAPInvoiceADJ.TIPJNo=VS4TAPInvoice.TIAPNo) LEFT JOIN (VS4TAP LEFT JOIN VS4TAPGroup ON VS4TAP.TAPNTAPGCode=VS4TAPGroup.TAPGCode) ON VS4TAPInvoiceADJ.TIPJTAPNCode=VS4TAP.TAPNCode) LEFT JOIN VS4TBranch ON VS4TAPInvoiceADJ.TIPJTBraCode=VS4TBranch.TBraCode) LEFT JOIN VS4TBusinessType ON VS4TAP.TAPNTBsTCode=VS4TBusinessType.TBsTCode) LEFT JOIN VS4TCountry ON VS4TAPInvoiceADJ.TIPJCountryOrigin=VS4TCountry.TCouCode
GO

CREATE VIEW VS4VAPInvoiceArrH
AS 
SELECT VS4TAPInvoice.*, VS4TAP.*, VS4TProject.TPrjName, VS4TAPGroup.TAPGCode, VS4TAPGroup.TAPGName, VS4TProject.TPrjMode, VS4TBusinessType.TBstName, VS4TBranch.TBraName
FROM (VS4TProject INNER JOIN (VS4TCountry RIGHT JOIN (VS4TBusinessType RIGHT JOIN ((VS4TAP LEFT JOIN VS4TAP2 ON VS4TAP.TAPNCode = VS4TAP2.TAP2TAPNCode) INNER JOIN (VS4TAPInvoice LEFT JOIN VS4TBranch ON VS4TAPInvoice.TIAPTBraCode = VS4TBranch.TBraCode) ON VS4TAP.TAPNCode = VS4TAPInvoice.TIAPTAPNCode) ON VS4TBusinessType.TBsTCode = VS4TAP.TAPNTBsTCode) ON VS4TCountry.TCouCode = VS4TAP.TAPNTCouCode) ON VS4TProject.TPrjCode = VS4TAPInvoice.TIAPTPrjCode) LEFT JOIN VS4TAPGroup ON VS4TAP.TAPNTAPGCode = VS4TAPGroup.TAPGCode
GO

CREATE VIEW VS4VAPInvoiceDBCN
AS 
SELECT VS4TAPInvoice.*, VS4TCountry.TCouName, VS4TAP.*, VS4TProject.TPrjName, VS4TAPGroup.TAPGCode, VS4TAPGroup.TAPGName, VS4TAPCreditNote.TPCNNo, VS4TAPCreditNote.TPCNGrandTotal, VS4TAPCreditNote.TPCNArrears, VS4TAPCreditNote.TPCNTaxBase, VS4TAPCreditNote.TPCNVATTotal, VS4TAPDebitNote.TDENNo, VS4TAPDebitNote.TDENTIAPNo, VS4TAPDebitNote.TDENTaxBase, VS4TAPDebitNote.TDENVATTotal, VS4TAPDebitNote.TDENGrandTotal, VS4TAPDebitNote.TDENArrears, VS4TProject.TPrjMode, VS4TBusinessType.TBstName, VS4TBranch.TBraName
FROM ((((((VS4TAPInvoice LEFT JOIN VS4TAPDebitNote ON VS4TAPInvoice.TIAPNo=VS4TAPDebitNote.TDENTIAPNo) LEFT JOIN VS4TAPCreditNote ON VS4TAPInvoice.TIAPNo=VS4TAPCreditNote.TPCNTIAPNo) LEFT JOIN (VS4TAP LEFT JOIN VS4TAPGroup ON VS4TAP.TAPNTAPGCode=VS4TAPGroup.TAPGCode) ON VS4TAPInvoice.TIAPTAPNCode=VS4TAP.TAPNCode) LEFT JOIN VS4TCountry ON VS4TAPInvoice.TIAPCountryOrigin=VS4TCountry.TCouCode) LEFT JOIN VS4TProject ON VS4TAPInvoice.TIAPTPrjCode=VS4TProject.TPrjCode) LEFT JOIN VS4TBusinessType ON VS4TAP.TAPNTBsTCode=VS4TBusinessType.TBsTCode) LEFT JOIN VS4TBranch ON VS4TAPInvoice.TIAPTBraCode=VS4TBranch.TBraCode
GO

CREATE VIEW VS4VAPInvoicePay
AS 
SELECT VS4TAPInvoice.*, VS4TProject.TPrjName, VS4TAP.TAPNName, VS4TCountry.TCouName, VS4TAPGroup.TAPGCode, VS4TAPGroup.TAPGName, VS4TAPInvoicePay.*, VS4TChequeSub.TCHSChqPassBy, VS4TChequeSub.TCHSChqPassDate, VS4TChequeSub.TCHSChqBackBy, VS4TChequeSub.TCHSChqBackDate, VS4TCompanyBank.TCBBTBnkCode, VS4TCompanyBank.TCBBAccountNo, VS4TCompanyBank.TCBBAccountBranch
FROM VS4TCompanyBank RIGHT JOIN (VS4TCountry INNER JOIN (VS4TChequeSub RIGHT JOIN ((VS4TAP LEFT JOIN VS4TAPGroup ON VS4TAP.TAPNTAPGCode = VS4TAPGroup.TAPGCode) INNER JOIN ((VS4TAPInvoice LEFT JOIN VS4TProject ON VS4TAPInvoice.TIAPTPrjCode = VS4TProject.TPrjCode) LEFT JOIN (VS4TAPInvoicePay LEFT JOIN VS4TChequeSub2IV ON (VS4TAPInvoicePay.TPIPLn = VS4TChequeSub2IV.TS2ITPIPLn) AND (VS4TAPInvoicePay.TPIPTIAPNo = VS4TChequeSub2IV.TS2ITPIPTIAPNo)) ON VS4TAPInvoice.TIAPNo = VS4TAPInvoicePay.TPIPTIAPNo) ON VS4TAP.TAPNCode = VS4TAPInvoice.TIAPTAPNCode) ON VS4TChequeSub.TCHSNo = VS4TChequeSub2IV.TS2ITCHSNo) ON VS4TCountry.TCouCode = VS4TAP.TAPNTCouCode) ON VS4TCompanyBank.TCBBNo = VS4TAPInvoicePay.TPIPTCBBNo
GO

CREATE VIEW VS4VAPParent
AS 
SELECT VS4TAPParent.*, VS4TAP_1.*, VS4TAP.TAPNCode AS VAPPCode, VS4TAP.TAPNName AS VAPPName, VS4TAP.TAPNName2 AS VAPPName2, VS4TAP.TAPNType AS VAPPType, VS4TAP.TAPNTAPTCode AS VAPPTAPTCode, VS4TAP.TAPNTAPGCode AS VAPPTAPGCode, VS4TAP.TAPNPhone AS VAPPPhone, VS4TAP.TAPNFax AS VAPPFax, VS4TAP.TAPNFlag1 AS VAPPFlag1
FROM (VS4TAPParent LEFT JOIN VS4TAP ON VS4TAPParent.TAPPTAPNCode=VS4TAP.TAPNCode) LEFT JOIN VS4TAP AS VS4TAP_1 ON VS4TAPParent.TAPPTAPNCode2=VS4TAP_1.TAPNCode
GO

CREATE VIEW VS4VAppCountComA
AS 
SELECT Year(TARADate) AS VARAYear, Month(TARADate) AS VARAMonth, VS4TARAppointment.TARATEmpCode
FROM VS4TARAppointment
GROUP BY Year(TARADate), Month(TARADate), VS4TARAppointment.TARATEmpCode, VS4TARAppointment.TARATARNCode, VS4TARAppointment.TARAAppointStatus
HAVING (((VS4TARAppointment.TARAAppointStatus)=1))
GO

CREATE VIEW VS4VAppCountCom
AS 
SELECT VS4VAppCountComA.VARAYear, VS4VAppCountComA.VARAMonth, VS4VAppCountComA.TARATEmpCode, Count(VS4VAppCountComA.TARATEmpCode) AS VARATotalCompany
FROM VS4VAppCountComA
GROUP BY VS4VAppCountComA.VARAYear, VS4VAppCountComA.VARAMonth, VS4VAppCountComA.TARATEmpCode
GO

CREATE VIEW VS4VAppCountMedA
AS 
SELECT Year(TARADate) AS VACMYear, Month(TARADate) AS VACMMonth, VS4TARAppointment.TARATEmpCode, Count(VS4TARAppointment.TARANo) AS VACMTotalMed
FROM VS4TARAppointment
GROUP BY Year(TARADate), Month(TARADate), VS4TARAppointment.TARATEmpCode, VS4TARAppointment.TARAAppointStatus
HAVING (((VS4TARAppointment.TARAAppointStatus)=1))
GO

CREATE VIEW VS4VAppCountMed
AS 
SELECT VS4VAppCountMedA.VACMYear, VS4VAppCountMedA.VACMMonth, VS4VAppCountMedA.TARATEmpCode, VS4VAppCountMedA.VACMTotalMed
FROM VS4VAppCountMedA
GROUP BY VS4VAppCountMedA.VACMYear, VS4VAppCountMedA.VACMMonth, VS4VAppCountMedA.TARATEmpCode, VS4VAppCountMedA.VACMTotalMed
GO

CREATE VIEW VS4VAppCountSumA
AS 
SELECT Year(TARADate) AS VACSYear, Month(TARADate) AS VACSMonth, VS4TARAppointment.TARATEmpCode, Count(VS4TARAppointment.TARANo) AS VACSTotalApp
FROM VS4TARAppointment
GROUP BY Year(TARADate), Month(TARADate), VS4TARAppointment.TARATEmpCode
GO

CREATE VIEW VS4VAppCountSum
AS 
SELECT VS4VAppCountSumA.VACSYear, VS4VAppCountSumA.VACSMonth, VS4VAppCountSumA.TARATEmpCode, VS4VAppCountSumA.VACSTotalApp
FROM VS4VAppCountSumA
GROUP BY VS4VAppCountSumA.VACSYear, VS4VAppCountSumA.VACSMonth, VS4VAppCountSumA.TARATEmpCode, VS4VAppCountSumA.VACSTotalApp
GO

CREATE VIEW VS4VApproveOne
AS 
SELECT VS4TApproveOne.*, VS4TUser.*, VS4TEmployee.*
FROM (VS4TApproveOne INNER JOIN VS4TUser ON VS4TApproveOne.TAP1TUsrID = VS4TUser.TUsrID) LEFT JOIN (VS4TEmployee RIGHT JOIN VS4TUserEmployee ON VS4TEmployee.TEmpCode = VS4TUserEmployee.TUsETEmpCode) ON VS4TUser.TUsrID = VS4TUserEmployee.TUsETUsrID
GO

CREATE VIEW VS4VAPSumCard
AS 
SELECT VS4TAPBalance.*, VS4TAP.*, VS4TCountry.TCouName, VS4TAPGroup.TAPGName, VS4TBusinessType.TBstName
FROM VS4TBusinessType INNER JOIN (((VS4TAP LEFT JOIN VS4TCountry ON VS4TAP.TAPNTCouCode=VS4TCountry.TCouCode) LEFT JOIN VS4TAPGroup ON VS4TAP.TAPNTAPGCode=VS4TAPGroup.TAPGCode) INNER JOIN VS4TAPBalance ON VS4TAP.TAPNCode=VS4TAPBalance.TAPLTAPNCode) ON VS4TBusinessType.TBsTCode=VS4TAP.TAPNTBsTCode
GO

CREATE VIEW VS4VAR
AS 
SELECT VS4TAR.*, VS4TARStatus.*, VS4TARType.*, VS4TBusinessType.*, VS4TCountry.*, VS4TState.*, VS4TAR2.*, VS4TSaleArea.TSAeName, VS4TARGroup.TARGName, VS4TEmployee.TEmpFullName, VS4TProvince.TPrvName, VS4TAR3.TAR3FirstTalkType, VS4TAR3.TAR3ProspectStatus, VS4TAR3.TAR3OrderStatus, VS4TAR3.TAR3Gender
FROM VS4TCountry RIGHT JOIN (VS4TBusinessType RIGHT JOIN (((VS4TARStatus RIGHT JOIN ((((VS4TAR LEFT JOIN VS4TARType ON VS4TAR.TARNTARTCode = VS4TARType.TARTCode) LEFT JOIN VS4TState ON VS4TAR.TARNStaCode = VS4TState.TStaCode) LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) ON VS4TARStatus.TARSAlias = VS4TAR.TARNTARSAlias) LEFT JOIN ((VS4TAR2 LEFT JOIN VS4TEmployee ON VS4TAR2.TAR2SaleCode = VS4TEmployee.TEmpCode) LEFT JOIN VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) LEFT JOIN VS4TAR3 ON VS4TAR.TARNCode = VS4TAR3.TAR3TARNCode) ON VS4TBusinessType.TBsTCode = VS4TAR.TARNTBsTCode) ON VS4TCountry.TCouCode = VS4TAR.TARNTCouCode
GO

CREATE VIEW VS4VARAppCntYear
AS 
SELECT VS4TARAppointment.TARATARNCode, Count(VS4TARAppointment.TARATARNCode) AS VARYCount, Year(TARADate) AS VARYYear
FROM VS4TARAppointment
GROUP BY VS4TARAppointment.TARATARNCode, Year(TARADate)
GO

CREATE VIEW VS4VARAppCount
AS 
SELECT VS4TARAppointment.TARATARNCode, Count(VS4TARAppointment.TARATARNCode) AS VARDCount, Year(TARADate) AS VARDYear, Month(TARADate) AS VARDMonth, Day(TARADate) AS VARDDay
FROM VS4TARAppointment
GROUP BY VS4TARAppointment.TARATARNCode, Year(TARADate), Month(TARADate), Day(TARADate)
GO

CREATE VIEW VS4VARAppCountY
AS 
SELECT VS4TARAppointment.TARATARNCode, Count(VS4TARAppointment.TARATARNCode) AS VARSCount, Year(TARADate) AS VARSYear, Month(TARADate) AS VARSMonth
FROM VS4TARAppointment
GROUP BY VS4TARAppointment.TARATARNCode, Year(TARADate), Month(TARADate)
GO

CREATE VIEW VS4VARAppointComp
AS 
SELECT VS4TARAppointment.*, VS4TAR.*, VS4TAR2.*, Year(TARADate) AS VARCYear, Month(TARADate) AS VARCMonth, VS4TEmpInOutNote.*, VS4TCompetSection.*, VS4TSaleArea.TSAeCode, VS4TSaleArea.TSAeName, VS4TSaleArea.TSAeName2, VS4TSaleZone.TSZnCode, VS4TSaleZone.TSZnName, VS4TSaleZone.TSZnName2, VS4TAppointType.TAtyCode, VS4TAppointType.TAtyName, VS4TAppointType.TAtyName2, VS4TAppointType.TAtyType, VS4TCompetitor.TCptCode, VS4TCompetitor.TCptName, VS4TCompetitor.TCptName2, VS4TCompetitor.TCptOwnerName, VS4TCompetitor.TCptTBsMCode, VS4TCompetitor.TCptTCouCode
FROM VS4TSaleZone RIGHT JOIN ((VS4TCompetitor RIGHT JOIN VS4TCompetSection ON VS4TCompetitor.TCptCode = VS4TCompetSection.TCPSTCPTCode) RIGHT JOIN (((VS4TAR LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN VS4TAR2 ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) INNER JOIN ((VS4TAppointType RIGHT JOIN (VS4TARAppointment LEFT JOIN VS4TEmpInOutNote ON (VS4TARAppointment.TARATEmpCode = VS4TEmpInOutNote.TEIOTEmpCode) AND (VS4TARAppointment.TARADate = VS4TEmpInOutNote.TEIODate)) ON VS4TAppointType.TAtyCode = VS4TARAppointment.TARATAtyCode) LEFT JOIN VS4TARAppointComp ON VS4TARAppointment.TARANo = VS4TARAppointComp.TARMTARANo) ON VS4TAR.TARNCode = VS4TARAppointment.TARATARNCode) ON (VS4TCompetSection.TCPSCode = VS4TARAppointComp.TARMTCPSCode) AND (VS4TCompetSection.TCPSTCPTCode = VS4TARAppointComp.TARMTTCPSTCPTCode)) ON VS4TSaleZone.TSZnCode = VS4TSaleArea.TSaeTSZnCode
WHERE (((VS4TEmpInOutNote.TEIOLn)=1))
GO

CREATE VIEW VS4VARAppointment
AS 
SELECT VS4TARAppointment.*, VS4TAR.*, VS4TAR2.*, VS4TSaleArea.*, VS4TSaleZone.*, VS4TAppointType.*, Year(TARADate) AS VARBYear, Month(TARADate) AS VARBMonth, VS4TEmpInOutNote.*, VS4TEmployee.TEmpAliasName
FROM VS4TSaleZone RIGHT JOIN (VS4TEmployee RIGHT JOIN (((VS4TAR LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN VS4TAR2 ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) INNER JOIN (VS4TAppointType RIGHT JOIN (VS4TARAppointment LEFT JOIN VS4TEmpInOutNote ON (VS4TARAppointment.TARATEmpCode = VS4TEmpInOutNote.TEIOTEmpCode) AND (VS4TARAppointment.TARADate = VS4TEmpInOutNote.TEIODate)) ON VS4TAppointType.TAtyCode = VS4TARAppointment.TARATAtyCode) ON VS4TAR.TARNCode = VS4TARAppointment.TARATARNCode) ON VS4TEmployee.TEmpCode = VS4TARAppointment.TARATEmpCode) ON VS4TSaleZone.TSZnCode = VS4TSaleArea.TSaeTSZnCode
WHERE (((VS4TEmpInOutNote.TEIOLn)=1 Or (VS4TEmpInOutNote.TEIOLn)=1 Or (VS4TEmpInOutNote.TEIOLn) Is Null))
GO

CREATE VIEW VS4VARAppointment2
AS 
SELECT VS4VARAppointment.*, VS4VAppCountSum.VACSTotalApp, VS4VAppCountMed.VACMTotalMed, VS4VAppCountCom.VARATotalCompany AS VARATotalCompany, VACMTotalMed*100/VACSTotalApp AS VAC2PCAppMed
FROM ((VS4VARAppointment LEFT JOIN VS4VAppCountCom ON (VS4VARAppointment.VARBYear=VS4VAppCountCom.VARAYear) AND (VS4VARAppointment.VARBMonth=VS4VAppCountCom.VARAMonth) AND (VS4VARAppointment.TARATEmpCode=VS4VAppCountCom.TARATEmpCode)) LEFT JOIN VS4VAppCountMed ON (VS4VARAppointment.VARBMonth=VS4VAppCountMed.VACMMonth) AND (VS4VARAppointment.VARBYear=VS4VAppCountMed.VACMYear) AND (VS4VARAppointment.TARATEmpCode=VS4VAppCountMed.TARATEmpCode)) LEFT JOIN VS4VAppCountSum ON (VS4VARAppointment.TARATEmpCode=VS4VAppCountSum.TARATEmpCode) AND (VS4VARAppointment.VARBMonth=VS4VAppCountSum.VACSMonth) AND (VS4VARAppointment.VARBYear=VS4VAppCountSum.VACSYear)
GO

CREATE VIEW Vs4VARBalance
AS 
SELECT VS4TARBalance.*, VS4TAR.*, VS4TSaleArea.TSAeName, VS4TSaleZone.TSZnCode, VS4TSaleZone.TSZnName, VS4TAR2.TAR2SaleCode, VS4TARHolder.TARHName, VS4TAR2.TAR2TPrvCode, VS4TProvince.TPrvName, VS4TBusinessType.TBstName, VS4TCountry.TCouName, VS4TARGroup.TARGName
FROM VS4TSaleZone RIGHT JOIN ((((((VS4TAR LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode=VS4TSaleArea.TSAeCode) LEFT JOIN VS4TBusinessType ON VS4TAR.TARNTBsTCode=VS4TBusinessType.TBsTCode) LEFT JOIN VS4TCountry ON VS4TAR.TARNTCouCode=VS4TCountry.TCouCode) LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode=VS4TARGroup.TARGCode) LEFT JOIN ((VS4TAR2 LEFT JOIN VS4TARHolder ON VS4TAR2.TAR2SaleCode=VS4TARHolder.TARHCode) LEFT JOIN VS4TProvince ON VS4TAR2.TAR2TPrvCode=VS4TProvince.TPrvCode) ON VS4TAR.TARNCode=VS4TAR2.TAR2TARNCode) INNER JOIN VS4TARBalance ON VS4TAR.TARNCode=VS4TARBalance.TARLTARNCode) ON VS4TSaleZone.TSZnCode=VS4TSaleArea.TSaeTSZnCode
GO

CREATE VIEW VS4VARBill
AS 
SELECT VS4TARBill.*, VS4TARBillMB.*, VS4TAR.TARNName, VS4TAR2.TAR2SaleCode, VS4TEmployee.TEmpFullName, VS4TAR2.TAR2TPrvCode, VS4TProvince.TPrvName, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TBranch.TBraName, VS4TAR.TARNTARGCode, VS4TARGroup.TARGName, VS4TAR.TARNTBsTCode, VS4TBusinessType.TBstName, VS4TAR.TARNTSAeCode, VS4TSaleArea.TSAeName, VS4TAR.TARNTCouCode, VS4TCountry.TCouName, VS4TEmployee.TEmpCode, VS4TARInvoice.TIvoRefNo, VS4TARInvoice.TIvoRefDate, VS4TARInvoice.TIvoRefNo2, VS4TARInvoice.TIvoRefDate2, VS4TARInvoice.TIvoPONo, VS4TARInvoice.TIvoSOCode, VS4TARInvoice.TIvoCustom1, VS4TARInvoice.TIvoCustom2, VS4TARInvoice.TIvoCustom3, VS4TARInvoice.TIvoCustom4, VS4TARInvoice.TIvoCustom5, VS4TARInvoice.TIvoDescription, VS4TARInvoice.TIvoCusAddress, VS4TARInvoice.TIvoType, VS4TARInvoice.TIvoVATTotal, VS4TARInvoice.TIvoVATRate, VS4TARDebitNote.TDBNNo, VS4TARDebitNote.TDBNTIvoNo, VS4TARDebitNote.TDBNVATType, VS4TARDebitNote.TDBNVATRate, VS4TARDebitNote.TDBNTaxBase, VS4TARDebitNote.TDBNVATTotal, VS4TARDebitNote.TDBNGrandTotal, VS4TARCreditNote.TRCNNo, VS4TARCreditNote.TRCNTIvoNo, VS4TARCreditNote.TRCNVATType, VS4TARCreditNote.TRCNVATRate, VS4TARCreditNote.TRCNTaxBase, VS4TARCreditNote.TRCNVATTotal, VS4TARCreditNote.TRCNGrandTotal, VS4TBranch.TBraAddressBill
FROM ((((((((VS4TARBill LEFT JOIN VS4TAR ON VS4TARBill.TBilTARNCode = VS4TAR.TARNCode) LEFT JOIN VS4TProject ON VS4TARBill.TBilTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TARBill.TBilTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) LEFT JOIN VS4TBusinessType ON VS4TAR.TARNTBsTCode = VS4TBusinessType.TBsTCode) LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN VS4TCountry ON VS4TAR.TARNTCouCode = VS4TCountry.TCouCode) LEFT JOIN ((VS4TAR2 LEFT JOIN VS4TEmployee ON VS4TAR2.TAR2SaleCode = VS4TEmployee.TEmpCode) LEFT JOIN VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) INNER JOIN (((VS4TARBillMB LEFT JOIN VS4TARInvoice ON VS4TARBillMB.TBMBRefNo2 = VS4TARInvoice.TIvoNo) LEFT JOIN VS4TARDebitNote ON VS4TARBillMB.TBMBRefNo2 = VS4TARDebitNote.TDBNNo) LEFT JOIN VS4TARCreditNote ON VS4TARBillMB.TBMBRefNo2 = VS4TARCreditNote.TRCNNo) ON VS4TARBill.TBilNo = VS4TARBillMB.TBMBTBilNo
GO

CREATE VIEW VS4VARBillIVDBCN
AS 
SELECT VS4TARBill.*, VS4TARBillMB.*, VS4TAR.TARNName, VS4TAR2.TAR2SaleCode, VS4TEmployee.TEmpFullName, VS4TAR2.TAR2TPrvCode, VS4TProvince.TPrvName, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TBranch.TBraName, VS4TAR.TARNTARGCode, VS4TARGroup.TARGName, VS4TAR.TARNTBsTCode, VS4TBusinessType.TBstName, VS4TAR.TARNTSAeCode, VS4TSaleArea.TSAeName, VS4TAR.TARNTCouCode, VS4TCountry.TCouName, VS4TEmployee.TEmpCode, VS4TARInvoice.TIvoRefNo, VS4TARInvoice.TIvoRefDate, VS4TARInvoice.TIvoRefNo2, VS4TARInvoice.TIvoRefDate2, VS4TARInvoice.TIvoPONo, VS4TARInvoice.TIvoSOCode, VS4TARInvoice.TIvoCustom1, VS4TARInvoice.TIvoCustom2, VS4TARInvoice.TIvoCustom3, VS4TARInvoice.TIvoCustom4, VS4TARInvoice.TIvoCustom5, VS4TARInvoice.TIvoDescription, VS4TARInvoice.TIvoCusAddress, VS4TARInvoice.TIvoType, VS4TARInvoiceMB.TIoMTPOSCode, VS4TARInvoiceMB.TIoMPOSName, VS4TARInvoiceMB.TIoMQuantity, VS4TARInvoiceMB.TIoMTUntCode, VS4TARInvoiceMB.TIoMPrice, VS4TARInvoiceMB.TIoMAmount, VS4TARCreditNoteMB.TRCMTPOSCode, VS4TARCreditNoteMB.TRCMPOSName, VS4TARCreditNoteMB.TRCMPrice, VS4TARCreditNoteMB.TRCMQuantity, VS4TARCreditNoteMB.TRCMTUntCode, VS4TARCreditNoteMB.TRCMAmount, VS4TARDebitNoteMB.TDBMTPOSCode, VS4TARDebitNoteMB.TDBMPOSName, VS4TARDebitNoteMB.TDBMPrice, VS4TARDebitNoteMB.TDBMQuantity, VS4TARDebitNoteMB.TDBMTUntCode, VS4TARDebitNoteMB.TDBMAmount, VS4TARInvoiceMB.TIoMPerQuantity, VS4TARInvoice.TIvoDiscountText, VS4TARInvoice.TIvoDiscountTotal, VS4TARInvoice.TIvoTaxBase, VS4TARInvoice.TIvoVATTotal, VS4TARInvoice.TIvoGrandTotal, VS4TARInvoice.TIvoDepositText, VS4TARInvoice.TIvoVATRate
FROM (((((((((VS4TARBill LEFT JOIN VS4TAR ON VS4TARBill.TBilTARNCode = VS4TAR.TARNCode) LEFT JOIN VS4TProject ON VS4TARBill.TBilTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TARBill.TBilTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) LEFT JOIN VS4TBusinessType ON VS4TAR.TARNTBsTCode = VS4TBusinessType.TBsTCode) LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN VS4TCountry ON VS4TAR.TARNTCouCode = VS4TCountry.TCouCode) LEFT JOIN ((VS4TAR2 LEFT JOIN VS4TEmployee ON VS4TAR2.TAR2SaleCode = VS4TEmployee.TEmpCode) LEFT JOIN VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) INNER JOIN (((((VS4TARBillMB LEFT JOIN VS4TARInvoice ON VS4TARBillMB.TBMBRefNo2 = VS4TARInvoice.TIvoNo) LEFT JOIN VS4TARCreditNote ON VS4TARBillMB.TBMBRefNo2 = VS4TARCreditNote.TRCNNo) LEFT JOIN VS4TARDebitNote ON VS4TARBillMB.TBMBRefNo2 = VS4TARDebitNote.TDBNNo) LEFT JOIN VS4TARCreditNoteMB ON VS4TARCreditNote.TRCNNo = VS4TARCreditNoteMB.TRCMTRCNNo) LEFT JOIN VS4TARDebitNoteMB ON VS4TARDebitNote.TDBNNo = VS4TARDebitNoteMB.TDBMTDBNNo) ON VS4TARBill.TBilNo = VS4TARBillMB.TBMBTBilNo) LEFT JOIN VS4TARInvoiceMB ON VS4TARInvoice.TIvoNo = VS4TARInvoiceMB.TIoMTIvoNo
GO

CREATE VIEW VS4VARCard
AS 
SELECT VS4TARCard.*, VS4TAR.TARNCode, VS4TAR.TARNName, VS4TAR.TARNIntroName, VS4TBranch.TBraName, VS4TAR.TARNTBsTCode, VS4TBusinessType.TBstName, VS4TAR.TARNTSAeCode, VS4TSaleArea.TSAeName, VS4TAR.TARNTCouCode, VS4TCountry.TCouName, VS4TAR2.TAR2TPrvCode, VS4TProvince.TPrvName, VS4TAR2.TAR2SaleCode, VS4TARHolder.TARHName, VS4TAR.TARNTARGCode, VS4TARGroup.TARGName, VS4TARInvoice.TIvoDate, VS4TARInvoice.TIvoTaxBase, VS4TARInvoice.TIvoVATTotal, VS4TARInvoice.TIvoGrandTotal, VS4TARDebitNote.TDBNDate, VS4TARDebitNote.TDBNTaxBase, VS4TARDebitNote.TDBNVATTotal, VS4TARDebitNote.TDBNGrandTotal, VS4TARCreditNote.TRCNDate, VS4TARCreditNote.TRCNTaxBase, VS4TARCreditNote.TRCNVATTotal, VS4TARCreditNote.TRCNGrandTotal, VS4TARInvoice.TIvoRefNo, VS4TARCreditNote.TRCNTIvoNo, VS4TARDebitNote.TDBNTIvoNo, VS4TARInvoice.TIvoSubTotal, VS4TARCreditNote.TRCNSubTotal, VS4TARDebitNote.TDBNSubTotal, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TEmployee.TEmpFullName, VS4TAR.TARNName2, VS4TARInvoice.TIvoTCurCode, VS4TARInvoice.TIvoExchangeRate, VS4TARCreditNote.TRCNTCurCode, VS4TARCreditNote.TRCNExchangeRate, VS4TARDebitNote.TDBNTCurCode, VS4TARDebitNote.TDBNExchangeRate, VS4TARBalance.TARLBeginBalance, VS4TARBalance.TARLEndBalance, VS4TARInvoice.TIvoPaymentNote, VS4TARInvoice.TIvoConditionDay, VS4TARInvoice.TIvoSaleName, VS4TARCreditNote.TRCNSaleName, VS4TARDebitNote.TDBNSaleName, VS4TARBalance.TARLMode, VS4TARInvoice.TIvoArrears, VS4TARCreditNote.TRCNArrears, VS4TARDebitNote.TDBNArrears, VS4TARInvoice.TIvoType, VS4TAccountPeriod.TACPStartDate, VS4TAccountPeriod.TACPEndDate, VS4TARBalance.TARLPayOther, VS4TARBalance.TARLPayMisc, VS4TARBalance.TARLPayCoupon, VS4TEmployee.TEmpFullName2, VS4TEmployee_1.TEmpFullName2 AS VARCIVEMPNAME2, VS4TEmployee_3.TEmpFullName2 AS VARCCNNAME2, VS4TEmployee_2.TEmpFullName2 AS VARCDBNAME2, VS4TARInvoice.TIvoIgnoreArrears, VS4TARInvoice.TIvoDestination
FROM (((((VS4TAR LEFT JOIN VS4TBusinessType ON VS4TAR.TARNTBsTCode = VS4TBusinessType.TBsTCode) LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN VS4TCountry ON VS4TAR.TARNTCouCode = VS4TCountry.TCouCode) LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) LEFT JOIN (((VS4TAR2 LEFT JOIN VS4TARHolder ON VS4TAR2.TAR2SaleCode = VS4TARHolder.TARHCode) LEFT JOIN VS4TEmployee ON VS4TAR2.TAR2SaleCode = VS4TEmployee.TEmpCode) LEFT JOIN VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) INNER JOIN (VS4TAccountPeriod RIGHT JOIN (((((((((VS4TARCard LEFT JOIN VS4TBranch ON VS4TARCard.TRICTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TARDebitNote ON VS4TARCard.TRICDocNo = VS4TARDebitNote.TDBNNo) LEFT JOIN VS4TARCreditNote ON VS4TARCard.TRICDocNo = VS4TARCreditNote.TRCNNo) LEFT JOIN VS4TARInvoice ON VS4TARCard.TRICDocNo = VS4TARInvoice.TIvoNo) LEFT JOIN VS4TProject ON VS4TARCard.TRICTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TARBalance ON (VS4TARCard.TRICTARNCode = VS4TARBalance.TARLTARNCode) AND (VS4TARCard.TRICTACPID = VS4TARBalance.TARLTACPID) AND (VS4TARCard.TRICTACPTACYID = VS4TARBalance.TARLTACPTACYID)) LEFT JOIN VS4TEmployee AS VS4TEmployee_1 ON VS4TARInvoice.TIvoTEmpCode = VS4TEmployee_1.TEmpCode) LEFT JOIN VS4TEmployee AS VS4TEmployee_2 ON VS4TARDebitNote.TDBNTEmpCode = VS4TEmployee_2.TEmpCode) LEFT JOIN VS4TEmployee AS VS4TEmployee_3 ON VS4TARCreditNote.TRCNTEmpCode = VS4TEmployee_3.TEmpCode) ON (VS4TAccountPeriod.TACPID = VS4TARBalance.TARLTACPID) AND (VS4TAccountPeriod.TACPTACYID = VS4TARBalance.TARLTACPTACYID)) ON VS4TAR.TARNCode = VS4TARCard.TRICTARNCode
WHERE (((VS4TARCard.TRICType)<>'O'))
GO

CREATE VIEW VS4VARCardCredit
AS 
SELECT VS4TARCard.*, VS4TAR.TARNCode, VS4TAR.TARNName, VS4TAR.TARNIntroName, VS4TARBalance.*, VS4TAccountPeriod.*, VS4TBranch.TBraName, VS4TAR.TARNTBsTCode, VS4TBusinessType.TBstName, VS4TAR.TARNTSAeCode, VS4TSaleArea.TSAeName, VS4TAR.TARNTCouCode, VS4TCountry.TCouName, VS4TAR2.TAR2TPrvCode, VS4TProvince.TPrvName, VS4TAR2.TAR2SaleCode, VS4TARHolder.TARHName, VS4TAR.TARNTARGCode, VS4TARGroup.TARGName, VS4TAR.TARNAddressBill, VS4TAR.TARNContactName, VS4TARInvoice.TIvoBillStatus, VS4TSO.TSODDeliveryStatus, VS4TARInvoice.tivoignorearrears
FROM (((((VS4TAR LEFT JOIN VS4TBusinessType ON VS4TAR.TARNTBsTCode = VS4TBusinessType.TBsTCode) LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN VS4TCountry ON VS4TAR.TARNTCouCode = VS4TCountry.TCouCode) LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) LEFT JOIN ((VS4TAR2 LEFT JOIN VS4TARHolder ON VS4TAR2.TAR2SaleCode = VS4TARHolder.TARHCode) LEFT JOIN VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) INNER JOIN (VS4TAccountPeriod INNER JOIN ((((VS4TARCard INNER JOIN VS4TARBalance ON (VS4TARCard.TRICTACPTACYID = VS4TARBalance.TARLTACPTACYID) AND (VS4TARCard.TRICTACPID = VS4TARBalance.TARLTACPID) AND (VS4TARCard.TRICTARNCode = VS4TARBalance.TARLTARNCode)) LEFT JOIN VS4TBranch ON VS4TARCard.TRICTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TARInvoice ON VS4TARCard.TRICDocNo = VS4TARInvoice.TIvoNo) LEFT JOIN VS4TSO ON VS4TARCard.TRICDocNo = VS4TSO.TSODNo) ON (VS4TAccountPeriod.TACPID = VS4TARBalance.TARLTACPID) AND (VS4TAccountPeriod.TACPTACYID = VS4TARBalance.TARLTACPTACYID)) ON VS4TAR.TARNCode = VS4TARCard.TRICTARNCode
GO

CREATE VIEW VS4VARCardCRV
AS 
SELECT VS4TARCard.*, VS4TAR.TARNCode, VS4TAR.TARNName, VS4TAR.TARNIntroName, VS4TARBalance.*, VS4TAccountPeriod.*, VS4TBranch.TBraName, VS4TAR.TARNTBsTCode, VS4TBusinessType.TBstName, VS4TAR.TARNTSAeCode, VS4TSaleArea.TSAeName, VS4TAR.TARNTCouCode, VS4TCountry.TCouName, VS4TAR2.TAR2TPrvCode, VS4TProvince.TPrvName, VS4TAR2.TAR2SaleCode, VS4TARHolder.TARHName, VS4TAR.TARNTARGCode, VS4TARGroup.TARGName, VS4TARVDocRef.TRDRTRVHNo, VS4TARVDocRef.TRDRRefDocType, VS4TARVDocRef.TRDRAmountRate, VS4TARDebitNote.TDBNArrears, VS4TARCreditNote.TRCNArrears, VS4TARVoucher.TRVHCancelStatus, VS4TARInvoice.TIvoArrears, VS4TARVoucher.TRVHNo, VS4TARVoucher.TRVHType, VS4TARVoucher.TRVHDate, VS4TARInvoice.tivoignorearrears
FROM (((((VS4TAR LEFT JOIN VS4TBusinessType ON VS4TAR.TARNTBsTCode = VS4TBusinessType.TBsTCode) LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN VS4TCountry ON VS4TAR.TARNTCouCode = VS4TCountry.TCouCode) LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) LEFT JOIN ((VS4TAR2 LEFT JOIN VS4TARHolder ON VS4TAR2.TAR2SaleCode = VS4TARHolder.TARHCode) LEFT JOIN VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) INNER JOIN (VS4TAccountPeriod INNER JOIN (((VS4TARCard INNER JOIN VS4TARBalance ON (VS4TARCard.TRICTARNCode = VS4TARBalance.TARLTARNCode) AND (VS4TARCard.TRICTACPID = VS4TARBalance.TARLTACPID) AND (VS4TARCard.TRICTACPTACYID = VS4TARBalance.TARLTACPTACYID)) LEFT JOIN VS4TBranch ON VS4TARCard.TRICTBraCode = VS4TBranch.TBraCode) LEFT JOIN ((((VS4TARVDocRef LEFT JOIN VS4TARDebitNote ON VS4TARVDocRef.TRDRRefDocNo = VS4TARDebitNote.TDBNNo) LEFT JOIN VS4TARCreditNote ON VS4TARVDocRef.TRDRRefDocNo = VS4TARCreditNote.TRCNNo) LEFT JOIN VS4TARInvoice ON VS4TARVDocRef.TRDRRefDocNo = VS4TARInvoice.TIvoNo) LEFT JOIN VS4TARVoucher ON VS4TARVDocRef.TRDRTRVHNo = VS4TARVoucher.TRVHNo) ON VS4TARCard.TRICDocNo = VS4TARVDocRef.TRDRTRVHNo) ON (VS4TAccountPeriod.TACPID = VS4TARBalance.TARLTACPID) AND (VS4TAccountPeriod.TACPTACYID = VS4TARBalance.TARLTACPTACYID)) ON VS4TAR.TARNCode = VS4TARCard.TRICTARNCode
WHERE (((VS4TARCard.TRICType)<>'O'))
GO

CREATE VIEW VS4VARCardIVDBCN
AS 
SELECT VS4TARCard.*, VS4TAR.TARNCode, VS4TAR.TARNName, VS4TAR.TARNIntroName, VS4TBranch.TBraName, VS4TAR.TARNTBsTCode, VS4TBusinessType.TBstName, VS4TAR.TARNTSAeCode, VS4TSaleArea.TSAeName, VS4TAR.TARNTCouCode, VS4TCountry.TCouName, VS4TAR2.TAR2TPrvCode, VS4TProvince.TPrvName, VS4TAR2.TAR2SaleCode, VS4TARHolder.TARHName, VS4TAR.TARNTARGCode, VS4TARGroup.TARGName, VS4TARInvoice.TIvoDate, VS4TARInvoice.TIvoTaxBase, VS4TARInvoice.TIvoVATTotal, VS4TARInvoice.TIvoGrandTotal, VS4TARDebitNote.TDBNDate, VS4TARDebitNote.TDBNTaxBase, VS4TARDebitNote.TDBNVATTotal, VS4TARDebitNote.TDBNGrandTotal, VS4TARCreditNote.TRCNDate, VS4TARCreditNote.TRCNTaxBase, VS4TARCreditNote.TRCNVATTotal, VS4TARCreditNote.TRCNGrandTotal, VS4TARInvoice.TIvoRefNo, VS4TARCreditNote.TRCNTIvoNo, VS4TARDebitNote.TDBNTIvoNo, VS4TARInvoice.TIvoSubTotal, VS4TARCreditNote.TRCNSubTotal, VS4TARDebitNote.TDBNSubTotal, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TEmployee.TEmpFullName, VS4TAR.TARNName2, VS4TARInvoice.TIvoTCurCode, VS4TARInvoice.TIvoExchangeRate, VS4TARCreditNote.TRCNTCurCode, VS4TARCreditNote.TRCNExchangeRate, VS4TARDebitNote.TDBNTCurCode, VS4TARDebitNote.TDBNExchangeRate, VS4TARBalance.TARLBeginBalance, VS4TARBalance.TARLEndBalance, VS4TARInvoice.TIvoExchangeRate2, VS4TARInvoice.TIvoDestination, VS4TARInvoice.tivoignorearrears, VS4TARInvoice.TIvoInsurance, VS4TARInvoice.TIvoFreightFee, VS4TARInvoice.TIvoCardFlag, VS4TEmployee_1.TEmpFullName2 AS VARCIVEMPNAME2, VS4TEmployee_2.TEmpFullName2 AS VARCDBNAME2, VS4TEmployee_3.TEmpFullName2 AS VARCCNNAME2, VS4TARInvoice.TIvoTotalQuantity, VS4TGLTrans.TGLTTGLBCode
FROM (((((VS4TAR LEFT JOIN VS4TBusinessType ON VS4TAR.TARNTBsTCode = VS4TBusinessType.TBsTCode) LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN VS4TCountry ON VS4TAR.TARNTCouCode = VS4TCountry.TCouCode) LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) LEFT JOIN (((VS4TAR2 LEFT JOIN VS4TARHolder ON VS4TAR2.TAR2SaleCode = VS4TARHolder.TARHCode) LEFT JOIN VS4TEmployee ON VS4TAR2.TAR2SaleCode = VS4TEmployee.TEmpCode) LEFT JOIN VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) INNER JOIN (VS4TAccountPeriod RIGHT JOIN ((((((((((VS4TARCard LEFT JOIN VS4TBranch ON VS4TARCard.TRICTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TARDebitNote ON VS4TARCard.TRICDocNo = VS4TARDebitNote.TDBNNo) LEFT JOIN VS4TARCreditNote ON VS4TARCard.TRICDocNo = VS4TARCreditNote.TRCNNo) LEFT JOIN VS4TARInvoice ON VS4TARCard.TRICDocNo = VS4TARInvoice.TIvoNo) LEFT JOIN VS4TProject ON VS4TARCard.TRICTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TARBalance ON (VS4TARCard.TRICTARNCode = VS4TARBalance.TARLTARNCode) AND (VS4TARCard.TRICTACPTACYID = VS4TARBalance.TARLTACPTACYID) AND (VS4TARCard.TRICTACPID = VS4TARBalance.TARLTACPID)) LEFT JOIN VS4TEmployee AS VS4TEmployee_1 ON VS4TARInvoice.TIvoTEmpCode = VS4TEmployee_1.TEmpCode) LEFT JOIN VS4TEmployee AS VS4TEmployee_2 ON VS4TARDebitNote.TDBNTEmpCode = VS4TEmployee_2.TEmpCode) LEFT JOIN VS4TEmployee AS VS4TEmployee_3 ON VS4TARCreditNote.TRCNTEmpCode = VS4TEmployee_3.TEmpCode) LEFT JOIN VS4TGLTrans ON VS4TARCard.TRICTGLTNo = VS4TGLTrans.TGLTNo) ON (VS4TAccountPeriod.TACPID = VS4TARBalance.TARLTACPID) AND (VS4TAccountPeriod.TACPTACYID = VS4TARBalance.TARLTACPTACYID)) ON VS4TAR.TARNCode = VS4TARCard.TRICTARNCode
WHERE (((VS4TARCard.TRICType)<>'O'))
GO

CREATE VIEW VS4VARCardIVDBCNMB
AS 
SELECT VS4TARCard.*, VS4TAR.TARNCode, VS4TAR.TARNName, VS4TAR.TARNIntroName, VS4TBranch.TBraName, VS4TAR.TARNTBsTCode, VS4TBusinessType.TBstName, VS4TAR.TARNTSAeCode, VS4TSaleArea.TSAeName, VS4TAR.TARNTCouCode, VS4TCountry.TCouName, VS4TAR2.TAR2TPrvCode, VS4TProvince.TPrvName, VS4TAR2.TAR2SaleCode, VS4TARHolder.TARHName, VS4TAR.TARNTARGCode, VS4TARGroup.TARGName, VS4TARInvoice.TIvoDate, VS4TARInvoice.TIvoTaxBase, VS4TARInvoice.TIvoVATTotal, VS4TARInvoice.TIvoGrandTotal, VS4TARDebitNote.TDBNDate, VS4TARDebitNote.TDBNTaxBase, VS4TARDebitNote.TDBNVATTotal, VS4TARDebitNote.TDBNGrandTotal, VS4TARCreditNote.TRCNDate, VS4TARCreditNote.TRCNTaxBase, VS4TARCreditNote.TRCNVATTotal, VS4TARCreditNote.TRCNGrandTotal, VS4TARInvoice.TIvoRefNo, VS4TARCreditNote.TRCNTIvoNo, VS4TARDebitNote.TDBNTIvoNo, VS4TARInvoice.TIvoSubTotal, VS4TARCreditNote.TRCNSubTotal, VS4TARDebitNote.TDBNSubTotal, VS4TARInvoice.TIvoExchangeRate, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TEmployee.TEmpFullName, VS4TARInvoiceMB.TIoMTPOSCode, VS4TARInvoiceMB.TIoMPOSName, VS4TARInvoiceMB.TIoMSerialNo, VS4TARInvoiceMB.TIoMCustom1, VS4TARInvoiceMB.TIoMCustom2, VS4TARInvoiceMB.TIoMCustom3, VS4TARInvoiceMB.TIoMCost, VS4TARInvoiceMB.TIoMPrice, VS4TARInvoiceMB.TIoMPerQuantity, VS4TARInvoiceMB.TIoMQuantityCalc, VS4TARInvoiceMB.TIoMQuantity, VS4TARInvoiceMB.TIoMTUntCode, VS4TARDebitNoteMB.TDBMTPOSCode, VS4TARDebitNoteMB.TDBMSerialNo, VS4TARDebitNoteMB.TDBMCustom1, VS4TARDebitNoteMB.TDBMCustom2, VS4TARDebitNoteMB.TDBMCustom3, VS4TARDebitNoteMB.TDBMCost, VS4TARDebitNoteMB.TDBMPrice, VS4TARDebitNoteMB.TDBMOldPrice, VS4TARDebitNoteMB.TDBMNewPrice, VS4TARDebitNoteMB.TDBMQuantityCalc, VS4TARDebitNoteMB.TDBMQuantity, VS4TARDebitNoteMB.TDBMTUntCode, VS4TARCreditNoteMB.TRCMTPOSCode, VS4TARCreditNoteMB.TRCMSerialNo, VS4TARCreditNoteMB.TRCMCustom1, VS4TARCreditNoteMB.TRCMCustom2, VS4TARCreditNoteMB.TRCMCustom3, VS4TARCreditNoteMB.TRCMPOSName, VS4TARDebitNoteMB.TDBMPOSName, VS4TARCreditNoteMB.TRCMCost, VS4TARCreditNoteMB.TRCMOldPrice, VS4TARCreditNoteMB.TRCMNewPrice, VS4TARCreditNoteMB.TRCMPrice, VS4TARCreditNoteMB.TRCMQuantityCalc, VS4TARCreditNoteMB.TRCMQuantity, VS4TARCreditNoteMB.TRCMTUntCode, VS4TARCreditNoteMB.TRCMReturnFlag, VS4TARInvoiceMB.TIoMTaxBase, VS4TARInvoiceMB.TIoMAmountVAT, VS4TARInvoiceMB.TIoMTaxType, VS4TARInvoiceMB.TIoMCostAmount, VS4TARCreditNoteMB.TRCMCostAmount, VS4TARCreditNoteMB.TRCMTaxBase, VS4TARCreditNoteMB.TRCMAmountVAT, VS4TARCreditNoteMB.TRCMGrandTotal, VS4TARDebitNoteMB.TDBMCostAmount, VS4TARDebitNoteMB.TDBMTaxBase, VS4TARDebitNoteMB.TDBMAmountVAT, VS4TARDebitNoteMB.TDBMGrandTotal, VS4TProductSec2.TPS2Code, VS4TProductSec2.TPS2Name, VS4TAR.TARNName2, VS4TARInvoice.TIvoTCurCode, VS4TARCreditNote.TRCNTCurCode, VS4TARCreditNote.TRCNExchangeRate, VS4TARDebitNote.TDBNTCurCode, VS4TARDebitNote.TDBNExchangeRate, VS4TARInvoice.TIvoDestination, VS4TARInvoice.TIvoExchangeRate2, VS4TProduct.TPdtStandardCost, VS4TProduct_1.TPdtStandardCost AS VICDCNStdCost, VS4TEmployee_1.TEmpFullName2 AS VARCIVEMPNAME2, VS4TEmployee_2.TEmpFullName2 AS VARCDBNAME2, VS4TEmployee_3.TEmpFullName2 AS VARCCNNAME2, VS4TARInvoice.TIvoInsurance, VS4TARInvoice.TIvoFreightFee, VS4TARInvoiceMB.TIoMNetAmount, VS4TARCreditNoteMB.TRCMNetAmount, VS4TARDebitNoteMB.TDBMNetAmount, VS4TARInvoice.TIvoCardFlag, VS4TARInvoice.tivoignorearrears, VS4TGLTrans.TGLTTGLBCode
FROM (((((((VS4TAR LEFT JOIN VS4TBusinessType ON VS4TAR.TARNTBsTCode = VS4TBusinessType.TBsTCode) LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN VS4TCountry ON VS4TAR.TARNTCouCode = VS4TCountry.TCouCode) LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) LEFT JOIN (((VS4TAR2 LEFT JOIN VS4TARHolder ON VS4TAR2.TAR2SaleCode = VS4TARHolder.TARHCode) LEFT JOIN VS4TEmployee ON VS4TAR2.TAR2SaleCode = VS4TEmployee.TEmpCode) LEFT JOIN VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) INNER JOIN ((((((((((VS4TARCard LEFT JOIN VS4TBranch ON VS4TARCard.TRICTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TARDebitNote ON VS4TARCard.TRICDocNo = VS4TARDebitNote.TDBNNo) LEFT JOIN VS4TARCreditNote ON VS4TARCard.TRICDocNo = VS4TARCreditNote.TRCNNo) LEFT JOIN VS4TARInvoice ON VS4TARCard.TRICDocNo = VS4TARInvoice.TIvoNo) LEFT JOIN VS4TProject ON VS4TARCard.TRICTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TEmployee AS VS4TEmployee_1 ON VS4TARInvoice.TIvoTEmpCode = VS4TEmployee_1.TEmpCode) LEFT JOIN VS4TEmployee AS VS4TEmployee_2 ON VS4TARDebitNote.TDBNTEmpCode = VS4TEmployee_2.TEmpCode) LEFT JOIN VS4TEmployee AS VS4TEmployee_3 ON VS4TARCreditNote.TRCNTEmpCode = VS4TEmployee_3.TEmpCode) LEFT JOIN (VS4TARCreditNoteMB LEFT JOIN VS4TProduct AS VS4TProduct_1 ON VS4TARCreditNoteMB.TRCMTPOSCode = VS4TProduct_1.TPdtCode) ON VS4TARCreditNote.TRCNNo = VS4TARCreditNoteMB.TRCMTRCNNo) LEFT JOIN VS4TARDebitNoteMB ON VS4TARDebitNote.TDBNNo = VS4TARDebitNoteMB.TDBMTDBNNo) ON VS4TAR.TARNCode = VS4TARCard.TRICTARNCode) LEFT JOIN ((VS4TARInvoiceMB LEFT JOIN VS4TPOS ON VS4TARInvoiceMB.TIoMTPOSCode = VS4TPOS.TPOSCode) LEFT JOIN (VS4TProduct LEFT JOIN VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code) ON VS4TPOS.TPOSCode = VS4TProduct.TPdtCode) ON VS4TARInvoice.TIvoNo = VS4TARInvoiceMB.TIoMTIvoNo) LEFT JOIN VS4TGLTrans ON VS4TARCard.TRICTGLTNo = VS4TGLTrans.TGLTNo
WHERE (((VS4TARInvoice.TIvoCardFlag)<>0) AND ((VS4TARCard.TRICType)<>'O') AND ((VS4TARInvoice.TIvoType)<>5))
GO

CREATE VIEW VS4VARChild1
AS 
SELECT VS4TARChild.TAChTARNCode, VS4TARChild.TAChLn, VS4TARChild.TAChTitleName, VS4TARChild.TAChFirstName, VS4TARChild.TAChLastName, VS4TARChild.TAChBirthday, VS4TARChild.TAChIDno, VS4TARChild.TAChBoneZone, VS4TARChild.TAChNational, VS4TARChild.TAChLiveWithYou
FROM VS4TARChild
WHERE (((VS4TARChild.TAChLn)=1) AND ((VS4TARChild.TAChFlag1)=1))
GO

CREATE VIEW VS4VARCodeFromATS
AS 
SELECT VS4TAR.TARNCode, VS4TAR.TARNName, VS4TAR.TARNName2, VS4TAR.TARNIntroName, VS4TAR.TARNFlag1, VS4TAR2.TAR2SaleCode
FROM (VS4TInventory INNER JOIN VS4TAR ON VS4TInventory.TInvTARNCode=VS4TAR.TARNCode) LEFT JOIN VS4TAR2 ON VS4TAR.TARNCode=VS4TAR2.TAR2TARNCode
GROUP BY VS4TAR.TARNCode, VS4TAR.TARNName, VS4TAR.TARNName2, VS4TAR.TARNIntroName, VS4TAR.TARNFlag1, VS4TAR2.TAR2SaleCode, VS4TInventory.TInvApproveStatus, VS4TInventory.TInvCancelStatus
HAVING (((VS4TInventory.TInvApproveStatus)=1) AND ((VS4TInventory.TInvCancelStatus)=0))
GO

CREATE VIEW VS4VARCodeFromBill
AS 
SELECT VS4TAR.TARNCode, VS4TAR.TARNName, VS4TAR.TARNName2, VS4TAR.TARNIntroName, VS4TAR.TARNFlag1, VS4TAR2.TAR2SaleCode
FROM (VS4TAR LEFT JOIN VS4TAR2 ON VS4TAR.TARNCode=VS4TAR2.TAR2TARNCode) INNER JOIN VS4TARBill ON VS4TAR.TARNCode=VS4TARBill.TBilTARNCode
GROUP BY VS4TAR.TARNCode, VS4TAR.TARNName, VS4TAR.TARNName2, VS4TAR.TARNIntroName, VS4TAR.TARNFlag1, VS4TAR2.TAR2SaleCode, VS4TARBill.TBilConfirmStatus, VS4TARBill.TBilApproveStatus, VS4TARBill.TBilCancelStatus
HAVING (((VS4TARBill.TBilConfirmStatus)=1) AND ((VS4TARBill.TBilApproveStatus)=1) AND ((VS4TARBill.TBilCancelStatus)<>1))
GO

CREATE VIEW VS4VARCodeFromBO
AS 
SELECT VS4TAR.TARNCode, VS4TAR.TARNName, VS4TAR.TARNName2, VS4TAR.TARNIntroName, VS4TAR.TARNFlag1, VS4TAR2.TAR2SaleCode
FROM (VS4TAR LEFT JOIN VS4TAR2 ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) INNER JOIN VS4TARInvoice ON VS4TAR.TARNCode = VS4TARInvoice.TIvoTARNCode
GROUP BY VS4TAR.TARNCode, VS4TAR.TARNName, VS4TAR.TARNName2, VS4TAR.TARNIntroName, VS4TAR.TARNFlag1, VS4TAR2.TAR2SaleCode, VS4TARInvoice.TIvoConfirmStatus, VS4TARInvoice.TIvoApproveStatus, VS4TARInvoice.TIvoCancelStatus, VS4TARInvoice.TIvoType
HAVING (((VS4TARInvoice.TIvoConfirmStatus)=1) AND ((VS4TARInvoice.TIvoApproveStatus)=1) AND ((VS4TARInvoice.TIvoCancelStatus)=0) AND ((VS4TARInvoice.TIvoType)=5))
GO

CREATE VIEW VS4VARCodeFromINV
AS 
SELECT VS4TAR.TARNCode, VS4TAR.TARNName, VS4TAR.TARNName2, VS4TAR.TARNIntroName, VS4TAR.TARNFlag1, VS4TAR2.TAR2SaleCode
FROM (VS4TAR LEFT JOIN VS4TAR2 ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) INNER JOIN VS4TARInvoice ON VS4TAR.TARNCode = VS4TARInvoice.TIvoTARNCode
GROUP BY VS4TAR.TARNCode, VS4TAR.TARNName, VS4TAR.TARNName2, VS4TAR.TARNIntroName, VS4TAR.TARNFlag1, VS4TAR2.TAR2SaleCode, VS4TARInvoice.TIvoArrears, VS4TARInvoice.TIvoConfirmStatus, VS4TARInvoice.TIvoApproveStatus, VS4TARInvoice.TIvoCancelStatus
HAVING (((VS4TARInvoice.TIvoArrears)<>0) AND ((VS4TARInvoice.TIvoConfirmStatus)=1) AND ((VS4TARInvoice.TIvoApproveStatus)=1) AND ((VS4TARInvoice.TIvoCancelStatus)<>1))
GO

CREATE VIEW VS4VARCodeFromQT
AS 
SELECT VS4TAR.TARNCode, VS4TAR.TARNName, VS4TAR.TARNName2, VS4TAR.TARNIntroName, VS4TAR.TARNFlag1, VS4TAR2.TAR2SaleCode
FROM (VS4TAR LEFT JOIN VS4TAR2 ON VS4TAR.TARNCode=VS4TAR2.TAR2TARNCode) INNER JOIN VS4TQuotation ON VS4TAR.TARNCode=VS4TQuotation.TQuoTARNCode
GROUP BY VS4TAR.TARNCode, VS4TAR.TARNName, VS4TAR.TARNName2, VS4TAR.TARNIntroName, VS4TAR.TARNFlag1, VS4TAR2.TAR2SaleCode, VS4TQuotation.TQuoConfirmStatus, VS4TQuotation.TQuoApproveStatus, VS4TQuotation.TQuoCancelStatus
HAVING (((VS4TQuotation.TQuoConfirmStatus)=1) AND ((VS4TQuotation.TQuoApproveStatus)=1) AND ((VS4TQuotation.TQuoCancelStatus)<>1))
GO

CREATE VIEW VS4VARCodeFromREC
AS 
SELECT VS4TAR.TARNCode, VS4TAR.TARNName, VS4TAR.TARNName2, VS4TAR.TARNIntroName, VS4TAR.TARNFlag1, VS4TAR2.TAR2SaleCode
FROM (VS4TAR LEFT JOIN VS4TAR2 ON VS4TAR.TARNCode=VS4TAR2.TAR2TARNCode) INNER JOIN VS4TARReceipt ON VS4TAR.TARNCode=VS4TARReceipt.TAIHTARNCode
GROUP BY VS4TAR.TARNCode, VS4TAR.TARNName, VS4TAR.TARNName2, VS4TAR.TARNIntroName, VS4TAR.TARNFlag1, VS4TAR2.TAR2SaleCode, VS4TARReceipt.TAIHCancelStatus, VS4TARReceipt.TAIHApproveStatus
HAVING (((VS4TARReceipt.TAIHCancelStatus)=0) AND ((VS4TARReceipt.TAIHApproveStatus)=1))
GO

CREATE VIEW VS4VARCodeFromSO
AS 
SELECT VS4TAR.TARNCode, VS4TAR.TARNName, VS4TAR.TARNName2, VS4TAR.TARNIntroName, VS4TAR.TARNFlag1, VS4TAR2.TAR2SaleCode
FROM (VS4TAR LEFT JOIN VS4TAR2 ON VS4TAR.TARNCode=VS4TAR2.TAR2TARNCode) INNER JOIN VS4TSO ON VS4TAR.TARNCode=VS4TSO.TSODTARNCode
GROUP BY VS4TAR.TARNCode, VS4TAR.TARNName, VS4TAR.TARNName2, VS4TAR.TARNIntroName, VS4TAR.TARNFlag1, VS4TAR2.TAR2SaleCode, VS4TSO.TSODConfirmStatus, VS4TSO.TSODApproveStatus, VS4TSO.TSODCancelStatus
HAVING (((VS4TSO.TSODConfirmStatus)=1) AND ((VS4TSO.TSODApproveStatus)=1) AND ((VS4TSO.TSODCancelStatus)<>1))
GO

CREATE VIEW VS4VARContact
AS 
SELECT VS4TAR.*, VS4TARStatus.*, VS4TARType.*, VS4TBusinessType.*, VS4TCountry.*, VS4TState.*, VS4TARContact.*, VS4TAR2.*, VS4TProvince.TPrvName, VS4TSaleArea.TSAeName, VS4TARGroup.TARGName, VS4TEmployee.TEmpFullName
FROM VS4TCountry RIGHT JOIN (VS4TBusinessType RIGHT JOIN (((VS4TARStatus RIGHT JOIN ((VS4TSaleArea RIGHT JOIN ((VS4TAR LEFT JOIN VS4TARType ON VS4TAR.TARNTARTCode = VS4TARType.TARTCode) LEFT JOIN VS4TState ON VS4TAR.TARNStaCode = VS4TState.TStaCode) ON VS4TSaleArea.TSAeCode = VS4TAR.TARNTSAeCode) LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) ON VS4TARStatus.TARSAlias = VS4TAR.TARNTARSAlias) LEFT JOIN ((VS4TAR2 LEFT JOIN VS4TEmployee ON VS4TAR2.TAR2SaleCode = VS4TEmployee.TEmpCode) LEFT JOIN VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) LEFT JOIN VS4TARContact ON VS4TAR.TARNCode = VS4TARContact.TARCTARNCode) ON VS4TBusinessType.TBsTCode = VS4TAR.TARNTBsTCode) ON VS4TCountry.TCouCode = VS4TAR.TARNTCouCode
GO

CREATE VIEW VS4VARCreditCard
AS 
SELECT VS4TAR.*, VS4TAR2.*, VS4TAR3.*, VS4TARGroup.*, VS4TARCreditCard.*
FROM (((VS4TAR INNER JOIN VS4TARCreditCard ON VS4TAR.TARNCode = VS4TARCreditCard.TACDTARNCode) LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) LEFT JOIN VS4TAR2 ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) INNER JOIN VS4TAR3 ON VS4TAR.TARNCode = VS4TAR3.TAR3TARNCode
GO

CREATE VIEW VS4VARCreditNote
AS 
SELECT VS4TARCreditNote.*, VS4TARCreditNoteMB.*, VS4TCountry.TCouName, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TBranch.TBraName, VS4TAR2.TAR2TPrvCode, VS4TProvince.TPrvName, VS4TAR.TARNTBsTCode, VS4TBusinessType.TBstName, VS4TAR.TARNTSAeCode, VS4TSaleArea.TSAeName, VS4TARGroup.TARGName, VS4TAR.TARNTARGCode, VS4TARInvoice.TIvoNo, VS4TARInvoice.TIvoBalanceFlag, VS4TARInvoice.TIvoType, VS4TARInvoice.TIvoDate, VS4TARInvoice.TIvoDueDate, VS4TARInvoice.TIvoRefNo, VS4TARInvoice.TIvoPONo, VS4TARInvoice.TIvoSOCode, VS4TARInvoice.TIvoJobCode, VS4TARInvoice.TIvoTJobNo, VS4TARInvoice.TIvoTPrjCode, VS4TARInvoice.TIvoTBraCode, VS4TARInvoice.TIvoTEmpCode, VS4TARInvoice.TIvoSaleName, VS4TARInvoice.TIvoDeliveryDate, VS4TARInvoice.TIvoTARNCode, VS4TARInvoice.TIvoCustomerName, VS4TARInvoice.TIvoCusAddress, VS4TARInvoice.TIvoCostTotal, VS4TARInvoice.TIvoTaxBase, VS4TARInvoice.TIvoGrandTotal, VS4TARInvoice.TIvoVATTotal, VS4TARInvoice.TIvoVATType, VS4TARInvoice.TIvoDiscountTotal, VS4TARInvoice.TIvoDiscountText, VS4TARInvoice.TIvoSubTotal, VS4TARInvoice.TIvoPriceChannel, VS4TARInvoice.TIvoTSOTCode, VS4TARInvoice.TIvoDepositText, VS4TARInvoice.TIvoDeposit, VS4TProduct.TPdtTransferCode, VS4TProduct.TPdtTransferName, VS4TProduct.TPdtTransferName2, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtDescription, VS4TARInvoice.TIvoCountryOrigin, VS4TAR.TARNName, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtTPSECode, VS4TProduct.TPdtTPG1Code, VS4TProduct.TPdtAverageCost, VS4TBranch.TBraAddressBill, VS4TAR.TARNPhone
FROM ((((((VS4TARCreditNote LEFT JOIN VS4TProject ON VS4TARCreditNote.TRCNTPrjCode = VS4TProject.TPrjCode) LEFT JOIN (((VS4TAR LEFT JOIN VS4TBusinessType ON VS4TAR.TARNTBsTCode = VS4TBusinessType.TBsTCode) LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) ON VS4TARCreditNote.TRCNTARNCode = VS4TAR.TARNCode) LEFT JOIN VS4TARInvoiceADJ ON VS4TARCreditNote.TRCNTIvoNo = VS4TARInvoiceADJ.TIvANo) LEFT JOIN VS4TCountry ON VS4TAR.TARNTCouCode = VS4TCountry.TCouCode) LEFT JOIN VS4TBranch ON VS4TARCreditNote.TRCNTBraCode = VS4TBranch.TBraCode) INNER JOIN (((VS4TARCreditNoteMB LEFT JOIN VS4TPOS ON VS4TARCreditNoteMB.TRCMTPOSCode = VS4TPOS.TPOSCode) LEFT JOIN VS4TARInvoice ON VS4TARCreditNoteMB.TRCMSourceNo = VS4TARInvoice.TIvoNo) LEFT JOIN VS4TProduct ON VS4TPOS.TPOSCode = VS4TProduct.TPdtCode) ON VS4TARCreditNote.TRCNNo = VS4TARCreditNoteMB.TRCMTRCNNo) LEFT JOIN (VS4TAR2 LEFT JOIN VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode
GO

CREATE VIEW VS4VARCreditNoteH
AS 
SELECT VS4TARCreditNote.*, VS4TARInvoiceADJ.TIvASubTotal, VS4TARInvoice.*
FROM ((VS4TARInvoiceADJ RIGHT JOIN VS4TARCreditNote ON VS4TARInvoiceADJ.TIvANo = VS4TARCreditNote.TRCNTIvoNo) LEFT JOIN VS4TARInvoice ON VS4TARCreditNote.TRCNTIvoNo = VS4TARInvoice.TIvoNo) LEFT JOIN VS4TAR ON VS4TARCreditNote.TRCNTARNCode = VS4TAR.TARNCode
GO

CREATE VIEW VS4VARDebitNote
AS 
SELECT VS4TARDebitNote.*, VS4TARDebitNoteMB.*, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TBranch.TBraName, VS4TAR2.TAR2TPrvCode, VS4TProvince.TPrvName, VS4TAR.TARNTSAeCode, VS4TSaleArea.TSAeName, VS4TAR.TARNTBsTCode, VS4TBusinessType.TBstName, VS4TCountry.TCouName, VS4TAR.TARNTARGCode, VS4TARGroup.TARGName, VS4TARInvoice.TIvoNo, VS4TARInvoice.TIvoBalanceFlag, VS4TARInvoice.TIvoType, VS4TARInvoice.TIvoDate, VS4TARInvoice.TIvoDueDate, VS4TARInvoice.TIvoRefNo, VS4TARInvoice.TIvoPONo, VS4TARInvoice.TIvoSOCode, VS4TARInvoice.TIvoJobCode, VS4TARInvoice.TIvoTJobNo, VS4TARInvoice.TIvoTPrjCode, VS4TARInvoice.TIvoTBraCode, VS4TARInvoice.TIvoTEmpCode, VS4TARInvoice.TIvoSaleName, VS4TARInvoice.TIvoDeliveryDate, VS4TARInvoice.TIvoTARNCode, VS4TARInvoice.TIvoCustomerName, VS4TARInvoice.TIvoCusAddress, VS4TARInvoice.TIvoCostTotal, VS4TARInvoice.TIvoTaxBase, VS4TARInvoice.TIvoGrandTotal, VS4TARInvoice.TIvoVATTotal, VS4TARInvoice.TIvoVATType, VS4TARInvoice.TIvoDiscountTotal, VS4TARInvoice.TIvoDiscountText, VS4TARInvoice.TIvoSubTotal, VS4TARInvoice.TIvoPriceChannel, VS4TARInvoice.TIvoTSOTCode, VS4TARInvoice.TIvoDepositText, VS4TARInvoice.TIvoDeposit, VS4TProduct.TPdtTransferCode, VS4TProduct.TPdtTransferName, VS4TProduct.TPdtTransferName2, VS4TProduct.TPdtName2, VS4TProduct.TPdtDescription, VS4TProduct.TPdtName, VS4TAR.TARNName, VS4TARInvoice.TIvoCountryOrigin, VS4TBranch.TBraAddressBill, VS4TAR.TARNPhone
FROM ((((VS4TAR LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN VS4TBusinessType ON VS4TAR.TARNTBsTCode = VS4TBusinessType.TBsTCode) LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) LEFT JOIN (VS4TAR2 LEFT JOIN VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) INNER JOIN ((((VS4TARDebitNote LEFT JOIN VS4TProject ON VS4TARDebitNote.TDBNTPrjCode = VS4TProject.TPrjTPjTCode) LEFT JOIN VS4TCountry ON VS4TARDebitNote.TDBNTCurCode = VS4TCountry.TCouCode) LEFT JOIN VS4TBranch ON VS4TARDebitNote.TDBNTBraCode = VS4TBranch.TBraCode) INNER JOIN ((((VS4TARDebitNoteMB LEFT JOIN VS4TPOS ON VS4TARDebitNoteMB.TDBMTPOSCode = VS4TPOS.TPOSCode) LEFT JOIN VS4TARInvoice ON VS4TARDebitNoteMB.TDBMSourceNo = VS4TARInvoice.TIvoNo) LEFT JOIN VS4TARInvoiceADJ ON VS4TARDebitNoteMB.TDBMSourceNo = VS4TARInvoiceADJ.TIvANo) LEFT JOIN VS4TProduct ON VS4TPOS.TPOSCode = VS4TProduct.TPdtCode) ON VS4TARDebitNote.TDBNNo = VS4TARDebitNoteMB.TDBMTDBNNo) ON VS4TAR.TARNCode = VS4TARDebitNote.TDBNTARNCode
GO

CREATE VIEW VS4VARDebitNoteH
AS 
SELECT VS4TARDebitNote.*, VS4TARInvoiceADJ.TIvASubTotal, VS4TARInvoice.*
FROM ((VS4TARInvoiceADJ RIGHT JOIN VS4TARDebitNote ON VS4TARInvoiceADJ.TIvANo = VS4TARDebitNote.TDBNTIvoNo) LEFT JOIN VS4TARInvoice ON VS4TARDebitNote.TDBNTIvoNo = VS4TARInvoice.TIvoNo) LEFT JOIN VS4TAR ON VS4TARDebitNote.TDBNTARNCode = VS4TAR.TARNCode
GO

CREATE VIEW VS4VARDebtAdjust
AS 
SELECT VS4TARDebtAdjust.*, VS4TARDebtAdjustMB.*, VS4TAR.*
FROM VS4TAR INNER JOIN (VS4TARDebtAdjust INNER JOIN VS4TARDebtAdjustMB ON VS4TARDebtAdjust.TRAJNo=VS4TARDebtAdjustMB.TRJMTRJANo) ON VS4TAR.TARNCode=VS4TARDebtAdjust.TRAJTARNCode
GO

CREATE VIEW VS4VARImportantDay
AS 
SELECT VS4TAR.*, VS4TAR2.*, VS4TARImportantDay.*, VS4TImportantDay.*
FROM VS4TImportantDay INNER JOIN ((VS4TAR LEFT JOIN VS4TAR2 ON VS4TAR.TARNCode=VS4TAR2.TAR2TARNCode) INNER JOIN VS4TARImportantDay ON VS4TAR.TARNCode=VS4TARImportantDay.TARITARNCode) ON VS4TImportantDay.TImDCode=VS4TARImportantDay.TARITIMDCode
GO

CREATE VIEW VS4VARInquiry
AS 
SELECT VS4TAR.*, VS4TAR3.*, VS4TARGroup.*, VS4TARInquiry.*, VS4TInquiryGroup.TIQGCode, VS4TInquiryGroup.TIQGName, VS4TInquiryGroup.TIQGName2, VS4TInquiryGroup.TIQGFlag1, VS4TInquiryChoice.TIQCTIQRCode, VS4TInquiryChoice.TIQCLn, VS4TInquiryChoice.TIQCName, VS4TInquiryChoice.TIQCName2, VS4TInquiryChoice.TIQCType, VS4TInquiryChoice.TIQCImage1, VS4TInquiryChoice.TIQCFlag1, VS4TInquiry.TIQRTIQGCode, VS4TInquiry.TIQRCode, VS4TAR2.TAR2TSPvCode
FROM (VS4TInquiryGroup RIGHT JOIN VS4TInquiry ON VS4TInquiryGroup.TIQGCode = VS4TInquiry.TIQRTIQGCode) RIGHT JOIN (VS4TInquiryChoice RIGHT JOIN ((((VS4TAR LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) LEFT JOIN VS4TAR2 ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) LEFT JOIN VS4TAR3 ON VS4TAR.TARNCode = VS4TAR3.TAR3TARNCode) INNER JOIN VS4TARInquiry ON VS4TAR.TARNCode = VS4TARInquiry.TAQCTARNCode) ON (VS4TInquiryChoice.TIQCLn = VS4TARInquiry.TAQCTIQCLn) AND (VS4TInquiryChoice.TIQCTIQRCode = VS4TARInquiry.TAQCTIQCTIQRCode)) ON VS4TInquiry.TIQRCode = VS4TInquiryChoice.TIQCTIQRCode
GO

CREATE VIEW VS4VARInvoice
AS 
SELECT VS4TARInvoice.*, VS4TARInvoiceMB.*, VS4TCountry.TCouName, VS4TAR.TARNAddressBill, VS4TAR.TARNName, VS4TAR2.TAR2TPrvCode, VS4TAR2.TAR2TBSMCode, VS4TBusinessMajor.TBsMName, VS4TProvince.TPrvName, VS4TARGroup.TARGName, VS4TSaleArea.TSAeName, VS4TSaleZone.TSZnName, VS4TBusinessType.TBstName, VS4TAR.TARNTARGCode, VS4TAR.TARNTBsTCode, VS4TAR.TARNTSAeCode, VS4TBranch.TBraName, VS4TProject.TPrjMode, VS4TAR2.TAR2SaleCode, VS4TProduct.TPdtTransferCode, VS4TProduct.TPdtTransferName, VS4TProduct.TPdtName, VS4TProduct.TPdtDescription, VS4TProduct.TPdtName2, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtTPSECode, VS4TProduct.TPdtTPG1Code, VS4TProduct.TPdtStandardCost, VS4TProductSec2.TPS2Code, VS4TProductSec2.TPS2Name, VS4TProductGroup1.TPG1Name, VS4TProduct.TPdtTPG2Code, VS4TProductGroup2.TPG2Name, VS4TAR2.TAR2Marks, VS4TProductSection.TPSEName, VS4TProduct.TPdtTAPNCode, VS4TProduct.TPdtCustom1, VS4TProduct.TPdtCustom2, VS4TProduct.TPdtCustom3, VS4TProduct.TPdtCustom4, VS4TProduct.TPdtCustom5, VS4TProduct.TPdtCustom6, VS4TARInvoiceBook.TRBKName, VS4TBranch.TBraAddressBill, VS4TProduct.TPdtOldCode, VS4TProduct.TPdtTPTTCode, VS4TShipping.TSHPName, VS4TLocation.TLctTWahCode, VS4TAR.TARNPhone
FROM VS4TSaleZone RIGHT JOIN ((VS4TBusinessType RIGHT JOIN ((((VS4TAR LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) LEFT JOIN (((VS4TAR2 LEFT JOIN VS4TBusinessMajor ON VS4TAR2.TAR2TBSMCode = VS4TBusinessMajor.TBsMCode) LEFT JOIN VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode) LEFT JOIN VS4TShipping ON VS4TAR2.TAR2TShpCode = VS4TShipping.TSHPCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) RIGHT JOIN ((((VS4TARInvoice LEFT JOIN VS4TCountry ON VS4TARInvoice.TIvoCountryOrigin = VS4TCountry.TCouCode) LEFT JOIN VS4TProject ON VS4TARInvoice.TIvoTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TARInvoice.TIvoTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TARInvoiceBook ON VS4TARInvoice.TIvoTRBKCode = VS4TARInvoiceBook.TRBKCode) ON VS4TAR.TARNCode = VS4TARInvoice.TIvoTARNCode) ON VS4TBusinessType.TBsTCode = VS4TAR.TARNTBsTCode) INNER JOIN (((VS4TARInvoiceMB LEFT JOIN VS4TPOS ON VS4TARInvoiceMB.TIoMTPOSCode = VS4TPOS.TPOSCode) LEFT JOIN ((((VS4TProduct LEFT JOIN VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code) LEFT JOIN VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code) LEFT JOIN VS4TProductGroup2 ON VS4TProduct.TPdtTPG2Code = VS4TProductGroup2.TPG2Code) LEFT JOIN VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode) ON VS4TPOS.TPOSCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TLocation ON VS4TARInvoiceMB.TIoMTLctCode = VS4TLocation.TLctCode) ON VS4TARInvoice.TIvoNo = VS4TARInvoiceMB.TIoMTIvoNo) ON VS4TSaleZone.TSZnCode = VS4TSaleArea.TSaeTSZnCode
GO

CREATE VIEW VS4VARInvoice2RV
AS 
SELECT VS4TARInvoice.TIvoNo, VS4TARInvoice.TIvoTARNCode, VS4TARInvoice.TIvoCustomerName, VS4TARInvoiceMB.TIoMTPOSCode, VS4TARInvoiceMB.TIoMNetAmount, VS4TARInvoice.TIvoTaxBase, VS4TARInvoice.TIvoVATTotal, VS4TARInvoice.TIvoGrandTotal, VS4TARVoucherPay.TRVRReceiveType, VS4TChequeRec.TCHRTBnkCode, VS4TChequeRec.TCHRNo, VS4TChequeRec.TCHRChqDate, VS4TARVoucher.TRVHFee, VS4TARVDocRef.TRDRWTAXTotal, VS4TARInvoice.TIvoArrears, VS4TARInvoice.TIvoRefNo, VS4TARVDocRef.TRDRRefDocNo, VS4TARVDocRef.TRDRRefDocType, VS4TARReceipt.TAIHDate, VS4TARInvoice.TIvoTPrjCode, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TBranch.TBraName, VS4TARInvoice.TIvoTBraCode, VS4TARInvoice.TIvoDueDate, VS4TARInvoice.TIvoDate, VS4TAR.TARNTARGCode, VS4TARGroup.TARGName, VS4TAR.TARNTBsTCode, VS4TBusinessType.TBstName, VS4TAR.TARNTSAeCode, VS4TSaleArea.TSAeName, VS4TARInvoice.TIvoCountryOrigin, VS4TCountry.TCouName, VS4TAR2.TAR2TPrvCode, VS4TProvince.TPrvName, VS4TARVoucher.TRVHApproveStatus, VS4TARVoucher.TRVHCancelStatus, VS4TARVoucher.TRVHConfirmStatus, VS4TARVoucher.TRVHDate, VS4TARVoucher.TRVHNo, VS4TARVoucher.TRVHType, VS4TARVoucher.TRVHFlag1, VS4TARInvoice.TIvoCancelStatus, VS4TARInvoice.TIvoApproveStatus, VS4TARInvoice.TIvoConfirmStatus, VS4TARVoucher.TRVHNote, VS4TARVoucherPay.TRVRLn, VS4TARInvoice.TIvoCondition, VS4TARInvoice.TIvoTEmpCode, VS4TARInvoice.TIvoSaleName, VS4TAR2.TAR2SaleCode, VS4TEmployee.TEmpFullName, VS4TARBill.TBilNo, VS4TARBill.TBilDate, VS4TARBill.TBilDueDate
FROM ((VS4TARVoucher RIGHT JOIN (VS4TProject RIGHT JOIN ((VS4TBusinessType RIGHT JOIN ((((VS4TAR2 RIGHT JOIN (VS4TSaleArea RIGHT JOIN (VS4TARGroup RIGHT JOIN VS4TAR ON VS4TARGroup.TARGCode = VS4TAR.TARNTARGCode) ON VS4TSaleArea.TSAeCode = VS4TAR.TARNTSAeCode) ON VS4TAR2.TAR2TARNCode = VS4TAR.TARNCode) LEFT JOIN VS4TEmployee ON VS4TAR2.TAR2SaleCode = VS4TEmployee.TEmpCode) LEFT JOIN VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode) RIGHT JOIN (((VS4TCountry RIGHT JOIN (VS4TBranch RIGHT JOIN (VS4TARInvoice LEFT JOIN VS4TARVDocRef ON VS4TARInvoice.TIvoNo = VS4TARVDocRef.TRDRRefDocNo) ON VS4TBranch.TBraCode = VS4TARInvoice.TIvoTBraCode) ON VS4TCountry.TCouCode = VS4TARInvoice.TIvoCountryOrigin) LEFT JOIN VS4TARReceipt ON VS4TARVDocRef.TRDRRefDocType = VS4TARReceipt.TAIHNo) LEFT JOIN VS4TARBill ON VS4TARVDocRef.TRDRRefBillNo = VS4TARBill.TBilNo) ON VS4TAR.TARNCode = VS4TARInvoice.TIvoTARNCode) ON VS4TBusinessType.TBsTCode = VS4TAR.TARNTBsTCode) INNER JOIN VS4TARInvoiceMB ON VS4TARInvoice.TIvoNo = VS4TARInvoiceMB.TIoMTIvoNo) ON VS4TProject.TPrjCode = VS4TARInvoice.TIvoTPrjCode) ON VS4TARVoucher.TRVHNo = VS4TARVDocRef.TRDRTRVHNo) LEFT JOIN VS4TARVoucherPay ON VS4TARVoucher.TRVHNo = VS4TARVoucherPay.TRVRTRVHNo) LEFT JOIN (VS4TChequeRec RIGHT JOIN VS4TChequeRec2RV ON VS4TChequeRec.TCHRNo = VS4TChequeRec2RV.TR2RTCHRNo) ON (VS4TARVoucherPay.TRVRLn = VS4TChequeRec2RV.TR2RTRVRLn) AND (VS4TARVoucherPay.TRVRTRVHNo = VS4TChequeRec2RV.TR2RTRVRTRVHNo)
GO

CREATE VIEW VS4VARInvoiceADJH
AS 
SELECT VS4TARInvoiceADJ.*, VS4TCountry.TCouName, VS4TProject.TPrjName, VS4TARBalance.*, VS4TARGroup.TARGCode, VS4TARGroup.TARGName, VS4TProject.TPrjMode, VS4TBranch.TBraName, VS4TBusinessType.TBstName, VS4TAR.TARNName, VS4TAR.TARNTARGCode, VS4TAR.TARNTBsTCode, VS4TAR2.TAR2TPrvCode, VS4TProvince.TPrvName, VS4TAR.TARNTSAeCode, VS4TSaleArea.TSAeName
FROM ((((VS4TAR LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) LEFT JOIN VS4TBusinessType ON VS4TAR.TARNTBsTCode = VS4TBusinessType.TBsTCode) LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN (VS4TAR2 LEFT JOIN VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) INNER JOIN (((((VS4TARInvoiceADJ LEFT JOIN VS4TCountry ON VS4TARInvoiceADJ.TIvACountryOrigin = VS4TCountry.TCouCode) LEFT JOIN VS4TProject ON VS4TARInvoiceADJ.TIvATPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TARBalance ON (VS4TARInvoiceADJ.TIvATACPTACYID = VS4TARBalance.TARLTACPTACYID) AND (VS4TARInvoiceADJ.TIvATACPID = VS4TARBalance.TARLTACPID) AND (VS4TARInvoiceADJ.TIvATARNCode = VS4TARBalance.TARLTARNCode)) INNER JOIN VS4TARInvoice ON VS4TARInvoiceADJ.TIvANo = VS4TARInvoice.TIvoNo) LEFT JOIN VS4TBranch ON VS4TARInvoiceADJ.TIvATBraCode = VS4TBranch.TBraCode) ON VS4TAR.TARNCode = VS4TARInvoiceADJ.TIvATARNCode
GO

CREATE VIEW VS4VARInvoiceArr
AS 
SELECT VS4TARInvoice.*, VS4TARInvoiceMB.*, VS4TCountry.TCouName, VS4TProject.TPrjName, VS4TAR.TARNAddressBill, VS4TAR.TARNBillDay1, VS4TAR.TARNBillDay2, VS4TAR.TARNBillDay3, VS4TAR.TARNBillDay4, VS4TCountry.TCouName2, VS4TBusinessType.TBstName, VS4TBusinessMajor.TBsMName, VS4TSaleArea.TSAeName, VS4TSaleZone.TSZnName, VS4TProvince.TPrvName, VS4TAR2.TAR2TDecCode, VS4TAR2.TAR2TBSMCode, VS4TAR.TARNName, VS4TAR.TARNName2, VS4TAR.TARNTBsTCode, VS4TAR.TARNTSAeCode, VS4TBranch.TBraName, VS4TARGroup.TARGName, VS4TAR2.TAR2TPrvCode, VS4TProject.TPrjMode, VS4TAR.TARNTARGCode, VS4TAR.TARNAddress, VS4TAR.TARNSubProvince, VS4TAR.TARNCity, VS4TAR.TARNPhone, VS4TAR.TARNFax, VS4TSaleArea.TSAeCode
FROM VS4TSaleZone RIGHT JOIN ((((((VS4TAR LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) LEFT JOIN VS4TBusinessType ON VS4TAR.TARNTBsTCode = VS4TBusinessType.TBsTCode) LEFT JOIN ((VS4TAR2 LEFT JOIN VS4TBusinessMajor ON VS4TAR2.TAR2TBSMCode = VS4TBusinessMajor.TBsMCode) LEFT JOIN VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) RIGHT JOIN (((VS4TARInvoice LEFT JOIN VS4TCountry ON VS4TARInvoice.TIvoCountryOrigin = VS4TCountry.TCouCode) LEFT JOIN VS4TProject ON VS4TARInvoice.TIvoTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TARInvoice.TIvoTBraCode = VS4TBranch.TBraCode) ON VS4TAR.TARNCode = VS4TARInvoice.TIvoTARNCode) INNER JOIN VS4TARInvoiceMB ON VS4TARInvoice.TIvoNo = VS4TARInvoiceMB.TIoMTIvoNo) ON VS4TSaleZone.TSZnCode = VS4TSaleArea.TSaeTSZnCode
GO

CREATE VIEW VS4VARInvoiceArrH
AS 
SELECT VS4TARInvoice.*, VS4TCountry.TCouName, VS4TAR.*, VS4TProject.TPrjName, VS4TSaleArea.*, VS4TARGroup.TARGCode, VS4TARGroup.TARGName, VS4TProject.TPrjMode, VS4TAR2.TAR2TPrvCode, VS4TProvince.TPrvName, VS4TBusinessType.TBstName, VS4TBranch.TBraName
FROM ((((VS4TAR LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) LEFT JOIN VS4TBusinessType ON VS4TAR.TARNTBsTCode = VS4TBusinessType.TBsTCode) LEFT JOIN (VS4TAR2 LEFT JOIN VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) RIGHT JOIN (((VS4TARInvoice LEFT JOIN VS4TCountry ON VS4TARInvoice.TIvoCountryOrigin = VS4TCountry.TCouCode) LEFT JOIN VS4TProject ON VS4TARInvoice.TIvoTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TARInvoice.TIvoTBraCode = VS4TBranch.TBraCode) ON VS4TAR.TARNCode = VS4TARInvoice.TIvoTARNCode
GO

CREATE VIEW VS4VARInvoiceDbCnA
AS 
SELECT *
FROM VS4TARCreditNote
WHERE (((VS4TARCreditNote.TRCNApproveStatus)=1) And ((VS4TARCreditNote.TRCNRevision)=0))
GO

CREATE VIEW VS4VARInvoiceDbCnB
AS 
SELECT *
FROM VS4TARDebitNote
WHERE (((VS4TARDebitNote.TDBNApproveStatus)=1) And ((VS4TARDebitNote.TDBNCancelStatus)=0))
GO

CREATE VIEW VS4VARInvoiceDbCn
AS 
SELECT VS4TARInvoice.*, VS4TCountry.TCouName, VS4TAR.*, VS4TProject.TPrjName, VS4TSaleArea.*, VS4TARGroup.TARGCode, VS4TARGroup.TARGName, VS4VARInvoiceDbCnA.TRCNNo, VS4VARInvoiceDbCnA.TRCNTIvoNo, VS4VARInvoiceDbCnA.TRCNGrandTotal, VS4VARInvoiceDbCnA.TRCNArrears, VS4VARInvoiceDbCnA.TRCNTaxBase, VS4VARInvoiceDbCnA.TRCNVATTotal, VS4VARInvoiceDbCnB.TDBNNo, VS4VARInvoiceDbCnB.TDBNTIvoNo, VS4VARInvoiceDbCnB.TDBNTaxBase, VS4VARInvoiceDbCnB.TDBNVATTotal, VS4VARInvoiceDbCnB.TDBNGrandTotal, VS4VARInvoiceDbCnB.TDBNArrears, VS4VARInvoiceDbCnA.TRCNApproveStatus, VS4VARInvoiceDbCnA.TRCNCancelStatus, VS4VARInvoiceDbCnB.TDBNApproveStatus, VS4VARInvoiceDbCnB.TDBNCancelStatus, VS4TProject.TPrjMode, VS4TAR2.TAR2TPrvCode, VS4TProvince.TPrvName, VS4TBusinessType.TBstName, VS4TBranch.TBraName
FROM ((((VS4TAR LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) LEFT JOIN VS4TBusinessType ON VS4TAR.TARNTBsTCode = VS4TBusinessType.TBsTCode) LEFT JOIN (VS4TAR2 LEFT JOIN VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) RIGHT JOIN (((((VS4TARInvoice LEFT JOIN VS4TCountry ON VS4TARInvoice.TIvoCountryOrigin = VS4TCountry.TCouCode) LEFT JOIN VS4TProject ON VS4TARInvoice.TIvoTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4VARInvoiceDbCnA ON VS4TARInvoice.TIvoNo = VS4VARInvoiceDbCnA.TRCNTIvoNo) LEFT JOIN VS4VARInvoiceDbCnB ON VS4TARInvoice.TIvoNo = VS4VARInvoiceDbCnB.TDBNTIvoNo) LEFT JOIN VS4TBranch ON VS4TARInvoice.TIvoTBraCode = VS4TBranch.TBraCode) ON VS4TAR.TARNCode = VS4TARInvoice.TIvoTARNCode
GO

CREATE VIEW VS4VARInvoiceH
AS 
SELECT VS4TARInvoice.*, VS4TCountry.TCouName, VS4TProject.TPrjName, VS4TAR.TARNAddressBill, VS4TAR.TARNBillDay1, VS4TAR.TARNBillDay2, VS4TAR.TARNBillDay3, VS4TAR.TARNBillDay4, VS4TAR.TARNName, VS4TAR.TARNName2, VS4TAR.TARNIntroName, VS4TAR2.TAR2TPrvCode, VS4TAR2.TAR2TBSMCode, VS4TBusinessMajor.TBsMName, VS4TProvince.TPrvName, VS4TARGroup.TARGName, VS4TSaleArea.TSAeName, VS4TSaleZone.TSZnName, VS4TBusinessType.TBstName, VS4TAR.TARNTARGCode, VS4TAR.TARNTBsTCode, VS4TAR.TARNTSAeCode, VS4TBranch.TBraName, VS4TAR2.TAR2SaleCode, VS4TAR.TARNTextSort, VS4TProject.TPrjMode, VS4TAR2.TAR2Distance, VS4TShipping.TSHPName
FROM VS4TSaleZone RIGHT JOIN (VS4TBusinessType RIGHT JOIN ((((VS4TAR LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) LEFT JOIN (((VS4TAR2 LEFT JOIN VS4TBusinessMajor ON VS4TAR2.TAR2TBSMCode = VS4TBusinessMajor.TBsMCode) LEFT JOIN VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode) LEFT JOIN VS4TShipping ON VS4TAR2.TAR2TShpCode = VS4TShipping.TSHPCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) RIGHT JOIN (((VS4TARInvoice LEFT JOIN VS4TCountry ON VS4TARInvoice.TIvoCountryOrigin = VS4TCountry.TCouCode) LEFT JOIN VS4TProject ON VS4TARInvoice.TIvoTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TARInvoice.TIvoTBraCode = VS4TBranch.TBraCode) ON VS4TAR.TARNCode = VS4TARInvoice.TIvoTARNCode) ON VS4TBusinessType.TBsTCode = VS4TAR.TARNTBsTCode) ON VS4TSaleZone.TSZnCode = VS4TSaleArea.TSaeTSZnCode
GO

CREATE VIEW VS4VARInvoiceMoveM
AS 
SELECT VS4TARInvoice.*, VS4TCountry.TCouName, VS4TAR.*, VS4TProject.TPrjName, VS4TSaleArea.*, VS4TARGroup.TARGCode, VS4TARGroup.TARGName
FROM ((VS4TAR LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) RIGHT JOIN ((VS4TARInvoice LEFT JOIN VS4TCountry ON VS4TARInvoice.TIvoCountryOrigin = VS4TCountry.TCouCode) LEFT JOIN VS4TProject ON VS4TARInvoice.TIvoTPrjCode = VS4TProject.TPrjCode) ON VS4TAR.TARNCode = VS4TARInvoice.TIvoTARNCode
GO

CREATE VIEW VS4VARInvoicePay
AS 
SELECT VS4TARInvoice.*, VS4TCountry.TCouName, VS4TProject.TPrjName, VS4TAR.TARNAddressBill, VS4TAR.TARNBillDay1, VS4TAR.TARNBillDay2, VS4TAR.TARNBillDay3, VS4TAR.TARNBillDay4, VS4TAR.TARNName, VS4TAR.TARNName2, VS4TAR.TARNIntroName, VS4TAR2.TAR2TPrvCode, VS4TAR2.TAR2TBSMCode, VS4TBusinessMajor.TBsMName, VS4TProvince.TPrvName, VS4TARGroup.TARGName, VS4TSaleArea.TSAeName, VS4TSaleZone.TSZnName, VS4TBusinessType.TBstName, VS4TAR.TARNTARGCode, VS4TAR.TARNTBsTCode, VS4TAR.TARNTSAeCode, VS4TBranch.TBraName, VS4TAR2.TAR2SaleCode, VS4TAR.TARNTextSort, VS4TARInvoicePay.*, VS4TChequeRec.TCHRChqPassDate, VS4TChequeRec.TCHRChqBackDate, VS4TChequeRec.TCHRChqBackBy, VS4TChequeRec.TCHRChqPassBy, VS4TChequeRec.TCHRNo, VS4TChequeRec.TCHRChqDate, VS4TCompanyBank.TCBBTBnkCode, VS4TCompanyBank.TCBBAccountNo, VS4TCompanyBank.TCBBAccountBranch
FROM VS4TCompanyBank RIGHT JOIN (VS4TSaleZone RIGHT JOIN ((VS4TBusinessType RIGHT JOIN ((((VS4TAR LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) LEFT JOIN ((VS4TAR2 LEFT JOIN VS4TBusinessMajor ON VS4TAR2.TAR2TBSMCode = VS4TBusinessMajor.TBsMCode) LEFT JOIN VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) RIGHT JOIN (((VS4TARInvoice LEFT JOIN VS4TCountry ON VS4TARInvoice.TIvoCountryOrigin = VS4TCountry.TCouCode) LEFT JOIN VS4TProject ON VS4TARInvoice.TIvoTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TARInvoice.TIvoTBraCode = VS4TBranch.TBraCode) ON VS4TAR.TARNCode = VS4TARInvoice.TIvoTARNCode) ON VS4TBusinessType.TBsTCode = VS4TAR.TARNTBsTCode) LEFT JOIN (VS4TARInvoicePay LEFT JOIN (VS4TChequeRec RIGHT JOIN VS4TChequeRec2IV ON VS4TChequeRec.TCHRNo = VS4TChequeRec2IV.TR2ITCHRNo) ON (VS4TARInvoicePay.TIPyLn = VS4TChequeRec2IV.TR2ITIPyLn) AND (VS4TARInvoicePay.TIPyTIvoNo = VS4TChequeRec2IV.TR2ITIPyTIvoNo)) ON VS4TARInvoice.TIvoNo = VS4TARInvoicePay.TIPyTIvoNo) ON VS4TSaleZone.TSZnCode = VS4TSaleArea.TSaeTSZnCode) ON VS4TCompanyBank.TCBBNo = VS4TARInvoicePay.TIPyTCBBNo
GO

CREATE VIEW VS4VARMedia
AS 
SELECT VS4TAR.*, VS4TAR2.*, VS4TAR3.*, VS4TARGroup.*, VS4TARMedia.*, VS4TMedia.*
FROM VS4TMedia INNER JOIN ((((VS4TAR INNER JOIN VS4TARMedia ON VS4TAR.TARNCode = VS4TARMedia.TAMdTARNCode) LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) LEFT JOIN VS4TAR2 ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) LEFT JOIN VS4TAR3 ON VS4TAR.TARNCode = VS4TAR3.TAR3TARNCode) ON VS4TMedia.TMedCode = VS4TARMedia.TAMdTMedCode
GO

CREATE VIEW VS4VARMemberCard
AS 
SELECT VS4TAR.*, VS4TAR3.*, VS4TARGroup.*, VS4TARMemberCard.*, VS4TMemberCard.*, VS4TAR2.TAR2TShpCode
FROM VS4TMemberCard INNER JOIN ((((VS4TAR LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) LEFT JOIN VS4TAR2 ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) INNER JOIN VS4TAR3 ON VS4TAR.TARNCode = VS4TAR3.TAR3TARNCode) INNER JOIN VS4TARMemberCard ON VS4TAR.TARNCode = VS4TARMemberCard.TAMCTARNCode) ON VS4TMemberCard.TMCDCode = VS4TARMemberCard.TAMCTMCDCode
GO

CREATE VIEW VS4VARParent
AS 
SELECT VS4TARParent.*, VS4TAR_1.*, VS4TAR.TARNCode AS VARPCode, VS4TAR.TARNName AS VARPName, VS4TAR.TARNName2 AS VARPName2, VS4TAR.TARNType AS VARPType, VS4TAR.TARNTARTCode AS VARPTARTCode, VS4TAR.TARNTARGCode AS VARPTARGCode, VS4TAR.TARNPhone AS VARPPhone, VS4TAR.TARNFax AS VARPFax, VS4TAR.TARNFlag1 AS VARPFlag1
FROM (VS4TARParent LEFT JOIN VS4TAR ON VS4TARParent.TARPTARNCode=VS4TAR.TARNCode) LEFT JOIN VS4TAR AS VS4TAR_1 ON VS4TARParent.TARPTARNCode2=VS4TAR_1.TARNCode
GO

CREATE VIEW VS4VARReceipt
AS 
SELECT VS4TARReceipt.*, VS4TARReceiptMB.*, VS4TAR.*, VS4TARInvoice.TIvoCustom1, VS4TARInvoice.TIvoCustom2, VS4TARInvoice.TIvoCustom3, VS4TARInvoice.TIvoCustom4, VS4TARInvoice.TIvoCustom5, VS4TBranch.TBraAddressBill
FROM (VS4TAR INNER JOIN (VS4TARReceipt INNER JOIN (VS4TARReceiptMB LEFT JOIN VS4TARInvoice ON VS4TARReceiptMB.TREMRefNo2 = VS4TARInvoice.TIvoNo) ON VS4TARReceipt.TAIHNo = VS4TARReceiptMB.TREMTAIHNo) ON VS4TAR.TARNCode = VS4TARReceipt.TAIHTARNCode) LEFT JOIN VS4TBranch ON VS4TARReceipt.TAIHTBraCode = VS4TBranch.TBraCode
GO

CREATE VIEW VS4VARReceiptD
AS 
SELECT VS4TARReceiptD.*, VS4TARReceiptDMB.*, VS4TAR.*, VS4TARInvoice.TIvoDescription, VS4TARInvoice.TIvoJobCode, VS4TBranch.TBraAddressBill
FROM (VS4TAR INNER JOIN (VS4TARReceiptD INNER JOIN (VS4TARReceiptDMB LEFT JOIN VS4TARInvoice ON VS4TARReceiptDMB.TRDMRefDocNo = VS4TARInvoice.TIvoNo) ON VS4TARReceiptD.TAIRNo = VS4TARReceiptDMB.TRDMTAIRNo) ON VS4TAR.TARNCode = VS4TARReceiptD.TAIRTARNCode) LEFT JOIN VS4TBranch ON VS4TARReceiptD.TAIRTBraCode = VS4TBranch.TBraCode
GO

CREATE VIEW VS4VARSumCard
AS 
SELECT VS4TARBalance.*, VS4TAR.*, VS4TAR2.*, VS4TBusinessType.TBstName, VS4TSaleArea.TSAeName, VS4TCountry.TCouName, VS4TARGroup.TARGName, VS4TARHolder.TARHName, VS4TProvince.TPrvName
FROM (((((VS4TAR LEFT JOIN VS4TBusinessType ON VS4TAR.TARNTBsTCode = VS4TBusinessType.TBsTCode) LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN VS4TCountry ON VS4TAR.TARNTCouCode = VS4TCountry.TCouCode) LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) LEFT JOIN ((VS4TAR2 LEFT JOIN VS4TARHolder ON VS4TAR2.TAR2SaleCode = VS4TARHolder.TARHCode) LEFT JOIN VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) INNER JOIN VS4TARBalance ON VS4TAR.TARNCode = VS4TARBalance.TARLTARNCode
GO

CREATE VIEW VS4VARTaxNoRefund
AS 
SELECT VS4TTaxTrans.*
FROM VS4TTaxTrans
WHERE (((VS4TTaxTrans.TTxTType)=1) AND ((VS4TTaxTrans.TTxTDefaultTax)=3)) OR (((VS4TTaxTrans.TTxTDefaultTax)=4))
GO

CREATE VIEW VS4VARTaxRefund
AS 
SELECT VS4TTaxTrans.*, VS4TARInvoice.TIvoTGLTNo
FROM VS4TTaxTrans LEFT JOIN VS4TARInvoice ON VS4TTaxTrans.TTxTDocNo = VS4TARInvoice.TIvoNo
WHERE (((VS4TTaxTrans.TTxTType)=1) AND ((VS4TTaxTrans.TTxTDefaultTax)=1))
GO

CREATE VIEW VS4VARTaxTrans
AS 
SELECT VS4TTaxTrans.*
FROM VS4TTaxTrans
WHERE (((VS4TTaxTrans.TTxTType)=1) AND ((VS4TTaxTrans.TTxTDefaultTax)=1)) OR (((VS4TTaxTrans.TTxTDefaultTax)=3)) OR (((VS4TTaxTrans.TTxTDefaultTax)=4))
GO

CREATE VIEW VS4VAsset
AS 
SELECT VS4TAsset.*, VS4TAssetSection.TAseName, VS4TAssetCalcType.TACTName, VS4TAssetType.TAstName, VS4TUnit.TUntName, VS4TBranch.TBraName, VS4TProject.TPrjCode, VS4TProject.TPrjMode, VS4TProject.TPrjName, VS4TSection.TSecName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TAssetType.TAstDocCode, VS4TSection.TSecName2, VS4TDivision.TDivName2, VS4TDepartment.TDepName2, VS4TAssetType.TAstName2, VS4TAssetSection.TAseName2, VS4TAssetAlias.TAsACode
FROM VS4TAssetAlias RIGHT JOIN ((VS4TAssetType INNER JOIN (VS4TAssetSection RIGHT JOIN (VS4TAssetCalcType RIGHT JOIN ((((VS4TSection RIGHT JOIN (VS4TDivision RIGHT JOIN (VS4TDepartment RIGHT JOIN VS4TAsset ON VS4TDepartment.TDepCode = VS4TAsset.TAssTDepCode) ON VS4TDivision.TDivCode = VS4TAsset.TAssTDivCode) ON VS4TSection.TSecCode = VS4TAsset.TAssTSecCode) LEFT JOIN VS4TBranch ON VS4TAsset.TAssTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TUnit ON VS4TAsset.TAssTUntCode = VS4TUnit.TUntCode) LEFT JOIN VS4TProject ON VS4TAsset.TAssTPrjCode = VS4TProject.TPrjCode) ON VS4TAssetCalcType.TACTAlias = VS4TAsset.TAssTACTAlias) ON VS4TAssetSection.TAseCode = VS4TAsset.TAssTAseCode) ON VS4TAssetType.TAsTCode = VS4TAsset.TAssTAsTCode) LEFT JOIN VS4TAsset2Alias ON VS4TAsset.TAssCode = VS4TAsset2Alias.TA2ATAssCode) ON VS4TAssetAlias.TAsACode = VS4TAsset2Alias.TA2ATAsACode
GO

CREATE VIEW VS4VAssetAlias
AS 
SELECT VS4TAssetAlias.*, VS4TAsset.*
FROM VS4TAsset RIGHT JOIN (VS4TAssetAlias LEFT JOIN VS4TAsset2Alias ON VS4TAssetAlias.TAsACode = VS4TAsset2Alias.TA2ATAsACode) ON VS4TAsset.TAssCode = VS4TAsset2Alias.TA2ATAssCode
GO

CREATE VIEW VS4VAssetAllocate
AS 
SELECT VS4TAsset.*, VS4TAssetSection.TAseName, VS4TAssetCalcType.TACTName, VS4TAssetType.TAstName, VS4TUnit.TUntName, VS4TBranch.TBraName, VS4TProject.TPrjCode, VS4TProject.TPrjMode, VS4TProject.TPrjName, VS4TSection.TSecName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TAssetType.TAstDocCode, VS4TSection.TSecName2, VS4TDivision.TDivName2, VS4TDepartment.TDepName2, VS4TAssetType.TAstName2, VS4TAssetSection.TAseName2
FROM VS4TAssetType INNER JOIN (VS4TAssetSection RIGHT JOIN ((((((VS4TAssetCalcType RIGHT JOIN ((VS4TAsset LEFT JOIN VS4TUnit ON VS4TAsset.TAssTUntCode=VS4TUnit.TUntCode) LEFT JOIN VS4TProject ON VS4TAsset.TAssTPrjCode=VS4TProject.TPrjCode) ON VS4TAssetCalcType.TACTAlias=VS4TAsset.TAssTACTAlias) INNER JOIN VS4TAssetAllocate ON VS4TAsset.TAssCode=VS4TAssetAllocate.TAsATAssCode) LEFT JOIN VS4TBranch ON VS4TAssetAllocate.TAsATBraCode=VS4TBranch.TBraCode) LEFT JOIN VS4TDivision ON VS4TAssetAllocate.TAsATDivCode=VS4TDivision.TDivCode) LEFT JOIN VS4TDepartment ON VS4TAssetAllocate.TAsATDepCode=VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TAssetAllocate.TAsATSecCode=VS4TSection.TSecCode) ON VS4TAssetSection.TAseCode=VS4TAsset.TAssTAseCode) ON VS4TAssetType.TAsTCode=VS4TAsset.TAssTAsTCode
GO

CREATE VIEW VS4VAssetBuiltReq
AS 
SELECT VS4TAsset.*, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TAssetBuiltReq.*, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TBranch.TBraName
FROM VS4TAsset RIGHT JOIN (((VS4TDivision RIGHT JOIN (VS4TDepartment RIGHT JOIN (VS4TSection RIGHT JOIN VS4TAssetBuiltReq ON VS4TSection.TSecCode = VS4TAssetBuiltReq.TBrqTSecCode) ON VS4TDepartment.TDepCode = VS4TAssetBuiltReq.TBrqTDepCode) ON VS4TDivision.TDivCode = VS4TAssetBuiltReq.TBrqTDivCode) LEFT JOIN VS4TProject ON VS4TAssetBuiltReq.TBrqTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TAssetBuiltReq.TBrqTBraCode = VS4TBranch.TBraCode) ON VS4TAsset.TAssCode = VS4TAssetBuiltReq.TBrqTAssCode
GO

CREATE VIEW VS4VAssetFix
AS 
SELECT VS4TAssetFix.*, VS4TAssetFixMB.*, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TSection.TSecName, VS4TAsset.*
FROM (VS4TSection RIGHT JOIN (VS4TDepartment RIGHT JOIN (((VS4TAssetFix LEFT JOIN VS4TProject ON VS4TAssetFix.TFstTPrjCode=VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TAssetFix.TFstTBraCode=VS4TBranch.TBraCode) LEFT JOIN VS4TDivision ON VS4TAssetFix.TFstTReqTDivCode=VS4TDivision.TDivCode) ON VS4TDepartment.TDepCode=VS4TAssetFix.TFstTReqTDepCode) ON VS4TSection.TSecCode=VS4TAssetFix.TFstTReqTSecCode) INNER JOIN (VS4TAssetFixMB LEFT JOIN VS4TAsset ON VS4TAssetFixMB.TFSbTAssCode=VS4TAsset.TAssCode) ON VS4TAssetFix.TFstNo=VS4TAssetFixMB.TFSbTFstNo
GO

CREATE VIEW VS4VAssetFixMain
AS 
SELECT VS4TAssetFix.*, VS4TAsset.*, VS4TAssetFixSub.*, VS4TAssetFixType.TFITName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TAssetFixReq.TFRqNo, VS4TAssetFixReq.TFRqDate, VS4TAssetFixReq.TFRqTAssCode, VS4TAssetFixReq.TFRqDescription
FROM VS4TAsset RIGHT JOIN ((((VS4TDepartment RIGHT JOIN (VS4TDivision RIGHT JOIN (VS4TSection RIGHT JOIN VS4TAssetFixReq ON VS4TSection.TSecCode=VS4TAssetFixReq.TFRqTSecCode) ON VS4TDivision.TDivCode=VS4TAssetFixReq.TFRqTDivCode) ON VS4TDepartment.TDepCode=VS4TAssetFixReq.TFRqTDepCode) INNER JOIN VS4TAssetFix ON VS4TAssetFixReq.TFRqNo=VS4TAssetFix.TFstTFRqNo) LEFT JOIN (VS4TAssetFixMB LEFT JOIN VS4TAssetFixType ON VS4TAssetFixMB.TFSbTFITCode=VS4TAssetFixType.TFITCode) ON VS4TAssetFix.TFstNo=VS4TAssetFixMB.TFSbTFstNo) LEFT JOIN VS4TAssetFixSub ON VS4TAssetFix.TFstNo=VS4TAssetFixSub.TFssTFstNo) ON VS4TAsset.TAssCode=VS4TAssetFixReq.TFRqTAssCode
GO

CREATE VIEW VS4VAssetFixReq
AS 
SELECT VS4TAsset.*, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TAssetFixReq.*, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TBranch.TBraName
FROM VS4TAsset INNER JOIN (((VS4TDivision RIGHT JOIN (VS4TDepartment RIGHT JOIN (VS4TSection RIGHT JOIN VS4TAssetFixReq ON VS4TSection.TSecCode = VS4TAssetFixReq.TFRqTSecCode) ON VS4TDepartment.TDepCode = VS4TAssetFixReq.TFRqTDepCode) ON VS4TDivision.TDivCode = VS4TAssetFixReq.TFRqTDivCode) LEFT JOIN VS4TProject ON VS4TAssetFixReq.TFRqTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TAssetFixReq.TFRqTBraCode = VS4TBranch.TBraCode) ON VS4TAsset.TAssCode = VS4TAssetFixReq.TFRqTAssCode
GO

CREATE VIEW VS4VAssetFund
AS 
SELECT VS4TAsset.*, VS4TAssetFund.*, VS4TAssetType.*, VS4TAssetSection.*
FROM VS4TAssetSection RIGHT JOIN ((VS4TAsset LEFT JOIN VS4TAssetType ON VS4TAsset.TAssTAsTCode=VS4TAssetType.TAsTCode) INNER JOIN VS4TAssetFund ON VS4TAsset.TAssCode=VS4TAssetFund.TAFdTAssCode) ON VS4TAssetSection.TAseCode=VS4TAsset.TAssTAseCode
GO

CREATE VIEW VS4VAssetGLPeriod
AS 
SELECT VS4TAsset.*, VS4TAssetCalcType.*, VS4TAssetSection.*, VS4TAssetType.*, VS4TAssetPeriodSub.*, VS4TProject.TPrjName, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TACChart.TACCName, VS4TProject.TPrjMode
FROM VS4TAssetType INNER JOIN (VS4TAssetSection INNER JOIN ((VS4TAssetCalcType INNER JOIN (VS4TAsset LEFT JOIN VS4TACChart ON VS4TAsset.TAssCreditCode = VS4TACChart.TACCCode) ON VS4TAssetCalcType.TACTAlias = VS4TAsset.TAssTACTAlias) INNER JOIN (((((VS4TAssetPeriodSub LEFT JOIN VS4TProject ON VS4TAssetPeriodSub.TSPbTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TAssetPeriodSub.TSPbTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TDivision ON VS4TAssetPeriodSub.TSPbTDivCode = VS4TDivision.TDivCode) LEFT JOIN VS4TDepartment ON VS4TAssetPeriodSub.TSPbTDepCode = VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TAssetPeriodSub.TSPbTSecCode = VS4TSection.TSecCode) ON VS4TAsset.TAssCode = VS4TAssetPeriodSub.TSPbTAssCode) ON VS4TAssetSection.TAseCode = VS4TAsset.TAssTAseCode) ON VS4TAssetType.TAsTCode = VS4TAsset.TAssTAsTCode
GO

CREATE VIEW VS4VAssetInWG
AS 
SELECT VS4TAssetWorkGroup.*, VS4TAsset.*, VS4TAssetType.*, VS4TAssetWorkTime.*
FROM VS4TAssetWorkGroup INNER JOIN (((VS4TAssetType INNER JOIN VS4TAsset ON VS4TAssetType.TAsTCode = VS4TAsset.TAssTAsTCode) INNER JOIN VS4TAssetWGMB ON VS4TAsset.TAssCode = VS4TAssetWGMB.TAegTAssCode) INNER JOIN VS4TAssetWorkTime ON VS4TAsset.TAssCode = VS4TAssetWorkTime.TEntTAssCode) ON VS4TAssetWorkGroup.TAgtCode = VS4TAssetWGMB.TAegTAgtCode
GO

CREATE VIEW VS4VAssetMB
AS 
SELECT VS4TAsset.*, VS4TAssetMB.*, VS4TAssetType.*, VS4TAssetSection.*
FROM (VS4TAssetType RIGHT JOIN (VS4TAssetSection RIGHT JOIN VS4TAsset ON VS4TAssetSection.TAseCode=VS4TAsset.TAssTAseCode) ON VS4TAssetType.TAsTCode=VS4TAsset.TAssTAsTCode) INNER JOIN VS4TAssetMB ON VS4TAsset.TAssCode=VS4TAssetMB.TAsbTAssCode
GO

CREATE VIEW VS4VAssetPeriod
AS 
SELECT VS4VAsset.*, VS4TAssetPeriod.*
FROM VS4VAsset INNER JOIN VS4TAssetPeriod ON VS4VAsset.TAssCode=VS4TAssetPeriod.TAPeTAssCode
GO

CREATE VIEW VS4VAssetPlan
AS 
SELECT VS4TAssetPM.*, VS4TAssetPlan.*, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TEmployee.TEmpFullName, VS4TEmployee.TEmpTitleName, VS4TEmployee.TEmpFirstName, VS4TEmployee.TEmpMiddleName, VS4TEmployee.TEmpLastName, VS4TEmployee.TEmpNickName, VS4TSection.TSecName
FROM ((((((VS4TAssetPlan INNER JOIN VS4TAssetPM ON VS4TAssetPlan.TASPTAFPNo=VS4TAssetPM.TAFPNo) LEFT JOIN VS4TProject ON VS4TAssetPM.TAFPTPrjCode=VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TAssetPM.TAFPTBraCode=VS4TBranch.TBraCode) LEFT JOIN VS4TDivision ON VS4TAssetPM.TAFPTDivCode=VS4TDivision.TDivCode) LEFT JOIN VS4TDepartment ON VS4TAssetPM.TAFPTDepCode=VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TAssetPM.TAFPTSecCode=VS4TSection.TSecCode) LEFT JOIN VS4TEmployee ON VS4TAssetPM.TAFPTEmpCode=VS4TEmployee.TEmpCode
GO

CREATE VIEW VS4VAssetPM
AS 
SELECT VS4TAssetPM.*, VS4TAssetPMMB.*, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TEmployee.TEmpFullName, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TBranch.TBraName, VS4TAssetFixType.*, VS4TAssetFixCCL.*
FROM ((((((VS4TAssetPM LEFT JOIN VS4TDivision ON VS4TAssetPM.TAFPTDivCode = VS4TDivision.TDivCode) LEFT JOIN VS4TDepartment ON VS4TAssetPM.TAFPTDepCode = VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TAssetPM.TAFPTSecCode = VS4TSection.TSecCode) LEFT JOIN VS4TEmployee ON VS4TAssetPM.TAFPTEmpCode = VS4TEmployee.TEmpCode) LEFT JOIN VS4TProject ON VS4TAssetPM.TAFPTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TAssetPM.TAFPTBraCode = VS4TBranch.TBraCode) INNER JOIN ((VS4TAssetFixType LEFT JOIN VS4TAssetFixCCL ON VS4TAssetFixType.TFITCode = VS4TAssetFixCCL.TCCLTFITCode) RIGHT JOIN VS4TAssetPMMB ON VS4TAssetFixType.TFITCode = VS4TAssetPMMB.TAFBTFITCode) ON VS4TAssetPM.TAFPNo = VS4TAssetPMMB.TAFBTAFPNo
GO

CREATE VIEW VS4VAssetPMH
AS 
SELECT VS4TAssetPM.*, VS4TAssetPMMB.*, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TEmployee.TEmpFullName, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TBranch.TBraName
FROM ((((((VS4TAssetPM INNER JOIN VS4TAssetPMMB ON VS4TAssetPM.TAFPNo=VS4TAssetPMMB.TAFBTAFPNo) LEFT JOIN VS4TDivision ON VS4TAssetPM.TAFPTDivCode=VS4TDivision.TDivCode) LEFT JOIN VS4TDepartment ON VS4TAssetPM.TAFPTDepCode=VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TAssetPM.TAFPTSecCode=VS4TSection.TSecCode) LEFT JOIN VS4TEmployee ON VS4TAssetPM.TAFPTEmpCode=VS4TEmployee.TEmpCode) LEFT JOIN VS4TProject ON VS4TAssetPM.TAFPTPrjCode=VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TAssetPM.TAFPTBraCode=VS4TBranch.TBraCode
GO

CREATE VIEW VS4VAssetTransfer
AS 
SELECT VS4TAssetType.*, VS4TAsset.*, VS4TAssetTransMB.*, VS4TAssetTrans.*, VS4TAssetTransType.*, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TAssetSection.TAseName
FROM VS4TAssetType INNER JOIN ((VS4TAssetTransType INNER JOIN (VS4TSection RIGHT JOIN (VS4TDepartment RIGHT JOIN (VS4TDivision RIGHT JOIN (VS4TBranch RIGHT JOIN VS4TAssetTrans ON VS4TBranch.TBraCode=VS4TAssetTrans.TATfToTBraCode) ON VS4TDivision.TDivCode=VS4TAssetTrans.TATfToTDivCode) ON VS4TDepartment.TDepCode=VS4TAssetTrans.TATfToTDepCode) ON VS4TSection.TSecCode=VS4TAssetTrans.TATfToTSecCode) ON VS4TAssetTransType.TATTAlias=VS4TAssetTrans.TATfTATTAlias) INNER JOIN (((VS4TAsset LEFT JOIN VS4TProject ON VS4TAsset.TAssTPrjCode=VS4TProject.TPrjCode) INNER JOIN VS4TAssetTransMB ON VS4TAsset.TAssCode=VS4TAssetTransMB.TATMTAssCode) LEFT JOIN VS4TAssetSection ON VS4TAsset.TAssTAseCode=VS4TAssetSection.TAseCode) ON VS4TAssetTrans.TATfNo=VS4TAssetTransMB.TATMTATfNo) ON VS4TAssetType.TAsTCode=VS4TAsset.TAssTAsTCode
GO

CREATE VIEW VS4VAssetWorkGroup
AS 
SELECT VS4TAssetWorkGroup.*, VS4TAssetWGMB.*, VS4TAsset.*
FROM VS4TAssetWorkGroup INNER JOIN (VS4TAsset INNER JOIN VS4TAssetWGMB ON VS4TAsset.TAssCode=VS4TAssetWGMB.TAegTAssCode) ON VS4TAssetWorkGroup.TAgtCode=VS4TAssetWGMB.TAegTAgtCode
GO

CREATE VIEW VS4VAssetWorkTime
AS 
SELECT VS4TAsset.*, VS4TAssetWorkTime.*, VS4TAssetSection.*, VS4TSection.TSecName, VS4TDepartment.TDepName, VS4TDivision.TDivName
FROM (VS4TAssetSection RIGHT JOIN (((VS4TAsset LEFT JOIN VS4TSection ON VS4TAsset.TAssTSecCode=VS4TSection.TSecCode) LEFT JOIN VS4TDepartment ON VS4TAsset.TAssTDepCode=VS4TDepartment.TDepCode) LEFT JOIN VS4TDivision ON VS4TAsset.TAssTDivCode=VS4TDivision.TDivCode) ON VS4TAssetSection.TAseCode=VS4TAsset.TAssTAseCode) RIGHT JOIN VS4TAssetWorkTime ON VS4TAsset.TAssCode=VS4TAssetWorkTime.TEntTAssCode
GO

CREATE VIEW VS4VAttachSheetDO
AS 
SELECT VS4TInventoryMB.*, VS4TWarehouse.TWahName, VS4TLocation.TLctName, VS4TDO.TPdyNo, VS4TDO.TPdyDate, VS4TDO.TPdyTARNCode, VS4TDO.TPdyCustomerName, VS4TDO.TPdyDeliveryTo, VS4TDO.TPdyCountryOrigin, VS4TDO.TPdyTShpCode, VS4TDO.TPdyTShpName, VS4TDO.TPdyInvoiceStatus, VS4TDO.TPdyDescription, VS4TDO.TPdyCountryTo, VS4TDO.TPdyDistance, VS4TDO.TPdyVehicleNo, VS4TDO.TPdyDriverName, VS4TDO.TPdyDriverPhone, VS4TDO.TPdyTEmpCode, VS4TDO.TPdyLeaveDate, VS4TDO.TPdyLeaveTime, VS4TDO.TPdyRefNo, VS4TDO.TPdyLeaveBy, VS4TDO.TPdyDriverCode, VS4TInventory.TInvNo, VS4TInventory.TInvDate, VS4TInventory.TInvRefNo, VS4TInventory.TInvRefDate, VS4TInventory.TInvRefNo2, VS4TInventory.TInvRefDate2, VS4TInventory.TInvRefNo3, VS4TInventory.TInvRefDate3, VS4TInventory.TInvTPrjCode, VS4TInventory.TInvTJobNo, VS4TInventory.TInvTJbMLn, VS4TInventory.TInvTJPdNo, VS4TInventory.TInvTJPMLn, VS4TInventory.TInvTSecCode, VS4TInventory.TInvTDivCode, VS4TInventory.TInvTDepCode, VS4TInventory.TInvTBraCode, VS4TInventory.TInvFromTBraCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TLocation.TLctTBraCode, VS4TWarehouse.TWahCode, VS4TInventoryLOT.*, VS4TSO.TSODNo, VS4TSO.TSODTSBkCode, VS4TSO.TSODTRCACode, VS4TSO.TSODMode, VS4TSO.TSODCode, VS4TSO.TSODType, VS4TSO.TSODDate, VS4TSO.TSODRefNo, VS4TSO.TSODRefDate, VS4TSO.TSODTEmpCode, VS4TSO.TSODSaleName, VS4TSO.TSODGuideText, VS4TSO.TSODTARNCode, VS4TSO.TSODTARDCode, VS4TSO.TSODContactNote, VS4TSO.TSODContactName, VS4TSO.TSODCustomerName, VS4TSO.TSODCusAddress, VS4TSO.TSODConsignee, VS4TSO.TSODNotifyParty, VS4TSO.TSODTransportFee, VS4TSO.TSODCountryOrigin, VS4TSO.TSODDestination, VS4TSO.TSODDeliveryNote, VS4TSO.TSODPackingNote, VS4TSO.TSODDescription
FROM VS4TUnit INNER JOIN (VS4TInventoryType INNER JOIN (VS4TProduct INNER JOIN (VS4TDO RIGHT JOIN (((VS4TInventory LEFT JOIN VS4TDOMB ON VS4TInventory.TInvNo = VS4TDOMB.TDymDocNo) LEFT JOIN VS4TSO ON VS4TInventory.TInvRefNo = VS4TSO.TSODNo) INNER JOIN (VS4TInventoryLOT INNER JOIN ((VS4TInventoryMB LEFT JOIN VS4TLocation ON VS4TInventoryMB.TInMTLctCode = VS4TLocation.TLctCode) LEFT JOIN VS4TWarehouse ON VS4TLocation.TLctTWahCode = VS4TWarehouse.TWahCode) ON (VS4TInventoryLOT.TIMCLotDate = VS4TInventoryMB.TInMLotDate) AND (VS4TInventoryLOT.TIMCLotNo = VS4TInventoryMB.TInMLotNo) AND (VS4TInventoryLOT.TIMCSerialNo = VS4TInventoryMB.TInMSerialNo) AND (VS4TInventoryLOT.TIMCCustom1 = VS4TInventoryMB.TInMCustom1) AND (VS4TInventoryLOT.TIMCTPdtCode = VS4TInventoryMB.TInMTPdtCode)) ON VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo) ON VS4TDO.TPdyNo = VS4TDOMB.TDymTPdyNo) ON (VS4TProduct.TPdtCode = VS4TInventoryMB.TInMTPdtCode) AND (VS4TProduct.TPdtCode = VS4TInventoryLOT.TIMCTPdtCode)) ON VS4TInventoryType.TInTAlias = VS4TInventory.TInvTInTAlias) ON VS4TUnit.TUntCode = VS4TProduct.TPdtTUntCode
WHERE (((VS4TInventoryType.TInTAlias)='SALEOUT'))
GO

CREATE VIEW VS4VAttachSheetSO
AS 
SELECT VS4TInventory.*, VS4TInventoryMB.*, VS4TWarehouse.TWahName, VS4TLocation.TLctName, VS4TJob.TJobCode, VS4TJob.TJobTARNCode, VS4TJob.TJobCustomerName, VS4TProduct.TPdtCode, VS4TProduct.TPdtBarcode, VS4TPOS.TPOSPackAlias1, VS4TPOS.TPOSPackAlias2, VS4TProduct.TPdtName, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTPTTCode, VS4TProductType.TPTTName, VS4TProduct.TPdtTPDLCode, VS4TProductLine.TPdLName, VS4TProduct.TPdtTPSECode, VS4TProductSection.TPSEName, VS4TProduct.TPdtTPS2Code, VS4TProduct.TPdtTPG1Code, VS4TProductGroup1.TPG1Name, VS4TProduct.TPdtTPG2Code, VS4TJob.TJobTPrjCode, VS4TProject.TPrjMode, VS4TProject.TPrjName, VS4TBranch.TBraName, VS4TSO.TSODNo, VS4TSO.TSODDate, VS4TSO.TSODDueDate, VS4TSO.TSODRefNo, VS4TSO.TSODRefDate, VS4TSO.TSODTEmpCode, VS4TSO.TSODSaleName, VS4TSO.TSODDeliveryDate, VS4TSO.TSODDeliveryTo, VS4TSO.TSODTARNCode, VS4TSO.TSODContactNote, VS4TSO.TSODContactName, VS4TSO.TSODCustomerName, VS4TSO.TSODCusAddress, VS4TSO.TSODSubTotal, VS4TSO.TSODDiscountTotal, VS4TSO.TSODTaxBase, VS4TSO.TSODVATRate, VS4TSO.TSODVATTotal, VS4TSO.TSODNOTAXTotal, VS4TSO.TSODNetTotal, VS4TSO.TSODTotal, VS4TSO.TSODGrandTotal, VS4TSO.TSODNetPayment, VS4TSO.TSODVATType, VS4TSO.TSODDepositText, VS4TSO.TSODDeposit, VS4TSO.TSODIncoType, VS4TSO.TSODInsurance, VS4TSO.TSODFreightFee, VS4TSO.TSODOtherFee, VS4TSO.TSODTotalInRate, VS4TSO.TSODTCurCode, VS4TSO.TSODExchangeRate, VS4TSO.TSODAdjustTotal, VS4TSO.TSODCountryOrigin, VS4TSO.TSODCondition, VS4TSO.TSODConditionDay, VS4TSO.TSODCondition1, VS4TSO.TSODConditionDay1, VS4TSO.TSODStatementNote, VS4TSO.TSODDeliveryNote, VS4TSO.TSODPackingNote, VS4TSO.TSODDayAvailable, VS4TSO.TSODDescription, VS4TSO.TSODCustom1, VS4TSO.TSODCustom2, VS4TSO.TSODCustom3, VS4TSO.TSODCustom4, VS4TSO.TSODCustom5, VS4TSO.TSODInvoiceStatus, VS4TSO.TSODRevision, VS4TSO.TSODApproveStatus, VS4TSO.TSODCancelStatus, VS4TSO.TSODDeliveryStatus, VS4TSO.TSODVerifyStatus, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TLocation.TLctTBraCode, VS4TWarehouse.TWahCode, VS4TSOMB.TSOBPOSName, VS4TSOMB.TSOBDescription, VS4TSOMB.TSOBUnitCalc, VS4TJobMB.TJbMUnitCalc, VS4TProduct.TPdtFlag1, VS4TInventoryLOT.TIMCTPdtCode, VS4TInventoryLOT.TIMCCustom1, VS4TInventoryLOT.TIMCSerialNo, VS4TInventoryLOT.TIMCLotNo, VS4TInventoryLOT.TIMCLotDate, VS4TInventoryLOT.TIMCReceiveNo, VS4TInventoryLOT.TIMCReceiveLn, VS4TInventoryLOT.TIMCJobCode, VS4TInventoryLOT.TIMCIsPremium, VS4TInventoryLOT.TIMCPremiumNote, VS4TInventoryLOT.TIMCCustom2, VS4TInventoryLOT.TIMCCustom3, VS4TInventoryLOT.TIMCCustom4, VS4TInventoryLOT.TIMCCustom5, VS4TInventoryLOT.TIMCScrapLevel, VS4TInventoryLOT.TIMCLotNo2, VS4TInventoryLOT.TIMCGrade, VS4TInventoryLOT.TIMCNoExpire, VS4TInventoryLOT.TIMCExpireDate, VS4TInventoryLOT.TIMCTCgTID, VS4TInventoryLOT.TIMCReserve, VS4TInventoryLOT.TIMCQAStatus, VS4TInventoryLOT.TIMCQANote, VS4TInventoryLOT.TIMCLastUnitCost, VS4TInventoryLOT.TIMCInputCost, VS4TInventoryLOT.TIMCPerQuantity, VS4TInventoryLOT.TIMCUnitCalc, VS4TInventoryLOT.TIMCUnitCost, VS4TInventoryLOT.TIMCCostCode, VS4TInventoryLOT.TIMCTPCTAlias, VS4TInventoryLOT.TIMCTAPNCode, VS4TInventoryLOT.TIMCInvoiceNo, VS4TInventoryLOT.TIMCInvoiceDate, VS4TInventoryLOT.TIMCTPODNo, VS4TInventoryLOT.TIMCTPOBLn, VS4TInventoryLOT.TIMCTPDELn, VS4TInventoryLOT.TIMCTUntCode, VS4TInventoryLOT.TIMCUnitRatio, VS4TInventoryLOT.TIMCUnit2Ratio, VS4TInventoryLOT.TIMCUnit3Ratio, VS4TInventoryLOT.TIMCLastDate, VS4TInventoryLOT.TIMCConsignFSDate, VS4TInventoryLOT.TIMCConsignLSDate, VS4TInventoryLOT.TIMCAccountLevel, VS4TInventoryLOT.TIMCIsOwner, VS4TInventoryLOT.TIMCBarCode
FROM VS4TUnit INNER JOIN (VS4TInventoryType INNER JOIN ((((((VS4TProduct LEFT JOIN VS4TProductType ON VS4TProduct.TPdtTPTTCode = VS4TProductType.TPTTCode) LEFT JOIN VS4TProductLine ON VS4TProduct.TPdtTPDLCode = VS4TProductLine.TPdLCode) LEFT JOIN VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode) LEFT JOIN VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) INNER JOIN (((VS4TInventory LEFT JOIN VS4TJobMB ON (VS4TInventory.TInvTJobNo = VS4TJobMB.TJbMTJobNo) AND (VS4TInventory.TInvTJbMLn = VS4TJobMB.TJbMLn)) LEFT JOIN (VS4TJob LEFT JOIN VS4TProject ON VS4TJob.TJobTPrjCode = VS4TProject.TPrjCode) ON VS4TJobMB.TJbMTJobNo = VS4TJob.TJobNo) INNER JOIN (VS4TInventoryLOT INNER JOIN (((((VS4TInventoryMB LEFT JOIN VS4TLocation ON VS4TInventoryMB.TInMTLctCode = VS4TLocation.TLctCode) LEFT JOIN VS4TSO ON VS4TInventoryMB.TInMTSODNo = VS4TSO.TSODNo) LEFT JOIN VS4TBranch ON VS4TSO.TSODTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TWarehouse ON VS4TLocation.TLctTWahCode = VS4TWarehouse.TWahCode) LEFT JOIN VS4TSOMB ON (VS4TInventoryMB.TInMTSODNo = VS4TSOMB.TSOBTSODNo) AND (VS4TInventoryMB.TInMTSOBLn = VS4TSOMB.TSOBLn)) ON (VS4TInventoryLOT.TIMCLotDate = VS4TInventoryMB.TInMLotDate) AND (VS4TInventoryLOT.TIMCLotNo = VS4TInventoryMB.TInMLotNo) AND (VS4TInventoryLOT.TIMCSerialNo = VS4TInventoryMB.TInMSerialNo) AND (VS4TInventoryLOT.TIMCCustom1 = VS4TInventoryMB.TInMCustom1) AND (VS4TInventoryLOT.TIMCTPdtCode = VS4TInventoryMB.TInMTPdtCode)) ON VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo) ON VS4TProduct.TPdtCode = VS4TInventoryMB.TInMTPdtCode) ON VS4TInventoryType.TInTAlias = VS4TInventory.TInvTInTAlias) ON VS4TUnit.TUntCode = VS4TProduct.TPdtTUntCode
WHERE (((VS4TInventoryType.TInTAlias)='SALEOUT' Or (VS4TInventoryType.TInTAlias)='SALEOUTPOS'))
GO

CREATE VIEW VS4VInventMDS
AS 
SELECT VS4TInventory.TInvNo, VS4TInventoryMB.TInMTPdtCode, VS4TProduct.TPdtName, VS4TInventory.TInvTInTAlias, Sum(VS4TInventoryMB.TInMAmouQuantity) AS TInMAmouQuantity, VS4TProduct.TPdtTUntCode, Sum(VS4TInventoryMB.TInMAmouQuantity2) AS TInMAmouQuantity2, VS4TProduct.TPdtTUntCode2, Sum(VS4TInventoryMB.TInMAmouQuantity3) AS TInMAmouQuantity3, VS4TProduct.TPdtTUntCode3, VS4TInventoryMB.TInMTSODNo, VS4TInventoryMB.TInMTSOBLn, VS4TInventoryMB.TInMTMDSLn, Sum(VS4TInventoryMB.TInMQuantityBase) AS TInMQuantityBase, VS4TInventoryMB.TInMTUntCode
FROM VS4TProduct INNER JOIN (VS4TInventory INNER JOIN VS4TInventoryMB ON VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo) ON VS4TProduct.TPdtCode = VS4TInventoryMB.TInMTPdtCode
GROUP BY VS4TInventory.TInvNo, VS4TInventoryMB.TInMTPdtCode, VS4TProduct.TPdtName, VS4TInventory.TInvTInTAlias, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TInventoryMB.TInMTSODNo, VS4TInventoryMB.TInMTSOBLn, VS4TInventoryMB.TInMTMDSLn, VS4TInventoryMB.TInMTUntCode, VS4TInventory.TInvApproveStatus, VS4TInventory.TInvCancelStatus
HAVING (((VS4TInventory.TInvTInTAlias)='SALEOUT' Or (VS4TInventory.TInvTInTAlias)='SALEOUTPOS') AND ((VS4TInventory.TInvApproveStatus)=1) AND ((VS4TInventory.TInvCancelStatus)=0))
GO

CREATE VIEW VS4VAttachSheetSOH
AS 
SELECT VS4TInventory.*, VS4TSO.*
FROM VS4TInventoryType INNER JOIN (VS4TInventory LEFT JOIN VS4TSO ON VS4TInventory.TInvRefNo = VS4TSO.TSODNo) ON VS4TInventoryType.TInTAlias = VS4TInventory.TInvTInTAlias
WHERE (((VS4TInventoryType.TInTAlias)='SALEOUT' Or (VS4TInventoryType.TInTAlias)='SALEOUTPOS'))
GO

CREATE VIEW VS4VAttachSheetSOM
AS 
SELECT VS4TInventoryMB.*, VS4TSO.*, VS4TSOMB.*, VS4TInventory.TInvNo, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3
FROM VS4TUnit INNER JOIN (VS4TInventoryType INNER JOIN (VS4TSO RIGHT JOIN (VS4TProduct INNER JOIN (VS4TInventory INNER JOIN (((VS4TInventoryMB LEFT JOIN VS4TLocation ON VS4TInventoryMB.TInMTLctCode = VS4TLocation.TLctCode) INNER JOIN VS4TSOMB ON (VS4TInventoryMB.TInMTSODNo = VS4TSOMB.TSOBTSODNo) AND (VS4TInventoryMB.TInMTSOBLn = VS4TSOMB.TSOBLn)) LEFT JOIN VS4TWarehouse ON VS4TLocation.TLctTWahCode = VS4TWarehouse.TWahCode) ON VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo) ON VS4TProduct.TPdtCode = VS4TInventoryMB.TInMTPdtCode) ON VS4TSO.TSODNo = VS4TSOMB.TSOBTSODNo) ON VS4TInventoryType.TInTAlias = VS4TInventory.TInvTInTAlias) ON VS4TUnit.TUntCode = VS4TProduct.TPdtTUntCode
WHERE (((VS4TInventoryType.TInTAlias)='SALEOUT' Or (VS4TInventoryType.TInTAlias)='SALEOUTPOS'))
GO

CREATE VIEW VS4VAverageLOT
AS 
SELECT VS4TInventoryLOT.TIMCTPdtCode, Avg(VS4TInventoryLOT.TIMCUnitCost) AS TIMCUnitCostAvg
FROM VS4TInventoryLOT
GROUP BY VS4TInventoryLOT.TIMCTPdtCode
GO

CREATE VIEW VS4VBalanceSheet
AS 
SELECT VS4TGLTransMove.*, VS4TACChart.*, VS4TACGroupSub.TAGsName, VS4TACGroupSub.TAGsName2, VS4TACGroup.TACGName, VS4TACGroup.TACGName2, VS4TBranch.TBraCode, VS4TBranch.TBraName, VS4TBranch.TBraName2
FROM VS4TBranch RIGHT JOIN (VS4TACGroup INNER JOIN (VS4TACGroupSub INNER JOIN (VS4TACChart INNER JOIN VS4TGLTransMove ON VS4TACChart.TACCCode = VS4TGLTransMove.TGTMTACCCode) ON VS4TACGroupSub.TAGsCode = VS4TACChart.TACCTAGsCode) ON VS4TACGroup.TACGCode = VS4TACGroupSub.TAGsTACGCode) ON VS4TBranch.TBraCode = VS4TGLTransMove.TGTMTBraCode
GO

CREATE VIEW VS4VBank
AS 
SELECT VS4TBank.*, VS4TCompanyBank.*, VS4TBankAccType.*
FROM VS4TBank INNER JOIN (VS4TCompanyBank LEFT JOIN VS4TBankAccType ON VS4TCompanyBank.TCBBAccountType=VS4TBankAccType.TBATID) ON VS4TBank.TBnkCode=VS4TCompanyBank.TCBBTBnkCode
GO

CREATE VIEW VS4VBankBranch
AS 
SELECT VS4TBank.*, VS4TBankBranch.*
FROM VS4TBank INNER JOIN VS4TBankBranch ON VS4TBank.TBnkCode=VS4TBankBranch.TBBrTBnkCode
GO

CREATE VIEW VS4VBankCardFee
AS 
SELECT VS4TBankCardFee.*, VS4TBank.*, VS4TCompanyBank.*, VS4TBankCreditCard.*, VS4TPayment.*, VS4TPaymentType.*
FROM (VS4TPaymentType INNER JOIN VS4TPayment ON VS4TPaymentType.TPyTAlias=VS4TPayment.TPymTPyTAlias) INNER JOIN (((VS4TBank INNER JOIN VS4TBankCardFee ON VS4TBank.TBnkCode=VS4TBankCardFee.TBCFTBnkCode) INNER JOIN VS4TCompanyBank ON VS4TBank.TBnkCode=VS4TCompanyBank.TCBBTBnkCode) INNER JOIN VS4TBankCreditCard ON VS4TCompanyBank.TCBBNo=VS4TBankCreditCard.TBCDTCBBNo) ON VS4TPayment.TPymCode=VS4TBankCardFee.TBCFTPymCode
GO

CREATE VIEW VS4VBankCheque
AS 
SELECT VS4TBankCheque.*, VS4TBank.*
FROM VS4TBank INNER JOIN VS4TBankCheque ON VS4TBank.TBnkCode=VS4TBankCheque.TBCqTBnkCode
GO

CREATE VIEW VS4VBankCreditCard
AS 
SELECT VS4TBankCreditCard.*, VS4TCompanyBank.*, VS4TBank.*
FROM (VS4TBank INNER JOIN VS4TCompanyBank ON VS4TBank.TBnkCode=VS4TCompanyBank.TCBBTBnkCode) INNER JOIN VS4TBankCreditCard ON VS4TCompanyBank.TCBBNo=VS4TBankCreditCard.TBCDTCBBNo
GO

CREATE VIEW VS4VBankSlip
AS 
SELECT VS4TBankSlip.*, VS4TBank.*
FROM VS4TBank INNER JOIN VS4TBankSlip ON VS4TBank.TBnkCode=VS4TBankSlip.TBSLTBnkCode
GO

CREATE VIEW VS4VBOQ
AS 
SELECT VS4TBOQ.*, VS4TBOQMB.*, VS4TBOQMaterial.*, VS4TProject.TPrjCode, VS4TProject.TPrjName, VS4TProject.TPrjName2, VS4TProject.TPrjTPjTCode, VS4TProjectPhase.TPHSTPrjCode, VS4TProjectPhase.TPHSLn, VS4TProjectPhase.TPHSName, VS4TProjectPhase.TPHSName2, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtBarcode
FROM ((VS4TProjectType RIGHT JOIN VS4TProject ON VS4TProjectType.TPjTCode = VS4TProject.TPrjTPjTCode) RIGHT JOIN (VS4TProjectPhase RIGHT JOIN ((VS4TBOQ INNER JOIN (VS4TBOQMB INNER JOIN VS4TBOQMaterial ON (VS4TBOQMB.TBQBLn = VS4TBOQMaterial.TBQMTBQBLn) AND (VS4TBOQMB.TBQBTBOQNo = VS4TBOQMaterial.TBQMTBQBTBOQNo)) ON VS4TBOQ.TBOQNo = VS4TBOQMB.TBQBTBOQNo) LEFT JOIN VS4TProjectBOQ ON VS4TBOQ.TBOQNo = VS4TProjectBOQ.TP2QTBOQNo) ON (VS4TProjectPhase.TPHSLn = VS4TProjectBOQ.TP2QTPHSLn) AND (VS4TProjectPhase.TPHSTPrjCode = VS4TProjectBOQ.TP2QTPHSTPrjCode)) ON VS4TProject.TPrjCode = VS4TProjectPhase.TPHSTPrjCode) LEFT JOIN VS4TProduct ON VS4TBOQMaterial.TBQMTPdtCode = VS4TProduct.TPdtCode
GO

CREATE VIEW VS4VBranch
AS 
SELECT VS4TBranch.*, VS4TBranchType.*, VS4TCompany.*, VS4TCurrency.*, VS4TCountry.TCouName, VS4TCountry_1.TCouName AS VBRATCouName, VS4TCountry_1.TCouName2 AS VBRATCouNAME2
FROM VS4TCountry RIGHT JOIN ((VS4TCompany LEFT JOIN VS4TCountry AS VS4TCountry_1 ON VS4TCompany.TCmpTCouCode=VS4TCountry_1.TCouCode) RIGHT JOIN (VS4TBranchType INNER JOIN (VS4TBranch LEFT JOIN VS4TCurrency ON VS4TBranch.TBraTCurCode=VS4TCurrency.TCurCode) ON VS4TBranchType.TBrTAlias=VS4TBranch.TBraTBrTAlias) ON VS4TCompany.TCmpCode=VS4TBranch.TBraTCmpCode) ON VS4TCountry.TCouCode=VS4TBranch.TBraTCouCode
GO

CREATE VIEW VS4VBudget
AS 
SELECT VS4TBudget.*, VS4TBudgetMB.*, VS4TACChart.TACCName, VS4TACChart.TACCName2
FROM VS4TBudget INNER JOIN (VS4TACChart INNER JOIN VS4TBudgetMB ON VS4TACChart.TACCCode = VS4TBudgetMB.TBDMTACCCode) ON VS4TBudget.TBDGNo = VS4TBudgetMB.TBDMTBDGNo
GO

CREATE VIEW VS4VBusinessFlow
AS 
SELECT VS4TBusinessFlow.*, VS4TBusinessFlowMB.*
FROM VS4TBusinessFlow INNER JOIN VS4TBusinessFlowMB ON VS4TBusinessFlow.TBsFCode=VS4TBusinessFlowMB.TBFMTBsFCode
GO

CREATE VIEW VS4VCashDeposit
AS 
SELECT VS4TCashDeposit.*, VS4TCashDepositMB.*, VS4TCompanyBank.*, VS4TChequeRec.*, VS4TAR.TARNName, VS4TAR.TARNName2, VS4TEmployee.TEmpFullName, VS4TAP.TAPNName, VS4TChequeSub.*
FROM VS4TCompanyBank INNER JOIN ((VS4TChequeSub LEFT JOIN VS4TAP ON VS4TChequeSub.TCHSTAPNCode=VS4TAP.TAPNCode) RIGHT JOIN ((VS4TCashDeposit LEFT JOIN VS4TEmployee ON VS4TCashDeposit.TDPSTEmpCode=VS4TEmployee.TEmpCode) INNER JOIN ((VS4TCashDepositMB LEFT JOIN (((VS4TDepositChq LEFT JOIN VS4TChequeRec ON VS4TDepositChq.TCDCTCHRNo=VS4TChequeRec.TCHRNo) LEFT JOIN VS4TAR ON VS4TChequeRec.TCHRTARNCode=VS4TAR.TARNCode) LEFT JOIN VS4TARVoucher ON VS4TChequeRec.TCHRTRVRTRVHNo=VS4TARVoucher.TRVHNo) ON (VS4TCashDepositMB.TDPMTDPSNo=VS4TDepositChq.TCDCTDPMTDPSNo) AND (VS4TCashDepositMB.TDPMLn=VS4TDepositChq.TCDCTDPMLn)) LEFT JOIN VS4TDepositChqSub ON (VS4TCashDepositMB.TDPMTDPSNo=VS4TDepositChqSub.TCDQTDPMTDPSNo) AND (VS4TCashDepositMB.TDPMLn=VS4TDepositChqSub.TCDQTDPMLn)) ON VS4TCashDeposit.TDPSNo=VS4TCashDepositMB.TDPMTDPSNo) ON VS4TChequeSub.TCHSNo=VS4TDepositChqSub.TCDQTCHSNo) ON VS4TCompanyBank.TCBBNo=VS4TCashDepositMB.TDPMTCBBNo
GO

CREATE VIEW VS4VCashDepositRVR
AS 
SELECT VS4TCashDeposit.*, VS4TCashDepositMB.*, VS4TCompanyBank.*, VS4TChequeRec.*, VS4TAR.TARNName, VS4TAR.TARNName2, VS4TEmployee.TEmpFullName, VS4TARVDocRef.*
FROM (VS4TCompanyBank INNER JOIN ((VS4TCashDeposit LEFT JOIN VS4TEmployee ON VS4TCashDeposit.TDPSTEmpCode=VS4TEmployee.TEmpCode) INNER JOIN (VS4TCashDepositMB LEFT JOIN (((VS4TDepositChq LEFT JOIN VS4TChequeRec ON VS4TDepositChq.TCDCTCHRNo=VS4TChequeRec.TCHRNo) LEFT JOIN VS4TAR ON VS4TChequeRec.TCHRTARNCode=VS4TAR.TARNCode) LEFT JOIN VS4TARVoucher ON VS4TChequeRec.TCHRTRVRTRVHNo=VS4TARVoucher.TRVHNo) ON (VS4TCashDepositMB.TDPMTDPSNo=VS4TDepositChq.TCDCTDPMTDPSNo) AND (VS4TCashDepositMB.TDPMLn=VS4TDepositChq.TCDCTDPMLn)) ON VS4TCashDeposit.TDPSNo=VS4TCashDepositMB.TDPMTDPSNo) ON VS4TCompanyBank.TCBBNo=VS4TCashDepositMB.TDPMTCBBNo) LEFT JOIN VS4TARVDocRef ON VS4TARVoucher.TRVHNo=VS4TARVDocRef.TRDRTRVHNo
GO

CREATE VIEW VS4VCashFlow
AS 
SELECT VS4TGLTransMove.*, VS4TACChart.*, VS4TBranch.TBraCode, VS4TBranch.TBraName, VS4TBranch.TBraName2
FROM VS4TBranch RIGHT JOIN (VS4TACChart INNER JOIN VS4TGLTransMove ON VS4TACChart.TACCCode = VS4TGLTransMove.TGTMTACCCode) ON VS4TBranch.TBraCode = VS4TGLTransMove.TGTMTBraCode
GO

CREATE VIEW VS4VCashRequest
AS 
SELECT VS4TCashRequest.*, VS4TCashRequestMB.*, VS4TOtherExpense.*
FROM VS4TOtherExpense RIGHT JOIN (VS4TCashRequest INNER JOIN VS4TCashRequestMB ON VS4TCashRequest.TCRQNo = VS4TCashRequestMB.TCRMTCRQNo) ON VS4TOtherExpense.TOExCode = VS4TCashRequestMB.TCRMTOEXCode
GO

CREATE VIEW VS4VCategory
AS 
SELECT VS4TCategory.*, VS4TCategoryMB.*, VS4TPOS.*
FROM VS4TPOS RIGHT JOIN (VS4TCategory LEFT JOIN VS4TCategoryMB ON VS4TCategory.TCatCode=VS4TCategoryMB.TCaMTCatCode) ON VS4TPOS.TPOSCode=VS4TCategoryMB.TCaMTPOSCode
GO

CREATE VIEW VS4VCertificate
AS 
SELECT VS4TCertificate.*, VS4TCertificateSub.*, VS4TProduct.*, VS4TPOS.*, VS4TBranch.TBraName
FROM (VS4TCertificate LEFT JOIN VS4TBranch ON VS4TCertificate.TCerTBraCode = VS4TBranch.TBraCode) INNER JOIN ((VS4TCertificateSub LEFT JOIN VS4TPOS ON VS4TCertificateSub.TCeMProductCode = VS4TPOS.TPOSCode) LEFT JOIN VS4TProduct ON VS4TPOS.TPOSCode = VS4TProduct.TPdtCode) ON VS4TCertificate.TCerNo = VS4TCertificateSub.TCeMTCerNo
GO

CREATE VIEW VS4VCheque
AS 
SELECT DISTINCT VS4TChequeSub.*, VS4TBank.TBnkName, VS4TAPVoucherPay.*, VS4TAPVoucher.*, VS4TProject.TPrjCode, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TAPInvoice.TIAPNo, VS4TAPInvoice.TIAPDate, VS4TBank.TBnkCode, VS4TCompanyBank.TCBBNo, VS4TCompanyBank.TCBBName, VS4TCompanyBank.TCBBName2, VS4TCompanyBank.TCBBTBraCode, VS4TCompanyBank.TCBBTBnkCode, VS4TCompanyBank.TCBBAccountType, VS4TCompanyBank.TCBBAccountName, VS4TCompanyBank.TCBBAccountNo, VS4TCompanyBank.TCBBAccountBranch, VS4TCompanyBank.TCBBCreditLimit, VS4TCompanyBank.TCBBCashBalance, VS4TCompanyBank.TCBBTACCCode, VS4TCompanyBank.TCBBParentBook, VS4TCompanyBank.TCBBBalance, VS4TCompanyBank.TCBBBalanceDate, VS4TCompanyBank.TCBBSwift, VS4TAP.TAPNCode, VS4TAP.TAPNName, VS4TAP.TAPNName2
FROM ((VS4TBank RIGHT JOIN ((VS4TChequeSub LEFT JOIN VS4TCompanyBank ON VS4TChequeSub.TCHSTCBBNo = VS4TCompanyBank.TCBBNo) LEFT JOIN VS4TAP ON VS4TChequeSub.TCHSTAPNCode = VS4TAP.TAPNCode) ON VS4TBank.TBnkCode = VS4TCompanyBank.TCBBTBnkCode) LEFT JOIN (VS4TAPInvoice RIGHT JOIN (VS4TAPInvoicePay RIGHT JOIN VS4TChequeSub2IV ON (VS4TAPInvoicePay.TPIPLn = VS4TChequeSub2IV.TS2ITPIPLn) AND (VS4TAPInvoicePay.TPIPTIAPNo = VS4TChequeSub2IV.TS2ITPIPTIAPNo)) ON VS4TAPInvoice.TIAPNo = VS4TAPInvoicePay.TPIPTIAPNo) ON VS4TChequeSub.TCHSNo = VS4TChequeSub2IV.TS2ITCHSNo) LEFT JOIN ((VS4TAPVoucher LEFT JOIN VS4TProject ON VS4TAPVoucher.TAPVTPrjCode = VS4TProject.TPrjCode) RIGHT JOIN (VS4TAPVoucherPay RIGHT JOIN VS4TChequeSub2PV ON (VS4TAPVoucherPay.TPVPLn = VS4TChequeSub2PV.TS2PTPVPLn) AND (VS4TAPVoucherPay.TPVPTAPVNo = VS4TChequeSub2PV.TS2PTPVPTAPVNo)) ON VS4TAPVoucher.TAPVNo = VS4TAPVoucherPay.TPVPTAPVNo) ON VS4TChequeSub.TCHSNo = VS4TChequeSub2PV.TS2PTCHSNo
GO

CREATE VIEW VS4VChequeRec
AS 
SELECT VS4TChequeRec.*, VS4TARVoucherPay.*, VS4TARVoucher.*, VS4TAR.*, VS4TProject.TPrjCode, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TARInvoice.TIvoNo, VS4TARInvoice.TIvoDate, VS4TBank.TBnkCode, VS4TBank.TBnkName, VS4TCompanyBank.TCBBNo, VS4TCompanyBank.TCBBName, VS4TCompanyBank.TCBBTBraCode, VS4TCompanyBank.TCBBTBnkCode, VS4TCompanyBank.TCBBAccountType, VS4TCompanyBank.TCBBAccountName, VS4TCompanyBank.TCBBAccountNo, VS4TCompanyBank.TCBBAccountBranch, VS4TCompanyBank.TCBBCreditLimit, VS4TCompanyBank.TCBBCashBalance, VS4TCompanyBank.TCBBTACCCode, VS4TCompanyBank.TCBBParentBook
FROM ((VS4TARVoucher LEFT JOIN VS4TProject ON VS4TARVoucher.TRVHTPrjCode = VS4TProject.TPrjCode) RIGHT JOIN VS4TARVoucherPay ON VS4TARVoucher.TRVHNo = VS4TARVoucherPay.TRVRTRVHNo) RIGHT JOIN (VS4TARInvoice RIGHT JOIN (VS4TARInvoicePay RIGHT JOIN (((VS4TBank RIGHT JOIN ((VS4TChequeRec LEFT JOIN VS4TCompanyBank ON VS4TChequeRec.TCHRTCBBNo = VS4TCompanyBank.TCBBNo) LEFT JOIN VS4TAR ON VS4TChequeRec.TCHRTARNCode = VS4TAR.TARNCode) ON VS4TBank.TBnkCode = VS4TCompanyBank.TCBBTBnkCode) LEFT JOIN VS4TChequeRec2IV ON VS4TChequeRec.TCHRNo = VS4TChequeRec2IV.TR2ITCHRNo) LEFT JOIN VS4TChequeRec2RV ON VS4TChequeRec.TCHRNo = VS4TChequeRec2RV.TR2RTCHRNo) ON (VS4TARInvoicePay.TIPyLn = VS4TChequeRec2IV.TR2ITIPyLn) AND (VS4TARInvoicePay.TIPyTIvoNo = VS4TChequeRec2IV.TR2ITIPyTIvoNo)) ON VS4TARInvoice.TIvoNo = VS4TARInvoicePay.TIPyTIvoNo) ON (VS4TARVoucherPay.TRVRLn = VS4TChequeRec2RV.TR2RTRVRLn) AND (VS4TARVoucherPay.TRVRTRVHNo = VS4TChequeRec2RV.TR2RTRVRTRVHNo)
GO

CREATE VIEW VS4VChequeRec2RV
AS 
SELECT VS4TChequeRec.*, VS4TAR.TARNName, VS4TAR.TARNName2, VS4TARVDocRef.TRDRRefDocType
FROM (((VS4TDepositChq RIGHT JOIN VS4TChequeRec ON VS4TDepositChq.TCDCTCHRNo=VS4TChequeRec.TCHRNo) LEFT JOIN VS4TAR ON VS4TChequeRec.TCHRTARNCode=VS4TAR.TARNCode) LEFT JOIN VS4TARVoucher ON VS4TChequeRec.TCHRTRVRTRVHNo=VS4TARVoucher.TRVHNo) LEFT JOIN VS4TARVDocRef ON VS4TARVoucher.TRVHNo=VS4TARVDocRef.TRDRTRVHNo
GO

CREATE VIEW VS4VCode
AS 
SELECT VS4TCode.*, VS4TCodeGroup.*, VS4TCommandGroup.*
FROM (VS4TCodeGroup LEFT JOIN VS4TCommandGroup ON VS4TCodeGroup.TCoGTCmGAlias=VS4TCommandGroup.TCmGAlias) INNER JOIN VS4TCode ON VS4TCodeGroup.TCoGAlias=VS4TCode.TCodTCoGAlias
GO

CREATE VIEW VS4VCommand
AS 
SELECT VS4TCommand.*, VS4TCommandGroup.*
FROM VS4TCommandGroup INNER JOIN VS4TCommand ON VS4TCommandGroup.TCmGAlias=VS4TCommand.TCmdTCmGAlias
GO

CREATE VIEW VS4VCompetitor
AS 
SELECT VS4TCompetitor.*, VS4TBusinessMajor.*, VS4TBusinessType.*, VS4TCountry.*
FROM VS4TCountry INNER JOIN (VS4TBusinessType INNER JOIN (VS4TBusinessMajor INNER JOIN VS4TCompetitor ON VS4TBusinessMajor.TBsMCode=VS4TCompetitor.TCptTBsMCode) ON VS4TBusinessType.TBsTCode=VS4TCompetitor.TCptTBsTCode) ON VS4TCountry.TCouCode=VS4TCompetitor.TCptTCouCode
GO

CREATE VIEW VS4VCompetSection
AS 
SELECT VS4TCompetitor.*, VS4TBusinessMajor.*, VS4TBusinessType.*, VS4TCountry.*, VS4TCompetSection.*, VS4TProductSection.*
FROM VS4TProductSection INNER JOIN (VS4TCountry INNER JOIN ((VS4TBusinessType INNER JOIN (VS4TBusinessMajor INNER JOIN VS4TCompetitor ON VS4TBusinessMajor.TBsMCode=VS4TCompetitor.TCptTBsMCode) ON VS4TBusinessType.TBsTCode=VS4TCompetitor.TCptTBsTCode) INNER JOIN VS4TCompetSection ON VS4TCompetitor.TCptCode=VS4TCompetSection.TCPSTCPTCode) ON VS4TCountry.TCouCode=VS4TCompetitor.TCptTCouCode) ON VS4TProductSection.TPSECode=VS4TCompetSection.TCPSTPSECode
GO

CREATE VIEW VS4VComSale
AS 
SELECT VS4TComSale.*, VS4TComSaleMB.*, VS4TEmployee.*
FROM VS4TComSale INNER JOIN (VS4TComSaleMB LEFT JOIN VS4TEmployee ON VS4TComSaleMB.TCsBTEmpCode = VS4TEmployee.TEmpCode) ON VS4TComSale.TCosNo = VS4TComSaleMB.TCsBTCosNo
GO

CREATE VIEW VS4VCurrency
AS 
SELECT VS4TCurrency.*
FROM VS4TCurrency
GO

CREATE VIEW VS4VDeliveryIN
AS 
SELECT VS4TDeliveryIN.*, VS4TDeliveryINMB.*, VS4TAPInvoice.*, VS4TAPInvoiceMB.*
FROM (VS4TAPInvoice INNER JOIN (VS4TDeliveryIN INNER JOIN VS4TDeliveryINMB ON VS4TDeliveryIN.TDCINo = VS4TDeliveryINMB.TDIMTDCINo) ON VS4TAPInvoice.TIAPNo = VS4TDeliveryINMB.TDIMTIAPNo) INNER JOIN VS4TAPInvoiceMB ON VS4TAPInvoice.TIAPNo = VS4TAPInvoiceMB.TIPMTIAPNo
GO

CREATE VIEW VS4VDeliveryOut
AS 
SELECT VS4TDeliveryOut.*, VS4TDeliveryOutMB.*, VS4TARInvoice.*, VS4TARInvoiceMB.*
FROM (VS4TDeliveryOut INNER JOIN (VS4TARInvoice INNER JOIN VS4TDeliveryOutMB ON VS4TARInvoice.TIvoNo = VS4TDeliveryOutMB.TDOMTIvoNo) ON VS4TDeliveryOut.TDCONo = VS4TDeliveryOutMB.TDOMTDCONo) INNER JOIN VS4TARInvoiceMB ON VS4TARInvoice.TIvoNo = VS4TARInvoiceMB.TIoMTIvoNo
GO

CREATE VIEW VS4VDO
AS 
SELECT VS4TDO.*, VS4TDOMB.*, VS4TARInvoiceMB.*, VS4TARInvoice.TIvoNo, VS4TARInvoice.TIvoDate, VS4TARInvoice.TIvoContactNote, VS4TARInvoice.TIvoContactName, VS4TARInvoice.TIvoCustomerName, VS4TARInvoice.TIvoCusAddress, VS4TARInvoice.TIvoTARNCode, VS4TARInvoice.TIvoSubTotal, VS4TARInvoice.TIvoVATTotal, VS4TARInvoice.TIvoGrandTotal, VS4TProject.TPrjMode, VS4TDOMBDetail.*, VS4TShipping.TSHPName, VS4TShipping_1.TSHPName AS VDODFirstShipName, VS4TARInvoice.TIvoDeliveryTo, VS4TARInvoice.TIvoDeliveryNote, VS4TARInvoice.TIvoPackingNote, VS4TARInvoice.TIvoDeliveryCond, VS4TARInvoice.TIvoTShpCode, VS4TARInvoice.TIvoTRouCode
FROM ((VS4TDO LEFT JOIN VS4TProject ON VS4TDO.TPdyTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TShipping AS VS4TShipping_1 ON VS4TDO.TPdyTShpCode = VS4TShipping_1.TSHPCode) INNER JOIN (((VS4TDOMB LEFT JOIN VS4TARInvoice ON VS4TDOMB.TDymDocNo = VS4TARInvoice.TIvoNo) LEFT JOIN VS4TShipping ON VS4TDOMB.TDymTShpCode = VS4TShipping.TSHPCode) LEFT JOIN (VS4TARInvoiceMB LEFT JOIN VS4TDOMBDetail ON (VS4TARInvoiceMB.TIoMTIvoNo = VS4TDOMBDetail.TDMDTIoMTIvoNo) AND (VS4TARInvoiceMB.TIoMLn = VS4TDOMBDetail.TDMDTIoMLn)) ON VS4TARInvoice.TIvoNo = VS4TARInvoiceMB.TIoMTIvoNo) ON VS4TDO.TPdyNo = VS4TDOMB.TDymTPdyNo
GO

CREATE VIEW VS4VDOBOXSet
AS 
SELECT VS4TDOBoxSet.*, VS4TDOBoxSetNo.*, VS4TDOBoxSetMB.*, VS4TARInvoice.*
FROM ((VS4TDOBoxSet LEFT JOIN VS4TDOBoxSetMB ON VS4TDOBoxSet.TDBSNo = VS4TDOBoxSetMB.TDSMTDBSNo) LEFT JOIN VS4TDOBoxSetNo ON VS4TDOBoxSet.TDBSNo = VS4TDOBoxSetNo.TDSNTDBSNo) LEFT JOIN VS4TARInvoice ON VS4TDOBoxSetMB.TDSMDocNo = VS4TARInvoice.TIvoNo
GO

CREATE VIEW VS4VDOPlan
AS 
SELECT VS4TDO.TPdyDate, VS4TDOMB.TDymTARNCode, VS4TDOMB.TDymCustomerName, VS4TDOMB.TDymDeliveryTo, VS4TDOMB.TDymCityTo, VS4TDOMB.TDymAppointTime, VS4TDO.TPdyApproveStatus, VS4TDO.TPdyCancelStatus, VS4TDOMB.TDymTRouCode, VS4TRoute.TRouName, VS4TDO.TPdyVehicleNo, VS4TDO.TPdyDriverCode, VS4TDO.TPdyDriverName, Min(VS4TDOMB.TDymTimeIn) AS TDymTimeIn, Max(VS4TDOMB.TDymTimeOut) AS TDymTimeOut, VS4TDOMB.TDymMile, VS4TDOMB.TDymTPdyNo, VS4TDOMB.TDymRountOrder
FROM VS4TDO INNER JOIN (VS4TDOMB LEFT JOIN VS4TRoute ON VS4TDOMB.TDymTRouCode = VS4TRoute.TRouCode) ON VS4TDO.TPdyNo = VS4TDOMB.TDymTPdyNo
GROUP BY VS4TDO.TPdyDate, VS4TDOMB.TDymTARNCode, VS4TDOMB.TDymCustomerName, VS4TDOMB.TDymDeliveryTo, VS4TDOMB.TDymCityTo, VS4TDOMB.TDymAppointTime, VS4TDO.TPdyApproveStatus, VS4TDO.TPdyCancelStatus, VS4TDOMB.TDymTRouCode, VS4TRoute.TRouName, VS4TDO.TPdyVehicleNo, VS4TDO.TPdyDriverCode, VS4TDO.TPdyDriverName, VS4TDOMB.TDymMile, VS4TDOMB.TDymTPdyNo, VS4TDOMB.TDymRountOrder
GO

CREATE VIEW VS4VDrawing
AS 
SELECT VS4TDrawing.*, VS4TDrawingMB.*
FROM VS4TDrawing INNER JOIN VS4TDrawingMB ON VS4TDrawing.TDwgCode=VS4TDrawingMB.TDwMTDwgCode
GO

CREATE VIEW VS4VDupBarcodeA
AS 
SELECT VS4TProduct.TPdtBarCode AS VDupBarCode, Count(VS4TProduct.TPdtBarCode) AS VDupTime
FROM VS4TProduct
GROUP BY VS4TProduct.TPdtBarCode
HAVING (((Count(VS4TProduct.TPdtBarCode))>1))
GO

CREATE VIEW VS4VDupBarcode
AS 
SELECT *
FROM VS4TProduct INNER JOIN VS4VDupBarcodeA ON VS4TProduct.TPdtBarCode=VS4VDupBarcodeA.VDupBarCode
GO

CREATE VIEW VS4VEmpAddMoney
AS 
SELECT VS4TEmpAddMoney.*, VS4TEmpAddMoneyTY.*
FROM VS4TEmpAddMoneyTY INNER JOIN VS4TEmpAddMoney ON VS4TEmpAddMoneyTY.TAMTAlias = VS4TEmpAddMoney.TAmyTAMTAlias
GO

CREATE VIEW VS4VEmpAmass
AS 
SELECT VS4TEmpSlipDoc.TEpsTEmpCode, VS4TEmpSlipDoc.TEpsCheckGroup, VS4TEmpSlipDoc.TEpsTSAPTEmTCode, VS4TEmpSlipDoc.TEpsTSaPDate, VS4TEmpSlipDoc.TEpsBalanceFlag, VS4TEmpSlipDoc.TEpsSalaryPeriod, VS4TEmpSlipMB.TSmbTAmyCode, VS4TEmpSlipMB.TSmbTAMTAlias, VS4TEmpSlipMB.TSmbAmassAmount, VS4TEmpSlipMB.TSmbDebit, VS4TEmpSlipMB.TSmbCrebit, VS4TEmpSlipMB.TSmbCheckMoney, VS4TEmpSlipMB.TSmbCheckFix, VS4TEmpSlipMB.TSmbInterestAmass, VS4TEmpAddMoney.*, VS4TEmpAddMoneyTY.*, Month(TEpsTSaPDate) AS VEPSMonth, Year(TEpsTSaPDate) AS VEPSYear
FROM VS4TEmpSlipDoc INNER JOIN ((VS4TEmpAddMoneyTY INNER JOIN VS4TEmpAddMoney ON VS4TEmpAddMoneyTY.TAMTAlias=VS4TEmpAddMoney.TAmyTAMTAlias) INNER JOIN VS4TEmpSlipMB ON VS4TEmpAddMoney.TAmyCode=VS4TEmpSlipMB.TSmbTAmyCode) ON (VS4TEmpSlipDoc.TEpsNo=VS4TEmpSlipMB.TSmbTEpsNo) AND (VS4TEmpSlipDoc.TEpsCheckGroup=VS4TEmpSlipMB.TSmbTEpsCheckGroup)
WHERE (((VS4TEmpSlipDoc.TEpsApproveStatus)=1) AND ((VS4TEmpSlipDoc.TEpsCancelStatus)=0))
GO

CREATE VIEW VS4VEmpPeriodLast
AS 
SELECT VS4TEmpSlipDoc.TEpsTEmpCode, VS4TEmpSlipDoc.TEpsCheckGroup, VS4TEmpSlipDoc.TEpsTSAPTEmTCode, Max(VS4TEmpSlipDoc.TEpsTSaPDate) AS TEpsTSaPDate, Min(VS4TEmpSlipDoc.TEpsBalanceFlag) AS TEpsBalanceFlag
FROM VS4TEmpSlipDoc
GROUP BY VS4TEmpSlipDoc.TEpsTEmpCode, VS4TEmpSlipDoc.TEpsCheckGroup, VS4TEmpSlipDoc.TEpsTSAPTEmTCode, VS4TEmpSlipDoc.TEpsApproveStatus, VS4TEmpSlipDoc.TEpsCancelStatus
HAVING (((VS4TEmpSlipDoc.TEpsApproveStatus)=1) AND ((VS4TEmpSlipDoc.TEpsCancelStatus)=0))
GO

CREATE VIEW VS4VEmpAmassType
AS 
SELECT VS4TEmpAmassType.*, VS4TEmployee.*, VS4TEmployeeType.*, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TBranch.TBraName, VS4TSection.TSecCode, VS4TDepartment.TDepCode, VS4TDivision.TDivCode, VS4TBranch.TBraCode, VS4TDivision.TDivTBraCode, VS4TSection.TSecName2, VS4TDepartment.TDepName2, VS4TDivision.TDivName2, VS4TDivision.TDivLevel, VS4TBranch.TBraName2
FROM VS4TEmployeeType RIGHT JOIN (VS4TDivision RIGHT JOIN (VS4TBranch INNER JOIN (VS4TSection RIGHT JOIN (VS4TDepartment RIGHT JOIN (VS4TEmpAmassType LEFT JOIN VS4TEmployee ON VS4TEmpAmassType.TEATTEmpCode = VS4TEmployee.TEmpCode) ON VS4TDepartment.TDepCode = VS4TEmpAmassType.TEATDepCode) ON VS4TSection.TSecCode = VS4TEmpAmassType.TEATSecCode) ON VS4TBranch.TBraCode = VS4TEmpAmassType.TEATTBraCode) ON VS4TDivision.TDivCode = VS4TEmpAmassType.TEATTDivCode) ON VS4TEmployeeType.TEmTCode = VS4TEmpAmassType.TEATTEmTCode
GO

CREATE VIEW VS4VEmpAmassYear
AS 
SELECT VS4TEmpSlipDoc.TEpsTEmpCode, VS4TEmpSlipDoc.TEpsCheckGroup, Year(TEpsTSaPDate) AS VEMAYear, VS4TEmpSlipDoc.TEpsBalanceFlag, VS4TEmpSlipMB.TSmbTAmyCode, VS4TEmpSlipMB.TSmbTAMTAlias, Sum(VS4TEmpSlipMB.TSmbAmassAmount) AS TSmbAmassAmount, Sum(VS4TEmpSlipMB.TSmbDebit) AS TSmbDebit, Sum(VS4TEmpSlipMB.TSmbCrebit) AS TSmbCrebit, VS4TEmpSlipMB.TSmbCheckMoney, VS4TEmpSlipMB.TSmbCheckFix, Sum(VS4TEmpSlipMB.TSmbInterestAmass) AS TSmbInterestAmass, VS4TEmpAddMoney.TAmyName, VS4TEmpAddMoneyTY.TAMTName
FROM VS4TEmpSlipDoc INNER JOIN ((VS4TEmpAddMoneyTY INNER JOIN VS4TEmpAddMoney ON VS4TEmpAddMoneyTY.TAMTAlias = VS4TEmpAddMoney.TAmyTAMTAlias) INNER JOIN VS4TEmpSlipMB ON VS4TEmpAddMoney.TAmyCode = VS4TEmpSlipMB.TSmbTAmyCode) ON (VS4TEmpSlipDoc.TEpsCheckGroup = VS4TEmpSlipMB.TSmbTEpsCheckGroup) AND (VS4TEmpSlipDoc.TEpsNo = VS4TEmpSlipMB.TSmbTEpsNo)
GROUP BY VS4TEmpSlipDoc.TEpsTEmpCode, VS4TEmpSlipDoc.TEpsCheckGroup, Year(TEpsTSaPDate), VS4TEmpSlipDoc.TEpsBalanceFlag, VS4TEmpSlipMB.TSmbTAmyCode, VS4TEmpSlipMB.TSmbTAMTAlias, VS4TEmpSlipMB.TSmbCheckMoney, VS4TEmpSlipMB.TSmbCheckFix, VS4TEmpAddMoney.TAmyName, VS4TEmpAddMoneyTY.TAMTName, VS4TEmpSlipDoc.TEpsApproveStatus, VS4TEmpSlipDoc.TEpsCancelStatus
HAVING (((VS4TEmpSlipDoc.TEpsApproveStatus)=1) AND ((VS4TEmpSlipDoc.TEpsCancelStatus)=0))
GO

CREATE VIEW VS4VEmpBankBranch
AS 
SELECT VS4TEmployeeBank.*, VS4TBank.*, VS4TEmployee.*, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TEmployeeType.TEmTCode, VS4TEmployeeType.TEmTName, VS4TBankAccType.TBATName, VS4TBankAccType.TBATName2, VS4TCountry.TCouName, VS4TPosition.TPstName
FROM (((((((VS4TEmployee LEFT JOIN VS4TBranch ON VS4TEmployee.TEmpTBraCode=VS4TBranch.TBraCode) LEFT JOIN VS4TDivision ON VS4TEmployee.TEmpTDivCode=VS4TDivision.TDivCode) LEFT JOIN VS4TDepartment ON VS4TEmployee.TEmpTDepCode=VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TEmployee.TEmpTSecCode=VS4TSection.TSecCode) LEFT JOIN VS4TEmployeeType ON VS4TEmployee.TEmpTEmTCode=VS4TEmployeeType.TEmTCode) LEFT JOIN VS4TCountry ON VS4TEmployee.TEmpTCouCode=VS4TCountry.TCouCode) LEFT JOIN VS4TPosition ON VS4TEmployee.TEmpTPstCode=VS4TPosition.TPstCode) INNER JOIN (VS4TBank INNER JOIN (VS4TEmployeeBank LEFT JOIN VS4TBankAccType ON VS4TEmployeeBank.TEmBAccountType=VS4TBankAccType.TBATID) ON VS4TBank.TBnkCode=VS4TEmployeeBank.TEmBTBnkCode) ON VS4TEmployee.TEmpCode=VS4TEmployeeBank.TEmBTEmpCode
GO

CREATE VIEW VS4VEmpBuddy
AS 
SELECT VS4TEmployee.*, VS4TEmpBuddy.*
FROM VS4TEmployee INNER JOIN VS4TEmpBuddy ON VS4TEmployee.TEmpCode=VS4TEmpBuddy.TEBuTEmpCode
GO

CREATE VIEW VS4VEmpChild
AS 
SELECT VS4TEmployee.*, VS4TEmpBuddy.*, VS4TEmpChild.*
FROM (VS4TEmployee INNER JOIN VS4TEmpBuddy ON VS4TEmployee.TEmpCode=VS4TEmpBuddy.TEBuTEmpCode) INNER JOIN VS4TEmpChild ON VS4TEmployee.TEmpCode=VS4TEmpChild.TEcdTEmpCode
GO

CREATE VIEW VS4VEmpCollateral
AS 
SELECT VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TEmpCollateral.*, VS4TEmployee.*, VS4TEmployeeType.*
FROM (((((VS4TEmployee LEFT JOIN VS4TBranch ON VS4TEmployee.TEmpTBraCode=VS4TBranch.TBraCode) LEFT JOIN VS4TDivision ON VS4TEmployee.TEmpTDivCode=VS4TDivision.TDivCode) LEFT JOIN VS4TDepartment ON VS4TEmployee.TEmpTDepCode=VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TEmployee.TEmpTSecCode=VS4TSection.TSecCode) LEFT JOIN VS4TEmployeeType ON VS4TEmployee.TEmpTEmTCode=VS4TEmployeeType.TEmTCode) INNER JOIN VS4TEmpCollateral ON VS4TEmployee.TEmpCode=VS4TEmpCollateral.TEclTEmpCode
GO

CREATE VIEW VS4VEmpContract
AS 
SELECT VS4TBranch.TBraName, VS4TDepartment.TDepName, VS4TDivision.TDivName, VS4TSection.TSecName, VS4TEmpContact.*, VS4TEmployee.*, VS4TEmployeeType.*, VS4TCountry.TCouName, VS4TPosition.TPstName
FROM (((((((VS4TEmployee LEFT JOIN VS4TBranch ON VS4TEmployee.TEmpTBraCode=VS4TBranch.TBraCode) LEFT JOIN VS4TDepartment ON VS4TEmployee.TEmpTDepCode=VS4TDepartment.TDepCode) LEFT JOIN VS4TDivision ON VS4TEmployee.TEmpTDivCode=VS4TDivision.TDivCode) LEFT JOIN VS4TSection ON VS4TEmployee.TEmpTSecCode=VS4TSection.TSecCode) LEFT JOIN VS4TEmployeeType ON VS4TEmployee.TEmpTEmTCode=VS4TEmployeeType.TEmTCode) LEFT JOIN VS4TCountry ON VS4TEmployee.TEmpTCouCode=VS4TCountry.TCouCode) LEFT JOIN VS4TPosition ON VS4TEmployee.TEmpTPstCode=VS4TPosition.TPstCode) INNER JOIN VS4TEmpContact ON VS4TEmployee.TEmpCode=VS4TEmpContact.TCttTEmpCode
GO

CREATE VIEW VS4VEmpHisEdu
AS 
SELECT VS4TEmployee.*, VS4TEmpHisEdu.*, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TPosition.TPstName, VS4TEmployeeType.*, VS4TCountry.TCouName
FROM VS4TPosition RIGHT JOIN (((((((VS4TEmployee LEFT JOIN VS4TSection ON VS4TEmployee.TEmpTSecCode=VS4TSection.TSecCode) LEFT JOIN VS4TDepartment ON VS4TEmployee.TEmpTDepCode=VS4TDepartment.TDepCode) LEFT JOIN VS4TDivision ON VS4TEmployee.TEmpTDivCode=VS4TDivision.TDivCode) LEFT JOIN VS4TBranch ON VS4TEmployee.TEmpTBraCode=VS4TBranch.TBraCode) LEFT JOIN VS4TEmployeeType ON VS4TEmployee.TEmpTEmTCode=VS4TEmployeeType.TEmTCode) LEFT JOIN VS4TCountry ON VS4TEmployee.TEmpTCouCode=VS4TCountry.TCouCode) INNER JOIN VS4TEmpHisEdu ON VS4TEmployee.TEmpCode=VS4TEmpHisEdu.THedTEmpCode) ON VS4TPosition.TPstCode=VS4TEmployee.TEmpTPstCode
GO

CREATE VIEW VS4VEmpHisPosition
AS 
SELECT VS4TEmpHisPosition.*, VS4TPosition.*, VS4TEmployee.*, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TEmployeeType.*, VS4TCountry.TCouName
FROM ((((VS4TPosition LEFT JOIN VS4TBranch ON VS4TPosition.TPstTBraCode=VS4TBranch.TBraCode) LEFT JOIN VS4TDivision ON VS4TPosition.TPstTDivCode=VS4TDivision.TDivCode) LEFT JOIN VS4TDepartment ON VS4TPosition.TPstTDepCode=VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TPosition.TPstTSecCode=VS4TSection.TSecCode) INNER JOIN (((VS4TEmpHisPosition INNER JOIN VS4TEmployee ON VS4TEmpHisPosition.TEHPTEmpCode=VS4TEmployee.TEmpCode) LEFT JOIN VS4TEmployeeType ON VS4TEmployee.TEmpTEmTCode=VS4TEmployeeType.TEmTCode) LEFT JOIN VS4TCountry ON VS4TEmployee.TEmpTCouCode=VS4TCountry.TCouCode) ON VS4TPosition.TPstCode=VS4TEmployee.TEmpTPstCode
GO

CREATE VIEW VS4VEmpHisProduce
AS 
SELECT VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TEmpHisProduce.*, VS4TEmployee.*, VS4TEmployeeType.*, VS4TCountry.TCouName, VS4TPosition.TPstName
FROM (((((((VS4TEmployee LEFT JOIN VS4TBranch ON VS4TEmployee.TEmpTBraCode=VS4TBranch.TBraCode) LEFT JOIN VS4TDivision ON VS4TEmployee.TEmpTDivCode=VS4TDivision.TDivCode) LEFT JOIN VS4TDepartment ON VS4TEmployee.TEmpTDepCode=VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TEmployee.TEmpTSecCode=VS4TSection.TSecCode) LEFT JOIN VS4TEmployeeType ON VS4TEmployee.TEmpTEmTCode=VS4TEmployeeType.TEmTCode) LEFT JOIN VS4TCountry ON VS4TEmployee.TEmpTCouCode=VS4TCountry.TCouCode) LEFT JOIN VS4TPosition ON VS4TEmployee.TEmpTPstCode=VS4TPosition.TPstCode) INNER JOIN VS4TEmpHisProduce ON VS4TEmployee.TEmpCode=VS4TEmpHisProduce.TEHSTEmpCode
GO

CREATE VIEW VS4VEmpHisPunish
AS 
SELECT VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TEmpHisPunish.*, VS4TEmployee.*, VS4TEmployeeType.*, VS4TCountry.TCouName, VS4TPosition.TPstName
FROM (((((((VS4TEmployee LEFT JOIN VS4TBranch ON VS4TEmployee.TEmpTBraCode=VS4TBranch.TBraCode) LEFT JOIN VS4TDivision ON VS4TEmployee.TEmpTDivCode=VS4TDivision.TDivCode) LEFT JOIN VS4TDepartment ON VS4TEmployee.TEmpTDepCode=VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TEmployee.TEmpTSecCode=VS4TSection.TSecCode) LEFT JOIN VS4TEmployeeType ON VS4TEmployee.TEmpTEmTCode=VS4TEmployeeType.TEmTCode) LEFT JOIN VS4TCountry ON VS4TEmployee.TEmpTCouCode=VS4TCountry.TCouCode) LEFT JOIN VS4TPosition ON VS4TEmployee.TEmpTPstCode=VS4TPosition.TPstCode) INNER JOIN VS4TEmpHisPunish ON VS4TEmployee.TEmpCode=VS4TEmpHisPunish.TEHUTEmpCode
GO

CREATE VIEW VS4VEmpHolidayA
AS 
SELECT VS4TEmpHoliday.TEhdYear, VS4TEmpHoliday.TEhdHolidayName, Count(VS4TEmpHoliday.TEhdYear) AS VEhdGroupDay
FROM VS4TEmpHoliday
GROUP BY VS4TEmpHoliday.TEhdYear, VS4TEmpHoliday.TEhdHolidayName
GO

CREATE VIEW VS4VEmpHoliday
AS 
SELECT VS4TEmpHoliday.*, VS4VEmpHolidayA.VEhdGroupDay
FROM VS4TEmpHoliday LEFT JOIN VS4VEmpHolidayA ON (VS4TEmpHoliday.TEhdYear=VS4VEmpHolidayA.TEhdYear) AND (VS4TEmpHoliday.TEhdHolidayName=VS4VEmpHolidayA.TEhdHolidayName)
GO

CREATE VIEW VS4VEmpIncome
AS 
SELECT VS4TEmpIncomeDoc.*, VS4TEmpIncomeMB.*, VS4TEmployee.*, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TEmployeeType.TEmTName
FROM (VS4TEmployeeType RIGHT JOIN ((((VS4TEmployee LEFT JOIN VS4TDepartment ON VS4TEmployee.TEmpTDepCode=VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TEmployee.TEmpTSecCode=VS4TSection.TSecCode) LEFT JOIN VS4TDivision ON VS4TEmployee.TEmpTDivCode=VS4TDivision.TDivCode) LEFT JOIN VS4TBranch ON VS4TEmployee.TEmpTBraCode=VS4TBranch.TBraCode) ON VS4TEmployeeType.TEmTCode=VS4TEmployee.TEmpTEmTCode) INNER JOIN (VS4TEmpIncomeDoc INNER JOIN VS4TEmpIncomeMB ON VS4TEmpIncomeDoc.TEidNo=VS4TEmpIncomeMB.TEwoTEidNo) ON VS4TEmployee.TEmpCode=VS4TEmpIncomeMB.TEwoTEmpCode
GO

CREATE VIEW VS4VEmpLeave
AS 
SELECT VS4TEmpLeave.*, VS4TEmpLeaveMB.*, VS4TEmpLeaveType.*, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TEmployee.*, VS4TEmployeeType.TEmTName
FROM VS4TEmployeeType RIGHT JOIN (VS4TEmpLeaveType INNER JOIN (VS4TEmpLeave INNER JOIN (VS4TEmpLeaveMB LEFT JOIN ((((VS4TEmployee LEFT JOIN VS4TBranch ON VS4TEmployee.TEmpTBraCode=VS4TBranch.TBraCode) LEFT JOIN VS4TDivision ON VS4TEmployee.TEmpTDivCode=VS4TDivision.TDivCode) LEFT JOIN VS4TDepartment ON VS4TEmployee.TEmpTDepCode=VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TEmployee.TEmpTSecCode=VS4TSection.TSecCode) ON VS4TEmpLeaveMB.TElbTEmpCode=VS4TEmployee.TEmpCode) ON VS4TEmpLeave.TEpaNo=VS4TEmpLeaveMB.TElbTEpaNo) ON VS4TEmpLeaveType.TLvtCode=VS4TEmpLeaveMB.TElbTLvtCode) ON VS4TEmployeeType.TEmTCode=VS4TEmployee.TEmpTEmTCode
GO

CREATE VIEW VS4VEmpLeaveAvail
AS 
SELECT VS4TEmpLeaveAllow.TELATEmpCode, VS4TEmpLeaveAllow.TELAYear, Sum(VS4TEmpLeaveAllow.TELATotal1) AS TELATotal1, Sum(VS4TEmpLeaveAllow.TELATime1) AS TELATime1, Sum(VS4TEmpLeaveAllow.TELATotal2) AS TELATotal2, Sum(VS4TEmpLeaveAllow.TELATime2) AS TELATime2, Sum(VS4TEmpLeaveAllow.TELATotal3) AS TELATotal3, Sum(VS4TEmpLeaveAllow.TELATime3) AS TELATime3, Sum(VS4TEmpLeaveAllow.TELATotal4) AS TELATotal4, Sum(VS4TEmpLeaveAllow.TELATime4) AS TELATime4, Sum(VS4TEmpLeaveAllow.TELATotal5) AS TELATotal5, Sum(VS4TEmpLeaveAllow.TELATime5) AS TELATime5, Sum(VS4TEmpLeaveAllow.TELATotal6) AS TELATotal6, Sum(VS4TEmpLeaveAllow.TELATime6) AS TELATime6, Sum(VS4TEmpLeaveAllow.TELATotal7) AS TELATotal7, Sum(VS4TEmpLeaveAllow.TELATime7) AS TELATime7, Sum(VS4TEmpLeaveAllow.TELATotal8) AS TELATotal8, Sum(VS4TEmpLeaveAllow.TELATime8) AS TELATime8, Sum(VS4TEmpLeaveAllow.TELATotal9) AS TELATotal9, Sum(VS4TEmpLeaveAllow.TELATime9) AS TELATime9, Sum(VS4TEmpLeaveAllow.TELATotal10) AS TELATotal10, Sum(VS4TEmpLeaveAllow.TELATime10) AS TELATime10, Sum(VS4TEmpLeaveAllow.TELATotal11) AS TELATotal11, Sum(VS4TEmpLeaveAllow.TELATime11) AS TELATime11, Sum(VS4TEmpLeaveAllow.TELATotal12) AS TELATotal12, Sum(VS4TEmpLeaveAllow.TELATime12) AS TELATime12, Sum(VS4TEmpLeaveAllow.TELATotal13) AS TELATotal13, Sum(VS4TEmpLeaveAllow.TELATime13) AS TELATime13, Sum(VS4TEmpLeaveAllow.TELATotal14) AS TELATotal14, Sum(VS4TEmpLeaveAllow.TELATime14) AS TELATime14, Sum(VS4TEmpLeaveAllow.TELATotal15) AS TELATotal15, Sum(VS4TEmpLeaveAllow.TELATime15) AS TELATime15, VS4TEmployee.TEmpFullName, VS4TEmployee.TEmpTBraCode, VS4TBranch.TBraName, VS4TEmployee.TEmpTEmTCode, VS4TEmployeeType.TEmTName, VS4TEmployee.TEmpTDivCode, VS4TDivision.TDivName, VS4TEmployee.TEmpTDepCode, VS4TDepartment.TDepName, VS4TEmployee.TEmpTSecCode, VS4TSection.TSecName, VS4TEmployee.TEmpStatus, VS4TEmployee.TEmpType
FROM (VS4TEmployeeType RIGHT JOIN (VS4TDivision RIGHT JOIN (VS4TBranch RIGHT JOIN ((VS4TEmployee LEFT JOIN VS4TDepartment ON VS4TEmployee.TEmpTDepCode=VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TEmployee.TEmpTSecCode=VS4TSection.TSecCode) ON VS4TBranch.TBraCode=VS4TEmployee.TEmpTBraCode) ON VS4TDivision.TDivCode=VS4TEmployee.TEmpTDivCode) ON VS4TEmployeeType.TEmTCode=VS4TEmployee.TEmpTEmTCode) INNER JOIN VS4TEmpLeaveAllow ON VS4TEmployee.TEmpCode=VS4TEmpLeaveAllow.TELATEmpCode
GROUP BY VS4TEmpLeaveAllow.TELATEmpCode, VS4TEmpLeaveAllow.TELAYear, VS4TEmployee.TEmpFullName, VS4TEmployee.TEmpTBraCode, VS4TBranch.TBraName, VS4TEmployee.TEmpTEmTCode, VS4TEmployeeType.TEmTName, VS4TEmployee.TEmpTDivCode, VS4TDivision.TDivName, VS4TEmployee.TEmpTDepCode, VS4TDepartment.TDepName, VS4TEmployee.TEmpTSecCode, VS4TSection.TSecName, VS4TEmployee.TEmpStatus, VS4TEmployee.TEmpType
GO

CREATE VIEW VS4VEmpLeaveTran
AS 
SELECT *
FROM VS4TEmpLeaveAllow
WHERE (((VS4TEmpLeaveAllow.TELAType)<>2))
GO

CREATE VIEW VS4VEmpLeaveUsed
AS 
SELECT VS4VEmpLeaveTran.TELATEmpCode AS TELATEmpCode, Sum(VS4VEmpLeaveTran.TELATotal1) AS TELATotal1, Sum(VS4VEmpLeaveTran.TELATime1) AS TELATime1, Sum(VS4VEmpLeaveTran.TELATotal2) AS TELATotal2, Sum(VS4VEmpLeaveTran.TELATime2) AS TELATime2, Sum(VS4VEmpLeaveTran.TELATotal3) AS TELATotal3, Sum(VS4VEmpLeaveTran.TELATime3) AS TELATime3, Sum(VS4VEmpLeaveTran.TELATotal4) AS TELATotal4, Sum(VS4VEmpLeaveTran.TELATime4) AS TELATime4, Sum(VS4VEmpLeaveTran.TELATotal5) AS TELATotal5, Sum(VS4VEmpLeaveTran.TELATime5) AS TELATime5, Sum(VS4VEmpLeaveTran.TELATotal6) AS TELATotal6, Sum(VS4VEmpLeaveTran.TELATime6) AS TELATime6, Sum(VS4VEmpLeaveTran.TELATotal7) AS TELATotal7, Sum(VS4VEmpLeaveTran.TELATime7) AS TELATime7, Sum(VS4VEmpLeaveTran.TELATotal8) AS TELATotal8, Sum(VS4VEmpLeaveTran.TELATime8) AS TELATime8, Sum(VS4VEmpLeaveTran.TELATotal9) AS TELATotal9, Sum(VS4VEmpLeaveTran.TELATime9) AS TELATime9, Sum(VS4VEmpLeaveTran.TELATotal10) AS TELATotal10, Sum(VS4VEmpLeaveTran.TELATime10) AS TELATime10, Sum(VS4VEmpLeaveTran.TELATotal11) AS TELATotal11, Sum(VS4VEmpLeaveTran.TELATime11) AS TELATime11, Sum(VS4VEmpLeaveTran.TELATotal12) AS TELATotal12, Sum(VS4VEmpLeaveTran.TELATime12) AS TELATime12, Sum(VS4VEmpLeaveTran.TELATotal13) AS TELATotal13, Sum(VS4VEmpLeaveTran.TELATime13) AS TELATime13, Sum(VS4VEmpLeaveTran.TELATotal14) AS TELATotal14, Sum(VS4VEmpLeaveTran.TELATime14) AS TELATime14, Sum(VS4VEmpLeaveTran.TELATotal15) AS TELATotal15, Sum(VS4VEmpLeaveTran.TELATime15) AS TELATime15, VS4TEmployee.TEmpFullName, VS4TEmployee.TEmpTEmTCode, VS4TEmployeeType.TEmTName, VS4TEmployee.TEmpTBraCode, VS4TBranch.TBraName, VS4TEmployee.TEmpTDivCode, VS4TDivision.TDivName, VS4TEmployee.TEmpTDepCode, VS4TDepartment.TDepName, VS4TEmployee.TEmpTSecCode, VS4TSection.TSecName, VS4TEmployee.TEmpType, VS4TEmployee.TEmpStatus, VS4VEmpLeaveTran.TELAYear AS TELAYear
FROM VS4TEmployeeType RIGHT JOIN (VS4TDivision RIGHT JOIN (VS4TBranch RIGHT JOIN (((VS4TEmployee INNER JOIN VS4VEmpLeaveTran ON VS4TEmployee.TEmpCode=VS4VEmpLeaveTran.TELATEmpCode) LEFT JOIN VS4TDepartment ON VS4TEmployee.TEmpTDepCode=VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TEmployee.TEmpTSecCode=VS4TSection.TSecCode) ON VS4TBranch.TBraCode=VS4TEmployee.TEmpTBraCode) ON VS4TDivision.TDivCode=VS4TEmployee.TEmpTDivCode) ON VS4TEmployeeType.TEmTCode=VS4TEmployee.TEmpTEmTCode
GROUP BY VS4VEmpLeaveTran.TELATEmpCode, VS4TEmployee.TEmpFullName, VS4TEmployee.TEmpTEmTCode, VS4TEmployeeType.TEmTName, VS4TEmployee.TEmpTBraCode, VS4TBranch.TBraName, VS4TEmployee.TEmpTDivCode, VS4TDivision.TDivName, VS4TEmployee.TEmpTDepCode, VS4TDepartment.TDepName, VS4TEmployee.TEmpTSecCode, VS4TSection.TSecName, VS4TEmployee.TEmpType, VS4TEmployee.TEmpStatus, VS4VEmpLeaveTran.TELAYear
GO

CREATE VIEW VS4VEmployee
AS 
SELECT VS4TEmployee.*, VS4TEmployeeType.*, VS4TCountry.TCouName, VS4TDepartment.TDepCode, VS4TDepartment.TDepName, VS4TDepartment.TDepName2, VS4TDepartment.TDepDocCode, VS4TSection.TSecCode, VS4TSection.TSecName, VS4TSection.TSecName2, VS4TSection.TSecDocCode, VS4TEmployee2.TEm2LastCompany, VS4TEmployee2.TEm2PassportFrom, VS4TEmployee2.TEm2PassportTo, VS4TEmployee2.TEm2WorkPermitFrom, VS4TEmployee2.TEm2WorkPermitTo, VS4TEmployee2.TEm2CitizenFrom, VS4TEmployee2.TEm2CitizenTo, VS4TDivision.TDivCode, VS4TDivision.TDivName, VS4TDivision.TDivName2, VS4TEmployee2.TEm2SkipTax, VS4TEmployee2.TEm2SkipSlip, VS4TEmpWorkPeriod.TWPDName, VS4TEmpWorkPeriod.TWPDDescription, VS4TPosition.TPstCode, VS4TPosition.TPstTPsYAlias, VS4TPosition.TPstName, VS4TPosition.TPstName2, VS4TPosition.TPstStructureLevel, VS4TBranch.TBraCode, VS4TBranch.TBraName, VS4TBranch.TBraName2, VS4TBranch.TBraDocCode, VS4TBranch.TBraTBrTAlias, VS4TBranch.TBraTaxMode, VS4TBranch.TBraTaxNo, VS4TBranch.TBraAddressBill, VS4TBranch.TBraSocialNo, VS4TBranch.TBraSocialArea, VS4TBranch.TBraTCurCode, VS4TBranch.TBraTCmpCode, VS4TBranch.TBraNo, VS4TBranch.TBraAddress, VS4TBranch.TBraSubProvince, VS4TBranch.TBraCity, VS4TBranch.TBraPostalCode, VS4TBranch.TBraStaCode, VS4TBranch.TBraTCouCode, VS4TBranch.TBraWebsite, VS4TBranch.TBraEmail, VS4TBranch.TBraPhone, VS4TBranch.TBraFax, VS4TBranch.TBraMap1, VS4TBranch.TBraMap2, VS4TBranch.TBraImage1, VS4TBranch.TBraIcon1, VS4TBranch.TBraNote, VS4TEmployee2.TEm2HasSSOBefore
FROM VS4TPosition RIGHT JOIN (VS4TEmpWorkPeriod INNER JOIN ((VS4TEmployeeType INNER JOIN (VS4TDivision RIGHT JOIN (VS4TBranch RIGHT JOIN (VS4TCountry RIGHT JOIN (((VS4TEmployee LEFT JOIN VS4TSection ON VS4TEmployee.TEmpTSecCode = VS4TSection.TSecCode) LEFT JOIN VS4TDepartment ON VS4TEmployee.TEmpTDepCode = VS4TDepartment.TDepCode) LEFT JOIN VS4TState ON VS4TEmployee.TEmpTStaCode = VS4TState.TStaCode) ON VS4TCountry.TCouCode = VS4TEmployee.TEmpTCouCode) ON VS4TBranch.TBraCode = VS4TEmployee.TEmpTBraCode) ON VS4TDivision.TDivCode = VS4TEmployee.TEmpTDivCode) ON VS4TEmployeeType.TEmTCode = VS4TEmployee.TEmpTEmTCode) LEFT JOIN VS4TEmployee2 ON VS4TEmployee.TEmpCode = VS4TEmployee2.TEm2TEmpCode) ON VS4TEmpWorkPeriod.TWPDCode = VS4TEmployee.TEmpTWPDCode) ON VS4TPosition.TPstCode = VS4TEmployee.TEmpTPstCode
GO

CREATE VIEW VS4VEmployee2
AS 
SELECT VS4TEmployee.*, VS4TEmployee2.*, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TPosition.TPstName, VS4TPosition.TPstName2, VS4TPosition.TPstTPsYAlias
FROM VS4TPosition RIGHT JOIN ((VS4TDivision RIGHT JOIN (VS4TBranch RIGHT JOIN ((VS4TEmployee LEFT JOIN VS4TSection ON VS4TEmployee.TEmpTSecCode = VS4TSection.TSecCode) LEFT JOIN VS4TDepartment ON VS4TEmployee.TEmpTDepCode = VS4TDepartment.TDepCode) ON VS4TBranch.TBraCode = VS4TEmployee.TEmpTBraCode) ON VS4TDivision.TDivCode = VS4TEmployee.TEmpTDivCode) LEFT JOIN VS4TEmployee2 ON VS4TEmployee.TEmpCode = VS4TEmployee2.TEm2TEmpCode) ON VS4TPosition.TPstCode = VS4TEmployee.TEmpTPstCode
GO

CREATE VIEW VS4VEmployeeGroup
AS 
SELECT VS4TEmployeeGroup.*, VS4TEmployeeGrpMB.*, VS4TEmployee.*, VS4TPositionGroup.*, VS4TEmpGroupDoc.*, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName
FROM VS4TPositionGroup INNER JOIN (VS4TEmployeeGroup INNER JOIN (((((VS4TEmpGroupDoc LEFT JOIN VS4TBranch ON VS4TEmpGroupDoc.TEgdTBraCode=VS4TBranch.TBraCode) LEFT JOIN VS4TDivision ON VS4TEmpGroupDoc.TEgdTDivCode=VS4TDivision.TDivCode) LEFT JOIN VS4TDepartment ON VS4TEmpGroupDoc.TEgdTDepCode=VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TEmpGroupDoc.TEgdTSecCode=VS4TSection.TSecCode) INNER JOIN (VS4TEmployee INNER JOIN VS4TEmployeeGrpMB ON VS4TEmployee.TEmpCode=VS4TEmployeeGrpMB.TEGMTEmpCode) ON VS4TEmpGroupDoc.TEgdNo=VS4TEmployeeGrpMB.TEGMTEgdNo) ON VS4TEmployeeGroup.TEmGCode=VS4TEmployeeGrpMB.TEGMTEmGCode) ON VS4TPositionGroup.TPgpCode=VS4TEmployeeGrpMB.TEGMTPgpCode
GO

CREATE VIEW VS4VEmployeeSlip
AS 
SELECT VS4TEmpSlipDoc.*, VS4TEmpSlipMB.*, VS4TEmployee.*, VS4TEmployeeType.TEmTName, VS4TEmployeeType.TEmTCalculateType, VS4TEmployeeType.TEmTSalaryType, VS4TDivision.TDivName, VS4TDivision.TDivName2, VS4TDivision.TDivLevel, VS4TDepartment.TDepName, VS4TDepartment.TDepName2, VS4TSection.TSecName, VS4TSection.TSecName2, VS4TEmpAddMoney.TAmyName2
FROM ((VS4TEmployeeType RIGHT JOIN (VS4TDivision RIGHT JOIN ((VS4TEmployee LEFT JOIN VS4TDepartment ON VS4TEmployee.TEmpTDepCode = VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TEmployee.TEmpTSecCode = VS4TSection.TSecCode) ON VS4TDivision.TDivCode = VS4TEmployee.TEmpTDivCode) ON VS4TEmployeeType.TEmTCode = VS4TEmployee.TEmpTEmTCode) RIGHT JOIN VS4TEmpSlipDoc ON VS4TEmployee.TEmpCode = VS4TEmpSlipDoc.TEpsTEmpCode) INNER JOIN (VS4TEmpAddMoney RIGHT JOIN VS4TEmpSlipMB ON VS4TEmpAddMoney.TAmyCode = VS4TEmpSlipMB.TSmbTAmyCode) ON (VS4TEmpSlipDoc.TEpsCheckGroup = VS4TEmpSlipMB.TSmbTEpsCheckGroup) AND (VS4TEmpSlipDoc.TEpsNo = VS4TEmpSlipMB.TSmbTEpsNo)
GO

CREATE VIEW VS4VEmployeeSlipH
AS 
SELECT VS4TEmpSlipDoc.*, VS4TEmployee.*, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TEmployeeType.TEmTCode, VS4TEmployeeType.TEmTName, VS4TEmployeeType.TEmTCalculateType, VS4TEmployeeType.TEmTSalaryType
FROM (VS4TEmployeeType RIGHT JOIN ((((VS4TEmployee LEFT JOIN VS4TBranch ON VS4TEmployee.TEmpTBraCode=VS4TBranch.TBraCode) LEFT JOIN VS4TDivision ON VS4TEmployee.TEmpTDivCode=VS4TDivision.TDivCode) LEFT JOIN VS4TDepartment ON VS4TEmployee.TEmpTDepCode=VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TEmployee.TEmpTSecCode=VS4TSection.TSecCode) ON VS4TEmployeeType.TEmTCode=VS4TEmployee.TEmpTEmTCode) RIGHT JOIN VS4TEmpSlipDoc ON VS4TEmployee.TEmpCode=VS4TEmpSlipDoc.TEpsTEmpCode
GO

CREATE VIEW VS4VEmployeeTypeSL
AS 
SELECT VS4TEmployeeTypeSL.*, VS4TEmpAddMoney.*
FROM VS4TEmployeeTypeSL INNER JOIN VS4TEmpAddMoney ON VS4TEmployeeTypeSL.TGSlTAmyCode = VS4TEmpAddMoney.TAmyCode
GO

CREATE VIEW VS4VEmpOT
AS 
SELECT VS4TEmpOT.*, VS4TEmpOTMB.*, VS4TEmployee.*, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TEmployeeType.TEmTName
FROM VS4TEmployeeType RIGHT JOIN (VS4TDivision RIGHT JOIN (VS4TBranch RIGHT JOIN ((((VS4TEmployee INNER JOIN VS4TEmpOTMB ON VS4TEmployee.TEmpCode=VS4TEmpOTMB.TOTMTEmpCode) INNER JOIN VS4TEmpOT ON VS4TEmpOTMB.TOTMTEOTNo=VS4TEmpOT.TEOTNo) LEFT JOIN VS4TSection ON VS4TEmployee.TEmpTSecCode=VS4TSection.TSecCode) LEFT JOIN VS4TDepartment ON VS4TEmployee.TEmpTDepCode=VS4TDepartment.TDepCode) ON VS4TBranch.TBraCode=VS4TEmployee.TEmpTBraCode) ON VS4TDivision.TDivCode=VS4TEmployee.TEmpTDivCode) ON VS4TEmployeeType.TEmTCode=VS4TEmployee.TEmpTEmTCode
GO

CREATE VIEW VS4VEmpParent
AS 
SELECT VS4TEmployee.*, VS4TEmpParent.*
FROM VS4TEmployee INNER JOIN VS4TEmpParent ON VS4TEmployee.TEmpCode=VS4TEmpParent.TEpPTEmpCode
GO

CREATE VIEW VS4VEmpAmassLast
AS 
SELECT VS4VEmpAmass.*
FROM VS4VEmpPeriodLast INNER JOIN VS4VEmpAmass ON (VS4VEmpPeriodLast.TEpsTEmpCode = VS4VEmpAmass.TEpsTEmpCode) AND (VS4VEmpPeriodLast.TEpsCheckGroup = VS4VEmpAmass.TEpsCheckGroup) AND (VS4VEmpPeriodLast.TEpsTSAPTEmTCode = VS4VEmpAmass.TEpsTSAPTEmTCode) AND (VS4VEmpPeriodLast.TEpsTSaPDate = VS4VEmpAmass.TEpsTSaPDate) AND (VS4VEmpPeriodLast.TEpsBalanceFlag = VS4VEmpAmass.TEpsBalanceFlag)
GO

CREATE VIEW VS4VEmpRevenue
AS 
SELECT VS4TEmpAmassType.TEATTEmpCode, VS4TEmpAmassType.TEATCheckGroup, Count(VS4TEmpAmassType.TEATTEmTCode) AS VEPRTotalSlip, Sum(VS4TEmpAmassType.TEATAddTotal) AS TEATAddTotal, Sum(VS4TEmpAmassType.TEATCutTotal) AS TEATCutTotal, Sum(VS4TEmpAmassType.TEATAmassTotal) AS TEATAmassTotal, Sum(VS4TEmpAmassType.TEATAmassFundInt) AS TEATAmassFundInt, Sum(VS4TEmpAmassType.TEATNetTotal) AS TEATNetTotal, Sum(VS4TEmpAmassType.TEATAmassTotal) AS TEATAmassTotal1
FROM VS4TEmpAmassType
GROUP BY VS4TEmpAmassType.TEATTEmpCode, VS4TEmpAmassType.TEATCheckGroup
GO

CREATE VIEW VS4VEmpRevenue1A
AS 
SELECT VS4TTaxTrans.*, VS4VEmpAmassYear.*
FROM VS4TTaxTrans LEFT JOIN VS4VEmpAmassYear ON (VS4TTaxTrans.TTxTYear = VS4VEmpAmassYear.VEMAYear) AND (VS4TTaxTrans.TTxTClientCode = VS4VEmpAmassYear.TEpsTEmpCode)
WHERE (((VS4VEmpAmassYear.TEpsCheckGroup)=0))
GO

CREATE VIEW VS4VEmpRevenue91
AS 
SELECT VS4TEmployee.*, VS4TEmpRevenue91.*, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TEmpBuddy.*, VS4TEmpParent.*, VS4TEmployeeType.TEmTName
FROM ((VS4TEmployeeType RIGHT JOIN (((((VS4TEmployee INNER JOIN VS4TEmpRevenue91 ON VS4TEmployee.TEmpCode=VS4TEmpRevenue91.TER9TEmpCode) LEFT JOIN VS4TDivision ON VS4TEmployee.TEmpTDivCode=VS4TDivision.TDivCode) LEFT JOIN VS4TBranch ON VS4TEmployee.TEmpTBraCode=VS4TBranch.TBraCode) LEFT JOIN VS4TDepartment ON VS4TEmployee.TEmpTDepCode=VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TEmployee.TEmpTSecCode=VS4TSection.TSecCode) ON VS4TEmployeeType.TEmTCode=VS4TEmployee.TEmpTEmTCode) LEFT JOIN VS4TEmpBuddy ON VS4TEmployee.TEmpCode=VS4TEmpBuddy.TEBuTEmpCode) LEFT JOIN VS4TEmpParent ON VS4TEmployee.TEmpCode=VS4TEmpParent.TEpPTEmpCode
WHERE (((VS4TEmpParent.TEpPLn)=1))
GO

CREATE VIEW VS4VEmpSalary
AS 
SELECT VS4TEmployee.*, VS4TEmployeeType.*, VS4TEmpSalary.*, VS4TPosition.TPstName, VS4TSection.TSecName, VS4TDepartment.TDepName, VS4TBranch.TBraName, VS4TEmpAddMoney.*, VS4TDivision.TDivName, VS4TEmpWorkPeriod.TWPDName
FROM VS4TPosition INNER JOIN (VS4TEmpWorkPeriod INNER JOIN ((VS4TEmployeeType INNER JOIN (VS4TDivision RIGHT JOIN (VS4TBranch INNER JOIN ((VS4TEmployee LEFT JOIN VS4TDepartment ON VS4TEmployee.TEmpTDepCode = VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TEmployee.TEmpTSecCode = VS4TSection.TSecCode) ON VS4TBranch.TBraCode = VS4TEmployee.TEmpTBraCode) ON VS4TDivision.TDivCode = VS4TEmployee.TEmpTDivCode) ON VS4TEmployeeType.TEmTCode = VS4TEmployee.TEmpTEmTCode) INNER JOIN (VS4TEmpAddMoney INNER JOIN VS4TEmpSalary ON VS4TEmpAddMoney.TAmyCode = VS4TEmpSalary.TSalTAmyCode) ON VS4TEmployee.TEmpCode = VS4TEmpSalary.TSalTEmpCode) ON VS4TEmpWorkPeriod.TWPDCode = VS4TEmployee.TEmpTWPDCode) ON VS4TPosition.TPstCode = VS4TEmployee.TEmpTPstCode
GO

CREATE VIEW VS4VEmpSlipPeriod
AS 
SELECT VS4TEmpSlipPeriod.*, VS4TEmployeeType.*
FROM VS4TEmployeeType INNER JOIN VS4TEmpSlipPeriod ON VS4TEmployeeType.TEmTCode=VS4TEmpSlipPeriod.TSaPTEmTCode
GO

CREATE VIEW VS4VEmpSlipValid
AS 
SELECT Count(VS4TEmployee.TEmpCode) AS TotalValid, VS4TEmpAddMoney.TAmyTAMTAlias, VS4TEmployee.TEmpTEmTCode, VS4TEmployee.TEmpStatus
FROM VS4TEmployee INNER JOIN (VS4TEmpAddMoney INNER JOIN VS4TEmpSalary ON VS4TEmpAddMoney.TAmyCode = VS4TEmpSalary.TSalTAmyCode) ON VS4TEmployee.TEmpCode = VS4TEmpSalary.TSalTEmpCode
GROUP BY VS4TEmpAddMoney.TAmyTAMTAlias, VS4TEmployee.TEmpTEmTCode, VS4TEmployee.TEmpStatus
HAVING (((VS4TEmpAddMoney.TAmyTAMTAlias)='SALARY'))
GO

CREATE VIEW VS4VEmpSpecial
AS 
SELECT VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TEmpSpecial.*, VS4TEmployee.*, VS4TEmployeeType.*, VS4TCountry.TCouName, VS4TPosition.TPstName
FROM (((((((VS4TEmployee LEFT JOIN VS4TBranch ON VS4TEmployee.TEmpTBraCode=VS4TBranch.TBraCode) LEFT JOIN VS4TDivision ON VS4TEmployee.TEmpTDivCode=VS4TDivision.TDivCode) LEFT JOIN VS4TDepartment ON VS4TEmployee.TEmpTDepCode=VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TEmployee.TEmpTSecCode=VS4TSection.TSecCode) LEFT JOIN VS4TEmployeeType ON VS4TEmployee.TEmpTEmTCode=VS4TEmployeeType.TEmTCode) LEFT JOIN VS4TCountry ON VS4TEmployee.TEmpTCouCode=VS4TCountry.TCouCode) LEFT JOIN VS4TPosition ON VS4TEmployee.TEmpTPstCode=VS4TPosition.TPstCode) INNER JOIN VS4TEmpSpecial ON VS4TEmployee.TEmpCode=VS4TEmpSpecial.TSplTEmpCode
GO

CREATE VIEW VS4VEmpSumAmass
AS 
SELECT VS4TEmpSlipDoc.TEpsTEmpCode, VS4TEmpSlipMB.TSmbTAmyCode, Sum(VS4TEmpSlipMB.TSmbDebit) AS TSmbDebit, Sum(VS4TEmpSlipMB.TSmbCrebit) AS TSmbCrebit, Sum(VS4TEmpSlipMB.TSmbIncrease) AS TSmbIncrease, Sum(VS4TEmpSlipMB.TSmbDecrease) AS TSmbDecrease, VS4TEmpSlipDoc.TEpsCheckGroup AS TEpsCheckGroup, VS4TEmpSlipMB.TSmbCheckMoney, VS4TEmpSlipMB.TSmbCheckFix, VS4TEmpSlipMB.TSmbTAMTAlias, Sum(VS4TEmpSlipMB.TSmbIntLastAmass) AS TSmbIntLastAmass, Sum(VS4TEmpSlipMB.TSmbInterestAmass) AS TSmbInterestAmass
FROM VS4TEmpSlipDoc INNER JOIN VS4TEmpSlipMB ON (VS4TEmpSlipDoc.TEpsNo=VS4TEmpSlipMB.TSmbTEpsNo) AND (VS4TEmpSlipDoc.TEpsCheckGroup=VS4TEmpSlipMB.TSmbTEpsCheckGroup)
GROUP BY VS4TEmpSlipDoc.TEpsTEmpCode, VS4TEmpSlipMB.TSmbTAmyCode, VS4TEmpSlipDoc.TEpsCheckGroup, VS4TEmpSlipMB.TSmbCheckMoney, VS4TEmpSlipMB.TSmbCheckFix, VS4TEmpSlipMB.TSmbTAMTAlias, VS4TEmpSlipDoc.TEpsApproveStatus, VS4TEmpSlipDoc.TEpsCancelStatus
HAVING (((VS4TEmpSlipDoc.TEpsApproveStatus)=1) AND ((VS4TEmpSlipDoc.TEpsCancelStatus)=0))
GO

CREATE VIEW VS4VEmpTimeCheck
AS 
SELECT VS4TEmpTimeChk.*, VS4TEmpTimeChkMB.*, VS4TEmployee.*, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName
FROM ((VS4TDivision RIGHT JOIN (VS4TBranch RIGHT JOIN ((VS4TEmployee LEFT JOIN VS4TDepartment ON VS4TEmployee.TEmpTDepCode=VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TEmployee.TEmpTSecCode=VS4TSection.TSecCode) ON VS4TBranch.TBraCode=VS4TEmployee.TEmpTBraCode) ON VS4TDivision.TDivCode=VS4TEmployee.TEmpTDivCode) INNER JOIN VS4TEmpTimeChk ON VS4TEmployee.TEmpCode=VS4TEmpTimeChk.TEtcTEmpCode) INNER JOIN VS4TEmpTimeChkMB ON VS4TEmpTimeChk.TEtcNo=VS4TEmpTimeChkMB.TTCKTEtcNo
GO

CREATE VIEW VS4VEmpTimeCheckH
AS 
SELECT VS4TEmpTimeChk.*, VS4TEmployee.*, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TEmployeeType.TEmTName, VS4TEmployeeType.TEmTCalculateType, VS4TEmployeeType.TEmTSalaryType
FROM (VS4TEmployeeType INNER JOIN (VS4TDivision RIGHT JOIN (VS4TBranch RIGHT JOIN ((VS4TEmployee LEFT JOIN VS4TDepartment ON VS4TEmployee.TEmpTDepCode=VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TEmployee.TEmpTSecCode=VS4TSection.TSecCode) ON VS4TBranch.TBraCode=VS4TEmployee.TEmpTBraCode) ON VS4TDivision.TDivCode=VS4TEmployee.TEmpTDivCode) ON VS4TEmployeeType.TEmTCode=VS4TEmployee.TEmpTEmTCode) INNER JOIN VS4TEmpTimeChk ON VS4TEmployee.TEmpCode=VS4TEmpTimeChk.TEtcTEmpCode
GO

CREATE VIEW VS4VEmpTimeFill
AS 
SELECT VS4TEmpTimeFill.*, VS4TEmployee.*, VS4TBranch.TBraCode, VS4TBranch.TBraName, VS4TBranch.TBraName2, VS4TDivision.TDivCode, VS4TDivision.TDivName, VS4TDepartment.TDepCode, VS4TDepartment.TDepName, VS4TDepartment.TDepName2, VS4TSection.TSecCode, VS4TSection.TSecName, VS4TSection.TSecName2
FROM VS4TDivision RIGHT JOIN (VS4TBranch RIGHT JOIN (((VS4TEmployee LEFT JOIN VS4TSection ON VS4TEmployee.TEmpTSecCode = VS4TSection.TSecCode) LEFT JOIN VS4TDepartment ON VS4TEmployee.TEmpTDepCode = VS4TDepartment.TDepCode) INNER JOIN VS4TEmpTimeFill ON VS4TEmployee.TEmpCode = VS4TEmpTimeFill.TTGMTEmpCode) ON VS4TBranch.TBraCode = VS4TEmployee.TEmpTBraCode) ON VS4TDivision.TDivCode = VS4TEmployee.TEmpTDivCode
GO

CREATE VIEW VS4VEmpTimeInput
AS 
SELECT VS4TTimeInput.*, VS4TEmployee.*, VS4TEmployeeType.*, VS4TEmpWorkPeriod.*, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TSection.TSecName, VS4TDepartment.TDepName, VS4TTimeInputNote.TTINNote
FROM (VS4TEmpWorkPeriod RIGHT JOIN (VS4TEmployeeType INNER JOIN (VS4TDivision RIGHT JOIN (VS4TBranch RIGHT JOIN (((VS4TTimeInput INNER JOIN VS4TEmployee ON VS4TTimeInput.TTIPCode = VS4TEmployee.TEmpCode) LEFT JOIN VS4TDepartment ON VS4TEmployee.TEmpTDepCode = VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TEmployee.TEmpTSecCode = VS4TSection.TSecCode) ON VS4TBranch.TBraCode = VS4TEmployee.TEmpTBraCode) ON VS4TDivision.TDivCode = VS4TEmployee.TEmpTDivCode) ON VS4TEmployeeType.TEmTCode = VS4TEmployee.TEmpTEmTCode) ON VS4TEmpWorkPeriod.TWPDCode = VS4TEmployee.TEmpTWPDCode) LEFT JOIN VS4TTimeInputNote ON VS4TTimeInput.TTIPID = VS4TTimeInputNote.TTINTTIPID
GO

CREATE VIEW VS4VEmpTimeMiss
AS 
SELECT VS4TTimeInput.*, VS4TEmployee.*, VS4TEmployeeType.*, VS4TEmpWorkPeriod.*, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TSection.TSecName, VS4TDepartment.TDepName
FROM VS4TEmpWorkPeriod RIGHT JOIN (VS4TEmployeeType INNER JOIN (VS4TDivision RIGHT JOIN (VS4TBranch RIGHT JOIN (((VS4TTimeInput RIGHT JOIN VS4TEmployee ON VS4TTimeInput.TTIPCode=VS4TEmployee.TEmpCode) LEFT JOIN VS4TDepartment ON VS4TEmployee.TEmpTDepCode=VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TEmployee.TEmpTSecCode=VS4TSection.TSecCode) ON VS4TBranch.TBraCode=VS4TEmployee.TEmpTBraCode) ON VS4TDivision.TDivCode=VS4TEmployee.TEmpTDivCode) ON VS4TEmployeeType.TEmTCode=VS4TEmployee.TEmpTEmTCode) ON VS4TEmpWorkPeriod.TWPDCode=VS4TEmployee.TEmpTWPDCode
GO

CREATE VIEW VS4VEmpTraining
AS 
SELECT VS4TEmpTraining.*, VS4TEmpTrainingMB.*, VS4TTrainingCourse.*, VS4TTrainingGroup.*
FROM VS4TTrainingGroup INNER JOIN (VS4TTrainingCourse INNER JOIN (VS4TEmpTraining INNER JOIN VS4TEmpTrainingMB ON VS4TEmpTraining.TETrNo=VS4TEmpTrainingMB.TETmTETrNo) ON VS4TTrainingCourse.TTrCCode=VS4TEmpTrainingMB.TETmTTrCCode) ON VS4TTrainingGroup.TTrGCode=VS4TTrainingCourse.TTrCTTrGCode
GO

CREATE VIEW VS4VEmpUpSalary
AS 
SELECT VS4TEmpUpSalary.*, VS4TEmpUpSalaryMB.*, VS4TEmployee.*, VS4TEmployeeType.TEmTName, VS4TBranch.TBraName, VS4TBranch.TBraName2, VS4TDivision.TDivName, VS4TDivision.TDivName2, VS4TDepartment.TDepName, VS4TDepartment.TDepName2, VS4TSection.TSecName, VS4TSection.TSecName2, VS4TPosition.TPstName, VS4TPosition.TPstName2, VS4TEmployeeType_1.TEmTName AS VEUMNewTEmTName, VS4TPosition_1.TPstName AS VEUMNewTPstName, VS4TPosition_1.TPstName2 AS VEUMNewTPstName2, VS4TBranch_1.TBraName AS VEUMNewTBraName, VS4TBranch_1.TBraName2 AS VEUMNewTBraName2, VS4TDivision_1.TDivName AS VEUMNewTDivName, VS4TDivision_1.TDivName2 AS VEUMNewTDivName2, VS4TDepartment_1.TDepName AS VEUMNewTDepName, VS4TDepartment_1.TDepName2 AS VEUMNewTDepName2, VS4TSection_1.TSecName AS VEUMNewTSecName, VS4TSection_1.TSecName2 AS VEUMNewTSecName2
FROM VS4TEmpUpSalary INNER JOIN (((((((((((((VS4TEmpUpSalaryMB INNER JOIN VS4TEmployee ON VS4TEmpUpSalaryMB.TEUMTEmpCode=VS4TEmployee.TEmpCode) LEFT JOIN VS4TEmployeeType ON VS4TEmpUpSalaryMB.TEUMTEmTCode=VS4TEmployeeType.TEmTCode) LEFT JOIN VS4TBranch ON VS4TEmpUpSalaryMB.TEUMTBraCode=VS4TBranch.TBraCode) LEFT JOIN VS4TPosition ON VS4TEmpUpSalaryMB.TEUMTPstCode=VS4TPosition.TPstCode) LEFT JOIN VS4TDivision ON VS4TEmpUpSalaryMB.TEUMTDivCode=VS4TDivision.TDivCode) LEFT JOIN VS4TDepartment ON VS4TEmpUpSalaryMB.TEUMTDepCode=VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TEmpUpSalaryMB.TEUMTSecCode=VS4TSection.TSecCode) LEFT JOIN VS4TEmployeeType AS VS4TEmployeeType_1 ON VS4TEmpUpSalaryMB.TEUMNewTEmTCode=VS4TEmployeeType_1.TEmTCode) LEFT JOIN VS4TBranch AS VS4TBranch_1 ON VS4TEmpUpSalaryMB.TEUMNewTBraCode=VS4TBranch_1.TBraCode) LEFT JOIN VS4TPosition AS VS4TPosition_1 ON VS4TEmpUpSalaryMB.TEUMNewTPstCode=VS4TPosition_1.TPstCode) LEFT JOIN VS4TDivision AS VS4TDivision_1 ON VS4TEmpUpSalaryMB.TEUMNewTDivCode=VS4TDivision_1.TDivCode) LEFT JOIN VS4TDepartment AS VS4TDepartment_1 ON VS4TEmpUpSalaryMB.TEUMNewTDepCode=VS4TDepartment_1.TDepCode) LEFT JOIN VS4TSection AS VS4TSection_1 ON VS4TEmpUpSalaryMB.TEUMNewTSecCode=VS4TSection_1.TSecCode) ON VS4TEmpUpSalary.TEUSNo=VS4TEmpUpSalaryMB.TEUMTEUSNo
GO

CREATE VIEW VS4VEmpWorkCount
AS 
SELECT VS4TEmpWorkCount.*, VS4TEmpWorkCountMB.*, VS4TEmployee.*, VS4TPosition.TPstName, VS4TPosition.TPstName2, VS4TMRPStepName.TSepName, VS4TEmpWorkRate.*, VS4TJob.TJobCode, VS4TEmployeeType.TEmTCalculateType, VS4TEmployeeType.TEmTSalaryType, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TJobProductionM.TJPMTPdtCode, VS4TProduct_1.TPdtName, VS4TProduct.TPdtName AS JProductName
FROM VS4TProduct RIGHT JOIN (VS4TPosition RIGHT JOIN (VS4TJob RIGHT JOIN (VS4TEmpWorkCount INNER JOIN ((VS4TEmployeeType INNER JOIN (((VS4TEmployee LEFT JOIN VS4TSection ON VS4TEmployee.TEmpTSecCode = VS4TSection.TSecCode) LEFT JOIN VS4TDepartment ON VS4TEmployee.TEmpTDepCode = VS4TDepartment.TDepCode) LEFT JOIN VS4TDivision ON VS4TEmployee.TEmpTDivCode = VS4TDivision.TDivCode) ON VS4TEmployeeType.TEmTCode = VS4TEmployee.TEmpTEmTCode) INNER JOIN (((((VS4TEmpWorkCountMB LEFT JOIN VS4TMRPStepName ON VS4TEmpWorkCountMB.TECMTSepCode = VS4TMRPStepName.TSepCode) LEFT JOIN VS4TEmpWorkRate ON VS4TEmpWorkCountMB.TECMTWRMCode = VS4TEmpWorkRate.TWRMCode) LEFT JOIN VS4TJobMB ON (VS4TEmpWorkCountMB.TECMTJbMTJobNo = VS4TJobMB.TJbMTJobNo) AND (VS4TEmpWorkCountMB.TECMTJbMLn = VS4TJobMB.TJbMLn)) LEFT JOIN VS4TJobProductionM ON (VS4TEmpWorkCountMB.TECMTJPdNo = VS4TJobProductionM.TJPMTJPdNo) AND (VS4TEmpWorkCountMB.TECMTSpdStep = VS4TJobProductionM.TJPMLn)) LEFT JOIN VS4TProduct AS VS4TProduct_1 ON VS4TJobProductionM.TJPMTPdtCode = VS4TProduct_1.TPdtCode) ON VS4TEmployee.TEmpCode = VS4TEmpWorkCountMB.TECMTEmpCode) ON VS4TEmpWorkCount.TEWCNo = VS4TEmpWorkCountMB.TECMTEWCNo) ON VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo) ON VS4TPosition.TPstCode = VS4TEmployee.TEmpTPstCode) ON VS4TProduct.TPdtCode = VS4TJobMB.TJbMTPdtCode
GO

CREATE VIEW VS4VEmpWorkSum
AS 
SELECT VS4TEmpWorkCountMB.TECMTEmpCode, VS4TEmpWorkCount.TEWCTBraCode, Sum(VS4TEmpWorkCountMB.TECMQuantity) AS TECMQuantity, Sum(VS4TEmpWorkCountMB.TECMTotal) AS TECMTotal
FROM VS4TEmpWorkCount INNER JOIN (VS4TEmployee INNER JOIN VS4TEmpWorkCountMB ON VS4TEmployee.TEmpCode = VS4TEmpWorkCountMB.TECMTEmpCode) ON VS4TEmpWorkCount.TEWCNo = VS4TEmpWorkCountMB.TECMTEWCNo
GROUP BY VS4TEmpWorkCountMB.TECMTEmpCode, VS4TEmpWorkCount.TEWCTBraCode, VS4TEmpWorkCount.TEWCApproveStatus, VS4TEmpWorkCount.TEWCCancelStatus
HAVING (((VS4TEmpWorkCount.TEWCApproveStatus)=1) AND ((VS4TEmpWorkCount.TEWCCancelStatus)=0))
GO

CREATE VIEW VS4VExchangeRate
AS 
SELECT VS4TExchange.*, VS4TExchangeRate.*, VS4TCurrency.*, VS4TBank.*
FROM VS4TExchange INNER JOIN (VS4TCurrency INNER JOIN (VS4TBank INNER JOIN VS4TExchangeRate ON VS4TBank.TBnkCode=VS4TExchangeRate.TExRTBnkCode) ON VS4TCurrency.TCurCode=VS4TExchangeRate.TExRTCurCode) ON VS4TExchange.TExcNo=VS4TExchangeRate.TExRTExcNo
GO

CREATE VIEW VS4VExportSlipBank
AS 
SELECT VS4TEmpSlipDoc.TEpsTSAPTEmTCode, VS4TEmpSlipDoc.TEpsTSaPDate, VS4TEmpSlipDoc.TEpsStartDate, VS4TEmpSlipDoc.TEpsEndDate, VS4TEmpSlipDoc.TEpsOTStartDate, VS4TEmpSlipDoc.TEpsOTEndDate, VS4TEmpSlipDoc.TEpsSalaryPeriod, VS4TEmpSlipDoc.TEpsPaymentType, VS4TEmpSlipDoc.TEpsTBnkCode, VS4TEmpSlipDoc.TEpsBankName, VS4TEmpSlipPeriod.TSaPStatus, VS4TEmpSlipDoc.TEpsNetTotal, VS4TEmpSlipDoc.TEpsBankAccType, VS4TEmpSlipDoc.TEpsBankAccName, VS4TEmpSlipDoc.TEpsBankAccNo, VS4TEmpSlipDoc.TEpsBankBranch, VS4TEmpSlipDoc.TEpsTEmpCode, VS4TEmpSlipDoc.TEpsTBBrCode, VS4TEmployee.TEmpTBraCode, VS4TEmployee.TEmpTDivCode, VS4TEmployee.TEmpTDepCode, VS4TEmployee.TEmpTSecCode, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TEmployee.TEmpFullName, VS4TEmpSlipDoc.TEpsCheckGroup, VS4TEmployeeType.TEmTName, VS4TEmployee.TEmpStatus, VS4TEmployee.TEmpType, VS4TEmployee.TEmpTEmTCode, VS4TEmpSlipDoc.TEpsEmployeeName
FROM VS4TEmpSlipPeriod INNER JOIN ((VS4TEmployeeType RIGHT JOIN (VS4TDivision INNER JOIN (VS4TBranch INNER JOIN ((VS4TEmployee INNER JOIN VS4TSection ON VS4TEmployee.TEmpTSecCode=VS4TSection.TSecCode) INNER JOIN VS4TDepartment ON VS4TEmployee.TEmpTDepCode=VS4TDepartment.TDepCode) ON VS4TBranch.TBraCode=VS4TEmployee.TEmpTBraCode) ON VS4TDivision.TDivCode=VS4TEmployee.TEmpTDivCode) ON VS4TEmployeeType.TEmTCode=VS4TEmployee.TEmpTEmTCode) INNER JOIN VS4TEmpSlipDoc ON VS4TEmployee.TEmpCode=VS4TEmpSlipDoc.TEpsTEmpCode) ON (VS4TEmpSlipPeriod.TSaPTEmTCode=VS4TEmpSlipDoc.TEpsTSAPTEmTCode) AND (VS4TEmpSlipPeriod.TSaPDate=VS4TEmpSlipDoc.TEpsTSaPDate)
GROUP BY VS4TEmpSlipDoc.TEpsTSAPTEmTCode, VS4TEmpSlipDoc.TEpsTSaPDate, VS4TEmpSlipDoc.TEpsStartDate, VS4TEmpSlipDoc.TEpsEndDate, VS4TEmpSlipDoc.TEpsOTStartDate, VS4TEmpSlipDoc.TEpsOTEndDate, VS4TEmpSlipDoc.TEpsSalaryPeriod, VS4TEmpSlipDoc.TEpsPaymentType, VS4TEmpSlipDoc.TEpsTBnkCode, VS4TEmpSlipDoc.TEpsBankName, VS4TEmpSlipPeriod.TSaPStatus, VS4TEmpSlipDoc.TEpsNetTotal, VS4TEmpSlipDoc.TEpsBankAccType, VS4TEmpSlipDoc.TEpsBankAccName, VS4TEmpSlipDoc.TEpsBankAccNo, VS4TEmpSlipDoc.TEpsBankBranch, VS4TEmpSlipDoc.TEpsTEmpCode, VS4TEmpSlipDoc.TEpsTBBrCode, VS4TEmployee.TEmpTBraCode, VS4TEmployee.TEmpTDivCode, VS4TEmployee.TEmpTDepCode, VS4TEmployee.TEmpTSecCode, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TEmployee.TEmpFullName, VS4TEmpSlipDoc.TEpsCheckGroup, VS4TEmployeeType.TEmTName, VS4TEmployee.TEmpStatus, VS4TEmployee.TEmpType, VS4TEmployee.TEmpTEmTCode, VS4TEmpSlipDoc.TEpsEmployeeName, VS4TEmpSlipDoc.TEpsApproveStatus, VS4TEmpSlipDoc.TEpsCancelStatus
HAVING (((VS4TEmpSlipDoc.TEpsApproveStatus)=1) AND ((VS4TEmpSlipDoc.TEpsCancelStatus)=0))
GO

CREATE VIEW VS4VExportSlipGov
AS 
SELECT Year(TEpsTSaPDate) AS VESGYEAR, Month(TEpsTSaPDate) AS VESGMONTH, Count(VS4TEmpSlipDoc.TEpsNo) AS VESGTotalSlip, VS4TEmpSlipPeriod.TSaPStatus, Sum(VS4TEmpSlipDoc.TEpsNetTotal) AS TEpsNetTotal, Sum(VS4TEmpSlipDoc.TEpsSalaryBase) AS TEpsSalaryBase, Sum(VS4TEmpSlipDoc.TEpsSalaryQuantity) AS TEpsSalaryQuantity, Sum(VS4TEmpSlipDoc.TEpsSalaryCalc) AS TEpsSalaryCalc, Sum(VS4TEmpSlipDoc.TEpsTotalDebit) AS TEpsTotalDebit, Sum(VS4TEmpSlipDoc.TEpsTotalCredit) AS TEpsTotalCredit, Sum(VS4TEmpSlipDoc.TEpsTotalSave) AS TEpsTotalSave, Sum(VS4TEmpSlipDoc.TEpsPTAXBase) AS TEpsPTAXBase, Sum(VS4TEmpSlipDoc.TEpsPTAX) AS TEpsPTAX, Sum(VS4TEmpSlipDoc.TEpsSTAXBase) AS TEpsSTAXBase, Sum(VS4TEmpSlipDoc.TEpsSTAX) AS TEpsSTAX, Sum(VS4TEmpSlipDoc.TEpsSFUNDBase) AS TEpsSFUNDBase, Sum(VS4TEmpSlipDoc.TEpsSFUND) AS TEpsSFUND, Sum(VS4TEmpSlipDoc.TEpsFUNDBase) AS TEpsFUNDBase, Sum(VS4TEmpSlipDoc.TEpsFUND) AS TEpsFUND, Sum(VS4TEmpSlipDoc.TEpsFINT) AS TEpsFINT, VS4TEmployee.TEmpCode, VS4TEmployee.TEmpFullName, VS4TEmployee.TEmpFullName2, VS4TEmployee.TEmpTaxNo, VS4TEmployee.TEmpSocialSecurity, VS4TEmployee.TEmpCitizenNo, VS4TEmployee.TEmpFundNo, VS4TEmployee.TEmpStartFund, VS4TEmployee.TEmpTBraCode, VS4TEmployee.TEmpTDivCode, VS4TEmployee.TEmpTDepCode, VS4TEmployee.TEmpTSecCode, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TEmpSlipDoc.TEpsTEmpCode, Sum(VS4TEmpSlipDoc.TEpsTotalWorkDay) AS TEpsTotalWorkDay, VS4TEmployee2.TEm2SkipTax, VS4TBranch.TBraDocCode, VS4TBranch.TBraAddressBill, Max(VS4TEmpSlipDoc.TEpsSFUNDAmass) AS TEpsSFUNDAmass, Max(VS4TEmpSlipDoc.TEpsSFUNDOffice) AS TEpsSFUNDOffice, Max(VS4TEmpSlipDoc.TEpsSTAXAmass) AS TEpsSTAXAmass, Max(VS4TEmpSlipDoc.TEpsSTAXOffice) AS TEpsSTAXOffice, Max(VS4TEmpSlipDoc.TEpsPTAXAmass) AS TEpsPTAXAmass, Max(VS4TEmpSlipDoc.TEpsPTAXOffice) AS TEpsPTAXOffice
FROM VS4TEmpSlipPeriod INNER JOIN (((VS4TDivision RIGHT JOIN (VS4TBranch RIGHT JOIN ((VS4TEmployee LEFT JOIN VS4TSection ON VS4TEmployee.TEmpTSecCode = VS4TSection.TSecCode) LEFT JOIN VS4TDepartment ON VS4TEmployee.TEmpTDepCode = VS4TDepartment.TDepCode) ON VS4TBranch.TBraCode = VS4TEmployee.TEmpTBraCode) ON VS4TDivision.TDivCode = VS4TEmployee.TEmpTDivCode) LEFT JOIN VS4TEmployee2 ON VS4TEmployee.TEmpCode = VS4TEmployee2.TEm2TEmpCode) INNER JOIN VS4TEmpSlipDoc ON VS4TEmployee.TEmpCode = VS4TEmpSlipDoc.TEpsTEmpCode) ON (VS4TEmpSlipPeriod.TSaPDate = VS4TEmpSlipDoc.TEpsTSaPDate) AND (VS4TEmpSlipPeriod.TSaPTEmTCode = VS4TEmpSlipDoc.TEpsTSAPTEmTCode)
GROUP BY Year(TEpsTSaPDate), Month(TEpsTSaPDate), VS4TEmpSlipPeriod.TSaPStatus, VS4TEmployee.TEmpCode, VS4TEmployee.TEmpFullName, VS4TEmployee.TEmpFullName2, VS4TEmployee.TEmpTaxNo, VS4TEmployee.TEmpSocialSecurity, VS4TEmployee.TEmpCitizenNo, VS4TEmployee.TEmpFundNo, VS4TEmployee.TEmpStartFund, VS4TEmployee.TEmpTBraCode, VS4TEmployee.TEmpTDivCode, VS4TEmployee.TEmpTDepCode, VS4TEmployee.TEmpTSecCode, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TEmpSlipDoc.TEpsTEmpCode, VS4TEmployee2.TEm2SkipTax, VS4TBranch.TBraDocCode, VS4TBranch.TBraAddressBill, VS4TEmpSlipDoc.TEpsApproveStatus, VS4TEmpSlipDoc.TEpsCancelStatus, VS4TEmpSlipDoc.TEpsCheckGroup
HAVING (((VS4TEmpSlipPeriod.TSaPStatus)=0) AND ((VS4TEmployee2.TEm2SkipTax)<>1) AND ((VS4TEmpSlipDoc.TEpsApproveStatus)=1) AND ((VS4TEmpSlipDoc.TEpsCancelStatus)=0) AND ((VS4TEmpSlipDoc.TEpsCheckGroup)=0))
GO

CREATE VIEW VS4VExportSlipGSum
AS 
SELECT Year(TEpsTSaPDate) AS VEGSYEAR, Month(TEpsTSaPDate) AS VEGSMONTH, Count(VS4TEmpSlipDoc.TEpsNo) AS VEGSTotalSlip, VS4TEmpSlipPeriod.TSaPStatus, Sum(VS4TEmpSlipDoc.TEpsNetTotal) AS TEpsNetTotal, Sum(VS4TEmpSlipDoc.TEpsSalaryBase) AS TEpsSalaryBase, Sum(VS4TEmpSlipDoc.TEpsSalaryQuantity) AS TEpsSalaryQuantity, Sum(VS4TEmpSlipDoc.TEpsSalaryCalc) AS TEpsSalaryCalc, Sum(VS4TEmpSlipDoc.TEpsTotalDebit) AS TEpsTotalDebit, Sum(VS4TEmpSlipDoc.TEpsTotalCredit) AS TEpsTotalCredit, Sum(VS4TEmpSlipDoc.TEpsTotalSave) AS TEpsTotalSave, Sum(VS4TEmpSlipDoc.TEpsPTAXBase) AS TEpsPTAXBase, Sum(VS4TEmpSlipDoc.TEpsPTAX) AS TEpsPTAX, Sum(VS4TEmpSlipDoc.TEpsSTAXBase) AS TEpsSTAXBase, Sum(VS4TEmpSlipDoc.TEpsSTAX) AS TEpsSTAX, Sum(VS4TEmpSlipDoc.TEpsSFUNDBase) AS TEpsSFUNDBase, Sum(VS4TEmpSlipDoc.TEpsSFUND) AS TEpsSFUND, Sum(VS4TEmpSlipDoc.TEpsFUNDBase) AS TEpsFUNDBase, Sum(VS4TEmpSlipDoc.TEpsFUND) AS TEpsFUND, Sum(VS4TEmpSlipDoc.TEpsFINT) AS TEpsFINT, VS4TEmployee2.TEm2SkipTax
FROM VS4TEmpSlipPeriod INNER JOIN ((VS4TEmployee LEFT JOIN VS4TEmployee2 ON VS4TEmployee.TEmpCode = VS4TEmployee2.TEm2TEmpCode) INNER JOIN VS4TEmpSlipDoc ON VS4TEmployee.TEmpCode = VS4TEmpSlipDoc.TEpsTEmpCode) ON (VS4TEmpSlipPeriod.TSaPDate = VS4TEmpSlipDoc.TEpsTSaPDate) AND (VS4TEmpSlipPeriod.TSaPTEmTCode = VS4TEmpSlipDoc.TEpsTSAPTEmTCode)
GROUP BY Year(TEpsTSaPDate), Month(TEpsTSaPDate), VS4TEmpSlipPeriod.TSaPStatus, VS4TEmployee2.TEm2SkipTax, VS4TEmpSlipDoc.TEpsApproveStatus, VS4TEmpSlipDoc.TEpsCancelStatus, VS4TEmpSlipDoc.TEpsCheckGroup
HAVING (((VS4TEmpSlipPeriod.TSaPStatus)=0) AND ((VS4TEmployee2.TEm2SkipTax)<>1) AND ((VS4TEmpSlipDoc.TEpsApproveStatus)=1) AND ((VS4TEmpSlipDoc.TEpsCancelStatus)=0) AND ((VS4TEmpSlipDoc.TEpsCheckGroup)=0))
GO

CREATE VIEW VS4VExpSlipBankG
AS 
SELECT VS4TEmpSlipDoc.TEpsTSAPTEmTCode, VS4TEmpSlipDoc.TEpsTSaPDate, VS4TEmpSlipDoc.TEpsStartDate, VS4TEmpSlipDoc.TEpsEndDate, VS4TEmpSlipDoc.TEpsOTStartDate, VS4TEmpSlipDoc.TEpsOTEndDate, VS4TEmpSlipDoc.TEpsSalaryPeriod, VS4TEmpSlipDoc.TEpsPaymentType, VS4TEmpSlipDoc.TEpsTBnkCode, VS4TEmpSlipDoc.TEpsBankName, VS4TEmpSlipPeriod.TSaPStatus, Sum(VS4TEmpSlipDoc.TEpsNetTotal) AS TEpsNetTotal, VS4TEmpSlipDoc.TEpsCheckGroup
FROM VS4TEmpSlipPeriod INNER JOIN VS4TEmpSlipDoc ON (VS4TEmpSlipPeriod.TSaPTEmTCode=VS4TEmpSlipDoc.TEpsTSAPTEmTCode) AND (VS4TEmpSlipPeriod.TSaPDate=VS4TEmpSlipDoc.TEpsTSaPDate)
GROUP BY VS4TEmpSlipDoc.TEpsTSAPTEmTCode, VS4TEmpSlipDoc.TEpsTSaPDate, VS4TEmpSlipDoc.TEpsStartDate, VS4TEmpSlipDoc.TEpsEndDate, VS4TEmpSlipDoc.TEpsOTStartDate, VS4TEmpSlipDoc.TEpsOTEndDate, VS4TEmpSlipDoc.TEpsSalaryPeriod, VS4TEmpSlipDoc.TEpsPaymentType, VS4TEmpSlipDoc.TEpsTBnkCode, VS4TEmpSlipDoc.TEpsBankName, VS4TEmpSlipPeriod.TSaPStatus, VS4TEmpSlipDoc.TEpsCheckGroup, VS4TEmpSlipDoc.TEpsApproveStatus, VS4TEmpSlipDoc.TEpsCancelStatus
HAVING (((VS4TEmpSlipDoc.TEpsApproveStatus)=1) AND ((VS4TEmpSlipDoc.TEpsCancelStatus)=0))
GO

CREATE VIEW VS4VFlight
AS 
SELECT VS4TFlight.*, VS4TAR.*
FROM VS4TAR RIGHT JOIN VS4TFlight ON VS4TAR.TARNCode = VS4TFlight.TFliTARNCode
GO

CREATE VIEW VS4VFlightEmployee
AS 
SELECT VS4TFlight.*, VS4TFlightEmployee.*
FROM VS4TFlight LEFT JOIN VS4TFlightEmployee ON VS4TFlight.TFliNo = VS4TFlightEmployee.TFlETFliNo
GO

CREATE VIEW VS4VFlightGuide
AS 
SELECT VS4TFlight.*, VS4TFlightGuide.*
FROM VS4TFlight LEFT JOIN VS4TFlightGuide ON VS4TFlight.TFliNo = VS4TFlightGuide.TFlGTFliNo
GO

CREATE VIEW VS4VFlightVehicle
AS 
SELECT VS4TFlight.*, VS4TFlightVehicle.*
FROM VS4TFlight LEFT JOIN VS4TFlightVehicle ON VS4TFlight.TFliNo = VS4TFlightVehicle.TFVhTFliNo
GO

CREATE VIEW VS4VFormula
AS 
SELECT VS4TFormula.*, VS4TFormulaSub.*, VS4TFormulaSubCell.*
FROM VS4TFormula INNER JOIN (VS4TFormulaSub LEFT JOIN VS4TFormulaSubCell ON VS4TFormulaSub.TFmSID=VS4TFormulaSubCell.TFSCTFmSID) ON VS4TFormula.TForCode=VS4TFormulaSub.TFmSTForCode
GO

CREATE VIEW VS4VFR
AS 
SELECT VS4TFR.*, VS4TFRRow.*, VS4TACChart.*
FROM (VS4TFR INNER JOIN VS4TFRRow ON VS4TFR.TFRHCode = VS4TFRRow.TFRRTFRHCode) LEFT JOIN VS4TACChart ON VS4TFRRow.TFRRTAccCode = VS4TACChart.TACCCode
GO

CREATE VIEW VS4VFundReport
AS 
SELECT VS4VExportSlipGov.*, VS4VEmpAmass.TSmbAmassAmount
FROM VS4VExportSlipGov LEFT JOIN VS4VEmpAmass ON (VS4VExportSlipGov.TEmpCode = VS4VEmpAmass.TEpsTEmpCode) AND (VS4VExportSlipGov.VESGMONTH = VS4VEmpAmass.VEPSMonth) AND (VS4VExportSlipGov.VESGYEAR = VS4VEmpAmass.VEPSYear)
WHERE (((VS4VExportSlipGov.TEpsSalaryCalc)>0) AND ((VS4VEmpAmass.TEpsCheckGroup)=0) AND ((VS4VEmpAmass.TAmyTAMTAlias)='SFUND') AND ((VS4VEmpAmass.TAmyCheckMoney)=2))
GO

CREATE VIEW VS4VGL
AS 
SELECT VS4TGLTrans.*, VS4TGLTransSub.*, VS4TGLBook.*, VS4TAccountPeriod.*, VS4TAccountYear.*, VS4TACGroup.*, VS4TACChart.*, VS4TAP.TAPNName, VS4TAR.TARNName, VS4TACGroupSub.*, VS4TAsset.TAssNo, VS4TAsset.TAssAlias, VS4TAsset.TAssName
FROM (VS4TGLBook INNER JOIN VS4TGLTrans ON VS4TGLBook.TGLBCode = VS4TGLTrans.TGLTTGLBCode) LEFT JOIN (VS4TACGroup RIGHT JOIN (VS4TACGroupSub RIGHT JOIN (VS4TAccountYear RIGHT JOIN (VS4TAccountPeriod RIGHT JOIN (VS4TACChart RIGHT JOIN (((VS4TGLTransSub LEFT JOIN VS4TAP ON VS4TGLTransSub.TGTSTAPNCode = VS4TAP.TAPNCode) LEFT JOIN VS4TAR ON VS4TGLTransSub.TGTSTARNCode = VS4TAR.TARNCode) LEFT JOIN VS4TAsset ON VS4TGLTransSub.TGTSTAssCode = VS4TAsset.TAssCode) ON VS4TACChart.TACCCode = VS4TGLTransSub.TGTSTACCCode) ON (VS4TAccountPeriod.TACPID = VS4TGLTransSub.TGTSTACPID) AND (VS4TAccountPeriod.TACPTACYID = VS4TGLTransSub.TGTSTACPTACYID)) ON VS4TAccountYear.TACYID = VS4TAccountPeriod.TACPTACYID) ON VS4TACGroupSub.TAGsCode = VS4TACChart.TACCTAGsCode) ON VS4TACGroup.TACGCode = VS4TACGroupSub.TAGsTACGCode) ON VS4TGLTrans.TGLTNo = VS4TGLTransSub.TGTSTGLTNo
GO

CREATE VIEW VS4VGLActive
AS 
SELECT VS4TGLTrans.TGLTConfirmStatus, VS4TGLTrans.TGLTApproveStatus, VS4TGLTrans.TGLTPostStatus, VS4TGLTransSub.TGTSTACCCode, VS4TGLTransSub.TGTSTBraCode, VS4TGLTransSub.TGTSTPrjCode, VS4TGLTransSub.TGTSTDivCode, VS4TGLTransSub.TGTSTDepCode, VS4TGLTransSub.TGTSTSecCode, VS4TGLTransSub.TGTSTSAeCode, VS4TGLTransSub.TGTSTARNCode, VS4TGLTransSub.TGTSTAPNCode, VS4TGLTransSub.TGTSTAssCode, VS4TGLTransSub.TGTSDebit, VS4TGLTransSub.TGTSCredit, VS4TGLTransSub.TGTSTACPTACYID, VS4TGLTransSub.TGTSTACPID, VS4TGLTransSub.TGTSStatus, VS4TGLTrans.TGLTCancelStatus, VS4TGLTransSub.TGTSTEmpCode, VS4TACChart.TACCTACGCode
FROM VS4TGLTrans INNER JOIN (VS4TACChart INNER JOIN VS4TGLTransSub ON VS4TACChart.TACCCode=VS4TGLTransSub.TGTSTACCCode) ON VS4TGLTrans.TGLTNo=VS4TGLTransSub.TGTSTGLTNo
WHERE (((VS4TGLTrans.TGLTCancelStatus)=0))
GO

CREATE VIEW VS4VGLActiveSum
AS 
SELECT VS4VGLActive.TGLTConfirmStatus, VS4VGLActive.TGLTPostStatus, VS4VGLActive.TGTSTACCCode, VS4VGLActive.TGTSTBraCode, VS4VGLActive.TGTSTPrjCode, VS4VGLActive.TGTSTDivCode, VS4VGLActive.TGTSTDepCode, VS4VGLActive.TGTSTSecCode, VS4VGLActive.TGTSTSAeCode, VS4VGLActive.TGTSTARNCode, VS4VGLActive.TGTSTAPNCode, VS4VGLActive.TGTSTAssCode, Sum(VS4VGLActive.TGTSDebit) AS TGTSDebit, Sum(VS4VGLActive.TGTSCredit) AS TGTSCredit, VS4VGLActive.TGTSTACPTACYID, VS4VGLActive.TGTSTACPID, VS4VGLActive.TGTSTEmpCode, VS4VGLActive.TACCTACGCode
FROM VS4VGLActive
GROUP BY VS4VGLActive.TGLTConfirmStatus, VS4VGLActive.TGLTPostStatus, VS4VGLActive.TGTSTACCCode, VS4VGLActive.TGTSTBraCode, VS4VGLActive.TGTSTPrjCode, VS4VGLActive.TGTSTDivCode, VS4VGLActive.TGTSTDepCode, VS4VGLActive.TGTSTSecCode, VS4VGLActive.TGTSTSAeCode, VS4VGLActive.TGTSTARNCode, VS4VGLActive.TGTSTAPNCode, VS4VGLActive.TGTSTAssCode, VS4VGLActive.TGTSTACPTACYID, VS4VGLActive.TGTSTACPID, VS4VGLActive.TGTSTEmpCode, VS4VGLActive.TACCTACGCode
GO

CREATE VIEW VS4VGLActiveSumY
AS 
SELECT VS4VGLActive.TGLTConfirmStatus, VS4VGLActive.TGLTPostStatus, VS4VGLActive.TGTSTACCCode, VS4VGLActive.TGTSTBraCode, VS4VGLActive.TGTSTPrjCode, VS4VGLActive.TGTSTDivCode, VS4VGLActive.TGTSTDepCode, VS4VGLActive.TGTSTSecCode, VS4VGLActive.TGTSTSAeCode, VS4VGLActive.TGTSTARNCode, VS4VGLActive.TGTSTAPNCode, VS4VGLActive.TGTSTAssCode, Sum(VS4VGLActive.TGTSDebit) AS TGTSDebit, Sum(VS4VGLActive.TGTSCredit) AS TGTSCredit, VS4VGLActive.TGTSTACPTACYID, VS4VGLActive.TGTSTEmpCode, VS4VGLActive.TACCTACGCode
FROM VS4VGLActive
GROUP BY VS4VGLActive.TGLTConfirmStatus, VS4VGLActive.TGLTPostStatus, VS4VGLActive.TGTSTACCCode, VS4VGLActive.TGTSTBraCode, VS4VGLActive.TGTSTPrjCode, VS4VGLActive.TGTSTDivCode, VS4VGLActive.TGTSTDepCode, VS4VGLActive.TGTSTSecCode, VS4VGLActive.TGTSTSAeCode, VS4VGLActive.TGTSTARNCode, VS4VGLActive.TGTSTAPNCode, VS4VGLActive.TGTSTAssCode, VS4VGLActive.TGTSTACPTACYID, VS4VGLActive.TGTSTEmpCode, VS4VGLActive.TACCTACGCode
GO

CREATE VIEW VS4VGLFR
AS 
SELECT VS4TGLTrans.TGLTBalanceFlag, VS4TGLTransSub.TGTSTACPTACYID, VS4TGLTransSub.TGTSTACPID, VS4TGLTransSub.TGTSDebit, VS4TGLTransSub.TGTSCredit, VS4TACChart.TACCCode, VS4TACChart.TACCName, VS4TACChart.TACCName2, VS4TACChart.TACCCashFlowGroup, VS4TGLTransSub.TGTSTBraCode, VS4TGLTransSub.TGTSTPrjCode, VS4TGLTransSub.TGTSTDivCode, VS4TGLTransSub.TGTSTDepCode, VS4TGLTransSub.TGTSTSecCode, VS4TGLTransSub.TGTSTSAeCode, VS4TGLTransSub.TGTSTARNCode, VS4TGLTransSub.TGTSTAPNCode, VS4TGLTransSub.TGTSTBnkCode, VS4TGLTransSub.TGTSTEmpCode, VS4TACChart.TACCTACGCode, VS4TACChart.TACCTAGsCode, VS4TACChart.TACCLevel, VS4TACGroupSub.TAGsTACGCode, VS4TAccountMap.TACMAlias, VS4TACGroupSub.TAGsName, VS4TACChart.TACCShowReport, VS4TACChart.TACCIsSpecial, VS4TACChart.TACCPLTAGsCode
FROM VS4TGLTrans LEFT JOIN (VS4TACGroupSub RIGHT JOIN ((VS4TACChart LEFT JOIN VS4TAccountMap ON VS4TACChart.TACCCode = VS4TAccountMap.TACMTACCCode) RIGHT JOIN VS4TGLTransSub ON VS4TACChart.TACCCode = VS4TGLTransSub.TGTSTACCCode) ON VS4TACGroupSub.TAGsCode = VS4TACChart.TACCTAGsCode) ON VS4TGLTrans.TGLTNo = VS4TGLTransSub.TGTSTGLTNo
GO

CREATE VIEW VS4VGLRepair
AS 
SELECT VS4TGLTransSub.TGTSTACCCode, Sum(VS4TGLTransSub.TGTSDebit) AS TGTSDebit, Sum(VS4TGLTransSub.TGTSCredit) AS TGTSCredit, VS4TGLTrans.TGLTCancelStatus, VS4TGLTrans.TGLTBalanceFlag, VS4TGLTrans.TGLTConfirmStatus, VS4TAccountPeriod.TACPStatus
FROM VS4TGLTrans INNER JOIN (VS4TAccountPeriod INNER JOIN VS4TGLTransSub ON (VS4TAccountPeriod.TACPTACYID=VS4TGLTransSub.TGTSTACPTACYID) AND (VS4TAccountPeriod.TACPID=VS4TGLTransSub.TGTSTACPID)) ON VS4TGLTrans.TGLTNo=VS4TGLTransSub.TGTSTGLTNo
GROUP BY VS4TGLTransSub.TGTSTACCCode, VS4TGLTrans.TGLTCancelStatus, VS4TGLTrans.TGLTBalanceFlag, VS4TGLTrans.TGLTConfirmStatus, VS4TAccountPeriod.TACPStatus
HAVING (((VS4TGLTrans.TGLTCancelStatus)=0) AND ((VS4TGLTrans.TGLTBalanceFlag)=0))
GO

CREATE VIEW VS4VGLTrans
AS 
SELECT VS4TGLTrans.*, VS4TGLBook.*, VS4TGLTransSub.*, VS4TProject.TPrjName2, VS4TProject.TPrjMode, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TACChart.TACCName, VS4TACChart.TACCName2
FROM VS4TProject RIGHT JOIN ((VS4TGLBook INNER JOIN VS4TGLTrans ON VS4TGLBook.TGLBCode = VS4TGLTrans.TGLTTGLBCode) LEFT JOIN (VS4TACChart RIGHT JOIN ((((VS4TGLTransSub LEFT JOIN VS4TBranch ON VS4TGLTransSub.TGTSTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TDivision ON VS4TGLTransSub.TGTSTDivCode = VS4TDivision.TDivCode) LEFT JOIN VS4TDepartment ON VS4TGLTransSub.TGTSTDepCode = VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TGLTransSub.TGTSTSecCode = VS4TSection.TSecCode) ON VS4TACChart.TACCCode = VS4TGLTransSub.TGTSTACCCode) ON VS4TGLTrans.TGLTNo = VS4TGLTransSub.TGTSTGLTNo) ON VS4TProject.TPrjCode = VS4TGLTransSub.TGTSTPrjCode
GO

CREATE VIEW VS4VGLTransHead
AS 
SELECT VS4TGLTrans.*, VS4TGLBook.*
FROM VS4TGLBook INNER JOIN VS4TGLTrans ON VS4TGLBook.TGLBCode=VS4TGLTrans.TGLTTGLBCode
GO

CREATE VIEW VS4VGLTrialBefore
AS 
SELECT VS4TGLTransMove.TGTMTACPTACYID, VS4TGLTransMove.TGTMTACPID, VS4TGLTransMove.TGTMStatus, VS4TGLTransMove.TGTMQuarter, VS4TGLTransMove.TGTMTACCCode, VS4TACChart.TACCName, VS4TGLTransMove.TGTMDebitBegin, VS4TGLTransMove.TGTMCreditBegin, VS4TGLTransMove.TGTMDebitEnd, VS4TGLTransMove.TGTMCreditEnd, VS4TGLTransMove.TGTMDebitTR, VS4TGLTransMove.TGTMCreditTR, VS4TGLTransMove.TGTMDebitApp, VS4TGLTransMove.TGTMCreditApp, VS4TGLTransMove.TGTMDebitAdj, VS4TGLTransMove.TGTMCreditAdj, VS4TGLTransMove.TGTMDebitBudget, VS4TGLTransMove.TGTMCreditBudget, VS4TGLTransMove.TGTMDebitBeginTR, VS4TGLTransMove.TGTMCreditBeginTR, VS4TACGroupSub.TAGsCode, VS4TACGroupSub.TAGsName, VS4TACGroupSub.TAGsName2, VS4TACGroup.TACGCode, VS4TACGroup.TACGName, VS4TACGroup.TACGName2, VS4TACChart.TACCPLTAGsCode, VS4TAccountPeriod.TACPTACYID, VS4TAccountPeriod.TACPID, VS4TGLTransMove.TGTMTBraCode, VS4TBranch.TBraCode, VS4TBranch.TBraName, VS4TBranch.TBraName2, VS4TACChart.TACCName2, VS4TGLTransMove.TGTMMode
FROM VS4TBranch RIGHT JOIN (VS4TACGroup INNER JOIN (VS4TAccountYear INNER JOIN (VS4TAccountPeriod INNER JOIN ((VS4TACChart INNER JOIN VS4TACGroupSub ON VS4TACChart.TACCPLTAGsCode = VS4TACGroupSub.TAGsCode) INNER JOIN VS4TGLTransMove ON VS4TACChart.TACCCode = VS4TGLTransMove.TGTMTACCCode) ON (VS4TAccountPeriod.TACPID = VS4TGLTransMove.TGTMTACPID) AND (VS4TAccountPeriod.TACPTACYID = VS4TGLTransMove.TGTMTACPTACYID)) ON VS4TAccountYear.TACYID = VS4TAccountPeriod.TACPTACYID) ON VS4TACGroup.TACGCode = VS4TACGroupSub.TAGsTACGCode) ON VS4TBranch.TBraCode = VS4TGLTransMove.TGTMTBraCode
GROUP BY VS4TGLTransMove.TGTMTACPTACYID, VS4TGLTransMove.TGTMTACPID, VS4TGLTransMove.TGTMStatus, VS4TGLTransMove.TGTMQuarter, VS4TGLTransMove.TGTMTACCCode, VS4TACChart.TACCName, VS4TGLTransMove.TGTMDebitBegin, VS4TGLTransMove.TGTMCreditBegin, VS4TGLTransMove.TGTMDebitEnd, VS4TGLTransMove.TGTMCreditEnd, VS4TGLTransMove.TGTMDebitTR, VS4TGLTransMove.TGTMCreditTR, VS4TGLTransMove.TGTMDebitApp, VS4TGLTransMove.TGTMCreditApp, VS4TGLTransMove.TGTMDebitAdj, VS4TGLTransMove.TGTMCreditAdj, VS4TGLTransMove.TGTMDebitBudget, VS4TGLTransMove.TGTMCreditBudget, VS4TGLTransMove.TGTMDebitBeginTR, VS4TGLTransMove.TGTMCreditBeginTR, VS4TACGroupSub.TAGsCode, VS4TACGroupSub.TAGsName, VS4TACGroupSub.TAGsName2, VS4TACGroup.TACGCode, VS4TACGroup.TACGName, VS4TACGroup.TACGName2, VS4TACChart.TACCPLTAGsCode, VS4TAccountPeriod.TACPTACYID, VS4TAccountPeriod.TACPID, VS4TGLTransMove.TGTMTBraCode, VS4TBranch.TBraCode, VS4TBranch.TBraName, VS4TBranch.TBraName2, VS4TACChart.TACCName2, VS4TGLTransMove.TGTMMode
GO

CREATE VIEW VS4VGLTrial
AS 
SELECT VS4VGLTrialBefore.TGTMTACPTACYID, VS4VGLTrialBefore.TGTMTACPID, VS4VGLTrialBefore.TGTMQuarter, VS4TACChart.TACCTACGCode, VS4TACChart.TACCLevel, VS4TACChart.TACCCode, VS4TACChart.TACCName, VS4VGLTrialBefore.TGTMDebitBegin, VS4VGLTrialBefore.TGTMCreditBegin, VS4VGLTrialBefore.TGTMDebitEnd, VS4VGLTrialBefore.TGTMCreditEnd, VS4VGLTrialBefore.TGTMDebitTR, VS4VGLTrialBefore.TGTMCreditTR, VS4VGLTrialBefore.TGTMDebitApp, VS4VGLTrialBefore.TGTMCreditApp, VS4VGLTrialBefore.TGTMDebitAdj, VS4VGLTrialBefore.TGTMCreditAdj, VS4VGLTrialBefore.TGTMDebitBudget, VS4VGLTrialBefore.TGTMCreditBudget, VS4VGLTrialBefore.TGTMStatus, VS4VGLTrialBefore.TGTMDebitBeginTR, VS4VGLTrialBefore.TGTMCreditBeginTR, VS4TACChart.TACCIsSpecial, VS4TACChart.TACCShowReport, VS4TACChart.TACCTAGsCode, VS4TACChart.TACCReportCaption, VS4TACChart.TACCReverseSign, VS4TACChart.TACCCashFlowGroup, VS4TACChart.TACCCashFlowUPDN, VS4VGLTrialBefore.TAGsName, VS4VGLTrialBefore.TACGName, VS4TACChart.TACCName2, VS4VGLTrialBefore.TAGsName2, VS4VGLTrialBefore.TACGName2, VS4TACChart.TACCPLTAGsCode, VS4VGLTrialBefore.TACPTACYID, VS4VGLTrialBefore.TACPID, VS4VGLTrialBefore.TGTMTBraCode, VS4VGLTrialBefore.TBraCode, VS4VGLTrialBefore.TBraName, VS4VGLTrialBefore.TGTMMode, VS4TACChart.TACCIsControl
FROM VS4VGLTrialBefore RIGHT JOIN VS4TACChart ON VS4VGLTrialBefore.TGTMTACCCode = VS4TACChart.TACCCode
GROUP BY VS4VGLTrialBefore.TGTMTACPTACYID, VS4VGLTrialBefore.TGTMTACPID, VS4VGLTrialBefore.TGTMQuarter, VS4TACChart.TACCTACGCode, VS4TACChart.TACCLevel, VS4TACChart.TACCCode, VS4TACChart.TACCName, VS4VGLTrialBefore.TGTMDebitBegin, VS4VGLTrialBefore.TGTMCreditBegin, VS4VGLTrialBefore.TGTMDebitEnd, VS4VGLTrialBefore.TGTMCreditEnd, VS4VGLTrialBefore.TGTMDebitTR, VS4VGLTrialBefore.TGTMCreditTR, VS4VGLTrialBefore.TGTMDebitApp, VS4VGLTrialBefore.TGTMCreditApp, VS4VGLTrialBefore.TGTMDebitAdj, VS4VGLTrialBefore.TGTMCreditAdj, VS4VGLTrialBefore.TGTMDebitBudget, VS4VGLTrialBefore.TGTMCreditBudget, VS4VGLTrialBefore.TGTMStatus, VS4VGLTrialBefore.TGTMDebitBeginTR, VS4VGLTrialBefore.TGTMCreditBeginTR, VS4TACChart.TACCIsSpecial, VS4TACChart.TACCShowReport, VS4TACChart.TACCTAGsCode, VS4TACChart.TACCReportCaption, VS4TACChart.TACCReverseSign, VS4TACChart.TACCCashFlowGroup, VS4TACChart.TACCCashFlowUPDN, VS4VGLTrialBefore.TAGsName, VS4VGLTrialBefore.TACGName, VS4TACChart.TACCName2, VS4VGLTrialBefore.TAGsName2, VS4VGLTrialBefore.TACGName2, VS4TACChart.TACCPLTAGsCode, VS4VGLTrialBefore.TACPTACYID, VS4VGLTrialBefore.TACPID, VS4VGLTrialBefore.TGTMTBraCode, VS4VGLTrialBefore.TBraCode, VS4VGLTrialBefore.TBraName, VS4VGLTrialBefore.TGTMMode, VS4TACChart.TACCIsControl
GO

CREATE VIEW VS4VGovPayment
AS 
SELECT VS4TGovPayment.*, VS4TGovPaymentMB.*
FROM VS4TGovPayment INNER JOIN VS4TGovPaymentMB ON (VS4TGovPayment.TGvPMonth=VS4TGovPaymentMB.TGvMTGvPMonth) AND (VS4TGovPayment.TGvPYear=VS4TGovPaymentMB.TGvMTGvPYear) AND (VS4TGovPayment.TGvPType=VS4TGovPaymentMB.TGvMTGvPType)
GO

CREATE VIEW VS4VGroup
AS 
SELECT VS4TGroup.*, VS4TUser.*, VS4TEmployee.TEmpFullName, VS4TDivision.TDivCode, VS4TDivision.TDivName, VS4TDepartment.TDepCode, VS4TDepartment.TDepName, VS4TSection.TSecCode, VS4TSection.TSecName, VS4TBranch.TBraCode, VS4TBranch.TBraName
FROM (VS4TUser INNER JOIN (VS4TGroup INNER JOIN VS4TGroupMB ON VS4TGroup.TGroID = VS4TGroupMB.TGrMTGroID) ON (VS4TUser.TUsrID = VS4TGroupMB.TGrMTUsrID) AND (VS4TUser.TUsrID = VS4TGroupMB.TGrMTUsrID)) LEFT JOIN ((VS4TBranch RIGHT JOIN (((VS4TEmployee LEFT JOIN VS4TSection ON VS4TEmployee.TEmpTSecCode = VS4TSection.TSecCode) LEFT JOIN VS4TDepartment ON VS4TEmployee.TEmpTDepCode = VS4TDepartment.TDepCode) LEFT JOIN VS4TDivision ON VS4TEmployee.TEmpTDivCode = VS4TDivision.TDivCode) ON VS4TBranch.TBraCode = VS4TEmployee.TEmpTBraCode) RIGHT JOIN VS4TUserEmployee ON VS4TEmployee.TEmpCode = VS4TUserEmployee.TUsETEmpCode) ON VS4TUser.TUsrID = VS4TUserEmployee.TUsETUsrID
GO

CREATE VIEW VS4VGroupPermiss
AS 
SELECT VS4TGroupPermiss.*, VS4TGroup.*, VS4TUser.*
FROM VS4TUser RIGHT JOIN ((VS4TGroup LEFT JOIN VS4TGroupMB ON VS4TGroup.TGroID = VS4TGroupMB.TGrMTGroID) INNER JOIN VS4TGroupPermiss ON VS4TGroup.TGroID = VS4TGroupPermiss.TGrPTGroID) ON VS4TUser.TUsrID = VS4TGroupMB.TGrMTUsrID
GO

CREATE VIEW VS4VGroupPermissR
AS 
SELECT VS4TGroupPermiss.*, VS4TGroup.*, VS4TCommand.*, VS4TCommandGroup.*
FROM VS4TGroup INNER JOIN (VS4TCommandGroup RIGHT JOIN (VS4TGroupPermiss LEFT JOIN VS4TCommand ON VS4TGroupPermiss.TGrPTCmdID=VS4TCommand.TCmdID) ON VS4TCommandGroup.TCmGAlias=VS4TCommand.TCmdTCmGAlias) ON VS4TGroup.TGroID=VS4TGroupPermiss.TGrPTGroID
GO

CREATE VIEW VS4VInquiry
AS 
SELECT VS4TInquiry.*, VS4TInquiryGroup.*
FROM VS4TInquiryGroup INNER JOIN VS4TInquiry ON VS4TInquiryGroup.TIQGCode = VS4TInquiry.TIQRTIQGCode
GO

CREATE VIEW VS4VInquiryChoice
AS 
SELECT VS4TInquiryChoice.*, VS4TInquiry.*, VS4TInquiryGroup.*
FROM (VS4TInquiryGroup INNER JOIN VS4TInquiry ON VS4TInquiryGroup.TIQGCode = VS4TInquiry.TIQRTIQGCode) LEFT JOIN VS4TInquiryChoice ON VS4TInquiry.TIQRCode = VS4TInquiryChoice.TIQCTIQRCode
GO

CREATE VIEW VS4VInventAdjust
AS 
SELECT VS4TInventAdjust.*, VS4TInventAdjustMB.*, VS4TProduct.*, VS4TWarehouse.TWahCode, VS4TLocation.TLctCode, VS4TLocation.TLctTBraCode
FROM VS4TWarehouse INNER JOIN (VS4TProduct INNER JOIN (VS4TLocation INNER JOIN (VS4TInventAdjust INNER JOIN VS4TInventAdjustMB ON VS4TInventAdjust.TIjtNo=VS4TInventAdjustMB.TIjMTIjtNo) ON VS4TLocation.TLctCode=VS4TInventAdjustMB.TIjMTLctCode) ON VS4TProduct.TPdtCode=VS4TInventAdjustMB.TIjMTPdtCode) ON VS4TWarehouse.TWahCode=VS4TLocation.TLctTWahCode
GO

CREATE VIEW VS4VInventBalLast
AS 
SELECT VS4TInventoryMB.TInMTPdtCode AS VLSBTPdtCode, Max(TInvDate-Day(TInvDAte)+1) AS VLSBLastDate, VS4TInventoryMB.TInMLotNo, VS4TInventoryMB.TInMLotDate
FROM VS4TInventory INNER JOIN VS4TInventoryMB ON VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo
GROUP BY VS4TInventoryMB.TInMTPdtCode, VS4TInventoryMB.TInMLotNo, VS4TInventoryMB.TInMLotDate, VS4TInventory.TInvTInTAlias, VS4TInventory.TInvApproveStatus, VS4TInventory.TInvCancelStatus, VS4TInventoryMB.TInMStatus
HAVING (((VS4TInventory.TInvTInTAlias)='BEGINBALANCE') AND ((VS4TInventory.TInvApproveStatus)=1) AND ((VS4TInventory.TInvCancelStatus)=0) AND ((VS4TInventoryMB.TInMStatus)=1))
GO

CREATE VIEW VS4VInventBR
AS 
SELECT VS4TInventory.*, VS4TInventoryType.TInTName, VS4TInventoryMB.*, VS4TInventoryLOT.*, VS4TWarehouse.TWahName, VS4TLocation.TLctName, VS4TJob.TJobTARNCode, VS4TJob.TJobCustomerName, VS4TLocation.TLctDayAlert, VS4TLocation.TLctDayMove, VS4TLocation.TLctTBraCode, VS4TUnit.TUntName, VS4TUnit.TUntName2, VS4TWarehouse.TWahCode, VS4TProduct.TPdtCode, VS4TProduct.TPdtBarcode, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtTPTTCode, VS4TProduct.TPdtTPPuCode, VS4TProduct.TPdtFlag1, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TProduct.TPdtTPSECode, VS4TProduct.TPdtTPS2Code, VS4TProduct.TPdtTPS3Code, VS4TProduct.TPdtTPS4Code, VS4TProduct.TPdtTPG1Code, VS4TProduct.TPdtTPG2Code, VS4TProduct.TPdtTPG3Code, VS4TProduct.TPdtTPG4Code, VS4TProduct.TPdtTPCTAlias, VS4TProduct.TPdtSlowDay, VS4TProduct.TPdtDeadDay, VS4TProduct.TPdtSerialType, VS4TProduct.TPdtOrderPoint, VS4TProduct.TPdtTAPNCode, VS4TProduct.TPdtPurchaseFee, VS4TProduct.TPdtFactoryCode, VS4TProduct.TPdtTPDLCode, VS4TPOS.TPOSPrice
FROM VS4TUnit INNER JOIN (VS4TInventoryType INNER JOIN ((VS4TProduct LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) INNER JOIN ((VS4TInventory LEFT JOIN VS4TJob ON VS4TInventory.TInvTJobNo = VS4TJob.TJobNo) INNER JOIN (((VS4TInventoryMB LEFT JOIN VS4TLocation ON VS4TInventoryMB.TInMTLctCode = VS4TLocation.TLctCode) LEFT JOIN VS4TWarehouse ON VS4TLocation.TLctTWahCode = VS4TWarehouse.TWahCode) LEFT JOIN VS4TInventoryLOT ON (VS4TInventoryMB.TInMLotDate = VS4TInventoryLOT.TIMCLotDate) AND (VS4TInventoryMB.TInMLotNo = VS4TInventoryLOT.TIMCLotNo) AND (VS4TInventoryMB.TInMSerialNo = VS4TInventoryLOT.TIMCSerialNo) AND (VS4TInventoryMB.TInMCustom1 = VS4TInventoryLOT.TIMCCustom1) AND (VS4TInventoryMB.TInMTPdtCode = VS4TInventoryLOT.TIMCTPdtCode)) ON VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo) ON VS4TProduct.TPdtCode = VS4TInventoryMB.TInMTPdtCode) ON VS4TInventoryType.TInTAlias = VS4TInventory.TInvTInTAlias) ON VS4TUnit.TUntCode = VS4TProduct.TPdtTUntCode
WHERE (((VS4TWarehouse.TWahCode)='BORROW') AND ((VS4TInventoryMB.TInMStatus)=1) AND ((VS4TInventory.TInvCancelStatus)=0) AND ((VS4TInventory.TInvApproveStatus)=1) AND ((VS4TInventory.TInvDate)>=TPdtLastBalDate))
GO

CREATE VIEW VS4VInventH
AS 
SELECT VS4TInventory.*, VS4TInventoryType.*, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TJob.TJobCode
FROM (VS4TInventoryType INNER JOIN (VS4TInventory LEFT JOIN VS4TProject ON VS4TInventory.TInvTPrjCode=VS4TProject.TPrjCode) ON VS4TInventoryType.TInTAlias=VS4TInventory.TInvTInTAlias) LEFT JOIN VS4TJob ON VS4TInventory.TInvTJobNo=VS4TJob.TJobNo
GO

CREATE VIEW VS4VInventHSaleOut
AS 
SELECT VS4TInventory.*, VS4TInventoryType.*, VS4TSO.TSODTARNCode, VS4TSO.TSODCustomerName
FROM VS4TInventoryType INNER JOIN (VS4TInventory LEFT JOIN VS4TSO ON VS4TInventory.TInvRefNo=VS4TSO.TSODNo) ON VS4TInventoryType.TInTAlias=VS4TInventory.TInvTInTAlias
GO

CREATE VIEW VS4VAttachSheetSO2
AS 
SELECT VS4VInventMDS.*, VS4TSOMB.*, VS4TSO.*
FROM VS4TSO RIGHT JOIN (VS4VInventMDS LEFT JOIN VS4TSOMB ON (VS4VInventMDS.TInMTSODNo = VS4TSOMB.TSOBTSODNo) AND (VS4VInventMDS.TInMTSOBLn = VS4TSOMB.TSOBLn)) ON VS4TSO.TSODNo = VS4TSOMB.TSOBTSODNo
GO

CREATE VIEW VS4VProductGroup
AS 
SELECT VS4TProduct.TPdtCode AS VPdtCode, VS4TProductLine.TPdLName, VS4TProductSection.TPSEName, VS4TProductSec2.TPS2Name, VS4TProductSec3.TPS3Name, VS4TProductSec4.TPS4Name, VS4TProductGroup1.TPG1Name, VS4TProductGroup2.TPG2Name, VS4TProductGroup3.TPG3Name, VS4TProductGroup4.TPG4Name
FROM VS4TProductLine RIGHT JOIN ((((((((VS4TProduct LEFT JOIN VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code=VS4TProductGroup1.TPG1Code) LEFT JOIN VS4TProductGroup2 ON VS4TProduct.TPdtTPG2Code=VS4TProductGroup2.TPG2Code) LEFT JOIN VS4TProductGroup3 ON VS4TProduct.TPdtTPG3Code=VS4TProductGroup3.TPG3Code) LEFT JOIN VS4TProductGroup4 ON VS4TProduct.TPdtTPG4Code=VS4TProductGroup4.TPG4Code) LEFT JOIN VS4TProductSection ON VS4TProduct.TPdtTPSECode=VS4TProductSection.TPSECode) LEFT JOIN VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code=VS4TProductSec2.TPS2Code) LEFT JOIN VS4TProductSec3 ON VS4TProduct.TPdtTPS3Code=VS4TProductSec3.TPS3Code) LEFT JOIN VS4TProductSec4 ON VS4TProduct.TPdtTPS4Code=VS4TProductSec4.TPS4Code) ON VS4TProductLine.TPdLCode=VS4TProduct.TPdtTPDLCode
GO

CREATE VIEW VS4VInventoryH
AS 
SELECT VS4TInventory.*, VS4TSection.TSecName, VS4TDepartment.TDepName, VS4TDivision.TDivName, VS4TBranch.TBraName, VS4TProject.TPrjMode, VS4TInventoryType.TInTName, VS4TInventoryType.TInTDescription, VS4TAR.TARNName, VS4TInventoryType.TInTSort, VS4TJob.TJobCode, VS4TJob.TJobCustomerName, VS4TJob.TJobNo, VS4TJobMB.TJbMTPdtCode, VS4TJobMB.TJbMProductName, VS4TPR.TPRDNo, VS4TPR.TPRDTPRBCode, VS4TPR.TPRDDate, VS4TPR.TPRDRefNo, VS4TPR.TPRDRequestCode, VS4TPR.TPRDRequestBy, VS4TPR.TPRDDescription, VS4TPR.TPRDTBraCode, VS4TPR.TPRDTDivCode, VS4TJobMB.TJbMQuantity, VS4TJobMB.TJbMTUntCode, VS4TJobMB.TJbMQuantity2, VS4TJobMB.TJbMQuantity3, VS4TProductSection.TPSECode AS VInMTPSECode, VS4TProductSection.TPSEName AS VInMTPSEName, VS4TJobMB.TJbMCustom1, VS4TJobMB.TJbMCustom2, VS4TJobMB.TJbMCustom3, VS4TInventoryType.TInTInputCost, VS4TAR.TARNAddressBill, VS4TPO.TPODDeliveryDate, VS4TAP.TAPNName, VS4TInventoryType.TInTAlias
FROM VS4TInventoryType INNER JOIN (((((((((((((VS4TInventory LEFT JOIN VS4TDepartment ON VS4TInventory.TInvTDepCode = VS4TDepartment.TDepCode) LEFT JOIN VS4TDivision ON VS4TInventory.TInvTDivCode = VS4TDivision.TDivCode) LEFT JOIN VS4TBranch ON VS4TInventory.TInvTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TProject ON VS4TInventory.TInvTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TJob ON VS4TInventory.TInvTJobNo = VS4TJob.TJobNo) LEFT JOIN VS4TJobMB ON (VS4TInventory.TInvTJobNo = VS4TJobMB.TJbMTJobNo) AND (VS4TInventory.TInvTJbMLn = VS4TJobMB.TJbMLn)) LEFT JOIN VS4TPR ON VS4TInventory.TInvRefNo = VS4TPR.TPRDNo) LEFT JOIN VS4TProduct AS VS4TProduct_1 ON VS4TJobMB.TJbMTPdtCode = VS4TProduct_1.TPdtCode) LEFT JOIN VS4TProductSection ON VS4TProduct_1.TPdtTPSECode = VS4TProductSection.TPSECode) LEFT JOIN VS4TAR ON VS4TInventory.TInvTARNCode = VS4TAR.TARNCode) LEFT JOIN VS4TSection ON VS4TInventory.TInvTSecCode = VS4TSection.TSecCode) LEFT JOIN VS4TAP ON VS4TInventory.TInvTARNCode = VS4TAP.TAPNCode) LEFT JOIN VS4TPO ON VS4TInventory.TInvRefNo = VS4TPO.TPODNo) ON VS4TInventoryType.TInTAlias = VS4TInventory.TInvTInTAlias
GO

CREATE VIEW VS4VInventoryList
AS 
SELECT VS4TInventory.TInvDate, VS4TInventoryMB.TInMTPdtCode, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtTUntCode, Sum(VS4TInventoryMB.TInMInQuantity) AS TInMInQuantity, Sum(VS4TInventoryMB.TInMOutQuantity) AS TInMOutQuantity, Sum(VS4TInventoryMB.TInMAmouQuantity3) AS TInMAmouQuantity3, VS4TInventoryMB.TInMTLctCode, VS4TWarehouse.TWahCode, VS4TInventoryType.TInTAlias, VS4TInventoryMB.TInMFlag1, VS4TProduct.TPdtTUntCode2, Sum(VS4TInventoryMB.TInMInQuantity2) AS TInMInQuantity2, Sum(VS4TInventoryMB.TInMOutQuantity2) AS TInMOutQuantity2, Sum(VS4TInventoryMB.TInMAmouQuantity2) AS TInMAmouQuantity2, Sum(VS4TInventoryMB.TInMAmouQuantity) AS TInMAmouQuantity, VS4TProduct.TPdtTUntCode3, Sum(VS4TInventoryMB.TInMInQuantity3) AS TInMInQuantity3, Sum(VS4TInventoryMB.TInMOutQuantity3) AS TInMOutQuantity3, VS4TInventoryType.TInTName, VS4TInventoryType.TInTName2, VS4TInventoryType.TInTDescription
FROM VS4TWarehouse RIGHT JOIN (VS4TInventoryType INNER JOIN (VS4TProduct INNER JOIN (VS4TInventory INNER JOIN (VS4TInventoryMB LEFT JOIN VS4TLocation ON VS4TInventoryMB.TInMTLctCode = VS4TLocation.TLctCode) ON VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo) ON VS4TProduct.TPdtCode = VS4TInventoryMB.TInMTPdtCode) ON VS4TInventoryType.TInTAlias = VS4TInventory.TInvTInTAlias) ON VS4TWarehouse.TWahCode = VS4TLocation.TLctTWahCode
GROUP BY VS4TInventory.TInvDate, VS4TInventoryMB.TInMTPdtCode, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtTUntCode, VS4TInventoryMB.TInMTLctCode, VS4TWarehouse.TWahCode, VS4TInventoryType.TInTAlias, VS4TInventoryMB.TInMFlag1, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TInventoryType.TInTName, VS4TInventoryType.TInTName2, VS4TInventoryType.TInTDescription
GO

CREATE VIEW VS4VInventoryLOT
AS 
SELECT VS4TProduct.*, VS4TProductSection.TPSEName, VS4TProductLine.TPdLName, VS4TPOS.TPOSPrice, VS4TAP.TAPNName, VS4TProduct2.*, VS4TPOS.TPOSSaleCount, VS4TBrand.TBndCode, VS4TBrand.TBndName, VS4TProductType.TPTTCode, VS4TProductType.TPTTName, VS4TProductType.TPTTDocCode, VS4TProductCalcTyp.TPCTAlias, VS4TProductCalcTyp.TPCTName, VS4TProductPURType.TPPuCode, VS4TProductPURType.TPPuName, VS4TProductGroup1.TPG1Code, VS4TProductGroup1.TPG1Name, VS4TProductGroup2.TPG2Code, VS4TProductGroup2.TPG2Name, VS4TProductGroup3.TPG3Code, VS4TProductGroup3.TPG3Name, VS4TProductGroup4.TPG4Code, VS4TProductGroup4.TPG4Name, VS4TInventoryLOT.*, VS4TInventory.TInvApproveStatus, VS4TInventory.TInvCancelStatus
FROM (((VS4TProductSection RIGHT JOIN (VS4TProductType INNER JOIN (VS4TProductPURType RIGHT JOIN (VS4TProductCalcTyp RIGHT JOIN (((((((VS4TProduct LEFT JOIN VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code) LEFT JOIN VS4TBrand ON VS4TProduct.TPdtTBndCode = VS4TBrand.TBndCode) LEFT JOIN VS4TProductGroup2 ON VS4TProduct.TPdtTPG2Code = VS4TProductGroup2.TPG2Code) LEFT JOIN VS4TProductGroup3 ON VS4TProduct.TPdtTPG3Code = VS4TProductGroup3.TPG3Code) LEFT JOIN VS4TProductGroup4 ON VS4TProduct.TPdtTPG4Code = VS4TProductGroup4.TPG4Code) LEFT JOIN VS4TProductLine ON VS4TProduct.TPdtTPDLCode = VS4TProductLine.TPdLCode) LEFT JOIN VS4TAP ON VS4TProduct.TPdtTAPNCode = VS4TAP.TAPNCode) ON VS4TProductCalcTyp.TPCTAlias = VS4TProduct.TPdtTPCTAlias) ON VS4TProductPURType.TPPuCode = VS4TProduct.TPdtTPPuCode) ON VS4TProductType.TPTTCode = VS4TProduct.TPdtTPTTCode) ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode) INNER JOIN (VS4TInventory RIGHT JOIN (VS4TInventoryLOT LEFT JOIN VS4TInventoryMB ON (VS4TInventoryLOT.TIMCReceiveNo = VS4TInventoryMB.TInMTInvNo) AND (VS4TInventoryLOT.TIMCReceiveLn = VS4TInventoryMB.TInMLn)) ON VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo) ON VS4TProduct.TPdtCode = VS4TInventoryLOT.TIMCTPdtCode) LEFT JOIN VS4TProduct2 ON VS4TProduct.TPdtCode = VS4TProduct2.TPd2TPdtCode) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode
WHERE (((VS4TPOS.TPOSType)=0 Or (VS4TPOS.TPOSType) Is Null))
GO

CREATE VIEW VS4VProductSafeH
AS 
SELECT VS4TProductSafeS.*
FROM VS4TProductSafeS LEFT JOIN VS4TBranch ON VS4TProductSafeS.TPSSTBraCode = VS4TBranch.TBraCode
WHERE (((VS4TBranch.TBraTBrTAlias)='HEADOFFICE' Or (VS4TBranch.TBraTBrTAlias) Is Null))
GO

CREATE VIEW VS4VInventoryPOS
AS 
SELECT VS4TInventory.*, VS4TInventoryType.*, VS4TInventoryMB.*, VS4TPOS.*
FROM (VS4TUnit INNER JOIN (VS4TInventoryType INNER JOIN (VS4TProduct INNER JOIN (VS4TInventory INNER JOIN VS4TInventoryMB ON VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo) ON VS4TProduct.TPdtCode = VS4TInventoryMB.TInMTPdtCode) ON VS4TInventoryType.TInTAlias = VS4TInventory.TInvTInTAlias) ON VS4TUnit.TUntCode = VS4TProduct.TPdtTUntCode) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode
GO

CREATE VIEW VS4VInventoryR
AS 
SELECT VS4TInventory.TInvNo, VS4TInventory.TInvDate, VS4TInventoryMB.TInMTPdtCode, VS4TInventoryMB.TInMQuantityBase, VS4TInventoryMB.TInMTUntCode, VS4TInventoryMB.TInMInQuantity, VS4TInventoryMB.TInMOutQuantity, VS4TInventoryMB.TInMAmouQuantity, VS4TInventoryMB.TInMInQuantity2, VS4TInventoryMB.TInMOutQuantity2, VS4TInventoryMB.TInMAmouQuantity2, VS4TInventoryMB.TInMInQuantity3, VS4TInventoryMB.TInMOutQuantity3, VS4TInventoryMB.TInMAmouQuantity3, VS4TInventoryMB.TInMAmount, VS4TInventoryMB.TInMTLctCode, VS4TLocation.TLctTBraCode, VS4TBranch.TBraName, VS4TProduct.TPdtName, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TProduct.TPdtTPTTCode, VS4TInventoryLOT.TIMCTUntCode, VS4TInventoryLOT.TIMCUnitRatio, VS4TInventoryMB.TInMCustom1, VS4TInventoryMB.TInMSerialNo, VS4TInventoryMB.TInMLotNo, VS4TInventoryMB.TInMLotDate, VS4TInventoryLOT.TIMCTCgTID, VS4TInventoryLOT.TIMCUnitCost, VS4TPOS.TPOSPrice, VS4TInventoryMB.TInMStatus, VS4TInventoryLOT.TIMCQAStatus, VS4TProject.TPrjMode, VS4TInventory.TInvTPrjCode, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtTPSECode, VS4TProduct.TPdtTPG1Code, VS4TProduct.TPdtTPG2Code, VS4TProduct.TPdtTPG3Code, VS4TProduct.TPdtTPG4Code, VS4TProduct.TPdtTPS2Code, VS4TProduct.TPdtTPS3Code, VS4TProduct.TPdtTPS4Code, VS4TInventory.TInvTDivCode, VS4TInventory.TInvTDepCode, VS4TInventory.TInvTSecCode, VS4TInventory.TInvTJobNo, VS4TInventoryLOT.TIMCTAPNCode, VS4TInventory.TInvRefNo, VS4TInventoryLOT.TIMCInvoiceNo, VS4TInventoryMB.TInMTInTAlias, VS4TInventory.TInvApproveStatus, VS4TInventory.TInvCancelStatus, VS4TWarehouse.TWahCode, VS4TInventory.TInvTInTAlias, VS4TWarehouse.TWahName, VS4TLocation.TLctName, VS4TInventoryLOT.TIMCPremiumNote, VS4TInventoryLOT.TIMCTPODNo, VS4TInventoryLOT.TIMCTPOBLn, VS4TInventoryLOT.TIMCTPDELn, VS4TInventoryMB.TInMTSODNo, VS4TInventoryMB.TInMTSOBLn, VS4TInventoryMB.TInMTMDSLn, VS4TInventoryMB.TInMSourceNo, VS4TInventoryMB.TInMSourceLn, VS4TProduct.TPdtCode, VS4TProduct.TPdtBarcode, VS4TInventoryMB.TInMScrapLevel, VS4TProduct.TPdtFlag1, VS4TInventoryLOT.TIMCAccountLevel, VS4TInventoryLOT.TIMCJobCode, VS4TProduct.TPdtLastBalDate
FROM VS4TProject RIGHT JOIN ((VS4TProduct LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) INNER JOIN ((VS4TInventory LEFT JOIN VS4TBranch ON VS4TInventory.TInvTBraCode = VS4TBranch.TBraCode) INNER JOIN (((VS4TInventoryMB LEFT JOIN VS4TLocation ON VS4TInventoryMB.TInMTLctCode = VS4TLocation.TLctCode) LEFT JOIN VS4TWarehouse ON VS4TLocation.TLctTWahCode = VS4TWarehouse.TWahCode) LEFT JOIN VS4TInventoryLOT ON (VS4TInventoryMB.TInMLotDate = VS4TInventoryLOT.TIMCLotDate) AND (VS4TInventoryMB.TInMLotNo = VS4TInventoryLOT.TIMCLotNo) AND (VS4TInventoryMB.TInMSerialNo = VS4TInventoryLOT.TIMCSerialNo) AND (VS4TInventoryMB.TInMCustom1 = VS4TInventoryLOT.TIMCCustom1) AND (VS4TInventoryMB.TInMTPdtCode = VS4TInventoryLOT.TIMCTPdtCode)) ON VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo) ON VS4TProduct.TPdtCode = VS4TInventoryMB.TInMTPdtCode) ON VS4TProject.TPrjCode = VS4TInventory.TInvTPrjCode
GO

CREATE VIEW VS4VInventoryRP
AS 
SELECT Vs4TInventoryP.TInvNo, Vs4TInventoryP.TInvDate, Vs4TInventoryMBP.TInMTPdtCode, Vs4TInventoryMBP.TInMQuantityBase, Vs4TInventoryMBP.TInMTUntCode, Vs4TInventoryMBP.TInMInQuantity, Vs4TInventoryMBP.TInMOutQuantity, Vs4TInventoryMBP.TInMAmouQuantity, Vs4TInventoryMBP.TInMInQuantity2, Vs4TInventoryMBP.TInMOutQuantity2, Vs4TInventoryMBP.TInMAmouQuantity2, Vs4TInventoryMBP.TInMInQuantity3, Vs4TInventoryMBP.TInMOutQuantity3, Vs4TInventoryMBP.TInMAmouQuantity3, Vs4TInventoryMBP.TInMAmount, Vs4TInventoryMBP.TInMTLctCode, VS4TLocation.TLctTBraCode, VS4TBranch.TBraName, VS4TProduct.TPdtName, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TProduct.TPdtTPTTCode, Vs4TInventoryLOTP.TIMCTUntCode, Vs4TInventoryLOTP.TIMCUnitRatio, Vs4TInventoryMBP.TInMCustom1, Vs4TInventoryMBP.TInMSerialNo, Vs4TInventoryMBP.TInMLotNo, Vs4TInventoryMBP.TInMLotDate, Vs4TInventoryLOTP.TIMCTCgTID, Vs4TInventoryLOTP.TIMCUnitCost, VS4TPOS.TPOSPrice, Vs4TInventoryMBP.TInMStatus, Vs4TInventoryLOTP.TIMCQAStatus, VS4TProject.TPrjMode, Vs4TInventoryP.TInvTPrjCode, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtTPSECode, VS4TProduct.TPdtTPG1Code, VS4TProduct.TPdtTPG2Code, VS4TProduct.TPdtTPG3Code, VS4TProduct.TPdtTPG4Code, VS4TProduct.TPdtTPS2Code, VS4TProduct.TPdtTPS3Code, VS4TProduct.TPdtTPS4Code, Vs4TInventoryP.TInvTDivCode, Vs4TInventoryP.TInvTDepCode, Vs4TInventoryP.TInvTSecCode, Vs4TInventoryP.TInvTJobNo, Vs4TInventoryLOTP.TIMCTAPNCode, Vs4TInventoryP.TInvRefNo, Vs4TInventoryLOTP.TIMCInvoiceNo, Vs4TInventoryMBP.TInMTInTAlias, Vs4TInventoryP.TInvApproveStatus, Vs4TInventoryP.TInvCancelStatus, VS4TWarehouse.TWahCode, Vs4TInventoryP.TInvTInTAlias, VS4TWarehouse.TWahName, VS4TLocation.TLctName, Vs4TInventoryLOTP.TIMCPremiumNote, Vs4TInventoryLOTP.TIMCTPODNo, Vs4TInventoryLOTP.TIMCTPOBLn, Vs4TInventoryLOTP.TIMCTPDELn, Vs4TInventoryMBP.TInMTSODNo, Vs4TInventoryMBP.TInMTSOBLn, Vs4TInventoryMBP.TInMTMDSLn, Vs4TInventoryMBP.TInMSourceNo, Vs4TInventoryMBP.TInMSourceLn, VS4TProduct.TPdtCode, VS4TProduct.TPdtBarcode, Vs4TInventoryMBP.TInMScrapLevel, VS4TProduct.TPdtFlag1, Vs4TInventoryLOTP.TIMCAccountLevel, Vs4TInventoryLOTP.TIMCJobCode, VS4TProduct.TPdtLastBalDate
FROM VS4TProject RIGHT JOIN ((VS4TProduct LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) INNER JOIN ((Vs4TInventoryP LEFT JOIN VS4TBranch ON Vs4TInventoryP.TInvTBraCode = VS4TBranch.TBraCode) INNER JOIN (((Vs4TInventoryMBP LEFT JOIN VS4TLocation ON Vs4TInventoryMBP.TInMTLctCode = VS4TLocation.TLctCode) LEFT JOIN VS4TWarehouse ON VS4TLocation.TLctTWahCode = VS4TWarehouse.TWahCode) LEFT JOIN Vs4TInventoryLOTP ON (Vs4TInventoryMBP.TInMTPdtCode = Vs4TInventoryLOTP.TIMCTPdtCode) AND (Vs4TInventoryMBP.TInMCustom1 = Vs4TInventoryLOTP.TIMCCustom1) AND (Vs4TInventoryMBP.TInMSerialNo = Vs4TInventoryLOTP.TIMCSerialNo) AND (Vs4TInventoryMBP.TInMLotNo = Vs4TInventoryLOTP.TIMCLotNo) AND (Vs4TInventoryMBP.TInMLotDate = Vs4TInventoryLOTP.TIMCLotDate)) ON Vs4TInventoryP.TInvNo = Vs4TInventoryMBP.TInMTInvNo) ON VS4TProduct.TPdtCode = Vs4TInventoryMBP.TInMTPdtCode) ON VS4TProject.TPrjCode = Vs4TInventoryP.TInvTPrjCode
GO

CREATE VIEW VS4VInventPDE
AS 
SELECT VS4TInventory.TInvNo, VS4TInventoryMB.TInMTPdtCode, VS4TProduct.TPdtName, VS4TInventory.TInvTInTAlias, Sum(VS4TInventoryMB.TInMAmouQuantity) AS TInMAmouQuantity, VS4TProduct.TPdtTUntCode, Sum(VS4TInventoryMB.TInMAmouQuantity2) AS TInMAmouQuantity2, VS4TProduct.TPdtTUntCode2, Sum(VS4TInventoryMB.TInMAmouQuantity3) AS TInMAmouQuantity3, VS4TProduct.TPdtTUntCode3, Sum(VS4TInventoryMB.TInMQuantityBase) AS TInMQuantityBase, VS4TInventoryMB.TInMTUntCode, VS4TInventory.TInvRefNo, VS4TInventory.TInvRefDate, VS4TInventory.TInvRefNo2, VS4TInventory.TInvRefDate2, VS4TProduct.TPdtTAPNCode, VS4TInventoryLOT.TIMCTPODNo, VS4TInventoryLOT.TIMCTPOBLn, VS4TInventoryLOT.TIMCTUntCode, VS4TInventoryLOT.TIMCUnitRatio, VS4TInventoryMB.TInMUnitRatio, VS4TInventory.TInvTARNCode, VS4TInventory.TInvRefNo3, VS4TInventoryLOT.TIMCUnitCost, VS4TInventoryLOT.TIMCInputCost, VS4TInventoryLOT.TIMCPerQuantity
FROM VS4TProduct INNER JOIN (VS4TInventory INNER JOIN (VS4TInventoryMB LEFT JOIN VS4TInventoryLOT ON (VS4TInventoryMB.TInMTPdtCode = VS4TInventoryLOT.TIMCTPdtCode) AND (VS4TInventoryMB.TInMCustom1 = VS4TInventoryLOT.TIMCCustom1) AND (VS4TInventoryMB.TInMSerialNo = VS4TInventoryLOT.TIMCSerialNo) AND (VS4TInventoryMB.TInMLotNo = VS4TInventoryLOT.TIMCLotNo) AND (VS4TInventoryMB.TInMLotDate = VS4TInventoryLOT.TIMCLotDate)) ON VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo) ON VS4TProduct.TPdtCode = VS4TInventoryMB.TInMTPdtCode
GROUP BY VS4TInventory.TInvNo, VS4TInventoryMB.TInMTPdtCode, VS4TProduct.TPdtName, VS4TInventory.TInvTInTAlias, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TInventoryMB.TInMTUntCode, VS4TInventory.TInvRefNo, VS4TInventory.TInvRefDate, VS4TInventory.TInvRefNo2, VS4TInventory.TInvRefDate2, VS4TProduct.TPdtTAPNCode, VS4TInventoryLOT.TIMCTPODNo, VS4TInventoryLOT.TIMCTPOBLn, VS4TInventoryLOT.TIMCTUntCode, VS4TInventoryLOT.TIMCUnitRatio, VS4TInventoryMB.TInMUnitRatio, VS4TInventory.TInvTARNCode, VS4TInventory.TInvRefNo3, VS4TInventoryLOT.TIMCUnitCost, VS4TInventoryLOT.TIMCInputCost, VS4TInventoryLOT.TIMCPerQuantity, VS4TInventory.TInvApproveStatus, VS4TInventory.TInvCancelStatus
HAVING (((VS4TInventory.TInvTInTAlias)='LOTIN' Or (VS4TInventory.TInvTInTAlias)='LOTINPREMIUM' Or (VS4TInventory.TInvTInTAlias)='LOTINPR' Or (VS4TInventory.TInvTInTAlias)='LOTINPOP' Or (VS4TInventory.TInvTInTAlias)='RECEIVEFGBUILTOUT') AND ((VS4TInventory.TInvApproveStatus)=1) AND ((VS4TInventory.TInvCancelStatus)=0))
GO

CREATE VIEW VS4VInventory
AS 
SELECT VS4TInventory.*, VS4TInventoryMB.*, VS4TWarehouse.TWahName, VS4TLocation.TLctName, VS4TSection.TSecName, VS4TDepartment.TDepName, VS4TDivision.TDivName, VS4TBranch.TBraName, VS4TProject.TPrjMode, VS4TProductType.TPTTName, VS4TInventoryType.TInTName, VS4TInventoryType.TInTDescription, VS4TLocation.TLctTBraCode, VS4TAR.TARNName, VS4TAP.TAPNName, VS4TInventoryType.TInTSort, VS4TPOS.TPOSPrice, VS4TJob.TJobCode, VS4TJob.TJobCustomerName, VS4TJob.TJobNo, VS4TJobMB.TJbMTPdtCode, VS4TJobMB.TJbMProductName, VS4TProduct.TPdtBarcode, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtFactoryCode, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TPOS.TPOSPackText1, VS4TPOS.TPOSPackText2, VS4TPOS.TPOSPackAlias1, VS4TProduct.TPdtTPTTCode, VS4TProduct.TPdtTAPNCode, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtTPSECode, VS4TProduct.TPdtTPS2Code, VS4TProduct.TPdtTPS3Code, VS4TProduct.TPdtTPS4Code, VS4TProduct.TPdtTPG1Code, VS4TProduct.TPdtTPG2Code, VS4TProduct.TPdtTPG3Code, VS4TProduct.TPdtTPG4Code, VS4TProduct.TPdtTBndCode, VS4TProduct.TPdtImage1, VS4TProduct.TPdtTPCTAlias, VS4TProduct.TPdtOrderPoint, VS4TProduct.TPdtMaxUsePerDay, VS4TProduct.TPdtAvgUsePerDay, VS4TProduct.TPdtStockQuantity, VS4TProduct.TPdtEOQ, VS4TProduct.TPdtFirstDate, VS4TProduct.TPdtLastMoveDate, VS4TProduct.TPdtLastCost, VS4TProduct.TPdtStdCostCode, VS4TProduct.TPdtAverageCost, VS4TProduct.TPdtSerialType, VS4TProduct.TPdtSlowDay, VS4TProduct.TPdtDeadDay, VS4TProduct.TPdtBackDayCalc, VS4TProduct.TPdtGroupReport, VS4TPRMB.TPRMTPdtCode, VS4TPRMB.TPRMProductName, VS4TPRMB.TPRMCustom1, VS4TPRMB.TPRMCustom2, VS4TPRMB.TPRMCustom3, VS4TPRMB.TPRMUseDate, VS4TPRMB.TPRMUseType, VS4TPRMB.TPRMTUntCode, VS4TPRMB.TPRMQuantity, VS4TPRMB.TPRMQuantity2, VS4TPRMB.TPRMQuantity3, VS4TPR.TPRDNo, VS4TPR.TPRDTPRBCode, VS4TPR.TPRDDate, VS4TPR.TPRDRefNo, VS4TPR.TPRDRequestCode, VS4TPR.TPRDRequestBy, VS4TPR.TPRDDescription, VS4TPR.TPRDTBraCode, VS4TPR.TPRDTDivCode, VS4TWarehouse_1.TWahCode AS VInMFromTWahCode, VS4TWarehouse.TWahCode AS VInMToTWahCode, VS4TWarehouse.TWahCode, VS4TJobMB.TJbMQuantity, VS4TJobMB.TJbMTUntCode, VS4TJobMB.TJbMQuantity2, VS4TJobMB.TJbMQuantity3, VS4TProductSection.TPSECode AS VInMTPSECode, VS4TProductSection.TPSEName AS VInMTPSEName, VS4TJobMB.TJbMCustom1, VS4TJobMB.TJbMCustom2, VS4TJobMB.TJbMCustom3, VS4TSOMB.TSOBPOSName, VS4TProduct.TPdtTPPuCode, VS4TInventoryLOT.TIMCJobCode, VS4TInventoryLOT.TIMCCustom2, VS4TInventoryLOT.TIMCCustom3, VS4TInventoryLOT.TIMCCustom4, VS4TInventoryLOT.TIMCCustom5, VS4TInventoryLOT.TIMCIsPremium, VS4TInventoryLOT.TIMCPremiumNote, VS4TInventoryLOT.TIMCLotNo2, VS4TInventoryLOT.TIMCGrade, VS4TInventoryLOT.TIMCNoExpire, VS4TInventoryLOT.TIMCExpireDate, VS4TInventoryLOT.TIMCTCgTID, VS4TInventoryLOT.TIMCInputCost, VS4TInventoryLOT.TIMCLastUnitCost, VS4TInventoryLOT.TIMCPerQuantity, VS4TInventoryLOT.TIMCUnitCalc, VS4TInventoryLOT.TIMCUnitCost, VS4TInventoryLOT.TIMCReserve, VS4TInventoryLOT.TIMCCostCode, VS4TInventoryLOT.TIMCTPODNo, VS4TInventoryLOT.TIMCTPOBLn, VS4TInventoryLOT.TIMCTPDELn, VS4TInventoryLOT.TIMCConsignFSDate, VS4TInventoryLOT.TIMCConsignLSDate, VS4TInventoryType.TInTInputCost, VS4TInventoryLOT.TIMCReceiveNo, VS4TInventoryLOT.TIMCReceiveLn, VS4VProductSafeH.TPSSStockMin, VS4TInventoryLOT.TIMCQAStatus, VS4TInventoryLOT.TIMCQANote, VS4TAR.TARNAddressBill, VS4TInventoryLOT.TIMCTAPNCode, VS4TInventoryLOT.TIMCInvoiceNo, VS4TInventoryLOT.TIMCInvoiceDate, VS4TInventoryLOT.TIMCTUntCode, VS4TInventoryLOT.TIMCUnitRatio, VS4TProduct.TPdtFlag1, VS4TProduct.TPdtCode, VS4VProductGroup.TPdLName, VS4VProductGroup.TPSEName, VS4VProductGroup.TPG1Name, VS4TInventoryLOT.TIMCAccountLevel, VS4TProduct.TPdtLastBalDate, VS4TPOS.TPOSPackAlias2
FROM VS4TInventoryType INNER JOIN (VS4TSO RIGHT JOIN ((((((VS4TProduct LEFT JOIN VS4TProductType ON VS4TProduct.TPdtTPTTCode = VS4TProductType.TPTTCode) LEFT JOIN VS4VProductGroup ON VS4TProduct.TPdtCode = VS4VProductGroup.VPdtCode) LEFT JOIN VS4VProductSafeH ON VS4TProduct.TPdtCode = VS4VProductSafeH.TPSSTPdtCode) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) INNER JOIN ((((((((((((VS4TInventory LEFT JOIN VS4TDepartment ON VS4TInventory.TInvTDepCode = VS4TDepartment.TDepCode) LEFT JOIN VS4TDivision ON VS4TInventory.TInvTDivCode = VS4TDivision.TDivCode) LEFT JOIN VS4TBranch ON VS4TInventory.TInvTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TProject ON VS4TInventory.TInvTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TJob ON VS4TInventory.TInvTJobNo = VS4TJob.TJobNo) LEFT JOIN VS4TJobMB ON (VS4TInventory.TInvTJobNo = VS4TJobMB.TJbMTJobNo) AND (VS4TInventory.TInvTJbMLn = VS4TJobMB.TJbMLn)) LEFT JOIN VS4TPR ON VS4TInventory.TInvRefNo = VS4TPR.TPRDNo) LEFT JOIN VS4TProduct AS VS4TProduct_1 ON VS4TJobMB.TJbMTPdtCode = VS4TProduct_1.TPdtCode) LEFT JOIN VS4TProductSection ON VS4TProduct_1.TPdtTPSECode = VS4TProductSection.TPSECode) LEFT JOIN VS4TAR ON VS4TInventory.TInvTARNCode = VS4TAR.TARNCode) LEFT JOIN VS4TSection ON VS4TInventory.TInvTSecCode = VS4TSection.TSecCode) INNER JOIN (((((((VS4TInventoryMB LEFT JOIN VS4TLocation ON VS4TInventoryMB.TInMTLctCode = VS4TLocation.TLctCode) LEFT JOIN VS4TWarehouse ON VS4TLocation.TLctTWahCode = VS4TWarehouse.TWahCode) LEFT JOIN VS4TPRMB ON (VS4TInventoryMB.TInMSourceLn = VS4TPRMB.TPRMLn) AND (VS4TInventoryMB.TInMSourceNo = VS4TPRMB.TPRMTPRDNo)) LEFT JOIN VS4TLocation AS VS4TLocation_1 ON VS4TInventoryMB.TInMFromTLctCode = VS4TLocation_1.TLctCode) LEFT JOIN VS4TWarehouse AS VS4TWarehouse_1 ON VS4TLocation_1.TLctTWahCode = VS4TWarehouse_1.TWahCode) LEFT JOIN VS4TSOMB ON (VS4TInventoryMB.TInMTSOBLn = VS4TSOMB.TSOBLn) AND (VS4TInventoryMB.TInMTSODNo = VS4TSOMB.TSOBTSODNo)) LEFT JOIN (VS4TInventoryLOT LEFT JOIN VS4TAP ON VS4TInventoryLOT.TIMCTAPNCode = VS4TAP.TAPNCode) ON (VS4TInventoryMB.TInMTPdtCode = VS4TInventoryLOT.TIMCTPdtCode) AND (VS4TInventoryMB.TInMCustom1 = VS4TInventoryLOT.TIMCCustom1) AND (VS4TInventoryMB.TInMSerialNo = VS4TInventoryLOT.TIMCSerialNo) AND (VS4TInventoryMB.TInMLotNo = VS4TInventoryLOT.TIMCLotNo) AND (VS4TInventoryMB.TInMLotDate = VS4TInventoryLOT.TIMCLotDate)) ON VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo) ON VS4TProduct.TPdtCode = VS4TInventoryMB.TInMTPdtCode) LEFT JOIN VS4TProduct2 ON VS4TProduct.TPdtCode = VS4TProduct2.TPd2TPdtCode) ON VS4TSO.TSODNo = VS4TSOMB.TSOBTSODNo) ON VS4TInventoryType.TInTAlias = VS4TInventory.TInvTInTAlias
GO

CREATE VIEW VS4VInventRecRep
AS 
SELECT VS4TInventory.TInvNo, VS4TInventoryMB.TInMTPdtCode, VS4TProduct.TPdtName, VS4TInventory.TInvTInTAlias, Sum(VS4TInventoryMB.TInMOutQuantity) AS TInMOutQuantity, VS4TProduct.TPdtTUntCode, Sum(VS4TInventoryMB.TInMOutQuantity2) AS TInMOutQuantity2, VS4TProduct.TPdtTUntCode2, Sum(VS4TInventoryMB.TInMOutQuantity3) AS TInMOutQuantity3, VS4TProduct.TPdtTUntCode3, Sum(VS4TInventoryMB.TInMQuantityBase) AS TInMQuantityBase, VS4TInventoryMB.TInMTUntCode
FROM VS4TProduct INNER JOIN (VS4TInventory INNER JOIN VS4TInventoryMB ON VS4TInventory.TInvNo=VS4TInventoryMB.TInMTInvNo) ON VS4TProduct.TPdtCode=VS4TInventoryMB.TInMTPdtCode
GROUP BY VS4TInventory.TInvNo, VS4TInventoryMB.TInMTPdtCode, VS4TProduct.TPdtName, VS4TInventory.TInvTInTAlias, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TInventoryMB.TInMTUntCode
HAVING (((VS4TInventory.TInvTInTAlias)='SENDREPAIR'))
GO

CREATE VIEW VS4VInventSaleFC
AS 
SELECT VS4TInventory.*, VS4TInventoryMB.*, VS4TWarehouse.TWahName, VS4TLocation.TLctName, VS4TPO.*, VS4TProduct.TPdtName, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TBranch.TBraName, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TProduct.TPdtTPSECode, VS4TProductSection.TPSEName, VS4TProduct.TPdtTPG1Code, VS4TProductGroup1.TPG1Name, VS4TProduct.TPdtTPTTCode, VS4TProductType.TPTTName, VS4TProduct.TPdtTPDLCode, VS4TProductLine.TPdLName, VS4TInventoryType.TInTAlias, VS4TInventoryType.TInTName, VS4TInventoryType.TInTGroupType, VS4TInventoryType.TInTCountType, VS4TInventoryType.TInTDescription, VS4TLocation.TLctTBraCode, VS4TWarehouse.TWahCode, VS4TInventoryType.TInTName2
FROM VS4TInventoryType INNER JOIN (((((VS4TProduct LEFT JOIN VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode) LEFT JOIN VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code) LEFT JOIN VS4TProductType ON VS4TProduct.TPdtTPTTCode = VS4TProductType.TPTTCode) LEFT JOIN VS4TProductLine ON VS4TProduct.TPdtTPDLCode = VS4TProductLine.TPdLCode) INNER JOIN (((VS4TInventory LEFT JOIN VS4TBranch ON VS4TInventory.TInvTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TProject ON VS4TInventory.TInvTPrjCode = VS4TProject.TPrjCode) INNER JOIN (((VS4TInventoryMB LEFT JOIN VS4TLocation ON VS4TInventoryMB.TInMTLctCode = VS4TLocation.TLctCode) LEFT JOIN VS4TWarehouse ON VS4TLocation.TLctTWahCode = VS4TWarehouse.TWahCode) LEFT JOIN (VS4TInventoryLOT LEFT JOIN VS4TPO ON VS4TInventoryLOT.TIMCTPODNo = VS4TPO.TPODNo) ON (VS4TInventoryMB.TInMLotDate = VS4TInventoryLOT.TIMCLotDate) AND (VS4TInventoryMB.TInMLotNo = VS4TInventoryLOT.TIMCLotNo) AND (VS4TInventoryMB.TInMSerialNo = VS4TInventoryLOT.TIMCSerialNo) AND (VS4TInventoryMB.TInMCustom1 = VS4TInventoryLOT.TIMCCustom1) AND (VS4TInventoryMB.TInMTPdtCode = VS4TInventoryLOT.TIMCTPdtCode)) ON VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo) ON VS4TProduct.TPdtCode = VS4TInventoryMB.TInMTPdtCode) ON VS4TInventoryType.TInTAlias = VS4TInventory.TInvTInTAlias
WHERE (((VS4TWarehouse.TWahCode)<>'INPROCESS' And (VS4TWarehouse.TWahCode)<>'OUTPROCESS' And (VS4TWarehouse.TWahCode)<>'BORROW' And (VS4TWarehouse.TWahCode)<>'CONSIGN' And (VS4TWarehouse.TWahCode)<>'PURCHASERETURN' And (VS4TWarehouse.TWahCode)<>'SCRAP') AND ((VS4TInventoryMB.TInMStatus)=1) AND ((VS4TInventory.TInvTInTAlias)='SALEOUT') AND ((VS4TInventoryLOT.TIMCTCgTID)=1)) OR (((VS4TInventory.TInvTInTAlias)='SALEOUTPOS'))
GO

CREATE VIEW VS4VInventSaleOut
AS 
SELECT VS4TInventory.TInvNo, VS4TInventoryMB.TInMTPdtCode, VS4TProduct.TPdtName, VS4TInventory.TInvTInTAlias, Sum(VS4TInventoryMB.TInMOutQuantity) AS TInMOutQuantity, VS4TProduct.TPdtTUntCode, Sum(VS4TInventoryMB.TInMOutQuantity2) AS TInMOutQuantity2, VS4TProduct.TPdtTUntCode2, Sum(VS4TInventoryMB.TInMOutQuantity3) AS TInMOutQuantity3, VS4TProduct.TPdtTUntCode3, VS4TInventoryMB.TInMQuantityBase, VS4TInventoryMB.TInMTUntCode
FROM VS4TProduct INNER JOIN (VS4TInventory INNER JOIN VS4TInventoryMB ON VS4TInventory.TInvNo=VS4TInventoryMB.TInMTInvNo) ON VS4TProduct.TPdtCode=VS4TInventoryMB.TInMTPdtCode
GROUP BY VS4TInventory.TInvNo, VS4TInventoryMB.TInMTPdtCode, VS4TProduct.TPdtName, VS4TInventory.TInvTInTAlias, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TInventoryMB.TInMQuantityBase, VS4TInventoryMB.TInMTUntCode
HAVING (((VS4TInventory.TInvTInTAlias)='SALEOUT' Or (VS4TInventory.TInvTInTAlias)='SALEOUTPOS'))
GO

CREATE VIEW VS4VInventSendRep
AS 
SELECT VS4TInventory.TInvNo, VS4TInventoryMB.TInMTPdtCode, VS4TProduct.TPdtName, VS4TInventory.TInvTInTAlias, Sum(VS4TInventoryMB.TInMOutQuantity) AS TInMOutQuantity, VS4TProduct.TPdtTUntCode, Sum(VS4TInventoryMB.TInMOutQuantity2) AS TInMOutQuantity2, VS4TProduct.TPdtTUntCode2, Sum(VS4TInventoryMB.TInMOutQuantity3) AS TInMOutQuantity3, VS4TProduct.TPdtTUntCode3, VS4TInventoryMB.TInMQuantityBase, VS4TInventoryMB.TInMTUntCode
FROM VS4TProduct INNER JOIN (VS4TInventory INNER JOIN VS4TInventoryMB ON VS4TInventory.TInvNo=VS4TInventoryMB.TInMTInvNo) ON VS4TProduct.TPdtCode=VS4TInventoryMB.TInMTPdtCode
GROUP BY VS4TInventory.TInvNo, VS4TInventoryMB.TInMTPdtCode, VS4TProduct.TPdtName, VS4TInventory.TInvTInTAlias, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TInventoryMB.TInMQuantityBase, VS4TInventoryMB.TInMTUntCode
HAVING (((VS4TInventory.TInvTInTAlias)='SENDREPAIR'))
GO

CREATE VIEW VS4VInventSerial
AS 
SELECT VS4TProduct.*, VS4TProduct2.*, VS4TInventoryLOT.*, VS4TProductLine.TPdLName, VS4TProductSection.TPSEName, VS4TProductSec2.TPS2Name, VS4TProductSec3.TPS3Name, VS4TProductSec4.TPS4Name, VS4TProductGroup1.TPG1Name, VS4TProductGroup2.TPG2Name, VS4TProductGroup3.TPG3Name, VS4TProductGroup4.TPG4Name
FROM ((VS4TProductLine RIGHT JOIN ((((((((VS4TProduct LEFT JOIN VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code=VS4TProductSec2.TPS2Code) LEFT JOIN VS4TProductSection ON VS4TProduct.TPdtTPSECode=VS4TProductSection.TPSECode) LEFT JOIN VS4TProductSec3 ON VS4TProduct.TPdtTPS3Code=VS4TProductSec3.TPS3Code) LEFT JOIN VS4TProductSec4 ON VS4TProduct.TPdtTPS4Code=VS4TProductSec4.TPS4Code) LEFT JOIN VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code=VS4TProductGroup1.TPG1Code) LEFT JOIN VS4TProductGroup2 ON VS4TProduct.TPdtTPG2Code=VS4TProductGroup2.TPG2Code) LEFT JOIN VS4TProductGroup3 ON VS4TProduct.TPdtTPG3Code=VS4TProductGroup3.TPG3Code) LEFT JOIN VS4TProductGroup4 ON VS4TProduct.TPdtTPG4Code=VS4TProductGroup4.TPG4Code) ON VS4TProductLine.TPdLCode=VS4TProduct.TPdtTPDLCode) INNER JOIN (VS4TInventSerial LEFT JOIN (VS4TInventoryMB LEFT JOIN VS4TInventoryLOT ON (VS4TInventoryMB.TInMTPdtCode=VS4TInventoryLOT.TIMCTPdtCode) AND (VS4TInventoryMB.TInMCustom1=VS4TInventoryLOT.TIMCCustom1) AND (VS4TInventoryMB.TInMSerialNo=VS4TInventoryLOT.TIMCSerialNo) AND (VS4TInventoryMB.TInMLotNo=VS4TInventoryLOT.TIMCLotNo) AND (VS4TInventoryMB.TInMLotDate=VS4TInventoryLOT.TIMCLotDate)) ON (VS4TInventSerial.TInRTPdtCode=VS4TInventoryMB.TInMTPdtCode) AND (VS4TInventSerial.TInRCustom1=VS4TInventoryMB.TInMCustom1) AND (VS4TInventSerial.TInRSerialNo=VS4TInventoryMB.TInMSerialNo) AND (VS4TInventSerial.TInRLotNo=VS4TInventoryMB.TInMLotNo) AND (VS4TInventSerial.TInRLotDate=VS4TInventoryMB.TInMLotDate)) ON VS4TProduct.TPdtCode=VS4TInventSerial.TInRTPdtCode) LEFT JOIN VS4TProduct2 ON VS4TProduct.TPdtCode=VS4TProduct2.TPd2TPdtCode
GO

CREATE VIEW VS4VInventStock
AS 
SELECT VS4TInventory.*, VS4TInventoryMB.*, VS4TWarehouse.TWahName, VS4TLocation.TLctName, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TInventoryType.TInTName, VS4TInventoryType.TInTDescription, VS4TInventoryType.TInTGroupType, VS4TInventoryType.TInTCountType, VS4TUnit.TUntName, VS4TProductType.TPTTName, VS4TProductLine.TPdLName, VS4TProductSection.TPSEName, VS4TProductSec2.TPS2Name, VS4TProductSec3.TPS3Name, VS4TProductSec4.TPS4Name, VS4TProductGroup1.TPG1Name, VS4TProductGroup2.TPG2Name, VS4TProductGroup3.TPG3Name, VS4TProductGroup4.TPG4Name, VS4TPOS.TPOSPrice, VS4TLocation.TLctDayAlert, VS4TLocation.TLctDayMove, VS4TLocation.TLctTBraCode, VS4TProduct.TPdtCode, VS4TProduct.TPdtBarcode, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtTPTTCode, VS4TProduct.TPdtTPPuCode, VS4TProduct.TPdtFlag1, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtTPSECode, VS4TProduct.TPdtTPS2Code, VS4TProduct.TPdtTPS3Code, VS4TProduct.TPdtTPS4Code, VS4TProduct.TPdtTPG1Code, VS4TProduct.TPdtTPG2Code, VS4TProduct.TPdtTPG3Code, VS4TProduct.TPdtTPG4Code, VS4TProduct.TPdtTPCTAlias, VS4TProduct.TPdtSlowDay, VS4TProduct.TPdtDeadDay, VS4TProduct.TPdtSerialType, VS4TProduct.TPdtOrderPoint, VS4TProduct.TPdtTAPNCode, VS4TProduct.TPdtPurchaseFee, VS4TProduct.TPdtFactoryCode, VS4TInventoryLOT.*, VS4TInventoryLOT.TIMCLastDate AS VLSBLastDate, VS4TWarehouse.TWahCode, VS4TPOS.TPOSPackAlias2, VS4TProduct.TPdtDescription
FROM VS4TUnit INNER JOIN (VS4TInventoryType INNER JOIN ((((((((((((VS4TProduct LEFT JOIN VS4TProductType ON VS4TProduct.TPdtTPTTCode = VS4TProductType.TPTTCode) LEFT JOIN VS4TProductLine ON VS4TProduct.TPdtTPDLCode = VS4TProductLine.TPdLCode) LEFT JOIN VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode) LEFT JOIN VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code) LEFT JOIN VS4TProductSec3 ON VS4TProduct.TPdtTPS3Code = VS4TProductSec3.TPS3Code) LEFT JOIN VS4TProductSec4 ON VS4TProduct.TPdtTPS4Code = VS4TProductSec4.TPS4Code) LEFT JOIN VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code) LEFT JOIN VS4TProductGroup2 ON VS4TProduct.TPdtTPG2Code = VS4TProductGroup2.TPG2Name) LEFT JOIN VS4TProductGroup3 ON VS4TProduct.TPdtTPG3Code = VS4TProductGroup3.TPG3Code) LEFT JOIN VS4TProductGroup4 ON VS4TProduct.TPdtTPG4Code = VS4TProductGroup4.TPG4Code) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) INNER JOIN ((((((VS4TInventory LEFT JOIN VS4TProject ON VS4TInventory.TInvTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TInventory.TInvTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TDivision ON VS4TInventory.TInvTDivCode = VS4TDivision.TDivCode) LEFT JOIN VS4TDepartment ON VS4TInventory.TInvTDepCode = VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TInventory.TInvTSecCode = VS4TSection.TSecCode) INNER JOIN (((VS4TInventoryMB LEFT JOIN VS4TLocation ON VS4TInventoryMB.TInMTLctCode = VS4TLocation.TLctCode) LEFT JOIN VS4TWarehouse ON VS4TLocation.TLctTWahCode = VS4TWarehouse.TWahCode) LEFT JOIN VS4TInventoryLOT ON (VS4TInventoryMB.TInMLotDate = VS4TInventoryLOT.TIMCLotDate) AND (VS4TInventoryMB.TInMLotNo = VS4TInventoryLOT.TIMCLotNo) AND (VS4TInventoryMB.TInMSerialNo = VS4TInventoryLOT.TIMCSerialNo) AND (VS4TInventoryMB.TInMCustom1 = VS4TInventoryLOT.TIMCCustom1) AND (VS4TInventoryMB.TInMTPdtCode = VS4TInventoryLOT.TIMCTPdtCode)) ON VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo) ON VS4TProduct.TPdtCode = VS4TInventoryMB.TInMTPdtCode) ON VS4TInventoryType.TInTAlias = VS4TInventory.TInvTInTAlias) ON VS4TUnit.TUntCode = VS4TProduct.TPdtTUntCode
WHERE (((VS4TInventory.TInvApproveStatus)=1) AND ((VS4TInventory.TInvCancelStatus)=0) AND ((VS4TInventory.TInvDate)>=TPdtLastBalDate) AND ((VS4TInventoryMB.TInMStatus)=1))
GO

CREATE VIEW VS4VInventStockF
AS 
SELECT VS4TInventory.*, VS4TInventoryMB.*, VS4TWarehouse.TWahName, VS4TLocation.TLctName, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TInventoryType.TInTName, VS4TInventoryType.TInTDescription, VS4TInventoryType.TInTGroupType, VS4TInventoryType.TInTCountType, VS4TUnit.TUntName, VS4TProductType.TPTTName, VS4TProductLine.TPdLName, VS4TProductSection.TPSEName, VS4TProductSec2.TPS2Name, VS4TProductSec3.TPS3Name, VS4TProductSec4.TPS4Name, VS4TProductGroup1.TPG1Name, VS4TProductGroup2.TPG2Name, VS4TProductGroup3.TPG3Name, VS4TProductGroup4.TPG4Name, VS4TPOS.TPOSPrice, VS4TLocation.TLctDayAlert, VS4TLocation.TLctDayMove, VS4TLocation.TLctTBraCode, VS4TProduct.TPdtCode, VS4TProduct.TPdtBarcode, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtTPTTCode, VS4TProduct.TPdtTPPuCode, VS4TProduct.TPdtFlag1, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtTPSECode, VS4TProduct.TPdtTPS2Code, VS4TProduct.TPdtTPS3Code, VS4TProduct.TPdtTPS4Code, VS4TProduct.TPdtTPG1Code, VS4TProduct.TPdtTPG2Code, VS4TProduct.TPdtTPG3Code, VS4TProduct.TPdtTPG4Code, VS4TProduct.TPdtTPCTAlias, VS4TProduct.TPdtSlowDay, VS4TProduct.TPdtDeadDay, VS4TProduct.TPdtSerialType, VS4TProduct.TPdtOrderPoint, VS4TProduct.TPdtTAPNCode, VS4TProduct.TPdtPurchaseFee, VS4TProduct.TPdtFactoryCode, VS4TInventoryLOT.*, VS4TInventoryLOT.TIMCLastDate AS VLSBLastDate, VS4TWarehouse.TWahCode, VS4TPOS.TPOSPackAlias2
FROM VS4TUnit INNER JOIN (VS4TInventoryType INNER JOIN ((((((((((((VS4TProduct LEFT JOIN VS4TProductType ON VS4TProduct.TPdtTPTTCode = VS4TProductType.TPTTCode) LEFT JOIN VS4TProductLine ON VS4TProduct.TPdtTPDLCode = VS4TProductLine.TPdLCode) LEFT JOIN VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode) LEFT JOIN VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code) LEFT JOIN VS4TProductSec3 ON VS4TProduct.TPdtTPS3Code = VS4TProductSec3.TPS3Code) LEFT JOIN VS4TProductSec4 ON VS4TProduct.TPdtTPS4Code = VS4TProductSec4.TPS4Code) LEFT JOIN VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code) LEFT JOIN VS4TProductGroup2 ON VS4TProduct.TPdtTPG2Code = VS4TProductGroup2.TPG2Name) LEFT JOIN VS4TProductGroup3 ON VS4TProduct.TPdtTPG3Code = VS4TProductGroup3.TPG3Code) LEFT JOIN VS4TProductGroup4 ON VS4TProduct.TPdtTPG4Code = VS4TProductGroup4.TPG4Code) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) INNER JOIN ((((((VS4TInventory LEFT JOIN VS4TProject ON VS4TInventory.TInvTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TInventory.TInvTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TDivision ON VS4TInventory.TInvTDivCode = VS4TDivision.TDivCode) LEFT JOIN VS4TDepartment ON VS4TInventory.TInvTDepCode = VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TInventory.TInvTSecCode = VS4TSection.TSecCode) INNER JOIN (((VS4TInventoryMB LEFT JOIN VS4TLocation ON VS4TInventoryMB.TInMTLctCode = VS4TLocation.TLctCode) LEFT JOIN VS4TWarehouse ON VS4TLocation.TLctTWahCode = VS4TWarehouse.TWahCode) LEFT JOIN VS4TInventoryLOT ON (VS4TInventoryMB.TInMTPdtCode = VS4TInventoryLOT.TIMCTPdtCode) AND (VS4TInventoryMB.TInMCustom1 = VS4TInventoryLOT.TIMCCustom1) AND (VS4TInventoryMB.TInMSerialNo = VS4TInventoryLOT.TIMCSerialNo) AND (VS4TInventoryMB.TInMLotNo = VS4TInventoryLOT.TIMCLotNo) AND (VS4TInventoryMB.TInMLotDate = VS4TInventoryLOT.TIMCLotDate)) ON VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo) ON VS4TProduct.TPdtCode = VS4TInventoryMB.TInMTPdtCode) ON VS4TInventoryType.TInTAlias = VS4TInventory.TInvTInTAlias) ON VS4TUnit.TUntCode = VS4TProduct.TPdtTUntCode
WHERE (((VS4TInventory.TInvApproveStatus)=1) AND ((VS4TInventory.TInvCancelStatus)=0) AND ((VS4TInventory.TInvDate)>=TPdtLastBalDate) AND ((VS4TInventoryMB.TInMStatus)=1) AND ((VS4TInventoryLOT.TIMCJobCode)='')) OR (((VS4TInventoryLOT.TIMCJobCode) Is Null))
GO

CREATE VIEW VS4VInventStockLC
AS 
SELECT VS4TInventory.*, VS4TInventoryMB.*, VS4TWarehouse.TWahName, VS4TLocation.TLctName, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TInventoryType.TInTName, VS4TInventoryType.TInTDescription, VS4TInventoryType.TInTGroupType, VS4TInventoryType.TInTCountType, VS4TUnit.TUntName, VS4TProductType.TPTTName, VS4TProductLine.TPdLName, VS4TProductSection.TPSEName, VS4TProductSec2.TPS2Name, VS4TProductSec3.TPS3Name, VS4TProductSec4.TPS4Name, VS4TProductGroup1.TPG1Name, VS4TProductGroup2.TPG2Name, VS4TProductGroup3.TPG3Name, VS4TProductGroup4.TPG4Name, VS4TPOS.TPOSPrice, VS4TLocation.TLctDayAlert, VS4TLocation.TLctDayMove, VS4TLocation.TLctTBraCode, VS4TProduct.TPdtCode, VS4TProduct.TPdtBarcode, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtTPTTCode, VS4TProduct.TPdtTPPuCode, VS4TProduct.TPdtFlag1, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtTPSECode, VS4TProduct.TPdtTPS2Code, VS4TProduct.TPdtTPS3Code, VS4TProduct.TPdtTPS4Code, VS4TProduct.TPdtTPG1Code, VS4TProduct.TPdtTPG2Code, VS4TProduct.TPdtTPG3Code, VS4TProduct.TPdtTPG4Code, VS4TProduct.TPdtTPCTAlias, VS4TProduct.TPdtSlowDay, VS4TProduct.TPdtDeadDay, VS4TProduct.TPdtSerialType, VS4TProduct.TPdtOrderPoint, VS4TProduct.TPdtTAPNCode, VS4TProduct.TPdtPurchaseFee, VS4TProduct.TPdtFactoryCode, VS4TWarehouse.TWahCode, VS4TPOS.TPOSPackAlias2
FROM VS4TUnit INNER JOIN (VS4TInventoryType INNER JOIN ((((((((((((VS4TProduct LEFT JOIN VS4TProductType ON VS4TProduct.TPdtTPTTCode = VS4TProductType.TPTTCode) LEFT JOIN VS4TProductLine ON VS4TProduct.TPdtTPDLCode = VS4TProductLine.TPdLCode) LEFT JOIN VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode) LEFT JOIN VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code) LEFT JOIN VS4TProductSec3 ON VS4TProduct.TPdtTPS3Code = VS4TProductSec3.TPS3Code) LEFT JOIN VS4TProductSec4 ON VS4TProduct.TPdtTPS4Code = VS4TProductSec4.TPS4Code) LEFT JOIN VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code) LEFT JOIN VS4TProductGroup2 ON VS4TProduct.TPdtTPG2Code = VS4TProductGroup2.TPG2Name) LEFT JOIN VS4TProductGroup3 ON VS4TProduct.TPdtTPG3Code = VS4TProductGroup3.TPG3Code) LEFT JOIN VS4TProductGroup4 ON VS4TProduct.TPdtTPG4Code = VS4TProductGroup4.TPG4Code) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) INNER JOIN ((((((VS4TInventory LEFT JOIN VS4TProject ON VS4TInventory.TInvTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TInventory.TInvTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TDivision ON VS4TInventory.TInvTDivCode = VS4TDivision.TDivCode) LEFT JOIN VS4TDepartment ON VS4TInventory.TInvTDepCode = VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TInventory.TInvTSecCode = VS4TSection.TSecCode) INNER JOIN ((VS4TInventoryMB LEFT JOIN VS4TLocation ON VS4TInventoryMB.TInMTLctCode = VS4TLocation.TLctCode) LEFT JOIN VS4TWarehouse ON VS4TLocation.TLctTWahCode = VS4TWarehouse.TWahCode) ON VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo) ON VS4TProduct.TPdtCode = VS4TInventoryMB.TInMTPdtCode) ON VS4TInventoryType.TInTAlias = VS4TInventory.TInvTInTAlias) ON VS4TUnit.TUntCode = VS4TProduct.TPdtTUntCode
WHERE (((VS4TWarehouse.TWahCode)<>'BORROW' And (VS4TWarehouse.TWahCode)<>'CONSIGN') AND ((VS4TInventory.TInvDate)>=TPdtLastBalDate) AND ((VS4TInventoryMB.TInMStatus)=1))
GO

CREATE VIEW VS4VInventStockM
AS 
SELECT VS4TInventory.*, VS4TInventoryMB.*, VS4TWarehouse.TWahName, VS4TLocation.TLctName, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TInventoryType.TInTName, VS4TInventoryType.TInTDescription, VS4TInventoryType.TInTGroupType, VS4TInventoryType.TInTCountType, VS4TUnit.TUntName, VS4TProductType.TPTTName, VS4TProductLine.TPdLName, VS4TProductSection.TPSEName, VS4TProductSec2.TPS2Name, VS4TProductSec3.TPS3Name, VS4TProductSec4.TPS4Name, VS4TProductGroup1.TPG1Name, VS4TProductGroup2.TPG2Name, VS4TProductGroup3.TPG3Name, VS4TProductGroup4.TPG4Name, VS4TPOS.TPOSPrice, VS4TLocation.TLctDayAlert, VS4TLocation.TLctDayMove, VS4TLocation.TLctTBraCode, VS4TProduct.TPdtCode, VS4TProduct.TPdtBarcode, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtTPTTCode, VS4TProduct.TPdtTPPuCode, VS4TProduct.TPdtFlag1, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtTPSECode, VS4TProduct.TPdtTPS2Code, VS4TProduct.TPdtTPS3Code, VS4TProduct.TPdtTPS4Code, VS4TProduct.TPdtTPG1Code, VS4TProduct.TPdtTPG2Code, VS4TProduct.TPdtTPG3Code, VS4TProduct.TPdtTPG4Code, VS4TProduct.TPdtTPCTAlias, VS4TProduct.TPdtSlowDay, VS4TProduct.TPdtDeadDay, VS4TProduct.TPdtSerialType, VS4TProduct.TPdtOrderPoint, VS4TProduct.TPdtTAPNCode, VS4TProduct.TPdtPurchaseFee, VS4TProduct.TPdtFactoryCode, VS4TInventoryLOT.*, VS4TInventoryLOT.TIMCLastDate AS VLSBLastDate, VS4TWarehouse.TWahCode, VS4TPOS.TPOSPackAlias2
FROM VS4TUnit INNER JOIN (VS4TInventoryType INNER JOIN ((((((((((((VS4TProduct LEFT JOIN VS4TProductType ON VS4TProduct.TPdtTPTTCode = VS4TProductType.TPTTCode) LEFT JOIN VS4TProductLine ON VS4TProduct.TPdtTPDLCode = VS4TProductLine.TPdLCode) LEFT JOIN VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode) LEFT JOIN VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code) LEFT JOIN VS4TProductSec3 ON VS4TProduct.TPdtTPS3Code = VS4TProductSec3.TPS3Code) LEFT JOIN VS4TProductSec4 ON VS4TProduct.TPdtTPS4Code = VS4TProductSec4.TPS4Code) LEFT JOIN VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code) LEFT JOIN VS4TProductGroup2 ON VS4TProduct.TPdtTPG2Code = VS4TProductGroup2.TPG2Name) LEFT JOIN VS4TProductGroup3 ON VS4TProduct.TPdtTPG3Code = VS4TProductGroup3.TPG3Code) LEFT JOIN VS4TProductGroup4 ON VS4TProduct.TPdtTPG4Code = VS4TProductGroup4.TPG4Code) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) INNER JOIN ((((((VS4TInventory LEFT JOIN VS4TProject ON VS4TInventory.TInvTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TInventory.TInvTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TDivision ON VS4TInventory.TInvTDivCode = VS4TDivision.TDivCode) LEFT JOIN VS4TDepartment ON VS4TInventory.TInvTDepCode = VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TInventory.TInvTSecCode = VS4TSection.TSecCode) INNER JOIN (((VS4TInventoryMB LEFT JOIN VS4TLocation ON VS4TInventoryMB.TInMTLctCode = VS4TLocation.TLctCode) LEFT JOIN VS4TWarehouse ON VS4TLocation.TLctTWahCode = VS4TWarehouse.TWahCode) LEFT JOIN VS4TInventoryLOT ON (VS4TInventoryMB.TInMTPdtCode = VS4TInventoryLOT.TIMCTPdtCode) AND (VS4TInventoryMB.TInMCustom1 = VS4TInventoryLOT.TIMCCustom1) AND (VS4TInventoryMB.TInMSerialNo = VS4TInventoryLOT.TIMCSerialNo) AND (VS4TInventoryMB.TInMLotNo = VS4TInventoryLOT.TIMCLotNo) AND (VS4TInventoryMB.TInMLotDate = VS4TInventoryLOT.TIMCLotDate)) ON VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo) ON VS4TProduct.TPdtCode = VS4TInventoryMB.TInMTPdtCode) ON VS4TInventoryType.TInTAlias = VS4TInventory.TInvTInTAlias) ON VS4TUnit.TUntCode = VS4TProduct.TPdtTUntCode
WHERE (((VS4TInventory.TInvApproveStatus)=1) AND ((VS4TInventory.TInvCancelStatus)=0) AND ((VS4TInventoryMB.TInMStatus)=1))
GO

CREATE VIEW VS4VInventStockP
AS 
SELECT VS4TInventory.*, VS4TInventoryMB.*, VS4TWarehouse.TWahName, VS4TLocation.TLctName, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TInventoryType.TInTName, VS4TInventoryType.TInTDescription, VS4TInventoryType.TInTGroupType, VS4TInventoryType.TInTCountType, VS4TUnit.TUntName, VS4TProductType.TPTTName, VS4TProductLine.TPdLName, VS4TProductSection.TPSEName, VS4TProductSec2.TPS2Name, VS4TProductSec3.TPS3Name, VS4TProductSec4.TPS4Name, VS4TProductGroup1.TPG1Name, VS4TProductGroup2.TPG2Name, VS4TProductGroup3.TPG3Name, VS4TProductGroup4.TPG4Name, VS4TPOS.TPOSPrice, VS4TLocation.TLctDayAlert, VS4TLocation.TLctDayMove, VS4TLocation.TLctTBraCode, VS4TProduct.TPdtCode, VS4TProduct.TPdtBarcode, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtTPTTCode, VS4TProduct.TPdtTPPuCode, VS4TProduct.TPdtFlag1, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtTPSECode, VS4TProduct.TPdtTPS2Code, VS4TProduct.TPdtTPS3Code, VS4TProduct.TPdtTPS4Code, VS4TProduct.TPdtTPG1Code, VS4TProduct.TPdtTPG2Code, VS4TProduct.TPdtTPG3Code, VS4TProduct.TPdtTPG4Code, VS4TProduct.TPdtTPCTAlias, VS4TProduct.TPdtSlowDay, VS4TProduct.TPdtDeadDay, VS4TProduct.TPdtSerialType, VS4TProduct.TPdtOrderPoint, VS4TProduct.TPdtTAPNCode, VS4TProduct.TPdtPurchaseFee, VS4TProduct.TPdtFactoryCode, VS4TInventoryLOT.*, VS4TInventoryLOT.TIMCLastDate AS VLSBLastDate, VS4TWarehouse.TWahCode, VS4TPOS.TPOSPackAlias2, VS4TProduct.TPdtDescription
FROM VS4TUnit INNER JOIN (VS4TInventoryType INNER JOIN ((((((((((((VS4TProduct LEFT JOIN VS4TProductType ON VS4TProduct.TPdtTPTTCode = VS4TProductType.TPTTCode) LEFT JOIN VS4TProductLine ON VS4TProduct.TPdtTPDLCode = VS4TProductLine.TPdLCode) LEFT JOIN VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode) LEFT JOIN VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code) LEFT JOIN VS4TProductSec3 ON VS4TProduct.TPdtTPS3Code = VS4TProductSec3.TPS3Code) LEFT JOIN VS4TProductSec4 ON VS4TProduct.TPdtTPS4Code = VS4TProductSec4.TPS4Code) LEFT JOIN VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code) LEFT JOIN VS4TProductGroup2 ON VS4TProduct.TPdtTPG2Code = VS4TProductGroup2.TPG2Name) LEFT JOIN VS4TProductGroup3 ON VS4TProduct.TPdtTPG3Code = VS4TProductGroup3.TPG3Code) LEFT JOIN VS4TProductGroup4 ON VS4TProduct.TPdtTPG4Code = VS4TProductGroup4.TPG4Code) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) INNER JOIN ((((((VS4TInventory LEFT JOIN VS4TProject ON VS4TInventory.TInvTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TInventory.TInvTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TDivision ON VS4TInventory.TInvTDivCode = VS4TDivision.TDivCode) LEFT JOIN VS4TDepartment ON VS4TInventory.TInvTDepCode = VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TInventory.TInvTSecCode = VS4TSection.TSecCode) INNER JOIN (((VS4TInventoryMB LEFT JOIN VS4TLocation ON VS4TInventoryMB.TInMTLctCode = VS4TLocation.TLctCode) LEFT JOIN VS4TWarehouse ON VS4TLocation.TLctTWahCode = VS4TWarehouse.TWahCode) LEFT JOIN VS4TInventoryLOT ON (VS4TInventoryMB.TInMLotDate = VS4TInventoryLOT.TIMCLotDate) AND (VS4TInventoryMB.TInMLotNo = VS4TInventoryLOT.TIMCLotNo) AND (VS4TInventoryMB.TInMSerialNo = VS4TInventoryLOT.TIMCSerialNo) AND (VS4TInventoryMB.TInMCustom1 = VS4TInventoryLOT.TIMCCustom1) AND (VS4TInventoryMB.TInMTPdtCode = VS4TInventoryLOT.TIMCTPdtCode)) ON VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo) ON VS4TProduct.TPdtCode = VS4TInventoryMB.TInMTPdtCode) ON VS4TInventoryType.TInTAlias = VS4TInventory.TInvTInTAlias) ON VS4TUnit.TUntCode = VS4TProduct.TPdtTUntCode
WHERE (((VS4TInventory.TInvApproveStatus)=1) AND ((VS4TInventory.TInvCancelStatus)=0) AND ((VS4TInventory.TInvDate)>=TPdtLastBalDate) AND ((VS4TInventoryMB.TInMStatus)=1))
GO

CREATE VIEW VS4VInventSumTopA
AS 
SELECT *
FROM VS4VInventory
WHERE (((VS4VInventory.TInvDate)>='1/1/2000' And (VS4VInventory.TInvDate)<'3/3/3333'))
GO

CREATE VIEW VS4VInventSumTop
AS 
SELECT VS4VInventSumTopA.TInMTPdtCode AS TPdtCode, VS4VInventSumTopA.TPdtFactoryCode, VS4VInventSumTopA.TPdtName, Abs(Sum(VS4VInventSumTopA.TInMAmount)) AS TInMAmount, Abs(Sum(VS4VInventSumTopA.TInMAmouQuantity)) AS TInMAmouQuantity, VS4VInventSumTopA.TPdtTUntCode
FROM VS4VInventSumTopA
GROUP BY VS4VInventSumTopA.TInMTPdtCode, VS4VInventSumTopA.TPdtFactoryCode, VS4VInventSumTopA.TPdtName, VS4VInventSumTopA.TPdtTUntCode
GO

CREATE VIEW VS4VISO
AS 
SELECT VS4TISO.*, VS4TDivision.*, VS4TISOGroup.*
FROM VS4TISOGroup INNER JOIN (VS4TISO LEFT JOIN VS4TDivision ON VS4TISO.TISOTDivCode=VS4TDivision.TDivCode) ON VS4TISOGroup.TISGCode=VS4TISO.TISOTISGCode
GO

CREATE VIEW VS4VJob
AS 
SELECT VS4TJob.*, VS4TJobMB.*, VS4TProject.TPrjName, VS4TProjectType.TPjTName, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TSO.TSODNo, VS4TSO.TSODCode, VS4TSO.TSODType, VS4TSO.TSODDate, VS4TSO.TSODDueDate, VS4TSO.TSODRefNo, VS4TSO.TSODRefDate, VS4TSO.TSODTEmpCode, VS4TSO.TSODSaleName, VS4TSO.TSODTARNCode, VS4TSO.TSODContactNote, VS4TSO.TSODContactName, VS4TSO.TSODCustomerName, VS4TSO.TSODCusAddress, VS4TAR.TARNName, VS4TProject.TPrjMode, VS4TJobBook.TJBkName, VS4TProductSection.TPSECode, VS4TProductSection.TPSEName, VS4TSOMB.TSOBTotalArrear, VS4TSOMB.TSOBTotalArrear2, VS4TSOMB.TSOBTotalArrear3, VS4TSOMB.TSOBTotalJobArr, VS4TSOMB.TSOBTotalJobArr2, VS4TSOMB.TSOBTotalJobArr3, VS4TEmpWorkRate.TWRMTarget0, VS4TEmpWorkRate.TWRMTarget1, VS4TSOMB.TSOBType, VS4TSOMB.TSOBGroupName, VS4TSOMB.TSOBFactoryCode, VS4TSOMB.TSOBTLctCode, VS4TSOMB.TSOBPrice, VS4TSOMB.TSOBPerQuantity, VS4TSOMB.TSOBDiscountText, VS4TSOMB.TSOBTaxType, VS4TSOMB.TSOBAcceptError, VS4TSOMB.TSOBUnitCalc, VS4TSOMB.TSOBFreeCode, VS4TSOMB.TSOBIsPremium, VS4TSOMB.TSOBPremiumCost, VS4TSOMB.TSOBDescription, VS4TSO.TSODDescription
FROM VS4TSO RIGHT JOIN ((VS4TProjectType RIGHT JOIN VS4TProject ON VS4TProjectType.TPjTCode = VS4TProject.TPrjTPjTCode) RIGHT JOIN ((VS4TProduct LEFT JOIN VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode) RIGHT JOIN ((VS4TJobBook RIGHT JOIN (((((VS4TJob LEFT JOIN VS4TDepartment ON VS4TJob.TJobTDepCode = VS4TDepartment.TDepCode) LEFT JOIN VS4TDivision ON VS4TJob.TJobTDivCode = VS4TDivision.TDivCode) LEFT JOIN VS4TBranch ON VS4TJob.TJobTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TSection ON VS4TJob.TJobTSecCode = VS4TSection.TSecCode) LEFT JOIN VS4TAR ON VS4TJob.TJobTARNCode = VS4TAR.TARNCode) ON VS4TJobBook.TJBkCode = VS4TJob.TJobTJBkCode) INNER JOIN ((VS4TJobMB LEFT JOIN VS4TSOMB ON (VS4TJobMB.TJbMSourceLn = VS4TSOMB.TSOBLn) AND (VS4TJobMB.TJbMSourceNo = VS4TSOMB.TSOBTSODNo)) LEFT JOIN VS4TEmpWorkRate ON VS4TJobMB.TJbMTWRMCode = VS4TEmpWorkRate.TWRMCode) ON VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo) ON VS4TProduct.TPdtCode = VS4TJobMB.TJbMTPdtCode) ON VS4TProject.TPrjCode = VS4TJob.TJobTPrjCode) ON VS4TSO.TSODNo = VS4TSOMB.TSOBTSODNo
GO

CREATE VIEW VS4VJob2PO
AS 
SELECT VS4TJob.TJobNo, VS4TJob.TJobCode, VS4TPR.*, VS4TPRMB.*, VS4TPO.TPODNo, VS4TPO.TPODType, VS4TPO.TPODDate, VS4TPO.TPODDueDate, VS4TPO.TPODDeliveryDate, VS4TPO.TPODDeliveryTo, VS4TPO.TPODTAPNCode, VS4TPO.TPODSupplierName, VS4TPOMB.*, VS4TPODelivery.*, VS4TJobBook.TJBkName
FROM VS4TPR RIGHT JOIN (VS4TPO RIGHT JOIN (VS4TJobBook RIGHT JOIN (VS4TJob LEFT JOIN ((VS4TPRMB LEFT JOIN VS4TPOMB ON (VS4TPRMB.TPRMTPRDNo = VS4TPOMB.TPOBSourceNo) AND (VS4TPRMB.TPRMLn = VS4TPOMB.TPOBSourceLn)) LEFT JOIN VS4TPODelivery ON (VS4TPOMB.TPOBTPODNo = VS4TPODelivery.TPDETPOBTPODNo) AND (VS4TPOMB.TPOBLn = VS4TPODelivery.TPDETPOBLn)) ON VS4TJob.TJobNo = VS4TPRMB.TPRMTJobNo) ON VS4TJobBook.TJBkCode = VS4TJob.TJobTJBkCode) ON VS4TPO.TPODNo = VS4TPOMB.TPOBTPODNo) ON VS4TPR.TPRDNo = VS4TPRMB.TPRMTPRDNo
GO

CREATE VIEW VS4VJob2SO
AS 
SELECT VS4TSO.TSODNo, VS4TSO.TSODCode, VS4TSO.TSODType, VS4TSO.TSODDate, VS4TSO.TSODDueDate, VS4TSO.TSODRefNo, VS4TSO.TSODRefDate, VS4TSO.TSODDeliveryDate, VS4TSO.TSODTEmpCode, VS4TSO.TSODSaleName, VS4TSO.TSODDeliveryTo, VS4TSO.TSODTARNCode, VS4TSO.TSODContactNote, VS4TSO.TSODContactName, VS4TSO.TSODCustomerName, VS4TSO.TSODDayAvailable, VS4TSOMB.*, VS4TProject.TPrjName, VS4TJob.TJobNo, VS4TJob.TJobCode, VS4TSO.TSODTPrjCode, VS4TJobBook.TJBkName
FROM (VS4TJobBook RIGHT JOIN (VS4TJob LEFT JOIN (VS4TSO LEFT JOIN VS4TProject ON VS4TSO.TSODTPrjCode=VS4TProject.TPrjCode) ON VS4TJob.TJobRefNo=VS4TSO.TSODNo) ON VS4TJobBook.TJBkCode=VS4TJob.TJobTJBkCode) LEFT JOIN VS4TSOMB ON VS4TSO.TSODNo=VS4TSOMB.TSOBTSODNo
GO

CREATE VIEW VS4VJobCapacity
AS 
SELECT VS4TMRPStepName.TSepTSecCode, VS4TSection.TSecName, VS4TMPS.TMPSWeek, Year(TMPSStartDate) AS VJsTYear, Sum(VS4TMPS.TMPSHour) AS TMPSHour, VS4TMPS.TMPSStatus
FROM ((VS4TJobMethod LEFT JOIN VS4TMRPStepName ON VS4TJobMethod.TJStTSepCode = VS4TMRPStepName.TSepCode) LEFT JOIN VS4TSection ON VS4TMRPStepName.TSepTSecCode = VS4TSection.TSecCode) INNER JOIN VS4TMPS ON (VS4TJobMethod.TJStTJbMTJobNo = VS4TMPS.TMPSTJStTJbMTJobNo) AND (VS4TJobMethod.TJStTJbMLn = VS4TMPS.TMPSTJStTJbMLn) AND (VS4TJobMethod.TJStTSpdStep = VS4TMPS.TMPSTJStTSpdStep) AND (VS4TJobMethod.TJStLn = VS4TMPS.TMPSTJStLn)
GROUP BY VS4TMRPStepName.TSepTSecCode, VS4TSection.TSecName, VS4TMPS.TMPSWeek, Year(TMPSStartDate), VS4TMPS.TMPSStatus
HAVING (((VS4TMPS.TMPSStatus)=1))
GO

CREATE VIEW VS4VJobCapacity2
AS 
SELECT VS4VJobCapacity.*, VS4TCapacitySect.*
FROM VS4VJobCapacity LEFT JOIN VS4TCapacitySect ON (VS4VJobCapacity.TMPSWeek = VS4TCapacitySect.TCPSWeek) AND (VS4VJobCapacity.VJsTYear = VS4TCapacitySect.TCPSYear) AND (VS4VJobCapacity.TSepTSecCode = VS4TCapacitySect.TCPSTSecCode)
GO

CREATE VIEW VS4VJobDL
AS 
SELECT VS4TJob.*, VS4TJobDL.*, VS4TJobMB.*, VS4TJobBook.TJBkName, VS4TMRPStepName.TSepName, VS4TSection.TSecName, VS4TJobMethod.*
FROM (VS4TJobBook RIGHT JOIN (VS4TJob LEFT JOIN VS4TSO ON VS4TJob.TJobRefNo=VS4TSO.TSODNo) ON VS4TJobBook.TJBkCode=VS4TJob.TJobTJBkCode) INNER JOIN (VS4TJobMB LEFT JOIN (((VS4TJobDL LEFT JOIN VS4TMRPStepName ON VS4TJobDL.TJDLTSepCode=VS4TMRPStepName.TSepCode) LEFT JOIN VS4TSection ON VS4TMRPStepName.TSepTSecCode=VS4TSection.TSecCode) LEFT JOIN VS4TJobMethod ON (VS4TJobDL.TJDLTPdtCode=VS4TJobMethod.TJStTPdtCode) AND (VS4TJobDL.TJDLLevel=VS4TJobMethod.TJStLevel) AND (VS4TJobDL.TJDLTSpdStep=VS4TJobMethod.TJStTSpdStep) AND (VS4TJobDL.TJDLTJbMLn=VS4TJobMethod.TJStTJbMLn) AND (VS4TJobDL.TJDLTJbMTJobNo=VS4TJobMethod.TJStTJbMTJobNo)) ON (VS4TJobMB.TJbMTJobNo=VS4TJobDL.TJDLTJbMTJobNo) AND (VS4TJobMB.TJbMLn=VS4TJobDL.TJDLTJbMLn)) ON VS4TJob.TJobNo=VS4TJobMB.TJbMTJobNo
GO

CREATE VIEW VS4VJobH
AS 
SELECT VS4TJob.*, VS4TProject.TPrjName, VS4TProjectType.TPjTName, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TSO.TSODNo, VS4TSO.TSODCode, VS4TSO.TSODType, VS4TSO.TSODDate, VS4TSO.TSODDueDate, VS4TSO.TSODRefNo, VS4TSO.TSODRefDate, VS4TSO.TSODTEmpCode, VS4TSO.TSODSaleName, VS4TSO.TSODTARNCode, VS4TSO.TSODContactNote, VS4TSO.TSODContactName, VS4TSO.TSODCustomerName, VS4TSO.TSODCusAddress, VS4TAR.TARNName, VS4TProject.TPrjMode, VS4TJobBook.TJBkName, VS4TSO.TSODDeliveryDate
FROM (VS4TProjectType RIGHT JOIN VS4TProject ON VS4TProjectType.TPjTCode = VS4TProject.TPrjTPjTCode) RIGHT JOIN (VS4TJobBook RIGHT JOIN ((((((VS4TJob LEFT JOIN VS4TDepartment ON VS4TJob.TJobTDepCode = VS4TDepartment.TDepCode) LEFT JOIN VS4TDivision ON VS4TJob.TJobTDivCode = VS4TDivision.TDivCode) LEFT JOIN VS4TBranch ON VS4TJob.TJobTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TSection ON VS4TJob.TJobTSecCode = VS4TSection.TSecCode) LEFT JOIN VS4TAR ON VS4TJob.TJobTARNCode = VS4TAR.TARNCode) LEFT JOIN VS4TSO ON VS4TJob.TJobRefNo = VS4TSO.TSODNo) ON VS4TJobBook.TJBkCode = VS4TJob.TJobTJBkCode) ON VS4TProject.TPrjCode = VS4TJob.TJobTPrjCode
GO

CREATE VIEW VS4VJobMaterial
AS 
SELECT VS4TJob.*, VS4TJobMB.*, VS4TJobMaterial.*, VS4TProduct.TPdtImage1, VS4TJobBook.TJBkName, VS4TProduct_1.TPdtStandardCost AS VPdtStandardCost, VS4TProduct.TPdtStandardCost, VS4TProductSection.TPSECode, VS4TProductSection.TPSEName, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct_1.TPdtName AS VJmtName, VS4TProduct_1.TPdtName2 AS VJmtName2, VS4TJobMethod.TJStStartDate, VS4TJobMethod.TJStEndDate, VS4TMRPStepName.TSepCode, VS4TMRPStepName.TSepName, VS4TMRPStepName.TSepTSecCode, VS4TJobMethod.TJStTJPDNo, VS4TSection.TSecName, VS4TMRPStepName.TSepTLctCode
FROM VS4TProductSection RIGHT JOIN ((VS4TJobBook RIGHT JOIN VS4TJob ON VS4TJobBook.TJBkCode = VS4TJob.TJobTJBkCode) INNER JOIN ((VS4TJobMB LEFT JOIN VS4TProduct ON VS4TJobMB.TJbMTPdtCode = VS4TProduct.TPdtCode) INNER JOIN (((VS4TJobMaterial LEFT JOIN VS4TProduct AS VS4TProduct_1 ON VS4TJobMaterial.TJMtProductCode = VS4TProduct_1.TPdtCode) LEFT JOIN VS4TJobMethod ON (VS4TJobMaterial.TJMtTJstLn = VS4TJobMethod.TJStLn) AND (VS4TJobMaterial.TJMtLevel = VS4TJobMethod.TJStLevel) AND (VS4TJobMaterial.TJMtTSpdStep = VS4TJobMethod.TJStTSpdStep) AND (VS4TJobMaterial.TJMtTJbMLn = VS4TJobMethod.TJStTJbMLn) AND (VS4TJobMaterial.TJMtTJbMTJobNo = VS4TJobMethod.TJStTJbMTJobNo)) LEFT JOIN (VS4TMRPStepName LEFT JOIN VS4TSection ON VS4TMRPStepName.TSepTSecCode = VS4TSection.TSecCode) ON VS4TJobMaterial.TJMtTSepCode = VS4TMRPStepName.TSepCode) ON (VS4TJobMB.TJbMLn = VS4TJobMaterial.TJMtTJbMLn) AND (VS4TJobMB.TJbMTJobNo = VS4TJobMaterial.TJMtTJbMTJobNo)) ON VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo) ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode
GO

CREATE VIEW VS4VStock
AS 
SELECT Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtTPTTCode, Vs4VInventStock.TPdtTPPuCode, Vs4VInventStock.TPdtFlag1, Sum(Vs4VInventStock.TInMInQuantity) AS TInMInQuantity, Sum(Vs4VInventStock.TInMOutQuantity) AS TInMOutQuantity, Sum(Vs4VInventStock.TInMAmouQuantity) AS TInMAmouQuantity, Vs4VInventStock.TPdtTUntCode, Sum(Vs4VInventStock.TInMInQuantity2) AS TInMInQuantity2, Sum(Vs4VInventStock.TInMOutQuantity2) AS TInMOutQuantity2, Sum(Vs4VInventStock.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, Sum(Vs4VInventStock.TInMInQuantity3) AS TInMInQuantity3, Sum(Vs4VInventStock.TInMOutQuantity3) AS TInMOutQuantity3, Sum(Vs4VInventStock.TInMAmouQuantity3) AS TInMAmouQuantity3, Vs4VInventStock.TPdtTUntCode3, Sum(Vs4VInventStock.TInMAmount) AS TInMAmount, Avg(Vs4VInventStock.TIMCUnitCost) AS TIMCUnitCost, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, Vs4VInventStock.TPdtTPG4Code, Vs4VInventStock.TPdtTPCTAlias, Vs4VInventStock.TPOSPrice, Vs4VInventStock.TPdtOrderPoint, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TIMCUnitCalc, Sum(Vs4VInventStock.TInMQuantityCalc) AS TInMQuantityCalc, Vs4VInventStock.TPdtTAPNCode, Vs4VInventStock.TPdtFactoryCode, Vs4VInventStock.TPOSPackAlias2
FROM Vs4VInventStock
GROUP BY Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtTPTTCode, Vs4VInventStock.TPdtTPPuCode, Vs4VInventStock.TPdtFlag1, Vs4VInventStock.TPdtTUntCode, Vs4VInventStock.TPdtTUntCode2, Vs4VInventStock.TPdtTUntCode3, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, Vs4VInventStock.TPdtTPG4Code, Vs4VInventStock.TPdtTPCTAlias, Vs4VInventStock.TPOSPrice, Vs4VInventStock.TPdtOrderPoint, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TIMCUnitCalc, Vs4VInventStock.TPdtTAPNCode, Vs4VInventStock.TPdtFactoryCode, Vs4VInventStock.TPOSPackAlias2
GO

CREATE VIEW VS4VJobMBSerial
AS 
SELECT VS4TJob.*, VS4TJobMB.*, VS4TJobMBSerial.*, VS4TJobBook.TJBkName
FROM (VS4TJobBook RIGHT JOIN VS4TJob ON VS4TJobBook.TJBkCode=VS4TJob.TJobTJBkCode) INNER JOIN (VS4TJobMB INNER JOIN VS4TJobMBSerial ON (VS4TJobMB.TJbMTJobNo=VS4TJobMBSerial.TJMSTJbMTJobNo) AND (VS4TJobMB.TJbMLn=VS4TJobMBSerial.TJMSTJbMLn)) ON VS4TJob.TJobNo=VS4TJobMB.TJbMTJobNo
GO

CREATE VIEW VS4VJobMBSerialNew
AS 
SELECT VS4VJobMBSerial.TJobTPrjCode, VS4VJobMBSerial.TJobNo, VS4VJobMBSerial.TJobCode, VS4VJobMBSerial.TJbMLn, VS4VJobMBSerial.TJbMTPdtCode, VS4VJobMBSerial.TJbMProductName, VS4VJobMBSerial.TJMSCustom1, VS4VJobMBSerial.TJMSCustom2, VS4VJobMBSerial.TJMSCustom3, Sum(VS4VJobMBSerial.TJMSQuantity) AS TJMSQuantity, VS4VJobMBSerial.TJMSTUntCode, Sum(VS4VJobMBSerial.TJMSQuantity2) AS TJMSQuantity2, VS4VJobMBSerial.TJMSTUntCode2, Sum(VS4VJobMBSerial.TJMSQuantity3) AS TJMSQuantity3, VS4VJobMBSerial.TJMSTUntCode3, VS4TAR.TARNName, VS4VJobMBSerial.TJobTARNCode
FROM VS4VJobMBSerial LEFT JOIN VS4TAR ON VS4VJobMBSerial.TJobTARNCode=VS4TAR.TARNCode
GROUP BY VS4VJobMBSerial.TJobTPrjCode, VS4VJobMBSerial.TJobNo, VS4VJobMBSerial.TJobCode, VS4VJobMBSerial.TJbMLn, VS4VJobMBSerial.TJbMTPdtCode, VS4VJobMBSerial.TJbMProductName, VS4VJobMBSerial.TJMSCustom1, VS4VJobMBSerial.TJMSCustom2, VS4VJobMBSerial.TJMSCustom3, VS4VJobMBSerial.TJMSTUntCode, VS4VJobMBSerial.TJMSTUntCode2, VS4VJobMBSerial.TJMSTUntCode3, VS4TAR.TARNName, VS4VJobMBSerial.TJobTARNCode, VS4VJobMBSerial.TJMSTransfered
HAVING (((VS4VJobMBSerial.TJMSTransfered)=0))
GO

CREATE VIEW VS4VJobMBStep
AS 
SELECT VS4TJobMBSerial.TJMSTJbMTJobNo, VS4TJobMBSerial.TJMSTJbMLn, VS4TJobMBSerial.TJMSTSpdStep, VS4TJobMBSerial.TJMSProductCode, VS4TJobMBSerial.TJMSProductName, VS4TJobMBSerial.TJMSCustom1, VS4TJobMBSerial.TJMSCustom2, VS4TJobMBSerial.TJMSCustom3, Sum(VS4TJobMBSerial.TJMSQuantity) AS TJMSQuantity, VS4TJobMBSerial.TJMSTUntCode, Sum(VS4TJobMBSerial.TJMSQuantity2) AS TJMSQuantity2, VS4TJobMBSerial.TJMSTUntCode2, Sum(VS4TJobMBSerial.TJMSQuantity3) AS TJMSQuantity3, VS4TJobMBSerial.TJMSTUntCode3
FROM VS4TJobMBSerial
GROUP BY VS4TJobMBSerial.TJMSTJbMTJobNo, VS4TJobMBSerial.TJMSTJbMLn, VS4TJobMBSerial.TJMSTSpdStep, VS4TJobMBSerial.TJMSProductCode, VS4TJobMBSerial.TJMSProductName, VS4TJobMBSerial.TJMSCustom1, VS4TJobMBSerial.TJMSCustom2, VS4TJobMBSerial.TJMSCustom3, VS4TJobMBSerial.TJMSTUntCode, VS4TJobMBSerial.TJMSTUntCode2, VS4TJobMBSerial.TJMSTUntCode3, VS4TJobMBSerial.TJMSTransfered
HAVING (((VS4TJobMBSerial.TJMSTransfered)=0))
GO

CREATE VIEW VS4VJobMethod
AS 
SELECT VS4TJob.*, VS4TJobMB.*, VS4TJobMethod.*, VS4TProduct.TPdtName, VS4TSection.TSecCode, VS4TSection.TSecName, VS4TSection.TSecName2, VS4TSection.TSecDocCode, VS4TSection.TSecTDepCode, VS4TSection.TSecWatt, VS4TSection.TSecHOffice, VS4TSection.TSecHWithOT1, VS4TSection.TSecHWithOT2, VS4TSection.TSecH2Shift, VS4TSection.TSecHFullDay, VS4TMRPStepName.TSepCode, VS4TMRPStepName.TSepName, VS4TMRPStepName.TSepDocCode, VS4TMRPStepName.TSepTSecCode, VS4TMRPStepName.TSepTLctCode, VS4TMRPStepName.TSepDescription, VS4TMRPStepName.TSepTAPNCode, VS4TMRPStepName.TSepCalcQtyAuto, VS4TMRPStepName.TSepCheckSemiCode, VS4TMRPStepName.TSepQAStatus, VS4TMRPStepName.TSepByPassStock, VS4TMRPStepName.TSepTextSort, VS4TProductMethod.TSpdTAgtCode, VS4TProductMethod.TSpdTMoSCode, VS4TProductMethod.TSpdLink1, VS4TProductMethod.TSpdFormula1, VS4TProductMethod.TSpdNameFor1, VS4TProductMethod.TSpdCheckClose
FROM VS4TProduct RIGHT JOIN (VS4TJob INNER JOIN (VS4TJobMB INNER JOIN (((VS4TJobMethod LEFT JOIN VS4TMRPStepName ON VS4TJobMethod.TJStTSepCode = VS4TMRPStepName.TSepCode) LEFT JOIN VS4TSection ON VS4TMRPStepName.TSepTSecCode = VS4TSection.TSecCode) LEFT JOIN VS4TProductMethod ON (VS4TJobMethod.TJStTSpdStep = VS4TProductMethod.TSpdStep) AND (VS4TJobMethod.TJStTPdtCode = VS4TProductMethod.TSpdTPdtCode)) ON (VS4TJobMB.TJbMLn = VS4TJobMethod.TJStTJbMLn) AND (VS4TJobMB.TJbMTJobNo = VS4TJobMethod.TJStTJbMTJobNo)) ON VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo) ON VS4TProduct.TPdtCode = VS4TProductMethod.TSpdTPdtCode
GO

CREATE VIEW VS4VJobName
AS 
SELECT VS4TJob.*, VS4TProject.*, VS4TProjectType.*, VS4TBranch.*, VS4TDivision.*, VS4TDepartment.*, VS4TSection.*, VS4TJobBook.TJBkName
FROM (VS4TProjectType RIGHT JOIN VS4TProject ON VS4TProjectType.TPjTCode=VS4TProject.TPrjTPjTCode) RIGHT JOIN (VS4TJobBook RIGHT JOIN ((((VS4TJob LEFT JOIN VS4TDepartment ON VS4TJob.TJobTDepCode=VS4TDepartment.TDepCode) LEFT JOIN VS4TDivision ON VS4TJob.TJobTDivCode=VS4TDivision.TDivCode) LEFT JOIN VS4TBranch ON VS4TJob.TJobTBraCode=VS4TBranch.TBraCode) LEFT JOIN VS4TSection ON VS4TJob.TJobTSecCode=VS4TSection.TSecCode) ON VS4TJobBook.TJBkCode=VS4TJob.TJobTJBkCode) ON VS4TProject.TPrjCode=VS4TJob.TJobTPrjCode
GO

CREATE VIEW VS4VJobProdAsset
AS 
SELECT VS4TJobProduction.*, VS4TJobProductionM.*, VS4TAssetWorkTime.*, VS4TAssetWGMB.*, VS4TAsset.TAssCode, VS4TAsset.TAssNo, VS4TAsset.TAssAlias, VS4TAsset.TAssName, VS4TAsset.TAssName2, VS4TAsset.TAssTAsTCode, VS4TAsset.TAssTAseCode, VS4TAsset.TAssTDepCode, VS4TAsset.TAssTSecCode, VS4TAsset.TAssTDivCode, VS4TAsset.TAssTBraCode, VS4TAP.TAPNName, VS4TMRPStepName.TSepTSecCode
FROM VS4TJobProduction INNER JOIN (((((VS4TJobProductionM LEFT JOIN VS4TAssetWorkGroup ON VS4TJobProductionM.TJPMTAgtCode=VS4TAssetWorkGroup.TAgtCode) LEFT JOIN VS4TMRPStepName ON VS4TJobProductionM.TJPMTSepCode=VS4TMRPStepName.TSepCode) LEFT JOIN VS4TAP ON VS4TJobProductionM.TJPMTAPNCode=VS4TAP.TAPNCode) LEFT JOIN VS4TSection ON VS4TMRPStepName.TSepTSecCode=VS4TSection.TSecCode) LEFT JOIN ((VS4TAssetWGMB LEFT JOIN VS4TAsset ON VS4TAssetWGMB.TAegTAssCode=VS4TAsset.TAssCode) LEFT JOIN VS4TAssetWorkTime ON VS4TAsset.TAssCode=VS4TAssetWorkTime.TEntTAssCode) ON VS4TAssetWorkGroup.TAgtCode=VS4TAssetWGMB.TAegTAgtCode) ON VS4TJobProduction.TJPdNo=VS4TJobProductionM.TJPMTJPdNo
GO

CREATE VIEW VS4VJobProdAssetWG
AS 
SELECT VS4TJobProductionM.*, VS4TAssetWorkGroup.*
FROM VS4TJobProductionM LEFT JOIN VS4TAssetWorkGroup ON VS4TJobProductionM.TJPMTAgtCode=VS4TAssetWorkGroup.TAgtCode
GO

CREATE VIEW VS4VJobProdCap
AS 
SELECT Sum(VS4TJobProductionM.TJPMMan) AS TJPMMan, Sum(VS4TJobProductionM.TJPMMachine) AS TJPMMachine, Sum(VS4TJobProductionM.TJPMHourPerDay) AS TJPMHourPerDay, Sum(VS4TJobProductionM.TJPMCapacity) AS TJPMCapacity, Sum(VS4TJobProductionM.TJPMCapacityHour) AS TJPMCapacityHour, VS4TMRPStepName.TSepTSecCode, VS4TSection.TSecName, VS4TJobProductionM.TJPMWeek, Year(VS4TJobProductionM.TJPMStartDate) AS VJCPYear
FROM VS4TSection INNER JOIN (VS4TMRPStepName INNER JOIN VS4TJobProductionM ON VS4TMRPStepName.TSepCode = VS4TJobProductionM.TJPMTSepCode) ON VS4TSection.TSecCode = VS4TMRPStepName.TSepTSecCode
GROUP BY VS4TMRPStepName.TSepTSecCode, VS4TSection.TSecName, VS4TJobProductionM.TJPMWeek, Year(VS4TJobProductionM.TJPMStartDate)
GO

CREATE VIEW VS4VJobProdCap2
AS 
SELECT VS4VJobProdCap.*, VS4TCapacitySect.*
FROM VS4VJobProdCap LEFT JOIN VS4TCapacitySect ON (VS4VJobProdCap.VJCPYear = VS4TCapacitySect.TCPSYear) AND (VS4VJobProdCap.TJPMWeek = VS4TCapacitySect.TCPSWeek) AND (VS4VJobProdCap.TSepTSecCode = VS4TCapacitySect.TCPSTSecCode)
GO

CREATE VIEW VS4VJobProduction
AS 
SELECT VS4TJobProduction.*, VS4TJobProductionM.*, VS4TJob.TJobCustomerName, VS4TProject.TPrjName, VS4TJob.TJobTARNCode, VS4TAP.TAPNName, VS4TMRPStepName.TSepName, VS4TSection.TSecName, VS4TAssetWorkGroup.TAgtName, VS4TProduct.TPdtImage1, VS4TJobMB.TJbMSourceDate, VS4TEmpWorkRate.TWRMTarget0, VS4TEmpWorkRate.TWRMTarget1, VS4TMRPStepName.TSepTSecCode, VS4TJobMB.TJbMProductName, VS4TJobMB.TJbMUseOrder, VS4TJobMB.TJbMTUntCode, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TProduct_1.TPdtTUntCode AS VJPMTUntCode, VS4TProduct_1.TPdtTUntCode2 AS VJPMTUntCode2, VS4TProduct_1.TPdtTUntCode3 AS VJPMTUntCode3, VS4TProduct_1.TPdtImage1 AS VJPMImage1, VS4TJobMB.TJbMTUntCode2, VS4TJobMB.TJbMTUntCode3, VS4TJobMB.TJbMAcceptError, VS4TJobMB.TJbMUseOrder2, VS4TJobMB.TJbMUseOrder3, VS4TJob.TJobDate, VS4TJobMB.TJbMDescription, VS4TProduct_2.TPdtName AS VJPDProductName, VS4TJob.TJobCode, VS4TJobProdBook.TJPkName, VS4TJobMB.TJbMTPdtCode, VS4TJobMB.TJbMCustom1, VS4TJobMB.TJbMQuantity, VS4TProduct.TPdtTPSECode, VS4TProduct.TPdtTPG1Code, VS4TJobMB.TjbMShippingMark, VS4TJobMB.TJbMUnitCalc, VS4TJob.TJobDescription, VS4TSOMB.TSOBDescription, VS4TSO.TSODDescription
FROM (VS4TProject RIGHT JOIN (VS4TJob RIGHT JOIN ((VS4TJobProdBook RIGHT JOIN ((VS4TJobProduction LEFT JOIN VS4TJobMB ON (VS4TJobProduction.TJPdTJbMLn = VS4TJobMB.TJbMLn) AND (VS4TJobProduction.TJPdTJbMTJobNo = VS4TJobMB.TJbMTJobNo)) LEFT JOIN VS4TProduct ON VS4TJobProduction.TJPdProductCode = VS4TProduct.TPdtCode) ON VS4TJobProdBook.TJPkCode = VS4TJobProduction.TJPdTJPkCode) LEFT JOIN (((((((VS4TJobProductionM LEFT JOIN VS4TAP ON VS4TJobProductionM.TJPMTAPNCode = VS4TAP.TAPNCode) LEFT JOIN VS4TMRPStepName ON VS4TJobProductionM.TJPMTSepCode = VS4TMRPStepName.TSepCode) LEFT JOIN VS4TAssetWorkGroup ON VS4TJobProductionM.TJPMTAgtCode = VS4TAssetWorkGroup.TAgtCode) LEFT JOIN VS4TEmpWorkRate ON VS4TJobProductionM.TJPMTWRMCode = VS4TEmpWorkRate.TWRMCode) LEFT JOIN VS4TSection ON VS4TMRPStepName.TSepTSecCode = VS4TSection.TSecCode) LEFT JOIN VS4TProduct AS VS4TProduct_1 ON VS4TJobProductionM.TJPMTPdtCode = VS4TProduct_1.TPdtCode) LEFT JOIN VS4TProduct AS VS4TProduct_2 ON VS4TJobProductionM.TJPMTPdtCode = VS4TProduct_2.TPdtCode) ON VS4TJobProduction.TJPdNo = VS4TJobProductionM.TJPMTJPdNo) ON VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo) ON VS4TProject.TPrjCode = VS4TJob.TJobTPrjCode) LEFT JOIN (VS4TSO RIGHT JOIN VS4TSOMB ON VS4TSO.TSODNo = VS4TSOMB.TSOBTSODNo) ON (VS4TJobMB.TJbMSourceLn = VS4TSOMB.TSOBLn) AND (VS4TJobMB.TJbMSourceNo = VS4TSOMB.TSOBTSODNo)
GO

CREATE VIEW VS4VJobProdDL
AS 
SELECT VS4TJobProduction.*, VS4TJobProdDL.*, VS4TMRPStepName.*, VS4TSection.*, VS4TJobProductionM.*
FROM VS4TJobProduction INNER JOIN (((VS4TJobProdDL LEFT JOIN VS4TMRPStepName ON VS4TJobProdDL.TJPLTSepCode=VS4TMRPStepName.TSepCode) LEFT JOIN VS4TSection ON VS4TMRPStepName.TSepTSecCode=VS4TSection.TSecCode) LEFT JOIN VS4TJobProductionM ON (VS4TJobProdDL.TJPLTPdtCode=VS4TJobProductionM.TJPMTPdtCode) AND (VS4TJobProdDL.TJPLTJPdNo=VS4TJobProductionM.TJPMTJPdNo) AND (VS4TJobProdDL.TJPLStep=VS4TJobProductionM.TJPMStep)) ON VS4TJobProduction.TJPdNo=VS4TJobProdDL.TJPLTJPdNo
GO

CREATE VIEW VS4VJobProdExp
AS 
SELECT VS4TJobProdExpDoc.*, VS4TJobProdExpMB.*, VS4TJobProduction.*, VS4TJob.*
FROM VS4TJobProdExpDoc INNER JOIN ((VS4TJobProdExpMB INNER JOIN VS4TJobProduction ON VS4TJobProdExpMB.TJebTJPdNo=VS4TJobProduction.TJPdNo) INNER JOIN VS4TJob ON VS4TJobProdExpMB.TJebTJobNo=VS4TJob.TJobNo) ON VS4TJobProdExpDoc.TJpeNo=VS4TJobProdExpMB.TJebTJpeNo
GO

CREATE VIEW VS4VJobProdMat
AS 
SELECT VS4TJobProduction.*, VS4TJobProdMat.*, VS4TMRPStepName.TSepName, VS4TSection.TSecName, VS4TJobProductionM.TJPMStartDate, VS4TJobProductionM.TJPMEndDate, VS4TMRPStepName.TSepTLctCode, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TProduct.TPdtImage1, VS4TProduct_1.TPdtTUntCode AS VJPMTPdtTUntCode, VS4TProduct_1.TPdtTUntCode2 AS VJPMTPdtTUntCode2, VS4TProduct_1.TPdtTUntCode3 AS VJPMTPdtTUntCode3, VS4TProduct_1.TPdtImage1 AS VJPMTPdtImage1
FROM (VS4TJobProduction INNER JOIN ((((VS4TJobProdMat LEFT JOIN VS4TMRPStepName ON VS4TJobProdMat.TMteTSepCode=VS4TMRPStepName.TSepCode) LEFT JOIN VS4TSection ON VS4TMRPStepName.TSepTSecCode=VS4TSection.TSecCode) LEFT JOIN VS4TJobProductionM ON (VS4TJobProdMat.TMteTPdtCode=VS4TJobProductionM.TJPMTPdtCode) AND (VS4TJobProdMat.TMteStep=VS4TJobProductionM.TJPMStep) AND (VS4TJobProdMat.TMteTJPdNo=VS4TJobProductionM.TJPMTJPdNo)) LEFT JOIN VS4TProduct ON VS4TJobProdMat.TMteTPdtCode=VS4TProduct.TPdtCode) ON VS4TJobProduction.TJPdNo=VS4TJobProdMat.TMteTJPdNo) LEFT JOIN VS4TProduct AS VS4TProduct_1 ON VS4TJobProduction.TJPdProductCode=VS4TProduct_1.TPdtCode
GO

CREATE VIEW VS4VJobProdDetail
AS 
SELECT DISTINCT VS4VJobProduction.TJPdNo, VS4VJobProduction.TJPdTJbMTJobNo, VS4VJobProduction.TJPdTJobCode, VS4VJobProduction.TJPdTPG1Code, VS4VJobProduction.TJPdTPSECode, VS4VJobProduction.TJPdStartDate, VS4VJobProduction.TJPdQuantity, VS4VJobProduction.TJPdQuantityNet, VS4VJobProduction.TJPdQuantity2, VS4VJobProduction.TJPdQuantityNet2, VS4VJobProduction.TJPdQuantity3, VS4VJobProduction.TJPdQuantityNet3, VS4VJobProduction.TPdtTUntCode, VS4VJobProduction.TPdtTUntCode2, VS4VJobProduction.TPdtTUntCode3, VS4VJobProduction.TJPdProductCode, VS4VJobProduction.TJPdCustom1, VS4VJobProduction.TJPdTJbMLn, VS4VJobProduction.TJPMTSepCode, VS4VJobProduction.TSepName, VS4VJobProduction.TJPMLn, VS4VJobProduction.TJPMTSecCode, VS4VJobProduction.TSecName, VS4VJobProduction.TJPdDate
FROM VS4VJobProduction
WHERE (((VS4VJobProduction.TJPdCancelStatus)=0) AND ((VS4VJobProduction.TJPdStatusJob)<>1) AND ((VS4VJobProduction.TJPdCheckStatus)<>1))
GO

CREATE VIEW VS4VJobProductionH
AS 
SELECT VS4TJobProduction.*, VS4TJob.TJobCustomerName, VS4TProject.TPrjName, VS4TJob.TJobTARNCode, VS4TJobMB.TJbMUseOrder, VS4TJobMB.TJbMUseOrder2, VS4TJobMB.TJbMUseOrder3, VS4TJobMB.TJbMTUntCode, VS4TJobMB.TJbMTUntCode2, VS4TJobMB.TJbMTUntCode3, VS4TJob.TJobDate, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TJobProdBook.TJPkName, VS4TJob.TJobCode
FROM VS4TProject RIGHT JOIN (VS4TJob RIGHT JOIN (VS4TJobProdBook RIGHT JOIN ((VS4TJobProduction LEFT JOIN VS4TJobMB ON (VS4TJobProduction.TJPdTJbMTJobNo = VS4TJobMB.TJbMTJobNo) AND (VS4TJobProduction.TJPdTJbMLn = VS4TJobMB.TJbMLn)) LEFT JOIN VS4TProduct ON VS4TJobProduction.TJPdProductCode = VS4TProduct.TPdtCode) ON VS4TJobProdBook.TJPkCode = VS4TJobProduction.TJPdTJPkCode) ON VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo) ON VS4TProject.TPrjCode = VS4TJob.TJobTPrjCode
GO

CREATE VIEW VS4VJobProductionM
AS 
SELECT VS4TJobProduction.*, VS4TJobProductionM.*, VS4TJob.TJobNo, VS4TJob.TJobCode, VS4TJob.TJobDate, VS4TJob.TJobRefNo, VS4TJob.TJobRefDate, VS4TJob.TJobTPrjCode, VS4TJob.TJobTSecCode, VS4TJob.TJobTDepCode, VS4TJob.TJobTDivCode, VS4TJob.TJobTBraCode, VS4TJob.TJobDescription, VS4TJob.TJobCloseStatus, VS4TJob.TJobApproveStatus, VS4TJob.TJobCancelStatus, VS4TJobMB.TJbMLn, VS4TJobMB.TJbMType, VS4TJobMB.TJbMTDwgCode, VS4TJobMB.TJbMTPdtCode, VS4TJobMB.TJbMProductName, VS4TJobMB.TJbMCustom1, VS4TJobMB.TJbMCustom2, VS4TJobMB.TJbMCustom3, VS4TJobMB.TJbMQuantityCalc, VS4TJobMB.TJbMUnitCalc, VS4TJobMB.TJbMAcceptError, VS4TJobMB.TJbMQuantity, VS4TJobMB.TJbMUseOrder, VS4TJobMB.TJbMTUntCode, VS4TJobMB.TJbMQuantity2, VS4TJobMB.TJbMUseOrder2, VS4TJobMB.TJbMTUntCode2, VS4TJobMB.TJbMQuantity3, VS4TJobMB.TJbMUseOrder3, VS4TJobMB.TJbMTUntCode3, VS4TJobMB.TJbMDescription, VS4TJobMB.TJbMProcessStatus, VS4TJobMB.TJbMTotalRequest, VS4TJobMB.TJbMTotalRequest2, VS4TJobMB.TJbMTotalRequest3, VS4TJobMB.TJbMTotalArrear, VS4TJobMB.TJbMTotalArrear2, VS4TJobMB.TJbMTotalArrear3, VS4TJobMB.TJbMFinishPC, VS4TJobMB.TJbMFinishQT, VS4TJobMB.TJbMFinishQT2, VS4TJobMB.TJbMFinishQT3, VS4TJobMB.TJbMTotalLoss, VS4TJobMB.TJbMTotalLoss2, VS4TJobMB.TJbMTotalLoss3, VS4TJobMB.TJbMCustomText1, VS4TJobMB.TJbMCustomText2, VS4TJobMB.TJbMCustomText3, VS4TJobMB.TJbMCustomText4, VS4TJobMB.TJbMCustomText5, VS4TJobMB.TJbMCustomText6, VS4TJobMB.TJbMCustomText7, VS4TJobBook.TJBkName, VS4TAP.TAPNName, VS4TProject.TPrjName, VS4TMRPStepName.TSepName, VS4TSection.TSecName, VS4TEmpWorkRate.TWRMTarget0, VS4TMRPStepName.TSepTSecCode, VS4TJobMB.TJbMCustomText8, VS4TJobMB.TJbMCustomText9, VS4TJobMB.TJbMCustomText10, VS4TJobProdBook.TJPkName
FROM VS4TProject RIGHT JOIN ((VS4TJobBook RIGHT JOIN VS4TJob ON VS4TJobBook.TJBkCode = VS4TJob.TJobTJBkCode) RIGHT JOIN ((VS4TJobProdBook RIGHT JOIN (VS4TJobProduction LEFT JOIN VS4TJobMB ON (VS4TJobProduction.TJPdTJbMLn = VS4TJobMB.TJbMLn) AND (VS4TJobProduction.TJPdTJbMTJobNo = VS4TJobMB.TJbMTJobNo)) ON VS4TJobProdBook.TJPkCode = VS4TJobProduction.TJPdTJPkCode) LEFT JOIN ((((VS4TJobProductionM LEFT JOIN VS4TAP ON VS4TJobProductionM.TJPMTAPNCode = VS4TAP.TAPNCode) LEFT JOIN VS4TMRPStepName ON VS4TJobProductionM.TJPMTSepCode = VS4TMRPStepName.TSepCode) LEFT JOIN VS4TEmpWorkRate ON VS4TJobProductionM.TJPMTWRMCode = VS4TEmpWorkRate.TWRMCode) LEFT JOIN VS4TSection ON VS4TMRPStepName.TSepTSecCode = VS4TSection.TSecCode) ON VS4TJobProduction.TJPdNo = VS4TJobProductionM.TJPMTJPdNo) ON VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo) ON VS4TProject.TPrjCode = VS4TJob.TJobTPrjCode
GO

CREATE VIEW VS4VJobProductionS
AS 
SELECT VS4TJobProduction.TJPdNo, VS4TJobProduction.TJPdTJbMTJobNo, VS4TJobProduction.TJPdTJobCode, VS4TJobProduction.TJPdTJbMLn, VS4TJobProduction.TJPdCustomText1, VS4TJob.TJobDate, VS4TJobProduction.TJPdDate, VS4TJobProduction.TJPdProductCode, VS4TJobProduction.TJPdTPSECode, VS4TJobProduction.TJPdTPG1Code, VS4TJobProduction.TJPdCustom1, VS4TJobProduction.TJPdStartDate, VS4TJobProduction.TJPdEndDate, VS4TJobProduction.TJPdEndPlan, VS4TJobMB.TJbMFinishPC, VS4TJobProduction.TJPdQuantity, VS4TJobMB.TJbMFinishQT, VS4TJobMB.TJbMTotalArrear, VS4TProduct.TPdtTUntCode, VS4TJobProduction.TJPdQuantity2, VS4TJobMB.TJbMFinishQT2, VS4TJobMB.TJbMTotalArrear2, VS4TProduct.TPdtTUntCode2, VS4TJobProduction.TJPdQuantity3, VS4TJobMB.TJbMFinishQT3, VS4TJobMB.TJbMTotalArrear3, VS4TProduct.TPdtTUntCode3, VS4TJobMB.TJbMProcessStatus, VS4TJob.TJobCloseStatus, VS4TJob.TJobNo, VS4TJob.TJobCancelStatus, VS4TJobProduction.TJPdCancelStatus, VS4TJobProduction.TJPdCheckStatus, VS4TJobProduction.TJPdConfirmStatus, VS4TJobProduction.TJPdFlag1, VS4TJobBook.TJBkName, VS4TProduct.TPdtBarcode, VS4TJobProduction.TJPdProductName, VS4TProductSection.TPSECode, VS4TProductSection.TPSEName, VS4TAP.TAPNCode, VS4TAP.TAPNName2, VS4TJobProduction.TJPdStartPlan, VS4TJobProduction.TJPdDescription, VS4TProductSection.TPSECapacity, VS4TProductSection.TPSECapacityHour, VS4TJobProduction.TJPdCustom2, VS4TJobProduction.TJPdCustom3, VS4TJobProduction.TJPdTMRFCode, VS4TJobProduction.TJPdFormulaName, VS4TJobProduction.TJPdTMRFCode2, VS4TJobProduction.TJPdFormulaName2, VS4TJobMB.TJbMUseOrder, VS4TJobMB.TJbMUseOrder2, VS4TJobMB.TJbMUseOrder3, VS4TJobMB.TJbMTUntCode, VS4TJobMB.TJbMTUntCode2, VS4TJobMB.TJbMTUntCode3, VS4TJobProdBook.TJPkName
FROM VS4TProject RIGHT JOIN (((VS4TProduct LEFT JOIN VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode) LEFT JOIN VS4TAP ON VS4TProduct.TPdtTAPNCode = VS4TAP.TAPNCode) RIGHT JOIN ((VS4TJobBook RIGHT JOIN VS4TJob ON VS4TJobBook.TJBkCode = VS4TJob.TJobTJBkCode) RIGHT JOIN (VS4TJobProdBook RIGHT JOIN (VS4TJobProduction LEFT JOIN VS4TJobMB ON (VS4TJobProduction.TJPdTJbMTJobNo = VS4TJobMB.TJbMTJobNo) AND (VS4TJobProduction.TJPdTJbMLn = VS4TJobMB.TJbMLn)) ON VS4TJobProdBook.TJPkCode = VS4TJobProduction.TJPdTJPkCode) ON VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo) ON VS4TProduct.TPdtCode = VS4TJobMB.TJbMTPdtCode) ON VS4TProject.TPrjCode = VS4TJob.TJobTPrjCode
GO

CREATE VIEW VS4VJobTransDetail
AS 
SELECT DISTINCT VS4VJobProduction.TJPdNo, VS4VJobProduction.TJPdTJbMTJobNo, VS4VJobProduction.TJPdTJobCode, VS4VJobProduction.TJPdTPG1Code, VS4VJobProduction.TJPdTPSECode, VS4VJobProduction.TJPdStartDate, VS4VJobProduction.TJPdQuantity, VS4VJobProduction.TJPdQuantityNet, VS4VJobProduction.TJPdQuantity2, VS4VJobProduction.TJPdQuantityNet2, VS4VJobProduction.TJPdQuantity3, VS4VJobProduction.TJPdQuantityNet3, VS4VJobProduction.TPdtTUntCode, VS4VJobProduction.TPdtTUntCode2, VS4VJobProduction.TPdtTUntCode3, VS4VJobProduction.TJPdProductCode, VS4VJobProduction.TJPdCustom1, VS4VJobProduction.TJPdTJbMLn, VS4VJobProduction.TJPdConfirmStatus, VS4VJobProduction.TJPdApproveStatus, VS4VJobProduction.TJPMTSepCode, VS4VJobProduction.TSepName, VS4VJobProduction.TJPMLn
FROM VS4VJobProduction
WHERE (((VS4VJobProduction.TJPdCancelStatus)=0) AND ((VS4VJobProduction.TJPdStatusJob)<>1) AND ((VS4VJobProduction.TJPdCheckStatus)<>1))
GO

CREATE VIEW VS4VJobVariance
AS 
SELECT VS4TJobMB.*, VS4TProject.TPrjName, VS4TProjectType.TPjTName, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TSO.TSODNo, VS4TSO.TSODCode, VS4TSO.TSODType, VS4TSO.TSODDate, VS4TSO.TSODDueDate, VS4TSO.TSODRefNo, VS4TSO.TSODRefDate, VS4TSO.TSODTEmpCode, VS4TSO.TSODSaleName, VS4TSO.TSODTARNCode, VS4TSO.TSODContactNote, VS4TSO.TSODContactName, VS4TSO.TSODCustomerName, VS4TSO.TSODCusAddress, VS4TAR.TARNName, VS4TProject.TPrjMode, VS4TJobBook.TJBkName, VS4TProductSection.TPSECode, VS4TProductSection.TPSEName, VS4TJobVariance.*, VS4TJobProduction.TJPdNo, VS4TJobProduction.TJPdRevision, VS4TJobProductionM.TJPMLn, VS4TJobProductionM.TJPMTSepCode, VS4TJob.TJobNo, VS4TJob.TJobDate, VS4TJob.TJobTARNCode, VS4TJob.TJobCustomerName, VS4TJob.TJobRefNo, VS4TJob.TJobType, VS4TJob.TJobTJBkCode, VS4TMRPStepName.TSepName, VS4TJobProdBook.TJPkName
FROM VS4TSO RIGHT JOIN ((VS4TProjectType RIGHT JOIN VS4TProject ON VS4TProjectType.TPjTCode=VS4TProject.TPrjTPjTCode) RIGHT JOIN ((VS4TProduct LEFT JOIN VS4TProductSection ON VS4TProduct.TPdtTPSECode=VS4TProductSection.TPSECode) RIGHT JOIN ((VS4TJobBook RIGHT JOIN (((((VS4TJob LEFT JOIN VS4TDepartment ON VS4TJob.TJobTDepCode=VS4TDepartment.TDepCode) LEFT JOIN VS4TDivision ON VS4TJob.TJobTDivCode=VS4TDivision.TDivCode) LEFT JOIN VS4TBranch ON VS4TJob.TJobTBraCode=VS4TBranch.TBraCode) LEFT JOIN VS4TSection ON VS4TJob.TJobTSecCode=VS4TSection.TSecCode) LEFT JOIN VS4TAR ON VS4TJob.TJobTARNCode=VS4TAR.TARNCode) ON VS4TJobBook.TJBkCode=VS4TJob.TJobTJBkCode) INNER JOIN ((VS4TJobProdBook RIGHT JOIN ((VS4TJobVariance RIGHT JOIN (VS4TJobMB LEFT JOIN VS4TSOMB ON (VS4TJobMB.TJbMSourceLn=VS4TSOMB.TSOBLn) AND (VS4TJobMB.TJbMSourceNo=VS4TSOMB.TSOBTSODNo)) ON (VS4TJobVariance.TJVATJbMLn=VS4TJobMB.TJbMLn) AND (VS4TJobVariance.TJVATJbMJobNo=VS4TJobMB.TJbMTJobNo)) LEFT JOIN VS4TJobProduction ON VS4TJobVariance.TJVATJPDNo=VS4TJobProduction.TJPdNo) ON VS4TJobProdBook.TJPkCode=VS4TJobProduction.TJPdTJPkCode) LEFT JOIN ((VS4TJobProductionM LEFT JOIN VS4TMRPStepName ON VS4TJobProductionM.TJPMTSepCode=VS4TMRPStepName.TSepCode) LEFT JOIN VS4TSection AS VS4TSection_1 ON VS4TJobProductionM.TJPMTSecCode=VS4TSection_1.TSecCode) ON VS4TJobProduction.TJPdNo=VS4TJobProductionM.TJPMTJPdNo) ON VS4TJob.TJobNo=VS4TJobMB.TJbMTJobNo) ON VS4TProduct.TPdtCode=VS4TJobMB.TJbMTPdtCode) ON VS4TProject.TPrjCode=VS4TJob.TJobTPrjCode) ON VS4TSO.TSODNo=VS4TSOMB.TSOBTSODNo
GO

CREATE VIEW VS4VKBase
AS 
SELECT VS4TKBase.*, VS4TKBaseGroup.*
FROM VS4TKBaseGroup INNER JOIN VS4TKBase ON VS4TKBaseGroup.TKBGCode=VS4TKBase.TKBsTKBGCode
GO

CREATE VIEW VS4VLocation
AS 
SELECT VS4TLocation.*, VS4TWarehouse.*, VS4TBranch.*, VS4TCompany.*, VS4TCountry.*
FROM VS4TCountry RIGHT JOIN (VS4TCompany RIGHT JOIN ((VS4TLocation LEFT JOIN VS4TWarehouse ON VS4TLocation.TLctTWahCode=VS4TWarehouse.TWahCode) LEFT JOIN VS4TBranch ON VS4TLocation.TLctTBraCode=VS4TBranch.TBraCode) ON VS4TCompany.TCmpCode=VS4TBranch.TBraTCmpCode) ON VS4TCountry.TCouCode=VS4TBranch.TBraTCouCode
GO

CREATE VIEW VS4VLotDuplicate
AS 
SELECT VS4TInventoryLOT.TIMCTPdtCode, VS4TInventoryLOT.TIMCSerialNo, VS4TInventoryLOT.TIMCCustom1, VS4TInventoryLOT.TIMCLotNo, VS4TInventoryLOT.TIMCLotDate, Count(VS4TInventoryLOT.TIMCReceiveNo) AS VIMCReceiveNo, Count(VS4TInventoryLOT.TIMCReceiveLn) AS VIMCReceiveLn
FROM VS4TInventoryLOT
GROUP BY VS4TInventoryLOT.TIMCTPdtCode, VS4TInventoryLOT.TIMCSerialNo, VS4TInventoryLOT.TIMCCustom1, VS4TInventoryLOT.TIMCLotNo, VS4TInventoryLOT.TIMCLotDate
HAVING (((Count(VS4TInventoryLOT.TIMCReceiveNo))>1)) OR (((Count(VS4TInventoryLOT.TIMCReceiveLn))>1))
GO

CREATE VIEW VS4VLotIn
AS 
SELECT VS4TInventory.*, VS4TInventoryType.TInTName, VS4TInventoryMB.*, VS4TWarehouse.TWahName, VS4TLocation.TLctName, VS4TPO.TPODDate, VS4TPO.TPODTAPNCode, VS4TPO.TPODSupplierName, VS4TPO.TPODContactNote, VS4TPO.TPODContactName, VS4TPO.TPODDeliveryDate, VS4TPO.TPODDeliveryTo, VS4TPO.TPODNo, VS4TPO.TPODDescription, VS4TPR.TPRDNo, VS4TPR.TPRDType, VS4TPR.TPRDDate, VS4TPR.TPRDRefNo, VS4TPR.TPRDJobCode, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TSection.TSecName, VS4TProduct.TPdtBarcode, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtDescription, VS4TPOS.TPOSPackText1, VS4TPOS.TPOSPackText2, VS4TPOS.TPOSPackAlias1, VS4TPOS.TPOSPackAlias2, VS4TDepartment.TDepName, VS4TProduct.TPdtTPTTCode, VS4TProduct.TPdtTPSECode, VS4TProduct.TPdtTPS2Code, VS4TProduct.TPdtTPS3Code, VS4TProduct.TPdtTPS4Code, VS4TProduct.TPdtTPG1Code, VS4TProduct.TPdtTPG3Code, VS4TProduct.TPdtTPG2Code, VS4TProduct.TPdtTPG4Code, VS4TProductType.TPTTName, VS4TProductLine.TPdLName, VS4TProductSection.TPSEName, VS4TProductSec2.TPS2Name, VS4TProductSec3.TPS3Name, VS4TProductSec4.TPS4Name, VS4TProductGroup1.TPG1Name, VS4TProductGroup2.TPG2Name, VS4TProductGroup3.TPG3Name, VS4TProductGroup4.TPG4Name, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TProduct.TPdtFactoryCode, VS4TProduct.TPdtCode, VS4TProduct.TPdtFlag1, VS4TProduct.TPdtTAPNCode, VS4TWarehouse.TWahCode, VS4TLocation.TLctTBraCode
FROM (VS4TUnit INNER JOIN (VS4TInventoryType INNER JOIN (((((((((((VS4TProduct LEFT JOIN VS4TProductType ON VS4TProduct.TPdtTPTTCode = VS4TProductType.TPTTCode) LEFT JOIN VS4TProductLine ON VS4TProduct.TPdtTPDLCode = VS4TProductLine.TPdLCode) LEFT JOIN VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode) LEFT JOIN VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code) LEFT JOIN VS4TProductSec3 ON VS4TProduct.TPdtTPS3Code = VS4TProductSec3.TPS3Code) LEFT JOIN VS4TProductSec4 ON VS4TProduct.TPdtTPS4Code = VS4TProductSec4.TPS4Code) LEFT JOIN VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code) LEFT JOIN VS4TProductGroup2 ON VS4TProduct.TPdtTPG2Code = VS4TProductGroup2.TPG2Code) LEFT JOIN VS4TProductGroup3 ON VS4TProduct.TPdtTPG3Code = VS4TProductGroup3.TPG3Code) LEFT JOIN VS4TProductGroup4 ON VS4TProduct.TPdtTPG4Code = VS4TProductGroup4.TPG4Code) INNER JOIN (((((((VS4TInventory LEFT JOIN VS4TPR ON VS4TInventory.TInvRefNo3 = VS4TPR.TPRDNo) LEFT JOIN VS4TProject ON VS4TInventory.TInvTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TInventory.TInvTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TDivision ON VS4TInventory.TInvTDivCode = VS4TDivision.TDivCode) LEFT JOIN VS4TDepartment ON VS4TInventory.TInvTDepCode = VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TInventory.TInvTSecCode = VS4TSection.TSecCode) INNER JOIN (((VS4TInventoryMB LEFT JOIN VS4TLocation ON VS4TInventoryMB.TInMTLctCode = VS4TLocation.TLctCode) LEFT JOIN VS4TWarehouse ON VS4TLocation.TLctTWahCode = VS4TWarehouse.TWahCode) LEFT JOIN (VS4TInventoryLOT LEFT JOIN VS4TPO ON VS4TInventoryLOT.TIMCTPODNo = VS4TPO.TPODNo) ON (VS4TInventoryMB.TInMLotDate = VS4TInventoryLOT.TIMCLotDate) AND (VS4TInventoryMB.TInMLotNo = VS4TInventoryLOT.TIMCLotNo) AND (VS4TInventoryMB.TInMSerialNo = VS4TInventoryLOT.TIMCSerialNo) AND (VS4TInventoryMB.TInMCustom1 = VS4TInventoryLOT.TIMCCustom1) AND (VS4TInventoryMB.TInMTPdtCode = VS4TInventoryLOT.TIMCTPdtCode)) ON VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo) ON VS4TProduct.TPdtCode = VS4TInventoryMB.TInMTPdtCode) ON VS4TInventoryType.TInTAlias = VS4TInventory.TInvTInTAlias) ON VS4TUnit.TUntCode = VS4TProduct.TPdtTUntCode) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode
WHERE (((VS4TWarehouse.TWahCode)<>'INPROCESS' And (VS4TWarehouse.TWahCode)<>'OUTPROCESS' And (VS4TWarehouse.TWahCode)<>'BORROW' And (VS4TWarehouse.TWahCode)<>'CONSIGN' And (VS4TWarehouse.TWahCode)<>'PURCHASERETURN' And (VS4TWarehouse.TWahCode)<>'SCRAP') AND ((VS4TInventoryMB.TInMStatus)=1) AND ((VS4TInventory.TInvTInTAlias)='LOTIN')) OR (((VS4TInventory.TInvTInTAlias)='LOTINPR')) OR (((VS4TInventory.TInvTInTAlias)='LOTINPREMIUM'))
GO

CREATE VIEW VS4VLotInBalance
AS 
SELECT VS4TInventory.*, VS4TInventoryType.TInTName, VS4TInventoryMB.*, VS4TWarehouse.TWahName, VS4TLocation.TLctName, VS4TPO.TPODDate, VS4TPO.TPODTAPNCode, VS4TPO.TPODSupplierName, VS4TPO.TPODContactNote, VS4TPO.TPODContactName, VS4TPO.TPODDeliveryDate, VS4TPO.TPODDeliveryTo, VS4TPO.TPODNo, VS4TPO.TPODDescription, VS4TPR.TPRDNo, VS4TPR.TPRDType, VS4TPR.TPRDDate, VS4TPR.TPRDRefNo, VS4TPR.TPRDJobCode, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TSection.TSecName, VS4TProduct.TPdtBarcode, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtDescription, VS4TPOS.TPOSPackText1, VS4TPOS.TPOSPackText2, VS4TPOS.TPOSPackAlias1, VS4TPOS.TPOSPackAlias2, VS4TDepartment.TDepName, VS4TProduct.TPdtTPTTCode, VS4TProduct.TPdtTPSECode, VS4TProduct.TPdtTPS2Code, VS4TProduct.TPdtTPS3Code, VS4TProduct.TPdtTPS4Code, VS4TProduct.TPdtTPG1Code, VS4TProduct.TPdtTPG3Code, VS4TProduct.TPdtTPG2Code, VS4TProduct.TPdtTPG4Code, VS4TProductType.TPTTName, VS4TProductLine.TPdLName, VS4TProductSection.TPSEName, VS4TProductSec2.TPS2Name, VS4TProductSec3.TPS3Name, VS4TProductSec4.TPS4Name, VS4TProductGroup1.TPG1Name, VS4TProductGroup2.TPG2Name, VS4TProductGroup3.TPG3Name, VS4TProductGroup4.TPG4Name, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TProduct.TPdtFactoryCode, VS4TProduct.TPdtCode, VS4TProduct.TPdtFlag1, VS4TProduct.TPdtTAPNCode, VS4TWarehouse.TWahCode, VS4TLocation.TLctTBraCode
FROM (VS4TUnit INNER JOIN (VS4TInventoryType INNER JOIN (((((((((((VS4TProduct LEFT JOIN VS4TProductType ON VS4TProduct.TPdtTPTTCode = VS4TProductType.TPTTCode) LEFT JOIN VS4TProductLine ON VS4TProduct.TPdtTPDLCode = VS4TProductLine.TPdLCode) LEFT JOIN VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode) LEFT JOIN VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code) LEFT JOIN VS4TProductSec3 ON VS4TProduct.TPdtTPS3Code = VS4TProductSec3.TPS3Code) LEFT JOIN VS4TProductSec4 ON VS4TProduct.TPdtTPS4Code = VS4TProductSec4.TPS4Code) LEFT JOIN VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code) LEFT JOIN VS4TProductGroup2 ON VS4TProduct.TPdtTPG2Code = VS4TProductGroup2.TPG2Code) LEFT JOIN VS4TProductGroup3 ON VS4TProduct.TPdtTPG3Code = VS4TProductGroup3.TPG3Code) LEFT JOIN VS4TProductGroup4 ON VS4TProduct.TPdtTPG4Code = VS4TProductGroup4.TPG4Code) INNER JOIN (((((((VS4TInventory LEFT JOIN VS4TPR ON VS4TInventory.TInvRefNo3 = VS4TPR.TPRDNo) LEFT JOIN VS4TProject ON VS4TInventory.TInvTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TInventory.TInvTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TDivision ON VS4TInventory.TInvTDivCode = VS4TDivision.TDivCode) LEFT JOIN VS4TDepartment ON VS4TInventory.TInvTDepCode = VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TInventory.TInvTSecCode = VS4TSection.TSecCode) INNER JOIN (((VS4TInventoryMB LEFT JOIN VS4TLocation ON VS4TInventoryMB.TInMTLctCode = VS4TLocation.TLctCode) LEFT JOIN VS4TWarehouse ON VS4TLocation.TLctTWahCode = VS4TWarehouse.TWahCode) LEFT JOIN (VS4TInventoryLOT LEFT JOIN VS4TPO ON VS4TInventoryLOT.TIMCTPODNo = VS4TPO.TPODNo) ON (VS4TInventoryMB.TInMLotDate = VS4TInventoryLOT.TIMCLotDate) AND (VS4TInventoryMB.TInMLotNo = VS4TInventoryLOT.TIMCLotNo) AND (VS4TInventoryMB.TInMSerialNo = VS4TInventoryLOT.TIMCSerialNo) AND (VS4TInventoryMB.TInMCustom1 = VS4TInventoryLOT.TIMCCustom1) AND (VS4TInventoryMB.TInMTPdtCode = VS4TInventoryLOT.TIMCTPdtCode)) ON VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo) ON VS4TProduct.TPdtCode = VS4TInventoryMB.TInMTPdtCode) ON VS4TInventoryType.TInTAlias = VS4TInventory.TInvTInTAlias) ON VS4TUnit.TUntCode = VS4TProduct.TPdtTUntCode) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode
WHERE (((VS4TWarehouse.TWahCode)<>'INPROCESS' And (VS4TWarehouse.TWahCode)<>'OUTPROCESS' And (VS4TWarehouse.TWahCode)<>'BORROW' And (VS4TWarehouse.TWahCode)<>'CONSIGN' And (VS4TWarehouse.TWahCode)<>'PURCHASERETURN' And (VS4TWarehouse.TWahCode)<>'SCRAP') AND ((VS4TInventoryMB.TInMStatus)=1) AND ((VS4TInventory.TInvTInTAlias)='LOTIN')) OR (((VS4TInventory.TInvTInTAlias)='LOTINPR')) OR (((VS4TInventory.TInvTInTAlias)='BEGINBALANCE')) OR (((VS4TInventory.TInvTInTAlias)='LOTINPREMIUM'))
GO

CREATE VIEW VS4VLotInBalanceH
AS 
SELECT VS4TInventory.*, VS4TPO.*
FROM VS4TInventoryType INNER JOIN (VS4TInventory LEFT JOIN VS4TPO ON VS4TInventory.TInvRefNo=VS4TPO.TPODNo) ON VS4TInventoryType.TInTAlias=VS4TInventory.TInvTInTAlias
WHERE (((VS4TInventoryType.TInTAlias)='LOTIN' Or (VS4TInventoryType.TInTAlias)='LOTINPR' Or (VS4TInventoryType.TInTAlias)='LOTINPREMIUM' Or (VS4TInventoryType.TInTAlias)='BEGINBALANCE' Or (VS4TInventoryType.TInTAlias)='LOTINPOP'))
GO

CREATE VIEW VS4VLotInH
AS 
SELECT VS4TInventory.*, VS4TPO.*, VS4TAP.TAPNName
FROM VS4TInventoryType INNER JOIN ((VS4TInventory LEFT JOIN VS4TPO ON VS4TInventory.TInvRefNo = VS4TPO.TPODNo) LEFT JOIN VS4TAP ON VS4TInventory.TInvTARNCode = VS4TAP.TAPNCode) ON VS4TInventoryType.TInTAlias = VS4TInventory.TInvTInTAlias
WHERE (((VS4TInventoryType.TInTAlias)='LOTIN' Or (VS4TInventoryType.TInTAlias)='LOTINPR' Or (VS4TInventoryType.TInTAlias)='LOTINPREMIUM' Or (VS4TInventoryType.TInTAlias)='LOTINPOP'))
GO

CREATE VIEW VS4VLotInPO2
AS 
SELECT VS4VInventPDE.*, VS4TPOMB.*, VS4TPO.*
FROM VS4TPO RIGHT JOIN (VS4VInventPDE LEFT JOIN VS4TPOMB ON (VS4VInventPDE.TIMCTPOBLn = VS4TPOMB.TPOBLn) AND (VS4VInventPDE.TIMCTPODNo = VS4TPOMB.TPOBTPODNo)) ON VS4TPO.TPODNo = VS4TPOMB.TPOBTPODNo
GO

CREATE VIEW VS4VLotInPOM
AS 
SELECT VS4TInventoryMB.*, VS4TPOMB.*, VS4TPO.*, VS4TInventory.TInvNo, VS4TInventory.TInvRefNo, VS4TInventory.TInvRefNo2, VS4TProduct.TPdtName, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TInventoryLOT.TIMCUnitRatio, VS4TInventoryLOT.TIMCTUntCode, VS4TInventory.TInvTARNCode, VS4TInventoryLOT.TIMCUnitCost, VS4TInventoryLOT.TIMCInputCost, VS4TInventoryLOT.TIMCPerQuantity
FROM VS4TUnit INNER JOIN (VS4TInventoryType INNER JOIN (VS4TPO RIGHT JOIN (VS4TProduct INNER JOIN (VS4TInventory INNER JOIN (((VS4TInventoryMB LEFT JOIN VS4TLocation ON VS4TInventoryMB.TInMTLctCode = VS4TLocation.TLctCode) LEFT JOIN VS4TWarehouse ON VS4TLocation.TLctTWahCode = VS4TWarehouse.TWahCode) LEFT JOIN (VS4TInventoryLOT LEFT JOIN VS4TPOMB ON (VS4TInventoryLOT.TIMCTPOBLn = VS4TPOMB.TPOBLn) AND (VS4TInventoryLOT.TIMCTPODNo = VS4TPOMB.TPOBTPODNo)) ON (VS4TInventoryMB.TInMLotDate = VS4TInventoryLOT.TIMCLotDate) AND (VS4TInventoryMB.TInMLotNo = VS4TInventoryLOT.TIMCLotNo) AND (VS4TInventoryMB.TInMSerialNo = VS4TInventoryLOT.TIMCSerialNo) AND (VS4TInventoryMB.TInMCustom1 = VS4TInventoryLOT.TIMCCustom1) AND (VS4TInventoryMB.TInMTPdtCode = VS4TInventoryLOT.TIMCTPdtCode)) ON VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo) ON VS4TProduct.TPdtCode = VS4TInventoryMB.TInMTPdtCode) ON VS4TPO.TPODNo = VS4TPOMB.TPOBTPODNo) ON VS4TInventoryType.TInTAlias = VS4TInventory.TInvTInTAlias) ON VS4TUnit.TUntCode = VS4TProduct.TPdtTUntCode
WHERE (((VS4TInventoryType.TInTAlias)='LOTIN' Or (VS4TInventoryType.TInTAlias)='LOTINPREMIUM' Or (VS4TInventoryType.TInTAlias)='LOTINPR' Or (VS4TInventoryType.TInTAlias)='LOTINPOP' Or (VS4TInventoryType.TInTAlias)='RECEIVEFGBUILTOUT'))
GO

CREATE VIEW VS4VLotLoss
AS 
SELECT DISTINCT VS4TInventoryMB.TInMTPdtCode, VS4TInventoryMB.TInMCustom1, VS4TInventoryMB.TInMSerialNo, VS4TInventoryMB.TInMLotNo, VS4TInventoryMB.TInMLotDate, VS4TInventoryLOT.TIMCTPdtCode, VS4TInventoryLOT.TIMCCustom1, VS4TInventoryLOT.TIMCSerialNo, VS4TInventoryLOT.TIMCLotNo, VS4TInventoryLOT.TIMCLotDate
FROM VS4TInventoryLOT RIGHT JOIN VS4TInventoryMB ON (VS4TInventoryLOT.TIMCTPdtCode = VS4TInventoryMB.TInMTPdtCode) AND (VS4TInventoryLOT.TIMCCustom1 = VS4TInventoryMB.TInMCustom1) AND (VS4TInventoryLOT.TIMCSerialNo = VS4TInventoryMB.TInMSerialNo) AND (VS4TInventoryLOT.TIMCLotNo = VS4TInventoryMB.TInMLotNo) AND (VS4TInventoryLOT.TIMCLotDate = VS4TInventoryMB.TInMLotDate)
WHERE (((VS4TInventoryMB.TInMTPdtCode)='001') AND ((VS4TInventoryLOT.TIMCTPdtCode) Is Null)) OR (((VS4TInventoryLOT.TIMCCustom1) Is Null) AND ((VS4TInventoryLOT.TIMCSerialNo) Is Null) AND ((VS4TInventoryLOT.TIMCLotNo) Is Null) AND ((VS4TInventoryLOT.TIMCLotDate) Is Null))
GO

CREATE VIEW VS4VMDS
AS 
SELECT VS4TMDS.*, VS4TMDSMB.*, VS4TSODelivery.*, VS4TSOMB.*, VS4TSO.TSODNo, VS4TSO.TSODTSBkCode, VS4TSO.TSODCode, VS4TSO.TSODType, VS4TSO.TSODDate, VS4TSO.TSODDueDate, VS4TSO.TSODTBraCode, VS4TSO.TSODTEmpCode, VS4TSO.TSODSaleName, VS4TSO.TSODGuideText, VS4TSO.TSODTARNCode, VS4TSO.TSODContactNote, VS4TSO.TSODContactName, VS4TSO.TSODCustomerName, VS4TSO.TSODCusAddress, VS4TSO.TSODTPrjCode, VS4TSO.TSODRefNo, VS4TSO.TSODRefDate, VS4TSO.TSODCountryOrigin, VS4TSO.TSODApproveStatus, VS4TSO.TSODCancelStatus, VS4TSO.TSODRevision, VS4TProduct.TPdtCode, VS4TProduct.TPdtBarcode, VS4TProduct.TPdtName, VS4TProduct.TPdtName2
FROM VS4TSO INNER JOIN (VS4TMDS INNER JOIN ((((VS4TSOMB INNER JOIN VS4TSODelivery ON (VS4TSOMB.TSOBLn = VS4TSODelivery.TMDSTSOBLn) AND (VS4TSOMB.TSOBTSODNo = VS4TSODelivery.TMDSTSOBTSODNo)) LEFT JOIN VS4TPOS ON VS4TSOMB.TSOBTPOSCode = VS4TPOS.TPOSCode) INNER JOIN VS4TMDSMB ON (VS4TSODelivery.TMDSLn = VS4TMDSMB.TMDMTMDSLn) AND (VS4TSODelivery.TMDSTSOBLn = VS4TMDSMB.TMDMTMDSTSOBLn) AND (VS4TSODelivery.TMDSTSOBTSODNo = VS4TMDSMB.TMDMTMDSTSOBTSODNo)) LEFT JOIN VS4TProduct ON VS4TPOS.TPOSCode = VS4TProduct.TPdtCode) ON VS4TMDS.TMDNNo = VS4TMDSMB.TMDMTMDNNo) ON VS4TSO.TSODNo = VS4TSOMB.TSOBTSODNo
GO

CREATE VIEW VS4VMember
AS 
SELECT VS4TMember.*, VS4TMemberGroup.*
FROM VS4TMember LEFT JOIN (VS4TMemberGroup RIGHT JOIN VS4TMemberGroupMB ON VS4TMemberGroup.TMbGCode=VS4TMemberGroupMB.TMMBTMbGCode) ON VS4TMember.TMbrCode=VS4TMemberGroupMB.TMMBTMbrCode
GO

CREATE VIEW VS4VModulePermiss
AS 
SELECT VS4TModulePermiss.*, VS4TGroup.*, VS4TGroupMB.*, VS4TUser.*
FROM VS4TUser INNER JOIN ((VS4TModulePermiss INNER JOIN VS4TGroup ON VS4TModulePermiss.TMdPID = VS4TGroup.TGroID) INNER JOIN VS4TGroupMB ON VS4TGroup.TGroID = VS4TGroupMB.TGrMTGroID) ON (VS4TUser.TUsrID = VS4TGroupMB.TGrMTUsrID) AND (VS4TUser.TUsrID = VS4TGroupMB.TGrMTUsrID)
WHERE (((VS4TModulePermiss.TMdPIDType)='G'))
GO

CREATE VIEW VS4VModulePermissR
AS 
SELECT VS4TModulePermiss.*, VS4TGroup.*, VS4TCommandGroup.*
FROM (VS4TModulePermiss INNER JOIN VS4TGroup ON VS4TModulePermiss.TMdPID=VS4TGroup.TGroID) LEFT JOIN VS4TCommandGroup ON VS4TModulePermiss.TMdPTCmGAlias=VS4TCommandGroup.TCmGAlias
WHERE (((VS4TModulePermiss.TMdPIDType)='G'))
GO

CREATE VIEW VS4VModulePermissU
AS 
SELECT VS4TModulePermiss.*, VS4TEmployee.TEmpFullName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TUser.*, VS4TCommandGroup.*
FROM ((VS4TModulePermiss INNER JOIN VS4TUser ON VS4TModulePermiss.TMdPID = VS4TUser.TUsrID) LEFT JOIN VS4TCommandGroup ON VS4TModulePermiss.TMdPTCmGAlias = VS4TCommandGroup.TCmGAlias) LEFT JOIN ((VS4TDivision RIGHT JOIN ((VS4TEmployee LEFT JOIN VS4TSection ON VS4TEmployee.TEmpTSecCode = VS4TSection.TSecCode) LEFT JOIN VS4TDepartment ON VS4TEmployee.TEmpTDepCode = VS4TDepartment.TDepCode) ON VS4TDivision.TDivCode = VS4TEmployee.TEmpTDivCode) RIGHT JOIN VS4TUserEmployee ON VS4TEmployee.TEmpCode = VS4TUserEmployee.TUsETEmpCode) ON VS4TUser.TUsrID = VS4TUserEmployee.TUsETUsrID
WHERE (((VS4TModulePermiss.TMdPIDType)='U'))
GO

CREATE VIEW VS4VMoldSet
AS 
SELECT VS4TMoldSet.*, VS4TMoldSetMB.*, VS4TMold.*
FROM VS4TMold RIGHT JOIN (VS4TMoldSet LEFT JOIN VS4TMoldSetMB ON VS4TMoldSet.TMoSCode = VS4TMoldSetMB.TMSMTMoSCode) ON VS4TMold.TMolCode = VS4TMoldSetMB.TMSMTMolCode
GO

CREATE VIEW VS4VMoldSetup
AS 
SELECT VS4TMoldSet.*, VS4TMoldSetup.*
FROM VS4TMoldSet LEFT JOIN VS4TMoldSetup ON VS4TMoldSet.TMoSCode = VS4TMoldSetup.TMSPTMoSCode
GO

CREATE VIEW VS4VTeasuryTransA
AS 
SELECT VS4TTeasuryTrans.*, VS4TTeasuryTransMB.*, VS4TCompanyBank.*, VS4TBranch.*, VS4TBank.*
FROM VS4TTeasuryTrans INNER JOIN ((VS4TBranch INNER JOIN (VS4TBank INNER JOIN VS4TCompanyBank ON VS4TBank.TBnkCode=VS4TCompanyBank.TCBBTBnkCode) ON VS4TBranch.TBraCode=VS4TCompanyBank.TCBBTBraCode) INNER JOIN VS4TTeasuryTransMB ON VS4TCompanyBank.TCBBNo=VS4TTeasuryTransMB.TTTMToTCBBNo) ON VS4TTeasuryTrans.TTeTNo=VS4TTeasuryTransMB.TTTMTTeTNo
WHERE (((VS4TTeasuryTrans.TTeTCancelStatus)=0) AND ((VS4TTeasuryTrans.TTeTApproveStatus)=1))
GO

CREATE VIEW VS4VMoneyNetBook
AS 
SELECT VS4VTeasuryTransA.TTTMToTCBBNo, VS4VTeasuryTransA.TCBBTBraCode, VS4VTeasuryTransA.TBraName, VS4VTeasuryTransA.TCBBTBnkCode, VS4VTeasuryTransA.TBnkName, VS4VTeasuryTransA.TTTMRate, VS4VTeasuryTransA.TCBBAccountName, VS4VTeasuryTransA.TCBBAccountBranch, VS4VTeasuryTransA.TCBBAccountNo
FROM VS4VTeasuryTransA
GROUP BY VS4VTeasuryTransA.TTTMToTCBBNo, VS4VTeasuryTransA.TCBBTBraCode, VS4VTeasuryTransA.TBraName, VS4VTeasuryTransA.TCBBTBnkCode, VS4VTeasuryTransA.TBnkName, VS4VTeasuryTransA.TTTMRate, VS4VTeasuryTransA.TCBBAccountName, VS4VTeasuryTransA.TCBBAccountBranch, VS4VTeasuryTransA.TCBBAccountNo
GO

CREATE VIEW VS4VMPR
AS 
SELECT VS4TMPR.*, VS4TMPRMB.*, VS4TPosition.*, VS4TBranch.TBraName, VS4TBranch.TBraName2, VS4TDivision.TDivName, VS4TDivision.TDivName2, VS4TDepartment.TDepName2, VS4TSection.TSecName2, VS4TProject.TPrjName, VS4TProject.TPrjName2, VS4TJob.*, VS4TJobProduction.*
FROM (((((VS4TDivision INNER JOIN (VS4TBranch INNER JOIN (VS4TPosition INNER JOIN (VS4TMPR INNER JOIN VS4TMPRMB ON VS4TMPR.TMPRNo = VS4TMPRMB.TMPMTMPRNo) ON VS4TPosition.TPstCode = VS4TMPRMB.TMPMTPstCode) ON VS4TBranch.TBraCode = VS4TMPR.TMPRTBraCode) ON VS4TDivision.TDivCode = VS4TMPR.TMPRTDivCode) LEFT JOIN VS4TJob ON VS4TMPR.TMPRTJobNo = VS4TJob.TJobNo) LEFT JOIN VS4TJobProduction ON VS4TMPR.TMPRTJPDNo = VS4TJobProduction.TJPdNo) LEFT JOIN VS4TDepartment ON VS4TMPR.TMPRTDepCode = VS4TDepartment.TDepCode) LEFT JOIN VS4TProject ON VS4TMPR.TMPRTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TSection ON VS4TMPR.TMPRTSecCode = VS4TSection.TSecCode
GO

CREATE VIEW VS4VMPS
AS 
SELECT VS4TMPS.*, VS4TJobMethod.*, VS4TJobMB.*, VS4TJob.*, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3
FROM VS4TJob RIGHT JOIN (VS4TJobMB RIGHT JOIN ((VS4TMPS LEFT JOIN VS4TJobMethod ON (VS4TMPS.TMPSTJStTJbMTJobNo = VS4TJobMethod.TJStTJbMTJobNo) AND (VS4TMPS.TMPSTJStTJbMLn = VS4TJobMethod.TJStTJbMLn) AND (VS4TMPS.TMPSTJStTSpdStep = VS4TJobMethod.TJStTSpdStep) AND (VS4TMPS.TMPSTJStLn = VS4TJobMethod.TJStLn)) LEFT JOIN VS4TProduct ON VS4TJobMethod.TJStTPdtCode = VS4TProduct.TPdtCode) ON (VS4TJobMB.TJbMLn = VS4TJobMethod.TJStTJbMLn) AND (VS4TJobMB.TJbMTJobNo = VS4TJobMethod.TJStTJbMTJobNo)) ON VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo
GO

CREATE VIEW VS4VMRPFormula
AS 
SELECT VS4TMRPFormulaGrp.*, VS4TMRPFormula.*, VS4TAssetWorkGroup.*, VS4TMRPFormulaSet.*, VS4TProduct.*
FROM VS4TMRPFormulaGrp INNER JOIN (VS4TAssetWorkGroup RIGHT JOIN ((VS4TMRPFormula LEFT JOIN VS4TMRPFormulaSet ON (VS4TMRPFormula.TMRFTMRSCode=VS4TMRPFormulaSet.TMRSCode) AND (VS4TMRPFormula.TMRFTMRGCode=VS4TMRPFormulaSet.TMRSTMRGCode)) LEFT JOIN VS4TProduct ON VS4TMRPFormula.TMRFTPdtCode=VS4TProduct.TPdtCode) ON VS4TAssetWorkGroup.TAgtCode=VS4TMRPFormula.TMRFTAgtCode) ON VS4TMRPFormulaGrp.TMRGCode=VS4TMRPFormula.TMRFTMRGCode
GO

CREATE VIEW VS4VMRPFormulaSet
AS 
SELECT VS4TMRPFormula.TMRFTMRGCode, VS4TMRPFormula.TMRFTMRSCode
FROM VS4TMRPFormula
GROUP BY VS4TMRPFormula.TMRFTMRGCode, VS4TMRPFormula.TMRFTMRSCode
GO

CREATE VIEW VS4VMRPStepName
AS 
SELECT VS4TMRPStepName.*, VS4TAP.*, VS4TSection.*, VS4TLocation.*
FROM ((VS4TMRPStepName LEFT JOIN VS4TSection ON VS4TMRPStepName.TSepTSecCode=VS4TSection.TSecCode) LEFT JOIN VS4TAP ON VS4TMRPStepName.TSepTAPNCode=VS4TAP.TAPNCode) LEFT JOIN VS4TLocation ON VS4TMRPStepName.TSepTLctCode=VS4TLocation.TLctCode
GO

CREATE VIEW VS4VAPCodeFromPA
AS 
SELECT VS4TAP.TAPNCode, VS4TAP.TAPNName, VS4TAP.TAPNName2, VS4TAP.TAPNIntroName, VS4TAP.TAPNFlag1, VS4TAP.TAPNTCouCode, VS4TCountry.TCouName, VS4TCountry.TCouName2
FROM VS4TCountry RIGHT JOIN (VS4VPA LEFT JOIN VS4TAP ON VS4VPA.TPSDContactNote=VS4TAP.TAPNCode) ON VS4TCountry.TCouCode=VS4TAP.TAPNTCouCode
GROUP BY VS4TAP.TAPNCode, VS4TAP.TAPNName, VS4TAP.TAPNName2, VS4TAP.TAPNIntroName, VS4TAP.TAPNFlag1, VS4TAP.TAPNTCouCode, VS4TCountry.TCouName, VS4TCountry.TCouName2, VS4VPA.TPADConfirmStatus, VS4VPA.TPADApproveStatus, VS4VPA.TPADCancelStatus
HAVING (((VS4VPA.TPADConfirmStatus)=1) AND ((VS4VPA.TPADApproveStatus)=1) AND ((VS4VPA.TPADCancelStatus)<>1))
GO

CREATE VIEW VS4VPA2PSMB
AS 
SELECT VS4TPA.*, VS4TPAMB.*, VS4TPS.*, VS4TPSMB.*, VS4TAP.TAPNTotalScore, VS4TAP.TAPNTimeToOrder, VS4TAP.TAPNLastDueDate, VS4TAP.TAPNLastOrderDate, VS4TAP.TAPNCreditLimit, VS4TAP.TAPNCreditBalance
FROM ((VS4TAP RIGHT JOIN VS4TPS ON VS4TAP.TAPNCode=VS4TPS.TPSDTAPNCode) INNER JOIN (VS4TPA INNER JOIN VS4TPAMB ON VS4TPA.TPADNo=VS4TPAMB.TPAMTPADNo) ON VS4TPS.TPSDNo=VS4TPAMB.TPAMTPSDNo) INNER JOIN VS4TPSMB ON VS4TPS.TPSDNo=VS4TPSMB.TPSMTPSDNo
GO

CREATE VIEW VS4VPackingList
AS 
SELECT VS4TPackingList.*, VS4TPackingListMB.*, VS4TARInvoice.*, VS4TCountry.TCouName, VS4TCountry.TCouName2, VS4TAR.TARNCode, VS4TAR.TARNName, VS4TAR.TARNName2, VS4TAR.TARNTaxNo, VS4TAR.TARNAccountCode, VS4TAR.TARNTARGCode, VS4TAR.TARNCity, VS4TShipping.TSHPName, VS4TShipping.TSHPName2, VS4TAP.TAPNName, VS4TAP.TAPNName2, VS4TAP.TAPNDiscountDay, VS4TProductSection.TPSEName, VS4TProductGroup1.TPG1Name, VS4TProduct.TPdtCustom2, VS4TProduct.TPdtCustom3, VS4TProduct.TPdtCustom4, VS4TProduct.TPdtCustom5, VS4TProduct.TPdtCustom6, VS4TProduct.TPdtCustom7, VS4TProduct.TPdtCustom8, VS4TProduct.TPdtCustom9, VS4TProduct.TPdtCustom10, VS4TProduct.TPdtCustom1
FROM VS4TProductSection RIGHT JOIN ((VS4TCountry RIGHT JOIN ((((VS4TPackingList LEFT JOIN VS4TARInvoice ON VS4TPackingList.TPKLRefNo = VS4TARInvoice.TIvoNo) LEFT JOIN VS4TAR ON VS4TPackingList.TPKLTARNCode = VS4TAR.TARNCode) LEFT JOIN VS4TShipping ON VS4TPackingList.TPKLTShpCode = VS4TShipping.TSHPCode) LEFT JOIN VS4TAP ON VS4TShipping.TSHPCode = VS4TAP.TAPNCode) ON VS4TCountry.TCouCode = VS4TAR.TARNTCouCode) INNER JOIN ((VS4TPackingListMB LEFT JOIN VS4TProduct ON VS4TPackingListMB.TPKMTPOSCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code) ON VS4TPackingList.TPKLNo = VS4TPackingListMB.TPKMTPKLNo) ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode
GO

CREATE VIEW VS4VPackingListH
AS 
SELECT VS4TPackingList.*, VS4TARInvoice.*, VS4TCountry.TCouName, VS4TCountry.TCouName2, VS4TAR.TARNCode, VS4TAR.TARNName, VS4TAR.TARNName2, VS4TAR.TARNTaxNo, VS4TAR.TARNAccountCode, VS4TAR.TARNTARGCode, VS4TAR.TARNCity, VS4TShipping.TSHPName, VS4TShipping.TSHPName2, VS4TAP.TAPNName, VS4TAP.TAPNName2, VS4TAP.TAPNDiscountDay
FROM VS4TCountry RIGHT JOIN ((((VS4TPackingList LEFT JOIN VS4TARInvoice ON VS4TPackingList.TPKLRefNo = VS4TARInvoice.TIvoNo) LEFT JOIN VS4TAR ON VS4TPackingList.TPKLTARNCode = VS4TAR.TARNCode) LEFT JOIN VS4TShipping ON VS4TPackingList.TPKLTShpCode = VS4TShipping.TSHPCode) LEFT JOIN VS4TAP ON VS4TShipping.TSHPCode = VS4TAP.TAPNCode) ON VS4TCountry.TCouCode = VS4TAR.TARNTCouCode
GO

CREATE VIEW VS4VPaymentRate
AS 
SELECT VS4TPayment.*, VS4TPaymentType.*, VS4TCurrency.*, VS4TExchange.*, VS4TExchangeRate.*, VS4TBank.*
FROM VS4TPaymentType INNER JOIN (VS4TExchange INNER JOIN ((VS4TCurrency INNER JOIN (VS4TBank INNER JOIN VS4TExchangeRate ON VS4TBank.TBnkCode=VS4TExchangeRate.TExRTBnkCode) ON VS4TCurrency.TCurCode=VS4TExchangeRate.TExRTCurCode) INNER JOIN VS4TPayment ON VS4TCurrency.TCurCode=VS4TPayment.TPymTCurCode) ON VS4TExchange.TExcNo=VS4TExchangeRate.TExRTExcNo) ON VS4TPaymentType.TPyTAlias=VS4TPayment.TPymTPyTAlias
GO

CREATE VIEW VS4VPCR
AS 
SELECT VS4TPCR.*, VS4TPCRMB.*, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtTUntCode, VS4TAP.TAPNName, VS4TAP.TAPNName2, VS4TPOS.TPOSPackAlias1, VS4TPOS.TPOSPackAlias2
FROM VS4TPOS INNER JOIN ((VS4TAP INNER JOIN VS4TPCR ON VS4TAP.TAPNCode = VS4TPCR.TPCRTAPNCode) INNER JOIN (VS4TPCRMB LEFT JOIN VS4TProduct ON VS4TPCRMB.TPMBTPdtCode = VS4TProduct.TPdtCode) ON VS4TPCR.TPCRNo = VS4TPCRMB.TPMBTPCRNo) ON VS4TPOS.TPOSCode = VS4TPCRMB.TPMBTPOSCode
GO

CREATE VIEW VS4VPCRH
AS 
SELECT VS4TPCR.*, VS4TAP.TAPNName, VS4TAP.TAPNName2
FROM VS4TAP INNER JOIN VS4TPCR ON VS4TAP.TAPNCode=VS4TPCR.TPCRTAPNCode
GO

CREATE VIEW VS4VPO
AS 
SELECT VS4TPO.*, VS4TPOMB.*, VS4TProject.TPrjName, VS4TCountry.TCouName, VS4TCountry.TCouName2, VS4TPR.TPRDType, VS4TPR.TPRDDate, VS4TPR.TPRDRefNo, VS4TPR.TPRDJobCode, VS4TPR.TPRDTJobNo, VS4TPR.TPRDTJbMLn, VS4TPR.TPRDTJPMLn, VS4TPR.TPRDTJPDNo, VS4TPR.TPRDTPrjCode, VS4TPR.TPRDTSecCode, VS4TPR.TPRDTDepCode, VS4TPR.TPRDTDivCode, VS4TPR.TPRDTBraCode, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TSection.TSecDocCode, VS4TDepartment.TDepDocCode, VS4TDivision.TDivDocCode, VS4TBranch.TBraName, VS4TBranch.TBraDocCode, VS4TPRMB.TPRMUseDate, VS4TPRMB.TPRMUseType, VS4TAP.TAPNCode, VS4TAP.TAPNName, VS4TAP.TAPNName2, VS4TAP.TAPNType, VS4TAP.TAPNAddressBill, VS4TAP.TAPNTAPGCode, VS4TAP.TAPNPhone, VS4TAP.TAPNFax, VS4TPR.TPRDDescription, VS4TProject.TPrjCode, VS4TProject.TPrjMode, VS4TAP.TAPNTBsTCode, VS4TBusinessType.TBstName, VS4TAPGroup.TAPGName, VS4TProduct.TPdtTPDLCode, VS4TProductLine.TPdLName, VS4TProduct.TPdtTPSECode, VS4TProductSection.TPSEName, VS4TProductSec2.TPS2Name, VS4TProduct.TPdtTPG1Code, VS4TProductGroup1.TPG1Name, VS4TProduct.TPdtTPG2Code, VS4TProductGroup2.TPG2Name, VS4TProduct.TPdtTPS2Code, VS4TProduct.TPdtName2, VS4TPR.TPRDApproveDate, VS4TPOS.TPOSType, VS4TLocation.TLctTWahCode, VS4TProduct.TPdtImage1, VS4TProduct.TPdtIcon1, VS4TProduct_1.TPdtName AS VPODTPdtName, VS4TProduct_1.TPdtTUntCode AS VPODTPdtTuntCode, VS4TProduct_1.TPdtTUntCode2 AS VPODTPdtTuntCode2, VS4TProduct_1.TPdtTUntCode3 AS VPODTPdtTuntCode3, VS4TBranch.TBraAddressBill
FROM ((((VS4TPR LEFT JOIN VS4TSection ON VS4TPR.TPRDTSecCode = VS4TSection.TSecCode) LEFT JOIN VS4TDepartment ON VS4TPR.TPRDTDepCode = VS4TDepartment.TDepCode) LEFT JOIN VS4TDivision ON VS4TPR.TPRDTDivCode = VS4TDivision.TDivCode) LEFT JOIN VS4TBranch ON VS4TPR.TPRDTBraCode = VS4TBranch.TBraCode) RIGHT JOIN ((VS4TCountry INNER JOIN (((VS4TAP LEFT JOIN VS4TBusinessType ON VS4TAP.TAPNTBsTCode = VS4TBusinessType.TBsTCode) LEFT JOIN VS4TAPGroup ON VS4TAP.TAPNTAPGCode = VS4TAPGroup.TAPGCode) INNER JOIN (VS4TPO LEFT JOIN VS4TProject ON VS4TPO.TPODTPrjCode = VS4TProject.TPrjCode) ON VS4TAP.TAPNCode = VS4TPO.TPODTAPNCode) ON VS4TCountry.TCouCode = VS4TAP.TAPNTCouCode) INNER JOIN ((((((((((VS4TPOMB LEFT JOIN VS4TPRMB ON (VS4TPOMB.TPOBSourceNo = VS4TPRMB.TPRMTPRDNo) AND (VS4TPOMB.TPOBSourceLn = VS4TPRMB.TPRMLn)) LEFT JOIN VS4TProduct ON VS4TPOMB.TPOBTPdtCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TProductLine ON VS4TProduct.TPdtTPDLCode = VS4TProductLine.TPdLCode) LEFT JOIN VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode) LEFT JOIN VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code) LEFT JOIN VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code) LEFT JOIN VS4TProductGroup2 ON VS4TProduct.TPdtTPG2Code = VS4TProductGroup2.TPG2Code) LEFT JOIN VS4TLocation ON VS4TPOMB.TPOBTLctCode = VS4TLocation.TLctCode) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) LEFT JOIN VS4TProduct AS VS4TProduct_1 ON VS4TPOMB.TPOBMapTPdtCode = VS4TProduct_1.TPdtCode) ON VS4TPO.TPODNo = VS4TPOMB.TPOBTPODNo) ON VS4TPR.TPRDNo = VS4TPRMB.TPRMTPRDNo
WHERE (((VS4TPOS.TPOSType)=0 Or (VS4TPOS.TPOSType) Is Null))
GO

CREATE VIEW VS4VPO2APInv
AS 
SELECT VS4TPO.*, VS4TPOMB.*, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TAP.TAPNName, VS4TBranch.TBraName, VS4TAPInvoice.TIAPNo, VS4TAPInvoice.TIAPDate, VS4TAPInvoice.TIAPRefNo, VS4TAPInvoiceMB.TIPMSerialNo, VS4TAPInvoiceMB.TIPMCustom1, VS4TAPInvoiceMB.TIPMCustom2, VS4TAPInvoiceMB.TIPMCustom3, VS4TAPInvoiceMB.TIPMFactoryCode, VS4TAPInvoiceMB.TIPMProductName, VS4TAPInvoiceMB.TIPMCost, VS4TAPInvoiceMB.TIPMPrice, VS4TAPInvoiceMB.TIPMPerQuantity, VS4TAPInvoiceMB.TIPMQuantity, VS4TAPInvoiceMB.TIPMUnitCalc, VS4TAPInvoiceMB.TIPMQuantityCalc, VS4TAPInvoiceMB.TIPMQuantityStock, VS4TAPInvoiceMB.TIPMQuantity2, VS4TAPInvoiceMB.TIPMQuantity3, VS4TAPInvoiceMB.TIPMTaxType, VS4TAPInvoiceMB.TIPMAmount, VS4TAPInvoiceMB.TIPMDiscountTotal, VS4TAPInvoiceMB.TIPMNetAmount, VS4TAPInvoiceMB.TIPMIsPremium, VS4TAPInvoice.TIAPDueDate, VS4TAPInvoice.TIAPNetPayment, VS4TAPInvoice.TIAPGrandTotal, VS4TAPInvoice.TIAPArrears, VS4TAPInvoiceMB.TIPMAmountVAT, VS4TAPInvoiceMB.TIPMAmountWTAX
FROM (VS4TAP INNER JOIN ((VS4TPO LEFT JOIN VS4TProject ON VS4TPO.TPODTPrjCode=VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TPO.TPODTBraCode=VS4TBranch.TBraCode) ON VS4TAP.TAPNCode=VS4TPO.TPODTAPNCode) INNER JOIN (VS4TAPInvoice RIGHT JOIN ((VS4TAPInvoiceMB RIGHT JOIN VS4TPOMB ON (VS4TAPInvoiceMB.TIPMSourceLn=VS4TPOMB.TPOBLn) AND (VS4TAPInvoiceMB.TIPMSourceNo=VS4TPOMB.TPOBTPODNo)) LEFT JOIN VS4TProduct ON VS4TPOMB.TPOBTPdtCode=VS4TProduct.TPdtCode) ON VS4TAPInvoice.TIAPNo=VS4TAPInvoiceMB.TIPMTIAPNo) ON VS4TPO.TPODNo=VS4TPOMB.TPOBTPODNo
GO

CREATE VIEW VS4VPO2LotIn
AS 
SELECT VS4TPO.TPODNo, VS4TPO.TPODType, VS4TPO.TPODDate, VS4TPO.TPODDueDate, VS4TPO.TPODDeliveryDate, VS4TPO.TPODDeliveryTo, VS4TPO.TPODTAPNCode, VS4TPO.TPODSupplierName, VS4TPOMB.*, VS4TPODelivery.*, VS4TPRMB.*, VS4TPO.TPODCountryOrigin, VS4TCountry.TCouName, VS4TPO.TPODTPrjCode, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TPO.TPODTBraCode, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TAP.TAPNTBsTCode, VS4TBusinessType.TBstName, VS4TProduct.TPdtTPTTCode, VS4TProductType.TPTTName, VS4TProduct.TPdtTPDLCode, VS4TProductLine.TPdLName, VS4TProduct.TPdtTPSECode, VS4TProductSection.TPSEName, VS4TProduct.TPdtTPG1Code, VS4TProductGroup1.TPG1Name, VS4TPO.TPODApproveStatus, VS4TPO.TPODConfirmStatus, VS4TPO.TPODCancelStatus, VS4TAP.TAPNTAPGCode, VS4TAPGroup.TAPGName, VS4TProduct2.TPd2ScrapPCMRP, VS4TProduct2.TPd2ScrapPCReceive, VS4TProduct2.TPd2ScrapPCSend, VS4TProduct2.TPd2TaxType, VS4TProduct2.TPd2TaxRate, VS4TProduct2.TPd2CostFormula, VS4TInventoryMB.TInMAmouQuantity, VS4TInventoryMB.TInMAmouQuantity2, VS4TInventoryMB.TInMAmouQuantity3, VS4TInventoryMB.TInMTInTAlias, VS4TInventory.TInvNo, VS4TInventory.TInvRefNo, VS4TInventory.TInvRefDate, VS4TInventory.TInvRefNo2, VS4TInventory.TInvRefDate2, VS4TInventory.TInvDate, VS4TInventoryMB.TInMLotNo, VS4TInventoryMB.TInMLotDate, VS4TInventoryLOT.TIMCIsPremium, VS4TInventoryLOT.TIMCPremiumNote, VS4TPR.TPRDNo, VS4TPR.TPRDDate, VS4TPR.TPRDJobCode, VS4TPR.TPRDTJobNo, VS4TPR.TPRDTJbMLn, VS4TPR.TPRDTPrjCode, VS4TPR.TPRDTSecCode, VS4TPR.TPRDTDepCode, VS4TPR.TPRDTDivCode, VS4TPR.TPRDTBraCode, VS4TPR.TPRDDescription, VS4TPR.TPRDTPRBCode, VS4TInventory.TInvCancelStatus, VS4TInventory.TInvTIBkCode, VS4TInventBook.TIBkName
FROM (VS4TPRBook RIGHT JOIN (((VS4TPR LEFT JOIN VS4TDivision ON VS4TPR.TPRDTDivCode = VS4TDivision.TDivCode) LEFT JOIN VS4TDepartment ON VS4TPR.TPRDTDepCode = VS4TDepartment.TDepName) LEFT JOIN VS4TSection ON VS4TPR.TPRDTSecCode = VS4TSection.TSecCode) ON VS4TPRBook.TPRBCode = VS4TPR.TPRDTPRBCode) RIGHT JOIN ((VS4TCountry RIGHT JOIN (VS4TBusinessType RIGHT JOIN ((VS4TAP LEFT JOIN VS4TAPGroup ON VS4TAP.TAPNTAPGCode = VS4TAPGroup.TAPGCode) INNER JOIN ((VS4TPO LEFT JOIN VS4TBranch ON VS4TPO.TPODTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TProject ON VS4TPO.TPODTPrjCode = VS4TProject.TPrjCode) ON VS4TAP.TAPNCode = VS4TPO.TPODTAPNCode) ON VS4TBusinessType.TBsTCode = VS4TAP.TAPNTBsTCode) ON VS4TCountry.TCouCode = VS4TAP.TAPNTCouCode) INNER JOIN ((VS4TProductLine RIGHT JOIN ((VS4TInventBook RIGHT JOIN VS4TInventory ON VS4TInventBook.TIBkCode = VS4TInventory.TInvTIBkCode) RIGHT JOIN ((VS4TInventoryLOT RIGHT JOIN (VS4TProductType RIGHT JOIN (((((VS4TPOMB LEFT JOIN VS4TPODelivery ON (VS4TPOMB.TPOBLn = VS4TPODelivery.TPDETPOBLn) AND (VS4TPOMB.TPOBTPODNo = VS4TPODelivery.TPDETPOBTPODNo)) LEFT JOIN VS4TProduct ON VS4TPOMB.TPOBTPdtCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode) LEFT JOIN VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code) LEFT JOIN VS4TPRMB ON (VS4TPOMB.TPOBSourceLn = VS4TPRMB.TPRMLn) AND (VS4TPOMB.TPOBSourceNo = VS4TPRMB.TPRMTPRDNo)) ON VS4TProductType.TPTTCode = VS4TProduct.TPdtTPTTCode) ON (VS4TInventoryLOT.TIMCTPODNo = VS4TPODelivery.TPDETPOBTPODNo) AND (VS4TInventoryLOT.TIMCTPOBLn = VS4TPODelivery.TPDETPOBLn) AND (VS4TInventoryLOT.TIMCTPDELn = VS4TPODelivery.TPDELn)) LEFT JOIN VS4TInventoryMB ON (VS4TInventoryLOT.TIMCLotDate = VS4TInventoryMB.TInMLotDate) AND (VS4TInventoryLOT.TIMCLotNo = VS4TInventoryMB.TInMLotNo) AND (VS4TInventoryLOT.TIMCSerialNo = VS4TInventoryMB.TInMSerialNo) AND (VS4TInventoryLOT.TIMCCustom1 = VS4TInventoryMB.TInMCustom1) AND (VS4TInventoryLOT.TIMCTPdtCode = VS4TInventoryMB.TInMTPdtCode)) ON VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo) ON VS4TProductLine.TPdLCode = VS4TProduct.TPdtTPDLCode) LEFT JOIN VS4TProduct2 ON VS4TProduct.TPdtCode = VS4TProduct2.TPd2TPdtCode) ON VS4TPO.TPODNo = VS4TPOMB.TPOBTPODNo) ON VS4TPR.TPRDNo = VS4TPRMB.TPRMTPRDNo
WHERE (((VS4TInventoryMB.TInMTInTAlias)='LOTIN' Or (VS4TInventoryMB.TInMTInTAlias)='LOTINPR' Or (VS4TInventoryMB.TInMTInTAlias)='LOTINPREMIUM'))
GO

CREATE VIEW VS4VPO2SO
AS 
SELECT VS4TSO.TSODNo, VS4TSO.TSODCode, VS4TSO.TSODType, VS4TSO.TSODDate, VS4TSO.TSODDueDate, VS4TSO.TSODRefNo, VS4TSO.TSODRefDate, VS4TSO.TSODDeliveryDate, VS4TSO.TSODTEmpCode, VS4TSO.TSODSaleName, VS4TSO.TSODDeliveryTo, VS4TSO.TSODTARNCode, VS4TSO.TSODContactNote, VS4TSO.TSODContactName, VS4TSO.TSODCustomerName, VS4TSO.TSODDayAvailable, VS4TProject.TPrjName, VS4TJob.TJobNo, VS4TJob.TJobCode, VS4TPR.*, VS4TPRMB.*, VS4TPO.TPODNo, VS4TPO.TPODType, VS4TPO.TPODDate, VS4TPO.TPODDueDate, VS4TPO.TPODDeliveryDate, VS4TPO.TPODDeliveryTo, VS4TPO.TPODTAPNCode, VS4TPO.TPODSupplierName, VS4TPOMB.*, VS4TSO.TSODTPrjCode, VS4TPODelivery.TPDEDate, VS4TPODelivery.TPDEDateTime, VS4TPODelivery.TPDEQuantity, VS4TPODelivery.TPDEQuantity2, VS4TPODelivery.TPDEQuantity3, VS4TPODelivery.TPDETotalDelivery, VS4TPODelivery.TPDETotalDelivery2, VS4TPODelivery.TPDETotalDelivery3, VS4TPODelivery.TPDETotalArrear, VS4TPODelivery.TPDETotalArrear2, VS4TPODelivery.TPDETotalArrear3, VS4TSOMB.TSOBTPOSCode, VS4TSOMB.TSOBCustom1, VS4TSOMB.TSOBCustom2, VS4TSOMB.TSOBCustom3, VS4TSOMB.TSOBCustom4, VS4TSOMB.TSOBCustom5, VS4TSOMB.TSOBPOSName, VS4TSOMB.TSOBQuantityCalc, VS4TSOMB.TSOBUnitCalc, VS4TSOMB.TSOBQuantity, VS4TSOMB.TSOBTUntCode, VS4TSOMB.TSOBQuantity2, VS4TSOMB.TSOBTUntCode2, VS4TSOMB.TSOBQuantity3, VS4TSOMB.TSOBTUntCode3, VS4TSOMB.TSOBAmount, VS4TSOMB.TSOBPrice, VS4TSOMB.TSOBJobCode, VS4TSOMB.TSOBType, VS4TSOMB.TSOBLn
FROM (VS4TPR RIGHT JOIN (VS4TPO LEFT JOIN (((VS4TPRMB RIGHT JOIN VS4TPOMB ON (VS4TPRMB.TPRMTPRDNo = VS4TPOMB.TPOBSourceNo) AND (VS4TPRMB.TPRMLn = VS4TPOMB.TPOBSourceLn)) LEFT JOIN VS4TPODelivery ON (VS4TPOMB.TPOBTPODNo = VS4TPODelivery.TPDETPOBTPODNo) AND (VS4TPOMB.TPOBLn = VS4TPODelivery.TPDETPOBLn)) LEFT JOIN (VS4TJob LEFT JOIN (VS4TSO LEFT JOIN VS4TProject ON VS4TSO.TSODTPrjCode = VS4TProject.TPrjCode) ON VS4TJob.TJobRefNo = VS4TSO.TSODNo) ON VS4TPRMB.TPRMTJobNo = VS4TJob.TJobNo) ON VS4TPO.TPODNo = VS4TPOMB.TPOBTPODNo) ON VS4TPR.TPRDNo = VS4TPRMB.TPRMTPRDNo) LEFT JOIN VS4TSOMB ON VS4TSO.TSODNo = VS4TSOMB.TSOBTSODNo
GO

CREATE VIEW VS4VPOBookStatus
AS 
SELECT VS4TPO.TPODNo, VS4TPO.TPODTAPNCode, VS4TPO.TPODSupplierName, VS4TPO.TPODContactName, VS4TPO.TPODContactNote, VS4TPOMB.TPOBTPdtCode, VS4TPOMB.TPOBQuantity, VS4TPO.TPODArrears
FROM VS4TPO INNER JOIN VS4TPOMB ON VS4TPO.TPODNo = VS4TPOMB.TPOBTPODNo
GROUP BY VS4TPO.TPODNo, VS4TPO.TPODTAPNCode, VS4TPO.TPODSupplierName, VS4TPO.TPODContactName, VS4TPO.TPODContactNote, VS4TPOMB.TPOBTPdtCode, VS4TPOMB.TPOBQuantity, VS4TPO.TPODArrears, VS4TPO.TPODApproveStatus, VS4TPO.TPODCancelStatus
HAVING (((VS4TPO.TPODApproveStatus)=1) AND ((VS4TPO.TPODCancelStatus)=0))
GO

CREATE VIEW VS4VPODelivery
AS 
SELECT VS4TPO.*, VS4TPOMB.*, VS4TProject.TPrjName, VS4TPODelivery.*, VS4TProject.TPrjMode, VS4TAP.TAPNName, VS4TBranch.TBraName, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3
FROM (VS4TAP INNER JOIN ((VS4TPO LEFT JOIN VS4TProject ON VS4TPO.TPODTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TPO.TPODTBraCode = VS4TBranch.TBraCode) ON VS4TAP.TAPNCode = VS4TPO.TPODTAPNCode) INNER JOIN ((VS4TPOMB INNER JOIN VS4TPODelivery ON (VS4TPOMB.TPOBTPODNo = VS4TPODelivery.TPDETPOBTPODNo) AND (VS4TPOMB.TPOBLn = VS4TPODelivery.TPDETPOBLn)) LEFT JOIN VS4TProduct ON VS4TPODelivery.TPDEMapTPdtCode = VS4TProduct.TPdtCode) ON VS4TPO.TPODNo = VS4TPOMB.TPOBTPODNo
GO

CREATE VIEW VS4VPOH
AS 
SELECT VS4TPO.*, VS4TProject.TPrjName, VS4TCountry.TCouName, VS4TCountry.TCouName2, VS4TBranch.TBraName, VS4TBranch.TBraDocCode, VS4TAP.TAPNCode, VS4TAP.TAPNName, VS4TAP.TAPNName2, VS4TAP.TAPNType, VS4TAP.TAPNAddressBill, VS4TAP.TAPNTAPGCode, VS4TAP.TAPNPhone, VS4TAP.TAPNFax, VS4TProject.TPrjCode, VS4TProject.TPrjMode, VS4TAP.TAPNTBsTCode, VS4TBusinessType.TBstName, VS4TAPGroup.TAPGName
FROM ((VS4TAP LEFT JOIN VS4TBusinessType ON VS4TAP.TAPNTBsTCode=VS4TBusinessType.TBsTCode) LEFT JOIN VS4TAPGroup ON VS4TAP.TAPNTAPGCode=VS4TAPGroup.TAPGCode) INNER JOIN (((VS4TPO LEFT JOIN VS4TProject ON VS4TPO.TPODTPrjCode=VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TPO.TPODTBraCode=VS4TBranch.TBraCode) LEFT JOIN VS4TCountry ON VS4TPO.TPODCountryOrigin=VS4TCountry.TCouCode) ON VS4TAP.TAPNCode=VS4TPO.TPODTAPNCode
GO

CREATE VIEW VS4VPOPayPeriod
AS 
SELECT VS4TPO.*, VS4TPOPayPeriod.*, VS4TPayPeriodType.*, VS4TPaymentType.*
FROM VS4TPO LEFT JOIN (VS4TPayPeriodType RIGHT JOIN (VS4TPaymentType RIGHT JOIN VS4TPOPayPeriod ON VS4TPaymentType.TPyTAlias=VS4TPOPayPeriod.TPPPTPyTAlias) ON VS4TPayPeriodType.TPPTCode=VS4TPOPayPeriod.TPPPTPPTCode) ON VS4TPO.TPODNo=VS4TPOPayPeriod.TPPPTPODNo
GO

CREATE VIEW VS4VPOPTrans
AS 
SELECT VS4TPOPTrans.*, VS4TPOPTransMB.*, VS4TProduct.TPdtTPSECode, VS4TProductSection.TPSEName, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TBranch.TBraName, VS4TEmployee.TEmpAliasName, VS4TEmployee_1.TEmpAliasName AS VPPDEditBy, VS4TEmployee.TEmpAliasName AS VPPDWeightBy
FROM VS4TProject RIGHT JOIN ((VS4TProduct LEFT JOIN VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode) RIGHT JOIN (((VS4TPOPTrans LEFT JOIN VS4TBranch ON VS4TPOPTrans.TPPDTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TEmployee AS VS4TEmployee_1 ON VS4TPOPTrans.TPPDEditCode = VS4TEmployee_1.TEmpCode) LEFT JOIN (VS4TPOPTransMB LEFT JOIN VS4TEmployee ON VS4TPOPTransMB.TPTBCreateCode = VS4TEmployee.TEmpCode) ON VS4TPOPTrans.TPPDNo = VS4TPOPTransMB.TPTBTPPDNo) ON VS4TProduct.TPdtCode = VS4TPOPTransMB.TPTBTPdtCode) ON VS4TProject.TPrjCode = VS4TPOPTrans.TPPDTPrjCode
GO

CREATE VIEW VS4VPOPTransH
AS 
SELECT VS4TPOPTrans.*, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TBranch.TBraName
FROM VS4TProject RIGHT JOIN (VS4TPOPTrans LEFT JOIN VS4TBranch ON VS4TPOPTrans.TPPDTBraCode = VS4TBranch.TBraCode) ON VS4TProject.TPrjCode = VS4TPOPTrans.TPPDTPrjCode
GO

CREATE VIEW VS4VPOSMB
AS 
SELECT VS4TPOSMB.*, VS4TProduct.*, VS4VStock.TInMAmouQuantity, VS4VStock.TInMAmouQuantity2, (VS4VStock.TInMAmouQuantity/VS4TPOSMB.TPoMQuantity) AS VPOMSetAvailable
FROM VS4TUnit INNER JOIN ((VS4TProduct LEFT JOIN VS4VStock ON VS4TProduct.TPdtCode = VS4VStock.TPdtCode) INNER JOIN (VS4TPOS INNER JOIN VS4TPOSMB ON VS4TPOS.TPOSCode = VS4TPOSMB.TPoMTPOSCode) ON VS4TProduct.TPdtCode = VS4TPOSMB.TPoMTPdtCode) ON VS4TUnit.TUntCode = VS4TProduct.TPdtTUntCode
GO

CREATE VIEW VS4VPOSBarcode
AS 
SELECT VS4TPOS.*, VS4TProduct.*, VS4TProductSection.*, VS4TProductLine.TPdLName, VS4TProductGroup1.*, VS4TBrand.TBndCode, VS4TBrand.TBndName, VS4TProductGroup2.TPG2Code, VS4TProductGroup2.TPG2Name, VS4TProductGroup2.TPG2Name2, VS4TProductGroup3.TPG3Code, VS4TProductGroup3.TPG3Name, VS4TProductGroup3.TPG3Name2, VS4TProductGroup4.TPG4Code, VS4TProductGroup4.TPG4Name, VS4TProductGroup4.TPG4Name2
FROM (VS4TProductSection RIGHT JOIN (VS4TProductType INNER JOIN ((((((VS4TProduct LEFT JOIN VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code) LEFT JOIN VS4TBrand ON VS4TProduct.TPdtTBndCode = VS4TBrand.TBndCode) LEFT JOIN VS4TProductGroup2 ON VS4TProduct.TPdtTPG2Code = VS4TProductGroup2.TPG2Code) LEFT JOIN VS4TProductGroup3 ON VS4TProduct.TPdtTPG3Code = VS4TProductGroup3.TPG3Code) LEFT JOIN VS4TProductGroup4 ON VS4TProduct.TPdtTPG4Code = VS4TProductGroup4.TPG4Code) LEFT JOIN VS4TProductLine ON VS4TProduct.TPdtTPDLCode = VS4TProductLine.TPdLCode) ON VS4TProductType.TPTTCode = VS4TProduct.TPdtTPTTCode) ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode
GO

CREATE VIEW VS4VPOSTransEmp
AS 
SELECT VS4TPOSTrans.*, VS4TPOSTransEmp.*, VS4TEmployeeGroup.*
FROM VS4TPOSTrans INNER JOIN (VS4TPOSTransEmp LEFT JOIN VS4TEmployeeGroup ON VS4TPOSTransEmp.TPTETEmGCode = VS4TEmployeeGroup.TEmGCode) ON VS4TPOSTrans.TPTANo = VS4TPOSTransEmp.TPTETPTANo
GO

CREATE VIEW VS4VPOSEmpSumDay
AS 
SELECT VS4VPOSTransEmp.TPTADate, VS4VPOSTransEmp.TPTATCurCode, Sum(VS4VPOSTransEmp.TPTAPremiumTotal) AS TPTAPremiumTotal, Sum(VS4VPOSTransEmp.TPTACustomTotal1) AS TPTACustomTotal1, Sum(VS4VPOSTransEmp.TPTACustomTotal2) AS TPTACustomTotal2, Sum(VS4VPOSTransEmp.TPTACustomTotal3) AS TPTACustomTotal3, Sum(VS4VPOSTransEmp.TPTAGrandTotal) AS TPTAGrandTotal, Sum(VS4VPOSTransEmp.TPTASubTotal) AS TPTASubTotal, Sum(VS4VPOSTransEmp.TPTADiscountTotal) AS TPTADiscountTotal, Sum(VS4VPOSTransEmp.TPTAVATTotal) AS TPTAVATTotal, Sum(VS4VPOSTransEmp.TPTAAdjustTotal) AS TPTAAdjustTotal, Sum(VS4VPOSTransEmp.TPTAChangeTotal) AS TPTAChangeTotal, VS4VPOSTransEmp.TPTACancelStatus, VS4VPOSTransEmp.TPTETEmpCode, VS4VPOSTransEmp.TPTEName, VS4VPOSTransEmp.TPTEPositionName, VS4VPOSTransEmp.TPTEPositionAlias, VS4VPOSTransEmp.TPTETEmGCode, Sum(VS4VPOSTransEmp.TPTEFee) AS TPTEFee, Sum(VS4VPOSTransEmp.TPTECustom1) AS TPTECustom1, Sum(VS4VPOSTransEmp.TPTECustom2) AS TPTECustom2, Sum(VS4VPOSTransEmp.TPTECustom3) AS TPTECustom3, VS4VPOSTransEmp.TPTETCurCode
FROM VS4VPOSTransEmp
GROUP BY VS4VPOSTransEmp.TPTADate, VS4VPOSTransEmp.TPTATCurCode, VS4VPOSTransEmp.TPTACancelStatus, VS4VPOSTransEmp.TPTETEmpCode, VS4VPOSTransEmp.TPTEName, VS4VPOSTransEmp.TPTEPositionName, VS4VPOSTransEmp.TPTEPositionAlias, VS4VPOSTransEmp.TPTETEmGCode, VS4VPOSTransEmp.TPTETCurCode
GO

CREATE VIEW VS4VPOSMBQuery
AS 
SELECT VS4VPOSMB.TPoMTPOSCode, Count(VS4VPOSMB.TPoMTPOSCode) AS VPoSMemberCount, Min(VS4VPOSMB.VPOMSetAvailable) AS VPoMSetAvailable
FROM VS4VPOSMB
GROUP BY VS4VPOSMB.TPoMTPOSCode
GO

CREATE VIEW VS4VPriceList2
AS 
SELECT VS4TPricelist.*, VS4TPricelistMB.*, VS4VPOSMBQuery.VPoSMemberCount, VS4VPOSMBQuery.VPoMSetAvailable, VS4TUnit.*, VS4TPOS.*, VS4TProduct.*
FROM (((VS4TPOS LEFT JOIN VS4VPOSMBQuery ON VS4TPOS.TPOSCode = VS4VPOSMBQuery.TPoMTPOSCode) LEFT JOIN VS4TProduct ON VS4TPOS.TPOSCode = VS4TProduct.TPdtCode) INNER JOIN (VS4TPricelist INNER JOIN VS4TPricelistMB ON VS4TPricelist.TPPLNo = VS4TPricelistMB.TPPMTPPLNo) ON VS4TPOS.TPOSCode = VS4TPricelistMB.TPPMTPOSCode) LEFT JOIN VS4TUnit ON VS4TUnit.TUntCode = VS4TProduct.TPdtTUntCode
GO

CREATE VIEW VS4VPOSFull
AS 
SELECT VS4TPOS.*, VS4VPOSMBQuery.VPoSMemberCount, VS4VPOSMBQuery.VPoMSetAvailable, VS4TProduct.*, VS4TProductType.*, VS4TProductLine.TPdLName, VS4TProductSection.TPSEName, VS4TProductGroup1.TPG1Name, VS4TProductGroup2.TPG2Name, VS4TProductGroup3.TPG3Name, VS4TProductGroup4.TPG4Name, VS4TProductSec2.TPS2Name, VS4TProductSec3.TPS3Name, VS4TProductSec4.TPS4Name, VS4TProduct_1.TPdtCode AS VPSFCode, VS4TProduct_1.TPdtBarcode AS VPSFBarcode, VS4TProduct_1.TPdtName AS VPSFName, VS4TProduct_1.TPdtName2 AS VPSFName2, VS4TProduct_1.TPdtTUntCode AS VPSFTuntCode, VS4TPOSMB.TPoMQuantity, VS4TPOSMB.TPoMQuantity2, VS4TPOSMB.TPoMQuantity3
FROM VS4TProductSection RIGHT JOIN (((VS4TProductType RIGHT JOIN ((((((((VS4TProduct LEFT JOIN VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code) LEFT JOIN VS4TProductGroup2 ON VS4TProduct.TPdtTPG2Code = VS4TProductGroup2.TPG2Code) LEFT JOIN VS4TProductGroup3 ON VS4TProduct.TPdtTPG3Code = VS4TProductGroup3.TPG3Code) LEFT JOIN VS4TProductGroup4 ON VS4TProduct.TPdtTPG4Code = VS4TProductGroup4.TPG4Code) LEFT JOIN VS4TProductSec3 ON VS4TProduct.TPdtTPS3Code = VS4TProductSec3.TPS3Code) LEFT JOIN VS4TProductSec4 ON VS4TProduct.TPdtTPS4Code = VS4TProductSec4.TPS4Code) LEFT JOIN VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code) LEFT JOIN VS4TProductLine ON VS4TProduct.TPdtTPDLCode = VS4TProductLine.TPdLCode) ON VS4TProductType.TPTTCode = VS4TProduct.TPdtTPTTCode) RIGHT JOIN (VS4TPOS LEFT JOIN VS4VPOSMBQuery ON VS4TPOS.TPOSCode = VS4VPOSMBQuery.TPoMTPOSCode) ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) INNER JOIN (VS4TPOSMB LEFT JOIN VS4TProduct AS VS4TProduct_1 ON VS4TPOSMB.TPoMTPdtCode = VS4TProduct_1.TPdtCode) ON VS4TPOS.TPOSCode = VS4TPOSMB.TPoMTPOSCode) ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode
GO

CREATE VIEW VS4VPOSLastPriceA
AS 
SELECT *
FROM VS4VPriceList2
WHERE (((VS4VPriceList2.TPPLApproveDate)<='3333-3-3'))
GO

CREATE VIEW VS4VPOSLastPriceB
AS 
SELECT VS4VPOSLastPriceA.TPPMFromQuantity AS TPPMFromQuantity, VS4VPOSLastPriceA.TPPMTPOSCode AS TPPMTPOSCode, VS4VPOSLastPriceA.TPPMTUntCode AS TPPMTUntCode, VS4VPOSLastPriceA.TPPMTARNCode AS TPPMTARNCode, Max(VS4VPOSLastPriceA.TPPLApproveDate) AS TPPLApproveDate
FROM VS4VPOSLastPriceA
GROUP BY VS4VPOSLastPriceA.TPPMFromQuantity, VS4VPOSLastPriceA.TPPMTPOSCode, VS4VPOSLastPriceA.TPPMTUntCode, VS4VPOSLastPriceA.TPPMTARNCode, VS4VPOSLastPriceA.TPPLApproveStatus, VS4VPOSLastPriceA.TPPLCancelStatus, VS4VPOSLastPriceA.TPPMStatus
HAVING (((VS4VPOSLastPriceA.TPPLApproveStatus)=1) AND ((VS4VPOSLastPriceA.TPPLCancelStatus)<>1) AND ((VS4VPOSLastPriceA.TPPMStatus)=1))
GO

CREATE VIEW VS4VPOSLPQueue
AS 
SELECT VS4TPOSLPQueue.*, VS4TPOS.*, VS4TProduct.*
FROM (VS4TPOSLPQueue LEFT JOIN VS4TPOS ON VS4TPOSLPQueue.TPLQTPOSCode = VS4TPOS.TPOSCode) LEFT JOIN VS4TProduct ON VS4TPOS.TPOSCode = VS4TProduct.TPdtCode
GO

CREATE VIEW VS4VPOSLastPrice
AS 
SELECT VS4VPriceList2.*
FROM VS4VPOSLastPriceB AS Q INNER JOIN VS4VPriceList2 ON (Q.TPPMFromQuantity=VS4VPriceList2.TPPMFromQuantity) AND (Q.TPPMTPOSCode=VS4VPriceList2.TPPMTPOSCode) AND (Q.TPPLApproveDate=VS4VPriceList2.TPPLApproveDate) AND (Q.TPPMTARNCode=VS4VPriceList2.TPPMTARNCode) AND (Q.TPPMTUntCode=VS4VPriceList2.TPPMTUntCode)
GO

CREATE VIEW VS4VPOSMB2
AS 
SELECT VS4TPOS.*, VS4TPOSMB.*, VS4TProduct.*, VS4TUnit.*
FROM VS4TUnit INNER JOIN (VS4TProduct INNER JOIN (VS4TPOS INNER JOIN VS4TPOSMB ON VS4TPOS.TPOSCode = VS4TPOSMB.TPoMTPOSCode) ON VS4TProduct.TPdtCode = VS4TPOSMB.TPoMTPdtCode) ON VS4TUnit.TUntCode = VS4TProduct.TPdtTUntCode
GO

CREATE VIEW VS4VPOS
AS 
SELECT VS4TPOS.*, VS4VPOSMBQuery.VPoSMemberCount, VS4VPOSMBQuery.VPoMSetAvailable, VS4TUnit.*, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TBranch.TBraName, VS4TProductType.TPTTName, VS4TProductLine.TPdLName, VS4TProductSection.TPSEName, VS4TProductSec2.TPS2Name, VS4TProductGroup1.TPG1Name, VS4TProductGroup2.TPG2Name, VS4TProduct.*
FROM (((((((VS4TPOS INNER JOIN VS4VPOSMBQuery ON VS4TPOS.TPOSCode = VS4VPOSMBQuery.TPoMTPOSCode) LEFT JOIN VS4TBranch ON VS4TPOS.TPOSCode = VS4TBranch.TBraCode) LEFT JOIN (((VS4TProduct LEFT JOIN VS4TProductType ON VS4TProduct.TPdtTPTTCode = VS4TProductType.TPTTCode) LEFT JOIN VS4TProductLine ON VS4TProduct.TPdtTPDLCode = VS4TProductLine.TPdLCode) LEFT JOIN VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode) ON VS4TPOS.TPOSCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code) LEFT JOIN VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code) LEFT JOIN VS4TProductGroup2 ON VS4TProduct.TPdtTPG2Code = VS4TProductGroup2.TPG2Code) LEFT JOIN VS4TProject ON VS4TProduct.TPdtTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TUnit ON VS4TProduct.TPdtTUntCode = VS4TUnit.TUntCode
GO

CREATE VIEW VS4VPOSTransPay
AS 
SELECT VS4TPOSTrans.*, VS4TPOSTransPay.*
FROM VS4TPOSTrans LEFT JOIN VS4TPOSTransPay ON VS4TPOSTrans.TPTANo = VS4TPOSTransPay.TPPyTPTANo
GO

CREATE VIEW VS4VPOSPayTypeSum
AS 
SELECT VS4VPOSTransPay.TPTANo, VS4VPOSTransPay.TPTADate, VS4VPOSTransPay.TPTASaleInvoiceNo, VS4VPOSTransPay.TPTAPOSNo, VS4VPOSTransPay.TPTAParkNo, VS4VPOSTransPay.TPPyPaymentType, VS4VPOSTransPay.TPPyIsChange, VS4VPOSTransPay.TPPyCurrency, Sum(VS4VPOSTransPay.TPPyAmount) AS TPPyAmount, Sum(VS4VPOSTransPay.TPPyAmountInRate) AS TPPyAmountInRate, VS4VPOSTransPay.TPTACancelStatus
FROM VS4VPOSTransPay
GROUP BY VS4VPOSTransPay.TPTANo, VS4VPOSTransPay.TPTADate, VS4VPOSTransPay.TPTASaleInvoiceNo, VS4VPOSTransPay.TPTAPOSNo, VS4VPOSTransPay.TPTAParkNo, VS4VPOSTransPay.TPPyPaymentType, VS4VPOSTransPay.TPPyIsChange, VS4VPOSTransPay.TPPyCurrency, VS4VPOSTransPay.TPTACancelStatus
GO

CREATE VIEW VS4VPOSTransDetail
AS 
SELECT VS4TPOSTrans.*, VS4TPOSTransSub.*, VS4TProduct.TPdtCode, VS4TProduct.TPdtName, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TProduct.TPdtFactoryCode, VS4TPOS.TPOSPackAlias2, VS4TProductLine.TPdLCode, VS4TProductLine.TPdLName, VS4TProductSection.TPSECode, VS4TProductSection.TPSEName, VS4TProductSec2.TPS2Code, VS4TProductSec2.TPS2Name, VS4TProductSec3.TPS3Code, VS4TProductSec3.TPS3Name, VS4TProductSec4.TPS4Code, VS4TProductSec4.TPS4Name, VS4TProductGroup1.TPG1Code, VS4TProductGroup1.TPG1Name, VS4TProductGroup2.TPG2Code, VS4TProductGroup2.TPG2Name, VS4TProductGroup3.TPG3Code, VS4TProductGroup3.TPG3Name, VS4TProductGroup4.TPG4Code, VS4TProductGroup4.TPG4Name, VS4TAR.TARNTBsTCode, VS4TAR2.TAR2TPrvCode, VS4TAR.TARNTSAeCode, VS4TAR.TARNTARGCode, VS4TARGroup.TARGName, VS4TCountry.TCouName, VS4TAR.TARNTCouCode, VS4TProvince.TPrvName, VS4TSaleArea.TSAeName, VS4TSaleZone.TSZnName2, VS4TProject.TPrjName, VS4TBranch.TBraName, VS4TBusinessType.TBstName, VS4TAR.TARNName, VS4TProduct.TPdtStandardCost, VS4TProduct.TPdtTAPNCode, VS4TAP.TAPNName, VS4TPOS.TPOSSaleCount, VS4TProduct.TPdtTPPuCode, VS4TAP_1.TAPNName AS VPTATourName, VS4TAP_2.TAPNName AS VPTAGuideName, VS4TAPBranch.TAPUFullName AS VPTAtourBranch, VS4TSaleZoneGroup.TSZGName, VS4TFlight.TFliNationalCode, VS4TFlight.TFliTotalMale, VS4TFlight.TFliTotalFemale, VS4TFlight.TFliTotalChild, VS4TFlight.TFLiLicenseNoList
FROM (VS4TSaleZone LEFT JOIN VS4TSaleZoneGroup ON VS4TSaleZone.TSZnTSZGCode = VS4TSaleZoneGroup.TSZGCode) RIGHT JOIN (VS4TProductLine RIGHT JOIN ((VS4TPOS LEFT JOIN (((((((((VS4TProduct LEFT JOIN VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode) LEFT JOIN VS4TProductGroup4 ON VS4TProduct.TPdtTPG4Code = VS4TProductGroup4.TPG4Code) LEFT JOIN VS4TProductGroup3 ON VS4TProduct.TPdtTPG3Code = VS4TProductGroup3.TPG3Code) LEFT JOIN VS4TProductGroup2 ON VS4TProduct.TPdtTPG2Code = VS4TProductGroup2.TPG2Code) LEFT JOIN VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code) LEFT JOIN VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code) LEFT JOIN VS4TProductSec3 ON VS4TProduct.TPdtTPS3Code = VS4TProductSec3.TPS3Code) LEFT JOIN VS4TProductSec4 ON VS4TProduct.TPdtTPS4Code = VS4TProductSec4.TPS4Code) LEFT JOIN VS4TAP ON VS4TProduct.TPdtTAPNCode = VS4TAP.TAPNCode) ON VS4TPOS.TPOSCode = VS4TProduct.TPdtCode) INNER JOIN ((VS4TCountry RIGHT JOIN (VS4TBusinessType RIGHT JOIN ((((((((((VS4TPOSTrans LEFT JOIN VS4TBranch ON VS4TPOSTrans.TPTATBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TAR ON VS4TPOSTrans.TPTATARNCode = VS4TAR.TARNCode) LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN VS4TProject ON VS4TPOSTrans.TPTATPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TAP AS VS4TAP_1 ON VS4TPOSTrans.TPTATAPNCode = VS4TAP_1.TAPNCode) LEFT JOIN VS4TAP AS VS4TAP_2 ON VS4TPOSTrans.TPTATAPNCode2 = VS4TAP_2.TAPNCode) LEFT JOIN VS4TAPBranch ON (VS4TPOSTrans.TPTATAPNCode = VS4TAPBranch.TAPUTAPNCode) AND (VS4TPOSTrans.TPTATAPUCode = VS4TAPBranch.TAPUCode)) LEFT JOIN VS4TFlight ON (VS4TPOSTrans.TPTADate = VS4TFlight.TFliDate) AND (VS4TPOSTrans.TPTAParkNo = VS4TFlight.TFliParkNo)) LEFT JOIN (VS4TAR2 LEFT JOIN VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) ON VS4TBusinessType.TBsTCode = VS4TAR.TARNTBsTCode) ON VS4TCountry.TCouCode = VS4TAR.TARNTCouCode) INNER JOIN VS4TPOSTransSub ON VS4TPOSTrans.TPTANo = VS4TPOSTransSub.TPTSTPTANo) ON VS4TPOS.TPOSCode = VS4TPOSTransSub.TPTSTPOSCode) ON VS4TProductLine.TPdLCode = VS4TProduct.TPdtTPDLCode) ON VS4TSaleZone.TSZnCode = VS4TSaleArea.TSaeTSZnCode
GO

CREATE VIEW VS4VPOSSumTopA
AS 
SELECT *
FROM VS4VPOSTransDetail
WHERE (((VS4VPOSTransDetail.TPTADate)>='2006-10-1' And (VS4VPOSTransDetail.TPTADate)<='2006-10-31'))
GO

CREATE VIEW VS4VPOSSumTop
AS 
SELECT VS4VPOSSumTopA.TPdtCode, VS4VPOSSumTopA.TPdtFactoryCode, VS4VPOSSumTopA.TPdtName, Sum(VS4VPOSSumTopA.TPTSNetAmount) AS TPTSNetAmount, Sum(VS4VPOSSumTopA.TPTSQuantity) AS TPTSQuantity, VS4VPOSSumTopA.TPdtTUntCode
FROM VS4VPOSSumTopA
GROUP BY VS4VPOSSumTopA.TPdtCode, VS4VPOSSumTopA.TPdtFactoryCode, VS4VPOSSumTopA.TPdtName, VS4VPOSSumTopA.TPdtTUntCode
GO

CREATE VIEW VS4VPOSSumTopSec
AS 
SELECT VS4VPOSSumTopA.TPseCode, VS4VPOSSumTopA.TPSeName, Sum(VS4VPOSSumTopA.TPTSNetAmount) AS TPTSNetAmount, Sum(VS4VPOSSumTopA.TPTSQuantity) AS TPTSQuantity
FROM VS4VPOSSumTopA
GROUP BY VS4VPOSSumTopA.TPseCode, VS4VPOSSumTopA.TPSeName, VS4VPOSSumTopA.TPdtTUntCode
GO

CREATE VIEW VS4VPOSTrans
AS 
SELECT VS4TPOSTrans.*, VS4TPOSTransSub.*, VS4TPOS.*, TPOSSaleCount*TPTSNetAmount AS VPSCSaleAmount, VS4TBranch.TBraCode, VS4TBranch.TBraName, VS4TBranch.TBraAddressBill, VS4TBranch.TBraTaxNo, VS4TBranch.TBraPhone, VS4TBranch.TBraFax, VS4TAP.TAPNName AS VPTATourName, VS4TAP_1.TAPNName AS VPTAGuideName, VS4TAPBranch.TAPUFullName AS VPTAtourBranch, VS4TPOSTransPay.TPPyPaymentType, VS4TPOSTransPay.TPPyCardType
FROM VS4TPOS RIGHT JOIN ((((((VS4TPOSTrans LEFT JOIN VS4TBranch ON VS4TPOSTrans.TPTATBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TAP ON VS4TPOSTrans.TPTATAPNCode = VS4TAP.TAPNCode) LEFT JOIN VS4TAP AS VS4TAP_1 ON VS4TPOSTrans.TPTATAPNCode2 = VS4TAP_1.TAPNCode) LEFT JOIN VS4TAPBranch ON (VS4TPOSTrans.TPTATAPNCode = VS4TAPBranch.TAPUTAPNCode) AND (VS4TPOSTrans.TPTATAPUCode = VS4TAPBranch.TAPUCode)) LEFT JOIN VS4TPOSTransPay ON VS4TPOSTrans.TPTANo = VS4TPOSTransPay.TPPyTPTANo) LEFT JOIN VS4TPOSTransSub ON VS4TPOSTrans.TPTANo = VS4TPOSTransSub.TPTSTPTANo) ON VS4TPOS.TPOSCode = VS4TPOSTransSub.TPTSTPOSCode
WHERE (((VS4TPOSTransPay.TPPyLn)=1 Or (VS4TPOSTransPay.TPPyLn) Is Null))
GO

CREATE VIEW VS4VPOSSumTopFac
AS 
SELECT VS4VPOSSumTopA.TPdtFactoryCode, VS4VPOSSumTopA.TPdtName, Sum(VS4VPOSSumTopA.TPTSNetAmount) AS TPTSNetAmount, Sum(VS4VPOSSumTopA.TPTSQuantity) AS TPTSQuantity, VS4VPOSSumTopA.TPdtTUntCode
FROM VS4VPOSSumTopA
GROUP BY VS4VPOSSumTopA.TPdtFactoryCode, VS4VPOSSumTopA.TPdtName, VS4VPOSSumTopA.TPdtTUntCode
GO

CREATE VIEW VS4VPOSEmpSumAll
AS 
SELECT VS4VPOSTransEmp.TPTATCurCode, Sum(VS4VPOSTransEmp.TPTAPremiumTotal) AS TPTAPremiumTotal, Sum(VS4VPOSTransEmp.TPTACustomTotal1) AS TPTACustomTotal1, Sum(VS4VPOSTransEmp.TPTACustomTotal2) AS TPTACustomTotal2, Sum(VS4VPOSTransEmp.TPTACustomTotal3) AS TPTACustomTotal3, Sum(VS4VPOSTransEmp.TPTAGrandTotal) AS TPTAGrandTotal, Sum(VS4VPOSTransEmp.TPTASubTotal) AS TPTASubTotal, Sum(VS4VPOSTransEmp.TPTAVATTotal) AS TPTAVATTotal, Sum(VS4VPOSTransEmp.TPTAAdjustTotal) AS TPTAAdjustTotal, Sum(VS4VPOSTransEmp.TPTAChangeTotal) AS TPTAChangeTotal, VS4VPOSTransEmp.TPTACancelStatus, VS4VPOSTransEmp.TPTETEmpCode, VS4VPOSTransEmp.TPTEName, VS4VPOSTransEmp.TPTEPositionName, VS4VPOSTransEmp.TPTEPositionAlias, VS4VPOSTransEmp.TPTETEmGCode, Sum(VS4VPOSTransEmp.TPTEFee) AS TPTEFee, Sum(VS4VPOSTransEmp.TPTECustom1) AS TPTECustom1, Sum(VS4VPOSTransEmp.TPTECustom2) AS TPTECustom2, Sum(VS4VPOSTransEmp.TPTECustom3) AS TPTECustom3, VS4VPOSTransEmp.TPTETCurCode, Sum(VS4VPOSTransEmp.TPTADiscountTotal) AS TPTADiscountTotal
FROM VS4VPOSTransEmp
GROUP BY VS4VPOSTransEmp.TPTATCurCode, VS4VPOSTransEmp.TPTACancelStatus, VS4VPOSTransEmp.TPTETEmpCode, VS4VPOSTransEmp.TPTEName, VS4VPOSTransEmp.TPTEPositionName, VS4VPOSTransEmp.TPTEPositionAlias, VS4VPOSTransEmp.TPTETEmGCode, VS4VPOSTransEmp.TPTETCurCode
GO

CREATE VIEW VS4VPOSTransEntru
AS 
SELECT VS4TPOSTrans.*, VS4TPOSTransSub.*, VS4TProductPURType.TPPuName, VS4TProductLine.TPdLCode, VS4TProductLine.TPdLName
FROM (VS4TPOS INNER JOIN (VS4TPOSTrans INNER JOIN VS4TPOSTransSub ON VS4TPOSTrans.TPTANo = VS4TPOSTransSub.TPTSTPTANo) ON VS4TPOS.TPOSCode = VS4TPOSTransSub.TPTSTPOSCode) LEFT JOIN (VS4TProductSection RIGHT JOIN (VS4TProductLine RIGHT JOIN (VS4TProductPURType RIGHT JOIN VS4TProduct ON VS4TProductPURType.TPPuCode = VS4TProduct.TPdtTPPuCode) ON VS4TProductLine.TPdLCode = VS4TProduct.TPdtTPDLCode) ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode) ON VS4TPOS.TPOSCode = VS4TProduct.TPdtCode
GO

CREATE VIEW VS4VPOSTransfer
AS 
SELECT VS4TPOSTransfer.*, VS4TPOSTransferMB.*, VS4TAR.*, VS4TCompanyBank.*, VS4TBank.*, VS4TPaymentType.*, VS4TACChart.*, VS4TBranch.TBraName
FROM (VS4TPOSTransfer LEFT JOIN VS4TBranch ON VS4TPOSTransfer.TPTRTBraCode=VS4TBranch.TBraCode) RIGHT JOIN (VS4TPaymentType RIGHT JOIN ((VS4TBank RIGHT JOIN VS4TCompanyBank ON VS4TBank.TBnkCode=VS4TCompanyBank.TCBBTBnkCode) RIGHT JOIN (VS4TAR RIGHT JOIN (VS4TPOSTransferMB LEFT JOIN VS4TACChart ON VS4TPOSTransferMB.TPTMTACCCode=VS4TACChart.TACCCode) ON VS4TAR.TARNCode=VS4TPOSTransferMB.TPTMTARNCode) ON VS4TCompanyBank.TCBBNo=VS4TPOSTransferMB.TPTMTCBBNo) ON VS4TPaymentType.TPyTAlias=VS4TPOSTransferMB.TPTMPaymentType) ON VS4TPOSTransfer.TPTRNo=VS4TPOSTransferMB.TPTMTPTRNo
GO

CREATE VIEW VS4VPOSTransSumPOS
AS 
SELECT VS4TPOSTrans.TPTADate, VS4TPOSTrans.TPTAPOSNo, VS4TPOSTrans.TPTAParkNo, VS4TPOSTrans.TPTATARNCode, VS4TPOSTrans.TPTACustomerName, VS4TPOSTrans.TPTATCurCode, Sum(VS4TPOSTrans.TPTAGrandTotal) AS TPTAGrandTotal, Sum(VS4TPOSTrans.TPTASubTotal) AS TPTASubTotal, Sum(VS4TPOSTrans.TPTADiscountTotal) AS TPTADiscountTotal, Sum(VS4TPOSTrans.TPTAVATTotal) AS TPTAVATTotal, Sum(VS4TPOSTrans.TPTATaxBase) AS TPTATaxBase, Sum(VS4TPOSTrans.TPTAAdjustTotal) AS TPTAAdjustTotal, Sum(VS4TPOSTrans.TPTAChangeTotal) AS TPTAChangeTotal, Sum(VS4TPOSTrans.TPTAPremiumTotal) AS TPTAPremiumTotal, Sum(VS4TPOSTrans.TPTACustomTotal1) AS TPTACustomTotal1, Sum(VS4TPOSTrans.TPTACustomTotal2) AS TPTACustomTotal2, Sum(VS4TPOSTrans.TPTACustomTotal3) AS TPTACustomTotal3, VS4TPOSTrans.TPTACancelStatus, VS4TPOSTrans.TPTATBraCode
FROM VS4TPOSTrans
GROUP BY VS4TPOSTrans.TPTADate, VS4TPOSTrans.TPTAPOSNo, VS4TPOSTrans.TPTAParkNo, VS4TPOSTrans.TPTATARNCode, VS4TPOSTrans.TPTACustomerName, VS4TPOSTrans.TPTATCurCode, VS4TPOSTrans.TPTACancelStatus, VS4TPOSTrans.TPTATBraCode
GO

CREATE VIEW VS4VPOSTransGuide
AS 
SELECT VS4TPOSTrans.*, VS4TPOSTransGuide.*
FROM VS4TPOSTrans INNER JOIN VS4TPOSTransGuide ON VS4TPOSTrans.TPTANo = VS4TPOSTransGuide.TPTGTPTANo
GO

CREATE VIEW VS4VPOSPayTypeAlli
AS 
SELECT VS4VPOSTransPay.TPTADate, VS4VPOSTransPay.TPPyPaymentType, Sum(VS4VPOSTransPay.TPPyAmount) AS TPPyAmount, VS4VPOSTransPay.TPTANo, VS4VPOSTransPay.TPTACancelStatus
FROM VS4VPOSTransPay
GROUP BY VS4VPOSTransPay.TPTADate, VS4VPOSTransPay.TPPyPaymentType, VS4VPOSTransPay.TPTANo, VS4VPOSTransPay.TPTACancelStatus
HAVING (((VS4VPOSTransPay.TPTACancelStatus)<>1))
GO

CREATE VIEW VS4VPOSTransFlight
AS 
SELECT VS4VFlightVehicle.*, VS4VPOSTransSumPOS.*
FROM VS4VFlightVehicle LEFT JOIN VS4VPOSTransSumPOS ON (VS4VFlightVehicle.TFliParkNo=VS4VPOSTransSumPOS.TPTAParkNo) AND (VS4VFlightVehicle.TFliDate=VS4VPOSTransSumPOS.TPTADate)
GO

CREATE VIEW VS4VPOSTransSumTP
AS 
SELECT VS4TPOSTrans.TPTADate, VS4TPOSTrans.TPTANo, VS4TPOSTrans.TPTAParkNo, VS4TPOSTrans.TPTATARNCode, VS4TPOSTrans.TPTACustomerName, VS4TPOSTrans.TPTATCurCode, Sum(VS4TPOSTrans.TPTAGrandTotal) AS TPTAGrandTotal, Sum(VS4TPOSTrans.TPTASubTotal) AS TPTASubTotal, Sum(VS4TPOSTrans.TPTADiscountTotal) AS TPTADiscountTotal, Sum(VS4TPOSTrans.TPTAVATRate) AS TPTAVATPercent, Sum(VS4TPOSTrans.TPTAVATTotal) AS TPTAVATTotal, Sum(VS4TPOSTrans.TPTATaxBase) AS TPTATaxBase, Sum(VS4TPOSTrans.TPTAAdjustTotal) AS TPTAAdjustTotal, Sum(VS4TPOSTrans.TPTAChangeTotal) AS TPTAChangeTotal, VS4TPOSTransPay.TPPyPaymentType, VS4TPOSTrans.TPTATBraCode
FROM VS4TPOSTrans INNER JOIN VS4TPOSTransPay ON VS4TPOSTrans.TPTANo = VS4TPOSTransPay.TPPyTPTANo
GROUP BY VS4TPOSTrans.TPTADate, VS4TPOSTrans.TPTANo, VS4TPOSTrans.TPTAParkNo, VS4TPOSTrans.TPTATARNCode, VS4TPOSTrans.TPTACustomerName, VS4TPOSTrans.TPTATCurCode, VS4TPOSTransPay.TPPyPaymentType, VS4TPOSTrans.TPTATBraCode
GO

CREATE VIEW VS4VPQ
AS 
SELECT VS4TPQ.*, VS4TPQMB.*, VS4TProduct.*
FROM VS4TPQ INNER JOIN (VS4TPQMB LEFT JOIN VS4TProduct ON VS4TPQMB.TPQMProductCode=VS4TProduct.TPdtCode) ON VS4TPQ.TPQDNo=VS4TPQMB.TPQMTPQDNo
GO

CREATE VIEW VS4VPR
AS 
SELECT VS4TPR.*, VS4TPRMB.*, VS4TJob.*, VS4TProduct.TPdtImage1, VS4TProduct.TPdtIcon1, VS4TProduct2.*, VS4TSection.TSecName, VS4TDepartment.TDepName, VS4TDivision.TDivName, VS4TProject.TPrjCode, VS4TProject.TPrjName, VS4TProject.TPrjDocCode, VS4TProject.TPrjMode, VS4TPRBook.TPRBCode, VS4TPRBook.TPRBName, VS4TPRBook.TPRBDocCode, VS4TProduct.TPdtTAPNCode, VS4TBranch.TBraCode, VS4TBranch.TBraName, VS4TBranch.TBraName2, VS4TAP.TAPNName, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TProduct_1.TPdtName AS VPRDTPdtName, VS4TProduct_1.TPdtTUntCode AS VPRDTPdtTUntCode, VS4TProduct_1.TPdtTUntCode2 AS VPRDTPdtTUntCode2, VS4TProduct_1.TPdtTUntCode3 AS VPRDTPdtTUntCode3
FROM (VS4TPRBook RIGHT JOIN (((((((VS4TPR LEFT JOIN VS4TJob ON VS4TPR.TPRDTJobNo = VS4TJob.TJobNo) LEFT JOIN VS4TProject ON VS4TPR.TPRDTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TSection ON VS4TPR.TPRDTSecCode = VS4TSection.TSecCode) LEFT JOIN VS4TDepartment ON VS4TPR.TPRDTDepCode = VS4TDepartment.TDepCode) LEFT JOIN VS4TDivision ON VS4TPR.TPRDTDivCode = VS4TDivision.TDivCode) LEFT JOIN VS4TBranch ON VS4TPR.TPRDTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TAP ON VS4TPR.TPRDTAPNCode = VS4TAP.TAPNCode) ON VS4TPRBook.TPRBCode = VS4TPR.TPRDTPRBCode) INNER JOIN (((VS4TPRMB LEFT JOIN VS4TProduct ON VS4TPRMB.TPRMTPdtCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TProduct AS VS4TProduct_1 ON VS4TPRMB.TPRMMapTPdtCode = VS4TProduct_1.TPdtCode) LEFT JOIN VS4TProduct2 ON VS4TProduct.TPdtCode = VS4TProduct2.TPd2TPdtCode) ON VS4TPR.TPRDNo = VS4TPRMB.TPRMTPRDNo
GO

CREATE VIEW VS4VPR2LotIn
AS 
SELECT VS4TPRMB.*, VS4TPO.TPODNo, VS4TPO.TPODType, VS4TPO.TPODDate, VS4TPO.TPODDueDate, VS4TPO.TPODDeliveryDate, VS4TPO.TPODDeliveryTo, VS4TPO.TPODTAPNCode, VS4TPO.TPODSupplierName, VS4TPOMB.*, VS4TPODelivery.*, VS4TPO.TPODCountryOrigin, VS4TCountry.TCouName, VS4TPO.TPODTPrjCode, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TPO.TPODTBraCode, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TAP.TAPNTBsTCode, VS4TBusinessType.TBstName, VS4TProduct.TPdtTPTTCode, VS4TProductType.TPTTName, VS4TProduct.TPdtTPDLCode, VS4TProductLine.TPdLName, VS4TProduct.TPdtTPSECode, VS4TProductSection.TPSEName, VS4TProduct.TPdtTPG1Code, VS4TProductGroup1.TPG1Name, VS4TPO.TPODApproveStatus, VS4TPO.TPODConfirmStatus, VS4TPO.TPODCancelStatus, VS4TAP.TAPNTAPGCode, VS4TAPGroup.TAPGName, VS4TProduct2.TPd2ScrapPCMRP, VS4TProduct2.TPd2ScrapPCReceive, VS4TProduct2.TPd2ScrapPCSend, VS4TProduct2.TPd2CostFormula, VS4TPR.TPRDNo, VS4TPR.TPRDDate, VS4TPR.TPRDJobCode, VS4TPR.TPRDTJobNo, VS4TPR.TPRDTJbMLn, VS4TPR.TPRDTPrjCode, VS4TPR.TPRDTSecCode, VS4TPR.TPRDTDepCode, VS4TPR.TPRDTDivCode, VS4TPR.TPRDTBraCode, VS4TPR.TPRDDescription, VS4TInventory.TInvNo, VS4TInventory.TInvRefNo, VS4TInventory.TInvRefDate, VS4TInventory.TInvRefNo2, VS4TInventory.TInvRefDate2, VS4TInventory.TInvDate, VS4TInventoryMB.TInMLotNo, VS4TInventoryMB.TInMLotDate, VS4TInventoryMB.TInMAmouQuantity, VS4TInventoryMB.TInMAmouQuantity2, VS4TInventoryMB.TInMAmouQuantity3, VS4TInventoryMB.TInMTInTAlias, VS4TInventoryLOT.TIMCIsPremium, VS4TInventoryLOT.TIMCPremiumNote, VS4TInventoryLOT.TIMCLastUnitCost, VS4TInventoryLOT.TIMCInputCost, VS4TInventoryLOT.TIMCUnitCost, VS4TInventoryLOT.TIMCUnitCalc, VS4TInventoryMB.TInMQuantityCalc, VS4TInventoryMB.TInMAmount, VS4TInventoryMB.TInMStatus, VS4TInventoryMB.TInMTLctCode, VS4TInventoryMB.TInMCustom1, VS4TInventoryLOT.TIMCJobCode, VS4TInventoryMB.TInMTPdtCode, VS4TWarehouse.TWahCode
FROM VS4TWarehouse RIGHT JOIN ((((VS4TPR LEFT JOIN VS4TSection ON VS4TPR.TPRDTSecCode = VS4TSection.TSecCode) LEFT JOIN VS4TDepartment ON VS4TPR.TPRDTDepCode = VS4TDepartment.TDepCode) LEFT JOIN VS4TDivision ON VS4TPR.TPRDTDivCode = VS4TDivision.TDivCode) INNER JOIN ((VS4TBusinessType RIGHT JOIN (((VS4TAP LEFT JOIN VS4TAPGroup ON VS4TAP.TAPNTAPGCode = VS4TAPGroup.TAPGCode) LEFT JOIN VS4TCountry ON VS4TAP.TAPNTCouCode = VS4TCountry.TCouCode) RIGHT JOIN ((VS4TPO LEFT JOIN VS4TProject ON VS4TPO.TPODTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TPO.TPODTBraCode = VS4TBranch.TBraCode) ON VS4TAP.TAPNCode = VS4TPO.TPODTAPNCode) ON VS4TBusinessType.TBsTCode = VS4TAP.TAPNTBsTCode) RIGHT JOIN ((VS4TProductLine RIGHT JOIN (VS4TInventory RIGHT JOIN (((VS4TProductType RIGHT JOIN (((((VS4TPRMB LEFT JOIN VS4TPOMB ON (VS4TPRMB.TPRMTPRDNo = VS4TPOMB.TPOBSourceNo) AND (VS4TPRMB.TPRMLn = VS4TPOMB.TPOBSourceLn)) LEFT JOIN VS4TPODelivery ON (VS4TPOMB.TPOBTPODNo = VS4TPODelivery.TPDETPOBTPODNo) AND (VS4TPOMB.TPOBLn = VS4TPODelivery.TPDETPOBLn)) LEFT JOIN VS4TProduct ON VS4TPOMB.TPOBTPdtCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code) LEFT JOIN VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode) ON VS4TProductType.TPTTCode = VS4TProduct.TPdtTPTTCode) LEFT JOIN VS4TInventoryLOT ON (VS4TPODelivery.TPDELn = VS4TInventoryLOT.TIMCTPDELn) AND (VS4TPODelivery.TPDETPOBLn = VS4TInventoryLOT.TIMCTPOBLn) AND (VS4TPODelivery.TPDETPOBTPODNo = VS4TInventoryLOT.TIMCTPODNo)) LEFT JOIN (VS4TInventoryMB LEFT JOIN VS4TLocation ON VS4TInventoryMB.TInMTLctCode = VS4TLocation.TLctCode) ON (VS4TInventoryLOT.TIMCLotDate = VS4TInventoryMB.TInMLotDate) AND (VS4TInventoryLOT.TIMCLotNo = VS4TInventoryMB.TInMLotNo) AND (VS4TInventoryLOT.TIMCSerialNo = VS4TInventoryMB.TInMSerialNo) AND (VS4TInventoryLOT.TIMCCustom1 = VS4TInventoryMB.TInMCustom1) AND (VS4TInventoryLOT.TIMCTPdtCode = VS4TInventoryMB.TInMTPdtCode)) ON VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo) ON VS4TProductLine.TPdLCode = VS4TProduct.TPdtTPDLCode) LEFT JOIN VS4TProduct2 ON VS4TProduct.TPdtCode = VS4TProduct2.TPd2TPdtCode) ON VS4TPO.TPODNo = VS4TPOMB.TPOBTPODNo) ON VS4TPR.TPRDNo = VS4TPRMB.TPRMTPRDNo) ON VS4TWarehouse.TWahCode = VS4TLocation.TLctTWahCode
GO

CREATE VIEW VS4VPR2PO
AS 
SELECT VS4TPR.*, VS4TPRMB.*, VS4TPO.TPODNo, VS4TPO.TPODType, VS4TPO.TPODDate, VS4TPO.TPODDueDate, VS4TPO.TPODDeliveryDate, VS4TPO.TPODDeliveryTo, VS4TPO.TPODTAPNCode, VS4TPO.TPODSupplierName, VS4TPOMB.*, VS4TPO.TPODCountryOrigin, VS4TCountry.TCouName, VS4TPO.TPODTPrjCode, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TPO.TPODTBraCode, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TAP.TAPNTBsTCode, VS4TBusinessType.TBstName, VS4TProduct.TPdtTPTTCode, VS4TProductType.TPTTName, VS4TProduct.TPdtTPDLCode, VS4TProductLine.TPdLName, VS4TProduct.TPdtTPSECode, VS4TProductSection.TPSEName, VS4TProduct.TPdtTPG1Code, VS4TProductGroup1.TPG1Name, VS4TPO.TPODApproveStatus, VS4TPO.TPODConfirmStatus, VS4TPO.TPODCancelStatus, VS4TAP.TAPNTAPGCode, VS4TAPGroup.TAPGName, VS4TProduct2.TPd2ScrapPCMRP, VS4TProduct2.TPd2ScrapPCReceive, VS4TProduct2.TPd2ScrapPCSend, VS4TProduct2.TPd2TaxRate, VS4TProduct2.TPd2Costformula, VS4TPODelivery.TPDETPOBTPODNo, VS4TPODelivery.TPDETPOBLn, VS4TPODelivery.TPDELn, VS4TPODelivery.TPDEDate, VS4TPODelivery.TPDEDateTime, VS4TPODelivery.TPDEQuantity, VS4TPODelivery.TPDEQuantity2, VS4TPODelivery.TPDEQuantity3, VS4TPODelivery.TPDETotalDelivery, VS4TPODelivery.TPDETotalDelivery2, VS4TPODelivery.TPDETotalDelivery3, VS4TPODelivery.TPDETotalArrear, VS4TPODelivery.TPDETotalArrear2, VS4TPODelivery.TPDETotalArrear3, VS4TPODelivery.TPDEMapTPdtCode, VS4TPODelivery.TPDEMapTUntCode, VS4TPODelivery.TPDEMapUnitRatio, VS4TPODelivery.TPDEQuantityBase, VS4TPODelivery.TPDEDeliveryBase, VS4TPODelivery.TPDEArrearBase, VS4TPODelivery.TPDELinkStatus, VS4TPODelivery.TPDELinkBy, VS4TPODelivery.TPDELinkDate, VS4TPODelivery.TPDETotalOntime, VS4TPODelivery.TPDETotalDelay, VS4TPODelivery.TPDETLctCode
FROM (((VS4TPR LEFT JOIN VS4TDepartment ON VS4TPR.TPRDTDepCode = VS4TDepartment.TDepCode) LEFT JOIN VS4TDivision ON VS4TPR.TPRDTDivCode = VS4TDivision.TDivCode) LEFT JOIN VS4TSection ON VS4TPR.TPRDTSecCode = VS4TSection.TSecCode) LEFT JOIN (((((((VS4TPO LEFT JOIN VS4TCountry ON VS4TPO.TPODCountryOrigin = VS4TCountry.TCouCode) LEFT JOIN VS4TProject ON VS4TPO.TPODTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TPO.TPODTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TAP ON VS4TPO.TPODTAPNCode = VS4TAP.TAPNCode) LEFT JOIN VS4TBusinessType ON VS4TAP.TAPNTBsTCode = VS4TBusinessType.TBsTCode) LEFT JOIN VS4TAPGroup ON VS4TAP.TAPNTAPGCode = VS4TAPGroup.TAPGCode) RIGHT JOIN ((((((((VS4TPRMB LEFT JOIN VS4TPOMB ON (VS4TPRMB.TPRMLn = VS4TPOMB.TPOBSourceLn) AND (VS4TPRMB.TPRMTPRDNo = VS4TPOMB.TPOBSourceNo)) LEFT JOIN VS4TPODelivery ON (VS4TPOMB.TPOBLn = VS4TPODelivery.TPDETPOBLn) AND (VS4TPOMB.TPOBTPODNo = VS4TPODelivery.TPDETPOBTPODNo)) LEFT JOIN VS4TProduct ON VS4TPOMB.TPOBTPdtCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TProductType ON VS4TProduct.TPdtTPTTCode = VS4TProductType.TPTTCode) LEFT JOIN VS4TProductLine ON VS4TProduct.TPdtTPDLCode = VS4TProductLine.TPdLCode) LEFT JOIN VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode) LEFT JOIN VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code) LEFT JOIN VS4TProduct2 ON VS4TProduct.TPdtCode = VS4TProduct2.TPd2TPdtCode) ON VS4TPO.TPODNo = VS4TPOMB.TPOBTPODNo) ON VS4TPR.TPRDNo = VS4TPRMB.TPRMTPRDNo
GO

CREATE VIEW VS4VPR2SO
AS 
SELECT VS4TSO.TSODNo, VS4TSO.TSODCode, VS4TSO.TSODType, VS4TSO.TSODDate, VS4TSO.TSODDueDate, VS4TSO.TSODRefNo, VS4TSO.TSODRefDate, VS4TSO.TSODDeliveryDate, VS4TSO.TSODTEmpCode, VS4TSO.TSODSaleName, VS4TSO.TSODDeliveryTo, VS4TSO.TSODTARNCode, VS4TSO.TSODContactNote, VS4TSO.TSODContactName, VS4TSO.TSODCustomerName, VS4TSO.TSODDayAvailable, VS4TSOMB.*, VS4TProject.TPrjName, VS4TJob.TJobNo, VS4TJob.TJobCode, VS4TPR.*, VS4TPRMB.*, VS4TSO.TSODTPrjCode, VS4TProduct2.*, VS4TProduct.TPdtName, VS4TProduct.TPdtName2
FROM (VS4TPR RIGHT JOIN (((VS4TPRMB LEFT JOIN VS4TProduct ON VS4TPRMB.TPRMTPdtCode=VS4TProduct.TPdtCode) LEFT JOIN (VS4TJob LEFT JOIN (VS4TSO LEFT JOIN VS4TProject ON VS4TSO.TSODTPrjCode=VS4TProject.TPrjCode) ON VS4TJob.TJobRefNo=VS4TSO.TSODNo) ON VS4TPRMB.TPRMTJobNo=VS4TJob.TJobNo) LEFT JOIN VS4TProduct2 ON VS4TProduct.TPdtCode=VS4TProduct2.TPd2TPdtCode) ON VS4TPR.TPRDNo=VS4TPRMB.TPRMTPRDNo) LEFT JOIN VS4TSOMB ON VS4TSO.TSODNo=VS4TSOMB.TSOBTSODNo
GO

CREATE VIEW VS4VPRArrearA
AS 
SELECT *
FROM VS4TPOMB
WHERE (((VS4TPOMB.TPOBTotalArrear)>0))
GO

CREATE VIEW VS4VPRArrear2
AS 
SELECT VS4TPRMB.TPRMTPdtCode, VS4TPRMB.TPRMTUntCode, VS4TPRMB.TPRMQuantity, VS4TPRMB.TPRMTotalArrear
FROM VS4TPR INNER JOIN VS4TPRMB ON VS4TPR.TPRDNo = VS4TPRMB.TPRMTPRDNo
GROUP BY VS4TPRMB.TPRMTPdtCode, VS4TPRMB.TPRMTUntCode, VS4TPRMB.TPRMQuantity, VS4TPRMB.TPRMTotalArrear
GO

CREATE VIEW VS4VPRArrear
AS 
SELECT VS4TPO.TPODNo, VS4TPR.TPRDNo, VS4TPR.TPRDType, VS4TJob.TJobCode, VS4TPR.TPRDTJobNo, VS4TPR.TPRDTJbMLn, VS4TPR.TPRDTPrjCode, VS4TPR.TPRDTJPDNo, VS4TPR.TPRDTJPMLn, VS4TJob.TJobTARNCode, VS4TAR.TARNName, VS4TPR.TPRDRefNo, VS4TPRBook.TPRBName, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TPO.TPODApproveStatus, VS4TPO.TPODCancelStatus, VS4TProject.TPrjCode, VS4VPRArrearA.TPOBTPdtCode, VS4VPRArrearA.TPOBProductName, VS4VPRArrearA.TPOBCustom1, VS4VPRArrearA.TPOBCustom2, VS4VPRArrearA.TPOBCustom3, VS4VPRArrearA.TPOBCustom4, VS4VPRArrearA.TPOBCustom5, VS4VPRArrearA.TPOBTUntCode, Sum(VS4VPRArrearA.TPOBQuantity) AS TPOBQuantity, Sum(VS4VPRArrearA.TPOBTotalDelivery) AS TPOBTotalDelivery, Sum(VS4VPRArrearA.TPOBTotalArrear) AS TPOBTotalArrear, VS4TPO.TPODDate, VS4TAR.TARNCode, VS4TAP.TAPNCode, VS4TAP.TAPNName, VS4TPR.TPRDTBraCode, VS4TPR.TPRDTDivCode, VS4TPR.TPRDTDepCode, VS4TPR.TPRDTSecCode, VS4TPR.TPRDTPRBCode, VS4TPO.TPODType, VS4TPR.TPRDDate
FROM VS4TPRBook RIGHT JOIN (VS4TAP RIGHT JOIN (((((((((VS4TPO RIGHT JOIN VS4VPRArrearA ON VS4TPO.TPODNo = VS4VPRArrearA.TPOBTPODNo) RIGHT JOIN VS4TPR ON VS4VPRArrearA.TPOBSourceNo = VS4TPR.TPRDNo) LEFT JOIN VS4TJob ON VS4TPR.TPRDTJobNo = VS4TJob.TJobNo) LEFT JOIN VS4TAR ON VS4TJob.TJobTARNCode = VS4TAR.TARNCode) LEFT JOIN VS4TProject ON VS4TPR.TPRDTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TPR.TPRDTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TDivision ON VS4TPR.TPRDTDivCode = VS4TDivision.TDivCode) LEFT JOIN VS4TDepartment ON VS4TPR.TPRDTDepCode = VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TPR.TPRDTSecCode = VS4TSection.TSecCode) ON VS4TAP.TAPNCode = VS4TPO.TPODTAPNCode) ON VS4TPRBook.TPRBCode = VS4TPR.TPRDTPRBCode
GROUP BY VS4TPO.TPODNo, VS4TPR.TPRDNo, VS4TPR.TPRDType, VS4TJob.TJobCode, VS4TPR.TPRDTJobNo, VS4TPR.TPRDTJbMLn, VS4TPR.TPRDTPrjCode, VS4TPR.TPRDTJPDNo, VS4TPR.TPRDTJPMLn, VS4TJob.TJobTARNCode, VS4TAR.TARNName, VS4TPR.TPRDRefNo, VS4TPRBook.TPRBName, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TPO.TPODApproveStatus, VS4TPO.TPODCancelStatus, VS4TProject.TPrjCode, VS4VPRArrearA.TPOBTPdtCode, VS4VPRArrearA.TPOBProductName, VS4VPRArrearA.TPOBCustom1, VS4VPRArrearA.TPOBCustom2, VS4VPRArrearA.TPOBCustom3, VS4VPRArrearA.TPOBCustom4, VS4VPRArrearA.TPOBCustom5, VS4VPRArrearA.TPOBTUntCode, VS4TPO.TPODDate, VS4TAR.TARNCode, VS4TAP.TAPNCode, VS4TAP.TAPNName, VS4TPR.TPRDTBraCode, VS4TPR.TPRDTDivCode, VS4TPR.TPRDTDepCode, VS4TPR.TPRDTSecCode, VS4TPR.TPRDTPRBCode, VS4TPO.TPODType, VS4TPR.TPRDDate, VS4TPRBook.TPRBName
HAVING (((VS4TPO.TPODApproveStatus)=1) AND ((VS4TPO.TPODCancelStatus)=0))
GO

CREATE VIEW VS4VPRHead
AS 
SELECT VS4TPR.*, VS4TProject.*, VS4TJob.*, VS4TBranch.*, VS4TDivision.*, VS4TDepartment.*, VS4TSection.*, VS4TSO.TSODTARNCode, VS4TSO.TSODCustomerName, VS4TJobProductionM.TJPMTSepCode, VS4TMRPStepName.TSepName
FROM ((((((((VS4TPR LEFT JOIN VS4TJob ON VS4TPR.TPRDTJobNo=VS4TJob.TJobNo) LEFT JOIN VS4TProject ON VS4TPR.TPRDTPrjCode=VS4TProject.TPrjCode) LEFT JOIN VS4TSection ON VS4TPR.TPRDTSecCode=VS4TSection.TSecCode) LEFT JOIN VS4TDepartment ON VS4TPR.TPRDTDepCode=VS4TDepartment.TDepCode) LEFT JOIN VS4TDivision ON VS4TPR.TPRDTDivCode=VS4TDivision.TDivCode) LEFT JOIN VS4TBranch ON VS4TPR.TPRDTBraCode=VS4TBranch.TBraCode) LEFT JOIN VS4TSO ON VS4TJob.TJobRefNo=VS4TSO.TSODNo) LEFT JOIN VS4TJobProductionM ON (VS4TPR.TPRDTJPDNo=VS4TJobProductionM.TJPMTJPdNo) AND (VS4TPR.TPRDTJPMLn=VS4TJobProductionM.TJPMLn)) LEFT JOIN VS4TMRPStepName ON VS4TJobProductionM.TJPMTSepCode=VS4TMRPStepName.TSepCode
GO

CREATE VIEW VS4VPricelist
AS 
SELECT VS4TPricelist.*, VS4TPricelistMB.*, VS4TPOS.*, VS4VPOSMBQuery.VPoSMemberCount, VS4VPOSMBQuery.VPoMSetAvailable, VS4TUnit.*, VS4TAR.TARNName, VS4TProduct.*
FROM (((VS4TPOS LEFT JOIN VS4VPOSMBQuery ON VS4TPOS.TPOSCode = VS4VPOSMBQuery.TPoMTPOSCode) LEFT JOIN VS4TProduct ON VS4TPOS.TPOSCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TUnit ON VS4TProduct.TPdtTUntCode = VS4TUnit.TUntCode) INNER JOIN (VS4TPricelist INNER JOIN (VS4TPricelistMB LEFT JOIN VS4TAR ON VS4TPricelistMB.TPPMTARNCode = VS4TAR.TARNCode) ON VS4TPricelist.TPPLNo = VS4TPricelistMB.TPPMTPPLNo) ON VS4TPOS.TPOSCode = VS4TPricelistMB.TPPMTPOSCode
GO

CREATE VIEW VS4VPOSLastPriceQP
AS 
SELECT VS4TQuickProductMB.TQPMProductCode, VS4TQuickProductMB.TQPMLn, VS4TQuickProduct.TQPdNo, VS4TQuickProduct.TQPdDate, VS4TQuickProduct.TQPdApproveDate, VS4TQuickProduct.TQPdApproveStatus, VS4TQuickProduct.TQPdCancelStatus, VS4VPOSLastPRICE.*
FROM VS4TQuickProduct INNER JOIN (VS4VPOSLastPRICE INNER JOIN VS4TQuickProductMB ON VS4VPOSLastPRICE.TPPMTPOSCode = VS4TQuickProductMB.TQPMProductCode) ON VS4TQuickProduct.TQPdNo = VS4TQuickProductMB.TQPMTQPdNo
GO

CREATE VIEW VS4VPriceList3
AS 
SELECT VS4TPricelist.*, VS4TPricelistMB.*
FROM VS4TPricelist INNER JOIN VS4TPricelistMB ON VS4TPricelist.TPPLNo = VS4TPricelistMB.TPPMTPPLNo
GO

CREATE VIEW VS4VPriceListGET
AS 
SELECT VS4TPricelist.*, VS4TPricelistMB.*
FROM VS4TPricelist INNER JOIN VS4TPricelistMB ON VS4TPricelist.TPPLNo = VS4TPricelistMB.TPPMTPPLNo
WHERE (((VS4TPricelist.TPPLApproveStatus)=1) AND ((VS4TPricelist.TPPLCancelStatus)=0))
GO

CREATE VIEW VS4VPrjCodeFromINV
AS 
SELECT VS4TARInvoice.TIvoTPrjCode, VS4TProject.TPrjName
FROM VS4TARInvoice LEFT JOIN VS4TProject ON VS4TARInvoice.TIvoTPrjCode = VS4TProject.TPrjCode
GROUP BY VS4TARInvoice.TIvoTPrjCode, VS4TProject.TPrjName
GO

CREATE VIEW VS4VPrjCodeFromQT
AS 
SELECT VS4TQuotation.TQuoTPrjCode, VS4TProject.TPrjName
FROM VS4TQuotation RIGHT JOIN VS4TProject ON VS4TQuotation.TQuoTPrjCode = VS4TProject.TPrjCode
GROUP BY VS4TQuotation.TQuoTPrjCode, VS4TProject.TPrjName
GO

CREATE VIEW VS4VPrjCodeFromSO
AS 
SELECT VS4TSO.TSODTPrjCode, VS4TProject.TPrjName
FROM VS4TSO LEFT JOIN VS4TProject ON VS4TSO.TSODTPrjCode = VS4TProject.TPrjCode
GROUP BY VS4TSO.TSODTPrjCode, VS4TProject.TPrjName
GO

CREATE VIEW VS4VProduct
AS 
SELECT VS4TProduct.*, VS4TProduct2.*, VS4TAP.TAPNName, VS4TBrand.TBndCode, VS4TBrand.TBndName, VS4TProductType.TPTTCode, VS4TProductType.TPTTName, VS4TProductType.TPTTDocCode, VS4TProductCalcTyp.TPCTAlias, VS4TProductCalcTyp.TPCTName, VS4TProductPURType.TPPuCode, VS4TProductPURType.TPPuName, VS4TProductGroup1.TPG1Code, VS4TProductGroup1.TPG1Name, VS4TProductGroup2.TPG2Code, VS4TProductGroup2.TPG2Name, VS4TProductGroup3.TPG3Code, VS4TProductGroup3.TPG3Name, VS4TProductGroup4.TPG4Code, VS4TProductGroup4.TPG4Name, VS4TProductSafeS.*, VS4TLocation.TLctName, VS4TWarehouse.TWahCode, VS4TWarehouse.TWahName, VS4TPOS.*, VS4TProductLine.TPdLCode, VS4TProductLine.TPdLName, VS4TProductLine.TPdLName2, VS4TProductLine.TPdLTDivCode, VS4TProductLine.TPdLDocCode, VS4TProductLine.TPdLTACSCode, VS4TProductSection.TPSECode, VS4TProductSection.TPSEName, VS4TProductSection.TPSEName2, VS4TProductSection.TPSECustomCaption, VS4TProductSection.TPSEGroupName1, VS4TProductSection.TPSEGroupName2, VS4TProductSection.TPSEGroupName3, VS4TProductSection.TPSEGroupName4
FROM VS4TWarehouse RIGHT JOIN (((VS4TProductSection RIGHT JOIN ((VS4TProductType INNER JOIN (VS4TProductPURType RIGHT JOIN (VS4TProductCalcTyp RIGHT JOIN (((((((VS4TProduct LEFT JOIN VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code) LEFT JOIN VS4TBrand ON VS4TProduct.TPdtTBndCode = VS4TBrand.TBndCode) LEFT JOIN VS4TProductGroup2 ON VS4TProduct.TPdtTPG2Code = VS4TProductGroup2.TPG2Code) LEFT JOIN VS4TProductGroup3 ON VS4TProduct.TPdtTPG3Code = VS4TProductGroup3.TPG3Code) LEFT JOIN VS4TProductGroup4 ON VS4TProduct.TPdtTPG4Code = VS4TProductGroup4.TPG4Code) LEFT JOIN VS4TProductLine ON VS4TProduct.TPdtTPDLCode = VS4TProductLine.TPdLCode) LEFT JOIN VS4TAP ON VS4TProduct.TPdtTAPNCode = VS4TAP.TAPNCode) ON VS4TProductCalcTyp.TPCTAlias = VS4TProduct.TPdtTPCTAlias) ON VS4TProductPURType.TPPuCode = VS4TProduct.TPdtTPPuCode) ON VS4TProductType.TPTTCode = VS4TProduct.TPdtTPTTCode) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode) LEFT JOIN VS4TProduct2 ON VS4TProduct.TPdtCode = VS4TProduct2.TPd2TPdtCode) LEFT JOIN ((VS4TProductSafeS LEFT JOIN VS4TBranch ON VS4TProductSafeS.TPSSTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TLocation ON VS4TProductSafeS.TPSSMainTLctCode = VS4TLocation.TLctCode) ON VS4TProduct.TPdtCode = VS4TProductSafeS.TPSSTPdtCode) ON VS4TWarehouse.TWahCode = VS4TLocation.TLctTWahCode
WHERE (((VS4TProduct.TPdtSetType)=0 Or (VS4TProduct.TPdtSetType) Is Null) AND ((VS4TBranch.TBraTBrTAlias)='HEADOFFICE' Or (VS4TBranch.TBraTBrTAlias) Is Null))
GO

CREATE VIEW VS4VProductBook
AS 
SELECT VS4TProductBook.*, VS4TProduct.*, VS4TProduct2.*, VS4TPOS.*, VS4TAirline.TAILName, VS4TProductLine.TPdLName, VS4TProductLine.TPdLName2, VS4TProductSection.TPSEName, VS4TProductSection.TPSEName2, VS4TAP.TAPNName, VS4TPOSSaleGroup.TPSGName, VS4TPOSSaleGroup.TPSGName2, VS4TProductBook_1.TPBGSeat AS VPBGSeat, VS4TProductBook_1.TPBGBook AS VPBGBook, VS4TProductBook_1.TPBGShare AS VPBGShare, VS4TProductBook_1.TPBGJoin AS VPBGJoin, VS4TProductBook_1.TPBGRemain AS VPBGRemain
FROM (VS4TProductSection INNER JOIN (VS4TProductLine INNER JOIN ((((((VS4TProduct INNER JOIN VS4TProductBook ON VS4TProduct.TPdtCode = VS4TProductBook.TPBGTPdtCode) INNER JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) LEFT JOIN VS4TAirline ON VS4TProduct.TPdtTAILCode = VS4TAirline.TAILCode) LEFT JOIN VS4TAP ON VS4TProduct.TPdtTAPNCode = VS4TAP.TAPNCode) LEFT JOIN VS4TPOSSaleGroup ON VS4TPOS.TPOSCode = VS4TPOSSaleGroup.TPSGCode) LEFT JOIN VS4TProductBook AS VS4TProductBook_1 ON VS4TProductBook.TPBGShareTPdtCode = VS4TProductBook_1.TPBGTPdtCode) ON VS4TProductLine.TPdLCode = VS4TProduct.TPdtTPDLCode) ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode) INNER JOIN VS4TProduct2 ON VS4TProduct.TPdtCode = VS4TProduct2.TPd2TPdtCode
GO

CREATE VIEW VS4VProductBrief
AS 
SELECT VS4TProduct.*, VS4TProductSection.*, VS4TProductLine.*, VS4TPOS.TPOSPrice, VS4TAP.TAPNName, VS4TProduct2.*, VS4TPOS.TPOSSaleCount, VS4TBrand.TBndCode, VS4TBrand.TBndName, VS4TProductType.TPTTCode, VS4TProductType.TPTTName, VS4TProductType.TPTTDocCode, VS4TProductCalcTyp.TPCTAlias, VS4TProductCalcTyp.TPCTName, VS4TProductPURType.TPPuCode, VS4TProductPURType.TPPuName, VS4TProductGroup1.TPG1Code, VS4TProductGroup1.TPG1Name, VS4TProductGroup2.TPG2Code, VS4TProductGroup2.TPG2Name, VS4TProductGroup3.TPG3Code, VS4TProductGroup3.TPG3Name, VS4TProductGroup4.TPG4Code, VS4TProductGroup4.TPG4Name
FROM ((VS4TProductSection RIGHT JOIN (VS4TProductType INNER JOIN (VS4TProductPURType RIGHT JOIN (VS4TProductCalcTyp RIGHT JOIN (((((((VS4TProduct LEFT JOIN VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code) LEFT JOIN VS4TBrand ON VS4TProduct.TPdtTBndCode = VS4TBrand.TBndCode) LEFT JOIN VS4TProductGroup2 ON VS4TProduct.TPdtTPG2Code = VS4TProductGroup2.TPG2Code) LEFT JOIN VS4TProductGroup3 ON VS4TProduct.TPdtTPG3Code = VS4TProductGroup3.TPG3Code) LEFT JOIN VS4TProductGroup4 ON VS4TProduct.TPdtTPG4Code = VS4TProductGroup4.TPG4Code) LEFT JOIN VS4TProductLine ON VS4TProduct.TPdtTPDLCode = VS4TProductLine.TPdLCode) LEFT JOIN VS4TAP ON VS4TProduct.TPdtTAPNCode = VS4TAP.TAPNCode) ON VS4TProductCalcTyp.TPCTAlias = VS4TProduct.TPdtTPCTAlias) ON VS4TProductPURType.TPPuCode = VS4TProduct.TPdtTPPuCode) ON VS4TProductType.TPTTCode = VS4TProduct.TPdtTPTTCode) ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode) LEFT JOIN VS4TProduct2 ON VS4TProduct.TPdtCode = VS4TProduct2.TPd2TPdtCode) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode
WHERE (((VS4TPOS.TPOSType)=0 Or (VS4TPOS.TPOSType) Is Null))
GO

CREATE VIEW VS4VProductCost
AS 
SELECT VS4TProductCost.*, VS4TProduct.*, VS4TProduct2.*, VS4TPOS.*, VS4TProduct_1.TPdtName AS VPMBName, VS4TProduct_1.TPdtName2 AS VPMBName2, VS4TProduct_1.TPdtTUntCode AS VPMBTUntCode, VS4TAR.TARNName, VS4TEmployee.TEmpFullName, VS4TEmployee.TEmpFullName2, VS4TEmployee.TEmpTel, VS4TAR.TARNAddressBill, VS4TAR.TARNPhone, VS4TAR.TARNFax, VS4TAP.TAPNName, VS4TAP.TAPNAddressBill, VS4TAP.TAPNPhone, VS4TAP.TAPNFax, VS4TAP.TAPNEmail, VS4TAP.TAPNContactName, VS4TPOSSaleGroup.TPSGName, VS4TPOSSaleGroup.TPSGName2
FROM ((((((((VS4TProduct INNER JOIN VS4TProductCost ON VS4TProduct.TPdtCode = VS4TProductCost.TPMBTPdtCode) INNER JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) LEFT JOIN VS4TProduct AS VS4TProduct_1 ON VS4TProductCost.TPMBTPdtCode2 = VS4TProduct_1.TPdtCode) LEFT JOIN VS4TAR ON VS4TPOS.TPOSTARNCode = VS4TAR.TARNCode) LEFT JOIN VS4TEmployee ON VS4TPOS.TPOSSaleCode = VS4TEmployee.TEmpCode) LEFT JOIN VS4TAP ON VS4TProduct.TPdtTAPNCode = VS4TAP.TAPNCode) LEFT JOIN VS4TProductBook ON VS4TProduct.TPdtCode = VS4TProductBook.TPBGTPdtCode) INNER JOIN VS4TProduct2 ON VS4TProduct.TPdtCode = VS4TProduct2.TPd2TPdtCode) LEFT JOIN VS4TPOSSaleGroup ON VS4TPOS.TPOSTPSGCode = VS4TPOSSaleGroup.TPSGCode
GO

CREATE VIEW VS4VPS
AS 
SELECT VS4TPS.*, VS4TPSMB.*, VS4TAP.*, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TBranch.TBraName, VS4TBranch.TBraAddressBill
FROM (((VS4TPS LEFT JOIN VS4TAP ON VS4TPS.TPSDTAPNCode = VS4TAP.TAPNCode) LEFT JOIN VS4TProject ON VS4TPS.TPSDTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TPS.TPSDTBraCode = VS4TBranch.TBraCode) INNER JOIN VS4TPSMB ON VS4TPS.TPSDNo = VS4TPSMB.TPSMTPSDNo
GO

CREATE VIEW VS4VInventoryP
AS 
SELECT Vs4TInventoryP.*, Vs4TInventoryMBP.*, VS4TWarehouse.TWahName, VS4TLocation.TLctName, VS4TSection.TSecName, VS4TDepartment.TDepName, VS4TDivision.TDivName, VS4TBranch.TBraName, VS4TProject.TPrjMode, VS4TProductType.TPTTName, Vs4TInventoryType.TInTName, Vs4TInventoryType.TInTDescription, VS4TLocation.TLctTBraCode, VS4TAR.TARNName, VS4TAP.TAPNName, Vs4TInventoryType.TInTSort, VS4TPOS.TPOSPrice, VS4TJob.TJobCode, VS4TJob.TJobCustomerName, VS4TJob.TJobNo, VS4TJobMB.TJbMTPdtCode, VS4TJobMB.TJbMProductName, VS4TProduct.TPdtBarcode, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtFactoryCode, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TPOS.TPOSPackText1, VS4TPOS.TPOSPackText2, VS4TPOS.TPOSPackAlias1, VS4TProduct.TPdtTPTTCode, VS4TProduct.TPdtTAPNCode, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtTPSECode, VS4TProduct.TPdtTPS2Code, VS4TProduct.TPdtTPS3Code, VS4TProduct.TPdtTPS4Code, VS4TProduct.TPdtTPG1Code, VS4TProduct.TPdtTPG2Code, VS4TProduct.TPdtTPG3Code, VS4TProduct.TPdtTPG4Code, VS4TProduct.TPdtTBndCode, VS4TProduct.TPdtImage1, VS4TProduct.TPdtTPCTAlias, VS4TProduct.TPdtOrderPoint, VS4TProduct.TPdtMaxUsePerDay, VS4TProduct.TPdtAvgUsePerDay, VS4TProduct.TPdtStockQuantity, VS4TProduct.TPdtEOQ, VS4TProduct.TPdtFirstDate, VS4TProduct.TPdtLastMoveDate, VS4TProduct.TPdtLastCost, VS4TProduct.TPdtStdCostCode, VS4TProduct.TPdtAverageCost, VS4TProduct.TPdtSerialType, VS4TProduct.TPdtSlowDay, VS4TProduct.TPdtDeadDay, VS4TProduct.TPdtBackDayCalc, VS4TProduct.TPdtGroupReport, VS4TPRMB.TPRMTPdtCode, VS4TPRMB.TPRMProductName, VS4TPRMB.TPRMCustom1, VS4TPRMB.TPRMCustom2, VS4TPRMB.TPRMCustom3, VS4TPRMB.TPRMUseDate, VS4TPRMB.TPRMUseType, VS4TPRMB.TPRMTUntCode, VS4TPRMB.TPRMQuantity, VS4TPRMB.TPRMQuantity2, VS4TPRMB.TPRMQuantity3, VS4TPR.TPRDNo, VS4TPR.TPRDTPRBCode, VS4TPR.TPRDDate, VS4TPR.TPRDRefNo, VS4TPR.TPRDRequestCode, VS4TPR.TPRDRequestBy, VS4TPR.TPRDDescription, VS4TPR.TPRDTBraCode, VS4TPR.TPRDTDivCode, VS4TWarehouse_1.TWahCode AS VInMFromTWahCode, VS4TWarehouse.TWahCode AS VInMToTWahCode, VS4TWarehouse.TWahCode, VS4TJobMB.TJbMQuantity, VS4TJobMB.TJbMTUntCode, VS4TJobMB.TJbMQuantity2, VS4TJobMB.TJbMQuantity3, VS4TProductSection.TPSECode AS VInMTPSECode, VS4TProductSection.TPSEName AS VInMTPSEName, VS4TJobMB.TJbMCustom1, VS4TJobMB.TJbMCustom2, VS4TJobMB.TJbMCustom3, VS4TSOMB.TSOBPOSName, VS4TProduct.TPdtTPPuCode, Vs4TInventoryLOTP.TIMCJobCode, Vs4TInventoryLOTP.TIMCCustom2, Vs4TInventoryLOTP.TIMCCustom3, Vs4TInventoryLOTP.TIMCCustom4, Vs4TInventoryLOTP.TIMCCustom5, Vs4TInventoryLOTP.TIMCIsPremium, Vs4TInventoryLOTP.TIMCPremiumNote, Vs4TInventoryLOTP.TIMCLotNo2, Vs4TInventoryLOTP.TIMCGrade, Vs4TInventoryLOTP.TIMCNoExpire, Vs4TInventoryLOTP.TIMCExpireDate, Vs4TInventoryLOTP.TIMCTCgTID, Vs4TInventoryLOTP.TIMCInputCost, Vs4TInventoryLOTP.TIMCLastUnitCost, Vs4TInventoryLOTP.TIMCPerQuantity, Vs4TInventoryLOTP.TIMCUnitCalc, Vs4TInventoryLOTP.TIMCUnitCost, Vs4TInventoryLOTP.TIMCReserve, Vs4TInventoryLOTP.TIMCCostCode, Vs4TInventoryLOTP.TIMCTPODNo, Vs4TInventoryLOTP.TIMCTPOBLn, Vs4TInventoryLOTP.TIMCTPDELn, Vs4TInventoryLOTP.TIMCConsignFSDate, Vs4TInventoryLOTP.TIMCConsignLSDate, Vs4TInventoryType.TInTInputCost, Vs4TInventoryLOTP.TIMCReceiveNo, Vs4TInventoryLOTP.TIMCReceiveLn, VS4VProductSafeH.TPSSStockMin, Vs4TInventoryLOTP.TIMCQAStatus, Vs4TInventoryLOTP.TIMCQANote, VS4TAR.TARNAddressBill, Vs4TInventoryLOTP.TIMCTAPNCode, Vs4TInventoryLOTP.TIMCInvoiceNo, Vs4TInventoryLOTP.TIMCInvoiceDate, Vs4TInventoryLOTP.TIMCTUntCode, Vs4TInventoryLOTP.TIMCUnitRatio, VS4TProduct.TPdtFlag1, VS4TProduct.TPdtCode, VS4VProductGroup.TPdLName, VS4VProductGroup.TPSEName, VS4VProductGroup.TPG1Name, Vs4TInventoryLOTP.TIMCAccountLevel, VS4TProduct.TPdtLastBalDate, VS4TPOS.TPOSPackAlias2
FROM Vs4TInventoryType INNER JOIN (VS4TSO RIGHT JOIN ((((((VS4TProduct LEFT JOIN VS4TProductType ON VS4TProduct.TPdtTPTTCode = VS4TProductType.TPTTCode) LEFT JOIN VS4VProductGroup ON VS4TProduct.TPdtCode = VS4VProductGroup.VPdtCode) LEFT JOIN VS4VProductSafeH ON VS4TProduct.TPdtCode = VS4VProductSafeH.TPSSTPdtCode) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) INNER JOIN ((((((((((((Vs4TInventoryP LEFT JOIN VS4TDepartment ON Vs4TInventoryP.TInvTDepCode = VS4TDepartment.TDepCode) LEFT JOIN VS4TDivision ON Vs4TInventoryP.TInvTDivCode = VS4TDivision.TDivCode) LEFT JOIN VS4TBranch ON Vs4TInventoryP.TInvTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TProject ON Vs4TInventoryP.TInvTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TJob ON Vs4TInventoryP.TInvTJobNo = VS4TJob.TJobNo) LEFT JOIN VS4TJobMB ON (Vs4TInventoryP.TInvTJbMLn = VS4TJobMB.TJbMLn) AND (Vs4TInventoryP.TInvTJobNo = VS4TJobMB.TJbMTJobNo)) LEFT JOIN VS4TPR ON Vs4TInventoryP.TInvRefNo = VS4TPR.TPRDNo) LEFT JOIN VS4TProduct AS VS4TProduct_1 ON VS4TJobMB.TJbMTPdtCode = VS4TProduct_1.TPdtCode) LEFT JOIN VS4TProductSection ON VS4TProduct_1.TPdtTPSECode = VS4TProductSection.TPSECode) LEFT JOIN VS4TAR ON Vs4TInventoryP.TInvTARNCode = VS4TAR.TARNCode) LEFT JOIN VS4TSection ON Vs4TInventoryP.TInvTSecCode = VS4TSection.TSecCode) INNER JOIN (((((((Vs4TInventoryMBP LEFT JOIN VS4TLocation ON Vs4TInventoryMBP.TInMTLctCode = VS4TLocation.TLctCode) LEFT JOIN VS4TWarehouse ON VS4TLocation.TLctTWahCode = VS4TWarehouse.TWahCode) LEFT JOIN VS4TPRMB ON (Vs4TInventoryMBP.TInMSourceNo = VS4TPRMB.TPRMTPRDNo) AND (Vs4TInventoryMBP.TInMSourceLn = VS4TPRMB.TPRMLn)) LEFT JOIN VS4TLocation AS VS4TLocation_1 ON Vs4TInventoryMBP.TInMFromTLctCode = VS4TLocation_1.TLctCode) LEFT JOIN VS4TWarehouse AS VS4TWarehouse_1 ON VS4TLocation_1.TLctTWahCode = VS4TWarehouse_1.TWahCode) LEFT JOIN VS4TSOMB ON (Vs4TInventoryMBP.TInMTSODNo = VS4TSOMB.TSOBTSODNo) AND (Vs4TInventoryMBP.TInMTSOBLn = VS4TSOMB.TSOBLn)) LEFT JOIN (Vs4TInventoryLOTP LEFT JOIN VS4TAP ON Vs4TInventoryLOTP.TIMCTAPNCode = VS4TAP.TAPNCode) ON (Vs4TInventoryMBP.TInMLotDate = Vs4TInventoryLOTP.TIMCLotDate) AND (Vs4TInventoryMBP.TInMLotNo = Vs4TInventoryLOTP.TIMCLotNo) AND (Vs4TInventoryMBP.TInMSerialNo = Vs4TInventoryLOTP.TIMCSerialNo) AND (Vs4TInventoryMBP.TInMCustom1 = Vs4TInventoryLOTP.TIMCCustom1) AND (Vs4TInventoryMBP.TInMTPdtCode = Vs4TInventoryLOTP.TIMCTPdtCode)) ON Vs4TInventoryP.TInvNo = Vs4TInventoryMBP.TInMTInvNo) ON VS4TProduct.TPdtCode = Vs4TInventoryMBP.TInMTPdtCode) LEFT JOIN VS4TProduct2 ON VS4TProduct.TPdtCode = VS4TProduct2.TPd2TPdtCode) ON VS4TSO.TSODNo = VS4TSOMB.TSOBTSODNo) ON Vs4TInventoryType.TInTAlias = Vs4TInventoryP.TInvTInTAlias
GO

CREATE VIEW VS4VProductGroup1
AS 
SELECT VS4TProductGroup1.*, VS4TProductSection.*, VS4TProductLine.*
FROM (VS4TProductGroup1 LEFT JOIN VS4TProductSection ON VS4TProductGroup1.TPG1TPSECode=VS4TProductSection.TPSECode) LEFT JOIN (VS4TProductLine RIGHT JOIN VS4TProductLineMB ON VS4TProductLine.TPdLCode=VS4TProductLineMB.TPLMTPDLCode) ON VS4TProductSection.TPSECode=VS4TProductLineMB.TPLMTPSECode
GO

CREATE VIEW VS4VProductGroup2
AS 
SELECT VS4TProductGroup2.*, VS4TProductSection.*, VS4TProductLine.*
FROM (VS4TProductGroup2 LEFT JOIN VS4TProductSection ON VS4TProductGroup2.TPG2TPSECode=VS4TProductSection.TPSECode) LEFT JOIN (VS4TProductLine RIGHT JOIN VS4TProductLineMB ON VS4TProductLine.TPdLCode=VS4TProductLineMB.TPLMTPDLCode) ON VS4TProductSection.TPSECode=VS4TProductLineMB.TPLMTPSECode
GO

CREATE VIEW VS4VProductGroup3
AS 
SELECT VS4TProductGroup3.*, VS4TProductSec2.*, VS4TProductLine.*
FROM VS4TProductLine INNER JOIN (VS4TProductGroup3 INNER JOIN VS4TProductSec2 ON VS4TProductGroup3.TPG3TPS2Code=VS4TProductSec2.TPS2Code) ON VS4TProductLine.TPdLCode=VS4TProductSec2.TPS2TPdLCode
GO

CREATE VIEW VS4VProductGroup4
AS 
SELECT VS4TProductGroup4.*, VS4TProductSec2.*, VS4TProductLine.*
FROM VS4TProductLine INNER JOIN (VS4TProductGroup4 INNER JOIN VS4TProductSec2 ON VS4TProductGroup4.TPG4TPS2Code=VS4TProductSec2.TPS2Code) ON VS4TProductLine.TPdLCode=VS4TProductSec2.TPS2TPdLCode
GO

CREATE VIEW VS4VProductItin
AS 
SELECT VS4TProduct.*, VS4TProductBook.*, VS4TProductItin.*, VS4TPOS.TPOSG1TAPNCode, VS4TPOS.TPOSG2TAPNCode, VS4TPOS.TPOSG3TAPNCode, VS4TPOS.TPOSG4TAPNCode, VS4TAP.TAPNName2 AS VPITG1Name2, VS4TAP_1.TAPNName2 AS VPITG2Name2, VS4TAP_2.TAPNName2 AS VPITG3Name2, VS4TAP_3.TAPNName2 AS VPITG4Name2
FROM ((((((VS4TProduct INNER JOIN VS4TProductBook ON VS4TProduct.TPdtCode = VS4TProductBook.TPBGTPdtCode) INNER JOIN VS4TProductItin ON VS4TProduct.TPdtCode = VS4TProductItin.TPITTPdtCode) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) LEFT JOIN VS4TAP ON VS4TPOS.TPOSG1TAPNCode = VS4TAP.TAPNCode) LEFT JOIN VS4TAP AS VS4TAP_1 ON VS4TPOS.TPOSG2TAPNCode = VS4TAP_1.TAPNCode) LEFT JOIN VS4TAP AS VS4TAP_2 ON VS4TPOS.TPOSG3TAPNCode = VS4TAP_2.TAPNCode) LEFT JOIN VS4TAP AS VS4TAP_3 ON VS4TPOS.TPOSG4TAPNCode = VS4TAP_3.TAPNCode
GO

CREATE VIEW VS4VProductLine
AS 
SELECT VS4TProductLine.*, VS4TDivision.*
FROM VS4TDivision RIGHT JOIN VS4TProductLine ON VS4TDivision.TDivCode=VS4TProductLine.TPdLTDivCode
GO

CREATE VIEW VS4VInventPdtL
AS 
SELECT VS4VInventory.TInMTPdtCode, VS4VInventory.TPdtBarcode, VS4VInventory.TPdtName, VS4VInventory.TInMLotNo, VS4VInventory.TInMLotDate, VS4VInventory.TIMCUnitCost, VS4VInventory.TInMStatus, VS4VInventory.TInMCustom1, VS4VInventory.TInMSerialNo
FROM VS4VInventory
GROUP BY VS4VInventory.TInMTPdtCode, VS4VInventory.TPdtBarcode, VS4VInventory.TPdtName, VS4VInventory.TInMLotNo, VS4VInventory.TInMLotDate, VS4VInventory.TIMCUnitCost, VS4VInventory.TInMStatus, VS4VInventory.TInMCustom1, VS4VInventory.TInMSerialNo, VS4VInventory.TInvApproveStatus, VS4VInventory.TInvCancelStatus
HAVING (((VS4VInventory.TInMTPdtCode)<>'') AND ((VS4VInventory.TInMStatus)=1) AND ((VS4VInventory.TInvApproveStatus)=1) AND ((VS4VInventory.TInvCancelStatus)=0))
GO

CREATE VIEW VS4VProductMat
AS 
SELECT VS4TProduct.*, VS4TProductSection.*, VS4TProductLine.*, VS4TPOS.TPOSPrice, VS4TAP.TAPNName, VS4TProduct2.*, VS4TPOS.TPOSSaleCount, VS4TBrand.TBndCode, VS4TBrand.TBndName, VS4TProductType.TPTTCode, VS4TProductType.TPTTName, VS4TProductType.TPTTDocCode, VS4TProductCalcTyp.TPCTAlias, VS4TProductCalcTyp.TPCTName, VS4TProductPURType.TPPuCode, VS4TProductPURType.TPPuName, VS4TProductGroup1.TPG1Code, VS4TProductGroup1.TPG1Name, VS4TProductGroup2.TPG2Code, VS4TProductGroup2.TPG2Name, VS4TProductGroup3.TPG3Code, VS4TProductGroup3.TPG3Name, VS4TProductGroup4.TPG4Code, VS4TProductGroup4.TPG4Name, VS4TProductMat.*, VS4TProduct_1.TPdtStandardCost AS VPmtStandardCost, VS4TProduct_1.TPdtName AS VPMtProductName, VS4TProduct_1.TPdtName2 AS VPMtProductName2, VS4TProduct_1.TPdtTUntCode AS VPMtTUntCode, VS4TProduct_1.TPdtTUntCode2 AS VPMtTUntCode2, VS4TProduct_1.TPdtTUntCode3 AS VPMtTUntCode3
FROM ((VS4TProductSection RIGHT JOIN ((VS4TProductType RIGHT JOIN (VS4TProductPURType RIGHT JOIN (VS4TProductCalcTyp RIGHT JOIN (((((((VS4TProduct LEFT JOIN VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code) LEFT JOIN VS4TBrand ON VS4TProduct.TPdtTBndCode = VS4TBrand.TBndCode) LEFT JOIN VS4TProductGroup2 ON VS4TProduct.TPdtTPG2Code = VS4TProductGroup2.TPG2Code) LEFT JOIN VS4TProductGroup3 ON VS4TProduct.TPdtTPG3Code = VS4TProductGroup3.TPG3Code) LEFT JOIN VS4TProductGroup4 ON VS4TProduct.TPdtTPG4Code = VS4TProductGroup4.TPG4Code) LEFT JOIN VS4TProductLine ON VS4TProduct.TPdtTPDLCode = VS4TProductLine.TPdLCode) LEFT JOIN VS4TAP ON VS4TProduct.TPdtTAPNCode = VS4TAP.TAPNCode) ON VS4TProductCalcTyp.TPCTAlias = VS4TProduct.TPdtTPCTAlias) ON VS4TProductPURType.TPPuCode = VS4TProduct.TPdtTPPuCode) ON VS4TProductType.TPTTCode = VS4TProduct.TPdtTPTTCode) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode) LEFT JOIN VS4TProduct2 ON VS4TProduct.TPdtCode = VS4TProduct2.TPd2TPdtCode) LEFT JOIN (VS4TProductMat LEFT JOIN VS4TProduct AS VS4TProduct_1 ON VS4TProductMat.TPMtProductCode = VS4TProduct_1.TPdtCode) ON VS4TProduct.TPdtCode = VS4TProductMat.TPMtTPdtCode
WHERE (((VS4TPOS.TPOSType)=0 Or (VS4TPOS.TPOSType) Is Null))
GO

CREATE VIEW VS4VProductMB
AS 
SELECT VS4TProduct.*, VS4TProductMB.*
FROM VS4TProductMB RIGHT JOIN VS4TProduct ON VS4TProductMB.TPDMTPdtCode2=VS4TProduct.TPdtCode
GO

CREATE VIEW VS4VProductMethod
AS 
SELECT VS4TProductMethod.*, VS4TMRPStepName.*, VS4TSection.*, VS4TAssetWorkGroup.*, VS4TAP.TAPNName, VS4TAP.TAPNName2, VS4TProduct.*, VS4TProduct2.*
FROM (VS4TProduct LEFT JOIN VS4TProduct2 ON VS4TProduct.TPdtCode = VS4TProduct2.TPd2TPdtCode) INNER JOIN (((VS4TProductMethod LEFT JOIN (VS4TMRPStepName LEFT JOIN VS4TAP ON VS4TMRPStepName.TSepTAPNCode = VS4TAP.TAPNCode) ON VS4TProductMethod.TSpdTSepCode = VS4TMRPStepName.TSepCode) LEFT JOIN VS4TAssetWorkGroup ON VS4TProductMethod.TSpdTAgtCode = VS4TAssetWorkGroup.TAgtCode) LEFT JOIN VS4TSection ON VS4TMRPStepName.TSepTSecCode = VS4TSection.TSecCode) ON VS4TProduct.TPdtCode = VS4TProductMethod.TSpdTPdtCode
GO

CREATE VIEW VS4VProductNote
AS 
SELECT VS4TProductNote.*, VS4TProduct.*, VS4TProductBook.*
FROM (VS4TProductNote INNER JOIN VS4TProduct ON VS4TProductNote.TPDNTPdtCode = VS4TProduct.TPdtCode) INNER JOIN VS4TProductBook ON VS4TProduct.TPdtCode = VS4TProductBook.TPBGTPdtCode
GO

CREATE VIEW VS4VProductPlace
AS 
SELECT VS4TProductPlace.*, VS4TPlace.*
FROM VS4TProductPlace LEFT JOIN VS4TPlace ON VS4TProductPlace.TPAPTPlaID = VS4TPlace.TPlaID
GO

CREATE VIEW VS4VProductRelate
AS 
SELECT VS4TProductRelate.*, VS4TProduct.*, VS4TProduct_1.TPdtName AS VPDRName, VS4TProduct_1.TPdtTUntCode AS VPDRTUntCode, VS4TProduct_1.TPdtTUntCode2 AS VPDRTUntCode2, VS4TProduct_1.TPdtTUntCode3 AS VPDRTUntCode3, VS4TProduct_1.TPdtBarcode AS VPDRBarCode
FROM (VS4TProductRelate LEFT JOIN VS4TProduct ON VS4TProductRelate.TPdRTPdtCode2=VS4TProduct.TPdtCode) LEFT JOIN VS4TProduct AS VS4TProduct_1 ON VS4TProductRelate.TPdRTPdtCode=VS4TProduct_1.TPdtCode
GO

CREATE VIEW VS4VProductLotCost
AS 
SELECT VS4VInventPdtL.TInMTPdtCode, VS4VInventPdtL.TInMLotNo, VS4VInventPdtL.TInMLotDate, VS4VInventPdtL.TIMCUnitCost, VS4VInventPdtL.TInMStatus, VS4VProduct.*
FROM VS4VInventPdtL LEFT JOIN VS4VProduct ON VS4VInventPdtL.TInMTPdtCode = VS4VProduct.TPdtCode
GO

CREATE VIEW VS4VStockBranch
AS 
SELECT Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtTPTTCode, Vs4VInventStock.TPdtTPPuCode, Vs4VInventStock.TPdtFlag1, Sum(Vs4VInventStock.TInMInQuantity) AS TInMInQuantity, Sum(Vs4VInventStock.TInMOutQuantity) AS TInMOutQuantity, Sum(Vs4VInventStock.TInMAmouQuantity) AS TInMAmouQuantity, Vs4VInventStock.TPdtTUntCode, Sum(Vs4VInventStock.TInMInQuantity2) AS TInMInQuantity2, Sum(Vs4VInventStock.TInMOutQuantity2) AS TInMOutQuantity2, Sum(Vs4VInventStock.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, Sum(Vs4VInventStock.TInMInQuantity3) AS TInMInQuantity3, Sum(Vs4VInventStock.TInMOutQuantity3) AS TInMOutQuantity3, Sum(Vs4VInventStock.TInMAmouQuantity3) AS TInMAmouQuantity3, Vs4VInventStock.TPdtTUntCode3, Sum(Vs4VInventStock.TInMAmount) AS TInMAmount, Avg(Vs4VInventStock.TIMCUnitCost) AS TIMCUnitCost, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, Vs4VInventStock.TPdtTPG4Code, Vs4VInventStock.TPdtTPCTAlias, Vs4VInventStock.TPOSPrice, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TIMCUnitCalc, Sum(Vs4VInventStock.TInMQuantityCalc) AS TInMQuantityCalc, Vs4VInventStock.TPdtOrderPoint, Vs4VInventStock.TPdtTAPNCode, Vs4VInventStock.TLctTBraCode, Vs4VInventStock.TPdtFactoryCode, VS4TProductSafeS.TPSSRefill, VS4TProductSafeS.TPSSSafePerDay, VS4TProductSafeS.TPSSSafeTotalDay, VS4TProductSafeS.TPSSStockMin, VS4TProductSafeS.TPSSSuggest, Vs4VInventStock.TPOSPackAlias2
FROM Vs4VInventStock LEFT JOIN VS4TProductSafeS ON (Vs4VInventStock.TLctTBraCode = VS4TProductSafeS.TPSSTBraCode) AND (Vs4VInventStock.TInMTPdtCode = VS4TProductSafeS.TPSSTPdtCode)
GROUP BY Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtTPTTCode, Vs4VInventStock.TPdtTPPuCode, Vs4VInventStock.TPdtFlag1, Vs4VInventStock.TPdtTUntCode, Vs4VInventStock.TPdtTUntCode2, Vs4VInventStock.TPdtTUntCode3, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, Vs4VInventStock.TPdtTPG4Code, Vs4VInventStock.TPdtTPCTAlias, Vs4VInventStock.TPOSPrice, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TIMCUnitCalc, Vs4VInventStock.TPdtOrderPoint, Vs4VInventStock.TPdtTAPNCode, Vs4VInventStock.TLctTBraCode, Vs4VInventStock.TPdtFactoryCode, VS4TProductSafeS.TPSSRefill, VS4TProductSafeS.TPSSSafePerDay, VS4TProductSafeS.TPSSSafeTotalDay, VS4TProductSafeS.TPSSStockMin, VS4TProductSafeS.TPSSSuggest, Vs4VInventStock.TPOSPackAlias2
GO

CREATE VIEW VS4VProductSec2
AS 
SELECT VS4TProductSec2.*, VS4TProductLine.*
FROM VS4TProductLine INNER JOIN VS4TProductSec2 ON VS4TProductLine.TPdLCode=VS4TProductSec2.TPS2TPdLCode
GO

CREATE VIEW VS4VProductSec3
AS 
SELECT VS4TProductSec3.*, VS4TProductLine.*
FROM VS4TProductLine INNER JOIN VS4TProductSec3 ON VS4TProductLine.TPdLCode=VS4TProductSec3.TPS3TPdLCode
GO

CREATE VIEW VS4VProductSec4
AS 
SELECT VS4TProductSec4.*, VS4TProductLine.*
FROM VS4TProductLine INNER JOIN VS4TProductSec4 ON VS4TProductLine.TPdLCode=VS4TProductSec4.TPS4TPdLCode
GO

CREATE VIEW VS4VProductSection
AS 
SELECT VS4TProductSection.*, VS4TProductLineMB.*, VS4TProductLine.*
FROM VS4TProductSection INNER JOIN (VS4TProductLine INNER JOIN VS4TProductLineMB ON VS4TProductLine.TPdLCode=VS4TProductLineMB.TPLMTPDLCode) ON VS4TProductSection.TPSECode=VS4TProductLineMB.TPLMTPSECode
GO

CREATE VIEW VS4VProductSeGp1
AS 
SELECT VS4TProductSection.*, VS4TProductGroup1.*
FROM VS4TProductSection INNER JOIN VS4TProductGroup1 ON VS4TProductSection.TPSECode=VS4TProductGroup1.TPG1TPSECode
GO

CREATE VIEW VS4VProductSeGp2
AS 
SELECT VS4TProductGroup2.*, VS4TProductSection.*
FROM VS4TProductGroup2 INNER JOIN VS4TProductSection ON VS4TProductGroup2.TPG2TPSECode=VS4TProductSection.TPSECode
GO

CREATE VIEW VS4VProductSub
AS 
SELECT VS4TProduct.*, VS4TProductCalcTyp.*, VS4TProductSub.*, VS4TProductSection.*, VS4TProductLine.TPdLName, VS4TProductGroup1.*, VS4TBrand.TBndCode, VS4TBrand.TBndName, VS4TProductType.TPTTCode, VS4TProductType.TPTTName, VS4TProductType.TPTTDocCode, VS4TProductType.TPTTSort, VS4TProductGroup2.TPG2Code, VS4TProductGroup2.TPG2Name, VS4TProductGroup2.TPG2Name2, VS4TProductGroup3.TPG3Code, VS4TProductGroup3.TPG3Name, VS4TProductGroup3.TPG3Name2, VS4TProductGroup4.TPG4Code, VS4TProductGroup4.TPG4Name, VS4TProductGroup4.TPG4Name2, VS4TProductBook.*, VS4TPOS.TPOSPeriod, VS4TPOS.TPOSTPSGCode, VS4TPOSSaleGroup.TPSGName, VS4TPOSSaleGroup.TPSGName2
FROM (VS4TProductSection RIGHT JOIN ((((VS4TProductType INNER JOIN (VS4TProductCalcTyp INNER JOIN ((((((VS4TProduct LEFT JOIN VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code) LEFT JOIN VS4TBrand ON VS4TProduct.TPdtTBndCode = VS4TBrand.TBndCode) LEFT JOIN VS4TProductGroup2 ON VS4TProduct.TPdtTPG2Code = VS4TProductGroup2.TPG2Code) LEFT JOIN VS4TProductGroup3 ON VS4TProduct.TPdtTPG3Code = VS4TProductGroup3.TPG3Code) LEFT JOIN VS4TProductGroup4 ON VS4TProduct.TPdtTPG4Code = VS4TProductGroup4.TPG4Code) LEFT JOIN VS4TProductLine ON VS4TProduct.TPdtTPDLCode = VS4TProductLine.TPdLCode) ON VS4TProductCalcTyp.TPCTAlias = VS4TProduct.TPdtTPCTAlias) ON VS4TProductType.TPTTCode = VS4TProduct.TPdtTPTTCode) LEFT JOIN VS4TProductBook ON VS4TProduct.TPdtCode = VS4TProductBook.TPBGTPdtCode) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) LEFT JOIN VS4TPOSSaleGroup ON VS4TPOS.TPOSCode = VS4TPOSSaleGroup.TPSGCode) ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode) LEFT JOIN VS4TProductSub ON VS4TProduct.TPdtCode = VS4TProductSub.TPdSTPdtCode
GO

CREATE VIEW VS4VProductUnit
AS 
SELECT VS4TProduct.*, VS4TUnit.*, VS4TProductType.*, VS4TProductCalcTyp.*, VS4TProductSection.*, VS4TProductLine.*, VS4TProductSafeS.*, VS4TBrand.TBndCode, VS4TBrand.TBndName, VS4TProductGroup1.TPG1Name, VS4TProductGroup2.TPG2Name, VS4TProductGroup3.TPG3Name, VS4TProductGroup4.TPG4Name
FROM ((VS4TProductSection RIGHT JOIN (VS4TProductType INNER JOIN (VS4TProductCalcTyp INNER JOIN ((((((VS4TProduct LEFT JOIN VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code=VS4TProductGroup1.TPG1Code) LEFT JOIN VS4TBrand ON VS4TProduct.TPdtTBndCode=VS4TBrand.TBndCode) LEFT JOIN VS4TProductGroup3 ON VS4TProduct.TPdtTPG3Code=VS4TProductGroup3.TPG3Code) LEFT JOIN VS4TProductGroup4 ON VS4TProduct.TPdtTPG4Code=VS4TProductGroup4.TPG4Code) LEFT JOIN VS4TProductGroup2 ON VS4TProduct.TPdtTPG2Code=VS4TProductGroup2.TPG2Code) LEFT JOIN VS4TProductLine ON VS4TProduct.TPdtTPDLCode=VS4TProductLine.TPdLCode) ON VS4TProductCalcTyp.TPCTAlias=VS4TProduct.TPdtTPCTAlias) ON VS4TProductType.TPTTCode=VS4TProduct.TPdtTPTTCode) ON VS4TProductSection.TPSECode=VS4TProduct.TPdtTPSECode) LEFT JOIN (VS4TProductSafeS LEFT JOIN VS4TBranch ON VS4TProductSafeS.TPSSTBraCode=VS4TBranch.TBraCode) ON VS4TProduct.TPdtCode=VS4TProductSafeS.TPSSTPdtCode) LEFT JOIN (VS4TUnit RIGHT JOIN VS4TProductUnit ON VS4TUnit.TUntCode=VS4TProductUnit.TPDUTUntCode) ON VS4TProduct.TPdtCode=VS4TProductUnit.TPDUTPdtCode
WHERE (((VS4TBranch.TBraTBRTAlias)='HEADOFFICE' Or (VS4TBranch.TBraTBRTAlias) Is Null))
GO

CREATE VIEW VS4VProject
AS 
SELECT VS4TProject.*, VS4TProjectType.*
FROM VS4TProjectType INNER JOIN VS4TProject ON VS4TProjectType.TPjTCode = VS4TProject.TPrjTPjTCode
GO

CREATE VIEW VS4VProjectBOQ
AS 
SELECT VS4TProjectType.*, VS4TProject.*, VS4TProjectPhase.*, VS4TProjectBOQ.*, VS4TProduct.*, VS4TProductMat.*
FROM (VS4TProjectType INNER JOIN VS4TProject ON VS4TProjectType.TPjTCode = VS4TProject.TPrjTPjTCode) INNER JOIN (VS4TProjectPhase LEFT JOIN ((VS4TProjectBOQ LEFT JOIN VS4TProduct ON VS4TProjectBOQ.TP2QTBOQNo = VS4TProduct.TPdtCode) LEFT JOIN VS4TProductMat ON VS4TProduct.TPdtCode = VS4TProductMat.TPMtTPdtCode) ON (VS4TProjectPhase.TPHSLn = VS4TProjectBOQ.TP2QTPHSLn) AND (VS4TProjectPhase.TPHSTPrjCode = VS4TProjectBOQ.TP2QTPHSTPrjCode)) ON VS4TProject.TPrjCode = VS4TProjectPhase.TPHSTPrjCode
GO

CREATE VIEW VS4VProjectPhase
AS 
SELECT VS4TProjectType.*, VS4TProject.*, VS4TProjectPhase.*, VS4TProjectBOQ.*, VS4TProduct.*
FROM (VS4TProjectType INNER JOIN VS4TProject ON VS4TProjectType.TPjTCode = VS4TProject.TPrjTPjTCode) INNER JOIN (VS4TProjectPhase LEFT JOIN (VS4TProjectBOQ LEFT JOIN VS4TProduct ON VS4TProjectBOQ.TP2QTBOQNo = VS4TProduct.TPdtCode) ON (VS4TProjectPhase.TPHSLn = VS4TProjectBOQ.TP2QTPHSLn) AND (VS4TProjectPhase.TPHSTPrjCode = VS4TProjectBOQ.TP2QTPHSTPrjCode)) ON VS4TProject.TPrjCode = VS4TProjectPhase.TPHSTPrjCode
GO

CREATE VIEW VS4VProjectTask
AS 
SELECT VS4TProjectType.*, VS4TProject.*, VS4TProjectPhase.*, VS4TProjectBOQ.*, VS4TProduct.*
FROM (VS4TProjectType INNER JOIN VS4TProject ON VS4TProjectType.TPjTCode = VS4TProject.TPrjTPjTCode) INNER JOIN (VS4TProjectPhase LEFT JOIN (VS4TProjectBOQ LEFT JOIN VS4TProduct ON VS4TProjectBOQ.TP2QTBOQNo = VS4TProduct.TPdtCode) ON (VS4TProjectPhase.TPHSLn = VS4TProjectBOQ.TP2QTPHSLn) AND (VS4TProjectPhase.TPHSTPrjCode = VS4TProjectBOQ.TP2QTPHSTPrjCode)) ON VS4TProject.TPrjCode = VS4TProjectPhase.TPHSTPrjCode
GO

CREATE VIEW VS4VPromotion
AS 
SELECT VS4TPromotion.*, VS4TPromotionMB.*, VS4TPOS.*
FROM VS4TPromotion INNER JOIN (VS4TPOS RIGHT JOIN VS4TPromotionMB ON VS4TPOS.TPOSCode=VS4TPromotionMB.TPMMTPOSCode) ON VS4TPromotion.TProNo=VS4TPromotionMB.TPMMTProNo
GO

CREATE VIEW VS4VPRProcessStat
AS 
SELECT VS4TPR.TPRDNo, Count(VS4TPRMB.TPRMProcessStatus) AS VPRDCount, Sum(VS4TPRMB.TPRMProcessStatus) AS VPRDStatus, VS4TPR.TPRDType
FROM VS4TPR INNER JOIN VS4TPRMB ON VS4TPR.TPRDNo=VS4TPRMB.TPRMTPRDNo
GROUP BY VS4TPR.TPRDNo, VS4TPR.TPRDType
GO

CREATE VIEW VS4VProductFacCode
AS 
SELECT VS4VPS.TPSMFactoryCode, VS4VPS.TPSMProductName
FROM VS4VPS
GROUP BY VS4VPS.TPSMFactoryCode, VS4VPS.TPSMProductName
HAVING (((VS4VPS.TPSMFactoryCode)<>''))
GO

CREATE VIEW VS4VPurPriceList
AS 
SELECT VS4TPurPriceList.*, VS4TPurPriceListMB.*, VS4TProduct.*, VS4TAP.TAPNName, VS4TUnit.*
FROM VS4TUnit INNER JOIN (VS4TPurPriceList INNER JOIN (VS4TProduct INNER JOIN (VS4TPurPriceListMB LEFT JOIN VS4TAP ON VS4TPurPriceListMB.TPUMTAPNCode = VS4TAP.TAPNCode) ON VS4TProduct.TPdtCode = VS4TPurPriceListMB.TPUMTPdtCode) ON VS4TPurPriceList.TPUPNo = VS4TPurPriceListMB.TPUMTPUPNo) ON VS4TUnit.TUntCode = VS4TPurPriceListMB.TPUMTUntCode
GO

CREATE VIEW VS4VPV
AS 
SELECT VS4TAPVoucher.*, VS4TAPVDocRef.*, VS4TAP.*, VS4TOtherExpense.*, VS4TProject.TPrjMode
FROM VS4TAP INNER JOIN ((VS4TAPVoucher LEFT JOIN VS4TProject ON VS4TAPVoucher.TAPVTPrjCode=VS4TProject.TPrjCode) INNER JOIN (((((VS4TAPVDocRef LEFT JOIN VS4TOtherExpense ON VS4TAPVDocRef.TPVRTOEXCode=VS4TOtherExpense.TOExCode) LEFT JOIN VS4TAPInvoice ON VS4TAPVDocRef.TPVRRefDocNo=VS4TAPInvoice.TIAPNo) LEFT JOIN VS4TAPCreditNote ON VS4TAPVDocRef.TPVRRefDocNo=VS4TAPCreditNote.TPCNNo) LEFT JOIN VS4TAPDebitNote ON VS4TAPVDocRef.TPVRRefDocNo=VS4TAPDebitNote.TDENNo) LEFT JOIN VS4TAPBill ON VS4TAPVDocRef.TPVRRefAPBillNo=VS4TAPBill.TPBINo) ON VS4TAPVoucher.TAPVNo=VS4TAPVDocRef.TPVRTAPVNo) ON VS4TAP.TAPNCode=VS4TAPVoucher.TAPVTAPNCode
GO

CREATE VIEW VS4VPVGL
AS 
SELECT VS4TGLTrans.*, VS4TGLTransSub.*, VS4TGLBook.*, VS4TAccountPeriod.*, VS4TAccountYear.*, VS4TACChart.*, VS4TAP.TAPNName, VS4TAR.TARNName, VS4TAPVoucher.*, VS4TACGroupSub.TAGsCode, VS4TACGroupSub.TAGsName, VS4TACGroupSub.TAGsName2, VS4TACGroup.TACGCode, VS4TACGroup.TACGName, VS4TACGroup.TACGName2
FROM (VS4TGLBook INNER JOIN ((VS4TAPVoucher LEFT JOIN VS4TAP ON VS4TAPVoucher.TAPVTAPNCode=VS4TAP.TAPNCode) INNER JOIN VS4TGLTrans ON VS4TAPVoucher.TAPVNo=VS4TGLTrans.TGLTNo) ON VS4TGLBook.TGLBCode=VS4TGLTrans.TGLTTGLBCode) INNER JOIN (VS4TACGroup INNER JOIN (VS4TACGroupSub INNER JOIN (VS4TAccountYear INNER JOIN (VS4TAccountPeriod INNER JOIN (VS4TACChart INNER JOIN (VS4TGLTransSub LEFT JOIN VS4TAR ON VS4TGLTransSub.TGTSTARNCode=VS4TAR.TARNCode) ON VS4TACChart.TACCCode=VS4TGLTransSub.TGTSTACCCode) ON (VS4TAccountPeriod.TACPTACYID=VS4TGLTransSub.TGTSTACPTACYID) AND (VS4TAccountPeriod.TACPID=VS4TGLTransSub.TGTSTACPID)) ON VS4TAccountYear.TACYID=VS4TAccountPeriod.TACPTACYID) ON VS4TACGroupSub.TAGsCode=VS4TACChart.TACCTAGsCode) ON VS4TACGroup.TACGCode=VS4TACGroupSub.TAGsTACGCode) ON VS4TGLTrans.TGLTNo=VS4TGLTransSub.TGTSTGLTNo
GO

CREATE VIEW VS4VPVPay
AS 
SELECT VS4TAPVoucher.*, VS4TAPVoucherPay.*, VS4TAP.*, VS4TChequeSub.*, VS4TProject.TPrjMode, VS4TCompanyBank.TCBBNo, VS4TCompanyBank.TCBBName, VS4TCompanyBank.TCBBName2, VS4TCompanyBank.TCBBTBraCode, VS4TCompanyBank.TCBBTBnkCode, VS4TCompanyBank.TCBBAccountType, VS4TCompanyBank.TCBBAccountName, VS4TCompanyBank.TCBBAccountNo, VS4TCompanyBank.TCBBAccountBranch, VS4TCompanyBank.TCBBCreditLimit, VS4TCompanyBank.TCBBCashBalance, VS4TCompanyBank.TCBBTACCCode, VS4TCompanyBank.TCBBParentBook, VS4TCompanyBank.TCBBBalance
FROM VS4TCompanyBank RIGHT JOIN (VS4TChequeSub RIGHT JOIN (VS4TAP INNER JOIN ((VS4TAPVoucher LEFT JOIN VS4TProject ON VS4TAPVoucher.TAPVTPrjCode = VS4TProject.TPrjCode) INNER JOIN (VS4TAPVoucherPay LEFT JOIN VS4TChequeSub2PV ON (VS4TAPVoucherPay.TPVPLn = VS4TChequeSub2PV.TS2PTPVPLn) AND (VS4TAPVoucherPay.TPVPTAPVNo = VS4TChequeSub2PV.TS2PTPVPTAPVNo)) ON VS4TAPVoucher.TAPVNo = VS4TAPVoucherPay.TPVPTAPVNo) ON VS4TAP.TAPNCode = VS4TAPVoucher.TAPVTAPNCode) ON VS4TChequeSub.TCHSNo = VS4TChequeSub2PV.TS2PTCHSNo) ON VS4TCompanyBank.TCBBNo = VS4TAPVoucherPay.TPVPTCBBNo
GO

CREATE VIEW VS4VPVSumAdjust
AS 
SELECT VS4TAPVoucherPay.TPVPTAPVNo, Sum(VS4TAPVoucherPay.TPVPAdjustTotal) AS TPVPAdjustTotal, Sum(VS4TAPVoucherPay.TPVPAmountInRate) AS TPVPAmountInRate
FROM VS4TAPVoucher INNER JOIN VS4TAPVoucherPay ON VS4TAPVoucher.TAPVNo=VS4TAPVoucherPay.TPVPTAPVNo
GROUP BY VS4TAPVoucherPay.TPVPTAPVNo
GO

CREATE VIEW VS4VPVSumPayType
AS 
SELECT VS4TAPVoucherPay.TPVPTAPVNo, VS4TAPVoucherPay.TPVPPaymentType, Sum(VS4TAPVoucherPay.TPVPAmountInRate) AS TPVPAmountInRate, Sum(VS4TAPVoucherPay.TPVPAdjustTotal) AS TPVPAdjustTotal
FROM VS4TAPVoucher INNER JOIN VS4TAPVoucherPay ON VS4TAPVoucher.TAPVNo=VS4TAPVoucherPay.TPVPTAPVNo
GROUP BY VS4TAPVoucherPay.TPVPTAPVNo, VS4TAPVoucherPay.TPVPPaymentType
GO

CREATE VIEW VS4VPVSumWTax
AS 
SELECT VS4TAPVDocRef.TPVRTAPVNo, Sum(VS4TAPVDocRef.TPVRRefDocAmount) AS TPVRRefDocAmount, Sum(VS4TAPVDocRef.TPVRAmountRate) AS TPVRAmountRate, Sum(VS4TAPVDocRef.TPVRTaxBase) AS TPVRTaxBase, Sum(VS4TAPVDocRef.TPVRWTAXTotal) AS TPVRWTAXTotal, Sum(VS4TAPVDocRef.TPVRCurDiscount) AS TPVRCurDiscount, Sum(VS4TAPVDocRef.TPVRVATTotal) AS TPVRVATTotal, Sum(VS4TAPVDocRef.TPVRCommissionBase) AS TPVRCommissionBase, Sum(VS4TAPVDocRef.TPVRCommission) AS TPVRCommission, Sum(VS4TAPVDocRef.TPVRInterestTotal) AS TPVRInterestTotal
FROM VS4TAPVoucher INNER JOIN VS4TAPVDocRef ON VS4TAPVoucher.TAPVNo=VS4TAPVDocRef.TPVRTAPVNo
GROUP BY VS4TAPVDocRef.TPVRTAPVNo
GO

CREATE VIEW VS4VQuickProduct
AS 
SELECT VS4TQuickProduct.*, VS4TQuickProductMB.*
FROM VS4TQuickProduct INNER JOIN VS4TQuickProductMB ON VS4TQuickProduct.TQPdNo = VS4TQuickProductMB.TQPMTQPdNo
GO

CREATE VIEW VS4VQuotation
AS 
SELECT VS4TQuotation.*, VS4TQuotationMB.*, VS4TPOS.*, VS4TDocumentStatus.TDStName, VS4TProject.TPrjMode, VS4TAR2.TAR2SaleCode, VS4TARGroup.TARGName, VS4TAR.TARNName, VS4TAR.TARNName2, VS4TAR.TARNTARGCode, VS4TAR.TARNTSAeCode, VS4TBranch.TBraName, VS4TSaleArea.TSAeName, VS4TProduct.TPdtTransferCode, VS4TProduct.TPdtTransferName, VS4TProduct.TPdtTransferName2, VS4TAR2.TAR2TPrvCode, VS4TProvince.TPrvName, VS4TProductSection.TPSEName, VS4TProductGroup1.TPG1Name, VS4TProduct.TPdtCustom1, VS4TProduct.TPdtCustom2, VS4TProduct.TPdtCustom3, VS4TProduct.TPdtCustom4, VS4TProduct.TPdtCustom5, VS4TProduct.TPdtCustom6, VS4TBranch.TBraAddressBill
FROM (VS4TDocumentStatus RIGHT JOIN ((((VS4TAR LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN (VS4TAR2 LEFT JOIN VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) INNER JOIN (((VS4TQuotation LEFT JOIN VS4TProject ON VS4TQuotation.TQuoTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TQuotation.TQuoTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TEmployee ON VS4TQuotation.TQuoTEmpCode = VS4TEmployee.TEmpCode) ON VS4TAR.TARNCode = VS4TQuotation.TQuoTARNCode) ON VS4TDocumentStatus.TDStCode = VS4TQuotation.TQuoTDStCode) INNER JOIN (VS4TProductSection RIGHT JOIN ((VS4TQuotationMB LEFT JOIN VS4TPOS ON VS4TQuotationMB.TQuBTPOSCode = VS4TPOS.TPOSCode) LEFT JOIN (VS4TProduct LEFT JOIN VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code) ON VS4TPOS.TPOSCode = VS4TProduct.TPdtCode) ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode) ON VS4TQuotation.TQuoNo = VS4TQuotationMB.TQuBTQuoNo
GO

CREATE VIEW VS4VQuotationHead
AS 
SELECT VS4TQuotation.*, VS4TAR.*, VS4TDocumentStatus.TDStCode, VS4TDocumentStatus.TDStName2, VS4TDocumentStatus.TDStName, VS4TAR2.TAR2SaleCode, VS4TAR2.TAR2TPrvCode, VS4TARBranch.TARDName
FROM VS4TDocumentStatus INNER JOIN ((VS4TAR LEFT JOIN VS4TAR2 ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) INNER JOIN (VS4TQuotation LEFT JOIN VS4TARBranch ON (VS4TQuotation.TQuoTARNCode = VS4TARBranch.TARDTARNCode) AND (VS4TQuotation.TQuoTARDCode = VS4TARBranch.TARDCode)) ON VS4TAR.TARNCode = VS4TQuotation.TQuoTARNCode) ON VS4TDocumentStatus.TDStCode = VS4TQuotation.TQuoTDStCode
GO

CREATE VIEW VS4VQuotationSet
AS 
SELECT VS4TQuotationSet.*, VS4TQuotationSetMB.*, VS4TQuotation.*, VS4TBranch.TBraName, VS4TBranch.TBraAddressBill
FROM (VS4TQuotation INNER JOIN (VS4TQuotationSet INNER JOIN VS4TQuotationSetMB ON VS4TQuotationSet.TQuSNo = VS4TQuotationSetMB.TQSBTQuSNo) ON (VS4TQuotation.TQuoNo = VS4TQuotationSetMB.TQSBTQuoNo) AND (VS4TQuotation.TQuoNo = VS4TQuotationSetMB.TQSBTQuoNo)) LEFT JOIN VS4TBranch ON VS4TQuotationSet.TQuSTBraCode = VS4TBranch.TBraCode
GO

CREATE VIEW VS4VRatioPeriod
AS 
SELECT VS4TGLTransMove.*, VS4TACChart.*, VS4TAccountMap.*, VS4TACGroupSub.*, VS4TBranch.TBraCode, VS4TBranch.TBraName, VS4TBranch.TBraName2
FROM VS4TBranch RIGHT JOIN (VS4TACGroupSub RIGHT JOIN ((VS4TACChart LEFT JOIN VS4TAccountMap ON VS4TACChart.TACCCode = VS4TAccountMap.TACMTACCCode) INNER JOIN VS4TGLTransMove ON VS4TACChart.TACCCode = VS4TGLTransMove.TGTMTACCCode) ON VS4TACGroupSub.TAGsCode = VS4TACChart.TACCTAGsCode) ON VS4TBranch.TBraCode = VS4TGLTransMove.TGTMTBraCode
GO

CREATE VIEW VS4VReceiveProduct
AS 
SELECT VS4TReceivePdu.*, VS4TReceivePduMB.*, VS4TBranch.TBraName, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TAR.TARNName, VS4TAR.TARNTSAeCode, VS4TSaleArea.TSAeName, VS4TAR2.TAR2SaleCode, VS4TEmployee.TEmpFullName, VS4TAR.TARNTARGCode, VS4TARGroup.TARGName, VS4TAR2.TAR2TPrvCode, VS4TProvince.TPrvName
FROM (((((VS4TReceivePdu LEFT JOIN VS4TBranch ON VS4TReceivePdu.TRCPTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TProject ON VS4TReceivePdu.TRCPTPrjCode = VS4TProject.TPrjCode) LEFT JOIN (VS4TAR LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) ON VS4TReceivePdu.TRCPTARNCode = VS4TAR.TARNCode) LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) LEFT JOIN ((VS4TAR2 LEFT JOIN VS4TEmployee ON VS4TAR2.TAR2SaleCode = VS4TEmployee.TEmpCode) LEFT JOIN VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) INNER JOIN VS4TReceivePduMB ON VS4TReceivePdu.TRCPNo = VS4TReceivePduMB.TRPMTRCPNo
GO

CREATE VIEW VS4VRevenue1
AS 
SELECT VS4TTaxTrans.*, VS4TEmployee.*, VS4TEmployeeType.TEmTTotalPeriod
FROM VS4TEmployeeType RIGHT JOIN (VS4TTaxTrans LEFT JOIN VS4TEmployee ON VS4TTaxTrans.TTxTClientCitizen = VS4TEmployee.TEmpCitizenNo) ON VS4TEmployeeType.TEmTCode = VS4TEmployee.TEmpTEmTCode
WHERE (((VS4TTaxTrans.TTxTType)=4) AND ((VS4TTaxTrans.TTxTDefaultTax)=2))
GO

CREATE VIEW VS4VRevenue1A
AS 
SELECT VS4VRevenue1.TTxTYear, VS4VRevenue1.TTxTLawType, VS4VRevenue1.TTxTClientCode, VS4VRevenue1.TEmpFullName, VS4VRevenue1.TEmpTaxNo, VS4VRevenue1.TEmpCitizenNo, VS4VRevenue1.TEmpAddress, VS4VRevenue1.TEmpSubProvince, VS4VRevenue1.TEmpCity, VS4VRevenue1.TEmpPostalCode, Min(VS4VRevenue1.TTxTCondition) AS TTxTCondition, VS4VRevenue1.TEmpSignDate, VS4VRevenue1.TEmpStatusPer, VS4VRevenue1.TEmpChildStudy, VS4VRevenue1.TEmpChildNotStudy, VS4VRevenue1.TEmpTotalReduce, VS4VRevenue1.TTxTBaseIncome, VS4VRevenue1.TTxTTaxRate, Sum(VS4VRevenue1.TTxTBaseAmount) AS TTxTBaseAmount, Sum(VS4VRevenue1.TTxTWTaxAmount) AS TTxTWTaxAmount, VS4VRevenue1.TTxTBaseIncome1, VS4VRevenue1.TTxTTaxRate1, Sum(VS4VRevenue1.TTxTBaseAmount1) AS TTxTBaseAmount1, Sum(VS4VRevenue1.TTxTWTaxAmount1) AS TTxTWTaxAmount1, VS4VRevenue1.TTxTBaseIncome2, VS4VRevenue1.TTxTTaxRate2, Sum(VS4VRevenue1.TTxTBaseAmount2) AS TTxTBaseAmount2, Sum(VS4VRevenue1.TTxTWTaxAmount2) AS TTxTWTaxAmount2, VS4VRevenue1.TTxTBaseIncome3, VS4VRevenue1.TTxTTaxRate3, Sum(VS4VRevenue1.TTxTBaseAmount3) AS TTxTBaseAmount3, Sum(VS4VRevenue1.TTxTWTaxAmount3) AS TTxTWTaxAmount3, VS4VRevenue1.TTxTBaseIncome4A, VS4VRevenue1.TTxTTaxRate4A, Sum(VS4VRevenue1.TTxTBaseAmount4A) AS TTxTBaseAmount4A, Sum(VS4VRevenue1.TTxTWTaxAmount4A) AS TTxTWTaxAmount4A, VS4VRevenue1.TTxTBaseIncome4B, VS4VRevenue1.TTxTTaxRate4B, Sum(VS4VRevenue1.TTxTBaseAmount4B) AS TTxTBaseAmount4B, Sum(VS4VRevenue1.TTxTWTaxAmount4B) AS TTxTWTaxAmount4B, VS4VRevenue1.TTxTBaseIncome5, VS4VRevenue1.TTxTTaxRate5, Sum(VS4VRevenue1.TTxTBaseAmount5) AS TTxTBaseAmount5, Sum(VS4VRevenue1.TTxTWTaxAmount5) AS TTxTWTaxAmount5, VS4VRevenue1.TTxTBaseIncome6, VS4VRevenue1.TTxTTaxRate6, Sum(VS4VRevenue1.TTxTBaseAmount6) AS TTxTBaseAmount6, Sum(VS4VRevenue1.TTxTWTaxAmount6) AS TTxTWTaxAmount6, VS4VRevenue1.TEmTTotalPeriod
FROM VS4VRevenue1
GROUP BY VS4VRevenue1.TTxTYear, VS4VRevenue1.TTxTLawType, VS4VRevenue1.TTxTClientCode, VS4VRevenue1.TEmpFullName, VS4VRevenue1.TEmpTaxNo, VS4VRevenue1.TEmpCitizenNo, VS4VRevenue1.TEmpAddress, VS4VRevenue1.TEmpSubProvince, VS4VRevenue1.TEmpCity, VS4VRevenue1.TEmpPostalCode, VS4VRevenue1.TEmpSignDate, VS4VRevenue1.TEmpStatusPer, VS4VRevenue1.TEmpChildStudy, VS4VRevenue1.TEmpChildNotStudy, VS4VRevenue1.TEmpTotalReduce, VS4VRevenue1.TTxTBaseIncome, VS4VRevenue1.TTxTTaxRate, VS4VRevenue1.TTxTBaseIncome1, VS4VRevenue1.TTxTTaxRate1, VS4VRevenue1.TTxTBaseIncome2, VS4VRevenue1.TTxTTaxRate2, VS4VRevenue1.TTxTBaseIncome3, VS4VRevenue1.TTxTTaxRate3, VS4VRevenue1.TTxTBaseIncome4A, VS4VRevenue1.TTxTTaxRate4A, VS4VRevenue1.TTxTBaseIncome4B, VS4VRevenue1.TTxTTaxRate4B, VS4VRevenue1.TTxTBaseIncome5, VS4VRevenue1.TTxTTaxRate5, VS4VRevenue1.TTxTBaseIncome6, VS4VRevenue1.TTxTTaxRate6, VS4VRevenue1.TEmTTotalPeriod, VS4VRevenue1.TTxTCancelStatus
HAVING (((VS4VRevenue1.TTxTCancelStatus)=0))
GO

CREATE VIEW VS4VRevenue3
AS 
SELECT VS4TTaxTrans.*
FROM VS4TTaxTrans
WHERE (((VS4TTaxTrans.TTxTType)=2) AND ((VS4TTaxTrans.TTxTDefaultTax)=2))
GO

CREATE VIEW VS4VRevenue53
AS 
SELECT VS4TTaxTrans.*
FROM VS4TTaxTrans
WHERE (((VS4TTaxTrans.TTxTType)=5) AND ((VS4TTaxTrans.TTxTDefaultTax)=2))
GO

CREATE VIEW VS4VRevenueWTAX
AS 
SELECT VS4TTaxTrans.*
FROM VS4TTaxTrans
WHERE (((VS4TTaxTrans.TTxTType)=3) AND ((VS4TTaxTrans.TTxTDefaultTax)=2))
GO

CREATE VIEW VS4VRevision
AS 
SELECT VS4TRevision.*, VS4TRevisionGroup.*, VS4TReviseEffect.*
FROM (VS4TRevisionGroup INNER JOIN VS4TRevision ON VS4TRevisionGroup.TReGCode=VS4TRevision.TRevTReGCode) INNER JOIN VS4TReviseEffect ON (VS4TRevision.TRevDocType=VS4TReviseEffect.TReETRevDocType) AND (VS4TRevision.TRevDocNo=VS4TReviseEffect.TReETRevDocNo) AND (VS4TRevision.TRevNo=VS4TReviseEffect.TReETRevNo)
GO

CREATE VIEW VS4VSaleAROnHandA
AS 
SELECT VS4TAR2.TAR2SaleCode AS VARHSaleCode, Count(VS4TAR.TARNCode) AS VARHProspect
FROM VS4TAR LEFT JOIN VS4TAR2 ON VS4TAR.TARNCode=VS4TAR2.TAR2TARNCode
GROUP BY VS4TAR2.TAR2SaleCode, VS4TAR.TARNTARSAlias
HAVING (((VS4TAR.TARNTARSAlias)='PROSPECT'))
GO

CREATE VIEW VS4VRV
AS 
SELECT VS4TARVoucher.*, VS4TARVDocRef.*, VS4TReceipt.*, VS4TAR.TARNName, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TBranch.TBraName, VS4TAR.TARNTARGCode, VS4TARGroup.TARGName, VS4TAR.TARNTBsTCode, VS4TBusinessType.TBstName, VS4TAR.TARNTSAeCode, VS4TSaleArea.TSAeName, VS4TAR.TARNTCouCode, VS4TCountry.TCouName, VS4TAR2.TAR2TPrvCode, VS4TProvince.TPrvName, VS4TARCreditNote.TRCNTEmpCode, VS4TARCreditNote.TRCNSaleName, VS4TARInvoice.TIvoTEmpCode, VS4TARInvoice.TIvoSaleName, VS4TARDebitNote.TDBNTEmpCode, VS4TARDebitNote.TDBNSaleName, VS4TAR.TARNName2, VS4TARInvoice.TIvoTCurCode, VS4TARInvoice.TIvoExchangeRate, VS4TARCreditNote.TRCNTCurCode, VS4TARCreditNote.TRCNExchangeRate, VS4TARDebitNote.TDBNTCurCode, VS4TARDebitNote.TDBNExchangeRate, VS4TARBill.TBilNo, VS4TARBill.TBilDate, VS4TARBill.TBilDueDate, VS4TOtherIncome.TOInCode, VS4TOtherIncome.TOInName, VS4TOtherIncome.TOInName2, VS4TOtherIncome.TOInTACCCode, VS4TAR2.TAR2SaleCode, VS4TARReceipt.TAIHNo, VS4TARReceipt.TAIHDate, VS4TARReceipt.TAIHType, VS4TBranch.TBraAddressBill
FROM (((((((((VS4TARVoucher LEFT JOIN VS4TProject ON VS4TARVoucher.TRVHTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TARVoucher.TRVHTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TAR ON VS4TARVoucher.TRVHTARNCode = VS4TAR.TARNCode) LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) LEFT JOIN VS4TBusinessType ON VS4TAR.TARNTBsTCode = VS4TBusinessType.TBsTCode) LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN VS4TCountry ON VS4TAR.TARNTCouCode = VS4TCountry.TCouCode) LEFT JOIN (VS4TAR2 LEFT JOIN VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) INNER JOIN (VS4TReceipt INNER JOIN VS4TARVandReceipt ON VS4TReceipt.TRECNo = VS4TARVandReceipt.TRNRTRECNo) ON VS4TARVoucher.TRVHNo = VS4TARVandReceipt.TRNRTRVHNo) INNER JOIN ((((((VS4TARVDocRef LEFT JOIN VS4TARReceipt ON VS4TARVDocRef.TRDRRefDocType = VS4TARReceipt.TAIHNo) LEFT JOIN VS4TARCreditNote ON VS4TARVDocRef.TRDRRefDocNo = VS4TARCreditNote.TRCNNo) LEFT JOIN VS4TARDebitNote ON VS4TARVDocRef.TRDRRefDocNo = VS4TARDebitNote.TDBNNo) LEFT JOIN VS4TARInvoice ON VS4TARVDocRef.TRDRRefDocNo = VS4TARInvoice.TIvoNo) LEFT JOIN VS4TARBill ON VS4TARVDocRef.TRDRRefBillNo = VS4TARBill.TBilNo) LEFT JOIN VS4TOtherIncome ON VS4TARVDocRef.TRDRTOINCode = VS4TOtherIncome.TOInCode) ON VS4TARVoucher.TRVHNo = VS4TARVDocRef.TRDRTRVHNo
GO

CREATE VIEW VS4VRVGL
AS 
SELECT VS4TGLTrans.*, VS4TGLTransSub.*, VS4TGLBook.*, VS4TAccountPeriod.*, VS4TAccountYear.*, VS4TACChart.*, VS4TAP.TAPNName, VS4TAR.TARNName, VS4TARVoucher.*, VS4TACGroupSub.TAGsCode, VS4TACGroupSub.TAGsName, VS4TACGroupSub.TAGsName2, VS4TACGroup.TACGCode, VS4TACGroup.TACGName, VS4TACGroup.TACGName2
FROM (VS4TGLBook INNER JOIN ((VS4TARVoucher LEFT JOIN VS4TAR ON VS4TARVoucher.TRVHTARNCode=VS4TAR.TARNCode) INNER JOIN VS4TGLTrans ON VS4TARVoucher.TRVHNo=VS4TGLTrans.TGLTNo) ON VS4TGLBook.TGLBCode=VS4TGLTrans.TGLTTGLBCode) INNER JOIN (VS4TACGroup INNER JOIN (VS4TACGroupSub INNER JOIN (VS4TAccountYear INNER JOIN (VS4TAccountPeriod INNER JOIN (VS4TACChart INNER JOIN (VS4TGLTransSub LEFT JOIN VS4TAP ON VS4TGLTransSub.TGTSTAPNCode=VS4TAP.TAPNCode) ON VS4TACChart.TACCCode=VS4TGLTransSub.TGTSTACCCode) ON (VS4TAccountPeriod.TACPTACYID=VS4TGLTransSub.TGTSTACPTACYID) AND (VS4TAccountPeriod.TACPID=VS4TGLTransSub.TGTSTACPID)) ON VS4TAccountYear.TACYID=VS4TAccountPeriod.TACPTACYID) ON VS4TACGroupSub.TAGsCode=VS4TACChart.TACCTAGsCode) ON VS4TACGroup.TACGCode=VS4TACGroupSub.TAGsTACGCode) ON VS4TGLTrans.TGLTNo=VS4TGLTransSub.TGTSTGLTNo
GO

CREATE VIEW VS4VRVMB
AS 
SELECT VS4TARVoucher.*, VS4TARVDocRef.*, VS4TARVandReceipt.*, VS4TReceipt.*, VS4TARVDocRefMB.*, VS4TARReceipt.TAIHNo, VS4TARReceipt.TAIHDate
FROM ((VS4TARVoucher INNER JOIN (VS4TReceipt INNER JOIN VS4TARVandReceipt ON VS4TReceipt.TRECNo=VS4TARVandReceipt.TRNRTRECNo) ON VS4TARVoucher.TRVHNo=VS4TARVandReceipt.TRNRTRVHNo) INNER JOIN (VS4TARVDocRef LEFT JOIN VS4TARReceipt ON VS4TARVDocRef.TRDRRefDocType=VS4TARReceipt.TAIHNo) ON VS4TARVoucher.TRVHNo=VS4TARVDocRef.TRDRTRVHNo) INNER JOIN VS4TARVDocRefMB ON (VS4TARVDocRef.TRDRTRVHNo=VS4TARVDocRefMB.TRVMTRDRTRVHNo) AND (VS4TARVDocRef.TRDRLn=VS4TARVDocRefMB.TRVMTRDRLn)
GO

CREATE VIEW VS4VRVPay
AS 
SELECT VS4TARVoucher.*, VS4TARVoucherPay.*, VS4TBank.*, VS4TCompanyBank.*, VS4TChequeRec.*, VS4TAR.TARNDiscountPC, VS4TAR.TARNDiscountDay, VS4TAR.TARNCreditDay, VS4TAR2.TAR2SaleCode, VS4TEmployee.TEmpFullName, VS4TReceipt.*, VS4TProject.TPrjMode
FROM (((((VS4TARVoucher LEFT JOIN VS4TAR ON VS4TARVoucher.TRVHTARNCode = VS4TAR.TARNCode) LEFT JOIN VS4TProject ON VS4TARVoucher.TRVHTPrjCode = VS4TProject.TPrjCode) LEFT JOIN (VS4TAR2 LEFT JOIN VS4TEmployee ON VS4TAR2.TAR2SaleCode = VS4TEmployee.TEmpCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) LEFT JOIN (VS4TReceipt RIGHT JOIN VS4TARVandReceipt ON VS4TReceipt.TRECNo = VS4TARVandReceipt.TRNRTRECNo) ON VS4TARVoucher.TRVHNo = VS4TARVandReceipt.TRNRTRVHNo) INNER JOIN (VS4TCompanyBank RIGHT JOIN (VS4TARVoucherPay LEFT JOIN VS4TBank ON VS4TARVoucherPay.TRVRTBnkCode = VS4TBank.TBnkCode) ON VS4TCompanyBank.TCBBNo = VS4TARVoucherPay.TRVRTCBBNo) ON VS4TARVoucher.TRVHNo = VS4TARVoucherPay.TRVRTRVHNo) LEFT JOIN (VS4TChequeRec RIGHT JOIN VS4TChequeRec2RV ON VS4TChequeRec.TCHRNo = VS4TChequeRec2RV.TR2RTCHRNo) ON (VS4TARVoucherPay.TRVRLn = VS4TChequeRec2RV.TR2RTRVRLn) AND (VS4TARVoucherPay.TRVRTRVHNo = VS4TChequeRec2RV.TR2RTRVRTRVHNo)
GO

CREATE VIEW VS4VRVSumAdjust
AS 
SELECT VS4TARVoucherPay.TRVRTRVHNo, Sum(VS4TARVoucherPay.TRVRAdjustTotal) AS TRVRAdjustTotal, Sum(VS4TARVoucherPay.TRVRAmountInRate) AS TRVRAmountInRate
FROM VS4TARVoucher INNER JOIN VS4TARVoucherPay ON VS4TARVoucher.TRVHNo=VS4TARVoucherPay.TRVRTRVHNo
GROUP BY VS4TARVoucherPay.TRVRTRVHNo
GO

CREATE VIEW VS4VRVSumPayType
AS 
SELECT VS4TARVoucherPay.TRVRTRVHNo, VS4TARVoucherPay.TRVRReceiveType, Sum(VS4TARVoucherPay.TRVRAmountInRate) AS TRVRAmountInRate, Sum(VS4TARVoucherPay.TRVRAdjustTotal) AS TRVRAdjustTotal
FROM VS4TARVoucher INNER JOIN VS4TARVoucherPay ON VS4TARVoucher.TRVHNo=VS4TARVoucherPay.TRVRTRVHNo
GROUP BY VS4TARVoucherPay.TRVRTRVHNo, VS4TARVoucherPay.TRVRReceiveType
GO

CREATE VIEW VS4VRVSumWTAX
AS 
SELECT VS4TARVDocRef.TRDRTRVHNo, Sum(VS4TARVDocRef.TRDRRefDocAmount) AS TRDRRefDocAmount, Sum(VS4TARVDocRef.TRDRAmountRate) AS TRDRAmountRate, Sum(VS4TARVDocRef.TRDRCurDiscount) AS TRDRCurDiscount, Sum(VS4TARVDocRef.TRDRTaxBase) AS TRDRTaxBase, Sum(VS4TARVDocRef.TRDRWTAXTotal) AS TRDRWTAXTotal, Sum(VS4TARVDocRef.TRDRVATTotal) AS TRDRVATTotal, Sum(VS4TARVDocRef.TRDRCommissionBase) AS TRDRCommissionBase, Sum(VS4TARVDocRef.TRDRCommission) AS TRDRCommission, Sum(VS4TARVDocRef.TRDRInterestTotal) AS TRDRInterestTotal
FROM VS4TARVoucher INNER JOIN VS4TARVDocRef ON VS4TARVoucher.TRVHNo=VS4TARVDocRef.TRDRTRVHNo
GROUP BY VS4TARVDocRef.TRDRTRVHNo
GO

CREATE VIEW VS4VSaleAROnHandB
AS 
SELECT VS4TAR2.TAR2SaleCode AS VARHSaleCode2, Count(VS4TAR.TARNCode) AS VARHLoss
FROM VS4TAR LEFT JOIN VS4TAR2 ON VS4TAR.TARNCode=VS4TAR2.TAR2TARNCode
GROUP BY VS4TAR2.TAR2SaleCode, VS4TAR.TARNTARSAlias
HAVING (((VS4TAR.TARNTARSAlias)='LOSS'))
GO

CREATE VIEW VS4VSaleAROnHandC
AS 
SELECT VS4VSaleAROnHandA.VARHSaleCode, VS4VSaleAROnHandA.VARHProspect, VS4VSaleAROnHandB.VARHLoss
FROM VS4VSaleAROnHandA INNER JOIN VS4VSaleAROnHandB ON VS4VSaleAROnHandA.VARHSaleCode=VS4VSaleAROnHandB.VARHSaleCode2
GO

CREATE VIEW VS4VSaleAROnHandD
AS 
SELECT VS4TAR2.TAR2SaleCode AS VARHSaleCode3, Count(VS4TAR.TARNCode) AS VARHTotal
FROM VS4TAR LEFT JOIN VS4TAR2 ON VS4TAR.TARNCode=VS4TAR2.TAR2TARNCode
GROUP BY VS4TAR2.TAR2SaleCode
GO

CREATE VIEW VS4VSaleAROnHand
AS 
SELECT VS4VSaleAROnHandC.VARHSaleCode, VS4VSaleAROnHandC.VARHProspect, VS4VSaleAROnHandC.VARHLoss, VS4VSaleAROnHandD.VARHTotal
FROM VS4VSaleAROnHandC INNER JOIN VS4VSaleAROnHandD ON VS4VSaleAROnHandC.VARHSaleCode=VS4VSaleAROnHandD.VARHSaleCode3
GO

CREATE VIEW VS4VRO
AS 
SELECT VS4TSO.*, VS4TSOMB.*, VS4TAR.TARNName2, VS4TAR.TARNPhone, VS4TAR.TARNFax, VS4TProject.TPrjMode, VS4TARGroup.TARGName, VS4TAR.TARNName, VS4TAR.TARNTARGCode, VS4TAR.TARNTSAeCode, VS4TAR2.TAR2SaleCode, VS4TEmployee.TEmpFullName, VS4TSaleArea.TSAeName, VS4TBranch.TBraName, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtAliasName, VS4TProduct.TPdtDescription, VS4TProduct.TPdtOnSale, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TProduct.TPdtTPTTCode, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtTPSECode, VS4TProduct.TPdtCode, VS4TAR.TARNTBsTCode, VS4TBusinessType.TBstName, VS4TProduct.TPdtTPS2Code, VS4TProduct.TPdtTPS3Code, VS4TProduct.TPdtTPS4Code, VS4TProduct.TPdtTPG1Code, VS4TProduct.TPdtTPG2Code, VS4TProduct.TPdtTPG3Code, VS4TProductLine.TPdLName, VS4TProductSection.TPSEName, VS4TProductSec2.TPS2Name, VS4TProductSec3.TPS3Name, VS4TProductGroup1.TPG1Name, VS4TProductGroup2.TPG2Name, VS4TBusinessMajor.TBsMName, VS4TAR2.TAR2TPrvCode, VS4TProvince.TPrvName, VS4TProduct.TPdtAverageCost, VS4VSaleAROnHand.*, VS4TProduct.TPdtGroupReport, VS4TLocation.TLctTWahCode, VS4TProduct.TPdtCustom1, VS4TProduct.TPdtCustom2, VS4TProduct.TPdtCustom3, VS4TAR.TARNFirstOrderDate, VS4TProduct.TPdtStartDate, VS4TProduct.TPdtEndDate, VS4TProduct.TPdtTAILCode, VS4TAP.TAPNShortName AS VRODGuide1, VS4TAP_1.TAPNShortName AS VRODGuide2, VS4TAP_2.TAPNShortName AS VRODTLName, VS4TPOS.TPOSTPSGCode, VS4TPOSSaleGroup.TPSGName, VS4TBranch.TBraAddressBill
FROM (VS4TCountry INNER JOIN (VS4TBusinessType RIGHT JOIN ((((VS4TAR LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN ((VS4TAR2 LEFT JOIN VS4TBusinessMajor ON VS4TAR2.TAR2TBSMCode = VS4TBusinessMajor.TBsMCode) LEFT JOIN VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) INNER JOIN (((((VS4TSO LEFT JOIN VS4TProject ON VS4TSO.TSODTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TSO.TSODTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4VSaleAROnHand ON VS4TSO.TSODTEmpCode = VS4VSaleAROnHand.VARHSaleCode) LEFT JOIN VS4TEmployee ON VS4TSO.TSODTEmpCode = VS4TEmployee.TEmpCode) LEFT JOIN VS4TARBranch ON (VS4TSO.TSODTARDCode = VS4TARBranch.TARDCode) AND (VS4TSO.TSODTARNCode = VS4TARBranch.TARDTARNCode)) ON VS4TAR.TARNCode = VS4TSO.TSODTARNCode) ON VS4TBusinessType.TBsTCode = VS4TAR.TARNTBsTCode) ON VS4TCountry.TCouCode = VS4TAR.TARNTCouCode) INNER JOIN (VS4TProductLine RIGHT JOIN ((((((((VS4TSOMB LEFT JOIN VS4TPOS ON VS4TSOMB.TSOBTPOSCode = VS4TPOS.TPOSCode) LEFT JOIN VS4TLocation ON VS4TSOMB.TSOBTLctCode = VS4TLocation.TLctCode) LEFT JOIN (((((((VS4TProduct LEFT JOIN VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode) LEFT JOIN VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code) LEFT JOIN VS4TProductSec3 ON VS4TProduct.TPdtTPS3Code = VS4TProductSec3.TPS3Code) LEFT JOIN VS4TProductSec4 ON VS4TProduct.TPdtTPS4Code = VS4TProductSec4.TPS4Code) LEFT JOIN VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code) LEFT JOIN VS4TProductGroup2 ON VS4TProduct.TPdtTPG2Code = VS4TProductGroup2.TPG2Code) LEFT JOIN VS4TProductGroup3 ON VS4TProduct.TPdtTPG3Code = VS4TProductGroup3.TPG3Code) ON VS4TPOS.TPOSCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TProductBook ON VS4TProduct.TPdtCode = VS4TProductBook.TPBGTPdtCode) LEFT JOIN VS4TAP ON VS4TPOS.TPOSG1TAPNCode = VS4TAP.TAPNCode) LEFT JOIN VS4TAP AS VS4TAP_1 ON VS4TPOS.TPOSG2TAPNCode = VS4TAP_1.TAPNCode) LEFT JOIN VS4TAP AS VS4TAP_2 ON VS4TPOS.TPOSTLTAPNCode = VS4TAP_2.TAPNCode) LEFT JOIN VS4TPOSSaleGroup ON VS4TPOS.TPOSTPSGCode = VS4TPOSSaleGroup.TPSGCode) ON VS4TProductLine.TPdLCode = VS4TProduct.TPdtTPDLCode) ON VS4TSO.TSODNo = VS4TSOMB.TSOBTSODNo
GO

CREATE VIEW VS4VSaleForecast
AS 
SELECT VS4TSaleForecast.*, VS4TProduct.*, VS4TPOS.*, VS4TEmployee.TEmpFullName, VS4TEmployee.TEmpFullName2, VS4TEmployee.TEmpTPstCode, VS4TEmployee.TEmpTSecCode, VS4TEmployee.TEmpTDepCode, VS4TEmployee.TEmpTDivCode, VS4TEmployee.TEmpTBraCode, VS4TBranch.TBraName, VS4TBranch.TBraName2, VS4TSection.TSecName, VS4TDivision.TDivName, VS4TDivision.TDivName2, VS4TDepartment.TDepName, VS4TDepartment.TDepName2, VS4TPosition.TPstName, VS4TPosition.TPstName2
FROM VS4TPosition RIGHT JOIN (VS4TDivision RIGHT JOIN (VS4TBranch RIGHT JOIN (((((VS4TSaleForecast INNER JOIN VS4TProduct ON VS4TSaleForecast.TSFCTPdtCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) LEFT JOIN VS4TEmployee ON VS4TSaleForecast.TSFCTEmpCode = VS4TEmployee.TEmpCode) LEFT JOIN VS4TSection ON VS4TEmployee.TEmpTSecCode = VS4TSection.TSecCode) LEFT JOIN VS4TDepartment ON VS4TEmployee.TEmpTDepCode = VS4TDepartment.TDepCode) ON VS4TBranch.TBraCode = VS4TEmployee.TEmpTBraCode) ON VS4TDivision.TDivCode = VS4TEmployee.TEmpTDivCode) ON VS4TPosition.TPstCode = VS4TEmployee.TEmpTPstCode
WHERE (((VS4TPOS.TPOSType)=0))
GO

CREATE VIEW VS4VSaleTarget
AS 
SELECT VS4TSaleTarget.*, VS4TSaleTargetMB.*, VS4TEmployee.*, VS4TSection.TSecName, VS4TSection.TSecName2, VS4TDepartment.TDepName, VS4TDepartment.TDepName2, VS4TDivision.TDivName, VS4TDivision.TDivName2, VS4TBranch.TBraName, VS4TBranch.TBraName2, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProductLine.TPdLName, VS4TProductLine.TPdLName2, VS4TProductSection.TPSEName, VS4TProductSection.TPSEName2, VS4TProductSec2.TPS2Name, VS4TProductSec2.TPS2Name2, VS4TProductSec3.TPS3Name, VS4TProductSec3.TPS3Name2, VS4TProductSec4.TPS4Name, VS4TProductSec4.TPS4Name2
FROM VS4TSaleTarget INNER JOIN (VS4TDivision RIGHT JOIN ((((((((((VS4TSaleTargetMB LEFT JOIN VS4TEmployee ON VS4TSaleTargetMB.TSGMTEmpCode = VS4TEmployee.TEmpCode) LEFT JOIN VS4TSection ON VS4TEmployee.TEmpTSecCode = VS4TSection.TSecCode) LEFT JOIN VS4TBranch ON VS4TEmployee.TEmpTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TDepartment ON VS4TEmployee.TEmpTDepCode = VS4TDepartment.TDepCode) LEFT JOIN VS4TProduct ON VS4TSaleTargetMB.TSGMTPdtCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TProductLine ON VS4TSaleTargetMB.TSGMTPDLCode = VS4TProductLine.TPdLCode) LEFT JOIN VS4TProductSection ON VS4TSaleTargetMB.TSGMTPSECode = VS4TProductSection.TPSECode) LEFT JOIN VS4TProductSec2 ON VS4TSaleTargetMB.TSGMTPS2Code = VS4TProductSec2.TPS2Code) LEFT JOIN VS4TProductSec3 ON VS4TSaleTargetMB.TSGMTPS3Code = VS4TProductSec3.TPS3Code) LEFT JOIN VS4TProductSec4 ON VS4TSaleTargetMB.TSGMTPS4Code = VS4TProductSec4.TPS4Code) ON VS4TDivision.TDivCode = VS4TEmployee.TEmpTDivCode) ON VS4TSaleTarget.TSTGNo = VS4TSaleTargetMB.TSGMTSTGNo
GO

CREATE VIEW VS4VScrap
AS 
SELECT VS4TScrap.*, VS4TSection.TSecName, VS4TDepartment.TDepName, VS4TDivision.TDivName, VS4TBranch.TBraName
FROM (((VS4TScrap LEFT JOIN VS4TSection ON VS4TScrap.TLotTSecCode=VS4TSection.TSecCode) LEFT JOIN VS4TDepartment ON VS4TScrap.TLotTDepCode=VS4TDepartment.TDepCode) LEFT JOIN VS4TDivision ON VS4TScrap.TLotTDivCode=VS4TDivision.TDivCode) LEFT JOIN VS4TBranch ON VS4TScrap.TLotTBraCode=VS4TBranch.TBraCode
GO

CREATE VIEW VS4VShipinstruct
AS 
SELECT VS4TShipInstruct.*, VS4TPackingList.*, VS4TPackingListMB.*, VS4TARInvoiceMB.*
FROM (VS4TShipInstruct LEFT JOIN VS4TPackingList ON VS4TShipInstruct.TSPIRefNo2 = VS4TPackingList.TPKLNo) LEFT JOIN (VS4TARInvoice RIGHT JOIN (VS4TPackingListMB LEFT JOIN VS4TARInvoiceMB ON (VS4TPackingListMB.TPKMSourceLn = VS4TARInvoiceMB.TIoMLn) AND (VS4TPackingListMB.TPKMSourceNo = VS4TARInvoiceMB.TIoMTIvoNo)) ON VS4TARInvoice.TIvoNo = VS4TARInvoiceMB.TIoMTIvoNo) ON VS4TPackingList.TPKLNo = VS4TPackingListMB.TPKMTPKLNo
GO

CREATE VIEW VS4VSO
AS 
SELECT VS4TSO.*, VS4TSOMB.*, VS4TAR.TARNName2, VS4TAR.TARNPhone, VS4TAR.TARNFax, VS4TProject.TPrjMode, VS4TARGroup.TARGName, VS4TAR.TARNName, VS4TAR.TARNTARGCode, VS4TAR.TARNTSAeCode, VS4TAR2.TAR2SaleCode, VS4TEmployee.TEmpFullName, VS4TSaleArea.TSAeName, VS4TBranch.TBraName, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtAliasName, VS4TProduct.TPdtDescription, VS4TProduct.TPdtOnSale, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TProduct.TPdtTPTTCode, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtTPSECode, VS4TProduct.TPdtCode, VS4TAR.TARNTBsTCode, VS4TBusinessType.TBstName, VS4TProduct.TPdtTPS2Code, VS4TProduct.TPdtTPS3Code, VS4TProduct.TPdtTPS4Code, VS4TProduct.TPdtTPG1Code, VS4TProduct.TPdtTPG2Code, VS4TProduct.TPdtTPG3Code, VS4TProductLine.TPdLName, VS4TProductSection.TPSEName, VS4TProductSec2.TPS2Name, VS4TProductSec3.TPS3Name, VS4TProductGroup1.TPG1Name, VS4TProductGroup2.TPG2Name, VS4TBusinessMajor.TBsMName, VS4TAR2.TAR2TPrvCode, VS4TProvince.TPrvName, VS4TProduct.TPdtTransferCode, VS4TProduct.TPdtTransferName, VS4TProduct.TPdtTransferName2, VS4TProduct.TPdtAverageCost, VS4VSaleAROnHand.*, VS4TProduct.TPdtGroupReport, VS4TLocation.TLctTWahCode, VS4TProduct.TPdtCustom1, VS4TProduct.TPdtCustom2, VS4TProduct.TPdtCustom3, VS4TProduct.TPdtCustom4, VS4TProduct.TPdtCustom5, VS4TProduct.TPdtCustom6, VS4TAR.TARNFirstOrderDate, VS4TProduct.TPdtStartDate, VS4TProduct.TPdtEndDate, VS4TBranch.TBraAddressBill
FROM (VS4TCountry INNER JOIN (VS4TBusinessType RIGHT JOIN ((((VS4TAR LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN ((VS4TAR2 LEFT JOIN VS4TBusinessMajor ON VS4TAR2.TAR2TBSMCode = VS4TBusinessMajor.TBsMCode) LEFT JOIN VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) INNER JOIN (((((VS4TSO LEFT JOIN VS4TProject ON VS4TSO.TSODTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TSO.TSODTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4VSaleAROnHand ON VS4TSO.TSODTEmpCode = VS4VSaleAROnHand.VARHSaleCode) LEFT JOIN VS4TEmployee ON VS4TSO.TSODTEmpCode = VS4TEmployee.TEmpCode) LEFT JOIN VS4TARBranch ON (VS4TSO.TSODTARDCode = VS4TARBranch.TARDCode) AND (VS4TSO.TSODTARNCode = VS4TARBranch.TARDTARNCode)) ON VS4TAR.TARNCode = VS4TSO.TSODTARNCode) ON VS4TBusinessType.TBsTCode = VS4TAR.TARNTBsTCode) ON VS4TCountry.TCouCode = VS4TAR.TARNTCouCode) INNER JOIN (VS4TProductLine RIGHT JOIN ((((VS4TSOMB LEFT JOIN VS4TPOS ON VS4TSOMB.TSOBTPOSCode = VS4TPOS.TPOSCode) LEFT JOIN VS4TLocation ON VS4TSOMB.TSOBTLctCode = VS4TLocation.TLctCode) LEFT JOIN ((((((((VS4TProduct LEFT JOIN VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode) LEFT JOIN VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code) LEFT JOIN VS4TProductSec3 ON VS4TProduct.TPdtTPS3Code = VS4TProductSec3.TPS3Code) LEFT JOIN VS4TProductSec4 ON VS4TProduct.TPdtTPS4Code = VS4TProductSec4.TPS4Code) LEFT JOIN VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code) LEFT JOIN VS4TProductGroup2 ON VS4TProduct.TPdtTPG2Code = VS4TProductGroup2.TPG2Code) LEFT JOIN VS4TProductGroup3 ON VS4TProduct.TPdtTPG3Code = VS4TProductGroup3.TPG3Code) LEFT JOIN VS4TProductGroup4 ON VS4TProduct.TPdtTPG4Code = VS4TProductGroup4.TPG4Code) ON VS4TPOS.TPOSCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TProductBook ON VS4TProduct.TPdtCode = VS4TProductBook.TPBGTPdtCode) ON VS4TProductLine.TPdLCode = VS4TProduct.TPdtTPDLCode) ON VS4TSO.TSODNo = VS4TSOMB.TSOBTSODNo
GO

CREATE VIEW VS4VSO2Invoice
AS 
SELECT VS4TSO.*, VS4TSOMB.*, VS4TSODelivery.*, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TBranch.TBraName, VS4TAR.TARNName, VS4TSaleArea.TSAeName, VS4TAR2.TAR2SaleCode, VS4TEmployee.TEmpFullName, VS4TAR.TARNTSAeCode, VS4TAR.TARNTARGCode, VS4TProduct.TPdtName, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TAR2.TAR2TPrvCode, VS4TProvince.TPrvName, VS4TAR.TARNPhone, VS4TAR.TARNFax, VS4TAR.TARNCreditLimit, VS4TProduct.TPdtGroupReport, VS4TARInvoiceMB.TIoMTIvoNo, VS4TARInvoiceMB.TIoMQuantity, VS4TARInvoiceMB.TIoMTUntCode, VS4TARInvoice.TIvoDate, VS4TJobMB.TJbMSourceDate, VS4TARInvoice.TIvoPONo, VS4TARInvoiceMB.TIoMAmountVAT, VS4TARInvoiceMB.TIoMAmountWTAX
FROM ((((VS4TAR LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN ((VS4TAR2 LEFT JOIN VS4TEmployee ON VS4TAR2.TAR2SaleCode = VS4TEmployee.TEmpCode) LEFT JOIN VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) INNER JOIN ((VS4TSO LEFT JOIN VS4TProject ON VS4TSO.TSODTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TSO.TSODTBraCode = VS4TBranch.TBraCode) ON VS4TAR.TARNCode = VS4TSO.TSODTARNCode) INNER JOIN ((VS4TARInvoice RIGHT JOIN ((((VS4TSOMB LEFT JOIN VS4TSODelivery ON (VS4TSOMB.TSOBLn = VS4TSODelivery.TMDSTSOBLn) AND (VS4TSOMB.TSOBTSODNo = VS4TSODelivery.TMDSTSOBTSODNo)) LEFT JOIN VS4TProduct ON VS4TSODelivery.TMDSProductCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TARInvoiceMB ON (VS4TSOMB.TSOBLn = VS4TARInvoiceMB.TIoMSourceLn) AND (VS4TSOMB.TSOBTSODNo = VS4TARInvoiceMB.TIoMSourceNo)) LEFT JOIN VS4TJob ON VS4TSOMB.TSOBJobCode = VS4TJob.TJobCode) ON VS4TARInvoice.TIvoNo = VS4TARInvoiceMB.TIoMTIvoNo) LEFT JOIN VS4TJobMB ON VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo) ON VS4TSO.TSODNo = VS4TSOMB.TSOBTSODNo
GO

CREATE VIEW VS4VSO2PO
AS 
SELECT VS4TSO.TSODNo, VS4TSO.TSODCode, VS4TSO.TSODType, VS4TSO.TSODDate, VS4TSO.TSODDueDate, VS4TSO.TSODRefNo, VS4TSO.TSODRefDate, VS4TSO.TSODDeliveryDate, VS4TSO.TSODTEmpCode, VS4TSO.TSODSaleName, VS4TSO.TSODDeliveryTo, VS4TSO.TSODTARNCode, VS4TSO.TSODContactNote, VS4TSO.TSODContactName, VS4TSO.TSODCustomerName, VS4TSO.TSODDayAvailable, VS4TProject.TPrjName, VS4TJob.TJobNo, VS4TJob.TJobCode, VS4TPR.*, VS4TPRMB.*, VS4TPO.TPODNo, VS4TPO.TPODType, VS4TPO.TPODDate, VS4TPO.TPODDueDate, VS4TPO.TPODDeliveryDate, VS4TPO.TPODDeliveryTo, VS4TPO.TPODTAPNCode, VS4TPO.TPODSupplierName, VS4TPOMB.*, VS4TSO.TSODTPrjCode, VS4TPODelivery.TPDEDate, VS4TPODelivery.TPDEDateTime, VS4TPODelivery.TPDEQuantity, VS4TPODelivery.TPDEQuantity2, VS4TPODelivery.TPDEQuantity3, VS4TPODelivery.TPDETotalDelivery, VS4TPODelivery.TPDETotalDelivery2, VS4TPODelivery.TPDETotalDelivery3, VS4TPODelivery.TPDETotalArrear, VS4TPODelivery.TPDETotalArrear2, VS4TPODelivery.TPDETotalArrear3, VS4TSOMB.TSOBTPOSCode, VS4TSOMB.TSOBCustom1, VS4TSOMB.TSOBCustom2, VS4TSOMB.TSOBCustom3, VS4TSOMB.TSOBPOSName, VS4TSOMB.TSOBQuantityCalc, VS4TSOMB.TSOBUnitCalc, VS4TSOMB.TSOBQuantity, VS4TSOMB.TSOBTUntCode, VS4TSOMB.TSOBQuantity2, VS4TSOMB.TSOBTUntCode2, VS4TSOMB.TSOBQuantity3, VS4TSOMB.TSOBTUntCode3, VS4TSOMB.TSOBAmount, VS4TSOMB.TSOBPrice, VS4TSOMB.TSOBJobCode, VS4TSOMB.TSOBType, VS4TSOMB.TSOBPOSCode, VS4TSOMB.TSOBLn, VS4TSOMB.TSOBCustom4, VS4TSOMB.TSOBCustom5
FROM (VS4TPR RIGHT JOIN (VS4TPO RIGHT JOIN (((VS4TSO LEFT JOIN VS4TProject ON VS4TSO.TSODTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TJob ON VS4TSO.TSODNo = VS4TJob.TJobRefNo) LEFT JOIN ((VS4TPRMB LEFT JOIN VS4TPOMB ON (VS4TPRMB.TPRMLn = VS4TPOMB.TPOBSourceLn) AND (VS4TPRMB.TPRMTPRDNo = VS4TPOMB.TPOBSourceNo)) LEFT JOIN VS4TPODelivery ON (VS4TPOMB.TPOBLn = VS4TPODelivery.TPDETPOBLn) AND (VS4TPOMB.TPOBTPODNo = VS4TPODelivery.TPDETPOBTPODNo)) ON VS4TJob.TJobNo = VS4TPRMB.TPRMTJobNo) ON VS4TPO.TPODNo = VS4TPOMB.TPOBTPODNo) ON VS4TPR.TPRDNo = VS4TPRMB.TPRMTPRDNo) INNER JOIN VS4TSOMB ON VS4TSO.TSODNo = VS4TSOMB.TSOBTSODNo
GO

CREATE VIEW VS4VSOSumDay
AS 
SELECT VS4TSO.TSODTARNCode, Sum(VS4TSO.TSODTaxBase) AS TSODTaxBase, Month(TSODDate) AS VSSDMonth, Year(tsoddate) AS VSSDYear, Day(TSODDate) AS VSSDDay
FROM VS4TSO
GROUP BY VS4TSO.TSODTARNCode, Month(TSODDate), Year(tsoddate), Day(TSODDate)
GO

CREATE VIEW VS4VSOAppointmentM
AS 
SELECT VS4TAR.*, VS4TAR2.*, VS4TSaleArea.*, VS4TSaleZone.*, VS4TEmployee.TEmpCode, VS4TEmployee.TEmpFullName, VS4TARGroup.TARGName, VS4TBusinessType.TBstName, VS4TBusinessMajor.TBsMName, VS4VARAppCount.*, VS4TEmployee.TEmpAliasName
FROM VS4TSaleZone RIGHT JOIN (VS4TBusinessType RIGHT JOIN ((((VS4TAR LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) RIGHT JOIN VS4VARAppCount ON VS4TAR.TARNCode = VS4VARAppCount.TARATARNCode) LEFT JOIN ((VS4TAR2 LEFT JOIN VS4TEmployee ON VS4TAR2.TAR2SaleCode = VS4TEmployee.TEmpCode) LEFT JOIN VS4TBusinessMajor ON VS4TAR2.TAR2TBSMCode = VS4TBusinessMajor.TBsMCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) ON VS4TBusinessType.TBsTCode = VS4TAR.TARNTBsTCode) ON VS4TSaleZone.TSZnCode = VS4TSaleArea.TSaeTSZnCode
GO

CREATE VIEW VS4VSOSumMonth
AS 
SELECT VS4TSO.TSODTARNCode, Sum(VS4TSO.TSODTaxBase) AS TSODTaxBase, Month(TSODDate) AS VSODMonth, Year(tsoddate) AS VSODYear
FROM VS4TSO
GROUP BY VS4TSO.TSODTARNCode, Month(TSODDate), Year(tsoddate)
GO

CREATE VIEW VS4VSOAppointmentN
AS 
SELECT VS4TAR.*, VS4TAR2.*, VS4TSaleArea.*, VS4TSaleZone.*, VS4TEmployee.TEmpCode, VS4TEmployee.TEmpFullName, VS4TARGroup.TARGName, VS4TBusinessType.TBstName, VS4VARAppCountY.*, VS4TBusinessMajor.TBsMName, VS4VARAppCntYear.VARYCount, VS4TEmployee.TEmpAliasName
FROM VS4TSaleZone RIGHT JOIN (VS4TBusinessType RIGHT JOIN (((VS4VARAppCountY LEFT JOIN ((VS4TAR LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) ON VS4VARAppCountY.TARATARNCode = VS4TAR.TARNCode) LEFT JOIN VS4VARAppCntYear ON (VS4VARAppCountY.VARSYear = VS4VARAppCntYear.VARYYear) AND (VS4VARAppCountY.TARATARNCode = VS4VARAppCntYear.TARATARNCode)) LEFT JOIN ((VS4TAR2 LEFT JOIN VS4TEmployee ON VS4TAR2.TAR2SaleCode = VS4TEmployee.TEmpCode) LEFT JOIN VS4TBusinessMajor ON VS4TAR2.TAR2TBSMCode = VS4TBusinessMajor.TBsMCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) ON VS4TBusinessType.TBsTCode = VS4TAR.TARNTBsTCode) ON VS4TSaleZone.TSZnCode = VS4TSaleArea.TSaeTSZnCode
GO

CREATE VIEW VS4VSOAppointmentY
AS 
SELECT VS4VSOSumMonth.*, VS4VSOAppointmentN.*
FROM VS4VSOAppointmentN, VS4VSOSumMonth
GO

CREATE VIEW VS4VSOApprove
AS 
SELECT VS4TSO.*, VS4TSOMB.*, VS4TProject.TPrjName, VS4TAR.TARNName2, VS4TCountry.TCouName, VS4TCountry.TCouName2, VS4TAR.TARNPhone, VS4TAR.TARNFax, VS4TProject.TPrjMode, VS4TARGroup.TARGName, VS4TAR.TARNName, VS4TAR.TARNTARGCode, VS4TAR.TARNTSAeCode, VS4TAR2.TAR2SaleCode, VS4TEmployee.TEmpFullName, VS4TSaleArea.TSAeName, VS4TBranch.TBraName, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtAliasName, VS4TProduct.TPdtDescription, VS4TProduct.TPdtCustom1, VS4TProduct.TPdtCustom2, VS4TProduct.TPdtCustom3, VS4TProduct.TPdtCustom4, VS4TProduct.TPdtOnSale, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TProduct.TPdtTPTTCode, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtTPSECode, VS4TProduct.TPdtCode, VS4TAR.TARNTBsTCode, VS4TBusinessType.TBstName, VS4TProduct.TPdtTPS2Code, VS4TProduct.TPdtTPS3Code, VS4TProduct.TPdtTPS4Code, VS4TProduct.TPdtTPG1Code, VS4TProduct.TPdtTPG2Code, VS4TProduct.TPdtTPG3Code, VS4TProduct.TPdtTPG4Code, VS4TProductLine.TPdLName, VS4TProductSection.TPSEName, VS4TProductSec2.TPS2Name, VS4TProductSec3.TPS3Name, VS4TProductSec4.TPS4Name, VS4TProductGroup1.TPG1Name, VS4TProductGroup2.TPG2Name, VS4TProductGroup3.TPG3Name, VS4TProductGroup4.TPG4Name, VS4TBusinessMajor.TBsMName, VS4TAR2.TAR2TPrvCode, VS4TProvince.TPrvName, VS4TProduct.TPdtTransferCode, VS4TProduct.TPdtTransferName, VS4TProduct.TPdtTransferName2
FROM (VS4TCountry INNER JOIN (VS4TBusinessType RIGHT JOIN ((((VS4TAR LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN (((VS4TAR2 LEFT JOIN VS4TEmployee ON VS4TAR2.TAR2SaleCode = VS4TEmployee.TEmpCode) LEFT JOIN VS4TBusinessMajor ON VS4TAR2.TAR2TBSMCode = VS4TBusinessMajor.TBsMCode) LEFT JOIN VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) INNER JOIN ((VS4TSO LEFT JOIN VS4TProject ON VS4TSO.TSODTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TSO.TSODTBraCode = VS4TBranch.TBraCode) ON VS4TAR.TARNCode = VS4TSO.TSODTARNCode) ON VS4TBusinessType.TBsTCode = VS4TAR.TARNTBsTCode) ON VS4TCountry.TCouCode = VS4TAR.TARNTCouCode) INNER JOIN (VS4TProductLine RIGHT JOIN ((VS4TSOMB LEFT JOIN VS4TPOS ON VS4TSOMB.TSOBTPOSCode = VS4TPOS.TPOSCode) LEFT JOIN ((((((((VS4TProduct LEFT JOIN VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode) LEFT JOIN VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code) LEFT JOIN VS4TProductSec3 ON VS4TProduct.TPdtTPS3Code = VS4TProductSec3.TPS3Code) LEFT JOIN VS4TProductSec4 ON VS4TProduct.TPdtTPS4Code = VS4TProductSec4.TPS4Code) LEFT JOIN VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code) LEFT JOIN VS4TProductGroup2 ON VS4TProduct.TPdtTPG2Code = VS4TProductGroup2.TPG2Code) LEFT JOIN VS4TProductGroup3 ON VS4TProduct.TPdtTPG3Code = VS4TProductGroup3.TPG3Code) LEFT JOIN VS4TProductGroup4 ON VS4TProduct.TPdtTPG4Code = VS4TProductGroup4.TPG4Code) ON VS4TPOS.TPOSCode = VS4TProduct.TPdtCode) ON VS4TProductLine.TPdLCode = VS4TProduct.TPdtTPDLCode) ON VS4TSO.TSODNo = VS4TSOMB.TSOBTSODNo
WHERE (((VS4TSO.TSODApproveStatus)=1) AND ((VS4TSO.TSODCancelStatus)=0))
GO

CREATE VIEW VS4VSOBookStatus
AS 
SELECT VS4TSO.TSODNo, VS4TSO.TSODTARNCode, VS4TSO.TSODCustomerName, VS4TSO.TSODContactName, VS4TSO.TSODContactNote, VS4TSOMB.TSOBTPOSCode, Sum(VS4TSOMB.TSOBQuantity) AS TSOBQuantity, VS4TSO.TSODArrears, VS4TSO.TSODTEmpCode, VS4TSO.TSODCancelStatus
FROM VS4TSO INNER JOIN VS4TSOMB ON VS4TSO.TSODNo = VS4TSOMB.TSOBTSODNo
GROUP BY VS4TSO.TSODNo, VS4TSO.TSODTARNCode, VS4TSO.TSODCustomerName, VS4TSO.TSODContactName, VS4TSO.TSODContactNote, VS4TSOMB.TSOBTPOSCode, VS4TSO.TSODArrears, VS4TSO.TSODTEmpCode, VS4TSO.TSODCancelStatus, VS4TSO.TSODApproveStatus
HAVING (((VS4TSO.TSODApproveStatus)=1))
GO

CREATE VIEW VS4VSOCRMSumYear
AS 
SELECT VS4VSOSumMonth.*, VS4VARAppCountY.*, VS4TAR2.TAR2SaleCode, VS4TEmployee.TEmpFullName, VS4TAR.TARNTSAeCode, VS4TSaleArea.TSAeName, VS4TAR.TARNName, VS4TEmployee.TEmpAliasName
FROM (((VS4VSOSumMonth LEFT JOIN VS4VARAppCountY ON (VS4VSOSumMonth.TSODTARNCode = VS4VARAppCountY.TARATARNCode) AND (VS4VSOSumMonth.VSODMonth = VS4VARAppCountY.VARSMonth) AND (VS4VSOSumMonth.VSODYear = VS4VARAppCountY.VARSYear)) LEFT JOIN VS4TAR ON VS4VSOSumMonth.TSODTARNCode = VS4TAR.TARNCode) LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN (VS4TAR2 LEFT JOIN VS4TEmployee ON VS4TAR2.TAR2SaleCode = VS4TEmployee.TEmpCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode
GO

CREATE VIEW VS4VSODelivery
AS 
SELECT VS4TSO.*, VS4TSOMB.*, VS4TSODelivery.*, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TBranch.TBraName, VS4TAR.TARNName, VS4TARGroup.TARGName, VS4TSaleArea.TSAeName, VS4TAR2.TAR2SaleCode, VS4TEmployee.TEmpFullName, VS4TAR.TARNTSAeCode, VS4TAR.TARNTARGCode, VS4TProduct.TPdtName, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TAR2.TAR2TPrvCode, VS4TProvince.TPrvName, VS4TAR.TARNPhone, VS4TAR.TARNFax, VS4TAR.TARNCreditLimit, VS4TAR.TARNCreditDay, VS4TProduct.TPdtGroupReport
FROM ((((VS4TAR LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN ((VS4TAR2 LEFT JOIN VS4TEmployee ON VS4TAR2.TAR2SaleCode = VS4TEmployee.TEmpCode) LEFT JOIN VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) INNER JOIN ((VS4TSO LEFT JOIN VS4TProject ON VS4TSO.TSODTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TSO.TSODTBraCode = VS4TBranch.TBraCode) ON VS4TAR.TARNCode = VS4TSO.TSODTARNCode) INNER JOIN ((VS4TSOMB LEFT JOIN VS4TSODelivery ON (VS4TSOMB.TSOBLn = VS4TSODelivery.TMDSTSOBLn) AND (VS4TSOMB.TSOBTSODNo = VS4TSODelivery.TMDSTSOBTSODNo)) LEFT JOIN VS4TProduct ON VS4TSODelivery.TMDSProductCode = VS4TProduct.TPdtCode) ON VS4TSO.TSODNo = VS4TSOMB.TSOBTSODNo
GO

CREATE VIEW VS4VSOH
AS 
SELECT VS4TSO.*, VS4TProject.TPrjName, VS4TAR.TARNName2, VS4TCountry.TCouName, VS4TCountry.TCouName2, VS4TAR.TARNPhone, VS4TAR.TARNFax, VS4TProject.TPrjMode, VS4TARGroup.TARGName, VS4TAR.TARNName, VS4TAR.TARNTARGCode, VS4TAR.TARNTSAeCode, VS4TAR2.TAR2SaleCode, VS4TEmployee.TEmpFullName, VS4TSaleArea.TSAeName, VS4TBranch.TBraName, VS4TAR.TARNTBsTCode, VS4TBusinessType.TBstName, VS4TBusinessMajor.TBsMName, VS4TAR2.TAR2TPrvCode, VS4TProvince.TPrvName, VS4TAR.TARNTARSAlias, VS4TAR.TARNFirstOrderDate, VS4VSaleAROnHand.*, VS4TARBranch.TARDName
FROM VS4TCountry INNER JOIN (VS4TBusinessType RIGHT JOIN ((((VS4TAR LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN (((VS4TAR2 LEFT JOIN VS4TEmployee ON VS4TAR2.TAR2SaleCode = VS4TEmployee.TEmpCode) LEFT JOIN VS4TBusinessMajor ON VS4TAR2.TAR2TBSMCode = VS4TBusinessMajor.TBsMCode) LEFT JOIN VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) INNER JOIN ((((VS4TSO LEFT JOIN VS4TProject ON VS4TSO.TSODTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TSO.TSODTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4VSaleAROnHand ON VS4TSO.TSODTEmpCode = VS4VSaleAROnHand.VARHSaleCode) LEFT JOIN VS4TARBranch ON (VS4TSO.TSODTARNCode = VS4TARBranch.TARDTARNCode) AND (VS4TSO.TSODTARDCode = VS4TARBranch.TARDCode)) ON VS4TAR.TARNCode = VS4TSO.TSODTARNCode) ON VS4TBusinessType.TBsTCode = VS4TAR.TARNTBsTCode) ON VS4TCountry.TCouCode = VS4TAR.TARNTCouCode
GO

CREATE VIEW VS4VSOHistory
AS 
SELECT VS4TSO.TSODTARNCode, VS4TProduct.TPdtCode, VS4TProduct.TPdtName, Count(VS4TProduct.TPdtCode) AS VSPCCount
FROM VS4TSO INNER JOIN (VS4TProductSection RIGHT JOIN (VS4TSOMB LEFT JOIN VS4TProduct ON VS4TSOMB.TSOBTPOSCode = VS4TProduct.TPdtCode) ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode) ON VS4TSO.TSODNo = VS4TSOMB.TSOBTSODNo
GROUP BY VS4TSO.TSODTARNCode, VS4TProduct.TPdtCode, VS4TProduct.TPdtName
GO

CREATE VIEW VS4VSOImigration
AS 
SELECT VS4TSOImigration.*, VS4TAR.*, VS4TAR3.*, VS4TProductBook.*
FROM (((VS4TSOImigration INNER JOIN VS4TAR ON VS4TSOImigration.TIMGTARNCode = VS4TAR.TARNCode) LEFT JOIN VS4TSOPassenger ON (VS4TSOImigration.TIMGTSODNo = VS4TSOPassenger.TVSPTSODNo) AND (VS4TSOImigration.TIMGLn = VS4TSOPassenger.TVSPLn) AND (VS4TSOImigration.TIMGTPdtCode = VS4TSOPassenger.TVSPTPdtCode)) INNER JOIN VS4TAR3 ON VS4TAR.TARNCode = VS4TAR3.TAR3TARNCode) LEFT JOIN VS4TProductBook ON VS4TSOImigration.TIMGTPdtCode = VS4TProductBook.TPBGTPdtCode
GO

CREATE VIEW VS4VSOPassenger
AS 
SELECT VS4TSOPassenger.*, VS4TAR3.*, VS4TAR.TARNName, VS4TAR.TARNName2, VS4TSOImigration.*, VS4TProductBook.*, VS4TProduct.TPdtName, VS4TAR.TARNTARTCode, VS4TPlace.TPlaName, VS4TProductPlace.TPAPLn, VS4TProductPlace.TPAPType, VS4TProduct.TPdtStartDate, VS4TProduct.TPdtEndDate, VS4TAR_1.TARNName AS VVSPFirstName2, VS4TAR_1.TARNName2 AS VVSPLastName2, VS4TAR3_1.TAR3CitizenNo AS VVSPCitizenNo, VS4TAR3_1.TAR3BirthDay AS VVSPBirthDay, VS4TPlace.TPlaPhone, VS4TPlace.TPlaFax, VS4TPlace.TPlaEmail, VS4TAR.TARNMobile, Right(10000+(Month(VS4TAR3.tar3birthday)*100)+Day(VS4TAR3.tar3birthday),4) AS VVSPBirthDayMonth
FROM (((((((VS4TSOPassenger LEFT JOIN VS4TAR3 ON VS4TSOPassenger.TVSPTARNCode = VS4TAR3.TAR3TARNCode) LEFT JOIN VS4TSO ON VS4TSOPassenger.TVSPTSODNo = VS4TSO.TSODNo) LEFT JOIN VS4TAR AS VS4TAR_1 ON VS4TSOPassenger.TVSPRelateTARNCode = VS4TAR_1.TARNCode) LEFT JOIN VS4TAR3 AS VS4TAR3_1 ON VS4TAR_1.TARNCode = VS4TAR3_1.TAR3TARNCode) LEFT JOIN VS4TAR ON VS4TAR3.TAR3TARNCode = VS4TAR.TARNCode) LEFT JOIN (VS4TProductPlace LEFT JOIN VS4TPlace ON VS4TProductPlace.TPAPTPlaID = VS4TPlace.TPlaID) ON (VS4TSOPassenger.TVSPHotelNo = VS4TProductPlace.TPAPLn) AND (VS4TSOPassenger.TVSPTPdtCode = VS4TProductPlace.TPAPTPdtCode)) LEFT JOIN VS4TSOImigration ON (VS4TSOPassenger.TVSPTSODNo = VS4TSOImigration.TIMGTSODNo) AND (VS4TSOPassenger.TVSPLn = VS4TSOImigration.TIMGLn) AND (VS4TSOPassenger.TVSPTPdtCode = VS4TSOImigration.TIMGTPdtCode)) LEFT JOIN (VS4TProductBook LEFT JOIN VS4TProduct ON VS4TProductBook.TPBGTPdtCode = VS4TProduct.TPdtCode) ON VS4TSOPassenger.TVSPTPdtCode = VS4TProductBook.TPBGTPdtCode
WHERE (((VS4TProductPlace.TPAPLn)=1 Or (VS4TProductPlace.TPAPLn) Is Null))
GO

CREATE VIEW VS4VSOPassHistory
AS 
SELECT VS4TSOPassenger.TVSPTARNCode, VS4TProduct.TPdtCode, VS4TProduct.TPdtName, Count(VS4TProduct.TPdtCode) AS VSPCCount
FROM (VS4TSO INNER JOIN VS4TSOPassenger ON VS4TSO.TSODNo = VS4TSOPassenger.TVSPTSODNo) INNER JOIN (VS4TProductSection RIGHT JOIN (VS4TSOMB LEFT JOIN VS4TProduct ON VS4TSOMB.TSOBTPOSCode = VS4TProduct.TPdtCode) ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode) ON VS4TSO.TSODNo = VS4TSOMB.TSOBTSODNo
GROUP BY VS4TSOPassenger.TVSPTARNCode, VS4TProduct.TPdtCode, VS4TProduct.TPdtName
GO

CREATE VIEW VS4VSOAppointment
AS 
SELECT VS4VARAppCount.*, VS4TAR.*, VS4TAR2.*, VS4TSaleArea.*, VS4TSaleZone.*, VS4TEmployee.TEmpCode, VS4TEmployee.TEmpFullName, VS4TARGroup.TARGName, VS4TBusinessType.TBstName, VS4VSOSumDay.*, VS4TEmployee.TEmpAliasName
FROM VS4TSaleZone RIGHT JOIN (VS4TBusinessType RIGHT JOIN (((((VS4TAR LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) LEFT JOIN VS4VARAppCount ON VS4TAR.TARNCode = VS4VARAppCount.TARATARNCode) LEFT JOIN VS4VSOSumDay ON (VS4VARAppCount.TARATARNCode = VS4VSOSumDay.TSODTARNCode) AND (VS4VARAppCount.VARDDay = VS4VSOSumDay.VSSDDay) AND (VS4VARAppCount.VARDMonth = VS4VSOSumDay.VSSDMonth) AND (VS4VARAppCount.VARDYear = VS4VSOSumDay.VSSDYear)) LEFT JOIN (VS4TAR2 LEFT JOIN VS4TEmployee ON VS4TAR2.TAR2SaleCode = VS4TEmployee.TEmpCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) ON VS4TBusinessType.TBsTCode = VS4TAR.TARNTBsTCode) ON VS4TSaleZone.TSZnCode = VS4TSaleArea.TSaeTSZnCode
GO

CREATE VIEW VS4VSOSumDayAll
AS 
SELECT VS4TSO.TSODDate, Sum(VS4TSO.TSODTaxBase) AS TSODTaxBase, Count(VS4TSO.TSODNo) AS VSDACount
FROM VS4TSO
GROUP BY VS4TSO.TSODDate, VS4TSO.TSODApproveStatus, VS4TSO.TSODCancelStatus
HAVING (((VS4TSO.TSODApproveStatus)=1) AND ((VS4TSO.TSODCancelStatus)=0))
GO

CREATE VIEW VS4VSOAppointmentD
AS 
SELECT VS4VSOAppointmentM.*, VS4VSOSumMonth.*
FROM VS4VSOSumMonth, VS4VSOAppointmentM
GO

CREATE VIEW VS4VSSO
AS 
SELECT VS4VExportSlipGov.*
FROM VS4VExportSlipGov
WHERE (((VS4VExportSlipGov.TEpsSTAXBase)>0) AND ((VS4VExportSlipGov.TEm2SkipTax)<>1) AND ((VS4VExportSlipGov.TEpsSTAX)>0))
GO

CREATE VIEW VS4VSSODetail
AS 
SELECT VS4VExportSlipGov.*
FROM VS4VExportSlipGov
WHERE (((VS4VExportSlipGov.TEm2SkipTax)<>1) AND ((VS4VExportSlipGov.TEpsSTAXBase)>0))
GO

CREATE VIEW VS4VJobMatStock
AS 
SELECT VS4TJob.*, VS4TJobMB.*, VS4TJobMaterial.*, VS4TProduct.TPdtImage1, VS4TJobBook.TJBkName, VS4TProduct_1.TPdtStandardCost AS VPdtStandardCost, VS4TProduct.TPdtStandardCost, VS4TProductSection.TPSECode, VS4TProductSection.TPSEName, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct_1.TPdtName AS VJmtName, VS4TProduct_1.TPdtName2 AS VJmtName2, VS4TJobMethod.TJStStartDate, VS4TJobMethod.TJStEndDate, VS4TMRPStepName.TSepCode, VS4TMRPStepName.TSepName, VS4TMRPStepName.TSepTSecCode, VS4VStock.TInMAmouQuantity, VS4VStock.TInMAmouQuantity2, VS4VStock.TInMAmouQuantity3, VS4TMRPStepName.TSepTLctCode
FROM VS4TProductSection RIGHT JOIN ((VS4TJobBook RIGHT JOIN VS4TJob ON VS4TJobBook.TJBkCode = VS4TJob.TJobTJBkCode) INNER JOIN ((VS4TJobMB LEFT JOIN VS4TProduct ON VS4TJobMB.TJbMTPdtCode = VS4TProduct.TPdtCode) INNER JOIN ((((VS4TJobMaterial LEFT JOIN VS4TProduct AS VS4TProduct_1 ON VS4TJobMaterial.TJMtProductCode = VS4TProduct_1.TPdtCode) LEFT JOIN VS4TJobMethod ON (VS4TJobMaterial.TJMtTJbMTJobNo = VS4TJobMethod.TJStTJbMTJobNo) AND (VS4TJobMaterial.TJMtTJbMLn = VS4TJobMethod.TJStTJbMLn) AND (VS4TJobMaterial.TJMtTSpdStep = VS4TJobMethod.TJStTSpdStep) AND (VS4TJobMaterial.TJMtLevel = VS4TJobMethod.TJStLevel)) LEFT JOIN VS4TMRPStepName ON VS4TJobMethod.TJStTSepCode = VS4TMRPStepName.TSepCode) LEFT JOIN VS4VStock ON VS4TProduct_1.TPdtCode = VS4VStock.TPdtCode) ON (VS4TJobMB.TJbMLn = VS4TJobMaterial.TJMtTJbMLn) AND (VS4TJobMB.TJbMTJobNo = VS4TJobMaterial.TJMtTJbMTJobNo)) ON VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo) ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode
GO

CREATE VIEW VS4VStockBase
AS 
SELECT Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtTPTTCode, Vs4VInventStock.TPdtTPPuCode, Vs4VInventStock.TPdtFlag1, Sum(Vs4VInventStock.TInMAmount) AS TInMAmount, Avg(Vs4VInventStock.TIMCUnitCost) AS TIMCUnitCost, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, Vs4VInventStock.TPdtTPG4Code, Vs4VInventStock.TPdtTPCTAlias, Sum(Vs4VInventStock.TInMQuantityBase) AS TInMQuantityBase, Vs4VInventStock.TInMTUntCode, Vs4VInventStock.TInMUnitRatio, Vs4VInventStock.TPdtTUntCode, Vs4VInventStock.TPdtTUntCode2, Vs4VInventStock.TPdtTUntCode3, Sum(Vs4VInventStock.TInMAmouQuantity) AS TInMAmouQuantity, Sum(Vs4VInventStock.TInMAmouQuantity2) AS TInMAmouQuantity2, Sum(Vs4VInventStock.TInMAmouQuantity3) AS TInMAmouQuantity3, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TIMCUnitCalc, Sum(Vs4VInventStock.TInMQuantityCalc) AS TInMQuantityCalc, Vs4VInventStock.TPdtOrderPoint, Vs4VInventStock.TPdtTAPNCode, Vs4VInventStock.TPdtFactoryCode, Vs4VInventStock.TPOSPackAlias2
FROM Vs4VInventStock
GROUP BY Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtTPTTCode, Vs4VInventStock.TPdtTPPuCode, Vs4VInventStock.TPdtFlag1, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, Vs4VInventStock.TPdtTPG4Code, Vs4VInventStock.TPdtTPCTAlias, Vs4VInventStock.TInMTUntCode, Vs4VInventStock.TInMUnitRatio, Vs4VInventStock.TPdtTUntCode, Vs4VInventStock.TPdtTUntCode2, Vs4VInventStock.TPdtTUntCode3, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TIMCUnitCalc, Vs4VInventStock.TPdtOrderPoint, Vs4VInventStock.TPdtTAPNCode, Vs4VInventStock.TPdtFactoryCode, Vs4VInventStock.TPOSPackAlias2
GO

CREATE VIEW VS4VStockBaseWH
AS 
SELECT Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtTPTTCode, Vs4VInventStock.TPdtTPPuCode, Vs4VInventStock.TPdtFlag1, Sum(Vs4VInventStock.TInMAmount) AS TInMAmount, Avg(Vs4VInventStock.TIMCUnitCost) AS TIMCUnitCost, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, Vs4VInventStock.TPdtTPG4Code, Vs4VInventStock.TPdtTPCTAlias, Sum(Vs4VInventStock.TInMQuantityBase) AS TInMQuantityBase, Vs4VInventStock.TInMTUntCode, Vs4VInventStock.TInMUnitRatio, Vs4VInventStock.TPdtTUntCode, Vs4VInventStock.TPdtTUntCode2, Vs4VInventStock.TPdtTUntCode3, Sum(Vs4VInventStock.TInMAmouQuantity) AS TInMAmouQuantity, Sum(Vs4VInventStock.TInMAmouQuantity2) AS TInMAmouQuantity2, Sum(Vs4VInventStock.TInMAmouQuantity3) AS TInMAmouQuantity3, Vs4VInventStock.TLctDayAlert, Vs4VInventStock.TLctDayMove, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TIMCUnitCalc, Sum(Vs4VInventStock.TInMQuantityCalc) AS TInMQuantityCalc, Vs4VInventStock.TWahCode, Vs4VInventStock.TInMTLctCode, Vs4VInventStock.TPdtOrderPoint, Vs4VInventStock.TPdtTAPNCode, Vs4VInventStock.TPdtFactoryCode, Vs4VInventStock.TLctTBraCode, Vs4VInventStock.TPOSPackAlias2
FROM Vs4VInventStock
GROUP BY Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtTPTTCode, Vs4VInventStock.TPdtTPPuCode, Vs4VInventStock.TPdtFlag1, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, Vs4VInventStock.TPdtTPG4Code, Vs4VInventStock.TPdtTPCTAlias, Vs4VInventStock.TInMTUntCode, Vs4VInventStock.TInMUnitRatio, Vs4VInventStock.TPdtTUntCode, Vs4VInventStock.TPdtTUntCode2, Vs4VInventStock.TPdtTUntCode3, Vs4VInventStock.TLctDayAlert, Vs4VInventStock.TLctDayMove, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TIMCUnitCalc, Vs4VInventStock.TWahCode, Vs4VInventStock.TInMTLctCode, Vs4VInventStock.TPdtOrderPoint, Vs4VInventStock.TPdtTAPNCode, Vs4VInventStock.TPdtFactoryCode, Vs4VInventStock.TLctTBraCode, Vs4VInventStock.TPOSPackAlias2
GO

CREATE VIEW VS4VProductSafeS
AS 
SELECT VS4VStockBranch.TInMAmouQuantity, VS4VStockBranch.TInMAmouQuantity2, VS4VStockBranch.TInMAmouQuantity3, VS4TBranch.TBraTBrTAlias, VS4VProductBrief.*, VS4TProductSafeS.*
FROM ((VS4TProductSafeS LEFT JOIN VS4VStockBranch ON (VS4TProductSafeS.TPSSTBraCode = VS4VStockBranch.TLctTBraCode) AND (VS4TProductSafeS.TPSSTPdtCode = VS4VStockBranch.TPdtCode)) LEFT JOIN VS4TBranch ON VS4TProductSafeS.TPSSTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4VProductBrief ON VS4TProductSafeS.TPSSTPdtCode = VS4VProductBrief.TPdtCode
GO

CREATE VIEW VS4VStockBranchF
AS 
SELECT Vs4VInventStockF.TPdtCode, Vs4VInventStockF.TPdtBarcode, Vs4VInventStockF.TPdtName, Vs4VInventStockF.TPdtTPTTCode, Vs4VInventStockF.TPdtTPPuCode, Vs4VInventStockF.TPdtFlag1, Sum(Vs4VInventStockF.TInMInQuantity) AS TInMInQuantity, Sum(Vs4VInventStockF.TInMOutQuantity) AS TInMOutQuantity, Sum(Vs4VInventStockF.TInMAmouQuantity) AS TInMAmouQuantity, Vs4VInventStockF.TPdtTUntCode, Sum(Vs4VInventStockF.TInMInQuantity2) AS TInMInQuantity2, Sum(Vs4VInventStockF.TInMOutQuantity2) AS TInMOutQuantity2, Sum(Vs4VInventStockF.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStockF.TPdtTUntCode2, Sum(Vs4VInventStockF.TInMInQuantity3) AS TInMInQuantity3, Sum(Vs4VInventStockF.TInMOutQuantity3) AS TInMOutQuantity3, Sum(Vs4VInventStockF.TInMAmouQuantity3) AS TInMAmouQuantity3, Vs4VInventStockF.TPdtTUntCode3, Sum(Vs4VInventStockF.TInMAmount) AS TInMAmount, Avg(Vs4VInventStockF.TIMCUnitCost) AS TIMCUnitCost, Vs4VInventStockF.TPdtTPDLCode, Vs4VInventStockF.TPdtTPSECode, Vs4VInventStockF.TPdtTPS2Code, Vs4VInventStockF.TPdtTPS3Code, Vs4VInventStockF.TPdtTPS4Code, Vs4VInventStockF.TPdtTPG1Code, Vs4VInventStockF.TPdtTPG2Code, Vs4VInventStockF.TPdtTPG3Code, Vs4VInventStockF.TPdtTPG4Code, Vs4VInventStockF.TPdtTPCTAlias, Vs4VInventStockF.TPOSPrice, Vs4VInventStockF.TPdtSlowDay, Vs4VInventStockF.TPdtDeadDay, Vs4VInventStockF.TPdtSerialType, Vs4VInventStockF.TIMCUnitCalc, Sum(Vs4VInventStockF.TInMQuantityCalc) AS TInMQuantityCalc, Vs4VInventStockF.TPdtOrderPoint, Vs4VInventStockF.TPdtTAPNCode, Vs4VInventStockF.TLctTBraCode, Vs4VInventStockF.TPdtFactoryCode, VS4TProductSafeS.TPSSRefill, VS4TProductSafeS.TPSSSafePerDay, VS4TProductSafeS.TPSSSafeTotalDay, VS4TProductSafeS.TPSSStockMin, VS4TProductSafeS.TPSSSuggest, Vs4VInventStockF.TPOSPackAlias2
FROM Vs4VInventStockF LEFT JOIN VS4TProductSafeS ON (Vs4VInventStockF.TLctTBraCode = VS4TProductSafeS.TPSSTBraCode) AND (Vs4VInventStockF.TInMTPdtCode = VS4TProductSafeS.TPSSTPdtCode)
GROUP BY Vs4VInventStockF.TPdtCode, Vs4VInventStockF.TPdtBarcode, Vs4VInventStockF.TPdtName, Vs4VInventStockF.TPdtTPTTCode, Vs4VInventStockF.TPdtTPPuCode, Vs4VInventStockF.TPdtFlag1, Vs4VInventStockF.TPdtTUntCode, Vs4VInventStockF.TPdtTUntCode2, Vs4VInventStockF.TPdtTUntCode3, Vs4VInventStockF.TPdtTPDLCode, Vs4VInventStockF.TPdtTPSECode, Vs4VInventStockF.TPdtTPS2Code, Vs4VInventStockF.TPdtTPS3Code, Vs4VInventStockF.TPdtTPS4Code, Vs4VInventStockF.TPdtTPG1Code, Vs4VInventStockF.TPdtTPG2Code, Vs4VInventStockF.TPdtTPG3Code, Vs4VInventStockF.TPdtTPG4Code, Vs4VInventStockF.TPdtTPCTAlias, Vs4VInventStockF.TPOSPrice, Vs4VInventStockF.TPdtSlowDay, Vs4VInventStockF.TPdtDeadDay, Vs4VInventStockF.TPdtSerialType, Vs4VInventStockF.TIMCUnitCalc, Vs4VInventStockF.TPdtOrderPoint, Vs4VInventStockF.TPdtTAPNCode, Vs4VInventStockF.TLctTBraCode, Vs4VInventStockF.TPdtFactoryCode, VS4TProductSafeS.TPSSRefill, VS4TProductSafeS.TPSSSafePerDay, VS4TProductSafeS.TPSSSafeTotalDay, VS4TProductSafeS.TPSSStockMin, VS4TProductSafeS.TPSSSuggest, Vs4VInventStockF.TPOSPackAlias2
GO

CREATE VIEW VS4VStockBranchFS
AS 
SELECT VS4VStockBranchF.*, TInMAmouQuantity-TPSSRefill AS VSTFOverStock
FROM VS4VStockBranchF
GO

CREATE VIEW VS4VStockBranchS
AS 
SELECT VS4VStockBranch.*, TInMAmouQuantity-TPSSRefill AS VSTBOverStock
FROM VS4VStockBranch
GO

CREATE VIEW VS4VStockDL
AS 
SELECT Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtTPTTCode, Vs4VInventStock.TPdtTPPuCode, Vs4VInventStock.TPdtFlag1, Sum(Vs4VInventStock.TInMInQuantity) AS TInMInQuantity, Sum(Vs4VInventStock.TInMOutQuantity) AS TInMOutQuantity, Sum(Vs4VInventStock.TInMAmouQuantity) AS TInMAmouQuantity, Vs4VInventStock.TPdtTUntCode, Sum(Vs4VInventStock.TInMInQuantity2) AS TInMInQuantity2, Sum(Vs4VInventStock.TInMOutQuantity2) AS TInMOutQuantity2, Sum(Vs4VInventStock.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, Sum(Vs4VInventStock.TInMInQuantity3) AS TInMInQuantity3, Sum(Vs4VInventStock.TInMOutQuantity3) AS TInMOutQuantity3, Sum(Vs4VInventStock.TInMAmouQuantity3) AS TInMAmouQuantity3, Vs4VInventStock.TPdtTUntCode3, Sum(Vs4VInventStock.TInMAmount) AS TInMAmount, Avg(Vs4VInventStock.TIMCUnitCost) AS TIMCUnitCost, Vs4VInventStock.TInMLotNo, Vs4VInventStock.TInMLotDate, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, Vs4VInventStock.TPdtTPG4Code, Vs4VInventStock.TPdtTPCTAlias, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TIMCUnitCalc, Sum(Vs4VInventStock.TInMQuantityCalc) AS TInMQuantityCalc, Vs4VInventStock.TPdtOrderPoint, Vs4VInventStock.TPdtTAPNCode, Vs4VInventStock.TPdtFactoryCode, Vs4VInventStock.TPOSPackAlias2
FROM Vs4VInventStock
GROUP BY Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtTPTTCode, Vs4VInventStock.TPdtTPPuCode, Vs4VInventStock.TPdtFlag1, Vs4VInventStock.TPdtTUntCode, Vs4VInventStock.TPdtTUntCode2, Vs4VInventStock.TPdtTUntCode3, Vs4VInventStock.TInMLotNo, Vs4VInventStock.TInMLotDate, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, Vs4VInventStock.TPdtTPG4Code, Vs4VInventStock.TPdtTPCTAlias, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TIMCUnitCalc, Vs4VInventStock.TPdtOrderPoint, Vs4VInventStock.TPdtTAPNCode, Vs4VInventStock.TPdtFactoryCode, Vs4VInventStock.TPOSPackAlias2
GO

CREATE VIEW VS4VStockFULL
AS 
SELECT Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtTPTTCode, Vs4VInventStock.TPdtTPPuCode, Vs4VInventStock.TPdtFlag1, Sum(Vs4VInventStock.TInMInQuantity) AS TInMInQuantity, Sum(Vs4VInventStock.TInMOutQuantity) AS TInMOutQuantity, Sum(Vs4VInventStock.TInMAmouQuantity) AS TInMAmouQuantity, Vs4VInventStock.TPdtTUntCode, Sum(Vs4VInventStock.TInMInQuantity2) AS TInMInQuantity2, Sum(Vs4VInventStock.TInMOutQuantity2) AS TInMOutQuantity2, Sum(Vs4VInventStock.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, Sum(Vs4VInventStock.TInMInQuantity3) AS TInMInQuantity3, Sum(Vs4VInventStock.TInMOutQuantity3) AS TInMOutQuantity3, Sum(Vs4VInventStock.TInMAmouQuantity3) AS TInMAmouQuantity3, Vs4VInventStock.TPdtTUntCode3, Sum(Vs4VInventStock.TInMAmount) AS TInMAmount, Vs4VInventStock.TIMCUnitCost AS TIMCUnitCost, Vs4VInventStock.TWahCode, Vs4VInventStock.TWahName, Vs4VInventStock.TInMTLctCode, Vs4VInventStock.TLctName, Vs4VInventStock.TInMLotNo, Vs4VInventStock.TInMLotDate, Vs4VInventStock.TIMCCustom4, Vs4VInventStock.TIMCCustom5, Vs4VInventStock.TIMCGrade, Vs4VInventStock.TInMSerialNo, Vs4VInventStock.TIMCTCgTID, Vs4VInventStock.TIMCNoExpire, Vs4VInventStock.TIMCExpireDate, Vs4VInventStock.TIMCLotNo2, Vs4VInventStock.TIMCJobCode, Vs4VInventStock.TInMCustom1, Vs4VInventStock.TIMCCustom2, Vs4VInventStock.TIMCCustom3, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, Vs4VInventStock.TPdtTPG4Code, Vs4VInventStock.TPdtTPCTAlias, Vs4VInventStock.TInMScrapLevel, Vs4VInventStock.TIMCReserve, Sum(Vs4VInventStock.TInMQuantityBase) AS TInMQuantityBase, Vs4VInventStock.TIMCIsPremium, Vs4VInventStock.TIMCPremiumNote, Vs4VInventStock.TLctDayAlert, Vs4VInventStock.TLctDayMove, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TIMCUnitCalc, Sum(Vs4VInventStock.TInMQuantityCalc) AS TInMQuantityCalc, Vs4VInventStock.TPdtOrderPoint, Vs4VInventStock.TIMCInputCost, Max(Vs4VInventStock.TIMCLastUnitCost) AS TIMCLastUnitCost, Vs4VInventStock.TIMCPerQuantity, Vs4VInventStock.TLctTBraCode, Vs4VInventStock.TPdtTAPNCode, Vs4VInventStock.TPdtFactoryCode, Vs4VInventStock.TIMCCostCode, Vs4VInventStock.TPOSPrice, Vs4VInventStock.TIMCReceiveNo, Vs4VInventStock.TIMCReceiveLn, Vs4VInventStock.TIMCQAStatus, Vs4VInventStock.TIMCQANote, Vs4VInventStock.TIMCTAPNCode, Vs4VInventStock.TIMCInvoiceNo, Vs4VInventStock.TIMCInvoiceDate, Vs4VInventStock.TIMCUnitRatio, Vs4VInventStock.TIMCTUntCode, Vs4VInventStock.TPOSPackAlias2, Vs4VInventStock.TInMTPltCode, Vs4VInventStock.TPdtName2, Vs4VInventStock.TPdtDescription
FROM Vs4VInventStock
GROUP BY Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtTPTTCode, Vs4VInventStock.TPdtTPPuCode, Vs4VInventStock.TPdtFlag1, Vs4VInventStock.TPdtTUntCode, Vs4VInventStock.TPdtTUntCode2, Vs4VInventStock.TPdtTUntCode3, Vs4VInventStock.TIMCUnitCost, Vs4VInventStock.TWahCode, Vs4VInventStock.TWahName, Vs4VInventStock.TInMTLctCode, Vs4VInventStock.TLctName, Vs4VInventStock.TInMLotNo, Vs4VInventStock.TInMLotDate, Vs4VInventStock.TIMCCustom4, Vs4VInventStock.TIMCCustom5, Vs4VInventStock.TIMCGrade, Vs4VInventStock.TInMSerialNo, Vs4VInventStock.TIMCTCgTID, Vs4VInventStock.TIMCNoExpire, Vs4VInventStock.TIMCExpireDate, Vs4VInventStock.TIMCLotNo2, Vs4VInventStock.TIMCJobCode, Vs4VInventStock.TInMCustom1, Vs4VInventStock.TIMCCustom2, Vs4VInventStock.TIMCCustom3, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, Vs4VInventStock.TPdtTPG4Code, Vs4VInventStock.TPdtTPCTAlias, Vs4VInventStock.TInMScrapLevel, Vs4VInventStock.TIMCReserve, Vs4VInventStock.TIMCIsPremium, Vs4VInventStock.TIMCPremiumNote, Vs4VInventStock.TLctDayAlert, Vs4VInventStock.TLctDayMove, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TIMCUnitCalc, Vs4VInventStock.TPdtOrderPoint, Vs4VInventStock.TIMCInputCost, Vs4VInventStock.TIMCPerQuantity, Vs4VInventStock.TLctTBraCode, Vs4VInventStock.TPdtTAPNCode, Vs4VInventStock.TPdtFactoryCode, Vs4VInventStock.TIMCCostCode, Vs4VInventStock.TPOSPrice, Vs4VInventStock.TIMCReceiveNo, Vs4VInventStock.TIMCReceiveLn, Vs4VInventStock.TIMCQAStatus, Vs4VInventStock.TIMCQANote, Vs4VInventStock.TIMCTAPNCode, Vs4VInventStock.TIMCInvoiceNo, Vs4VInventStock.TIMCInvoiceDate, Vs4VInventStock.TIMCUnitRatio, Vs4VInventStock.TIMCTUntCode, Vs4VInventStock.TPOSPackAlias2, Vs4VInventStock.TInMTPltCode, Vs4VInventStock.TPdtName2, Vs4VInventStock.TPdtDescription
GO

CREATE VIEW VS4VStockFullByJob
AS 
SELECT VS4VStockFULL.*, VS4TJobMaterial.*
FROM VS4VStockFULL INNER JOIN VS4TJobMaterial ON VS4VStockFULL.TPdtCode = VS4TJobMaterial.TJMtProductCode
GO

CREATE VIEW VS4VStockFULLD
AS 
SELECT VS4VInventStockP.TPdtCode, VS4VInventStockP.TPdtBarcode, VS4VInventStockP.TPdtName, VS4VInventStockP.TPdtTPTTCode, VS4VInventStockP.TPdtTPPuCode, VS4VInventStockP.TPdtFlag1, Sum(VS4VInventStockP.TInMInQuantity) AS TInMInQuantity, Sum(VS4VInventStockP.TInMOutQuantity) AS TInMOutQuantity, Sum(VS4VInventStockP.TInMAmouQuantity) AS TInMAmouQuantity, VS4VInventStockP.TPdtTUntCode, Sum(VS4VInventStockP.TInMInQuantity2) AS TInMInQuantity2, Sum(VS4VInventStockP.TInMOutQuantity2) AS TInMOutQuantity2, Sum(VS4VInventStockP.TInMAmouQuantity2) AS TInMAmouQuantity2, VS4VInventStockP.TPdtTUntCode2, Sum(VS4VInventStockP.TInMInQuantity3) AS TInMInQuantity3, Sum(VS4VInventStockP.TInMOutQuantity3) AS TInMOutQuantity3, Sum(VS4VInventStockP.TInMAmouQuantity3) AS TInMAmouQuantity3, VS4VInventStockP.TPdtTUntCode3, Sum(VS4VInventStockP.TInMAmount) AS TInMAmount, VS4VInventStockP.TIMCUnitCost AS TIMCUnitCost, VS4VInventStockP.TWahCode, VS4VInventStockP.TWahName, VS4VInventStockP.TInMTLctCode, VS4VInventStockP.TLctName, VS4VInventStockP.TInMLotNo, VS4VInventStockP.TInMLotDate, VS4VInventStockP.TIMCCustom4, VS4VInventStockP.TIMCCustom5, VS4VInventStockP.TIMCGrade, VS4VInventStockP.TInMSerialNo, VS4VInventStockP.TIMCTCgTID, VS4VInventStockP.TIMCNoExpire, VS4VInventStockP.TIMCExpireDate, VS4VInventStockP.TIMCLotNo2, VS4VInventStockP.TIMCJobCode, VS4VInventStockP.TInMCustom1, VS4VInventStockP.TIMCCustom2, VS4VInventStockP.TIMCCustom3, VS4VInventStockP.TPdtTPDLCode, VS4VInventStockP.TPdtTPSECode, VS4VInventStockP.TPdtTPS2Code, VS4VInventStockP.TPdtTPS3Code, VS4VInventStockP.TPdtTPS4Code, VS4VInventStockP.TPdtTPG1Code, VS4VInventStockP.TPdtTPG2Code, VS4VInventStockP.TPdtTPG3Code, VS4VInventStockP.TPdtTPG4Code, VS4VInventStockP.TPdtTPCTAlias, VS4VInventStockP.TInMScrapLevel, VS4VInventStockP.TIMCReserve, Sum(VS4VInventStockP.TInMQuantityBase) AS TInMQuantityBase, VS4VInventStockP.TDivName, VS4VInventStockP.TDepName, VS4VInventStockP.TSecName, VS4VInventStockP.TPTTName, VS4VInventStockP.TPdLName, VS4VInventStockP.TPSEName, VS4VInventStockP.TPS2Name, VS4VInventStockP.TPS3Name, VS4VInventStockP.TPS4Name, VS4VInventStockP.TPG1Name, VS4VInventStockP.TPG2Name, VS4VInventStockP.TPG3Name, VS4VInventStockP.TPG4Name, VS4VInventStockP.TInvTBraCode, VS4VInventStockP.TInvTDivCode, VS4VInventStockP.TInvTDepCode, VS4VInventStockP.TInvTSecCode, VS4VInventStockP.TIMCIsPremium, VS4VInventStockP.TInMStatus, VS4VInventStockP.TIMCUnitCalc, Sum(VS4VInventStockP.TInMQuantityCalc) AS TInMQuantityCalc, VS4VInventStockP.TLctDayAlert, VS4VInventStockP.TLctDayMove, VS4VInventStockP.TPdtOrderPoint, VS4VInventStockP.TPdtSlowDay, VS4VInventStockP.TPdtDeadDay, VS4VInventStockP.TPdtSerialType, VS4VInventStockP.TIMCInputCost, Max(VS4VInventStockP.TIMCLastUnitCost) AS TIMCLastUnitCost, VS4VInventStockP.TPdtTAPNCode, VS4VInventStockP.TPdtFactoryCode, VS4VInventStockP.TInvDate, VS4VInventStockP.TBraName, VS4VInventStockP.TIMCReceiveLn, VS4VInventStockP.TIMCQAStatus, VS4VInventStockP.TIMCQANote, VS4VInventStockP.TIMCTAPNCode, VS4VInventStockP.TIMCInvoiceNo, VS4VInventStockP.TIMCInvoiceDate, VS4VInventStockP.TIMCUnitRatio, VS4VInventStockP.TIMCTUntCode, VS4VInventStockP.TPOSPackAlias2, VS4VInventStockP.TInMTPltCode
FROM VS4VInventStockP
GROUP BY VS4VInventStockP.TPdtCode, VS4VInventStockP.TPdtBarcode, VS4VInventStockP.TPdtName, VS4VInventStockP.TPdtTPTTCode, VS4VInventStockP.TPdtTPPuCode, VS4VInventStockP.TPdtFlag1, VS4VInventStockP.TPdtTUntCode, VS4VInventStockP.TPdtTUntCode2, VS4VInventStockP.TPdtTUntCode3, VS4VInventStockP.TIMCUnitCost, VS4VInventStockP.TWahCode, VS4VInventStockP.TWahName, VS4VInventStockP.TInMTLctCode, VS4VInventStockP.TLctName, VS4VInventStockP.TInMLotNo, VS4VInventStockP.TInMLotDate, VS4VInventStockP.TIMCCustom4, VS4VInventStockP.TIMCCustom5, VS4VInventStockP.TIMCGrade, VS4VInventStockP.TInMSerialNo, VS4VInventStockP.TIMCTCgTID, VS4VInventStockP.TIMCNoExpire, VS4VInventStockP.TIMCExpireDate, VS4VInventStockP.TIMCLotNo2, VS4VInventStockP.TIMCJobCode, VS4VInventStockP.TInMCustom1, VS4VInventStockP.TIMCCustom2, VS4VInventStockP.TIMCCustom3, VS4VInventStockP.TPdtTPDLCode, VS4VInventStockP.TPdtTPSECode, VS4VInventStockP.TPdtTPS2Code, VS4VInventStockP.TPdtTPS3Code, VS4VInventStockP.TPdtTPS4Code, VS4VInventStockP.TPdtTPG1Code, VS4VInventStockP.TPdtTPG2Code, VS4VInventStockP.TPdtTPG3Code, VS4VInventStockP.TPdtTPG4Code, VS4VInventStockP.TPdtTPCTAlias, VS4VInventStockP.TInMScrapLevel, VS4VInventStockP.TIMCReserve, VS4VInventStockP.TDivName, VS4VInventStockP.TDepName, VS4VInventStockP.TSecName, VS4VInventStockP.TPTTName, VS4VInventStockP.TPdLName, VS4VInventStockP.TPSEName, VS4VInventStockP.TPS2Name, VS4VInventStockP.TPS3Name, VS4VInventStockP.TPS4Name, VS4VInventStockP.TPG1Name, VS4VInventStockP.TPG2Name, VS4VInventStockP.TPG3Name, VS4VInventStockP.TPG4Name, VS4VInventStockP.TInvTBraCode, VS4VInventStockP.TInvTDivCode, VS4VInventStockP.TInvTDepCode, VS4VInventStockP.TInvTSecCode, VS4VInventStockP.TIMCIsPremium, VS4VInventStockP.TInMStatus, VS4VInventStockP.TIMCUnitCalc, VS4VInventStockP.TLctDayAlert, VS4VInventStockP.TLctDayMove, VS4VInventStockP.TPdtOrderPoint, VS4VInventStockP.TPdtSlowDay, VS4VInventStockP.TPdtDeadDay, VS4VInventStockP.TPdtSerialType, VS4VInventStockP.TIMCInputCost, VS4VInventStockP.TPdtTAPNCode, VS4VInventStockP.TPdtFactoryCode, VS4VInventStockP.TInvDate, VS4VInventStockP.TBraName, VS4VInventStockP.TIMCReceiveLn, VS4VInventStockP.TIMCQAStatus, VS4VInventStockP.TIMCQANote, VS4VInventStockP.TIMCTAPNCode, VS4VInventStockP.TIMCInvoiceNo, VS4VInventStockP.TIMCInvoiceDate, VS4VInventStockP.TIMCUnitRatio, VS4VInventStockP.TIMCTUntCode, VS4VInventStockP.TPOSPackAlias2, VS4VInventStockP.TInMTPltCode
HAVING (((VS4VInventStockP.TInMStatus)=1))
GO

CREATE VIEW VS4VStockFullDraw
AS 
SELECT VS4VStockFULL.*, VS4TInventory.TInvTJobNo, VS4TInventory.TInvTJbMLn, VS4TInventory.TInvTJPdNo, VS4TInventory.TInvTJPMLn, VS4TInventory.TInvTSecCode
FROM VS4VStockFULL INNER JOIN (VS4TInventory INNER JOIN VS4TInventoryMB ON VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo) ON (VS4VStockFULL.TInMCustom1 = VS4TInventoryMB.TInMCustom1) AND (VS4VStockFULL.TInMSerialNo = VS4TInventoryMB.TInMSerialNo) AND (VS4VStockFULL.TInMLotDate = VS4TInventoryMB.TInMLotDate) AND (VS4VStockFULL.TInMLotNo = VS4TInventoryMB.TInMLotNo) AND (VS4VStockFULL.TPdtCode = VS4TInventoryMB.TInMTPdtCode)
GO

CREATE VIEW VS4VStockFULLM
AS 
SELECT Vs4VInventStockM.TPdtCode, Vs4VInventStockM.TPdtBarcode, Vs4VInventStockM.TPdtName, Vs4VInventStockM.TPdtTPTTCode, Vs4VInventStockM.TPdtTPPuCode, Vs4VInventStockM.TPdtFlag1, Sum(Vs4VInventStockM.TInMInQuantity) AS TInMInQuantity, Sum(Vs4VInventStockM.TInMOutQuantity) AS TInMOutQuantity, Sum(Vs4VInventStockM.TInMAmouQuantity) AS TInMAmouQuantity, Vs4VInventStockM.TPdtTUntCode, Sum(Vs4VInventStockM.TInMInQuantity2) AS TInMInQuantity2, Sum(Vs4VInventStockM.TInMOutQuantity2) AS TInMOutQuantity2, Sum(Vs4VInventStockM.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStockM.TPdtTUntCode2, Sum(Vs4VInventStockM.TInMInQuantity3) AS TInMInQuantity3, Sum(Vs4VInventStockM.TInMOutQuantity3) AS TInMOutQuantity3, Sum(Vs4VInventStockM.TInMAmouQuantity3) AS TInMAmouQuantity3, Vs4VInventStockM.TPdtTUntCode3, Sum(Vs4VInventStockM.TInMAmount) AS TInMAmount, Vs4VInventStockM.TIMCUnitCost AS TIMCUnitCost, Vs4VInventStockM.TWahCode, Vs4VInventStockM.TWahName, Vs4VInventStockM.TInMTLctCode, Vs4VInventStockM.TLctName, Vs4VInventStockM.TInMLotNo, Vs4VInventStockM.TInMLotDate, Vs4VInventStockM.TIMCCustom4, Vs4VInventStockM.TIMCCustom5, Vs4VInventStockM.TIMCGrade, Vs4VInventStockM.TInMSerialNo, Vs4VInventStockM.TIMCTCgTID, Vs4VInventStockM.TIMCNoExpire, Vs4VInventStockM.TIMCExpireDate, Vs4VInventStockM.TIMCLotNo2, Vs4VInventStockM.TIMCJobCode, Vs4VInventStockM.TInMCustom1, Vs4VInventStockM.TIMCCustom2, Vs4VInventStockM.TIMCCustom3, Vs4VInventStockM.TPdtTPDLCode, Vs4VInventStockM.TPdtTPSECode, Vs4VInventStockM.TPdtTPS2Code, Vs4VInventStockM.TPdtTPS3Code, Vs4VInventStockM.TPdtTPS4Code, Vs4VInventStockM.TPdtTPG1Code, Vs4VInventStockM.TPdtTPG2Code, Vs4VInventStockM.TPdtTPG3Code, Vs4VInventStockM.TPdtTPG4Code, Vs4VInventStockM.TPdtTPCTAlias, Vs4VInventStockM.TInMScrapLevel, Vs4VInventStockM.TIMCReserve, Sum(Vs4VInventStockM.TInMQuantityBase) AS TInMQuantityBase, Vs4VInventStockM.TIMCIsPremium, Vs4VInventStockM.TIMCPremiumNote, Vs4VInventStockM.TLctDayAlert, Vs4VInventStockM.TLctDayMove, Vs4VInventStockM.TPdtSlowDay, Vs4VInventStockM.TPdtDeadDay, Vs4VInventStockM.TPdtSerialType, Vs4VInventStockM.TIMCUnitCalc, Sum(Vs4VInventStockM.TInMQuantityCalc) AS TInMQuantityCalc, Vs4VInventStockM.TPdtOrderPoint, Vs4VInventStockM.TIMCInputCost, Max(Vs4VInventStockM.TIMCLastUnitCost) AS TIMCLastUnitCost, Vs4VInventStockM.TIMCPerQuantity, Vs4VInventStockM.TLctTBraCode, Vs4VInventStockM.TPdtTAPNCode, Vs4VInventStockM.TPdtFactoryCode, Vs4VInventStockM.TIMCCostCode, Vs4VInventStockM.TPOSPrice, Vs4VInventStockM.TIMCReceiveNo, Vs4VInventStockM.TIMCReceiveLn, Vs4VInventStockM.TIMCQAStatus, Vs4VInventStockM.TIMCQANote, Vs4VInventStockM.TIMCTAPNCode, Vs4VInventStockM.TIMCInvoiceNo, Vs4VInventStockM.TIMCInvoiceDate, Vs4VInventStockM.TIMCUnitRatio, Vs4VInventStockM.TIMCTUntCode, Vs4VInventStockM.TPOSPackAlias2, Vs4VInventStockM.TInMTACPTACYID, Vs4VInventStockM.TInMTACPID, Vs4VInventStockM.TInMTPltCode
FROM Vs4VInventStockM
GROUP BY Vs4VInventStockM.TPdtCode, Vs4VInventStockM.TPdtBarcode, Vs4VInventStockM.TPdtName, Vs4VInventStockM.TPdtTPTTCode, Vs4VInventStockM.TPdtTPPuCode, Vs4VInventStockM.TPdtFlag1, Vs4VInventStockM.TPdtTUntCode, Vs4VInventStockM.TPdtTUntCode2, Vs4VInventStockM.TPdtTUntCode3, Vs4VInventStockM.TIMCUnitCost, Vs4VInventStockM.TWahCode, Vs4VInventStockM.TWahName, Vs4VInventStockM.TInMTLctCode, Vs4VInventStockM.TLctName, Vs4VInventStockM.TInMLotNo, Vs4VInventStockM.TInMLotDate, Vs4VInventStockM.TIMCCustom4, Vs4VInventStockM.TIMCCustom5, Vs4VInventStockM.TIMCGrade, Vs4VInventStockM.TInMSerialNo, Vs4VInventStockM.TIMCTCgTID, Vs4VInventStockM.TIMCNoExpire, Vs4VInventStockM.TIMCExpireDate, Vs4VInventStockM.TIMCLotNo2, Vs4VInventStockM.TIMCJobCode, Vs4VInventStockM.TInMCustom1, Vs4VInventStockM.TIMCCustom2, Vs4VInventStockM.TIMCCustom3, Vs4VInventStockM.TPdtTPDLCode, Vs4VInventStockM.TPdtTPSECode, Vs4VInventStockM.TPdtTPS2Code, Vs4VInventStockM.TPdtTPS3Code, Vs4VInventStockM.TPdtTPS4Code, Vs4VInventStockM.TPdtTPG1Code, Vs4VInventStockM.TPdtTPG2Code, Vs4VInventStockM.TPdtTPG3Code, Vs4VInventStockM.TPdtTPG4Code, Vs4VInventStockM.TPdtTPCTAlias, Vs4VInventStockM.TInMScrapLevel, Vs4VInventStockM.TIMCReserve, Vs4VInventStockM.TIMCIsPremium, Vs4VInventStockM.TIMCPremiumNote, Vs4VInventStockM.TLctDayAlert, Vs4VInventStockM.TLctDayMove, Vs4VInventStockM.TPdtSlowDay, Vs4VInventStockM.TPdtDeadDay, Vs4VInventStockM.TPdtSerialType, Vs4VInventStockM.TIMCUnitCalc, Vs4VInventStockM.TPdtOrderPoint, Vs4VInventStockM.TIMCInputCost, Vs4VInventStockM.TIMCPerQuantity, Vs4VInventStockM.TLctTBraCode, Vs4VInventStockM.TPdtTAPNCode, Vs4VInventStockM.TPdtFactoryCode, Vs4VInventStockM.TIMCCostCode, Vs4VInventStockM.TPOSPrice, Vs4VInventStockM.TIMCReceiveNo, Vs4VInventStockM.TIMCReceiveLn, Vs4VInventStockM.TIMCQAStatus, Vs4VInventStockM.TIMCQANote, Vs4VInventStockM.TIMCTAPNCode, Vs4VInventStockM.TIMCInvoiceNo, Vs4VInventStockM.TIMCInvoiceDate, Vs4VInventStockM.TIMCUnitRatio, Vs4VInventStockM.TIMCTUntCode, Vs4VInventStockM.TPOSPackAlias2, Vs4VInventStockM.TInMTACPTACYID, Vs4VInventStockM.TInMTACPID, Vs4VInventStockM.TInMTPltCode
GO

CREATE VIEW VS4VStockFULLP
AS 
SELECT VS4VInventStockP.TPdtCode, VS4VInventStockP.TPdtBarcode, VS4VInventStockP.TPdtName, VS4VInventStockP.TPdtTPTTCode, VS4VInventStockP.TPdtTPPuCode, VS4VInventStockP.TPdtFlag1, Sum(VS4VInventStockP.TInMInQuantity) AS TInMInQuantity, Sum(VS4VInventStockP.TInMOutQuantity) AS TInMOutQuantity, Sum(VS4VInventStockP.TInMAmouQuantity) AS TInMAmouQuantity, VS4VInventStockP.TPdtTUntCode, Sum(VS4VInventStockP.TInMInQuantity2) AS TInMInQuantity2, Sum(VS4VInventStockP.TInMOutQuantity2) AS TInMOutQuantity2, Sum(VS4VInventStockP.TInMAmouQuantity2) AS TInMAmouQuantity2, VS4VInventStockP.TPdtTUntCode2, Sum(VS4VInventStockP.TInMInQuantity3) AS TInMInQuantity3, Sum(VS4VInventStockP.TInMOutQuantity3) AS TInMOutQuantity3, Sum(VS4VInventStockP.TInMAmouQuantity3) AS TInMAmouQuantity3, VS4VInventStockP.TPdtTUntCode3, Sum(VS4VInventStockP.TInMAmount) AS TInMAmount, VS4VInventStockP.TIMCUnitCost AS TIMCUnitCost, VS4VInventStockP.TWahCode, VS4VInventStockP.TWahName, VS4VInventStockP.TInMTLctCode, VS4VInventStockP.TLctName, VS4VInventStockP.TInMLotNo, VS4VInventStockP.TInMLotDate, VS4VInventStockP.TIMCCustom4, VS4VInventStockP.TIMCCustom5, VS4VInventStockP.TIMCGrade, VS4VInventStockP.TInMSerialNo, VS4VInventStockP.TIMCTCgTID, VS4VInventStockP.TIMCNoExpire, VS4VInventStockP.TIMCExpireDate, VS4VInventStockP.TIMCLotNo2, VS4VInventStockP.TIMCJobCode, VS4VInventStockP.TInMCustom1, VS4VInventStockP.TIMCCustom2, VS4VInventStockP.TIMCCustom3, VS4VInventStockP.TPdtTPDLCode, VS4VInventStockP.TPdtTPSECode, VS4VInventStockP.TPdtTPS2Code, VS4VInventStockP.TPdtTPS3Code, VS4VInventStockP.TPdtTPS4Code, VS4VInventStockP.TPdtTPG1Code, VS4VInventStockP.TPdtTPG2Code, VS4VInventStockP.TPdtTPG3Code, VS4VInventStockP.TPdtTPG4Code, VS4VInventStockP.TPdtTPCTAlias, VS4VInventStockP.TInMScrapLevel, VS4VInventStockP.TIMCReserve, Sum(VS4VInventStockP.TInMQuantityBase) AS TInMQuantityBase, VS4VInventStockP.TIMCIsPremium, VS4VInventStockP.TIMCPremiumNote, VS4VInventStockP.TLctDayAlert, VS4VInventStockP.TLctDayMove, VS4VInventStockP.TPdtSlowDay, VS4VInventStockP.TPdtDeadDay, VS4VInventStockP.TPdtSerialType, VS4VInventStockP.TIMCUnitCalc, Sum(VS4VInventStockP.TInMQuantityCalc) AS TInMQuantityCalc, VS4VInventStockP.TPdtOrderPoint, VS4VInventStockP.TIMCInputCost, Max(VS4VInventStockP.TIMCLastUnitCost) AS TIMCLastUnitCost, VS4VInventStockP.TIMCPerQuantity, VS4VInventStockP.TLctTBraCode, VS4VInventStockP.TPdtTAPNCode, VS4VInventStockP.TPdtFactoryCode, VS4VInventStockP.TIMCReceiveNo, VS4VInventStockP.TIMCReceiveLn, VS4VInventStockP.TIMCQAStatus, VS4VInventStockP.TIMCQANote, VS4VInventStockP.TIMCTAPNCode, VS4VInventStockP.TIMCInvoiceNo, VS4VInventStockP.TIMCInvoiceDate, VS4VInventStockP.TIMCUnitRatio, VS4VInventStockP.TIMCTUntCode, VS4VInventStockP.TPOSPackAlias2, VS4VInventStockP.TInMTPltCode
FROM VS4VInventStockP
GROUP BY VS4VInventStockP.TPdtCode, VS4VInventStockP.TPdtBarcode, VS4VInventStockP.TPdtName, VS4VInventStockP.TPdtTPTTCode, VS4VInventStockP.TPdtTPPuCode, VS4VInventStockP.TPdtFlag1, VS4VInventStockP.TPdtTUntCode, VS4VInventStockP.TPdtTUntCode2, VS4VInventStockP.TPdtTUntCode3, VS4VInventStockP.TIMCUnitCost, VS4VInventStockP.TWahCode, VS4VInventStockP.TWahName, VS4VInventStockP.TInMTLctCode, VS4VInventStockP.TLctName, VS4VInventStockP.TInMLotNo, VS4VInventStockP.TInMLotDate, VS4VInventStockP.TIMCCustom4, VS4VInventStockP.TIMCCustom5, VS4VInventStockP.TIMCGrade, VS4VInventStockP.TInMSerialNo, VS4VInventStockP.TIMCTCgTID, VS4VInventStockP.TIMCNoExpire, VS4VInventStockP.TIMCExpireDate, VS4VInventStockP.TIMCLotNo2, VS4VInventStockP.TIMCJobCode, VS4VInventStockP.TInMCustom1, VS4VInventStockP.TIMCCustom2, VS4VInventStockP.TIMCCustom3, VS4VInventStockP.TPdtTPDLCode, VS4VInventStockP.TPdtTPSECode, VS4VInventStockP.TPdtTPS2Code, VS4VInventStockP.TPdtTPS3Code, VS4VInventStockP.TPdtTPS4Code, VS4VInventStockP.TPdtTPG1Code, VS4VInventStockP.TPdtTPG2Code, VS4VInventStockP.TPdtTPG3Code, VS4VInventStockP.TPdtTPG4Code, VS4VInventStockP.TPdtTPCTAlias, VS4VInventStockP.TInMScrapLevel, VS4VInventStockP.TIMCReserve, VS4VInventStockP.TIMCIsPremium, VS4VInventStockP.TIMCPremiumNote, VS4VInventStockP.TLctDayAlert, VS4VInventStockP.TLctDayMove, VS4VInventStockP.TPdtSlowDay, VS4VInventStockP.TPdtDeadDay, VS4VInventStockP.TPdtSerialType, VS4VInventStockP.TIMCUnitCalc, VS4VInventStockP.TPdtOrderPoint, VS4VInventStockP.TIMCInputCost, VS4VInventStockP.TIMCPerQuantity, VS4VInventStockP.TLctTBraCode, VS4VInventStockP.TPdtTAPNCode, VS4VInventStockP.TPdtFactoryCode, VS4VInventStockP.TIMCReceiveNo, VS4VInventStockP.TIMCReceiveLn, VS4VInventStockP.TIMCQAStatus, VS4VInventStockP.TIMCQANote, VS4VInventStockP.TIMCTAPNCode, VS4VInventStockP.TIMCInvoiceNo, VS4VInventStockP.TIMCInvoiceDate, VS4VInventStockP.TIMCUnitRatio, VS4VInventStockP.TIMCTUntCode, VS4VInventStockP.TPOSPackAlias2, VS4VInventStockP.TInMTPltCode
GO

CREATE VIEW VS4VStockFULLY
AS 
SELECT Vs4VInventStockM.TPdtCode, Vs4VInventStockM.TPdtBarcode, Vs4VInventStockM.TPdtName, Vs4VInventStockM.TPdtTPTTCode, Vs4VInventStockM.TPdtTPPuCode, Vs4VInventStockM.TPdtFlag1, Sum(Vs4VInventStockM.TInMInQuantity) AS TInMInQuantity, Sum(Vs4VInventStockM.TInMOutQuantity) AS TInMOutQuantity, Sum(Vs4VInventStockM.TInMAmouQuantity) AS TInMAmouQuantity, Vs4VInventStockM.TPdtTUntCode, Sum(Vs4VInventStockM.TInMInQuantity2) AS TInMInQuantity2, Sum(Vs4VInventStockM.TInMOutQuantity2) AS TInMOutQuantity2, Sum(Vs4VInventStockM.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStockM.TPdtTUntCode2, Sum(Vs4VInventStockM.TInMInQuantity3) AS TInMInQuantity3, Sum(Vs4VInventStockM.TInMOutQuantity3) AS TInMOutQuantity3, Sum(Vs4VInventStockM.TInMAmouQuantity3) AS TInMAmouQuantity3, Vs4VInventStockM.TPdtTUntCode3, Sum(Vs4VInventStockM.TInMAmount) AS TInMAmount, Vs4VInventStockM.TIMCUnitCost AS TIMCUnitCost, Vs4VInventStockM.TWahCode, Vs4VInventStockM.TWahName, Vs4VInventStockM.TInMTLctCode, Vs4VInventStockM.TLctName, Vs4VInventStockM.TInMLotNo, Vs4VInventStockM.TInMLotDate, Vs4VInventStockM.TIMCCustom4, Vs4VInventStockM.TIMCCustom5, Vs4VInventStockM.TIMCGrade, Vs4VInventStockM.TInMSerialNo, Vs4VInventStockM.TIMCTCgTID, Vs4VInventStockM.TIMCNoExpire, Vs4VInventStockM.TIMCExpireDate, Vs4VInventStockM.TIMCLotNo2, Vs4VInventStockM.TIMCJobCode, Vs4VInventStockM.TInMCustom1, Vs4VInventStockM.TIMCCustom2, Vs4VInventStockM.TIMCCustom3, Vs4VInventStockM.TPdtTPDLCode, Vs4VInventStockM.TPdtTPSECode, Vs4VInventStockM.TPdtTPS2Code, Vs4VInventStockM.TPdtTPS3Code, Vs4VInventStockM.TPdtTPS4Code, Vs4VInventStockM.TPdtTPG1Code, Vs4VInventStockM.TPdtTPG2Code, Vs4VInventStockM.TPdtTPG3Code, Vs4VInventStockM.TPdtTPG4Code, Vs4VInventStockM.TPdtTPCTAlias, Vs4VInventStockM.TInMScrapLevel, Vs4VInventStockM.TIMCReserve, Sum(Vs4VInventStockM.TInMQuantityBase) AS TInMQuantityBase, Vs4VInventStockM.TIMCIsPremium, Vs4VInventStockM.TIMCPremiumNote, Vs4VInventStockM.TLctDayAlert, Vs4VInventStockM.TLctDayMove, Vs4VInventStockM.TPdtSlowDay, Vs4VInventStockM.TPdtDeadDay, Vs4VInventStockM.TPdtSerialType, Vs4VInventStockM.TIMCUnitCalc, Sum(Vs4VInventStockM.TInMQuantityCalc) AS TInMQuantityCalc, Vs4VInventStockM.TPdtOrderPoint, Vs4VInventStockM.TIMCInputCost, Max(Vs4VInventStockM.TIMCLastUnitCost) AS TIMCLastUnitCost, Vs4VInventStockM.TIMCPerQuantity, Vs4VInventStockM.TLctTBraCode, Vs4VInventStockM.TPdtTAPNCode, Vs4VInventStockM.TPdtFactoryCode, Vs4VInventStockM.TIMCCostCode, Vs4VInventStockM.TPOSPrice, Vs4VInventStockM.TIMCReceiveNo, Vs4VInventStockM.TIMCReceiveLn, Vs4VInventStockM.TIMCQAStatus, Vs4VInventStockM.TIMCQANote, Vs4VInventStockM.TIMCTAPNCode, Vs4VInventStockM.TIMCInvoiceNo, Vs4VInventStockM.TIMCInvoiceDate, Vs4VInventStockM.TIMCUnitRatio, Vs4VInventStockM.TIMCTUntCode, Vs4VInventStockM.TPOSPackAlias2, Vs4VInventStockM.TInMTACPTACYID, Vs4VInventStockM.TInMTPltCode
FROM Vs4VInventStockM
GROUP BY Vs4VInventStockM.TPdtCode, Vs4VInventStockM.TPdtBarcode, Vs4VInventStockM.TPdtName, Vs4VInventStockM.TPdtTPTTCode, Vs4VInventStockM.TPdtTPPuCode, Vs4VInventStockM.TPdtFlag1, Vs4VInventStockM.TPdtTUntCode, Vs4VInventStockM.TPdtTUntCode2, Vs4VInventStockM.TPdtTUntCode3, Vs4VInventStockM.TIMCUnitCost, Vs4VInventStockM.TWahCode, Vs4VInventStockM.TWahName, Vs4VInventStockM.TInMTLctCode, Vs4VInventStockM.TLctName, Vs4VInventStockM.TInMLotNo, Vs4VInventStockM.TInMLotDate, Vs4VInventStockM.TIMCCustom4, Vs4VInventStockM.TIMCCustom5, Vs4VInventStockM.TIMCGrade, Vs4VInventStockM.TInMSerialNo, Vs4VInventStockM.TIMCTCgTID, Vs4VInventStockM.TIMCNoExpire, Vs4VInventStockM.TIMCExpireDate, Vs4VInventStockM.TIMCLotNo2, Vs4VInventStockM.TIMCJobCode, Vs4VInventStockM.TInMCustom1, Vs4VInventStockM.TIMCCustom2, Vs4VInventStockM.TIMCCustom3, Vs4VInventStockM.TPdtTPDLCode, Vs4VInventStockM.TPdtTPSECode, Vs4VInventStockM.TPdtTPS2Code, Vs4VInventStockM.TPdtTPS3Code, Vs4VInventStockM.TPdtTPS4Code, Vs4VInventStockM.TPdtTPG1Code, Vs4VInventStockM.TPdtTPG2Code, Vs4VInventStockM.TPdtTPG3Code, Vs4VInventStockM.TPdtTPG4Code, Vs4VInventStockM.TPdtTPCTAlias, Vs4VInventStockM.TInMScrapLevel, Vs4VInventStockM.TIMCReserve, Vs4VInventStockM.TIMCIsPremium, Vs4VInventStockM.TIMCPremiumNote, Vs4VInventStockM.TLctDayAlert, Vs4VInventStockM.TLctDayMove, Vs4VInventStockM.TPdtSlowDay, Vs4VInventStockM.TPdtDeadDay, Vs4VInventStockM.TPdtSerialType, Vs4VInventStockM.TIMCUnitCalc, Vs4VInventStockM.TPdtOrderPoint, Vs4VInventStockM.TIMCInputCost, Vs4VInventStockM.TIMCPerQuantity, Vs4VInventStockM.TLctTBraCode, Vs4VInventStockM.TPdtTAPNCode, Vs4VInventStockM.TPdtFactoryCode, Vs4VInventStockM.TIMCCostCode, Vs4VInventStockM.TPOSPrice, Vs4VInventStockM.TIMCReceiveNo, Vs4VInventStockM.TIMCReceiveLn, Vs4VInventStockM.TIMCQAStatus, Vs4VInventStockM.TIMCQANote, Vs4VInventStockM.TIMCTAPNCode, Vs4VInventStockM.TIMCInvoiceNo, Vs4VInventStockM.TIMCInvoiceDate, Vs4VInventStockM.TIMCUnitRatio, Vs4VInventStockM.TIMCTUntCode, Vs4VInventStockM.TPOSPackAlias2, Vs4VInventStockM.TInMTACPTACYID, Vs4VInventStockM.TInMTPltCode
GO

CREATE VIEW VS4VStockG
AS 
SELECT Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtTPTTCode, Vs4VInventStock.TPdtTPPuCode, Vs4VInventStock.TPdtFlag1, Sum(Vs4VInventStock.TInMInQuantity) AS TInMInQuantity, Sum(Vs4VInventStock.TInMOutQuantity) AS TInMOutQuantity, Sum(Vs4VInventStock.TInMAmouQuantity) AS TInMAmouQuantity, Vs4VInventStock.TPdtTUntCode, Sum(Vs4VInventStock.TInMInQuantity2) AS TInMInQuantity2, Sum(Vs4VInventStock.TInMOutQuantity2) AS TInMOutQuantity2, Sum(Vs4VInventStock.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, Sum(Vs4VInventStock.TInMInQuantity3) AS TInMInQuantity3, Sum(Vs4VInventStock.TInMOutQuantity3) AS TInMOutQuantity3, Sum(Vs4VInventStock.TInMAmouQuantity3) AS TInMAmouQuantity3, Vs4VInventStock.TPdtTUntCode3, Sum(Vs4VInventStock.TInMAmount) AS TInMAmount, Avg(Vs4VInventStock.TIMCUnitCost) AS TIMCUnitCost, Vs4VInventStock.TIMCGrade, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, Vs4VInventStock.TPdtTPG4Code, Vs4VInventStock.TPdtTPCTAlias, Vs4VInventStock.TIMCUnitCalc, Sum(Vs4VInventStock.TInMQuantityCalc) AS TInMQuantityCalc, Vs4VInventStock.TPdtOrderPoint, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TPdtTAPNCode, Vs4VInventStock.TPdtFactoryCode, Vs4VInventStock.TPdtPurchaseFee, Vs4VInventStock.TPOSPackAlias2
FROM Vs4VInventStock
GROUP BY Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtTPTTCode, Vs4VInventStock.TPdtTPPuCode, Vs4VInventStock.TPdtFlag1, Vs4VInventStock.TPdtTUntCode, Vs4VInventStock.TPdtTUntCode2, Vs4VInventStock.TPdtTUntCode3, Vs4VInventStock.TIMCGrade, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, Vs4VInventStock.TPdtTPG4Code, Vs4VInventStock.TPdtTPCTAlias, Vs4VInventStock.TIMCUnitCalc, Vs4VInventStock.TPdtOrderPoint, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TPdtTAPNCode, Vs4VInventStock.TPdtFactoryCode, Vs4VInventStock.TPdtPurchaseFee, Vs4VInventStock.TPOSPackAlias2
GO

CREATE VIEW VS4VStockM
AS 
SELECT Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtTPTTCode, Vs4VInventStock.TPdtTPPuCode, Vs4VInventStock.TPdtFlag1, Sum(Vs4VInventStock.TInMInQuantity) AS TInMInQuantity, Sum(Vs4VInventStock.TInMOutQuantity) AS TInMOutQuantity, Sum(Vs4VInventStock.TInMAmouQuantity) AS TInMAmouQuantity, Vs4VInventStock.TPdtTUntCode, Sum(Vs4VInventStock.TInMInQuantity2) AS TInMInQuantity2, Sum(Vs4VInventStock.TInMOutQuantity2) AS TInMOutQuantity2, Sum(Vs4VInventStock.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, Sum(Vs4VInventStock.TInMInQuantity3) AS TInMInQuantity3, Sum(Vs4VInventStock.TInMOutQuantity3) AS TInMOutQuantity3, Sum(Vs4VInventStock.TInMAmouQuantity3) AS TInMAmouQuantity3, Vs4VInventStock.TPdtTUntCode3, Sum(Vs4VInventStock.TInMAmount) AS TInMAmount, Avg(Vs4VInventStock.TIMCUnitCost) AS TIMCUnitCost, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, Vs4VInventStock.TPdtTPG4Code, Vs4VInventStock.TPdtTPCTAlias, Vs4VInventStock.TPOSPrice, Vs4VInventStock.TPdtOrderPoint, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TIMCUnitCalc, Sum(Vs4VInventStock.TInMQuantityCalc) AS TInMQuantityCalc, Vs4VInventStock.TPdtTAPNCode, Vs4VInventStock.TPdtFactoryCode, Vs4VInventStock.TPOSPackAlias2
FROM Vs4VInventStock
GROUP BY Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtTPTTCode, Vs4VInventStock.TPdtTPPuCode, Vs4VInventStock.TPdtFlag1, Vs4VInventStock.TPdtTUntCode, Vs4VInventStock.TPdtTUntCode2, Vs4VInventStock.TPdtTUntCode3, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, Vs4VInventStock.TPdtTPG4Code, Vs4VInventStock.TPdtTPCTAlias, Vs4VInventStock.TPOSPrice, Vs4VInventStock.TPdtOrderPoint, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TIMCUnitCalc, Vs4VInventStock.TPdtTAPNCode, Vs4VInventStock.TPdtFactoryCode, Vs4VInventStock.TPOSPackAlias2, Vs4VInventStock.TWahCode
HAVING (((Vs4VInventStock.TwahCode)<>'PURCHASERETURN' And (Vs4VInventStock.TwahCode)<>'INPROCESS' And (Vs4VInventStock.TwahCode)<>'OUTPROCESS' And (Vs4VInventStock.TwahCode)<>'TEMP' And (Vs4VInventStock.TwahCode)<>'CONSIGN' And (Vs4VInventStock.TwahCode)<>'CUSTOMER' And (Vs4VInventStock.TwahCode)<>'BORROW' And (Vs4VInventStock.TwahCode)<>'SALERETURN'))
GO

CREATE VIEW VS4VStockMoveSum
AS 
SELECT VS4TInventory.TInvDate, VS4TProduct.TPdtCode, VS4TProduct.TPdtName, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, Sum(VS4TInventoryMB.TInMInQuantity) AS TInMInQuantity, Sum(VS4TInventoryMB.TInMOutQuantity) AS TInMOutQuantity, Sum(VS4TInventoryMB.TInMInQuantity2) AS TInMInQuantity2, Sum(VS4TInventoryMB.TInMOutQuantity2) AS TInMOutQuantity2, Sum(VS4TInventoryMB.TInMInQuantity3) AS TInMInQuantity3, Sum(VS4TInventoryMB.TInMOutQuantity3) AS TInMOutQuantity3, Max(VS4TInventoryMB.TInMInQuantity) AS HTInMInQuantity, Max(VS4TInventoryMB.TInMOutQuantity) AS HTInMOutQuantity, Max(VS4TInventoryMB.TInMInQuantity2) AS HTInMInQuantity2, Max(VS4TInventoryMB.TInMOutQuantity2) AS HTInMOutQuantity2, Max(VS4TInventoryMB.TInMInQuantity3) AS HTInMInQuantity3, Max(VS4TInventoryMB.TInMOutQuantity3) AS HTInMOutQuantity3, Min(VS4TInventoryMB.TInMInQuantity) AS LTInMInQuantity, Min(VS4TInventoryMB.TInMOutQuantity) AS LTInMOutQuantity, Min(VS4TInventoryMB.TInMInQuantity2) AS LTInMInQuantity2, Min(VS4TInventoryMB.TInMOutQuantity2) AS LTInMOutQuantity2, Min(VS4TInventoryMB.TInMInQuantity3) AS LTInMInQuantity3, Min(VS4TInventoryMB.TInMOutQuantity3) AS LTInMOutQuantity3, Avg(VS4TInventoryMB.TInMInQuantity) AS ATInMInQuantity, Avg(VS4TInventoryMB.TInMOutQuantity) AS ATInMOutQuantity, Avg(VS4TInventoryMB.TInMInQuantity2) AS ATInMInQuantity2, Avg(VS4TInventoryMB.TInMOutQuantity2) AS ATInMOutQuantity2, Avg(VS4TInventoryMB.TInMInQuantity3) AS ATInMInQuantity3, Avg(VS4TInventoryMB.TInMOutQuantity3) AS ATInMOutQuantity3, VS4TInventoryLOT.TIMCUnitCalc, Sum(VS4TInventoryMB.TInMQuantityCalc) AS TInMQuantityCalc, VS4TProduct.TPdtOrderPoint, VS4TProduct.TPdtSlowDay, VS4TProduct.TPdtDeadDay, VS4TProduct.TPdtSerialType, VS4TProduct.TPdtFactoryCode, VS4TProduct.TPdtTAPNCode, VS4TWarehouse.TWahCode, VS4TLocation.TLctTBraCode, VS4TPOS.TPOSPackAlias2
FROM (VS4TUnit INNER JOIN (VS4TInventoryType INNER JOIN (VS4TProduct INNER JOIN (VS4TInventory INNER JOIN (((VS4TInventoryMB LEFT JOIN VS4TLocation ON VS4TInventoryMB.TInMTLctCode = VS4TLocation.TLctCode) LEFT JOIN VS4TWarehouse ON VS4TLocation.TLctTWahCode = VS4TWarehouse.TWahCode) LEFT JOIN VS4TInventoryLOT ON (VS4TInventoryMB.TInMLotDate = VS4TInventoryLOT.TIMCLotDate) AND (VS4TInventoryMB.TInMLotNo = VS4TInventoryLOT.TIMCLotNo) AND (VS4TInventoryMB.TInMSerialNo = VS4TInventoryLOT.TIMCSerialNo) AND (VS4TInventoryMB.TInMCustom1 = VS4TInventoryLOT.TIMCCustom1) AND (VS4TInventoryMB.TInMTPdtCode = VS4TInventoryLOT.TIMCTPdtCode)) ON VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo) ON VS4TProduct.TPdtCode = VS4TInventoryMB.TInMTPdtCode) ON VS4TInventoryType.TInTAlias = VS4TInventory.TInvTInTAlias) ON VS4TUnit.TUntCode = VS4TProduct.TPdtTUntCode) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode
GROUP BY VS4TInventory.TInvDate, VS4TProduct.TPdtCode, VS4TProduct.TPdtName, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TInventoryLOT.TIMCUnitCalc, VS4TProduct.TPdtOrderPoint, VS4TProduct.TPdtSlowDay, VS4TProduct.TPdtDeadDay, VS4TProduct.TPdtSerialType, VS4TProduct.TPdtFactoryCode, VS4TProduct.TPdtTAPNCode, VS4TWarehouse.TWahCode, VS4TLocation.TLctTBraCode, VS4TPOS.TPOSPackAlias2, VS4TInventoryMB.TInMStatus, VS4TInventory.TInvCancelStatus, VS4TInventory.TInvApproveStatus, VS4TInventoryMB.TInMStatus
HAVING (((VS4TWarehouse.TWahCode)<>'INPROCESS' And (VS4TWarehouse.TWahCode)<>'OUTPROCESS' And (VS4TWarehouse.TWahCode)<>'BORROW' And (VS4TWarehouse.TWahCode)<>'CONSIGN' And (VS4TWarehouse.TWahCode)<>'PURCHASERETURN' And (VS4TWarehouse.TWahCode)<>'SCRAP') AND ((VS4TInventory.TInvCancelStatus)=0) AND ((VS4TInventory.TInvApproveStatus)=1) AND ((VS4TInventoryMB.TInMStatus)=1 And (VS4TInventoryMB.TInMStatus)=1))
GO

CREATE VIEW VS4VStockNo
AS 
SELECT VS4TInventoryMB.TInMTInvNo, VS4TInventoryMB.TInMLn, VS4TInventory.TInvRefNo, VS4TInventory.TInvRefDate, VS4TInventory.TInvRefNo2, VS4TInventory.TInvRefDate2, VS4TInventory.TInvRefNo3, VS4TInventory.TInvRefDate3, VS4TInventory.TInvFromTBraCode, VS4TInventory.TInvTBraCode, VS4TInventory.TInvRequestCode, VS4TInventory.TInvRequestBy, VS4TAP.TAPNCode, VS4TAP.TAPNName
FROM VS4TInventory INNER JOIN ((VS4TInventoryMB LEFT JOIN VS4TInventoryType ON VS4TInventoryMB.TInMTInTAlias = VS4TInventoryType.TInTAlias) LEFT JOIN (VS4TInventoryLOT LEFT JOIN VS4TAP ON VS4TInventoryLOT.TIMCTAPNCode = VS4TAP.TAPNCode) ON (VS4TInventoryMB.TInMTPdtCode = VS4TInventoryLOT.TIMCTPdtCode) AND (VS4TInventoryMB.TInMCustom1 = VS4TInventoryLOT.TIMCCustom1) AND (VS4TInventoryMB.TInMSerialNo = VS4TInventoryLOT.TIMCSerialNo) AND (VS4TInventoryMB.TInMLotNo = VS4TInventoryLOT.TIMCLotNo) AND (VS4TInventoryMB.TInMLotDate = VS4TInventoryLOT.TIMCLotDate)) ON VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo
WHERE (((VS4TInventoryType.TInTInputCost)=1))
GO

CREATE VIEW VS4VStockNow
AS 
SELECT VS4TInventoryLOT.*, VS4TStockNow.*, VS4TProduct.*, VS4TPOS.*, VS4TProductGroup1.TPG1Name, VS4TProductGroup2.TPG2Name, VS4TProductGroup3.TPG3Name, VS4TProductGroup4.TPG4Name, VS4TProductSection.TPSEName, VS4TProductSec2.TPS2Name, VS4TProductSec3.TPS3Name, VS4TProductSec4.TPS4Name
FROM (VS4TProductLine RIGHT JOIN (VS4TInventoryLOT LEFT JOIN (((((((((VS4TStockNow LEFT JOIN VS4TProduct ON VS4TStockNow.TSFNTPdtCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode) LEFT JOIN VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code) LEFT JOIN VS4TProductGroup2 ON VS4TProduct.TPdtTPG2Code = VS4TProductGroup2.TPG2Code) LEFT JOIN VS4TProductSec3 ON VS4TProduct.TPdtTPS3Code = VS4TProductSec3.TPS3Code) LEFT JOIN VS4TProductSec4 ON VS4TProduct.TPdtTPS4Code = VS4TProductSec4.TPS4Code) LEFT JOIN VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code) LEFT JOIN VS4TProductGroup4 ON VS4TProduct.TPdtTPG4Code = VS4TProductGroup4.TPG4Code) LEFT JOIN VS4TProductGroup3 ON VS4TProduct.TPdtTPG3Code = VS4TProductGroup3.TPG3Code) ON (VS4TInventoryLOT.TIMCLotDate = VS4TStockNow.TSFNLotDate) AND (VS4TInventoryLOT.TIMCLotNo = VS4TStockNow.TSFNLotNo) AND (VS4TInventoryLOT.TIMCSerialNo = VS4TStockNow.TSFNSerialNo) AND (VS4TInventoryLOT.TIMCCustom1 = VS4TStockNow.TSFNCustom1) AND (VS4TInventoryLOT.TIMCTPdtCode = VS4TStockNow.TSFNTPdtCode)) ON VS4TProductLine.TPdLCode = VS4TProduct.TPdtTPDLCode) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode
GO

CREATE VIEW VS4VStockOrderP
AS 
SELECT VS4VProduct.*, VS4VStock.TInMAmouQuantity, VS4VStock.TInMAmouQuantity2, VS4VStock.TInMAmouQuantity3, VS4VStock.TIMCUnitCost, VS4VStock.TInMAmount
FROM VS4VProduct LEFT JOIN VS4VStock ON VS4VProduct.TPdtCode = VS4VStock.TPdtCode
WHERE (((VS4VProduct.TPdtOrderPoint)>=0))
GO

CREATE VIEW VS4VStockOrderPoin
AS 
SELECT VS4VStockOrderP.*, TPdtOrderPoint-TInMAmouQuantity AS VORPOrderPoint
FROM VS4VStockOrderP
GO

CREATE VIEW VS4VStockP
AS 
SELECT Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtTPTTCode, Vs4VInventStock.TPdtTPPuCode, Vs4VInventStock.TPdtFlag1, Sum(Vs4VInventStock.TInMInQuantity) AS TInMInQuantity, Sum(Vs4VInventStock.TInMOutQuantity) AS TInMOutQuantity, Sum(Vs4VInventStock.TInMAmouQuantity) AS TInMAmouQuantity, Vs4VInventStock.TPdtTUntCode, Sum(Vs4VInventStock.TInMInQuantity2) AS TInMInQuantity2, Sum(Vs4VInventStock.TInMOutQuantity2) AS TInMOutQuantity2, Sum(Vs4VInventStock.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, Sum(Vs4VInventStock.TInMInQuantity3) AS TInMInQuantity3, Sum(Vs4VInventStock.TInMOutQuantity3) AS TInMOutQuantity3, Sum(Vs4VInventStock.TInMAmouQuantity3) AS TInMAmouQuantity3, Vs4VInventStock.TPdtTUntCode3, Sum(Vs4VInventStock.TInMAmount) AS TInMAmount, Avg(Vs4VInventStock.TIMCUnitCost) AS TIMCUnitCost, Vs4VInventStock.TInvTPrjCode, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, Vs4VInventStock.TPdtTPG4Code, Vs4VInventStock.TPdtTPCTAlias, Vs4VInventStock.TIMCUnitCalc, Sum(Vs4VInventStock.TInMQuantityCalc) AS TInMQuantityCalc, Vs4VInventStock.TPrjName, Vs4VInventStock.TPrjMode, Vs4VInventStock.TPdtOrderPoint, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TPdtTAPNCode, Vs4VInventStock.TPdtFactoryCode, Vs4VInventStock.TPOSPackAlias2
FROM Vs4VInventStock
GROUP BY Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtTPTTCode, Vs4VInventStock.TPdtTPPuCode, Vs4VInventStock.TPdtFlag1, Vs4VInventStock.TPdtTUntCode, Vs4VInventStock.TPdtTUntCode2, Vs4VInventStock.TPdtTUntCode3, Vs4VInventStock.TInvTPrjCode, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, Vs4VInventStock.TPdtTPG4Code, Vs4VInventStock.TPdtTPCTAlias, Vs4VInventStock.TIMCUnitCalc, Vs4VInventStock.TPrjName, Vs4VInventStock.TPrjMode, Vs4VInventStock.TPdtOrderPoint, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TPdtTAPNCode, Vs4VInventStock.TPdtFactoryCode, Vs4VInventStock.TPOSPackAlias2
GO

CREATE VIEW VS4VStockPeriod
AS 
SELECT Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtTPTTCode, Vs4VInventStock.TPdtTPPuCode, Vs4VInventStock.TPdtFlag1, Sum(Vs4VInventStock.TInMInQuantity) AS TInMInQuantity, Sum(Vs4VInventStock.TInMOutQuantity) AS TInMOutQuantity, Sum(Vs4VInventStock.TInMAmouQuantity) AS TInMAmouQuantity, Vs4VInventStock.TPdtTUntCode, Sum(Vs4VInventStock.TInMInQuantity2) AS TInMInQuantity2, Sum(Vs4VInventStock.TInMOutQuantity2) AS TInMOutQuantity2, Sum(Vs4VInventStock.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, Sum(Vs4VInventStock.TInMInQuantity3) AS TInMInQuantity3, Sum(Vs4VInventStock.TInMOutQuantity3) AS TInMOutQuantity3, Sum(Vs4VInventStock.TInMAmouQuantity3) AS TInMAmouQuantity3, Vs4VInventStock.TPdtTUntCode3, Sum(Vs4VInventStock.TInMAmount) AS TInMAmount, Avg(Vs4VInventStock.TIMCUnitCost) AS TIMCUnitCost, Vs4VInventStock.TInvDate, Vs4VInventStock.TInMTACPTACYID, Vs4VInventStock.TInMTACPID, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, Vs4VInventStock.TPdtTPG4Code, Vs4VInventStock.TPdtTPCTAlias, Vs4VInventStock.TIMCUnitCalc, Sum(Vs4VInventStock.TInMQuantityCalc) AS TInMQuantityCalc, Vs4VInventStock.TPdtOrderPoint, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TPdtTAPNCode, Vs4VInventStock.TPdtFactoryCode, Vs4VInventStock.TPOSPackAlias2
FROM Vs4VInventStock
GROUP BY Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtTPTTCode, Vs4VInventStock.TPdtTPPuCode, Vs4VInventStock.TPdtFlag1, Vs4VInventStock.TPdtTUntCode, Vs4VInventStock.TPdtTUntCode2, Vs4VInventStock.TPdtTUntCode3, Vs4VInventStock.TInvDate, Vs4VInventStock.TInMTACPTACYID, Vs4VInventStock.TInMTACPID, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, Vs4VInventStock.TPdtTPG4Code, Vs4VInventStock.TPdtTPCTAlias, Vs4VInventStock.TIMCUnitCalc, Vs4VInventStock.TPdtOrderPoint, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TPdtTAPNCode, Vs4VInventStock.TPdtFactoryCode, Vs4VInventStock.TPOSPackAlias2
GO

CREATE VIEW VS4VStockPJ
AS 
SELECT Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtTPTTCode, Vs4VInventStock.TPdtTPPuCode, Vs4VInventStock.TPdtFlag1, Sum(Vs4VInventStock.TInMInQuantity) AS TInMInQuantity, Sum(Vs4VInventStock.TInMOutQuantity) AS TInMOutQuantity, Sum(Vs4VInventStock.TInMAmouQuantity) AS TInMAmouQuantity, Vs4VInventStock.TPdtTUntCode, Sum(Vs4VInventStock.TInMInQuantity2) AS TInMInQuantity2, Sum(Vs4VInventStock.TInMOutQuantity2) AS TInMOutQuantity2, Sum(Vs4VInventStock.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, Sum(Vs4VInventStock.TInMInQuantity3) AS TInMInQuantity3, Sum(Vs4VInventStock.TInMOutQuantity3) AS TInMOutQuantity3, Sum(Vs4VInventStock.TInMAmouQuantity3) AS TInMAmouQuantity3, Vs4VInventStock.TPdtTUntCode3, Sum(Vs4VInventStock.TInMAmount) AS TInMAmount, Avg(Vs4VInventStock.TIMCUnitCost) AS TIMCUnitCost, Vs4VInventStock.TInvTJobNo, Vs4VInventStock.TInvTJbMLn, Vs4VInventStock.TInvTJPdNo, VS4TJob.TJobCode, Vs4VInventStock.TInvTJPMLn, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, Vs4VInventStock.TPdtTPG4Code, Vs4VInventStock.TPdtTPCTAlias, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TIMCUnitCalc, Sum(Vs4VInventStock.TInMQuantityCalc) AS TInMQuantityCalc, Vs4VInventStock.TInvTPrjCode, Vs4VInventStock.TPrjName, Vs4VInventStock.TPrjMode, Vs4VInventStock.TPdtOrderPoint, Vs4VInventStock.TPdtTAPNCode, Vs4VInventStock.TPdtFactoryCode
FROM Vs4VInventStock LEFT JOIN VS4TJob ON Vs4VInventStock.TInvTJobNo = VS4TJob.TJobNo
GROUP BY Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtTPTTCode, Vs4VInventStock.TPdtTPPuCode, Vs4VInventStock.TPdtFlag1, Vs4VInventStock.TPdtTUntCode, Vs4VInventStock.TPdtTUntCode2, Vs4VInventStock.TPdtTUntCode3, Vs4VInventStock.TInvTJobNo, Vs4VInventStock.TInvTJbMLn, Vs4VInventStock.TInvTJPdNo, VS4TJob.TJobCode, Vs4VInventStock.TInvTJPMLn, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, Vs4VInventStock.TPdtTPG4Code, Vs4VInventStock.TPdtTPCTAlias, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TIMCUnitCalc, Vs4VInventStock.TInvTPrjCode, Vs4VInventStock.TPrjName, Vs4VInventStock.TPrjMode, Vs4VInventStock.TPdtOrderPoint, Vs4VInventStock.TPdtTAPNCode, Vs4VInventStock.TPdtFactoryCode
GO

CREATE VIEW VS4VStockPJSo
AS 
SELECT VS4VStockPJ.*, VS4TJobMB.TJbMSourceNo, VS4TJobMB.TJbMSourceLn, VS4TJobMB.TJbMSourceDate, VS4TSO.*
FROM VS4TSO RIGHT JOIN ((VS4VStockPJ LEFT JOIN VS4TJobMB ON (VS4VStockPJ.TInvTJbMLn = VS4TJobMB.TJbMLn) AND (VS4VStockPJ.TInvTJobNo = VS4TJobMB.TJbMTJobNo)) LEFT JOIN VS4TSOMB ON (VS4TJobMB.TJbMSourceNo = VS4TSOMB.TSOBTSODNo) AND (VS4TJobMB.TJbMSourceLn = VS4TSOMB.TSOBLn)) ON VS4TSO.TSODNo = VS4TSOMB.TSOBTSODNo
GO

CREATE VIEW VS4VStockQ
AS 
SELECT Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtTPTTCode, Vs4VInventStock.TPdtTPPuCode, Vs4VInventStock.TPdtFlag1, Sum(Vs4VInventStock.TInMInQuantity) AS TInMInQuantity, Sum(Vs4VInventStock.TInMOutQuantity) AS TInMOutQuantity, Sum(Vs4VInventStock.TInMAmouQuantity) AS TInMAmouQuantity, Vs4VInventStock.TPdtTUntCode, Sum(Vs4VInventStock.TInMInQuantity2) AS TInMInQuantity2, Sum(Vs4VInventStock.TInMOutQuantity2) AS TInMOutQuantity2, Sum(Vs4VInventStock.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, Sum(Vs4VInventStock.TInMInQuantity3) AS TInMInQuantity3, Sum(Vs4VInventStock.TInMOutQuantity3) AS TInMOutQuantity3, Sum(Vs4VInventStock.TInMAmouQuantity3) AS TInMAmouQuantity3, Vs4VInventStock.TPdtTUntCode3, Sum(Vs4VInventStock.TInMAmount) AS TInMAmount, Avg(Vs4VInventStock.TIMCUnitCost) AS TIMCUnitCost, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, Vs4VInventStock.TPdtTPG4Code, Vs4VInventStock.TPdtTPCTAlias, Vs4VInventStock.TPOSPrice, Vs4VInventStock.TPdtOrderPoint, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TPdtTAPNCode, Vs4VInventStock.TPdtFactoryCode, Vs4VInventStock.TIMCUnitCalc
FROM Vs4VInventStock
GROUP BY Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtTPTTCode, Vs4VInventStock.TPdtTPPuCode, Vs4VInventStock.TPdtFlag1, Vs4VInventStock.TPdtTUntCode, Vs4VInventStock.TPdtTUntCode2, Vs4VInventStock.TPdtTUntCode3, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, Vs4VInventStock.TPdtTPG4Code, Vs4VInventStock.TPdtTPCTAlias, Vs4VInventStock.TPOSPrice, Vs4VInventStock.TPdtOrderPoint, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TPdtTAPNCode, Vs4VInventStock.TPdtFactoryCode, Vs4VInventStock.TIMCUnitCalc
GO

CREATE VIEW VS4VStockQA
AS 
SELECT Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtTPTTCode, Vs4VInventStock.TPdtTPPuCode, Vs4VInventStock.TPdtFlag1, Sum(Vs4VInventStock.TInMInQuantity) AS TInMInQuantity, Sum(Vs4VInventStock.TInMOutQuantity) AS TInMOutQuantity, Sum(Vs4VInventStock.TInMAmouQuantity) AS TInMAmouQuantity, Vs4VInventStock.TPdtTUntCode, Sum(Vs4VInventStock.TInMInQuantity2) AS TInMInQuantity2, Sum(Vs4VInventStock.TInMOutQuantity2) AS TInMOutQuantity2, Sum(Vs4VInventStock.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, Sum(Vs4VInventStock.TInMInQuantity3) AS TInMInQuantity3, Sum(Vs4VInventStock.TInMOutQuantity3) AS TInMOutQuantity3, Sum(Vs4VInventStock.TInMAmouQuantity3) AS TInMAmouQuantity3, Vs4VInventStock.TPdtTUntCode3, Sum(Vs4VInventStock.TInMAmount) AS TInMAmount, Avg(Vs4VInventStock.TIMCUnitCost) AS TIMCUnitCost, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, Vs4VInventStock.TPdtTPG4Code, Vs4VInventStock.TPdtTPCTAlias, Vs4VInventStock.TPOSPrice, Vs4VInventStock.TPdtOrderPoint, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TIMCUnitCalc, Sum(Vs4VInventStock.TInMQuantityCalc) AS TInMQuantityCalc, Vs4VInventStock.TPdtTAPNCode, Vs4VInventStock.TPdtFactoryCode, Vs4VInventStock.TPOSPackAlias2
FROM Vs4VInventStock
GROUP BY Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtTPTTCode, Vs4VInventStock.TPdtTPPuCode, Vs4VInventStock.TPdtFlag1, Vs4VInventStock.TPdtTUntCode, Vs4VInventStock.TPdtTUntCode2, Vs4VInventStock.TPdtTUntCode3, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, Vs4VInventStock.TPdtTPG4Code, Vs4VInventStock.TPdtTPCTAlias, Vs4VInventStock.TPOSPrice, Vs4VInventStock.TPdtOrderPoint, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TIMCUnitCalc, Vs4VInventStock.TPdtTAPNCode, Vs4VInventStock.TPdtFactoryCode, Vs4VInventStock.TPOSPackAlias2
GO

CREATE VIEW VS4VStockS
AS 
SELECT VS4VStock.*, TInMAmouQuantity-TPSSReFill AS VSTKOverStock
FROM (VS4VStock LEFT JOIN VS4TProductSafeS ON VS4VStock.TPdtCode = VS4TProductSafeS.TPSSTPdtCode) LEFT JOIN VS4TBranch ON VS4TProductSafeS.TPSSTBraCode = VS4TBranch.TBraCode
WHERE (((VS4TBranch.TBraTBrTAlias)='HEADOFFICE' Or (VS4TBranch.TBraTBrTAlias) Is Null))
GO

CREATE VIEW VS4VStockSaleMonth
AS 
SELECT VS4TProduct.TPdtCode, VS4TInventoryMB.TInMTACPTACYID, VS4TInventoryMB.TInMTACPID, Sum(VS4TInventoryMB.TInMOutQuantity) AS TInMOutQuantity, VS4TProduct.TPdtTUntCode, Sum(VS4TInventoryMB.TInMOutQuantity2) AS TInMOutQuantity2, VS4TProduct.TPdtTUntCode2, Sum(VS4TInventoryMB.TInMOutQuantity3) AS TInMOutQuantity3, VS4TProduct.TPdtTUntCode3, VS4TProduct.TPdtFactoryCode, VS4TProduct.TPdtTAPNCode, VS4TLocation.TLctTBraCode, (TInMTACPTACYID*100+TInMTACPID) AS VSSMPeriod
FROM VS4TProduct INNER JOIN (VS4TInventory INNER JOIN (VS4TInventoryMB LEFT JOIN VS4TLocation ON VS4TInventoryMB.TInMTLctCode = VS4TLocation.TLctCode) ON VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo) ON VS4TProduct.TPdtCode = VS4TInventoryMB.TInMTPdtCode
GROUP BY VS4TProduct.TPdtCode, VS4TInventoryMB.TInMTACPTACYID, VS4TInventoryMB.TInMTACPID, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TProduct.TPdtFactoryCode, VS4TProduct.TPdtTAPNCode, VS4TLocation.TLctTBraCode, VS4TInventory.TInvTInTAlias
HAVING (((VS4TInventory.TInvTInTAlias)='SALEOUT' Or (VS4TInventory.TInvTInTAlias)='SALEOUTPOS'))
GO

CREATE VIEW VS4VStockSumDay
AS 
SELECT VS4TInventory.TInvDate, VS4TInventoryMB.TInMTPdtCode, Sum(VS4TInventoryMB.TInMInQuantity) AS TInMInQuantity, Sum(VS4TInventoryMB.TInMOutQuantity) AS TInMOutQuantity, Sum(VS4TInventoryMB.TInMAmouQuantity) AS TInMAmouQuantity, Min(VS4TInventoryMB.TInMLotDate) AS FirstLotDate, Sum(VS4TInventoryMB.TInMAmount) AS TInMAmount
FROM VS4TInventory INNER JOIN VS4TInventoryMB ON VS4TInventory.TInvNo=VS4TInventoryMB.TInMTInvNo
GROUP BY VS4TInventory.TInvDate, VS4TInventoryMB.TInMTPdtCode, VS4TInventoryMB.TInMStatus, VS4TInventory.TInvApproveStatus, VS4TInventory.TInvCancelStatus
HAVING (((VS4TInventoryMB.TInMStatus)=1) AND ((VS4TInventory.TInvApproveStatus)=1) AND ((VS4TInventory.TInvCancelStatus)<>1))
GO

CREATE VIEW VS4VStockStatistic
AS 
SELECT VS4VStockSumDay.TInMTPdtCode, Count(VS4VStockSumDay.TInvDate) AS VSSTCountDay, Min(VS4VStockSumDay.TInMAmouQuantity) AS VSSTMinQuantity, Max(VS4VStockSumDay.TInMAmouQuantity) AS VSSTMaxQuantity, Sum(VS4VStockSumDay.TInMAmouQuantity) AS TInMAmouQuantity, Avg(VS4VStockSumDay.TInMAmouQuantity) AS VSSTAvgQuantity, Min(VS4VStockSumDay.TInvDate) AS VSSTFirstDate, Max(VS4VStockSumDay.TInvDate) AS VSSTLastMoveDate, Min(VS4VStockSumDay.FirstLotDate) AS VSSTFirstLotDate, VS4TProduct.TPdtSlowDay, VS4TProduct.TPdtDeadDay, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TProduct.TPdtOrderPoint, VS4TProductSafeS.TPSSLeadDay, VS4TProductSafeS.TPSSSafePerDay, VS4TProductSafeS.TPSSSafeTotalDay, VS4TProduct.TPdtEOQ, VS4TProduct.TPdtFirstCostInStk, VS4TProduct.TPdtLastCost, VS4TProduct.TPdtStandardCost, VS4TProduct.TPdtAreaCost, VS4TProduct.TPdtSerialType, Sum(VS4VStockSumDay.TInMAmount) AS TInMAmount, VS4TProduct.TPdtFactoryCode, VS4TProduct.TPdtTAPNCode
FROM (VS4VStockSumDay LEFT JOIN VS4TProduct ON VS4VStockSumDay.TInMTPdtCode = VS4TProduct.TPdtCode) LEFT JOIN (VS4TProductSafeS LEFT JOIN VS4TBranch ON VS4TProductSafeS.TPSSTBraCode = VS4TBranch.TBraCode) ON VS4TProduct.TPdtCode = VS4TProductSafeS.TPSSTPdtCode
GROUP BY VS4VStockSumDay.TInMTPdtCode, VS4TProduct.TPdtSlowDay, VS4TProduct.TPdtDeadDay, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TProduct.TPdtOrderPoint, VS4TProductSafeS.TPSSLeadDay, VS4TProductSafeS.TPSSSafePerDay, VS4TProductSafeS.TPSSSafeTotalDay, VS4TProduct.TPdtEOQ, VS4TProduct.TPdtFirstCostInStk, VS4TProduct.TPdtLastCost, VS4TProduct.TPdtStandardCost, VS4TProduct.TPdtAreaCost, VS4TProduct.TPdtSerialType, VS4TProduct.TPdtFactoryCode, VS4TProduct.TPdtTAPNCode, VS4TProductSafeS.TPSSTBraCode, VS4TBranch.TBraTBrTAlias
HAVING (((VS4TBranch.TBraTBrTAlias)='HEADOFFICE' Or (VS4TBranch.TBraTBrTAlias) Is Null))
GO

CREATE VIEW VS4VStockSumType
AS 
SELECT Vs4VInventStock.TPdtTPTTCode, Vs4VInventStock.TPdtTPPuCode, Vs4VInventStock.TPdtFlag1, Sum(Vs4VInventStock.TInMInQuantity) AS TInMInQuantity, Sum(Vs4VInventStock.TInMOutQuantity) AS TInMOutQuantity, Sum(Vs4VInventStock.TInMAmouQuantity) AS TInMAmouQuantity, Sum(Vs4VInventStock.TInMInQuantity2) AS TInMInQuantity2, Sum(Vs4VInventStock.TInMOutQuantity2) AS TInMOutQuantity2, Sum(Vs4VInventStock.TInMAmouQuantity2) AS TInMAmouQuantity2, Sum(Vs4VInventStock.TInMInQuantity3) AS TInMInQuantity3, Sum(Vs4VInventStock.TInMOutQuantity3) AS TInMOutQuantity3, Sum(Vs4VInventStock.TInMAmouQuantity3) AS TInMAmouQuantity3, Sum(Vs4VInventStock.TInMAmount) AS TInMAmount, Vs4VInventStock.TPdtTPDLCode, VS4TProductLine.TPdLName, VS4TProductType.TPTTName
FROM (Vs4VInventStock LEFT JOIN VS4TProductLine ON Vs4VInventStock.TPdtTPDLCode = VS4TProductLine.TPdLCode) LEFT JOIN VS4TProductType ON Vs4VInventStock.TPdtTPTTCode = VS4TProductType.TPTTCode
GROUP BY Vs4VInventStock.TPdtTPTTCode, Vs4VInventStock.TPdtTPPuCode, Vs4VInventStock.TPdtFlag1, Vs4VInventStock.TPdtTPDLCode, VS4TProductLine.TPdLName, VS4TProductType.TPTTName
GO

CREATE VIEW VS4VStockWH
AS 
SELECT Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtTPTTCode, Vs4VInventStock.TPdtTPPuCode, Vs4VInventStock.TPdtFlag1, Sum(Vs4VInventStock.TInMInQuantity) AS TInMInQuantity, Sum(Vs4VInventStock.TInMOutQuantity) AS TInMOutQuantity, Sum(Vs4VInventStock.TInMAmouQuantity) AS TInMAmouQuantity, Vs4VInventStock.TPdtTUntCode, Sum(Vs4VInventStock.TInMInQuantity2) AS TInMInQuantity2, Sum(Vs4VInventStock.TInMOutQuantity2) AS TInMOutQuantity2, Sum(Vs4VInventStock.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, Sum(Vs4VInventStock.TInMInQuantity3) AS TInMInQuantity3, Sum(Vs4VInventStock.TInMOutQuantity3) AS TInMOutQuantity3, Sum(Vs4VInventStock.TInMAmouQuantity3) AS TInMAmouQuantity3, Vs4VInventStock.TPdtTUntCode3, Sum(Vs4VInventStock.TInMAmount) AS TInMAmount, Avg(Vs4VInventStock.TIMCUnitCost) AS TIMCUnitCost, Vs4VInventStock.TWahCode, Vs4VInventStock.TWahName, Vs4VInventStock.TInMTLctCode, Vs4VInventStock.TLctName, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, Vs4VInventStock.TPdtTPG4Code, Vs4VInventStock.TPdtTPCTAlias, Vs4VInventStock.TPOSPrice, Vs4VInventStock.TLctDayAlert, Vs4VInventStock.TLctDayMove, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TIMCUnitCalc, Sum(Vs4VInventStock.TInMQuantityCalc) AS TInMQuantityCalc, Vs4VInventStock.TPdtOrderPoint, Vs4VInventStock.TPdtTAPNCode, Vs4VInventStock.TLctTBraCode, Vs4VInventStock.TPdtFactoryCode
FROM Vs4VInventStock
GROUP BY Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtTPTTCode, Vs4VInventStock.TPdtTPPuCode, Vs4VInventStock.TPdtFlag1, Vs4VInventStock.TPdtTUntCode, Vs4VInventStock.TPdtTUntCode2, Vs4VInventStock.TPdtTUntCode3, Vs4VInventStock.TWahCode, Vs4VInventStock.TWahName, Vs4VInventStock.TInMTLctCode, Vs4VInventStock.TLctName, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, Vs4VInventStock.TPdtTPG4Code, Vs4VInventStock.TPdtTPCTAlias, Vs4VInventStock.TPOSPrice, Vs4VInventStock.TLctDayAlert, Vs4VInventStock.TLctDayMove, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TIMCUnitCalc, Vs4VInventStock.TPdtOrderPoint, Vs4VInventStock.TPdtTAPNCode, Vs4VInventStock.TLctTBraCode, Vs4VInventStock.TPdtFactoryCode
GO

CREATE VIEW VS4VStockWHCD
AS 
SELECT Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtTPTTCode, Vs4VInventStock.TPdtTPPuCode, Vs4VInventStock.TPdtFlag1, Sum(Vs4VInventStock.TInMInQuantity) AS TInMInQuantity, Sum(Vs4VInventStock.TInMOutQuantity) AS TInMOutQuantity, Sum(Vs4VInventStock.TInMAmouQuantity) AS TInMAmouQuantity, Vs4VInventStock.TPdtTUntCode, Sum(Vs4VInventStock.TInMInQuantity2) AS TInMInQuantity2, Sum(Vs4VInventStock.TInMOutQuantity2) AS TInMOutQuantity2, Sum(Vs4VInventStock.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, Sum(Vs4VInventStock.TInMInQuantity3) AS TInMInQuantity3, Sum(Vs4VInventStock.TInMOutQuantity3) AS TInMOutQuantity3, Sum(Vs4VInventStock.TInMAmouQuantity3) AS TInMAmouQuantity3, Vs4VInventStock.TPdtTUntCode3, Sum(Vs4VInventStock.TInMAmount) AS TInMAmount, Avg(Vs4VInventStock.TIMCUnitCost) AS TIMCUnitCost, Vs4VInventStock.TWahCode, Vs4VInventStock.TWahName, Vs4VInventStock.TInMTLctCode, Vs4VInventStock.TLctName, Vs4VInventStock.TInMLotDate, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, Vs4VInventStock.TPdtTPG4Code, Vs4VInventStock.TPdtTPCTAlias, Vs4VInventStock.TIMCUnitCalc, Sum(Vs4VInventStock.TInMQuantityCalc) AS TInMQuantityCalc, Vs4VInventStock.TLctDayAlert, Vs4VInventStock.TLctDayMove, Vs4VInventStock.TPdtOrderPoint, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TLctTBraCode, Vs4VInventStock.TPdtTAPNCode, Vs4VInventStock.TPdtFactoryCode, Vs4VInventStock.TInMLotNo
FROM Vs4VInventStock
GROUP BY Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtTPTTCode, Vs4VInventStock.TPdtTPPuCode, Vs4VInventStock.TPdtFlag1, Vs4VInventStock.TPdtTUntCode, Vs4VInventStock.TPdtTUntCode2, Vs4VInventStock.TPdtTUntCode3, Vs4VInventStock.TWahCode, Vs4VInventStock.TWahName, Vs4VInventStock.TInMTLctCode, Vs4VInventStock.TLctName, Vs4VInventStock.TInMLotDate, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, Vs4VInventStock.TPdtTPG4Code, Vs4VInventStock.TPdtTPCTAlias, Vs4VInventStock.TIMCUnitCalc, Vs4VInventStock.TLctDayAlert, Vs4VInventStock.TLctDayMove, Vs4VInventStock.TPdtOrderPoint, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TLctTBraCode, Vs4VInventStock.TPdtTAPNCode, Vs4VInventStock.TPdtFactoryCode, Vs4VInventStock.TInMLotNo
GO

CREATE VIEW VS4VStockWHG
AS 
SELECT Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtTPTTCode, Vs4VInventStock.TPdtTPPuCode, Vs4VInventStock.TPdtFlag1, Sum(Vs4VInventStock.TInMInQuantity) AS TInMInQuantity, Sum(Vs4VInventStock.TInMOutQuantity) AS TInMOutQuantity, Sum(Vs4VInventStock.TInMAmouQuantity) AS TInMAmouQuantity, Vs4VInventStock.TPdtTUntCode, Sum(Vs4VInventStock.TInMInQuantity2) AS TInMInQuantity2, Sum(Vs4VInventStock.TInMOutQuantity2) AS TInMOutQuantity2, Sum(Vs4VInventStock.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, Sum(Vs4VInventStock.TInMInQuantity3) AS TInMInQuantity3, Sum(Vs4VInventStock.TInMOutQuantity3) AS TInMOutQuantity3, Sum(Vs4VInventStock.TInMAmouQuantity3) AS TInMAmouQuantity3, Vs4VInventStock.TPdtTUntCode3, Sum(Vs4VInventStock.TInMAmount) AS TInMAmount, Vs4VInventStock.TIMCUnitCost, Vs4VInventStock.TWahCode, Vs4VInventStock.TWahName, Vs4VInventStock.TInMTLctCode, Vs4VInventStock.TLctName, Vs4VInventStock.TIMCGrade, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, Vs4VInventStock.TPdtTPG4Code, Vs4VInventStock.TPdtTPCTAlias, Vs4VInventStock.TIMCUnitCalc, Sum(Vs4VInventStock.TInMQuantityCalc) AS TInMQuantityCalc, Vs4VInventStock.TLctDayAlert, Vs4VInventStock.TLctDayMove, Vs4VInventStock.TPdtOrderPoint, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TLctTBraCode
FROM Vs4VInventStock
GROUP BY Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtTPTTCode, Vs4VInventStock.TPdtTPPuCode, Vs4VInventStock.TPdtFlag1, Vs4VInventStock.TPdtTUntCode, Vs4VInventStock.TPdtTUntCode2, Vs4VInventStock.TPdtTUntCode3, Vs4VInventStock.TIMCUnitCost, Vs4VInventStock.TWahCode, Vs4VInventStock.TWahName, Vs4VInventStock.TInMTLctCode, Vs4VInventStock.TLctName, Vs4VInventStock.TIMCGrade, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, Vs4VInventStock.TPdtTPG4Code, Vs4VInventStock.TPdtTPCTAlias, Vs4VInventStock.TIMCUnitCalc, Vs4VInventStock.TLctDayAlert, Vs4VInventStock.TLctDayMove, Vs4VInventStock.TPdtOrderPoint, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TLctTBraCode
GO

CREATE VIEW VS4VStockWHQ
AS 
SELECT Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtTPTTCode, Vs4VInventStock.TPdtTPPuCode, Vs4VInventStock.TPdtFlag1, Sum(Vs4VInventStock.TInMInQuantity) AS TInMInQuantity, Sum(Vs4VInventStock.TInMOutQuantity) AS TInMOutQuantity, Sum(Vs4VInventStock.TInMAmouQuantity) AS TInMAmouQuantity, Vs4VInventStock.TPdtTUntCode, Sum(Vs4VInventStock.TInMInQuantity2) AS TInMInQuantity2, Sum(Vs4VInventStock.TInMOutQuantity2) AS TInMOutQuantity2, Sum(Vs4VInventStock.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, Sum(Vs4VInventStock.TInMInQuantity3) AS TInMInQuantity3, Sum(Vs4VInventStock.TInMOutQuantity3) AS TInMOutQuantity3, Sum(Vs4VInventStock.TInMAmouQuantity3) AS TInMAmouQuantity3, Vs4VInventStock.TPdtTUntCode3, Sum(Vs4VInventStock.TInMAmount) AS TInMAmount, Avg(Vs4VInventStock.TIMCUnitCost) AS TIMCUnitCost, Vs4VInventStock.TWahCode, Vs4VInventStock.TWahName, Vs4VInventStock.TInMTLctCode, Vs4VInventStock.TLctName, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, Vs4VInventStock.TPdtTPG4Code, Vs4VInventStock.TPdtTPCTAlias, Vs4VInventStock.TPOSPrice, Vs4VInventStock.TLctDayAlert, Vs4VInventStock.TLctDayMove, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TPdtOrderPoint, Vs4VInventStock.TLctTBraCode
FROM Vs4VInventStock
GROUP BY Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtTPTTCode, Vs4VInventStock.TPdtTPPuCode, Vs4VInventStock.TPdtFlag1, Vs4VInventStock.TPdtTUntCode, Vs4VInventStock.TPdtTUntCode2, Vs4VInventStock.TPdtTUntCode3, Vs4VInventStock.TWahCode, Vs4VInventStock.TWahName, Vs4VInventStock.TInMTLctCode, Vs4VInventStock.TLctName, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, Vs4VInventStock.TPdtTPG4Code, Vs4VInventStock.TPdtTPCTAlias, Vs4VInventStock.TPOSPrice, Vs4VInventStock.TLctDayAlert, Vs4VInventStock.TLctDayMove, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TPdtOrderPoint, Vs4VInventStock.TLctTBraCode
GO

CREATE VIEW VS4VSumBackDayCalc
AS 
SELECT VS4VStockSaleMonth.TLctTBraCode, VS4VStockSaleMonth.TInMOutQuantity, VS4VStockSaleMonth.VSSMPeriod
FROM VS4VStockSaleMonth
WHERE (((VS4VStockSaleMonth.TPdtCode)='11010') And ((VS4VStockSaleMonth.VSSMPeriod)>=200701 And (VS4VStockSaleMonth.VSSMPeriod)<=200712))
GO

CREATE VIEW VS4VSumProduct
AS 
SELECT Year(TPODDate) AS TPODDate, VS4TPODelivery.TPDEProductCode, Sum(VS4TPODelivery.TPDETotalArrear) AS TPDETotalArrear, Sum(VS4TPOMB.TPOBQuantity) AS TPOBQuantity, Sum(VS4TPOMB.TPOBNetAmount) AS TPOBNetAmount, VS4TPOMB.TPOBTPdtCode, VS4TProductRelate.TPdRTPdtCode, VS4TProductRelate.TPdRTPdtCode2, VS4TProductRelate.TPdRRelateType
FROM VS4TPO INNER JOIN ((VS4TPOMB INNER JOIN VS4TPODelivery ON (VS4TPOMB.TPOBLn=VS4TPODelivery.TPDETPOBLn) AND (VS4TPOMB.TPOBTPODNo=VS4TPODelivery.TPDETPOBTPODNo)) LEFT JOIN VS4TProductRelate ON VS4TPODelivery.TPDEProductCode=VS4TProductRelate.TPdRTPdtCode) ON VS4TPO.TPODNo=VS4TPOMB.TPOBTPODNo
GROUP BY Year(TPODDate), VS4TPODelivery.TPDEProductCode, VS4TPOMB.TPOBTPdtCode, VS4TProductRelate.TPdRTPdtCode, VS4TProductRelate.TPdRTPdtCode2, VS4TProductRelate.TPdRRelateType
GO

CREATE VIEW VS4VSwitchTime
AS 
SELECT VS4TSwitchTime.*, VS4TSwitchTimeMB.*, VS4TEmployee.*, VS4TEmpWorkPeriod.*, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TEmployeeType.TEmTName, VS4TSection.TSecName
FROM VS4TSwitchTime INNER JOIN (VS4TEmpWorkPeriod INNER JOIN ((VS4TEmployeeType RIGHT JOIN (VS4TDivision RIGHT JOIN (VS4TBranch RIGHT JOIN (VS4TSection RIGHT JOIN (VS4TDepartment RIGHT JOIN VS4TEmployee ON VS4TDepartment.TDepCode = VS4TEmployee.TEmpTDepCode) ON VS4TSection.TSecCode = VS4TEmployee.TEmpTSecCode) ON VS4TBranch.TBraCode = VS4TEmployee.TEmpTBraCode) ON VS4TDivision.TDivCode = VS4TEmployee.TEmpTDivCode) ON VS4TEmployeeType.TEmTCode = VS4TEmployee.TEmpTEmTCode) INNER JOIN VS4TSwitchTimeMB ON VS4TEmployee.TEmpCode = VS4TSwitchTimeMB.TSTMTEmpCode) ON VS4TEmpWorkPeriod.TWPDCode = VS4TEmployee.TEmpTWPDCode) ON VS4TSwitchTime.TSwTNo = VS4TSwitchTimeMB.TSTMTSWTNo
GO

CREATE VIEW VS4VTaxRate
AS 
SELECT VS4TTax.*, VS4TTaxRate.*
FROM VS4TTax INNER JOIN VS4TTaxRate ON VS4TTax.TTaxAlias = VS4TTaxRate.TTxRTTaxAlias
GO

CREATE VIEW VS4VTeasuryNetA
AS 
SELECT VS4TCompanyBank.TCBBNo, Sum(VS4TTeasuryTransMB.TTTMMoneyRate) AS TTTMMoneyRate, Sum(VS4TTeasuryTransMB.TTTMAdjustTotal) AS TTTMAdjustTotal, Sum(VS4TTeasuryTransMB.TTTMFee) AS TTTMFee, Sum(VS4TTeasuryTransMB.TTTMNetTotal) AS TTTMNetTotal, Sum(VS4TTeasuryTransMB.TTTMMoneyInCard) AS TTTMMoneyInCard, Sum(VS4TTeasuryTransMB.TTTMMoneyInCheque) AS TTTMMoneyInCheque, Sum(VS4TTeasuryTransMB.TTTMMoneyOutCheque) AS TTTMMoneyOutCheque, Sum(VS4TTeasuryTransMB.TTTMMoneyIn) AS TTTMMoneyIn, Sum(VS4TTeasuryTransMB.TTTMMoneyOut) AS TTTMMoneyOut, Sum(VS4TTeasuryTransMB.TTTMMoneyAmount) AS TTTMMoneyAmount, Sum(VS4TTeasuryTransMB.TTTMMoneyNet) AS TTTMMoneyNet, Sum(VS4TTeasuryTransMB.TTTMMoneyNetSafe) AS TTTMMoneyNetSafe, VS4TCompanyBank.TCBBName, VS4TCompanyBank.TCBBTBraCode, VS4TCompanyBank.TCBBTBnkCode, VS4TCompanyBank.TCBBAccountType, VS4TCompanyBank.TCBBAccountName, VS4TCompanyBank.TCBBAccountNo, VS4TCompanyBank.TCBBAccountBranch, VS4TCompanyBank.TCBBTACCCode, VS4TBank.TBnkVirtual, VS4TBank.TBnkName, VS4TCompanyBank.TCBBCreditLimit
FROM VS4TTeasuryTrans INNER JOIN ((VS4TBank INNER JOIN VS4TCompanyBank ON VS4TBank.TBnkCode=VS4TCompanyBank.TCBBTBnkCode) INNER JOIN VS4TTeasuryTransMB ON VS4TCompanyBank.TCBBNo=VS4TTeasuryTransMB.TTTMToTCBBNo) ON VS4TTeasuryTrans.TTeTNo=VS4TTeasuryTransMB.TTTMTTeTNo
GROUP BY VS4TCompanyBank.TCBBNo, VS4TCompanyBank.TCBBName, VS4TCompanyBank.TCBBTBraCode, VS4TCompanyBank.TCBBTBnkCode, VS4TCompanyBank.TCBBAccountType, VS4TCompanyBank.TCBBAccountName, VS4TCompanyBank.TCBBAccountNo, VS4TCompanyBank.TCBBAccountBranch, VS4TCompanyBank.TCBBTACCCode, VS4TBank.TBnkVirtual, VS4TBank.TBnkName, VS4TCompanyBank.TCBBCreditLimit, VS4TTeasuryTrans.TTeTApproveStatus, VS4TTeasuryTrans.TTeTCancelStatus, VS4TTeasuryTransMB.TTTMStatus
HAVING (((VS4TTeasuryTrans.TTeTApproveStatus)=1) AND ((VS4TTeasuryTrans.TTeTCancelStatus)=0) AND ((VS4TTeasuryTransMB.TTTMStatus)=1))
GO

CREATE VIEW VS4VTeasuryNet
AS 
SELECT VS4VTeasuryNetA.*, TTTMMoneyNetSafe+TCBBCreditLimit AS VTTMMoneyNetOD
FROM VS4VTeasuryNetA
GO

CREATE VIEW VS4VTeasuryTo
AS 
SELECT VS4TTeasuryTrans.*, VS4TCompanyBank.*, VS4TBranch.*, VS4TBank.*
FROM VS4TBranch RIGHT JOIN (VS4TBank RIGHT JOIN (VS4TTeasuryTrans LEFT JOIN VS4TCompanyBank ON VS4TTeasuryTrans.TTeTRefNo=VS4TCompanyBank.TCBBNo) ON VS4TBank.TBnkCode=VS4TCompanyBank.TCBBTBnkCode) ON VS4TBranch.TBraCode=VS4TCompanyBank.TCBBTBraCode
WHERE (((VS4TTeasuryTrans.TTeTType)=12 Or (VS4TTeasuryTrans.TTeTType)=15))
GO

CREATE VIEW VS4VTeasuryTrans
AS 
SELECT VS4TTeasuryTrans.*, VS4TTeasuryTransMB.*, VS4TCompanyBank.*, VS4TBranch.*, VS4TBank.*, VS4TTeasuryMove.*
FROM VS4TTeasuryTrans INNER JOIN ((VS4TBranch INNER JOIN (VS4TBank INNER JOIN VS4TCompanyBank ON VS4TBank.TBnkCode=VS4TCompanyBank.TCBBTBnkCode) ON VS4TBranch.TBraCode=VS4TCompanyBank.TCBBTBraCode) INNER JOIN (VS4TTeasuryTransMB LEFT JOIN VS4TTeasuryMove ON (VS4TTeasuryTransMB.TTTMTACPTACYID=VS4TTeasuryMove.TTYMTACPTACYID) AND (VS4TTeasuryTransMB.TTTMTACPID=VS4TTeasuryMove.TTYMTACPID) AND (VS4TTeasuryTransMB.TTTMToTCBBNo=VS4TTeasuryMove.TTYMTCBBNo)) ON VS4TCompanyBank.TCBBNo=VS4TTeasuryTransMB.TTTMToTCBBNo) ON VS4TTeasuryTrans.TTeTNo=VS4TTeasuryTransMB.TTTMTTeTNo
GO

CREATE VIEW VS4VMoneyNet
AS 
SELECT VS4VTeasuryTransA.TTTMMoneyRate
FROM VS4VTeasuryTransA
GO

CREATE VIEW VS4VTimeInput
AS 
SELECT VS4TTimeInput.*, VS4TEmployee.*, VS4TPosition.*, VS4TDivision.*, VS4TTimeInputNote.TTINNote
FROM (VS4TPosition RIGHT JOIN (VS4TDivision RIGHT JOIN (VS4TTimeInput LEFT JOIN VS4TEmployee ON VS4TTimeInput.TTIPCode = VS4TEmployee.TEmpCode) ON VS4TDivision.TDivCode = VS4TEmployee.TEmpTDivCode) ON VS4TPosition.TPstCode = VS4TEmployee.TEmpTPstCode) LEFT JOIN VS4TTimeInputNote ON VS4TTimeInput.TTIPID = VS4TTimeInputNote.TTINTTIPID
GO

CREATE VIEW VS4VTimeRecord
AS 
SELECT VS4TEmpTimeChk.*, VS4TEmpTimeChkMB.*, VS4TEmployee.*, VS4TSection.TSecName, VS4TDepartment.TDepName, VS4TDivision.TDivCode, VS4TDivision.TDivName, VS4TDivision.TDivName2, VS4TDivision.TDivLevel, VS4TPosition.TPstName, VS4TPosition.TPstName2
FROM VS4TPosition RIGHT JOIN (((VS4TDivision RIGHT JOIN ((VS4TEmployee LEFT JOIN VS4TSection ON VS4TEmployee.TEmpTSecCode=VS4TSection.TSecCode) LEFT JOIN VS4TDepartment ON VS4TEmployee.TEmpTDepCode=VS4TDepartment.TDepCode) ON VS4TDivision.TDivCode=VS4TEmployee.TEmpTDivCode) INNER JOIN VS4TEmpTimeChk ON VS4TEmployee.TEmpCode=VS4TEmpTimeChk.TEtcTEmpCode) INNER JOIN VS4TEmpTimeChkMB ON VS4TEmpTimeChk.TEtcNo=VS4TEmpTimeChkMB.TTCKTEtcNo) ON VS4TPosition.TPstCode=VS4TEmployee.TEmpTPstCode
GO

CREATE VIEW VS4VTmpSelectSet
AS 
SELECT VS4TTmpSelectSet.*, VS4TTmpSelectSetMB.*
FROM VS4TTmpSelectSet INNER JOIN VS4TTmpSelectSetMB ON VS4TTmpSelectSet.TTSSID=VS4TTmpSelectSetMB.TTSMTSSID
GO

CREATE VIEW VS4VTR
AS 
SELECT VS4TTR.*, VS4TTRMB.*, VS4TInventBook.*, VS4TProduct.*, VS4TWarehouse.*, VS4TLocation.*, VS4TBranch.TBraName, VS4TAP.TAPNName
FROM (VS4TInventBook INNER JOIN (((VS4TTR LEFT JOIN VS4TLocation ON VS4TTR.TTRDTLctCode = VS4TLocation.TLctCode) LEFT JOIN VS4TBranch ON VS4TTR.TTRDTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TWarehouse ON VS4TLocation.TLctTWahCode = VS4TWarehouse.TWahCode) ON VS4TInventBook.TIBkCode = VS4TTR.TTRDTIBKCode) INNER JOIN ((VS4TProduct LEFT JOIN VS4TAP ON VS4TProduct.TPdtTAPNCode = VS4TAP.TAPNCode) INNER JOIN VS4TTRMB ON VS4TProduct.TPdtCode = VS4TTRMB.TTRMTPdtCode) ON VS4TTR.TTRDNo = VS4TTRMB.TTRMTTRDNo
GO

CREATE VIEW VS4VTR2PO
AS 
SELECT VS4TTR.*, VS4TTRMB.*, VS4TPO.TPODNo, VS4TPO.TPODType, VS4TPO.TPODDate, VS4TPO.TPODDueDate, VS4TPO.TPODDeliveryDate, VS4TPO.TPODDeliveryTo, VS4TPO.TPODTAPNCode, VS4TPO.TPODSupplierName, VS4TPOMB.*, VS4TPO.TPODCountryOrigin, VS4TCountry.TCouName, VS4TPO.TPODTPrjCode, VS4TProject.TPrjName, VS4TProject.TPrjMode, VS4TPO.TPODTBraCode, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TAP.TAPNTBsTCode, VS4TBusinessType.TBstName, VS4TProduct.TPdtTPTTCode, VS4TProductType.TPTTName, VS4TProduct.TPdtTPDLCode, VS4TProductLine.TPdLName, VS4TProduct.TPdtTPSECode, VS4TProductSection.TPSEName, VS4TProduct.TPdtTPG1Code, VS4TProductGroup1.TPG1Name, VS4TPO.TPODApproveStatus, VS4TPO.TPODConfirmStatus, VS4TPO.TPODCancelStatus, VS4TAP.TAPNTAPGCode, VS4TAPGroup.TAPGName, VS4TProduct2.TPd2ScrapPCMRP, VS4TProduct2.TPd2ScrapPCReceive, VS4TProduct2.TPd2ScrapPCSend, VS4TProduct2.TPd2TaxRate, VS4TProduct2.TPd2CostFormula, VS4TPODelivery.TPDETPOBTPODNo, VS4TPODelivery.TPDETPOBLn, VS4TPODelivery.TPDELn, VS4TPODelivery.TPDEDate, VS4TPODelivery.TPDEDateTime, VS4TPODelivery.TPDEQuantity, VS4TPODelivery.TPDEQuantity2, VS4TPODelivery.TPDEQuantity3, VS4TPODelivery.TPDETotalDelivery, VS4TPODelivery.TPDETotalDelivery2, VS4TPODelivery.TPDETotalDelivery3, VS4TPODelivery.TPDETotalArrear, VS4TPODelivery.TPDETotalArrear2, VS4TPODelivery.TPDETotalArrear3, VS4TPODelivery.TPDEMapTPdtCode, VS4TPODelivery.TPDEMapTUntCode, VS4TPODelivery.TPDEMapUnitRatio, VS4TPODelivery.TPDEQuantityBase, VS4TPODelivery.TPDEDeliveryBase, VS4TPODelivery.TPDEArrearBase, VS4TPODelivery.TPDELinkStatus, VS4TPODelivery.TPDELinkBy, VS4TPODelivery.TPDELinkDate, VS4TPODelivery.TPDETotalOntime, VS4TPODelivery.TPDETotalDelay, VS4TPODelivery.TPDETLctCode, VS4TPR.TPRDNo, VS4TPR.TPRDDate, VS4TPR.TPRDApproveStatus, VS4TPR.TPRDApproveDate, VS4TPR.TPRDCancelStatus, VS4TPR.TPRDRequestCode, VS4TPR.TPRDRequestBy, VS4TPR.TPRDTPrjCode, VS4TPR.TPRDTSecCode, VS4TPR.TPRDTDepCode, VS4TPR.TPRDTDivCode, VS4TPR.TPRDType, VS4TPR.TPRDTPRBCode, VS4TWarehouse.TWahCode, VS4TProduct.TPdtName, VS4TProduct.TPdtName2
FROM VS4TWarehouse RIGHT JOIN ((VS4TTR LEFT JOIN VS4TLocation ON VS4TTR.TTRDTLctCode = VS4TLocation.TLctCode) INNER JOIN ((((VS4TPR LEFT JOIN VS4TDepartment ON VS4TPR.TPRDTDepCode = VS4TDepartment.TDepCode) LEFT JOIN VS4TDivision ON VS4TPR.TPRDTDivCode = VS4TDivision.TDivCode) LEFT JOIN VS4TSection ON VS4TPR.TPRDTSecCode = VS4TSection.TSecCode) RIGHT JOIN (((((((VS4TPO LEFT JOIN VS4TCountry ON VS4TPO.TPODCountryOrigin = VS4TCountry.TCouCode) LEFT JOIN VS4TProject ON VS4TPO.TPODTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TPO.TPODTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TAP ON VS4TPO.TPODTAPNCode = VS4TAP.TAPNCode) LEFT JOIN VS4TBusinessType ON VS4TAP.TAPNTBsTCode = VS4TBusinessType.TBsTCode) LEFT JOIN VS4TAPGroup ON VS4TAP.TAPNTAPGCode = VS4TAPGroup.TAPGCode) RIGHT JOIN ((((((VS4TProduct LEFT JOIN VS4TProductType ON VS4TProduct.TPdtTPTTCode = VS4TProductType.TPTTCode) LEFT JOIN VS4TProductLine ON VS4TProduct.TPdtTPDLCode = VS4TProductLine.TPdLCode) LEFT JOIN VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode) LEFT JOIN VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code) LEFT JOIN VS4TProduct2 ON VS4TProduct.TPdtCode = VS4TProduct2.TPd2TPdtCode) INNER JOIN (VS4TTRMB LEFT JOIN ((VS4TPRMB LEFT JOIN VS4TPOMB ON (VS4TPRMB.TPRMTPRDNo = VS4TPOMB.TPOBSourceNo) AND (VS4TPRMB.TPRMLn = VS4TPOMB.TPOBSourceLn)) LEFT JOIN VS4TPODelivery ON (VS4TPOMB.TPOBTPODNo = VS4TPODelivery.TPDETPOBTPODNo) AND (VS4TPOMB.TPOBLn = VS4TPODelivery.TPDETPOBLn)) ON VS4TTRMB.TTRMTPdtCode = VS4TPRMB.TPRMTPdtCode) ON VS4TProduct.TPdtCode = VS4TTRMB.TTRMTPdtCode) ON VS4TPO.TPODNo = VS4TPOMB.TPOBTPODNo) ON VS4TPR.TPRDNo = VS4TPRMB.TPRMTPRDNo) ON VS4TTR.TTRDNo = VS4TTRMB.TTRMTTRDNo) ON VS4TWarehouse.TWahCode = VS4TLocation.TLctTWahCode
GO

CREATE VIEW VS4VTrainingCourse
AS 
SELECT VS4TTrainingCourse.*, VS4TTrainingGroup.*
FROM VS4TTrainingGroup INNER JOIN VS4TTrainingCourse ON VS4TTrainingGroup.TTrGCode = VS4TTrainingCourse.TTrCTTrGCode
GO

CREATE VIEW VS4VTRH
AS 
SELECT VS4TTR.*, VS4TInventBook.*, VS4TWarehouse.*, VS4TLocation.*, VS4TBranch.TBraName
FROM VS4TInventBook INNER JOIN (((VS4TTR LEFT JOIN VS4TLocation ON VS4TTR.TTRDTLctCode=VS4TLocation.TLctCode) LEFT JOIN VS4TBranch ON VS4TTR.TTRDTBraCode=VS4TBranch.TBraCode) LEFT JOIN VS4TWarehouse ON VS4TLocation.TLctTWahCode=VS4TWarehouse.TWahCode) ON VS4TInventBook.TIBkCode=VS4TTR.TTRDTIBKCode
GO

CREATE VIEW VS4VTRStockFull
AS 
SELECT VS4TTR.*, VS4TTRMB.*, VS4TInventBook.*, VS4TBranch.TBraName, VS4VStockFULL.*
FROM (VS4TInventBook INNER JOIN (VS4TTR LEFT JOIN VS4TBranch ON VS4TTR.TTRDTBraCode = VS4TBranch.TBraCode) ON VS4TInventBook.TIBkCode = VS4TTR.TTRDTIBKCode) INNER JOIN (VS4TTRMB INNER JOIN VS4VStockFULL ON VS4TTRMB.TTRMTPdtCode = VS4VStockFULL.TPdtCode) ON VS4TTR.TTRDNo = VS4TTRMB.TTRMTTRDNo
GO

CREATE VIEW VS4VUnit
AS 
SELECT VS4TUnit.*, VS4TUnitGroup.*
FROM VS4TUnitGroup INNER JOIN VS4TUnit ON VS4TUnitGroup.TUnGAlias=VS4TUnit.TUntTUnGAlias
GO

CREATE VIEW VS4VUnit1
AS 
SELECT VS4TUnit.TUntCode AS VUn1Code, VS4TUnit.TUntName AS VUn1Name, VS4TUnit.TUntName2 AS VUn1Name2, VS4TUnit.TUntMultiCode AS VUn1MultiCode, VS4TUnit.TUntMultiCode2 AS VUn1MultiCode2
FROM VS4TUnit
GO

CREATE VIEW VS4VUnit2
AS 
SELECT VS4TUnit.TUntCode AS VUn2Code, VS4TUnit.TUntName AS VUn2Name, VS4TUnit.TUntName2 AS VUn2Name2, VS4TUnit.TUntMultiCode AS VUn2MultiCode, VS4TUnit.TUntMultiCode2 AS VUn2MultiCode2
FROM VS4TUnit
GO

CREATE VIEW VS4VUnit3
AS 
SELECT VS4TUnit.TUntCode AS VUn3Code, VS4TUnit.TUntName AS VUn3Name, VS4TUnit.TUntName2 AS VUn3Name2, VS4TUnit.TUntMultiCode AS VUn3MultiCode, VS4TUnit.TUntMultiCode2 AS VUn3MultiCode2
FROM VS4TUnit
GO

CREATE VIEW VS4VUser
AS 
SELECT VS4TUser.*, VS4TEmployee.*
FROM VS4TUser LEFT JOIN (VS4TEmployee RIGHT JOIN VS4TUserEmployee ON VS4TEmployee.TEmpCode = VS4TUserEmployee.TUsETEmpCode) ON VS4TUser.TUsrID = VS4TUserEmployee.TUsETUsrID
GO

CREATE VIEW VS4VUserAlert
AS 
SELECT VS4TUserAlert.*, VS4TCommand.*, VS4TUser.*, VS4TUserEmployee.*, VS4TEmployee.*, VS4TCommandGroup.*
FROM (VS4TUser INNER JOIN ((VS4TCommandGroup RIGHT JOIN VS4TCommand ON VS4TCommandGroup.TCmGAlias = VS4TCommand.TCmdTCmGAlias) INNER JOIN VS4TUserAlert ON VS4TCommand.TCmdID = VS4TUserAlert.TUsATCmdID) ON VS4TUser.TUsrID = VS4TUserAlert.TUsATUsrID) LEFT JOIN (VS4TEmployee RIGHT JOIN VS4TUserEmployee ON VS4TEmployee.TEmpCode = VS4TUserEmployee.TUsETEmpCode) ON VS4TUser.TUsrID = VS4TUserEmployee.TUsETUsrID
GO

CREATE VIEW VS4VUserBranch
AS 
SELECT VS4TUserBranch.*, VS4TBranch.*, VS4TUser.*, VS4TCommandGroup.*
FROM VS4TUser INNER JOIN (VS4TBranch INNER JOIN (VS4TUserBranch LEFT JOIN VS4TCommandGroup ON VS4TUserBranch.TUsBTCmGAlias = VS4TCommandGroup.TCmGAlias) ON VS4TBranch.TBraCode = VS4TUserBranch.TUsBTBraCode) ON VS4TUser.TUsrID = VS4TUserBranch.TUsBTUsrID
GO

CREATE VIEW VS4VUserPermiss
AS 
SELECT VS4TUserPermiss.*, VS4TUser.*, VS4TCommand.*, VS4TCommandGroup.*, VS4TEmployee.TEmpFullName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName
FROM (VS4TUser LEFT JOIN ((VS4TDivision RIGHT JOIN ((VS4TEmployee LEFT JOIN VS4TDepartment ON VS4TEmployee.TEmpTDepCode = VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TEmployee.TEmpTSecCode = VS4TSection.TSecCode) ON VS4TDivision.TDivCode = VS4TEmployee.TEmpTDivCode) RIGHT JOIN VS4TUserEmployee ON VS4TEmployee.TEmpCode = VS4TUserEmployee.TUsETEmpCode) ON VS4TUser.TUsrID = VS4TUserEmployee.TUsETUsrID) INNER JOIN (VS4TCommandGroup RIGHT JOIN (VS4TUserPermiss LEFT JOIN VS4TCommand ON VS4TUserPermiss.TUsPTCmdID = VS4TCommand.TCmdID) ON VS4TCommandGroup.TCmGAlias = VS4TCommand.TCmdTCmGAlias) ON VS4TUser.TUsrID = VS4TUserPermiss.TUsPTUsrID
GO

CREATE VIEW VS4VVATMovement
AS 
SELECT VS4TTaxTrans.*
FROM VS4TTaxTrans
WHERE (((VS4TTaxTrans.TTxTType)=0) AND ((VS4TTaxTrans.TTxTDefaultTax)=1)) OR (((VS4TTaxTrans.TTxTType)=1))
GO

CREATE VIEW VS4VVATBalance
AS 
SELECT Sum(VS4VVATMovement.TTxTSignTaxAmount) AS TTxTSignTaxAmount
FROM VS4VVATMovement
GO

CREATE VIEW VS4VVehicle
AS 
SELECT VS4TVehicle.*, VS4TVehicleType.*
FROM VS4TVehicleType INNER JOIN VS4TVehicle ON VS4TVehicleType.TVeTCode = VS4TVehicle.TVehTVeTCode
GO

CREATE VIEW VS4VVisa
AS 
SELECT VS4TVisa.*, VS4TProduct.*
FROM VS4TVisa LEFT JOIN VS4TProduct ON VS4TVisa.TVSATPdtCode = VS4TProduct.TPdtCode
GO

CREATE VIEW VS4VVisaPassenger
AS 
SELECT VS4TVisa.*, VS4TSOPassenger.*, VS4TAR3.*, VS4TProduct.TPdtCode, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProductBook.TPBGTAILCode, VS4TProductBook.TPBGFromTCouCode, VS4TProductBook.TPBGFromPort, VS4TProductBook.TPBGFlightNo, VS4TProductBook.TPBGBookCodeList, VS4TProductBook.TPBGDepDate, VS4TProductBook.TPBGDepTime, VS4TProductBook.TPBGToTCouCode, VS4TProductBook.TPBGToPort, VS4TProductBook.TPBGArrDate, VS4TProductBook.TPBGArrTime, VS4TProductBook.TPBGFromTCouCode2, VS4TProductBook.TPBGFromPort2, VS4TProductBook.TPBGFlightNo2, VS4TProductBook.TPBGBookCodeList2, VS4TProductBook.TPBGDepDate2, VS4TProductBook.TPBGDepTime2, VS4TProductBook.TPBGToPort2, VS4TProductBook.TPBGArrDate2, VS4TProductBook.TPBGArrTime2, VS4TAR.TARNName, VS4TAR.TARNName2, VS4TAR.TARNIntroName, VS4TAR.TARNTaxNo, VS4TAR.TARNTARGCode, VS4TAR.TARNAddressBill, VS4TAR.TARNAddressDeliver, VS4TAR.TARNAddress, VS4TAR.TARNAddress2, VS4TAR.TARNSubProvince, VS4TAR.TARNCity, VS4TAR.TARNPostalCode, VS4TAR.TARNStaCode, VS4TAR.TARNTCouCode, VS4TAR.TARNWebsite, VS4TAR.TARNEmail, VS4TAR.TARNPhone, VS4TAR.TARNFax, VS4TAR.TARNMobile, VS4TAR.TARNImage1, VS4TAR.TARNTBsTCode, VS4TAR.TARNTSAeCode, VS4TAR.TARNTARSAlias, VS4TAR2.TAR2Nature, VS4TAR2.TAR2TaxNo, VS4TAR2.TAR2SaleCode, VS4TAR2.TAR2RelationLevel, VS4TAR2.TAR2TSPvCode, VS4TAR2.TAR2TPrvCode, VS4TProduct.TPdtStartDate, VS4TProduct.TPdtEndDate, VS4TAR_1.TARNName2 AS VVSAFirstName2, VS4TAR_1.TARNName2 AS VVSALastName2, VS4TAR3_1.TAR3CitizenNo AS VVSACitizenNo, VS4TAR3_1.TAR3BirthDay AS VVSABirthDay, VS4TPlace.TPlaName, VS4TPlace.TPlaPhone, VS4TPlace.TPlaFax, VS4TPlace.TPlaEmail, VS4TProductBook.TPBGTPdtCode
FROM ((((((((VS4TSOPassenger LEFT JOIN VS4TAR3 ON VS4TSOPassenger.TVSPTARNCode = VS4TAR3.TAR3TARNCode) LEFT JOIN VS4TAR ON VS4TSOPassenger.TVSPTARNCode = VS4TAR.TARNCode) LEFT JOIN VS4TAR2 ON VS4TSOPassenger.TVSPTARNCode = VS4TAR2.TAR2TARNCode) LEFT JOIN VS4TAR AS VS4TAR_1 ON VS4TSOPassenger.TVSPRelateTARNCode = VS4TAR_1.TARNCode) LEFT JOIN VS4TAR3 AS VS4TAR3_1 ON VS4TAR_1.TARNCode = VS4TAR3_1.TAR3TARNCode) LEFT JOIN (VS4TProductPlace LEFT JOIN VS4TPlace ON VS4TProductPlace.TPAPTPlaID = VS4TPlace.TPlaID) ON (VS4TSOPassenger.TVSPHotelNo = VS4TProductPlace.TPAPLn) AND (VS4TSOPassenger.TVSPTPdtCode = VS4TProductPlace.TPAPTPdtCode)) LEFT JOIN (VS4TProduct LEFT JOIN VS4TProductBook ON VS4TProduct.TPdtCode = VS4TProductBook.TPBGTPdtCode) ON VS4TSOPassenger.TVSPTPdtCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TVisa ON (VS4TSOPassenger.TVSPLn = VS4TVisa.TVSALn) AND (VS4TSOPassenger.TVSPTPdtCode = VS4TVisa.TVSATPdtCode)) LEFT JOIN VS4TSOImigration ON (VS4TSOPassenger.TVSPTSODNo = VS4TSOImigration.TIMGTSODNo) AND (VS4TSOPassenger.TVSPLn = VS4TSOImigration.TIMGLn) AND (VS4TSOPassenger.TVSPTPdtCode = VS4TSOImigration.TIMGTPdtCode)
WHERE (((VS4TProductPlace.TPAPLn)=1 Or (VS4TProductPlace.TPAPLn) Is Null))
GO

CREATE VIEW VS4VWarehouse
AS 
SELECT VS4TWarehouse.*
FROM VS4TWarehouse
GO


