Beispiel #1
0
        public BaseTranDetail(TranCodeDetailFull_Info trancodedetail, string accountIdCust)
        {
            if (trancodedetail == null)
            {
                throw new Exception("trancodedetail is null or empty");
            }

            _trandaydetail = new TrandayDetail_Info();
            // kiểm tra gan tài khoản khách hàng.
            D_Account    dalAccount = new D_Account();
            Account_Info acInfo;

            if (trancodedetail.Is_Account_Cust == true)
            {
                // Xác định sự tồn tại của tài khoản khách hàng
                acInfo = dalAccount.GetOneAccount(accountIdCust);
                if (acInfo == null)
                {
                    throw new Exception("AccountId Customer not found");
                }
                _trandaydetail.Account_ID = accountIdCust;
            }
            else
            {
                List <Account_Info> list = dalAccount.GetListAccountLike(trancodedetail.Account_ID, trancodedetail.Categories);
                if (list.Count > 1 || list.Count == 0)
                {
                    throw new Exception("AccountId invalid");
                }
                _trandaydetail.Account_ID = list[0].Account_ID;
            }
            _trancodedetail    = trancodedetail;
            _trandaydetail.SEQ = trancodedetail.SEQ;
            switch (trancodedetail.NumberType)
            {
            case NumberType.FixAmount:
                if (trancodedetail.CreditDebit == "DB")
                {
                    _trandaydetail.DB_Amount = (decimal)trancodedetail.NumberValue;
                    _completed = true;
                }
                else
                {
                    _trandaydetail.CR_Amount = (decimal)trancodedetail.NumberValue;
                    _completed = true;
                }
                break;

            default:
                _trandaydetail.DB_Amount = 0;
                _trandaydetail.CR_Amount = 0;
                _completed = false;
                break;
            }
        }
Beispiel #2
0
        public MakeTranday(Channel_Info channel)
        {
            // lấy thông tin ngày giao dịch
            logger       = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            _channel     = channel;
            _dalTranday  = new D_Tranday();
            _dalAc       = new D_Account();
            _dalTrancode = new D_TranCode();

            // Ghi log
            if (logger.IsDebugEnabled)
            {
                logger.Debug(string.Format("Create MakeTranday object successfull"));
            }
        }
Beispiel #3
0
        /// <summary>
        /// Lấy danh sach tài khoản chi tiết của khách hàng
        /// </summary>
        /// <param name="custId">Mã khách hàng</param>
        /// <returns>Danh sách chi tiết khách hàng</returns>
        protected decimal Balance(string custId)
        {
            decimal   amnt  = 0;
            D_Account dalAc = new D_Account();
            // Lấy danh sách tài khoản theo mã khách hàng
            List <Account_Info> list = dalAc.GetListAccountByCustId(custId);

            //if (list.Count == 0)
            //    throw new Exception(string.Format("Can not find any account by customer: {0}", custId));
            foreach (Account_Info ac in list)
            {
                amnt += ac.Balance;
            }
            return(amnt);
        }
Beispiel #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);
        }
Beispiel #5
0
        /// <summary>
        /// tạo mới giao dịch mua hàng
        /// </summary>
        /// <param name="docid">số chứng từ hạch toán (phải duy nhất trong giai đoạn mở sổ)</param>
        /// <param name="account_id">tài khoản ghi nợ của khách hàng mua hàng</param>
        /// <param name="amount">số tiền mua hàng</param>
        /// <param name="descript">mô tả chi tiết giao dịch mua hàng</param>
        /// <returns>trả về 1 nếu thành công và 0 nếu không thành công</returns>
        public ResponseMessage Retail(string trace, string pan, decimal amount, string descript)
        {
            ResponseMessage msg = new ResponseMessage();

            msg.LocalDate   = DateTime.Now.ToString("MMdd");
            msg.LocalTime   = DateTime.Now.ToString("hhmmss");
            msg.SystemTrace = trace;

            D_Tranday dt = new D_Tranday();

            // kiểm tra số chứng từ đã có hay chưa
            if (dt.IsExists("", trace))
            {
                logger.Error(string.Format("Transaction {0} does exists", trace));
                msg.ResponseCode = "12";
                return(msg);
            }

            Tranday_Info ti = new Tranday_Info();

            // tạo lại số chứng từ mới
            ti.DocID = base.GenerateDocId();

            msg.RetrievalRefNum = ti.DocID;

            ti.Trace         = trace;
            ti.TransDate     = transdate;
            ti.ValueDate     = transdate;
            ti.Status        = TransactionStatus.Approved;
            ti.Branch_ID     = branch_id;
            ti.AllowReverse  = true;
            ti.Descript      = descript;
            ti.NextDocId     = "";
            ti.OtherRef      = "";
            ti.TranCode      = retail_trancode;
            ti.UserCreate    = user_id;
            ti.Verified      = true;
            ti.Verified_User = user_id;
            dt.CreateOneTranday(ti);
            // lấy mã giao dịch được định nghĩa cách hạch toán
            D_TranCodeDetail           dtd  = new D_TranCodeDetail();
            List <TranCodeDetail_Info> list = dtd.GetTranCodeDetailByCode(retail_trancode);

            if (list == null)
            {
                if (logger.IsErrorEnabled)
                {
                    logger.Error(string.Format("Can't load trancodedetail: {0}", retail_trancode));
                }
                msg.ResponseCode = "06";
                return(msg);
            }
            D_Account           da = new D_Account();
            TrandayDetail_Info  tid;
            List <Account_Info> ac_list;
            Account_Info        tmp_ac;
            D_TrandayDetail     trand = new D_TrandayDetail();

            #region Build Trandaydetail
            foreach (TranCodeDetail_Info tcdi in list)
            {
                ac_list = new List <Account_Info>();
                tid     = new TrandayDetail_Info();
                #region Xác định tài khoản hạch toán
                if (tcdi.Is_Account_Cust)
                {
                    // là tài khoản khách hàng
                    // so sánh tài khoản khách hàng có thuộc nhóm tài khoản định nghĩa.
                    // tài khoản chi tiết: 10100099992222
                    // thuộc nhóm tài khoản 101000
                    if (pan.IndexOf(tcdi.Account_ID) != 0)
                    {
                        // không xác định được nhóm tài khoản khách hàng
                        if (logger.IsErrorEnabled)
                        {
                            logger.Error(string.Format("{0} not in group {1}", pan, tcdi.Account_ID));
                        }
                        msg.ResponseCode = "14";    // Invalid card number
                        return(msg);
                    }
                    tmp_ac = da.GetOneAccount(pan);
                    if (tmp_ac == null)
                    {
                        if (logger.IsErrorEnabled)
                        {
                            logger.Error(string.Format("{0} does not exists", pan));
                        }
                        msg.ResponseCode = "14";    // Invalid card number
                        return(msg);
                    }
                }
                else
                {
                    // là tài khoản nội bộ
                    ac_list = da.GetListAccountLike(tcdi.Account_ID);
                    // nếu xác định được nhiều tài khoản thì lỗi
                    if (ac_list.Count > 1)
                    {
                        if (logger.IsErrorEnabled)
                        {
                            logger.Error(string.Format("{0} does too many accounts", tcdi.Account_ID));
                        }
                        msg.ResponseCode = "14";    // Invalid card number
                        return(msg);
                    }
                    tmp_ac = ac_list[0];
                }
                #endregion
                tid.Account_ID = tmp_ac.Account_ID;
                tid.Ccy        = tmp_ac.Ccy;
                tid.SEQ        = tcdi.SEQ;
                if (!string.IsNullOrEmpty(tcdi.NumberType.ToString()))
                {
                    switch (tcdi.NumberType)
                    {
                    case NumberType.FixAmount:
                        if (tcdi.CreditDebit == CreditDebit.DB)
                        {
                            tid.DB_Amount = (decimal)tcdi.NumberValue;
                        }
                        else
                        {
                            tid.CR_Amount = (decimal)tcdi.NumberValue;
                        }
                        break;

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

                    default:
                        if (tcdi.CreditDebit == CreditDebit.DB)
                        {
                            tid.DB_Amount = amount;
                        }
                        else
                        {
                            tid.CR_Amount = amount;
                        }
                        break;
                    }
                }
                else
                {
                    if (tcdi.CreditDebit == CreditDebit.DB)
                    {
                        tid.DB_Amount = amount;
                    }
                    else
                    {
                        tid.CR_Amount = amount;
                    }
                }
                tid.DocID = ti.DocID;
                // cập nhật thông tin tài khoản
                tmp_ac.d_Debit += tid.DB_Amount;
                tmp_ac.w_Debit += tid.DB_Amount;
                tmp_ac.m_Debit += tid.DB_Amount;
                tmp_ac.q_Debit += tid.DB_Amount;
                tmp_ac.y_Debit += tid.DB_Amount;

                tmp_ac.d_Credit += tid.CR_Amount;
                tmp_ac.w_Credit += tid.CR_Amount;
                tmp_ac.m_Credit += tid.CR_Amount;
                tmp_ac.q_Credit += tid.CR_Amount;
                tmp_ac.y_Credit += tid.CR_Amount;

                dt.AddCommand(trand.CreateOneTrandayDetail(tid));
                dt.AddCommand(da.EditOneAccount(tmp_ac));
            }
            #endregion
            if (dt.Execute() == true)
            {
                // thực hiện giao dịch thành công
                if (logger.IsDebugEnabled)
                {
                    logger.Debug(string.Format("Done create new one retail transaction: {0}", ti.DocID));
                }
                msg.ResponseCode = "00";    // Approved
                return(msg);
            }
            else
            {
                // thực hiện giao dịch không thành công
                if (logger.IsErrorEnabled)
                {
                    logger.Error(string.Format("Fails create new one retail transaction: {0}", ti.DocID));
                }
                msg.ResponseCode = "06";    // Error
                return(msg);
            }
        }
Beispiel #6
0
        /// <summary>
        /// tạo mới một giao dịch đảo ngược
        /// thêm một bản ghi vào bảng tranday
        /// thêm một bản ghi vào bảng trandaydetail
        /// nhưng với số tiền ghi âm mục đich triệt tiêu doanh số
        /// </summary>
        /// <param name="docid">
        /// số chứng từ hay mã số giao dịch cần đảo ngược
        /// hệ thống sẽ sinh ra số chứng từ mới hạch toán âm
        /// với số chứng từ là số chứng từ cần đảo ngược cộng với 2 ký tự ".1"
        /// </param>
        /// <returns>
        /// giá trị trả về là số giao dịch được tạo (1)
        /// nếu lỗi trả về giá trị 0
        /// </returns>
        public ResponseMessage Reverse(string trace, string docid)
        {
            ResponseMessage msg = new ResponseMessage();

            try
            {
                msg.LocalDate = DateTime.Now.ToString("MMdd");
                msg.LocalTime = DateTime.Now.ToString("hhmmss");

                D_Tranday    dt = new D_Tranday();
                Tranday_Info ti = dt.GetOneTranday(trace);
                if (ti == null)
                {
                    logger.Error(string.Format("Transaction {0} does not exists", trace));
                    msg.ResponseCode = "12";  // Invalid transaction
                    return(msg);
                }
                if (ti.AllowReverse == false)
                {
                    logger.Error(string.Format("Transaction {0} does not allow reverse", trace));
                    msg.ResponseCode = "06";  // Error
                    return(msg);
                }
                // cập nhật hồ sơ giao dịch không cho cho phép đảo ngược nữa
                ti.AllowReverse = false;
                dt.EditOneTranday(ti);
                ti.Descript      = string.Format("REVERSE: {0}", trace);
                ti.DocID         = base.GenerateDocId();
                ti.Trace         = trace;
                ti.OtherRef      = docid;
                ti.NextDocId     = "";
                ti.Status        = TransactionStatus.Approved;
                ti.TransDate     = transdate;
                ti.ValueDate     = transdate;
                ti.Verified      = true;
                ti.Verified_User = user_id;
                ti.UserCreate    = user_id;
                dt.CreateOneTranday(ti);
                D_Account       da = new D_Account();
                Account_Info    ai;
                D_TrandayDetail dtd = new D_TrandayDetail();
                foreach (TrandayDetail_Info tdi in ti.TrandayDetails)
                {
                    tdi.CR_Amount *= -1;
                    tdi.DB_Amount *= -1;
                    tdi.DocID      = ti.DocID;
                    dt.AddCommand(dtd.CreateOneTrandayDetail(tdi));

                    ai = da.GetOneAccount(tdi.Account_ID);
                    // ghi có tài khoản.
                    ai.y_Credit += tdi.CR_Amount;
                    ai.q_Credit += tdi.CR_Amount;
                    ai.m_Credit += tdi.CR_Amount;
                    ai.w_Credit += tdi.CR_Amount;
                    ai.d_Credit += tdi.CR_Amount;
                    // ghi nợ tài khoản.
                    ai.y_Debit += tdi.DB_Amount;
                    ai.q_Debit += tdi.DB_Amount;
                    ai.m_Debit += tdi.DB_Amount;
                    ai.w_Debit += tdi.DB_Amount;
                    ai.d_Debit += tdi.DB_Amount;
                    dt.AddCommand(da.EditOneAccount(ai));
                }
                if (dt.Execute())
                {
                    // nếu thực hiện thành công
                    if (logger.IsDebugEnabled)
                    {
                        logger.Debug(string.Format("Done create new merchant transaction: {0}", ti.DocID));
                    }
                    msg.ResponseCode = "00";  // Approved
                    return(msg);
                }
                else
                {
                    if (logger.IsErrorEnabled)
                    {
                        logger.Error(string.Format("Fails create new one merchant transaction: {0}", ti.DocID));
                    }
                    msg.ResponseCode = "06";  // Error
                    return(msg);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                msg.ResponseCode = "06";  // Error
                return(msg);
            }
        }
Beispiel #7
0
        /// <summary>
        /// chuyển khoản từ tài khoản db_account sang tài khoản cr_account
        /// (ghi nợ tài khoản db_account và ghi có tài khoản cr_account)
        /// </summary>
        /// <param name="amount">số tiền chuyển khoản</param>
        /// <param name="from_account">tài khoản ghi nợ</param>
        /// <param name="to_account">tài khoản ghi có</param>
        /// <returns>
        /// 0 không thành công
        /// 1 thành công
        /// </returns>
        public ResponseMessage FundTransfer(string trace, decimal amount, string db_account, string cr_account)
        {
            ResponseMessage msg = new ResponseMessage();

            msg.LocalDate = DateTime.Now.ToString("MMdd");
            msg.LocalTime = DateTime.Now.ToString("hhmmss");

            D_Tranday dt = new D_Tranday();

            // kiểm tra số chứng từ đã tồn tại hay chưa
            if (dt.IsExists("", trace))
            {
                logger.Error(string.Format("Transaction {0} does exists", trace));
                msg.ResponseCode = "12";    // Invalid transaction
                return(msg);
            }
            // kiểm tra hai tài khoản đã có hay chưa
            D_Account da = new D_Account();

            if (da.GetOneAccount(db_account) == null)
            {
                logger.Error(string.Format("From account {0} does not found", db_account));
                msg.ResponseCode = "78";    //No Account
                return(msg);
            }
            if (da.GetOneAccount(cr_account) == null)
            {
                logger.Error(string.Format("To account {0} does not found", cr_account));
                msg.ResponseCode = "78";    //No Account
                return(msg);
            }
            // kiểm tra số dư chuyển khoản.
            Tranday_Info ti = new Tranday_Info();

            ti.AllowReverse  = true;
            ti.Branch_ID     = branch_id;
            ti.Descript      = string.Format("transfer from {0} to {1} with amount = {2}", db_account, cr_account, amount);
            ti.NextDocId     = "";
            ti.Status        = TransactionStatus.Approved;
            ti.TranCode      = fundtransfer_trancode;
            ti.TransDate     = transdate;
            ti.UserCreate    = user_id;
            ti.ValueDate     = transdate;
            ti.Verified      = true;
            ti.Verified_User = user_id;
            ti.Trace         = trace;
            ti.DocID         = base.GenerateDocId();
            dt.CreateOneTranday(ti);
            D_TrandayDetail            dtd;
            TrandayDetail_Info         tdi;
            Account_Info               ai   = new Account_Info();
            D_TranCodeDetail           dcd  = new D_TranCodeDetail();
            List <TranCodeDetail_Info> list = dcd.GetTranCodeDetailByCode(fundtransfer_trancode);

            foreach (TranCodeDetail_Info tcdi in list)
            {
                dtd = new D_TrandayDetail();
                tdi = new TrandayDetail_Info();
                switch (tcdi.CreditDebit)
                {
                case  CreditDebit.DB:
                    if (db_account.IndexOf(tcdi.Account_ID) != 0)
                    {
                        // không xác định được nhóm tài khoản khách hàng
                        if (logger.IsErrorEnabled)
                        {
                            logger.Error(string.Format("{0} not in group {1}", db_account, tcdi.Account_ID));
                        }
                        msg.ResponseCode = "78";        //No Account
                        return(msg);
                    }
                    tdi.Account_ID = db_account;
                    tdi.DB_Amount  = amount;
                    ai             = da.GetOneAccount(tdi.Account_ID);
                    ai.y_Debit    += amount;
                    ai.q_Debit    += amount;
                    ai.m_Debit    += amount;
                    ai.w_Debit    += amount;
                    ai.d_Debit    += amount;
                    tdi.Ccy        = ai.Ccy;
                    break;

                case CreditDebit.CR:
                    if (cr_account.IndexOf(tcdi.Account_ID) != 0)
                    {
                        // không xác định được nhóm tài khoản khách hàng
                        if (logger.IsErrorEnabled)
                        {
                            logger.Error(string.Format("{0} not in group {1}", cr_account, tcdi.Account_ID));
                        }
                        msg.ResponseCode = "78";        //No Account
                        return(msg);
                    }
                    tdi.Account_ID = cr_account;
                    tdi.CR_Amount  = amount;
                    ai             = da.GetOneAccount(tdi.Account_ID);
                    ai.y_Credit   += amount;
                    ai.q_Credit   += amount;
                    ai.m_Credit   += amount;
                    ai.w_Credit   += amount;
                    ai.d_Credit   += amount;
                    tdi.Ccy        = ai.Ccy;
                    break;
                }
                tdi.SEQ   = tcdi.SEQ;
                tdi.DocID = ti.DocID;
                dt.AddCommand(dtd.CreateOneTrandayDetail(tdi));
                dt.AddCommand(da.EditOneAccount(ai));
            }
            if (dt.Execute() == true)
            {
                if (logger.IsDebugEnabled)
                {
                    logger.Debug(string.Format("Done transfer from {0} to {1}", db_account, cr_account));
                }
                msg.ResponseCode = "00";    //Approved
                return(msg);
            }
            else
            {
                if (logger.IsErrorEnabled)
                {
                    logger.Error(string.Format("Fails transfer from {0} to {1}", db_account, cr_account));
                }
                msg.ResponseCode = "06";    //Error
                return(msg);
            }
        }
Beispiel #8
0
 /// <summary>
 /// Lớp thư viện tài khoản cơ sở
 /// </summary>
 protected BaseAccount()
 {
     dalAc = new D_Account();
 }
Beispiel #9
0
        protected Account_Info Balance(string accountId)
        {
            D_Account da = new D_Account();

            return(da.GetOneAccount(accountId));
        }