Ejemplo n.º 1
0
        public void ReleaseDocProc(JournalEntry je, INRegister doc, INReleaseProcess_Extension.ReleaseDocProcDelegate baseMethod)
        {
            baseMethod(je, doc);

            foreach (INTranSplit row in this.Base.intransplit.Cache.Cached)
            {
                INTranSplit tranSplit = SelectINTranRcpSplit(Base, row.LotSerialNbr, row.InventoryID, row.SubItemID, row.SiteID, row.LocationID);

                if (tranSplit != null && row.DocType != INDocType.Receipt)
                {
                    INTranSplitExt tranSplitExt = tranSplit.GetExtension <INTranSplitExt>();

                    Base.intransplit.Cache.SetValue <INTranSplitExt.usrCOO>(row, tranSplitExt.UsrCOO);
                    Base.intransplit.Cache.SetValue <INTranSplitExt.usrDateCode>(row, tranSplitExt.UsrDateCode);
                }
                else
                {
                    SOShipLineSplit lineSplit = SelectSOShipLineSplit(Base, row.LotSerialNbr, row.InventoryID, row.SubItemID, row.SiteID, row.LocationID);

                    if (lineSplit == null)
                    {
                        continue;
                    }

                    SOShipLineSplitExt lineSplitExt = lineSplit.GetExtension <SOShipLineSplitExt>();

                    Base.intransplit.Cache.SetValue <INTranSplitExt.usrCOO>(row, lineSplitExt.UsrCOO);
                    Base.intransplit.Cache.SetValue <INTranSplitExt.usrDateCode>(row, lineSplitExt.UsrDateCode);
                }

                Base.Caches[typeof(INTranSplit)].PersistUpdated(this.Base.Caches[typeof(INTranSplit)].Update(row));

                PXTimeStampScope.PutPersisted(this.Base.Caches[typeof(INTranSplit)], row, PXDatabase.SelectTimeStamp());
            }
        }
        public virtual PMProforma CalculateExternalTax(PMProforma doc, bool forceRecalculate)
        {
            var toAddress = GetToAddress(doc);

            GetTaxRequest getRequest       = null;
            bool          isValidByDefault = true;

            if ((doc.IsTaxValid != true || forceRecalculate) && !IsNonTaxable(toAddress))
            {
                getRequest = BuildGetTaxRequest(doc);

                if (getRequest.CartItems.Count > 0)
                {
                    isValidByDefault = false;
                }
                else
                {
                    getRequest = null;
                }
            }

            if (isValidByDefault)
            {
                doc.CuryTaxTotal = 0;
                doc.IsTaxValid   = true;
                Base.Document.Update(doc);

                foreach (PMTaxTran item in Base.Taxes.Select())
                {
                    Base.Taxes.Delete(item);
                }

                using (var ts = new PXTransactionScope())
                {
                    Base.Persist(typeof(PMTaxTran), PXDBOperation.Delete);
                    Base.Persist(typeof(PMProforma), PXDBOperation.Update);
                    PXTimeStampScope.PutPersisted(Base.Document.Cache, doc, PXDatabase.SelectTimeStamp());
                    ts.Complete();
                }
                return(doc);
            }

            GetTaxResult result       = null;
            var          service      = TaxProviderFactory(Base, doc.TaxZoneID);
            bool         getTaxFailed = false;

            if (getRequest != null)
            {
                result = service.GetTax(getRequest);
                if (!result.IsSuccess)
                {
                    getTaxFailed = true;
                }
            }

            if (!getTaxFailed)
            {
                try
                {
                    ApplyTax(doc, result);
                    using (var ts = new PXTransactionScope())
                    {
                        doc.IsTaxValid = true;
                        Base.Document.Update(doc);
                        Base.Persist(typeof(PMProforma), PXDBOperation.Update);
                        PXTimeStampScope.PutPersisted(Base.Document.Cache, doc, PXDatabase.SelectTimeStamp());
                        ts.Complete();
                    }
                }
                catch (PXOuterException ex)
                {
                    string msg = TX.Messages.FailedToApplyTaxes;
                    foreach (string err in ex.InnerMessages)
                    {
                        msg += Environment.NewLine + err;
                    }

                    throw new PXException(ex, msg);
                }
                catch (Exception ex)
                {
                    string msg = TX.Messages.FailedToApplyTaxes;
                    msg += Environment.NewLine + ex.Message;

                    throw new PXException(ex, msg);
                }
            }
            else
            {
                LogMessages(result);

                throw new PXException(TX.Messages.FailedToGetTaxes);
            }

            return(doc);
        }