Exemplo n.º 1
0
        public virtual IEnumerable amts(PXAdapter adapter)
        {
            AccBalanceByAssetFilter filter = Filter.Current;

            if (filter == null)
            {
                yield break;
            }

            PXSelectBase <FATran> select = new PXSelectJoin <FATran,
                                                             InnerJoin <FixedAsset, On <FixedAsset.assetID, Equal <FATran.assetID>, And <FixedAsset.recordType, Equal <FARecordType.assetType> > >,
                                                                        InnerJoin <FADetails, On <FADetails.assetID, Equal <FixedAsset.assetID> >,
                                                                                   InnerJoin <FALocationHistoryCurrent, On <FALocationHistoryCurrent.assetID, Equal <FixedAsset.assetID> >,
                                                                                              InnerJoin <FALocationHistory, On <FALocationHistory.assetID, Equal <FixedAsset.assetID>,
                                                                                                                                And <FALocationHistory.periodID, Equal <FALocationHistoryCurrent.lastPeriodID>,
                                                                                                                                     And <FALocationHistory.revisionID, Equal <FALocationHistoryCurrent.lastRevisionID> > > > > > > >,
                                                             Where <FATran.released, Equal <True>,
                                                                    And <FATran.finPeriodID, LessEqual <Current <AccBalanceByAssetFilter.periodID> >,
                                                                         And <FATran.bookID, Equal <Current <AccBalanceByAssetFilter.bookID> >,
                                                                              And2 <Where <FALocationHistory.fAAccountID, Equal <Current <AccBalanceByAssetFilter.accountID> >,
                                                                                           And <FALocationHistory.fASubID, Equal <Current <AccBalanceByAssetFilter.subID> >,
                                                                                                Or <FALocationHistory.accumulatedDepreciationAccountID, Equal <Current <AccBalanceByAssetFilter.accountID> >,
                                                                                                    And <FALocationHistory.accumulatedDepreciationSubID, Equal <Current <AccBalanceByAssetFilter.subID> > > > > >,
                                                                                    And <Where <FATran.debitAccountID, Equal <Current <AccBalanceByAssetFilter.accountID> >,
                                                                                                And <FATran.debitSubID, Equal <Current <AccBalanceByAssetFilter.subID> >,
                                                                                                     Or <FATran.creditAccountID, Equal <Current <AccBalanceByAssetFilter.accountID> >,
                                                                                                         And <FATran.creditSubID, Equal <Current <AccBalanceByAssetFilter.subID> > > > > > > > > > > >(this);

            if (filter.BranchID != null)
            {
                select.WhereAnd <Where <FALocationHistory.locationID, Equal <Current <AccBalanceByAssetFilter.branchID> > > >();
            }

            Dictionary <int?, Amounts> dict = new Dictionary <int?, Amounts>();

            foreach (PXResult <FATran, FixedAsset, FADetails, FALocationHistoryCurrent, FALocationHistory> res in select.Select())
            {
                FATran            tran     = (FATran)res;
                FixedAsset        asset    = (FixedAsset)res;
                FADetails         details  = (FADetails)res;
                FALocationHistory location = (FALocationHistory)res;

                Amounts record = null;
                if (!dict.TryGetValue(asset.AssetID, out record))
                {
                    record = new Amounts
                    {
                        AssetID            = asset.AssetID,
                        Description        = asset.Description,
                        Status             = details.Status,
                        ClassID            = asset.ClassID,
                        DepreciateFromDate = details.DepreciateFromDate,
                        BranchID           = location.BranchID,
                        Department         = location.Department,
                        ItdAmt             = decimal.Zero,
                        YtdAmt             = decimal.Zero,
                        PtdAmt             = decimal.Zero
                    };
                }

                decimal tranAmt = tran.TranAmt ?? decimal.Zero;
                decimal amount  = tran.DebitAccountID == tran.CreditAccountID && tran.DebitSubID == tran.CreditSubID
                                        ? decimal.Zero
                                        : tran.DebitAccountID == filter.AccountID && tran.DebitSubID == filter.SubID ? tranAmt : -tranAmt;

                record.ItdAmt += amount;
                record.YtdAmt += (FinPeriodIDAttribute.FinPeriodEqual(filter.PeriodID, tran.FinPeriodID, FinPeriodIDAttribute.FinPeriodComparison.Year) ? amount : decimal.Zero);
                record.PtdAmt += (filter.PeriodID == tran.FinPeriodID ? amount : decimal.Zero);

                dict[asset.AssetID] = record;
            }

            foreach (Amounts amt in dict.Values)
            {
                if (amt.ItdAmt != decimal.Zero || amt.YtdAmt != decimal.Zero || amt.PtdAmt != decimal.Zero)
                {
                    yield return(amt);
                }
            }
        }