Esempio n. 1
0
        public List <Tranday_Info> GetTransactionByAccount(string accountId, DateTime dateFrom, DateTime dateTo)
        {
            if (string.IsNullOrEmpty(accountId))
            {
                throw new Exception("Account Id is null or empty");
            }
            if (dateFrom == DateTime.MinValue)
            {
                throw new Exception("Invalid date from");
            }
            if (dateTo == DateTime.MinValue)
            {
                throw new Exception("Invalid date to");
            }
            if (dateFrom > dateTo)
            {
                throw new Exception("invalid date from > date to");
            }
            List <Tranday_Info> list;

            if ((dateFrom == dateTo) && (dateTo == BaseParameters.ToDay().TransDate))
            {
                // ngày giao dịch hiện tại
                list = base.GetTrandayByAccount(accountId);
            }
            else
            {
                list = base.GetTranAllByAccount(accountId, dateFrom, dateTo);
            }
            return(list);
        }
Esempio n. 2
0
        public ISO8583TranDay(Channel_Info channel)
        {
            logger                = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
            user_id               = channel.UserLogin;
            branch_id             = channel.Branch;
            retail_trancode       = channel.Retail_Trancode;
            fundtransfer_trancode = channel.FundTranfer_Trancode;
            transdate             = BaseParameters.ToDay().TransDate;
            string a = Validation();

            if (a != "")
            {
                if (logger.IsDebugEnabled)
                {
                    logger.Debug(a);
                }
                throw new Exception(a);
            }
            _channel = channel;
        }
Esempio n. 3
0
        public xml_response Reverse(string docid)
        {
            _res = new xml_response();
            _res.function_name = this.ToString() + string.Format(".Reverse({0})", docid);
            if (logger.IsDebugEnabled)
            {
                logger.Debug(string.Format("Start function: {0}", _res.function_name));
            }

            try
            {
                Tranday_Info tranInfo = _dalTranday.GetOneTranday(docid);
                if (tranInfo == null)
                {
                    _res.SetError("40", string.Format("Transaction {0} does not exists", docid));
                    if (logger.IsErrorEnabled)
                    {
                        logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                    }
                    return(_res);
                }
                if (tranInfo.Verified == false)
                {
                    _res.SetError("42", string.Format("{0} transaction are not verified", docid));
                    if (logger.IsErrorEnabled)
                    {
                        logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                    }
                    return(_res);
                }
                if (string.IsNullOrEmpty(_docId))
                {
                    if (tranInfo.AllowReverse == false)
                    {
                        _res.SetError("44", string.Format("Transaction {0} does not allow reverse", docid));
                        if (logger.IsErrorEnabled)
                        {
                            logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                        }
                        return(_res);
                    }
                }
                Tranday_Info oldTran = tranInfo;
                // cập nhật hồ sơ giao dịch không cho cho phép đảo ngược nữa
                tranInfo.AllowReverse = false;
                _dalTranday.EditOneTranday(tranInfo);
                tranInfo.Descript  = string.Format("REVERSE: {0}", docid);
                tranInfo.DocID     = base.GenerateDocId();
                tranInfo.Trace     = tranInfo.DocID;
                tranInfo.OtherRef  = docid;
                tranInfo.NextDocId = "";
                tranInfo.Status    = TransactionStatus.Approved;

                _transdate = BaseParameters.ToDay().TransDate;   // Lấy thông tin ngày giao dịch

                tranInfo.TransDate     = _transdate;
                tranInfo.ValueDate     = _transdate;
                tranInfo.Verified      = true;
                tranInfo.Verified_User = _channel.UserLogin;
                tranInfo.UserCreate    = _channel.UserLogin;

                _dalTranday.CreateOneTranday(tranInfo);

                Account_Info    acInfo;
                D_TrandayDetail dtd = new D_TrandayDetail();
                foreach (TrandayDetail_Info tdi in tranInfo.TrandayDetails)
                {
                    // đổi dấu số dư hạch toán.
                    tdi.CR_Amount *= -1;
                    tdi.DB_Amount *= -1;
                    // lấy thông tin tài khoản hạch toán
                    acInfo = _dalAc.GetOneAccount(tdi.Account_ID);
                    // kiểm tra luật hạch toán
                    if (tdi.DB_Amount != 0)
                    {
                        if (!CheckAccountRules(acInfo, CreditDebit.DB, tdi.DB_Amount))
                        {
                            _res.SetError("15", _msgRule);
                            if (logger.IsErrorEnabled)
                            {
                                logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                            }
                            _dalTranday.ClearCommand();
                            return(_res);
                        }
                    }
                    if (tdi.CR_Amount != 0)
                    {
                        if (!CheckAccountRules(acInfo, CreditDebit.CR, tdi.CR_Amount))
                        {
                            _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 có tài khoản.
                    acInfo.y_Credit += tdi.CR_Amount;
                    acInfo.q_Credit += tdi.CR_Amount;
                    acInfo.m_Credit += tdi.CR_Amount;
                    acInfo.w_Credit += tdi.CR_Amount;
                    acInfo.d_Credit += tdi.CR_Amount;
                    // ghi nợ tài khoản
                    acInfo.y_Debit += tdi.DB_Amount;
                    acInfo.q_Debit += tdi.DB_Amount;
                    acInfo.m_Debit += tdi.DB_Amount;
                    acInfo.w_Debit += tdi.DB_Amount;
                    acInfo.d_Debit += tdi.DB_Amount;
                    // cập nhật số dư
                    tdi.BalanceAvaiable = acInfo.BalanceAvaiable;
                    tdi.DocID           = tranInfo.DocID;
                    // cập nhật thời gian
                    acInfo.Last_Date = DateTime.Now;
                    // thực hiện câu lệnh
                    _dalTranday.AddCommand(dtd.CreateOneTrandayDetail(tdi));
                    _dalTranday.AddCommand(_dalAc.EditOneAccount(acInfo));
                }
                if (string.IsNullOrEmpty(_docId))
                {
                    _docId = tranInfo.DocID;
                }
                if (!string.IsNullOrEmpty(oldTran.NextDocId))
                {
                    Reverse(oldTran.NextDocId);
                }
                else
                {
                    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
                    {
                        //_res.doc_id = ti.DocID;
                        _res.Transactions = base.GetTrandayById(_docId).RenderXML();
                        _docId            = String.Empty;
                    }
                }
            }
            catch (Exception ex)
            {
                _res.SetError("99", ex.Message);
                if (logger.IsErrorEnabled)
                {
                    logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                }
                _docId = String.Empty;
                _dalTranday.ClearCommand();
            }
            return(_res);
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
        }