예제 #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 override POOrder CalculateExternalTax(POOrder order)
        {
            var  toAddress    = GetToAddress(order);
            bool isNonTaxable = IsNonTaxable(toAddress);

            if (isNonTaxable)
            {
                order.IsTaxValid         = true;
                order.IsUnbilledTaxValid = true;
                ApplyTax(order, GetTaxResult.Empty, GetTaxResult.Empty);

                return(order);
            }

            var service = TaxProviderFactory(Base, order.TaxZoneID);

            GetTaxRequest getRequest         = null;
            GetTaxRequest getRequestUnbilled = null;

            bool isValidByDefault = true;

            if (order.IsTaxValid != true)
            {
                getRequest = BuildGetTaxRequest(order);

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

            if (order.IsUnbilledTaxValid != true)
            {
                getRequestUnbilled = BuildGetTaxRequestUnbilled(order);
                if (getRequestUnbilled.CartItems.Count > 0)
                {
                    isValidByDefault = false;
                }
                else
                {
                    getRequestUnbilled = null;
                }
            }

            if (isValidByDefault)
            {
                PXDatabase.Update <POOrder>(
                    new PXDataFieldAssign(nameof(POOrder.IsTaxValid), true),
                    new PXDataFieldAssign(nameof(POOrder.IsUnbilledTaxValid), true),
                    new PXDataFieldRestrict(nameof(POOrder.OrderType), PXDbType.VarChar, 2, order.OrderType, PXComp.EQ),
                    new PXDataFieldRestrict(nameof(POOrder.OrderNbr), PXDbType.NVarChar, 15, order.OrderNbr, PXComp.EQ)
                    );
                order.IsTaxValid         = true;
                order.IsUnbilledTaxValid = true;
                PXTimeStampScope.PutPersisted(Base.Document.Cache, order, PXDatabase.SelectTimeStamp());
                return(order);
            }

            GetTaxResult result         = null;
            GetTaxResult resultUnbilled = null;

            bool getTaxFailed = false;

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

            if (!getTaxFailed)
            {
                try
                {
                    ApplyTax(order, result, resultUnbilled);
                    PXDatabase.Update <POOrder>(
                        new PXDataFieldAssign(nameof(POOrder.IsTaxValid), true),
                        new PXDataFieldAssign(nameof(POOrder.IsUnbilledTaxValid), true),
                        new PXDataFieldRestrict(nameof(POOrder.OrderType), PXDbType.VarChar, 2, order.OrderType, PXComp.EQ),
                        new PXDataFieldRestrict(nameof(POOrder.OrderNbr), PXDbType.NVarChar, 15, order.OrderNbr, PXComp.EQ)
                        );
                    order.IsTaxValid         = true;
                    order.IsUnbilledTaxValid = true;
                    PXTimeStampScope.PutPersisted(Base.Document.Cache, order, PXDatabase.SelectTimeStamp());
                }
                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
            {
                ResultBase taxResult = result ?? resultUnbilled;
                if (taxResult != null)
                {
                    LogMessages(taxResult);
                }

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

            return(order);
        }
예제 #3
0
        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);
        }
예제 #4
0
        public virtual void RowPersisted(PXCache sender, PXRowPersistedEventArgs e)
        {
            PXCache cache = sender.Graph.Caches[typeof(CATran)];

            if (e.TranStatus == PXTranStatus.Open)
            {
                object key = sender.GetValue(e.Row, _FieldOrdinal);
            }
            else if (e.TranStatus == PXTranStatus.Aborted)
            {
                object key = sender.GetValue(e.Row, _FieldOrdinal);
                if (_KeyToAbort != null && (long)_KeyToAbort < 0L)
                {
                    sender.SetValue(e.Row, _FieldOrdinal, _KeyToAbort);
                    foreach (CATran data in cache.Inserted)
                    {
                        if (Equals(key, data.TranID))
                        {
                            data.TranID = (long)_KeyToAbort;
                            cache.ResetPersisted(data);
                            break;
                        }
                    }
                }
                else
                {
                    foreach (CATran data in cache.Updated)
                    {
                        if (object.Equals(key, data.TranID))
                        {
                            cache.ResetPersisted(data);
                        }
                    }
                }

                cache.Normalize();
            }
            else
            {
                object key = sender.GetValue(e.Row, _FieldOrdinal);
                foreach (CATran data in cache.Inserted)
                {
                    if (object.Equals(key, data.TranID))
                    {
                        cache.RaiseRowPersisted(data, PXDBOperation.Insert, e.TranStatus, e.Exception);
                        cache.SetStatus(data, PXEntryStatus.Notchanged);
                        PXTimeStampScope.PutPersisted(cache, data, sender.Graph.TimeStamp);
                        cache.ResetPersisted(data);
                    }
                }
                foreach (CATran data in cache.Updated)
                {
                    if (object.Equals(key, data.TranID))
                    {
                        cache.RaiseRowPersisted(data, PXDBOperation.Update, e.TranStatus, e.Exception);
                        cache.SetStatus(data, PXEntryStatus.Notchanged);
                        PXTimeStampScope.PutPersisted(cache, data, sender.Graph.TimeStamp);
                        cache.ResetPersisted(data);
                    }
                }
                foreach (CATran data in cache.Deleted)
                {
                    cache.RaiseRowPersisted(data, PXDBOperation.Delete, e.TranStatus, e.Exception);
                    cache.SetStatus(data, PXEntryStatus.Notchanged);
                    PXTimeStampScope.PutPersisted(cache, data, sender.Graph.TimeStamp);
                    cache.ResetPersisted(data);
                }
                cache.IsDirty = false;
                cache.Normalize();
            }
        }
        public FSAppointment CalculateExternalTax(FSAppointment fsAppointment, FSServiceOrder order, bool forceRecalculate)
        {
            var toAddress = GetToAddress(order);

            var service = TaxProviderFactory(Base, fsAppointment.TaxZoneID);

            GetTaxRequest getRequest         = null;
            GetTaxRequest getRequestOpen     = null;
            GetTaxRequest getRequestUnbilled = null;
            GetTaxRequest getRequestFreight  = null;

            bool isValidByDefault = false;

            FSSrvOrdType srvOrdType = PXSelect <FSSrvOrdType, Where <FSSrvOrdType.srvOrdType, Equal <Required <FSAppointment.srvOrdType> > > > .Select(this.Base, fsAppointment.SrvOrdType);

            if (/*srvOrdType.INDocType != INTranType.Transfer &&*/ !IsNonTaxable(toAddress))
            {
                if (fsAppointment.IsTaxValid != true || forceRecalculate)
                {
                    getRequest = BuildGetTaxRequest(fsAppointment, order);

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

                /*if (order.IsOpenTaxValid != true || forceRecalculate)
                 * {
                 *  getRequestOpen = BuildGetTaxRequestOpen(order);
                 *  if (getRequestOpen.CartItems.Count > 0)
                 *  {
                 *      isValidByDefault = false;
                 *  }
                 *  else
                 *  {
                 *      getRequestOpen = null;
                 *  }
                 * }*/

                /*if (order.IsUnbilledTaxValid != true || forceRecalculate)
                 * {
                 *  getRequestUnbilled = BuildGetTaxRequestUnbilled(order);
                 *  if (getRequestUnbilled.CartItems.Count > 0)
                 *  {
                 *      isValidByDefault = false;
                 *  }
                 *  else
                 *  {
                 *      getRequestUnbilled = null;
                 *  }
                 * }*/

                /*if (order.IsFreightTaxValid != true || forceRecalculate)
                 * {
                 *  getRequestFreight = BuildGetTaxRequestFreight(order);
                 *  if (getRequestFreight.CartItems.Count > 0)
                 *  {
                 *      isValidByDefault = false;
                 *  }
                 *  else
                 *  {
                 *      getRequestFreight = null;
                 *  }
                 * }*/
            }

            if (isValidByDefault)
            {
                fsAppointment.CuryTaxTotal = 0;
                //order.CuryOpenTaxTotal = 0;
                //order.CuryUnbilledTaxTotal = 0;
                fsAppointment.IsTaxValid = true;
                //order.IsOpenTaxValid = true;
                //order.IsUnbilledTaxValid = true;
                //order.IsFreightTaxValid = true;

                Base.AppointmentRecords.Update(fsAppointment);

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

                using (var ts = new PXTransactionScope())
                {
                    Base.Persist(typeof(FSAppointmentTaxTran), PXDBOperation.Delete);
                    Base.Persist(typeof(FSAppointment), PXDBOperation.Update);
                    PXTimeStampScope.PutPersisted(Base.AppointmentRecords.Cache, fsAppointment, PXDatabase.SelectTimeStamp());
                    ts.Complete();
                }
                return(fsAppointment);
            }

            GetTaxResult result         = null;
            GetTaxResult resultOpen     = null;
            GetTaxResult resultUnbilled = null;
            GetTaxResult resultFreight  = null;

            bool getTaxFailed = false;

            if (getRequest != null)
            {
                result = service.GetTax(getRequest);

                if (!result.IsSuccess)
                {
                    getTaxFailed = true;
                }
            }
            if (getRequestOpen != null)
            {
                if (getRequest != null && IsSame(getRequest, getRequestOpen))
                {
                    resultOpen = result;
                }
                else
                {
                    resultOpen = service.GetTax(getRequestOpen);

                    if (!resultOpen.IsSuccess)
                    {
                        getTaxFailed = true;
                    }
                }
            }
            if (getRequestUnbilled != null)
            {
                if (getRequest != null && IsSame(getRequest, getRequestUnbilled))
                {
                    resultUnbilled = result;
                }
                else
                {
                    resultUnbilled = service.GetTax(getRequestUnbilled);

                    if (!resultUnbilled.IsSuccess)
                    {
                        getTaxFailed = true;
                    }
                }
            }
            if (getRequestFreight != null)
            {
                resultFreight = service.GetTax(getRequestFreight);

                if (!resultFreight.IsSuccess)
                {
                    getTaxFailed = true;
                }
            }

            if (!getTaxFailed)
            {
                try
                {
                    ApplyTax(fsAppointment, result, resultOpen, resultUnbilled, resultFreight);
                }
                catch (PXOuterException ex)
                {
                    string msg = PX.Objects.TX.Messages.FailedToApplyTaxes;
                    foreach (string err in ex.InnerMessages)
                    {
                        msg += Environment.NewLine + err;
                    }

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

                    throw new PXException(ex, msg);
                }
            }
            else
            {
                ResultBase taxResult = result ?? resultOpen ?? resultUnbilled ?? resultFreight;
                if (taxResult != null)
                {
                    LogMessages(taxResult);
                }

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

            return(fsAppointment);
        }