Example #1
0
        /// <summary>
        /// load the batches into the grid
        /// </summary>
        /// <param name="ALedgerNumber"></param>
        public void LoadRecurringBatches(Int32 ALedgerNumber)
        {
            InitialiseLedgerControls();

            ((TFrmRecurringGiftBatch)ParentForm).ClearCurrentSelections();

            // TODO: more criteria: state of batch, period, etc
            FMainDS.Merge(TRemote.MFinance.Gift.WebConnectors.LoadARecurringGiftBatch(ALedgerNumber));

            // 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.AMotivationDetail.AcceptChanges();

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

            ((TFrmRecurringGiftBatch)this.ParentForm).EnableTransactions(grdDetails.Rows.Count > 1);
            ShowData();

            UpdateRecordNumberDisplay();
            SelectRowInGrid(1);

            FBatchLoaded = true;
        }
Example #2
0
        public void TestComboboxEmptyDescriptionBug()
        {
            TCmbAutoPopulated cmb = new TCmbAutoPopulated();

            DataTable detailTable = TDataCache.TMFinance.GetCacheableFinanceTable(TCacheableFinanceTablesEnum.MotivationList, FLedgerNumber);

            Assert.AreNotEqual(0, detailTable.Rows.Count, "There should be a motivation detail in the cached table");

            cmb.Name = "TestCombobox";
            cmb.InitialiseUserControl(detailTable,
                                      AMotivationDetailTable.GetMotivationDetailCodeDBName(),
                                      AMotivationDetailTable.GetMotivationDetailDescDBName(),
                                      null);
            cmb.AppearanceSetup(new int[] { -1, 150 }, -1);

            Form TestForm = new Form();

            TestForm.Controls.Add(cmb);

            TestForm.Show();

            cmb.SelectedIndex = 1;
            Assert.AreEqual(cmb.GetSelectedString(), "KEYMIN");
            Assert.AreEqual(cmb.GetSelectedDescription(), "Key Ministry Gift");

            cmb.SelectedIndex = 0;
            Assert.AreEqual(cmb.GetSelectedString(), "FIELD");
            Assert.AreEqual(cmb.GetSelectedDescription(), "Field Gift");
        }
Example #3
0
        private void OnCmbMotivationChange(object sender, EventArgs e)
        {
            // if the list is dropped down while the value is changed (not the case when a value from the list is clicked on)
            if (cmbMotivationGroup.cmbCombobox.DroppedDown)
            {
                // this is used to stop an 'Enter' key press triggering a search while a combo boxes list is dropped down
                MotivationGroupDroppedDown = true;
            }

            if (cmbMotivationDetail.cmbCombobox.DroppedDown)
            {
                // this is used to stop an 'Enter' key press triggering a search while a combo boxes list is dropped down
                MotivationDetailDroppedDown = true;
            }

            if ((Ict.Petra.Client.CommonControls.TCmbAutoPopulated)sender == cmbMotivationGroup)
            {
                if (cmbMotivationGroup.Text == string.Empty)
                {
                    cmbMotivationDetail.Filter = string.Empty;
                }
                else
                {
                    TFinanceControls.ChangeFilterMotivationDetailList(ref cmbMotivationDetail, cmbMotivationGroup.Text, false);
                    cmbMotivationDetail.Filter       += " OR " + AMotivationDetailTable.GetMotivationDetailCodeDBName() + " = ''";
                    cmbMotivationDetail.SelectedIndex = -1;
                }
            }
        }
Example #4
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.ARecurringGiftBatch.DefaultView.Sort = String.Format("{0}, {1} DESC",
                                                                         ARecurringGiftBatchTable.GetLedgerNumberDBName(),
                                                                         ARecurringGiftBatchTable.GetBatchNumberDBName()
                                                                         );

            SetupExtraGridFunctionality();
            RefreshBankAccountAndCostCentreData();

            // 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);
        }
Example #5
0
        /// <summary>
        /// Sets TaxDeductiblePct and uses it to calculate the tax deductibility amounts for a Gift Detail
        /// </summary>
        /// <param name="AGiftDetail">Calculated amounts are added to this row</param>
        /// <param name="ADateEntered"></param>
        /// <param name="ATransaction"></param>
        public static void SetDefaultTaxDeductibilityData(
            ref AGiftDetailRow AGiftDetail, DateTime ADateEntered, TDBTransaction ATransaction)
        {
            bool FoundTaxDeductiblePct = false;

            // if the gift it tax deductible
            if (AGiftDetail.TaxDeductible)
            {
                AMotivationDetailTable Tbl = AMotivationDetailAccess.LoadByPrimaryKey(
                    AGiftDetail.LedgerNumber, AGiftDetail.MotivationGroupCode, AGiftDetail.MotivationDetailCode, ATransaction);
                AMotivationDetailRow MotivationDetailRow;

                Boolean HasTaxDeductibleAccountCode = false;

                if (Tbl.Rows.Count > 0)
                {
                    MotivationDetailRow         = Tbl[0];
                    HasTaxDeductibleAccountCode = !string.IsNullOrEmpty(MotivationDetailRow.TaxDeductibleAccountCode);
                }

                // if the gift's motivation detail has a tax-deductible account
                if (HasTaxDeductibleAccountCode)
                {
                    // default pct is 100
                    AGiftDetail.TaxDeductiblePct = 100;
                    FoundTaxDeductiblePct        = true;

                    PPartnerTaxDeductiblePctTable PartnerTaxDeductiblePctTable =
                        PPartnerTaxDeductiblePctAccess.LoadViaPPartner(AGiftDetail.RecipientKey, ATransaction);

                    // search for tax deductible pct for recipient
                    foreach (PPartnerTaxDeductiblePctRow Row in PartnerTaxDeductiblePctTable.Rows)
                    {
                        if (Row.DateValidFrom <= ADateEntered)
                        {
                            AGiftDetail.TaxDeductiblePct = Row.PercentageTaxDeductible;
                            break;
                        }
                    }
                }
            }

            // if a tax deductible pct is set for the recipient
            if (FoundTaxDeductiblePct)
            {
                // calculate TaxDeductibleAmount and NonDeductibleAmount for all three currencies
                TaxDeductibility.UpdateTaxDeductibiltyAmounts(ref AGiftDetail);
            }

            // if gift is not tax deductible or motivation detail does not hace a tax deductible account
            if (!AGiftDetail.TaxDeductible || !FoundTaxDeductiblePct)
            {
                AGiftDetail.TaxDeductiblePct        = 0;
                AGiftDetail.NonDeductibleAmount     = AGiftDetail.GiftTransactionAmount;
                AGiftDetail.NonDeductibleAmountBase = AGiftDetail.GiftAmount;
                AGiftDetail.NonDeductibleAmountIntl = AGiftDetail.GiftAmountIntl;
            }
        }
        private void ResetMotivationDetailCodeFilter(bool AShowGiftDetail)
        {
            bool AlreadySuppressingChanges = FPetraUtilsObject.SuppressChangeDetection;

            try
            {
                if (!AlreadySuppressingChanges)
                {
                    FPetraUtilsObject.SuppressChangeDetection = true;
                }

                //If motivation detail combobox is empty and with a valid filter
                if ((cmbMotivationDetailCode.Count == 0) && (cmbMotivationDetailCode.Filter != null) &&
                    (!cmbMotivationDetailCode.Filter.Contains("1 = 2")))
                {
                    FMotivationDetail = string.Empty;
                    txtDetailMotivationDetailCode.Text = string.Empty;
                    txtMotivationDetailDesc.Text       = string.Empty;

                    if (AShowGiftDetail)
                    {
                        //This is needed as the code in TFinanceControls.ChangeFilterMotivationDetailList looks for presence of the active only prefix
                        cmbMotivationDetailCode.Filter = AMotivationDetailTable.GetMotivationStatusDBName() + " = true And 1 = 2";
                    }
                    else
                    {
                        cmbMotivationDetailCode.Filter = "1 = 2";
                    }

                    return;
                }

                if (AShowGiftDetail)
                {
                    cmbMotivationDetailCode.Filter = AMotivationDetailTable.GetMotivationStatusDBName() + " = true";
                }
                else
                {
                    cmbMotivationDetailCode.Filter = string.Empty;
                }

                //After removing the filter, reselect correct value
                cmbMotivationDetailCode.SetSelectedString(FMotivationDetail);
            }
            finally
            {
                if (!AlreadySuppressingChanges)
                {
                    FPetraUtilsObject.SuppressChangeDetection = false;
                }
            }
        }
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="ALedgerNr"></param>
        /// <param name="ACheckedMember"></param>
        /// <param name="ADisplayMember"></param>
        /// <param name="AValueMember"></param>
        /// <param name="AExcludeInactive"></param>
        /// <returns></returns>
        public static System.Data.DataTable GetMotivationDetails(System.Int32 ALedgerNr,
                                                                 ref String ACheckedMember,
                                                                 ref String ADisplayMember,
                                                                 ref String AValueMember,
                                                                 bool AExcludeInactive)
        {
            System.Data.DataTable ReturnValue;
            DataTable             CachedDataTable;
            String whereClause;

            DataRow[] filteredRows;
            CachedDataTable = TDataCache.TMFinance.GetCacheableFinanceTable(TCacheableFinanceTablesEnum.MotivationList, ALedgerNr);
            whereClause     = AMotivationDetailTable.GetLedgerNumberDBName() + " = " + ALedgerNr.ToString();

            if (AExcludeInactive)
            {
                whereClause = whereClause + " AND " + AMotivationDetailTable.GetMotivationStatusDBName() + " = 1";
            }

            filteredRows = CachedDataTable.Select(whereClause,
                                                  AMotivationDetailTable.GetMotivationGroupCodeDBName() + ',' + AMotivationDetailTable.GetMotivationDetailCodeDBName());
            ReturnValue = CachedDataTable.Clone();

            foreach (DataRow oldDr in filteredRows)
            {
                ReturnValue.ImportRow(oldDr);
            }

            ACheckedMember = "CHECKED";
            ADisplayMember = "DISPLAY";
            AValueMember   = "VALUE";
            ReturnValue.Columns.Add(new DataColumn(ACheckedMember, typeof(bool)));
            ReturnValue.Columns.Add(new DataColumn(AValueMember, typeof(String)));
            ReturnValue.Columns.Add(new DataColumn(ADisplayMember, typeof(String)));

            foreach (DataRow oldDr in ReturnValue.Rows)
            {
                oldDr[AValueMember] =
                    (System.Object)(oldDr[AMotivationDetailTable.GetMotivationGroupCodeDBName()].ToString() + ", " +
                                    oldDr[AMotivationDetailTable.GetMotivationDetailCodeDBName()].ToString());
                oldDr[ADisplayMember] =
                    (System.Object)(oldDr[AMotivationDetailTable.GetMotivationGroupCodeDBName()].ToString() + " - " +
                                    oldDr[AMotivationDetailTable.GetMotivationDetailCodeDBName()].ToString());
            }

            return(ReturnValue);
        }
        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);
        }
Example #9
0
        private void RefreshMotivationDetailList()
        {
            // don't do anything unless screen is activated or settings are loaded
            if (FDuringLoadSettings)
            {
                return;
            }

            string Value1MemberMotDetail  = AMotivationDetailTable.GetMotivationDetailCodeDBName();
            string Value2MemberMotDetail  = AMotivationDetailTable.GetMotivationGroupCodeDBName();
            string DisplayMemberMotDetail = AMotivationDetailTable.GetMotivationDetailDescDBName();
            //List<String> KeyColumnList = new List<String>();
            //KeyColumnList.Add(Value1MemberMotDetail);
            //KeyColumnList.Add(Value2MemberMotDetail);
            string CheckedMotivationDetails = FSelectMotDialog.GetDetailsCheckedString();
            string CheckedMotivationGroups  = FSelectMotDialog.GetGroupsCheckedString();
            string Filter = "";


            DataView MotDetailView = new DataView(FMotDetailTable);

            MotDetailView.Sort = Value2MemberMotDetail + "," + Value1MemberMotDetail;

            if (CheckedMotivationDetails.Length == 0)
            {
                Filter = Value1MemberMotDetail + " = ''";
            }
            else
            {
                while (CheckedMotivationDetails.Length > 0)
                {
                    if (Filter.Length > 0)
                    {
                        Filter = Filter + " OR ";
                    }

                    Filter += " (" + Value2MemberMotDetail + " = '" + StringHelper.GetNextCSV(ref CheckedMotivationDetails) + "'";
                    Filter += " AND " + Value1MemberMotDetail + " = '" + StringHelper.GetNextCSV(ref CheckedMotivationDetails) + "') ";
                }
            }

            MotDetailView.RowFilter = Filter;

            DataTable NewMotDetailTable = MotDetailView.ToTable(true,
                                                                new string[] { Value2MemberMotDetail, Value1MemberMotDetail, DisplayMemberMotDetail });

            grdMotivationSelection.SpecialKeys =
                ((SourceGrid.GridSpecialKeys)((((((SourceGrid.GridSpecialKeys.Arrows |
                                                   SourceGrid.GridSpecialKeys.PageDownUp) |
                                                  SourceGrid.GridSpecialKeys.Enter) |
                                                 SourceGrid.GridSpecialKeys.Escape) |
                                                SourceGrid.GridSpecialKeys.Control) | SourceGrid.GridSpecialKeys.Shift)));

            grdMotivationSelection.Columns.Clear();
            grdMotivationSelection.AddTextColumn(Catalog.GetString("Group Code"), NewMotDetailTable.Columns[Value2MemberMotDetail]);
            grdMotivationSelection.AddTextColumn(Catalog.GetString("Detail Code"), NewMotDetailTable.Columns[Value1MemberMotDetail]);
            grdMotivationSelection.AddTextColumn(Catalog.GetString("Description"), NewMotDetailTable.Columns[DisplayMemberMotDetail]);
            DataView tempDataView = NewMotDetailTable.DefaultView;

            tempDataView.AllowNew             = false;
            grdMotivationSelection.DataSource = new DevAge.ComponentModel.BoundDataView(tempDataView);

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

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

            DataUtilities.CopyAllColumnValuesWithoutPK(AOldGiftDetail, giftDetail);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            AMainDS.AGiftDetail.Rows.Add(giftDetail);
        }
        private void InitializeMotivationDetailList()
        {
            // don't do anything unless screen is activated or settings are loaded
            if (FDuringLoadSettings)
            {
                return;
            }

            // remember checked records
            FCheckedMotDetailStringList = clbMotivationDetail.GetCheckedStringList();

            string        CheckedMemberMotDetail = "CHECKED";
            string        Value1MemberMotDetail  = AMotivationDetailTable.GetMotivationGroupCodeDBName();
            string        Value2MemberMotDetail  = AMotivationDetailTable.GetMotivationDetailCodeDBName();
            string        DisplayMemberMotDetail = AMotivationDetailTable.GetMotivationDetailDescDBName();
            List <String> KeyColumnList          = new List <String>();

            KeyColumnList.Add(Value1MemberMotDetail);
            KeyColumnList.Add(Value2MemberMotDetail);
            string CheckedMotivationGroups = clbMotivationGroup.GetCheckedStringList();
            string Filter = "";

            if (FMotDetailTable == null)
            {
                SetDetailTable();
            }

            DataView MotDetailView = new DataView(FMotDetailTable);

            MotDetailView.Sort = Value1MemberMotDetail + "," + Value2MemberMotDetail;

            if (CheckedMotivationGroups.Length == 0)
            {
                Filter = Value1MemberMotDetail + " = ''";
            }
            else
            {
                while (CheckedMotivationGroups.Length > 0)
                {
                    if (Filter.Length > 0)
                    {
                        Filter = Filter + " OR ";
                    }

                    Filter = Filter + " " + Value1MemberMotDetail + " = '" + StringHelper.GetNextCSV(ref CheckedMotivationGroups) + "'";
                }
            }

            MotDetailView.RowFilter = Filter;

            DataTable NewMotDetailTable = MotDetailView.ToTable(true,
                                                                new string[] { Value2MemberMotDetail, Value1MemberMotDetail, DisplayMemberMotDetail });

            NewMotDetailTable.Columns.Add(new DataColumn(CheckedMemberMotDetail, typeof(bool)));

            clbMotivationDetail.SpecialKeys =
                ((SourceGrid.GridSpecialKeys)((((((SourceGrid.GridSpecialKeys.Arrows |
                                                   SourceGrid.GridSpecialKeys.PageDownUp) |
                                                  SourceGrid.GridSpecialKeys.Enter) |
                                                 SourceGrid.GridSpecialKeys.Escape) |
                                                SourceGrid.GridSpecialKeys.Control) | SourceGrid.GridSpecialKeys.Shift)));

            clbMotivationDetail.Columns.Clear();
            clbMotivationDetail.AddCheckBoxColumn("", NewMotDetailTable.Columns[CheckedMemberMotDetail], 17, false);
            clbMotivationDetail.AddTextColumn(Catalog.GetString("Detail Code"), NewMotDetailTable.Columns[Value2MemberMotDetail]);
            clbMotivationDetail.AddTextColumn(Catalog.GetString("Group Code"), NewMotDetailTable.Columns[Value1MemberMotDetail]);
            clbMotivationDetail.AddTextColumn(Catalog.GetString("Description"), NewMotDetailTable.Columns[DisplayMemberMotDetail]);
            clbMotivationDetail.DataBindGrid(NewMotDetailTable, "", CheckedMemberMotDetail, KeyColumnList, false, true, false);

            // reset checked records
            clbMotivationDetail.SetCheckedStringList(FCheckedMotDetailStringList);

            clbMotivationDetail.AutoResizeGrid();
        }
Example #12
0
        private void ParseTransactionLine(AGiftRow AGift,
            AGiftBatchRow AGiftBatch,
            ref AGiftRow APreviousGift,
            int ANumberOfColumns,
            ref decimal ATotalBatchAmount,
            ref string AImportMessage,
            int ARowNumber,
            decimal AIntlRateFromBase,
            TVerificationResultCollection AMessages,
            AMotivationDetailTable AMotivationDetailTable,
//            TValidationControlsDict AValidationControlsDictGift,
//            TValidationControlsDict AValidationControlsDictGiftDetail,
//            ACostCentreTable AValidationCostCentreTable,
//            AAccountTable AValidationAccountTable,
//            AMotivationGroupTable AValidationMotivationGroupTable,
//            AMethodOfGivingTable AValidationMethodOfGivingTable,
//            AMethodOfPaymentTable AValidationMethodOfPaymentTable,
//            PMailingTable AValidationMailingTable,
            GiftBatchTDSAGiftDetailTable ANeedRecipientLedgerNumber,
            AGiftDetailRow AGiftDetails)
        {
            // Start parsing
            int preParseMessageCount = AMessages.Count;

            // Is this the format with extra columns?
            // Actually if it has the extra columns but does not have the optional final 8 columns we cannot distiguish using this test...
            //   A file without extra columns will have between 13 and 21 columns - depending on whether some of the optional ones at the end are included.
            //   A file with extra columns will be between 19 and 27.
            //  So any count between 19 and 21 is ambiguous.  We will assume that if the file has extra columns it also has
            //   at least enough of the optional ones to exceed 21.
            bool HasExtraColumns = (ANumberOfColumns > 21);

            AImportMessage = Catalog.GetString("Importing the gift data");

            AGift.DonorKey = TCommonImport.ImportInt64(ref FImportLine, FDelimiter, Catalog.GetString("Donor key"),
                FMainDS.AGift.ColumnDonorKey, ARowNumber, AMessages, null);

            TCommonImport.ImportString(ref FImportLine, FDelimiter, Catalog.GetString(
                    "short name of donor (unused)"), null, ARowNumber, AMessages, null);                                                                   // unused

            // This group is optional and database NULL's are allowed
            AGift.MethodOfGivingCode = TCommonImport.ImportString(ref FImportLine, FDelimiter, Catalog.GetString("Method of giving Code"),
                FMainDS.AGift.ColumnMethodOfGivingCode, ARowNumber, AMessages, null, false);
            AGift.MethodOfPaymentCode = TCommonImport.ImportString(ref FImportLine, FDelimiter, Catalog.GetString("Method Of Payment Code"),
                FMainDS.AGift.ColumnMethodOfPaymentCode, ARowNumber, AMessages, null, false);
            AGift.Reference = TCommonImport.ImportString(ref FImportLine, FDelimiter, Catalog.GetString("Reference"),
                FMainDS.AGift.ColumnReference, ARowNumber, AMessages, null, false);
            AGift.ReceiptLetterCode = TCommonImport.ImportString(ref FImportLine, FDelimiter, Catalog.GetString("Receipt letter code"),
                FMainDS.AGift.ColumnReceiptLetterCode, ARowNumber, AMessages, null, false);

            if (AGift.MethodOfGivingCode != null)
            {
                AGift.MethodOfGivingCode = AGift.MethodOfGivingCode.ToUpper();
            }

            if (AGift.MethodOfPaymentCode != null)
            {
                AGift.MethodOfPaymentCode = AGift.MethodOfPaymentCode.ToUpper();
            }

            if (AGift.ReceiptLetterCode != null)
            {
                AGift.ReceiptLetterCode = AGift.ReceiptLetterCode.ToUpper();
            }

            if (HasExtraColumns)
            {
                TCommonImport.ImportInt32(ref FImportLine, FDelimiter, Catalog.GetString("Receipt number"),
                    FMainDS.AGift.ColumnReceiptNumber, ARowNumber, AMessages, null);
                TCommonImport.ImportBoolean(ref FImportLine, FDelimiter, Catalog.GetString("First time gift"),
                    FMainDS.AGift.ColumnFirstTimeGift, ARowNumber, AMessages, null);
                TCommonImport.ImportBoolean(ref FImportLine, FDelimiter, Catalog.GetString("Receipt printed"),
                    FMainDS.AGift.ColumnReceiptPrinted, ARowNumber, AMessages, null);
            }

            AImportMessage = Catalog.GetString("Importing the gift details");

            if ((APreviousGift != null) && (AGift.DonorKey == APreviousGift.DonorKey)
                && (AGift.MethodOfGivingCode == APreviousGift.MethodOfGivingCode)
                && (AGift.MethodOfPaymentCode == APreviousGift.MethodOfPaymentCode)
                && (AGift.Reference == APreviousGift.Reference)
                && (AGift.ReceiptLetterCode == APreviousGift.ReceiptLetterCode)
                && (AGift.ReceiptNumber == APreviousGift.ReceiptNumber)
                && (AGift.FirstTimeGift == APreviousGift.FirstTimeGift)
                && (AGift.ReceiptPrinted == APreviousGift.ReceiptPrinted))
            {
                // this row is a new detail for the previousGift
                AGift = APreviousGift;
                AGift.LastDetailNumber++;
                AGiftDetails.DetailNumber = AGift.LastDetailNumber;
            }
            else
            {
                APreviousGift = AGift;
                AGift.LedgerNumber = AGiftBatch.LedgerNumber;
                AGift.BatchNumber = AGiftBatch.BatchNumber;
                AGift.GiftTransactionNumber = AGiftBatch.LastGiftNumber + 1;
                AGiftBatch.LastGiftNumber++;
                AGift.LastDetailNumber = 1;
                FMainDS.AGift.Rows.Add(AGift);
                AGiftDetails.DetailNumber = 1;
            }

            AGiftDetails.LedgerNumber = AGift.LedgerNumber;
            AGiftDetails.BatchNumber = AGiftBatch.BatchNumber;
            AGiftDetails.GiftTransactionNumber = AGift.GiftTransactionNumber;
            FMainDS.AGiftDetail.Rows.Add(AGiftDetails);

            AGiftDetails.RecipientKey = TCommonImport.ImportInt64(ref FImportLine, FDelimiter, Catalog.GetString("Recipient key"),
                FMainDS.AGiftDetail.ColumnRecipientKey, ARowNumber, AMessages, null);

            TCommonImport.ImportString(ref FImportLine, FDelimiter, Catalog.GetString(
                    "short name of recipient (unused)"), null, ARowNumber, AMessages, null);                           // unused

            if (HasExtraColumns)
            {
                TCommonImport.ImportInt32(ref FImportLine, FDelimiter, Catalog.GetString("Recipient ledger number"),
                    FMainDS.AGiftDetail.ColumnRecipientLedgerNumber, ARowNumber, AMessages, null);
            }

            // we always calculate RecipientLedgerNumber
            AGiftDetails.RecipientLedgerNumber = TGiftTransactionWebConnector.GetRecipientFundNumber(
                AGiftDetails.RecipientKey, AGiftBatch.GlEffectiveDate);

            decimal currentGiftAmount =
                TCommonImport.ImportDecimal(ref FImportLine, FDelimiter, FCultureInfoNumberFormat, Catalog.GetString("Gift amount"),
                    FMainDS.AGiftDetail.ColumnGiftTransactionAmount, ARowNumber, AMessages, null);
            AGiftDetails.GiftTransactionAmount = currentGiftAmount;     // amount in batch currency
            ATotalBatchAmount += currentGiftAmount;

            AGiftDetails.GiftAmount = GLRoutines.Divide(currentGiftAmount, AGiftBatch.ExchangeRateToBase);      // amount in ledger currency

            if (HasExtraColumns)
            {
                // amount in international currency
                TCommonImport.ImportDecimal(ref FImportLine, FDelimiter, FCultureInfoNumberFormat, Catalog.GetString("Gift amount intl"),
                    FMainDS.AGiftDetail.ColumnGiftAmountIntl, ARowNumber, AMessages, null);
            }
            else if (AIntlRateFromBase > 0.0m)
            {
                AGiftDetails.GiftAmountIntl = GLRoutines.Divide(AGiftDetails.GiftAmount, AIntlRateFromBase, 2);
            }

            AGiftDetails.ConfidentialGiftFlag = TCommonImport.ImportBoolean(ref FImportLine, FDelimiter, Catalog.GetString("Confidential gift"),
                FMainDS.AGiftDetail.ColumnConfidentialGiftFlag, ARowNumber, AMessages, null);
            AGiftDetails.MotivationGroupCode = TCommonImport.ImportString(ref FImportLine, FDelimiter, Catalog.GetString("Motivation group code"),
                FMainDS.AGiftDetail.ColumnMotivationGroupCode, ARowNumber, AMessages, null).ToUpper();
            AGiftDetails.MotivationDetailCode = TCommonImport.ImportString(ref FImportLine, FDelimiter, Catalog.GetString("Motivation detail"),
                FMainDS.AGiftDetail.ColumnMotivationDetailCode, ARowNumber, AMessages, null).ToUpper();

            if (HasExtraColumns)
            {
                TCommonImport.ImportString(ref FImportLine, FDelimiter, Catalog.GetString("Cost centre code"),
                    FMainDS.AGiftDetail.ColumnCostCentreCode, ARowNumber, AMessages, null);
            }

            // "In Petra Cost Centre is always inferred from recipient field and motivation detail so is not needed in the import."
            AGiftDetails.CostCentreCode = TGiftTransactionWebConnector.RetrieveCostCentreCodeForRecipient(
                AGiftDetails.LedgerNumber, AGiftDetails.RecipientKey, AGiftDetails.RecipientLedgerNumber,
                AGift.DateEntered, AGiftDetails.MotivationGroupCode, AGiftDetails.MotivationDetailCode);

            // All the remaining columns are optional and can contain database NULL
            AGiftDetails.GiftCommentOne = TCommonImport.ImportString(ref FImportLine, FDelimiter, Catalog.GetString("Gift comment one"),
                FMainDS.AGiftDetail.ColumnGiftCommentOne, ARowNumber, AMessages, null, false);
            string commentOneType = TCommonImport.ImportString(ref FImportLine, FDelimiter, Catalog.GetString("Comment one type"),
                FMainDS.AGiftDetail.ColumnCommentOneType, ARowNumber, AMessages, null, false);

            AGiftDetails.MailingCode = TCommonImport.ImportString(ref FImportLine, FDelimiter, Catalog.GetString("Mailing code"),
                FMainDS.AGiftDetail.ColumnMailingCode, ARowNumber, AMessages, null, false);

            AGiftDetails.GiftCommentTwo = TCommonImport.ImportString(ref FImportLine, FDelimiter, Catalog.GetString("Gift comment two"),
                FMainDS.AGiftDetail.ColumnGiftCommentTwo, ARowNumber, AMessages, null, false);
            string commentTwoType = TCommonImport.ImportString(ref FImportLine, FDelimiter, Catalog.GetString("Comment two type"),
                FMainDS.AGiftDetail.ColumnCommentTwoType, ARowNumber, AMessages, null, false);
            AGiftDetails.GiftCommentThree = TCommonImport.ImportString(ref FImportLine, FDelimiter, Catalog.GetString("Gift comment three"),
                FMainDS.AGiftDetail.ColumnGiftCommentThree, ARowNumber, AMessages, null, false);
            string commentThreeType = TCommonImport.ImportString(ref FImportLine, FDelimiter, Catalog.GetString("Comment three type"),
                FMainDS.AGiftDetail.ColumnCommentThreeType, ARowNumber, AMessages, null, false);

            SetCommentTypeCase(ref commentOneType);
            AGiftDetails.CommentOneType = commentOneType;

            SetCommentTypeCase(ref commentTwoType);
            AGiftDetails.CommentTwoType = commentTwoType;

            SetCommentTypeCase(ref commentThreeType);
            AGiftDetails.CommentThreeType = commentThreeType;

            if (AGiftDetails.MailingCode != null)
            {
                AGiftDetails.MailingCode = AGiftDetails.MailingCode.ToUpper();
            }

            // Find the default Tax deductabilty from the motivation detail. This ensures that the column can be missing.
            AMotivationDetailRow motivationDetailRow = (AMotivationDetailRow)AMotivationDetailTable.Rows.Find(
                new object[] { FLedgerNumber, AGiftDetails.MotivationGroupCode, AGiftDetails.MotivationDetailCode });
            string defaultTaxDeductible =
                ((motivationDetailRow != null) && !motivationDetailRow.IsTaxDeductibleAccountCodeNull()
                 && motivationDetailRow.TaxDeductible) ? "yes" : "no";

            AGiftDetails.TaxDeductible = TCommonImport.ImportBoolean(ref FImportLine, FDelimiter, Catalog.GetString("Tax deductible"),
                FMainDS.AGiftDetail.ColumnTaxDeductible, ARowNumber, AMessages, null, defaultTaxDeductible);

            // Account Codes are always inferred from the motivation detail and so is not needed in the import.
            string NewAccountCode = null;
            string NewTaxDeductibleAccountCode = null;

            // get up-to-date account codes
            if (motivationDetailRow != null)
            {
                NewAccountCode = motivationDetailRow.AccountCode;
                NewTaxDeductibleAccountCode = motivationDetailRow.TaxDeductibleAccountCode;
            }

            AGiftDetails.AccountCode = NewAccountCode;
            AGiftDetails.TaxDeductibleAccountCode = NewTaxDeductibleAccountCode;

            // Date entered cannot be imported although it can be modified in the GUI.
            // This is because it would have to be the last column in the import for compatibility
            // but it belongs with the gift and not the detail so it would need to go in an earlier column.
            // For now the import date entered is the effective date.
            AGift.DateEntered = AGiftBatch.GlEffectiveDate;

            // Enforce the correct case for our GIFT constant
            if (String.Compare(AGiftDetails.MotivationGroupCode, MFinanceConstants.MOTIVATION_GROUP_GIFT, true) == 0)
            {
                AGiftDetails.MotivationGroupCode = MFinanceConstants.MOTIVATION_GROUP_GIFT;
            }
        } // Parse TransactionLine
Example #13
0
        /// <summary>
        /// Validates the Gift Detail data.
        /// </summary>
        /// <param name="AContext">Context that describes where the data validation failed.</param>
        /// <param name="ARow">The <see cref="DataRow" /> which holds the the data against which the validation is run.</param>
        /// <param name="AVerificationResultCollection">Will be filled with any <see cref="TVerificationResult" /> items if
        /// data validation errors occur.</param>
        /// <param name="AValidationControlsDict">A <see cref="TValidationControlsDict" /> containing the Controls that
        /// display data that is about to be validated.</param>
        /// <param name="ARecipientPartnerClass">Recipient's Partner Class (used for Motivation Detail validation).</param>
        /// <param name="ASetupForILT">Optional - Is the recipient set up for inter-ledger transfers.</param>
        /// <param name="ACostCentres">Optional - a CostCentres table.  Is required for import validation. </param>
        /// <param name="AAccounts">Optional - a Accounts table.  Is required for import validation. </param>
        /// <param name="AMotivationGroups">Optional - a MotivationGroups table.  Is required for import validation. </param>
        /// <param name="AMotivationDetails">Optional - a MotivationDetails table.  Is required for import validation. </param>
        /// <param name="AMailingTable">Optional - a Mailing table.  Is required for import validation. </param>
        /// <param name="ARecipientField">Optional The recipient field for the gift.  Is required for import validation. </param>
        /// <returns>True if the validation found no data validation errors, otherwise false.</returns>
        public static bool ValidateGiftDetailManual(object AContext,
            GiftBatchTDSAGiftDetailRow ARow,
            ref TVerificationResultCollection AVerificationResultCollection,
            TValidationControlsDict AValidationControlsDict,
            TPartnerClass? ARecipientPartnerClass,
            bool? ASetupForILT = null,
            ACostCentreTable ACostCentres = null,
            AAccountTable AAccounts = null,
            AMotivationGroupTable AMotivationGroups = null,
            AMotivationDetailTable AMotivationDetails = null,
            PMailingTable AMailingTable = null,
            Int64 ARecipientField = -1)
        {
            DataColumn ValidationColumn;
            TValidationControlsData ValidationControlsData;
            TVerificationResult VerificationResult = null;
            object ValidationContext;
            int VerifResultCollAddedCount = 0;
            bool ValidPartner = true;

            // Don't validate deleted DataRows
            if (ARow.RowState == DataRowState.Deleted)
            {
                return true;
            }

            bool isImporting = AContext.ToString().Contains("Importing");

            // Check if valid recipient
            ValidationColumn = ARow.Table.Columns[AGiftDetailTable.ColumnRecipientKeyId];
            ValidationContext = String.Format("Batch no. {0}, gift no. {1}, detail no. {2}",
                ARow.BatchNumber,
                ARow.GiftTransactionNumber,
                ARow.DetailNumber);

            VerificationResult = TSharedPartnerValidation_Partner.IsValidPartner(
                ARow.RecipientKey, new TPartnerClass[] { TPartnerClass.FAMILY, TPartnerClass.UNIT }, true,
                isImporting ? Catalog.GetString("Recipient key") :
                "Recipient of " + THelper.NiceValueDescription(ValidationContext.ToString()),
                AContext, ValidationColumn, null);

            if (VerificationResult != null)
            {
                AVerificationResultCollection.Remove(ValidationColumn);
                AVerificationResultCollection.AddAndIgnoreNullValue(VerificationResult);
                ValidPartner = false;
            }

            // 'Gift amount must be non-zero
            ValidationColumn = ARow.Table.Columns[AGiftDetailTable.ColumnGiftTransactionAmountId];
            ValidationContext = String.Format("Batch Number {0} (transaction:{1} detail:{2})",
                ARow.BatchNumber,
                ARow.GiftTransactionNumber,
                ARow.DetailNumber);

            if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
            {
                VerificationResult = TNumericalChecks.IsNonZeroDecimal(ARow.GiftTransactionAmount,
                    ValidationControlsData.ValidationControlLabel + (isImporting ? String.Empty : " of " + ValidationContext),
                    AContext, ValidationColumn, ValidationControlsData.ValidationControl);

                // Handle addition/removal to/from TVerificationResultCollection
                if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn, true))
                {
                    VerifResultCollAddedCount++;
                }
            }

            // If recipient is non-zero, field must also be non-zero. Only check for valid recipient keys.
            ValidationColumn = ARow.Table.Columns[AGiftDetailTable.ColumnRecipientLedgerNumberId];
            ValidationContext = String.Format("batch:{0} transaction:{1} detail:{2}",
                ARow.BatchNumber,
                ARow.GiftTransactionNumber,
                ARow.DetailNumber);

            if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
            {
                if ((ARow.RecipientKey > 0) && ValidPartner && (ARow.RecipientLedgerNumber == 0))
                {
                    VerificationResult = TNumericalChecks.IsGreaterThanZero(ARow.RecipientLedgerNumber,
                        "Recipient field of " + ValidationContext + " is 0",
                        AContext, ValidationColumn, ValidationControlsData.ValidationControl);

                    // Handle addition/removal to/from TVerificationResultCollection
                    if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn, true))
                    {
                        VerifResultCollAddedCount++;
                    }
                }

                // Motivation Group code must exist
                if (!ARow.IsMotivationGroupCodeNull() && (AMotivationGroups != null))
                {
                    AMotivationGroupRow foundRow = (AMotivationGroupRow)AMotivationGroups.Rows.Find(
                        new object[] { ARow.LedgerNumber, ARow.MotivationGroupCode });

                    if ((foundRow == null) && AVerificationResultCollection.Auto_Add_Or_AddOrRemove(
                            AContext,
                            new TVerificationResult(ValidationContext,
                                String.Format(Catalog.GetString("Unknown motivation group code '{0}'."),
                                    ARow.MotivationGroupCode),
                                TResultSeverity.Resv_Critical),
                            ValidationColumn))
                    {
                        VerifResultCollAddedCount++;
                    }
                }
            }

            if (!isImporting)
            {
                // NOTE AlanP Oct 2014.  This gets checked by standard validation so may no longer be necessary?
                //  (There was a bug in standard validation where NULL and empty string checks did not quite work as they should ...
                //   so maybe this was necessary before.  Anyway I am leaving it in for now.  I know that importing works fine,
                //   but maybe it is necessary in other circumstances?)

                // Motivation Detail must not be null
                ValidationColumn = ARow.Table.Columns[AGiftDetailTable.ColumnMotivationDetailCodeId];
                ValidationContext = String.Format("(batch:{0} transaction:{1} detail:{2})",
                    ARow.BatchNumber,
                    ARow.GiftTransactionNumber,
                    ARow.DetailNumber);

                if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
                {
                    if (ARow.IsMotivationDetailCodeNull() || (ARow.MotivationDetailCode == String.Empty))
                    {
                        VerificationResult = TGeneralChecks.ValueMustNotBeNullOrEmptyString(ARow.MotivationDetailCode,
                            (isImporting ? ValidationControlsData.ValidationControlLabel : "Motivation Detail code " + ValidationContext),
                            AContext, ValidationColumn, ValidationControlsData.ValidationControl);

                        // Handle addition/removal to/from TVerificationResultCollection
                        if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn, true))
                        {
                            VerifResultCollAddedCount++;
                        }
                    }
                }
            }

            // Motivation Detail must be valid
            ValidationColumn = ARow.Table.Columns[AGiftDetailTable.ColumnMotivationDetailCodeId];
            ValidationContext = String.Format("(batch:{0} transaction:{1} detail:{2})",
                ARow.BatchNumber,
                ARow.GiftTransactionNumber,
                ARow.DetailNumber);

            if (!ARow.IsMotivationDetailCodeNull() && (AMotivationDetails != null))
            {
                AMotivationDetailRow foundRow = (AMotivationDetailRow)AMotivationDetails.Rows.Find(
                    new object[] { ARow.LedgerNumber, ARow.MotivationGroupCode, ARow.MotivationDetailCode });

                if ((foundRow == null) && AVerificationResultCollection.Auto_Add_Or_AddOrRemove(
                        AContext,
                        new TVerificationResult(ValidationContext,
                            String.Format(Catalog.GetString("Unknown motivation detail code '{0}' for group '{1}'."),
                                ARow.MotivationDetailCode, ARow.MotivationGroupCode),
                            TResultSeverity.Resv_Critical),
                        ValidationColumn))
                {
                    VerifResultCollAddedCount++;
                }

                if ((foundRow != null) && (foundRow.MotivationStatus == false) && AVerificationResultCollection.Auto_Add_Or_AddOrRemove(
                        AContext,
                        new TVerificationResult(ValidationContext,
                            String.Format(Catalog.GetString("Motivation detail code '{0}' is no longer in use."),
                                ARow.MotivationDetailCode),
                            TResultSeverity.Resv_Critical),
                        ValidationColumn))
                {
                    VerifResultCollAddedCount++;
                }

                if ((foundRow != null) && (foundRow.RecipientKey != 0) && (ARow.RecipientKey != 0) && (foundRow.RecipientKey != ARow.RecipientKey)
                    && AVerificationResultCollection.Auto_Add_Or_AddOrRemove(
                        AContext,
                        new TVerificationResult(ValidationContext,
                            String.Format(Catalog.GetString(
                                    "The recipient partner key for motivation detail code '{0}' does not match the recipient partner key in the import line."),
                                ARow.MotivationDetailCode),
                            TResultSeverity.Resv_Critical),
                        ValidationColumn))
                {
                    VerifResultCollAddedCount++;
                }
            }

            // Motivation Detail must not be 'Field' or 'Keymin' if the recipient is a Family partner
            ValidationColumn = ARow.Table.Columns[AGiftDetailTable.ColumnMotivationDetailCodeId];
            ValidationContext = String.Format("(batch:{0} transaction:{1} detail:{2})",
                ARow.BatchNumber,
                ARow.GiftTransactionNumber,
                ARow.DetailNumber);

            if (!ARow.IsMotivationDetailCodeNull()
                && (ARow.MotivationGroupCode == MFinanceConstants.MOTIVATION_GROUP_GIFT) && (ARecipientPartnerClass != null)
                && ((ARow.MotivationDetailCode == MFinanceConstants.GROUP_DETAIL_FIELD)
                    || (ARow.MotivationDetailCode == MFinanceConstants.GROUP_DETAIL_KEY_MIN))
                && (ARecipientPartnerClass == TPartnerClass.FAMILY))
            {
                if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
                {
                    VerificationResult = new TVerificationResult(AContext,
                        String.Format(Catalog.GetString("Motivation Detail code '{0}' is not allowed for Family recipients."),
                            ARow.MotivationDetailCode),
                        TResultSeverity.Resv_Critical);

                    if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext,
                            new TScreenVerificationResult(VerificationResult, ValidationColumn, ValidationControlsData.ValidationControl),
                            ValidationColumn, true))
                    {
                        VerifResultCollAddedCount++;
                    }
                }
            }

            // Cost Centre Code must exist and be active.  Only required for importing because the GUI does this for us otherwise.
            if (isImporting && (ACostCentres != null) && !ARow.IsCostCentreCodeNull())
            {
                ValidationColumn = ARow.Table.Columns[AGiftDetailTable.ColumnCostCentreCodeId];
                ValidationContext = ARow.CostCentreCode;

                if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
                {
                    // We even need to check that the code exists!
                    DataRow foundRow = ACostCentres.Rows.Find(new object[] { ARow.LedgerNumber, ARow.CostCentreCode });

                    if ((foundRow == null)
                        && AVerificationResultCollection.Auto_Add_Or_AddOrRemove(
                            AContext,
                            new TScreenVerificationResult(ValidationContext,
                                ValidationColumn,
                                String.Format(Catalog.GetString("Unknown cost centre code '{0}'."), ARow.CostCentreCode),
                                ValidationControlsData.ValidationControl,
                                TResultSeverity.Resv_Critical),

/*
 *                          new TVerificationResult(ValidationContext,
 *                              String.Format(Catalog.GetString("Unknown cost centre code '{0}'."), ARow.CostCentreCode),
 *                              TResultSeverity.Resv_Critical),
 */
                            ValidationColumn))
                    {
                        VerifResultCollAddedCount++;
                    }

                    VerificationResult = (TScreenVerificationResult)TStringChecks.ValidateValueIsActive(ARow.LedgerNumber,
                        ACostCentres,
                        ValidationContext.ToString(),
                        ACostCentreTable.GetCostCentreActiveFlagDBName(),
                        AContext,
                        ValidationColumn,
                        ValidationControlsData.ValidationControl);

                    // Handle addition/removal to/from TVerificationResultCollection
                    if ((VerificationResult != null)
                        && AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn, true))
                    {
                        VerifResultCollAddedCount++;
                    }
                }
            }

            // Account Code must exist and be active.  Only required for importing because the GUI does this for us otherwise.
            if (isImporting && (AAccounts != null) && !ARow.IsAccountCodeNull())
            {
                DataColumn[] ValidationColumns = new DataColumn[] {
                    ARow.Table.Columns[AGiftDetailTable.ColumnAccountCodeId], ARow.Table.Columns[AGiftDetailTable.ColumnTaxDeductibleAccountCodeId]
                };
                string[] AccountCodes = new string[] {
                    ARow.AccountCode, ARow.TaxDeductibleAccountCode
                };

                for (int i = 0; i < 2; i++)
                {
                    if (AValidationControlsDict.TryGetValue(ValidationColumns[i], out ValidationControlsData))
                    {
                        // We even need to check that the code exists!
                        DataRow foundRow = AAccounts.Rows.Find(new object[] { ARow.LedgerNumber, AccountCodes[i] });

                        if ((foundRow == null)
                            && AVerificationResultCollection.Auto_Add_Or_AddOrRemove(
                                AContext,
                                new TVerificationResult(AccountCodes[i],
                                    String.Format(Catalog.GetString("Unknown account code '{0}'."), AccountCodes[i]),
                                    TResultSeverity.Resv_Critical),
                                ValidationColumns[i]))
                        {
                            VerifResultCollAddedCount++;
                        }

                        VerificationResult = (TScreenVerificationResult)TStringChecks.ValidateValueIsActive(ARow.LedgerNumber,
                            AAccounts,
                            AccountCodes[i],
                            AAccountTable.GetAccountActiveFlagDBName(),
                            AContext,
                            ValidationColumns[i],
                            ValidationControlsData.ValidationControl);

                        // Handle addition/removal to/from TVerificationResultCollection
                        if ((VerificationResult != null)
                            && AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumns[i], true))
                        {
                            VerifResultCollAddedCount++;
                        }
                    }
                }
            }

            // Mailing code must exist
            ValidationColumn = ARow.Table.Columns[AGiftDetailTable.ColumnMailingCodeId];
            ValidationContext = String.Format("(batch:{0} transaction:{1} detail:{2})",
                ARow.BatchNumber,
                ARow.GiftTransactionNumber,
                ARow.DetailNumber);

            if (!ARow.IsMailingCodeNull() && (AMailingTable != null))
            {
                PMailingRow foundRow = (PMailingRow)AMailingTable.Rows.Find(ARow.MailingCode);

                if ((foundRow == null) && AVerificationResultCollection.Auto_Add_Or_AddOrRemove(
                        AContext,
                        new TVerificationResult(ValidationContext,
                            String.Format(Catalog.GetString("Unknown mailing code '{0}'."),
                                ARow.MailingCode),
                            TResultSeverity.Resv_Critical),
                        ValidationColumn))
                {
                    VerifResultCollAddedCount++;
                }
            }

            // Detail comments type 1 must not be null if associated comment is not null
            ValidationColumn = ARow.Table.Columns[AGiftDetailTable.ColumnCommentOneTypeId];
            ValidationContext = String.Format("(batch:{0} transaction:{1} detail:{2})",
                ARow.BatchNumber,
                ARow.GiftTransactionNumber,
                ARow.DetailNumber);

            if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
            {
                if (!ARow.IsGiftCommentOneNull() && (ARow.GiftCommentOne != String.Empty))
                {
                    VerificationResult = TGeneralChecks.ValueMustNotBeNullOrEmptyString(ARow.CommentOneType,
                        (isImporting ? ValidationControlsData.ValidationControlLabel : "Comment 1 type " + ValidationContext),
                        AContext, ValidationColumn, ValidationControlsData.ValidationControl);

                    // Handle addition/removal to/from TVerificationResultCollection
                    if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn, true))
                    {
                        VerifResultCollAddedCount++;
                    }

                    if (VerificationResult == null)
                    {
                        // There is a comment type for the comment - but it needs to be one of the valid types
                        if ((ARow.CommentOneType != MFinanceConstants.GIFT_COMMENT_TYPE_DONOR)
                            && (ARow.CommentOneType != MFinanceConstants.GIFT_COMMENT_TYPE_RECIPIENT)
                            && (ARow.CommentOneType != MFinanceConstants.GIFT_COMMENT_TYPE_BOTH)
                            && (ARow.CommentOneType != MFinanceConstants.GIFT_COMMENT_TYPE_OFFICE)
                            && AVerificationResultCollection.Auto_Add_Or_AddOrRemove(
                                AContext,
                                new TVerificationResult(ValidationContext,
                                    String.Format(Catalog.GetString("Comment type must be one of '{0}', '{1}', '{2}' or '{3}'."),
                                        MFinanceConstants.GIFT_COMMENT_TYPE_DONOR,
                                        MFinanceConstants.GIFT_COMMENT_TYPE_RECIPIENT,
                                        MFinanceConstants.GIFT_COMMENT_TYPE_BOTH,
                                        MFinanceConstants.GIFT_COMMENT_TYPE_OFFICE),
                                    TResultSeverity.Resv_Critical),
                                ValidationColumn))
                        {
                            VerifResultCollAddedCount++;
                        }
                    }
                }
            }

            // Detail comments type 2 must not be null if associated comment is not null
            ValidationColumn = ARow.Table.Columns[AGiftDetailTable.ColumnCommentTwoTypeId];
            ValidationContext = String.Format("(batch:{0} transaction:{1} detail:{2})",
                ARow.BatchNumber,
                ARow.GiftTransactionNumber,
                ARow.DetailNumber);

            if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
            {
                if (!ARow.IsGiftCommentTwoNull() && (ARow.GiftCommentTwo != String.Empty))
                {
                    VerificationResult = TGeneralChecks.ValueMustNotBeNullOrEmptyString(ARow.CommentTwoType,
                        (isImporting ? ValidationControlsData.ValidationControlLabel : "Comment 2 type " + ValidationContext),
                        AContext, ValidationColumn, ValidationControlsData.ValidationControl);

                    // Handle addition/removal to/from TVerificationResultCollection
                    if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn, true))
                    {
                        VerifResultCollAddedCount++;
                    }

                    if (VerificationResult == null)
                    {
                        // There is a comment type for the comment - but it needs to be one of the valid types
                        if ((ARow.CommentTwoType != MFinanceConstants.GIFT_COMMENT_TYPE_DONOR)
                            && (ARow.CommentTwoType != MFinanceConstants.GIFT_COMMENT_TYPE_RECIPIENT)
                            && (ARow.CommentTwoType != MFinanceConstants.GIFT_COMMENT_TYPE_BOTH)
                            && (ARow.CommentTwoType != MFinanceConstants.GIFT_COMMENT_TYPE_OFFICE)
                            && AVerificationResultCollection.Auto_Add_Or_AddOrRemove(
                                AContext,
                                new TVerificationResult(ValidationContext,
                                    String.Format(Catalog.GetString("Comment type must be one of '{0}', '{1}', '{2}' or '{3}'."),
                                        MFinanceConstants.GIFT_COMMENT_TYPE_DONOR,
                                        MFinanceConstants.GIFT_COMMENT_TYPE_RECIPIENT,
                                        MFinanceConstants.GIFT_COMMENT_TYPE_BOTH,
                                        MFinanceConstants.GIFT_COMMENT_TYPE_OFFICE),
                                    TResultSeverity.Resv_Critical),
                                ValidationColumn))
                        {
                            VerifResultCollAddedCount++;
                        }
                    }
                }
            }

            // Detail comments type 3 must not be null if associated comment is not null
            ValidationColumn = ARow.Table.Columns[AGiftDetailTable.ColumnCommentThreeTypeId];
            ValidationContext = String.Format("(batch:{0} transaction:{1} detail:{2})",
                ARow.BatchNumber,
                ARow.GiftTransactionNumber,
                ARow.DetailNumber);

            if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
            {
                if (!ARow.IsGiftCommentThreeNull() && (ARow.GiftCommentThree != String.Empty))
                {
                    VerificationResult = TGeneralChecks.ValueMustNotBeNullOrEmptyString(ARow.CommentThreeType,
                        (isImporting ? ValidationControlsData.ValidationControlLabel : "Comment 3 type " + ValidationContext),
                        AContext, ValidationColumn, ValidationControlsData.ValidationControl);

                    // Handle addition/removal to/from TVerificationResultCollection
                    if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn, true))
                    {
                        VerifResultCollAddedCount++;
                    }

                    if (VerificationResult == null)
                    {
                        // There is a comment type for the comment - but it needs to be one of the valid types
                        if ((ARow.CommentThreeType != MFinanceConstants.GIFT_COMMENT_TYPE_DONOR)
                            && (ARow.CommentThreeType != MFinanceConstants.GIFT_COMMENT_TYPE_RECIPIENT)
                            && (ARow.CommentThreeType != MFinanceConstants.GIFT_COMMENT_TYPE_BOTH)
                            && (ARow.CommentThreeType != MFinanceConstants.GIFT_COMMENT_TYPE_OFFICE)
                            && AVerificationResultCollection.Auto_Add_Or_AddOrRemove(
                                AContext,
                                new TVerificationResult(ValidationContext,
                                    String.Format(Catalog.GetString("Comment type must be one of '{0}', '{1}', '{2}' or '{3}'."),
                                        MFinanceConstants.GIFT_COMMENT_TYPE_DONOR,
                                        MFinanceConstants.GIFT_COMMENT_TYPE_RECIPIENT,
                                        MFinanceConstants.GIFT_COMMENT_TYPE_BOTH,
                                        MFinanceConstants.GIFT_COMMENT_TYPE_OFFICE),
                                    TResultSeverity.Resv_Critical),
                                ValidationColumn))
                        {
                            VerifResultCollAddedCount++;
                        }
                    }
                }
            }

            return VerifResultCollAddedCount == 0;
        }
Example #14
0
        private void ParseTransactionLine(AGiftRow AGift, AGiftBatchRow AGiftBatch, ref AGiftRow APreviousGift, int ANumberOfColumns,
            ref decimal ATotalBatchAmount, ref string AImportMessage, int ARowNumber, TVerificationResultCollection AMessages,
            TValidationControlsDict AValidationControlsDictGift, TValidationControlsDict AValidationControlsDictGiftDetail,
            ACostCentreTable AValidationCostCentreTable, AMotivationGroupTable AValidationMotivationGroupTable,
            AMotivationDetailTable AValidationMotivationDetailTable, AMethodOfGivingTable AValidationMethodOfGivingTable,
            AMethodOfPaymentTable AValidationMethodOfPaymentTable,
            ref GiftBatchTDSAGiftDetailTable ANeedRecipientLedgerNumber, out AGiftDetailRow AGiftDetails)
        {
            // Is this the format with extra columns?
            // Actually if it has the extra columns but does not have the optional final 8 columns we cannot distiguish using this test...
            //   A file without extra columns will have between 13 and 21 columns - depending on whether some of the optional ones at the end are included.
            //   A file with extra columns will be between 19 and 27.
            //  So any count between 19 and 21 is ambiguous.  We will assume that if the file has extra columns it also has
            //   at least enough of the optional ones to exceed 21.
            bool HasExtraColumns = (ANumberOfColumns > 21);

            AImportMessage = Catalog.GetString("Importing the gift data");

            AGift.DonorKey = ImportInt64(Catalog.GetString("Donor key"),
                FMainDS.AGift.ColumnDonorKey, ARowNumber, AMessages, AValidationControlsDictGift);

            ImportString(Catalog.GetString("short name of donor (unused)"), null, null); // unused

            // This group is optional and database NULL's are allowed
            AGift.MethodOfGivingCode = ImportString(Catalog.GetString("Method of giving Code"),
                FMainDS.AGift.ColumnMethodOfGivingCode, AValidationControlsDictGift, false);
            AGift.MethodOfPaymentCode = ImportString(Catalog.GetString("Method Of Payment Code"),
                FMainDS.AGift.ColumnMethodOfPaymentCode, AValidationControlsDictGift, false);
            AGift.Reference = ImportString(Catalog.GetString("Reference"),
                FMainDS.AGift.ColumnReference, AValidationControlsDictGift, false);
            AGift.ReceiptLetterCode = ImportString(Catalog.GetString("Receipt letter code"),
                FMainDS.AGift.ColumnReceiptLetterCode, AValidationControlsDictGift, false);

            if (HasExtraColumns)
            {
                ImportInt32(Catalog.GetString("Receipt number"),
                    FMainDS.AGift.ColumnReceiptNumber, ARowNumber, AMessages, AValidationControlsDictGift);
                ImportBoolean(Catalog.GetString("First time gift"),
                    FMainDS.AGift.ColumnFirstTimeGift, AValidationControlsDictGift);
                ImportBoolean(Catalog.GetString("Receipt printed"),
                    FMainDS.AGift.ColumnReceiptPrinted, AValidationControlsDictGift);
            }

            AImportMessage = Catalog.GetString("Importing the gift details");

            AGiftDetails = FMainDS.AGiftDetail.NewRowTyped(true);

            if ((APreviousGift != null) && (AGift.DonorKey == APreviousGift.DonorKey)
                && (AGift.MethodOfGivingCode == APreviousGift.MethodOfGivingCode)
                && (AGift.MethodOfPaymentCode == APreviousGift.MethodOfPaymentCode)
                && (AGift.Reference == APreviousGift.Reference)
                && (AGift.ReceiptLetterCode == APreviousGift.ReceiptLetterCode)
                && (AGift.ReceiptNumber == APreviousGift.ReceiptNumber)
                && (AGift.FirstTimeGift == APreviousGift.FirstTimeGift)
                && (AGift.ReceiptPrinted == APreviousGift.ReceiptPrinted))
            {
                // this row is a new detail for the previousGift
                AGift = APreviousGift;
                AGift.LastDetailNumber++;
                AGiftDetails.DetailNumber = AGift.LastDetailNumber;
            }
            else
            {
                APreviousGift = AGift;
                AGift.LedgerNumber = AGiftBatch.LedgerNumber;
                AGift.BatchNumber = AGiftBatch.BatchNumber;
                AGift.GiftTransactionNumber = AGiftBatch.LastGiftNumber + 1;
                AGiftBatch.LastGiftNumber++;
                AGift.LastDetailNumber = 1;
                FMainDS.AGift.Rows.Add(AGift);
                AGiftDetails.DetailNumber = 1;
            }

            AGiftDetails.LedgerNumber = AGift.LedgerNumber;
            AGiftDetails.BatchNumber = AGiftBatch.BatchNumber;
            AGiftDetails.GiftTransactionNumber = AGift.GiftTransactionNumber;
            FMainDS.AGiftDetail.Rows.Add(AGiftDetails);

            AGiftDetails.RecipientKey = ImportInt64(Catalog.GetString("Recipient key"),
                FMainDS.AGiftDetail.ColumnRecipientKey, ARowNumber, AMessages, AValidationControlsDictGiftDetail);

            ImportString(Catalog.GetString("short name of recipient (unused)"), null, null); // unused

            if (HasExtraColumns)
            {
                ImportInt32(Catalog.GetString("Recipient ledger number"),
                    FMainDS.AGiftDetail.ColumnRecipientLedgerNumber, ARowNumber, AMessages, AValidationControlsDictGiftDetail);
            }

            // we always calculate RecipientLedgerNumber
            AGiftDetails.RecipientLedgerNumber = TGiftTransactionWebConnector.GetRecipientFundNumber(
                AGiftDetails.RecipientKey, AGiftBatch.GlEffectiveDate);

            decimal currentGiftAmount = ImportDecimal(Catalog.GetString("Gift amount"),
                FMainDS.AGiftDetail.ColumnGiftTransactionAmount, ARowNumber, AMessages, AValidationControlsDictGiftDetail);
            AGiftDetails.GiftTransactionAmount = currentGiftAmount;     // amount in batch currency
            ATotalBatchAmount += currentGiftAmount;

            AGiftDetails.GiftAmount = GLRoutines.Divide(currentGiftAmount, AGiftBatch.ExchangeRateToBase);      // amount in ledger currency

            if (HasExtraColumns)
            {
                // amount in international currency
                ImportDecimal(Catalog.GetString("Gift amount intl"),
                    FMainDS.AGiftDetail.ColumnGiftAmountIntl, ARowNumber, AMessages, AValidationControlsDictGiftDetail);
            }

            AGiftDetails.ConfidentialGiftFlag = ImportBoolean(Catalog.GetString("Confidential gift"),
                FMainDS.AGiftDetail.ColumnConfidentialGiftFlag, AValidationControlsDictGiftDetail, "no");
            AGiftDetails.MotivationGroupCode = ImportString(Catalog.GetString("Motivation group code"),
                FMainDS.AGiftDetail.ColumnMotivationGroupCode, AValidationControlsDictGiftDetail);
            AGiftDetails.MotivationDetailCode = ImportString(Catalog.GetString("Motivation detail"),
                FMainDS.AGiftDetail.ColumnMotivationDetailCode, AValidationControlsDictGiftDetail);

            if (HasExtraColumns)
            {
                ImportString(Catalog.GetString("Cost centre code"),
                    FMainDS.AGiftDetail.ColumnCostCentreCode, AValidationControlsDictGiftDetail);
            }

            // "In Petra Cost Centre is always inferred from recipient field and motivation detail so is not needed in the import."
            AGiftDetails.CostCentreCode = InferCostCentre(AGiftDetails);

            // All the remaining columns are optional and can contain database NULL
            AGiftDetails.GiftCommentOne = ImportString(Catalog.GetString("Gift comment one"),
                FMainDS.AGiftDetail.ColumnGiftCommentOne, AValidationControlsDictGiftDetail, false);
            string commentOneType = ImportString(Catalog.GetString("Comment one type"),
                FMainDS.AGiftDetail.ColumnCommentOneType, AValidationControlsDictGiftDetail, false);

            AGiftDetails.MailingCode = ImportString(Catalog.GetString("Mailing code"),
                FMainDS.AGiftDetail.ColumnMailingCode, AValidationControlsDictGiftDetail, false);

            AGiftDetails.GiftCommentTwo = ImportString(Catalog.GetString("Gift comment two"),
                FMainDS.AGiftDetail.ColumnGiftCommentTwo, AValidationControlsDictGiftDetail, false);
            string commentTwoType = ImportString(Catalog.GetString("Comment two type"),
                FMainDS.AGiftDetail.ColumnCommentTwoType, AValidationControlsDictGiftDetail, false);
            AGiftDetails.GiftCommentThree = ImportString(Catalog.GetString("Gift comment three"),
                FMainDS.AGiftDetail.ColumnGiftCommentThree, AValidationControlsDictGiftDetail, false);
            string commentThreeType = ImportString(Catalog.GetString("Comment three type"),
                FMainDS.AGiftDetail.ColumnCommentThreeType, AValidationControlsDictGiftDetail, false);

            SetCommentTypeCase(ref commentOneType);
            AGiftDetails.CommentOneType = commentOneType;

            SetCommentTypeCase(ref commentTwoType);
            AGiftDetails.CommentOneType = commentTwoType;

            SetCommentTypeCase(ref commentThreeType);
            AGiftDetails.CommentOneType = commentThreeType;

            // Find the default Tax deductabilty from the motivation detail. This ensures that the column can be missing.
            AMotivationDetailRow motivationDetailRow = (AMotivationDetailRow)AValidationMotivationDetailTable.Rows.Find(
                new object[] { FLedgerNumber, AGiftDetails.MotivationGroupCode, AGiftDetails.MotivationDetailCode });
            string defaultTaxDeductible =
                ((motivationDetailRow != null) && !motivationDetailRow.IsTaxDeductibleAccountNull()
                 && motivationDetailRow.TaxDeductible) ? "yes" : "no";

            AGiftDetails.TaxDeductible = ImportBoolean(Catalog.GetString("Tax deductible"),
                FMainDS.AGiftDetail.ColumnTaxDeductible, AValidationControlsDictGiftDetail, defaultTaxDeductible);

            // Date entered cannot be imported although it can be modified in the GUI.
            // This is because it would have to be the last column in the import for compatibility
            // but it belongs with the gift and not the detail so it would need to go in an earlier column.
            // For now the import date entered is the effective date.
            AGift.DateEntered = AGiftBatch.GlEffectiveDate;

            // Enforce the correct case for our GIFT constant
            if (String.Compare(AGiftDetails.MotivationGroupCode, MFinanceConstants.MOTIVATION_GROUP_GIFT, true) == 0)
            {
                AGiftDetails.MotivationGroupCode = MFinanceConstants.MOTIVATION_GROUP_GIFT;
            }

            TPartnerClass RecipientClass;
            string RecipientDescription;
            TPartnerServerLookups.GetPartnerShortName(AGiftDetails.RecipientKey, out RecipientDescription, out RecipientClass);

            // If the gift has a Family recipient with no Gift Destination then the import will fail. Gift is added to a table and returned to client.
            if ((AGiftDetails.RecipientLedgerNumber == 0) && (AGiftDetails.MotivationGroupCode == MFinanceConstants.MOTIVATION_GROUP_GIFT))
            {
                if (RecipientClass == TPartnerClass.FAMILY)
                {
                    ((GiftBatchTDSAGiftDetailRow)AGiftDetails).RecipientDescription = RecipientDescription;
                    ANeedRecipientLedgerNumber.Rows.Add((object[])AGiftDetails.ItemArray.Clone());
                }
            }

            AImportMessage = Catalog.GetString("Validating the gift data");

            int messageCountBeforeValidate = AMessages.Count;

            // Do our standard validation on this gift
            AGiftValidation.Validate(this, AGift, ref AMessages, AValidationControlsDictGift);
            TSharedFinanceValidation_Gift.ValidateGiftManual(this, AGift, AGiftBatch.BatchYear, AGiftBatch.BatchPeriod,
                null, ref AMessages, AValidationControlsDictGift, AValidationMethodOfGivingTable, AValidationMethodOfPaymentTable);

            AImportMessage = Catalog.GetString("Validating the gift details data");

            AGiftDetailValidation.Validate(this, AGiftDetails, ref AMessages, AValidationControlsDictGiftDetail);
            TSharedFinanceValidation_Gift.ValidateGiftDetailManual(this, (GiftBatchTDSAGiftDetailRow)AGiftDetails,
                ref AMessages, AValidationControlsDictGiftDetail, RecipientClass, AValidationCostCentreTable, AValidationMotivationGroupTable,
                AValidationMotivationDetailTable, AGiftDetails.RecipientKey);

            for (int i = messageCountBeforeValidate; i < AMessages.Count; i++)
            {
                ((TVerificationResult)AMessages[i]).OverrideResultContext(String.Format(MCommonConstants.StrValidationErrorInLine, ARowNumber));

                if (AMessages[i] is TScreenVerificationResult)
                {
                    TVerificationResult downgrade = new TVerificationResult((TScreenVerificationResult)AMessages[i]);
                    AMessages.RemoveAt(i);
                    AMessages.Insert(i, downgrade);
                }
            }
        }
Example #15
0
        /// <summary>
        /// This "Einzahlungsschein mit Referenznummer" (ESR) input format is only used in Switzerland.
        /// This method could be pulled out of here, but sits here quite nicely.
        /// </summary>
        /// <param name="AImportLine"></param>
        /// <param name="AgiftBatch"></param>
        /// <param name="Agift"></param>
        /// <param name="AgiftDetails"></param>
        /// <param name="AIntlRateToBase"></param>
        /// <param name="AMotivationDetailTable"></param>
        /// <param name="ANeedRecipientLedgerNumber"></param>
        /// <param name="AMessages"></param>
        /// <returns></returns>
        private Boolean ParseEsrTransactionLine(
            String AImportLine,
            AGiftBatchRow AgiftBatch,
            AGiftRow Agift,
            AGiftDetailRow AgiftDetails,
            Decimal AIntlRateToBase,
            AMotivationDetailTable AMotivationDetailTable,
            GiftBatchTDSAGiftDetailTable ANeedRecipientLedgerNumber,
            TVerificationResultCollection AMessages
            )
        {
            Boolean NonNumericError = false;
            String Field = AImportLine.Substring(0, 3);

            Int32 FunctionType = 0;

            NonNumericError &= !Int32.TryParse(Field, out FunctionType);

            Int64 DonorKey = 0;
            Field = AImportLine.Substring(12, 10);
            NonNumericError &= !Int64.TryParse(Field, out DonorKey);

            Int64 RecipientKey = 0;
            Field = AImportLine.Substring(22, 10);
            NonNumericError &= !Int64.TryParse(Field, out RecipientKey);

            Int64 intAmount = 0;
            Field = AImportLine.Substring(39, 10);
            NonNumericError &= !Int64.TryParse(Field, out intAmount);

            Decimal Amount = intAmount / 100;

            if (NonNumericError)
            {
                return false;
            }

            String MotivGroup = "GIFT";
            String MotivDetail = "UNDESIG";
            TGuiTools.GetMotivationGroupAndDetail(RecipientKey, ref MotivGroup, ref MotivDetail);

            Agift.LedgerNumber = AgiftBatch.LedgerNumber;
            Agift.BatchNumber = AgiftBatch.BatchNumber;
            Agift.GiftTransactionNumber = AgiftBatch.LastGiftNumber + 1;
            AgiftBatch.LastGiftNumber++;
            AgiftBatch.BatchTotal += Amount;
            Agift.LastDetailNumber = 1;

            ExchangeFieldsInEsrTransaction(ref DonorKey, ref RecipientKey, AMessages, Agift.GiftTransactionNumber);

            Agift.DonorKey = DonorKey;
            Agift.MethodOfGivingCode = "DEFAULT";
            Agift.MethodOfPaymentCode = "ESR";
            FMainDS.AGift.Rows.Add(Agift);

            AgiftDetails.RecipientKey = RecipientKey;
            AgiftDetails.LedgerNumber = AgiftBatch.LedgerNumber;
            AgiftDetails.BatchNumber = AgiftBatch.BatchNumber;
            AgiftDetails.GiftTransactionNumber = Agift.GiftTransactionNumber;
            AgiftDetails.DetailNumber = 1;
            AgiftDetails.GiftTransactionAmount = Amount;
            AgiftDetails.GiftAmount = GLRoutines.Divide(Amount, AgiftBatch.ExchangeRateToBase);      // amount in ledger currency

            if (AIntlRateToBase > 0.0m)
            {
                AgiftDetails.GiftAmountIntl = GLRoutines.Divide(AgiftDetails.GiftAmount, AIntlRateToBase, 2);
            }

            AgiftDetails.RecipientLedgerNumber = TGiftTransactionWebConnector.GetRecipientFundNumber(AgiftDetails.RecipientKey,
                AgiftBatch.GlEffectiveDate);


            AgiftDetails.MotivationGroupCode = MotivGroup;
            AgiftDetails.MotivationDetailCode = MotivDetail;
            AgiftDetails.CostCentreCode = TGiftTransactionWebConnector.RetrieveCostCentreCodeForRecipient(
                AgiftDetails.LedgerNumber, AgiftDetails.RecipientKey, AgiftDetails.RecipientLedgerNumber,
                Agift.DateEntered, AgiftDetails.MotivationGroupCode, AgiftDetails.MotivationDetailCode);

            AMotivationDetailRow motivationDetailRow = (AMotivationDetailRow)AMotivationDetailTable.Rows.Find(
                new object[] { FLedgerNumber, AgiftDetails.MotivationGroupCode, AgiftDetails.MotivationDetailCode });

            // Account Code is inferred from the motivation detail.
            Boolean IsTaxDeductible = false;
            string NewAccountCode = null;
            string NewTaxDeductibleAccountCode = null;

            if (motivationDetailRow != null)
            {
                IsTaxDeductible = motivationDetailRow.TaxDeductible;
                NewAccountCode = motivationDetailRow.AccountCode;
                NewTaxDeductibleAccountCode = motivationDetailRow.TaxDeductibleAccountCode;
            }

            AgiftDetails.TaxDeductible = IsTaxDeductible;
            AgiftDetails.AccountCode = NewAccountCode;
            AgiftDetails.TaxDeductibleAccountCode = NewTaxDeductibleAccountCode;

            // If the gift has a recipient with no Gift Destination then the import will fail. Gift is added to a table and returned to client.
            if ((AgiftDetails.RecipientLedgerNumber == 0) && (AgiftDetails.MotivationGroupCode == MFinanceConstants.MOTIVATION_GROUP_GIFT))
            {
                ((GiftBatchTDSAGiftDetailRow)AgiftDetails).RecipientDescription = "Fault: RecipientLedger Not known";
                ANeedRecipientLedgerNumber.Rows.Add((object[])AgiftDetails.ItemArray.Clone());
            }

            FMainDS.AGiftDetail.Rows.Add(AgiftDetails);
            return true;
        }
Example #16
0
        public static Boolean GetMotivationGroupAndDetail(Int64 APartnerKey,
                                                          ref String AMotivationGroup,
                                                          ref String AMotivationDetail)
        {
            Boolean PartnerKeyIsValid = false;

            if (APartnerKey != 0)
            {
                string MotivationGroup  = MFinanceConstants.MOTIVATION_GROUP_GIFT;
                string MotivationDetail = AMotivationDetail;

                TDBTransaction readTransaction = null;

                DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                                                                          TEnforceIsolationLevel.eilMinimum,
                                                                          ref readTransaction,
                                                                          delegate
                {
                    PPartnerTable myPPartnerTable = null;

                    myPPartnerTable = PPartnerAccess.LoadByPrimaryKey(APartnerKey, readTransaction);

                    if (myPPartnerTable.Rows.Count == 1)
                    {
                        // Entry for partnerKey is valid
                        PartnerKeyIsValid      = true;
                        PPartnerRow partnerRow = null;

                        partnerRow = (PPartnerRow)myPPartnerTable.Rows[0];

                        // Change motivationDetail if ColumnPartnerClass is UNIT
                        if (partnerRow.PartnerClass.Equals(MPartnerConstants.PARTNERCLASS_UNIT))
                        {
                            // AND KEY-MIN

                            bool KeyMinFound = false;

                            // first check if a motivation detail is linked to this potential key min
                            AMotivationDetailTable MotivationDetailTable = null;

                            MotivationDetailTable = AMotivationDetailAccess.LoadViaPPartner(APartnerKey, readTransaction);

                            if ((MotivationDetailTable != null) && (MotivationDetailTable.Rows.Count > 0))
                            {
                                foreach (AMotivationDetailRow Row in MotivationDetailTable.Rows)
                                {
                                    if (Row.MotivationStatus)
                                    {
                                        MotivationGroup  = MotivationDetailTable[0].MotivationGroupCode;
                                        MotivationDetail = MotivationDetailTable[0].MotivationDetailCode;

                                        KeyMinFound = true;
                                        break;
                                    }
                                }
                            }

                            // second check to see if this is a key min
                            if (!KeyMinFound)
                            {
                                PUnitTable pUnitTable = null;

                                pUnitTable = PUnitAccess.LoadByPrimaryKey(APartnerKey, readTransaction);

                                if (pUnitTable.Rows.Count == 1)
                                {
                                    PUnitRow unitRow = null;

                                    unitRow = (PUnitRow)pUnitTable.Rows[0];

                                    if (unitRow.UnitTypeCode.Equals(MPartnerConstants.UNIT_TYPE_KEYMIN))
                                    {
                                        MotivationDetail = MFinanceConstants.GROUP_DETAIL_KEY_MIN;
                                    }
                                    else
                                    {
                                        MotivationDetail =
                                            TSystemDefaults.GetStringDefault(SharedConstants.SYSDEFAULT_DEFAULTFIELDMOTIVATION,
                                                                             MFinanceConstants.GROUP_DETAIL_FIELD);

                                        // if system default is empty then set to FIELD
                                        if (string.IsNullOrEmpty(MotivationDetail))
                                        {
                                            MotivationDetail = MFinanceConstants.GROUP_DETAIL_FIELD;
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            MotivationDetail = MFinanceConstants.GROUP_DETAIL_SUPPORT;
                        }
                    }
                });

                AMotivationGroup  = MotivationGroup;
                AMotivationDetail = MotivationDetail;
            }

            return(PartnerKeyIsValid);
        }
Example #17
0
        public static Boolean GetMotivationGroupAndDetailForPartner(Int64 APartnerKey,
                                                                    ref String AMotivationGroup,
                                                                    ref String AMotivationDetail)
        {
            Boolean PartnerKeyIsValid = false;

            if (APartnerKey != 0)
            {
                string motivationGroup  = MFinanceConstants.MOTIVATION_GROUP_GIFT;
                string motivationDetail = AMotivationDetail;

                TDBTransaction readTransaction = null;

                DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                                                                          TEnforceIsolationLevel.eilMinimum,
                                                                          ref readTransaction,
                                                                          delegate
                {
                    PPartnerTable myPPartnerTable = PPartnerAccess.LoadByPrimaryKey(APartnerKey, readTransaction);

                    if (myPPartnerTable.Rows.Count == 1)
                    {
                        // partnerKey is valid
                        PartnerKeyIsValid      = true;
                        PPartnerRow partnerRow = myPPartnerTable[0];

                        // Change motivationDetail if PartnerClass is UNIT
                        if (partnerRow.PartnerClass.Equals(MPartnerConstants.PARTNERCLASS_UNIT))
                        {
                            // AND KEY-MIN
                            bool KeyMinFound = false;

                            // first check if a specific motivation detail is linked to this partner
                            AMotivationDetailTable MotivationDetailTable
                                = AMotivationDetailAccess.LoadViaPPartner(APartnerKey, readTransaction);

                            if ((MotivationDetailTable != null) && (MotivationDetailTable.Rows.Count > 0))
                            {
                                foreach (AMotivationDetailRow Row in MotivationDetailTable.Rows)
                                {
                                    if (Row.MotivationStatus)
                                    {
                                        motivationGroup  = MotivationDetailTable[0].MotivationGroupCode;
                                        motivationDetail = MotivationDetailTable[0].MotivationDetailCode;

                                        KeyMinFound = true;
                                        break;     // Go with the first entry found.
                                    }
                                }
                            }

                            if (!KeyMinFound)
                            {
                                // Is this is a key min, or a field?
                                PUnitTable pUnitTable = PUnitAccess.LoadByPrimaryKey(APartnerKey, readTransaction);

                                if (pUnitTable.Rows.Count == 1)
                                {
                                    PUnitRow unitRow = pUnitTable[0];

                                    switch (unitRow.UnitTypeCode)
                                    {
                                    case MPartnerConstants.UNIT_TYPE_AREA:
                                    case MPartnerConstants.UNIT_TYPE_FUND:
                                    case MPartnerConstants.UNIT_TYPE_FIELD:
                                        motivationDetail = MFinanceConstants.GROUP_DETAIL_FIELD;
                                        break;

                                    case MPartnerConstants.UNIT_TYPE_KEYMIN:
                                        motivationDetail = MFinanceConstants.GROUP_DETAIL_KEY_MIN;
                                        break;

                                    case MPartnerConstants.UNIT_TYPE_COUNTRY:
                                    case MPartnerConstants.UNIT_TYPE_CONFERENCE:
                                    case MPartnerConstants.UNIT_TYPE_OTHER:
                                    case MPartnerConstants.UNIT_TYPE_ROOT:
                                    case MPartnerConstants.UNIT_TYPE_TEAM:
                                    case MPartnerConstants.UNIT_TYPE_WORKING_GROUP:
                                    default:
                                        motivationDetail = MFinanceConstants.GROUP_DETAIL_SUPPORT;
                                        break;
                                    }
                                }
                            }
                        }
                        else
                        {
                            motivationDetail = MFinanceConstants.GROUP_DETAIL_SUPPORT;
                        }
                    }
                });

                AMotivationGroup  = motivationGroup;
                AMotivationDetail = motivationDetail;
            }

            return(PartnerKeyIsValid);
        }
Example #18
0
        public void TestPostGiftBatchWithMotivationDetailCostCentre()
        {
            // import a gift batch, that we will modify later
            TGiftImporting importer = new TGiftImporting();

            string testFile = TAppSettingsManager.GetValue("GiftBatch.file", "../../csharp/ICT/Testing/lib/MFinance/SampleData/sampleGiftBatch.csv");
            StreamReader sr = new StreamReader(testFile);
            string FileContent = sr.ReadToEnd();

            FileContent = FileContent.Replace("{ledgernumber}", FLedgerNumber.ToString());
            FileContent = FileContent.Replace("{thisyear}", DateTime.Today.Year.ToString());

            sr.Close();

            Hashtable parameters = new Hashtable();
            parameters.Add("Delimiter", ",");
            parameters.Add("ALedgerNumber", FLedgerNumber);
            parameters.Add("DateFormatString", "yyyy-MM-dd");
            parameters.Add("NumberFormat", "American");
            parameters.Add("NewLine", Environment.NewLine);

            TVerificationResultCollection VerificationResult = null;
            GiftBatchTDSAGiftDetailTable NeedRecipientLedgerNumber;

            if (!importer.ImportGiftBatches(parameters, FileContent, out NeedRecipientLedgerNumber, out VerificationResult))
            {
                Assert.Fail("Gift Batch was not imported: " + VerificationResult.BuildVerificationResultString());
            }

            int BatchNumber = importer.GetLastGiftBatchNumber();

            Assert.AreNotEqual(-1, BatchNumber, "Should have imported the gift batch and returned a valid batch number");

            bool NewTransaction = false;

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

            // create a new costcentre
            const string newCostCentre = "100001";
            if (!ACostCentreAccess.Exists(FLedgerNumber, newCostCentre, Transaction))
            {
                ACostCentreTable cc = new ACostCentreTable();
                ACostCentreRow ccrow = cc.NewRowTyped();
                ccrow.LedgerNumber = FLedgerNumber;
                ccrow.CostCentreCode = newCostCentre;
                ccrow.CostCentreName = newCostCentre;
                ccrow.PostingCostCentreFlag = true;
                ccrow.CostCentreToReportTo = (FLedgerNumber*100).ToString("0000");
                ccrow.CostCentreType = MFinanceConstants.LOCAL_CC_TYPE;
                cc.Rows.Add(ccrow);
                ACostCentreAccess.SubmitChanges(cc, Transaction, UserInfo.GUserInfo.UserID);
            }

            // create a new motivation detail
            if (!AMotivationDetailAccess.Exists(FLedgerNumber, MFinanceConstants.MOTIVATION_GROUP_GIFT, newCostCentre, Transaction))
            {
                AMotivationDetailTable mot = new AMotivationDetailTable();
                AMotivationDetailRow motrow = mot.NewRowTyped();
                motrow.LedgerNumber = FLedgerNumber;
                motrow.MotivationGroupCode = MFinanceConstants.MOTIVATION_GROUP_GIFT;
                motrow.MotivationDetailCode = newCostCentre;
                motrow.AccountCode = "0100";
                motrow.CostCentreCode = newCostCentre;
                motrow.MotivationDetailDesc = newCostCentre;
                mot.Rows.Add(motrow);
                AMotivationDetailAccess.SubmitChanges(mot, Transaction, UserInfo.GUserInfo.UserID);
            }

            // modify the gift batch with that motivation detail, but with wrong costcentre
            AGiftDetailTable giftdetails = AGiftDetailAccess.LoadByPrimaryKey(FLedgerNumber, BatchNumber, 1, 1, null, Transaction);
            giftdetails[0].MotivationDetailCode = newCostCentre;
            giftdetails[0].RecipientKey = 0;
            Assert.AreNotEqual(newCostCentre, giftdetails[0].CostCentreCode, "cost centre code should not match the one defined by the motivation detail");
            AGiftDetailAccess.SubmitChanges(giftdetails, Transaction);

            DBAccess.GDBAccessObj.CommitTransaction();

            if (!TGiftTransactionWebConnector.PostGiftBatch(FLedgerNumber, BatchNumber, out VerificationResult))
            {
                Assert.Fail("Gift Batch was not posted: " + VerificationResult.BuildVerificationResultString());
            }

            Transaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted, out NewTransaction);
            giftdetails = AGiftDetailAccess.LoadByPrimaryKey(FLedgerNumber, BatchNumber, 1, 1, null, Transaction);
            Assert.AreEqual(newCostCentre, giftdetails[0].CostCentreCode, "cost centre code should have been adjusted because of the motivation detail");
            DBAccess.GDBAccessObj.CommitTransaction();
        }