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

CREATE VIEW VS4VAccountHR AS  SELECT VS4TAccountHR.*, VS4TDivision.*, VS4TEmpAddMoney.*, VS4TOtherExpense.TOExName, VS4TOtherExpense_1.TOExName AS VAHRTOExName, VS4TPaymentType.TPyTName, VS4TPaymentType_1.tPyTName AS VAHRTPyTName FROM (((((VS4TAccountHR INNER JOIN VS4TDivision ON VS4TAccountHR.TAHRTDivCode = VS4TDivision.TDivCode) INNER JOIN VS4TEmpAddMoney ON VS4TAccountHR.TAHRTAmyCode = VS4TEmpAddMoney.TAmyCode) LEFT JOIN VS4TOtherExpense ON VS4TAccountHR.TAHRTOExCode = VS4TOtherExpense.TOExCode) LEFT JOIN VS4TOtherExpense AS VS4TOtherExpense_1 ON VS4TAccountHR.TAHRIDLTOExCode = VS4TOtherExpense_1.TOExCode) LEFT JOIN VS4TPaymentType ON VS4TEmpAddMoney.TAmyTPyTAlias = VS4TPaymentType.TPyTAlias) LEFT JOIN VS4TPaymentType AS VS4TPaymentType_1 ON VS4TAccountHR.TAHRTPyTAlias = VS4TPaymentType_1.TPyTAlias
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, VS4TAP2.* 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) LEFT JOIN VS4TAP2 ON VS4TAP.TAPNCode = VS4TAP2.TAP2TAPNCode) 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 VS4VAPBankFirst AS  SELECT VS4TAPBank.TAPBTAPNCode, VS4TAPBank.TAPBLn, VS4TAPBank.TAPBTBnkCode, VS4TAPBank.TAPBTBBrCode, VS4TAPBank.TAPBAccountType, VS4TAPBank.TAPBAccountName, VS4TAPBank.TAPBAccountNo, VS4TAPBank.TAPBAccountBranch, VS4TBank.TBnkName, VS4TBank.TBnkName2, TAPBAccountNo + ' ' + TBnkName + ' ' + TAPBAccountBranch AS VAPBAccountNo FROM VS4TAPBank LEFT JOIN VS4TBank ON VS4TAPBank.TAPBTBnkCode = VS4TBank.TBnkCode WHERE (((VS4TAPBank.TAPBLn)=1))
GO

CREATE VIEW VS4VAPBill AS  SELECT VS4TAPBill.*, VS4TAPBillMB.*, VS4TAP.TAPNName, VS4TProject.TPrjName, 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, VS4TAPInvoice.TIAPArrears, VS4TAPInvoice.TIAPDescription 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 VS4TAPInvoice ON VS4TAPBillMB.TPBMTIPJNo = VS4TAPInvoice.TIAPNo) LEFT JOIN VS4TAPDebitNote ON VS4TAPBillMB.TPBMTIPJNo = VS4TAPDebitNote.TDENNo) LEFT JOIN VS4TAPCreditNote ON VS4TAPBillMB.TPBMTIPJNo = VS4TAPCreditNote.TPCNNo) ON VS4TAPBill.TPBINo = VS4TAPBillMB.TPBMTPBINo
GO

CREATE VIEW VS4VAPCard AS  SELECT VS4TAP.TAPNCode, VS4TAP.TAPNName, VS4TAP.TAPNIntroName, VS4TAPCard.*, TAPLTACPTACYID, TAPLTACPID, TAPLTAPNCode, TAPLMode, TAPLQuarter, TAPLCreditLimit, TAPLCreditUseBal, TAPLCreditUse, TAPLCreditBalance, TAPLCreditAvaiBal, TAPLBeginBalance, TAPLTotalOrderBal, TAPLDisBill, TAPLTotalOrder, TAPLTimeOrder, TAPLCosTotal, TAPLInvGrandTotal, TAPLCNGrandTotal, TAPLDBGrandTotal, TAPLBillTotal, TAPLChequePayment, TAPLCashPayment, TAPLBankPayment, TAPLCardPayment, TAPLDisCash, TAPLAdjustTotal, TAPLInterestTotal, TAPLCutDeposit, TAPLFee, TAPLWtaxTotal, TAPLWtaxTotal2, TAPLPayLess, TAPLPayCoupon, TAPLPayOther, TAPLPayMisc, TAPLTotalPaid, TAPLTotalLate, TAPLEndBalance, TAPLFlag1, VS4TBranch.TBraName, VS4TAP.TAPNTBsTCode, VS4TBusinessType.TBstName, VS4TAP.TAPNTAPGCode, VS4TAPGroup.TAPGName, VS4TAP.TAPNTCouCode, VS4TCountry.TCouName, TIAPNo, TIAPBalanceFlag, TIAPType, TIAPTPCACode, TIAPMode, TIAPDate, TIAPDueDate, TIAPGLMethod, TIAPTGLTNo, TIAPTaxNo, TIAPRefNo, TIAPRefDate, TIAPRefNo2, TIAPRefDate2, TIAPPONo, TIAPSOCode, TIAPJobCode, TIAPTJobNo, TIAPTJbMLn, TIAPTPrjCode, TIAPTBraCode, TIAPDeliveryDate, TIAPDeliveryTo, TIAPTAPNCode, TIAPTAPUCode, TIAPContactNote, TIAPContactName, TIAPSupplierName, TIAPSupAddress, TIAPConsignee, TIAPNotifyParty, TIAPPriceChannel, TIAPDiscountList, TIAPSubTotal, TIAPDiscountText, TIAPDiscountTotal, TIAPNetTotal, TIAPDepositText, TIAPDeposit, TIAPTotal, TIAPTotalFOB, TIAPTCurCode, TIAPExchangeRate, TIAPTotalInRate, TIAPVATType, TIAPVATRate, TIAPTaxBase, TIAPVATTotal, TIAPGrandTotal, TIAPNOTAXTotal, TIAPWTaxBase, TIAPWTaxRate, TIAPWTaxTotal, TIAPNetPayment, TIAPBaseArrears, TIAPArrears, TIAPAdjustTotal, TIAPBaseAVailable, TIAPAVailable, TIAPPremiumTotal, TIAPBaseIncoType, TIAPIncoType, TIAPIncoterms, TIAPOtherFee, TIAPTransportFee, TIAPHandlingFee, TIAPFreightFee, TIAPInsurance, TIAPTransportDesc, TIAPDuty, TIAPShipBy, TIAPCountryOrigin, TIAPDestination, TIAPCondition, TIAPConditionDay, TIAPCondition1, TIAPConditionDay1, TIAPPaymentNote, TIAPStatementNote, TIAPTShpCode, TIAPDeliveryNote, TIAPPackingNote, TIAPDayAvailable, TIAPDescription, TIAPCustom1, TIAPCustom2, TIAPCustom3, TIAPCustom4, TIAPCustom5, TIAPTPOTCode, TIAPDeliveryStatus, TIAPBillStatus, TIAPCardFlag, TIAPTaxFlag, TIAPConfirmStatus, TIAPApproveStatus, TIAPCancelStatus, TIAPFlag1, TIAPConditionType, TIAPCustomNo, TIAPCustomDate, TIAPLoadingDate, TIAPStartAgingDate, TIAPIgnoreArrears, TIAPNote, TIAPReceiptStatus, TIAPManualArrear, TIAPWTaxBase2, TIAPWTaxRate2, TIAPWTaxTotal2, TIAPExciseBase, TIAPExciseRate, TIAPExciseTotal, TIAPRefNo3, TIAPRefNo4, TIAPLastPayDate, TIAPInvoiceStatus, TIAPCNStatus, TIAPClientTaxNo, TIAPBranchCode, TIAPBranchName, TIAPStockMode, TIAPTPIBCode, TIAPStockCard, TIAPVATManual, TIAPVATAdjust, VS4TAccountPeriod.TACPTACYID, VS4TAccountPeriod.TACPID, VS4TAccountPeriod.TACPStartDate, VS4TAccountPeriod.TACPEndDate, VS4TAccountPeriod.TACPFinishGoods, VS4TAccountPeriod.TACPWorkInProcess, VS4TAccountPeriod.TACPRawMaterials, VS4TAccountPeriod.TACPAssets, VS4TAccountPeriod.TACPLiabilities, VS4TAccountPeriod.TACPCaptitals, VS4TAccountPeriod.TACPNetProfitLoss, VS4TAccountPeriod.TACPSumProfitLoss, VS4TAccountPeriod.TACPStatus, VS4TAccountPeriod.TACPFlag1 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.TPICTACPTACYID = VS4TAPBalance.TAPLTACPTACYID) AND (VS4TAPCard.TPICTACPID = VS4TAPBalance.TAPLTACPID) AND (VS4TAPCard.TPICTAPNCode = VS4TAPBalance.TAPLTAPNCode)) LEFT JOIN VS4TBranch ON VS4TAPCard.TPICTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TAPInvoice ON VS4TAPCard.TPICDocNo = VS4TAPInvoice.TIAPNo) ON (VS4TAccountPeriod.TACPTACYID = VS4TAPBalance.TAPLTACPTACYID) AND (VS4TAccountPeriod.TACPID = VS4TAPBalance.TAPLTACPID)) ON VS4TAP.TAPNCode = VS4TAPCard.TPICTAPNCode WHERE (((VS4TAPCard.TPICType)<>'O'))
GO

CREATE VIEW VS4VAPCardIVDBCN AS  SELECT VS4TAPCard.*, VS4TAPInvoice.TIAPNo, VS4TAPInvoice.TIAPTaxBase, VS4TAPInvoice.TIAPVATTotal, VS4TAPInvoice.TIAPGrandTotal, VS4TAPInvoice.TIAPExchangeRate, VS4TAP.TAPNName, VS4TAPInvoice.TIAPDate, VS4TAPInvoice.TIAPSubTotal, VS4TAPInvoice.TIAPRefNo, VS4TBranch.TBraName, VS4TProject.TPrjName, VS4TAP.TAPNTCouCode, VS4TCountry.TCouName, VS4TAP.TAPNTBsTCode, VS4TBusinessType.TBstName, VS4TAP.TAPNTAPGCode, VS4TAPGroup.TAPGName, VS4TAP.TAPNName2, VS4TAPInvoice.TIAPTCurCode, VS4TAPInvoice.TIAPType, VS4TAPInvoice.TIAPNetTotal, VS4TAPInvoice.TIAPArrears, VS4TAPInvoice.TIAPNetPayment, VS4TAPInvoice.TIAPLastPayDate 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 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 (((VS4TAPInvoice.TIAPType)<>10 And (VS4TAPInvoice.TIAPType)<>7 And (VS4TAPInvoice.TIAPType)<>5) AND ((VS4TAPCard.TPICType)<>'O')) OR (((VS4TAPInvoice.TIAPType) Is Null))
GO

CREATE VIEW VS4VAPCardIVDBCN2 AS  SELECT VS4TAPCard.*, VS4TAPInvoice.TIAPNo, VS4TAPInvoice.TIAPTaxBase, VS4TAPInvoice.TIAPVATTotal, VS4TAPInvoice.TIAPGrandTotal, VS4TAPInvoice.TIAPExchangeRate, VS4TAP.TAPNName, VS4TAPInvoice.TIAPDate, VS4TAPInvoice.TIAPSubTotal, VS4TAPInvoice.TIAPRefNo, VS4TBranch.TBraName, VS4TProject.TPrjName, VS4TAP.TAPNTCouCode, VS4TCountry.TCouName, VS4TAP.TAPNTBsTCode, VS4TBusinessType.TBstName, VS4TAP.TAPNTAPGCode, VS4TAPGroup.TAPGName, VS4TAP.TAPNName2, VS4TAPInvoice.TIAPTCurCode, VS4TAPInvoice.TIAPType, VS4TAPInvoice.TIAPNetTotal, VS4TAPInvoice.TIAPArrears, VS4TAPInvoice.TIAPNetPayment, VS4TAPInvoice.TIAPLastPayDate 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 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 (((VS4TAPInvoice.TIAPType)<>10 And (VS4TAPInvoice.TIAPType)<>7 And (VS4TAPInvoice.TIAPType)<>5) AND ((VS4TAPCard.TPICType)<>'O')) OR (((VS4TAPInvoice.TIAPType) Is Null))
GO

CREATE VIEW VS4VAPCardIVDBCNFM AS  SELECT VS4TAPCard.*, VS4TAPInvoice.TIAPNo, VS4TAPInvoice.TIAPTaxBase, VS4TAPInvoice.TIAPVATTotal, VS4TAPInvoice.TIAPGrandTotal, VS4TAPInvoice.TIAPExchangeRate, VS4TAP.TAPNName, VS4TAPInvoice.TIAPDate, VS4TAPInvoice.TIAPSubTotal, VS4TAPInvoice.TIAPRefNo, VS4TBranch.TBraName, 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.TIPMCustom4, VS4TAPInvoiceMB.TIPMCustom5, VS4TAPInvoiceMB.TIPMProductName, VS4TAPInvoiceMB.TIPMCost, VS4TAPInvoiceMB.TIPMPrice, VS4TAPInvoiceMB.TIPMQuantity, VS4TAPInvoiceMB.TIPMQuantityCalc, VS4TAPInvoiceMB.TIPMTUntCode, VS4TAPInvoiceMB.TIPMAmountWTAX, VS4TAPInvoiceMB.TIPMAmountVAT, VS4TAPInvoiceMB.TIPMTaxType, VS4TAPInvoiceMB.TIPMCostAmount, VS4TProductSec2.TPS2Code, VS4TProductSec2.TPS2Name, VS4TAP.TAPNName2, VS4TAPInvoice.TIAPTCurCode, VS4TAPInvoiceMB.TIPMIsPremium, VS4TAPInvoiceMB.TIPMUnitFactor, VS4TAPInvoiceMB.TIPMNetAmount, VS4TAPInvoice.TIAPDiscountTotal, VS4TAPInvoice.TIAPDeposit, VS4TAPInvoice.TIAPVATType, VS4TAPInvoice.TIAPType, VS4TProductSection.TPSECode, VS4TProductSection.TPSEName, VS4TAPInvoice.TIAPNetTotal, VS4TAPInvoice.TIAPArrears, VS4TAPInvoice.TIAPNetPayment, VS4TAPInvoice.TIAPLastPayDate, VS4TAPInvoiceMB.TIPMTIAPNo, VS4TAPInvoiceMB.TIPMLn, VS4TAPInvoice.TIAPBaseAVailable, VS4TAPInvoice.TIAPBaseArrears, VS4TAPInvoice.TIAPAVailable FROM VS4TProductSection RIGHT JOIN ((((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 VS4TAPInvoice ON VS4TAPCard.TPICDocNo = VS4TAPInvoice.TIAPNo) ON VS4TBranch.TBraCode = VS4TAPCard.TPICTBraCode) LEFT JOIN VS4TProject ON VS4TAPCard.TPICTPrjCode = VS4TProject.TPrjCode) 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) ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode WHERE (((VS4TAPInvoice.TIAPType)<>10) AND ((VS4TAPCard.TPICType)<>'O')) OR (((VS4TAPInvoice.TIAPType) Is Null))
GO

CREATE VIEW VS4VAPCardIVDBCNMB AS  SELECT VS4TAPCard.*, VS4TAPInvoice.TIAPNo, VS4TAPInvoice.TIAPTaxBase, VS4TAPInvoice.TIAPVATTotal, VS4TAPInvoice.TIAPGrandTotal, VS4TAPInvoice.TIAPExchangeRate, VS4TAP.TAPNName, VS4TAPInvoice.TIAPDate, VS4TAPInvoice.TIAPSubTotal, VS4TAPInvoice.TIAPRefNo, VS4TBranch.TBraName, 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.TIPMCustom4, VS4TAPInvoiceMB.TIPMCustom5, VS4TAPInvoiceMB.TIPMProductName, VS4TAPInvoiceMB.TIPMCost, VS4TAPInvoiceMB.TIPMPrice, VS4TAPInvoiceMB.TIPMQuantity, VS4TAPInvoiceMB.TIPMQuantityCalc, VS4TAPInvoiceMB.TIPMTUntCode, VS4TAPInvoiceMB.TIPMAmountWTAX, VS4TAPInvoiceMB.TIPMAmountVAT, VS4TAPInvoiceMB.TIPMTaxType, VS4TAPInvoiceMB.TIPMCostAmount, VS4TProductSec2.TPS2Code, VS4TProductSec2.TPS2Name, VS4TAP.TAPNName2, VS4TAPInvoice.TIAPTCurCode, VS4TAPInvoiceMB.TIPMIsPremium, VS4TAPInvoiceMB.TIPMUnitFactor, VS4TAPInvoiceMB.TIPMNetAmount, VS4TAPInvoice.TIAPDiscountTotal, VS4TAPInvoice.TIAPDeposit, VS4TAPInvoice.TIAPVATType, VS4TAPInvoice.TIAPType, VS4TProductSection.TPSECode, VS4TProductSection.TPSEName, VS4TAPInvoice.TIAPNetTotal, VS4TAPInvoice.TIAPArrears, VS4TAPInvoice.TIAPNetPayment, VS4TAPInvoice.TIAPLastPayDate, VS4TAPInvoiceMB.TIPMTIAPNo, VS4TAPInvoiceMB.TIPMLn, VS4TAPInvoiceMBAOL.TIPATPrjCode, VS4TAPInvoice.TIAPDueDate, VS4TAPCreditNoteMB.TPCMReturnFlag, VS4TAPInvoiceMB.TIPMTOExCode, VS4TOtherExpense.TOExName, VS4TAPInvoiceMB.TIPMDiscountText, VS4TAPInvoiceMB.TIPMDiscountTotal FROM VS4TProductSection RIGHT JOIN ((((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 VS4TAPInvoice ON VS4TAPCard.TPICDocNo = VS4TAPInvoice.TIAPNo) ON VS4TBranch.TBraCode = VS4TAPCard.TPICTBraCode) LEFT JOIN VS4TProject ON VS4TAPCard.TPICTPrjCode = VS4TProject.TPrjCode) LEFT JOIN (((((VS4TAPInvoiceMB LEFT JOIN VS4TProduct ON VS4TAPInvoiceMB.TIPMTPdtCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code) LEFT JOIN VS4TAPInvoiceMBAOL ON (VS4TAPInvoiceMB.TIPMLn = VS4TAPInvoiceMBAOL.TIPATIPMLn) AND (VS4TAPInvoiceMB.TIPMTIAPNo = VS4TAPInvoiceMBAOL.TIPATIPMTIAPNo)) LEFT JOIN VS4TAPCreditNoteMB ON (VS4TAPInvoiceMB.TIPMLn = VS4TAPCreditNoteMB.TPCMLn) AND (VS4TAPInvoiceMB.TIPMTIAPNo = VS4TAPCreditNoteMB.TPCMTPCNNo)) LEFT JOIN VS4TOtherExpense ON VS4TAPInvoiceMB.TIPMTOExCode = VS4TOtherExpense.TOExCode) ON VS4TAPInvoice.TIAPNo = VS4TAPInvoiceMB.TIPMTIAPNo) ON VS4TAP.TAPNCode = VS4TAPCard.TPICTAPNCode) ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode WHERE (((VS4TAPInvoice.TIAPType)<>10 And (VS4TAPInvoice.TIAPType)<>7 And (VS4TAPInvoice.TIAPType)<>5) AND ((VS4TAPCard.TPICType)<>'O')) OR (((VS4TAPInvoice.TIAPType) Is Null))
GO

CREATE VIEW VS4VAPCardIVDBCNMO AS  SELECT VS4TAPCard.*, VS4TAPInvoice.TIAPNo, VS4TAPInvoice.TIAPTaxBase, VS4TAPInvoice.TIAPVATTotal, VS4TAPInvoice.TIAPGrandTotal, VS4TAPInvoice.TIAPExchangeRate, VS4TAP.TAPNName, VS4TAPInvoice.TIAPDate, VS4TAPInvoice.TIAPSubTotal, VS4TAPInvoice.TIAPRefNo, VS4TBranch.TBraName, 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.TIPMCustom4, VS4TAPInvoiceMB.TIPMCustom5, VS4TAPInvoiceMB.TIPMProductName, VS4TAPInvoiceMB.TIPMCost, VS4TAPInvoiceMB.TIPMPrice, VS4TAPInvoiceMB.TIPMQuantity, VS4TAPInvoiceMB.TIPMQuantityCalc, VS4TAPInvoiceMB.TIPMTUntCode, VS4TAPInvoiceMB.TIPMAmountWTAX, VS4TAPInvoiceMB.TIPMAmountVAT, VS4TAPInvoiceMB.TIPMTaxType, VS4TAPInvoiceMB.TIPMCostAmount, VS4TProductSec2.TPS2Code, VS4TProductSec2.TPS2Name, VS4TAP.TAPNName2, VS4TAPInvoice.TIAPTCurCode, VS4TAPInvoiceMB.TIPMIsPremium, VS4TAPInvoiceMB.TIPMUnitFactor, VS4TAPInvoiceMB.TIPMNetAmount, VS4TAPInvoice.TIAPDiscountTotal, VS4TAPInvoice.TIAPDeposit, VS4TAPInvoice.TIAPVATType, VS4TAPInvoice.TIAPType, VS4TProductSection.TPSECode, VS4TProductSection.TPSEName, VS4TAPInvoice.TIAPNetTotal, VS4TAPInvoice.TIAPArrears, VS4TAPInvoice.TIAPNetPayment, VS4TAPInvoice.TIAPLastPayDate, VS4TAPInvoiceMB.TIPMTIAPNo, VS4TAPInvoiceMB.TIPMLn, VS4TAPInvoiceMBAOL.TIPATPrjCode, VS4TAPInvoice.TIAPDueDate, VS4TAPCreditNoteMB.TPCMReturnFlag, VS4TAPInvoiceMB.TIPMTOExCode, VS4TOtherExpense.TOExName, VS4TAPInvoiceMB.TIPMDiscountText, VS4TAPInvoiceMB.TIPMDiscountTotal, VS4TAPVDocRef.TPVRTOEXCode, VS4TAPVDocRef.TPVRTaxBase, VS4TAPVDocRef.TPVRVATType, VS4TAPVDocRef.TPVRVATTotal, VS4TAPVDocRef.TPVRDOVAT, VS4TAPVDocRef.TPVRRefDocAmount, VS4TOtherExpense_1.TOExName AS VPMOTOEName FROM VS4TProductSection RIGHT JOIN ((((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 VS4TAPInvoice ON VS4TAPCard.TPICDocNo = VS4TAPInvoice.TIAPNo) ON VS4TBranch.TBraCode = VS4TAPCard.TPICTBraCode) LEFT JOIN VS4TProject ON VS4TAPCard.TPICTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TAPVoucher ON VS4TAPCard.TPICDocNo = VS4TAPVoucher.TAPVNo) LEFT JOIN (((((VS4TAPInvoiceMB LEFT JOIN VS4TProduct ON VS4TAPInvoiceMB.TIPMTPdtCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code) LEFT JOIN VS4TAPInvoiceMBAOL ON (VS4TAPInvoiceMB.TIPMLn = VS4TAPInvoiceMBAOL.TIPATIPMLn) AND (VS4TAPInvoiceMB.TIPMTIAPNo = VS4TAPInvoiceMBAOL.TIPATIPMTIAPNo)) LEFT JOIN VS4TAPCreditNoteMB ON (VS4TAPInvoiceMB.TIPMLn = VS4TAPCreditNoteMB.TPCMLn) AND (VS4TAPInvoiceMB.TIPMTIAPNo = VS4TAPCreditNoteMB.TPCMTPCNNo)) LEFT JOIN VS4TOtherExpense ON VS4TAPInvoiceMB.TIPMTOExCode = VS4TOtherExpense.TOExCode) ON VS4TAPInvoice.TIAPNo = VS4TAPInvoiceMB.TIPMTIAPNo) LEFT JOIN (VS4TAPVDocRef LEFT JOIN VS4TOtherExpense AS VS4TOtherExpense_1 ON VS4TAPVDocRef.TPVRTOEXCode = VS4TOtherExpense_1.TOExCode) ON VS4TAPVoucher.TAPVNo = VS4TAPVDocRef.TPVRTAPVNo) ON VS4TAP.TAPNCode = VS4TAPCard.TPICTAPNCode) ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode WHERE (((VS4TAPInvoice.TIAPType)<>10 And (VS4TAPInvoice.TIAPType)<>7 And (VS4TAPInvoice.TIAPType)<>5) AND ((VS4TAPCard.TPICType)<>'O')) OR (((VS4TAPInvoice.TIAPType) Is Null))
GO

CREATE VIEW VS4VPV AS SELECT VS4TAPVoucher.TAPVNo, VS4TAPVoucher.TAPVDate, VS4TAPVoucher.TAPVType, VS4TAPVoucher.TAPVDetailType, VS4TAPVoucher.TAPVMode, VS4TAPVoucher.TAPVBalanceFlag,                    VS4TAPVoucher.TAPVBaseArrear, VS4TAPVoucher.TAPVArrear, VS4TAPVoucher.TAPVRefNo, VS4TAPVoucher.TAPVRefDate, VS4TAPVoucher.TAPVRefNo2, VS4TAPVoucher.TAPVRefNo3,                    VS4TAPVoucher.TAPVPaymentStatus, VS4TAPVoucher.TAPVTBraCode, VS4TAPVoucher.TAPVTAPNCode, VS4TAPVoucher.TAPVPayTo, VS4TAPVoucher.TAPVAddress, VS4TAPVoucher.TAPVCurrency,                    VS4TAPVoucher.TAPVSubTotal, VS4TAPVoucher.TAPVCurRate, VS4TAPVoucher.TAPVCurAmount, VS4TAPVoucher.TAPVCurDiscount, VS4TAPVoucher.TAPVDiscount, VS4TAPVoucher.TAPVPayLess,                    VS4TAPVoucher.TAPVAdjustTotal, VS4TAPVoucher.TAPVFee, VS4TAPVoucher.TAPVNetAmount, VS4TAPVoucher.TAPVTaxBase, VS4TAPVoucher.TAPVWTAXTotal, VS4TAPVoucher.TAPVTaxBase2,                    VS4TAPVoucher.TAPVWTAXTotal2, VS4TAPVoucher.TAPVTotal, VS4TAPVoucher.TAPVNote, VS4TAPVoucher.TAPVTGLBCode, VS4TAPVoucher.TAPVTPrjCode, VS4TAPVoucher.TAPVGLMethod,                    VS4TAPVoucher.TAPVTGLTNo, VS4TAPVoucher.TAPVTTeTNo, VS4TAPVoucher.TAPVVATNo, VS4TAPVoucher.TAPVTaxPeriodNo, VS4TAPVoucher.TAPVTaxPeriodType, VS4TAPVoucher.TAPVTaxRefund,                    VS4TAPVoucher.TAPVPayType, VS4TAPVoucher.TAPVTaxNo, VS4TAPVoucher.TAPVWTaxPeriodNo, VS4TAPVoucher.TAPVWTaxPeriodType, VS4TAPVoucher.TAPVChequePayment,                    VS4TAPVoucher.TAPVCashPayment, VS4TAPVoucher.TAPVBankPayment, VS4TAPVoucher.TAPVCutDeposit, VS4TAPVoucher.TAPVCardPayment, VS4TAPVoucher.TAPVPayCoupon,                    VS4TAPVoucher.TAPVPayOther, VS4TAPVoucher.TAPVPayMisc, VS4TAPVoucher.TAPVInterestRate, VS4TAPVoucher.TAPVInterestTotal, VS4TAPVoucher.TAPVCardFlag, VS4TAPVoucher.TAPVTaxFlag,                    VS4TAPVoucher.TAPVClientTaxNo, VS4TAPVoucher.TAPVAPType, VS4TAPVoucher.TAPVCreateCode, VS4TAPVoucher.TAPVCreateBy, VS4TAPVoucher.TAPVCreateDate, VS4TAPVoucher.TAPVEditCode,                    VS4TAPVoucher.TAPVEditBy, VS4TAPVoucher.TAPVEditDate, VS4TAPVoucher.TAPVConfirmStatus, VS4TAPVoucher.TAPVConfirmBy, VS4TAPVoucher.TAPVConfirmDate, VS4TAPVoucher.TAPVApproveStatus,                    VS4TAPVoucher.TAPVApproveBy, VS4TAPVoucher.TAPVApproveDate, VS4TAPVoucher.TAPVApproveNote, VS4TAPVoucher.TAPVRevision, VS4TAPVoucher.TAPVCancelStatus,                    VS4TAPVoucher.TAPVCancelNo, VS4TAPVoucher.TAPVCancelBy, VS4TAPVoucher.TAPVCancelDate, VS4TAPVoucher.TAPVCancelNote, VS4TAPVoucher.TAPVFlag1, VS4TAPVoucher.TAPVFlag2,                    VS4TAPVoucher.TAPVFlag3, VS4TAPVoucher.TAPVTDivCode, VS4TAPVoucher.TAPVTDepCode, VS4TAPVoucher.TAPVTSecCode, VS4TAPVoucher.TAPVTEmpCode, VS4TAPVoucher.TAPVTAssCode,                    VS4TAPVoucher.TAPVTPdtCode, VS4TAPVoucher.TAPVTARNCode, VS4TAPVoucher.TAPVDescription, VS4TAPVoucher.TAPVRefNo4, VS4TAPVoucher.TAPVLicenseNo, VS4TAPVoucher.TAPVRefValue,                    VS4TAPVoucher.TAPVTAPUCode, VS4TAPVoucher.TAPVTjobNo, VS4TAPVoucher.TAPVTJbMLn, VS4TAPVoucher.TAPVPublishStatus, VS4TAPVoucher.TAPVPublishDate, VS4TAPVoucher.TAPVPublishNo,                    VS4TAPVDocRef.TPVRTAPVNo, VS4TAPVDocRef.TPVRLn, VS4TAPVDocRef.TPVRType, VS4TAPVDocRef.TPVRRefAPBillNo, VS4TAPVDocRef.TPVRRefDocNo, VS4TAPVDocRef.TPVRRefDocDate,                    VS4TAPVDocRef.TPVRRefNo, VS4TAPVDocRef.TPVRRefNo2, VS4TAPVDocRef.TPVRRefNo3, VS4TAPVDocRef.TPVRRefDocAmount, VS4TAPVDocRef.TPVRRefDocType, VS4TAPVDocRef.TPVRRefDueDate,                    VS4TAPVDocRef.TPVRCurrency, VS4TAPVDocRef.TPVRCurRate, VS4TAPVDocRef.TPVRCurSubTotal, VS4TAPVDocRef.TPVRCurDiscount, VS4TAPVDocRef.TPVRCurAmount, VS4TAPVDocRef.TPVRAmountRate,                    VS4TAPVDocRef.TPVRTaxBase, VS4TAPVDocRef.TPVRVATType, VS4TAPVDocRef.TPVRVATRate, VS4TAPVDocRef.TPVRVATTotal, VS4TAPVDocRef.TPVRVATNo, VS4TAPVDocRef.TPVRTAXNo,                    VS4TAPVDocRef.TPVRWTAXRate, VS4TAPVDocRef.TPVRWTAXTotal, VS4TAPVDocRef.TPVRWTAXCond, VS4TAPVDocRef.TPVRWTAXDesc, VS4TAPVDocRef.TPVRCommissionBase,                    VS4TAPVDocRef.TPVRCommissionRate, VS4TAPVDocRef.TPVRCommission, VS4TAPVDocRef.TPVRInterestRate, VS4TAPVDocRef.TPVRInterestTotal, VS4TAPVDocRef.TPVRTOEXCode,                    VS4TAPVDocRef.TPVRDOVAT, VS4TAPVDocRef.TPVRNote, VS4TAPVDocRef.TPVRNote2, VS4TAPVDocRef.TPVRFlag1, VS4TAPVDocRef.TPVRFlag2, VS4TAPVDocRef.TPVRFlag3,                    VS4TAPVDocRef.TPVRWTAXRate2, VS4TAPVDocRef.TPVRWTAXTotal2, VS4TAPVDocRef.TPVRWTAXCond2, VS4TAPVDocRef.TPVRWTAXDesc2, VS4TAPVDocRef.TPVRWTAXBase2,                    VS4TAPVDocRef.TPVRWTAXBase, VS4TAPVDocRef.TPVRWTAXSection, VS4TAPVDocRef.TPVRWTAXSection2, VS4TAPVDocRef.TPVRRefWtaxTotal, VS4TAP.TAPNCode, VS4TAP.TAPNTCmpCode,                    VS4TAP.TAPNTAPTCode, VS4TAP.TAPNIntro, VS4TAP.TAPNName, VS4TAP.TAPNName2, VS4TAP.TAPNIntroName, VS4TAP.TAPNType, VS4TAP.TAPNTBsTCode, VS4TAP.TAPNOwnerName,                    VS4TAP.TAPNDocCode, VS4TAP.TAPNContactName, VS4TAP.TAPNTaxNo, VS4TAP.TAPNAccountCode, VS4TAP.TAPNTAPGCode, VS4TAP.TAPNTAPCCode, VS4TAP.TAPNAddressBill,                    VS4TAP.TAPNAddressDeliver, VS4TAP.TAPNAddress, VS4TAP.TAPNSubProvince, VS4TAP.TAPNCity, VS4TAP.TAPNPostalCode, VS4TAP.TAPNStaCode, VS4TAP.TAPNTCouCode, VS4TAP.TAPNWebsite,                    VS4TAP.TAPNEmail, VS4TAP.TAPNPhone, VS4TAP.TAPNFax, VS4TAP.TAPNImage1, VS4TAP.TAPNDiscountPC, VS4TAP.TAPNDiscountDay, VS4TAP.TAPNCreditDay, VS4TAP.TAPNLimitTCurCode,                    VS4TAP.TAPNSpecialTaxRate, VS4TAP.TAPNPaymentNote, VS4TAP.TAPNStatementNote, VS4TAP.TAPNDeliveryNote, VS4TAP.TAPNQualityScore, VS4TAP.TAPNDeliveryScore, VS4TAP.TAPNTotalScore,                    VS4TAP.TAPNTimeToOrder, VS4TAP.TAPNLastDueDate, VS4TAP.TAPNLastOrderDate, VS4TAP.TAPNMapFile, VS4TAP.TAPNCreditLimit, VS4TAP.TAPNCreditUseBal, VS4TAP.TAPNCreditUse,                    VS4TAP.TAPNCreditBalance, VS4TAP.TAPNCreditAvaiBal, VS4TAP.TAPNTotalOrderBal, VS4TAP.TAPNQualityBal, VS4TAP.TAPNDeliveryBal, VS4TAP.TAPNTotalScoreBal, VS4TAP.TAPNBillAdjust,                    VS4TAP.TAPNNote, VS4TAP.TAPNCreateCode, VS4TAP.TAPNCreateDate, VS4TAP.TAPNEditCode, VS4TAP.TAPNEditDate, VS4TAP.TAPNTextSort, VS4TAP.TAPNFlag1, VS4TAP.TAPNFlag2,                    VS4TAP.TAPNFlag3, VS4TAP.TAPNConditionType, VS4TAP.TAPNShortName, VS4TAP.TAPNAddressBill2, VS4TAP.TAPNTBraCode, VS4TAP.TAPNTSPvCode, VS4TAP.TAPNTPrvCode, VS4TAP.TAPNMode,                    VS4TAP.TAPNPaymentType, VS4TAP.TAPNPaymentParam, VS4TAP.TAPNCreditMode, VS4TAP.TAPNTVG2Code, VS4TAP.TAPNTVG3Code, VS4TAP.TAPNInternal, VS4TOtherExpense.TOExCode,                    VS4TOtherExpense.TOExName, VS4TOtherExpense.TOExName2, VS4TOtherExpense.TOExTACCCode, VS4TOtherExpense.TOExFlag1, VS4TOtherExpense.TOExFlag2, VS4TOtherExpense.TOExFlag3,                    VS4TOtherExpense.TOExPrice, VS4TOtherExpense.TOExType, VS4TOtherExpense.TOExHasPending, VS4TOtherExpense.TOExGroupReport1, VS4TOtherExpense.TOExGroupReport2,                    VS4TOtherExpense.TOExNote, VS4TAPVDocRefAOL.TPDATBraCode, VS4TAPVDocRefAOL.TPDATPrjCode, VS4TAPVDocRefAOL.TPDATDivCode, VS4TAPVDocRefAOL.TPDATDepCode,                    VS4TAPVDocRefAOL.TPDATSecCode, VS4TAPVDocRefAOL.TPDATSZGCode, VS4TAPVDocRefAOL.TPDATSZnCode, VS4TAPVDocRefAOL.TPDATSAeCode, VS4TAPVDocRefAOL.TPDATARNCode,                    VS4TAPVDocRefAOL.TPDATAPNCode, VS4TAPVDocRefAOL.TPDATAssCode, VS4TAPVDocRefAOL.TPDATEmpCode, VS4TAPVDocRefAOL.TPDATPdtCode, VS4TDivision.TDivName, VS4TDepartment.TDepName,                    VS4TSection.TSecName, VS4TEmployee.TEmpFullName, VS4TGLBook.TGLBName, VS4TProject.TPrjName, VS4TProject.TPrjTEmpCode, VS4TEmployee_1.TEmpFullName AS VEmpFullName,                    VS4TAPBank.TAPBAccountNo, VS4TAPBank.TAPBAccountName, VS4TAPBank.TAPBTBnkCode, VS4TAR2.TAR2TARNCode, VS4TAPVDocRefAOL.TPDATJobNo, VS4TAR.TARNName FROM     VS4TAP LEFT OUTER JOIN                   VS4TAR2 ON VS4TAP.TAPNCode = VS4TAR2.TAR2TAPNCode LEFT OUTER JOIN                   VS4TAPBank ON VS4TAP.TAPNCode = VS4TAPBank.TAPBTAPNCode INNER JOIN                   VS4TAPVoucher LEFT OUTER JOIN                   VS4TProject ON VS4TAPVoucher.TAPVTPrjCode = VS4TProject.TPrjCode LEFT OUTER JOIN                   VS4TGLBook ON VS4TAPVoucher.TAPVTGLBCode = VS4TGLBook.TGLBCode LEFT OUTER JOIN                   VS4TEmployee AS VS4TEmployee_1 ON VS4TProject.TPrjTEmpCode = VS4TEmployee_1.TEmpCode INNER JOIN                   VS4TAPVDocRef LEFT OUTER JOIN                   VS4TOtherExpense ON VS4TAPVDocRef.TPVRTOEXCode = VS4TOtherExpense.TOExCode LEFT OUTER JOIN                   VS4TAPInvoice ON VS4TAPVDocRef.TPVRRefDocNo = VS4TAPInvoice.TIAPNo LEFT OUTER JOIN                   VS4TAPCreditNote ON VS4TAPVDocRef.TPVRRefDocNo = VS4TAPCreditNote.TPCNNo LEFT OUTER JOIN                   VS4TAPDebitNote ON VS4TAPVDocRef.TPVRRefDocNo = VS4TAPDebitNote.TDENNo LEFT OUTER JOIN                   VS4TAPBill ON VS4TAPVDocRef.TPVRRefAPBillNo = VS4TAPBill.TPBINo LEFT OUTER JOIN                   VS4TAPVDocRefAOL ON VS4TAPVDocRef.TPVRTAPVNo = VS4TAPVDocRefAOL.TPDATPVRTAPVNo AND VS4TAPVDocRef.TPVRLn = VS4TAPVDocRefAOL.TPDATPVRLn LEFT OUTER JOIN                   VS4TDivision ON VS4TAPVDocRefAOL.TPDATDivCode = VS4TDivision.TDivCode LEFT OUTER JOIN                   VS4TDepartment ON VS4TAPVDocRefAOL.TPDATDepCode = VS4TDepartment.TDepCode LEFT OUTER JOIN                   VS4TSection ON VS4TAPVDocRefAOL.TPDATSecCode = VS4TSection.TSecCode LEFT OUTER JOIN                   VS4TEmployee ON VS4TAPVDocRefAOL.TPDATEmpCode = VS4TEmployee.TEmpCode ON VS4TAPVoucher.TAPVNo = VS4TAPVDocRef.TPVRTAPVNo ON                    VS4TAP.TAPNCode = VS4TAPVoucher.TAPVTAPNCode LEFT OUTER JOIN                   VS4TAR ON VS4TAPVoucher.TAPVTARNCode = VS4TAR.TARNCode WHERE  (VS4TAPBank.TAPBLn = 1) OR                   (VS4TAPBank.TAPBLn IS NULL)
GO

CREATE VIEW VS4VAPCodeFromBill AS  SELECT VS4TAP.TAPNCode, VS4TAP.TAPNName, VS4TAP.TAPNName2, VS4TAP.TAPNIntroName, VS4TAP.TAPNFlag1, VS4TAP.TAPNTCouCode, VS4TCountry.TCouName, VS4TCountry.TCouName2, VS4TAPBill.TPBIConfirmStatus, VS4TAPBill.TPBICancelStatus, VS4TAPBill.TPBIApproveStatus FROM (VS4TCountry INNER JOIN VS4TAP ON VS4TCountry.TCouCode = VS4TAP.TAPNTCouCode) INNER JOIN VS4TAPBill ON VS4TAP.TAPNCode = VS4TAPBill.TPBITAPNCode GROUP BY VS4TAP.TAPNCode, VS4TAP.TAPNName, VS4TAP.TAPNName2, VS4TAP.TAPNIntroName, VS4TAP.TAPNFlag1, VS4TAP.TAPNTCouCode, VS4TCountry.TCouName, VS4TCountry.TCouName2, VS4TAPBill.TPBIConfirmStatus, VS4TAPBill.TPBICancelStatus, VS4TAPBill.TPBIApproveStatus HAVING (((VS4TAPBill.TPBIConfirmStatus)=1) AND ((VS4TAPBill.TPBICancelStatus)<>1) AND ((VS4TAPBill.TPBIApproveStatus)=1))
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 Or (VS4TAPInvoice.TIAPType)=7))
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.TPODInvoiceStatus, 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.TPPDInvoiceStatus, 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 VS4VAPCodeFromSI 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)=9))
GO

CREATE VIEW VS4VAPContact AS  SELECT VS4TAP.*, VS4TAPType.*, VS4TBusinessType.*, VS4TCountry.*, VS4TState.*, VS4TAPGroup.TAPGName, VS4TAPContact.* 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) INNER JOIN VS4TAPContact ON VS4TAP.TAPNCode = VS4TAPContact.TAPCTAPNCode) ON VS4TBusinessType.TBsTCode = VS4TAP.TAPNTBsTCode) ON VS4TCountry.TCouCode = VS4TAP.TAPNTCouCode
GO

CREATE VIEW VS4VAPContract AS  SELECT VS4TAPContract.*, VS4TAPContractMB.*, VS4TProductLine.TPdLName, VS4TProductSec2.TPS2Name, VS4TProductSection.TPSEName, VS4TProduct.TPdtName, VS4TNational.TNalName, VS4TNational.TNalName2, VS4TProductLine.TPdLName2, VS4TProductSection.TPSEName2, VS4TProductSec2.TPS2Name2, VS4TProduct.TPdtName2, VS4TAPBank.TAPBAccountName AS VCntPaxACName, VS4TAPBank_1.TAPBAccountName AS VCntTGACName, VS4TAPBank_2.TAPBAccountName AS VCntTACName, VS4TAPBank_3.TAPBAccountName AS VCntGACName, VS4TAPBank_4.TAPBAccountName AS VCntKBACName, VS4TAPBank_5.TAPBAccountName AS VCntGDACName, VS4TAPBank_6.TAPBAccountName AS VCntTLACName, VS4TAPBank_7.TAPBAccountName AS VCntComACName, VS4TAPBank_8.TAPBAccountName AS VCntBonusACName, VS4TAPBank_9.TAPBAccountName AS VCntBusACName, VS4TBank.TBnkShortName AS VCntPaxBName, VS4TBank_1.TBnkShortName AS VCntTGBName, VS4TBank_2.TBnkShortName AS VCntTBName, VS4TBank_3.TBnkShortName AS VCntGBName, VS4TBank_4.TBnkShortName AS VCntKBBName, VS4TBank_5.TBnkShortName AS VCntGDBName, VS4TBank_6.TBnkShortName AS VCntTLBName, VS4TBank_7.TBnkShortName AS VCntComBName, VS4TBank_8.TBnkShortName AS VCntBonusBName, VS4TBank_9.TBnkShortName AS VCntBusBName, VS4TAR.TARNName, VS4TAR.TARNName2 FROM (((((((((((((((((((((VS4TAPContract LEFT JOIN VS4TNational ON VS4TAPContract.TCntTNalCode = VS4TNational.TNalCode) LEFT JOIN VS4TAPBank ON (VS4TAPContract.TCntTAPNCode = VS4TAPBank.TAPBTAPNCode) AND (VS4TAPContract.TCntPayPAXACNo = VS4TAPBank.TAPBAccountNo)) LEFT JOIN VS4TAPBank AS VS4TAPBank_1 ON (VS4TAPContract.TCntTAPNCode = VS4TAPBank_1.TAPBTAPNCode) AND (VS4TAPContract.TCntPayTGACNo = VS4TAPBank_1.TAPBAccountNo)) LEFT JOIN VS4TAPBank AS VS4TAPBank_2 ON (VS4TAPContract.TCntTAPNCode = VS4TAPBank_2.TAPBTAPNCode) AND (VS4TAPContract.TCntPayTourACNo = VS4TAPBank_2.TAPBAccountNo)) LEFT JOIN VS4TAPBank AS VS4TAPBank_3 ON (VS4TAPContract.TCntTAPNCode = VS4TAPBank_3.TAPBTAPNCode) AND (VS4TAPContract.TCntPayGuideACNo = VS4TAPBank_3.TAPBAccountNo)) LEFT JOIN VS4TAPBank AS VS4TAPBank_4 ON (VS4TAPContract.TCntTAPNCode = VS4TAPBank_4.TAPBTAPNCode) AND (VS4TAPContract.TCntPayKBACNo = VS4TAPBank_4.TAPBAccountNo)) LEFT JOIN VS4TAPBank AS VS4TAPBank_5 ON (VS4TAPContract.TCntTAPNCode = VS4TAPBank_5.TAPBTAPNCode) AND (VS4TAPContract.TCntPayGDACNo = VS4TAPBank_5.TAPBAccountNo)) LEFT JOIN VS4TAPBank AS VS4TAPBank_6 ON (VS4TAPContract.TCntTAPNCode = VS4TAPBank_6.TAPBTAPNCode) AND (VS4TAPContract.TCntPayTLACNo = VS4TAPBank_6.TAPBAccountNo)) LEFT JOIN VS4TAPBank AS VS4TAPBank_7 ON (VS4TAPContract.TCntTAPNCode = VS4TAPBank_7.TAPBTAPNCode) AND (VS4TAPContract.TCntPayComACNo = VS4TAPBank_7.TAPBAccountNo)) LEFT JOIN VS4TAPBank AS VS4TAPBank_8 ON (VS4TAPContract.TCntTAPNCode = VS4TAPBank_8.TAPBTAPNCode) AND (VS4TAPContract.TCntPayBonusACNo = VS4TAPBank_8.TAPBAccountNo)) LEFT JOIN VS4TAPBank AS VS4TAPBank_9 ON (VS4TAPContract.TCntTAPNCode = VS4TAPBank_9.TAPBTAPNCode) AND (VS4TAPContract.TCntPayBusACNo = VS4TAPBank_9.TAPBAccountNo)) LEFT JOIN VS4TBank ON VS4TAPBank.TAPBTBnkCode = VS4TBank.TBnkCode) LEFT JOIN VS4TBank AS VS4TBank_1 ON VS4TAPBank_1.TAPBTBnkCode = VS4TBank_1.TBnkCode) LEFT JOIN VS4TBank AS VS4TBank_2 ON VS4TAPBank_2.TAPBTBnkCode = VS4TBank_2.TBnkCode) LEFT JOIN VS4TBank AS VS4TBank_3 ON VS4TAPBank_3.TAPBTBnkCode = VS4TBank_3.TBnkCode) LEFT JOIN VS4TBank AS VS4TBank_4 ON VS4TAPBank_4.TAPBTBnkCode = VS4TBank_4.TBnkCode) LEFT JOIN VS4TBank AS VS4TBank_5 ON VS4TAPBank_5.TAPBTBnkCode = VS4TBank_5.TBnkCode) LEFT JOIN VS4TBank AS VS4TBank_6 ON VS4TAPBank_6.TAPBTBnkCode = VS4TBank_6.TBnkCode) LEFT JOIN VS4TBank AS VS4TBank_7 ON VS4TAPBank_7.TAPBTBnkCode = VS4TBank_7.TBnkCode) LEFT JOIN VS4TBank AS VS4TBank_8 ON VS4TAPBank_8.TAPBTBnkCode = VS4TBank_8.TBnkCode) LEFT JOIN VS4TBank AS VS4TBank_9 ON VS4TAPBank_9.TAPBTBnkCode = VS4TBank_9.TBnkCode) INNER JOIN (((((VS4TAPContractMB LEFT JOIN VS4TProductSec2 ON VS4TAPContractMB.TCnMTPs2Code = VS4TProductSec2.TPS2Code) LEFT JOIN VS4TProductSection ON VS4TAPContractMB.TCnMTPSeCode = VS4TProductSection.TPSECode) LEFT JOIN VS4TProductLine ON VS4TAPContractMB.TCnMTPDLCode = VS4TProductLine.TPdLCode) LEFT JOIN VS4TProduct ON VS4TAPContractMB.TCnMTPdtCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TAR ON VS4TAPContractMB.TCnMTARNCode = VS4TAR.TARNCode) ON VS4TAPContract.TCntNo = VS4TAPContractMB.TCnMTCntNo
GO

CREATE VIEW VS4VAPContractBus AS  SELECT VS4TAPContract.*, VS4TAPContractBus.*, VS4TVehicleType.* FROM VS4TAPContract INNER JOIN (VS4TAPContractBus LEFT JOIN VS4TVehicleType ON VS4TAPContractBus.TCnBTVeTCode = VS4TVehicleType.TVeTCode) ON VS4TAPContract.TCntNo = VS4TAPContractBus.TCnBTCntNo
GO

CREATE VIEW VS4VAPCreditNote AS  SELECT VS4TAPCreditNote.*, VS4TAPCreditNoteMB.*, VS4TAP.TAPNTaxNo, VS4TAP.TAPNPhone, VS4TAP.TAPNFax, 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, VS4TAP.TAPNName2, VS4TAP.TAPNAddressBill2, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TAPInvoice_1.TIAPClientTaxNo, VS4TAPInvoice_1.TIAPBranchCode, VS4TAPInvoice_1.TIAPBranchName, VS4TLocation.TLctTWahCode, VS4TBranch.TBraAddressBill, VS4TBranch.TBraAddressBill2, VS4TBranch.TBraAddressBillOF, VS4TAPInvoiceMBAOL.* FROM ((((((VS4TAPCreditNote LEFT JOIN VS4TProject ON VS4TAPCreditNote.TPCNTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TAPCreditNote.TPCNTBraCode = VS4TBranch.TBraCode) 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) LEFT JOIN VS4TAPInvoice AS VS4TAPInvoice_1 ON VS4TAPCreditNote.TPCNNo = VS4TAPInvoice_1.TIAPNo) INNER JOIN (((VS4TAPCreditNoteMB LEFT JOIN VS4TProduct ON VS4TAPCreditNoteMB.TPCMTPdtCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TAPInvoice ON VS4TAPCreditNoteMB.TPCMSourceNo = VS4TAPInvoice.TIAPNo) LEFT JOIN VS4TLocation ON VS4TAPCreditNoteMB.TPCMTLctCode = VS4TLocation.TLctCode) ON VS4TAPCreditNote.TPCNNo = VS4TAPCreditNoteMB.TPCMTPCNNo) LEFT JOIN VS4TAPInvoiceMBAOL ON (VS4TAPCreditNoteMB.TPCMLn = VS4TAPInvoiceMBAOL.TIPATIPMLn) AND (VS4TAPCreditNoteMB.TPCMTPCNNo = VS4TAPInvoiceMBAOL.TIPATIPMTIAPNo)
GO

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

CREATE VIEW VS4VAPDebitNote AS  SELECT VS4TAPDebitNote.*, VS4TAPDebitNoteMB.*, VS4TAP.TAPNTaxNo, VS4TAP.TAPNPhone, VS4TAP.TAPNFax, VS4TCountry.TCouName, VS4TBranch.TBraName, 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, VS4TAP.TAPNName2, VS4TAP.TAPNAddressBill2, VS4TAPInvoice_1.TIAPClientTaxNo, VS4TAPInvoice_1.TIAPBranchCode, VS4TAPInvoice_1.TIAPBranchName, VS4TBranch.TBraAddressBill, VS4TBranch.TBraAddressBill2, VS4TBranch.TBraAddressBillOF, VS4TAPInvoice_1.TIAPStatementNote, VS4TAPInvoiceMBAOL.* 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) LEFT JOIN VS4TAPInvoice AS VS4TAPInvoice_1 ON VS4TAPDebitNote.TDENNo = VS4TAPInvoice_1.TIAPNo) INNER JOIN (VS4TAPDebitNoteMB LEFT JOIN VS4TAPInvoice ON VS4TAPDebitNoteMB.TDEBSourceNo = VS4TAPInvoice.TIAPNo) ON VS4TAPDebitNote.TDENNo = VS4TAPDebitNoteMB.TDEBTDENNo) LEFT JOIN VS4TAPInvoiceMBAOL ON (VS4TAPDebitNoteMB.TDEBLn = VS4TAPInvoiceMBAOL.TIPATIPMLn) AND (VS4TAPDebitNoteMB.TDEBTDENNo = VS4TAPInvoiceMBAOL.TIPATIPMTIAPNo)
GO

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

CREATE VIEW VS4VAPInvoice AS  SELECT VS4TAPInvoice.TIAPNo, VS4TAPInvoice.TIAPBalanceFlag, VS4TAPInvoice.TIAPType, VS4TAPInvoice.TIAPTPCACode, VS4TAPInvoice.TIAPMode, VS4TAPInvoice.TIAPDate, VS4TAPInvoice.TIAPDueDate, VS4TAPInvoice.TIAPGLMethod, VS4TAPInvoice.TIAPTGLTNo, VS4TAPInvoice.TIAPTaxNo, VS4TAPInvoice.TIAPRefNo, VS4TAPInvoice.TIAPRefDate, VS4TAPInvoice.TIAPRefNo2, VS4TAPInvoice.TIAPRefDate2, VS4TAPInvoice.TIAPPONo, VS4TAPInvoice.TIAPSOCode, VS4TAPInvoice.TIAPJobCode, VS4TAPInvoice.TIAPTJobNo, VS4TAPInvoice.TIAPTJbMLn, VS4TAPInvoice.TIAPTPrjCode, VS4TAPInvoice.TIAPTBraCode, VS4TAPInvoice.TIAPDeliveryDate, VS4TAPInvoice.TIAPDeliveryTo, VS4TAPInvoice.TIAPTAPNCode, VS4TAPInvoice.TIAPTAPUCode, VS4TAPInvoice.TIAPContactNote, VS4TAPInvoice.TIAPContactName, VS4TAPInvoice.TIAPSupplierName, VS4TAPInvoice.TIAPSupAddress, VS4TAPInvoice.TIAPConsignee, VS4TAPInvoice.TIAPNotifyParty, VS4TAPInvoice.TIAPPriceChannel, VS4TAPInvoice.TIAPDiscountList, VS4TAPInvoice.TIAPSubTotal, VS4TAPInvoice.TIAPDiscountText, VS4TAPInvoice.TIAPDiscountTotal, VS4TAPInvoice.TIAPNetTotal, VS4TAPInvoice.TIAPDepositText, VS4TAPInvoice.TIAPDeposit, VS4TAPInvoice.TIAPTotal, VS4TAPInvoice.TIAPTotalFOB, VS4TAPInvoice.TIAPTCurCode, VS4TAPInvoice.TIAPExchangeRate, VS4TAPInvoice.TIAPTotalInRate, VS4TAPInvoice.TIAPVATType, VS4TAPInvoice.TIAPVATRate, VS4TAPInvoice.TIAPTaxBase, VS4TAPInvoice.TIAPVATTotal, VS4TAPInvoice.TIAPGrandTotal, VS4TAPInvoice.TIAPNOTAXTotal, VS4TAPInvoice.TIAPWTaxBase, VS4TAPInvoice.TIAPWTaxRate, VS4TAPInvoice.TIAPWTaxTotal, VS4TAPInvoice.TIAPNetPayment, VS4TAPInvoice.TIAPBaseArrears, VS4TAPInvoice.TIAPArrears, VS4TAPInvoice.TIAPAdjustTotal, VS4TAPInvoice.TIAPBaseAVailable, VS4TAPInvoice.TIAPAVailable, VS4TAPInvoice.TIAPPremiumTotal, VS4TAPInvoice.TIAPBaseIncoType, VS4TAPInvoice.TIAPIncoType, VS4TAPInvoice.TIAPIncoterms, VS4TAPInvoice.TIAPOtherFee, VS4TAPInvoice.TIAPTransportFee, VS4TAPInvoice.TIAPHandlingFee, VS4TAPInvoice.TIAPFreightFee, VS4TAPInvoice.TIAPInsurance, VS4TAPInvoice.TIAPTransportDesc, VS4TAPInvoice.TIAPDuty, VS4TAPInvoice.TIAPShipBy, VS4TAPInvoice.TIAPCountryOrigin, VS4TAPInvoice.TIAPDestination, VS4TAPInvoice.TIAPCondition, VS4TAPInvoice.TIAPConditionDay, VS4TAPInvoice.TIAPCondition1, VS4TAPInvoice.TIAPConditionDay1, VS4TAPInvoice.TIAPPaymentNote, VS4TAPInvoice.TIAPStatementNote, VS4TAPInvoice.TIAPTShpCode, VS4TAPInvoice.TIAPDeliveryNote, VS4TAPInvoice.TIAPPackingNote, VS4TAPInvoice.TIAPDayAvailable, VS4TAPInvoice.TIAPDescription, VS4TAPInvoice.TIAPCustom1, VS4TAPInvoice.TIAPCustom2, VS4TAPInvoice.TIAPCustom3, VS4TAPInvoice.TIAPCustom4, VS4TAPInvoice.TIAPCustom5, VS4TAPInvoice.TIAPTPOTCode, VS4TAPInvoice.TIAPDeliveryStatus, VS4TAPInvoice.TIAPBillStatus, VS4TAPInvoice.TIAPCardFlag, VS4TAPInvoice.TIAPTaxFlag, VS4TAPInvoice.TIAPCreateBy, VS4TAPInvoice.TIAPEditCode, VS4TAPInvoice.TIAPEditBy, VS4TAPInvoice.TIAPEditDate, VS4TAPInvoice.TIAPConfirmStatus, VS4TAPInvoice.TIAPConfirmBy, VS4TAPInvoice.TIAPApproveStatus, VS4TAPInvoice.TIAPApproveBy, VS4TAPInvoice.TIAPApproveDate, VS4TAPInvoice.TIAPApproveNote, VS4TAPInvoice.TIAPRevision, VS4TAPInvoice.TIAPCancelStatus, VS4TAPInvoice.TIAPCancelBy, VS4TAPInvoice.TIAPCancelDate, VS4TAPInvoice.TIAPFlag1, VS4TAPInvoice.TIAPConditionType, VS4TAPInvoice.TIAPCustomNo, VS4TAPInvoice.TIAPCustomDate, VS4TAPInvoice.TIAPLoadingDate, VS4TAPInvoice.TIAPStartAgingDate, VS4TAPInvoice.TIAPIgnoreArrears, VS4TAPInvoice.TIAPNote, VS4TAPInvoice.TIAPReceiptStatus, VS4TAPInvoice.TIAPManualArrear, VS4TAPInvoice.TIAPWTaxBase2, VS4TAPInvoice.TIAPWTaxRate2, VS4TAPInvoice.TIAPWTaxTotal2, VS4TAPInvoice.TIAPExciseBase, VS4TAPInvoice.TIAPExciseRate, VS4TAPInvoice.TIAPExciseTotal, VS4TAPInvoice.TIAPRefNo3, VS4TAPInvoice.TIAPRefNo4, VS4TAPInvoice.TIAPLastPayDate, VS4TAPInvoice.TIAPInvoiceStatus, VS4TAPInvoice.TIAPCNStatus, VS4TAPInvoice.TIAPClientTaxNo, VS4TAPInvoice.TIAPBranchCode, VS4TAPInvoice.TIAPBranchName, VS4TAPInvoiceMB.TIPMTIAPNo, VS4TAPInvoiceMB.TIPMLn, VS4TAPInvoiceMB.TIPMType, VS4TAPInvoiceMB.TIPMGroupName, VS4TAPInvoiceMB.TIPMJobCode, VS4TAPInvoiceMB.TIPMTOExCode, VS4TAPInvoiceMB.TIPMTPdtCode, VS4TAPInvoiceMB.TIPMSerialNo, VS4TAPInvoiceMB.TIPMCustom1, VS4TAPInvoiceMB.TIPMCustom2, VS4TAPInvoiceMB.TIPMCustom3, VS4TAPInvoiceMB.TIPMCustom4, VS4TAPInvoiceMB.TIPMCustom5, VS4TAPInvoiceMB.TIPMShippingMark, VS4TAPInvoiceMB.TIPMProductCode, VS4TAPInvoiceMB.TIPMFactoryCode, VS4TAPInvoiceMB.TIPMProductName, VS4TAPInvoiceMB.TIPMMinimumOrder, VS4TAPInvoiceMB.TIPMMaximumOrder, VS4TAPInvoiceMB.TIPMCost, VS4TAPInvoiceMB.TIPMPrice, VS4TAPInvoiceMB.TIPMPerQuantity, VS4TAPInvoiceMB.TIPMUnitFactor, VS4TAPInvoiceMB.TIPMQuantityText, VS4TAPInvoiceMB.TIPMQuantity, VS4TAPInvoiceMB.TIPMAcceptError, VS4TAPInvoiceMB.TIPMUnitCalc, VS4TAPInvoiceMB.TIPMQuantityCalc, VS4TAPInvoiceMB.TIPMQuantityStock, VS4TAPInvoiceMB.TIPMTUntCode, VS4TAPInvoiceMB.TIPMQuantity2, VS4TAPInvoiceMB.TIPMTUntCode2, VS4TAPInvoiceMB.TIPMQuantity3, VS4TAPInvoiceMB.TIPMTUntCode3, VS4TAPInvoiceMB.TIPMDutyAmount, VS4TAPInvoiceMB.TIPMDivideExpense, VS4TAPInvoiceMB.TIPMCostAmount, VS4TAPInvoiceMB.TIPMAmount, VS4TAPInvoiceMB.TIPMDiscountText, VS4TAPInvoiceMB.TIPMDiscountTotal, VS4TAPInvoiceMB.TIPMNetAmount, VS4TAPInvoiceMB.TIPMTaxType, VS4TAPInvoiceMB.TIPMTaxBase, VS4TAPInvoiceMB.TIPMWTAXBase, VS4TAPInvoiceMB.TIPMAmountVAT, VS4TAPInvoiceMB.TIPMAmountWTAX, VS4TAPInvoiceMB.TIPMGetNumber, VS4TAPInvoiceMB.TIPMFreeCode, VS4TAPInvoiceMB.TIPMIsPremium, VS4TAPInvoiceMB.TIPMDescription, VS4TAPInvoiceMB.TIPMSourceNo, VS4TAPInvoiceMB.TIPMSourceLn, VS4TAPInvoiceMB.TIPMSourceDate, VS4TAPInvoiceMB.TIPMTLctCode, VS4TAPInvoiceMB.TIPMFlag1, VS4TAPInvoiceMB.TIPMQuantityCost, VS4TAPInvoiceMB.TIPMAVGWeighting, VS4TAPInvoiceMB.TIPMDiscountBill, VS4TAPInvoiceMB.TIPMDeposit, VS4TAPInvoiceMB.TIPMExciseBase, VS4TAPInvoiceMB.TIPMAmountExcise, VS4TAPInvoiceMB.TIPMWTAXBase2, VS4TAPInvoiceMB.TIPMAmountWTAX2, VS4TAPInvoiceMB.TIPMWTAXType, VS4TAPInvoiceMB.TIPMExciseType, VS4TProject.TPrjName, VS4TAP.TAPNName, VS4TCountry.TCouName, VS4TAPGroup.TAPGCode, VS4TAPGroup.TAPGName, VS4TAP.TAPNPhone, VS4TAP.TAPNFax, VS4TAP.TAPNTaxNo, VS4TAP.TAPNImage1, VS4TBranch.TBraName, VS4TAP.TAPNTBsTCode, VS4TBusinessType.TBstName, VS4TAP.TAPNTAPGCode, VS4TPOS.TPOSPrice, VS4TProduct.TPdtTPG1Code, VS4TProduct.TPdtTPSECode, VS4TProduct.TPdtName, VS4TPO.TPODDate, VS4TPOPTrans.TPPDType, VS4TAPInvoiceMBAOL.TIPATBraCode, VS4TAPInvoiceMBAOL.TIPATPrjCode, VS4TAPInvoiceMBAOL.TIPATDivCode, VS4TAPInvoiceMBAOL.TIPATDepCode, VS4TAPInvoiceMBAOL.TIPATSecCode, VS4TAPInvoiceMBAOL.TIPATSZGCode, VS4TAPInvoiceMBAOL.TIPATSZnCode, VS4TAPInvoiceMBAOL.TIPATSAeCode, VS4TAPInvoiceMBAOL.TIPATARNCode, VS4TAPInvoiceMBAOL.TIPATAPNCode, VS4TAPInvoiceMBAOL.TIPATAssCode, VS4TAPInvoiceMBAOL.TIPATEmpCode, VS4TAPInvoiceMBAOL.TIPATPdtCode, VS4TAPInvoiceMBAOL.TIPAFlag1, VS4TAP.TAPNName2, VS4TAP.TAPNAddressBill2, VS4TDeliveryINMB.TDIMDutyAmount, VS4TDeliveryIN.TDCIUseMethod, VS4TDeliveryIN.TDCIExchangeRate, VS4TDeliveryIN.TDCIDate, VS4TDeliveryIN.TDCIArticleType, VS4TPOPTransMB.TPTBQuantity, VS4TPOPTransMB.TPTBWDisQtyTotal, VS4TPOPTransMB.TPTBWDisQtyTotal2, VS4TPOPTransMB.TPTBWNetQty, VS4TPOPTransMB.TPTBDisRemark, VS4TPOS.TPOSType, VS4TProject_1.TPrjName AS VIAPProjectName, VS4TAPInvoiceMB.TIPMGRNNo, VS4TAPInvoice.TIAPTPIBCode, VS4TAPInvoiceBook.TPIBName, VS4TBranch.TBraAddressBill, VS4TAPInvoiceMB.TIPMStockFlag, VS4TAPBranch.TAPUName, VS4TAPInvoiceMBAOL.TIPATJobNo, VS4VAPBankFirst.TAPBAccountName, VS4VAPBankFirst.TAPBAccountNo, VS4VAPBankFirst.TAPBAccountBranch, VS4VAPBankFirst.TAPBTBnkCode 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) LEFT JOIN VS4TDeliveryIN ON VS4TAPInvoice.TIAPCustomNo = VS4TDeliveryIN.TDCINo) LEFT JOIN VS4TAPInvoiceBook ON VS4TAPInvoice.TIAPTPIBCode = VS4TAPInvoiceBook.TPIBCode) LEFT JOIN VS4TAPBranch ON (VS4TAPInvoice.TIAPTAPUCode = VS4TAPBranch.TAPUCode) AND (VS4TAPInvoice.TIAPTAPNCode = VS4TAPBranch.TAPUTAPNCode)) LEFT JOIN VS4VAPBankFirst ON VS4TAPInvoice.TIAPTAPNCode = VS4VAPBankFirst.TAPBTAPNCode) INNER JOIN (((((((VS4TAPInvoiceMB LEFT JOIN VS4TProduct ON VS4TAPInvoiceMB.TIPMTPdtCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) LEFT JOIN VS4TPOPTrans ON VS4TAPInvoiceMB.TIPMSourceNo = VS4TPOPTrans.TPPDNo) LEFT JOIN VS4TAPInvoiceMBAOL ON (VS4TAPInvoiceMB.TIPMLn = VS4TAPInvoiceMBAOL.TIPATIPMLn) AND (VS4TAPInvoiceMB.TIPMTIAPNo = VS4TAPInvoiceMBAOL.TIPATIPMTIAPNo)) LEFT JOIN VS4TDeliveryINMB ON (VS4TAPInvoiceMB.TIPMLn = VS4TDeliveryINMB.TDIMTIPMLn) AND (VS4TAPInvoiceMB.TIPMTIAPNo = VS4TDeliveryINMB.TDIMTIPMTIAPNo)) LEFT JOIN VS4TPOPTransMB ON (VS4TAPInvoiceMB.TIPMSourceLn = VS4TPOPTransMB.TPTBLn) AND (VS4TAPInvoiceMB.TIPMSourceNo = VS4TPOPTransMB.TPTBTPPDNo)) LEFT JOIN VS4TProject AS VS4TProject_1 ON VS4TAPInvoiceMBAOL.TIPATPrjCode = VS4TProject_1.TPrjCode) ON VS4TAPInvoice.TIAPNo = VS4TAPInvoiceMB.TIPMTIAPNo) ON VS4TAP.TAPNCode = VS4TAPInvoice.TIAPTAPNCode) ON VS4TCountry.TCouCode = VS4TAP.TAPNTCouCode
GO

CREATE VIEW VS4VAPInvoice2PV AS SELECT        VS4TAPInvoice.TIAPNo, VS4TAPInvoice.TIAPBalanceFlag, VS4TAPInvoice.TIAPType, VS4TAPInvoice.TIAPTPCACode, VS4TAPInvoice.TIAPMode, VS4TAPInvoice.TIAPDate,                           VS4TAPInvoice.TIAPDueDate, VS4TAPInvoice.TIAPGLMethod, VS4TAPInvoice.TIAPTGLTNo, VS4TAPInvoice.TIAPTaxNo, VS4TAPInvoice.TIAPRefNo, VS4TAPInvoice.TIAPRefDate,                           VS4TAPInvoice.TIAPRefNo2, VS4TAPInvoice.TIAPRefDate2, VS4TAPInvoice.TIAPPONo, VS4TAPInvoice.TIAPSOCode, VS4TAPInvoice.TIAPJobCode, VS4TAPInvoice.TIAPTJobNo,                           VS4TAPInvoice.TIAPTJbMLn, VS4TAPInvoice.TIAPTPrjCode, VS4TAPInvoice.TIAPTBraCode, VS4TAPInvoice.TIAPDeliveryDate, VS4TAPInvoice.TIAPDeliveryTo, VS4TAPInvoice.TIAPTAPNCode,                           VS4TAPInvoice.TIAPTAPUCode, VS4TAPInvoice.TIAPContactNote, VS4TAPInvoice.TIAPContactName, VS4TAPInvoice.TIAPSupplierName, VS4TAPInvoice.TIAPSupAddress, VS4TAPInvoice.TIAPConsignee,                           VS4TAPInvoice.TIAPNotifyParty, VS4TAPInvoice.TIAPPriceChannel, VS4TAPInvoice.TIAPDiscountList, VS4TAPInvoice.TIAPSubTotal, VS4TAPInvoice.TIAPDiscountText, VS4TAPInvoice.TIAPDiscountTotal,                           VS4TAPInvoice.TIAPNetTotal, VS4TAPInvoice.TIAPDepositText, VS4TAPInvoice.TIAPDeposit, VS4TAPInvoice.TIAPTotal, VS4TAPInvoice.TIAPTotalFOB, VS4TAPInvoice.TIAPTCurCode,                           VS4TAPInvoice.TIAPExchangeRate, VS4TAPInvoice.TIAPTotalInRate, VS4TAPInvoice.TIAPVATType, VS4TAPInvoice.TIAPVATRate, VS4TAPInvoice.TIAPTaxBase, VS4TAPInvoice.TIAPVATTotal,                           VS4TAPInvoice.TIAPGrandTotal, VS4TAPInvoice.TIAPNOTAXTotal, VS4TAPInvoice.TIAPWTaxBase, VS4TAPInvoice.TIAPWTaxRate, VS4TAPInvoice.TIAPWTaxTotal, VS4TAPInvoice.TIAPNetPayment,                           VS4TAPInvoice.TIAPBaseArrears, VS4TAPInvoice.TIAPArrears, VS4TAPInvoice.TIAPAdjustTotal, VS4TAPInvoice.TIAPBaseAVailable, VS4TAPInvoice.TIAPAVailable, VS4TAPInvoice.TIAPPremiumTotal,                           VS4TAPInvoice.TIAPBaseIncoType, VS4TAPInvoice.TIAPIncoType, VS4TAPInvoice.TIAPIncoterms, VS4TAPInvoice.TIAPOtherFee, VS4TAPInvoice.TIAPTransportFee, VS4TAPInvoice.TIAPHandlingFee,                           VS4TAPInvoice.TIAPFreightFee, VS4TAPInvoice.TIAPInsurance, VS4TAPInvoice.TIAPTransportDesc, VS4TAPInvoice.TIAPDuty, VS4TAPInvoice.TIAPShipBy, VS4TAPInvoice.TIAPCountryOrigin,                           VS4TAPInvoice.TIAPDestination, VS4TAPInvoice.TIAPCondition, VS4TAPInvoice.TIAPConditionDay, VS4TAPInvoice.TIAPCondition1, VS4TAPInvoice.TIAPConditionDay1, VS4TAPInvoice.TIAPPaymentNote,                           VS4TAPInvoice.TIAPStatementNote, VS4TAPInvoice.TIAPTShpCode, VS4TAPInvoice.TIAPDeliveryNote, VS4TAPInvoice.TIAPPackingNote, VS4TAPInvoice.TIAPDayAvailable,                           VS4TAPInvoice.TIAPDescription, VS4TAPInvoice.TIAPCustom1, VS4TAPInvoice.TIAPCustom2, VS4TAPInvoice.TIAPCustom3, VS4TAPInvoice.TIAPCustom4, VS4TAPInvoice.TIAPCustom5,                           VS4TAPInvoice.TIAPTPOTCode, VS4TAPInvoice.TIAPDeliveryStatus, VS4TAPInvoice.TIAPBillStatus, VS4TAPInvoice.TIAPCardFlag, VS4TAPInvoice.TIAPTaxFlag, VS4TAPInvoice.TIAPCreateCode,                           VS4TAPInvoice.TIAPCreateBy, VS4TAPInvoice.TIAPCreateDate, VS4TAPInvoice.TIAPEditCode, VS4TAPInvoice.TIAPEditBy, VS4TAPInvoice.TIAPEditDate, VS4TAPInvoice.TIAPConfirmStatus,                           VS4TAPInvoice.TIAPConfirmBy, VS4TAPInvoice.TIAPConfirmDate, VS4TAPInvoice.TIAPApproveStatus, VS4TAPInvoice.TIAPApproveBy, VS4TAPInvoice.TIAPApproveDate, VS4TAPInvoice.TIAPApproveNote,                           VS4TAPInvoice.TIAPRevision, VS4TAPInvoice.TIAPCancelStatus, VS4TAPInvoice.TIAPCancelNo, VS4TAPInvoice.TIAPCancelBy, VS4TAPInvoice.TIAPCancelDate, VS4TAPInvoice.TIAPCancelNote,                           VS4TAPInvoice.TIAPFlag1, VS4TAPInvoice.TIAPFlag2, VS4TAPInvoice.TIAPFlag3, VS4TAPInvoice.TIAPConditionType, VS4TAPInvoice.TIAPCustomNo, VS4TAPInvoice.TIAPCustomDate,                           VS4TAPInvoice.TIAPLoadingDate, VS4TAPInvoice.TIAPStartAgingDate, VS4TAPInvoice.TIAPIgnoreArrears, VS4TAPInvoice.TIAPNote, VS4TAPInvoice.TIAPReceiptStatus, VS4TAPInvoice.TIAPManualArrear,                           VS4TAPInvoice.TIAPWTaxBase2, VS4TAPInvoice.TIAPWTaxRate2, VS4TAPInvoice.TIAPWTaxTotal2, VS4TAPInvoice.TIAPExciseBase, VS4TAPInvoice.TIAPExciseRate, VS4TAPInvoice.TIAPExciseTotal,                           VS4TAPInvoice.TIAPRefNo3, VS4TAPInvoice.TIAPRefNo4, VS4TAPInvoice.TIAPLastPayDate, VS4TAPInvoice.TIAPInvoiceStatus, VS4TAPInvoice.TIAPCNStatus, VS4TAPInvoice.TIAPClientTaxNo,                           VS4TAPInvoice.TIAPBranchCode, VS4TAPInvoice.TIAPBranchName, VS4TAPInvoice.TIAPStockMode, VS4TAPInvoice.TIAPTPIBCode, VS4TAPInvoice.TIAPStockCard, VS4TAPInvoice.TIAPVATManual,                           VS4TAPInvoice.TIAPVATAdjust, VS4TAPInvoice.TIAPMultiJobPay, VS4TAPInvoice.TIAPPayPartial, VS4TAPInvoice.TIAPPartialAmount, VS4TAPInvoiceMB.TIPMTIAPNo, VS4TAPInvoiceMB.TIPMLn,                           VS4TAPInvoiceMB.TIPMType, VS4TAPInvoiceMB.TIPMGroupName, VS4TAPInvoiceMB.TIPMJobCode, VS4TAPInvoiceMB.TIPMTOExCode, VS4TAPInvoiceMB.TIPMTPdtCode,                           VS4TAPInvoiceMB.TIPMSerialNo, VS4TAPInvoiceMB.TIPMCustom1, VS4TAPInvoiceMB.TIPMCustom2, VS4TAPInvoiceMB.TIPMCustom3, VS4TAPInvoiceMB.TIPMCustom4,                           VS4TAPInvoiceMB.TIPMCustom5, VS4TAPInvoiceMB.TIPMShippingMark, VS4TAPInvoiceMB.TIPMProductCode, VS4TAPInvoiceMB.TIPMFactoryCode, VS4TAPInvoiceMB.TIPMProductName,                           VS4TAPInvoiceMB.TIPMMinimumOrder, VS4TAPInvoiceMB.TIPMMaximumOrder, VS4TAPInvoiceMB.TIPMCost, VS4TAPInvoiceMB.TIPMPrice, VS4TAPInvoiceMB.TIPMPerQuantity,                           VS4TAPInvoiceMB.TIPMUnitFactor, VS4TAPInvoiceMB.TIPMQuantityText, VS4TAPInvoiceMB.TIPMQuantity, VS4TAPInvoiceMB.TIPMAcceptError, VS4TAPInvoiceMB.TIPMUnitCalc,                           VS4TAPInvoiceMB.TIPMQuantityCalc, VS4TAPInvoiceMB.TIPMQuantityStock, VS4TAPInvoiceMB.TIPMTUntCode, VS4TAPInvoiceMB.TIPMQuantity2, VS4TAPInvoiceMB.TIPMTUntCode2,                           VS4TAPInvoiceMB.TIPMQuantity3, VS4TAPInvoiceMB.TIPMTUntCode3, VS4TAPInvoiceMB.TIPMDutyAmount, VS4TAPInvoiceMB.TIPMDivideExpense, VS4TAPInvoiceMB.TIPMCostAmount,                           VS4TAPInvoiceMB.TIPMAmount, VS4TAPInvoiceMB.TIPMDiscountText, VS4TAPInvoiceMB.TIPMDiscountTotal, VS4TAPInvoiceMB.TIPMNetAmount, VS4TAPInvoiceMB.TIPMTaxType,                           VS4TAPInvoiceMB.TIPMTaxBase, VS4TAPInvoiceMB.TIPMWTAXBase, VS4TAPInvoiceMB.TIPMAmountVAT, VS4TAPInvoiceMB.TIPMAmountWTAX, VS4TAPInvoiceMB.TIPMGetNumber,                           VS4TAPInvoiceMB.TIPMFreeCode, VS4TAPInvoiceMB.TIPMIsPremium, VS4TAPInvoiceMB.TIPMDescription, VS4TAPInvoiceMB.TIPMSourceNo, VS4TAPInvoiceMB.TIPMSourceLn,                           VS4TAPInvoiceMB.TIPMSourceDate, VS4TAPInvoiceMB.TIPMTWahCode, VS4TAPInvoiceMB.TIPMTLctCode, VS4TAPInvoiceMB.TIPMFlag1, VS4TAPInvoiceMB.TIPMFlag2, VS4TAPInvoiceMB.TIPMFlag3,                           VS4TAPInvoiceMB.TIPMQuantityCost, VS4TAPInvoiceMB.TIPMAVGWeighting, VS4TAPInvoiceMB.TIPMDiscountBill, VS4TAPInvoiceMB.TIPMDeposit, VS4TAPInvoiceMB.TIPMExciseBase,                           VS4TAPInvoiceMB.TIPMAmountExcise, VS4TAPInvoiceMB.TIPMWTAXBase2, VS4TAPInvoiceMB.TIPMAmountWTAX2, VS4TAPInvoiceMB.TIPMWTAXType, VS4TAPInvoiceMB.TIPMExciseType,                           VS4TAPInvoiceMB.TIPMTotalCN, VS4TAPInvoiceMB.TIPMTotalCNArr, VS4TAPInvoiceMB.TIPMWTAXSection, VS4TAPInvoiceMB.TIPMWTAXSection2, VS4TAPInvoiceMB.TIPMGRNNo,                           VS4TAPInvoiceMB.TIPMNAmountInRate, VS4TAPInvoiceMB.TIPMStockFlag, VS4TAPInvoiceMB.TIPMWeight, VS4TProject.TPrjName, VS4TAP.TAPNName, VS4TCountry.TCouName,                           VS4TAPGroup.TAPGCode, VS4TAPGroup.TAPGName, VS4TAP.TAPNPhone, VS4TAP.TAPNFax, VS4TAP.TAPNTaxNo, VS4TAP.TAPNImage1, VS4TCountry.TCouName2, VS4TBranch.TBraName,                           VS4TAP.TAPNTBsTCode, VS4TBusinessType.TBstName, VS4TAP.TAPNTAPGCode, VS4TPOS.TPOSPrice, VS4TProduct.TPdtTPG1Code, VS4TProduct.TPdtTPSECode, VS4TProduct.TPdtGroupReport,                           VS4TProduct.TPdtName, VS4TPO.TPODDate, VS4TPOPTrans.TPPDType, VS4TAPVoucher.TAPVNote, VS4TAPVoucherPay.TPVPPaymentType, VS4TAPVoucherPay.TPVPLn,                           VS4TChequeSub.TCHSChqDate, VS4TChequeSub.TCHSNo, VS4TAPVDocRef.TPVRWTAXTotal, VS4TChequeSub.TCHSTBnkCode, VS4TChequeSub.TCHSTotal, VS4TAPVoucher.TAPVDate,                           VS4TAPVDocRef.TPVRRefDocType, VS4TAPVoucherPay.TPVPFee, VS4TPOS.TPOSType, VS4TAPVoucherPay.TPVPAmountInRate, VS4TAPVoucherPay.TPVPCashDate, VS4TAPVoucher.TAPVNo,                           VS4TAPVDocRef.TPVRRefAPBillNo, VS4TAPVoucher.TAPVFee FROM            VS4TCountry INNER JOIN                          VS4TChequeSub RIGHT OUTER JOIN                          VS4TAP LEFT OUTER JOIN                          VS4TAPGroup ON VS4TAP.TAPNTAPGCode = VS4TAPGroup.TAPGCode LEFT OUTER JOIN                          VS4TBusinessType ON VS4TAP.TAPNTBsTCode = VS4TBusinessType.TBsTCode INNER JOIN                          VS4TAPVoucher RIGHT OUTER JOIN                          VS4TAPInvoice LEFT OUTER JOIN                          VS4TProject ON VS4TAPInvoice.TIAPTPrjCode = VS4TProject.TPrjCode LEFT OUTER JOIN                          VS4TBranch ON VS4TAPInvoice.TIAPTBraCode = VS4TBranch.TBraCode LEFT OUTER JOIN                          VS4TPO ON VS4TAPInvoice.TIAPPONo = VS4TPO.TPODNo LEFT OUTER JOIN                          VS4TAPVDocRef ON VS4TAPInvoice.TIAPNo = VS4TAPVDocRef.TPVRRefDocNo INNER JOIN                          VS4TAPInvoiceMB LEFT OUTER JOIN                          VS4TProduct ON VS4TAPInvoiceMB.TIPMTPdtCode = VS4TProduct.TPdtCode LEFT OUTER JOIN                          VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode LEFT OUTER JOIN                          VS4TPOPTrans ON VS4TAPInvoiceMB.TIPMSourceNo = VS4TPOPTrans.TPPDNo ON VS4TAPInvoice.TIAPNo = VS4TAPInvoiceMB.TIPMTIAPNo ON                           VS4TAPVoucher.TAPVNo = VS4TAPVDocRef.TPVRTAPVNo LEFT OUTER JOIN                          VS4TAPVoucherPay LEFT OUTER JOIN                          VS4TChequeSub2PV ON VS4TAPVoucherPay.TPVPLn = VS4TChequeSub2PV.TS2PTPVPLn AND VS4TAPVoucherPay.TPVPTAPVNo = VS4TChequeSub2PV.TS2PTPVPTAPVNo ON                           VS4TAPVoucher.TAPVNo = VS4TAPVoucherPay.TPVPTAPVNo ON VS4TAP.TAPNCode = VS4TAPInvoice.TIAPTAPNCode ON VS4TChequeSub.TCHSNo = VS4TChequeSub2PV.TS2PTCHSNo ON                           VS4TCountry.TCouCode = VS4TAP.TAPNTCouCode
GO

CREATE VIEW VS4VAPInvoiceADJH AS  SELECT VS4TAPInvoice.*, VS4TProject.TPrjName, VS4TAP.TAPNName, VS4TCountry.TCouName, VS4TAPGroup.TAPGCode, VS4TAPGroup.TAPGName, VS4TAP.TAPNPhone, VS4TAP.TAPNFax, VS4TAP.TAPNTaxNo, VS4TAP.TAPNImage1, VS4TCountry.TCouName2, VS4TBranch.TBraName, VS4TAP.TAPNTBsTCode, VS4TBusinessType.TBstName, VS4TAP.TAPNTAPGCode, VS4TPO.TPODDate, VS4TAPInvoiceADJ.TIPJIVTotal, VS4TAPInvoiceADJ.TIPJCNTotal, VS4TAPInvoiceADJ.TIPJDBTotal, VS4TAPInvoiceADJ.TIPJIVArrear, VS4TAPInvoiceADJ.TIPJCNArrear, VS4TAPInvoiceADJ.TIPJDBArrear, VS4TAPInvoiceADJ.TIPJTotalArrear, VS4TAPInvoiceADJ.TIPJIVNetPayment, VS4TAPInvoiceADJ.TIPJCNNetPayment, VS4TAPInvoiceADJ.TIPJDBNetPayment, VS4TAPInvoiceADJ.TIPJRefCN, VS4TAPInvoiceADJ.TIPJRefDB, VS4TAPInvoiceADJ.TIPJRefPayment 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) LEFT JOIN VS4TAPInvoiceADJ ON VS4TAPInvoice.TIAPNo = VS4TAPInvoiceADJ.TIPJNo) ON VS4TAP.TAPNCode = VS4TAPInvoice.TIAPTAPNCode) ON VS4TCountry.TCouCode = VS4TAP.TAPNTCouCode
GO

CREATE VIEW VS4VAPInvoiceArrH AS  SELECT VS4TAPInvoice.*, VS4TAP.*, VS4TProject.TPrjName, VS4TAPGroup.TAPGCode, VS4TAPGroup.TAPGName, VS4TBusinessType.TBstName, VS4TBranch.TBraName FROM VS4TProject INNER JOIN (VS4TCountry RIGHT JOIN (VS4TBusinessType RIGHT JOIN (((VS4TAP LEFT JOIN VS4TAPGroup ON VS4TAP.TAPNTAPGCode = VS4TAPGroup.TAPGCode) 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
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, 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 VS4VAPInvoiceDep AS  SELECT VS4TAPInvoiceDep.*, VS4TAPInvoice.* FROM VS4TAPInvoice INNER JOIN VS4TAPInvoiceDep ON VS4TAPInvoice.TIAPNo = VS4TAPInvoiceDep.TIPDTIAPNo
GO

CREATE VIEW VS4VAPInvoiceH AS  SELECT VS4TAPInvoice.*, VS4TProject.TPrjName, VS4TAP.TAPNName, VS4TCountry.TCouName, VS4TAPGroup.TAPGCode, VS4TAPGroup.TAPGName, VS4TAP.TAPNPhone, VS4TAP.TAPNFax, VS4TAP.TAPNTaxNo, VS4TAP.TAPNImage1, VS4TCountry.TCouName2, VS4TBranch.TBraName, VS4TAP.TAPNTBsTCode, VS4TBusinessType.TBstName, VS4TAP.TAPNTAPGCode, VS4TPO.TPODDate, VS4TAPInvoiceBook.TPIBName 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) LEFT JOIN VS4TAPInvoiceBook ON VS4TAPInvoice.TIAPTPIBCode = VS4TAPInvoiceBook.TPIBCode) ON VS4TAP.TAPNCode = VS4TAPInvoice.TIAPTAPNCode) ON VS4TCountry.TCouCode = VS4TAP.TAPNTCouCode
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, VS4TChequeSub.TCHSNo, VS4TChequeSub.TCHSChqDate, VS4TChequeSub.TCHSPayTo, VS4TAPInvoice_1.TIAPAVailable AS VPIPAVailable FROM VS4TCountry INNER JOIN (VS4TCompanyBank RIGHT 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 VS4TAPInvoice AS VS4TAPInvoice_1 ON VS4TAPInvoicePay.TPIPDocNo = VS4TAPInvoice_1.TIAPNo) 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 VS4TCompanyBank.TCBBNo = VS4TAPInvoicePay.TPIPTCBBNo) ON VS4TCountry.TCouCode = VS4TAP.TAPNTCouCode
GO

CREATE VIEW VS4VAPInvoiceR AS  SELECT VS4TAPInvoice.TIAPNo, VS4TAPInvoice.TIAPBalanceFlag, VS4TAPInvoice.TIAPType, VS4TAPInvoice.TIAPTPCACode, VS4TAPInvoice.TIAPMode, VS4TAPInvoice.TIAPDate, VS4TAPInvoice.TIAPDueDate, VS4TAPInvoice.TIAPGLMethod, VS4TAPInvoice.TIAPTGLTNo, VS4TAPInvoice.TIAPTaxNo, VS4TAPInvoice.TIAPRefNo, VS4TAPInvoice.TIAPRefDate, VS4TAPInvoice.TIAPRefNo2, VS4TAPInvoice.TIAPRefDate2, VS4TAPInvoice.TIAPPONo, VS4TAPInvoice.TIAPSOCode, VS4TAPInvoice.TIAPJobCode, VS4TAPInvoice.TIAPTJobNo, VS4TAPInvoice.TIAPTJbMLn, VS4TAPInvoice.TIAPTPrjCode, VS4TAPInvoice.TIAPTBraCode, VS4TAPInvoice.TIAPDeliveryDate, VS4TAPInvoice.TIAPDeliveryTo, VS4TAPInvoice.TIAPTAPNCode, VS4TAPInvoice.TIAPTAPUCode, VS4TAPInvoice.TIAPContactNote, VS4TAPInvoice.TIAPContactName, VS4TAPInvoice.TIAPSupplierName, VS4TAPInvoice.TIAPSupAddress, VS4TAPInvoice.TIAPConsignee, VS4TAPInvoice.TIAPNotifyParty, VS4TAPInvoice.TIAPPriceChannel, VS4TAPInvoice.TIAPDiscountList, VS4TAPInvoice.TIAPSubTotal, VS4TAPInvoice.TIAPDiscountText, VS4TAPInvoice.TIAPDiscountTotal, VS4TAPInvoice.TIAPNetTotal, VS4TAPInvoice.TIAPDepositText, VS4TAPInvoice.TIAPDeposit, VS4TAPInvoice.TIAPTotal, VS4TAPInvoice.TIAPTotalFOB, VS4TAPInvoice.TIAPTCurCode, VS4TAPInvoice.TIAPExchangeRate, VS4TAPInvoice.TIAPTotalInRate, VS4TAPInvoice.TIAPVATType, VS4TAPInvoice.TIAPVATRate, VS4TAPInvoice.TIAPTaxBase, VS4TAPInvoice.TIAPVATTotal, VS4TAPInvoice.TIAPGrandTotal, VS4TAPInvoice.TIAPNOTAXTotal, VS4TAPInvoice.TIAPWTaxBase, VS4TAPInvoice.TIAPWTaxRate, VS4TAPInvoice.TIAPWTaxTotal, VS4TAPInvoice.TIAPNetPayment, VS4TAPInvoice.TIAPBaseArrears, VS4TAPInvoice.TIAPArrears, VS4TAPInvoice.TIAPAdjustTotal, VS4TAPInvoice.TIAPBaseAVailable, VS4TAPInvoice.TIAPAVailable, VS4TAPInvoice.TIAPPremiumTotal, VS4TAPInvoice.TIAPBaseIncoType, VS4TAPInvoice.TIAPIncoType, VS4TAPInvoice.TIAPIncoterms, VS4TAPInvoice.TIAPOtherFee, VS4TAPInvoice.TIAPTransportFee, VS4TAPInvoice.TIAPHandlingFee, VS4TAPInvoice.TIAPFreightFee, VS4TAPInvoice.TIAPInsurance, VS4TAPInvoice.TIAPTransportDesc, VS4TAPInvoice.TIAPDuty, VS4TAPInvoice.TIAPShipBy, VS4TAPInvoice.TIAPCountryOrigin, VS4TAPInvoice.TIAPDestination, VS4TAPInvoice.TIAPCondition, VS4TAPInvoice.TIAPConditionDay, VS4TAPInvoice.TIAPCondition1, VS4TAPInvoice.TIAPConditionDay1, VS4TAPInvoice.TIAPPaymentNote, VS4TAPInvoice.TIAPStatementNote, VS4TAPInvoice.TIAPTShpCode, VS4TAPInvoice.TIAPDeliveryNote, VS4TAPInvoice.TIAPPackingNote, VS4TAPInvoice.TIAPDayAvailable, VS4TAPInvoice.TIAPDescription, VS4TAPInvoice.TIAPCustom1, VS4TAPInvoice.TIAPCustom2, VS4TAPInvoice.TIAPCustom3, VS4TAPInvoice.TIAPCustom4, VS4TAPInvoice.TIAPCustom5, VS4TAPInvoice.TIAPTPOTCode, VS4TAPInvoice.TIAPDeliveryStatus, VS4TAPInvoice.TIAPBillStatus, VS4TAPInvoice.TIAPCardFlag, VS4TAPInvoice.TIAPTaxFlag, VS4TAPInvoice.TIAPEditCode, VS4TAPInvoice.TIAPEditBy, VS4TAPInvoice.TIAPEditDate, VS4TAPInvoice.TIAPConfirmStatus, VS4TAPInvoice.TIAPConfirmBy, VS4TAPInvoice.TIAPConfirmDate, VS4TAPInvoice.TIAPApproveStatus, VS4TAPInvoice.TIAPApproveBy, VS4TAPInvoice.TIAPApproveDate, VS4TAPInvoice.TIAPApproveNote, VS4TAPInvoice.TIAPRevision, VS4TAPInvoice.TIAPCancelStatus, VS4TAPInvoice.TIAPCancelBy, VS4TAPInvoice.TIAPCancelDate, VS4TAPInvoice.TIAPCancelNote, VS4TAPInvoice.TIAPFlag1, VS4TAPInvoice.TIAPConditionType, VS4TAPInvoice.TIAPCustomNo, VS4TAPInvoice.TIAPCustomDate, VS4TAPInvoice.TIAPLoadingDate, VS4TAPInvoice.TIAPStartAgingDate, VS4TAPInvoice.TIAPIgnoreArrears, VS4TAPInvoice.TIAPNote, VS4TAPInvoice.TIAPReceiptStatus, VS4TAPInvoice.TIAPManualArrear, VS4TAPInvoice.TIAPWTaxBase2, VS4TAPInvoice.TIAPWTaxRate2, VS4TAPInvoice.TIAPWTaxTotal2, VS4TAPInvoice.TIAPExciseBase, VS4TAPInvoice.TIAPExciseRate, VS4TAPInvoice.TIAPExciseTotal, VS4TAPInvoice.TIAPRefNo3, VS4TAPInvoice.TIAPRefNo4, VS4TAPInvoice.TIAPLastPayDate, VS4TAPInvoice.TIAPInvoiceStatus, VS4TAPInvoice.TIAPCNStatus, VS4TAPInvoice.TIAPClientTaxNo, VS4TAPInvoice.TIAPBranchCode, VS4TAPInvoice.TIAPBranchName, VS4TAPInvoice.TIAPStockMode, VS4TAPInvoiceMB.TIPMTIAPNo, VS4TAPInvoiceMB.TIPMLn, VS4TAPInvoiceMB.TIPMType, VS4TAPInvoiceMB.TIPMGroupName, VS4TAPInvoiceMB.TIPMJobCode, VS4TAPInvoiceMB.TIPMTOExCode, VS4TAPInvoiceMB.TIPMTPdtCode, VS4TAPInvoiceMB.TIPMSerialNo, VS4TAPInvoiceMB.TIPMCustom1, VS4TAPInvoiceMB.TIPMCustom2, VS4TAPInvoiceMB.TIPMCustom3, VS4TAPInvoiceMB.TIPMCustom4, VS4TAPInvoiceMB.TIPMCustom5, VS4TAPInvoiceMB.TIPMShippingMark, VS4TAPInvoiceMB.TIPMProductCode, VS4TAPInvoiceMB.TIPMFactoryCode, VS4TAPInvoiceMB.TIPMProductName, VS4TAPInvoiceMB.TIPMMinimumOrder, VS4TAPInvoiceMB.TIPMMaximumOrder, VS4TAPInvoiceMB.TIPMCost, VS4TAPInvoiceMB.TIPMPrice, VS4TAPInvoiceMB.TIPMPerQuantity, VS4TAPInvoiceMB.TIPMUnitFactor, VS4TAPInvoiceMB.TIPMQuantityText, VS4TAPInvoiceMB.TIPMQuantity, VS4TAPInvoiceMB.TIPMAcceptError, VS4TAPInvoiceMB.TIPMUnitCalc, VS4TAPInvoiceMB.TIPMQuantityCalc, VS4TAPInvoiceMB.TIPMQuantityStock, VS4TAPInvoiceMB.TIPMTUntCode, VS4TAPInvoiceMB.TIPMQuantity2, VS4TAPInvoiceMB.TIPMTUntCode2, VS4TAPInvoiceMB.TIPMQuantity3, VS4TAPInvoiceMB.TIPMTUntCode3, VS4TAPInvoiceMB.TIPMDutyAmount, VS4TAPInvoiceMB.TIPMDivideExpense, VS4TAPInvoiceMB.TIPMCostAmount, VS4TAPInvoiceMB.TIPMAmount, VS4TAPInvoiceMB.TIPMDiscountText, VS4TAPInvoiceMB.TIPMDiscountTotal, VS4TAPInvoiceMB.TIPMNetAmount, VS4TAPInvoiceMB.TIPMTaxType, VS4TAPInvoiceMB.TIPMTaxBase, VS4TAPInvoiceMB.TIPMWTAXBase, VS4TAPInvoiceMB.TIPMAmountVAT, VS4TAPInvoiceMB.TIPMAmountWTAX, VS4TAPInvoiceMB.TIPMGetNumber, VS4TAPInvoiceMB.TIPMFreeCode, VS4TAPInvoiceMB.TIPMIsPremium, VS4TAPInvoiceMB.TIPMDescription, VS4TAPInvoiceMB.TIPMSourceNo, VS4TAPInvoiceMB.TIPMSourceLn, VS4TAPInvoiceMB.TIPMSourceDate, VS4TAPInvoiceMB.TIPMTLctCode, VS4TAPInvoiceMB.TIPMFlag1, VS4TAPInvoiceMB.TIPMQuantityCost, VS4TAPInvoiceMB.TIPMAVGWeighting, VS4TAPInvoiceMB.TIPMDiscountBill, VS4TAPInvoiceMB.TIPMDeposit, VS4TAPInvoiceMB.TIPMExciseBase, VS4TAPInvoiceMB.TIPMAmountExcise, VS4TAPInvoiceMB.TIPMWTAXBase2, VS4TAPInvoiceMB.TIPMAmountWTAX2, VS4TAPInvoiceMB.TIPMWTAXType, VS4TAPInvoiceMB.TIPMExciseType, VS4TProject.TPrjName, VS4TAP.TAPNName, VS4TCountry.TCouName, VS4TAPGroup.TAPGCode, VS4TAPGroup.TAPGName, VS4TAP.TAPNPhone, VS4TAP.TAPNFax, VS4TAP.TAPNTaxNo, VS4TAP.TAPNImage1, VS4TCountry.TCouName2, VS4TBranch.TBraName, VS4TAP.TAPNTBsTCode, VS4TBusinessType.TBstName, VS4TAP.TAPNTAPGCode, VS4TPOS.TPOSPrice, VS4TProduct.TPdtTPG1Code, VS4TProduct.TPdtTPSECode, VS4TProduct.TPdtGroupReport, VS4TProduct.TPdtName, VS4TPO.TPODDate, VS4TPOPTrans.TPPDType, TIPATIPMTIAPNo, TIPATIPMLn, TIPATBraCode, TIPATPrjCode, TIPATDivCode, TIPATDepCode, TIPATSecCode, TIPATSZGCode, TIPATSZnCode, TIPATSAeCode, TIPATARNCode, TIPATAPNCode, TIPATAssCode, TIPATEmpCode, TIPATPdtCode, TIPAFlag1, TIPATJobNo, VS4TAP.TAPNName2, VS4TAP.TAPNAddressBill2, VS4TDeliveryINMB.TDIMDutyAmount, VS4TDeliveryIN.TDCIUseMethod, VS4TDeliveryIN.TDCIExchangeRate, VS4TDeliveryIN.TDCIDate, VS4TDeliveryIN.TDCIArticleType, VS4TPOPTransMB.TPTBQuantity, VS4TPOPTransMB.TPTBWDisQtyTotal, VS4TPOPTransMB.TPTBWDisQtyTotal2, VS4TPOPTransMB.TPTBWNetQty, VS4TPOPTransMB.TPTBDisRemark, VS4TPOS.TPOSType, VS4TProject_1.TPrjName AS VIPRProjectName, VS4TAPInvoiceMB.TIPMGRNNo, VS4TAPInvoice.TIAPTPIBCode, VS4TAPInvoiceBook.TPIBName, VS4TAPInvoiceMB.TIPMStockFlag 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) LEFT JOIN VS4TDeliveryIN ON VS4TAPInvoice.TIAPCustomNo = VS4TDeliveryIN.TDCINo) LEFT JOIN VS4TAPInvoiceBook ON VS4TAPInvoice.TIAPTPIBCode=VS4TAPInvoiceBook.TPIBCode) INNER JOIN (((((((VS4TAPInvoiceMB LEFT JOIN VS4TProduct ON VS4TAPInvoiceMB.TIPMTPdtCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) LEFT JOIN VS4TPOPTrans ON VS4TAPInvoiceMB.TIPMSourceNo = VS4TPOPTrans.TPPDNo) LEFT JOIN VS4TAPInvoiceMBAOL ON (VS4TAPInvoiceMB.TIPMLn = VS4TAPInvoiceMBAOL.TIPATIPMLn) AND (VS4TAPInvoiceMB.TIPMTIAPNo = VS4TAPInvoiceMBAOL.TIPATIPMTIAPNo)) LEFT JOIN VS4TDeliveryINMB ON (VS4TAPInvoiceMB.TIPMLn = VS4TDeliveryINMB.TDIMTIPMLn) AND (VS4TAPInvoiceMB.TIPMTIAPNo = VS4TDeliveryINMB.TDIMTIPMTIAPNo)) LEFT JOIN VS4TPOPTransMB ON (VS4TAPInvoiceMB.TIPMSourceLn = VS4TPOPTransMB.TPTBLn) AND (VS4TAPInvoiceMB.TIPMSourceNo = VS4TPOPTransMB.TPTBTPPDNo)) LEFT JOIN VS4TProject AS VS4TProject_1 ON VS4TAPInvoiceMBAOL.TIPATPrjCode = VS4TProject_1.TPrjCode) ON VS4TAPInvoice.TIAPNo = VS4TAPInvoiceMB.TIPMTIAPNo) ON VS4TAP.TAPNCode = VS4TAPInvoice.TIAPTAPNCode) ON VS4TCountry.TCouCode = VS4TAP.TAPNTCouCode
GO

CREATE VIEW VS4VAPLog AS  SELECT VS4TEmployee.TEmpFullName, VS4TEmployee.TEmpFullName2, VS4TAPLog.*, VS4TAP.*, VS4TAP2.* FROM (VS4TAP INNER JOIN VS4TAP2 ON VS4TAP.TAPNCode = VS4TAP2.TAP2TAPNCode) INNER JOIN (VS4TAPLog LEFT JOIN VS4TEmployee ON VS4TAPLog.TPLgTEmpCode = VS4TEmployee.TEmpCode) ON VS4TAP.TAPNCode = VS4TAPLog.TPLgTAPNCode
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, VS4TAR3.TAR3NickName, VS4TAR3.TAR3FirstName, VS4TAR3.TAR3LastName, VS4TAR3.TAR3BirthDay, VS4TSaleArea.TSAETEmpCode, VS4TContinent.TCTNName, VS4TAR3.TAR3CitizenNo, VS4TAR3.TAR3SourceType, VS4TAR3.TAR3Acceptance, VS4TAR3.TAR3ReceiveInfo, VS4TAR3.TAR3OcupationInfo, VS4TAR3.TAR3Hobby, VS4TAR3.TAR3Salary, VS4TAR3.TAR3SalaryTo, VS4TARGroup2.TRG2Name, VS4TARGroup3.TRG3Name FROM (VS4TCountry LEFT JOIN VS4TContinent ON VS4TCountry.TCouTCTNCode = VS4TContinent.TCTNCode) 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) LEFT JOIN VS4TARGroup2 ON VS4TAR.TARNTRG2Code = VS4TARGroup2.TRG2Code) LEFT JOIN VS4TARGroup3 ON VS4TAR.TARNTRG3Code = VS4TARGroup3.TRG3Code) 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 VS4VARAppCallLog AS  SELECT VS4TARAppointment.*, VS4TAR.*, VS4TARAppointPdt.*, VS4TProductLine.TPdLName, VS4TProductLine.TPdLName2, VS4TProductBook.TPBGPaxMin, VS4TProductBook.TPBGPaxMax, VS4TPOS.TPOSPrice, VS4TPOS.TPOSTPSGCode, VS4TPOS.TPOSPeriod, VS4TAR3.TAR3Gender, VS4TPOS.TPOSSaleCode, VS4TProduct.TPdtCode, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtStartDate, VS4TProduct.TPdtEndDate, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtTPSECode, VS4TProduct.TPdtTPS2Code, VS4TProduct.TPdtTPS3Code, VS4TProduct.TPdtTPS4Code, VS4TProduct.TPdtTPG1Code, VS4TProduct.TPdtTPG2Code, VS4TProduct.TPdtTPG3Code, VS4TProduct.TPdtTPG4Code, VS4TProduct.TPdtTUntCode, VS4TAR2Product.*, VS4TEmployee.TEmpFullName, VS4TEmployee.TEmpNickName, VS4TARStatus.TARSIsProspect, VS4TAccountDay.TDayWeekDay, VS4TAccountDay.TDayWeek, VS4TAccountDay.TDayMonth, VS4TAccountDay.TDayQuarter, VS4TAccountDay.TDayYear, VS4TAccountDay.TDayPeriod FROM (VS4TEmployee RIGHT JOIN ((((VS4TARStatus RIGHT JOIN (VS4TAR LEFT JOIN VS4TAR2Product ON VS4TAR.TARNCode = VS4TAR2Product.TPHITARNCode) ON VS4TARStatus.TARSAlias = VS4TAR.TARNTARSAlias) LEFT JOIN VS4TAR2 ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) LEFT JOIN VS4TAR3 ON VS4TAR.TARNCode = VS4TAR3.TAR3TARNCode) INNER JOIN ((((((VS4TARAppointment LEFT JOIN VS4TARAppointPdt ON VS4TARAppointment.TARANo = VS4TARAppointPdt.TARRTARANo) LEFT JOIN VS4TProduct ON VS4TARAppointPdt.TARRTPdtCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TProductBook ON VS4TProduct.TPdtCode = VS4TProductBook.TPBGTPdtCode) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) LEFT JOIN VS4TProductLine ON VS4TARAppointPdt.TARRTPDLCode = VS4TProductLine.TPdLCode) LEFT JOIN VS4TAccountDay ON VS4TARAppointment.TARADate = VS4TAccountDay.TDayDate) ON VS4TAR.TARNCode = VS4TARAppointment.TARATARNCode) ON VS4TEmployee.TEmpCode = VS4TARAppointment.TARATEmpCode) LEFT JOIN VS4TProduct2 ON VS4TProduct.TPdtCode = VS4TProduct2.TPd2TPdtCode
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, (TARADate-day(TARADate)+1) AS VARDPeriod FROM VS4TARAppointment GROUP BY VS4TARAppointment.TARATARNCode, Year(TARADate), Month(TARADate), Day(TARADate), (TARADate-day(TARADate)+1)
GO

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

CREATE VIEW VS4VARAppointComp AS  SELECT VS4TARAppointment.*, VS4TAR.*, VS4TAR2.*, Year(TARADate) AS VARCYear, Month(TARADate) AS VARCMonth, 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 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
GO

CREATE VIEW VS4VARAppointment AS  SELECT VS4TARAppointment.*, VS4TAR.*, VS4TAR2.*, VS4TSaleArea.*, VS4TSaleZone.*, VS4TAppointType.*, Year(TARADate) AS VARBYear, Month(TARADate) AS VARBMonth, TARADate-Day(TARADate)+1 AS VARBPeriod, 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 ON VS4TAppointType.TAtyCode = VS4TARAppointment.TARATAtyCode) ON VS4TAR.TARNCode = VS4TARAppointment.TARATARNCode) ON VS4TEmployee.TEmpCode = VS4TARAppointment.TARATEmpCode) ON VS4TSaleZone.TSZnCode = VS4TSaleArea.TSaeTSZnCode
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, VS4TSaleArea.TSAeCode, CAST(CONVERT(VARCHAR, TARLTACPTACYID) + '-' + CONVERT(VARCHAR, TARLTACPID) + '-01' AS DATETIME) AS VARLPeriod 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 VS4VARBank AS  SELECT VS4TAR.*, VS4TARBank.*, VS4TBank.* FROM (VS4TAR INNER JOIN VS4TARBank ON VS4TAR.TARNCode = VS4TARBank.TARBTARNCode) LEFT JOIN VS4TBank ON VS4TARBank.TARBTBnkCode = VS4TBank.TBnkCode
GO

CREATE VIEW VS4VARBill AS SELECT VS4TARBill.*, VS4TARBillMB.*, VS4TAR.TARNName, VS4TAR2.TAR2SaleCode, VS4TEmployee.TEmpFullName,                    VS4TAR2.TAR2TPRVCode, VS4TProvince.TPrvName, VS4TProject.TPrjName, 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, VS4TAR.TARNChequeDay,                    VS4TAR.TARNChequeAddMonth, Vs4TARInvoice.TIvoConditionDay, Vs4TARInvoice.TIvoStartAgingDate, VS4TAR.TARNPriceChannel, VS4TAR.TARNIECNo, VS4TAR2.TAR2BillNote,                    Vs4TARInvoice.TIvoArrears, VS4TAR.TARNPhone, VS4TAR.TARNFax, VS4TAR.TARNMobile, VS4TAR.TARNTaxNo, VS4TAR.TARNVirtualAccNo, Vs4TARInvoice.TIvoSubTotal,                    Vs4TARInvoice.TIvoDiscountTotal, Vs4TARInvoice.TIvoTaxBase, Vs4TARInvoice.TIvoVATType, Vs4TARInvoice.TIvoCondition, Vs4TARInvoice.TIvoGrandTotal, Vs4TARInvoice.TIvoAvailable,                    Vs4TARInvoice.TIvoNetPayment, Vs4TARInvoice.TIvoCommissionBase, Vs4TARInvoice.TIvoCommissionRate, Vs4TARInvoice.TIvoCommission FROM     VS4TARBill LEFT OUTER JOIN                   VS4TAR ON VS4TARBill.TBilTARNCode = VS4TAR.TARNCode LEFT OUTER JOIN                   VS4TProject ON VS4TARBill.TBilTPrjCode = VS4TProject.TPrjCode LEFT OUTER JOIN                   VS4TBranch ON VS4TARBill.TBilTBraCode = VS4TBranch.TBraCode LEFT OUTER JOIN                   VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode LEFT OUTER JOIN                   VS4TBusinessType ON VS4TAR.TARNTBsTCode = VS4TBusinessType.TBsTCode LEFT OUTER JOIN                   VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode LEFT OUTER JOIN                   VS4TCountry ON VS4TAR.TARNTCouCode = VS4TCountry.TCouCode LEFT OUTER JOIN                   VS4TAR2 LEFT OUTER JOIN                   VS4TEmployee ON VS4TAR2.TAR2SaleCode = VS4TEmployee.TEmpCode LEFT OUTER JOIN                   VS4TProvince ON VS4TAR2.TAR2TPRVCode = VS4TProvince.TPrvCode ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode INNER JOIN                   VS4TARBillMB LEFT OUTER JOIN                   Vs4TARInvoice ON VS4TARBillMB.TBMBTIvANo = Vs4TARInvoice.TIvoNo LEFT OUTER JOIN                   VS4TARDebitNote ON VS4TARBillMB.TBMBTIvANo = VS4TARDebitNote.TDBNNo LEFT OUTER JOIN                   VS4TARCreditNote ON VS4TARBillMB.TBMBTIvANo = 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, 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, VS4TARInvoiceMB.TIoMDiscountText, VS4TARInvoiceMB.TIoMNetAmount, VS4TARCreditNoteMB.TRCMDiscountText, VS4TARCreditNoteMB.TRCMNetAmount, VS4TARDebitNoteMB.TDBMDiscountText, VS4TARDebitNoteMB.TDBMNetAmount, VS4TAR.TARNIECNo 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 VS4VARCallLast AS  SELECT VS4TAR.*, VS4TAR2Product.*, VS4TProductLine.TPdLName, VS4TProductLine.TPdLName2, VS4TMedia.TMedCode, VS4TMedia.TMedName, VS4TMedia.TMedName2, VS4TProduct.*, VS4TProductBook.TPBGPaxMin, VS4TProductBook.TPBGPaxMax, VS4TPOS.TPOSPrice, VS4TPOS.TPOSTPSGCode, VS4TPOS.TPOSPeriod, VS4TARMedia.TAMdLastContact FROM (VS4TMedia RIGHT JOIN ((((((VS4TAR LEFT JOIN VS4TAR2Product ON VS4TAR.TARNCode = VS4TAR2Product.TPHITARNCode) LEFT JOIN VS4TProductLine ON VS4TAR2Product.TPHITPDLCode = VS4TProductLine.TPdLCode) LEFT JOIN ((VS4TProduct LEFT JOIN VS4TProductBook ON VS4TProduct.TPdtCode = VS4TProductBook.TPBGTPdtCode) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) ON VS4TAR2Product.TPHITPdtCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TARMedia ON VS4TAR.TARNCode = VS4TARMedia.TAMdTARNCode) LEFT JOIN VS4TAR2 ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) LEFT JOIN VS4TAR3 ON VS4TAR.TARNCode = VS4TAR3.TAR3TARNCode) ON VS4TMedia.TMedCode = VS4TARMedia.TAMdTMedCode) LEFT JOIN VS4TProduct2 ON VS4TProduct.TPdtCode = VS4TProduct2.TPd2TPdtCode
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, VS4TARInvoice.TIvoRefNo, VS4TARInvoice.TIvoSubTotal, VS4TProject.TPrjName, VS4TEmployee.TEmpFullName, VS4TAR.TARNName2, VS4TARInvoice.TIvoTCurCode, VS4TARInvoice.TIvoExchangeRate, VS4TARBalance.TARLBeginBalance, VS4TARBalance.TARLEndBalance, VS4TARInvoice.TIvoPaymentNote, VS4TARInvoice.TIvoConditionDay, VS4TARInvoice.TIvoSaleName, VS4TARBalance.TARLMode, VS4TARInvoice.TIvoArrears, VS4TARInvoice.TIvoType, VS4TAccountPeriod.TACPStartDate, VS4TAccountPeriod.TACPEndDate, VS4TARBalance.TARLPayOther, VS4TARBalance.TARLPayMisc, VS4TARBalance.TARLPayCoupon, VS4TEmployee.TEmpFullName2, VS4TEmployee_1.TEmpFullName2 AS VARCIVEMPNAME2, VS4TARInvoice.TIvoIgnoreArrears, VS4TARInvoice.TIvoDestination, VS4TARInvoice.TIvoNetTotal, VS4TARInvoice.TIvoTRBKCode, VS4TARInvoice.TIvoLastPayDate, VS4TEmployee_1.TEmpFullName2 AS VARCIVEMPNAME 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 VS4TARInvoice ON VS4TARCard.TRICDocNo = VS4TARInvoice.TIvoNo) LEFT JOIN VS4TProject ON VS4TARCard.TRICTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TARBalance ON (VS4TARCard.TRICTACPTACYID = VS4TARBalance.TARLTACPTACYID) AND (VS4TARCard.TRICTACPID = VS4TARBalance.TARLTACPID) AND (VS4TARCard.TRICTARNCode = VS4TARBalance.TARLTARNCode)) LEFT JOIN VS4TEmployee AS VS4TEmployee_1 ON VS4TARInvoice.TIvoTEmpCode = VS4TEmployee_1.TEmpCode) ON (VS4TAccountPeriod.TACPID = VS4TARBalance.TARLTACPID) AND (VS4TAccountPeriod.TACPTACYID = VS4TARBalance.TARLTACPTACYID)) ON VS4TAR.TARNCode = VS4TARCard.TRICTARNCode WHERE (((VS4TARInvoice.TIvoType)<>10) AND ((VS4TARCard.TRICType)<>'O')) OR (((VS4TARInvoice.TIvoType) Is Null))
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, VS4TARInvoice.TIvoRefNo, VS4TARInvoice.TIvoSubTotal, VS4TProject.TPrjName, VS4TEmployee.TEmpFullName, VS4TAR.TARNName2, VS4TARInvoice.TIvoTCurCode, VS4TARInvoice.TIvoExchangeRate, VS4TARBalance.TARLBeginBalance, VS4TARBalance.TARLEndBalance, VS4TARInvoice.TIvoExchangeRate2, VS4TARInvoice.TIvoDestination, VS4TARInvoice.tivoignorearrears, VS4TARInvoice.TIvoInsurance, VS4TARInvoice.TIvoFreightFee, VS4TARInvoice.TIvoCardFlag, VS4TEmployee_1.TEmpFullName2 AS VARCIVEMPNAME2, VS4TARInvoice.TIvoTotalQuantity, VS4TGLTrans.TGLTTGLBCode, VS4TARInvoice.TIvoNetTotal, VS4TARInvoice.TIvoDeposit, VS4TARInvoice.TIvoType, VS4TARInvoice.TIvoTPOSCode, VS4TARInvoice.TIvoTRBKCode, VS4TARInvoice.TIvoTEmpCode, VS4TARInvoice.TIvoSaleName, VS4TARInvoice.TIvoArrears, VS4TARInvoice.TIvoNetPayment, VS4TAR.TARNAddress, VS4TARInvoice.TIvoLastPayDate, VS4TARInvoice.TIvoOtherFee, VS4TARInvoice.TIvoPaymentNote, VS4TARInvoice.TIVOSTARTAGINGDATE, VS4TAR2.TAR2TSPVCODE, VS4TSaleArea.TSAETSZNCODE, VS4TAR2.TAR2TSHPCODE, VS4TProduct.TPdtTPSECode AS VICDIVTPSECODE, VS4TARInvoice.TIvoDiscountTotal, VS4TARInvoice.TIvoHandlingFee, VS4TARInvoice.TIvoTransportFee FROM VS4TProductSection RIGHT JOIN ((((((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 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 VS4TGLTrans ON VS4TARCard.TRICTGLTNo = VS4TGLTrans.TGLTNo) LEFT JOIN VS4TProduct ON VS4TARInvoice.TIvoTPOSCode = VS4TProduct.TPdtCode) ON (VS4TAccountPeriod.TACPID = VS4TARBalance.TARLTACPID) AND (VS4TAccountPeriod.TACPTACYID = VS4TARBalance.TARLTACPTACYID)) ON VS4TAR.TARNCode = VS4TARCard.TRICTARNCode) ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode WHERE (((VS4TARInvoice.TIvoType)<>10 And (VS4TARInvoice.TIvoType)<>7 And (VS4TARInvoice.TIvoType)<>5) AND ((VS4TARCard.TRICType)<>'O')) OR (((VS4TARInvoice.TIvoType) Is Null))
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, VS4TARInvoice.TIvoNetTotal, VS4TAR2.TAR2LastPayAmount, VS4TAR2.TAR2ChqReturnSumQ, VS4TAR2.TAR2ChqReturnSumA, VS4TAR2.TAR2LastChqReturnQ, VS4TAR2.TAR2LastChqReturnA, VS4TAR2.TAR2ChqReturnDate, VS4TARInvoice.TIvoDeliveryStatus, VS4TAR.TARNRegisterDate, VS4TARInvoice.TIvoType 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 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.TRDRRefReceiptNo, VS4TARVDocRef.TRDRAmountRate, VS4TARVoucher.TRVHCancelStatus, VS4TARInvoice.TIvoArrears, VS4TARVoucher.TRVHNo, VS4TARVoucher.TRVHType, VS4TARVoucher.TRVHDate, VS4TARInvoice.tivoignorearrears, VS4TARInvoice.TIvoNetTotal 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 ((VS4TARVDocRef 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 VS4VARCARD2APCARD AS  SELECT VS4VARCardIVDBCN.* FROM VS4VARCardIVDBCN, VS4VAPCardIVDBCN2
GO

CREATE VIEW VS4VARCardIVDBCNFM 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, VS4TARInvoice.TIvoRefNo, VS4TARInvoice.TIvoSubTotal, VS4TARInvoice.TIvoExchangeRate, VS4TProject.TPrjName, VS4TEmployee.TEmpFullName, VS4TARInvoiceMB.TIoMTPOSCode, VS4TARInvoiceMB.TIoMPOSName, VS4TARInvoiceMB.TIoMSerialNo, VS4TARInvoiceMB.TIoMCustom1, VS4TARInvoiceMB.TIoMCustom2, VS4TARInvoiceMB.TIoMCustom3, VS4TARInvoiceMB.TIoMCustom4, VS4TARInvoiceMB.TIoMCustom5, VS4TARInvoiceMB.TIoMCost, VS4TARInvoiceMB.TIoMPrice, VS4TARInvoiceMB.TIoMPerQuantity, VS4TARInvoiceMB.TIoMQuantityCalc, VS4TARInvoiceMB.TIoMQuantity, VS4TARInvoiceMB.TIoMTUntCode, VS4TARInvoiceMB.TIoMTaxBase, VS4TARInvoiceMB.TIoMAmountVAT, VS4TARInvoiceMB.TIoMTaxType, VS4TARInvoiceMB.TIoMCostAmount, VS4TProductSec2.TPS2Code AS VARCIVTPS2Code, VS4TProductSec2.TPS2Name AS VARCIVTPS2Name, VS4TAR.TARNName2, VS4TARInvoice.TIvoTCurCode, VS4TARInvoice.TIvoDestination, VS4TARInvoice.TIvoExchangeRate2, VS4TProduct.TPdtStandardCost, VS4TEmployee_1.TEmpFullName2 AS VARCIVEMPNAME2, VS4TARInvoice.TIvoInsurance, VS4TARInvoice.TIvoFreightFee, VS4TARInvoiceMB.TIoMNetAmount, VS4TARInvoice.TIvoCardFlag, VS4TARInvoice.tivoignorearrears, VS4TGLTrans.TGLTTGLBCode, VS4TARInvoiceMB.TIoMIsPremium, VS4TARInvoiceMB.TIoMUnitFactor, VS4TARInvoice.TIvoDeposit, VS4TARInvoice.TIvoDiscountTotal, VS4TARInvoice.TIvoVATType, VS4TProductSection.TPSECode, VS4TProductSection.TPSEName, VS4TARInvoice.TIvoType, VS4TARInvoice.TIvoTPOSCode, VS4TARInvoice.TIvoArrears, VS4TARInvoice.TIvoNetTotal, VS4TARInvoice.TIvoTRBKCode, VS4TARInvoice.TIvoTEmpCode, VS4TARInvoice.TIvoSaleName, VS4TARInvoice.TIvoNetPayment, VS4TAR.TARNAddress, VS4TProduct.TPdtAliasSlip, VS4TProduct.TPdtTPDLCode, VS4TProductLine.TPdLName, VS4TARInvoice.TIvoDeliveryStatus, VS4TARInvoice.TIvoConditionDay, VS4TARInvoice.TIvoStartAgingDate, VS4TSaleArea.TSaeTSZnCode, VS4TARInvoiceMB.TIoMTARWCode, VS4TARInvoice.TIvoLastPayDate, VS4TARInvoiceMB.TIoMTIvoNo, VS4TARInvoiceMB.TIoMLn, VS4TARInvoice.TIvoBaseAvailable, VS4TARInvoice.TIvoBaseArrears, VS4TARInvoice.TIvoAvailable FROM VS4TProductSection RIGHT JOIN (VS4TProductLine RIGHT JOIN (((((((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 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 VS4TGLTrans ON VS4TARCard.TRICTGLTNo = VS4TGLTrans.TGLTNo) 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) ON VS4TProductLine.TPdLCode = VS4TProduct.TPdtTPDLCode) ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode WHERE (((VS4TARInvoice.TIvoType)<>10) AND ((VS4TARCard.TRICType)<>'O')) OR (((VS4TARInvoice.TIvoType) Is Null))
GO

CREATE VIEW VS4VARCardIVDBCNMB AS SELECT        VS4TARCard.TRICTARNCode, VS4TARCard.TRICDocNo, VS4TARCard.TRICType, VS4TARCard.TRICLn, VS4TARCard.TRICTBraCode, VS4TARCard.TRICTPrjCode, VS4TARCard.TRICBalanceFlag,                           VS4TARCard.TRICTACPTACYID, VS4TARCard.TRICTACPID, VS4TARCard.TRICDueDate, VS4TARCard.TRICDocDate, VS4TARCard.TRICTGLTNo, VS4TARCard.TRICTaxNo, VS4TARCard.TRICRefNo,                           VS4TARCard.TRICRefDate, VS4TARCard.TRICRefNo2, VS4TARCard.TRICRefDate2, VS4TARCard.TRICRefNo3, VS4TARCard.TRICRefDate3, VS4TARCard.TRICTotalOrder, VS4TARCard.TRICCostTotal,                           VS4TARCard.TRICInvGrandTotal, VS4TARCard.TRICCNGrandTotal, VS4TARCard.TRICDBGrandTotal, VS4TARCard.TRICChequePayment, VS4TARCard.TRICCashPayment, VS4TARCard.TRICBankPayment,                           VS4TARCard.TRICCardPayment, VS4TARCard.TRICDiscountTotal, VS4TARCard.TRICAdjustTotal, VS4TARCard.TRICInterestTotal, VS4TARCard.TRICCutDeposit, VS4TARCard.TRICFee,                           VS4TARCard.TRICWtaxTotal, VS4TARCard.TRICWtaxTotal2, VS4TARCard.TRICPayLess, VS4TARCard.TRICPayCoupon, VS4TARCard.TRICPayOther, VS4TARCard.TRICPayMisc,                           VS4TARCard.TRICDescription, VS4TARCard.TRICApproveStatus, VS4TARCard.TRICCancelStatus, VS4TARCard.TRICSignTotal, VS4TARCard.TRICSignArrear, VS4TARCard.TRICFlag1,                           VS4TARCard.TRICFlag2, VS4TARCard.TRICFlag3, VS4TARCard.TRICMode, VS4TARCard.TRICNetTotal, VS4TARCard.TRICDocType, VS4TARCard.TRICDisplayDate, VS4TARCard.TRICCreditUseTotal,                           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,                           VS4TARInvoice.TIvoRefNo, VS4TARInvoice.TIvoSubTotal, VS4TARInvoice.TIvoExchangeRate, VS4TProject.TPrjName, VS4TEmployee.TEmpFullName, VS4TARInvoiceMB.TIoMTPOSCode,                           VS4TARInvoiceMB.TIoMPOSName, VS4TARInvoiceMB.TIoMSerialNo, VS4TARInvoiceMB.TIoMCustom1, VS4TARInvoiceMB.TIoMCustom2, VS4TARInvoiceMB.TIoMCustom3,                           VS4TARInvoiceMB.TIoMCustom4, VS4TARInvoiceMB.TIoMCustom5, VS4TARInvoiceMB.TIoMCost, VS4TARInvoiceMB.TIoMPrice, VS4TARInvoiceMB.TIoMPerQuantity,                           VS4TARInvoiceMB.TIoMQuantityCalc, VS4TARInvoiceMB.TIoMQuantity, VS4TARInvoiceMB.TIoMTUntCode, VS4TARInvoiceMB.TIoMTaxBase, VS4TARInvoiceMB.TIoMAmountVAT,                           VS4TARInvoiceMB.TIoMTaxType, VS4TARInvoiceMB.TIoMCostAmount, VS4TProductSec2.TPS2Code AS VARCIVTPS2Code, VS4TProductSec2.TPS2Name AS VARCIVTPS2Name, VS4TAR.TARNName2,                           VS4TARInvoice.TIvoTCurCode, VS4TARInvoice.TIvoDestination, VS4TARInvoice.TIvoExchangeRate2, VS4TProduct.TPdtStandardCost, VS4TEmployee_1.TEmpFullName2 AS VARCIVEMPNAME2,                           VS4TARInvoice.TIvoInsurance, VS4TARInvoice.TIvoFreightFee, VS4TARInvoiceMB.TIoMNetAmount, VS4TARInvoice.TIvoCardFlag, VS4TARInvoice.TIvoIgnoreArrears, VS4TGLTrans.TGLTTGLBCode,                           VS4TARInvoiceMB.TIoMIsPremium, VS4TARInvoiceMB.TIoMUnitFactor, VS4TARInvoice.TIvoDeposit, VS4TARInvoice.TIvoDiscountTotal, VS4TARInvoice.TIvoVATType, VS4TProductSection.TPSECode,                           VS4TProductSection.TPSEName, VS4TARInvoice.TIvoType, VS4TARInvoice.TIvoTPOSCode, VS4TARInvoice.TIvoArrears, VS4TARInvoice.TIvoNetTotal, VS4TARInvoice.TIvoTRBKCode,                           VS4TARInvoice.TIvoTEmpCode, VS4TARInvoice.TIvoSaleName, VS4TARInvoice.TIvoNetPayment, VS4TAR.TARNAddress, VS4TProduct.TPdtAliasSlip, VS4TProduct.TPdtTPDLCode,                           VS4TProductLine.TPdLName, VS4TARInvoice.TIvoDeliveryStatus, VS4TARInvoice.TIvoConditionDay, VS4TARInvoice.TIvoStartAgingDate, VS4TSaleArea.TSaeTSZnCode,                           VS4TARInvoiceMB.TIoMTARWCode, VS4TARInvoiceMB.TIoMWelfareRate, VS4TARInvoiceMB.TIoMWelfareAmount, VS4TARWelfare.TARWRate, VS4TProductSec2.TPS2Code,                           VS4TProductSec2.TPS2Name, VS4TARInvoice.TIvoLastPayDate, VS4TProduct.TPdtTAPNCode, VS4TAP.TAPNName, VS4TProduct.TPdtStartDate, VS4TProduct.TPdtEndDate,                           VS4TARInvoiceMB.TIoMTIvoNo, VS4TARInvoiceMB.TIoMLn, VS4TARInvoice.TIvoDueDate, VS4TARCreditNoteMB.TRCMReturnFlag, VS4TARInvoiceMB.TIoMSourceNo, VS4TEmployee.TEmpNickName,                           VS4TARInvoiceMB.TIoMTOInCode, VS4TOtherIncome.TOInName, VS4TARInvoiceMB.TIoMDiscountText, VS4TARInvoiceMB.TIoMDiscountTotal, VS4TARInvoice.TIvoPONo, VS4TAR.TARNTaxNo,                           VS4TARInvoiceMB.TIoMQuantity2, VS4TARInvoiceMB.TIoMTUntCode2, VS4TARInvoiceMB.TIoMDescription FROM            VS4TProductSection RIGHT OUTER JOIN                          VS4TProductLine RIGHT OUTER JOIN                          VS4TAR LEFT OUTER JOIN                          VS4TBusinessType ON VS4TAR.TARNTBsTCode = VS4TBusinessType.TBsTCode LEFT OUTER JOIN                          VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode LEFT OUTER JOIN                          VS4TCountry ON VS4TAR.TARNTCouCode = VS4TCountry.TCouCode LEFT OUTER JOIN                          VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode LEFT OUTER JOIN                          VS4TAR2 LEFT OUTER JOIN                          VS4TARHolder ON VS4TAR2.TAR2SaleCode = VS4TARHolder.TARHCode LEFT OUTER JOIN                          VS4TEmployee ON VS4TAR2.TAR2SaleCode = VS4TEmployee.TEmpCode LEFT OUTER JOIN                          VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode INNER JOIN                          VS4TARCard LEFT OUTER JOIN                          VS4TBranch ON VS4TARCard.TRICTBraCode = VS4TBranch.TBraCode LEFT OUTER JOIN                          VS4TARInvoice ON VS4TARCard.TRICDocNo = VS4TARInvoice.TIvoNo LEFT OUTER JOIN                          VS4TProject ON VS4TARCard.TRICTPrjCode = VS4TProject.TPrjCode LEFT OUTER JOIN                          VS4TEmployee AS VS4TEmployee_1 ON VS4TARInvoice.TIvoTEmpCode = VS4TEmployee_1.TEmpCode LEFT OUTER JOIN                          VS4TGLTrans ON VS4TARCard.TRICTGLTNo = VS4TGLTrans.TGLTNo ON VS4TAR.TARNCode = VS4TARCard.TRICTARNCode LEFT OUTER JOIN                          VS4TARInvoiceMB LEFT OUTER JOIN                          VS4TPOS ON VS4TARInvoiceMB.TIoMTPOSCode = VS4TPOS.TPOSCode LEFT OUTER JOIN                          VS4TProduct LEFT OUTER JOIN                          VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code ON VS4TPOS.TPOSCode = VS4TProduct.TPdtCode LEFT OUTER JOIN                          VS4TARWelfare ON VS4TARInvoiceMB.TIoMTARWCode = VS4TARWelfare.TARWCode LEFT OUTER JOIN                          VS4TAP ON VS4TProduct.TPdtTAPNCode = VS4TAP.TAPNCode LEFT OUTER JOIN                          VS4TARCreditNoteMB ON VS4TARInvoiceMB.TIoMLn = VS4TARCreditNoteMB.TRCMLn AND VS4TARInvoiceMB.TIoMTIvoNo = VS4TARCreditNoteMB.TRCMTRCNNo LEFT OUTER JOIN                          VS4TOtherIncome ON VS4TARInvoiceMB.TIoMTOInCode = VS4TOtherIncome.TOInCode ON VS4TARInvoice.TIvoNo = VS4TARInvoiceMB.TIoMTIvoNo ON                           VS4TProductLine.TPdLCode = VS4TProduct.TPdtTPDLCode ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode WHERE        (VS4TARInvoice.TIvoType <> 10) AND (VS4TARInvoice.TIvoType <> 7) AND (VS4TARInvoice.TIvoType <> 5) AND (VS4TARCard.TRICType <> 'O') OR                          (VS4TARInvoice.TIvoType IS NULL)
GO

CREATE VIEW VS4VARCardIVDBCNMO 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, VS4TARInvoice.TIvoRefNo, VS4TARInvoice.TIvoSubTotal, VS4TARInvoice.TIvoExchangeRate, VS4TProject.TPrjName, VS4TEmployee.TEmpFullName, VS4TARInvoiceMB.TIoMTPOSCode, VS4TARInvoiceMB.TIoMPOSName, VS4TARInvoiceMB.TIoMSerialNo, VS4TARInvoiceMB.TIoMCustom1, VS4TARInvoiceMB.TIoMCustom2, VS4TARInvoiceMB.TIoMCustom3, VS4TARInvoiceMB.TIoMCustom4, VS4TARInvoiceMB.TIoMCustom5, VS4TARInvoiceMB.TIoMCost, VS4TARInvoiceMB.TIoMPrice, VS4TARInvoiceMB.TIoMPerQuantity, VS4TARInvoiceMB.TIoMQuantityCalc, VS4TARInvoiceMB.TIoMQuantity, VS4TARInvoiceMB.TIoMTUntCode, VS4TARInvoiceMB.TIoMTaxBase, VS4TARInvoiceMB.TIoMAmountVAT, VS4TARInvoiceMB.TIoMTaxType, VS4TARInvoiceMB.TIoMCostAmount, VS4TProductSec2.TPS2Code AS VARCIVTPS2Code, VS4TProductSec2.TPS2Name AS VARCIVTPS2Name, VS4TAR.TARNName2, VS4TARInvoice.TIvoTCurCode, VS4TARInvoice.TIvoDestination, VS4TARInvoice.TIvoExchangeRate2, VS4TProduct.TPdtStandardCost, VS4TEmployee_1.TEmpFullName2 AS VARCIVEMPNAME2, VS4TARInvoice.TIvoInsurance, VS4TARInvoice.TIvoFreightFee, VS4TARInvoiceMB.TIoMNetAmount, VS4TARInvoice.TIvoCardFlag, VS4TARInvoice.tivoignorearrears, VS4TGLTrans.TGLTTGLBCode, VS4TARInvoiceMB.TIoMIsPremium, VS4TARInvoiceMB.TIoMUnitFactor, VS4TARInvoice.TIvoDeposit, VS4TARInvoice.TIvoDiscountTotal, VS4TARInvoice.TIvoVATType, VS4TProductSection.TPSECode, VS4TProductSection.TPSEName, VS4TARInvoice.TIvoType, VS4TARInvoice.TIvoTPOSCode, VS4TARInvoice.TIvoArrears, VS4TARInvoice.TIvoNetTotal, VS4TARInvoice.TIvoTRBKCode, VS4TARInvoice.TIvoTEmpCode, VS4TARInvoice.TIvoSaleName, VS4TARInvoice.TIvoNetPayment, VS4TAR.TARNAddress, VS4TProduct.TPdtAliasSlip, VS4TProduct.TPdtTPDLCode, VS4TProductLine.TPdLName, VS4TARInvoice.TIvoDeliveryStatus, VS4TARInvoice.TIvoConditionDay, VS4TARInvoice.TIvoStartAgingDate, VS4TSaleArea.TSaeTSZnCode, VS4TARInvoiceMB.TIoMTARWCode, VS4TARInvoiceMB.TIoMWelfareRate, VS4TARInvoiceMB.TIoMWelfareAmount, VS4TARWelfare.TARWRate, VS4TProductSec2.TPS2Code, VS4TProductSec2.TPS2Name, VS4TARInvoice.TIvoLastPayDate, VS4TProduct.TPdtTAPNCode, VS4TAP.TAPNName, VS4TProduct.TPdtStartDate, VS4TProduct.TPdtEndDate, VS4TARInvoiceMB.TIoMTIvoNo, VS4TARInvoiceMB.TIoMLn, VS4TARInvoice.TIvoDueDate, VS4TARCreditNoteMB.TRCMReturnFlag, VS4TARInvoiceMB.TIoMSourceNo, VS4TEmployee.TEmpNickName, VS4TARInvoiceMB.TIoMTOInCode, VS4TOtherIncome.TOInName, VS4TARInvoiceMB.TIoMDiscountText, VS4TARInvoiceMB.TIoMDiscountTotal, VS4TARVDocRef.TRDRTOINCode, VS4TARVDocRef.TRDRTaxBase, VS4TARVDocRef.TRDRVATType, VS4TARVDocRef.TRDRVATTotal, VS4TARVDocRef.TRDRDOVAT, VS4TARVDocRef.TRDRRefDocAmount, VS4TOtherIncome_1.TOInName AS VRMOTOInName FROM (VS4TProductSection RIGHT JOIN (VS4TProductLine RIGHT JOIN (((((((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 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 VS4TGLTrans ON VS4TARCard.TRICTGLTNo = VS4TGLTrans.TGLTNo) LEFT JOIN VS4TARVoucher ON VS4TARCard.TRICDocNo = VS4TARVoucher.TRVHNo) 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) LEFT JOIN VS4TARWelfare ON VS4TARInvoiceMB.TIoMTARWCode = VS4TARWelfare.TARWCode) LEFT JOIN VS4TAP ON VS4TProduct.TPdtTAPNCode = VS4TAP.TAPNCode) LEFT JOIN VS4TARCreditNoteMB ON (VS4TARInvoiceMB.TIoMLn = VS4TARCreditNoteMB.TRCMLn) AND (VS4TARInvoiceMB.TIoMTIvoNo = VS4TARCreditNoteMB.TRCMTRCNNo)) LEFT JOIN VS4TOtherIncome ON VS4TARInvoiceMB.TIoMTOInCode = VS4TOtherIncome.TOInCode) ON VS4TARInvoice.TIvoNo = VS4TARInvoiceMB.TIoMTIvoNo) ON VS4TProductLine.TPdLCode = VS4TProduct.TPdtTPDLCode) ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode) LEFT JOIN (VS4TARVDocRef LEFT JOIN VS4TOtherIncome AS VS4TOtherIncome_1 ON VS4TARVDocRef.TRDRTOINCode = VS4TOtherIncome_1.TOInCode) ON VS4TARVoucher.TRVHNo = VS4TARVDocRef.TRDRTRVHNo WHERE (((VS4TARInvoice.TIvoType)<>10 And (VS4TARInvoice.TIvoType)<>7 And (VS4TARInvoice.TIvoType)<>5) AND ((VS4TARCard.TRICType)<>'O')) OR (((VS4TARInvoice.TIvoType) Is Null))
GO

CREATE VIEW VS4VPVPay AS SELECT VS4TAPVoucher.TAPVNo, VS4TAPVoucher.TAPVDate, VS4TAPVoucher.TAPVType, VS4TAPVoucher.TAPVDetailType, VS4TAPVoucher.TAPVMode, VS4TAPVoucher.TAPVBalanceFlag,                    VS4TAPVoucher.TAPVBaseArrear, VS4TAPVoucher.TAPVArrear, VS4TAPVoucher.TAPVRefNo, VS4TAPVoucher.TAPVRefDate, VS4TAPVoucher.TAPVRefNo2, VS4TAPVoucher.TAPVRefNo3,                    VS4TAPVoucher.TAPVPaymentStatus, VS4TAPVoucher.TAPVTBraCode, VS4TAPVoucher.TAPVTAPNCode, VS4TAPVoucher.TAPVPayTo, VS4TAPVoucher.TAPVAddress, VS4TAPVoucher.TAPVCurrency,                    VS4TAPVoucher.TAPVSubTotal, VS4TAPVoucher.TAPVCurRate, VS4TAPVoucher.TAPVCurAmount, VS4TAPVoucher.TAPVCurDiscount, VS4TAPVoucher.TAPVDiscount, VS4TAPVoucher.TAPVPayLess,                    VS4TAPVoucher.TAPVAdjustTotal, VS4TAPVoucher.TAPVFee, VS4TAPVoucher.TAPVNetAmount, VS4TAPVoucher.TAPVTaxBase, VS4TAPVoucher.TAPVWTAXTotal, VS4TAPVoucher.TAPVTaxBase2,                    VS4TAPVoucher.TAPVWTAXTotal2, VS4TAPVoucher.TAPVTotal, VS4TAPVoucher.TAPVNote, VS4TAPVoucher.TAPVTGLBCode, VS4TAPVoucher.TAPVTPrjCode, VS4TAPVoucher.TAPVGLMethod,                    VS4TAPVoucher.TAPVTGLTNo, VS4TAPVoucher.TAPVTTeTNo, VS4TAPVoucher.TAPVVATNo, VS4TAPVoucher.TAPVTaxPeriodNo, VS4TAPVoucher.TAPVTaxPeriodType, VS4TAPVoucher.TAPVTaxRefund,                    VS4TAPVoucher.TAPVPayType, VS4TAPVoucher.TAPVTaxNo, VS4TAPVoucher.TAPVWTaxPeriodNo, VS4TAPVoucher.TAPVWTaxPeriodType, VS4TAPVoucher.TAPVChequePayment,                    VS4TAPVoucher.TAPVCashPayment, VS4TAPVoucher.TAPVBankPayment, VS4TAPVoucher.TAPVCutDeposit, VS4TAPVoucher.TAPVCardPayment, VS4TAPVoucher.TAPVPayCoupon,                    VS4TAPVoucher.TAPVPayOther, VS4TAPVoucher.TAPVPayMisc, VS4TAPVoucher.TAPVInterestRate, VS4TAPVoucher.TAPVInterestTotal, VS4TAPVoucher.TAPVCardFlag, VS4TAPVoucher.TAPVTaxFlag,                    VS4TAPVoucher.TAPVClientTaxNo, VS4TAPVoucher.TAPVAPType, VS4TAPVoucher.TAPVCreateBy, VS4TAPVoucher.TAPVCreateDate, VS4TAPVoucher.TAPVEditCode, VS4TAPVoucher.TAPVEditBy,                    VS4TAPVoucher.TAPVEditDate, VS4TAPVoucher.TAPVConfirmStatus, VS4TAPVoucher.TAPVConfirmBy, VS4TAPVoucher.TAPVConfirmDate, VS4TAPVoucher.TAPVApproveStatus,                    VS4TAPVoucher.TAPVApproveBy, VS4TAPVoucher.TAPVApproveDate, VS4TAPVoucher.TAPVApproveNote, VS4TAPVoucher.TAPVRevision, VS4TAPVoucher.TAPVCancelStatus,                    VS4TAPVoucher.TAPVCancelNo, VS4TAPVoucher.TAPVCancelBy, VS4TAPVoucher.TAPVCancelDate, VS4TAPVoucher.TAPVCancelNote, VS4TAPVoucher.TAPVFlag1, VS4TAPVoucher.TAPVTDivCode,                    VS4TAPVoucher.TAPVTDepCode, VS4TAPVoucher.TAPVTSecCode, VS4TAPVoucher.TAPVTEmpCode, VS4TAPVoucher.TAPVTAssCode, VS4TAPVoucher.TAPVTPdtCode, VS4TAPVoucher.TAPVTARNCode,                    VS4TAPVoucher.TAPVDescription, VS4TAPVoucher.TAPVRefNo4, VS4TAPVoucherPay.TPVPTAPVNo, VS4TAPVoucherPay.TPVPLn, VS4TAPVoucherPay.TPVPIsChange, VS4TAPVoucherPay.TPVPPaymentType,                    VS4TAPVoucherPay.TPVPCurrency, VS4TAPVoucherPay.TPVPTBnkCode, VS4TAPVoucherPay.TPVPTransferDate, VS4TAPVoucherPay.TPVPCashDate, VS4TAPVoucherPay.TPVPDocNo,                    VS4TAPVoucherPay.TPVPBankBranch, VS4TAPVoucherPay.TPVPAccountType, VS4TAPVoucherPay.TPVPAccountName, VS4TAPVoucherPay.TPVPAccountNumber, VS4TAPVoucherPay.TPVPTBCDNo,                    VS4TAPVoucherPay.TPVPCardCode, VS4TAPVoucherPay.TPVPCardType, VS4TAPVoucherPay.TPVPCardName, VS4TAPVoucherPay.TPVPCardNo, VS4TAPVoucherPay.TPVPCardExpire,                    VS4TAPVoucherPay.TPVPExchangeRate, VS4TAPVoucherPay.TPVPAmount, VS4TAPVoucherPay.TPVPAmountInRate, VS4TAPVoucherPay.TPVPAdjustTotal, VS4TAPVoucherPay.TPVPDiscount,                    VS4TAPVoucherPay.TPVPFee, VS4TAPVoucherPay.TPVPFeeProvide, VS4TAPVoucherPay.TPVPNetAmount, VS4TAPVoucherPay.TPVPTCBBNo, VS4TAPVoucherPay.TPVPNote,                    VS4TAPVoucherPay.TPVPDocType, VS4TAPVoucherPay.TPVPUseOD, VS4TAPVoucherPay.TPVPAmountMain, VS4TChequeSub.TCHSNo, VS4TChequeSub.TCHSTBnkCode, VS4TChequeSub.TCHSTCBBNo,                    VS4TChequeSub.TCHSTPVPTAPVNo, VS4TChequeSub.TCHSTPVPLn, VS4TChequeSub.TCHSTPrjCode, VS4TChequeSub.TCHSChqDate, VS4TChequeSub.TCHSTCurCode, VS4TChequeSub.TCHSTotal,                    VS4TChequeSub.TCHSCurRate, VS4TChequeSub.TCHSTotalRate, VS4TChequeSub.TCHSAvailable, VS4TChequeSub.TCHSPayment, VS4TChequeSub.TCHSDepositCount, VS4TChequeSub.TCHSTAPNCode,                    VS4TChequeSub.TCHSPayTo, VS4TChequeSub.TCHSPayFor, VS4TChequeSub.TCHSPayChqDate, VS4TChequeSub.TCHSCashDate, VS4TChequeSub.TCHSDescription, VS4TChequeSub.TCHSDescription2,                    VS4TChequeSub.TCHSChqStatus, VS4TChequeSub.TCHSChqRef, VS4TChequeSub.TCHSTGLTNo, VS4TChequeSub.TCHSChqOnHandBy, VS4TChequeSub.TCHSChqOnHandDate,                    VS4TChequeSub.TCHSChqDepBy, VS4TChequeSub.TCHSChqDepDate, VS4TChequeSub.TCHSChqPassBy, VS4TChequeSub.TCHSChqPassDate, VS4TChequeSub.TCHSChqBackBy,                    VS4TChequeSub.TCHSChqBackDate, VS4TChequeSub.TCHSCreateCode, VS4TChequeSub.TCHSCreateDate, VS4TChequeSub.TCHSEditCode, VS4TChequeSub.TCHSEditDate,                    VS4TChequeSub.TCHSApproveStatus, VS4TChequeSub.TCHSApproveBy, VS4TChequeSub.TCHSApproveDate, VS4TChequeSub.TCHSApproveNote, VS4TChequeSub.TCHSCancelStatus,                    VS4TChequeSub.TCHSCancelNo, VS4TChequeSub.TCHSCancelBy, VS4TChequeSub.TCHSCancelDate, VS4TChequeSub.TCHSCancelNote, VS4TChequeSub.TCHSFlag1, VS4TAP.TAPNCode,                    VS4TAP.TAPNTCmpCode, VS4TAP.TAPNTAPTCode, VS4TAP.TAPNIntro, VS4TAP.TAPNName, VS4TAP.TAPNName2, VS4TAP.TAPNIntroName, VS4TAP.TAPNType, VS4TAP.TAPNTBsTCode,                    VS4TAP.TAPNOwnerName, VS4TAP.TAPNDocCode, VS4TAP.TAPNContactName, VS4TAP.TAPNTaxNo, VS4TAP.TAPNAccountCode, VS4TAP.TAPNTAPGCode, VS4TAP.TAPNTAPCCode,                    VS4TAP.TAPNAddressBill, VS4TAP.TAPNAddressDeliver, VS4TAP.TAPNAddress, VS4TAP.TAPNSubProvince, VS4TAP.TAPNCity, VS4TAP.TAPNPostalCode, VS4TAP.TAPNStaCode,                    VS4TAP.TAPNTCouCode, VS4TAP.TAPNWebsite, VS4TAP.TAPNEmail, VS4TAP.TAPNPhone, VS4TAP.TAPNFax, VS4TAP.TAPNImage1, VS4TAP.TAPNDiscountPC, VS4TAP.TAPNDiscountDay,                    VS4TAP.TAPNCreditDay, VS4TAP.TAPNLimitTCurCode, VS4TAP.TAPNSpecialTaxRate, VS4TAP.TAPNPaymentNote, VS4TAP.TAPNStatementNote, VS4TAP.TAPNDeliveryNote, VS4TAP.TAPNQualityScore,                    VS4TAP.TAPNDeliveryScore, VS4TAP.TAPNTotalScore, VS4TAP.TAPNTimeToOrder, VS4TAP.TAPNLastDueDate, VS4TAP.TAPNLastOrderDate, VS4TAP.TAPNMapFile, VS4TAP.TAPNCreditLimit,                    VS4TAP.TAPNCreditUseBal, VS4TAP.TAPNCreditUse, VS4TAP.TAPNCreditBalance, VS4TAP.TAPNCreditAvaiBal, VS4TAP.TAPNTotalOrderBal, VS4TAP.TAPNQualityBal, VS4TAP.TAPNDeliveryBal,                    VS4TAP.TAPNTotalScoreBal, VS4TAP.TAPNBillAdjust, VS4TAP.TAPNNote, VS4TAP.TAPNCreateDate, VS4TAP.TAPNEditCode, VS4TAP.TAPNEditDate, VS4TAP.TAPNTextSort,                    VS4TAP.TAPNConditionType, VS4TAP.TAPNShortName, VS4TAP.TAPNAddressBill2, VS4TAP.TAPNTBraCode, VS4TAP.TAPNTSPvCode, VS4TAP.TAPNTPrvCode, VS4TAP.TAPNMode,                    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.TCBBBalance, VS4TProject.TPrjTEmpCode, VS4TEmployee.TEmpFullName,                    VS4TAPInvoice.TIAPAVailable AS VPVPAVailable, VS4TPaymentType.TPyTDescription, VS4TAPGroup.TAPGName, VS4TAPInvoice.TIAPDate, VS4TAPInvoice.TIAPGrandTotal, VS4TAPInvoice.TIAPTaxBase,                    VS4TAPInvoice.TIAPVATTotal, VS4TAPInvoice.TIAPArrears, VS4TPaymentType.TPyTGroupSum, VS4TAPVoucher.TAPVPublishStatus, VS4TAPVoucher.TAPVPublishDate, VS4TAPVoucher.TAPVPublishNo,                    VS4TAP.TAPNInternal FROM     VS4TPaymentType RIGHT OUTER JOIN                   VS4TCompanyBank RIGHT OUTER JOIN                   VS4TChequeSub RIGHT OUTER JOIN                   VS4TAP LEFT OUTER JOIN                   VS4TAPGroup ON VS4TAP.TAPNTAPGCode = VS4TAPGroup.TAPGCode INNER JOIN                   VS4TAPVoucher LEFT OUTER JOIN                   VS4TProject ON VS4TAPVoucher.TAPVTPrjCode = VS4TProject.TPrjCode LEFT OUTER JOIN                   VS4TEmployee ON VS4TProject.TPrjTEmpCode = VS4TEmployee.TEmpCode INNER JOIN                   VS4TAPVoucherPay LEFT OUTER JOIN                   VS4TAPInvoice ON VS4TAPVoucherPay.TPVPDocNo = VS4TAPInvoice.TIAPNo LEFT OUTER 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 ON VS4TPaymentType.TPyTAlias = VS4TAPVoucherPay.TPVPPaymentType
GO

CREATE VIEW VS4VARCardMBTarget AS  SELECT VS4VARCardIVDBCNMB.*, VS4TSaleTargetApp.TTGATargetQty AS VARCIVTargetQty, VS4TSaleTargetApp.TTGATarget AS VARCIVTarget, VS4TSaleTargetApp.TTGABonus AS VARCIVBonus, VS4TSaleTargetApp.TTGATargetQty2 AS VARCIVTargetQty2, VS4TSaleTargetApp.TTGATarget2 AS VARCIVTarget2, VS4TSaleTargetApp.TTGABonus2 AS VARCIVBonus2, VS4TSaleTargetApp.TTGATargetQty3 AS VARCIVTargetQty3, VS4TSaleTargetApp.TTGATarget3 AS VARCIVTarget3, VS4TSaleTargetApp.TTGABonus3 AS VARCIVBonus3 FROM VS4VARCardIVDBCNMB LEFT JOIN VS4TSaleTargetApp ON (VS4VARCardIVDBCNMB.TIvoTEmpCode = VS4TSaleTargetApp.TTGATEmpCode) AND (VS4VARCardIVDBCNMB.TRICTACPID = VS4TSaleTargetApp.TTGAMonth) AND (VS4VARCardIVDBCNMB.TRICTACPTACYID = VS4TSaleTargetApp.TTGAYear) AND (VS4VARCardIVDBCNMB.TIoMTPOSCode = VS4TSaleTargetApp.TTGATPdtCode)
GO

CREATE VIEW VS4VARCardMBTgtPS2 AS  SELECT VS4VARCardIVDBCNMB.*, VS4TSaleTargetApp.TTGATargetQty AS VARCIVTargetQty, VS4TSaleTargetApp.TTGATarget AS VARCIVTarget, VS4TSaleTargetApp.TTGABonus AS VARCIVBonus, VS4TSaleTargetApp.TTGATargetQty2 AS VARCIVTargetQty2, VS4TSaleTargetApp.TTGATarget2 AS VARCIVTarget2, VS4TSaleTargetApp.TTGABonus2 AS VARCIVBonus2, VS4TSaleTargetApp.TTGATargetQty3 AS VARCIVTargetQty3, VS4TSaleTargetApp.TTGATarget3 AS VARCIVTarget3, VS4TSaleTargetApp.TTGABonus3 AS VARCIVBonus3 FROM VS4VARCardIVDBCNMB LEFT JOIN VS4TSaleTargetApp ON (VS4VARCardIVDBCNMB.TRICTACPTACYID = VS4TSaleTargetApp.TTGAYear) AND (VS4VARCardIVDBCNMB.TRICTACPID = VS4TSaleTargetApp.TTGAMonth) AND (VS4VARCardIVDBCNMB.TIvoTEmpCode = VS4TSaleTargetApp.TTGATEmpCode) AND (VS4VARCardIVDBCNMB.VARCIVTPS2Code = VS4TSaleTargetApp.TTGATPS2Code)
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, VS4TInventory.TInvTInTAlias HAVING (((VS4TInventory.TInvApproveStatus)=1) AND ((VS4TInventory.TInvCancelStatus)=0) AND ((VS4TInventory.TInvTInTAlias) IN ('SALEOUT')))
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 Or (VS4TARInvoice.TIvoType)=7))
GO

CREATE VIEW VS4VARCodeFromDN AS  SELECT VS4TAR.TARNCode, VS4TAR.TARNName, VS4TAR.TARNName2, VS4TAR.TARNIntroName, VS4TAR.TARNFlag1, VS4TAR2.TAR2SaleCode, VS4TARInvoice.TIvoType 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.TIvoType, VS4TARInvoice.TIvoArrears, VS4TARInvoice.TIvoConfirmStatus, VS4TARInvoice.TIvoApproveStatus, VS4TARInvoice.TIvoCancelStatus HAVING (((VS4TARInvoice.TIvoType)=4) AND ((VS4TARInvoice.TIvoConfirmStatus)=1) AND ((VS4TARInvoice.TIvoApproveStatus)=1) AND ((VS4TARInvoice.TIvoCancelStatus)<>1))
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 VS4VARCodeFromLSC AS  SELECT  VS4TAR.TARNCode,  VS4TAR.TARNName,  VS4TAR.TARNName2,  VS4TAR.TARNIntroName,  VS4TAR.TARNFlag1,  VS4TAR2.TAR2SaleCode FROM      VS4TAR LEFT OUTER 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,  VS4TSO.TSODType HAVING ( VS4TSO.TSODConfirmStatus = 1) AND ( VS4TSO.TSODApproveStatus = 1) AND ( VS4TSO.TSODCancelStatus <> 1) AND ( VS4TSO.TSODType = 4)
GO

CREATE VIEW VS4VARCodeFromPOP AS  SELECT VS4TAR.TARNCode, VS4TAR.TARNName, VS4TAR.TARNName2, VS4TAR.TARNIntroName, VS4TAR.TARNFlag1, VS4TAR.TARNTCouCode, VS4TCountry.TCouName, VS4TCountry.TCouName2 FROM VS4TCountry INNER JOIN (VS4TAR INNER JOIN VS4TPOPTrans ON VS4TAR.TARNCode = VS4TPOPTrans.TPPDTAPNCode) ON VS4TCountry.TCouCode = VS4TAR.TARNTCouCode GROUP BY VS4TAR.TARNCode, VS4TAR.TARNName, VS4TAR.TARNName2, VS4TAR.TARNIntroName, VS4TAR.TARNFlag1, VS4TAR.TARNTCouCode, VS4TCountry.TCouName, VS4TCountry.TCouName2, VS4TPOPTrans.TPPDInvoiceStatus, VS4TPOPTrans.TPPDConfirmStatus, VS4TPOPTrans.TPPDApproveStatus, VS4TPOPTrans.TPPDCancelStatus HAVING (((VS4TPOPTrans.TPPDConfirmStatus)=1) AND ((VS4TPOPTrans.TPPDApproveStatus)=1) AND ((VS4TPOPTrans.TPPDCancelStatus)<>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 VS4VARCodeFromRO AS  SELECT  VS4TAR.TARNCode,  VS4TAR.TARNName,  VS4TAR.TARNName2,  VS4TAR.TARNIntroName,  VS4TAR.TARNFlag1,  VS4TAR2.TAR2SaleCode FROM      VS4TAR LEFT OUTER 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.TSODInvoicestatus, VS4TSO.TSODCancelStatus,  VS4TSO.TSODType HAVING (VS4TSO.TSODInvoicestatus<2) AND ( VS4TSO.TSODConfirmStatus = 1) AND ( VS4TSO.TSODApproveStatus = 1) AND ( VS4TSO.TSODCancelStatus <> 1) AND ( VS4TSO.TSODType = 2)
GO

CREATE VIEW VS4VARCodeFromRT AS  SELECT  VS4TAR.TARNCode,  VS4TAR.TARNName,  VS4TAR.TARNName2,  VS4TAR.TARNIntroName,  VS4TAR.TARNFlag1,  VS4TAR2.TAR2SaleCode FROM      VS4TAR LEFT OUTER 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.TSODInvoicestatus, VS4TSO.TSODCancelStatus,  VS4TSO.TSODType HAVING (VS4TSO.TSODInvoicestatus<2) AND ( VS4TSO.TSODConfirmStatus = 1) AND ( VS4TSO.TSODApproveStatus = 1) AND ( VS4TSO.TSODCancelStatus <> 1) AND ( VS4TSO.TSODType = 3)
GO

CREATE VIEW VS4VARCodeFromSE AS  SELECT  VS4TAR.TARNCode,  VS4TAR.TARNName,  VS4TAR.TARNName2,  VS4TAR.TARNIntroName,  VS4TAR.TARNFlag1,  VS4TAR2.TAR2SaleCode FROM      VS4TAR LEFT OUTER 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.TSODInvoicestatus, VS4TSO.TSODCancelStatus,  VS4TSO.TSODType HAVING (VS4TSO.TSODInvoicestatus<2) AND ( VS4TSO.TSODConfirmStatus = 1) AND ( VS4TSO.TSODApproveStatus = 1) AND ( VS4TSO.TSODCancelStatus <> 1) AND ( VS4TSO.TSODType = 1)
GO

CREATE VIEW VS4VARCodeFromSI 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)=9))
GO

CREATE VIEW VS4VARCodeFromSO AS  SELECT  VS4TAR.TARNCode,  VS4TAR.TARNName,  VS4TAR.TARNName2,  VS4TAR.TARNIntroName,  VS4TAR.TARNFlag1,  VS4TAR2.TAR2SaleCode FROM      VS4TAR LEFT OUTER 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.TSODInvoicestatus, VS4TSO.TSODCancelStatus,  VS4TSO.TSODType HAVING (VS4TSO.TSODInvoicestatus<2) AND ( VS4TSO.TSODConfirmStatus = 1) AND ( VS4TSO.TSODApproveStatus = 1) AND ( VS4TSO.TSODCancelStatus <> 1) AND ( VS4TSO.TSODType = 0)
GO

CREATE VIEW VS4VARCodeFromSR 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, VS4TInventory.TInvTInTAlias HAVING (((VS4TInventory.TInvApproveStatus)=1) AND ((VS4TInventory.TInvCancelStatus)=0) AND ((VS4TInventory.TInvTInTAlias) In ('SALERETURN','SALERETURNED','SALERETURNNEWLOT')))
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) INNER 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.TARGCode, VS4TARGroup.TARGName, VS4TARCreditCard.TACDLn, VS4TARCreditCard.TACDCardCode, VS4TARCreditCard.TACDCardType, VS4TARCreditCard.TACDLevel, VS4TARCreditCard.TACDCardName, VS4TARCreditCard.TACDCardNo, VS4TARCreditCard.TACDCardExpire, VS4TARCreditCard.TACDCardIssue, VS4TARCreditCard.TACDCardSince, VS4TARCreditCard.TACDNote, VS4TARCreditCard.TACDFlag1 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.TRCMTRCNNo, VS4TARCreditNoteMB.TRCMLn, VS4TARCreditNoteMB.TRCMType, VS4TARCreditNoteMB.TRCMReturnFlag, VS4TARCreditNoteMB.TRCMTOInCode, VS4TARCreditNoteMB.TRCMTPOSCode, VS4TARCreditNoteMB.TRCMSerialNo, VS4TARCreditNoteMB.TRCMJobCode, VS4TARCreditNoteMB.TRCMCustom1, VS4TARCreditNoteMB.TRCMCustom2, VS4TARCreditNoteMB.TRCMCustom3, VS4TARCreditNoteMB.TRCMCustom4, VS4TARCreditNoteMB.TRCMCustom5, VS4TARCreditNoteMB.TRCMShippingMark, VS4TARCreditNoteMB.TRCMPOSCode, VS4TARCreditNoteMB.TRCMFactoryCode, VS4TARCreditNoteMB.TRCMPOSName, VS4TARCreditNoteMB.TRCMCost, VS4TARCreditNoteMB.TRCMOldPrice, VS4TARCreditNoteMB.TRCMNewPrice, VS4TARCreditNoteMB.TRCMPrice, VS4TARCreditNoteMB.TRCMPerQuantity, VS4TARCreditNoteMB.TRCMUnitFactor, VS4TARCreditNoteMB.TRCMUnitCalc, VS4TARCreditNoteMB.TRCMOldQuantityCal, VS4TARCreditNoteMB.TRCMQuantityCalc, VS4TARCreditNoteMB.TRCMOldQuantity, VS4TARCreditNoteMB.TRCMQuantityText, VS4TARCreditNoteMB.TRCMQuantity, VS4TARCreditNoteMB.TRCMTUntCode, VS4TARCreditNoteMB.TRCMOldQuantity2, VS4TARCreditNoteMB.TRCMQuantity2, VS4TARCreditNoteMB.TRCMTUntCode2, VS4TARCreditNoteMB.TRCMOldQuantity3, VS4TARCreditNoteMB.TRCMQuantity3, VS4TARCreditNoteMB.TRCMTUntCode3, VS4TARCreditNoteMB.TRCMCostOldAmount, VS4TARCreditNoteMB.TRCMCostAmount, VS4TARCreditNoteMB.TRCMOldAmount, VS4TARCreditNoteMB.TRCMAmount, VS4TARCreditNoteMB.TRCMDiscountText, VS4TARCreditNoteMB.TRCMDiscountTotal, VS4TARCreditNoteMB.TRCMOLDDiscTotal, VS4TARCreditNoteMB.TRCMOldNetAmount, VS4TARCreditNoteMB.TRCMNetAmount, VS4TARCreditNoteMB.TRCMNAmountInRate, VS4TARCreditNoteMB.TRCMTaxBase, VS4TARCreditNoteMB.TRCMTaxType, VS4TARCreditNoteMB.TRCMAmountVAT, VS4TARCreditNoteMB.TRCMDescription, VS4TARCreditNoteMB.TRCMSourceNo, VS4TARCreditNoteMB.TRCMSourceLn, VS4TARCreditNoteMB.TRCMSourceDate, VS4TARCreditNoteMB.TRCMTaxNo, VS4TARCreditNoteMB.TRCMRefNo, VS4TARCreditNoteMB.TRCMRefDate, VS4TARCreditNoteMB.TRCMIVType, VS4TARCreditNoteMB.TRCMVATRate, VS4TARCreditNoteMB.TRCMGrandTotal, VS4TARCreditNoteMB.TRCMNetPayment, VS4TARCreditNoteMB.TRCMArrears, VS4TARCreditNoteMB.TRCMBaseArrears, VS4TARCreditNoteMB.TRCMIsPremium, VS4TARCreditNoteMB.TRCMCommissionBase, VS4TARCreditNoteMB.TRCMCommissionRate, VS4TARCreditNoteMB.TRCMCommission, VS4TARCreditNoteMB.TRCMFlag1, VS4TARCreditNoteMB.TRCMQuantityStock, VS4TARCreditNoteMB.TRCMAVGWeighting, VS4TARCreditNoteMB.TRCMDiscountBill, VS4TARCreditNoteMB.TRCMDeposit, VS4TARCreditNoteMB.TRCMOLDDiscountBil, VS4TARCreditNoteMB.TRCMOLDDeposit, VS4TARCreditNoteMB.TRCMTotalDelivery, VS4TARCreditNoteMB.TRCMTotalDelivery2, VS4TARCreditNoteMB.TRCMTotalDelivery3, VS4TARCreditNoteMB.TRCMTotalArrear, VS4TARCreditNoteMB.TRCMTotalArrear2, VS4TARCreditNoteMB.TRCMTotalArrear3, VS4TARCreditNoteMB.TRCMTARWCode, VS4TARCreditNoteMB.TRCMTRCACode, VS4TARCreditNoteMB.TRCMTLctCode, VS4TARCreditNoteMB.TRCMWelfareRate, VS4TCountry.TCouName, VS4TProject.TPrjName, 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, VS4TProduct.TPdtTPS2Code, VS4TProductSection.TPSEName, VS4TProductSec2.TPS2Name, VS4TAR2.TAR2SaleCode, VS4TARHolder.TARHName, VS4TAR.TARNName2, VS4TAR.TARNAddressBill, VS4TAR.TARNAddressBill2, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TARWelfare.TARWName, VS4TBranch.TBraAddressBill2, VS4TBranch.TBraAddressBillOF, VS4TARBranch.TARDName, VS4TAR.TARNTaxNo, VS4TARInvoice_1.TIvoClientTaxNo, VS4TARInvoice_1.TIvoBranchCode, VS4TARInvoice_1.TIvoBranchName, VS4TLocation.TLctTWahCode, VS4TARInvoice_1.TIvoCopyNote, VS4TARInvoice_1.TIvoDescription, VS4TARInvoiceMB.TIoMCost, VS4TARInvoiceMB.TIoMPremiumCost, VS4TARInvoiceMB.TIoMCostAmount, VS4TARInvoice.TIvoTRBKCode, VS4TProduct.TPdtFactoryCode, VS4TProduct.TPdtTAPNCode, VS4TAR.TARNVirtualAccNo FROM VS4TProductSection RIGHT JOIN ((((((((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 VS4TCountry ON VS4TAR.TARNTCouCode = VS4TCountry.TCouCode) LEFT JOIN VS4TBranch ON VS4TARCreditNote.TRCNTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TARBranch ON (VS4TARCreditNote.TRCNTARDCode = VS4TARBranch.TARDCode) AND (VS4TARCreditNote.TRCNTARNCode = VS4TARBranch.TARDTARNCode)) LEFT JOIN VS4TARInvoice AS VS4TARInvoice_1 ON VS4TARCreditNote.TRCNNo = VS4TARInvoice_1.TIvoNo) 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) LEFT JOIN VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code) LEFT JOIN VS4TARWelfare ON VS4TARCreditNoteMB.TRCMTARWCode = VS4TARWelfare.TARWCode) LEFT JOIN VS4TLocation ON VS4TARCreditNoteMB.TRCMTLctCode = VS4TLocation.TLctCode) LEFT JOIN VS4TARInvoiceMB ON (VS4TARCreditNoteMB.TRCMLn = VS4TARInvoiceMB.TIoMLn) AND (VS4TARCreditNoteMB.TRCMTRCNNo = VS4TARInvoiceMB.TIoMTIvoNo)) ON VS4TARCreditNote.TRCNNo = VS4TARCreditNoteMB.TRCMTRCNNo) LEFT JOIN ((VS4TAR2 LEFT JOIN VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode) LEFT JOIN VS4TARHolder ON VS4TAR2.TAR2SaleCode = VS4TARHolder.TARHCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode
GO

CREATE VIEW VS4VARCreditNoteH AS  SELECT VS4TARCreditNote.*, VS4TARInvoice.*, VS4TAR.TARNTSAeCode, VS4TAR2.TAR2SaleCode FROM ((VS4TARCreditNote LEFT JOIN VS4TAR ON VS4TARCreditNote.TRCNTARNCode = VS4TAR.TARNCode) LEFT JOIN VS4TARInvoice ON VS4TARCreditNote.TRCNNo = VS4TARInvoice.TIvoNo) LEFT JOIN VS4TAR2 ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode
GO

CREATE VIEW VS4VARDebitNote AS  SELECT VS4TARDebitNote.*, VS4TARDebitNoteMB.*, VS4TProject.TPrjName, 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, VS4TProduct.TPdtTPS2Code, VS4TProduct.TPdtTPSECode, VS4TProductSection.TPSEName, VS4TProductSec2.TPS2Name, VS4TAR2.TAR2SaleCode, VS4TARHolder.TARHName, VS4TAR.TARNName2, VS4TAR.TARNAddressBill, VS4TAR.TARNAddressBill2, VS4TARWelfare.TARWName, VS4TARBranch.TARDName, VS4TAR.TARNTaxNo, VS4TARInvoice_1.TIvoClientTaxNo, VS4TARInvoice_1.TIvoBranchCode, VS4TARInvoice_1.TIvoBranchName, VS4TARInvoice_1.TIvoCopyNote, VS4TARInvoice_1.TIvoDestination, VS4TAR.TARNVirtualAccNo FROM VS4TProductSection RIGHT JOIN (((((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) LEFT JOIN VS4TARHolder ON VS4TAR2.TAR2SaleCode = VS4TARHolder.TARHCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) INNER JOIN ((((((VS4TARDebitNote LEFT JOIN VS4TCountry ON VS4TARDebitNote.TDBNTCurCode = VS4TCountry.TCouCode) LEFT JOIN VS4TBranch ON VS4TARDebitNote.TDBNTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TARBranch ON (VS4TARDebitNote.TDBNTARDCode = VS4TARBranch.TARDCode) AND (VS4TARDebitNote.TDBNTARNCode = VS4TARBranch.TARDTARNCode)) LEFT JOIN VS4TARInvoice AS VS4TARInvoice_1 ON VS4TARDebitNote.TDBNNo = VS4TARInvoice_1.TIvoNo) LEFT JOIN VS4TProject ON VS4TARDebitNote.TDBNTPrjCode = VS4TProject.TPrjCode) INNER JOIN (((((VS4TARDebitNoteMB LEFT JOIN VS4TPOS ON VS4TARDebitNoteMB.TDBMTPOSCode = VS4TPOS.TPOSCode) LEFT JOIN VS4TARInvoice ON VS4TARDebitNoteMB.TDBMSourceNo = VS4TARInvoice.TIvoNo) LEFT JOIN VS4TProduct ON VS4TPOS.TPOSCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code) LEFT JOIN VS4TARWelfare ON VS4TARDebitNoteMB.TDBMTARWCode = VS4TARWelfare.TARWCode) ON VS4TARDebitNote.TDBNNo = VS4TARDebitNoteMB.TDBMTDBNNo) ON VS4TAR.TARNCode = VS4TARDebitNote.TDBNTARNCode) ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode
GO

CREATE VIEW VS4VARDebitNoteH AS  SELECT VS4TARDebitNote.*, VS4TARInvoice.*, VS4TAR.TARNTSAeCode, VS4TAR2.TAR2SaleCode FROM ((VS4TARDebitNote LEFT JOIN VS4TAR ON VS4TARDebitNote.TDBNTARNCode = VS4TAR.TARNCode) LEFT JOIN VS4TARInvoice ON VS4TARDebitNote.TDBNNo = VS4TARInvoice.TIvoNo) LEFT JOIN VS4TAR2 ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode
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, VS4TARCampaign.*, VS4TProduct.TPdtCode, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtStartDate, VS4TProduct.TPdtEndDate FROM ((VS4TInquiryGroup RIGHT JOIN VS4TInquiry ON VS4TInquiryGroup.TIQGCode = VS4TInquiry.TIQRTIQGCode) RIGHT JOIN (VS4TInquiryChoice RIGHT JOIN (((((((VS4TAR LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) RIGHT JOIN VS4TARInquiry ON VS4TAR.TARNCode = VS4TARInquiry.TAQCTARNCode) LEFT JOIN VS4TPOS ON VS4TARInquiry.TAQCTPOSCode = VS4TPOS.TPOSCode) LEFT JOIN VS4TProduct ON VS4TARInquiry.TAQCTPOSCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TARCampaign ON VS4TARInquiry.TAQCTRCACode = VS4TARCampaign.TRCACode) LEFT JOIN VS4TAR2 ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) LEFT JOIN VS4TAR3 ON VS4TAR.TARNCode = VS4TAR3.TAR3TARNCode) ON (VS4TInquiryChoice.TIQCLn = VS4TARInquiry.TAQCTIQCLn) AND (VS4TInquiryChoice.TIQCTIQRCode = VS4TARInquiry.TAQCTIQCTIQRCode)) ON VS4TInquiry.TIQRCode = VS4TInquiryChoice.TIQCTIQRCode) LEFT JOIN VS4TProduct2 ON VS4TProduct.TPdtCode = VS4TProduct2.TPd2TPdtCode
GO

CREATE VIEW VS4VARInvoice AS  SELECT VS4TARInvoice.TIvoNo, VS4TARInvoice.TIvoBalanceFlag, VS4TARInvoice.TIvoType, VS4TARInvoice.TIvoTRBKCode, VS4TARInvoice.TIvoTRCACode, VS4TARInvoice.TIvoMode, VS4TARInvoice.TIvoDate, VS4TARInvoice.TIvoDueDate, VS4TARInvoice.TIvoGLMethod, VS4TARInvoice.TIvoTGLTNo, VS4TARInvoice.TIvoTaxNo, VS4TARInvoice.TIvoRefNo, VS4TARInvoice.TIvoRefDate, VS4TARInvoice.TIvoRefNo2, VS4TARInvoice.TIvoRefDate2, VS4TARInvoice.TIvoPONo, VS4TARInvoice.TIvoSOCode, VS4TARInvoice.TIvoJobCode, VS4TARInvoice.TIvoTJobNo, VS4TARInvoice.TIvoTPrjCode, VS4TARInvoice.TIvoTBraCode, VS4TARInvoice.TIvoTEmpCode, VS4TARInvoice.TIvoSaleName, VS4TARInvoice.TIvoDeliveryDate, VS4TARInvoice.TIvoDeliveryTo, VS4TARInvoice.TIvoTARNCode, VS4TARInvoice.TIvoTARDCode, VS4TARInvoice.TIvoContactNote, VS4TARInvoice.TIvoContactName, VS4TARInvoice.TIvoCustomerName, VS4TARInvoice.TIvoCusAddress, VS4TARInvoice.TIvoCustomerName2, VS4TARInvoice.TIvoCusAddress2, VS4TARInvoice.TIvoConsignee, VS4TARInvoice.TIvoNotifyParty, VS4TARInvoice.TIvoCostTotal, VS4TARInvoice.TIvoPriceChannel, VS4TARInvoice.TIvoDiscountList, VS4TARInvoice.TIvoSubTotal, VS4TARInvoice.TIvoDiscountText, VS4TARInvoice.TIvoDiscountTotal, VS4TARInvoice.TIvoNetTotal, VS4TARInvoice.TIvoDepositText, VS4TARInvoice.TIvoDeposit, VS4TARInvoice.TIvoTotal, VS4TARInvoice.TIvoTotalFOB, VS4TARInvoice.TIvoTCurCode, VS4TARInvoice.TIvoExchangeRate, VS4TARInvoice.TIvoTotalInRate, VS4TARInvoice.TIvoVATType, VS4TARInvoice.TIvoVATRate, VS4TARInvoice.TIvoTaxBase, VS4TARInvoice.TIvoVATTotal, VS4TARInvoice.TIvoGrandTotal, VS4TARInvoice.TIvoWTaxBase, VS4TARInvoice.TIvoWTaxRate, VS4TARInvoice.TIvoWTaxTotal, VS4TARInvoice.TIvoNetPayment, VS4TARInvoice.TIvoBaseArrears, VS4TARInvoice.TIvoArrears, VS4TARInvoice.TIvoAdjustTotal, VS4TARInvoice.TIvoBaseAvailable, VS4TARInvoice.TIvoAvailable, VS4TARInvoice.TIvoRewardTotal, VS4TARInvoice.TIvoPremiumTotal, VS4TARInvoice.TIvoCommissionBase, VS4TARInvoice.TIvoCommissionRate, VS4TARInvoice.TIvoCommission, VS4TARInvoice.TIvoBaseIncoType, VS4TARInvoice.TIvoIncoType, VS4TARInvoice.TIvoIncoTerms, VS4TARInvoice.TIvoOtherFee, VS4TARInvoice.TIvoTransportFee, VS4TARInvoice.TIvoHandlingFee, VS4TARInvoice.TIvoFreightFee, VS4TARInvoice.TIvoInsurance, VS4TARInvoice.TIvoTransportDesc, VS4TARInvoice.TIvoDuty, VS4TARInvoice.TIvoShipBy, VS4TARInvoice.TIvoCountryOrigin, VS4TARInvoice.TIvoDestination, VS4TARInvoice.TIvoCondition, VS4TARInvoice.TIvoConditionDay, VS4TARInvoice.TIvoCondition1, VS4TARInvoice.TIvoConditionDay1, VS4TARInvoice.TIvoPaymentNote, VS4TARInvoice.TIvoStatementNote, VS4TARInvoice.TIvoTShpCode, VS4TARInvoice.TIvoDeliveryNote, VS4TARInvoice.TIvoPackingNote, VS4TARInvoice.TIvoCustom1, VS4TARInvoice.TIvoCustom2, VS4TARInvoice.TIvoCustom3, VS4TARInvoice.TIvoCustom4, VS4TARInvoice.TIvoCustom5, VS4TARInvoice.TIvoCustom6, VS4TARInvoice.TIvoCartonName, VS4TARInvoice.TIvoTotalCarton, VS4TARInvoice.TIvoTotalNW, VS4TARInvoice.TIvoTotalGW, VS4TARInvoice.TIvoDayAvailable, VS4TARInvoice.TIvoDescription, VS4TARInvoice.TIvoTSOTCode, VS4TARInvoice.TIvoDeliveryStatus, VS4TARInvoice.TIvoBillStatus, VS4TARInvoice.TIvoCardFlag, VS4TARInvoice.TIvoEditCode, VS4TARInvoice.TIvoEditBy, VS4TARInvoice.TIvoEditDate, VS4TARInvoice.TIvoConfirmBy, VS4TARInvoice.TIvoApproveStatus, VS4TARInvoice.TIvoApproveBy, VS4TARInvoice.TIvoApproveDate, VS4TARInvoice.TIvoApproveNote, VS4TARInvoice.TIvoRevision, VS4TARInvoice.TIvoCancelStatus, VS4TARInvoice.TIvoFlag1, VS4TARInvoice.TIvoTRouCode, VS4TARInvoice.TIvoCustomNo, VS4TARInvoice.TIvoCustomDate, VS4TARInvoice.TIvoPMCostTotal, VS4TARInvoice.TIvoTOTNLn, VS4TARInvoice.TIvoDeliveryCond, VS4TARInvoice.TIvoLoadingDate, VS4TARInvoice.TIvoStartAgingDate, VS4TARInvoice.TIvoIgnoreArrears, VS4TARInvoice.TIvoBoxList, VS4TARInvoice.TIvoExchangeRate2, VS4TARInvoice.TIvoNote, VS4TARInvoice.TIvoTotalQuantity, VS4TARInvoice.TIvoTPOSCode, VS4TARInvoice.TIvoReceiptStatus, VS4TARInvoice.TIvoManualArrear, VS4TARInvoice.TIvoCardStatus, VS4TARInvoice.TIvoRefNo3, VS4TARInvoice.TIvoTARWCode, VS4TARInvoiceMB.TIoMTIvoNo, VS4TARInvoiceMB.TIoMLn, VS4TARInvoiceMB.TIoMType, VS4TARInvoiceMB.TIoMGroupName, VS4TARInvoiceMB.TIoMJobCode, VS4TARInvoiceMB.TIoMTOInCode, VS4TARInvoiceMB.TIoMTPOSCode, VS4TARInvoiceMB.TIoMSerialNo, VS4TARInvoiceMB.TIoMCustom1, VS4TARInvoiceMB.TIoMCustom2, VS4TARInvoiceMB.TIoMCustom3, VS4TARInvoiceMB.TIoMCustom4, VS4TARInvoiceMB.TIoMCustom5, VS4TARInvoiceMB.TIoMShippingMark, VS4TARInvoiceMB.TIoMPOSCode, VS4TARInvoiceMB.TIoMFactoryCode, VS4TARInvoiceMB.TIoMPOSName, VS4TARInvoiceMB.TIoMCost, VS4TARInvoiceMB.TIoMPrice, VS4TARInvoiceMB.TIoMPerQuantity, VS4TARInvoiceMB.TIoMUnitFactor, VS4TARInvoiceMB.TIoMAcceptError, VS4TARInvoiceMB.TIoMUnitCalc, VS4TARInvoiceMB.TIoMQuantityCalc, VS4TARInvoiceMB.TIoMQuantityText, VS4TARInvoiceMB.TIoMQuantity, VS4TARInvoiceMB.TIoMTUntCode, VS4TARInvoiceMB.TIoMQuantity2, VS4TARInvoiceMB.TIoMTUntCode2, VS4TARInvoiceMB.TIoMQuantity3, VS4TARInvoiceMB.TIoMTUntCode3, VS4TARInvoiceMB.TIoMCostAmount, VS4TARInvoiceMB.TIoMAmount, VS4TARInvoiceMB.TIoMDiscountText, VS4TARInvoiceMB.TIoMDiscountTotal, VS4TARInvoiceMB.TIoMNetAmount, VS4TARInvoiceMB.TIoMTaxType, VS4TARInvoiceMB.TIoMTaxBase, VS4TARInvoiceMB.TIoMWTAXBase, VS4TARInvoiceMB.TIoMAmountVAT, VS4TARInvoiceMB.TIoMAmountWTAX, VS4TARInvoiceMB.TIoMPromotionType, VS4TARInvoiceMB.TIoMFreeCode, VS4TARInvoiceMB.TIoMIsPremium, VS4TARInvoiceMB.TIoMDescription, VS4TARInvoiceMB.TIoMSourceNo, VS4TARInvoiceMB.TIoMSourceLn, VS4TARInvoiceMB.TIoMSourcePeriod, VS4TARInvoiceMB.TIoMSourceDate, VS4TARInvoiceMB.TIoMTLctCode, VS4TARInvoiceMB.TIoMCommissionBase, VS4TARInvoiceMB.TIoMCommissionRate, VS4TARInvoiceMB.TIoMCommission, VS4TARInvoiceMB.TIoMPremiumCost, VS4TARInvoiceMB.TIoMQuantityStock, VS4TARInvoiceMB.TIoMAVGWeighting, VS4TARInvoiceMB.TIoMDiscountBill, VS4TARInvoiceMB.TIoMDeposit, VS4TARInvoiceMB.TIoMTARWCode, VS4TCountry.TCouName, VS4TAR.TARNAddressBill, VS4TAR.TARNName, VS4TAR2.TAR2TPrvCode, VS4TProvince.TPrvName, VS4TARGroup.TARGName, VS4TAR.TARNTARGCode, VS4TAR.TARNTBsTCode, VS4TAR.TARNTSAeCode, VS4TBranch.TBraName, VS4TAR2.TAR2SaleCode, VS4TProduct.TPdtTransferCode, VS4TProduct.TPdtName, VS4TProduct.TPdtDescription, VS4TProduct.TPdtName2, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtTPSECode, VS4TProduct.TPdtTPG1Code, VS4TProduct.TPdtTPS2Code, VS4TProductSec2.TPS2Name, VS4TProductGroup1.TPG1Name, VS4TProduct.TPdtTPG2Code, VS4TAR2.TAR2Marks, VS4TProductSection.TPSEName, VS4TProduct.TPdtTAPNCode, VS4TProduct.TPdtCustom1, VS4TBranch.TBraAddressBill, VS4TProduct.TPdtTPTTCode, VS4TShipping.TSHPName, VS4TAR.TARNPhone, VS4TARHolder.TARHName, VS4TProduct.TPdtFactoryCode, VS4TProduct.TPdtTUntCode, VS4TAR.TARNName2, VS4TAR.TARNAddressBill2, VS4TAR.TARNFax, VS4TProduct.TPdtOldCode, VS4TSOMB.TSOBSourceNo, VS4TAR2.TAR2DeliveryCond, VS4TARInvoiceMB.TIoMTRCACode, VS4TARInvoiceMB.TIoMFlag1, VS4TProject.TPrjName, VS4TProduct.TPdtBarcode, VS4TARInvoiceMB.TIoMStockFlag, VS4TARInvoiceMB.TIoMMinimumOrder, VS4TARInvoiceMB.TIoMWelfareRate, VS4TARInvoice.TIvoFlag2, VS4TARInvoiceMB.TIoMTPltCode, VS4TAR.TARNTaxNo, VS4TARBranch.TARDName, VS4TRoute.TRouName, VS4TARInvoice.TIvoClientTaxNo, VS4TARInvoice.TIvoBranchCode, VS4TARInvoice.TIvoBranchName, VS4TARInvoiceMB.TIoMPickingNo, VS4TARInvoice.TIvoCopyNote, VS4TProduct.TPdtCustom2, VS4TARInvoiceMB.TIoMQuantityBase, VS4TARInvoiceDep.TIRDDocNo, VS4TSaleArea.TSAeName, VS4TAR.TARNVirtualAccNo FROM ((((VS4TAR LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) LEFT JOIN (((VS4TAR2 LEFT JOIN VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode) LEFT JOIN VS4TARHolder ON VS4TAR2.TAR2SaleCode = VS4TARHolder.TARHCode) LEFT JOIN VS4TShipping AS VS4TShipping_1 ON VS4TAR2.TAR2TShpCode = VS4TShipping_1.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) LEFT JOIN VS4TDeliveryOut ON VS4TARInvoice.TIvoCustomNo = VS4TDeliveryOut.TDCONo) LEFT JOIN VS4TARBranch ON (VS4TARInvoice.TIvoTARDCode = VS4TARBranch.TARDCode) AND (VS4TARInvoice.TIvoTARNCode = VS4TARBranch.TARDTARNCode)) LEFT JOIN VS4TRoute ON VS4TARInvoice.TIvoTRouCode = VS4TRoute.TRouCode) LEFT JOIN VS4TShipping ON VS4TARInvoice.TIvoTShpCode = VS4TShipping.TSHPCode) LEFT JOIN VS4TARInvoiceDep ON VS4TARInvoice.TIvoNo = VS4TARInvoiceDep.TIRDTIvoNo) ON VS4TAR.TARNCode = VS4TARInvoice.TIvoTARNCode) 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) LEFT JOIN VS4TDeliveryOutMB ON (VS4TARInvoiceMB.TIoMLn = VS4TDeliveryOutMB.TDOMTIoMLn) AND (VS4TARInvoiceMB.TIoMTIvoNo = VS4TDeliveryOutMB.TDOMTIoMTIvoNo)) LEFT JOIN VS4TProduct3 ON VS4TProduct.TPdtCode = VS4TProduct3.TPD3TPdtCode) LEFT JOIN VS4TSOMB ON (VS4TARInvoiceMB.TIoMSourceLn = VS4TSOMB.TSOBLn) AND (VS4TARInvoiceMB.TIoMSourceNo = VS4TSOMB.TSOBTSODNo)) LEFT JOIN VS4TARWelfare ON VS4TARInvoiceMB.TIoMTARWCode = VS4TARWelfare.TARWCode) ON VS4TARInvoice.TIvoNo = VS4TARInvoiceMB.TIoMTIvoNo WHERE (((VS4TARInvoiceDep.TIRDLn)=1 Or (VS4TARInvoiceDep.TIRDLn) Is Null))
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.TRDRRefReceiptNo,                           VS4TARReceipt.TAIHDate, VS4TARInvoice.TIvoTPrjCode, VS4TProject.TPrjName, 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, VS4TARVDocRef.TRDRRefDocDate,                           VS4TARVoucherPay.TRVRAmountInRate, VS4TARVoucherPay.TRVRTransferDate, VS4TARVoucherPay.TRVRCashDate, VS4TAR.TARNAddressBill, VS4TAR.TARNPhone, VS4TAR.TARNMobile,                           VS4TAR3.TAR3BirthDay, VS4TAR3.TAR3BirthDayValid, VS4TARInvoice.TIvoTPOSCode, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtStartDate, VS4TProduct.TPdtEndDate,                           VS4TARInvoiceMB.TIoMTIvoNo, VS4TARInvoiceMB.TIoMLn, VS4TARInvoice.TIvoType, VS4TARVoucher.TRVHArrear, VS4TARVDocRef.TRDRAmountRate, VS4TARVoucher.TRVHTBraCode,                           VS4TARVoucherPay.TRVRFee FROM            VS4TARVoucher RIGHT OUTER JOIN                          VS4TProject RIGHT OUTER JOIN                          VS4TBusinessType RIGHT OUTER JOIN                          VS4TAR2 RIGHT OUTER JOIN                          VS4TSaleArea RIGHT OUTER JOIN                          VS4TARGroup RIGHT OUTER JOIN                          VS4TAR ON VS4TARGroup.TARGCode = VS4TAR.TARNTARGCode ON VS4TSaleArea.TSAeCode = VS4TAR.TARNTSAeCode ON VS4TAR2.TAR2TARNCode = VS4TAR.TARNCode LEFT OUTER JOIN                          VS4TEmployee ON VS4TAR2.TAR2SaleCode = VS4TEmployee.TEmpCode LEFT OUTER JOIN                          VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode LEFT OUTER JOIN                          VS4TAR3 ON VS4TAR.TARNCode = VS4TAR3.TAR3TARNCode RIGHT OUTER JOIN                          VS4TCountry RIGHT OUTER JOIN                          VS4TBranch RIGHT OUTER JOIN                          VS4TARInvoice LEFT OUTER JOIN                          VS4TARVDocRef ON VS4TARInvoice.TIvoNo = VS4TARVDocRef.TRDRRefDocNo ON VS4TBranch.TBraCode = VS4TARInvoice.TIvoTBraCode ON                           VS4TCountry.TCouCode = VS4TARInvoice.TIvoCountryOrigin LEFT OUTER JOIN                          VS4TARReceipt ON VS4TARVDocRef.TRDRRefReceiptNo = VS4TARReceipt.TAIHNo LEFT OUTER JOIN                          VS4TARBill ON VS4TARVDocRef.TRDRRefBillNo = VS4TARBill.TBilNo LEFT OUTER JOIN                          VS4TProduct ON VS4TARInvoice.TIvoTPOSCode = VS4TProduct.TPdtCode 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 OUTER JOIN                          VS4TARVoucherPay ON VS4TARVoucher.TRVHNo = VS4TARVoucherPay.TRVRTRVHNo LEFT OUTER JOIN                          VS4TChequeRec RIGHT OUTER JOIN                          VS4TChequeRec2RV ON VS4TChequeRec.TCHRNo = VS4TChequeRec2RV.TR2RTCHRNo ON VS4TARVoucherPay.TRVRLn = VS4TChequeRec2RV.TR2RTRVRLn AND                           VS4TARVoucherPay.TRVRTRVHNo = VS4TChequeRec2RV.TR2RTRVRTRVHNo WHERE        (VS4TARInvoice.TIvoType <> 10)
GO

CREATE VIEW VS4VARInvoiceADJH 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, VS4TAR2.TAR2Distance, VS4TShipping.TSHPName, VS4TEmployee.TEmpFullName, VS4TARInvoiceADJ.TIvAIVTotal, VS4TARInvoiceADJ.TIvACNTotal, VS4TARInvoiceADJ.TIvADBTotal, VS4TARInvoiceADJ.TIvAIVArrear, VS4TARInvoiceADJ.TIvACNArrear, VS4TARInvoiceADJ.TIvADBArrear, VS4TARInvoiceADJ.TIvATotalArrear, VS4TARInvoiceADJ.TIvAIVNetPayment, VS4TARInvoiceADJ.TIvACNNetPayment, VS4TARInvoiceADJ.TIvADBNetPayment, VS4TARInvoiceADJ.TIvARefCN, VS4TARInvoiceADJ.TIvARefDB, VS4TARInvoiceADJ.TIvARefPayment 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) LEFT JOIN VS4TEmployee ON VS4TAR2.TAR2SaleCode = VS4TEmployee.TEmpCode) 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 VS4TARInvoiceADJ ON VS4TARInvoice.TIvoNo = VS4TARInvoiceADJ.TIvANo) ON VS4TAR.TARNCode = VS4TARInvoice.TIvoTARNCode) ON VS4TBusinessType.TBsTCode = VS4TAR.TARNTBsTCode) ON VS4TSaleZone.TSZnCode = VS4TSaleArea.TSaeTSZnCode
GO

CREATE VIEW VS4VARInvoiceArr AS  SELECT TIvoNo, TIvoBalanceFlag, TIvoType, TIvoTRBKCode, TIvoTRCACode, TIvoMode, TIvoDate, TIvoDueDate, TIvoGLMethod, TIvoTGLTNo, TIvoClientTaxNo, TIvoTaxNo, TIvoRefNo, TIvoRefDate, TIvoRefNo2, TIvoRefDate2, TIvoPONo, TIvoSOCode, TIvoJobCode, TIvoTJobNo, TIvoTJbMLn, TIvoTPrjCode, TIvoTBraCode, TIvoTEmpCode, TIvoSaleName, TIvoDeliveryDate, TIvoDeliveryTo, TIvoTARNCode, TIvoTARDCode, TIvoContactNote, TIvoContactName, TIvoCustomerName, TIvoCusAddress, TIvoCustomerName2, TIvoCusAddress2, TIvoConsignee, TIvoNotifyParty, TIvoCostTotal, TIvoPriceChannel, TIvoDiscountList, TIvoSubTotal, TIvoDiscountText, TIvoDiscountTotal, TIvoNetTotal, TIvoDepositText, TIvoDeposit, TIvoTotal, TIvoTotalFOB, TIvoTCurCode, TIvoExchangeRate, TIvoTotalInRate, TIvoVATType, TIvoVATRate, TIvoTaxBase, TIvoVATTotal, TIvoGrandTotal, TIvoNOTAXTotal, TIvoWTaxBase, TIvoWTaxRate, TIvoWTaxTotal, TIvoNetPayment, TIvoBaseArrears, TIvoArrears, TIvoAdjustTotal, TIvoBaseAvailable, TIvoAvailable, TIvoRewardTotal, TIvoPremiumTotal, TIvoCommissionBase, TIvoCommissionRate, TIvoCommission, TIvoBaseIncoType, TIvoIncoType, TIvoIncoTerms, TIvoOtherFee, TIvoTransportFee, TIvoHandlingFee, TIvoFreightFee, TIvoInsurance, TIvoTransportDesc, TIvoDuty, TIvoShipBy, TIvoCountryOrigin, TIvoDestination, TIvoCondition, TIvoConditionDay, TIvoCondition1, TIvoConditionDay1, TIvoPaymentNote, TIvoStatementNote, TIvoTShpCode, TIvoDeliveryNote, TIvoPackingNote, TIvoCustom1, TIvoCustom2, TIvoCustom3, TIvoCustom4, TIvoCustom5, TIvoCustom6, TIvoCartonName, TIvoTotalCarton, TIvoTotalNW, TIvoTotalGW, TIvoDayAvailable, TIvoDescription, TIvoTSOTCode, TIvoDeliveryStatus, TIvoBillStatus, TIvoCardFlag, TIvoTaxFlag, TIvoCreateBy, TIvoEditCode, TIvoEditBy, TIvoEditDate, TIvoConfirmStatus, TIvoConfirmBy, TIvoConfirmDate, TIvoApproveStatus, TIvoApproveBy, TIvoApproveDate, TIvoApproveNote, TIvoRevision, TIvoCancelStatus, TIvoCancelBy, TIvoCancelDate, TIvoCancelNote, TIvoFlag1, TIvoTRouCode, TIvoCustomNo, TIvoCustomDate, TIvoPMCostTotal, TIvoTOTNLn, TIvoDeliveryCond, TIvoLoadingDate, TIvoStartAgingDate, TIvoIgnoreArrears, TIvoBoxList, TIvoExchangeRate2, TIvoNote, TIvoTotalQuantity, TIvoTPOSCode, TIvoReceiptStatus, TIvoManualArrear, TIvoCardStatus, TIvoRefNo3, TIvoTARWCode, TIvoTotalVolumeM, TIvoRefNo4, TIvoLastPayDate, TIvoInvoiceStatus, TIvoCNStatus, TIoMTIvoNo, TIoMLn, TIoMType, TIoMGroupName, TIoMJobCode, TIoMTOInCode, TIoMTPOSCode, TIoMSerialNo, TIoMCustom1, TIoMCustom2, TIoMCustom3, TIoMCustom4, TIoMCustom5, TIoMShippingMark, TIoMPOSCode, TIoMFactoryCode, TIoMPOSName, TIoMCost, TIoMPrice, TIoMPerQuantity, TIoMUnitFactor, TIoMAcceptError, TIoMUnitCalc, TIoMQuantityCalc, TIoMQuantityText, TIoMQuantity, TIoMTUntCode, TIoMQuantity2, TIoMTUntCode2, TIoMQuantity3, TIoMTUntCode3, TIoMCostAmount, TIoMAmount, TIoMDiscountText, TIoMDiscountTotal, TIoMNetAmount, TIoMTaxType, TIoMTaxBase, TIoMWTAXBase, TIoMAmountVAT, TIoMAmountWTAX, TIoMPromotionType, TIoMFreeCode, TIoMIsPremium, TIoMDescription, TIoMSourceNo, TIoMSourceLn, TIoMSourceDate, TIoMTLctCode, TIoMCommissionBase, TIoMCommissionRate, TIoMCommission, TIoMFlag1, TIoMFlag2, TIoMPremiumCost, TIoMQuantityStock, TIoMAVGWeighting, TIoMDiscountBill, TIoMDeposit, TIoMTARWCode, TIoMTRCACode, TIoMStockFlag, TIoMMinimumOrder, TIoMWelfareRate, TIoMControlQty, TIoMWelfareAmount, TIoMTPltCode, TIoMTotalCN, TIoMTotalCNArr, TIoMQuantityPallet, TIoMPOSName2, TIoMQuantityBase, TIoMPickingNo, 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, VS4TAR.TARNTARGCode, VS4TAR.TARNAddress, VS4TAR.TARNSubProvince, VS4TAR.TARNCity, VS4TAR.TARNPhone, VS4TAR.TARNFax, VS4TSaleArea.TSAeCode, VS4TProduct.TPdtTPS2Code, VS4TProductSec2.TPS2Name 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 LEFT JOIN VS4TProduct ON VS4TARInvoiceMB.TIoMTPOSCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code) ON VS4TARInvoice.TIvoNo = VS4TARInvoiceMB.TIoMTIvoNo) ON VS4TSaleZone.TSZnCode = VS4TSaleArea.TSaeTSZnCode
GO

CREATE VIEW VS4VARInvoiceArrH AS  SELECT VS4TARInvoice.*, VS4TCountry.TCouName, VS4TAR.*, VS4TProject.TPrjName, TSAeCode, TSaeTSZnCode, TSAeName, TSAeName2, VS4TARGroup.TARGCode, VS4TARGroup.TARGName, 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.TIvoNo, VS4TARInvoice.TIvoBalanceFlag, VS4TARInvoice.TIvoType, VS4TARInvoice.TIvoTRBKCode, VS4TARInvoice.TIvoTRCACode, VS4TARInvoice.TIvoMode, VS4TARInvoice.TIvoDate, VS4TARInvoice.TIvoDueDate, VS4TARInvoice.TIvoGLMethod, VS4TARInvoice.TIvoTGLTNo, VS4TARInvoice.TIvoClientTaxNo, VS4TARInvoice.TIvoTaxNo, VS4TARInvoice.TIvoRefNo, VS4TARInvoice.TIvoRefDate, VS4TARInvoice.TIvoRefNo2, VS4TARInvoice.TIvoRefDate2, VS4TARInvoice.TIvoPONo, VS4TARInvoice.TIvoSOCode, VS4TARInvoice.TIvoJobCode, VS4TARInvoice.TIvoTJobNo, VS4TARInvoice.TIvoTJbMLn, VS4TARInvoice.TIvoTPrjCode, VS4TARInvoice.TIvoTBraCode, VS4TARInvoice.TIvoTEmpCode, VS4TARInvoice.TIvoSaleName, VS4TARInvoice.TIvoDeliveryDate, VS4TARInvoice.TIvoDeliveryTo, VS4TARInvoice.TIvoTARNCode, VS4TARInvoice.TIvoTARDCode, VS4TARInvoice.TIvoContactNote, VS4TARInvoice.TIvoContactName, VS4TARInvoice.TIvoCustomerName, VS4TARInvoice.TIvoCusAddress, VS4TARInvoice.TIvoCustomerName2, VS4TARInvoice.TIvoCusAddress2, VS4TARInvoice.TIvoConsignee, VS4TARInvoice.TIvoNotifyParty, VS4TARInvoice.TIvoCostTotal, VS4TARInvoice.TIvoPriceChannel, VS4TARInvoice.TIvoDiscountList, VS4TARInvoice.TIvoSubTotal, VS4TARInvoice.TIvoDiscountText, VS4TARInvoice.TIvoDiscountTotal, VS4TARInvoice.TIvoNetTotal, VS4TARInvoice.TIvoDepositText, VS4TARInvoice.TIvoDeposit, VS4TARInvoice.TIvoTotal, VS4TARInvoice.TIvoTotalFOB, VS4TARInvoice.TIvoTCurCode, VS4TARInvoice.TIvoExchangeRate, VS4TARInvoice.TIvoTotalInRate, VS4TARInvoice.TIvoVATType, VS4TARInvoice.TIvoVATRate, VS4TARInvoice.TIvoTaxBase, VS4TARInvoice.TIvoVATTotal, VS4TARInvoice.TIvoGrandTotal, VS4TARInvoice.TIvoNOTAXTotal, VS4TARInvoice.TIvoWTaxBase, VS4TARInvoice.TIvoWTaxRate, VS4TARInvoice.TIvoWTaxTotal, VS4TARInvoice.TIvoNetPayment, VS4TARInvoice.TIvoBaseArrears, VS4TARInvoice.TIvoArrears, VS4TARInvoice.TIvoAdjustTotal, VS4TARInvoice.TIvoBaseAvailable, VS4TARInvoice.TIvoAvailable, VS4TARInvoice.TIvoRewardTotal, VS4TARInvoice.TIvoPremiumTotal, VS4TARInvoice.TIvoCommissionBase, VS4TARInvoice.TIvoCommissionRate, VS4TARInvoice.TIvoCommission, VS4TARInvoice.TIvoBaseIncoType, VS4TARInvoice.TIvoIncoType, VS4TARInvoice.TIvoIncoTerms, VS4TARInvoice.TIvoOtherFee, VS4TARInvoice.TIvoTransportFee, VS4TARInvoice.TIvoHandlingFee, VS4TARInvoice.TIvoFreightFee, VS4TARInvoice.TIvoInsurance, VS4TARInvoice.TIvoTransportDesc, VS4TARInvoice.TIvoDuty, VS4TARInvoice.TIvoShipBy, VS4TARInvoice.TIvoCountryOrigin, VS4TARInvoice.TIvoDestination, VS4TARInvoice.TIvoCondition, VS4TARInvoice.TIvoConditionDay, VS4TARInvoice.TIvoCondition1, VS4TARInvoice.TIvoConditionDay1, VS4TARInvoice.TIvoPaymentNote, VS4TARInvoice.TIvoStatementNote, VS4TARInvoice.TIvoTShpCode, VS4TARInvoice.TIvoDeliveryNote, VS4TARInvoice.TIvoPackingNote, VS4TARInvoice.TIvoCustom1, VS4TARInvoice.TIvoCustom2, VS4TARInvoice.TIvoCustom3, VS4TARInvoice.TIvoCustom4, VS4TARInvoice.TIvoCustom5, VS4TARInvoice.TIvoCustom6, VS4TARInvoice.TIvoCartonName, VS4TARInvoice.TIvoTotalCarton, VS4TARInvoice.TIvoTotalNW, VS4TARInvoice.TIvoTotalGW, VS4TARInvoice.TIvoDayAvailable, VS4TARInvoice.TIvoDescription, VS4TARInvoice.TIvoTSOTCode, VS4TARInvoice.TIvoDeliveryStatus, VS4TARInvoice.TIvoBillStatus, VS4TARInvoice.TIvoCardFlag, VS4TARInvoice.TIvoTaxFlag, VS4TARInvoice.TIvoCreateBy, VS4TARInvoice.TIvoEditCode, VS4TARInvoice.TIvoEditBy, VS4TARInvoice.TIvoConfirmStatus, VS4TARInvoice.TIvoConfirmBy, VS4TARInvoice.TIvoApproveStatus, VS4TARInvoice.TIvoApproveBy, VS4TARInvoice.TIvoApproveDate, VS4TARInvoice.TIvoRevision, VS4TARInvoice.TIvoCancelStatus, VS4TARInvoice.TIvoCancelBy, VS4TARInvoice.TIvoCancelDate, VS4TARInvoice.TIvoFlag1, VS4TARInvoice.TIvoFlag2, VS4TARInvoice.TIvoFlag3, VS4TARInvoice.TIvoTRouCode, VS4TARInvoice.TIvoCustomNo, VS4TARInvoice.TIvoCustomDate, VS4TARInvoice.TIvoPMCostTotal, VS4TARInvoice.TIvoTOTNLn, VS4TARInvoice.TIvoDeliveryCond, VS4TARInvoice.TIvoLoadingDate, VS4TARInvoice.TIvoStartAgingDate, VS4TARInvoice.TIvoIgnoreArrears, VS4TARInvoice.TIvoBoxList, VS4TARInvoice.TIvoExchangeRate2, VS4TARInvoice.TIvoNote, VS4TARInvoice.TIvoTotalQuantity, VS4TARInvoice.TIvoTPOSCode, VS4TARInvoice.TIvoReceiptStatus, VS4TARInvoice.TIvoManualArrear, VS4TARInvoice.TIvoCardStatus, VS4TARInvoice.TIvoRefNo3, VS4TARInvoice.TIvoTARWCode, VS4TARInvoice.TIvoTotalVolumeM, VS4TARInvoice.TIvoRefNo4, VS4TARInvoice.TIvoLastPayDate, VS4TARInvoice.TIvoInvoiceStatus, VS4TCountry.TCouName, VS4TAR.TARNCode, VS4TAR.TARNTCmpCode, VS4TAR.TARNTARTCode, VS4TAR.TARNIntro, VS4TAR.TARNName, VS4TAR.TARNName2, VS4TAR.TARNIntroName, VS4TAR.TARNType, VS4TAR.TARNOwnerName, VS4TAR.TARNDocCode, VS4TAR.TARNContactName, VS4TAR.TARNTaxNo, VS4TAR.TARNAccountCode, 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.TARNCreditLimit, VS4TAR.TARNCreditUseBal, VS4TAR.TARNCreditUse, VS4TAR.TARNCreditBalance, VS4TAR.TARNCreditAvaiBal, VS4TAR.TARNTotalOrderBal, VS4TAR.TARNPriceChannel, VS4TAR.TARNDiscountPC, VS4TAR.TARNDiscountDay, VS4TAR.TARNCreditDay, VS4TAR.TARNLimitTCurCode, VS4TAR.TARNSpecialTaxRate, VS4TAR.TARNPaymentNote, VS4TAR.TARNStatementNote, VS4TAR.TARNDeliveryNote, VS4TAR.TARNMapFile, VS4TAR.TARNTimeToOrder, VS4TAR.TARNLastDueDate, VS4TAR.TARNFirstOrderDate, VS4TAR.TARNLastOrderDate, VS4TAR.TARNTARSAlias, VS4TAR.TARNTBsTCode, VS4TAR.TARNTSAeCode, VS4TAR.TARNNeedBill, VS4TAR.TARNBillDay1, VS4TAR.TARNBillDay2, VS4TAR.TARNBillDay3, VS4TAR.TARNBillDay4, VS4TAR.TARNBillMove, VS4TAR.TARNBillAdjust, VS4TAR.TARNNote, VS4TAR.TARNCreateCode, VS4TAR.TARNCreateDate, VS4TAR.TARNEditCode, VS4TAR.TARNEditDate, VS4TAR.TARNTextSort, VS4TAR.TARNFlag1, VS4TAR.TARNDiscount, VS4TAR.TARNAddressBill2, VS4TAR.TARNTBraCode, VS4TAR.TARNChequeDay, VS4TAR.TARNChequeAddMonth, VS4TAR.TARNRegisterDate, VS4TAR.TARNMode, VS4TAR.TARNIECNo, VS4TProject.TPrjName, 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, VS4TAR2.TAR2TPrvCode, VS4TProvince.TPrvName, VS4TBusinessType.TBstName, VS4TBranch.TBraName, VS4TSaleArea.TSAeCode, VS4TSaleArea.TSaeTSZnCode, VS4TSaleArea.TSAeName, VS4TSaleArea.TSAeName2, VS4TSaleArea.TSAETEmpCode 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 VS4VARInvoiceDep AS  SELECT VS4TARInvoiceDep.*, VS4TARInvoice.* FROM VS4TARInvoice INNER JOIN VS4TARInvoiceDep ON VS4TARInvoice.TIvoNo = VS4TARInvoiceDep.TIRDTIvoNo
GO

CREATE VIEW VS4VARInvoiceEX AS  SELECT VS4TARInvoice.TIvoNo, VS4TARInvoice.TIvoBalanceFlag, VS4TARInvoice.TIvoType, VS4TARInvoice.TIvoTRBKCode, VS4TARInvoice.TIvoTRCACode, VS4TARInvoice.TIvoMode, VS4TARInvoice.TIvoDate, VS4TARInvoice.TIvoDueDate, VS4TARInvoice.TIvoGLMethod, VS4TARInvoice.TIvoTGLTNo, VS4TARInvoice.TIvoClientTaxNo, VS4TARInvoice.TIvoTaxNo, VS4TARInvoice.TIvoRefNo, VS4TARInvoice.TIvoRefDate, VS4TARInvoice.TIvoRefNo2, VS4TARInvoice.TIvoRefDate2, VS4TARInvoice.TIvoPONo, VS4TARInvoice.TIvoSOCode, VS4TARInvoice.TIvoJobCode, VS4TARInvoice.TIvoTJobNo, VS4TARInvoice.TIvoTJbMLn, VS4TARInvoice.TIvoTPrjCode, VS4TARInvoice.TIvoTBraCode, VS4TARInvoice.TIvoTEmpCode, VS4TARInvoice.TIvoSaleName, VS4TARInvoice.TIvoDeliveryDate, VS4TARInvoice.TIvoDeliveryTo, VS4TARInvoice.TIvoTARNCode, VS4TARInvoice.TIvoTARDCode, VS4TARInvoice.TIvoContactNote, VS4TARInvoice.TIvoContactName, VS4TARInvoice.TIvoCustomerName, VS4TARInvoice.TIvoCusAddress, VS4TARInvoice.TIvoCustomerName2, VS4TARInvoice.TIvoCusAddress2, VS4TARInvoice.TIvoConsignee, VS4TARInvoice.TIvoNotifyParty, VS4TARInvoice.TIvoCostTotal, VS4TARInvoice.TIvoPriceChannel, VS4TARInvoice.TIvoDiscountList, VS4TARInvoice.TIvoSubTotal, VS4TARInvoice.TIvoDiscountText, VS4TARInvoice.TIvoDiscountTotal, VS4TARInvoice.TIvoNetTotal, VS4TARInvoice.TIvoDepositText, VS4TARInvoice.TIvoDeposit, VS4TARInvoice.TIvoTotal, VS4TARInvoice.TIvoTotalFOB, VS4TARInvoice.TIvoTCurCode, VS4TARInvoice.TIvoExchangeRate, VS4TARInvoice.TIvoTotalInRate, VS4TARInvoice.TIvoVATType, VS4TARInvoice.TIvoVATRate, VS4TARInvoice.TIvoTaxBase, VS4TARInvoice.TIvoVATTotal, VS4TARInvoice.TIvoGrandTotal, VS4TARInvoice.TIvoNOTAXTotal, VS4TARInvoice.TIvoWTaxBase, VS4TARInvoice.TIvoWTaxRate, VS4TARInvoice.TIvoWTaxTotal, VS4TARInvoice.TIvoNetPayment, VS4TARInvoice.TIvoBaseArrears, VS4TARInvoice.TIvoArrears, VS4TARInvoice.TIvoAdjustTotal, VS4TARInvoice.TIvoBaseAvailable, VS4TARInvoice.TIvoAvailable, VS4TARInvoice.TIvoRewardTotal, VS4TARInvoice.TIvoPremiumTotal, VS4TARInvoice.TIvoCommissionBase, VS4TARInvoice.TIvoCommissionRate, VS4TARInvoice.TIvoCommission, VS4TARInvoice.TIvoBaseIncoType, VS4TARInvoice.TIvoIncoType, VS4TARInvoice.TIvoIncoTerms, VS4TARInvoice.TIvoOtherFee, VS4TARInvoice.TIvoTransportFee, VS4TARInvoice.TIvoHandlingFee, VS4TARInvoice.TIvoFreightFee, VS4TARInvoice.TIvoInsurance, VS4TARInvoice.TIvoTransportDesc, VS4TARInvoice.TIvoDuty, VS4TARInvoice.TIvoShipBy, VS4TARInvoice.TIvoCountryOrigin, VS4TARInvoice.TIvoDestination, VS4TARInvoice.TIvoCondition, VS4TARInvoice.TIvoConditionDay, VS4TARInvoice.TIvoCondition1, VS4TARInvoice.TIvoConditionDay1, VS4TARInvoice.TIvoPaymentNote, VS4TARInvoice.TIvoStatementNote, VS4TARInvoice.TIvoTShpCode, VS4TARInvoice.TIvoDeliveryNote, VS4TARInvoice.TIvoPackingNote, VS4TARInvoice.TIvoCustom1, VS4TARInvoice.TIvoCustom2, VS4TARInvoice.TIvoCustom3, VS4TARInvoice.TIvoCustom4, VS4TARInvoice.TIvoCustom5, VS4TARInvoice.TIvoCustom6, VS4TARInvoice.TIvoCartonName, VS4TARInvoice.TIvoTotalCarton, VS4TARInvoice.TIvoTotalNW, VS4TARInvoice.TIvoTotalGW, VS4TARInvoice.TIvoTotalVolumeM, VS4TARInvoice.TIvoDayAvailable, VS4TARInvoice.TIvoDescription, VS4TARInvoice.TIvoTSOTCode, VS4TARInvoice.TIvoDeliveryStatus, VS4TARInvoice.TIvoBillStatus, VS4TARInvoice.TIvoCardFlag, VS4TARInvoice.TIvoTaxFlag, VS4TARInvoice.TIvoCreateBy, VS4TARInvoice.TIvoEditCode, VS4TARInvoice.TIvoEditBy, VS4TARInvoice.TIvoEditDate, VS4TARInvoice.TIvoConfirmBy, VS4TARInvoice.TIvoApproveBy, VS4TARInvoice.TIvoRevision, VS4TARInvoice.TIvoCancelStatus, VS4TARInvoice.TIvoCancelBy, VS4TARInvoice.TIvoCancelDate, VS4TARInvoice.TIvoTRouCode, VS4TARInvoice.TIvoCustomNo, VS4TARInvoice.TIvoCustomDate, VS4TARInvoice.TIvoPMCostTotal, VS4TARInvoice.TIvoTOTNLn, VS4TARInvoice.TIvoDeliveryCond, VS4TARInvoice.TIvoLoadingDate, VS4TARInvoice.TIvoStartAgingDate, VS4TARInvoice.TIvoIgnoreArrears, VS4TARInvoice.TIvoBoxList, VS4TARInvoice.TIvoExchangeRate2, VS4TARInvoice.TIvoNote, VS4TARInvoice.TIvoTotalQuantity, VS4TARInvoice.TIvoTPOSCode, VS4TARInvoice.TIvoReceiptStatus, VS4TARInvoice.TIvoManualArrear, VS4TARInvoice.TIvoCardStatus, VS4TARInvoice.TIvoRefNo3, VS4TARInvoice.TIvoTARWCode, VS4TARInvoiceMB.TIoMTIvoNo, VS4TARInvoiceMB.TIoMLn, VS4TARInvoiceMB.TIoMType, VS4TARInvoiceMB.TIoMGroupName, VS4TARInvoiceMB.TIoMJobCode, VS4TARInvoiceMB.TIoMTOInCode, VS4TARInvoiceMB.TIoMTPOSCode, VS4TARInvoiceMB.TIoMSerialNo, VS4TARInvoiceMB.TIoMCustom1, VS4TARInvoiceMB.TIoMCustom2, VS4TARInvoiceMB.TIoMCustom3, VS4TARInvoiceMB.TIoMCustom4, VS4TARInvoiceMB.TIoMCustom5, VS4TARInvoiceMB.TIoMShippingMark, VS4TARInvoiceMB.TIoMPOSCode, VS4TARInvoiceMB.TIoMFactoryCode, VS4TARInvoiceMB.TIoMPOSName, VS4TARInvoiceMB.TIoMCost, VS4TARInvoiceMB.TIoMPrice, VS4TARInvoiceMB.TIoMPerQuantity, VS4TARInvoiceMB.TIoMUnitFactor, VS4TARInvoiceMB.TIoMAcceptError, VS4TARInvoiceMB.TIoMUnitCalc, VS4TARInvoiceMB.TIoMQuantityCalc, VS4TARInvoiceMB.TIoMQuantityText, VS4TARInvoiceMB.TIoMQuantity, VS4TARInvoiceMB.TIoMTUntCode, VS4TARInvoiceMB.TIoMQuantity2, VS4TARInvoiceMB.TIoMTUntCode2, VS4TARInvoiceMB.TIoMQuantity3, VS4TARInvoiceMB.TIoMTUntCode3, VS4TARInvoiceMB.TIoMCostAmount, VS4TARInvoiceMB.TIoMAmount, VS4TARInvoiceMB.TIoMDiscountText, VS4TARInvoiceMB.TIoMDiscountTotal, VS4TARInvoiceMB.TIoMNetAmount, VS4TARInvoiceMB.TIoMTaxType, VS4TARInvoiceMB.TIoMTaxBase, VS4TARInvoiceMB.TIoMWTAXBase, VS4TARInvoiceMB.TIoMAmountVAT, VS4TARInvoiceMB.TIoMAmountWTAX, VS4TARInvoiceMB.TIoMPromotionType, VS4TARInvoiceMB.TIoMFreeCode, VS4TARInvoiceMB.TIoMIsPremium, VS4TARInvoiceMB.TIoMDescription, VS4TARInvoiceMB.TIoMSourceNo, VS4TARInvoiceMB.TIoMSourceLn, VS4TARInvoiceMB.TIoMSourceDate, VS4TARInvoiceMB.TIoMTLctCode, VS4TARInvoiceMB.TIoMCommissionBase, VS4TARInvoiceMB.TIoMCommissionRate, VS4TARInvoiceMB.TIoMCommission, VS4TARInvoiceMB.TIoMPremiumCost, VS4TARInvoiceMB.TIoMQuantityStock, VS4TARInvoiceMB.TIoMAVGWeighting, VS4TARInvoiceMB.TIoMDiscountBill, VS4TARInvoiceMB.TIoMDeposit, VS4TARInvoiceMB.TIoMTARWCode, VS4TCountry.TCouName, VS4TAR.TARNAddressBill, VS4TAR.TARNName, VS4TAR2.TAR2TPrvCode, VS4TProvince.TPrvName, VS4TARGroup.TARGName, VS4TSaleArea.TSAeName, VS4TSaleZone.TSZnName, VS4TAR.TARNTARGCode, VS4TBranch.TBraName, VS4TProduct.TPdtName, VS4TProduct.TPdtDescription, VS4TProduct.TPdtName2, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtTPSECode, VS4TProduct.TPdtTPG1Code, VS4TProduct.TPdtStandardCost, VS4TProduct.TPdtTPS2Code, VS4TProduct.TPdtTPG2Code, VS4TAR2.TAR2Marks, VS4TProductSection.TPSEName, VS4TProduct.TPdtTAPNCode, VS4TProduct.TPdtCustom1, VS4TProduct.TPdtCustom2, VS4TBranch.TBraAddressBill, VS4TProduct.TPdtTPTTCode, VS4TShipping.TSHPName, VS4TAR.TARNPhone, VS4TARHolder.TARHName, VS4TProduct.TPdtFactoryCode, VS4TProduct.TPdtTUntCode, VS4TAR.TARNName2, VS4TAR.TARNAddressBill2, VS4TAR.TARNFax, VS4TProduct.TPdtAliasSlip, VS4TSOMB.TSOBSourceNo, VS4TARInvoice2.TIv2ShipDate, VS4TARInvoice2.TIv2Vessel, VS4TARInvoice2.TIv2IDC, VS4TARInvoice2.TIv2ILCNo, VS4TARInvoice2.TIv2BLNo, VS4TAR.TARNIECNo, VS4TProductGroup1.TPG1Name, VS4TProduct.TPdtCustom3, VS4TProduct.TPdtCustom4, VS4TProduct.TPdtCustom5, VS4TProduct.TPdtOldCode, VS4TARWelfare.TARWName, VS4TARInvoice.TIvoApproveStatus, VS4TAR2.TAR2Style, VS4TARInvoiceDep.TIRDDocNo 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) LEFT JOIN VS4TARHolder ON VS4TAR2.TAR2SaleCode = VS4TARHolder.TARHCode) ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) RIGHT JOIN (VS4TARInvoice2 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) LEFT JOIN VS4TDeliveryOut ON VS4TARInvoice.TIvoCustomNo = VS4TDeliveryOut.TDCONo) ON VS4TARInvoice2.TIv2TIvoNo = VS4TARInvoice.TIvoNo) 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) LEFT JOIN VS4TDeliveryOutMB ON (VS4TARInvoiceMB.TIoMLn = VS4TDeliveryOutMB.TDOMTIoMLn) AND (VS4TARInvoiceMB.TIoMTIvoNo = VS4TDeliveryOutMB.TDOMTIoMTIvoNo)) LEFT JOIN VS4TProduct3 ON VS4TProduct.TPdtCode = VS4TProduct3.TPD3TPdtCode) LEFT JOIN VS4TSOMB ON (VS4TARInvoiceMB.TIoMSourceLn = VS4TSOMB.TSOBLn) AND (VS4TARInvoiceMB.TIoMSourceNo = VS4TSOMB.TSOBTSODNo)) LEFT JOIN VS4TARWelfare ON VS4TARInvoiceMB.TIoMTARWCode = VS4TARWelfare.TARWCode) ON VS4TARInvoice.TIvoNo = VS4TARInvoiceMB.TIoMTIvoNo) ON VS4TSaleZone.TSZnCode = VS4TSaleArea.TSaeTSZnCode) LEFT JOIN VS4TARInvoiceDep ON VS4TARInvoice.TIvoNo = VS4TARInvoiceDep.TIRDTIvoNo WHERE (((VS4TARInvoiceDep.TIRDLn)=1 Or (VS4TARInvoiceDep.TIRDLn) Is Null))
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, VS4TAR.TARNTARGCode, VS4TAR.TARNTBsTCode, VS4TAR.TARNTSAeCode, VS4TBranch.TBraName, VS4TAR2.TAR2SaleCode, VS4TAR.TARNTextSort, VS4TAR2.TAR2Distance, VS4TShipping.TSHPName, VS4TEmployee.TEmpFullName, VS4TAR.TARNTaxNo 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) LEFT JOIN VS4TEmployee ON VS4TAR2.TAR2SaleCode = VS4TEmployee.TEmpCode) 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 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 ((VS4TCompanyBank RIGHT JOIN VS4TARInvoicePay ON VS4TCompanyBank.TCBBNo = VS4TARInvoicePay.TIPyTCBBNo) 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
GO

CREATE VIEW VS4VARInvoiceR AS  SELECT VS4TARInvoice.TIvoNo, VS4TARInvoice.TIvoBalanceFlag, VS4TARInvoice.TIvoType, VS4TARInvoice.TIvoTRBKCode, VS4TARInvoice.TIvoTRCACode, VS4TARInvoice.TIvoMode, VS4TARInvoice.TIvoDate, VS4TARInvoice.TIvoDueDate, VS4TARInvoice.TIvoGLMethod, VS4TARInvoice.TIvoTGLTNo, VS4TARInvoice.TIvoClientTaxNo, VS4TARInvoice.TIvoTaxNo, VS4TARInvoice.TIvoRefNo, VS4TARInvoice.TIvoRefDate, VS4TARInvoice.TIvoRefNo2, VS4TARInvoice.TIvoRefDate2, VS4TARInvoice.TIvoPONo, VS4TARInvoice.TIvoSOCode, VS4TARInvoice.TIvoJobCode, VS4TARInvoice.TIvoTJobNo, VS4TARInvoice.TIvoTJbMLn, VS4TARInvoice.TIvoTPrjCode, VS4TARInvoice.TIvoTBraCode, VS4TARInvoice.TIvoTEmpCode, VS4TARInvoice.TIvoSaleName, VS4TARInvoice.TIvoDeliveryDate, VS4TARInvoice.TIvoDeliveryTo, VS4TARInvoice.TIvoTARNCode, VS4TARInvoice.TIvoTARDCode, VS4TARInvoice.TIvoContactNote, VS4TARInvoice.TIvoContactName, VS4TARInvoice.TIvoCustomerName, VS4TARInvoice.TIvoCusAddress, VS4TARInvoice.TIvoCustomerName2, VS4TARInvoice.TIvoCusAddress2, VS4TARInvoice.TIvoConsignee, VS4TARInvoice.TIvoNotifyParty, VS4TARInvoice.TIvoCostTotal, VS4TARInvoice.TIvoPriceChannel, VS4TARInvoice.TIvoDiscountList, VS4TARInvoice.TIvoSubTotal, VS4TARInvoice.TIvoDiscountText, VS4TARInvoice.TIvoDiscountTotal, VS4TARInvoice.TIvoNetTotal, VS4TARInvoice.TIvoDepositText, VS4TARInvoice.TIvoDeposit, VS4TARInvoice.TIvoTotal, VS4TARInvoice.TIvoTotalFOB, VS4TARInvoice.TIvoTCurCode, VS4TARInvoice.TIvoExchangeRate, VS4TARInvoice.TIvoTotalInRate, VS4TARInvoice.TIvoVATType, VS4TARInvoice.TIvoVATRate, VS4TARInvoice.TIvoTaxBase, VS4TARInvoice.TIvoVATTotal, VS4TARInvoice.TIvoGrandTotal, VS4TARInvoice.TIvoNOTAXTotal, VS4TARInvoice.TIvoWTaxBase, VS4TARInvoice.TIvoWTaxRate, VS4TARInvoice.TIvoWTaxTotal, VS4TARInvoice.TIvoNetPayment, VS4TARInvoice.TIvoBaseArrears, VS4TARInvoice.TIvoArrears, VS4TARInvoice.TIvoAdjustTotal, VS4TARInvoice.TIvoBaseAvailable, VS4TARInvoice.TIvoAvailable, VS4TARInvoice.TIvoRewardTotal, VS4TARInvoice.TIvoPremiumTotal, VS4TARInvoice.TIvoCommissionBase, VS4TARInvoice.TIvoCommissionRate, VS4TARInvoice.TIvoCommission, VS4TARInvoice.TIvoBaseIncoType, VS4TARInvoice.TIvoIncoType, VS4TARInvoice.TIvoIncoTerms, VS4TARInvoice.TIvoOtherFee, VS4TARInvoice.TIvoTransportFee, VS4TARInvoice.TIvoHandlingFee, VS4TARInvoice.TIvoFreightFee, VS4TARInvoice.TIvoInsurance, VS4TARInvoice.TIvoTransportDesc, VS4TARInvoice.TIvoDuty, VS4TARInvoice.TIvoShipBy, VS4TARInvoice.TIvoCountryOrigin, VS4TARInvoice.TIvoDestination, VS4TARInvoice.TIvoCondition, VS4TARInvoice.TIvoConditionDay, VS4TARInvoice.TIvoCondition1, VS4TARInvoice.TIvoConditionDay1, VS4TARInvoice.TIvoPaymentNote, VS4TARInvoice.TIvoStatementNote, VS4TARInvoice.TIvoTShpCode, VS4TARInvoice.TIvoDeliveryNote, VS4TARInvoice.TIvoPackingNote, VS4TARInvoice.TIvoCustom1, VS4TARInvoice.TIvoCustom2, VS4TARInvoice.TIvoCustom3, VS4TARInvoice.TIvoCustom4, VS4TARInvoice.TIvoCustom5, VS4TARInvoice.TIvoCartonName, VS4TARInvoice.TIvoTotalCarton, VS4TARInvoice.TIvoTotalNW, VS4TARInvoice.TIvoTotalGW, VS4TARInvoice.TIvoDayAvailable, VS4TARInvoice.TIvoDescription, VS4TARInvoice.TIvoTSOTCode, VS4TARInvoice.TIvoDeliveryStatus, VS4TARInvoice.TIvoBillStatus, VS4TARInvoice.TIvoCardFlag, VS4TARInvoice.TIvoTaxFlag, VS4TARInvoice.TIvoEditCode, VS4TARInvoice.TIvoEditBy, VS4TARInvoice.TIvoEditDate, VS4TARInvoice.TIvoConfirmStatus, VS4TARInvoice.TIvoConfirmDate, VS4TARInvoice.TIvoApproveStatus, VS4TARInvoice.TIvoApproveBy, VS4TARInvoice.TIvoApproveDate, VS4TARInvoice.TIvoRevision, VS4TARInvoice.TIvoCancelStatus, VS4TARInvoice.TIvoCancelBy, VS4TARInvoice.TIvoCancelDate, VS4TARInvoice.TIvoFlag1, VS4TARInvoice.TIvoTRouCode, VS4TARInvoice.TIvoCustomNo, VS4TARInvoice.TIvoCustomDate, VS4TARInvoice.TIvoPMCostTotal, VS4TARInvoice.TIvoTOTNLn, VS4TARInvoice.TIvoDeliveryCond, VS4TARInvoice.TIvoLoadingDate, VS4TARInvoice.TIvoStartAgingDate, VS4TARInvoice.TIvoIgnoreArrears, VS4TARInvoice.TIvoBoxList, VS4TARInvoice.TIvoExchangeRate2, VS4TARInvoice.TIvoNote, VS4TARInvoice.TIvoTotalQuantity, VS4TARInvoice.TIvoTPOSCode, VS4TARInvoice.TIvoReceiptStatus, VS4TARInvoice.TIvoManualArrear, VS4TARInvoice.TIvoCardStatus, VS4TARInvoice.TIvoRefNo3, VS4TARInvoice.TIvoTARWCode, VS4TARInvoiceMB.TIoMTIvoNo, VS4TARInvoiceMB.TIoMLn, VS4TARInvoiceMB.TIoMType, VS4TARInvoiceMB.TIoMGroupName, VS4TARInvoiceMB.TIoMJobCode, VS4TARInvoiceMB.TIoMTOInCode, VS4TARInvoiceMB.TIoMTPOSCode, VS4TARInvoiceMB.TIoMSerialNo, VS4TARInvoiceMB.TIoMCustom1, VS4TARInvoiceMB.TIoMCustom2, VS4TARInvoiceMB.TIoMCustom3, VS4TARInvoiceMB.TIoMCustom4, VS4TARInvoiceMB.TIoMCustom5, VS4TARInvoiceMB.TIoMShippingMark, VS4TARInvoiceMB.TIoMPOSCode, VS4TARInvoiceMB.TIoMFactoryCode, VS4TARInvoiceMB.TIoMPOSName, VS4TARInvoiceMB.TIoMCost, VS4TARInvoiceMB.TIoMPrice, VS4TARInvoiceMB.TIoMPerQuantity, VS4TARInvoiceMB.TIoMUnitFactor, VS4TARInvoiceMB.TIoMAcceptError, VS4TARInvoiceMB.TIoMUnitCalc, VS4TARInvoiceMB.TIoMQuantityCalc, VS4TARInvoiceMB.TIoMQuantityText, VS4TARInvoiceMB.TIoMQuantity, VS4TARInvoiceMB.TIoMTUntCode, VS4TARInvoiceMB.TIoMQuantity2, VS4TARInvoiceMB.TIoMTUntCode2, VS4TARInvoiceMB.TIoMQuantity3, VS4TARInvoiceMB.TIoMTUntCode3, VS4TARInvoiceMB.TIoMCostAmount, VS4TARInvoiceMB.TIoMAmount, VS4TARInvoiceMB.TIoMDiscountText, VS4TARInvoiceMB.TIoMDiscountTotal, VS4TARInvoiceMB.TIoMNetAmount, VS4TARInvoiceMB.TIoMTaxType, VS4TARInvoiceMB.TIoMTaxBase, VS4TARInvoiceMB.TIoMWTAXBase, VS4TARInvoiceMB.TIoMAmountVAT, VS4TARInvoiceMB.TIoMAmountWTAX, VS4TARInvoiceMB.TIoMPromotionType, VS4TARInvoiceMB.TIoMFreeCode, VS4TARInvoiceMB.TIoMIsPremium, VS4TARInvoiceMB.TIoMDescription, VS4TARInvoiceMB.TIoMSourceNo, VS4TARInvoiceMB.TIoMSourceLn, VS4TARInvoiceMB.TIoMSourceDate, VS4TARInvoiceMB.TIoMTLctCode, VS4TARInvoiceMB.TIoMCommissionBase, VS4TARInvoiceMB.TIoMCommissionRate, VS4TARInvoiceMB.TIoMCommission, VS4TARInvoiceMB.TIoMPremiumCost, VS4TARInvoiceMB.TIoMQuantityStock, VS4TARInvoiceMB.TIoMAVGWeighting, VS4TARInvoiceMB.TIoMDiscountBill, VS4TARInvoiceMB.TIoMDeposit, VS4TARInvoiceMB.TIoMTARWCode, VS4TCountry.TCouName, VS4TAR.TARNAddressBill, VS4TAR.TARNName, VS4TAR2.TAR2TPrvCode, VS4TAR2.TAR2TBSMCode, VS4TProvince.TPrvName, VS4TARGroup.TARGName, VS4TSaleArea.TSAeName, VS4TSaleZone.TSZnName, VS4TAR.TARNTARGCode, VS4TAR.TARNTBsTCode, VS4TAR.TARNTSAeCode, VS4TBranch.TBraName, VS4TAR2.TAR2SaleCode, VS4TProduct.TPdtName, VS4TProduct.TPdtDescription, VS4TProduct.TPdtName2, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtTPSECode, VS4TProduct.TPdtTPG1Code, VS4TProduct.TPdtStandardCost, VS4TProduct.TPdtTPS2Code, VS4TProductSec2.TPS2Name, VS4TProductGroup1.TPG1Name, VS4TProduct.TPdtTPG2Code, VS4TAR2.TAR2Marks, VS4TProductSection.TPSEName, VS4TProduct.TPdtTAPNCode, VS4TProduct.TPdtCustom1, VS4TProduct.TPdtCustom2, VS4TProduct.TPdtCustom3, VS4TProduct.TPdtCustom4, VS4TProduct.TPdtCustom5, VS4TBranch.TBraAddressBill, VS4TProduct.TPdtTPTTCode, VS4TShipping.TSHPName, VS4TAR.TARNPhone, VS4TARHolder.TARHName, VS4TProduct.TPdtFactoryCode, VS4TProduct.TPdtTUntCode, VS4TAR.TARNName2, VS4TAR.TARNAddressBill2, VS4TAR.TARNFax, VS4TProduct.TPdtAliasSlip, VS4TProduct.TPdtOldCode, VS4TSOMB.TSOBSourceNo, VS4TARWelfare.TARWName, VS4TARInvoiceMB.TIoMTRCACode, VS4TSaleZone.TSZnTSZGCode, VS4TAR.TARNTCouCode, VS4TARInvoiceMB.TIoMWelfareAmount, VS4TProduct.TPdtGroupReport, VS4TAccountDay.TDayMonth, VS4TAccountDay.TDayQuarter, VS4TAccountDay.TDayYear, VS4TAccountDay.TDayPeriod 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) LEFT JOIN VS4TARHolder ON VS4TAR2.TAR2SaleCode = VS4TARHolder.TARHCode) 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) LEFT JOIN VS4TDeliveryOut ON VS4TARInvoice.TIvoCustomNo = VS4TDeliveryOut.TDCONo) LEFT JOIN VS4TAccountDay ON VS4TARInvoice.TIvoDate = VS4TAccountDay.TDayDate) 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) LEFT JOIN VS4TDeliveryOutMB ON (VS4TARInvoiceMB.TIoMTIvoNo = VS4TDeliveryOutMB.TDOMTIoMTIvoNo) AND (VS4TARInvoiceMB.TIoMLn = VS4TDeliveryOutMB.TDOMTIoMLn)) LEFT JOIN VS4TProduct3 ON VS4TProduct.TPdtCode = VS4TProduct3.TPD3TPdtCode) LEFT JOIN VS4TSOMB ON (VS4TARInvoiceMB.TIoMSourceNo = VS4TSOMB.TSOBTSODNo) AND (VS4TARInvoiceMB.TIoMSourceLn = VS4TSOMB.TSOBLn)) LEFT JOIN VS4TARWelfare ON VS4TARInvoiceMB.TIoMTARWCode = VS4TARWelfare.TARWCode) ON VS4TARInvoice.TIvoNo = VS4TARInvoiceMB.TIoMTIvoNo) ON VS4TSaleZone.TSZnCode = VS4TSaleArea.TSaeTSZnCode
GO

CREATE VIEW VS4VARInvoiceRS AS  SELECT VS4TARInvoice.TIvoNo, VS4TARInvoice.TIvoBalanceFlag, VS4TARInvoice.TIvoType, VS4TARInvoice.TIvoTRBKCode, VS4TARInvoice.TIvoTRCACode, VS4TARInvoice.TIvoMode, VS4TARInvoice.TIvoDate, VS4TARInvoice.TIvoDueDate, VS4TARInvoice.TIvoGLMethod, VS4TARInvoice.TIvoTGLTNo, VS4TARInvoice.TIvoClientTaxNo, VS4TARInvoice.TIvoTaxNo, VS4TARInvoice.TIvoRefNo, VS4TARInvoice.TIvoRefDate, VS4TARInvoice.TIvoRefNo2, VS4TARInvoice.TIvoRefDate2, VS4TARInvoice.TIvoPONo, VS4TARInvoice.TIvoSOCode, VS4TARInvoice.TIvoJobCode, VS4TARInvoice.TIvoTJobNo, VS4TARInvoice.TIvoTJbMLn, VS4TARInvoice.TIvoTPrjCode, VS4TARInvoice.TIvoTBraCode, VS4TARInvoice.TIvoTEmpCode, VS4TARInvoice.TIvoSaleName, VS4TARInvoice.TIvoDeliveryDate, VS4TARInvoice.TIvoDeliveryTo, VS4TARInvoice.TIvoTARNCode, VS4TARInvoice.TIvoTARDCode, VS4TARInvoice.TIvoContactNote, VS4TARInvoice.TIvoContactName, VS4TARInvoice.TIvoCustomerName, VS4TARInvoice.TIvoCusAddress, VS4TARInvoice.TIvoCustomerName2, VS4TARInvoice.TIvoCusAddress2, VS4TARInvoice.TIvoConsignee, VS4TARInvoice.TIvoNotifyParty, VS4TARInvoice.TIvoCostTotal, VS4TARInvoice.TIvoPriceChannel, VS4TARInvoice.TIvoDiscountList, VS4TARInvoice.TIvoSubTotal, VS4TARInvoice.TIvoDiscountText, VS4TARInvoice.TIvoDiscountTotal, VS4TARInvoice.TIvoNetTotal, VS4TARInvoice.TIvoDepositText, VS4TARInvoice.TIvoDeposit, VS4TARInvoice.TIvoTotal, VS4TARInvoice.TIvoTotalFOB, VS4TARInvoice.TIvoTCurCode, VS4TARInvoice.TIvoExchangeRate, VS4TARInvoice.TIvoTotalInRate, VS4TARInvoice.TIvoVATType, VS4TARInvoice.TIvoVATRate, VS4TARInvoice.TIvoTaxBase, VS4TARInvoice.TIvoVATTotal, VS4TARInvoice.TIvoGrandTotal, VS4TARInvoice.TIvoNOTAXTotal, VS4TARInvoice.TIvoWTaxBase, VS4TARInvoice.TIvoWTaxRate, VS4TARInvoice.TIvoWTaxTotal, VS4TARInvoice.TIvoNetPayment, VS4TARInvoice.TIvoBaseArrears, VS4TARInvoice.TIvoArrears, VS4TARInvoice.TIvoAdjustTotal, VS4TARInvoice.TIvoBaseAvailable, VS4TARInvoice.TIvoAvailable, VS4TARInvoice.TIvoRewardTotal, VS4TARInvoice.TIvoPremiumTotal, VS4TARInvoice.TIvoCommissionBase, VS4TARInvoice.TIvoCommissionRate, VS4TARInvoice.TIvoCommission, VS4TARInvoice.TIvoBaseIncoType, VS4TARInvoice.TIvoIncoType, VS4TARInvoice.TIvoIncoTerms, VS4TARInvoice.TIvoOtherFee, VS4TARInvoice.TIvoTransportFee, VS4TARInvoice.TIvoHandlingFee, VS4TARInvoice.TIvoFreightFee, VS4TARInvoice.TIvoInsurance, VS4TARInvoice.TIvoTransportDesc, VS4TARInvoice.TIvoDuty, VS4TARInvoice.TIvoShipBy, VS4TARInvoice.TIvoCountryOrigin, VS4TARInvoice.TIvoDestination, VS4TARInvoice.TIvoCondition, VS4TARInvoice.TIvoConditionDay, VS4TARInvoice.TIvoCondition1, VS4TARInvoice.TIvoConditionDay1, VS4TARInvoice.TIvoPaymentNote, VS4TARInvoice.TIvoStatementNote, VS4TARInvoice.TIvoTShpCode, VS4TARInvoice.TIvoDeliveryNote, VS4TARInvoice.TIvoPackingNote, VS4TARInvoice.TIvoCustom1, VS4TARInvoice.TIvoCustom2, VS4TARInvoice.TIvoCustom3, VS4TARInvoice.TIvoCustom4, VS4TARInvoice.TIvoCustom5, VS4TARInvoice.TIvoCustom6, VS4TARInvoice.TIvoCartonName, VS4TARInvoice.TIvoTotalCarton, VS4TARInvoice.TIvoTotalNW, VS4TARInvoice.TIvoTotalGW, VS4TARInvoice.TIvoTotalVolumeM, VS4TARInvoice.TIvoDayAvailable, VS4TARInvoice.TIvoDescription, VS4TARInvoice.TIvoTSOTCode, VS4TARInvoice.TIvoDeliveryStatus, VS4TARInvoice.TIvoBillStatus, VS4TARInvoice.TIvoCardFlag, VS4TARInvoice.TIvoTaxFlag, VS4TARInvoice.TIvoCreateBy, VS4TARInvoice.TIvoEditCode, VS4TARInvoice.TIvoEditBy, VS4TARInvoice.TIvoEditDate, VS4TARInvoice.TIvoConfirmBy, VS4TARInvoice.TIvoApproveBy, VS4TARInvoice.TIvoRevision, VS4TARInvoice.TIvoCancelStatus, VS4TARInvoice.TIvoCancelBy, VS4TARInvoice.TIvoCancelDate, VS4TARInvoice.TIvoCancelNote, VS4TARInvoice.TIvoTRouCode, VS4TARInvoice.TIvoCustomNo, VS4TARInvoice.TIvoCustomDate, VS4TARInvoice.TIvoPMCostTotal, VS4TARInvoice.TIvoTOTNLn, VS4TARInvoice.TIvoDeliveryCond, VS4TARInvoice.TIvoLoadingDate, VS4TARInvoice.TIvoStartAgingDate, VS4TARInvoice.TIvoIgnoreArrears, VS4TARInvoice.TIvoBoxList, VS4TARInvoice.TIvoExchangeRate2, VS4TARInvoice.TIvoNote, VS4TARInvoice.TIvoTotalQuantity, VS4TARInvoice.TIvoTPOSCode, VS4TARInvoice.TIvoReceiptStatus, VS4TARInvoice.TIvoManualArrear, VS4TARInvoice.TIvoCardStatus, VS4TARInvoice.TIvoRefNo3, VS4TARInvoice.TIvoTARWCode, VS4TARInvoiceMB.TIoMTIvoNo, VS4TARInvoiceMB.TIoMLn, VS4TARInvoiceMB.TIoMType, VS4TARInvoiceMB.TIoMGroupName, VS4TARInvoiceMB.TIoMJobCode, VS4TARInvoiceMB.TIoMTOInCode, VS4TARInvoiceMB.TIoMTPOSCode, VS4TARInvoiceMB.TIoMSerialNo, VS4TARInvoiceMB.TIoMCustom1, VS4TARInvoiceMB.TIoMCustom2, VS4TARInvoiceMB.TIoMCustom3, VS4TARInvoiceMB.TIoMCustom4, VS4TARInvoiceMB.TIoMCustom5, VS4TARInvoiceMB.TIoMShippingMark, VS4TARInvoiceMB.TIoMPOSCode, VS4TARInvoiceMB.TIoMFactoryCode, VS4TARInvoiceMB.TIoMPOSName, VS4TARInvoiceMB.TIoMCost, VS4TARInvoiceMB.TIoMPrice, VS4TARInvoiceMB.TIoMPerQuantity, VS4TARInvoiceMB.TIoMUnitFactor, VS4TARInvoiceMB.TIoMAcceptError, VS4TARInvoiceMB.TIoMUnitCalc, VS4TARInvoiceMB.TIoMQuantityCalc, VS4TARInvoiceMB.TIoMQuantityText, VS4TARInvoiceMB.TIoMQuantity, VS4TARInvoiceMB.TIoMTUntCode, VS4TARInvoiceMB.TIoMQuantity2, VS4TARInvoiceMB.TIoMTUntCode2, VS4TARInvoiceMB.TIoMQuantity3, VS4TARInvoiceMB.TIoMTUntCode3, VS4TARInvoiceMB.TIoMCostAmount, VS4TARInvoiceMB.TIoMAmount, VS4TARInvoiceMB.TIoMDiscountText, VS4TARInvoiceMB.TIoMDiscountTotal, VS4TARInvoiceMB.TIoMNetAmount, VS4TARInvoiceMB.TIoMTaxType, VS4TARInvoiceMB.TIoMTaxBase, VS4TARInvoiceMB.TIoMWTAXBase, VS4TARInvoiceMB.TIoMAmountVAT, VS4TARInvoiceMB.TIoMAmountWTAX, VS4TARInvoiceMB.TIoMPromotionType, VS4TARInvoiceMB.TIoMFreeCode, VS4TARInvoiceMB.TIoMIsPremium, VS4TARInvoiceMB.TIoMDescription, VS4TARInvoiceMB.TIoMSourceNo, VS4TARInvoiceMB.TIoMSourceLn, VS4TARInvoiceMB.TIoMSourceDate, VS4TARInvoiceMB.TIoMTLctCode, VS4TARInvoiceMB.TIoMCommissionBase, VS4TARInvoiceMB.TIoMCommissionRate, VS4TARInvoiceMB.TIoMCommission, VS4TARInvoiceMB.TIoMPremiumCost, VS4TARInvoiceMB.TIoMQuantityStock, VS4TARInvoiceMB.TIoMAVGWeighting, VS4TARInvoiceMB.TIoMDiscountBill, VS4TARInvoiceMB.TIoMDeposit, VS4TARInvoiceMB.TIoMTARWCode, VS4TCountry.TCouName, VS4TAR.TARNName, VS4TAR2.TAR2TPrvCode, VS4TARGroup.TARGName, VS4TSaleArea.TSAeName, VS4TAR.TARNTARGCode, VS4TAR.TARNTSAeCode, VS4TBranch.TBraName, VS4TAR2.TAR2SaleCode, VS4TProduct.TPdtName, VS4TProduct.TPdtDescription, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtTPSECode, VS4TProduct.TPdtTPS2Code, VS4TProduct.TPdtTPG2Code, VS4TProductSection.TPSEName, VS4TProduct.TPdtTAPNCode, VS4TBranch.TBraAddressBill, VS4TProduct.TPdtStartDate, VS4TProduct.TPdtEndDate, 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.TPBGToTCouCode2, VS4TProductBook.TPBGToPort2, VS4TProductBook.TPBGArrDate2, VS4TProductBook.TPBGArrTime2, VS4TProduct.TPdtTPTTCode, VS4TPOSSaleGroup.TPSGName, VS4TPOS.TPOSTPSGCode, VS4TAR.TARNPhone, VS4TAR.TARNFax, VS4TAR.TARNMobile, VS4TARWelfare.TARWName, VS4TAR.TARNTaxNo, VS4TARBranch.TARDName, VS4TARInvoice.TIvoBranchCode, VS4TARInvoice.TIvoBranchName, VS4TARInvoiceDep.TIRDDocNo, VS4TARInvoice.TIvoApproveStatus 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) LEFT JOIN VS4TARBranch ON (VS4TARInvoice.TIvoTARNCode = VS4TARBranch.TARDTARNCode) AND (VS4TARInvoice.TIvoTARDCode = VS4TARBranch.TARDCode)) LEFT JOIN VS4TARInvoiceDep ON VS4TARInvoice.TIvoNo = VS4TARInvoiceDep.TIRDTIvoNo) 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) LEFT JOIN VS4TProductBook ON VS4TProduct.TPdtCode = VS4TProductBook.TPBGTPdtCode) LEFT JOIN VS4TPOSSaleGroup ON VS4TPOS.TPOSTPSGCode = VS4TPOSSaleGroup.TPSGCode) LEFT JOIN VS4TARWelfare ON VS4TARInvoiceMB.TIoMTARWCode = VS4TARWelfare.TARWCode) ON VS4TARInvoice.TIvoNo = VS4TARInvoiceMB.TIoMTIvoNo) ON VS4TSaleZone.TSZnCode = VS4TSaleArea.TSaeTSZnCode WHERE (((VS4TARInvoiceDep.TIRDLn)=1 Or (VS4TARInvoiceDep.TIRDLn) Is Null))
GO

CREATE VIEW VS4VARInvoiceRS2 AS  SELECT VS4TARVoucher.TRVHNo, VS4TARVoucher.TRVHDate, VS4TARInvoice.TIvoNo, VS4TARInvoice.TIvoDate, VS4TARInvoice.TIvoType, VS4TARInvoice.TIvoTARNCode, VS4TAR.TARNName, VS4TAR.TARNName2, VS4TAR.TARNAddressBill, VS4TAR.TARNAddressBill2, VS4TAR.TARNAddressDeliver, VS4TAR.TARNAddress, VS4TAR.TARNAddress2, VS4TAR.TARNEmail, VS4TAR.TARNPhone, VS4TAR.TARNFax, VS4TAR.TARNMobile, VS4TARInvoice.TIvoNetTotal, VS4TARInvoice.TIvoVATType, VS4TARInvoice.TIvoTaxBase, VS4TARInvoice.TIvoTotalInRate, VS4TARInvoice.TIvoArrears, VS4TARInvoiceMB.TIoMTPOSCode, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtTPDLCode, VS4TProductLine.TPdLName, VS4TProductLine.TPdLName2, VS4TPOS.TPOSTPSGCode, VS4TPOSSaleGroup.TPSGName, VS4TPOSSaleGroup.TPSGName2, VS4TProduct.TPdtStartDate, VS4TProduct.TPdtEndDate, VS4TSOPassenger.TVSPTARNCode, VS4TAR_1.TARNName AS PassengerName, VS4TARInvoice.TIvoApproveStatus FROM ((VS4TAR INNER JOIN VS4TARVoucher ON VS4TAR.TARNCode = VS4TARVoucher.TRVHTARNCode) INNER JOIN (VS4TProductLine RIGHT JOIN (((VS4TARVDocRef INNER JOIN VS4TARInvoice ON VS4TARVDocRef.TRDRRefDocNo = VS4TARInvoice.TIvoNo) LEFT JOIN VS4TSO ON VS4TARInvoice.TIvoRefNo = VS4TSO.TSODNo) INNER JOIN (((VS4TARInvoiceMB LEFT JOIN VS4TPOS ON VS4TARInvoiceMB.TIoMTPOSCode = VS4TPOS.TPOSCode) LEFT JOIN VS4TProduct ON VS4TPOS.TPOSCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TPOSSaleGroup ON VS4TPOS.TPOSTPSGCode = VS4TPOSSaleGroup.TPSGCode) ON VS4TARInvoice.TIvoNo = VS4TARInvoiceMB.TIoMTIvoNo) ON VS4TProductLine.TPdLCode = VS4TProduct.TPdtTPDLCode) ON VS4TARVoucher.TRVHNo = VS4TARVDocRef.TRDRTRVHNo) LEFT JOIN ((VS4TSOMB LEFT JOIN VS4TSOPassenger ON (VS4TSOMB.TSOBTPOSCode = VS4TSOPassenger.TVSPTPdtCode) AND (VS4TSOMB.TSOBTSODNo = VS4TSOPassenger.TVSPTSODNo)) LEFT JOIN VS4TAR AS VS4TAR_1 ON VS4TSOPassenger.TVSPTARNCode = VS4TAR_1.TARNCode) ON VS4TSO.TSODNo = VS4TSOMB.TSOBTSODNo WHERE (((VS4TARInvoice.TIvoType) In (5,7,9,20,30)) AND ((VS4TARInvoiceMB.TIoMLn)=1) AND ((VS4TARInvoice.TIvoApproveStatus)=1) AND ((VS4TARInvoice.TIvoCancelStatus)=0) AND ((VS4TARVoucher.TRVHType)=0) AND ((VS4TARVoucher.TRVHApproveStatus)=1) AND ((VS4TARVoucher.TRVHCancelStatus)=0) AND ((VS4TSOMB.TSOBLn)=1))
GO

CREATE VIEW VS4VARLog AS  SELECT VS4TARLog.*, VS4TAR.*, VS4TEmployee.TEmpFullName, VS4TEmployee.TEmpFullName2 FROM ((VS4TAR LEFT JOIN VS4TAR2 ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) LEFT JOIN VS4TAR3 ON VS4TAR.TARNCode = VS4TAR3.TAR3TARNCode) INNER JOIN (VS4TARLog LEFT JOIN VS4TEmployee ON VS4TARLog.TRLgTEmpCode = VS4TEmployee.TEmpCode) ON VS4TAR.TARNCode = VS4TARLog.TRLgTARNCode
GO

CREATE VIEW VS4VARMedia AS  SELECT VS4TAR.*, VS4TAR2.*, VS4TAR3.*, VS4TARMedia.TAMdTMedCode, VS4TARMedia.TAMdTARNCode, VS4TARMedia.TAMdLastContact, VS4TARGroup.TARGCode, VS4TARGroup.TARGName, VS4TARGroup.TARGName2 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.TAIHNo, VS4TARReceipt.TAIHDate, VS4TARReceipt.TAIHType, VS4TARReceipt.TAIHTGLBCode, VS4TARReceipt.TAIHTBraCode, VS4TARReceipt.TAIHTPrjCode,                           VS4TARReceipt.TAIHRefNo, VS4TARReceipt.TAIHRefDate, VS4TARReceipt.TAIHRefNo2, VS4TARReceipt.TAIHRefDate2, VS4TARReceipt.TAIHTARNCode, VS4TARReceipt.TAIHCustomerName,                           VS4TARReceipt.TAIHCusAddress, VS4TARReceipt.TAIHCostTotal, VS4TARReceipt.TAIHSubTotal, VS4TARReceipt.TAIHDiscountPC, VS4TARReceipt.TAIHDiscPCAmount, VS4TARReceipt.TAIHDiscountFix,                           VS4TARReceipt.TAIHDiscountTotal, VS4TARReceipt.TAIHNetTotal, VS4TARReceipt.TAIHDepositRate, VS4TARReceipt.TAIHDepPCAmount, VS4TARReceipt.TAIHDepositFix, VS4TARReceipt.TAIHDeposit,                           VS4TARReceipt.TAIHTotal, VS4TARReceipt.TAIHTCurCode, VS4TARReceipt.TAIHExchangeRate, VS4TARReceipt.TAIHTotalInRate, VS4TARReceipt.TAIHCommissionBase,                           VS4TARReceipt.TAIHCommissionRate, VS4TARReceipt.TAIHCommission, VS4TARReceipt.TAIHVATType, VS4TARReceipt.TAIHVATRate, VS4TARReceipt.TAIHTaxBase, VS4TARReceipt.TAIHVATTotal,                           VS4TARReceipt.TAIHGrandTotal, VS4TARReceipt.TAIHNetPayment, VS4TARReceipt.TAIHArrears, VS4TARReceipt.TAIHDescription, VS4TARReceipt.TAIHStatus, VS4TARReceipt.TAIHWTaxRate,                           VS4TARReceipt.TAIHDiscount, VS4TARReceipt.TAIHWTaxTotal, VS4TARReceipt.TAIHCreateCode, VS4TARReceipt.TAIHCreateBy, VS4TARReceipt.TAIHCreateDate, VS4TARReceipt.TAIHEditCode,                           VS4TARReceipt.TAIHEditBy, VS4TARReceipt.TAIHEditDate, VS4TARReceipt.TAIHConfirmStatus, VS4TARReceipt.TAIHConfirmBy, VS4TARReceipt.TAIHConfirmDate, VS4TARReceipt.TAIHApproveStatus,                           VS4TARReceipt.TAIHApproveBy, VS4TARReceipt.TAIHApproveDate, VS4TARReceipt.TAIHApproveNote, VS4TARReceipt.TAIHRevision, VS4TARReceipt.TAIHCancelStatus, VS4TARReceipt.TAIHCancelNo,                           VS4TARReceipt.TAIHCancelBy, VS4TARReceipt.TAIHCancelDate, VS4TARReceipt.TAIHCancelNote, VS4TARReceipt.TAIHFlag1, VS4TARReceipt.TAIHFlag2, VS4TARReceipt.TAIHFlag3,                           VS4TARReceipt.TAIHMode, VS4TARReceipt.TAIHTARDCode, VS4TARReceipt.TAIHClientTaxNo, VS4TARReceipt.TAIHBranchCode, VS4TARReceipt.TAIHBranchName, VS4TARReceiptMB.TREMTAIHNo,                           VS4TARReceiptMB.TREMLn, VS4TARReceiptMB.TREMType, VS4TARReceiptMB.TREMRefBillNo, VS4TARReceiptMB.TREMRefDocNo, VS4TARReceiptMB.TREMRefDocDate,                           VS4TARReceiptMB.TREMRefNo, VS4TARReceiptMB.TREMRefNo2, VS4TARReceiptMB.TREMRefNo3, VS4TARReceiptMB.TREMRefDocAmount, VS4TARReceiptMB.TREMRefDocType,                           VS4TARReceiptMB.TREMRefDueDate, VS4TARReceiptMB.TREMCurrency, VS4TARReceiptMB.TREMCurRate, VS4TARReceiptMB.TREMCurSubTotal, VS4TARReceiptMB.TREMDiscount,                           VS4TARReceiptMB.TREMCurDiscount, VS4TARReceiptMB.TREMCurAmount, VS4TARReceiptMB.TREMAmountRate, VS4TARReceiptMB.TREMTaxBase, VS4TARReceiptMB.TREMVATType,                           VS4TARReceiptMB.TREMVATRate, VS4TARReceiptMB.TREMVATTotal, VS4TARReceiptMB.TREMWTAXRate, VS4TARReceiptMB.TREMWTAXTotal, VS4TARReceiptMB.TREMWTAXCond,                           VS4TARReceiptMB.TREMWTAXDesc, VS4TARReceiptMB.TREMCommissionBase, VS4TARReceiptMB.TREMCommissionRate, VS4TARReceiptMB.TREMCommission, VS4TARReceiptMB.TREMInterestRate,                           VS4TARReceiptMB.TREMInterestTotal, VS4TARReceiptMB.TREMNote, VS4TARReceiptMB.TREMStatus, VS4TARReceiptMB.TREMFlag1, VS4TARReceiptMB.TREMFlag2, VS4TARReceiptMB.TREMFlag3,                           VS4TAR.TARNCode, VS4TAR.TARNTCmpCode, VS4TAR.TARNTARTCode, VS4TAR.TARNIntro, VS4TAR.TARNName, VS4TAR.TARNName2, VS4TAR.TARNIntroName, VS4TAR.TARNType,                           VS4TAR.TARNOwnerName, VS4TAR.TARNDocCode, VS4TAR.TARNContactName, VS4TAR.TARNTaxNo, VS4TAR.TARNAccountCode, 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.TARNCreditLimit,                           VS4TAR.TARNCreditUseBal, VS4TAR.TARNCreditUse, VS4TAR.TARNCreditBalance, VS4TAR.TARNCreditAvaiBal, VS4TAR.TARNTotalOrderBal, VS4TAR.TARNPriceChannel, VS4TAR.TARNDiscountPC,                           VS4TAR.TARNDiscountDay, VS4TAR.TARNCreditDay, VS4TAR.TARNLimitTCurCode, VS4TAR.TARNSpecialTaxRate, VS4TAR.TARNPaymentNote, VS4TAR.TARNStatementNote,                           VS4TAR.TARNDeliveryNote, VS4TAR.TARNMapFile, VS4TAR.TARNTimeToOrder, VS4TAR.TARNLastDueDate, VS4TAR.TARNFirstOrderDate, VS4TAR.TARNLastOrderDate, VS4TAR.TARNTARSAlias,                           VS4TAR.TARNTBsTCode, VS4TAR.TARNTSAeCode, VS4TAR.TARNNeedBill, VS4TAR.TARNBillDay1, VS4TAR.TARNBillDay2, VS4TAR.TARNBillDay3, VS4TAR.TARNBillDay4,                           VS4TAR.TARNBillMove, VS4TAR.TARNBillAdjust, VS4TAR.TARNNote, VS4TAR.TARNCreateCode, VS4TAR.TARNCreateDate, VS4TAR.TARNEditCode, VS4TAR.TARNEditDate,                           VS4TAR.TARNTextSort, VS4TAR.TARNFlag1, VS4TAR.TARNFlag2, VS4TAR.TARNFlag3, VS4TAR.TARNDiscount, VS4TAR.TARNAddressBill2, VS4TAR.TARNTBraCode, VS4TAR.TARNChequeDay,                           VS4TAR.TARNChequeAddMonth, VS4TAR.TARNRegisterDate, VS4TAR.TARNMode, VS4TAR.TARNIECNo, VS4TAR.TARNCardNo, VS4TAR.TARNLineId,                           VS4TAR.TARNMakerCode, VS4TAR.TARNTRG2Code, VS4TAR.TARNVirtualAccNo, VS4TAR.TARNTRG3Code, VS4TARInvoice.TIvoCustom1, VS4TARInvoice.TIvoCustom2, VS4TARInvoice.TIvoCustom3,                           VS4TARInvoice.TIvoCustom4, VS4TARInvoice.TIvoCustom5, VS4TBranch.TBraAddressBill, VS4TARInvoice.TIvoTEmpCode, VS4TARInvoice.TIvoSaleName, VS4TARInvoice.TIvoArrears,                           VS4TARInvoice.TIvoDiscountTotal, VS4TARInvoice.TIvoDeposit, VS4TARInvoice.TIvoCusAddress FROM            VS4TAR INNER JOIN                          VS4TARReceipt LEFT OUTER JOIN                          VS4TBranch ON VS4TARReceipt.TAIHTBraCode = VS4TBranch.TBraCode INNER JOIN                          VS4TARReceiptMB LEFT OUTER JOIN                          VS4TARInvoice ON VS4TARReceiptMB.TREMRefDocNo = VS4TARInvoice.TIvoNo ON VS4TARReceipt.TAIHNo = VS4TARReceiptMB.TREMTAIHNo ON                           VS4TAR.TARNCode = VS4TARReceipt.TAIHTARNCode
GO

CREATE VIEW VS4VARReceiptMB
AS
SELECT VS4TARReceipt.TAIHNo, VS4TARReceipt.TAIHDate, VS4TARReceipt.TAIHType, VS4TARReceipt.TAIHTGLBCode, VS4TARReceipt.TAIHTBraCode, VS4TARReceipt.TAIHTPrjCode, VS4TARReceipt.TAIHRefNo, 
                  VS4TARReceipt.TAIHRefDate, VS4TARReceipt.TAIHRefNo2, VS4TARReceipt.TAIHRefDate2, VS4TARReceipt.TAIHTARNCode, VS4TARReceipt.TAIHCustomerName, VS4TARReceipt.TAIHCusAddress, 
                  VS4TARReceipt.TAIHCostTotal, VS4TARReceipt.TAIHSubTotal, VS4TARReceipt.TAIHDiscountPC, VS4TARReceipt.TAIHDiscPCAmount, VS4TARReceipt.TAIHDiscountFix, VS4TARReceipt.TAIHDiscountTotal, 
                  VS4TARReceipt.TAIHNetTotal, VS4TARReceipt.TAIHDepositRate, VS4TARReceipt.TAIHDepPCAmount, VS4TARReceipt.TAIHDepositFix, VS4TARReceipt.TAIHDeposit, VS4TARReceipt.TAIHTotal, 
                  VS4TARReceipt.TAIHTCurCode, VS4TARReceipt.TAIHExchangeRate, VS4TARReceipt.TAIHTotalInRate, VS4TARReceipt.TAIHCommissionBase, VS4TARReceipt.TAIHCommissionRate, 
                  VS4TARReceipt.TAIHCommission, VS4TARReceipt.TAIHVATType, VS4TARReceipt.TAIHVATRate, VS4TARReceipt.TAIHTaxBase, VS4TARReceipt.TAIHVATTotal, VS4TARReceipt.TAIHGrandTotal, 
                  VS4TARReceipt.TAIHNetPayment, VS4TARReceipt.TAIHArrears, VS4TARReceipt.TAIHDescription, VS4TARReceipt.TAIHStatus, VS4TARReceipt.TAIHWTaxRate, VS4TARReceipt.TAIHDiscount, 
                  VS4TARReceipt.TAIHWTaxTotal, VS4TARReceipt.TAIHCreateCode, VS4TARReceipt.TAIHCreateBy, VS4TARReceipt.TAIHCreateDate, VS4TARReceipt.TAIHEditCode, VS4TARReceipt.TAIHEditBy, 
                  VS4TARReceipt.TAIHEditDate, VS4TARReceipt.TAIHConfirmStatus, VS4TARReceipt.TAIHConfirmBy, VS4TARReceipt.TAIHConfirmDate, VS4TARReceipt.TAIHApproveStatus, VS4TARReceipt.TAIHApproveBy, 
                  VS4TARReceipt.TAIHApproveDate, VS4TARReceipt.TAIHApproveNote, VS4TARReceipt.TAIHRevision, VS4TARReceipt.TAIHCancelStatus, VS4TARReceipt.TAIHCancelNo, VS4TARReceipt.TAIHCancelBy, 
                  VS4TARReceipt.TAIHCancelDate, VS4TARReceipt.TAIHCancelNote, VS4TARReceipt.TAIHFlag1, VS4TARReceipt.TAIHFlag2, VS4TARReceipt.TAIHFlag3, VS4TARReceipt.TAIHMode, 
                  VS4TARReceipt.TAIHTARDCode, VS4TARReceipt.TAIHClientTaxNo, VS4TARReceipt.TAIHBranchCode, VS4TARReceipt.TAIHBranchName, VS4TARReceiptMB.TREMTAIHNo, VS4TARReceiptMB.TREMLn, 
                  VS4TARReceiptMB.TREMType, VS4TARReceiptMB.TREMRefBillNo, VS4TARReceiptMB.TREMRefDocNo, VS4TARReceiptMB.TREMRefDocDate, VS4TARReceiptMB.TREMRefNo, VS4TARReceiptMB.TREMRefNo2, 
                  VS4TARReceiptMB.TREMRefNo3, VS4TARReceiptMB.TREMRefDocAmount, VS4TARReceiptMB.TREMRefDocType, VS4TARReceiptMB.TREMRefDueDate, VS4TARReceiptMB.TREMCurrency, 
                  VS4TARReceiptMB.TREMCurRate, VS4TARReceiptMB.TREMCurSubTotal, VS4TARReceiptMB.TREMDiscount, VS4TARReceiptMB.TREMCurDiscount, VS4TARReceiptMB.TREMCurAmount, 
                  VS4TARReceiptMB.TREMAmountRate, VS4TARReceiptMB.TREMTaxBase, VS4TARReceiptMB.TREMVATType, VS4TARReceiptMB.TREMVATRate, VS4TARReceiptMB.TREMVATTotal, 
                  VS4TARReceiptMB.TREMWTAXRate, VS4TARReceiptMB.TREMWTAXTotal, VS4TARReceiptMB.TREMWTAXCond, VS4TARReceiptMB.TREMWTAXDesc, VS4TARReceiptMB.TREMCommissionBase, 
                  VS4TARReceiptMB.TREMCommissionRate, VS4TARReceiptMB.TREMCommission, VS4TARReceiptMB.TREMInterestRate, VS4TARReceiptMB.TREMInterestTotal, VS4TARReceiptMB.TREMNote, 
                  VS4TARReceiptMB.TREMStatus, VS4TARReceiptMB.TREMFlag1, VS4TARReceiptMB.TREMFlag2, VS4TARReceiptMB.TREMFlag3, VS4TARInvoice.TIvoCustom1, VS4TARInvoice.TIvoCustom2, 
                  VS4TARInvoice.TIvoCustom3, VS4TARInvoice.TIvoCustom4, VS4TARInvoice.TIvoCustom5, VS4TBranch.TBraAddressBill, VS4TARInvoiceMB.TIoMTIvoNo, VS4TARInvoiceMB.TIoMLn, 
                  VS4TARInvoiceMB.TIoMType, VS4TARInvoiceMB.TIoMGroupName, VS4TARInvoiceMB.TIoMJobCode, VS4TARInvoiceMB.TIoMTOInCode, VS4TARInvoiceMB.TIoMTPOSCode, VS4TARInvoiceMB.TIoMSerialNo, 
                  VS4TARInvoiceMB.TIoMCustom1, VS4TARInvoiceMB.TIoMCustom2, VS4TARInvoiceMB.TIoMCustom3, VS4TARInvoiceMB.TIoMCustom4, VS4TARInvoiceMB.TIoMCustom5, VS4TARInvoiceMB.TIoMShippingMark, 
                  VS4TARInvoiceMB.TIoMPOSCode, VS4TARInvoiceMB.TIoMFactoryCode, VS4TARInvoiceMB.TIoMPOSName, VS4TARInvoiceMB.TIoMCost, VS4TARInvoiceMB.TIoMPrice, VS4TARInvoiceMB.TIoMPerQuantity, 
                  VS4TARInvoiceMB.TIoMUnitFactor, VS4TARInvoiceMB.TIoMAcceptError, VS4TARInvoiceMB.TIoMUnitCalc, VS4TARInvoiceMB.TIoMQuantityCalc, VS4TARInvoiceMB.TIoMQuantityText, 
                  VS4TARInvoiceMB.TIoMQuantity, VS4TARInvoiceMB.TIoMTUntCode, VS4TARInvoiceMB.TIoMQuantity2, VS4TARInvoiceMB.TIoMTUntCode2, VS4TARInvoiceMB.TIoMQuantity3, VS4TARInvoiceMB.TIoMTUntCode3, 
                  VS4TARInvoiceMB.TIoMCostAmount, VS4TARInvoiceMB.TIoMAmount, VS4TARInvoiceMB.TIoMDiscountText, VS4TARInvoiceMB.TIoMDiscountTotal, VS4TARInvoiceMB.TIoMNetAmount, 
                  VS4TARInvoiceMB.TIoMTaxType, VS4TARInvoiceMB.TIoMTaxBase, VS4TARInvoiceMB.TIoMWTAXBase, VS4TARInvoiceMB.TIoMAmountVAT, VS4TARInvoiceMB.TIoMAmountWTAX, 
                  VS4TARInvoiceMB.TIoMPromotionType, VS4TARInvoiceMB.TIoMFreeCode, VS4TARInvoiceMB.TIoMIsPremium, VS4TARInvoiceMB.TIoMDescription, VS4TARInvoiceMB.TIoMSourceNo, 
                  VS4TARInvoiceMB.TIoMSourceLn, VS4TARInvoiceMB.TIoMSourceDate, VS4TARInvoiceMB.TIoMTWahCode, VS4TARInvoiceMB.TIoMTLctCode, VS4TARInvoiceMB.TIoMCommissionBase, 
                  VS4TARInvoiceMB.TIoMCommissionRate, VS4TARInvoiceMB.TIoMCommission, VS4TARInvoiceMB.TIoMFlag1, VS4TARInvoiceMB.TIoMFlag2, VS4TARInvoiceMB.TIoMFlag3, VS4TARInvoiceMB.TIoMPremiumCost, 
                  VS4TARInvoiceMB.TIoMQuantityStock, VS4TARInvoiceMB.TIoMAVGWeighting, VS4TARInvoiceMB.TIoMDiscountBill, VS4TARInvoiceMB.TIoMDeposit, VS4TARInvoiceMB.TIoMTARWCode, 
                  VS4TARInvoiceMB.TIoMTRCACode, VS4TARInvoiceMB.TIoMStockFlag, VS4TARInvoiceMB.TIoMMinimumOrder, VS4TARInvoiceMB.TIoMWelfareRate, VS4TARInvoiceMB.TIoMControlQty, 
                  VS4TARInvoiceMB.TIoMWelfareAmount, VS4TARInvoiceMB.TIoMTPltCode, VS4TARInvoiceMB.TIoMTotalCN, VS4TARInvoiceMB.TIoMTotalCNArr, VS4TARInvoiceMB.TIoMQuantityPallet, 
                  VS4TARInvoiceMB.TIoMPOSName2, VS4TARInvoiceMB.TIoMQuantityBase, VS4TARInvoiceMB.TIoMPickingNo, VS4TARInvoiceMB.TIoMNAmountInRate, VS4TARInvoiceMB.TIoMSourcePeriod, 
                  VS4TAR.TARNName, VS4TAR.TARNName2, VS4TAR.TARNTaxNo, VS4TAR.TARNTARGCode, VS4TARInvoice.TIvoTEmpCode, VS4TARInvoice.TIvoSaleName, VS4TARInvoice.TIvoDiscountTotal, 
                  VS4TARInvoice.TIvoDeposit
FROM     VS4TPOS RIGHT OUTER JOIN
                  VS4TAR INNER JOIN
                  VS4TARReceipt LEFT OUTER JOIN
                  VS4TBranch ON VS4TARReceipt.TAIHTBraCode = VS4TBranch.TBraCode INNER JOIN
                  VS4TARReceiptMB ON VS4TARReceipt.TAIHNo = VS4TARReceiptMB.TREMTAIHNo ON VS4TAR.TARNCode = VS4TARReceipt.TAIHTARNCode INNER JOIN
                  VS4TARInvoiceMB INNER JOIN
                  VS4TARInvoice ON VS4TARInvoiceMB.TIoMTIvoNo = VS4TARInvoice.TIvoNo ON VS4TARReceiptMB.TREMRefDocNo = VS4TARInvoice.TIvoNo ON VS4TPOS.TPOSCode = VS4TARInvoiceMB.TIoMTPOSCode

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 VS4VARVCollect AS  SELECT VS4TARVCollect.*, VS4TARVCollectMB.*, VS4TARVoucherPay.*, VS4TARVoucher.*, VS4TEmployee.TEmpFullName, VS4TEmployee.TEmpFullName2, VS4TSaleArea.TSAeName, VS4TSaleArea.TSAeName2, VS4TAR.TARNName2, VS4TBranch.TBraName, VS4TBranch.TBraName2, VS4TChequeRec.*, VS4TAR2.TAR2SaleCode, VS4TAR.TARNTSAeCode, VS4TEmployee_1.TEmpFullName AS VRVCFullName, VS4TAR.TARNName, VS4TAR.TARNChequeDay, VS4TAR.TARNChequeAddMonth, VS4TBank.TBnkCode FROM (((VS4TAR INNER JOIN VS4TAR2 ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) INNER JOIN VS4TARVoucher ON VS4TAR.TARNCode = VS4TARVoucher.TRVHTARNCode) INNER JOIN ((VS4TARVoucherPay LEFT JOIN VS4TBank ON VS4TARVoucherPay.TRVRTBnkCode = VS4TBank.TBnkCode) INNER JOIN (((((VS4TARVCollect LEFT JOIN VS4TEmployee ON VS4TARVCollect.TRVCTEmpCode = VS4TEmployee.TEmpCode) LEFT JOIN VS4TSaleArea ON VS4TARVCollect.TRVCTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN VS4TBranch ON VS4TARVCollect.TRVCTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TEmployee AS VS4TEmployee_1 ON VS4TARVCollect.TRVCSupTEmpCode = VS4TEmployee_1.TEmpCode) INNER JOIN VS4TARVCollectMB ON VS4TARVCollect.TRVCNo = VS4TARVCollectMB.TRMBTRVCNo) ON (VS4TARVoucherPay.TRVRLn = VS4TARVCollectMB.TRMBTRVRLn) AND (VS4TARVoucherPay.TRVRTRVHNo = VS4TARVCollectMB.TRMBTRVRTRVHNo)) 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 VS4VAsset AS  SELECT VS4TAsset.*, VS4TAssetSection.TAseName, VS4TAssetCalcType.TACTName, VS4TAssetType.TAstName, VS4TUnit.TUntName, VS4TBranch.TBraName, VS4TProject.TPrjCode, VS4TProject.TPrjName, VS4TSection.TSecName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TAssetType.TAstDocCode, VS4TSection.TSecName2, VS4TDivision.TDivName2, VS4TDepartment.TDepName2, VS4TAssetType.TAstName2, VS4TAssetSection.TAseName2, VS4TAssetAlias.TAsACode, VS4TAssetAlias.TAsATAsTCode, VS4TAssetAlias.TAsATSecCode, VS4TSection_1.TSecName AS VAssSecName, VS4TAP.TAPNName, VS4TAP.TAPNName2, VS4TAssetType.TAsTCode FROM ((VS4TAssetSection LEFT JOIN VS4TAssetType ON VS4TAssetSection.TAseTAsTCode = VS4TAssetType.TAsTCode) 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) LEFT JOIN VS4TAP ON VS4TAsset.TAssTAPNCode = VS4TAP.TAPNCode) ON VS4TAssetSection.TAseCode = VS4TAsset.TAssTAseCode) LEFT JOIN ((VS4TAssetAlias LEFT JOIN VS4TSection AS VS4TSection_1 ON VS4TAssetAlias.TAsATSecCode = VS4TSection_1.TSecCode) RIGHT JOIN VS4TAsset2Alias ON VS4TAssetAlias.TAsACode = VS4TAsset2Alias.TA2ATAsACode) ON VS4TAsset.TAssCode = VS4TAsset2Alias.TA2ATAssCode
GO

CREATE VIEW VS4VAssetAlias AS  SELECT VS4TAssetAlias.*, VS4TAsset.*, VS4TAssetType.TAstName, VS4TAssetType.TAstName2, VS4TSection.TSecName, VS4TSection.TSecName2,VS4TProduct.TPdtName, VS4TProduct.TPdtName2,VS4TProductSection.TPSEName,VS4TProductSection.TPSECode, VS4TProductSection.TPSEName2, VS4TAssetAliasGrp.TAAGCode,VS4TAssetAliasGrp.TAAGName,VS4TAssetAliasGrp.TAAGName2, VS4TBranch.TBraName, VS4TBranch.TBraName2, VS4TEmployee.TEmpFullName, VS4TEmployee_1.TEmpFullName AS TEmpFullName2,  VS4TEmployee_2.TEmpFullName AS TEmpFullName3 FROM (((VS4TAsset RIGHT JOIN (VS4TAssetType RIGHT JOIN ((((((VS4TAssetAlias LEFT JOIN VS4TSection ON VS4TAssetAlias.TAsATSecCode = VS4TSection.TSecCode) LEFT JOIN VS4TBranch ON VS4TAssetAlias.TAsATBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TAsset2Alias ON VS4TAssetAlias.TAsACode = VS4TAsset2Alias.TA2ATAsACode) LEFT JOIN                   VS4TAssetAliasGrp ON VS4TAssetAlias.TAsATAAGCode = VS4TAssetAliasGrp.TAAGCode) LEFT JOIN VS4TProduct ON VS4TAssetAlias.TAsATPdtCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode) ON VS4TAssetType.TAsTCode = VS4TAssetAlias.TAsATAsTCode) ON VS4TAsset.TAssCode = VS4TAsset2Alias.TA2ATAssCode) LEFT JOIN VS4TEmployee ON VS4TAssetAlias.TAsATEmpCode = VS4TEmployee.TEmpCode) LEFT JOIN VS4TEmployee AS VS4TEmployee_1 ON VS4TAssetAlias.TAsATEmpCode2 = VS4TEmployee_1.TEmpCode) LEFT JOIN VS4TEmployee AS VS4TEmployee_2 ON VS4TAssetAlias.TAsATEmpCode3 = VS4TEmployee_2.TEmpCode
GO

CREATE VIEW VS4VAssetAllocate AS  SELECT VS4TAsset.*, VS4TAssetSection.TAseName, VS4TAssetCalcType.TACTName, VS4TAssetType.TAstName, VS4TUnit.TUntName, VS4TBranch.TBraName, VS4TProject.TPrjCode, 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.TAALTAssCode) LEFT JOIN VS4TBranch ON VS4TAssetAllocate.TAALTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TDivision ON VS4TAssetAllocate.TAALTDivCode = VS4TDivision.TDivCode) LEFT JOIN VS4TDepartment ON VS4TAssetAllocate.TAALTDepCode = VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TAssetAllocate.TAALTSecCode = VS4TSection.TSecCode) ON VS4TAssetSection.TAseCode = VS4TAsset.TAssTAseCode) ON VS4TAssetType.TAsTCode = VS4TAsset.TAssTAsTCode
GO

CREATE VIEW VS4VAssetBuiltReq AS  SELECT VS4TAssetBuiltReq.*, VS4TAssetAlias.*, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TProject.TPrjName, VS4TBranch.TBraName FROM (((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) LEFT JOIN VS4TAssetAlias ON VS4TAssetBuiltReq.TBRqTAsACode = VS4TAssetAlias.TAsACode
GO

CREATE VIEW VS4VAssetFix AS  SELECT VS4TAssetFix.*, VS4TAssetFixMB.*, VS4TAssetAlias.*, VS4TProject.TPrjName, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TSection.TSecName 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 ON VS4TAssetFix.TFstNo = VS4TAssetFixMB.TFSbTFstNo) LEFT JOIN VS4TAssetAlias ON VS4TAssetFixMB.TFSbTAsACode = VS4TAssetAlias.TAsACode
GO

CREATE VIEW VS4VAssetFixMain AS  SELECT VS4TAssetFix.*, VS4TAssetFixSub.*, VS4TAssetAlias.*, VS4TAssetFixType.TFITName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TAssetFixReq.TFRqNo, VS4TAssetFixReq.TFRqDate, VS4TAssetFixReq.TFRqTAsACode, VS4TAssetFixReq.TFRqDescription FROM ((((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) LEFT JOIN VS4TAssetAlias ON VS4TAssetFixReq.TFRqTAsACode = VS4TAssetAlias.TAsACode
GO

CREATE VIEW VS4VAssetFixReq AS  SELECT VS4TAssetFixReq.*, VS4TAssetAlias.*, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TProject.TPrjName, VS4TBranch.TBraName FROM (((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) LEFT JOIN VS4TAssetAlias ON VS4TAssetFixReq.TFRqTAsACode = VS4TAssetAlias.TAsACode
GO

CREATE VIEW VS4VAssetFund AS  SELECT VS4TAsset.*, VS4TAssetFund.*, VS4TAssetType.*, VS4TAssetSection.*, VS4TAssetFundType.TAFtName, VS4TAssetFundType.TAFtName2 FROM VS4TAssetSection RIGHT JOIN (VS4TAssetFundType RIGHT JOIN ((VS4TAsset LEFT JOIN VS4TAssetType ON VS4TAsset.TAssTAsTCode = VS4TAssetType.TAsTCode) INNER JOIN VS4TAssetFund ON VS4TAsset.TAssCode = VS4TAssetFund.TAFdTAssCode) ON VS4TAssetFundType.TAFtCode = VS4TAssetFund.TAFdTAFtCode) 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 FROM (VS4TAssetType INNER JOIN (VS4TAssetSection INNER JOIN ((VS4TAssetCalcType INNER JOIN VS4TAsset 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) LEFT JOIN VS4TACChart ON VS4TAsset.TAssDebitCode = VS4TACChart.TACCCode
GO

CREATE VIEW VS4VAssetGLSum AS  SELECT VS4TAsset.TAssTPrjCode, VS4TAsset.TAssTBraCode, VS4TAssetPeriodSub.TSPbYear, VS4TAssetPeriodSub.TSPbMonth, VS4TAsset.TAssDebitCode, VS4TACChart_1.TACCName AS VAGLDebitName, VS4TAsset.TAssCreditCode, VS4TACChart.TACCName AS VAGLCreditName, Sum(VS4TAssetPeriodSub.TSPbAmount) AS TSPbAmount, VS4TAssetPeriodSub.TSPbStatus FROM ((VS4TAsset LEFT JOIN VS4TACChart ON VS4TAsset.TAssCreditCode = VS4TACChart.TACCCode) INNER JOIN VS4TAssetPeriodSub ON VS4TAsset.TAssCode = VS4TAssetPeriodSub.TSPbTAssCode) LEFT JOIN VS4TACChart AS VS4TACChart_1 ON VS4TAsset.TAssDebitCode = VS4TACChart_1.TACCCode GROUP BY VS4TAsset.TAssTPrjCode, VS4TAsset.TAssTBraCode, VS4TAssetPeriodSub.TSPbYear, VS4TAssetPeriodSub.TSPbMonth, VS4TAsset.TAssDebitCode, VS4TACChart_1.TACCName, VS4TAsset.TAssCreditCode, VS4TACChart.TACCName, VS4TAssetPeriodSub.TSPbStatus, VS4TAssetPeriodSub.TSPbLn HAVING (((VS4TAssetPeriodSub.TSPbLn)<>0))
GO

CREATE VIEW VS4VAssetInWG AS  SELECT VS4TAssetWorkGroup.*, VS4TAssetAlias.*, VS4TAssetType.*, VS4TAssetWorkTime.*, VS4TAsset.* FROM VS4TAssetWorkGroup INNER JOIN (VS4TAsset RIGHT JOIN (VS4TAssetType INNER JOIN (((VS4TAssetAlias LEFT JOIN VS4TAsset2Alias ON VS4TAssetAlias.TAsACode = VS4TAsset2Alias.TA2ATAsACode) INNER JOIN VS4TAssetWGMB ON VS4TAssetAlias.TAsACode = VS4TAssetWGMB.TAegTAsACode) LEFT JOIN VS4TAssetWorkTime ON VS4TAssetAlias.TAsACode = VS4TAssetWorkTime.TEntTAsACode) ON VS4TAssetType.TAsTCode = VS4TAssetAlias.TAsATAsTCode) ON VS4TAsset.TAssCode = VS4TAsset2Alias.TA2ATAssCode) 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, 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, VS4TBranch.TBraName, VS4TAssetFixType.*, VS4TAssetFixCCL.*, VS4TAssetAlias.* 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 LEFT JOIN VS4TAssetAlias ON VS4TAssetPMMB.TAFBTAsACode = VS4TAssetAlias.TAsACode) 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, VS4TBranch.TBraName 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 VS4TAssetPMMB ON VS4TAssetPM.TAFPNo = VS4TAssetPMMB.TAFBTAFPNo
GO

CREATE VIEW VS4VAssetTransfer AS  SELECT VS4TAssetType.*, VS4TAsset.*, VS4TAssetTransMB.*, VS4TAssetTrans.*, VS4TAssetTransType.*, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TProject.TPrjName, 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.*, VS4TAssetAlias.* FROM VS4TAssetWorkGroup INNER JOIN (VS4TAsset RIGHT JOIN ((VS4TAssetAlias LEFT JOIN VS4TAsset2Alias ON VS4TAssetAlias.TAsACode = VS4TAsset2Alias.TA2ATAsACode) INNER JOIN VS4TAssetWGMB ON VS4TAssetAlias.TAsACode = VS4TAssetWGMB.TAegTAsACode) ON VS4TAsset.TAssCode = VS4TAsset2Alias.TA2ATAssCode) ON VS4TAssetWorkGroup.TAgtCode = VS4TAssetWGMB.TAegTAgtCode
GO

CREATE VIEW VS4VAssetWorkTime AS  SELECT VS4TAssetAlias.*, VS4TAssetWorkTime.*, VS4TAsset.*, 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 ((VS4TAssetAlias LEFT JOIN VS4TAsset2Alias ON VS4TAssetAlias.TAsACode = VS4TAsset2Alias.TA2ATAsACode) RIGHT JOIN VS4TAssetWorkTime ON VS4TAssetAlias.TAsACode = VS4TAssetWorkTime.TEntTAsACode) ON VS4TAsset.TAssCode = VS4TAsset2Alias.TA2ATAssCode
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, VS4TSOMB.TSOBFactoryCode FROM VS4TUnit RIGHT 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) LEFT JOIN VS4TSOMB ON (VS4TInventoryMB.TInMTSOBLn = VS4TSOMB.TSOBLn) AND (VS4TInventoryMB.TInMTSODNo = VS4TSOMB.TSOBTSODNo)) 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.TInvNo, VS4TInventory.TInvMode, VS4TInventory.TInvTIBkCode, VS4TInventory.TInvDate, VS4TInventory.TInvInvoiceStatus, VS4TInventory.TInvTARNCode,                           VS4TInventory.TInvTInTAlias, VS4TInventory.TInvRefNo, VS4TInventory.TInvRefDate, VS4TInventory.TInvRefNo2, VS4TInventory.TInvRefDate2, VS4TInventory.TInvRefNo3,                           VS4TInventory.TInvRefDate3, VS4TInventory.TInvCustom1, VS4TInventory.TInvCustom2, VS4TInventory.TInvCustom3, VS4TInventory.TInvCustom4, VS4TInventory.TInvCustom5,                           VS4TInventory.TInvTPrjCode, VS4TInventory.TInvTJobNo, VS4TInventory.TInvTJbMLn, VS4TInventory.TInvTMPSNo, VS4TInventory.TInvTJPdNo, VS4TInventory.TInvTJPMLn,                           VS4TInventory.TInvTSecCode, VS4TInventory.TInvTDepCode, VS4TInventory.TInvTDivCode, VS4TInventory.TInvTBraCode, VS4TInventory.TInvFromTBraCode, VS4TInventory.TInvTotal,                           VS4TInventory.TInvTotalRecord, VS4TInventory.TInvTotalQuantity, VS4TInventory.TInvRequestCode, VS4TInventory.TInvRequestBy, VS4TInventory.TInvDescription, VS4TInventory.TInvGLMethod,                           VS4TInventory.TInvTGLTNo, VS4TInventory.TInvDeliveryStatus, VS4TInventory.TInvSpecialFlag, VS4TInventory.TInvIsCompleted, VS4TInventory.TInvCreateBy, VS4TInventory.TInvCreateDate,                           VS4TInventory.TInvEditCode, VS4TInventory.TInvEditBy, VS4TInventory.TInvEditDate, VS4TInventory.TInvConfirmStatus, VS4TInventory.TInvConfirmBy, VS4TInventory.TInvConfirmDate,                           VS4TInventory.TInvApproveStatus, VS4TInventory.TInvApproveBy, VS4TInventory.TInvApproveDate, VS4TInventory.TInvApproveNote, VS4TInventory.TInvRevision, VS4TInventory.TInvCancelStatus,                           VS4TInventory.TInvCancelBy, VS4TInventory.TInvCancelDate, VS4TInventory.TInvFlag1, VS4TInventory.TInvCustomNo, VS4TInventory.TInvCustomDate, VS4TInventory.TInvTotalScrap,                           VS4TInventory.TInvTotalQScrap, VS4TInventory.TInvTotalQInput, VS4TInventory.TInvTotalAInput, VS4TInventory.TInvTotalRecordIn, VS4TInventory.TInvTotalPCScrap, VS4TInventory.TInvTotalPCQScrap,                           VS4TInventory.TInvSourceType, VS4TInventoryMB.TInMTInvNo, VS4TInventoryMB.TInMLn, VS4TInventoryMB.TInMTACPTACYID, VS4TInventoryMB.TInMTACPID, VS4TInventoryMB.TInMTPdtCode,                           VS4TInventoryMB.TInMCustom1, VS4TInventoryMB.TInMSerialNo, VS4TInventoryMB.TInMLotNo, VS4TInventoryMB.TInMLotDate, VS4TInventoryMB.TInMScrapLevel,                           VS4TInventoryMB.TInMQuantityCalc, VS4TInventoryMB.TInMUnitRatio, VS4TInventoryMB.TInMQuantityBase, VS4TInventoryMB.TInMTUntCode, VS4TInventoryMB.TInMInQuantity,                           VS4TInventoryMB.TInMOutQuantity, VS4TInventoryMB.TInMAmouQuantity, VS4TInventoryMB.TInMAmouQuantity2, VS4TInventoryMB.TInMAmouQuantity3, VS4TInventoryMB.TInMAmount,                           VS4TInventoryMB.TInMStatus, VS4TInventoryMB.TInMFromTLctCode, VS4TInventoryMB.TInMTLctCode, VS4TInventoryMB.TInMDescription, VS4TInventoryMB.TInMTInTAlias,                           VS4TInventoryMB.TInMTSODNo, VS4TInventoryMB.TInMTSOBLn, VS4TInventoryMB.TInMTMDSLn, VS4TInventoryMB.TInMSourceType, VS4TInventoryMB.TInMSourceNo,                           VS4TInventoryMB.TInMSourceLn, VS4TInventoryMB.TInMQuantityText, VS4TInventoryMB.TInMQuantityCutTxt, VS4TInventoryMB.TInMQuantityCut, VS4TInventoryMB.TInMQuantityFirst,                           VS4TInventoryMB.TInMArrear, VS4TInventoryMB.TInMAgentPrice, VS4TInventoryMB.TInMQAStatus, VS4TInventoryMB.TInMQANote, VS4TInventoryMB.TInMTPltCode,                           VS4TInventoryMB.TInMFromTPltCode, VS4TInventoryMB.TInMQuantityCost, VS4TInventoryMB.TInMAgentPrice2, VS4TInventoryMB.TInMAgentPrice3, VS4TInventoryMB.TInMFromTIvsCode,                           VS4TInventoryMB.TInMUnitCalc, VS4TInventoryMB.TInMUnitCost, 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, 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.TSODDeliveryNote, VS4TSO.TSODPackingNote, VS4TSO.TSODDayAvailable,                           VS4TSO.TSODDescription, VS4TSO.TSODCustom1, VS4TSO.TSODCustom2, VS4TSO.TSODCustom3, VS4TSO.TSODCustom4, VS4TSO.TSODCustom5, VS4TSO.TSODInvoiceStatus,                           VS4TSO.TSODRevision, VS4TSO.TSODDeliveryStatus, 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.TIMCIsOwner, VS4TJob.TJobTPrjCode, VS4TRoute.TRouCode, VS4TRoute.TRouName,                           VS4TSOMB.TSOBTUntCode, VS4TSOMB.TSOBUnitFactor, VS4TInventoryLOT.TIMCInputTCurCode, VS4TSOMB.TSOBFactoryCode, VS4TAR2.TAR2TShpCode, VS4TShipping.TSHPName,                           VS4TAR.TARNName, VS4TAR.TARNName2, VS4TSO.TSODTSBkCode, VS4TSOBook.TSBKName, VS4TSOMB.TSOBTLblCode FROM            VS4TUnit RIGHT OUTER JOIN                          VS4TInventoryType INNER JOIN                          VS4TSOBook RIGHT OUTER JOIN                          VS4TProduct LEFT OUTER JOIN                          VS4TProductType ON VS4TProduct.TPdtTPTTCode = VS4TProductType.TPTTCode LEFT OUTER JOIN                          VS4TProductLine ON VS4TProduct.TPdtTPDLCode = VS4TProductLine.TPdLCode LEFT OUTER JOIN                          VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode LEFT OUTER JOIN                          VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code LEFT OUTER JOIN                          VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode INNER JOIN                          VS4TInventory LEFT OUTER JOIN                          VS4TJobMB ON VS4TInventory.TInvTJobNo = VS4TJobMB.TJbMTJobNo AND VS4TInventory.TInvTJbMLn = VS4TJobMB.TJbMLn LEFT OUTER JOIN                          VS4TJob LEFT OUTER JOIN                          VS4TProject ON VS4TJob.TJobTPrjCode = VS4TProject.TPrjCode ON VS4TJobMB.TJbMTJobNo = VS4TJob.TJobNo LEFT OUTER JOIN                          VS4TAR2 ON VS4TInventory.TInvTARNCode = VS4TAR2.TAR2TARNCode LEFT OUTER JOIN                          VS4TRoute ON VS4TAR2.TAR2TRouCode = VS4TRoute.TRouCode LEFT OUTER JOIN                          VS4TShipping ON VS4TAR2.TAR2TShpCode = VS4TShipping.TSHPCode LEFT OUTER JOIN                          VS4TAR ON VS4TInventory.TInvTARNCode = VS4TAR.TARNCode INNER JOIN                          VS4TInventoryLOT INNER JOIN                          VS4TInventoryMB LEFT OUTER JOIN                          VS4TLocation ON VS4TInventoryMB.TInMTLctCode = VS4TLocation.TLctCode LEFT OUTER JOIN                          VS4TSO ON VS4TInventoryMB.TInMTSODNo = VS4TSO.TSODNo LEFT OUTER JOIN                          VS4TBranch ON VS4TSO.TSODTBraCode = VS4TBranch.TBraCode LEFT OUTER JOIN                          VS4TWarehouse ON VS4TLocation.TLctTWahCode = VS4TWarehouse.TWahCode LEFT OUTER 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                           VS4TSOBook.TSBKCode = VS4TSO.TSODTSBkCode 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, VS4TInventory.TInvCustomNo, VS4TInventory.TInvCustomDate, VS4TInventoryLOT.TIMCCustom2, VS4TInventoryLOT.TIMCCustom3, VS4TInventoryLOT.TIMCCustom4, VS4TInventoryLOT.TIMCCustom5 FROM VS4TInventoryLOT RIGHT JOIN (VS4TProduct INNER JOIN (VS4TInventory INNER JOIN VS4TInventoryMB ON VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo) ON VS4TProduct.TPdtCode = VS4TInventoryMB.TInMTPdtCode) 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) 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.TInvCustomNo, VS4TInventory.TInvCustomDate, VS4TInventory.TInvApproveStatus, VS4TInventory.TInvCancelStatus, VS4TInventoryLOT.TIMCCustom2, VS4TInventoryLOT.TIMCCustom3, VS4TInventoryLOT.TIMCCustom4, VS4TInventoryLOT.TIMCCustom5 HAVING (((VS4TInventory.TInvTInTAlias)='SALEOUT' Or (VS4TInventory.TInvTInTAlias)='SALEOUTPOS') AND ((VS4TInventory.TInvApproveStatus)=1) AND ((VS4TInventory.TInvCancelStatus)=0))
GO

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

CREATE VIEW VS4VAttachSheetSOM AS  SELECT VS4TInventoryMB.*, VS4TSO.TSODNo, VS4TSO.TSODTSBkCode, VS4TSO.TSODTRCACode, VS4TSO.TSODMode, VS4TSO.TSODCode, VS4TSO.TSODType, VS4TSO.TSODDate, VS4TSO.TSODDueDate, VS4TSO.TSODRefNo, VS4TSO.TSODRefDate, VS4TSO.TSODTPrjCode, VS4TSO.TSODTBraCode, VS4TSO.TSODTEmpCode, VS4TSO.TSODSaleName, VS4TSO.TSODGuideText, VS4TSO.TSODEmpText, VS4TSO.TSODDeliveryDate, VS4TSO.TSODDeliveryTo, VS4TSO.TSODTARNCode, VS4TSO.TSODTARDCode, VS4TSO.TSODContactNote, VS4TSO.TSODContactName, VS4TSO.TSODCustomerName, VS4TSO.TSODCusAddress, VS4TSO.TSODConsignee, VS4TSO.TSODNotifyParty, VS4TSO.TSODCostTotal, VS4TSO.TSODPriceChannel, VS4TSO.TSODDiscountList, VS4TSO.TSODSubTotal, VS4TSO.TSODDiscountText, VS4TSO.TSODDiscountTotal, VS4TSO.TSODNetTotal, VS4TSO.TSODDepositText, VS4TSO.TSODDeposit, VS4TSO.TSODTotal, VS4TSO.TSODTotalFOB, VS4TSO.TSODTCurCode, VS4TSO.TSODExchangeRate, VS4TSO.TSODTotalInRate, VS4TSO.TSODVATType, VS4TSO.TSODVATRate, VS4TSO.TSODTaxBase, VS4TSO.TSODVATTotal, VS4TSO.TSODGrandTotal, VS4TSO.TSODNOTAXTotal, VS4TSO.TSODWTAXBase, VS4TSO.TSODWTaxRate, VS4TSO.TSODWTaxTotal, VS4TSO.TSODNetPayment, VS4TSO.TSODAdjustTotal, VS4TSO.TSODRewardTotal, VS4TSO.TSODPremiumTotal, VS4TSO.TSODCommissionBase, VS4TSO.TSODCommissionRate, VS4TSO.TSODCommission, VS4TSO.TSODBaseIncoType, VS4TSO.TSODIncoType, VS4TSO.TSODIncoterms, VS4TSO.TSODOtherFee, VS4TSO.TSODTransportFee, VS4TSO.TSODHandlingFee, VS4TSO.TSODFreightFee, VS4TSO.TSODInsurance, VS4TSO.TSODTransportDesc, VS4TSO.TSODDuty, VS4TSO.TSODShipBy, VS4TSO.TSODCountryOrigin, VS4TSO.TSODDestination, VS4TSO.TSODCondition, VS4TSO.TSODConditionDay, VS4TSO.TSODCondition1, VS4TSO.TSODConditionDay1, VS4TSO.TSODPaymentNote, VS4TSO.TSODStatementNote, VS4TSO.TSODDeliveryNote, VS4TSO.TSODPackingNote, VS4TSO.TSODDayAvailable, VS4TSO.TSODDescription, VS4TSO.TSODCustom1, VS4TSO.TSODCustom2, VS4TSO.TSODCustom3, VS4TSO.TSODCustom4, VS4TSO.TSODCustom5, VS4TSO.TSODInvoiceStatus, VS4TSO.TSODVerifyStatus, VS4TSO.TSODTSOTCode, VS4TSO.TSODDeliveryStatus, VS4TSO.TSODFinishDate, VS4TSO.TSODCreateBy, VS4TSO.TSODCreateDate, VS4TSO.TSODEditCode, VS4TSO.TSODEditBy, VS4TSO.TSODEditDate, VS4TSO.TSODConfirmStatus, VS4TSO.TSODConfirmBy, VS4TSO.TSODConfirmDate, VS4TSO.TSODApproveStatus, VS4TSO.TSODApproveBy, VS4TSO.TSODApproveDate, VS4TSO.TSODApproveNote, VS4TSO.TSODRevision, VS4TSO.TSODReviseBy, VS4TSO.TSODCancelStatus, VS4TSO.TSODCancelBy, VS4TSO.TSODCancelDate, VS4TSO.TSODCancelNote, VS4TSO.TSODFlag1, VS4TSO.TSODPMCostTotal, VS4TSO.TSODTOTNLn, VS4TSO.TSODTime, VS4TSO.TSODDeliveryTime, VS4TSO.TSODStartDate, VS4TSO.TSODLoadingDate, VS4TSO.TSODStartAgingDate, VS4TSO.TSODArrears, VS4TSO.TSODNote, VS4TSO.TSODTAPNCode, VS4TSO.TSODCheckPoint, VS4TSOMB.TSOBTSODNo, VS4TSOMB.TSOBLn, VS4TSOMB.TSOBType, VS4TSOMB.TSOBJobCode, VS4TSOMB.TSOBGroupName, VS4TSOMB.TSOBTOInCode, VS4TSOMB.TSOBTPOSCode, VS4TSOMB.TSOBCustom1, VS4TSOMB.TSOBCustom2, VS4TSOMB.TSOBCustom3, VS4TSOMB.TSOBCustom4, VS4TSOMB.TSOBCustom5, VS4TSOMB.TSOBShippingMark, VS4TSOMB.TSOBPOSCode, VS4TSOMB.TSOBFactoryCode, VS4TSOMB.TSOBPOSName, VS4TSOMB.TSOBOLDPOSName, VS4TSOMB.TSOBCost, VS4TSOMB.TSOBPrice, VS4TSOMB.TSOBPerQuantity, VS4TSOMB.TSOBUnitFactor, VS4TSOMB.TSOBQuantityCalc, VS4TSOMB.TSOBUnitCalc, VS4TSOMB.TSOBAcceptError, VS4TSOMB.TSOBQuantityText, VS4TSOMB.TSOBQuantity, VS4TSOMB.TSOBTUntCode, VS4TSOMB.TSOBQuantity2, VS4TSOMB.TSOBTUntCode2, VS4TSOMB.TSOBQuantity3, VS4TSOMB.TSOBTUntCode3, VS4TSOMB.TSOBCostAmount, VS4TSOMB.TSOBAmount, VS4TSOMB.TSOBDiscountText, VS4TSOMB.TSOBDiscountTotal, VS4TSOMB.TSOBNetAmount, VS4TSOMB.TSOBTaxType, VS4TSOMB.TSOBTaxBase, VS4TSOMB.TSOBWTAXBase, VS4TSOMB.TSOBAmountVAT, VS4TSOMB.TSOBAmountWTAX, VS4TSOMB.TSOBPromotionType, VS4TSOMB.TSOBFreeCode, VS4TSOMB.TSOBIsPremium, VS4TSOMB.TSOBDescription, VS4TSOMB.TSOBUseDate, VS4TSOMB.TSOBSourceNo, VS4TSOMB.TSOBSourceLn, VS4TSOMB.TSOBTIvoNo, VS4TSOMB.TSOBTotalDelivery, VS4TSOMB.TSOBTotalDelivery2, VS4TSOMB.TSOBTotalDelivery3, VS4TSOMB.TSOBTotalArrear, VS4TSOMB.TSOBTotalArrear2, VS4TSOMB.TSOBTotalArrear3, VS4TSOMB.TSOBTotalJob, VS4TSOMB.TSOBTotalJob2, VS4TSOMB.TSOBTotalJob3, VS4TSOMB.TSOBTotalJobArr, VS4TSOMB.TSOBTotalJobArr2, VS4TSOMB.TSOBTotalJobArr3, VS4TSOMB.TSOBDayProcess, VS4TSOMB.TSOBTLctCode, VS4TSOMB.TSOBFG, VS4TSOMB.TSOBJobRequest, VS4TSOMB.TSOBRequestDate, VS4TSOMB.TSOBReadyDate, VS4TSOMB.TSOBStatus, VS4TSOMB.TSOBManualClose, VS4TSOMB.TSOBPremiumCost, VS4TSOMB.TSOBTotalInv, VS4TSOMB.TSOBTotalInv2, VS4TSOMB.TSOBTotalInv3, VS4TInventory.TInvNo, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TInventory.TInvCustomNo, VS4TInventory.TInvCustomDate, VS4TInventoryLOT.TIMCCustom2, VS4TInventoryLOT.TIMCCustom3, VS4TInventoryLOT.TIMCCustom4, VS4TInventoryLOT.TIMCCustom5 FROM VS4TUnit RIGHT JOIN (VS4TInventoryType INNER JOIN (VS4TSO RIGHT JOIN (VS4TProduct INNER JOIN (VS4TInventory INNER JOIN (VS4TInventoryLOT RIGHT JOIN (((VS4TInventoryMB LEFT JOIN VS4TLocation ON VS4TInventoryMB.TInMTLctCode = VS4TLocation.TLctCode) INNER JOIN VS4TSOMB ON (VS4TInventoryMB.TInMTSOBLn = VS4TSOMB.TSOBLn) AND (VS4TInventoryMB.TInMTSODNo = VS4TSOMB.TSOBTSODNo)) 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 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 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 VS4VBankHoliday AS  SELECT VS4TBankHoliday.*, VS4VBnkHolidayA.VBhdGroupDay FROM VS4TBankHoliday LEFT JOIN (SELECT VS4TBankHoliday.TBhdYear, VS4TBankHoliday.TBhdHolidayName, Count(VS4TBankHoliday.TBhdYear) AS VBhdGroupDay FROM VS4TBankHoliday GROUP BY VS4TBankHoliday.TBhdYear, VS4TBankHoliday.TBhdHolidayName) AS VS4VBnkHolidayA ON (VS4TBankHoliday.TBhdHolidayName = VS4VBnkHolidayA.TBhdHolidayName) AND (VS4TBankHoliday.TBhdYear = VS4VBnkHolidayA.TBhdYear)
GO

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

CREATE VIEW VS4VBankStatement AS  SELECT VS4TCompanyBank.*, VS4TAPVoucherPay.*, VS4TARVoucherPay.*, VS4TBank.*, VS4TPaymentType.TPyTName, VS4TPaymentType_1.TPyTName AS VBSmPayName, VS4TChequeSub.*, VS4TChequeRec.* FROM (VS4TPaymentType RIGHT JOIN (((VS4TBank INNER JOIN VS4TCompanyBank ON VS4TBank.TBnkCode = VS4TCompanyBank.TCBBTBnkCode) INNER JOIN (VS4TChequeSub RIGHT JOIN ((VS4TAPVoucherPay LEFT JOIN VS4TPaymentType AS VS4TPaymentType_1 ON VS4TAPVoucherPay.TPVPPaymentType = VS4TPaymentType_1.TPyTAlias) LEFT JOIN VS4TChequeSub2PV ON (VS4TAPVoucherPay.TPVPLn = VS4TChequeSub2PV.TS2PTPVPLn) AND (VS4TAPVoucherPay.TPVPTAPVNo = VS4TChequeSub2PV.TS2PTPVPTAPVNo)) ON VS4TChequeSub.TCHSNo = VS4TChequeSub2PV.TS2PTCHSNo) ON VS4TCompanyBank.TCBBNo = VS4TAPVoucherPay.TPVPTCBBNo) INNER JOIN VS4TARVoucherPay ON VS4TCompanyBank.TCBBNo = VS4TARVoucherPay.TRVRTCBBNo) ON VS4TPaymentType.TPyTAlias = VS4TARVoucherPay.TRVRReceiveType) LEFT JOIN (VS4TChequeRec RIGHT JOIN VS4TChequeRec2RV ON VS4TChequeRec.TCHRNo = VS4TChequeRec2RV.TR2RTCHRNo) ON (VS4TARVoucherPay.TRVRLn = VS4TChequeRec2RV.TR2RTRVRLn) AND (VS4TARVoucherPay.TRVRTRVHNo = VS4TChequeRec2RV.TR2RTRVRTRVHNo)
GO

CREATE VIEW VS4VBOQ AS  SELECT VS4TBOQ.*, VS4TBOQMB.*, 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 LEFT JOIN VS4TProduct ON VS4TBOQMB.TBQBTPdtCode = VS4TProduct.TPdtCode) 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
GO

CREATE VIEW VS4VBOQDL AS  SELECT VS4TBOQ.*, VS4TBOQMB.*, VS4TProject.TPrjCode, VS4TProject.TPrjName, VS4TProject.TPrjName2, VS4TProject.TPrjTPjTCode, VS4TProjectPhase.TPHSTPrjCode, VS4TProjectPhase.TPHSLn, VS4TProjectPhase.TPHSName, VS4TProjectPhase.TPHSName2, VS4TBOQMethod.*, VS4TBOQDL.* FROM (VS4TProjectType RIGHT JOIN VS4TProject ON VS4TProjectType.TPjTCode = VS4TProject.TPrjTPjTCode) RIGHT JOIN (VS4TProjectPhase RIGHT JOIN ((VS4TBOQ INNER JOIN (VS4TBOQMB LEFT JOIN (VS4TBOQDL LEFT JOIN VS4TBOQMethod ON (VS4TBOQDL.TBQLLevel = VS4TBOQMethod.TBQRLevel) AND (VS4TBOQDL.TBQLTSpdStep = VS4TBOQMethod.TBQRTSpdStep) AND (VS4TBOQDL.TBQLTBQBLn = VS4TBOQMethod.TBQRTBQBLn) AND (VS4TBOQDL.TBQLTBQBTBOQNo = VS4TBOQMethod.TBQRTBQBTBOQNo)) ON (VS4TBOQMB.TBQBLn = VS4TBOQDL.TBQLTBQBLn) AND (VS4TBOQMB.TBQBTBOQNo = VS4TBOQDL.TBQLTBQBTBOQNo)) 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
GO

CREATE VIEW VS4VBOQH AS  SELECT VS4TBOQ.*, VS4TBOQMB.*, VS4TProject.TPrjCode, VS4TProject.TPrjName, VS4TProject.TPrjName2, VS4TProject.TPrjTPjTCode, VS4TProjectPhase.TPHSTPrjCode, VS4TProjectPhase.TPHSLn, VS4TProjectPhase.TPHSName, VS4TProjectPhase.TPHSName2 FROM (VS4TProjectType RIGHT JOIN VS4TProject ON VS4TProjectType.TPjTCode = VS4TProject.TPrjTPjTCode) RIGHT JOIN (VS4TProjectPhase RIGHT JOIN ((VS4TBOQ INNER JOIN VS4TBOQMB 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
GO

CREATE VIEW VS4VBOQMaterial 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, VS4TMRPStepName.TSepName, VS4TSO.TSODCustom1, VS4TSO.TSODCustom2, VS4TJob.TJOBOriginalNo, VS4TProductSection.TPSECode, VS4TProductSection.TPSEName, VS4TProductSection.TPSEName2 FROM (VS4TProjectType RIGHT JOIN VS4TProject ON VS4TProjectType.TPjTCode = VS4TProject.TPrjTPjTCode) RIGHT JOIN (VS4TProjectPhase RIGHT JOIN ((((VS4TBOQ LEFT JOIN VS4TJob ON VS4TBOQ.TBOQTJobNo = VS4TJob.TJobNo) LEFT JOIN VS4TSO ON VS4TBOQ.TBOQRefNo = VS4TSO.TSODNo) INNER JOIN (VS4TBOQMB INNER JOIN (((((VS4TBOQMaterial LEFT JOIN VS4TProduct ON VS4TBOQMaterial.TBQMTPdtCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TBOQMethod ON (VS4TBOQMaterial.TBQMLevel = VS4TBOQMethod.TBQRLevel) AND (VS4TBOQMaterial.TBQMTSpdStep = VS4TBOQMethod.TBQRTSpdStep) AND (VS4TBOQMaterial.TBQMTBQBLn = VS4TBOQMethod.TBQRTBQBLn) AND (VS4TBOQMaterial.TBQMTBQBTBOQNo = VS4TBOQMethod.TBQRTBQBTBOQNo)) LEFT JOIN VS4TMRPStepName ON VS4TBOQMethod.TBQRTSepCode = VS4TMRPStepName.TSepCode) LEFT JOIN VS4TProduct AS VS4TProduct_1 ON VS4TBOQMaterial.TBQMProductCode = VS4TProduct_1.TPdtCode) LEFT JOIN VS4TProductSection ON VS4TProduct_1.TPdtTPSECode = VS4TProductSection.TPSECode) 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
GO

CREATE VIEW VS4VBOQMethod AS  SELECT VS4TBOQ.*, VS4TBOQMB.*, VS4TProject.TPrjCode, VS4TProject.TPrjName, VS4TProject.TPrjName2, VS4TProject.TPrjTPjTCode, VS4TProjectPhase.TPHSTPrjCode, VS4TProjectPhase.TPHSLn, VS4TProjectPhase.TPHSName, VS4TProjectPhase.TPHSName2, VS4TBOQMethod.* FROM (VS4TProjectType RIGHT JOIN VS4TProject ON VS4TProjectType.TPjTCode = VS4TProject.TPrjTPjTCode) RIGHT JOIN (VS4TProjectPhase RIGHT JOIN ((VS4TBOQ INNER JOIN (VS4TBOQMB LEFT JOIN VS4TBOQMethod ON (VS4TBOQMB.TBQBLn = VS4TBOQMethod.TBQRTBQBLn) AND (VS4TBOQMB.TBQBTBOQNo = VS4TBOQMethod.TBQRTBQBTBOQNo)) 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
GO

CREATE VIEW VS4VBOQSumGL AS SELECT        YEAR(VS4TBOQ.TBOQDate) AS VBOQTACPTACYID, MONTH(VS4TBOQ.TBOQDate) AS VBOQTACPID, VS4TBOQ.TBOQTBraCode, VS4TBOQMaterial.TBQMTAccCode, VS4TACChart.TACCName,                           SUM(VS4TBOQMaterial.TBQMSTDCost) AS TBQMSTDCost, SUM(VS4TBOQMaterial.TBQMActualCost) AS TBQMActualCost FROM            VS4TBOQ INNER JOIN                          VS4TBOQMB ON VS4TBOQ.TBOQNo = VS4TBOQMB.TBQBTBOQNo INNER JOIN                          VS4TBOQMaterial ON VS4TBOQMB.TBQBTBOQNo = VS4TBOQMaterial.TBQMTBQBTBOQNo AND VS4TBOQMB.TBQBLn = VS4TBOQMaterial.TBQMTBQBLn LEFT OUTER JOIN                          VS4TACChart ON VS4TBOQMaterial.TBQMTAccCode = VS4TACChart.TACCCode GROUP BY YEAR(VS4TBOQ.TBOQDate), MONTH(VS4TBOQ.TBOQDate), VS4TBOQ.TBOQCancelStatus, VS4TBOQ.TBOQApproveStatus, VS4TBOQMaterial.TBQMTAccCode, VS4TACChart.TACCName,                           VS4TBOQ.TBOQTBraCode HAVING        (VS4TBOQ.TBOQApproveStatus = 1) AND (VS4TBOQ.TBOQCancelStatus = 0)
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 VS4VBudgetApp AS  SELECT VS4TGLTrans.*, VS4TGLTransSub.*, VS4TGLBook.*, VS4TAccountPeriod.*, VS4TAccountYear.*, VS4TACGroup.*, VS4TACChart.*, VS4TAP.TAPNName, VS4TAR.TARNName, VS4TACGroupSub.*, VS4TAsset.TAssNo, VS4TAsset.TAssAlias, VS4TAsset.TAssName, VS4TBudgetApp.* 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) LEFT JOIN VS4TBudgetApp ON (VS4TGLTransSub.TGTSTACPTACYID = VS4TBudgetApp.TBGATACPTACYID) AND (VS4TGLTransSub.TGTSTACCCode = VS4TBudgetApp.TBGATACCCode) AND (VS4TGLTransSub.TGTSTDivCode = VS4TBudgetApp.TBGATDivCode) AND (VS4TGLTransSub.TGTSTDepCode = VS4TBudgetApp.TBGATDepCode) AND (VS4TGLTransSub.TGTSTSecCode = VS4TBudgetApp.TBGATSecCode) AND (VS4TGLTransSub.TGTSTBraCode = VS4TBudgetApp.TBGATBraCode)) 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 VS4VBusinessFlow AS  SELECT VS4TBusinessFlow.*, VS4TBusinessFlowMB.* FROM VS4TBusinessFlow INNER JOIN VS4TBusinessFlowMB ON VS4TBusinessFlow.TBsFCode = VS4TBusinessFlowMB.TBFMTBsFCode
GO

CREATE VIEW VS4VCapacityMG AS  SELECT VS4TCapacitySect.TCAPTSecCode, VS4TCapacitySect.TCAPYear, VS4TCapacitySect.TCAPWeek, Sum(VS4TCapacitySect.TCAPHour) AS TCAPHour, Sum(VS4TCapacitySect.TCAPHourOT15) AS TCAPHourOT15, Sum(VS4TCapacitySect.TCAPHourOT2) AS TCAPHourOT2, Sum(VS4TCapacitySect.TCAPHourOT3) AS TCAPHourOT3, Sum(VS4TCapacitySect.TCAPTotalHour) AS TCAPTotalHour FROM VS4TCapacitySect GROUP BY VS4TCapacitySect.TCAPTSecCode, VS4TCapacitySect.TCAPYear, VS4TCapacitySect.TCAPWeek
GO

CREATE VIEW VS4VCapacitySect AS  SELECT VS4TCapacitySect.TCAPTSecCode, VS4TCapacitySect.TCAPYear, VS4TCapacitySect.TCAPWeek, Sum(VS4TCapacitySect.TCAPHour) AS TCAPHour, Sum(VS4TCapacitySect.TCAPHourOT15) AS TCAPHourOT15, Sum(VS4TCapacitySect.TCAPHourOT2) AS TCAPHourOT2, Sum(VS4TCapacitySect.TCAPHourOT3) AS TCAPHourOT3, Sum(VS4TCapacitySect.TCAPTotalHour) AS TCAPTotalHour FROM VS4TCapacitySect GROUP BY VS4TCapacitySect.TCAPTSecCode, VS4TCapacitySect.TCAPYear, VS4TCapacitySect.TCAPWeek
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.TDPMLn = VS4TDepositChq.TCDCTDPMLn) AND (VS4TCashDepositMB.TDPMTDPSNo = VS4TDepositChq.TCDCTDPMTDPSNo)) LEFT JOIN VS4TDepositChqSub ON (VS4TCashDepositMB.TDPMLn = VS4TDepositChqSub.TCDQTDPMLn) AND (VS4TCashDepositMB.TDPMTDPSNo = VS4TDepositChqSub.TCDQTDPMTDPSNo)) 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.TDPMLn = VS4TDepositChq.TCDCTDPMLn) AND (VS4TCashDepositMB.TDPMTDPSNo = VS4TDepositChq.TCDCTDPMTDPSNo)) ON VS4TCashDeposit.TDPSNo = VS4TCashDepositMB.TDPMTDPSNo) ON VS4TCompanyBank.TCBBNo = VS4TCashDepositMB.TDPMTCBBNo) LEFT JOIN VS4TARVDocRef ON VS4TARVoucher.TRVHNo = VS4TARVDocRef.TRDRTRVHNo
GO

CREATE VIEW VS4VCashRequest AS  SELECT VS4TCashRequest.*, VS4TCashRequestMB.*, VS4TOtherExpense.*, VS4TEmployee.TEmpFullName FROM VS4TOtherExpense RIGHT JOIN ((VS4TCashRequest LEFT JOIN VS4TEmployee ON VS4TCashRequest.TCRQTEmpCode = VS4TEmployee.TEmpCode) 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, 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, VS4TProject.TPrjName, VS4TAPVoucher.TAPVNo, VS4TAPVoucher.TAPVDate FROM VS4TBank RIGHT JOIN ((((VS4TChequeSub LEFT JOIN VS4TCompanyBank ON VS4TChequeSub.TCHSTCBBNo = VS4TCompanyBank.TCBBNo) LEFT JOIN VS4TAP ON VS4TChequeSub.TCHSTAPNCode = VS4TAP.TAPNCode) LEFT JOIN VS4TProject ON VS4TChequeSub.TCHSTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TAPVoucher ON VS4TChequeSub.TCHSTPVPTAPVNo = VS4TAPVoucher.TAPVNo) ON VS4TBank.TBnkCode = VS4TCompanyBank.TCBBTBnkCode
GO

CREATE VIEW VS4VCheque2PV AS  SELECT DISTINCT VS4TChequeSub.*, VS4TBank.TBnkName, VS4TAPVoucherPay.*, VS4TAPVoucher.*, VS4TProject.TPrjCode, VS4TProject.TPrjName, 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.*, VS4TARVoucher.*, VS4TAR.*, VS4TProject.TPrjCode, VS4TProject.TPrjName, VS4TBank.TBnkCode, VS4TBank.TBnkName, VS4TCompanyBank.TCBBNo, VS4TCompanyBank.TCBBName, VS4TCompanyBank.TCBBTBraCode, VS4TCompanyBank.TCBBTBnkCode, VS4TCompanyBank.TCBBAccountType, VS4TCompanyBank.TCBBAccountName, VS4TCompanyBank.TCBBAccountNo, VS4TCompanyBank.TCBBAccountBranch, VS4TCompanyBank.TCBBTACCCode, VS4TAR2.TAR2TPrvCode, VS4TProvince.TPrvName, VS4TSaleArea.TSAeName, VS4TSaleZone.TSZnCode, VS4TSaleZone.TSZnName, VS4TSaleZoneGroup.TSZGCode, VS4TSaleZoneGroup.TSZGName FROM (VS4TSaleZone LEFT JOIN VS4TSaleZoneGroup ON VS4TSaleZone.TSZnTSZGCode = VS4TSaleZoneGroup.TSZGCode) RIGHT JOIN (VS4TProvince RIGHT JOIN ((((((VS4TChequeRec LEFT JOIN VS4TCompanyBank ON VS4TChequeRec.TCHRTCBBNo = VS4TCompanyBank.TCBBNo) LEFT JOIN VS4TAR ON VS4TChequeRec.TCHRTARNCode = VS4TAR.TARNCode) LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN (VS4TARVoucher LEFT JOIN VS4TProject ON VS4TARVoucher.TRVHTPrjCode = VS4TProject.TPrjCode) ON VS4TChequeRec.TCHRTRVRTRVHNo = VS4TARVoucher.TRVHNo) LEFT JOIN VS4TBank ON VS4TChequeRec.TCHRTBnkCode = VS4TBank.TBnkCode) LEFT JOIN VS4TAR2 ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) ON VS4TProvince.TPrvCode = VS4TAR2.TAR2TPrvCode) ON VS4TSaleZone.TSZnCode = VS4TSaleArea.TSaeTSZnCode
GO

CREATE VIEW VS4VChequeRec2RV AS  SELECT VS4TChequeRec.*, VS4TARVoucher.*, VS4TAR.*, VS4TProject.TPrjCode, VS4TProject.TPrjName, 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.TCBBTACCCode, VS4TAR2.TAR2TPrvCode, VS4TProvince.TPrvName, VS4TSaleArea.TSAeName, VS4TSaleZone.TSZnCode, VS4TSaleZone.TSZnName, VS4TSaleZoneGroup.TSZGCode, VS4TSaleZoneGroup.TSZGName, VS4TARVoucherPay.TRVRIsChange, VS4TARVoucherPay.TRVRNote FROM (VS4TSaleZone LEFT JOIN VS4TSaleZoneGroup ON VS4TSaleZone.TSZnTSZGCode = VS4TSaleZoneGroup.TSZGCode) RIGHT JOIN (((VS4TARVoucher LEFT JOIN VS4TProject ON VS4TARVoucher.TRVHTPrjCode = VS4TProject.TPrjCode) RIGHT JOIN VS4TARVoucherPay ON VS4TARVoucher.TRVHNo = VS4TARVoucherPay.TRVRTRVHNo) RIGHT JOIN (VS4TProvince 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) LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN VS4TAR2 ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) 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 VS4TProvince.TPrvCode = VS4TAR2.TAR2TPrvCode) ON (VS4TARVoucherPay.TRVRLn = VS4TChequeRec2RV.TR2RTRVRLn) AND (VS4TARVoucherPay.TRVRTRVHNo = VS4TChequeRec2RV.TR2RTRVRTRVHNo)) ON VS4TSaleZone.TSZnCode = VS4TSaleArea.TSaeTSZnCode
GO

CREATE VIEW VS4VCOA AS  SELECT VS4TCOA.*, VS4TCOABook.*, VS4TCOAMB.*, VS4TARInvoiceMB.*, VS4TARInvoice.TIvoNo, VS4TARInvoice.TIvoRefNo, VS4TARInvoice.TIvoRefNo2, VS4TARInvoice.TIvoRefNo3, VS4TARInvoice.TIvoRefNo4, VS4TARInvoice.TIvoPONo, VS4TARInvoice.TIvoSOCode, VS4TARInvoice.TIvoJobCode, VS4TARInvoice.TIvoTARNCode, VS4TARInvoice.TIvoTARDCode, VS4TARInvoice.TIvoContactNote, VS4TARInvoice.TIvoContactName, VS4TARInvoice.TIvoCustomerName, VS4TARInvoice.TIvoCusAddress, VS4TARInvoice.TIvoConsignee, VS4TARInvoice.TIvoNotifyParty FROM ((VS4TCOABook INNER JOIN VS4TCOA ON VS4TCOABook.TCOBCode = VS4TCOA.TCOATCOBCode) INNER JOIN VS4TCOAMB ON VS4TCOA.TCOANo = VS4TCOAMB.TCABTCOANo) LEFT JOIN (VS4TARInvoice RIGHT JOIN VS4TARInvoiceMB ON VS4TARInvoice.TIvoNo = VS4TARInvoiceMB.TIoMTIvoNo) ON (VS4TCOA.TCOATIoMLn = VS4TARInvoiceMB.TIoMLn) AND (VS4TCOA.TCOATIoMTIvoNo = VS4TARInvoiceMB.TIoMTIvoNo)
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 VS4VComDoc AS  SELECT VS4TComDoc.*, VS4TComDocMB.*, VS4TAPContractMB.*, VS4TAR.TARNName, VS4TAR.TARNName2, VS4TAR.TARNCode FROM VS4TAPContract RIGHT JOIN (VS4TComDoc INNER JOIN ((VS4TComDocMB LEFT JOIN VS4TAR ON VS4TComDocMB.TCmBTARNCode = VS4TAR.TARNCode) LEFT JOIN VS4TAPContractMB ON (VS4TComDocMB.TCmBTCnMTCntNo = VS4TAPContractMB.TCnMTCntNo) AND (VS4TComDocMB.TCmBTCnMLn = VS4TAPContractMB.TCnMLn)) ON VS4TComDoc.TComNo = VS4TComDocMB.TCmBTComNo) ON VS4TAPContract.TCntNo = VS4TAPContractMB.TCnMTCntNo
GO

CREATE VIEW VS4VComInput AS  SELECT VS4TComInput.*, VS4TComInputMB.*, VS4TAR.*, VS4TAPContractMB.* FROM VS4TAPContract RIGHT JOIN ((VS4TComInput LEFT JOIN VS4TAR ON VS4TComInput.TCmITARNCode = VS4TAR.TARNCode) INNER JOIN (VS4TComInputMB LEFT JOIN VS4TAPContractMB ON (VS4TComInputMB.TCIBTCnMLn = VS4TAPContractMB.TCnMLn) AND (VS4TComInputMB.TCIBTCnMTCntNo = VS4TAPContractMB.TCnMTCntNo)) ON VS4TComInput.TCmINo = VS4TComInputMB.TCIBTCmINo) ON VS4TAPContract.TCntNo = VS4TAPContractMB.TCnMTCntNo
GO

CREATE VIEW VS4VCommand AS  SELECT VS4TCommand.*, VS4TCommandGroup.* FROM (VS4TCommand INNER JOIN VS4TCommandModule ON VS4TCommand.TCmdTCmMAlias = VS4TCommandModule.TCmMAlias) INNER JOIN VS4TCommandGroup ON VS4TCommandModule.TCmMTCmGAlias = VS4TCommandGroup.TCmGAlias
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 VS4VCostAllocate AS  SELECT VS4TCostAllocate.*, VS4TSection.TSecCode, VS4TSection.TSecName, VS4TSection.TSecName2, VS4TDepartment.TDepCode, VS4TDepartment.TDepName, VS4TDepartment.TDepName2, VS4TDivision.TDivCode, VS4TDivision.TDivName, VS4TDivision.TDivName2, VS4TBranch.TBraCode, VS4TBranch.TBraName, VS4TBranch.TBraName2, VS4TDivision.TDivCostGroup FROM (VS4TBranch INNER JOIN VS4TDivision ON VS4TBranch.TBraCode = VS4TDivision.TDivTBraCode) INNER JOIN (VS4TDepartment INNER JOIN (VS4TCostAllocate INNER JOIN VS4TSection ON VS4TCostAllocate.TCALTSecCode = VS4TSection.TSecCode) ON VS4TDepartment.TDepCode = VS4TSection.TSecTDepCode) ON VS4TDivision.TDivCode = VS4TDepartment.TDepTDivCode
GO

CREATE VIEW VS4VCurrency AS  SELECT VS4TCurrency.* FROM VS4TCurrency
GO

CREATE VIEW VS4VDeliveryIN AS  SELECT VS4TDeliveryIN.*, VS4TAPInvoice.*, VS4TAPInvoiceMB.*, VS4TDeliveryINMB.TDIMType, VS4TDeliveryINMB.TDIMDutyAmount FROM VS4TDeliveryIN INNER JOIN ((VS4TAPInvoiceMB RIGHT JOIN VS4TDeliveryINMB ON (VS4TAPInvoiceMB.TIPMTIAPNo = VS4TDeliveryINMB.TDIMTIPMTIAPNo) AND (VS4TAPInvoiceMB.TIPMLn = VS4TDeliveryINMB.TDIMTIPMLn)) LEFT JOIN VS4TAPInvoice ON VS4TAPInvoiceMB.TIPMTIAPNo = VS4TAPInvoice.TIAPNo) ON VS4TDeliveryIN.TDCINo = VS4TDeliveryINMB.TDIMTDCINo
GO

CREATE VIEW VS4VDeliveryOrder AS  SELECT VS4TARInvoice.TIvoNo, VS4TARInvoice.TIvoBalanceFlag, VS4TARInvoice.TIvoType, VS4TARInvoice.TIvoTRBKCode, VS4TARInvoice.TIvoTRCACode, VS4TARInvoice.TIvoMode, VS4TARInvoice.TIvoDate, VS4TARInvoice.TIvoDueDate, VS4TARInvoice.TIvoGLMethod, VS4TARInvoice.TIvoTGLTNo, VS4TARInvoice.TIvoClientTaxNo, VS4TARInvoice.TIvoTaxNo, VS4TARInvoice.TIvoRefNo, VS4TARInvoice.TIvoRefDate, VS4TARInvoice.TIvoRefNo2, VS4TARInvoice.TIvoRefDate2, VS4TARInvoice.TIvoPONo, VS4TARInvoice.TIvoSOCode, VS4TARInvoice.TIvoJobCode, VS4TARInvoice.TIvoTJobNo, VS4TARInvoice.TIvoTPrjCode, VS4TARInvoice.TIvoTBraCode, VS4TARInvoice.TIvoTEmpCode, VS4TARInvoice.TIvoSaleName, VS4TARInvoice.TIvoDeliveryDate, VS4TARInvoice.TIvoDeliveryTo, VS4TARInvoice.TIvoTARNCode, VS4TARInvoice.TIvoTARDCode, VS4TARInvoice.TIvoContactNote, VS4TARInvoice.TIvoContactName, VS4TARInvoice.TIvoCustomerName, VS4TARInvoice.TIvoCusAddress, VS4TARInvoice.TIvoCustomerName2, VS4TARInvoice.TIvoCusAddress2, VS4TARInvoice.TIvoConsignee, VS4TARInvoice.TIvoNotifyParty, VS4TARInvoice.TIvoCostTotal, VS4TARInvoice.TIvoPriceChannel, VS4TARInvoice.TIvoDiscountList, VS4TARInvoice.TIvoSubTotal, VS4TARInvoice.TIvoDiscountText, VS4TARInvoice.TIvoDiscountTotal, VS4TARInvoice.TIvoNetTotal, VS4TARInvoice.TIvoDepositText, VS4TARInvoice.TIvoDeposit, VS4TARInvoice.TIvoTotal, VS4TARInvoice.TIvoTotalFOB, VS4TARInvoice.TIvoTCurCode, VS4TARInvoice.TIvoExchangeRate, VS4TARInvoice.TIvoTotalInRate, VS4TARInvoice.TIvoVATType, VS4TARInvoice.TIvoVATRate, VS4TARInvoice.TIvoTaxBase, VS4TARInvoice.TIvoVATTotal, VS4TARInvoice.TIvoGrandTotal, VS4TARInvoice.TIvoNOTAXTotal, VS4TARInvoice.TIvoWTaxBase, VS4TARInvoice.TIvoWTaxRate, VS4TARInvoice.TIvoWTaxTotal, VS4TARInvoice.TIvoNetPayment, VS4TARInvoice.TIvoBaseArrears, VS4TARInvoice.TIvoArrears, VS4TARInvoice.TIvoAdjustTotal, VS4TARInvoice.TIvoBaseAvailable, VS4TARInvoice.TIvoAvailable, VS4TARInvoice.TIvoBaseIncoType, VS4TARInvoice.TIvoIncoType, VS4TARInvoice.TIvoIncoTerms, VS4TARInvoice.TIvoOtherFee, VS4TARInvoice.TIvoTransportFee, VS4TARInvoice.TIvoHandlingFee, VS4TARInvoice.TIvoFreightFee, VS4TARInvoice.TIvoInsurance, VS4TARInvoice.TIvoTransportDesc, VS4TARInvoice.TIvoDuty, VS4TARInvoice.TIvoShipBy, VS4TARInvoice.TIvoCountryOrigin, VS4TARInvoice.TIvoDestination, VS4TARInvoice.TIvoCondition, VS4TARInvoice.TIvoConditionDay, VS4TARInvoice.TIvoCondition1, VS4TARInvoice.TIvoConditionDay1, VS4TARInvoice.TIvoPaymentNote, VS4TARInvoice.TIvoStatementNote, VS4TARInvoice.TIvoTShpCode, VS4TARInvoice.TIvoDeliveryNote, VS4TARInvoice.TIvoPackingNote, VS4TARInvoice.TIvoCustom1, VS4TARInvoice.TIvoCustom2, VS4TARInvoice.TIvoCustom3, VS4TARInvoice.TIvoCustom4, VS4TARInvoice.TIvoCustom5, VS4TARInvoice.TIvoCustom6, VS4TARInvoice.TIvoCartonName, VS4TARInvoice.TIvoTotalCarton, VS4TARInvoice.TIvoTotalNW, VS4TARInvoice.TIvoTotalGW, VS4TARInvoice.TIvoDayAvailable, VS4TARInvoice.TIvoDescription, VS4TARInvoice.TIvoTSOTCode, VS4TARInvoice.TIvoDeliveryStatus, VS4TARInvoice.TIvoBillStatus, VS4TARInvoice.TIvoEditCode, VS4TARInvoice.TIvoEditBy, VS4TARInvoice.TIvoEditDate, VS4TARInvoice.TIvoConfirmBy, VS4TARInvoice.TIvoApproveStatus, VS4TARInvoice.TIvoApproveBy, VS4TARInvoice.TIvoApproveDate, VS4TARInvoice.TIvoRevision, VS4TARInvoice.TIvoCancelStatus, VS4TARInvoice.TIvoCancelDate, VS4TARInvoice.TIvoFlag1, VS4TARInvoice.TIvoTRouCode, VS4TARInvoice.TIvoCustomNo, VS4TARInvoice.TIvoCustomDate, VS4TARInvoice.TIvoPMCostTotal, VS4TARInvoice.TIvoTOTNLn, VS4TARInvoice.TIvoDeliveryCond, VS4TARInvoice.TIvoLoadingDate, VS4TARInvoice.TIvoStartAgingDate, VS4TARInvoice.TIvoIgnoreArrears, VS4TARInvoice.TIvoBoxList, VS4TARInvoice.TIvoExchangeRate2, VS4TARInvoice.TIvoNote, VS4TARInvoice.TIvoTotalQuantity, VS4TARInvoice.TIvoTPOSCode, VS4TARInvoice.TIvoReceiptStatus, VS4TARInvoice.TIvoManualArrear, VS4TARInvoice.TIvoCardStatus, VS4TARInvoice.TIvoRefNo3, VS4TARInvoice.TIvoTARWCode, VS4TARInvoiceMB.TIoMTIvoNo, VS4TARInvoiceMB.TIoMLn, VS4TARInvoiceMB.TIoMType, VS4TARInvoiceMB.TIoMGroupName, VS4TARInvoiceMB.TIoMJobCode, VS4TARInvoiceMB.TIoMTOInCode, VS4TARInvoiceMB.TIoMTPOSCode, VS4TARInvoiceMB.TIoMSerialNo, VS4TARInvoiceMB.TIoMCustom1, VS4TARInvoiceMB.TIoMCustom2, VS4TARInvoiceMB.TIoMCustom3, VS4TARInvoiceMB.TIoMCustom4, VS4TARInvoiceMB.TIoMCustom5, VS4TARInvoiceMB.TIoMShippingMark, VS4TARInvoiceMB.TIoMPOSCode, VS4TARInvoiceMB.TIoMFactoryCode, VS4TARInvoiceMB.TIoMPOSName, VS4TARInvoiceMB.TIoMCost, VS4TARInvoiceMB.TIoMPrice, VS4TARInvoiceMB.TIoMPerQuantity, VS4TARInvoiceMB.TIoMUnitFactor, VS4TARInvoiceMB.TIoMAcceptError, VS4TARInvoiceMB.TIoMUnitCalc, VS4TARInvoiceMB.TIoMQuantityCalc, VS4TARInvoiceMB.TIoMQuantityText, VS4TARInvoiceMB.TIoMQuantity, VS4TARInvoiceMB.TIoMTUntCode, VS4TARInvoiceMB.TIoMQuantity2, VS4TARInvoiceMB.TIoMTUntCode2, VS4TARInvoiceMB.TIoMQuantity3, VS4TARInvoiceMB.TIoMTUntCode3, VS4TARInvoiceMB.TIoMCostAmount, VS4TARInvoiceMB.TIoMAmount, VS4TARInvoiceMB.TIoMDiscountText, VS4TARInvoiceMB.TIoMDiscountTotal, VS4TARInvoiceMB.TIoMNetAmount, VS4TARInvoiceMB.TIoMTaxType, VS4TARInvoiceMB.TIoMTaxBase, VS4TARInvoiceMB.TIoMWTAXBase, VS4TARInvoiceMB.TIoMAmountVAT, VS4TARInvoiceMB.TIoMAmountWTAX, VS4TARInvoiceMB.TIoMPromotionType, VS4TARInvoiceMB.TIoMFreeCode, VS4TARInvoiceMB.TIoMIsPremium, VS4TARInvoiceMB.TIoMDescription, VS4TARInvoiceMB.TIoMSourceNo, VS4TARInvoiceMB.TIoMSourceLn, VS4TARInvoiceMB.TIoMSourceDate, VS4TARInvoiceMB.TIoMTLctCode, VS4TARInvoiceMB.TIoMQuantityStock, VS4TARInvoiceMB.TIoMAVGWeighting, VS4TARInvoiceMB.TIoMDiscountBill, VS4TARInvoiceMB.TIoMDeposit, VS4TARInvoiceMB.TIoMTARWCode, VS4TCountry.TCouName, VS4TAR.TARNAddressBill, VS4TAR.TARNName, VS4TAR2.TAR2TPrvCode, VS4TProvince.TPrvName, VS4TARGroup.TARGName, VS4TSaleArea.TSAeName, VS4TAR.TARNTARGCode, VS4TAR.TARNTBsTCode, VS4TAR.TARNTSAeCode, VS4TBranch.TBraName, VS4TAR2.TAR2SaleCode, VS4TProduct.TPdtTransferCode, VS4TProduct.TPdtName, VS4TProduct.TPdtDescription, VS4TProduct.TPdtName2, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtTPSECode, VS4TProduct.TPdtTPG1Code, VS4TProduct.TPdtStandardCost, VS4TProduct.TPdtTPS2Code, VS4TProductSec2.TPS2Name, VS4TProductGroup1.TPG1Name, VS4TProduct.TPdtTPG2Code, VS4TAR2.TAR2Marks, VS4TProductSection.TPSEName, VS4TProduct.TPdtTAPNCode, VS4TProduct.TPdtCustom1, VS4TProduct.TPdtCustom2, VS4TProduct.TPdtCustom3, VS4TProduct.TPdtCustom4, VS4TProduct.TPdtCustom5, VS4TBranch.TBraAddressBill, VS4TProduct.TPdtTPTTCode, VS4TShipping.TSHPName, VS4TAR.TARNPhone, VS4TARHolder.TARHName, VS4TProduct.TPdtFactoryCode, VS4TProduct.TPdtTUntCode, VS4TAR.TARNName2, VS4TAR.TARNAddressBill2, VS4TAR.TARNFax, VS4TProduct.TPdtAliasSlip, VS4TProduct.TPdtOldCode, VS4TSOMB.TSOBSourceNo, VS4TAR2.TAR2DeliveryCond, VS4TARInvoiceMB.TIoMTRCACode, VS4TARInvoiceMB.TIoMFlag1, VS4TARInvoice.TIvoCreateBy, VS4TProject.TPrjName, VS4TProduct.TPdtBarcode, VS4TARInvoiceMB.TIoMStockFlag, VS4TARInvoiceMB.TIoMMinimumOrder, VS4TARInvoiceMB.TIoMWelfareRate, VS4TARInvoice.TIvoFlag2, VS4TARInvoiceMB.TIoMTPltCode, VS4TARInvoice.TIvoInvoiceStatus, VS4TARInvoice2.TIv2TSDVNo, VS4TARInvoice2.TIv2LogisticType, VS4TARInvoice2.TIv2TruckNo, VS4TARInvoice2.TIv2BLNo, VS4TARInvoice2.TIv2ILCNo, VS4TARInvoice2.TIv2IDC, VS4TARInvoice2.TIv2Vessel, VS4TARInvoice2.TIv2ShipDate, VS4TARInvoiceMB.TIoMPOSName2, VS4TARInvoiceMB.TIoMQuantityBase FROM VS4TSaleZone RIGHT JOIN (((((VS4TAR LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) LEFT JOIN (((VS4TAR2 LEFT JOIN VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode) LEFT JOIN VS4TShipping ON VS4TAR2.TAR2TShpCode = VS4TShipping.TSHPCode) LEFT JOIN VS4TARHolder ON VS4TAR2.TAR2SaleCode = VS4TARHolder.TARHCode) 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) INNER JOIN VS4TARInvoice2 ON VS4TARInvoice.TIvoNo = VS4TARInvoice2.TIv2TIvoNo) ON VS4TAR.TARNCode = VS4TARInvoice.TIvoTARNCode) 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) LEFT JOIN VS4TProduct3 ON VS4TProduct.TPdtCode = VS4TProduct3.TPD3TPdtCode) LEFT JOIN VS4TSOMB ON (VS4TARInvoiceMB.TIoMSourceLn = VS4TSOMB.TSOBLn) AND (VS4TARInvoiceMB.TIoMSourceNo = VS4TSOMB.TSOBTSODNo)) LEFT JOIN VS4TARWelfare ON VS4TARInvoiceMB.TIoMTARWCode = VS4TARWelfare.TARWCode) ON VS4TARInvoice.TIvoNo = VS4TARInvoiceMB.TIoMTIvoNo) ON VS4TSaleZone.TSZnCode = VS4TSaleArea.TSaeTSZnCode
GO

CREATE VIEW VS4VDeliveryOut AS  SELECT VS4TDeliveryOut.*, VS4TARInvoice.TIvoNo, VS4TARInvoice.TIvoBalanceFlag, VS4TARInvoice.TIvoType, VS4TARInvoice.TIvoTRBKCode, VS4TARInvoice.TIvoTRCACode, VS4TARInvoice.TIvoMode, VS4TARInvoice.TIvoDate, VS4TARInvoice.TIvoStockCard, VS4TARInvoice.TIvoDueDate, VS4TARInvoice.TIvoGLMethod, VS4TARInvoice.TIvoTGLTNo, VS4TARInvoice.TIvoTaxNo, VS4TARInvoice.TIvoRefNo, VS4TARInvoice.TIvoRefDate, VS4TARInvoice.TIvoRefNo2, VS4TARInvoice.TIvoRefDate2, VS4TARInvoice.TIvoPONo, VS4TARInvoice.TIvoSOCode, VS4TARInvoice.TIvoJobCode, VS4TARInvoice.TIvoTJobNo, VS4TARInvoice.TIvoTJbMLn, VS4TARInvoice.TIvoTPrjCode, VS4TARInvoice.TIvoTBraCode, VS4TARInvoice.TIvoTEmpCode, VS4TARInvoice.TIvoSaleName, VS4TARInvoice.TIvoDeliveryDate, VS4TARInvoice.TIvoDeliveryTo, VS4TARInvoice.TIvoTARNCode, VS4TARInvoice.TIvoTARDCode, VS4TARInvoice.TIvoContactNote, VS4TARInvoice.TIvoContactName, VS4TARInvoice.TIvoCustomerName, VS4TARInvoice.TIvoCusAddress, VS4TARInvoice.TIvoCustomerName2, VS4TARInvoice.TIvoCusAddress2, VS4TARInvoice.TIvoConsignee, VS4TARInvoice.TIvoNotifyParty, VS4TARInvoice.TIvoCostTotal, VS4TARInvoice.TIvoPriceChannel, VS4TARInvoice.TIvoDiscountList, VS4TARInvoice.TIvoSubTotal, VS4TARInvoice.TIvoDiscountText, VS4TARInvoice.TIvoDiscountTotal, VS4TARInvoice.TIvoNetTotal, VS4TARInvoice.TIvoDepositText, VS4TARInvoice.TIvoDeposit, VS4TARInvoice.TIvoTotal, VS4TARInvoice.TIvoTotalFOB, VS4TARInvoice.TIvoTCurCode, VS4TARInvoice.TIvoExchangeRate, VS4TARInvoice.TIvoTotalInRate, VS4TARInvoice.TIvoVATType, VS4TARInvoice.TIvoVATRate, VS4TARInvoice.TIvoTaxBase, VS4TARInvoice.TIvoVATTotal, VS4TARInvoice.TIvoGrandTotal, VS4TARInvoice.TIvoNOTAXTotal, VS4TARInvoice.TIvoWTaxBase, VS4TARInvoice.TIvoWTaxRate, VS4TARInvoice.TIvoWTaxTotal, VS4TARInvoice.TIvoNetPayment, VS4TARInvoice.TIvoBaseArrears, VS4TARInvoice.TIvoArrears, VS4TARInvoice.TIvoAdjustTotal, VS4TARInvoice.TIvoBaseAvailable, VS4TARInvoice.TIvoAvailable, VS4TARInvoice.TIvoRewardTotal, VS4TARInvoice.TIvoPremiumTotal, VS4TARInvoice.TIvoCommissionBase, VS4TARInvoice.TIvoCommissionRate, VS4TARInvoice.TIvoCommission, VS4TARInvoice.TIvoBaseIncoType, VS4TARInvoice.TIvoIncoType, VS4TARInvoice.TIvoIncoTerms, VS4TARInvoice.TIvoOtherFee, VS4TARInvoice.TIvoTransportFee, VS4TARInvoice.TIvoHandlingFee, VS4TARInvoice.TIvoFreightFee, VS4TARInvoice.TIvoInsurance, VS4TARInvoice.TIvoTransportDesc, VS4TARInvoice.TIvoDuty, VS4TARInvoice.TIvoShipBy, VS4TARInvoice.TIvoCountryOrigin, VS4TARInvoice.TIvoDestination, VS4TARInvoice.TIvoCondition, VS4TARInvoice.TIvoConditionDay, VS4TARInvoice.TIvoCondition1, VS4TARInvoice.TIvoConditionDay1, VS4TARInvoice.TIvoPaymentNote, VS4TARInvoice.TIvoStatementNote, VS4TARInvoice.TIvoTShpCode, VS4TARInvoice.TIvoDeliveryNote, VS4TARInvoice.TIvoPackingNote, VS4TARInvoice.TIvoCustom1, VS4TARInvoice.TIvoCustom2, VS4TARInvoice.TIvoCustom3, VS4TARInvoice.TIvoCustom4, VS4TARInvoice.TIvoCustom5, VS4TARInvoice.TIvoCustom6, VS4TARInvoice.TIvoCartonName, VS4TARInvoice.TIvoTotalCarton, VS4TARInvoice.TIvoTotalNW, VS4TARInvoice.TIvoTotalGW, VS4TARInvoice.TIvoDayAvailable, VS4TARInvoice.TIvoDescription, VS4TARInvoice.TIvoTSOTCode, VS4TARInvoice.TIvoDeliveryStatus, VS4TARInvoice.TIvoBillStatus, VS4TARInvoice.TIvoCardFlag, VS4TARInvoice.TIvoTaxFlag, VS4TARInvoice.TIvoCreateBy, VS4TARInvoice.TIvoCreateDate, VS4TARInvoice.TIvoEditCode, VS4TARInvoice.TIvoEditBy, VS4TARInvoice.TIvoEditDate, VS4TARInvoice.TIvoConfirmStatus, VS4TARInvoice.TIvoConfirmBy, VS4TARInvoice.TIvoConfirmDate, VS4TARInvoice.TIvoApproveStatus, VS4TARInvoice.TIvoApproveBy, VS4TARInvoice.TIvoApproveDate, VS4TARInvoice.TIvoApproveNote, VS4TARInvoice.TIvoRevision, VS4TARInvoice.TIvoCancelNote, VS4TARInvoice.TIvoFlag1, VS4TARInvoice.TIvoTRouCode, VS4TARInvoice.TIvoCustomNo, VS4TARInvoice.TIvoCustomDate, VS4TARInvoice.TIvoPMCostTotal, VS4TARInvoice.TIvoTOTNLn, VS4TARInvoice.TIvoDeliveryCond, VS4TARInvoice.TIvoLoadingDate, VS4TARInvoice.TIvoStartAgingDate, VS4TARInvoice.TIvoIgnoreArrears, VS4TARInvoice.TIvoBoxList, VS4TARInvoice.TIvoExchangeRate2, VS4TARInvoice.TIvoNote, VS4TARInvoice.TIvoTotalQuantity, VS4TARInvoice.TIvoTPOSCode, VS4TARInvoice.TIvoReceiptStatus, VS4TARInvoice.TIvoManualArrear, VS4TARInvoice.TIvoCardStatus, VS4TARInvoice.TIvoRefNo3, VS4TARInvoice.TIvoTARWCode, VS4TARInvoice.TIvoTotalVolumeM, VS4TARInvoice.TIvoRefNo4, VS4TARInvoice.TIvoLastPayDate, VS4TARInvoice.TIvoInvoiceStatus, VS4TARInvoice.TIvoCNStatus, VS4TARInvoice.TIvoClientTaxNo, VS4TARInvoice.TIvoBranchCode, VS4TARInvoice.TIvoBranchName, VS4TARInvoiceMB.TIoMTIvoNo, VS4TARInvoiceMB.TIoMLn, VS4TARInvoiceMB.TIoMType, VS4TARInvoiceMB.TIoMGroupName, VS4TARInvoiceMB.TIoMJobCode, VS4TARInvoiceMB.TIoMTOInCode, VS4TARInvoiceMB.TIoMTPOSCode, VS4TARInvoiceMB.TIoMSerialNo, VS4TARInvoiceMB.TIoMCustom1, VS4TARInvoiceMB.TIoMCustom2, VS4TARInvoiceMB.TIoMCustom3, VS4TARInvoiceMB.TIoMCustom4, VS4TARInvoiceMB.TIoMCustom5, VS4TARInvoiceMB.TIoMShippingMark, VS4TARInvoiceMB.TIoMPOSCode, VS4TARInvoiceMB.TIoMFactoryCode, VS4TARInvoiceMB.TIoMPOSName, VS4TARInvoiceMB.TIoMCost, VS4TARInvoiceMB.TIoMPrice, VS4TARInvoiceMB.TIoMPerQuantity, VS4TARInvoiceMB.TIoMUnitFactor, VS4TARInvoiceMB.TIoMAcceptError, VS4TARInvoiceMB.TIoMUnitCalc, VS4TARInvoiceMB.TIoMQuantityCalc, VS4TARInvoiceMB.TIoMQuantityText, VS4TARInvoiceMB.TIoMQuantity, VS4TARInvoiceMB.TIoMTUntCode, VS4TARInvoiceMB.TIoMQuantity2, VS4TARInvoiceMB.TIoMTUntCode2, VS4TARInvoiceMB.TIoMQuantity3, VS4TARInvoiceMB.TIoMTUntCode3, VS4TARInvoiceMB.TIoMCostAmount, VS4TARInvoiceMB.TIoMAmount, VS4TARInvoiceMB.TIoMDiscountText, VS4TARInvoiceMB.TIoMDiscountTotal, VS4TARInvoiceMB.TIoMNetAmount, VS4TARInvoiceMB.TIoMTaxType, VS4TARInvoiceMB.TIoMTaxBase, VS4TARInvoiceMB.TIoMWTAXBase, VS4TARInvoiceMB.TIoMAmountVAT, VS4TARInvoiceMB.TIoMAmountWTAX, VS4TARInvoiceMB.TIoMPromotionType, VS4TARInvoiceMB.TIoMFreeCode, VS4TARInvoiceMB.TIoMIsPremium, VS4TARInvoiceMB.TIoMDescription, VS4TARInvoiceMB.TIoMSourceNo, VS4TARInvoiceMB.TIoMSourceLn, VS4TARInvoiceMB.TIoMSourceDate, VS4TARInvoiceMB.TIoMTLctCode, VS4TARInvoiceMB.TIoMCommissionBase, VS4TARInvoiceMB.TIoMCommissionRate, VS4TARInvoiceMB.TIoMCommission, VS4TARInvoiceMB.TIoMPremiumCost, VS4TARInvoiceMB.TIoMQuantityStock, VS4TARInvoiceMB.TIoMAVGWeighting, VS4TARInvoiceMB.TIoMDiscountBill, VS4TARInvoiceMB.TIoMDeposit, VS4TARInvoiceMB.TIoMTARWCode, VS4TARInvoiceMB.TIoMTRCACode, VS4TARInvoiceMB.TIoMStockFlag, VS4TARInvoiceMB.TIoMMinimumOrder, VS4TDeliveryOutMB.TDOMTDCONo, VS4TDeliveryOutMB.TDOMLn, VS4TDeliveryOutMB.TDOMType, VS4TDeliveryOutMB.TDOMTIoMTIvoNo, VS4TDeliveryOutMB.TDOMTIoMLn, VS4TDeliveryOutMB.TDOMDutyAmount FROM VS4TARInvoice RIGHT JOIN (VS4TDeliveryOut INNER JOIN (VS4TARInvoiceMB RIGHT JOIN VS4TDeliveryOutMB ON (VS4TARInvoiceMB.TIoMTIvoNo = VS4TDeliveryOutMB.TDOMTIoMTIvoNo) AND (VS4TARInvoiceMB.TIoMLn = VS4TDeliveryOutMB.TDOMTIoMLn)) ON VS4TDeliveryOut.TDCONo = VS4TDeliveryOutMB.TDOMTDCONo) 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, VS4TDOMBDetail.*, VS4TShipping.TSHPName, VS4TShipping_1.TSHPName AS VDODFirstShipName, VS4TARInvoice.TIvoDeliveryTo, VS4TARInvoice.TIvoDeliveryNote, VS4TARInvoice.TIvoPackingNote, VS4TARInvoice.TIvoDeliveryCond, VS4TARInvoice.TIvoTShpCode, VS4TARInvoice.TIvoTRouCode, VS4TARInvoice.TIvoBoxList, VS4TProduct.TPdtAliasSlip, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtTPSECode, VS4TProductLine.TPdLName, VS4TProductSection.TPSEName, VS4TARInvoice.TIvoRefNo2, VS4TARInvoice.TIvoRefNo3, VS4TProductSection.TPSEName2 FROM VS4TProductSection RIGHT JOIN (VS4TProductLine RIGHT JOIN (((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.TIoMLn = VS4TDOMBDetail.TDMDTIoMLn) AND (VS4TARInvoiceMB.TIoMTIvoNo = VS4TDOMBDetail.TDMDTIoMTIvoNo)) LEFT JOIN VS4TProduct ON VS4TARInvoiceMB.TIoMTPOSCode = VS4TProduct.TPdtCode) ON VS4TARInvoice.TIvoNo = VS4TARInvoiceMB.TIoMTIvoNo) ON VS4TDO.TPdyNo = VS4TDOMB.TDymTPdyNo) ON VS4TProductLine.TPdLCode = VS4TProduct.TPdtTPDLCode) ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode
GO

CREATE VIEW VS4VDOBaseQty 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, VS4TDOMBDetail.*, VS4TShipping.TSHPName, VS4TShipping_1.TSHPName AS VDODFirstShipName, VS4TARInvoice.TIvoDeliveryTo, VS4TARInvoice.TIvoDeliveryNote, VS4TARInvoice.TIvoPackingNote, VS4TARInvoice.TIvoDeliveryCond, VS4TARInvoice.TIvoTShpCode, VS4TARInvoice.TIvoTRouCode, VS4TARInvoice.TIvoBoxList, VS4TProduct.TPdtTUntCode, (TIoMUnitFactor*TIoMQuantity) AS VDOBQuantityBase FROM VS4TProduct RIGHT JOIN (((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)) LEFT JOIN VS4TPOSMB ON VS4TARInvoiceMB.TIoMTPOSCode = VS4TPOSMB.TPoMTPOSCode) ON VS4TARInvoice.TIvoNo = VS4TARInvoiceMB.TIoMTIvoNo) ON VS4TDO.TPdyNo = VS4TDOMB.TDymTPdyNo) ON VS4TProduct.TPdtCode = VS4TPOSMB.TPoMTPdtCode
GO

CREATE VIEW VS4VDOBOX AS  SELECT VS4TDO.*, VS4TDOMB.*, VS4TARInvoice.TIvoNo, VS4TARInvoice.TIvoDate, VS4TARInvoice.TIvoContactNote, VS4TARInvoice.TIvoContactName, VS4TARInvoice.TIvoCustomerName, VS4TARInvoice.TIvoCusAddress, VS4TARInvoice.TIvoTARNCode, VS4TARInvoice.TIvoSubTotal, VS4TARInvoice.TIvoVATTotal, VS4TARInvoice.TIvoGrandTotal, VS4TShipping.TSHPName, VS4TShipping_1.TSHPName AS VDODFirstShipName, VS4TARInvoice.TIvoDeliveryTo, VS4TARInvoice.TIvoDeliveryNote, VS4TARInvoice.TIvoPackingNote, VS4TARInvoice.TIvoDeliveryCond, VS4TARInvoice.TIvoTShpCode, VS4TARInvoice.TIvoTRouCode, VS4TDOBoxSet.TDBSNo, VS4TDOBoxSet.TDBSQuantity, VS4TDOBoxSet.TDBSDeliveryTo, VS4TDOBoxSet.TDBSNote, VS4TARInvoice.TIvoBoxList FROM ((VS4TDO LEFT JOIN VS4TProject ON VS4TDO.TPdyTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TShipping AS VS4TShipping_1 ON VS4TDO.TPdyTShpCode = VS4TShipping_1.TSHPCode) INNER JOIN (VS4TDOBoxSet RIGHT JOIN (((VS4TDOMB LEFT JOIN VS4TARInvoice ON VS4TDOMB.TDymDocNo = VS4TARInvoice.TIvoNo) LEFT JOIN VS4TShipping ON VS4TDOMB.TDymTShpCode = VS4TShipping.TSHPCode) LEFT JOIN VS4TDOBoxSetMB ON VS4TARInvoice.TIvoNo = VS4TDOBoxSetMB.TDSMDocNo) ON VS4TDOBoxSet.TDBSNo = VS4TDOBoxSetMB.TDSMTDBSNo) ON VS4TDO.TPdyNo = VS4TDOMB.TDymTPdyNo
GO

CREATE VIEW VS4VDOBOXSet AS  SELECT VS4TDOBoxSet.*, VS4TDOBoxSetNo.*, VS4TDOBoxSetMB.*, VS4TARInvoice.*, VS4TShipping.TSHPName, VS4TAP.TAPNPhone, VS4TAR.TARNPhone, VS4TDOMB.TDymTPdyNo FROM (VS4TDOBoxSet LEFT JOIN (VS4TAR RIGHT JOIN ((((VS4TDOBoxSetMB LEFT JOIN VS4TARInvoice ON VS4TDOBoxSetMB.TDSMDocNo = VS4TARInvoice.TIvoNo) LEFT JOIN VS4TShipping ON VS4TDOBoxSetMB.TDSMTShpCode = VS4TShipping.TSHPCode) LEFT JOIN VS4TAP ON VS4TDOBoxSetMB.TDSMTShpCode = VS4TAP.TAPNCode) LEFT JOIN VS4TDOMB ON VS4TARInvoice.TIvoNo = VS4TDOMB.TDymDocNo) ON VS4TAR.TARNCode = VS4TARInvoice.TIvoTARNCode) ON VS4TDOBoxSet.TDBSNo = VS4TDOBoxSetMB.TDSMTDBSNo) LEFT JOIN VS4TDOBoxSetNo ON VS4TDOBoxSet.TDBSNo = VS4TDOBoxSetNo.TDSNTDBSNo
GO

CREATE VIEW VS4VInventStock AS SELECT        VS4TInventory.TInvNo, VS4TInventory.TInvMode, VS4TInventory.TInvTIBkCode, VS4TInventory.TInvDate, VS4TInventory.TInvInvoiceStatus, VS4TInventory.TInvTARNCode,                           VS4TInventory.TInvTInTAlias, VS4TInventory.TInvRefNo, VS4TInventory.TInvRefDate, VS4TInventory.TInvRefNo2, VS4TInventory.TInvRefDate2, VS4TInventory.TInvRefNo3,                           VS4TInventory.TInvRefDate3, VS4TInventory.TInvCustom1, VS4TInventory.TInvCustom2, VS4TInventory.TInvCustom3, VS4TInventory.TInvCustom4, VS4TInventory.TInvCustom5,                           VS4TInventory.TInvTPrjCode, VS4TInventory.TInvTJobNo, VS4TInventory.TInvTJbMLn, VS4TInventory.TInvTMPSNo, VS4TInventory.TInvTJPdNo, VS4TInventory.TInvTJPMLn,                           VS4TInventory.TInvTSecCode, VS4TInventory.TInvTDepCode, VS4TInventory.TInvTDivCode, VS4TInventory.TInvTBraCode, VS4TInventory.TInvFromTBraCode, VS4TInventory.TInvTotal,                           VS4TInventory.TInvTotalRecord, VS4TInventory.TInvTotalQuantity, VS4TInventory.TInvRequestCode, VS4TInventory.TInvRequestBy, VS4TInventory.TInvDescription, VS4TInventory.TInvGLMethod,                           VS4TInventory.TInvTGLTNo, VS4TInventory.TInvDeliveryStatus, VS4TInventory.TInvSpecialFlag, VS4TInventory.TInvIsCompleted, VS4TInventory.TInvCreateCode, VS4TInventory.TInvCreateBy,                           VS4TInventory.TInvCreateDate, VS4TInventory.TInvEditCode, VS4TInventory.TInvEditBy, VS4TInventory.TInvEditDate, VS4TInventory.TInvConfirmStatus, VS4TInventory.TInvConfirmBy,                           VS4TInventory.TInvConfirmDate, VS4TInventory.TInvApproveStatus, VS4TInventory.TInvApproveBy, VS4TInventory.TInvApproveDate, VS4TInventory.TInvApproveNote, VS4TInventory.TInvRevision,                           VS4TInventory.TInvCancelStatus, VS4TInventory.TInvCancelNo, VS4TInventory.TInvCancelBy, VS4TInventory.TInvCancelDate, VS4TInventory.TInvCancelNote, VS4TInventory.TInvFlag1,                           VS4TInventory.TInvFlag2, VS4TInventory.TInvFlag3, VS4TInventory.TInvCustomNo, VS4TInventory.TInvCustomDate, VS4TInventory.TInvTotalScrap, VS4TInventory.TInvTotalQScrap,                           VS4TInventory.TInvTotalQInput, VS4TInventory.TInvTotalAInput, VS4TInventory.TInvTotalRecordIn, VS4TInventory.TInvTotalPCScrap, VS4TInventory.TInvTotalPCQScrap, VS4TInventory.TInvSourceType,                           VS4TInventory.TInvRefNo4, VS4TInventory.TInvRefLn, VS4TInventory.TInvTJStLn, VS4TInventory.TInvStockCard, VS4TInventory.TInvCustomRate, VS4TInventoryMB.TInMTInvNo,                           VS4TInventoryMB.TInMLn, VS4TInventoryMB.TInMTACPTACYID, VS4TInventoryMB.TInMTACPID, VS4TInventoryMB.TInMTPdtCode, VS4TInventoryMB.TInMCustom1, VS4TInventoryMB.TInMSerialNo,                           VS4TInventoryMB.TInMLotNo, VS4TInventoryMB.TInMLotDate, VS4TInventoryMB.TInMScrapLevel, VS4TInventoryMB.TInMQuantityCalc, VS4TInventoryMB.TInMUnitRatio,                           VS4TInventoryMB.TInMQuantityBase, VS4TInventoryMB.TInMTUntCode, VS4TInventoryMB.TInMInQuantity, VS4TInventoryMB.TInMOutQuantity, VS4TInventoryMB.TInMAmouQuantity,                           VS4TInventoryMB.TInMAmouQuantity2, VS4TInventoryMB.TInMAmouQuantity3, VS4TInventoryMB.TInMAmount, VS4TInventoryMB.TInMStatus, VS4TInventoryMB.TInMFromTLctCode,                           VS4TInventoryMB.TInMTLctCode, VS4TInventoryMB.TInMDescription, VS4TInventoryMB.TInMTInTAlias, VS4TInventoryMB.TInMTSODNo, VS4TInventoryMB.TInMTSOBLn,                           VS4TInventoryMB.TInMTMDSLn, VS4TInventoryMB.TInMSourceType, VS4TInventoryMB.TInMSourceNo, VS4TInventoryMB.TInMSourceLn, VS4TInventoryMB.TInMQuantityText,                           VS4TInventoryMB.TInMQuantityCutTxt, VS4TInventoryMB.TInMQuantityCut, VS4TInventoryMB.TInMQuantityFirst, VS4TInventoryMB.TInMArrear, VS4TInventoryMB.TInMShow,                           VS4TInventoryMB.TInMAgentPrice, VS4TInventoryMB.TInMQAStatus, VS4TInventoryMB.TInMQANote, VS4TInventoryMB.TInMTPltCode, VS4TInventoryMB.TInMFromTPltCode,                           VS4TInventoryMB.TInMQuantityCost, VS4TInventoryMB.TInMAgentPrice2, VS4TInventoryMB.TInMAgentPrice3, VS4TInventoryMB.TInMTIvsCode, VS4TInventoryMB.TInMFromTIvsCode,                           VS4TWarehouse.TWahName, VS4TLocation.TLctName, VS4TProject.TPrjName, 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, 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.TPdtTPCTAlias,                           VS4TProduct.TPdtSlowDay, VS4TProduct.TPdtDeadDay, VS4TProduct.TPdtSerialType, VS4TProduct.TPdtOrderPoint, VS4TProduct.TPdtTAPNCode, VS4TProduct.TPdtPurchaseFee,                           VS4TProduct.TPdtFactoryCode, 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.TIMCPKI, VS4TInventoryLOT.TIMCBarcode, VS4TInventoryLOT.TIMCRFID, VS4TInventoryLOT.TIMCQuantityCost, VS4TInventoryLOT.TIMCInputTCurCode,                           VS4TInventoryLOT.TIMCInputCostRate, VS4TInventoryLOT.TIMCAdjustCost, VS4TInventoryLOT.TIMCStandardCost, VS4TInventoryLOT.TIMCAVGCost, VS4TInventoryLOT.TIMCEmbUnitDMVAR,                           VS4TInventoryLOT.TIMCEmbUnitDLVAR, VS4TInventoryLOT.TIMCUnitDMVariance, VS4TInventoryLOT.TIMCUnitDLVariance, VS4TInventoryLOT.TIMCEmbUnitOHVAR, VS4TInventoryLOT.TIMCUnitOHVariance,                           VS4TInventoryLOT.TIMCDutyAmount, VS4TInventoryLOT.TIMCCOA, VS4TInventoryLOT.TIMCProposeStatus, VS4TInventoryLOT.TIMCProposeNote, VS4TInventoryLOT.TIMCUnitRatioC,                           VS4TInventoryLOT.TIMCquantityCalc, VS4TInventoryLOT.TIMCDiscountText, VS4TInventoryLOT.TIMCDiscountTotal, VS4TInventoryLOT.TIMCTIvsCode, VS4TInventoryLOT.TIMCPrice,                           VS4TInventoryLOT.TIMCLastDate AS VLSBLastDate, VS4TWarehouse.TWahCode, VS4TPOS.TPOSPackAlias2, VS4TProduct.TPdtDescription, VS4TWarehouse.TWahGroup, VS4TProduct.TPdtTPG4Code,                           VS4TProductGroup4.TPG4Name, VS4TInventoryLOT.TIMCVATRate, VS4TInventoryLOT.TIMCVATAmount, VS4TPOS.TPOSPackAlias1, VS4TInventory_1.TInvRefNo2 AS VInvREfNo2,                           VS4TInventory_1.TInvRefNo3 AS VInvREfNo3 FROM            VS4TUnit RIGHT OUTER JOIN                          VS4TInventoryType INNER JOIN                          VS4TProduct LEFT OUTER JOIN                          VS4TProductType ON VS4TProduct.TPdtTPTTCode = VS4TProductType.TPTTCode LEFT OUTER JOIN                          VS4TProductLine ON VS4TProduct.TPdtTPDLCode = VS4TProductLine.TPdLCode LEFT OUTER JOIN                          VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode LEFT OUTER JOIN                          VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code LEFT OUTER JOIN                          VS4TProductSec3 ON VS4TProduct.TPdtTPS3Code = VS4TProductSec3.TPS3Code LEFT OUTER JOIN                          VS4TProductSec4 ON VS4TProduct.TPdtTPS4Code = VS4TProductSec4.TPS4Code LEFT OUTER JOIN                          VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code LEFT OUTER JOIN                          VS4TProductGroup2 ON VS4TProduct.TPdtTPG2Code = VS4TProductGroup2.TPG2Name LEFT OUTER JOIN                          VS4TProductGroup3 ON VS4TProduct.TPdtTPG3Code = VS4TProductGroup3.TPG3Code LEFT OUTER JOIN                          VS4TProductGroup4 ON VS4TProduct.TPdtTPG4Code = VS4TProductGroup4.TPG4Code LEFT OUTER JOIN                          VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode INNER JOIN                          VS4TInventory LEFT OUTER JOIN                          VS4TProject ON VS4TInventory.TInvTPrjCode = VS4TProject.TPrjCode LEFT OUTER JOIN                          VS4TBranch ON VS4TInventory.TInvTBraCode = VS4TBranch.TBraCode LEFT OUTER JOIN                          VS4TDivision ON VS4TInventory.TInvTDivCode = VS4TDivision.TDivCode LEFT OUTER JOIN                          VS4TDepartment ON VS4TInventory.TInvTDepCode = VS4TDepartment.TDepCode LEFT OUTER JOIN                          VS4TSection ON VS4TInventory.TInvTSecCode = VS4TSection.TSecCode INNER JOIN                          VS4TInventoryMB LEFT OUTER JOIN                          VS4TLocation ON VS4TInventoryMB.TInMTLctCode = VS4TLocation.TLctCode LEFT OUTER JOIN                          VS4TWarehouse ON VS4TLocation.TLctTWahCode = VS4TWarehouse.TWahCode LEFT OUTER 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 AND                           VS4TProduct.TPdtLastBalDate <= VS4TInventory.TInvDate ON VS4TInventoryType.TInTAlias = VS4TInventory.TInvTInTAlias ON VS4TUnit.TUntCode = VS4TProduct.TPdtTUntCode LEFT OUTER JOIN                          VS4TInventory AS VS4TInventory_1 ON VS4TInventoryLOT.TIMCReceiveNo = VS4TInventory_1.TInvNo WHERE        (VS4TInventoryMB.TInMStatus = 1) AND (1 = 1) AND (VS4TInventory.TInvApproveStatus = 1) AND (VS4TInventory.TInvCancelStatus = 0)
GO

CREATE VIEW VS4VDOMB AS  SELECT VS4TDO.*, VS4TDOMB.*, VS4TRoute.*, VS4TShipping.* FROM (VS4TDO INNER JOIN (VS4TDOMB LEFT JOIN VS4TRoute ON VS4TDOMB.TDymTRouCode = VS4TRoute.TRouCode) ON VS4TDO.TPdyNo = VS4TDOMB.TDymTPdyNo) LEFT JOIN VS4TShipping ON VS4TDOMB.TDymTShpCode = VS4TShipping.TSHPCode
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 VS4VStockWH AS  SELECT Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtName2, 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.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, 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, Vs4VInventStock.TWahGroup, Vs4VInventStock.TIMCQAStatus FROM Vs4VInventStock GROUP BY Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtName2, 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, Vs4VInventStock.TWahGroup, Vs4VInventStock.TIMCQAStatus
GO

CREATE VIEW VS4VDOStockLoad 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, VS4TDOMB.TDymRountOrder, VS4TDOMB.TDymLn, VS4TARInvoice.TIvoRefNo2 FROM VS4TWarehouse RIGHT JOIN (VS4TUnit RIGHT JOIN (VS4TInventoryType RIGHT JOIN (VS4TProduct RIGHT JOIN (VS4TDO INNER JOIN (VS4TLocation RIGHT JOIN ((((VS4TDOMB LEFT JOIN VS4TARInvoice ON VS4TDOMB.TDymDocNo = VS4TARInvoice.TIvoNo) LEFT JOIN VS4TInventory ON VS4TARInvoice.TIvoRefNo2 = VS4TInventory.TInvNo) LEFT JOIN VS4TSO ON VS4TInventory.TInvRefNo = VS4TSO.TSODNo) LEFT JOIN (VS4TInventoryLOT RIGHT 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 VS4TLocation.TLctCode = VS4TInventoryMB.TInMTLctCode) ON VS4TDO.TPdyNo = VS4TDOMB.TDymTPdyNo) ON VS4TProduct.TPdtCode = VS4TInventoryMB.TInMTPdtCode) ON VS4TInventoryType.TInTAlias = VS4TInventory.TInvTInTAlias) ON VS4TUnit.TUntCode = VS4TProduct.TPdtTUntCode) ON VS4TWarehouse.TWahCode = VS4TLocation.TLctTWahCode
GO

CREATE VIEW VS4VDrawing 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, VS4TPOS.*, VS4TProductLine.TPdLCode, VS4TProductLine.TPdLName, VS4TProductLine.TPdLName2, VS4TProductLine.TPdLTDivCode, VS4TProductLine.TPdLDocCode, VS4TProductLine.TPdLTACSCode, VS4TProductSection.TPSECode, VS4TProductSection.TPSEName, VS4TProductSection.TPSEName2, VS4TProductDrawing.*, VS4TProductLine.TPdlCustomName, VS4TProductLine.TPdlGroupName1, VS4TProductLine.TPdlGroupName2, VS4TProductLine.TPdlGroupName3, VS4TProductLine.TPdlGroupName4, VS4TProductLine.TPdlSectionName1, VS4TProductLine.TPdlSectionName2, VS4TProductLine.TPdlSectionName3, VS4TProductLine.TPdlSectionName4 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) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) LEFT JOIN VS4TProductDrawing ON VS4TProduct.TPdtCode = VS4TProductDrawing.TPDwTPdtCode) ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode) LEFT JOIN VS4TProduct2 ON VS4TProduct.TPdtCode = VS4TProduct2.TPd2TPdtCode
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, VS4TEmpSlipMB.TSmbAmount, VS4TEmpSlipMB.TSmbBaseAmount 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) 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 VS4VEmpAmassMonth AS  SELECT VS4TEmpSlipDoc.TEpsTEmpCode, VS4TEmpSlipDoc.TEpsCheckGroup, Month(TEpsTSaPDate) AS VEPSMonth, Year(TEpsTSaPDate) AS VEPSYear, Sum(VS4TEmpSlipMB.TSmbAmount) AS TSmbAmount, VS4TEmpSlipMB.TSmbBaseAmount, VS4TEmpSlipMB.TSmbTAMTAlias 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) GROUP BY VS4TEmpSlipDoc.TEpsTEmpCode, VS4TEmpSlipDoc.TEpsCheckGroup, Month(TEpsTSaPDate), Year(TEpsTSaPDate), VS4TEmpSlipMB.TSmbBaseAmount, VS4TEmpSlipMB.TSmbTAMTAlias, VS4TEmpSlipDoc.TEpsApproveStatus, VS4TEmpSlipDoc.TEpsCancelStatus HAVING (((VS4TEmpSlipDoc.TEpsApproveStatus)=1) AND ((VS4TEmpSlipDoc.TEpsCancelStatus)=0))
GO

CREATE VIEW VS4VEmpAmassType AS  SELECT VS4TEmpAmassType.*, VS4TEmployee.*, 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, VS4TEmployeeType.TEmTCode, VS4TEmployeeType.TEmTName, VS4TEmployeeType.TEmTName2, VS4TEmployeeType.TEmTFlag1, VS4TEmployeeType.TEmTCalculateType, VS4TEmployeeType.TEmTSalaryType, VS4TEmployeeType.TEmTPeriodType, VS4TEmpSlipPeriod.TSaPPeriodNo, VS4TEmpSlipPeriod.TSaPYearPeriodNo, VS4TDivision.TDivCostGroup, VS4TEmployeeType.TEmTDayPerMonth, VS4TEmployeeType.TEmTHourPerDay, VS4TEmployeeType.TEmTDayPerWeek 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) LEFT JOIN VS4TEmpSlipPeriod ON (VS4TEmpAmassType.TEATTEmTCode = VS4TEmpSlipPeriod.TSaPTEmTCode) AND (VS4TEmpAmassType.TEATPaymentDate = VS4TEmpSlipPeriod.TSaPDate)) 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, Sum(VS4TEmpSlipMB.TSmbInterestAmass) AS TSmbInterestAmass, VS4TEmpAddMoney.TAmyName, VS4TEmpAddMoneyTY.TAMTName, Max(VS4TEmpSlipMB.TSmbCheckFix) AS TSmbCheckFix 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) GROUP BY VS4TEmpSlipDoc.TEpsTEmpCode, VS4TEmpSlipDoc.TEpsCheckGroup, Year(TEpsTSaPDate), VS4TEmpSlipDoc.TEpsBalanceFlag, VS4TEmpSlipMB.TSmbTAmyCode, VS4TEmpSlipMB.TSmbTAMTAlias, VS4TEmpSlipMB.TSmbCheckMoney, 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, VS4TEmpPunish.* FROM VS4TEmpPunish INNER 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) 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) ON VS4TEmpPunish.TEPNCode = VS4TEmpHisPunish.TEHUTEPNCode
GO

CREATE VIEW VS4VEmpHoliday AS  SELECT VS4TEmpHoliday.*, VS4VEmpHolidayA.VEhdGroupDay FROM VS4TEmpHoliday LEFT JOIN (SELECT VS4TEmpHoliday.TEhdYear, VS4TEmpHoliday.TEhdHolidayName, Count(VS4TEmpHoliday.TEhdYear) AS VEhdGroupDay FROM VS4TEmpHoliday GROUP BY VS4TEmpHoliday.TEhdYear, VS4TEmpHoliday.TEhdHolidayName) AS 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, VS4TEmpAddMoney.TAmyTUntCode FROM VS4TEmpAddMoney INNER JOIN ((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) ON VS4TEmpAddMoney.TAmyCode = VS4TEmpIncomeMB.TEwoTAmyCode
GO

CREATE VIEW VS4VEmpInOut AS  SELECT VS4TEmpInOutDoc.*, VS4TEmpInOutNote.*, VS4TEmployee.*, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TBranch.TBraName FROM VS4TBranch RIGHT JOIN (((VS4TEmpInOutDoc INNER JOIN (VS4TDivision RIGHT JOIN (VS4TEmpInOutNote LEFT JOIN VS4TEmployee ON VS4TEmpInOutNote.TEIOTEmpCode = VS4TEmployee.TEmpCode) ON VS4TDivision.TDivCode = VS4TEmployee.TEmpTDivCode) ON VS4TEmpInOutDoc.TEODNo = VS4TEmpInOutNote.TEIOTEODNo) LEFT JOIN VS4TDepartment ON VS4TEmployee.TEmpTDepCode = VS4TDepartment.TDepCode) LEFT JOIN VS4TSection ON VS4TEmployee.TEmpTSecCode = VS4TSection.TSecCode) ON VS4TBranch.TBraCode = VS4TEmployee.TEmpTBraCode
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, VS4TEmployee.TEmpCode, VS4TEmployee.TEmpResignDate 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, VS4TEmployee.TEmpCode, VS4TEmployee.TEmpResignDate
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, VS4TEmployee.TEmpCode, VS4TEmployee.TEmpResignDate 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, VS4TEmployee.TEmpCode, VS4TEmployee.TEmpResignDate
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, VS4TEmployee2.TEm2LastSalary, VS4TEmployee2.TEm2LastWTax, VS4TEmployee2.TEm2LastSTAX, VS4TEmployee2.TEm2LastSFUND, VS4TEmployee2.TEm2LastFund, VS4TEmployee2.TEm2SkipFUND, VS4TEmployee2.TEm2SkipSFUND, VS4TEmployee2.TEm2ResignNote, VS4TEmployee2.TEm2AccountNo, VS4TEmployee2.TEm2AccountNo2, VS4TEmployee2.TEm2ReportDate, VS4TEmployee2.TEm2visaTo, VS4TEmployee2.TEm2VisaFrom 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 VS4TEmpGroupDoc.*, VS4TEmployeeGrpMB.*, VS4TEmployeeGroup.*, VS4TPositionGroup.*, VS4TEmployee.*, VS4TBranch.TBraName, VS4TPosition.TPstName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName FROM VS4TPosition RIGHT JOIN (VS4TPositionGroup 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) INNER JOIN (VS4TEmployeeGroup INNER JOIN (VS4TEmpGroupDoc INNER JOIN VS4TEmployeeGrpMB ON VS4TEmpGroupDoc.TEgdNo = VS4TEmployeeGrpMB.TEGMTEgdNo) ON VS4TEmployeeGroup.TEmGCode = VS4TEmployeeGrpMB.TEGMTEmGCode) ON VS4TEmployee.TEmpCode = VS4TEmployeeGrpMB.TEGMTEmpCode) ON VS4TPositionGroup.TPgpCode = VS4TEmployeeGrpMB.TEGMTPgpCode) ON VS4TPosition.TPstCode = VS4TEmployee.TEmpTPstCode
GO

CREATE VIEW VS4VEmployeeGroupA AS  SELECT VS4TEmployeeGrpMB.TEGMTEmpCode, Max(VS4TEmpGroupDoc.TEgdTime) AS TEgdTime FROM VS4TEmpGroupDoc INNER JOIN VS4TEmployeeGrpMB ON VS4TEmpGroupDoc.TEgdNo = VS4TEmployeeGrpMB.TEGMTEgdNo GROUP BY VS4TEmployeeGrpMB.TEGMTEmpCode, VS4TEmpGroupDoc.TEgdApproveStatus, VS4TEmpGroupDoc.TEgdCancelStatus HAVING (((VS4TEmpGroupDoc.TEgdApproveStatus)=1) AND ((VS4TEmpGroupDoc.TEgdCancelStatus)=0))
GO

CREATE VIEW VS4VEmployeeGroupL AS  SELECT VS4TEmployeeGrpMB.TEGMTEmpCode, VS4TEmployee.TEmpFullName, VS4TEmployeeGrpMB.TEGMTEmGCode, VS4TEmployeeGroup.TEmGName, VS4TEmployeeGrpMB.TEGMTPgpCode, VS4TPositionGroup.TPgpName, VS4TEmpGroupDoc.TEgdTime, VS4TEmpGroupDoc.TEgdDate, VS4TEmpGroupDoc.TEgdNo, VS4TEmployeeGrpMB.TEgmStatus FROM VS4TPositionGroup RIGHT JOIN (VS4TEmployee RIGHT JOIN (VS4TEmployeeGroup RIGHT JOIN ((VS4VEmployeeGroupA INNER JOIN VS4TEmpGroupDoc ON VS4VEmployeeGroupA.TEgdTime = VS4TEmpGroupDoc.TEgdTime) INNER JOIN VS4TEmployeeGrpMB ON (VS4TEmpGroupDoc.TEgdNo = VS4TEmployeeGrpMB.TEGMTEgdNo) AND (VS4VEmployeeGroupA.TEGMTEmpCode = VS4TEmployeeGrpMB.TEGMTEmpCode)) ON VS4TEmployeeGroup.TEmGCode = VS4TEmployeeGrpMB.TEGMTEmGCode) ON VS4TEmployee.TEmpCode = VS4TEmployeeGrpMB.TEGMTEmpCode) ON VS4TPositionGroup.TPgpCode = VS4TEmployeeGrpMB.TEGMTPgpCode GROUP BY VS4TEmployeeGrpMB.TEGMTEmpCode, VS4TEmployee.TEmpFullName, VS4TEmployeeGrpMB.TEGMTEmGCode, VS4TEmployeeGroup.TEmGName, VS4TEmployeeGrpMB.TEGMTPgpCode, VS4TPositionGroup.TPgpName, VS4TEmpGroupDoc.TEgdTime, VS4TEmpGroupDoc.TEgdDate, VS4TEmpGroupDoc.TEgdNo, VS4TEmployeeGrpMB.TEgmStatus HAVING (((VS4TEmployeeGrpMB.TEgmStatus)=0))
GO

CREATE VIEW VS4VEmployeeSlip AS  SELECT VS4TEmpSlipDoc.*, TSmbTEpsNo, TSmbTEpsCheckGroup, TSmbLn, TSmbTAmyCode, TSmbTAMTAlias, TSmbMoneyCode, TSmbMoneyName, TSmbAmassName, TSmbRate, TSmbRateType, TSmbBaseSource,  TSmbCalcTax, TSmbTUntCode, TSmbCheckMoney, TSmbCheckFix,  TSmbPayDay, TSmbBaseAmount, TSmbQuantity, TSmbAmount, TSmbInterestRate, TSmbInterestType, TSmbInterestAmount, TSmbIntLastAmass, TSmbInterestAmass, TSmbTotal, TSmbDebit, TSmbCrebit, TSmbIncrease, TSmbDecrease, TSmbUseAllow, TSmbCutTip, TSmbFixUnit, TSmbAmass, TSmbAmassAmount, TSmbDescription, TSmbFlag1, TSmbCalcSTAX, TSmbCalcSalary, TSmbCalcSFUND, TSmbTDivCode, TEmpCode, TEmpNo, TEmpBarCode, TEmpCardNo, TEmpTEmTCode, TEmpTWPDCode, TEmpGender, TEmpTitleName, TEmpFirstName, TEmpMiddleName, TEmpLastName, TEmpAliasName, TEmpNickName, TEmpFullName, TEmpTitleName2, TEmpFirstName2, TEmpMiddleName2, TEmpLastname2, TEmpFullName2, TEmpAddress, TEmpSubProvince, TEmpCity, TEmpPostalCode, TEmpTStaCode, TEmpTCouCode, TEmpTel, TEmpFax, TEmpEmail, TEmpAddressContact, TEmpImage1, TEmpBirthDay, TEmpBornZone, TEmpBlood, TEmpFundNo, TEmpCitizenNo, TEmpCitizenAddress, TEmpPassportNo, TEmpTaxNo, TEmpSocialSecurity, TEmpCardAlien, TEmpAllowAlien, TEmpRace, TEmpCitizenShip, TEmpReligion, TEmpHospital, TEmpHospital1, TEmpType, TEmpDropStatus, TEmpStatus, TEmpSignDate, TEmpPermanantDate, TEmpResignDate, TEmpStatusPer, TEmpBuddyCalcTAX, TEmpTotalParent, TEmpTotalFMCalc, TEmpSoldierStatus, TEmpChildStudy, TEmpChildNotStudy, TEmpCalcChildList, TEmpCalcBuddy, TEmpTPstCode, TEmpTSecCode, TEmpTDepCode, TEmpTDivCode, TEmpTBraCode, TEmpPriority, TEmpProbationDate, TEmpScroll, TEmpIsAdmin, TEmpMainChange, TEmpGradeLevel, TEmpHeight, TEmpWeight, TEmpLastSalaryDate, TEmpSalary, TEmpCustom, TEmpWTax, TEmpSTAX, TEmpSFund, TEmpStartSFund, TEmpFund, TEmpEnableFUND, TEmpStartFund, TEmpApproveLimit, TEmpApproveLimitM, TEmpApproveLimitY, TEmpTotalReduce, TEmpCreateCode, TEmpCreateDate, TEmpEditCode, TEmpEditDate, TEmpTextSort, TEmpFlag1, TEmpTSAeCode, TEmpRegisterDate, TEmpTEmGCode, TEmpBirthdayText, TEmpCostGroup, TEmpMode, VS4TEmployeeType.TEmTName, VS4TEmployeeType.TEmTCalculateType, VS4TEmployeeType.TEmTSalaryType, VS4TDivision.TDivName, VS4TDivision.TDivName2, VS4TDivision.TDivLevel, VS4TDepartment.TDepName, VS4TDepartment.TDepName2, VS4TSection.TSecName, VS4TSection.TSecName2, VS4TEmpAddMoney.TAmyName2, VS4TBank.TBnkTransferFee, VS4TEmpSlipPeriod.TSaPPeriodNo, VS4TEmpSlipPeriod.TSaPYearPeriodNo, VS4TEmployee2.TEm2SkipSSO, VS4TEmployee2.TEm2SkipFUND, VS4TEmployee2.TEm2SkipSFUND, VS4TEmployee2.TEm2SkipTax FROM VS4TEmpSlipPeriod RIGHT JOIN ((((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) LEFT JOIN VS4TEmployee2 ON VS4TEmployee.TEmpCode = VS4TEmployee2.TEm2TEmpCode) RIGHT JOIN (VS4TEmpSlipDoc LEFT JOIN VS4TBank ON VS4TEmpSlipDoc.TEpsTBnkCode = VS4TBank.TBnkCode) ON VS4TEmployee.TEmpCode = VS4TEmpSlipDoc.TEpsTEmpCode) INNER JOIN (VS4TEmpAddMoney RIGHT JOIN VS4TEmpSlipMB ON VS4TEmpAddMoney.TAmyCode = VS4TEmpSlipMB.TSmbTAmyCode) ON (VS4TEmpSlipDoc.TEpsNo = VS4TEmpSlipMB.TSmbTEpsNo) AND (VS4TEmpSlipDoc.TEpsCheckGroup = VS4TEmpSlipMB.TSmbTEpsCheckGroup)) ON (VS4TEmpSlipPeriod.TSaPTEmTCode = VS4TEmpSlipDoc.TEpsTSAPTEmTCode) AND (VS4TEmpSlipPeriod.TSaPDate = VS4TEmpSlipDoc.TEpsTSaPDate)
GO

CREATE VIEW VS4VEmployeeSlipG AS  SELECT VS4TEmpSlipDoc.*, TSmbTEpsNo, TSmbTEpsCheckGroup, TSmbLn, TSmbTAmyCode, TSmbTAMTAlias, TSmbMoneyCode, TSmbMoneyName, TSmbAmassName, TSmbRate, TSmbRateType, TSmbBaseSource,  TSmbCalcTax, TSmbTUntCode, TSmbCheckMoney, TSmbCheckFix,  TSmbPayDay, TSmbBaseAmount, TSmbQuantity, TSmbAmount, TSmbInterestRate, TSmbInterestType, TSmbInterestAmount, TSmbIntLastAmass, TSmbInterestAmass, TSmbTotal, TSmbDebit, TSmbCrebit, TSmbIncrease, TSmbDecrease, TSmbUseAllow, TSmbCutTip, TSmbFixUnit, TSmbAmass, TSmbAmassAmount, TSmbDescription, TSmbFlag1, TSmbCalcSTAX, TSmbCalcSalary, TSmbCalcSFUND, TSmbTDivCode, VS4TEmployee.TEmpCode, VS4TEmployee.TEmpNo, VS4TEmployee.TEmpBarCode, VS4TEmployee.TEmpCardNo, VS4TEmployee.TEmpTEmTCode, VS4TEmployee.TEmpTWPDCode, VS4TEmployee.TEmpGender, VS4TEmployee.TEmpTitleName, VS4TEmployee.TEmpFirstName, VS4TEmployee.TEmpMiddleName, VS4TEmployee.TEmpLastName, VS4TEmployee.TEmpAliasName, VS4TEmployee.TEmpNickName, VS4TEmployee.TEmpFullName, VS4TEmployee.TEmpTitleName2, VS4TEmployee.TEmpFirstName2, VS4TEmployee.TEmpMiddleName2, VS4TEmployee.TEmpLastname2, VS4TEmployee.TEmpFullName2, VS4TEmployee.TEmpAddress, VS4TEmployee.TEmpSubProvince, VS4TEmployee.TEmpCity, VS4TEmployee.TEmpPostalCode, VS4TEmployee.TEmpTStaCode, VS4TEmployee.TEmpTCouCode, VS4TEmployee.TEmpTel, VS4TEmployee.TEmpFax, VS4TEmployee.TEmpEmail, VS4TEmployee.TEmpAddressContact, VS4TEmployee.TEmpImage1, VS4TEmployee.TEmpBirthDay, VS4TEmployee.TEmpBornZone, VS4TEmployee.TEmpBlood, VS4TEmployee.TEmpFundNo, VS4TEmployee.TEmpCitizenNo, VS4TEmployee.TEmpCitizenAddress, VS4TEmployee.TEmpPassportNo, VS4TEmployee.TEmpTaxNo, VS4TEmployee.TEmpSocialSecurity, VS4TEmployee.TEmpCardAlien, VS4TEmployee.TEmpAllowAlien, VS4TEmployee.TEmpRace, VS4TEmployee.TEmpCitizenShip, VS4TEmployee.TEmpReligion, VS4TEmployee.TEmpHospital, VS4TEmployee.TEmpHospital1, VS4TEmployee.TEmpType, VS4TEmployee.TEmpDropStatus, VS4TEmployee.TEmpStatus, VS4TEmployee.TEmpSignDate, VS4TEmployee.TEmpPermanantDate, VS4TEmployee.TEmpResignDate, VS4TEmployee.TEmpStatusPer, VS4TEmployee.TEmpBuddyCalcTAX, VS4TEmployee.TEmpTotalParent, VS4TEmployee.TEmpTotalFMCalc, VS4TEmployee.TEmpSoldierStatus, VS4TEmployee.TEmpChildStudy, VS4TEmployee.TEmpChildNotStudy, VS4TEmployee.TEmpCalcChildList, VS4TEmployee.TEmpCalcBuddy, VS4TEmployee.TEmpTPstCode, VS4TEmployee.TEmpTSecCode, VS4TEmployee.TEmpTDepCode, VS4TEmployee.TEmpTDivCode, VS4TEmployee.TEmpTBraCode, VS4TEmployee.TEmpPriority, VS4TEmployee.TEmpProbationDate, VS4TEmployee.TEmpScroll, VS4TEmployee.TEmpIsAdmin, VS4TEmployee.TEmpMainChange, VS4TEmployee.TEmpGradeLevel, VS4TEmployee.TEmpHeight, VS4TEmployee.TEmpWeight, VS4TEmployee.TEmpLastSalaryDate, VS4TEmployee.TEmpSalary, VS4TEmployee.TEmpCustom, VS4TEmployee.TEmpWTax, VS4TEmployee.TEmpSTAX, VS4TEmployee.TEmpSFund, VS4TEmployee.TEmpStartSFund, VS4TEmployee.TEmpFund, VS4TEmployee.TEmpEnableFUND, VS4TEmployee.TEmpStartFund, VS4TEmployee.TEmpApproveLimit, VS4TEmployee.TEmpApproveLimitM, VS4TEmployee.TEmpApproveLimitY, VS4TEmployee.TEmpTotalReduce, VS4TEmployee.TEmpCreateDate, VS4TEmployee.TEmpEditCode, VS4TEmployee.TEmpEditDate, VS4TEmployee.TEmpTextSort, VS4TEmployee.TEmpFlag1, VS4TEmployee.TEmpTSAeCode, VS4TEmployee.TEmpRegisterDate, VS4TEmployee.TEmpTEmGCode, VS4TEmployee.TEmpBirthdayText, VS4TEmployee.TEmpCostGroup, VS4TEmployee.TEmpMode, VS4TEmployeeType.TEmTName, VS4TEmployeeType.TEmTCalculateType, VS4TEmployeeType.TEmTSalaryType, VS4TDivision.TDivName, VS4TDivision.TDivName2, VS4TDivision.TDivLevel, VS4TDepartment.TDepName, VS4TDepartment.TDepName2, VS4TSection.TSecName, VS4TSection.TSecName2, VS4TEmpAddMoney.TAmyName2, VS4TEmpTypeGroup.TETGCode, VS4TEmpTypeGroup.TETGName, VS4TEmpTypeGroup.TETGName2, VS4TBank.TBnkTransferFee,  VS4TEmployee2.TEm2SkipTax, VS4TEmployee2.TEm2SkipSSO, VS4TEmployee2.TEm2SkipFUND, VS4TEmployee2.TEm2SkipSFUND FROM VS4TEmpTypeGroup INNER JOIN (((((VS4TEmployeeType INNER 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) INNER JOIN VS4TEmpTypeGroupMB ON VS4TEmployeeType.TEmTCode = VS4TEmpTypeGroupMB.TEGBTEmTCode) LEFT JOIN VS4TEmployee2 ON VS4TEmployee.TEmpCode = VS4TEmployee2.TEm2TEmpCode) INNER JOIN (VS4TEmpSlipDoc LEFT JOIN VS4TBank ON VS4TEmpSlipDoc.TEpsTBnkCode = VS4TBank.TBnkCode) 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)) ON VS4TEmpTypeGroup.TETGCode = VS4TEmpTypeGroupMB.TEGBTETGCode
GO

CREATE VIEW VS4VEmployeeSlipH AS  SELECT VS4TEmpSlipDoc.*, VS4TEmployee.*, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TEmployeeType.TEmTCode, VS4TEmployeeType.TEmTName, VS4TEmployeeType.TEmTCalculateType, VS4TEmployeeType.TEmTSalaryType, VS4TBank.TBnkTransferFee, VS4TEmpSlipPeriod.TSaPPeriodNo, VS4TEmpSlipPeriod.TSaPYearPeriodNo, VS4TEmployee2.TEm2TRouCode, VS4TEmployee2.TEm2SkipTax, VS4TEmployee2.TEm2SkipSSO, VS4TEmployee2.TEm2SkipFUND, VS4TEmployee2.TEm2SkipSFUND, VS4TEmpSlipPeriod.TSaPTEmTCode AS TEPSTEmTCode FROM VS4TEmpSlipPeriod RIGHT JOIN (((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) LEFT JOIN VS4TEmployee2 ON VS4TEmployee.TEmpCode = VS4TEmployee2.TEm2TEmpCode) RIGHT JOIN (VS4TEmpSlipDoc LEFT JOIN VS4TBank ON VS4TEmpSlipDoc.TEpsTBnkCode = VS4TBank.TBnkCode) ON VS4TEmployee.TEmpCode = VS4TEmpSlipDoc.TEpsTEmpCode) ON (VS4TEmpSlipPeriod.TSaPDate = VS4TEmpSlipDoc.TEpsTSaPDate) AND (VS4TEmpSlipPeriod.TSaPTEmTCode = VS4TEmpSlipDoc.TEpsTSAPTEmTCode)
GO

CREATE VIEW VS4VEmployeeSlipHG AS  SELECT VS4TEmpSlipDoc.*, VS4TEmployee.*, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TEmployeeType.TEmTCode, VS4TEmployeeType.TEmTName, VS4TEmployeeType.TEmTCalculateType, VS4TEmployeeType.TEmTSalaryType, VS4TEmpTypeGroup.TETGCode, VS4TEmpTypeGroup.TETGName, VS4TEmpTypeGroup.TETGName2, VS4TBank.TBnkTransferFee, VS4TEmployee2.TEm2SkipTax, VS4TEmployee2.TEm2SkipSSO, VS4TEmployee2.TEm2SkipFUND, VS4TEmployee2.TEm2SkipSFUND FROM VS4TEmpTypeGroup INNER JOIN ((((VS4TEmployeeType INNER 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) INNER JOIN VS4TEmpTypeGroupMB ON VS4TEmployeeType.TEmTCode = VS4TEmpTypeGroupMB.TEGBTEmTCode) LEFT JOIN VS4TEmployee2 ON VS4TEmployee.TEmpCode = VS4TEmployee2.TEm2TEmpCode) INNER JOIN (VS4TEmpSlipDoc LEFT JOIN VS4TBank ON VS4TEmpSlipDoc.TEpsTBnkCode = VS4TBank.TBnkCode) ON VS4TEmployee.TEmpCode = VS4TEmpSlipDoc.TEpsTEmpCode) ON VS4TEmpTypeGroup.TETGCode = VS4TEmpTypeGroupMB.TEGBTETGCode
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.*, VS4TEmployee2.TEm2ManualSFUND, VS4TEmployee.* FROM ((VS4TTaxTrans LEFT JOIN VS4VEmpAmassYear ON (VS4TTaxTrans.TTxTYear = VS4VEmpAmassYear.VEMAYear) AND (VS4TTaxTrans.TTxTClientCode = VS4VEmpAmassYear.TEpsTEmpCode)) LEFT JOIN VS4TEmployee2 ON VS4VEmpAmassYear.TEpsTEmpCode = VS4TEmployee2.TEm2TEmpCode) LEFT JOIN VS4TEmployee ON VS4VEmpAmassYear.TEpsTEmpCode = VS4TEmployee.TEmpCode 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 Or (VS4TEmpParent.TEpPLn) Is Null))
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 VS4VEmpSalaryCount AS  SELECT VS4TEmpSalary.TSalTEmpCode, VS4TEmpSalary.TSalTAmyCode, Count(VS4TEmpSalary.TSalTAmyCode) AS VSaCCount, VS4TEmployee.TEmpStatus FROM VS4TEmployee INNER JOIN VS4TEmpSalary ON VS4TEmployee.TEmpCode = VS4TEmpSalary.TSalTEmpCode GROUP BY VS4TEmpSalary.TSalTEmpCode, VS4TEmpSalary.TSalTAmyCode, VS4TEmployee.TEmpStatus HAVING (((Count(VS4TEmpSalary.TSalTAmyCode))>1) AND ((VS4TEmployee.TEmpStatus)<=3))
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.TEpsCheckGroup = VS4TEmpSlipMB.TSmbTEpsCheckGroup) AND (VS4TEmpSlipDoc.TEpsNo = VS4TEmpSlipMB.TSmbTEpsNo) 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.*, VS4TEmployee.*, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TEmpTimeFill.*, VS4TEmpTimeChkMB.TTCKTEtcNo, VS4TEmpTimeChkMB.TTCKLn 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 LEFT JOIN VS4TEmpTimeFill ON (VS4TEmpTimeChkMB.TTCKWorkDate = VS4TEmpTimeFill.TTGMWorkDate) AND (VS4TEmpTimeChkMB.TTCKTEmpCode = VS4TEmpTimeFill.TTGMTEmpCode)) 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, VS4TEmpTimeChk.TEtcTSAPTEmTCode AS TEtcTEmTCode 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.TTIPNo = VS4TTimeInputNote.TTINTTIPNo
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.*, VS4TEmployee.TEmpTSecCode, VS4TEmployee.TEmpTDepCode, VS4TEmployee.TEmpTDivCode, VS4TEmployee.TEmpTBraCode, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4TEmployee.TEmpTEmTCode, VS4TEmployee.TEmpFullName FROM VS4TTrainingGroup INNER JOIN (VS4TTrainingCourse INNER JOIN (VS4TEmpTraining INNER JOIN (VS4TDivision RIGHT JOIN (VS4TBranch RIGHT JOIN (((VS4TEmployee LEFT JOIN VS4TSection ON VS4TEmployee.TEmpTSAeCode = VS4TSection.TSecCode) LEFT JOIN VS4TDepartment ON VS4TEmployee.TEmpTDepCode = VS4TDepartment.TDepCode) INNER JOIN VS4TEmpTrainingMB ON (VS4TEmployee.TEmpCode = VS4TEmpTrainingMB.TETmTEmpCode) AND (VS4TEmployee.TEmpCode = VS4TEmpTrainingMB.TETmTEmpCode)) ON VS4TBranch.TBraCode = VS4TEmployee.TEmpTBraCode) ON VS4TDivision.TDivCode = VS4TEmployee.TEmpTDivCode) 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, VS4TJob.TJobTPrjCode 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 VS4VErrARCardCN AS  SELECT VS4TARCard.TRICTARNCode, VS4TARCard.TRICDocNo, VS4TARCard.TRICType, VS4TARCreditNote.TRCNNo FROM VS4TARCard LEFT JOIN VS4TARCreditNote ON (VS4TARCard.TRICTARNCode = VS4TARCreditNote.TRCNTARNCode) AND (VS4TARCard.TRICDocNo = VS4TARCreditNote.TRCNNo) WHERE (((VS4TARCard.TRICType)='C') AND ((VS4TARCreditNote.TRCNNo) Is Null))
GO

CREATE VIEW VS4VErrARCardDB AS  SELECT VS4TARCard.TRICTARNCode, VS4TARCard.TRICDocNo, VS4TARCard.TRICType, VS4TARDebitNote.TDBNNo FROM VS4TARCard LEFT JOIN VS4TARDebitNote ON (VS4TARCard.TRICDocNo = VS4TARDebitNote.TDBNNo) AND (VS4TARCard.TRICTARNCode = VS4TARDebitNote.TDBNTARNCode) WHERE (((VS4TARCard.TRICType)='D') AND ((VS4TARDebitNote.TDBNNo) Is Null))
GO

CREATE VIEW VS4VErrARCardIV AS  SELECT VS4TARCard.TRICTARNCode, VS4TARCard.TRICDocNo, VS4TARCard.TRICType, VS4TARInvoice.TIvoNo FROM VS4TARCard LEFT JOIN VS4TARInvoice ON (VS4TARCard.TRICDocNo = VS4TARInvoice.TIvoNo) AND (VS4TARCard.TRICTARNCode = VS4TARInvoice.TIvoTARNCode) WHERE (((VS4TARCard.TRICType)='I') AND ((VS4TARInvoice.TIvoNo) Is Null))
GO

CREATE VIEW VS4VErrARCardRV AS  SELECT VS4TARCard.TRICTARNCode, VS4TARCard.TRICDocNo, VS4TARCard.TRICType, VS4TARVoucher.TRVHNo FROM VS4TARCard LEFT JOIN VS4TARVoucher ON (VS4TARCard.TRICDocNo = VS4TARVoucher.TRVHNo) AND (VS4TARCard.TRICTARNCode = VS4TARVoucher.TRVHTARNCode) WHERE (((VS4TARCard.TRICType)='P') AND ((VS4TARVoucher.TRVHNo) Is Null))
GO

CREATE VIEW VS4VErrDupARCard AS  SELECT VS4TARCard.TRICDocNo, Count(VS4TARCard.TRICDocNo) AS VCDPCount, VS4TARCard.TRICType FROM VS4TARCard GROUP BY VS4TARCard.TRICDocNo, VS4TARCard.TRICType HAVING (((Count(VS4TARCard.TRICDocNo))>1 Or (Count(VS4TARCard.TRICDocNo))=0) AND ((VS4TARCard.TRICType)<>'H'))
GO

CREATE VIEW VS4VErrDupARName AS  SELECT VS4TAR3.TAR3FirstName, VS4TAR3.TAR3LastName, Count(VS4TAR.TARNCode) AS VARDCount FROM VS4TAR INNER JOIN VS4TAR3 ON VS4TAR.TARNCode = VS4TAR3.TAR3TARNCode GROUP BY VS4TAR3.TAR3FirstName, VS4TAR3.TAR3LastName HAVING (((Count(VS4TAR.TARNCode))>1))
GO

CREATE VIEW VS4VErrDupARNameY AS  SELECT Year(VS4TAR.TARNRegisterDate) AS VARDYear, VS4TAR3.TAR3FirstName, VS4TAR3.TAR3LastName, Count(VS4TAR.TARNCode) AS VARDCount FROM VS4TAR INNER JOIN VS4TAR3 ON VS4TAR.TARNCode = VS4TAR3.TAR3TARNCode GROUP BY VS4TAR3.TAR3FirstName, VS4TAR3.TAR3LastName, Year(VS4TAR.TARNRegisterDate) HAVING (((Count(VS4TAR.TARNCode))>1))
GO

CREATE VIEW VS4VErrDupBarcodeA 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 VS4VErrDupBarcode AS  SELECT * FROM VS4TProduct INNER JOIN VS4VErrDupBarcodeA ON VS4TProduct.TPdtBarCode = VS4VErrDupBarcodeA.VDupBarCode
GO

CREATE VIEW VS4VErrDupLot 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 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, VS4TEmployee.TEmpResignDate FROM VS4TEmpSlipPeriod INNER JOIN ((VS4TEmployeeType RIGHT JOIN (VS4TDivision RIGHT JOIN (VS4TBranch INNER 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) ON VS4TEmployeeType.TEmTCode = VS4TEmployee.TEmpTEmTCode) INNER JOIN VS4TEmpSlipDoc ON VS4TEmployee.TEmpCode = VS4TEmpSlipDoc.TEpsTEmpCode) ON (VS4TEmpSlipPeriod.TSaPDate = VS4TEmpSlipDoc.TEpsTSaPDate) AND (VS4TEmpSlipPeriod.TSaPTEmTCode = VS4TEmpSlipDoc.TEpsTSAPTEmTCode) 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, VS4TEmployee.TEmpResignDate, VS4TEmpSlipDoc.TEpsApproveStatus, VS4TEmpSlipDoc.TEpsCancelStatus HAVING (((VS4TEmpSlipDoc.TEpsApproveStatus)=1) AND ((VS4TEmpSlipDoc.TEpsCancelStatus)=0))
GO

CREATE VIEW VS4VExportSlipGov AS  SELECT Year(TEpsEndDate) AS VESGYEAR, Month(TEpsEndDate) AS VESGMONTH, (TEpsEndDate-Day(TEpsEndDate)+1) AS VESGPeriod, 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, VS4TBranch.TBraDocCode, VS4TBranch.TBraAddressBill, Max(VS4TEmpSlipDoc.TEpsSFUNDAmass) AS TEpsSFUNDAmass, Sum(VS4TEmpSlipDoc.TEpsSFUNDOffice) AS TEpsSFUNDOffice, Max(VS4TEmpSlipDoc.TEpsSTAXAmass) AS TEpsSTAXAmass, Sum(VS4TEmpSlipDoc.TEpsSTAXOffice) AS TEpsSTAXOffice, Max(VS4TEmpSlipDoc.TEpsPTAXAmass) AS TEpsPTAXAmass, Sum(VS4TEmpSlipDoc.TEpsPTAXOffice) AS TEpsPTAXOffice, VS4TEmployee2.TEm2SkipSSO, VS4TEmployee2.TEm2SkipSFUND, VS4TEmployee2.TEm2SkipTax, VS4TEmployee2.TEm2SkipFUND, VS4TEmployee.TEmpCostGroup, VS4TEmployeeType.TEmTCalculateType, VS4TBranch.TBraTaxNo, VS4TBranch.TBraSocialNo, VS4TBranch.TBraSocialNoUpload, VS4TBranch.TBraNo, VS4TEmployee.TEmpTEmTCode FROM VS4TEmpSlipPeriod INNER JOIN (((VS4TEmployeeType 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) ON VS4TEmployeeType.TEmTCode = VS4TEmployee.TEmpTEmTCode) 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 (TEpsEndDate-Day(TEpsEndDate)+1), 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, VS4TBranch.TBraDocCode, VS4TBranch.TBraAddressBill, VS4TEmployee2.TEm2SkipSSO, VS4TEmployee2.TEm2SkipSFUND, VS4TEmployee2.TEm2SkipTax, VS4TEmployee2.TEm2SkipFUND, VS4TEmployee.TEmpCostGroup, VS4TEmployeeType.TEmTCalculateType, VS4TBranch.TBraTaxNo, VS4TBranch.TBraSocialNo, VS4TBranch.TBraSocialNoUpload, VS4TBranch.TBraNo, VS4TEmployee.TEmpTEmTCode, Year(TEpsEndDate), Month(TEpsEndDate), VS4TEmpSlipDoc.TEpsApproveStatus, VS4TEmpSlipDoc.TEpsCancelStatus, VS4TEmpSlipDoc.TEpsCheckGroup HAVING (((VS4TEmpSlipPeriod.TSaPStatus)=0) AND ((VS4TEmpSlipDoc.TEpsApproveStatus)=1) AND ((VS4TEmpSlipDoc.TEpsCancelStatus)=0) AND ((VS4TEmpSlipDoc.TEpsCheckGroup)=0))
GO

CREATE VIEW VS4VExportSlipGSum AS SELECT        YEAR(VS4TEmpSlipDoc.TEpsEndDate) AS VEGSYEAR, MONTH(VS4TEmpSlipDoc.TEpsEndDate) 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, SUM(VS4TEmpSlipDoc.TEpsSTAXOffice)                           AS TEpsSTAXOffice, SUM(VS4TEmpSlipDoc.TEpsSFUNDOffice) AS TEpsSFUNDOffice FROM            VS4TEmpSlipPeriod INNER JOIN                          VS4TEmployee LEFT OUTER JOIN                          VS4TEmployee2 ON VS4TEmployee.TEmpCode = VS4TEmployee2.TEm2TEmpCode INNER JOIN                          VS4TEmpSlipDoc ON VS4TEmployee.TEmpCode = VS4TEmpSlipDoc.TEpsTEmpCode ON VS4TEmpSlipPeriod.TSaPTEmTCode = VS4TEmpSlipDoc.TEpsTSAPTEmTCode AND                           VS4TEmpSlipPeriod.TSaPDate = VS4TEmpSlipDoc.TEpsTSaPDate GROUP BY YEAR(VS4TEmpSlipDoc.TEpsEndDate), MONTH(VS4TEmpSlipDoc.TEpsEndDate), VS4TEmpSlipPeriod.TSaPStatus, VS4TEmpSlipDoc.TEpsApproveStatus, VS4TEmpSlipDoc.TEpsCancelStatus,                           VS4TEmpSlipDoc.TEpsCheckGroup HAVING        (VS4TEmpSlipPeriod.TSaPStatus = 0) 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.TSaPDate = VS4TEmpSlipDoc.TEpsTSaPDate) AND (VS4TEmpSlipPeriod.TSaPTEmTCode = VS4TEmpSlipDoc.TEpsTSAPTEmTCode) 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.*, (SELECT SUM(TPTAGrandTotal) AS A FROM VS4TPOSTrans  WHERE TPTAApproveStatus=1 AND TPTACancelStatus=0 AND VS4TPOSTrans.tptaparkno=VS4TFlight.tfliparkno AND VS4TPOSTrans.TPTADate=VS4TFlight.tflidate) AS TPTAGrandTotal, (SELECT SUM(TPTAGrandTotalCom) AS A FROM VS4TPOSTrans  WHERE TPTAApproveStatus=1 AND TPTACancelStatus=0 AND VS4TPOSTrans.tptaparkno=VS4TFlight.tfliparkno AND VS4TPOSTrans.TPTADate=VS4TFlight.tflidate) AS TPTAGrandTotalCom, (SELECT SUM(TPTAGrandTotalComG) AS A FROM VS4TPOSTrans  WHERE TPTAApproveStatus=1 AND TPTACancelStatus=0 AND VS4TPOSTrans.tptaparkno=VS4TFlight.tfliparkno AND VS4TPOSTrans.TPTADate=VS4TFlight.tflidate) AS TPTAGrandTotalComG, (SELECT SUM(TPTAGrandTotalComT) AS A FROM VS4TPOSTrans  WHERE TPTAApproveStatus=1 AND TPTACancelStatus=0 AND VS4TPOSTrans.tptaparkno=VS4TFlight.tfliparkno AND VS4TPOSTrans.TPTADate=VS4TFlight.tflidate) AS TPTAGrandTotalComT, (SELECT SUM(TPTACommission) AS A FROM VS4TPOSTrans  WHERE TPTAApproveStatus=1 AND TPTACancelStatus=0 AND VS4TPOSTrans.tptaparkno=VS4TFlight.tfliparkno AND VS4TPOSTrans.TPTADate=VS4TFlight.tflidate) AS TPTACommission, (SELECT SUM(TPTAGuideCom) AS A FROM VS4TPOSTrans  WHERE TPTAApproveStatus=1 AND TPTACancelStatus=0 AND VS4TPOSTrans.tptaparkno=VS4TFlight.tfliparkno AND VS4TPOSTrans.TPTADate=VS4TFlight.tflidate) AS TPTAGuideCom, (SELECT SUM(TPTATourCom) AS A FROM VS4TPOSTrans  WHERE TPTAApproveStatus=1 AND TPTACancelStatus=0 AND VS4TPOSTrans.tptaparkno=VS4TFlight.tfliparkno AND VS4TPOSTrans.TPTADate=VS4TFlight.tflidate) AS TPTATourCom 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.*, VS4TVehicleType.TVeTName, VS4TAP.TAPNPhone, VS4TAP.TAPNFax, VS4TAP.TAPNEmail, VS4TFlightGuide.TFlGCode, VS4TFlightGuide.TFlGName, VS4TAP_1.TAPNPhone AS VFVhPhone, VS4TAP_1.TAPNFax AS VFVhFax, VS4TAP_1.TAPNEmail AS VFVhEmail, (SELECT SUM(TPTAGrandTotal) AS A FROM VS4TPOSTrans  WHERE TPTAApproveStatus=1 AND TPTACancelStatus=0 AND VS4TPOSTrans.tptaparkno=VS4TFlight.tfliparkno AND VS4TPOSTrans.TPTADate=VS4TFlight.tflidate) AS TPTAGrandTotal, (SELECT SUM(TPTAGrandTotalCom) AS A FROM VS4TPOSTrans  WHERE TPTAApproveStatus=1 AND TPTACancelStatus=0 AND VS4TPOSTrans.tptaparkno=VS4TFlight.tfliparkno AND VS4TPOSTrans.TPTADate=VS4TFlight.tflidate) AS TPTAGrandTotalCom, (SELECT SUM(TPTAGrandTotalComG) AS A FROM VS4TPOSTrans  WHERE TPTAApproveStatus=1 AND TPTACancelStatus=0 AND VS4TPOSTrans.tptaparkno=VS4TFlight.tfliparkno AND VS4TPOSTrans.TPTADate=VS4TFlight.tflidate) AS TPTAGrandTotalComG, (SELECT SUM(TPTAGrandTotalComT) AS A FROM VS4TPOSTrans  WHERE TPTAApproveStatus=1 AND TPTACancelStatus=0 AND VS4TPOSTrans.tptaparkno=VS4TFlight.tfliparkno AND VS4TPOSTrans.TPTADate=VS4TFlight.tflidate) AS TPTAGrandTotalComT, (SELECT SUM(TPTACommission) AS A FROM VS4TPOSTrans  WHERE TPTAApproveStatus=1 AND TPTACancelStatus=0 AND VS4TPOSTrans.tptaparkno=VS4TFlight.tfliparkno AND VS4TPOSTrans.TPTADate=VS4TFlight.tflidate) AS TPTACommission, (SELECT SUM(TPTAGuideCom) AS A FROM VS4TPOSTrans  WHERE TPTAApproveStatus=1 AND TPTACancelStatus=0 AND VS4TPOSTrans.tptaparkno=VS4TFlight.tfliparkno AND VS4TPOSTrans.TPTADate=VS4TFlight.tflidate) AS TPTAGuideCom, (SELECT SUM(TPTATourCom) AS A FROM VS4TPOSTrans  WHERE TPTAApproveStatus=1 AND TPTACancelStatus=0 AND VS4TPOSTrans.tptaparkno=VS4TFlight.tfliparkno AND VS4TPOSTrans.TPTADate=VS4TFlight.tflidate) AS TPTATourCom FROM ((VS4TVehicleType RIGHT JOIN ((VS4TFlight LEFT JOIN VS4TAP ON VS4TFlight.TFliTAPNCode = VS4TAP.TAPNCode) LEFT JOIN VS4TFlightVehicle ON VS4TFlight.TFliNo = VS4TFlightVehicle.TFVhTFliNo) ON VS4TVehicleType.TVeTCode = VS4TFlightVehicle.TFVhTVeTCode) LEFT JOIN VS4TFlightGuide ON VS4TFlight.TFliNo = VS4TFlightGuide.TFlGTFliNo) LEFT JOIN VS4TAP AS VS4TAP_1 ON VS4TFlightGuide.TFlGCode = VS4TAP_1.TAPNCode WHERE (((VS4TFlightGuide.TFlGLn)=1 Or (VS4TFlightGuide.TFlGLn) Is Null))
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.*, VS4VEmpAmassMonth.TEpsCheckGroup, VS4VEmpAmassMonth.TSmbTAMTAlias FROM (VS4VExportSlipGov LEFT JOIN VS4VEmpAmass ON (VS4VExportSlipGov.VESGYEAR = VS4VEmpAmass.VEPSYear) AND (VS4VExportSlipGov.VESGMONTH = VS4VEmpAmass.VEPSMonth) AND (VS4VExportSlipGov.TEmpCode = VS4VEmpAmass.TEpsTEmpCode)) LEFT JOIN VS4VEmpAmassMonth ON (VS4VExportSlipGov.TEmpCode = VS4VEmpAmassMonth.TEpsTEmpCode) AND (VS4VExportSlipGov.VESGMONTH = VS4VEmpAmassMonth.VEPSMonth) AND (VS4VExportSlipGov.VESGYEAR = VS4VEmpAmassMonth.VEPSYear) WHERE (((VS4VEmpAmassMonth.TEpsCheckGroup)=0) AND ((VS4VEmpAmassMonth.TSmbTAMTAlias)='SFUND'))
GO

CREATE VIEW VS4VGL AS  SELECT VS4TGLTrans.*, VS4TGLTransSub.*, VS4TGLBook.*, VS4TAccountPeriod.*, VS4TAccountYear.*, VS4TACGroup.*, VS4TACChart.*, VS4TACGroupSub.*, VS4TAP.TAPNName, VS4TAR.TARNName, VS4TAsset.TAssNo, VS4TAsset.TAssAlias, VS4TAsset.TAssName, VS4TGLSort.TGLSSort, VS4TChequeRec.TCHRChqDate, VS4TChequeSub.TCHSChqDate 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) LEFT JOIN VS4TGLSort ON VS4TGLTransSub.TGTSInputSource = VS4TGLSort.TGLSAlias) 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) LEFT JOIN VS4TChequeRec ON VS4TGLTransSub.TGTSChequeNo = VS4TChequeRec.TCHRNo) LEFT JOIN VS4TChequeSub ON VS4TGLTransSub.TGTSChequeNo = VS4TChequeSub.TCHSNo
GO

CREATE VIEW VS4VGLActive AS  SELECT VS4TGLTrans.TGLTConfirmStatus, VS4TGLTrans.TGLTApproveStatus, 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.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.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.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.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 VS4VGLARIVDBCN AS  SELECT VS4TGLTrans.*, VS4TGLTransSub.*, VS4TGLBook.*, VS4TAccountPeriod.*, VS4TAccountYear.*, VS4TACGroup.*, VS4TACChart.*, VS4TAP.TAPNName, VS4TAR.TARNName, VS4TACGroupSub.*, VS4TAsset.TAssNo, VS4TAsset.TAssAlias, VS4TAsset.TAssName, VS4TARInvoice.TIvoDeliveryStatus, VS4TARCreditNote.TRCNDeliveryStatus, VS4TAR.TARNTSAeCode, VS4TSaleArea.TSAeName, VS4TSaleZone.TSZnCode, VS4TSaleZone.TSZnName, VS4TSaleZoneGroup.TSZGCode, VS4TSaleZoneGroup.TSZGName, VS4TARInvoice.TIvoStartAgingDate FROM (VS4TSaleZone LEFT JOIN VS4TSaleZoneGroup ON VS4TSaleZone.TSZnTSZGCode = VS4TSaleZoneGroup.TSZGCode) RIGHT JOIN ((VS4TGLBook INNER JOIN (((((((VS4TARDebitNote RIGHT JOIN (VS4TARCreditNote RIGHT JOIN (VS4TARInvoice RIGHT JOIN VS4TGLTrans ON VS4TARInvoice.TIvoTGLTNo = VS4TGLTrans.TGLTNo) ON VS4TARCreditNote.TRCNTGLTNo = VS4TGLTrans.TGLTNo) ON VS4TARDebitNote.TDBNTGLTNo = VS4TGLTrans.TGLTNo) LEFT JOIN VS4TAR AS VS4TAR_1 ON VS4TARInvoice.TIvoTARNCode = VS4TAR_1.TARNCode) LEFT JOIN VS4TSaleArea AS VS4TSaleArea_1 ON VS4TAR_1.TARNTSAeCode = VS4TSaleArea_1.TSAeCode) LEFT JOIN VS4TAR AS VS4TAR_2 ON VS4TARCreditNote.TRCNTARNCode = VS4TAR_2.TARNCode) LEFT JOIN VS4TSaleArea AS VS4TSaleArea_2 ON VS4TAR_2.TARNTSAeCode = VS4TSaleArea_2.TSAeCode) LEFT JOIN VS4TAR AS VS4TAR_3 ON VS4TARDebitNote.TDBNTARNCode = VS4TAR_3.TARNCode) LEFT JOIN VS4TSaleArea AS VS4TSaleArea_3 ON VS4TAR_3.TARNTSAeCode = VS4TSaleArea_3.TSAeCode) 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) LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) 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) ON VS4TSaleZone.TSZnCode = VS4TSaleArea.TSaeTSZnCode
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 VS4VGLR AS  SELECT VS4TGLTrans.TGLTBalanceFlag, VS4TGLTransSub.TGTSTACPTACYID, VS4TGLTransSub.TGTSTACPID, VS4TGLTransSub.TGTSDebit, VS4TGLTransSub.TGTSCredit, VS4TACChart.TACCLevel, VS4TACChart.TACCTACGCode, VS4TACChart.TACCCode, VS4TACChart.TACCName, VS4TACChart.TACCName2, VS4TGLTrans.TGLTTGLBCode, VS4TGLTransSub.TGTSTSecCode, VS4TGLTrans.TGLTConfirmStatus, VS4TGLTrans.TGLTApproveStatus, VS4TACChart.TACCIsControl, VS4TACChart.TACCIsSpecial, VS4TAccountPeriod.TACPID, VS4TAccountYear.TACYID, VS4TGLTransSub.TGTSTPrjCode, VS4TGLTransSub.TGTSTPdtCode, VS4TGLTrans.TGLTDate, VS4TGLTransSub.TGTSTBraCode, VS4TGLTrans.TGLTNo, VS4TAccountPeriod.TACPTACYID, VS4TGLTrans.TGLTCancelStatus, VS4TAccountDay.TDayWeekDay, VS4TAccountDay.TDayWeek, VS4TAccountDay.TDayMonth, VS4TAccountDay.TDayQuarter, VS4TAccountDay.TDayYear FROM (VS4TGLBook INNER JOIN (VS4TGLTrans LEFT JOIN VS4TAccountDay ON VS4TGLTrans.TGLTDate = VS4TAccountDay.TDayDate) 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 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.TACPID = VS4TGLTransSub.TGTSTACPID) AND (VS4TAccountPeriod.TACPTACYID = VS4TGLTransSub.TGTSTACPTACYID)) 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, 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 VS4VGovPayment AS  SELECT VS4TGovPayment.*, VS4TGovPaymentMB.*, VS4TBranch.TBraCode, VS4TBranch.TBraName, VS4TBranch.TBraName2 FROM VS4TBranch RIGHT JOIN ((VS4TGovPayment INNER JOIN VS4TGovPaymentMB ON (VS4TGovPayment.TGvPType = VS4TGovPaymentMB.TGvMTGvPType) AND (VS4TGovPayment.TGvPYear = VS4TGovPaymentMB.TGvMTGvPYear) AND (VS4TGovPayment.TGvPMonth = VS4TGovPaymentMB.TGvMTGvPMonth)) LEFT JOIN VS4TEmployee ON VS4TGovPaymentMB.TGvMTEmpCode = VS4TEmployee.TEmpCode) ON VS4TBranch.TBraCode = VS4TEmployee.TEmpTBraCode
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 VS4VHR2PV AS  SELECT VS4TEmployee.TEmpTBraCode, VS4TEmployee.TEmpTDivCode, VS4TEmployee.TEmpTDepCode, VS4TEmployee.TEmpTSecCode, VS4TEmpSlipMB.TSmbTAmyCode, VS4TEmpSlipDoc.TEpsTSAPTEmTCode, VS4TEmpSlipDoc.TEpsTSaPDate, VS4TEmpSlipDoc.TEpsSalaryPeriod, VS4TAccountHR.TAHRTOExCode, VS4TAccountHR.TAHRIDLTOExCode, VS4TOtherExpense.TOExName AS VH2PTOExName, VS4TOtherExpense.TOExName2 AS VH2PTOExName2, VS4TOtherExpense_1.TOExName AS VH2PIDLTOExName, VS4TOtherExpense_1.TOExName2 AS VH2PIDLTOExName2, VS4TAccountHR.TAHRMode, Sum(VS4TEmpSlipMB.TSmbDebit-VS4TEmpSlipMB.TSmbCrebit) AS TSmbAmount, VS4TEmpAddMoney.TAmyTOExCode, VS4TEmpAddMoney.TAmyIDLTOExCode, VS4TOtherExpense_2.TOExName, VS4TOtherExpense_2.TOExName2, VS4TOtherExpense_3.TOExName AS VH2PAIDLTOExName, VS4TOtherExpense_3.TOExName2 AS VH2PAIDLTOExName2, VS4TEmpAddMoney.TAmyTAMTAlias, VS4TEmpAddMoney.TAmyTPyTAlias, VS4TPaymentType.TPyTName, VS4TAccountHR.TAHRTPyTAlias, VS4TPaymentType_1.TPyTName AS VH2PTPyTName FROM (VS4TEmployee INNER JOIN VS4TEmpSlipDoc ON VS4TEmployee.TEmpCode = VS4TEmpSlipDoc.TEpsTEmpCode) INNER JOIN ((((VS4TEmpAddMoney LEFT JOIN VS4TOtherExpense AS VS4TOtherExpense_2 ON VS4TEmpAddMoney.TAmyTOExCode = VS4TOtherExpense_2.TOExCode) LEFT JOIN VS4TOtherExpense AS VS4TOtherExpense_3 ON VS4TEmpAddMoney.TAmyIDLTOExCode = VS4TOtherExpense_3.TOExCode) LEFT JOIN VS4TPaymentType ON VS4TEmpAddMoney.TAmyTPyTAlias = VS4TPaymentType.TPyTAlias) INNER JOIN ((((VS4TEmpSlipMB LEFT JOIN VS4TAccountHR ON (VS4TEmpSlipMB.TSmbTAmyCode = VS4TAccountHR.TAHRTAmyCode) AND (VS4TEmpSlipMB.TSmbTDivCode = VS4TAccountHR.TAHRTDivCode)) LEFT JOIN VS4TOtherExpense ON VS4TAccountHR.TAHRTOExCode = VS4TOtherExpense.TOExCode) LEFT JOIN VS4TOtherExpense AS VS4TOtherExpense_1 ON VS4TAccountHR.TAHRIDLTOExCode = VS4TOtherExpense_1.TOExCode) LEFT JOIN VS4TPaymentType AS VS4TPaymentType_1 ON VS4TAccountHR.TAHRTPyTAlias = VS4TPaymentType_1.TPyTAlias) ON VS4TEmpAddMoney.TAmyCode = VS4TEmpSlipMB.TSmbTAmyCode) ON (VS4TEmpSlipDoc.TEpsNo = VS4TEmpSlipMB.TSmbTEpsNo) AND (VS4TEmpSlipDoc.TEpsCheckGroup = VS4TEmpSlipMB.TSmbTEpsCheckGroup) GROUP BY VS4TEmployee.TEmpTBraCode, VS4TEmployee.TEmpTDivCode, VS4TEmployee.TEmpTDepCode, VS4TEmployee.TEmpTSecCode, VS4TEmpSlipMB.TSmbTAmyCode, VS4TEmpSlipDoc.TEpsTSAPTEmTCode, VS4TEmpSlipDoc.TEpsTSaPDate, VS4TEmpSlipDoc.TEpsSalaryPeriod, VS4TAccountHR.TAHRTOExCode, VS4TAccountHR.TAHRIDLTOExCode, VS4TOtherExpense.TOExName, VS4TOtherExpense.TOExName2, VS4TOtherExpense_1.TOExName, VS4TOtherExpense_1.TOExName2, VS4TAccountHR.TAHRMode, VS4TEmpAddMoney.TAmyTOExCode, VS4TEmpAddMoney.TAmyIDLTOExCode, VS4TOtherExpense_2.TOExName, VS4TOtherExpense_2.TOExName2, VS4TOtherExpense_3.TOExName, VS4TOtherExpense_3.TOExName2, VS4TEmpAddMoney.TAmyTAMTAlias, VS4TEmpAddMoney.TAmyTPyTAlias, VS4TPaymentType.TPyTName, VS4TAccountHR.TAHRTPyTAlias, VS4TPaymentType_1.TPyTName, VS4TEmpSlipDoc.TEpsApproveStatus, VS4TEmpSlipDoc.TEpsCancelStatus HAVING (((VS4TEmpSlipDoc.TEpsApproveStatus)=1) AND ((VS4TEmpSlipDoc.TEpsCancelStatus)=0))
GO

CREATE VIEW VS4VImportCost AS  SELECT VS4TImportCost.*, VS4TImportCostMB.*, VS4TInventoryLOT.*, VS4TAP.TAPNName, VS4TAP.TAPNName2, VS4TProduct.TPdtName, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3 FROM (VS4TImportCost LEFT JOIN VS4TAP ON VS4TImportCost.TICATAPNCode = VS4TAP.TAPNCode) INNER JOIN ((VS4TImportCostMB LEFT JOIN VS4TInventoryLOT ON (VS4TImportCostMB.TICBLotDate = VS4TInventoryLOT.TIMCLotDate) AND (VS4TImportCostMB.TICBLotNo = VS4TInventoryLOT.TIMCLotNo) AND (VS4TImportCostMB.TICBSerialNo = VS4TInventoryLOT.TIMCSerialNo) AND (VS4TImportCostMB.TICBCustom1 = VS4TInventoryLOT.TIMCCustom1) AND (VS4TImportCostMB.TICBTPdtCode = VS4TInventoryLOT.TIMCTPdtCode)) LEFT JOIN VS4TProduct ON VS4TImportCostMB.TICBTPdtCode = VS4TProduct.TPdtCode) ON VS4TImportCost.TICANo = VS4TImportCostMB.TICBTICANo
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 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 VS4VInventAdjustS AS  SELECT VS4TInventoryMB.TInMTInvNo, VS4TInventoryMB.TInMLn, VS4TInventoryMB.TInMShow, VS4TInventoryMB.TInMTPdtCode, VS4TInventoryMB.TInMAmouQuantity, VS4TInventoryMB.TInMAmouQuantity2, VS4TInventoryMB.TInMAmouQuantity3, VS4TInventoryMB.TInMLOTNo, VS4TInventoryMB.TInMLOTDATE, VS4TInventoryMB.TInMTIvsCode, VS4TInventoryMB.TInMScrapLevel, VS4TInventoryMB.TInMSerialNo, VS4TInventoryMB.TInMDescription, VS4TInventoryMB.TInMCustom1, VS4TInventoryMB.TInMQuantityBase, VS4TInventoryMB.TInMTUntCode, VS4TInventoryMB.TInMTSODNo, VS4TInventoryMB.TInMTSOBLn, VS4TInventoryMB.TInMTLctCode, VS4TInventoryMB.TInMTPltCode, VS4TInventoryMB.TInMAgentPrice, VS4TLocation.TLctTWahCode, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtBarcode, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TInventoryLOT.*, VS4TInventAdjustMB.*, VS4TInventory.TInvNo FROM VS4TProduct INNER JOIN (VS4TLocation INNER JOIN (VS4TInventory INNER JOIN ((VS4TInventoryLOT INNER 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)) INNER JOIN VS4TInventAdjustMB ON (VS4TInventoryMB.TInMLn = VS4TInventAdjustMB.TIjMLn) AND (VS4TInventoryMB.TInMTInvNo = VS4TInventAdjustMB.TIjMTIjtNo)) ON VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo) ON VS4TLocation.TLctCode = VS4TInventoryMB.TInMTLctCode) ON VS4TProduct.TPdtCode = VS4TInventoryMB.TInMTPdtCode WHERE (((VS4TInventory.TInvTInTAlias)='STOCKADJUST'))
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 TInvNo, TInvMode, TInvTIBkCode, TInvDate, TInvInvoiceStatus, TInvTARNCode, TInvTInTAlias, TInvRefNo, TInvRefDate, TInvRefNo2, TInvRefDate2, TInvRefNo3, TInvRefDate3, TInvCustom1, TInvCustom2, TInvCustom3, TInvCustom4, TInvCustom5, TInvTPrjCode, TInvTJobNo, TInvTJbMLn, TInvTMPSNo, TInvTJPdNo, TInvTJPMLn, TInvTSecCode, TInvTDepCode, TInvTDivCode, TInvTBraCode, TInvFromTBraCode, TInvTotal, TInvTotalRecord, TInvTotalQuantity, TInvRequestCode, TInvRequestBy, TInvDescription, TInvGLMethod, TInvTGLTNo, TInvDeliveryStatus, TInvSpecialFlag, TInvIsCompleted, TInvCreateBy, TInvCreateDate, TInvEditCode, TInvEditBy, TInvEditDate, TInvConfirmStatus, TInvConfirmBy, TInvConfirmDate, TInvApproveStatus, TInvApproveBy, TInvApproveDate, TInvApproveNote, TInvRevision, TInvCancelStatus, TInvCancelBy, TInvCancelDate, TInvCancelNote, TInvCustomNo, TInvCustomDate, TInvTotalScrap, TInvTotalQScrap, TInvTotalQInput, TInvTotalAInput, TInvTotalRecordIn, TInvTotalPCScrap, TInvTotalPCQScrap, TInvSourceType, TInvRefNo4, TInvRefLn, VS4TInventoryType.TInTName, VS4TInventoryMB.*, TIMCTPdtCode, TIMCCustom1, TIMCSerialNo, TIMCLotNo, TIMCLotDate, TIMCReceiveNo, TIMCReceiveLn, TIMCJobCode, TIMCIsPremium, TIMCPremiumNote, TIMCCustom2, TIMCCustom3, TIMCCustom4, TIMCCustom5, TIMCScrapLevel, TIMCLotNo2, TIMCGrade, TIMCNoExpire, TIMCExpireDate, TIMCTCgTID, TIMCReserve, TIMCQAStatus, TIMCQANote, TIMCLastUnitCost, TIMCInputCost, TIMCPerQuantity, TIMCUnitCalc, TIMCUnitCost, TIMCCostCode, TIMCTPCTAlias, TIMCTAPNCode, TIMCInvoiceNo, TIMCInvoiceDate, TIMCTPODNo, TIMCTPOBLn, TIMCTPDELn, TIMCTUntCode, TIMCUnitRatio, TIMCUnit2Ratio, TIMCUnit3Ratio, TIMCLastDate, TIMCConsignFSDate, TIMCConsignLSDate, TIMCAccountLevel, TIMCIsOwner, TIMCPKI, TIMCBarcode, TIMCRFID, TIMCQuantityCost, TIMCInputTCurCode, TIMCInputCostRate, TIMCAdjustCost, TIMCStandardCost, TIMCAVGCost, TIMCEmbUnitDMVAR, TIMCEmbUnitDLVAR, TIMCUnitDMVariance, TIMCUnitDLVariance, TIMCEmbUnitOHVAR, TIMCUnitOHVariance, TIMCDutyAmount, TIMCCOA, TIMCProposeStatus, TIMCProposeNote, TIMCUnitRatioC, TIMCquantityCalc, TIMCDiscountText, TIMCDiscountTotal, TIMCTIvsCode, TIMCPrice, TIMCVATType, TIMCVATRate, TIMCVATAmount, TIMCTInTAlias, TIMCDutyRate, TIMCOtherFee, TIMCTransportFee, TIMCHandlingFee, TIMCFreightFee, TIMCInsurance, TIMCTransportDesc, TIMCDM, TIMCDL, TIMCOS, TIMCMOH, TIMCCostAmount, TIMCInputCostRateC, TIMCBahtBank, TIMCBahtCustom, TIMCBahtDif, 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 RIGHT 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, VS4TJob.TJobCode, VS4TInventoryMB.TInMTLctCode, VS4TAR.TARNName FROM VS4TInventoryType INNER JOIN ((((VS4TInventory LEFT JOIN VS4TProject ON VS4TInventory.TInvTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TJob ON VS4TInventory.TInvTJobNo = VS4TJob.TJobNo) LEFT JOIN VS4TAR ON VS4TInventory.TInvTARNCode = VS4TAR.TARNCode) LEFT JOIN VS4TInventoryMB ON VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo) ON VS4TInventoryType.TInTAlias = VS4TInventory.TInvTInTAlias WHERE (((VS4TInventoryMB.TInMLn)=1 Or (VS4TInventoryMB.TInMLn) Is Null))
GO

CREATE VIEW VS4VInventHSaleOut AS  SELECT VS4TInventory.*, VS4TInventoryType.*, VS4TSO.TSODTARNCode, VS4TSO.TSODCustomerName, VS4TARInvoice.TIvoCustomerName, VS4TARInvoice.TIvoSOCode, VS4TARInvoice2.TIv2LogisticType, VS4TARInvoice2.TIv2TruckNo, VS4TARInvoice.TIvoInvoiceStatus, VS4TARInvoice.TIvoTEmpCode, VS4TARInvoice.TIvoRefNo FROM VS4TInventoryType INNER JOIN (((VS4TInventory LEFT JOIN VS4TSO ON VS4TInventory.TInvRefNo = VS4TSO.TSODNo) LEFT JOIN VS4TARInvoice ON VS4TInventory.TInvRefNo3 = VS4TARInvoice.TIvoNo) LEFT JOIN VS4TARInvoice2 ON VS4TARInvoice.TIvoNo = VS4TARInvoice2.TIv2TIvoNo) 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 VS4VProductSafeH AS  SELECT VS4TProductSafeS.* FROM VS4TProductSafeS LEFT JOIN VS4TBranch ON VS4TProductSafeS.TPSSTBraCode = VS4TBranch.TBraCode WHERE (((VS4TBranch.TBraTBrTAlias)='HEADOFFICE'))
GO

CREATE VIEW VS4VInventoryA AS  SELECT VS4TInventory.*, VS4TInventoryMB.*, VS4TInventoryLOT.*, VS4TInventBook.* FROM (VS4TInventBook INNER JOIN VS4TInventory ON VS4TInventBook.TIBkCode = VS4TInventory.TInvTIBkCode) INNER JOIN (VS4TInventoryLOT INNER 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 WHERE (((VS4TInventoryMB.TInMAmouQuantity)>0) AND ((VS4TInventory.TInvApproveStatus)=1) AND ((VS4TInventory.TInvCancelStatus)=0) AND ((VS4TInventoryMB.TInMStatus)=1))
GO

CREATE VIEW VS4VInventoryAGP AS SELECT        VS4TInventory.TInvNo, VS4TInventory.TInvMode, VS4TInventory.TInvTIBkCode, VS4TInventory.TInvDate, VS4TInventory.TInvInvoiceStatus, VS4TInventory.TInvTARNCode,                           VS4TInventory.TInvTInTAlias, VS4TInventory.TInvRefNo, VS4TInventory.TInvRefDate, VS4TInventory.TInvRefNo2, VS4TInventory.TInvRefDate2, VS4TInventory.TInvRefNo3,                           VS4TInventory.TInvRefDate3, VS4TInventory.TInvCustom1, VS4TInventory.TInvCustom2, VS4TInventory.TInvCustom3, VS4TInventory.TInvCustom4, VS4TInventory.TInvCustom5,                           VS4TInventory.TInvTPrjCode, VS4TInventory.TInvTJobNo, VS4TInventory.TInvTJbMLn, VS4TInventory.TInvTSecCode, VS4TInventory.TInvTDepCode, VS4TInventory.TInvTDivCode,                           VS4TInventory.TInvTBraCode, VS4TInventory.TInvFromTBraCode, VS4TInventory.TInvTotal, VS4TInventory.TInvTotalRecord, VS4TInventory.TInvTotalQuantity, VS4TInventory.TInvRequestCode,                           VS4TInventory.TInvRequestBy, VS4TInventory.TInvDescription, VS4TInventory.TInvGLMethod, VS4TInventory.TInvTGLTNo, VS4TInventory.TInvDeliveryStatus, VS4TInventory.TInvSpecialFlag,                           VS4TInventory.TInvIsCompleted, VS4TInventory.TInvEditCode, VS4TInventory.TInvApproveStatus, VS4TInventory.TInvRevision, VS4TInventory.TInvCancelStatus, VS4TInventory.TInvCustomNo,                           VS4TInventory.TInvCustomDate, VS4TInventory.TInvTotalScrap, VS4TInventory.TInvTotalQScrap, VS4TInventory.TInvTotalQInput, VS4TInventory.TInvTotalAInput, VS4TInventory.TInvTotalRecordIn,                           VS4TInventory.TInvTotalPCScrap, VS4TInventory.TInvTotalPCQScrap, VS4TInventory.TInvSourceType, VS4TInventoryMB.TInMTInvNo, VS4TInventoryMB.TInMLn, VS4TInventoryMB.TInMTPdtCode,                           VS4TInventoryMB.TInMCustom1, VS4TInventoryMB.TInMSerialNo, VS4TInventoryMB.TInMLotNo, VS4TInventoryMB.TInMLotDate, VS4TInventoryMB.TInMScrapLevel,                           VS4TInventoryMB.TInMQuantityCalc, VS4TInventoryMB.TInMUnitRatio, VS4TInventoryMB.TInMQuantityBase, VS4TInventoryMB.TInMTUntCode, VS4TInventoryMB.TInMInQuantity,                           VS4TInventoryMB.TInMOutQuantity, VS4TInventoryMB.TInMAmouQuantity, VS4TInventoryMB.TInMAmouQuantity2, VS4TInventoryMB.TInMAmouQuantity3, VS4TInventoryMB.TInMAmount,                           VS4TInventoryMB.TInMStatus, VS4TInventoryMB.TInMFromTLctCode, VS4TInventoryMB.TInMTLctCode, VS4TInventoryMB.TInMDescription, VS4TInventoryMB.TInMTInTAlias,                           VS4TInventoryMB.TInMTSODNo, VS4TInventoryMB.TInMTSOBLn, VS4TInventoryMB.TInMTMDSLn, VS4TInventoryMB.TInMSourceType, VS4TInventoryMB.TInMSourceNo,                           VS4TInventoryMB.TInMSourceLn, VS4TInventoryMB.TInMQuantityText, VS4TInventoryMB.TInMArrear, VS4TInventoryMB.TInMShow, VS4TInventoryMB.TInMAgentPrice, VS4TInventoryMB.TInMQAStatus,                           VS4TInventoryMB.TInMQANote, VS4TInventoryMB.TInMTPltCode, VS4TInventoryMB.TInMFromTPltCode, VS4TInventoryMB.TInMQuantityCost, VS4TInventoryMB.TInMAgentPrice2,                           VS4TInventoryMB.TInMAgentPrice3, VS4TWarehouse.TWahName, VS4TLocation.TLctName, VS4TBranch.TBraName, VS4TProductType.TPTTName, VS4TInventoryType.TInTName,                           VS4TLocation.TLctTBraCode, VS4TAR.TARNName, VS4TAP.TAPNName, VS4TInventoryType.TInTSort, VS4TPOS.TPOSPrice, VS4TJob.TJobCode, VS4TJob.TJobCustomerName,                           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.TPdtTPG1Code,                           VS4TProduct.TPdtTPG2Code, VS4TProduct.TPdtTBndCode, VS4TProduct.TPdtImage1, VS4TProduct.TPdtTPCTAlias, VS4TProduct.TPdtOrderPoint, VS4TProduct.TPdtAvgUsePerDay,                           VS4TProduct.TPdtStockQuantity, VS4TProduct.TPdtLastCost, VS4TProduct.TPdtStdCostCode, VS4TProduct.TPdtAverageCost, VS4TProduct.TPdtSerialType, VS4TProduct.TPdtBackDayCalc,                           VS4TPR.TPRDNo, VS4TPR.TPRDTPRBCode, VS4TPR.TPRDDate, VS4TPR.TPRDRequestBy, VS4TPR.TPRDDescription, VS4TPR.TPRDTBraCode, VS4TPR.TPRDTDivCode,                           VS4TLocation_1.TLctTWahCode AS VInMFromTWahCode, VS4TWarehouse.TWahCode AS VInMToTWahCode, VS4TWarehouse.TWahCode, VS4TJobMB.TJbMQuantity, VS4TJobMB.TJbMTUntCode,                           VS4TJobMB.TJbMQuantity2, VS4TJobMB.TJbMQuantity3, VS4TJobMB.TJbMCustom1, VS4TJobMB.TJbMCustom2, VS4TJobMB.TJbMCustom3, VS4TJobMB.TJbMCustom4,                           VS4TJobMB.TJbMCustom5, 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.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.TPdtPremiumCost, VS4VProductGroup.TPdLName, VS4VProductGroup.TPSEName, VS4VProductGroup.TPG1Name,                           VS4TInventoryLOT.TIMCAccountLevel, VS4TProduct.TPdtLastBalDate, VS4TPOS.TPOSPackAlias2, VS4TProduct.TPdtStandardCost, VS4TInventoryLOT.TIMCInputTCurCode,                           VS4TInventoryLOT.TIMCInputCostRate, VS4TInventoryLOT.TIMCAdjustCost, VS4TInventoryLOT.TIMCStandardCost, VS4TInventoryLOT.TIMCAVGCost, VS4TProductType.TPTTStockCost,                           VS4TProduct.TPdtStockType, VS4TProduct.TPdtCode, VS4TInventoryLOT.TIMCCOA, VS4TInventoryLOT.TIMCProposeStatus, VS4TInventoryLOT.TIMCProposeNote, VS4TDivision.TDivName,                           VS4TDepartment.TDepName, VS4TProject.TPrjName, VS4TProductLPrice.TPLRPrice, VS4TInventoryLOT.TIMCUnitRatioC, VS4TInventoryLOT.TIMCquantityCalc, VS4TInventoryLOT.TIMCDutyRate,                           VS4TLocation.TLctType, VS4TWarehouse.TWahGroup, VS4TInventoryLOT.TIMCDiscountText, VS4TInventoryLOT.TIMCDiscountTotal, VS4TPRMB.TPRMCustom1, VS4TPRMB.TPRMCustom2,                           VS4TPRMB.TPRMCustom3, VS4TPRMB.TPRMCustom4, VS4TPRMB.TPRMCustom5, VS4TProduct.TPdtDescription, VS4TInventoryLOT.TIMCTIvsCode, VS4TInventoryLOT.TIMCPrice,                           VS4TInventoryLOT.TIMCVATType, VS4TInventoryMB.TInMTIvsCode, VS4TInventoryMB.TInMFromTIvsCode, VS4TAP_1.TAPNName AS VInvTAPNName, VS4TInventory.TInvTJStLn,                           VS4TJobMB.TJbMControlQty, VS4TInventoryMB.TInMFlag3, VS4TProduct.TPdtFlag1, VS4TInventoryLOT.TIMCMachineOutlet, VS4TInventoryLOT.TIMCMachineNo, VS4TInventoryType.TInTDescription,                           VS4TInventoryLOT.TIMCWastage, VS4TInventoryLOT.TIMCLOTCustom1, VS4TInventoryMB.TInMTACPTACYID, VS4TInventoryMB.TInMTACPID, VS4TInventoryLOT.TIMCReserve,                           VS4TAP.TAPNAddressBill, VS4TAP.TAPNPhone, VS4TInventory.TInvApproveDate, VS4TInventory.TInvConfirmStatus, VS4TInventoryLOT.TIMCCostInputType, VS4TInventory.TInvFlag1,                           VS4TPOMB.TPOBSourceNo, VS4TPOMB.TPOBSourceLn, VS4TJobProductionM.TJPMTSecCode, VS4TPOMBAOL.TPOATSecCode, VS4TProduct.TPdtAliasSlip, VS4TProductStat.TPMSLastPPrice,                           VS4TProductStat.TPMSLastPTCurCode, VS4TSOMB.TSOBPrice, VS4TSOMB.TSOBDiscountText, VS4TInventory.TInvConfirmBy FROM            VS4TInventoryType INNER JOIN                          VS4TProduct LEFT OUTER JOIN                          VS4TProductType ON VS4TProduct.TPdtTPTTCode = VS4TProductType.TPTTCode LEFT OUTER JOIN                          VS4VProductGroup ON VS4TProduct.TPdtCode = VS4VProductGroup.VPdtCode LEFT OUTER JOIN                          VS4VProductSafeH ON VS4TProduct.TPdtCode = VS4VProductSafeH.TPSSTPdtCode LEFT OUTER JOIN                          VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode INNER JOIN                          VS4TInventory LEFT OUTER JOIN                          VS4TDepartment ON VS4TInventory.TInvTDepCode = VS4TDepartment.TDepCode LEFT OUTER JOIN                          VS4TDivision ON VS4TInventory.TInvTDivCode = VS4TDivision.TDivCode LEFT OUTER JOIN                          VS4TBranch ON VS4TInventory.TInvTBraCode = VS4TBranch.TBraCode LEFT OUTER JOIN                          VS4TProject ON VS4TInventory.TInvTPrjCode = VS4TProject.TPrjCode LEFT OUTER JOIN                          VS4TJob ON VS4TInventory.TInvTJobNo = VS4TJob.TJobNo LEFT OUTER JOIN                          VS4TJobMB ON VS4TInventory.TInvTJbMLn = VS4TJobMB.TJbMLn AND VS4TInventory.TInvTJobNo = VS4TJobMB.TJbMTJobNo LEFT OUTER JOIN                          VS4TProduct AS VS4TProduct_1 ON VS4TJobMB.TJbMTPdtCode = VS4TProduct_1.TPdtCode LEFT OUTER JOIN                          VS4TAR ON VS4TInventory.TInvTARNCode = VS4TAR.TARNCode LEFT OUTER JOIN                          VS4TSection ON VS4TInventory.TInvTSecCode = VS4TSection.TSecCode LEFT OUTER JOIN                          VS4TAP AS VS4TAP_1 ON VS4TInventory.TInvTARNCode = VS4TAP_1.TAPNCode LEFT OUTER JOIN                          VS4TJobProductionM ON VS4TInventory.TInvTJPMLn = VS4TJobProductionM.TJPMLn AND VS4TInventory.TInvTJPdNo = VS4TJobProductionM.TJPMTJPdNo INNER JOIN                          VS4TInventoryMB LEFT OUTER JOIN                          VS4TLocation ON VS4TInventoryMB.TInMTLctCode = VS4TLocation.TLctCode LEFT OUTER JOIN                          VS4TWarehouse ON VS4TLocation.TLctTWahCode = VS4TWarehouse.TWahCode LEFT OUTER JOIN                          VS4TLocation AS VS4TLocation_1 ON VS4TInventoryMB.TInMFromTLctCode = VS4TLocation_1.TLctCode LEFT OUTER JOIN                          VS4TSOMB ON VS4TInventoryMB.TInMTSODNo = VS4TSOMB.TSOBTSODNo AND VS4TInventoryMB.TInMTSOBLn = VS4TSOMB.TSOBLn LEFT OUTER JOIN                          VS4TInventoryLOT LEFT OUTER JOIN                          VS4TAP ON VS4TInventoryLOT.TIMCTAPNCode = VS4TAP.TAPNCode 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 LEFT OUTER JOIN                          VS4TProductLPrice ON VS4TInventoryMB.TInMTPdtCode = VS4TProductLPrice.TPLRTPdtCode AND VS4TInventoryMB.TInMTLctCode = VS4TProductLPrice.TPLRTLctCode LEFT OUTER JOIN                          VS4TPOMB ON VS4TInventoryLOT.TIMCTPOBLn = VS4TPOMB.TPOBLn AND VS4TInventoryLOT.TIMCTPODNo = VS4TPOMB.TPOBTPODNo LEFT OUTER JOIN                          VS4TPRMB ON VS4TPOMB.TPOBSourceLn = VS4TPRMB.TPRMLn AND VS4TPOMB.TPOBSourceNo = VS4TPRMB.TPRMTPRDNo LEFT OUTER JOIN                          VS4TPR ON VS4TPRMB.TPRMTPRDNo = VS4TPR.TPRDNo LEFT OUTER JOIN                          VS4TPOMBAOL ON VS4TPOMB.TPOBLn = VS4TPOMBAOL.TPOATPOBLn AND VS4TPOMB.TPOBTPODNo = VS4TPOMBAOL.TPOATPOBTPODNo ON                           VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo ON VS4TProduct.TPdtCode = VS4TInventoryMB.TInMTPdtCode LEFT OUTER JOIN                          VS4TProductStat ON VS4TProduct.TPdtCode = VS4TProductStat.TPMSTPdtCode ON VS4TInventoryType.TInTAlias = VS4TInventory.TInvTInTAlias
GO

CREATE VIEW VS4VInventoryCost AS  SELECT VS4TInventory.TInvNo, VS4TInventory.TInvMode, VS4TInventory.TInvTIBkCode, VS4TInventory.TInvDate, VS4TInventory.TInvInvoiceStatus, VS4TInventory.TInvTARNCode, VS4TInventory.TInvTInTAlias, VS4TInventory.TInvRefNo, VS4TInventory.TInvRefDate, VS4TInventory.TInvRefNo2, VS4TInventory.TInvRefDate2, VS4TInventory.TInvRefNo3, VS4TInventory.TInvRefDate3, VS4TInventory.TInvCustom1, VS4TInventory.TInvCustom2, VS4TInventory.TInvCustom3, VS4TInventory.TInvCustom4, VS4TInventory.TInvCustom5, VS4TInventory.TInvTPrjCode, VS4TInventory.TInvTJobNo, VS4TInventory.TInvTJbMLn, VS4TInventory.TInvTMPSNo, VS4TInventory.TInvTJPdNo, VS4TInventory.TInvTJPMLn, VS4TInventory.TInvTSecCode, VS4TInventory.TInvTDepCode, VS4TInventory.TInvTDivCode, VS4TInventory.TInvTBraCode, VS4TInventory.TInvFromTBraCode, VS4TInventory.TInvTotal, VS4TInventory.TInvTotalRecord, VS4TInventory.TInvTotalQuantity, VS4TInventory.TInvRequestCode, VS4TInventory.TInvRequestBy, VS4TInventory.TInvDescription, VS4TInventory.TInvGLMethod, VS4TInventory.TInvTGLTNo, VS4TInventory.TInvDeliveryStatus, VS4TInventory.TInvSpecialFlag, VS4TInventory.TInvIsCompleted, VS4TInventory.TInvCreateBy, VS4TInventory.TInvCreateDate, VS4TInventory.TInvEditCode, VS4TInventory.TInvEditBy, VS4TInventory.TInvEditDate, VS4TInventory.TInvConfirmStatus, VS4TInventory.TInvConfirmBy, VS4TInventory.TInvConfirmDate, VS4TInventory.TInvApproveStatus, VS4TInventory.TInvApproveBy, VS4TInventory.TInvApproveDate, VS4TInventory.TInvApproveNote, VS4TInventory.TInvRevision, VS4TInventory.TInvCancelStatus, VS4TInventory.TInvFlag1, VS4TInventory.TInvCustomNo, VS4TInventory.TInvCustomDate, VS4TInventory.TInvTotalScrap, VS4TInventory.TInvTotalQScrap, VS4TInventory.TInvTotalQInput, VS4TInventory.TInvTotalAInput, VS4TInventory.TInvTotalRecordIn, VS4TInventory.TInvTotalPCScrap, VS4TInventory.TInvTotalPCQScrap, VS4TInventory.TInvSourceType, VS4TInventory.TInvRefNo4, VS4TInventory.TInvRefLn, VS4TInventory.TInvTJStLn, VS4TInventory.TInvStockCard, VS4TInventoryMB.TInMTInvNo, VS4TInventoryMB.TInMLn, VS4TInventoryMB.TInMTACPTACYID, VS4TInventoryMB.TInMTACPID, VS4TInventoryMB.TInMTPdtCode, VS4TInventoryMB.TInMCustom1, VS4TInventoryMB.TInMSerialNo, VS4TInventoryMB.TInMLotNo, VS4TInventoryMB.TInMLotDate, VS4TInventoryMB.TInMScrapLevel, VS4TInventoryMB.TInMQuantityCalc, VS4TInventoryMB.TInMUnitRatio, VS4TInventoryMB.TInMQuantityBase, VS4TInventoryMB.TInMTUntCode, VS4TInventoryMB.TInMInQuantity, VS4TInventoryMB.TInMOutQuantity, VS4TInventoryMB.TInMAmouQuantity, VS4TInventoryMB.TInMAmouQuantity2, VS4TInventoryMB.TInMAmouQuantity3, VS4TInventoryMB.TInMAmount, VS4TInventoryMB.TInMStatus, VS4TInventoryMB.TInMFromTLctCode, VS4TInventoryMB.TInMTLctCode, VS4TInventoryMB.TInMDescription, VS4TInventoryMB.TInMTInTAlias, VS4TInventoryMB.TInMTSODNo, VS4TInventoryMB.TInMTSOBLn, VS4TInventoryMB.TInMTMDSLn, VS4TInventoryMB.TInMSourceType, VS4TInventoryMB.TInMSourceNo, VS4TInventoryMB.TInMSourceLn, VS4TInventoryMB.TInMQuantityText, VS4TInventoryMB.TInMQuantityCutTxt, VS4TInventoryMB.TInMQuantityCut, VS4TInventoryMB.TInMQuantityFirst, VS4TInventoryMB.TInMArrear, VS4TInventoryMB.TInMShow, VS4TInventoryMB.TInMAgentPrice, VS4TInventoryMB.TInMQAStatus, VS4TInventoryMB.TInMQANote, VS4TInventoryMB.TInMFlag1, VS4TInventoryMB.TInMTPltCode, VS4TInventoryMB.TInMFromTPltCode, VS4TInventoryMB.TInMQuantityCost, VS4TInventoryMB.TInMTIvsCode, VS4TInventoryMB.TInMFromTIvsCode, VS4TInventoryMB.TInMUnitCalc, VS4TInventoryMB.TInMUnitCost, VS4TInventoryMB.TInMCustomerPallet, 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.TIMCFlag1, VS4TInventoryLOT.TIMCPKI, VS4TInventoryLOT.TIMCBarcode, VS4TInventoryLOT.TIMCRFID, VS4TInventoryLOT.TIMCQuantityCost, VS4TInventoryLOT.TIMCInputTCurCode, VS4TInventoryLOT.TIMCInputCostRate, VS4TInventoryLOT.TIMCAdjustCost, VS4TInventoryLOT.TIMCStandardCost, VS4TInventoryLOT.TIMCAVGCost, VS4TInventoryLOT.TIMCEmbUnitDMVAR, VS4TInventoryLOT.TIMCEmbUnitDLVAR, VS4TInventoryLOT.TIMCUnitDMVariance, VS4TInventoryLOT.TIMCUnitDLVariance, VS4TInventoryLOT.TIMCEmbUnitOHVAR, VS4TInventoryLOT.TIMCUnitOHVariance, VS4TInventoryLOT.TIMCDutyAmount, VS4TInventoryLOT.TIMCCOA, VS4TInventoryLOT.TIMCProposeStatus, VS4TInventoryLOT.TIMCProposeNote, VS4TInventoryLOT.TIMCUnitRatioC, VS4TInventoryLOT.TIMCquantityCalc, VS4TInventoryLOT.TIMCDiscountText, VS4TInventoryLOT.TIMCDiscountTotal, VS4TInventoryLOT.TIMCTIvsCode, VS4TInventoryLOT.TIMCPrice, VS4TInventoryLOT.TIMCVATType, VS4TInventoryLOT.TIMCVATRate, VS4TInventoryLOT.TIMCVATAmount, VS4TInventoryLOT.TIMCTInTAlias, VS4TInventoryLOT.TIMCDutyRate, VS4TInventoryLOT.TIMCInputCostRateC, VS4TInventoryLOT.TIMCOtherFee, VS4TInventoryLOT.TIMCTransportFee, VS4TInventoryLOT.TIMCHandlingFee, VS4TInventoryLOT.TIMCFreightFee, VS4TInventoryLOT.TIMCInsurance, VS4TInventoryLOT.TIMCTransportDesc, VS4TInventoryLOT.TIMCDM, VS4TInventoryLOT.TIMCDL, VS4TInventoryLOT.TIMCOS, VS4TInventoryLOT.TIMCMOH, VS4TInventoryLOT.TIMCCostAmount, VS4TInventoryLOT.TIMCBahtBank, VS4TInventoryLOT.TIMCBahtCustom, VS4TInventoryLOT.TIMCBahtDif, VS4TInventoryLOT.TIMCUnitRatioType, VS4TInventoryLOT.TIMCMachineNo, VS4TInventoryLOT.TIMCMachineOutlet, VS4TInventoryLOT.TIMCWastage, VS4TInventoryLOT.TIMCLOTCustom1, VS4TInventoryLOT.TIMCTPRMTPRDNo, VS4TInventoryLOT.TIMCTPRMLn, VS4TInventoryLOT.TIMCCostInputType, VS4TInventoryLOT.TIMCLOTCost, VS4TInventoryLOT.TIMCQCInputCount, VS4TInventoryLOT.TIMCQCSet, VS4TInventoryLOT.TIMCDiscountText2, VS4TInventoryLOT.TIMCAgingDate, VS4TInventoryLOT.TIMCSOH, VS4TInventoryLOT.TIMCSDL, VS4TInventoryLOT.TIMCStockId, VS4TInventoryLOT.TIMCUnitCostBFA, VS4TProduct.TPdtPremiumCost, VS4TProduct.TPdtStandardCost, VS4TProduct.TPdtAverageCost, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtTUntCode, VS4TInventoryCost.TIM2Ln, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TInventoryCost.TIM2Type, VS4TInventoryCost.TIM2DutyAmount, VS4TInventoryCost.TIM2OtherFee, VS4TInventoryCost.TIM2TransportFee, VS4TInventoryCost.TIM2HandlingFee, VS4TInventoryCost.TIM2FreightFee, VS4TInventoryCost.TIM2Insurance, VS4TInventoryCost.TIM2TransportDesc, VS4TInventoryCost.TIM2DM, VS4TInventoryCost.TIM2DL, VS4TInventoryCost.TIM2OS, VS4TInventoryCost.TIM2SDL, VS4TInventoryCost.TIM2SOH, VS4TInventoryCost.TIM2MOH, VS4TJobProductionM.TJPMTSepCode, VS4TMRPStepName.TSepName, VS4TMRPStepName.TSepTSecCode, VS4TSection.TSecName, VS4TInventoryLOT.TIMCCostDecimal FROM VS4TSection RIGHT JOIN (VS4TProduct INNER JOIN (VS4TMRPStepName RIGHT JOIN (((VS4TInventory LEFT JOIN VS4TJobProductionM ON (VS4TInventory.TInvTJPdNo = VS4TJobProductionM.TJPMTJPdNo) AND (VS4TInventory.TInvTJPMLn = VS4TJobProductionM.TJPMLn)) LEFT JOIN VS4TInventory2 ON VS4TInventory.TInvNo = VS4TInventory2.TIn2TInvNo) INNER JOIN ((VS4TInventoryLOT LEFT JOIN VS4TInventoryCost ON (VS4TInventoryLOT.TIMCLotDate = VS4TInventoryCost.TIM2LotDate) AND (VS4TInventoryLOT.TIMCLotNo = VS4TInventoryCost.TIM2LotNo) AND (VS4TInventoryLOT.TIMCSerialNo = VS4TInventoryCost.TIM2SerialNo) AND (VS4TInventoryLOT.TIMCCustom1 = VS4TInventoryCost.TIM2Custom1) AND (VS4TInventoryLOT.TIMCTPdtCode = VS4TInventoryCost.TIM2TPdtCode)) INNER 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 VS4TMRPStepName.TSepCode = VS4TJobProductionM.TJPMTSepCode) ON VS4TProduct.TPdtCode = VS4TInventoryMB.TInMTPdtCode) ON VS4TSection.TSecCode = VS4TMRPStepName.TSepTSecCode
GO

CREATE VIEW VS4VInventoryH AS  SELECT VS4TInventory.*, VS4TSection.TSecName, VS4TDepartment.TDepName, VS4TDivision.TDivName, VS4TBranch.TBraName, 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, VS4TJobMB.TJbMCustom4, VS4TJobMB.TJbMCustom5, 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 VS4VJobPending AS  SELECT VS4TJobMB.TJbMTJobNo, VS4TJobMB.TJbMTPdtCode, Sum(VS4TJobMB.TJbMQuantity) AS VJbMQuantity, Sum(VS4TJobMB.TJbMTotalArrear) AS VJbMTotalArrear FROM VS4TJobMB GROUP BY VS4TJobMB.TJbMTJobNo, VS4TJobMB.TJbMTPdtCode
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.TInMAmouQuantity2) AS TInMAmouQuantity2, Sum(VS4TInventoryMB.TInMAmouQuantity) AS TInMAmouQuantity, VS4TProduct.TPdtTUntCode3, 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.TPdtCode, VS4TProduct.TPdtBarcode, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtAliasSlip, VS4TProduct.TPdtAliasName, VS4TProduct.TPdtTDwgCode, VS4TProduct.TPdtTPrjCode, VS4TProduct.TPdtDescription, VS4TProduct.TPdtUnitType, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TProduct.TPdtUnit2Ratio, VS4TProduct.TPdtUnit3Ratio, VS4TProduct.TPdtUsage, VS4TProduct.TPdtUseBOM, VS4TProduct.TPdtOldCode, VS4TProduct.TPdtFactoryCode, VS4TProduct.TPdtFactoryOldCode, VS4TProduct.TPdtFactoryName, VS4TProduct.TPdtTransferCode, VS4TProduct.TPdtTransferName, VS4TProduct.TPdtTransferName2, VS4TProduct.TPdtTAPNCode, VS4TProduct.TPdtTPTTCode, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtTPSECode, VS4TProduct.TPdtTPS2Code, VS4TProduct.TPdtTPS3Code, VS4TProduct.TPdtTPS4Code, VS4TProduct.TPdtTPG1Code, VS4TProduct.TPdtTPG2Code, VS4TProduct.TPdtTPG3Code, VS4TProduct.TPdtTPG4Code, VS4TProduct.TPdtTBndCode, VS4TProduct.TPdtSceinceName, VS4TProduct.TPdtRegisterNo, VS4TProduct.TPdtUseMethod, VS4TProduct.TPdtWarning, VS4TProduct.TPdtGoodsDateLabel, VS4TProduct.TPdtExpDateLabel, VS4TProduct.TPdtQuantityText, VS4TProduct.TPdtIcon1, VS4TProduct.TPdtImage1, VS4TProduct.TPdtSpec1, VS4TProduct.TPdtTPCTAlias, VS4TProduct.TPdtCustom1, VS4TProduct.TPdtCustom2, VS4TProduct.TPdtCustom3, VS4TProduct.TPdtCustom4, VS4TProduct.TPdtCustom5, VS4TProduct.TPdtCustom6, VS4TProduct.TPdtCustom7, VS4TProduct.TPdtCustom8, VS4TProduct.TPdtCustom9, VS4TProduct.TPdtCustom10, VS4TProduct.TPdtSafeDayCalc, VS4TProduct.TPdtBackDayCalc, VS4TProduct.TPdtEOQ, VS4TProduct.TPdtOrderPoint, VS4TProduct.TPdtMaxUsePerDay, VS4TProduct.TPdtAvgUsePerDay, VS4TProduct.TPdtStockType, VS4TProduct.TPdtStockQuantity, VS4TProduct.TPdtFirstDate, VS4TProduct.TPdtLastMoveDate, VS4TProduct.TPdtFirstCostInStk, VS4TProduct.TPdtLastCost, VS4TProduct.TPdtStandardCost, VS4TProduct.TPdtStdCostCode, VS4TProduct.TPdtAutoCostCode, VS4TProduct.TPdtAverageCost, VS4TProduct.TPdtAreaCost, VS4TProduct.TPdtAmount, VS4TProduct.TPdtTPPuCode, VS4TProduct.TPdtSerialType, VS4TProduct.TPdtPurchaseFee, VS4TProduct.TPdtGroupReport, VS4TProduct.TPdtSlowDay, VS4TProduct.TPdtDeadDay, VS4TProduct.TPdtLastBalDate, VS4TProduct.TPdtCreateDate, VS4TProduct.TPdtEditCode, VS4TProduct.TPdtEditDate, VS4TProduct.TPdtTextSort, VS4TProduct.TPdtFlag1, VS4TProduct.TPdtPremiumCost, VS4TProduct.TPdtTACSCode, VS4TProduct.TPdtStartDate, VS4TProduct.TPdtEndDate, VS4TProduct.TPdtTripDay, VS4TProduct.TPdtTAILCode, VS4TProduct.TPdtTCouCode, VS4TProduct.TPdtONSale, VS4TProduct.TPdtSetType, VS4TProduct.TPdtRFID, VS4TProduct.TPdtHasExpireDate, VS4TProduct.TPdtRequireCOA, VS4TProduct.TPdtTBraCode, VS4TProduct.TPdtDayExpire, VS4TProduct.TPdtGrade, VS4TProduct.TPdtAdjustCost, VS4TProduct.TPdtLastUnitCost, VS4TProduct.TPdtUnitRatioType, VS4TProductSection.TPSEName, VS4TProductLine.TPdLName, VS4TPOS.TPOSPrice, VS4TAP.TAPNName, VS4TProduct2.TPd2TPdtCode, VS4TProduct2.TPd2Ln, VS4TProduct2.TPd2FillNameStock, VS4TProduct2.TPd2ScrapPCMRP, VS4TProduct2.TPd2ScrapPCReceive, VS4TProduct2.TPd2ScrapPCSend, VS4TProduct2.TPd2TaxType, VS4TProduct2.TPd2TaxRate, VS4TProduct2.TPd2CostFormula, VS4TProduct2.TPd2Weight, VS4TProduct2.TPd2SkipSuggest, VS4TProduct2.TPd2QuantityAlert, VS4TProduct2.TPd2TotalQuantity, VS4TProduct2.TPd2Yield, VS4TProduct2.TPd2HasBOM, VS4TProduct2.TPd2TWRMCode, VS4TProduct2.TPd2StdDM, VS4TProduct2.TPd2StdDL, VS4TProduct2.TPd2StdOH, VS4TProduct2.TPd2StdOHType, VS4TProduct2.TPd2ScrapType, VS4TProduct2.TPd2BulkPOrder, VS4TProduct2.TPd2MinimumPOrder, VS4TProduct2.TPd2MultiplePOrder, VS4TProduct2.TPd2VendorIncent1, VS4TProduct2.TPd2VendorIncent2, VS4TProduct2.TPd2BOMNote, VS4TProduct2.TPd2SelfMat, 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.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.TIMCPKI, VS4TInventoryLOT.TIMCBarcode, VS4TInventoryLOT.TIMCRFID, VS4TInventoryLOT.TIMCQuantityCost, VS4TInventoryLOT.TIMCInputTCurCode, VS4TInventoryLOT.TIMCInputCostRate, VS4TInventoryLOT.TIMCAdjustCost, VS4TInventoryLOT.TIMCStandardCost, VS4TInventoryLOT.TIMCAVGCost, VS4TInventoryLOT.TIMCEmbUnitDMVAR, VS4TInventoryLOT.TIMCEmbUnitDLVAR, VS4TInventoryLOT.TIMCUnitDMVariance, VS4TInventoryLOT.TIMCUnitDLVariance, VS4TInventoryLOT.TIMCEmbUnitOHVAR, VS4TInventoryLOT.TIMCUnitOHVariance, VS4TInventoryLOT.TIMCDutyAmount, VS4TInventoryLOT.TIMCCOA, VS4TInventoryLOT.TIMCProposeStatus, VS4TInventoryLOT.TIMCProposeNote, VS4TInventoryLOT.TIMCUnitRatioC, VS4TInventoryLOT.TIMCquantityCalc, VS4TInventoryLOT.TIMCDiscountText, VS4TInventoryLOT.TIMCDiscountTotal, VS4TInventoryLOT.TIMCTIvsCode, VS4TInventoryLOT.TIMCPrice, VS4TInventoryLOT.TIMCVATType, VS4TInventoryLOT.TIMCVATRate, VS4TInventoryLOT.TIMCVATAmount, VS4TInventoryLOT.TIMCTInTAlias, VS4TInventoryLOT.TIMCDutyRate, VS4TInventoryLOT.TIMCOtherFee, VS4TInventoryLOT.TIMCTransportFee, VS4TInventoryLOT.TIMCHandlingFee, VS4TInventoryLOT.TIMCFreightFee, VS4TInventoryLOT.TIMCInsurance, VS4TInventoryLOT.TIMCTransportDesc, VS4TInventoryLOT.TIMCDM, VS4TInventoryLOT.TIMCDL, VS4TInventoryLOT.TIMCOS, VS4TInventoryLOT.TIMCMOH, VS4TInventoryLOT.TIMCCostAmount, VS4TInventoryLOT.TIMCInputCostRateC, VS4TInventoryLOT.TIMCBahtBank, VS4TInventoryLOT.TIMCBahtCustom, VS4TInventoryLOT.TIMCBahtDif, VS4TInventory.TInvApproveStatus, VS4TInventory.TInvCancelStatus, VS4TInventoryMB.TInMQuantityBase, VS4TInventoryMB.TInMAmouQuantity, VS4TInventoryMB.TInMAmouQuantity2, VS4TInventoryMB.TInMAmouQuantity3, VS4TInventoryMB.TInMAmount, VS4TInventoryLOT.TIMCCostDecimal 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) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) 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 WHERE (((VS4TPOS.TPOSType)=0 Or (VS4TPOS.TPOSType) Is Null))
GO

CREATE VIEW VS4VInventoryLOTIN AS SELECT        VS4TInventory.TInvNo, VS4TInventory.TInvMode, VS4TInventory.TInvTIBkCode, VS4TInventory.TInvDate, VS4TInventory.TInvInvoiceStatus, VS4TInventory.TInvTARNCode,                           VS4TInventory.TInvTInTAlias, VS4TInventory.TInvRefNo, VS4TInventory.TInvRefDate, VS4TInventory.TInvRefNo2, VS4TInventory.TInvRefDate2, VS4TInventory.TInvRefNo3,                           VS4TInventory.TInvCustom1, VS4TInventory.TInvCustom2, VS4TInventory.TInvCustom3, VS4TInventory.TInvCustom4, VS4TInventory.TInvCustom5, VS4TInventory.TInvTPrjCode,                           VS4TInventory.TInvTJobNo, VS4TInventory.TInvTJbMLn, VS4TInventory.TInvTJPdNo, VS4TInventory.TInvTJPMLn, VS4TInventory.TInvTSecCode, VS4TInventory.TInvTDepCode,                           VS4TInventory.TInvTDivCode, VS4TInventory.TInvTBraCode, VS4TInventory.TInvFromTBraCode, VS4TInventory.TInvTotal, VS4TInventory.TInvTotalRecord, VS4TInventory.TInvTotalQuantity,                           VS4TInventory.TInvRequestCode, VS4TInventory.TInvRequestBy, VS4TInventory.TInvDescription, VS4TInventory.TInvGLMethod, VS4TInventory.TInvTGLTNo, VS4TInventory.TInvDeliveryStatus,                           VS4TInventory.TInvSpecialFlag, VS4TInventory.TInvIsCompleted, VS4TInventory.TInvEditCode, VS4TInventory.TInvApproveStatus, VS4TInventory.TInvRevision, VS4TInventory.TInvCancelStatus,                           VS4TInventory.TInvCustomNo, VS4TInventory.TInvCustomDate, VS4TInventory.TInvTotalScrap, VS4TInventory.TInvTotalQScrap, VS4TInventory.TInvTotalQInput, VS4TInventory.TInvTotalAInput,                           VS4TInventory.TInvTotalRecordIn, VS4TInventory.TInvTotalPCScrap, VS4TInventory.TInvTotalPCQScrap, VS4TInventory.TInvSourceType, VS4TInventoryMB.TInMTInvNo, VS4TInventoryMB.TInMLn,                           VS4TInventoryMB.TInMTPdtCode, VS4TInventoryMB.TInMCustom1, VS4TInventoryMB.TInMSerialNo, VS4TInventoryMB.TInMLotNo, VS4TInventoryMB.TInMLotDate, VS4TInventoryMB.TInMScrapLevel,                           VS4TInventoryMB.TInMQuantityCalc, VS4TInventoryMB.TInMUnitRatio, VS4TInventoryMB.TInMQuantityBase, VS4TInventoryMB.TInMTUntCode, VS4TInventoryMB.TInMInQuantity,                           VS4TInventoryMB.TInMOutQuantity, VS4TInventoryMB.TInMAmouQuantity, VS4TInventoryMB.TInMAmouQuantity2, VS4TInventoryMB.TInMAmouQuantity3, VS4TInventoryMB.TInMAmount,                           VS4TInventoryMB.TInMStatus, VS4TInventoryMB.TInMFromTLctCode, VS4TInventoryMB.TInMTLctCode, VS4TInventoryMB.TInMDescription, VS4TInventoryMB.TInMTInTAlias,                           VS4TInventoryMB.TInMTSODNo, VS4TInventoryMB.TInMTSOBLn, VS4TInventoryMB.TInMTMDSLn, VS4TInventoryMB.TInMSourceType, VS4TInventoryMB.TInMSourceNo,                           VS4TInventoryMB.TInMSourceLn, VS4TInventoryMB.TInMQuantityText, VS4TInventoryMB.TInMArrear, VS4TInventoryMB.TInMShow, VS4TInventoryMB.TInMAgentPrice, VS4TInventoryMB.TInMQAStatus,                           VS4TInventoryMB.TInMQANote, VS4TInventoryMB.TInMTPltCode, VS4TInventoryMB.TInMFromTPltCode, VS4TInventoryMB.TInMQuantityCost, VS4TWarehouse.TWahName, VS4TLocation.TLctName,                           VS4TBranch.TBraName, VS4TProductType.TPTTName, VS4TInventoryType.TInTName, VS4TLocation.TLctTBraCode, VS4TAR.TARNName, VS4TAP.TAPNName, VS4TInventoryType.TInTSort,                           VS4TPOS.TPOSPrice, VS4TJob.TJobCode, VS4TJob.TJobCustomerName, 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.TPdtTPG1Code, VS4TProduct.TPdtTPG2Code, VS4TProduct.TPdtTBndCode, VS4TProduct.TPdtImage1, VS4TProduct.TPdtTPCTAlias,                           VS4TProduct.TPdtOrderPoint, VS4TProduct.TPdtAvgUsePerDay, VS4TProduct.TPdtStockQuantity, VS4TProduct.TPdtLastCost, VS4TProduct.TPdtAverageCost, VS4TProduct.TPdtSerialType,                           VS4TProduct.TPdtBackDayCalc, VS4TPR.TPRDNo, VS4TPR.TPRDTPRBCode, VS4TPR.TPRDDate, VS4TPR.TPRDRequestBy, VS4TPR.TPRDDescription, VS4TPR.TPRDTBraCode,                           VS4TPR.TPRDTDivCode, VS4TLocation_1.TLctTWahCode AS VInMFromTWahCode, VS4TWarehouse.TWahCode AS VInMToTWahCode, VS4TWarehouse.TWahCode, VS4TJobMB.TJbMQuantity,                           VS4TJobMB.TJbMTUntCode, VS4TJobMB.TJbMQuantity2, VS4TJobMB.TJbMQuantity3, 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.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.TPdtPremiumCost, VS4VProductGroup.TPdLName,                           VS4VProductGroup.TPSEName, VS4VProductGroup.TPG1Name, VS4TInventoryLOT.TIMCAccountLevel, VS4TProduct.TPdtLastBalDate, VS4TPOS.TPOSPackAlias2, VS4TProduct.TPdtStandardCost,                           VS4TInventoryLOT.TIMCInputTCurCode, VS4TInventoryLOT.TIMCInputCostRate, VS4TInventoryLOT.TIMCAdjustCost, VS4TInventoryLOT.TIMCStandardCost, VS4TInventoryLOT.TIMCAVGCost,                           VS4TProductType.TPTTStockCost, VS4TProduct.TPdtStockType, VS4TProduct.TPdtCode, VS4TInventoryLOT.TIMCCOA, VS4TInventoryLOT.TIMCProposeStatus, VS4TInventoryLOT.TIMCProposeNote,                           VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TProject.TPrjName, VS4TProductLPrice.TPLRPrice, VS4TInventoryLOT.TIMCUnitRatioC, VS4TInventoryLOT.TIMCquantityCalc,                           VS4TInventoryLOT.TIMCDutyRate, VS4TLocation.TLctType, VS4TWarehouse.TWahGroup, VS4TInventoryLOT.TIMCDiscountText, VS4TInventoryLOT.TIMCDiscountTotal, VS4TProduct.TPdtDescription,                           VS4TInventoryLOT.TIMCTIvsCode, VS4TInventoryLOT.TIMCPrice, VS4TInventoryLOT.TIMCVATType, VS4TInventoryMB.TInMTIvsCode, VS4TInventoryMB.TInMFromTIvsCode,                           VS4TAP_1.TAPNName AS VInvTAPNName, VS4TInventory.TInvTJStLn, VS4TJobMB.TJbMControlQty, VS4TInventoryMB.TInMFlag3, VS4TProduct.TPdtFlag1, VS4TInventoryLOT.TIMCMachineOutlet,                           VS4TInventoryLOT.TIMCMachineNo, VS4TInventoryType.TInTDescription, VS4TInventoryLOT.TIMCWastage, VS4TInventoryLOT.TIMCLOTCustom1, VS4TInventoryMB.TInMTACPTACYID,                           VS4TInventoryMB.TInMTACPID, VS4TInventoryLOT.TIMCReserve, VS4TAP.TAPNAddressBill, VS4TAP.TAPNPhone, VS4TInventory.TInvApproveDate, VS4TInventory.TInvConfirmStatus,                           VS4TInventoryLOT.TIMCCostInputType, VS4TInventory.TInvFlag1, VS4TPOMB.TPOBSourceNo, VS4TPOMB.TPOBSourceLn, VS4TPR.TPRDTSecCode, VS4TPOMBAOL.TPOATSecCode,                           VS4TProduct.TPdtAliasSlip, VS4TProductStat.TPMSLastPPrice, VS4TProductStat.TPMSLastPTCurCode, VS4TProduct.TPdtUnit2Ratio, VS4TProduct.TPdtUnit3Ratio, VS4TInventoryLOT.TIMCFreightFee,                           VS4TInventoryLOT.TIMCInsurance, VS4TInventoryLOT.TIMCOtherFee, VS4TInventoryLOT.TIMCDutyAmount, VS4TInventoryLOT.TIMCUnitCostBFA, VS4TInventoryMB.TInMUnitCost,                           VS4TInventoryLOT.TIMCCostDecimal, VS4TAPInvoice.TIAPRefNo, VS4TPOMB.TPOBTotalArrear, VS4TPO.TPODConditionDay, VS4TInventory.TInvCreateBy, VS4TInventory.TInvCreateDate,                           VS4TPR.TPRDApproveBy, VS4TPO.TPODApproveBy FROM            VS4TInventoryType INNER JOIN                          VS4TPO RIGHT OUTER JOIN                          VS4TProduct LEFT OUTER JOIN                          VS4TProductType ON VS4TProduct.TPdtTPTTCode = VS4TProductType.TPTTCode LEFT OUTER JOIN                          VS4VProductGroup ON VS4TProduct.TPdtCode = VS4VProductGroup.VPdtCode LEFT OUTER JOIN                          VS4VProductSafeH ON VS4TProduct.TPdtCode = VS4VProductSafeH.TPSSTPdtCode LEFT OUTER JOIN                          VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode INNER JOIN                          VS4TInventory LEFT OUTER JOIN                          VS4TDepartment ON VS4TInventory.TInvTDepCode = VS4TDepartment.TDepCode LEFT OUTER JOIN                          VS4TDivision ON VS4TInventory.TInvTDivCode = VS4TDivision.TDivCode LEFT OUTER JOIN                          VS4TBranch ON VS4TInventory.TInvTBraCode = VS4TBranch.TBraCode LEFT OUTER JOIN                          VS4TProject ON VS4TInventory.TInvTPrjCode = VS4TProject.TPrjCode LEFT OUTER JOIN                          VS4TJob ON VS4TInventory.TInvTJobNo = VS4TJob.TJobNo LEFT OUTER JOIN                          VS4TJobMB ON VS4TInventory.TInvTJbMLn = VS4TJobMB.TJbMLn AND VS4TInventory.TInvTJobNo = VS4TJobMB.TJbMTJobNo LEFT OUTER JOIN                          VS4TAR ON VS4TInventory.TInvTARNCode = VS4TAR.TARNCode LEFT OUTER JOIN                          VS4TSection ON VS4TInventory.TInvTSecCode = VS4TSection.TSecCode LEFT OUTER JOIN                          VS4TAP AS VS4TAP_1 ON VS4TInventory.TInvTARNCode = VS4TAP_1.TAPNCode LEFT OUTER JOIN                          VS4TAPInvoice ON VS4TInventory.TInvRefNo3 = VS4TAPInvoice.TIAPNo INNER JOIN                          VS4TInventoryMB LEFT OUTER JOIN                          VS4TLocation ON VS4TInventoryMB.TInMTLctCode = VS4TLocation.TLctCode LEFT OUTER JOIN                          VS4TWarehouse ON VS4TLocation.TLctTWahCode = VS4TWarehouse.TWahCode LEFT OUTER JOIN                          VS4TLocation AS VS4TLocation_1 ON VS4TInventoryMB.TInMFromTLctCode = VS4TLocation_1.TLctCode LEFT OUTER JOIN                          VS4TInventoryLOT LEFT OUTER JOIN                          VS4TAP ON VS4TInventoryLOT.TIMCTAPNCode = VS4TAP.TAPNCode 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 LEFT OUTER JOIN                          VS4TProductLPrice ON VS4TInventoryMB.TInMTPdtCode = VS4TProductLPrice.TPLRTPdtCode AND VS4TInventoryMB.TInMTLctCode = VS4TProductLPrice.TPLRTLctCode LEFT OUTER JOIN                          VS4TPOMB ON VS4TInventoryLOT.TIMCTPOBLn = VS4TPOMB.TPOBLn AND VS4TInventoryLOT.TIMCTPODNo = VS4TPOMB.TPOBTPODNo LEFT OUTER JOIN                          VS4TPRMB ON VS4TPOMB.TPOBSourceLn = VS4TPRMB.TPRMLn AND VS4TPOMB.TPOBSourceNo = VS4TPRMB.TPRMTPRDNo LEFT OUTER JOIN                          VS4TPR ON VS4TPRMB.TPRMTPRDNo = VS4TPR.TPRDNo LEFT OUTER JOIN                          VS4TPOMBAOL ON VS4TPOMB.TPOBLn = VS4TPOMBAOL.TPOATPOBLn AND VS4TPOMB.TPOBTPODNo = VS4TPOMBAOL.TPOATPOBTPODNo ON                           VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo ON VS4TProduct.TPdtCode = VS4TInventoryMB.TInMTPdtCode LEFT OUTER JOIN                          VS4TProductStat ON VS4TProduct.TPdtCode = VS4TProductStat.TPMSTPdtCode ON VS4TPO.TPODNo = VS4TPOMB.TPOBTPODNo ON VS4TInventoryType.TInTAlias = VS4TInventory.TInvTInTAlias
GO

CREATE VIEW VS4VInventoryLOTQC AS  SELECT VS4TInventoryLOT.*, VS4TInventoryLOTQC.*, VS4TQC.*, VS4TQCMethod.*, VS4TInventory.*, VS4TProduct.TPdtBarcode, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TProduct.TPdtTAPNCode FROM VS4TQCMethod INNER JOIN (VS4TProduct INNER JOIN ((VS4TInventoryLOT LEFT JOIN VS4TInventory ON VS4TInventoryLOT.TIMCReceiveNo = VS4TInventory.TInvNo) INNER JOIN (VS4TInventoryLOTQC INNER JOIN VS4TQC ON VS4TInventoryLOTQC.TLQCTQCCCode = VS4TQC.TQCCCode) ON (VS4TInventoryLOT.TIMCTPdtCode = VS4TInventoryLOTQC.TLQCTIMCTPdtCode) AND (VS4TInventoryLOT.TIMCCustom1 = VS4TInventoryLOTQC.TLQCCustom1) AND (VS4TInventoryLOT.TIMCSerialNo = VS4TInventoryLOTQC.TLQCSerialNo) AND (VS4TInventoryLOT.TIMCLotNo = VS4TInventoryLOTQC.TLQCLotNo) AND (VS4TInventoryLOT.TIMCLotDate = VS4TInventoryLOTQC.TLQCLotDate)) ON VS4TProduct.TPdtCode = VS4TInventoryLOT.TIMCTPdtCode) ON VS4TQCMethod.TQMTCode = VS4TQC.TQCCTQMTCode
GO

CREATE VIEW VS4VInventoryM AS  SELECT VS4TInventory.TInvNo, VS4TInventory.TInvRefNo, VS4TInventory.TInvRefDate, VS4TInventory.TInvRefNo2, VS4TInventory.TInvRefDate2, VS4TInventory.TInvRefNo3, VS4TInventory.TInvCustom1, VS4TInventory.TInvCustom2, VS4TInventory.TInvCustom3, VS4TInventory.TInvCustom4, VS4TInventory.TInvCustom5, VS4TInventory.TInvTPrjCode, VS4TInventory.TInvTJobNo, VS4TInventory.TInvTJbMLn, VS4TInventory.TInvTJPdNo, VS4TInventory.TInvTJPMLn, VS4TInventory.TInvTSecCode, VS4TInventory.TInvTDepCode, VS4TInventory.TInvTDivCode, VS4TInventory.TInvTBraCode, VS4TInventory.TInvFromTBraCode, VS4TInventory.TInvTotal, VS4TInventory.TInvTotalRecord, VS4TInventory.TInvTotalQuantity, VS4TInventory.TInvRequestCode, VS4TInventory.TInvRequestBy, VS4TInventory.TInvDescription, VS4TInventory.TInvGLMethod, VS4TInventory.TInvTGLTNo, VS4TInventory.TInvDeliveryStatus, VS4TInventory.TInvSpecialFlag, VS4TInventory.TInvIsCompleted, VS4TInventory.TInvConfirmDate, VS4TInventory.TInvApproveStatus, VS4TInventory.TInvApproveBy, VS4TInventory.TInvApproveDate, VS4TInventory.TInvRevision, VS4TInventory.TInvCancelStatus, VS4TInventory.TInvCancelBy, VS4TInventory.TInvCancelDate, VS4TInventory.TInvCustomNo, VS4TInventory.TInvCustomDate, VS4TInventory.TInvTotalScrap, VS4TInventory.TInvTotalQScrap, VS4TInventory.TInvTotalQInput, VS4TInventory.TInvTotalAInput, VS4TInventory.TInvTotalRecordIn, VS4TInventory.TInvTotalPCScrap, VS4TInventory.TInvTotalPCQScrap, VS4TInventory.TInvSourceType, VS4TInventoryMB.TInMTInvNo, VS4TInventoryMB.TInMLn, VS4TInventoryMB.TInMTACPTACYID, VS4TInventoryMB.TInMTACPID, VS4TInventoryMB.TInMTPdtCode, VS4TInventoryMB.TInMCustom1, VS4TInventoryMB.TInMSerialNo, VS4TInventoryMB.TInMLotNo, VS4TInventoryMB.TInMLotDate, VS4TInventoryMB.TInMScrapLevel, VS4TInventoryMB.TInMQuantityCalc, VS4TInventoryMB.TInMUnitRatio, VS4TInventoryMB.TInMQuantityBase, VS4TInventoryMB.TInMTUntCode, VS4TInventoryMB.TInMInQuantity, VS4TInventoryMB.TInMOutQuantity, VS4TInventoryMB.TInMAmouQuantity, VS4TInventoryMB.TInMAmouQuantity2, VS4TInventoryMB.TInMAmouQuantity3, VS4TInventoryMB.TInMAmount, VS4TInventoryMB.TInMStatus, VS4TInventoryMB.TInMFromTLctCode, VS4TInventoryMB.TInMTLctCode, VS4TInventoryMB.TInMDescription, VS4TInventoryMB.TInMTInTAlias, VS4TInventoryMB.TInMTSODNo, VS4TInventoryMB.TInMTSOBLn, VS4TInventoryMB.TInMTMDSLn, VS4TInventoryMB.TInMSourceType, VS4TInventoryMB.TInMSourceNo, VS4TInventoryMB.TInMSourceLn, VS4TInventoryMB.TInMQuantityText, VS4TInventoryMB.TInMQuantityCutTxt, VS4TInventoryMB.TInMQuantityCut, VS4TInventoryMB.TInMQuantityFirst, VS4TInventoryMB.TInMArrear, VS4TInventoryMB.TInMShow, VS4TInventoryMB.TInMAgentPrice, VS4TInventoryMB.TInMQAStatus, VS4TInventoryMB.TInMQANote, VS4TInventoryMB.TInMTPltCode, VS4TInventoryMB.TInMFromTPltCode, VS4TInventoryMB.TInMQuantityCost, VS4TInventoryMB.TInMAgentPrice2, VS4TInventoryMB.TInMAgentPrice3, VS4TWarehouse.TWahName, VS4TLocation.TLctName, VS4TBranch.TBraName, VS4TProductType.TPTTName, VS4TInventoryType.TInTName, VS4TInventoryType.TInTDescription, VS4TLocation.TLctTBraCode, VS4TAR.TARNName, VS4TAP.TAPNName, VS4TInventoryType.TInTSort, VS4TPOS.TPOSPrice, VS4TJob.TJobCode, VS4TJob.TJobCustomerName, 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.TPdtTPG1Code, VS4TInventory.TInvDate, VS4TProduct.TPdtTPG2Code, VS4TProduct.TPdtTBndCode, VS4TProduct.TPdtImage1, VS4TProduct.TPdtTPCTAlias, VS4TProduct.TPdtOrderPoint, VS4TProduct.TPdtAvgUsePerDay, VS4TProduct.TPdtStockQuantity, VS4TProduct.TPdtLastCost, VS4TProduct.TPdtStdCostCode, VS4TProduct.TPdtAverageCost, VS4TProduct.TPdtSerialType, VS4TProduct.TPdtBackDayCalc, VS4TWarehouse_1.TWahCode AS VInMFromTWahCode, VS4TWarehouse.TWahCode AS VInMToTWahCode, VS4TWarehouse.TWahCode, VS4TProduct.TPdtTPPuCode, VS4TInventoryType.TInTInputCost, VS4VProductSafeH.TPSSStockMin, VS4TAR.TARNAddressBill, VS4TProduct.TPdtFlag1, VS4TProduct.TPdtPremiumCost, VS4VProductGroup.TPdLName, VS4VProductGroup.TPSEName, VS4VProductGroup.TPG1Name, VS4TProduct.TPdtLastBalDate, VS4TPOS.TPOSPackAlias2, VS4TProduct.TPdtStandardCost, VS4TProductType.TPTTStockCost, VS4TProduct.TPdtStockType, VS4TProduct.TPdtCode, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TProject.TPrjName, VS4TProductLPrice.TPLRPrice, VS4TLocation.TLctType, VS4TWarehouse.TWahGroup, VS4TProduct.TPdtDescription, VS4TInventoryMB.TInMTIvSCode, 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.TIMCAccountLevel, VS4TInventoryLOT.TIMCIsOwner, VS4TInventoryLOT.TIMCPKI, VS4TInventoryLOT.TIMCBarcode, VS4TInventoryLOT.TIMCRFID, VS4TInventoryLOT.TIMCQuantityCost, VS4TInventoryLOT.TIMCInputTCurCode, VS4TInventoryLOT.TIMCInputCostRate, VS4TInventoryLOT.TIMCAdjustCost, VS4TInventoryLOT.TIMCStandardCost, VS4TInventoryLOT.TIMCAVGCost, VS4TInventoryLOT.TIMCDutyAmount, VS4TInventoryLOT.TIMCCOA, VS4TInventoryLOT.TIMCProposeStatus, VS4TInventoryLOT.TIMCProposeNote, VS4TInventoryLOT.TIMCUnitRatioC, VS4TInventoryLOT.TIMCquantityCalc, VS4TInventoryLOT.TIMCDiscountText, VS4TInventoryLOT.TIMCDiscountTotal, VS4TInventoryLOT.TIMCPrice, VS4TInventoryLOT.TIMCVATType, VS4TInventoryLOT.TIMCVATRate, VS4TInventoryLOT.TIMCVATAmount, VS4TInventoryLOT.TIMCTInTAlias, VS4TInventoryLOT.TIMCDutyRate, VS4TInventoryLOT.TIMCInputCostRateC, VS4TInventoryLOT.TIMCOtherFee, VS4TInventoryLOT.TIMCTransportFee, VS4TInventoryLOT.TIMCHandlingFee, VS4TInventoryLOT.TIMCFreightFee, VS4TInventoryLOT.TIMCInsurance, VS4TInventoryLOT.TIMCTransportDesc, VS4TInventoryLOT.TIMCDM, VS4TInventoryLOT.TIMCDL, VS4TInventoryLOT.TIMCOS, VS4TInventoryLOT.TIMCMOH, VS4TInventoryLOT.TIMCCostAmount, VS4TInventoryMB.TInMFromTIvsCode, VS4TInventoryMB.TInMCustomerPallet, VS4TInventoryLOT.TIMCCostInputType, VS4TInventoryLOT.TIMCQCInputCount, VS4TInventoryLOT.TIMCQCSet, VS4TSOMB.TSOBFactoryCode, VS4TPOMB.TPOBSourceNo, VS4TPOMB.TPOBSourceLn, VS4TPR.TPRDTSecCode, VS4TPOMBAOL.TPOATSecCode, VS4TInventoryLOT.TIMCCostDecimal, VS4TInventory.TInvConfirmStatus 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.TInvTJbMLn = VS4TJobMB.TJbMLn) AND (VS4TInventory.TInvTJobNo = VS4TJobMB.TJbMTJobNo)) LEFT JOIN VS4TProduct AS VS4TProduct_1 ON VS4TJobMB.TJbMTPdtCode = VS4TProduct_1.TPdtCode) 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 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.TInMTSODNo = VS4TSOMB.TSOBTSODNo) AND (VS4TInventoryMB.TInMTSOBLn = VS4TSOMB.TSOBLn)) LEFT JOIN (VS4TInventoryLOT LEFT JOIN VS4TAP ON VS4TInventoryLOT.TIMCTAPNCode = VS4TAP.TAPNCode) 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)) LEFT JOIN VS4TProductLPrice ON (VS4TInventoryMB.TInMTPdtCode = VS4TProductLPrice.TPLRTPdtCode) AND (VS4TInventoryMB.TInMTLctCode = VS4TProductLPrice.TPLRTLctCode)) LEFT JOIN VS4TPOMB ON (VS4TInventoryLOT.TIMCTPOBLn = VS4TPOMB.TPOBLn) AND (VS4TInventoryLOT.TIMCTPODNo = VS4TPOMB.TPOBTPODNo)) LEFT JOIN VS4TPRMB ON (VS4TPOMB.TPOBSourceLn = VS4TPRMB.TPRMLn) AND (VS4TPOMB.TPOBSourceNo = VS4TPRMB.TPRMTPRDNo)) LEFT JOIN VS4TPR ON VS4TPRMB.TPRMTPRDNo = VS4TPR.TPRDNo) LEFT JOIN VS4TPOMBAOL ON (VS4TPOMB.TPOBLn = VS4TPOMBAOL.TPOATPOBLn) AND (VS4TPOMB.TPOBTPODNo = VS4TPOMBAOL.TPOATPOBTPODNo)) 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 VS4VInventoryMQC AS  SELECT VS4TInventory.TInvNo, VS4TInventory.TInvRefNo, VS4TInventory.TInvRefDate, VS4TInventory.TInvRefNo2, VS4TInventory.TInvRefDate2, VS4TInventory.TInvRefNo3, VS4TInventory.TInvCustom1, VS4TInventory.TInvCustom2, VS4TInventory.TInvCustom3, VS4TInventory.TInvCustom4, VS4TInventory.TInvCustom5, VS4TInventory.TInvTPrjCode, VS4TInventory.TInvTJobNo, VS4TInventory.TInvTJbMLn, VS4TInventory.TInvTJPdNo, VS4TInventory.TInvTJPMLn, VS4TInventory.TInvTSecCode, VS4TInventory.TInvTDepCode, VS4TInventory.TInvTDivCode, VS4TInventory.TInvTBraCode, VS4TInventory.TInvFromTBraCode, VS4TInventory.TInvTotal, VS4TInventory.TInvTotalRecord, VS4TInventory.TInvTotalQuantity, VS4TInventory.TInvRequestCode, VS4TInventory.TInvRequestBy, VS4TInventory.TInvDescription, VS4TInventory.TInvGLMethod, VS4TInventory.TInvDeliveryStatus, VS4TInventory.TInvSpecialFlag, VS4TInventory.TInvIsCompleted, VS4TInventory.TInvEditCode, VS4TInventory.TInvEditBy, VS4TInventory.TInvEditDate, VS4TInventory.TInvConfirmStatus, VS4TInventory.TInvConfirmBy, VS4TInventory.TInvConfirmDate, VS4TInventory.TInvApproveStatus, VS4TInventory.TInvApproveBy, VS4TInventory.TInvApproveDate, VS4TInventory.TInvRevision, VS4TInventory.TInvCancelStatus, VS4TInventory.TInvCancelBy, VS4TInventory.TInvCancelDate, VS4TInventory.TInvCustomNo, VS4TInventory.TInvCustomDate, VS4TInventory.TInvTotalScrap, VS4TInventory.TInvTotalQScrap, VS4TInventory.TInvTotalQInput, VS4TInventory.TInvTotalAInput, VS4TInventory.TInvTotalRecordIn, VS4TInventory.TInvTotalPCScrap, VS4TInventory.TInvTotalPCQScrap, VS4TInventory.TInvSourceType, VS4TInventoryMB.TInMTInvNo, VS4TInventoryMB.TInMLn, VS4TInventoryMB.TInMTACPTACYID, VS4TInventoryMB.TInMTACPID, VS4TInventoryMB.TInMTPdtCode, VS4TInventoryMB.TInMCustom1, VS4TInventoryMB.TInMSerialNo, VS4TInventoryMB.TInMLotNo, VS4TInventoryMB.TInMLotDate, VS4TInventoryMB.TInMScrapLevel, VS4TInventoryMB.TInMQuantityCalc, VS4TInventoryMB.TInMUnitRatio, VS4TInventoryMB.TInMQuantityBase, VS4TInventoryMB.TInMTUntCode, VS4TInventoryMB.TInMInQuantity, VS4TInventoryMB.TInMOutQuantity, VS4TInventoryMB.TInMAmouQuantity, VS4TInventoryMB.TInMAmouQuantity2, VS4TInventoryMB.TInMAmouQuantity3, VS4TInventoryMB.TInMAmount, VS4TInventoryMB.TInMStatus, VS4TInventoryMB.TInMFromTLctCode, VS4TInventoryMB.TInMTLctCode, VS4TInventoryMB.TInMDescription, VS4TInventoryMB.TInMTInTAlias, VS4TInventoryMB.TInMTSODNo, VS4TInventoryMB.TInMTSOBLn, VS4TInventoryMB.TInMTMDSLn, VS4TInventoryMB.TInMSourceType, VS4TInventoryMB.TInMSourceNo, VS4TInventoryMB.TInMSourceLn, VS4TInventoryMB.TInMQuantityText, VS4TInventoryMB.TInMQuantityCutTxt, VS4TInventoryMB.TInMQuantityCut, VS4TInventoryMB.TInMQuantityFirst, VS4TInventoryMB.TInMArrear, VS4TInventoryMB.TInMShow, VS4TInventoryMB.TInMAgentPrice, VS4TInventoryMB.TInMQAStatus, VS4TInventoryMB.TInMQANote, VS4TInventoryMB.TInMTPltCode, VS4TInventoryMB.TInMFromTPltCode, VS4TInventoryMB.TInMQuantityCost, VS4TInventoryMB.TInMAgentPrice2, VS4TInventoryMB.TInMAgentPrice3, VS4TWarehouse.TWahName, VS4TLocation.TLctName, VS4TBranch.TBraName, VS4TProductType.TPTTName, VS4TInventoryType.TInTName, VS4TInventoryType.TInTDescription, VS4TLocation.TLctTBraCode, VS4TAR.TARNName, VS4TAP.TAPNName, VS4TInventoryType.TInTSort, VS4TPOS.TPOSPrice, VS4TJob.TJobCode, VS4TJob.TJobCustomerName, 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.TPdtTPG1Code, VS4TProduct.TPdtTPG2Code, VS4TProduct.TPdtTBndCode, VS4TProduct.TPdtImage1, VS4TProduct.TPdtTPCTAlias, VS4TProduct.TPdtOrderPoint, VS4TProduct.TPdtAvgUsePerDay, VS4TProduct.TPdtStockQuantity, VS4TProduct.TPdtLastCost, VS4TProduct.TPdtStdCostCode, VS4TProduct.TPdtAverageCost, VS4TProduct.TPdtSerialType, VS4TWarehouse_1.TWahCode AS VInMFromTWahCode, VS4TWarehouse.TWahCode AS VInMToTWahCode, VS4TWarehouse.TWahCode, VS4TProduct.TPdtTPPuCode, VS4TInventoryType.TInTInputCost, VS4TAR.TARNAddressBill, VS4TProduct.TPdtFlag1, VS4TProduct.TPdtLastBalDate, VS4TPOS.TPOSPackAlias2, VS4TProduct.TPdtStandardCost, VS4TProductType.TPTTStockCost, VS4TProduct.TPdtStockType, VS4TProduct.TPdtCode, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TProject.TPrjName, VS4TProductSection.TPSECode, VS4TLocation.TLctType, VS4TWarehouse.TWahGroup, VS4TProduct.TPdtDescription, VS4TInventoryMB.TInMTIvSCode, 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.TIMCAccountLevel, VS4TInventoryLOT.TIMCIsOwner, VS4TInventoryLOT.TIMCPKI, VS4TInventoryLOT.TIMCBarcode, VS4TInventoryLOT.TIMCRFID, VS4TInventoryLOT.TIMCQuantityCost, VS4TInventoryLOT.TIMCInputTCurCode, VS4TInventoryLOT.TIMCInputCostRate, VS4TInventoryLOT.TIMCAdjustCost, VS4TInventoryLOT.TIMCStandardCost, VS4TInventoryLOT.TIMCAVGCost, VS4TInventoryLOT.TIMCDutyAmount, VS4TInventoryLOT.TIMCCOA, VS4TInventoryLOT.TIMCProposeStatus, VS4TInventoryLOT.TIMCProposeNote, VS4TInventoryLOT.TIMCUnitRatioC, VS4TInventoryLOT.TIMCquantityCalc, VS4TInventoryLOT.TIMCDiscountText, VS4TInventoryLOT.TIMCDiscountTotal, VS4TInventoryLOT.TIMCPrice, VS4TInventoryLOT.TIMCVATType, VS4TInventoryLOT.TIMCVATRate, VS4TInventoryLOT.TIMCVATAmount, VS4TInventoryLOT.TIMCTInTAlias, VS4TInventoryLOT.TIMCDutyRate, VS4TInventoryLOT.TIMCInputCostRateC, VS4TInventoryLOT.TIMCOtherFee, VS4TInventoryLOT.TIMCTransportFee, VS4TInventoryLOT.TIMCHandlingFee, VS4TInventoryLOT.TIMCFreightFee, VS4TInventoryLOT.TIMCInsurance, VS4TInventoryLOT.TIMCTransportDesc, VS4TInventoryLOT.TIMCDM, VS4TInventoryLOT.TIMCDL, VS4TInventoryLOT.TIMCOS, VS4TInventoryLOT.TIMCMOH, VS4TInventoryLOT.TIMCCostAmount, VS4TInventoryMB.TInMFromTIvsCode, VS4TInventoryMB.TInMCustomerPallet, VS4TInventoryLOT.TIMCCostInputType, VS4TInventoryLOT.TIMCQCInputCount, VS4TInventoryLOT.TIMCQCSet, VS4TJobProduction.TJPdDate, VS4TJobProductionM.TJPMProcessStatus, VS4TJobProduction.TJPdCancelStatus, VS4TJobProduction.TJPdApproveStatus, VS4TJobProductionM.TJPMStartDate, VS4TJobProductionM.TJPMEndDate, VS4TInventory.TInvTJStLn, VS4TJobProductionM.TJPMFinishPC, VS4TJobProductionM.TJPMArrear, VS4TInventoryLOT.TIMCCostDecimal FROM VS4TInventoryType INNER JOIN (VS4TSO RIGHT JOIN ((((((VS4TProduct LEFT JOIN VS4TProductType ON VS4TProduct.TPdtTPTTCode = VS4TProductType.TPTTCode) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) LEFT JOIN VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode) LEFT JOIN VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code) 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 VS4TProduct AS VS4TProduct_1 ON VS4TJobMB.TJbMTPdtCode = VS4TProduct_1.TPdtCode) LEFT JOIN VS4TAR ON VS4TInventory.TInvTARNCode = VS4TAR.TARNCode) LEFT JOIN VS4TSection ON VS4TInventory.TInvTSecCode = VS4TSection.TSecCode) LEFT JOIN VS4TJobProductionM ON (VS4TInventory.TInvTJPdNo = VS4TJobProductionM.TJPMTJPdNo) AND (VS4TInventory.TInvTJPMLn = VS4TJobProductionM.TJPMLn)) LEFT JOIN VS4TJobProduction ON VS4TInventory.TInvTJPdNo = VS4TJobProduction.TJPdNo) INNER JOIN ((((((VS4TInventoryMB LEFT JOIN VS4TLocation ON VS4TInventoryMB.TInMTLctCode = VS4TLocation.TLctCode) LEFT JOIN VS4TWarehouse ON VS4TLocation.TLctTWahCode = VS4TWarehouse.TWahCode) 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 VS4VInventoryOUT AS SELECT VS4TInventory.TInvNo, VS4TInventory.TInvMode, VS4TInventory.TInvTIBkCode, VS4TInventory.TInvDate, VS4TInventory.TInvTARNCode, VS4TInventory.TInvTInTAlias, VS4TInventory.TInvRefNo,                    VS4TInventory.TInvRefDate, VS4TInventory.TInvRefNo2, VS4TInventory.TInvRefDate2, VS4TInventory.TInvRefNo3, VS4TInventory.TInvRefDate3, VS4TInventory.TInvCustom1, VS4TInventory.TInvCustom2,                    VS4TInventory.TInvCustom3, VS4TInventory.TInvCustom4, VS4TInventory.TInvCustom5, VS4TInventory.TInvTPrjCode, VS4TInventory.TInvTJobNo, VS4TInventory.TInvTJbMLn, VS4TInventory.TInvTJPdNo,                    VS4TInventory.TInvTJPMLn, VS4TInventory.TInvTSecCode, VS4TInventory.TInvTDepCode, VS4TInventory.TInvTDivCode, VS4TInventory.TInvTBraCode, VS4TInventory.TInvFromTBraCode,                    VS4TInventory.TInvTotal, VS4TInventory.TInvTotalRecord, VS4TInventory.TInvTotalQuantity, VS4TInventory.TInvRequestCode, VS4TInventory.TInvRequestBy, VS4TInventory.TInvDescription,                    VS4TInventory.TInvDeliveryStatus, VS4TInventory.TInvSpecialFlag, VS4TInventory.TInvIsCompleted, VS4TInventory.TInvEditCode, VS4TInventory.TInvApproveStatus, VS4TInventory.TInvRevision,                    VS4TInventory.TInvCancelStatus, VS4TInventory.TInvCustomNo, VS4TInventory.TInvCustomDate, VS4TInventory.TInvTotalScrap, VS4TInventory.TInvTotalQScrap, VS4TInventory.TInvTotalQInput,                    VS4TInventory.TInvTotalAInput, VS4TInventory.TInvTotalRecordIn, VS4TInventory.TInvTotalPCScrap, VS4TInventory.TInvTotalPCQScrap, VS4TInventory.TInvSourceType, VS4TInventoryMB.TInMTInvNo,                    VS4TInventoryMB.TInMLn, VS4TInventoryMB.TInMTPdtCode, VS4TInventoryMB.TInMCustom1, VS4TInventoryMB.TInMSerialNo, VS4TInventoryMB.TInMLotNo, VS4TInventoryMB.TInMLotDate,                    VS4TInventoryMB.TInMScrapLevel, VS4TInventoryMB.TInMQuantityCalc, VS4TInventoryMB.TInMUnitRatio, VS4TInventoryMB.TInMQuantityBase, VS4TInventoryMB.TInMTUntCode,                    VS4TInventoryMB.TInMInQuantity, VS4TInventoryMB.TInMOutQuantity, VS4TInventoryMB.TInMAmouQuantity, VS4TInventoryMB.TInMAmouQuantity2, VS4TInventoryMB.TInMAmouQuantity3,                    VS4TInventoryMB.TInMAmount, VS4TInventoryMB.TInMStatus, VS4TInventoryMB.TInMFromTLctCode, VS4TInventoryMB.TInMTLctCode, VS4TInventoryMB.TInMDescription, VS4TInventoryMB.TInMTInTAlias,                    VS4TInventoryMB.TInMTSODNo, VS4TInventoryMB.TInMTSOBLn, VS4TInventoryMB.TInMTMDSLn, VS4TInventoryMB.TInMSourceType, VS4TInventoryMB.TInMSourceNo, VS4TInventoryMB.TInMSourceLn,                    VS4TInventoryMB.TInMQuantityText, VS4TInventoryMB.TInMArrear, VS4TInventoryMB.TInMShow, VS4TInventoryMB.TInMAgentPrice, VS4TInventoryMB.TInMQAStatus, VS4TInventoryMB.TInMQANote,                    VS4TInventoryMB.TInMTPltCode, VS4TInventoryMB.TInMFromTPltCode, VS4TInventoryMB.TInMQuantityCost, VS4TInventoryMB.TInMAgentPrice2, VS4TInventoryMB.TInMAgentPrice3,                    VS4TWarehouse.TWahName, VS4TLocation.TLctName, VS4TBranch.TBraName, VS4TProductType.TPTTName, VS4TInventoryType.TInTName, VS4TLocation.TLctTBraCode, VS4TAP.TAPNName,                    VS4TInventoryType.TInTSort, VS4TPOS.TPOSPrice, VS4TJob.TJobCode, VS4TJob.TJobCustomerName, 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.TPdtTPG1Code, VS4TProduct.TPdtTPG2Code, VS4TProduct.TPdtTBndCode, VS4TProduct.TPdtImage1, VS4TProduct.TPdtTPCTAlias, VS4TProduct.TPdtOrderPoint,                    VS4TProduct.TPdtAvgUsePerDay, VS4TProduct.TPdtStockQuantity, VS4TProduct.TPdtLastCost, VS4TProduct.TPdtStdCostCode, VS4TProduct.TPdtAverageCost, VS4TProduct.TPdtSerialType,                    VS4TProduct.TPdtBackDayCalc, VS4TPRMB.TPRMTPdtCode, VS4TPRMB.TPRMProductName, VS4TPRMB.TPRMUseDate, VS4TPRMB.TPRMUseType, VS4TPRMB.TPRMTUntCode, VS4TPRMB.TPRMQuantity,                    VS4TPRMB.TPRMQuantity2, VS4TPR.TPRDNo, VS4TPR.TPRDTPRBCode, VS4TPR.TPRDDate, VS4TPR.TPRDRequestBy, VS4TPR.TPRDDescription, VS4TPR.TPRDTBraCode, VS4TPR.TPRDTDivCode,                    VS4TLocation_1.TLctTWahCode AS VInMFromTWahCode, VS4TWarehouse.TWahCode AS VInMToTWahCode, VS4TWarehouse.TWahCode, VS4TJobMB.TJbMQuantity, VS4TJobMB.TJbMTUntCode,                    VS4TJobMB.TJbMQuantity2, VS4TJobMB.TJbMQuantity3, VS4TJobMB.TJbMCustom1, VS4TJobMB.TJbMCustom2, VS4TJobMB.TJbMCustom3, VS4TJobMB.TJbMCustom4, VS4TJobMB.TJbMCustom5,                    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.TIMCCostCode, VS4TInventoryLOT.TIMCTPODNo, VS4TInventoryLOT.TIMCTPOBLn, VS4TInventoryLOT.TIMCTPDELn,                    VS4TInventoryLOT.TIMCConsignFSDate, VS4TInventoryLOT.TIMCConsignLSDate, VS4TInventoryType.TInTInputCost, VS4TInventoryLOT.TIMCReceiveNo, VS4TInventoryLOT.TIMCReceiveLn,                    VS4VProductSafeH.TPSSStockMin, VS4TInventoryLOT.TIMCQAStatus, VS4TInventoryLOT.TIMCQANote, VS4TInventoryLOT.TIMCTAPNCode, VS4TInventoryLOT.TIMCInvoiceNo,                    VS4TInventoryLOT.TIMCInvoiceDate, VS4TInventoryLOT.TIMCTUntCode, VS4TInventoryLOT.TIMCUnitRatio, VS4TProduct.TPdtPremiumCost, VS4VProductGroup.TPdLName, VS4VProductGroup.TPSEName,                    VS4VProductGroup.TPG1Name, VS4TInventoryLOT.TIMCAccountLevel, VS4TProduct.TPdtLastBalDate, VS4TPOS.TPOSPackAlias2, VS4TProduct.TPdtStandardCost, VS4TInventoryLOT.TIMCInputTCurCode,                    VS4TInventoryLOT.TIMCInputCostRate, VS4TInventoryLOT.TIMCAdjustCost, VS4TInventoryLOT.TIMCStandardCost, VS4TInventoryLOT.TIMCAVGCost, VS4TProductType.TPTTStockCost,                    VS4TProduct.TPdtStockType, VS4TProduct.TPdtCode, VS4TInventoryLOT.TIMCCOA, VS4TInventoryLOT.TIMCProposeStatus, VS4TInventoryLOT.TIMCProposeNote, VS4TDivision.TDivName,                    VS4TDepartment.TDepName, VS4TProject.TPrjName, VS4TProductLPrice.TPLRPrice, VS4TInventoryLOT.TIMCUnitRatioC, VS4TInventoryLOT.TIMCquantityCalc, VS4TInventoryLOT.TIMCDutyRate,                    VS4TProductSection.TPSECode, VS4TLocation.TLctType, VS4TWarehouse.TWahGroup, VS4TInventoryLOT.TIMCDiscountText, VS4TInventoryLOT.TIMCDiscountTotal, VS4TPRMB.TPRMCustom1,                    VS4TPRMB.TPRMCustom2, VS4TPRMB.TPRMCustom3, VS4TPRMB.TPRMCustom4, VS4TPRMB.TPRMCustom5, VS4TProduct.TPdtDescription, VS4TInventoryLOT.TIMCTIvsCode,                    VS4TInventoryLOT.TIMCPrice, VS4TInventoryLOT.TIMCVATType, VS4TInventoryMB.TInMTIvsCode, VS4TInventoryMB.TInMFromTIvsCode, VS4TAP_1.TAPNName AS VInvTAPNName, VS4TInventory.TInvTJStLn,                    VS4TJobMB.TJbMControlQty, VS4TInventoryMB.TInMFlag3, VS4TProduct.TPdtFlag1, VS4TInventoryLOT.TIMCMachineOutlet, VS4TInventoryLOT.TIMCMachineNo, VS4TInventoryType.TInTDescription,                    VS4TInventoryLOT.TIMCWastage, VS4TInventoryLOT.TIMCLOTCustom1, VS4TInventoryMB.TInMTACPTACYID, VS4TInventoryMB.TInMTACPID, VS4TInventoryLOT.TIMCReserve, VS4TAP.TAPNAddressBill,                    VS4TAP.TAPNPhone, VS4TAP.TAPNFax, VS4TInventory.TInvApproveDate, VS4TAP_2.TAPNName AS VInvPRAPName, VS4TProduct_2.TPdtCustom1, VS4TProduct_2.TPdtCustom2, VS4TProduct_2.TPdtCustom3,                    VS4TProduct_2.TPdtCustom4, VS4TProduct_2.TPdtCustom5, VS4TInventory.TInvTWahCode FROM     VS4TInventoryType INNER JOIN                   VS4TProduct LEFT OUTER JOIN                   VS4TProductType ON VS4TProduct.TPdtTPTTCode = VS4TProductType.TPTTCode LEFT OUTER JOIN                   VS4VProductGroup ON VS4TProduct.TPdtCode = VS4VProductGroup.VPdtCode LEFT OUTER JOIN                   VS4VProductSafeH ON VS4TProduct.TPdtCode = VS4VProductSafeH.TPSSTPdtCode LEFT OUTER JOIN                   VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode LEFT OUTER JOIN                   VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode LEFT OUTER JOIN                   VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code INNER JOIN                   VS4TInventory LEFT OUTER JOIN                   VS4TDepartment ON VS4TInventory.TInvTDepCode = VS4TDepartment.TDepCode LEFT OUTER JOIN                   VS4TDivision ON VS4TInventory.TInvTDivCode = VS4TDivision.TDivCode LEFT OUTER JOIN                   VS4TBranch ON VS4TInventory.TInvTBraCode = VS4TBranch.TBraCode LEFT OUTER JOIN                   VS4TProject ON VS4TInventory.TInvTPrjCode = VS4TProject.TPrjCode LEFT OUTER JOIN                   VS4TJob ON VS4TInventory.TInvTJobNo = VS4TJob.TJobNo LEFT OUTER JOIN                   VS4TJobMB ON VS4TInventory.TInvTJbMLn = VS4TJobMB.TJbMLn AND VS4TInventory.TInvTJobNo = VS4TJobMB.TJbMTJobNo LEFT OUTER JOIN                   VS4TPR ON VS4TInventory.TInvRefNo = VS4TPR.TPRDNo LEFT OUTER JOIN                   VS4TProduct AS VS4TProduct_1 ON VS4TJobMB.TJbMTPdtCode = VS4TProduct_1.TPdtCode LEFT OUTER JOIN                   VS4TSection ON VS4TInventory.TInvTSecCode = VS4TSection.TSecCode LEFT OUTER JOIN                   VS4TAP AS VS4TAP_1 ON VS4TInventory.TInvTARNCode = VS4TAP_1.TAPNCode LEFT OUTER JOIN                   VS4TAP AS VS4TAP_2 ON VS4TPR.TPRDTAPNCode = VS4TAP_2.TAPNCode INNER JOIN                   VS4TInventoryMB LEFT OUTER JOIN                   VS4TLocation ON VS4TInventoryMB.TInMTLctCode = VS4TLocation.TLctCode LEFT OUTER JOIN                   VS4TWarehouse ON VS4TLocation.TLctTWahCode = VS4TWarehouse.TWahCode LEFT OUTER JOIN                   VS4TPRMB ON VS4TInventoryMB.TInMSourceNo = VS4TPRMB.TPRMTPRDNo AND VS4TInventoryMB.TInMSourceLn = VS4TPRMB.TPRMLn LEFT OUTER JOIN                   VS4TLocation AS VS4TLocation_1 ON VS4TInventoryMB.TInMFromTLctCode = VS4TLocation_1.TLctCode LEFT OUTER JOIN                   VS4TSOMB ON VS4TInventoryMB.TInMTSODNo = VS4TSOMB.TSOBTSODNo AND VS4TInventoryMB.TInMTSOBLn = VS4TSOMB.TSOBLn LEFT OUTER JOIN                   VS4TInventoryLOT LEFT OUTER JOIN                   VS4TAP ON VS4TInventoryLOT.TIMCTAPNCode = VS4TAP.TAPNCode 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 LEFT OUTER JOIN                   VS4TProductLPrice ON VS4TInventoryMB.TInMTPdtCode = VS4TProductLPrice.TPLRTPdtCode AND VS4TInventoryMB.TInMTLctCode = VS4TProductLPrice.TPLRTLctCode LEFT OUTER JOIN                   VS4TProduct AS VS4TProduct_2 ON VS4TPRMB.TPRMTPdtCode = VS4TProduct_2.TPdtCode ON VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo ON                    VS4TProduct.TPdtCode = VS4TInventoryMB.TInMTPdtCode LEFT OUTER JOIN                   VS4TProduct2 ON VS4TProduct.TPdtCode = VS4TProduct2.TPd2TPdtCode ON VS4TInventoryType.TInTAlias = VS4TInventory.TInvTInTAlias
GO

CREATE VIEW VS4VInventoryPOS AS  SELECT VS4TInventory.*, VS4TInventoryType.*, VS4TInventoryMB.*, VS4TPOS.* FROM VS4TUnit RIGHT JOIN (VS4TInventoryType INNER JOIN ((VS4TProduct LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) 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
GO

CREATE VIEW VS4VInventoryPR AS  SELECT VS4TInventory.TInvNo, VS4TInventory.TInvMode, VS4TInventory.TInvTIBkCode, VS4TInventory.TInvDate, VS4TInventory.TInvInvoiceStatus, VS4TInventory.TInvTARNCode, VS4TInventory.TInvTInTAlias, VS4TInventory.TInvRefNo, VS4TInventory.TInvRefDate, VS4TInventory.TInvRefNo2, VS4TInventory.TInvRefDate2, VS4TInventory.TInvRefNo3, VS4TInventory.TInvRefDate3, VS4TInventory.TInvCustom1, VS4TInventory.TInvCustom2, VS4TInventory.TInvCustom3, VS4TInventory.TInvCustom4, VS4TInventory.TInvCustom5, VS4TInventory.TInvTPrjCode, VS4TInventory.TInvTJobNo, VS4TInventory.TInvTJbMLn, VS4TInventory.TInvTJPdNo, VS4TInventory.TInvTJPMLn, VS4TInventory.TInvTSecCode, VS4TInventory.TInvTDepCode, VS4TInventory.TInvTDivCode, VS4TInventory.TInvTBraCode, VS4TInventory.TInvFromTBraCode, VS4TInventory.TInvTotal, VS4TInventory.TInvTotalRecord, VS4TInventory.TInvTotalQuantity, VS4TInventory.TInvRequestCode, VS4TInventory.TInvRequestBy, VS4TInventory.TInvDescription, VS4TInventory.TInvGLMethod, VS4TInventory.TInvTGLTNo, VS4TInventory.TInvDeliveryStatus, VS4TInventory.TInvSpecialFlag, VS4TInventory.TInvIsCompleted, VS4TInventory.TInvEditCode, VS4TInventory.TInvApproveStatus, VS4TInventory.TInvRevision, VS4TInventory.TInvCancelStatus, VS4TInventory.TInvCustomNo, VS4TInventory.TInvCustomDate, VS4TInventory.TInvTotalScrap, VS4TInventory.TInvTotalQScrap, VS4TInventory.TInvTotalQInput, VS4TInventory.TInvTotalAInput, VS4TInventory.TInvTotalRecordIn, VS4TInventory.TInvTotalPCScrap, VS4TInventory.TInvTotalPCQScrap, VS4TInventory.TInvSourceType, VS4TInventoryMB.TInMTInvNo, VS4TInventoryMB.TInMLn, VS4TInventoryMB.TInMTPdtCode, VS4TInventoryMB.TInMCustom1, VS4TInventoryMB.TInMSerialNo, VS4TInventoryMB.TInMLotNo, VS4TInventoryMB.TInMLotDate, VS4TInventoryMB.TInMScrapLevel, VS4TInventoryMB.TInMQuantityCalc, VS4TInventoryMB.TInMUnitRatio, VS4TInventoryMB.TInMQuantityBase, VS4TInventoryMB.TInMTUntCode, VS4TInventoryMB.TInMInQuantity, VS4TInventoryMB.TInMOutQuantity, VS4TInventoryMB.TInMAmouQuantity, VS4TInventoryMB.TInMAmouQuantity2, VS4TInventoryMB.TInMAmouQuantity3, VS4TInventoryMB.TInMAmount, VS4TInventoryMB.TInMStatus, VS4TInventoryMB.TInMFromTLctCode, VS4TInventoryMB.TInMTLctCode, VS4TInventoryMB.TInMDescription, VS4TInventoryMB.TInMTInTAlias, VS4TInventoryMB.TInMTSODNo, VS4TInventoryMB.TInMTSOBLn, VS4TInventoryMB.TInMTMDSLn, VS4TInventoryMB.TInMSourceType, VS4TInventoryMB.TInMSourceNo, VS4TInventoryMB.TInMSourceLn, VS4TInventoryMB.TInMQuantityText, VS4TInventoryMB.TInMArrear, VS4TInventoryMB.TInMShow, VS4TInventoryMB.TInMAgentPrice, VS4TInventoryMB.TInMQAStatus, VS4TInventoryMB.TInMQANote, VS4TInventoryMB.TInMTPltCode, VS4TInventoryMB.TInMFromTPltCode, VS4TInventoryMB.TInMQuantityCost, VS4TInventoryMB.TInMAgentPrice2, VS4TInventoryMB.TInMAgentPrice3, VS4TWarehouse.TWahName, VS4TLocation.TLctName, VS4TBranch.TBraName, VS4TProductType.TPTTName, VS4TInventoryType.TInTName, VS4TLocation.TLctTBraCode, VS4TAR.TARNName, VS4TAP.TAPNName, VS4TInventoryType.TInTSort, VS4TPOS.TPOSPrice, VS4TJob.TJobCode, VS4TJob.TJobCustomerName, 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.TPdtTPG1Code, VS4TProduct.TPdtTPG2Code, VS4TProduct.TPdtTBndCode, VS4TProduct.TPdtImage1, VS4TProduct.TPdtTPCTAlias, VS4TProduct.TPdtOrderPoint, VS4TProduct.TPdtAvgUsePerDay, VS4TProduct.TPdtStockQuantity, VS4TProduct.TPdtLastCost, VS4TProduct.TPdtStdCostCode, VS4TProduct.TPdtAverageCost, VS4TProduct.TPdtSerialType, VS4TProduct.TPdtBackDayCalc, VS4TPRMB.TPRMTPdtCode, VS4TPRMB.TPRMProductName, VS4TPRMB.TPRMUseDate, VS4TPRMB.TPRMUseType, VS4TPRMB.TPRMTUntCode, VS4TPRMB.TPRMQuantity, VS4TPRMB.TPRMQuantity2, VS4TPR.TPRDNo, VS4TPR.TPRDTPRBCode, VS4TPR.TPRDDate, VS4TPR.TPRDRequestBy, VS4TPR.TPRDDescription, VS4TPR.TPRDTBraCode, VS4TPR.TPRDTDivCode, VS4TLocation_1.TLctTWahCode AS VInMFromTWahCode, VS4TWarehouse.TWahCode AS VInMToTWahCode, VS4TWarehouse.TWahCode, VS4TJobMB.TJbMQuantity, VS4TJobMB.TJbMTUntCode, VS4TJobMB.TJbMQuantity2, VS4TJobMB.TJbMQuantity3, VS4TJobMB.TJbMCustom1, VS4TJobMB.TJbMCustom2, VS4TJobMB.TJbMCustom3, VS4TJobMB.TJbMCustom4, VS4TJobMB.TJbMCustom5, 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.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.TPdtPremiumCost, VS4VProductGroup.TPdLName, VS4VProductGroup.TPSEName, VS4VProductGroup.TPG1Name, VS4TInventoryLOT.TIMCAccountLevel, VS4TProduct.TPdtLastBalDate, VS4TPOS.TPOSPackAlias2, VS4TProduct.TPdtStandardCost, VS4TInventoryLOT.TIMCInputTCurCode, VS4TInventoryLOT.TIMCInputCostRate, VS4TInventoryLOT.TIMCAdjustCost, VS4TInventoryLOT.TIMCStandardCost, VS4TInventoryLOT.TIMCAVGCost, VS4TProductType.TPTTStockCost, VS4TProduct.TPdtStockType, VS4TProduct.TPdtCode, VS4TInventoryLOT.TIMCCOA, VS4TInventoryLOT.TIMCProposeStatus, VS4TInventoryLOT.TIMCProposeNote, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TProject.TPrjName, VS4TProductLPrice.TPLRPrice, VS4TInventoryLOT.TIMCUnitRatioC, VS4TInventoryLOT.TIMCQuantityCalc, VS4TInventoryLOT.TIMCDutyRate, VS4TProductSection.TPSECode, VS4TLocation.TLctType, VS4TWarehouse.TWahGroup, VS4TInventoryLOT.TIMCDiscountText, VS4TInventoryLOT.TIMCDiscountTotal, VS4TPRMB.TPRMCustom1, VS4TPRMB.TPRMCustom2, VS4TPRMB.TPRMCustom3, VS4TPRMB.TPRMCustom4, VS4TPRMB.TPRMCustom5, VS4TProduct.TPdtDescription, VS4TInventoryLOT.TIMCTIvSCode, VS4TInventoryLOT.TIMCPrice, VS4TInventoryLOT.TIMCVATType, VS4TInventoryMB.TInMTIvSCode, VS4TInventoryMB.TInMFromTIvsCode, VS4TAP_1.TAPNName AS VInvTAPNName, VS4TInventory.TInvTJStLn, VS4TJobMB.TJbMControlQty, VS4TInventoryMB.TInMFlag3, VS4TProduct.TPdtFlag1, VS4TInventoryLOT.TIMCMachineOutlet, VS4TInventoryLOT.TIMCMachineNo, VS4TInventoryType.TInTDescription, VS4TInventoryLOT.TIMCWASTAGE, VS4TInventoryLOT.TIMCLotCustom1, VS4TInventoryMB.TInMTACPTACYID, VS4TInventoryMB.TInMTACPID, VS4TInventoryLOT.TIMCReserve, VS4TAP.TAPNAddressBill, VS4TAP.TAPNPhone, VS4TInventory.TInvApproveDate, VS4TInventory.TInvConfirmStatus, VS4TInventoryLOT.TIMCCostInputType, VS4TInventory.TInvFlag1 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) LEFT JOIN VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode) LEFT JOIN VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code) 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.TInvTJbMLn = VS4TJobMB.TJbMLn) AND (VS4TInventory.TInvTJobNo = VS4TJobMB.TJbMTJobNo)) LEFT JOIN VS4TPR ON VS4TInventory.TInvRefNo = VS4TPR.TPRDNo) LEFT JOIN VS4TProduct AS VS4TProduct_1 ON VS4TJobMB.TJbMTPdtCode = VS4TProduct_1.TPdtCode) LEFT JOIN VS4TAR ON VS4TInventory.TInvTARNCode = VS4TAR.TARNCode) LEFT JOIN VS4TSection ON VS4TInventory.TInvTSecCode = VS4TSection.TSecCode) LEFT JOIN VS4TAP AS VS4TAP_1 ON VS4TInventory.TInvTARNCode = VS4TAP_1.TAPNCode) INNER JOIN (((((((VS4TInventoryMB LEFT JOIN VS4TLocation ON VS4TInventoryMB.TInMTLctCode = VS4TLocation.TLctCode) LEFT JOIN VS4TWarehouse ON VS4TLocation.TLctTWahCode = VS4TWarehouse.TWahCode) LEFT JOIN VS4TPRMB ON (VS4TInventoryMB.TInMSourceNo = VS4TPRMB.TPRMTPRDNo) AND (VS4TInventoryMB.TInMSourceLn = VS4TPRMB.TPRMLn)) LEFT JOIN VS4TLocation AS VS4TLocation_1 ON VS4TInventoryMB.TInMFromTLctCode = VS4TLocation_1.TLctCode) LEFT JOIN VS4TSOMB ON (VS4TInventoryMB.TInMTSODNo = VS4TSOMB.TSOBTSODNo) AND (VS4TInventoryMB.TInMTSOBLn = VS4TSOMB.TSOBLn)) LEFT JOIN (VS4TInventoryLOT LEFT JOIN VS4TAP ON VS4TInventoryLOT.TIMCTAPNCode = VS4TAP.TAPNCode) 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)) LEFT JOIN VS4TProductLPrice ON (VS4TInventoryMB.TInMTPdtCode = VS4TProductLPrice.TPLRTPdtCode) AND (VS4TInventoryMB.TInMTLctCode = VS4TProductLPrice.TPLRTLctCode)) 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 VS4VInventoryR AS SELECT        VS4TInventory_1.TInvNo, VS4TInventory_1.TInvTIBkCode, VS4TInventory_1.TInvDate, VS4TInventoryMB.TInMTPdtCode, VS4TInventoryMB.TInMQuantityBase, VS4TInventoryMB.TInMTUntCode,                           VS4TInventoryMB.TInMInQuantity, VS4TInventoryMB.TInMOutQuantity, VS4TInventoryMB.TInMAmouQuantity, VS4TInventoryMB.TInMAmouQuantity2, 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, VS4TInventory_1.TInvTPrjCode, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtTPSECode, VS4TProduct.TPdtTPG1Code,                           VS4TProduct.TPdtTPG2Code, VS4TProduct.TPdtTPG3Code, VS4TProduct.TPdtTPG4Code, VS4TProduct.TPdtTPS2Code, VS4TProduct.TPdtTPS3Code, VS4TProduct.TPdtTPS4Code,                           VS4TInventory_1.TInvTDivCode, VS4TInventory_1.TInvTDepCode, VS4TInventory_1.TInvTSecCode, VS4TInventory_1.TInvTJobNo, VS4TInventoryLOT.TIMCTAPNCode, VS4TInventory_1.TInvRefNo,                           VS4TInventoryLOT.TIMCInvoiceNo, VS4TInventoryMB.TInMTInTAlias, VS4TInventory_1.TInvApproveStatus, VS4TInventory_1.TInvCancelStatus, VS4TWarehouse.TWahCode, VS4TInventory_1.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,                           VS4TProduct.TPdtLastCost, VS4TProduct.TPdtStandardCost, VS4TInventoryLOT.TIMCInputTCurCode, VS4TInventoryLOT.TIMCInputCostRate, VS4TInventoryLOT.TIMCAdjustCost,                           VS4TInventoryLOT.TIMCInputCost, VS4TInventoryLOT.TIMCPerQuantity, VS4TInventoryLOT.TIMCUnitCalc, VS4TInventoryLOT.TIMCLastUnitCost, VS4TProduct.TPdtTAPNCode,                           VS4TInventoryLOT.TIMCStandardCost, VS4TInventoryLOT.TIMCAVGCost, VS4TProduct.TPdtStockType, VS4TProductType.TPTTStockCost, VS4TProduct.TPdtPremiumCost,                           VS4TInventoryLOT.TIMCCustom2, VS4TInventoryLOT.TIMCQANote, VS4TInventoryLOT.TIMCCOA, VS4TInventoryLOT.TIMCProposeStatus, VS4TInventoryLOT.TIMCProposeNote,                           VS4TProductLPrice.TPLRPrice, VS4TInventoryLOT.TIMCUnitRatioC, VS4TInventoryLOT.TIMCquantityCalc, VS4TInventoryLOT.TIMCDutyRate, VS4TLocation.TLctType, VS4TWarehouse.TWahGroup,                           VS4TInventoryLOT.TIMCDiscountText, VS4TInventoryLOT.TIMCDiscountTotal, VS4TInventoryLOT.TIMCTIvsCode, VS4TInventoryLOT.TIMCPrice, VS4TInventoryLOT.TIMCVATType,                           VS4TInventoryMB.TInMTPltCode, VS4TInventoryMB.TInMTIvsCode, VS4TAP.TAPNTCouCode, VS4TInventBook.TIBkName, VS4TInventStatus.TIvSName, VS4TProductStat.TPMSLastPTCurCode,                           VS4TCurrency.TCurLastRate, (VS4TProductStat.TPMSLastPPrice * VS4TCurrency.TCurLastRate) * (VS4TProduct2.TPd2TaxRate + 100) / 100 AS VInvNetCost, VS4TInventory_1.TInvTJStLn,                           VS4TInventoryLOT.TIMCMachineNo, VS4TInventoryLOT.TIMCMachineOutlet, VS4TInventoryMB.TInMTACPTACYID, VS4TInventoryMB.TInMTACPID, VS4TInventoryMB.TInMTInvNo,                           VS4TInventoryMB.TInMLn, VS4TInventory_1.TInvApproveDate, VS4TInventoryLOT.TIMCCostInputType, VS4TInventoryType.TInTSort, VS4TProduct.TPdtUnit2Ratio, VS4TProduct.TPdtUnit3Ratio,                           VS4TProductStat.TPMSLastPPrice, VS4TInventory_1.TInvTBraCode, VS4TInventoryLOT.TIMCFreightFee, VS4TInventoryLOT.TIMCInsurance, VS4TInventoryLOT.TIMCOtherFee,                           VS4TInventoryLOT.TIMCDutyAmount, VS4TInventoryLOT.TIMCHandlingFee, VS4TInventoryLOT.TIMCUnitCostBFA, VS4TInventoryLOT.TIMCCostDecimal,                              (SELECT        TPSSStockMin                                FROM            VS4TProductSafeS                                WHERE        (TPSSTPdtCode = VS4TInventoryMB.TInMTPdtCode) AND (TPSSTBraCode = VS4TLocation.TLctTBraCode)) AS TPSSStockMin, VS4TInventory_1.TInvCreateBy, VS4TInventory_1.TInvEditBy,                           VS4TInventory_1.TInvConfirmBy, VS4TInventory.TInvTJobNo AS TJobNo FROM            VS4TProduct LEFT OUTER JOIN                          VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode LEFT OUTER JOIN                          VS4TProductType ON VS4TProduct.TPdtTPTTCode = VS4TProductType.TPTTCode INNER JOIN                          VS4TInventBook INNER JOIN                          VS4TInventory AS VS4TInventory_1 LEFT OUTER JOIN                          VS4TBranch ON VS4TInventory_1.TInvTBraCode = VS4TBranch.TBraCode ON VS4TInventBook.TIBkCode = VS4TInventory_1.TInvTIBkCode INNER JOIN                          VS4TInventoryType INNER JOIN                          VS4TInventoryMB LEFT OUTER JOIN                          VS4TLocation ON VS4TInventoryMB.TInMTLctCode = VS4TLocation.TLctCode LEFT OUTER JOIN                          VS4TWarehouse ON VS4TLocation.TLctTWahCode = VS4TWarehouse.TWahCode LEFT OUTER 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 LEFT OUTER JOIN                          VS4TProductLPrice ON VS4TInventoryMB.TInMTPdtCode = VS4TProductLPrice.TPLRTPdtCode AND VS4TInventoryMB.TInMTLctCode = VS4TProductLPrice.TPLRTLctCode LEFT OUTER JOIN                          VS4TAP ON VS4TInventoryLOT.TIMCTAPNCode = VS4TAP.TAPNCode LEFT OUTER JOIN                          VS4TInventStatus ON VS4TInventoryMB.TInMTIvsCode = VS4TInventStatus.TIvSCode ON VS4TInventoryType.TInTAlias = VS4TInventoryMB.TInMTInTAlias ON                           VS4TInventory_1.TInvNo = VS4TInventoryMB.TInMTInvNo ON VS4TProduct.TPdtCode = VS4TInventoryMB.TInMTPdtCode LEFT OUTER JOIN                          VS4TInventory ON VS4TInventoryLOT.TIMCReceiveNo = VS4TInventory.TInvNo AND VS4TInventoryLOT.TIMCReceiveLn = VS4TInventory.TInvMode LEFT OUTER JOIN                          VS4TProject ON VS4TInventory_1.TInvTPrjCode = VS4TProject.TPrjCode LEFT OUTER JOIN                          VS4TProduct2 ON VS4TProduct.TPdtCode = VS4TProduct2.TPd2TPdtCode LEFT OUTER JOIN                          VS4TProductStat LEFT OUTER JOIN                          VS4TCurrency ON VS4TProductStat.TPMSLastPTCurCode = VS4TCurrency.TCurCode ON VS4TProduct.TPdtCode = VS4TProductStat.TPMSTPdtCode
GO

CREATE VIEW VS4VInventoryR2 AS SELECT VS4TInventory.TInvNo, VS4TInventory.TInvMode, VS4TInventory.TInvTIBkCode, VS4TInventory.TInvDate, VS4TInventory.TInvInvoiceStatus, VS4TInventory.TInvTARNCode, VS4TInventory.TInvTInTAlias,                    VS4TInventory.TInvRefNo, VS4TInventory.TInvRefDate, VS4TInventory.TInvRefNo2, VS4TInventory.TInvRefDate2, VS4TInventory.TInvRefNo3, VS4TInventory.TInvRefDate3, VS4TInventory.TInvCustom1,                    VS4TInventory.TInvCustom2, VS4TInventory.TInvCustom3, VS4TInventory.TInvCustom4, VS4TInventory.TInvCustom5, VS4TInventory.TInvTPrjCode, VS4TInventory.TInvTJobNo, VS4TInventory.TInvTJbMLn,                    VS4TInventory.TInvTJPdNo, VS4TInventory.TInvTJPMLn, VS4TInventory.TInvTSecCode, VS4TInventory.TInvTDepCode, VS4TInventory.TInvTDivCode, VS4TInventory.TInvTBraCode,                    VS4TInventory.TInvFromTBraCode, VS4TInventory.TInvTotal, VS4TInventory.TInvTotalRecord, VS4TInventory.TInvTotalQuantity, VS4TInventory.TInvRequestCode, VS4TInventory.TInvRequestBy,                    VS4TInventory.TInvDescription, VS4TInventory.TInvGLMethod, VS4TInventory.TInvTGLTNo, VS4TInventory.TInvDeliveryStatus, VS4TInventory.TInvSpecialFlag, VS4TInventory.TInvIsCompleted,                    VS4TInventory.TInvEditCode, VS4TInventory.TInvApproveStatus, VS4TInventory.TInvRevision, VS4TInventory.TInvCancelStatus, VS4TInventory.TInvCustomNo, VS4TInventory.TInvCustomDate,                    VS4TInventory.TInvTotalScrap, VS4TInventory.TInvTotalQScrap, VS4TInventory.TInvTotalQInput, VS4TInventory.TInvTotalAInput, VS4TInventory.TInvTotalRecordIn, VS4TInventory.TInvTotalPCScrap,                    VS4TInventory.TInvTotalPCQScrap, VS4TInventory.TInvSourceType, VS4TInventoryMB.TInMTInvNo, VS4TInventoryMB.TInMLn, VS4TInventoryMB.TInMTPdtCode, VS4TInventoryMB.TInMCustom1,                    VS4TInventoryMB.TInMSerialNo, VS4TInventoryMB.TInMLotNo, VS4TInventoryMB.TInMLotDate, VS4TInventoryMB.TInMScrapLevel, VS4TInventoryMB.TInMQuantityCalc, VS4TInventoryMB.TInMUnitRatio,                    VS4TInventoryMB.TInMQuantityBase, VS4TInventoryMB.TInMTUntCode, VS4TInventoryMB.TInMInQuantity, VS4TInventoryMB.TInMOutQuantity, VS4TInventoryMB.TInMAmouQuantity,                    VS4TInventoryMB.TInMAmouQuantity2, VS4TInventoryMB.TInMAmouQuantity3, VS4TInventoryMB.TInMAmount, VS4TInventoryMB.TInMStatus, VS4TInventoryMB.TInMFromTLctCode,                    VS4TInventoryMB.TInMTLctCode, VS4TInventoryMB.TInMDescription, VS4TInventoryMB.TInMTInTAlias, VS4TInventoryMB.TInMTSODNo, VS4TInventoryMB.TInMTSOBLn, VS4TInventoryMB.TInMTMDSLn,                    VS4TInventoryMB.TInMSourceType, VS4TInventoryMB.TInMSourceNo, VS4TInventoryMB.TInMSourceLn, VS4TInventoryMB.TInMQuantityText, VS4TInventoryMB.TInMArrear, VS4TInventoryMB.TInMShow,                    VS4TInventoryMB.TInMAgentPrice, VS4TInventoryMB.TInMQAStatus, VS4TInventoryMB.TInMQANote, VS4TInventoryMB.TInMTPltCode, VS4TInventoryMB.TInMFromTPltCode,                    VS4TInventoryMB.TInMQuantityCost, VS4TWarehouse.TWahName, VS4TLocation.TLctName, VS4TBranch.TBraName, VS4TProductType.TPTTName, VS4TInventoryType.TInTName,                    VS4TLocation.TLctTBraCode, VS4TAR.TARNName, VS4TAP.TAPNName, VS4TInventoryType.TInTSort, VS4TPOS.TPOSPrice, VS4TJob.TJobCode, VS4TJob.TJobCustomerName,                    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.TPdtTPG1Code, VS4TProduct.TPdtTPG2Code, VS4TProduct.TPdtTBndCode, VS4TProduct.TPdtImage1,                    VS4TProduct.TPdtTPCTAlias, VS4TProduct.TPdtOrderPoint, VS4TProduct.TPdtAvgUsePerDay, VS4TProduct.TPdtStockQuantity, VS4TProduct.TPdtLastCost, VS4TProduct.TPdtStdCostCode,                    VS4TProduct.TPdtAverageCost, VS4TProduct.TPdtSerialType, VS4TProduct.TPdtBackDayCalc, VS4TPR.TPRDNo, VS4TPR.TPRDTPRBCode, VS4TPR.TPRDDate, VS4TPR.TPRDRequestBy,                    VS4TPR.TPRDDescription, VS4TPR.TPRDTBraCode, VS4TPR.TPRDTDivCode, VS4TLocation_1.TLctTWahCode AS VInMFromTWahCode, VS4TWarehouse.TWahCode AS VInMToTWahCode,                    VS4TWarehouse.TWahCode, VS4TJobMB.TJbMQuantity, VS4TJobMB.TJbMTUntCode, VS4TJobMB.TJbMQuantity2, VS4TJobMB.TJbMQuantity3, VS4TJobMB.TJbMCustom1, VS4TJobMB.TJbMCustom2,                    VS4TJobMB.TJbMCustom3, VS4TJobMB.TJbMCustom4, VS4TJobMB.TJbMCustom5, 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.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.TPdtPremiumCost, VS4VProductGroup.TPdLName, VS4VProductGroup.TPSEName, VS4VProductGroup.TPG1Name,                    VS4TInventoryLOT.TIMCAccountLevel, VS4TProduct.TPdtLastBalDate, VS4TPOS.TPOSPackAlias2, VS4TProduct.TPdtStandardCost, VS4TInventoryLOT.TIMCInputTCurCode,                    VS4TInventoryLOT.TIMCInputCostRate, VS4TInventoryLOT.TIMCAdjustCost, VS4TInventoryLOT.TIMCStandardCost, VS4TInventoryLOT.TIMCAVGCost, VS4TProductType.TPTTStockCost,                    VS4TProduct.TPdtStockType, VS4TProduct.TPdtCode, VS4TInventoryLOT.TIMCCOA, VS4TInventoryLOT.TIMCProposeStatus, VS4TInventoryLOT.TIMCProposeNote, VS4TDivision.TDivName,                    VS4TDepartment.TDepName, VS4TProject.TPrjName, VS4TProductLPrice.TPLRPrice, VS4TInventoryLOT.TIMCUnitRatioC, VS4TInventoryLOT.TIMCquantityCalc, VS4TInventoryLOT.TIMCDutyRate,                    VS4TLocation.TLctType, VS4TWarehouse.TWahGroup, VS4TInventoryLOT.TIMCDiscountText, VS4TInventoryLOT.TIMCDiscountTotal, VS4TPRMB.TPRMCustom1, VS4TPRMB.TPRMCustom2,                    VS4TPRMB.TPRMCustom3, VS4TPRMB.TPRMCustom4, VS4TPRMB.TPRMCustom5, VS4TProduct.TPdtDescription, VS4TInventoryLOT.TIMCTIvsCode, VS4TInventoryLOT.TIMCPrice,                    VS4TInventoryLOT.TIMCVATType, VS4TInventoryMB.TInMTIvsCode, VS4TInventoryMB.TInMFromTIvsCode, VS4TAP_1.TAPNName AS VInvTAPNName, VS4TInventory.TInvTJStLn, VS4TJobMB.TJbMControlQty,                    VS4TInventoryMB.TInMFlag3, VS4TProduct.TPdtFlag1, VS4TInventoryType.TInTDescription, VS4TInventoryLOT.TIMCWastage, VS4TInventoryLOT.TIMCLOTCustom1, VS4TInventoryMB.TInMTACPTACYID,                    VS4TInventoryMB.TInMTACPID, VS4TInventoryLOT.TIMCReserve, VS4TAP.TAPNAddressBill, VS4TAP.TAPNPhone, VS4TInventory.TInvApproveDate, VS4TInventory.TInvConfirmStatus,                    VS4TInventoryLOT.TIMCCostInputType, VS4TInventory.TInvFlag1, VS4TPOMB.TPOBSourceNo, VS4TPOMB.TPOBSourceLn, VS4TPR.TPRDTSecCode, VS4TJobProductionM.TJPMTSecCode,                    VS4TPOMBAOL.TPOATSecCode, VS4TProduct.TPdtAliasSlip, VS4TProductStat.TPMSLastPPrice, VS4TProductStat.TPMSLastPTCurCode, VS4TProduct.TPdtUnit2Ratio, VS4TProduct.TPdtUnit3Ratio,                    VS4TInventoryLOT.TIMCUnitCostBFA, VS4TInventoryLOT.TIMCCostDecimal, VS4TInventory.TInvCreateBy, VS4TInventory.TInvEditBy, VS4TInventory.TInvConfirmBy, VS4TInventory.TInvApproveBy,                    VS4TPOMB.TPOBPrice, VS4TSOMB.TSOBPrice, VS4TSOMB.TSOBDiscountText, ISNULL(VS4TAssetAlias.TAsACustom1, VS4TSO.TSODCustom1) AS VInvCustom1, ISNULL(VS4TAssetAlias.TAsACustom2,                    VS4TSO.TSODCustom2) AS VInvCustom2, ISNULL(VS4TAssetAlias.TAsACustom3, VS4TSO.TSODCustom3) AS VInvCustom3, VS4TSO.TSODVerifyDate, VS4TSO.TSODVerifyStatus, VS4TSO.TSODTSBkCode,                    VS4TAssetAlias.TAsATPdtCode, VS4TProduct_2.TPdtTPSECode AS VPdtTPSECode FROM     VS4TAssetAlias LEFT OUTER JOIN                   VS4TProduct AS VS4TProduct_2 ON VS4TAssetAlias.TAsATPdtCode = VS4TProduct_2.TPdtCode RIGHT OUTER JOIN                   VS4TInventoryType INNER JOIN                   VS4TProduct LEFT OUTER JOIN                   VS4TProductType ON VS4TProduct.TPdtTPTTCode = VS4TProductType.TPTTCode LEFT OUTER JOIN                   VS4VProductGroup ON VS4TProduct.TPdtCode = VS4VProductGroup.VPdtCode LEFT OUTER JOIN                   VS4VProductSafeH ON VS4TProduct.TPdtCode = VS4VProductSafeH.TPSSTPdtCode LEFT OUTER JOIN                   VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode INNER JOIN                   VS4TInventory LEFT OUTER JOIN                   VS4TDepartment ON VS4TInventory.TInvTDepCode = VS4TDepartment.TDepCode LEFT OUTER JOIN                   VS4TDivision ON VS4TInventory.TInvTDivCode = VS4TDivision.TDivCode LEFT OUTER JOIN                   VS4TBranch ON VS4TInventory.TInvTBraCode = VS4TBranch.TBraCode LEFT OUTER JOIN                   VS4TProject ON VS4TInventory.TInvTPrjCode = VS4TProject.TPrjCode LEFT OUTER JOIN                   VS4TJob ON VS4TInventory.TInvTJobNo = VS4TJob.TJobNo LEFT OUTER JOIN                   VS4TJobMB ON VS4TInventory.TInvTJbMLn = VS4TJobMB.TJbMLn AND VS4TInventory.TInvTJobNo = VS4TJobMB.TJbMTJobNo LEFT OUTER JOIN                   VS4TProduct AS VS4TProduct_1 ON VS4TJobMB.TJbMTPdtCode = VS4TProduct_1.TPdtCode LEFT OUTER JOIN                   VS4TAR ON VS4TInventory.TInvTARNCode = VS4TAR.TARNCode LEFT OUTER JOIN                   VS4TSection ON VS4TInventory.TInvTSecCode = VS4TSection.TSecCode LEFT OUTER JOIN                   VS4TAP AS VS4TAP_1 ON VS4TInventory.TInvTARNCode = VS4TAP_1.TAPNCode LEFT OUTER JOIN                   VS4TJobProductionM ON VS4TInventory.TInvTJPMLn = VS4TJobProductionM.TJPMLn AND VS4TInventory.TInvTJPdNo = VS4TJobProductionM.TJPMTJPdNo INNER JOIN                   VS4TInventoryMB LEFT OUTER JOIN                   VS4TLocation ON VS4TInventoryMB.TInMTLctCode = VS4TLocation.TLctCode LEFT OUTER JOIN                   VS4TWarehouse ON VS4TLocation.TLctTWahCode = VS4TWarehouse.TWahCode LEFT OUTER JOIN                   VS4TLocation AS VS4TLocation_1 ON VS4TInventoryMB.TInMFromTLctCode = VS4TLocation_1.TLctCode LEFT OUTER JOIN                   VS4TSOMB ON VS4TInventoryMB.TInMTSODNo = VS4TSOMB.TSOBTSODNo AND VS4TInventoryMB.TInMTSOBLn = VS4TSOMB.TSOBLn LEFT OUTER JOIN                   VS4TInventoryLOT LEFT OUTER JOIN                   VS4TAP ON VS4TInventoryLOT.TIMCTAPNCode = VS4TAP.TAPNCode 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 LEFT OUTER JOIN                   VS4TProductLPrice ON VS4TInventoryMB.TInMTPdtCode = VS4TProductLPrice.TPLRTPdtCode AND VS4TInventoryMB.TInMTLctCode = VS4TProductLPrice.TPLRTLctCode LEFT OUTER JOIN                   VS4TPOMB ON VS4TInventoryLOT.TIMCTPOBLn = VS4TPOMB.TPOBLn AND VS4TInventoryLOT.TIMCTPODNo = VS4TPOMB.TPOBTPODNo LEFT OUTER JOIN                   VS4TPRMB ON VS4TPOMB.TPOBSourceLn = VS4TPRMB.TPRMLn AND VS4TPOMB.TPOBSourceNo = VS4TPRMB.TPRMTPRDNo LEFT OUTER JOIN                   VS4TPR ON VS4TPRMB.TPRMTPRDNo = VS4TPR.TPRDNo LEFT OUTER JOIN                   VS4TPOMBAOL ON VS4TPOMB.TPOBLn = VS4TPOMBAOL.TPOATPOBLn AND VS4TPOMB.TPOBTPODNo = VS4TPOMBAOL.TPOATPOBTPODNo ON VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo ON                    VS4TProduct.TPdtCode = VS4TInventoryMB.TInMTPdtCode LEFT OUTER JOIN                   VS4TProductStat ON VS4TProduct.TPdtCode = VS4TProductStat.TPMSTPdtCode ON VS4TInventoryType.TInTAlias = VS4TInventory.TInvTInTAlias LEFT OUTER JOIN                   VS4TSO ON VS4TJob.TJobNo = VS4TSO.TSODNo ON VS4TAssetAlias.TAsACode = VS4TJob.TJobCode
GO

CREATE VIEW VS4VInventoryRJob AS SELECT        VS4TInventory.TInvNo, VS4TInventory.TInvMode, VS4TInventory.TInvTIBkCode, VS4TInventory.TInvDate, VS4TInventory.TInvTARNCode, VS4TInventory.TInvTInTAlias, VS4TInventory.TInvRefNo,                           VS4TInventory.TInvRefDate, VS4TInventory.TInvRefNo2, VS4TInventory.TInvRefDate2, VS4TInventory.TInvRefNo3, VS4TInventory.TInvCustom1, VS4TInventory.TInvCustom2,                           VS4TInventory.TInvCustom3, VS4TInventory.TInvCustom4, VS4TInventory.TInvCustom5, VS4TInventory.TInvTPrjCode, VS4TInventory.TInvTJobNo, VS4TInventory.TInvTJbMLn, VS4TInventory.TInvTJPdNo,                           VS4TInventory.TInvTJPMLn, VS4TInventory.TInvTSecCode, VS4TInventory.TInvTDepCode, VS4TInventory.TInvTDivCode, VS4TInventory.TInvTBraCode, VS4TInventory.TInvFromTBraCode,                           VS4TInventory.TInvTotal, VS4TInventory.TInvTotalRecord, VS4TInventory.TInvTotalQuantity, VS4TInventory.TInvRequestCode, VS4TInventory.TInvRequestBy, VS4TInventory.TInvDescription,                           VS4TInventory.TInvGLMethod, VS4TInventory.TInvTGLTNo, VS4TInventory.TInvDeliveryStatus, VS4TInventory.TInvSpecialFlag, VS4TInventory.TInvIsCompleted, VS4TInventory.TInvEditCode,                           VS4TInventory.TInvApproveStatus, VS4TInventory.TInvRevision, VS4TInventory.TInvCancelStatus, VS4TInventory.TInvTotalScrap, VS4TInventory.TInvTotalQScrap, VS4TInventory.TInvTotalQInput,                           VS4TInventory.TInvTotalAInput, VS4TInventory.TInvTotalRecordIn, VS4TInventory.TInvTotalPCScrap, VS4TInventory.TInvTotalPCQScrap, VS4TInventory.TInvSourceType, VS4TInventoryMB.TInMTInvNo,                           VS4TInventoryMB.TInMLn, VS4TInventoryMB.TInMTPdtCode, VS4TInventoryMB.TInMCustom1, VS4TInventoryMB.TInMSerialNo, VS4TInventoryMB.TInMLotNo, VS4TInventoryMB.TInMLotDate,                           VS4TInventoryMB.TInMScrapLevel, VS4TInventoryMB.TInMQuantityCalc, VS4TInventoryMB.TInMUnitRatio, VS4TInventoryMB.TInMQuantityBase, VS4TInventoryMB.TInMTUntCode,                           VS4TInventoryMB.TInMInQuantity, VS4TInventoryMB.TInMOutQuantity, VS4TInventoryMB.TInMAmouQuantity, VS4TInventoryMB.TInMAmouQuantity2, VS4TInventoryMB.TInMAmouQuantity3,                           VS4TInventoryMB.TInMAmount, VS4TInventoryMB.TInMStatus, VS4TInventoryMB.TInMFromTLctCode, VS4TInventoryMB.TInMTLctCode, VS4TInventoryMB.TInMDescription,                           VS4TInventoryMB.TInMTInTAlias, VS4TInventoryMB.TInMTSODNo, VS4TInventoryMB.TInMTSOBLn, VS4TInventoryMB.TInMTMDSLn, VS4TInventoryMB.TInMSourceType,                           VS4TInventoryMB.TInMSourceNo, VS4TInventoryMB.TInMSourceLn, VS4TInventoryMB.TInMQuantityText, VS4TInventoryMB.TInMArrear, VS4TInventoryMB.TInMShow,                           VS4TInventoryMB.TInMAgentPrice, VS4TInventoryMB.TInMQAStatus, VS4TInventoryMB.TInMQANote, VS4TInventoryMB.TInMTPltCode, VS4TInventoryMB.TInMFromTPltCode,                           VS4TInventoryMB.TInMQuantityCost, VS4TWarehouse.TWahName, VS4TLocation.TLctName, VS4TBranch.TBraName, VS4TProductType.TPTTName, VS4TInventoryType.TInTName,                           VS4TLocation.TLctTBraCode, VS4TAR.TARNName, VS4TAP.TAPNName, VS4TInventoryType.TInTSort, VS4TJob.TJobCode, VS4TJob.TJobCustomerName, 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.TPdtTPG1Code, VS4TProduct.TPdtTPG2Code,                           VS4TProduct.TPdtTBndCode, VS4TProduct.TPdtImage1, VS4TProduct.TPdtTPCTAlias, VS4TProduct.TPdtOrderPoint, VS4TProduct.TPdtLastCost, VS4TProduct.TPdtStdCostCode,                           VS4TProduct.TPdtAverageCost, VS4TProduct.TPdtSerialType, VS4TProduct.TPdtBackDayCalc, VS4TPR.TPRDNo, VS4TPR.TPRDTPRBCode, VS4TPR.TPRDDate, VS4TPR.TPRDRequestBy,                           VS4TPR.TPRDDescription, VS4TPR.TPRDTBraCode, VS4TPR.TPRDTDivCode, VS4TLocation_1.TLctTWahCode AS VInMFromTWahCode, VS4TWarehouse.TWahCode AS VInMToTWahCode,                           VS4TWarehouse.TWahCode, VS4TJobMB.TJbMQuantity, VS4TJobMB.TJbMTUntCode, VS4TJobMB.TJbMQuantity2, VS4TJobMB.TJbMQuantity3, VS4TJobMB.TJbMCustom1,                           VS4TJobMB.TJbMCustom2, VS4TJobMB.TJbMCustom3, VS4TJobMB.TJbMCustom4, VS4TJobMB.TJbMCustom5, 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.TIMCCostCode,                           VS4TInventoryLOT.TIMCTPODNo, VS4TInventoryLOT.TIMCTPOBLn, VS4TInventoryLOT.TIMCTPDELn, 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.TPdtPremiumCost,                           VS4VProductGroup.TPdLName, VS4VProductGroup.TPSEName, VS4VProductGroup.TPG1Name, VS4TInventoryLOT.TIMCAccountLevel, VS4TProduct.TPdtLastBalDate, VS4TPOS.TPOSPackAlias2,                           VS4TProduct.TPdtStandardCost, VS4TInventoryLOT.TIMCInputTCurCode, VS4TInventoryLOT.TIMCInputCostRate, VS4TInventoryLOT.TIMCAdjustCost, VS4TInventoryLOT.TIMCStandardCost,                           VS4TInventoryLOT.TIMCAVGCost, VS4TProductType.TPTTStockCost, VS4TProduct.TPdtStockType, VS4TProduct.TPdtCode, VS4TInventoryLOT.TIMCCOA, VS4TInventoryLOT.TIMCProposeStatus,                           VS4TInventoryLOT.TIMCProposeNote, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TProject.TPrjName, VS4TProductLPrice.TPLRPrice, VS4TInventoryLOT.TIMCUnitRatioC,                           VS4TInventoryLOT.TIMCquantityCalc, VS4TInventoryLOT.TIMCDutyRate, VS4TLocation.TLctType, VS4TWarehouse.TWahGroup, VS4TInventoryLOT.TIMCDiscountText,                           VS4TInventoryLOT.TIMCDiscountTotal, VS4TPRMB.TPRMCustom1, VS4TPRMB.TPRMCustom2, VS4TPRMB.TPRMCustom3, VS4TPRMB.TPRMCustom4,VS4TPRMB.TPRMCustom5, VS4TProduct.TPdtDescription, VS4TInventoryLOT.TIMCTIvsCode,                           VS4TInventoryLOT.TIMCPrice, VS4TInventoryLOT.TIMCVATType, VS4TInventoryMB.TInMTIvsCode, VS4TInventoryMB.TInMFromTIvsCode, VS4TAP_1.TAPNName AS VInvTAPNName,                           VS4TInventory.TInvTJStLn, VS4TJobMB.TJbMControlQty, VS4TInventoryMB.TInMFlag3, VS4TInventoryLOT.TIMCMachineOutlet, VS4TInventoryLOT.TIMCMachineNo,                           VS4TInventoryType.TInTDescription, VS4TInventoryLOT.TIMCWastage, VS4TInventoryLOT.TIMCLOTCustom1, VS4TInventoryMB.TInMTACPTACYID, VS4TInventoryMB.TInMTACPID,                           VS4TInventoryLOT.TIMCReserve, VS4TAP.TAPNAddressBill, VS4TAP.TAPNPhone, VS4TInventory.TInvApproveDate, VS4TInventoryLOT.TIMCCostInputType, VS4TPOMB.TPOBSourceNo,                           VS4TPOMB.TPOBSourceLn, VS4TPR.TPRDTSecCode, VS4TProduct.TPdtAliasSlip, VS4TProductStat.TPMSLastPPrice, VS4TProductStat.TPMSLastPTCurCode, VS4TProduct.TPdtUnit2Ratio,                           VS4TProduct.TPdtUnit3Ratio, VS4TJobProductionM.TJPMTSepCode, VS4TMRPStepName.TSepName, VS4TMRPStepName.TSepTSecCode, VS4TSection_1.TSecName AS VIR2TSecName,                           VS4TInventoryLOT.TIMCDM, VS4TInventoryLOT.TIMCDL, VS4TInventoryLOT.TIMCOS, VS4TInventoryLOT.TIMCSDL, VS4TInventoryLOT.TIMCSOH, VS4TInventoryLOT.TIMCMOH,                           VS4TJob.TJobTBraCode, VS4TJobProduction.TJPdProductCode, VS4TInventory.TInvFlag1, VS4TProduct.TPdtFlag1, VS4TInventoryLOT.TIMCCostDecimal, VS4TInventory.TInvCreateBy,                           VS4TInventory.TInvEditBy, VS4TInventory.TInvConfirmBy, VS4TInventory.TInvApproveBy FROM            VS4TInventoryType INNER JOIN                          VS4TProduct LEFT OUTER JOIN                          VS4TProductType ON VS4TProduct.TPdtTPTTCode = VS4TProductType.TPTTCode LEFT OUTER JOIN                          VS4VProductGroup ON VS4TProduct.TPdtCode = VS4VProductGroup.VPdtCode LEFT OUTER JOIN                          VS4VProductSafeH ON VS4TProduct.TPdtCode = VS4VProductSafeH.TPSSTPdtCode LEFT OUTER JOIN                          VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode INNER JOIN                          VS4TMRPStepName RIGHT OUTER JOIN                          VS4TJobProduction RIGHT OUTER JOIN                          VS4TInventory LEFT OUTER JOIN                          VS4TDepartment ON VS4TInventory.TInvTDepCode = VS4TDepartment.TDepCode LEFT OUTER JOIN                          VS4TDivision ON VS4TInventory.TInvTDivCode = VS4TDivision.TDivCode LEFT OUTER JOIN                          VS4TBranch ON VS4TInventory.TInvTBraCode = VS4TBranch.TBraCode LEFT OUTER JOIN                          VS4TProject ON VS4TInventory.TInvTPrjCode = VS4TProject.TPrjCode LEFT OUTER JOIN                          VS4TJob ON VS4TInventory.TInvTJobNo = VS4TJob.TJobNo LEFT OUTER JOIN                          VS4TJobMB ON VS4TInventory.TInvTJobNo = VS4TJobMB.TJbMTJobNo AND VS4TInventory.TInvTJbMLn = VS4TJobMB.TJbMLn LEFT OUTER JOIN                          VS4TAR ON VS4TInventory.TInvTARNCode = VS4TAR.TARNCode LEFT OUTER JOIN                          VS4TSection ON VS4TInventory.TInvTSecCode = VS4TSection.TSecCode LEFT OUTER JOIN                          VS4TAP AS VS4TAP_1 ON VS4TInventory.TInvTARNCode = VS4TAP_1.TAPNCode LEFT OUTER JOIN                          VS4TJobProductionM ON VS4TInventory.TInvTJPdNo = VS4TJobProductionM.TJPMTJPdNo AND VS4TInventory.TInvTJPMLn = VS4TJobProductionM.TJPMLn LEFT OUTER JOIN                          VS4TSection AS VS4TSection_1 ON VS4TJobProductionM.TJPMTSecCode = VS4TSection_1.TSecCode INNER JOIN                          VS4TInventoryMB LEFT OUTER JOIN                          VS4TLocation ON VS4TInventoryMB.TInMTLctCode = VS4TLocation.TLctCode LEFT OUTER JOIN                          VS4TWarehouse ON VS4TLocation.TLctTWahCode = VS4TWarehouse.TWahCode LEFT OUTER JOIN                          VS4TLocation AS VS4TLocation_1 ON VS4TInventoryMB.TInMFromTLctCode = VS4TLocation_1.TLctCode LEFT OUTER JOIN                          VS4TInventoryLOT LEFT OUTER 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 LEFT OUTER JOIN                          VS4TProductLPrice ON VS4TInventoryMB.TInMTLctCode = VS4TProductLPrice.TPLRTLctCode AND VS4TInventoryMB.TInMTPdtCode = VS4TProductLPrice.TPLRTPdtCode LEFT OUTER JOIN                          VS4TPOMB ON VS4TInventoryLOT.TIMCTPODNo = VS4TPOMB.TPOBTPODNo AND VS4TInventoryLOT.TIMCTPOBLn = VS4TPOMB.TPOBLn LEFT OUTER JOIN                          VS4TPRMB ON VS4TPOMB.TPOBSourceNo = VS4TPRMB.TPRMTPRDNo AND VS4TPOMB.TPOBSourceLn = VS4TPRMB.TPRMLn LEFT OUTER JOIN                          VS4TPR ON VS4TPRMB.TPRMTPRDNo = VS4TPR.TPRDNo ON VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo ON VS4TJobProduction.TJPdNo = VS4TJobProductionM.TJPMTJPdNo ON                           VS4TMRPStepName.TSepCode = VS4TJobProductionM.TJPMTSepCode ON VS4TProduct.TPdtCode = VS4TInventoryMB.TInMTPdtCode LEFT OUTER JOIN                          VS4TProductStat ON VS4TProduct.TPdtCode = VS4TProductStat.TPMSTPdtCode ON VS4TInventoryType.TInTAlias = VS4TInventory.TInvTInTAlias
GO

CREATE VIEW VS4VInventoryROut AS  SELECT VS4TInventory.TInvNo, VS4TInventory.TInvMode, VS4TInventory.TInvTIBkCode, VS4TInventory.TInvDate, VS4TInventory.TInvInvoiceStatus, VS4TInventory.TInvTARNCode, VS4TInventory.TInvTInTAlias, VS4TInventory.TInvRefNo, VS4TInventory.TInvRefDate, VS4TInventory.TInvRefNo2, VS4TInventory.TInvRefDate2, VS4TInventory.TInvRefNo3, VS4TInventory.TInvCustom1, VS4TInventory.TInvCustom2, VS4TInventory.TInvCustom3, VS4TInventory.TInvCustom4, VS4TInventory.TInvCustom5, VS4TInventory.TInvTPrjCode, VS4TInventory.TInvTJobNo, VS4TInventory.TInvTJbMLn, VS4TInventory.TInvTJPdNo, VS4TInventory.TInvTJPMLn, VS4TInventory.TInvTSecCode, VS4TInventory.TInvTDepCode, VS4TInventory.TInvTDivCode, VS4TInventory.TInvTBraCode, VS4TInventory.TInvFromTBraCode, VS4TInventory.TInvTotal, VS4TInventory.TInvTotalRecord, VS4TInventory.TInvTotalQuantity, VS4TInventory.TInvRequestCode, VS4TInventory.TInvRequestBy, VS4TInventory.TInvDescription, VS4TInventory.TInvGLMethod, VS4TInventory.TInvTGLTNo, VS4TInventory.TInvDeliveryStatus, VS4TInventory.TInvSpecialFlag, VS4TInventory.TInvIsCompleted, VS4TInventory.TInvEditCode, VS4TInventory.TInvApproveStatus, VS4TInventory.TInvRevision, VS4TInventory.TInvCancelStatus, VS4TInventory.TInvCustomNo, VS4TInventory.TInvCustomDate, VS4TInventory.TInvTotalScrap, VS4TInventory.TInvTotalQScrap, VS4TInventory.TInvTotalQInput, VS4TInventory.TInvTotalAInput, VS4TInventory.TInvTotalRecordIn, VS4TInventory.TInvTotalPCScrap, VS4TInventory.TInvTotalPCQScrap, VS4TInventory.TInvSourceType, VS4TInventoryMB.TInMTInvNo, VS4TInventoryMB.TInMLn, VS4TInventoryMB.TInMTPdtCode, VS4TInventoryMB.TInMCustom1, VS4TInventoryMB.TInMSerialNo, VS4TInventoryMB.TInMLotNo, VS4TInventoryMB.TInMLotDate, VS4TInventoryMB.TInMScrapLevel, VS4TInventoryMB.TInMQuantityCalc, VS4TInventoryMB.TInMUnitRatio, VS4TInventoryMB.TInMQuantityBase, VS4TInventoryMB.TInMTUntCode, VS4TInventoryMB.TInMInQuantity, VS4TInventoryMB.TInMOutQuantity, VS4TInventoryMB.TInMAmouQuantity, VS4TInventoryMB.TInMAmouQuantity2, VS4TInventoryMB.TInMAmouQuantity3, VS4TInventoryMB.TInMAmount, VS4TInventoryMB.TInMStatus, VS4TInventoryMB.TInMFromTLctCode, VS4TInventoryMB.TInMTLctCode, VS4TInventoryMB.TInMDescription, VS4TInventoryMB.TInMTInTAlias, VS4TInventoryMB.TInMTSODNo, VS4TInventoryMB.TInMTSOBLn, VS4TInventoryMB.TInMTMDSLn, VS4TInventoryMB.TInMSourceType, VS4TInventoryMB.TInMSourceNo, VS4TInventoryMB.TInMSourceLn, VS4TInventoryMB.TInMQuantityText, VS4TInventoryMB.TInMArrear, VS4TInventoryMB.TInMShow, VS4TInventoryMB.TInMAgentPrice, VS4TInventoryMB.TInMQAStatus, VS4TInventoryMB.TInMQANote, VS4TInventoryMB.TInMTPltCode, VS4TInventoryMB.TInMFromTPltCode, VS4TInventoryMB.TInMQuantityCost, VS4TWarehouse.TWahName, VS4TLocation.TLctName, VS4TBranch.TBraName, VS4TProductType.TPTTName, VS4TInventoryType.TInTName, VS4TLocation.TLctTBraCode, VS4TAR.TARNName, VS4TAP.TAPNName, VS4TInventoryType.TInTSort, VS4TPOS.TPOSPrice, VS4TJob.TJobCode, VS4TJob.TJobCustomerName, 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.TPdtTPG1Code, VS4TProduct.TPdtTPG2Code, VS4TProduct.TPdtTBndCode, VS4TProduct.TPdtImage1, VS4TProduct.TPdtTPCTAlias, VS4TProduct.TPdtOrderPoint, VS4TProduct.TPdtAvgUsePerDay, VS4TProduct.TPdtStockQuantity, VS4TProduct.TPdtLastCost, VS4TProduct.TPdtStdCostCode, VS4TProduct.TPdtAverageCost, VS4TProduct.TPdtSerialType, VS4TProduct.TPdtBackDayCalc, VS4TLocation_1.TLctTWahCode AS VInMFromTWahCode, VS4TWarehouse.TWahCode AS VInMToTWahCode, VS4TWarehouse.TWahCode, VS4TJobMB.TJbMQuantity, VS4TJobMB.TJbMTUntCode, VS4TJobMB.TJbMQuantity2, VS4TJobMB.TJbMQuantity3, 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.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.TPdtPremiumCost, VS4VProductGroup.TPdLName, VS4VProductGroup.TPSEName, VS4VProductGroup.TPG1Name, VS4TInventoryLOT.TIMCAccountLevel, VS4TProduct.TPdtLastBalDate, VS4TPOS.TPOSPackAlias2, VS4TProduct.TPdtStandardCost, VS4TInventoryLOT.TIMCInputTCurCode, VS4TInventoryLOT.TIMCInputCostRate, VS4TInventoryLOT.TIMCAdjustCost, VS4TInventoryLOT.TIMCStandardCost, VS4TInventoryLOT.TIMCAVGCost, VS4TProductType.TPTTStockCost, VS4TProduct.TPdtStockType, VS4TProduct.TPdtCode, VS4TInventoryLOT.TIMCCOA, VS4TInventoryLOT.TIMCProposeStatus, VS4TInventoryLOT.TIMCProposeNote, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TProject.TPrjName, VS4TInventoryLOT.TIMCUnitRatioC, VS4TInventoryLOT.TIMCQuantityCalc, VS4TInventoryLOT.TIMCDutyRate, VS4TLocation.TLctType, VS4TWarehouse.TWahGroup, VS4TInventoryLOT.TIMCDiscountText, VS4TInventoryLOT.TIMCDiscountTotal, VS4TProduct.TPdtDescription, VS4TInventoryLOT.TIMCTIvSCode, VS4TInventoryLOT.TIMCPrice, VS4TInventoryLOT.TIMCVATType, VS4TInventoryMB.TInMTIvSCode, VS4TInventoryMB.TInMFromTIvsCode, VS4TAP_1.TAPNName AS VInvTAPNName, VS4TInventory.TInvTJStLn, VS4TJobMB.TJbMControlQty, VS4TInventoryMB.TInMFlag3, VS4TJobMB.TJbMCustom4, VS4TJobMB.TJbMCustom5, VS4TProduct.TPdtFlag1, VS4TInventoryLOT.TIMCMachineOutlet, VS4TInventoryLOT.TIMCMachineNo, VS4TInventoryType.TInTDescription, VS4TInventoryLOT.TIMCWASTAGE, VS4TInventoryLOT.TIMCLotCustom1, VS4TInventoryMB.TInMTACPTACYID, VS4TInventoryMB.TInMTACPID, VS4TInventoryLOT.TIMCReserve, VS4TAP.TAPNAddressBill, VS4TAP.TAPNPhone, VS4TInventory.TInvApproveDate, VS4TInventory.TInvConfirmStatus, VS4TInventoryLOT.TIMCCostInputType, VS4TInventory.TInvFlag1, VS4TJobProductionM.TJPMTSecCode, VS4TProduct.TPdtAliasSlip, VS4TProductStat.TPMSLastPPrice, VS4TProductStat.TPMSLastPTCurCode, VS4TProduct.TPdtUnit2Ratio, VS4TProduct.TPdtUnit3Ratio, VS4TInventoryLOT.TIMCFreightFee, VS4TInventoryLOT.TIMCInsurance, VS4TInventoryLOT.TIMCOtherFee, VS4TInventoryLOT.TIMCDutyAmount, VS4TInventoryLOT.TIMCUnitCostBFA, VS4TInventoryMB.TInMUnitCost, VS4TInventoryLOT.TIMCCostDecimal, VS4TSO.TSODTSBkCode, VS4TSO_1.TSODTSBkCode AS VIROTSBkCode 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 VS4TProduct AS VS4TProduct_1 ON VS4TJobMB.TJbMTPdtCode = VS4TProduct_1.TPdtCode) LEFT JOIN VS4TAR ON VS4TInventory.TInvTARNCode = VS4TAR.TARNCode) LEFT JOIN VS4TSection ON VS4TInventory.TInvTSecCode = VS4TSection.TSecCode) LEFT JOIN VS4TAP AS VS4TAP_1 ON VS4TInventory.TInvTARNCode = VS4TAP_1.TAPNCode) LEFT JOIN VS4TJobProductionM ON (VS4TInventory.TInvTJPdNo = VS4TJobProductionM.TJPMTJPdNo) AND (VS4TInventory.TInvTJPMLn = VS4TJobProductionM.TJPMLn)) INNER JOIN (((((VS4TInventoryMB LEFT JOIN VS4TLocation ON VS4TInventoryMB.TInMTLctCode = VS4TLocation.TLctCode) LEFT JOIN VS4TWarehouse ON VS4TLocation.TLctTWahCode = VS4TWarehouse.TWahCode) LEFT JOIN VS4TLocation AS VS4TLocation_1 ON VS4TInventoryMB.TInMFromTLctCode = VS4TLocation_1.TLctCode) 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 VS4TProductStat ON VS4TProduct.TPdtCode = VS4TProductStat.TPMSTPdtCode) ON VS4TSO.TSODNo = VS4TSOMB.TSOBTSODNo) ON VS4TInventoryType.TInTAlias = VS4TInventory.TInvTInTAlias) LEFT JOIN VS4TSO AS VS4TSO_1 ON VS4TJob.TJobNo = VS4TSO_1.TSODNo
GO

CREATE VIEW VS4VInventorySCD AS  SELECT VS4TInventorySCD.*, VS4TProduct.*, VS4TUnit.TUntName, VS4VProductGroup.*, VS4TInventoryType.TInTSort FROM VS4TUnit RIGHT JOIN (((VS4TInventorySCD LEFT JOIN VS4TProduct ON VS4TInventorySCD.TSCDTPdtCode = VS4TProduct.TPdtCode) LEFT JOIN VS4VProductGroup ON VS4TProduct.TPdtCode = VS4VProductGroup.VPdtCode) LEFT JOIN VS4TInventoryType ON VS4TInventorySCD.TSCDTInTAlias = VS4TInventoryType.TInTAlias) ON VS4TUnit.TUntCode = VS4TProduct.TPdtTUntCode
GO

CREATE VIEW VS4VInventorySCDJB AS  SELECT VS4VInventoryRJob.TInvNo, VS4VInventoryRJob.TInvMode, VS4VInventoryRJob.TInvTIBkCode, VS4VInventoryRJob.TInvDate, VS4VInventoryRJob.TInvTARNCode, VS4VInventoryRJob.TInvTInTAlias, VS4VInventoryRJob.TInvRefNo, VS4VInventoryRJob.TInvRefDate, VS4VInventoryRJob.TInvRefNo2, VS4VInventoryRJob.TInvRefDate2, VS4VInventoryRJob.TInvRefNo3, VS4VInventoryRJob.TInvCustom1, VS4VInventoryRJob.TInvCustom2, VS4VInventoryRJob.TInvCustom3, VS4VInventoryRJob.TInvCustom4, VS4VInventoryRJob.TInvCustom5, VS4VInventoryRJob.TInvTPrjCode, VS4VInventoryRJob.TInvTJobNo, VS4VInventoryRJob.TInvTJbMLn, VS4VInventoryRJob.TInvTJPdNo, VS4VInventoryRJob.TInvTJPMLn, VS4VInventoryRJob.TInvTSecCode, VS4VInventoryRJob.TInvTDepCode, VS4VInventoryRJob.TInvTDivCode, VS4VInventoryRJob.TInvTBraCode, VS4VInventoryRJob.TInvTotal, VS4VInventoryRJob.TInvTotalRecord, VS4VInventoryRJob.TInvTotalQuantity, VS4VInventoryRJob.TInvRequestCode, VS4VInventoryRJob.TInvRequestBy, VS4VInventoryRJob.TInvDescription, VS4VInventoryRJob.TInvGLMethod, VS4VInventoryRJob.TInvTGLTNo, VS4VInventoryRJob.TInvDeliveryStatus, VS4VInventoryRJob.TInvSpecialFlag, VS4VInventoryRJob.TInvIsCompleted, VS4VInventoryRJob.TInvEditCode, VS4VInventoryRJob.TInvApproveStatus, VS4VInventoryRJob.TInvRevision, VS4VInventoryRJob.TInvCancelStatus, VS4VInventoryRJob.TInvTotalScrap, VS4VInventoryRJob.TInvTotalQScrap, VS4VInventoryRJob.TInvTotalQInput, VS4VInventoryRJob.TInvTotalAInput, VS4VInventoryRJob.TInvTotalRecordIn, VS4VInventoryRJob.TInvTotalPCScrap, VS4VInventoryRJob.TInvTotalPCQScrap, VS4VInventoryRJob.TInvSourceType, VS4VInventoryRJob.TInMTInvNo, VS4VInventoryRJob.TInMLn, VS4VInventoryRJob.TInMTPdtCode, VS4VInventoryRJob.TInMCustom1, VS4VInventoryRJob.TInMSerialNo, VS4VInventoryRJob.TInMLotNo, VS4VInventoryRJob.TInMLotDate, VS4VInventoryRJob.TInMScrapLevel, VS4VInventoryRJob.TInMQuantityCalc, VS4VInventoryRJob.TInMUnitRatio, VS4VInventoryRJob.TInMQuantityBase, VS4VInventoryRJob.TInMTUntCode, VS4VInventoryRJob.TInMInQuantity, VS4VInventoryRJob.TInMOutQuantity, VS4VInventoryRJob.TInMAmouQuantity, VS4VInventoryRJob.TInMAmouQuantity2, VS4VInventoryRJob.TInMAmouQuantity3, VS4VInventoryRJob.TInMAmount, VS4VInventoryRJob.TInMStatus, VS4VInventoryRJob.TInMTLctCode, VS4VInventoryRJob.TInMDescription, VS4VInventoryRJob.TInMTInTAlias, VS4VInventoryRJob.TInMTSODNo, VS4VInventoryRJob.TInMTSOBLn, VS4VInventoryRJob.TInMTMDSLn, VS4VInventoryRJob.TInMSourceType, VS4VInventoryRJob.TInMSourceNo, VS4VInventoryRJob.TInMSourceLn, VS4VInventoryRJob.TInMQuantityText, VS4VInventoryRJob.TInMArrear, VS4VInventoryRJob.TInMShow, VS4VInventoryRJob.TInMAgentPrice, VS4VInventoryRJob.TInMQAStatus, VS4VInventoryRJob.TInMQANote, VS4VInventoryRJob.TInMTPltCode, VS4VInventoryRJob.TInMFromTPltCode, VS4VInventoryRJob.TInMQuantityCost, VS4VInventoryRJob.TWahName, VS4VInventoryRJob.TLctName, VS4VInventoryRJob.TBraName, VS4VInventoryRJob.TPTTName, VS4VInventoryRJob.TInTName, VS4VInventoryRJob.TLctTBraCode, VS4VInventoryRJob.TARNName, VS4VInventoryRJob.TAPNName, VS4VInventoryRJob.TInTSort, VS4VInventoryRJob.TJobCode, VS4VInventoryRJob.TJobCustomerName, VS4VInventoryRJob.TJbMTPdtCode, VS4VInventoryRJob.TJbMProductName, VS4VInventoryRJob.TPdtBarcode, VS4VInventoryRJob.TPdtName, VS4VInventoryRJob.TPdtName2, VS4VInventoryRJob.TPdtFactoryCode, VS4VInventoryRJob.TPdtTUntCode, VS4VInventoryRJob.TPdtTUntCode2, VS4VInventoryRJob.TPdtTUntCode3, VS4VInventoryRJob.TPOSPackText1, VS4VInventoryRJob.TPOSPackText2, VS4VInventoryRJob.TPOSPackAlias1, VS4VInventoryRJob.TPdtTPTTCode, VS4VInventoryRJob.TPdtTAPNCode, VS4VInventoryRJob.TPdtTPDLCode, VS4VInventoryRJob.TPdtTPSECode, VS4VInventoryRJob.TPdtTPS2Code, VS4VInventoryRJob.TPdtTPG1Code, VS4VInventoryRJob.TPdtTPG2Code, VS4VInventoryRJob.TPdtTBndCode, VS4VInventoryRJob.TPdtImage1, VS4VInventoryRJob.TPdtTPCTAlias, VS4VInventoryRJob.TPdtOrderPoint, VS4VInventoryRJob.TPdtLastCost, VS4VInventoryRJob.TPdtStdCostCode, VS4VInventoryRJob.TPdtAverageCost, VS4VInventoryRJob.TPdtSerialType, VS4VInventoryRJob.TPdtBackDayCalc, VS4VInventoryRJob.TPRDNo, VS4VInventoryRJob.TPRDTPRBCode, VS4VInventoryRJob.TPRDDate, VS4VInventoryRJob.VInMFromTWahCode, VS4VInventoryRJob.VInMToTWahCode, VS4VInventoryRJob.TWahCode, VS4VInventoryRJob.TJbMQuantity, VS4VInventoryRJob.TJbMTUntCode, VS4VInventoryRJob.TJbMQuantity2, VS4VInventoryRJob.TJbMQuantity3, VS4VInventoryRJob.TJbMCustom1, VS4VInventoryRJob.TJbMCustom2, VS4VInventoryRJob.TJbMCustom3, VS4VInventoryRJob.TJbMCustom4,VS4VInventoryRJob.TJbMCustom5,VS4VInventoryRJob.TPdtTPPuCode, VS4VInventoryRJob.TIMCJobCode, VS4VInventoryRJob.TIMCCustom2, VS4VInventoryRJob.TIMCCustom3, VS4VInventoryRJob.TIMCCustom4, VS4VInventoryRJob.TIMCCustom5, VS4VInventoryRJob.TIMCIsPremium, VS4VInventoryRJob.TIMCPremiumNote, VS4VInventoryRJob.TIMCLotNo2, VS4VInventoryRJob.TIMCGrade, VS4VInventoryRJob.TIMCNoExpire, VS4VInventoryRJob.TIMCExpireDate, VS4VInventoryRJob.TIMCTCgTID, VS4VInventoryRJob.TIMCInputCost, VS4VInventoryRJob.TIMCLastUnitCost, VS4VInventoryRJob.TIMCPerQuantity, VS4VInventoryRJob.TIMCUnitCalc, VS4VInventoryRJob.TIMCUnitCost, VS4VInventoryRJob.TIMCCostCode, VS4VInventoryRJob.TIMCTPODNo, VS4VInventoryRJob.TIMCTPOBLn, VS4VInventoryRJob.TIMCTPDELn, VS4VInventoryRJob.TInTInputCost, VS4VInventoryRJob.TIMCReceiveNo, VS4VInventoryRJob.TIMCReceiveLn, VS4VInventoryRJob.TPSSStockMin, VS4VInventoryRJob.TIMCQAStatus, VS4VInventoryRJob.TIMCQANote, VS4VInventoryRJob.TARNAddressBill, VS4VInventoryRJob.TIMCTAPNCode, VS4VInventoryRJob.TIMCInvoiceNo, VS4VInventoryRJob.TIMCInvoiceDate, VS4VInventoryRJob.TIMCTUntCode, VS4VInventoryRJob.TIMCUnitRatio, VS4VInventoryRJob.TPdtPremiumCost, VS4VInventoryRJob.TPdLName, VS4VInventoryRJob.TPSEName, VS4VInventoryRJob.TPG1Name, VS4VInventoryRJob.TIMCAccountLevel, VS4VInventoryRJob.TPdtLastBalDate, VS4VInventoryRJob.TPOSPackAlias2, VS4VInventoryRJob.TPdtStandardCost, VS4VInventoryRJob.TIMCInputTCurCode, VS4VInventoryRJob.TIMCInputCostRate, VS4VInventoryRJob.TIMCAdjustCost, VS4VInventoryRJob.TIMCStandardCost, VS4VInventoryRJob.TIMCAVGCost, VS4VInventoryRJob.TPTTStockCost, VS4VInventoryRJob.TPdtStockType, VS4VInventoryRJob.TPdtCode, VS4VInventoryRJob.TIMCCOA, VS4VInventoryRJob.TIMCProposeStatus, VS4VInventoryRJob.TIMCProposeNote, VS4VInventoryRJob.TDivName, VS4VInventoryRJob.TDepName, VS4VInventoryRJob.TPrjName, VS4VInventoryRJob.TPLRPrice, VS4VInventoryRJob.TIMCUnitRatioC, VS4VInventoryRJob.TIMCQuantityCalc, VS4VInventoryRJob.TIMCDutyRate, VS4VInventoryRJob.TLctType, VS4VInventoryRJob.TWahGroup, VS4VInventoryRJob.TIMCDiscountText, VS4VInventoryRJob.TIMCDiscountTotal, VS4VInventoryRJob.TPdtDescription, VS4VInventoryRJob.TIMCTIvSCode, VS4VInventoryRJob.TIMCPrice, VS4VInventoryRJob.TIMCVATType, VS4VInventoryRJob.TInMTIvSCode, VS4VInventoryRJob.TInMFromTIvsCode, VS4VInventoryRJob.VInvTAPNName, VS4VInventoryRJob.TInvTJStLn, VS4VInventoryRJob.TJbMControlQty, VS4VInventoryRJob.TInMFlag3, VS4VInventoryRJob.TIMCMachineOutlet, VS4VInventoryRJob.TIMCMachineNo, VS4VInventoryRJob.TInTDescription, VS4VInventoryRJob.TIMCWASTAGE, VS4VInventoryRJob.TIMCLotCustom1, VS4VInventoryRJob.TInMTACPTACYID, VS4VInventoryRJob.TInMTACPID, VS4VInventoryRJob.TIMCReserve, VS4VInventoryRJob.TAPNAddressBill, VS4VInventoryRJob.TAPNPhone, VS4VInventoryRJob.TInvApproveDate, VS4VInventoryRJob.TIMCCostInputType, VS4VInventoryRJob.TInvFlag1, VS4VInventoryRJob.TPOBSourceNo, VS4VInventoryRJob.TPOBSourceLn, VS4VInventoryRJob.TPdtAliasSlip, VS4VInventoryRJob.TPMSLastPPrice, VS4VInventoryRJob.TPMSLastPTCurCode, VS4VInventoryRJob.TPdtUnit2Ratio, VS4VInventoryRJob.TPdtUnit3Ratio, VS4VInventoryRJob.TJPMTSepCode, VS4VInventoryRJob.TSepName, VS4VInventoryRJob.TSepTSecCode, VS4VInventoryRJob.VIR2TSecName, VS4VInventoryRJob.TIMCDM, VS4VInventoryRJob.TIMCDL, VS4VInventoryRJob.TIMCOS, VS4VInventoryRJob.TIMCSDL, VS4VInventoryRJob.TIMCSOH, VS4VInventoryRJob.TIMCMOH, VS4TInventorySCD.TSCDTPdtCode, VS4TInventorySCD.TSCDPayQty, VS4TInventorySCD.TSCDPayCost, VS4TInventorySCD.TSCDPayAmount, VS4TInventorySCD.TSCDID, VS4VInventoryRJob.TJobTBraCode, VS4TProduct.TPdtName AS VSCJTPdtName, VS4TProduct.TPdtTUntCode AS VSCJTPdtTUntCode, VS4VInventoryRJob.TIMCCostDecimal FROM (VS4VInventoryRJob INNER JOIN VS4TInventorySCD ON VS4VInventoryRJob.TInMTInvNo = VS4TInventorySCD.TSCDDocNo) LEFT JOIN VS4TProduct ON VS4TInventorySCD.TSCDTPdtCode = VS4TProduct.TPdtCode WHERE (((VS4VInventoryRJob.TInMAmouQuantity)>0) AND ((VS4TInventorySCD.TSCDPayQty)>0))
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, VS4TInventoryMB.TInMTInvNo, VS4TInventory.TInvCustomNo, VS4TInventory.TInvCustomDate, VS4TInventoryLOT.TIMCQuantityCalc, VS4TInventoryLOT.TIMCDiscountText, VS4TInventoryLOT.TIMCPrice, VS4TInventoryLOT.TIMCIsPremium, VS4TInventoryLOT.TIMCVATType, VS4TInventoryLOT.TIMCVATRate, VS4TInventoryLOT.TIMCInputTCurCode, VS4TInventoryLOT.TIMCInputCostRate, VS4TInventory.TInvInvoiceStatus 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, VS4TInventoryMB.TInMTInvNo, VS4TInventory.TInvCustomNo, VS4TInventory.TInvCustomDate, VS4TInventoryLOT.TIMCQuantityCalc, VS4TInventoryLOT.TIMCDiscountText, VS4TInventoryLOT.TIMCPrice, VS4TInventoryLOT.TIMCIsPremium, VS4TInventoryLOT.TIMCVATType, VS4TInventoryLOT.TIMCVATRate, VS4TInventoryLOT.TIMCInputTCurCode, VS4TInventoryLOT.TIMCInputCostRate, VS4TInventory.TInvApproveStatus, VS4TInventory.TInvCancelStatus, VS4TInventory.TInvInvoiceStatus 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.TInvNo, VS4TInventory.TInvMode, VS4TInventory.TInvTIBkCode, VS4TInventory.TInvDate, VS4TInventory.TInvInvoiceStatus, VS4TInventory.TInvTARNCode, VS4TInventory.TInvTInTAlias,                    VS4TInventory.TInvRefNo, VS4TInventory.TInvRefDate, VS4TInventory.TInvRefNo2, VS4TInventory.TInvRefDate2, VS4TInventory.TInvRefNo3, VS4TInventory.TInvCustom1, VS4TInventory.TInvCustom2,                    VS4TInventory.TInvCustom3, VS4TInventory.TInvCustom4, VS4TInventory.TInvCustom5, VS4TInventory.TInvTPrjCode, VS4TInventory.TInvTJobNo, VS4TInventory.TInvTJbMLn, VS4TInventory.TInvTJPdNo,                    VS4TInventory.TInvTJPMLn, VS4TInventory.TInvTSecCode, VS4TInventory.TInvTDepCode, VS4TInventory.TInvTDivCode, VS4TInventory.TInvTBraCode, VS4TInventory.TInvFromTBraCode,                    VS4TInventory.TInvTotal, VS4TInventory.TInvTotalRecord, VS4TInventory.TInvTotalQuantity, VS4TInventory.TInvRequestCode, VS4TInventory.TInvRequestBy, VS4TInventory.TInvDescription,                    VS4TInventory.TInvGLMethod, VS4TInventory.TInvTGLTNo, VS4TInventory.TInvDeliveryStatus, VS4TInventory.TInvSpecialFlag, VS4TInventory.TInvIsCompleted, VS4TInventory.TInvEditCode,                    VS4TInventory.TInvApproveStatus, VS4TInventory.TInvRevision, VS4TInventory.TInvCancelStatus, VS4TInventory.TInvCustomNo, VS4TInventory.TInvCustomDate, VS4TInventory.TInvTotalScrap,                    VS4TInventory.TInvTotalQScrap, VS4TInventory.TInvTotalQInput, VS4TInventory.TInvTotalAInput, VS4TInventory.TInvTotalRecordIn, VS4TInventory.TInvTotalPCScrap, VS4TInventory.TInvTotalPCQScrap,                    VS4TInventory.TInvSourceType, VS4TInventoryMB.TInMTInvNo, VS4TInventoryMB.TInMLn, VS4TInventoryMB.TInMTPdtCode, VS4TInventoryMB.TInMCustom1, VS4TInventoryMB.TInMSerialNo,                    VS4TInventoryMB.TInMLotNo, VS4TInventoryMB.TInMLotDate, VS4TInventoryMB.TInMScrapLevel, VS4TInventoryMB.TInMQuantityCalc, VS4TInventoryMB.TInMUnitRatio, VS4TInventoryMB.TInMQuantityBase,                    VS4TInventoryMB.TInMTUntCode, VS4TInventoryMB.TInMInQuantity, VS4TInventoryMB.TInMOutQuantity, VS4TInventoryMB.TInMAmouQuantity, VS4TInventoryMB.TInMAmouQuantity2,                    VS4TInventoryMB.TInMAmouQuantity3, VS4TInventoryMB.TInMAmount, VS4TInventoryMB.TInMStatus, VS4TInventoryMB.TInMFromTLctCode, VS4TInventoryMB.TInMTLctCode,                    VS4TInventoryMB.TInMDescription, VS4TInventoryMB.TInMTInTAlias, VS4TInventoryMB.TInMTSODNo, VS4TInventoryMB.TInMTSOBLn, VS4TInventoryMB.TInMTMDSLn, VS4TInventoryMB.TInMSourceType,                    VS4TInventoryMB.TInMSourceNo, VS4TInventoryMB.TInMSourceLn, VS4TInventoryMB.TInMQuantityText, VS4TInventoryMB.TInMArrear, VS4TInventoryMB.TInMShow, VS4TInventoryMB.TInMAgentPrice,                    VS4TInventoryMB.TInMQAStatus, VS4TInventoryMB.TInMQANote, VS4TInventoryMB.TInMTPltCode, VS4TInventoryMB.TInMFromTPltCode, VS4TInventoryMB.TInMQuantityCost, VS4TWarehouse.TWahName,                    VS4TLocation.TLctName, VS4TBranch.TBraName, VS4TProductType.TPTTName, VS4TInventoryType.TInTName, VS4TLocation.TLctTBraCode, VS4TAR.TARNName, VS4TAP.TAPNName,                    VS4TInventoryType.TInTSort, VS4TPOS.TPOSPrice, VS4TJob.TJobCode, VS4TJob.TJobCustomerName, 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.TPdtTPG1Code, VS4TProduct.TPdtTPG2Code, VS4TProduct.TPdtTBndCode, VS4TProduct.TPdtImage1, VS4TProduct.TPdtTPCTAlias, VS4TProduct.TPdtOrderPoint,                    VS4TProduct.TPdtAvgUsePerDay, VS4TProduct.TPdtStockQuantity, VS4TProduct.TPdtLastCost, VS4TProduct.TPdtAverageCost, VS4TProduct.TPdtSerialType, VS4TProduct.TPdtBackDayCalc,                    VS4TPR.TPRDNo, VS4TPR.TPRDTPRBCode, VS4TPR.TPRDDate, VS4TPR.TPRDRequestBy, VS4TPR.TPRDDescription, VS4TPR.TPRDTBraCode, VS4TPR.TPRDTDivCode,                    VS4TLocation_1.TLctTWahCode AS VInMFromTWahCode, VS4TWarehouse.TWahCode AS VInMToTWahCode, VS4TWarehouse.TWahCode, VS4TJobMB.TJbMQuantity, VS4TJobMB.TJbMTUntCode,                    VS4TJobMB.TJbMQuantity2, VS4TJobMB.TJbMQuantity3, 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.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.TPdtPremiumCost, VS4VProductGroup.TPdLName, VS4VProductGroup.TPSEName, VS4VProductGroup.TPG1Name, VS4TInventoryLOT.TIMCAccountLevel,                    VS4TProduct.TPdtLastBalDate, VS4TPOS.TPOSPackAlias2, VS4TProduct.TPdtStandardCost, VS4TInventoryLOT.TIMCInputTCurCode, VS4TInventoryLOT.TIMCInputCostRate, VS4TInventoryLOT.TIMCAdjustCost,                    VS4TInventoryLOT.TIMCStandardCost, VS4TInventoryLOT.TIMCAVGCost, VS4TProductType.TPTTStockCost, VS4TProduct.TPdtStockType, VS4TProduct.TPdtCode, VS4TInventoryLOT.TIMCCOA,                    VS4TInventoryLOT.TIMCProposeStatus, VS4TInventoryLOT.TIMCProposeNote, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TProject.TPrjName, VS4TProductLPrice.TPLRPrice,                    VS4TInventoryLOT.TIMCUnitRatioC, VS4TInventoryLOT.TIMCquantityCalc, VS4TInventoryLOT.TIMCDutyRate, VS4TLocation.TLctType, VS4TWarehouse.TWahGroup, VS4TInventoryLOT.TIMCDiscountText,                    VS4TInventoryLOT.TIMCDiscountTotal, VS4TProduct.TPdtDescription, VS4TInventoryLOT.TIMCTIvsCode, VS4TInventoryLOT.TIMCPrice, VS4TInventoryLOT.TIMCVATType, VS4TInventoryMB.TInMTIvsCode,                    VS4TInventoryMB.TInMFromTIvsCode, VS4TAP_1.TAPNName AS VInvTAPNName, VS4TInventory.TInvTJStLn, VS4TJobMB.TJbMControlQty, VS4TInventoryMB.TInMFlag3, VS4TProduct.TPdtFlag1,                    VS4TInventoryLOT.TIMCMachineOutlet, VS4TInventoryLOT.TIMCMachineNo, VS4TInventoryType.TInTDescription, VS4TInventoryLOT.TIMCWastage, VS4TInventoryLOT.TIMCLOTCustom1,                    VS4TInventoryMB.TInMTACPTACYID, VS4TInventoryMB.TInMTACPID, VS4TInventoryLOT.TIMCReserve, VS4TAP.TAPNAddressBill, VS4TAP.TAPNPhone, VS4TInventory.TInvApproveDate,                    VS4TInventory.TInvConfirmStatus, VS4TInventoryLOT.TIMCCostInputType, VS4TInventory.TInvFlag1, VS4TPOMB.TPOBSourceNo, VS4TPOMB.TPOBSourceLn, VS4TPR.TPRDTSecCode,                    VS4TJobProductionM.TJPMTSecCode, VS4TPOMBAOL.TPOATSecCode, VS4TProduct.TPdtAliasSlip, VS4TProductStat.TPMSLastPPrice, VS4TProductStat.TPMSLastPTCurCode, VS4TProduct.TPdtUnit2Ratio,                    VS4TProduct.TPdtUnit3Ratio, VS4TInventoryLOT.TIMCFreightFee, VS4TInventoryLOT.TIMCInsurance, VS4TInventoryLOT.TIMCOtherFee, VS4TInventoryLOT.TIMCDutyAmount,                    VS4TInventoryLOT.TIMCUnitCostBFA, VS4TInventoryMB.TInMUnitCost, VS4TInventoryLOT.TIMCCostDecimal, VS4TAPInvoice.TIAPRefNo, VS4TPOMB.TPOBTotalArrear, VS4TProduct2.TPd2Weight,                    VS4TInventory.TInvConfirmBy, VS4TSOMB.TSOBTLblCode, VS4TSO.TSODCustom1, VS4TSO.TSODCustom2, VS4TSO.TSODCustom3, VS4TAssetAlias.TAsACustom1, VS4TAssetAlias.TAsACustom2,                    VS4TAssetAlias.TAsACustom3, ISNULL(VS4TAssetAlias.TAsACustom1, VS4TSO.TSODCustom1) AS VInvCustom1, ISNULL(VS4TAssetAlias.TAsACustom2, VS4TSO.TSODCustom2) AS VInvCustom2,                    ISNULL(VS4TAssetAlias.TAsACustom3, VS4TSO.TSODCustom3) AS VInvCustom3 FROM     VS4TInventoryType INNER JOIN                   VS4TProduct LEFT OUTER JOIN                   VS4TProductType ON VS4TProduct.TPdtTPTTCode = VS4TProductType.TPTTCode LEFT OUTER JOIN                   VS4VProductGroup ON VS4TProduct.TPdtCode = VS4VProductGroup.VPdtCode LEFT OUTER JOIN                   VS4VProductSafeH ON VS4TProduct.TPdtCode = VS4VProductSafeH.TPSSTPdtCode LEFT OUTER JOIN                   VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode INNER JOIN                   VS4TInventory LEFT OUTER JOIN                   VS4TDepartment ON VS4TInventory.TInvTDepCode = VS4TDepartment.TDepCode LEFT OUTER JOIN                   VS4TDivision ON VS4TInventory.TInvTDivCode = VS4TDivision.TDivCode LEFT OUTER JOIN                   VS4TBranch ON VS4TInventory.TInvTBraCode = VS4TBranch.TBraCode LEFT OUTER JOIN                   VS4TProject ON VS4TInventory.TInvTPrjCode = VS4TProject.TPrjCode LEFT OUTER JOIN                   VS4TJob ON VS4TInventory.TInvTJobNo = VS4TJob.TJobNo LEFT OUTER JOIN                   VS4TJobMB ON VS4TInventory.TInvTJbMLn = VS4TJobMB.TJbMLn AND VS4TInventory.TInvTJobNo = VS4TJobMB.TJbMTJobNo LEFT OUTER JOIN                   VS4TAR ON VS4TInventory.TInvTARNCode = VS4TAR.TARNCode LEFT OUTER JOIN                   VS4TSection ON VS4TInventory.TInvTSecCode = VS4TSection.TSecCode LEFT OUTER JOIN                   VS4TAP AS VS4TAP_1 ON VS4TInventory.TInvTARNCode = VS4TAP_1.TAPNCode LEFT OUTER JOIN                   VS4TJobProductionM ON VS4TInventory.TInvTJPMLn = VS4TJobProductionM.TJPMLn AND VS4TInventory.TInvTJPdNo = VS4TJobProductionM.TJPMTJPdNo LEFT OUTER JOIN                   VS4TAPInvoice ON VS4TInventory.TInvRefNo3 = VS4TAPInvoice.TIAPNo INNER JOIN                   VS4TInventoryMB LEFT OUTER JOIN                   VS4TLocation ON VS4TInventoryMB.TInMTLctCode = VS4TLocation.TLctCode LEFT OUTER JOIN                   VS4TWarehouse ON VS4TLocation.TLctTWahCode = VS4TWarehouse.TWahCode LEFT OUTER JOIN                   VS4TLocation AS VS4TLocation_1 ON VS4TInventoryMB.TInMFromTLctCode = VS4TLocation_1.TLctCode LEFT OUTER JOIN                   VS4TSOMB ON VS4TInventoryMB.TInMTSODNo = VS4TSOMB.TSOBTSODNo AND VS4TInventoryMB.TInMTSOBLn = VS4TSOMB.TSOBLn LEFT OUTER JOIN                   VS4TInventoryLOT LEFT OUTER JOIN                   VS4TAP ON VS4TInventoryLOT.TIMCTAPNCode = VS4TAP.TAPNCode 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 LEFT OUTER JOIN                   VS4TProductLPrice ON VS4TInventoryMB.TInMTPdtCode = VS4TProductLPrice.TPLRTPdtCode AND VS4TInventoryMB.TInMTLctCode = VS4TProductLPrice.TPLRTLctCode LEFT OUTER JOIN                   VS4TPOMB ON VS4TInventoryLOT.TIMCTPOBLn = VS4TPOMB.TPOBLn AND VS4TInventoryLOT.TIMCTPODNo = VS4TPOMB.TPOBTPODNo LEFT OUTER JOIN                   VS4TPRMB ON VS4TPOMB.TPOBSourceLn = VS4TPRMB.TPRMLn AND VS4TPOMB.TPOBSourceNo = VS4TPRMB.TPRMTPRDNo LEFT OUTER JOIN                   VS4TPR ON VS4TPRMB.TPRMTPRDNo = VS4TPR.TPRDNo LEFT OUTER JOIN                   VS4TPOMBAOL ON VS4TPOMB.TPOBLn = VS4TPOMBAOL.TPOATPOBLn AND VS4TPOMB.TPOBTPODNo = VS4TPOMBAOL.TPOATPOBTPODNo ON VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo ON                    VS4TProduct.TPdtCode = VS4TInventoryMB.TInMTPdtCode LEFT OUTER JOIN                   VS4TProductStat ON VS4TProduct.TPdtCode = VS4TProductStat.TPMSTPdtCode ON VS4TInventoryType.TInTAlias = VS4TInventory.TInvTInTAlias LEFT OUTER JOIN                   VS4TAssetAlias ON VS4TJob.TJobCode = VS4TAssetAlias.TAsACode LEFT OUTER JOIN                   VS4TSO ON VS4TJob.TJobNo = VS4TSO.TSODNo LEFT OUTER JOIN                   VS4TProduct2 ON VS4TProduct.TPdtCode = VS4TProduct2.TPd2TPdtCode
GO

CREATE VIEW VS4VInventSaleFC AS  SELECT VS4TInventory.TInvNo, VS4TInventory.TInvMode, VS4TInventory.TInvTIBkCode, VS4TInventory.TInvDate, VS4TInventory.TInvInvoiceStatus, VS4TInventory.TInvTARNCode, VS4TInventory.TInvTInTAlias, VS4TInventory.TInvRefNo, VS4TInventory.TInvRefDate, VS4TInventory.TInvRefNo2, VS4TInventory.TInvRefDate2, VS4TInventory.TInvRefNo3, VS4TInventory.TInvRefDate3, VS4TInventory.TInvCustom1, VS4TInventory.TInvCustom2, VS4TInventory.TInvCustom3, VS4TInventory.TInvCustom4, VS4TInventory.TInvCustom5, VS4TInventory.TInvTPrjCode, VS4TInventory.TInvTJobNo, VS4TInventory.TInvTJbMLn, VS4TInventory.TInvTMPSNo, VS4TInventory.TInvTJPdNo, VS4TInventory.TInvTJPMLn, VS4TInventory.TInvTSecCode, VS4TInventory.TInvTDepCode, VS4TInventory.TInvTDivCode, VS4TInventory.TInvTBraCode, VS4TInventory.TInvFromTBraCode, VS4TInventory.TInvTotal, VS4TInventory.TInvTotalRecord, VS4TInventory.TInvTotalQuantity, VS4TInventory.TInvRequestCode, VS4TInventory.TInvRequestBy, VS4TInventory.TInvDescription, VS4TInventory.TInvGLMethod, VS4TInventory.TInvTGLTNo, VS4TInventory.TInvDeliveryStatus, VS4TInventory.TInvSpecialFlag, VS4TInventory.TInvIsCompleted, VS4TInventory.TInvCreateBy, VS4TInventory.TInvCreateDate, VS4TInventory.TInvEditCode, VS4TInventory.TInvEditBy, VS4TInventory.TInvEditDate, VS4TInventory.TInvConfirmStatus, VS4TInventory.TInvConfirmBy, VS4TInventory.TInvConfirmDate, VS4TInventory.TInvApproveStatus, VS4TInventory.TInvApproveBy, VS4TInventory.TInvApproveDate, VS4TInventory.TInvApproveNote, VS4TInventory.TInvRevision, VS4TInventory.TInvCancelStatus, VS4TInventory.TInvCancelBy, VS4TInventory.TInvCancelDate, VS4TInventory.TInvCancelNote, VS4TInventory.TInvCustomNo, VS4TInventory.TInvCustomDate, VS4TInventory.TInvTotalScrap, VS4TInventory.TInvTotalQScrap, VS4TInventory.TInvTotalQInput, VS4TInventory.TInvTotalAInput, VS4TInventory.TInvTotalRecordIn, VS4TInventory.TInvTotalPCScrap, VS4TInventory.TInvTotalPCQScrap, VS4TInventory.TInvSourceType, VS4TInventoryMB.*, VS4TPO.TPODNo, VS4TPO.TPODTPOkCode, VS4TPO.TPODTPCACode, VS4TPO.TPODMode, VS4TPO.TPODDOArrears, VS4TPO.TPODType, VS4TPO.TPODDate, VS4TPO.TPODDueDate, VS4TPO.TPODRefNo, VS4TPO.TPODRefDate, VS4TPO.TPODRefNo2, VS4TPO.TPODInvoiceStatus, VS4TPO.TPODTJobNo, VS4TPO.TPODTJbMLn, VS4TPO.TPODTPrjCode, VS4TPO.TPODTBraCode, VS4TPO.TPODDeliveryDate, VS4TPO.TPODDeliveryTo, VS4TPO.TPODTAPNCode, VS4TPO.TPODTAPUCode, VS4TPO.TPODContactNote, VS4TPO.TPODContactName, VS4TPO.TPODSupplierName, VS4TPO.TPODSupAddress, VS4TPO.TPODConsignee, VS4TPO.TPODNotifyParty, VS4TPO.TPODPriceChannel, VS4TPO.TPODDiscountList, VS4TPO.TPODSubTotal, VS4TPO.TPODDiscountText, VS4TPO.TPODDiscountTotal, VS4TPO.TPODNetTotal, VS4TPO.TPODDepositText, VS4TPO.TPODDeposit, VS4TPO.TPODTotal, VS4TPO.TPODTotalFOB, VS4TPO.TPODTCurCode, VS4TPO.TPODExchangeRate, VS4TPO.TPODTotalInRate, VS4TPO.TPODVATType, VS4TPO.TPODVATRate, VS4TPO.TPODTaxBase, VS4TPO.TPODVATTotal, VS4TPO.TPODGrandTotal, VS4TPO.TPODNOTAXTotal, VS4TPO.TPODWTaxBase, VS4TPO.TPODWTaxRate, VS4TPO.TPODWTaxTotal, VS4TPO.TPODNetPayment, VS4TPO.TPODAdjustTotal, VS4TPO.TPODPremiumTotal, VS4TPO.TPODBaseIncoType, VS4TPO.TPODIncoType, VS4TPO.TPODIncoterms, VS4TPO.TPODOtherFee, VS4TPO.TPODTransportFee, VS4TPO.TPODHandlingFee, VS4TPO.TPODFreightFee, VS4TPO.TPODInsurance, VS4TPO.TPODTransportDesc, VS4TPO.TPODDuty, VS4TPO.TPODShipBy, VS4TPO.TPODCountryOrigin, VS4TPO.TPODDestination, VS4TPO.TPODCondition, VS4TPO.TPODConditionDay, VS4TPO.TPODCondition1, VS4TPO.TPODConditionDay1, VS4TPO.TPODPaymentNote, VS4TPO.TPODStatementNote, VS4TPO.TPODTShpCode, VS4TPO.TPODDeliveryNote, VS4TPO.TPODPackingNote, VS4TPO.TPODDayAvailable, VS4TPO.TPODDescription, VS4TPO.TPODCustom1, VS4TPO.TPODCustom2, VS4TPO.TPODCustom3, VS4TPO.TPODCustom4, VS4TPO.TPODCustom5, VS4TPO.TPODTPOTCode, VS4TPO.TPODLinkStatus, VS4TPO.TPODDeliveryStatus, VS4TPO.TPODFinishDate, VS4TPO.TPODCreateBy, VS4TPO.TPODCreateDate, VS4TPO.TPODEditCode, VS4TPO.TPODEditBy, VS4TPO.TPODEditDate, VS4TPO.TPODConfirmStatus, VS4TPO.TPODConfirmBy, VS4TPO.TPODConfirmDate, VS4TPO.TPODApproveStatus, VS4TPO.TPODApproveBy, VS4TPO.TPODApproveDate, VS4TPO.TPODApproveNote, VS4TPO.TPODRevision, VS4TPO.TPODCancelStatus, VS4TPO.TPODCancelBy, VS4TPO.TPODCancelDate, VS4TPO.TPODCancelNote, VS4TPO.TPODConditionType, VS4TPO.TPODLoadingDate, VS4TPO.TPODStartAgingDate, VS4TPO.TPODArrears, VS4TPO.TPODNote, VS4TPO.TPODToTBraCode, VS4TWarehouse.TWahName, VS4TLocation.TLctName, VS4TProduct.TPdtName, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TBranch.TBraName, VS4TProject.TPrjName, VS4TProduct.TPdtTPSECode, VS4TProductSection.TPSEName, VS4TProduct.TPdtTPG1Code, VS4TProductGroup1.TPG1Name, VS4TProduct.TPdtTPTTCode, 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.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 WHERE (((VS4TInventory.TInvTInTAlias)='SALEOUT') AND ((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 ((VS4TInventoryLOT.TIMCTCgTID)=1)) OR (((VS4TInventory.TInvTInTAlias)='SALEOUTPOS'))
GO

CREATE VIEW VS4VInventSerial AS  SELECT VS4TProduct.TPdtCode, VS4TProduct.TPdtBarcode, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtAliasSlip, VS4TProduct.TPdtAliasName, VS4TProduct.TPdtTDwgCode, VS4TProduct.TPdtTPrjCode, VS4TProduct.TPdtDescription, VS4TProduct.TPdtUnitType, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TProduct.TPdtUnit2Ratio, VS4TProduct.TPdtUnit3Ratio, VS4TProduct.TPdtUsage, VS4TProduct.TPdtUseBOM, VS4TProduct.TPdtOldCode, VS4TProduct.TPdtFactoryCode, VS4TProduct.TPdtFactoryOldCode, VS4TProduct.TPdtFactoryName, VS4TProduct.TPdtTransferCode, VS4TProduct.TPdtTransferName, VS4TProduct.TPdtTransferName2, VS4TProduct.TPdtTAPNCode, VS4TProduct.TPdtTPTTCode, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtTPSECode, VS4TProduct.TPdtTPS2Code, VS4TProduct.TPdtTPS3Code, VS4TProduct.TPdtTPS4Code, VS4TProduct.TPdtTPG1Code, VS4TProduct.TPdtTPG2Code, VS4TProduct.TPdtTPG3Code, VS4TProduct.TPdtTPG4Code, VS4TProduct.TPdtTBndCode, VS4TProduct.TPdtSceinceName, VS4TProduct.TPdtRegisterNo, VS4TProduct.TPdtUseMethod, VS4TProduct.TPdtWarning, VS4TProduct.TPdtGoodsDateLabel, VS4TProduct.TPdtExpDateLabel, VS4TProduct.TPdtQuantityText, VS4TProduct.TPdtIcon1, VS4TProduct.TPdtImage1, VS4TProduct.TPdtSpec1, VS4TProduct.TPdtTPCTAlias, VS4TProduct.TPdtCustom1, VS4TProduct.TPdtCustom2, VS4TProduct.TPdtCustom3, VS4TProduct.TPdtCustom4, VS4TProduct.TPdtCustom5, VS4TProduct.TPdtCustom6, VS4TProduct.TPdtCustom7, VS4TProduct.TPdtCustom8, VS4TProduct.TPdtCustom9, VS4TProduct.TPdtCustom10, VS4TProduct.TPdtSafeDayCalc, VS4TProduct.TPdtBackDayCalc, VS4TProduct.TPdtOrderPoint, VS4TProduct.TPdtMaxUsePerDay, VS4TProduct.TPdtAvgUsePerDay, VS4TProduct.TPdtStockType, VS4TProduct.TPdtStockQuantity, VS4TProduct.TPdtFirstDate, VS4TProduct.TPdtLastMoveDate, VS4TProduct.TPdtFirstCostInStk, VS4TProduct.TPdtLastCost, VS4TProduct.TPdtStandardCost, VS4TProduct.TPdtStdCostCode, VS4TProduct.TPdtAutoCostCode, VS4TProduct.TPdtAverageCost, VS4TProduct.TPdtAreaCost, VS4TProduct.TPdtAmount, VS4TProduct.TPdtTPPuCode, VS4TProduct.TPdtSerialType, VS4TProduct.TPdtPurchaseFee, VS4TProduct.TPdtGroupReport, VS4TProduct.TPdtSlowDay, VS4TProduct.TPdtDeadDay, VS4TProduct.TPdtLastBalDate, VS4TProduct.TPdtCreateCode, VS4TProduct.TPdtCreateDate, VS4TProduct.TPdtEditCode, VS4TProduct.TPdtEditDate, VS4TProduct.TPdtTextSort, VS4TProduct.TPdtFlag1, VS4TProduct.TPdtPremiumCost, VS4TProduct.TPdtTACSCode, VS4TProduct.TPdtStartDate, VS4TProduct.TPdtEndDate, VS4TProduct.TPdtTripDay, VS4TProduct.TPdtTAILCode, VS4TProduct.TPdtTCouCode, VS4TProduct.TPdtONSale, VS4TProduct.TPdtSetType, VS4TProduct.TPdtRFID, VS4TProduct.TPdtHasExpireDate, VS4TProduct.TPdtRequireCOA, VS4TProduct.TPdtTBraCode, VS4TProduct.TPdtDayExpire, VS4TProduct.TPdtGrade, VS4TProduct.TPdtAdjustCost, VS4TProduct.TPdtLastUnitCost, VS4TProduct.TPdtUnitRatioType, VS4TProduct2.TPd2TPdtCode, VS4TProduct2.TPd2Ln, VS4TProduct2.TPd2FillNameStock, VS4TProduct2.TPd2ScrapPCMRP, VS4TProduct2.TPd2ScrapPCReceive, VS4TProduct2.TPd2ScrapPCSend, VS4TProduct2.TPd2TaxType, VS4TProduct2.TPd2TaxRate, VS4TProduct2.TPd2CostFormula, VS4TProduct2.TPd2Weight, VS4TProduct2.TPd2SkipSuggest, VS4TProduct2.TPd2QuantityAlert, VS4TProduct2.TPd2TotalQuantity, VS4TProduct2.TPd2Yield, VS4TProduct2.TPd2HasBOM, VS4TProduct2.TPd2TWRMCode, VS4TProduct2.TPd2StdDM, VS4TProduct2.TPd2StdDL, VS4TProduct2.TPd2StdOH, VS4TProduct2.TPd2StdOHType, VS4TProduct2.TPd2ScrapType, VS4TProduct2.TPd2BulkPOrder, VS4TProduct2.TPd2MinimumPOrder, VS4TProduct2.TPd2MultiplePOrder, VS4TProduct2.TPd2Flag1, VS4TProduct2.TPd2VendorIncent1, VS4TProduct2.TPd2VendorIncent2, VS4TProduct2.TPd2BOMNote, VS4TProduct2.TPd2SelfMat, VS4TProduct2.TPd2StdDLType, TIMCTPdtCode, TIMCCustom1, TIMCSerialNo, TIMCLotNo, TIMCLotDate, TIMCReceiveNo, TIMCReceiveLn, TIMCJobCode, TIMCIsPremium, TIMCPremiumNote, TIMCCustom2, TIMCCustom3, TIMCCustom4, TIMCCustom5, TIMCScrapLevel, TIMCLotNo2, TIMCGrade, TIMCNoExpire, TIMCExpireDate, TIMCTCgTID, TIMCReserve, TIMCQAStatus, TIMCQANote, TIMCLastUnitCost, TIMCInputCost, TIMCPerQuantity, TIMCUnitCalc, TIMCUnitCost, TIMCCostCode, TIMCTPCTAlias, TIMCTAPNCode, TIMCInvoiceNo, TIMCInvoiceDate, TIMCTPODNo, TIMCTPOBLn, TIMCTPDELn, TIMCTUntCode, TIMCUnitRatio, TIMCUnit2Ratio, TIMCUnit3Ratio, TIMCLastDate, TIMCConsignFSDate, TIMCConsignLSDate, TIMCAccountLevel, TIMCIsOwner, TIMCFlag1, TIMCPKI, TIMCBarcode, TIMCRFID, TIMCQuantityCost, TIMCInputTCurCode, TIMCInputCostRate, TIMCAdjustCost, TIMCStandardCost, TIMCAVGCost, TIMCEmbUnitDMVAR, TIMCEmbUnitDLVAR, TIMCUnitDMVariance, TIMCUnitDLVariance, TIMCEmbUnitOHVAR, TIMCUnitOHVariance, TIMCDutyAmount, TIMCCOA, TIMCProposeStatus, TIMCProposeNote, TIMCUnitRatioC, TIMCquantityCalc, TIMCDiscountText, TIMCDiscountTotal, TIMCTIvsCode, TIMCPrice, TIMCVATType, TIMCVATRate, TIMCVATAmount, TIMCTInTAlias, TIMCDutyRate, TIMCInputCostRateC, TIMCOtherFee, TIMCTransportFee, TIMCHandlingFee, TIMCFreightFee, TIMCInsurance, TIMCTransportDesc, TIMCDM, TIMCDL, TIMCOS, TIMCMOH, TIMCCostAmount, TIMCBahtBank, TIMCBahtCustom, TIMCBahtDif, TIMCUnitRatioType, TIMCMachineNo, TIMCMachineOutlet, TIMCWastage, TIMCLOTCustom1, TIMCTPRMTPRDNo, TIMCTPRMLn, TIMCCostInputType, TIMCLOTCost, TIMCQCInputCount, TIMCQCSet, TIMCDiscountText2, TIMCAgingDate, TIMCSOH, TIMCSDL, TIMCStockId, 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.TInMLotDate = VS4TInventoryLOT.TIMCLotDate) AND (VS4TInventoryMB.TInMLotNo = VS4TInventoryLOT.TIMCLotNo) AND (VS4TInventoryMB.TInMSerialNo = VS4TInventoryLOT.TIMCSerialNo) AND (VS4TInventoryMB.TInMCustom1 = VS4TInventoryLOT.TIMCCustom1) AND (VS4TInventoryMB.TInMTPdtCode = VS4TInventoryLOT.TIMCTPdtCode)) ON (VS4TInventSerial.TInRLotDate = VS4TInventoryMB.TInMLotDate) AND (VS4TInventSerial.TInRLotNo = VS4TInventoryMB.TInMLotNo) AND (VS4TInventSerial.TInRSerialNo = VS4TInventoryMB.TInMSerialNo) AND (VS4TInventSerial.TInRCustom1 = VS4TInventoryMB.TInMCustom1) AND (VS4TInventSerial.TInRTPdtCode = VS4TInventoryMB.TInMTPdtCode)) ON VS4TProduct.TPdtCode = VS4TInventSerial.TInRTPdtCode) LEFT JOIN VS4TProduct2 ON VS4TProduct.TPdtCode = VS4TProduct2.TPd2TPdtCode
GO

CREATE VIEW VS4VStockBranch AS  SELECT Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtName2, 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.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, 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.TPdtTPCTAlias, Vs4VInventStock.TPOSPrice, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TIMCUnitCalc, Sum(Vs4VInventStock.TInMQuantityCalc) AS TInMQuantityCalc, VS4TProductSafeS.TPSSOrderPoint, Vs4VInventStock.TPdtTAPNCode, Vs4VInventStock.TLctTBraCode, Vs4VInventStock.TPdtFactoryCode, VS4TProductSafeS.TPSSRefill, VS4TProductSafeS.TPSSSafePerDay, VS4TProductSafeS.TPSSSafeTotalDay, VS4TProductSafeS.TPSSStockMin, VS4TProductSafeS.TPSSSuggest, Vs4VInventStock.TPOSPackAlias2, VS4TProductSafeS.TPSSStockMax FROM (SELECT * FROM Vs4VInventStock WHERE TwahCode<>'PURCHASERETURN' AND TwahCode<>'INPROCESS' AND TwahCode<>'OUTSOURCE' AND TwahCode<>'TEMP' AND TwahCode<>'CUSTOMER' AND TwahCode<>'BORROW' AND TwahCode<>'SALERETURN' AND TwahCode<>'LOAD' AND TwahCode<>'SCRAP') AS Vs4VInventStock LEFT JOIN VS4TProductSafeS ON (Vs4VInventStock.TLctTBraCode = VS4TProductSafeS.TPSSTBraCode) AND (Vs4VInventStock.TInMTPdtCode = VS4TProductSafeS.TPSSTPdtCode) GROUP BY Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtName2, 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.TPdtTPCTAlias, Vs4VInventStock.TPOSPrice, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TIMCUnitCalc, VS4TProductSafeS.TPSSOrderPoint, Vs4VInventStock.TPdtTAPNCode, Vs4VInventStock.TLctTBraCode, Vs4VInventStock.TPdtFactoryCode, VS4TProductSafeS.TPSSRefill, VS4TProductSafeS.TPSSSafePerDay, VS4TProductSafeS.TPSSSafeTotalDay, VS4TProductSafeS.TPSSStockMin, VS4TProductSafeS.TPSSSuggest, Vs4VInventStock.TPOSPackAlias2, VS4TProductSafeS.TPSSStockMax
GO

CREATE VIEW VS4VInventStockF AS  SELECT VS4TInventory.*, VS4TInventoryMB.TInMTInvNo, VS4TInventoryMB.TInMLn, VS4TInventoryMB.TInMTACPTACYID, VS4TInventoryMB.TInMTACPID, VS4TInventoryMB.TInMTPdtCode, VS4TInventoryMB.TInMCustom1, VS4TInventoryMB.TInMSerialNo, VS4TInventoryMB.TInMLotNo, VS4TInventoryMB.TInMLotDate, VS4TInventoryMB.TInMScrapLevel, VS4TInventoryMB.TInMQuantityCalc, VS4TInventoryMB.TInMUnitRatio, VS4TInventoryMB.TInMQuantityBase, VS4TInventoryMB.TInMTUntCode, VS4TInventoryMB.TInMInQuantity, VS4TInventoryMB.TInMOutQuantity, VS4TInventoryMB.TInMAmouQuantity, VS4TInventoryMB.TInMAmouQuantity2, VS4TInventoryMB.TInMAmouQuantity3, VS4TInventoryMB.TInMAmount, VS4TInventoryMB.TInMStatus, VS4TInventoryMB.TInMFromTLctCode, VS4TInventoryMB.TInMTLctCode, VS4TInventoryMB.TInMDescription, VS4TInventoryMB.TInMTInTAlias, VS4TInventoryMB.TInMTSODNo, VS4TInventoryMB.TInMTSOBLn, VS4TInventoryMB.TInMTMDSLn, VS4TInventoryMB.TInMSourceType, VS4TInventoryMB.TInMSourceNo, VS4TInventoryMB.TInMSourceLn, VS4TInventoryMB.TInMQuantityText, VS4TInventoryMB.TInMQuantityCutTxt, VS4TInventoryMB.TInMQuantityCut, VS4TInventoryMB.TInMQuantityFirst, VS4TInventoryMB.TInMArrear, VS4TInventoryMB.TInMShow, VS4TInventoryMB.TInMAgentPrice, VS4TInventoryMB.TInMQAStatus, VS4TInventoryMB.TInMQANote, VS4TInventoryMB.TInMTPltCode, VS4TInventoryMB.TInMFromTPltCode, VS4TInventoryMB.TInMQuantityCost, VS4TInventoryMB.TInMAgentPrice2, VS4TInventoryMB.TInMAgentPrice3, VS4TInventoryMB.TInMTIvsCode, VS4TInventoryMB.TInMFromTIvsCode, VS4TWarehouse.TWahName, VS4TLocation.TLctName, VS4TProject.TPrjName, 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.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.TIMCPKI, VS4TInventoryLOT.TIMCBarcode, VS4TInventoryLOT.TIMCRFID, VS4TInventoryLOT.TIMCQuantityCost, VS4TInventoryLOT.TIMCInputTCurCode, VS4TInventoryLOT.TIMCInputCostRate, VS4TInventoryLOT.TIMCAdjustCost, VS4TInventoryLOT.TIMCStandardCost, VS4TInventoryLOT.TIMCAVGCost, VS4TInventoryLOT.TIMCEmbUnitDMVAR, VS4TInventoryLOT.TIMCEmbUnitDLVAR, VS4TInventoryLOT.TIMCUnitDMVariance, VS4TInventoryLOT.TIMCUnitDLVariance, VS4TInventoryLOT.TIMCEmbUnitOHVAR, VS4TInventoryLOT.TIMCUnitOHVariance, VS4TInventoryLOT.TIMCDutyAmount, VS4TInventoryLOT.TIMCCOA, VS4TInventoryLOT.TIMCProposeStatus, VS4TInventoryLOT.TIMCProposeNote, VS4TInventoryLOT.TIMCUnitRatioC, VS4TInventoryLOT.TIMCquantityCalc, VS4TInventoryLOT.TIMCDiscountText, VS4TInventoryLOT.TIMCDiscountTotal, VS4TInventoryLOT.TIMCTIvsCode, VS4TInventoryLOT.TIMCPrice, VS4TInventoryLOT.TIMCLastDate AS VLSBLastDate, VS4TWarehouse.TWahCode, VS4TPOS.TPOSPackAlias2, VS4TPOS.TPOSPackAlias1 FROM VS4TUnit RIGHT 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 (((VS4TInventoryMB.TInMStatus)=1) AND ((VS4TInventoryLOT.TIMCJobCode)='') AND ((VS4TInventory.TInvApproveStatus)=1) AND ((VS4TInventory.TInvCancelStatus)=0) AND ((VS4TInventory.TInvDate)>=TPdtLastBalDate)) OR (((VS4TInventoryLOT.TIMCJobCode) Is Null))
GO

CREATE VIEW VS4VInventStockLC AS  SELECT VS4TInventory.*, VS4TInventoryMB.TInMTInvNo, VS4TInventoryMB.TInMLn, VS4TInventoryMB.TInMTACPTACYID, VS4TInventoryMB.TInMTACPID, VS4TInventoryMB.TInMTPdtCode, VS4TInventoryMB.TInMCustom1, VS4TInventoryMB.TInMSerialNo, VS4TInventoryMB.TInMLotNo, VS4TInventoryMB.TInMLotDate, VS4TInventoryMB.TInMScrapLevel, VS4TInventoryMB.TInMQuantityCalc, VS4TInventoryMB.TInMUnitRatio, VS4TInventoryMB.TInMQuantityBase, VS4TInventoryMB.TInMTUntCode, VS4TInventoryMB.TInMInQuantity, VS4TInventoryMB.TInMOutQuantity, VS4TInventoryMB.TInMAmouQuantity, VS4TInventoryMB.TInMAmouQuantity2, VS4TInventoryMB.TInMAmouQuantity3, VS4TInventoryMB.TInMAmount, VS4TInventoryMB.TInMStatus, VS4TInventoryMB.TInMFromTLctCode, VS4TInventoryMB.TInMTLctCode, VS4TInventoryMB.TInMDescription, VS4TInventoryMB.TInMTInTAlias, VS4TInventoryMB.TInMTSODNo, VS4TInventoryMB.TInMTSOBLn, VS4TInventoryMB.TInMTMDSLn, VS4TInventoryMB.TInMSourceType, VS4TInventoryMB.TInMSourceNo, VS4TInventoryMB.TInMSourceLn, VS4TInventoryMB.TInMQuantityText, VS4TInventoryMB.TInMQuantityCutTxt, VS4TInventoryMB.TInMQuantityCut, VS4TInventoryMB.TInMQuantityFirst, VS4TInventoryMB.TInMArrear, VS4TInventoryMB.TInMShow, VS4TInventoryMB.TInMAgentPrice, VS4TInventoryMB.TInMQAStatus, VS4TInventoryMB.TInMQANote, VS4TInventoryMB.TInMTPltCode, VS4TInventoryMB.TInMFromTPltCode, VS4TInventoryMB.TInMQuantityCost, VS4TInventoryMB.TInMAgentPrice2, VS4TInventoryMB.TInMAgentPrice3, VS4TInventoryMB.TInMTIvsCode, VS4TInventoryMB.TInMFromTIvsCode, VS4TWarehouse.TWahName, VS4TLocation.TLctName, VS4TProject.TPrjName, 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, VS4TPOS.TPOSPackAlias1 FROM VS4TUnit RIGHT 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 (((VS4TInventoryMB.TInMStatus)=1) AND ((VS4TWarehouse.TWahCode)<>'BORROW' And (VS4TWarehouse.TWahCode)<>'CONSIGN') AND ((VS4TInventory.TInvDate)>=TPdtLastBalDate))
GO

CREATE VIEW VS4VInventStockM AS  SELECT VS4TInventory.*, VS4TInventoryMB.TInMTInvNo, VS4TInventoryMB.TInMLn, VS4TInventoryMB.TInMTACPTACYID, VS4TInventoryMB.TInMTACPID, VS4TInventoryMB.TInMTPdtCode, VS4TInventoryMB.TInMCustom1, VS4TInventoryMB.TInMSerialNo, VS4TInventoryMB.TInMLotNo, VS4TInventoryMB.TInMLotDate, VS4TInventoryMB.TInMScrapLevel, VS4TInventoryMB.TInMQuantityCalc, VS4TInventoryMB.TInMUnitRatio, VS4TInventoryMB.TInMQuantityBase, VS4TInventoryMB.TInMTUntCode, VS4TInventoryMB.TInMInQuantity, VS4TInventoryMB.TInMOutQuantity, VS4TInventoryMB.TInMAmouQuantity, VS4TInventoryMB.TInMAmouQuantity2, VS4TInventoryMB.TInMAmouQuantity3, VS4TInventoryMB.TInMAmount, VS4TInventoryMB.TInMStatus, VS4TInventoryMB.TInMFromTLctCode, VS4TInventoryMB.TInMTLctCode, VS4TInventoryMB.TInMDescription, VS4TInventoryMB.TInMTInTAlias, VS4TInventoryMB.TInMTSODNo, VS4TInventoryMB.TInMTSOBLn, VS4TInventoryMB.TInMTMDSLn, VS4TInventoryMB.TInMSourceType, VS4TInventoryMB.TInMSourceNo, VS4TInventoryMB.TInMSourceLn, VS4TInventoryMB.TInMQuantityText, VS4TInventoryMB.TInMQuantityCutTxt, VS4TInventoryMB.TInMQuantityCut, VS4TInventoryMB.TInMQuantityFirst, VS4TInventoryMB.TInMArrear, VS4TInventoryMB.TInMShow, VS4TInventoryMB.TInMAgentPrice, VS4TInventoryMB.TInMQAStatus, VS4TInventoryMB.TInMQANote, VS4TInventoryMB.TInMTPltCode, VS4TInventoryMB.TInMFromTPltCode, VS4TInventoryMB.TInMQuantityCost, VS4TInventoryMB.TInMAgentPrice2, VS4TInventoryMB.TInMAgentPrice3, VS4TInventoryMB.TInMTIvsCode, VS4TInventoryMB.TInMFromTIvsCode, VS4TWarehouse.TWahName, VS4TLocation.TLctName, VS4TProject.TPrjName, 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.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.TIMCPKI, VS4TInventoryLOT.TIMCBarcode, VS4TInventoryLOT.TIMCRFID, VS4TInventoryLOT.TIMCQuantityCost, VS4TInventoryLOT.TIMCInputTCurCode, VS4TInventoryLOT.TIMCInputCostRate, VS4TInventoryLOT.TIMCAdjustCost, VS4TInventoryLOT.TIMCStandardCost, VS4TInventoryLOT.TIMCAVGCost, VS4TInventoryLOT.TIMCEmbUnitDMVAR, VS4TInventoryLOT.TIMCEmbUnitDLVAR, VS4TInventoryLOT.TIMCUnitDMVariance, VS4TInventoryLOT.TIMCUnitDLVariance, VS4TInventoryLOT.TIMCEmbUnitOHVAR, VS4TInventoryLOT.TIMCUnitOHVariance, VS4TInventoryLOT.TIMCDutyAmount, VS4TInventoryLOT.TIMCCOA, VS4TInventoryLOT.TIMCProposeStatus, VS4TInventoryLOT.TIMCProposeNote, VS4TInventoryLOT.TIMCUnitRatioC, VS4TInventoryLOT.TIMCquantityCalc, VS4TInventoryLOT.TIMCDiscountText, VS4TInventoryLOT.TIMCDiscountTotal, VS4TInventoryLOT.TIMCTIvsCode, VS4TInventoryLOT.TIMCPrice, VS4TInventoryLOT.TIMCVATType, VS4TInventoryLOT.TIMCVATRate, VS4TInventoryLOT.TIMCVATAmount, VS4TInventoryLOT.TIMCLastDate AS VLSBLastDate, VS4TWarehouse.TWahCode, VS4TPOS.TPOSPackAlias2, VS4TPOS.TPOSPackAlias1 FROM VS4TUnit RIGHT 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 (((VS4TInventoryMB.TInMStatus)=1) AND ((VS4TInventory.TInvApproveStatus)=1) AND ((VS4TInventory.TInvCancelStatus)=0))
GO

CREATE VIEW VS4VInventStockP AS  SELECT VS4TInventory.*, VS4TInventoryMB.TInMTInvNo, VS4TInventoryMB.TInMLn, VS4TInventoryMB.TInMTACPTACYID, VS4TInventoryMB.TInMTACPID, VS4TInventoryMB.TInMTPdtCode, VS4TInventoryMB.TInMCustom1, VS4TInventoryMB.TInMSerialNo, VS4TInventoryMB.TInMLotNo, VS4TInventoryMB.TInMLotDate, VS4TInventoryMB.TInMScrapLevel, VS4TInventoryMB.TInMQuantityCalc, VS4TInventoryMB.TInMUnitRatio, VS4TInventoryMB.TInMQuantityBase, VS4TInventoryMB.TInMTUntCode, VS4TInventoryMB.TInMInQuantity, VS4TInventoryMB.TInMOutQuantity, VS4TInventoryMB.TInMAmouQuantity, VS4TInventoryMB.TInMAmouQuantity2, VS4TInventoryMB.TInMAmouQuantity3, VS4TInventoryMB.TInMAmount, VS4TInventoryMB.TInMStatus, VS4TInventoryMB.TInMFromTLctCode, VS4TInventoryMB.TInMTLctCode, VS4TInventoryMB.TInMDescription, VS4TInventoryMB.TInMTInTAlias, VS4TInventoryMB.TInMTSODNo, VS4TInventoryMB.TInMTSOBLn, VS4TInventoryMB.TInMTMDSLn, VS4TInventoryMB.TInMSourceType, VS4TInventoryMB.TInMSourceNo, VS4TInventoryMB.TInMSourceLn, VS4TInventoryMB.TInMQuantityText, VS4TInventoryMB.TInMQuantityCutTxt, VS4TInventoryMB.TInMQuantityCut, VS4TInventoryMB.TInMQuantityFirst, VS4TInventoryMB.TInMArrear, VS4TInventoryMB.TInMShow, VS4TInventoryMB.TInMAgentPrice, VS4TInventoryMB.TInMQAStatus, VS4TInventoryMB.TInMQANote, VS4TInventoryMB.TInMTPltCode, VS4TInventoryMB.TInMFromTPltCode, VS4TInventoryMB.TInMQuantityCost, VS4TInventoryMB.TInMAgentPrice2, VS4TInventoryMB.TInMAgentPrice3, VS4TInventoryMB.TInMTIvsCode, VS4TInventoryMB.TInMFromTIvsCode, VS4TWarehouse.TWahName, VS4TLocation.TLctName, VS4TProject.TPrjName, 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.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.TIMCPKI, VS4TInventoryLOT.TIMCBarcode, VS4TInventoryLOT.TIMCRFID, VS4TInventoryLOT.TIMCQuantityCost, VS4TInventoryLOT.TIMCInputTCurCode, VS4TInventoryLOT.TIMCInputCostRate, VS4TInventoryLOT.TIMCAdjustCost, VS4TInventoryLOT.TIMCStandardCost, VS4TInventoryLOT.TIMCAVGCost, VS4TInventoryLOT.TIMCEmbUnitDMVAR, VS4TInventoryLOT.TIMCEmbUnitDLVAR, VS4TInventoryLOT.TIMCUnitDMVariance, VS4TInventoryLOT.TIMCUnitDLVariance, VS4TInventoryLOT.TIMCEmbUnitOHVAR, VS4TInventoryLOT.TIMCUnitOHVariance, VS4TInventoryLOT.TIMCDutyAmount, VS4TInventoryLOT.TIMCCOA, VS4TInventoryLOT.TIMCProposeStatus, VS4TInventoryLOT.TIMCProposeNote, VS4TInventoryLOT.TIMCUnitRatioC, VS4TInventoryLOT.TIMCquantityCalc, VS4TInventoryLOT.TIMCDiscountText, VS4TInventoryLOT.TIMCDiscountTotal, VS4TInventoryLOT.TIMCTIvsCode, VS4TInventoryLOT.TIMCPrice, VS4TInventoryLOT.TIMCVATType, VS4TInventoryLOT.TIMCVATRate, VS4TInventoryLOT.TIMCVATAmount, VS4TInventoryLOT.TIMCLastDate AS VLSBLastDate, VS4TWarehouse.TWahCode, VS4TPOS.TPOSPackAlias2, VS4TProduct.TPdtDescription, VS4TPOS.TPOSPackAlias1 FROM VS4TUnit RIGHT 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 (((VS4TInventoryMB.TInMStatus)=1) AND ((VS4TInventory.TInvApproveStatus)=1) AND ((VS4TInventory.TInvCancelStatus)=0) AND ((VS4TInventory.TInvDate)>=TPdtLastBalDate))
GO

CREATE VIEW VS4VInventSumTopA AS  SELECT * FROM VS4VInventory WHERE (((VS4VInventory.TInvDate)>='2000-01-01' And (VS4VInventory.TInvDate)<'3333-3-3'))
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.TJobNo, VS4TJob.TJobCode, VS4TJob.TJobTJBkCode, VS4TJob.TJobType, VS4TJob.TJobDate, VS4TJob.TJobRefNo, VS4TJob.TJobRefDate, VS4TJob.TJobRefLn, VS4TJob.TJobRefNo2,                    VS4TJob.TJobRefDate2, VS4TJob.TJOBOriginalNo, VS4TJob.TJobTARNCode, VS4TJob.TJobCustomerName, VS4TJob.TJobTPrjCode, VS4TJob.TJobTSecCode, VS4TJob.TJobTDepCode,                    VS4TJob.TJobTDivCode, VS4TJob.TJobTBraCode, VS4TJob.TJobFinishDate, VS4TJob.TJobFinishTime, VS4TJob.TJobDescription, VS4TJob.TJobSetMode, VS4TJob.TJobTotalRequest,                    VS4TJob.TJobTotalRequest2, VS4TJob.TJobTotalRequest3, VS4TJob.TJobTotalArrear, VS4TJob.TJobTotalArrear2, VS4TJob.TJobTotalArrear3, VS4TJob.TJobTotalFinishPCB, VS4TJob.TJobTotalFinishPCO,                    VS4TJob.TJobTotalFinishPC, VS4TJob.TJobTotalFinishQT, VS4TJob.TJobTotalFinishQT2, VS4TJob.TJobTotalFinishQT3, VS4TJob.TJobTotalLoss, VS4TJob.TJobTotalLoss2, VS4TJob.TJobTotalLoss3,                    VS4TJob.TJobStandardTotal, VS4TJob.TJobActualTotal, VS4TJob.TJobActualLastDate, VS4TJob.TJobEstimateTotal, VS4TJob.TJobCustomText1, VS4TJob.TJobCustomText2, VS4TJob.TJobCustomValue1,                    VS4TJob.TJobCustomValue2, VS4TJob.TJobRequestCode, VS4TJob.TJobRequestBy, VS4TJob.TJobCloseStatus, VS4TJob.TJobCloseBy, VS4TJob.TJobCloseDate, VS4TJob.TJobCloseNote,                    VS4TJob.TJobCreateCode, VS4TJob.TJobCreateBy, VS4TJob.TJobCreateDate, VS4TJob.TJobEditCode, VS4TJob.TJobEditBy, VS4TJob.TJobEditDate, VS4TJob.TJobConfirmStatus,                    VS4TJob.TJobConfirmBy, VS4TJob.TJobConfirmDate, VS4TJob.TJobApproveStatus, VS4TJob.TJobApproveBy, VS4TJob.TJobApproveDate, VS4TJob.TJobApproveNote, VS4TJob.TJobRevision,                    VS4TJob.TJobCancelStatus, VS4TJob.TJobCancelNo, VS4TJob.TJobCancelBy, VS4TJob.TJobCancelDate, VS4TJob.TJobCancelNote, VS4TJob.TJobFlag1, VS4TJob.TJobTInvNo,                    VS4TJob.TJobIncomeTotal, VS4TJob.TJobCostTotal, VS4TJob.TJobProfit, VS4TJobMB.TJbMTJobNo, VS4TJobMB.TJbMLn, VS4TJobMB.TJbMType, VS4TJobMB.TJbMTDwgCode,                    VS4TJobMB.TJbMTPdtCode, VS4TJobMB.TJbMProductName, VS4TJobMB.TJbMCustom1, VS4TJobMB.TJbMCustom2, VS4TJobMB.TJbMCustom3, VS4TJobMB.TJbMCustom4, VS4TJobMB.TJbMCustom5,                    VS4TJobMB.TJbMQuantityCalc, VS4TJobMB.TJbMUnitCalc, VS4TJobMB.TJbMQuantity, VS4TJobMB.TJbMStockOnHand, VS4TJobMB.TJbMUseStock, VS4TJobMB.TJbMUseOrder, VS4TJobMB.TJbMTUntCode,                    VS4TJobMB.TJbMQuantity2, VS4TJobMB.TJbMStockOnHand2, VS4TJobMB.TJbMUseStock2, VS4TJobMB.TJbMUseOrder2, VS4TJobMB.TJbMTUntCode2, VS4TJobMB.TJbMQuantity3,                    VS4TJobMB.TJbMStockOnHand3, VS4TJobMB.TJbMUseStock3, VS4TJobMB.TJbMUseOrder3, VS4TJobMB.TJbMTUntCode3, VS4TJobMB.TJbMDescription, VS4TJobMB.TJbMProcessStatus,                    VS4TJobMB.TJbMTotalRequest, VS4TJobMB.TJbMTotalRequest2, VS4TJobMB.TJbMTotalRequest3, VS4TJobMB.TJbMTotalArrear, VS4TJobMB.TJbMTotalArrear2, VS4TJobMB.TJbMTotalArrear3,                    VS4TJobMB.TJbMFinishPCOrder, VS4TJobMB.TJbMFinishPC, VS4TJobMB.TJbMFinishQT, VS4TJobMB.TJbMFinishQT2, VS4TJobMB.TJbMFinishQT3, VS4TJobMB.TJbMTotalLoss, VS4TJobMB.TJbMTotalLoss2,                    VS4TJobMB.TJbMTotalLoss3, VS4TJobMB.TJbMStandardDM, VS4TJobMB.TJbMStandardDL, VS4TJobMB.TJbMStandardMOH, VS4TJobMB.TJbMStandardTotal, VS4TJobMB.TJbMStandardUnit,                    VS4TJobMB.TJbMActualDM, VS4TJobMB.TJbMActualDL, VS4TJobMB.TJbMActualMOH, VS4TJobMB.TJbMActualTotal, VS4TJobMB.TJbMActualUnit, VS4TJobMB.TJbMActualLastDate,                    VS4TJobMB.TJbMEstimateDM, VS4TJobMB.TJbMEstimateDL, VS4TJobMB.TJbMEstimateMOH, VS4TJobMB.TJbMEstimateTotal, VS4TJobMB.TJbMEstimateUnit, VS4TJobMB.TJbMCustomText1,                    VS4TJobMB.TJbMCustomText2, VS4TJobMB.TJbMCustomText3, VS4TJobMB.TJbMCustomText4, VS4TJobMB.TJbMCustomText5, VS4TJobMB.TJbMCustomText6, VS4TJobMB.TJbMCustomText7,                    VS4TJobMB.TJbMCustomText8, VS4TJobMB.TJbMCustomText9, VS4TJobMB.TJbMCustomText10, VS4TJobMB.TJbMCustomValue1, VS4TJobMB.TJbMCustomValue2, VS4TJobMB.TJbMCustomValue3,                    VS4TJobMB.TJbMCustomValue4, VS4TJobMB.TJbMCustomValue5, VS4TJobMB.TJbMSetMode, VS4TJobMB.TJbMSourceNo, VS4TJobMB.TJbMSourceLn, VS4TJobMB.TJbMSourceDate,                    VS4TJobMB.TJbMFlag1, VS4TJobMB.TJbMTMDMTMDNNo, VS4TJobMB.TJbMTMDMLn, VS4TJobMB.TJbMTWRMCode, VS4TJobMB.TJbMStartDate, VS4TJobMB.TJbMAcceptError,                    VS4TJobMB.TjbMShippingMark, VS4TJobMB.TJbMUnitFactor, VS4TJobMB.TJbMPriority, VS4TJobMB.TJbMControlQty, VS4TJobMB.TJbMQuantityBase, VS4TJobMB.TJbMKindOfPack,                    VS4TJobMB.TJbMPcsPerCarton, VS4TJobMB.TJbMTotalCarton, VS4TJobMB.TJbMTLblCode, 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, 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.TSOBIsPremium, VS4TSOMB.TSOBPremiumCost, VS4TSOMB.TSOBDescription, VS4TSO.TSODDescription,                    VS4TSOMB.TSOBUseDate, VS4TProduct.TPdtCustom1, VS4TProduct.TPdtCustom2, VS4TProduct.TPdtCustom3, VS4TProduct.TPdtCustom4, VS4TProduct.TPdtCustom5, VS4TProduct.TPdtCustom6,                    VS4TProduct.TPdtCustom7, VS4TProduct.TPdtCustom9, VS4TProduct.TPdtCustom10, VS4TProduct3.TPd3Custom11, VS4TProduct3.TPd3Custom12, VS4TProduct3.TPd3Custom13,                    VS4TProduct3.TPd3Custom14, VS4TProduct3.TPd3Custom15, VS4TProduct3.TPd3Custom16, VS4TProduct3.TPd3Custom17, VS4TProduct3.TPd3Custom18, VS4TProduct3.TPd3Custom19,                    VS4TProduct3.TPd3Custom20, VS4TProduct3.TPd3Custom21, VS4TProduct3.TPd3Custom22, VS4TProduct3.TPd3Custom23, VS4TProduct3.TPd3Custom24, VS4TProduct3.TPd3Custom25,                    VS4TProduct3.TPd3Custom26, VS4TProduct3.TPd3Custom27, VS4TProduct3.TPd3Custom28, VS4TProduct3.TPd3Custom29, VS4TProduct3.TPd3Custom30, VS4TSOMB.TSOBFlag1,                    VS4TSOMB.TSOBTARWCode, VS4TSOMB.TSOBTRCACode, VS4TSOMB.TSOBStockFlag, VS4TProductLine.TPdLCode, VS4TProduct.TPdtTUntCode, VS4TSO.TSODCustom1, VS4TSO.TSODCustom2,                    VS4TJob.TJobInvoiceStatus, VS4TJob.TJobIVCloseDate, VS4TSOMB.TSOBFreeCode, VS4TARGroup.TARGCode, VS4TARGroup.TARGName FROM     VS4TProjectType RIGHT OUTER JOIN                   VS4TProject ON VS4TProjectType.TPjTCode = VS4TProject.TPrjTPjTCode RIGHT OUTER JOIN                   VS4TProductLine RIGHT OUTER JOIN                   VS4TProduct LEFT OUTER JOIN                   VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode LEFT OUTER JOIN                   VS4TProduct3 ON VS4TProduct.TPdtCode = VS4TProduct3.TPD3TPdtCode ON VS4TProductLine.TPdLCode = VS4TProduct.TPdtTPDLCode RIGHT OUTER JOIN                   VS4TARGroup RIGHT OUTER JOIN                   VS4TJobBook RIGHT OUTER JOIN                   VS4TJob LEFT OUTER JOIN                   VS4TDepartment ON VS4TJob.TJobTDepCode = VS4TDepartment.TDepCode LEFT OUTER JOIN                   VS4TDivision ON VS4TJob.TJobTDivCode = VS4TDivision.TDivCode LEFT OUTER JOIN                   VS4TBranch ON VS4TJob.TJobTBraCode = VS4TBranch.TBraCode LEFT OUTER JOIN                   VS4TSection ON VS4TJob.TJobTSecCode = VS4TSection.TSecCode LEFT OUTER JOIN                   VS4TAR ON VS4TJob.TJobTARNCode = VS4TAR.TARNCode ON VS4TJobBook.TJBkCode = VS4TJob.TJobTJBkCode INNER JOIN                   VS4TJobMB LEFT OUTER JOIN                   VS4TSOMB ON VS4TJobMB.TJbMSourceLn = VS4TSOMB.TSOBLn AND VS4TJobMB.TJbMSourceNo = VS4TSOMB.TSOBTSODNo LEFT OUTER JOIN                   VS4TEmpWorkRate ON VS4TJobMB.TJbMTWRMCode = VS4TEmpWorkRate.TWRMCode LEFT OUTER JOIN                   VS4TUnit ON VS4TJobMB.TJbMTUntCode = VS4TUnit.TUntCode ON VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo ON VS4TARGroup.TARGCode = VS4TAR.TARNTARGCode ON                    VS4TProduct.TPdtCode = VS4TJobMB.TJbMTPdtCode ON VS4TProject.TPrjCode = VS4TJob.TJobTPrjCode LEFT OUTER JOIN                   VS4TSO ON VS4TSOMB.TSOBTSODNo = VS4TSO.TSODNo
GO

CREATE VIEW VS4VJob2PO AS  SELECT VS4TJob.TJobNo, VS4TJob.TJobCode, TPRDNo, TPRDTPRBCode, TPRDMode, TPRDCode, TPRDType, TPRDDate, TPRDRefNo, TPRDRefDate, TPRDJobCode, TPRDTJobNo, TPRDTJbMLn, TPRDTJPMLn, TPRDTJPDNo, TPRDTPrjCode, TPRDTSecCode, TPRDTDepCode, TPRDTDivCode, TPRDTBraCode, TPRDTAPNCode, TPRDDescription, TPRDProcessStatus, TPRDDeliveryStatus, TPRDRequestCode, TPRDRequestBy, TPRDCreateBy, TPRDCreateDate, TPRDEditCode, TPRDEditBy, TPRDEditDate, TPRDConfirmStatus, TPRDConfirmBy, TPRDConfirmDate, TPRDApproveStatus, TPRDApproveBy, TPRDApproveDate, TPRDApproveNote, TPRDRevision, TPRDReviseStatus, TPRDCancelStatus, TPRDFlag1, TPRDMProcessStatus, TPRDTCurCode, TPRDExchangeRate, TPRDBaseIncoType, TPRDIncoType, TPRDIncoterms, TPRMTPRDNo, TPRMLn, TPRMType, TPRMTJobNo, TPRMJobCode, TPRMMaterialMode, TPRMGroupName, TPRMTPdtCode, TPRMProductCode, TPRMFactoryCode, TPRMProductName, TPRMCustom1, TPRMCustom2, TPRMCustom3, TPRMCustom4, TPRMCustom5, TPRMPrice, TPRMPerQuantity, TPRMDiscountText, TPRMDiscountTotal, TPRMTaxType, TPRMQuantityCalc, TPRMUnitFactor, TPRMUnitCalc, TPRMQuantity, TPRMAmount, TPRMNetAmount, TPRMRefill, TPRMMarkTotal, TPRMStockOnHand, TPRMMinStock, TPRMPOArrearCalc, TPRMSuggest, TPRMPOArrear, TPRMTotalDelivery, TPRMTotalArrear, TPRMTUntCode, TPRMQuantity2, TPRMStockOnHand2, TPRMTotalDelivery2, TPRMTotalArrear2, TPRMTUntCode2, TPRMQuantity3, TPRMStockOnHand3, TPRMTotalDelivery3, TPRMTotalArrear3, TPRMTUntCode3, TPRMUseType, TPRMUseDate, TPRMDescription, TPRMProcessStatus, TPRMStatus, TPRMFlag1, TPRMMapTPdtCode, TPRMMapTUntCode, TPRMMapRatioP, TPRMMaxStock, TPRMOrderPoint, TPRMOrderQuantity, TPRMSafetyStock, TPRMPRArrearCalc, TPRMSourceNo, TPRMSourceLn, TPRMTOExCode, 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.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 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 VS4VJobAllocate AS SELECT VS4TJobAllocate.*, VS4TProduct_1.TPdtName FROM     VS4TJob INNER JOIN                   VS4TJobBook ON VS4TJob.TJobTJBkCode = VS4TJobBook.TJBkCode INNER JOIN                   VS4TJobMB ON VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo INNER JOIN                   VS4TProduct ON VS4TJobMB.TJbMTPdtCode = VS4TProduct.TPdtCode INNER JOIN                   VS4TJobAllocate ON VS4TJobMB.TJbMTJobNo = VS4TJobAllocate.TJALTJbMTJobNo AND VS4TJobMB.TJbMLn = VS4TJobAllocate.TJALTJbMLn LEFT OUTER JOIN                   VS4TProduct AS VS4TProduct_1 ON VS4TJobAllocate.TJALTPdtCode = VS4TProduct_1.TPdtCode
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.*, VS4VCapacitySect.* FROM VS4VJobCapacity LEFT JOIN VS4VCapacitySect ON (VS4VJobCapacity.VJsTYear = VS4VCapacitySect.TCAPYear) AND (VS4VJobCapacity.TMPSWeek = VS4VCapacitySect.TCAPWeek) AND (VS4VJobCapacity.TSepTSecCode = VS4VCapacitySect.TCAPTSecCode)
GO

CREATE VIEW VS4VJobCost AS  SELECT VS4TJob.TJobNo, VS4TJob.TJobCode, VS4TJob.TJobTJBkCode, VS4TJob.TJobType, VS4TJob.TJobDate, VS4TJob.TJobRefNo, VS4TJob.TJobRefDate, VS4TJob.TJobRefLn, VS4TJob.TJobRefNo2, VS4TJob.TJobRefDate2, VS4TJob.TJOBOriginalNo, VS4TJob.TJobTARNCode, VS4TJob.TJobCustomerName, VS4TJob.TJobTPrjCode, VS4TJob.TJobTSecCode, VS4TJob.TJobTDepCode, VS4TJob.TJobTDivCode, VS4TJob.TJobTBraCode, VS4TJob.TJobFinishDate, VS4TJob.TJobFinishTime, VS4TJob.TJobDescription, VS4TJob.TJobSetMode, VS4TJob.TJobTotalRequest, VS4TJob.TJobTotalRequest2, VS4TJob.TJobTotalRequest3, VS4TJob.TJobTotalArrear, VS4TJob.TJobTotalArrear2, VS4TJob.TJobTotalArrear3, VS4TJob.TJobTotalFinishPCB, VS4TJob.TJobTotalFinishPCO, VS4TJob.TJobTotalFinishPC, VS4TJob.TJobTotalFinishQT, VS4TJob.TJobTotalFinishQT2, VS4TJob.TJobTotalFinishQT3, VS4TJob.TJobTotalLoss, VS4TJob.TJobTotalLoss2, VS4TJob.TJobTotalLoss3, VS4TJob.TJobStandardTotal, VS4TJob.TJobActualTotal, VS4TJob.TJobActualLastDate, VS4TJob.TJobEstimateTotal, VS4TJob.TJobCustomText1, VS4TJob.TJobCustomText2, VS4TJob.TJobCustomValue1, VS4TJob.TJobCustomValue2, VS4TJob.TJobRequestCode, VS4TJob.TJobRequestBy, VS4TJob.TJobCloseStatus, VS4TJob.TJobCloseBy, VS4TJob.TJobCloseDate, VS4TJob.TJobCloseNote, VS4TJob.TJobCreateCode, VS4TJob.TJobCreateBy, VS4TJob.TJobCreateDate, VS4TJob.TJobEditCode, VS4TJob.TJobEditBy, VS4TJob.TJobEditDate, VS4TJob.TJobConfirmStatus, VS4TJob.TJobConfirmBy, VS4TJob.TJobConfirmDate, VS4TJob.TJobApproveStatus, VS4TJob.TJobApproveBy, VS4TJob.TJobApproveDate, VS4TJob.TJobApproveNote, VS4TJob.TJobRevision, VS4TJob.TJobCancelStatus, VS4TJob.TJobCancelNo, VS4TJob.TJobCancelBy, VS4TJob.TJobCancelDate, VS4TJob.TJobCancelNote, VS4TJob.TJobFlag1, VS4TJob.TJobTInvNo, VS4TJob.TJobIncomeTotal, VS4TJob.TJobCostTotal, VS4TJob.TJobProfit, 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, VS4TJobBook.TJBkName, VS4TSO.TSODDeliveryDate, VS4TSO2.TSO2Acknowledge, VS4TSO2.TSO2AcknowDate, VS4TSO2.TSO2Status, VS4TSO2.TSO2IncomeTotal, VS4TSO2.TSO2CostTotal, VS4TSO2.TSO2Profit, VS4TSO.TSODRefNo2, VS4TSO.TSODTotal, VS4TSO.TSODExchangeRate, VS4TSO.TSODTotalInRate, VS4TSO.TSODGrandTotal, VS4TSO.TSODTCurCode, VS4TSO.TSODCreateBy, VS4TSO.TSODCreateDate, VS4TSO.TSODEditBy, VS4TSO.TSODEditDate, VS4TJobMB.*, VS4TSO.TSODCustom1, VS4TSO.TSODCustom2, VS4TSO2.TSO2BaseIncome, VS4TSO2.TSO2BaseCost, VS4TJobCost.*, VS4TSO.TSODTaxBase, VS4TSO2.TSO2CompletedDate 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) INNER JOIN (VS4TJobMB INNER JOIN VS4TJobCost ON (VS4TJobMB.TJbMLn = VS4TJobCost.TJCTTJbMLn) AND (VS4TJobMB.TJbMTJobNo = VS4TJobCost.TJCTTJbMTJobNo)) ON (VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo) AND (VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo)) ON VS4TProject.TPrjCode = VS4TJob.TJobTPrjCode) LEFT JOIN VS4TSO2 ON VS4TSO.TSODNo = VS4TSO2.TSO2TSODNo WHERE (((VS4TJobMB.TJbMLn) Is Null Or (VS4TJobMB.TJbMLn)=1))
GO

CREATE VIEW VS4VJobCostAnalyst AS SELECT        VS4TJOBCostAnalyst.TJCATJOBNo, VS4TJOBCostAnalyst.TJCAYear, VS4TJOBCostAnalyst.TJCAQuarter, VS4TJOBCostAnalyst.TJCAActualCostBal, VS4TJOBCostAnalyst.TJCAEstCost,                           VS4TJOBCostAnalyst.TJCAEstCostBal, VS4TJOBCostAnalyst.TJCAEstLoss, VS4TJOBCostAnalyst.TJCAEstFirst, VS4TJOBCostAnalyst.TJCAEstIncomeBal, VS4TJOBCostAnalyst.TJCAActualBal,                           VS4TJOBCostAnalyst.TJCANoteM1, VS4TJOBCostAnalyst.TJCAAuditNoteM1, VS4TJOBCostAnalyst.TJCANoteM2, VS4TJOBCostAnalyst.TJCAAuditNoteM2, VS4TJOBCostAnalyst.TJCANoteM3,                           VS4TJOBCostAnalyst.TJCAAuditNoteM3, VS4TJOBCostAnalyst.TJCANoteM4, VS4TJOBCostAnalyst.TJCAAuditNoteM4, VS4TJOBCostAnalyst.TJCANoteM5, VS4TJOBCostAnalyst.TJCAAuditNoteM5,                           VS4TJOBCostAnalyst.TJCANoteM6, VS4TJOBCostAnalyst.TJCAAuditNoteM6, VS4TJOBCostAnalyst.TJCANoteM7, VS4TJOBCostAnalyst.TJCAAuditNoteM7, VS4TJOBCostAnalyst.TJCANoteM8,                           VS4TJOBCostAnalyst.TJCAAuditNoteM8, VS4TJOBCostAnalyst.TJCANoteM9, VS4TJOBCostAnalyst.TJCAAuditNoteM9, VS4TJOBCostAnalyst.TJCANoteM10, VS4TJOBCostAnalyst.TJCAAuditNoteM10,                           VS4TJOBCostAnalyst.TJCANoteM11, VS4TJOBCostAnalyst.TJCAAuditNoteM11, VS4TJOBCostAnalyst.TJCANoteM12, VS4TJOBCostAnalyst.TJCAAuditNoteM12, VS4TJOBCostAnalyst.TJCACreateDate,                           VS4TJOBCostAnalyst.TJCAEditCode, VS4TJOBCostAnalyst.TJCAEditDate, VS4TJOBCostAnalyst.TJCAFlag1, VS4TJOBCostAnalyst.TJCAFlag2, VS4TJOBCostAnalyst.TJCAFlag3, VS4TJob.TJobTJBkCode,                           VS4TJob.TJobTARNCode, VS4TJob.TJobCustomerName, VS4TJob.TJobTPrjCode, VS4TJob.TJobNo, VS4TSO.TSODNo, VS4TSO.TSODTSBkCode, VS4TSO.TSODTPrjCode,                           VS4TSO.TSODTARNCode, VS4TSO.TSODContactName, VS4TSO.TSODDeliveryDate, VS4TSO.TSODDate, VS4TJob.TJobDate, VS4TJob.TJobDescription, VS4TSO.TSODDescription,                           VS4TSO2.TSO2HandOnDate, VS4TSO2.TSO2Insurance, VS4TSO2.TSO2Status, VS4TSO.TSODSaleName, VS4TSO.TSODTotalInRate, VS4TSO.TSODTaxBase, VS4TSO.TSODCustom1,                           VS4TSO.TSODCustom2, VS4TJob.TJobApproveStatus, VS4TJob.TJobCancelStatus, VS4TJobMB.TJbMLn, VS4TJobMB.TJbMProductName, VS4TJOBCostAnalyst.TJCACreateCode FROM            VS4TJobMB INNER JOIN                          VS4TJOBCostAnalyst INNER JOIN                          VS4TJob ON VS4TJOBCostAnalyst.TJCATJOBNo = VS4TJob.TJobNo ON VS4TJobMB.TJbMTJobNo = VS4TJob.TJobNo LEFT OUTER JOIN                          VS4TSO2 RIGHT OUTER JOIN                          VS4TSO ON VS4TSO2.TSO2TSODNo = VS4TSO.TSODNo ON VS4TJob.TJobRefNo = VS4TSO.TSODNo WHERE        (VS4TJobMB.TJbMLn IS NULL) OR                          (VS4TJobMB.TJbMLn = 1)
GO

CREATE VIEW VS4VJobCostSheet AS SELECT VS4TJob.TJobNo, VS4TJob.TJobCode, VS4TJob.TJobTJBkCode, VS4TJob.TJobType, VS4TJob.TJobDate, VS4TJob.TJobRefNo, VS4TJob.TJobRefDate, VS4TJob.TJobRefLn, VS4TJob.TJobRefNo2,                    VS4TJob.TJobRefDate2, VS4TJob.TJOBOriginalNo, VS4TJob.TJobTARNCode, VS4TJob.TJobCustomerName, VS4TJob.TJobTPrjCode, VS4TJob.TJobTSecCode, VS4TJob.TJobTDepCode,                    VS4TJob.TJobTDivCode, VS4TJob.TJobTBraCode, VS4TJob.TJobFinishDate, VS4TJob.TJobFinishTime, VS4TJob.TJobDescription, VS4TJob.TJobSetMode, VS4TJob.TJobTotalRequest,                    VS4TJob.TJobTotalRequest2, VS4TJob.TJobTotalRequest3, VS4TJob.TJobTotalArrear, VS4TJob.TJobTotalArrear2, VS4TJob.TJobTotalArrear3, VS4TJob.TJobTotalFinishPCB, VS4TJob.TJobTotalFinishPCO,                    VS4TJob.TJobTotalFinishPC, VS4TJob.TJobTotalFinishQT, VS4TJob.TJobTotalFinishQT2, VS4TJob.TJobTotalFinishQT3, VS4TJob.TJobTotalLoss, VS4TJob.TJobTotalLoss2, VS4TJob.TJobTotalLoss3,                    VS4TJob.TJobStandardTotal, VS4TJob.TJobActualTotal, VS4TJob.TJobActualLastDate, VS4TJob.TJobEstimateTotal, VS4TJob.TJobCustomText1, VS4TJob.TJobCustomText2, VS4TJob.TJobCustomValue1,                    VS4TJob.TJobCustomValue2, VS4TJob.TJobRequestCode, VS4TJob.TJobRequestBy, VS4TJob.TJobCloseStatus, VS4TJob.TJobCloseBy, VS4TJob.TJobCloseDate, VS4TJob.TJobCloseNote,                    VS4TJob.TJobCreateCode, VS4TJob.TJobCreateBy, VS4TJob.TJobCreateDate, VS4TJob.TJobEditCode, VS4TJob.TJobEditBy, VS4TJob.TJobEditDate, VS4TJob.TJobConfirmStatus,                    VS4TJob.TJobConfirmBy, VS4TJob.TJobConfirmDate, VS4TJob.TJobApproveStatus, VS4TJob.TJobApproveBy, VS4TJob.TJobApproveDate, VS4TJob.TJobApproveNote, VS4TJob.TJobRevision,                    VS4TJob.TJobCancelStatus, VS4TJob.TJobCancelNo, VS4TJob.TJobCancelBy, VS4TJob.TJobCancelDate, VS4TJob.TJobCancelNote, VS4TJob.TJobFlag1, VS4TJob.TJobFlag2, VS4TJob.TJobFlag3,                    VS4TJob.TJobTInvNo, VS4TJob.TJobIncomeTotal, VS4TJob.TJobCostTotal, VS4TJob.TJobProfit, VS4TJob.TJobBaseIncome, VS4TJob.TJobBaseCost, VS4TJob.TJobInvoiceStatus,                    VS4TJob.TJobIVCloseBy, VS4TJob.TJobIVCloseDate, VS4TJobCostSheet.TJCSTJbMLn, VS4TJobCostSheet.TJCSTJPDNo, VS4TJobCostSheet.TJCSLevel, VS4TJobCostSheet.TJCSCode,                    VS4TJobCostSheet.TJCSDescription, VS4TJobCostSheet.TJCSFactor, VS4TJobCostSheet.TJCSAmount, VS4TJobCostSheet.TJCSRemark, VS4TJobCostSheet.TJCSFlag1, VS4TJobCostSheet.TJCSFlag2,                    VS4TJobCostSheet.TJCSFlag3, VS4TJobCostSheet.TJCSTJbMTJobNo, VS4TJobCostSheet.TJCSTSpdStep, VS4TJobCostSheet.TJCSLn, VS4TJobCostSheet.TJCSPrice, VS4TJobCostSheet.TJCSDiscount,                    VS4TJobCostSheet.TJCSQuantity, VS4TJobCostSheet.TJCSPayChannel, VS4TJobCostSheet.TJCSSignAmount, VS4TOtherIncome.TOInCode, VS4TOtherIncome.TOInName, VS4TOtherIncome.TOInName2,                    VS4TOtherIncome.TOInTACCCode, VS4TOtherExpense.TOExCode, VS4TOtherExpense.TOExName, VS4TOtherExpense.TOExName2, VS4TOtherExpense.TOExTACCCode, VS4TJobMB.TJbMTJobNo,                    VS4TJobMB.TJbMLn, VS4TJobMB.TJbMType, VS4TJobMB.TJbMTDwgCode, VS4TJobMB.TJbMTPdtCode, VS4TJobMB.TJbMProductName, VS4TJobMB.TJbMCustom1, VS4TJobMB.TJbMCustom2,                    VS4TJobMB.TJbMCustom3, VS4TJobMB.TJbMCustom4, VS4TJobMB.TJbMCustom5, VS4TJobMB.TjbMShippingMark, VS4TJobMB.TJbMUnitFactor, VS4TJobMB.TJbMQuantityCalc, VS4TJobMB.TJbMUnitCalc,                    VS4TJobMB.TJbMAcceptError, VS4TJobMB.TJbMQuantity, VS4TJobMB.TJbMStockOnHand, VS4TJobMB.TJbMUseStock, VS4TJobMB.TJbMUseOrder, VS4TJobMB.TJbMTUntCode,                    VS4TJobMB.TJbMQuantity2, VS4TJobMB.TJbMStockOnHand2, VS4TJobMB.TJbMUseStock2, VS4TJobMB.TJbMUseOrder2, VS4TJobMB.TJbMTUntCode2, VS4TJobMB.TJbMQuantity3,                    VS4TJobMB.TJbMStockOnHand3, VS4TJobMB.TJbMUseStock3, VS4TJobMB.TJbMUseOrder3, VS4TJobMB.TJbMTUntCode3, VS4TJobMB.TJbMDescription, VS4TJobMB.TJbMProcessStatus,                    VS4TJobMB.TJbMTotalRequest, VS4TJobMB.TJbMTotalRequest2, VS4TJobMB.TJbMTotalRequest3, VS4TJobMB.TJbMTotalArrear, VS4TJobMB.TJbMTotalArrear2, VS4TJobMB.TJbMTotalArrear3,                    VS4TJobMB.TJbMFinishPCOrder, VS4TJobMB.TJbMFinishPC, VS4TJobMB.TJbMFinishQT, VS4TJobMB.TJbMFinishQT2, VS4TJobMB.TJbMFinishQT3, VS4TJobMB.TJbMTotalLoss, VS4TJobMB.TJbMTotalLoss2,                    VS4TJobMB.TJbMTotalLoss3, VS4TJobMB.TJbMStandardDM, VS4TJobMB.TJbMStandardDL, VS4TJobMB.TJbMStandardMOH, VS4TJobMB.TJbMStandardTotal, VS4TJobMB.TJbMStandardUnit,                    VS4TJobMB.TJbMActualDM, VS4TJobMB.TJbMActualDL, VS4TJobMB.TJbMActualMOH, VS4TJobMB.TJbMActualTotal, VS4TJobMB.TJbMActualUnit, VS4TJobMB.TJbMActualLastDate,                    VS4TJobMB.TJbMEstimateDM, VS4TJobMB.TJbMEstimateDL, VS4TJobMB.TJbMEstimateMOH, VS4TJobMB.TJbMEstimateTotal, VS4TJobMB.TJbMEstimateUnit, VS4TJobMB.TJbMCustomText1,                    VS4TJobMB.TJbMCustomText2, VS4TJobMB.TJbMCustomText3, VS4TJobMB.TJbMCustomText4, VS4TJobMB.TJbMCustomText5, VS4TJobMB.TJbMCustomText6, VS4TJobMB.TJbMCustomText7,                    VS4TJobMB.TJbMCustomText8, VS4TJobMB.TJbMCustomText9, VS4TJobMB.TJbMCustomText10, VS4TJobMB.TJbMCustomValue1, VS4TJobMB.TJbMCustomValue2, VS4TJobMB.TJbMCustomValue3,                    VS4TJobMB.TJbMCustomValue4, VS4TJobMB.TJbMCustomValue5, VS4TJobMB.TJbMUseDate, VS4TJobMB.TJbMSetMode, VS4TJobMB.TJbMSourceNo, VS4TJobMB.TJbMSourceLn,                    VS4TJobMB.TJbMStartDate, VS4TJobMB.TJbMSourceDate, VS4TJobMB.TJbMTMDMTMDNNo, VS4TJobMB.TJbMTMDMLn, VS4TJobMB.TJbMTWRMCode, VS4TJobMB.TJbMFlag1, VS4TJobMB.TJbMFlag2,                    VS4TJobMB.TJbMFlag3, VS4TJobMB.TJbMPriority, VS4TJobMB.TJbMControlQty, VS4TJobMB.TJbMQuantityBase, VS4TJobMB.TJbMKindOfPack, VS4TJobMB.TJbMPcsPerCarton,                    VS4TJobMB.TJbMTotalCarton, VS4TJobMB.TJbMTLblCode, VS4TJobMB.TJbMTotalLossPC, VS4TJobMB.TJbMTotalLossPCJob, VS4TJobMB.TJbMCalcDateType, VS4TJobMB.TJbMDOOrder,                    VS4TOtherIncome.TOInGroupReport1, VS4TOtherIncome.TOInGroupReport2, VS4TOtherExpense.TOExGroupReport1, VS4TOtherExpense.TOExGroupReport2, VS4TJobCostSheet.TJCSDiscountType,                    VS4TProduct.TPdtTPSECode, VS4TProductSection.TPSEName FROM     VS4TProductSection RIGHT OUTER JOIN                   VS4TProduct ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode RIGHT OUTER JOIN                   VS4TJobCostSheet INNER JOIN                   VS4TJob ON VS4TJobCostSheet.TJCSTJbMTJobNo = VS4TJob.TJobNo INNER JOIN                   VS4TJobMB ON VS4TJobCostSheet.TJCSTJbMTJobNo = VS4TJobMB.TJbMTJobNo AND VS4TJobCostSheet.TJCSTJbMLn = VS4TJobMB.TJbMLn ON                    VS4TProduct.TPdtCode = VS4TJobMB.TJbMTPdtCode LEFT OUTER JOIN                   VS4TOtherExpense ON VS4TJobCostSheet.TJCSCode = VS4TOtherExpense.TOExCode LEFT OUTER JOIN                   VS4TOtherIncome ON VS4TJobCostSheet.TJCSCode = VS4TOtherIncome.TOInCode
GO

CREATE VIEW VS4VJobDL AS  SELECT VS4TJob.*, VS4TJobDL.*, VS4TJobMB.*, VS4TJobBook.TJBkName, VS4TMRPStepName.TSepName, VS4TSection.TSecName, TJStTJbMTJobNo, TJStTJbMLn, TJStTSpdStep, TJStLn, TJStLevel, TJStTSepCode, TJStWeek, TJStMan, TJStMachine, TJStCapacity, TJStHourPerDay, TJStCapacityHour, TJStCapPerHour, TJStCapPerDay, TJStEstimateDay, TJStSetupTime, TJStLeadIn, TJStLeadOut, TJStTime, TJStProductBy, TJStStartDate, TJStEndDate, TJStDependent, TJStTJPDNo, TJStTPdtCode, TJStQuantity, TJStFinishQT, TJStFinishPC, TJStArrear, TJStFGPC, TJStProcessStatus, TJStFlag1, TJStAlternative, TJStHolidayType, TJstTMoSCode, TJstTAgtCode, TJstEngine, TJstPriority, TJstRemark, TJstLink1, TJstFormulaCode, TJstFormulaName, TJstTQCSCode, TJstSelfMaterial, TJStManBOM, TJStMachineBOM 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.TJDLTJbMTJobNo = VS4TJobMethod.TJStTJbMTJobNo) AND (VS4TJobDL.TJDLTJbMLn = VS4TJobMethod.TJStTJbMLn) AND (VS4TJobDL.TJDLTSpdStep = VS4TJobMethod.TJStTSpdStep) AND (VS4TJobDL.TJDLLevel = VS4TJobMethod.TJStLevel) AND (VS4TJobDL.TJDLTPdtCode = VS4TJobMethod.TJStTPdtCode)) ON (VS4TJobMB.TJbMTJobNo = VS4TJobDL.TJDLTJbMTJobNo) AND (VS4TJobMB.TJbMLn = VS4TJobDL.TJDLTJbMLn)) ON VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo
GO

CREATE VIEW VS4VJobH AS SELECT VS4TJob.TJobNo, VS4TJob.TJobCode, VS4TJob.TJobTJBkCode, VS4TJob.TJobType, VS4TJob.TJobDate, VS4TJob.TJobRefNo, VS4TJob.TJobRefDate, VS4TJob.TJobRefLn, VS4TJob.TJobRefNo2,                    VS4TJob.TJobRefDate2, VS4TJob.TJOBOriginalNo, VS4TJob.TJobTARNCode, VS4TJob.TJobCustomerName, VS4TJob.TJobTPrjCode, VS4TJob.TJobTSecCode, VS4TJob.TJobTDepCode,                    VS4TJob.TJobTDivCode, VS4TJob.TJobTBraCode, VS4TJob.TJobFinishDate, VS4TJob.TJobFinishTime, VS4TJob.TJobDescription, VS4TJob.TJobSetMode, VS4TJob.TJobTotalRequest,                    VS4TJob.TJobTotalRequest2, VS4TJob.TJobTotalRequest3, VS4TJob.TJobTotalArrear, VS4TJob.TJobTotalArrear2, VS4TJob.TJobTotalArrear3, VS4TJob.TJobTotalFinishPCB, VS4TJob.TJobTotalFinishPCO,                    VS4TJob.TJobTotalFinishPC, VS4TJob.TJobTotalFinishQT, VS4TJob.TJobTotalFinishQT2, VS4TJob.TJobTotalFinishQT3, VS4TJob.TJobTotalLoss, VS4TJob.TJobTotalLoss2, VS4TJob.TJobTotalLoss3,                    VS4TJob.TJobStandardTotal, VS4TJob.TJobActualTotal, VS4TJob.TJobActualLastDate, VS4TJob.TJobEstimateTotal, VS4TJob.TJobCustomText1, VS4TJob.TJobCustomText2, VS4TJob.TJobCustomValue1,                    VS4TJob.TJobCustomValue2, VS4TJob.TJobRequestCode, VS4TJob.TJobRequestBy, VS4TJob.TJobCloseStatus, VS4TJob.TJobCloseBy, VS4TJob.TJobCloseDate, VS4TJob.TJobCloseNote,                    VS4TJob.TJobCreateCode, VS4TJob.TJobCreateBy, VS4TJob.TJobCreateDate, VS4TJob.TJobEditCode, VS4TJob.TJobEditBy, VS4TJob.TJobEditDate, VS4TJob.TJobConfirmStatus,                    VS4TJob.TJobConfirmBy, VS4TJob.TJobConfirmDate, VS4TJob.TJobApproveStatus, VS4TJob.TJobApproveBy, VS4TJob.TJobApproveDate, VS4TJob.TJobApproveNote, VS4TJob.TJobRevision,                    VS4TJob.TJobCancelStatus, VS4TJob.TJobCancelNo, VS4TJob.TJobCancelBy, VS4TJob.TJobCancelDate, VS4TJob.TJobCancelNote, VS4TJob.TJobFlag1, VS4TJob.TJobTInvNo,                    VS4TJob.TJobIncomeTotal, VS4TJob.TJobCostTotal, VS4TJob.TJobProfit, 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, VS4TJobBook.TJBkName, VS4TSO.TSODDeliveryDate, VS4TSO2.TSO2Acknowledge, VS4TSO2.TSO2AcknowDate, VS4TSO2.TSO2Status,                    VS4TSO2.TSO2IncomeTotal, VS4TSO2.TSO2CostTotal, VS4TSO2.TSO2Profit, VS4TSO.TSODRefNo2, VS4TSO.TSODTotal, VS4TSO.TSODExchangeRate, VS4TSO.TSODTotalInRate,                    VS4TSO.TSODGrandTotal, VS4TSO.TSODTCurCode, VS4TSO.TSODCreateBy, VS4TSO.TSODCreateDate, VS4TSO.TSODEditBy, VS4TSO.TSODEditDate, VS4TJobMB.TJbMTJobNo, VS4TJobMB.TJbMLn,                    VS4TJobMB.TJbMType, VS4TJobMB.TJbMTDwgCode, VS4TJobMB.TJbMTPdtCode, VS4TJobMB.TJbMProductName, VS4TJobMB.TJbMCustom1, VS4TJobMB.TJbMCustom2, VS4TJobMB.TJbMCustom3,                    VS4TJobMB.TJbMCustom4, VS4TJobMB.TJbMCustom5, VS4TJobMB.TjbMShippingMark, VS4TJobMB.TJbMUnitFactor, VS4TJobMB.TJbMQuantityCalc, VS4TJobMB.TJbMUnitCalc,                    VS4TJobMB.TJbMAcceptError, VS4TJobMB.TJbMQuantity, VS4TJobMB.TJbMStockOnHand, VS4TJobMB.TJbMUseStock, VS4TJobMB.TJbMUseOrder, VS4TJobMB.TJbMTUntCode,                    VS4TJobMB.TJbMQuantity2, VS4TJobMB.TJbMStockOnHand2, VS4TJobMB.TJbMUseStock2, VS4TJobMB.TJbMUseOrder2, VS4TJobMB.TJbMTUntCode2, VS4TJobMB.TJbMQuantity3,                    VS4TJobMB.TJbMStockOnHand3, VS4TJobMB.TJbMUseStock3, VS4TJobMB.TJbMUseOrder3, VS4TJobMB.TJbMTUntCode3, VS4TJobMB.TJbMDescription, VS4TJobMB.TJbMProcessStatus,                    VS4TJobMB.TJbMTotalRequest, VS4TJobMB.TJbMTotalRequest2, VS4TJobMB.TJbMTotalRequest3, VS4TJobMB.TJbMTotalArrear, VS4TJobMB.TJbMTotalArrear2, VS4TJobMB.TJbMTotalArrear3,                    VS4TJobMB.TJbMFinishPCOrder, VS4TJobMB.TJbMFinishPC, VS4TJobMB.TJbMFinishQT, VS4TJobMB.TJbMFinishQT2, VS4TJobMB.TJbMFinishQT3, VS4TJobMB.TJbMTotalLoss, VS4TJobMB.TJbMTotalLoss2,                    VS4TJobMB.TJbMTotalLoss3, VS4TJobMB.TJbMStandardDM, VS4TJobMB.TJbMStandardDL, VS4TJobMB.TJbMStandardMOH, VS4TJobMB.TJbMStandardTotal, VS4TJobMB.TJbMStandardUnit,                    VS4TJobMB.TJbMActualDM, VS4TJobMB.TJbMActualDL, VS4TJobMB.TJbMActualMOH, VS4TJobMB.TJbMActualTotal, VS4TJobMB.TJbMActualUnit, VS4TJobMB.TJbMActualLastDate,                    VS4TJobMB.TJbMEstimateDM, VS4TJobMB.TJbMEstimateDL, VS4TJobMB.TJbMEstimateMOH, VS4TJobMB.TJbMEstimateTotal, VS4TJobMB.TJbMEstimateUnit, VS4TJobMB.TJbMCustomText1,                    VS4TJobMB.TJbMCustomText2, VS4TJobMB.TJbMCustomText3, VS4TJobMB.TJbMCustomText4, VS4TJobMB.TJbMCustomText5, VS4TJobMB.TJbMCustomText6, VS4TJobMB.TJbMCustomText7,                    VS4TJobMB.TJbMCustomText8, VS4TJobMB.TJbMCustomText9, VS4TJobMB.TJbMCustomText10, VS4TJobMB.TJbMCustomValue1, VS4TJobMB.TJbMCustomValue2, VS4TJobMB.TJbMCustomValue3,                    VS4TJobMB.TJbMCustomValue4, VS4TJobMB.TJbMCustomValue5, VS4TJobMB.TJbMUseDate, VS4TJobMB.TJbMSetMode, VS4TJobMB.TJbMSourceNo, VS4TJobMB.TJbMSourceLn,                    VS4TJobMB.TJbMStartDate, VS4TJobMB.TJbMSourceDate, VS4TJobMB.TJbMTMDMTMDNNo, VS4TJobMB.TJbMTMDMLn, VS4TJobMB.TJbMTWRMCode, VS4TJobMB.TJbMFlag1, VS4TJobMB.TJbMFlag2,                    VS4TJobMB.TJbMFlag3, VS4TJobMB.TJbMPriority, VS4TJobMB.TJbMControlQty, VS4TJobMB.TJbMQuantityBase, VS4TJobMB.TJbMKindOfPack, VS4TJobMB.TJbMPcsPerCarton,                    VS4TJobMB.TJbMTotalCarton, VS4TJobMB.TJbMTLblCode, VS4TJobMB.TJbMTotalLossPC, VS4TJobMB.TJbMTotalLossPCJob, VS4TJobMB.TJbMCalcDateType, VS4TJobMB.TJbMDOOrder,                    VS4TSO.TSODCustom1, VS4TSO.TSODCustom2, VS4TSO2.TSO2BaseIncome, VS4TSO2.TSO2BaseCost, VS4TSO.TSODTaxBase, VS4TSO2.TSO2CompletedDate, VS4TProduct.TPdtTPSECode,                    VS4TProductSection.TPSEName FROM     VS4TProduct LEFT OUTER JOIN                   VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode RIGHT OUTER JOIN                   VS4TJobBook RIGHT OUTER JOIN                   VS4TJob LEFT OUTER JOIN                   VS4TDepartment ON VS4TJob.TJobTDepCode = VS4TDepartment.TDepCode LEFT OUTER JOIN                   VS4TDivision ON VS4TJob.TJobTDivCode = VS4TDivision.TDivCode LEFT OUTER JOIN                   VS4TBranch ON VS4TJob.TJobTBraCode = VS4TBranch.TBraCode LEFT OUTER JOIN                   VS4TSection ON VS4TJob.TJobTSecCode = VS4TSection.TSecCode LEFT OUTER JOIN                   VS4TAR ON VS4TJob.TJobTARNCode = VS4TAR.TARNCode LEFT OUTER JOIN                   VS4TSO ON VS4TJob.TJobRefNo = VS4TSO.TSODNo ON VS4TJobBook.TJBkCode = VS4TJob.TJobTJBkCode INNER JOIN                   VS4TJobMB ON VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo AND VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo ON VS4TProduct.TPdtCode = VS4TJobMB.TJbMTPdtCode LEFT OUTER JOIN                   VS4TProjectType RIGHT OUTER JOIN                   VS4TProject ON VS4TProjectType.TPjTCode = VS4TProject.TPrjTPjTCode ON VS4TJob.TJobTPrjCode = VS4TProject.TPrjCode LEFT OUTER JOIN                   VS4TSO2 ON VS4TSO.TSODNo = VS4TSO2.TSO2TSODNo WHERE  (VS4TJobMB.TJbMLn IS NULL) OR                   (VS4TJobMB.TJbMLn = 1)
GO

CREATE VIEW VS4VJobMaterial AS  SELECT VS4TJob.*, VS4TJobMB.*, TJMtTJbMTJobNo, TJMtTJbMLn, TJMtTSpdStep, TJMtLn, TJMtTJstLn, TJMtLevel, TJMtMatType, TJMtType, TJMtTJPdNo, TJMtTPdtCode, TJMtTSepCode, TJMtProductCode, TJMtProductName, TJMtCustom1, TJMtCustom2, TJMtCustom3, TJMtCustom4, TJMtCustom5, TJMtQuantity, TJMtUseStock, TJMtUseOrder, TJMtTotalUsed, TJMtTotalDif, TJMtUnitCode, TJMtQuantity2, TJMtUseStock2, TJMtUseOrder2, TJMtTotalUsed2, TJMtTotalDif2, TJMtUnitCode2, TJMtQuantity3, TJMtUseStock3, TJMtUseOrder3, TJMtTotalUsed3, TJMtTotalDif3, TJMtUnitCode3, TJMtRemark, TJMtFlag1, TJMtAlternative, TJMtNo, 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, VS4TJobMethod.TJStProcessStatus, VS4TProduct_2.TPdtName AS VJmtOName, VS4TProduct_2.TPdtName2 AS VJmtOName2, VS4TProduct_2.TPdtStandardCost AS VJmtOStandardCost, VS4TProduct_2.TPdtTUntCode AS VJmtOTUntCode, VS4TProduct_2.TPdtTUntCode2 AS VJmtOTUntCode2, VS4TProduct_2.TPdtTUntCode3 AS VJmtOTUntCode3, VS4TProduct2.TPd2ScrapPCMRP AS VJmtOScrapPCMRP, VS4TJobMethod.TJStQuantity, VS4TProduct2.TPd2BOMNote, VS4TProduct_1.TPdtUnit3Ratio, VS4TProduct_1.TPdtTUntCode, VS4TProduct_1.TPdtTUntCode3, VS4TJobMethod.TJStLn 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.TJMtTPdtCode = VS4TJobMethod.TJStTPdtCode) AND (VS4TJobMaterial.TJMtTJbMTJobNo = VS4TJobMethod.TJStTJbMTJobNo) AND (VS4TJobMaterial.TJMtTJbMLn = VS4TJobMethod.TJStTJbMLn) AND (VS4TJobMaterial.TJMtTSpdStep = VS4TJobMethod.TJStTSpdStep) AND (VS4TJobMaterial.TJMtLevel = VS4TJobMethod.TJStLevel)) LEFT JOIN VS4TProduct AS VS4TProduct_2 ON VS4TJobMaterial.TJMtTPdtCode = VS4TProduct_2.TPdtCode) LEFT JOIN VS4TProduct2 ON VS4TProduct_2.TPdtCode = VS4TProduct2.TPd2TPdtCode) LEFT JOIN (VS4TMRPStepName LEFT JOIN VS4TSection ON VS4TMRPStepName.TSepTSecCode = VS4TSection.TSecCode) ON VS4TJobMethod.TJStTSepCode = VS4TMRPStepName.TSepCode) ON (VS4TJobMB.TJbMTJobNo = VS4TJobMaterial.TJMtTJbMTJobNo) AND (VS4TJobMB.TJbMLn = VS4TJobMaterial.TJMtTJbMLn)) 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.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, 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 AS Expr1, 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, Vs4VInventStock.TInMTLctCode 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.TInMTLctCode HAVING (((Vs4VInventStock.TInMTLctCode)<>'PURCHASERETURN' And (Vs4VInventStock.TInMTLctCode)<>'INPROCESS' And (Vs4VInventStock.TInMTLctCode)<>'OUTSOURCE' And (Vs4VInventStock.TInMTLctCode)<>'SCRAP' And (Vs4VInventStock.TInMTLctCode)<>'TEMP' And (Vs4VInventStock.TInMTLctCode)<>'CONSIGN' And (Vs4VInventStock.TInMTLctCode)<>'CUSTOMER' And (Vs4VInventStock.TInMTLctCode)<>'BORROW' And (Vs4VInventStock.TInMTLctCode)<>'SALERETURN' And (Vs4VInventStock.TInMTLctCode)<>'LOAD'))
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.TJbMLn = VS4TJobMBSerial.TJMSTJbMLn) AND (VS4TJobMB.TJbMTJobNo = VS4TJobMBSerial.TJMSTJbMTJobNo)) 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, VS4VJobMBSerial.TJMSCustom4,VS4VJobMBSerial.TJMSCustom5, 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.TJMSCustom4, VS4VJobMBSerial.TJMSCustom5, 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, VS4TJobMBSerial.TJMSCustom4, VS4TJobMBSerial.TJMSCustom5, 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.TJMSCustom4, VS4TJobMBSerial.TJMSCustom5, VS4TJobMBSerial.TJMSTUntCode, VS4TJobMBSerial.TJMSTUntCode2, VS4TJobMBSerial.TJMSTUntCode3, VS4TJobMBSerial.TJMSTransfered HAVING (((VS4TJobMBSerial.TJMSTransfered)=0))
GO

CREATE VIEW VS4VJobMethod AS  SELECT VS4TJob.TJobNo, VS4TJob.TJobCode, VS4TJob.TJobTJBkCode, VS4TJob.TJobType, VS4TJob.TJobDate, VS4TJob.TJobRefNo, VS4TJob.TJobRefDate, VS4TJob.TJobRefLn, VS4TJob.TJobRefNo2, VS4TJob.TJobRefDate2, VS4TJob.TJOBOriginalNo, VS4TJob.TJobTARNCode, VS4TJob.TJobCustomerName, VS4TJob.TJobTPrjCode, VS4TJob.TJobTSecCode, VS4TJob.TJobTDepCode, VS4TJob.TJobTDivCode, VS4TJob.TJobTBraCode, VS4TJob.TJobFinishDate, VS4TJob.TJobFinishTime, VS4TJob.TJobDescription, VS4TJob.TJobSetMode, VS4TJob.TJobTotalRequest, VS4TJob.TJobTotalRequest2, VS4TJob.TJobTotalRequest3, VS4TJob.TJobTotalArrear, VS4TJob.TJobTotalArrear2, VS4TJob.TJobTotalArrear3, VS4TJob.TJobTotalFinishPCB, VS4TJob.TJobTotalFinishPCO, VS4TJob.TJobTotalFinishPC, VS4TJob.TJobTotalFinishQT, VS4TJob.TJobTotalFinishQT2, VS4TJob.TJobTotalFinishQT3, VS4TJob.TJobTotalLoss, VS4TJob.TJobTotalLoss2, VS4TJob.TJobTotalLoss3, VS4TJob.TJobStandardTotal, VS4TJob.TJobActualTotal, VS4TJob.TJobActualLastDate, VS4TJob.TJobEstimateTotal, VS4TJob.TJobCustomText1, VS4TJob.TJobCustomText2, VS4TJob.TJobCustomValue1, VS4TJob.TJobCustomValue2, VS4TJob.TJobRequestCode, VS4TJob.TJobRequestBy, VS4TJob.TJobCloseStatus, VS4TJob.TJobCloseBy, VS4TJob.TJobCloseDate, VS4TJob.TJobCloseNote, VS4TJob.TJobCreateBy, VS4TJob.TJobCreateDate, VS4TJob.TJobEditCode, VS4TJob.TJobEditBy, VS4TJob.TJobEditDate, VS4TJob.TJobConfirmStatus, VS4TJob.TJobConfirmBy, VS4TJob.TJobConfirmDate, VS4TJob.TJobApproveStatus, VS4TJob.TJobApproveBy, VS4TJob.TJobApproveDate, VS4TJob.TJobApproveNote, VS4TJob.TJobRevision, VS4TJob.TJobCancelStatus, VS4TJob.TJobCancelNo, VS4TJob.TJobCancelBy, VS4TJob.TJobCancelDate, VS4TJob.TJobCancelNote, VS4TJob.TJobFlag1, VS4TJob.TJobTInvNo, VS4TJobMB.TJbMTJobNo, VS4TJobMB.TJbMLn, VS4TJobMB.TJbMType, VS4TJobMB.TJbMTDwgCode, VS4TJobMB.TJbMTPdtCode, VS4TJobMB.TJbMProductName, VS4TJobMB.TJbMCustom1, VS4TJobMB.TJbMCustom2, VS4TJobMB.TJbMCustom3, VS4TJobMB.TJbMCustom4, VS4TJobMB.TJbMCustom5, VS4TJobMB.TjbMShippingMark, VS4TJobMB.TJbMUnitFactor, VS4TJobMB.TJbMQuantityCalc, VS4TJobMB.TJbMUnitCalc, VS4TJobMB.TJbMAcceptError, VS4TJobMB.TJbMQuantity, VS4TJobMB.TJbMStockOnHand, VS4TJobMB.TJbMUseStock, VS4TJobMB.TJbMUseOrder, VS4TJobMB.TJbMTUntCode, VS4TJobMB.TJbMQuantity2, VS4TJobMB.TJbMStockOnHand2, VS4TJobMB.TJbMUseStock2, VS4TJobMB.TJbMUseOrder2, VS4TJobMB.TJbMTUntCode2, VS4TJobMB.TJbMQuantity3, VS4TJobMB.TJbMStockOnHand3, VS4TJobMB.TJbMUseStock3, VS4TJobMB.TJbMUseOrder3, VS4TJobMB.TJbMTUntCode3, VS4TJobMB.TJbMDescription, VS4TJobMB.TJbMProcessStatus, VS4TJobMB.TJbMTotalRequest, VS4TJobMB.TJbMTotalRequest2, VS4TJobMB.TJbMTotalRequest3, VS4TJobMB.TJbMTotalArrear, VS4TJobMB.TJbMTotalArrear2, VS4TJobMB.TJbMTotalArrear3, VS4TJobMB.TJbMFinishPCOrder, VS4TJobMB.TJbMFinishPC, VS4TJobMB.TJbMFinishQT, VS4TJobMB.TJbMFinishQT2, VS4TJobMB.TJbMFinishQT3, VS4TJobMB.TJbMTotalLoss, VS4TJobMB.TJbMTotalLoss2, VS4TJobMB.TJbMTotalLoss3, VS4TJobMB.TJbMStandardDM, VS4TJobMB.TJbMStandardDL, VS4TJobMB.TJbMStandardMOH, VS4TJobMB.TJbMStandardTotal, VS4TJobMB.TJbMStandardUnit, VS4TJobMB.TJbMActualDM, VS4TJobMB.TJbMActualDL, VS4TJobMB.TJbMActualMOH, VS4TJobMB.TJbMActualTotal, VS4TJobMB.TJbMActualUnit, VS4TJobMB.TJbMActualLastDate, VS4TJobMB.TJbMEstimateDM, VS4TJobMB.TJbMEstimateDL, VS4TJobMB.TJbMEstimateMOH, VS4TJobMB.TJbMEstimateTotal, VS4TJobMB.TJbMEstimateUnit, VS4TJobMB.TJbMCustomText1, VS4TJobMB.TJbMCustomText2, VS4TJobMB.TJbMCustomText3, VS4TJobMB.TJbMCustomText4, VS4TJobMB.TJbMCustomText5, VS4TJobMB.TJbMCustomText6, VS4TJobMB.TJbMCustomText7, VS4TJobMB.TJbMCustomText8, VS4TJobMB.TJbMCustomText9, VS4TJobMB.TJbMCustomText10, VS4TJobMB.TJbMCustomValue1, VS4TJobMB.TJbMCustomValue2, VS4TJobMB.TJbMCustomValue3, VS4TJobMB.TJbMCustomValue4, VS4TJobMB.TJbMCustomValue5, VS4TJobMB.TJbMUseDate, VS4TJobMB.TJbMSetMode, VS4TJobMB.TJbMSourceNo, VS4TJobMB.TJbMSourceLn, VS4TJobMB.TJbMStartDate, VS4TJobMB.TJbMSourceDate, VS4TJobMB.TJbMTMDMTMDNNo, VS4TJobMB.TJbMTMDMLn, VS4TJobMB.TJbMTWRMCode, VS4TJobMB.TJbMFlag1, VS4TJobMB.TJbMPriority, VS4TJobMB.TJbMControlQty, VS4TJobMB.TJbMQuantityBase, VS4TJobMB.TJbMKindOfPack, VS4TJobMB.TJbMPcsPerCarton, VS4TJobMB.TJbMTotalCarton, VS4TJobMB.TJbMTLblCode, VS4TJobMB.TJbMTotalLossPC, VS4TJobMB.TJbMTotalLossPCJob, VS4TJobMB.TJbMCalcDateType, VS4TJobMB.TJbMDOOrder, VS4TJobMethod.TJStTJbMTJobNo, VS4TJobMethod.TJStTJbMLn, VS4TJobMethod.TJStTSpdStep, VS4TJobMethod.TJStLn, VS4TJobMethod.TJStLevel, VS4TJobMethod.TJStTSepCode, VS4TJobMethod.TJStWeek, VS4TJobMethod.TJStMan, VS4TJobMethod.TJStMachine, VS4TJobMethod.TJStCapacity, VS4TJobMethod.TJStHourPerDay, VS4TJobMethod.TJStCapacityHour, VS4TJobMethod.TJStCapPerHour, VS4TJobMethod.TJStCapPerDay, VS4TJobMethod.TJStEstimateDay, VS4TJobMethod.TJStSetupTime, VS4TJobMethod.TJStLeadIn, VS4TJobMethod.TJStLeadOut, VS4TJobMethod.TJStTime, VS4TJobMethod.TJStProductBy, VS4TJobMethod.TJStStartDate, VS4TJobMethod.TJStEndDate, VS4TJobMethod.TJStDependent, VS4TJobMethod.TJStTJPDNo, VS4TJobMethod.TJStTPdtCode, VS4TJobMethod.TJStQuantity, VS4TJobMethod.TJStFinishQT, VS4TJobMethod.TJStFinishPC, VS4TJobMethod.TJStArrear, VS4TJobMethod.TJStFGPC, VS4TJobMethod.TJStProcessStatus, VS4TJobMethod.TJStFlag1, VS4TJobMethod.TJStAlternative, VS4TJobMethod.TJStHolidayType, VS4TJobMethod.TJstTMoSCode, VS4TJobMethod.TJstTAgtCode, VS4TJobMethod.TJstEngine, VS4TJobMethod.TJstPriority, VS4TJobMethod.TJstRemark, VS4TJobMethod.TJstLink1, VS4TJobMethod.TJstFormulaCode, VS4TJobMethod.TJstFormulaName, VS4TJobMethod.TJstTQCSCode, VS4TJobMethod.TJstSelfMaterial, VS4TJobMethod.TJStManBOM, VS4TJobMethod.TJStMachineBOM, 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, VS4TProductLine.TPdLCode, VS4TProductSection.TPSECode, VS4TProduct.TPdtTUntCode FROM (VS4TProductSection RIGHT JOIN (VS4TProductLine RIGHT JOIN VS4TProduct ON VS4TProductLine.TPdLCode = VS4TProduct.TPdtTPDLCode) ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode) 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.TJStTPdtCode = VS4TProductMethod.TSpdTPdtCode) AND (VS4TJobMethod.TJStTSpdStep = VS4TProductMethod.TSpdStep)) ON (VS4TJobMB.TJbMTJobNo = VS4TJobMethod.TJStTJbMTJobNo) AND (VS4TJobMB.TJbMLn = VS4TJobMethod.TJStTJbMLn)) ON VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo) ON VS4TProduct.TPdtCode = VS4TProductMethod.TSpdTPdtCode
GO

CREATE VIEW VS4VJobMethodMMP AS  SELECT VS4TJob.TJobNo, VS4TJob.TJobCode, VS4TJob.TJobTJBkCode, VS4TJob.TJobType, VS4TJob.TJobDate, VS4TJob.TJobRefNo, VS4TJob.TJobRefDate, VS4TJob.TJobRefLn, VS4TJob.TJobRefNo2, VS4TJob.TJobRefDate2, VS4TJob.TJOBOriginalNo, VS4TJob.TJobTARNCode, VS4TJob.TJobCustomerName, VS4TJob.TJobTPrjCode, VS4TJob.TJobTSecCode, VS4TJob.TJobTDepCode, VS4TJob.TJobTDivCode, VS4TJob.TJobTBraCode, VS4TJob.TJobFinishDate, VS4TJob.TJobFinishTime, VS4TJob.TJobDescription, VS4TJob.TJobSetMode, VS4TJob.TJobTotalRequest, VS4TJob.TJobTotalRequest2, VS4TJob.TJobTotalRequest3, VS4TJob.TJobTotalArrear, VS4TJob.TJobTotalArrear2, VS4TJob.TJobTotalArrear3, VS4TJob.TJobTotalFinishPCB, VS4TJob.TJobTotalFinishPCO, VS4TJob.TJobTotalFinishPC, VS4TJob.TJobTotalFinishQT, VS4TJob.TJobTotalFinishQT2, VS4TJob.TJobTotalFinishQT3, VS4TJob.TJobTotalLoss, VS4TJob.TJobTotalLoss2, VS4TJob.TJobTotalLoss3, VS4TJob.TJobStandardTotal, VS4TJob.TJobActualTotal, VS4TJob.TJobActualLastDate, VS4TJob.TJobEstimateTotal, VS4TJob.TJobCustomText1, VS4TJob.TJobCustomText2, VS4TJob.TJobCustomValue1, VS4TJob.TJobCustomValue2, VS4TJob.TJobRequestCode, VS4TJob.TJobRequestBy, VS4TJob.TJobCloseStatus, VS4TJob.TJobCloseBy, VS4TJob.TJobCloseDate, VS4TJob.TJobCloseNote, VS4TJob.TJobEditCode, VS4TJob.TJobEditBy, VS4TJob.TJobEditDate, VS4TJob.TJobConfirmStatus, VS4TJob.TJobConfirmBy, VS4TJob.TJobConfirmDate, VS4TJob.TJobApproveStatus, VS4TJob.TJobApproveBy, VS4TJob.TJobApproveDate, VS4TJob.TJobApproveNote, VS4TJob.TJobRevision, VS4TJob.TJobCancelStatus, VS4TJob.TJobCancelNo, VS4TJob.TJobCancelBy, VS4TJob.TJobCancelDate, VS4TJob.TJobCancelNote, VS4TJob.TJobFlag1, VS4TJob.TJobTInvNo, TJbMTJobNo, TJbMLn, TJbMType, TJbMTDwgCode, TJbMTPdtCode, TJbMProductName, TJBMCustom1, TJBMCustom2, TJBMCustom3, TJBMCustom4, TJBMCustom5, TJbMQuantityCalc, TJbMUnitCalc, TJbMAcceptError, TJbMQuantity, TJbMStockOnHand, TJbMUseStock, TJbMUseOrder, TJbMTUntCode, TJbMQuantity2, TJbMStockOnHand2, TJbMUseStock2, TJbMUseOrder2, TJbMTUntCode2, TJbMQuantity3, TJbMStockOnHand3, TJbMUseStock3, TJbMUseOrder3, TJbMTUntCode3, TJbMDescription, TJbMProcessStatus, TJbMTotalRequest, TJbMTotalRequest2, TJbMTotalRequest3, TJbMTotalArrear, TJbMTotalArrear2, TJbMTotalArrear3, TJbMFinishPCOrder, TJbMFinishPC, TJbMFinishQT, TJbMFinishQT2, TJbMFinishQT3, TJbMTotalLoss, TJbMTotalLoss2, TJbMTotalLoss3, TJbMStandardDM, TJbMStandardDL, TJbMStandardMOH, TJbMStandardTotal, TJbMStandardUnit, TJbMActualDM, TJbMActualDL, TJbMActualMOH, TJbMActualTotal, TJbMActualUnit, TJbMActualLastDate, TJbMEstimateDM, TJbMEstimateDL, TJbMEstimateMOH, TJbMEstimateTotal, TJbMEstimateUnit, TJbMCustomText1, TJbMCustomText2, TJbMCustomText3, TJbMCustomText4, TJbMCustomText5, TJbMCustomText6, TJbMCustomText7, TJbMCustomText8, TJbMCustomText9, TJbMCustomText10, TJbMCustomValue1, TJbMCustomValue2, TJbMCustomValue3, TJbMCustomValue4, TJbMCustomValue5, TJbMSetMode, TJbMSourceNo, TJbMSourceLn, TJbMSourceDate, TJbMFlag1, TJbMTMDMTMDNNo, TJbMTMDMLn, TJbMTWRMCode, TJbMStartDate, TjbMShippingMark, TJbMUnitFactor, TJbMPriority, TJbMControlQty, TJbMQuantityBase, TJbMKindOfPack, TJbMPcsPerCarton, TJbMTotalCarton, TJbMTLblCode, 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, VS4TProductLine.TPdLCode, VS4TProductSection.TPSECode, VS4TSOMB.TSOBUseDate, VS4TSOMB.TSOBRequestDate, VS4TProduct3.TPd3Custom11, VS4TProduct_1.TPdtCustom10, VS4TProduct_1.TPdtCustom8, VS4TProduct_1.TPdtCustom5, VS4TProduct3.TPd3Custom12 FROM VS4TJob INNER JOIN ((((VS4TJobMB LEFT JOIN VS4TSOMB ON (VS4TJobMB.TJbMSourceLn = VS4TSOMB.TSOBLn) AND (VS4TJobMB.TJbMSourceNo = VS4TSOMB.TSOBTSODNo)) LEFT JOIN VS4TProduct AS VS4TProduct_1 ON VS4TJobMB.TJbMTPdtCode = VS4TProduct_1.TPdtCode) LEFT JOIN VS4TProduct3 ON VS4TProduct_1.TPdtCode = VS4TProduct3.TPD3TPdtCode) LEFT JOIN (VS4TProductSection RIGHT JOIN (VS4TProductLine RIGHT 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)) LEFT JOIN VS4TProduct ON VS4TProductMethod.TSpdTPdtCode = VS4TProduct.TPdtCode) ON VS4TProductLine.TPdLCode = VS4TProduct.TPdtTPDLCode) ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode) ON (VS4TJobMB.TJbMTJobNo = VS4TJobMethod.TJStTJbMTJobNo) AND (VS4TJobMB.TJbMLn = VS4TJobMethod.TJStTJbMLn)) ON VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo
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 VS4VInventoryJOB AS SELECT VS4TInventory.TInvNo, VS4TInventory.TInvTIBkCode, VS4TInventory.TInvDate, VS4TInventory.TInvInvoiceStatus, VS4TInventory.TInvTARNCode, VS4TInventory.TInvTInTAlias, VS4TInventory.TInvRefNo,                    VS4TInventory.TInvRefDate, VS4TInventory.TInvRefNo2, VS4TInventory.TInvRefDate2, VS4TInventory.TInvRefNo3, VS4TInventory.TInvCustom1, VS4TInventory.TInvCustom2, VS4TInventory.TInvCustom3,                    VS4TInventory.TInvCustom4, VS4TInventory.TInvCustom5, VS4TInventory.TInvTPrjCode, VS4TInventory.TInvTJobNo, VS4TInventory.TInvTJbMLn, VS4TInventory.TInvTJPdNo, VS4TInventory.TInvTJPMLn,                    VS4TInventory.TInvTSecCode, VS4TInventory.TInvTDepCode, VS4TInventory.TInvTDivCode, VS4TInventory.TInvTBraCode, VS4TInventory.TInvFromTBraCode, VS4TInventory.TInvTotal,                    VS4TInventory.TInvTotalRecord, VS4TInventory.TInvTotalQuantity, VS4TInventory.TInvRequestCode, VS4TInventory.TInvRequestBy, VS4TInventory.TInvDescription, VS4TInventory.TInvGLMethod,                    VS4TInventory.TInvTGLTNo, VS4TInventory.TInvDeliveryStatus, VS4TInventory.TInvSpecialFlag, VS4TInventory.TInvIsCompleted, VS4TInventory.TInvEditCode, VS4TInventory.TInvApproveStatus,                    VS4TInventory.TInvRevision, VS4TInventory.TInvCancelStatus, VS4TInventory.TInvCustomNo, VS4TInventory.TInvCustomDate, VS4TInventory.TInvTotalScrap, VS4TInventory.TInvTotalQScrap,                    VS4TInventory.TInvTotalQInput, VS4TInventory.TInvTotalAInput, VS4TInventory.TInvTotalRecordIn, VS4TInventory.TInvTotalPCScrap, VS4TInventory.TInvTotalPCQScrap, VS4TInventory.TInvSourceType,                    VS4TInventoryMB.TInMTInvNo, VS4TInventoryMB.TInMLn, VS4TInventoryMB.TInMTPdtCode, VS4TInventoryMB.TInMCustom1, VS4TInventoryMB.TInMSerialNo, VS4TInventoryMB.TInMLotNo,                    VS4TInventoryMB.TInMLotDate, VS4TInventoryMB.TInMScrapLevel, VS4TInventoryMB.TInMQuantityCalc, VS4TInventoryMB.TInMUnitRatio, VS4TInventoryMB.TInMQuantityBase,                    VS4TInventoryMB.TInMTUntCode, VS4TInventoryMB.TInMInQuantity, VS4TInventoryMB.TInMOutQuantity, VS4TInventoryMB.TInMAmouQuantity, VS4TInventoryMB.TInMAmouQuantity2,                    VS4TInventoryMB.TInMAmouQuantity3, VS4TInventoryMB.TInMAmount, VS4TInventoryMB.TInMStatus, VS4TInventoryMB.TInMFromTLctCode, VS4TInventoryMB.TInMTLctCode,                    VS4TInventoryMB.TInMDescription, VS4TInventoryMB.TInMTInTAlias, VS4TInventoryMB.TInMTSODNo, VS4TInventoryMB.TInMTSOBLn, VS4TInventoryMB.TInMTMDSLn, VS4TInventoryMB.TInMSourceType,                    VS4TInventoryMB.TInMSourceNo, VS4TInventoryMB.TInMSourceLn, VS4TInventoryMB.TInMQuantityText, VS4TInventoryMB.TInMArrear, VS4TInventoryMB.TInMShow, VS4TInventoryMB.TInMAgentPrice,                    VS4TInventoryMB.TInMQAStatus, VS4TInventoryMB.TInMQANote, VS4TInventoryMB.TInMTPltCode, VS4TInventoryMB.TInMFromTPltCode, VS4TInventoryMB.TInMQuantityCost, VS4TWarehouse.TWahName,                    VS4TLocation.TLctName, VS4TBranch.TBraName, VS4TProductType.TPTTName, VS4TInventoryType.TInTName, VS4TLocation.TLctTBraCode, VS4TAR.TARNName, VS4TInventoryType.TInTSort,                    VS4TPOS.TPOSPrice, VS4TJob.TJobCode, VS4TJob.TJobCustomerName, VS4TJobMB.TJbMTPdtCode, VS4TJobMB.TJbMProductName, VS4TProduct.TPdtBarcode, VS4TProduct.TPdtName,                    VS4TProduct.TPdtName2, VS4TProduct.TPdtFactoryCode, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TPOS.TPOSPackText2, VS4TPOS.TPOSPackAlias2,                    VS4TProduct.TPdtTPTTCode, VS4TProduct.TPdtTAPNCode, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtTPSECode, VS4TProduct.TPdtTPS2Code, VS4TProduct.TPdtTPG1Code,                    VS4TProduct.TPdtTPG2Code, VS4TProduct.TPdtTBndCode, VS4TProduct.TPdtImage1, VS4TProduct.TPdtTPCTAlias, VS4TProduct.TPdtOrderPoint, VS4TProduct.TPdtStockQuantity,                    VS4TProduct.TPdtLastCost, VS4TProduct.TPdtStdCostCode, VS4TProduct.TPdtAverageCost, VS4TProduct.TPdtSerialType, VS4TPR.TPRDNo, VS4TPR.TPRDTPRBCode, VS4TPR.TPRDDate,                    VS4TPR.TPRDRequestBy, VS4TPR.TPRDDescription, VS4TPR.TPRDTBraCode, VS4TPR.TPRDTDivCode, VS4TLocation_1.TLctTWahCode AS VInMFromTWahCode, VS4TWarehouse.TWahCode AS VInMToTWahCode,                    VS4TWarehouse.TWahCode, VS4TJobMB.TJbMQuantity, VS4TJobMB.TJbMTUntCode, VS4TJobMB.TJbMQuantity2, VS4TJobMB.TJbMQuantity3, VS4TJobMB.TJbMCustom1, VS4TJobMB.TJbMCustom2,                    VS4TJobMB.TJbMCustom3, VS4TJobMB.TJbMCustom4, VS4TJobMB.TJbMCustom5, 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.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.TPdtPremiumCost, VS4VProductGroup.TPdLName, VS4VProductGroup.TPSEName, VS4VProductGroup.TPG1Name,                    VS4TInventoryLOT.TIMCAccountLevel, VS4TProduct.TPdtLastBalDate, VS4TPOS.TPOSPackAlias1, VS4TProduct.TPdtStandardCost, VS4TInventoryLOT.TIMCInputTCurCode,                    VS4TInventoryLOT.TIMCInputCostRate, VS4TInventoryLOT.TIMCAdjustCost, VS4TInventoryLOT.TIMCStandardCost, VS4TInventoryLOT.TIMCAVGCost, VS4TProductType.TPTTStockCost,                    VS4TProduct.TPdtStockType, VS4TProduct.TPdtCode, VS4TInventoryLOT.TIMCCOA, VS4TInventoryLOT.TIMCProposeStatus, VS4TInventoryLOT.TIMCProposeNote, VS4TDivision.TDivName,                    VS4TDepartment.TDepName, VS4TProject.TPrjName, VS4TInventoryLOT.TIMCUnitRatioC, VS4TInventoryLOT.TIMCquantityCalc, VS4TInventoryLOT.TIMCDutyRate, VS4TLocation.TLctType,                    VS4TWarehouse.TWahGroup, VS4TInventoryLOT.TIMCDiscountText, VS4TInventoryLOT.TIMCDiscountTotal, VS4TPRMB.TPRMCustom1, VS4TPRMB.TPRMCustom2, VS4TPRMB.TPRMCustom3,                    VS4TPRMB.TPRMCustom4, VS4TPRMB.TPRMCustom5, VS4TProduct.TPdtDescription, VS4TInventoryLOT.TIMCTIvsCode, VS4TInventoryLOT.TIMCPrice, VS4TInventoryLOT.TIMCVATType,                    VS4TInventoryMB.TInMTIvsCode, VS4TInventoryMB.TInMFromTIvsCode, VS4TAP_1.TAPNName AS VInvTAPNName, VS4TInventory.TInvTJStLn, VS4TJobMB.TJbMControlQty, VS4TInventoryMB.TInMFlag3,                    VS4TProduct.TPdtFlag1, VS4TInventoryLOT.TIMCMachineOutlet, VS4TInventoryLOT.TIMCMachineNo, VS4TInventoryType.TInTDescription, VS4TInventoryLOT.TIMCWastage,                    VS4TInventoryLOT.TIMCLOTCustom1, VS4TInventoryMB.TInMTACPTACYID, VS4TInventoryMB.TInMTACPID, VS4TInventoryLOT.TIMCReserve, VS4TAP.TAPNAddressBill, VS4TAP.TAPNPhone,                    VS4TInventory.TInvApproveDate, VS4TInventory.TInvConfirmStatus, VS4TInventoryLOT.TIMCCostInputType, VS4TInventory.TInvFlag1, VS4TPOMB.TPOBSourceNo, VS4TPOMB.TPOBSourceLn,                    VS4TPR.TPRDTSecCode, VS4TJobProductionM.TJPMTSecCode, VS4TPOMBAOL.TPOATSecCode, VS4TProduct.TPdtAliasSlip, VS4TProductStat.TPMSLastPPrice, VS4TProductStat.TPMSLastPTCurCode,                    VS4TProduct.TPdtUnit2Ratio, VS4TProduct.TPdtUnit3Ratio, VS4TJobMB.TJbMProcessStatus, VS4TInventory.TInvRefNo4, VS4TProduct.TPdtCustom2, VS4TInventoryLOT.TIMCCostDecimal,                    VS4VJobPending.VJbMTotalArrear, VS4VJobPending.VJbMQuantity, VS4TInventory.TInvTWahCode FROM     VS4TInventoryType INNER JOIN                   VS4TProduct LEFT OUTER JOIN                   VS4TProductType ON VS4TProduct.TPdtTPTTCode = VS4TProductType.TPTTCode LEFT OUTER JOIN                   VS4VProductGroup ON VS4TProduct.TPdtCode = VS4VProductGroup.VPdtCode LEFT OUTER JOIN                   VS4VProductSafeH ON VS4TProduct.TPdtCode = VS4VProductSafeH.TPSSTPdtCode LEFT OUTER JOIN                   VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode INNER JOIN                   VS4TInventory LEFT OUTER JOIN                   VS4TDepartment ON VS4TInventory.TInvTDepCode = VS4TDepartment.TDepCode LEFT OUTER JOIN                   VS4TDivision ON VS4TInventory.TInvTDivCode = VS4TDivision.TDivCode LEFT OUTER JOIN                   VS4TBranch ON VS4TInventory.TInvTBraCode = VS4TBranch.TBraCode LEFT OUTER JOIN                   VS4TProject ON VS4TInventory.TInvTPrjCode = VS4TProject.TPrjCode LEFT OUTER JOIN                   VS4TJob ON VS4TInventory.TInvTJobNo = VS4TJob.TJobNo LEFT OUTER JOIN                   VS4TJobMB ON VS4TInventory.TInvTJobNo = VS4TJobMB.TJbMTJobNo AND VS4TInventory.TInvTJbMLn = VS4TJobMB.TJbMLn LEFT OUTER JOIN                   VS4TProduct AS VS4TProduct_1 ON VS4TJobMB.TJbMTPdtCode = VS4TProduct_1.TPdtCode LEFT OUTER JOIN                   VS4TAR ON VS4TInventory.TInvTARNCode = VS4TAR.TARNCode LEFT OUTER JOIN                   VS4TAP AS VS4TAP_1 ON VS4TInventory.TInvTARNCode = VS4TAP_1.TAPNCode LEFT OUTER JOIN                   VS4TJobProductionM ON VS4TInventory.TInvTJPdNo = VS4TJobProductionM.TJPMTJPdNo AND VS4TInventory.TInvTJPMLn = VS4TJobProductionM.TJPMLn INNER JOIN                   VS4TInventoryMB LEFT OUTER JOIN                   VS4TLocation ON VS4TInventoryMB.TInMTLctCode = VS4TLocation.TLctCode LEFT OUTER JOIN                   VS4TWarehouse ON VS4TLocation.TLctTWahCode = VS4TWarehouse.TWahCode LEFT OUTER JOIN                   VS4TLocation AS VS4TLocation_1 ON VS4TInventoryMB.TInMFromTLctCode = VS4TLocation_1.TLctCode LEFT OUTER JOIN                   VS4TSOMB ON VS4TInventoryMB.TInMTSOBLn = VS4TSOMB.TSOBLn AND VS4TInventoryMB.TInMTSODNo = VS4TSOMB.TSOBTSODNo LEFT OUTER JOIN                   VS4TInventoryLOT LEFT OUTER 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 LEFT OUTER JOIN                   VS4TProductLPrice ON VS4TInventoryMB.TInMTLctCode = VS4TProductLPrice.TPLRTLctCode AND VS4TInventoryMB.TInMTPdtCode = VS4TProductLPrice.TPLRTPdtCode LEFT OUTER JOIN                   VS4TPOMB ON VS4TInventoryLOT.TIMCTPODNo = VS4TPOMB.TPOBTPODNo AND VS4TInventoryLOT.TIMCTPOBLn = VS4TPOMB.TPOBLn LEFT OUTER JOIN                   VS4TPRMB ON VS4TPOMB.TPOBSourceNo = VS4TPRMB.TPRMTPRDNo AND VS4TPOMB.TPOBSourceLn = VS4TPRMB.TPRMLn LEFT OUTER JOIN                   VS4TPR ON VS4TPRMB.TPRMTPRDNo = VS4TPR.TPRDNo LEFT OUTER JOIN                   VS4TPOMBAOL ON VS4TPOMB.TPOBTPODNo = VS4TPOMBAOL.TPOATPOBTPODNo AND VS4TPOMB.TPOBLn = VS4TPOMBAOL.TPOATPOBLn LEFT OUTER JOIN                   VS4VJobPending ON VS4TInventoryLOT.TIMCTPdtCode = VS4VJobPending.TJbMTPdtCode AND VS4TInventoryLOT.TIMCJobCode = VS4VJobPending.TJbMTJobNo ON                    VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo ON VS4TProduct.TPdtCode = VS4TInventoryMB.TInMTPdtCode LEFT OUTER JOIN                   VS4TProductStat ON VS4TProduct.TPdtCode = VS4TProductStat.TPMSTPdtCode ON VS4TInventoryType.TInTAlias = VS4TInventory.TInvTInTAlias
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, VS4TJobProd2JobMB.TP2JTJPdNo, VS4TJobProd2JobMB.TP2JTJbMTJobNo, VS4TJobProd2JobMB.TP2JTJbMLn, VS4TAssetAlias.* FROM (VS4TJobProduction LEFT JOIN VS4TJobProd2JobMB ON VS4TJobProduction.TJPdNo = VS4TJobProd2JobMB.TP2JTJPdNo) 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 (VS4TAsset RIGHT JOIN (((VS4TAssetAlias LEFT JOIN VS4TAsset2Alias ON VS4TAssetAlias.TAsACode = VS4TAsset2Alias.TA2ATAsACode) RIGHT JOIN VS4TAssetWGMB ON VS4TAssetAlias.TAsACode = VS4TAssetWGMB.TAegTAsACode) LEFT JOIN VS4TAssetWorkTime ON VS4TAssetAlias.TAsACode = VS4TAssetWorkTime.TEntTAsACode) ON VS4TAsset.TAssCode = VS4TAsset2Alias.TA2ATAssCode) 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.*, VS4VCapacitySect.* FROM VS4VJobProdCap LEFT JOIN VS4VCapacitySect ON (VS4VJobProdCap.VJCPYear = VS4VCapacitySect.TCAPYear) AND (VS4VJobProdCap.TJPMWeek = VS4VCapacitySect.TCAPWeek) AND (VS4VJobProdCap.TSepTSecCode = VS4VCapacitySect.TCAPTSecCode)
GO

CREATE VIEW VS4VJobProduction AS  SELECT VS4TJobProduction.TJPdNo, VS4TJobProduction.TJPdRevision, VS4TJobProduction.TJPdTJPkCode, VS4TJobProduction.TJPdStatusOrder, VS4TJobProduction.TJPdDate, VS4TJobProduction.TJPdRefNo, VS4TJobProduction.TJPdTJbMTJobNo, VS4TJobProduction.TJPdTJbMLn, VS4TJobProduction.TJPdTJobCode, VS4TJobProduction.TJPdTPrjCode, VS4TJobProduction.TJPdTDwgCode, VS4TJobProduction.TJPdProductCode, VS4TJobProduction.TJPdProductName, VS4TJobProduction.TJPdTPSECode, VS4TJobProduction.TJPdTPG1Code, VS4TJobProduction.TJPdCustom1, VS4TJobProduction.TJPdCustom2, VS4TJobProduction.TJPdCustom3, VS4TJobProduction.TJPdCustom4, VS4TJobProduction.TJPdCustom5, VS4TJobProduction.TJPdStartDate, VS4TJobProduction.TJPdEndDate, VS4TJobProduction.TJPdStartPlan, VS4TJobProduction.TJPdEndPlan, VS4TJobProduction.TJPdCustomText1, VS4TJobProduction.TJPdCustomText2, VS4TJobProduction.TJPdCustomText3, VS4TJobProduction.TJPdCustomText4, VS4TJobProduction.TJPdCustomText5, VS4TJobProduction.TJPdCustomText6, VS4TJobProduction.TJPdCustomText7, VS4TJobProduction.TJPdCustomText8, VS4TJobProduction.TJPdCustomText9, VS4TJobProduction.TJPdCustomText10, VS4TJobProduction.TJPdCalsQty, VS4TJobProduction.TJPdCalsQty2, VS4TJobProduction.TJPdCalsQty3, VS4TJobProduction.TJPdUnitCals, VS4TJobProduction.TJPdUnitCals2, VS4TJobProduction.TJPdUnitCals3, VS4TJobProduction.TJPdQtyNeed, VS4TJobProduction.TJPdQtyNeedUnit, VS4TJobProduction.TJPdQtyNeedMode, VS4TJobProduction.TJPdQtyPer, VS4TJobProduction.TJPdQtyNum, VS4TJobProduction.TJPdQtyHead, VS4TJobProduction.TJPdQtyLast, VS4TJobProduction.TJPdQuantity, VS4TJobProduction.TJPdQuantityNet, VS4TJobProduction.TJPdQuantity2, VS4TJobProduction.TJPdQuantityNet2, VS4TJobProduction.TJPdQuantity3, VS4TJobProduction.TJPdQuantityNet3, VS4TJobProduction.TJPdPriority, VS4TJobProduction.TJPdDependent, VS4TJobProduction.TJPdTotalStep, VS4TJobProduction.TJPdFGPC, VS4TJobProduction.TJPdCheckStatus, VS4TJobProduction.TJPdStatusJob, VS4TJobProduction.TJPdDescription, VS4TJobProduction.TJPdMaterialUsed, VS4TJobProduction.TJPdUnitMatUsed, VS4TJobProduction.TJPdMaterialLost, VS4TJobProduction.TJPdEngine, VS4TJobProduction.TJPdTMRFCode, VS4TJobProduction.TJPdFormulaName, VS4TJobProduction.TJPdTMRFCode2, VS4TJobProduction.TJPdFormulaName2, VS4TJobProduction.TJPdEditCode, VS4TJobProduction.TJPdEditBy, VS4TJobProduction.TJPdEditDate, VS4TJobProduction.TJPdConfirmStatus, VS4TJobProduction.TJPdConfirmBy, VS4TJobProduction.TJPdApproveStatus, VS4TJobProduction.TJPdApproveBy, VS4TJobProduction.TJPdApproveDate, VS4TJobProduction.TJPdApproveNote, VS4TJobProduction.TJPdCancelStatus, VS4TJobProduction.TJPdCancelBy, VS4TJobProduction.TJPdCancelDate, VS4TJobProduction.TJPdFlag1, VS4TJobProduction.TJPdTJobRevision, VS4TJobProduction.TJPdTBraCode, VS4TJobProduction.TJPdControlQty, VS4TJobProduction.TJPdKindOfPack, VS4TJobProduction.TJPdPcsPerCarton, VS4TJobProduction.TJPdTotalCarton, VS4TJobProduction.TJPdTLblCode, VS4TJobProduction.TJPdShippingMark, VS4TJobProductionM.TJPMTJPdNo, VS4TJobProductionM.TJPMLn, VS4TJobProductionM.TJPMStep, VS4TJobProductionM.TJPMLevel, VS4TJobProductionM.TJPMRevision, VS4TJobProductionM.TJPMTSepCode, VS4TJobProductionM.TJPMWeek, VS4TJobProductionM.TJPMMan, VS4TJobProductionM.TJPMMachine, VS4TJobProductionM.TJPMCapacity, VS4TJobProductionM.TJPMHourPerDay, VS4TJobProductionM.TJPMCapacityHour, VS4TJobProductionM.TJPMCapPerHour, VS4TJobProductionM.TJPMCapPerDay, VS4TJobProductionM.TJPMEstimateDay, VS4TJobProductionM.TJPMSetupTime, VS4TJobProductionM.TJPMLeadIn, VS4TJobProductionM.TJPMLeadOut, VS4TJobProductionM.TJPMTime, VS4TJobProductionM.TJPMLink1, VS4TJobProductionM.TJPMFormulaCode, VS4TJobProductionM.TJPMFormulaName, VS4TJobProductionM.TJPMProductBy, VS4TJobProductionM.TJPMTSecCode, VS4TJobProductionM.TJPMTAgtCode, VS4TJobProductionM.TJPMEngine, VS4TJobProductionM.TJPMPlanStartDate, VS4TJobProductionM.TJPMPlanEndDate, VS4TJobProductionM.TJPMStartDate, VS4TJobProductionM.TJPMEndDate, VS4TJobProductionM.TJPMDependent, VS4TJobProductionM.TJPMTAPNCode, VS4TJobProductionM.TJPMProcessStatus, VS4TJobProductionM.TJPMRequest, VS4TJobProductionM.TJPMRequest2, VS4TJobProductionM.TJPMRequest3, VS4TJobProductionM.TJPMArrear, VS4TJobProductionM.TJPMArrear2, VS4TJobProductionM.TJPMArrear3, VS4TJobProductionM.TJPMFinishPC, VS4TJobProductionM.TJPMFinishQT, VS4TJobProductionM.TJPMFinishQT2, VS4TJobProductionM.TJPMFinishQT3, VS4TJobProductionM.TJPMAmount, VS4TJobProductionM.TJPMAmount2, VS4TJobProductionM.TJPMAmount3, VS4TJobProductionM.TJPMAmountEngine, VS4TJobProductionM.TJPMAmountEngine2, VS4TJobProductionM.TJPMAmountEngine3, VS4TJobProductionM.TJPMAmountNet, VS4TJobProductionM.TJPMAmountNet2, VS4TJobProductionM.TJPMAmountNet3, VS4TJobProductionM.TJPMTotalTrans, VS4TJobProductionM.TJPMTotalTrans2, VS4TJobProductionM.TJPMTotalTrans3, VS4TJobProductionM.TJPMAmountTrans, VS4TJobProductionM.TJPMAmountTrans2, VS4TJobProductionM.TJPMAmountTrans3, VS4TJobProductionM.TJPMLoss, VS4TJobProductionM.TJPMLoss2, VS4TJobProductionM.TJPMLoss3, VS4TJobProductionM.TJPMAmountLost, VS4TJobProductionM.TJPMTPdtCode, VS4TJobProductionM.TJPMQuantity, VS4TJobProductionM.TJPMDescription, VS4TJobProductionM.TJPMDescription1, VS4TJobProductionM.TJPMStatus, VS4TJobProductionM.TJPMCheckTrans, VS4TJobProductionM.TJPMCheckSemiCode, VS4TJobProductionM.TJPMCheckClose, VS4TJobProductionM.TJPMUsed, VS4TJobProductionM.TJPMAppCode, VS4TJobProductionM.TJPMAppName, VS4TJobProductionM.TJPMAppDate, VS4TJobProductionM.TJPMFGPC, VS4TJobProductionM.TJPMTWRMCode, VS4TJobProductionM.TJPMFlag1, VS4TJobProductionM.TJPMAlternative, VS4TJobProductionM.TJPMHolidayType, VS4TJobProductionM.TJPMTMoSCode, 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_1.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, VS4TJobProd2JobMB.TP2JTJPdNo, VS4TJobProd2JobMB.TP2JTJbMTJobNo, VS4TJobProd2JobMB.TP2JTJbMLn, VS4TProduct.TPdtCustom1, VS4TProduct.TPdtCustom2, VS4TProduct.TPdtCustom3, VS4TProduct.TPdtCustom4, VS4TProduct.TPdtCustom5, VS4TProduct.TPdtCustom6, VS4TProduct.TPdtCustom7, VS4TProduct.TPdtCustom8, VS4TProduct.TPdtCustom9, VS4TProduct.TPdtCustom10, VS4TProduct3.TPd3Custom11, VS4TProduct3.TPd3Custom12, VS4TProduct3.TPd3Custom13, VS4TProduct3.TPd3Custom14, VS4TProduct3.TPd3Custom15, VS4TProduct3.TPd3Custom16, VS4TProduct3.TPd3Custom17, VS4TProduct3.TPd3Custom18, VS4TProduct3.TPd3Custom19, VS4TProduct3.TPd3Custom20, VS4TProduct3.TPd3Custom21, VS4TProduct3.TPd3Custom22, VS4TProduct3.TPd3Custom23, VS4TProduct3.TPd3Custom24, VS4TProduct3.TPd3Custom25, VS4TJobProductionM.TJPMTQCSCode, VS4TDepartment.TDepCode, VS4TDivision.TDivCode, VS4TSOMB.TSOBFactoryCode, VS4TMRPStepName.TSepTLctCode, VS4TJobProduction.TJPdCalcDateType, VS4TJobProductionM.TJPMLossPC, VS4TJob.TJobCloseStatus, VS4TProduct_1.TPdtTPSECode AS VJPMTPSECode, VS4TProductSection_1.TPSEName AS VJPMTPSEName, VS4TProduct.TPdtBarcode, VS4TProduct3.TPd3Custom26, VS4TProduct3.TPd3Custom27, VS4TProduct3.TPd3Custom28, VS4TProduct3.TPd3Custom29, VS4TProduct3.TPd3Custom30 FROM VS4TSO RIGHT JOIN (VS4TProject RIGHT JOIN (VS4TProductSection 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) LEFT JOIN VS4TSOMB ON (VS4TJobMB.TJbMSourceLn = VS4TSOMB.TSOBLn) AND (VS4TJobMB.TJbMSourceNo = VS4TSOMB.TSOBTSODNo)) LEFT JOIN VS4TProduct3 ON VS4TProduct.TPdtCode = VS4TProduct3.TPD3TPdtCode) ON VS4TJobProdBook.TJPkCode = VS4TJobProduction.TJPdTJPkCode) LEFT JOIN VS4TJobProd2JobMB ON VS4TJobProduction.TJPdNo = VS4TJobProd2JobMB.TP2JTJPdNo) LEFT JOIN (VS4TDivision RIGHT JOIN (VS4TDepartment RIGHT 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 VS4TProductSection AS VS4TProductSection_1 ON VS4TProduct_1.TPdtTPSECode = VS4TProductSection_1.TPSECode) ON VS4TDepartment.TDepCode = VS4TSection.TSecTDepCode) ON VS4TDivision.TDivCode = VS4TDepartment.TDepTDivCode) ON VS4TJobProduction.TJPdNo = VS4TJobProductionM.TJPMTJPdNo) ON VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo) ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode) ON VS4TProject.TPrjCode = VS4TJob.TJobTPrjCode) ON VS4TSO.TSODNo = VS4TSOMB.TSOBTSODNo
GO

CREATE VIEW VS4VJobProdDL AS  SELECT VS4TJobProduction.*, VS4TJobProdDL.*, VS4TMRPStepName.*, VS4TSection.*, VS4TJobProductionM.*, VS4TJobProd2JobMB.TP2JTJPdNo, VS4TJobProd2JobMB.TP2JTJbMTJobNo, VS4TJobProd2JobMB.TP2JTJbMLn FROM (VS4TJobProduction LEFT JOIN VS4TJobProd2JobMB ON VS4TJobProduction.TJPdNo = VS4TJobProd2JobMB.TP2JTJPdNo) 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.*, VS4TJobProd2JobMB.TP2JTJPdNo, VS4TJobProd2JobMB.TP2JTJbMTJobNo, VS4TJobProd2JobMB.TP2JTJbMLn 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) LEFT JOIN VS4TJobProd2JobMB ON VS4TJobProduction.TJPdNo = VS4TJobProd2JobMB.TP2JTJPdNo
GO

CREATE VIEW VS4VJobProdMat AS  SELECT VS4TJobProduction.TJPdNo, VS4TJobProduction.TJPdRevision, VS4TJobProduction.TJPdTJPkCode, VS4TJobProduction.TJPdStatusOrder, VS4TJobProduction.TJPdDate, VS4TJobProduction.TJPdRefNo, VS4TJobProduction.TJPdTJbMTJobNo, VS4TJobProduction.TJPdTJbMLn, VS4TJobProduction.TJPdTJobCode, VS4TJobProduction.TJPdTPrjCode, VS4TJobProduction.TJPdTDwgCode, VS4TJobProduction.TJPdProductCode, VS4TJobProduction.TJPdProductName, VS4TJobProduction.TJPdTPSECode, VS4TJobProduction.TJPdTPG1Code, VS4TJobProduction.TJPdCustom1, VS4TJobProduction.TJPdCustom2, VS4TJobProduction.TJPdCustom3, VS4TJobProduction.TJPdCustom4, VS4TJobProduction.TJPdCustom5, VS4TJobProduction.TJPdStartDate, VS4TJobProduction.TJPdEndDate, VS4TJobProduction.TJPdStartPlan, VS4TJobProduction.TJPdEndPlan, VS4TJobProduction.TJPdCustomText1, VS4TJobProduction.TJPdCustomText2, VS4TJobProduction.TJPdCustomText3, VS4TJobProduction.TJPdCustomText4, VS4TJobProduction.TJPdCustomText5, VS4TJobProduction.TJPdCustomText6, VS4TJobProduction.TJPdCustomText7, VS4TJobProduction.TJPdCustomText8, VS4TJobProduction.TJPdCustomText9, VS4TJobProduction.TJPdCustomText10, VS4TJobProduction.TJPdCustomText11, VS4TJobProduction.TJPdCustomText12, VS4TJobProduction.TJPdCustomText13, VS4TJobProduction.TJPdCustomText14, VS4TJobProduction.TJPdCustomText15, VS4TJobProduction.TJPdCalsQty, VS4TJobProduction.TJPdCalsQty2, VS4TJobProduction.TJPdCalsQty3, VS4TJobProduction.TJPdUnitCals, VS4TJobProduction.TJPdUnitCals2, VS4TJobProduction.TJPdUnitCals3, VS4TJobProduction.TJPdQtyNeed, VS4TJobProduction.TJPdQtyNeedUnit, VS4TJobProduction.TJPdQtyNeedMode, VS4TJobProduction.TJPdQtyPer, VS4TJobProduction.TJPdQtyNum, VS4TJobProduction.TJPdQtyHead, VS4TJobProduction.TJPdQtyLast, VS4TJobProduction.TJPdQuantity, VS4TJobProduction.TJPdQuantityNet, VS4TJobProduction.TJPdQuantity2, VS4TJobProduction.TJPdQuantityNet2, VS4TJobProduction.TJPdQuantity3, VS4TJobProduction.TJPdQuantityNet3, VS4TJobProduction.TJPdPriority, VS4TJobProduction.TJPdDependent, VS4TJobProduction.TJPdTotalStep, VS4TJobProduction.TJPdFGPC, VS4TJobProduction.TJPdCheckStatus, VS4TJobProduction.TJPdStatusJob, VS4TJobProduction.TJPdDescription, VS4TJobProduction.TJPdMaterialUsed, VS4TJobProduction.TJPdUnitMatUsed, VS4TJobProduction.TJPdMaterialLost, VS4TJobProduction.TJPdEngine, VS4TJobProduction.TJPdTMRFCode, VS4TJobProduction.TJPdFormulaName, VS4TJobProduction.TJPdTMRFCode2, VS4TJobProduction.TJPdFormulaName2, VS4TJobProduction.TJPdCreateBy, VS4TJobProduction.TJPdCreateDate, VS4TJobProduction.TJPdEditCode, VS4TJobProduction.TJPdEditBy, VS4TJobProduction.TJPdEditDate, VS4TJobProduction.TJPdConfirmStatus, VS4TJobProduction.TJPdConfirmBy, VS4TJobProduction.TJPdConfirmDate, VS4TJobProduction.TJPdApproveStatus, VS4TJobProduction.TJPdApproveBy, VS4TJobProduction.TJPdApproveDate, VS4TJobProduction.TJPdApproveNote, VS4TJobProduction.TJPdCancelStatus, VS4TJobProduction.TJPdCancelNo, VS4TJobProduction.TJPdCancelBy, VS4TJobProduction.TJPdCancelDate, VS4TJobProduction.TJPdCancelNote, VS4TJobProduction.TJPdFlag1, VS4TJobProduction.TJPdFlag2, VS4TJobProduction.TJPdFlag3, VS4TJobProduction.TJPdTJobRevision, VS4TJobProduction.TJPdTBraCode, VS4TJobProduction.TJPdControlQty, VS4TJobProduction.TJPdKindOfPack, VS4TJobProduction.TJPdPcsPerCarton, VS4TJobProduction.TJPdTotalCarton, VS4TJobProduction.TJPdTLblCode, VS4TJobProduction.TJPdShippingMark, VS4TJobProdMat.TMteTJPdNo, VS4TJobProdMat.TMteStep, VS4TJobProdMat.TMteLn, VS4TJobProdMat.TMteTJPMLn, VS4TJobProdMat.TMteLevel, VS4TJobProdMat.TMteMatType, VS4TJobProdMat.TMteType, VS4TJobProdMat.TMteTSepCode, VS4TJobProdMat.TMteTPdtCode, VS4TJobProdMat.TMteProductCode, VS4TJobProdMat.TMteProductName, VS4TJobProdMat.TMteCustom1, VS4TJobProdMat.TMteCustom2, VS4TJobProdMat.TMteCustom3, VS4TJobProdMat.TMteCustom4, VS4TJobProdMat.TMteCustom5, VS4TJobProdMat.TMteQuantity, VS4TJobProdMat.TMteUseStock, VS4TJobProdMat.TMteUseOrder, VS4TJobProdMat.TMteTotalUsed, VS4TJobProdMat.TMteTotalDif, VS4TJobProdMat.TMteUntCode, VS4TJobProdMat.TMteQuantity2, VS4TJobProdMat.TMteUseStock2, VS4TJobProdMat.TMteUseOrder2, VS4TJobProdMat.TMteTotalUsed2, VS4TJobProdMat.TMteTotalDif2, VS4TJobProdMat.TMteUntCode2, VS4TJobProdMat.TMteQuantity3, VS4TJobProdMat.TMteUseStock3, VS4TJobProdMat.TMteUseOrder3, VS4TJobProdMat.TMteTotalUsed3, VS4TJobProdMat.TMteTotalDif3, VS4TJobProdMat.TMteUntCode3, VS4TJobProdMat.TMteDescription, VS4TJobProdMat.TMtePRStatus, VS4TJobProdMat.TMteFlag1, VS4TJobProdMat.TMteFlag2, VS4TJobProdMat.TMteFlag3, VS4TJobProdMat.TMteAlternative, VS4TJobProdMat.TMteNo, 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, VS4TJobProductionM.TJPMProcessStatus, VS4TProduct2.TPd2BOMNote, VS4TJobProd2JobMB.TP2JTJPdNo, VS4TJobProd2JobMB.TP2JTJbMTJobNo, VS4TJobProd2JobMB.TP2JTJbMLn, VS4TProduct.TPdtUnit3Ratio, VS4TSection.TSecCode, VS4TDepartment.TDepCode, VS4TDepartment.TDepName, VS4TMRPStepName.TSepCode, VS4TJobProductionM.TJPMQuantity, VS4TProduct.TPdtName, VS4TProduct_3.TPdtTUntCode3 AS VJMTTUntCode3, VS4TProduct_3.TPdtUnit3Ratio AS VJMtUnit3Ratio, VS4TProductSection.TPSECode, VS4TProductSection.TPSEName, VS4TProduct.TPdtCustom1, VS4TProduct.TPdtCustom2, VS4TProduct.TPdtCustom3, VS4TProduct.TPdtCustom4, VS4TProduct.TPdtCustom5, VS4TProduct.TPdtCustom6, VS4TProduct.TPdtCustom7, VS4TProduct.TPdtCustom8, VS4TProduct.TPdtCustom9, VS4TProduct.TPdtCustom10, VS4TMRPStepName.TSepTSecCode FROM ((VS4TJobProduction LEFT JOIN VS4TProduct AS VS4TProduct_1 ON VS4TJobProduction.TJPdProductCode = VS4TProduct_1.TPdtCode) LEFT JOIN VS4TJobProd2JobMB ON VS4TJobProduction.TJPdNo = VS4TJobProd2JobMB.TP2JTJPdNo) INNER JOIN (VS4TDepartment RIGHT JOIN ((((((VS4TJobProdMat LEFT JOIN VS4TJobProductionM ON (VS4TJobProdMat.TMteTJPdNo = VS4TJobProductionM.TJPMTJPdNo) AND (VS4TJobProdMat.TMteStep = VS4TJobProductionM.TJPMStep) AND (VS4TJobProdMat.TMteTPdtCode = VS4TJobProductionM.TJPMTPdtCode) AND (VS4TJobProdMat.TMteLevel = VS4TJobProductionM.TJPMLevel)) LEFT JOIN VS4TProduct ON VS4TJobProdMat.TMteTPdtCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TProduct2 ON VS4TProduct.TPdtCode = VS4TProduct2.TPd2TPdtCode) LEFT JOIN (VS4TMRPStepName LEFT JOIN VS4TSection ON VS4TMRPStepName.TSepTSecCode = VS4TSection.TSecCode) ON VS4TJobProductionM.TJPMTSepCode = VS4TMRPStepName.TSepCode) LEFT JOIN VS4TProduct AS VS4TProduct_3 ON VS4TJobProdMat.TMteProductCode = VS4TProduct_3.TPdtCode) LEFT JOIN VS4TProductSection ON VS4TProduct_3.TPdtTPSECode = VS4TProductSection.TPSECode) ON VS4TDepartment.TDepCode = VS4TSection.TSecTDepCode) ON VS4TJobProduction.TJPdNo = VS4TJobProdMat.TMteTJPdNo
GO

CREATE VIEW VS4VJobProdQC AS  SELECT VS4TJobProduction.*, VS4TJobProductionM.*, VS4TQCSet.*, VS4TQCSetMB.*, VS4TQC.*, VS4TQCMethod.* FROM (VS4TQCMethod RIGHT JOIN VS4TQC ON VS4TQCMethod.TQMTCode = VS4TQC.TQCCTQMTCode) RIGHT JOIN ((VS4TJobProduction INNER JOIN (VS4TJobProductionM LEFT JOIN VS4TQCSet ON VS4TJobProductionM.TJPMTQCSCode = VS4TQCSet.TQCSCode) ON VS4TJobProduction.TJPdNo = VS4TJobProductionM.TJPMTJPdNo) LEFT JOIN VS4TQCSetMB ON VS4TQCSet.TQCSCode = VS4TQCSetMB.TQCMTQCSCode) ON VS4TQC.TQCCCode = VS4TQCSetMB.TQCMTQCCCode
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, VS4TJobProd2JobMB.TP2JTJPdNo, VS4TJobProd2JobMB.TP2JTJbMTJobNo, VS4TJobProd2JobMB.TP2JTJbMLn 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) LEFT JOIN VS4TJobProd2JobMB ON VS4TJobProduction.TJPdNo = VS4TJobProd2JobMB.TP2JTJPdNo) ON VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo) ON VS4TProject.TPrjCode = VS4TJob.TJobTPrjCode
GO

CREATE VIEW VS4VJobProductionM AS  SELECT VS4TJobProduction.TJPdNo, VS4TJobProduction.TJPdRevision, VS4TJobProduction.TJPdTJPkCode, VS4TJobProduction.TJPdStatusOrder, VS4TJobProduction.TJPdDate, VS4TJobProduction.TJPdRefNo, VS4TJobProduction.TJPdTJbMTJobNo, VS4TJobProduction.TJPdTJbMLn, VS4TJobProduction.TJPdTJobCode, VS4TJobProduction.TJPdTPrjCode, VS4TJobProduction.TJPdTDwgCode, VS4TJobProduction.TJPdProductCode, VS4TJobProduction.TJPdProductName, VS4TJobProduction.TJPdTPSECode, VS4TJobProduction.TJPdTPG1Code, VS4TJobProduction.TJPdCustom1, VS4TJobProduction.TJPdCustom2, VS4TJobProduction.TJPdCustom3, VS4TJobProduction.TJPdCustom4, VS4TJobProduction.TJPdCustom5, VS4TJobProduction.TJPdStartDate, VS4TJobProduction.TJPdEndDate, VS4TJobProduction.TJPdStartPlan, VS4TJobProduction.TJPdEndPlan, VS4TJobProduction.TJPdCustomText1, VS4TJobProduction.TJPdCustomText2, VS4TJobProduction.TJPdCustomText3, VS4TJobProduction.TJPdCustomText4, VS4TJobProduction.TJPdCustomText5, VS4TJobProduction.TJPdCustomText6, VS4TJobProduction.TJPdCustomText7, VS4TJobProduction.TJPdCustomText8, VS4TJobProduction.TJPdCustomText9, VS4TJobProduction.TJPdCustomText10, VS4TJobProduction.TJPdCustomText11, VS4TJobProduction.TJPdCustomText12, VS4TJobProduction.TJPdCustomText13, VS4TJobProduction.TJPdCustomText14, VS4TJobProduction.TJPdCustomText15, VS4TJobProduction.TJPdCalsQty, VS4TJobProduction.TJPdCalsQty2, VS4TJobProduction.TJPdCalsQty3, VS4TJobProduction.TJPdUnitCals, VS4TJobProduction.TJPdUnitCals2, VS4TJobProduction.TJPdUnitCals3, VS4TJobProduction.TJPdQtyNeed, VS4TJobProduction.TJPdQtyNeedUnit, VS4TJobProduction.TJPdQtyNeedMode, VS4TJobProduction.TJPdQtyPer, VS4TJobProduction.TJPdQtyNum, VS4TJobProduction.TJPdQtyHead, VS4TJobProduction.TJPdQtyLast, VS4TJobProduction.TJPdQuantity, VS4TJobProduction.TJPdQuantityNet, VS4TJobProduction.TJPdQuantity2, VS4TJobProduction.TJPdQuantityNet2, VS4TJobProduction.TJPdQuantity3, VS4TJobProduction.TJPdQuantityNet3, VS4TJobProduction.TJPdPriority, VS4TJobProduction.TJPdDependent, VS4TJobProduction.TJPdTotalStep, VS4TJobProduction.TJPdFGPC, VS4TJobProduction.TJPdCheckStatus, VS4TJobProduction.TJPdStatusJob, VS4TJobProduction.TJPdDescription, VS4TJobProduction.TJPdMaterialUsed, VS4TJobProduction.TJPdUnitMatUsed, VS4TJobProduction.TJPdMaterialLost, VS4TJobProduction.TJPdEngine, VS4TJobProduction.TJPdTMRFCode, VS4TJobProduction.TJPdFormulaName, VS4TJobProduction.TJPdTMRFCode2, VS4TJobProduction.TJPdFormulaName2, VS4TJobProduction.TJPdEditCode, VS4TJobProduction.TJPdEditBy, VS4TJobProduction.TJPdEditDate, VS4TJobProduction.TJPdConfirmStatus, VS4TJobProduction.TJPdConfirmBy, VS4TJobProduction.TJPdConfirmDate, VS4TJobProduction.TJPdApproveStatus, VS4TJobProduction.TJPdApproveBy, VS4TJobProduction.TJPdApproveDate, VS4TJobProduction.TJPdApproveNote, VS4TJobProduction.TJPdCancelStatus, VS4TJobProduction.TJPdCancelNo, VS4TJobProduction.TJPdCancelBy, VS4TJobProduction.TJPdCancelDate, VS4TJobProduction.TJPdCancelNote, VS4TJobProduction.TJPdFlag1, VS4TJobProduction.TJPdTJobRevision, VS4TJobProduction.TJPdTBraCode, VS4TJobProduction.TJPdControlQty, VS4TJobProduction.TJPdKindOfPack, VS4TJobProduction.TJPdPcsPerCarton, VS4TJobProduction.TJPdTotalCarton, VS4TJobProduction.TJPdTLblCode, VS4TJobProduction.TJPdShippingMark, 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.TJbMCustom4, VS4TJobMB.TJbMCustom5, 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, VS4TJobProd2JobMB.TP2JTJPdNo, VS4TJobProd2JobMB.TP2JTJbMTJobNo, VS4TJobProd2JobMB.TP2JTJbMLn, VS4TJob.TJobInvoiceStatus, TJobIVCloseDate 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 VS4TJobProd2JobMB ON VS4TJobProduction.TJPdNo = VS4TJobProd2JobMB.TP2JTJPdNo) 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.TJPdCustom4, VS4TJobProduction.TJPdCustom5, VS4TJobProduction.TJPdTMRFCode, VS4TJobProduction.TJPdFormulaName, VS4TJobProduction.TJPdTMRFCode2, VS4TJobProduction.TJPdFormulaName2, VS4TJobMB.TJbMUseOrder, VS4TJobMB.TJbMUseOrder2, VS4TJobMB.TJbMUseOrder3, VS4TJobMB.TJbMTUntCode, VS4TJobMB.TJbMTUntCode2, VS4TJobMB.TJbMTUntCode3, VS4TJobProdBook.TJPkName, VS4TJobProd2JobMB.TP2JTJPdNo, VS4TJobProd2JobMB.TP2JTJbMTJobNo, VS4TJobProd2JobMB.TP2JTJbMLn 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) LEFT JOIN VS4TJobProd2JobMB ON VS4TJobProduction.TJPdNo = VS4TJobProd2JobMB.TP2JTJPdNo) 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 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, VS4TJobVariance.*, VS4TSection.TSecName, VS4TJobProd2JobMB.TP2JTJPdNo, VS4TJobProd2JobMB.TP2JTJbMTJobNo, VS4TJobProd2JobMB.TP2JTJbMLn 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) INNER JOIN VS4TJobVariance ON VS4TJobProduction.TJPdNo = VS4TJobVariance.TJVATJPDNo) LEFT JOIN VS4TSection ON VS4TJobVariance.TJVATSecCode = VS4TSection.TSecCode) ON VS4TJobProdBook.TJPkCode = VS4TJobProduction.TJPdTJPkCode) LEFT JOIN VS4TJobProd2JobMB ON VS4TJobProduction.TJPdNo = VS4TJobProd2JobMB.TP2JTJPdNo) ON VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo) ON VS4TProject.TPrjCode = VS4TJob.TJobTPrjCode
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 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, 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, VS4TAP.TAPNName FROM VS4TUnit RIGHT 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) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) 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) LEFT JOIN VS4TAP ON VS4TInventory.TInvTARNCode = VS4TAP.TAPNCode) 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 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, 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 RIGHT 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) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) 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 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 VS4VLotInCost AS  SELECT VS4TInventory.TInvNo, 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, 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, VS4TAP.TAPNName, VS4TInventoryLOT.* FROM VS4TUnit RIGHT 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) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) 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) LEFT JOIN VS4TAP ON VS4TInventory.TInvTARNCode = VS4TAP.TAPNCode) 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 WHERE (((VS4TInventoryMB.TInMStatus)=1) AND ((VS4TInventory.TInvTInTAlias)='LOTIN')) OR (((VS4TInventory.TInvTInTAlias)='LOTINPR')) OR (((VS4TInventory.TInvTInTAlias)='LOTINPREMIUM')) OR (((VS4TInventory.TInvTInTAlias)='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.*, VS4TPOMBAOL.TPOATBraCode, VS4TPOMBAOL.TPOATPrjCode, VS4TPOMBAOL.TPOATDivCode, VS4TPOMBAOL.TPOATDepCode, VS4TPOMBAOL.TPOATSecCode, VS4TPOMBAOL.TPOATSZGCode, VS4TPOMBAOL.TPOATSZnCode, VS4TPOMBAOL.TPOATSAeCode, VS4TPOMBAOL.TPOATARNCode, VS4TPOMBAOL.TPOATAPNCode, VS4TPOMBAOL.TPOATAssCode, VS4TPOMBAOL.TPOATEmpCode, VS4TPOMBAOL.TPOATPdtCode FROM VS4TPO RIGHT JOIN ((VS4VInventPDE LEFT JOIN VS4TPOMB ON (VS4VInventPDE.TIMCTPOBLn = VS4TPOMB.TPOBLn) AND (VS4VInventPDE.TIMCTPODNo = VS4TPOMB.TPOBTPODNo)) LEFT JOIN VS4TPOMBAOL ON (VS4TPOMB.TPOBTPODNo = VS4TPOMBAOL.TPOATPOBTPODNo) AND (VS4TPOMB.TPOBLn = VS4TPOMBAOL.TPOATPOBLn)) ON VS4TPO.TPODNo = VS4TPOMB.TPOBTPODNo WHERE (((VS4VInventPDE.TInMAmouQuantity)>0) AND ((VS4VInventPDE.TInvInvoiceStatus)<>1))
GO

CREATE VIEW VS4VLotInPOM AS  SELECT VS4TInventoryMB.*, VS4TPOMB.*, VS4TInventory.TInvRefNo, VS4TInventory.TInvRefNo2, VS4TProduct.TPdtName, VS4TProduct.TPdtTUntCode, VS4TInventoryLOT.TIMCUnitRatio, VS4TInventoryLOT.TIMCTUntCode, VS4TInventory.TInvTARNCode, VS4TInventoryLOT.TIMCUnitCost, VS4TInventoryLOT.TIMCInputCost, VS4TInventoryLOT.TIMCPerQuantity, VS4TInventory.TInvCustomNo, VS4TInventory.TInvCustomDate, VS4TPO.TPODPriceChannel, VS4TPOMBAOL.*, VS4TInventoryLOT.TIMCIsPremium, VS4TInventoryLOT.TIMCVATRate, VS4TInventoryLOT.TIMCVATType, VS4TPO.TPODVATRate, VS4TInventoryLOT.TIMCPrice, VS4TInventoryLOT.TIMCDiscountText, VS4TInventoryLOT.TIMCCustom2, VS4TInventoryLOT.TIMCCustom3, VS4TInventoryLOT.TIMCCustom4, VS4TInventoryLOT.TIMCCustom5, VS4TInventoryLOT.TIMCInputTCurCode, VS4TInventoryLOT.TIMCInputCostRate FROM VS4TUnit RIGHT 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)) LEFT JOIN VS4TPOMBAOL ON (VS4TPOMB.TPOBTPODNo = VS4TPOMBAOL.TPOATPOBTPODNo) AND (VS4TPOMB.TPOBLn = VS4TPOMBAOL.TPOATPOBLn)) 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') AND ((VS4TInventoryMB.TInMAmouQuantity)>0) AND ((VS4TInventory.TInvInvoiceStatus)<>1))
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.TIMCLotDate = VS4TInventoryMB.TInMLotDate) AND (VS4TInventoryLOT.TIMCLotNo = VS4TInventoryMB.TInMLotNo) AND (VS4TInventoryLOT.TIMCSerialNo = VS4TInventoryMB.TInMSerialNo) AND (VS4TInventoryLOT.TIMCCustom1 = VS4TInventoryMB.TInMCustom1) AND (VS4TInventoryLOT.TIMCTPdtCode = VS4TInventoryMB.TInMTPdtCode) 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 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 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 VS4VLSCPayPeriod AS SELECT VS4TSOPayPeriod.TSPPTSODNo, VS4TSOPayPeriod.TSPPLn, VS4TSOPayPeriod.TSPPPeriod, VS4TSOPayPeriod.TSPPDueDate, VS4TSOPayPeriod.TSPPCondition, VS4TSOPayPeriod.TSPPTPPTCode,                    VS4TSOPayPeriod.TSPPTPyTAlias, VS4TSOPayPeriod.TSPPTCurCode, VS4TSOPayPeriod.TSPPPercent, VS4TSOPayPeriod.TSPPExchangeRate, VS4TSOPayPeriod.TSPPAmountInRate,                    VS4TSOPayPeriod.TSPPNote, VS4TSOPayPeriod.TSPPFlag1, VS4TSOPayPeriod.TSPPFlag2, VS4TSOPayPeriod.TSPPFlag3, VS4TSOPayPeriod.TSPPTSOBLn, VS4TSOPayPeriod.TSPPAmount,                    VS4TSOPayPeriod.TSPPInterestRate, VS4TSOPayPeriod.TSPPInterest, VS4TSOPayPeriod.TSPPTaxBase, VS4TSOPayPeriod.TSPPVATTotal, VS4TSOPayPeriod.TSPPGrandTotal, VS4TSOPayPeriod.TSPPPaid,                    VS4TSOPayPeriod.TSPPBalance, VS4TSOPayPeriod.TSPPInvoiceDate, VS4TSOPayPeriod.TSPPReceiptDate, VS4TSOPayPeriod.TSPPReceiptNo, VS4TSOPayPeriod.TSPPRVNo, VS4TSOPayPeriod.TSPPInvoiceNo, VS4TSOMB2.TSB2TSODNo,                    VS4TSOMB2.TSB2Ln, VS4TSOMB2.TSB2DownText, VS4TSOMB2.TSB2DownAmount, VS4TSOMB2.TSB2Periods, VS4TSOMB2.TSB2PeriodAmount, VS4TSOMB2.TSB2PeriodType,                    VS4TSOMB2.TSB2InterestRate, VS4TSOMB2.TSB2InterestType, VS4TSOMB2.TSB2InterestMode, VS4TSOMB2.TSB2FirstPeriod, VS4TSOMB2.TSB2LastPeriod, VS4TSOMB2.TSB2FirstInvoiceD,                    VS4TSOMB2.TSB2FirstReceiptD, VS4TSOMB2.TSB2Flag1, VS4TSOMB2.TSB2Flag2, VS4TSOMB2.TSB2Flag3, VS4TSOMB2.TSB2BaseAmount, VS4TSOMB2.TSB2NetAmount, VS4TSOMB2.TSB2Paid,                    VS4TSOMB2.TSB2Balance, VS4TSOMB2.TSB2LastReceiptNo, VS4TSO.TSODNo, VS4TSO.TSODTSBkCode, VS4TSO.TSODType, VS4TSO.TSODDate, VS4TSO.TSODDueDate, VS4TSO.TSODTPrjCode,                    VS4TSO.TSODTBraCode, VS4TSO.TSODTARNCode, VS4TSO.TSODCustomerName, VS4TSO.TSODVATType, VS4TSO.TSODVATTotal, VS4TSO.TSODGrandTotal, VS4TSO.TSODVATRate,                    VS4TSO.TSODTaxBase, VS4TSO.TSODDescription, VS4TSO.TSODConfirmStatus, VS4TSO.TSODApproveStatus, VS4TSO.TSODCancelStatus, VS4TSO.TSODArrears, VS4TSOMB.TSOBTSODNo,                    VS4TSOMB.TSOBLn, VS4TSOMB.TSOBTPOSCode, VS4TSOMB.TSOBPOSName, VS4TSOMB.TSOBPrice, VS4TSOMB.TSOBPerQuantity, VS4TSOMB.TSOBUnitFactor, VS4TSOMB.TSOBQuantityCalc,                    VS4TSOMB.TSOBUnitCalc, VS4TSOMB.TSOBQuantity, VS4TSOMB.TSOBTUntCode, VS4TSOMB.TSOBAmount, VS4TSOMB.TSOBDiscountText, VS4TSOMB.TSOBDiscountTotal, VS4TSOMB.TSOBNetAmount,                    VS4TSOMB.TSOBTaxType, VS4TSOMB.TSOBTaxBase, VS4TSOMB.TSOBWTAXBase, VS4TSOMB.TSOBIsPremium, VS4TSOMB.TSOBDescription, VS4TSOMB.TSOBUseDate, VS4TSOMB.TSOBSourceNo,                    VS4TSOMB.TSOBSourceLn, VS4TSOMB.TSOBTotalDelivery, VS4TSOMB.TSOBTotalArrear, VS4TSOMB.TSOBTotalJob, VS4TSOMB.TSOBTotalJobArr, VS4TSOMB.TSOBStatus, VS4TSOMB.TSOBManualClose,                    VS4TSOMB.TSOBFlag1, VS4TSOMB.TSOBTotalInv, VS4TSOMB.TSOBTotalInvArr, VS4TSOMB.TSOBBaseArrears, VS4TSOMB.TSOBBaseInvArr, VS4TSOMB.TSOBBaseJobArr, VS4TSOMB.TSOBCustom1,                    VS4TSOMB.TSOBCustom2, VS4TSOMB.TSOBCustom3, VS4TSOMB.TSOBCustom4, VS4TSOMB.TSOBCustom5, VS4TSO.TSODRefNo, VS4TSO.TSODRefNo2, VS4TSO.TSODTEmpCode,                    VS4TSO.TSODSaleName, VS4TSO.TSODTARDCode, VS4TSO.TSODContactName, VS4TSO.TSODContactNote, VS4TSO.TSODCusAddress, VS4TSO.TSODTCurCode, VS4TSO.TSODPriceChannel,                    VS4TSO.TSODCode, VS4TSO.TSODRefDate, VS4TSO.TSODCommissionBase, VS4TSO.TSODCommissionRate, VS4TSO.TSODInvoiceStatus, VS4TSOMB.TSOBTOInCode FROM     VS4TSOPayPeriod INNER JOIN                   VS4TSOMB2 ON VS4TSOPayPeriod.TSPPTSODNo = VS4TSOMB2.TSB2TSODNo AND VS4TSOPayPeriod.TSPPTSOBLn = VS4TSOMB2.TSB2Ln INNER JOIN                   VS4TSO INNER JOIN                   VS4TSOMB ON VS4TSO.TSODNo = VS4TSOMB.TSOBTSODNo ON VS4TSOMB2.TSB2TSODNo = VS4TSOMB.TSOBTSODNo AND VS4TSOMB2.TSB2Ln = VS4TSOMB.TSOBLn
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.*, VS4TCommand.TCmdAlias, VS4TCommand.TCmdName, VS4TCommand.TCmdName2 FROM ((VS4TModulePermiss INNER JOIN VS4TGroup ON VS4TModulePermiss.TMdPID = VS4TGroup.TGroID) INNER JOIN (VS4TCommandModule INNER JOIN VS4TCommandGroup ON VS4TCommandModule.TCmMTCmGAlias = VS4TCommandGroup.TCmGAlias) ON VS4TModulePermiss.TMdPTCmMAlias = VS4TCommandModule.TCmMAlias) LEFT JOIN VS4TCommand ON VS4TCommandModule.TCmMAlias = VS4TCommand.TCmdAlias 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 VS4TCommand ON VS4TModulePermiss.TMdPTCmMAlias = VS4TCommand.TCmdAlias) LEFT JOIN VS4TCommandModule ON VS4TCommand.TCmdTCmMAlias = VS4TCommandModule.TCmMAlias) LEFT JOIN VS4TCommandGroup ON VS4TCommandModule.TCmMTCmGAlias = 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 VS4VMOHAllocate AS  SELECT VS4TMOHAllocate.*, VS4TMOHAllocateMB.*, VS4TOtherExpense.*, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtTUntCode FROM VS4TOtherExpense INNER JOIN (VS4TMOHAllocate INNER JOIN (VS4TMOHAllocateMB LEFT JOIN VS4TProduct ON VS4TMOHAllocateMB.TMOBTPdtCode = VS4TProduct.TPdtCode) ON VS4TMOHAllocate.TMOHNo = VS4TMOHAllocateMB.TMOBTMOHNo) ON VS4TOtherExpense.TOExCode = VS4TMOHAllocate.TMOHTOExCode
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.*, VS4TBranch.TBraName, VS4TBranch.TBraName2, VS4TDivision.TDivName, VS4TDivision.TDivName2, VS4TDepartment.TDepName2, VS4TSection.TSecName2, VS4TProject.TPrjName, VS4TProject.TPrjName2, VS4TJob.*, VS4TJobProduction.*, VS4TJobProd2JobMB.TP2JTJPdNo, VS4TJobProd2JobMB.TP2JTJbMTJobNo, VS4TJobProd2JobMB.TP2JTJbMLn, VS4TPosition.TPstName, VS4TPosition.TPstName2 FROM VS4TPosition INNER JOIN (((VS4TDivision INNER JOIN (VS4TBranch INNER JOIN (((((VS4TMPR 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) ON VS4TBranch.TBraCode = VS4TMPR.TMPRTBraCode) ON VS4TDivision.TDivCode = VS4TMPR.TMPRTDivCode) LEFT JOIN VS4TJobProd2JobMB ON VS4TJobProduction.TJPdNo = VS4TJobProd2JobMB.TP2JTJPdNo) INNER JOIN VS4TMPRMB ON VS4TMPR.TMPRNo = VS4TMPRMB.TMPMTMPRNo) ON VS4TPosition.TPstCode = VS4TMPRMB.TMPMTPstCode
GO

CREATE VIEW VS4VMPS AS  SELECT TMPSNo, TMPSTJStTJbMTJobNo, TMPSTJStTJbMLn, TMPSTJStTSpdStep, TMPSTJStLn, TMPSPriority, TMPSTJStLevel, TMPSTSecCode, TMPSTBraCode, TMPSHour, TMPSES, TMPSLS, TMPSEF, TMPSLF, TMPSTMPSNo, TMPSStartDate, TMPSEndDate, TMPSYear, TMPSWeek, TMPSDate, TMPSReserveType, TMPSNote, TMPSStatus, TMPSTJPDNo, TMPSTJPMLn, VS4TJobMethod.*, TJbMTJobNo, TJbMLn, TJbMType, TJbMTDwgCode, TJbMTPdtCode, TJbMProductName, TJBMCustom1, TJBMCustom2, TJBMCustom3, TJBMCustom4, TJBMCustom5, TJbMQuantityCalc, TJbMUnitCalc, TJbMQuantity, TJbMStockOnHand, TJbMUseStock, TJbMUseOrder, TJbMTUntCode, TJbMQuantity2, TJbMStockOnHand2, TJbMUseStock2, TJbMUseOrder2, TJbMTUntCode2, TJbMQuantity3, TJbMStockOnHand3, TJbMUseStock3, TJbMUseOrder3, TJbMTUntCode3, TJbMDescription, TJbMProcessStatus, TJbMTotalRequest, TJbMTotalRequest2, TJbMTotalRequest3, TJbMTotalArrear, TJbMTotalArrear2, TJbMTotalArrear3, TJbMFinishPCOrder, TJbMFinishPC, TJbMFinishQT, TJbMFinishQT2, TJbMFinishQT3, TJbMTotalLoss, TJbMTotalLoss2, TJbMTotalLoss3, TJbMStandardDM, TJbMStandardDL, TJbMStandardMOH, TJbMStandardTotal, TJbMStandardUnit, TJbMActualDM, TJbMActualDL, TJbMActualMOH, TJbMActualTotal, TJbMActualUnit, TJbMActualLastDate, TJbMEstimateDM, TJbMEstimateDL, TJbMEstimateMOH, TJbMEstimateTotal, TJbMEstimateUnit, TJbMCustomText1, TJbMCustomText2, TJbMCustomText3, TJbMCustomText4, TJbMCustomText5, TJbMCustomText6, TJbMCustomText7, TJbMCustomText8, TJbMCustomText9, TJbMCustomText10, TJbMCustomValue1, TJbMCustomValue2, TJbMCustomValue3, TJbMCustomValue4, TJbMCustomValue5, TJbMSetMode, TJbMSourceNo, TJbMSourceLn, TJbMSourceDate, TJbMFlag1, TJbMTMDMTMDNNo, TJbMTMDMLn, TJbMTWRMCode, TJbMStartDate, TJbMAcceptError, TjbMShippingMark, TJbMUnitFactor, TJbMPriority, TJbMControlQty, TJbMQuantityBase, TJbMKindOfPack, TJbMPcsPerCarton, TJbMTotalCarton, TJbMTLblCode, TJobNo, TJobCode, TJobTJBkCode, TJobType, TJobDate, TJobRefNo, TJobRefDate, TJobRefLn, TJobRefNo2, TJobRefDate2, TJOBOriginalNo, TJobTARNCode, TJobCustomerName, TJobTPrjCode, TJobTSecCode, TJobTDepCode, TJobTDivCode, TJobTBraCode, TJobFinishDate, TJobFinishTime, TJobDescription, TJobSetMode, TJobTotalRequest, TJobTotalRequest2, TJobTotalRequest3, TJobTotalArrear, TJobTotalArrear2, TJobTotalArrear3, TJobTotalFinishPCB, TJobTotalFinishPCO, TJobTotalFinishPC, TJobTotalFinishQT, TJobTotalFinishQT2, TJobTotalFinishQT3, TJobTotalLoss, TJobTotalLoss2, TJobTotalLoss3, TJobStandardTotal, TJobActualTotal, TJobActualLastDate, TJobEstimateTotal, TJobCustomText1, TJobCustomText2, TJobCustomValue1, TJobCustomValue2, TJobRequestCode, TJobRequestBy, TJobCloseStatus, TJobCloseBy, TJobCloseDate, TJobCloseNote, TJobCreateBy, TJobCreateDate, TJobEditCode, TJobEditBy, TJobEditDate, TJobConfirmStatus, TJobConfirmBy, TJobConfirmDate, TJobApproveStatus, TJobApproveBy, TJobApproveDate, TJobApproveNote, TJobRevision, TJobCancelStatus, TJobCancelNo, TJobCancelBy, TJobCancelDate, TJobCancelNote, TJobFlag1, TJobTInvNo, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TProduct.TPdtBarcode, VS4TProduct.TPdtTAPNCode, VS4TAR.TARNName, VS4TARGroup.TARGCode, VS4TARGroup.TARGName FROM ((VS4TJob LEFT JOIN VS4TAR ON VS4TJob.TJobTARNCode = VS4TAR.TARNCode) LEFT JOIN VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode) 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 VS4VMRP AS  SELECT VS4TMRP.*, VS4TProduct.*, VS4TProductGroup1.TPG1Name, VS4TProductSection.TPSEName, VS4TProductLine.TPdLName, VS4TPOS.TPOSPrice FROM VS4TProductSection RIGHT JOIN (VS4TProductLine RIGHT JOIN (((VS4TMRP INNER JOIN VS4TProduct ON VS4TMRP.TMRPTPdtCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) ON VS4TProductLine.TPdLCode = VS4TProduct.TPdtTPDLCode) ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode
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.TPKLNo, VS4TPackingList.TPKLDate, VS4TPackingList.TPKLRefNo, VS4TPackingList.TPKLRefDate, VS4TPackingList.TPKLRefNo2, VS4TPackingList.TPKLTPrjCode, VS4TPackingList.TPKLTBraCode, VS4TPackingList.TPKLTARNCode, VS4TPackingList.TPKLTShpCode, VS4TPackingList.TPKLDeliveryCond, VS4TPackingList.TPKLDeliveryTerm, VS4TPackingList.TPKLContainerNo, VS4TPackingList.TPKLShipBy, VS4TPackingList.TPKLTotalQuantity, VS4TPackingList.TPKLTotalCarton, VS4TPackingList.TPKLTotalNW, VS4TPackingList.TPKLTotalGW, VS4TPackingList.TPKLTotalVolumeM, VS4TPackingList.TPKLGrandTotal, VS4TPackingList.TPKLGrandTotalReal, VS4TPackingList.TPKLDescription, VS4TPackingList.TPKLEditCode, VS4TPackingList.TPKLEditBy, VS4TPackingList.TPKLEditDate, VS4TPackingList.TPKLConfirmStatus, VS4TPackingList.TPKLApproveStatus, VS4TPackingList.TPKLApproveBy, VS4TPackingList.TPKLApproveDate, VS4TPackingList.TPKLRevision, VS4TPackingList.TPKLCancelStatus, VS4TPackingList.TPKLMode, VS4TPackingList.TPKLCustom1, VS4TPackingList.TPKLCustom2, VS4TPackingList.TPKLCustom3, VS4TPackingList.TPKLCustom4, VS4TPackingList.TPKLCustom5, VS4TPackingList.TPKLCartonName, VS4TPackingListMB.TPKMTPKLNo, VS4TPackingListMB.TPKMLn, VS4TPackingListMB.TPKMTPOSCode, VS4TPackingListMB.TPKMPOSName, VS4TPackingListMB.TPKMQuantity, VS4TPackingListMB.TPKMTUntCode, VS4TPackingListMB.TPKMKindOfPack, VS4TPackingListMB.TPKMPerQuantity, VS4TPackingListMB.TPKMPcsPerCarton, VS4TPackingListMB.TPKMTotalCarton, VS4TPackingListMB.TPKMCartonNo, VS4TPackingListMB.TPKMToCartonNo, VS4TPackingListMB.TPKMWidth, VS4TPackingListMB.TPKMLength, VS4TPackingListMB.TPKMHeight, VS4TPackingListMB.TPKMVolume, VS4TPackingListMB.TPKMNW, VS4TPackingListMB.TPKMGW, VS4TPackingListMB.TPKMVolumeM, VS4TPackingListMB.TPKMTotalNW, VS4TPackingListMB.TPKMTotalGW, VS4TPackingListMB.TPKMTotalVolumeM, VS4TPackingListMB.TPKMPrice, VS4TPackingListMB.TPKMAmount, VS4TPackingListMB.TPKMRealPrice, VS4TPackingListMB.TPKMRealAmount, VS4TPackingListMB.TPKMRealDate, VS4TPackingListMB.TPKMSourceNo, VS4TPackingListMB.TPKMSourceLn, VS4TPackingListMB.TPKMContainerNo, VS4TPackingListMB.TPKMContainerSize, VS4TPackingListMB.TPKMContainerLCL, VS4TPackingListMB.TPKMGroupName, VS4TPackingListMB.TPKMDescription, VS4TARInvoice.TIvoNo, VS4TARInvoice.TIvoType, VS4TARInvoice.TIvoTRBKCode, VS4TARInvoice.TIvoTRCACode, VS4TARInvoice.TIvoMode, VS4TARInvoice.TIvoDate, VS4TARInvoice.TIvoDueDate, VS4TARInvoice.TIvoGLMethod, VS4TARInvoice.TIvoTGLTNo, VS4TARInvoice.TIvoClientTaxNo, VS4TARInvoice.TIvoTaxNo, VS4TARInvoice.TIvoRefNo, VS4TARInvoice.TIvoRefDate, VS4TARInvoice.TIvoRefNo2, VS4TARInvoice.TIvoRefDate2, VS4TARInvoice.TIvoPONo, VS4TARInvoice.TIvoSOCode, VS4TARInvoice.TIvoTJobNo, VS4TARInvoice.TIvoTJbMLn, VS4TARInvoice.TIvoTPrjCode, VS4TARInvoice.TIvoTBraCode, VS4TARInvoice.TIvoTEmpCode, VS4TARInvoice.TIvoSaleName, VS4TARInvoice.TIvoDeliveryDate, VS4TARInvoice.TIvoDeliveryTo, VS4TARInvoice.TIvoTARNCode, VS4TARInvoice.TIvoTARDCode, VS4TARInvoice.TIvoContactNote, VS4TARInvoice.TIvoContactName, VS4TARInvoice.TIvoCustomerName, VS4TARInvoice.TIvoCusAddress, VS4TARInvoice.TIvoCustomerName2, VS4TARInvoice.TIvoCusAddress2, VS4TARInvoice.TIvoConsignee, VS4TARInvoice.TIvoNotifyParty, VS4TARInvoice.TIvoCostTotal, VS4TARInvoice.TIvoPriceChannel, VS4TARInvoice.TIvoDiscountList, VS4TARInvoice.TIvoSubTotal, VS4TARInvoice.TIvoDiscountText, VS4TARInvoice.TIvoDiscountTotal, VS4TARInvoice.TIvoNetTotal, VS4TARInvoice.TIvoDepositText, VS4TARInvoice.TIvoDeposit, VS4TARInvoice.TIvoTotal, VS4TARInvoice.TIvoTotalFOB, VS4TARInvoice.TIvoTCurCode, VS4TARInvoice.TIvoExchangeRate, VS4TARInvoice.TIvoTotalInRate, VS4TARInvoice.TIvoVATType, VS4TARInvoice.TIvoVATRate, VS4TARInvoice.TIvoTaxBase, VS4TARInvoice.TIvoVATTotal, VS4TARInvoice.TIvoGrandTotal, VS4TARInvoice.TIvoNOTAXTotal, VS4TARInvoice.TIvoWTaxBase, VS4TARInvoice.TIvoWTaxRate, VS4TARInvoice.TIvoWTaxTotal, VS4TARInvoice.TIvoNetPayment, VS4TARInvoice.TIvoAdjustTotal, VS4TARInvoice.TIvoBaseAvailable, VS4TARInvoice.TIvoAvailable, VS4TARInvoice.TIvoPremiumTotal, VS4TARInvoice.TIvoCommissionBase, VS4TARInvoice.TIvoCommissionRate, VS4TARInvoice.TIvoCommission, VS4TARInvoice.TIvoBaseIncoType, VS4TARInvoice.TIvoIncoType, VS4TARInvoice.TIvoIncoTerms, VS4TARInvoice.TIvoOtherFee, VS4TARInvoice.TIvoTransportFee, VS4TARInvoice.TIvoHandlingFee, VS4TARInvoice.TIvoFreightFee, VS4TARInvoice.TIvoInsurance, VS4TARInvoice.TIvoTransportDesc, VS4TARInvoice.TIvoDuty, VS4TARInvoice.TIvoShipBy, VS4TARInvoice.TIvoCountryOrigin, VS4TARInvoice.TIvoDestination, VS4TARInvoice.TIvoCondition, VS4TARInvoice.TIvoConditionDay, VS4TARInvoice.TIvoCondition1, VS4TARInvoice.TIvoConditionDay1, VS4TARInvoice.TIvoPaymentNote, VS4TARInvoice.TIvoStatementNote, VS4TARInvoice.TIvoTShpCode, VS4TARInvoice.TIvoDeliveryNote, VS4TARInvoice.TIvoPackingNote, VS4TARInvoice.TIvoCustom1, VS4TARInvoice.TIvoCustom2, VS4TARInvoice.TIvoCustom3, VS4TARInvoice.TIvoCustom4, VS4TARInvoice.TIvoCustom5, VS4TARInvoice.TIvoCustom6, VS4TARInvoice.TIvoCartonName, VS4TARInvoice.TIvoTotalCarton, VS4TARInvoice.TIvoTotalNW, VS4TARInvoice.TIvoTotalGW, VS4TARInvoice.TIvoDayAvailable, VS4TARInvoice.TIvoDescription, VS4TARInvoice.TIvoTSOTCode, VS4TARInvoice.TIvoDeliveryStatus, VS4TARInvoice.TIvoBillStatus, VS4TARInvoice.TIvoCardFlag, VS4TARInvoice.TIvoTaxFlag, VS4TARInvoice.TIvoEditBy, VS4TARInvoice.TIvoApproveBy, VS4TARInvoice.TIvoRevision, VS4TARInvoice.TIvoCancelStatus, VS4TARInvoice.TIvoTRouCode, VS4TARInvoice.TIvoCustomNo, VS4TARInvoice.TIvoCustomDate, VS4TARInvoice.TIvoPMCostTotal, VS4TARInvoice.TIvoTOTNLn, VS4TARInvoice.TIvoDeliveryCond, VS4TARInvoice.TIvoLoadingDate, VS4TARInvoice.TIvoStartAgingDate, VS4TARInvoice.TIvoIgnoreArrears, VS4TARInvoice.TIvoBoxList, VS4TARInvoice.TIvoExchangeRate2, VS4TARInvoice.TIvoNote, VS4TARInvoice.TIvoTotalQuantity, VS4TARInvoice.TIvoTPOSCode, VS4TARInvoice.TIvoReceiptStatus, VS4TARInvoice.TIvoManualArrear, VS4TARInvoice.TIvoCardStatus, VS4TARInvoice.TIvoRefNo3, VS4TARInvoice.TIvoTARWCode, VS4TCountry.TCouName, VS4TCountry.TCouName2, VS4TAR.TARNCode, VS4TAR.TARNName, VS4TAR.TARNName2, 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, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TARInvoice2.TIv2Vessel, VS4TAR.TARNPhone, VS4TAR.TARNFax, VS4TARInvoiceMB.TIoMCustom1, VS4TARInvoiceMB.TIoMCustom2, VS4TARInvoiceMB.TIoMCustom3, VS4TARInvoiceMB.TIoMCustom4, VS4TARInvoiceMB.TIoMCustom5, VS4TARInvoiceMB.TIoMQuantityPallet, VS4TARInvoiceMB.TIoMQuantityStock, VS4TARInvoiceMB.TIoMControlQty, VS4TARInvoiceMB.TIoMAcceptError, VS4TARInvoice2.TIv2TruckNo, VS4TARInvoice2.TIv2TSDVNo, VS4TARInvoice2.TIv2LogisticType, VS4TARInvoiceMB.TIoMTPOSCode, VS4TARInvoiceMB.TIoMPOSName, VS4TARInvoiceMB.TIoMDescription, VS4TARInvoiceMB.TIoMQuantity, VS4TARInvoiceMB.TIoMQuantity2, VS4TARInvoiceMB.TIoMQuantity3, VS4TARInvoiceMB.TIoMPOSName2, VS4TARInvoiceMB.TIoMQuantityBase, VS4TARInvoiceMB.TIoMUnitFactor, VS4TARInvoiceMB.TIoMTUntCode, VS4TARInvoiceMB.TIoMFactoryCode, VS4TAR2.TAR2Style, VS4TARInvoice2.TIv2IDC, VS4TARInvoice2.TIv2ShipDate, VS4TARInvoice.TIvoApproveStatus 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) LEFT JOIN VS4TARInvoice2 ON VS4TARInvoice.TIvoNo = VS4TARInvoice2.TIv2TIvoNo) LEFT JOIN VS4TAR2 ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) ON VS4TCountry.TCouCode = VS4TAR.TARNTCouCode) INNER JOIN (((VS4TPackingListMB LEFT JOIN VS4TProduct ON VS4TPackingListMB.TPKMTPOSCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code) LEFT JOIN VS4TARInvoiceMB ON (VS4TPackingListMB.TPKMSourceNo = VS4TARInvoiceMB.TIoMTIvoNo) AND (VS4TPackingListMB.TPKMSourceLn = VS4TARInvoiceMB.TIoMLn)) 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 VS4TAP INNER JOIN (VS4TPOS INNER JOIN (VS4TPCR INNER JOIN (VS4TPCRMB LEFT JOIN VS4TProduct ON VS4TPCRMB.TPCBTPdtCode = VS4TProduct.TPdtCode) ON VS4TPCR.TPCRNo = VS4TPCRMB.TPCBTPCRNo) ON VS4TPOS.TPOSCode = VS4TPCRMB.TPCBTPOSCode) ON VS4TAP.TAPNCode = VS4TPCR.TPCRTAPNCode
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.TPODNo, VS4TPO.TPODTPOkCode, VS4TPO.TPODTPCACode, VS4TPO.TPODMode, VS4TPO.TPODDOArrears, VS4TPO.TPODType, VS4TPO.TPODDate, VS4TPO.TPODDueDate,                    VS4TPO.TPODRefNo, VS4TPO.TPODRefDate, VS4TPO.TPODRefNo2, VS4TPO.TPODTJobNo, VS4TPO.TPODTJbMLn, VS4TPO.TPODTPrjCode, VS4TPO.TPODTBraCode, VS4TPO.TPODDeliveryDate,                    VS4TPO.TPODDeliveryTo, VS4TPO.TPODTAPNCode, VS4TPO.TPODTAPUCode, VS4TPO.TPODContactNote, VS4TPO.TPODContactName, VS4TPO.TPODSupplierName, VS4TPO.TPODSupAddress,                    VS4TPO.TPODConsignee, VS4TPO.TPODNotifyParty, VS4TPO.TPODPriceChannel, VS4TPO.TPODDiscountList, VS4TPO.TPODSubTotal, VS4TPO.TPODDiscountText, VS4TPO.TPODDiscountTotal,                    VS4TPO.TPODNetTotal, VS4TPO.TPODDepositText, VS4TPO.TPODDeposit, VS4TPO.TPODTotal, VS4TPO.TPODTotalFOB, VS4TPO.TPODTCurCode, VS4TPO.TPODExchangeRate,                    VS4TPO.TPODTotalInRate, VS4TPO.TPODVATType, VS4TPO.TPODVATRate, VS4TPO.TPODTaxBase, VS4TPO.TPODVATTotal, VS4TPO.TPODGrandTotal, VS4TPO.TPODNOTAXTotal,                    VS4TPO.TPODWTaxBase, VS4TPO.TPODWTaxRate, VS4TPO.TPODWTaxTotal, VS4TPO.TPODNetPayment, VS4TPO.TPODAdjustTotal, VS4TPO.TPODPremiumTotal, VS4TPO.TPODBaseIncoType,                    VS4TPO.TPODIncoType, VS4TPO.TPODIncoterms, VS4TPO.TPODOtherFee, VS4TPO.TPODTransportFee, VS4TPO.TPODHandlingFee, VS4TPO.TPODFreightFee, VS4TPO.TPODInsurance,                    VS4TPO.TPODTransportDesc, VS4TPO.TPODDuty, VS4TPO.TPODShipBy, VS4TPO.TPODCountryOrigin, VS4TPO.TPODDestination, VS4TPO.TPODCondition, VS4TPO.TPODConditionDay,                    VS4TPO.TPODCondition1, VS4TPO.TPODConditionDay1, VS4TPO.TPODPaymentNote, VS4TPO.TPODStatementNote, VS4TPO.TPODTShpCode, VS4TPO.TPODDeliveryNote, VS4TPO.TPODPackingNote,                    VS4TPO.TPODDayAvailable, VS4TPO.TPODDescription, VS4TPO.TPODCustom1, VS4TPO.TPODCustom2, VS4TPO.TPODCustom3, VS4TPO.TPODCustom4, VS4TPO.TPODCustom5,                    VS4TPO.TPODTPOTCode, VS4TPO.TPODLinkStatus, VS4TPO.TPODInvoiceStatus, VS4TPO.TPODDeliveryStatus, VS4TPO.TPODFinishDate, VS4TPO.TPODCreateBy, VS4TPO.TPODEditCode,                    VS4TPO.TPODEditBy, VS4TPO.TPODEditDate, VS4TPO.TPODConfirmStatus, VS4TPO.TPODConfirmBy, VS4TPO.TPODConfirmDate, VS4TPO.TPODApproveStatus, VS4TPO.TPODApproveBy,                    VS4TPO.TPODApproveDate, VS4TPO.TPODRevision, VS4TPO.TPODCancelStatus, VS4TPO.TPODCancelDate, VS4TPO.TPODFlag1, VS4TPO.TPODConditionType, VS4TPO.TPODLoadingDate,                    VS4TPO.TPODStartAgingDate, VS4TPO.TPODArrears, VS4TPO.TPODNote, VS4TPOMB.TPOBTPODNo, VS4TPOMB.TPOBLn, VS4TPOMB.TPOBType, VS4TPOMB.TPOBJobCode,                    VS4TPOMB.TPOBGroupName, VS4TPOMB.TPOBTOExCode, VS4TPOMB.TPOBTPdtCode, VS4TPOMB.TPOBCustom1, VS4TPOMB.TPOBCustom2, VS4TPOMB.TPOBCustom3, VS4TPOMB.TPOBCustom4,                    VS4TPOMB.TPOBCustom5, VS4TPOMB.TPOBShippingMark, VS4TPOMB.TPOBProductCode, VS4TPOMB.TPOBFactoryCode, VS4TPOMB.TPOBProductName, VS4TPOMB.TPOBUseBom,                    VS4TPOMB.TPOBDeliveryDate, VS4TPOMB.TPOBDeliveryTime, VS4TPOMB.TPOBMinimumOrder, VS4TPOMB.TPOBCost, VS4TPOMB.TPOBPrice, VS4TPOMB.TPOBPerQuantity, VS4TPOMB.TPOBUnitFactor,                    VS4TPOMB.TPOBAcceptError, VS4TPOMB.TPOBUnitCalc, VS4TPOMB.TPOBQuantityCalc, VS4TPOMB.TPOBQuantityText, VS4TPOMB.TPOBQuantity, VS4TPOMB.TPOBTUntCode, VS4TPOMB.TPOBQuantity2,                    VS4TPOMB.TPOBTUntCode2, VS4TPOMB.TPOBQuantity3, VS4TPOMB.TPOBTUntCode3, VS4TPOMB.TPOBDutyAmount, VS4TPOMB.TPOBDivideExpense, VS4TPOMB.TPOBCostAmount,                    VS4TPOMB.TPOBAmount, VS4TPOMB.TPOBDiscountText, VS4TPOMB.TPOBDiscountTotal, VS4TPOMB.TPOBNetAmount, VS4TPOMB.TPOBTaxType, VS4TPOMB.TPOBTaxBase, VS4TPOMB.TPOBWTAXBase,                    VS4TPOMB.TPOBAmountVAT, VS4TPOMB.TPOBAmountWTAX, VS4TPOMB.TPOBAutoSTD, VS4TPOMB.TPOBStandardCost, VS4TPOMB.TPOBMargin, VS4TPOMB.TPOBSaleMargin,                    VS4TPOMB.TPOBSalePrice, VS4TPOMB.TPOBGetNumber, VS4TPOMB.TPOBFreeCode, VS4TPOMB.TPOBIsPremium, VS4TPOMB.TPOBDescription, VS4TPOMB.TPOBSourceNo, VS4TPOMB.TPOBSourceLn,                    VS4TPOMB.TPOBStatus, VS4TPOMB.TPOBStockTotal, VS4TPOMB.TPOBPRArrear, VS4TPOMB.TPOBTotalDelivery, VS4TPOMB.TPOBTotalDelivery2, VS4TPOMB.TPOBTotalDelivery3,                    VS4TPOMB.TPOBTotalArrear, VS4TPOMB.TPOBTotalArrear2, VS4TPOMB.TPOBTotalArrear3, VS4TPOMB.TPOBMapTPdtCode, VS4TPOMB.TPOBMapTUntCode, VS4TPOMB.TPOBDayProcess,                    VS4TPOMB.TPOBTLctCode, VS4TPOMB.TPOBManualClose, VS4TPOMB.TPOBMapRatioP, VS4TPOMB.TPOBQuantityCost, VS4TPOMB.TPOBTotalInv, VS4TPOMB.TPOBTotalInv2, VS4TPOMB.TPOBTotalInv3,                    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, 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, VS4TAP.TAPNTBsTCode, VS4TAPGroup.TAPGName, VS4TProduct.TPdtTPDLCode, VS4TProductLine.TPdLName, VS4TProduct.TPdtTPSECode,                    VS4TProductSection.TPSEName, VS4TProductSec2.TPS2Name, VS4TProductGroup1.TPG1Name, VS4TProductGroup2.TPG2Name, 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, VS4TAP.TAPNAddressBill2, VS4TProduct.TPdtRequireCOA,                    VS4TPO.TPODFlag2, VS4TProductSection.TPSEName2, VS4TProduct.TPdtBarcode, VS4TPOMB.TPOBTotalInvArr, VS4TPOMB.TPOBTotalInvArr2, VS4TPOMB.TPOBTotalInvArr3, VS4TUnit.TUntName,                    VS4TUnit.TUntName2, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtAliasSlip, VS4TProduct.TPdtDescription, VS4TPOMBAOL.TPOATBraCode, VS4TPOMBAOL.TPOATDivCode,                    VS4TPOMBAOL.TPOATDepCode, VS4TPOMBAOL.TPOATSecCode, VS4TPOMBAOL.TPOATEmpCode, VS4TPR.TPRDRequestBy, VS4TPO.TPODApproveNote, VS4TEmployee.TEmpFullName2,                    VS4TPRMB.TPRMDescription, VS4TAPBranch.TAPUName, VS4TPR.TPRDCreateBy, VS4TPR.TPRDCreateDate, VS4TPR.TPRDConfirmBy, VS4TPR.TPRDConfirmDate, VS4TPR.TPRDApproveBy,                    VS4TAP.TAPNTCouCode, VS4TPO.TPODHireWork, VS4TPO.TPODBalanceFlag, VS4TPO.TPODToTBraCode, VS4TPO.TPODSuggestCode, VS4TPO.TPODSuggestBy FROM     VS4TPR LEFT OUTER JOIN                   VS4TSection ON VS4TPR.TPRDTSecCode = VS4TSection.TSecCode LEFT OUTER JOIN                   VS4TDepartment ON VS4TPR.TPRDTDepCode = VS4TDepartment.TDepCode LEFT OUTER JOIN                   VS4TDivision ON VS4TPR.TPRDTDivCode = VS4TDivision.TDivCode LEFT OUTER JOIN                   VS4TBranch ON VS4TPR.TPRDTBraCode = VS4TBranch.TBraCode RIGHT OUTER JOIN                   VS4TCountry INNER JOIN                   VS4TAP LEFT OUTER JOIN                   VS4TBusinessType ON VS4TAP.TAPNTBsTCode = VS4TBusinessType.TBsTCode LEFT OUTER JOIN                   VS4TAPGroup ON VS4TAP.TAPNTAPGCode = VS4TAPGroup.TAPGCode INNER JOIN                   VS4TPO LEFT OUTER JOIN                   VS4TProject ON VS4TPO.TPODTPrjCode = VS4TProject.TPrjCode LEFT OUTER JOIN                   VS4TEmployee ON VS4TPO.TPODEditCode = VS4TEmployee.TEmpCode LEFT OUTER JOIN                   VS4TAPBranch ON VS4TPO.TPODTAPUCode = VS4TAPBranch.TAPUCode AND VS4TPO.TPODTAPNCode = VS4TAPBranch.TAPUTAPNCode ON VS4TAP.TAPNCode = VS4TPO.TPODTAPNCode ON                    VS4TCountry.TCouCode = VS4TAP.TAPNTCouCode INNER JOIN                   VS4TPOMB LEFT OUTER JOIN                   VS4TPRMB ON VS4TPOMB.TPOBSourceLn = VS4TPRMB.TPRMLn AND VS4TPOMB.TPOBSourceNo = VS4TPRMB.TPRMTPRDNo LEFT OUTER JOIN                   VS4TProduct ON VS4TPOMB.TPOBTPdtCode = VS4TProduct.TPdtCode LEFT OUTER JOIN                   VS4TProductLine ON VS4TProduct.TPdtTPDLCode = VS4TProductLine.TPdLCode LEFT OUTER JOIN                   VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode LEFT OUTER JOIN                   VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code LEFT OUTER JOIN                   VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code LEFT OUTER JOIN                   VS4TProductGroup2 ON VS4TProduct.TPdtTPG2Code = VS4TProductGroup2.TPG2Code LEFT OUTER JOIN                   VS4TLocation ON VS4TPOMB.TPOBTLctCode = VS4TLocation.TLctCode LEFT OUTER JOIN                   VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode LEFT OUTER JOIN                   VS4TProduct AS VS4TProduct_1 ON VS4TPOMB.TPOBMapTPdtCode = VS4TProduct_1.TPdtCode LEFT OUTER JOIN                   VS4TPOMBAOL ON VS4TPOMB.TPOBLn = VS4TPOMBAOL.TPOATPOBLn AND VS4TPOMB.TPOBTPODNo = VS4TPOMBAOL.TPOATPOBTPODNo LEFT OUTER JOIN                   VS4TUnit ON VS4TPOMB.TPOBTUntCode = VS4TUnit.TUntCode ON VS4TPO.TPODNo = VS4TPOMB.TPOBTPODNo ON VS4TPR.TPRDNo = VS4TPRMB.TPRMTPRDNo
GO

CREATE VIEW VS4VPO2APInv AS  SELECT VS4TPO.*, VS4TPOMB.*, VS4TProject.TPrjName, VS4TAP.TAPNName, VS4TBranch.TBraName, VS4TAPInvoice.TIAPNo, VS4TAPInvoice.TIAPDate, VS4TAPInvoice.TIAPRefNo, VS4TAPInvoiceMB.TIPMSerialNo, VS4TAPInvoiceMB.TIPMCustom1, VS4TAPInvoiceMB.TIPMCustom2, VS4TAPInvoiceMB.TIPMCustom3, VS4TAPInvoiceMB.TIPMCustom4, VS4TAPInvoiceMB.TIPMCustom5, 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, TPOBTPODNo, TPOBLn, TPOBType, TPOBJobCode, TPOBGroupName, TPOBTOExCode, TPOBTPdtCode, TPOBCustom1, TPOBCustom2, TPOBCustom3, TPOBCustom4, TPOBCustom5, TPOBShippingMark, TPOBProductCode, TPOBFactoryCode, TPOBProductName, TPOBUseBom, TPOBDeliveryDate, TPOBDeliveryTime, TPOBMinimumOrder, TPOBCost, TPOBPrice, TPOBPerQuantity, TPOBUnitFactor, TPOBAcceptError, TPOBUnitCalc, TPOBQuantityCalc, TPOBQuantityText, TPOBQuantity, TPOBTUntCode, TPOBQuantity2, TPOBTUntCode2, TPOBQuantity3, TPOBTUntCode3, TPOBDutyAmount, TPOBDivideExpense, TPOBCostAmount, TPOBAmount, TPOBDiscountText, TPOBDiscountTotal, TPOBNetAmount, TPOBTaxType, TPOBTaxBase, TPOBWTAXBase, TPOBAmountVAT, TPOBAmountWTAX, TPOBAutoSTD, TPOBStandardCost, TPOBMargin, TPOBSaleMargin, TPOBAutoPrice, TPOBSalePrice, TPOBGetNumber, TPOBFreeCode, TPOBIsPremium, TPOBDescription, TPOBSourceNo, TPOBSourceLn, TPOBStatus, TPOBStockTotal, TPOBPRArrear, TPOBEOQ, TPOBTotalDelivery, TPOBTotalDelivery2, TPOBTotalDelivery3, TPOBTotalArrear, TPOBTotalArrear2, TPOBTotalArrear3, TPOBMapTPdtCode, TPOBMapTUntCode, TPOBDayProcess, TPOBTLctCode, TPOBManualClose, TPOBMapRatioP, TPOBQuantityCost, TPOBTotalInv2, TPOBTotalInv3, TPOBTotalInv, TPOBTotalInvArr, TPOBTotalInvArr2, TPOBTotalInvArr3, TPDETPOBTPODNo, TPDETPOBLn, TPDELn, TPDEProductCode, TPDEProductName, TPDEDate, TPDEDateTime, TPDEQuantity, TPDEQuantity2, TPDEQuantity3, TPDETotalDelivery, TPDETotalDelivery2, TPDETotalDelivery3, TPDETotalArrear, TPDETotalArrear2, TPDETotalArrear3, TPDEUnitCalc, TPDEMapTPdtCode, TPDEMapTUntCode, TPDEMapUnitRatio, TPDEQuantityBase, TPDEDeliveryBase, TPDEArrearBase, TPDELinkStatus, TPDELinkBy, TPDELinkDate, TPDETotalOntime, TPDETotalDelay, TPDETLctCode, TPDEFlag1, TPDETotalInv2, TPDETotalInv3, TPDETotalInv, TPDETotalInvArr, TPDETotalInvArr2, TPDETotalInvArr3, TPRMTPRDNo, TPRMLn, TPRMType, TPRMTJobNo, TPRMJobCode, TPRMMaterialMode, TPRMGroupName, TPRMTPdtCode, TPRMProductCode, TPRMFactoryCode, TPRMProductName, TPRMCustom1, TPRMCustom2, TPRMCustom3, TPRMCustom4, TPRMCustom5, TPRMPrice, TPRMPerQuantity, TPRMDiscountText, TPRMDiscountTotal, TPRMTaxType, TPRMQuantityCalc, TPRMUnitFactor, TPRMUnitCalc, TPRMQuantity, TPRMAmount, TPRMNetAmount, TPRMRefill, TPRMMarkTotal, TPRMStockOnHand, TPRMMinStock, TPRMPOArrearCalc, TPRMSuggest, TPRMPOArrear, TPRMTotalDelivery, TPRMTotalArrear, TPRMTUntCode, TPRMQuantity2, TPRMStockOnHand2, TPRMTotalDelivery2, TPRMTotalArrear2, TPRMTUntCode2, TPRMQuantity3, TPRMStockOnHand3, TPRMTotalDelivery3, TPRMTotalArrear3, TPRMTUntCode3, TPRMUseType, TPRMUseDate, TPRMDescription, TPRMProcessStatus, TPRMStatus, TPRMFlag1, TPRMMapTPdtCode, TPRMMapTUntCode, TPRMMapRatioP, TPRMMaxStock, TPRMOrderPoint, TPRMOrderQuantity, TPRMSafetyStock, TPRMPRArrearCalc, TPRMSourceNo, TPRMSourceLn, VS4TPO.TPODCountryOrigin, VS4TCountry.TCouName, VS4TPO.TPODTPrjCode, VS4TProject.TPrjName, 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, VS4TPR.TPRDNo, VS4TPR.TPRDDate, VS4TPR.TPRDJobCode, VS4TPR.TPRDTJobNo, VS4TPR.TPRDTJbMLn, VS4TPR.TPRDTPrjCode, VS4TPR.TPRDTSecCode, VS4TPR.TPRDTDepCode, VS4TPR.TPRDTDivCode, VS4TPR.TPRDTBraCode, VS4TPR.TPRDDescription, VS4TPR.TPRDTPRBCode, VS4TPO.TPODRefNo, VS4VInventoryA.TInMAmouQuantity, VS4VInventoryA.TInMAmouQuantity2, VS4VInventoryA.TInMAmouQuantity3, VS4VInventoryA.TInMTInTAlias, VS4VInventoryA.TInvNo, VS4VInventoryA.TInvRefNo, VS4VInventoryA.TInvRefDate, VS4VInventoryA.TInvRefNo2, VS4VInventoryA.TInvRefDate2, VS4VInventoryA.TInvDate, VS4VInventoryA.TInMLotNo, VS4VInventoryA.TInMLotDate, VS4VInventoryA.TIMCIsPremium, VS4VInventoryA.TIMCPremiumNote, VS4VInventoryA.TInvCancelStatus, VS4VInventoryA.TInvTIBkCode, VS4VInventoryA.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 ((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) LEFT JOIN VS4VInventoryA ON (VS4TPODelivery.TPDELn = VS4VInventoryA.TInMTMDSLn) AND (VS4TPODelivery.TPDETPOBLn = VS4VInventoryA.TInMTSOBLn) AND (VS4TPODelivery.TPDETPOBTPODNo = VS4VInventoryA.TInMTSODNo)) ON VS4TProductLine.TPdLCode = VS4TProduct.TPdtTPDLCode) LEFT JOIN VS4TProduct2 ON VS4TProduct.TPdtCode = VS4TProduct2.TPd2TPdtCode) ON VS4TPO.TPODNo = VS4TPOMB.TPOBTPODNo) ON VS4TPR.TPRDNo = VS4TPRMB.TPRMTPRDNo
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, TPRDNo, TPRDTPRBCode, TPRDMode, TPRDCode, TPRDType, TPRDDate, TPRDRefNo, TPRDRefDate, TPRDJobCode, TPRDTJobNo, TPRDTJbMLn, TPRDTJPMLn, TPRDTJPDNo, TPRDTPrjCode, TPRDTSecCode, TPRDTDepCode, TPRDTDivCode, TPRDTBraCode, TPRDTAPNCode, TPRDDescription, TPRDProcessStatus, TPRDDeliveryStatus, TPRDRequestCode, TPRDRequestBy, TPRDCreateBy, TPRDCreateDate, TPRDEditCode, TPRDEditBy, TPRDEditDate, TPRDConfirmStatus, TPRDConfirmBy, TPRDConfirmDate, TPRDApproveStatus, TPRDApproveBy, TPRDApproveDate, TPRDApproveNote, TPRDRevision, TPRDReviseStatus, TPRDCancelStatus, TPRDFlag1, TPRDMProcessStatus, TPRDTCurCode, TPRDExchangeRate, TPRDBaseIncoType, TPRDIncoType, TPRDIncoterms, TPRMTPRDNo, TPRMLn, TPRMType, TPRMTJobNo, TPRMJobCode, TPRMMaterialMode, TPRMGroupName, TPRMTPdtCode, TPRMProductCode, TPRMFactoryCode, TPRMProductName, TPRMCustom1, TPRMCustom2, TPRMCustom3, TPRMCustom4, TPRMCustom5, TPRMPrice, TPRMPerQuantity, TPRMDiscountText, TPRMDiscountTotal, TPRMTaxType, TPRMQuantityCalc, TPRMUnitFactor, TPRMUnitCalc, TPRMQuantity, TPRMAmount, TPRMNetAmount, TPRMRefill, TPRMMarkTotal, TPRMStockOnHand, TPRMMaxStock, TPRMMinStock, TPRMPOArrearCalc, TPRMSuggest, TPRMPOArrear, TPRMTotalDelivery, TPRMTotalArrear, TPRMTUntCode, TPRMQuantity2, TPRMStockOnHand2, TPRMTotalDelivery2, TPRMTotalArrear2, TPRMTUntCode2, TPRMQuantity3, TPRMStockOnHand3, TPRMTotalDelivery3, TPRMTotalArrear3, TPRMTUntCode3, TPRMUseType, TPRMUseDate, TPRMDescription, TPRMProcessStatus, TPRMStatus, TPRMFlag1, TPRMMapTPdtCode, TPRMMapTUntCode, TPRMMapRatioP, 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 VS4VPOArrear AS  SELECT VS4TPOMB.*, VS4TPO.* FROM VS4TPO INNER JOIN VS4TPOMB ON VS4TPO.TPODNo = VS4TPOMB.TPOBTPODNo WHERE (((VS4TPOMB.TPOBTotalArrear)>0) AND ((VS4TPO.TPODApproveStatus)=1) AND ((VS4TPO.TPODCancelStatus)=0))
GO

CREATE VIEW VS4VPOArrearSum AS  SELECT VS4TPOMB.TPOBTPdtCode, Sum(VS4TPOMB.TPOBQuantity) AS TPOBQuantity, Sum(VS4TPOMB.TPOBTotalArrear) AS TPOBTotalArrear, Sum(VS4TPOMB.TPOBQuantity*TPOBUnitFactor) AS TPOBQuantityBase, Sum(VS4TPOMB.TPOBTotalArrear*TPOBUnitFactor) AS TPOBTotalArrearBas FROM VS4TPO INNER JOIN VS4TPOMB ON VS4TPO.TPODNo = VS4TPOMB.TPOBTPODNo GROUP BY VS4TPOMB.TPOBTPdtCode, VS4TPO.TPODApproveStatus, VS4TPO.TPODCancelStatus HAVING (((VS4TPO.TPODApproveStatus)=1) AND ((VS4TPO.TPODCancelStatus)=0))
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 VS4VPOControl AS  SELECT VS4TPO.*, VS4TPO2.*, VS4TPOBook.*, VS4TPOMB.*, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtBarcode, VS4TAP.TAPNTaxNo, A.TInvNo, A.TInvDate, A.TInMTSODNo, VS4TAP.TAPNTBsTCode, VS4TAP.TAPNTAPGCode, VS4TAP.TAPNTPrvCode, VS4TAP.TAPNTCouCode, VS4TAP.TAPNTSPvCode, VS4TJob.TJobTARNCode, VS4TJob.TJobCustomerName FROM (VS4TPOBook INNER JOIN (VS4TAP INNER JOIN ((VS4TPO LEFT JOIN VS4TPO2 ON VS4TPO.TPODNo = VS4TPO2.TPO2TPODNo) LEFT JOIN VS4TJob ON VS4TPO.TPODTJobNo = VS4TJob.TJobNo) ON VS4TAP.TAPNCode = VS4TPO.TPODTAPNCode) ON VS4TPOBook.TPOKCode = VS4TPO.TPODTPOkCode) INNER JOIN ((SELECT DISTINCT TOP 100 PERCENT TInvNo, TInvDate, TInMTSODNo, VS4TInventoryMB.TInMTPdtCode FROM VS4TInventory INNER JOIN VS4TInventoryMB ON VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo WHERE (((VS4TInventoryMB.TInMTSODNo)<>'' And (VS4TInventoryMB.TInMTSODNo) Is Not Null) And ((VS4TInventory.TInvTInTAlias)='LOTIN') And ((VS4TInventory.TInvCancelStatus)=0) And ((VS4TInventory.TInvApproveStatus)=1)) ORDER BY VS4TInventory.TInvDate DESC , VS4TInventory.TInvNo DESC) AS A RIGHT JOIN (VS4TPOMB LEFT JOIN VS4TProduct ON VS4TPOMB.TPOBTPdtCode = VS4TProduct.TPdtCode) ON A.TInMTSODNo = VS4TPOMB.TPOBTPODNo) ON VS4TPO.TPODNo = VS4TPOMB.TPOBTPODNo
GO

CREATE VIEW VS4VPODelivery AS SELECT VS4TPO.TPODNo, VS4TPO.TPODTPOkCode, VS4TPO.TPODTPCACode, VS4TPO.TPODMode, VS4TPO.TPODDOArrears, VS4TPO.TPODType, VS4TPO.TPODDate, VS4TPO.TPODDueDate,                    VS4TPO.TPODRefNo, VS4TPO.TPODRefDate, VS4TPO.TPODRefNo2, VS4TPO.TPODTJobNo, VS4TPO.TPODTJbMLn, VS4TPO.TPODTPrjCode, VS4TPO.TPODTBraCode, VS4TPO.TPODDeliveryDate,                    VS4TPO.TPODDeliveryTo, VS4TPO.TPODTAPNCode, VS4TPO.TPODTAPUCode, VS4TPO.TPODContactNote, VS4TPO.TPODContactName, VS4TPO.TPODSupplierName, VS4TPO.TPODSupAddress,                    VS4TPO.TPODConsignee, VS4TPO.TPODNotifyParty, VS4TPO.TPODPriceChannel, VS4TPO.TPODDiscountList, VS4TPO.TPODSubTotal, VS4TPO.TPODDiscountText, VS4TPO.TPODDiscountTotal,                    VS4TPO.TPODNetTotal, VS4TPO.TPODDepositText, VS4TPO.TPODDeposit, VS4TPO.TPODTotal, VS4TPO.TPODTotalFOB, VS4TPO.TPODTCurCode, VS4TPO.TPODExchangeRate,                    VS4TPO.TPODTotalInRate, VS4TPO.TPODVATType, VS4TPO.TPODVATRate, VS4TPO.TPODTaxBase, VS4TPO.TPODVATTotal, VS4TPO.TPODGrandTotal, VS4TPO.TPODNOTAXTotal,                    VS4TPO.TPODWTaxBase, VS4TPO.TPODWTaxRate, VS4TPO.TPODWTaxTotal, VS4TPO.TPODNetPayment, VS4TPO.TPODAdjustTotal, VS4TPO.TPODPremiumTotal, VS4TPO.TPODBaseIncoType,                    VS4TPO.TPODIncoType, VS4TPO.TPODIncoterms, VS4TPO.TPODOtherFee, VS4TPO.TPODTransportFee, VS4TPO.TPODHandlingFee, VS4TPO.TPODFreightFee, VS4TPO.TPODInsurance,                    VS4TPO.TPODTransportDesc, VS4TPO.TPODDuty, VS4TPO.TPODShipBy, VS4TPO.TPODCountryOrigin, VS4TPO.TPODDestination, VS4TPO.TPODCondition, VS4TPO.TPODConditionDay,                    VS4TPO.TPODCondition1, VS4TPO.TPODConditionDay1, VS4TPO.TPODPaymentNote, VS4TPO.TPODStatementNote, VS4TPO.TPODTShpCode, VS4TPO.TPODDeliveryNote, VS4TPO.TPODPackingNote,                    VS4TPO.TPODDayAvailable, VS4TPO.TPODDescription, VS4TPO.TPODCustom1, VS4TPO.TPODCustom2, VS4TPO.TPODCustom3, VS4TPO.TPODCustom4, VS4TPO.TPODCustom5,                    VS4TPO.TPODTPOTCode, VS4TPO.TPODLinkStatus, VS4TPO.TPODInvoiceStatus, VS4TPO.TPODDeliveryStatus, VS4TPO.TPODFinishDate, VS4TPO.TPODCreateBy, VS4TPO.TPODCreateDate,                    VS4TPO.TPODEditCode, VS4TPO.TPODEditBy, VS4TPO.TPODEditDate, VS4TPO.TPODConfirmStatus, VS4TPO.TPODConfirmBy, VS4TPO.TPODConfirmDate, VS4TPO.TPODApproveStatus,                    VS4TPO.TPODApproveBy, VS4TPO.TPODApproveDate, VS4TPO.TPODApproveNote, VS4TPO.TPODRevision, VS4TPO.TPODCancelStatus, VS4TPO.TPODCancelBy, VS4TPO.TPODCancelDate,                    VS4TPO.TPODCancelNote, VS4TPO.TPODFlag1, VS4TPO.TPODConditionType, VS4TPO.TPODLoadingDate, VS4TPO.TPODStartAgingDate, VS4TPO.TPODArrears, VS4TPO.TPODNote,                    VS4TPO.TPODToTBraCode, VS4TPO.TPODBalanceFlag, VS4TPO.TPODHireWork, VS4TPOMB.TPOBTPODNo, VS4TPOMB.TPOBLn, VS4TPOMB.TPOBType, VS4TPOMB.TPOBJobCode,                    VS4TPOMB.TPOBGroupName, VS4TPOMB.TPOBTOExCode, VS4TPOMB.TPOBTPdtCode, VS4TPOMB.TPOBCustom1, VS4TPOMB.TPOBCustom2, VS4TPOMB.TPOBCustom3, VS4TPOMB.TPOBCustom4,                    VS4TPOMB.TPOBCustom5, VS4TPOMB.TPOBShippingMark, VS4TPOMB.TPOBProductCode, VS4TPOMB.TPOBFactoryCode, VS4TPOMB.TPOBProductName, VS4TPOMB.TPOBUseBom,                    VS4TPOMB.TPOBDeliveryDate, VS4TPOMB.TPOBDeliveryTime, VS4TPOMB.TPOBMinimumOrder, VS4TPOMB.TPOBCost, VS4TPOMB.TPOBPrice, VS4TPOMB.TPOBPerQuantity, VS4TPOMB.TPOBUnitFactor,                    VS4TPOMB.TPOBAcceptError, VS4TPOMB.TPOBUnitCalc, VS4TPOMB.TPOBQuantityCalc, VS4TPOMB.TPOBQuantityText, VS4TPOMB.TPOBQuantity, VS4TPOMB.TPOBTUntCode, VS4TPOMB.TPOBQuantity2,                    VS4TPOMB.TPOBTUntCode2, VS4TPOMB.TPOBQuantity3, VS4TPOMB.TPOBTUntCode3, VS4TPOMB.TPOBDutyAmount, VS4TPOMB.TPOBDivideExpense, VS4TPOMB.TPOBCostAmount,                    VS4TPOMB.TPOBAmount, VS4TPOMB.TPOBDiscountText, VS4TPOMB.TPOBDiscountTotal, VS4TPOMB.TPOBNetAmount, VS4TPOMB.TPOBTaxType, VS4TPOMB.TPOBTaxBase, VS4TPOMB.TPOBWTAXBase,                    VS4TPOMB.TPOBAmountVAT, VS4TPOMB.TPOBAmountWTAX, VS4TPOMB.TPOBAutoSTD, VS4TPOMB.TPOBStandardCost, VS4TPOMB.TPOBMargin, VS4TPOMB.TPOBSaleMargin,                    VS4TPOMB.TPOBAutoPrice, VS4TPOMB.TPOBSalePrice, VS4TPOMB.TPOBGetNumber, VS4TPOMB.TPOBFreeCode, VS4TPOMB.TPOBIsPremium, VS4TPOMB.TPOBDescription, VS4TPOMB.TPOBSourceNo,                    VS4TPOMB.TPOBSourceLn, VS4TPOMB.TPOBStatus, VS4TPOMB.TPOBStockTotal, VS4TPOMB.TPOBPRArrear, VS4TPOMB.TPOBEOQ, VS4TPOMB.TPOBTotalDelivery, VS4TPOMB.TPOBTotalDelivery2,                    VS4TPOMB.TPOBTotalDelivery3, VS4TPOMB.TPOBTotalArrear, VS4TPOMB.TPOBTotalArrear2, VS4TPOMB.TPOBTotalArrear3, VS4TPOMB.TPOBMapTPdtCode, VS4TPOMB.TPOBDayProcess,                    VS4TPOMB.TPOBTLctCode, VS4TPOMB.TPOBManualClose, VS4TPOMB.TPOBFlag1, VS4TPOMB.TPOBMapRatioP, VS4TPOMB.TPOBQuantityCost, VS4TPOMB.TPOBTotalInv2, VS4TPOMB.TPOBTotalInv3,                    VS4TPOMB.TPOBTotalInv, VS4TPOMB.TPOBTotalInvArr, VS4TPOMB.TPOBTotalInvArr2, VS4TPOMB.TPOBTotalInvArr3, VS4TPOMB.TPOBBaseArrears, VS4TPOMB.TPOBBaseInvArr,                    VS4TPOMB.TPOBQuantityBase, VS4TPOMB.TPOBCloseStatus, VS4TProject.TPrjName, VS4TPODelivery.TPDETPOBTPODNo, VS4TPODelivery.TPDETPOBLn, VS4TPODelivery.TPDELn,                    VS4TPODelivery.TPDEProductCode, VS4TPODelivery.TPDEProductName, VS4TPODelivery.TPDEDate, VS4TPODelivery.TPDEDateTime, VS4TPODelivery.TPDEQuantity, VS4TPODelivery.TPDEQuantity2,                    VS4TPODelivery.TPDEQuantity3, VS4TPODelivery.TPDEUnitCode, VS4TPODelivery.TPDEUnitCode2, VS4TPODelivery.TPDEUnitCode3, VS4TPODelivery.TPDETotalDelivery, VS4TPODelivery.TPDETotalDelivery2,                    VS4TPODelivery.TPDETotalDelivery3, VS4TPODelivery.TPDETotalArrear, VS4TPODelivery.TPDETotalArrear2, VS4TPODelivery.TPDETotalArrear3, VS4TPODelivery.TPDEUnitCalc,                    VS4TPODelivery.TPDEMapTPdtCode, VS4TPODelivery.TPDEMapTUntCode, VS4TPODelivery.TPDEMapUnitRatio, VS4TPODelivery.TPDEQuantityBase, VS4TPODelivery.TPDEDeliveryBase,                    VS4TPODelivery.TPDEArrearBase, VS4TPODelivery.TPDELinkStatus, VS4TPODelivery.TPDELinkBy, VS4TPODelivery.TPDELinkDate, VS4TPODelivery.TPDETotalOntime, VS4TPODelivery.TPDETotalDelay,                    VS4TPODelivery.TPDETLctCode, VS4TPODelivery.TPDEFlag1, VS4TPODelivery.TPDETotalInv2, VS4TPODelivery.TPDETotalInv3, VS4TPODelivery.TPDETotalInv, VS4TPODelivery.TPDETotalInvArr,                    VS4TPODelivery.TPDETotalInvArr2, VS4TPODelivery.TPDETotalInvArr3, VS4TPODelivery.TPDECloseStatus, VS4TAP.TAPNName, VS4TBranch.TBraName, VS4TProduct.TPdtName, VS4TProduct.TPdtName2,                    VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TPR.TPRDTSecCode, VS4TPR.TPRDTDepCode, VS4TPR.TPRDTDivCode, VS4TPOMBAOL.TPOATBraCode,                    VS4TPOMBAOL.TPOATPrjCode, VS4TPOMBAOL.TPOATDivCode, VS4TPOMBAOL.TPOATDepCode, VS4TPOMBAOL.TPOATSecCode, VS4TPO2.TPO2ETDDate, VS4TPO2.TPO2ETADate,                    VS4TPO2.TPO2EXWDate, VS4TAP.TAPNTCouCode, VS4TDepartment.TDepName FROM     VS4TPR LEFT OUTER JOIN                   VS4TDepartment ON VS4TPR.TPRDTDepCode = VS4TDepartment.TDepCode RIGHT OUTER JOIN                   VS4TAP INNER JOIN                   VS4TPO LEFT OUTER JOIN                   VS4TProject ON VS4TPO.TPODTPrjCode = VS4TProject.TPrjCode LEFT OUTER JOIN                   VS4TBranch ON VS4TPO.TPODTBraCode = VS4TBranch.TBraCode LEFT OUTER JOIN                   VS4TPO2 ON VS4TPO.TPODNo = VS4TPO2.TPO2TPODNo ON VS4TAP.TAPNCode = VS4TPO.TPODTAPNCode INNER JOIN                   VS4TPOMB INNER JOIN                   VS4TPODelivery ON VS4TPOMB.TPOBLn = VS4TPODelivery.TPDETPOBLn AND VS4TPOMB.TPOBTPODNo = VS4TPODelivery.TPDETPOBTPODNo LEFT OUTER JOIN                   VS4TProduct ON VS4TPODelivery.TPDEMapTPdtCode = VS4TProduct.TPdtCode LEFT OUTER JOIN                   VS4TPRMB ON VS4TPOMB.TPOBSourceNo = VS4TPRMB.TPRMTPRDNo AND VS4TPOMB.TPOBSourceLn = VS4TPRMB.TPRMLn LEFT OUTER JOIN                   VS4TPOMBAOL ON VS4TPOMB.TPOBTPODNo = VS4TPOMBAOL.TPOATPOBTPODNo AND VS4TPOMB.TPOBLn = VS4TPOMBAOL.TPOATPOBLn ON VS4TPO.TPODNo = VS4TPOMB.TPOBTPODNo ON                    VS4TPR.TPRDNo = VS4TPRMB.TPRMTPRDNo
GO

CREATE VIEW VS4VPODeliveryMail AS SELECT DISTINCT                           VS4TPO.TPODNo, VS4TPO.TPODDate, VS4TAP.TAPNTCouCode, VS4TEmployee.TEmpEmail, VS4TEmployee_1.TEmpEmail AS VPDEPREmail, VS4TAP.TAPNEmail, VS4TPODelivery.TPDEDate,                           VS4TPODelivery.TPDETotalArrear, VS4TPODelivery.TPDETotalDelivery, VS4TPO.TPODSupplierName FROM            VS4TEmployee AS VS4TEmployee_1 RIGHT OUTER JOIN                          VS4TPR ON VS4TEmployee_1.TEmpCode = VS4TPR.TPRDEditCode RIGHT OUTER JOIN                          VS4TPO INNER JOIN                          VS4TPOMB ON VS4TPO.TPODNo = VS4TPOMB.TPOBTPODNo INNER JOIN                          VS4TAP ON VS4TPO.TPODTAPNCode = VS4TAP.TAPNCode INNER JOIN                          VS4TPODelivery ON VS4TPOMB.TPOBTPODNo = VS4TPODelivery.TPDETPOBTPODNo AND VS4TPOMB.TPOBLn = VS4TPODelivery.TPDETPOBLn INNER JOIN                          VS4TEmployee ON VS4TPO.TPODEditCode = VS4TEmployee.TEmpCode ON VS4TPR.TPRDNo = VS4TPOMB.TPOBSourceNo WHERE        (VS4TPO.TPODApproveStatus = 1) AND (VS4TPO.TPODCancelStatus = 0)
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, VS4TAP.TAPNTBsTCode, VS4TBusinessType.TBstName, VS4TAPGroup.TAPGName, VS4TPO2.TPO2Acknowledge, VS4TPO2.TPO2AcknowDate, VS4TJob.TJobTARNCode, VS4TJob.TJobCustomerName, VS4TPO2.TPO2ETDDate, VS4TPO2.TPO2ETADate, VS4TPO2.TPO2StatusNote, VS4TPO2.TPO2DeliveryStatus, VS4TPO2.TPO2Status, VS4TPO2.TPO2Complaint, VS4TPO2.TPO2EXWDate 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) LEFT JOIN VS4TPO2 ON VS4TPO.TPODNo = VS4TPO2.TPO2TPODNo) LEFT JOIN VS4TJob ON VS4TPO.TPODTJobNo = VS4TJob.TJobNo) ON VS4TAP.TAPNCode = VS4TPO.TPODTAPNCode
GO

CREATE VIEW VS4VPointOnHand AS  SELECT TPoiTARNCode, TARNName, TAR3NickName, TAR3CitizenNo, TARNCardNo, TARNAddressBill, TARNEmail, TARNPhone, TARNMobile, TARNFax, SUM(TPoTQuantity) AS VPoTQuantity FROM (SELECT VS4TPoint.TPoiTARNCode, VS4TAR.TARNName, TAR3CitizenNo, VS4TAR.TARNCardNo, TAR3NickName, TARNAddressBill, TARNEmail, TARNPhone, TARNMobile, TARNFax, VS4TPointTransMB.TPoTQuantity, VS4TPoint.TPoiExpireDate, VS4TPoint.TPoiExpireDate2 FROM ((VS4TPoint LEFT JOIN VS4TAR ON VS4TPoint.TPoiTARNCode = VS4TAR.TARNCode) INNER JOIN (VS4TPointTrans INNER JOIN VS4TPointTransMB ON VS4TPointTrans.TPiTNo = VS4TPointTransMB.TPoTTPiTNo) ON VS4TPoint.TPoiID = VS4TPointTransMB.TPoTTPoiID) LEFT JOIN VS4TAR3 ON VS4TAR.TARNCode = VS4TAR3.TAR3TARNCode WHERE (((VS4TPointTrans.TPiTApproveStatus)=1) AND ((VS4TPointTrans.TPiTCancelStatus)=0))  AND  TPoiValidDate<='2400-08-20' AND  TPoiExpireDate2>'2000-01-01' AND TPoiTARNCode<>'') AS VS4VPointONHand GROUP BY TPoiTARNCode, TARNName, TAR3CitizenNo, TARNCardNo, TAR3NickName, TARNAddressBill, TARNEmail, TARNPhone, TARNMobile, TARNFax
GO

CREATE VIEW VS4VPointOnHandDT AS  SELECT TPoiTARNCode, TARNName, SUM(TPoTQuantity) AS VPoTQuantity, TPoiID FROM (SELECT VS4TPoint.TPoiTARNCode, VS4TAR.TARNName, VS4TPointTransMB.TPoTQuantity, VS4TPoint.TPoiID, VS4TPoint.TPoiExpireDate, VS4TPoint.TPoiExpireDate2 FROM (VS4TPoint LEFT JOIN VS4TAR ON VS4TPoint.TPoiTARNCode = VS4TAR.TARNCode) INNER JOIN (VS4TPointTrans INNER JOIN VS4TPointTransMB ON VS4TPointTrans.TPiTNo = VS4TPointTransMB.TPoTTPiTNo) ON VS4TPoint.TPoiID = VS4TPointTransMB.TPoTTPoiID WHERE (((VS4TPointTrans.TPiTApproveStatus)=1) AND ((VS4TPointTrans.TPiTCancelStatus)=0))  AND  TPoiValidDate<='2400-08-20' AND  TPoiExpireDate2>'2000-01-01' AND TPoiTARNCode<>'' AND  TPiTNo<>'') AS VS4VPointOnHandDT GROUP BY TPoiTARNCode, TARNName, TPoiID HAVING SUM(TPoTQuantity) > 0
GO

CREATE VIEW VS4VPointTrans AS  SELECT VS4TPointTrans.*, VS4TPointTransMB.*, VS4TPointBook.*, VS4TPoint.*, VS4TAR.*, VS4TAR_1.TARNName AS VPoiTARNName, VS4TAR_1.TARNName2 AS VPoiTARNName2, VS4TAR_2.TARNName AS VPoiToTARNName, VS4TAR_3.TARNName AS VPoiFromTARNName, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtStartDate, VS4TProduct.TPdtEndDate, VS4TAR_2.TARNCardNo AS VPoiToTARNCardNo, VS4TAR_3.TARNCardNo AS VPoiFromTARNCardNo, VS4TAR3.TAR3CitizenNo FROM (((VS4TPoint LEFT JOIN VS4TAR AS VS4TAR_1 ON VS4TPoint.TPoiTARNCode = VS4TAR_1.TARNCode) LEFT JOIN VS4TProduct ON VS4TPoint.TPoiTPdtCode = VS4TProduct.TPdtCode) INNER JOIN ((VS4TPointBook INNER JOIN (VS4TPointTrans LEFT JOIN VS4TAR ON VS4TPointTrans.TPiTTARNCode = VS4TAR.TARNCode) ON VS4TPointBook.TPikCode = VS4TPointTrans.TPiTPiKCode) INNER JOIN ((VS4TPointTransMB LEFT JOIN VS4TAR AS VS4TAR_2 ON VS4TPointTransMB.TPoTTARNCode = VS4TAR_2.TARNCode) LEFT JOIN VS4TAR AS VS4TAR_3 ON VS4TPointTransMB.TPoTFromTARNCode = VS4TAR_3.TARNCode) ON VS4TPointTrans.TPiTNo = VS4TPointTransMB.TPoTTPiTNo) ON VS4TPoint.TPoiID = VS4TPointTransMB.TPoTTPoiID) LEFT JOIN VS4TAR3 ON VS4TAR.TARNCode = VS4TAR3.TAR3TARNCode
GO

CREATE VIEW VS4VPointTransH AS  SELECT VS4TPointTrans.*, VS4TPointBook.*, VS4TAR.*, VS4TAR3.TAR3CitizenNo FROM (VS4TPointBook INNER JOIN (VS4TPointTrans LEFT JOIN VS4TAR ON VS4TPointTrans.TPiTTARNCode = VS4TAR.TARNCode) ON VS4TPointBook.TPikCode = VS4TPointTrans.TPiTPiKCode) LEFT JOIN VS4TAR3 ON VS4TAR.TARNCode = VS4TAR3.TAR3TARNCode
GO

CREATE VIEW VS4VPointTransSum AS  SELECT VS4TPointTransMB.TPoTTPiTNo, VS4TPointTransMB.TPoTFromTARNCode, VS4TPointTransMB.TPoTTARNCode, VS4TAR_2.TARNName, VS4TProduct.TPdtCode, VS4TProduct.TPdtTUntCode, Sum(VS4TPointTransMB.TPoTQuantity) AS TPoTQuantity, VS4TPointTransMB.TPoTUseDate, VS4TPointTransMB.TPoTDescription FROM VS4TPoint INNER JOIN (((VS4TPointTransMB LEFT JOIN VS4TAR AS VS4TAR_2 ON VS4TPointTransMB.TPoTTARNCode = VS4TAR_2.TARNCode) LEFT JOIN VS4TAR AS VS4TAR_3 ON VS4TPointTransMB.TPoTFromTARNCode = VS4TAR_3.TARNCode) LEFT JOIN VS4TProduct ON VS4TPointTransMB.TPoTTPdtCode = VS4TProduct.TPdtCode) ON VS4TPoint.TPoiID = VS4TPointTransMB.TPoTTPoiID GROUP BY VS4TPointTransMB.TPoTTPiTNo, VS4TPointTransMB.TPoTFromTARNCode, VS4TPointTransMB.TPoTTARNCode, VS4TAR_2.TARNName, VS4TProduct.TPdtCode, VS4TProduct.TPdtTUntCode, VS4TPointTransMB.TPoTUseDate, VS4TPointTransMB.TPoTDescription
GO

CREATE VIEW VS4VPOMail AS SELECT        VS4TPO.TPODNo, VS4TAP.TAPNTCouCode, VS4TPO.TPODDate, VS4TEmployee.TEmpEmail, VS4TAP.TAPNEmail, VS4TPO2.TPO2Acknowledge, VS4TPO2.TPO2AcknowDate,                           VS4TPO.TPODDeliveryStatus, VS4TPO.TPODSupplierName, VS4TPO.TPODApproveDate FROM            VS4TPO INNER JOIN                          VS4TAP ON VS4TPO.TPODTAPNCode = VS4TAP.TAPNCode LEFT OUTER JOIN                          VS4TPO2 ON VS4TPO.TPODNo = VS4TPO2.TPO2TPODNo LEFT OUTER JOIN                          VS4TEmployee ON VS4TPO.TPODEditCode = VS4TEmployee.TEmpCode WHERE        (VS4TPO.TPODApproveStatus = 1) AND (VS4TPO.TPODCancelStatus = 0) AND (VS4TPO2.TPO2Acknowledge = N'' OR                          VS4TPO2.TPO2Acknowledge IS NULL)
GO

CREATE VIEW VS4VPOMB AS  SELECT VS4TPOMB.*, VS4TProject.TPrjName, 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, 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, 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, VS4TPOMBAOL.TPOATBraCode, VS4TPOMBAOL.TPOATPrjCode, VS4TPOMBAOL.TPOATDivCode, VS4TPOMBAOL.TPOATDepCode, VS4TPOMBAOL.TPOATSecCode, VS4TPOMBAOL.TPOATSZGCode, VS4TPOMBAOL.TPOATSZnCode, VS4TPOMBAOL.TPOATSAeCode, VS4TPOMBAOL.TPOATARNCode, VS4TPOMBAOL.TPOATAPNCode, VS4TPOMBAOL.TPOATAssCode, VS4TPOMBAOL.TPOATEmpCode, VS4TPOMBAOL.TPOATPdtCode, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TPO.TPODTAPNCode, VS4TPO.TPODSupplierName 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.TPOBSourceLn = VS4TPRMB.TPRMLn) AND (VS4TPOMB.TPOBSourceNo = VS4TPRMB.TPRMTPRDNo)) 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) LEFT JOIN VS4TPOMBAOL ON (VS4TPOMB.TPOBLn = VS4TPOMBAOL.TPOATPOBLn) AND (VS4TPOMB.TPOBTPODNo = VS4TPOMBAOL.TPOATPOBTPODNo)) ON VS4TPO.TPODNo = VS4TPOMB.TPOBTPODNo) ON VS4TPR.TPRDNo = VS4TPRMB.TPRMTPRDNo
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, VS4TBranch.TBraName, VS4TEmployee.TEmpAliasName, VS4TEmployee_1.TEmpAliasName AS VPPDEditBy, VS4TEmployee.TEmpAliasName AS VPPDWeightBy, VS4TProject.TPrjTEmpCode, VS4TEmployee_2.TEmpFullName, VS4TAP.TAPNName2, VS4TAR.TARNName2, VS4TAR.TARNAddressBill2, VS4TAP.TAPNAddressBill2, VS4TAR.TARNAddress2, VS4TPOPBook.TPPKCode, VS4TPOPBook.TPPKName, VS4TPOPBook.TPPKName2, VS4TVehicleType.TVeTName, VS4TAR_1.TARNName AS VPOPFromName, VS4TAR_1.TARNName2 AS VPOPFromName2, VS4TAR_2.TARNName AS VPOPToName, VS4TAR_2.TARNName2 AS VPOPToName2, VS4TProduct.TPdtCode, VS4TProduct.TPdtName, VS4TProduct.TPdtTUntCode, VS4TAR.TARNName, VS4TAP.TAPNName, VS4TProduct.TPdtTBndCode, VS4TBrand.TBndName, VS4TProduct.TPdtTAPNCode FROM VS4TVehicleType RIGHT JOIN ((VS4TProject LEFT JOIN VS4TEmployee AS VS4TEmployee_2 ON VS4TProject.TPrjTEmpCode = VS4TEmployee_2.TEmpCode) RIGHT JOIN (((VS4TProduct LEFT JOIN VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode) LEFT JOIN VS4TBrand ON VS4TProduct.TPdtTBndCode = VS4TBrand.TBndCode) RIGHT JOIN ((VS4TPOPBook 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 VS4TAP ON VS4TPOPTrans.TPPDTAPNCode = VS4TAP.TAPNCode) LEFT JOIN VS4TAR ON VS4TPOPTrans.TPPDTAPNCode = VS4TAR.TARNCode) LEFT JOIN VS4TAR AS VS4TAR_1 ON VS4TPOPTrans.TPPDFROMTARNCode = VS4TAR_1.TARNCode) LEFT JOIN VS4TAR AS VS4TAR_2 ON VS4TPOPTrans.TPPDTOTARNCode = VS4TAR_2.TARNCode) ON VS4TPOPBook.TPPKCode = VS4TPOPTrans.TPPDTPPKCode) 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) ON VS4TVehicleType.TVeTCode = VS4TPOPTrans.TPPDTVeTCode
GO

CREATE VIEW VS4VPOPTransH AS  SELECT VS4TPOPTrans.*, VS4TProject.TPrjName, VS4TBranch.TBraName, VS4TProject.TPrjTEmpCode, VS4TEmployee.TEmpFullName, VS4TPOPBook.TPPKCode, VS4TPOPBook.TPPKName, VS4TPOPBook.TPPKName2, VS4TVehicleType.TVeTName, VS4TPOPTransMB.TPTBTPdtCode, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TPOPTransMB.TPTBUnitPrice, VS4TAP.TAPNName, VS4TAP.TAPNName2, VS4TAR.TARNName, VS4TAR.TARNName2 FROM VS4TVehicleType RIGHT JOIN ((VS4TProject LEFT JOIN VS4TEmployee ON VS4TProject.TPrjTEmpCode = VS4TEmployee.TEmpCode) RIGHT JOIN (VS4TProduct RIGHT JOIN ((VS4TPOPBook RIGHT JOIN (((VS4TPOPTrans LEFT JOIN VS4TBranch ON VS4TPOPTrans.TPPDTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TAP ON VS4TPOPTrans.TPPDTAPNCode = VS4TAP.TAPNCode) LEFT JOIN VS4TAR ON VS4TPOPTrans.TPPDTAPNCode = VS4TAR.TARNCode) ON VS4TPOPBook.TPPKCode = VS4TPOPTrans.TPPDTPPKCode) LEFT JOIN VS4TPOPTransMB ON VS4TPOPTrans.TPPDNo = VS4TPOPTransMB.TPTBTPPDNo) ON VS4TProduct.TPdtCode = VS4TPOPTransMB.TPTBTPdtCode) ON VS4TProject.TPrjCode = VS4TPOPTrans.TPPDTPrjCode) ON VS4TVehicleType.TVeTCode = VS4TPOPTrans.TPPDTVeTCode WHERE (((VS4TPOPTransMB.TPTBLn)=1 Or (VS4TPOPTransMB.TPTBLn) Is Null))
GO

CREATE VIEW VS4VPOPTransMBDisc AS SELECT VS4TPOPTrans.*, VS4TPOPTransMB.*, VS4TPOPTransMBDisc.*, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TPOPScrap.TPScName, VS4TPOPScrap.TPScName2 FROM VS4TProduct INNER JOIN (VS4TPOPTrans INNER JOIN ((VS4TPOPTransMB INNER JOIN VS4TPOPTransMBDisc ON (VS4TPOPTransMB.TPTBLn = VS4TPOPTransMBDisc.TPTDTPTBLn) AND (VS4TPOPTransMB.TPTBBalanceNo = VS4TPOPTransMBDisc.TPTDTPTBBalanceNo) AND (VS4TPOPTransMB.TPTBTPPDNo = VS4TPOPTransMBDisc.TPTDTPTBTPPDNo)) LEFT JOIN VS4TPOPScrap ON VS4TPOPTransMBDisc.TPTDTPScCode = VS4TPOPScrap.TPScCode) ON VS4TPOPTrans.TPPDNo = VS4TPOPTransMB.TPTBTPPDNo) ON VS4TProduct.TPdtCode = VS4TPOPTransMB.TPTBTPdtCode
GO

CREATE VIEW VS4VPOR AS  SELECT VS4TPO.TPODNo, VS4TPO.TPODTPOkCode, VS4TPO.TPODTPCACode, VS4TPO.TPODMode, VS4TPO.TPODDOArrears, VS4TPO.TPODType, VS4TPO.TPODDate, VS4TPO.TPODRefNo, VS4TPO.TPODRefDate, VS4TPO.TPODRefNo2, VS4TPO.TPODTJobNo, VS4TPO.TPODTJbMLn, VS4TPO.TPODTPrjCode, VS4TPO.TPODTBraCode, VS4TPO.TPODDeliveryDate, VS4TPO.TPODDeliveryTo, VS4TPO.TPODTAPNCode, VS4TPO.TPODTAPUCode, VS4TPO.TPODContactNote, VS4TPO.TPODContactName, VS4TPO.TPODSupplierName, VS4TPO.TPODSupAddress, VS4TPO.TPODConsignee, VS4TPO.TPODNotifyParty, VS4TPO.TPODPriceChannel, VS4TPO.TPODDiscountList, VS4TPO.TPODSubTotal, VS4TPO.TPODDiscountText, VS4TPO.TPODDiscountTotal, VS4TPO.TPODNetTotal, VS4TPO.TPODDepositText, VS4TPO.TPODDeposit, VS4TPO.TPODTotal, VS4TPO.TPODTotalFOB, VS4TPO.TPODTCurCode, VS4TPO.TPODExchangeRate, VS4TPO.TPODTotalInRate, VS4TPO.TPODVATType, VS4TPO.TPODVATRate, VS4TPO.TPODTaxBase, VS4TPO.TPODVATTotal, VS4TPO.TPODGrandTotal, VS4TPO.TPODNOTAXTotal, VS4TPO.TPODWTaxBase, VS4TPO.TPODWTaxRate, VS4TPO.TPODWTaxTotal, VS4TPO.TPODNetPayment, VS4TPO.TPODAdjustTotal, VS4TPO.TPODPremiumTotal, VS4TPO.TPODBaseIncoType, VS4TPO.TPODIncoType, VS4TPO.TPODIncoterms, VS4TPO.TPODOtherFee, VS4TPO.TPODTransportFee, VS4TPO.TPODHandlingFee, VS4TPO.TPODFreightFee, VS4TPO.TPODInsurance, VS4TPO.TPODTransportDesc, VS4TPO.TPODDuty, VS4TPO.TPODShipBy, VS4TPO.TPODCountryOrigin, VS4TPO.TPODDestination, VS4TPO.TPODCondition, VS4TPO.TPODConditionDay, VS4TPO.TPODCondition1, VS4TPO.TPODConditionDay1, VS4TPO.TPODPaymentNote, VS4TPO.TPODStatementNote, VS4TPO.TPODTShpCode, VS4TPO.TPODDeliveryNote, VS4TPO.TPODPackingNote, VS4TPO.TPODDayAvailable, VS4TPO.TPODDescription, VS4TPO.TPODCustom1, VS4TPO.TPODCustom2, VS4TPO.TPODCustom3, VS4TPO.TPODCustom4, VS4TPO.TPODCustom5, VS4TPO.TPODTPOTCode, VS4TPO.TPODLinkStatus, VS4TPO.TPODInvoiceStatus, VS4TPO.TPODDeliveryStatus, VS4TPO.TPODFinishDate, VS4TPO.TPODCreateBy, VS4TPO.TPODEditCode, VS4TPO.TPODEditBy, VS4TPO.TPODEditDate, VS4TPO.TPODConfirmStatus, VS4TPO.TPODConfirmBy, VS4TPO.TPODConfirmDate, VS4TPO.TPODApproveStatus, VS4TPO.TPODApproveBy, VS4TPO.TPODApproveDate, VS4TPO.TPODRevision, VS4TPO.TPODCancelStatus, VS4TPO.TPODCancelBy, VS4TPO.TPODCancelDate, VS4TPO.TPODCancelNote, VS4TPO.TPODFlag1, VS4TPO.TPODConditionType, VS4TPO.TPODLoadingDate, VS4TPO.TPODArrears, VS4TPO.TPODNote, VS4TPOMB.TPOBTPODNo, VS4TPOMB.TPOBLn, VS4TPOMB.TPOBType, VS4TPOMB.TPOBJobCode, VS4TPOMB.TPOBGroupName, VS4TPOMB.TPOBTOExCode, VS4TPOMB.TPOBTPdtCode, VS4TPOMB.TPOBCustom1, VS4TPOMB.TPOBCustom2, VS4TPOMB.TPOBCustom3, VS4TPOMB.TPOBCustom4, VS4TPOMB.TPOBCustom5, VS4TPOMB.TPOBShippingMark, VS4TPOMB.TPOBProductCode, VS4TPOMB.TPOBFactoryCode, VS4TPOMB.TPOBProductName, VS4TPOMB.TPOBUseBom, VS4TPOMB.TPOBDeliveryDate, VS4TPOMB.TPOBDeliveryTime, VS4TPOMB.TPOBMinimumOrder, VS4TPOMB.TPOBCost, VS4TPOMB.TPOBPrice, VS4TPOMB.TPOBPerQuantity, VS4TPOMB.TPOBUnitFactor, VS4TPOMB.TPOBAcceptError, VS4TPOMB.TPOBUnitCalc, VS4TPOMB.TPOBQuantityCalc, VS4TPOMB.TPOBQuantityText, VS4TPOMB.TPOBQuantity, VS4TPOMB.TPOBTUntCode, VS4TPOMB.TPOBQuantity2, VS4TPOMB.TPOBTUntCode2, VS4TPOMB.TPOBQuantity3, VS4TPOMB.TPOBTUntCode3, VS4TPOMB.TPOBDutyAmount, VS4TPOMB.TPOBDivideExpense, VS4TPOMB.TPOBCostAmount, VS4TPOMB.TPOBAmount, VS4TPOMB.TPOBDiscountText, VS4TPOMB.TPOBDiscountTotal, VS4TPOMB.TPOBNetAmount, VS4TPOMB.TPOBTaxType, VS4TPOMB.TPOBTaxBase, VS4TPOMB.TPOBWTAXBase, VS4TPOMB.TPOBAmountVAT, VS4TPOMB.TPOBAmountWTAX, VS4TPOMB.TPOBAutoSTD, VS4TPOMB.TPOBStandardCost, VS4TPOMB.TPOBMargin, VS4TPOMB.TPOBSaleMargin, VS4TPOMB.TPOBSalePrice, VS4TPOMB.TPOBGetNumber, VS4TPOMB.TPOBFreeCode, VS4TPOMB.TPOBIsPremium, VS4TPOMB.TPOBDescription, VS4TPOMB.TPOBSourceNo, VS4TPOMB.TPOBSourceLn, VS4TPOMB.TPOBStatus, VS4TPOMB.TPOBFlag1, VS4TPOMB.TPOBStockTotal, VS4TPOMB.TPOBPRArrear, VS4TPOMB.TPOBEOQ, VS4TPOMB.TPOBTotalDelivery, VS4TPOMB.TPOBTotalDelivery2, VS4TPOMB.TPOBTotalDelivery3, VS4TPOMB.TPOBTotalArrear, VS4TPOMB.TPOBTotalArrear2, VS4TPOMB.TPOBTotalArrear3, VS4TPOMB.TPOBMapTPdtCode, VS4TPOMB.TPOBMapTUntCode, VS4TPOMB.TPOBDayProcess, VS4TPOMB.TPOBTLctCode, VS4TPOMB.TPOBManualClose, VS4TPOMB.TPOBMapRatioP, VS4TPOMB.TPOBQuantityCost, VS4TPOMB.TPOBTotalInv, VS4TPOMB.TPOBTotalInv2, VS4TPOMB.TPOBTotalInv3, 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, 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_1.TPdtName AS VPODTPdtName, VS4TProduct_1.TPdtTUntCode AS VPODTPdtTuntCode, VS4TProduct_1.TPdtTUntCode2 AS VPODTPdtTuntCode2, VS4TProduct_1.TPdtTUntCode3 AS VPODTPdtTuntCode3, VS4TBranch.TBraAddressBill, VS4TAP.TAPNAddressBill2, VS4TProduct.TPdtRequireCOA, VS4TPO.TPODFlag2, VS4TProductSection.TPSEName2, VS4TPO.TPODCreateDate, VS4TProduct.TPdtBarcode, VS4TProduct.TPdtEOQ, VS4TPOMBAOL.TPOATBraCode, VS4TPOMBAOL.TPOATDivCode, VS4TPOMBAOL.TPOATDepCode, VS4TPOMBAOL.TPOATSecCode, VS4TPOMBAOL.TPOATEmpCode, VS4TPO2.TPO2StatusNote, VS4TPO2.TPO2Complaint, VS4TPO2.TPO2Status, VS4TPR.TPRDRequestBy 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) LEFT JOIN VS4TPO2 ON VS4TPO.TPODNo = VS4TPO2.TPO2TPODNo) ON VS4TAP.TAPNCode = VS4TPO.TPODTAPNCode) ON VS4TCountry.TCouCode = VS4TAP.TAPNTCouCode) INNER JOIN (((((((((((VS4TPOMB LEFT JOIN VS4TPRMB ON (VS4TPOMB.TPOBSourceLn = VS4TPRMB.TPRMLn) AND (VS4TPOMB.TPOBSourceNo = VS4TPRMB.TPRMTPRDNo)) 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) LEFT JOIN VS4TPOMBAOL ON (VS4TPOMB.TPOBLn = VS4TPOMBAOL.TPOATPOBLn) AND (VS4TPOMB.TPOBTPODNo = VS4TPOMBAOL.TPOATPOBTPODNo)) ON VS4TPO.TPODNo = VS4TPOMB.TPOBTPODNo) ON VS4TPR.TPRDNo = VS4TPRMB.TPRMTPRDNo
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) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode
GO

CREATE VIEW VS4VPOSTransEmp AS  SELECT VS4TPOSTrans.*, 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, 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, VS4TFlight.TFLiEmpCodeList, VS4TFlight.TFLiEmpNameList, VS4TFlight.TFLiGuildCodeList, VS4TFlight.TFLiGuildNameList, VS4TFlight.TFliTotalDriver, VS4TFlight.TFliTotalGPark, VS4TFlight.TFliTourLeader, VS4TFlight.TFliTotalPAX, VS4TFlight.TFliDateTime, VS4TFlight.TFliNote, (SELECT SUM(TPPyAmount) FROM VS4TPOSTranspay WHERE VS4TPOSTranspay.TPPyTPTANo=VS4TPOSTrans.TPTANo AND TPPyPaymentType='CARD') AS VPTAReceiveCard, (SELECT SUM(TPPyAmount) FROM VS4TPOSTranspay WHERE VS4TPOSTranspay.TPPyTPTANo=VS4TPOSTrans.TPTANo AND TPPyPaymentType<>'CARD') AS VPTAReceiveCash, (SELECT SUM(TPPyAmount) FROM VS4TPOSTranspay WHERE VS4TPOSTranspay.TPPyTPTANo=VS4TPOSTrans.TPTANo AND TPPyPaymentType<>'CARD' AND TPpyISchange=1) AS VPTACashOut, VS4TFlight.TFliNo, VS4TFlight.TFliParkNo, VS4TFlight.TFliCardNo, VS4TPOSTransEmp.*, VS4TEmployeeGroup.TEmGName FROM (((VS4TSaleZone LEFT JOIN VS4TSaleZoneGroup ON VS4TSaleZone.TSZnTSZGCode = VS4TSaleZoneGroup.TSZGCode) RIGHT 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.TPTATAPUCode = VS4TAPBranch.TAPUCode) AND (VS4TPOSTrans.TPTATAPNCode = VS4TAPBranch.TAPUTAPNCode)) LEFT JOIN VS4TFlight ON (VS4TPOSTrans.TPTAParkNo = VS4TFlight.TFliParkNo) AND (VS4TPOSTrans.TPTADate = VS4TFlight.TFliDate)) 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) ON VS4TSaleZone.TSZnCode = VS4TSaleArea.TSaeTSZnCode) INNER JOIN VS4TPOSTransEmp ON VS4TPOSTrans.TPTANo = VS4TPOSTransEmp.TPTETPTANo) LEFT JOIN VS4TEmployeeGroup ON VS4TPOSTransEmp.TPTETEmGCode = VS4TEmployeeGroup.TEmGCode WHERE (((VS4TFlight.TFliCancelStatus)=0 Or (VS4TFlight.TFliCancelStatus) Is Null))
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, 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 VS4VPOService AS  SELECT VS4TPOService.*, VS4TPOServiceMB.*, VS4TAP.TAPNName, VS4TPODelivery.*, VS4TPOMB.*, VS4TPO.TPODNo, VS4TPO.TPODDate, VS4TPO.TPODTPrjCode, VS4TPO.TPODTAPNCode, VS4TPO.TPODSupplierName, VS4TPO.TPODCancelStatus, VS4TPO.TPODApproveStatus FROM VS4TPO RIGHT JOIN (((VS4TPOService LEFT JOIN VS4TPOBook ON VS4TPOService.TPSNTPOkCode = VS4TPOBook.TPOKCode) LEFT JOIN VS4TAP ON VS4TPOService.TPSNTAPNCode = VS4TAP.TAPNCode) INNER JOIN (VS4TPOServiceMB LEFT JOIN (VS4TPOMB RIGHT JOIN VS4TPODelivery ON (VS4TPOMB.TPOBLn = VS4TPODelivery.TPDETPOBLn) AND (VS4TPOMB.TPOBTPODNo = VS4TPODelivery.TPDETPOBTPODNo)) ON (VS4TPOServiceMB.TPnMTPDELn = VS4TPODelivery.TPDELn) AND (VS4TPOServiceMB.TPnMTPDETPOBLn = VS4TPODelivery.TPDETPOBLn) AND (VS4TPOServiceMB.TPnMTPDETPOBTPODNo = VS4TPODelivery.TPDETPOBTPODNo)) ON VS4TPOService.TPSNNo = VS4TPOServiceMB.TPNMTPSNNo) ON VS4TPO.TPODNo = VS4TPOMB.TPOBTPODNo
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, TPOSCode, TPOSType, TPOSPackText1, TPOSPackText2, TPOSPackAlias1, TPOSPackAlias2, TPOSLeadDay, TPOSMultipleOrder, TPOSMinimumOrder, TPOSCutStock, TPOSPrice, TPOSLastPrice, TPOSLastPriceDate, TPOSHideAfterSold, TPOSSaleCount, TPOSFirstSaleDate, TPOSLastSaleDate, TPOSDisplaySub, TPOSDisplaySubMB, TPOSOnSale, TPOSRefund, TPOSWarranty, TPOSWarrantyUnit, TPOSWarrantyType, TPOSSaleStockMinus, TPOSTotalQuantity, TPOSFlag1, TPOSSaleCode, TPOSPeriod, TPOSTARNCode, TPOSTPSGCode, TPOSG1TAPNCode, TPOSG2TAPNCode, TPOSTLTAPNCode, TPOSTL2TAPNCode, TPOSTL3TAPNCode, TPOSTL4TAPNCode, TPOSG3TAPNCode, TPOSG4TAPNCode, TPOSS1TEmpCode, TPOSS2TEmpCode, TPOSPackDisplay, TPOSUnitCalc, TPOSGuideCount, TPOSTourCount, TPOSSaleCountShip, VS4TProduct.*, VS4TProduct3.TPD3PackText11, VS4TProduct3.TPD3PackText12, VS4TProduct3.TPD3PackText13, VS4TProduct3.TPD3PackText14, VS4TProduct3.TPD3PackText15, VS4TProduct3.TPD3PackText16, VS4TProduct3.TPD3PackAlias21, VS4TProduct3.TPD3PackAlias22, VS4TProduct3.TPD3PackAlias23, VS4TProduct3.TPD3PackAlias24, VS4TProduct3.TPD3PackAlias25, VS4TProduct3.TPD3PackAlias26, VS4TUnit.TUntCode, VS4TUnit.TUntFactor 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) LEFT JOIN VS4TProduct3 ON VS4TPOS.TPOSCode = VS4TProduct3.TPD3TPdtCode) INNER JOIN (VS4TPricelist INNER JOIN VS4TPricelistMB ON VS4TPricelist.TPPLNo = VS4TPricelistMB.TPPMTPPLNo) ON VS4TPOS.TPOSCode = VS4TPricelistMB.TPPMTPOSCode
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.TPPLActiveDate)<='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.TPPLActiveDate) AS TPPLActiveDate 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.TPPLActiveDate = VS4VPriceList2.TPPLActiveDate) 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, VS4TBranch.TBraName, VS4TProductType.TPTTName, VS4TProductLine.TPdLName, VS4TProductSection.TPSEName, VS4TProductSec2.TPS2Name, VS4TProductGroup1.TPG1Name, VS4TProductGroup2.TPG2Name, VS4TProduct.*, VS4TProduct3.TPd3Custom11, VS4TProduct3.TPd3Custom12, VS4TProduct3.TPd3Custom13, VS4TProduct3.TPd3Custom14, VS4TProduct3.TPd3Custom15, VS4TProduct3.TPd3Custom16, VS4TProduct3.TPd3Custom17, VS4TProduct3.TPd3Custom18, VS4TProduct3.TPd3Custom19, VS4TProduct3.TPd3Custom20 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) LEFT JOIN VS4TProduct3 ON VS4TProduct.TPdtCode = VS4TProduct3.TPD3TPdtCode
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, VS4TFlight.TFLiEmpCodeList, VS4TFlight.TFLiEmpNameList, VS4TFlight.TFLiGuildCodeList, VS4TFlight.TFLiGuildNameList, VS4TFlight.TFliTotalDriver, VS4TPOSTransPay.TPPyPaymentType, VS4TPOSTransPay.TPPyCardType, VS4TFlight.TFliTotalGPark, VS4TFlight.TFliTourLeader, VS4TFlight.TFliTotalPAX, VS4TFlight.TFliDateTime, VS4TFlight.TFliNote, (SELECT SUM(TPPyAmount) FROM VS4TPOSTranspay WHERE VS4TPOSTranspay.TPPyTPTANo=VS4TPOSTrans.TPTANo AND TPPyPaymentType='CARD') AS VPTAReceiveCard, (SELECT SUM(TPPyAmount) FROM VS4TPOSTranspay WHERE VS4TPOSTranspay.TPPyTPTANo=VS4TPOSTrans.TPTANo AND TPPyPaymentType<>'CARD') AS VPTAReceiveCash, (SELECT SUM(TPPyAmount) FROM VS4TPOSTranspay WHERE VS4TPOSTranspay.TPPyTPTANo=VS4TPOSTrans.TPTANo AND TPPyPaymentType<>'CARD' AND TPpyISchange=1) AS VPTACashOut, VS4TFlight.TFliNo, VS4TFlight.TFliParkNo, VS4TFlight.TFliCardNo, (SELECT Count(TPTETEmpCode) FROM VS4TPOSTransEmp WHERE VS4TPOSTransEmp.TPTETPTANo=VS4TPOSTrans.TPTANo AND TPTEPositionAlias='03') AS VPTANOS, (SELECT Count(TPTETEmpCode) FROM VS4TPOSTransEmp WHERE VS4TPOSTransEmp.TPTETPTANo=VS4TPOSTrans.TPTANo AND TPTEPositionAlias='30') AS VPTANOA 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) LEFT JOIN VS4TPOSTransPay ON VS4TPOSTrans.TPTANo = VS4TPOSTransPay.TPPyTPTANo) INNER JOIN VS4TPOSTransSub ON VS4TPOSTrans.TPTANo = VS4TPOSTransSub.TPTSTPTANo) ON VS4TPOS.TPOSCode = VS4TPOSTransSub.TPTSTPOSCode) ON VS4TProductLine.TPdLCode = VS4TProduct.TPdtTPDLCode) ON VS4TSaleZone.TSZnCode = VS4TSaleArea.TSaeTSZnCode WHERE (((VS4TPOSTransPay.TPPyLn)=1 Or (VS4TPOSTransPay.TPPyLn) Is Null) AND ((VS4TFlight.TFliCancelStatus)=0 Or (VS4TFlight.TFliCancelStatus) Is Null))
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, VS4TComRateBook.TCRBName, VS4TPOSTransPay.TPPyCardNo, VS4TProduct.TPdtName 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 VS4TComRateBook ON VS4TPOSTrans.TPTATCRBCode = VS4TComRateBook.TCRBCode) LEFT JOIN VS4TPOSTransPay ON VS4TPOSTrans.TPTANo = VS4TPOSTransPay.TPPyTPTANo) LEFT JOIN (VS4TPOSTransSub LEFT JOIN VS4TProduct ON VS4TPOSTransSub.TPTSTPOSCode = VS4TProduct.TPdtCode) ON VS4TPOSTrans.TPTANo = VS4TPOSTransSub.TPTSTPTANo) ON VS4TPOS.TPOSCode = VS4TPOSTransSub.TPTSTPOSCode WHERE (((VS4TPOSTransPay.TPPyLn)=1 Or (VS4TPOSTransPay.TPPyLn) Is Null))
GO

CREATE VIEW VS4VPOSTransConSGN AS  SELECT VS4TPOSTrans.*, VS4TPOSTransSub.*, VS4TProductPURType.TPPuName, VS4TProductLine.TPdLCode, VS4TProductLine.TPdLName, VS4TProductPURType.TPPuCode, VS4TProduct.TPdtTAPNCode, VS4TAP.TAPNName FROM VS4TProductSection RIGHT JOIN (VS4TProductLine RIGHT JOIN (((VS4TPOS LEFT JOIN (VS4TProductPURType RIGHT JOIN VS4TProduct ON VS4TProductPURType.TPPuCode = VS4TProduct.TPdtTPPuCode) ON VS4TPOS.TPOSCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TAP ON VS4TProduct.TPdtTAPNCode = VS4TAP.TAPNCode) INNER JOIN (VS4TPOSTrans INNER JOIN VS4TPOSTransSub ON VS4TPOSTrans.TPTANo = VS4TPOSTransSub.TPTSTPTANo) ON VS4TPOS.TPOSCode = VS4TPOSTransSub.TPTSTPOSCode) ON VS4TProductLine.TPdLCode = VS4TProduct.TPdtTPDLCode) ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode WHERE (((VS4TProductPURType.TPPuCode)='CONSIGN'))
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, 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 VS4VPOSTransfer AS  SELECT VS4TPOSTransfer.*, VS4TPOSTransferMB.*, VS4TAR.*, VS4TCompanyBank.*, VS4TBank.*, VS4TPaymentType.*, VS4TBranch.TBraName, VS4TACChart.TACCName, VS4TACChart.TACCName2 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 VS4VPOSTransGuide AS  SELECT VS4TPOSTrans.*, 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, 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, VS4TFlight.TFLiEmpCodeList, VS4TFlight.TFLiEmpNameList, VS4TFlight.TFLiGuildCodeList, VS4TFlight.TFLiGuildNameList, VS4TFlight.TFliTotalDriver, VS4TFlight.TFliTotalGPark, VS4TFlight.TFliTourLeader, VS4TFlight.TFliTotalPAX, VS4TFlight.TFliDateTime, VS4TFlight.TFliNote, (SELECT SUM(TPPyAmount) FROM VS4TPOSTranspay WHERE VS4TPOSTranspay.TPPyTPTANo=VS4TPOSTrans.TPTANo AND TPPyPaymentType='CARD') AS VPTAReceiveCard, (SELECT SUM(TPPyAmount) FROM VS4TPOSTranspay WHERE VS4TPOSTranspay.TPPyTPTANo=VS4TPOSTrans.TPTANo AND TPPyPaymentType<>'CARD') AS VPTAReceiveCash, (SELECT SUM(TPPyAmount) FROM VS4TPOSTranspay WHERE VS4TPOSTranspay.TPPyTPTANo=VS4TPOSTrans.TPTANo AND TPPyPaymentType<>'CARD' AND TPpyISchange=1) AS VPTACashOut, VS4TFlight.TFliNo, VS4TFlight.TFliParkNo, VS4TFlight.TFliCardNo, VS4TPOSTransGuide.* FROM (VS4TSaleZone LEFT JOIN VS4TSaleZoneGroup ON VS4TSaleZone.TSZnTSZGCode = VS4TSaleZoneGroup.TSZGCode) RIGHT 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 VS4TPOSTransGuide ON VS4TPOSTrans.TPTANo = VS4TPOSTransGuide.TPTGTPTANo) ON VS4TSaleZone.TSZnCode = VS4TSaleArea.TSaeTSZnCode WHERE (((VS4TFlight.TFliCancelStatus)=0 Or (VS4TFlight.TFliCancelStatus) Is Null))
GO

CREATE VIEW VS4VPOSPayTypeAlli AS  SELECT VS4VPOSTransPay.TPTATBraCode, VS4VPOSTransPay.TPTADate, VS4VPOSTransPay.TPPyPaymentType, Sum(VS4VPOSTransPay.TPPyAmount) AS TPPyAmount, VS4VPOSTransPay.TPTANo, VS4VPOSTransPay.TPTATaxNo, VS4VPOSTransPay.TPTACancelStatus FROM VS4VPOSTransPay GROUP BY VS4VPOSTransPay.TPTATBraCode, VS4VPOSTransPay.TPTADate, VS4VPOSTransPay.TPPyPaymentType, VS4VPOSTransPay.TPTANo, VS4VPOSTransPay.TPTATaxNo, VS4VPOSTransPay.TPTACancelStatus HAVING (((VS4VPOSTransPay.TPTACancelStatus)<>1))
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.TPRDNo, VS4TPR.TPRDTPRBCode, VS4TPR.TPRDMode, VS4TPR.TPRDCode, VS4TPR.TPRDType, VS4TPR.TPRDDate, VS4TPR.TPRDRefNo, VS4TPR.TPRDRefDate, VS4TPR.TPRDJobCode,                    VS4TPR.TPRDTJobNo, VS4TPR.TPRDTJbMLn, VS4TPR.TPRDTJPMLn, VS4TPR.TPRDTJPDNo, VS4TPR.TPRDTPrjCode, VS4TPR.TPRDTSecCode, VS4TPR.TPRDTDepCode, VS4TPR.TPRDTDivCode,                    VS4TPR.TPRDTBraCode, VS4TPR.TPRDTAPNCode, VS4TPR.TPRDDescription, VS4TPR.TPRDProcessStatus, VS4TPR.TPRDDeliveryStatus, VS4TPR.TPRDRequestCode, VS4TPR.TPRDRequestBy,                    VS4TPR.TPRDCreateCode, VS4TPR.TPRDCreateBy, VS4TPR.TPRDCreateDate, VS4TPR.TPRDEditCode, VS4TPR.TPRDEditBy, VS4TPR.TPRDEditDate, VS4TPR.TPRDConfirmStatus,                    VS4TPR.TPRDConfirmBy, VS4TPR.TPRDConfirmDate, VS4TPR.TPRDApproveStatus, VS4TPR.TPRDApproveBy, VS4TPR.TPRDApproveDate, VS4TPR.TPRDApproveNote, VS4TPR.TPRDRevision,                    VS4TPR.TPRDReviseStatus, VS4TPR.TPRDCancelStatus, VS4TPR.TPRDCancelNo, VS4TPR.TPRDCancelBy, VS4TPR.TPRDCancelDate, VS4TPR.TPRDCancelNote, VS4TPR.TPRDFlag1, VS4TPR.TPRDFlag2,                    VS4TPR.TPRDFlag3, VS4TPR.TPRDMProcessStatus, VS4TPR.TPRDTCurCode, VS4TPR.TPRDExchangeRate, VS4TPR.TPRDBaseIncoType, VS4TPR.TPRDIncoType, VS4TPR.TPRDIncoterms,                    VS4TPR.TPRDStockTJobNo, VS4TPR.TPRDTotal, VS4TPR.TPRDTotalRecord, VS4TPR.TPRDTotalQuantity, VS4TPRMB.TPRMTPRDNo, VS4TPRMB.TPRMLn, VS4TPRMB.TPRMType,                    VS4TPRMB.TPRMTJobNo, VS4TPRMB.TPRMJobCode, VS4TPRMB.TPRMMaterialMode, VS4TPRMB.TPRMGroupName, VS4TPRMB.TPRMTPdtCode, VS4TPRMB.TPRMProductCode,                    VS4TPRMB.TPRMFactoryCode, VS4TPRMB.TPRMProductName, VS4TPRMB.TPRMCustom1, VS4TPRMB.TPRMCustom2, VS4TPRMB.TPRMCustom3, VS4TPRMB.TPRMCustom4, VS4TPRMB.TPRMCustom5,                    VS4TPRMB.TPRMPrice, VS4TPRMB.TPRMPerQuantity, VS4TPRMB.TPRMDiscountText, VS4TPRMB.TPRMDiscountTotal, VS4TPRMB.TPRMTaxType, VS4TPRMB.TPRMQuantityCalc,                    VS4TPRMB.TPRMUnitFactor, VS4TPRMB.TPRMUnitCalc, VS4TPRMB.TPRMQuantity, VS4TPRMB.TPRMAmount, VS4TPRMB.TPRMNetAmount, VS4TPRMB.TPRMRefill, VS4TPRMB.TPRMMarkTotal,                    VS4TPRMB.TPRMStockOnHand, VS4TPRMB.TPRMMinStock, VS4TPRMB.TPRMPOArrearCalc, VS4TPRMB.TPRMSuggest, VS4TPRMB.TPRMPOArrear, VS4TPRMB.TPRMTotalDelivery,                    VS4TPRMB.TPRMTotalArrear, VS4TPRMB.TPRMTUntCode, VS4TPRMB.TPRMQuantity2, VS4TPRMB.TPRMStockOnHand2, VS4TPRMB.TPRMTotalDelivery2, VS4TPRMB.TPRMTotalArrear2,                    VS4TPRMB.TPRMTUntCode2, VS4TPRMB.TPRMQuantity3, VS4TPRMB.TPRMStockOnHand3, VS4TPRMB.TPRMTotalDelivery3, VS4TPRMB.TPRMTotalArrear3, VS4TPRMB.TPRMTUntCode3,                    VS4TPRMB.TPRMUseType, VS4TPRMB.TPRMUseDate, VS4TPRMB.TPRMDescription, VS4TPRMB.TPRMProcessStatus, VS4TPRMB.TPRMStatus, VS4TPRMB.TPRMFlag1, VS4TPRMB.TPRMMapTPdtCode,                    VS4TPRMB.TPRMMapTUntCode, VS4TPRMB.TPRMMapRatioP, VS4TPRMB.TPRMMaxStock, VS4TPRMB.TPRMOrderPoint, VS4TPRMB.TPRMOrderQuantity, VS4TPRMB.TPRMSafetyStock,                    VS4TPRMB.TPRMPRArrearCalc, VS4TPRMB.TPRMSourceNo, VS4TPRMB.TPRMSourceLn, VS4TPRMB.TPRMTOExCode, VS4TJob.TJobNo, VS4TJob.TJobCode, VS4TJob.TJobTJBkCode,                    VS4TJob.TJobType, VS4TJob.TJobDate, VS4TJob.TJobRefNo, VS4TJob.TJobRefDate, VS4TJob.TJobRefLn, VS4TJob.TJobRefNo2, VS4TJob.TJobRefDate2, VS4TJob.TJOBOriginalNo,                    VS4TJob.TJobTARNCode, VS4TJob.TJobCustomerName, VS4TJob.TJobTPrjCode, VS4TJob.TJobTSecCode, VS4TJob.TJobTDepCode, VS4TJob.TJobTDivCode, VS4TJob.TJobTBraCode,                    VS4TJob.TJobFinishDate, VS4TJob.TJobFinishTime, VS4TJob.TJobDescription, VS4TJob.TJobSetMode, VS4TJob.TJobTotalRequest, VS4TJob.TJobTotalRequest2, VS4TJob.TJobTotalRequest3,                    VS4TJob.TJobTotalArrear, VS4TJob.TJobTotalArrear2, VS4TJob.TJobTotalArrear3, VS4TJob.TJobTotalFinishPCB, VS4TJob.TJobTotalFinishPCO, VS4TJob.TJobTotalFinishPC, VS4TJob.TJobTotalFinishQT,                    VS4TJob.TJobTotalFinishQT2, VS4TJob.TJobTotalFinishQT3, VS4TJob.TJobTotalLoss, VS4TJob.TJobTotalLoss2, VS4TJob.TJobTotalLoss3, VS4TJob.TJobStandardTotal, VS4TJob.TJobActualTotal,                    VS4TJob.TJobActualLastDate, VS4TJob.TJobEstimateTotal, VS4TJob.TJobCustomText1, VS4TJob.TJobCustomText2, VS4TJob.TJobCustomValue1, VS4TJob.TJobCustomValue2, VS4TJob.TJobRequestCode,                    VS4TJob.TJobRequestBy, VS4TJob.TJobCloseStatus, VS4TJob.TJobCloseBy, VS4TJob.TJobCloseDate, VS4TJob.TJobCloseNote, VS4TJob.TJobCreateBy, VS4TJob.TJobCreateDate,                    VS4TJob.TJobEditCode, VS4TJob.TJobEditBy, VS4TJob.TJobEditDate, VS4TJob.TJobConfirmStatus, VS4TJob.TJobConfirmBy, VS4TJob.TJobConfirmDate, VS4TJob.TJobApproveStatus,                    VS4TJob.TJobApproveBy, VS4TJob.TJobApproveDate, VS4TJob.TJobApproveNote, VS4TJob.TJobRevision, VS4TJob.TJobCancelStatus, VS4TJob.TJobCancelNo, VS4TJob.TJobCancelBy,                    VS4TJob.TJobCancelDate, VS4TJob.TJobCancelNote, VS4TJob.TJobFlag1, VS4TJob.TJobTInvNo, VS4TProduct.TPdtImage1, VS4TProduct.TPdtIcon1, VS4TProduct2.TPd2TPdtCode, VS4TProduct2.TPd2Ln,                    VS4TProduct2.TPd2FillNameStock, VS4TProduct2.TPd2ScrapPCMRP, VS4TProduct2.TPd2ScrapPCReceive, VS4TProduct2.TPd2ScrapPCSend, VS4TProduct2.TPd2TaxType, VS4TProduct2.TPd2TaxRate,                    VS4TProduct2.TPd2CostFormula, VS4TProduct2.TPd2Weight, VS4TProduct2.TPd2SkipSuggest, VS4TProduct2.TPd2QuantityAlert, VS4TProduct2.TPd2TotalQuantity, VS4TProduct2.TPd2Yield,                    VS4TProduct2.TPd2HasBOM, VS4TProduct2.TPd2TWRMCode, VS4TProduct2.TPd2StdDM, VS4TProduct2.TPd2StdDL, VS4TProduct2.TPd2StdOH, VS4TProduct2.TPd2StdOHType,                    VS4TProduct2.TPd2ScrapType, VS4TProduct2.TPd2BulkPOrder, VS4TProduct2.TPd2MinimumPOrder, VS4TProduct2.TPd2MultiplePOrder, VS4TProduct2.TPd2Flag1, VS4TProduct2.TPd2Flag2,                    VS4TProduct2.TPd2Flag3, VS4TProduct2.TPd2VendorIncent1, VS4TProduct2.TPd2VendorIncent2, VS4TProduct2.TPd2BOMNote, VS4TProduct2.TPd2SelfMat, VS4TProduct2.TPd2StdDLType,                    VS4TSection.TSecName, VS4TDepartment.TDepName, VS4TDivision.TDivName, VS4TProject.TPrjCode, VS4TProject.TPrjName, VS4TProject.TPrjDocCode, 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, VS4TAP.TAPNAddressDeliver, VS4TProduct.TPdtName, VS4TProduct.TPdtName2,                    VS4TProduct_1.TPdtName2 AS VPRDTPdtName2, VS4TProduct.TPdtAliasSlip, VS4TProduct.TPdtDescription, VS4TProduct.TPdtOrderPoint, VS4TProductSection.TPSECode, VS4TProductSection.TPSEName,                    VS4TProductSection.TPSEBudget, VS4TAP.TAPNTAPGCode FROM     VS4TPRBook RIGHT OUTER JOIN                   VS4TPR LEFT OUTER JOIN                   VS4TJob ON VS4TPR.TPRDTJobNo = VS4TJob.TJobNo LEFT OUTER JOIN                   VS4TProject ON VS4TPR.TPRDTPrjCode = VS4TProject.TPrjCode LEFT OUTER JOIN                   VS4TSection ON VS4TPR.TPRDTSecCode = VS4TSection.TSecCode LEFT OUTER JOIN                   VS4TDepartment ON VS4TPR.TPRDTDepCode = VS4TDepartment.TDepCode LEFT OUTER JOIN                   VS4TDivision ON VS4TPR.TPRDTDivCode = VS4TDivision.TDivCode LEFT OUTER JOIN                   VS4TBranch ON VS4TPR.TPRDTBraCode = VS4TBranch.TBraCode LEFT OUTER JOIN                   VS4TAP ON VS4TPR.TPRDTAPNCode = VS4TAP.TAPNCode ON VS4TPRBook.TPRBCode = VS4TPR.TPRDTPRBCode INNER JOIN                   VS4TPRMB LEFT OUTER JOIN                   VS4TProduct ON VS4TPRMB.TPRMTPdtCode = VS4TProduct.TPdtCode LEFT OUTER JOIN                   VS4TProduct AS VS4TProduct_1 ON VS4TPRMB.TPRMMapTPdtCode = VS4TProduct_1.TPdtCode LEFT OUTER JOIN                   VS4TProduct2 ON VS4TProduct.TPdtCode = VS4TProduct2.TPd2TPdtCode ON VS4TPR.TPRDNo = VS4TPRMB.TPRMTPRDNo LEFT OUTER JOIN                   VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode
GO

CREATE VIEW VS4VPR2LotIn AS  SELECT VS4TPRMB.*, VS4TPO.TPODNo, VS4TPO.TPODType, VS4TPO.TPODDate, VS4TPO.TPODDueDate, VS4TPO.TPODDeliveryDate, VS4TPO.TPODDeliveryTo, VS4TPO.TPODTAPNCode, VS4TPO.TPODSupplierName, VS4TPOMB.TPOBTPODNo, VS4TPOMB.TPOBLn, VS4TPOMB.TPOBType, VS4TPOMB.TPOBJobCode, VS4TPOMB.TPOBGroupName, VS4TPOMB.TPOBTOExCode, VS4TPOMB.TPOBTPdtCode, VS4TPOMB.TPOBCustom1, VS4TPOMB.TPOBCustom2, VS4TPOMB.TPOBCustom3, VS4TPOMB.TPOBCustom4, VS4TPOMB.TPOBCustom5, VS4TPOMB.TPOBShippingMark, VS4TPOMB.TPOBProductCode, VS4TPOMB.TPOBFactoryCode, VS4TPOMB.TPOBProductName, VS4TPOMB.TPOBUseBom, VS4TPOMB.TPOBDeliveryDate, VS4TPOMB.TPOBDeliveryTime, VS4TPOMB.TPOBMinimumOrder, VS4TPOMB.TPOBCost, VS4TPOMB.TPOBPrice, VS4TPOMB.TPOBPerQuantity, VS4TPOMB.TPOBUnitFactor, VS4TPOMB.TPOBAcceptError, VS4TPOMB.TPOBUnitCalc, VS4TPOMB.TPOBQuantityCalc, VS4TPOMB.TPOBQuantityText, VS4TPOMB.TPOBQuantity, VS4TPOMB.TPOBTUntCode, VS4TPOMB.TPOBQuantity2, VS4TPOMB.TPOBTUntCode2, VS4TPOMB.TPOBQuantity3, VS4TPOMB.TPOBTUntCode3, VS4TPOMB.TPOBDutyAmount, VS4TPOMB.TPOBDivideExpense, VS4TPOMB.TPOBCostAmount, VS4TPOMB.TPOBAmount, VS4TPOMB.TPOBDiscountText, VS4TPOMB.TPOBDiscountTotal, VS4TPOMB.TPOBNetAmount, VS4TPOMB.TPOBTaxType, VS4TPOMB.TPOBTaxBase, VS4TPOMB.TPOBWTAXBase, VS4TPOMB.TPOBAmountVAT, VS4TPOMB.TPOBAmountWTAX, VS4TPOMB.TPOBAutoSTD, VS4TPOMB.TPOBStandardCost, VS4TPOMB.TPOBMargin, VS4TPOMB.TPOBSaleMargin, VS4TPOMB.TPOBAutoPrice, VS4TPOMB.TPOBSalePrice, VS4TPOMB.TPOBGetNumber, VS4TPOMB.TPOBFreeCode, VS4TPOMB.TPOBIsPremium, VS4TPOMB.TPOBDescription, VS4TPOMB.TPOBSourceNo, VS4TPOMB.TPOBSourceLn, VS4TPOMB.TPOBStatus, VS4TPOMB.TPOBFlag1, VS4TPOMB.TPOBStockTotal, VS4TPOMB.TPOBPRArrear, VS4TPOMB.TPOBEOQ, VS4TPOMB.TPOBTotalDelivery, VS4TPOMB.TPOBTotalDelivery2, VS4TPOMB.TPOBTotalDelivery3, VS4TPOMB.TPOBTotalArrear, VS4TPOMB.TPOBTotalArrear2, VS4TPOMB.TPOBTotalArrear3, VS4TPOMB.TPOBMapTPdtCode, VS4TPOMB.TPOBMapTUntCode, VS4TPOMB.TPOBDayProcess, VS4TPOMB.TPOBTLctCode, VS4TPOMB.TPOBManualClose, VS4TPOMB.TPOBMapRatioP, VS4TPOMB.TPOBQuantityCost, VS4TPOMB.TPOBTotalInv2, VS4TPOMB.TPOBTotalInv3, VS4TPOMB.TPOBTotalInv, VS4TPODelivery.TPDETPOBTPODNo, VS4TPODelivery.TPDETPOBLn, VS4TPODelivery.TPDELn, VS4TPODelivery.TPDEProductCode, VS4TPODelivery.TPDEProductName, VS4TPODelivery.TPDEDate, VS4TPODelivery.TPDEDateTime, VS4TPODelivery.TPDEQuantity, VS4TPODelivery.TPDEQuantity2, VS4TPODelivery.TPDEQuantity3, VS4TPODelivery.TPDEUnitCode, VS4TPODelivery.TPDEUnitCode2, VS4TPODelivery.TPDEUnitCode3, VS4TPODelivery.TPDETotalDelivery, VS4TPODelivery.TPDETotalDelivery2, VS4TPODelivery.TPDETotalDelivery3, VS4TPODelivery.TPDETotalArrear, VS4TPODelivery.TPDETotalArrear2, VS4TPODelivery.TPDETotalArrear3, VS4TPODelivery.TPDEUnitCalc, VS4TPODelivery.TPDEMapTPdtCode, VS4TPODelivery.TPDEMapTUntCode, VS4TPODelivery.TPDEMapUnitRatio, VS4TPODelivery.TPDEQuantityBase, VS4TPODelivery.TPDEDeliveryBase, VS4TPODelivery.TPDEArrearBase, VS4TPODelivery.TPDELinkStatus, VS4TPODelivery.TPDELinkBy, VS4TPODelivery.TPDELinkDate, VS4TPODelivery.TPDETotalOntime, VS4TPODelivery.TPDETotalDelay, VS4TPODelivery.TPDETLctCode, VS4TPO.TPODCountryOrigin, VS4TCountry.TCouName, VS4TPO.TPODTPrjCode, VS4TProject.TPrjName, 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, VS4TPOMBAOL.TPOATBraCode, VS4TPOMBAOL.TPOATDivCode, VS4TPOMBAOL.TPOATDepCode, VS4TPOMBAOL.TPOATSecCode, VS4TPOMBAOL.TPOATEmpCode 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.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 VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code) LEFT JOIN VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode) ON VS4TProductType.TPTTCode = VS4TProduct.TPdtTPTTCode) LEFT JOIN VS4TInventoryLOT ON (VS4TPODelivery.TPDETPOBTPODNo = VS4TInventoryLOT.TIMCTPODNo) AND (VS4TPODelivery.TPDETPOBLn = VS4TInventoryLOT.TIMCTPOBLn) AND (VS4TPODelivery.TPDELn = VS4TInventoryLOT.TIMCTPDELn)) LEFT JOIN VS4TPOMBAOL ON (VS4TPOMB.TPOBLn = VS4TPOMBAOL.TPOATPOBLn) AND (VS4TPOMB.TPOBTPODNo = VS4TPOMBAOL.TPOATPOBTPODNo)) 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.TPRDNo, VS4TPR.TPRDTPRBCode, VS4TPR.TPRDMode, VS4TPR.TPRDCode, VS4TPR.TPRDType, VS4TPR.TPRDDate, VS4TPR.TPRDRefNo, VS4TPR.TPRDRefDate, VS4TPR.TPRDJobCode, VS4TPR.TPRDTJobNo, VS4TPR.TPRDTJbMLn, VS4TPR.TPRDTJPMLn, VS4TPR.TPRDTJPDNo, VS4TPR.TPRDTPrjCode, VS4TPR.TPRDTSecCode, VS4TPR.TPRDTDepCode, VS4TPR.TPRDTDivCode, VS4TPR.TPRDTBraCode, VS4TPR.TPRDTAPNCode, VS4TPR.TPRDDescription, VS4TPR.TPRDProcessStatus, VS4TPR.TPRDDeliveryStatus, VS4TPR.TPRDRequestCode, VS4TPR.TPRDRequestBy, VS4TPR.TPRDCreateBy, VS4TPR.TPRDCreateDate, VS4TPR.TPRDEditCode, VS4TPR.TPRDEditBy, VS4TPR.TPRDEditDate, VS4TPR.TPRDConfirmStatus, VS4TPR.TPRDConfirmBy, VS4TPR.TPRDConfirmDate, VS4TPR.TPRDApproveStatus, VS4TPR.TPRDApproveBy, VS4TPR.TPRDApproveDate, VS4TPR.TPRDApproveNote, VS4TPR.TPRDRevision, VS4TPR.TPRDReviseStatus, VS4TPR.TPRDCancelStatus, VS4TPR.TPRDCancelNo, VS4TPR.TPRDCancelBy, VS4TPR.TPRDCancelDate, VS4TPR.TPRDCancelNote, VS4TPR.TPRDFlag1, VS4TPRMB.TPRMTPRDNo, VS4TPRMB.TPRMLn, VS4TPRMB.TPRMType, VS4TPRMB.TPRMTJobNo, VS4TPRMB.TPRMJobCode, VS4TPRMB.TPRMMaterialMode, VS4TPRMB.TPRMGroupName, VS4TPRMB.TPRMTPdtCode, VS4TPRMB.TPRMProductCode, VS4TPRMB.TPRMFactoryCode, VS4TPRMB.TPRMProductName, VS4TPRMB.TPRMCustom1, VS4TPRMB.TPRMCustom2, VS4TPRMB.TPRMCustom3, VS4TPRMB.TPRMCustom4, VS4TPRMB.TPRMCustom5, VS4TPRMB.TPRMPrice, VS4TPRMB.TPRMPerQuantity, VS4TPRMB.TPRMDiscountText, VS4TPRMB.TPRMDiscountTotal, VS4TPRMB.TPRMTaxType, VS4TPRMB.TPRMQuantityCalc, VS4TPRMB.TPRMUnitFactor, VS4TPRMB.TPRMUnitCalc, VS4TPRMB.TPRMQuantity, VS4TPRMB.TPRMAmount, VS4TPRMB.TPRMNetAmount, VS4TPRMB.TPRMRefill, VS4TPRMB.TPRMMarkTotal, VS4TPRMB.TPRMStockOnHand, VS4TPRMB.TPRMMinStock, VS4TPRMB.TPRMPOArrearCalc, VS4TPRMB.TPRMSuggest, VS4TPRMB.TPRMPOArrear, VS4TPRMB.TPRMTotalDelivery, VS4TPRMB.TPRMTotalArrear, VS4TPRMB.TPRMTUntCode, VS4TPRMB.TPRMQuantity2, VS4TPRMB.TPRMStockOnHand2, VS4TPRMB.TPRMTotalDelivery2, VS4TPRMB.TPRMTotalArrear2, VS4TPRMB.TPRMTUntCode2, VS4TPRMB.TPRMQuantity3, VS4TPRMB.TPRMStockOnHand3, VS4TPRMB.TPRMTotalDelivery3, VS4TPRMB.TPRMTotalArrear3, VS4TPRMB.TPRMTUntCode3, VS4TPRMB.TPRMUseType, VS4TPRMB.TPRMUseDate, VS4TPRMB.TPRMDescription, VS4TPRMB.TPRMProcessStatus, VS4TPRMB.TPRMStatus, VS4TPRMB.TPRMFlag1, VS4TPRMB.TPRMMapTPdtCode, VS4TPRMB.TPRMMapTUntCode, VS4TPRMB.TPRMMapRatioP, VS4TPRMB.TPRMMaxStock, VS4TPRMB.TPRMOrderPoint, VS4TPRMB.TPRMOrderQuantity, VS4TPRMB.TPRMSafetyStock, VS4TPRMB.TPRMPRArrearCalc, VS4TPO.TPODNo, VS4TPO.TPODType, VS4TPO.TPODDate, VS4TPO.TPODDueDate, VS4TPO.TPODDeliveryDate, VS4TPO.TPODDeliveryTo, VS4TPO.TPODTAPNCode, VS4TPO.TPODSupplierName, VS4TPOMB.TPOBTPODNo, VS4TPOMB.TPOBLn, VS4TPOMB.TPOBJobCode, VS4TPOMB.TPOBTOExCode, VS4TPOMB.TPOBTPdtCode, VS4TPOMB.TPOBCustom1, VS4TPOMB.TPOBCustom2, VS4TPOMB.TPOBCustom3, VS4TPOMB.TPOBCustom4, VS4TPOMB.TPOBCustom5, VS4TPOMB.TPOBShippingMark, VS4TPOMB.TPOBProductCode, VS4TPOMB.TPOBFactoryCode, VS4TPOMB.TPOBProductName, VS4TPOMB.TPOBUseBom, VS4TPOMB.TPOBDeliveryDate, VS4TPOMB.TPOBDeliveryTime, VS4TPOMB.TPOBMinimumOrder, VS4TPOMB.TPOBCost, VS4TPOMB.TPOBPrice, VS4TPOMB.TPOBPerQuantity, VS4TPOMB.TPOBUnitFactor, VS4TPOMB.TPOBAcceptError, VS4TPOMB.TPOBUnitCalc, VS4TPOMB.TPOBQuantityCalc, VS4TPOMB.TPOBQuantityText, VS4TPOMB.TPOBQuantity, VS4TPOMB.TPOBTUntCode, VS4TPOMB.TPOBQuantity2, VS4TPOMB.TPOBTUntCode2, VS4TPOMB.TPOBQuantity3, VS4TPOMB.TPOBTUntCode3, VS4TPOMB.TPOBDutyAmount, VS4TPOMB.TPOBDivideExpense, VS4TPOMB.TPOBCostAmount, VS4TPOMB.TPOBAmount, VS4TPOMB.TPOBDiscountText, VS4TPOMB.TPOBDiscountTotal, VS4TPOMB.TPOBNetAmount, VS4TPOMB.TPOBTaxType, VS4TPOMB.TPOBTaxBase, VS4TPOMB.TPOBWTAXBase, VS4TPOMB.TPOBAmountVAT, VS4TPOMB.TPOBAmountWTAX, VS4TPOMB.TPOBAutoSTD, VS4TPOMB.TPOBStandardCost, VS4TPOMB.TPOBMargin, VS4TPOMB.TPOBSaleMargin, VS4TPOMB.TPOBAutoPrice, VS4TPOMB.TPOBSalePrice, VS4TPOMB.TPOBGetNumber, VS4TPOMB.TPOBFreeCode, VS4TPOMB.TPOBIsPremium, VS4TPOMB.TPOBDescription, VS4TPOMB.TPOBSourceNo, VS4TPOMB.TPOBSourceLn, VS4TPOMB.TPOBStatus, VS4TPOMB.TPOBFlag1, VS4TPOMB.TPOBStockTotal, VS4TPOMB.TPOBPRArrear, VS4TPOMB.TPOBEOQ, VS4TPOMB.TPOBTotalDelivery, VS4TPOMB.TPOBTotalDelivery2, VS4TPOMB.TPOBTotalDelivery3, VS4TPOMB.TPOBTotalArrear, VS4TPOMB.TPOBTotalArrear2, VS4TPOMB.TPOBTotalArrear3, VS4TPOMB.TPOBMapTPdtCode, VS4TPOMB.TPOBMapTUntCode, VS4TPOMB.TPOBDayProcess, VS4TPOMB.TPOBTLctCode, VS4TPOMB.TPOBManualClose, VS4TPOMB.TPOBMapRatioP, VS4TPOMB.TPOBQuantityCost, VS4TPOMB.TPOBTotalInv2, VS4TPOMB.TPOBTotalInv3, VS4TPOMB.TPOBTotalInv, VS4TPOMB.TPOBTotalInvArr, VS4TPOMB.TPOBTotalInvArr2, VS4TPOMB.TPOBTotalInvArr3, VS4TPO.TPODCountryOrigin, VS4TCountry.TCouName, VS4TPO.TPODTPrjCode, VS4TProject.TPrjName, 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, VS4TPOMBAOL.TPOATBraCode, VS4TPOMBAOL.TPOATDivCode, VS4TPOMBAOL.TPOATDepCode, VS4TPOMBAOL.TPOATSecCode, VS4TPOMBAOL.TPOATEmpCode, VS4TPRMB.TPRMTOExCode 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.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 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 VS4TPOMBAOL ON (VS4TPOMB.TPOBTPODNo = VS4TPOMBAOL.TPOATPOBTPODNo) AND (VS4TPOMB.TPOBLn = VS4TPOMBAOL.TPOATPOBLn)) 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, TPRDNo, TPRDTPRBCode, TPRDMode, TPRDCode, TPRDType, TPRDDate, TPRDRefNo, TPRDRefDate, TPRDJobCode, TPRDTJobNo, TPRDTJbMLn, TPRDTJPMLn, TPRDTJPDNo, TPRDTPrjCode, TPRDTSecCode, TPRDTDepCode, TPRDTDivCode, TPRDTBraCode, TPRDTAPNCode, TPRDDescription, TPRDProcessStatus, TPRDDeliveryStatus, TPRDRequestCode, TPRDRequestBy, TPRDCreateBy, TPRDCreateDate, TPRDEditCode, TPRDEditBy, TPRDEditDate, TPRDConfirmStatus, TPRDConfirmBy, TPRDConfirmDate, TPRDApproveStatus, TPRDApproveBy, TPRDApproveDate, TPRDApproveNote, TPRDRevision, TPRDReviseStatus, TPRDCancelStatus, TPRDCancelNo, TPRDCancelBy, TPRDCancelDate, TPRDCancelNote, TPRDFlag1, TPRDMProcessStatus, VS4TPRMB.TPRMTPRDNo, VS4TPRMB.TPRMLn, VS4TPRMB.TPRMType, VS4TPRMB.TPRMTJobNo, VS4TPRMB.TPRMJobCode, VS4TPRMB.TPRMMaterialMode, VS4TPRMB.TPRMGroupName, VS4TPRMB.TPRMTPdtCode, VS4TPRMB.TPRMProductCode, VS4TPRMB.TPRMFactoryCode, VS4TPRMB.TPRMProductName, VS4TPRMB.TPRMCustom1, VS4TPRMB.TPRMCustom2, VS4TPRMB.TPRMCustom3, VS4TPRMB.TPRMCustom4, VS4TPRMB.TPRMCustom5, VS4TPRMB.TPRMPrice, VS4TPRMB.TPRMPerQuantity, VS4TPRMB.TPRMDiscountText, VS4TPRMB.TPRMDiscountTotal, VS4TPRMB.TPRMTaxType, VS4TPRMB.TPRMQuantityCalc, VS4TPRMB.TPRMUnitFactor, VS4TPRMB.TPRMUnitCalc, VS4TPRMB.TPRMQuantity, VS4TPRMB.TPRMAmount, VS4TPRMB.TPRMNetAmount, VS4TPRMB.TPRMRefill, VS4TPRMB.TPRMMarkTotal, VS4TPRMB.TPRMStockOnHand, VS4TPRMB.TPRMMaxStock, VS4TPRMB.TPRMMinStock, VS4TPRMB.TPRMPOArrearCalc, VS4TPRMB.TPRMSuggest, VS4TPRMB.TPRMPOArrear, VS4TPRMB.TPRMTotalDelivery, VS4TPRMB.TPRMTotalArrear, VS4TPRMB.TPRMTUntCode, VS4TPRMB.TPRMQuantity2, VS4TPRMB.TPRMStockOnHand2, VS4TPRMB.TPRMTotalDelivery2, VS4TPRMB.TPRMTotalArrear2, VS4TPRMB.TPRMTUntCode2, VS4TPRMB.TPRMQuantity3, VS4TPRMB.TPRMStockOnHand3, VS4TPRMB.TPRMTotalDelivery3, VS4TPRMB.TPRMTotalArrear3, VS4TPRMB.TPRMTUntCode3, VS4TPRMB.TPRMUseType, VS4TPRMB.TPRMUseDate, VS4TPRMB.TPRMDescription, VS4TPRMB.TPRMProcessStatus, VS4TPRMB.TPRMStatus, VS4TPRMB.TPRMFlag1, VS4TPRMB.TPRMMapTPdtCode, VS4TPRMB.TPRMMapTUntCode, VS4TPRMB.TPRMMapRatioP, VS4TSO.TSODTPrjCode, VS4TProduct2.TPd2TPdtCode, VS4TProduct2.TPd2Ln, VS4TProduct2.TPd2FillNameStock, VS4TProduct2.TPd2ScrapPCMRP, VS4TProduct2.TPd2ScrapPCReceive, VS4TProduct2.TPd2ScrapPCSend, VS4TProduct2.TPd2TaxType, VS4TProduct2.TPd2TaxRate, VS4TProduct2.TPd2CostFormula, VS4TProduct2.TPd2Weight, VS4TProduct2.TPd2SkipSuggest, VS4TProduct2.TPd2QuantityAlert, VS4TProduct2.TPd2TotalQuantity, VS4TProduct2.TPd2Yield, VS4TProduct2.TPd2HasBOM, VS4TProduct2.TPd2TWRMCode, VS4TProduct2.TPd2StdDM, VS4TProduct2.TPd2StdDL, VS4TProduct2.TPd2StdOH, VS4TProduct2.TPd2StdOHType, VS4TProduct2.TPd2ScrapType, VS4TProduct2.TPd2BulkPOrder, VS4TProduct2.TPd2MinimumPOrder, VS4TProduct2.TPd2MultiplePOrder, VS4TProduct2.TPd2Flag1, VS4TProduct2.TPd2VendorIncent1, VS4TProduct2.TPd2VendorIncent2, VS4TProduct2.TPd2BOMNote, VS4TProduct2.TPd2SelfMat, VS4TProduct2.TPd2StdDLType, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TPRMB.TPRMTOExCode 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 VS4VPRArrear AS  SELECT 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, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4VPOArrear.TPODNo, VS4VPOArrear.TPODApproveStatus, VS4VPOArrear.TPODCancelStatus, VS4TProject.TPrjCode, VS4VPOArrear.TPOBTPdtCode, VS4VPOArrear.TPOBProductName, VS4VPOArrear.TPOBCustom1, VS4VPOArrear.TPOBCustom2, VS4VPOArrear.TPOBCustom3, VS4VPOArrear.TPOBCustom4, VS4VPOArrear.TPOBCustom5, VS4VPOArrear.TPOBTUntCode, Sum(VS4VPOArrear.TPOBQuantity) AS TPOBQuantity, Sum(VS4VPOArrear.TPOBTotalDelivery) AS TPOBTotalDelivery, Sum(VS4VPOArrear.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, VS4VPOArrear.TPOBDeliveryDate, VS4VPOArrear.TPOBPrice, VS4TPRMB.TPRMTPdtCode, VS4TPRMB.TPRMTotalArrear, VS4TPRMB.TPRMPOArrear, VS4TPRMB.TPRMTotalDelivery, VS4TPRMB.TPRMTOExCode FROM (VS4TPRBook RIGHT JOIN (((((((VS4TPR 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 VS4TPRBook.TPRBCode = VS4TPR.TPRDTPRBCode) INNER JOIN (VS4TAP RIGHT JOIN (VS4TPRMB LEFT JOIN (VS4TPO RIGHT JOIN VS4VPOArrear ON VS4TPO.TPODNo = VS4VPOArrear.TPOBTPODNo) ON (VS4TPRMB.TPRMTPRDNo = VS4VPOArrear.TPOBSourceNo) AND (VS4TPRMB.TPRMLn = VS4VPOArrear.TPOBSourceLn)) ON VS4TAP.TAPNCode = VS4TPO.TPODTAPNCode) ON VS4TPR.TPRDNo = VS4TPRMB.TPRMTPRDNo GROUP BY 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, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TSection.TSecName, VS4VPOArrear.TPODNo, VS4VPOArrear.TPODApproveStatus, VS4VPOArrear.TPODCancelStatus, VS4TProject.TPrjCode, VS4VPOArrear.TPOBTPdtCode, VS4VPOArrear.TPOBProductName, VS4VPOArrear.TPOBCustom1, VS4VPOArrear.TPOBCustom2, VS4VPOArrear.TPOBCustom3, VS4VPOArrear.TPOBCustom4, VS4VPOArrear.TPOBCustom5, VS4VPOArrear.TPOBTUntCode, VS4TPO.TPODDate, VS4TAR.TARNCode, VS4TAP.TAPNCode, VS4TAP.TAPNName, VS4TPR.TPRDTBraCode, VS4TPR.TPRDTDivCode, VS4TPR.TPRDTDepCode, VS4TPR.TPRDTSecCode, VS4TPR.TPRDTPRBCode, VS4TPO.TPODType, VS4TPR.TPRDDate, VS4VPOArrear.TPOBDeliveryDate, VS4VPOArrear.TPOBPrice, VS4TPRMB.TPRMTPdtCode, VS4TPRMB.TPRMTotalArrear, VS4TPRMB.TPRMPOArrear, VS4TPRMB.TPRMTotalDelivery, VS4TPRBook.TPRBName, VS4TPRMB.TPRMProductName, VS4TPRMB.TPRMTOExCode HAVING (((VS4VPOArrear.TPODApproveStatus)=1) AND ((VS4VPOArrear.TPODCancelStatus)=0))
GO

CREATE VIEW VS4VPRArrearSum AS  SELECT VS4TPRMB.TPRMTPdtCode, Sum(VS4TPRMB.TPRMQuantity) AS TPRMQuantity, Sum(VS4TPRMB.TPRMTotalArrear) AS TPRMTotalArrear, Sum(VS4TPRMB.TPRMPOArrear) AS TPRMPOArrear, Sum(VS4TPRMB.TPRMQuantity*TPRMUnitFactor) AS TPRMQuantityBase, Sum(VS4TPRMB.TPRMTotalArrear*TPRMUnitFactor) AS TPRMTotalArrearBas, Sum(VS4TPRMB.TPRMPOArrear*TPRMUnitFactor) AS TPRMPOArrearBase FROM VS4TPR INNER JOIN VS4TPRMB ON VS4TPR.TPRDNo = VS4TPRMB.TPRMTPRDNo GROUP BY VS4TPRMB.TPRMTPdtCode, VS4TPR.TPRDCancelStatus, VS4TPR.TPRDApproveStatus HAVING (((VS4TPR.TPRDCancelStatus)=0) AND ((VS4TPR.TPRDApproveStatus)=1))
GO

CREATE VIEW VS4VPRHead AS  SELECT VS4TPR.*, VS4TProject.*, VS4TJob.*, VS4TBranch.*, VS4TSO.TSODTARNCode, VS4TSO.TSODCustomerName, VS4TJobProductionM.TJPMTSepCode, VS4TMRPStepName.TSepName, VS4TAP.TAPNName, VS4TAP.TAPNName2, VS4TDivision.TDivCode, VS4TDivision.TDivName, VS4TDivision.TDivName2, VS4TDepartment.TDepCode, VS4TDepartment.TDepName, VS4TDepartment.TDepName2, VS4TSection.TSecCode, VS4TSection.TSecName, VS4TSection.TSecName2, VS4TPRMB.TPRMLn, VS4TPRMB.TPRMUseDate 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) LEFT JOIN VS4TAP ON VS4TPR.TPRDTAPNCode = VS4TAP.TAPNCode) LEFT JOIN VS4TPRMB ON VS4TPR.TPRDNo = VS4TPRMB.TPRMTPRDNo WHERE (((VS4TPRMB.TPRMLn)=1 Or (VS4TPRMB.TPRMLn) Is Null))
GO

CREATE VIEW VS4VPricelist AS  SELECT VS4TPricelist.*, VS4TPricelistMB.*, VS4TPOS.*, VS4VPOSMBQuery.VPoSMemberCount, VS4VPOSMBQuery.VPoMSetAvailable, VS4TAR.TARNName, VS4TProduct.*, VS4TUnit.TUntCode, VS4TUnit.TUntName, VS4TUnit.TUntName2, VS4TUnit.TUntInSlip, VS4TUnit.TUntDecimal, VS4TUnit.TUntFactor 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.TPd2TPdtCode, VS4TProduct2.TPd2FillNameStock, VS4TProduct2.TPd2ScrapPCMRP, VS4TProduct2.TPd2ScrapPCReceive, VS4TProduct2.TPd2ScrapPCSend, VS4TProduct2.TPd2TaxType, VS4TProduct2.TPd2TaxRate, VS4TProduct2.TPd2CostFormula, VS4TProduct2.TPd2Weight, VS4TProduct2.TPd2SkipSuggest, VS4TProduct2.TPd2QuantityAlert, VS4TProduct2.TPd2TotalQuantity, VS4TProduct2.TPd2Yield, VS4TProduct2.TPd2HasBOM, VS4TProduct2.TPd2SelfMat, VS4TProduct2.TPd2TWRMCode, VS4TProduct2.TPd2StdDM, VS4TProduct2.TPd2StdDL, VS4TProduct2.TPd2StdOH, VS4TProduct2.TPd2StdOHType, VS4TProduct2.TPd2ScrapType, VS4TProduct2.TPd2BulkPOrder, VS4TProduct2.TPd2MinimumPOrder, VS4TProduct2.TPd2MultiplePOrder, VS4TProduct2.TPd2VendorIncent1, VS4TProduct2.TPd2VendorIncent2, VS4TProduct2.TPd2BOMNote, VS4TProduct3.TPD3PackText11, VS4TProduct3.TPD3PackText12, VS4TProduct3.TPD3PackText13, VS4TProduct3.TPD3PackText14, VS4TProduct3.TPD3PackText15, VS4TProduct3.TPD3PackText16, VS4TProduct3.TPD3PackAlias21, VS4TProduct3.TPD3PackAlias22, VS4TProduct3.TPD3PackAlias23, VS4TProduct3.TPD3PackAlias24, VS4TProduct3.TPD3PackAlias25, VS4TProduct3.TPD3PackAlias26, VS4TProduct3.TPD3Flag1, VS4TProduct3.TPD3Flag2, VS4TProduct3.TPD3Flag3, VS4TProduct3.TPd3Custom11, VS4TProduct3.TPd3Custom12, VS4TProduct3.TPd3Custom13, VS4TProduct3.TPd3Custom14, VS4TProduct3.TPd3Custom15, VS4TProduct3.TPd3Custom16, VS4TProduct3.TPd3Custom17, VS4TProduct3.TPd3Custom18, VS4TProduct3.TPd3Custom19, VS4TProduct3.TPd3Custom20, VS4TProduct3.TPd3Custom21, VS4TProduct3.TPd3Custom22, VS4TProduct3.TPd3Custom23, VS4TProduct3.TPd3Custom24, VS4TProduct3.TPd3Custom25, VS4TProduct3.TPd3Custom26, VS4TProduct3.TPd3Custom27, VS4TProduct3.TPd3Custom28, VS4TProduct3.TPd3Custom29, VS4TProduct3.TPd3Custom30, VS4TPOS.TPOSCode, VS4TPOS.TPOSType, VS4TPOS.TPOSPackText1, VS4TPOS.TPOSPackText2, VS4TPOS.TPOSPackAlias1, VS4TPOS.TPOSPackAlias2, VS4TPOS.TPOSLeadDay, VS4TPOS.TPOSMultipleOrder, VS4TPOS.TPOSMinimumOrder, VS4TPOS.TPOSCutStock, VS4TPOS.TPOSPrice, VS4TPOS.TPOSLastPrice, VS4TPOS.TPOSLastPriceDate, VS4TPOS.TPOSHideAfterSold, VS4TPOS.TPOSSaleCount, VS4TPOS.TPOSFirstSaleDate, VS4TPOS.TPOSLastSaleDate, VS4TPOS.TPOSDisplaySub, VS4TPOS.TPOSDisplaySubMB, VS4TPOS.TPOSOnSale, VS4TPOS.TPOSRefund, VS4TPOS.TPOSWarranty, VS4TPOS.TPOSWarrantyUnit, VS4TPOS.TPOSWarrantyType, VS4TPOS.TPOSSaleStockMinus, VS4TPOS.TPOSTotalQuantity, VS4TPOS.TPOSFlag1, VS4TPOS.TPOSPackDisplay, VS4TPOS.TPOSSaleCode, VS4TPOS.TPOSPeriod, VS4TPOS.TPOSTARNCode, VS4TPOS.TPOSTPSGCode, VS4TPOS.TPOSG1TAPNCode, VS4TPOS.TPOSG2TAPNCode, VS4TPOS.TPOSTLTAPNCode, VS4TPOS.TPOSTL2TAPNCode, VS4TPOS.TPOSTL3TAPNCode, VS4TPOS.TPOSTL4TAPNCode, VS4TPOS.TPOSG3TAPNCode, VS4TPOS.TPOSG4TAPNCode, VS4TPOS.TPOSS1TEmpCode, VS4TPOS.TPOSS2TEmpCode, 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, VS4TProductLine.TPdLCode, VS4TProductLine.TPdLName, VS4TProductLine.TPdLName2, VS4TProductLine.TPdLTDivCode, VS4TProductLine.TPdLDocCode, VS4TProductLine.TPdLTACSCode, VS4TProductSection.TPSECode, VS4TProductSection.TPSEName, VS4TProductSection.TPSEName2, VS4TProductLine.TPDLCustomName, VS4TProductLine.TPDLGroupName1, VS4TProductLine.TPDLGroupName2, VS4TProductLine.TPDLGroupName3, VS4TProductLine.TPDLGroupName4, VS4TProductStat.TPMSLastPPrice, VS4TProductStat.TPMSLastPTCurCode, VS4TCurrency.TCurLastRate, (TPMSLastPPrice*TCurLastRate*(TPd2TaxRate+100)/100) AS VPdtNetCost, VS4TProductSafeS.TPSSStockMin, VS4TProductSafeS.TPSSStockMax, VS4TPOS.TPOSUnitCalc, VS4TProductSec2.TPS2Name 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) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) LEFT JOIN VS4TProduct3 ON VS4TProduct.TPdtCode = VS4TProduct3.TPD3TPdtCode) LEFT JOIN VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code) ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode) LEFT JOIN VS4TProduct2 ON VS4TProduct.TPdtCode = VS4TProduct2.TPd2TPdtCode) LEFT JOIN (VS4TProductSafeS LEFT JOIN VS4TBranch ON VS4TProductSafeS.TPSSTBraCode = VS4TBranch.TBraCode) ON VS4TProduct.TPdtCode = VS4TProductSafeS.TPSSTPdtCode) LEFT JOIN (VS4TProductStat LEFT JOIN VS4TCurrency ON VS4TProductStat.TPMSLastPTCurCode = VS4TCurrency.TCurCode) ON VS4TProduct.TPdtCode = VS4TProductStat.TPMSTPdtCode WHERE (((VS4TBranch.TBraTBrTAlias)='HEADOFFICE' Or (VS4TBranch.TBraTBrTAlias) Is Null))
GO

CREATE VIEW VS4VProductBook AS  SELECT VS4TProductBook.TPBGTPdtCode, VS4TProductBook.TPBGLn, VS4TProductBook.TPBGPaxMin, VS4TProductBook.TPBGPaxMax, VS4TProductBook.TPBGSeat, VS4TProductBook.TPBGBook, VS4TProductBook.TPBGRemain, VS4TProductBook.TPBGPaxCost, VS4TProductBook.TPBGFlag1, VS4TProductBook.TPBGConfirmBook, 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.TPBGToTCouCode2, VS4TProductBook.TPBGToPort2, VS4TProductBook.TPBGArrDate2, VS4TProductBook.TPBGArrTime2, VS4TProductBook.TPBGPrice, VS4TProductBook.TPBGIssTicketDate, VS4TProductBook.TPBGFor, VS4TProductBook.TPBGDepositStatus, VS4TProductBook.TPBGCheckDate, VS4TProductBook.TPBGDepositRate, VS4TProductBook.TPBGDepositAmount, VS4TProductBook.TPBGSplitRT, VS4TProductBook.TPBGNote, VS4TProductBook.TPBGGuide, VS4TProductBook.TPBGTL, VS4TProductBook.TPBGShareCostA, VS4TProductBook.TPBGShareCostB, VS4TProductBook.TPBGDepositSeat, VS4TProductBook.TPBGShareTPdtCode, VS4TProductBook.TPBGShare, VS4TProductBook.TPBGJoin, VS4TProductBook.TPBGDepositDate, VS4TProductBook.TPBGVisaDate, VS4TProductBook.TPBGLastBookDate, VS4TProductBook.TPBGPriority, VS4TProductBook.TPBGPortFromToAll, VS4TProductBook.TPBGFlightAll, VS4TProductBook.TPBGStatus, VS4TProductBook.TPBGMaxPaxUsePoint, VS4TProductBook.TPBGMaxPaxRecPoint, VS4TProductBook.TPBGMaxUsePoint, TPdtCode, TPdtBarcode, TPdtName, TPdtName2, TPdtAliasSlip, TPdtAliasName, TPdtTDwgCode, TPdtTPrjCode, TPdtDescription, TPdtUnitType, TPdtTUntCode, TPdtTUntCode2, TPdtTUntCode3, TPdtUnit2Ratio, TPdtUnit3Ratio, TPdtUsage, TPdtUseBOM, TPdtOldCode, TPdtFactoryCode, TPdtFactoryOldCode, TPdtFactoryName, TPdtTransferCode, TPdtTransferName, TPdtTransferName2, TPdtTAPNCode, TPdtTPTTCode, TPdtTPDLCode, TPdtTPSECode, TPdtTPS2Code, TPdtTPS3Code, TPdtTPS4Code, TPdtTPG1Code, TPdtTPG2Code, TPdtTPG3Code, TPdtTPG4Code, TPdtTBndCode, TPdtSceinceName, TPdtRegisterNo, TPdtUseMethod, TPdtWarning, TPdtGoodsDateLabel, TPdtExpDateLabel, TPdtQuantityText, TPdtIcon1, TPdtImage1, TPdtSpec1, TPdtTPCTAlias, TPdtCustom1, TPdtCustom2, TPdtCustom3, TPdtCustom4, TPdtCustom5, TPdtCustom6, TPdtCustom7, TPdtCustom8, TPdtCustom9, TPdtCustom10, TPdtSafeDayCalc, TPdtBackDayCalc, TPdtEOQ, TPdtOrderPoint, TPdtMaxUsePerDay, TPdtAvgUsePerDay, TPdtStockType, TPdtStockQuantity, TPdtFirstDate, TPdtLastMoveDate, TPdtFirstCostInStk, TPdtLastCost, TPdtStandardCost, TPdtStdCostCode, TPdtAutoCostCode, TPdtAverageCost, TPdtAreaCost, TPdtAmount, TPdtTPPuCode, TPdtSerialType, TPdtPurchaseFee, TPdtGroupReport, TPdtSlowDay, TPdtDeadDay, TPdtLastBalDate, TPdtCreateCode, TPdtCreateDate, TPdtEditCode, TPdtEditDate, TPdtTextSort, TPdtFlag1, TPdtPremiumCost, TPdtTACSCode, TPdtStartDate, TPdtEndDate, TPdtTripDay, TPdtTAILCode, TPdtTCouCode, TPdtONSale, TPdtSetType, TPdtRFID, TPdtHasExpireDate, TPdtRequireCOA, TPdtTBraCode, TPdtDayExpire, TPdtGrade, TPdtAdjustCost, TPdtLastUnitCost, TPdtUnitRatioType, TPd2TPdtCode, TPd2Ln, TPd2FillNameStock, TPd2ScrapPCMRP, TPd2ScrapPCReceive, TPd2ScrapPCSend, TPd2TaxType, TPd2TaxRate, TPd2CostFormula, TPd2Weight, TPd2SkipSuggest, TPd2QuantityAlert, TPd2TotalQuantity, TPd2Yield, TPd2HasBOM, TPd2TWRMCode, TPd2StdDM, TPd2StdDL, TPd2StdOH, TPd2StdOHType, TPd2ScrapType, TPd2BulkPOrder, TPd2MinimumPOrder, TPd2MultiplePOrder, TPd2VendorIncent1, TPd2VendorIncent2, TPd2BOMNote, TPd2SelfMat, TPd2StdDLType, TPOSCode, TPOSType, TPOSPackText1, TPOSPackText2, TPOSPackAlias1, TPOSPackAlias2, TPOSLeadDay, TPOSMultipleOrder, TPOSMinimumOrder, TPOSCutStock, TPOSPrice, TPOSLastPrice, TPOSLastPriceDate, TPOSHideAfterSold, TPOSSaleCount, TPOSFirstSaleDate, TPOSLastSaleDate, TPOSDisplaySub, TPOSDisplaySubMB, TPOSOnSale, TPOSRefund, TPOSWarranty, TPOSWarrantyUnit, TPOSWarrantyType, TPOSSaleStockMinus, TPOSTotalQuantity, TPOSFlag1, TPOSSaleCode, TPOSPeriod, TPOSTARNCode, TPOSTPSGCode, TPOSG1TAPNCode, TPOSG2TAPNCode, TPOSTLTAPNCode, TPOSTL2TAPNCode, TPOSTL3TAPNCode, TPOSTL4TAPNCode, TPOSG3TAPNCode, TPOSG4TAPNCode, TPOSS1TEmpCode, TPOSS2TEmpCode, TPOSPackDisplay, TPOSUnitCalc, VS4TAirline.TAILName, VS4TProductLine.TPdLName, VS4TProductSection.TPSEName, 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.*, TPdLCode, TPdLName, TPdLName2, TPdLTDivCode, TPdLDocCode, TPdlRequireSec1, TPdlRequireSec2, TPdlRequireSec3, TPdlRequireSec4, TPdlSectionName1, TPdlSectionName2, TPdlSectionName3, TPdlSectionName4, TPdlRequireGroup1, TPdlRequireGroup2, TPdlRequireGroup3, TPdlRequireGroup4, TPdlGroupName1, TPdlGroupName2, TPdlGroupName3, TPdlGroupName4,  TPdlCustomName, TPdlTACSCode, 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, VS4TPOS.TPOSType, VS4TProductSec2.TPS2Name 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) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) LEFT JOIN VS4TProduct3 ON VS4TProduct.TPdtCode = VS4TProduct3.TPD3TPdtCode) LEFT JOIN VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code) ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode) LEFT JOIN VS4TProduct2 ON VS4TProduct.TPdtCode = VS4TProduct2.TPd2TPdtCode
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) LEFT JOIN VS4TPOSSaleGroup ON VS4TPOS.TPOSTPSGCode = VS4TPOSSaleGroup.TPSGCode) INNER JOIN VS4TProduct2 ON VS4TProduct.TPdtCode = VS4TProduct2.TPd2TPdtCode
GO

CREATE VIEW VS4VPS AS  SELECT VS4TPS.*, VS4TPSMB.*, VS4TAP.*, VS4TProject.TPrjName, VS4TBranch.TBraName, VS4TBranch.TBraAddressBill, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TAPBranch.TAPUName 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 LEFT JOIN VS4TProduct ON VS4TPSMB.TPSMTPdtCode = VS4TProduct.TPdtCode) ON VS4TPS.TPSDNo = VS4TPSMB.TPSMTPSDNo) LEFT JOIN VS4TAPBranch ON (VS4TPS.TPSDTAPUCode = VS4TAPBranch.TAPUCode) AND (VS4TPS.TPSDTAPNCode = VS4TAPBranch.TAPUTAPNCode)
GO

CREATE VIEW VS4VInventAdjust AS  SELECT VS4TInventory.TInvNo, VS4TInventory.TInvMode, VS4TInventory.TInvTIBkCode, VS4TInventory.TInvDate, VS4TInventory.TInvTInTAlias, VS4TInventory.TInvRefNo, VS4TInventory.TInvRefDate, VS4TInventory.TInvTSecCode, VS4TInventory.TInvTDepCode, VS4TInventory.TInvTDivCode, VS4TInventory.TInvTBraCode, VS4TInventory.TInvFromTBraCode, VS4TInventory.TInvTotal, VS4TInventory.TInvTotalRecord, VS4TInventory.TInvTotalQuantity, VS4TInventory.TInvRequestCode, VS4TInventory.TInvRequestBy, VS4TInventory.TInvDescription, VS4TInventory.TInvGLMethod, VS4TInventory.TInvTGLTNo, VS4TInventory.TInvDeliveryStatus, VS4TInventory.TInvSpecialFlag, VS4TInventory.TInvEditCode, VS4TInventory.TInvEditBy, VS4TInventory.TInvEditDate, VS4TInventory.TInvConfirmStatus, VS4TInventory.TInvConfirmBy, VS4TInventory.TInvConfirmDate, VS4TInventory.TInvApproveStatus, VS4TInventory.TInvApproveBy, VS4TInventory.TInvApproveDate, VS4TInventory.TInvApproveNote, VS4TInventory.TInvRevision, VS4TInventory.TInvCancelStatus, VS4TInventory.TInvCancelBy, VS4TInventory.TInvCancelDate, VS4TInventory.TInvCancelNote, VS4TInventory.TInvFlag1, VS4TInventory.TInvCustomNo, VS4TInventory.TInvCustomDate, VS4TInventory.TInvTotalScrap, VS4TInventory.TInvTotalQScrap, VS4TInventory.TInvTotalQInput, VS4TInventory.TInvTotalAInput, VS4TInventory.TInvTotalRecordIn, VS4TInventory.TInvTotalPCScrap, VS4TInventory.TInvTotalPCQScrap, VS4TInventory.TInvSourceType, VS4TInventoryMB.TInMTInvNo, VS4TInventoryMB.TInMLn, VS4TInventoryMB.TInMTACPTACYID, VS4TInventoryMB.TInMTACPID, VS4TInventoryMB.TInMTPdtCode, VS4TInventoryMB.TInMCustom1, VS4TInventoryMB.TInMSerialNo, VS4TInventoryMB.TInMLotNo, VS4TInventoryMB.TInMLotDate, VS4TInventoryMB.TInMScrapLevel, VS4TInventoryMB.TInMQuantityCalc, VS4TInventoryMB.TInMUnitRatio, VS4TInventoryMB.TInMQuantityBase, VS4TInventoryMB.TInMTUntCode, VS4TInventoryMB.TInMInQuantity, VS4TInventoryMB.TInMOutQuantity, VS4TInventoryMB.TInMAmouQuantity, VS4TInventoryMB.TInMAmouQuantity2, VS4TInventoryMB.TInMAmouQuantity3, VS4TInventoryMB.TInMAmount, VS4TInventoryMB.TInMStatus, VS4TInventoryMB.TInMFromTLctCode, VS4TInventoryMB.TInMTLctCode, VS4TInventoryMB.TInMDescription, VS4TInventoryMB.TInMTInTAlias, VS4TInventoryMB.TInMTSODNo, VS4TInventoryMB.TInMTSOBLn, VS4TInventoryMB.TInMTMDSLn, VS4TInventoryMB.TInMSourceType, VS4TInventoryMB.TInMSourceNo, VS4TInventoryMB.TInMSourceLn, VS4TInventoryMB.TInMQuantityText, VS4TInventoryMB.TInMQuantityCutTxt, VS4TInventoryMB.TInMQuantityCut, VS4TInventoryMB.TInMQuantityFirst, VS4TInventoryMB.TInMArrear, VS4TInventoryMB.TInMShow, VS4TInventoryMB.TInMAgentPrice, VS4TInventoryMB.TInMQAStatus, VS4TInventoryMB.TInMQANote, VS4TInventoryMB.TInMTPltCode, VS4TInventoryMB.TInMFromTPltCode, VS4TInventoryMB.TInMQuantityCost, VS4TInventoryMB.TInMAgentPrice2, VS4TInventoryMB.TInMAgentPrice3, VS4TWarehouse.TWahName, VS4TLocation.TLctName, VS4TBranch.TBraName, VS4TProductType.TPTTName, VS4TInventoryType.TInTName, VS4TInventoryType.TInTDescription, VS4TLocation.TLctTBraCode, VS4TAR.TARNName, VS4TAP.TAPNName, VS4TInventoryType.TInTSort, VS4TPOS.TPOSPrice, VS4TJob.TJobCode, VS4TJob.TJobCustomerName, 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.TPdtTPG1Code, VS4TProduct.TPdtTPG2Code, VS4TProduct.TPdtTBndCode, VS4TProduct.TPdtImage1, VS4TProduct.TPdtTPCTAlias, VS4TProduct.TPdtOrderPoint, VS4TProduct.TPdtAvgUsePerDay, VS4TProduct.TPdtStockQuantity, VS4TProduct.TPdtLastCost, VS4TProduct.TPdtStdCostCode, VS4TProduct.TPdtAverageCost, VS4TProduct.TPdtSerialType, VS4TProduct.TPdtBackDayCalc, VS4TProduct.TPdtGroupReport, 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, VS4TJobMB.TJbMCustom4, VS4TJobMB.TJbMCustom5, 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, VS4TInventoryLOT.TIMCQAStatus, VS4TInventoryLOT.TIMCQANote, VS4TAR.TARNAddressBill, VS4TInventoryLOT.TIMCTAPNCode, VS4TInventoryLOT.TIMCInvoiceNo, VS4TInventoryLOT.TIMCInvoiceDate, VS4TInventoryLOT.TIMCTUntCode, VS4TInventoryLOT.TIMCUnitRatio, VS4TProduct.TPdtFlag1, VS4TProduct.TPdtPremiumCost, VS4VProductGroup.TPdLName, VS4VProductGroup.TPSEName, VS4VProductGroup.TPG1Name, VS4TInventoryLOT.TIMCAccountLevel, VS4TProduct.TPdtLastBalDate, VS4TPOS.TPOSPackAlias2, VS4TProduct.TPdtStandardCost, VS4TInventoryLOT.TIMCInputTCurCode, VS4TInventoryLOT.TIMCInputCostRate, VS4TInventoryLOT.TIMCAdjustCost, VS4TInventoryLOT.TIMCStandardCost, VS4TInventoryLOT.TIMCAVGCost, VS4TProductType.TPTTStockCost, VS4TProduct.TPdtStockType, VS4TProduct.TPdtCode, VS4TInventoryLOT.TIMCCOA, VS4TInventoryLOT.TIMCProposeStatus, VS4TInventoryLOT.TIMCProposeNote, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TProject.TPrjName, VS4TInventAdjustMB.TIjMQuantityBal, VS4TInventAdjustMB.TIjMQuantityAdj, VS4TInventAdjustMB.TIjMQuantityBal2, VS4TInventAdjustMB.TIjMQuantityAdj2, VS4TInventAdjustMB.TIjMQuantityBal3, VS4TInventAdjustMB.TIjMQuantityAdj3, VS4TInventAdjustMB.TIjMAmountAdj, VS4TInventAdjustMB.TIjMAmountBal, VS4TInventAdjustMB.TIjMType, VS4TInventAdjustMB.TIjMQuantityNew, VS4TInventAdjustMB.TIjMQuantityNew2, VS4TInventAdjustMB.TIjMQuantityNew3, VS4TInventoryLOT.TIMCQuantityCalc, VS4TLocation.TLctType, VS4TWarehouse.TWahGroup, VS4TInventoryLOT.TIMCVATType, VS4TInventoryLOT.TIMCVATRate, VS4TInventoryLOT.TIMCVATAmount, VS4TInventoryLOT.TIMCPrice, VS4TInventoryLOT.TIMCDutyRate, VS4TInventoryLOT.TIMCOtherFee, VS4TInventoryLOT.TIMCTransportFee, VS4TInventoryLOT.TIMCHandlingFee, VS4TInventoryLOT.TIMCFreightFee, VS4TInventoryLOT.TIMCInsurance, VS4TInventoryLOT.TIMCDutyAmount, VS4TInventoryLOT.TIMCTransportDesc, VS4TInventoryLOT.TIMCDM, VS4TInventoryLOT.TIMCDL, VS4TInventoryLOT.TIMCOS, VS4TInventoryLOT.TIMCMOH, VS4TInventoryLOT.TIMCCostAmount, VS4TInventoryLOT.TIMCQuantityCost, VS4TInventoryLOT.TIMCUnitRatioC, VS4TInventoryMB.TInMTIvSCode, VS4TInventBook.TIBkName, VS4TInventAdjustMB.TIjMAmountNew, VS4TProductStat.TPMSLastPTCurCode, VS4TCurrency.TCurLastRate, (TPMSLastPPrice*TCurLastRate*(TPd2TaxRate+100)/100) AS VIJMNetCost, VS4TAP.TAPNTCouCode, VS4TInventStatus.TIvSName FROM VS4TInventoryType INNER JOIN ((((((VS4TProduct LEFT JOIN VS4TProductType ON VS4TProduct.TPdtTPTTCode = VS4TProductType.TPTTCode) LEFT JOIN VS4VProductGroup ON VS4TProduct.TPdtCode = VS4VProductGroup.VPdtCode) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) INNER JOIN ((VS4TInventBook RIGHT 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) ON VS4TInventBook.TIBkCode = VS4TInventory.TInvTIBkCode) INNER JOIN (((((((VS4TInventoryMB LEFT JOIN VS4TLocation ON VS4TInventoryMB.TInMTLctCode = VS4TLocation.TLctCode) LEFT JOIN VS4TWarehouse ON VS4TLocation.TLctTWahCode = VS4TWarehouse.TWahCode) 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 (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)) LEFT JOIN VS4TInventStatus ON VS4TInventoryMB.TInMTIvSCode = VS4TInventStatus.TIvSCode) LEFT JOIN VS4TInventAdjustMB ON (VS4TInventoryMB.TInMLn = VS4TInventAdjustMB.TIjMLn) AND (VS4TInventoryMB.TInMTInvNo = VS4TInventAdjustMB.TIjMTIjtNo)) ON VS4TInventory.TInvNo = VS4TInventoryMB.TInMTInvNo) ON VS4TProduct.TPdtCode = VS4TInventoryMB.TInMTPdtCode) LEFT JOIN VS4TProduct2 ON VS4TProduct.TPdtCode = VS4TProduct2.TPd2TPdtCode) LEFT JOIN (VS4TProductStat LEFT JOIN VS4TCurrency ON VS4TProductStat.TPMSLastPTCurCode = VS4TCurrency.TCurCode) ON VS4TProduct.TPdtCode = VS4TProductStat.TPMSTPdtCode) ON VS4TInventoryType.TInTAlias = VS4TInventory.TInvTInTAlias WHERE (((VS4TInventory.TInvTInTAlias)='STOCKADJUST'))
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.TPTNTPdtCode) 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.TPdtCode, VS4TProduct.TPdtBarcode, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtAliasSlip, VS4TProduct.TPdtAliasName, VS4TProduct.TPdtTDwgCode,                    VS4TProduct.TPdtTPrjCode, VS4TProduct.TPdtDescription, VS4TProduct.TPdtUnitType, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3,                    VS4TProduct.TPdtUnit2Ratio, VS4TProduct.TPdtUnit3Ratio, VS4TProduct.TPdtUsage, VS4TProduct.TPdtUseBOM, VS4TProduct.TPdtOldCode, VS4TProduct.TPdtFactoryCode,                    VS4TProduct.TPdtFactoryOldCode, VS4TProduct.TPdtFactoryName, VS4TProduct.TPdtTransferCode, VS4TProduct.TPdtTransferName, VS4TProduct.TPdtTransferName2, VS4TProduct.TPdtTAPNCode,                    VS4TProduct.TPdtTPTTCode, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtTPSECode, VS4TProduct.TPdtTPS2Code, VS4TProduct.TPdtTPS3Code, VS4TProduct.TPdtTPS4Code,                    VS4TProduct.TPdtTPG1Code, VS4TProduct.TPdtTPG2Code, VS4TProduct.TPdtTPG3Code, VS4TProduct.TPdtTPG4Code, VS4TProduct.TPdtTBndCode, VS4TProduct.TPdtSceinceName,                    VS4TProduct.TPdtRegisterNo, VS4TProduct.TPdtUseMethod, VS4TProduct.TPdtWarning, VS4TProduct.TPdtGoodsDateLabel, VS4TProduct.TPdtExpDateLabel, VS4TProduct.TPdtQuantityText,                    VS4TProduct.TPdtIcon1, VS4TProduct.TPdtImage1, VS4TProduct.TPdtSpec1, VS4TProduct.TPdtTPCTAlias, VS4TProduct.TPdtCustom1, VS4TProduct.TPdtCustom2, VS4TProduct.TPdtCustom3,                    VS4TProduct.TPdtCustom4, VS4TProduct.TPdtCustom5, VS4TProduct.TPdtCustom6, VS4TProduct.TPdtCustom7, VS4TProduct.TPdtCustom8, VS4TProduct.TPdtCustom9, VS4TProduct.TPdtCustom10,                    VS4TProduct.TPdtSafeDayCalc, VS4TProduct.TPdtBackDayCalc, VS4TProduct.TPdtEOQ, VS4TProduct.TPdtOrderPoint, VS4TProduct.TPdtMaxUsePerDay, VS4TProduct.TPdtAvgUsePerDay,                    VS4TProduct.TPdtStockType, VS4TProduct.TPdtStockQuantity, VS4TProduct.TPdtFirstDate, VS4TProduct.TPdtLastMoveDate, VS4TProduct.TPdtFirstCostInStk, VS4TProduct.TPdtLastCost,                    VS4TProduct.TPdtStandardCost, VS4TProduct.TPdtStdCostCode, VS4TProduct.TPdtAutoCostCode, VS4TProduct.TPdtAverageCost, VS4TProduct.TPdtAreaCost, VS4TProduct.TPdtAmount,                    VS4TProduct.TPdtTPPuCode, VS4TProduct.TPdtSerialType, VS4TProduct.TPdtPurchaseFee, VS4TProduct.TPdtGroupReport, VS4TProduct.TPdtSlowDay, VS4TProduct.TPdtDeadDay,                    VS4TProduct.TPdtLastBalDate, VS4TProduct.TPdtCreateCode, VS4TProduct.TPdtCreateDate, VS4TProduct.TPdtEditCode, VS4TProduct.TPdtEditDate, VS4TProduct.TPdtTextSort, VS4TProduct.TPdtFlag1,                    VS4TProduct.TPdtFlag2, VS4TProduct.TPdtFlag3, VS4TProduct.TPdtPremiumCost, VS4TProduct.TPdtTACSCode, VS4TProduct.TPdtStartDate, VS4TProduct.TPdtEndDate, VS4TProduct.TPdtTripDay,                    VS4TProduct.TPdtTAILCode, VS4TProduct.TPdtTCouCode, VS4TProduct.TPdtONSale, VS4TProduct.TPdtSetType, VS4TProduct.TPdtRFID, VS4TProduct.TPdtHasExpireDate, VS4TProduct.TPdtRequireCOA,                    VS4TProduct.TPdtTBraCode, VS4TProduct.TPdtDayExpire, VS4TProduct.TPdtGrade, VS4TProduct.TPdtAdjustCost, VS4TProduct.TPdtLastUnitCost, VS4TProduct.TPdtUnitRatioType,                    VS4TProductSection.TPSECode, VS4TProductSection.TPSEName, VS4TProductSection.TPSEName2, VS4TProductSection.TPSETPdLCode, VS4TProductSection.TPSEDocCode,                    VS4TProductSection.TPSECapacity, VS4TProductSection.TPSECapacityHour, VS4TProductSection.TPSEStartWIPPC, VS4TProductSection.TPSEStandardCost, VS4TProductSection.TPSEFlag1,                    VS4TProductSection.TPSEFlag2, VS4TProductSection.TPSEFlag3, VS4TProductSection.TPSETACSCode, VS4TProductSection.TPSEBudget, VS4TProductLine.TPdLCode, VS4TProductLine.TPdLName,                    VS4TProductLine.TPdLName2, VS4TProductLine.TPdLTDivCode, VS4TProductLine.TPdLDocCode, VS4TProductLine.TPdlRequireSec1, VS4TProductLine.TPdlRequireSec2, VS4TProductLine.TPdlRequireSec3,                    VS4TProductLine.TPdlRequireSec4, VS4TProductLine.TPdlSectionName1, VS4TProductLine.TPdlSectionName2, VS4TProductLine.TPdlSectionName3, VS4TProductLine.TPdlSectionName4,                    VS4TProductLine.TPdlRequireGroup1, VS4TProductLine.TPdlRequireGroup2, VS4TProductLine.TPdlRequireGroup3, VS4TProductLine.TPdlRequireGroup4, VS4TProductLine.TPdlGroupName1,                    VS4TProductLine.TPdlGroupName2, VS4TProductLine.TPdlGroupName3, VS4TProductLine.TPdlGroupName4, VS4TProductLine.TPdlCustomName, VS4TProductLine.TPdLFlag1, VS4TProductLine.TPdlTACSCode,                    VS4TPOS.TPOSPrice, VS4TAP.TAPNName, VS4TProduct2.TPd2TPdtCode, VS4TProduct2.TPd2Ln, VS4TProduct2.TPd2FillNameStock, VS4TProduct2.TPd2ScrapPCMRP, VS4TProduct2.TPd2ScrapPCReceive,                    VS4TProduct2.TPd2ScrapPCSend, VS4TProduct2.TPd2TaxType, VS4TProduct2.TPd2TaxRate, VS4TProduct2.TPd2CostFormula, VS4TProduct2.TPd2Weight, VS4TProduct2.TPd2SkipSuggest,                    VS4TProduct2.TPd2QuantityAlert, VS4TProduct2.TPd2TotalQuantity, VS4TProduct2.TPd2Yield, VS4TProduct2.TPd2HasBOM, VS4TProduct2.TPd2TWRMCode, VS4TProduct2.TPd2StdDM,                    VS4TProduct2.TPd2StdDL, VS4TProduct2.TPd2StdOH, VS4TProduct2.TPd2StdOHType, VS4TProduct2.TPd2ScrapType, VS4TProduct2.TPd2BulkPOrder, VS4TProduct2.TPd2MinimumPOrder,                    VS4TProduct2.TPd2MultiplePOrder, VS4TProduct2.TPd2Flag1, VS4TProduct2.TPd2Flag2, VS4TProduct2.TPd2Flag3, VS4TProduct2.TPd2VendorIncent1, VS4TProduct2.TPd2VendorIncent2,                    VS4TProduct2.TPd2BOMNote, VS4TProduct2.TPd2SelfMat, VS4TProduct2.TPd2StdDLType, 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.TPMtTPdtCode, VS4TProductMat.TPMtTSpdStep, VS4TProductMat.TPMtLn, VS4TProductMat.TPMtMatType,                    VS4TProductMat.TPMtProductCode, VS4TProductMat.TPMtProductName, VS4TProductMat.TPMtQuantity, VS4TProductMat.TPMtUnitCode, VS4TProductMat.TPMtQuantity2, VS4TProductMat.TPMtUnitCode2,                    VS4TProductMat.TPMtQuantity3, VS4TProductMat.TPMtUnitCode3, VS4TProductMat.TPMtRemark, VS4TProductMat.TPMtFlag1, VS4TProductMat.TPMtFlag2, VS4TProductMat.TPMtFlag3,                    VS4TProductMat.TPMtAlternative, VS4TProductMat.TPmtNo, VS4TProductMat.TPMtCustom1, VS4TProductMat.TPMtCustom2, VS4TProductMat.TPMtCustom3, VS4TProductMat.TPMtCustom4,                    VS4TProductMat.TPMtCustom5, VS4TProductMat.TPMtAutoExplore, VS4TProductMat.TPMtScrapPCMRP, 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,                    VS4TProduct_1.TPdtTAPNCode AS VPmtTAPNCode, VS4TAP_1.TAPNName AS VPmtTAPNName, VS4TAP_1.TAPNTCouCode AS VPmtTCouCode, VS4TProductStat.TPMSLastPPrice, VS4TProductStat.TPMSLastPTCurCode,                    VS4TCurrency.TCurLastRate, VS4TCurrency.TCurBOMRate, VS4TProduct2_1.TPd2TaxRate AS VPMtTaxRate, (VS4TProductStat.TPMSLastPPrice * VS4TCurrency.TCurLastRate) * (VS4TProduct2_1.TPd2TaxRate + 100)                    / 100 AS VPMtNetCost, VS4TProduct_1.TPdtLastUnitCost AS VPmtLastUnitCost, VS4TProduct_1.TPdtAverageCost AS VPmtAverageCost, VS4TProduct_1.TPdtLastCost AS VPmtLastCost FROM     VS4TProductSection RIGHT OUTER JOIN                   VS4TProductType RIGHT OUTER JOIN                   VS4TProductPURType RIGHT OUTER JOIN                   VS4TProductCalcTyp RIGHT OUTER JOIN                   VS4TProduct LEFT OUTER JOIN                   VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code LEFT OUTER JOIN                   VS4TBrand ON VS4TProduct.TPdtTBndCode = VS4TBrand.TBndCode LEFT OUTER JOIN                   VS4TProductGroup2 ON VS4TProduct.TPdtTPG2Code = VS4TProductGroup2.TPG2Code LEFT OUTER JOIN                   VS4TProductGroup3 ON VS4TProduct.TPdtTPG3Code = VS4TProductGroup3.TPG3Code LEFT OUTER JOIN                   VS4TProductGroup4 ON VS4TProduct.TPdtTPG4Code = VS4TProductGroup4.TPG4Code LEFT OUTER JOIN                   VS4TProductLine ON VS4TProduct.TPdtTPDLCode = VS4TProductLine.TPdLCode LEFT OUTER JOIN                   VS4TAP ON VS4TProduct.TPdtTAPNCode = VS4TAP.TAPNCode ON VS4TProductCalcTyp.TPCTAlias = VS4TProduct.TPdtTPCTAlias ON VS4TProductPURType.TPPuCode = VS4TProduct.TPdtTPPuCode ON                    VS4TProductType.TPTTCode = VS4TProduct.TPdtTPTTCode LEFT OUTER JOIN                   VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode LEFT OUTER JOIN                   VS4TProduct2 ON VS4TProduct.TPdtCode = VS4TProduct2.TPd2TPdtCode INNER JOIN                   VS4TProductMat LEFT OUTER JOIN                   VS4TProduct AS VS4TProduct_1 ON VS4TProductMat.TPMtProductCode = VS4TProduct_1.TPdtCode LEFT OUTER JOIN                   VS4TAP AS VS4TAP_1 ON VS4TProduct_1.TPdtTAPNCode = VS4TAP_1.TAPNCode LEFT OUTER JOIN                   VS4TProductStat ON VS4TProduct_1.TPdtCode = VS4TProductStat.TPMSTPdtCode LEFT OUTER JOIN                   VS4TProduct2 AS VS4TProduct2_1 ON VS4TProduct_1.TPdtCode = VS4TProduct2_1.TPd2TPdtCode LEFT OUTER JOIN                   VS4TCurrency ON VS4TProductStat.TPMSLastPTCurCode = VS4TCurrency.TCurCode 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.TPdtCode, VS4VProduct.TPdtBarcode, VS4VProduct.TPdtName, VS4VProduct.TPdtName2, VS4VProduct.TPdtAliasSlip, VS4VProduct.TPdtAliasName, VS4VProduct.TPdtTDwgCode, VS4VProduct.TPdtTPrjCode, VS4VProduct.TPdtDescription, VS4VProduct.TPdtUnitType, VS4VProduct.TPdtTUntCode, VS4VProduct.TPdtTUntCode2, VS4VProduct.TPdtTUntCode3, VS4VProduct.TPdtUnit2Ratio, VS4VProduct.TPdtUnit3Ratio, VS4VProduct.TPdtUsage, VS4VProduct.TPdtUseBOM, VS4VProduct.TPdtOldCode, VS4VProduct.TPdtFactoryCode, VS4VProduct.TPdtFactoryOldCode, VS4VProduct.TPdtFactoryName, VS4VProduct.TPdtTransferCode, VS4VProduct.TPdtTransferName, VS4VProduct.TPdtTransferName2, VS4VProduct.TPdtTAPNCode, VS4VProduct.TPdtTPTTCode, VS4VProduct.TPdtTPDLCode, VS4VProduct.TPdtTPSECode, VS4VProduct.TPdtTPS2Code, VS4VProduct.TPdtTPS3Code, VS4VProduct.TPdtTPS4Code, VS4VProduct.TPdtTPG1Code, VS4VProduct.TPdtTPG2Code, VS4VProduct.TPdtTPG3Code, VS4VProduct.TPdtTPG4Code, VS4VProduct.TPdtTBndCode, VS4VProduct.TPdtSceinceName, VS4VProduct.TPdtRegisterNo, VS4VProduct.TPdtUseMethod, VS4VProduct.TPdtWarning, VS4VProduct.TPdtGoodsDateLabel, VS4VProduct.TPdtExpDateLabel, VS4VProduct.TPdtQuantityText, VS4VProduct.TPdtIcon1, VS4VProduct.TPdtImage1, VS4VProduct.TPdtSpec1, VS4VProduct.TPdtTPCTAlias, VS4VProduct.TPdtCustom1, VS4VProduct.TPdtCustom2, VS4VProduct.TPdtCustom3, VS4VProduct.TPdtCustom4, VS4VProduct.TPdtCustom5, VS4VProduct.TPdtCustom6, VS4VProduct.TPdtCustom7, VS4VProduct.TPdtCustom8, VS4VProduct.TPdtCustom9, VS4VProduct.TPdtCustom10, VS4VProduct.TPdtSafeDayCalc, VS4VProduct.TPdtBackDayCalc, VS4VProduct.TPdtEOQ, VS4VProduct.TPdtOrderPoint, VS4VProduct.TPdtMaxUsePerDay, VS4VProduct.TPdtAvgUsePerDay, VS4VProduct.TPdtStockType, VS4VProduct.TPdtStockQuantity, VS4VProduct.TPdtFirstDate, VS4VProduct.TPdtLastMoveDate, VS4VProduct.TPdtFirstCostInStk, VS4VProduct.TPdtLastCost, VS4VProduct.TPdtStandardCost, VS4VProduct.TPdtStdCostCode, VS4VProduct.TPdtAutoCostCode, VS4VProduct.TPdtAverageCost, VS4VProduct.TPdtAreaCost, VS4VProduct.TPdtAmount, VS4VProduct.TPdtTPPuCode, VS4VProduct.TPdtSerialType, VS4VProduct.TPdtPurchaseFee, VS4VProduct.TPdtGroupReport, VS4VProduct.TPdtSlowDay, VS4VProduct.TPdtDeadDay, VS4VProduct.TPdtLastBalDate, VS4VProduct.TPdtCreateCode, VS4VProduct.TPdtCreateDate, VS4VProduct.TPdtEditCode, VS4VProduct.TPdtEditDate, VS4VProduct.TPdtTextSort, VS4VProduct.TPdtFlag1, VS4VProduct.TPdtFlag2, VS4VProduct.TPdtFlag3, VS4VProduct.TPdtPremiumCost, VS4VProduct.TPdtTACSCode, VS4VProduct.TPdtStartDate, VS4VProduct.TPdtEndDate, VS4VProduct.TPdtTripDay, VS4VProduct.TPdtTAILCode, VS4VProduct.TPdtTCouCode, VS4VProduct.TPdtONSale, VS4VProduct.TPdtSetType, VS4VProduct.TPdtRFID, VS4VProduct.TPdtHasExpireDate, VS4VProduct.TPdtRequireCOA, VS4VProduct.TPdtTBraCode, VS4VProduct.TPdtDayExpire, VS4VProduct.TPdtGrade, VS4VProduct.TPdtAdjustCost, VS4VProduct.TPdtLastUnitCost, VS4VProduct.TPdtUnitRatioType, VS4VProduct.TPd2TPdtCode, VS4VProduct.TPd2FillNameStock, VS4VProduct.TPd2ScrapPCMRP, VS4VProduct.TPd2ScrapPCReceive, VS4VProduct.TPd2ScrapPCSend, VS4VProduct.TPd2TaxType, VS4VProduct.TPd2TaxRate, VS4VProduct.TPd2CostFormula, VS4VProduct.TPd2Weight, VS4VProduct.TPd2SkipSuggest, VS4VProduct.TPd2QuantityAlert, VS4VProduct.TPd2TotalQuantity, VS4VProduct.TPd2Yield, VS4VProduct.TPd2HasBOM, VS4VProduct.TPd2SelfMat, VS4VProduct.TPd2TWRMCode, VS4VProduct.TPd2StdDM, VS4VProduct.TPd2StdDL, VS4VProduct.TPd2StdOH, VS4VProduct.TPd2StdOHType, VS4VProduct.TPd2ScrapType, VS4VProduct.TPd2BulkPOrder, VS4VProduct.TPd2MinimumPOrder, VS4VProduct.TPd2MultiplePOrder, VS4VProduct.TPd2VendorIncent1, VS4VProduct.TPd2VendorIncent2, VS4VProduct.TPd2BOMNote, VS4VProduct.TPD3PackText11, VS4VProduct.TPD3PackText12, VS4VProduct.TPD3PackText13, VS4VProduct.TPD3PackText14, VS4VProduct.TPD3PackText15, VS4VProduct.TPD3PackText16, VS4VProduct.TPD3PackAlias21, VS4VProduct.TPD3PackAlias22, VS4VProduct.TPD3PackAlias23, VS4VProduct.TPD3PackAlias24, VS4VProduct.TPD3PackAlias25, VS4VProduct.TPD3PackAlias26, VS4VProduct.TPD3Flag1, VS4VProduct.TPD3Flag2, VS4VProduct.TPD3Flag3, VS4VProduct.TPd3Custom11, VS4VProduct.TPd3Custom12, VS4VProduct.TPd3Custom13, VS4VProduct.TPd3Custom14, VS4VProduct.TPd3Custom15, VS4VProduct.TPd3Custom16, VS4VProduct.TPd3Custom17, VS4VProduct.TPd3Custom18, VS4VProduct.TPd3Custom19, VS4VProduct.TPd3Custom20, VS4VProduct.TPd3Custom21, VS4VProduct.TPd3Custom22, VS4VProduct.TPd3Custom23, VS4VProduct.TPd3Custom24, VS4VProduct.TPd3Custom25, VS4VProduct.TPd3Custom26, VS4VProduct.TPd3Custom27, VS4VProduct.TPd3Custom28, VS4VProduct.TPd3Custom29, VS4VProduct.TPd3Custom30, VS4VProduct.TPOSCode, VS4VProduct.TPOSType, VS4VProduct.TPOSPackText1, VS4VProduct.TPOSPackText2, VS4VProduct.TPOSPackAlias1, VS4VProduct.TPOSPackAlias2, VS4VProduct.TPOSLeadDay, VS4VProduct.TPOSMultipleOrder, VS4VProduct.TPOSMinimumOrder, VS4VProduct.TPOSCutStock, VS4VProduct.TPOSPrice, VS4VProduct.TPOSLastPrice, VS4VProduct.TPOSLastPriceDate, VS4VProduct.TPOSHideAfterSold, VS4VProduct.TPOSSaleCount, VS4VProduct.TPOSFirstSaleDate, VS4VProduct.TPOSLastSaleDate, VS4VProduct.TPOSDisplaySub, VS4VProduct.TPOSDisplaySubMB, VS4VProduct.TPOSOnSale, VS4VProduct.TPOSRefund, VS4VProduct.TPOSWarranty, VS4VProduct.TPOSWarrantyUnit, VS4VProduct.TPOSWarrantyType, VS4VProduct.TPOSSaleStockMinus, VS4VProduct.TPOSTotalQuantity, VS4VProduct.TPOSFlag1, VS4VProduct.TPOSPackDisplay, VS4VProduct.TPOSSaleCode, VS4VProduct.TPOSPeriod, VS4VProduct.TPOSTARNCode, VS4VProduct.TPOSTPSGCode, VS4VProduct.TPOSG1TAPNCode, VS4VProduct.TPOSG2TAPNCode, VS4VProduct.TPOSTLTAPNCode, VS4VProduct.TPOSTL2TAPNCode, VS4VProduct.TPOSTL3TAPNCode, VS4VProduct.TPOSTL4TAPNCode, VS4VProduct.TPOSG3TAPNCode, VS4VProduct.TPOSG4TAPNCode, VS4VProduct.TPOSS1TEmpCode, VS4VProduct.TPOSS2TEmpCode, VS4VProduct.TAPNName, VS4VProduct.TBndCode, VS4VProduct.TBndName, VS4VProduct.TPTTCode, VS4VProduct.TPTTName, VS4VProduct.TPTTDocCode, VS4VProduct.TPCTAlias, VS4VProduct.TPCTName, VS4VProduct.TPPuCode, VS4VProduct.TPPuName, VS4VProduct.TPG1Code, VS4VProduct.TPG1Name, VS4VProduct.TPG2Code, VS4VProduct.TPG2Name, VS4VProduct.TPG3Code, VS4VProduct.TPG3Name, VS4VProduct.TPG4Code, VS4VProduct.TPG4Name, VS4VProduct.TPdLCode, VS4VProduct.TPdLName, VS4VProduct.TPdLName2, VS4VProduct.TPdLTDivCode, VS4VProduct.TPdLDocCode, VS4VProduct.TPdLTACSCode, VS4VProduct.TPSECode, VS4VProduct.TPSEName, VS4VProduct.TPSEName2, VS4VProduct.TPDLCustomName, VS4VProduct.TPdlGroupName1, VS4VProduct.TPdlGroupName2, VS4VProduct.TPdlGroupName3, VS4VProduct.TPdlGroupName4, VS4VProduct.TPMSLastPPrice, VS4VProduct.TPMSLastPTCurCode, VS4VProduct.TCurLastRate, VS4VProduct.VPdtNetCost FROM VS4VInventPdtL LEFT JOIN VS4VProduct ON VS4VInventPdtL.TInMTPdtCode = VS4VProduct.TPdtCode
GO

CREATE VIEW VS4VSOArrearSum AS  SELECT VS4TSOMB.TSOBTPOSCode, Sum(VS4TSOMB.TSOBQuantity) AS TSOBQuantity, Sum(VS4TSOMB.TSOBTotalArrear) AS TSOBTotalArrear, Sum(VS4TSOMB.TSOBQuantity*TSOBUnitFactor) AS TSOBQuantityBase, Sum(VS4TSOMB.TSOBTotalArrear*TSOBUnitFactor) AS TSOBTotalArrearBas FROM VS4TSO INNER JOIN VS4TSOMB ON VS4TSO.TSODNo = VS4TSOMB.TSOBTSODNo GROUP BY VS4TSOMB.TSOBTPOSCode, VS4TSO.TSODApproveStatus, VS4TSO.TSODCancelStatus HAVING (((VS4TSO.TSODApproveStatus)=1) AND ((VS4TSO.TSODCancelStatus)=0))
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.*, VS4TProductUnit.*, 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
GO

CREATE VIEW VS4VProductVendor AS  SELECT VS4TProduct.*, VS4TProduct2.TPd2TPdtCode, VS4TProduct2.TPd2FillNameStock, VS4TProduct2.TPd2ScrapPCMRP, VS4TProduct2.TPd2ScrapPCReceive, VS4TProduct2.TPd2ScrapPCSend, VS4TProduct2.TPd2TaxType, VS4TProduct2.TPd2TaxRate, VS4TProduct2.TPd2CostFormula, VS4TProduct2.TPd2Weight, VS4TProduct2.TPd2SkipSuggest, VS4TProduct2.TPd2QuantityAlert, VS4TProduct2.TPd2TotalQuantity, VS4TProduct2.TPd2Yield, VS4TProduct2.TPd2HasBOM, VS4TProduct2.TPd2SelfMat, VS4TProduct2.TPd2TWRMCode, VS4TProduct2.TPd2StdDM, VS4TProduct2.TPd2StdDL, VS4TProduct2.TPd2StdOH, VS4TProduct2.TPd2StdOHType, VS4TProduct2.TPd2ScrapType, VS4TProduct2.TPd2BulkPOrder, VS4TProduct2.TPd2MinimumPOrder, VS4TProduct2.TPd2MultiplePOrder, VS4TProduct2.TPd2VendorIncent1, VS4TProduct2.TPd2VendorIncent2, VS4TProduct2.TPd2BOMNote, VS4TProduct3.TPD3PackText11, VS4TProduct3.TPD3PackText12, VS4TProduct3.TPD3PackText13, VS4TProduct3.TPD3PackText14, VS4TProduct3.TPD3PackText15, VS4TProduct3.TPD3PackText16, VS4TProduct3.TPD3PackAlias21, VS4TProduct3.TPD3PackAlias22, VS4TProduct3.TPD3PackAlias23, VS4TProduct3.TPD3PackAlias24, VS4TProduct3.TPD3PackAlias25, VS4TProduct3.TPD3PackAlias26, VS4TProduct3.TPD3Flag1, VS4TProduct3.TPD3Flag2, VS4TProduct3.TPD3Flag3, VS4TProduct3.TPd3Custom11, VS4TProduct3.TPd3Custom12, VS4TProduct3.TPd3Custom13, VS4TProduct3.TPd3Custom14, VS4TProduct3.TPd3Custom15, VS4TProduct3.TPd3Custom16, VS4TProduct3.TPd3Custom17, VS4TProduct3.TPd3Custom18, VS4TProduct3.TPd3Custom19, VS4TProduct3.TPd3Custom20, VS4TProduct3.TPd3Custom21, VS4TProduct3.TPd3Custom22, VS4TProduct3.TPd3Custom23, VS4TProduct3.TPd3Custom24, VS4TProduct3.TPd3Custom25, VS4TProduct3.TPd3Custom26, VS4TProduct3.TPd3Custom27, VS4TProduct3.TPd3Custom28, VS4TProduct3.TPd3Custom29, VS4TProduct3.TPd3Custom30, VS4TPOS.TPOSCode, VS4TPOS.TPOSType, VS4TPOS.TPOSPackText1, VS4TPOS.TPOSPackText2, VS4TPOS.TPOSPackAlias1, VS4TPOS.TPOSPackAlias2, VS4TPOS.TPOSLeadDay, VS4TPOS.TPOSMultipleOrder, VS4TPOS.TPOSMinimumOrder, VS4TPOS.TPOSCutStock, VS4TPOS.TPOSPrice, VS4TPOS.TPOSLastPrice, VS4TPOS.TPOSLastPriceDate, VS4TPOS.TPOSHideAfterSold, VS4TPOS.TPOSSaleCount, VS4TPOS.TPOSFirstSaleDate, VS4TPOS.TPOSLastSaleDate, VS4TPOS.TPOSDisplaySub, VS4TPOS.TPOSDisplaySubMB, VS4TPOS.TPOSOnSale, VS4TPOS.TPOSRefund, VS4TPOS.TPOSWarranty, VS4TPOS.TPOSWarrantyUnit, VS4TPOS.TPOSWarrantyType, VS4TPOS.TPOSSaleStockMinus, VS4TPOS.TPOSTotalQuantity, VS4TPOS.TPOSFlag1, VS4TPOS.TPOSPackDisplay, VS4TPOS.TPOSSaleCode, VS4TPOS.TPOSPeriod, VS4TPOS.TPOSTARNCode, VS4TPOS.TPOSTPSGCode, VS4TPOS.TPOSG1TAPNCode, VS4TPOS.TPOSG2TAPNCode, VS4TPOS.TPOSTLTAPNCode, VS4TPOS.TPOSTL2TAPNCode, VS4TPOS.TPOSTL3TAPNCode, VS4TPOS.TPOSTL4TAPNCode, VS4TPOS.TPOSG3TAPNCode, VS4TPOS.TPOSG4TAPNCode, VS4TPOS.TPOSS1TEmpCode, VS4TPOS.TPOSS2TEmpCode, 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, VS4TProductLine.TPdLCode, VS4TProductLine.TPdLName, VS4TProductLine.TPdLName2, VS4TProductLine.TPdLTDivCode, VS4TProductLine.TPdLDocCode, VS4TProductLine.TPdLTACSCode, VS4TProductSection.TPSECode, VS4TProductSection.TPSEName, VS4TProductSection.TPSEName2, VS4TProductLine.TPDLCustomName, VS4TProductLine.TPDLGroupName1, VS4TProductLine.TPDLGroupName2, VS4TProductLine.TPDLGroupName3, VS4TProductLine.TPDLGroupName4, VS4TProductStat.TPMSLastPPrice, VS4TProductStat.TPMSLastPTCurCode, VS4TCurrency.TCurLastRate, (TPMSLastPPrice*TCurLastRate*(TPd2TaxRate+100)/100) AS VPdtNetCost, VS4TProductVender.TPdVTAPNCode, VS4TProductSec2.TPS2Name 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) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) LEFT JOIN VS4TProduct3 ON VS4TProduct.TPdtCode = VS4TProduct3.TPD3TPdtCode) LEFT JOIN VS4TProductVender ON VS4TProduct.TPdtCode = VS4TProductVender.TPdVTPdtcode) LEFT JOIN VS4TAP AS VS4TAP_1 ON VS4TProductVender.TPdVTAPNCode = VS4TAP_1.TAPNCode) LEFT JOIN VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code) ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode) LEFT JOIN VS4TProduct2 ON VS4TProduct.TPdtCode = VS4TProduct2.TPd2TPdtCode) LEFT JOIN (VS4TProductStat LEFT JOIN VS4TCurrency ON VS4TProductStat.TPMSLastPTCurCode = VS4TCurrency.TCurCode) ON VS4TProduct.TPdtCode = VS4TProductStat.TPMSTPdtCode
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.*, VS4TProjectModule.*, VS4TProjectKind.* FROM (VS4TProjectType INNER JOIN VS4TProject ON VS4TProjectType.TPjTCode = VS4TProject.TPrjTPjTCode) INNER JOIN (((VS4TProjectPhase LEFT JOIN VS4TProjectKind ON VS4TProjectPhase.TPHSTPjKCode = VS4TProjectKind.TPjKCode) LEFT JOIN VS4TProjectModule ON VS4TProjectPhase.TPHSTPjMCode = VS4TProjectModule.TPjMCode) 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.*, VS4TAR.TARNName, VS4TARGroup.TARGName, VS4TPromotionSet.TPrSName, VS4TProductLine.TPdLName, VS4TProductSection.TPSEName, VS4TProductGroup1.TPG1Name, VS4TProduct.*, VS4TPOS.TPOSCode, VS4TPOS.TPOSType, VS4TPOS.TPOSPrice, VS4TAP.TAPNName FROM VS4TPromotion INNER JOIN (((((((((VS4TPOS RIGHT JOIN VS4TPromotionMB ON VS4TPOS.TPOSCode = VS4TPromotionMB.TPMMTPOSCode) LEFT JOIN VS4TProductLine ON VS4TPromotionMB.TPMMTPDLCode = VS4TProductLine.TPdLCode) LEFT JOIN VS4TProductSection ON VS4TPromotionMB.TPMMTPSECode = VS4TProductSection.TPSECode) LEFT JOIN VS4TProductGroup1 ON VS4TPromotionMB.TPMMTPG1Code = VS4TProductGroup1.TPG1Code) LEFT JOIN VS4TAR ON VS4TPromotionMB.TPMMTARNCode = VS4TAR.TARNCode) LEFT JOIN VS4TARGroup ON VS4TPromotionMB.TPMMTARGCode = VS4TARGroup.TARGCode) LEFT JOIN VS4TPromotionSet ON VS4TPromotionMB.TPMMTPRSCode = VS4TPromotionSet.TPrSCode) LEFT JOIN VS4TProduct ON VS4TPOS.TPOSCode = VS4TProduct.TPdtCode) LEFT JOIN VS4TAP ON VS4TPromotionMB.TPMMTAPNCode = VS4TAP.TAPNCode) 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 VS4VRVPay AS SELECT VS4TARVoucher.TRVHNo, VS4TARVoucher.TRVHType, VS4TARVoucher.TRVHDetailType, VS4TARVoucher.TRVHMode, VS4TARVoucher.TRVHBalanceFlag, VS4TARVoucher.TRVHBaseArrear,                    VS4TARVoucher.TRVHArrear, VS4TARVoucher.TRVHDate, VS4TARVoucher.TRVHTBraCode, VS4TARVoucher.TRVHPaymentStatus, VS4TARVoucher.TRVHRefNo, VS4TARVoucher.TRVHRefDate,                    VS4TARVoucher.TRVHTARNCode, VS4TARVoucher.TRVHPayTo, VS4TARVoucher.TRVHAddress, VS4TARVoucher.TRVHPayTo2, VS4TARVoucher.TRVHAddress2, VS4TARVoucher.TRVHCurDiscount,                    VS4TARVoucher.TRVHCurRate, VS4TARVoucher.TRVHCurAmount, VS4TARVoucher.TRVHSubTotal, VS4TARVoucher.TRVHDiscount, VS4TARVoucher.TRVHPayLess, VS4TARVoucher.TRVHAdjustTotal,                    VS4TARVoucher.TRVHFee, VS4TARVoucher.TRVHNetAmount, VS4TARVoucher.TRVHTaxBase, VS4TARVoucher.TRVHWTaxTotal, VS4TARVoucher.TRVHTaxBase2, VS4TARVoucher.TRVHWTaxTotal2,                    VS4TARVoucher.TRVHTotal, VS4TARVoucher.TRVHNote, VS4TARVoucher.TRVHTGLBCode, VS4TARVoucher.TRVHTPrjCode, VS4TARVoucher.TRVHGLMethod, VS4TARVoucher.TRVHTGLTNo,                    VS4TARVoucher.TRVHTTeTNo, VS4TARVoucher.TRVHVATNo, VS4TARVoucher.TRVHTaxPeriodNo, VS4TARVoucher.TRVHTaxPeriodType, VS4TARVoucher.TRVHTaxRefund, VS4TARVoucher.TRVHPayType,                    VS4TARVoucher.TRVHTaxNo, VS4TARVoucher.TRVHWTaxPeriodNo, VS4TARVoucher.TRVHWTaxPeriodType, VS4TARVoucher.TRVHChequePayment, VS4TARVoucher.TRVHCashPayment,                    VS4TARVoucher.TRVHBankPayment, VS4TARVoucher.TRVHCardPayment, VS4TARVoucher.TRVHPayCoupon, VS4TARVoucher.TRVHPayOther, VS4TARVoucher.TRVHPayMisc,                    VS4TARVoucher.TRVHCutDeposit, VS4TARVoucher.TRVHCommissionBase, VS4TARVoucher.TRVHCommissionRate, VS4TARVoucher.TRVHCommission, VS4TARVoucher.TRVHInterestRate,                    VS4TARVoucher.TRVHInterestTotal, VS4TARVoucher.TRVHCardFlag, VS4TARVoucher.TRVHTaxFlag, VS4TARVoucher.TRVHCreateCode, VS4TARVoucher.TRVHCreateBy, VS4TARVoucher.TRVHCreateDate,                    VS4TARVoucher.TRVHEditCode, VS4TARVoucher.TRVHEditBy, VS4TARVoucher.TRVHEditDate, VS4TARVoucher.TRVHConfirmStatus, VS4TARVoucher.TRVHConfirmBy, VS4TARVoucher.TRVHConfirmDate,                    VS4TARVoucher.TRVHApproveStatus, VS4TARVoucher.TRVHApproveBy, VS4TARVoucher.TRVHApproveDate, VS4TARVoucher.TRVHApproveNote, VS4TARVoucher.TRVHRevision,                    VS4TARVoucher.TRVHCancelStatus, VS4TARVoucher.TRVHCancelNo, VS4TARVoucher.TRVHCancelBy, VS4TARVoucher.TRVHCancelDate, VS4TARVoucher.TRVHCancelNote, VS4TARVoucher.TRVHFlag1,                    VS4TARVoucher.TRVHFlag2, VS4TARVoucher.TRVHFlag3, VS4TARVoucher.TRVHRefNo2, VS4TARVoucher.TRVHDescription, VS4TARVoucher.TRVHRefNo3, VS4TARVoucher.TRVHRefNo4,                    VS4TARVoucher.TRVHTARDCode, VS4TARVoucher.TRVHClientTaxNo, VS4TARVoucher.TRVHBranchCode, VS4TARVoucher.TRVHBranchName, VS4TARVoucher.TRVHTjobNo, VS4TARVoucher.TRVHTJbMLn,                    VS4TARVoucherPay.TRVRTRVHNo, VS4TARVoucherPay.TRVRLn, VS4TARVoucherPay.TRVRIsChange, VS4TARVoucherPay.TRVRReceiveType, VS4TARVoucherPay.TRVRCurrency,                    VS4TARVoucherPay.TRVRTBnkCode, VS4TARVoucherPay.TRVRTransferDate, VS4TARVoucherPay.TRVRCashDate, VS4TARVoucherPay.TRVRDocNo, VS4TARVoucherPay.TRVRBankBranch,                    VS4TARVoucherPay.TRVRAccountType, VS4TARVoucherPay.TRVRAccountName, VS4TARVoucherPay.TRVRAccountNumber, VS4TARVoucherPay.TRVRTBCDNo, VS4TARVoucherPay.TRVRCardCode,                    VS4TARVoucherPay.TRVRCardType, VS4TARVoucherPay.TRVRCardName, VS4TARVoucherPay.TRVRCardNo, VS4TARVoucherPay.TRVRCardExpire, VS4TARVoucherPay.TRVRExchangeRate,                    VS4TARVoucherPay.TRVRAmount, VS4TARVoucherPay.TRVRAmountInRate, VS4TARVoucherPay.TRVRAdjustTotal, VS4TARVoucherPay.TRVRDiscount, VS4TARVoucherPay.TRVRFee,                    VS4TARVoucherPay.TRVRFeeProvide, VS4TARVoucherPay.TRVRNetAmount, VS4TARVoucherPay.TRVRTCBBNo, VS4TARVoucherPay.TRVRNote, VS4TARVoucherPay.TRVRFlag1,                    VS4TARVoucherPay.TRVRDocType, VS4TARVoucherPay.TRVRCollectNo, VS4TARVoucherPay.TRVRAmountMain, 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, VS4TCompanyBank.TCBBFlag1, VS4TCompanyBank.TCBBTAPNCode,                    VS4TCompanyBank.TCBBODTACCCode, VS4TChequeRec.TCHRNo, VS4TChequeRec.TCHRTBnkCode, VS4TChequeRec.TCHRTCBBNo, VS4TChequeRec.TCHRTRVRTRVHNo, VS4TChequeRec.TCHRTRVRLn,                    VS4TChequeRec.TCHRTPrjCode, VS4TChequeRec.TCHRChqDate, VS4TChequeRec.TCHRTotal, VS4TChequeRec.TCHRTCurCode, VS4TChequeRec.TCHRCurRate, VS4TChequeRec.TCHRTotalRate,                    VS4TChequeRec.TCHRAvailable, VS4TChequeRec.TCHRPayment, VS4TChequeRec.TCHRDepositCount, VS4TChequeRec.TCHRTARNCode, VS4TChequeRec.TCHRPayChqDate, VS4TChequeRec.TCHRCashDate,                    VS4TChequeRec.TCHRChqStatus, VS4TChequeRec.TCHRChqRef, VS4TChequeRec.TCHRBankBranch, VS4TChequeRec.TCHRTGLTNo, VS4TChequeRec.TCHRDescription, VS4TChequeRec.TCHRChqOnHandBy,                    VS4TChequeRec.TCHRChqOnHandDate, VS4TChequeRec.TCHRChqDepBy, VS4TChequeRec.TCHRChqDepDate, VS4TChequeRec.TCHRChqPassBy, VS4TChequeRec.TCHRChqPassDate,                    VS4TChequeRec.TCHRChqBackBy, VS4TChequeRec.TCHRChqBackDate, VS4TChequeRec.TCHRChqBackNote, VS4TChequeRec.TCHRCreateCode, VS4TChequeRec.TCHRCreateDate,                    VS4TChequeRec.TCHREditCode, VS4TChequeRec.TCHREditDate, VS4TChequeRec.TCHRApproveStatus, VS4TChequeRec.TCHRApproveBy, VS4TChequeRec.TCHRApproveDate,                    VS4TChequeRec.TCHRApproveNote, VS4TChequeRec.TCHRConfidential, VS4TChequeRec.TCHRCancelStatus, VS4TChequeRec.TCHRCancelNo, VS4TChequeRec.TCHRCancelBy,                    VS4TChequeRec.TCHRCancelDate, VS4TChequeRec.TCHRCancelNote, VS4TChequeRec.TCHRFlag1, VS4TChequeRec.TCHRFlag2, VS4TChequeRec.TCHRFlag3, VS4TChequeRec.TCHRType,                    VS4TChequeRec.TCHRFee, VS4TChequeRec.TCHRPayTo, VS4TChequeRec.TCHRChqDepTBnkCode, VS4TChequeRec.TCHRFirstPayDate, VS4TChequeRec.TCHRLastPayDate,                    VS4TChequeRec.TCHRAccountType, VS4TChequeRec.TCHRAccountName, VS4TChequeRec.TCHRAccountNo, VS4TChequeRec.TCHRPassTGLTNo, VS4TAR.TARNDiscountPC, VS4TAR.TARNDiscountDay,                    VS4TAR.TARNCreditDay, VS4TAR2.TAR2SaleCode, VS4TEmployee.TEmpFullName, VS4TReceipt.TRECNo, VS4TReceipt.TRECDate, VS4TReceipt.TRECType, VS4TReceipt.TRECRefNo,                    VS4TReceipt.TRECRefDate, VS4TReceipt.TRECPayTo, VS4TReceipt.TRECTBraCode, VS4TReceipt.TRECTPrjCode, VS4TReceipt.TRECTGLBCode, VS4TReceipt.TRECSubTotal, VS4TReceipt.TRECWTaxRate,                    VS4TReceipt.TRECDiscount, VS4TReceipt.TRECWTaxTotal, VS4TReceipt.TRECTotal, VS4TReceipt.TRECNote, VS4TReceipt.TRECMode, VS4TReceipt.TRECWTaxBase, VS4TReceipt.TRECPayTotal,                    VS4TAR.TARNTSAeCode, VS4TBank.TBnkCode, VS4TBank.TBnkName, VS4TBank.TBnkShortName, VS4TARInvoice.TIvoAvailable AS VRVRAVailable, VS4TPaymentType.TPyTDescription,                    VS4TARInvoice.TIvoDate, VS4TARInvoice.TIvoGrandTotal, VS4TARInvoice.TIvoTaxBase, VS4TARInvoice.TIvoVATTotal, VS4TARInvoice.TIvoArrears, VS4TPaymentType.TPyTGroupSum FROM     VS4TARVoucher LEFT OUTER JOIN                   VS4TAR ON VS4TARVoucher.TRVHTARNCode = VS4TAR.TARNCode LEFT OUTER JOIN                   VS4TProject ON VS4TARVoucher.TRVHTPrjCode = VS4TProject.TPrjCode LEFT OUTER JOIN                   VS4TAR2 LEFT OUTER JOIN                   VS4TEmployee ON VS4TAR2.TAR2SaleCode = VS4TEmployee.TEmpCode ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode LEFT OUTER JOIN                   VS4TReceipt RIGHT OUTER JOIN                   VS4TARVandReceipt ON VS4TReceipt.TRECNo = VS4TARVandReceipt.TRNRTRECNo ON VS4TARVoucher.TRVHNo = VS4TARVandReceipt.TRNRTRVHNo INNER JOIN                   VS4TPaymentType RIGHT OUTER JOIN                   VS4TCompanyBank RIGHT OUTER JOIN                   VS4TARVoucherPay LEFT OUTER JOIN                   VS4TBank ON VS4TARVoucherPay.TRVRTBnkCode = VS4TBank.TBnkCode LEFT OUTER JOIN                   VS4TARInvoice ON VS4TARVoucherPay.TRVRDocNo = VS4TARInvoice.TIvoNo ON VS4TCompanyBank.TCBBNo = VS4TARVoucherPay.TRVRTCBBNo ON                    VS4TPaymentType.TPyTAlias = VS4TARVoucherPay.TRVRReceiveType ON VS4TARVoucher.TRVHNo = VS4TARVoucherPay.TRVRTRVHNo LEFT OUTER JOIN                   VS4TChequeRec RIGHT OUTER JOIN                   VS4TChequeRec2RV ON VS4TChequeRec.TCHRNo = VS4TChequeRec2RV.TR2RTCHRNo ON VS4TARVoucherPay.TRVRLn = VS4TChequeRec2RV.TR2RTRVRLn AND                    VS4TARVoucherPay.TRVRTRVHNo = VS4TChequeRec2RV.TR2RTRVRTRVHNo
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.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 VS4VRV AS SELECT VS4TARVoucher.TRVHNo, VS4TARVoucher.TRVHType, VS4TARVoucher.TRVHDetailType, VS4TARVoucher.TRVHMode, VS4TARVoucher.TRVHBalanceFlag, VS4TARVoucher.TRVHBaseArrear,                    VS4TARVoucher.TRVHArrear, VS4TARVoucher.TRVHDate, VS4TARVoucher.TRVHTBraCode, VS4TARVoucher.TRVHPaymentStatus, VS4TARVoucher.TRVHRefNo, VS4TARVoucher.TRVHRefDate,                    VS4TARVoucher.TRVHTARNCode, VS4TARVoucher.TRVHPayTo, VS4TARVoucher.TRVHAddress, VS4TARVoucher.TRVHPayTo2, VS4TARVoucher.TRVHAddress2, VS4TARVoucher.TRVHCurDiscount,                    VS4TARVoucher.TRVHCurRate, VS4TARVoucher.TRVHCurAmount, VS4TARVoucher.TRVHSubTotal, VS4TARVoucher.TRVHDiscount, VS4TARVoucher.TRVHPayLess, VS4TARVoucher.TRVHAdjustTotal,                    VS4TARVoucher.TRVHFee, VS4TARVoucher.TRVHNetAmount, VS4TARVoucher.TRVHTaxBase, VS4TARVoucher.TRVHWTaxTotal, VS4TARVoucher.TRVHTaxBase2, VS4TARVoucher.TRVHWTaxTotal2,                    VS4TARVoucher.TRVHTotal, VS4TARVoucher.TRVHNote, VS4TARVoucher.TRVHTGLBCode, VS4TARVoucher.TRVHTPrjCode, VS4TARVoucher.TRVHGLMethod, VS4TARVoucher.TRVHTGLTNo,                    VS4TARVoucher.TRVHTTeTNo, VS4TARVoucher.TRVHVATNo, VS4TARVoucher.TRVHTaxPeriodNo, VS4TARVoucher.TRVHTaxPeriodType, VS4TARVoucher.TRVHTaxRefund, VS4TARVoucher.TRVHPayType,                    VS4TARVoucher.TRVHTaxNo, VS4TARVoucher.TRVHWTaxPeriodNo, VS4TARVoucher.TRVHWTaxPeriodType, VS4TARVoucher.TRVHChequePayment, VS4TARVoucher.TRVHCashPayment,                    VS4TARVoucher.TRVHBankPayment, VS4TARVoucher.TRVHCardPayment, VS4TARVoucher.TRVHPayCoupon, VS4TARVoucher.TRVHPayOther, VS4TARVoucher.TRVHPayMisc,                    VS4TARVoucher.TRVHCutDeposit, VS4TARVoucher.TRVHCommissionBase, VS4TARVoucher.TRVHCommissionRate, VS4TARVoucher.TRVHCommission, VS4TARVoucher.TRVHInterestRate,                    VS4TARVoucher.TRVHInterestTotal, VS4TARVoucher.TRVHCardFlag, VS4TARVoucher.TRVHTaxFlag, VS4TARVoucher.TRVHCreateCode, VS4TARVoucher.TRVHCreateBy, VS4TARVoucher.TRVHCreateDate,                    VS4TARVoucher.TRVHEditCode, VS4TARVoucher.TRVHEditBy, VS4TARVoucher.TRVHEditDate, VS4TARVoucher.TRVHConfirmStatus, VS4TARVoucher.TRVHConfirmBy, VS4TARVoucher.TRVHConfirmDate,                    VS4TARVoucher.TRVHApproveStatus, VS4TARVoucher.TRVHApproveBy, VS4TARVoucher.TRVHApproveDate, VS4TARVoucher.TRVHApproveNote, VS4TARVoucher.TRVHRevision,                    VS4TARVoucher.TRVHCancelStatus, VS4TARVoucher.TRVHCancelNo, VS4TARVoucher.TRVHCancelBy, VS4TARVoucher.TRVHCancelDate, VS4TARVoucher.TRVHCancelNote, VS4TARVoucher.TRVHFlag1,                    VS4TARVoucher.TRVHFlag2, VS4TARVoucher.TRVHFlag3, VS4TARVoucher.TRVHRefNo2, VS4TARVoucher.TRVHDescription, VS4TARVoucher.TRVHRefNo3, VS4TARVoucher.TRVHRefNo4,                    VS4TARVoucher.TRVHTARDCode, VS4TARVoucher.TRVHClientTaxNo, VS4TARVoucher.TRVHBranchCode, VS4TARVoucher.TRVHBranchName, VS4TARVoucher.TRVHTjobNo, VS4TARVoucher.TRVHTJbMLn,                    VS4TARVDocRef.TRDRTRVHNo, VS4TARVDocRef.TRDRLn, VS4TARVDocRef.TRDRType, VS4TARVDocRef.TRDRRefBillNo, VS4TARVDocRef.TRDRRefDocNo, VS4TARVDocRef.TRDRRefDocDate,                    VS4TARVDocRef.TRDRRefNo, VS4TARVDocRef.TRDRRefNo2, VS4TARVDocRef.TRDRRefNo3, VS4TARVDocRef.TRDRRefDocAmount, VS4TARVDocRef.TRDRRefReceiptNo, VS4TARVDocRef.TRDRRefDueDate,                    VS4TARVDocRef.TRDRCurrency, VS4TARVDocRef.TRDRCurRate, VS4TARVDocRef.TRDRCurSubTotal, VS4TARVDocRef.TRDRCurDiscount, VS4TARVDocRef.TRDRCurAmount,                    VS4TARVDocRef.TRDRAmountRate, VS4TARVDocRef.TRDRTaxBase, VS4TARVDocRef.TRDRVATType, VS4TARVDocRef.TRDRVATRate, VS4TARVDocRef.TRDRVATTotal, VS4TARVDocRef.TRDRVATNo,                    VS4TARVDocRef.TRDRTAXNo, VS4TARVDocRef.TRDRWTAXRate, VS4TARVDocRef.TRDRWTAXTotal, VS4TARVDocRef.TRDRWTAXCond, VS4TARVDocRef.TRDRWTAXDesc,                    VS4TARVDocRef.TRDRCommissionBase, VS4TARVDocRef.TRDRCommissionRate, VS4TARVDocRef.TRDRCommission, VS4TARVDocRef.TRDRInterestRate, VS4TARVDocRef.TRDRInterestTotal,                    VS4TARVDocRef.TRDRTOINCode, VS4TARVDocRef.TRDRDOVAT, VS4TARVDocRef.TRDRNote, VS4TARVDocRef.TRDRNote2, VS4TARVDocRef.TRDRFlag1, VS4TARVDocRef.TRDRFlag2,                    VS4TARVDocRef.TRDRFlag3, VS4TARVDocRef.TRDRWTAXSection, VS4TARVDocRef.TRDRWTAXBase, VS4TReceipt.TRECNo, VS4TReceipt.TRECDate, VS4TReceipt.TRECType, VS4TReceipt.TRECRefNo,                    VS4TReceipt.TRECRefDate, VS4TReceipt.TRECPayTo, VS4TReceipt.TRECTBraCode, VS4TReceipt.TRECTPrjCode, VS4TReceipt.TRECTGLBCode, VS4TReceipt.TRECSubTotal, VS4TReceipt.TRECWTaxRate,                    VS4TReceipt.TRECDiscount, VS4TReceipt.TRECWTaxTotal, VS4TReceipt.TRECTotal, VS4TReceipt.TRECNote, VS4TReceipt.TRECCreateCode, VS4TReceipt.TRECCreateBy, VS4TReceipt.TRECCreateDate,                    VS4TReceipt.TRECEditCode, VS4TReceipt.TRECEditBy, VS4TReceipt.TRECEditDate, VS4TReceipt.TRECConfirmStatus, VS4TReceipt.TRECConfirmBy, VS4TReceipt.TRECConfirmDate,                    VS4TReceipt.TRECApproveStatus, VS4TReceipt.TRECApproveBy, VS4TReceipt.TRECApproveDate, VS4TReceipt.TRECApproveNote, VS4TReceipt.TRECRevision, VS4TReceipt.TRECCancelStatus,                    VS4TReceipt.TRECCancelNo, VS4TReceipt.TRECCancelBy, VS4TReceipt.TRECCancelDate, VS4TReceipt.TRECCancelNote, VS4TReceipt.TRECFlag1, VS4TReceipt.TRECFlag2, VS4TReceipt.TRECFlag3,                    VS4TReceipt.TRECMode, VS4TReceipt.TRECWTaxBase, VS4TReceipt.TRECPayTotal, VS4TAR.TARNName, VS4TProject.TPrjName, 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, VS4TAR.TARNAddressBill, VS4TAR.TARNAddressBill2, VS4TGLBook.TGLBName, VS4TAR.TARNChequeAddMonth, VS4TAR.TARNChequeDay,                    VS4TARInvoice.TIvoStartAgingDate, VS4TAR.TARNTaxNo, VS4TARVDocRefAOL.TRDATRDRTRVHNo, VS4TARVDocRefAOL.TRDATPDRLn, VS4TARVDocRefAOL.TRDATBraCode,                    VS4TARVDocRefAOL.TRDATPrjCode, VS4TARVDocRefAOL.TRDATDivCode, VS4TARVDocRefAOL.TRDATDepCode, VS4TARVDocRefAOL.TRDATSecCode, VS4TARVDocRefAOL.TRDATSZGCode,                    VS4TARVDocRefAOL.TRDATSZnCode, VS4TARVDocRefAOL.TRDATSAeCode, VS4TARVDocRefAOL.TRDATARNCode, VS4TARVDocRefAOL.TRDATAPNCode, VS4TARVDocRefAOL.TRDATAssCode,                    VS4TARVDocRefAOL.TRDATEmpCode, VS4TARVDocRefAOL.TRDATPdtCode, VS4TARVDocRefAOL.TRDATJobNo, VS4TARVDocRefAOL.TRDAFlag1, VS4TARVDocRefAOL.TRDAFlag2,                    VS4TARVDocRefAOL.TRDAFlag3, VS4TAR.TARNPhone, VS4TAR.TARNFax, VS4TAR2.TAR2TAPNCode, VS4TARInvoice.TIvoVATType, VS4TARInvoice.TIvoVATRate, VS4TARInvoiceMB.TIoMTOInCode,                    VS4TARInvoiceMB.TIoMCustom1, VS4TARInvoiceMB.TIoMCustom2, VS4TARInvoiceMB.TIoMCustom3, VS4TARInvoiceMB.TIoMCustom4, VS4TARInvoiceMB.TIoMCustom5, VS4TARInvoiceMB.TIoMPOSName,                    VS4TARInvoiceMB.TIoMDescription, VS4TARInvoiceMB.TIoMSourceNo, VS4TARInvoiceMB.TIoMSourceLn, VS4TARInvoiceMB.TIoMSourceDate, VS4TARInvoiceMB.TIoMSourcePeriod FROM     VS4TARVoucher LEFT OUTER JOIN                   VS4TProject ON VS4TARVoucher.TRVHTPrjCode = VS4TProject.TPrjCode LEFT OUTER JOIN                   VS4TBranch ON VS4TARVoucher.TRVHTBraCode = VS4TBranch.TBraCode LEFT OUTER JOIN                   VS4TAR ON VS4TARVoucher.TRVHTARNCode = VS4TAR.TARNCode LEFT OUTER JOIN                   VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode LEFT OUTER JOIN                   VS4TBusinessType ON VS4TAR.TARNTBsTCode = VS4TBusinessType.TBsTCode LEFT OUTER JOIN                   VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode LEFT OUTER JOIN                   VS4TCountry ON VS4TAR.TARNTCouCode = VS4TCountry.TCouCode LEFT OUTER JOIN                   VS4TGLBook ON VS4TARVoucher.TRVHTGLBCode = VS4TGLBook.TGLBCode LEFT OUTER JOIN                   VS4TAR2 LEFT OUTER JOIN                   VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode LEFT OUTER JOIN                   VS4TReceipt RIGHT OUTER JOIN                   VS4TARVandReceipt ON VS4TReceipt.TRECNo = VS4TARVandReceipt.TRNRTRECNo ON VS4TARVoucher.TRVHNo = VS4TARVandReceipt.TRNRTRVHNo INNER JOIN                   VS4TARVDocRef LEFT OUTER JOIN                   VS4TARReceipt ON VS4TARVDocRef.TRDRRefReceiptNo = VS4TARReceipt.TAIHNo LEFT OUTER JOIN                   VS4TARCreditNote ON VS4TARVDocRef.TRDRRefDocNo = VS4TARCreditNote.TRCNNo LEFT OUTER JOIN                   VS4TARDebitNote ON VS4TARVDocRef.TRDRRefDocNo = VS4TARDebitNote.TDBNNo LEFT OUTER JOIN                   VS4TARInvoice ON VS4TARVDocRef.TRDRRefDocNo = VS4TARInvoice.TIvoNo LEFT OUTER JOIN                   VS4TARBill ON VS4TARVDocRef.TRDRRefBillNo = VS4TARBill.TBilNo LEFT OUTER JOIN                   VS4TOtherIncome ON VS4TARVDocRef.TRDRTOINCode = VS4TOtherIncome.TOInCode LEFT OUTER JOIN                   VS4TARVDocRefAOL ON VS4TARVDocRef.TRDRTRVHNo = VS4TARVDocRefAOL.TRDATRDRTRVHNo AND VS4TARVDocRef.TRDRLn = VS4TARVDocRefAOL.TRDATPDRLn ON                    VS4TARVoucher.TRVHNo = VS4TARVDocRef.TRDRTRVHNo LEFT OUTER JOIN                   VS4TARInvoiceMB ON VS4TARInvoice.TIvoNo = VS4TARInvoiceMB.TIoMTIvoNo WHERE  (VS4TARInvoiceMB.TIoMLn = 1 or VS4TARInvoiceMB.TIoMLn is null)
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 VS4VQCSet AS  SELECT VS4TQCSet.*, VS4TQCSetMB.*, VS4TQC.*, VS4TQCMethod.* FROM (VS4TQCMethod INNER JOIN VS4TQC ON VS4TQCMethod.TQMTCode = VS4TQC.TQCCTQMTCode) INNER JOIN (VS4TQCSet INNER JOIN VS4TQCSetMB ON VS4TQCSet.TQCSCode = VS4TQCSetMB.TQCMTQCSCode) ON VS4TQC.TQCCCode = VS4TQCSetMB.TQCMTQCCCode
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.*, TQuBTQuoNo, TQuBLn, TQuBType, TQuBGroupName, TQuBTOInCode, TQuBTPOSCode, TQuBCustom1, TQuBCustom2, TQuBCustom3, TQuBCustom4, TQuBCustom5, TQuBShippingMark, TQuBPOSCode, TQuBFactoryCode, TQuBPOSName, TQuBCost, TQuBPrice, TQuBPerQuantity, TQuBUnitFactor, TQuBAcceptError, TQuBUnitCalc, TQuBQuantityCalc, TQuBQuantityText, TQuBQuantity, TQuBTUntCode, TQuBQuantity2, TQuBTUntCode2, TQuBQuantity3, TQuBTUntCode3, TQuBCostAmount, TQuBAmount, TQuBDiscountText, TQuBDiscountTotal, TQuBNetAmount, TQuBTaxType, TQuBTaxBase, TQuBWTAXBase, TQuBAmountVAT, TQuBAmountWTAX, TQuBPromotionType, TQuBFreeCode, TQuBIsPremium, TQuBDescription, TQuBUseDate, TQuBFlag1, TQuBPremiumCost, TQuBTARWCode, TQuBTRCACode, TQuBStockFlag, TQuBMinimumOrder, TQuBWelfareRate, TQuBTotalSO, TQuBTotalSOArr, TQuBControlQty, VS4TPOS.TPOSCode, VS4TPOS.TPOSType, VS4TPOS.TPOSPackAlias1, VS4TPOS.TPOSPackAlias2, VS4TPOS.TPOSLeadDay, VS4TPOS.TPOSMultipleOrder, VS4TPOS.TPOSMinimumOrder, VS4TPOS.TPOSCutStock, VS4TPOS.TPOSPrice, VS4TPOS.TPOSLastPrice, VS4TPOS.TPOSLastPriceDate, VS4TPOS.TPOSHideAfterSold, VS4TPOS.TPOSSaleCount, VS4TPOS.TPOSFirstSaleDate, VS4TPOS.TPOSLastSaleDate, VS4TPOS.TPOSDisplaySub, VS4TPOS.TPOSDisplaySubMB, VS4TPOS.TPOSOnSale, VS4TPOS.TPOSRefund, VS4TPOS.TPOSWarranty, VS4TPOS.TPOSWarrantyUnit, VS4TPOS.TPOSWarrantyType, VS4TPOS.TPOSSaleStockMinus, VS4TPOS.TPOSTotalQuantity, VS4TPOS.TPOSFlag1, VS4TPOS.TPOSSaleCode, VS4TPOS.TPOSPeriod, VS4TPOS.TPOSTARNCode, VS4TPOS.TPOSTPSGCode, VS4TPOS.TPOSG1TAPNCode, VS4TPOS.TPOSTLTAPNCode, VS4TPOS.TPOSPackDisplay, VS4TPOS.TPOSUnitCalc, VS4TDocumentStatus.TDStName, 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, VS4TAR.TARNAddressBill, VS4TAR.TARNAddressBill2, VS4TARWelfare.TARWName, VS4TProduct.TPdtBarcode, VS4TAR.TARNPhone, VS4TAR.TARNFax, VS4TQuotationBook.TQBKName, VS4TAR.TARNEmail, VS4TEmployee.TEmpFullName2 AS VQuoFullName2, VS4TPosition.TPstName, VS4TEmployee.TEmpEmail, VS4TEmployee.TEmpTel, VS4TEmployee_1.TEmpFullName2, VS4TPosition_1.TPstName AS VQuoPositionName, VS4TEmployee_1.TEmpEmail AS VQuoEmail, VS4TEmployee_1.TEmpTel AS VQuoTel, VS4TAR.TARNTaxNo, VS4TEmployee.TEmpNickName, VS4TEmployee.TEmpLineId, VS4TProduct.TPdtName2, VS4TARBranch.TARDName, VS4TARContact.TARCEmail, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3 FROM (VS4TQuotationBook RIGHT JOIN (VS4TPosition RIGHT JOIN (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) LEFT JOIN VS4TEmployee AS VS4TEmployee_1 ON VS4TQuotation.TQuoApproveNote = VS4TEmployee_1.TEmpCode) LEFT JOIN VS4TPosition AS VS4TPosition_1 ON VS4TEmployee_1.TEmpTPstCode = VS4TPosition_1.TPstCode) LEFT JOIN VS4TARBranch ON (VS4TQuotation.TQuoTARNCode = VS4TARBranch.TARDTARNCode) AND (VS4TQuotation.TQuoTARDCode = VS4TARBranch.TARDCode)) LEFT JOIN VS4TARContact ON (VS4TQuotation.TQuoContactName = VS4TARContact.TARCFirstName) AND (VS4TQuotation.TQuoTARNCode = VS4TARContact.TARCTARNCode)) ON VS4TAR.TARNCode = VS4TQuotation.TQuoTARNCode) ON VS4TDocumentStatus.TDStCode = VS4TQuotation.TQuoTDStCode) ON VS4TPosition.TPstCode = VS4TEmployee.TEmpTPstCode) ON VS4TQuotationBook.TQBKCode = VS4TQuotation.TQuoTQBkCode) 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) LEFT JOIN VS4TProduct3 ON VS4TProduct.TPdtCode = VS4TProduct3.TPD3TPdtCode) LEFT JOIN VS4TARWelfare ON VS4TQuotationMB.TQuBTARWCode = VS4TARWelfare.TARWCode) 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, VS4TSaleArea.TSAETEmpCode, (SELECT TOP 1 TSODNO FROM VS4TSO WHERE VS4TQuotation.TQuoNo = VS4TSO.TSODRefNo2) AS TSODNO FROM VS4TDocumentStatus INNER JOIN (((VS4TAR LEFT JOIN VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode) LEFT JOIN VS4TAR2 ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode) INNER JOIN (VS4TQuotation LEFT JOIN VS4TARBranch ON (VS4TQuotation.TQuoTARDCode = VS4TARBranch.TARDCode) AND (VS4TQuotation.TQuoTARNCode = VS4TARBranch.TARDTARNCode)) 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 LEFT JOIN VS4TBranch ON VS4TQuotationSet.TQuSTBraCode = VS4TBranch.TBraCode) INNER JOIN VS4TQuotationSetMB ON VS4TQuotationSet.TQuSNo = VS4TQuotationSetMB.TQSBTQuSNo) ON (VS4TQuotation.TQuoNo = VS4TQuotationSetMB.TQSBTQuoNo) AND (VS4TQuotation.TQuoNo = VS4TQuotationSetMB.TQSBTQuoNo)
GO

CREATE VIEW VS4VQuotationSetH AS  SELECT VS4TQuotationSet.*, VS4TBranch.TBraName, VS4TBranch.TBraAddressBill, VS4TAR.TARNName, VS4TAR.TARNName2 FROM (VS4TQuotationSet LEFT JOIN VS4TBranch ON VS4TQuotationSet.TQuSTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TAR ON VS4TQuotationSet.TQuSTARNCode = VS4TAR.TARNCode
GO

CREATE VIEW VS4VRatioPeriod AS  SELECT TGLTDate-Day(TGLTDate)+1 AS VGLTPeriod, VS4TACChart.*, VS4TAccountMap.*, VS4TACGroupSub.*, VS4TBranch.TBraCode, VS4TBranch.TBraName, VS4TBranch.TBraName2, VS4TGLTrans.*, VS4TGLTransSub.* FROM VS4TGLTrans INNER JOIN (VS4TBranch INNER JOIN (VS4TACGroupSub RIGHT JOIN ((VS4TACChart LEFT JOIN VS4TAccountMap ON VS4TACChart.TACCCode = VS4TAccountMap.TACMTACCCode) INNER JOIN VS4TGLTransSub ON VS4TACChart.TACCCode = VS4TGLTransSub.TGTSTACCCode) ON VS4TACGroupSub.TAGsCode = VS4TACChart.TACCTAGsCode) ON VS4TBranch.TBraCode = VS4TGLTransSub.TGTSTBraCode) ON VS4TGLTrans.TGLTNo = VS4TGLTransSub.TGTSTGLTNo
GO

CREATE VIEW VS4VReceiveProduct AS  SELECT VS4TReceivePdu.*, VS4TReceivePduMB.*, VS4TBranch.TBraName, VS4TProject.TPrjName, 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 VS4VReport AS  SELECT VS4TReport.*, VS4TCommand.*, VS4TCommandGroup.* FROM (VS4TReport LEFT JOIN VS4TCommand ON VS4TReport.TRptTCmdAlias = VS4TCommand.TCmdAlias) LEFT JOIN VS4TCommandGroup ON VS4TCommand.TCmdTCmGAlias = VS4TCommandGroup.TCmGAlias
GO

CREATE VIEW VS4VRevenue1 AS  SELECT TTxtDocDate-Day(TTxtDocDate)+1 AS VTxTPeriod, VS4TTaxTrans.*, VS4TEmployee.*, VS4TEmployeeType.TEmTTotalPeriod, VS4TEmployee2.TEm2ManualSFUND FROM (VS4TEmployeeType RIGHT JOIN (VS4TTaxTrans LEFT JOIN VS4TEmployee ON VS4TTaxTrans.TTxTClientCitizen = VS4TEmployee.TEmpCitizenNo) ON VS4TEmployeeType.TEmTCode = VS4TEmployee.TEmpTEmTCode) LEFT JOIN VS4TEmployee2 ON VS4TEmployee.TEmpCode = VS4TEmployee2.TEm2TEmpCode 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, VS4VRevenue1.TEm2ManualSFUND, VS4VRevenue1.TTxTTBraCode, VS4VRevenue1.TEmpTEmTCode, VS4VRevenue1.TEmpTSecCode, VS4VRevenue1.TEmpTDepCode, VS4VRevenue1.TEmpTDivCode, VS4VRevenue1.TEmpTBraCode 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.TEm2ManualSFUND, VS4VRevenue1.TTxTTBraCode, VS4VRevenue1.TTxTCancelStatus, VS4VRevenue1.TEmpTEmTCode, VS4VRevenue1.TEmpTSecCode, VS4VRevenue1.TEmpTDepCode, VS4VRevenue1.TEmpTDivCode, VS4VRevenue1.TEmpTBraCode HAVING (((VS4VRevenue1.TTxTCancelStatus)=0))
GO

CREATE VIEW VS4VRevenue2 AS  SELECT TTxtDocDate-Day(TTxtDocDate)+1 AS VTxTPeriod, VS4TTaxTrans.* FROM VS4TTaxTrans WHERE (((VS4TTaxTrans.TTxTType)=7) AND ((VS4TTaxTrans.TTxTDefaultTax)=2))
GO

CREATE VIEW VS4VRevenue3 AS  SELECT TTxtDocDate-Day(TTxtDocDate)+1 AS VTxTPeriod, VS4TTaxTrans.* FROM VS4TTaxTrans WHERE (((VS4TTaxTrans.TTxTType)=2) AND ((VS4TTaxTrans.TTxTDefaultTax)=2))
GO

CREATE VIEW VS4VRevenue53 AS  SELECT TTxtDocDate-Day(TTxtDocDate)+1 AS VTxTPeriod, VS4TTaxTrans.* FROM VS4TTaxTrans WHERE (((VS4TTaxTrans.TTxTType)=5) AND ((VS4TTaxTrans.TTxTDefaultTax)=2))
GO

CREATE VIEW VS4VRevenueWTAX AS  SELECT TTxtDocDate-Day(TTxtDocDate)+1 AS VTxTPeriod, 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.TRevNo = VS4TReviseEffect.TReETRevNo) AND (VS4TRevision.TRevDocNo = VS4TReviseEffect.TReETRevDocNo) AND (VS4TRevision.TRevDocType = VS4TReviseEffect.TReETRevDocType)
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 VS4VRTH AS  SELECT VS4TSO.*, VS4TProject.TPrjName, VS4TAR.TARNName2, VS4TCountry.TCouName, VS4TCountry.TCouName2, VS4TAR.TARNPhone, VS4TAR.TARNFax, 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 WHERE (((VS4TSO.TSODType)=3))
GO

CREATE VIEW VS4VARCardIVDBCNR AS  SELECT VS4TEmployee_1.TEmpFullName2 AS VARCIVEMPNAME2, VS4TARCard.TRICSignArrear, VS4TARBalance.TARLBeginBalance, VS4TARBalance.TARLEndBalance, VS4TARCard.TRICTACPID, VS4TARCard.TRICTACPTACYID, VS4TARCard.TRICSignTotal, VS4TARInvoice.TIvoPaymentNote, VS4TARInvoice.TIvoConditionDay, VS4TARInvoice.TIvoIgnoreArrears, VS4TARInvoice.TIvoDestination, VS4TARCard.TRICTARNCode, VS4TARCard.TRICDOCNO, VS4TARCard.TRICType, VS4TARCard.TRICDueDate, VS4TARCard.TRICDocDate, VS4TAR.TARNName, VS4TARInvoice.TIvoDate, VS4TARInvoice.TIvoGrandTotal, VS4TARInvoice.TIvoRefNo, VS4TARInvoice.TIvoArrears, VS4TARCard.TRICMode, VS4TARCard.TRICTPrjCode, VS4TARCard.TRICTBraCode, VS4TGLTrans.TGLTTGLBCode, VS4TARInvoice.TIvoStartAgingDate, VS4TAR.TARNTBsTCode, VS4TAR.TARNTARGCode, VS4TAR.TARNTCouCode, VS4TAR2.TAR2TPrvCode, VS4TAR2.TAR2TSPvCode, VS4TAR2.TAR2SaleCode, VS4TARInvoice.TIvoTEmpCode, VS4TSaleArea.TSAeTSZnCode, VS4TAR.TARNTSaeCode, VS4TAR2.TAR2TShpCode, VS4TARInvoice.TIvoTPOSCode, VS4TProduct.TPdtTPSECode AS VICDIVTPSECODE, VS4TARInvoice.TIvoTRBKCode, VS4TARCard.TRICLn, VS4TARCard.TRICCancelStatus, VS4TARInvoice.TIVOTYPE, VS4TARInvoice.TIvoTotalFOB, VS4TARInvoice.TIvoTotal, VS4TARInvoice.TIvoExchangeRate, VS4TARInvoice.TIvoExchangeRate2, VS4TARInvoice.TIvoTCurCode, VS4TARInvoice.TIvoIncoType, VS4TARInvoice.TIvoBaseIncoType, VS4TARInvoice.TIvoFreightFee, VS4TARInvoice.TIvoInsurance,  (SELECT isnull(SUM(TIvoAvailable),0) AS A FROM VS4TARInvoice WHERE (TIvoType=5 or TIvoType=7) AND TIvoApproveStatus=1 AND TIvoCancelStatus=0 AND TIvoAvailable>0 AND (3=3) AND VS4TARInvoice.TIvoTARNCode=VS4TAR.TARNCode) AS VRICDeposit,  (SELECT isnull(sum(TRDRAmountRate),0) FROM VS4VRV WHERE VS4VRV.TRVHApproveStatus=1 AND VS4VRV.TRVHCancelStatus=0 AND VS4VRV.TRDRRefDocNo=VS4TARCARD.TRICDocNo AND (1=1)) AS VRICRVPaid,  (SELECT isnull(sum(TPVPAmountInRate),0) FROM VS4VPVPAY WHERE VS4VPVPAY.TAPVApproveStatus=1 AND VS4VPVPAY.TAPVCancelStatus=0 AND VS4VPVPAY.TPVPDocNo=VS4TARCARD.TRICDocNo AND (2=2)) AS VRICPVPaid, VS4TARCard.TRICDisplayDate, VS4TEmployee_1.TEmpFullName2 AS VARCIVEMPNAME FROM VS4TProductSection RIGHT JOIN ((((((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 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 VS4TGLTrans ON VS4TARCard.TRICTGLTNo = VS4TGLTrans.TGLTNo) LEFT JOIN VS4TProduct ON VS4TARInvoice.TIvoTPOSCode = VS4TProduct.TPdtCode) ON (VS4TAccountPeriod.TACPID = VS4TARBalance.TARLTACPID) AND (VS4TAccountPeriod.TACPTACYID = VS4TARBalance.TARLTACPTACYID)) ON VS4TAR.TARNCode = VS4TARCard.TRICTARNCode) ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode WHERE (((VS4TARCard.TRICType)<>'O') AND ((VS4TARInvoice.TIVOTYPE)<>10 And (VS4TARInvoice.TIVOTYPE)<>7 And (VS4TARInvoice.TIVOTYPE)<>5)) OR (((VS4TARInvoice.TIVOTYPE) Is Null))
GO

CREATE VIEW VS4VRV2 AS SELECT VS4TARVDocRef2.*, VS4TOtherExpense.TOExName FROM     VS4TARVoucher INNER JOIN                   VS4TARVDocRef2 ON VS4TARVoucher.TRVHNo = VS4TARVDocRef2.TRDPTRVHNo LEFT OUTER JOIN                   VS4TOtherExpense ON VS4TARVDocRef2.TRDPTOExCode = VS4TOtherExpense.TOExCode
GO

CREATE VIEW VS4VRV2IVCNDBMB AS SELECT        VS4TARVoucher_1.TRVHNo, VS4TARVoucher_1.TRVHType, VS4TARVoucher_1.TRVHDetailType, VS4TARVoucher_1.TRVHMode, VS4TARVoucher_1.TRVHBalanceFlag, VS4TARVoucher_1.TRVHBaseArrear,                           VS4TARVoucher_1.TRVHArrear, VS4TARVoucher_1.TRVHDate, VS4TARVoucher_1.TRVHTBraCode, VS4TARVoucher_1.TRVHPaymentStatus, VS4TARVoucher_1.TRVHRefNo, VS4TARVoucher_1.TRVHRefDate,                           VS4TARVoucher_1.TRVHTARNCode, VS4TARVoucher_1.TRVHPayTo, VS4TARVoucher_1.TRVHAddress, VS4TARVoucher_1.TRVHPayTo2, VS4TARVoucher_1.TRVHAddress2, VS4TARVoucher_1.TRVHCurDiscount,                           VS4TARVoucher_1.TRVHCurRate, VS4TARVoucher_1.TRVHCurAmount, VS4TARVoucher_1.TRVHSubTotal, VS4TARVoucher_1.TRVHDiscount, VS4TARVoucher_1.TRVHPayLess, VS4TARVoucher_1.TRVHAdjustTotal,                           VS4TARVoucher_1.TRVHFee, VS4TARVoucher_1.TRVHNetAmount, VS4TARVoucher_1.TRVHTaxBase, VS4TARVoucher_1.TRVHWTaxTotal, VS4TARVoucher_1.TRVHTaxBase2, VS4TARVoucher_1.TRVHWTaxTotal2,                           VS4TARVoucher_1.TRVHTotal, VS4TARVoucher_1.TRVHNote, VS4TARVoucher_1.TRVHTGLBCode, VS4TARVoucher_1.TRVHTPrjCode, VS4TARVoucher_1.TRVHGLMethod, VS4TARVoucher_1.TRVHTGLTNo,                           VS4TARVoucher_1.TRVHTTeTNo, VS4TARVoucher_1.TRVHVATNo, VS4TARVoucher_1.TRVHTaxPeriodNo, VS4TARVoucher_1.TRVHTaxPeriodType, VS4TARVoucher_1.TRVHTaxRefund, VS4TARVoucher_1.TRVHPayType,                           VS4TARVoucher_1.TRVHTaxNo, VS4TARVoucher_1.TRVHWTaxPeriodNo, VS4TARVoucher_1.TRVHWTaxPeriodType, VS4TARVoucher_1.TRVHChequePayment, VS4TARVoucher_1.TRVHCashPayment,                           VS4TARVoucher_1.TRVHBankPayment, VS4TARVoucher_1.TRVHCardPayment, VS4TARVoucher_1.TRVHPayCoupon, VS4TARVoucher_1.TRVHPayOther, VS4TARVoucher_1.TRVHPayMisc, VS4TARVoucher_1.TRVHCutDeposit,                           VS4TARVoucher_1.TRVHCommissionBase, VS4TARVoucher_1.TRVHCommissionRate, VS4TARVoucher_1.TRVHCommission, VS4TARVoucher_1.TRVHInterestRate, VS4TARVoucher_1.TRVHInterestTotal,                           VS4TARVoucher_1.TRVHCardFlag, VS4TARVoucher_1.TRVHTaxFlag, VS4TARVoucher_1.TRVHCreateCode, VS4TARVoucher_1.TRVHCreateBy, VS4TARVoucher_1.TRVHCreateDate, VS4TARVoucher_1.TRVHEditCode,                           VS4TARVoucher_1.TRVHEditBy, VS4TARVoucher_1.TRVHEditDate, VS4TARVoucher_1.TRVHConfirmStatus, VS4TARVoucher_1.TRVHConfirmBy, VS4TARVoucher_1.TRVHConfirmDate, VS4TARVoucher_1.TRVHApproveStatus,                           VS4TARVoucher_1.TRVHApproveBy, VS4TARVoucher_1.TRVHApproveDate, VS4TARVoucher_1.TRVHApproveNote, VS4TARVoucher_1.TRVHRevision, VS4TARVoucher_1.TRVHCancelStatus, VS4TARVoucher_1.TRVHCancelNo,                           VS4TARVoucher_1.TRVHCancelBy, VS4TARVoucher_1.TRVHCancelDate, VS4TARVoucher_1.TRVHCancelNote, VS4TARVoucher_1.TRVHFlag1, VS4TARVoucher_1.TRVHFlag2, VS4TARVoucher_1.TRVHFlag3,                           VS4TARVoucher_1.TRVHRefNo2, VS4TARVoucher_1.TRVHDescription, VS4TARVoucher_1.TRVHRefNo3, VS4TARVoucher_1.TRVHRefNo4, VS4TARVoucher_1.TRVHTARDCode, VS4TARVoucher_1.TRVHClientTaxNo,                           VS4TARVoucher_1.TRVHBranchCode, VS4TARVoucher_1.TRVHBranchName, VS4TARVoucher_1.TRVHTjobNo, VS4TARVoucher_1.TRVHTJbMLn, VS4TARVDocRef_1.TRDRTRVHNo, VS4TARVDocRef_1.TRDRLn,                           VS4TARVDocRef_1.TRDRType, VS4TARVDocRef_1.TRDRRefBillNo, VS4TARVDocRef_1.TRDRRefDocNo, VS4TARVDocRef_1.TRDRRefDocDate, VS4TARVDocRef_1.TRDRRefNo, VS4TARVDocRef_1.TRDRRefNo2,                           VS4TARVDocRef_1.TRDRRefNo3, VS4TARVDocRef_1.TRDRRefDocAmount, VS4TARVDocRef_1.TRDRRefReceiptNo, VS4TARVDocRef_1.TRDRRefDueDate, VS4TARVDocRef_1.TRDRCurrency, VS4TARVDocRef_1.TRDRCurRate,                           VS4TARVDocRef_1.TRDRCurSubTotal, VS4TARVDocRef_1.TRDRCurDiscount, VS4TARVDocRef_1.TRDRCurAmount, VS4TARVDocRef_1.TRDRAmountRate, VS4TARVDocRef_1.TRDRTaxBase, VS4TARVDocRef_1.TRDRVATType,                           VS4TARVDocRef_1.TRDRVATRate, VS4TARVDocRef_1.TRDRVATTotal, VS4TARVDocRef_1.TRDRVATNo, VS4TARVDocRef_1.TRDRTAXNo, VS4TARVDocRef_1.TRDRWTAXRate, VS4TARVDocRef_1.TRDRWTAXTotal,                           VS4TARVDocRef_1.TRDRWTAXCond, VS4TARVDocRef_1.TRDRWTAXDesc, VS4TARVDocRef_1.TRDRCommissionBase, VS4TARVDocRef_1.TRDRCommissionRate, VS4TARVDocRef_1.TRDRCommission,                           VS4TARVDocRef_1.TRDRInterestRate, VS4TARVDocRef_1.TRDRInterestTotal, VS4TARVDocRef_1.TRDRTOINCode, VS4TARVDocRef_1.TRDRDOVAT, VS4TARVDocRef_1.TRDRNote, VS4TARVDocRef_1.TRDRNote2,                           VS4TARVDocRef_1.TRDRFlag1, VS4TARVDocRef_1.TRDRFlag2, VS4TARVDocRef_1.TRDRFlag3, VS4TARVDocRef_1.TRDRWTAXSection, VS4TARVDocRef_1.TRDRWTAXBase, VS4TReceipt.TRECNo,                           VS4TReceipt.TRECDate, VS4TReceipt.TRECType, VS4TReceipt.TRECRefNo, VS4TReceipt.TRECRefDate, VS4TReceipt.TRECPayTo, VS4TReceipt.TRECTBraCode, VS4TReceipt.TRECTPrjCode,                           VS4TReceipt.TRECTGLBCode, VS4TReceipt.TRECSubTotal, VS4TReceipt.TRECWTaxRate, VS4TReceipt.TRECDiscount, VS4TReceipt.TRECWTaxTotal, VS4TReceipt.TRECTotal,                           VS4TReceipt.TRECNote, VS4TReceipt.TRECCreateCode, VS4TReceipt.TRECCreateBy, VS4TReceipt.TRECCreateDate, VS4TReceipt.TRECEditCode, VS4TReceipt.TRECEditBy,                           VS4TReceipt.TRECEditDate, VS4TReceipt.TRECConfirmStatus, VS4TReceipt.TRECConfirmBy, VS4TReceipt.TRECConfirmDate, VS4TReceipt.TRECApproveStatus, VS4TReceipt.TRECApproveBy,                           VS4TReceipt.TRECApproveDate, VS4TReceipt.TRECApproveNote, VS4TReceipt.TRECRevision, VS4TReceipt.TRECCancelStatus, VS4TReceipt.TRECCancelNo, VS4TReceipt.TRECCancelBy,                           VS4TReceipt.TRECCancelDate, VS4TReceipt.TRECCancelNote, VS4TReceipt.TRECFlag1, VS4TReceipt.TRECFlag2, VS4TReceipt.TRECFlag3, VS4TReceipt.TRECMode, VS4TReceipt.TRECWTaxBase,                           VS4TReceipt.TRECPayTotal, VS4TAR.TARNName, VS4TProject.TPrjName, VS4TBranch.TBraName, VS4TAR.TARNTARGCode, VS4TARGroup.TARGName, VS4TAR.TARNTBsTCode,                           VS4TBusinessType.TBstName, VS4TAR.TARNTSAeCode, VS4TSaleArea.TSAeName, VS4TAR.TARNTCouCode, VS4TCountry.TCouName, VS4TAR2.TAR2TPrvCode, VS4TProvince.TPrvName,                           VS4TARInvoice.TIvoTEmpCode, VS4TARInvoice.TIvoSaleName, VS4TAR.TARNName2, VS4TARInvoice.TIvoTCurCode, VS4TARInvoice.TIvoExchangeRate, VS4TARBill.TBilNo, VS4TARBill.TBilDate,                           VS4TARBill.TBilDueDate, VS4TOtherIncome.TOInCode, VS4TOtherIncome.TOInName, VS4TOtherIncome.TOInName2, VS4TOtherIncome.TOInTACCCode, VS4TAR2.TAR2SaleCode,                           VS4TARReceipt.TAIHNo, VS4TARReceipt.TAIHDate, VS4TARReceipt.TAIHType, VS4TBranch.TBraAddressBill, VS4TProduct.TPdtTPS2Code, VS4TProductSec2.TPS2Name,                           VS4TProduct.TPdtTPSECode, VS4TProductSection.TPSEName, VS4TProduct.TPdtName, VS4TARInvoice.TIvoGrandTotal, VS4TARInvoice.TIvoSubTotal, VS4TARInvoice.TIvoArrears,                           VS4TARInvoiceMB.TIoMLn, VS4TARInvoiceMB.TIoMTPOSCode, VS4TARInvoiceMB.TIoMCustom1, VS4TARInvoiceMB.TIoMPOSName, VS4TARInvoiceMB.TIoMPOSName2, VS4TARInvoiceMB.TIoMPrice,                           VS4TARInvoiceMB.TIoMPerQuantity, VS4TARInvoiceMB.TIoMUnitFactor, VS4TARInvoiceMB.TIoMUnitCalc, VS4TARInvoiceMB.TIoMQuantityBase, VS4TARInvoiceMB.TIoMQuantityCalc,                           VS4TARInvoiceMB.TIoMQuantity, VS4TARInvoiceMB.TIoMTUntCode, VS4TARInvoiceMB.TIoMAmount, VS4TARInvoiceMB.TIoMDiscountText, VS4TARInvoiceMB.TIoMDiscountTotal,                           VS4TARInvoiceMB.TIoMNetAmount, VS4TARInvoiceMB.TIoMTaxType, VS4TARInvoiceMB.TIoMTaxBase, VS4TARInvoiceMB.TIoMAmountVAT, VS4TARInvoiceMB.TIoMFreeCode,                           VS4TARInvoiceMB.TIoMIsPremium, VS4TARInvoiceMB.TIoMSourceNo, VS4TARInvoiceMB.TIoMSourceLn, VS4TARInvoiceMB.TIoMSourceDate, VS4TARInvoiceMB.TIoMCommissionBase,                           VS4TARInvoiceMB.TIoMCommissionRate, VS4TARInvoiceMB.TIoMCommission, VS4TARInvoiceMB.TIoMTARWCode, VS4TARInvoiceMB.TIoMWelfareRate, VS4TARInvoiceMB.TIoMWelfareAmount,                           VS4TARInvoiceMB.TIoMTRCACode, VS4TARInvoiceMB.TIoMStockFlag,                              (SELECT        MAX(VS4TARVoucher.TRVHDate) AS TRV2LastPayDate                                FROM            VS4TARVoucher INNER JOIN                                                          VS4TARVDocRef ON VS4TARVoucher.TRVHNo = VS4TARVDocRef.TRDRTRVHNo                                GROUP BY VS4TARVoucher.TRVHApproveStatus, VS4TARVoucher.TRVHCancelStatus, VS4TARVDocRef.TRDRRefDocNo                                HAVING         (VS4TARVoucher.TRVHApproveStatus = 1) AND (VS4TARVoucher.TRVHCancelStatus = 0) AND (VS4TARVDocRef.TRDRRefDocNo = VS4TARInvoice.TIvoNo)) AS TRV2LastPayDate FROM            VS4TARVoucher AS VS4TARVoucher_1 LEFT OUTER JOIN                          VS4TProject ON VS4TARVoucher_1.TRVHTPrjCode = VS4TProject.TPrjCode LEFT OUTER JOIN                          VS4TBranch ON VS4TARVoucher_1.TRVHTBraCode = VS4TBranch.TBraCode LEFT OUTER JOIN                          VS4TAR ON VS4TARVoucher_1.TRVHTARNCode = VS4TAR.TARNCode LEFT OUTER JOIN                          VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode LEFT OUTER JOIN                          VS4TBusinessType ON VS4TAR.TARNTBsTCode = VS4TBusinessType.TBsTCode LEFT OUTER JOIN                          VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode LEFT OUTER JOIN                          VS4TCountry ON VS4TAR.TARNTCouCode = VS4TCountry.TCouCode LEFT OUTER JOIN                          VS4TAR2 LEFT OUTER 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_1.TRVHNo = VS4TARVandReceipt.TRNRTRVHNo INNER JOIN                          VS4TProductSection RIGHT OUTER JOIN                          VS4TARVDocRef AS VS4TARVDocRef_1 LEFT OUTER JOIN                          VS4TARReceipt ON VS4TARVDocRef_1.TRDRRefReceiptNo = VS4TARReceipt.TAIHNo LEFT OUTER JOIN                          VS4TARCreditNote ON VS4TARVDocRef_1.TRDRRefDocNo = VS4TARCreditNote.TRCNNo LEFT OUTER JOIN                          VS4TARDebitNote ON VS4TARVDocRef_1.TRDRRefDocNo = VS4TARDebitNote.TDBNNo LEFT OUTER JOIN                          VS4TARInvoice ON VS4TARVDocRef_1.TRDRRefDocNo = VS4TARInvoice.TIvoNo LEFT OUTER JOIN                          VS4TARBill ON VS4TARVDocRef_1.TRDRRefBillNo = VS4TARBill.TBilNo LEFT OUTER JOIN                          VS4TOtherIncome ON VS4TARVDocRef_1.TRDRTOINCode = VS4TOtherIncome.TOInCode LEFT OUTER JOIN                          VS4TARCreditNoteMB ON VS4TARCreditNote.TRCNNo = VS4TARCreditNoteMB.TRCMTRCNNo LEFT OUTER JOIN                          VS4TARDebitNoteMB ON VS4TARDebitNote.TDBNNo = VS4TARDebitNoteMB.TDBMTDBNNo LEFT OUTER JOIN                          VS4TARInvoiceMB LEFT OUTER JOIN                          VS4TProduct ON VS4TARInvoiceMB.TIoMTPOSCode = VS4TProduct.TPdtCode LEFT OUTER JOIN                          VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code ON VS4TARInvoice.TIvoNo = VS4TARInvoiceMB.TIoMTIvoNo ON                           VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode ON VS4TARVoucher_1.TRVHNo = VS4TARVDocRef_1.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.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 VS4VRVMB
AS
SELECT VS4TARVoucher.TRVHNo, VS4TARVoucher.TRVHType, VS4TARVoucher.TRVHDetailType, VS4TARVoucher.TRVHMode, VS4TARVoucher.TRVHBalanceFlag, VS4TARVoucher.TRVHBaseArrear, 
                  VS4TARVoucher.TRVHArrear, VS4TARVoucher.TRVHDate, VS4TARVoucher.TRVHTBraCode, VS4TARVoucher.TRVHPaymentStatus, VS4TARVoucher.TRVHRefNo, VS4TARVoucher.TRVHRefDate, 
                  VS4TARVoucher.TRVHTARNCode, VS4TARVoucher.TRVHPayTo, VS4TARVoucher.TRVHAddress, VS4TARVoucher.TRVHPayTo2, VS4TARVoucher.TRVHAddress2, VS4TARVoucher.TRVHCurDiscount, 
                  VS4TARVoucher.TRVHCurRate, VS4TARVoucher.TRVHCurAmount, VS4TARVoucher.TRVHSubTotal, VS4TARVoucher.TRVHDiscount, VS4TARVoucher.TRVHPayLess, VS4TARVoucher.TRVHAdjustTotal, 
                  VS4TARVoucher.TRVHFee, VS4TARVoucher.TRVHNetAmount, VS4TARVoucher.TRVHTaxBase, VS4TARVoucher.TRVHWTaxTotal, VS4TARVoucher.TRVHTaxBase2, VS4TARVoucher.TRVHWTaxTotal2, 
                  VS4TARVoucher.TRVHTotal, VS4TARVoucher.TRVHNote, VS4TARVoucher.TRVHTGLBCode, VS4TARVoucher.TRVHTPrjCode, VS4TARVoucher.TRVHGLMethod, VS4TARVoucher.TRVHTGLTNo, 
                  VS4TARVoucher.TRVHTTeTNo, VS4TARVoucher.TRVHVATNo, VS4TARVoucher.TRVHTaxPeriodNo, VS4TARVoucher.TRVHTaxPeriodType, VS4TARVoucher.TRVHTaxRefund, VS4TARVoucher.TRVHPayType, 
                  VS4TARVoucher.TRVHTaxNo, VS4TARVoucher.TRVHWTaxPeriodNo, VS4TARVoucher.TRVHWTaxPeriodType, VS4TARVoucher.TRVHChequePayment, VS4TARVoucher.TRVHCashPayment, 
                  VS4TARVoucher.TRVHBankPayment, VS4TARVoucher.TRVHCardPayment, VS4TARVoucher.TRVHPayCoupon, VS4TARVoucher.TRVHPayOther, VS4TARVoucher.TRVHPayMisc, 
                  VS4TARVoucher.TRVHCutDeposit, VS4TARVoucher.TRVHCommissionBase, VS4TARVoucher.TRVHCommissionRate, VS4TARVoucher.TRVHCommission, VS4TARVoucher.TRVHInterestRate, 
                  VS4TARVoucher.TRVHInterestTotal, VS4TARVoucher.TRVHCardFlag, VS4TARVoucher.TRVHTaxFlag, VS4TARVoucher.TRVHCreateCode, VS4TARVoucher.TRVHCreateBy, VS4TARVoucher.TRVHCreateDate, 
                  VS4TARVoucher.TRVHEditCode, VS4TARVoucher.TRVHEditBy, VS4TARVoucher.TRVHEditDate, VS4TARVoucher.TRVHConfirmStatus, VS4TARVoucher.TRVHConfirmBy, VS4TARVoucher.TRVHConfirmDate, 
                  VS4TARVoucher.TRVHApproveStatus, VS4TARVoucher.TRVHApproveBy, VS4TARVoucher.TRVHApproveDate, VS4TARVoucher.TRVHApproveNote, VS4TARVoucher.TRVHRevision, 
                  VS4TARVoucher.TRVHCancelStatus, VS4TARVoucher.TRVHCancelNo, VS4TARVoucher.TRVHCancelBy, VS4TARVoucher.TRVHCancelDate, VS4TARVoucher.TRVHCancelNote, VS4TARVoucher.TRVHFlag1, 
                  VS4TARVoucher.TRVHFlag2, VS4TARVoucher.TRVHFlag3, VS4TARVoucher.TRVHRefNo2, VS4TARVoucher.TRVHDescription, VS4TARVoucher.TRVHRefNo3, VS4TARVoucher.TRVHRefNo4, 
                  VS4TARVoucher.TRVHTARDCode, VS4TARVoucher.TRVHClientTaxNo, VS4TARVoucher.TRVHBranchCode, VS4TARVoucher.TRVHBranchName, VS4TARVoucher.TRVHTjobNo, VS4TARVoucher.TRVHTJbMLn, 
                  VS4TARVoucher.TRVHExpenseTotal, VS4TARVDocRef.TRDRTRVHNo, VS4TARVDocRef.TRDRLn, VS4TARVDocRef.TRDRType, VS4TARVDocRef.TRDRRefBillNo, VS4TARVDocRef.TRDRRefDocNo, 
                  VS4TARVDocRef.TRDRRefDocDate, VS4TARVDocRef.TRDRRefNo, VS4TARVDocRef.TRDRRefNo2, VS4TARVDocRef.TRDRRefNo3, VS4TARVDocRef.TRDRRefDocAmount, VS4TARVDocRef.TRDRRefReceiptNo, 
                  VS4TARVDocRef.TRDRRefDueDate, VS4TARVDocRef.TRDRCurrency, VS4TARVDocRef.TRDRCurRate, VS4TARVDocRef.TRDRCurSubTotal, VS4TARVDocRef.TRDRCurDiscount, 
                  VS4TARVDocRef.TRDRCurAmount, VS4TARVDocRef.TRDRAmountRate, VS4TARVDocRef.TRDRTaxBase, VS4TARVDocRef.TRDRVATType, VS4TARVDocRef.TRDRVATRate, VS4TARVDocRef.TRDRVATTotal, 
                  VS4TARVDocRef.TRDRVATNo, VS4TARVDocRef.TRDRTAXNo, VS4TARVDocRef.TRDRWTAXRate, VS4TARVDocRef.TRDRWTAXTotal, VS4TARVDocRef.TRDRWTAXCond, VS4TARVDocRef.TRDRWTAXDesc, 
                  VS4TARVDocRef.TRDRCommissionBase, VS4TARVDocRef.TRDRCommissionRate, VS4TARVDocRef.TRDRCommission, VS4TARVDocRef.TRDRInterestRate, VS4TARVDocRef.TRDRInterestTotal, 
                  VS4TARVDocRef.TRDRTOINCode, VS4TARVDocRef.TRDRDOVAT, VS4TARVDocRef.TRDRNote, VS4TARVDocRef.TRDRNote2, VS4TARVDocRef.TRDRFlag1, VS4TARVDocRef.TRDRFlag2, 
                  VS4TARVDocRef.TRDRFlag3, VS4TARVDocRef.TRDRWTAXSection, VS4TARVDocRef.TRDRWTAXBase, VS4TARInvoice.TIvoNo, VS4TARInvoice.TIvoBalanceFlag, VS4TARInvoice.TIvoType, 
                  VS4TARInvoice.TIvoTRBKCode, VS4TARInvoice.TIvoTRCACode, VS4TARInvoice.TIvoMode, VS4TARInvoice.TIvoDate, VS4TARInvoice.TIvoDueDate, VS4TARInvoice.TIvoGLMethod, 
                  VS4TARInvoice.TIvoTGLTNo, VS4TARInvoice.TIvoTaxNo, VS4TARInvoice.TIvoRefNo, VS4TARInvoice.TIvoRefDate, VS4TARInvoice.TIvoRefNo2, VS4TARInvoice.TIvoRefDate2, VS4TARInvoice.TIvoPONo, 
                  VS4TARInvoice.TIvoSOCode, VS4TARInvoice.TIvoJobCode, VS4TARInvoice.TIvoTJobNo, VS4TARInvoice.TIvoTJbMLn, VS4TARInvoice.TIvoTPrjCode, VS4TARInvoice.TIvoTBraCode, 
                  VS4TARInvoice.TIvoTEmpCode, VS4TARInvoice.TIvoSaleName, VS4TARInvoice.TIvoDeliveryDate, VS4TARInvoice.TIvoDeliveryTo, VS4TARInvoice.TIvoTARNCode, VS4TARInvoice.TIvoTARDCode, 
                  VS4TARInvoice.TIvoContactNote, VS4TARInvoice.TIvoContactName, VS4TARInvoice.TIvoCustomerName, VS4TARInvoice.TIvoCusAddress, VS4TARInvoice.TIvoCustomerName2, 
                  VS4TARInvoice.TIvoCusAddress2, VS4TARInvoice.TIvoConsignee, VS4TARInvoice.TIvoNotifyParty, VS4TARInvoice.TIvoCostTotal, VS4TARInvoice.TIvoPriceChannel, VS4TARInvoice.TIvoChannelName, 
                  VS4TARInvoice.TIvoDiscountList, VS4TARInvoice.TIvoSubTotal, VS4TARInvoice.TIvoDiscountText, VS4TARInvoice.TIvoDiscountTotal, VS4TARInvoice.TIvoNetTotal, VS4TARInvoice.TIvoDepositText, 
                  VS4TARInvoice.TIvoDeposit, VS4TARInvoice.TIvoTotal, VS4TARInvoice.TIvoTotalFOB, VS4TARInvoice.TIvoTCurCode, VS4TARInvoice.TIvoExchangeRate, VS4TARInvoice.TIvoTotalInRate, 
                  VS4TARInvoice.TIvoVATType, VS4TARInvoice.TIvoVATRate, VS4TARInvoice.TIvoTaxBase, VS4TARInvoice.TIvoVATTotal, VS4TARInvoice.TIvoGrandTotal, VS4TARInvoice.TIvoNOTAXTotal, 
                  VS4TARInvoice.TIvoWTaxBase, VS4TARInvoice.TIvoWTaxRate, VS4TARInvoice.TIvoWTaxTotal, VS4TARInvoice.TIvoNetPayment, VS4TARInvoice.TIvoBaseArrears, VS4TARInvoice.TIvoArrears, 
                  VS4TARInvoice.TIvoAdjustTotal, VS4TARInvoice.TIvoBaseAvailable, VS4TARInvoice.TIvoAvailable, VS4TARInvoice.TIvoRewardTotal, VS4TARInvoice.TIvoPremiumTotal, VS4TARInvoice.TIvoCommissionBase, 
                  VS4TARInvoice.TIvoCommissionRate, VS4TARInvoice.TIvoCommission, VS4TARInvoice.TIvoBaseIncoType, VS4TARInvoice.TIvoIncoType, VS4TARInvoice.TIvoIncoTerms, VS4TARInvoice.TIvoOtherFee, 
                  VS4TARInvoice.TIvoTransportFee, VS4TARInvoice.TIvoHandlingFee, VS4TARInvoice.TIvoFreightFee, VS4TARInvoice.TIvoInsurance, VS4TARInvoice.TIvoTransportDesc, VS4TARInvoice.TIvoDuty, 
                  VS4TARInvoice.TIvoShipBy, VS4TARInvoice.TIvoCountryOrigin, VS4TARInvoice.TIvoDestination, VS4TARInvoice.TIvoCondition, VS4TARInvoice.TIvoConditionDay, VS4TARInvoice.TIvoCondition1, 
                  VS4TARInvoice.TIvoConditionDay1, VS4TARInvoice.TIvoPaymentNote, VS4TARInvoice.TIvoStatementNote, VS4TARInvoice.TIvoTShpCode, VS4TARInvoice.TIvoDeliveryNote, VS4TARInvoice.TIvoPackingNote, 
                  VS4TARInvoice.TIvoCustom1, VS4TARInvoice.TIvoCustom2, VS4TARInvoice.TIvoCustom3, VS4TARInvoice.TIvoCustom4, VS4TARInvoice.TIvoCustom5, VS4TARInvoice.TIvoCustom6, 
                  VS4TARInvoice.TIvoCartonName, VS4TARInvoice.TIvoTotalCarton, VS4TARInvoice.TIvoTotalNW, VS4TARInvoice.TIvoTotalGW, VS4TARInvoice.TIvoDayAvailable, VS4TARInvoice.TIvoDescription, 
                  VS4TARInvoice.TIvoTSOTCode, VS4TARInvoice.TIvoDeliveryStatus, VS4TARInvoice.TIvoBillStatus, VS4TARInvoice.TIvoCardFlag, VS4TARInvoice.TIvoTaxFlag, VS4TARInvoice.TIvoCreateCode, 
                  VS4TARInvoice.TIvoCreateBy, VS4TARInvoice.TIvoCreateDate, VS4TARInvoice.TIvoEditCode, VS4TARInvoice.TIvoEditBy, VS4TARInvoice.TIvoEditDate, VS4TARInvoice.TIvoConfirmStatus, 
                  VS4TARInvoice.TIvoConfirmBy, VS4TARInvoice.TIvoConfirmDate, VS4TARInvoice.TIvoApproveStatus, VS4TARInvoice.TIvoApproveBy, VS4TARInvoice.TIvoApproveDate, VS4TARInvoice.TIvoApproveNote, 
                  VS4TARInvoice.TIvoRevision, VS4TARInvoice.TIvoCancelStatus, VS4TARInvoice.TIvoCancelNo, VS4TARInvoice.TIvoCancelBy, VS4TARInvoice.TIvoCancelDate, VS4TARInvoice.TIvoCancelNote, 
                  VS4TARInvoice.TIvoFlag1, VS4TARInvoice.TIvoFlag2, VS4TARInvoice.TIvoFlag3, VS4TARInvoice.TIvoTRouCode, VS4TARInvoice.TIvoCustomNo, VS4TARInvoice.TIvoCustomDate, 
                  VS4TARInvoice.TIvoPMCostTotal, VS4TARInvoice.TIvoTOTNLn, VS4TARInvoice.TIvoDeliveryCond, VS4TARInvoice.TIvoLoadingDate, VS4TARInvoice.TIvoStartAgingDate, VS4TARInvoice.TIvoIgnoreArrears, 
                  VS4TARInvoice.TIvoBoxList, VS4TARInvoice.TIvoExchangeRate2, VS4TARInvoice.TIvoNote, VS4TARInvoice.TIvoTotalQuantity, VS4TARInvoice.TIvoTPOSCode, VS4TARInvoice.TIvoReceiptStatus, 
                  VS4TARInvoice.TIvoManualArrear, VS4TARInvoice.TIvoCardStatus, VS4TARInvoice.TIvoRefNo3, VS4TARInvoice.TIvoTARWCode, VS4TARInvoice.TIvoTotalVolumeM, VS4TARInvoice.TIvoRefNo4, 
                  VS4TARInvoice.TIvoLastPayDate, VS4TARInvoice.TIvoInvoiceStatus, VS4TARInvoice.TIvoCNStatus, VS4TARInvoice.TIvoClientTaxNo, VS4TARInvoice.TIvoBranchCode, VS4TARInvoice.TIvoBranchName, 
                  VS4TARInvoice.TIvoStockCard, VS4TARInvoice.TIvoCopyNote, VS4TARInvoice.TIvoTPitNo, VS4TARInvoice.TIvoTIvoNo, VS4TARInvoiceMB.TIoMTIvoNo, VS4TARInvoiceMB.TIoMLn, 
                  VS4TARInvoiceMB.TIoMType, VS4TARInvoiceMB.TIoMGroupName, VS4TARInvoiceMB.TIoMJobCode, VS4TARInvoiceMB.TIoMTOInCode, VS4TARInvoiceMB.TIoMTPOSCode, VS4TARInvoiceMB.TIoMSerialNo, 
                  VS4TARInvoiceMB.TIoMCustom1, VS4TARInvoiceMB.TIoMCustom2, VS4TARInvoiceMB.TIoMCustom3, VS4TARInvoiceMB.TIoMCustom4, VS4TARInvoiceMB.TIoMCustom5, VS4TARInvoiceMB.TIoMShippingMark, 
                  VS4TARInvoiceMB.TIoMPOSCode, VS4TARInvoiceMB.TIoMFactoryCode, VS4TARInvoiceMB.TIoMPOSName, VS4TARInvoiceMB.TIoMCost, VS4TARInvoiceMB.TIoMPrice, VS4TARInvoiceMB.TIoMPerQuantity, 
                  VS4TARInvoiceMB.TIoMUnitFactor, VS4TARInvoiceMB.TIoMAcceptError, VS4TARInvoiceMB.TIoMUnitCalc, VS4TARInvoiceMB.TIoMQuantityCalc, VS4TARInvoiceMB.TIoMQuantityText, 
                  VS4TARInvoiceMB.TIoMQuantity, VS4TARInvoiceMB.TIoMTUntCode, VS4TARInvoiceMB.TIoMQuantity2, VS4TARInvoiceMB.TIoMTUntCode2, VS4TARInvoiceMB.TIoMQuantity3, VS4TARInvoiceMB.TIoMTUntCode3, 
                  VS4TARInvoiceMB.TIoMCostAmount, VS4TARInvoiceMB.TIoMAmount, VS4TARInvoiceMB.TIoMDiscountText, VS4TARInvoiceMB.TIoMDiscountTotal, VS4TARInvoiceMB.TIoMNetAmount, 
                  VS4TARInvoiceMB.TIoMTaxType, VS4TARInvoiceMB.TIoMTaxBase, VS4TARInvoiceMB.TIoMWTAXBase, VS4TARInvoiceMB.TIoMAmountVAT, VS4TARInvoiceMB.TIoMAmountWTAX, 
                  VS4TARInvoiceMB.TIoMPromotionType, VS4TARInvoiceMB.TIoMFreeCode, VS4TARInvoiceMB.TIoMIsPremium, VS4TARInvoiceMB.TIoMDescription, VS4TARInvoiceMB.TIoMSourceNo, 
                  VS4TARInvoiceMB.TIoMSourceLn, VS4TARInvoiceMB.TIoMSourceDate, VS4TARInvoiceMB.TIoMTWahCode, VS4TARInvoiceMB.TIoMTLctCode, VS4TARInvoiceMB.TIoMCommissionBase, 
                  VS4TARInvoiceMB.TIoMCommissionRate, VS4TARInvoiceMB.TIoMCommission, VS4TARInvoiceMB.TIoMFlag1, VS4TARInvoiceMB.TIoMFlag2, VS4TARInvoiceMB.TIoMFlag3, VS4TARInvoiceMB.TIoMPremiumCost, 
                  VS4TARInvoiceMB.TIoMQuantityStock, VS4TARInvoiceMB.TIoMAVGWeighting, VS4TARInvoiceMB.TIoMDiscountBill, VS4TARInvoiceMB.TIoMDeposit, VS4TARInvoiceMB.TIoMTARWCode, 
                  VS4TARInvoiceMB.TIoMTRCACode, VS4TARInvoiceMB.TIoMStockFlag, VS4TARInvoiceMB.TIoMMinimumOrder, VS4TARInvoiceMB.TIoMWelfareRate, VS4TARInvoiceMB.TIoMControlQty, 
                  VS4TARInvoiceMB.TIoMWelfareAmount, VS4TARInvoiceMB.TIoMTPltCode, VS4TARInvoiceMB.TIoMTotalCN, VS4TARInvoiceMB.TIoMTotalCNArr, VS4TARInvoiceMB.TIoMQuantityPallet, 
                  VS4TARInvoiceMB.TIoMPOSName2, VS4TARInvoiceMB.TIoMQuantityBase, VS4TARInvoiceMB.TIoMPickingNo, VS4TARInvoiceMB.TIoMNAmountInRate, VS4TARInvoiceMB.TIoMSourcePeriod, 
                  VS4TPOS.TPOSCode, VS4TPOS.TPOSType, VS4TPOS.TPOSPackText1, VS4TPOS.TPOSPackText2, VS4TPOS.TPOSPackAlias1, VS4TPOS.TPOSPackAlias2, VS4TPOS.TPOSLeadDay, 
                  VS4TPOS.TPOSMultipleOrder, VS4TPOS.TPOSMinimumOrder, VS4TPOS.TPOSCutStock, VS4TPOS.TPOSPrice, VS4TPOS.TPOSLastPrice, VS4TPOS.TPOSLastPriceDate, VS4TPOS.TPOSHideAfterSold, 
                  VS4TPOS.TPOSSaleCount, VS4TPOS.TPOSFirstSaleDate, VS4TPOS.TPOSLastSaleDate, VS4TPOS.TPOSDisplaySub, VS4TPOS.TPOSDisplaySubMB, VS4TPOS.TPOSOnSale, VS4TPOS.TPOSRefund, 
                  VS4TPOS.TPOSWarranty, VS4TPOS.TPOSWarrantyUnit, VS4TPOS.TPOSWarrantyType, VS4TPOS.TPOSSaleStockMinus, VS4TPOS.TPOSTotalQuantity, VS4TPOS.TPOSFlag1, VS4TPOS.TPOSFlag2, 
                  VS4TPOS.TPOSFlag3, VS4TPOS.TPOSSaleCode, VS4TPOS.TPOSPeriod, VS4TPOS.TPOSTARNCode, VS4TPOS.TPOSTPSGCode, VS4TPOS.TPOSG1TAPNCode, VS4TPOS.TPOSG2TAPNCode, 
                  VS4TPOS.TPOSTLTAPNCode, VS4TPOS.TPOSTL2TAPNCode, VS4TPOS.TPOSTL3TAPNCode, VS4TPOS.TPOSTL4TAPNCode, VS4TPOS.TPOSG3TAPNCode, VS4TPOS.TPOSG4TAPNCode, 
                  VS4TPOS.TPOSS1TEmpCode, VS4TPOS.TPOSS2TEmpCode, VS4TPOS.TPOSPackDisplay, VS4TPOS.TPOSUnitCalc, VS4TPOS.TPOSGuideCount, VS4TPOS.TPOSTourCount, VS4TPOS.TPOSSaleCountShip, 
                  VS4TARReceipt.TAIHNo, VS4TARReceipt.TAIHDate
FROM     VS4TARInvoiceMB INNER JOIN
                  VS4TARInvoice ON VS4TARInvoiceMB.TIoMTIvoNo = VS4TARInvoice.TIvoNo INNER JOIN
                  VS4TARVoucher INNER JOIN
                  VS4TReceipt INNER JOIN
                  VS4TARVandReceipt ON VS4TReceipt.TRECNo = VS4TARVandReceipt.TRNRTRECNo ON VS4TARVoucher.TRVHNo = VS4TARVandReceipt.TRNRTRVHNo INNER JOIN
                  VS4TARVDocRef LEFT OUTER JOIN
                  VS4TARReceipt ON VS4TARVDocRef.TRDRRefReceiptNo = VS4TARReceipt.TAIHNo ON VS4TARVoucher.TRVHNo = VS4TARVDocRef.TRDRTRVHNo ON 
                  VS4TARInvoice.TIvoNo = VS4TARVDocRef.TRDRRefDocNo LEFT OUTER JOIN
                  VS4TPOS ON VS4TARInvoiceMB.TIoMTPOSCode = VS4TPOS.TPOSCode

GO

CREATE VIEW VS4VRVPassenger AS  SELECT VS4TSOPassenger.TVSPTARNCode, VS4TAR.TARNName, VS4TARVDocRef.TRDRAmountRate, VS4TARInvoiceMB.TIoMQuantity, VS4TARVoucher.TRVHNo, VS4TARInvoice.TIvoNo, VS4TARInvoice.TIvoType, VS4TARInvoiceMB.TIoMSourceNo, VS4TSOMB.TSOBTSODNo, VS4TSOMB.TSOBTPOSCode, VS4TSO.TSODTBraCode, VS4TSOPassenger.TVSPLn, VS4TSO.TSODApproveStatus, VS4TSO.TSODCancelStatus, VS4TARVoucher.TRVHApproveStatus, VS4TARVoucher.TRVHCancelStatus, VS4TAR3.TAR3SourceType, VS4TPOS.TPOSTPSGCode, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtTPSECode, VS4TSO.TSODDate, VS4TSO.TSODTSBkCode, VS4TSO.TSODTPrjCode FROM VS4TARVoucher INNER JOIN ((((((VS4TSO INNER JOIN (((VS4TARVDocRef INNER JOIN VS4TARInvoice ON VS4TARVDocRef.TRDRRefDocNo = VS4TARInvoice.TIvoNo) INNER JOIN (SELECT VS4TARInvoiceMB.TIoMTIvoNo, VS4TARInvoiceMB.TIoMTPOSCode, Sum(VS4TARInvoiceMB.TIoMQuantity) AS TIoMQuantity, Max(VS4TARInvoiceMB.TIoMSourceNo) AS TIoMSourceNo FROM VS4TARInvoiceMB GROUP BY VS4TARInvoiceMB.TIoMTIvoNo, VS4TARInvoiceMB.TIoMTPOSCode) AS VS4TARInvoiceMB ON VS4TARInvoice.TIvoNo = VS4TARInvoiceMB.TIoMTIvoNo) INNER JOIN (SELECT VS4TSOMB.TSOBTSODNo, VS4TSOMB.TSOBTPOSCode, Sum(VS4TSOMB.TSOBQuantity) AS TSOBQuantity FROM VS4TSOMB GROUP BY VS4TSOMB.TSOBTSODNo, VS4TSOMB.TSOBTPOSCode) AS VS4TSOMB ON VS4TARInvoiceMB.TIoMSourceNo = VS4TSOMB.TSOBTSODNo) ON VS4TSO.TSODNo = VS4TSOMB.TSOBTSODNo) INNER JOIN VS4TSOPassenger ON (VS4TSOMB.TSOBTSODNo = VS4TSOPassenger.TVSPTSODNo) AND (VS4TSOMB.TSOBTPOSCode = VS4TSOPassenger.TVSPTPdtCode)) INNER JOIN VS4TAR ON VS4TSOPassenger.TVSPTARNCode = VS4TAR.TARNCode) INNER JOIN VS4TPOS ON VS4TSOMB.TSOBTPOSCode = VS4TPOS.TPOSCode) INNER JOIN VS4TProduct ON VS4TPOS.TPOSCode = VS4TProduct.TPdtCode) INNER JOIN VS4TAR3 ON VS4TAR.TARNCode = VS4TAR3.TAR3TARNCode) ON VS4TARVoucher.TRVHNo = VS4TARVDocRef.TRDRTRVHNo
GO

CREATE VIEW VS4VAPCardIVDBCNR AS  SELECT VS4TAPCard.TPICTAPNCODE, VS4TAPCard.TPICDOCNO, VS4TAPCard.TPICTYPE, VS4TAPCard.TPICDUEDATE, VS4TAPCard.TPICDOCDATE, VS4TAPInvoice.TIAPGRANDTOTAL, VS4TAP.TAPNNAME, VS4TAPInvoice.TIAPDATE, VS4TAPInvoice.TIAPREFNO, VS4TAPInvoice.TIAPARREARS, VS4TAPCard.TPICLN, VS4TAPCard.TPICTPrjCode, VS4TAPCard.TPICCANCELSTATUS, VS4TAPInvoice.TIAPType, VS4TAPInvoice.TIAPTotalFOB, VS4TAPInvoice.TIAPTotal, VS4TAPInvoice.TIAPExchangeRate, VS4TAPInvoice.TIAPIncoType, VS4TAPInvoice.TIAPBaseIncoType, VS4TAPInvoice.TIAPFreightFee, VS4TAPInvoice.TIAPInsurance,  (SELECT isnull(SUM(TIAPAvailable),0) AS A FROM VS4TAPInvoice WHERE (TIAPType=5 or TIAPType=7) AND TIAPApproveStatus=1 AND TIAPCancelStatus=0 AND TIAPAvailable>0 AND (3=3) AND VS4TAPInvoice.TIAPTAPNCode=VS4TAP.TAPNCode) AS VPICDeposit,  (SELECT isnull(sum(TPVRAmountRate),0) FROM VS4VPV WHERE VS4VPV.TAPVApproveStatus=1 AND VS4VPV.TAPVCancelStatus=0 AND VS4VPV.TPVRRefDocNo=VS4TAPCARD.TPICDocNo AND (1=1)) AS VPICPVPaid,  (SELECT isnull(SUM(TTxTWTaxAmount),0) FROM VS4TTaxTrans WHERE TTxTTTaxAlias='WTAX' AND VS4TTaxTrans.TTxTDocNo=VS4TAPCARD.TPICDOCNO AND VS4TTaxTrans.TTxTCANCELSTATUS=0) AS VPICWHT,  (SELECT isnull(sum(TRVRAmountInRate),0) FROM VS4VRVPay WHERE VS4VRVPay.TRVHApproveStatus=1 AND VS4VRVPay.TRVHCancelStatus=0 AND VS4VRVPay.TRVRDocNo=VS4TAPCARD.TPICDocNo AND (2=2)) AS VPICRVPaid, VS4TAP.TAPNTAPGCode, VS4TAPCard.TPICDisplayDate, VS4TAPCard.TPICSignArrear, VS4TAPBalance.TAPLBeginBalance, VS4TAPBalance.TAPLEndBalance, VS4TAPCard.TPICSignTotal, VS4TAPCard.TPICTACPTACYID, VS4TAPInvoice.TIAPStartAgingDate 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 VS4TAPInvoice ON VS4TAPCard.TPICDocNo = VS4TAPInvoice.TIAPNo) ON VS4TBranch.TBraCode = VS4TAPCard.TPICTBraCode) LEFT JOIN VS4TProject ON VS4TAPCard.TPICTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TAPBalance ON (VS4TAPCard.TPICTAPNCode = VS4TAPBalance.TAPLTAPNCode) AND (VS4TAPCard.TPICTACPTACYID = VS4TAPBalance.TAPLTACPTACYID) AND (VS4TAPCard.TPICTACPID = VS4TAPBalance.TAPLTACPID)) ON VS4TAP.TAPNCode = VS4TAPCard.TPICTAPNCode WHERE (((VS4TAPCard.TPICTYPE)<>'O') AND ((VS4TAPInvoice.TIAPType)<>10 And (VS4TAPInvoice.TIAPType)<>7 And (VS4TAPInvoice.TIAPType)<>5)) OR (((VS4TAPInvoice.TIAPType) Is Null))
GO

CREATE VIEW VS4VRVPay2Invoice 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.TRDRRefReceiptNo,                           VS4TARReceipt.TAIHDate, VS4TARInvoice.TIvoTPrjCode, VS4TProject.TPrjName, 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, VS4TARVDocRef.TRDRRefDocDate,                           VS4TARVoucherPay.TRVRAmountInRate, VS4TARVoucherPay.TRVRTransferDate, VS4TARVoucherPay.TRVRCashDate, VS4TAR.TARNAddressBill, VS4TAR.TARNPhone, VS4TAR.TARNMobile,                           VS4TAR3.TAR3BirthDay, VS4TAR3.TAR3BirthDayValid, VS4TARInvoice.TIvoTPOSCode, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtStartDate, VS4TProduct.TPdtEndDate,                           VS4TARInvoiceMB.TIoMTIvoNo, VS4TARInvoiceMB.TIoMLn, VS4TARInvoice.TIvoType, VS4TARVoucher.TRVHArrear, VS4TARVDocRef.TRDRAmountRate, VS4TARVoucher.TRVHTBraCode,                           VS4TARVoucherPay.TRVRTCBBNo FROM            VS4TProject RIGHT OUTER JOIN                          VS4TAR2 RIGHT OUTER JOIN                          VS4TSaleArea RIGHT OUTER JOIN                          VS4TARGroup RIGHT OUTER JOIN                          VS4TAR ON VS4TARGroup.TARGCode = VS4TAR.TARNTARGCode ON VS4TSaleArea.TSAeCode = VS4TAR.TARNTSAeCode ON VS4TAR2.TAR2TARNCode = VS4TAR.TARNCode LEFT OUTER JOIN                          VS4TEmployee ON VS4TAR2.TAR2SaleCode = VS4TEmployee.TEmpCode LEFT OUTER JOIN                          VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode LEFT OUTER JOIN                          VS4TAR3 ON VS4TAR.TARNCode = VS4TAR3.TAR3TARNCode RIGHT OUTER JOIN                          VS4TProduct RIGHT OUTER JOIN                          VS4TARVoucherPay RIGHT OUTER JOIN                          VS4TARVDocRef INNER JOIN                          VS4TARInvoice INNER JOIN                          VS4TARInvoiceMB ON VS4TARInvoice.TIvoNo = VS4TARInvoiceMB.TIoMTIvoNo ON VS4TARVDocRef.TRDRRefDocNo = VS4TARInvoice.TIvoNo LEFT OUTER JOIN                          VS4TARReceipt ON VS4TARVDocRef.TRDRRefReceiptNo = VS4TARReceipt.TAIHNo LEFT OUTER JOIN                          VS4TARBill ON VS4TARVDocRef.TRDRRefBillNo = VS4TARBill.TBilNo LEFT OUTER JOIN                          VS4TARVoucher ON VS4TARVDocRef.TRDRTRVHNo = VS4TARVoucher.TRVHNo ON VS4TARVoucherPay.TRVRTRVHNo = VS4TARVoucher.TRVHNo LEFT OUTER JOIN                          VS4TChequeRec RIGHT OUTER JOIN                          VS4TChequeRec2RV ON VS4TChequeRec.TCHRNo = VS4TChequeRec2RV.TR2RTCHRNo ON VS4TARVoucherPay.TRVRLn = VS4TChequeRec2RV.TR2RTRVRLn AND                           VS4TARVoucherPay.TRVRTRVHNo = VS4TChequeRec2RV.TR2RTRVRTRVHNo LEFT OUTER JOIN                          VS4TBranch ON VS4TARInvoice.TIvoTBraCode = VS4TBranch.TBraCode LEFT OUTER JOIN                          VS4TCountry ON VS4TARInvoice.TIvoCountryOrigin = VS4TCountry.TCouCode ON VS4TProduct.TPdtCode = VS4TARInvoice.TIvoTPOSCode ON                           VS4TAR.TARNCode = VS4TARInvoice.TIvoTARNCode LEFT OUTER JOIN                          VS4TBusinessType ON VS4TAR.TARNTBsTCode = VS4TBusinessType.TBsTCode ON VS4TProject.TPrjCode = VS4TARInvoice.TIvoTPrjCode WHERE        (VS4TARInvoice.TIvoType <> 10)
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 VS4VRT AS  SELECT VS4TSO.TSODNo, VS4TSO.TSODTSBkCode, VS4TSO.TSODTRCACode, VS4TSO.TSODMode, VS4TSO.TSODCode, VS4TSO.TSODType, VS4TSO.TSODDate, VS4TSO.TSODDueDate, VS4TSO.TSODRefNo, VS4TSO.TSODRefDate, VS4TSO.TSODTPrjCode, VS4TSO.TSODTBraCode, VS4TSO.TSODTEmpCode, VS4TSO.TSODSaleName, VS4TSO.TSODGuideText, VS4TSO.TSODEmpText, VS4TSO.TSODDeliveryDate, VS4TSO.TSODDeliveryTo, VS4TSO.TSODTARNCode, VS4TSO.TSODTARDCode, VS4TSO.TSODContactNote, VS4TSO.TSODContactName, VS4TSO.TSODCustomerName, VS4TSO.TSODCusAddress, VS4TSO.TSODConsignee, VS4TSO.TSODNotifyParty, VS4TSO.TSODCostTotal, VS4TSO.TSODPriceChannel, VS4TSO.TSODDiscountList, VS4TSO.TSODSubTotal, VS4TSO.TSODDiscountText, VS4TSO.TSODDiscountTotal, VS4TSO.TSODNetTotal, VS4TSO.TSODDepositText, VS4TSO.TSODDeposit, VS4TSO.TSODTotal, VS4TSO.TSODTotalFOB, VS4TSO.TSODTCurCode, VS4TSO.TSODExchangeRate, VS4TSO.TSODTotalInRate, VS4TSO.TSODVATType, VS4TSO.TSODVATRate, VS4TSO.TSODTaxBase, VS4TSO.TSODVATTotal, VS4TSO.TSODGrandTotal, VS4TSO.TSODNOTAXTotal, VS4TSO.TSODWTAXBase, VS4TSO.TSODWTaxRate, VS4TSO.TSODWTaxTotal, VS4TSO.TSODNetPayment, VS4TSO.TSODAdjustTotal, VS4TSO.TSODRewardTotal, VS4TSO.TSODPremiumTotal, VS4TSO.TSODCommissionBase, VS4TSO.TSODCommissionRate, VS4TSO.TSODCommission, VS4TSO.TSODBaseIncoType, VS4TSO.TSODIncoType, VS4TSO.TSODIncoterms, VS4TSO.TSODOtherFee, VS4TSO.TSODTransportFee, VS4TSO.TSODHandlingFee, VS4TSO.TSODFreightFee, VS4TSO.TSODInsurance, VS4TSO.TSODTransportDesc, VS4TSO.TSODDuty, VS4TSO.TSODShipBy, VS4TSO.TSODCountryOrigin, VS4TSO.TSODDestination, VS4TSO.TSODCondition, VS4TSO.TSODConditionDay, VS4TSO.TSODCondition1, VS4TSO.TSODConditionDay1, VS4TSO.TSODPaymentNote, VS4TSO.TSODStatementNote, VS4TSO.TSODDeliveryNote, VS4TSO.TSODPackingNote, VS4TSO.TSODDayAvailable, VS4TSO.TSODDescription, VS4TSO.TSODCustom1, VS4TSO.TSODCustom2, VS4TSO.TSODCustom3, VS4TSO.TSODCustom4, VS4TSO.TSODCustom5, VS4TSO.TSODInvoiceStatus, VS4TSO.TSODVerifyStatus, VS4TSO.TSODTSOTCode, VS4TSO.TSODDeliveryStatus, VS4TSO.TSODFinishDate, VS4TSO.TSODCreateBy, VS4TSO.TSODCreateDate, VS4TSO.TSODEditCode, VS4TSO.TSODEditBy, VS4TSO.TSODEditDate, VS4TSO.TSODConfirmStatus, VS4TSO.TSODConfirmBy, VS4TSO.TSODConfirmDate, VS4TSO.TSODApproveStatus, VS4TSO.TSODApproveBy, VS4TSO.TSODApproveDate, VS4TSO.TSODApproveNote, VS4TSO.TSODRevision, VS4TSO.TSODReviseBy, VS4TSO.TSODCancelStatus, VS4TSO.TSODCancelBy, VS4TSO.TSODCancelDate, VS4TSO.TSODCancelNote, VS4TSO.TSODFlag1, VS4TSO.TSODPMCostTotal, VS4TSO.TSODTOTNLn, VS4TSO.TSODTime, VS4TSO.TSODDeliveryTime, VS4TSO.TSODStartDate, VS4TSO.TSODLoadingDate, VS4TSO.TSODStartAgingDate, VS4TSO.TSODArrears, VS4TSO.TSODNote, VS4TSO.TSODTAPNCode, VS4TSO.TSODCheckPoint, VS4TSOMB.TSOBTSODNo, VS4TSOMB.TSOBLn, VS4TSOMB.TSOBType, VS4TSOMB.TSOBJobCode, VS4TSOMB.TSOBGroupName, VS4TSOMB.TSOBTOInCode, VS4TSOMB.TSOBTPOSCode, VS4TSOMB.TSOBCustom1, VS4TSOMB.TSOBCustom2, VS4TSOMB.TSOBCustom3, VS4TSOMB.TSOBCustom4, VS4TSOMB.TSOBCustom5, VS4TSOMB.TSOBShippingMark, VS4TSOMB.TSOBPOSCode, VS4TSOMB.TSOBFactoryCode, VS4TSOMB.TSOBPOSName, VS4TSOMB.TSOBOLDPOSName, VS4TSOMB.TSOBCost, VS4TSOMB.TSOBPrice, VS4TSOMB.TSOBPerQuantity, VS4TSOMB.TSOBUnitFactor, VS4TSOMB.TSOBQuantityCalc, VS4TSOMB.TSOBUnitCalc, VS4TSOMB.TSOBAcceptError, VS4TSOMB.TSOBQuantityText, VS4TSOMB.TSOBQuantity, VS4TSOMB.TSOBTUntCode, VS4TSOMB.TSOBQuantity2, VS4TSOMB.TSOBTUntCode2, VS4TSOMB.TSOBQuantity3, VS4TSOMB.TSOBTUntCode3, VS4TSOMB.TSOBCostAmount, VS4TSOMB.TSOBAmount, VS4TSOMB.TSOBDiscountText, VS4TSOMB.TSOBDiscountTotal, VS4TSOMB.TSOBNetAmount, VS4TSOMB.TSOBTaxType, VS4TSOMB.TSOBTaxBase, VS4TSOMB.TSOBWTAXBase, VS4TSOMB.TSOBAmountVAT, VS4TSOMB.TSOBAmountWTAX, VS4TSOMB.TSOBPromotionType, VS4TSOMB.TSOBFreeCode, VS4TSOMB.TSOBIsPremium, VS4TSOMB.TSOBDescription, VS4TSOMB.TSOBUseDate, VS4TSOMB.TSOBSourceNo, VS4TSOMB.TSOBSourceLn, VS4TSOMB.TSOBTIvoNo, VS4TSOMB.TSOBTotalDelivery, VS4TSOMB.TSOBTotalDelivery2, VS4TSOMB.TSOBTotalDelivery3, VS4TSOMB.TSOBTotalArrear, VS4TSOMB.TSOBTotalArrear2, VS4TSOMB.TSOBTotalArrear3, VS4TSOMB.TSOBTotalJob, VS4TSOMB.TSOBTotalJob2, VS4TSOMB.TSOBTotalJob3, VS4TSOMB.TSOBTotalJobArr, VS4TSOMB.TSOBTotalJobArr2, VS4TSOMB.TSOBTotalJobArr3, VS4TSOMB.TSOBDayProcess, VS4TSOMB.TSOBTLctCode, VS4TSOMB.TSOBFG, VS4TSOMB.TSOBJobRequest, VS4TSOMB.TSOBRequestDate, VS4TSOMB.TSOBReadyDate, VS4TSOMB.TSOBStatus, VS4TSOMB.TSOBManualClose, VS4TSOMB.TSOBPremiumCost, VS4TSOMB.TSOBTotalInv, VS4TSOMB.TSOBTotalInv2, VS4TSOMB.TSOBTotalInv3, VS4TAR.TARNName2, VS4TAR.TARNPhone, VS4TAR.TARNFax, 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, 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, VS4TAR.TARNMobile, VS4TAR3.TAR3SourceType, VS4TSO.TSODTPiTNo, VS4TProductBook.TPBGTAILCode, VS4TSO.TSODSubject 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 VS4TAR3 ON VS4TAR.TARNCode = VS4TAR3.TAR3TARNCode) 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.TSODTARNCode = VS4TARBranch.TARDTARNCode) AND (VS4TSO.TSODTARDCode = VS4TARBranch.TARDCode)) 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) 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 WHERE (((VS4TSO.TSODType)=3))
GO

CREATE VIEW VS4VROH AS  SELECT VS4TSO.*, VS4TProject.TPrjName, VS4TAR.TARNName2, VS4TCountry.TCouName, VS4TCountry.TCouName2, VS4TAR.TARNPhone, VS4TAR.TARNFax, 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 WHERE (((VS4TSO.TSODType)=2))
GO

CREATE VIEW VS4VRO AS  SELECT VS4TSO.TSODNo, VS4TSO.TSODTSBkCode, VS4TSO.TSODTRCACode, VS4TSO.TSODMode, VS4TSO.TSODCode, VS4TSO.TSODType, VS4TSO.TSODDate, VS4TSO.TSODDueDate, VS4TSO.TSODRefNo, VS4TSO.TSODRefDate, VS4TSO.TSODTPrjCode, VS4TSO.TSODTBraCode, VS4TSO.TSODTEmpCode, VS4TSO.TSODSaleName, VS4TSO.TSODGuideText, VS4TSO.TSODEmpText, VS4TSO.TSODDeliveryDate, VS4TSO.TSODDeliveryTo, VS4TSO.TSODTARNCode, VS4TSO.TSODTARDCode, VS4TSO.TSODContactNote, VS4TSO.TSODContactName, VS4TSO.TSODCustomerName, VS4TSO.TSODCusAddress, VS4TSO.TSODConsignee, VS4TSO.TSODNotifyParty, VS4TSO.TSODCostTotal, VS4TSO.TSODPriceChannel, VS4TSO.TSODDiscountList, VS4TSO.TSODSubTotal, VS4TSO.TSODDiscountText, VS4TSO.TSODDiscountTotal, VS4TSO.TSODNetTotal, VS4TSO.TSODDepositText, VS4TSO.TSODDeposit, VS4TSO.TSODTotal, VS4TSO.TSODTotalFOB, VS4TSO.TSODTCurCode, VS4TSO.TSODExchangeRate, VS4TSO.TSODTotalInRate, VS4TSO.TSODVATType, VS4TSO.TSODVATRate, VS4TSO.TSODTaxBase, VS4TSO.TSODVATTotal, VS4TSO.TSODGrandTotal, VS4TSO.TSODNOTAXTotal, VS4TSO.TSODWTAXBase, VS4TSO.TSODWTaxRate, VS4TSO.TSODWTaxTotal, VS4TSO.TSODNetPayment, VS4TSO.TSODAdjustTotal, VS4TSO.TSODRewardTotal, VS4TSO.TSODPremiumTotal, VS4TSO.TSODCommissionBase, VS4TSO.TSODCommissionRate, VS4TSO.TSODCommission, VS4TSO.TSODBaseIncoType, VS4TSO.TSODIncoType, VS4TSO.TSODIncoterms, VS4TSO.TSODOtherFee, VS4TSO.TSODTransportFee, VS4TSO.TSODHandlingFee, VS4TSO.TSODFreightFee, VS4TSO.TSODInsurance, VS4TSO.TSODTransportDesc, VS4TSO.TSODDuty, VS4TSO.TSODShipBy, VS4TSO.TSODCountryOrigin, VS4TSO.TSODDestination, VS4TSO.TSODCondition, VS4TSO.TSODConditionDay, VS4TSO.TSODCondition1, VS4TSO.TSODConditionDay1, VS4TSO.TSODPaymentNote, VS4TSO.TSODStatementNote, VS4TSO.TSODDeliveryNote, VS4TSO.TSODPackingNote, VS4TSO.TSODDayAvailable, VS4TSO.TSODDescription, VS4TSO.TSODCustom1, VS4TSO.TSODCustom2, VS4TSO.TSODCustom3, VS4TSO.TSODCustom4, VS4TSO.TSODCustom5, VS4TSO.TSODInvoiceStatus, VS4TSO.TSODVerifyStatus, VS4TSO.TSODTSOTCode, VS4TSO.TSODDeliveryStatus, VS4TSO.TSODFinishDate, VS4TSO.TSODCreateBy, VS4TSO.TSODCreateDate, VS4TSO.TSODEditCode, VS4TSO.TSODEditBy, VS4TSO.TSODEditDate, VS4TSO.TSODConfirmStatus, VS4TSO.TSODConfirmBy, VS4TSO.TSODConfirmDate, VS4TSO.TSODApproveStatus, VS4TSO.TSODApproveBy, VS4TSO.TSODApproveDate, VS4TSO.TSODApproveNote, VS4TSO.TSODRevision, VS4TSO.TSODReviseBy, VS4TSO.TSODCancelStatus, VS4TSO.TSODCancelBy, VS4TSO.TSODCancelDate, VS4TSO.TSODCancelNote, VS4TSO.TSODFlag1, VS4TSO.TSODPMCostTotal, VS4TSO.TSODTOTNLn, VS4TSO.TSODTime, VS4TSO.TSODDeliveryTime, VS4TSO.TSODStartDate, VS4TSO.TSODLoadingDate, VS4TSO.TSODStartAgingDate, VS4TSO.TSODArrears, VS4TSO.TSODNote, VS4TSO.TSODTAPNCode, VS4TSO.TSODCheckPoint, VS4TSOMB.TSOBTSODNo, VS4TSOMB.TSOBLn, VS4TSOMB.TSOBType, VS4TSOMB.TSOBJobCode, VS4TSOMB.TSOBGroupName, VS4TSOMB.TSOBTOInCode, VS4TSOMB.TSOBTPOSCode, VS4TSOMB.TSOBCustom1, VS4TSOMB.TSOBCustom2, VS4TSOMB.TSOBCustom3, VS4TSOMB.TSOBCustom4, VS4TSOMB.TSOBCustom5, VS4TSOMB.TSOBShippingMark, VS4TSOMB.TSOBPOSCode, VS4TSOMB.TSOBFactoryCode, VS4TSOMB.TSOBPOSName, VS4TSOMB.TSOBOLDPOSName, VS4TSOMB.TSOBCost, VS4TSOMB.TSOBPrice, VS4TSOMB.TSOBPerQuantity, VS4TSOMB.TSOBUnitFactor, VS4TSOMB.TSOBQuantityCalc, VS4TSOMB.TSOBUnitCalc, VS4TSOMB.TSOBAcceptError, VS4TSOMB.TSOBQuantityText, VS4TSOMB.TSOBQuantity, VS4TSOMB.TSOBTUntCode, VS4TSOMB.TSOBQuantity2, VS4TSOMB.TSOBTUntCode2, VS4TSOMB.TSOBQuantity3, VS4TSOMB.TSOBTUntCode3, VS4TSOMB.TSOBCostAmount, VS4TSOMB.TSOBAmount, VS4TSOMB.TSOBDiscountText, VS4TSOMB.TSOBDiscountTotal, VS4TSOMB.TSOBNetAmount, VS4TSOMB.TSOBTaxType, VS4TSOMB.TSOBTaxBase, VS4TSOMB.TSOBWTAXBase, VS4TSOMB.TSOBAmountVAT, VS4TSOMB.TSOBAmountWTAX, VS4TSOMB.TSOBPromotionType, VS4TSOMB.TSOBFreeCode, VS4TSOMB.TSOBIsPremium, VS4TSOMB.TSOBDescription, VS4TSOMB.TSOBUseDate, VS4TSOMB.TSOBSourceNo, VS4TSOMB.TSOBSourceLn, VS4TSOMB.TSOBTIvoNo, VS4TSOMB.TSOBTotalDelivery, VS4TSOMB.TSOBTotalDelivery2, VS4TSOMB.TSOBTotalDelivery3, VS4TSOMB.TSOBTotalArrear, VS4TSOMB.TSOBTotalArrear2, VS4TSOMB.TSOBTotalArrear3, VS4TSOMB.TSOBTotalJob, VS4TSOMB.TSOBTotalJob2, VS4TSOMB.TSOBTotalJob3, VS4TSOMB.TSOBTotalJobArr, VS4TSOMB.TSOBTotalJobArr2, VS4TSOMB.TSOBTotalJobArr3, VS4TSOMB.TSOBDayProcess, VS4TSOMB.TSOBTLctCode, VS4TSOMB.TSOBFG, VS4TSOMB.TSOBJobRequest, VS4TSOMB.TSOBRequestDate, VS4TSOMB.TSOBReadyDate, VS4TSOMB.TSOBStatus, VS4TSOMB.TSOBManualClose, VS4TSOMB.TSOBPremiumCost, VS4TSOMB.TSOBTotalInv, VS4TSOMB.TSOBTotalInv2, VS4TSOMB.TSOBTotalInv3, VS4TAR.TARNName2, VS4TAR.TARNPhone, VS4TAR.TARNFax, 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, 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, VS4TAR.TARNMobile, VS4TAR3.TAR3SourceType, VS4TSO.TSODTPiTNo, VS4TProductBook.TPBGTAILCode, VS4TSO.TSODSubject 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 VS4TAR3 ON VS4TAR.TARNCode = VS4TAR3.TAR3TARNCode) 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.TSODTARNCode = VS4TARBranch.TARDTARNCode) AND (VS4TSO.TSODTARDCode = VS4TARBranch.TARDCode)) 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) 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 WHERE (((VS4TSO.TSODType)=2))
GO

CREATE VIEW VS4VLSCH AS  SELECT VS4TSO.*, VS4TProject.TPrjName, VS4TAR.TARNName2, VS4TCountry.TCouName, VS4TCountry.TCouName2, VS4TAR.TARNPhone, VS4TAR.TARNFax, 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 WHERE (((VS4TSO.TSODType)=4))
GO

CREATE VIEW VS4VLSC AS SELECT VS4TSO.TSODNo, VS4TSO.TSODTSBkCode, VS4TSO.TSODTRCACode, VS4TSO.TSODMode, VS4TSO.TSODCode, VS4TSO.TSODType, VS4TSO.TSODDate, VS4TSO.TSODDueDate,                    VS4TSO.TSODRefNo, VS4TSO.TSODRefDate, VS4TSO.TSODTPrjCode, VS4TSO.TSODTBraCode, VS4TSO.TSODTEmpCode, VS4TSO.TSODSaleName, VS4TSO.TSODGuideText, VS4TSO.TSODEmpText,                    VS4TSO.TSODDeliveryDate, VS4TSO.TSODDeliveryTo, VS4TSO.TSODTARNCode, VS4TSO.TSODTARDCode, VS4TSO.TSODContactNote, VS4TSO.TSODContactName, VS4TSO.TSODCustomerName,                    VS4TSO.TSODCusAddress, VS4TSO.TSODConsignee, VS4TSO.TSODNotifyParty, VS4TSO.TSODCostTotal, VS4TSO.TSODPriceChannel, VS4TSO.TSODDiscountList, VS4TSO.TSODSubTotal,                    VS4TSO.TSODDiscountText, VS4TSO.TSODDiscountTotal, VS4TSO.TSODNetTotal, VS4TSO.TSODDepositText, VS4TSO.TSODDeposit, VS4TSO.TSODTotal, VS4TSO.TSODTotalFOB,                    VS4TSO.TSODTCurCode, VS4TSO.TSODExchangeRate, VS4TSO.TSODTotalInRate, VS4TSO.TSODVATType, VS4TSO.TSODVATRate, VS4TSO.TSODTaxBase, VS4TSO.TSODVATTotal,                    VS4TSO.TSODGrandTotal, VS4TSO.TSODNOTAXTotal, VS4TSO.TSODWTAXBase, VS4TSO.TSODWTaxRate, VS4TSO.TSODWTaxTotal, VS4TSO.TSODNetPayment, VS4TSO.TSODAdjustTotal,                    VS4TSO.TSODRewardTotal, VS4TSO.TSODPremiumTotal, VS4TSO.TSODCommissionBase, VS4TSO.TSODCommissionRate, VS4TSO.TSODCommission, VS4TSO.TSODBaseIncoType, VS4TSO.TSODIncoType,                    VS4TSO.TSODIncoterms, VS4TSO.TSODOtherFee, VS4TSO.TSODTransportFee, VS4TSO.TSODHandlingFee, VS4TSO.TSODFreightFee, VS4TSO.TSODInsurance, VS4TSO.TSODTransportDesc,                    VS4TSO.TSODDuty, VS4TSO.TSODShipBy, VS4TSO.TSODCountryOrigin, VS4TSO.TSODDestination, VS4TSO.TSODCondition, VS4TSO.TSODConditionDay, VS4TSO.TSODCondition1,                    VS4TSO.TSODConditionDay1, VS4TSO.TSODPaymentNote, VS4TSO.TSODStatementNote, VS4TSO.TSODDeliveryNote, VS4TSO.TSODPackingNote, VS4TSO.TSODDayAvailable, VS4TSO.TSODDescription,                    VS4TSO.TSODCustom1, VS4TSO.TSODCustom2, VS4TSO.TSODCustom3, VS4TSO.TSODCustom4, VS4TSO.TSODCustom5, VS4TSO.TSODInvoiceStatus, VS4TSO.TSODVerifyStatus,                    VS4TSO.TSODTSOTCode, VS4TSO.TSODDeliveryStatus, VS4TSO.TSODFinishDate, VS4TSO.TSODCreateBy, VS4TSO.TSODCreateDate, VS4TSO.TSODEditCode, VS4TSO.TSODEditBy,                    VS4TSO.TSODEditDate, VS4TSO.TSODConfirmStatus, VS4TSO.TSODConfirmBy, VS4TSO.TSODConfirmDate, VS4TSO.TSODApproveStatus, VS4TSO.TSODApproveBy, VS4TSO.TSODApproveDate,                    VS4TSO.TSODApproveNote, VS4TSO.TSODRevision, VS4TSO.TSODReviseBy, VS4TSO.TSODCancelStatus, VS4TSO.TSODCancelBy, VS4TSO.TSODCancelDate, VS4TSO.TSODCancelNote,                    VS4TSO.TSODFlag1, VS4TSO.TSODPMCostTotal, VS4TSO.TSODTOTNLn, VS4TSO.TSODTime, VS4TSO.TSODDeliveryTime, VS4TSO.TSODStartDate, VS4TSO.TSODLoadingDate,                    VS4TSO.TSODStartAgingDate, VS4TSO.TSODArrears, VS4TSO.TSODNote, VS4TSO.TSODTAPNCode, VS4TSO.TSODCheckPoint, VS4TSOMB.TSOBTSODNo, VS4TSOMB.TSOBLn, VS4TSOMB.TSOBType,                    VS4TSOMB.TSOBJobCode, VS4TSOMB.TSOBGroupName, VS4TSOMB.TSOBTOInCode, VS4TSOMB.TSOBTPOSCode, VS4TSOMB.TSOBCustom1, VS4TSOMB.TSOBCustom2, VS4TSOMB.TSOBCustom3,                    VS4TSOMB.TSOBCustom4, VS4TSOMB.TSOBCustom5, VS4TSOMB.TSOBShippingMark, VS4TSOMB.TSOBPOSCode, VS4TSOMB.TSOBFactoryCode, VS4TSOMB.TSOBPOSName,                    VS4TSOMB.TSOBOLDPOSName, VS4TSOMB.TSOBCost, VS4TSOMB.TSOBPrice, VS4TSOMB.TSOBPerQuantity, VS4TSOMB.TSOBUnitFactor, VS4TSOMB.TSOBQuantityCalc, VS4TSOMB.TSOBUnitCalc,                    VS4TSOMB.TSOBAcceptError, VS4TSOMB.TSOBQuantityText, VS4TSOMB.TSOBQuantity, VS4TSOMB.TSOBTUntCode, VS4TSOMB.TSOBQuantity2, VS4TSOMB.TSOBTUntCode2, VS4TSOMB.TSOBQuantity3,                    VS4TSOMB.TSOBTUntCode3, VS4TSOMB.TSOBCostAmount, VS4TSOMB.TSOBAmount, VS4TSOMB.TSOBDiscountText, VS4TSOMB.TSOBDiscountTotal, VS4TSOMB.TSOBNetAmount,                    VS4TSOMB.TSOBTaxType, VS4TSOMB.TSOBTaxBase, VS4TSOMB.TSOBWTAXBase, VS4TSOMB.TSOBAmountVAT, VS4TSOMB.TSOBAmountWTAX, VS4TSOMB.TSOBPromotionType,                    VS4TSOMB.TSOBFreeCode, VS4TSOMB.TSOBIsPremium, VS4TSOMB.TSOBDescription, VS4TSOMB.TSOBUseDate, VS4TSOMB.TSOBSourceNo, VS4TSOMB.TSOBSourceLn, VS4TSOMB.TSOBTIvoNo,                    VS4TSOMB.TSOBTotalDelivery, VS4TSOMB.TSOBTotalDelivery2, VS4TSOMB.TSOBTotalDelivery3, VS4TSOMB.TSOBTotalArrear, VS4TSOMB.TSOBTotalArrear2, VS4TSOMB.TSOBTotalArrear3,                    VS4TSOMB.TSOBTotalJob, VS4TSOMB.TSOBTotalJob2, VS4TSOMB.TSOBTotalJob3, VS4TSOMB.TSOBTotalJobArr, VS4TSOMB.TSOBTotalJobArr2, VS4TSOMB.TSOBTotalJobArr3,                    VS4TSOMB.TSOBDayProcess, VS4TSOMB.TSOBTLctCode, VS4TSOMB.TSOBFG, VS4TSOMB.TSOBJobRequest, VS4TSOMB.TSOBRequestDate, VS4TSOMB.TSOBReadyDate, VS4TSOMB.TSOBStatus,                    VS4TSOMB.TSOBManualClose, VS4TSOMB.TSOBPremiumCost, VS4TSOMB.TSOBTotalInv, VS4TSOMB.TSOBTotalInv2, VS4TSOMB.TSOBTotalInv3, VS4TAR.TARNName2, VS4TAR.TARNPhone,                    VS4TAR.TARNFax, 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.VARHSaleCode,                    VS4VSaleAROnHand.VARHProspect, VS4VSaleAROnHand.VARHLoss, VS4VSaleAROnHand.VARHTotal, VS4TProduct.TPdtGroupReport, VS4TLocation.TLctTWahCode, 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, VS4TAR.TARNMobile, VS4TAR3.TAR3SourceType,                    VS4TSO.TSODTPiTNo, VS4TProductBook.TPBGTAILCode, VS4TSO.TSODSubject, VS4TSOMB2.* FROM     VS4TCountry INNER JOIN                   VS4TBusinessType RIGHT OUTER JOIN                   VS4TAR LEFT OUTER JOIN                   VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode LEFT OUTER JOIN                   VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode LEFT OUTER JOIN                   VS4TAR2 LEFT OUTER JOIN                   VS4TBusinessMajor ON VS4TAR2.TAR2TBSMCode = VS4TBusinessMajor.TBsMCode LEFT OUTER JOIN                   VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode INNER JOIN                   VS4TAR3 ON VS4TAR.TARNCode = VS4TAR3.TAR3TARNCode INNER JOIN                   VS4TSO LEFT OUTER JOIN                   VS4TProject ON VS4TSO.TSODTPrjCode = VS4TProject.TPrjCode LEFT OUTER JOIN                   VS4TBranch ON VS4TSO.TSODTBraCode = VS4TBranch.TBraCode LEFT OUTER JOIN                   VS4VSaleAROnHand ON VS4TSO.TSODTEmpCode = VS4VSaleAROnHand.VARHSaleCode LEFT OUTER JOIN                   VS4TEmployee ON VS4TSO.TSODTEmpCode = VS4TEmployee.TEmpCode LEFT OUTER 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 INNER JOIN                   VS4TProductLine RIGHT OUTER JOIN                   VS4TSOMB LEFT OUTER JOIN                   VS4TPOS ON VS4TSOMB.TSOBTPOSCode = VS4TPOS.TPOSCode LEFT OUTER JOIN                   VS4TLocation ON VS4TSOMB.TSOBTLctCode = VS4TLocation.TLctCode LEFT OUTER JOIN                   VS4TProduct LEFT OUTER JOIN                   VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode LEFT OUTER JOIN                   VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code LEFT OUTER JOIN                   VS4TProductSec3 ON VS4TProduct.TPdtTPS3Code = VS4TProductSec3.TPS3Code LEFT OUTER JOIN                   VS4TProductSec4 ON VS4TProduct.TPdtTPS4Code = VS4TProductSec4.TPS4Code LEFT OUTER JOIN                   VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code LEFT OUTER JOIN                   VS4TProductGroup2 ON VS4TProduct.TPdtTPG2Code = VS4TProductGroup2.TPG2Code ON VS4TPOS.TPOSCode = VS4TProduct.TPdtCode LEFT OUTER JOIN                   VS4TProductBook ON VS4TProduct.TPdtCode = VS4TProductBook.TPBGTPdtCode LEFT OUTER JOIN                   VS4TAP ON VS4TPOS.TPOSG1TAPNCode = VS4TAP.TAPNCode LEFT OUTER JOIN                   VS4TAP AS VS4TAP_1 ON VS4TPOS.TPOSG2TAPNCode = VS4TAP_1.TAPNCode LEFT OUTER JOIN                   VS4TAP AS VS4TAP_2 ON VS4TPOS.TPOSTLTAPNCode = VS4TAP_2.TAPNCode LEFT OUTER JOIN                   VS4TPOSSaleGroup ON VS4TPOS.TPOSTPSGCode = VS4TPOSSaleGroup.TPSGCode ON VS4TProductLine.TPdLCode = VS4TProduct.TPdtTPDLCode ON                    VS4TSO.TSODNo = VS4TSOMB.TSOBTSODNo LEFT OUTER JOIN                   VS4TSOMB2 ON VS4TSOMB.TSOBTSODNo = VS4TSOMB2.TSB2TSODNo AND VS4TSOMB.TSOBLn = VS4TSOMB2.TSB2Ln WHERE  (VS4TSO.TSODType = 4)
GO

CREATE VIEW VS4VSaleForecast AS  SELECT VS4TBranch.TBraName, VS4TBranch.TBraName2, VS4TSaleForecast.*, VS4TProduct.*, VS4TPOS.*, VS4TAR.TARNName, VS4TAR.TARNName2 FROM (((VS4TSaleForecast INNER JOIN VS4TProduct ON VS4TSaleForecast.TSFCTPdtCode = VS4TProduct.TPdtCode) INNER JOIN VS4TPOS ON VS4TSaleForecast.TSFCTPdtCode = VS4TPOS.TPOSCode) INNER JOIN VS4TBranch ON VS4TSaleForecast.TSFCTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TAR ON VS4TSaleForecast.TSFCTARNCode = VS4TAR.TARNCode
GO

CREATE VIEW VS4VSaleForecastMB AS  SELECT VS4TSaleForecastMB.*, VS4TSaleForecast.*, VS4TProduct.* FROM VS4TSaleForecast INNER JOIN (VS4TSaleForecastMB LEFT JOIN VS4TProduct ON VS4TSaleForecastMB.TSFBTSFCTPdtCode = VS4TProduct.TPdtCode) ON (VS4TSaleForecast.TSFCDay = VS4TSaleForecastMB.TSFBTSFCDay) AND (VS4TSaleForecast.TSFCMonth = VS4TSaleForecastMB.TSFBTSFCMonth) AND (VS4TSaleForecast.TSFCYear = VS4TSaleForecastMB.TSFBTSFCYear) AND (VS4TSaleForecast.TSFCTPdtCode = VS4TSaleForecastMB.TSFBTSFCTPdtCode) AND (VS4TSaleForecast.TSFCTARNCode = VS4TSaleForecastMB.TSFBTSFCTARNCode) AND (VS4TSaleForecast.TSFCTBraCode = VS4TSaleForecastMB.TSFBTSFCTBraCode)
GO

CREATE VIEW VS4VSaleForecastMT AS  SELECT VS4TSaleForecastMT.*, VS4TSaleForecast.*, VS4TProduct.* FROM VS4TSaleForecast INNER JOIN (VS4TSaleForecastMT LEFT JOIN VS4TProduct ON VS4TSaleForecastMT.TSFMTPdtCode = VS4TProduct.TPdtCode) ON (VS4TSaleForecast.TSFCDay = VS4TSaleForecastMT.TSFMTSFCDay) AND (VS4TSaleForecast.TSFCMonth = VS4TSaleForecastMT.TSFMTSFCMonth) AND (VS4TSaleForecast.TSFCYear = VS4TSaleForecastMT.TSFMTSFCYear) AND (VS4TSaleForecast.TSFCTPdtCode = VS4TSaleForecastMT.TSFMTSFCTPdtCode) AND (VS4TSaleForecast.TSFCTARNCode = VS4TSaleForecastMT.TSFMTSFCTARNCode) AND (VS4TSaleForecast.TSFCTBraCode = VS4TSaleForecastMT.TSFMTSFCTBraCode)
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 VS4VSaleTargetApp AS  SELECT VS4TSaleTarget.TSTGApproveStatus, VS4TSaleTarget.TSTGCancelStatus, VS4TSaleTargetMB.TSGMTEmpCode, VS4TSaleTargetMB.TSGMYear, VS4TSaleTargetMB.TSGMMonth, VS4TSaleTargetMB.TSGMTPDLCode, VS4TSaleTargetMB.TSGMTPSECode, VS4TSaleTargetMB.TSGMTPS2Code, VS4TSaleTargetMB.TSGMTPS3Code, VS4TSaleTargetMB.TSGMTPS4Code, VS4TSaleTargetMB.TSGMTPdtCode, VS4TSaleTargetMB.TSGMTargetQty, VS4TSaleTargetMB.TSGMTarget, VS4TSaleTargetMB.TSGMBonus, VS4TSaleTargetMB.TSGMTargetQty2, VS4TSaleTargetMB.TSGMTarget2, VS4TSaleTargetMB.TSGMBonus2, VS4TSaleTargetMB.TSGMTargetQty3, VS4TSaleTargetMB.TSGMTarget3, VS4TSaleTargetMB.TSGMBonus3, Max(VS4TSaleTarget.TSTGApproveDate) AS TSTGApproveDate FROM VS4TSaleTarget INNER JOIN VS4TSaleTargetMB ON VS4TSaleTarget.TSTGNo = VS4TSaleTargetMB.TSGMTSTGNo GROUP BY VS4TSaleTarget.TSTGApproveStatus, VS4TSaleTarget.TSTGCancelStatus, VS4TSaleTargetMB.TSGMTEmpCode, VS4TSaleTargetMB.TSGMYear, VS4TSaleTargetMB.TSGMMonth, VS4TSaleTargetMB.TSGMTPDLCode, VS4TSaleTargetMB.TSGMTPSECode, VS4TSaleTargetMB.TSGMTPS2Code, VS4TSaleTargetMB.TSGMTPS3Code, VS4TSaleTargetMB.TSGMTPS4Code, VS4TSaleTargetMB.TSGMTPdtCode, VS4TSaleTargetMB.TSGMTargetQty, VS4TSaleTargetMB.TSGMTarget, VS4TSaleTargetMB.TSGMBonus, VS4TSaleTargetMB.TSGMTargetQty2, VS4TSaleTargetMB.TSGMTarget2, VS4TSaleTargetMB.TSGMBonus2, VS4TSaleTargetMB.TSGMTargetQty3, VS4TSaleTargetMB.TSGMTarget3, VS4TSaleTargetMB.TSGMBonus3 HAVING (((VS4TSaleTarget.TSTGApproveStatus)=1) AND ((VS4TSaleTarget.TSTGCancelStatus)=0))
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 VS4VSDV AS  SELECT VS4TPackingList.*, VS4TPackingListMB.*, VS4TARInvoiceMB.*, VS4TARInvoice.TIvoNo, VS4TInventory.TInvDate, VS4TInventory.TInvRefNo3, VS4TInventoryMB.TInMTInvNo, VS4TInventoryMB.TInMSerialNo, VS4TInventoryMB.TInMAmouQuantity, VS4TInventoryMB.TInMAmouQuantity2, VS4TInventoryMB.TInMAmouQuantity3, VS4TARInvoice2.TIv2TruckNo, VS4TARInvoice2.TIv2TSDVNo, VS4TARInvoice2.TIv2LogisticType, VS4TInventoryMB.TInMTLctCode, VS4TInventoryMB.TInMTPltCode, VS4TARInvoice.TIvoDeliveryTo, VS4TARInvoice.TIvoConsignee, VS4TARInvoice.TIvoNotifyParty, VS4TARInvoice.TIvoTARNCode, VS4TARInvoice.TIvoTARDCode, VS4TARInvoice.TIvoContactNote, VS4TARInvoice.TIvoContactName, VS4TARInvoice.TIvoCustomerName, VS4TARInvoice.TIvoCusAddress, VS4TARInvoice.TIvoCustomerName2, VS4TARInvoice.TIvoCusAddress2, VS4TAR.TARNPhone, VS4TAR.TARNFax, VS4TInventoryMB.TInMScrapLevel, VS4TInventoryMB.TInMCustomerPallet FROM VS4TPackingList RIGHT JOIN ((VS4TAR RIGHT JOIN (VS4TARInvoice LEFT JOIN VS4TARInvoice2 ON VS4TARInvoice.TIvoNo = VS4TARInvoice2.TIv2TIvoNo) ON VS4TAR.TARNCode = VS4TARInvoice.TIvoTARNCode) RIGHT JOIN (VS4TInventory INNER JOIN (VS4TInventoryLOT RIGHT JOIN ((VS4TPackingListMB LEFT JOIN VS4TARInvoiceMB ON (VS4TPackingListMB.TPKMSourceLn = VS4TARInvoiceMB.TIoMLn) AND (VS4TPackingListMB.TPKMSourceNo = VS4TARInvoiceMB.TIoMTIvoNo)) RIGHT JOIN VS4TInventoryMB ON (VS4TPackingListMB.TPKMSourceLn = VS4TInventoryMB.TInMSourceLn) AND (VS4TPackingListMB.TPKMSourceNo = VS4TInventoryMB.TInMSourceNo)) 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 VS4TARInvoice.TIvoNo = VS4TARInvoiceMB.TIoMTIvoNo) ON VS4TPackingList.TPKLNo = VS4TPackingListMB.TPKMTPKLNo
GO

CREATE VIEW VS4VSE AS SELECT VS4TSO.TSODNo, VS4TSO.TSODTSBkCode, VS4TSO.TSODTRCACode, VS4TSO.TSODMode, VS4TSO.TSODCode, VS4TSO.TSODType, VS4TSO.TSODDate, VS4TSO.TSODDueDate,                    VS4TSO.TSODRefNo, VS4TSO.TSODRefDate, VS4TSO.TSODRefNo2, VS4TSO.TSODTPrjCode, VS4TSO.TSODTBraCode, VS4TSO.TSODTEmpCode, VS4TSO.TSODSaleName, VS4TSO.TSODGuideText,                    VS4TSO.TSODEmpText, VS4TSO.TSODDeliveryDate, VS4TSO.TSODDeliveryTo, VS4TSO.TSODTARNCode, VS4TSO.TSODTARDCode, VS4TSO.TSODContactNote, VS4TSO.TSODContactName,                    VS4TSO.TSODCustomerName, VS4TSO.TSODCusAddress, VS4TSO.TSODCostTotal, VS4TSO.TSODPriceChannel, VS4TSO.TSODDiscountList, VS4TSO.TSODSubTotal, VS4TSO.TSODDiscountText,                    VS4TSO.TSODDiscountTotal, VS4TSO.TSODNetTotal, VS4TSO.TSODDepositText, VS4TSO.TSODDeposit, VS4TSO.TSODTotal, VS4TSO.TSODTotalFOB, VS4TSO.TSODTCurCode,                    VS4TSO.TSODExchangeRate, VS4TSO.TSODTotalInRate, VS4TSO.TSODVATType, VS4TSO.TSODVATRate, VS4TSO.TSODTaxBase, VS4TSO.TSODVATTotal, VS4TSO.TSODGrandTotal,                    VS4TSO.TSODNOTAXTotal, VS4TSO.TSODWTAXBase, VS4TSO.TSODWTaxRate, VS4TSO.TSODWTaxTotal, VS4TSO.TSODNetPayment, VS4TSO.TSODAdjustTotal, VS4TSO.TSODRewardTotal,                    VS4TSO.TSODPremiumTotal, VS4TSO.TSODCommissionBase, VS4TSO.TSODCommissionRate, VS4TSO.TSODCommission, VS4TSO.TSODShipBy, VS4TSO.TSODCondition, VS4TSO.TSODConditionDay,                    VS4TSO.TSODCondition1, VS4TSO.TSODConditionDay1, VS4TSO.TSODPaymentNote, VS4TSO.TSODStatementNote, VS4TSO.TSODDeliveryNote, VS4TSO.TSODPackingNote, VS4TSO.TSODDayAvailable,                    VS4TSO.TSODDescription, VS4TSO.TSODCustom1, VS4TSO.TSODCustom2, VS4TSO.TSODCustom3, VS4TSO.TSODCustom4, VS4TSO.TSODCustom5, VS4TSO.TSODInvoiceStatus,                    VS4TSO.TSODVerifyStatus, VS4TSO.TSODTSOTCode, VS4TSO.TSODDeliveryStatus, VS4TSO.TSODFinishDate, VS4TSO.TSODEditCode, VS4TSO.TSODEditBy, VS4TSO.TSODEditDate,                    VS4TSO.TSODConfirmStatus, VS4TSO.TSODApproveStatus, VS4TSO.TSODApproveBy, VS4TSO.TSODApproveDate, VS4TSO.TSODApproveNote, VS4TSO.TSODRevision, VS4TSO.TSODCancelStatus,                    VS4TSO.TSODCancelDate, VS4TSO.TSODFlag1, VS4TSO.TSODPMCostTotal, VS4TSO.TSODTOTNLn, VS4TSO.TSODDeliveryTime, VS4TSO.TSODStartDate, VS4TSO.TSODLoadingDate,                    VS4TSO.TSODStartAgingDate, VS4TSO.TSODArrears, VS4TSO.TSODNote, VS4TSO.TSODTAPNCode, VS4TSOMB.TSOBTSODNo, VS4TSOMB.TSOBLn, VS4TSOMB.TSOBType, VS4TSOMB.TSOBJobCode,                    VS4TSOMB.TSOBGroupName, VS4TSOMB.TSOBTOInCode, VS4TSOMB.TSOBTPOSCode, VS4TSOMB.TSOBCustom1, VS4TSOMB.TSOBCustom2, VS4TSOMB.TSOBCustom3, VS4TSOMB.TSOBCustom4,                    VS4TSOMB.TSOBCustom5, VS4TSOMB.TSOBShippingMark, VS4TSOMB.TSOBPOSCode, VS4TSOMB.TSOBFactoryCode, VS4TSOMB.TSOBPOSName, VS4TSOMB.TSOBOLDPOSName, VS4TSOMB.TSOBCost,                    VS4TSOMB.TSOBPrice, VS4TSOMB.TSOBPerQuantity, VS4TSOMB.TSOBUnitFactor, VS4TSOMB.TSOBQuantityCalc, VS4TSOMB.TSOBUnitCalc, VS4TSOMB.TSOBAcceptError, VS4TSOMB.TSOBQuantityText,                    VS4TSOMB.TSOBQuantity, VS4TSOMB.TSOBTUntCode, VS4TSOMB.TSOBQuantity2, VS4TSOMB.TSOBTUntCode2, VS4TSOMB.TSOBQuantity3, VS4TSOMB.TSOBTUntCode3, VS4TSOMB.TSOBCostAmount,                    VS4TSOMB.TSOBAmount, VS4TSOMB.TSOBDiscountText, VS4TSOMB.TSOBDiscountTotal, VS4TSOMB.TSOBNetAmount, VS4TSOMB.TSOBTaxType, VS4TSOMB.TSOBTaxBase, VS4TSOMB.TSOBWTAXBase,                    VS4TSOMB.TSOBAmountVAT, VS4TSOMB.TSOBAmountWTAX, VS4TSOMB.TSOBPromotionType, VS4TSOMB.TSOBFreeCode, VS4TSOMB.TSOBIsPremium, VS4TSOMB.TSOBDescription,                    VS4TSOMB.TSOBUseDate, VS4TSOMB.TSOBSourceNo, VS4TSOMB.TSOBSourceLn, VS4TSOMB.TSOBTIvoNo, VS4TSOMB.TSOBTotalDelivery, VS4TSOMB.TSOBTotalArrear, VS4TSOMB.TSOBDayProcess,                    VS4TSOMB.TSOBTLctCode, VS4TSOMB.TSOBStatus, VS4TSOMB.TSOBManualClose, VS4TSOMB.TSOBPremiumCost, VS4TSOMB.TSOBTotalInv, VS4TAR.TARNName2, VS4TAR.TARNPhone,                    VS4TAR.TARNFax, VS4TARGroup.TARGName, VS4TAR.TARNName, VS4TAR.TARNTARGCode, VS4TAR.TARNTSAeCode, VS4TAR2.TAR2SaleCode, VS4TEmployee.TEmpFullName,                    VS4TBranch.TBraName, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtAliasName, VS4TProduct.TPdtDescription, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2,                    VS4TProduct.TPdtTUntCode3, VS4TProduct.TPdtTPTTCode, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtTPSECode, VS4TAR.TARNTBsTCode, VS4TProduct.TPdtTPS2Code, VS4TProduct.TPdtTPS3Code,                    VS4TProduct.TPdtTPS4Code, VS4TProduct.TPdtTPG1Code, VS4TProduct.TPdtTPG2Code, VS4TProductLine.TPdLName, VS4TProductSection_1.TPSEName, VS4TProductSec2.TPS2Name,                    VS4TProductGroup1.TPG1Name, VS4TProductGroup2.TPG2Name, VS4TAR2.TAR2TPrvCode, VS4TProvince.TPrvName, VS4TProduct.TPdtAverageCost, VS4TLocation.TLctTWahCode,                    VS4TAR.TARNFirstOrderDate, VS4TBranch.TBraAddressBill, VS4TAR.TARNAddressBill, VS4TAR.TARNAddressBill2, VS4TSOMB.TSOBTotalMDS, VS4TProject.TPrjName, VS4TSOMB.TSOBTARWCode,                    VS4TARWelfare.TARWName, VS4TSO.TSODTARWCode, VS4TSOMB.TSOBTRCACode, VS4TSOMB.TSOBFlag1, VS4TProduct.TPdtBarcode, VS4TSOMB.TSOBStockFlag, VS4TSOMB.TSOBMinimumOrder,                    VS4TSOMB.TSOBTotalInvArr, VS4TSOMB.TSOBWelfareRate, VS4TEmployee.TEmpFullName2, VS4TSO3.TSO3OnSite, VS4TSO3.TSO3TotalAttach, VS4TSO3.TSO3PayType, VS4TSO3.TSO3IsReclaim,                    VS4TSO3.TSO3Location, VS4TSO3.TSO3ReclaimNo, VS4TSO3.TSO3AppointDate, VS4TSO3.TSO3AppointTime, VS4TSO3.TSO3DestDate, VS4TSO3.TSO3DestTime, VS4TSO3.TSO3ReceiveType,                    VS4TSO3.TSO3RefFixReqNo, VS4TSO3.TSO3RefFixReqDate, VS4TSO3.TSO3Symptom, VS4TSO3.TSO3Cause, VS4TSO3.TSO3Note, VS4TSO3.TSO3CheckGoods, VS4TSO3.TSO3CheckOther,                    VS4TSO3.TSO3SlaveEquipment, VS4TSO3.TSO3CtrlTEmpCode, VS4TSO3.TSO3ExtraCharge, VS4TSO3.TSO3Status, VS4TSO3.TSO3StatusNote, VS4TSO3.TSO3CtrlNote, VS4TSO3.TSO3DriverTEmpCode,                    VS4TSO3.TSO3FirstMile, VS4TSO3.TSO3LastMile, VS4TSO3.TSO3IsCharge, VS4TSO3.TSO3JobLevel, VS4TSO3.TSO3IsOurGoods, VS4TSO3.TSO3TPOSCode, VS4TSO3.TSO3TBndCode,                    VS4TSO3.TSO3Warranty, VS4TSO3.TSO3WarrantyUnit, VS4TSO3.TSO3StartWarranty, VS4TSO3.TSO3EndWarranty, VS4TSO3.TSO3InWarranty, VS4TSO3.TSO3CtrlDate, VS4TSO3.TSO3QCTEmpCode,                    VS4TSO3.TSO3CtrlCheck, VS4TSO3.TSO3CtrlSolution, VS4TSO3.TSO3QCNote, VS4TSO.TSODCustomerStatus, VS4TSO3.TSO3JobScroll, VS4TSO3.TSO3JobScrollMode, VS4TSO3.TSO3TotalExpense,                    VS4TSO3.TSO3TAsACode, VS4TSO3.TSO3TAsAName, VS4TSO3.TSO3ServiceType, VS4TSO3.TSO3TEmpCode, VS4TSO3.TSO3TEmpName, VS4TAssetAlias.TAsATAsTCode, VS4TAssetAlias.TAsACustom1,                    VS4TAssetAlias.TAsACustom2, VS4TAssetAlias.TAsACustom3, VS4TAssetAlias.TAsACustom4, VS4TAssetAlias.TAsACustom5, VS4TSO3.TSO3StarFixTime, VS4TSO3.TSO3FinishFixTime,                    VS4TSO3.TSO3TSecCode, VS4TSO3.TSO3TDepCode, VS4TSO3.TSO3TDivCode, VS4TSO3.TSO3TBraCode, VS4TSO3.TSO3TAPNCode, VS4TSO3.TSO3QCTEmpName, VS4TSO3.TSO3CtrlTEmpName,                    VS4TSO3.TSO3DriverTEmpName, VS4TSO.TSODTime, VS4TEmployee.TEmpLicenseNote, VS4TSO3.TSO3LicenseNote, VS4TJob.TJobIncomeTotal, VS4TJob.TJobCostTotal, VS4TJob.TJobProfit,                    VS4TJob.TJobActualTotal, VS4TJobMB.TJbMActualDL, VS4TJobMB.TJbMActualMOH, VS4TJobMB.TJbMActualDM, VS4TJobMB.TJbMActualTotal, VS4TAssetAlias.TAsATPdtCode, VS4TJob.TJobRefNo,                    VS4TJob.TJobRefNo2, VS4TSO.TSODVerifyDate, CASE WHEN TSODVerifyStatus = 1 THEN TSODVerifyDate ELSE NULL END AS VSODVerifyDate, VS4TProductSection.TPSECode AS VSODTPSECode,                    VS4TProductLine_1.TPdLCode AS VSODTPdLCode FROM     VS4TAssetAlias FULL OUTER JOIN                   VS4TJob LEFT OUTER JOIN                   VS4TJobMB ON VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo RIGHT OUTER JOIN                   VS4TCountry INNER JOIN                   VS4TBusinessType RIGHT OUTER JOIN                   VS4TAR LEFT OUTER JOIN                   VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode LEFT OUTER JOIN                   VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode LEFT OUTER JOIN                   VS4TAR2 LEFT OUTER JOIN                   VS4TBusinessMajor ON VS4TAR2.TAR2TBSMCode = VS4TBusinessMajor.TBsMCode LEFT OUTER JOIN                   VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode INNER JOIN                   VS4TSO LEFT OUTER JOIN                   VS4TProject ON VS4TSO.TSODTPrjCode = VS4TProject.TPrjCode LEFT OUTER JOIN                   VS4TBranch ON VS4TSO.TSODTBraCode = VS4TBranch.TBraCode LEFT OUTER JOIN                   VS4VSaleAROnHand ON VS4TSO.TSODTEmpCode = VS4VSaleAROnHand.VARHSaleCode LEFT OUTER JOIN                   VS4TEmployee ON VS4TSO.TSODTEmpCode = VS4TEmployee.TEmpCode LEFT OUTER 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 LEFT OUTER JOIN                   VS4TSO3 ON VS4TSO.TSODNo = VS4TSO3.TSO3TSODNo INNER JOIN                   VS4TProductLine RIGHT OUTER JOIN                   VS4TSOMB LEFT OUTER JOIN                   VS4TPOS ON VS4TSOMB.TSOBTPOSCode = VS4TPOS.TPOSCode LEFT OUTER JOIN                   VS4TLocation ON VS4TSOMB.TSOBTLctCode = VS4TLocation.TLctCode LEFT OUTER JOIN                   VS4TProduct LEFT OUTER JOIN                   VS4TProductSection AS VS4TProductSection_1 ON VS4TProduct.TPdtTPSECode = VS4TProductSection_1.TPSECode LEFT OUTER JOIN                   VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code LEFT OUTER JOIN                   VS4TProductSec3 ON VS4TProduct.TPdtTPS3Code = VS4TProductSec3.TPS3Code LEFT OUTER JOIN                   VS4TProductSec4 ON VS4TProduct.TPdtTPS4Code = VS4TProductSec4.TPS4Code LEFT OUTER JOIN                   VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code LEFT OUTER JOIN                   VS4TProductGroup2 ON VS4TProduct.TPdtTPG2Code = VS4TProductGroup2.TPG2Code LEFT OUTER JOIN                   VS4TProductGroup3 ON VS4TProduct.TPdtTPG3Code = VS4TProductGroup3.TPG3Code LEFT OUTER JOIN                   VS4TProductGroup4 ON VS4TProduct.TPdtTPG4Code = VS4TProductGroup4.TPG4Code ON VS4TPOS.TPOSCode = VS4TProduct.TPdtCode LEFT OUTER JOIN                   VS4TProductBook ON VS4TProduct.TPdtCode = VS4TProductBook.TPBGTPdtCode LEFT OUTER JOIN                   VS4TProduct3 ON VS4TProduct.TPdtCode = VS4TProduct3.TPD3TPdtCode LEFT OUTER JOIN                   VS4TARWelfare ON VS4TSOMB.TSOBTARWCode = VS4TARWelfare.TARWCode ON VS4TProductLine.TPdLCode = VS4TProduct.TPdtTPDLCode ON VS4TSO.TSODNo = VS4TSOMB.TSOBTSODNo ON                    VS4TJob.TJobNo = VS4TSO.TSODNo ON VS4TAssetAlias.TAsACode = VS4TSO3.TSO3TAsACode FULL OUTER JOIN                   VS4TProduct AS VS4TProduct_1 LEFT OUTER JOIN                   VS4TProductLine AS VS4TProductLine_1 ON VS4TProduct_1.TPdtTPDLCode = VS4TProductLine_1.TPdLCode LEFT OUTER JOIN                   VS4TProductSection ON VS4TProduct_1.TPdtTPSECode = VS4TProductSection.TPSECode ON VS4TAssetAlias.TAsATPdtCode = VS4TProduct_1.TPdtCode WHERE  (VS4TSO.TSODType = 1) AND (VS4TJobMB.TJbMLn = 1 OR                   VS4TJobMB.TJbMLn IS NULL)
GO

CREATE VIEW VS4VSEH AS SELECT VS4TSO.TSODNo, VS4TSO.TSODTSBkCode, VS4TSO.TSODTRCACode, VS4TSO.TSODMode, VS4TSO.TSODCode, VS4TSO.TSODType, VS4TSO.TSODDate, VS4TSO.TSODDueDate,                    VS4TSO.TSODRefNo, VS4TSO.TSODRefDate, VS4TSO.TSODBODeposit, VS4TSO.TSODTPrjCode, VS4TSO.TSODTBraCode, VS4TSO.TSODTEmpCode, VS4TSO.TSODSaleName, VS4TSO.TSODGuideText,                    VS4TSO.TSODEmpText, VS4TSO.TSODDeliveryDate, VS4TSO.TSODDeliveryTo, VS4TSO.TSODTARNCode, VS4TSO.TSODTARDCode, VS4TSO.TSODContactNote, VS4TSO.TSODContactName,                    VS4TSO.TSODCustomerName, VS4TSO.TSODCusAddress, VS4TSO.TSODConsignee, VS4TSO.TSODNotifyParty, VS4TSO.TSODCostTotal, VS4TSO.TSODPriceChannel, VS4TSO.TSODDiscountList,                    VS4TSO.TSODSubTotal, VS4TSO.TSODDiscountText, VS4TSO.TSODDiscountTotal, VS4TSO.TSODNetTotal, VS4TSO.TSODDepositText, VS4TSO.TSODDeposit, VS4TSO.TSODTotal,                    VS4TSO.TSODTotalFOB, VS4TSO.TSODTCurCode, VS4TSO.TSODExchangeRate, VS4TSO.TSODTotalInRate, VS4TSO.TSODVATType, VS4TSO.TSODVATRate, VS4TSO.TSODTaxBase,                    VS4TSO.TSODVATTotal, VS4TSO.TSODGrandTotal, VS4TSO.TSODNOTAXTotal, VS4TSO.TSODWTAXBase, VS4TSO.TSODWTaxRate, VS4TSO.TSODWTaxTotal, VS4TSO.TSODNetPayment,                    VS4TSO.TSODAdjustTotal, VS4TSO.TSODRewardTotal, VS4TSO.TSODPremiumTotal, VS4TSO.TSODCommissionBase, VS4TSO.TSODCommissionRate, VS4TSO.TSODCommission,                    VS4TSO.TSODBaseIncoType, VS4TSO.TSODIncoType, VS4TSO.TSODIncoterms, VS4TSO.TSODOtherFee, VS4TSO.TSODTransportFee, VS4TSO.TSODHandlingFee, VS4TSO.TSODFreightFee,                    VS4TSO.TSODInsurance, VS4TSO.TSODTransportDesc, VS4TSO.TSODDuty, VS4TSO.TSODShipBy, VS4TSO.TSODCountryOrigin, VS4TSO.TSODDestination, VS4TSO.TSODCondition,                    VS4TSO.TSODConditionDay, VS4TSO.TSODCondition1, VS4TSO.TSODConditionDay1, VS4TSO.TSODPaymentNote, VS4TSO.TSODStatementNote, VS4TSO.TSODDeliveryNote, VS4TSO.TSODPackingNote,                    VS4TSO.TSODDayAvailable, VS4TSO.TSODDescription, VS4TSO.TSODCustom1, VS4TSO.TSODCustom2, VS4TSO.TSODCustom3, VS4TSO.TSODCustom4, VS4TSO.TSODCustom5,                    VS4TSO.TSODInvoiceStatus, VS4TSO.TSODVerifyStatus, VS4TSO.TSODTSOTCode, VS4TSO.TSODDeliveryStatus, VS4TSO.TSODFinishDate, VS4TSO.TSODCreateCode, VS4TSO.TSODCreateBy,                    VS4TSO.TSODCreateDate, VS4TSO.TSODEditCode, VS4TSO.TSODEditBy, VS4TSO.TSODEditDate, VS4TSO.TSODConfirmStatus, VS4TSO.TSODConfirmBy, VS4TSO.TSODConfirmDate,                    VS4TSO.TSODApproveStatus, VS4TSO.TSODApproveBy, VS4TSO.TSODApproveDate, VS4TSO.TSODApproveNote, VS4TSO.TSODRevision, VS4TSO.TSODReviseBy, VS4TSO.TSODCancelStatus,                    VS4TSO.TSODCancelNo, VS4TSO.TSODCancelBy, VS4TSO.TSODCancelDate, VS4TSO.TSODCancelNote, VS4TSO.TSODFlag1, VS4TSO.TSODFlag2, VS4TSO.TSODFlag3, VS4TSO.TSODPMCostTotal,                    VS4TSO.TSODTOTNLn, VS4TSO.TSODTime, VS4TSO.TSODDeliveryTime, VS4TSO.TSODStartDate, VS4TSO.TSODLoadingDate, VS4TSO.TSODStartAgingDate, VS4TSO.TSODArrears, VS4TSO.TSODNote,                    VS4TSO.TSODTAPNCode, VS4TSO.TSODCheckPoint, VS4TSO.TSODCreditUseTotal, VS4TSO.TSODRefNo2, VS4TSO.TSODTARWCode, VS4TSO.TSODBalanceFlag, VS4TSO.TSODTPOSCode,                    VS4TSO.TSODCustomerStatus, VS4TSO.TSODTPiTNo, VS4TSO.TSODSubject, VS4TProject.TPrjName, VS4TAR.TARNName2, VS4TCountry.TCouName, VS4TCountry.TCouName2, VS4TAR.TARNPhone,                    VS4TAR.TARNFax, 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.VARHSaleCode, VS4VSaleAROnHand.VARHProspect, VS4VSaleAROnHand.VARHLoss, VS4VSaleAROnHand.VARHTotal,                    VS4TARBranch.TARDName, VS4TSO3.TSO3OnSite, VS4TSO3.TSO3TotalAttach, VS4TSO3.TSO3PayType, VS4TSO3.TSO3IsReclaim, VS4TSO3.TSO3Status, VS4TSO3.TSO3StatusNote,                    VS4TAR.TARNMobile, VS4TSO3.TSO3JobScroll, VS4TSO3.TSO3JobScrollMode, VS4TSO3.TSO3TotalExpense, VS4TSO3.TSO3RefFixReqNo, VS4TSO3.TSO3TAsACode, VS4TSO3.TSO3TAsAName,                    VS4TSO3.TSO3ServiceType, VS4TSO3.TSO3TEmpCode, VS4TSO3.TSO3TEmpName, VS4TAssetAlias.TAsATAsTCode, VS4TAssetAlias.TAsACustom1, VS4TAssetAlias.TAsACustom2,                    VS4TAssetAlias.TAsACustom3, VS4TAssetAlias.TAsACustom4, VS4TAssetAlias.TAsACustom5, VS4TJob.TJobIncomeTotal, VS4TJob.TJobCostTotal, VS4TJob.TJobProfit, VS4TJob.TJobActualTotal,                    VS4TJobMB.TJbMActualDL, VS4TJobMB.TJbMActualMOH, VS4TJobMB.TJbMActualDM, VS4TJobMB.TJbMActualTotal, VS4TAssetAlias.TAsATPdtCode, VS4TProduct.TPdtTPSECode, VS4TJob.TJobRefNo,                    VS4TJob.TJobRefNo2, VS4TProductSection.TPSECode AS VSODTPSECode, VS4TProductLine.TPdLCode AS VSODTPdLCode, VS4TSO.TSODVerifyDate,                    CASE WHEN TSODVerifyStatus = 1 THEN TSODVerifyDate ELSE NULL END AS VSODVerifyDate FROM     VS4TAssetAlias LEFT OUTER JOIN                   VS4TProductLine RIGHT OUTER JOIN                   VS4TProduct ON VS4TProductLine.TPdLCode = VS4TProduct.TPdtTPDLCode LEFT OUTER JOIN                   VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode ON VS4TAssetAlias.TAsATPdtCode = VS4TProduct.TPdtCode RIGHT OUTER JOIN                   VS4TSO3 ON VS4TAssetAlias.TAsACode = VS4TSO3.TSO3TAsACode RIGHT OUTER JOIN                   VS4TJob RIGHT OUTER JOIN                   VS4TCountry INNER JOIN                   VS4TBusinessType RIGHT OUTER JOIN                   VS4TAR LEFT OUTER JOIN                   VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode LEFT OUTER JOIN                   VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode LEFT OUTER JOIN                   VS4TAR2 LEFT OUTER JOIN                   VS4TEmployee ON VS4TAR2.TAR2SaleCode = VS4TEmployee.TEmpCode LEFT OUTER JOIN                   VS4TBusinessMajor ON VS4TAR2.TAR2TBSMCode = VS4TBusinessMajor.TBsMCode LEFT OUTER JOIN                   VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode INNER JOIN                   VS4TSO LEFT OUTER JOIN                   VS4TProject ON VS4TSO.TSODTPrjCode = VS4TProject.TPrjCode LEFT OUTER JOIN                   VS4TBranch ON VS4TSO.TSODTBraCode = VS4TBranch.TBraCode LEFT OUTER JOIN                   VS4VSaleAROnHand ON VS4TSO.TSODTEmpCode = VS4VSaleAROnHand.VARHSaleCode LEFT OUTER 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 ON VS4TJob.TJobNo = VS4TSO.TSODNo ON                    VS4TSO3.TSO3TSODNo = VS4TSO.TSODNo LEFT OUTER JOIN                   VS4TJobMB ON VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo WHERE  (VS4TSO.TSODType = 1) AND (VS4TJobMB.TJbMLn = 1 OR                   VS4TJobMB.TJbMLn IS NULL)
GO

CREATE VIEW VS4VSF AS  SELECT VS4TSF.*, VS4TSFMB.*, VS4TPOS.*, VS4TProduct.*, VS4TBranch.TBraName, VS4TSFBook.*, VS4TAR.TARNName, VS4TAR.TARNName2, VS4TProject.TPrjName, VS4TAR.TARNMakerCode FROM ((((VS4TSF INNER JOIN VS4TBranch ON VS4TSF.TSFHTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TSFBook ON VS4TSF.TSFHTSFKCode = VS4TSFBook.TSFKCode) LEFT JOIN VS4TAR ON VS4TSF.TSFHTARNCode = VS4TAR.TARNCode) LEFT JOIN VS4TProject ON VS4TSF.TSFHTPrjCode = VS4TProject.TPrjCode) INNER JOIN ((VS4TSFMB INNER JOIN VS4TPOS ON VS4TSFMB.TSFSTPOSCode = VS4TPOS.TPOSCode) INNER JOIN VS4TProduct ON VS4TPOS.TPOSCode = VS4TProduct.TPdtCode) ON VS4TSF.TSFHNo = VS4TSFMB.TSFSTSFHNo
GO

CREATE VIEW VS4VSFH AS  SELECT VS4TSF.*, VS4TBranch.TBraName, VS4TSFBook.*, VS4TAR.TARNName, VS4TAR.TARNName2, VS4TProject.TPrjName, VS4TAR.TARNMakerCode FROM (((VS4TSF INNER JOIN VS4TBranch ON VS4TSF.TSFHTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TSFBook ON VS4TSF.TSFHTSFKCode = VS4TSFBook.TSFKCode) LEFT JOIN VS4TAR ON VS4TSF.TSFHTARNCode = VS4TAR.TARNCode) LEFT JOIN VS4TProject ON VS4TSF.TSFHTPrjCode = VS4TProject.TPrjCode
GO

CREATE VIEW VS4VShipinstruct AS  SELECT VS4TShipInstruct.*, VS4TPackingList.*, VS4TPackingListMB.*, TIoMTIvoNo, TIoMLn, TIoMType, TIoMGroupName, TIoMJobCode, TIoMTOInCode, TIoMTPOSCode, TIoMSerialNo, TIoMCustom1, TIoMCustom2, TIoMCustom3, TIoMCustom4, TIoMCustom5, TIoMShippingMark, TIoMPOSCode, TIoMFactoryCode, TIoMPOSName, TIoMCost, TIoMPrice, TIoMPerQuantity, TIoMUnitFactor, TIoMAcceptError, TIoMUnitCalc, TIoMQuantityCalc, TIoMQuantityText, TIoMQuantity, TIoMTUntCode, TIoMQuantity2, TIoMTUntCode2, TIoMQuantity3, TIoMTUntCode3, TIoMCostAmount, TIoMAmount, TIoMDiscountText, TIoMDiscountTotal, TIoMNetAmount, TIoMTaxType, TIoMTaxBase, TIoMWTAXBase, TIoMAmountVAT, TIoMAmountWTAX, TIoMPromotionType, TIoMFreeCode, TIoMIsPremium, TIoMDescription, TIoMSourceNo, TIoMSourceLn, TIoMSourceDate, TIoMTLctCode, TIoMCommissionBase, TIoMCommissionRate, TIoMCommission, TIoMFlag1, TIoMPremiumCost, TIoMQuantityStock, TIoMAVGWeighting, TIoMDiscountBill, TIoMDeposit, TIoMTARWCode, TIoMTRCACode, TIoMStockFlag, TIoMMinimumOrder, TIoMWelfareRate, TIoMControlQty, TIoMWelfareAmount, TIoMTPltCode, TIoMTotalCN, TIoMTotalCNArr, TIoMQuantityPallet, TIoMPOSName2, TIoMQuantityBase, TIoMPickingNo, VS4TARInvoice.TIvoNo, VS4TARInvoice.TIvoDate, VS4TARInvoice.TIvoApproveStatus, VS4TARInvoice.TIvoCancelStatus, VS4TARInvoice.TIvoTRBKCode, VS4TARInvoice.TIvoTARNCode, VS4TARInvoice.TIvoConsignee, VS4TARInvoice.TIvoTotalFOB, VS4TARInvoice.TIvoTotal, VS4TARInvoice.TIvoTCurCode, VS4TARInvoice.TIvoDestination, VS4TARInvoice.TIvoIncoType, VS4TARInvoice.TIvoBaseIncoType, VS4TARInvoice.TIvoFreightFee, VS4TARInvoice.TIvoInsurance FROM (VS4TAR RIGHT JOIN ((VS4TShipInstruct LEFT JOIN VS4TPackingList ON VS4TShipInstruct.TSPIRefNo2 = VS4TPackingList.TPKLNo) LEFT JOIN VS4TARInvoice ON VS4TShipInstruct.TSPIRefNo = VS4TARInvoice.TIvoNo) ON VS4TAR.TARNCode = VS4TARInvoice.TIvoTARNCode) LEFT JOIN (VS4TPackingListMB LEFT JOIN VS4TARInvoiceMB ON (VS4TPackingListMB.TPKMSourceNo = VS4TARInvoiceMB.TIoMTIvoNo) AND (VS4TPackingListMB.TPKMSourceLn = VS4TARInvoiceMB.TIoMLn)) ON VS4TPackingList.TPKLNo = VS4TPackingListMB.TPKMTPKLNo
GO

CREATE VIEW VS4VShipinstructH AS  SELECT VS4TShipInstruct.*, VS4TARInvoice.TIvoNo, VS4TARInvoice.TIvoDate, VS4TARInvoice.TIvoApproveStatus, VS4TARInvoice.TIvoCancelStatus, VS4TARInvoice.TIvoTRBKCode, VS4TARInvoice.TIvoTARNCode, VS4TARInvoice.TIvoConsignee, VS4TARInvoice.TIvoTotalFOB, VS4TARInvoice.TIvoTotal, VS4TARInvoice.TIvoTCurCode, VS4TARInvoice.TIvoDestination, VS4TARInvoice.TIvoIncoType, VS4TARInvoice.TIvoBaseIncoType, VS4TARInvoice.TIvoFreightFee, VS4TARInvoice.TIvoInsurance, VS4TAR.TARNName FROM (VS4TShipInstruct LEFT JOIN VS4TARInvoice ON VS4TShipInstruct.TSPIRefNo = VS4TARInvoice.TIvoNo) LEFT JOIN VS4TAR ON VS4TShipInstruct.TSPITARNCode = VS4TAR.TARNCode
GO

CREATE VIEW VS4VShipment AS  SELECT VS4TARInvoice.TIvoNo, VS4TARInvoice.TIvoBalanceFlag, VS4TARInvoice.TIvoType, VS4TARInvoice.TIvoTRBKCode, VS4TARInvoice.TIvoTRCACode, VS4TARInvoice.TIvoMode, VS4TARInvoice.TIvoDate, VS4TARInvoice.TIvoDueDate, VS4TARInvoice.TIvoGLMethod, VS4TARInvoice.TIvoTGLTNo, VS4TARInvoice.TIvoClientTaxNo, VS4TARInvoice.TIvoTaxNo, VS4TARInvoice.TIvoRefNo, VS4TARInvoice.TIvoRefDate, VS4TARInvoice.TIvoRefNo2, VS4TARInvoice.TIvoRefDate2, VS4TARInvoice.TIvoPONo, VS4TARInvoice.TIvoSOCode, VS4TARInvoice.TIvoJobCode, VS4TARInvoice.TIvoTJobNo, VS4TARInvoice.TIvoTJbMLn, VS4TARInvoice.TIvoTPrjCode, VS4TARInvoice.TIvoTBraCode, VS4TARInvoice.TIvoTEmpCode, VS4TARInvoice.TIvoSaleName, VS4TARInvoice.TIvoDeliveryDate, VS4TARInvoice.TIvoDeliveryTo, VS4TARInvoice.TIvoTARNCode, VS4TARInvoice.TIvoTARDCode, VS4TARInvoice.TIvoContactNote, VS4TARInvoice.TIvoContactName, VS4TARInvoice.TIvoCustomerName, VS4TARInvoice.TIvoCusAddress, VS4TARInvoice.TIvoCustomerName2, VS4TARInvoice.TIvoCusAddress2, VS4TARInvoice.TIvoConsignee, VS4TARInvoice.TIvoNotifyParty, VS4TARInvoice.TIvoCostTotal, VS4TARInvoice.TIvoPriceChannel, VS4TARInvoice.TIvoDiscountList, VS4TARInvoice.TIvoSubTotal, VS4TARInvoice.TIvoDiscountText, VS4TARInvoice.TIvoDiscountTotal, VS4TARInvoice.TIvoNetTotal, VS4TARInvoice.TIvoDepositText, VS4TARInvoice.TIvoDeposit, VS4TARInvoice.TIvoTotal, VS4TARInvoice.TIvoTotalFOB, VS4TARInvoice.TIvoTCurCode, VS4TARInvoice.TIvoExchangeRate, VS4TARInvoice.TIvoTotalInRate, VS4TARInvoice.TIvoVATType, VS4TARInvoice.TIvoVATRate, VS4TARInvoice.TIvoTaxBase, VS4TARInvoice.TIvoVATTotal, VS4TARInvoice.TIvoGrandTotal, VS4TARInvoice.TIvoNOTAXTotal, VS4TARInvoice.TIvoWTaxBase, VS4TARInvoice.TIvoWTaxRate, VS4TARInvoice.TIvoWTaxTotal, VS4TARInvoice.TIvoNetPayment, VS4TARInvoice.TIvoBaseArrears, VS4TARInvoice.TIvoArrears, VS4TARInvoice.TIvoAdjustTotal, VS4TARInvoice.TIvoBaseAvailable, VS4TARInvoice.TIvoAvailable, VS4TARInvoice.TIvoRewardTotal, VS4TARInvoice.TIvoPremiumTotal, VS4TARInvoice.TIvoCommissionBase, VS4TARInvoice.TIvoCommissionRate, VS4TARInvoice.TIvoCommission, VS4TARInvoice.TIvoBaseIncoType, VS4TARInvoice.TIvoIncoType, VS4TARInvoice.TIvoIncoTerms, VS4TARInvoice.TIvoOtherFee, VS4TARInvoice.TIvoTransportFee, VS4TARInvoice.TIvoHandlingFee, VS4TARInvoice.TIvoFreightFee, VS4TARInvoice.TIvoInsurance, VS4TARInvoice.TIvoTransportDesc, VS4TARInvoice.TIvoDuty, VS4TARInvoice.TIvoShipBy, VS4TARInvoice.TIvoCountryOrigin, VS4TARInvoice.TIvoDestination, VS4TARInvoice.TIvoCondition, VS4TARInvoice.TIvoConditionDay, VS4TARInvoice.TIvoCondition1, VS4TARInvoice.TIvoConditionDay1, VS4TARInvoice.TIvoPaymentNote, VS4TARInvoice.TIvoStatementNote, VS4TARInvoice.TIvoTShpCode, VS4TARInvoice.TIvoDeliveryNote, VS4TARInvoice.TIvoPackingNote, VS4TARInvoice.TIvoCustom1, VS4TARInvoice.TIvoCustom2, VS4TARInvoice.TIvoCustom3, VS4TARInvoice.TIvoCustom4, VS4TARInvoice.TIvoCustom5, VS4TARInvoice.TIvoCustom6, VS4TARInvoice.TIvoCartonName, VS4TARInvoice.TIvoTotalCarton, VS4TARInvoice.TIvoTotalNW, VS4TARInvoice.TIvoTotalGW, VS4TARInvoice.TIvoTotalVolumeM, VS4TARInvoice.TIvoDayAvailable, VS4TARInvoice.TIvoDescription, VS4TARInvoice.TIvoTSOTCode, VS4TARInvoice.TIvoDeliveryStatus, VS4TARInvoice.TIvoBillStatus, VS4TARInvoice.TIvoCardFlag, VS4TARInvoice.TIvoTaxFlag, VS4TARInvoice.TIvoEditCode, VS4TARInvoice.TIvoEditBy, VS4TARInvoice.TIvoEditDate, VS4TARInvoice.TIvoApproveBy, VS4TARInvoice.TIvoRevision, VS4TARInvoice.TIvoCancelStatus, VS4TARInvoice.TIvoCancelBy, VS4TARInvoice.TIvoCancelDate, VS4TARInvoice.TIvoCancelNote, VS4TARInvoice.TIvoTRouCode, VS4TARInvoice.TIvoCustomNo, VS4TARInvoice.TIvoCustomDate, VS4TARInvoice.TIvoPMCostTotal, VS4TARInvoice.TIvoTOTNLn, VS4TARInvoice.TIvoDeliveryCond, VS4TARInvoice.TIvoLoadingDate, VS4TARInvoice.TIvoStartAgingDate, VS4TARInvoice.TIvoIgnoreArrears, VS4TARInvoice.TIvoBoxList, VS4TARInvoice.TIvoExchangeRate2, VS4TARInvoice.TIvoNote, VS4TARInvoice.TIvoTotalQuantity, VS4TARInvoice.TIvoTPOSCode, VS4TARInvoice.TIvoReceiptStatus, VS4TARInvoice.TIvoManualArrear, VS4TARInvoice.TIvoCardStatus, VS4TARInvoice.TIvoRefNo3, VS4TARInvoice.TIvoTARWCode, TIoMTIvoNo, TIoMLn, TIoMType, TIoMGroupName, TIoMJobCode, TIoMTOInCode, TIoMTPOSCode, TIoMSerialNo, TIoMCustom1, TIoMCustom2, TIoMCustom3, TIoMCustom4, TIoMCustom5, TIoMShippingMark, TIoMPOSCode, TIoMFactoryCode, TIoMPOSName, TIoMCost, TIoMPrice, TIoMPerQuantity, TIoMUnitFactor, TIoMAcceptError, TIoMUnitCalc, TIoMQuantityCalc, TIoMQuantityText, TIoMQuantity, TIoMTUntCode, TIoMQuantity2, TIoMTUntCode2, TIoMQuantity3, TIoMTUntCode3, TIoMCostAmount, TIoMAmount, TIoMDiscountText, TIoMDiscountTotal, TIoMNetAmount, TIoMTaxType, TIoMTaxBase, TIoMWTAXBase, TIoMAmountVAT, TIoMAmountWTAX, TIoMPromotionType, TIoMFreeCode, TIoMIsPremium, TIoMDescription, TIoMSourceNo, TIoMSourceLn, TIoMSourceDate, TIoMTLctCode, TIoMCommissionBase, TIoMCommissionRate, TIoMCommission, TIoMFlag1, TIoMFlag2, TIoMPremiumCost, TIoMQuantityStock, TIoMAVGWeighting, TIoMDiscountBill, TIoMDeposit, TIoMTARWCode, TIoMTRCACode, TIoMStockFlag, TIoMMinimumOrder, TIoMWelfareRate, TIoMControlQty, TIoMWelfareAmount, TIoMTPltCode, TIoMTotalCN, TIoMTotalCNArr, TIoMQuantityPallet, TIoMPOSName2, TIoMQuantityBase, TIoMPickingNo, VS4TPackingListMB.TPKMTPKLNo, VS4TPackingListMB.TPKMLn, VS4TPackingListMB.TPKMTPOSCode, VS4TPackingListMB.TPKMPOSName, VS4TPackingListMB.TPKMQuantity, VS4TPackingListMB.TPKMTUntCode, VS4TPackingListMB.TPKMKindOfPack, VS4TPackingListMB.TPKMPerQuantity, VS4TPackingListMB.TPKMPcsPerCarton, VS4TPackingListMB.TPKMTotalCarton, VS4TPackingListMB.TPKMCartonNo, VS4TPackingListMB.TPKMToCartonNo, VS4TPackingListMB.TPKMWidth, VS4TPackingListMB.TPKMLength, VS4TPackingListMB.TPKMHeight, VS4TPackingListMB.TPKMVolume, VS4TPackingListMB.TPKMNW, VS4TPackingListMB.TPKMGW, VS4TPackingListMB.TPKMVolumeM, VS4TPackingListMB.TPKMTotalNW, VS4TPackingListMB.TPKMTotalGW, VS4TPackingListMB.TPKMTotalVolumeM, VS4TPackingListMB.TPKMPrice, VS4TPackingListMB.TPKMAmount, VS4TPackingListMB.TPKMRealPrice, VS4TPackingListMB.TPKMRealAmount, VS4TPackingListMB.TPKMRealDate, VS4TPackingListMB.TPKMSourceNo, VS4TPackingListMB.TPKMSourceLn, VS4TPackingListMB.TPKMContainerNo, VS4TPackingListMB.TPKMContainerSize, VS4TPackingListMB.TPKMContainerLCL, VS4TShipInstruct.TSPINo, VS4TShipInstruct.TSPIDate, VS4TShipInstruct.TSPIDateTime, VS4TShipInstruct.TSPIETDDate, VS4TShipInstruct.TSPIETADate, VS4TPackingList.TPKLNo, VS4TPackingList.TPKLDate, VS4TPackingList.TPKLApproveStatus, VS4TPackingList.TPKLCancelStatus, VS4TShipInstruct.TSPIApproveStatus, VS4TShipInstruct.TSPICancelStatus FROM (VS4TShipInstruct RIGHT JOIN VS4TPackingList ON VS4TShipInstruct.TSPIRefNo2 = VS4TPackingList.TPKLNo) RIGHT JOIN (VS4TARInvoice LEFT JOIN (VS4TPackingListMB RIGHT JOIN VS4TARInvoiceMB ON (VS4TPackingListMB.TPKMSourceNo = VS4TARInvoiceMB.TIoMTIvoNo) AND (VS4TPackingListMB.TPKMSourceLn = VS4TARInvoiceMB.TIoMLn)) ON VS4TARInvoice.TIvoNo = VS4TARInvoiceMB.TIoMTIvoNo) ON VS4TPackingList.TPKLNo = VS4TPackingListMB.TPKMTPKLNo
GO

CREATE VIEW VS4VSO AS SELECT        VS4TSO.TSODNo, VS4TSO.TSODTSBkCode, VS4TSO.TSODTRCACode, VS4TSO.TSODMode, VS4TSO.TSODCode, VS4TSO.TSODType, VS4TSO.TSODDate, VS4TSO.TSODDueDate,                           VS4TSO.TSODRefNo, VS4TSO.TSODRefDate, VS4TSO.TSODRefNo2, VS4TSO.TSODTPrjCode, VS4TSO.TSODTBraCode, VS4TSO.TSODTEmpCode, VS4TSO.TSODSaleName,                           VS4TSO.TSODDeliveryDate, VS4TSO.TSODDeliveryTo, VS4TSO.TSODTARNCode, VS4TSO.TSODTARDCode, VS4TSO.TSODContactNote, VS4TSO.TSODContactName, VS4TSO.TSODCustomerName,                           VS4TSO.TSODCusAddress, VS4TSO.TSODConsignee, VS4TSO.TSODNotifyParty, VS4TSO.TSODCostTotal, VS4TSO.TSODPriceChannel, VS4TSO.TSODDiscountList, VS4TSO.TSODSubTotal,                           VS4TSO.TSODDiscountText, VS4TSO.TSODDiscountTotal, VS4TSO.TSODNetTotal, VS4TSO.TSODDepositText, VS4TSO.TSODDeposit, VS4TSO.TSODTotal, VS4TSO.TSODTotalFOB,                           VS4TSO.TSODTCurCode, VS4TSO.TSODExchangeRate, VS4TSO.TSODTotalInRate, VS4TSO.TSODVATType, VS4TSO.TSODVATRate, VS4TSO.TSODTaxBase, VS4TSO.TSODVATTotal,                           VS4TSO.TSODGrandTotal, VS4TSO.TSODNOTAXTotal, VS4TSO.TSODWTAXBase, VS4TSO.TSODWTaxRate, VS4TSO.TSODWTaxTotal, VS4TSO.TSODNetPayment, VS4TSO.TSODAdjustTotal,                           VS4TSO.TSODRewardTotal, VS4TSO.TSODPremiumTotal, VS4TSO.TSODCommissionBase, VS4TSO.TSODCommissionRate, VS4TSO.TSODCommission, VS4TSO.TSODBaseIncoType,                           VS4TSO.TSODIncoType, VS4TSO.TSODIncoterms, VS4TSO.TSODOtherFee, VS4TSO.TSODTransportFee, VS4TSO.TSODHandlingFee, VS4TSO.TSODFreightFee, VS4TSO.TSODInsurance,                           VS4TSO.TSODTransportDesc, VS4TSO.TSODDuty, VS4TSO.TSODShipBy, VS4TSO.TSODCountryOrigin, VS4TSO.TSODDestination, VS4TSO.TSODCondition, VS4TSO.TSODConditionDay,                           VS4TSO.TSODCondition1, VS4TSO.TSODConditionDay1, VS4TSO.TSODPaymentNote, VS4TSO.TSODStatementNote, VS4TSO.TSODDeliveryNote, VS4TSO.TSODPackingNote,                           VS4TSO.TSODDayAvailable, VS4TSO.TSODDescription, VS4TSO.TSODCustom1, VS4TSO.TSODCustom2, VS4TSO.TSODCustom3, VS4TSO.TSODCustom4, VS4TSO.TSODCustom5,                           VS4TSO.TSODInvoiceStatus, VS4TSO.TSODVerifyStatus, VS4TSO.TSODTSOTCode, VS4TSO.TSODDeliveryStatus, VS4TSO.TSODFinishDate, VS4TSO.TSODEditCode, VS4TSO.TSODEditBy,                           VS4TSO.TSODEditDate, VS4TSO.TSODConfirmStatus, VS4TSO.TSODApproveStatus, VS4TSO.TSODApproveBy, VS4TSO.TSODApproveDate, VS4TSO.TSODRevision, VS4TSO.TSODCancelStatus,                           VS4TSO.TSODCancelDate, VS4TSO.TSODFlag1, VS4TSO.TSODPMCostTotal, VS4TSO.TSODTOTNLn, VS4TSO.TSODStartDate, VS4TSO.TSODLoadingDate, VS4TSO.TSODStartAgingDate,                           VS4TSO.TSODArrears, VS4TSO.TSODNote, VS4TSO.TSODTAPNCode, VS4TSOMB.TSOBTSODNo, VS4TSOMB.TSOBLn, VS4TSOMB.TSOBType, VS4TSOMB.TSOBJobCode,                           VS4TSOMB.TSOBGroupName, VS4TSOMB.TSOBTOInCode, VS4TSOMB.TSOBTPOSCode, VS4TSOMB.TSOBCustom1, VS4TSOMB.TSOBCustom2, VS4TSOMB.TSOBCustom3,                           VS4TSOMB.TSOBCustom4, VS4TSOMB.TSOBCustom5, VS4TSOMB.TSOBShippingMark, VS4TSOMB.TSOBPOSCode, VS4TSOMB.TSOBFactoryCode, VS4TSOMB.TSOBPOSName,                           VS4TSOMB.TSOBOLDPOSName, VS4TSOMB.TSOBCost, VS4TSOMB.TSOBPrice, VS4TSOMB.TSOBPerQuantity, VS4TSOMB.TSOBUnitFactor, VS4TSOMB.TSOBQuantityCalc,                           VS4TSOMB.TSOBUnitCalc, VS4TSOMB.TSOBAcceptError, VS4TSOMB.TSOBQuantityText, VS4TSOMB.TSOBQuantity, VS4TSOMB.TSOBTUntCode, VS4TSOMB.TSOBQuantity2,                           VS4TSOMB.TSOBTUntCode2, VS4TSOMB.TSOBQuantity3, VS4TSOMB.TSOBTUntCode3, VS4TSOMB.TSOBCostAmount, VS4TSOMB.TSOBAmount, VS4TSOMB.TSOBDiscountText,                           VS4TSOMB.TSOBDiscountTotal, VS4TSOMB.TSOBNetAmount, VS4TSOMB.TSOBTaxType, VS4TSOMB.TSOBTaxBase, VS4TSOMB.TSOBWTAXBase, VS4TSOMB.TSOBAmountVAT,                           VS4TSOMB.TSOBAmountWTAX, VS4TSOMB.TSOBPromotionType, VS4TSOMB.TSOBFreeCode, VS4TSOMB.TSOBIsPremium, VS4TSOMB.TSOBDescription, VS4TSOMB.TSOBUseDate,                           VS4TSOMB.TSOBSourceNo, VS4TSOMB.TSOBSourceLn, VS4TSOMB.TSOBTIvoNo, VS4TSOMB.TSOBTotalDelivery, VS4TSOMB.TSOBTotalDelivery2, VS4TSOMB.TSOBTotalDelivery3,                           VS4TSOMB.TSOBTotalArrear, VS4TSOMB.TSOBTotalArrear2, VS4TSOMB.TSOBTotalArrear3, VS4TSOMB.TSOBTotalJob, VS4TSOMB.TSOBTotalJob2, VS4TSOMB.TSOBTotalJob3,                           VS4TSOMB.TSOBTotalJobArr, VS4TSOMB.TSOBTotalJobArr2, VS4TSOMB.TSOBTotalJobArr3, VS4TSOMB.TSOBDayProcess, VS4TSOMB.TSOBTLctCode, VS4TSOMB.TSOBFG,                           VS4TSOMB.TSOBJobRequest, VS4TSOMB.TSOBRequestDate, VS4TSOMB.TSOBReadyDate, VS4TSOMB.TSOBStatus, VS4TSOMB.TSOBManualClose, VS4TSOMB.TSOBPremiumCost,                           VS4TSOMB.TSOBTotalInv, VS4TSOMB.TSOBTotalInv2, VS4TSOMB.TSOBTotalInv3, VS4TAR.TARNName2, VS4TAR.TARNPhone, VS4TAR.TARNFax, VS4TARGroup.TARGName,                           VS4TAR.TARNName, VS4TAR.TARNTARGCode, VS4TAR.TARNTSAeCode, VS4TAR2.TAR2SaleCode, VS4TEmployee.TEmpFullName, VS4TBranch.TBraName, VS4TAR.TARNTBsTCode,                           VS4TAR2.TAR2TPrvCode, VS4TProvince.TPrvName, VS4TLocation.TLctTWahCode, VS4TAR.TARNFirstOrderDate, VS4TBranch.TBraAddressBill, VS4TAR.TARNAddressBill,                           VS4TAR.TARNAddressBill2, VS4TSOMB.TSOBTotalMDS, VS4TProject.TPrjName, VS4TSOMB.TSOBTARWCode, VS4TARWelfare.TARWName, VS4TSO.TSODTARWCode, VS4TSOMB.TSOBTRCACode,                           VS4TSOMB.TSOBFlag1, VS4TSOMB.TSOBStockFlag, VS4TSOMB.TSOBMinimumOrder, VS4TSOMB.TSOBTotalInvArr, VS4TSOMB.TSOBTotalInvArr2, VS4TSOMB.TSOBTotalInvArr3,                           VS4TSOMB.TSOBWelfareRate, VS4TSOMB.TSOBControlQty, VS4TSOMB.TSOBKindOfPack, VS4TSOMB.TSOBPcsPerCarton, VS4TSOMB.TSOBTotalCarton, VS4TSOMB.TSOBTLblCode,                           VS4TEmployee.TEmpFullName2, VS4TAR2.TAR2TShpCode, VS4TShipping.TSHPName, VS4TSO.TSODCreateBy, VS4TAR2.TAR2TRouCode, VS4TRoute.TRouName, VS4VProductBrief.TPdtDescription,                           VS4VProductBrief.TPdtTUntCode, VS4VProductBrief.TPdtTUntCode2, VS4VProductBrief.TPdtTUntCode3, VS4VProductBrief.TPdtTPTTCode, VS4VProductBrief.TPdtTPDLCode,                           VS4VProductBrief.TPdtTPSECode, VS4VProductBrief.TPdtTPS2Code, VS4VProductBrief.TPdtTPS3Code, VS4VProductBrief.TPdtTPS4Code, VS4VProductBrief.TPdtTPG1Code,                           VS4VProductBrief.TPdtTPG2Code, VS4VProductBrief.TPdLName, VS4VProductBrief.TPSEName, VS4VProductBrief.TPS2Name, VS4VProductBrief.TPdtTransferCode, VS4VProductBrief.TPdtTransferName,                           VS4VProductBrief.TPdtAverageCost, VS4VProductBrief.TPdtName, VS4VProductBrief.TPdtName2, VS4VProductBrief.TPdtCustom1, VS4VProductBrief.TPdtCustom2, VS4VProductBrief.TPdtCustom3,                           VS4VProductBrief.TPdtCustom4, VS4VProductBrief.TPdtCustom5, VS4VProductBrief.TPdtCustom6, VS4TSOMB.TSOBPRArrear, VS4TSO2.TSO2Acknowledge, VS4TSO2.TSO2AcknowDate,                           VS4TSO.TSODSubject, VS4TARBranch.TARDName, VS4TAR.TARNTaxNo, VS4TARContact.TARCEmail, VS4TSO2.TSO2Status, VS4TSO2.TSO2CompletedDate, VS4TSO2.TSO2HandOnDate,                           VS4TSO2.TSO2Insurance, VS4TSOMB.TSOBTotalMDS2, VS4TSOMB.TSOBTotalMDS3, VS4TAR.TARNTCouCode FROM            VS4TCountry INNER JOIN                          VS4TBusinessType RIGHT OUTER JOIN                          VS4TAR LEFT OUTER JOIN                          VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode LEFT OUTER JOIN                          VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode LEFT OUTER JOIN                          VS4TAR2 LEFT OUTER JOIN                          VS4TBusinessMajor ON VS4TAR2.TAR2TBSMCode = VS4TBusinessMajor.TBsMCode LEFT OUTER JOIN                          VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode LEFT OUTER JOIN                          VS4TShipping ON VS4TAR2.TAR2TShpCode = VS4TShipping.TSHPCode LEFT OUTER JOIN                          VS4TRoute ON VS4TAR2.TAR2TRouCode = VS4TRoute.TRouCode ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode INNER JOIN                          VS4TSO LEFT OUTER JOIN                          VS4TProject ON VS4TSO.TSODTPrjCode = VS4TProject.TPrjCode LEFT OUTER JOIN                          VS4TBranch ON VS4TSO.TSODTBraCode = VS4TBranch.TBraCode LEFT OUTER JOIN                          VS4VSaleAROnHand ON VS4TSO.TSODTEmpCode = VS4VSaleAROnHand.VARHSaleCode LEFT OUTER JOIN                          VS4TEmployee ON VS4TSO.TSODTEmpCode = VS4TEmployee.TEmpCode LEFT OUTER JOIN                          VS4TARBranch ON VS4TSO.TSODTARNCode = VS4TARBranch.TARDTARNCode AND VS4TSO.TSODTARDCode = VS4TARBranch.TARDCode LEFT OUTER JOIN                          VS4TARContact ON VS4TSO.TSODTARNCode = VS4TARContact.TARCTARNCode AND VS4TSO.TSODContactName = VS4TARContact.TARCFirstName ON                           VS4TAR.TARNCode = VS4TSO.TSODTARNCode ON VS4TBusinessType.TBsTCode = VS4TAR.TARNTBsTCode ON VS4TCountry.TCouCode = VS4TAR.TARNTCouCode LEFT OUTER JOIN                          VS4TSO2 ON VS4TSO.TSODNo = VS4TSO2.TSO2TSODNo INNER JOIN                          VS4TSOMB LEFT OUTER JOIN                          VS4TLocation ON VS4TSOMB.TSOBTLctCode = VS4TLocation.TLctCode LEFT OUTER JOIN                          VS4TARWelfare ON VS4TSOMB.TSOBTARWCode = VS4TARWelfare.TARWCode LEFT OUTER JOIN                          VS4VProductBrief ON VS4TSOMB.TSOBTPOSCode = VS4VProductBrief.TPdtCode LEFT OUTER JOIN                          VS4TProductBook ON VS4VProductBrief.TPdtCode = VS4TProductBook.TPBGTPdtCode ON VS4TSO.TSODNo = VS4TSOMB.TSOBTSODNo WHERE        (VS4TSO.TSODType = 0)
GO

CREATE VIEW VS4VSO2Invoice AS  SELECT VS4TSO.TSODNo, VS4TSO.TSODTSBkCode, VS4TSO.TSODTRCACode, VS4TSO.TSODMode, VS4TSO.TSODCode, VS4TSO.TSODType, VS4TSO.TSODDate, VS4TSO.TSODDueDate, VS4TSO.TSODRefNo, VS4TSO.TSODRefDate, VS4TSO.TSODTPrjCode, VS4TSO.TSODTBraCode, VS4TSO.TSODTEmpCode, VS4TSO.TSODSaleName, VS4TSO.TSODGuideText, VS4TSO.TSODEmpText, VS4TSO.TSODDeliveryDate, VS4TSO.TSODDeliveryTo, VS4TSO.TSODTARNCode, VS4TSO.TSODTARDCode, VS4TSO.TSODContactNote, VS4TSO.TSODContactName, VS4TSO.TSODCustomerName, VS4TSO.TSODCusAddress, VS4TSO.TSODConsignee, VS4TSO.TSODNotifyParty, VS4TSO.TSODCostTotal, VS4TSO.TSODPriceChannel, VS4TSO.TSODDiscountList, VS4TSO.TSODSubTotal, VS4TSO.TSODDiscountText, VS4TSO.TSODDiscountTotal, VS4TSO.TSODNetTotal, VS4TSO.TSODDepositText, VS4TSO.TSODDeposit, VS4TSO.TSODTotal, VS4TSO.TSODTotalFOB, VS4TSO.TSODTCurCode, VS4TSO.TSODExchangeRate, VS4TSO.TSODTotalInRate, VS4TSO.TSODVATType, VS4TSO.TSODVATRate, VS4TSO.TSODTaxBase, VS4TSO.TSODVATTotal, VS4TSO.TSODGrandTotal, VS4TSO.TSODNOTAXTotal, VS4TSO.TSODWTAXBase, VS4TSO.TSODWTaxRate, VS4TSO.TSODWTaxTotal, VS4TSO.TSODNetPayment, VS4TSO.TSODAdjustTotal, VS4TSO.TSODRewardTotal, VS4TSO.TSODPremiumTotal, VS4TSO.TSODCommissionBase, VS4TSO.TSODCommissionRate, VS4TSO.TSODCommission, VS4TSO.TSODBaseIncoType, VS4TSO.TSODIncoType, VS4TSO.TSODIncoterms, VS4TSO.TSODOtherFee, VS4TSO.TSODTransportFee, VS4TSO.TSODHandlingFee, VS4TSO.TSODFreightFee, VS4TSO.TSODInsurance, VS4TSO.TSODTransportDesc, VS4TSO.TSODDuty, VS4TSO.TSODShipBy, VS4TSO.TSODCountryOrigin, VS4TSO.TSODDestination, VS4TSO.TSODCondition, VS4TSO.TSODConditionDay, VS4TSO.TSODCondition1, VS4TSO.TSODConditionDay1, VS4TSO.TSODPaymentNote, VS4TSO.TSODStatementNote, VS4TSO.TSODDeliveryNote, VS4TSO.TSODPackingNote, VS4TSO.TSODDayAvailable, VS4TSO.TSODDescription, VS4TSO.TSODCustom1, VS4TSO.TSODCustom2, VS4TSO.TSODCustom3, VS4TSO.TSODCustom4, VS4TSO.TSODCustom5, VS4TSO.TSODInvoiceStatus, VS4TSO.TSODVerifyStatus, VS4TSO.TSODTSOTCode, VS4TSO.TSODDeliveryStatus, VS4TSO.TSODFinishDate, VS4TSO.TSODCreateBy, VS4TSO.TSODCreateDate, VS4TSO.TSODEditCode, VS4TSO.TSODEditBy, VS4TSO.TSODEditDate, VS4TSO.TSODConfirmStatus, VS4TSO.TSODConfirmBy, VS4TSO.TSODConfirmDate, VS4TSO.TSODApproveStatus, VS4TSO.TSODApproveBy, VS4TSO.TSODApproveDate, VS4TSO.TSODApproveNote, VS4TSO.TSODRevision, VS4TSO.TSODReviseBy, VS4TSO.TSODCancelStatus, VS4TSO.TSODCancelBy, VS4TSO.TSODCancelDate, VS4TSO.TSODCancelNote, VS4TSO.TSODFlag1, VS4TSO.TSODPMCostTotal, VS4TSO.TSODTOTNLn, VS4TSO.TSODTime, VS4TSO.TSODDeliveryTime, VS4TSO.TSODStartDate, VS4TSO.TSODLoadingDate, VS4TSO.TSODStartAgingDate, VS4TSO.TSODArrears, VS4TSO.TSODNote, VS4TSO.TSODTAPNCode, VS4TSO.TSODCheckPoint, VS4TSOMB.TSOBTSODNo, VS4TSOMB.TSOBLn, VS4TSOMB.TSOBType, VS4TSOMB.TSOBJobCode, VS4TSOMB.TSOBGroupName, VS4TSOMB.TSOBTOInCode, VS4TSOMB.TSOBTPOSCode, VS4TSOMB.TSOBCustom1, VS4TSOMB.TSOBCustom2, VS4TSOMB.TSOBCustom3, VS4TSOMB.TSOBCustom4, VS4TSOMB.TSOBCustom5, VS4TSOMB.TSOBShippingMark, VS4TSOMB.TSOBPOSCode, VS4TSOMB.TSOBFactoryCode, VS4TSOMB.TSOBPOSName, VS4TSOMB.TSOBOLDPOSName, VS4TSOMB.TSOBCost, VS4TSOMB.TSOBPrice, VS4TSOMB.TSOBPerQuantity, VS4TSOMB.TSOBUnitFactor, VS4TSOMB.TSOBQuantityCalc, VS4TSOMB.TSOBUnitCalc, VS4TSOMB.TSOBAcceptError, VS4TSOMB.TSOBQuantityText, VS4TSOMB.TSOBQuantity, VS4TSOMB.TSOBTUntCode, VS4TSOMB.TSOBQuantity2, VS4TSOMB.TSOBTUntCode2, VS4TSOMB.TSOBQuantity3, VS4TSOMB.TSOBTUntCode3, VS4TSOMB.TSOBCostAmount, VS4TSOMB.TSOBAmount, VS4TSOMB.TSOBDiscountText, VS4TSOMB.TSOBDiscountTotal, VS4TSOMB.TSOBNetAmount, VS4TSOMB.TSOBTaxType, VS4TSOMB.TSOBTaxBase, VS4TSOMB.TSOBWTAXBase, VS4TSOMB.TSOBAmountVAT, VS4TSOMB.TSOBAmountWTAX, VS4TSOMB.TSOBPromotionType, VS4TSOMB.TSOBFreeCode, VS4TSOMB.TSOBIsPremium, VS4TSOMB.TSOBDescription, VS4TSOMB.TSOBUseDate, VS4TSOMB.TSOBSourceNo, VS4TSOMB.TSOBSourceLn, VS4TSOMB.TSOBTIvoNo, VS4TSOMB.TSOBTotalDelivery, VS4TSOMB.TSOBTotalDelivery2, VS4TSOMB.TSOBTotalDelivery3, VS4TSOMB.TSOBTotalArrear, VS4TSOMB.TSOBTotalArrear2, VS4TSOMB.TSOBTotalArrear3, VS4TSOMB.TSOBTotalJob, VS4TSOMB.TSOBTotalJob2, VS4TSOMB.TSOBTotalJob3, VS4TSOMB.TSOBTotalJobArr, VS4TSOMB.TSOBTotalJobArr2, VS4TSOMB.TSOBTotalJobArr3, VS4TSOMB.TSOBDayProcess, VS4TSOMB.TSOBTLctCode, VS4TSOMB.TSOBFG, VS4TSOMB.TSOBJobRequest, VS4TSOMB.TSOBRequestDate, VS4TSOMB.TSOBReadyDate, VS4TSOMB.TSOBStatus, VS4TSOMB.TSOBManualClose, VS4TSOMB.TSOBPremiumCost, VS4TSOMB.TSOBTotalInv, VS4TSOMB.TSOBTotalInv2, VS4TSOMB.TSOBTotalInv3, VS4TSODelivery.TMDSTSOBTSODNo, VS4TSODelivery.TMDSTSOBLn, VS4TSODelivery.TMDSLn, VS4TSODelivery.TMDSProductCode, VS4TSODelivery.TMDSProductName, VS4TSODelivery.TMDSDate, VS4TSODelivery.TMDSDateTime, VS4TSODelivery.TMDSQuantity, VS4TSODelivery.TMDSQuantity2, VS4TSODelivery.TMDSQuantity3, VS4TSODelivery.TMDSUnitCode, VS4TSODelivery.TMDSUnitCode2, VS4TSODelivery.TMDSUnitCode3, VS4TSODelivery.TMDSTotalDelivery, VS4TSODelivery.TMDSTotalDelivery2, VS4TSODelivery.TMDSTotalDelivery3, VS4TSODelivery.TMDSTotalArrear, VS4TSODelivery.TMDSTotalArrear2, VS4TSODelivery.TMDSTotalArrear3, VS4TSODelivery.TMDSUnitCalc, VS4TSODelivery.TMDSMapTPdtCode, VS4TSODelivery.TMDSMapTUntCode, VS4TSODelivery.TMDSMapUnitRatio, VS4TSODelivery.TMDSQuantityBase, VS4TSODelivery.TMDSDeliveryBase, VS4TSODelivery.TMDSArrearBase, VS4TSODelivery.TMDSTLctCode, VS4TProject.TPrjName, 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, VS4TPOS.TPOSTPSGCode, VS4TEmployee_1.TEmpNickName, VS4TProduct.TPdtTPTTCode, VS4TARInvoice.TIvoArrears, VS4TProduct.TPdtStartDate, VS4TProduct.TPdtEndDate, VS4TProduct.TPdtTPDLCode, VS4TProductLine.TPdLName, VS4TAR3.TAR3SourceType 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) LEFT JOIN VS4TAR3 ON VS4TAR.TARNCode = VS4TAR3.TAR3TARNCode) INNER JOIN (((VS4TSO LEFT JOIN VS4TProject ON VS4TSO.TSODTPrjCode = VS4TProject.TPrjCode) LEFT JOIN VS4TBranch ON VS4TSO.TSODTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4TEmployee AS VS4TEmployee_1 ON VS4TSO.TSODTEmpCode = VS4TEmployee_1.TEmpCode) ON VS4TAR.TARNCode = VS4TSO.TSODTARNCode) INNER JOIN (VS4TProductLine RIGHT 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) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode) LEFT JOIN VS4TProductBook ON VS4TProduct.TPdtCode = VS4TProductBook.TPBGTPdtCode) ON VS4TARInvoice.TIvoNo = VS4TARInvoiceMB.TIoMTIvoNo) LEFT JOIN VS4TJobMB ON VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo) ON VS4TProductLine.TPdLCode = VS4TProduct.TPdtTPDLCode) 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, TPRDNo, TPRDTPRBCode, TPRDMode, TPRDCode, TPRDType, TPRDDate, TPRDRefNo, TPRDRefDate, TPRDJobCode, TPRDTJobNo, TPRDTJbMLn, TPRDTJPMLn, TPRDTJPDNo, TPRDTPrjCode, TPRDTSecCode, TPRDTDepCode, TPRDTDivCode, TPRDTBraCode, TPRDTAPNCode, TPRDDescription, TPRDProcessStatus, TPRDDeliveryStatus, TPRDRequestCode, TPRDRequestBy, TPRDCreateBy, TPRDCreateDate, TPRDEditCode, TPRDEditBy, TPRDEditDate, TPRDConfirmStatus, TPRDConfirmBy, TPRDConfirmDate, TPRDApproveStatus, TPRDApproveBy, TPRDApproveDate, TPRDApproveNote, TPRDRevision, TPRDReviseStatus, TPRDCancelStatus, TPRDFlag1, TPRDMProcessStatus, TPRDTCurCode, TPRDExchangeRate, TPRDBaseIncoType, TPRDIncoType, TPRDIncoterms, TPRMTPRDNo, TPRMLn, TPRMType, TPRMTJobNo, TPRMJobCode, TPRMMaterialMode, TPRMGroupName, TPRMTPdtCode, TPRMProductCode, TPRMFactoryCode, TPRMProductName, TPRMCustom1, TPRMCustom2, TPRMCustom3, TPRMCustom4, TPRMCustom5, TPRMPrice, TPRMPerQuantity, TPRMDiscountText, TPRMDiscountTotal, TPRMTaxType, TPRMQuantityCalc, TPRMUnitFactor, TPRMUnitCalc, TPRMQuantity, TPRMAmount, TPRMNetAmount, TPRMRefill, TPRMMarkTotal, TPRMStockOnHand, TPRMMinStock, TPRMPOArrearCalc, TPRMSuggest, TPRMPOArrear, TPRMTotalDelivery, TPRMTotalArrear, TPRMTUntCode, TPRMQuantity2, TPRMStockOnHand2, TPRMTotalDelivery2, TPRMTotalArrear2, TPRMTUntCode2, TPRMQuantity3, TPRMStockOnHand3, TPRMTotalDelivery3, TPRMTotalArrear3, TPRMTUntCode3, TPRMUseType, TPRMUseDate, TPRMDescription, TPRMProcessStatus, TPRMStatus, TPRMFlag1, TPRMMapTPdtCode, TPRMMapTUntCode, TPRMMapRatioP, TPRMMaxStock, TPRMOrderPoint, TPRMOrderQuantity, TPRMSafetyStock, TPRMPRArrearCalc, TPRMSourceNo, TPRMSourceLn, TPRMTOExCode, VS4TPO.TPODNo, VS4TPO.TPODType, VS4TPO.TPODDate, VS4TPO.TPODDueDate, VS4TPO.TPODDeliveryDate, VS4TPO.TPODDeliveryTo, VS4TPO.TPODTAPNCode, VS4TPO.TPODSupplierName, VS4TPOMB.TPOBTPODNo, VS4TPOMB.TPOBLn, VS4TPOMB.TPOBType, VS4TPOMB.TPOBJobCode, VS4TPOMB.TPOBGroupName, VS4TPOMB.TPOBTOExCode, VS4TPOMB.TPOBTPdtCode, VS4TPOMB.TPOBCustom1, VS4TPOMB.TPOBCustom2, VS4TPOMB.TPOBCustom3, VS4TPOMB.TPOBCustom4, VS4TPOMB.TPOBCustom5, VS4TPOMB.TPOBShippingMark, VS4TPOMB.TPOBProductCode, VS4TPOMB.TPOBFactoryCode, VS4TPOMB.TPOBProductName, VS4TPOMB.TPOBUseBom, VS4TPOMB.TPOBDeliveryDate, VS4TPOMB.TPOBDeliveryTime, VS4TPOMB.TPOBMinimumOrder, VS4TPOMB.TPOBCost, VS4TPOMB.TPOBPrice, VS4TPOMB.TPOBPerQuantity, VS4TPOMB.TPOBUnitFactor, VS4TPOMB.TPOBAcceptError, VS4TPOMB.TPOBUnitCalc, VS4TPOMB.TPOBQuantityCalc, VS4TPOMB.TPOBQuantityText, VS4TPOMB.TPOBQuantity, VS4TPOMB.TPOBTUntCode, VS4TPOMB.TPOBQuantity2, VS4TPOMB.TPOBTUntCode2, VS4TPOMB.TPOBQuantity3, VS4TPOMB.TPOBTUntCode3, VS4TPOMB.TPOBDutyAmount, VS4TPOMB.TPOBDivideExpense, VS4TPOMB.TPOBCostAmount, VS4TPOMB.TPOBAmount, VS4TPOMB.TPOBDiscountText, VS4TPOMB.TPOBDiscountTotal, VS4TPOMB.TPOBNetAmount, VS4TPOMB.TPOBTaxType, VS4TPOMB.TPOBTaxBase, VS4TPOMB.TPOBWTAXBase, VS4TPOMB.TPOBAmountVAT, VS4TPOMB.TPOBAmountWTAX, VS4TPOMB.TPOBAutoSTD, VS4TPOMB.TPOBStandardCost, VS4TPOMB.TPOBMargin, VS4TPOMB.TPOBSaleMargin, VS4TPOMB.TPOBAutoPrice, VS4TPOMB.TPOBSalePrice, VS4TPOMB.TPOBGetNumber, VS4TPOMB.TPOBFreeCode, VS4TPOMB.TPOBIsPremium, VS4TPOMB.TPOBDescription, VS4TPOMB.TPOBSourceNo, VS4TPOMB.TPOBSourceLn, VS4TPOMB.TPOBStatus, VS4TPOMB.TPOBFlag1, VS4TPOMB.TPOBStockTotal, VS4TPOMB.TPOBPRArrear, VS4TPOMB.TPOBEOQ, VS4TPOMB.TPOBTotalDelivery, VS4TPOMB.TPOBTotalDelivery2, VS4TPOMB.TPOBTotalDelivery3, VS4TPOMB.TPOBTotalArrear, VS4TPOMB.TPOBTotalArrear2, VS4TPOMB.TPOBTotalArrear3, VS4TPOMB.TPOBMapTPdtCode, VS4TPOMB.TPOBMapTUntCode, VS4TPOMB.TPOBDayProcess, VS4TPOMB.TPOBTLctCode, VS4TPOMB.TPOBManualClose, VS4TPOMB.TPOBMapRatioP, VS4TPOMB.TPOBQuantityCost, VS4TPOMB.TPOBTotalInv2, VS4TPOMB.TPOBTotalInv3, VS4TPOMB.TPOBTotalInv, 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, VS4TPOMBAOL.TPOATBraCode, VS4TPOMBAOL.TPOATDivCode, VS4TPOMBAOL.TPOATDepCode, VS4TPOMBAOL.TPOATSecCode, VS4TPOMBAOL.TPOATEmpCode 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.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) LEFT JOIN VS4TPOMBAOL ON (VS4TPOMB.TPOBLn = VS4TPOMBAOL.TPOATPOBLn) AND (VS4TPOMB.TPOBTPODNo = VS4TPOMBAOL.TPOATPOBTPODNo)) 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, TSODDate-Day(TSODDate)+1 AS VSODPeriod FROM VS4TSO GROUP BY VS4TSO.TSODTARNCode, Month(TSODDate), Year(tsoddate), TSODDate-Day(TSODDate)+1
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.TSODNo, VS4TSO.TSODTSBkCode, VS4TSO.TSODTRCACode, VS4TSO.TSODMode, VS4TSO.TSODCode, VS4TSO.TSODType, VS4TSO.TSODDate, VS4TSO.TSODDueDate, VS4TSO.TSODRefNo, VS4TSO.TSODRefDate, VS4TSO.TSODTPrjCode, VS4TSO.TSODTBraCode, VS4TSO.TSODTEmpCode, VS4TSO.TSODSaleName, VS4TSO.TSODGuideText, VS4TSO.TSODEmpText, VS4TSO.TSODDeliveryDate, VS4TSO.TSODDeliveryTo, VS4TSO.TSODTARNCode, VS4TSO.TSODTARDCode, VS4TSO.TSODContactNote, VS4TSO.TSODContactName, VS4TSO.TSODCustomerName, VS4TSO.TSODCusAddress, VS4TSO.TSODConsignee, VS4TSO.TSODNotifyParty, VS4TSO.TSODCostTotal, VS4TSO.TSODPriceChannel, VS4TSO.TSODDiscountList, VS4TSO.TSODSubTotal, VS4TSO.TSODDiscountText, VS4TSO.TSODDiscountTotal, VS4TSO.TSODNetTotal, VS4TSO.TSODDepositText, VS4TSO.TSODDeposit, VS4TSO.TSODTotal, VS4TSO.TSODTotalFOB, VS4TSO.TSODTCurCode, VS4TSO.TSODExchangeRate, VS4TSO.TSODTotalInRate, VS4TSO.TSODVATType, VS4TSO.TSODVATRate, VS4TSO.TSODTaxBase, VS4TSO.TSODVATTotal, VS4TSO.TSODGrandTotal, VS4TSO.TSODNOTAXTotal, VS4TSO.TSODWTAXBase, VS4TSO.TSODWTaxRate, VS4TSO.TSODWTaxTotal, VS4TSO.TSODNetPayment, VS4TSO.TSODAdjustTotal, VS4TSO.TSODRewardTotal, VS4TSO.TSODPremiumTotal, VS4TSO.TSODCommissionBase, VS4TSO.TSODCommissionRate, VS4TSO.TSODCommission, VS4TSO.TSODBaseIncoType, VS4TSO.TSODIncoType, VS4TSO.TSODIncoterms, VS4TSO.TSODOtherFee, VS4TSO.TSODTransportFee, VS4TSO.TSODHandlingFee, VS4TSO.TSODFreightFee, VS4TSO.TSODInsurance, VS4TSO.TSODTransportDesc, VS4TSO.TSODDuty, VS4TSO.TSODShipBy, VS4TSO.TSODCountryOrigin, VS4TSO.TSODDestination, VS4TSO.TSODCondition, VS4TSO.TSODConditionDay, VS4TSO.TSODCondition1, VS4TSO.TSODConditionDay1, VS4TSO.TSODPaymentNote, VS4TSO.TSODStatementNote, VS4TSO.TSODDeliveryNote, VS4TSO.TSODPackingNote, VS4TSO.TSODDayAvailable, VS4TSO.TSODDescription, VS4TSO.TSODCustom1, VS4TSO.TSODCustom2, VS4TSO.TSODCustom3, VS4TSO.TSODCustom4, VS4TSO.TSODCustom5, VS4TSO.TSODInvoiceStatus, VS4TSO.TSODVerifyStatus, VS4TSO.TSODTSOTCode, VS4TSO.TSODDeliveryStatus, VS4TSO.TSODFinishDate, VS4TSO.TSODCreateBy, VS4TSO.TSODCreateDate, VS4TSO.TSODEditCode, VS4TSO.TSODEditBy, VS4TSO.TSODEditDate, VS4TSO.TSODConfirmStatus, VS4TSO.TSODConfirmBy, VS4TSO.TSODConfirmDate, VS4TSO.TSODApproveStatus, VS4TSO.TSODApproveBy, VS4TSO.TSODApproveDate, VS4TSO.TSODApproveNote, VS4TSO.TSODRevision, VS4TSO.TSODReviseBy, VS4TSO.TSODCancelStatus, VS4TSO.TSODCancelBy, VS4TSO.TSODCancelDate, VS4TSO.TSODFlag1, VS4TSO.TSODPMCostTotal, VS4TSO.TSODTOTNLn, VS4TSO.TSODTime, VS4TSO.TSODDeliveryTime, VS4TSO.TSODStartDate, VS4TSO.TSODLoadingDate, VS4TSO.TSODStartAgingDate, VS4TSO.TSODArrears, VS4TSO.TSODNote, VS4TSO.TSODTAPNCode, VS4TSO.TSODCheckPoint, VS4TSOMB.TSOBTSODNo, VS4TSOMB.TSOBLn, VS4TSOMB.TSOBType, VS4TSOMB.TSOBJobCode, VS4TSOMB.TSOBGroupName, VS4TSOMB.TSOBTOInCode, VS4TSOMB.TSOBTPOSCode, VS4TSOMB.TSOBCustom1, VS4TSOMB.TSOBCustom2, VS4TSOMB.TSOBCustom3, VS4TSOMB.TSOBCustom4, VS4TSOMB.TSOBCustom5, VS4TSOMB.TSOBShippingMark, VS4TSOMB.TSOBPOSCode, VS4TSOMB.TSOBFactoryCode, VS4TSOMB.TSOBPOSName, VS4TSOMB.TSOBOLDPOSName, VS4TSOMB.TSOBCost, VS4TSOMB.TSOBPrice, VS4TSOMB.TSOBPerQuantity, VS4TSOMB.TSOBUnitFactor, VS4TSOMB.TSOBQuantityCalc, VS4TSOMB.TSOBUnitCalc, VS4TSOMB.TSOBAcceptError, VS4TSOMB.TSOBQuantityText, VS4TSOMB.TSOBQuantity, VS4TSOMB.TSOBTUntCode, VS4TSOMB.TSOBQuantity2, VS4TSOMB.TSOBTUntCode2, VS4TSOMB.TSOBQuantity3, VS4TSOMB.TSOBTUntCode3, VS4TSOMB.TSOBCostAmount, VS4TSOMB.TSOBAmount, VS4TSOMB.TSOBDiscountText, VS4TSOMB.TSOBDiscountTotal, VS4TSOMB.TSOBNetAmount, VS4TSOMB.TSOBTaxType, VS4TSOMB.TSOBTaxBase, VS4TSOMB.TSOBWTAXBase, VS4TSOMB.TSOBAmountVAT, VS4TSOMB.TSOBAmountWTAX, VS4TSOMB.TSOBPromotionType, VS4TSOMB.TSOBFreeCode, VS4TSOMB.TSOBIsPremium, VS4TSOMB.TSOBDescription, VS4TSOMB.TSOBUseDate, VS4TSOMB.TSOBSourceNo, VS4TSOMB.TSOBSourceLn, VS4TSOMB.TSOBTIvoNo, VS4TSOMB.TSOBTotalDelivery, VS4TSOMB.TSOBTotalDelivery2, VS4TSOMB.TSOBTotalDelivery3, VS4TSOMB.TSOBTotalArrear, VS4TSOMB.TSOBTotalArrear2, VS4TSOMB.TSOBTotalArrear3, VS4TSOMB.TSOBTotalJob, VS4TSOMB.TSOBTotalJob2, VS4TSOMB.TSOBTotalJob3, VS4TSOMB.TSOBTotalJobArr, VS4TSOMB.TSOBTotalJobArr2, VS4TSOMB.TSOBTotalJobArr3, VS4TSOMB.TSOBDayProcess, VS4TSOMB.TSOBTLctCode, VS4TSOMB.TSOBFG, VS4TSOMB.TSOBJobRequest, VS4TSOMB.TSOBRequestDate, VS4TSOMB.TSOBReadyDate, VS4TSOMB.TSOBStatus, VS4TSOMB.TSOBManualClose, VS4TSOMB.TSOBPremiumCost, VS4TSOMB.TSOBTotalInv, VS4TSOMB.TSOBTotalInv2, VS4TSOMB.TSOBTotalInv3, VS4TProject.TPrjName, VS4TAR.TARNName2, VS4TCountry.TCouName, VS4TCountry.TCouName2, VS4TAR.TARNPhone, VS4TAR.TARNFax, 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.TPdtCustom5, 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 VS4VTRArrearSum AS  SELECT VS4TTRMB.TTRMTPdtCode, Sum(VS4TTRMB.TTRMQuantity) AS TTRMQuantity, Sum(VS4TTRMB.TTRMTotalArrear) AS TTRMTotalArrear FROM VS4TTR INNER JOIN VS4TTRMB ON VS4TTR.TTRDNo = VS4TTRMB.TTRMTTRDNo GROUP BY VS4TTRMB.TTRMTPdtCode, VS4TTR.TTRDCancelStatus, VS4TTR.TTRDApproveStatus HAVING (((VS4TTR.TTRDCancelStatus)=0) AND ((VS4TTR.TTRDApproveStatus)=1))
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, VS4TSO.TSODApproveDate, VS4TSO.TSODDate, VS4TSO.TSODCreateDate 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.TSODApproveDate, VS4TSO.TSODDate, VS4TSO.TSODCreateDate, 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 VS4VSOCustom AS  SELECT VS4TSO.TSODNo, VS4TSO.TSODTSBkCode, VS4TSO.TSODTRCACode, VS4TSO.TSODMode, VS4TSO.TSODCode, VS4TSO.TSODType, VS4TSO.TSODDate, VS4TSO.TSODDueDate, VS4TSO.TSODRefNo, VS4TSO.TSODRefDate, VS4TSO.TSODRefNo2, VS4TSO.TSODTPrjCode, VS4TSO.TSODTBraCode, VS4TSO.TSODTEmpCode, VS4TSO.TSODSaleName, VS4TSO.TSODDeliveryDate, VS4TSO.TSODDeliveryTo, VS4TSO.TSODTARNCode, VS4TSO.TSODTARDCode, VS4TSO.TSODContactNote, VS4TSO.TSODContactName, VS4TSO.TSODCustomerName, VS4TSO.TSODCusAddress, VS4TSO.TSODConsignee, VS4TSO.TSODNotifyParty, VS4TSO.TSODCostTotal, VS4TSO.TSODPriceChannel, VS4TSO.TSODDiscountList, VS4TSO.TSODSubTotal, VS4TSO.TSODDiscountText, VS4TSO.TSODDiscountTotal, VS4TSO.TSODNetTotal, VS4TSO.TSODDepositText, VS4TSO.TSODDeposit, VS4TSO.TSODTotal, VS4TSO.TSODTotalFOB, VS4TSO.TSODTCurCode, VS4TSO.TSODExchangeRate, VS4TSO.TSODTotalInRate, VS4TSO.TSODVATType, VS4TSO.TSODVATRate, VS4TSO.TSODTaxBase, VS4TSO.TSODVATTotal, VS4TSO.TSODGrandTotal, VS4TSO.TSODNOTAXTotal, VS4TSO.TSODWTAXBase, VS4TSO.TSODWTaxRate, VS4TSO.TSODWTaxTotal, VS4TSO.TSODNetPayment, VS4TSO.TSODAdjustTotal, VS4TSO.TSODRewardTotal, VS4TSO.TSODPremiumTotal, VS4TSO.TSODCommissionBase, VS4TSO.TSODCommissionRate, VS4TSO.TSODCommission, VS4TSO.TSODBaseIncoType, VS4TSO.TSODIncoType, VS4TSO.TSODIncoterms, VS4TSO.TSODOtherFee, VS4TSO.TSODTransportFee, VS4TSO.TSODHandlingFee, VS4TSO.TSODFreightFee, VS4TSO.TSODInsurance, VS4TSO.TSODTransportDesc, VS4TSO.TSODDuty, VS4TSO.TSODShipBy, VS4TSO.TSODCountryOrigin, VS4TSO.TSODDestination, VS4TSO.TSODCondition, VS4TSO.TSODConditionDay, VS4TSO.TSODCondition1, VS4TSO.TSODConditionDay1, VS4TSO.TSODPaymentNote, VS4TSO.TSODStatementNote, VS4TSO.TSODDeliveryNote, VS4TSO.TSODPackingNote, VS4TSO.TSODDayAvailable, VS4TSO.TSODDescription, VS4TSO.TSODCustom1, VS4TSO.TSODCustom2, VS4TSO.TSODCustom3, VS4TSO.TSODCustom4, VS4TSO.TSODCustom5, VS4TSO.TSODInvoiceStatus, VS4TSO.TSODVerifyStatus, VS4TSO.TSODTSOTCode, VS4TSO.TSODDeliveryStatus, VS4TSO.TSODFinishDate, VS4TSO.TSODEditBy, VS4TSO.TSODEditDate, VS4TSO.TSODConfirmBy, VS4TSO.TSODConfirmDate, VS4TSO.TSODApproveBy, VS4TSO.TSODApproveDate, VS4TSO.TSODRevision, VS4TSO.TSODReviseBy, VS4TSO.TSODCancelBy, VS4TSO.TSODCancelDate, VS4TSO.TSODPMCostTotal, VS4TSO.TSODTOTNLn, VS4TSO.TSODDeliveryTime, VS4TSO.TSODStartDate, VS4TSO.TSODLoadingDate, VS4TSO.TSODStartAgingDate, VS4TSO.TSODNote, VS4TSO.TSODTAPNCode, VS4TSOMB.TSOBTSODNo, VS4TSOMB.TSOBLn, VS4TSOMB.TSOBType, VS4TSOMB.TSOBJobCode, VS4TSOMB.TSOBGroupName, VS4TSOMB.TSOBTOInCode, VS4TSOMB.TSOBTPOSCode, VS4TSOMB.TSOBCustom1, VS4TSOMB.TSOBCustom2, VS4TSOMB.TSOBCustom3, VS4TSOMB.TSOBCustom4, VS4TSOMB.TSOBCustom5, VS4TSOMB.TSOBShippingMark, VS4TSOMB.TSOBPOSCode, VS4TSOMB.TSOBFactoryCode, VS4TSOMB.TSOBPOSName, VS4TSOMB.TSOBOLDPOSName, VS4TSOMB.TSOBCost, VS4TSOMB.TSOBPrice, VS4TSOMB.TSOBPerQuantity, VS4TSOMB.TSOBUnitFactor, VS4TSOMB.TSOBQuantityCalc, VS4TSOMB.TSOBUnitCalc, VS4TSOMB.TSOBAcceptError, VS4TSOMB.TSOBQuantityText, VS4TSOMB.TSOBQuantity, VS4TSOMB.TSOBTUntCode, VS4TSOMB.TSOBQuantity2, VS4TSOMB.TSOBTUntCode2, VS4TSOMB.TSOBQuantity3, VS4TSOMB.TSOBTUntCode3, VS4TSOMB.TSOBCostAmount, VS4TSOMB.TSOBAmount, VS4TSOMB.TSOBDiscountText, VS4TSOMB.TSOBDiscountTotal, VS4TSOMB.TSOBNetAmount, VS4TSOMB.TSOBTaxType, VS4TSOMB.TSOBTaxBase, VS4TSOMB.TSOBWTAXBase, VS4TSOMB.TSOBAmountVAT, VS4TSOMB.TSOBAmountWTAX, VS4TSOMB.TSOBPromotionType, VS4TSOMB.TSOBFreeCode, VS4TSOMB.TSOBIsPremium, VS4TSOMB.TSOBDescription, VS4TSOMB.TSOBUseDate, VS4TSOMB.TSOBSourceNo, VS4TSOMB.TSOBSourceLn, VS4TSOMB.TSOBTIvoNo, VS4TSOMB.TSOBDayProcess, VS4TSOMB.TSOBTLctCode, VS4TSOMB.TSOBFG, VS4TSOMB.TSOBJobRequest, VS4TSOMB.TSOBRequestDate, VS4TSOMB.TSOBReadyDate, VS4TSOMB.TSOBStatus, VS4TSOMB.TSOBFlag1, VS4TSOMB.TSOBManualClose, VS4TSOMB.TSOBPremiumCost, VS4TSOMB.TSOBTotalInv, VS4TSOMB.TSOBTotalInv2, VS4TSOMB.TSOBTotalInv3, VS4TAR.TARNName2, VS4TAR.TARNPhone, VS4TAR.TARNFax, 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.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TProduct.TPdtTPTTCode, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtTPSECode, 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.*, VS4TLocation.TLctTWahCode, VS4TProduct.TPdtCustom1, VS4TProduct.TPdtCustom2, VS4TProduct.TPdtCustom3, VS4TProduct.TPdtCustom4, VS4TProduct.TPdtCustom5, VS4TProduct.TPdtCustom6, VS4TAR.TARNFirstOrderDate, VS4TBranch.TBraAddressBill, VS4TAR.TARNAddressBill, VS4TAR.TARNAddressBill2, VS4TSOMB.TSOBTotalMDS, VS4TSOMB.TSOBTotalMDS2, VS4TSOMB.TSOBTotalMDS3, VS4TProject.TPrjName, VS4TProduct.TPdtCustom7, VS4TProduct.TPdtCustom8, VS4TProduct.TPdtCustom9, VS4TProduct.TPdtCustom10, VS4TProduct3.TPd3Custom11, VS4TProduct3.TPd3Custom12, VS4TProduct3.TPd3Custom13, VS4TProduct3.TPd3Custom14, VS4TProduct3.TPd3Custom15, VS4TProduct3.TPd3Custom16, VS4TProduct3.TPd3Custom17, VS4TProduct3.TPd3Custom18, VS4TProduct3.TPd3Custom19, VS4TProduct3.TPd3Custom20, VS4TProduct3.TPd3Custom21, VS4TProduct3.TPd3Custom22, VS4TProduct3.TPd3Custom23, VS4TProduct3.TPd3Custom24, VS4TProduct3.TPd3Custom25, VS4TProduct3.TPd3Custom26, VS4TProduct3.TPd3Custom27, VS4TProduct3.TPd3Custom28, VS4TProduct3.TPd3Custom29, VS4TProduct3.TPd3Custom30, VS4TSO.TSODApproveStatus, VS4TSO.TSODCancelStatus 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) LEFT JOIN VS4TProduct3 ON VS4TProduct.TPdtCode = VS4TProduct3.TPD3TPdtCode) ON VS4TProductLine.TPdLCode = VS4TProduct.TPdtTPDLCode) ON VS4TSO.TSODNo = VS4TSOMB.TSOBTSODNo
GO

CREATE VIEW VS4VSODelivery AS SELECT VS4TSO.TSODNo, VS4TSO.TSODTSBkCode, VS4TSO.TSODTRCACode, VS4TSO.TSODCode, VS4TSO.TSODType, VS4TSO.TSODDate, VS4TSO.TSODDueDate, VS4TSO.TSODRefNo,                    VS4TSO.TSODRefDate, VS4TSO.TSODTPrjCode, VS4TSO.TSODTBraCode, VS4TSO.TSODTEmpCode, VS4TSO.TSODSaleName, VS4TSO.TSODDeliveryDate, VS4TSO.TSODDeliveryTo,                    VS4TSO.TSODTARNCode, VS4TSO.TSODTARDCode, VS4TSO.TSODContactNote, VS4TSO.TSODContactName, VS4TSO.TSODCustomerName, VS4TSO.TSODCusAddress, VS4TSO.TSODConsignee,                    VS4TSO.TSODNotifyParty, VS4TSO.TSODCostTotal, VS4TSO.TSODPriceChannel, VS4TSO.TSODDiscountList, VS4TSO.TSODSubTotal, VS4TSO.TSODDiscountText, VS4TSO.TSODDiscountTotal,                    VS4TSO.TSODNetTotal, VS4TSO.TSODDepositText, VS4TSO.TSODDeposit, VS4TSO.TSODTotal, VS4TSO.TSODTotalFOB, VS4TSO.TSODTCurCode, VS4TSO.TSODExchangeRate,                    VS4TSO.TSODTotalInRate, VS4TSO.TSODVATType, VS4TSO.TSODVATRate, VS4TSO.TSODTaxBase, VS4TSO.TSODVATTotal, VS4TSO.TSODGrandTotal, VS4TSO.TSODNOTAXTotal,                    VS4TSO.TSODWTAXBase, VS4TSO.TSODWTaxRate, VS4TSO.TSODWTaxTotal, VS4TSO.TSODNetPayment, VS4TSO.TSODAdjustTotal, VS4TSO.TSODRewardTotal, VS4TSO.TSODPremiumTotal,                    VS4TSO.TSODCommissionBase, VS4TSO.TSODCommissionRate, VS4TSO.TSODCommission, VS4TSO.TSODBaseIncoType, VS4TSO.TSODIncoType, VS4TSO.TSODIncoterms, VS4TSO.TSODOtherFee,                    VS4TSO.TSODTransportFee, VS4TSO.TSODHandlingFee, VS4TSO.TSODFreightFee, VS4TSO.TSODInsurance, VS4TSO.TSODTransportDesc, VS4TSO.TSODDuty, VS4TSO.TSODShipBy,                    VS4TSO.TSODCountryOrigin, VS4TSO.TSODDestination, VS4TSO.TSODCondition, VS4TSO.TSODConditionDay, VS4TSO.TSODCondition1, VS4TSO.TSODConditionDay1, VS4TSO.TSODPaymentNote,                    VS4TSO.TSODStatementNote, VS4TSO.TSODDeliveryNote, VS4TSO.TSODPackingNote, VS4TSO.TSODDayAvailable, VS4TSO.TSODDescription, VS4TSO.TSODCustom1, VS4TSO.TSODCustom2,                    VS4TSO.TSODCustom3, VS4TSO.TSODCustom4, VS4TSO.TSODCustom5, VS4TSO.TSODInvoiceStatus, VS4TSO.TSODVerifyStatus, VS4TSO.TSODTSOTCode, VS4TSO.TSODDeliveryStatus,                    VS4TSO.TSODFinishDate, VS4TSO.TSODEditCode, VS4TSO.TSODEditBy, VS4TSO.TSODEditDate, VS4TSO.TSODConfirmStatus, VS4TSO.TSODApproveStatus, VS4TSO.TSODApproveBy,                    VS4TSO.TSODApproveDate, VS4TSO.TSODApproveNote, VS4TSO.TSODRevision, VS4TSO.TSODReviseBy, VS4TSO.TSODCancelStatus, VS4TSO.TSODCancelDate, VS4TSO.TSODFlag1,                    VS4TSO.TSODPMCostTotal, VS4TSO.TSODTOTNLn, VS4TSO.TSODTime, VS4TSO.TSODDeliveryTime, VS4TSO.TSODStartDate, VS4TSO.TSODLoadingDate, VS4TSO.TSODStartAgingDate,                    VS4TSO.TSODArrears, VS4TSO.TSODNote, VS4TSO.TSODTAPNCode, VS4TSO.TSODCheckPoint, VS4TSOMB.TSOBTSODNo, VS4TSOMB.TSOBLn, VS4TSOMB.TSOBType, VS4TSOMB.TSOBJobCode,                    VS4TSOMB.TSOBGroupName, VS4TSOMB.TSOBTOInCode, VS4TSOMB.TSOBTPOSCode, VS4TSOMB.TSOBCustom1, VS4TSOMB.TSOBCustom2, VS4TSOMB.TSOBCustom3, VS4TSOMB.TSOBCustom4,                    VS4TSOMB.TSOBCustom5, VS4TSOMB.TSOBShippingMark, VS4TSOMB.TSOBPOSCode, VS4TSOMB.TSOBFactoryCode, VS4TSOMB.TSOBPOSName, VS4TSOMB.TSOBOLDPOSName, VS4TSOMB.TSOBCost,                    VS4TSOMB.TSOBPrice, VS4TSOMB.TSOBPerQuantity, VS4TSOMB.TSOBUnitFactor, VS4TSOMB.TSOBQuantityCalc, VS4TSOMB.TSOBUnitCalc, VS4TSOMB.TSOBAcceptError, VS4TSOMB.TSOBQuantityText,                    VS4TSOMB.TSOBQuantity, VS4TSOMB.TSOBTUntCode, VS4TSOMB.TSOBQuantity2, VS4TSOMB.TSOBTUntCode2, VS4TSOMB.TSOBQuantity3, VS4TSOMB.TSOBTUntCode3, VS4TSOMB.TSOBCostAmount,                    VS4TSOMB.TSOBAmount, VS4TSOMB.TSOBDiscountText, VS4TSOMB.TSOBDiscountTotal, VS4TSOMB.TSOBNetAmount, VS4TSOMB.TSOBTaxType, VS4TSOMB.TSOBTaxBase, VS4TSOMB.TSOBWTAXBase,                    VS4TSOMB.TSOBAmountVAT, VS4TSOMB.TSOBAmountWTAX, VS4TSOMB.TSOBPromotionType, VS4TSOMB.TSOBFreeCode, VS4TSOMB.TSOBIsPremium, VS4TSOMB.TSOBDescription,                    VS4TSOMB.TSOBUseDate, VS4TSOMB.TSOBSourceNo, VS4TSOMB.TSOBSourceLn, VS4TSOMB.TSOBTIvoNo, VS4TSOMB.TSOBTotalDelivery, VS4TSOMB.TSOBTotalDelivery2,                    VS4TSOMB.TSOBTotalDelivery3, VS4TSOMB.TSOBTotalArrear, VS4TSOMB.TSOBTotalArrear2, VS4TSOMB.TSOBTotalArrear3, VS4TSOMB.TSOBTotalJob, VS4TSOMB.TSOBTotalJob2,                    VS4TSOMB.TSOBTotalJob3, VS4TSOMB.TSOBTotalJobArr, VS4TSOMB.TSOBTotalJobArr2, VS4TSOMB.TSOBTotalJobArr3, VS4TSOMB.TSOBDayProcess, VS4TSOMB.TSOBTWahCode,                    VS4TSOMB.TSOBTLctCode, VS4TSOMB.TSOBFG, VS4TSOMB.TSOBJobRequest, VS4TSOMB.TSOBRequestDate, VS4TSOMB.TSOBReadyDate, VS4TSOMB.TSOBStatus, VS4TSOMB.TSOBFlag1,                    VS4TSOMB.TSOBManualClose, VS4TSOMB.TSOBPremiumCost, VS4TSOMB.TSOBTotalInv, VS4TSOMB.TSOBTotalInv2, VS4TSOMB.TSOBTotalInv3, VS4TAR.TARNName2, VS4TAR.TARNPhone,                    VS4TAR.TARNFax, 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, VS4TProduct.TPdtTPS2Code, VS4TProduct.TPdtTPS4Code, VS4TProduct.TPdtTPG1Code, VS4TProduct.TPdtTPG2Code, VS4TProduct.TPdtTPG3Code, VS4TProductLine.TPdLName,                    VS4TProductSection.TPSEName, VS4TProductSec2.TPS2Name, VS4TProductGroup1.TPG1Name, VS4TProductGroup2.TPG2Name, VS4TAR2.TAR2TPrvCode, VS4TProvince.TPrvName,                    VS4TProduct.TPdtAverageCost, VS4TLocation.TLctTWahCode, VS4TSODelivery.TMDSTotalArrear, VS4TSODelivery.TMDSTotalArrear2, VS4TSODelivery.TMDSTotalArrear3, VS4TSODelivery.TMDSMapTPdtCode,                    VS4TSODelivery.TMDSMapTUntCode, VS4TSODelivery.TMDSMapUnitRatio, VS4TSODelivery.TMDSQuantityBase, VS4TSODelivery.TMDSQuantity2, VS4TSODelivery.TMDSQuantity3,                    VS4TSODelivery.TMDSDateTime, VS4TSODelivery.TMDSUnitCalc, VS4TSODelivery.TMDSArrearBase, VS4TSODelivery.TMDSProductCode, VS4TSODelivery.TMDSLn, VS4TSODelivery.TMDSProductName,                    VS4TSODelivery.TMDSDate, VS4TSODelivery.TMDSQuantity, VS4TSODelivery.TMDSUnitCode, VS4TSODelivery.TMDSUnitCode2, VS4TSODelivery.TMDSUnitCode3, VS4TAR2.TAR2TShpCode,                    VS4TAR2.TAR2TRouCode, VS4TSOMB.TSOBTotalMDS, VS4TSOMB.TSOBTotalMDS2, VS4TSOMB.TSOBTotalMDS3, VS4TSOMB.TSOBStockFlag, VS4TSOMB.TSOBTotalInvArr, VS4TSOMB.TSOBTotalInvArr2,                    VS4TSOMB.TSOBTotalInvArr3, VS4TAR.TARNCreditAvaiBal, VS4TAR.TARNCreditBalance, VS4TAR.TARNCreditUse, VS4TAR.TARNCreditUseBal, VS4TAR.TARNCreditLimit, VS4TAR.TARNTCouCode,                    VS4TProduct2.TPd2Weight FROM     VS4TCountry INNER JOIN                   VS4TBusinessType RIGHT OUTER JOIN                   VS4TAR LEFT OUTER JOIN                   VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode LEFT OUTER JOIN                   VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode LEFT OUTER JOIN                   VS4TAR2 LEFT OUTER JOIN                   VS4TBusinessMajor ON VS4TAR2.TAR2TBSMCode = VS4TBusinessMajor.TBsMCode LEFT OUTER JOIN                   VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode INNER JOIN                   VS4TSO LEFT OUTER JOIN                   VS4TProject ON VS4TSO.TSODTPrjCode = VS4TProject.TPrjCode LEFT OUTER JOIN                   VS4TBranch ON VS4TSO.TSODTBraCode = VS4TBranch.TBraCode LEFT OUTER JOIN                   VS4VSaleAROnHand ON VS4TSO.TSODTEmpCode = VS4VSaleAROnHand.VARHSaleCode LEFT OUTER JOIN                   VS4TEmployee ON VS4TSO.TSODTEmpCode = VS4TEmployee.TEmpCode LEFT OUTER 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 INNER JOIN                   VS4TProductLine RIGHT OUTER JOIN                   VS4TSOMB LEFT OUTER JOIN                   VS4TPOS ON VS4TSOMB.TSOBTPOSCode = VS4TPOS.TPOSCode LEFT OUTER JOIN                   VS4TLocation ON VS4TSOMB.TSOBTLctCode = VS4TLocation.TLctCode LEFT OUTER JOIN                   VS4TProduct LEFT OUTER JOIN                   VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode LEFT OUTER JOIN                   VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code LEFT OUTER JOIN                   VS4TProductSec3 ON VS4TProduct.TPdtTPS3Code = VS4TProductSec3.TPS3Code LEFT OUTER JOIN                   VS4TProductSec4 ON VS4TProduct.TPdtTPS4Code = VS4TProductSec4.TPS4Code LEFT OUTER JOIN                   VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code LEFT OUTER JOIN                   VS4TProductGroup2 ON VS4TProduct.TPdtTPG2Code = VS4TProductGroup2.TPG2Code LEFT OUTER JOIN                   VS4TProductGroup3 ON VS4TProduct.TPdtTPG3Code = VS4TProductGroup3.TPG3Code LEFT OUTER JOIN                   VS4TProductGroup4 ON VS4TProduct.TPdtTPG4Code = VS4TProductGroup4.TPG4Code ON VS4TPOS.TPOSCode = VS4TProduct.TPdtCode LEFT OUTER JOIN                   VS4TProductBook ON VS4TProduct.TPdtCode = VS4TProductBook.TPBGTPdtCode LEFT OUTER JOIN                   VS4TSODelivery ON VS4TSOMB.TSOBTSODNo = VS4TSODelivery.TMDSTSOBTSODNo AND VS4TSOMB.TSOBLn = VS4TSODelivery.TMDSTSOBLn ON                    VS4TProductLine.TPdLCode = VS4TProduct.TPdtTPDLCode ON VS4TSO.TSODNo = VS4TSOMB.TSOBTSODNo LEFT OUTER JOIN                   VS4TProduct2 ON VS4TProduct.TPdtCode = VS4TProduct2.TPd2TPdtCode
GO

CREATE VIEW VS4VSODeliveryMail AS SELECT        VS4TSO.TSODNo, VS4TSO.TSODDate, VS4TSODelivery.TMDSDate, VS4TAR.TARNEmail, VS4TAR.TARNTCouCode, VS4TEmployee_1.TEmpEmail AS VSDESaleEmail, VS4TEmployee.TEmpEmail,                           VS4TSODelivery.TMDSTotalDelivery, VS4TSODelivery.TMDSTotalArrear, VS4TSO.TSODCustomerName FROM            VS4TSO INNER JOIN                          VS4TAR ON VS4TSO.TSODTARNCode = VS4TAR.TARNCode INNER JOIN                          VS4TSOMB ON VS4TSO.TSODNo = VS4TSOMB.TSOBTSODNo INNER JOIN                          VS4TSODelivery ON VS4TSOMB.TSOBTSODNo = VS4TSODelivery.TMDSTSOBTSODNo AND VS4TSOMB.TSOBLn = VS4TSODelivery.TMDSTSOBLn LEFT OUTER JOIN                          VS4TEmployee ON VS4TSO.TSODEditCode = VS4TEmployee.TEmpCode LEFT OUTER JOIN                          VS4TEmployee AS VS4TEmployee_1 ON VS4TSO.TSODTEmpCode = VS4TEmployee_1.TEmpCode WHERE        (VS4TSO.TSODApproveStatus = 1) AND (VS4TSO.TSODCancelStatus = 0)
GO

CREATE VIEW VS4VProductSafeS AS  SELECT VS4TProductSafeS.TPSSTPdtCode, VS4TProductSafeS.TPSSTBraCode, VS4TProductSafeS.TPSSLeadDay, VS4TProductSafeS.TPSSRefill, VS4TProductSafeS.TPSSSafetyManual, VS4TProductSafeS.TPSSSafetyManualD, VS4TProductSafeS.TPSSSafeDayCalc, VS4TProductSafeS.TPSSBackDayCalc, VS4TProductSafeS.TPSSSafePerDay, VS4TProductSafeS.TPSSSaleArrear, VS4TProductSafeS.TPSSStock, VS4TProductSafeS.TPSSTRArrear, VS4TProductSafeS.TPSSSafeTotalDay, VS4TProductSafeS.TPSSStockMin, VS4TProductSafeS.TPSSStockMax, VS4TProductSafeS.TPSSSuggest, VS4TProductSafeS.TPSSPURTLctCode, VS4TProductSafeS.TPSSSaleTLctCode, VS4TProductSafeS.TPSSSaleTWahCode, VS4TProductSafeS.TPSSMainTLctCode, VS4TProductSafeS.TPSSRepTLctCode, VS4TProductSafeS.TPSSBrkTLctCode, VS4TProductSafeS.TPSSFlag1, VS4TProductSafeS.TPSSOrderPoint, VS4TProductSafeS.TPSSOrderQuantity, VS4VProductBrief.*, VS4TBranch.TBraTBrTAlias, VS4VStockBranch.TInMAmouQuantity, VS4VStockBranch.TInMAmouQuantity2, VS4VStockBranch.TInMAmouQuantity3, VS4VSOArrearSum.TSOBQuantity, VS4VSOArrearSum.TSOBTotalArrear, VS4VSOArrearSum.TSOBQuantityBase, VS4VSOArrearSum.TSOBTotalArrearBas, VS4VPRArrearSum.TPRMQuantity, VS4VPRArrearSum.TPRMTotalArrear, VS4VPRArrearSum.TPRMPOArrear, VS4VPRArrearSum.TPRMQuantityBase, VS4VPRArrearSum.TPRMTotalArrearBas, VS4VPRArrearSum.TPRMPOArrearBase, VS4VPOArrearSum.TPOBQuantity, VS4VPOArrearSum.TPOBTotalArrear, VS4VPOArrearSum.TPOBQuantityBase, VS4VPOArrearSum.TPOBTotalArrearBas, VS4VTRArrearSum.TTRMQuantity, VS4VTRArrearSum.TTRMTotalArrear FROM ((((((VS4TProductSafeS LEFT JOIN VS4VStockBranch ON (VS4TProductSafeS.TPSSTPdtCode = VS4VStockBranch.TPdtCode) AND (VS4TProductSafeS.TPSSTBraCode = VS4VStockBranch.TLctTBraCode)) LEFT JOIN VS4TBranch ON VS4TProductSafeS.TPSSTBraCode = VS4TBranch.TBraCode) LEFT JOIN VS4VProductBrief ON VS4TProductSafeS.TPSSTPdtCode = VS4VProductBrief.TPdtCode) LEFT JOIN VS4VPRArrearSum ON VS4TProductSafeS.TPSSTPdtCode = VS4VPRArrearSum.TPRMTPdtCode) LEFT JOIN VS4VPOArrearSum ON VS4TProductSafeS.TPSSTPdtCode = VS4VPOArrearSum.TPOBTPdtCode) LEFT JOIN VS4VSOArrearSum ON VS4TProductSafeS.TPSSTPdtCode = VS4VSOArrearSum.TSOBTPOSCode) LEFT JOIN VS4VTRArrearSum ON VS4TProductSafeS.TPSSTPdtCode = VS4VTRArrearSum.TTRMTPdtCode
GO

CREATE VIEW VS4VSOExpense AS  SELECT VS4TSO.*, VS4TSOExpense.*, VS4TOtherExpense.* FROM (VS4TSO INNER JOIN VS4TSOExpense ON VS4TSO.TSODNo = VS4TSOExpense.TSOETSODNo) INNER JOIN VS4TOtherExpense ON VS4TSOExpense.TSOETOExCode = VS4TOtherExpense.TOExCode
GO

CREATE VIEW VS4VSOH AS SELECT        VS4TSO.TSODNo, VS4TSO.TSODTSBkCode, VS4TSO.TSODTRCACode, VS4TSO.TSODMode, VS4TSO.TSODCode, VS4TSO.TSODType, VS4TSO.TSODDate, VS4TSO.TSODDueDate,                           VS4TSO.TSODRefNo, VS4TSO.TSODRefDate, VS4TSO.TSODBODeposit, VS4TSO.TSODTPrjCode, VS4TSO.TSODTBraCode, VS4TSO.TSODTEmpCode, VS4TSO.TSODSaleName,                           VS4TSO.TSODGuideText, VS4TSO.TSODEmpText, VS4TSO.TSODDeliveryDate, VS4TSO.TSODDeliveryTo, VS4TSO.TSODTARNCode, VS4TSO.TSODTARDCode, VS4TSO.TSODContactNote,                           VS4TSO.TSODContactName, VS4TSO.TSODCustomerName, VS4TSO.TSODCusAddress, VS4TSO.TSODConsignee, VS4TSO.TSODNotifyParty, VS4TSO.TSODCostTotal, VS4TSO.TSODPriceChannel,                           VS4TSO.TSODDiscountList, VS4TSO.TSODSubTotal, VS4TSO.TSODDiscountText, VS4TSO.TSODDiscountTotal, VS4TSO.TSODNetTotal, VS4TSO.TSODDepositText, VS4TSO.TSODDeposit,                           VS4TSO.TSODTotal, VS4TSO.TSODTotalFOB, VS4TSO.TSODTCurCode, VS4TSO.TSODExchangeRate, VS4TSO.TSODTotalInRate, VS4TSO.TSODVATType, VS4TSO.TSODVATRate,                           VS4TSO.TSODTaxBase, VS4TSO.TSODVATTotal, VS4TSO.TSODGrandTotal, VS4TSO.TSODNOTAXTotal, VS4TSO.TSODWTAXBase, VS4TSO.TSODWTaxRate, VS4TSO.TSODWTaxTotal,                           VS4TSO.TSODNetPayment, VS4TSO.TSODAdjustTotal, VS4TSO.TSODRewardTotal, VS4TSO.TSODPremiumTotal, VS4TSO.TSODCommissionBase, VS4TSO.TSODCommissionRate,                           VS4TSO.TSODCommission, VS4TSO.TSODBaseIncoType, VS4TSO.TSODIncoType, VS4TSO.TSODIncoterms, VS4TSO.TSODOtherFee, VS4TSO.TSODTransportFee, VS4TSO.TSODHandlingFee,                           VS4TSO.TSODFreightFee, VS4TSO.TSODInsurance, VS4TSO.TSODTransportDesc, VS4TSO.TSODDuty, VS4TSO.TSODShipBy, VS4TSO.TSODCountryOrigin, VS4TSO.TSODDestination,                           VS4TSO.TSODCondition, VS4TSO.TSODConditionDay, VS4TSO.TSODCondition1, VS4TSO.TSODConditionDay1, VS4TSO.TSODPaymentNote, VS4TSO.TSODStatementNote,                           VS4TSO.TSODDeliveryNote, VS4TSO.TSODPackingNote, VS4TSO.TSODDayAvailable, VS4TSO.TSODDescription, VS4TSO.TSODCustom1, VS4TSO.TSODCustom2, VS4TSO.TSODCustom3,                           VS4TSO.TSODCustom4, VS4TSO.TSODCustom5, VS4TSO.TSODInvoiceStatus, VS4TSO.TSODVerifyStatus, VS4TSO.TSODTSOTCode, VS4TSO.TSODDeliveryStatus, VS4TSO.TSODFinishDate,                           VS4TSO.TSODCreateCode, VS4TSO.TSODCreateBy, VS4TSO.TSODCreateDate, VS4TSO.TSODEditCode, VS4TSO.TSODEditBy, VS4TSO.TSODEditDate, VS4TSO.TSODConfirmStatus,                           VS4TSO.TSODConfirmBy, VS4TSO.TSODConfirmDate, VS4TSO.TSODApproveStatus, VS4TSO.TSODApproveBy, VS4TSO.TSODApproveDate, VS4TSO.TSODApproveNote, VS4TSO.TSODRevision,                           VS4TSO.TSODReviseBy, VS4TSO.TSODCancelStatus, VS4TSO.TSODCancelNo, VS4TSO.TSODCancelBy, VS4TSO.TSODCancelDate, VS4TSO.TSODCancelNote, VS4TSO.TSODFlag1,                           VS4TSO.TSODFlag2, VS4TSO.TSODFlag3, VS4TSO.TSODPMCostTotal, VS4TSO.TSODTOTNLn, VS4TSO.TSODTime, VS4TSO.TSODDeliveryTime, VS4TSO.TSODStartDate,                           VS4TSO.TSODLoadingDate, VS4TSO.TSODStartAgingDate, VS4TSO.TSODArrears, VS4TSO.TSODNote, VS4TSO.TSODTAPNCode, VS4TSO.TSODCheckPoint, VS4TSO.TSODCreditUseTotal,                           VS4TSO.TSODRefNo2, VS4TSO.TSODTARWCode, VS4TSO.TSODBalanceFlag, VS4TSO.TSODTPOSCode, VS4TSO.TSODCustomerStatus, VS4TSO.TSODTPiTNo, VS4TSO.TSODSubject,                           VS4TProject.TPrjName, VS4TAR.TARNName2, VS4TCountry.TCouName, VS4TCountry.TCouName2, VS4TAR.TARNPhone, VS4TAR.TARNFax, 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.VARHSaleCode, VS4VSaleAROnHand.VARHProspect, VS4VSaleAROnHand.VARHLoss, VS4VSaleAROnHand.VARHTotal, VS4TARBranch.TARDName, VS4TSO2.TSO2Acknowledge,                           VS4TSO2.TSO2AcknowDate, VS4TSO2.TSO2StatusNote, VS4TSO2.TSO2Status, VS4TSO2.TSO2IncomeTotal, VS4TSO2.TSO2CostTotal, VS4TSO2.TSO2Profit, VS4TSO2.TSO2BaseIncome,                           VS4TSO2.TSO2BaseCost, VS4TSO2.TSO2CompletedDate, VS4TJob.TJobInvoiceStatus, VS4TJob.TJobIVCloseBy, VS4TJob.TJobIVCloseDate, VS4TAR.TARNTARTCode, VS4TAR.TARNTRG2Code,                           VS4TSO2.TSO2HandOnDate, VS4TSO2.TSO2Insurance, VS4TAR.TARNTRG3Code, VS4TARGroup2.TRG2Name, VS4TARGroup3.TRG3Name FROM            VS4TCountry INNER JOIN                          VS4TBusinessType RIGHT OUTER JOIN                          VS4TAR LEFT OUTER JOIN                          VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode LEFT OUTER JOIN                          VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode LEFT OUTER JOIN                          VS4TAR2 LEFT OUTER JOIN                          VS4TEmployee ON VS4TAR2.TAR2SaleCode = VS4TEmployee.TEmpCode LEFT OUTER JOIN                          VS4TBusinessMajor ON VS4TAR2.TAR2TBSMCode = VS4TBusinessMajor.TBsMCode LEFT OUTER JOIN                          VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode INNER JOIN                          VS4TSO LEFT OUTER JOIN                          VS4TProject ON VS4TSO.TSODTPrjCode = VS4TProject.TPrjCode LEFT OUTER JOIN                          VS4TBranch ON VS4TSO.TSODTBraCode = VS4TBranch.TBraCode LEFT OUTER JOIN                          VS4VSaleAROnHand ON VS4TSO.TSODTEmpCode = VS4VSaleAROnHand.VARHSaleCode LEFT OUTER JOIN                          VS4TARBranch ON VS4TSO.TSODTARNCode = VS4TARBranch.TARDTARNCode AND VS4TSO.TSODTARDCode = VS4TARBranch.TARDCode LEFT OUTER JOIN                          VS4TJob ON VS4TSO.TSODNo = VS4TJob.TJobNo ON VS4TAR.TARNCode = VS4TSO.TSODTARNCode ON VS4TBusinessType.TBsTCode = VS4TAR.TARNTBsTCode ON                           VS4TCountry.TCouCode = VS4TAR.TARNTCouCode LEFT OUTER JOIN                          VS4TARGroup2 ON VS4TAR.TARNTRG2Code = VS4TARGroup2.TRG2Code LEFT OUTER JOIN                          VS4TARGroup3 ON VS4TAR.TARNTRG3Code = VS4TARGroup3.TRG3Code LEFT OUTER JOIN                          VS4TSO2 ON VS4TSO.TSODNo = VS4TSO2.TSO2TSODNo WHERE        (VS4TSO.TSODType = 0)
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.*, TAR3TARNCode, TAR3Ln, TAR3Gender, TAR3TitleName, TAR3FirstName, TAR3MiddleName, TAR3LastName, TAR3AliasName, TAR3NickName, TAR3TitleName2, TAR3FirstName2, TAR3MiddleName2, TAR3Lastname2, TAR3PostAddess, TAR3CitizenNo, TAR3CitizenFrom, TAR3CitizenTo, TAR3CitizenAddress, TAR3Race, TAR3CitizenShip, TAR3Religion, TAR3Language, TAR3BornZone, TAR3SocialSecurity, TAR3BirthDay, TAR3Blood, TAR3Height, TAR3Weight, TAR3StatusPer, TAR3PassportNo, TAR3CardAlien, TAR3AllowAlien, TAR3PassportFrom, TAR3PassportTo, TAR3WorkPermitFrom, TAR3WorkPermitTo, TAR3Company, TAR3Company2, TAR3CmpAddress, TAR3CmpAddress2, TAR3TSpvCode, TAR3TPrvCode, TAR3PostalCode, TAR3TStaCode, TAR3TCouCode, TAR3Website, TAR3Email, TAR3Phone, TAR3Fax, TAR3Image1, TAR3Salary, TAR3OtherIncome, TAR3FirstTalkType, TAR3ProspectStatus, TAR3OrderStatus, TAR3FormerTName, TAR3FormerFName, TAR3FormerMName, TAR3FormerLName, TAR3StartWorkDate, TAR3PassportType, TAR3PassportNote, TAR3PassportAuthor, TAR3Ocupation, TAR3OtherCitizen, TAR3LiveWith, TAR3FormerNational, TAR3EndWorkDate, TAR3EmployType, TAR3EmployNote, TAR3TotalSave, TAR3TakeCareOther, TAR3MonthlyExpense, TAR3TotalChild, TAR3TotalChildLive, TAR3PassportFirst, TAR3AutoMatch, TAR3Auto2TARNCode, TAR3PassportIssue, TAR3FormerPosition, TAR3Position, TAR3BirthDayValid, TAR3SourceType, TAR3ReceiveInfo, TAR3Hobby, TAR3Acceptance, TAR3SalaryTo, TAR3CompleteMember, TAR3MemberMedia, TAR3OcupationInfo, VS4TProductBook.TPBGTPdtCode, VS4TProductBook.TPBGLn, VS4TProductBook.TPBGPaxMin, VS4TProductBook.TPBGPaxMax, VS4TProductBook.TPBGSeat, VS4TProductBook.TPBGBook, VS4TProductBook.TPBGRemain, VS4TProductBook.TPBGPaxCost, VS4TProductBook.TPBGFlag1, VS4TProductBook.TPBGConfirmBook, 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.TPBGToTCouCode2, VS4TProductBook.TPBGToPort2, VS4TProductBook.TPBGArrDate2, VS4TProductBook.TPBGArrTime2, VS4TProductBook.TPBGPrice, VS4TProductBook.TPBGIssTicketDate, VS4TProductBook.TPBGFor, VS4TProductBook.TPBGDepositStatus, VS4TProductBook.TPBGCheckDate, VS4TProductBook.TPBGDepositRate, VS4TProductBook.TPBGDepositAmount, VS4TProductBook.TPBGSplitRT, VS4TProductBook.TPBGNote, VS4TProductBook.TPBGGuide, VS4TProductBook.TPBGTL, VS4TProductBook.TPBGShareCostA, VS4TProductBook.TPBGShareCostB, VS4TProductBook.TPBGDepositSeat, VS4TProductBook.TPBGShareTPdtCode, VS4TProductBook.TPBGShare, VS4TProductBook.TPBGJoin, VS4TProductBook.TPBGDepositDate, VS4TProductBook.TPBGVisaDate, VS4TProductBook.TPBGLastBookDate, VS4TProductBook.TPBGPriority, VS4TProductBook.TPBGPortFromToAll, VS4TProductBook.TPBGFlightAll, VS4TProductBook.TPBGStatus, VS4TProductBook.TPBGMaxPaxUsePoint, VS4TProductBook.TPBGMaxPaxRecPoint, VS4TProductBook.TPBGMaxUsePoint 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)) LEFT JOIN VS4TProductBook ON VS4TSOImigration.TIMGTPdtCode = VS4TProductBook.TPBGTPdtCode) INNER JOIN VS4TAR3 ON VS4TAR.TARNCode = VS4TAR3.TAR3TARNCode
GO

CREATE VIEW VS4VSOInquiry AS  SELECT VS4TSOInquiry.*, VS4TSOInquiryBook.*, VS4TSOInquiryMB.*, VS4TInquiryChoice.*, VS4TInquiry.*, VS4TInquiryGroup.*, VS4TEmployee.TEmpFullName, VS4TEmployee_1.TEmpFullName AS VSOQFullName2, VS4TEmployee_2.TEmpFullName AS VSOQFullName3 FROM ((((VS4TSOInquiryBook INNER JOIN VS4TSOInquiry ON VS4TSOInquiryBook.TSQBCode = VS4TSOInquiry.TSOQTSQBCode) INNER JOIN ((VS4TInquiryGroup INNER JOIN VS4TInquiry ON VS4TInquiryGroup.TIQGCode = VS4TInquiry.TIQRTIQGCode) INNER JOIN (VS4TInquiryChoice INNER JOIN VS4TSOInquiryMB ON (VS4TInquiryChoice.TIQCLn = VS4TSOInquiryMB.TSQCLn) AND (VS4TInquiryChoice.TIQCTIQRCode = VS4TSOInquiryMB.TSQCTSODNo)) ON VS4TInquiry.TIQRCode = VS4TInquiryChoice.TIQCTIQRCode) ON VS4TSOInquiry.TSOQNo = VS4TSOInquiryMB.TSQCTSODNo) LEFT JOIN VS4TEmployee ON VS4TSOInquiry.TSOQS1TEmpCode = VS4TEmployee.TEmpCode) LEFT JOIN VS4TEmployee AS VS4TEmployee_1 ON VS4TSOInquiry.TSOQ2TEmpCode = VS4TEmployee_1.TEmpCode) LEFT JOIN VS4TEmployee AS VS4TEmployee_2 ON VS4TSOInquiry.TSOQS3TEmpCode = VS4TEmployee_2.TEmpCode
GO

CREATE VIEW VS4VSOMbPRMbPOMb AS SELECT        VS4TSOMB.TSOBTSODNo, VS4TSOMB.TSOBLn, VS4TPO.TPODNo, VS4TPO.TPODDate, VS4TPO.TPODInvoiceStatus, VS4TPO.TPODDeliveryStatus, VS4TPOMB.TPOBLn,                           VS4TPOMB.TPOBQuantity, VS4TPOMB.TPOBTUntCode, VS4TPOMB.TPOBTPdtCode, VS4TPOMB.TPOBProductName, VS4TPOMB.TPOBDeliveryDate FROM            VS4TPO RIGHT OUTER JOIN                          VS4TSOMB LEFT OUTER JOIN                          VS4TPOMB RIGHT OUTER JOIN                          VS4TPRMB ON VS4TPOMB.TPOBSourceNo = VS4TPRMB.TPRMTPRDNo AND VS4TPOMB.TPOBSourceLn = VS4TPRMB.TPRMLn ON VS4TSOMB.TSOBTSODNo = VS4TPRMB.TPRMSourceNo AND                           VS4TSOMB.TSOBLn = VS4TPRMB.TPRMSourceLn LEFT OUTER JOIN                          VS4TPR ON VS4TPRMB.TPRMTPRDNo = VS4TPR.TPRDNo ON VS4TPO.TPODNo = VS4TPOMB.TPOBTPODNo WHERE        (VS4TPO.TPODApproveStatus = 1) AND (VS4TPR.TPRDApproveStatus = 1) AND (VS4TPR.TPRDCancelStatus = 0) AND (VS4TPO.TPODCancelStatus = 0)
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, VS4TAR3_1.TAR3BirthDayValid AS VVSPBirthDayValid, VS4TPlace.TPlaPhone, VS4TPlace.TPlaFax, VS4TPlace.TPlaEmail, VS4TAR.TARNMobile, Right(10000+(Month(VS4TAR3.tar3birthday)*100)+Day(VS4TAR3.tar3birthday),4) AS VVSPBirthDayMonth, VS4TAR.TARNAddress2, VS4TVisa.TVSANo, VS4TAR.TARNAddressBill, VS4TAR.TARNAddressBill2, VS4TAR.TARNAddress, VS4TAR.TARNSubProvince, VS4TAR.TARNCity, VS4TAR.TARNPostalCode, VS4TAR.TARNStaCode, VS4TAR.TARNTCouCode, VS4TAR.TARNPhone, VS4TAR.TARNEmail, VS4TSO.TSODTBraCode, VS4TSO.TSODCancelStatus, VS4TSO.TSODApproveStatus, VS4TPOS.TPOSPrice 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 (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) LEFT JOIN VS4TVisa ON (VS4TSOImigration.TIMGTARNCode = VS4TVisa.TVSATARNCode) AND (VS4TSOImigration.TIMGTPdtCode = VS4TVisa.TVSATPdtCode)) LEFT JOIN VS4TAR ON VS4TSOPassenger.TVSPTARNCode = VS4TAR.TARNCode) LEFT JOIN VS4TPOS ON VS4TProduct.TPdtCode = VS4TPOS.TPOSCode 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 VS4VSOR AS SELECT        VS4TSO.TSODNo, VS4TSO.TSODTSBkCode, VS4TSO.TSODTRCACode, VS4TSO.TSODMode, VS4TSO.TSODCode, VS4TSO.TSODType, VS4TSO.TSODDate, VS4TSO.TSODRefNo,                           VS4TSO.TSODRefDate, VS4TSO.TSODRefNo2, VS4TSO.TSODTPrjCode, VS4TSO.TSODTBraCode, VS4TSO.TSODTEmpCode, VS4TSO.TSODSaleName, VS4TSO.TSODGuideText,                           VS4TSO.TSODEmpText, VS4TSO.TSODDeliveryDate, VS4TSO.TSODDeliveryTo, VS4TSO.TSODTARNCode, VS4TSO.TSODTARDCode, VS4TSO.TSODContactNote, VS4TSO.TSODContactName,                           VS4TSO.TSODCustomerName, VS4TSO.TSODCusAddress, VS4TSO.TSODConsignee, VS4TSO.TSODNotifyParty, VS4TSO.TSODCostTotal, VS4TSO.TSODPriceChannel, VS4TSO.TSODDiscountList,                           VS4TSO.TSODSubTotal, VS4TSO.TSODDiscountText, VS4TSO.TSODDiscountTotal, VS4TSO.TSODNetTotal, VS4TSO.TSODDepositText, VS4TSO.TSODDeposit, VS4TSO.TSODTotal,                           VS4TSO.TSODTotalFOB, VS4TSO.TSODTCurCode, VS4TSO.TSODExchangeRate, VS4TSO.TSODTotalInRate, VS4TSO.TSODVATType, VS4TSO.TSODVATRate, VS4TSO.TSODTaxBase,                           VS4TSO.TSODVATTotal, VS4TSO.TSODGrandTotal, VS4TSO.TSODNOTAXTotal, VS4TSO.TSODWTAXBase, VS4TSO.TSODWTaxRate, VS4TSO.TSODWTaxTotal, VS4TSO.TSODNetPayment,                           VS4TSO.TSODAdjustTotal, VS4TSO.TSODRewardTotal, VS4TSO.TSODPremiumTotal, VS4TSO.TSODCommissionBase, VS4TSO.TSODCommissionRate, VS4TSO.TSODCommission,                           VS4TSO.TSODBaseIncoType, VS4TSO.TSODIncoType, VS4TSO.TSODIncoterms, VS4TSO.TSODOtherFee, VS4TSO.TSODTransportFee, VS4TSO.TSODHandlingFee, VS4TSO.TSODFreightFee,                           VS4TSO.TSODInsurance, VS4TSO.TSODTransportDesc, VS4TSO.TSODDuty, VS4TSO.TSODShipBy, VS4TSO.TSODCountryOrigin, VS4TSO.TSODDestination, VS4TSO.TSODCondition,                           VS4TSO.TSODConditionDay, VS4TSO.TSODCondition1, VS4TSO.TSODConditionDay1, VS4TSO.TSODPaymentNote, VS4TSO.TSODStatementNote, VS4TSO.TSODDeliveryNote,                           VS4TSO.TSODPackingNote, VS4TSO.TSODDayAvailable, VS4TSO.TSODDescription, VS4TSO.TSODCustom1, VS4TSO.TSODCustom2, VS4TSO.TSODCustom3, VS4TSO.TSODCustom4,                           VS4TSO.TSODCustom5, VS4TSO.TSODInvoiceStatus, VS4TSO.TSODVerifyStatus, VS4TSO.TSODTSOTCode, VS4TSO.TSODDeliveryStatus, VS4TSO.TSODFinishDate, VS4TSO.TSODCreateBy,                           VS4TSO.TSODEditCode, VS4TSO.TSODEditBy, VS4TSO.TSODEditDate, VS4TSO.TSODConfirmStatus, VS4TSO.TSODConfirmBy, VS4TSO.TSODApproveStatus, VS4TSO.TSODApproveBy,                           VS4TSO.TSODApproveDate, VS4TSO.TSODApproveNote, VS4TSO.TSODRevision, VS4TSO.TSODReviseBy, VS4TSO.TSODCancelStatus, VS4TSO.TSODCancelBy, VS4TSO.TSODCancelDate,                           VS4TSO.TSODFlag1, VS4TSO.TSODPMCostTotal, VS4TSO.TSODTOTNLn, VS4TSO.TSODTime, VS4TSO.TSODDeliveryTime, VS4TSO.TSODStartDate, VS4TSO.TSODLoadingDate,                           VS4TSO.TSODStartAgingDate, VS4TSO.TSODArrears, VS4TSO.TSODNote, VS4TSO.TSODTAPNCode, VS4TSOMB.TSOBTSODNo, VS4TSOMB.TSOBLn, VS4TSOMB.TSOBType,                           VS4TSOMB.TSOBJobCode, VS4TSOMB.TSOBGroupName, VS4TSOMB.TSOBTOInCode, VS4TSOMB.TSOBTPOSCode, VS4TSOMB.TSOBCustom1, VS4TSOMB.TSOBCustom2,                           VS4TSOMB.TSOBCustom3, VS4TSOMB.TSOBCustom4, VS4TSOMB.TSOBCustom5, VS4TSOMB.TSOBShippingMark, VS4TSOMB.TSOBPOSCode, VS4TSOMB.TSOBFactoryCode,                           VS4TSOMB.TSOBPOSName, VS4TSOMB.TSOBOLDPOSName, VS4TSOMB.TSOBCost, VS4TSOMB.TSOBPrice, VS4TSOMB.TSOBPerQuantity, VS4TSOMB.TSOBUnitFactor,                           VS4TSOMB.TSOBQuantityCalc, VS4TSOMB.TSOBUnitCalc, VS4TSOMB.TSOBAcceptError, VS4TSOMB.TSOBQuantityText, VS4TSOMB.TSOBQuantity, VS4TSOMB.TSOBTUntCode,                           VS4TSOMB.TSOBQuantity2, VS4TSOMB.TSOBTUntCode2, VS4TSOMB.TSOBQuantity3, VS4TSOMB.TSOBTUntCode3, VS4TSOMB.TSOBCostAmount, VS4TSOMB.TSOBAmount,                           VS4TSOMB.TSOBDiscountText, VS4TSOMB.TSOBDiscountTotal, VS4TSOMB.TSOBNetAmount, VS4TSOMB.TSOBTaxType, VS4TSOMB.TSOBTaxBase, VS4TSOMB.TSOBWTAXBase,                           VS4TSOMB.TSOBAmountVAT, VS4TSOMB.TSOBAmountWTAX, VS4TSOMB.TSOBPromotionType, VS4TSOMB.TSOBFreeCode, VS4TSOMB.TSOBIsPremium, VS4TSOMB.TSOBDescription,                           VS4TSOMB.TSOBUseDate, VS4TSOMB.TSOBSourceNo, VS4TSOMB.TSOBSourceLn, VS4TSOMB.TSOBTIvoNo, VS4TSOMB.TSOBTotalDelivery, VS4TSOMB.TSOBTotalDelivery2,                           VS4TSOMB.TSOBTotalDelivery3, VS4TSOMB.TSOBTotalArrear, VS4TSOMB.TSOBTotalArrear2, VS4TSOMB.TSOBTotalArrear3, VS4TSOMB.TSOBTotalJob, VS4TSOMB.TSOBTotalJob2,                           VS4TSOMB.TSOBTotalJob3, VS4TSOMB.TSOBTotalJobArr, VS4TSOMB.TSOBTotalJobArr2, VS4TSOMB.TSOBTotalJobArr3, VS4TSOMB.TSOBDayProcess, VS4TSOMB.TSOBTLctCode,                           VS4TSOMB.TSOBFG, VS4TSOMB.TSOBJobRequest, VS4TSOMB.TSOBRequestDate, VS4TSOMB.TSOBReadyDate, VS4TSOMB.TSOBStatus, VS4TSOMB.TSOBManualClose,                           VS4TSOMB.TSOBPremiumCost, VS4TSOMB.TSOBTotalInv, VS4TSOMB.TSOBTotalInv2, VS4TSOMB.TSOBTotalInv3, VS4TAR.TARNName2, VS4TAR.TARNPhone, VS4TAR.TARNFax,                           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.TPdtTUntCode, VS4TProduct.TPdtTUntCode2,                           VS4TProduct.TPdtTUntCode3, VS4TProduct.TPdtTPTTCode, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtTPSECode, 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, VS4TLocation.TLctTWahCode, VS4TProduct.TPdtCustom1, VS4TProduct.TPdtCustom2, VS4TProduct.TPdtCustom3, VS4TProduct.TPdtCustom4,                           VS4TProduct.TPdtCustom5, VS4TProduct.TPdtCustom6, VS4TAR.TARNFirstOrderDate, VS4TBranch.TBraAddressBill, VS4TAR.TARNAddressBill, VS4TAR.TARNAddressBill2,                           VS4TSOMB.TSOBTotalMDS, VS4TSOMB.TSOBTotalMDS2, VS4TSOMB.TSOBTotalMDS3, VS4TProject.TPrjName, VS4TSOMB.TSOBTARWCode, VS4TARWelfare.TARWName,                           VS4TSO.TSODTARWCode, VS4TSOMB.TSOBTRCACode, VS4TSOMB.TSOBFlag1, VS4TProduct.TPdtBarcode, VS4TSOMB.TSOBStockFlag, VS4TPOS.TPOSMinimumOrder,                           VS4TProduct.TPdtTPPuCode, VS4TSOMB.TSOBTWahCode FROM            VS4TCountry INNER JOIN                          VS4TBusinessType RIGHT OUTER JOIN                          VS4TAR LEFT OUTER JOIN                          VS4TARGroup ON VS4TAR.TARNTARGCode = VS4TARGroup.TARGCode LEFT OUTER JOIN                          VS4TSaleArea ON VS4TAR.TARNTSAeCode = VS4TSaleArea.TSAeCode LEFT OUTER JOIN                          VS4TAR2 LEFT OUTER JOIN                          VS4TBusinessMajor ON VS4TAR2.TAR2TBSMCode = VS4TBusinessMajor.TBsMCode LEFT OUTER JOIN                          VS4TProvince ON VS4TAR2.TAR2TPrvCode = VS4TProvince.TPrvCode ON VS4TAR.TARNCode = VS4TAR2.TAR2TARNCode INNER JOIN                          VS4TSO LEFT OUTER JOIN                          VS4TProject ON VS4TSO.TSODTPrjCode = VS4TProject.TPrjCode LEFT OUTER JOIN                          VS4TBranch ON VS4TSO.TSODTBraCode = VS4TBranch.TBraCode LEFT OUTER JOIN                          VS4VSaleAROnHand ON VS4TSO.TSODTEmpCode = VS4VSaleAROnHand.VARHSaleCode LEFT OUTER JOIN                          VS4TEmployee ON VS4TSO.TSODTEmpCode = VS4TEmployee.TEmpCode LEFT OUTER 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 OUTER JOIN                          VS4TSOMB LEFT OUTER JOIN                          VS4TPOS ON VS4TSOMB.TSOBTPOSCode = VS4TPOS.TPOSCode LEFT OUTER JOIN                          VS4TLocation ON VS4TSOMB.TSOBTLctCode = VS4TLocation.TLctCode LEFT OUTER JOIN                          VS4TProduct LEFT OUTER JOIN                          VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode LEFT OUTER JOIN                          VS4TProductSec2 ON VS4TProduct.TPdtTPS2Code = VS4TProductSec2.TPS2Code LEFT OUTER JOIN                          VS4TProductSec3 ON VS4TProduct.TPdtTPS3Code = VS4TProductSec3.TPS3Code LEFT OUTER JOIN                          VS4TProductSec4 ON VS4TProduct.TPdtTPS4Code = VS4TProductSec4.TPS4Code LEFT OUTER JOIN                          VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code LEFT OUTER JOIN                          VS4TProductGroup2 ON VS4TProduct.TPdtTPG2Code = VS4TProductGroup2.TPG2Code LEFT OUTER JOIN                          VS4TProductGroup3 ON VS4TProduct.TPdtTPG3Code = VS4TProductGroup3.TPG3Code LEFT OUTER JOIN                          VS4TProductGroup4 ON VS4TProduct.TPdtTPG4Code = VS4TProductGroup4.TPG4Code ON VS4TPOS.TPOSCode = VS4TProduct.TPdtCode LEFT OUTER JOIN                          VS4TProductBook ON VS4TProduct.TPdtCode = VS4TProductBook.TPBGTPdtCode LEFT OUTER JOIN                          VS4TProduct3 ON VS4TProduct.TPdtCode = VS4TProduct3.TPD3TPdtCode LEFT OUTER JOIN                          VS4TARWelfare ON VS4TSOMB.TSOBTARWCode = VS4TARWelfare.TARWCode ON VS4TProductLine.TPdLCode = VS4TProduct.TPdtTPDLCode ON VS4TSO.TSODNo = VS4TSOMB.TSOBTSODNo
GO

CREATE VIEW VS4VSORCustom AS  SELECT VS4TSO.TSODNo, VS4TSO.TSODTSBkCode, VS4TSO.TSODTRCACode, VS4TSO.TSODMode, VS4TSO.TSODCode, VS4TSO.TSODType, VS4TSO.TSODDate, VS4TSO.TSODDueDate, VS4TSO.TSODRefNo, VS4TSO.TSODRefDate, VS4TSO.TSODRefNo2, VS4TSO.TSODTPrjCode, VS4TSO.TSODTBraCode, VS4TSO.TSODTEmpCode, VS4TSO.TSODSaleName, VS4TSO.TSODGuideText, VS4TSO.TSODEmpText, VS4TSO.TSODDeliveryDate, VS4TSO.TSODDeliveryTo, VS4TSO.TSODTARNCode, VS4TSO.TSODTARDCode, VS4TSO.TSODContactNote, VS4TSO.TSODContactName, VS4TSO.TSODCustomerName, VS4TSO.TSODCusAddress, VS4TSO.TSODConsignee, VS4TSO.TSODNotifyParty, VS4TSO.TSODCostTotal, VS4TSO.TSODPriceChannel, VS4TSO.TSODDiscountList, VS4TSO.TSODSubTotal, VS4TSO.TSODDiscountText, VS4TSO.TSODDiscountTotal, VS4TSO.TSODNetTotal, VS4TSO.TSODDepositText, VS4TSO.TSODDeposit, VS4TSO.TSODTotal, VS4TSO.TSODTotalFOB, VS4TSO.TSODTCurCode, VS4TSO.TSODExchangeRate, VS4TSO.TSODTotalInRate, VS4TSO.TSODVATType, VS4TSO.TSODVATRate, VS4TSO.TSODTaxBase, VS4TSO.TSODVATTotal, VS4TSO.TSODGrandTotal, VS4TSO.TSODNOTAXTotal, VS4TSO.TSODWTAXBase, VS4TSO.TSODWTaxRate, VS4TSO.TSODWTaxTotal, VS4TSO.TSODNetPayment, VS4TSO.TSODAdjustTotal, VS4TSO.TSODRewardTotal, VS4TSO.TSODPremiumTotal, VS4TSO.TSODCommissionBase, VS4TSO.TSODCommissionRate, VS4TSO.TSODCommission, VS4TSO.TSODBaseIncoType, VS4TSO.TSODIncoType, VS4TSO.TSODIncoterms, VS4TSO.TSODOtherFee, VS4TSO.TSODTransportFee, VS4TSO.TSODHandlingFee, VS4TSO.TSODFreightFee, VS4TSO.TSODInsurance, VS4TSO.TSODTransportDesc, VS4TSO.TSODDuty, VS4TSO.TSODShipBy, VS4TSO.TSODCountryOrigin, VS4TSO.TSODDestination, VS4TSO.TSODCondition, VS4TSO.TSODConditionDay, VS4TSO.TSODCondition1, VS4TSO.TSODConditionDay1, VS4TSO.TSODPaymentNote, VS4TSO.TSODStatementNote, VS4TSO.TSODDeliveryNote, VS4TSO.TSODPackingNote, VS4TSO.TSODDayAvailable, VS4TSO.TSODDescription, VS4TSO.TSODCustom1, VS4TSO.TSODCustom2, VS4TSO.TSODCustom3, VS4TSO.TSODCustom4, VS4TSO.TSODCustom5, VS4TSO.TSODInvoiceStatus, VS4TSO.TSODVerifyStatus, VS4TSO.TSODTSOTCode, VS4TSO.TSODDeliveryStatus, VS4TSO.TSODFinishDate, VS4TSO.TSODCreateBy, VS4TSO.TSODEditCode, VS4TSO.TSODEditBy, VS4TSO.TSODEditDate, VS4TSO.TSODConfirmStatus, VS4TSO.TSODConfirmBy, VS4TSO.TSODApproveStatus, VS4TSO.TSODApproveBy, VS4TSO.TSODApproveDate, VS4TSO.TSODApproveNote, VS4TSO.TSODRevision, VS4TSO.TSODReviseBy, VS4TSO.TSODCancelStatus, VS4TSO.TSODCancelBy, VS4TSO.TSODCancelDate, VS4TSO.TSODFlag1, VS4TSO.TSODPMCostTotal, VS4TSO.TSODTOTNLn, VS4TSO.TSODTime, VS4TSO.TSODDeliveryTime, VS4TSO.TSODStartDate, VS4TSO.TSODLoadingDate, VS4TSO.TSODStartAgingDate, VS4TSO.TSODArrears, VS4TSO.TSODNote, VS4TSO.TSODTAPNCode, VS4TSOMB.TSOBTSODNo, VS4TSOMB.TSOBLn, VS4TSOMB.TSOBType, VS4TSOMB.TSOBJobCode, VS4TSOMB.TSOBGroupName, VS4TSOMB.TSOBTOInCode, VS4TSOMB.TSOBTPOSCode, VS4TSOMB.TSOBCustom1, VS4TSOMB.TSOBCustom2, VS4TSOMB.TSOBCustom3, VS4TSOMB.TSOBCustom4, VS4TSOMB.TSOBCustom5, VS4TSOMB.TSOBShippingMark, VS4TSOMB.TSOBPOSCode, VS4TSOMB.TSOBFactoryCode, VS4TSOMB.TSOBPOSName, VS4TSOMB.TSOBOLDPOSName, VS4TSOMB.TSOBCost, VS4TSOMB.TSOBPrice, VS4TSOMB.TSOBPerQuantity, VS4TSOMB.TSOBUnitFactor, VS4TSOMB.TSOBQuantityCalc, VS4TSOMB.TSOBUnitCalc, VS4TSOMB.TSOBAcceptError, VS4TSOMB.TSOBQuantityText, VS4TSOMB.TSOBQuantity, VS4TSOMB.TSOBTUntCode, VS4TSOMB.TSOBQuantity2, VS4TSOMB.TSOBTUntCode2, VS4TSOMB.TSOBQuantity3, VS4TSOMB.TSOBTUntCode3, VS4TSOMB.TSOBCostAmount, VS4TSOMB.TSOBAmount, VS4TSOMB.TSOBDiscountText, VS4TSOMB.TSOBDiscountTotal, VS4TSOMB.TSOBNetAmount, VS4TSOMB.TSOBTaxType, VS4TSOMB.TSOBTaxBase, VS4TSOMB.TSOBWTAXBase, VS4TSOMB.TSOBAmountVAT, VS4TSOMB.TSOBAmountWTAX, VS4TSOMB.TSOBPromotionType, VS4TSOMB.TSOBFreeCode, VS4TSOMB.TSOBIsPremium, VS4TSOMB.TSOBDescription, VS4TSOMB.TSOBUseDate, VS4TSOMB.TSOBSourceNo, VS4TSOMB.TSOBSourceLn, VS4TSOMB.TSOBTIvoNo, VS4TSOMB.TSOBTotalDelivery, VS4TSOMB.TSOBTotalArrear, VS4TSOMB.TSOBTotalJob, VS4TSOMB.TSOBTotalJobArr, VS4TSOMB.TSOBDayProcess, VS4TSOMB.TSOBTLctCode, VS4TSOMB.TSOBFG, VS4TSOMB.TSOBJobRequest, VS4TSOMB.TSOBRequestDate, VS4TSOMB.TSOBReadyDate, VS4TSOMB.TSOBStatus, VS4TSOMB.TSOBManualClose, VS4TSOMB.TSOBPremiumCost, VS4TSOMB.TSOBTotalInv, VS4TAR.TARNName2, VS4TAR.TARNPhone, VS4TAR.TARNFax, 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.TPdtTUntCode, VS4TProduct.TPdtTUntCode2, VS4TProduct.TPdtTUntCode3, VS4TProduct.TPdtTPTTCode, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtTPSECode, 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, VS4TLocation.TLctTWahCode, VS4TProduct.TPdtCustom1, VS4TProduct.TPdtCustom2, VS4TProduct.TPdtCustom3, VS4TProduct.TPdtCustom4, VS4TProduct.TPdtCustom5, VS4TProduct.TPdtCustom6, VS4TAR.TARNFirstOrderDate, VS4TBranch.TBraAddressBill, VS4TAR.TARNAddressBill, VS4TAR.TARNAddressBill2, VS4TSOMB.TSOBTotalMDS, VS4TProject.TPrjName, VS4TSOMB.TSOBTARWCode, VS4TARWelfare.TARWName, VS4TSO.TSODTARWCode, VS4TSOMB.TSOBTRCACode, VS4TSOMB.TSOBFlag1, VS4TProduct.TPdtBarcode, VS4TSOMB.TSOBStockFlag, VS4TPOS.TPOSMinimumOrder, VS4TProduct.TPdtCustom9, VS4TProduct.TPdtCustom10, VS4TProduct3.TPd3Custom11, VS4TProduct3.TPd3Custom12, VS4TProduct3.TPd3Custom13, VS4TProduct3.TPd3Custom14, VS4TProduct3.TPd3Custom15, VS4TProduct3.TPd3Custom16, VS4TProduct3.TPd3Custom17, VS4TProduct3.TPd3Custom18, VS4TProduct3.TPd3Custom25 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.TSODTARNCode = VS4TARBranch.TARDTARNCode) AND (VS4TSO.TSODTARDCode = VS4TARBranch.TARDCode)) 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) LEFT JOIN VS4TProduct3 ON VS4TProduct.TPdtCode = VS4TProduct3.TPD3TPdtCode) LEFT JOIN VS4TARWelfare ON VS4TSOMB.TSOBTARWCode = VS4TARWelfare.TARWCode) ON VS4TProductLine.TPdLCode = VS4TProduct.TPdtTPDLCode) ON VS4TSO.TSODNo = VS4TSOMB.TSOBTSODNo
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 VS4VSOTechnician AS  SELECT VS4TSO.*, VS4TSOTechnician.*, VS4TEmployee.* FROM VS4TSO INNER JOIN (VS4TSOTechnician INNER JOIN VS4TEmployee ON VS4TSOTechnician.TSTcTEmpCode = VS4TEmployee.TEmpCode) ON VS4TSO.TSODNo = VS4TSOTechnician.TSTcTSODNo
GO

CREATE VIEW VS4VSSO AS  SELECT VS4VExportSlipGov.* FROM VS4VExportSlipGov WHERE (((VS4VExportSlipGov.TEm2SkipSSO)=0))
GO

CREATE VIEW VS4VSSODetail AS  SELECT VS4VExportSlipGov.* FROM VS4VExportSlipGov WHERE (((VS4VExportSlipGov.TEm2SkipSSO)=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 VS4VStock1 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.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, 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, Vs4VInventStock.TInMTLctCode FROM (SELECT TPdtCode, TPdtBarcode, TPdtName, TPdtTPTTCode, TPdtTPPuCode, TPdtFlag1, TInMInQuantity, TInMOutQuantity, TInMAmouQuantity, TPdtTUntCode, TInMAmouQuantity2, TPdtTUntCode2, TInMAmouQuantity3, TPdtTUntCode3, TInMAmount, TIMCUnitCost, TPdtTPDLCode, TPdtTPSECode, TPdtTPS2Code, TPdtTPS3Code, TPdtTPS4Code, TPdtTPG1Code, TPdtTPG2Code, TPdtTPG3Code, TPdtTPG4Code, TPdtTPCTAlias, TPOSPrice, TPdtOrderPoint, TPdtSlowDay, TPdtDeadDay, TPdtSerialType, TIMCUnitCalc, TInMQuantityCalc, TPdtTAPNCode, TPdtFactoryCode, TPOSPackAlias2, TInMTLctCode FROM VS4TUnit RIGHT 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))  AND (((TInMTLctCode)<>'PURCHASERETURN' And (TInMTLctCode)<>'INPROCESS' And (TInMTLctCode)<>'OUTSOURCE' And (TInMTLctCode)<>'SCRAP' And (TInMTLctCode)<>'TEMP' And (TInMTLctCode)<>'CONSIGN' And (TInMTLctCode)<>'CUSTOMER' And (TInMTLctCode)<>'BORROW' And (TInMTLctCode)<>'SALERETURN' And (TInMTLctCode)<>'LOAD')) AND ((VS4TInventory.TInvDate)<'3333-3-3') AND (1=1)) AS 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.TInMTLctCode HAVING (((2)=2))
GO

CREATE VIEW VS4VStockAll 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.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, 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 VS4VStockBase AS  SELECT Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtName2, 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.TIMCTUntCode, 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.TPdtName2, 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.TIMCTUntCode, 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 VS4VDOCheckStock 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, VS4TDOMBDetail.*, VS4TShipping.TSHPName, VS4TShipping_1.TSHPName AS VDODFirstShipName, VS4TARInvoice.TIvoDeliveryTo, VS4TARInvoice.TIvoDeliveryNote, VS4TARInvoice.TIvoPackingNote, VS4TARInvoice.TIvoDeliveryCond, VS4TARInvoice.TIvoTShpCode, VS4TARInvoice.TIvoTRouCode, VS4TARInvoice.TIvoBoxList, VS4VStockBranch.TInMAmouQuantity, VS4VStockBranch.TInMAmouQuantity2, VS4VStockBranch.TInMAmouQuantity3 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.TIoMLn = VS4TDOMBDetail.TDMDTIoMLn) AND (VS4TARInvoiceMB.TIoMTIvoNo = VS4TDOMBDetail.TDMDTIoMTIvoNo)) LEFT JOIN VS4VStockBranch ON VS4TARInvoiceMB.TIoMTPOSCode = VS4VStockBranch.TPdtCode) ON VS4TARInvoice.TIvoNo = VS4TARInvoiceMB.TIoMTIvoNo) ON VS4TDO.TPdyNo = VS4TDOMB.TDymTPdyNo
GO

CREATE VIEW VS4VStockBranch1 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.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, 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.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.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 VS4VStockBranchF AS  SELECT Vs4VInventStockF.TPdtCode, Vs4VInventStockF.TPdtBarcode, Vs4VInventStockF.TPdtName, Vs4VInventStockF.TPdtName2, 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.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStockF.TPdtTUntCode2, 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.TPdtName2, 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 VS4VStockBranchSJ AS  SELECT VS4VSODelivery.TSODTBraCode, VS4VSODelivery.TSODTSBkCode, VS4VSODelivery.TSODTEmpCode, VS4VSODelivery.TSODSaleName, VS4VSODelivery.TSODNo, VS4VSODelivery.TSODDate, VS4VSODelivery.TSODTARNCode, VS4VSODelivery.TARNName, VS4VSODelivery.TARNTSAeCode, VS4VSODelivery.TSAeName, VS4VSODelivery.TMDSTotalArrear, VS4VStockBranch.TInMAmouQuantity, VS4VJob.TJbMTotalArrear, VS4VStockBranch.TPdtTUntCode, VS4VStockBranch.TPdtCode, VS4VStockBranch.TPdtName, VS4VProductSafeS.TPSSStockMin, VS4VProductSafeS.TPSSStockMax, VS4VProduct.TPDLCode, VS4VProduct.TPSECode, VS4VProduct.TPdLName, VS4VProduct.TPSEName, (SELECT Sum(VS4TJobMB.TJbMUseOrder) as VSOJUseOrder   FROM VS4TJob INNER JOIN VS4TJobMB ON (VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo) AND (VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo)  WHERE TJobApproveStatus=1 AND TJobCancelStatus=0 AND TJbMTPdtCode=VS4VStockBranch.TPdtCode AND TJobCloseStatus=0 AND TJbMProcessStatus<3) AS VSOJUseOrder, (SELECT Sum(VS4TJobMB.TJbMFinishQT) as VSOJFinishQT   FROM VS4TJob INNER JOIN VS4TJobMB ON (VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo) AND (VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo)  WHERE TJobApproveStatus=1 AND TJobCancelStatus=0 AND TJbMTPdtCode=VS4VStockBranch.TPdtCode AND TJobCloseStatus=0 AND TJbMProcessStatus<3) AS VSOJFinishQT, (SELECT Sum(VS4TJobMB.TJbMUseOrder-VS4TJobMB.TJbMFinishQT) as VSOJFinishQT   FROM VS4TJob INNER JOIN VS4TJobMB ON (VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo) AND (VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo)  WHERE TJobApproveStatus=1 AND TJobCancelStatus=0 AND TJbMTPdtCode=VS4VStockBranch.TPdtCode AND TJobCloseStatus=0 AND TJbMProcessStatus<3) AS VSOJTotalArrear, VS4VStockBranch.TLctTBraCode FROM ((((SELECT * FROM VS4VSODelivery WHERE TSODApprovestatus=1 AND TSodCancelStatus=0) AS VS4VSODelivery RIGHT JOIN VS4VStockBranch ON (VS4VSODelivery.TSOBTPOSCode = VS4VStockBranch.TPdtCode) AND (VS4VSODelivery.TSODTBraCode = VS4VStockBranch.TLctTBraCode)) LEFT JOIN VS4VJob ON (VS4VStockBranch.TPdtCode = VS4VJob.TJbMTPdtCode) AND (VS4VStockBranch.TLctTBraCode = VS4VJob.TJobTBraCode)) LEFT JOIN VS4VProductSafeS ON (VS4VStockBranch.TLctTBraCode = VS4VProductSafeS.TPSSTBraCode) AND (VS4VStockBranch.TPdtCode = VS4VProductSafeS.TPSSTPdtCode)) LEFT JOIN VS4VProduct ON VS4VStockBranch.TPdtCode = VS4VProduct.TPdtCode
GO

CREATE VIEW VS4VStockDL AS  SELECT Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtName2, 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.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, 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, Vs4VInventStock.TLctTBraCode FROM Vs4VInventStock GROUP BY Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtName2, 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, Vs4VInventStock.TLctTBraCode
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.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, 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.TIMCGrade, Vs4VInventStock.TInMSerialNo, Vs4VInventStock.TIMCTCgTID, Vs4VInventStock.TIMCNoExpire, Vs4VInventStock.TIMCExpireDate, Vs4VInventStock.TIMCLotNo2, Vs4VInventStock.TIMCJobCode, Vs4VInventStock.TInMCustom1, Vs4VInventStock.TIMCCustom2, Vs4VInventStock.TIMCCustom3, Vs4VInventStock.TIMCCustom4, Vs4VInventStock.TIMCCustom5, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, 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, Vs4VInventStock.TIMCCOA, Vs4VInventStock.TIMCProposeStatus, Vs4VInventStock.TIMCProposeNote, Vs4VInventStock.TIMCUnitRatioC, Vs4VInventStock.TIMCQuantityCalc, Vs4VInventStock.TIMCPrice, Vs4VInventStock.TIMCDiscountText, Vs4VInventStock.TIMCDiscountTotal, Vs4VInventStock.TpdtTPG4Code, Vs4VInventStock.TIMCVATRate, Vs4VInventStock.TIMCVATAmount, Vs4VInventStock.TInMTIvSCode, Vs4VInventStock.TPOSPackAlias1, Vs4VInventStock.TIMCScrapLevel 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.TIMCCustom4, Vs4VInventStock.TIMCCustom5, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, 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, Vs4VInventStock.TIMCCOA, Vs4VInventStock.TIMCProposeStatus, Vs4VInventStock.TIMCProposeNote, Vs4VInventStock.TIMCUnitRatioC, Vs4VInventStock.TIMCQuantityCalc, Vs4VInventStock.TIMCPrice, Vs4VInventStock.TIMCDiscountText, Vs4VInventStock.TIMCDiscountTotal, Vs4VInventStock.TpdtTPG4Code, Vs4VInventStock.TIMCVATRate, Vs4VInventStock.TIMCVATAmount, Vs4VInventStock.TInMTIvSCode, Vs4VInventStock.TPOSPackAlias1, Vs4VInventStock.TIMCScrapLevel HAVING (((1)=1))
GO

CREATE VIEW VS4VStockFULL1 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.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, 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.TIMCGrade, Vs4VInventStock.TInMSerialNo, Vs4VInventStock.TIMCTCgTID, Vs4VInventStock.TIMCNoExpire, Vs4VInventStock.TIMCExpireDate, Vs4VInventStock.TIMCLotNo2, Vs4VInventStock.TIMCJobCode, Vs4VInventStock.TInMCustom1, Vs4VInventStock.TIMCCustom2, Vs4VInventStock.TIMCCustom3, Vs4VInventStock.TIMCCustom4, Vs4VInventStock.TIMCCustom5, 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.TInMTPltCode, Vs4VInventStock.TPdtName2, Vs4VInventStock.TPdtDescription, Vs4VInventStock.TIMCCOA, Vs4VInventStock.TIMCProposeStatus, Vs4VInventStock.TIMCProposeNote, Vs4VInventStock.TIMCUnitRatioC, Vs4VInventStock.TIMCQuantityCalc, Vs4VInventStock.TPOSPackAlias1, Vs4VInventStock.TPOSPackAlias2 FROM (SELECT TInvNo, TInvMode, TInvTIBkCode, TInvDate, TInvInvoiceStatus, TInvTARNCode, TInvTInTAlias, TInvRefNo, TInvRefDate, TInvRefNo2, TInvRefDate2, TInvRefNo3, TInvRefDate3, TInvCustom1, TInvCustom2, TInvCustom3, TInvCustom4, TInvCustom5, TInvTPrjCode, TInvTJobNo, TInvTJbMLn, TInvTMPSNo, TInvTJPdNo, TInvTJPMLn, TInvTSecCode, TInvTDepCode, TInvTDivCode, TInvTBraCode, TInvFromTBraCode, TInvTotal, TInvTotalRecord, TInvTotalQuantity, TInvRequestCode, TInvRequestBy, TInvDescription, TInvGLMethod, TInvTGLTNo, TInvDeliveryStatus, TInvSpecialFlag, TInvIsCompleted, TInvEditCode, TInvConfirmStatus, TInvApproveStatus, TInvApproveNote, TInvRevision, TInvCancelStatus, TInvCustomNo, TInvCustomDate, TInvSourceType, VS4TInventoryMB.*, VS4TWarehouse.TWahName, VS4TLocation.TLctName, VS4TProject.TPrjName, 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, TIMCTPdtCode, TIMCCustom1, TIMCSerialNo, TIMCLotNo, TIMCLotDate, TIMCReceiveNo, TIMCReceiveLn, TIMCJobCode, TIMCIsPremium, TIMCPremiumNote, TIMCCustom2, TIMCCustom3, TIMCCustom4, TIMCCustom5, TIMCScrapLevel, TIMCLotNo2, TIMCGrade, TIMCNoExpire, TIMCExpireDate, TIMCTCgTID, TIMCReserve, TIMCQAStatus, TIMCQANote, TIMCLastUnitCost, TIMCInputCost, TIMCPerQuantity, TIMCUnitCalc, TIMCUnitCost, TIMCCostCode, TIMCTPCTAlias, TIMCTAPNCode, TIMCInvoiceNo, TIMCInvoiceDate, TIMCTPODNo, TIMCTPOBLn, TIMCTPDELn, TIMCTUntCode, TIMCUnitRatio, TIMCUnit2Ratio, TIMCUnit3Ratio, TIMCLastDate, TIMCConsignFSDate, TIMCConsignLSDate, TIMCAccountLevel, TIMCIsOwner, TIMCPKI, TIMCBarcode, TIMCRFID, TIMCQuantityCost, TIMCInputTCurCode, TIMCInputCostRate, TIMCAdjustCost, TIMCStandardCost, TIMCAVGCost, TIMCEmbUnitDMVAR, TIMCEmbUnitDLVAR, TIMCUnitDMVariance, TIMCUnitDLVariance, TIMCEmbUnitOHVAR, TIMCUnitOHVariance, TIMCDutyAmount, TIMCCOA, TIMCProposeStatus, TIMCProposeNote, TIMCUnitRatioC, TIMCquantityCalc, TIMCDiscountText, TIMCDiscountTotal, TIMCTIvsCode, TIMCPrice, TIMCVATType, TIMCVATRate, TIMCVATAmount, TIMCTInTAlias, TIMCDutyRate, TIMCInputCostRateC, TIMCOtherFee, TIMCTransportFee, TIMCHandlingFee, TIMCFreightFee, TIMCInsurance, TIMCTransportDesc, TIMCDM, TIMCDL, TIMCOS, TIMCMOH, TIMCCostAmount, TIMCBahtBank, TIMCBahtCustom, TIMCBahtDif, VS4TInventoryLOT.TIMCLastDate AS VLSBLastDate, VS4TWarehouse.TWahCode, Vs4TPOS.TPOSPackAlias1, VS4TPOS.TPOSPackAlias2, VS4TProduct.TPdtDescription, VS4TWarehouse.TWahGroup FROM VS4TUnit RIGHT 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 ((VS4TInventory.TInvDate)<'3333-3-3') AND (1=1)) AS 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.TIMCCustom4, Vs4VInventStock.TIMCCustom5, 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.TInMTPltCode, Vs4VInventStock.TPdtName2, Vs4VInventStock.TPdtDescription, Vs4VInventStock.TIMCCOA, Vs4VInventStock.TIMCProposeStatus, Vs4VInventStock.TIMCProposeNote, Vs4VInventStock.TIMCUnitRatioC, Vs4VInventStock.TIMCQuantityCalc, Vs4VInventStock.TPOSPackAlias1, Vs4VInventStock.TPOSPackAlias2 HAVING (((2)=2))
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.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStockM.TPdtTUntCode2, 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.TIMCGrade, Vs4VInventStockM.TInMSerialNo, Vs4VInventStockM.TIMCTCgTID, Vs4VInventStockM.TIMCNoExpire, Vs4VInventStockM.TIMCExpireDate, Vs4VInventStockM.TIMCLotNo2, Vs4VInventStockM.TIMCJobCode, Vs4VInventStockM.TInMCustom1, Vs4VInventStockM.TIMCCustom2, Vs4VInventStockM.TIMCCustom3, Vs4VInventStockM.TIMCCustom4, Vs4VInventStockM.TIMCCustom5, 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.TInMTACPTACYID, Vs4VInventStockM.TInMTACPID, Vs4VInventStockM.TInMTPltCode, Vs4VInventStockM.TIMCCOA, Vs4VInventStockM.TIMCProposeStatus, Vs4VInventStockM.TIMCProposeNote, Vs4VInventStockM.TIMCUnitRatioC, Vs4VInventStockM.TIMCQuantityCalc, Vs4VInventStockM.TIMCPrice, Vs4VInventStockM.TIMCDiscountText, Vs4VInventStockM.TIMCDiscountTotal, Vs4VInventStockM.TIMCVATRate, Vs4VInventStockM.TIMCVATAmount, Vs4VInventStockM.TInMTIvSCode, Vs4VInventStockM.TPOSPackAlias2, Vs4VInventStockM.TPOSPackAlias1 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.TIMCCustom4, Vs4VInventStockM.TIMCCustom5, 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.TInMTACPTACYID, Vs4VInventStockM.TInMTACPID, Vs4VInventStockM.TInMTPltCode, Vs4VInventStockM.TIMCCOA, Vs4VInventStockM.TIMCProposeStatus, Vs4VInventStockM.TIMCProposeNote, Vs4VInventStockM.TIMCUnitRatioC, Vs4VInventStockM.TIMCQuantityCalc, Vs4VInventStockM.TIMCPrice, Vs4VInventStockM.TIMCDiscountText, Vs4VInventStockM.TIMCDiscountTotal, Vs4VInventStockM.TIMCVATRate, Vs4VInventStockM.TIMCVATAmount, Vs4VInventStockM.TInMTIvSCode, Vs4VInventStockM.TPOSPackAlias2, Vs4VInventStockM.TPOSPackAlias1
GO

CREATE VIEW VS4VStockFULLPR 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.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, 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.TIMCGrade, Vs4VInventStock.TInMSerialNo, Vs4VInventStock.TIMCTCgTID, Vs4VInventStock.TIMCNoExpire, Vs4VInventStock.TIMCExpireDate, Vs4VInventStock.TIMCLotNo2, Vs4VInventStock.TIMCJobCode, Vs4VInventStock.TInMCustom1, Vs4VInventStock.TIMCCustom2, Vs4VInventStock.TIMCCustom3, Vs4VInventStock.TIMCCustom4, Vs4VInventStock.TIMCCustom5, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, 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, Vs4VInventStock.TIMCCOA, Vs4VInventStock.TIMCProposeStatus, Vs4VInventStock.TIMCProposeNote, Vs4VInventStock.TIMCUnitRatioC, Vs4VInventStock.TIMCQuantityCalc, Vs4VInventStock.TIMCPrice, Vs4VInventStock.TIMCDiscountText, Vs4VInventStock.TIMCDiscountTotal, Vs4VInventStock.TpdtTPG4Code, Vs4VInventStock.TIMCVATRate, Vs4VInventStock.TIMCVATAmount, Vs4VInventStock.TInMTIvSCode, Vs4VInventStock.TPOSPackAlias1, Vs4VInventStock.TIMCScrapLevel, VS4TPR.TPRDDescription FROM (Vs4VInventStock LEFT JOIN VS4TPOMB ON (Vs4VInventStock.TIMCTPOBLn = VS4TPOMB.TPOBLn) AND (Vs4VInventStock.TIMCTPODNo = VS4TPOMB.TPOBTPODNo)) LEFT JOIN VS4TPR ON VS4TPOMB.TPOBSourceNo = VS4TPR.TPRDNo 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.TIMCGrade, Vs4VInventStock.TInMSerialNo, Vs4VInventStock.TIMCTCgTID, Vs4VInventStock.TIMCNoExpire, Vs4VInventStock.TIMCExpireDate, Vs4VInventStock.TIMCLotNo2, Vs4VInventStock.TIMCJobCode, Vs4VInventStock.TInMCustom1, Vs4VInventStock.TIMCCustom2, Vs4VInventStock.TIMCCustom3, Vs4VInventStock.TIMCCustom4, Vs4VInventStock.TIMCCustom5, Vs4VInventStock.TPdtTPDLCode, Vs4VInventStock.TPdtTPSECode, Vs4VInventStock.TPdtTPS2Code, Vs4VInventStock.TPdtTPS3Code, Vs4VInventStock.TPdtTPS4Code, Vs4VInventStock.TPdtTPG1Code, Vs4VInventStock.TPdtTPG2Code, Vs4VInventStock.TPdtTPG3Code, 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, Vs4VInventStock.TIMCCOA, Vs4VInventStock.TIMCProposeStatus, Vs4VInventStock.TIMCProposeNote, Vs4VInventStock.TIMCUnitRatioC, Vs4VInventStock.TIMCQuantityCalc, Vs4VInventStock.TIMCPrice, Vs4VInventStock.TIMCDiscountText, Vs4VInventStock.TIMCDiscountTotal, Vs4VInventStock.TpdtTPG4Code, Vs4VInventStock.TIMCVATRate, Vs4VInventStock.TIMCVATAmount, Vs4VInventStock.TInMTIvSCode, Vs4VInventStock.TPOSPackAlias1, Vs4VInventStock.TIMCScrapLevel, VS4TPR.TPRDDescription HAVING (((1)=1))
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.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, 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.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, 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 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 VS4VStockOrderP AS  SELECT VS4VProduct.TPdtCode, VS4VProduct.TPdtBarcode, VS4VProduct.TPdtName, VS4VProduct.TPdtName2, VS4VProduct.TPdtAliasSlip, VS4VProduct.TPdtAliasName, VS4VProduct.TPdtTDwgCode, VS4VProduct.TPdtTPrjCode, VS4VProduct.TPdtDescription, VS4VProduct.TPdtUnitType, VS4VProduct.TPdtTUntCode, VS4VProduct.TPdtTUntCode2, VS4VProduct.TPdtTUntCode3, VS4VProduct.TPdtUnit2Ratio, VS4VProduct.TPdtUnit3Ratio, VS4VProduct.TPdtUsage, VS4VProduct.TPdtUseBOM, VS4VProduct.TPdtOldCode, VS4VProduct.TPdtFactoryCode, VS4VProduct.TPdtFactoryOldCode, VS4VProduct.TPdtFactoryName, VS4VProduct.TPdtTransferCode, VS4VProduct.TPdtTransferName, VS4VProduct.TPdtTransferName2, VS4VProduct.TPdtTAPNCode, VS4VProduct.TPdtTPTTCode, VS4VProduct.TPdtTPDLCode, VS4VProduct.TPdtTPSECode, VS4VProduct.TPdtTPS2Code, VS4VProduct.TPdtTPS3Code, VS4VProduct.TPdtTPS4Code, VS4VProduct.TPdtTPG1Code, VS4VProduct.TPdtTPG2Code, VS4VProduct.TPdtTPG3Code, VS4VProduct.TPdtTPG4Code, VS4VProduct.TPdtTBndCode, VS4VProduct.TPdtSceinceName, VS4VProduct.TPdtRegisterNo, VS4VProduct.TPdtUseMethod, VS4VProduct.TPdtWarning, VS4VProduct.TPdtGoodsDateLabel, VS4VProduct.TPdtExpDateLabel, VS4VProduct.TPdtQuantityText, VS4VProduct.TPdtIcon1, VS4VProduct.TPdtImage1, VS4VProduct.TPdtSpec1, VS4VProduct.TPdtTPCTAlias, VS4VProduct.TPdtCustom1, VS4VProduct.TPdtCustom2, VS4VProduct.TPdtCustom3, VS4VProduct.TPdtCustom4, VS4VProduct.TPdtCustom5, VS4VProduct.TPdtCustom6, VS4VProduct.TPdtCustom7, VS4VProduct.TPdtCustom8, VS4VProduct.TPdtCustom9, VS4VProduct.TPdtCustom10, VS4VProduct.TPdtSafeDayCalc, VS4VProduct.TPdtBackDayCalc, VS4VProduct.TPdtEOQ, VS4VProduct.TPdtOrderPoint, VS4VProduct.TPdtMaxUsePerDay, VS4VProduct.TPdtAvgUsePerDay, VS4VProduct.TPdtStockType, VS4VProduct.TPdtStockQuantity, VS4VProduct.TPdtFirstDate, VS4VProduct.TPdtLastMoveDate, VS4VProduct.TPdtFirstCostInStk, VS4VProduct.TPdtLastCost, VS4VProduct.TPdtStandardCost, VS4VProduct.TPdtStdCostCode, VS4VProduct.TPdtAutoCostCode, VS4VProduct.TPdtAverageCost, VS4VProduct.TPdtAreaCost, VS4VProduct.TPdtAmount, VS4VProduct.TPdtTPPuCode, VS4VProduct.TPdtSerialType, VS4VProduct.TPdtPurchaseFee, VS4VProduct.TPdtGroupReport, VS4VProduct.TPdtSlowDay, VS4VProduct.TPdtDeadDay, VS4VProduct.TPdtLastBalDate, VS4VProduct.TPdtCreateCode, VS4VProduct.TPdtCreateDate, VS4VProduct.TPdtEditCode, VS4VProduct.TPdtEditDate, VS4VProduct.TPdtTextSort, VS4VProduct.TPdtFlag1, VS4VProduct.TPdtPremiumCost, VS4VProduct.TPdtTACSCode, VS4VProduct.TPdtStartDate, VS4VProduct.TPdtEndDate, VS4VProduct.TPdtTripDay, VS4VProduct.TPdtTAILCode, VS4VProduct.TPdtTCouCode, VS4VProduct.TPdtONSale, VS4VProduct.TPdtSetType, VS4VProduct.TPdtRFID, VS4VProduct.TPdtHasExpireDate, VS4VProduct.TPdtRequireCOA, VS4VProduct.TPdtTBraCode, VS4VProduct.TPdtDayExpire, VS4VProduct.TPdtGrade, VS4VProduct.TPdtAdjustCost, VS4VProduct.TPdtLastUnitCost, 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 VS4VStockBranch.*, TPSSOrderPoint-TInMAmouQuantity AS VORPOrderPoint FROM VS4VStockBranch
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.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, 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.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.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.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, 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.TPdtName2, 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.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, 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.TPdtOrderPoint, Vs4VInventStock.TPdtTAPNCode, Vs4VInventStock.TPdtFactoryCode FROM Vs4VInventStock LEFT JOIN VS4TJob ON Vs4VInventStock.TInvTJobNo = VS4TJob.TJobNo GROUP BY Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtName2, 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.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 VS4VStockProcess 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.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, 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.TPdtTPCTAlias, Vs4VInventStock.TPOSPrice, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TIMCUnitCalc, Sum(Vs4VInventStock.TInMQuantityCalc) AS TInMQuantityCalc, VS4TProductSafeS.TPSSOrderPoint, Vs4VInventStock.TPdtTAPNCode, Vs4VInventStock.TLctTBraCode, Vs4VInventStock.TPdtFactoryCode, VS4TProductSafeS.TPSSRefill, VS4TProductSafeS.TPSSSafePerDay, VS4TProductSafeS.TPSSSafeTotalDay, VS4TProductSafeS.TPSSStockMin, VS4TProductSafeS.TPSSSuggest, Vs4VInventStock.TPOSPackAlias2, VS4TProductSafeS.TPSSStockMax, Vs4VInventStock.TWahCode FROM (SELECT * FROM Vs4VInventStock WHERE (TwahCode='INPROCESS' OR TwahCode='OUTSOURCE')) AS Vs4VInventStock LEFT JOIN VS4TProductSafeS ON (Vs4VInventStock.TInMTPdtCode = VS4TProductSafeS.TPSSTPdtCode) AND (Vs4VInventStock.TLctTBraCode = VS4TProductSafeS.TPSSTBraCode) 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.TPdtTPCTAlias, Vs4VInventStock.TPOSPrice, Vs4VInventStock.TPdtSlowDay, Vs4VInventStock.TPdtDeadDay, Vs4VInventStock.TPdtSerialType, Vs4VInventStock.TIMCUnitCalc, VS4TProductSafeS.TPSSOrderPoint, Vs4VInventStock.TPdtTAPNCode, Vs4VInventStock.TLctTBraCode, Vs4VInventStock.TPdtFactoryCode, VS4TProductSafeS.TPSSRefill, VS4TProductSafeS.TPSSSafePerDay, VS4TProductSafeS.TPSSSafeTotalDay, VS4TProductSafeS.TPSSStockMin, VS4TProductSafeS.TPSSSuggest, Vs4VInventStock.TPOSPackAlias2, VS4TProductSafeS.TPSSStockMax, Vs4VInventStock.TWahCode
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.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, 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.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, 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 VS4VStockS1 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 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.TInMAmouQuantity2) AS TInMAmouQuantity2, 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 VS4VDOStock 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, VS4TDOMBDetail.*, VS4TShipping.TSHPName, VS4TShipping_1.TSHPName AS VDODFirstShipName, VS4TARInvoice.TIvoDeliveryTo, VS4TARInvoice.TIvoDeliveryNote, VS4TARInvoice.TIvoPackingNote, VS4TARInvoice.TIvoDeliveryCond, VS4TARInvoice.TIvoTShpCode, VS4TARInvoice.TIvoTRouCode, VS4TARInvoice.TIvoBoxList, VS4VStockWH.TWahGroup 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.TIoMLn = VS4TDOMBDetail.TDMDTIoMLn) AND (VS4TARInvoiceMB.TIoMTIvoNo = VS4TDOMBDetail.TDMDTIoMTIvoNo)) LEFT JOIN VS4VStockWH ON VS4TARInvoiceMB.TIoMTPOSCode = VS4VStockWH.TPdtCode) ON VS4TARInvoice.TIvoNo = VS4TARInvoiceMB.TIoMTIvoNo) ON VS4TDO.TPdyNo = VS4TDOMB.TDymTPdyNo WHERE (((VS4VStockWH.TWahGroup)='STOCK'))
GO

CREATE VIEW VS4VStockWH1 AS  SELECT Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtName2, 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.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, 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, Vs4VInventStock.TWahGroup, Vs4VInventStock.TIMCQAStatus FROM (SELECT TPdtCode, TPdtBarcode, TPdtName, TPdtName2, TPdtTPTTCode, TPdtTPPuCode, TPdtFlag1, TInMInQuantity, TInMOutQuantity, TInMAmouQuantity, TPdtTUntCode, TInMAmouQuantity2, TPdtTUntCode2, TInMAmouQuantity3, TPdtTUntCode3, TInMAmount, TIMCUnitCost, TWahCode, TWahName, TInMTLctCode, TLctName, TPdtTPDLCode, TPdtTPSECode, TPdtTPS2Code, TPdtTPS3Code, TPdtTPS4Code, TPdtTPG1Code, TPdtTPG2Code, TPdtTPG3Code, TPdtTPG4Code, TPdtTPCTAlias, TPOSPrice, TLctDayAlert, TLctDayMove, TPdtSlowDay, TPdtDeadDay, TPdtSerialType, TIMCUnitCalc, TInMQuantityCalc, TPdtOrderPoint, TPdtTAPNCode, TLctTBraCode, TPdtFactoryCode, TWahGroup, TIMCQAStatus FROM VS4TUnit RIGHT 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 ((VS4TInventory.TInvDate)<'3333-3-3') AND (1=1)) AS Vs4VInventStock GROUP BY Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtName2, 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, Vs4VInventStock.TWahGroup, Vs4VInventStock.TIMCQAStatus HAVING (((2)=2))
GO

CREATE VIEW VS4VStockWHCD AS  SELECT Vs4VInventStock.TPdtCode, Vs4VInventStock.TPdtBarcode, Vs4VInventStock.TPdtName, Vs4VInventStock.TPdtName2, 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.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, 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.TPdtName2, 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.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, 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.TInMAmouQuantity2) AS TInMAmouQuantity2, Vs4VInventStock.TPdtTUntCode2, 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 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.*, VS4TEmployee.*, VS4TEmpWorkPeriod.*, VS4TBranch.TBraName, VS4TDivision.TDivName, VS4TDepartment.TDepName, VS4TEmployeeType.TEmTName, VS4TSection.TSecName, VS4TSwitchTimeMB.TSTMTSWTNo, VS4TSwitchTimeMB.TSTMLn, VS4TSwitchTimeMB.TSTMTEmpCode, VS4TSwitchTimeMB.TSTMFromTWPDCode, VS4TSwitchTimeMB.TSTMToTWPDCode, VS4TSwitchTimeMB.TSTMSwitchFromDate, VS4TSwitchTimeMB.TSTMSwitchToDate, VS4TEmployee2.TEm2ExceptTimeIn, VS4TEmployee2.TEm2ExceptLunchOut, VS4TEmployee2.TEm2ExceptLunchIn, VS4TEmployee2.TEm2ExceptTimeOut, VS4TEmployee2.TEm2ExceptOTIn, VS4TEmployee2.TEm2ExceptOTOut, VS4TEmployee2.TEm2ExceptTip, VS4TEmployee2.TEm2ExceptOT FROM VS4TSwitchTime 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) LEFT JOIN VS4TEmployee2 ON VS4TEmployee.TEmpCode = VS4TEmployee2.TEm2TEmpCode) INNER JOIN (VS4TSwitchTimeMB LEFT JOIN VS4TEmpWorkPeriod ON VS4TSwitchTimeMB.TSTMToTWPDCode = VS4TEmpWorkPeriod.TWPDCode) ON VS4TEmployee.TEmpCode = VS4TSwitchTimeMB.TSTMTEmpCode) ON VS4TSwitchTime.TSwTNo = VS4TSwitchTimeMB.TSTMTSWTNo
GO

CREATE VIEW VS4VSwitchTimeGp AS  SELECT VS4TSwitchTimeGp.*, VS4TEmployeeGroup.*, VS4TEmpWorkPeriod.*, VS4TSwitchTimeGpMB.TSWMTSWGNo, VS4TSwitchTimeGpMB.TSWMLn, VS4TSwitchTimeGpMB.TSWMTEmGCode, VS4TSwitchTimeGpMB.TSWMFromTWPDCode, VS4TSwitchTimeGpMB.TSWMToTWPDCode, VS4TSwitchTimeGpMB.TSWMSwitchFromDate, VS4TSwitchTimeGpMB.TSWMSwitchToDate FROM VS4TSwitchTimeGp INNER JOIN (VS4TEmployeeGroup INNER JOIN (VS4TSwitchTimeGpMB LEFT JOIN VS4TEmpWorkPeriod ON VS4TSwitchTimeGpMB.TSWMToTWPDCode = VS4TEmpWorkPeriod.TWPDCode) ON VS4TEmployeeGroup.TEmGCode = VS4TSwitchTimeGpMB.TSWMTEmGCode) ON VS4TSwitchTimeGp.TSwGNo = VS4TSwitchTimeGpMB.TSWMTSWGNo
GO

CREATE VIEW VS4VTaxGLSum AS  SELECT VS4TGLTransSub.TGTSTACCCode, Sum(VS4TGLTransSub.TGTSDebit) AS TGTSDebit, Sum(VS4TGLTransSub.TGTSCredit) AS TGTSCredit, VS4TGLTrans.TGLTDate-Day(VS4TGLTrans.TGLTDate)+1 AS VTxGPeriodNo FROM VS4TGLTrans INNER JOIN VS4TGLTransSub ON VS4TGLTrans.TGLTNo = VS4TGLTransSub.TGTSTGLTNo GROUP BY VS4TGLTransSub.TGTSTACCCode, VS4TGLTrans.TGLTDate-Day(VS4TGLTrans.TGLTDate)+1, VS4TGLTrans.TGLTCancelStatus HAVING (((VS4TGLTransSub.TGTSTACCCode)='11-82-00') AND ((VS4TGLTrans.TGLTCancelStatus)=0))
GO

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

CREATE VIEW VS4VTaxSum AS  SELECT VS4TTaxTrans.TTxTType, VS4TTaxTrans.TTxTTaxPeriodNo, Sum(VS4TTaxTrans.TTxTBaseAmount) AS TTxTBaseAmount, Sum(VS4TTaxTrans.TTxTVATAmount) AS TTxTVATAmount, year(TTxTTaxPeriodNo) AS VTxSYear, month(TTxTTaxPeriodNo) AS VTxSmonth FROM VS4TTaxTrans GROUP BY VS4TTaxTrans.TTxTType, VS4TTaxTrans.TTxTTaxPeriodNo
GO

CREATE VIEW VS4VTaxSum2GL AS  SELECT VS4VTaxSum.*, VS4TGLTrans.TGLTNo, VS4TGLTransSub.TGTSDebit, VS4TGLTransSub.TGTSCredit, TGTSDebit-TGTSCredit-TTxTVATAmount AS VTaxValueDif, VS4TGLTrans.TGLTCancelStatus, VS4TGLTransSub.TGTSTACCCode FROM VS4TGLTrans INNER JOIN (VS4VTaxSum INNER JOIN VS4TGLTransSub ON (VS4VTaxSum.VTxSYear = VS4TGLTransSub.TGTSTACPTACYID) AND (VS4VTaxSum.VTxSmonth = VS4TGLTransSub.TGTSTACPID)) ON VS4TGLTrans.TGLTNo = VS4TGLTransSub.TGTSTGLTNo WHERE (((VS4TGLTrans.TGLTCancelStatus)=0) AND ((VS4TGLTransSub.TGTSTACCCode)='11-82-00') AND ((TGTSDebit-TGTSCredit-TTxTVATAmount)<>0) AND ((VS4VTaxSum.TTxTType)=0))
GO

CREATE VIEW VS4VTaxSum2GLSum AS  SELECT VS4VTaxSum.*, VS4VTaxGLSum.*, TGTSDebit-TGTSCredit-TTxTVATAmount AS VTaxValueDif FROM VS4VTaxSum INNER JOIN VS4VTaxGLSum ON VS4VTaxSum.TTxTTaxPeriodNo = VS4VTaxGLSum.VTxGPeriodNo WHERE (((TGTSDebit-TGTSCredit-TTxTVATAmount)<>0) AND ((VS4VTaxSum.TTxTType)=0))
GO

CREATE VIEW VS4VTaxSumByGL AS  SELECT VS4TTaxTrans.TTxTType, VS4TTaxTrans.TTxTTaxPeriodNo, Sum(VS4TTaxTrans.TTxTBaseAmount) AS TTxTBaseAmount, Sum(VS4TTaxTrans.TTxTVATAmount) AS TTxTVATAmount, VS4TTaxTrans.TTxTTGLTNo FROM VS4TTaxTrans GROUP BY VS4TTaxTrans.TTxTType, VS4TTaxTrans.TTxTTaxPeriodNo, VS4TTaxTrans.TTxTTGLTNo HAVING (((VS4TTaxTrans.TTxTType)=0) AND ((VS4TTaxTrans.TTxTTaxPeriodNo)<'9/1/2013'))
GO

CREATE VIEW VS4VTaxSumByGL2GL AS  SELECT VS4VTaxSumByGL.TTxTType, VS4VTaxSumByGL.TTxTTaxPeriodNo, VS4VTaxSumByGL.TTxTBaseAmount, VS4VTaxSumByGL.TTxTVATAmount, VS4VTaxSumByGL.TTxTTGLTNo, VS4TGLTransSub.TGTSTACCCode, VS4TGLTransSub.TGTSDebit, VS4TGLTransSub.TGTSCredit, TGTSDebit-TGTSCredit-TTxTVATAmount AS VTaxValueDif, VS4TGLTrans.TGLTDate FROM (VS4VTaxSumByGL INNER JOIN VS4TGLTrans ON VS4VTaxSumByGL.TTxTTGLTNo = VS4TGLTrans.TGLTNo) INNER JOIN VS4TGLTransSub ON VS4TGLTrans.TGLTNo = VS4TGLTransSub.TGTSTGLTNo WHERE (((VS4VTaxSumByGL.TTxTType)=0 Or (VS4VTaxSumByGL.TTxTType) Is Null) AND ((VS4TGLTransSub.TGTSTACCCode)='11-82-00') AND ((VS4TGLTrans.TGLTDate)>='8/1/2013') AND ((TGTSDebit-TGTSCredit-TTxTVATAmount) Is Null)) OR (((VS4TGLTrans.TGLTDate)<'9/1/2013'))
GO

CREATE VIEW VS4VTaxTrans AS  SELECT TTxtDocDate-Day(TTxtDocDate)+1 AS VTxTPeriod, VS4TTaxTrans.*, VS4TAR.TARNTaxNo, VS4TARInvoice.TIvoTARDCode, VS4TARBranch.TARDName, VS4TAP.TAPNTaxNo, VS4TAPInvoice.TIAPTAPUCode, VS4TAPBranch.TAPUName, VS4TAR.TARNName2, VS4TAP.TAPNName2, VS4TTaxSort.TTxSSort, VS4TARInvoice.TIvoDescription, VS4TARInvoice.TIvoCopyNote FROM VS4TAR RIGHT JOIN (VS4TAP RIGHT JOIN (((((VS4TTaxTrans LEFT JOIN VS4TARInvoice ON VS4TTaxTrans.TTxTDocNo = VS4TARInvoice.TIvoNo) LEFT JOIN VS4TAPInvoice ON VS4TTaxTrans.TTxTDocNo = VS4TAPInvoice.TIAPNo) LEFT JOIN VS4TARBranch ON (VS4TARInvoice.TIvoTARDCode = VS4TARBranch.TARDCode) AND (VS4TARInvoice.TIvoTARNCode = VS4TARBranch.TARDTARNCode)) LEFT JOIN VS4TAPBranch ON (VS4TAPInvoice.TIAPTAPNCode = VS4TAPBranch.TAPUTAPNCode) AND (VS4TAPInvoice.TIAPTAPUCode = VS4TAPBranch.TAPUCode)) LEFT JOIN VS4TTaxSort ON VS4TTaxTrans.TTxTSaveFrom = VS4TTaxSort.TTxSAlias) ON VS4TAP.TAPNCode = VS4TAPInvoice.TIAPTAPNCode) ON VS4TAR.TARNCode = VS4TARInvoice.TIvoTARNCode
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.TTIPNo = VS4TTimeInputNote.TTINTTIPNo
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.TTRDNo, VS4TTR.TTRDTIBKCode, VS4TTR.TTRDCode, VS4TTR.TTRDType, VS4TTR.TTRDDate, VS4TTR.TTRDRefNo, VS4TTR.TTRDJobCode, VS4TTR.TTRDTJobNo, VS4TTR.TTRDTJbMLn,                    VS4TTR.TTRDTJPMLn, VS4TTR.TTRDTJPDNo, VS4TTR.TTRDTPrjCode, VS4TTR.TTRDTLctCode, VS4TTR.TTRDTBraCode, VS4TTR.TTRDDescription, VS4TTR.TTRDProcessStatus,                    VS4TTR.TTRDDeliveryStatus, VS4TTR.TTRDRequestCode, VS4TTR.TTRDRequestBy, VS4TTR.TTRDCreateCode, VS4TTR.TTRDCreateBy, VS4TTR.TTRDCreateDate, VS4TTR.TTRDEditCode,                    VS4TTR.TTRDEditBy, VS4TTR.TTRDEditDate, VS4TTR.TTRDConfirmStatus, VS4TTR.TTRDConfirmBy, VS4TTR.TTRDConfirmDate, VS4TTR.TTRDApproveStatus, VS4TTR.TTRDApproveBy,                    VS4TTR.TTRDApproveDate, VS4TTR.TTRDApproveNote, VS4TTR.TTRDRevision, VS4TTR.TTRDReviseStatus, VS4TTR.TTRDCancelStatus, VS4TTR.TTRDCancelNo, VS4TTR.TTRDCancelBy,                    VS4TTR.TTRDCancelDate, VS4TTR.TTRDCancelNote, VS4TTR.TTRDFlag1, VS4TTR.TTRDFlag2, VS4TTR.TTRDFlag3, VS4TTR.TTRDTWahCode, VS4TTRMB.TTRMTTRDNo, VS4TTRMB.TTRMLn,                    VS4TTRMB.TTRMTPdtCode, VS4TTRMB.TTRMRefill, VS4TTRMB.TTRMMarkTotal, VS4TTRMB.TTRMStockOnHand, VS4TTRMB.TTRMMinStock, VS4TTRMB.TTRMTRArrear, VS4TTRMB.TTRMSuggest,                    VS4TTRMB.TTRMQuantity, VS4TTRMB.TTRMTotalDelivery, VS4TTRMB.TTRMTotalArrear, VS4TTRMB.TTRMTUntCode, VS4TTRMB.TTRMStockOnHand2, VS4TTRMB.TTRMQuantity2,                    VS4TTRMB.TTRMTotalDelivery2, VS4TTRMB.TTRMTotalArrear2, VS4TTRMB.TTRMTUntCode2, VS4TTRMB.TTRMStockOnHand3, VS4TTRMB.TTRMQuantity3, VS4TTRMB.TTRMTotalDelivery3,                    VS4TTRMB.TTRMTotalArrear3, VS4TTRMB.TTRMTUntCode3, VS4TTRMB.TTRMUseType, VS4TTRMB.TTRMUseDate, VS4TTRMB.TTRMDescription, VS4TTRMB.TTRMProcessStatus, VS4TTRMB.TTRMStatus,                    VS4TTRMB.TTRMFlag1, VS4TTRMB.TTRMFlag2, VS4TTRMB.TTRMFlag3, VS4TTRMB.TTRMCustom1, VS4TTRMB.TTRMCustom2, VS4TTRMB.TTRMCustom3, VS4TTRMB.TTRMCustom4,                    VS4TTRMB.TTRMCustom5, VS4TInventBook.TIBkCode, VS4TInventBook.TIBkName, VS4TInventBook.TIBkName2, VS4TInventBook.TIBkDocCode, VS4TInventBook.TIBkFlag1, VS4TInventBook.TIBkFlag2,                    VS4TInventBook.TIBkFlag3, VS4TProduct.TPdtCode, VS4TProduct.TPdtBarcode, VS4TProduct.TPdtName, VS4TProduct.TPdtName2, VS4TProduct.TPdtAliasSlip, VS4TProduct.TPdtAliasName,                    VS4TProduct.TPdtTDwgCode, VS4TProduct.TPdtTPrjCode, VS4TProduct.TPdtDescription, VS4TProduct.TPdtUnitType, VS4TProduct.TPdtTUntCode, VS4TProduct.TPdtTUntCode2,                    VS4TProduct.TPdtTUntCode3, VS4TProduct.TPdtUnit2Ratio, VS4TProduct.TPdtUnit3Ratio, VS4TProduct.TPdtUsage, VS4TProduct.TPdtUseBOM, VS4TProduct.TPdtOldCode, VS4TProduct.TPdtFactoryCode,                    VS4TProduct.TPdtFactoryOldCode, VS4TProduct.TPdtFactoryName, VS4TProduct.TPdtTransferCode, VS4TProduct.TPdtTransferName, VS4TProduct.TPdtTransferName2, VS4TProduct.TPdtTAPNCode,                    VS4TProduct.TPdtTPTTCode, VS4TProduct.TPdtTPDLCode, VS4TProduct.TPdtTPSECode, VS4TProduct.TPdtTPS2Code, VS4TProduct.TPdtTPS3Code, VS4TProduct.TPdtTPS4Code,                    VS4TProduct.TPdtTPG1Code, VS4TProduct.TPdtTPG2Code, VS4TProduct.TPdtTPG3Code, VS4TProduct.TPdtTPG4Code, VS4TProduct.TPdtTBndCode, VS4TProduct.TPdtSceinceName,                    VS4TProduct.TPdtRegisterNo, VS4TProduct.TPdtUseMethod, VS4TProduct.TPdtWarning, VS4TProduct.TPdtGoodsDateLabel, VS4TProduct.TPdtExpDateLabel, VS4TProduct.TPdtQuantityText,                    VS4TProduct.TPdtIcon1, VS4TProduct.TPdtImage1, VS4TProduct.TPdtSpec1, VS4TProduct.TPdtTPCTAlias, VS4TProduct.TPdtCustom1, VS4TProduct.TPdtCustom2, VS4TProduct.TPdtCustom3,                    VS4TProduct.TPdtCustom4, VS4TProduct.TPdtCustom5, VS4TProduct.TPdtCustom6, VS4TProduct.TPdtCustom7, VS4TProduct.TPdtCustom8, VS4TProduct.TPdtCustom9, VS4TProduct.TPdtCustom10,                    VS4TProduct.TPdtSafeDayCalc, VS4TProduct.TPdtBackDayCalc, VS4TProduct.TPdtEOQ, VS4TProduct.TPdtOrderPoint, VS4TProduct.TPdtMaxUsePerDay, VS4TProduct.TPdtAvgUsePerDay,                    VS4TProduct.TPdtStockType, VS4TProduct.TPdtStockQuantity, VS4TProduct.TPdtFirstDate, VS4TProduct.TPdtLastMoveDate, VS4TProduct.TPdtFirstCostInStk, VS4TProduct.TPdtLastCost,                    VS4TProduct.TPdtStandardCost, VS4TProduct.TPdtStdCostCode, VS4TProduct.TPdtAutoCostCode, VS4TProduct.TPdtAverageCost, VS4TProduct.TPdtAreaCost, VS4TProduct.TPdtAmount,                    VS4TProduct.TPdtTPPuCode, VS4TProduct.TPdtSerialType, VS4TProduct.TPdtPurchaseFee, VS4TProduct.TPdtGroupReport, VS4TProduct.TPdtSlowDay, VS4TProduct.TPdtDeadDay,                    VS4TProduct.TPdtLastBalDate, VS4TProduct.TPdtCreateCode, VS4TProduct.TPdtCreateDate, VS4TProduct.TPdtEditCode, VS4TProduct.TPdtEditDate, VS4TProduct.TPdtTextSort, VS4TProduct.TPdtFlag1,                    VS4TProduct.TPdtFlag2, VS4TProduct.TPdtFlag3, VS4TProduct.TPdtPremiumCost, VS4TProduct.TPdtTACSCode, VS4TProduct.TPdtStartDate, VS4TProduct.TPdtEndDate, VS4TProduct.TPdtTripDay,                    VS4TProduct.TPdtTAILCode, VS4TProduct.TPdtTCouCode, VS4TProduct.TPdtONSale, VS4TProduct.TPdtSetType, VS4TProduct.TPdtRFID, VS4TProduct.TPdtHasExpireDate, VS4TProduct.TPdtRequireCOA,                    VS4TProduct.TPdtTBraCode, VS4TProduct.TPdtDayExpire, VS4TProduct.TPdtGrade, VS4TProduct.TPdtAdjustCost, VS4TProduct.TPdtLastUnitCost, VS4TProduct.TPdtUnitRatioType,                    VS4TWarehouse.TWahCode, VS4TWarehouse.TWahName, VS4TWarehouse.TWahName2, VS4TWarehouse.TWahSystem, VS4TWarehouse.TWahFlag1, VS4TWarehouse.TWahFlag2,                    VS4TWarehouse.TWahFlag3, VS4TWarehouse.TWahGroup, VS4TLocation.TLctCode, VS4TLocation.TLctName, VS4TLocation.TLctName2, VS4TLocation.TLctTWahCode, VS4TLocation.TLctTBraCode,                    VS4TLocation.TLctDayAlert, VS4TLocation.TLctDayMove, VS4TLocation.TLctVolume, VS4TLocation.TLctFlag1, VS4TLocation.TLctFlag2, VS4TLocation.TLctFlag3, VS4TLocation.TLctVolumeUsed,                    VS4TLocation.TLctVolumeAval, VS4TLocation.TLctWeight, VS4TLocation.TLctWeightUsed, VS4TLocation.TLctWeightAval, VS4TLocation.TLctType, VS4TLocation.TLctAccountLevel, VS4TBranch.TBraName,                    VS4TAP.TAPNName, VS4TJob.TJobCode FROM     VS4TInventBook INNER JOIN                   VS4TTR LEFT OUTER JOIN                   VS4TLocation ON VS4TTR.TTRDTLctCode = VS4TLocation.TLctCode LEFT OUTER JOIN                   VS4TBranch ON VS4TTR.TTRDTBraCode = VS4TBranch.TBraCode LEFT OUTER JOIN                   VS4TWarehouse ON VS4TLocation.TLctTWahCode = VS4TWarehouse.TWahCode ON VS4TInventBook.TIBkCode = VS4TTR.TTRDTIBKCode INNER JOIN                   VS4TProduct LEFT OUTER JOIN                   VS4TAP ON VS4TProduct.TPdtTAPNCode = VS4TAP.TAPNCode INNER JOIN                   VS4TTRMB ON VS4TProduct.TPdtCode = VS4TTRMB.TTRMTPdtCode ON VS4TTR.TTRDNo = VS4TTRMB.TTRMTTRDNo LEFT OUTER JOIN                   VS4TJob ON VS4TTR.TTRDTJobNo = VS4TJob.TJobNo
GO

CREATE VIEW VS4VTR2PO AS SELECT VS4TTR.TTRDNo, VS4TTR.TTRDTIBKCode, VS4TTR.TTRDCode, VS4TTR.TTRDType, VS4TTR.TTRDDate, VS4TTR.TTRDRefNo, VS4TTR.TTRDJobCode, VS4TTR.TTRDTJobNo, VS4TTR.TTRDTJbMLn,                    VS4TTR.TTRDTJPMLn, VS4TTR.TTRDTJPDNo, VS4TTR.TTRDTPrjCode, VS4TTR.TTRDTLctCode, VS4TTR.TTRDTBraCode, VS4TTR.TTRDDescription, VS4TTR.TTRDProcessStatus,                    VS4TTR.TTRDDeliveryStatus, VS4TTR.TTRDRequestCode, VS4TTR.TTRDRequestBy, VS4TTR.TTRDCreateCode, VS4TTR.TTRDCreateBy, VS4TTR.TTRDCreateDate, VS4TTR.TTRDEditCode,                    VS4TTR.TTRDEditBy, VS4TTR.TTRDEditDate, VS4TTR.TTRDConfirmStatus, VS4TTR.TTRDConfirmBy, VS4TTR.TTRDConfirmDate, VS4TTR.TTRDApproveStatus, VS4TTR.TTRDApproveBy,                    VS4TTR.TTRDApproveDate, VS4TTR.TTRDApproveNote, VS4TTR.TTRDRevision, VS4TTR.TTRDReviseStatus, VS4TTR.TTRDCancelStatus, VS4TTR.TTRDCancelNo, VS4TTR.TTRDCancelBy,                    VS4TTR.TTRDCancelDate, VS4TTR.TTRDCancelNote, VS4TTR.TTRDFlag1, VS4TTR.TTRDFlag2, VS4TTR.TTRDFlag3, VS4TTR.TTRDTWahCode, VS4TTRMB.TTRMTTRDNo, VS4TTRMB.TTRMLn,                    VS4TTRMB.TTRMTPdtCode, VS4TTRMB.TTRMRefill, VS4TTRMB.TTRMMarkTotal, VS4TTRMB.TTRMStockOnHand, VS4TTRMB.TTRMMinStock, VS4TTRMB.TTRMTRArrear, VS4TTRMB.TTRMSuggest,                    VS4TTRMB.TTRMQuantity, VS4TTRMB.TTRMTotalDelivery, VS4TTRMB.TTRMTotalArrear, VS4TTRMB.TTRMTUntCode, VS4TTRMB.TTRMStockOnHand2, VS4TTRMB.TTRMQuantity2,                    VS4TTRMB.TTRMTotalDelivery2, VS4TTRMB.TTRMTotalArrear2, VS4TTRMB.TTRMTUntCode2, VS4TTRMB.TTRMStockOnHand3, VS4TTRMB.TTRMQuantity3, VS4TTRMB.TTRMTotalDelivery3,                    VS4TTRMB.TTRMTotalArrear3, VS4TTRMB.TTRMTUntCode3, VS4TTRMB.TTRMUseType, VS4TTRMB.TTRMUseDate, VS4TTRMB.TTRMDescription, VS4TTRMB.TTRMProcessStatus, VS4TTRMB.TTRMStatus,                    VS4TTRMB.TTRMFlag1, VS4TTRMB.TTRMFlag2, VS4TTRMB.TTRMFlag3, VS4TTRMB.TTRMCustom1, VS4TTRMB.TTRMCustom2, VS4TTRMB.TTRMCustom3, VS4TTRMB.TTRMCustom4,                    VS4TTRMB.TTRMCustom5, VS4TPO.TPODNo, VS4TPO.TPODType, VS4TPO.TPODDate, VS4TPO.TPODDueDate, VS4TPO.TPODDeliveryDate, VS4TPO.TPODDeliveryTo, VS4TPO.TPODTAPNCode,                    VS4TPO.TPODSupplierName, VS4TPOMB.TPOBTPODNo, VS4TPOMB.TPOBLn, VS4TPOMB.TPOBType, VS4TPOMB.TPOBJobCode, VS4TPOMB.TPOBGroupName, VS4TPOMB.TPOBTOExCode,                    VS4TPOMB.TPOBTPdtCode, VS4TPOMB.TPOBCustom1, VS4TPOMB.TPOBCustom2, VS4TPOMB.TPOBCustom3, VS4TPOMB.TPOBCustom4, VS4TPOMB.TPOBCustom5, VS4TPOMB.TPOBShippingMark,                    VS4TPOMB.TPOBProductCode, VS4TPOMB.TPOBFactoryCode, VS4TPOMB.TPOBProductName, VS4TPOMB.TPOBUseBom, VS4TPOMB.TPOBDeliveryDate, VS4TPOMB.TPOBDeliveryTime,                    VS4TPOMB.TPOBMinimumOrder, VS4TPOMB.TPOBCost, VS4TPOMB.TPOBPrice, VS4TPOMB.TPOBPerQuantity, VS4TPOMB.TPOBUnitFactor, VS4TPOMB.TPOBAcceptError, VS4TPOMB.TPOBUnitCalc,                    VS4TPOMB.TPOBQuantityCalc, VS4TPOMB.TPOBQuantityText, VS4TPOMB.TPOBQuantity, VS4TPOMB.TPOBTUntCode, VS4TPOMB.TPOBQuantity2, VS4TPOMB.TPOBTUntCode2, VS4TPOMB.TPOBQuantity3,                    VS4TPOMB.TPOBTUntCode3, VS4TPOMB.TPOBDutyAmount, VS4TPOMB.TPOBDivideExpense, VS4TPOMB.TPOBCostAmount, VS4TPOMB.TPOBAmount, VS4TPOMB.TPOBDiscountText,                    VS4TPOMB.TPOBDiscountTotal, VS4TPOMB.TPOBNetAmount, VS4TPOMB.TPOBTaxType, VS4TPOMB.TPOBTaxBase, VS4TPOMB.TPOBWTAXBase, VS4TPOMB.TPOBAmountVAT,                    VS4TPOMB.TPOBAmountWTAX, VS4TPOMB.TPOBAutoSTD, VS4TPOMB.TPOBStandardCost, VS4TPOMB.TPOBMargin, VS4TPOMB.TPOBSaleMargin, VS4TPOMB.TPOBAutoPrice, VS4TPOMB.TPOBSalePrice,                    VS4TPOMB.TPOBGetNumber, VS4TPOMB.TPOBFreeCode, VS4TPOMB.TPOBIsPremium, VS4TPOMB.TPOBDescription, VS4TPOMB.TPOBSourceNo, VS4TPOMB.TPOBSourceLn, VS4TPOMB.TPOBStatus,                    VS4TPOMB.TPOBStockTotal, VS4TPOMB.TPOBPRArrear, VS4TPOMB.TPOBEOQ, VS4TPOMB.TPOBTotalDelivery, VS4TPOMB.TPOBTotalDelivery2, VS4TPOMB.TPOBTotalDelivery3,                    VS4TPOMB.TPOBTotalArrear, VS4TPOMB.TPOBTotalArrear2, VS4TPOMB.TPOBTotalArrear3, VS4TPOMB.TPOBMapTPdtCode, VS4TPOMB.TPOBMapTUntCode, VS4TPOMB.TPOBDayProcess,                    VS4TPOMB.TPOBTLctCode, VS4TPOMB.TPOBManualClose, VS4TPOMB.TPOBFlag1, VS4TPOMB.TPOBFlag2, VS4TPOMB.TPOBFlag3, VS4TPOMB.TPOBMapRatioP, VS4TPOMB.TPOBQuantityCost,                    VS4TPOMB.TPOBTotalInv2, VS4TPOMB.TPOBTotalInv3, VS4TPOMB.TPOBTotalInv, VS4TPOMB.TPOBTotalInvArr, VS4TPOMB.TPOBTotalInvArr2, VS4TPOMB.TPOBTotalInvArr3,                    VS4TPOMB.TPOBBaseArrears, VS4TPOMB.TPOBBaseInvArr, VS4TPOMB.TPOBQuantityBase, VS4TPOMB.TPOBCloseStatus, VS4TPOMB.TPOBStockFlag, VS4TPO.TPODCountryOrigin,                    VS4TCountry.TCouName, VS4TPO.TPODTPrjCode, VS4TProject.TPrjName, 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, VS4TJob.TJobCode FROM     VS4TJob RIGHT OUTER JOIN                   VS4TTR LEFT OUTER JOIN                   VS4TLocation ON VS4TTR.TTRDTLctCode = VS4TLocation.TLctCode INNER JOIN                   VS4TPR LEFT OUTER JOIN                   VS4TDepartment ON VS4TPR.TPRDTDepCode = VS4TDepartment.TDepCode LEFT OUTER JOIN                   VS4TDivision ON VS4TPR.TPRDTDivCode = VS4TDivision.TDivCode LEFT OUTER JOIN                   VS4TSection ON VS4TPR.TPRDTSecCode = VS4TSection.TSecCode RIGHT OUTER JOIN                   VS4TPO LEFT OUTER JOIN                   VS4TCountry ON VS4TPO.TPODCountryOrigin = VS4TCountry.TCouCode LEFT OUTER JOIN                   VS4TProject ON VS4TPO.TPODTPrjCode = VS4TProject.TPrjCode LEFT OUTER JOIN                   VS4TBranch ON VS4TPO.TPODTBraCode = VS4TBranch.TBraCode LEFT OUTER JOIN                   VS4TAP ON VS4TPO.TPODTAPNCode = VS4TAP.TAPNCode LEFT OUTER JOIN                   VS4TBusinessType ON VS4TAP.TAPNTBsTCode = VS4TBusinessType.TBsTCode LEFT OUTER JOIN                   VS4TAPGroup ON VS4TAP.TAPNTAPGCode = VS4TAPGroup.TAPGCode RIGHT OUTER JOIN                   VS4TProduct LEFT OUTER JOIN                   VS4TProductType ON VS4TProduct.TPdtTPTTCode = VS4TProductType.TPTTCode LEFT OUTER JOIN                   VS4TProductLine ON VS4TProduct.TPdtTPDLCode = VS4TProductLine.TPdLCode LEFT OUTER JOIN                   VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode LEFT OUTER JOIN                   VS4TProductGroup1 ON VS4TProduct.TPdtTPG1Code = VS4TProductGroup1.TPG1Code LEFT OUTER JOIN                   VS4TProduct2 ON VS4TProduct.TPdtCode = VS4TProduct2.TPd2TPdtCode INNER JOIN                   VS4TTRMB LEFT OUTER JOIN                   VS4TPRMB LEFT OUTER JOIN                   VS4TPOMB ON VS4TPRMB.TPRMTPRDNo = VS4TPOMB.TPOBSourceNo AND VS4TPRMB.TPRMLn = VS4TPOMB.TPOBSourceLn LEFT OUTER 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 VS4TJob.TJobNo = VS4TTR.TTRDTJobNo LEFT OUTER JOIN                   VS4TWarehouse ON VS4TLocation.TLctTWahCode = VS4TWarehouse.TWahCode
GO

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

CREATE VIEW VS4VSODeliverySJ AS  SELECT VS4VSODelivery.TSODTBraCode, VS4VSODelivery.TSODTSBkCode, VS4VSODelivery.TSODTEmpCode, VS4VSODelivery.TSODSaleName, VS4VSODelivery.TSODNo, VS4VSODelivery.TSODDate, VS4VSODelivery.TSODTARNCode, VS4VSODelivery.TARNName, VS4VSODelivery.TARNTSAeCode, VS4VSODelivery.TSAeName, VS4VSODelivery.TMDSTotalArrear, VS4VStockBranch.TInMAmouQuantity, VS4VJob.TJbMTotalArrear, VS4VStockBranch.TPdtTUntCode, VS4VSODelivery.TSOBTPOSCode, VS4VSODelivery.TSOBPOSName, VS4VProductSafeS.TPSSStockMin, VS4VProductSafeS.TPSSStockMax, VS4VProduct.TPDLCode, VS4VProduct.TPSECode, VS4VProduct.TPdLName, VS4VProduct.TPSEName, VS4VSODelivery.TSODType, (SELECT Sum(VS4TJobMB.TJbMUseOrder) as VSOJUseOrder   FROM VS4TJob INNER JOIN VS4TJobMB ON (VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo) AND (VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo)  WHERE TJobApproveStatus=1 AND TJobCancelStatus=0 AND TJbMTPdtCode=VS4VSODelivery.TSOBTPOSCode AND TJobCloseStatus=0 AND TJbMProcessStatus<3) AS VSOJUseOrder, (SELECT Sum(VS4TJobMB.TJbMFinishQT) as VSOJFinishQT   FROM VS4TJob INNER JOIN VS4TJobMB ON (VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo) AND (VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo)  WHERE TJobApproveStatus=1 AND TJobCancelStatus=0 AND TJbMTPdtCode=VS4VSODelivery.TSOBTPOSCode AND TJobCloseStatus=0 AND TJbMProcessStatus<3) AS VSOJFinishQT, (SELECT Sum(VS4TJobMB.TJbMUseOrder-VS4TJobMB.TJbMFinishQT) as VSOJFinishQT   FROM VS4TJob INNER JOIN VS4TJobMB ON (VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo) AND (VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo)  WHERE TJobApproveStatus=1 AND TJobCancelStatus=0 AND TJbMTPdtCode=VS4VSODelivery.TSOBTPOSCode AND TJobCloseStatus=0 AND TJbMProcessStatus<3) AS VSOJTotalArrear FROM (((VS4VSODelivery LEFT JOIN VS4VStockBranch ON (VS4VSODelivery.TSODTBraCode = VS4VStockBranch.TLctTBraCode) AND (VS4VSODelivery.TSOBTPOSCode = VS4VStockBranch.TPdtCode)) LEFT JOIN VS4VJob ON (VS4VSODelivery.TSODTBraCode = VS4VJob.TJobTBraCode) AND (VS4VSODelivery.TSOBTPOSCode = VS4VJob.TJbMTPdtCode)) LEFT JOIN VS4VProductSafeS ON (VS4VSODelivery.TSODTBraCode = VS4VProductSafeS.TPSSTBraCode) AND (VS4VSODelivery.TSOBTPOSCode = VS4VProductSafeS.TPSSTPdtCode)) LEFT JOIN VS4VProduct ON VS4VSODelivery.TSOBTPOSCode = VS4VProduct.TPdtCode WHERE (((VS4VSODelivery.TSODApproveStatus)=1) AND ((VS4VSODelivery.TSODCancelStatus)=0))
GO

CREATE VIEW VS4VTRH AS SELECT VS4TTR.TTRDNo, VS4TTR.TTRDTIBKCode, VS4TTR.TTRDCode, VS4TTR.TTRDType, VS4TTR.TTRDDate, VS4TTR.TTRDRefNo, VS4TTR.TTRDJobCode, VS4TTR.TTRDTJobNo, VS4TTR.TTRDTJbMLn,                    VS4TTR.TTRDTJPMLn, VS4TTR.TTRDTJPDNo, VS4TTR.TTRDTPrjCode, VS4TTR.TTRDTLctCode, VS4TTR.TTRDTBraCode, VS4TTR.TTRDDescription, VS4TTR.TTRDProcessStatus,                    VS4TTR.TTRDDeliveryStatus, VS4TTR.TTRDRequestCode, VS4TTR.TTRDRequestBy, VS4TTR.TTRDCreateCode, VS4TTR.TTRDCreateBy, VS4TTR.TTRDCreateDate, VS4TTR.TTRDEditCode,                    VS4TTR.TTRDEditBy, VS4TTR.TTRDEditDate, VS4TTR.TTRDConfirmStatus, VS4TTR.TTRDConfirmBy, VS4TTR.TTRDConfirmDate, VS4TTR.TTRDApproveStatus, VS4TTR.TTRDApproveBy,                    VS4TTR.TTRDApproveDate, VS4TTR.TTRDApproveNote, VS4TTR.TTRDRevision, VS4TTR.TTRDReviseStatus, VS4TTR.TTRDCancelStatus, VS4TTR.TTRDCancelNo, VS4TTR.TTRDCancelBy,                    VS4TTR.TTRDCancelDate, VS4TTR.TTRDCancelNote, VS4TTR.TTRDFlag1, VS4TTR.TTRDFlag2, VS4TTR.TTRDFlag3, VS4TTR.TTRDTWahCode, VS4TInventBook.TIBkCode, VS4TInventBook.TIBkName,                    VS4TInventBook.TIBkName2, VS4TInventBook.TIBkDocCode, VS4TInventBook.TIBkFlag1, VS4TInventBook.TIBkFlag2, VS4TInventBook.TIBkFlag3, VS4TWarehouse.TWahCode, VS4TWarehouse.TWahName,                    VS4TWarehouse.TWahName2, VS4TWarehouse.TWahSystem, VS4TWarehouse.TWahFlag1, VS4TWarehouse.TWahFlag2, VS4TWarehouse.TWahFlag3, VS4TWarehouse.TWahGroup, VS4TLocation.TLctCode,                    VS4TLocation.TLctName, VS4TLocation.TLctName2, VS4TLocation.TLctTWahCode, VS4TLocation.TLctTBraCode, VS4TLocation.TLctDayAlert, VS4TLocation.TLctDayMove, VS4TLocation.TLctVolume,                    VS4TLocation.TLctFlag1, VS4TLocation.TLctFlag2, VS4TLocation.TLctFlag3, VS4TLocation.TLctVolumeUsed, VS4TLocation.TLctVolumeAval, VS4TLocation.TLctWeight, VS4TLocation.TLctWeightUsed,                    VS4TLocation.TLctWeightAval, VS4TLocation.TLctType, VS4TLocation.TLctAccountLevel, VS4TBranch.TBraName, VS4TJob.TJobCode FROM     VS4TInventBook INNER JOIN                   VS4TTR LEFT OUTER JOIN                   VS4TLocation ON VS4TTR.TTRDTLctCode = VS4TLocation.TLctCode LEFT OUTER JOIN                   VS4TBranch ON VS4TTR.TTRDTBraCode = VS4TBranch.TBraCode LEFT OUTER JOIN                   VS4TWarehouse ON VS4TLocation.TLctTWahCode = VS4TWarehouse.TWahCode ON VS4TInventBook.TIBkCode = VS4TTR.TTRDTIBKCode LEFT OUTER JOIN                   VS4TJob ON VS4TTR.TTRDTJobNo = VS4TJob.TJobNo
GO

CREATE VIEW VS4VTripCostD AS SELECT YEAR(VS4TJob.TJobDate) AS VJCSYear, MONTH(VS4TJob.TJobDate) AS VJCSMonth, VS4TJob.TJobDate - DAY(VS4TJob.TJobDate) + 1 AS VJCSPeriod, VS4TJob.TJobDate, VS4TJobMB.TJbMTPdtCode,                    VS4TProduct.TPdtName, VS4TJobCostSheet.TJCSCode, VS4TOtherExpense.TOExName, VS4TOtherExpense.TOExGroupReport1, VS4TOtherExpense.TOExGroupReport2, SUM(VS4TJobCostSheet.TJCSAmount)                    AS TJCSAmount, VS4TJobCostSheet.TJCSFactor, SUM(VS4TJobCostSheet.TJCSSignAmount) AS TJCSSignAmount, VS4TOtherIncome.TOInName, VS4TOtherIncome.TOInGroupReport1,                    VS4TOtherIncome.TOInGroupReport2, VS4TProductSection.TPSECode, VS4TProductSection.TPSEName, VS4TOtherIncome.TOInTACCCode, VS4TOtherExpense.TOExTACCCode FROM     VS4TProductSection LEFT OUTER JOIN                   VS4TProduct ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode RIGHT OUTER JOIN                   VS4TJob INNER JOIN                   VS4TJobMB ON VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo INNER JOIN                   VS4TJobCostSheet ON VS4TJobMB.TJbMTJobNo = VS4TJobCostSheet.TJCSTJbMTJobNo AND VS4TJobMB.TJbMLn = VS4TJobCostSheet.TJCSTJbMLn ON                    VS4TProduct.TPdtCode = VS4TJobMB.TJbMTPdtCode LEFT OUTER JOIN                   VS4TOtherIncome ON VS4TJobCostSheet.TJCSCode = VS4TOtherIncome.TOInCode LEFT OUTER JOIN                   VS4TOtherExpense ON VS4TJobCostSheet.TJCSCode = VS4TOtherExpense.TOExCode GROUP BY VS4TJobMB.TJbMTPdtCode, VS4TJobCostSheet.TJCSCode, VS4TJob.TJobDate, VS4TOtherExpense.TOExName, VS4TJobCostSheet.TJCSFactor, VS4TOtherIncome.TOInName, VS4TProduct.TPdtName,                    VS4TOtherIncome.TOInGroupReport1, VS4TOtherIncome.TOInGroupReport2, VS4TOtherExpense.TOExGroupReport1, VS4TOtherExpense.TOExGroupReport2, VS4TProductSection.TPSECode,                    VS4TProductSection.TPSEName, VS4TOtherIncome.TOInTACCCode, VS4TOtherExpense.TOExTACCCode, VS4TJob.TJobType, VS4TJob.TJobApproveStatus, VS4TJob.TJobCancelStatus HAVING (VS4TJob.TJobType IN (6, 7)) AND (VS4TJob.TJobApproveStatus = 1) AND (VS4TJob.TJobCancelStatus = 0)
GO

CREATE VIEW VS4VTripCostDGR1 AS SELECT YEAR(VS4TJob.TJobDate) AS VJCSYear, MONTH(VS4TJob.TJobDate) AS VJCSMonth, VS4TJob.TJobDate - DAY(VS4TJob.TJobDate) + 1 AS VJCSPeriod, VS4TJob.TJobDate, VS4TJobMB.TJbMTPdtCode,                    VS4TProduct.TPdtName, VS4TOtherExpense.TOExName, VS4TOtherExpense.TOExGroupReport1, SUM(VS4TJobCostSheet.TJCSAmount) AS TJCSAmount, VS4TJobCostSheet.TJCSFactor,                    SUM(VS4TJobCostSheet.TJCSSignAmount) AS TJCSSignAmount, VS4TOtherIncome.TOInName, VS4TOtherIncome.TOInGroupReport1, VS4TProductSection.TPSECode, VS4TProductSection.TPSEName FROM     VS4TJob INNER JOIN                   VS4TJobMB ON VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo INNER JOIN                   VS4TJobCostSheet ON VS4TJobMB.TJbMTJobNo = VS4TJobCostSheet.TJCSTJbMTJobNo AND VS4TJobMB.TJbMLn = VS4TJobCostSheet.TJCSTJbMLn LEFT OUTER JOIN                   VS4TProduct ON VS4TJobMB.TJbMTPdtCode = VS4TProduct.TPdtCode LEFT OUTER JOIN                   VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode LEFT OUTER JOIN                   VS4TOtherIncome ON VS4TJobCostSheet.TJCSCode = VS4TOtherIncome.TOInCode LEFT OUTER JOIN                   VS4TOtherExpense ON VS4TJobCostSheet.TJCSCode = VS4TOtherExpense.TOExCode GROUP BY VS4TJobMB.TJbMTPdtCode, VS4TJob.TJobDate, VS4TOtherExpense.TOExName, VS4TJobCostSheet.TJCSFactor, VS4TOtherIncome.TOInName, VS4TProduct.TPdtName,                    VS4TOtherIncome.TOInGroupReport1, VS4TOtherExpense.TOExGroupReport1, VS4TProductSection.TPSECode, VS4TProductSection.TPSEName, VS4TJob.TJobType, VS4TJob.TJobApproveStatus,                    VS4TJob.TJobCancelStatus HAVING (VS4TJob.TJobType IN (6, 7)) AND (VS4TJob.TJobApproveStatus = 1) AND (VS4TJob.TJobCancelStatus = 0)
GO

CREATE VIEW VS4VTripCostDGR2 AS SELECT YEAR(VS4TJob.TJobDate) AS VJCSYear, MONTH(VS4TJob.TJobDate) AS VJCSMonth, VS4TJob.TJobDate - DAY(VS4TJob.TJobDate) + 1 AS VJCSPeriod, VS4TJob.TJobDate, VS4TJobMB.TJbMTPdtCode,                    VS4TProduct.TPdtName, VS4TOtherExpense.TOExName, VS4TOtherExpense.TOExGroupReport2, SUM(VS4TJobCostSheet.TJCSAmount) AS TJCSAmount, VS4TJobCostSheet.TJCSFactor,                    SUM(VS4TJobCostSheet.TJCSSignAmount) AS TJCSSignAmount, VS4TOtherIncome.TOInName, VS4TOtherIncome.TOInGroupReport2, VS4TProductSection.TPSECode, VS4TProductSection.TPSEName FROM     VS4TJob INNER JOIN                   VS4TJobMB ON VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo INNER JOIN                   VS4TJobCostSheet ON VS4TJobMB.TJbMTJobNo = VS4TJobCostSheet.TJCSTJbMTJobNo AND VS4TJobMB.TJbMLn = VS4TJobCostSheet.TJCSTJbMLn LEFT OUTER JOIN                   VS4TProduct ON VS4TJobMB.TJbMTPdtCode = VS4TProduct.TPdtCode LEFT OUTER JOIN                   VS4TOtherIncome ON VS4TJobCostSheet.TJCSCode = VS4TOtherIncome.TOInCode LEFT OUTER JOIN                   VS4TOtherExpense ON VS4TJobCostSheet.TJCSCode = VS4TOtherExpense.TOExCode LEFT OUTER JOIN                   VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode GROUP BY VS4TJobMB.TJbMTPdtCode, VS4TJob.TJobDate, VS4TOtherExpense.TOExName, VS4TJobCostSheet.TJCSFactor, VS4TOtherIncome.TOInName, VS4TProduct.TPdtName,                    VS4TOtherIncome.TOInGroupReport2, VS4TOtherExpense.TOExGroupReport2, VS4TProductSection.TPSECode, VS4TProductSection.TPSEName, VS4TJob.TJobType, VS4TJob.TJobApproveStatus,                    VS4TJob.TJobCancelStatus HAVING (VS4TJob.TJobType IN (6, 7)) AND (VS4TJob.TJobApproveStatus = 1) AND (VS4TJob.TJobCancelStatus = 0)
GO

CREATE VIEW VS4VTripCostM AS SELECT YEAR(VS4TJob.TJobDate) AS VJCSYear, MONTH(VS4TJob.TJobDate) AS VJCSMonth, VS4TJob.TJobDate - DAY(VS4TJob.TJobDate) + 1 AS VJCSPeriod, VS4TJobMB.TJbMTPdtCode, VS4TProduct.TPdtName,                    VS4TJobCostSheet.TJCSCode, VS4TOtherExpense.TOExName, VS4TOtherExpense.TOExGroupReport1, VS4TOtherExpense.TOExGroupReport2, SUM(VS4TJobCostSheet.TJCSAmount) AS TJCSAmount,                    VS4TJobCostSheet.TJCSFactor, SUM(VS4TJobCostSheet.TJCSSignAmount) AS TJCSSignAmount, VS4TOtherIncome.TOInName, VS4TOtherIncome.TOInGroupReport1, VS4TOtherIncome.TOInGroupReport2,                    VS4TProductSection.TPSECode, VS4TProductSection.TPSEName, VS4TOtherIncome.TOInTACCCode, VS4TOtherExpense.TOExTACCCode FROM     VS4TProductSection LEFT OUTER JOIN                   VS4TProduct ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode RIGHT OUTER JOIN                   VS4TJob INNER JOIN                   VS4TJobMB ON VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo INNER JOIN                   VS4TJobCostSheet ON VS4TJobMB.TJbMTJobNo = VS4TJobCostSheet.TJCSTJbMTJobNo AND VS4TJobMB.TJbMLn = VS4TJobCostSheet.TJCSTJbMLn ON                    VS4TProduct.TPdtCode = VS4TJobMB.TJbMTPdtCode LEFT OUTER JOIN                   VS4TOtherIncome ON VS4TJobCostSheet.TJCSCode = VS4TOtherIncome.TOInCode LEFT OUTER JOIN                   VS4TOtherExpense ON VS4TJobCostSheet.TJCSCode = VS4TOtherExpense.TOExCode GROUP BY VS4TJobMB.TJbMTPdtCode, VS4TJobCostSheet.TJCSCode, YEAR(VS4TJob.TJobDate), MONTH(VS4TJob.TJobDate), VS4TOtherExpense.TOExName, VS4TJobCostSheet.TJCSFactor,                    VS4TOtherIncome.TOInName, VS4TProduct.TPdtName, VS4TOtherIncome.TOInGroupReport1, VS4TOtherIncome.TOInGroupReport2, VS4TOtherExpense.TOExGroupReport1,                    VS4TOtherExpense.TOExGroupReport2, VS4TJob.TJobDate - DAY(VS4TJob.TJobDate) + 1, VS4TProductSection.TPSECode, VS4TProductSection.TPSEName, VS4TOtherIncome.TOInTACCCode,                    VS4TOtherExpense.TOExTACCCode, VS4TJob.TJobType, VS4TJob.TJobApproveStatus, VS4TJob.TJobCancelStatus HAVING (VS4TJob.TJobType IN (6, 7)) AND (VS4TJob.TJobApproveStatus = 1) AND (VS4TJob.TJobCancelStatus = 0)
GO

CREATE VIEW VS4VTripCostMGR1 AS SELECT YEAR(VS4TJob.TJobDate) AS VJCSYear, MONTH(VS4TJob.TJobDate) AS VJCSMonth, VS4TJob.TJobDate - DAY(VS4TJob.TJobDate) + 1 AS VJCSPeriod, VS4TJobMB.TJbMTPdtCode, VS4TProduct.TPdtName,                    VS4TOtherExpense.TOExGroupReport1, SUM(VS4TJobCostSheet.TJCSAmount) AS TJCSAmount, VS4TJobCostSheet.TJCSFactor, SUM(VS4TJobCostSheet.TJCSSignAmount) AS TJCSSignAmount,                    VS4TOtherIncome.TOInGroupReport1, VS4TProductSection.TPSECode, VS4TProductSection.TPSEName FROM     VS4TProductSection RIGHT OUTER JOIN                   VS4TProduct ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode RIGHT OUTER JOIN                   VS4TJob INNER JOIN                   VS4TJobMB ON VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo INNER JOIN                   VS4TJobCostSheet ON VS4TJobMB.TJbMTJobNo = VS4TJobCostSheet.TJCSTJbMTJobNo AND VS4TJobMB.TJbMLn = VS4TJobCostSheet.TJCSTJbMLn ON                    VS4TProduct.TPdtCode = VS4TJobMB.TJbMTPdtCode LEFT OUTER JOIN                   VS4TOtherIncome ON VS4TJobCostSheet.TJCSCode = VS4TOtherIncome.TOInCode LEFT OUTER JOIN                   VS4TOtherExpense ON VS4TJobCostSheet.TJCSCode = VS4TOtherExpense.TOExCode GROUP BY VS4TJobMB.TJbMTPdtCode, VS4TJobCostSheet.TJCSFactor, VS4TProduct.TPdtName, VS4TOtherIncome.TOInGroupReport1, VS4TOtherExpense.TOExGroupReport1, YEAR(VS4TJob.TJobDate),                    MONTH(VS4TJob.TJobDate), VS4TJob.TJobDate - DAY(VS4TJob.TJobDate) + 1, VS4TProductSection.TPSECode, VS4TProductSection.TPSEName, VS4TJob.TJobType, VS4TJob.TJobApproveStatus,                    VS4TJob.TJobCancelStatus HAVING (VS4TJob.TJobType IN (6, 7)) AND (VS4TJob.TJobApproveStatus = 1) AND (VS4TJob.TJobCancelStatus = 0)
GO

CREATE VIEW VS4VTripCostMGR2 AS SELECT YEAR(VS4TJob.TJobDate) AS VJCSYear, MONTH(VS4TJob.TJobDate) AS VJCSMonth, VS4TJob.TJobDate - DAY(VS4TJob.TJobDate) + 1 AS VJCSPeriod, VS4TJobMB.TJbMTPdtCode, VS4TProduct.TPdtName,                    VS4TOtherExpense.TOExGroupReport2, SUM(VS4TJobCostSheet.TJCSAmount) AS TJCSAmount, VS4TJobCostSheet.TJCSFactor, SUM(VS4TJobCostSheet.TJCSSignAmount) AS TJCSSignAmount,                    VS4TOtherIncome.TOInGroupReport2, VS4TProductSection.TPSECode, VS4TProductSection.TPSEName FROM     VS4TProductSection RIGHT OUTER JOIN                   VS4TProduct ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode RIGHT OUTER JOIN                   VS4TJob INNER JOIN                   VS4TJobMB ON VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo INNER JOIN                   VS4TJobCostSheet ON VS4TJobMB.TJbMTJobNo = VS4TJobCostSheet.TJCSTJbMTJobNo AND VS4TJobMB.TJbMLn = VS4TJobCostSheet.TJCSTJbMLn ON                    VS4TProduct.TPdtCode = VS4TJobMB.TJbMTPdtCode LEFT OUTER JOIN                   VS4TOtherIncome ON VS4TJobCostSheet.TJCSCode = VS4TOtherIncome.TOInCode LEFT OUTER JOIN                   VS4TOtherExpense ON VS4TJobCostSheet.TJCSCode = VS4TOtherExpense.TOExCode GROUP BY VS4TJobMB.TJbMTPdtCode, VS4TJobCostSheet.TJCSFactor, VS4TProduct.TPdtName, VS4TOtherIncome.TOInGroupReport2, VS4TOtherExpense.TOExGroupReport2, YEAR(VS4TJob.TJobDate),                    MONTH(VS4TJob.TJobDate), VS4TJob.TJobDate - DAY(VS4TJob.TJobDate) + 1, VS4TProductSection.TPSECode, VS4TProductSection.TPSEName, VS4TJob.TJobType, VS4TJob.TJobApproveStatus,                    VS4TJob.TJobCancelStatus HAVING (VS4TJob.TJobType IN (6, 7)) AND (VS4TJob.TJobApproveStatus = 1) AND (VS4TJob.TJobCancelStatus = 0)
GO

CREATE VIEW VS4VTripDay AS SELECT VS4TJob.TJobDate, VS4TJobMB.TJbMTPdtCode, VS4TProduct.TPdtName, VS4TProductSection.TPSECode, VS4TProductSection.TPSEName, COUNT(VS4TJob.TJobNo) AS VJCSTrips,                    SUM(VS4TJobMB.TJbMCustomValue5) AS TJbMCustomValue5, SUM(VS4TJob.TJobIncomeTotal) AS TJobIncomeTotal, SUM(VS4TJob.TJobCostTotal) AS TJobCostTotal, SUM(VS4TJob.TJobProfit) AS TJobProfit,                    VS4TProduct.TPdtTPDLCode, VS4TJob.TJobTBraCode FROM     VS4TJob INNER JOIN                   VS4TJobMB ON VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo INNER JOIN                   VS4TProduct ON VS4TJobMB.TJbMTPdtCode = VS4TProduct.TPdtCode INNER JOIN                   VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode WHERE  (VS4TJob.TJobType IN (6, 7)) AND (VS4TJob.TJobCancelStatus = 0) GROUP BY VS4TJob.TJobDate, VS4TJobMB.TJbMTPdtCode, VS4TProduct.TPdtName, VS4TProductSection.TPSEName, VS4TProductSection.TPSECode, VS4TJobMB.TJbMLn, VS4TProduct.TPdtTPDLCode,                    VS4TJob.TJobTBraCode HAVING (VS4TJobMB.TJbMLn = 1)
GO

CREATE VIEW VS4VTripSumDay AS SELECT VS4VTripSumDay_1.TJobDate, VS4VTripSumDay_1.TPSECode, VS4VTripSumDay_1.TPSEName, VS4VTripSumDay_1.TJbMQuantity, VS4VTripSumDay_1.TJbMCustomValue2, VS4VTripSumDay_1.TJbMCustomValue5,                    VS4VTripSumDay_1.TJbMPcsPerCarton, VS4VTripSumDay_1.TJbMUseStock, VS4VTripSumDay_1.TJbMUseStock2, VS4VTripSumDay_1.TJobIncomeTotal, VS4VTripSumDay_1.TJobCostTotal, VS4VTripSumDay_1.TJobProfit,                    VS4VTripSumDay_1.TJobTBraCode, VS4VTripSumDay_1.TJobTPrjCode, VS4VTripSumDay_1.VJCSTrips, VS4VTripSumDay_1.VJCSFillFuel, VS4VTripSumDay_1.VJCSFuelReady, VS4VTripSumDay_1.VJCSCloseCount,                    VS4VTripSumDay_1.VJCSCloseReady, CASE WHEN TRVHCancelStatus = 0 THEN TRVHNo ELSE NULL END AS TRVHNo, VS4TARVoucher.TRVHSubTotal, VS4TARVoucher.TRVHDiscount, VS4TARVoucher.TRVHNetAmount,                    VS4VTripSumDay_1.TJbMCustomValue5 - VS4TARVoucher.TRVHNetAmount AS VJCSDiffSale, VS4TARVoucher.TRVHExpenseTotal,                    VS4VTripSumDay_1.TJobCostTotal - VS4TARVoucher.TRVHExpenseTotal AS VJCSDiffExpense FROM     (SELECT VS4TJob.TJobDate, VS4TProductSection.TPSECode, VS4TProductSection.TPSEName, SUM(VS4TJobMB.TJbMQuantity) AS TJbMQuantity, SUM(VS4TJobMB.TJbMCustomValue2) AS TJbMCustomValue2,                                      SUM(VS4TJobMB.TJbMCustomValue5) AS TJbMCustomValue5, SUM(VS4TJobMB.TJbMPcsPerCarton) AS TJbMPcsPerCarton, SUM(VS4TJobMB.TJbMUseStock) AS TJbMUseStock,                                      SUM(VS4TJobMB.TJbMUseStock2) AS TJbMUseStock2, SUM(VS4TJob.TJobIncomeTotal) AS TJobIncomeTotal, SUM(VS4TJob.TJobCostTotal) AS TJobCostTotal, SUM(VS4TJob.TJobProfit) AS TJobProfit,                                      VS4TJob.TJobTBraCode, VS4TJob.TJobTPrjCode, COUNT(VS4TJob.TJobNo) AS VJCSTrips, SUM(CASE isnull(TJbMTotalCarton, 0) WHEN 0 THEN 0 ELSE 1 END) AS VJCSFillFuel, MIN(CASE isnull(TJbMTotalCarton, 0)                                      WHEN 0 THEN 0 ELSE 1 END) AS VJCSFuelReady, SUM(CASE isnull(TJobCloseStatus, 2) WHEN 1 THEN 1 ELSE 0 END) AS VJCSCloseCount, MIN(CASE isnull(TJobCloseStatus, 2) WHEN 1 THEN 1 ELSE 0 END)                                      AS VJCSCloseReady                   FROM      VS4TJob INNER JOIN                                     VS4TJobMB ON VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo INNER JOIN                                     VS4TProduct ON VS4TJobMB.TJbMTPdtCode = VS4TProduct.TPdtCode INNER JOIN                                     VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode                   WHERE   (VS4TJob.TJobType IN (6, 7)) AND (VS4TJob.TJobCancelStatus = 0) AND (VS4TJob.TJobApproveStatus = 1)                   GROUP BY VS4TJob.TJobDate, VS4TProductSection.TPSECode, VS4TProductSection.TPSEName, VS4TJob.TJobTBraCode, VS4TJob.TJobTPrjCode) AS VS4VTripSumDay_1 LEFT OUTER JOIN                   VS4TARVoucher ON VS4VTripSumDay_1.TJobDate = VS4TARVoucher.TRVHDate AND VS4VTripSumDay_1.TPSECode = VS4TARVoucher.TRVHRefNo WHERE  (VS4TARVoucher.TRVHType = 5) OR                   (VS4TARVoucher.TRVHNo IS NULL)
GO

CREATE VIEW VS4VTripSumDayCost AS SELECT YEAR(VS4TJob.TJobDate) AS VJCSYear, MONTH(VS4TJob.TJobDate) AS VJCSMonth, VS4TJob.TJobDate - DAY(VS4TJob.TJobDate) + 1 AS VJCSPeriod, VS4TJob.TJobDate, VS4TJobCostSheet.TJCSCode,                    VS4TOtherExpense.TOExName, VS4TOtherExpense.TOExGroupReport1, VS4TOtherExpense.TOExGroupReport2, SUM(VS4TJobCostSheet.TJCSAmount) AS TJCSAmount, VS4TJobCostSheet.TJCSFactor,                    SUM(VS4TJobCostSheet.TJCSSignAmount) AS TJCSSignAmount, VS4TOtherIncome.TOInName, VS4TOtherIncome.TOInGroupReport1, VS4TOtherIncome.TOInGroupReport2, VS4TProductSection.TPSECode,                    VS4TProductSection.TPSEName, VS4TOtherIncome.TOInTACCCode, VS4TOtherExpense.TOExTACCCode FROM     VS4TProductSection LEFT OUTER JOIN                   VS4TProduct ON VS4TProductSection.TPSECode = VS4TProduct.TPdtTPSECode RIGHT OUTER JOIN                   VS4TJob INNER JOIN                   VS4TJobMB ON VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo INNER JOIN                   VS4TJobCostSheet ON VS4TJobMB.TJbMTJobNo = VS4TJobCostSheet.TJCSTJbMTJobNo AND VS4TJobMB.TJbMLn = VS4TJobCostSheet.TJCSTJbMLn ON                    VS4TProduct.TPdtCode = VS4TJobMB.TJbMTPdtCode LEFT OUTER JOIN                   VS4TOtherIncome ON VS4TJobCostSheet.TJCSCode = VS4TOtherIncome.TOInCode LEFT OUTER JOIN                   VS4TOtherExpense ON VS4TJobCostSheet.TJCSCode = VS4TOtherExpense.TOExCode GROUP BY VS4TJobCostSheet.TJCSCode, VS4TJob.TJobDate, VS4TOtherExpense.TOExName, VS4TJobCostSheet.TJCSFactor, VS4TOtherIncome.TOInName, VS4TOtherIncome.TOInGroupReport1,                    VS4TOtherIncome.TOInGroupReport2, VS4TOtherExpense.TOExGroupReport1, VS4TOtherExpense.TOExGroupReport2, VS4TProductSection.TPSECode, VS4TProductSection.TPSEName,                    VS4TOtherIncome.TOInTACCCode, VS4TOtherExpense.TOExTACCCode, VS4TJob.TJobType, VS4TJob.TJobApproveStatus, VS4TJob.TJobCancelStatus HAVING (VS4TJob.TJobType IN (6, 7)) AND (VS4TJob.TJobApproveStatus = 1) AND (VS4TJob.TJobCancelStatus = 0)
GO

CREATE VIEW VS4VTripSumDayPay AS SELECT VS4TJob.TJobDate, VS4TProductSection.TPSECode, VS4TProductSection.TPSEName, VS4TJob.TJobTBraCode, VS4TJob.TJobTPrjCode, COUNT(VS4TJob.TJobNo) AS VJCSTrips,                    VS4TJobCostSheet.TJCSPayChannel, VS4TPayment.TPymTPyTAlias, VS4TPayment.TPymTCBBNo, VS4TPayment.TPymModule, SUM(VS4TJobCostSheet.TJCSAmount) AS TJCSAmount,                    VS4TPayment.TPymTPSECode FROM     VS4TPayment RIGHT OUTER JOIN                   VS4TJob INNER JOIN                   VS4TJobMB ON VS4TJob.TJobNo = VS4TJobMB.TJbMTJobNo INNER JOIN                   VS4TJobCostSheet ON VS4TJobMB.TJbMTJobNo = VS4TJobCostSheet.TJCSTJbMTJobNo AND VS4TJobMB.TJbMLn = VS4TJobCostSheet.TJCSTJbMLn INNER JOIN                   VS4TProduct INNER JOIN                   VS4TProductSection ON VS4TProduct.TPdtTPSECode = VS4TProductSection.TPSECode ON VS4TJobMB.TJbMTPdtCode = VS4TProduct.TPdtCode ON                    VS4TPayment.TPymTPSECode = VS4TProductSection.TPSECode AND VS4TPayment.TPymName = VS4TJobCostSheet.TJCSPayChannel GROUP BY VS4TJob.TJobType, VS4TJob.TJobDate, VS4TProductSection.TPSECode, VS4TProductSection.TPSEName, VS4TJob.TJobTBraCode, VS4TJob.TJobTPrjCode, VS4TJob.TJobApproveStatus,                    VS4TJob.TJobCancelStatus, VS4TPayment.TPymTPyTAlias, VS4TPayment.TPymTCBBNo, VS4TPayment.TPymModule, VS4TJobCostSheet.TJCSPayChannel, VS4TJobCostSheet.TJCSFactor,                    VS4TPayment.TPymTPSECode HAVING (VS4TJob.TJobType IN (6, 7)) AND (VS4TJob.TJobApproveStatus = 1) AND (VS4TJob.TJobCancelStatus = 0) AND (VS4TJobCostSheet.TJCSFactor = 1)
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.TUsrID, VS4TUser.TUsrName, VS4TUser.TUsrPassword, VS4TUser.TUsrTEmpCode, VS4TUser.TUsrFullName, VS4TUser.TUsrDescription, VS4TUser.TUsrDisable,                           VS4TUser.TUsrSecurity, VS4TUser.TUsrLevel, VS4TUser.TUsrGroupware, VS4TUser.TUsrOwner, VS4TUser.TUsrFlag1, VS4TUser.TUsrFlag2, VS4TUser.TUsrFlag3, VS4TUser.TUsrMobile,                           VS4TUser.TUsrProjectLevel, VS4TEmployee.TEmpCode, VS4TEmployee.TEmpNo, VS4TEmployee.TEmpBarCode, VS4TEmployee.TEmpCardNo, VS4TEmployee.TEmpTEmTCode,                           VS4TEmployee.TEmpTWPDCode, VS4TEmployee.TEmpGender, VS4TEmployee.TEmpTitleName, VS4TEmployee.TEmpFirstName, VS4TEmployee.TEmpMiddleName, VS4TEmployee.TEmpLastName,                           VS4TEmployee.TEmpAliasName, VS4TEmployee.TEmpNickName, VS4TEmployee.TEmpFullName, VS4TEmployee.TEmpTitleName2, VS4TEmployee.TEmpFirstName2,                           VS4TEmployee.TEmpMiddleName2, VS4TEmployee.TEmpLastname2, VS4TEmployee.TEmpFullName2, VS4TEmployee.TEmpAddress, VS4TEmployee.TEmpSubProvince, VS4TEmployee.TEmpCity,                           VS4TEmployee.TEmpPostalCode, VS4TEmployee.TEmpTStaCode, VS4TEmployee.TEmpTCouCode, VS4TEmployee.TEmpTel, VS4TEmployee.TEmpFax, VS4TEmployee.TEmpEmail,                           VS4TEmployee.TEmpAddressContact, VS4TEmployee.TEmpImage1, VS4TEmployee.TEmpBirthDay, VS4TEmployee.TEmpBornZone, VS4TEmployee.TEmpBlood, VS4TEmployee.TEmpFundNo,                           VS4TEmployee.TEmpCitizenNo, VS4TEmployee.TEmpCitizenAddress, VS4TEmployee.TEmpPassportNo, VS4TEmployee.TEmpTaxNo, VS4TEmployee.TEmpSocialSecurity,                           VS4TEmployee.TEmpCardAlien, VS4TEmployee.TEmpAllowAlien, VS4TEmployee.TEmpRace, VS4TEmployee.TEmpCitizenShip, VS4TEmployee.TEmpReligion, VS4TEmployee.TEmpHospital,                           VS4TEmployee.TEmpHospital1, VS4TEmployee.TEmpType, VS4TEmployee.TEmpDropStatus, VS4TEmployee.TEmpStatus, VS4TEmployee.TEmpSignDate, VS4TEmployee.TEmpPermanantDate,                           VS4TEmployee.TEmpResignDate, VS4TEmployee.TEmpStatusPer, VS4TEmployee.TEmpBuddyCalcTAX, VS4TEmployee.TEmpTotalParent, VS4TEmployee.TEmpTotalFMCalc,                           VS4TEmployee.TEmpSoldierStatus, VS4TEmployee.TEmpChildStudy, VS4TEmployee.TEmpChildNotStudy, VS4TEmployee.TEmpCalcChildList, VS4TEmployee.TEmpCalcBuddy,                           VS4TEmployee.TEmpTPstCode, VS4TEmployee.TEmpTSecCode, VS4TEmployee.TEmpTDepCode, VS4TEmployee.TEmpTDivCode, VS4TEmployee.TEmpTBraCode, VS4TEmployee.TEmpPriority,                           VS4TEmployee.TEmpProbationDate, VS4TEmployee.TEmpScroll, VS4TEmployee.TEmpIsAdmin, VS4TEmployee.TEmpMainChange, VS4TEmployee.TEmpGradeLevel, VS4TEmployee.TEmpHeight,                           VS4TEmployee.TEmpWeight, VS4TEmployee.TEmpLastSalaryDate, VS4TEmployee.TEmpSalary, VS4TEmployee.TEmpCustom, VS4TEmployee.TEmpWTax, VS4TEmployee.TEmpSTAX,                           VS4TEmployee.TEmpSFund, VS4TEmployee.TEmpStartSFund, VS4TEmployee.TEmpFund, VS4TEmployee.TEmpEnableFUND, VS4TEmployee.TEmpStartFund, VS4TEmployee.TEmpApproveLimit,                           VS4TEmployee.TEmpApproveLimitM, VS4TEmployee.TEmpApproveLimitY, VS4TEmployee.TEmpTotalReduce, VS4TEmployee.TEmpCreateCode, VS4TEmployee.TEmpCreateDate,                           VS4TEmployee.TEmpEditCode, VS4TEmployee.TEmpEditDate, VS4TEmployee.TEmpTextSort, VS4TEmployee.TEmpFlag1, VS4TEmployee.TEmpFlag2, VS4TEmployee.TEmpFlag3,                           VS4TEmployee.TEmpTSAeCode, VS4TEmployee.TEmpRegisterDate, VS4TEmployee.TEmpTEmGCode, VS4TEmployee.TEmpBirthdayText, VS4TEmployee.TEmpCostGroup, VS4TEmployee.TEmpMode,                           VS4TEmployee.TEmpLineId, VS4TDivision.TDivName, VS4TDivision.TDivName2 FROM            VS4TUserEmployee LEFT OUTER JOIN                          VS4TEmployee LEFT OUTER JOIN                          VS4TDivision ON VS4TEmployee.TEmpTDivCode = VS4TDivision.TDivCode ON VS4TUserEmployee.TUsETEmpCode = VS4TEmployee.TEmpCode RIGHT OUTER JOIN                          VS4TUser ON VS4TUserEmployee.TUsETUsrID = VS4TUser.TUsrID
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 VS4VUserProject AS  SELECT VS4TUserProject.*, VS4TProject.*, VS4TUser.*, VS4TCommandGroup.* FROM VS4TUser INNER JOIN (VS4TCommandGroup INNER JOIN (VS4TUserProject INNER JOIN VS4TProject ON VS4TUserProject.TUPrTPrjCode = VS4TProject.TPrjCode) ON VS4TCommandGroup.TCmGAlias = VS4TUserProject.TUPrTCmGAlias) ON VS4TUser.TUsrID = VS4TUserProject.TUPrTUsrID
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, VS4TAR3_1.TAR3BirthDayValid AS VVSABirthDayValid, VS4TPlace.TPlaName, VS4TPlace.TPlaPhone, VS4TPlace.TPlaFax, VS4TPlace.TPlaEmail, VS4TProductBook.TPBGTPdtCode, VS4TSOImigration.* 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


