Пример #1
0
        private static void CAExpense_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
        {
            var expense = (CAExpense)e.Row;

            if (string.IsNullOrEmpty(expense.AdjRefNbr))
            {
                return;
            }

            CAAdj adj = PXSelect <CAAdj, Where <CAAdj.adjTranType, Equal <CATranType.cATransferExp>, And <CAAdj.adjRefNbr, Equal <Required <CAExpense.adjRefNbr> > > > > .Select(sender.Graph, expense.AdjRefNbr);

            CASplit split = PXSelect <CASplit, Where <CASplit.adjTranType, Equal <CATranType.cATransferExp>, And <CASplit.adjRefNbr, Equal <Required <CAExpense.adjRefNbr> >,
                                                                                                                  And <CASplit.lineNbr, Equal <one> > > > > .Select(sender.Graph, expense.AdjRefNbr);

            adj.EntryTypeID     = expense.EntryTypeID;
            split.AccountID     = expense.AccountID;
            split.SubID         = expense.SubID;
            split.CuryUnitPrice = expense.CuryTranAmt;
            split.CuryTranAmt   = expense.CuryTranAmt;
            split.TranAmt       = expense.TranAmt;
            adj.DrCr            = expense.DrCr;
            adj.CuryTranAmt     = expense.CuryTranAmt;
            adj.TranAmt         = expense.TranAmt;
            adj.CuryControlAmt  = expense.CuryTranAmt;
            adj.ControlAmt      = expense.TranAmt;
            adj.TranDate        = expense.TranDate;
            adj.TranPeriodID    = expense.TranPeriodID;
            adj.TranDesc        = expense.TranDesc;
            adj.ExtRefNbr       = expense.ExtRefNbr;

            sender.Graph.Caches[typeof(CASplit)].Update(split);
            sender.Graph.Caches[typeof(CAAdj)].Update(adj);
        }
Пример #2
0
        protected override void SetExtCostExt(PXCache sender, object child, decimal?value)
        {
            CASplit row = child as CASplit;

            if (row != null)
            {
                row.CuryTranAmt = value;
                sender.Update(row);
            }
        }
        protected virtual GetTaxRequest BuildGetTaxRequest(CAAdj invoice)
        {
            if (invoice == null)
            {
                throw new PXArgumentException(nameof(invoice), ErrorMessages.ArgumentNullException);
            }

            GetTaxRequest request = new GetTaxRequest();

            request.CompanyCode  = CompanyCodeFromBranch(invoice.TaxZoneID, invoice.BranchID);
            request.CurrencyCode = invoice.CuryID;
            request.CustomerCode = "N/A";
            IAddressBase fromAddress = GetToAddress(invoice);
            IAddressBase toAddress   = fromAddress;

            if (fromAddress == null)
            {
                throw new PXException(Messages.FailedGetFrom);
            }

            if (toAddress == null)
            {
                throw new PXException(Messages.FailedGetTo);
            }

            request.OriginAddress      = AddressConverter.ConvertTaxAddress(fromAddress);
            request.DestinationAddress = AddressConverter.ConvertTaxAddress(toAddress);
            request.DocCode            = $"CA.{invoice.AdjRefNbr}";
            request.DocDate            = invoice.TranDate.GetValueOrDefault();
            request.LocationCode       = GetExternalTaxProviderLocationCode(invoice);
            Location branchLoc = GetBranchLocation(invoice);

            if (branchLoc != null)
            {
                request.CustomerUsageType = branchLoc.CAvalaraCustomerUsageType;
                request.ExemptionNo       = branchLoc.CAvalaraExemptionNumber;
            }

            request.DocType = TaxDocumentType.PurchaseInvoice;
            int mult = 1;

            if (invoice.DrCr == CADrCr.CADebit)
            {
                request.DocType = TaxDocumentType.SalesInvoice;
            }
            else
            {
                request.DocType = TaxDocumentType.PurchaseInvoice;
            }

            PXSelectBase <CASplit> select = new PXSelectJoin <CASplit,
                                                              LeftJoin <InventoryItem, On <InventoryItem.inventoryID, Equal <CASplit.inventoryID> > >,
                                                              Where <CASplit.adjRefNbr, Equal <Current <CAAdj.adjRefNbr> > >,
                                                              OrderBy <Asc <CASplit.adjRefNbr, Asc <CASplit.lineNbr> > > >(Base);

            foreach (PXResult <CASplit, InventoryItem> res in select.View.SelectMultiBound(new object[] { invoice }))
            {
                CASplit       tran = (CASplit)res;
                InventoryItem item = (InventoryItem)res;

                var line = new TaxCartItem
                {
                    Index              = tran.LineNbr ?? 0,
                    Amount             = mult * tran.CuryTranAmt.GetValueOrDefault(),
                    Description        = tran.TranDesc,
                    DestinationAddress = request.DestinationAddress,
                    OriginAddress      = request.OriginAddress,
                    ItemCode           = item.InventoryCD,
                    Quantity           = Math.Abs(tran.Qty.GetValueOrDefault()),
                    Discounted         = request.Discount > 0,
                    TaxCode            = tran.TaxCategoryID,
                };

                request.CartItems.Add(line);
            }

            return(request);
        }