public override void Persist()
        {
            foreach (DocumentSelection b in Document_Detail.Cache.Updated)
            {
                ARReleaseProcess.UpdateARBalances(this, b, -b.OrigDocAmt);

                if (b.Voided == false)
                {
                    b.Scheduled  = true;
                    b.ScheduleID = Schedule_Header.Current.ScheduleID;
                    Document_Detail.Cache.Update(b);
                }

                ARReleaseProcess.UpdateARBalances(this, b, b.OrigDocAmt);
            }

            foreach (DocumentSelection b in Document_Detail.Cache.Deleted)
            {
                ARReleaseProcess.UpdateARBalances(this, b, -b.OrigDocAmt);

                PXDBDefaultAttribute.SetDefaultForUpdate <DocumentSelection.scheduleID>(Document_Detail.Cache, b, false);
                b.Voided     = true;
                b.OpenDoc    = false;
                b.Scheduled  = false;
                b.ScheduleID = null;
                Document_Detail.Cache.SetStatus(b, PXEntryStatus.Updated);
                Document_Detail.Cache.Update(b);

                ARReleaseProcess.UpdateARBalances(this, b, b.OrigDocAmt);
            }
            base.Persist();
        }
Example #2
0
        protected virtual void DocumentSelection_RowUpdated(PXCache cache, PXRowUpdatedEventArgs e)
        {
            ARRegister documentAsRegister = e.Row as ARRegister;

            if (documentAsRegister != null && documentAsRegister.Voided == false && documentAsRegister.Scheduled == false)
            {
                ARReleaseProcess.UpdateARBalances(this, documentAsRegister, -documentAsRegister.OrigDocAmt);

                documentAsRegister.Scheduled  = true;
                documentAsRegister.ScheduleID = Schedule_Header.Current.ScheduleID;

                ARReleaseProcess.UpdateARBalances(this, documentAsRegister, documentAsRegister.OrigDocAmt);
            }

            DocumentSelection document = e.Row as DocumentSelection;

            if (document != null &&
                !string.IsNullOrWhiteSpace(document.DocType) &&
                !string.IsNullOrWhiteSpace(document.RefNbr) &&
                PXSelectorAttribute.Select <DocumentSelection.refNbr>(cache, document) == null)
            {
                cache.RaiseExceptionHandling <DocumentSelection.refNbr>(
                    document,
                    document.RefNbr,
                    new PXSetPropertyException(AP.Messages.ReferenceNotValid));

                Document_Detail.Cache.Remove(document);
            }
        }
Example #3
0
        public virtual void CreateWriteOff(ReasonCode reasonCode, string WOSubCD, DateTime?WODate, string WOFinPeriodID, ARRegister ardoc)
        {
            Int32?WOAccountID = reasonCode.AccountID;

            if (WOAccountID == null)
            {
                throw new ArgumentNullException("WOAccountID");
            }

            if (WOSubCD == null)
            {
                throw new ArgumentNullException("WOSubCD");
            }

            this.Clear();
            customer.Current = null;
            _CustomerID      = ardoc.CustomerID;

            ARPayment payment = new ARPayment();

            payment.BranchID = ardoc.BranchID;
            payment          = PXCache <ARPayment> .CreateCopy(this.Document.Insert(payment));

            payment.CustomerID         = ardoc.CustomerID;
            payment.CustomerLocationID = ardoc.CustomerLocationID;
            payment.AdjDate            = WODate;
            payment.AdjFinPeriodID     = WOFinPeriodID;
            payment.DocDate            = WODate;
            payment.FinPeriodID        = WOFinPeriodID;
            payment.CuryID             = ardoc.CuryID;
            payment.ARAccountID        = WOAccountID;
            payment.Hold    = false;
            payment.DocDesc = reasonCode.Descr;

            payment = this.Document.Update(payment);
            this.Document.Cache.SetValueExt <ARPayment.aRSubID>(payment, WOSubCD);

            ARAdjust adj = new ARAdjust();

            adj.AdjdDocType = ardoc.DocType;
            adj.AdjdRefNbr  = ardoc.RefNbr;

            adj = this.Adjustments.Insert(adj);

            Document.Current.CuryDocBal += (decimal)adj.CuryAdjgAmt;
            Document.Current.DocBal     += (decimal)adj.AdjAmt;

            Document.Current.CuryOrigDocAmt += (decimal)adj.CuryAdjgAmt;
            Document.Current.OrigDocAmt     += (decimal)adj.AdjAmt;

            ARReleaseProcess.UpdateARBalances(this, Document.Current, adj.AdjAmt);

            if (Document.Cache.GetStatus(Document.Current) == PXEntryStatus.Notchanged)
            {
                Document.Cache.SetStatus(Document.Current, PXEntryStatus.Updated);
            }

            this.Actions.PressSave();
        }
Example #4
0
 public decimal Round(decimal amount, int curyPlaces)
 {
     if (this._rounding == RoundingType.Currency)
     {
         return(decimal.Round(amount, curyPlaces));
     }
     else
     {
         return(ARReleaseProcess.RoundAmount(amount, this._rounding, this._precision).Value);
     }
 }
        public override void UpdateARBalances(PXCache cache, object newRow, object oldRow)
        {
            if (oldRow != null)
            {
                ARInvoice oldARRow = Document.Cache.GetMain((Document)oldRow) as ARInvoice;
                ARReleaseProcess.UpdateARBalances(cache.Graph, (ARInvoice)oldARRow, -((ARInvoice)oldARRow).OrigDocAmt);
            }

            if (newRow != null)
            {
                ARInvoice newARRow = Document.Cache.GetMain((Document)newRow) as ARInvoice;
                ARReleaseProcess.UpdateARBalances(cache.Graph, (ARInvoice)newARRow, ((ARInvoice)newARRow).OrigDocAmt);
            }
        }
Example #6
0
        public override void UpdateARBalances(PXCache cache, Object newRow, Object oldRow)
        {
            if (oldRow != null)
            {
                SOOrder oldSORow = Document.Cache.GetMain((Document)oldRow) as SOOrder;
                ARReleaseProcess.UpdateARBalances(cache.Graph, oldSORow, -(oldSORow).UnbilledOrderTotal, -(oldSORow.OpenOrderTotal));
            }

            if (newRow != null)
            {
                SOOrder newSORow = Document.Cache.GetMain((Document)newRow) as SOOrder;
                ARReleaseProcess.UpdateARBalances(cache.Graph, newSORow, (newSORow).UnbilledOrderTotal, newSORow.OpenOrderTotal);
            }
        }
        protected virtual void DocumentSelection_RowUpdated(PXCache cache, PXRowUpdatedEventArgs e)
        {
            ARRegister ap = e.Row as ARRegister;

            if (ap != null && ap.Voided == false && ap.Scheduled == false)
            {
                ARReleaseProcess.UpdateARBalances(this, ap, -ap.OrigDocAmt);

                ap.Scheduled  = true;
                ap.ScheduleID = Schedule_Header.Current.ScheduleID;

                ARReleaseProcess.UpdateARBalances(this, ap, ap.OrigDocAmt);
            }
        }
Example #8
0
        public static Amount CalculateSalesPostingAmount(PXGraph graph, DRSchedule customSchedule)
        {
            var netLinesAmount = new Amount(0m, 0m);

            var processedTrans = new HashSet <ARTran>();

            foreach (PXResult <ARTran, ARRegister, ARTax, Tax> item in PXSelectJoin <
                         ARTran,
                         InnerJoin <ARRegister, On <ARTran.tranType, Equal <ARRegister.docType>,
                                                    And <ARTran.refNbr, Equal <ARRegister.refNbr> > >,
                                    LeftJoin <ARTax,
                                              On <ARTran.tranType, Equal <ARTax.tranType>,
                                                  And <ARTran.refNbr, Equal <ARTax.refNbr>,
                                                       And <ARTran.lineNbr, Equal <ARTax.lineNbr> > > >,
                                              LeftJoin <Tax,
                                                        On <Tax.taxID, Equal <ARTax.taxID> > > > >,
                         Where <ARTran.tranType, Equal <Required <ARInvoice.docType> >,
                                And <ARTran.refNbr, Equal <Required <ARInvoice.refNbr> >,
                                     And <ARTran.deferredCode, IsNull,
                                          And <Where <ARTran.lineType, IsNull,
                                                      Or <ARTran.lineType, NotEqual <SO.SOLineType.discount> > > > > > > >
                     .Select(graph, customSchedule.DocType, customSchedule.RefNbr))
            {
                ARTran     line     = item;
                ARRegister register = item;
                ARTax      artax    = item;
                Tax        tax      = item;

                if (processedTrans.Contains(line))
                {
                    continue;
                }

                var netLineAmount = ARReleaseProcess.GetSalesPostingAmount(graph, register, line, artax, tax,
                                                                           amnt => PXDBCurrencyAttribute.Round(graph.Caches[typeof(ARTran)], line, amnt, CMPrecision.TRANCURY));

                netLinesAmount += netLineAmount;

                processedTrans.Add(line);
            }

            return(netLinesAmount);
        }
Example #9
0
        public virtual void CreateWriteOff(ReasonCode reasonCode, string WOSubCD, DateTime?WODate, string WOFinPeriodID, ARRegister ardoc)
        {
            Int32?WOAccountID = reasonCode.AccountID;

            if (WOAccountID == null)
            {
                throw new ArgumentNullException("WOAccountID");
            }

            if (WOSubCD == null)
            {
                throw new ArgumentNullException("WOSubCD");
            }


            this.Clear();
            customer.Current = null;
            _CustomerID      = ardoc.CustomerID;

            ARInvoice payment = new ARInvoice();

            payment.BranchID = ardoc.BranchID;
            payment          = PXCache <ARInvoice> .CreateCopy(this.Document.Insert(payment));

            payment.CustomerID         = ardoc.CustomerID;
            payment.CustomerLocationID = ardoc.CustomerLocationID;
            payment.DocDate            = WODate;
            payment.FinPeriodID        = WOFinPeriodID;
            payment.CuryID             = ardoc.CuryID;
            payment.ARAccountID        = WOAccountID;
            payment.Hold    = false;
            payment.AdjCntr = -1;
            payment.DocDesc = reasonCode.Descr;

            payment = this.Document.Update(payment);

            this.Document.Cache.SetValueExt <ARInvoice.aRSubID>(payment, WOSubCD);

            ARAddressAttribute.DefaultRecord <ARInvoice.billAddressID>(Document.Cache, payment);
            ARContactAttribute.DefaultRecord <ARInvoice.billContactID>(Document.Cache, payment);

            ARAdjust adj = new ARAdjust();

            adj.AdjgDocType        = ardoc.DocType;
            adj.AdjgRefNbr         = ardoc.RefNbr;
            adj.AdjNbr             = payment.AdjCntr;
            adj.AdjdCuryInfoID     = Document.Current.CuryInfoID;
            adj.AdjdOrigCuryInfoID = Document.Current.CuryInfoID;

            adj = this.Adjustments.Insert(adj);

            Document.Current.CuryDocBal += (decimal)adj.CuryAdjdAmt;
            Document.Current.DocBal     += (decimal)adj.AdjAmt;

            Document.Current.CuryOrigDocAmt += (decimal)adj.CuryAdjdAmt;
            Document.Current.OrigDocAmt     += (decimal)adj.AdjAmt;

            ARReleaseProcess.UpdateARBalances(this, Document.Current, adj.AdjAmt);

            Document.Cache.MarkUpdated(Document.Current);

            this.Actions.PressSave();
        }
Example #10
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);
            }
        }