コード例 #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;
            }
        }
コード例 #2
0
        public static void CalculateBalancesAR <TInvoice>(PXGraph graph, PXSelectBase <CurrencyInfo> curyInfoSelect, ARAdjust adj, TInvoice invoice, bool isCalcRGOL, bool DiscOnDiscDate)
            where TInvoice : IInvoice
        {
            Customer currentCustomer = PXSelect <Customer, Where <Customer.bAccountID, Equal <Optional <CABankTran.payeeBAccountID> > > > .Select(graph);

            PaymentEntry.CalcBalances <TInvoice, ARAdjust>(curyInfoSelect, adj.AdjgCuryInfoID, adj.AdjdCuryInfoID, invoice, adj);
            if (DiscOnDiscDate)
            {
                PaymentEntry.CalcDiscount <TInvoice, ARAdjust>(adj.AdjgDocDate, invoice, adj);
            }
            PaymentEntry.WarnDiscount <TInvoice, ARAdjust>(graph, adj.AdjgDocDate, invoice, adj);

            CurrencyInfo pay_info   = curyInfoSelect.Select(adj.AdjgCuryInfoID);
            CurrencyInfo vouch_info = curyInfoSelect.Select(adj.AdjdCuryInfoID);

            if (vouch_info != null && string.Equals(pay_info.CuryID, vouch_info.CuryID) == false)
            {
                adj.AdjdCuryRate = Math.Round((vouch_info.CuryMultDiv == "M" ? (decimal)vouch_info.CuryRate : 1 / (decimal)vouch_info.CuryRate) * (pay_info.CuryMultDiv == "M" ? 1 / (decimal)pay_info.CuryRate : (decimal)pay_info.CuryRate), 8, MidpointRounding.AwayFromZero);
            }
            else
            {
                adj.AdjdCuryRate = 1m;
            }

            if (currentCustomer != null && currentCustomer.SmallBalanceAllow == true && adj.AdjgDocType != ARDocType.Refund && adj.AdjdDocType != ARDocType.CreditMemo)
            {
                decimal      payment_smallbalancelimit;
                CurrencyInfo payment_info = curyInfoSelect.Select(adj.AdjgCuryInfoID);
                PXDBCurrencyAttribute.CuryConvCury(curyInfoSelect.Cache, payment_info, currentCustomer.SmallBalanceLimit ?? 0m, out payment_smallbalancelimit);
                adj.CuryWOBal = payment_smallbalancelimit;
                adj.WOBal     = currentCustomer.SmallBalanceLimit;
            }
            else
            {
                adj.CuryWOBal = 0m;
                adj.WOBal     = 0m;
            }

            PaymentEntry.AdjustBalance <ARAdjust>(curyInfoSelect, adj);
            if (isCalcRGOL && (adj.Voided != true))
            {
                PaymentEntry.CalcRGOL <TInvoice, ARAdjust>(curyInfoSelect, invoice, adj);
                adj.RGOLAmt = (bool)adj.ReverseGainLoss ? -1.0m * adj.RGOLAmt : adj.RGOLAmt;
            }
        }
コード例 #3
0
        public virtual IEnumerable documents()
        {
            PendingInvoiceFilter filter = Filter.Current;
            Dictionary <CashAcctKey, PendingPaymentSummary> result = new Dictionary <CashAcctKey, PendingPaymentSummary>();

            if (filter == null && !filter.PayDate.HasValue)
            {
                return(result.Values);
            }
            PXSelectBase <APInvoice> sel = new PXSelectJoin <APInvoice,
                                                             InnerJoin <CashAccount, On <CashAccount.cashAccountID, Equal <APInvoice.payAccountID> >,
                                                                        LeftJoin <APAdjust, On <APInvoice.docType, Equal <APAdjust.adjdDocType>,
                                                                                                And <APInvoice.refNbr, Equal <APAdjust.adjdRefNbr>, And <APAdjust.released, Equal <BitOff> > > > > >,
                                                             Where <APInvoice.paySel, Equal <BitOn>,
                                                                    And2 <Where <APInvoice.released, Equal <True>, Or <APInvoice.prebooked, Equal <True> > >,
                                                                          And <APInvoice.openDoc, Equal <BitOn> > > >,
                                                             OrderBy <
                                                                 Asc <APInvoice.docType,
                                                                      Asc <APInvoice.refNbr> > >
                                                             >(this);

            /*if(filter.CuryID != null)
             * {
             *      sel.WhereAnd<Where<APInvoice.curyID, Equal<Current<PendingInvoiceFilter.curyID>>>>();
             * }*/
            if (filter.PayDate != null)
            {
                sel.WhereAnd <Where <APInvoice.payDate, LessEqual <Current <PendingInvoiceFilter.payDate> > > >();
            }

            if (filter.PayAccountID != null)
            {
                sel.WhereAnd <Where <APInvoice.payAccountID, Equal <Current <PendingInvoiceFilter.payAccountID> > > >();
            }

            if (filter.PayTypeID != null)
            {
                sel.WhereAnd <Where <APInvoice.payTypeID, Equal <Current <PendingInvoiceFilter.payTypeID> > > >();
            }

            APInvoiceKey lastInvoice = null;

            foreach (PXResult <APInvoice, CashAccount, APAdjust> it in sel.Select())
            {
                APInvoice   inv    = (APInvoice)it;
                CashAccount acct   = (CashAccount)it;
                APAdjust    adjust = (APAdjust)it;
                if (adjust.AdjdDocType != null)
                {
                    continue;                                     //Skip invoices, having unreleased payments
                }
                APInvoiceKey invNbr = new APInvoiceKey(inv.DocType, inv.RefNbr);
                if (lastInvoice != null && lastInvoice.CompareTo(invNbr) == 0)
                {
                    continue;                     //Skip multiple entries for invoice
                }
                //inv.DocCount = it.RowCount;
                lastInvoice = invNbr;
                CashAcctKey           key = new CashAcctKey(inv.PayAccountID.Value, inv.PayTypeID);
                PendingPaymentSummary res = null;
                if (!result.ContainsKey(key))
                {
                    res = new PendingPaymentSummary();
                    res.PayAccountID = inv.PayAccountID;
                    res.PayTypeID    = inv.PayTypeID;
                    res.CuryID       = acct.CuryID;
                    result[key]      = res;
                    //Assign new CyrrencyInfo - to do conersion correctly. RateTypeID must be taken from the Cash Account
                    CurrencyInfo new_info = new CurrencyInfo();
                    new_info.CuryID         = res.CuryID;
                    new_info.CuryRateTypeID = acct.CuryRateTypeID;
                    new_info.CuryEffDate    = filter.PayDate;
                    new_info       = this.CurrencyInfo_CuryInfoID.Insert(new_info);
                    res.CuryInfoID = new_info.CuryInfoID;
                }
                else
                {
                    res = result[key];
                }

                APAdjust adj = new APAdjust();
                adj.VendorID    = inv.VendorID;
                adj.AdjdDocType = inv.DocType;
                adj.AdjdRefNbr  = inv.RefNbr;
                adj.AdjgDocType = APDocType.Check;
                adj.AdjgRefNbr  = " <NEW>";
                try
                {
                    PaymentEntry.CalcBalances <APInvoice, APAdjust>(this.CurrencyInfo_CuryInfoID, res.CuryInfoID, filter.PayDate, inv, adj);
                }
                catch (PXRateIsNotDefinedForThisDateException ex)
                {
                    Documents.Cache.RaiseExceptionHandling <PendingPaymentSummary.curyID>(res, res.CuryID, new PXSetPropertyException(ex.Message, PXErrorLevel.RowError));
                }
                Aggregate(res, new PXResult <APAdjust, APInvoice> (adj, inv), filter.PayDate);
            }
            return(result.Values);
        }