Пример #1
0
        protected virtual int ConsolidationRead(GLConsolSetup item)
        {
            int cnt = 0;

            string aFiscalPeriod = null;
            int?   ledgerID      = item.LedgerId;
            int?   branchID      = item.BranchID;

            var importSubaccountCDCalculator = CreateImportSubaccountMapper(item);

            PXSelect <GLConsolHistory,
                      Where <GLConsolHistory.setupID, Equal <Required <GLConsolHistory.setupID> > > >
            .Select(this, item.SetupID);

            var roundFunc = GetRoundDelegateForLedger(ledgerID);

            JournalEntry je = PXGraph.CreateInstance <JournalEntry>();

            if (item.BypassAccountSubValidation == true)
            {
                je.FieldVerifying.AddHandler <GLTran.accountID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });
                je.FieldVerifying.AddHandler <GLTran.subID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });
            }

            consolSetup = DecryptRemoteUserPassword(item);

            using (PXSoapScope scope = new PXSoapScope(consolSetup.Url, consolSetup.Login, consolSetup.Password))
            {
                GLConsolReadMaint reader = PXGraph.CreateInstance <GLConsolReadMaint>();
                reader.ConsolRecords.Select(item.SourceLedgerCD, item.SourceBranchCD);
                scope.Process(reader);

                int min = 0;
                if (!String.IsNullOrEmpty(item.StartPeriod))
                {
                    int.TryParse(item.StartPeriod, out min);
                }
                int max = 0;
                if (!String.IsNullOrEmpty(item.EndPeriod))
                {
                    int.TryParse(item.EndPeriod, out max);
                }
                foreach (GLConsolData row in reader.ConsolRecords.Select())
                {
                    if (min > 0 || max > 0)
                    {
                        if (!String.IsNullOrEmpty(row.FinPeriodID))
                        {
                            int p;
                            if (int.TryParse(row.FinPeriodID, out p))
                            {
                                if (min > 0 && p < min || max > 0 && p > max)
                                {
                                    continue;
                                }
                            }
                        }
                    }
                    if (aFiscalPeriod == null)
                    {
                        aFiscalPeriod = row.FinPeriodID;
                    }
                    else if (aFiscalPeriod != row.FinPeriodID)
                    {
                        if (listConsolRead.Count > 0)
                        {
                            cnt += AppendRemapped(aFiscalPeriod, ledgerID, branchID, item.SetupID, roundFunc);
                            CreateBatch(je, aFiscalPeriod, ledgerID, branchID, item);
                        }
                        aFiscalPeriod = row.FinPeriodID;
                        listConsolRead.Clear();
                    }

                    GLConsolRead read = new GLConsolRead();

                    var account = AccountMaint.FindAccountByCD(this, row.AccountCD);

                    if (account.AccountID == GLSetup.Current.YtdNetIncAccountID)
                    {
                        throw new PXException(Messages.ImportingYTDNetIncomeAccountDataIsProhibited);
                    }

                    read.AccountCD = account.AccountCD;
                    read.AccountID = account.AccountID;

                    var mappedValue = GetMappedValue(row);
                    var subKeys     = importSubaccountCDCalculator.GetMappedSubaccountKeys(mappedValue);

                    read.MappedValue = subKeys.SubCD;
                    read.SubID       = subKeys.SubID;
                    read.FinPeriodID = row.FinPeriodID;

                    GLConsolHistory history = new GLConsolHistory();
                    history.SetupID     = item.SetupID;
                    history.FinPeriodID = read.FinPeriodID;
                    history.AccountID   = read.AccountID;
                    history.SubID       = read.SubID;
                    history.LedgerID    = item.LedgerId;
                    history.BranchID    = item.BranchID;
                    history             = (GLConsolHistory)Caches[typeof(GLConsolHistory)].Locate(history);

                    if (history != null)
                    {
                        read.ConsolAmtCredit = roundFunc(row.ConsolAmtCredit) - roundFunc(history.PtdCredit);
                        read.ConsolAmtDebit  = roundFunc(row.ConsolAmtDebit) - roundFunc(history.PtdDebit);
                        history.PtdCredit    = 0m;
                        history.PtdDebit     = 0m;
                    }
                    else
                    {
                        read.ConsolAmtCredit = roundFunc(row.ConsolAmtCredit);
                        read.ConsolAmtDebit  = roundFunc(row.ConsolAmtDebit);
                    }

                    if (read.ConsolAmtCredit != 0m || read.ConsolAmtDebit != 0m)
                    {
                        listConsolRead.Add(read);
                        cnt++;
                    }
                }
            }

            if (listConsolRead.Count > 0)
            {
                cnt += AppendRemapped(aFiscalPeriod, ledgerID, branchID, item.SetupID, roundFunc);
                CreateBatch(je, aFiscalPeriod, ledgerID, branchID, item);
            }

            if (exception != null)
            {
                PXException ex = exception;
                exception = null;
                throw ex;
            }

            return(cnt);
        }
Пример #2
0
        protected Dictionary <short, string> segmentNames   = new Dictionary <short, string>();     // <segmentid, segmentName>

        protected virtual int ConsolidationRead(GLConsolSetup item)
        {
            int cnt = 0;

            string aFiscalPeriod = null;
            int?   ledgerID      = item.LedgerId;
            int?   branchID      = item.BranchID;
            string segmentValue  = item.SegmentValue;

            InitSegmentData(item);

            PXSelect <GLConsolHistory,
                      Where <GLConsolHistory.setupID, Equal <Required <GLConsolHistory.setupID> > > >
            .Select(this, item.SetupID);

            JournalEntry je = PXGraph.CreateInstance <JournalEntry>();

            if (item.BypassAccountSubValidation == true)
            {
                je.FieldVerifying.AddHandler <GLTran.accountID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });
                je.FieldVerifying.AddHandler <GLTran.subID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });
            }

            using (PXSoapScope scope = new PXSoapScope(consolSetup.Url, consolSetup.Login, consolSetup.Password))
            {
                GLConsolReadMaint reader = PXGraph.CreateInstance <GLConsolReadMaint>();
                reader.ConsolRecords.Select(item.SourceLedgerCD, item.SourceBranchCD);
                scope.Process(reader);

                int min = 0;
                if (!String.IsNullOrEmpty(item.StartPeriod))
                {
                    int.TryParse(item.StartPeriod, out min);
                }
                int max = 0;
                if (!String.IsNullOrEmpty(item.EndPeriod))
                {
                    int.TryParse(item.EndPeriod, out max);
                }
                foreach (GLConsolData row in reader.ConsolRecords.Select())
                {
                    if (min > 0 || max > 0)
                    {
                        if (!String.IsNullOrEmpty(row.FinPeriodID))
                        {
                            int p;
                            if (int.TryParse(row.FinPeriodID, out p))
                            {
                                if (min > 0 && p < min || max > 0 && p > max)
                                {
                                    continue;
                                }
                            }
                        }
                    }
                    if (aFiscalPeriod == null)
                    {
                        aFiscalPeriod = row.FinPeriodID;
                    }
                    else if (aFiscalPeriod != row.FinPeriodID)
                    {
                        if (listConsolRead.Count > 0)
                        {
                            cnt += AppendRemapped(aFiscalPeriod, ledgerID, branchID, item.SetupID);
                            CreateBatch(je, aFiscalPeriod, ledgerID, branchID, item);
                        }
                        aFiscalPeriod = row.FinPeriodID;
                        listConsolRead.Clear();
                    }

                    GLConsolRead read      = new GLConsolRead();
                    int?         accountId = ValidateAccountCD(row.AccountCD);
                    string       subCD     = GetRegeneratedSubCD(row.MappedValue);
                    int?         subId     = ValidateSubCD(subCD);

                    read.AccountCD   = row.AccountCD;
                    read.AccountID   = accountId;
                    read.MappedValue = subCD;
                    read.SubID       = subId;
                    read.FinPeriodID = row.FinPeriodID;

                    GLConsolHistory history = new GLConsolHistory();
                    history.SetupID     = item.SetupID;
                    history.FinPeriodID = read.FinPeriodID;
                    history.AccountID   = read.AccountID;
                    history.SubID       = read.SubID;
                    history.LedgerID    = item.LedgerId;
                    history.BranchID    = item.BranchID;
                    history             = (GLConsolHistory)Caches[typeof(GLConsolHistory)].Locate(history);
                    if (history != null)
                    {
                        read.ConsolAmtCredit = (row.ConsolAmtCredit - history.PtdCredit);
                        read.ConsolAmtDebit  = (row.ConsolAmtDebit - history.PtdDebit);
                        history.PtdCredit    = 0m;
                        history.PtdDebit     = 0m;
                    }
                    else
                    {
                        read.ConsolAmtCredit = row.ConsolAmtCredit;
                        read.ConsolAmtDebit  = row.ConsolAmtDebit;
                    }
                    if (read.ConsolAmtCredit != 0m || read.ConsolAmtDebit != 0m)
                    {
                        listConsolRead.Add(read);
                        cnt++;
                    }
                }
            }

            if (listConsolRead.Count > 0)
            {
                cnt += AppendRemapped(aFiscalPeriod, ledgerID, branchID, item.SetupID);
                CreateBatch(je, aFiscalPeriod, ledgerID, branchID, item);
            }

            if (exception != null)
            {
                PXException ex = exception;
                exception = null;
                throw ex;
            }

            return(cnt);
        }