Esempio n. 1
0
        /// create a new gift batch using some of the details of an existing gift batch
        private static AGiftBatchRow CreateNewGiftBatch(
            Int32 ALedgerNumber,
            Int32 ABatchNumber,
            DateTime ADateEffective,
            GiftAdjustmentFunctionEnum AFunction,
            ref GiftBatchTDS AMainDS,
            ref ALedgerTable ALedgerTable,
            TDBTransaction ATransaction)
        {
            AGiftBatchRow ReturnValue;

            AGiftBatchAccess.LoadByPrimaryKey(AMainDS, ALedgerNumber, ABatchNumber, ATransaction);

            AGiftBatchRow oldGiftBatch = AMainDS.AGiftBatch[0];

            TGiftBatchFunctions.CreateANewGiftBatchRow(ref AMainDS, ref ATransaction, ref ALedgerTable, ALedgerNumber, ADateEffective);
            ReturnValue = AMainDS.AGiftBatch[1];
            ReturnValue.BankAccountCode     = oldGiftBatch.BankAccountCode;
            ReturnValue.BankCostCentre      = oldGiftBatch.BankCostCentre;
            ReturnValue.CurrencyCode        = oldGiftBatch.CurrencyCode;
            ReturnValue.ExchangeRateToBase  = oldGiftBatch.ExchangeRateToBase;
            ReturnValue.MethodOfPaymentCode = oldGiftBatch.MethodOfPaymentCode;
            ReturnValue.HashTotal           = 0;

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

            ReturnValue.BankCostCentre = oldGiftBatch.BankCostCentre;
            ReturnValue.GiftType       = oldGiftBatch.GiftType;

            if (AFunction.Equals(GiftAdjustmentFunctionEnum.AdjustGift))
            {
                ReturnValue.BatchDescription = Catalog.GetString("Gift Adjustment");
            }
            else if (AFunction.Equals(GiftAdjustmentFunctionEnum.AdjustGiftBatch))
            {
                ReturnValue.BatchDescription = Catalog.GetString("Gift Batch Adjustment");
            }
            else if (AFunction.Equals(GiftAdjustmentFunctionEnum.FieldAdjust))
            {
                ReturnValue.BatchDescription = Catalog.GetString("Gift Adjustment (Field Change)");
            }
            else if (AFunction.Equals(GiftAdjustmentFunctionEnum.TaxDeductiblePctAdjust))
            {
                ReturnValue.BatchDescription = Catalog.GetString("Gift Adjustment (Tax Deductible Pct Change)");
            }
            else
            {
                ReturnValue.BatchDescription = Catalog.GetString("Reverse Gift");
            }

            return(ReturnValue);
        }
Esempio n. 2
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));
        }
Esempio n. 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 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));
        }
Esempio n. 4
0
        /// <summary>
        /// Adds a duplicate Gift Detail (or reversed duplicate GiftDetail) to Gift.
        /// </summary>
        /// <param name="AMainDS"></param>
        /// <param name="AGift"></param>
        /// <param name="AOldGiftDetail"></param>
        /// <param name="AReversal">True for reverse or false for straight duplicate</param>
        /// <param name="ATransaction"></param>
        /// <param name="AFunction"></param>
        /// <param name="ANewPct"></param>
        /// <param name="AAutoCompleteComments"></param>
        /// <param name="AReversalCommentOne"></param>
        /// <param name="AReversalCommentTwo"></param>
        /// <param name="AReversalCommentThree"></param>
        /// <param name="AReversalCommentOneType"></param>
        /// <param name="AReversalCommentTwoType"></param>
        /// <param name="AReversalCommentThreeType"></param>
        /// <param name="AUpdateTaxDeductiblePctRecipients"></param>
        /// <param name="AGeneralFixedGiftDestination"></param>
        /// <param name="AFixedGiftDestination"></param>
        private static void AddDuplicateGiftDetailToGift(ref GiftBatchTDS AMainDS,
                                                         ref AGiftRow AGift,
                                                         AGiftDetailRow AOldGiftDetail,
                                                         bool AReversal,
                                                         TDBTransaction ATransaction,
                                                         GiftAdjustmentFunctionEnum AFunction,
                                                         Decimal ANewPct,
                                                         bool AAutoCompleteComments       = false,
                                                         string AReversalCommentOne       = "",
                                                         string AReversalCommentTwo       = "",
                                                         string AReversalCommentThree     = "",
                                                         string AReversalCommentOneType   = "",
                                                         string AReversalCommentTwoType   = "",
                                                         string AReversalCommentThreeType = "",
                                                         List <string[]> AUpdateTaxDeductiblePctRecipients = null,
                                                         bool AGeneralFixedGiftDestination   = false,
                                                         List <string> AFixedGiftDestination = null
                                                         )
        {
            bool TaxDeductiblePercentageEnabled =
                new TSystemDefaults(ATransaction.DataBaseObj).GetBooleanDefault(SharedConstants.SYSDEFAULT_TAXDEDUCTIBLEPERCENTAGE, false);

            AGiftDetailRow giftDetail = AMainDS.AGiftDetail.NewRowTyped(true);

            DataUtilities.CopyAllColumnValuesWithoutPK(AOldGiftDetail, giftDetail);

            giftDetail.DetailNumber = AGift.LastDetailNumber + 1;
            AGift.LastDetailNumber++;

            giftDetail.LedgerNumber          = AGift.LedgerNumber;
            giftDetail.BatchNumber           = AGift.BatchNumber;
            giftDetail.GiftTransactionNumber = AGift.GiftTransactionNumber;
            giftDetail.IchNumber             = 0;

            decimal signum = (AReversal) ? -1 : 1;

            giftDetail.GiftTransactionAmount = signum * AOldGiftDetail.GiftTransactionAmount;
            giftDetail.GiftAmount            = signum * AOldGiftDetail.GiftAmount;
            giftDetail.GiftAmountIntl        = signum * AOldGiftDetail.GiftAmountIntl;

            if (TaxDeductiblePercentageEnabled)
            {
                if (!AReversal && AFunction.Equals(GiftAdjustmentFunctionEnum.TaxDeductiblePctAdjust))
                {
                    giftDetail.TaxDeductiblePct = ANewPct;
                    TaxDeductibility.UpdateTaxDeductibiltyAmounts(ref giftDetail);
                }
                else if (!AReversal)
                {
                    if (AUpdateTaxDeductiblePctRecipients != null)
                    {
                        string[] Result = AUpdateTaxDeductiblePctRecipients.Find(x => x[0] == giftDetail.RecipientKey.ToString());

                        // true if a new percentage is available and the user wants to use it
                        if (Result != null)
                        {
                            giftDetail.TaxDeductiblePct = Convert.ToDecimal(Result[1]);
                            TaxDeductibility.UpdateTaxDeductibiltyAmounts(ref giftDetail);
                        }
                    }
                }
                else
                {
                    giftDetail.TaxDeductibleAmount     = signum * AOldGiftDetail.TaxDeductibleAmount;
                    giftDetail.TaxDeductibleAmountBase = signum * AOldGiftDetail.TaxDeductibleAmountBase;
                    giftDetail.TaxDeductibleAmountIntl = signum * AOldGiftDetail.TaxDeductibleAmountIntl;
                    giftDetail.NonDeductibleAmount     = signum * AOldGiftDetail.NonDeductibleAmount;
                    giftDetail.NonDeductibleAmountBase = signum * AOldGiftDetail.NonDeductibleAmountBase;
                    giftDetail.NonDeductibleAmountIntl = signum * AOldGiftDetail.NonDeductibleAmountIntl;
                }
            }

            if (AAutoCompleteComments) // only used for tax deductible pct gift adjustments
            {
                AGiftRow OldGiftRow = (AGiftRow)AMainDS.AGift.Rows.Find(
                    new object[] { AOldGiftDetail.LedgerNumber, AOldGiftDetail.BatchNumber, AOldGiftDetail.GiftTransactionNumber });

                giftDetail.GiftCommentThree = Catalog.GetString("Original gift date: " + OldGiftRow.DateEntered.ToString("dd-MMM-yyyy"));
                giftDetail.CommentThreeType = "Both";
            }
            else // user defined
            {
                giftDetail.GiftCommentOne   = AReversalCommentOne;
                giftDetail.GiftCommentTwo   = AReversalCommentTwo;
                giftDetail.GiftCommentThree = AReversalCommentThree;
                giftDetail.CommentOneType   = AReversalCommentOneType;
                giftDetail.CommentTwoType   = AReversalCommentTwoType;
                giftDetail.CommentThreeType = AReversalCommentThreeType;
            }

            // If reversal: mark the new gift as a reversal
            if (AReversal)
            {
                giftDetail.ModifiedDetail = true;

                //Identify the reversal source
                giftDetail.ModifiedDetailKey = "|" + AOldGiftDetail.BatchNumber.ToString() + "|" +
                                               AOldGiftDetail.GiftTransactionNumber.ToString() + "|" +
                                               AOldGiftDetail.DetailNumber.ToString();
            }
            else
            {
                giftDetail.ModifiedDetail = false;

                // Make sure the motivation detail is still active. If not then we need a new one.
                AMotivationDetailTable MotivationDetailTable = AMotivationDetailAccess.LoadViaAMotivationGroup(
                    giftDetail.LedgerNumber, giftDetail.MotivationGroupCode, ATransaction);
                DataRow CurrentMotivationDetail = MotivationDetailTable.Rows.Find(
                    new object[] { giftDetail.LedgerNumber, giftDetail.MotivationGroupCode, giftDetail.MotivationDetailCode });

                // Motivation detail has been made inactive (or doesn't exist) then use default
                if (!((MotivationDetailTable != null) && (MotivationDetailTable.Rows.Count > 0) && (CurrentMotivationDetail != null)) ||
                    !Convert.ToBoolean(CurrentMotivationDetail[AMotivationDetailTable.GetMotivationStatusDBName()]))
                {
                    bool ActiveRowFound = false;

                    // search for first alternative active detail that is part of the same group
                    foreach (AMotivationDetailRow Row in MotivationDetailTable.Rows)
                    {
                        if ((Row.MotivationDetailCode != giftDetail.MotivationDetailCode) && Row.MotivationStatus)
                        {
                            ActiveRowFound = true;
                            giftDetail.MotivationGroupCode  = Row.MotivationGroupCode;
                            giftDetail.MotivationDetailCode = Row.MotivationDetailCode;
                            break;
                        }
                    }

                    // if none found then use default group and detail
                    if (!ActiveRowFound)
                    {
                        giftDetail.MotivationGroupCode  = MFinanceConstants.MOTIVATION_GROUP_GIFT;
                        giftDetail.MotivationDetailCode = MFinanceConstants.GROUP_DETAIL_SUPPORT;
                    }
                }

                // if the gift destination should be fixed
                if ((AFunction.Equals(GiftAdjustmentFunctionEnum.TaxDeductiblePctAdjust) && AGeneralFixedGiftDestination) ||
                    ((AFixedGiftDestination != null) && (AFixedGiftDestination.Exists(x => x == giftDetail.RecipientKey.ToString()))))
                {
                    giftDetail.FixedGiftDestination = true;
                }
                else
                {
                    giftDetail.FixedGiftDestination = false;
                }
            }

            AMainDS.AGiftDetail.Rows.Add(giftDetail);
        }
Esempio n. 5
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);
        }
        /// <summary>
        /// show the form for the gift reversal/adjustment
        /// </summary>
        /// <param name="AFunctionName">Which function shall be called on the server</param>
        public void ShowRevertAdjustForm(GiftAdjustmentFunctionEnum AFunctionName)
        {
            TFrmGiftBatch ParentGiftBatchForm = (TFrmGiftBatch)ParentForm;
            bool ReverseWholeBatch = (AFunctionName == GiftAdjustmentFunctionEnum.ReverseGiftBatch);
            bool AdjustGift = (AFunctionName == GiftAdjustmentFunctionEnum.AdjustGift);

            if (!ParentGiftBatchForm.SaveChangesManual())
            {
                return;
            }

            ParentGiftBatchForm.Cursor = Cursors.WaitCursor;

            AGiftBatchRow giftBatch = ((TFrmGiftBatch)ParentForm).GetBatchControl().GetSelectedDetailRow();
            int BatchNumber = giftBatch.BatchNumber;

            if (giftBatch == null)
            {
                MessageBox.Show(Catalog.GetString("Please select a Gift Batch to Reverse."));
                ParentGiftBatchForm.Cursor = Cursors.Default;
                return;
            }

            if (!giftBatch.BatchStatus.Equals(MFinanceConstants.BATCH_POSTED))
            {
                MessageBox.Show(Catalog.GetString("This function is only possible when the selected batch is already posted."));
                ParentGiftBatchForm.Cursor = Cursors.Default;
                return;
            }

            if (FPetraUtilsObject.HasChanges)
            {
                MessageBox.Show(Catalog.GetString("Please save first and than try again!"));
                ParentGiftBatchForm.Cursor = Cursors.Default;
                return;
            }

            if (ReverseWholeBatch && (FBatchNumber != BatchNumber))
            {
                ParentGiftBatchForm.SelectTab(TFrmGiftBatch.eGiftTabs.Transactions, true);
                ParentGiftBatchForm.SelectTab(TFrmGiftBatch.eGiftTabs.Batches);
                ParentGiftBatchForm.Cursor = Cursors.WaitCursor;
            }

            if (FPreviouslySelectedDetailRow == null)
            {
                MessageBox.Show(Catalog.GetString("Please select a Gift to Reverse."));
                ParentGiftBatchForm.Cursor = Cursors.Default;
                return;
            }

            TFrmGiftRevertAdjust revertForm = new TFrmGiftRevertAdjust(FPetraUtilsObject.GetForm());

            int workingLedgerNumber = FPreviouslySelectedDetailRow.LedgerNumber;
            int workingBatchNumber = FPreviouslySelectedDetailRow.BatchNumber;
            int workingTransactionNumber = FPreviouslySelectedDetailRow.GiftTransactionNumber;
            int workingDetailNumber = FPreviouslySelectedDetailRow.DetailNumber;

            if (FTaxDeductiblePercentageEnabled)
            {
                revertForm.CheckTaxDeductPctChange = true;
            }

            revertForm.CheckGiftDestinationChange = true;

            try
            {
                ParentForm.ShowInTaskbar = false;
                revertForm.LedgerNumber = FLedgerNumber;
                revertForm.CurrencyCode = ((AGiftBatchRow)FMainDS.AGiftBatch.Rows.Find(
                                               new object[] { workingLedgerNumber, workingBatchNumber })).CurrencyCode;

                // put spaces inbetween words
                revertForm.Text = Regex.Replace(AFunctionName.ToString(), "([a-z])([A-Z])", @"$1 $2");

                revertForm.AddParam("Function", AFunctionName);

                revertForm.GiftDetailRow = (AGiftDetailRow)FMainDS.AGiftDetail.Rows.Find(
                    new object[] { workingLedgerNumber, workingBatchNumber, workingTransactionNumber, workingDetailNumber });

                if (!revertForm.IsDisposed && (revertForm.ShowDialog() == DialogResult.OK))
                {
                    ParentGiftBatchForm.Cursor = Cursors.WaitCursor;

                    if ((revertForm.AdjustmentBatchNumber > 0) && (revertForm.AdjustmentBatchNumber != workingBatchNumber))
                    {
                        // select the relevant batch
                        ParentGiftBatchForm.InitialBatchNumber = revertForm.AdjustmentBatchNumber;
                    }

                    ParentGiftBatchForm.RefreshAll();
                }
            }
            finally
            {
                ParentGiftBatchForm.Cursor = Cursors.WaitCursor;
                revertForm.Dispose();
                ParentForm.ShowInTaskbar = true;
                ParentGiftBatchForm.Cursor = Cursors.Default;
            }

            if (AdjustGift && (ParentGiftBatchForm.ActiveTab() == TFrmGiftBatch.eGiftTabs.Transactions))
            {
                //Select first row for adjusting, i.e. first +ve amount
                foreach (DataRowView drv in FMainDS.AGiftDetail.DefaultView)
                {
                    AGiftDetailRow gdr = (AGiftDetailRow)drv.Row;

                    if (gdr.GiftTransactionAmount > 0)
                    {
                        grdDetails.SelectRowInGrid(grdDetails.Rows.DataSourceRowToIndex(drv) + 1);
                    }
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// show the form for the gift reversal/adjustment
        /// </summary>
        /// <param name="AFunctionName">Which function shall be called on the server</param>
        private void ShowRevertAdjustForm(GiftAdjustmentFunctionEnum AFunctionName)
        {
            TFrmGiftBatch ParentGiftBatchForm = (TFrmGiftBatch)ParentForm;
            bool          ReverseWholeBatch   = (AFunctionName == GiftAdjustmentFunctionEnum.ReverseGiftBatch);
            bool          AdjustGift          = (AFunctionName == GiftAdjustmentFunctionEnum.AdjustGift);

            if (!ParentGiftBatchForm.SaveChangesManual())
            {
                return;
            }

            ParentGiftBatchForm.Cursor = Cursors.WaitCursor;

            AGiftBatchRow giftBatch   = ((TFrmGiftBatch)ParentForm).GetBatchControl().GetSelectedDetailRow();
            int           BatchNumber = giftBatch.BatchNumber;

            if (giftBatch == null)
            {
                MessageBox.Show(Catalog.GetString("Please select a Gift Batch to Reverse."));
                ParentGiftBatchForm.Cursor = Cursors.Default;
                return;
            }

            if (!giftBatch.BatchStatus.Equals(MFinanceConstants.BATCH_POSTED))
            {
                MessageBox.Show(Catalog.GetString("This function is only possible when the selected batch is already posted."));
                ParentGiftBatchForm.Cursor = Cursors.Default;
                return;
            }

            if (FPetraUtilsObject.HasChanges)
            {
                MessageBox.Show(Catalog.GetString("Please save first and than try again!"));
                ParentGiftBatchForm.Cursor = Cursors.Default;
                return;
            }

            if (ReverseWholeBatch && (FBatchNumber != BatchNumber))
            {
                ParentGiftBatchForm.SelectTab(TFrmGiftBatch.eGiftTabs.Transactions, true);
                ParentGiftBatchForm.SelectTab(TFrmGiftBatch.eGiftTabs.Batches);
                ParentGiftBatchForm.Cursor = Cursors.WaitCursor;
            }

            if (!ReverseWholeBatch && (FPreviouslySelectedDetailRow == null))
            {
                MessageBox.Show(Catalog.GetString("Please select a Gift to Adjust/Reverse."));
                ParentGiftBatchForm.Cursor = Cursors.Default;
                return;
            }

            TFrmGiftRevertAdjust revertForm = new TFrmGiftRevertAdjust(FPetraUtilsObject.GetForm());

            if (AdjustGift)
            {
                if (FSETUseTaxDeductiblePercentageFlag)
                {
                    revertForm.CheckTaxDeductPctChange = true;
                }

                revertForm.CheckGiftDestinationChange = true;
            }

            try
            {
                ParentForm.ShowInTaskbar = false;
                revertForm.LedgerNumber  = FLedgerNumber;
                revertForm.CurrencyCode  = giftBatch.CurrencyCode;

                // put spaces inbetween words
                revertForm.Text = Regex.Replace(AFunctionName.ToString(), "([a-z])([A-Z])", @"$1 $2");

                revertForm.AddParam("Function", AFunctionName);
                revertForm.AddParam("BatchNumber", giftBatch.BatchNumber);

                if (AdjustGift)
                {
                    int workingTransactionNumber = FPreviouslySelectedDetailRow.GiftTransactionNumber;
                    int workingDetailNumber      = FPreviouslySelectedDetailRow.DetailNumber;
                    revertForm.GiftDetailRow = (AGiftDetailRow)FMainDS.AGiftDetail.Rows.Find(
                        new object[] { giftBatch.LedgerNumber, giftBatch.BatchNumber, workingTransactionNumber, workingDetailNumber });
                }

                if (ReverseWholeBatch)
                {
                    revertForm.GetGiftsForReverseAdjust(); // Added Feb '17 Tim Ingham - previously, reversing a whole batch didn't work.
                }

                if (!revertForm.IsDisposed && (revertForm.ShowDialog() == DialogResult.OK))
                {
                    ParentGiftBatchForm.Cursor = Cursors.WaitCursor;

                    if ((revertForm.AdjustmentBatchNumber > 0) && (revertForm.AdjustmentBatchNumber != giftBatch.BatchNumber))
                    {
                        // select the relevant batch
                        ParentGiftBatchForm.InitialBatchNumber = revertForm.AdjustmentBatchNumber;
                    }

                    ParentGiftBatchForm.RefreshAll();
                }
            }
            finally
            {
                ParentGiftBatchForm.Cursor = Cursors.WaitCursor;
                revertForm.Dispose();
                ParentForm.ShowInTaskbar   = true;
                ParentGiftBatchForm.Cursor = Cursors.Default;
            }

            if (AdjustGift && (ParentGiftBatchForm.ActiveTab() == TFrmGiftBatch.eGiftTabs.Transactions))
            {
                //Select first row for adjusting, i.e. first +ve amount
                foreach (DataRowView drv in FMainDS.AGiftDetail.DefaultView)
                {
                    AGiftDetailRow gdr = (AGiftDetailRow)drv.Row;

                    if (gdr.GiftTransactionAmount > 0)
                    {
                        grdDetails.SelectRowInGrid(grdDetails.Rows.DataSourceRowToIndex(drv) + 1);
                    }
                }
            }
        }
Esempio n. 8
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);
        }