Пример #1
0
        protected virtual IEnumerable Cancel(PXAdapter adapter)
        {
            VendorLocation vendor = this.BAccount.Current;

            if (vendor != null && adapter.Searches.Length == 2 && adapter.Searches[0] != null && vendor.AcctCD != null)
            {
                if (vendor.AcctCD.Trim() != adapter.Searches[0].ToString().Trim())
                {
                    PXResult <BAccountR, CRLocation> r =
                        (PXResult <BAccountR, CRLocation>) PXSelectJoin <BAccountR,
                                                                         InnerJoin <CRLocation, On <CRLocation.bAccountID, Equal <BAccountR.bAccountID>, And <CRLocation.locationID, Equal <BAccountR.defLocationID> > > >,
                                                                         Where <BAccountR.acctCD, Equal <Required <BAccountR.acctCD> > > >
                        .SelectWindowed(this, 0, 1, adapter.Searches[0]);

                    CRLocation location = r;
                    adapter.Searches[1] = location.LocationCD;
                }
            }

            foreach (VendorLocation i in (new PXCancel <VendorLocation>(this, "Cancel")).Press(adapter))
            {
                yield return(i);
            }
        }
Пример #2
0
        public static void CreatePayments(List <ARRegister> list, ARWriteOffFilter filter)
        {
            if (string.IsNullOrEmpty(filter.ReasonCode))
            {
                throw new PXException(Messages.ReasonCodeIsRequired);
            }

            bool failed = false;

            IARWriteOffEntry pe = null;

            if (filter.WOType == ARDocType.SmallBalanceWO)
            {
                pe = PXGraph.CreateInstance <ARSmallBalanceWriteOffEntry>();
            }
            else
            {
                pe = PXGraph.CreateInstance <ARSmallCreditWriteOffEntry>();
            }

            List <ARRegister> orig = list;

            list = new List <ARRegister>(orig);

            List <ARRegister> paylist = new List <ARRegister>();
            List <int>        paybind = new List <int>();

            var cache = (pe as PXGraph).Caches[typeof(ARRegisterEx)];

            list = list.OrderBy(doc => new Tuple <string, string, string, string, string>(
                                    (string)(cache.GetValueExt <ARRegisterEx.branchID>(doc) as PXFieldState).Value,
                                    doc.CuryID,
                                    (string)(cache.GetValueExt <ARRegisterEx.customerID>(doc) as PXFieldState).Value,
                                    doc.DocType,
                                    doc.RefNbr
                                    )).ToList();

            for (int i = 0; i < list.Count; i++)
            {
                ARRegisterEx doc = (ARRegisterEx)list[i];
                int          idx = orig.IndexOf(doc);
                try
                {
                    ReasonCode reasonCode = PXSelect <ReasonCode, Where <ReasonCode.reasonCodeID, Equal <Required <ReasonCode.reasonCodeID> > > > .Select((PXGraph)pe, doc.ReasonCode ?? filter.ReasonCode);

                    if (reasonCode == null)
                    {
                        throw new PXException(PXMessages.LocalizeFormatNoPrefixNLA(Messages.ReasonCodeNotFound, filter.ReasonCode));
                    }

                    Location customerLocation = PXSelect <Location, Where <Location.bAccountID, Equal <Required <Location.bAccountID> >,
                                                                           And <Location.locationID, Equal <Required <Location.locationID> > > > > .Select((PXGraph)pe, doc.CustomerID, doc.CustomerLocationID);

                    CRLocation companyLocation = PXSelectJoin <CRLocation,
                                                               InnerJoin <BAccountR, On <CRLocation.bAccountID, Equal <BAccountR.bAccountID>, And <CRLocation.locationID, Equal <BAccountR.defLocationID> > >,
                                                                          InnerJoin <GL.Branch, On <BAccountR.bAccountID, Equal <GL.Branch.bAccountID> > > >, Where <Branch.branchID, Equal <Required <Branch.branchID> > > > .Select((PXGraph)pe, doc.BranchID);

                    object value = null;
                    if (reasonCode.Usage == ReasonCodeUsages.BalanceWriteOff || reasonCode.Usage == ReasonCodeUsages.CreditWriteOff)
                    {
                        value = ReasonCodeSubAccountMaskAttribute.MakeSub <ReasonCode.subMask>((PXGraph)pe, reasonCode.SubMask,
                                                                                               new object[] { reasonCode.SubID, customerLocation.CSalesSubID, companyLocation.CMPSalesSubID },
                                                                                               new Type[] { typeof(ReasonCode.subID), typeof(Location.cSalesSubID), typeof(CRLocation.cMPSalesSubID) });
                    }
                    else
                    {
                        throw new PXException(Messages.InvalidReasonCode);
                    }

                    ARReleaseProcess.EnsureNoUnreleasedVoidPaymentExists((pe as PXGraph), doc, Common.Messages.ActionWrittenOff);
                    pe.CreateWriteOff(reasonCode, value.ToString(), filter.WODate, filter.WOFinPeriodID, doc);

                    if (pe.ARDocument != null && !paylist.Contains(pe.ARDocument))
                    {
                        paylist.Add(pe.ARDocument);
                        paybind.Add(idx);
                    }
                }
                catch (Exception e)
                {
                    PXProcessing <ARRegister> .SetError(idx, e);

                    failed = true;
                }
            }

            if (paylist.Count > 0)
            {
                try
                {
                    ARDocumentRelease.ReleaseDoc(paylist, false);
                }
                catch (PXMassProcessException e)
                {
                    PXProcessing <ARRegister> .SetError(paybind[e.ListIndex], e.InnerException);

                    failed = true;
                }
            }

            if (failed)
            {
                throw new PXException(GL.Messages.DocumentsNotReleased);
            }
        }
        protected virtual GetTaxRequest BuildTaxRequest(APInvoice invoice)
        {
            if (invoice == null)
            {
                throw new PXArgumentException(nameof(invoice), ErrorMessages.ArgumentNullException);
            }

            Vendor vend = (Vendor)Base.vendor.View.SelectSingleBound(new object[] { invoice });

            var request = new PX.TaxProvider.GetTaxRequest();

            request.CompanyCode  = CompanyCodeFromBranch(invoice.TaxZoneID, invoice.BranchID);
            request.CurrencyCode = invoice.CuryID;
            request.CustomerCode = vend.AcctCD;
            IAddressBase fromAddress = GetFromAddress(invoice);
            IAddressBase toAddress   = GetToAddress(invoice);

            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            = $"AP.{invoice.DocType}.{invoice.RefNbr}";
            request.DocDate            = invoice.DocDate.GetValueOrDefault();
            request.LocationCode       = GetExternalTaxProviderLocationCode(invoice);

            Location branchLoc = GetBranchLocation(invoice);

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

            request.DocType = GetTaxDocumentType(invoice);
            Sign sign = GetDocumentSign(invoice);

            PXSelectBase <APTran> select = new PXSelectJoin <APTran,
                                                             LeftJoin <InventoryItem, On <InventoryItem.inventoryID, Equal <APTran.inventoryID> >,
                                                                       LeftJoin <Account, On <Account.accountID, Equal <APTran.accountID> > > >,
                                                             Where <APTran.tranType, Equal <Current <APInvoice.docType> >,
                                                                    And <APTran.refNbr, Equal <Current <APInvoice.refNbr> >,
                                                                         And <APTran.lineType, NotEqual <SOLineType.discount> > > >,
                                                             OrderBy <Asc <APTran.tranType, Asc <APTran.refNbr, Asc <APTran.lineNbr> > > > >(Base);

            request.Discount = GetDocDiscount().GetValueOrDefault();
            foreach (PXResult <APTran, InventoryItem, Account> res in select.View.SelectMultiBound(new object[] { invoice }))
            {
                APTran        tran         = (APTran)res;
                InventoryItem item         = (InventoryItem)res;
                Account       salesAccount = (Account)res;

                var line = new TaxCartItem();
                line.Index              = tran.LineNbr.GetValueOrDefault();
                line.Amount             = sign * tran.CuryTranAmt.GetValueOrDefault();
                line.Description        = tran.TranDesc;
                line.OriginAddress      = AddressConverter.ConvertTaxAddress(GetFromAddress(invoice, tran));
                line.DestinationAddress = AddressConverter.ConvertTaxAddress(GetToAddress(invoice, tran));
                line.ItemCode           = item.InventoryCD;
                line.Quantity           = Math.Abs(tran.Qty.GetValueOrDefault());
                line.Discounted         = request.Discount > 0;
                line.RevAcct            = salesAccount.AccountCD;

                line.TaxCode = tran.TaxCategoryID;

                request.CartItems.Add(line);
            }

            if (invoice.DocType == APDocType.DebitAdj && (invoice.OrigDocDate != null))
            {
                request.TaxOverride.Reason          = Messages.DebitAdjustmentReason;
                request.TaxOverride.TaxDate         = invoice.OrigDocDate.Value;
                request.TaxOverride.TaxOverrideType = PX.TaxProvider.TaxOverrideType.TaxDate;
            }

            return(request);
        }