示例#1
0
        public static void MarkReceiptsPrinted(int ALedgerNumber, DataTable AGiftTbl)
        {
            TDBTransaction Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.Serializable);
            AGiftTable     Tbl         = new AGiftTable();

            foreach (DataRow Row in AGiftTbl.Rows)
            {
                Tbl.Merge(AGiftAccess.LoadByPrimaryKey(
                              ALedgerNumber,
                              Convert.ToInt32(Row["BatchNumber"]),
                              Convert.ToInt32(Row["TransactionNumber"]),
                              Transaction));
            }

            foreach (AGiftRow Row in Tbl.Rows)
            {
                Row.ReceiptPrinted = true;
            }

            try
            {
                AGiftAccess.SubmitChanges(Tbl, Transaction);

                DBAccess.GDBAccessObj.CommitTransaction();
            }
            catch (Exception Exc)
            {
                TLogging.Log("An Exception occured while marking Receipts as printed:" + Environment.NewLine + Exc.ToString());

                DBAccess.GDBAccessObj.RollbackTransaction();

                throw;
            }
        }
示例#2
0
        public static bool GetGiftsForFieldChangeAdjustment(ref GiftBatchTDS AGiftDS, Int32 ALedgerNumber,
                                                            Int64 ARecipientKey,
                                                            DateTime AStartDate,
                                                            DateTime AEndDate,
                                                            Int64 AOldField,
                                                            out TVerificationResultCollection AMessages)
        {
            TDBTransaction Transaction = new TDBTransaction();
            TDataBase      db          = DBAccess.Connect("GetGiftsForFieldChangeAdjustment");
            GiftBatchTDS   MainDS      = new GiftBatchTDS();

            AMessages = new TVerificationResultCollection();

            db.ReadTransaction(
                ref Transaction,
                delegate
            {
                string SqlStmt = TDataBase.ReadSqlFile("Gift.GetGiftsToAdjustField.sql");

                List <OdbcParameter> parameters = new List <OdbcParameter>();
                OdbcParameter param             = new OdbcParameter("LedgerNumber", OdbcType.Int);
                param.Value = ALedgerNumber;
                parameters.Add(param);
                param       = new OdbcParameter("StartDate", OdbcType.Date);
                param.Value = AStartDate;
                parameters.Add(param);
                param       = new OdbcParameter("EndDate", OdbcType.Date);
                param.Value = AEndDate;
                parameters.Add(param);
                param       = new OdbcParameter("RecipientKey", OdbcType.BigInt);
                param.Value = ARecipientKey;
                parameters.Add(param);
                param       = new OdbcParameter("OldField", OdbcType.BigInt);
                param.Value = AOldField;
                parameters.Add(param);

                db.Select(MainDS, SqlStmt, MainDS.AGiftDetail.TableName, Transaction, parameters.ToArray());

                // get additional data
                foreach (GiftBatchTDSAGiftDetailRow Row in MainDS.AGiftDetail.Rows)
                {
                    AGiftBatchAccess.LoadByPrimaryKey(MainDS, Row.LedgerNumber, Row.BatchNumber, Transaction);
                    AGiftRow GiftRow =
                        AGiftAccess.LoadByPrimaryKey(MainDS, Row.LedgerNumber, Row.BatchNumber, Row.GiftTransactionNumber, Transaction);

                    Row.DateEntered = GiftRow.DateEntered;
                    Row.DonorKey    = GiftRow.DonorKey;
                    Row.IchNumber   = 0;
                    Row.DonorName   = PPartnerAccess.LoadByPrimaryKey(Row.DonorKey, Transaction)[0].PartnerShortName;
                }
            });

            AGiftDS = MainDS;

            db.CloseDBConnection();

            return(CheckGiftsNotPreviouslyReversed(AGiftDS, out AMessages));
        }
示例#3
0
        public static bool GetGiftsForReverseAdjust(
            Hashtable requestParams, ref GiftBatchTDS AGiftDS, out TVerificationResultCollection AMessages)
        {
            GiftAdjustmentFunctionEnum Function = (GiftAdjustmentFunctionEnum)requestParams["Function"];
            Int32 LedgerNumber = (Int32)requestParams["ALedgerNumber"];
            Int32 BatchNumber  = (Int32)requestParams["BatchNumber"];

            AMessages = new TVerificationResultCollection();
            GiftBatchTDS MainDS = new GiftBatchTDS();

            TDBTransaction Transaction = new TDBTransaction();
            TDataBase      db          = DBAccess.Connect("GetGiftsForReverseAdjust");

            db.ReadTransaction(
                ref Transaction,
                delegate
            {
                // get data needed for new gifts
                if (Function.Equals(GiftAdjustmentFunctionEnum.ReverseGiftBatch))
                {
                    AGiftAccess.LoadViaAGiftBatch(MainDS, LedgerNumber, BatchNumber, Transaction);

                    foreach (AGiftRow gift in MainDS.AGift.Rows)
                    {
                        AGiftDetailAccess.LoadViaAGift(MainDS, LedgerNumber, BatchNumber, gift.GiftTransactionNumber, Transaction);
                    }
                }
                else
                {
                    Int32 GiftNumber       = (Int32)requestParams["GiftNumber"];
                    Int32 GiftDetailNumber = (Int32)requestParams["GiftDetailNumber"];
                    AGiftAccess.LoadByPrimaryKey(MainDS, LedgerNumber, BatchNumber, GiftNumber, Transaction);

                    if (Function.Equals(GiftAdjustmentFunctionEnum.ReverseGiftDetail))
                    {
                        AGiftDetailAccess.LoadByPrimaryKey(MainDS, LedgerNumber, BatchNumber, GiftNumber, GiftDetailNumber, Transaction);
                    }
                    else
                    {
                        AGiftDetailAccess.LoadViaAGift(MainDS, LedgerNumber, BatchNumber, GiftNumber, Transaction);
                    }
                }
            });

            AGiftDS = MainDS;

            db.CloseDBConnection();

            return(CheckGiftsNotPreviouslyReversed(AGiftDS, out AMessages));
        }
        public static bool GetGiftsForTaxDeductiblePctAdjustment(ref GiftBatchTDS AGiftDS,
                                                                 Int64 ARecipientKey,
                                                                 DateTime ADateFrom,
                                                                 decimal ANewPct,
                                                                 out TVerificationResultCollection AMessages)
        {
            TDBTransaction Transaction = new TDBTransaction();
            TDataBase      db          = DBAccess.Connect("GetGiftsForTaxDeductiblePctAdjustment");
            GiftBatchTDS   MainDS      = new GiftBatchTDS();

            AMessages = new TVerificationResultCollection();

            db.ReadTransaction(ref Transaction,
                               delegate
            {
                string Query = "SELECT a_gift_detail.*" +

                               " FROM a_gift_detail, a_gift_batch" +

                               " WHERE a_gift_detail.p_recipient_key_n = " + ARecipientKey +
                               " AND a_gift_detail.a_tax_deductible_pct_n <> " + ANewPct +
                               " AND a_gift_detail.a_modified_detail_l <> true" +
                               " AND a_gift_detail.a_tax_deductible_l = true" +
                               " AND a_gift_batch.a_ledger_number_i = a_gift_detail.a_ledger_number_i" +
                               " AND a_gift_batch.a_batch_number_i = a_gift_detail.a_batch_number_i" +
                               " AND a_gift_batch.a_ledger_number_i = a_gift_detail.a_ledger_number_i" +
                               " AND a_gift_batch.a_batch_status_c = 'Posted' " +
                               " AND a_gift_batch.a_gl_effective_date_d >= '" + ADateFrom.ToString("yyyy-MM-dd") + "'";

                db.Select(MainDS, Query, MainDS.AGiftDetail.TableName, Transaction);

                // get additional data
                foreach (GiftBatchTDSAGiftDetailRow Row in MainDS.AGiftDetail.Rows)
                {
                    AGiftBatchAccess.LoadByPrimaryKey(MainDS, Row.LedgerNumber, Row.BatchNumber, Transaction);
                    AGiftRow GiftRow =
                        AGiftAccess.LoadByPrimaryKey(MainDS, Row.LedgerNumber, Row.BatchNumber, Row.GiftTransactionNumber, Transaction);

                    Row.DateEntered = GiftRow.DateEntered;
                    Row.DonorKey    = GiftRow.DonorKey;
                    Row.DonorName   = PPartnerAccess.LoadByPrimaryKey(Row.DonorKey, Transaction)[0].PartnerShortName;
                }
            });

            AGiftDS = MainDS;

            return(TAdjustmentWebConnector.CheckGiftsNotPreviouslyReversed(AGiftDS, out AMessages));
        }
        public static bool GetGiftsForReverseAdjust(
            Hashtable requestParams, ref GiftBatchTDS AGiftDS, out TVerificationResultCollection AMessages)
        {
            GiftAdjustmentFunctionEnum Function = (GiftAdjustmentFunctionEnum)requestParams["Function"];
            Int32 LedgerNumber     = (Int32)requestParams["ALedgerNumber"];
            Int32 GiftDetailNumber = (Int32)requestParams["GiftDetailNumber"];
            Int32 GiftNumber       = (Int32)requestParams["GiftNumber"];
            Int32 BatchNumber      = (Int32)requestParams["BatchNumber"];

            AMessages = new TVerificationResultCollection();
            GiftBatchTDS MainDS = new GiftBatchTDS();

            TDBTransaction Transaction = null;

            DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                                                                      TEnforceIsolationLevel.eilMinimum,
                                                                      ref Transaction,
                                                                      delegate
            {
                // get data needed for new gifts
                if (Function.Equals(GiftAdjustmentFunctionEnum.ReverseGiftBatch))
                {
                    AGiftAccess.LoadViaAGiftBatch(MainDS, LedgerNumber, BatchNumber, Transaction);

                    foreach (AGiftRow gift in MainDS.AGift.Rows)
                    {
                        AGiftDetailAccess.LoadViaAGift(MainDS, LedgerNumber, BatchNumber, gift.GiftTransactionNumber, Transaction);
                    }
                }
                else
                {
                    AGiftAccess.LoadByPrimaryKey(MainDS, LedgerNumber, BatchNumber, GiftNumber, Transaction);

                    if (Function.Equals(GiftAdjustmentFunctionEnum.ReverseGiftDetail))
                    {
                        AGiftDetailAccess.LoadByPrimaryKey(MainDS, LedgerNumber, BatchNumber, GiftNumber, GiftDetailNumber, Transaction);
                    }
                    else
                    {
                        AGiftDetailAccess.LoadViaAGift(MainDS, LedgerNumber, BatchNumber, GiftNumber, Transaction);
                    }
                }
            });

            AGiftDS = MainDS;

            return(CheckGiftsNotPreviouslyReversed(AGiftDS, out AMessages));
        }
示例#6
0
        public static Int32 FieldChangeAdjustment(Int32 ALedgerNumber,
                                                  Int64 ARecipientKey,
                                                  DateTime AStartDate,
                                                  DateTime AEndDate,
                                                  Int64 AOldField,
                                                  DateTime ADateCorrection,
                                                  bool AWithReceipt)
        {
            TDBTransaction Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.ReadCommitted);
            GiftBatchTDS   oldGiftDS   = new GiftBatchTDS();

            try
            {
                // find all gifts that need reversing.
                // criteria:
                // posted gift batches only
                // no adjusted/reversed gifts
                // date of gift batch in specified date range
                // recipient field is the old field
                string SqlStmt = TDataBase.ReadSqlFile("Gift.GetGiftsToReverse.sql");

                List <OdbcParameter> parameters = new List <OdbcParameter>();
                OdbcParameter        param      = new OdbcParameter("LedgerNumber", OdbcType.Int);
                param.Value = ALedgerNumber;
                parameters.Add(param);
                param       = new OdbcParameter("StartDate", OdbcType.Date);
                param.Value = AStartDate;
                parameters.Add(param);
                param       = new OdbcParameter("EndDate", OdbcType.Date);
                param.Value = AEndDate;
                parameters.Add(param);
                param       = new OdbcParameter("RecipientKey", OdbcType.BigInt);
                param.Value = ARecipientKey;
                parameters.Add(param);
                param       = new OdbcParameter("OldField", OdbcType.BigInt);
                param.Value = AOldField;
                parameters.Add(param);

                DBAccess.GDBAccessObj.Select(oldGiftDS, SqlStmt, oldGiftDS.AGiftDetail.TableName, Transaction, parameters.ToArray());

                // load the gift and the gift batch records if they have not been loaded yet
                foreach (AGiftDetailRow giftdetail in oldGiftDS.AGiftDetail.Rows)
                {
                    oldGiftDS.AGift.DefaultView.RowFilter = String.Format("{0} = {1} and {2} = {3}",
                                                                          AGiftTable.GetBatchNumberDBName(),
                                                                          giftdetail.BatchNumber,
                                                                          AGiftTable.GetGiftTransactionNumberDBName(),
                                                                          giftdetail.GiftTransactionNumber);

                    if (oldGiftDS.AGift.DefaultView.Count == 0)
                    {
                        AGiftTable tempGiftTable =
                            AGiftAccess.LoadByPrimaryKey(giftdetail.LedgerNumber,
                                                         giftdetail.BatchNumber,
                                                         giftdetail.GiftTransactionNumber,
                                                         Transaction);
                        oldGiftDS.AGift.Merge(tempGiftTable);
                    }

                    oldGiftDS.AGiftBatch.DefaultView.RowFilter = String.Format("{0} = {1}",
                                                                               AGiftTable.GetBatchNumberDBName(),
                                                                               giftdetail.BatchNumber);

                    if (oldGiftDS.AGiftBatch.DefaultView.Count == 0)
                    {
                        AGiftBatchTable tempGiftBatchTable =
                            AGiftBatchAccess.LoadByPrimaryKey(giftdetail.LedgerNumber,
                                                              giftdetail.BatchNumber,
                                                              Transaction);
                        oldGiftDS.AGiftBatch.Merge(tempGiftBatchTable);
                    }
                }

                DBAccess.GDBAccessObj.RollbackTransaction();
            }
            catch (Exception)
            {
                DBAccess.GDBAccessObj.RollbackTransaction();
                throw;
            }

            // we need to create a gift batch for each set of gifts with the same Currency, BankAccountCode, BankCostCentre, and Gift Type
            SortedList <string, GiftBatchTDS> NewGiftBatches = new SortedList <string, GiftBatchTDS>();

            foreach (GiftBatchTDSAGiftDetailRow oldGiftDetail in oldGiftDS.AGiftDetail.Rows)
            {
                // get the gift batch row for this detail
                oldGiftDS.AGiftBatch.DefaultView.RowFilter =
                    String.Format("{0} = {1}",
                                  AGiftTable.GetBatchNumberDBName(), oldGiftDetail.BatchNumber);

                AGiftBatchRow oldGiftBatch = (AGiftBatchRow)oldGiftDS.AGiftBatch.DefaultView[0].Row;

                GiftBatchTDS GiftDS = CreateNewGiftBatch(NewGiftBatches, oldGiftBatch, ADateCorrection);

                AGiftBatchRow giftbatchRow = GiftDS.AGiftBatch[0];

                // get the gift row for this detail
                DataView v = oldGiftDS.AGift.DefaultView;
                v.RowFilter =
                    String.Format("{0} = {1} and {2} = {3}",
                                  AGiftTable.GetBatchNumberDBName(), oldGiftDetail.BatchNumber,
                                  AGiftTable.GetGiftTransactionNumberDBName(), oldGiftDetail.GiftTransactionNumber);

                AGiftRow oldGift = (AGiftRow)v[0].Row;

                AGiftRow gift = GiftDS.AGift.NewRowTyped();
                gift.LedgerNumber          = giftbatchRow.LedgerNumber;
                gift.BatchNumber           = giftbatchRow.BatchNumber;
                gift.GiftTransactionNumber = giftbatchRow.LastGiftNumber + 1;
                gift.DonorKey    = oldGift.DonorKey;
                gift.DateEntered = ADateCorrection;
                giftbatchRow.LastGiftNumber++;
                GiftDS.AGift.Rows.Add(gift);

                if (!AWithReceipt)
                {
                    gift.ReceiptLetterCode = "NO*RECET";
                }

                // reverse the original gift
                GiftBatchTDSAGiftDetailRow detail = GiftDS.AGiftDetail.NewRowTyped();

                DataUtilities.CopyAllColumnValues(oldGiftDetail, detail);

                detail.LedgerNumber          = gift.LedgerNumber;
                detail.BatchNumber           = gift.BatchNumber;
                detail.GiftTransactionNumber = gift.GiftTransactionNumber;
                detail.DetailNumber          = gift.LastDetailNumber + 1;
                detail.GiftAmount            = detail.GiftAmount * -1;
                detail.GiftAmountIntl        = detail.GiftAmountIntl * -1;
                detail.GiftTransactionAmount = detail.GiftTransactionAmount * -1;
                gift.LastDetailNumber++;

                GiftDS.AGiftDetail.Rows.Add(detail);

                // create the detail for the corrected gift to the new field
                detail = GiftDS.AGiftDetail.NewRowTyped();

                DataUtilities.CopyAllColumnValues(oldGiftDetail, detail);

                detail.LedgerNumber          = gift.LedgerNumber;
                detail.BatchNumber           = gift.BatchNumber;
                detail.GiftTransactionNumber = gift.GiftTransactionNumber;
                detail.DetailNumber          = gift.LastDetailNumber + 1;
                detail.GiftCommentOne        = String.Format(Catalog.GetString("posted on {0}"), oldGiftBatch.GlEffectiveDate.ToShortDateString());
                gift.LastDetailNumber++;

                // TODO: calculate costcentre code from current commitment; this currently is done only at time of posting
                // detail.RecipientLedgerNumber = oldGiftDetail.RecipientLedgerNumber;
                // detail.CostCentreCode = oldGiftDetail.CostCentreCode;

                GiftDS.AGiftDetail.Rows.Add(detail);

                // TODO: how to make sure that the gl transaction is marked as System generated? avoid display on HOSA?

                // mark original gift detail as modified
                oldGiftDetail.ModifiedDetail = true;
            }

            TVerificationResultCollection VerificationResult;

            TSubmitChangesResult result = TSubmitChangesResult.scrOK;

            for (Int32 batchCounter = 0; batchCounter < NewGiftBatches.Count; batchCounter++)
            {
                if (result == TSubmitChangesResult.scrOK)
                {
                    GiftBatchTDS GiftDS = NewGiftBatches.Values[batchCounter];
                    result = TGiftTransactionWebConnector.SaveGiftBatchTDS(ref GiftDS, out VerificationResult);
                }
            }

            if (result == TSubmitChangesResult.scrOK)
            {
                result = TGiftTransactionWebConnector.SaveGiftBatchTDS(ref oldGiftDS, out VerificationResult);

                if ((result == TSubmitChangesResult.scrOK) && (NewGiftBatches.Count > 0))
                {
                    return(NewGiftBatches.Values[0].AGiftBatch[0].BatchNumber);
                }
            }

            return(-1);
        }
示例#7
0
        public static bool GiftRevertAdjust(Hashtable requestParams, out TVerificationResultCollection AMessages)
        {
            AMessages = new TVerificationResultCollection();

            Int32   ALedgerNumber   = (Int32)requestParams["ALedgerNumber"];
            Boolean batchSelected   = (Boolean)requestParams["NewBatchSelected"];
            Int32   ANewBatchNumber = 0;

            bool TaxDeductiblePercentageEnabled = Convert.ToBoolean(
                TSystemDefaults.GetSystemDefault(SharedConstants.SYSDEFAULT_TAXDEDUCTIBLEPERCENTAGE, "FALSE"));

            if (batchSelected)
            {
                ANewBatchNumber = (Int32)requestParams["NewBatchNumber"];
            }

            String Function          = (String)requestParams["Function"];
            Int32  AGiftDetailNumber = (Int32)requestParams["GiftDetailNumber"];
            Int32  AGiftNumber       = (Int32)requestParams["GiftNumber"];
            Int32  ABatchNumber      = (Int32)requestParams["BatchNumber"];

            //decimal batchHashTotal = 0;
            decimal batchGiftTotal = 0;

            GiftBatchTDS   MainDS      = new GiftBatchTDS();
            TDBTransaction Transaction = null;
            DateTime       ADateEffective;

            Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.Serializable);

            try
            {
                ALedgerTable LedgerTable = ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, Transaction);

                AGiftBatchRow giftBatch;

                if (!batchSelected)
                {
                    ADateEffective = (DateTime)requestParams["GlEffectiveDate"];

                    AGiftBatchAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, ABatchNumber, Transaction);

                    AGiftBatchRow oldGiftBatch = MainDS.AGiftBatch[0];
                    TGiftBatchFunctions.CreateANewGiftBatchRow(ref MainDS, ref Transaction, ref LedgerTable, ALedgerNumber, ADateEffective);
                    giftBatch = MainDS.AGiftBatch[1];
                    giftBatch.BankAccountCode     = oldGiftBatch.BankAccountCode;
                    giftBatch.BankCostCentre      = oldGiftBatch.BankCostCentre;
                    giftBatch.CurrencyCode        = oldGiftBatch.CurrencyCode;
                    giftBatch.ExchangeRateToBase  = oldGiftBatch.ExchangeRateToBase;
                    giftBatch.MethodOfPaymentCode = oldGiftBatch.MethodOfPaymentCode;
                    giftBatch.HashTotal           = 0;

                    if (giftBatch.MethodOfPaymentCode.Length == 0)
                    {
                        giftBatch.SetMethodOfPaymentCodeNull();
                    }

                    giftBatch.BankCostCentre = oldGiftBatch.BankCostCentre;
                    giftBatch.GiftType       = oldGiftBatch.GiftType;

                    if (Function.Equals("AdjustGift"))
                    {
                        giftBatch.BatchDescription = Catalog.GetString("Gift Adjustment");
                    }
                    else
                    {
                        giftBatch.BatchDescription = Catalog.GetString("Reverse Gift");
                    }
                }
                else
                {
                    AGiftBatchAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, ANewBatchNumber, Transaction);

                    giftBatch      = MainDS.AGiftBatch[0];
                    ADateEffective = giftBatch.GlEffectiveDate;
                    //If into an existing batch, then retrive the existing batch total
                    batchGiftTotal = giftBatch.BatchTotal;
                }

                if (Function.Equals("ReverseGiftBatch"))
                {
                    AGiftAccess.LoadViaAGiftBatch(MainDS, ALedgerNumber, ABatchNumber, Transaction);

                    foreach (AGiftRow gift in MainDS.AGift.Rows)
                    {
                        AGiftDetailAccess.LoadViaAGift(MainDS, ALedgerNumber, ABatchNumber, gift.GiftTransactionNumber, Transaction);
                    }
                }
                else
                {
                    AGiftAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, ABatchNumber, AGiftNumber, Transaction);

                    if (Function.Equals("ReverseGiftDetail"))
                    {
                        AGiftDetailAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, ABatchNumber, AGiftNumber, AGiftDetailNumber, Transaction);
                    }
                    else
                    {
                        AGiftDetailAccess.LoadViaAGift(MainDS, ALedgerNumber, ABatchNumber, AGiftNumber, Transaction);
                    }
                }

                //assuming new elements are added after these static borders

                int cycle = 0;

                MainDS.AGift.DefaultView.Sort = string.Format("{0}, {1}",
                                                              AGiftTable.GetBatchNumberDBName(),
                                                              AGiftTable.GetGiftTransactionNumberDBName());

                MainDS.AGiftDetail.DefaultView.Sort = string.Format("{0}, {1}, {2}",
                                                                    AGiftDetailTable.GetBatchNumberDBName(),
                                                                    AGiftDetailTable.GetGiftTransactionNumberDBName(),
                                                                    AGiftDetailTable.GetDetailNumberDBName());

                do
                {
                    foreach (DataRowView giftRow in MainDS.AGift.DefaultView)
                    {
                        AGiftRow oldGift = (AGiftRow)giftRow.Row;

                        if ((oldGift.BatchNumber == ABatchNumber) && (oldGift.LedgerNumber == ALedgerNumber) &&
                            (Function.Equals("ReverseGiftBatch") || (oldGift.GiftTransactionNumber == AGiftNumber)))
                        {
                            AGiftRow gift = MainDS.AGift.NewRowTyped(true);
                            DataUtilities.CopyAllColumnValuesWithoutPK(oldGift, gift);
                            gift.LedgerNumber          = giftBatch.LedgerNumber;
                            gift.BatchNumber           = giftBatch.BatchNumber;
                            gift.DateEntered           = ADateEffective;
                            gift.GiftTransactionNumber = giftBatch.LastGiftNumber + 1;
                            giftBatch.LastGiftNumber++;
                            gift.LastDetailNumber = 0;

                            MainDS.AGift.Rows.Add(gift);

                            foreach (DataRowView giftDetailRow in MainDS.AGiftDetail.DefaultView)
                            {
                                AGiftDetailRow oldGiftDetail = (AGiftDetailRow)giftDetailRow.Row;

                                if ((oldGiftDetail.GiftTransactionNumber == oldGift.GiftTransactionNumber) &&
                                    (oldGiftDetail.BatchNumber == ABatchNumber) &&
                                    (oldGiftDetail.LedgerNumber == ALedgerNumber) &&
                                    (!Function.Equals("ReverseGiftDetail") || (oldGiftDetail.DetailNumber == AGiftDetailNumber)))
                                {
                                    if ((cycle == 0) && oldGiftDetail.ModifiedDetail)
                                    {
                                        AMessages.Add(new TVerificationResult(
                                                          String.Format(Catalog.GetString("Cannot reverse or adjust Gift {0} with Detail {1} in Batch {2}"),
                                                                        oldGiftDetail.GiftTransactionNumber, oldGiftDetail.DetailNumber, oldGiftDetail.BatchNumber),
                                                          String.Format(Catalog.GetString("It was already adjusted or reversed.")),
                                                          TResultSeverity.Resv_Critical));

                                        DBAccess.GDBAccessObj.RollbackTransaction();

                                        return(false);
                                    }

                                    AGiftDetailRow giftDetail = MainDS.AGiftDetail.NewRowTyped(true);
                                    DataUtilities.CopyAllColumnValuesWithoutPK(oldGiftDetail, giftDetail);

                                    giftDetail.DetailNumber = ++gift.LastDetailNumber;

                                    giftDetail.LedgerNumber          = gift.LedgerNumber;
                                    giftDetail.BatchNumber           = giftBatch.BatchNumber;
                                    giftDetail.GiftTransactionNumber = gift.GiftTransactionNumber;
                                    //Identify the reversal source
                                    giftDetail.ModifiedDetailKey = "|" + oldGiftDetail.BatchNumber.ToString() + "|" +
                                                                   oldGiftDetail.GiftTransactionNumber.ToString() + "|" +
                                                                   oldGiftDetail.DetailNumber.ToString();

                                    decimal signum = (cycle == 0) ? -1 : 1;
                                    giftDetail.GiftTransactionAmount = signum * oldGiftDetail.GiftTransactionAmount;
                                    batchGiftTotal           += giftDetail.GiftTransactionAmount;
                                    giftDetail.GiftAmount     = signum * oldGiftDetail.GiftAmount;
                                    giftDetail.GiftAmountIntl = signum * oldGiftDetail.GiftAmountIntl;

                                    if (TaxDeductiblePercentageEnabled)
                                    {
                                        giftDetail.TaxDeductibleAmount     = signum * oldGiftDetail.TaxDeductibleAmount;
                                        giftDetail.TaxDeductibleAmountBase = signum * oldGiftDetail.TaxDeductibleAmountBase;
                                        giftDetail.TaxDeductibleAmountIntl = signum * oldGiftDetail.TaxDeductibleAmountIntl;
                                        giftDetail.NonDeductibleAmount     = signum * oldGiftDetail.NonDeductibleAmount;
                                        giftDetail.NonDeductibleAmountBase = signum * oldGiftDetail.NonDeductibleAmountBase;
                                        giftDetail.NonDeductibleAmountIntl = signum * oldGiftDetail.NonDeductibleAmountIntl;
                                    }

                                    giftDetail.GiftCommentOne   = (String)requestParams["ReversalCommentOne"];
                                    giftDetail.GiftCommentTwo   = (String)requestParams["ReversalCommentTwo"];
                                    giftDetail.GiftCommentThree = (String)requestParams["ReversalCommentThree"];
                                    giftDetail.CommentOneType   = (String)requestParams["ReversalCommentOneType"];
                                    giftDetail.CommentTwoType   = (String)requestParams["ReversalCommentTwoType"];
                                    giftDetail.CommentThreeType = (String)requestParams["ReversalCommentThreeType"];

                                    // This is used to mark both as a Reverted giftDetails, except the adjusted (new) gift

                                    giftDetail.ModifiedDetail    = (cycle == 0);
                                    oldGiftDetail.ModifiedDetail = (cycle == 0);
                                    MainDS.AGiftDetail.Rows.Add(giftDetail);
                                }
                            }
                        }
                    }

                    cycle++;
                } while ((cycle < 2) && Function.Equals("AdjustGift"));

                //When reversing into a new or existing batch, set batch total
                if (!Function.Equals("AdjustGift"))
                {
                    giftBatch.BatchTotal = batchGiftTotal;
                }

                // save everything at the end
                AGiftBatchAccess.SubmitChanges(MainDS.AGiftBatch, Transaction);

                ALedgerAccess.SubmitChanges(LedgerTable, Transaction);

                AGiftAccess.SubmitChanges(MainDS.AGift, Transaction);

                AGiftDetailAccess.SubmitChanges(MainDS.AGiftDetail, Transaction);

                MainDS.AGiftBatch.AcceptChanges();

                DBAccess.GDBAccessObj.CommitTransaction();

                return(true);
            }
            catch (Exception Exc)
            {
                TLogging.Log("An Exception occured while performing Gift Reverse/Adjust:" + Environment.NewLine + Exc.ToString());

                DBAccess.GDBAccessObj.RollbackTransaction();

                throw new EOPAppException(Catalog.GetString("Gift Reverse/Adjust failed."), Exc);
            }
        }
示例#8
0
        public static bool GiftRevertAdjust(
            Int32 ALedgerNumber,
            Int32 ABatchNumber,
            Int32 AGiftDetailNumber,
            bool ABatchSelected,
            Int32 ANewBatchNumber,
            DateTime?ANewGLDateEffective,
            GiftAdjustmentFunctionEnum AFunction,
            bool ANoReceipt,
            Decimal ANewPct,
            out int AAdjustmentBatchNumber)
        {
            AAdjustmentBatchNumber = 0;
            int AdjustmentBatchNo = AAdjustmentBatchNumber;

            GiftBatchTDS GiftDS = new GiftBatchTDS();

            decimal batchGiftTotal = 0;

            ANewBatchNumber = ABatchSelected ? ANewBatchNumber : 0;

            TDBTransaction Transaction  = new TDBTransaction();
            TDataBase      db           = DBAccess.Connect("GiftRevertAdjust");
            bool           SubmissionOK = false;

            try
            {
                db.WriteTransaction(
                    ref Transaction,
                    ref SubmissionOK,
                    delegate
                {
                    // load the original gifts and gift details
                    AGiftAccess.LoadViaAGiftBatch(GiftDS, ALedgerNumber, ABatchNumber, Transaction);
                    AGiftDetailAccess.LoadViaAGiftBatch(GiftDS, ALedgerNumber, ABatchNumber, Transaction);

                    ALedgerTable ledgerTable = ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, Transaction);

                    AGiftBatchRow giftBatch;

                    DateTime DateEffective;

                    if (ANewGLDateEffective.HasValue)
                    {
                        DateEffective = ANewGLDateEffective.Value;
                    }
                    else
                    {
                        AGiftBatchTable OriginalGiftBatch = AGiftBatchAccess.LoadByPrimaryKey(ALedgerNumber, ABatchNumber, Transaction);
                        DateEffective = OriginalGiftBatch[0].GlEffectiveDate;
                    }

                    // if we need to create a new gift batch
                    if (!ABatchSelected)
                    {
                        giftBatch = CreateNewGiftBatch(
                            ALedgerNumber,
                            ABatchNumber,
                            DateEffective,
                            AFunction,
                            ref GiftDS, ref ledgerTable, Transaction);
                    }
                    else     // using an existing gift batch
                    {
                        AGiftBatchAccess.LoadByPrimaryKey(GiftDS, ALedgerNumber, ANewBatchNumber, Transaction);

                        giftBatch     = GiftDS.AGiftBatch[0];
                        DateEffective = giftBatch.GlEffectiveDate;
                        //If into an existing batch, then retrieve the existing batch total
                        batchGiftTotal = giftBatch.BatchTotal;
                    }

                    AdjustmentBatchNo = giftBatch.BatchNumber;

                    //assuming new elements are added after these static borders

                    GiftDS.AGift.DefaultView.Sort = string.Format("{0}, {1}",
                                                                  AGiftTable.GetBatchNumberDBName(),
                                                                  AGiftTable.GetGiftTransactionNumberDBName());

                    GiftDS.AGiftDetail.DefaultView.Sort = string.Format("{0}, {1}, {2}",
                                                                        AGiftDetailTable.GetBatchNumberDBName(),
                                                                        AGiftDetailTable.GetGiftTransactionNumberDBName(),
                                                                        AGiftDetailTable.GetDetailNumberDBName());

                    foreach (DataRowView giftRow in GiftDS.AGift.DefaultView)
                    {
                        int cycle = 0;

                        // first cycle creates gift reversal; second cycle creates new adjusted gift (if needed)
                        do
                        {
                            AGiftRow oldGift = (AGiftRow)giftRow.Row;

                            if (oldGift.RowState != DataRowState.Added)
                            {
                                AGiftRow gift = GiftDS.AGift.NewRowTyped(true);
                                DataUtilities.CopyAllColumnValuesWithoutPK(oldGift, gift);
                                gift.LedgerNumber = giftBatch.LedgerNumber;
                                gift.BatchNumber  = giftBatch.BatchNumber;
                                // keep the same DateEntered as in the original gift if it is in the same period as the batch
                                if ((gift.DateEntered.Year != DateEffective.Year) || (gift.DateEntered.Month != DateEffective.Month))
                                {
                                    gift.DateEntered = DateEffective;
                                }
                                gift.GiftTransactionNumber = giftBatch.LastGiftNumber + 1;
                                giftBatch.LastGiftNumber++;
                                gift.LinkToPreviousGift = (cycle != 0);
                                gift.LastDetailNumber   = 0;
                                gift.FirstTimeGift      = false;

                                // do not print a receipt for reversed gifts
                                if (cycle == 0)
                                {
                                    gift.ReceiptPrinted = true;
                                    gift.PrintReceipt   = false;
                                }
                                else
                                {
                                    gift.ReceiptPrinted = false;
                                    gift.PrintReceipt   = !ANoReceipt;
                                }

                                GiftDS.AGift.Rows.Add(gift);

                                foreach (DataRowView giftDetailRow in GiftDS.AGiftDetail.DefaultView)
                                {
                                    AGiftDetailRow oldGiftDetail = (AGiftDetailRow)giftDetailRow.Row;

                                    // if gift detail belongs to gift
                                    if ((oldGiftDetail.GiftTransactionNumber == oldGift.GiftTransactionNumber) &&
                                        (oldGiftDetail.BatchNumber == oldGift.BatchNumber) &&
                                        (AFunction != GiftAdjustmentFunctionEnum.ReverseGiftDetail) ||
                                        (oldGiftDetail.DetailNumber == AGiftDetailNumber))
                                    {
                                        AddDuplicateGiftDetailToGift(ref GiftDS, ref gift, oldGiftDetail, cycle == 0, Transaction,
                                                                     AFunction,
                                                                     ANewPct);

                                        batchGiftTotal += ((cycle == 0) ? 0 : oldGiftDetail.GiftTransactionAmount);

                                        // original gift also gets marked as a reversal
                                        oldGiftDetail.ModifiedDetail = true;
                                    }
                                }
                            }

                            cycle++;
                        } while ((cycle < 2) &&
                                 (AFunction.Equals(GiftAdjustmentFunctionEnum.AdjustGift) ||
                                  AFunction.Equals(GiftAdjustmentFunctionEnum.FieldAdjust) ||
                                  AFunction.Equals(GiftAdjustmentFunctionEnum.TaxDeductiblePctAdjust)));
                    }

                    //When reversing into a new or existing batch, set batch total
                    giftBatch.BatchTotal = batchGiftTotal;

                    // save everything at the end
                    AGiftBatchAccess.SubmitChanges(GiftDS.AGiftBatch, Transaction);
                    ALedgerAccess.SubmitChanges(ledgerTable, Transaction);
                    AGiftAccess.SubmitChanges(GiftDS.AGift, Transaction);
                    AGiftDetailAccess.SubmitChanges(GiftDS.AGiftDetail, Transaction);

                    GiftDS.AGiftBatch.AcceptChanges();

                    SubmissionOK = true;
                });
            }
            catch (Exception ex)
            {
                TLogging.LogException(ex, Utilities.GetMethodSignature());
                throw new EOPAppException(Catalog.GetString("Gift Reverse/Adjust failed."), ex);
            }

            AAdjustmentBatchNumber = AdjustmentBatchNo;

            db.CloseDBConnection();

            return(SubmissionOK);
        }
示例#9
0
        /// <summary>
        /// get more details of the last gift of the partner
        /// </summary>
        /// <param name="APartnerKey"></param>
        /// <param name="ALastGiftDate"></param>
        /// <param name="ALastGiftAmount"></param>
        /// <param name="ALastGiftGivenToPartnerKey"></param>
        /// <param name="ALastGiftRecipientLedger"></param>
        /// <param name="ALastGiftCurrencyCode"></param>
        /// <param name="ALastGiftDisplayFormat"></param>
        /// <param name="ALastGiftGivenToShortName"></param>
        /// <param name="ALastGiftRecipientLedgerShortName"></param>
        /// <param name="ARestrictedOrConfidentialGiftAccessDenied"></param>
        /// <returns></returns>
        public static Boolean GetLastGiftDetails(Int64 APartnerKey,
                                                 out DateTime ALastGiftDate,
                                                 out decimal ALastGiftAmount,
                                                 out Int64 ALastGiftGivenToPartnerKey,
                                                 out Int64 ALastGiftRecipientLedger,
                                                 out String ALastGiftCurrencyCode,
                                                 out String ALastGiftDisplayFormat,
                                                 out String ALastGiftGivenToShortName,
                                                 out String ALastGiftRecipientLedgerShortName,
                                                 out Boolean ARestrictedOrConfidentialGiftAccessDenied)
        {
            DataSet          LastGiftDS;
            AGiftDetailTable GiftDetailDT;
            SGroupGiftTable  GroupGiftDT;
            SUserGroupTable  UserGroupDT;
            AGiftRow         GiftDR;
            AGiftBatchRow    GiftBatchDR;
            AGiftDetailRow   GiftDetailDR;
            ACurrencyRow     CurrencyDR;
            Int16            Counter;
            Boolean          AccessToGift = false;

            DataRow[] FoundUserGroups;

            ALastGiftAmount                           = 0;
            ALastGiftCurrencyCode                     = "";
            ALastGiftDisplayFormat                    = "";
            ALastGiftDate                             = DateTime.MinValue;
            ALastGiftGivenToPartnerKey                = 0;
            ALastGiftGivenToShortName                 = "";
            ALastGiftRecipientLedger                  = 0;
            ALastGiftRecipientLedgerShortName         = "";
            ARestrictedOrConfidentialGiftAccessDenied = false;

            DateTime tmpLastGiftDate                             = ALastGiftDate;
            decimal  tmpLastGiftAmount                           = ALastGiftAmount;
            Int64    tmpLastGiftGivenToPartnerKey                = ALastGiftGivenToPartnerKey;
            Int64    tmpLastGiftRecipientLedger                  = ALastGiftRecipientLedger;
            String   tmpLastGiftCurrencyCode                     = ALastGiftCurrencyCode;
            String   tmpLastGiftDisplayFormat                    = ALastGiftDisplayFormat;
            String   tmpLastGiftGivenToShortName                 = ALastGiftGivenToShortName;
            String   tmpLastGiftRecipientLedgerShortName         = ALastGiftRecipientLedgerShortName;
            Boolean  tmpRestrictedOrConfidentialGiftAccessDenied = ARestrictedOrConfidentialGiftAccessDenied;

            if ((!UserInfo.GUserInfo.IsTableAccessOK(TTableAccessPermission.tapINQUIRE, AGiftTable.GetTableDBName())))
            {
                // User hasn't got access to a_gift Table in the DB
                return(false);
            }

            // Set up temp DataSet
            LastGiftDS = new DataSet("LastGiftDetails");
            LastGiftDS.Tables.Add(new AGiftTable());
            LastGiftDS.Tables.Add(new AGiftBatchTable());
            LastGiftDS.Tables.Add(new AGiftDetailTable());
            LastGiftDS.Tables.Add(new ACurrencyTable());
            LastGiftDS.Tables.Add(new PPartnerTable());

            TDBTransaction Transaction  = null;
            bool           SubmissionOK = true;

            // Important: The IsolationLevel here needs to correspond with the IsolationLevel in the
            // Ict.Petra.Server.MPartner.Partner.UIConnectors.TPartnerEditUIConnector.LoadData Method
            // as otherwise the attempt of taking-out of a DB Transaction here will lead to Bug #4167!
            DBAccess.GDBAccessObj.GetNewOrExistingAutoTransaction(IsolationLevel.ReadCommitted,
                                                                  TEnforceIsolationLevel.eilMinimum, ref Transaction, ref SubmissionOK,
                                                                  delegate
            {
                try
                {
                    try
                    {
                        AGiftAccess.LoadViaPPartner(LastGiftDS, APartnerKey, null, Transaction,
                                                    StringHelper.InitStrArr(new String[] { "ORDER BY", AGiftTable.GetDateEnteredDBName() + " DESC" }), 0, 1);
                    }
                    catch (ESecurityDBTableAccessDeniedException)
                    {
                        // User hasn't got access to a_gift Table in the DB
                        return;
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }

                    if (LastGiftDS.Tables[AGiftTable.GetTableName()].Rows.Count == 0)
                    {
                        // Partner hasn't given any Gift so far
                        return;
                    }

                    // Get the last gift
                    GiftDR = ((AGiftTable)LastGiftDS.Tables[AGiftTable.GetTableName()])[0];

                    if (GiftDR.Restricted)
                    {
                        AccessToGift = false;
                        GroupGiftDT  = SGroupGiftAccess.LoadViaAGift(
                            GiftDR.LedgerNumber,
                            GiftDR.BatchNumber,
                            GiftDR.GiftTransactionNumber,
                            Transaction);
                        UserGroupDT = SUserGroupAccess.LoadViaSUser(UserInfo.GUserInfo.UserID, Transaction);

                        // Loop over all rows of GroupGiftDT
                        for (Counter = 0; Counter <= GroupGiftDT.Rows.Count - 1; Counter += 1)
                        {
                            // To be able to view a Gift, ReadAccess must be granted
                            if (GroupGiftDT[Counter].ReadAccess)
                            {
                                // Find out whether the user has a row in s_user_group with the
                                // GroupID of the GroupGift row
                                FoundUserGroups =
                                    UserGroupDT.Select(SUserGroupTable.GetGroupIdDBName() + " = '" + GroupGiftDT[Counter].GroupId + "'");

                                if (FoundUserGroups.Length != 0)
                                {
                                    // Access to gift can be granted
                                    AccessToGift = true;
                                    continue;

                                    // don't evaluate further GroupGiftDT rows
                                }
                            }
                        }
                    }
                    else
                    {
                        AccessToGift = true;
                    }

                    if (AccessToGift)
                    {
                        tmpLastGiftDate = GiftDR.DateEntered;

                        // Console.WriteLine('GiftDR.LedgerNumber: ' + GiftDR.LedgerNumber.ToString + '; ' +
                        // 'GiftDR.BatchNumber:  ' + GiftDR.BatchNumber.ToString);
                        // Load Gift Batch
                        AGiftBatchAccess.LoadByPrimaryKey(LastGiftDS, GiftDR.LedgerNumber, GiftDR.BatchNumber,
                                                          StringHelper.InitStrArr(new String[] { AGiftBatchTable.GetCurrencyCodeDBName() }), Transaction, null, 0, 0);

                        if (LastGiftDS.Tables[AGiftBatchTable.GetTableName()].Rows.Count != 0)
                        {
                            GiftBatchDR             = ((AGiftBatchRow)LastGiftDS.Tables[AGiftBatchTable.GetTableName()].Rows[0]);
                            tmpLastGiftCurrencyCode = GiftBatchDR.CurrencyCode;

                            // Get Currency
                            ACurrencyAccess.LoadByPrimaryKey(LastGiftDS, GiftBatchDR.CurrencyCode, Transaction);

                            if (LastGiftDS.Tables[ACurrencyTable.GetTableName()].Rows.Count != 0)
                            {
                                CurrencyDR = (ACurrencyRow)(LastGiftDS.Tables[ACurrencyTable.GetTableName()].Rows[0]);
                                tmpLastGiftCurrencyCode  = CurrencyDR.CurrencyCode;
                                tmpLastGiftDisplayFormat = CurrencyDR.DisplayFormat;
                            }
                            else
                            {
                                tmpLastGiftCurrencyCode  = "";
                                tmpLastGiftDisplayFormat = "";
                            }
                        }
                        else
                        {
                            // missing Currency
                            tmpLastGiftCurrencyCode  = "";
                            tmpLastGiftDisplayFormat = "";
                        }

                        // Load Gift Detail
                        AGiftDetailAccess.LoadViaAGift(LastGiftDS,
                                                       GiftDR.LedgerNumber,
                                                       GiftDR.BatchNumber,
                                                       GiftDR.GiftTransactionNumber,
                                                       StringHelper.InitStrArr(new String[] { AGiftDetailTable.GetGiftTransactionAmountDBName(),
                                                                                              AGiftDetailTable.GetRecipientKeyDBName(),
                                                                                              AGiftDetailTable.
                                                                                              GetRecipientLedgerNumberDBName(),
                                                                                              AGiftDetailTable.GetConfidentialGiftFlagDBName() }),
                                                       Transaction,
                                                       null,
                                                       0,
                                                       0);
                        GiftDetailDT = (AGiftDetailTable)LastGiftDS.Tables[AGiftDetailTable.GetTableName()];

                        if (GiftDetailDT.Rows.Count != 0)
                        {
                            if (GiftDR.LastDetailNumber > 1)
                            {
                                // Gift is a Split Gift
                                tmpLastGiftAmount = 0;

                                for (Counter = 0; Counter <= GiftDetailDT.Rows.Count - 1; Counter += 1)
                                {
                                    GiftDetailDR = (AGiftDetailRow)GiftDetailDT.Rows[Counter];

                                    // Check for confidential gift and whether the current user is allowed to see it
                                    if (GiftDetailDR.ConfidentialGiftFlag)
                                    {
                                        if (!((UserInfo.GUserInfo.IsInGroup(SharedConstants.PETRAGROUP_FINANCE2)) ||
                                              (UserInfo.GUserInfo.IsInGroup(SharedConstants.PETRAGROUP_FINANCE3))))
                                        {
                                            // User isn't allowed to see the gift
                                            tmpRestrictedOrConfidentialGiftAccessDenied = true;
                                            tmpLastGiftAmount = 0;
                                            return;
                                        }
                                    }

                                    tmpLastGiftAmount = tmpLastGiftAmount + GiftDetailDR.GiftTransactionAmount;
                                }

                                tmpLastGiftGivenToShortName         = "";
                                tmpLastGiftRecipientLedgerShortName = "";
                                tmpLastGiftGivenToPartnerKey        = -1;
                                tmpLastGiftRecipientLedger          = -1;
                            }
                            else
                            {
                                // Gift isn't a Split Gift
                                GiftDetailDR = (AGiftDetailRow)GiftDetailDT.Rows[0];

                                // Check for confidential gift and whether the current user is allowed to see it
                                if (GiftDetailDR.ConfidentialGiftFlag)
                                {
                                    if (!((UserInfo.GUserInfo.IsInGroup(SharedConstants.PETRAGROUP_FINANCE2)) ||
                                          (UserInfo.GUserInfo.IsInGroup(SharedConstants.PETRAGROUP_FINANCE3))))
                                    {
                                        // User isn't allowed to see the gift
                                        tmpRestrictedOrConfidentialGiftAccessDenied = true;
                                        return;
                                    }
                                }

                                tmpLastGiftAmount            = GiftDetailDR.GiftTransactionAmount;
                                tmpLastGiftGivenToPartnerKey = GiftDetailDR.RecipientKey;

                                // Get Partner ShortName
                                PPartnerAccess.LoadByPrimaryKey(LastGiftDS, GiftDetailDR.RecipientKey,
                                                                StringHelper.InitStrArr(new String[] { PPartnerTable.GetPartnerShortNameDBName() }), Transaction, null, 0, 0);

                                if (LastGiftDS.Tables[PPartnerTable.GetTableName()].Rows.Count != 0)
                                {
                                    tmpLastGiftGivenToShortName =
                                        ((PPartnerRow)(LastGiftDS.Tables[PPartnerTable.GetTableName()].Rows[0])).PartnerShortName;
                                }
                                else
                                {
                                    // missing Partner
                                    tmpLastGiftGivenToShortName = "";
                                }

                                // Get rid of last record because we are about to select again into the same DataTable...
                                LastGiftDS.Tables[PPartnerTable.GetTableName()].Rows.Clear();

                                // Get Recipient Ledger
                                PPartnerAccess.LoadByPrimaryKey(LastGiftDS, GiftDetailDR.RecipientLedgerNumber,
                                                                StringHelper.InitStrArr(new String[] { PPartnerTable.GetPartnerShortNameDBName() }), Transaction, null, 0, 0);

                                if (LastGiftDS.Tables[PPartnerTable.GetTableName()].Rows.Count != 0)
                                {
                                    tmpLastGiftRecipientLedgerShortName =
                                        ((PPartnerRow)(LastGiftDS.Tables[PPartnerTable.GetTableName()].Rows[0])).PartnerShortName;
                                }
                                else
                                {
                                    // missing Ledger
                                    tmpLastGiftRecipientLedgerShortName = "";
                                }
                            }
                        }
                        else
                        {
                            // missing Gift Detail
                            tmpLastGiftAmount                   = 0;
                            tmpLastGiftGivenToShortName         = "";
                            tmpLastGiftRecipientLedgerShortName = "";
                            tmpLastGiftGivenToPartnerKey        = -1;
                            tmpLastGiftRecipientLedger          = -1;
                        }
                    }
                    else
                    {
                        // Gift is a restriced Gift and the current user isn't allowed to see it
                        tmpRestrictedOrConfidentialGiftAccessDenied = true;
                    }
                }
                finally
                {
                    TLogging.LogAtLevel(7, "TGift.GetLastGiftDetails: committed own transaction.");
                }
            });

            ALastGiftDate                             = tmpLastGiftDate;
            ALastGiftAmount                           = tmpLastGiftAmount;
            ALastGiftGivenToPartnerKey                = tmpLastGiftGivenToPartnerKey;
            ALastGiftRecipientLedger                  = tmpLastGiftRecipientLedger;
            ALastGiftCurrencyCode                     = tmpLastGiftCurrencyCode;
            ALastGiftDisplayFormat                    = tmpLastGiftDisplayFormat;
            ALastGiftGivenToShortName                 = tmpLastGiftGivenToShortName;
            ALastGiftRecipientLedgerShortName         = tmpLastGiftRecipientLedgerShortName;
            ARestrictedOrConfidentialGiftAccessDenied = tmpRestrictedOrConfidentialGiftAccessDenied;

            return(AccessToGift);
        }
示例#10
0
        public static bool GiftRevertAdjust(Hashtable requestParams, out int AAdjustmentBatchNumber, GiftBatchTDS AGiftDS)
        {
            AAdjustmentBatchNumber = 0;
            int AdjustmentBatchNo = AAdjustmentBatchNumber;

            if ((AGiftDS == null) || (AGiftDS.AGiftDetail == null) || (AGiftDS.AGiftDetail.Rows.Count == 0))
            {
                TLogging.Log("Empty dataset sent to GiftRevertAdjust");
                return(false);
            }

            Int32   ALedgerNumber = (Int32)requestParams["ALedgerNumber"];
            Boolean BatchSelected = (Boolean)requestParams["NewBatchSelected"];
            GiftAdjustmentFunctionEnum Function = (GiftAdjustmentFunctionEnum)requestParams["Function"];
            Int32 GiftDetailNumber = (Int32)requestParams["GiftDetailNumber"];
            bool  NoReceipt        = (Boolean)requestParams["NoReceipt"];

            DateTime DateEffective;
            decimal  batchGiftTotal  = 0;
            Int32    ANewBatchNumber = (BatchSelected ? (Int32)requestParams["NewBatchNumber"] : 0);

            TDBTransaction Transaction  = null;
            bool           SubmissionOK = false;

            try
            {
                DBAccess.GDBAccessObj.GetNewOrExistingAutoTransaction(IsolationLevel.Serializable,
                                                                      ref Transaction,
                                                                      ref SubmissionOK,
                                                                      delegate
                {
                    ALedgerTable ledgerTable = ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, Transaction);

                    AGiftBatchRow giftBatch;

                    // if we need to create a new gift batch
                    if (!BatchSelected)
                    {
                        giftBatch = CreateNewGiftBatch(requestParams, ref AGiftDS, out DateEffective, ref ledgerTable, Transaction);
                    }
                    else     // using an existing gift batch
                    {
                        AGiftBatchAccess.LoadByPrimaryKey(AGiftDS, ALedgerNumber, ANewBatchNumber, Transaction);

                        giftBatch     = AGiftDS.AGiftBatch[0];
                        DateEffective = giftBatch.GlEffectiveDate;
                        //If into an existing batch, then retrive the existing batch total
                        batchGiftTotal = giftBatch.BatchTotal;
                    }

                    AdjustmentBatchNo = giftBatch.BatchNumber;

                    //assuming new elements are added after these static borders

                    AGiftDS.AGift.DefaultView.Sort = string.Format("{0}, {1}",
                                                                   AGiftTable.GetBatchNumberDBName(),
                                                                   AGiftTable.GetGiftTransactionNumberDBName());

                    AGiftDS.AGiftDetail.DefaultView.Sort = string.Format("{0}, {1}, {2}",
                                                                         AGiftDetailTable.GetBatchNumberDBName(),
                                                                         AGiftDetailTable.GetGiftTransactionNumberDBName(),
                                                                         AGiftDetailTable.GetDetailNumberDBName());

                    foreach (DataRowView giftRow in AGiftDS.AGift.DefaultView)
                    {
                        int cycle = 0;

                        // first cycle creates gift reversal; second cycle creates new adjusted gift (if needed)
                        do
                        {
                            AGiftRow oldGift = (AGiftRow)giftRow.Row;

                            if (oldGift.RowState != DataRowState.Added)
                            {
                                AGiftRow gift = AGiftDS.AGift.NewRowTyped(true);
                                DataUtilities.CopyAllColumnValuesWithoutPK(oldGift, gift);
                                gift.LedgerNumber          = giftBatch.LedgerNumber;
                                gift.BatchNumber           = giftBatch.BatchNumber;
                                gift.DateEntered           = DateEffective;
                                gift.GiftTransactionNumber = giftBatch.LastGiftNumber + 1;
                                giftBatch.LastGiftNumber++;
                                gift.LinkToPreviousGift = (cycle != 0);
                                gift.LastDetailNumber   = 0;

                                // do not print a receipt for reversed gifts
                                if (cycle == 0)
                                {
                                    gift.ReceiptPrinted = true;
                                    gift.PrintReceipt   = false;
                                }
                                else
                                {
                                    gift.ReceiptPrinted = false;
                                    gift.PrintReceipt   = !NoReceipt;
                                }

                                AGiftDS.AGift.Rows.Add(gift);

                                foreach (DataRowView giftDetailRow in AGiftDS.AGiftDetail.DefaultView)
                                {
                                    AGiftDetailRow oldGiftDetail = (AGiftDetailRow)giftDetailRow.Row;

                                    // if gift detail belongs to gift
                                    if ((oldGiftDetail.GiftTransactionNumber == oldGift.GiftTransactionNumber) &&
                                        (oldGiftDetail.BatchNumber == oldGift.BatchNumber) &&
                                        (!Function.Equals(GiftAdjustmentFunctionEnum.ReverseGiftDetail) ||
                                         (oldGiftDetail.DetailNumber == GiftDetailNumber)))
                                    {
                                        AddDuplicateGiftDetailToGift(ref AGiftDS, ref gift, oldGiftDetail, cycle == 0, Transaction,
                                                                     requestParams);

                                        batchGiftTotal += oldGiftDetail.GiftTransactionAmount * ((cycle == 0) ? -1 : 1);

                                        // original gift also gets marked as a reversal
                                        oldGiftDetail.ModifiedDetail = true;
                                    }
                                }
                            }

                            cycle++;
                        } while ((cycle < 2) &&
                                 (Function.Equals(GiftAdjustmentFunctionEnum.AdjustGift) ||
                                  Function.Equals(GiftAdjustmentFunctionEnum.FieldAdjust) ||
                                  Function.Equals(GiftAdjustmentFunctionEnum.TaxDeductiblePctAdjust)));
                    }

                    //When reversing into a new or existing batch, set batch total
                    if (!Function.Equals(GiftAdjustmentFunctionEnum.AdjustGift))
                    {
                        giftBatch.BatchTotal = batchGiftTotal;
                    }

                    // save everything at the end
                    AGiftBatchAccess.SubmitChanges(AGiftDS.AGiftBatch, Transaction);
                    ALedgerAccess.SubmitChanges(ledgerTable, Transaction);
                    AGiftAccess.SubmitChanges(AGiftDS.AGift, Transaction);
                    AGiftDetailAccess.SubmitChanges(AGiftDS.AGiftDetail, Transaction);

                    AGiftDS.AGiftBatch.AcceptChanges();

                    SubmissionOK = true;
                });
            }
            catch (Exception ex)
            {
                TLogging.LogException(ex, Utilities.GetMethodSignature());
                throw new EOPAppException(Catalog.GetString("Gift Reverse/Adjust failed."), ex);
            }

            AAdjustmentBatchNumber = AdjustmentBatchNo;

            return(SubmissionOK);
        }