Exemple #1
0
        protected virtual void CATransfer_InAccountID_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            CATransfer   transfer      = e.Row as CATransfer;
            CashAccount  cashaccountIn = (CashAccount)PXSelectorAttribute.Select <CATransfer.inAccountID>(sender, transfer);
            CurrencyInfo currinfo      = CurInfoIN.Select();

            if (cashaccountIn?.CuryRateTypeID != null)
            {
                currinfo.CuryRateTypeID = cashaccountIn.CuryRateTypeID;
            }
            else
            {
                CMSetup cmsetup = PXSelect <CMSetup> .Select(this);

                if (!string.IsNullOrEmpty(cmsetup?.CARateTypeDflt))
                {
                    currinfo.CuryRateTypeID = cmsetup.CARateTypeDflt;
                }
            }
            sender.SetDefaultExt <CATransfer.inCuryID>(transfer);
            CurInfoIN.Cache.RaiseFieldUpdated <CurrencyInfo.curyRateTypeID>(currinfo, null);

            if (cashaccountIn?.Reconcile != true)
            {
                transfer.ClearedIn   = true;
                transfer.ClearDateIn = transfer.InDate;
            }
            else
            {
                transfer.ClearedIn   = false;
                transfer.ClearDateIn = null;
            }
            CurrencyInfoAttribute.SetEffectiveDate <CATransfer.inDate, CATransfer.inCuryInfoID>(sender, e);
        }
Exemple #2
0
        protected virtual void CATransfer_OutAccountID_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            CATransfer  transfer       = e.Row as CATransfer;
            CashAccount cashaccountOut = (CashAccount)PXSelectorAttribute.Select <CATransfer.outAccountID>(sender, e.Row);

            CurrencyInfo currinfo = CurInfoOUT.Select();

            if (cashaccountOut?.CuryRateTypeID != null)
            {
                currinfo.CuryRateTypeID = cashaccountOut.CuryRateTypeID;
            }
            else
            {
                CMSetup cmsetup = PXSelect <CMSetup> .Select(this);

                if (!string.IsNullOrEmpty(cmsetup?.CARateTypeDflt))
                {
                    currinfo.CuryRateTypeID = cmsetup.CARateTypeDflt;
                }
            }
            sender.SetDefaultExt <CATransfer.outCuryID>(transfer);
            CurInfoOUT.Update(currinfo);

            if (cashaccountOut?.Reconcile != true)
            {
                transfer.ClearedOut   = true;
                transfer.ClearDateOut = transfer.OutDate;
            }
            else
            {
                transfer.ClearedOut   = false;
                transfer.ClearDateOut = null;
            }
            CurrencyInfoAttribute.SetEffectiveDate <CATransfer.outDate, CATransfer.outCuryInfoID>(sender, e);
        }
        protected virtual void TaxAdjustment_VendorID_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            TaxAdjustment doc = (TaxAdjustment)e.Row;

            if (doc == null)
            {
                return;
            }

            if (PXAccess.FeatureInstalled <FeaturesSet.multicurrency>())
            {
                if (e.ExternalCall || sender.GetValuePending <TaxAdjustment.curyID>(doc) == null)
                {
                    CurrencyInfo info = CurrencyInfoAttribute.SetDefaults <TaxAdjustment.curyInfoID>(sender, doc);

                    string message = PXUIFieldAttribute.GetError <CurrencyInfo.curyEffDate>(currencyinfo.Cache, info);
                    if (string.IsNullOrEmpty(message) == false)
                    {
                        sender.RaiseExceptionHandling <TaxAdjustment.docDate>(doc, doc.DocDate, new PXSetPropertyException(message, PXErrorLevel.Warning));
                    }

                    if (info != null)
                    {
                        doc.CuryID = info.CuryID;
                    }
                }
            }

            sender.SetDefaultExt <TaxAdjustment.vendorLocationID>(e.Row);
            sender.SetDefaultExt <TaxAdjustment.taxPeriod>(e.Row);
            sender.SetDefaultExt <TaxAdjustment.adjAccountID>(e.Row);
            sender.SetDefaultExt <TaxAdjustment.adjSubID>(e.Row);
        }
Exemple #4
0
        protected virtual void CAExpense_CashAccountID_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            CAExpense   expense     = e.Row as CAExpense;
            CashAccount cashaccount = (CashAccount)PXSelectorAttribute.Select <CAExpense.cashAccountID>(sender, e.Row);

            UpdateCuryInfoExpense(sender, expense);

            if (cashaccount?.Reconcile != true)
            {
                expense.Cleared   = true;
                expense.ClearDate = expense.TranDate;
            }
            else
            {
                expense.Cleared   = false;
                expense.ClearDate = null;
            }

            CurrencyInfo currinfo = PXSelect <CurrencyInfo, Where <CurrencyInfo.curyInfoID, Equal <Required <CAExpense.curyInfoID> >,
                                                                   And <CurrencyInfo.curyID, Equal <Required <CAExpense.curyID> > > > > .Select(this, expense.CuryInfoID, expense.CuryID);

            if (currinfo != null)
            {
                CurrencyInfoAttribute.SetEffectiveDate <CAExpense.tranDate, CAExpense.curyInfoID>(sender, e);
            }
        }
Exemple #5
0
        /// <summary>The FieldUpdated2 event handler for the <see cref="Document.BAccountID" /> field. When the BAccountID field value is changed, <see cref="Document.CuryID" /> is assigned the default
        /// value.</summary>
        /// <param name="e">Parameters of the event.</param>
        protected virtual void _(Events.FieldUpdated <Document, Document.bAccountID> e)
        {
            if (PXAccess.FeatureInstalled <FeaturesSet.multicurrency>())
            {
                if (e.Row == null)
                {
                    return;
                }

                if (e.ExternalCall || e.Row.CuryID == null)
                {
                    CurrencyInfo info    = CurrencyInfoAttribute.SetDefaults <Document.curyInfoID>(e.Cache, e.Row, e.Cache.GetMain(e.Row).GetType());
                    string       message = PXUIFieldAttribute.GetError <CurrencyInfo.curyEffDate>(e.Cache.Graph.Caches[typeof(CurrencyInfo)], info);
                    if (string.IsNullOrEmpty(message) == false)
                    {
                        Documents.Cache.RaiseExceptionHandling <Document.documentDate>(e.Row,
                                                                                       e.Row.DocumentDate,
                                                                                       new PXSetPropertyException(message, PXErrorLevel.Warning));
                    }

                    if (info != null)
                    {
                        Documents.Cache.SetValue <Document.curyID>(e.Row, info.CuryID);
                    }
                }
            }
        }
Exemple #6
0
        protected virtual void PTInstStatement_CashAccountID_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            if (this.cashAccount.Current == null || this.cashAccount.Current.AccountID != ((PTInstStatement)e.Row).CashAccountID)
            {
                this.cashAccount.Current = (CashAccount)PXSelectorAttribute.Select <CashAccount.cashAccountID>(sender, e.Row);
            }

            //if ((bool)CMSetup.Current.MCActivated)
            {
                if (e.ExternalCall || sender.GetValuePending <PTInstStatement.curyID>(e.Row) == null)
                {
                    CurrencyInfo info = CurrencyInfoAttribute.SetDefaults <PTInstStatement.curyInfoID>(sender, e.Row);

                    string message = PXUIFieldAttribute.GetError <CurrencyInfo.curyEffDate>(currencyinfo.Cache, info);
                    if (string.IsNullOrEmpty(message) == false)
                    {
                        sender.RaiseExceptionHandling <PTInstStatement.statementDate>(e.Row, ((PTInstStatement)e.Row).StatementDate, new PXSetPropertyException(message, PXErrorLevel.Warning));
                    }

                    if (info != null)
                    {
                        ((PTInstStatement)e.Row).CuryID = info.CuryID;
                    }
                }
            }
        }
Exemple #7
0
        protected virtual void CRServiceCase_CustomerID_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            if (cmSetup.Current.MCActivated == true &&
                (e.ExternalCall || sender.GetValuePending <CRServiceCase.curyID>(e.Row) == null))
            {
                var info = CurrencyInfoAttribute.SetDefaults <CRServiceCase.curyInfoID>(sender, e.Row);
                var row  = (CRServiceCase)e.Row;

                var message = PXUIFieldAttribute.GetError <CurrencyInfo.curyEffDate>(dummyCuryInfo.Cache, info);
                if (!string.IsNullOrEmpty(message))
                {
                    sender.RaiseExceptionHandling <CRServiceCase.createdDateTime>(e.Row,
                                                                                  row.CreatedDateTime,
                                                                                  new PXSetPropertyException(message, PXErrorLevel.Warning));
                }
                if (info != null)
                {
                    row.CuryID = info.CuryID;
                }
            }

            SharedRecordAttribute.DefaultRecord <CRServiceCase.destinationAddressID>(sender, e.Row);
            SharedRecordAttribute.DefaultRecord <CRServiceCase.billAddressID>(sender, e.Row);
            sender.SetDefaultExt <CRServiceCase.locationID>(e.Row);
        }
        protected virtual void TaxAdjustment_DocDate_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            CurrencyInfoAttribute.SetEffectiveDate <TaxAdjustment.docDate>(sender, e);

            foreach (TaxTran taxTran in Transactions.Select())
            {
                SetTaxTranTranDate(taxTran);

                _TaxRev = SalesTaxRev_Select.Select(taxTran.TaxID, taxTran.TaxType, taxTran.TranDate);

                Transactions.Cache.SetDefaultExt <TaxTran.taxBucketID>(taxTran);
                Transactions.Cache.SetDefaultExt <TaxTran.taxRate>(taxTran);
            }

            _TaxRev = null;

            if (!(e.Row is TaxAdjustment taxAdjustment) || taxAdjustment.TaxPeriod != null || taxAdjustment.DocDate == null)
            {
                return;
            }

            TaxPeriod taxPeriod = GetTaxPeriodForTaxAdjustment(taxAdjustment);

            if (taxPeriod == null)
            {
                return;
            }

            if (taxPeriod.Status == TaxPeriodStatus.Prepared)
            {
                sender.SetValue <TaxAdjustment.taxPeriod>(taxAdjustment, taxPeriod.TaxPeriodID);
            }
        }
Exemple #9
0
 /// <summary>The FieldDefaulting2 event handler for the <see cref="Document.DocumentDate" /> field. When the DocumentDate field value is changed, <see cref="CurrencyInfo.curyEffDate"/> is changed to DocumentDate value.</summary>
 /// <param name="e">Parameters of the event.</param>
 protected virtual void _(Events.FieldUpdated <Document, Document.documentDate> e)
 {
     if (e.Row == null)
     {
         return;
     }
     CurrencyInfoAttribute.SetEffectiveDate <Document.documentDate>(Documents.Cache,
                                                                    new PXFieldUpdatedEventArgs(e.Row, e.OldValue, e.ExternalCall));
 }
Exemple #10
0
        protected virtual void EPExpenseClaimDetails_RowInserted(PXCache cache, PXRowInsertedEventArgs e)
        {
            CurrencyInfo info = CurrencyInfoAttribute.SetDefaults <EPExpenseClaimDetails.curyInfoID>(cache, e.Row);

            if (info != null)
            {
                ((EPExpenseClaimDetails)e.Row).CuryID = info.CuryID;
            }
        }
Exemple #11
0
        protected virtual void CAExpense_TranDate_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            CAExpense expense = e.Row as CAExpense;

            CurrencyInfo currinfo = PXSelect <CurrencyInfo, Where <CurrencyInfo.curyInfoID, Equal <Required <CAExpense.curyInfoID> >, And <CurrencyInfo.curyID, Equal <Required <CAExpense.curyID> > > > > .Select(this, expense.CuryInfoID, expense.CuryID);

            if (currinfo != null)
            {
                CurrencyInfoAttribute.SetEffectiveDate <CAExpense.tranDate, CAExpense.curyInfoID>(sender, e);
            }
        }
        public virtual void DefaultCardCurrencyInfo(PXCache cache, EPExpenseClaimDetails document)
        {
            if (document.CardCuryInfoID != null)
            {
                CurrencyInfo cardCuryInfo = CurrencyInfoAttribute.SetDefaults <EPExpenseClaimDetails.cardCuryInfoID>(cache, document);

                if (cardCuryInfo != null)
                {
                    document.CardCuryID = cardCuryInfo.CuryID;
                }
            }
        }
Exemple #13
0
        protected virtual void CATransfer_InDate_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            CurrencyInfoAttribute.SetEffectiveDate <CATransfer.inDate, CATransfer.inCuryInfoID>(sender, e);
            CATransfer transfer = e.Row as CATransfer;

            if (transfer.ClearedIn == true)
            {
                CashAccount cashaccountIn = (CashAccount)PXSelectorAttribute.Select <CATransfer.inAccountID>(sender, e.Row);
                if ((cashaccountIn != null) && (cashaccountIn.Reconcile != true))
                {
                    transfer.ClearDateIn = transfer.InDate;
                }
            }
        }
        protected virtual void RQBiddingVendor_RowInserted(PXCache sender, PXRowInsertedEventArgs e)
        {
            RQBiddingVendor row = (RQBiddingVendor)e.Row;

            if (row != null)
            {
                if ((bool)cmsetup.Current.MCActivated && row.ReqNbr != null && row.VendorID != null)
                {
                    BVendor.Current = (Vendor)BVendor.View.SelectSingleBound(new object[] { e.Row });
                    CurrencyInfo info = CurrencyInfoAttribute.SetDefaults <RQBiddingVendor.curyInfoID>(sender, e.Row);
                    sender.SetDefaultExt <RQBiddingVendor.curyID>(e.Row);
                }
            }
        }
Exemple #15
0
        protected virtual void RQBiddingVendor_RowInserted(PXCache sender, PXRowInsertedEventArgs e)
        {
            RQBiddingVendor row = (RQBiddingVendor)e.Row;

            if (row != null)
            {
                if (PXAccess.FeatureInstalled <FeaturesSet.multicurrency>() && row.ReqNbr != null && row.VendorID != null)
                {
                    BVendor.Current = (Vendor)BVendor.View.SelectSingleBound(new object[] { e.Row });
                    CurrencyInfo info = CurrencyInfoAttribute.SetDefaults <RQBiddingVendor.curyInfoID>(sender, e.Row);
                    sender.SetDefaultExt <RQBiddingVendor.curyID>(e.Row);
                }
            }
        }
Exemple #16
0
        protected virtual void EPExpenseClaimDetails_EmployeeID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
        {
            var row = e.Row as EPExpenseClaimDetails;

            if (!IsCopyPasteContext && ((row.CuryTranAmt ?? 0) == 0))
            {
                CurrencyInfo info = CurrencyInfoAttribute.SetDefaults <EPExpenseClaim.curyInfoID>(cache, row);

                if (info != null)
                {
                    ((EPExpenseClaimDetails)e.Row).CuryID = info.CuryID;
                }
            }
            cache.SetDefaultExt <EPExpenseClaim.taxZoneID>(row);
        }
Exemple #17
0
        protected virtual void CATransfer_OutDate_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            CurrencyInfoAttribute.SetEffectiveDate <CATransfer.outDate, CATransfer.outCuryInfoID>(sender, e);
            CATransfer transfer = e.Row as CATransfer;

            if (transfer.ClearedOut == true)
            {
                CashAccount cashaccountOut = (CashAccount)PXSelectorAttribute.Select <CATransfer.outAccountID>(sender, e.Row);
                if ((cashaccountOut != null) && (cashaccountOut.Reconcile != true))
                {
                    transfer.ClearDateOut = transfer.OutDate;
                }
            }
            sender.SetValueExt <CATransfer.inDate>(transfer, transfer.OutDate);
        }
Exemple #18
0
        protected virtual void TaxAdjustment_DocDate_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            CurrencyInfoAttribute.SetEffectiveDate <TaxAdjustment.docDate>(sender, e);

            foreach (TaxTran taxTran in Transactions.Select())
            {
                SetTaxTranTranDate(taxTran);

                _TaxRev = SalesTaxRev_Select.Select(taxTran.TaxID, taxTran.TaxType, taxTran.TranDate);

                Transactions.Cache.SetDefaultExt <TaxTran.taxBucketID>(taxTran);
                Transactions.Cache.SetDefaultExt <TaxTran.taxRate>(taxTran);
            }

            _TaxRev = null;
        }
Exemple #19
0
        protected virtual void EPExpenseClaim_EmployeeID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
        {
            EPEmployee.RaiseFieldUpdated(cache, e.Row);

            if (cmsetup.Current.MCActivated == true)
            {
                CurrencyInfo info = CurrencyInfoAttribute.SetDefaults <EPExpenseClaim.curyInfoID>(cache, e.Row);

                string message = PXUIFieldAttribute.GetError <CurrencyInfo.curyEffDate>(currencyinfo.Cache, info);
                if (string.IsNullOrEmpty(message) == false)
                {
                    cache.RaiseExceptionHandling <EPExpenseClaim.docDate>(e.Row, ((EPExpenseClaim)e.Row).DocDate, new PXSetPropertyException(message, PXErrorLevel.Warning));
                }
                if (info != null)
                {
                    ((EPExpenseClaim)e.Row).CuryID = info.CuryID;
                }
            }
            cache.SetDefaultExt <EPExpenseClaim.locationID>(e.Row);
            cache.SetDefaultExt <EPExpenseClaim.departmentID>(e.Row);
        }
        public virtual void GenerateProc(Schedule schedule, short times, DateTime runDate)
        {
            string lastBatchNbr = "0000000000";
            long   lastInfoID   = -1;

            IEnumerable <ScheduleDet> occurrences = new Scheduler(this).MakeSchedule(schedule, times, runDate);

            using (PXTransactionScope ts = new PXTransactionScope())
            {
                foreach (ScheduleDet occurrence in occurrences)
                {
                    foreach (BatchNew scheduledBatch in PXSelect <
                                 BatchNew,
                                 Where <
                                     BatchNew.scheduleID, Equal <Optional <Schedule.scheduleID> >,
                                     And <BatchNew.scheduled, Equal <boolTrue> > > >
                             .Select(this, schedule.ScheduleID))
                    {
                        BatchNew copy = PXCache <BatchNew> .CreateCopy(scheduledBatch);

                        copy.OrigBatchNbr = copy.BatchNbr;
                        copy.OrigModule   = copy.Module;
                        copy.CuryInfoID   = null;
                        copy.NumberCode   = "GLREC";
                        copy.NoteID       = null;

                        CurrencyInfo info = (CurrencyInfo)PXSelect <
                            CurrencyInfo,
                            Where <CurrencyInfo.curyInfoID, Equal <Required <CurrencyInfo.curyInfoID> > > >
                                            .Select(this, scheduledBatch.CuryInfoID);

                        if (info != null)
                        {
                            CurrencyInfo infocopy = PXCache <CurrencyInfo> .CreateCopy(info);

                            infocopy.CuryInfoID = lastInfoID;
                            copy.CuryInfoID     = lastInfoID;

                            CuryInfo_Created.Cache.Insert(infocopy);
                        }

                        copy.Posted          = false;
                        copy.Released        = false;
                        copy.Status          = BatchStatus.Balanced;
                        copy.Scheduled       = false;
                        copy.AutoReverseCopy = false;

                        copy.DateEntered = occurrence.ScheduledDate;

                        FinPeriod finPeriod =
                            FinPeriodRepository.GetFinPeriodByMasterPeriodID(PXAccess.GetParentOrganizationID(copy.BranchID), occurrence.ScheduledPeriod)
                            .GetValueOrRaiseError();
                        copy.FinPeriodID  = finPeriod.FinPeriodID;
                        copy.TranPeriodID = null;

                        copy.BatchNbr    = lastBatchNbr;
                        copy.RefBatchNbr = lastBatchNbr;

                        lastBatchNbr = AutoNumberAttribute.NextNumber(lastBatchNbr);
                        lastInfoID--;

                        copy = (BatchNew)Batch_Created.Cache.Insert(copy);

                        CurrencyInfoAttribute.SetEffectiveDate <Batch.dateEntered>(Batch_Created.Cache, new PXFieldUpdatedEventArgs(copy, null, false));
                        PXNoteAttribute.CopyNoteAndFiles(Caches[typeof(BatchNew)], scheduledBatch, Batch_Created.Cache, copy);

                        foreach (GLTranNew scheduledBatchTransaction in PXSelect <
                                     GLTranNew,
                                     Where <
                                         GLTranNew.module, Equal <Required <GLTranNew.module> >,
                                         And <GLTranNew.batchNbr, Equal <Required <GLTranNew.batchNbr> > > > >
                                 .Select(this, scheduledBatch.Module, scheduledBatch.BatchNbr))
                        {
                            GLTranNew transactionCopy = PXCache <GLTranNew> .CreateCopy(scheduledBatchTransaction);

                            transactionCopy.OrigBatchNbr = transactionCopy.BatchNbr;
                            transactionCopy.OrigModule   = transactionCopy.Module;
                            transactionCopy.BatchNbr     = copy.BatchNbr;
                            transactionCopy.RefBatchNbr  = copy.RefBatchNbr;
                            transactionCopy.CuryInfoID   = copy.CuryInfoID;
                            transactionCopy.CATranID     = null;
                            transactionCopy.NoteID       = null;

                            transactionCopy.TranDate = occurrence.ScheduledDate;
                            FinPeriodIDAttribute.SetPeriodsByMaster <GLTranNew.finPeriodID>(Tran_Created.Cache, transactionCopy, occurrence.ScheduledPeriod);

                            transactionCopy = Tran_Created.Cache.Insert(transactionCopy) as GLTranNew;
                            PXNoteAttribute.CopyNoteAndFiles(Tran_Created.Cache, scheduledBatchTransaction, Tran_Created.Cache, transactionCopy);
                        }
                    }

                    schedule.LastRunDate = occurrence.ScheduledDate;
                    Running_Schedule.Cache.Update(schedule);
                }

                Running_Schedule.Cache.Persist(PXDBOperation.Update);

                Batch_Created.Cache.Persist(PXDBOperation.Insert);
                Batch_Created.Cache.Persist(PXDBOperation.Update);

                foreach (GLTranNew createdTransaction in Tran_Created.Cache.Inserted)
                {
                    foreach (BatchNew createdBatch in Batch_Created.Cache.Cached)
                    {
                        if (object.Equals(createdBatch.RefBatchNbr, createdTransaction.RefBatchNbr))
                        {
                            createdTransaction.BatchNbr   = createdBatch.BatchNbr;
                            createdTransaction.CuryInfoID = createdBatch.CuryInfoID;

                            if (!string.IsNullOrEmpty(createdBatch.RefNbr))
                            {
                                createdTransaction.RefNbr = createdBatch.RefNbr;
                            }

                            break;
                        }
                    }
                }

                Tran_Created.Cache.Normalize();

                Tran_Created.Cache.Persist(PXDBOperation.Insert);
                Tran_Created.Cache.Persist(PXDBOperation.Update);
                Caches[typeof(CA.CADailySummary)].Persist(PXDBOperation.Insert);

                ts.Complete(this);
            }

            Running_Schedule.Cache.Persisted(false);
            Batch_Created.Cache.Persisted(false);
            Tran_Created.Cache.Persisted(false);
            Caches[typeof(CA.CADailySummary)].Persisted(false);
        }
        public virtual void GenerateProc(Schedule s, short Times, DateTime runDate)
        {
            string             LastBatchNbr = "0000000000";
            Int64              LastInfoID   = -1;
            List <ScheduleDet> sd           = MakeSchedule(s, Times, runDate);

            using (PXTransactionScope ts = new PXTransactionScope())
            {
                foreach (ScheduleDet d in sd)
                {
                    foreach (BatchNew b in PXSelect <BatchNew, Where <BatchNew.scheduleID, Equal <Optional <Schedule.scheduleID> >, And <BatchNew.scheduled, Equal <boolTrue> > > > .Select(this, s.ScheduleID))
                    {
                        BatchNew copy = PXCache <BatchNew> .CreateCopy(b);

                        copy.OrigBatchNbr = copy.BatchNbr;
                        copy.OrigModule   = copy.Module;
                        copy.CuryInfoID   = null;
                        copy.NumberCode   = "GLREC";
                        copy.NoteID       = null;

                        CurrencyInfo info = (CurrencyInfo)PXSelect <CurrencyInfo, Where <CurrencyInfo.curyInfoID, Equal <Required <CurrencyInfo.curyInfoID> > > > .Select(this, b.CuryInfoID);

                        if (info != null)
                        {
                            CurrencyInfo infocopy = PXCache <CurrencyInfo> .CreateCopy(info);

                            infocopy.CuryInfoID = LastInfoID;
                            copy.CuryInfoID     = LastInfoID;
                            CuryInfo_Created.Cache.Insert(infocopy);
                        }

                        copy.Posted    = false;
                        copy.Released  = false;
                        copy.Status    = "B";
                        copy.Scheduled = false;

                        copy.DateEntered  = d.ScheduledDate;
                        copy.FinPeriodID  = d.ScheduledPeriod;
                        copy.TranPeriodID = null;

                        copy.BatchNbr    = LastBatchNbr;
                        copy.RefBatchNbr = LastBatchNbr;
                        LastBatchNbr     = AutoNumberAttribute.NextNumber(LastBatchNbr);
                        LastInfoID--;

                        copy = (BatchNew)Batch_Created.Cache.Insert(copy);

                        CurrencyInfoAttribute.SetEffectiveDate <Batch.dateEntered>(Batch_Created.Cache, new PXFieldUpdatedEventArgs(copy, null, false));
                        PXNoteAttribute.SetNote(Batch_Created.Cache, copy, PXNoteAttribute.GetNote(Caches[typeof(BatchNew)], b));
                        PXNoteAttribute.SetFileNotes(Batch_Created.Cache, copy, PXNoteAttribute.GetFileNotes(Caches[typeof(BatchNew)], b));

                        foreach (GLTranNew tran in PXSelect <GLTranNew, Where <GLTranNew.module, Equal <Required <GLTranNew.module> >, And <GLTranNew.batchNbr, Equal <Required <GLTranNew.batchNbr> > > > > .Select(this, b.Module, b.BatchNbr))
                        {
                            GLTranNew trancopy = PXCache <GLTranNew> .CreateCopy(tran);

                            trancopy.OrigBatchNbr = trancopy.BatchNbr;
                            trancopy.OrigModule   = trancopy.Module;
                            trancopy.BatchNbr     = copy.BatchNbr;
                            trancopy.RefBatchNbr  = copy.RefBatchNbr;
                            trancopy.CuryInfoID   = copy.CuryInfoID;
                            trancopy.CATranID     = null;

                            trancopy.TranDate     = d.ScheduledDate;
                            trancopy.FinPeriodID  = d.ScheduledPeriod;
                            trancopy.TranPeriodID = d.ScheduledPeriod;
                            Tran_Created.Cache.Insert(trancopy);
                        }
                    }

                    s.LastRunDate = d.ScheduledDate;
                    Running_Schedule.Cache.Update(s);
                }
                Running_Schedule.Cache.Persist(PXDBOperation.Update);

                Batch_Created.Cache.Persist(PXDBOperation.Insert);
                Batch_Created.Cache.Persist(PXDBOperation.Update);

                foreach (GLTranNew tran in Tran_Created.Cache.Inserted)
                {
                    foreach (BatchNew batch in Batch_Created.Cache.Cached)
                    {
                        if (object.Equals(batch.RefBatchNbr, tran.RefBatchNbr))
                        {
                            tran.BatchNbr   = batch.BatchNbr;
                            tran.CuryInfoID = batch.CuryInfoID;
                            if (!string.IsNullOrEmpty(batch.RefNbr))
                            {
                                tran.RefNbr = batch.RefNbr;
                            }
                            break;
                        }
                    }
                }
                Tran_Created.Cache.Normalize();

                Tran_Created.Cache.Persist(PXDBOperation.Insert);
                Tran_Created.Cache.Persist(PXDBOperation.Update);
                Caches[typeof(CA.CADailySummary)].Persist(PXDBOperation.Insert);

                ts.Complete(this);
            }
            Running_Schedule.Cache.Persisted(false);
            Batch_Created.Cache.Persisted(false);
            Tran_Created.Cache.Persisted(false);
            Caches[typeof(CA.CADailySummary)].Persisted(false);
        }
 protected virtual void CATransfer_OutDate_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
 {
     CurrencyInfoAttribute.SetEffectiveDate <CATransfer.outDate, CATransfer.outCuryInfoID>(sender, e);
 }
Exemple #23
0
 protected virtual void EPExpenseClaimDetails_ExpenseDate_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
 {
     CurrencyInfoAttribute.SetEffectiveDate <EPExpenseClaimDetails.expenseDate>(cache, e);
 }
        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);
        }
        public virtual void GenerateProc(Schedule schedule, short times, DateTime runDate)
        {
            IEnumerable <ScheduleDet> occurrences = new Scheduler(this).MakeSchedule(schedule, times, runDate);

            APInvoiceEntry invoiceEntry = CreateGraph();

            using (PXTransactionScope transactionScope = new PXTransactionScope())
            {
                foreach (ScheduleDet occurrence in occurrences)
                {
                    foreach (PXResult <APInvoice, Vendor, CurrencyInfo> scheduledInvoiceResult in PXSelectJoin <
                                 APInvoice,
                                 InnerJoin <Vendor, On <Vendor.bAccountID, Equal <APInvoice.vendorID> >,
                                            InnerJoin <CurrencyInfo, On <CurrencyInfo.curyInfoID, Equal <APInvoice.curyInfoID> > > >,
                                 Where <
                                     APInvoice.scheduleID, Equal <Required <APInvoice.scheduleID> >,
                                     And <APInvoice.scheduled, Equal <boolTrue> > > >
                             .Select(this, schedule.ScheduleID))
                    {
                        invoiceEntry.Clear();

                        invoiceEntry.vendor.Current = (Vendor)scheduledInvoiceResult;
                        APInvoice    scheduledInvoice             = (APInvoice)scheduledInvoiceResult;
                        CurrencyInfo scheduledInvoiceCurrencyInfo = (CurrencyInfo)scheduledInvoiceResult;

                        if (scheduledInvoice.Released == true)
                        {
                            throw new PXException(AR.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);

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

                        newInvoice.CuryInfoID          = newCurrencyInfo.CuryInfoID;
                        newInvoice.DocDate             = occurrence.ScheduledDate;
                        newInvoice.FinPeriodID         = occurrence.ScheduledPeriod;
                        newInvoice.TranPeriodID        = null;
                        newInvoice.DueDate             = null;
                        newInvoice.DiscDate            = null;
                        newInvoice.PayDate             = 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.PaySel              = false;
                        newInvoice.IsTaxValid          = false;
                        newInvoice.IsTaxPosted         = false;
                        newInvoice.IsTaxSaved          = false;
                        newInvoice.OrigDocType         = scheduledInvoice.DocType;
                        newInvoice.OrigRefNbr          = scheduledInvoice.RefNbr;

                        newInvoice = invoiceEntry.Document.Insert(newInvoice);                         //we insert an item here because we need DontApprove field to be set in RowSelected
                        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);

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

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

                        foreach (APTran originalLine in PXSelect <
                                     APTran,
                                     Where <
                                         APTran.tranType, Equal <Required <APTran.tranType> >,
                                         And <APTran.refNbr, Equal <Required <APTran.refNbr> >,
                                              And <Where <
                                                       APTran.lineType, IsNull,
                                                       Or <APTran.lineType, NotEqual <SOLineType.discount> > > > > > >
                                 .Select(invoiceEntry, scheduledInvoice.DocType, scheduledInvoice.RefNbr))
                        {
                            APTran newLine = PXCache <APTran> .CreateCopy(originalLine);

                            newLine.RefNbr      = null;
                            newLine.CuryInfoID  = null;
                            newLine.ManualPrice = true;
                            newLine.ManualDisc  = true;
                            newLine.NoteID      = null;
                            newLine             = invoiceEntry.Transactions.Insert(newLine);

                            PXNoteAttribute.CopyNoteAndFiles(Caches[typeof(APTran)], originalLine, invoiceEntry.Transactions.Cache, newLine);
                        }

                        foreach (APInvoiceDiscountDetail originalDiscountDetail in PXSelect <
                                     APInvoiceDiscountDetail,
                                     Where <
                                         APInvoiceDiscountDetail.docType, Equal <Required <APInvoiceDiscountDetail.docType> >,
                                         And <APInvoiceDiscountDetail.refNbr, Equal <Required <APInvoiceDiscountDetail.refNbr> > > > >
                                 .Select(invoiceEntry, scheduledInvoice.DocType, scheduledInvoice.RefNbr))
                        {
                            APInvoiceDiscountDetail newDiscountDetail =
                                PXCache <APInvoiceDiscountDetail> .CreateCopy(originalDiscountDetail);

                            newDiscountDetail.RefNbr     = null;
                            newDiscountDetail.CuryInfoID = null;
                            newDiscountDetail.IsManual   = true;

                            DiscountEngineProvider.GetEngineFor <APTran, APInvoiceDiscountDetail>().InsertDiscountDetail(invoiceEntry.DiscountDetails.Cache, invoiceEntry.DiscountDetails, newDiscountDetail);
                        }

                        BalanceCalculation.ForceDocumentControlTotals(invoiceEntry, newInvoice);

                        try
                        {
                            invoiceEntry.Save.Press();
                        }
                        catch
                        {
                            if (invoiceEntry.Document.Cache.IsInsertedUpdatedDeleted)
                            {
                                throw;
                            }
                        }
                    }

                    schedule.LastRunDate = occurrence.ScheduledDate;
                    Running_Schedule.Cache.Update(schedule);
                }

                transactionScope.Complete(this);
            }

            using (PXTransactionScope ts = new PXTransactionScope())
            {
                Running_Schedule.Cache.Persist(PXDBOperation.Update);
                ts.Complete(this);
            }

            Running_Schedule.Cache.Persisted(false);
        }
 protected virtual void TaxAdjustment_DocDate_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
 {
     CurrencyInfoAttribute.SetEffectiveDate <TaxAdjustment.docDate>(sender, e);
 }