Пример #1
0
        private void SetupRepositoryMethods(ICollection <GLTran> glTrans,
                                            CurrencyInfo curyInfo,
                                            ICollection <TaxTran> taxTrans,
                                            DocumentIDGroup documentIDGroup,
                                            int?branchID,
                                            string taxPeriodID,
                                            string[] taxIDs,
                                            TaxCategoryDet taxCategoryDet)
        {
            GAFRepositoryMock.Setup(repo => repo.GetTaxableGLTransWithCuryInfoGroupedByDocumentAttrAndTaxCategory(branchID,
                                                                                                                  It.Is <string[]>(refNbrs => refNbrs.SequenceEqual(documentIDGroup.RefNbrs))))
            .Returns(glTrans.Select(glTran => new PXResult <GLTran, CurrencyInfo>(glTran, curyInfo)));

            GAFRepositoryMock.Setup(repo => repo.GetTaxTransForDocuments(documentIDGroup.Module,
                                                                         It.Is <string[]>(refNbrs => refNbrs.SequenceEqual(documentIDGroup.DocumentTypes)),
                                                                         It.Is <string[]>(refNbrs => refNbrs.SequenceEqual(documentIDGroup.RefNbrs)), taxPeriodID))
            .Returns(taxTrans);

            GAFRepositoryMock.Setup(repo => repo.GetTaxCategoryDetsForTaxIDs(It.Is <string[]>(pTaxIDs => pTaxIDs.SequenceEqual(taxIDs))))
            .Returns(taxCategoryDet.SingleToArray());
        }
        private void SetSOLineObjectsData(PrepareAndImportOrdersParams orderParams)
        {
            IEnumerable <SOFieldMapping> objMapping = orderParams.objliUsrMapping.Where(x => x.TargetObject == orderParams.objSOOrderEntry.Transactions.View.Name &&
                                                                                        x.TargetField.ToLower() == SOConstants.inventoryID.ToLower());

            if (objMapping.ToList().Count > 0)
            {
                foreach (OrderItem currentitem in orderParams.objamwLineItems)
                {
                    SOLine newitems = (SOLine)orderParams.objSOOrderEntry.Transactions.Cache.Insert();
                    foreach (SOFieldMapping data in orderParams.objliUsrMapping.Where(x => x.TargetObject == orderParams.objSOOrderEntry.Transactions.View.Name &&
                                                                                      x.TargetField.ToLower() == SOConstants.inventoryID.ToLower()))
                    {
                        if (data.SourceObject.ToLower().Trim() == SOConstants.orderItemTag.ToLower())
                        {
                            string fieldValue = currentitem != null?Convert.ToString(currentitem.GetType().GetProperty(data.SourceField).GetValue(currentitem, null)) : string.Empty;

                            string itemCode = SOLineInventoryItemAmazonExtAttribute.GetInventoryCode(orderParams.objSOOrderEntry.Transactions.Cache, fieldValue);

                            InventoryItem item = PXSelect <InventoryItem, Where <InventoryItem.inventoryCD, Equal <Required <InventoryItem.inventoryCD> >,
                                                                                 And <InventoryItem.itemStatus, Equal <InventoryItemStatus.active> > > > .Select(orderParams.objSOOrderEntry, itemCode);

                            newitems.InventoryID = item != null && item.InventoryID.HasValue ? item.InventoryID : null;
                            orderParams.objSOOrderEntry.Transactions.Update(newitems);
                            if (newitems.InventoryID.HasValue)
                            {
                                AssignValueAsPerIntegrationMapping(orderParams.objliUsrMapping, newitems, orderParams.ObjCurrentOrder, currentitem, orderParams.objSOOrderEntry.Transactions.View.Name);
                                //Embedd GiftPrice
                                string sGiftWrappPrice = currentitem.GiftWrapPrice != null?Convert.ToString(currentitem.GiftWrapPrice.Amount) : string.Empty;

                                newitems.CuryUnitPrice += String.IsNullOrEmpty(sGiftWrappPrice) ? 0m : Convert.ToDecimal(sGiftWrappPrice);

                                newitems.CuryUnitPrice = newitems.CuryUnitPrice > 0 && currentitem.QuantityOrdered > 0 ? newitems.CuryUnitPrice / currentitem.QuantityOrdered : newitems.CuryUnitPrice;
                                newitems.SiteID        = orderParams.objSOAmazonSetup.DfltWarehouseID;
                                SOSetupAmazonExt objSOOSetupext = orderParams.objSOOrderEntry.sosetup.Current.GetExtension <SOSetupAmazonExt>();
                                if (objSOOSetupext != null && !string.IsNullOrEmpty(objSOOSetupext.UsrAmazonTaxID))
                                {
                                    TaxCategoryDet objTaxDetails = PXSelect <TaxCategoryDet,
                                                                             Where <TaxCategoryDet.taxID, Equal <Required <Tax.taxID> > > >
                                                                   .Select(orderParams.objSOOrderEntry, objSOOSetupext.UsrAmazonTaxID);

                                    if (objTaxDetails != null)
                                    {
                                        newitems.TaxCategoryID = objTaxDetails.TaxCategoryID;
                                    }
                                    SOLineAmazonExt objnewitemsext = newitems.GetExtension <SOLineAmazonExt>();
                                    if (objnewitemsext != null)
                                    {
                                        objnewitemsext.UsrAMOrderItemID = currentitem.OrderItemId;
                                    }
                                    orderParams.objSOOrderEntry.Transactions.Update(newitems);
                                    FillDiscountObjectsData(orderParams.objSOOrderEntry, newitems, currentitem);

                                    taxtotal += currentitem.GiftWrapTax != null && !string.IsNullOrEmpty(currentitem.GiftWrapTax.Amount) && Convert.ToDecimal(currentitem.GiftWrapTax.Amount) > 0
                                             ? Convert.ToDecimal(currentitem.GiftWrapTax.Amount) : 0;

                                    taxtotal += currentitem.ItemTax != null && !string.IsNullOrEmpty(currentitem.ItemTax.Amount) && Convert.ToDecimal(currentitem.ItemTax.Amount) > 0
                                                 ? Convert.ToDecimal(currentitem.ItemTax.Amount) : 0;
                                    taxtotal += currentitem.ShippingTax != null && !string.IsNullOrEmpty(currentitem.ShippingTax.Amount) && Convert.ToDecimal(currentitem.ShippingTax.Amount) > 0
                                                ? Convert.ToDecimal(currentitem.ShippingTax.Amount) : 0;
                                    taxableamount += currentitem.ItemPrice != null && !string.IsNullOrEmpty(currentitem.ItemPrice.Amount) && Convert.ToDecimal(currentitem.ItemPrice.Amount) > 0
                                                    ? Convert.ToDecimal(currentitem.ItemPrice.Amount) : 0;
                                    shippingprice += currentitem.ShippingPrice != null && !string.IsNullOrEmpty(currentitem.ShippingPrice.Amount) && Convert.ToDecimal(currentitem.ShippingPrice.Amount) > 0
                                                    ? Convert.ToDecimal(currentitem.ShippingPrice.Amount) : 0;
                                    taxRate = (taxableamount > 0) ? (taxtotal * 100) / taxableamount : 0;
                                }
                                else
                                {
                                    throw new PXException(SOMessages.configMissing);
                                }
                            }
                            else
                            {
                                throw new PXException(SOMessages.inventoryItemNotExists);
                            }
                        }
                        else
                        {
                            throw new PXException(SOMessages.inventoryMappedtoOrderItem);
                        }
                    }
                }
            }
            else
            {
                throw new PXException(SOMessages.InvMappingErrorMsg);
            }
        }
Пример #3
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);
        }
Пример #4
0
        public void Test_CreateGAFRecordsForDocumentGroup_Batch_Contains_Two_RefNbrs()
        {
            //Arrange
            var taxID = _taxDataContext.VatTax.TaxID;

            var taxableGLTrans = new[]
            {
                new GLTran()
                {
                    TranDate      = TranDate,
                    TranDesc      = TranDesc,
                    BatchNbr      = BatchNbr,
                    RefNbr        = RefNbr,
                    TaxCategoryID = TaxCategoryID,
                    BranchID      = BranchID
                },
                new GLTran()
                {
                    TranDate      = TranDate2,
                    TranDesc      = TranDesc2,
                    BatchNbr      = BatchNbr,
                    RefNbr        = RefNbr2,
                    TaxCategoryID = TaxCategoryID,
                    BranchID      = BranchID
                },
            };

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

            var taxTrans = new[]
            {
                new TaxTran()
                {
                    Module         = BatchModule.GL,
                    TranType       = TaxTran.tranType.TranForward,
                    RefNbr         = BatchNbr,
                    TaxID          = taxID,
                    TaxableAmt     = 100,
                    TaxAmt         = 7,
                    CuryTaxableAmt = 200,
                    CuryTaxAmt     = 14,
                    TaxType        = CSTaxType.Sales,
                    LineRefNbr     = RefNbr,
                    BranchID       = BranchID
                },
                new TaxTran()
                {
                    Module         = BatchModule.GL,
                    TranType       = TaxTran.tranType.TranForward,
                    RefNbr         = BatchNbr,
                    TaxID          = taxID,
                    TaxableAmt     = 300,
                    TaxAmt         = 21,
                    CuryTaxableAmt = 600,
                    CuryTaxAmt     = 42,
                    TaxType        = CSTaxType.Sales,
                    LineRefNbr     = RefNbr2,
                    BranchID       = BranchID
                },
            };

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

            SetupRepositoryMethods(taxableGLTrans, curyInfo, taxTrans, documentIDGroup, BranchID,
                                   TaxPeriodID, taxID.SingleToArray(), taxCategoryDetail);

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

            //Assert
            Approvals.VerifyAll(recordsAggr.SupplyRecords, "supplyRecords", record => record.Dump());
        }
Пример #5
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);
        }