Exemple #1
0
        private void CalcBalances(object row, bool isCalcRGOL, bool DiscOnDiscDate)
        {
            ARAdjust adj = (ARAdjust)row;

            PXCache cache = Caches[typeof(ARAdjust)];

            ARPayment payment = (ARPayment)ARPayment_CustomerID_DocType_RefNbr.Select(adj.CustomerID, adj.AdjgDocType, adj.AdjgRefNbr);

            if (payment == null)
            {
                return;
            }

            PaymentEntry.CalcBalances <ARPayment, ARAdjust>(CurrencyInfo_CuryInfoID, adj.AdjgCuryInfoID, adj.AdjdCuryInfoID, payment, adj);

            if (DiscOnDiscDate)
            {
                PaymentEntry.CalcDiscount <ARPayment, ARAdjust>(adj.AdjgDocDate, payment, adj);
            }

            PaymentEntry.AdjustBalance <ARAdjust>(CurrencyInfo_CuryInfoID, adj);
            if (isCalcRGOL)
            {
                PaymentEntry.CalcRGOL <ARPayment, ARAdjust>(CurrencyInfo_CuryInfoID, payment, adj);
                adj.RGOLAmt = (bool)adj.ReverseGainLoss ? -1m * adj.RGOLAmt : adj.RGOLAmt;
            }
        }
        private CABatch UpdateDocAmount(CABatchDetail row, bool negative)
        {
            CABatch doc = this.Document.Current;

            if (row.OrigDocType != null && row.OrigRefNbr != null)
            {
                decimal?  curyAmount = null, amount = null;
                ARPayment pmt = PXSelect <ARPayment,
                                          Where <ARPayment.docType, Equal <Required <ARPayment.docType> >,
                                                 And <ARPayment.refNbr, Equal <Required <ARPayment.refNbr> > > > > .Select(this, row.OrigDocType, row.OrigRefNbr);

                if (pmt != null)
                {
                    curyAmount = pmt.CuryOrigDocAmt;
                    amount     = pmt.OrigDocAmt;
                }

                CABatch copy = (CABatch)this.Document.Cache.CreateCopy(doc);
                if (curyAmount.HasValue)
                {
                    doc.CuryDetailTotal += negative ? -curyAmount : curyAmount;
                }
                if (amount.HasValue)
                {
                    doc.DetailTotal += negative ? -amount : amount;
                }
                doc = this.Document.Update(doc);
            }
            return(doc);
        }
        public static void CreateAdjustment(ARInvoiceEntry graph, ARInvoice invoice, RUTROT rutrot)
        {
            ARPayment creditMemo = PXSelect <ARPayment, Where <ARPayment.docType, Equal <Required <RUTROT.docType> >,
                                                               And <ARPayment.refNbr, Equal <Required <RUTROT.refNbr> > > > > .Select(graph, rutrot.BalancingCreditMemoDocType, rutrot.BalancingCreditMemoRefNbr);

            ARAdjust2 applicationToCreditMemo = new ARAdjust2
            {
                AdjdDocType        = invoice.DocType,
                AdjdRefNbr         = invoice.RefNbr,
                AdjgDocType        = creditMemo.DocType,
                AdjgRefNbr         = creditMemo.RefNbr,
                AdjNbr             = creditMemo.AdjCntr,
                CustomerID         = creditMemo.CustomerID,
                AdjdCustomerID     = invoice.CustomerID,
                AdjdBranchID       = invoice.BranchID,
                AdjgBranchID       = creditMemo.BranchID,
                AdjgCuryInfoID     = creditMemo.CuryInfoID,
                AdjdOrigCuryInfoID = invoice.CuryInfoID,
                AdjdCuryInfoID     = invoice.CuryInfoID,
                CuryAdjdAmt        = creditMemo.CuryDocBal
            };

            graph.Adjustments.Insert(applicationToCreditMemo);
            graph.Save.Press();
        }
        public static void ReleaseDoc(CABatch aDoc)
        {
            if ((bool)aDoc.Released || (bool)aDoc.Hold)
            {
                throw new PXException(CA.Messages.CABatchStatusIsNotValidForProcessing);
            }
            ARBatchUpdate be  = PXGraph.CreateInstance <ARBatchUpdate>();
            CABatch       doc = be.Document.Select(aDoc.BatchNbr);

            be.Document.Current = doc;
            if ((bool)doc.Released || (bool)doc.Hold)
            {
                throw new PXException(CA.Messages.CABatchStatusIsNotValidForProcessing);
            }

            ARPayment voided = PXSelectReadonly2 <ARPayment,
                                                  InnerJoin <CABatchDetail, On <CABatchDetail.origDocType, Equal <ARPayment.docType>,
                                                                                And <CABatchDetail.origRefNbr, Equal <ARPayment.refNbr>,
                                                                                     And <CABatchDetail.origModule, Equal <GL.BatchModule.moduleAR> > > > >,
                                                  Where <CABatchDetail.batchNbr, Equal <Required <CABatch.batchNbr> >,
                                                         And <ARPayment.voided, Equal <True> > > > .Select(be, doc.BatchNbr);

            if (voided != null && String.IsNullOrEmpty(voided.RefNbr) == false)
            {
                throw new PXException(CA.Messages.CABatchContainsVoidedPaymentsAndConnotBeReleased);
            }

            List <ARRegister>        unreleasedList   = new List <ARRegister>();
            PXSelectBase <ARPayment> selectUnreleased = new PXSelectReadonly2 <ARPayment,
                                                                               InnerJoin <CABatchDetail, On <CABatchDetail.origDocType, Equal <ARPayment.docType>,
                                                                                                             And <CABatchDetail.origRefNbr, Equal <ARPayment.refNbr>,
                                                                                                                  And <CABatchDetail.origModule, Equal <GL.BatchModule.moduleAR> > > > >,
                                                                               Where <CABatchDetail.batchNbr, Equal <Optional <CABatch.batchNbr> >,
                                                                                      And <ARPayment.released, Equal <boolFalse> > > >(be);

            foreach (ARPayment iPmt in selectUnreleased.Select(doc.BatchNbr))
            {
                if (iPmt.Released != true)
                {
                    unreleasedList.Add(iPmt);
                }
            }
            if (unreleasedList.Count > 0)
            {
                ARDocumentRelease.ReleaseDoc(unreleasedList, true);
            }

            selectUnreleased.View.Clear();
            ARPayment pmt = selectUnreleased.Select(doc.BatchNbr);

            if (pmt != null)
            {
                throw new PXException(CA.Messages.CABatchContainsUnreleasedPaymentsAndCannotBeReleased);
            }
            doc.Released   = true;
            doc.DateSeqNbr = CABatchEntry.GetNextDateSeqNbr(be, aDoc); //Nothing AP specific in this static function
            be.RecalcTotals();
            doc = be.Document.Update(doc);
            be.Actions.PressSave();
        }
Exemple #5
0
        private void UpdateOrderBalances(SOOrder order)
        {
            if (order == null)
            {
                return;
            }
            bool?     isFromCA = order.GetExtension <KCSOOrderExt>().UsrKCSiteName?.EndsWith("FBA");
            ARPayment payment  = KCOrderPayment.Select(order.CustomerOrderNbr);

            if (isFromCA == true && payment != null)
            {
                order.PaymentTotal = order.CuryPaymentTotal = payment.CuryOrigDocAmt;
            }

            order.DocBal        = order.CuryDocBal = order.CuryOrderTotal;
            order.UnpaidBalance = order.CuryUnpaidBalance = 0;

            foreach (ARTran line in Base.Transactions.Select())
            {
                SOLine      sOLine      = KCSOLineByOrderNbrAndLineNbr.SelectSingle(line.SOOrderNbr, line.SOOrderLineNbr);
                SOLinePCExt SOLinePCExt = sOLine.GetExtension <SOLinePCExt>();
                if (SOLinePCExt.UsrKNMasterLineNbr == sOLine.LineNbr)
                {
                    line.CuryExtPrice = sOLine.CuryExtPrice;
                    line.CuryTranAmt  = sOLine.CuryLineAmt;
                }
            }
        }
Exemple #6
0
        public virtual IEnumerable cCTrans()
        {
            List <PXResult <CCProcTran, CustomerPaymentMethod, Customer, ARPayment> > res = new List <PXResult <CCProcTran, CustomerPaymentMethod, Customer, ARPayment> >();

            CCTransactionsHistoryFilter filter = (CCTransactionsHistoryFilter)this.Filter.Current;


            if (filter != null && string.IsNullOrEmpty(filter.PaymentMethodID) == false &&
                filter.StartDate.HasValue && filter.EndDate.HasValue && filter.PMInstanceID != null)
            {
                GetInternalData(filter.PaymentMethodID);

                PXSelectBase <CCProcTran> sel = new PXSelectJoin <CCProcTran,
                                                                  InnerJoin <CustomerPaymentMethod, On <CustomerPaymentMethod.pMInstanceID, Equal <CCProcTran.pMInstanceID> >,
                                                                             InnerJoin <Customer, On <CustomerPaymentMethod.bAccountID, Equal <Customer.bAccountID> >,
                                                                                        LeftJoin <ARPayment, On <ARPayment.docType, Equal <CCProcTran.docType>, And <ARPayment.refNbr, Equal <CCProcTran.refNbr> > > > > > >(this);

                if (string.IsNullOrEmpty(filter.PaymentMethodID) == false)
                {
                    sel.WhereAnd <Where <CustomerPaymentMethod.paymentMethodID, Equal <Current <CCTransactionsHistoryFilter.paymentMethodID> > > >();
                }
                if (string.IsNullOrEmpty(filter.ProcessingCenterID) == false)
                {
                    sel.WhereAnd <Where <CCProcTran.processingCenterID, Equal <Current <CCTransactionsHistoryFilter.processingCenterID> > > >();
                }
                if (filter.StartDate.HasValue)
                {
                    sel.WhereAnd <Where <CCProcTran.startTime, GreaterEqual <Current <CCTransactionsHistoryFilter.startDate> > > >();
                }
                if (filter.EndDate.HasValue)
                {
                    sel.WhereAnd <Where <CCProcTran.startTime, LessEqual <Current <CCTransactionsHistoryFilter.endDatePlusOne> > > >();
                }

                if (filter.PMInstanceID.HasValue)
                {
                    sel.WhereAnd <Where <CustomerPaymentMethod.pMInstanceID, Equal <Current <CCTransactionsHistoryFilter.pMInstanceID> > > >();
                }

                foreach (PXResult <CCProcTran, CustomerPaymentMethod, Customer, ARPayment> it in sel.Select(CardNumber_DetailID, NameOnCard_DetailID))
                {
                    ARPayment  payment = it;
                    CCProcTran ccTran  = it;
                    if (ccTran.TranType == CCTranTypeCode.Credit || ccTran.TranType == CCTranTypeCode.VoidTran)
                    {
                        ARPayment voiding = PXSelect <ARPayment, Where <ARPayment.refNbr, Equal <Required <ARPayment.refNbr> >,
                                                                        And <ARPayment.docType, Equal <ARDocType.voidPayment> > > > .Select(this, payment.RefNbr);

                        if (voiding != null)
                        {
                            ((ARPayment)it).DocType  = ARDocType.VoidPayment;
                            ((CCProcTran)it).DocType = ARDocType.VoidPayment;
                        }
                    }
                    yield return(it);
                }
            }
            yield break;
        }
Exemple #7
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();
        }
        public virtual CABatchDetail AddPayment(ARPayment aPayment)
        {
            CABatchDetail detail = new CABatchDetail();

            detail.Copy(aPayment);
            detail = this.BatchPayments.Insert(detail);
            return(detail);
        }
 public static bool VoidEnabled(ARPayment payment)
 {
     return
         (payment.DocType == Payment ||
          payment.DocType == Prepayment ||
          payment.DocType == Refund ||
          payment.SelfVoidingDoc == true);
 }
        private bool DocTypeSuits(ARPayment payment)
        {
            if (payment == null)
            {
                return(true);
            }

            return(payment.DocType == ARDocType.Payment || payment.DocType == ARDocType.VoidPayment || payment.DocType == ARDocType.CreditMemo);
        }
Exemple #11
0
        public virtual void ReverseApplicationProc(ARAdjust application, ARPayment payment, Action <ARAdjust, ARPayment> baseMethod)
        {
            if (payment?.IsCancellation == true)
            {
                throw new PXException(Messages.CantReverseCancellationApplication, application.AdjgRefNbr, application.AdjdRefNbr);
            }

            baseMethod(application, payment);
        }
        //public PXSelect<ARInvoice, Where<ARInvoice.status, Equal<open>>> Adjustments2;

        protected virtual IEnumerable adjustments2()
        {
            PXGraph   graph                  = Base;
            var       opts                   = Base.loadOpts.Current;
            ARPayment currentDoc             = Base.Document.Current;
            PXResultset <ARInvoice> custdocs = GetCustDocs(opts, currentDoc, Base.arsetup.Current, graph);

            return(custdocs);
        }
 public virtual void CalcDetailsTotal(ref decimal?aCuryTotal, ref decimal?aTotal)
 {
     aCuryTotal = Decimal.Zero;
     aTotal     = Decimal.Zero;
     foreach (PXResult <CABatchDetail, ARPayment> it in this.BatchPayments.Select())
     {
         ARPayment pmt = it;
         if (!String.IsNullOrEmpty(pmt.RefNbr))
         {
             aCuryTotal += pmt.CuryOrigDocAmt;
             aTotal     += pmt.OrigDocAmt;
         }
     }
 }
 public void Complete(PXLongRunStatus status, PXGraph graph)
 {
     if (status == PXLongRunStatus.Completed && graph is ARPaymentEntry)
     {
         ((ARPaymentEntry)graph).RowSelected.AddHandler <ARPayment>((sender, e) =>
         {
             ARPayment payment = e.Row as ARPayment;
             if (payment != null && payment.Released == false && DateTime.Compare(payment.AdjDate.Value, _NewDate) != 0)
             {
                 sender.RaiseExceptionHandling <ARPayment.adjDate>(payment, payment.AdjDate, new PXSetPropertyException(Messages.ApplicationDateChanged, PXErrorLevel.Warning));
             }
         });
     }
 }
        public virtual IEnumerable editDetail(PXAdapter adapter)
        {
            ARPayment doc = this.ARDocumentList.Current;

            if (doc != null)
            {
                ARPaymentEntry pe = PXGraph.CreateInstance <ARPaymentEntry>();
                pe.Document.Current = pe.Document.Search <ARPayment.refNbr>(doc.RefNbr, doc.DocType);
                throw new PXRedirectRequiredException(pe, true, "Payment")
                      {
                          Mode = PXRedirectRequiredException.WindowMode.NewWindow
                      };
            }
            return(adapter.Get());
        }
        protected virtual void ARPayment_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
        {
            ARPayment doc = e.Row as ARPayment;

            Branch           branch             = Base.CurrentBranch.SelectSingle(doc.BranchID);
            var              adjustments        = Adjustments.Select();
            List <ARInvoice> invoices           = adjustments.Select(d => d.GetItem <ARInvoice>()).ToList();
            List <RUTROT>    rutrots            = adjustments.Select(d => d.GetItem <RUTROT>()).ToList();
            bool             hasRutRotInvoices  = invoices.Any(d => (d != null && PXCache <ARInvoice> .GetExtension <ARInvoiceRUTROT>(d)?.IsRUTROTDeductible == true));
            bool             someInvoiceClaimed = rutrots.Any(d => (d != null && d.IsClaimed == true));

            PXUIFieldAttribute.SetVisible <ARPaymentRUTROT.isRUTROTPayment>(Base.Document.Cache, e.Row, branch != null && PXCache <Branch> .GetExtension <BranchRUTROT>(branch).AllowsRUTROT == true && DocTypeSuits(doc));
            PXUIFieldAttribute.SetEnabled <ARPaymentRUTROT.isRUTROTPayment>(Base.Document.Cache, e.Row, branch != null && PXCache <Branch> .GetExtension <BranchRUTROT>(branch).RUTROTCuryID == doc.CuryID && doc.Released != true &&
                                                                            (someInvoiceClaimed == true || hasRutRotInvoices == false));
        }
        private static void _createPayments(List <ARInvoice> list, PayBillsFilter filter, CurrencyInfo info)
        {
            bool           failed = false;
            ARPaymentEntry pe     = PXGraph.CreateInstance <ARPaymentEntry>();

            list.Sort((in1, in2) =>
            {
                if (in1.CustomerID != in2.CustomerID)
                {
                    return(((IComparable)in1.CustomerID).CompareTo(in2.CustomerID));
                }
                return(((IComparable)in1.PMInstanceID).CompareTo(in2.PMInstanceID));
            }
                      );
            for (int i = 0; i < list.Count; i++)
            {
                ARInvoice doc       = list[i];
                ARPayment pmt       = null;
                bool      docFailed = false;
                try
                {
                    pe.CreatePayment(doc, info, filter.PayDate, filter.PayFinPeriodID, false);
                    pmt = pe.Document.Current;
                    if (pmt != null)
                    {
                        pmt.Hold = false;

                        FinPeriodIDAttribute.SetPeriodsByMaster <ARPayment.finPeriodID>(pe.Document.Cache, pmt, filter.PayFinPeriodID);
                    }
                    pe.Save.Press();
                }
                catch (Exception e)
                {
                    PXFilteredProcessing <ARInvoice, PayBillsFilter> .SetError(i, e.Message);

                    docFailed = failed = true;
                }

                if (!docFailed)
                {
                    PXFilteredProcessing <ARInvoice, PayBillsFilter> .SetInfo(i, PXMessages.LocalizeFormatNoPrefixNLA(Messages.ARPaymentIsCreatedProcessingINProgress, pmt.RefNbr));
                }
            }
            if (failed)
            {
                throw new PXException(Messages.CreationOfARPaymentFailedForSomeInvoices);
            }
        }
        protected virtual void RedirectToDoc(string aDocType, string aRefNbr)
        {
            Dictionary <string, string> alltypes = new ARDocType.ListAttribute().ValueLabelDic;

            if (new ARInvoiceType.ListAttribute().ValueLabelDic.ContainsKey(aDocType))
            {
                ARInvoice doc = ARDocumentEnq.FindDoc <ARInvoice>(this, aDocType, aRefNbr);
                if (doc != null)
                {
                    ARInvoiceEntry graph = PXGraph.CreateInstance <ARInvoiceEntry>();
                    graph.Document.Current = doc;
                    throw new PXRedirectRequiredException(graph, true, "Document")
                          {
                              Mode = PXBaseRedirectException.WindowMode.NewWindow
                          };
                }
                throw new PXException(Messages.DocumentNotFound, alltypes[aDocType], aRefNbr);
            }
            if (new ARPaymentType.ListAttribute().ValueLabelDic.ContainsKey(aDocType))
            {
                ARPayment doc = ARDocumentEnq.FindDoc <ARPayment>(this, aDocType, aRefNbr);
                if (doc != null)
                {
                    ARPaymentEntry graph = PXGraph.CreateInstance <ARPaymentEntry>();
                    graph.Document.Current = doc;
                    throw new PXRedirectRequiredException(graph, true, "Document")
                          {
                              Mode = PXBaseRedirectException.WindowMode.NewWindow
                          };
                }
                throw new PXException(Messages.DocumentNotFound, alltypes[aDocType], aRefNbr);
            }
            if (new ARCashSaleType.ListAttribute().ValueLabelDic.ContainsKey(aDocType))
            {
                ARCashSale doc = ARDocumentEnq.FindDoc <ARCashSale>(this, aDocType, aRefNbr);
                if (doc != null)
                {
                    ARCashSaleEntry graph = PXGraph.CreateInstance <ARCashSaleEntry>();
                    graph.Document.Current = doc;
                    throw new PXRedirectRequiredException(graph, true, "Document")
                          {
                              Mode = PXBaseRedirectException.WindowMode.NewWindow
                          };
                }
                throw new PXException(Messages.DocumentNotFound, alltypes[aDocType], aRefNbr);
            }
            throw new PXException(Messages.UnknownDocumentType);
        }
Exemple #19
0
        protected virtual void _(Events.RowSelected <ARPayment> e)
        {
            if (e.Row == null)
            {
                return;
            }

            ARPayment arPaymentRow = (ARPayment)e.Row;

            bool atleastoneFSAdjust = FSAdjustments.SelectWindowed(0, 1).Count > 0;

            FSAdjustments.Cache.AllowInsert = !(atleastoneFSAdjust);
            FSAdjustments.Cache.AllowDelete = false;
            FSAdjustments.AllowSelect       = arPaymentRow.CreatedByScreenID == ID.ScreenID.APPOINTMENT ||
                                              arPaymentRow.CreatedByScreenID == ID.ScreenID.SERVICE_ORDER ||
                                              atleastoneFSAdjust;
        }
        public void CreatePaymentProcess(PrepareAndImportOrdersParams orderParams)
        {
            SOOrder          order    = orderParams.objSOOrderEntry.Document.Current;
            SOOrderAmazonExt OrderExt = order.GetExtension <SOOrderAmazonExt>();

            if (orderParams.objSOOrderEntry.sosetup.Current != null)
            {
                SOSetupAmazonExt objSOOSetupext = orderParams.objSOOrderEntry.sosetup.Current.GetExtension <SOSetupAmazonExt>();
                if (objSOOSetupext != null && !string.IsNullOrEmpty(objSOOSetupext.UsrAmazonPaymentMethodID))
                {
                    string paymentType = ARPaymentType.Payment;
                    orderParams.paymentGraph.Clear();
                    ARPayment payment = new ARPayment()
                    {
                        DocType = paymentType
                    };
                    payment = PXCache <ARPayment> .CreateCopy(orderParams.paymentGraph.Document.Insert(payment));

                    payment.CustomerID         = order.CustomerID;
                    payment.CustomerLocationID = order.CustomerLocationID;
                    payment.PaymentMethodID    = objSOOSetupext.UsrAmazonPaymentMethodID;
                    payment.PMInstanceID       = order.PMInstanceID;
                    payment.CuryOrigDocAmt     = 0m;
                    payment.ExtRefNbr          = OrderExt != null ? OrderExt.UsrAmazonOrderID : order.OrderNbr;
                    payment.DocDesc            = order.OrderDesc;
                    payment = orderParams.paymentGraph.Document.Update(payment);
                    SOAdjust adj = new SOAdjust()
                    {
                        AdjdOrderType = order.OrderType.Trim(),
                        AdjdOrderNbr  = order.OrderNbr.Trim()
                    };
                    orderParams.paymentGraph.SOAdjustments.Insert(adj);
                    if (payment.CuryOrigDocAmt == 0m)
                    {
                        payment.CuryOrigDocAmt = payment.CurySOApplAmt;
                        payment = orderParams.paymentGraph.Document.Update(payment);
                    }
                    orderParams.paymentGraph.Actions.PressSave();
                    if (orderParams.paymentGraph.Actions.Contains("Release"))
                    {
                        orderParams.paymentGraph.Actions["Release"].Press();
                    }
                }
            }
        }
            public virtual void RecalcTotals()
            {
                CABatch row = this.Document.Current;

                if (row != null)
                {
                    row.DetailTotal = row.CuryDetailTotal = row.CuryTotal = row.Total = decimal.Zero;
                    foreach (PXResult <ARPayment, CABatchDetail> it in this.ARPaymentList.Select())
                    {
                        ARPayment pmt = it;
                        if (!String.IsNullOrEmpty(pmt.RefNbr))
                        {
                            row.CuryDetailTotal += pmt.CuryOrigDocAmt;
                            row.DetailTotal     += pmt.OrigDocAmt;
                        }
                    }
                }
            }
        public virtual CABatchDetail AddPayment(ARPayment aPayment, bool skipCheck)
        {
            if (!skipCheck)
            {
                foreach (CABatchDetail iDel in this.BatchPayments.Select())
                {
                    if (IsKeyEqual(aPayment, iDel))
                    {
                        return(iDel);
                    }
                }
            }
            CABatchDetail detail = new CABatchDetail();

            detail.Copy(aPayment);
            detail = this.BatchPayments.Insert(detail);
            return(detail);
        }
Exemple #23
0
        /// <summary>
        /// Manually create AR payment and related to specified sales order.
        /// </summary>
        public static void CreatePaymentProcess(SOOrder order)
        {
            ARPaymentEntry pymtEntry = PXGraph.CreateInstance <ARPaymentEntry>();

            string paymentType = ARPaymentType.Payment;

            ARPayment payment = new ARPayment()
            {
                DocType = paymentType
            };

            payment = PXCache <ARPayment> .CreateCopy(pymtEntry.Document.Insert(payment));

            payment.CustomerID         = order.CustomerID;
            payment.CustomerLocationID = order.CustomerLocationID;
            payment.PaymentMethodID    = order.PaymentMethodID;
            payment.PMInstanceID       = order.PMInstanceID;
            payment.CuryOrigDocAmt     = 0m;
            payment.ExtRefNbr          = order.CustomerRefNbr ?? order.OrderNbr;
            payment.DocDesc            = order.OrderDesc;

            payment = pymtEntry.Document.Update(payment);

            SOAdjust adj = new SOAdjust()
            {
                AdjdOrderType = order.OrderType.Trim(),
                AdjdOrderNbr  = order.OrderNbr.Trim()
            };

            pymtEntry.SOAdjustments.Insert(adj);

            if (payment.CuryOrigDocAmt == 0m)
            {
                payment.CuryOrigDocAmt = payment.CurySOApplAmt;
                payment = pymtEntry.Document.Update(payment);
            }
            pymtEntry.Actions.PressSave();

            //if (orderParams.paymentGraph.Actions.Contains("Release"))
            //{
            //    orderParams.paymentGraph.Actions["Release"].Press();
            //}
        }
Exemple #24
0
        protected void ARPayment_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
        {
            if (e.Row == null)
            {
                return;
            }

            ARPayment arPaymentRow = (ARPayment)e.Row;

            PXUIFieldAttribute.SetVisible <FSxARPayment.serviceContractID>(cache, arPaymentRow, PXAccess.FeatureInstalled <FeaturesSet.equipmentManagementModule>() == true && arPaymentRow.DocType == ARPaymentType.Prepayment);

            bool atleastoneFSAdjust = FSAdjustments.SelectWindowed(0, 1).Count > 0;

            FSAdjustments.Cache.AllowInsert = !(atleastoneFSAdjust);
            FSAdjustments.Cache.AllowDelete = false;
            FSAdjustments.AllowSelect       = arPaymentRow.CreatedByScreenID == ID.ScreenID.APPOINTMENT ||
                                              arPaymentRow.CreatedByScreenID == ID.ScreenID.SERVICE_ORDER ||
                                              atleastoneFSAdjust;
        }
        private void SetNumbering(PXCache sender, ARPayment row)
        {
            if (row == null)
            {
                return;
            }
            if (Base.IsWithinContext)
            {
                Numbering numbering = PXSelectJoin <Numbering,
                                                    InnerJoin <GLWorkBook, On <GLWorkBook.voucherNumberingID, Equal <Numbering.numberingID> > >,
                                                    Where <GLWorkBook.workBookID, Equal <Required <GLWorkBook.workBookID> > > > .Select(this.Base, Base.GetContextValue <GLVoucherBatch.workBookID>());

                AutoNumberAttribute.SetNumberingId <ARPayment.refNbr>(sender, row.DocType, numbering.NumberingID);
                if (numbering.UserNumbering == true)
                {
                    sender.RaiseExceptionHandling <ARPayment.refNbr>(row, row.RefNbr, new PXException(GL.Messages.ManualNumberingDisabled));
                }
            }
        }
Exemple #26
0
        protected virtual void ARPayment_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
        {
            ProcessPaymentFilter filter = Filter.Current;

            if (filter != null)
            {
                object OldRow = e.OldRow;
                if (object.ReferenceEquals(e.Row, e.OldRow) && !_copies.TryGetValue(e.Row, out OldRow))
                {
                    decimal?curyval = 0m;
                    decimal?val     = 0m;
                    int?    count   = 0;
                    foreach (ARPayment res in ARPaymentList.Select())
                    {
                        if (res.Selected == true)
                        {
                            curyval += res.CuryOrigDocAmt ?? 0m;
                            val     += res.OrigDocAmt ?? 0m;
                            count++;
                        }
                    }

                    filter.CurySelTotal = curyval;
                    filter.SelTotal     = val;
                    filter.SelCount     = count;
                }
                else
                {
                    ARPayment old_row = OldRow as ARPayment;
                    ARPayment new_row = e.Row as ARPayment;

                    filter.CurySelTotal -= old_row.Selected == true ? old_row.CuryOrigDocAmt : 0m;
                    filter.CurySelTotal += new_row.Selected == true ? new_row.CuryOrigDocAmt : 0m;

                    filter.SelTotal -= old_row.Selected == true ? old_row.OrigDocAmt : 0m;
                    filter.SelTotal += new_row.Selected == true ? new_row.OrigDocAmt : 0m;

                    filter.SelCount -= old_row.Selected == true ? 1 : 0;
                    filter.SelCount += new_row.Selected == true ? 1 : 0;
                }
            }
        }
Exemple #27
0
        public virtual void AssignNumbers(ARPaymentEntryExt pe, ARPayment doc, ref string NextCheckNbr)
        {
            pe.RowPersisting.RemoveHandler <ARAdjust>(pe.ARAdjust_RowPersisting);
            pe.Clear(PXClearOption.PreserveTimeStamp);
            doc = pe.Document.Current = pe.Document.Search <ARPayment.refNbr>(doc.RefNbr, doc.DocType);
            PaymentMethodAccount det = pe.cashaccountdetail.Select();

            var payExt = PXCache <ARPayment> .GetExtension <ARPaymentExt>(pe.Document.Current);

            if (!string.IsNullOrEmpty(NextCheckNbr))
            {
                if (String.IsNullOrEmpty(pe.Document.Current.ExtRefNbr))
                {
                    payExt.StubCntr = 1;
                    payExt.BillCntr = 0;
                    pe.Document.Current.ExtRefNbr = NextCheckNbr;
                    if (String.IsNullOrEmpty(NextCheckNbr))
                    {
                        throw new PXException(AP.Messages.NextCheckNumberIsRequiredForProcessing);
                    }

                    pe.cashaccountdetail.Update(det); // det.APLastRefNumber was modified in StoreStubNumber method

                    NextCheckNbr                         = AutoNumberAttribute.NextNumber(NextCheckNbr);
                    payExt.Printed                       = true;
                    pe.Document.Current.Hold             = false;
                    pe.Document.Current.UpdateNextNumber = true;
                    pe.Document.Update(pe.Document.Current);
                }
                else
                {
                    if (payExt.Printed != true || pe.Document.Current.Hold != false)
                    {
                        payExt.Printed           = true;
                        pe.Document.Current.Hold = false;
                        pe.Document.Update(pe.Document.Current);
                    }
                }
            }
        }
Exemple #28
0
        protected CashAccount findDefaultCashAccount(ARInvoice aDoc)
        {
            CashAccount acct    = null;
            PXCache     cache   = this.arPayment.Cache;
            ARPayment   payment = new ARPayment();

            payment.CustomerID         = aDoc.CustomerID;
            payment.CustomerLocationID = aDoc.CustomerLocationID;
            payment.BranchID           = aDoc.BranchID;
            payment.PaymentMethodID    = aDoc.PaymentMethodID;
            payment.PMInstanceID       = aDoc.PMInstanceID;
            {
                object newValue;
                cache.RaiseFieldDefaulting <ARPayment.cashAccountID>(payment, out newValue);
                Int32?acctID = newValue as Int32?;
                if (acctID.HasValue)
                {
                    acct = PXSelect <CashAccount, Where <CashAccount.cashAccountID, Equal <Required <CashAccount.cashAccountID> > > > .Select(this, acctID);
                }
            }
            return(acct);
        }
Exemple #29
0
        protected virtual void ARAdjust_RowInserted(PXCache sender, PXRowInsertedEventArgs e)
        {
            var adjust = e.Row as ARAdjust;

            foreach (PXResult <ARPayment, CurrencyInfo> res in PXSelectJoin <ARPayment, InnerJoin <CurrencyInfo, On <CurrencyInfo.curyInfoID, Equal <ARPayment.curyInfoID> > >, Where <ARPayment.customerID, Equal <Current <ARInvoice.customerID> >, And <ARPayment.docType, Equal <Required <ARPayment.docType> >, And <ARPayment.refNbr, Equal <Required <ARPayment.refNbr> > > > > > .Select(this, adjust.AdjgDocType, adjust.AdjgRefNbr))
            {
                PXCache <CurrencyInfo> .RestoreCopy(currencyinfo.Current, ((CurrencyInfo)res));

                currencyinfo.Current.CuryInfoID = Document.Current.CuryInfoID;

                ARPayment payment = res;

                adjust.CustomerID = Document.Current.CustomerID;
                //must be from SC for Trial Balance & Release
                adjust.AdjgDocDate      = Document.Current.DocDate;
                adjust.AdjgFinPeriodID  = Document.Current.FinPeriodID;
                adjust.AdjgTranPeriodID = Document.Current.TranPeriodID;
                adjust.AdjgCuryInfoID   = payment.CuryInfoID;
                adjust.AdjgBranchID     = payment.BranchID;
                adjust.AdjdCustomerID   = Document.Current.CustomerID;
                adjust.AdjdARAcct       = payment.ARAccountID;
                adjust.AdjdARSub        = payment.ARSubID;
                adjust.AdjdDocDate      = Document.Current.DocDate;
                adjust.AdjdTranPeriodID = Document.Current.TranPeriodID;
                adjust.AdjdFinPeriodID  = Document.Current.FinPeriodID;

                adjust.Released = false;

                CalcBalances(e.Row, false, e.ExternalCall);

                decimal?CuryApplAmt     = adjust.CuryDocBal;
                decimal?CuryApplDiscAmt = 0m;

                adjust.CuryAdjgAmt     = CuryApplAmt;
                adjust.CuryAdjgDiscAmt = CuryApplDiscAmt;

                CalcBalances(e.Row, true, e.ExternalCall);
            }
        }
        /// <summary>
        /// For an application of a payment to an invoice, calculates the
        /// value of the <see cref="ARAdjust.CuryDocBal"/> field, which is
        /// the remaining balance of the applied payment.
        /// </summary>
        public static void CalculateApplicationDocumentBalance(
            PXCache cache,
            ARPayment payment,
            IAdjustment application,
            CurrencyInfo paymentCurrencyInfo,
            CurrencyInfo invoiceCurrencyInfo)
        {
            decimal CuryDocBal = CalculateApplicationDocumentBalance(
                cache,
                paymentCurrencyInfo,
                invoiceCurrencyInfo,
                payment.DocBal,
                payment.CuryDocBal);

            if (application == null)
            {
                return;
            }

            if (application.Released == false)
            {
                if (application.CuryAdjdAmt > CuryDocBal)
                {
                    // TODO: if reconsidered need to calculate RGOL.
                    // -
                    application.CuryDocBal  = CuryDocBal;
                    application.CuryAdjdAmt = 0m;
                }
                else
                {
                    application.CuryDocBal = CuryDocBal - application.CuryAdjdAmt;
                }
            }
            else
            {
                application.CuryDocBal = CuryDocBal;
            }
        }