Пример #1
0
 public xml_response AddFund(string trancode, string accountId, decimal amount, string descript)
 {
     _res = Retail(trancode, accountId, amount, descript);
     _res.function_name = this.ToString() +
                          string.Format(".AddFund({0}, {1}, {2},{3})", trancode, accountId, amount, descript);
     return(_res);
 }
Пример #2
0
 /// <summary>
 /// Get one Account detail
 /// </summary>
 /// <param name="accountId"></param>
 /// <returns>Account_Info</returns>
 public new xml_response GetAccountById(string accountId)
 {
     try
     {
         _res = new xml_response();
         _res.function_name = this.ToString() + string.Format(".GetAccountById({0})", accountId);
         if (logger.IsDebugEnabled)
         {
             logger.Debug(string.Format("Start function: {0}", _res.function_name));
         }
         Account_Info ai = base.GetAccountById(accountId);
         if (ai == null)
         {
             // không tìm thấy thông tin tài khoản.
             _res.SetError("11", string.Format("Account: {0} not found", accountId));
             if (logger.IsErrorEnabled)
             {
                 logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
             }
         }
         else
         {
             _res.Accounts = ai.RenderXML();
         }
     }
     catch (Exception ex)
     {
         if (logger.IsErrorEnabled)
         {
             logger.Error(ex);
         }
         throw;
     }
     return(_res);
 }
Пример #3
0
 public new xml_response GetCustomerById(string custId)
 {
     try
     {
         _res = new xml_response();
         _res.function_name = this.ToString() + string.Format(".GetCustomerById({0})", custId);
         if (Logger.IsDebugEnabled)
         {
             Logger.Debug(string.Format("Start function: {0}", _res.function_name));
         }
         Customer_Info custInfo = base.GetCustomerById(custId);
         if (custInfo == null)
         {
             _res.SetError("01", string.Format("Customer: {0} not found", custId));
             if (Logger.IsErrorEnabled)
             {
                 Logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
             }
         }
         else
         {
             custInfo.Balance = base.Balance(custId);    // lấy số dư theo khách hàng
             _res.Customers   = custInfo.RenderXML();
         }
     }
     catch (Exception ex)
     {
         if (Logger.IsErrorEnabled)
         {
             Logger.Error(ex);
         }
         throw;
     }
     return(_res);
 }
Пример #4
0
        /// <summary>
        /// hàm bỏ khóa số dư tài khoản
        /// </summary>
        /// <param name="accountId"></param>
        /// <param name="amnt"></param>
        /// <returns></returns>
        public new xml_response UnBlock(string accountId, decimal amnt)
        {
            try
            {
                _res = new xml_response();
                _res.function_name = this.ToString() + string.Format(".UnBlock({0}, {1})", accountId, amnt);
                if (logger.IsDebugEnabled)
                {
                    logger.Debug(string.Format("Start function: {0}", _res.function_name));
                }
                //D_Account da = new D_Account();
                Account      da = new Account();
                Account_Info ai = da.GetAccountByID(accountId);
                if (ai == null)
                {
                    _res.SetError("11", string.Format("Account {0} can not find", accountId));
                    if (logger.IsErrorEnabled)
                    {
                        logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                    }
                    return(_res);
                }
                if (ai.BalanceAvaiable < amnt)
                {
                    _res.SetError("14", "Account balance is not enough");
                    if (logger.IsErrorEnabled)
                    {
                        logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                    }
                    return(_res);
                }

                // Thực hiện bỏ khóa số dư
                if (base.UnBlock(ai, amnt) == 0)
                {
                    // mở khóa số dư không thành công
                    _res.SetError("99", base.Error_Message);
                    if (logger.IsErrorEnabled)
                    {
                        logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                    }
                }
            }
            catch (Exception ex)
            {
                if (logger.IsErrorEnabled)
                {
                    logger.Error(ex);
                }
                throw;
            }
            return(_res);
        }
Пример #5
0
        public xml_response GetOneTransaction(string docid)
        {
            try
            {
                _res = new xml_response();
                _res.function_name = this.ToString() + string.Format(".Transaction({0})", docid);
                if (logger.IsDebugEnabled)
                {
                    logger.Debug(string.Format("Start fucntion: {0}", _res.function_name));
                }

                Tranday_Info ti = base.GetTrandayById(docid);
                if (ti == null)
                {
                    // không tìm thấy chứng từ
                    _res.SetError("17", "transaction not found");
                    if (logger.IsErrorEnabled)
                    {
                        logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                    }
                }
                else
                {
                    // đưa vào mảng
                    _res.Transactions = ti.RenderXML();
                }
            }
            catch (Exception ex)
            {
                _res.SetError("99", ex.Message);
                if (logger.IsErrorEnabled)
                {
                    logger.Error(ex);
                }
            }
            return(_res);
        }
Пример #6
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);
        }
Пример #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);
        }
Пример #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);
        }
Пример #9
0
        /// <summary>
        /// Mở tài khoản theo Categories và mã khách hàng
        /// </summary>
        /// <param name="categories">Mã sản phẩm</param>
        /// <param name="custId">Mã khách hàng</param>
        /// <returns>chuỗi ký tự thông tin tài khoản chi tiết được mở theo định dạng
        /// xml hoặc chuối ký tự lỗi định dạng xml</returns>
        public xml_response Insert(string categories, string custId)
        {
            try
            {
                _res = new xml_response();
                _res.function_name = this.ToString() + string.Format(".Insert({0},{1})", categories, custId);
                Customer      bcust    = new Customer();
                Customer_Info custInfo = bcust.GetCustomerByID(custId);
                if (custInfo == null)
                {
                    _res.SetError("01", "Customer can not find");
                    if (logger.IsErrorEnabled)
                    {
                        logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                    }
                    return(_res);
                }
                else
                {
                    if (custInfo.Active == false)
                    {
                        _res.SetError("03", "Customers have not been approved");
                        if (logger.IsErrorEnabled)
                        {
                            logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                        }
                        return(_res);
                    }
                }
                Categories      dalCat  = new Categories();
                Categories_Info catInfo = dalCat.GetCategoriesByID(categories);
                if (catInfo == null)
                {
                    _res.SetError("98", string.Format("Categories Id {0} can not find", categories));
                    if (logger.IsErrorEnabled)
                    {
                        logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                    }
                    return(_res);
                }

                Account_Info acInfo = GetAccountBy(_channel.Branch, categories, custId);
                if (acInfo == null)
                {
                    // Khởi tạo thông tin mở tài khoản.
                    acInfo              = new Account_Info();
                    acInfo.Name         = custInfo.Name; // tên tài khoản.
                    acInfo.Customer_ID  = custInfo.ID;   // Mã khách hàng.
                    acInfo.Branch_ID    = _channel.Branch;
                    acInfo.Categories   = categories;
                    acInfo.Ccy          = _channel.Currency_Code;
                    acInfo.Account_GL   = catInfo.Account_GL.Account_ID;
                    acInfo.CreditDebit  = catInfo.Account_GL.CreditDebit;
                    acInfo.Approved     = true;
                    acInfo.ApprovedTime = DateTime.Now;
                    acInfo.UserCreate   = _channel.UserLogin;
                    acInfo.Account_ID   = GenerateNewAccountId(acInfo.Branch_ID, acInfo.Categories);
                    acInfo.Open_Date    = DateTime.Now;
                    acInfo.Last_Date    = DateTime.Now;
                    // thực hiện mở tài khoản.
                    if (Insert(acInfo) == 0)
                    {
                        _res.Accounts = acInfo.RenderXML();
                    }
                    else
                    {
                        // Lấy nội dung lỗi
                        _res.SetError("99", dalAc.GetException.Message);
                        if (logger.IsErrorEnabled)
                        {
                            logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                        }
                        return(_res);
                    }
                }
                else
                {
                    // tài khoản đã được mở
                    _res.SetError("12", "Account opened");
                    if (logger.IsErrorEnabled)
                    {
                        logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                    }
                }
            }
            catch (Exception ex)
            {
                _res.SetError("99", ex.Message);
                if (logger.IsErrorEnabled)
                {
                    logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                }
            }
            return(_res);
        }
Пример #10
0
        /// <summary>
        /// Hàm đóng tài khoản.
        /// </summary>
        /// <param name="accountId">Mã tài khoản</param>
        /// <returns></returns>
        public new xml_response Close(string accountId)
        {
            try
            {
                _res = new xml_response();
                _res.function_name = this.ToString() + string.Format(".Close({0})", accountId);
                if (logger.IsDebugEnabled)
                {
                    logger.Debug(string.Format("Start function: {0}", _res.function_name));
                }

                //var da = new D_Account();
                var da = new Account();
                _acc = da.GetAccountByID(accountId);
                if (_acc == null)
                {
                    // tài khoản không tìm thấy
                    _res.SetError("11", string.Format("Account_ID: {0} can not find", accountId));
                    if (logger.IsErrorEnabled)
                    {
                        logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                    }
                    return(_res);
                }
                else
                {
                    if (_acc.Balance != 0)
                    {
                        // tài khoản vẫn còn số dư
                        _res.SetError("19",
                                      string.Format("Account_ID: {0} not allowed to close while still balance",
                                                    accountId));
                        if (logger.IsErrorEnabled)
                        {
                            logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                        }
                        return(_res);
                    }
                    if (!_acc.Approved)
                    {
                        // tài khoản chưa được duyệt
                        _res.SetError("13", string.Format("Account_ID: {0} has not been approved", accountId));
                        if (logger.IsErrorEnabled)
                        {
                            logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                        }
                        return(_res);
                    }
                    if (_acc.Closed)
                    {
                        // tài khoản đã được đóng
                        _res.SetError("21", string.Format("Account_ID: {0} closed", accountId));
                        if (logger.IsErrorEnabled)
                        {
                            logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                        }
                        return(_res);
                    }
                }

                // thực hiện đóng tài khoản.
                if (Close(_acc) == 0)
                {
                    // đóng tài khoản không thành công
                    _res.SetError("99", base.Error_Message);
                    if (logger.IsErrorEnabled)
                    {
                        logger.Error(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
                    }
                }
            }
            catch (Exception ex)
            {
                if (logger.IsErrorEnabled)
                {
                    logger.Error(ex);
                }
                throw;
            }
            return(_res);
        }
Пример #11
0
 public xml_response Insert(string custName, string custAdd, string custCert)
 {
     try
     {
         _res = new xml_response();
         _res.function_name = this.ToString() +
                              string.Format(".Insert({0},{1},{2})", custName, custAdd, custCert);
         if (string.IsNullOrEmpty(custName))
         {
             _res.SetError("98", "Customer name is null or empty");
             if (Logger.IsDebugEnabled)
             {
                 Logger.Debug(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
             }
             return(_res);
         }
         if (string.IsNullOrEmpty(custAdd))
         {
             _res.SetError("98", "Customer address is null or empty");
             if (Logger.IsDebugEnabled)
             {
                 Logger.Debug(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
             }
             return(_res);
         }
         if (string.IsNullOrEmpty(custCert))
         {
             _res.SetError("98", "Customer identity card is null or empty");
             if (Logger.IsDebugEnabled)
             {
                 Logger.Debug(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
             }
             return(_res);
         }
         if (base.GetCustomerByCert(custCert) != null)
         {
             _res.SetError("02", "Customer by identity card:" + custCert + " opened");
             if (Logger.IsDebugEnabled)
             {
                 Logger.Debug(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
             }
             return(_res);
         }
         if (base.Insert(_channel.Branch, _channel.UserLogin, custName, custAdd, custCert) == 0)
         {
             _res.SetError("99", GetException.Message);
             if (Logger.IsDebugEnabled)
             {
                 Logger.Debug(string.Format("{0}\t{1}", _res.error_code, _res.error_msg));
             }
         }
         _res.Customers = base.GetCustomerByCert(custCert).RenderXML();
     }
     catch (Exception ex)
     {
         if (Logger.IsErrorEnabled)
         {
             Logger.Error(ex);
         }
         throw;
     }
     return(_res);
 }