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

            #region Check if the business participants already have booking account and skip creation for them.

            var checkParam = new CL3_BookingAccounts.Atomic.Retrieval.P_L3BA_GBAPBPAfBP_1717
            {
                FiscalYearID = Parameter.FiscalYearID,
                BusinessParticipantID_List = Parameter.BusinessParticipantIDs
            };

            var bpThatAlreadyHaveAccountArray = CL3_BookingAccounts.Atomic.Retrieval.cls_Get_BookingAccount_Purpose_BPAssignment_for_BPID_List.Invoke(
                Connection, Transaction, checkParam, securityTicket).Result.Select(x => x.BusinessParticipant_RefID);

            var bpItems = Parameter.BusinessParticipantIDs.Except(bpThatAlreadyHaveAccountArray);

            #endregion

            foreach (var BPID in bpItems)
            {
                var accBPAssignment = CL3_BookingAccounts.Utils.BookingAccountUtils.GetEmptyCustomerAccount();

                #region Business participant's data

                var customer = CL1_CMN_BPT_CTM.ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction,
                                                                                     new CL1_CMN_BPT_CTM.ORM_CMN_BPT_CTM_Customer.Query
                {
                    Ext_BusinessParticipant_RefID = BPID,
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID
                }).Single();

                var businessParticipant = CL1_CMN_BPT.ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction,
                                                                                                   new CL1_CMN_BPT.ORM_CMN_BPT_BusinessParticipant.Query
                {
                    CMN_BPT_BusinessParticipantID = BPID,
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID
                }).Single();

                #endregion

                #region Create booking account

                var bookingAccount = new CL1_ACC_BOK.ORM_ACC_BOK_BookingAccount
                {
                    ACC_BOK_BookingAccountID = Guid.NewGuid(),
                    BookingAccountName       = businessParticipant.DisplayName, // TODO: just name or something else?
                    BookingAccountNumber     = customer.InternalCustomerNumber,
                    FiscalYear_RefID         = Parameter.FiscalYearID,
                    Creation_Timestamp       = DateTime.Now,
                    Tenant_RefID             = securityTicket.TenantID
                };
                bookingAccount.Save(Connection, Transaction);

                #endregion

                #region Create Account assignment to booking account as "Customer Account"

                var accountAssignment = CL3_BookingAccounts.Utils.BookingAccountUtils.GetEmptyCustomerAccount();
                accountAssignment.ACC_BOK_BookingAccounts_Purpose_BP_AssignmentID = Guid.NewGuid();
                accountAssignment.BookingAccount_RefID      = bookingAccount.ACC_BOK_BookingAccountID;
                accountAssignment.BusinessParticipant_RefID = BPID;
                accountAssignment.Creation_Timestamp        = DateTime.Now;
                accountAssignment.Tenant_RefID = securityTicket.TenantID;

                accountAssignment.Save(Connection, Transaction);

                #endregion
            }

            returnValue.Result = true;
            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_L3BA_CCAfBP_1655 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_Create_Customer_Account_for_BusinessParticipants", 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_L3BA_CCAfBP_1655 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_L3BA_CCAfBP_1655 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
 {
     return(Invoke(Connection, Transaction, null, Parameter, securityTicket));
 }
Beispiel #5
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L3BA_CBAfFY_1249 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            Guid currentFiscalYearID = Parameter.ACC_FiscalYearID;

            #region Get current fiscal year if none is given by the parameter

            if (currentFiscalYearID == Guid.Empty)
            {
                currentFiscalYearID = CL2_FiscalYear.Complex.Retrieval.cls_Get_Current_FiscalYear.Invoke(Connection, Transaction, securityTicket).Result.ACC_FiscalYearID;
            }

            #endregion

            #region Get tenant's business participant ID

            var tenantBusinessParticipantID = CL1_CMN_BPT.ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new
                                                                                                       CL1_CMN_BPT.ORM_CMN_BPT_BusinessParticipant.Query
            {
                IsDeleted             = false,
                IsTenant              = true,
                IfTenant_Tenant_RefID = securityTicket.TenantID
            }).Single().CMN_BPT_BusinessParticipantID;

            #endregion

            #region Create VAT accounts (made for each tax)

            var taxParam = new P_L3BA_CTBAfFY_1530
            {
                BusinessParticipantID = tenantBusinessParticipantID,
                FiscalYearID          = currentFiscalYearID
            };

            cls_Create_Tax_Booking_Accounts_for_FiscalYear.Invoke(Connection, Transaction, taxParam, securityTicket);

            #endregion

            #region Create customer accounts for each business participant that is the customer

            var customerBPIDs = CL1_CMN_BPT_CTM.ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction,
                                                                                      new CL1_CMN_BPT_CTM.ORM_CMN_BPT_CTM_Customer.Query
            {
                IsDeleted    = false,
                Tenant_RefID = securityTicket.TenantID
            }).Select(x => x.Ext_BusinessParticipant_RefID);

            if (customerBPIDs.Count() > 0)
            {
                var customerAccParam = new P_L3BA_CCAfBP_1655
                {
                    FiscalYearID           = currentFiscalYearID,
                    BusinessParticipantIDs = customerBPIDs.ToArray()
                };
                cls_Create_Customer_Account_for_BusinessParticipants.Invoke(Connection, Transaction, customerAccParam, securityTicket);
            }

            #endregion

            #region Create revenue account for business participant that is the current tenant

            var revAccParam = new P_L3BA_CRAfT_0903
            {
                FiscalYearID = currentFiscalYearID
            };

            cls_Create_Revenue_Account_for_TenantID.Invoke(Connection, Transaction, revAccParam, securityTicket);

            #endregion

            #region Create bank account for business participant that is the current tenant

            var tenantBP = CL1_CMN_BPT.ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction,
                                                                                    new CL1_CMN_BPT.ORM_CMN_BPT_BusinessParticipant.Query
            {
                IsTenant = true,
                IfTenant_Tenant_RefID = securityTicket.TenantID,
                Tenant_RefID          = securityTicket.TenantID
            }).Single();

            var bnkAccParam = new P_L3BA_CBA_1141
            {
                FiscalYearID          = currentFiscalYearID,
                BusinessParticipantID = tenantBP.CMN_BPT_BusinessParticipantID,
                BookingAccountName    = tenantBP.DisplayName
            };

            cls_Create_Bank_Account.Invoke(Connection, Transaction, bnkAccParam, securityTicket);

            #endregion

            return(returnValue);

            #endregion UserCode
        }