コード例 #1
0
        // This manual method lets us peek at the data that is about to be saved...
        // The data has already been collected from the contols and validated and there is definitely something to save...
        private TSubmitChangesResult StoreManualCode(ref GiftBatchTDS SubmitDS, out TVerificationResultCollection VerificationResult)
        {
            FLatestSaveIncludedForex = false;

            if (SubmitDS.AGiftBatch != null)
            {
                // Check whether we are saving any rows that are in foreign currency
                DataView dv = new DataView(SubmitDS.AGiftBatch,
                                           String.Format("{0}<>'{1}'", AGiftBatchTable.GetCurrencyCodeDBName(), FMainDS.ALedger[0].BaseCurrency),
                                           String.Empty, DataViewRowState.CurrentRows);
                FLatestSaveIncludedForex = (dv.Count > 0);
            }

            // Now do the standard call to save the changes
            return(TRemote.MFinance.Gift.WebConnectors.SaveGiftBatchTDS(ref SubmitDS, out VerificationResult));
        }
コード例 #2
0
ファイル: Gift.cs プロジェクト: Kingefosa/openpetra
        /// <summary>
        /// get more details of the last gift of the partner
        /// </summary>
        /// <param name="APartnerKey"></param>
        /// <param name="ALastGiftDate"></param>
        /// <param name="ALastGiftAmount"></param>
        /// <param name="ALastGiftGivenToPartnerKey"></param>
        /// <param name="ALastGiftRecipientLedger"></param>
        /// <param name="ALastGiftCurrencyCode"></param>
        /// <param name="ALastGiftDisplayFormat"></param>
        /// <param name="ALastGiftGivenToShortName"></param>
        /// <param name="ALastGiftRecipientLedgerShortName"></param>
        /// <param name="ARestrictedOrConfidentialGiftAccessDenied"></param>
        /// <returns></returns>
        public static Boolean GetLastGiftDetails(Int64 APartnerKey,
                                                 out DateTime ALastGiftDate,
                                                 out decimal ALastGiftAmount,
                                                 out Int64 ALastGiftGivenToPartnerKey,
                                                 out Int64 ALastGiftRecipientLedger,
                                                 out String ALastGiftCurrencyCode,
                                                 out String ALastGiftDisplayFormat,
                                                 out String ALastGiftGivenToShortName,
                                                 out String ALastGiftRecipientLedgerShortName,
                                                 out Boolean ARestrictedOrConfidentialGiftAccessDenied)
        {
            DataSet          LastGiftDS;
            AGiftDetailTable GiftDetailDT;
            SGroupGiftTable  GroupGiftDT;
            SUserGroupTable  UserGroupDT;
            AGiftRow         GiftDR;
            AGiftBatchRow    GiftBatchDR;
            AGiftDetailRow   GiftDetailDR;
            ACurrencyRow     CurrencyDR;
            Int16            Counter;
            Boolean          AccessToGift = false;

            DataRow[] FoundUserGroups;

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

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

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

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

            TDBTransaction Transaction  = null;
            bool           SubmissionOK = true;

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

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

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

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

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

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

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

                    if (AccessToGift)
                    {
                        tmpLastGiftDate = GiftDR.DateEntered;

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

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

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

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

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

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

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

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

                                    tmpLastGiftAmount = tmpLastGiftAmount + GiftDetailDR.GiftTransactionAmount;
                                }

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

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

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

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

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

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

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

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

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

            return(AccessToGift);
        }
コード例 #3
0
        /// <summary>
        /// Carry out the gift adjustment (field or tax deductible pct)
        /// </summary>
        /// <param name="AGiftBatchDS">Gift Batch containing GiftDetail rows for all gifts to be adjusted.</param>
        /// <param name="ANewPct">New Tax Deductible Percentage (null if not being used)</param>
        /// <param name="ANoReceipt">True if no receipt</param>
        /// <param name="AParentForm"></param>
        public static void GiftAdjustment(GiftBatchTDS AGiftBatchDS, decimal?ANewPct, bool ANoReceipt, Form AParentForm)
        {
            // sort gift batches so like batches are together
            AGiftBatchDS.AGiftBatch.DefaultView.Sort = AGiftBatchTable.GetLedgerNumberDBName() + " ASC, " +
                                                       AGiftBatchTable.GetCurrencyCodeDBName() + " ASC, " +
                                                       AGiftBatchTable.GetBankCostCentreDBName() + " ASC, " +
                                                       AGiftBatchTable.GetBankAccountCodeDBName() + " ASC, " +
                                                       AGiftBatchTable.GetGiftTypeDBName() + " ASC";

            GiftBatchTDS NewGiftDS = new GiftBatchTDS();

            NewGiftDS.AGiftDetail.Merge(new GiftBatchTDSAGiftDetailTable());

            for (int i = 0; i < AGiftBatchDS.AGiftBatch.Rows.Count; i++)
            {
                AGiftBatchRow OldGiftBatch  = (AGiftBatchRow)AGiftBatchDS.AGiftBatch.DefaultView[i].Row;
                AGiftBatchRow NextGiftBatch = null;

                // add batch's gift/s to dataset
                DataView Gifts = new DataView(AGiftBatchDS.AGift);
                Gifts.RowFilter = string.Format("{0}={1}",
                                                AGiftDetailTable.GetBatchNumberDBName(),
                                                OldGiftBatch.BatchNumber);

                foreach (DataRowView giftRows in Gifts)
                {
                    AGiftRow gR = (AGiftRow)giftRows.Row;
                    NewGiftDS.AGift.ImportRow(gR);
                }

                // add batch's gift detail/s to dataset
                DataView GiftDetails = new DataView(AGiftBatchDS.AGiftDetail);
                GiftDetails.RowFilter = string.Format("{0}={1}",
                                                      AGiftDetailTable.GetBatchNumberDBName(),
                                                      OldGiftBatch.BatchNumber);

                foreach (DataRowView giftDetailRows in GiftDetails)
                {
                    AGiftDetailRow gDR = (AGiftDetailRow)giftDetailRows.Row;
                    NewGiftDS.AGiftDetail.ImportRow(gDR);
                }

                // if not the last row
                if (i != AGiftBatchDS.AGiftBatch.Rows.Count - 1)
                {
                    NextGiftBatch = (AGiftBatchRow)AGiftBatchDS.AGiftBatch.DefaultView[i + 1].Row;
                }

                // if this is the last batch or if the next batch's gifts need to be added to a different new batch
                if ((NextGiftBatch == null) ||
                    (NextGiftBatch.LedgerNumber != OldGiftBatch.LedgerNumber) ||
                    (NextGiftBatch.CurrencyCode != OldGiftBatch.CurrencyCode) ||
                    (NextGiftBatch.BankCostCentre != OldGiftBatch.BankCostCentre) ||
                    (NextGiftBatch.BankAccountCode != OldGiftBatch.BankAccountCode) ||
                    (NextGiftBatch.GiftType != OldGiftBatch.GiftType))
                {
                    TFrmGiftRevertAdjust AdjustForm = new TFrmGiftRevertAdjust(AParentForm);

                    try
                    {
                        AParentForm.ShowInTaskbar = false;

                        AdjustForm.LedgerNumber = OldGiftBatch.LedgerNumber;
                        AdjustForm.CurrencyCode = OldGiftBatch.CurrencyCode;
                        AdjustForm.Text         = "Adjust Gift";
                        AdjustForm.AddParam("Function", GiftAdjustmentFunctionEnum.FieldAdjust);
                        AdjustForm.GiftMainDS = NewGiftDS;
                        AdjustForm.NoReceipt  = ANoReceipt;

                        AdjustForm.AddBatchDetailsToScreen(OldGiftBatch.LedgerNumber, OldGiftBatch.CurrencyCode,
                                                           OldGiftBatch.BankCostCentre, OldGiftBatch.BankAccountCode, OldGiftBatch.GiftType);

                        if (ANewPct != null)
                        {
                            AdjustForm.AddParam("Function", GiftAdjustmentFunctionEnum.TaxDeductiblePctAdjust);
                            AdjustForm.AddParam("NewPct", ANewPct);

                            // gift destination must be the original for tax deduct pct adjustments
                            AdjustForm.AddParam("FixedGiftDestination", true);

                            // comments will be auto completed
                            AdjustForm.AutoCompleteComments();
                        }
                        else
                        {
                            AdjustForm.AddParam("Function", GiftAdjustmentFunctionEnum.FieldAdjust);
                        }

                        AdjustForm.GiftDetailRow = NewGiftDS.AGiftDetail[0];

                        if (AdjustForm.IsDisposed || (AdjustForm.ShowDialog() != DialogResult.OK))
                        {
                            continue;
                        }
                    }
                    finally
                    {
                        AParentForm.Cursor = Cursors.WaitCursor;
                        AdjustForm.Dispose();
                        AParentForm.ShowInTaskbar = true;
                        NewGiftDS.AGiftDetail.Clear();
                        NewGiftDS.AGift.Clear();
                        AParentForm.Cursor = Cursors.Default;
                    }
                }
            }
        }