protected GAFRecordType GetRecordType(TaxTran taxTran, Tax tax)
 {
     if (taxTran.TaxType == CSTaxType.Use ||
         taxTran.TaxType == CSTaxType.Sales && tax.ReverseTax == true ||
         tax.TaxType == CSTaxType.Withholding)
     {
         return(GAFRecordType.Purchase);
     }
     else if (taxTran.TaxType == CSTaxType.Sales && tax.ReverseTax != true)
     {
         return(GAFRecordType.Supply);
     }
     else
     {
         throw new PXException(Messages.TheTypeOfGAFRecordPurchaseOrSupplyCannotBeDefined, taxTran);
     }
 }
Beispiel #2
0
        private PXResult <GLTran, CurrencyInfo> GetGLTranWithCuryInfo(TaxTran taxTran)
        {
            foreach (var taxCategoryDet in _taxCategoryDetsByTaxID[taxTran.TaxID])
            {
                var taxableGLTranKey = new TaxableGLTranKey()
                {
                    BranchID          = taxTran.BranchID,
                    RefNbr            = taxTran.LineRefNbr,
                    BatchNbr          = taxTran.RefNbr,
                    TaxableCategoryID = taxCategoryDet.TaxCategoryID
                };

                if (_taxableGLTransWithCuryInfo.ContainsKey(taxableGLTranKey))
                {
                    return(_taxableGLTransWithCuryInfo[taxableGLTranKey]);
                }
            }

            return(null);
        }
        protected override IList <PurchaseRecord> CreateGafRecordsForDocument(DocumentID documentId)
        {
            //we can not match old check to bill -- skip it.
            if (!_taxTransWithAdjdDocumentByRefNbrAndTaxID.ContainsKey(documentId.RefNbr))
            {
                return(new List <PurchaseRecord>());
            }

            var taxTransWithAdjdDocument = _taxTransWithAdjdDocumentByRefNbrAndTaxID[documentId.RefNbr].OrderBy(taxTranWithAdjdDocument => ((TaxTran)taxTranWithAdjdDocument).AdjdDocType)
                                           .ThenBy(taxTranWithAdjdDocument => ((TaxTran)taxTranWithAdjdDocument).AdjdRefNbr)
                                           .ThenBy(taxTranWithAdjdDocument => ((TaxTran)taxTranWithAdjdDocument).AdjNbr)
                                           .ThenBy(taxTranWithAdjdDocument => ((TaxTran)taxTranWithAdjdDocument).TaxID);

            var paymentRegister = DocumentsByRefNbr[documentId.RefNbr];

            var     lineNumberForGaf = 1;
            TaxTran prevTaxTran      = taxTransWithAdjdDocument.First();

            var purchaseRecords = new List <PurchaseRecord>();

            foreach (var taxTranWithAdjdDocument in taxTransWithAdjdDocument)
            {
                var taxTran = (TaxTran)taxTranWithAdjdDocument;
                var adjdDocumentRegister = (APRegister)taxTranWithAdjdDocument;

                if (taxTran.AdjdDocType != prevTaxTran.AdjdDocType ||
                    taxTran.AdjdRefNbr != prevTaxTran.AdjdRefNbr ||
                    taxTran.AdjNbr != prevTaxTran.AdjNbr)
                {
                    prevTaxTran = taxTran;
                    lineNumberForGaf++;
                }

                var gafRecord = _recordBuilderByTaxTranOfApPayment.Build(paymentRegister, taxTran,
                                                                         Contragents[paymentRegister.VendorID], lineNumberForGaf, adjdDocumentRegister.DocDesc);

                purchaseRecords.Add(gafRecord);
            }

            return(purchaseRecords);
        }
Beispiel #4
0
        public virtual void VoidReportProc(TaxTran taxTran)
        {
            using (new PXConnectionScope())
            {
                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    // Acuminator disable once PX1015 IncorrectNumberOfSelectParameters [Justification]
                    PXUpdate <
                        Set <TaxTran.taxPeriodID, Null,
                             Set <TaxTran.revisionID, Null> >,
                        TaxTran,
                        Where <TaxTran.vendorID, Equal <Required <TaxTran.vendorID> >,
                               And <TaxTran.taxPeriodID, Equal <Required <TaxTran.taxPeriodID> >,
                                    And <TaxTran.revisionID, Equal <Required <TaxTran.revisionID> >,
                                         And <TaxTran.released, Equal <True>,
                                              And <TaxTran.voided, Equal <False> > > > > > >
                    .Update(this, taxTran.VendorID, taxTran.TaxPeriodID);

                    ts.Complete(this);
                }
            }
        }
Beispiel #5
0
 public SupplyRecord Build(CAAdj caAdj, TaxTran taxTran, int gafLineNumber)
 {
     return(BuildInternal(caAdj, taxTran, gafLineNumber));
 }
Beispiel #6
0
        public DocumentRecordsAggregate Test_CreateGAFRecordsForDocumentGroup_For_Many_Documents_Taxes_And_TaxTrans(string docType)
        {
            //Arrange
            var vatTaxID  = TaxDataContext.VatTax.TaxID;
            var vatTaxID2 = TaxDataContext.VatTax2.TaxID;

            var taxDataItems = _arTaxDataBuilder.CreateTaxDataItems(new[]
            {
                vatTaxID,
                vatTaxID2
            });

            var taxAdjustments = new[]
            {
                new TX.TaxAdjustment()
                {
                    DocType = docType,
                    RefNbr  = DocumentDataContext.RefNbr,
                    DocDate = DocumentDataContext.DocDate,
                    CuryID  = DocumentDataContext.CuryIDGBP,
                    DocDesc = "doc1 desc"
                },
                new TX.TaxAdjustment()
                {
                    DocType = docType,
                    RefNbr  = DocumentDataContext.RefNbr2,
                    DocDate = DocumentDataContext.DocDate2,
                    CuryID  = DocumentDataContext.CuryIDEUR,
                    DocDesc = "doc2 desc"
                }
            };

            #region TaxTrans

            var taxTranRecordID = 1;

            var taxTrans = new TaxTran[]
            {
                //Tax Adjustment 1
                new TaxTran()
                {
                    RefNbr         = DocumentDataContext.RefNbr,
                    TaxID          = vatTaxID,
                    TaxableAmt     = 100,
                    TaxAmt         = 7,
                    CuryTaxableAmt = 200,
                    CuryTaxAmt     = 14,
                    RecordID       = taxTranRecordID++,
                    TaxType        = taxDataItems[0].TranTaxType
                },
                new TaxTran()
                {
                    RefNbr         = DocumentDataContext.RefNbr,
                    TaxID          = TaxDataContext.VatTax.TaxID,
                    TaxableAmt     = 150,
                    TaxAmt         = 10.5m,
                    CuryTaxableAmt = 300,
                    CuryTaxAmt     = 21,
                    RecordID       = taxTranRecordID++,
                    TaxType        = taxDataItems[0].TranTaxType
                },
                new TaxTran()
                {
                    RefNbr         = DocumentDataContext.RefNbr,
                    TaxID          = TaxDataContext.VatTax2.TaxID,
                    TaxableAmt     = 110,
                    TaxAmt         = 11,
                    CuryTaxableAmt = 220,
                    CuryTaxAmt     = 22,
                    RecordID       = taxTranRecordID++,
                    TaxType        = taxDataItems[1].TranTaxType
                },
                //Tax Adjustment 2
                new TaxTran()
                {
                    RefNbr         = DocumentDataContext.RefNbr2,
                    TaxID          = TaxDataContext.VatTax.TaxID,
                    TaxableAmt     = 400,
                    TaxAmt         = 28,
                    CuryTaxableAmt = 800,
                    CuryTaxAmt     = 56,
                    RecordID       = taxTranRecordID++,
                    TaxType        = taxDataItems[0].TranTaxType
                },
                new TaxTran()
                {
                    RefNbr         = DocumentDataContext.RefNbr2,
                    TaxID          = TaxDataContext.VatTax2.TaxID,
                    TaxableAmt     = 600,
                    TaxAmt         = 42,
                    CuryTaxableAmt = 1200,
                    CuryTaxAmt     = 84,
                    RecordID       = taxTranRecordID++,
                    TaxType        = taxDataItems[1].TranTaxType
                },
                new TaxTran()
                {
                    RefNbr         = DocumentDataContext.RefNbr2,
                    TaxID          = TaxDataContext.VatTax2.TaxID,
                    TaxableAmt     = 330,
                    TaxAmt         = 33,
                    CuryTaxableAmt = 660,
                    CuryTaxAmt     = 66,
                    RecordID       = taxTranRecordID++,
                    TaxType        = taxDataItems[1].TranTaxType
                },
            };

            #endregion

            var documentIDGroup = new DocumentIDGroup()
            {
                Module       = BatchModule.GL,
                DocumentType = docType,
                RefNbrs      = taxAdjustments.Select(taxAdj => taxAdj.RefNbr).ToList()
            };

            SetupRepositoryMethods(taxAdjustments, taxTrans, documentIDGroup, TaxPeriodID);

            //Action
            return(_taxAdjustmentGAFRecordsCreator.CreateGAFRecordsForDocumentGroup(documentIDGroup, BranchID, TaxPeriodID));
        }
Beispiel #7
0
        public void Test_CreateGAFRecordsForDocumentGroup_When_Document_Is_In_Base_Cury(string docType)
        {
            //Arrange
            TaxDataBuilderBase taxDataBuilder = null;

            taxDataBuilder = docType == TaxAdjustmentType.AdjustOutput
                                                                ? (TaxDataBuilderBase)GetService <ARTaxDataBuilder>()
                                                                : GetService <APTaxDataBuilder>();

            var taxData = taxDataBuilder.CreateTaxDataItems(TaxDataContext.VatTax.TaxID.SingleToArray())
                          .Single();

            const string docDesc = "doc1 desc";

            var taxAdjustment = new TX.TaxAdjustment()
            {
                DocType = docType,
                RefNbr  = DocumentDataContext.RefNbr,
                DocDate = DocumentDataContext.DocDate,
                CuryID  = CompanyDataContext.Company.BaseCuryID,
                DocDesc = docDesc
            };

            const decimal taxableAmt     = 100;
            const decimal taxAmt         = 7;
            const decimal curyTaxableAmt = 200;
            const decimal curyTaxAmt     = 14;

            var taxTran = new TaxTran()
            {
                RefNbr         = DocumentDataContext.RefNbr,
                TaxID          = taxData.TaxID,
                TaxableAmt     = taxableAmt,
                TaxAmt         = taxAmt,
                CuryTaxableAmt = curyTaxableAmt,
                CuryTaxAmt     = curyTaxAmt,
                TaxType        = taxData.TranTaxType
            };

            var documentIDGroup = new DocumentIDGroup()
            {
                Module       = BatchModule.GL,
                DocumentType = docType,
                RefNbrs      = taxAdjustment.RefNbr.SingleToList()
            };

            SetupRepositoryMethods(taxAdjustment.SingleToArray(), taxTran.SingleToArray(), documentIDGroup, TaxPeriodID);

            //Action
            var recordsAggr = _taxAdjustmentGAFRecordsCreator.CreateGAFRecordsForDocumentGroup(documentIDGroup, BranchID, TaxPeriodID);

            var gafRecord = taxAdjustment.DocType == TaxAdjustmentType.AdjustOutput
                                ? (GAFRecordBase)recordsAggr.SupplyRecords.Single()
                                : (GAFRecordBase)recordsAggr.PurchaseRecords.Single();

            //Assert
            Assert.Equal(taxableAmt, gafRecord.Amount);
            Assert.Equal(taxAmt, gafRecord.GSTAmount);
            Assert.Equal(ForeignCurrencyCodeForDocumentInBaseCury, gafRecord.ForeignCurrencyCode);
            Assert.Equal(0, gafRecord.ForeignCurrencyAmount);
            Assert.Equal(0, gafRecord.ForeignCurrencyAmountGST);
        }
Beispiel #8
0
        public void Test_CreateGAFRecordsForDocumentGroup_That_SupplyRecords_Are_Generated(string docType, string taxID)
        {
            //Arrange
            TaxDataBuilderBase taxDataBuilder = null;

            taxDataBuilder = docType == TaxAdjustmentType.AdjustOutput
                                                                ? (TaxDataBuilderBase)GetService <ARTaxDataBuilder>()
                                                                : GetService <APTaxDataBuilder>();

            var taxData = taxDataBuilder.CreateTaxDataItems(taxID.SingleToArray())
                          .Single();

            const string docDesc = "doc1 desc";

            var taxAdjustment = new TX.TaxAdjustment()
            {
                DocType = docType,
                RefNbr  = DocumentDataContext.RefNbr,
                DocDate = DocumentDataContext.DocDate,
                CuryID  = DocumentDataContext.CuryIDGBP,
                DocDesc = docDesc
            };

            const decimal taxableAmt     = 100;
            decimal       taxAmt         = taxableAmt / taxData.Rate;
            const decimal curyTaxableAmt = 200;
            decimal       curyTaxAmt     = curyTaxableAmt / taxData.Rate;

            var taxTran = new TaxTran()
            {
                RefNbr         = DocumentDataContext.RefNbr,
                TaxID          = taxData.TaxID,
                TaxableAmt     = taxableAmt,
                TaxAmt         = taxAmt,
                CuryTaxableAmt = curyTaxableAmt,
                CuryTaxAmt     = curyTaxAmt,
                TaxType        = taxData.TranTaxType
            };

            var documentIDGroup = new DocumentIDGroup()
            {
                Module       = BatchModule.GL,
                DocumentType = docType,
                RefNbrs      = taxAdjustment.RefNbr.SingleToList()
            };

            SetupRepositoryMethods(taxAdjustment.SingleToArray(), taxTran.SingleToArray(), documentIDGroup, TaxPeriodID);

            //Action
            var recordsAggr  = _taxAdjustmentGAFRecordsCreator.CreateGAFRecordsForDocumentGroup(documentIDGroup, BranchID, TaxPeriodID);
            var supplyRecord = recordsAggr.SupplyRecords.Single();

            //Assert
            Assert.Empty(recordsAggr.PurchaseRecords);
            Assert.NotEmpty(recordsAggr.SupplyRecords);

            Assert.Null(supplyRecord.CustomerName);
            Assert.Null(supplyRecord.CustomerBRN);
            Assert.Null(supplyRecord.Country);
            Assert.Equal(DocumentDataContext.DocDate, supplyRecord.InvoiceDate);
            Assert.Equal(DocumentDataContext.RefNbr, supplyRecord.InvoiceNumber);
            Assert.Equal(1, supplyRecord.LineNumber);
            Assert.Equal(docDesc, supplyRecord.ProductDescription);
            Assert.Equal(taxID, supplyRecord.TaxCode);
            Assert.Equal(DocumentDataContext.CuryIDGBP, supplyRecord.ForeignCurrencyCode);
            Assert.Equal(taxableAmt, supplyRecord.Amount);
            Assert.Equal(taxAmt, supplyRecord.GSTAmount);
            Assert.Equal(curyTaxableAmt, supplyRecord.ForeignCurrencyAmount);
            Assert.Equal(curyTaxAmt, supplyRecord.ForeignCurrencyAmountGST);
        }
 protected abstract TGAFRecord BuildGafRecordByTaxTranCalcedOnDocumentAmt(TDocument document, TaxTran taxTran, int gafLineNumber);
Beispiel #10
0
        public void Test_CreateGAFRecordsForDocumentGroup_That_PurchaseRecords_Are_Generated(string tranTaxType, string taxID)
        {
            //Arrange
            var rate = _taxRevDataContext.TaxRevs.Single(taxRev => taxRev.TaxID == taxID).TaxRate.Value;

            var taxableGLTran = new GLTran()
            {
                TranDate      = TranDate,
                TranDesc      = TranDesc,
                BatchNbr      = BatchNbr,
                RefNbr        = RefNbr,
                TaxCategoryID = TaxCategoryID,
                BranchID      = BranchID
            };

            var curyInfo = new CurrencyInfo()
            {
                CuryID = CuryIDEUR
            };
            var taxCategoryDetail = new TaxCategoryDet()
            {
                TaxID = taxID, TaxCategoryID = TaxCategoryID
            };

            const decimal taxableAmt     = 100;
            decimal       taxAmt         = taxableAmt / rate;
            const decimal curyTaxableAmt = 200;
            decimal       curyTaxAmt     = curyTaxableAmt / rate;

            var taxTran = new TaxTran()
            {
                Module         = BatchModule.GL,
                TranType       = TaxTran.tranType.TranForward,
                RefNbr         = BatchNbr,
                TaxID          = taxID,
                TaxableAmt     = taxableAmt,
                TaxAmt         = taxAmt,
                CuryTaxableAmt = curyTaxableAmt,
                CuryTaxAmt     = curyTaxAmt,
                TaxType        = tranTaxType,
                LineRefNbr     = RefNbr,
                BranchID       = BranchID
            };

            var documentIDGroup = new DocumentIDGroup()
            {
                Module  = BatchModule.GL,
                RefNbrs = taxTran.RefNbr.SingleToList()
            };

            SetupRepositoryMethods(taxableGLTran.SingleToArray(), curyInfo, taxTran.SingleToArray(), documentIDGroup, BranchID,
                                   TaxPeriodID, taxID.SingleToArray(), taxCategoryDetail);

            //Action
            var recordsAggr    = _glDocumentGAFRecordsCreator.CreateGAFRecordsForDocumentGroup(documentIDGroup, BranchID, TaxPeriodID);
            var purchaseRecord = recordsAggr.PurchaseRecords.Single();

            //Assert
            Assert.Empty(recordsAggr.SupplyRecords);
            Assert.NotEmpty(recordsAggr.PurchaseRecords);

            Assert.Null(purchaseRecord.SupplierName);
            Assert.Null(purchaseRecord.SupplierBRN);
            Assert.Null(purchaseRecord.ImportDeclarationNumber);
            Assert.Equal(TranDate, purchaseRecord.InvoiceDate);
            Assert.Equal(string.Concat(BatchNbr, RefNbr), purchaseRecord.InvoiceNumber);
            Assert.Equal(1, purchaseRecord.LineNumber);
            Assert.Equal(TranDesc, purchaseRecord.ProductDescription);
            Assert.Equal(taxID, purchaseRecord.TaxCode);
            Assert.Equal(CuryIDEUR, purchaseRecord.ForeignCurrencyCode);
            Assert.Equal(taxableAmt, purchaseRecord.Amount);
            Assert.Equal(taxAmt, purchaseRecord.GSTAmount);
            Assert.Equal(curyTaxableAmt, purchaseRecord.ForeignCurrencyAmount);
            Assert.Equal(curyTaxAmt, purchaseRecord.ForeignCurrencyAmountGST);
        }
Beispiel #11
0
        public void Test_CreateGAFRecordsForDocumentGroup_That_Sign_Is_Negative_When_Have_Reversed_Type(string tranTaxType)
        {
            //Arrange
            var taxID = _taxDataContext.VatTax.TaxID;

            var rate = _taxRevDataContext.TaxRevs.Single(taxRev => taxRev.TaxID == taxID).TaxRate.Value;

            var taxableGLTran = new GLTran()
            {
                TranDate      = TranDate,
                TranDesc      = TranDesc,
                BatchNbr      = BatchNbr,
                RefNbr        = RefNbr,
                TaxCategoryID = TaxCategoryID,
                BranchID      = BranchID
            };

            var curyInfo = new CurrencyInfo()
            {
                CuryID = CuryIDEUR
            };
            var taxCategoryDetail = new TaxCategoryDet()
            {
                TaxID = taxID, TaxCategoryID = TaxCategoryID
            };

            const decimal taxableAmt     = 100;
            decimal       taxAmt         = taxableAmt / rate;
            const decimal curyTaxableAmt = 200;
            decimal       curyTaxAmt     = curyTaxableAmt / rate;

            var taxTran = new TaxTran()
            {
                RefNbr         = BatchNbr,
                TaxID          = taxID,
                TaxableAmt     = taxableAmt,
                TaxAmt         = taxAmt,
                CuryTaxableAmt = curyTaxableAmt,
                CuryTaxAmt     = curyTaxAmt,
                TaxType        = tranTaxType,
                TranType       = TaxTran.tranType.TranReversed,
                LineRefNbr     = RefNbr,
                BranchID       = BranchID
            };

            var documentIDGroup = new DocumentIDGroup()
            {
                Module  = BatchModule.GL,
                RefNbrs = taxTran.RefNbr.SingleToList()
            };

            SetupRepositoryMethods(taxableGLTran.SingleToArray(), curyInfo, taxTran.SingleToArray(), documentIDGroup, BranchID,
                                   TaxPeriodID, taxID.SingleToArray(), taxCategoryDetail);

            //Action
            var recordsAggr = _glDocumentGAFRecordsCreator.CreateGAFRecordsForDocumentGroup(documentIDGroup, BranchID, TaxPeriodID);

            var gafRecord = tranTaxType == CSTaxType.Sales
                                ? (GAFRecordBase)recordsAggr.SupplyRecords.Single()
                                : (GAFRecordBase)recordsAggr.PurchaseRecords.Single();

            //Assert
            Assert.Equal(-taxableAmt, gafRecord.Amount);
            Assert.Equal(-taxAmt, gafRecord.GSTAmount);
            Assert.Equal(-curyTaxableAmt, gafRecord.ForeignCurrencyAmount);
            Assert.Equal(-curyTaxAmt, gafRecord.ForeignCurrencyAmountGST);
        }
 protected override PurchaseRecord BuildGafRecordByTaxTranCalcedOnDocumentAmt(APInvoice document, TaxTran taxTran, int gafLineNumber)
 {
     return(_recordBuilderByTaxTranForTaxCalcedOnDocumentAmt.Build(document, taxTran, Vendors[document.VendorID], gafLineNumber));
 }
 protected override SupplyRecord BuildGafRecordByTaxTranCalcedOnDocumentAmt(CAAdj document, TaxTran taxTran, int gafLineNumber)
 {
     return(_recordBuilderByTaxTranForTaxCalcedOnDocumentAmt.Build(document, taxTran, gafLineNumber));
 }
Beispiel #14
0
        public void Persist(PersistDelegate baseMethod)
        {
            baseMethod();

            if (skipPersist == false)
            {
                ARRegister    doc    = Base.ARDocument.Current;
                ARRegisterExt docExt = PXCache <ARRegister> .GetExtension <ARRegisterExt>(doc);

                // Check for document and released flag
                if (doc != null &&
                    doc.Released == true &&
                    doc.DocType.IsIn(ARDocType.Invoice, ARDocType.CreditMemo, ARDocType.CashSale) &&
                    ((string.IsNullOrEmpty(docExt.UsrGUINbr) && docExt.UsrVATOutCode == TWGUIFormatCode.vATOutCode36) || !string.IsNullOrEmpty(docExt.UsrVATOutCode))
                    )
                {
                    if (docExt.UsrVATOutCode.IsIn(TWGUIFormatCode.vATOutCode33, TWGUIFormatCode.vATOutCode34) &&
                        docExt.UsrCreditAction == TWNCreditAction.NO)
                    {
                        throw new PXException(TWMessages.CRACIsNone);
                    }
                    else if (docExt.UsrVATOutCode == TWGUIFormatCode.vATOutCode37)
                    {
                        throw new PXException(TWMessages.VATOutCodeIs37);
                    }

                    TaxTran xTran = APReleaseProcess_Extension.SelectTaxTran(Base, doc.DocType, doc.RefNbr, BatchModule.AR);

                    if (xTran == null)
                    {
                        throw new PXException(TWMessages.NoInvTaxDtls);
                    }

                    if (PXCache <Tax> .GetExtension <TaxExt>(Tax.PK.Find(Base, xTran.TaxID)).UsrTWNGUI != true)
                    {
                        return;
                    }

                    decimal?netAmt     = xTran.TaxableAmt + xTran.RetainedTaxableAmt;
                    decimal?taxAmt     = xTran.TaxAmt + xTran.RetainedTaxAmt;
                    decimal?remainNet  = netAmt;
                    decimal?remainTax  = taxAmt;
                    decimal?settledNet = 0;
                    decimal?settledTax = 0;

                    using (PXTransactionScope ts = new PXTransactionScope())
                    {
                        TWNReleaseProcess rp = PXGraph.CreateInstance <TWNReleaseProcess>();

                        Customer customer = SelectFrom <Customer> .Where <Customer.bAccountID.IsEqual <@P.AsInt> > .View.ReadOnly.Select(Base, doc.CustomerID);

                        string[] gUINbrs = !string.IsNullOrEmpty(docExt.UsrGUINbr) ? docExt.UsrGUINbr.Split(';') : new string[1] {
                            string.Empty
                        };

                        for (int i = 0; i < gUINbrs.Length; i++)
                        {
                            string gUINbr = gUINbrs[i].TrimStart();

                            // Avoid standard logic calling this method twice and inserting duplicate records into TWNGUITrans.
                            if (APReleaseProcess_Extension.CountExistedRec(Base, gUINbr, docExt.UsrVATOutCode, doc.RefNbr) > 0)
                            {
                                return;
                            }

                            TWNGUITrans tWNGUITrans = rp.InitAndCheckOnAR(gUINbr, docExt.UsrVATOutCode);

                            string taxCateID = string.Empty;

                            foreach (ARTran row in Base.ARTran_TranType_RefNbr.Cache.Cached)
                            {
                                taxCateID = row.TaxCategoryID;

                                goto CreatGUI;
                            }

CreatGUI:
                            if (docExt.UsrCreditAction.IsIn(TWNCreditAction.CN, TWNCreditAction.NO))
                            {
                                //TWNGUIPreferences gUIPreferences = SelectFrom<TWNGUIPreferences>.View.Select(Base);

                                //string numberingSeq = (docExt.UsrVATOutCode == TWGUIFormatCode.vATOutCode32) ? gUIPreferences.GUI2CopiesNumbering : gUIPreferences.GUI3CopiesNumbering;

                                //docExt.UsrGUINbr = ARGUINbrAutoNumAttribute.GetNextNumber(Base.ARDocument.Cache, doc, numberingSeq, doc.DocDate);

                                FSAppointment appointment = SelectFrom <FSAppointment> .LeftJoin <FSPostDoc> .On <FSPostDoc.appointmentID.IsEqual <FSAppointment.appointmentID> >
                                                            .Where <FSPostDoc.postDocType.IsEqual <@P.AsString>
                                                                    .And <FSPostDoc.postRefNbr.IsEqual <@P.AsString> > >
                                                            .View.ReadOnly.Select(Base, doc.DocType, doc.RefNbr);

                                if (tWNGUITrans != null)
                                {
                                    settledNet = (tWNGUITrans.NetAmtRemain < remainNet) ? tWNGUITrans.NetAmtRemain : remainNet;
                                    settledTax = (tWNGUITrans.TaxAmtRemain < remainTax) ? tWNGUITrans.TaxAmtRemain : remainTax;

                                    remainNet -= settledNet;
                                    remainTax -= settledTax;
                                }
                                else
                                {
                                    settledNet = remainNet;
                                    settledTax = remainTax;
                                }

                                rp.CreateGUITrans(new STWNGUITran()
                                {
                                    VATCode       = docExt.UsrVATOutCode,
                                    GUINbr        = gUINbr ?? string.Empty,
                                    GUIStatus     = doc.CuryOrigDocAmt == 0m ? TWNGUIStatus.Voided : TWNGUIStatus.Used,
                                    BranchID      = doc.BranchID,
                                    GUIDirection  = TWNGUIDirection.Issue,
                                    GUIDate       = docExt.UsrGUIDate.Value.Date.Add(doc.CreatedDateTime.Value.TimeOfDay),
                                    GUITitle      = customer.AcctName,
                                    TaxZoneID     = Base.ARInvoice_DocType_RefNbr.Current.TaxZoneID,
                                    TaxCategoryID = taxCateID,
                                    TaxID         = xTran.TaxID,
                                    TaxNbr        = docExt.UsrTaxNbr,
                                    OurTaxNbr     = docExt.UsrOurTaxNbr,
                                    NetAmount     = settledNet < 0 ? 0 : settledNet,
                                    TaxAmount     = settledTax < 0 ? 0 : settledTax,
                                    AcctCD        = customer.AcctCD,
                                    AcctName      = customer.AcctName,
                                    Remark        = (appointment is null) ? string.Empty : appointment.RefNbr,
                                    BatchNbr      = doc.BatchNbr,
                                    OrderNbr      = doc.RefNbr,
                                    CarrierType   = GetCarrierType(docExt.UsrCarrierID),
                                    CarrierID     = docExt.UsrB2CType == TWNB2CType.MC ? GetCarrierID(docExt.UsrTaxNbr, docExt.UsrCarrierID) : null,
                                    NPONbr        = docExt.UsrB2CType == TWNB2CType.NPO ? GetNPOBAN(docExt.UsrTaxNbr, docExt.UsrNPONbr) : null,
                                    B2CPrinted    = (docExt.UsrB2CType == TWNB2CType.DEF && string.IsNullOrEmpty(docExt.UsrTaxNbr)) ? true : false,
                                });
Beispiel #15
0
 protected override SupplyRecord BuildGafRecordByTaxTranCalcedOnDocumentAmt(ARInvoice document, TaxTran taxTran, int gafLineNumber)
 {
     return(_recordBuilderByTaxTranForTaxCalcedOnDocumentAmt.Build(GetExtendedInvoice(document), document, taxTran,
                                                                   Customers[document.CustomerID], gafLineNumber));
 }