// carry out the adjustment
        /// <summary>
        /// Carry out a Tax Deductible Pct adjustment.
        /// </summary>
        /// <param name="ARecipientKey"></param>
        /// <param name="ANewPct"></param>
        /// <param name="AValidFrom"></param>
        /// <param name="ANoReceipt"></param>
        /// <param name="AParentForm"></param>
        public static void TaxDeductiblePctAdjustment(Int64 ARecipientKey, decimal ANewPct, DateTime AValidFrom, bool ANoReceipt, Form AParentForm)
        {
            GiftBatchTDS GiftBatchDS = new GiftBatchTDS();

            // get all the data needed for this Field Adjustment
            if (!GetAllDataNeeded(ref GiftBatchDS, ARecipientKey, ANewPct, AValidFrom, AParentForm))
            {
                return;
            }

            // show the list of gifts to be adjusted and ask the user for confirmation
            TFrmGiftFieldAdjustmentConfirmation ConfirmationForm = new TFrmGiftFieldAdjustmentConfirmation(AParentForm);
            ConfirmationForm.MainDS = GiftBatchDS;
            ConfirmationForm.Text = Catalog.GetString("Confirm Tax Deductible Percentage Adjustment");

            if (ConfirmationForm.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
            {
                return;
            }

            // Carry out the gift adjustment
            TFrmGiftFieldAdjustment.GiftAdjustment(GiftBatchDS, ANewPct, ANoReceipt, AParentForm);

            // refresh gift batch screen
            TFormsMessage broadcastMessage = new TFormsMessage(TFormsMessageClassEnum.mcRefreshGiftBatches, AParentForm.ToString());
            TFormsList.GFormsList.BroadcastFormMessage(broadcastMessage);
        }
Exemplo n.º 2
0
        public static GiftBatchTDS LoadMotivationDetails(Int32 ALedgerNumber)
        {
            GiftBatchTDS MainDS = new GiftBatchTDS();

            TDBTransaction Transaction = null;

            DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                                                                      TEnforceIsolationLevel.eilMinimum,
                                                                      ref Transaction,
                                                                      delegate
            {
                ALedgerAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, Transaction);
                AMotivationGroupAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction);
                AMotivationDetailAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction);
                AMotivationDetailFeeAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction);
            });

            // Accept row changes here so that the Client gets 'unmodified' rows
            MainDS.AcceptChanges();

            // Remove all Tables that were not filled with data before remoting them.
            MainDS.RemoveEmptyTables();

            return(MainDS);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="APetraUtilsObject">Reference to the PetraUtilsObject for the form</param>
        /// <param name="ALedgerNumber">Ledger number</param>
        /// <param name="AMainDS">The main data set</param>
        /// <param name="AFilterFindPanelObject">The filter panel control object</param>
        public TUC_GiftBatches_LoadAndFilter(TFrmPetraEditUtils APetraUtilsObject,
                                             int ALedgerNumber,
                                             GiftBatchTDS AMainDS,
                                             TFilterAndFindPanel AFilterFindPanelObject)
        {
            FPetraUtilsObject      = APetraUtilsObject;
            FLedgerNumber          = ALedgerNumber;
            FMainDS                = AMainDS;
            FFilterFindPanelObject = AFilterFindPanelObject;

            FrbtEditing    = (RadioButton)AFilterFindPanelObject.FilterPanelControls.FindControlByName("rbtEditing");
            FrbtPosting    = (RadioButton)AFilterFindPanelObject.FilterPanelControls.FindControlByName("rbtPosting");
            FrbtAll        = (RadioButton)AFilterFindPanelObject.FilterPanelControls.FindControlByName("rbtAll");
            FcmbYearEnding = (TCmbAutoComplete)AFilterFindPanelObject.FilterPanelControls.FindControlByName("cmbYearEnding");
            FcmbPeriod     = (TCmbAutoComplete)AFilterFindPanelObject.FilterPanelControls.FindControlByName("cmbPeriod");

            FMainDS.AGiftBatch.DefaultView.Sort = String.Format("{0}, {1} DESC",
                                                                AGiftBatchTable.GetLedgerNumberDBName(),
                                                                AGiftBatchTable.GetBatchNumberDBName()
                                                                );

            // Populate the Year ComboBox with available years for the specified ledger
            TFinanceControls.InitialiseAvailableGiftYearsList(ref FcmbYearEnding, FLedgerNumber);
            //TLogging.Log("Gift Years completed");

            // Ensure that we start with the status set to 'editing'.
            FrbtEditing.Checked = true;
            //TLogging.Log("Editing checkbox selected");
        }
Exemplo n.º 4
0
        /// <summary>
        /// create a new batch with a consecutive batch number in the ledger
        /// for call inside a server function
        /// for performance reasons submitting (save the data in the database) is done later (not here)
        /// </summary>
        /// <param name="MainDS"></param>
        /// <param name="Transaction"></param>
        /// <param name="LedgerTable"></param>
        /// <param name="ALedgerNumber"></param>
        /// <param name="ADateEffective"></param>
        /// <param name="AForceEffectiveDateToFit"></param>
        /// <returns>the new gift batch row</returns>
        public static AGiftBatchRow CreateANewGiftBatchRow(ref GiftBatchTDS MainDS,
                                                           ref TDBTransaction Transaction,
                                                           ref ALedgerTable LedgerTable,
                                                           Int32 ALedgerNumber,
                                                           DateTime ADateEffective,
                                                           bool AForceEffectiveDateToFit = true)
        {
            AGiftBatchRow NewRow = MainDS.AGiftBatch.NewRowTyped(true);

            NewRow.LedgerNumber = ALedgerNumber;
            LedgerTable[0].LastGiftBatchNumber++;
            NewRow.BatchNumber = LedgerTable[0].LastGiftBatchNumber;
            Int32 BatchYear, BatchPeriod;

            // if DateEffective is outside the range of open periods, use the most fitting date
            TFinancialYear.GetLedgerDatePostingPeriod(ALedgerNumber,
                                                      ref ADateEffective,
                                                      out BatchYear,
                                                      out BatchPeriod,
                                                      Transaction,
                                                      AForceEffectiveDateToFit);
            NewRow.BatchYear          = BatchYear;
            NewRow.BatchPeriod        = BatchPeriod;
            NewRow.GlEffectiveDate    = ADateEffective;
            NewRow.ExchangeRateToBase = 1.0M;
            NewRow.BatchDescription   = "PLEASE ENTER A DESCRIPTION";
            NewRow.BankAccountCode    = TLedgerInfo.GetDefaultBankAccount(ALedgerNumber);
            NewRow.BankCostCentre     = TLedgerInfo.GetStandardCostCentre(ALedgerNumber);
            NewRow.CurrencyCode       = LedgerTable[0].BaseCurrency;
            MainDS.AGiftBatch.Rows.Add(NewRow);
            return(NewRow);
        }
Exemplo n.º 5
0
        public static GiftBatchTDS LoadMotivationDetails(Int32 ALedgerNumber, string AMotivationGroupCode)
        {
            GiftBatchTDS MainDS = new GiftBatchTDS();

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

            db.ReadTransaction(
                ref Transaction,
                delegate
            {
                ALedgerAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, Transaction);

                if (AMotivationGroupCode.Length > 0)
                {
                    AMotivationGroupAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, AMotivationGroupCode, Transaction);
                    AMotivationDetailAccess.LoadViaAMotivationGroup(MainDS, ALedgerNumber, AMotivationGroupCode, Transaction);
                }
                else
                {
                    AMotivationGroupAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction);
                    AMotivationDetailAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction);
                }

                AMotivationDetailFeeAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction);
            });

            // Accept row changes here so that the Client gets 'unmodified' rows
            MainDS.AcceptChanges();

            // Remove all Tables that were not filled with data before remoting them.
            MainDS.RemoveEmptyTables();

            return(MainDS);
        }
Exemplo n.º 6
0
        /// try to find a new gift batch that does already have the same properties
        private static GiftBatchTDS CreateNewGiftBatch(SortedList <string, GiftBatchTDS> ANewGiftBatches,
                                                       AGiftBatchRow AOldGiftBatch,
                                                       DateTime ADateCorrection)
        {
            string key = AOldGiftBatch.CurrencyCode + ";" +
                         AOldGiftBatch.BankAccountCode + ";" +
                         AOldGiftBatch.BankCostCentre + ";" +
                         AOldGiftBatch.GiftType;

            if (!ANewGiftBatches.ContainsKey(key))
            {
                GiftBatchTDS GiftDS = TGiftTransactionWebConnector.CreateAGiftBatch(AOldGiftBatch.LedgerNumber, ADateCorrection,
                                                                                    Catalog.GetString("Gift Adjustment (Field Change)"));
                AGiftBatchRow giftbatchRow = GiftDS.AGiftBatch[0];
                giftbatchRow.BankCostCentre  = AOldGiftBatch.BankCostCentre;
                giftbatchRow.BankAccountCode = AOldGiftBatch.BankAccountCode;
                giftbatchRow.GiftType        = AOldGiftBatch.GiftType;
                ANewGiftBatches.Add(key, GiftDS);

                return(GiftDS);
            }
            else
            {
                return(ANewGiftBatches[key]);
            }
        }
        // carry out the field adjustment
        private void FieldChangeAdjustment(System.Object sender, EventArgs e)
        {
            if (!ValidateControls())
            {
                return;
            }

            GiftBatchTDS GiftBatchDS = new GiftBatchTDS();

            // get all the data needed for this Field Adjustment
            if (!GetAllDataNeeded(ref GiftBatchDS))
            {
                return;
            }

            // show the list of gifts to be adjusted and ask the user for confirmation
            TFrmGiftFieldAdjustmentConfirmation ConfirmationForm = new TFrmGiftFieldAdjustmentConfirmation(this);

            ConfirmationForm.MainDS = GiftBatchDS;

            if (ConfirmationForm.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
            {
                return;
            }

            // Carry out the gift adjustment
            GiftAdjustment(GiftBatchDS, null, chkNoReceipt.Checked, this);

            // refresh batches
            this.Cursor = Cursors.WaitCursor;
            ((TFrmGiftBatch)FPetraUtilsObject.GetCallerForm()).RefreshAll();
            this.Cursor = Cursors.Default;
            this.Close();
        }
        public void TestProcessAdminFees()
        {
            ImportAdminFees();

            GiftBatchTDS MainDS = new GiftBatchTDS();

            TDBTransaction Transaction = null;

            DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted, ref Transaction,
                                                                      delegate
            {
                AFeesPayableAccess.LoadViaALedger(MainDS, FLedgerNumber, Transaction);
                AFeesReceivableAccess.LoadViaALedger(MainDS, FLedgerNumber, Transaction);
            });

            TVerificationResultCollection VerificationResults = null;

            //TODO If this first one works, try different permatations for Assert.AreEqual
            // Test also for exception handling
            Assert.AreEqual(2m, TGiftTransactionWebConnector.CalculateAdminFee(MainDS,
                                                                               FLedgerNumber,
                                                                               "GIF",
                                                                               200m,
                                                                               out VerificationResults), "expect 1% of 200");
        }
        private TSubmitChangesResult StoreManualCode(ref GiftBatchTDS ASubmitChanges, out TVerificationResultCollection AVerificationResult)
        {
            TSubmitChangesResult Result;

            AVerificationResult = null;

            if (ASubmitChanges.AMotivationDetailFee != null)
            {
                // delete any invalid motivation detail fees (i.e. because the motivation detail's name has changed)
                foreach (DataRowView rv in ASubmitChanges.AMotivationDetailFee.DefaultView)
                {
                    AMotivationDetailFeeRow Row = (AMotivationDetailFeeRow)rv.Row;

                    if ((Row.RowState == DataRowState.Added) &&
                        !FMainDS.AMotivationDetail.Rows.Contains(new object[] { Row.LedgerNumber, Row.MotivationGroupCode,
                                                                                Row.MotivationDetailCode }))
                    {
                        Row.Delete();
                    }
                }
            }

            Result = TRemote.MFinance.Gift.WebConnectors.SaveMotivationDetails(ref ASubmitChanges);

            if (Result == TSubmitChangesResult.scrOK)
            {
                // needed to reorder the two checked listboxes
                SelectRowInGrid(FPrevRowChangedRow);

                // refresh cachaeble table
                TDataCache.TMFinance.RefreshCacheableFinanceTable(TCacheableFinanceTablesEnum.MotivationList, FLedgerNumber);
            }

            return(Result);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Checks the entire gift batch for inactive values and informs the user
        /// </summary>
        /// <param name="AAction"></param>
        /// <param name="AMainDS"></param>
        /// <param name="APetraUtilsObject"></param>
        /// <param name="AIsRecurringGift"></param>
        /// <returns></returns>
        public static bool CheckForConsistentFieldValues(GiftBatchAction AAction,
                                                         GiftBatchTDS AMainDS,
                                                         TFrmPetraEditUtils APetraUtilsObject,
                                                         Boolean AIsRecurringGift = false)
        {
            bool RetVal = false;

            //TODO: check for field value consistency before saving

            //TODO: Check Batch, Gift and Detail key field consistency
            //  e.g. consecutive numbers, last number values etc
            if (!AIsRecurringGift)
            {
            }
            else
            {
            }

            //TODO: Check Method of Payment between Batch and Gift level
            if (!AIsRecurringGift)
            {
            }
            else
            {
            }

            //TODO: Check for Tax value correctness at Gift Detail level
            if (!AIsRecurringGift)
            {
            }

            //Nothing to do for recurring

            return(RetVal);
        }
Exemplo n.º 11
0
        public static GiftBatchTDS LoadMotivationDetails(Int32 ALedgerNumber)
        {
            GiftBatchTDS MainDS = new GiftBatchTDS();

            TDBTransaction Transaction = null;

            DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                TEnforceIsolationLevel.eilMinimum,
                ref Transaction,
                delegate
                {
                    ALedgerAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, Transaction);
                    AMotivationGroupAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction);
                    AMotivationDetailAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction);
                    AMotivationDetailFeeAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction);
                });

            // Accept row changes here so that the Client gets 'unmodified' rows
            MainDS.AcceptChanges();

            // Remove all Tables that were not filled with data before remoting them.
            MainDS.RemoveEmptyTables();

            return MainDS;
        }
Exemplo n.º 12
0
        private void PostBatch(System.Object sender, EventArgs e)
        {
            if (GetSelectedRowIndex() < 0)
            {
                return; // Oops - there's no selected row.
            }

            if (FPostingLogicObject.PostBatch(FPreviouslySelectedDetailRow))
            {
                // Posting succeeded so now deal with gift receipting ...
                GiftBatchTDS PostedGiftTDS = TRemote.MFinance.Gift.WebConnectors.LoadAGiftBatchAndRelatedData(FLedgerNumber,
                                                                                                              FSelectedBatchNumber,
                                                                                                              false);

                FReceiptingLogicObject.PrintGiftBatchReceipts(PostedGiftTDS);

                // Now we need to get the data back from the server to pick up all the changes
                RefreshAllData();

                if (FPetraUtilsObject.HasChanges)
                {
                    ((TFrmGiftBatch)ParentForm).SaveChangesManual();
                }
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// create a new batch with a consecutive batch number in the ledger
        /// for call inside a server function
        /// for performance reasons submitting (save the data in the database) is done later (not here)
        /// </summary>
        /// <param name="MainDS"></param>
        /// <param name="Transaction"></param>
        /// <param name="LedgerTable"></param>
        /// <param name="ALedgerNumber"></param>
        /// <param name="ADateEffective"></param>
        /// <param name="AForceEffectiveDateToFit"></param>
        /// <returns>the new gift batch row</returns>
        public static AGiftBatchRow CreateANewGiftBatchRow(ref GiftBatchTDS MainDS,
            ref TDBTransaction Transaction,
            ref ALedgerTable LedgerTable,
            Int32 ALedgerNumber,
            DateTime ADateEffective,
            bool AForceEffectiveDateToFit = true)
        {
            AGiftBatchRow NewRow = MainDS.AGiftBatch.NewRowTyped(true);

            NewRow.LedgerNumber = ALedgerNumber;
            LedgerTable[0].LastGiftBatchNumber++;
            NewRow.BatchNumber = LedgerTable[0].LastGiftBatchNumber;
            Int32 BatchYear, BatchPeriod;
            // if DateEffective is outside the range of open periods, use the most fitting date
            TFinancialYear.GetLedgerDatePostingPeriod(ALedgerNumber,
                ref ADateEffective,
                out BatchYear,
                out BatchPeriod,
                Transaction,
                AForceEffectiveDateToFit);
            NewRow.BatchYear = BatchYear;
            NewRow.BatchPeriod = BatchPeriod;
            NewRow.GlEffectiveDate = ADateEffective;
            NewRow.ExchangeRateToBase = 1.0M;
            NewRow.BatchDescription = "PLEASE ENTER A DESCRIPTION";
            NewRow.BankAccountCode = TLedgerInfo.GetDefaultBankAccount(ALedgerNumber);
            NewRow.BankCostCentre = TLedgerInfo.GetStandardCostCentre(ALedgerNumber);
            NewRow.CurrencyCode = LedgerTable[0].BaseCurrency;
            MainDS.AGiftBatch.Rows.Add(NewRow);
            return NewRow;
        }
        // This manual method lets us peek at the data that is about to be saved...
        // The data has already been collected from the contols and validated and there is definitely something to save...
        private TSubmitChangesResult StoreManualCode(ref GiftBatchTDS SubmitDS, out TVerificationResultCollection VerificationResult)
        {
            //Used in Gift Batch, which has more code. Included here for easier cross-refeence

            // Now do the standard call to save the changes
            return(TRemote.MFinance.Gift.WebConnectors.SaveGiftBatchTDS(ref SubmitDS, out VerificationResult));
        }
        private Int64 GetLedgerPartnerKey(Int32 ALedgerNumber)
        {
            Int64 retVal         = 0;
            bool  NewTransaction = false;

            TDBTransaction Transaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.Serializable, out NewTransaction);

            try
            {
                GiftBatchTDS MainDS = new GiftBatchTDS();

                ALedgerAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, Transaction);

                if (MainDS.ALedger.Count > 0)
                {
                    retVal = MainDS.ALedger[0].PartnerKey;
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (NewTransaction)
                {
                    DBAccess.GDBAccessObj.RollbackTransaction();
                }
            }

            return(retVal);
        }
        // carry out the adjustment
        /// <summary>
        /// Carry out a Tax Deductible Pct adjustment.
        /// </summary>
        /// <param name="ARecipientKey"></param>
        /// <param name="ANewPct"></param>
        /// <param name="AValidFrom"></param>
        /// <param name="ANoReceipt"></param>
        /// <param name="AParentForm"></param>
        public static void TaxDeductiblePctAdjustment(Int64 ARecipientKey, decimal ANewPct, DateTime AValidFrom, bool ANoReceipt, Form AParentForm)
        {
            GiftBatchTDS GiftBatchDS = new GiftBatchTDS();

            // get all the data needed for this Field Adjustment
            if (!GetAllDataNeeded(ref GiftBatchDS, ARecipientKey, ANewPct, AValidFrom, AParentForm))
            {
                return;
            }

            // show the list of gifts to be adjusted and ask the user for confirmation
            TFrmGiftFieldAdjustmentConfirmation ConfirmationForm = new TFrmGiftFieldAdjustmentConfirmation(AParentForm);

            ConfirmationForm.MainDS = GiftBatchDS;
            ConfirmationForm.Text   = Catalog.GetString("Confirm Tax Deductible Percentage Adjustment");

            if (ConfirmationForm.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
            {
                return;
            }

            // Carry out the gift adjustment
            TFrmGiftFieldAdjustment.GiftAdjustment(GiftBatchDS, ANewPct, ANoReceipt, AParentForm);

            // refresh gift batch screen
            TFormsMessage broadcastMessage = new TFormsMessage(TFormsMessageClassEnum.mcRefreshGiftBatches, AParentForm.ToString());

            TFormsList.GFormsList.BroadcastFormMessage(broadcastMessage);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Looks for gifts where the donor is anoymous but the gift is not marked as confidential and asks the user if they want to continue.
        /// (Make sure GetDataFromControls is called before this method so that AMainDS is up-to-date.)
        /// </summary>
        /// <param name="AMainDS"></param>
        public static bool CanContinueWithAnyAnonymousDonors(GiftBatchTDS AMainDS)
        {
            GiftBatchTDSAGiftDetailTable UnConfidentialGiftsWithAnonymousDonors = new GiftBatchTDSAGiftDetailTable();

            foreach (GiftBatchTDSAGiftDetailRow Row in AMainDS.AGiftDetail.Rows)
            {
                if (!Row.ConfidentialGiftFlag)
                {
                    PPartnerRow PartnerRow = (PPartnerRow)AMainDS.DonorPartners.Rows.Find(Row.DonorKey);

                    if ((PartnerRow != null) && PartnerRow.AnonymousDonor)
                    {
                        UnConfidentialGiftsWithAnonymousDonors.Rows.Add((object[])Row.ItemArray.Clone());
                    }
                }
            }

            if (UnConfidentialGiftsWithAnonymousDonors.Rows.Count > 0)
            {
                string Message = string.Empty;

                DataView dv = UnConfidentialGiftsWithAnonymousDonors.DefaultView;
                dv.Sort = GiftBatchTDSAGiftDetailTable.GetGiftTransactionNumberDBName() + " ASC";
                DataTable sortedDT = dv.ToTable();

                if (UnConfidentialGiftsWithAnonymousDonors.Rows.Count == 1)
                {
                    Message = Catalog.GetString(
                        "The gift listed below in this batch is not marked as confidential but the donor has asked to remain anonymous.");
                }
                else
                {
                    Message = Catalog.GetString(
                        "The gifts listed below in this batch are not marked as confidential but the donors have asked to remain anonymous.");
                }

                Message += "\n\n";

                foreach (DataRow UnConfidentialGifts in sortedDT.Rows)
                {
                    Message += Catalog.GetString("Batch: ") + UnConfidentialGifts[GiftBatchTDSAGiftDetailTable.GetBatchNumberDBName()] + "; " +
                               Catalog.GetString("Gift: ") + UnConfidentialGifts[GiftBatchTDSAGiftDetailTable.GetGiftTransactionNumberDBName()] +
                               "; " +
                               Catalog.GetString("Donor: ") + UnConfidentialGifts[GiftBatchTDSAGiftDetailTable.GetDonorNameDBName()] + " (" +
                               UnConfidentialGifts[GiftBatchTDSAGiftDetailTable.GetDonorKeyDBName()] + ")\n";
                }

                Message += "\n" + Catalog.GetString("Do you want to continue with posting anyway?");

                if (MessageBox.Show(
                        Message, Catalog.GetString("Anonymous Donor Warning"), MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
                    == DialogResult.No)
                {
                    return(false);
                }
            }

            return(true);
        }
        /// <summary>
        /// Constructor
        /// </summary>
        public TUC_GiftBatches_Cancel(TFrmPetraEditUtils APetraUtilsObject, Int32 ALedgerNumber, GiftBatchTDS AMainDS)
        {
            FPetraUtilsObject = APetraUtilsObject;
            FLedgerNumber = ALedgerNumber;
            FMainDS = AMainDS;

            FMyForm = (TFrmGiftBatch)FPetraUtilsObject.GetForm();
        }
Exemplo n.º 19
0
        /// <summary>
        /// generate the gift batches from a text file that was generated with Benerator, for a specific period
        /// </summary>
        public static void CreateGiftBatches(int APeriodNumber)
        {
            GiftBatchTDS MainDS = CreateGiftBatches(GiftsPerDate, APeriodNumber);

            MainDS.ThrowAwayAfterSubmitChanges = true;

            GiftBatchTDSAccess.SubmitChanges(MainDS);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Constructor
        /// </summary>
        public TUC_GiftBatches_Cancel(TFrmPetraEditUtils APetraUtilsObject, Int32 ALedgerNumber, GiftBatchTDS AMainDS)
        {
            FPetraUtilsObject = APetraUtilsObject;
            FLedgerNumber     = ALedgerNumber;
            FMainDS           = AMainDS;

            FMyForm = (TFrmGiftBatch)FPetraUtilsObject.GetForm();
        }
Exemplo n.º 21
0
        /// <summary>
        /// Constructor
        /// </summary>
        public TUC_RecurringGiftBatches_Submit(TFrmPetraEditUtils APetraUtilsObject, Int32 ALedgerNumber, GiftBatchTDS AMainDS)
        {
            FPetraUtilsObject = APetraUtilsObject;
            FLedgerNumber     = ALedgerNumber;
            FMainDS           = AMainDS;

            FMyForm = (TFrmRecurringGiftBatch)FPetraUtilsObject.GetForm();
        }
Exemplo n.º 22
0
        private void PostBatch(System.Object sender, EventArgs e)
        {
            bool Success = false;

            if (GetSelectedRowIndex() < 0)
            {
                return; // Oops - there's no selected row.
            }

            try
            {
                Cursor = Cursors.WaitCursor;

                Success = FPostingLogicObject.PostBatch(FPreviouslySelectedDetailRow);

                if (Success)
                {
                    // Posting succeeded so now deal with gift receipting ...
                    GiftBatchTDS PostedGiftTDS = TRemote.MFinance.Gift.WebConnectors.LoadAGiftBatchAndRelatedData(FLedgerNumber,
                                                                                                                  FSelectedBatchNumber,
                                                                                                                  false);

                    FReceiptingLogicObject.PrintGiftBatchReceipts(PostedGiftTDS);

                    // Now we need to get the data back from the server to pick up all the changes
                    RefreshAllData();

                    if (FPetraUtilsObject.HasChanges)
                    {
                        ((TFrmGiftBatch)ParentForm).SaveChangesManual();
                    }
                }
            }
            catch (Exception ex)
            {
                string errMsg;

                if (!Success)
                {
                    errMsg = Catalog.GetString("Error trying to post batch");
                }
                else
                {
                    errMsg = Catalog.GetString("Error trying to print gift receipts for batch");
                }

                errMsg += String.Format(" {0}:{1}{1}{2}",
                                        FPreviouslySelectedDetailRow.BatchNumber,
                                        Environment.NewLine,
                                        ex.Message);

                MessageBox.Show(errMsg, Catalog.GetString("Post Gift Batch"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }
        private bool GetAllDataNeeded(ref GiftBatchTDS AGiftBatchDS)
        {
            // if dtpEndDate is blank use the max date value
            DateTime EndTime = DateTime.MaxValue;

            if (dtpEndDate.Date.HasValue)
            {
                EndTime = dtpEndDate.Date.Value;
            }

            Boolean ok;
            TVerificationResultCollection Messages;

            try
            {
                this.Cursor = Cursors.WaitCursor;

                ok = TRemote.MFinance.Gift.WebConnectors.GetGiftsForFieldChangeAdjustment(
                    ref AGiftBatchDS,
                    FLedgerNumber,
                    Convert.ToInt64(txtRecipientKey.Text),
                    dtpStartDate.Date.Value,
                    EndTime,
                    Convert.ToInt64(txtOldFieldKey.Text),
                    out Messages);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }

            // If one or more of the gifts have already been reversed.
            if (!ok)
            {
                if (Messages.Count > 0)
                {
                    foreach (TVerificationResult message in Messages)
                    {
                        if (message.ResultText.Length > 0)
                        {
                            MessageBox.Show(this.Text + Catalog.GetString(" cancelled. ") + message.ResultText,
                                            Catalog.GetString("Gift Field Adjust"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }

                return(false);
            }

            // if there are no gifts to be adjusted
            if ((AGiftBatchDS.AGiftDetail == null) || (AGiftBatchDS.AGiftDetail.Rows.Count == 0))
            {
                MessageBox.Show(Catalog.GetString("There are no gifts to adjust."));
                return(false);
            }

            return(true);
        }
Exemplo n.º 24
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));
        }
Exemplo n.º 25
0
        private void RevertDataSet(GiftBatchTDS AMainDS, GiftBatchTDS ABackupDS)
        {
            AMainDS.ALedger.Clear();
            AMainDS.AGiftDetail.Clear();
            AMainDS.AGift.Clear();
            AMainDS.AGiftBatch.Clear();

            AMainDS.Merge(ABackupDS);
        }
Exemplo n.º 26
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);
        }
Exemplo n.º 27
0
        public void SpeedTestLoadIntoTypedTable()
        {
            TDBTransaction ReadTransaction = null;
            DateTime       before          = DateTime.Now;
            DateTime       after           = DateTime.Now;
            GiftBatchTDS   ds = new GiftBatchTDS();

            DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(
                IsolationLevel.ReadCommitted,
                TEnforceIsolationLevel.eilMinimum,
                ref ReadTransaction,
                delegate
            {
                string sql = "SELECT PUB_a_gift_detail.*, false AS AlreadyMatched, PUB_a_gift_batch.a_batch_status_c AS BatchStatus " +
                             "FROM PUB_a_gift_batch, PUB_a_gift_detail " +
                             "WHERE PUB_a_gift_detail.a_ledger_number_i = PUB_a_gift_batch.a_ledger_number_i AND PUB_a_gift_detail.a_batch_number_i = PUB_a_gift_batch.a_batch_number_i";

                before            = DateTime.Now;
                DataTable untyped = DBAccess.GDBAccessObj.SelectDT(sql, "test", ReadTransaction);
                after             = DateTime.Now;

                TLogging.Log(String.Format("loading all {0} gift details into an untyped table took {1} milliseconds",
                                           untyped.Rows.Count,
                                           (after.Subtract(before)).TotalMilliseconds));

                GiftBatchTDSAGiftDetailTable typed = new GiftBatchTDSAGiftDetailTable();
                before = DateTime.Now;
                DBAccess.GDBAccessObj.SelectDT(typed, sql, ReadTransaction, new OdbcParameter[0], 0, 0);
                after = DateTime.Now;

                TLogging.Log(String.Format("loading all {0} gift details into a typed table took {1} milliseconds",
                                           typed.Rows.Count,
                                           (after.Subtract(before)).TotalMilliseconds));

                AMotivationDetailAccess.LoadAll(ds, ReadTransaction);

                before = DateTime.Now;
                DBAccess.GDBAccessObj.Select(ds, sql, ds.AGiftDetail.TableName, ReadTransaction);
                after = DateTime.Now;
            });

            TLogging.Log(String.Format("loading all {0} gift details into a typed dataset took {1} milliseconds",
                                       ds.AGiftDetail.Rows.Count,
                                       (after.Subtract(before)).TotalMilliseconds));

            before = DateTime.Now;
            GiftBatchTDS ds2 = new GiftBatchTDS();

            ds2.Merge(ds.AGiftDetail);
            after = DateTime.Now;

            TLogging.Log(String.Format("merging typed table into other dataset took {0} milliseconds",
                                       (after.Subtract(before)).TotalMilliseconds));
        }
        /// <summary>
        /// Constructor
        /// </summary>
        public TUC_GiftBatches_AccountAndCostCentre(Int32 ALedgerNumber,
            GiftBatchTDS AMainDS,
            TCmbAutoPopulated ACmbBankAccountCode,
            TCmbAutoPopulated ACmbCostCentreCode)
        {
            FLedgerNumber = ALedgerNumber;
            FMainDS = AMainDS;

            FCmbBankAccountCode = ACmbBankAccountCode;
            FCmbCostCentreCode = ACmbCostCentreCode;
        }
Exemplo n.º 29
0
        /// <summary>
        /// Constructor
        /// </summary>
        public TUC_RecurringGiftBatches_AccountAndCostCentre(Int32 ALedgerNumber,
                                                             GiftBatchTDS AMainDS,
                                                             TCmbAutoPopulated ACmbBankAccountCode,
                                                             TCmbAutoPopulated ACmbCostCentreCode)
        {
            FLedgerNumber = ALedgerNumber;
            FMainDS       = AMainDS;

            FCmbBankAccountCode = ACmbBankAccountCode;
            FCmbCostCentreCode  = ACmbCostCentreCode;
        }
Exemplo n.º 30
0
        public static TSubmitChangesResult SaveMotivationDetails(ref GiftBatchTDS AInspectDS)
        {
            if (AInspectDS != null)
            {
                // TODO make sure new motivation groups are created. at the moment only 1 existing motivation group is supported
                GiftBatchTDSAccess.SubmitChanges(AInspectDS);

                return(TSubmitChangesResult.scrOK);
            }

            return(TSubmitChangesResult.scrError);
        }
Exemplo n.º 31
0
        /// create new gift info
        public static AGiftBatchRow CreateNewGiftInfo(Int64 APartnerKey, ref GiftBatchTDS AGiftDS, TDataBase ADataBase = null)
        {
            TDataBase      db = DBAccess.Connect("CreateNewGiftInfo", ADataBase);
            bool           NewTransaction;
            TDBTransaction Transaction = db.GetNewOrExistingTransaction(IsolationLevel.Serializable, out NewTransaction);

            ALedgerAccess.LoadAll(AGiftDS, Transaction);

            AGiftDS = TGiftTransactionWebConnector.CreateAGiftBatch(AGiftDS.ALedger[0].LedgerNumber, DateTime.Today, "Test batch", db);

            // Create a new GiftBatch
            AGiftBatchRow Batch = AGiftDS.AGiftBatch[0];

            Batch.BankAccountCode    = "6000";
            Batch.BatchYear          = 1;
            Batch.BatchPeriod        = 1;
            Batch.CurrencyCode       = "EUR";
            Batch.BankCostCentre     = Batch.LedgerNumber.ToString() + "00";
            Batch.LastGiftNumber     = 1;
            Batch.ExchangeRateToBase = 0.5M;

            // Create a new Gift record
            AGiftRow Gift = AGiftDS.AGift.NewRowTyped();

            Gift.LedgerNumber          = Batch.LedgerNumber;
            Gift.BatchNumber           = Batch.BatchNumber;
            Gift.GiftTransactionNumber = 1;
            Gift.DonorKey = APartnerKey;
            AGiftDS.AGift.Rows.Add(Gift);

            // Create a new GiftDetail record
            AGiftDetailRow GiftDetail = AGiftDS.AGiftDetail.NewRowTyped();

            GiftDetail.LedgerNumber          = Gift.LedgerNumber;
            GiftDetail.BatchNumber           = Gift.BatchNumber;
            GiftDetail.GiftTransactionNumber = Gift.GiftTransactionNumber;
            GiftDetail.DetailNumber          = 1;
            GiftDetail.MotivationGroupCode   = "GIFT";
            GiftDetail.MotivationDetailCode  = "SUPPORT";
            // this won't work with RecipientKey 0 anymore. see https://github.com/openpetra/openpetra/issues/183
            GiftDetail.RecipientKey          = 43000000;
            GiftDetail.RecipientLedgerNumber = APartnerKey;
            GiftDetail.GiftTransactionAmount = 10;
            AGiftDS.AGiftDetail.Rows.Add(GiftDetail);

            if (NewTransaction)
            {
                Transaction.Rollback();
            }

            return(Batch);
        }
        private void RevertDataSet(GiftBatchTDS AMainDS, GiftBatchTDS ABackupDS, int ASelectRowInGrid = 0)
        {
            if ((ABackupDS != null) && (AMainDS != null))
            {
                AMainDS.RejectChanges();
                AMainDS.Merge(ABackupDS);

                if (ASelectRowInGrid > 0)
                {
                    SelectRowInGrid(ASelectRowInGrid);
                }
            }
        }
Exemplo n.º 33
0
        private void OnLedgerChange(Object Sender, EventArgs e)
        {
            String LedgerDescr = (string)cmbLedger.Items[cmbLedger.SelectedIndex];

            FLedgerNumber = Convert.ToInt32(LedgerDescr.Substring(0, LedgerDescr.IndexOf(':')));

            //
            // If I've got changes in the current list, I need to commit that first..
            //
            SaveAllChangedRows();
            FMainDS = TRemote.MFinance.Gift.WebConnectors.LoadMotivationDetails(FLedgerNumber);
            LoadLists();
        }
        private TSubmitChangesResult StoreManualCode(ref GiftBatchTDS ASubmitChanges, out TVerificationResultCollection AVerificationResult)
        {
            AVerificationResult = null;

            TSubmitChangesResult result = TRemote.MFinance.Gift.WebConnectors.SaveMotivationDetails(ref ASubmitChanges);

            if (result == TSubmitChangesResult.scrOK)
            {
                TDataCache.TMFinance.RefreshCacheableFinanceTable(TCacheableFinanceTablesEnum.MotivationGroupList, FLedgerNumber);
            }

            return(result);
        }
Exemplo n.º 35
0
        public void UpdateRecord()
        {
            TDBTransaction ReadTransaction = new TDBTransaction();
            GiftBatchTDS   MainDS          = new GiftBatchTDS();
            TDataBase      db = DBAccess.Connect("test");

            db.ReadTransaction(ref ReadTransaction,
                               delegate
            {
                ALedgerAccess.LoadAll(MainDS, ReadTransaction);
            });
            ReadTransaction.Rollback();

            MainDS.ALedger[0].LastGiftBatchNumber++;

            AGiftBatchRow batch = MainDS.AGiftBatch.NewRowTyped();

            batch.LedgerNumber     = MainDS.ALedger[0].LedgerNumber;
            batch.BatchNumber      = MainDS.ALedger[0].LastGiftBatchNumber;
            batch.BankAccountCode  = "6000";
            batch.BatchYear        = 0;
            batch.BatchPeriod      = 1;
            batch.CurrencyCode     = "EUR";
            batch.BatchDescription = "test";
            batch.BankCostCentre   = (MainDS.ALedger[0].LedgerNumber * 100).ToString("0000");
            batch.LastGiftNumber   = 0;
            batch.HashTotal        = 83;
            MainDS.AGiftBatch.Rows.Add(batch);

            GiftBatchTDSAccess.SubmitChanges(MainDS);
            MainDS.AcceptChanges();

            MainDS.AGiftBatch[0].BatchDescription = "test2";
            GiftBatchTDSAccess.SubmitChanges(MainDS);


            TDBTransaction  transaction = new TDBTransaction();
            AGiftBatchTable batches     = null;

            db.ReadTransaction(
                ref transaction,
                delegate
            {
                batches = AGiftBatchAccess.LoadByPrimaryKey(batch.LedgerNumber, batch.BatchNumber, transaction);
            });

            // some problems with sqlite and datagrid
            Assert.AreEqual(typeof(decimal), batches[0][AGiftBatchTable.ColumnHashTotalId].GetType(), "type decimal");
            Assert.AreEqual(83.0m, batches[0].HashTotal, "gift batch hashtotal does not equal");
        }
Exemplo n.º 36
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);
        }
        private static bool GetAllDataNeeded(ref GiftBatchTDS AGiftBatchDS, Int64 ARecipientKey, decimal ANewPct, DateTime AValidFrom, Form AForm)
        {
            Boolean ok;
            TVerificationResultCollection Messages;

            try
            {
                AForm.Cursor = Cursors.WaitCursor;

                ok = TRemote.MFinance.Gift.WebConnectors.GetGiftsForTaxDeductiblePctAdjustment(
                    ref AGiftBatchDS,
                    ARecipientKey,
                    AValidFrom,
                    ANewPct,
                    out Messages);
            }
            finally
            {
                AForm.Cursor = Cursors.Default;
            }

            // If one or more of the gifts have already been reversed.
            if (!ok)
            {
                if (Messages.Count > 0)
                {
                    foreach (TVerificationResult message in Messages)
                    {
                        if (message.ResultText.Length > 0)
                        {
                            MessageBox.Show(AForm.Text + Catalog.GetString(" cancelled. ") + message.ResultText,
                                Catalog.GetString("Tax Deductible Percentage Adjust"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }

                return false;
            }

            // if there are no gifts to be adjusted
            if ((AGiftBatchDS.AGiftDetail == null) || (AGiftBatchDS.AGiftDetail.Rows.Count == 0))
            {
                MessageBox.Show(Catalog.GetString("There are no gifts to adjust."));
                return false;
            }

            return true;
        }
Exemplo n.º 38
0
        public void UpdateRecord()
        {
            TDBTransaction ReadTransaction = null;
            GiftBatchTDS MainDS = new GiftBatchTDS();

            DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(
                IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum, ref ReadTransaction,
                delegate
                {
                    ALedgerAccess.LoadAll(MainDS, ReadTransaction);
                });

            MainDS.ALedger[0].LastGiftBatchNumber++;

            AGiftBatchRow batch = MainDS.AGiftBatch.NewRowTyped();
            batch.LedgerNumber = MainDS.ALedger[0].LedgerNumber;
            batch.BatchNumber = MainDS.ALedger[0].LastGiftBatchNumber;
            batch.BankAccountCode = "6000";
            batch.BatchYear = 0;
            batch.BatchPeriod = 1;
            batch.CurrencyCode = "EUR";
            batch.BatchDescription = "test";
            batch.BankCostCentre = (MainDS.ALedger[0].LedgerNumber * 100).ToString("0000");
            batch.LastGiftNumber = 0;
            batch.HashTotal = 83;
            MainDS.AGiftBatch.Rows.Add(batch);

            GiftBatchTDSAccess.SubmitChanges(MainDS);
            MainDS.AcceptChanges();

            MainDS.AGiftBatch[0].BatchDescription = "test2";
            GiftBatchTDSAccess.SubmitChanges(MainDS);


            TDBTransaction transaction = null;
            AGiftBatchTable batches = null;
            DBAccess.GDBAccessObj.BeginAutoReadTransaction(ref transaction,
                delegate
                {
                    batches = AGiftBatchAccess.LoadByPrimaryKey(batch.LedgerNumber, batch.BatchNumber, transaction);
                });

            // some problems with sqlite and datagrid
            Assert.AreEqual(typeof(decimal), batches[0][AGiftBatchTable.ColumnHashTotalId].GetType(), "type decimal");
            Assert.AreEqual(83.0m, batches[0].HashTotal, "gift batch hashtotal does not equal");
        }
Exemplo n.º 39
0
        /// <summary>
        /// post all gift batches in the given period, but leave some (or none) unposted
        /// </summary>
        public static bool PostBatches(int AYear, int APeriod, int ALeaveBatchesUnposted = 0)
        {
            GiftBatchTDS MainDS = new GiftBatchTDS();

            AGiftBatchRow GiftBatchTemplateRow = MainDS.AGiftBatch.NewRowTyped(false);

            GiftBatchTemplateRow.LedgerNumber = FLedgerNumber;
            GiftBatchTemplateRow.BatchYear = AYear;
            GiftBatchTemplateRow.BatchPeriod = APeriod;
            GiftBatchTemplateRow.BatchStatus = MFinanceConstants.BATCH_UNPOSTED;
            AGiftBatchAccess.LoadUsingTemplate(MainDS, GiftBatchTemplateRow, null);

            int countUnPosted = MainDS.AGiftBatch.Count;

            List <Int32>GiftBatchesToPost = new List <int>();

            foreach (AGiftBatchRow batch in MainDS.AGiftBatch.Rows)
            {
                if (countUnPosted <= ALeaveBatchesUnposted)
                {
                    break;
                }

                countUnPosted--;

                GiftBatchesToPost.Add(batch.BatchNumber);
            }

            TVerificationResultCollection VerificationResult;

            if (!TGiftTransactionWebConnector.PostGiftBatches(FLedgerNumber, GiftBatchesToPost, out VerificationResult))
            {
                TLogging.Log(VerificationResult.BuildVerificationResultString());
                return false;
            }

            return true;
        }
Exemplo n.º 40
0
        public static GiftBatchTDS CreateAGiftBatch(Int32 ALedgerNumber, DateTime ADateEffective, string ABatchDescription)
        {
            GiftBatchTDS MainDS = new GiftBatchTDS();

            TDBTransaction ReadWriteTransaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.Serializable);

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

                TGiftBatchFunctions.CreateANewGiftBatchRow(ref MainDS, ref ReadWriteTransaction, ref LedgerTable, ALedgerNumber, ADateEffective);

                if (ABatchDescription.Length > 0)
                {
                    MainDS.AGiftBatch[0].BatchDescription = ABatchDescription;
                }

                AGiftBatchAccess.SubmitChanges(MainDS.AGiftBatch, ReadWriteTransaction);

                ALedgerAccess.SubmitChanges(LedgerTable, ReadWriteTransaction);

                MainDS.AGiftBatch.AcceptChanges();

                DBAccess.GDBAccessObj.CommitTransaction();
            }
            catch (Exception Exc)
            {
                TLogging.Log("An Exception occured during the creation of a Gift Batch record:" + Environment.NewLine + Exc.ToString());

                DBAccess.GDBAccessObj.RollbackTransaction();

                throw;
            }

            return MainDS;
        }
Exemplo n.º 41
0
        /// <summary>
        /// Looks for gifts where the recipient is an ExWorker and asks the user if they want to continue.
        /// (Make sure GetDataFromControls is called before this method so that AMainDS is up-to-date.)
        /// </summary>
        /// <param name="AAction">Why this method is being called</param>
        /// <param name="AMainDS"></param>
        /// <param name="APetraUtilsObject"></param>
        /// <param name="APostingGiftDetails">Only used when being called in order to carry out a batch posting</param>
        /// <returns>Returns true if saving/posting can continue</returns>
        public static bool CanContinueWithAnyExWorkers(GiftBatchAction AAction,
            GiftBatchTDS AMainDS,
            TFrmPetraEditUtils APetraUtilsObject,
            DataTable APostingGiftDetails = null)
        {
            DataTable ExWorkers = null;
            string Msg = string.Empty;
            int BatchNumber = -1;
            int ExWorkerGifts = 0;

            string ExWorkerSpecialType = TSystemDefaults.GetSystemDefault(SharedConstants.SYSDEFAULT_EXWORKERSPECIALTYPE, "EX-WORKER");

            // first check for Ex-Workers in the batch that is being posted/submitted (if a batch is being posted/submitted)
            if ((APostingGiftDetails != null) && (APostingGiftDetails.Rows.Count > 0))
            {
                ExWorkers = TRemote.MFinance.Gift.WebConnectors.FindGiftRecipientExWorker(APostingGiftDetails, BatchNumber);
                ExWorkerGifts += ExWorkers.Rows.Count;

                Msg = GetExWorkersString(AAction, ExWorkerSpecialType, ExWorkers);

                if (ExWorkers.Rows.Count > 0)
                {
                    BatchNumber = (int)APostingGiftDetails.Rows[0][GiftBatchTDSAGiftDetailTable.GetBatchNumberDBName()];
                }
            }

            // check for Ex-Workers in all added and modified data
            if (APetraUtilsObject.HasChanges)
            {
                DataTable Changes = new DataTable();

                if (AMainDS.AGiftDetail.GetChangesTyped() != null)
                {
                    Changes.Merge(AMainDS.AGiftDetail.GetChangesTyped());
                }
                else if (AMainDS.ARecurringGiftDetail.GetChangesTyped() != null)
                {
                    Changes.Merge(AMainDS.ARecurringGiftDetail.GetChangesTyped());
                }

                if ((Changes != null) && (Changes.Rows.Count > 0))
                {
                    ExWorkers = TRemote.MFinance.Gift.WebConnectors.FindGiftRecipientExWorker(Changes, BatchNumber);
                    ExWorkerGifts += ExWorkers.Rows.Count;

                    Msg += GetExWorkersString(null, ExWorkerSpecialType, ExWorkers);
                }
            }

            // alert the user to any recipients who are Ex-Workers
            if (Msg != string.Empty)
            {
                if (AAction == GiftBatchAction.SAVING)
                {
                    Msg += Catalog.GetString("Do you want to continue with saving anyway?");
                }
                else
                {
                    // singular
                    if (ExWorkerGifts == 1)
                    {
                        if (AAction == GiftBatchAction.POSTING)
                        {
                            Msg += Catalog.GetString("This gift will need to be saved before this batch can be posted.");
                        }
                        else if (AAction == GiftBatchAction.NEWBATCH)
                        {
                            Msg += Catalog.GetString("This gift will need to be saved before a new batch can be created.");
                        }
                        else if (AAction == GiftBatchAction.CANCELLING)
                        {
                            Msg += Catalog.GetString("This gift will need to be saved before this batch can be cancelled.");
                        }
                        else if (AAction == GiftBatchAction.SUBMITTING)
                        {
                            Msg += Catalog.GetString("This gift will need to be saved before this batch can be submitted.");
                        }
                        else if (AAction == GiftBatchAction.DELETING)
                        {
                            Msg += Catalog.GetString("This gift will need to be saved before this batch can be deleted.");
                        }
                    }
                    // plural
                    else
                    {
                        if (AAction == GiftBatchAction.POSTING)
                        {
                            Msg += Catalog.GetString("These gifts will need to be saved before this batch can be posted.");
                        }
                        else if (AAction == GiftBatchAction.NEWBATCH)
                        {
                            Msg += Catalog.GetString("These gifts will need to be saved before a new batch can be created.");
                        }
                        else if (AAction == GiftBatchAction.CANCELLING)
                        {
                            Msg += Catalog.GetString("These gifts will need to be saved before this batch can be cancelled.");
                        }
                        else if (AAction == GiftBatchAction.SUBMITTING)
                        {
                            Msg += Catalog.GetString("These gifts will need to be saved before this batch can be submitted.");
                        }
                        else if (AAction == GiftBatchAction.DELETING)
                        {
                            Msg += Catalog.GetString("These gifts will need to be saved before this batch can be deleted.");
                        }
                    }

                    Msg += " " + Catalog.GetString("Do you want to continue?");
                }

                if (MessageBox.Show(
                        Msg, string.Format(Catalog.GetString("{0} Warning"), ExWorkerSpecialType), MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
                    == DialogResult.No)
                {
                    return false;
                }
            }

            return true;
        }
Exemplo n.º 42
0
        /// <summary>
        /// Looks for gifts where the donor is anoymous but the gift is not marked as confidential and asks the user if they want to continue.
        /// (Make sure GetDataFromControls is called before this method so that AMainDS is up-to-date.)
        /// </summary>
        /// <param name="AMainDS"></param>
        public static bool CanContinueWithAnyAnonymousDonors(GiftBatchTDS AMainDS)
        {
            GiftBatchTDSAGiftDetailTable UnConfidentialGiftsWithAnonymousDonors = new GiftBatchTDSAGiftDetailTable();

            foreach (GiftBatchTDSAGiftDetailRow Row in AMainDS.AGiftDetail.Rows)
            {
                if (!Row.ConfidentialGiftFlag)
                {
                    PPartnerRow PartnerRow = (PPartnerRow)AMainDS.DonorPartners.Rows.Find(Row.DonorKey);

                    if ((PartnerRow != null) && PartnerRow.AnonymousDonor)
                    {
                        UnConfidentialGiftsWithAnonymousDonors.Rows.Add((object[])Row.ItemArray.Clone());
                    }
                }
            }

            if (UnConfidentialGiftsWithAnonymousDonors.Rows.Count > 0)
            {
                string Message = string.Empty;

                DataView dv = UnConfidentialGiftsWithAnonymousDonors.DefaultView;
                dv.Sort = GiftBatchTDSAGiftDetailTable.GetGiftTransactionNumberDBName() + " ASC";
                DataTable sortedDT = dv.ToTable();

                if (UnConfidentialGiftsWithAnonymousDonors.Rows.Count == 1)
                {
                    Message = Catalog.GetString(
                        "The gift listed below in this batch is not marked as confidential but the donor has asked to remain anonymous.");
                }
                else
                {
                    Message = Catalog.GetString(
                        "The gifts listed below in this batch are not marked as confidential but the donors have asked to remain anonymous.");
                }

                Message += "\n\n";

                foreach (DataRow UnConfidentialGifts in sortedDT.Rows)
                {
                    Message += Catalog.GetString("Batch: ") + UnConfidentialGifts[GiftBatchTDSAGiftDetailTable.GetBatchNumberDBName()] + "; " +
                               Catalog.GetString("Gift: ") + UnConfidentialGifts[GiftBatchTDSAGiftDetailTable.GetGiftTransactionNumberDBName()] +
                               "; " +
                               Catalog.GetString("Donor: ") + UnConfidentialGifts[GiftBatchTDSAGiftDetailTable.GetDonorNameDBName()] + " (" +
                               UnConfidentialGifts[GiftBatchTDSAGiftDetailTable.GetDonorKeyDBName()] + ")\n";
                }

                Message += "\n" + Catalog.GetString("Do you want to continue with posting anyway?");

                if (MessageBox.Show(
                        Message, Catalog.GetString("Anonymous Donor Warning"), MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
                    == DialogResult.No)
                {
                    return false;
                }
            }

            return true;
        }
Exemplo n.º 43
0
        /// <summary>
        /// Loads tables needed for the calculation of admin fees for a gift detail.
        /// </summary>
        private static void LoadAdminFeeTablesForGiftDetail(GiftBatchTDS AMainDS,
            AGiftDetailRow AGiftDetail,
            TDBTransaction ATransaction)
        {
            // only needs to be loaded once for the whole batch
            if ((AMainDS.AProcessedFee == null) || (AMainDS.AProcessedFee.Rows.Count == 0))
            {
                AProcessedFeeAccess.LoadViaAGiftBatch(AMainDS, AGiftDetail.LedgerNumber, AGiftDetail.BatchNumber, ATransaction);
            }

            // only needs to be loaded once for the whole batch
            if ((AMainDS.AFeesPayable == null) || (AMainDS.AFeesPayable.Rows.Count == 0))
            {
                AFeesPayableAccess.LoadViaALedger(AMainDS, AGiftDetail.LedgerNumber, ATransaction);
            }

            // if motivation detail has changed from the last gift detail
            if ((AMainDS.AMotivationDetailFee == null) || (AMainDS.AMotivationDetailFee.Rows.Count == 0)
                || (AMainDS.AMotivationDetailFee[0].MotivationGroupCode != AGiftDetail.MotivationGroupCode)
                || (AMainDS.AMotivationDetailFee[0].MotivationDetailCode != AGiftDetail.MotivationDetailCode))
            {
                AMainDS.AMotivationDetailFee.Rows.Clear();
                AMotivationDetailFeeAccess.LoadViaAMotivationDetail(
                    AMainDS, AGiftDetail.LedgerNumber, AGiftDetail.MotivationGroupCode, AGiftDetail.MotivationDetailCode, ATransaction);
            }

            // If this gift is for the local field, don't charge the fee to itself. So we don't need the fees receivable.
            string Query = "SELECT a_fees_receivable.* FROM a_fees_receivable" +
                           " WHERE EXISTS (SELECT * FROM a_cost_centre" +
                           " WHERE a_cost_centre.a_ledger_number_i = " + AGiftDetail.LedgerNumber +
                           " AND a_cost_centre.a_cost_centre_code_c = '" + AGiftDetail.CostCentreCode + "'" +
                           " AND a_cost_centre.a_cost_centre_type_c = '" + MFinanceConstants.FOREIGN_CC_TYPE + "')" +
                           " AND a_fees_receivable.a_ledger_number_i = " + AGiftDetail.LedgerNumber;

            AMainDS.AFeesReceivable.Rows.Clear();

            // need to use a typed table to avoid problems with SQLite in the Merge
            AFeesReceivableTable tmpFeesReceivable = new AFeesReceivableTable();
            DBAccess.GDBAccessObj.SelectDT(tmpFeesReceivable, Query, ATransaction);
            AMainDS.AFeesReceivable.Merge(tmpFeesReceivable);

            #region Validate Data

            if ((AMainDS.AMotivationDetailFee != null) && (AMainDS.AMotivationDetailFee.Count > 0)
                && ((AMainDS.AFeesPayable == null) || (AMainDS.AFeesPayable.Rows.Count == 0))
                && ((AMainDS.AFeesReceivable == null) || (AMainDS.AFeesReceivable.Rows.Count == 0)))
            {
                throw new EFinanceSystemDataTableReturnedNoDataException(String.Format(Catalog.GetString(
                            "Function:{0} - Admin fee data for Gift Detail {1}, from Gift {2} in Batch {3} and Ledger {4} does not exist or could not be accessed!"),
                        Utilities.GetMethodSignature(),
                        AGiftDetail.DetailNumber,
                        AGiftDetail.GiftTransactionNumber,
                        AGiftDetail.BatchNumber,
                        AGiftDetail.LedgerNumber));
            }

            #endregion Validate Data
        }
Exemplo n.º 44
0
        /// create new recurring gift info
        public static ARecurringGiftBatchRow CreateNewRecurringGiftInfo(Int64 APartnerKey, ref GiftBatchTDS AGiftDS)
        {
            ALedgerAccess.LoadAll(AGiftDS, DBAccess.GDBAccessObj.Transaction);

            AGiftDS = TGiftTransactionWebConnector.CreateARecurringGiftBatch(AGiftDS.ALedger[0].LedgerNumber);

            // Create a new RecurringGiftBatch
            ARecurringGiftBatchRow Batch = AGiftDS.ARecurringGiftBatch[0];
            Batch.BankAccountCode = "6000";
            Batch.CurrencyCode = "EUR";

            // Create a new RecurringGift record
            ARecurringGiftRow RecurringGift = AGiftDS.ARecurringGift.NewRowTyped();
            RecurringGift.LedgerNumber = Batch.LedgerNumber;
            RecurringGift.BatchNumber = Batch.BatchNumber;
            RecurringGift.GiftTransactionNumber = 1;
            RecurringGift.DonorKey = APartnerKey;
            AGiftDS.ARecurringGift.Rows.Add(RecurringGift);

            // Create a new RecurringGiftDetail record
            ARecurringGiftDetailRow RecurringGiftDetail = AGiftDS.ARecurringGiftDetail.NewRowTyped();
            RecurringGiftDetail.LedgerNumber = Batch.LedgerNumber;
            RecurringGiftDetail.BatchNumber = Batch.BatchNumber;
            RecurringGiftDetail.GiftTransactionNumber = 1;
            RecurringGiftDetail.MotivationGroupCode = "GIFT";
            RecurringGiftDetail.MotivationDetailCode = "SUPPORT";
            RecurringGiftDetail.RecipientKey = APartnerKey;
            RecurringGiftDetail.RecipientLedgerNumber = APartnerKey;
            AGiftDS.ARecurringGiftDetail.Rows.Add(RecurringGiftDetail);

            return Batch;
        }
Exemplo n.º 45
0
        /// create new gift info
        public static AGiftBatchRow CreateNewGiftInfo(Int64 APartnerKey, ref GiftBatchTDS AGiftDS)
        {
            ALedgerAccess.LoadAll(AGiftDS, DBAccess.GDBAccessObj.Transaction);

            AGiftDS = TGiftTransactionWebConnector.CreateAGiftBatch(AGiftDS.ALedger[0].LedgerNumber, DateTime.Today, "Test batch");

            // Create a new GiftBatch
            AGiftBatchRow Batch = AGiftDS.AGiftBatch[0];
            Batch.BankAccountCode = "6000";
            Batch.BatchYear = 1;
            Batch.BatchPeriod = 1;
            Batch.CurrencyCode = "EUR";
            Batch.BankCostCentre = Batch.LedgerNumber.ToString() + "00";
            Batch.LastGiftNumber = 1;
            Batch.ExchangeRateToBase = 0.5M;

            // Create a new Gift record
            AGiftRow Gift = AGiftDS.AGift.NewRowTyped();
            Gift.LedgerNumber = Batch.LedgerNumber;
            Gift.BatchNumber = Batch.BatchNumber;
            Gift.GiftTransactionNumber = 1;
            Gift.DonorKey = APartnerKey;
            AGiftDS.AGift.Rows.Add(Gift);

            // Create a new GiftDetail record
            AGiftDetailRow GiftDetail = AGiftDS.AGiftDetail.NewRowTyped();
            GiftDetail.LedgerNumber = Gift.LedgerNumber;
            GiftDetail.BatchNumber = Gift.BatchNumber;
            GiftDetail.GiftTransactionNumber = Gift.GiftTransactionNumber;
            GiftDetail.DetailNumber = 1;
            GiftDetail.MotivationGroupCode = "GIFT";
            GiftDetail.MotivationDetailCode = "SUPPORT";
            GiftDetail.RecipientKey = 0;
            GiftDetail.RecipientLedgerNumber = APartnerKey;
            AGiftDS.AGiftDetail.Rows.Add(GiftDetail);

            return Batch;
        }
        private TSubmitChangesResult StoreManualCode(ref GiftBatchTDS ASubmitChanges, out TVerificationResultCollection AVerificationResult)
        {
            AVerificationResult = null;

            TSubmitChangesResult result = TRemote.MFinance.Gift.WebConnectors.SaveMotivationDetails(ref ASubmitChanges);

            if (result == TSubmitChangesResult.scrOK)
            {
                TDataCache.TMFinance.RefreshCacheableFinanceTable(TCacheableFinanceTablesEnum.MotivationGroupList, FLedgerNumber);
            }

            return result;
        }
Exemplo n.º 47
0
        private static GiftBatchTDS CreateGiftBatches(SortedList <DateTime, List <XmlNode>>AGiftsPerDate, int APeriodNumber)
        {
            GiftBatchTDS MainDS = new GiftBatchTDS();
            ALedgerTable LedgerTable = null;

            TDBTransaction ReadTransaction = null;

            DBAccess.GDBAccessObj.BeginAutoReadTransaction(IsolationLevel.ReadCommitted, ref ReadTransaction,
                delegate
                {
                    // get a list of potential donors (all class FAMILY)
                    string sqlGetFamilyPartnerKeys = "SELECT p_partner_key_n FROM PUB_p_family";
                    DataTable FamilyKeys = DBAccess.GDBAccessObj.SelectDT(sqlGetFamilyPartnerKeys,
                        "keys",
                        ReadTransaction);

                    // get a list of workers (all class FAMILY, with special type WORKER)
                    string sqlGetWorkerPartnerKeys =
                        "SELECT PUB_p_family.p_partner_key_n FROM PUB_p_family, PUB_p_partner_type WHERE PUB_p_partner_type.p_partner_key_n = PUB_p_family.p_partner_key_n AND p_type_code_c = 'WORKER'";
                    DataTable WorkerKeys = DBAccess.GDBAccessObj.SelectDT(sqlGetWorkerPartnerKeys, "keys", ReadTransaction);

                    // get a list of fields (all class UNIT, with unit type F)
                    string sqlGetFieldPartnerKeys =
                        String.Format(
                            "SELECT U.p_partner_key_n FROM PUB_p_unit U WHERE u_unit_type_code_c = 'F' AND EXISTS (SELECT * FROM PUB_a_valid_ledger_number V WHERE V.a_ledger_number_i = {0} AND V.p_partner_key_n = U.p_partner_key_n)",
                            FLedgerNumber);
                    DataTable FieldKeys = DBAccess.GDBAccessObj.SelectDT(sqlGetFieldPartnerKeys, "keys", ReadTransaction);

                    // get a list of key ministries (all class UNIT, with unit type KEY-MIN), and their field ledger number and cost centre code
                    string sqlGetKeyMinPartnerKeys =
                        "SELECT u.p_partner_key_n, us.um_parent_unit_key_n, vl.a_cost_centre_code_c " +
                        "FROM PUB_p_unit u, PUB_um_unit_structure us, PUB_a_valid_ledger_number vl " +
                        "WHERE u.u_unit_type_code_c = 'KEY-MIN' " +
                        "AND us.um_child_unit_key_n = u.p_partner_key_n " +
                        "AND vl.p_partner_key_n = us.um_parent_unit_key_n " +
                        "AND vl.a_ledger_number_i = " + FLedgerNumber.ToString();
                    DataTable KeyMinistries = DBAccess.GDBAccessObj.SelectDT(sqlGetKeyMinPartnerKeys, "keys", ReadTransaction);

                    LedgerTable = ALedgerAccess.LoadByPrimaryKey(FLedgerNumber, ReadTransaction);

                    AAccountingPeriodRow AccountingPeriodRow = AAccountingPeriodAccess.LoadByPrimaryKey(FLedgerNumber,
                        APeriodNumber,
                        ReadTransaction)[0];

                    // create a gift batch for each day.
                    // TODO: could create one batch per month, if there are not so many gifts (less than 100 per month)
                    foreach (DateTime GlEffectiveDate in AGiftsPerDate.Keys)
                    {
                        if ((GlEffectiveDate.CompareTo(AccountingPeriodRow.PeriodStartDate) < 0)
                            || (GlEffectiveDate.CompareTo(AccountingPeriodRow.PeriodEndDate) > 0))
                        {
                            // only create gifts in that period
                            continue;
                        }

                        AGiftBatchRow giftBatch = TGiftBatchFunctions.CreateANewGiftBatchRow(ref MainDS,
                            ref ReadTransaction,
                            ref LedgerTable,
                            FLedgerNumber,
                            GlEffectiveDate);

                        TLogging.LogAtLevel(1, "create gift batch for " + GlEffectiveDate.ToShortDateString());
                        giftBatch.BatchDescription = "Benerator Batch for " + GlEffectiveDate.ToShortDateString();
                        giftBatch.BatchTotal = 0.0m;

                        foreach (XmlNode RecordNode in AGiftsPerDate[GlEffectiveDate])
                        {
                            AGiftRow gift = MainDS.AGift.NewRowTyped();
                            gift.LedgerNumber = giftBatch.LedgerNumber;
                            gift.BatchNumber = giftBatch.BatchNumber;
                            gift.GiftTransactionNumber = giftBatch.LastGiftNumber + 1;
                            gift.DateEntered = GlEffectiveDate;

                            // set donorKey
                            int donorID = Convert.ToInt32(TXMLParser.GetAttribute(RecordNode, "donor")) % FamilyKeys.Rows.Count;
                            gift.DonorKey = Convert.ToInt64(FamilyKeys.Rows[donorID].ItemArray[0]);

                            // calculate gift detail information
                            int countDetails = Convert.ToInt32(TXMLParser.GetAttribute(RecordNode, "splitgift"));

                            for (int counter = 1; counter <= countDetails; counter++)
                            {
                                AGiftDetailRow giftDetail = MainDS.AGiftDetail.NewRowTyped();
                                giftDetail.LedgerNumber = gift.LedgerNumber;
                                giftDetail.BatchNumber = gift.BatchNumber;
                                giftDetail.GiftTransactionNumber = gift.GiftTransactionNumber;

                                giftDetail.MotivationGroupCode = "GIFT";
                                giftDetail.GiftTransactionAmount = Convert.ToDecimal(TXMLParser.GetAttribute(RecordNode, "amount_" + counter.ToString()));
                                giftDetail.GiftAmount = giftDetail.GiftTransactionAmount;
                                giftBatch.BatchTotal += giftDetail.GiftAmount;

                                string motivation = TXMLParser.GetAttribute(RecordNode, "motivation_" + counter.ToString());

                                if (motivation == "SUPPORT")
                                {
                                    if (WorkerKeys.Rows.Count == 0)
                                    {
                                        continue;
                                    }

                                    giftDetail.MotivationDetailCode = "SUPPORT";
                                    int recipientID =
                                        Convert.ToInt32(TXMLParser.GetAttribute(RecordNode, "recipient_support_" +
                                                counter.ToString())) % WorkerKeys.Rows.Count;
                                    giftDetail.RecipientKey = Convert.ToInt64(WorkerKeys.Rows[recipientID].ItemArray[0]);

                                    giftDetail.RecipientLedgerNumber = TGiftTransactionWebConnector.GetRecipientFundNumber(giftDetail.RecipientKey,
                                        giftBatch.GlEffectiveDate);

                                    // ignore this gift detail, if there is no valid commitment period for the worker
                                    if (giftDetail.RecipientLedgerNumber == 0)
                                    {
                                        continue;
                                    }
                                }
                                else if (motivation == "FIELD")
                                {
                                    if (FieldKeys.Rows.Count == 0)
                                    {
                                        continue;
                                    }

                                    giftDetail.MotivationDetailCode = "FIELD";
                                    int recipientID =
                                        Convert.ToInt32(TXMLParser.GetAttribute(RecordNode, "recipient_field_" +
                                                counter.ToString())) % FieldKeys.Rows.Count;
                                    giftDetail.RecipientKey = Convert.ToInt64(FieldKeys.Rows[recipientID].ItemArray[0]);
                                    giftDetail.RecipientLedgerNumber = giftDetail.RecipientKey;
                                    giftDetail.CostCentreCode = (giftDetail.RecipientKey / 10000).ToString("0000");
                                }
                                else if (motivation == "KEYMIN")
                                {
                                    if (KeyMinistries.Rows.Count == 0)
                                    {
                                        continue;
                                    }

                                    giftDetail.MotivationDetailCode = "KEYMIN";
                                    int recipientID =
                                        Convert.ToInt32(TXMLParser.GetAttribute(RecordNode, "recipient_keymin_" +
                                                counter.ToString())) % KeyMinistries.Rows.Count;
                                    giftDetail.RecipientKey = Convert.ToInt64(KeyMinistries.Rows[recipientID].ItemArray[0]);

                                    giftDetail.RecipientLedgerNumber = Convert.ToInt64(KeyMinistries.Rows[recipientID].ItemArray[1]);
                                    // TTransactionWebConnector.GetRecipientFundNumber(giftDetail.RecipientKey);
                                    giftDetail.CostCentreCode = KeyMinistries.Rows[recipientID].ItemArray[2].ToString();
                                    // TTransactionWebConnector.IdentifyPartnerCostCentre(FLedgerNumber, giftDetail.RecipientLedgerNumber);
                                }

                                giftDetail.DetailNumber = gift.LastDetailNumber + 1;
                                MainDS.AGiftDetail.Rows.Add(giftDetail);
                                gift.LastDetailNumber = giftDetail.DetailNumber;
                            }

                            if (gift.LastDetailNumber > 0)
                            {
                                MainDS.AGift.Rows.Add(gift);
                                giftBatch.LastGiftNumber = gift.GiftTransactionNumber;
                            }

                            if (giftBatch.LastGiftNumber >= MaxGiftsPerBatch)
                            {
                                break;
                            }
                        }

                        if (TLogging.DebugLevel > 0)
                        {
                            TLogging.Log(
                                GlEffectiveDate.ToShortDateString() + " " + giftBatch.LastGiftNumber.ToString());
                        }
                    }
                });

            // need to save the last gift batch number in a_ledger
            if (LedgerTable != null)
            {
                TDBTransaction WriteTransaction = null;
                bool SubmissionOk = false;
                DBAccess.GDBAccessObj.BeginAutoTransaction(IsolationLevel.Serializable, ref WriteTransaction, ref SubmissionOk,
                    delegate
                    {
                        ALedgerAccess.SubmitChanges(LedgerTable, WriteTransaction);
                        SubmissionOk = true;
                    });

                if (!SubmissionOk)
                {
                    TLogging.Log("An Exception occured during the creation of Gift Batches" + Environment.NewLine);
                }
            }

            return MainDS;
        }
Exemplo n.º 48
0
        public static GiftBatchTDS LoadAGiftSingle(Int32 ALedgerNumber, Int32 ABatchNumber, Int32 AGiftTransactionNumber)
        {
            #region Validate Arguments

            if (ALedgerNumber <= 0)
            {
                throw new EFinanceSystemInvalidLedgerNumberException(String.Format(Catalog.GetString(
                            "Function:{0} - The Ledger number must be greater than 0!"),
                        Utilities.GetMethodName(true)), ALedgerNumber);
            }
            else if (ABatchNumber <= 0)
            {
                throw new EFinanceSystemInvalidBatchNumberException(String.Format(Catalog.GetString(
                            "Function:{0} - The Batch number must be greater than 0!"),
                        Utilities.GetMethodName(true)), ALedgerNumber, ABatchNumber);
            }
            else if (AGiftTransactionNumber <= 0)
            {
                throw new ArgumentException(String.Format(Catalog.GetString(
                            "Function:{0} - The Gift Transaction number in Ledger {1}, Batch {2} must be greater than 0!"),
                        Utilities.GetMethodName(true), ALedgerNumber, ABatchNumber));
            }

            #endregion Validate Arguments

            GiftBatchTDS MainDS = new GiftBatchTDS();

            TDBTransaction Transaction = null;

            try
            {
                DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum,
                    ref Transaction,
                    delegate
                    {
                        ALedgerAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, Transaction);
                        AGiftBatchAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, ABatchNumber, Transaction);
                        AGiftAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, ABatchNumber, AGiftTransactionNumber, Transaction);
                        AGiftDetailAccess.LoadViaAGift(MainDS, ALedgerNumber, ABatchNumber, AGiftTransactionNumber, Transaction);

                        #region Validate Data

                        if ((MainDS.ALedger == null) || (MainDS.ALedger.Count == 0))
                        {
                            throw new EFinanceSystemDataTableReturnedNoDataException(String.Format(Catalog.GetString(
                                        "Function:{0} - Ledger data for Ledger number {1} does not exist or could not be accessed!"),
                                    Utilities.GetMethodName(true),
                                    ALedgerNumber));
                        }
                        else if ((MainDS.AGiftBatch == null) || (MainDS.AGiftBatch.Count == 0))
                        {
                            throw new EFinanceSystemDataTableReturnedNoDataException(String.Format(Catalog.GetString(
                                        "Function:{0} - Batch data for Gift Batch number {1} in Ledger number {2} does not exist or could not be accessed!"),
                                    Utilities.GetMethodName(true),
                                    ABatchNumber,
                                    ALedgerNumber));
                        }
                        else if ((MainDS.AGift == null) || (MainDS.AGift.Count == 0))
                        {
                            throw new EFinanceSystemDataTableReturnedNoDataException(String.Format(Catalog.GetString(
                                        "Function:{0} - Gift data for Gift {1} in Batch number {2} in Ledger number {3} does not exist or could not be accessed!"),
                                    Utilities.GetMethodName(true),
                                    AGiftTransactionNumber,
                                    ABatchNumber,
                                    ALedgerNumber));
                        }
                        else if ((MainDS.AGiftDetail == null) || (MainDS.AGiftDetail.Count == 0))
                        {
                            throw new EFinanceSystemDataTableReturnedNoDataException(String.Format(Catalog.GetString(
                                        "Function:{0} - Gift Details for Gift {1} in Batch number {2} in Ledger number {3} do not exist or could not be accessed!"),
                                    Utilities.GetMethodName(true),
                                    AGiftTransactionNumber,
                                    ABatchNumber,
                                    ALedgerNumber));
                        }

                        #endregion Validate Data
                    });

                MainDS.AcceptChanges();
            }
            catch (Exception ex)
            {
                TLogging.Log(String.Format("Method:{0} - Unexpected error!{1}{1}{2}",
                        Utilities.GetMethodSignature(),
                        Environment.NewLine,
                        ex.Message));
                throw ex;
            }

            return MainDS;
        }
        /// <summary>
        /// Print a receipt for each gift (one page for each donor) in the batch
        /// </summary>
        /// <param name="AGiftTDS"></param>
        public void PrintGiftBatchReceipts(GiftBatchTDS AGiftTDS)
        {
            AGiftBatchRow GiftBatchRow = AGiftTDS.AGiftBatch[0];

            DataView GiftView = new DataView(AGiftTDS.AGift);

            //AGiftTDS.AGift.DefaultView.RowFilter
            GiftView.RowFilter = String.Format("{0}={1} and {2}={3}",
                AGiftTable.GetLedgerNumberDBName(), GiftBatchRow.LedgerNumber,
                AGiftTable.GetBatchNumberDBName(), GiftBatchRow.BatchNumber);
            String ReceiptedDonorsList = "";
            List <Int32>ReceiptedGiftTransactions = new List <Int32>();
            SortedList <Int64, AGiftTable>GiftsPerDonor = new SortedList <Int64, AGiftTable>();

            foreach (DataRowView rv in GiftView)
            {
                AGiftRow GiftRow = (AGiftRow)rv.Row;

                // this will be true for gift reversals for which we do not need a receipt
                if (GiftRow.ReceiptPrinted)
                {
                    continue;
                }

                bool ReceiptEachGift;
                String ReceiptLetterFrequency;
                bool EmailGiftStatement;
                bool AnonymousDonor;

                TRemote.MPartner.Partner.ServerLookups.WebConnectors.GetPartnerReceiptingInfo(
                    GiftRow.DonorKey,
                    out ReceiptEachGift,
                    out ReceiptLetterFrequency,
                    out EmailGiftStatement,
                    out AnonymousDonor);

                if (ReceiptEachGift)
                {
                    // I want to print a receipt for this gift,
                    // but if there's already one queued for this donor,
                    // I'll add this gift onto the existing receipt.

                    if (!GiftsPerDonor.ContainsKey(GiftRow.DonorKey))
                    {
                        GiftsPerDonor.Add(GiftRow.DonorKey, new AGiftTable());
                    }

                    AGiftRow NewRow = GiftsPerDonor[GiftRow.DonorKey].NewRowTyped();
                    DataUtilities.CopyAllColumnValues(GiftRow, NewRow);
                    GiftsPerDonor[GiftRow.DonorKey].Rows.Add(NewRow);
                }  // if receipt required
            } // foreach gift

            if (GiftsPerDonor.Count == 0) // no receipts needed
            {
                return;
            }

            String HtmlDoc = "";

            OpenFileDialog DialogOpen = new OpenFileDialog();

            if (Directory.Exists(TAppSettingsManager.GetValue("Formletters.Path")))
            {
                DialogOpen.InitialDirectory = TAppSettingsManager.GetValue("Formletters.Path");
            }

            DialogOpen.Filter = Catalog.GetString("HTML file (*.html)|*.html;*.htm");
            DialogOpen.RestoreDirectory = true;
            DialogOpen.Title = Catalog.GetString("Select the template for the gift receipt");

            if (DialogOpen.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            string HTMLTemplateFilename = DialogOpen.FileName;
            int NumberOfDonors = 0;

            foreach (Int64 DonorKey in GiftsPerDonor.Keys)
            {
                String DonorShortName;
                TPartnerClass DonorClass;
                TRemote.MPartner.Partner.ServerLookups.WebConnectors.GetPartnerShortName(DonorKey, out DonorShortName, out DonorClass);
                DonorShortName = Calculations.FormatShortName(DonorShortName, eShortNameFormat.eReverseShortname);

                string HtmlPage = TRemote.MFinance.Gift.WebConnectors.PrintGiftReceipt(
                    GiftBatchRow.CurrencyCode,
                    DonorShortName,
                    DonorKey,
                    DonorClass,
                    GiftsPerDonor[DonorKey],
                    HTMLTemplateFilename
                    );

                TFormLettersTools.AttachNextPage(ref HtmlDoc, HtmlPage);
                ReceiptedDonorsList += (DonorShortName + "\r\n");
                NumberOfDonors++;

                foreach (AGiftRow GiftRow in GiftsPerDonor[DonorKey].Rows)
                {
                    ReceiptedGiftTransactions.Add(GiftRow.GiftTransactionNumber);
                }
            }

            TFormLettersTools.CloseDocument(ref HtmlDoc);

            if (ReceiptedGiftTransactions.Count > 0)
            {
                TFrmReceiptControl.PreviewOrPrint(HtmlDoc);

                string Message = Catalog.GetPluralString("Was a receipt to the following donor printed correctly?",
                    "Were receipts to the following donors printed correctly?", NumberOfDonors);

                if (MessageBox.Show(
                        Message + "\n\n" +
                        ReceiptedDonorsList,
                        Catalog.GetString("Receipt Printing"),
                        MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    foreach (Int32 Trans in ReceiptedGiftTransactions)
                    {
                        TRemote.MFinance.Gift.WebConnectors.MarkReceiptsPrinted(
                            GiftBatchRow.LedgerNumber,
                            GiftBatchRow.BatchNumber,
                            Trans);
                    }
                }
            }
        }
Exemplo n.º 50
0
        public static GiftBatchTDS LoadAGiftBatchForYearPeriod(Int32 ALedgerNumber, Int32 AYear, Int32 APeriod)
        {
            #region Validate Arguments

            if (ALedgerNumber <= 0)
            {
                throw new EFinanceSystemInvalidLedgerNumberException(String.Format(Catalog.GetString(
                            "Function:{0} - The Ledger number must be greater than 0!"),
                        Utilities.GetMethodName(true)), ALedgerNumber);
            }

            #endregion Validate Arguments

            string FilterByPeriod = string.Empty;

            GiftBatchTDS MainDS = new GiftBatchTDS();

            TDBTransaction Transaction = null;

            try
            {
                DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum,
                    ref Transaction,
                    delegate
                    {
                        //Load Ledger table
                        ALedgerAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, Transaction);

                        #region Validate Data

                        if ((MainDS.ALedger == null) || (MainDS.ALedger.Count == 0))
                        {
                            throw new EFinanceSystemDataTableReturnedNoDataException(String.Format(Catalog.GetString(
                                        "Function:{0} - Details for Ledger {1} could not be accessed!"), Utilities.GetMethodSignature(),
                                    ALedgerNumber));
                        }

                        #endregion Validate Data

                        if (AYear > -1)
                        {
                            FilterByPeriod = String.Format(" AND PUB_{0}.{1} = {2}",
                                AGiftBatchTable.GetTableDBName(),
                                AGiftBatchTable.GetBatchYearDBName(),
                                AYear);

                            if ((APeriod == 0) && (AYear == MainDS.ALedger[0].CurrentFinancialYear))
                            {
                                //Return current and forwarding periods
                                FilterByPeriod += String.Format(" AND PUB_{0}.{1} >= {2}",
                                    AGiftBatchTable.GetTableDBName(),
                                    AGiftBatchTable.GetBatchPeriodDBName(),
                                    MainDS.ALedger[0].CurrentPeriod);
                            }
                            else if (APeriod > 0)
                            {
                                //Return only specified period
                                FilterByPeriod += String.Format(" AND PUB_{0}.{1} = {2}",
                                    AGiftBatchTable.GetTableDBName(),
                                    AGiftBatchTable.GetBatchPeriodDBName(),
                                    APeriod);
                            }
                            else
                            {
                                //Nothing to add, returns all periods
                            }
                        }

                        string SelectClause =
                            String.Format("SELECT * FROM PUB_{0} WHERE {1} = {2}",
                                AGiftBatchTable.GetTableDBName(),
                                AGiftBatchTable.GetLedgerNumberDBName(),
                                ALedgerNumber);

                        DBAccess.GDBAccessObj.Select(MainDS, SelectClause + FilterByPeriod,
                            MainDS.AGiftBatch.TableName, Transaction);
                    });

                MainDS.AcceptChanges();
            }
            catch (Exception ex)
            {
                TLogging.Log(String.Format("Method:{0} - Unexpected error!{1}{1}{2}",
                        Utilities.GetMethodSignature(),
                        Environment.NewLine,
                        ex.Message));
                throw ex;
            }

            return MainDS;
        }
Exemplo n.º 51
0
        public static GiftBatchTDS LoadAGiftBatchesForCurrentYearPeriod(Int32 ALedgerNumber)
        {
            #region Validate Arguments

            if (ALedgerNumber <= 0)
            {
                throw new EFinanceSystemInvalidLedgerNumberException(String.Format(Catalog.GetString(
                            "Function:{0} - The Ledger number must be greater than 0!"),
                        Utilities.GetMethodName(true)), ALedgerNumber);
            }

            #endregion Validate Arguments

            GiftBatchTDS MainDS = new GiftBatchTDS();

            TDBTransaction Transaction = null;

            try
            {
                DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum,
                    ref Transaction,
                    delegate
                    {
                        ALedgerAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, Transaction);

                        #region Validate Data

                        if ((MainDS.ALedger == null) || (MainDS.ALedger.Count == 0))
                        {
                            throw new EFinanceSystemDataTableReturnedNoDataException(String.Format(Catalog.GetString(
                                        "Function:{0} - Ledger data for Ledger number {1} does not exist or could not be accessed!"),
                                    Utilities.GetMethodName(true),
                                    ALedgerNumber));
                        }

                        #endregion Validate Data

                        string SelectClause = String.Format("SELECT * FROM PUB_{0} WHERE {1} = {2} AND PUB_{0}.{3} = {4} AND PUB_{0}.{5} >= {6}",
                            AGiftBatchTable.GetTableDBName(),
                            AGiftBatchTable.GetLedgerNumberDBName(),
                            ALedgerNumber,
                            AGiftBatchTable.GetBatchYearDBName(),
                            MainDS.ALedger[0].CurrentFinancialYear,
                            AGiftBatchTable.GetBatchPeriodDBName(),
                            MainDS.ALedger[0].CurrentPeriod);

                        DBAccess.GDBAccessObj.Select(MainDS, SelectClause, MainDS.AGiftBatch.TableName, Transaction);
                    });

                MainDS.AcceptChanges();
            }
            catch (Exception ex)
            {
                TLogging.Log(String.Format("Method:{0} - Unexpected error!{1}{1}{2}",
                        Utilities.GetMethodSignature(),
                        Environment.NewLine,
                        ex.Message));
                throw ex;
            }

            return MainDS;
        }
Exemplo n.º 52
0
        public static GiftBatchTDS CreateAGiftBatch(Int32 ALedgerNumber, DateTime ADateEffective, string ABatchDescription)
        {
            #region Validate Arguments

            if (ALedgerNumber <= 0)
            {
                throw new EFinanceSystemInvalidLedgerNumberException(String.Format(Catalog.GetString(
                            "Function:{0} - The Ledger number must be greater than 0!"),
                        Utilities.GetMethodName(true)), ALedgerNumber);
            }

            #endregion Validate Arguments

            GiftBatchTDS MainDS = new GiftBatchTDS();

            TDBTransaction Transaction = null;
            bool SubmissionOK = false;

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

                        #region Validate Data

                        if ((ledgerTable == null) || (ledgerTable.Count == 0))
                        {
                            throw new EFinanceSystemDataTableReturnedNoDataException(String.Format(Catalog.GetString(
                                        "Function:{0} - Ledger data for Ledger number {1} does not exist or could not be accessed!"),
                                    Utilities.GetMethodName(true),
                                    ALedgerNumber));
                        }

                        #endregion Validate Data

                        TGiftBatchFunctions.CreateANewGiftBatchRow(ref MainDS, ref Transaction, ref ledgerTable, ALedgerNumber, ADateEffective);

                        if (ABatchDescription.Length > 0)
                        {
                            MainDS.AGiftBatch[0].BatchDescription = ABatchDescription;
                        }

                        ALedgerAccess.SubmitChanges(ledgerTable, Transaction);
                        AGiftBatchAccess.SubmitChanges(MainDS.AGiftBatch, Transaction);
                        MainDS.AGiftBatch.AcceptChanges();

                        SubmissionOK = true;
                    });
            }
            catch (Exception ex)
            {
                TLogging.Log(String.Format("Method:{0} - Unexpected error!{1}{1}{2}",
                        Utilities.GetMethodSignature(),
                        Environment.NewLine,
                        ex.Message));
                throw ex;
            }

            return MainDS;
        }
Exemplo n.º 53
0
        // This manual method lets us peek at the data that is about to be saved...
        // The data has already been collected from the contols and validated and there is definitely something to save...
        private TSubmitChangesResult StoreManualCode(ref GiftBatchTDS SubmitDS, out TVerificationResultCollection VerificationResult)
        {
            FLatestSaveIncludedForex = false;

            if (SubmitDS.AGiftBatch != null)
            {
                // Check whether we are saving any rows that are in foreign currency
                foreach (AGiftBatchRow row in SubmitDS.AGiftBatch.Rows)
                {
                    if (row.CurrencyCode != FMainDS.ALedger[0].BaseCurrency)
                    {
                        FLatestSaveIncludedForex = true;
                        break;
                    }
                }
            }

            // Now do the standard call to save the changes
            return TRemote.MFinance.Gift.WebConnectors.SaveGiftBatchTDS(ref SubmitDS, out VerificationResult);
        }
Exemplo n.º 54
0
        /// <summary>
        /// export all the Data of the batches matching the parameters to a String
        /// </summary>
        /// <param name="requestParams">Hashtable containing the given params </param>
        /// <param name="exportString">Big parts of the export file as a simple String</param>
        /// <param name="AMessages">Additional messages to display in a messagebox</param>
        /// <returns>number of exported batches</returns>
        public Int32 ExportAllGiftBatchData(
            Hashtable requestParams,
            out String exportString,
            out TVerificationResultCollection AMessages)
        {
            FStringWriter = new StringWriter();
            FMainDS = new GiftBatchTDS();
            FDelimiter = (String)requestParams["Delimiter"];
            FLedgerNumber = (Int32)requestParams["ALedgerNumber"];
            FDateFormatString = (String)requestParams["DateFormatString"];
            bool Summary = (bool)requestParams["Summary"];

            FUseBaseCurrency = (bool)requestParams["bUseBaseCurrency"];
            FDateForSummary = (DateTime)requestParams["DateForSummary"];
            String NumberFormat = (String)requestParams["NumberFormat"];
            FCultureInfo = new CultureInfo(NumberFormat.Equals("American") ? "en-US" : "de-DE");
            FTransactionsOnly = (bool)requestParams["TransactionsOnly"];
            FExtraColumns = (bool)requestParams["ExtraColumns"];

            FTransaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.ReadCommitted);

            TProgressTracker.InitProgressTracker(DomainManager.GClientID.ToString(),
                Catalog.GetString("Exporting Gift Batches"), 100);

            TProgressTracker.SetCurrentState(DomainManager.GClientID.ToString(),
                Catalog.GetString("Retrieving records"),
                5);

            try
            {
                ALedgerAccess.LoadByPrimaryKey(FMainDS, FLedgerNumber, FTransaction);

                List <OdbcParameter>parameters = new List <OdbcParameter>();

                SortedList <String, String>SQLCommandDefines = new SortedList <string, string>();

                if ((bool)requestParams["IncludeUnposted"])
                {
                    SQLCommandDefines.Add("INCLUDEUNPOSTED", string.Empty);
                }

                OdbcParameter param = new OdbcParameter("LedgerNumber", OdbcType.Int);
                param.Value = FLedgerNumber;
                parameters.Add(param);

                Int64 recipientNumber = (Int64)requestParams["RecipientNumber"];
                Int64 fieldNumber = (Int64)requestParams["FieldNumber"];

                if (recipientNumber != 0)
                {
                    SQLCommandDefines.Add("BYRECIPIENT", string.Empty);
                    param = new OdbcParameter("RecipientNumber", OdbcType.Int);
                    param.Value = recipientNumber;
                    parameters.Add(param);
                }

                if (fieldNumber != 0)
                {
                    SQLCommandDefines.Add("BYFIELD", string.Empty);
                    param = new OdbcParameter("fieldNumber", OdbcType.Int);
                    param.Value = fieldNumber;
                    parameters.Add(param);
                }

                if (requestParams.ContainsKey("BatchNumberStart"))
                {
                    SQLCommandDefines.Add("BYBATCHNUMBER", string.Empty);
                    param = new OdbcParameter("BatchNumberStart", OdbcType.Int);
                    param.Value = (Int32)requestParams["BatchNumberStart"];
                    parameters.Add(param);
                    param = new OdbcParameter("BatchNumberEnd", OdbcType.Int);
                    param.Value = (Int32)requestParams["BatchNumberEnd"];
                    parameters.Add(param);
                }
                else
                {
                    SQLCommandDefines.Add("BYDATERANGE", string.Empty);
                    param = new OdbcParameter("BatchDateFrom", OdbcType.DateTime);
                    param.Value = (DateTime)requestParams["BatchDateFrom"];
                    parameters.Add(param);
                    param = new OdbcParameter("BatchDateTo", OdbcType.DateTime);
                    param.Value = (DateTime)requestParams["BatchDateTo"];
                    parameters.Add(param);
                }

                string sqlStatement = TDataBase.ReadSqlFile("Gift.GetGiftsToExport.sql", SQLCommandDefines);

                DBAccess.GDBAccessObj.Select(FMainDS,
                    "SELECT DISTINCT PUB_a_gift_batch.* " + sqlStatement + " ORDER BY " + AGiftBatchTable.GetBatchNumberDBName(),
                    FMainDS.AGiftBatch.TableName,
                    FTransaction,
                    parameters.ToArray());

                TProgressTracker.SetCurrentState(DomainManager.GClientID.ToString(),
                    Catalog.GetString("Retrieving gift records"),
                    10);

                DBAccess.GDBAccessObj.Select(FMainDS,
                    "SELECT DISTINCT PUB_a_gift.* " + sqlStatement + " ORDER BY " + AGiftBatchTable.GetBatchNumberDBName() + ", " +
                    AGiftTable.GetGiftTransactionNumberDBName(),
                    FMainDS.AGift.TableName,
                    FTransaction,
                    parameters.ToArray());

                TProgressTracker.SetCurrentState(DomainManager.GClientID.ToString(),
                    Catalog.GetString("Retrieving gift detail records"),
                    15);

                DBAccess.GDBAccessObj.Select(FMainDS,
                    "SELECT DISTINCT PUB_a_gift_detail.* " + sqlStatement,
                    FMainDS.AGiftDetail.TableName,
                    FTransaction,
                    parameters.ToArray());
            }
            finally
            {
                DBAccess.GDBAccessObj.RollbackTransaction();
            }

            string BaseCurrency = FMainDS.ALedger[0].BaseCurrency;
            FCurrencyCode = BaseCurrency; // Depending on FUseBaseCurrency, this will be overwritten for each gift.

            SortedDictionary <String, AGiftSummaryRow>sdSummary = new SortedDictionary <String, AGiftSummaryRow>();

            UInt32 counter = 0;

            // TProgressTracker Variables
            UInt32 GiftCounter = 0;

            AGiftSummaryRow giftSummary = null;

            FMainDS.AGiftDetail.DefaultView.Sort =
                AGiftDetailTable.GetLedgerNumberDBName() + "," +
                AGiftDetailTable.GetBatchNumberDBName() + "," +
                AGiftDetailTable.GetGiftTransactionNumberDBName();

            foreach (AGiftBatchRow giftBatch in FMainDS.AGiftBatch.Rows)
            {
                TProgressTracker.SetCurrentState(DomainManager.GClientID.ToString(),
                    string.Format(Catalog.GetString("Batch {0}"), giftBatch.BatchNumber),
                    20);
                GiftCounter = 0;

                if (!FTransactionsOnly & !Summary)
                {
                    WriteGiftBatchLine(giftBatch);
                }

                foreach (AGiftRow gift in FMainDS.AGift.Rows)
                {
                    if (gift.BatchNumber.Equals(giftBatch.BatchNumber) && gift.LedgerNumber.Equals(giftBatch.LedgerNumber))
                    {
                        // Update progress tracker every 25 records
                        if (++GiftCounter % 25 == 0)
                        {
                            TProgressTracker.SetCurrentState(DomainManager.GClientID.ToString(),
                                string.Format(Catalog.GetString("Batch {0} - Exporting gifts"), giftBatch.BatchNumber),
                                (GiftCounter / 25 + 4) * 5 > 90 ? 90 : (GiftCounter / 25 + 4) * 5);
                        }

                        DataRowView[] selectedRowViews = FMainDS.AGiftDetail.DefaultView.FindRows(
                            new object[] { gift.LedgerNumber, gift.BatchNumber, gift.GiftTransactionNumber });

                        foreach (DataRowView rv in selectedRowViews)
                        {
                            AGiftDetailRow giftDetail = (AGiftDetailRow)rv.Row;

                            if (Summary)
                            {
                                FCurrencyCode = FUseBaseCurrency ? BaseCurrency : giftBatch.CurrencyCode;
                                decimal mapExchangeRateToBase = FUseBaseCurrency ? 1 : giftBatch.ExchangeRateToBase;


                                counter++;
                                String DictionaryKey = FCurrencyCode + ";" + giftBatch.BankCostCentre + ";" + giftBatch.BankAccountCode + ";" +
                                                       giftDetail.RecipientKey + ";" + giftDetail.MotivationGroupCode + ";" +
                                                       giftDetail.MotivationDetailCode;

                                if (sdSummary.TryGetValue(DictionaryKey, out giftSummary))
                                {
                                    giftSummary.GiftTransactionAmount += giftDetail.GiftTransactionAmount;
                                    giftSummary.GiftAmount += giftDetail.GiftAmount;
                                }
                                else
                                {
                                    giftSummary = new AGiftSummaryRow();

                                    /*
                                     * summary_data.a_transaction_currency_c = lv_stored_currency_c
                                     * summary_data.a_bank_cost_centre_c = a_gift_batch.a_bank_cost_centre_c
                                     * summary_data.a_bank_account_code_c = a_gift_batch.a_bank_account_code_c
                                     * summary_data.a_recipient_key_n = a_gift_detail.p_recipient_key_n
                                     * summary_data.a_motivation_group_code_c = a_gift_detail.a_motivation_group_code_c
                                     * summary_data.a_motivation_detail_code_c = a_gift_detail.a_motivation_detail_code_c
                                     * summary_data.a_exchange_rate_to_base_n = lv_exchange_rate_n
                                     * summary_data.a_gift_type_c = a_gift_batch.a_gift_type_c */
                                    giftSummary.CurrencyCode = FCurrencyCode;
                                    giftSummary.BankCostCentre = giftBatch.BankCostCentre;
                                    giftSummary.BankAccountCode = giftBatch.BankAccountCode;
                                    giftSummary.RecipientKey = giftDetail.RecipientKey;
                                    giftSummary.MotivationGroupCode = giftDetail.MotivationGroupCode;
                                    giftSummary.MotivationDetailCode = giftDetail.MotivationDetailCode;
                                    giftSummary.GiftTransactionAmount = giftDetail.GiftTransactionAmount;
                                    giftSummary.GiftAmount = giftDetail.GiftAmount;

                                    sdSummary.Add(DictionaryKey, giftSummary);
                                }

                                //overwrite always because we want to have the last
                                giftSummary.ExchangeRateToBase = mapExchangeRateToBase;
                            }
                            else  // not summary
                            {
                                WriteGiftLine(gift, giftDetail);
                            }
                        }
                    }
                }
            }

            if (Summary)
            {
                TProgressTracker.SetCurrentState(DomainManager.GClientID.ToString(),
                    Catalog.GetString("Export Summary"),
                    95);

                bool first = true;

                foreach (KeyValuePair <string, AGiftSummaryRow>kvp in sdSummary)
                {
                    if (!FTransactionsOnly && first)
                    {
                        WriteGiftBatchSummaryLine(kvp.Value);
                        first = false;
                    }

                    WriteGiftSummaryLine(kvp.Value);
                }
            }

            TProgressTracker.SetCurrentState(DomainManager.GClientID.ToString(),
                Catalog.GetString("Gift batch export successful"),
                100);

            TProgressTracker.FinishJob(DomainManager.GClientID.ToString());

            exportString = FStringWriter.ToString();
            AMessages = FMessages;
            return FMainDS.AGiftBatch.Count;
        }
Exemplo n.º 55
0
        private static Int64 GetRecipientFundNumberInner(GiftBatchTDS AMainDS, Int64 APartnerKey, DateTime? AGiftDate = null)
        {
            #region Validate Arguments

            if (AMainDS == null)
            {
                throw new EFinanceSystemDataObjectNullOrEmptyException(String.Format(Catalog.GetString(
                            "Function:{0} - The Gift Batch dataset is null!"),
                        Utilities.GetMethodName(true)));
            }
            else if (APartnerKey < 0)
            {
                throw new ArgumentException(String.Format(Catalog.GetString("Function:{0} - The Partner Key must be greater than 0!"),
                        Utilities.GetMethodName(true)));
            }

            #endregion Validate Arguments

            TDBTransaction Transaction = null;

            if (APartnerKey == 0)
            {
                return 0;
            }

            //Look in RecipientFamily table
            PFamilyRow FamilyRow = (PFamilyRow)AMainDS.RecipientFamily.Rows.Find(APartnerKey);

            if (FamilyRow != null)
            {
                return GetGiftDestinationForRecipient(APartnerKey, AGiftDate);
            }

            //Look in RecipientPerson table
            PPersonRow PersonRow = (PPersonRow)AMainDS.RecipientPerson.Rows.Find(APartnerKey);

            if (PersonRow != null)
            {
                return GetGiftDestinationForRecipient(PersonRow.FamilyKey, AGiftDate);
            }

            //Check that LedgerPartnertypes are already loaded
            if ((AMainDS.LedgerPartnerTypes != null) && (AMainDS.LedgerPartnerTypes.Count == 0))
            {
                PPartnerTypeTable PPTTable = null;

                DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                    TEnforceIsolationLevel.eilMinimum,
                    ref Transaction,
                    delegate
                    {
                        PPTTable = PPartnerTypeAccess.LoadViaPType(MPartnerConstants.PARTNERTYPE_LEDGER, Transaction);

                        #region Validate Data

                        if ((PPTTable == null) || (PPTTable.Count == 0))
                        {
                            throw new EFinanceSystemDataTableReturnedNoDataException(String.Format(Catalog.GetString(
                                        "Function:{0} - Ledger Partner Types data does not exist or could not be accessed!"),
                                    Utilities.GetMethodName(true)));
                        }

                        #endregion Validate Data
                    });

                AMainDS.LedgerPartnerTypes.Merge(PPTTable);
            }

            if ((AMainDS.LedgerPartnerTypes != null)
                && (AMainDS.LedgerPartnerTypes.Rows.Find(new object[] { APartnerKey, MPartnerConstants.PARTNERTYPE_LEDGER }) != null))
            {
                //TODO Warning on inactive Fund from p_partner table
                return APartnerKey;
            }

            UmUnitStructureTable UnitStructTbl = null;

            DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                TEnforceIsolationLevel.eilMinimum,
                ref Transaction,
                delegate
                {
                    UnitStructTbl = UmUnitStructureAccess.LoadViaPUnitChildUnitKey(APartnerKey, Transaction);
                });

            if ((UnitStructTbl != null) && (UnitStructTbl.Rows.Count > 0))
            {
                UmUnitStructureRow structureRow = UnitStructTbl[0];

                if (structureRow.ParentUnitKey == structureRow.ChildUnitKey)
                {
                    // should not get here
                    TLogging.Log("GetRecipientFundNumberInner: - should not get here");
                    return 0;
                }

                // recursive call until we find a partner that has partnertype LEDGER
                return GetRecipientFundNumberInner(AMainDS, structureRow.ParentUnitKey);
            }
            else
            {
                return APartnerKey;
            }
        }
Exemplo n.º 56
0
        public static Int64 GetRecipientFundNumber(Int64 APartnerKey, DateTime? AGiftDate = null)
        {
            #region Validate Arguments

            if (APartnerKey < 0)
            {
                throw new ArgumentException(String.Format(Catalog.GetString("Function:{0} - The Partner Key cannot be negative!"),
                        Utilities.GetMethodName(true)));
            }

            #endregion Validate Arguments

            bool DataLoaded = false;

            GiftBatchTDS MainDS = new GiftBatchTDS();

            TDBTransaction Transaction = null;

            try
            {
                DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                    TEnforceIsolationLevel.eilMinimum,
                    ref Transaction,
                    delegate
                    {
                        MainDS.LedgerPartnerTypes.Merge(PPartnerTypeAccess.LoadViaPType(MPartnerConstants.PARTNERTYPE_LEDGER, Transaction));
                        MainDS.RecipientPartners.Merge(PPartnerAccess.LoadByPrimaryKey(APartnerKey, Transaction));
                        MainDS.RecipientFamily.Merge(PFamilyAccess.LoadByPrimaryKey(APartnerKey, Transaction));
                        MainDS.RecipientPerson.Merge(PPersonAccess.LoadByPrimaryKey(APartnerKey, Transaction));
                        MainDS.RecipientUnit.Merge(PUnitAccess.LoadByPrimaryKey(APartnerKey, Transaction));

                        #region Validate Data

                        if ((MainDS.LedgerPartnerTypes == null) || (MainDS.LedgerPartnerTypes.Count == 0))
                        {
                            throw new EFinanceSystemDataTableReturnedNoDataException(String.Format(Catalog.GetString(
                                        "Function:{0} - Ledger Partner Types data does not exist or could not be accessed!"),
                                    Utilities.GetMethodName(true)));
                        }
                        else if ((MainDS.RecipientPartners == null) || (MainDS.RecipientPartners.Count == 0))
                        {
                            throw new EFinanceSystemDataTableReturnedNoDataException(String.Format(Catalog.GetString(
                                        "Function:{0} - Recipient data for Partner Key {1} does not exist or could not be accessed!"),
                                    Utilities.GetMethodName(true),
                                    APartnerKey));
                        }

                        #endregion Validate Data

                        DataLoaded = true;
                    });
            }
            catch (Exception ex)
            {
                TLogging.Log(String.Format("Method:{0} - Unexpected error!{1}{1}{2}",
                        Utilities.GetMethodSignature(),
                        Environment.NewLine,
                        ex.Message));
                throw ex;
            }

            if (DataLoaded)
            {
                return GetRecipientFundNumberInner(MainDS, APartnerKey, AGiftDate);
            }
            else
            {
                return 0;
            }
        }
Exemplo n.º 57
0
        /// <summary>
        /// create a new batch with a consecutive batch number in the ledger
        /// for call inside a server function
        /// for performance reasons submitting (save the data in the database) is done later (not here)
        /// </summary>
        /// <param name="MainDS"></param>
        /// <param name="Transaction"></param>
        /// <param name="LedgerTable"></param>
        /// <param name="ALedgerNumber"></param>
        /// <returns>the new gift batch row</returns>
        public static ARecurringGiftBatchRow CreateANewRecurringGiftBatchRow(ref GiftBatchTDS MainDS,
            ref TDBTransaction Transaction,
            ref ALedgerTable LedgerTable,
            Int32 ALedgerNumber)
        {
            GiftBatchTDS Temp = new GiftBatchTDS();

            ARecurringGiftBatchAccess.LoadViaALedger(Temp, LedgerTable[0].LedgerNumber, Transaction);

            DataView RecurringGiftBatchDV = new DataView(Temp.ARecurringGiftBatch);
            RecurringGiftBatchDV.RowFilter = string.Empty;
            RecurringGiftBatchDV.Sort = string.Format("{0} DESC",
                ARecurringGiftBatchTable.GetBatchNumberDBName());

            //Recurring batch numbers can be reused so check each time for current highest number
            if (RecurringGiftBatchDV.Count > 0)
            {
                LedgerTable[0].LastRecGiftBatchNumber = (int)(RecurringGiftBatchDV[0][ARecurringGiftBatchTable.GetBatchNumberDBName()]);
            }
            else
            {
                LedgerTable[0].LastRecGiftBatchNumber = 0;
            }

            ARecurringGiftBatchRow NewRow = MainDS.ARecurringGiftBatch.NewRowTyped(true);

            NewRow.LedgerNumber = ALedgerNumber;
            NewRow.BatchNumber = ++LedgerTable[0].LastRecGiftBatchNumber;
            NewRow.BatchDescription = Catalog.GetString("Please enter recurring batch description");
            NewRow.BankAccountCode = TLedgerInfo.GetDefaultBankAccount(ALedgerNumber);
            NewRow.BankCostCentre = TLedgerInfo.GetStandardCostCentre(ALedgerNumber);
            NewRow.CurrencyCode = LedgerTable[0].BaseCurrency;
            MainDS.ARecurringGiftBatch.Rows.Add(NewRow);
            return NewRow;
        }
Exemplo n.º 58
0
        public static bool GetGiftsForTaxDeductiblePctAdjustment(ref GiftBatchTDS AGiftDS,
            Int64 ARecipientKey,
            DateTime ADateFrom,
            decimal ANewPct,
            out TVerificationResultCollection AMessages)
        {
            TDBTransaction Transaction = null;
            GiftBatchTDS MainDS = new GiftBatchTDS();

            AMessages = new TVerificationResultCollection();

            DBAccess.GDBAccessObj.BeginAutoReadTransaction(IsolationLevel.ReadCommitted, 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") + "'";

                    DBAccess.GDBAccessObj.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);
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="ALedgerNumber">Ledger number</param>
        /// <param name="AMainDS">The main data set</param>
        /// <param name="AFilterFindPanelObject">The filter panel control object</param>
        public TUC_GiftBatches_LoadAndFilter(int ALedgerNumber, GiftBatchTDS AMainDS, TFilterAndFindPanel AFilterFindPanelObject)
        {
            FLedgerNumber = ALedgerNumber;
            FMainDS = AMainDS;
            FFilterFindPanelObject = AFilterFindPanelObject;

            FrbtEditing = (RadioButton)AFilterFindPanelObject.FilterPanelControls.FindControlByName("rbtEditing");
            FrbtPosting = (RadioButton)AFilterFindPanelObject.FilterPanelControls.FindControlByName("rbtPosting");
            FrbtAll = (RadioButton)AFilterFindPanelObject.FilterPanelControls.FindControlByName("rbtAll");
            FcmbYearEnding = (TCmbAutoComplete)AFilterFindPanelObject.FilterPanelControls.FindControlByName("cmbYearEnding");
            FcmbPeriod = (TCmbAutoComplete)AFilterFindPanelObject.FilterPanelControls.FindControlByName("cmbPeriod");

            FMainDS.AGiftBatch.DefaultView.Sort = String.Format("{0}, {1} DESC",
                AGiftBatchTable.GetLedgerNumberDBName(),
                AGiftBatchTable.GetBatchNumberDBName()
                );

            // Populate the Year ComboBox with available years for the specified ledger
            TFinanceControls.InitialiseAvailableGiftYearsList(ref FcmbYearEnding, FLedgerNumber);
            //TLogging.Log("Gift Years completed");

            // Ensure that we start with the status set to 'editing'.
            FrbtEditing.Checked = true;
            //TLogging.Log("Editing checkbox selected");
        }
Exemplo n.º 60
0
        public static GiftBatchTDS LoadALedgerTable(Int32 ALedgerNumber)
        {
            #region Validate Arguments

            if (ALedgerNumber <= 0)
            {
                throw new EFinanceSystemInvalidLedgerNumberException(String.Format(Catalog.GetString(
                            "Function:{0} - The Ledger number must be greater than 0!"),
                        Utilities.GetMethodName(true)), ALedgerNumber);
            }

            #endregion Validate Arguments

            GiftBatchTDS MainDS = new GiftBatchTDS();

            TDBTransaction Transaction = null;

            try
            {
                DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum,
                    ref Transaction,
                    delegate
                    {
                        ALedgerAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, Transaction);

                        #region Validate Data

                        if ((MainDS.ALedger == null) || (MainDS.ALedger.Count == 0))
                        {
                            throw new EFinanceSystemDataTableReturnedNoDataException(String.Format(Catalog.GetString(
                                        "Function:{0} - Details for Ledger {1} could not be accessed!"), Utilities.GetMethodSignature(),
                                    ALedgerNumber));
                        }

                        #endregion Validate Data
                    });

                // Remove all Tables that were not filled with data before remoting them.
                MainDS.RemoveEmptyTables();

                // Accept row changes here so that the Client gets 'unmodified' rows
                MainDS.AcceptChanges();
            }
            catch (Exception ex)
            {
                TLogging.Log(String.Format("Method:{0} - Unexpected error!{1}{1}{2}",
                        Utilities.GetMethodSignature(),
                        Environment.NewLine,
                        ex.Message));
                throw ex;
            }

            return MainDS;
        }