Beispiel #1
0
		protected override void CalcTotals(PXCache sender, object row, bool CalcTaxes)
		{
			string taxZondeID = GetTaxZone(sender, row);
			bool isExternalTax = ExternalTax.IsExternalTax(sender.Graph, taxZondeID);

			bool doCalc = _NoSumTotals == false && CalcTaxes && !isExternalTax;
			if (doCalc && (ParentCache(sender.Graph).Current != null || _ParentRow != null))
			{
				ResetDiscrepancy(sender.Graph);
			}
			base.CalcTotals(sender, row, doCalc);
		}
Beispiel #2
0
            public void Post(Document doc)
            {
                if (!TaxPluginMaint.IsActive(this, doc.TaxZoneID))
                {
                    throw new PXException(Messages.ExternalTaxProviderNotConfigured);
                }

                var service = TaxProviderFactory(this, doc.TaxZoneID);

                var request = new CommitTaxRequest();

                request.CompanyCode = ExternalTax.CompanyCodeFromBranch(this, doc.TaxZoneID, doc.BranchID);
                request.DocCode     = string.Format("{0}.{1}.{2}", doc.Module, doc.DocType, doc.RefNbr);

                request.DocType = GetTaxDocumentType(doc);

                CommitTaxResult result    = service.CommitTax(request);
                bool            setPosted = false;

                if (result.IsSuccess)
                {
                    setPosted = true;
                }
                else
                {
                    //Avalara retuned an error - The given document is already marked as posted on the avalara side.
                    //Just fix the discrepency by setting the IsTaxPosted=1 in the acumatica document. Do not return this as an error to the user.
                    if (!result.IsSuccess && result.Messages.Any(t => t.Contains("Expected Posted")))
                    {
                        setPosted = true;
                    }
                }

                if (setPosted)
                {
                    if (doc.Module == BatchModule.AP)
                    {
                        PXDatabase.Update <AP.APRegister>(
                            new PXDataFieldAssign("IsTaxPosted", true),
                            new PXDataFieldRestrict("DocType", PXDbType.Char, 3, doc.DocType, PXComp.EQ),
                            new PXDataFieldRestrict("RefNbr", PXDbType.NVarChar, 15, doc.RefNbr, PXComp.EQ)
                            );
                    }
                    else if (doc.Module == BatchModule.AR)
                    {
                        PXDatabase.Update <AR.ARRegister>(
                            new PXDataFieldAssign("IsTaxPosted", true),
                            new PXDataFieldRestrict("DocType", PXDbType.Char, 3, doc.DocType, PXComp.EQ),
                            new PXDataFieldRestrict("RefNbr", PXDbType.NVarChar, 15, doc.RefNbr, PXComp.EQ)
                            );
                    }
                    else if (doc.Module == BatchModule.CA)
                    {
                        PXDatabase.Update <CA.CAAdj>(
                            new PXDataFieldAssign("IsTaxPosted", true),
                            new PXDataFieldRestrict("AdjRefNbr", PXDbType.NVarChar, 15, doc.RefNbr, PXComp.EQ)
                            );
                    }
                }
                else
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (var msg in result.Messages)
                    {
                        sb.AppendLine(msg);
                    }

                    throw new PXException(sb.ToString());
                }
            }