Ejemplo n.º 1
0
        public void Test_CreateGAFRecordsForDocumentGroup_When_Check_Has_Many_Applications_With_Two_Taxes()
        {
            //Arrange
            var taxAgencyID = _vendorDataContext.TaxAgency.BAccountID;
            var taxPeriodID = _taxPeriodDataContext.TaxPeriod.TaxPeriodID;

            var adjdDocumentsRawData = new List <object[]>()
            {
                //			DocType,				RefNbr,		expected gaf line number
                new object[] { APDocType.Invoice, "BILL1", 2 },
                new object[] { APDocType.Invoice, "BILL2", 3 },
                new object[] { APDocType.CreditAdj, "CRADJ1", 1 },
            };

            var paymentAggrBuilder = new APRegisterAggregateBuilder()
                                     .CreateDocument(APDocType.Check,
                                                     DocumentDataContext.RefNbr,
                                                     DocumentDataContext.DocDate,
                                                     CompanyDataContext.Company.BaseCuryID)
                                     .DocumentWith(vendorID: _vendorDataContext.Vendor.BAccountID,
                                                   vendorLocationID: _locationDataContext.VendorLocation.LocationID);

            var adjdRegisters = new List <APRegister>();

            var taxIDs = new string[]
            {
                TaxDataContext.WithholdingTax.TaxID,
                TaxDataContext.WithholdingTax2.TaxID
            };

            foreach (var adjdDocumentRawData in adjdDocumentsRawData)
            {
                foreach (var taxID in taxIDs)
                {
                    paymentAggrBuilder.AddTaxTran(new TaxTran()
                    {
                        TaxableAmt     = 0,
                        TaxAmt         = 0,
                        CuryTaxableAmt = 0,
                        CuryTaxAmt     = 0,
                        AdjdDocType    = (string)adjdDocumentRawData[0],
                        AdjdRefNbr     = (string)adjdDocumentRawData[1],
                        TaxID          = taxID
                    });
                }

                adjdRegisters.Add(new APRegister()
                {
                    DocType = (string)adjdDocumentRawData[0],
                    RefNbr  = (string)adjdDocumentRawData[1],
                    DocDesc = (string)adjdDocumentRawData[1],                    //to identify gaf record on asserting
                });
            }

            var paymentAggr  = paymentAggrBuilder.Build();
            var paymentAggrs = paymentAggr.SingleToArray();

            SetupRepositoryMethods(paymentAggrs, adjdRegisters, paymentAggr.Document.OrigModule, paymentAggr.Document.DocType, taxAgencyID, taxPeriodID);

            var documentGroup = new DocumentGroup <AP.APRegister>()
            {
                Module            = paymentAggr.Document.OrigModule,
                DocumentType      = paymentAggr.Document.DocType,
                DocumentsByRefNbr = paymentAggrs.ToDictionary(aggr => aggr.Document.RefNbr, aggr => aggr.Document)
            };

            //Action
            var purchaseRecords = ApPaymentGAFRecordsCreator.CreateGAFRecordsForDocumentGroup(documentGroup, taxAgencyID,
                                                                                              taxPeriodID);

            //Assert
            foreach (var purchaseRecord in purchaseRecords)
            {
                var adjdDocumentRawData = adjdDocumentsRawData.Single(data => data[1] == purchaseRecord.ProductDescription);

                Assert.Equal(adjdDocumentRawData[2], purchaseRecord.LineNumber);
            }
        }