Ejemplo n.º 1
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L3IP_SIP_1718 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();
            returnValue.Result = Guid.Empty;

            bool isNew = Parameter.InstallmentPlanID == Guid.Empty;

            Guid currencyID = CL2_Currency.Atomic.Retrieval.cls_Get_DefaultCurrency_for_Tenant.Invoke(Connection, Transaction, securityTicket).Result.CMN_CurrencyID;

            var installmentPlan = new CL1_ACC_IPL.ORM_ACC_IPL_InstallmentPlan();
            var statusHistory   = new CL1_ACC_IPL.ORM_ACC_IPL_InstallmentPlan_StatusHistory();

            var firstDate = DateTime.Now;

            if (isNew)
            {
                #region Create new Installment Plan

                installmentPlan.ACC_IPL_InstallmentPlanID = Guid.NewGuid();

                installmentPlan.InstallmentPeriodType = 0;
                installmentPlan.InstallmentStart      = firstDate;
                installmentPlan.Currency_RefID        = currencyID;
                installmentPlan.Creation_Timestamp    = DateTime.Now;
                installmentPlan.Tenant_RefID          = securityTicket.TenantID;

                Guid statusID = CL1_ACC_IPL.ORM_ACC_IPL_InstallmentPlan_Status.Query.Search(Connection, Transaction,
                                                                                            new CL1_ACC_IPL.ORM_ACC_IPL_InstallmentPlan_Status.Query
                {
                    GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(EInstallmentPlanStatus.Created),
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID
                }).Single().ACC_IPL_InstallmentPlan_StatusID;

                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;

                statusHistory = new CL1_ACC_IPL.ORM_ACC_IPL_InstallmentPlan_StatusHistory
                {
                    ACC_IPL_InstallmentPlan_StatusHistoryID = Guid.NewGuid(),
                    ACC_IPL_InstallmentPlan_RefID           = installmentPlan.ACC_IPL_InstallmentPlanID,
                    ACC_IPL_InstallmentPlan_Status_RefID    = statusID,
                    PerformedBy_BusinessParticipant_RefID   = BusinessParticipantID,
                    StatusHistoryComment = Parameter.Comment,
                    Creation_Timestamp   = DateTime.Now,
                    Tenant_RefID         = securityTicket.TenantID
                };
                statusHistory.Save(Connection, Transaction);

                installmentPlan.Current_InstallmentPlanStatus_RefID = statusID;

                #endregion
            }
            else
            {
                #region Load existing InstallmentPlan

                var fetched = installmentPlan.Load(Connection, Transaction, Parameter.InstallmentPlanID);
                if (fetched.Status != FR_Status.Success || installmentPlan.ACC_IPL_InstallmentPlanID != Parameter.InstallmentPlanID)
                {
                    returnValue.Status = FR_Status.Error_Internal;
                    return(returnValue);
                }

                #endregion
            }

            installmentPlan.NominalValue = Parameter.NominalValue;

            installmentPlan.Save(Connection, Transaction);

            #region Save Installments

            CL1_ACC_IPL.ORM_ACC_IPL_Installment installment = null;
            foreach (var item in Parameter.Installments)
            {
                if (item.InstallmentID == Guid.Empty)
                {
                    installment = new CL1_ACC_IPL.ORM_ACC_IPL_Installment
                    {
                        ACC_IPL_InstallmentID = Guid.NewGuid(),
                        InstallmentPlan_RefID = installmentPlan.ACC_IPL_InstallmentPlanID,
                        IsFullyPaid           = false,
                        Creation_Timestamp    = DateTime.Now,
                        Tenant_RefID          = securityTicket.TenantID
                    };
                }
                else
                {
                    installment = new CL1_ACC_IPL.ORM_ACC_IPL_Installment();
                    var fetched = installment.Load(Connection, Transaction, item.InstallmentID);
                    if (fetched.Status != FR_Status.Success || installment.ACC_IPL_InstallmentID != item.InstallmentID)
                    {
                        returnValue.Status = FR_Status.Error_Internal;
                        return(returnValue);
                    }
                }

                installment.PaymentDeadline = item.PaymentDeadline;
                installment.Amount          = item.Amount;

                installment.Save(Connection, Transaction);
            }

            #endregion

            returnValue.Result = installmentPlan.ACC_IPL_InstallmentPlanID;
            return(returnValue);

            #endregion UserCode
        }
Ejemplo n.º 2
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
        }