Exemplo n.º 1
0
        public virtual IEnumerable documents()
        {
            DocFilter filter = Filter.Current;
            Dictionary <CashAcctKey, CheckSummary> result = new Dictionary <CashAcctKey, CheckSummary>();

            if (filter == null && !filter.PayDate.HasValue)
            {
                return(result.Values);
            }
            PXSelectBase <APPaymentExt> sel = new PXSelectJoin <APPaymentExt,
                                                                InnerJoin <CashAccount, On <CashAccount.cashAccountID, Equal <APPaymentExt.cashAccountID> >,
                                                                           InnerJoin <Vendor, On <Vendor.bAccountID, Equal <APPayment.vendorID> >,
                                                                                      InnerJoin <PaymentMethod, On <PaymentMethod.paymentMethodID, Equal <APPaymentExt.paymentMethodID> >,
                                                                                                 LeftJoin <CABatchDetail, On <CABatchDetail.origModule, Equal <GL.BatchModule.moduleAP>,
                                                                                                                              And <CABatchDetail.origDocType, Equal <APPayment.docType>,
                                                                                                                                   And <CABatchDetail.origRefNbr, Equal <APPayment.refNbr> > > > > > > >,
                                                                Where <APPaymentExt.released, Equal <boolFalse>,
                                                                       And <APPayment.docType, NotEqual <APDocType.prepayment>,
                                                                            And <APPayment.docType, NotEqual <APDocType.refund>,

                                                                                 And <APPaymentExt.openDoc, Equal <boolTrue>,
                                                                                      And2 <Match <Vendor, Current <AccessInfo.userName> >,
                                                                                            And <Where2 <Where <PaymentMethod.aPCreateBatchPayment, Equal <True>, And <CABatchDetail.batchNbr, IsNull> >,
                                                                                                         Or <Where <PaymentMethod.aPCreateBatchPayment, Equal <False>,
                                                                                                                    And <PaymentMethod.aPPrintChecks, Equal <boolTrue>,
                                                                                                                         And <APPayment.printed, Equal <boolFalse> > > > > > > > > > > >,
                                                                OrderBy <
                                                                    Asc <APPaymentExt.docType,
                                                                         Asc <APPaymentExt.refNbr> > >
                                                                >(this);

            if (filter.PayDate != null)
            {
                sel.WhereAnd <Where <APPaymentExt.docDate, LessEqual <Current <DocFilter.payDate> > > >();
            }

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

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

            APPaymentKey lastInvoice = null;

            foreach (PXResult <APPaymentExt, CashAccount, Vendor, PaymentMethod, CABatchDetail> it in sel.Select())
            {
                APPaymentExt inv    = (APPaymentExt)it;
                CashAccount  acct   = (CashAccount)it;
                APPaymentKey invNbr = new APPaymentKey(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.CashAccountID.Value, inv.PaymentMethodID);
                CheckSummary res = null;
                if (!result.ContainsKey(key))
                {
                    res = new CheckSummary();
                    res.PayAccountID = inv.CashAccountID;
                    res.PayTypeID    = inv.PaymentMethodID;
                    res.CuryID       = acct.CuryID;
                    res.CuryInfoID   = inv.CuryInfoID;
                    result[key]      = res;
                }
                else
                {
                    res = result[key];
                }
                Aggregate(res, inv, filter.PayDate);
            }
            return(result.Values);
        }
Exemplo n.º 2
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);
        }