Пример #1
0
        protected virtual void CurrencyRate_RowUpdating(PXCache cache, PXRowUpdatingEventArgs e)
        {
            CurrencyRate cr = e.NewRow as CurrencyRate;

            if (cr.CuryEffDate == null)
            {
                cr.CuryEffDate = DateTime.Now;
            }

            if (cr.FromCuryID != null && cr.ToCuryID != null && String.Compare(cr.FromCuryID, cr.ToCuryID, true) == 0)
            {
                throw new PXException(Messages.DestShouldDifferFromOrig);
            }
            if (cr.CuryRate != null)
            {
                if (Math.Round((decimal)(cr.CuryRate), 8) == 0)
                {
                    throw new PXException(Messages.CuryRateCantBeZero);
                }
                cr.RateReciprocal = Math.Round((decimal)(1 / cr.CuryRate), 8);
                if (((CurrencyInfo)cr).CheckRateVariance(cache))
                {
                    cache.RaiseExceptionHandling <CurrencyRate.curyRate>(cr, cr.CuryRate, new PXSetPropertyException(Messages.RateVarianceExceeded, PXErrorLevel.Warning));
                }
            }
            if (cr.FromCuryID != null &&
                cr.CuryRateType != null &&
                cr.CuryRateType != null &&
                cr.CuryEffDate != null &&
                cr.CuryRate != null)
            {
                CurrencyRate existRate = PXSelectReadonly <CurrencyRate,
                                                           Where <CurrencyRate.toCuryID, Equal <Required <CurrencyRate.toCuryID> >,
                                                                  And <CurrencyRate.fromCuryID, Equal <Required <CurrencyRate.fromCuryID> >,
                                                                       And <CurrencyRate.curyRateType, Equal <Required <CurrencyRate.curyRateType> >,
                                                                            And <CurrencyRate.curyEffDate, Equal <Required <CurrencyRate.curyEffDate> > > > > >,
                                                           OrderBy <Desc <CurrencyRate.curyEffDate> > > .Select(cache.Graph, cr.ToCuryID, cr.FromCuryID, cr.CuryRateType, cr.CuryEffDate);


                if (existRate != null)
                {
                    if (CuryRateRecordsEntry.Locate(existRate) == null)
                    {
                        CurrencyRate newExistRate = (CurrencyRate)CuryRateRecordsEntry.Cache.CreateCopy(existRate);
                        newExistRate.CuryRate       = cr.CuryRate;
                        newExistRate.CuryMultDiv    = cr.CuryMultDiv;
                        newExistRate.RateReciprocal = cr.RateReciprocal;
                        CuryRateRecordsEntry.Delete(cr);
                        CuryRateRecordsEntry.Update(newExistRate);
                    }
                    cache.RaiseExceptionHandling <CurrencyRate.curyRate>(cr, cr.CuryRate, new PXSetPropertyException(Messages.SuchRateTypeAlreadyExist, PXErrorLevel.Warning));
                }
            }
        }
Пример #2
0
        protected virtual IEnumerable consolRecords(
            [PXDBString]
            string ledgerCD,
            [PXDBString]
            string branchCD
            )
        {
            Ledger ledger = PXSelect <Ledger,
                                      Where <Ledger.consolAllowed, Equal <True>,
                                             And <Ledger.ledgerCD, Equal <Required <Ledger.ledgerCD> > > > > .Select(this, ledgerCD);

            Branch branch = PXSelect <Branch,
                                      Where <Branch.branchCD, Equal <Required <Branch.branchCD> > > > .Select(this, branchCD);

            if (ledger == null)
            {
                throw new PXException(Messages.CantFindConsolidationLedger, ledgerCD);
            }

            if (!string.IsNullOrEmpty(branchCD) && branch == null)
            {
                throw new PXException(Messages.CantFindConsolidationBranch, branchCD);
            }

            var exportSubaccountMapper = CreateExportSubaccountMapper();

            var noSegmentsToExport = false;

            if (PXAccess.FeatureInstalled <FeaturesSet.subAccount>())
            {
                noSegmentsToExport = SubaccountSegmentsView.Select()
                                     .RowCast <Segment>()
                                     .All(segment => segment.ConsolNumChar <= 0);
            }

            PXSelectBase <GLHistory> cmd = new PXSelectJoin <GLHistory,
                                                             InnerJoin <Account, On <Account.accountID, Equal <GLHistory.accountID> >,
                                                                        InnerJoin <Sub, On <Sub.subID, Equal <GLHistory.subID> >,
                                                                                   InnerJoin <Ledger, On <Ledger.ledgerID, Equal <GLHistory.ledgerID> >,
                                                                                              InnerJoin <Branch, On <Branch.branchID, Equal <GLHistory.branchID> > > > > >,
                                                             Where <Ledger.ledgerCD, Equal <Required <Ledger.ledgerCD> >,
                                                                    And <GLHistory.accountID, NotEqual <Current <GLSetup.ytdNetIncAccountID> > > >,
                                                             OrderBy <Asc <GLHistory.finPeriodID, Asc <Account.accountCD, Asc <Sub.subCD> > > > >(this);

            if (!string.IsNullOrEmpty(branchCD))
            {
                cmd.WhereAnd <Where <Branch.branchCD, Equal <Required <Branch.branchCD> > > >();
            }

            foreach (PXResult <GLHistory, Account, Sub> result in cmd.Select(ledgerCD, branchCD))
            {
                GLHistory history = result;
                Account   account = result;
                Sub       sub     = result;

                string accountCD = account.GLConsolAccountCD;
                string subCD     = exportSubaccountMapper.GetMappedSubaccountCD(sub);

                if (accountCD != null && accountCD.TrimEnd() != "" &&
                    (subCD != null && subCD.TrimEnd() != "" || noSegmentsToExport))
                {
                    GLConsolData consolData = new GLConsolData();
                    consolData.MappedValue = subCD;
                    consolData.AccountCD   = accountCD;
                    consolData.FinPeriodID = history.FinPeriodID;
                    consolData             = ConsolRecords.Locate(consolData);
                    if (consolData != null)
                    {
                        consolData.ConsolAmtDebit  += history.FinPtdDebit;
                        consolData.ConsolAmtCredit += history.FinPtdCredit;
                    }
                    else
                    {
                        consolData                   = new GLConsolData();
                        consolData.MappedValue       = subCD;
                        consolData.MappedValueLength = subCD.Length;
                        consolData.AccountCD         = accountCD;
                        consolData.FinPeriodID       = history.FinPeriodID;
                        consolData.ConsolAmtDebit    = history.FinPtdDebit;
                        consolData.ConsolAmtCredit   = history.FinPtdCredit;
                        ConsolRecords.Insert(consolData);
                    }
                }
            }

            return(ConsolRecords.Cache.Inserted);
        }
Пример #3
0
        protected virtual IEnumerable consolRecords(
            [PXDBString]
            string ledgerCD,
            [PXDBString]
            string branchCD
            )
        {
            Ledger ledger = PXSelect <Ledger,
                                      Where <Ledger.consolAllowed, Equal <boolTrue>,
                                             And <Ledger.ledgerCD, Equal <Required <Ledger.ledgerCD> > > > > .Select(this, ledgerCD);

            Branch branch = PXSelect <Branch,
                                      Where <Branch.branchCD, Equal <Required <Branch.branchCD> > > > .Select(this, branchCD);

            if (ledger == null)
            {
                throw new PXException(Messages.CantFindConsolidationLedger, ledgerCD);
            }

            if (!string.IsNullOrEmpty(branchCD) && branch == null)
            {
                throw new PXException(Messages.CantFindConsolidationBranch, branchCD);
            }

            if (true)
            {
                InitSegmentData(null);

                PXSelectBase <GLHistory> cmd = new PXSelectJoin <GLHistory,
                                                                 InnerJoin <Account, On <Account.accountID, Equal <GLHistory.accountID> >,
                                                                            InnerJoin <Sub, On <Sub.subID, Equal <GLHistory.subID> >,
                                                                                       InnerJoin <Ledger, On <Ledger.ledgerID, Equal <GLHistory.ledgerID> >,
                                                                                                  InnerJoin <Branch, On <Branch.branchID, Equal <GLHistory.branchID> > > > > >,
                                                                 Where <Ledger.ledgerCD, Equal <Required <Ledger.ledgerCD> >,
                                                                        And <GLHistory.accountID, NotEqual <Current <GLSetup.ytdNetIncAccountID> > > >,
                                                                 OrderBy <Asc <GLHistory.finPeriodID, Asc <Account.accountCD, Asc <Sub.subCD> > > > >(this);

                if (!string.IsNullOrEmpty(branchCD))
                {
                    cmd.WhereAnd <Where <Branch.branchCD, Equal <Required <Branch.branchCD> > > >();
                }

                foreach (PXResult <GLHistory, Account, Sub> result in cmd.Select(ledgerCD, branchCD))
                {
                    GLHistory history = result;
                    Account   account = result;
                    Sub       sub     = result;

                    string accountCD = account.GLConsolAccountCD;
                    string subCD     = GetMappedValue(sub.SubCD);

                    if (accountCD != null && accountCD.TrimEnd() != "" &&
                        subCD != null && subCD.TrimEnd() != "")
                    {
                        GLConsolData consolData = new GLConsolData();
                        consolData.MappedValue = subCD;
                        consolData.AccountCD   = accountCD;
                        consolData.FinPeriodID = history.FinPeriodID;
                        consolData             = ConsolRecords.Locate(consolData);
                        if (consolData != null)
                        {
                            consolData.ConsolAmtDebit  += history.FinPtdDebit;
                            consolData.ConsolAmtCredit += history.FinPtdCredit;
                        }
                        else
                        {
                            consolData                 = new GLConsolData();
                            consolData.MappedValue     = subCD;
                            consolData.AccountCD       = accountCD;
                            consolData.FinPeriodID     = history.FinPeriodID;
                            consolData.ConsolAmtDebit  = history.FinPtdDebit;
                            consolData.ConsolAmtCredit = history.FinPtdCredit;
                            ConsolRecords.Insert(consolData);
                        }
                    }
                }
            }

            return(ConsolRecords.Cache.Inserted);
        }