Exemple #1
0
 public SqlCommand EditOneTranCode(Trancode_Info objTrancode_Info)
 {
     try
     {
         SqlCommand command = new SqlCommand(
             "UPDATE Trancode SET "
             + "Name = @Name, "
             + "Status = @Status, "
             + "Categories = @Categories, "
             + "NextCode = @NextCode, "
             + "CostCode = @CostCode, "
             + "Descript = @Descript, "
             + "CodeType = @CodeType, "
             + "AllowReverse = @AllowReverse, "
             + "Report = @Report, "
             + "Display = @Display, "
             + "formula = @formula, "
             + "RefNum = @RefNum, "
             + "CheckOn = @CheckOn, "
             + "DateCreated = @DateCreated, "
             + "UserCreate = @UserCreate, "
             + "Branch_ID = @Branch_ID "
             + "WHERE Code = @Code");
         command.CommandType = CommandType.Text;
         command.Parameters.Clear();
         command.Parameters.Add("@Code", SqlDbType.NVarChar, 5).Value        = objTrancode_Info.Code;
         command.Parameters.Add("@Name", SqlDbType.NVarChar, 135).Value      = objTrancode_Info.Name;
         command.Parameters.Add("@Status", SqlDbType.Bit).Value              = objTrancode_Info.Status;
         command.Parameters.Add("@Categories", SqlDbType.NVarChar, 45).Value = objTrancode_Info.Categories;
         command.Parameters.Add("@NextCode", SqlDbType.NVarChar, 5).Value    = objTrancode_Info.NextCode;
         command.Parameters.Add("@CostCode", SqlDbType.NVarChar, 10).Value   = objTrancode_Info.CostCode;
         command.Parameters.Add("@Descript", SqlDbType.NVarChar, 135).Value  = objTrancode_Info.Descript;
         command.Parameters.Add("@CodeType", SqlDbType.NVarChar, 25).Value   = objTrancode_Info.CodeType.ToString();
         command.Parameters.Add("@AllowReverse", SqlDbType.Bit).Value        = objTrancode_Info.AllowReverse;
         command.Parameters.Add("@Report", SqlDbType.Bit).Value              = objTrancode_Info.Report;
         command.Parameters.Add("@Display", SqlDbType.Bit).Value             = objTrancode_Info.Display;
         command.Parameters.Add("@formula", SqlDbType.NVarChar, 135).Value   = objTrancode_Info.Formula;
         command.Parameters.Add("@RefNum", SqlDbType.NVarChar, 4).Value      = objTrancode_Info.RefNum;
         command.Parameters.Add("@CheckOn", SqlDbType.Bit).Value             = objTrancode_Info.CheckOn;
         command.Parameters.Add("@DateCreated", SqlDbType.DateTime).Value    = objTrancode_Info.DateCreated;
         command.Parameters.Add("@UserCreate", SqlDbType.NVarChar, 10).Value = objTrancode_Info.UserCreate;
         if (string.IsNullOrEmpty(objTrancode_Info.Branch_ID))
         {
             command.Parameters.Add("@Branch_ID", SqlDbType.NVarChar, 135).Value = DBNull.Value;
         }
         else
         {
             command.Parameters.Add("@Branch_ID", SqlDbType.NVarChar, 135).Value = objTrancode_Info.Branch_ID;
         }
         AddCommand(command);
         return(command);
     }
     catch (Exception ex)
     { Logger.Error(ex); throw ex; }
 }
Exemple #2
0
 public static int Update(Trancode_Info obj)
 {
     if (obj != null)
     {
         return(dal_trancode.Update(obj));
     }
     else
     {
         throw new Exception(dal_trancode.Error_Message);
     }
 }
Exemple #3
0
 public new int Update(Trancode_Info obj)
 {
     if (obj == null)
     {
         SetError(99, "Invalid data input");
         return(Error_Number);
     }
     if (string.IsNullOrEmpty(obj.Code))
     {
         SetError(98, "Trancode code is null or empty");
         return(Error_Number);
     }
     if (string.IsNullOrEmpty(obj.Name))
     {
         SetError(98, "Trancode name is null or empty");
         return(Error_Number);
     }
     if (string.IsNullOrEmpty(obj.Categories))
     {
         SetError(98, "Trancode categories is null or empty");
         return(Error_Number);
     }
     if (string.IsNullOrEmpty(obj.CodeType.ToString()))
     {
         SetError(98, "Trancode type is null or empty");
         return(Error_Number);
     }
     if (string.IsNullOrEmpty(obj.UserCreate))
     {
         SetError(98, "Trancode usercreate is null or empty");
         return(Error_Number);
     }
     if (obj.DateCreated == DateTime.MinValue)
     {
         SetError(98, "Trancode DateCreated is null or empty");
         return(Error_Number);
     }
     if (base.GetTrancodeByID(obj.Code) == null)
     {
         SetError(98, "Trancode not find");
         return(Error_Number);
     }
     if (base.Update(obj) != 0)
     {
         SetError(0, String.Empty);
     }
     else
     {
         SetError(99, Error_Message);
     }
     return(Error_Number);
 }
Exemple #4
0
 protected int Delete(Trancode_Info obj)
 {
     if (obj == null)
     {
         throw new Exception("Invalid data input");
     }
     _dalTrancode.RemoveOneTranCode(obj.Code);
     if (_dalTrancode.Execute())
     {
         return(_dalTrancode.LastRecordsEffected);
     }
     else
     {
         throw _dalTrancode.GetException;
     }
 }
Exemple #5
0
        public int Delete(string code)
        {
            if (string.IsNullOrEmpty(code))
            {
                SetError(98, "Trancode code is null or empty");
                return(Error_Number);
            }
            Trancode_Info obj = base.GetTrancodeByID(code);

            if (obj == null)
            {
                SetError(98, "Trancode not find");
                return(Error_Number);
            }
            if (base.Delete(obj) != 0)
            {
                SetError(0, String.Empty);
            }
            else
            {
                SetError(99, Error_Message);
            }
            return(Error_Number);
        }
Exemple #6
0
        private Trancode_Info GenerateObject(DataRow row)
        {
            if (row == null)
            {
                throw new Exception("Data row not set");
            }
            Trancode_Info ti = new Trancode_Info();

            if (row["Code"] != DBNull.Value)
            {
                ti.Code = Convert.ToString(row["Code"]);
            }
            if (row["Name"] != DBNull.Value)
            {
                ti.Name = Convert.ToString(row["Name"]);
            }
            if (row["Status"] != DBNull.Value)
            {
                ti.Status = Convert.ToBoolean(row["Status"]);
            }
            if (row["Categories"] != DBNull.Value)
            {
                ti.Categories = Convert.ToString(row["Categories"]);
            }
            if (row["NextCode"] != DBNull.Value)
            {
                ti.NextCode = Convert.ToString(row["NextCode"]);
            }
            if (row["CostCode"] != DBNull.Value)
            {
                ti.CostCode = Convert.ToString(row["CostCode"]);
            }
            if (row["Descript"] != DBNull.Value)
            {
                ti.Descript = Convert.ToString(row["Descript"]);
            }
            if (row["CodeType"] != DBNull.Value)
            {
                ti.CodeType = (CodeType)Enum.Parse(typeof(CodeType), row["CodeType"].ToString());
            }
            if (row["AllowReverse"] != DBNull.Value)
            {
                ti.AllowReverse = Convert.ToBoolean(row["AllowReverse"]);
            }
            if (row["Report"] != DBNull.Value)
            {
                ti.Report = Convert.ToBoolean(row["Report"]);
            }
            if (row["Display"] != DBNull.Value)
            {
                ti.Display = Convert.ToBoolean(row["Display"]);
            }
            if (row["Formula"] != DBNull.Value)
            {
                ti.Formula = Convert.ToString(row["Formula"]);
            }
            if (row["RefNum"] != DBNull.Value)
            {
                ti.RefNum = Convert.ToString(row["RefNum"]);
            }
            if (row["CheckOn"] != DBNull.Value)
            {
                ti.CheckOn = Convert.ToBoolean(row["CheckOn"]);
            }
            if (row["DateCreated"] != DBNull.Value)
            {
                ti.DateCreated = Convert.ToDateTime(row["DateCreated"]);
            }
            if (row["UserCreate"] != DBNull.Value)
            {
                ti.UserCreate = Convert.ToString(row["UserCreate"]);
            }
            if (row["Branch_ID"] != DBNull.Value)
            {
                ti.Branch_ID = Convert.ToString(row["Branch_ID"]);
            }
            return(ti);
        }
Exemple #7
0
        public xml_response Retail(string trancode, string accountId, decimal amount, string descript)
        {
            try
            {
                _res = new xml_response();
                _res.function_name = this.ToString() +
                                     string.Format(".Retail({0}, {1}, {2},{3})", trancode, accountId, amount, descript);
                if (logger.IsDebugEnabled)
                {
                    logger.Debug(string.Format("Start function: {0}", _res.function_name));
                }
                // kiểm tra trancode
                Trancode_Info trancodeInfo = _dalTrancode.GetOneTranCode(trancode);
                if (trancodeInfo == null)
                {
                    _res.SetError("99", string.Format("Trancode Id: {0} not found", trancode));
                    if (logger.IsErrorEnabled)
                    {
                        logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                    }
                    return(_res);
                }
                if (trancodeInfo.CodeType == CodeType.FundTransfer)
                {
                    _res.SetError("99", string.Format("Trancode Id: {0} invalid code type", trancode));
                    if (logger.IsErrorEnabled)
                    {
                        logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                    }
                    return(_res);
                }

                Tranday_Info trandayInfo = new Tranday_Info();
                _transdate               = BaseParameters.ToDay().TransDate;
                trandayInfo.DocID        = GenerateDocId(); // tạo số chứng từ mới
                trandayInfo.Trace        = trandayInfo.DocID;
                trandayInfo.TransDate    = _transdate;
                trandayInfo.ValueDate    = _transdate;
                trandayInfo.Status       = TransactionStatus.Approved;
                trandayInfo.Branch_ID    = _channel.Branch;
                trandayInfo.AllowReverse = trancodeInfo.AllowReverse;
                if (string.IsNullOrEmpty(descript))
                {
                    trandayInfo.Descript = string.Format("Retail: {0} with amount={1}", accountId, amount);
                }
                else
                {
                    trandayInfo.Descript = descript;
                }
                trandayInfo.NextDocId     = "";
                trandayInfo.OtherRef      = "";
                trandayInfo.TranCode      = trancode;
                trandayInfo.UserCreate    = _channel.UserLogin;
                trandayInfo.Verified      = true;
                trandayInfo.Verified_User = _channel.UserLogin;

                _dalTranday.CreateOneTranday(trandayInfo);

                // lấy mã giao dịch được định nghĩa cách hạch toán
                List <TranCodeDetail_Info> list = _dalTrancode.GetTranCodeDetailByCode(trancode);
                if (list == null)
                {
                    _res.SetError("30", string.Format("Can't load trancodedetail: {0}", trancode));
                    if (logger.IsErrorEnabled)
                    {
                        logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                    }
                    _dalTranday.ClearCommand();
                    return(_res);
                }
                D_Account           dalAc = new D_Account();
                TrandayDetail_Info  tid;
                List <Account_Info> AcList;
                Account_Info        tmpAc;
                D_TrandayDetail     trand       = new D_TrandayDetail();
                decimal             remain_amnt = 0; // số tiền còn lại
                decimal             db_amnt;
                decimal             cr_amnt;
                decimal             sum_db_amnt = 0;
                decimal             sum_cr_amnt = 0;
                bool find_ac = false;

                tmpAc = dalAc.GetOneAccount(accountId);
                if (tmpAc == null)
                {
                    _res.SetError("11", string.Format("{0} does not exists", accountId));
                    if (logger.IsErrorEnabled)
                    {
                        logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                    }
                    _dalTranday.ClearCommand();
                    return(_res);
                }
                #region Build Trandaydetail

                foreach (TranCodeDetail_Info tcdi in list)
                {
                    AcList  = new List <Account_Info>();
                    tid     = new TrandayDetail_Info();
                    db_amnt = 0;
                    cr_amnt = 0;

                    #region Find Account_ID

                    if (tcdi.Is_Account_Cust)
                    {
                        // là tài khoản khách hàng
                        AcList = dalAc.GetListAccountLike(tcdi.Account_ID);
                        foreach (Account_Info acInfo in AcList)
                        {
                            if (accountId == acInfo.Account_ID)
                            {
                                find_ac = true;
                                break;
                            }
                        }
                        if (find_ac == false)
                        {
                            // không xác định được nhóm tài khoản khách hàng
                            _res.SetError("31", string.Format("{0} not in group {1}", accountId, tcdi.Account_ID));
                            if (logger.IsErrorEnabled)
                            {
                                logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                            }
                            _dalTranday.ClearCommand();
                            return(_res);
                        }
                    }
                    else
                    {
                        // là tài khoản đã được định danh chi tiết
                        AcList = dalAc.GetListAccountLike(tcdi.Account_ID);
                        if (AcList.Count > 1)
                        {
                            // nếu xác định được nhiều tài khoản thì lỗi
                            _res.SetError("31", string.Format("{0} does too many accounts", tcdi.Account_ID));
                            if (logger.IsErrorEnabled)
                            {
                                logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                            }
                            _dalTranday.ClearCommand();
                            return(_res);
                        }
                        if (AcList.Count == 0)
                        {
                            // không xác định được tài khoản
                            _res.SetError("31", string.Format("{0} Invalid account id", tcdi.Account_ID));
                            if (logger.IsErrorEnabled)
                            {
                                logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                            }
                            _dalTranday.ClearCommand();
                            return(_res);
                        }
                        tmpAc = AcList[0];
                    }

                    #endregion

                    tid.Account_ID = tmpAc.Account_ID;
                    tid.Ccy        = tmpAc.Ccy;
                    tid.SEQ        = tcdi.SEQ;

                    if (!tcdi.Master)
                    {
                        switch (tcdi.NumberType)
                        {
                        case NumberType.FixAmount:
                            // Kiểm tra số dư fix
                            if ((decimal)tcdi.NumberValue > amount - remain_amnt)
                            {
                                _res.SetError("",
                                              string.Format("fix amount is {0} greater than {1}", tcdi.NumberValue,
                                                            amount - remain_amnt));
                                if (logger.IsErrorEnabled)
                                {
                                    logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                                }
                                _dalTranday.ClearCommand();
                                return(_res);
                            }
                            if (tcdi.CreditDebit == CreditDebit.DB)
                            {
                                db_amnt = (decimal)tcdi.NumberValue;
                            }
                            else
                            {
                                cr_amnt = (decimal)tcdi.NumberValue;
                            }
                            break;

                        case NumberType.Percentage:
                            if (tcdi.CreditDebit == CreditDebit.DB)
                            {
                                db_amnt = amount * (decimal)tcdi.NumberValue;
                            }
                            else
                            {
                                cr_amnt = amount * (decimal)tcdi.NumberValue;
                            }
                            break;

                        default:
                            if (tcdi.CreditDebit == CreditDebit.DB)
                            {
                                db_amnt = amount - remain_amnt;
                            }
                            else
                            {
                                cr_amnt = amount - remain_amnt;
                            }
                            break;
                        }
                        if (tcdi.CreditDebit == CreditDebit.DB)
                        {
                            remain_amnt += db_amnt;
                        }
                        else
                        {
                            remain_amnt += cr_amnt;
                        }
                    }
                    else
                    {
                        if (tcdi.CreditDebit == CreditDebit.DB)
                        {
                            db_amnt = amount;
                        }
                        else
                        {
                            cr_amnt = amount;
                        }
                    }
                    tid.DB_Amount = db_amnt;
                    tid.CR_Amount = cr_amnt;
                    tid.DocID     = trandayInfo.DocID;
                    // ===============================
                    // kiểm tra điều kiện hạch toán ==
                    // ===============================
                    decimal temp_amnt = 0;
                    if (tcdi.CreditDebit == CreditDebit.DB)
                    {
                        temp_amnt = tid.DB_Amount;
                    }
                    else
                    {
                        temp_amnt = tid.CR_Amount;
                    }
                    if (!CheckAccountRules(tmpAc, tcdi.CreditDebit, temp_amnt))
                    {
                        _res.SetError("15", _msgRule);
                        if (logger.IsErrorEnabled)
                        {
                            logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                        }
                        _dalTranday.ClearCommand();
                        return(_res);
                    }
                    // ===============================
                    // ghi nợ tài khoản
                    tmpAc.d_Debit += tid.DB_Amount;
                    tmpAc.w_Debit += tid.DB_Amount;
                    tmpAc.m_Debit += tid.DB_Amount;
                    tmpAc.q_Debit += tid.DB_Amount;
                    tmpAc.y_Debit += tid.DB_Amount;
                    // ghi có tài khoản.
                    tmpAc.d_Credit += tid.CR_Amount;
                    tmpAc.w_Credit += tid.CR_Amount;
                    tmpAc.m_Credit += tid.CR_Amount;
                    tmpAc.q_Credit += tid.CR_Amount;
                    tmpAc.y_Credit += tid.CR_Amount;

                    tmpAc.Last_Date = DateTime.Now;
                    // Cập nhật số dư mới
                    tid.BalanceAvaiable = tmpAc.BalanceAvaiable;
                    // thực hiện câu lệnh
                    // Kiểm tra điều kiện số dư hạch toán nợ/có
                    if ((tid.DB_Amount == 0) && (tid.CR_Amount == 0))
                    {
                        break;
                    }
                    else
                    {
                        _dalTranday.AddCommand(trand.CreateOneTrandayDetail(tid));
                        _dalTranday.AddCommand(dalAc.EditOneAccount(tmpAc));
                        // ghi nhận tổng nợ và tổng có
                        sum_db_amnt += db_amnt;
                        sum_cr_amnt += cr_amnt;
                    }
                } // end forearch

                #endregion

                // với bút toán nhiều chân thì kiểm tra cân đối tổng nợ và tổng có
                if (list.Count > 1)
                {
                    if (sum_cr_amnt != sum_db_amnt)
                    {
                        // không cân đối giữa tổng nợ và tổng có
                        _res.SetError("52",
                                      string.Format("total debit ({0}) and total credit ({1}) is difference",
                                                    sum_db_amnt,
                                                    sum_cr_amnt));
                        if (logger.IsErrorEnabled)
                        {
                            logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                        }
                        _dalTranday.ClearCommand();
                        return(_res);
                    }
                }
                if (string.IsNullOrEmpty(_docId))
                {
                    _docId = trandayInfo.DocID;
                }
                if (!string.IsNullOrEmpty(trancodeInfo.NextCode))
                {
                    Retail(trancodeInfo.NextCode, accountId, amount, descript);
                }
                else
                // ghi nhận hạch toán
                if (_dalTranday.Execute())
                // Lấy thông tin giao dịch
                {
                    _res.Transactions = base.GetTrandayById(_docId).RenderXML();
                    _docId            = String.Empty;
                }
                else
                {
                    _res.SetError("99", _dalTranday.GetException.Message);
                    if (logger.IsErrorEnabled)
                    {
                        logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                    }
                    _docId = String.Empty;
                    _dalTranday.ClearCommand();
                }
            }
            catch (Exception ex)
            {
                _res.SetError("99", ex.Message);
                if (logger.IsErrorEnabled)
                {
                    logger.Error(ex);
                }
                _docId = String.Empty;
                _dalTranday.ClearCommand();
            }
            return(_res);
        }
Exemple #8
0
        public xml_response Fundtransfer(string trancode, string fromAccount, string toAccount, decimal amount, string descript)
        {
            try
            {
                _res = new xml_response();
                _res.function_name = this.ToString() +
                                     string.Format(".Fundtransfer({0}, {1}, {2}, {3},{4})", trancode, fromAccount,
                                                   toAccount, amount, descript);
                if (logger.IsDebugEnabled)
                {
                    logger.Debug(string.Format("Start function: {0}", _res.function_name));
                }
                // kiểm tra trancode
                Trancode_Info trancodeInfo = _dalTrancode.GetOneTranCode(trancode);
                if (trancodeInfo == null)
                {
                    _res.SetError("99", string.Format("Trancode Id: {0} not found", trancode));
                    if (logger.IsErrorEnabled)
                    {
                        logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                    }
                    return(_res);
                }
                if (trancodeInfo.CodeType != CodeType.FundTransfer)
                {
                    _res.SetError("99", string.Format("Trancode Id: {0} invalid code type", trancode));
                    if (logger.IsErrorEnabled)
                    {
                        logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                    }
                    return(_res);
                }

                // kiểm tra tài khoản đã có hay chưa
                string db_account = fromAccount;
                string cr_account = toAccount;

                if (_dalAc.GetOneAccount(db_account) == null)
                {
                    _res.SetError("11", string.Format("From account {0} does not found", db_account));
                    if (logger.IsErrorEnabled)
                    {
                        logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                    }
                    return(_res);
                }
                if (_dalAc.GetOneAccount(cr_account) == null)
                {
                    _res.SetError("11", string.Format("From account {0} does not found", cr_account));
                    if (logger.IsErrorEnabled)
                    {
                        logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                    }
                    return(_res);
                }
                // kiểm tra số dư chuyển khoản.
                Tranday_Info trandayInfo = new Tranday_Info();
                trandayInfo.AllowReverse = trancodeInfo.AllowReverse;
                trandayInfo.Branch_ID    = _channel.Branch;
                if (string.IsNullOrEmpty(descript))
                {
                    trandayInfo.Descript = string.Format("transfer from {0} to {1} with amount = {2}", db_account, cr_account, amount);
                }
                else
                {
                    trandayInfo.Descript = descript;
                }
                trandayInfo.NextDocId = "";
                trandayInfo.Status    = TransactionStatus.Approved;

                _transdate = BaseParameters.ToDay().TransDate;

                trandayInfo.TranCode      = trancode;
                trandayInfo.TransDate     = _transdate;
                trandayInfo.UserCreate    = _channel.UserLogin;
                trandayInfo.ValueDate     = _transdate;
                trandayInfo.Verified      = true;
                trandayInfo.Verified_User = _channel.UserLogin;
                trandayInfo.DocID         = base.GenerateDocId();
                trandayInfo.Trace         = trandayInfo.DocID;

                _dalTranday.CreateOneTranday(trandayInfo);

                D_TrandayDetail     dalTrandaydetail;
                TrandayDetail_Info  trandaydetailInfo;
                Account_Info        ai                       = new Account_Info();
                List <Account_Info> ac_list                  = new List <Account_Info>();
                bool                       find_ac           = false;
                D_TranCodeDetail           dalTrancodedetail = new D_TranCodeDetail();
                List <TranCodeDetail_Info> list              = dalTrancodedetail.GetTranCodeDetailByCode(trancode);
                if (list == null)
                {
                    _res.SetError("30", string.Format("Can't load trancodedetail: {0}", trancode));
                    if (logger.IsErrorEnabled)
                    {
                        logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                    }
                    _dalTranday.ClearCommand();
                    return(_res);
                }
                foreach (TranCodeDetail_Info tcdi in list)
                {
                    dalTrandaydetail  = new D_TrandayDetail();
                    trandaydetailInfo = new TrandayDetail_Info();
                    switch (tcdi.CreditDebit)
                    {
                    case  CreditDebit.DB:
                        ac_list = _dalAc.GetListAccountLike(tcdi.Account_ID);
                        foreach (Account_Info acInfo in ac_list)
                        {
                            if (db_account == acInfo.Account_ID)
                            {
                                find_ac = true;
                                break;
                            }
                        }
                        if (find_ac == false)
                        {
                            // không xác định được nhóm tài khoản khách hàng
                            _res.SetError("31", string.Format("{0} not in group {1}", db_account, tcdi.Account_ID));
                            if (logger.IsErrorEnabled)
                            {
                                logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                            }
                            _dalTranday.ClearCommand();
                            return(_res);
                        }
                        trandaydetailInfo.Account_ID = db_account;
                        trandaydetailInfo.DB_Amount  = amount;
                        ai = _dalAc.GetOneAccount(trandaydetailInfo.Account_ID);
                        // kiểm tra luật hạch toán
                        if (!CheckAccountRules(ai, CreditDebit.DB, amount))
                        {
                            _res.SetError("15", _msgRule);
                            _dalTranday.ClearCommand();
                            return(_res);
                        }
                        // ghi nợ tài khoản.
                        ai.y_Debit           += amount;
                        ai.q_Debit           += amount;
                        ai.m_Debit           += amount;
                        ai.w_Debit           += amount;
                        ai.d_Debit           += amount;
                        trandaydetailInfo.Ccy = ai.Ccy;
                        break;

                    case CreditDebit.CR:
                        ac_list = _dalAc.GetListAccountLike(tcdi.Account_ID);
                        foreach (Account_Info acInfo in ac_list)
                        {
                            if (cr_account == acInfo.Account_ID)
                            {
                                find_ac = true;
                                break;
                            }
                        }
                        if (find_ac == false)
                        {
                            // không xác định được nhóm tài khoản khách hàng
                            _res.SetError("31", string.Format("{0} not in group {1}", cr_account, tcdi.Account_ID));
                            if (logger.IsErrorEnabled)
                            {
                                logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                            }
                            _dalTranday.ClearCommand();
                            return(_res);
                        }
                        trandaydetailInfo.Account_ID = cr_account;
                        trandaydetailInfo.CR_Amount  = amount;
                        ai = _dalAc.GetOneAccount(trandaydetailInfo.Account_ID);
                        // kiểm tra luật hạch toán
                        if (!CheckAccountRules(ai, CreditDebit.CR, amount))
                        {
                            _res.SetError("15", _msgRule);
                            _dalTranday.ClearCommand();
                            return(_res);
                        }
                        // ghi có tài khoản.
                        ai.y_Credit          += amount;
                        ai.q_Credit          += amount;
                        ai.m_Credit          += amount;
                        ai.w_Credit          += amount;
                        ai.d_Credit          += amount;
                        trandaydetailInfo.Ccy = ai.Ccy;
                        break;
                    }
                    trandaydetailInfo.SEQ   = tcdi.SEQ;
                    trandaydetailInfo.DocID = trandayInfo.DocID;
                    // cập nhật số dư mới
                    trandaydetailInfo.BalanceAvaiable = ai.BalanceAvaiable;
                    // cập nhật thời gian
                    ai.Last_Date = DateTime.Now;
                    // thực hiện câu lệnh
                    _dalTranday.AddCommand(dalTrandaydetail.CreateOneTrandayDetail(trandaydetailInfo));
                    _dalTranday.AddCommand(_dalAc.EditOneAccount(ai));
                }
                if (string.IsNullOrEmpty(_docId))
                {
                    _docId = trandayInfo.DocID;
                }
                if (!string.IsNullOrEmpty(trancodeInfo.NextCode))
                {
                    Fundtransfer(trancodeInfo.NextCode, fromAccount, toAccount, amount, descript);
                }
                else
                // ghi nhận hạch toán
                if (!_dalTranday.Execute())
                {
                    _res.SetError("99", _dalTranday.GetException.Message);
                    if (logger.IsErrorEnabled)
                    {
                        logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                    }
                    _docId = String.Empty;
                    _dalTranday.ClearCommand();
                }
                else
                // Lấy thông tin giao dịch
                {
                    _res.Transactions = base.GetTrandayById(_docId).RenderXML();
                    _docId            = String.Empty;
                }
            }
            catch (Exception ex)
            {
                _res.SetError("99", ex.Message);
                if (logger.IsErrorEnabled)
                {
                    logger.Error(ex);
                }
                _docId = String.Empty;
                _dalTranday.ClearCommand();
            }
            return(_res);
        }