Ejemplo n.º 1
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
        }
        protected static FR_Bool Execute(DbConnection Connection, DbTransaction Transaction, P_L3BA_CRAfT_0903 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Bool();

            #region Tenant's Business Participant

            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();

            #endregion

            #region Retrieve all valid taxes

            var taxQuery = new CL1_ACC_TAX.ORM_ACC_TAX_Tax.Query
            {
                IsDeleted    = false,
                Tenant_RefID = securityTicket.TenantID
            };
            var taxes = CL1_ACC_TAX.ORM_ACC_TAX_Tax.Query.Search(Connection, Transaction, taxQuery);

            #endregion

            int counter = 0;
            foreach (var tax in taxes)
            {
                #region Booking Account

                var bookingAccountParam = new P_L3BA_CBA_1305
                {
                    FiscalYearID         = Parameter.FiscalYearID,
                    BookingAccountName   = tenantBP.DisplayName,
                    BookingAccountNumber = String.Format("{0:000000000000}", counter + 1)
                };
                Guid bookingAccountID = cls_Create_Booking_Account.Invoke(Connection, Transaction, bookingAccountParam, securityTicket).Result;

                #endregion

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

                var bookingAccountTypeParam = new P_L3BA_SBAT_1310
                {
                    BookingAccountID      = bookingAccountID,
                    BusinessParticipantID = tenantBP.CMN_BPT_BusinessParticipantID,
                    FiscalYearID          = Parameter.FiscalYearID,
                    IsRevenueAccount      = true,
                    TaxRate = tax.TaxRate
                };
                cls_Set_Booking_Account_Type.Invoke(Connection, Transaction, bookingAccountTypeParam, securityTicket);

                #endregion
            }

            returnValue.Result = true;
            return(returnValue);

            #endregion UserCode
        }
 ///<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_CRAfT_0903 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
 {
     return(Invoke(Connection, Transaction, null, Parameter, securityTicket));
 }
        ///<summary>
        /// Method Invocation of wrapper classes
        ///<summary>
        protected static FR_Bool Invoke(DbConnection Connection, DbTransaction Transaction, string ConnectionString, P_L3BA_CRAfT_0903 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_Revenue_Account_for_TenantID", ex);
            }
            return(functionReturn);
        }
 ///<summary>
 /// Opens the connection/transaction for the given connectionString, and closes them when complete
 ///<summary>
 public static FR_Bool Invoke(string ConnectionString, P_L3BA_CRAfT_0903 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
 {
     return(Invoke(null, null, ConnectionString, Parameter, securityTicket));
 }