Esempio n. 1
0
        private bool IsJointPayment(APAdjust adjustment)
        {
            var invoice          = InvoiceDataProvider.GetInvoice(Base, adjustment.AdjdDocType, adjustment.AdjdRefNbr);
            var invoiceExtension = PXCache <APInvoice> .GetExtension <APInvoiceJCExt>(invoice);

            return(invoiceExtension.IsJointPayees == true);
        }
 public void UpdateComplianceDocumentsIfRequired(APAdjust adjustment)
 {
     if (IsCheck())
     {
         UpdateComplianceDocuments(adjustment);
     }
 }
Esempio n. 3
0
        public void ValidateVendorAndJointPayees(PXCache cache, APAdjust adjustment, List <JointPayee> jointPayees)
        {
            var projectIds = LienWaiverProjectDataProvider.GetProjectIds(adjustment, cache.Graph).ToList();
            var doesAnyOutstandingComplianceExistForJointVendors = jointPayees.Any(jp =>
                                                                                   lienWaiverDataProvider.DoesAnyOutstandingComplianceExistForJointVendor(jp, projectIds));
            var outstandingCompliances = lienWaiverDataProvider
                                         .GetOutstandingCompliancesForPrimaryVendor(adjustment.VendorID, projectIds).ToList();

            if (outstandingCompliances.Any() && doesAnyOutstandingComplianceExistForJointVendors)
            {
                ValidateVendorAndJointPayees(cache, jointPayees, adjustment, projectIds,
                                             outstandingCompliances);
            }
            else if (outstandingCompliances.Any())
            {
                ValidatePrimaryVendor(cache, adjustment, projectIds, outstandingCompliances);
            }
            else if (doesAnyOutstandingComplianceExistForJointVendors)
            {
                jointPayees.ForEach(jp => ValidateJointPayee(cache, jp, adjustment, projectIds));
            }
            else
            {
                cache.ClearFieldErrors <APAdjust.adjdLineNbr>(adjustment);
            }
        }
        public virtual decimal?GetVendorPreparedBalance(APAdjust adjustment)
        {
            FinDocumentExtKey actualDocLineKey = InvoiceDataProvider.GetSourceEntityKeyByRetainage(Graph,
                                                                                                   adjustment.AdjdDocType, adjustment.AdjdRefNbr, adjustment.AdjdLineNbr);

            decimal?fullAmount;

            if (adjustment.AdjdLineNbr == 0)
            {
                APInvoice bill = InvoiceDataProvider.GetInvoice(Graph, actualDocLineKey.Type, actualDocLineKey.RefNbr);

                fullAmount = bill.CuryOrigDocAmt + bill.CuryRetainageTotal;
            }
            else
            {
                APTran tran = TransactionDataProvider.GetTransaction(Graph, actualDocLineKey.Type, actualDocLineKey.RefNbr, actualDocLineKey.LineNbr);

                fullAmount = tran.CuryOrigTranAmt + tran.CuryRetainageAmt;
            }

            var totalJointAmountOwed = JointPayeeDataProvider.GetJointPayees(Graph, actualDocLineKey.RefNbr, actualDocLineKey.LineNbr)
                                       .Sum(jp => jp.JointAmountOwed.GetValueOrDefault());
            var totalVendorPaymentAmount   = GetTotalVendorPaymentAmount(adjustment, actualDocLineKey.RefNbr, actualDocLineKey.LineNbr);
            var currentVendorPaymentAmount = GetVendorPaymentAmount(adjustment);
            var reversedRetainageAmount    = GetReversedRetainageAmount(actualDocLineKey.RefNbr, actualDocLineKey.LineNbr);

            return(fullAmount + reversedRetainageAmount - totalJointAmountOwed
                   - (totalVendorPaymentAmount - currentVendorPaymentAmount));
        }
 private void UpdateComplianceDocumentAmountsIfRequired(APAdjust adjustment, ComplianceDocument complianceDocument)
 {
     if (complianceDocument.DocumentType == GetLienWaiverDocumentTypeId())
     {
         UpdateComplianceDocumentAmounts(adjustment, complianceDocument);
     }
 }
        private bool PaymentCycleWorkflowIsStartedAndItIsOtherPayment(string paymentDocType, string paymentRefNbr, string origDocType, string origRefNbr)
        {
            PXResult <APInvoice, APAdjust>[] records = PXSelectJoinGroupBy <APInvoice,
                                                                            InnerJoin <APAdjust,
                                                                                       On <APAdjust.adjdDocType, Equal <APInvoice.docType>,
                                                                                           And <APAdjust.adjdRefNbr, Equal <APInvoice.refNbr>,
                                                                                                And <APAdjust.voided, Equal <False> > > > >,
                                                                            Where2 <Where <APAdjust.adjgDocType, Equal <Required <APAdjust.adjgDocType> >,
                                                                                           And <APAdjust.adjgRefNbr, Equal <Required <APAdjust.adjgRefNbr> >,
                                                                                                Or <APInvoiceJCExt.isPaymentCycleWorkflow, Equal <True> > > >,
                                                                                    And <Where <APInvoice.origDocType, Equal <Required <APInvoice.origDocType> >,
                                                                                                And <APInvoice.origRefNbr, Equal <Required <APInvoice.origRefNbr> >,
                                                                                                     And <APInvoice.isRetainageDocument, Equal <True>,
                                                                                                          Or <APInvoice.docType, Equal <Required <APInvoice.docType> >,
                                                                                                              And <APInvoice.refNbr, Equal <Required <APInvoice.refNbr> > > > > > > > >,
                                                                            Aggregate <GroupBy <APInvoiceJCExt.isPaymentCycleWorkflow,
                                                                                                GroupBy <APAdjust.adjgRefNbr,
                                                                                                         GroupBy <APAdjust.adjgDocType> > > > >
                                                       .Select(Graph, paymentDocType, paymentRefNbr, origDocType, origRefNbr, origDocType, origRefNbr)
                                                       .AsEnumerable()
                                                       .Cast <PXResult <APInvoice, APAdjust> >()
                                                       .ToArray();

            return(records.Any(record => ((APInvoice)record).GetExtension <APInvoiceJCExt>().IsPaymentCycleWorkflow == true) &&
                   !records.Any(record =>
            {
                APAdjust adjust = record;
                return adjust.AdjgDocType == paymentDocType && adjust.AdjgRefNbr == paymentRefNbr;
            }));
        }
Esempio n. 7
0
        public override decimal?GetInvoiceBalance(APAdjust adjustment)
        {
            var transaction = TransactionDataProvider.GetTransaction(Graph, adjustment.AdjdDocType,
                                                                     adjustment.AdjdRefNbr, adjustment.AdjdLineNbr);

            return(transaction.CuryTranAmt);
        }
Esempio n. 8
0
 private APTran GetTransaction(APAdjust adjustment)
 {
     return(adjustment.AdjdLineNbr == 0
         ? GetTransactionIfAdjustmentIsRelatedToSingleCommitment(adjustment)
         : TransactionDataProvider.GetTransaction(graph, adjustment.AdjdDocType, adjustment.AdjdRefNbr,
                                                  adjustment.AdjdLineNbr));
 }
Esempio n. 9
0
 private void AddJointAmountsForJointCheckAdjustment(APAdjust adjustment)
 {
     if (Base1.JointPayees.AskExt().IsPositive())
     {
         adjustment.CuryAdjgAmt = PXCache <APAdjust> .GetExtension <ApAdjustExt>(adjustment).AmountToPayPerLine;
     }
 }
        protected virtual decimal?GetVendorAmountToPay(APAdjust adjustment)
        {
            var invoice          = InvoiceDataProvider.GetInvoice(Graph, adjustment.AdjdDocType, adjustment.AdjdRefNbr);
            var invoiceExtension = PXCache <APInvoice> .GetExtension <APInvoiceJCExt>(invoice);

            return(invoiceExtension.AmountToPay);
        }
 public void ValidateAmountPaid(APAdjust adjustment, decimal?amountPaid, bool doNeedShowErrorOnPersist)
 {
     InitializeServices(adjustment.AdjdLineNbr != 0);
     ValidateAmountPaidGreaterThanTotalJointAmountToPay(adjustment, amountPaid, doNeedShowErrorOnPersist);
     ValidateAmountPaidExceedsBillBalance(adjustment, amountPaid, doNeedShowErrorOnPersist);
     ValidateAmountPaidExceedsVendorBalanceWithCashDiscountTaken(adjustment, amountPaid, doNeedShowErrorOnPersist);
 }
Esempio n. 12
0
        private bool DoesAnyOutstandingLienWaiverExist(APAdjust adjustment)
        {
            var projectIds = LienWaiverProjectDataProvider.GetProjectIds(adjustment, Base).ToList();

            return(lienWaiverDataProvider
                   .DoesAnyOutstandingComplianceExistForPrimaryVendor(adjustment.VendorID, projectIds) ||
                   DoesAnyOutstandingLienWaiverExistForJointPayees(adjustment, projectIds));
        }
Esempio n. 13
0
        protected decimal GetAllowableCashDiscountConsiderJointPayees(APAdjust apAdjust, decimal totalJointAmountToPay)
        {
            var vendorPreparedBalance =
                VendorPreparedBalanceCalculationService.GetVendorPreparedBalance(apAdjust);
            var amountPaid = apAdjust.CuryAdjgAmt ?? 0;

            return(Math.Min(vendorPreparedBalance.GetValueOrDefault(), Math.Max(amountPaid - totalJointAmountToPay, 0)));
        }
        private static void InitializeAdjustments(APAdjust adjustment, PayBillsFilter filter)
        {
            PXProcessing <APAdjust> .SetCurrentItem(adjustment);

            adjustment.AdjgDocDate     = filter.PayDate;
            adjustment.AdjgFinPeriodID = filter.PayFinPeriodID;
            PXProcessing <APAdjust> .SetProcessed();
        }
Esempio n. 15
0
        private void SetAmountToPay(APInvoice invoice, APAdjust adjustment)
        {
            var adjustmentExtension = PXCache <APAdjust> .GetExtension <ApAdjustExt>(adjustment);

            var invoiceExtension = PXCache <APInvoice> .GetExtension <APInvoiceJCExt>(invoice);

            adjustmentExtension.AmountToPayPerLine = invoiceExtension.AmountToPay;
        }
Esempio n. 16
0
 protected override decimal?GetTotalVendorPaymentAmount(APAdjust adjustment, string referenceNumber,
                                                        int?origLineNbr)
 {
     return(AdjustmentDataProvider
            .GetAdjustmentsForInvoiceGroup(Graph, referenceNumber, origLineNbr)
            .Where(adj => adj.AdjdRefNbr == adjustment.AdjdRefNbr && adj.AdjdLineNbr == adjustment.AdjdLineNbr)
            .Sum(adj => GetVendorPaymentAmount(adj).GetValueOrDefault()));
 }
Esempio n. 17
0
        protected override decimal GetAllowableCashDiscountConsiderBillBalance(APAdjust apAdjust)
        {
            var billLineBalance = TransactionDataProvider
                                  .GetTransaction(Graph, apAdjust.AdjdDocType, apAdjust.AdjdRefNbr, apAdjust.AdjdLineNbr).CuryTranBal;
            var cashDiscount = billLineBalance - apAdjust.CuryAdjgPPDAmt;

            return(Math.Max(cashDiscount.GetValueOrDefault(), 0));
        }
Esempio n. 18
0
        private bool IsFinalAdjustment(APAdjust adjustment)
        {
            var invoice = InvoiceDataProvider.GetInvoice(Base, adjustment.AdjdDocType, adjustment.AdjdRefNbr);

            invoiceBalanceCalculationService = invoice.PaymentsByLinesAllowed == true
                ? new InvoiceLineBalanceCalculationService(Base)
                : new InvoiceBalanceCalculationService(Base);
            return(invoiceBalanceCalculationService.GetInvoiceBalance(adjustment) == adjustment.CuryAdjgAmt);
        }
Esempio n. 19
0
        private void ValidatePrimaryVendor(PXCache cache, APAdjust adjustment, IEnumerable <int?> projectIds,
                                           IEnumerable <ComplianceDocument> outstandingCompliances)
        {
            var warningMessage          = lienWaiverWarningMessageService.CreateWarningMessage(outstandingCompliances);
            var formattedWarningMessage = PXMessages.LocalizeFormatNoPrefix(warningMessage);

            ValidatePrimaryVendor <APAdjust.adjdLineNbr>(cache, adjustment, adjustment.VendorID, projectIds,
                                                         formattedWarningMessage, PXErrorLevel.RowWarning);
        }
Esempio n. 20
0
        private bool DoesAnyOutstandingLienWaiverExistForJointPayees(APAdjust adjustment, List <int?> projectsIds)
        {
            var jointPayeePayments = JointPayeePaymentDataProvider.GetJointPayeePayments(Base, adjustment.AdjdRefNbr,
                                                                                         adjustment.AdjdDocType, adjustment.AdjdLineNbr);
            var jointPayees = JointPayeeDataProvider.GetJointPayees(Base, jointPayeePayments, adjustment.AdjdLineNbr);

            return(jointPayees.Any(jp => lienWaiverDataProvider
                                   .DoesAnyOutstandingComplianceExistForJointVendor(jp, projectsIds)));
        }
Esempio n. 21
0
        private void SetCashDiscountBalance(APAdjust adjustment)
        {
            var invoice = InvoiceDataProvider.GetInvoice(Base, adjustment.AdjdDocType, adjustment.AdjdRefNbr);

            adjustment.CuryDiscBal = invoice.PaymentsByLinesAllowed == true
                ? TransactionDataProvider.GetTransaction(Base, invoice.DocType, invoice.RefNbr, adjustment.AdjdLineNbr)
                                     .CuryCashDiscBal
                : invoice.CuryOrigDiscAmt;
        }
    protected void APAdjust_RowInserting(PXCache sender, PXRowInsertingEventArgs e)
    {
        APAdjust row = e.Row as APAdjust;

        if (row != null)
        {
            row.GetExtension <APAdjustExt>().InvoiceNbr = GetInvoiceNbr(row);
        }
    }
 public static bool IsRelatedJointPayeePayment(this APAdjust adjustment, JointPayeePayment jointPayeePayment)
 {
     return(adjustment.AdjgRefNbr == jointPayeePayment.PaymentRefNbr &&
            adjustment.AdjgDocType == jointPayeePayment.PaymentDocType &&
            adjustment.AdjdRefNbr == jointPayeePayment.InvoiceRefNbr &&
            adjustment.AdjdDocType == jointPayeePayment.InvoiceDocType &&
            adjustment.AdjNbr == jointPayeePayment.AdjustmentNumber &&
            adjustment.AdjdLineNbr == jointPayeePayment.BillLineNumber);
 }
        public void ClosePaymentCycleWorkflowIfNeeded(APAdjust adjustment)
        {
            var invoice = InvoiceDataProvider.GetInvoice(graph, adjustment.AdjdDocType, adjustment.AdjdRefNbr);

            if (!JointPayeePaymentDataProvider.DoesAnyNonReleasedJointPayeePaymentExist(graph, invoice))
            {
                UpdateIsPaymentCycleWorkflow(invoice, false);
            }
        }
        private void UpdateComplianceDocumentData(APAdjust adjustment, ComplianceDocument complianceDocument)
        {
            var payment = graph.Document.Current;

            ComplianceDocumentRefNoteAttribute.SetComplianceDocumentReference <ComplianceDocument.apCheckId>(
                graph.Caches <ComplianceDocument>(), complianceDocument, payment.DocType, payment.RefNbr, payment.NoteID);

            UpdateComplianceDocumentAmountsIfRequired(adjustment, complianceDocument);
        }
Esempio n. 26
0
        protected virtual void InsertUpdatePOAdjust(APAdjust apadjust)
        {
            if (Base.Document.Current?.DocType.IsNotIn(APDocType.Prepayment, APDocType.VoidCheck) == true ||
                apadjust?.AdjdDocType != APDocType.Prepayment)
            {
                return;
            }

            var prepaymentRequests = new PXSelectJoin <POOrderPrepayment,
                                                       InnerJoin <POOrder, On <POOrderPrepayment.orderType, Equal <POOrder.orderType>, And <POOrderPrepayment.orderNbr, Equal <POOrder.orderNbr> > > >,
                                                       Where <POOrderPrepayment.aPDocType, Equal <Required <APAdjust.adjdDocType> >,
                                                              And <POOrderPrepayment.aPRefNbr, Equal <Required <APAdjust.adjdRefNbr> >,
                                                                   And <POOrderPrepayment.aPDocType, Equal <APDocType.prepayment> > > > >(Base)
                                     .Select(apadjust.AdjdDocType, apadjust.AdjdRefNbr);

            foreach (PXResult <POOrderPrepayment, POOrder> row in prepaymentRequests)
            {
                POOrder           order             = row;
                POOrderPrepayment prepaymentRequest = row;

                POAdjust poadjustment = new PXSelect <POAdjust,
                                                      Where <POAdjust.adjgDocType, Equal <Current <APPayment.docType> >,
                                                             And <POAdjust.adjgRefNbr, Equal <Current <APPayment.refNbr> >,
                                                                  And <POAdjust.adjNbr, Equal <Current <APPayment.adjCntr> >,
                                                                       And <POAdjust.adjdDocType, Equal <Required <APInvoice.docType> >,
                                                                            And <POAdjust.adjdRefNbr, Equal <Required <APInvoice.refNbr> > > > > > > >(Base)
                                        .Select(apadjust.AdjdDocType, apadjust.AdjdRefNbr);

                if (poadjustment == null)
                {
                    poadjustment = POAdjustments.Insert(new POAdjust()
                    {
                        AdjgDocType   = Base.Document.Current.DocType,
                        AdjgRefNbr    = Base.Document.Current.RefNbr,
                        AdjdOrderType = prepaymentRequest.OrderType,
                        AdjdOrderNbr  = prepaymentRequest.OrderNbr,
                        AdjdDocType   = apadjust.AdjdDocType,
                        AdjdRefNbr    = apadjust.AdjdRefNbr,
                        AdjNbr        = Base.Document.Current.AdjCntr,
                        IsRequest     = true,
                    });
                }

                if (order.CuryID == Base.Document.Current.CuryID)
                {
                    POAdjustments.Cache.SetValueExt <POAdjust.curyAdjgAmt>(poadjustment, apadjust.CuryAdjgAmt);
                }
                else
                {
                    PXCurrencyAttribute.CuryConvCury(Base.Document.Cache, Base.Document.Current, apadjust.AdjAmt ?? 0, out decimal curyamount);
                    POAdjustments.Cache.SetValueExt <POAdjust.curyAdjgAmt>(poadjustment, curyamount);
                }

                POAdjustments.Update(poadjustment);
            }
        }
Esempio n. 27
0
        protected decimal GetAllowableCashDiscountConsiderVendorPreparedBalance(APAdjust apAdjust)
        {
            var vendorPreparedBalance =
                VendorPreparedBalanceCalculationService.GetVendorPreparedBalance(apAdjust);
            var cashDiscountTakenFromOtherNonReleasedChecks =
                GetNonReleasedCashDiscountTakenExceptCurrentAdjustment(apAdjust);
            var cashDiscount = vendorPreparedBalance - cashDiscountTakenFromOtherNonReleasedChecks;

            return(Math.Max(cashDiscount.GetValueOrDefault(), 0));
        }
        protected void AddRevertingJointPayeePayments(APAdjust originalAdjustment, APAdjust revertedAdjustment)
        {
            var originalJointPayeePayments =
                JointPayeePaymentDataProvider.GetJointPayeePayments(Base, originalAdjustment);

            foreach (var jointPayeePayment in originalJointPayeePayments)
            {
                AddRevertingJointPayeePayment(jointPayeePayment, revertedAdjustment);
            }
        }
        private void UpdateComplianceDocumentAmounts(APAdjust adjustment, ComplianceDocument complianceDocument)
        {
            complianceDocument.LienWaiverAmount = adjustment.CuryAdjgAmt;
            var jointPayeePayments = GetJointPayeePaymentsAndJointPayees(adjustment);

            if (jointPayeePayments.Any())
            {
                complianceDocument.JointAmount = GetTotalJointAmountToPay(jointPayeePayments);
            }
        }
        private void UpdateComplianceDocuments(APAdjust adjustment)
        {
            var complianceDocuments = GetRelatedComplianceDocuments(adjustment.AdjdRefNbr, adjustment.AdjdDocType);

            graph.Caches <JointPayeePayment>().Persist(PXDBOperation.Insert);
            foreach (var complianceDocument in complianceDocuments)
            {
                UpdateComplianceDocument(adjustment, complianceDocument);
            }
        }