Beispiel #1
0
        protected static FR_Bool Execute(DbConnection Connection, DbTransaction Transaction, P_L3IP_CIPSH_1447 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Bool();
            returnValue.Result = false;

            var installmentPlan = new CL1_ACC_IPL.ORM_ACC_IPL_InstallmentPlan();
            installmentPlan.Load(Connection, Transaction, Parameter.InstallmentPlanID);

            var statuses = CL1_ACC_IPL.ORM_ACC_IPL_InstallmentPlan_Status.Query.Search(Connection, Transaction,
                                                                                       new CL1_ACC_IPL.ORM_ACC_IPL_InstallmentPlan_Status.Query
            {
                IsDeleted    = false,
                Tenant_RefID = securityTicket.TenantID
            });

            bool isNotFullyPaidInstallmentPlan = CL1_ACC_IPL.ORM_ACC_IPL_Installment.Query.Exists(Connection, Transaction,
                                                                                                  new CL1_ACC_IPL.ORM_ACC_IPL_Installment.Query
            {
                InstallmentPlan_RefID = installmentPlan.ACC_IPL_InstallmentPlanID,
                IsFullyPaid           = false,
                IsDeleted             = false,
                Tenant_RefID          = securityTicket.TenantID
            });

            var BusinessParticipantID = CL1_USR.ORM_USR_Account.Query.Search(Connection, Transaction,
                                                                             new CL1_USR.ORM_USR_Account.Query
            {
                USR_AccountID = securityTicket.AccountID,
                IsDeleted     = false,
                Tenant_RefID  = securityTicket.TenantID
            }).Single().BusinessParticipant_RefID;

            // prepare new status history entry
            var newStatusHistoryEntry = new CL1_ACC_IPL.ORM_ACC_IPL_InstallmentPlan_StatusHistory
            {
                ACC_IPL_InstallmentPlan_StatusHistoryID = Guid.NewGuid(),
                ACC_IPL_InstallmentPlan_RefID           = installmentPlan.ACC_IPL_InstallmentPlanID,
                PerformedBy_BusinessParticipant_RefID   = BusinessParticipantID,
                Creation_Timestamp = DateTime.Now,
                Tenant_RefID       = securityTicket.TenantID
            };

            bool doUpdateStatus = false;
            EInstallmentPlanStatus newStatusEnum = EInstallmentPlanStatus.Created;

            if (Parameter.DoTerminate)
            {
                doUpdateStatus = true;
                newStatusEnum  = EInstallmentPlanStatus.Terminated;
            }
            else if (isNotFullyPaidInstallmentPlan)
            {
                // Find out in which status Installment plan is
                var currentStatusMatchingID = statuses.Single(x => x.ACC_IPL_InstallmentPlan_StatusID == installmentPlan.Current_InstallmentPlanStatus_RefID).GlobalPropertyMatchingID;

                // If installment plan is not fully paid and if it is not in that status already, make it so
                if (currentStatusMatchingID != EnumUtils.GetEnumDescription(EInstallmentPlanStatus.PartiallyPayed))
                {
                    doUpdateStatus = true;
                    newStatusEnum  = EInstallmentPlanStatus.PartiallyPayed;
                }
            }
            else
            {
                // If it is fully paid and not going to be terminated, installment plan has status 'PayedInTotal'
                doUpdateStatus = true;
                newStatusEnum  = EInstallmentPlanStatus.PayedInTotal;
            }

            // finally, save status
            if (doUpdateStatus)
            {
                newStatusHistoryEntry.ACC_IPL_InstallmentPlan_Status_RefID = statuses.Single(
                    x => x.GlobalPropertyMatchingID == EnumUtils.GetEnumDescription(newStatusEnum)).ACC_IPL_InstallmentPlan_StatusID;
                newStatusHistoryEntry.Save(Connection, Transaction);

                installmentPlan.Current_InstallmentPlanStatus_RefID = newStatusHistoryEntry.ACC_IPL_InstallmentPlan_Status_RefID;
                installmentPlan.Save(Connection, Transaction);
            }

            return(returnValue);

            #endregion UserCode
        }
Beispiel #2
0
        ///<summary>
        /// Method Invocation of wrapper classes
        ///<summary>
        protected static FR_Bool Invoke(DbConnection Connection, DbTransaction Transaction, string ConnectionString, P_L3IP_CIPSH_1447 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            bool cleanupConnection  = Connection == null;
            bool cleanupTransaction = Transaction == null;

            FR_Bool functionReturn = new FR_Bool();

            try
            {
                if (cleanupConnection == true)
                {
                    Connection = CSV2Core_MySQL.Support.DBSQLSupport.CreateConnection(ConnectionString);
                    Connection.Open();
                }
                if (cleanupTransaction == true)
                {
                    Transaction = Connection.BeginTransaction();
                }

                functionReturn = Execute(Connection, Transaction, Parameter, securityTicket);

                #region Cleanup Connection/Transaction
                //Commit the transaction
                if (cleanupTransaction == true)
                {
                    Transaction.Commit();
                }
                //Close the connection
                if (cleanupConnection == true)
                {
                    Connection.Close();
                }
                #endregion
            }
            catch (Exception ex)
            {
                try
                {
                    if (cleanupTransaction == true && Transaction != null)
                    {
                        Transaction.Rollback();
                    }
                }
                catch { }

                try
                {
                    if (cleanupConnection == true && Connection != null)
                    {
                        Connection.Close();
                    }
                }
                catch { }

                throw new Exception("Exception occured in method cls_Change_InstallmentPlan_StatusHistory", ex);
            }
            return(functionReturn);
        }
Beispiel #3
0
 ///<summary>
 /// Opens the connection/transaction for the given connectionString, and closes them when complete
 ///<summary>
 public static FR_Bool Invoke(string ConnectionString, P_L3IP_CIPSH_1447 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
 {
     return(Invoke(null, null, ConnectionString, Parameter, securityTicket));
 }
Beispiel #4
0
 ///<summary>
 /// Invokes the method for the given Connection, and Transaction, leaving them open/not commited if no exceptions occured
 ///<summary>
 public static FR_Bool Invoke(DbConnection Connection, DbTransaction Transaction, P_L3IP_CIPSH_1447 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
 {
     return(Invoke(Connection, Transaction, null, Parameter, securityTicket));
 }
Beispiel #5
0
        protected static FR_Guids Execute(DbConnection Connection, DbTransaction Transaction, P_L3IP_AATfIP_1331 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guids();

            /*
             * 0. Load current's account business participant ID
             * 1. Find all not fully payed installments
             * 2. Assign payment to open installments
             * 3. Change installment plan status history
             *
             */

            List <Guid> updatedInstallmentIDs = new List <Guid>();

            #region 0. Load current's account business participant ID

            var account = CL1_USR.ORM_USR_Account.Query.Search(Connection, Transaction,
                                                               new CL1_USR.ORM_USR_Account.Query
            {
                USR_AccountID = securityTicket.AccountID,
                IsDeleted     = false,
                Tenant_RefID  = securityTicket.TenantID
            }).Single();

            #endregion

            #region 1. Find all not fully payed installments

            var installments = CL1_ACC_IPL.ORM_ACC_IPL_Installment.Query.Search(Connection, Transaction,
                                                                                new CL1_ACC_IPL.ORM_ACC_IPL_Installment.Query
            {
                InstallmentPlan_RefID = Parameter.InstallmentPlanID,
                IsFullyPaid           = false,
                IsDeleted             = false,
                Tenant_RefID          = securityTicket.TenantID
            }).OrderBy(x => x.PaymentDeadline);

            #endregion

            #region 2. Assign payment to open installments and set to fully paid if needed

            CL1_ACC_IPL.ORM_ACC_IPL_Installment_2_AssignedPayment             installment2AssignedPayment             = null;
            CL1_ACC_IPL.ORM_ACC_IPL_Installment_2_AccountTransactionPairBatch installment2AccountTransactionPairBatch = null;

            decimal unassignedAmount = Parameter.TransactionAmount;
            foreach (var item in installments)
            {
                // stop if unassigned amount has reached zero
                if (Decimal.Compare(unassignedAmount, 0M) == 0)
                {
                    break;
                }

                /**
                 * assigned value is amount on installment by default,
                 * but if it is less than unassigned amount it receives the value of unassigned amount
                 */
                bool isFullyPaid = (item.Amount <= unassignedAmount);

                decimal amountAssignedToInstallment = isFullyPaid ? item.Amount : unassignedAmount;

                installment2AssignedPayment = new CL1_ACC_IPL.ORM_ACC_IPL_Installment_2_AssignedPayment
                {
                    ACC_IPL_Installment_2_AssignedPaymentID = Guid.NewGuid(),
                    ACC_BOK_Accounting_Transaction_RefID    = Parameter.AccountingTransactionID,
                    ACC_IPL_Installment_RefID            = item.ACC_IPL_InstallmentID,
                    AssignedValue                        = amountAssignedToInstallment,
                    AssignedBy_BusinessParticipant_RefID = account.BusinessParticipant_RefID,
                    Creation_Timestamp                   = DateTime.Now,
                    Tenant_RefID = securityTicket.TenantID
                };
                installment2AssignedPayment.Save(Connection, Transaction);

                installment2AccountTransactionPairBatch = new CL1_ACC_IPL.ORM_ACC_IPL_Installment_2_AccountTransactionPairBatch
                {
                    AssignmentID = Guid.NewGuid(),
                    ACC_BOK_Accounting_Transaction_RefID = Parameter.AccountingTransactionID,
                    ACC_IPL_Installment_RefID            = item.ACC_IPL_InstallmentID,
                    Creation_Timestamp = DateTime.Now,
                    Tenant_RefID       = securityTicket.TenantID
                };
                installment2AccountTransactionPairBatch.Save(Connection, Transaction);

                #region Set current as fully paid and adjust amount if it is lower than the part of the payment can cover

                if (item.Amount < amountAssignedToInstallment)
                {
                    item.Amount = amountAssignedToInstallment;
                }
                item.IsFullyPaid = true;
                item.Save(Connection, Transaction);

                #endregion

                if (isFullyPaid == false)
                {
                    #region Create new installment with the amount that is left on current installment

                    var newInstallment = new CL1_ACC_IPL.ORM_ACC_IPL_Installment
                    {
                        ACC_IPL_InstallmentID = Guid.NewGuid(),
                        InstallmentPlan_RefID = Parameter.InstallmentPlanID,
                        PaymentDeadline       = item.PaymentDeadline,
                        IsFullyPaid           = false,
                        Amount       = item.Amount - unassignedAmount,
                        Tenant_RefID = securityTicket.TenantID
                    };

                    newInstallment.IsFullyPaid = false;
                    newInstallment.Save(Connection, Transaction);

                    #endregion
                }

                unassignedAmount -= amountAssignedToInstallment;

                updatedInstallmentIDs.Add(item.ACC_IPL_InstallmentID);
            }

            #endregion

            #region 3. Change installment plan status history

            var statusHistoryParam = new P_L3IP_CIPSH_1447
            {
                InstallmentPlanID = Parameter.InstallmentPlanID,
                DoTerminate       = false
            };
            cls_Change_InstallmentPlan_StatusHistory.Invoke(Connection, Transaction, statusHistoryParam, securityTicket);

            #endregion

            returnValue.Result = updatedInstallmentIDs.ToArray();

            return(returnValue);

            #endregion UserCode
        }