public virtual IEnumerable billcontact()
        {
            CustomerPaymentMethod cpm = this.cards.Current;

            if (cpm == null)
            {
                yield break;
            }
            if (cpm.BillContactID.HasValue)
            {
                foreach (Contact it in PXSelect <Contact, Where <Contact.contactID, Equal <Current <CustomerPaymentMethod.billContactID> > > > .Select(this))
                {
                    yield return(it);
                }
            }
            else
            {
                foreach (Contact it in PXSelectJoin <Contact, InnerJoin <Customer, On <Customer.bAccountID, Equal <Contact.bAccountID>,
                                                                                       And <Customer.defBillContactID, Equal <Contact.contactID> > > >,
                                                     Where <Customer.bAccountID, Equal <Current <CustomerPaymentMethod.bAccountID> > > > .Select(this))
                {
                    yield return(it);
                }
            }
        }
        public virtual IEnumerable cards()
        {
            ARExpiredCardFilter filter = this.Filter.Current;

            if (filter != null)
            {
                PXSelectBase <CustomerPaymentMethod> select = new PXSelectJoin <CustomerPaymentMethod,
                                                                                InnerJoin <Customer, On <Customer.bAccountID, Equal <CustomerPaymentMethod.bAccountID>,
                                                                                                         And <Customer.status, NotEqual <Customer.status.inactive> > >,
                                                                                           LeftJoin <CR.Contact, On <CR.Contact.bAccountID, Equal <Customer.bAccountID>,
                                                                                                                     And <CR.Contact.contactID, Equal <Customer.defBillContactID> > > > >,
                                                                                Where <CustomerPaymentMethod.isActive, Equal <boolTrue>,
                                                                                       And <CustomerPaymentMethod.expirationDate, LessEqual <Required <CustomerPaymentMethod.expirationDate> >,
                                                                                            And <CustomerPaymentMethod.expirationDate, GreaterEqual <Required <CustomerPaymentMethod.expirationDate> > > > > >(this);

                if (!string.IsNullOrEmpty(filter.CustomerClassID))
                {
                    select.WhereAnd <Where <Customer.customerClassID, Equal <Required <Customer.customerClassID> > > >();
                }
                if (filter.DefaultOnly == true)
                {
                    select.WhereAnd <Where <CustomerPaymentMethod.pMInstanceID, Equal <Customer.defPMInstanceID> > >();
                }
                //Dates are inverted - end is less then begin
                foreach (PXResult <CustomerPaymentMethod, Customer, Contact> it in select.Select(filter.BeginDate, filter.EndDate, filter.CustomerClassID))
                {
                    CustomerPaymentMethod cpm = (CustomerPaymentMethod)it;
                    if (filter.NotificationSendOnly == true)
                    {
                        if (cpm.LastNotificationDate.HasValue)
                        {
                            if (cpm.ExpirationDate.HasValue)
                            {
                                TimeSpan diff = cpm.ExpirationDate.Value - cpm.LastNotificationDate.Value;
                                if (diff.TotalDays > 0)
                                {
                                    if (diff.TotalDays > 60)
                                    {
                                        continue;
                                    }
                                }
                                else
                                {
                                    if (Math.Abs(diff.TotalDays) > 180)
                                    {
                                        continue;
                                    }
                                }
                            }
                        }
                        else
                        {
                            continue;
                        }
                    }
                    yield return(it);
                }
            }
            yield break;
        }
        public virtual void MailExpirationNotification(CustomerPaymentMethod aCard)
        {
            this.Clear();
            CustomerPaymentMethod doc = this.cards.Select(aCard.PMInstanceID);

            this.cards.Current = doc;
            Customer owner = this.customer.Select();

            this.customer.Current = owner;

            var parameters = new Dictionary <string, string>();

            parameters[FldName_CardType]       = doc.PaymentMethodID;
            parameters[FldName_CardNumber]     = doc.Descr;
            parameters[FldName_ExpirationDate] = doc.ExpirationDate.Value.ToString();
            try
            {
                Activity.SendNotification(ARNotificationSource.Customer, notificationCD, null, parameters);
            }
            catch (PXException e)
            {
                throw new PXException(Messages.CreditCardExpirationNotificationException, e.Message);
            }
            doc.LastNotificationDate = DateTime.Now;
            cards.Update(doc);

            this.Actions.PressSave();
        }
Esempio n. 4
0
        public static CustomerPaymentMethod CreateCopy(this CustomerPaymentMethod cpm, PXCache cache)
        {
            CustomerPaymentMethod ret = cache.CreateCopy(cpm) as CustomerPaymentMethod;
            var test = cache.CreateCopy(cpm).GetType();

            return(ret);
        }
        public virtual IEnumerable cards()
        {
            ARExpiringCardFilter filter = this.Filter.Current;

            if (filter != null)
            {
                PXSelectBase <CustomerPaymentMethod> select = null;
                select = new PXSelectJoin <CustomerPaymentMethod,
                                           InnerJoin <Customer, On <Customer.bAccountID, Equal <CustomerPaymentMethod.bAccountID>,
                                                                    And <Customer.status, NotEqual <BAccount.status.inactive> > >,
                                                      LeftJoin <CR.Contact, On <CR.Contact.bAccountID, Equal <CustomerPaymentMethod.bAccountID>,
                                                                                And <Where2 <Where <CustomerPaymentMethod.billContactID, IsNull,
                                                                                                    And <CR.Contact.contactID, Equal <Customer.defBillContactID> > >,
                                                                                             Or <Where <CustomerPaymentMethod.billContactID, IsNotNull,
                                                                                                        And <CustomerPaymentMethod.billContactID, Equal <CR.Contact.contactID> > > > > > > > >,
                                           Where <CustomerPaymentMethod.expirationDate, GreaterEqual <Required <CustomerPaymentMethod.expirationDate> >,
                                                  And <CustomerPaymentMethod.expirationDate, LessEqual <Required <CustomerPaymentMethod.expirationDate> > > > >(this);

                if (!string.IsNullOrEmpty(filter.CustomerClassID))
                {
                    select.WhereAnd <Where <Customer.customerClassID, Equal <Required <Customer.customerClassID> > > >();
                }

                if (filter.DefaultOnly == true)
                {
                    select.WhereAnd <Where <CustomerPaymentMethod.pMInstanceID, Equal <Customer.defPMInstanceID> > >();
                }
                if ((bool)filter.ActiveOnly)
                {
                    select.WhereAnd <Where <CustomerPaymentMethod.isActive, Equal <BQLConstants.BitOn> > >();
                }
                foreach (PXResult <CustomerPaymentMethod, Customer, Contact> it in select.Select(filter.BeginDate, filter.EndDate, filter.CustomerClassID, filter.ActiveOnly))
                {
                    CustomerPaymentMethod cpm = (CustomerPaymentMethod)it;
                    if (cpm.LastNotificationDate.HasValue && cpm.ExpirationDate.HasValue)
                    {
                        TimeSpan diff = cpm.ExpirationDate.Value - cpm.LastNotificationDate.Value;
                        if (diff.TotalDays > 0)
                        {
                            if (diff.TotalDays < filter.NoteLeftLimit)
                            {
                                continue;
                            }
                        }
                        else
                        {
                            if (Math.Abs(diff.TotalDays) < filter.NoteRightLimit)
                            {
                                continue;
                            }
                        }
                    }

                    yield return(it);
                }
            }
            yield break;
        }
        protected virtual IEnumerable ardocumentlist()
        {
            DateTime now = DateTime.Now.Date;
            PXSelectBase <CCProcTran> tranSelect = new PXSelect <CCProcTran, Where <CCProcTran.docType, Equal <Optional <CCProcTran.docType> >, And <CCProcTran.refNbr, Equal <Optional <CCProcTran.refNbr> > > >, OrderBy <Desc <CCProcTran.tranNbr> > >(this);

            foreach (PXResult <ARPaymentInfo, Customer, CustomerPaymentMethod, PaymentMethod, CCProcessingCenterPmntMethod> it
                     in PXSelectJoin <ARPaymentInfo,
                                      InnerJoin <Customer, On <Customer.bAccountID, Equal <ARPaymentInfo.customerID> >,
                                                 InnerJoin <CustomerPaymentMethod, On <CustomerPaymentMethod.pMInstanceID, Equal <ARPaymentInfo.pMInstanceID> >,
                                                            InnerJoin <PaymentMethod, On <PaymentMethod.paymentMethodID, Equal <ARPaymentInfo.paymentMethodID>,
                                                                                          And <PaymentMethod.paymentType, Equal <PaymentMethodType.creditCard>,
                                                                                               And <PaymentMethod.aRIsProcessingRequired, Equal <True> > > >,
                                                                       LeftJoin <CCProcessingCenterPmntMethod, On <CCProcessingCenterPmntMethod.paymentMethodID, Equal <PaymentMethod.paymentMethodID>,
                                                                                                                   And <CCProcessingCenterPmntMethod.isDefault, Equal <True>,
                                                                                                                        And <CCProcessingCenterPmntMethod.isActive, Equal <True> > > > > > > >,
                                      Where <ARPaymentInfo.released, Equal <False>,
                                             And <ARPaymentInfo.hold, Equal <False>,
                                                  And <ARPaymentInfo.voided, Equal <False>,
                                                       And <ARPaymentInfo.docType, Equal <ARPaymentType.payment>,
                                                            And <ARPaymentInfo.docDate, LessEqual <Current <PaymentFilter.payDate> >,
                                                                 And <ARPaymentInfo.isMigratedRecord, NotEqual <True>,
                                                                      And2 <Where <Customer.statementCycleId, Equal <Current <PaymentFilter.statementCycleId> >,
                                                                                   Or <Current <PaymentFilter.statementCycleId>, IsNull> >,
                                                                            And2 <Where <PaymentMethod.paymentMethodID, Equal <Current <PaymentFilter.paymentMethodID> >,
                                                                                         Or <Current <PaymentFilter.paymentMethodID>, IsNull> >,
                                                                                  And <Match <Customer, Current <AccessInfo.userName> > > > > > > > > > >,
                                      OrderBy <Asc <ARPaymentInfo.refNbr> > > .Select(this))
            {
                ARPaymentInfo                doc  = (ARPaymentInfo)it;
                CustomerPaymentMethod        cpm  = (CustomerPaymentMethod)it;
                CCProcessingCenterPmntMethod pcpm = (CCProcessingCenterPmntMethod)it;
                if (!String.IsNullOrEmpty(this.Filter.Current.ProcessingCenterID) && (this.Filter.Current.ProcessingCenterID != pcpm.ProcessingCenterID))
                {
                    continue;
                }
                ARDocKey key = new ARDocKey(doc);
                if (Filter.Current == null || Filter.Current.CustomerID == null || object.Equals(Filter.Current.CustomerID, doc.CustomerID))
                {
                    doc.PMInstanceDescr    = cpm.Descr;
                    doc.PaymentMethodID    = cpm.PaymentMethodID;
                    doc.IsCCExpired        = (cpm.ExpirationDate < now);
                    doc.ProcessingCenterID = (pcpm != null) ? pcpm.ProcessingCenterID: string.Empty;
                    CCProcTran     lastTran;
                    CCPaymentState ccPaymentState = CCProcTranHelper.ResolveCCPaymentState(tranSelect.Select(doc.DocType, doc.RefNbr), out lastTran);
                    doc.CCPaymentStateDescr = CCProcTranHelper.FormatCCPaymentState(ccPaymentState);
                    doc.CCTranDescr         = (lastTran != null) ? (string.IsNullOrEmpty(lastTran.PCResponseReasonText)?lastTran.PCResponseReasonText: lastTran.ErrorText): String.Empty;
                    if (doc.IsCCExpired == true && String.IsNullOrEmpty(doc.CCTranDescr))
                    {
                        doc.CCTranDescr = Messages.CreditCardIsExpired;
                    }
                    if ((ccPaymentState & CCPaymentState.Captured) == 0)
                    {
                        yield return(doc);
                    }
                }
            }
        }
        public virtual void SetActive(CustomerPaymentMethod aCard, bool on)
        {
            this.Clear();
            CustomerPaymentMethod card = this.cards.Select(aCard.PMInstanceID);

            if (card != null && card.IsActive != on)
            {
                card.IsActive = on;
                card          = this.cards.Update(card);
            }
            this.Actions.PressSave();
        }
        public virtual IEnumerable ViewPaymentMethod(PXAdapter adapter)
        {
            if (this.Cards.Current != null)
            {
                CustomerPaymentMethod payMethod = PXSelect <CustomerPaymentMethod,
                                                            Where <CustomerPaymentMethod.pMInstanceID, Equal <Required <CustomerPaymentMethod.pMInstanceID> > > >
                                                  .Select(this, this.Cards.Current.PMInstanceID);

                CustomerPaymentMethodMaint graph = PXGraph.CreateInstance <CustomerPaymentMethodMaint>();
                graph.CustomerPaymentMethod.Current = payMethod;
                throw new PXPopupRedirectException(graph, Messages.ViewPaymentMethod, true);
            }
            return(adapter.Get());
        }
Esempio n. 9
0
        public virtual IEnumerable viewPaymentMethod(PXAdapter adapter)
        {
            if (this.CCTrans.Current != null)
            {
                CustomerPaymentMethod payMethod = PXSelect <CustomerPaymentMethod,
                                                            Where <CustomerPaymentMethod.pMInstanceID, Equal <Required <CustomerPaymentMethod.pMInstanceID> > > >
                                                  .Select(this, this.CCTrans.Current.PMInstanceID);

                CustomerPaymentMethodMaint graph = PXGraph.CreateInstance <CustomerPaymentMethodMaint>();
                graph.CustomerPaymentMethod.Current = payMethod;
                throw new PXRedirectRequiredException(graph, true, Messages.ViewPaymentMethod)
                      {
                          Mode = PXBaseRedirectException.WindowMode.NewWindow
                      };
            }
            return(adapter.Get());
        }
        public virtual IEnumerable viewProcessingCenter(PXAdapter adapter)
        {
            if (this.PaymentTrans.Current != null)
            {
                ExternalTransactionExt row        = this.PaymentTrans.Current;
                CustomerPaymentMethod  pmInstance = PXSelect <CustomerPaymentMethod, Where <CustomerPaymentMethod.pMInstanceID, Equal <Required <CustomerPaymentMethod.pMInstanceID> > > > .Select(this, row.PMInstanceID);

                CCProcessingCenterMaint graph = PXGraph.CreateInstance <CCProcessingCenterMaint>();
                graph.ProcessingCenter.Current = graph.ProcessingCenter.Search <CCProcessingCenter.processingCenterID>(pmInstance.CCProcessingCenterID);
                if (graph.ProcessingCenter.Current != null)
                {
                    throw new PXRedirectRequiredException(graph, true, Messages.ViewProcessingCenter)
                          {
                              Mode = PXBaseRedirectException.WindowMode.NewWindow
                          };
                }
            }
            return(Filter.Select());
        }
        public virtual IEnumerable ViewCreditCard(PXAdapter adapter)
        {
            if (this.PaymentTrans.Current != null)
            {
                CCProcTran            row        = this.PaymentTrans.Current;
                CustomerPaymentMethod pmInstance = PXSelect <CustomerPaymentMethod, Where <CustomerPaymentMethod.pMInstanceID, Equal <Required <CustomerPaymentMethod.pMInstanceID> > > > .Select(this, row.PMInstanceID);

                CustomerPaymentMethodMaint graph = PXGraph.CreateInstance <CustomerPaymentMethodMaint>();
                graph.CustomerPaymentMethod.Current = graph.CustomerPaymentMethod.Search <CustomerPaymentMethod.pMInstanceID>(pmInstance.PMInstanceID, pmInstance.BAccountID);
                if (graph.CustomerPaymentMethod.Current != null)
                {
                    throw new PXRedirectRequiredException(graph, true, Messages.ViewDocument)
                          {
                              Mode = PXBaseRedirectException.WindowMode.NewWindow
                          };
                }
            }
            return(Filter.Select());
        }
        public virtual IEnumerable cards()
        {
            ARExpiredCardFilter filter = this.Filter.Current;

            if (filter != null)
            {
                PXSelectBase <CustomerPaymentMethod> select = new PXSelectJoin <CustomerPaymentMethod,
                                                                                InnerJoin <Customer, On <Customer.bAccountID, Equal <CustomerPaymentMethod.bAccountID>,
                                                                                                         And <Customer.status, NotEqual <BAccount.status.inactive> > >,
                                                                                           LeftJoin <CR.Contact, On <CR.Contact.bAccountID, Equal <Customer.bAccountID>,
                                                                                                                     And <CR.Contact.contactID, Equal <Customer.defBillContactID> > > > >,
                                                                                Where <CustomerPaymentMethod.isActive, Equal <True>,
                                                                                       And <CustomerPaymentMethod.expirationDate, LessEqual <Required <CustomerPaymentMethod.expirationDate> >,
                                                                                            And <CustomerPaymentMethod.expirationDate, GreaterEqual <Required <CustomerPaymentMethod.expirationDate> > > > > >(this);

                if (!string.IsNullOrEmpty(filter.CustomerClassID))
                {
                    select.WhereAnd <Where <Customer.customerClassID, Equal <Required <Customer.customerClassID> > > >();
                }
                if (filter.DefaultOnly == true)
                {
                    select.WhereAnd <Where <CustomerPaymentMethod.pMInstanceID, Equal <Customer.defPMInstanceID> > >();
                }

                foreach (PXResult <CustomerPaymentMethod, Customer, Contact> it in select.Select(filter.BeginDate, filter.EndDate, filter.CustomerClassID))
                {
                    CustomerPaymentMethod cpm = (CustomerPaymentMethod)it;

                    if (filter.NotificationSendOnly.GetValueOrDefault() == true && !cpm.LastNotificationDate.HasValue)
                    {
                        continue;
                    }
                    yield return(it);
                }
            }
            yield break;
        }
Esempio n. 13
0
        protected virtual IEnumerable ardocumentlist()
        {
            DateTime now = DateTime.Now.Date;
            PXSelectBase <ExternalTransaction> tranSelect = new PXSelect <ExternalTransaction, Where <ExternalTransaction.docType, Equal <Optional <ExternalTransaction.docType> >, And <ExternalTransaction.refNbr, Equal <Optional <ExternalTransaction.refNbr> > > >, OrderBy <Desc <ExternalTransaction.transactionID> > >(this);

            foreach (PXResult <ARPaymentInfo, Customer, PaymentMethod, CustomerPaymentMethod, CCProcessingCenterPmntMethod> it
                     in PXSelectJoin <ARPaymentInfo,
                                      InnerJoin <Customer, On <Customer.bAccountID, Equal <ARPaymentInfo.customerID> >,
                                                 InnerJoin <PaymentMethod, On <PaymentMethod.paymentMethodID, Equal <ARPaymentInfo.paymentMethodID>,
                                                                               And <PaymentMethod.paymentType, Equal <PaymentMethodType.creditCard>,
                                                                                    And <PaymentMethod.aRIsProcessingRequired, Equal <True> > > >,
                                                            LeftJoin <CustomerPaymentMethod, On <CustomerPaymentMethod.pMInstanceID, Equal <ARPaymentInfo.pMInstanceID> >,
                                                                      LeftJoin <CCProcessingCenterPmntMethod, On <CCProcessingCenterPmntMethod.paymentMethodID, Equal <PaymentMethod.paymentMethodID>,
                                                                                                                  And <CCProcessingCenterPmntMethod.isDefault, Equal <True>,
                                                                                                                       And <CCProcessingCenterPmntMethod.isActive, Equal <True> > > > > > > >,
                                      Where <ARPaymentInfo.released, Equal <False>,
                                             And <ARPaymentInfo.hold, Equal <False>,
                                                  And <ARPaymentInfo.voided, Equal <False>,
                                                       And <ARPaymentInfo.docType, Equal <ARPaymentType.payment>,
                                                            And <ARPaymentInfo.docDate, LessEqual <Current <PaymentFilter.payDate> >,
                                                                 And <ARPaymentInfo.isMigratedRecord, NotEqual <True>,
                                                                      And2 <Where <Customer.statementCycleId, Equal <Current <PaymentFilter.statementCycleId> >,
                                                                                   Or <Current <PaymentFilter.statementCycleId>, IsNull> >,
                                                                            And2 <Where <PaymentMethod.paymentMethodID, Equal <Current <PaymentFilter.paymentMethodID> >,
                                                                                         Or <Current <PaymentFilter.paymentMethodID>, IsNull> >,
                                                                                  And <Match <Customer, Current <AccessInfo.userName> > > > > > > > > > >,
                                      OrderBy <Asc <ARPaymentInfo.refNbr> > > .Select(this))
            {
                ARPaymentInfo                doc  = (ARPaymentInfo)it;
                CustomerPaymentMethod        cpm  = (CustomerPaymentMethod)it;
                CCProcessingCenterPmntMethod pcpm = (CCProcessingCenterPmntMethod)it;
                if (!string.IsNullOrEmpty(this.Filter.Current.ProcessingCenterID) && (this.Filter.Current.ProcessingCenterID != pcpm.ProcessingCenterID))
                {
                    continue;
                }
                ARDocKey key = new ARDocKey(doc);
                if (Filter.Current == null || Filter.Current.CustomerID == null || object.Equals(Filter.Current.CustomerID, doc.CustomerID))
                {
                    if (cpm?.PMInstanceID != null)
                    {
                        doc.PMInstanceDescr = cpm.Descr;
                        doc.PaymentMethodID = cpm.PaymentMethodID;
                        doc.IsCCExpired     = (cpm.ExpirationDate < now);
                    }
                    doc.ProcessingCenterID = (pcpm != null) ? pcpm.ProcessingCenterID : string.Empty;
                    ExternalTransactionState paymentState = ExternalTranHelper.GetActiveTransactionState(this, tranSelect.Select(doc.DocType, doc.RefNbr).RowCast <ExternalTransaction>());
                    ExternalTransaction      lastTran     = (ExternalTransaction)paymentState.ExternalTransaction;
                    doc.CCPaymentStateDescr = paymentState.Description;
                    int?tranId = paymentState?.ExternalTransaction?.TransactionID;
                    if (paymentState.HasErrors && tranId != null)
                    {
                        string errText = tranRepo.GetCCProcTranByTranID(tranId).OrderByDescending(i => i.TranNbr).Select(i => i.ErrorText).FirstOrDefault();
                        doc.CCTranDescr = errText;
                    }
                    if (doc.IsCCExpired == true && string.IsNullOrEmpty(doc.CCTranDescr))
                    {
                        doc.CCTranDescr = Messages.CreditCardIsExpired;
                    }
                    if (doc.PMInstanceID == PaymentTranExtConstants.NewPaymentProfile && paymentState.IsOpenForReview)
                    {
                        yield return(doc);
                    }
                    if (doc.PMInstanceID != PaymentTranExtConstants.NewPaymentProfile &&
                        (!paymentState.IsCaptured || (paymentState.IsCaptured && paymentState.IsOpenForReview)))
                    {
                        yield return(doc);
                    }
                }
            }
        }
 public static void SetCardInactive(CustomerPaymentMethodMassProcess aGraph, CustomerPaymentMethod aCard)
 {
     aGraph.SetActive(aCard, false);
 }
 public static void MailExpiringNotification(CustomerPaymentMethodMassProcess aGraph, CustomerPaymentMethod aCard)
 {
     aGraph.MailExpirationNotification(aCard);
 }
Esempio n. 16
0
        public virtual void GenerateProc(Schedule s, short Times, DateTime runDate)
        {
            List <ScheduleDet> sd = GL.ScheduleProcess.MakeSchedule(this, s, Times, runDate);

            ARInvoiceEntry docgraph = CreateGraph();

            foreach (ScheduleDet sdet in sd)
            {
                foreach (PXResult <ARInvoice, Customer, CurrencyInfo> res in PXSelectJoin <ARInvoice, InnerJoin <Customer, On <Customer.bAccountID, Equal <ARInvoice.customerID> >, InnerJoin <CurrencyInfo, On <CurrencyInfo.curyInfoID, Equal <ARInvoice.curyInfoID> > > >, Where <ARInvoice.scheduleID, Equal <Required <ARInvoice.scheduleID> >, And <ARInvoice.scheduled, Equal <boolTrue> > > > .Select(this, s.ScheduleID))
                {
                    docgraph.Clear();
                    docgraph.customer.Current = (Customer)res;
                    ARInvoice    apdoc = (ARInvoice)res;
                    CurrencyInfo info  = (CurrencyInfo)res;

                    CurrencyInfo new_info = PXCache <CurrencyInfo> .CreateCopy(info);

                    new_info.CuryInfoID = null;
                    new_info            = docgraph.currencyinfo.Insert(new_info);

                    ARInvoice new_ardoc = PXCache <ARInvoice> .CreateCopy(apdoc);

                    new_ardoc.CuryInfoID          = new_info.CuryInfoID;
                    new_ardoc.DocDate             = sdet.ScheduledDate;
                    new_ardoc.FinPeriodID         = sdet.ScheduledPeriod;
                    new_ardoc.TranPeriodID        = null;
                    new_ardoc.DueDate             = null;
                    new_ardoc.DiscDate            = null;
                    new_ardoc.CuryOrigDiscAmt     = null;
                    new_ardoc.OrigDiscAmt         = null;
                    new_ardoc.RefNbr              = null;
                    new_ardoc.Scheduled           = false;
                    new_ardoc.CuryLineTotal       = 0m;
                    new_ardoc.CuryVatTaxableTotal = 0m;
                    new_ardoc.CuryVatExemptTotal  = 0m;
                    new_ardoc.NoteID              = null;
                    bool forceClear = false;
                    bool clearPM    = false;
                    if (new_ardoc.PMInstanceID.HasValue)
                    {
                        PXResult <CustomerPaymentMethod, CA.PaymentMethod> pmiResult = (PXResult <CustomerPaymentMethod, CA.PaymentMethod>) PXSelectJoin <CustomerPaymentMethod, InnerJoin <CA.PaymentMethod, On <CA.PaymentMethod.paymentMethodID, Equal <CustomerPaymentMethod.paymentMethodID> > >, Where <CustomerPaymentMethod.pMInstanceID, Equal <Required <CustomerPaymentMethod.pMInstanceID> > > > .Select(docgraph, new_ardoc.PMInstanceID);

                        if (pmiResult != null)
                        {
                            CustomerPaymentMethod pmInstance    = pmiResult;
                            CA.PaymentMethod      paymentMethod = pmiResult;
                            if (pmInstance == null || pmInstance.IsActive != true || paymentMethod.IsActive != true || paymentMethod.UseForAR != true)
                            {
                                clearPM    = true;
                                forceClear = true;
                            }
                        }
                        else
                        {
                            clearPM    = true;
                            forceClear = true;
                        }
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(new_ardoc.PaymentMethodID) == false)
                        {
                            CA.PaymentMethod pm = PXSelect <CA.PaymentMethod, Where <CA.PaymentMethod.paymentMethodID, Equal <Required <CA.PaymentMethod.paymentMethodID> > > > .Select(docgraph, new_ardoc.PaymentMethodID);

                            if (pm == null || pm.IsActive != true || pm.UseForAR != true)
                            {
                                clearPM    = true;
                                forceClear = true;
                            }
                        }
                    }

                    if (clearPM)
                    {
                        new_ardoc.PMInstanceID    = null;
                        new_ardoc.PaymentMethodID = null;
                        new_ardoc.CashAccountID   = null;
                    }

                    new_ardoc = docgraph.Document.Insert(new_ardoc);

                    //force creditrule back
                    docgraph.customer.Current = (Customer)res;

                    if (forceClear == true)
                    {
                        ARInvoice copy = PXCache <ARInvoice> .CreateCopy(new_ardoc);

                        copy.PMInstanceID    = null;
                        copy.PaymentMethodID = null;
                        copy.CashAccountID   = null;
                        new_ardoc            = docgraph.Document.Update(copy);
                    }
                    AddressAttribute.CopyRecord <ARInvoice.billAddressID>(docgraph.Document.Cache, new_ardoc, apdoc, false);
                    ContactAttribute.CopyRecord <ARInvoice.billContactID>(docgraph.Document.Cache, new_ardoc, apdoc, false);

                    TaxAttribute.SetTaxCalc <ARTran.taxCategoryID, ARTaxAttribute>(docgraph.Transactions.Cache, null, TaxCalc.ManualCalc);
                    PXNoteAttribute.SetNote(docgraph.Document.Cache, new_ardoc, PXNoteAttribute.GetNote(Caches[typeof(ARInvoice)], apdoc));
                    PXNoteAttribute.SetFileNotes(docgraph.Document.Cache, new_ardoc, PXNoteAttribute.GetFileNotes(Caches[typeof(ARInvoice)], apdoc));

                    foreach (ARTran aptran in PXSelect <ARTran, Where <ARTran.tranType, Equal <Required <ARTran.tranType> >, And <ARTran.refNbr, Equal <Required <ARTran.refNbr> > > > > .Select(docgraph, apdoc.DocType, apdoc.RefNbr))
                    {
                        ARTran new_aptran = PXCache <ARTran> .CreateCopy(aptran);

                        new_aptran.RefNbr     = null;
                        new_aptran.CuryInfoID = null;
                        docgraph.Transactions.Insert(new_aptran);
                    }

                    foreach (ARTaxTran tax in PXSelect <ARTaxTran, Where <ARTaxTran.tranType, Equal <Required <ARTaxTran.tranType> >, And <ARTaxTran.refNbr, Equal <Required <ARTaxTran.refNbr> > > > > .Select(docgraph, apdoc.DocType, apdoc.RefNbr))
                    {
                        ARTaxTran new_artax = new ARTaxTran();
                        new_artax.TaxID = tax.TaxID;

                        new_artax = docgraph.Taxes.Insert(new_artax);

                        if (new_artax != null)
                        {
                            new_artax = PXCache <ARTaxTran> .CreateCopy(new_artax);

                            new_artax.TaxRate        = tax.TaxRate;
                            new_artax.CuryTaxableAmt = tax.CuryTaxableAmt;
                            new_artax.CuryTaxAmt     = tax.CuryTaxAmt;
                            new_artax = docgraph.Taxes.Update(new_artax);
                        }
                    }

                    docgraph.Save.Press();
                }
                s.LastRunDate = sdet.ScheduledDate;
                Running_Schedule.Cache.Update(s);
            }

            using (PXTransactionScope ts = new PXTransactionScope())
            {
                Running_Schedule.Cache.Persist(PXDBOperation.Update);
                ts.Complete(this);
            }
            Running_Schedule.Cache.Persisted(false);
        }
Esempio n. 17
0
        protected virtual ARInvoice InsertDocument(
            ARInvoiceEntry invoiceEntry,
            ScheduleDet occurrence,
            Customer customer,
            ARInvoice scheduledInvoice,
            CurrencyInfo scheduledInvoiceCurrencyInfo)
        {
            if (scheduledInvoice.Released == true)
            {
                throw new PXException(Messages.ScheduledDocumentAlreadyReleased);
            }

            // Cloning currency info is required because we want to preserve
            // (and not default) the currency rate type of the template document.
            // -
            CurrencyInfo newCurrencyInfo = PXCache <CurrencyInfo> .CreateCopy(scheduledInvoiceCurrencyInfo);

            newCurrencyInfo.CuryInfoID  = null;
            newCurrencyInfo.CuryRate    = null;
            newCurrencyInfo.CuryEffDate = occurrence.ScheduledDate;

            newCurrencyInfo = invoiceEntry.currencyinfo.Insert(newCurrencyInfo);

            ARInvoice newInvoice = PXCache <ARInvoice> .CreateCopy(scheduledInvoice);

            newInvoice.CuryInfoID = newCurrencyInfo.CuryInfoID;
            newInvoice.DocDate    = occurrence.ScheduledDate;

            FinPeriod finPeriod =
                FinPeriodRepository.GetFinPeriodByMasterPeriodID(PXAccess.GetParentOrganizationID(newInvoice.BranchID), occurrence.ScheduledPeriod)
                .GetValueOrRaiseError();

            newInvoice.FinPeriodID = finPeriod.FinPeriodID;

            newInvoice.TranPeriodID        = null;
            newInvoice.DueDate             = null;
            newInvoice.DiscDate            = null;
            newInvoice.CuryOrigDiscAmt     = null;
            newInvoice.OrigDiscAmt         = null;
            newInvoice.RefNbr              = null;
            newInvoice.Scheduled           = false;
            newInvoice.CuryLineTotal       = 0m;
            newInvoice.CuryVatTaxableTotal = 0m;
            newInvoice.CuryVatExemptTotal  = 0m;
            newInvoice.NoteID              = null;
            newInvoice.IsTaxValid          = false;
            newInvoice.IsTaxPosted         = false;
            newInvoice.IsTaxSaved          = false;
            newInvoice.OrigDocType         = scheduledInvoice.DocType;
            newInvoice.OrigRefNbr          = scheduledInvoice.RefNbr;

            invoiceEntry.Document.Cache.SetDefaultExt <ARInvoice.printed>(newInvoice);
            invoiceEntry.Document.Cache.SetDefaultExt <ARInvoice.emailed>(newInvoice);

            bool forceClear         = false;
            bool clearPaymentMethod = false;

            if (newInvoice.PMInstanceID.HasValue)
            {
                PXResult <CustomerPaymentMethod, PaymentMethod> paymentMethodResult = (PXResult <CustomerPaymentMethod, PaymentMethod>)
                                                                                      PXSelectJoin <
                    CustomerPaymentMethod,
                    InnerJoin <PaymentMethod,
                               On <PaymentMethod.paymentMethodID, Equal <CustomerPaymentMethod.paymentMethodID> > >,
                    Where <
                        CustomerPaymentMethod.pMInstanceID, Equal <Required <CustomerPaymentMethod.pMInstanceID> > > >
                                                                                      .Select(invoiceEntry, newInvoice.PMInstanceID);

                if (paymentMethodResult != null)
                {
                    CustomerPaymentMethod customerPaymentMethod = paymentMethodResult;
                    PaymentMethod         paymentMethod         = paymentMethodResult;
                    if (customerPaymentMethod == null || customerPaymentMethod.IsActive != true || paymentMethod.IsActive != true || paymentMethod.UseForAR != true)
                    {
                        clearPaymentMethod = true;
                        forceClear         = true;
                    }
                }
                else
                {
                    clearPaymentMethod = true;
                    forceClear         = true;
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(newInvoice.PaymentMethodID))
                {
                    PaymentMethod paymentMethod = PXSelect <
                        PaymentMethod,
                        Where <PaymentMethod.paymentMethodID, Equal <Required <PaymentMethod.paymentMethodID> > > >
                                                  .Select(invoiceEntry, newInvoice.PaymentMethodID);

                    if (paymentMethod == null || paymentMethod.IsActive != true || paymentMethod.UseForAR != true)
                    {
                        clearPaymentMethod = true;
                        forceClear         = true;
                    }
                }
            }

            if (clearPaymentMethod)
            {
                newInvoice.PMInstanceID    = null;
                newInvoice.PaymentMethodID = null;
                newInvoice.CashAccountID   = null;
            }

            invoiceEntry.ClearRetainageSummary(newInvoice);

            newInvoice = invoiceEntry.Document.Insert(newInvoice);

            if (newInvoice.DontApprove != true)
            {
                // We always generate documents on hold
                // if approval process is enabled in AP.
                // -
                newInvoice.Hold = true;
            }

            newInvoice = invoiceEntry.Document.Update(newInvoice);

            // Force credit rule back
            // -
            invoiceEntry.customer.Current = customer;

            if (forceClear == true)
            {
                ARInvoice copy = PXCache <ARInvoice> .CreateCopy(newInvoice);

                copy.PMInstanceID    = null;
                copy.PaymentMethodID = null;
                copy.CashAccountID   = null;
                newInvoice           = invoiceEntry.Document.Update(copy);
            }

            AddressAttribute.CopyRecord <ARInvoice.billAddressID>(invoiceEntry.Document.Cache, newInvoice, scheduledInvoice, false);
            ContactAttribute.CopyRecord <ARInvoice.billContactID>(invoiceEntry.Document.Cache, newInvoice, scheduledInvoice, false);

            CurrencyInfoAttribute.SetEffectiveDate <ARInvoice.docDate>(
                invoiceEntry.Document.Cache,
                new PXFieldUpdatedEventArgs(newInvoice, null, false));

            PXNoteAttribute.CopyNoteAndFiles(Caches[typeof(ARInvoice)], scheduledInvoice, invoiceEntry.Document.Cache, newInvoice);

            return(newInvoice);
        }