private void RefreshBankAccountAndCostCentreFilters(bool AActiveOnly, ARecurringGiftBatchRow ARow = null)
        {
            if (FActiveOnly != AActiveOnly)
            {
                FActiveOnly = AActiveOnly;

                cmbDetailBankAccountCode.Filter = TFinanceControls.PrepareAccountFilter(true, false, AActiveOnly, true, "");
                cmbDetailBankCostCentre.Filter  = TFinanceControls.PrepareCostCentreFilter(true, false, AActiveOnly, true);

                if (ARow != null)
                {
                    cmbDetailBankCostCentre.SetSelectedString(ARow.BankCostCentre, -1);
                    cmbDetailBankAccountCode.SetSelectedString(ARow.BankAccountCode, -1);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Init the grid
        /// </summary>
        /// <param name="ALedgerNumber"></param>
        public void InitialiseCostCentreList(int ALedgerNumber)
        {
            FLedgerNumber = ALedgerNumber;

            TFinanceControls.InitialiseCostCentreList(ref clbCostCentres, ALedgerNumber, false, false, chkExcludeInactiveCostCentres.Checked, true);

            if (FCostCenterCodesDuringLoad.Length > 0)
            {
                clbCostCentres.SetCheckedStringList(FCostCenterCodesDuringLoad);
                FCostCenterCodesDuringLoad = "";
            }
            else
            {
                clbCostCentres.SetCheckedStringList("");
            }
        }
        private void ShowDataManual()
        {
            AccountsPayableTDSAApDocumentRow DocumentRow = FMainDS.AApDocument[0];

            FDocumentLedgerNumber = DocumentRow.LedgerNumber;

            // This will involve a trip to the server to access GLSetupTDS
            TFrmLedgerSettingsDialog settings = new TFrmLedgerSettingsDialog(this, FDocumentLedgerNumber);

            FRequireApprovalBeforePosting = settings.APRequiresApprovalBeforePosting;

            txtTotalAmount.CurrencyCode  = DocumentRow.CurrencyCode;
            txtDetailAmount.CurrencyCode = DocumentRow.CurrencyCode;
            dtpDateDue.Date = DocumentRow.DateIssued.AddDays(Convert.ToDouble(nudCreditTerms.Value));

            this.Text += " - " + TFinanceControls.GetLedgerNumberAndName(FDocumentLedgerNumber);

            FLedgerRow =
                ((ALedgerTable)TDataCache.TMFinance.GetCacheableFinanceTable(TCacheableFinanceTablesEnum.LedgerDetails, FDocumentLedgerNumber))[0];
            txtDetailBaseAmount.CurrencyCode = FLedgerRow.BaseCurrency;
            //txtExchangeRateToBase.SetControlProperties(10);

            //
            // If this document's currency is that of my own ledger,
            // I need to disable the rate of exchange field.
            if (DocumentRow.CurrencyCode == FLedgerRow.BaseCurrency)
            {
                txtExchangeRateToBase.Enabled = false;
                btnLookupExchangeRate.Enabled = false;
            }

            if ((FMainDS.AApDocumentDetail == null) || (FMainDS.AApDocumentDetail.Rows.Count == 0)) // When the document is new, I need to create the first detail line.
            {
                NewDetail(null, null);
            }

            FMainDS.AApDocumentDetail.DefaultView.Sort = AApDocumentDetailTable.GetDetailNumberDBName();

            // Create Text description of Anal Attribs for each DetailRow..
            foreach (AccountsPayableTDSAApDocumentDetailRow DetailRow in FMainDS.AApDocumentDetail.Rows)
            {
                UpdateAttributeLabel(DetailRow);
            }

            EnableControls();
        }
        /// <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_GLBatches_LoadAndFilter(int ALedgerNumber, GLBatchTDS AMainDS, TFilterAndFindPanel AFilterFindPanelObject)
        {
            FFilterFindPanelObject = AFilterFindPanelObject;
            FMainDS       = AMainDS;
            FLedgerNumber = ALedgerNumber;

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

            TFinanceControls.InitialiseAvailableFinancialYearsList(ref FcmbYearEnding, FLedgerNumber, false, true);
            //TLogging.Log("GL Financial Years completed");
            FrbtEditing.Checked = true;
            //TLogging.Log("Editing checkbox selected");
        }
Exemplo n.º 5
0
        /// <summary>
        /// show ledger and batch number
        /// </summary>
        private void ShowDataManual()
        {
            if (FLedgerNumber != -1)
            {
                txtLedgerNumber.Text = TFinanceControls.GetLedgerNumberAndName(FLedgerNumber);
                txtBatchNumber.Text  = FBatchNumber.ToString();
            }

            if (FPreviouslySelectedDetailRow != null)
            {
                txtDebit.NumberValueDecimal   = FPreviouslySelectedDetailRow.JournalDebitTotal;
                txtCredit.NumberValueDecimal  = FPreviouslySelectedDetailRow.JournalCreditTotal;
                txtControl.NumberValueDecimal =
                    FPreviouslySelectedDetailRow.JournalDebitTotal -
                    FPreviouslySelectedDetailRow.JournalCreditTotal;
            }
        }
Exemplo n.º 6
0
        private void RunOnceOnActivationManual()
        {
            //Setup Cost Centre combo
            TFinanceControls.InitialiseLocalCostCentreList(ref cmbCostCentre, FLedgerNumber, false, FLocalCostCentres);
            cmbCostCentre.Width = 300;
            cmbCostCentre.AttachedLabel.Width = 150;

            //Setup Reports To combo
            TFinanceControls.InitialiseLocalCostCentreList(ref cmbReportsTo, FLedgerNumber, true, FLocalCostCentres);
            cmbReportsTo.Width = 300;
            cmbReportsTo.AttachedLabel.Width = 150;

            lblInvisible.Visible = false;

            FLinkedView           = new DataView(FPartnerCostCentreTbl);
            FLinkedView.RowFilter = "IsLinked <> '0'";
            FLinkedView.AllowNew  = false;

            FUnlinkedView           = new DataView(FPartnerCostCentreTbl);
            FUnlinkedView.RowFilter = "IsLinked = '0'";
            FUnlinkedView.AllowNew  = false;

            grdLinkedCCs.DataSource   = new DevAge.ComponentModel.BoundDataView(FLinkedView);
            grdUnlinkedCCs.DataSource = new DevAge.ComponentModel.BoundDataView(FUnlinkedView);

            grdLinkedCCs.Columns.Clear();
            grdLinkedCCs.AddTextColumn("Partner Name", FPartnerCostCentreTbl.Columns["ShortName"], 240);
            grdLinkedCCs.AddTextColumn("Partner Key", FPartnerCostCentreTbl.Columns["PartnerKey"], 90);
            grdLinkedCCs.AddTextColumn("Cost Centre", FPartnerCostCentreTbl.Columns["IsLinked"], 90);
            grdLinkedCCs.AddTextColumn("Reports To", FPartnerCostCentreTbl.Columns["ReportsTo"], 90);
            grdLinkedCCs.Selection.FocusRowEntered += new SourceGrid.RowEventHandler(grdLinkedCCs_Click);

            grdUnlinkedCCs.Columns.Clear();
            grdUnlinkedCCs.AddTextColumn("Partner Name", FPartnerCostCentreTbl.Columns["ShortName"], 240);
            grdUnlinkedCCs.AddTextColumn("Partner Key", FPartnerCostCentreTbl.Columns["PartnerKey"], 90);
            grdUnlinkedCCs.Enter += new EventHandler(grdUnlinkedCCs_Enter);
            grdUnlinkedCCs.Selection.FocusRowEntered += new SourceGrid.RowEventHandler(grdUnlinkedCCs_Click);

            btnLink.Text      = "\u25B2 Link";
            btnLink.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            btnLink.Enabled   = false;

            btnUnlink.Text      = "\u25BC Unlink";
            btnUnlink.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            btnUnlink.Enabled   = false;
        }
Exemplo n.º 7
0
        /// <summary>
        /// The screen has been shown
        /// </summary>
        private void RunOnceOnActivationManual()
        {
            FActiveTab = tpgLedger;

            // See if we were launched with an initial tab set??
            if (FInitialTab == "AP")
            {
                tabAllSettings.SelectedTab = tpgAccountsPayable;
                FActiveTab = tpgAccountsPayable;
            }

            ALedgerRow ledgerRow = (ALedgerRow)FMainDS.ALedger.Rows[0];

            this.Text = this.Text + String.Format(" - {0}", TFinanceControls.GetLedgerNumberAndName(ledgerRow.LedgerNumber));

            FPetraUtilsObject.DataSaved += new TDataSavedHandler(FPetraUtilsObject_DataSaved);
        }
Exemplo n.º 8
0
        private void SetupAccountAndCostCentreCombos(bool AActiveOnly = true, ARecurringGiftBatchRow ARow = null)
        {
            if (!FBatchLoaded || (FActiveOnly != AActiveOnly))
            {
                FActiveOnly = AActiveOnly;

                cmbDetailBankCostCentre.Clear();
                cmbDetailBankAccountCode.Clear();
                TFinanceControls.InitialiseAccountList(ref cmbDetailBankAccountCode, FLedgerNumber, true, false, AActiveOnly, true, true);
                TFinanceControls.InitialiseCostCentreList(ref cmbDetailBankCostCentre, FLedgerNumber, true, false, AActiveOnly, true, true);

                if (ARow != null)
                {
                    cmbDetailBankCostCentre.SetSelectedString(ARow.BankCostCentre, -1);
                    cmbDetailBankAccountCode.SetSelectedString(ARow.BankAccountCode, -1);
                }
            }
        }
        // populate the comboboxes
        private void SetupComboboxes()
        {
            TFinanceControls.InitialiseCostCentreList(ref cmbCostCentre, FLedgerNumber, true, false, false, false);
            cmbCostCentre.ColumnWidthCol2             = 300;
            cmbCostCentre.AttachedLabel.Width         = 280;
            cmbCostCentre.cmbCombobox.AllowBlankValue = true;

            TFinanceControls.InitialiseAccountList(ref cmbAccount, FLedgerNumber,
                                                   true, false, false, false, FCurrency, true);
            cmbAccount.ColumnWidthCol2             = 300;
            cmbAccount.AttachedLabel.Width         = 280;
            cmbAccount.cmbCombobox.AllowBlankValue = true;

            cmbStatus.AddStringItem(Catalog.GetString("All"));
            cmbStatus.AddStringItem(MFinanceConstants.BATCH_POSTED);
            cmbStatus.AddStringItem(MFinanceConstants.BATCH_UNPOSTED);
            cmbStatus.SelectedIndex = 0;
        }
Exemplo n.º 10
0
        /// <summary>
        /// Load the supplier and all the transactions (invoices and payments) that relate to it.
        /// </summary>
        /// <param name="ALedgerNumber"></param>
        /// <param name="APartnerKey"></param>
        public void LoadSupplier(Int32 ALedgerNumber, Int64 APartnerKey)
        {
            this.Cursor = Cursors.WaitCursor;

            FLedgerNumber = ALedgerNumber;
            FPartnerKey   = APartnerKey;
            FMainDS       = TRemote.MFinance.AP.WebConnectors.LoadAApSupplier(ALedgerNumber, APartnerKey);

            FSupplierRow = FMainDS.AApSupplier[0];

            // Get our AP ledger settings and enable/disable the corresponding search option on the filter panel
            TFrmLedgerSettingsDialog settings = new TFrmLedgerSettingsDialog(this, ALedgerNumber);

            FRequireApprovalBeforePosting = settings.APRequiresApprovalBeforePosting;
            Control rbtForApproval = FFilterAndFindObject.FilterPanelControls.FindControlByName("rbtForApproval");

            rbtForApproval.Enabled = FRequireApprovalBeforePosting;

            //
            // Transactions older than
            DateTime AgedOlderThan = DateTime.Now;

            if (!FSupplierRow.IsPreferredScreenDisplayNull())
            {
                AgedOlderThan = AgedOlderThan.AddMonths(0 - FSupplierRow.PreferredScreenDisplay);
            }

            FAgedOlderThan = AgedOlderThan.ToString("u");

            txtSupplierName.Text     = FMainDS.PPartner[0].PartnerShortName;
            txtSupplierCurrency.Text = FSupplierRow.CurrencyCode;
            FFindObject = TRemote.MFinance.AP.UIConnectors.Find();

            FFindObject.FindSupplierTransactions(FLedgerNumber, FPartnerKey);

            // Start thread that checks for the end of the search operation on the PetraServer
            FKeepUpSearchFinishedCheck = true;
            Thread FinishedCheckThread = new Thread(new ThreadStart(SearchFinishedCheckThread));

            FinishedCheckThread.Start();

            this.Text = Catalog.GetString("Supplier Transactions") + " - " + TFinanceControls.GetLedgerNumberAndName(FLedgerNumber);
        }
        private void ApplyMotivationDetailCodeFilter(out bool ADoTaxUpdate)
        {
            ADoTaxUpdate = false;

            //Refilter the combo with suppressed changes
            TFinanceControls.ChangeMotivationDetailListFilter(ref cmbMotivationDetailCode, FMotivationGroup, -1, FPetraUtilsObject);

            Int32 NumberOfFilteredMotivationDetails = cmbMotivationDetailCode.Count;

            if (FMotivationGroupChangedInProcess && (NumberOfFilteredMotivationDetails > 0))
            {
                //Highlight first item after refilter
                cmbMotivationDetailCode.SelectedIndex = 0;
                FMotivationDetail = cmbMotivationDetailCode.GetSelectedString();
                txtDetailMotivationDetailCode.Text = FMotivationDetail;
                txtMotivationDetailDesc.Text       = cmbMotivationDetailCode.GetSelectedDescription();
            }
            else if (NumberOfFilteredMotivationDetails > 0)
            {
                cmbMotivationDetailCode.SetSelectedString(FMotivationDetail, -1);
                txtMotivationDetailDesc.Text = cmbMotivationDetailCode.GetSelectedDescription();
                ADoTaxUpdate = false;
            }
            else
            {
                //No motivation details added to this motivation group as yet
                cmbMotivationDetailCode.SelectedIndex = -1;
                txtDetailMotivationDetailCode.Text    = string.Empty;
                txtMotivationDetailDesc.Text          = string.Empty;
                FMotivationDetail = string.Empty;
            }

            //The following code will handle an empty motivation details combo box
            DisplayMotivationDetailAccountCode();

            if ((txtDetailRecipientKey.Text == string.Empty) || (Convert.ToInt64(txtDetailRecipientKey.Text) == 0))
            {
                txtDetailRecipientKey.Text = String.Format("{0:0000000000}", 0);
                DisplayMotivationDetailCostCentreCode();
            }
        }
Exemplo n.º 12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ALedgerNumber"></param>
        /// <param name="ABatchNumber"></param>
        /// <param name="ABatchYear"></param>
        /// <param name="ABatchPeriod"></param>
        public void LoadOneBatch(Int32 ALedgerNumber, Int32 ABatchNumber, int ABatchYear, int ABatchPeriod)
        {
            FLedgerNumber = ALedgerNumber;
            InitialiseLogicObjects();

            FMainDS.Merge(ViewModeTDS);
            FPetraUtilsObject.SuppressChangeDetection = true;

            if (FLoadAndFilterLogicObject.BatchYear != ABatchYear)
            {
                FLoadAndFilterLogicObject.BatchYear = ABatchYear;
                FLoadAndFilterLogicObject.RefreshPeriods(ABatchYear);
            }

            FLoadAndFilterLogicObject.BatchPeriod = ABatchPeriod;
            FLoadAndFilterLogicObject.DisableYearAndPeriod(false);

            FMainDS.AGiftBatch.DefaultView.RowFilter =
                String.Format("{0}={1}", AGiftBatchTable.GetBatchNumberDBName(), ABatchNumber);
            Int32 RowToSelect = GetDataTableRowIndexByPrimaryKeys(ALedgerNumber, ABatchNumber);

            FAccountAndCostCentreLogicObject.RefreshBankAccountAndCostCentreData(FLoadAndFilterLogicObject);
            SetupExtraGridFunctionality();

            // if this form is readonly, then we need all codes, because old codes might have been used
            bool ActiveOnly = this.Enabled;

            SetupAccountAndCostCentreCombos(ActiveOnly);

            cmbDetailMethodOfPaymentCode.AddNotSetRow("", "");
            TFinanceControls.InitialiseMethodOfPaymentCodeList(ref cmbDetailMethodOfPaymentCode, ActiveOnly);

            SelectRowInGrid(RowToSelect);

            UpdateChangeableStatus();
            FPetraUtilsObject.HasChanges = false;
            FPetraUtilsObject.SuppressChangeDetection = false;
            FBatchLoaded = true;
        }
Exemplo n.º 13
0
        /// <summary>
        /// Gift Type radiobutton selection changed
        /// </summary>
        private void GiftTypeChanged(Object sender, EventArgs e)
        {
            bool BankAccountOnly = true;

            // show all accounts for 'Gift In Kind' and 'Other'
            if (rbtGiftInKind.Checked || rbtOther.Checked)
            {
                BankAccountOnly = false;
            }

            if (BankAccountOnly != FBankAccountOnly)
            {
                cmbDetailBankAccountCode.Clear();
                TFinanceControls.InitialiseAccountList(ref cmbDetailBankAccountCode,
                                                       FLedgerNumber,
                                                       true,
                                                       false,
                                                       FActiveOnly,
                                                       BankAccountOnly,
                                                       true,
                                                       FAccountTable);

                if (BankAccountOnly)
                {
                    lblDetailBankAccountCode.Text = Catalog.GetString("Bank Account:");
                }
                else
                {
                    lblDetailBankAccountCode.Text = Catalog.GetString("Account Code:");
                }

                FBankAccountOnly = BankAccountOnly;

                if (FPreviouslySelectedDetailRow != null)
                {
                    cmbDetailBankAccountCode.SetSelectedString(FPreviouslySelectedDetailRow.BankAccountCode, -1);
                }
            }
        }
        /// initialise some comboboxes
        private void BeforeShowDetailsManual(AApDocumentDetailRow ARow)
        {
            if (ARow == null)
            {
                return;
            }

            grdDetails.Columns[1].Width = pnlDetailGrid.Width - 380;   // It doesn't really work having these here -
            grdDetails.Columns[0].Width = 90;                          // there's something else that overrides these settings.
            grdDetails.Columns[2].Width = 200;
            grdDetails.Columns[3].Width = 90;

            // if this document was already posted, then we need all account and cost centre codes, because old codes might have been used
            bool ActiveOnly = ("|POSTED|PARTPAID|PAID|".IndexOf("|" + FMainDS.AApDocument[0].DocumentStatus) < 0);

            FPetraUtilsObject.SuppressChangeDetection = true;
            TFinanceControls.InitialiseAccountList(ref cmbDetailAccountCode, ARow.LedgerNumber, true, false, ActiveOnly, false);
            TFinanceControls.InitialiseCostCentreList(ref cmbDetailCostCentreCode, ARow.LedgerNumber, true, false, ActiveOnly, false);
            FPetraUtilsObject.SuppressChangeDetection = false;
            EnableControls();

            Decimal ExchangeRateToBase = 0;

            if (txtExchangeRateToBase.NumberValueDecimal.HasValue)
            {
                ExchangeRateToBase = txtExchangeRateToBase.NumberValueDecimal.Value;
            }

            if (ARow.IsAmountNull() || (ExchangeRateToBase == 0))
            {
                txtDetailBaseAmount.NumberValueDecimal = null;
            }
            else
            {
                decimal DetailAmount = Convert.ToDecimal(ARow.Amount);
                DetailAmount /= ExchangeRateToBase;
                txtDetailBaseAmount.NumberValueDecimal = DetailAmount;
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Init the grid
        /// </summary>
        private void InitialiseCostCentreList()
        {
            TFinanceControls.InitialiseCostCentreList(
                ref clbCostCentres,
                FLedgerNumber,
                true,  // postingonly
                false, // excludeposting
                chkExcludeInactiveCostCentres.Checked,
                rbtFields.Checked,
                rbtDepartments.Checked,
                rbtPersonalCostcentres.Checked);

            if (FCostCenterCodesDuringLoad.Length > 0)
            {
                clbCostCentres.SetCheckedStringList(FCostCenterCodesDuringLoad);
                FCostCenterCodesDuringLoad = "";
            }
            else
            {
                clbCostCentres.SetCheckedStringList("");
            }
        }
Exemplo n.º 16
0
        private void InitialiseLedgerControls()
        {
            // Load Motivation detail in this central place; it will be used by UC_GiftTransactions
            AMotivationDetailTable motivationDetail = (AMotivationDetailTable)TDataCache.TMFinance.GetCacheableFinanceTable(
                TCacheableFinanceTablesEnum.MotivationList,
                FLedgerNumber);

            motivationDetail.TableName = FMainDS.AMotivationDetail.TableName;
            FMainDS.Merge(motivationDetail);

            FMainDS.AcceptChanges();

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

            SetupExtraGridFunctionality();
            FAccountAndCostCentreLogicObject.RefreshBankAccountAndCostCentreData(FLoadAndFilterLogicObject);

            // if this form is readonly, then we need all codes, because old codes might have been used
            bool ActiveOnly = this.Enabled;

            SetupAccountAndCostCentreCombos(ActiveOnly);

            cmbDetailMethodOfPaymentCode.AddNotSetRow("", "");
            TFinanceControls.InitialiseMethodOfPaymentCodeList(ref cmbDetailMethodOfPaymentCode, ActiveOnly);

            TLedgerSelection.GetCurrentPostingRangeDates(FLedgerNumber,
                                                         out FStartDateCurrentPeriod,
                                                         out FEndDateLastForwardingPeriod,
                                                         out FDefaultDate);
            lblValidDateRange.Text = String.Format(Catalog.GetString("Valid between {0} and {1}"),
                                                   FStartDateCurrentPeriod.ToShortDateString(), FEndDateLastForwardingPeriod.ToShortDateString());

            FLoadAndFilterLogicObject.InitialiseDataSources(cmbDetailBankCostCentre, cmbDetailBankAccountCode);
        }
Exemplo n.º 17
0
        // populate the motivation detail and motivation group comboboxes
        private void SetupMotivationComboboxes()
        {
            TFinanceControls.InitialiseMotivationGroupList(ref cmbMotivationGroup, FLedgerNumber, false);
            DataRow BlankRow = cmbMotivationGroup.Table.NewRow();

            BlankRow["a_ledger_number_i"]                = FLedgerNumber;
            BlankRow["a_motivation_group_code_c"]        = "";
            BlankRow["a_motivation_group_description_c"] = Catalog.GetString("All groups");
            cmbMotivationGroup.Table.Rows.InsertAt(BlankRow, 0);
            cmbMotivationGroup.cmbCombobox.SelectedIndex   = 0;
            cmbMotivationGroup.ColumnWidthCol2             = 300;
            cmbMotivationGroup.cmbCombobox.SelectionLength = 0;

            TFinanceControls.InitialiseMotivationDetailList(ref cmbMotivationDetail, FLedgerNumber, false);
            BlankRow = cmbMotivationDetail.Table.NewRow();
            BlankRow["a_ledger_number_i"]          = FLedgerNumber;
            BlankRow["a_motivation_group_code_c"]  = "";
            BlankRow["a_motivation_detail_code_c"] = "";
            BlankRow["a_motivation_detail_desc_c"] = Catalog.GetString("All details");
            cmbMotivationDetail.Table.Rows.InsertAt(BlankRow, 0);
            cmbMotivationDetail.cmbCombobox.SelectedIndex   = 0;
            cmbMotivationDetail.ColumnWidthCol2             = 300;
            cmbMotivationDetail.cmbCombobox.SelectionLength = 0;
        }
        private void RunOnceOnActivationManual()
        {
            TRemote.MFinance.Setup.WebConnectors.LoadCostCentrePartnerLinks(FLedgerNumber, 0, out FPartnerCostCentreTbl);
            FLocalCostCentres = TRemote.MFinance.Setup.WebConnectors.LoadLocalCostCentres(FLedgerNumber);

            //Setup Cost Centre combo
            TFinanceControls.InitialiseLocalCostCentreList(ref cmbCostCentre, FLedgerNumber, false, FLocalCostCentres);
            cmbCostCentre.Width = 300;
            cmbCostCentre.AttachedLabel.Width = 150;

            //Setup Reports To combo
            TFinanceControls.InitialiseLocalCostCentreList(ref cmbReportsTo, FLedgerNumber, true, FLocalCostCentres);
            cmbReportsTo.Width = 300;
            cmbReportsTo.AttachedLabel.Width = 150;

            lblInvisible.Visible = false;

            FLinkedView           = new DataView(FPartnerCostCentreTbl);
            FLinkedView.RowFilter = "IsLinked <> '0'";
            FLinkedView.AllowNew  = false;

            FUnlinkedView           = new DataView(FPartnerCostCentreTbl);
            FUnlinkedView.RowFilter = "IsLinked = '0'";
            FUnlinkedView.AllowNew  = false;

            grdLinkedCCs.DataSource   = new DevAge.ComponentModel.BoundDataView(FLinkedView);
            grdUnlinkedCCs.DataSource = new DevAge.ComponentModel.BoundDataView(FUnlinkedView);

            grdLinkedCCs.Columns.Clear();
            grdLinkedCCs.AddTextColumn("Partner Name", FPartnerCostCentreTbl.Columns["ShortName"], 240);
            grdLinkedCCs.AddTextColumn("Partner Key", FPartnerCostCentreTbl.Columns["PartnerKey"], 90);
            grdLinkedCCs.AddTextColumn("Cost Centre", FPartnerCostCentreTbl.Columns["IsLinked"], 90);
            grdLinkedCCs.AddTextColumn("Reports To", FPartnerCostCentreTbl.Columns["ReportsTo"], 90);
            grdUnlinkedCCs.Enter += new EventHandler(grdLinkedCCs_Enter);
            grdLinkedCCs.Selection.FocusRowEntered += new SourceGrid.RowEventHandler(grdLinkedCCs_Click);

            grdUnlinkedCCs.Columns.Clear();
            grdUnlinkedCCs.AddTextColumn("Partner Name", FPartnerCostCentreTbl.Columns["ShortName"], 240);
            grdUnlinkedCCs.AddTextColumn("Partner Key", FPartnerCostCentreTbl.Columns["PartnerKey"], 90);
            grdUnlinkedCCs.Enter += new EventHandler(grdUnlinkedCCs_Enter);
            grdUnlinkedCCs.Selection.FocusRowEntered += new SourceGrid.RowEventHandler(grdUnlinkedCCs_Click);

            btnLink.Text      = "\u25B2 Link";
            btnLink.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            btnLink.Enabled   = false;

            btnUnlink.Text      = "\u25BC Unlink";
            btnUnlink.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            btnUnlink.Enabled   = false;

            btnRemove.Enabled = false;

            FPetraUtilsObject.ApplySecurity(TSecurityChecks.SecurityPermissionsSetupScreensEditingAndSaving);

            if (FPetraUtilsObject.SecurityReadOnly)
            {
                btnLink.Enabled   = false;
                btnUnlink.Enabled = false;
                btnRemove.Enabled = false;
            }
        }
        /// <summary>
        /// load the gifts into the grid
        /// </summary>
        /// <param name="ALedgerNumber"></param>
        /// <param name="ABatchNumber"></param>
        /// <param name="ABatchStatus"></param>
        /// <param name="AForceLoadFromServer">Set to true to get data from the server even though it is apparently the current batch number and status</param>
        /// <returns>True if gift transactions were loaded from server, false if transactions had been loaded already.</returns>
        public bool LoadGifts(Int32 ALedgerNumber, Int32 ABatchNumber, string ABatchStatus, bool AForceLoadFromServer = false)
        {
            //Set key flags
            bool FirstGiftTransLoad = (FLedgerNumber == -1);
            bool SameCurrentBatch   = ((FLedgerNumber == ALedgerNumber) &&
                                       (FBatchNumber == ABatchNumber) &&
                                       (FBatchStatus == ABatchStatus) &&
                                       !AForceLoadFromServer);

            FBatchRow = GetBatchRow();

            if ((FBatchRow == null) && (GetAnyBatchRow(ABatchNumber) == null))
            {
                MessageBox.Show(String.Format("Cannot load transactions for Gift Batch {0} as the batch is not currently loaded!",
                                              ABatchNumber));
                return(false);
            }

            //Set key values from Batch
            FLedgerNumber         = ALedgerNumber;
            FBatchNumber          = ABatchNumber;
            FBatchCurrencyCode    = FBatchRow.CurrencyCode;
            FBatchMethodOfPayment = FBatchRow.MethodOfPaymentCode;
            FBatchStatus          = ABatchStatus;
            FBatchUnpostedFlag    = (FBatchStatus == MFinanceConstants.BATCH_UNPOSTED);

            if (FirstGiftTransLoad)
            {
                InitialiseControls();
            }

            UpdateCurrencySymbols(FBatchCurrencyCode);

            //Check if the same batch is selected, so no need to apply filter
            if (SameCurrentBatch)
            {
                //Same as previously selected and we have not been asked to force a full refresh
                if (FBatchUnpostedFlag && (GetSelectedRowIndex() > 0))
                {
                    if (FGLEffectivePeriodHasChangedFlag)
                    {
                        //Just in case for the currently selected row, the date field has not been updated
                        FGLEffectivePeriodHasChangedFlag   = false;
                        GetSelectedDetailRow().DateEntered = FBatchRow.GlEffectiveDate;
                        dtpDateEntered.Date = FBatchRow.GlEffectiveDate;
                    }

                    GetDetailsFromControls(GetSelectedDetailRow());
                }

                UpdateControlsProtection();

                if (FBatchUnpostedFlag &&
                    ((FBatchCurrencyCode != FBatchRow.CurrencyCode) ||
                     (FBatchExchangeRateToBase != FBatchRow.ExchangeRateToBase)))
                {
                    UpdateBaseAmount(false);
                }

                return(false);
            }

            //New Batch
            FCurrentGiftInBatch = 0;

            //New set of transactions to be loaded
            TFrmStatusDialog dlgStatus = new TFrmStatusDialog(FPetraUtilsObject.GetForm());

            if (FShowStatusDialogOnLoadFlag == true)
            {
                dlgStatus.Show();
                FShowStatusDialogOnLoadFlag = false;
                dlgStatus.Heading           = String.Format(Catalog.GetString("Batch {0}"), ABatchNumber);
                dlgStatus.CurrentStatus     = Catalog.GetString("Loading transactions ...");
            }

            FGiftTransactionsLoadedFlag = false;
            FSuppressListChangedFlag    = false;

            //Apply new filter
            FPreviouslySelectedDetailRow = null;
            grdDetails.DataSource        = null;

            // if this form is readonly, then we need all codes, because old (inactive) codes might have been used
            if (FirstGiftTransLoad || (FActiveOnlyFlag == (ViewMode || !FBatchUnpostedFlag)))
            {
                FActiveOnlyFlag         = !(ViewMode || !FBatchUnpostedFlag);
                dlgStatus.CurrentStatus = Catalog.GetString("Initialising controls ...");

                try
                {
                    //Without this, the Save button enables even for Posted batches!
                    FPetraUtilsObject.SuppressChangeDetection = true;

                    TFinanceControls.InitialiseMotivationGroupList(ref cmbDetailMotivationGroupCode, FLedgerNumber, FActiveOnlyFlag);
                    TFinanceControls.InitialiseMotivationDetailList(ref cmbMotivationDetailCode, FLedgerNumber, FActiveOnlyFlag);
                    TFinanceControls.InitialiseMethodOfGivingCodeList(ref cmbDetailMethodOfGivingCode, FActiveOnlyFlag);
                    TFinanceControls.InitialiseMethodOfPaymentCodeList(ref cmbDetailMethodOfPaymentCode, FActiveOnlyFlag);
                    TFinanceControls.InitialisePMailingList(ref cmbDetailMailingCode, FActiveOnlyFlag);
                }
                finally
                {
                    FPetraUtilsObject.SuppressChangeDetection = false;
                }
            }

            // This sets the incomplete filter but does check the panel enabled state
            ShowData();

            // This sets the main part of the filter but excluding the additional items set by the user GUI
            // It gets the right sort order
            SetGiftDetailDefaultView();

            // only load from server if there are no transactions loaded yet for this batch
            // otherwise we would overwrite transactions that have already been modified
            if (FMainDS.AGiftDetail.DefaultView.Count == 0)
            {
                dlgStatus.CurrentStatus = Catalog.GetString("Requesting transactions from server ...");
                //Load all partners in Batch
                FMainDS.DonorPartners.Merge(TRemote.MFinance.Gift.WebConnectors.LoadAllPartnerDataForBatch(ALedgerNumber, ABatchNumber)); //LoadAllPartnerDataForBatch();
                //Include Donor fields
                LoadGiftDataForBatch(ALedgerNumber, ABatchNumber);
            }

            //Check if need to update batch period in each gift
            if (FBatchUnpostedFlag)
            {
                dlgStatus.CurrentStatus = Catalog.GetString("Updating batch period ...");
                ((TFrmGiftBatch)ParentForm).GetBatchControl().UpdateBatchPeriod();
            }

            // Now we set the full filter
            FFilterAndFindObject.ApplyFilter();
            UpdateRecordNumberDisplay();
            FFilterAndFindObject.SetRecordNumberDisplayProperties();

            SelectRowInGrid(1);

            UpdateControlsProtection();

            dlgStatus.CurrentStatus = Catalog.GetString("Updating totals for the batch ...");
            UpdateTotals();

            if ((FPreviouslySelectedDetailRow != null) && (FBatchUnpostedFlag))
            {
                bool disableSave = (FBatchRow.RowState == DataRowState.Unchanged && !FPetraUtilsObject.HasChanges);

                if (disableSave && FPetraUtilsObject.HasChanges && !DataUtilities.DataRowColumnsHaveChanged(FBatchRow))
                {
                    FPetraUtilsObject.DisableSaveButton();
                }
            }

            FGiftTransactionsLoadedFlag = true;
            dlgStatus.Close();

            return(true);
        }
        private void SetupMotivationComboboxes()
        {
            /* cmbMotivationGroup */

            TFinanceControls.InitialiseMotivationGroupList(ref cmbMotivationGroup, FLedgerNumber, false);

            // remove motivation groups that are not used in the results
            List <int> RemoveIndexes = new List <int>();

            for (int i = 0; i < cmbMotivationGroup.Table.Rows.Count; i++)
            {
                bool NotFound = true;

                foreach (DataRow DetailRow in FMainDS.Tables[TEMP_TABLE_NAME].Rows)
                {
                    if (cmbMotivationGroup.Table.Rows[i]["a_motivation_group_code_c"].ToString() == DetailRow["MotivationGroupCode"].ToString())
                    {
                        NotFound = false;
                        break;
                    }
                }

                if (NotFound)
                {
                    RemoveIndexes.Add(i);
                }
            }

            for (int i = RemoveIndexes.Count - 1; i >= 0; i--)
            {
                cmbMotivationGroup.Table.Rows.RemoveAt(RemoveIndexes[i]);
            }

            DataRow BlankRow = cmbMotivationGroup.Table.NewRow();

            BlankRow["a_ledger_number_i"]                = FLedgerNumber;
            BlankRow["a_motivation_group_code_c"]        = ALL;
            BlankRow["a_motivation_group_description_c"] = Catalog.GetString("All groups");
            cmbMotivationGroup.Table.Rows.InsertAt(BlankRow, 0);
            cmbMotivationGroup.cmbCombobox.SelectedIndex = 0;
            cmbMotivationGroup.ColumnWidthCol2           = 300;
            cmbMotivationGroup.Enabled = true;
            cmbMotivationGroup.cmbCombobox.SelectionLength = 0;

            /* cmbMotivationDetail */

            TFinanceControls.InitialiseMotivationDetailList(ref cmbMotivationDetail, FLedgerNumber, false);

            // remove motivation details that are not used in the results
            RemoveIndexes.Clear();

            for (int i = 0; i < cmbMotivationDetail.Table.Rows.Count; i++)
            {
                bool NotFound = true;

                foreach (DataRow DetailRow in FMainDS.Tables[TEMP_TABLE_NAME].Rows)
                {
                    if (cmbMotivationDetail.Table.Rows[i]["a_motivation_detail_code_c"].ToString() == DetailRow["MotivationDetailCode"].ToString())
                    {
                        NotFound = false;
                        break;
                    }
                }

                if (NotFound)
                {
                    RemoveIndexes.Add(i);
                }
            }

            for (int i = RemoveIndexes.Count - 1; i >= 0; i--)
            {
                cmbMotivationDetail.Table.Rows.RemoveAt(RemoveIndexes[i]);
            }

            BlankRow = cmbMotivationDetail.Table.NewRow();
            BlankRow["a_ledger_number_i"]          = FLedgerNumber;
            BlankRow["a_motivation_group_code_c"]  = "";
            BlankRow["a_motivation_detail_code_c"] = ALL;
            BlankRow["a_motivation_detail_desc_c"] = Catalog.GetString("All details");
            cmbMotivationDetail.Table.Rows.InsertAt(BlankRow, 0);
            cmbMotivationDetail.cmbCombobox.SelectedIndex = 0;
            cmbMotivationDetail.ColumnWidthCol2           = 300;
            cmbMotivationDetail.Enabled = true;
            cmbMotivationDetail.cmbCombobox.SelectionLength = 0;
        }
Exemplo n.º 21
0
        private void SetupTaxDeductibilityControls()
        {
            // increase the width of the screen from the default width (760)
            if (ClientSize.Width == 760)
            {
                ClientSize = new System.Drawing.Size(920, ClientSize.Height);
            }

            // new label
            Label lblAccounts = new Label();

            lblAccounts.Name      = "lblAccounts";
            lblAccounts.Location  = lblDetailAccountCode.Location;
            lblAccounts.Anchor    = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)));
            lblAccounts.Size      = lblDetailAccountCode.Size;
            lblAccounts.Text      = "Accounts:";
            lblAccounts.TextAlign = System.Drawing.ContentAlignment.TopRight;
            pnlDetails.Controls.Add(lblAccounts);

            // changes to DetailAccountCode control
            lblDetailAccountCode.Location = new System.Drawing.Point(lblDetailAccountCode.Location.X + 90, lblDetailAccountCode.Location.Y);
            lblDetailAccountCode.Text     = "Non-Deductible:";
            lblDetailAccountCode.Size     = new System.Drawing.Size(102, 17);
            cmbDetailAccountCode.Location = new System.Drawing.Point(cmbDetailAccountCode.Location.X + 105, cmbDetailAccountCode.Location.Y);

            // create new label and combobox for the Tax-Deductible Account Code
            Label lblDeductibleAccountCode = new Label();

            lblDeductibleAccountCode.Name     = "lblDeductibleAccountCode";
            lblDeductibleAccountCode.Location = new System.Drawing.Point(cmbDetailAccountCode.Location.X + 310, lblDetailAccountCode.Location.Y);
            lblDeductibleAccountCode.Anchor   =
                ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)));
            lblDeductibleAccountCode.Size      = new System.Drawing.Size(102, 17);
            lblDeductibleAccountCode.Text      = "Tax-Deductible:";
            lblDeductibleAccountCode.TextAlign = System.Drawing.ContentAlignment.TopRight;
            pnlDetails.Controls.Add(lblDeductibleAccountCode);

            cmbDeductibleAccountCode            = new TCmbAutoPopulated();
            cmbDeductibleAccountCode.Name       = "cmbDeductibleAccountCode";
            cmbDeductibleAccountCode.Location   = new System.Drawing.Point(cmbDetailAccountCode.Location.X + 415, cmbDetailAccountCode.Location.Y);
            cmbDeductibleAccountCode.Size       = new System.Drawing.Size(300, 22);
            cmbDeductibleAccountCode.ListTable  = TCmbAutoPopulated.TListTableEnum.UserDefinedList;
            cmbDeductibleAccountCode.TabIndex   = cmbDetailAccountCode.TabIndex + 1;
            cmbDeductibleAccountCode.Validated += ControlValidatedHandler;
            pnlDetails.Controls.Add(cmbDeductibleAccountCode);

            TFinanceControls.InitialiseAccountList(ref cmbDeductibleAccountCode, FLedgerNumber, true, false, false, false);

            if (FMainDS.AMotivationDetail != null)
            {
                FPetraUtilsObject.ValidationControlsDict.Add(FMainDS.AMotivationDetail.Columns[(short)FMainDS.AMotivationDetail.GetType().GetField(
                                                                                                   "ColumnTaxDeductibleAccountId",
                                                                                                   BindingFlags.Public | BindingFlags.Static |
                                                                                                   BindingFlags.FlattenHierarchy).GetValue(FMainDS.
                                                                                                                                           AMotivationDetail.GetType())],
                                                             new TValidationControlsData(cmbDeductibleAccountCode, Catalog.GetString("Tax Deductible Account")));
            }

            // add new column to grid (TaxDeductibleAccount)
            grdDetails.Columns.Clear();
            grdDetails.AddTextColumn(Catalog.GetString("Group"), FMainDS.AMotivationDetail.ColumnMotivationGroupCode);
            grdDetails.AddTextColumn(Catalog.GetString("Motivation Detail"), FMainDS.AMotivationDetail.ColumnMotivationDetailCode);
            grdDetails.AddTextColumn(Catalog.GetString("Description"), FMainDS.AMotivationDetail.ColumnMotivationDetailDesc);
            grdDetails.AddTextColumn(Catalog.GetString("Non-Deductible Account"), FMainDS.AMotivationDetail.ColumnAccountCode);
            grdDetails.AddTextColumn(Catalog.GetString("Tax-Deductible Account"), FMainDS.AMotivationDetail.ColumnTaxDeductibleAccount);
            grdDetails.AddTextColumn(Catalog.GetString("Cost Centre Code"), FMainDS.AMotivationDetail.ColumnCostCentreCode);
            grdDetails.AddCheckBoxColumn(Catalog.GetString("Active"), FMainDS.AMotivationDetail.ColumnMotivationStatus);
            grdDetails.AddCheckBoxColumn(Catalog.GetString("Print Receipt"), FMainDS.AMotivationDetail.ColumnReceipt);

            SelectRowInGrid(1);
        }
        /// <summary>
        /// auto populate new gift recipient info using the donor's last gift
        /// </summary>
        /// <param name="ADonorKey"></param>
        /// <param name="APartnerShortName"></param>
        /// <param name="AGiftTransactionNumber"></param>
        private void AutoPopulateGiftDetail(Int64 ADonorKey, String APartnerShortName, Int32 AGiftTransactionNumber)
        {
            FAutoPopulatingGiftInProcess = true;

            bool IsSplitGift = false;

            DateTime LatestUnpostedGiftDateEntered = new DateTime(1900, 1, 1);

            try
            {
                //Check for Donor in loaded gift batches
                // and record most recent date entered
                AGiftTable DonorRecentGiftsTable             = new AGiftTable();
                GiftBatchTDSAGiftDetailTable GiftDetailTable = new GiftBatchTDSAGiftDetailTable();

                AGiftRow MostRecentLoadedGiftForDonorRow = null;

                DataView giftDV = new DataView(FMainDS.AGift);

                giftDV.RowStateFilter = DataViewRowState.CurrentRows;

                giftDV.RowFilter = string.Format("{0}={1} And Not ({2}={3} And {4}={5})",
                                                 AGiftTable.GetDonorKeyDBName(),
                                                 ADonorKey,
                                                 AGiftTable.GetBatchNumberDBName(),
                                                 FBatchNumber,
                                                 AGiftTable.GetGiftTransactionNumberDBName(),
                                                 AGiftTransactionNumber);

                giftDV.Sort = String.Format("{0} DESC, {1} DESC",
                                            AGiftTable.GetDateEnteredDBName(),
                                            AGiftTable.GetGiftTransactionNumberDBName());

                if (giftDV.Count > 0)
                {
                    //Take first row = most recent date entered value
                    MostRecentLoadedGiftForDonorRow = (AGiftRow)giftDV[0].Row;
                    LatestUnpostedGiftDateEntered   = MostRecentLoadedGiftForDonorRow.DateEntered;
                    DonorRecentGiftsTable.Rows.Add((object[])MostRecentLoadedGiftForDonorRow.ItemArray.Clone());
                }

                //Check for even more recent saved gifts on server (i.e. not necessarily loaded)
                GiftDetailTable = TRemote.MFinance.Gift.WebConnectors.LoadDonorLastPostedGift(ADonorKey, FLedgerNumber, LatestUnpostedGiftDateEntered);

                if (((GiftDetailTable != null) && (GiftDetailTable.Count > 0)))
                {
                    //UnLoaded/Saved gift from donor is more recent
                    IsSplitGift = (GiftDetailTable.Count > 1);
                }
                else if (MostRecentLoadedGiftForDonorRow != null)
                {
                    //Loaded/unsaved gift from donor is more recent
                    DataView giftDetailDV = new DataView(FMainDS.AGiftDetail);

                    giftDetailDV.RowStateFilter = DataViewRowState.CurrentRows;

                    giftDetailDV.RowFilter = string.Format("{0}={1} And {2}={3}",
                                                           AGiftDetailTable.GetBatchNumberDBName(),
                                                           MostRecentLoadedGiftForDonorRow.BatchNumber,
                                                           AGiftDetailTable.GetGiftTransactionNumberDBName(),
                                                           MostRecentLoadedGiftForDonorRow.GiftTransactionNumber);

                    foreach (DataRowView drv in giftDetailDV)
                    {
                        GiftBatchTDSAGiftDetailRow gDR = (GiftBatchTDSAGiftDetailRow)drv.Row;
                        GiftDetailTable.Rows.Add((object[])gDR.ItemArray.Clone());
                    }

                    IsSplitGift = (GiftDetailTable.Count > 1);
                }
                else
                {
                    //nothing to autocopy
                    return;
                }

                // if the last gift was a split gift (multiple details) then ask the user if they would like this new gift to also be split
                if (IsSplitGift)
                {
                    GiftDetailTable.DefaultView.Sort = GiftBatchTDSAGiftDetailTable.GetDetailNumberDBName() + " ASC";

                    string Message = string.Format(Catalog.GetString(
                                                       "The last gift from this donor was a split gift.{0}{0}Here are the details:{0}"), "\n");
                    int DetailNumber = 1;

                    foreach (DataRowView dvr in GiftDetailTable.DefaultView)
                    {
                        GiftBatchTDSAGiftDetailRow Row = (GiftBatchTDSAGiftDetailRow)dvr.Row;

                        Message += DetailNumber + ")  ";

                        if (Row.RecipientKey > 0)
                        {
                            Message +=
                                string.Format(Catalog.GetString("Recipient: {0} ({1});  Motivation Group: {2};  Motivation Detail: {3};  Amount: {4}"),
                                              Row.RecipientDescription, Row.RecipientKey, Row.MotivationGroupCode, Row.MotivationDetailCode,
                                              StringHelper.FormatUsingCurrencyCode(Row.GiftTransactionAmount, GetBatchRow().CurrencyCode) +
                                              " " + FBatchRow.CurrencyCode) +
                                "\n";
                        }

                        DetailNumber++;
                    }

                    Message += "\n" + Catalog.GetString("Do you want to create the same split gift again?");

                    if (!(MessageBox.Show(Message, Catalog.GetString(
                                              "Create Split Gift"), MessageBoxButtons.YesNo, MessageBoxIcon.Question)
                          == DialogResult.Yes))
                    {
                        if (cmbDetailMethodOfGivingCode.CanFocus)
                        {
                            cmbDetailMethodOfGivingCode.Focus();
                        }
                        else if (txtDetailReference.CanFocus)
                        {
                            txtDetailReference.Focus();
                        }

                        return;
                    }
                }

                this.Cursor = Cursors.WaitCursor;

                GiftBatchTDSAGiftDetailRow giftDetailRow = (GiftBatchTDSAGiftDetailRow)GiftDetailTable.DefaultView[0].Row;

                // Handle first row, which is FPreviouslySelectedDetailRow
                txtDetailDonorKey.Text     = String.Format("{0:0000000000}", ADonorKey);
                txtDetailRecipientKey.Text = String.Format("{0:0000000000}", giftDetailRow.RecipientKey);
                cmbDetailMotivationGroupCode.SetSelectedString(giftDetailRow.MotivationGroupCode);
                txtDetailMotivationDetailCode.Text = giftDetailRow.MotivationDetailCode;
                cmbMotivationDetailCode.SetSelectedString(giftDetailRow.MotivationDetailCode);
                chkDetailConfidentialGiftFlag.Checked = giftDetailRow.ConfidentialGiftFlag;
                // Change #5481
                chkDetailChargeFlag.Checked = true;
                cmbDetailMethodOfPaymentCode.SetSelectedString(FBatchMethodOfPayment, -1);
                cmbDetailMethodOfGivingCode.SetSelectedString(giftDetailRow.MethodOfGivingCode, -1);

                //Handle mailing code
                if (FSETAutoCopyIncludeMailingCodeFlag)
                {
                    cmbDetailMailingCode.SetSelectedString(giftDetailRow.MailingCode, -1);
                }
                else
                {
                    cmbDetailMailingCode.SelectedIndex = -1;
                }

                //Copy the comments and comment types if required
                if (FSETAutoCopyIncludeCommentsFlag)
                {
                    txtDetailGiftCommentOne.Text = giftDetailRow.GiftCommentOne;
                    cmbDetailCommentOneType.SetSelectedString(giftDetailRow.CommentOneType);
                    txtDetailGiftCommentTwo.Text = giftDetailRow.GiftCommentTwo;
                    cmbDetailCommentTwoType.SetSelectedString(giftDetailRow.CommentTwoType);
                    txtDetailGiftCommentThree.Text = giftDetailRow.GiftCommentThree;
                    cmbDetailCommentThreeType.SetSelectedString(giftDetailRow.CommentThreeType);
                }

                //Handle tax fields on current row
                if (FSETUseTaxDeductiblePercentageFlag)
                {
                    bool taxDeductible = (giftDetailRow.IsTaxDeductibleNull() ? true : giftDetailRow.TaxDeductible);
                    giftDetailRow.TaxDeductible = taxDeductible;

                    try
                    {
                        FPetraUtilsObject.SuppressChangeDetection = true;
                        chkDetailTaxDeductible.Checked            = taxDeductible;
                        EnableTaxDeductibilityPct(taxDeductible);
                    }
                    finally
                    {
                        FPetraUtilsObject.SuppressChangeDetection = false;
                    }

                    if (!IsSplitGift)
                    {
                        //Most commonly not a split gift (?)
                        if (!taxDeductible)
                        {
                            txtDeductiblePercentage.NumberValueDecimal = 0.0m;
                        }

                        txtTaxDeductAmount.NumberValueDecimal = 0.0m;
                        txtNonDeductAmount.NumberValueDecimal = 0.0m;
                    }
                    else
                    {
                        if (taxDeductible)
                        {
                            //In case the tax percentage has changed or null values in amount fields
                            ReconcileTaxDeductibleAmounts(giftDetailRow);
                        }
                        else
                        {
                            //Changing this will update the unbound amount textboxes
                            txtDeductiblePercentage.NumberValueDecimal = 0.0m;
                        }
                    }
                }

                //Process values that are not bound to a control
                giftDetailRow.ReceiptPrinted = false;
                giftDetailRow.ReceiptNumber  = 0;

                //Now process other gift details if they exist
                if (IsSplitGift)
                {
                    //Only copy amount to first row if copying split gifts
                    txtDetailGiftTransactionAmount.NumberValueDecimal = giftDetailRow.GiftTransactionAmount;

                    // clear previous validation errors.
                    // otherwise we get an error if the user has changed the control immediately after changing the donor key.
                    FPetraUtilsObject.VerificationResultCollection.Clear();

                    bool SelectEndRow = (FBatchRow.LastGiftNumber == FPreviouslySelectedDetailRow.GiftTransactionNumber);

                    //Just retain other details to add
                    giftDetailRow.Delete();
                    GiftDetailTable.AcceptChanges();

                    foreach (DataRowView drv in GiftDetailTable.DefaultView)
                    {
                        GiftBatchTDSAGiftDetailRow detailRow = (GiftBatchTDSAGiftDetailRow)drv.Row;

                        //______________________
                        //Update basic field values
                        detailRow.LedgerNumber          = FLedgerNumber;
                        detailRow.BatchNumber           = FBatchNumber;
                        detailRow.GiftTransactionNumber = AGiftTransactionNumber;
                        detailRow.DetailNumber          = ++FGift.LastDetailNumber;
                        detailRow.DonorName             = APartnerShortName;
                        detailRow.DonorClass            = FPreviouslySelectedDetailRow.DonorClass;
                        detailRow.DateEntered           = FGift.DateEntered;
                        detailRow.MethodOfPaymentCode   = FPreviouslySelectedDetailRow.MethodOfPaymentCode;
                        detailRow.ReceiptPrinted        = false;
                        detailRow.ReceiptNumber         = 0;
                        // Change #5481
                        detailRow.ChargeFlag = true;

                        if (!FSETAutoCopyIncludeMailingCodeFlag)
                        {
                            detailRow.MailingCode = string.Empty;
                        }

                        //______________________
                        //process recipient details to get most recent data
                        Int64         partnerKey       = detailRow.RecipientKey;
                        string        partnerShortName = string.Empty;
                        TPartnerClass partnerClass;
                        bool          recipientIsValid = true;

                        if (TServerLookup.TMPartner.GetPartnerShortName(partnerKey, out partnerShortName, out partnerClass))
                        {
                            detailRow.RecipientDescription = partnerShortName;
                            detailRow.RecipientClass       = partnerClass.ToString();

                            if (partnerClass == TPartnerClass.FAMILY)
                            {
                                detailRow.RecipientLedgerNumber = TRemote.MFinance.Gift.WebConnectors.GetRecipientFundNumber(partnerKey,
                                                                                                                             FGift.DateEntered);
                                detailRow.RecipientField       = detailRow.RecipientLedgerNumber;
                                detailRow.RecipientKeyMinistry = string.Empty;
                            }
                            else
                            {
                                //Class - UNIT
                                Int64  field;
                                string keyMinName;

                                recipientIsValid = TFinanceControls.GetRecipientKeyMinData(partnerKey, out field, out keyMinName);

                                detailRow.RecipientLedgerNumber = field;
                                detailRow.RecipientField        = field;
                                detailRow.RecipientKeyMinistry  = keyMinName;

                                if (!recipientIsValid)
                                {
                                    string msg =
                                        String.Format(Catalog.GetString(
                                                          "Gift: {0}, Detail: {1} has a recipient: '{2}-{3}' that is an inactive Key Ministry!"),
                                                      AGiftTransactionNumber,
                                                      detailRow.DetailNumber,
                                                      partnerKey,
                                                      keyMinName);
                                    MessageBox.Show(msg, Catalog.GetString(
                                                        "Copying Previous Split Gift"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                }
                            }
                        }
                        else
                        {
                            recipientIsValid = false;
                            string msg = String.Format(Catalog.GetString("Gift: {0}, Detail: {1} has an invalid Recipient key: '{2}'!"),
                                                       AGiftTransactionNumber,
                                                       detailRow.DetailNumber,
                                                       partnerKey);
                            MessageBox.Show(msg, Catalog.GetString("Copying Previous Split Gift"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }

                        //______________________
                        //Process motivation
                        if (string.IsNullOrEmpty(detailRow.MotivationGroupCode))
                        {
                            detailRow.MotivationGroupCode = string.Empty;
                            string msg = String.Format(Catalog.GetString("Gift: {0}, Detail: {1} has no Motivation Group!"),
                                                       AGiftTransactionNumber,
                                                       detailRow.DetailNumber);
                            MessageBox.Show(msg, Catalog.GetString("Copying Previous Split Gift"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                        else if (string.IsNullOrEmpty(detailRow.MotivationDetailCode))
                        {
                            detailRow.MotivationDetailCode = string.Empty;
                            string msg = String.Format(Catalog.GetString("Gift: {0}, Detail: {1} has no Motivation Detail!"),
                                                       AGiftTransactionNumber,
                                                       detailRow.DetailNumber);
                            MessageBox.Show(msg, Catalog.GetString("Copying Previous Split Gift"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                        else
                        {
                            AMotivationDetailRow motivationDetailRow = null;
                            string motivationGroup  = detailRow.MotivationGroupCode;
                            string motivationDetail = detailRow.MotivationDetailCode;

                            motivationDetailRow = (AMotivationDetailRow)FMainDS.AMotivationDetail.Rows.Find(
                                new object[] { FLedgerNumber, motivationGroup, motivationDetail });

                            if (motivationDetailRow != null)
                            {
                                if (partnerKey > 0)
                                {
                                    bool partnerIsMissingLink = false;

                                    detailRow.CostCentreCode = TRemote.MFinance.Gift.WebConnectors.RetrieveCostCentreCodeForRecipient(FLedgerNumber,
                                                                                                                                      partnerKey,
                                                                                                                                      detailRow.RecipientLedgerNumber,
                                                                                                                                      detailRow.DateEntered,
                                                                                                                                      motivationGroup,
                                                                                                                                      motivationDetail,
                                                                                                                                      out partnerIsMissingLink);
                                }
                                else
                                {
                                    if (motivationGroup != MFinanceConstants.MOTIVATION_GROUP_GIFT)
                                    {
                                        detailRow.RecipientDescription = motivationGroup;
                                    }
                                    else
                                    {
                                        detailRow.RecipientDescription = string.Empty;
                                    }

                                    detailRow.CostCentreCode = motivationDetailRow.CostCentreCode;
                                }

                                detailRow.AccountCode = motivationDetailRow.AccountCode;

                                if (FSETUseTaxDeductiblePercentageFlag && string.IsNullOrEmpty(motivationDetailRow.TaxDeductibleAccountCode))
                                {
                                    detailRow.TaxDeductibleAccountCode = string.Empty;

                                    string msg = String.Format(Catalog.GetString(
                                                                   "Gift: {0}, Detail: {1} has  Motivation Detail: {2} which has no Tax Deductible Account!" +
                                                                   "This can be added in Finance / Setup / Motivation Details.{3}{3}" +
                                                                   "Unless this is changed it will be impossible to assign a Tax Deductible Percentage to this gift."),
                                                               AGiftTransactionNumber,
                                                               detailRow.DetailNumber,
                                                               motivationDetail,
                                                               Environment.NewLine);
                                    MessageBox.Show(msg, Catalog.GetString(
                                                        "Copying Previous Split Gift"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                }
                                else
                                {
                                    detailRow.TaxDeductibleAccountCode = motivationDetailRow.TaxDeductibleAccountCode;
                                }
                            }
                            else
                            {
                                string msg =
                                    String.Format(Catalog.GetString(
                                                      "Gift: {0}, Detail: {1} has Motivation Group and Detail codes ('{2} : {3}') not found in the database!"),
                                                  AGiftTransactionNumber,
                                                  detailRow.DetailNumber,
                                                  motivationGroup,
                                                  motivationDetail);
                                MessageBox.Show(msg, Catalog.GetString("Copying Previous Split Gift"), MessageBoxButtons.OK, MessageBoxIcon.Warning);

                                detailRow.TaxDeductible = false;
                            }
                        }

                        //______________________
                        //Handle tax fields
                        detailRow.TaxDeductiblePct = RetrieveTaxDeductiblePct((recipientIsValid ? detailRow.RecipientKey : 0),
                                                                              detailRow.TaxDeductible);

                        AGiftDetailRow giftDetails = (AGiftDetailRow)detailRow;
                        TaxDeductibility.UpdateTaxDeductibiltyAmounts(ref giftDetails);

                        //______________________
                        //Process comments
                        if (!FSETAutoCopyIncludeCommentsFlag)
                        {
                            detailRow.SetCommentOneTypeNull();
                            detailRow.SetCommentTwoTypeNull();
                            detailRow.SetCommentThreeTypeNull();
                            detailRow.SetGiftCommentOneNull();
                            detailRow.SetGiftCommentTwoNull();
                            detailRow.SetGiftCommentThreeNull();
                        }

                        detailRow.AcceptChanges();
                        detailRow.SetAdded();
                    }

                    //Add in the new records (latter two arguments put in to parallel recurring form)
                    FMainDS.AGiftDetail.Merge(GiftDetailTable, false, MissingSchemaAction.Ignore);

                    int indexOfLatestRow = FMainDS.AGiftDetail.Rows.Count - 1;

                    //Select last row added
                    if (SelectEndRow)
                    {
                        grdDetails.SelectRowInGrid(grdDetails.Rows.Count - 1);
                    }
                    else if (!SelectDetailRowByDataTableIndex(indexOfLatestRow))
                    {
                        if (!FFilterAndFindObject.IsActiveFilterEqualToBase)
                        {
                            MessageBox.Show(
                                MCommonResourcestrings.StrNewRecordIsFiltered,
                                MCommonResourcestrings.StrAddNewRecordTitle,
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                            FFilterAndFindObject.FilterPanelControls.ClearAllDiscretionaryFilters();

                            if (FFilterAndFindObject.FilterFindPanel.ShowApplyFilterButton != TUcoFilterAndFind.FilterContext.None)
                            {
                                FFilterAndFindObject.ApplyFilter();
                            }

                            SelectDetailRowByDataTableIndex(indexOfLatestRow);
                        }
                    }

                    ClearKeyMinistries();
                    cmbMotivationDetailCode.Clear();
                    mniRecipientHistory.Enabled = false;
                    btnDeleteAll.Enabled        = btnDelete.Enabled;
                    UpdateRecordNumberDisplay();
                    FLastDonor = -1;
                }
                else
                {
                    txtDetailDonorKey.FocusTextBoxPartAfterFindScreenCloses = false;
                    txtDetailGiftTransactionAmount.Focus();
                }

                FPetraUtilsObject.SetChangedFlag();
            }
            finally
            {
                this.Cursor = Cursors.Default;
                FAutoPopulatingGiftInProcess = false;
            }
        }