protected virtual void CancelTax(CAAdj invoice, VoidReasonCode code)
        {
            var request = new VoidTaxRequest();

            request.CompanyCode = CompanyCodeFromBranch(invoice.TaxZoneID, invoice.BranchID);
            request.Code        = code;
            request.DocCode     = $"CA.{invoice.AdjRefNbr}";

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

            var service = TaxProviderFactory(Base, invoice.TaxZoneID);
            var result  = service.VoidTax(request);

            bool raiseError = false;

            if (!result.IsSuccess)
            {
                LogMessages(result);

                if (result.Messages.Any(t
                                        => t.Contains("DocumentNotFoundError") ||
                                        t.Contains("The tax document could not be found.")))
                {
                    //just ignore this error. There is no document to delete in avalara.
                }
                else
                {
                    raiseError = true;
                }
            }

            if (raiseError)
            {
                throw new PXException(TX.Messages.FailedToDeleteFromExternalTaxProvider);
            }
            else
            {
                invoice.IsTaxSaved = false;
                invoice.IsTaxValid = false;
                if (Base.CAAdjRecords.Cache.GetStatus(invoice) == PXEntryStatus.Notchanged)
                {
                    Base.CAAdjRecords.Cache.SetStatus(invoice, PXEntryStatus.Updated);
                }
            }
        }
Ejemplo n.º 2
0
        public virtual void CancelTax(ARInvoice invoice, VoidReasonCode code)
        {
            string taxZoneID = ARInvoice.PK.Find(Base, invoice)?.TaxZoneID ?? invoice.TaxZoneID;

            var request = new VoidTaxRequest();

            request.CompanyCode = CompanyCodeFromBranch(taxZoneID, invoice.BranchID);
            request.Code        = code;
            request.DocCode     = $"AR.{invoice.DocType}.{invoice.RefNbr}";
            request.DocType     = GetTaxDocumentType(invoice);

            var service = ExternalTax.TaxProviderFactory(Base, taxZoneID);
            var result  = service.VoidTax(request);

            bool raiseError = false;

            if (!result.IsSuccess)
            {
                LogMessages(result);

                if (result.Messages.Any(t
                                        => t.Contains("DocumentNotFoundError") ||
                                        t.Contains("The tax document could not be found.")))
                {
                    //just ignore this error. There is no document to delete in avalara.
                }
                else
                {
                    raiseError = true;
                }
            }

            if (raiseError)
            {
                throw new PXException(TX.Messages.FailedToDeleteFromExternalTaxProvider);
            }
            else
            {
                invoice.IsTaxSaved = false;
                invoice.IsTaxValid = false;
                if (Base.Document.Cache.GetStatus(invoice) == PXEntryStatus.Notchanged)
                {
                    Base.Document.Cache.SetStatus(invoice, PXEntryStatus.Updated);
                }
            }
        }