public static string updateActualFee(ArrayList list)
    {
        ArrayList codeList      = new ArrayList();
        ArrayList actualFeeList = new ArrayList();

        foreach (Dictionary <string, string> dict in list)
        {
            if (dict != null)
            {
                codeList.Add(dict["Id"].ToString());
                actualFeeList.Add(dict["ApprovalNumber"].ToString());
            }
            else
            {
                codeList.Add("");
                actualFeeList.Add("");
            }
        }

        string res = OperationDeliverSrv.updateActualFee(list);

        OperationDeliverSrv.UpdateOperationApprovalTime(codeList);

        // 插入一条数据到销售日表中
        OperationDeliverSrv.insertSalesData(codeList);

        string[]  msgs   = res.Split(';');
        DataTable dtUser = ReimbursementSrv.GetUserNameAndWxUserId();
        WxCommon  wx     = new WxCommon("DeliverApplyReport",
                                        "vvsnJs9JYf8AisLWOE4idJbdR1QGc7roIcUtN6P2Lhc",
                                        "1000009",
                                        "");

        for (int i = 0; i < msgs.Length - 1; i++)
        {
            SqlExceRes sqlRes = new SqlExceRes(msgs[i]);
            if (sqlRes.Result == SqlExceRes.ResState.Success)
            {
                Dictionary <string, string> dict = (Dictionary <string, string>)list[i];
                string WxUserId = "";
                foreach (DataRow row in dtUser.Rows)
                {
                    if (row["userName"].ToString() == dict["ApprovalName"])
                    {
                        WxUserId = row["wechatUserId"].ToString();
                        break;
                    }
                }
                if (!string.IsNullOrEmpty(WxUserId))
                {
                    // 发送审批的消息给提交者
                    wx.SendWxMsg(WxUserId, "审批通知", "您编号为" + codeList[i] + "的发货单据已被运营部进行实发数量复审,审批人为:"
                                 + dict["ApprovalName"] + ",实发数量为" + actualFeeList[i] + ",请知悉"
                                 , "http://yelioa.top//mDeliverApplyReportAppRoval.aspx?type=0&docCode=" + codeList[i]);
                }
            }
        }

        return(res);
    }
    public static DataTable getApprovalRecordCount(string code)
    {
        DataSet ds = ReimbursementSrv.getApprovalRecordCount(code);

        if (ds == null)
        {
            return(null);
        }
        return(ds.Tables[0]);
    }
    public static DataTable getApproverByCode(string docCode)
    {
        DataSet ds = ReimbursementSrv.getApproverByCode(docCode);

        if (ds == null)
        {
            return(null);
        }
        return(ds.Tables[0]);
    }
    public static DataTable findByCode(string code)
    {
        DataSet ds = ReimbursementSrv.findByCond(code, null, null, null, null, null, null, null, null, null, null, null, null);

        if (ds == null)
        {
            return(null);
        }

        return(ds.Tables[0]);
    }
    public static DataTable findByCond(string applystarttm, string applyendtm, string starttm, string endtm, string applyName, string depart, string fee_depart, string fee_detail
                                       , string account_status, string status, string sortName, string sortOrder)
    {
        DataSet ds = ReimbursementSrv.findByCond(null, applystarttm, applyendtm, starttm, endtm, applyName, depart, fee_depart, fee_detail, account_status, status, sortName, sortOrder);

        if (ds == null)
        {
            return(null);
        }

        return(ds.Tables[0]);
    }
    public static string batchInsertReimburse(Dictionary <string, object> dict)
    {
        string msg = ReimbursementSrv.batchInsertReimburse(dict);

        if (msg.Contains("操作成功"))
        {
            return("成功");
        }
        else
        {
            return("失败");
        }
    }
    public static string updateActualFee(List <Dictionary <string, object> > list)
    {
        string res = ReimbursementSrv.updateActualFee(list);

        //string[] msgs = res.Split(';');
        //DataTable dtUser = ReimbursementSrv.GetUserNameAndWxUserId();
        //WxCommon wx = new WxCommon("mMobileReimbursement",
        //    "UM0i5TXSIqQIOWk-DmUlfTqBqvZAfbZdGGDKiFZ-nRk",
        //    "1000006",
        //    "");
        //for (int i = 0; i < msgs.Length - 1; i++)
        //{
        //    SqlExceRes sqlRes = new SqlExceRes(msgs[i]);
        //    if (sqlRes.Result == SqlExceRes.ResState.Success)
        //    {
        //        //Dictionary<string, string> dict = (Dictionary<string, string>)list[i];
        //        //string WxUserId = SqlHelper.Find("select wechatUserId from users where userName = '******'").Tables[0].Rows[0][0].ToString();
        //        //foreach (DataRow row in dtUser.Rows)
        //        //{
        //        //    if (row["userName"].ToString() == dict["name"])
        //        //    {
        //        //        WxUserId = row["wechatUserId"].ToString();
        //        //        break;
        //        //    }
        //        //}
        //        //if (!string.IsNullOrEmpty(WxUserId))
        //        //{
        //        //    // 发送审批的消息给提交者
        //        //    wx.SendWxMsg(WxUserId, "审批通知", "您编号为:" + codeList[i] + "的审批单据已被财务进行金额复审,审批人为:"
        //        //        + dict["approver"] + ",财务已付款" + actualFeeList[i] + "元,请知悉"
        //        //        , "http://yelioa.top/mMySubmittedReimburse.aspx?docCode=" + codeList[i]);
        //        //}
        //    }
        //}

        return(res);
    }
 public static DataSet checkApprover(string code, string userId)
 {
     return(ReimbursementSrv.checkApprover(userId, code));
 }
 public static DataSet GetDocumnetsInfosByCode(string DocCode, string name)
 {
     return(ReimbursementSrv.GetDocumnetsInfosByCode(DocCode, name));
 }
 public static DataSet GetDocumnetsInfosToBeSubmitedByMe(string userName, string keyword)
 {
     return(ReimbursementSrv.GetDocumnetsInfosToBeSubmitedByMe(userName, keyword));
 }
 public static DataSet GetDocumnetsInfosRelatedToMe(string userId, string keyword)
 {
     return(ReimbursementSrv.GetDocumnetsInfosRelatedToMe(userId, keyword));
 }
 public static string recordAccountEvent(DataTable dt)
 {
     return(ReimbursementSrv.recordAccountEvent(dt));
 }
 public static DataSet GetInfos(string name, string keyword, int year, int month)
 {
     return(ReimbursementSrv.GetInfos(name, keyword, year, month));
 }
    /// <summary>
    /// 财务单据审批
    /// </summary>
    /// <param name="list">
    /// list元素为Dictionary<string,string>,其中key包含:
    /// 单据编号,code
    /// 审批人,approver
    /// 审批结果,ApprovalResult
    /// 审批意见,ApprovalOpinions
    /// 审批时间,approval_time
    /// 提交人, name
    /// </param>
    /// <returns>
    ///
    /// </returns>
    public static string Approval(ArrayList list)
    {
        // 记录code 因为下一步不更新code会把code删除
        ArrayList codeList = new ArrayList();

        foreach (Dictionary <string, string> dict in list)
        {
            if (dict != null)
            {
                codeList.Add(dict["code"].ToString());
            }
            else
            {
                codeList.Add("");
            }
        }

        string res = ReimbursementSrv.Approval(list);

        string[]  msgs   = res.Split(';');
        DataTable dtUser = ReimbursementSrv.GetUserNameAndWxUserId();
        WxCommon  wx     = new WxCommon("mMobileReimbursement",
                                        "UM0i5TXSIqQIOWk-DmUlfTqBqvZAfbZdGGDKiFZ-nRk",
                                        "1000006",
                                        "");

        for (int i = 0; i < msgs.Length - 1; i++)
        {
            SqlExceRes sqlRes = new SqlExceRes(msgs[i]);
            if (sqlRes.Result == SqlExceRes.ResState.Success)
            {
                Dictionary <string, string> dict = (Dictionary <string, string>)list[i];
                string WxUserId = "";
                foreach (DataRow row in dtUser.Rows)
                {
                    if (row["userName"].ToString() == dict["name"])
                    {
                        WxUserId = row["wechatUserId"].ToString();
                        break;
                    }
                }
                if (!string.IsNullOrEmpty(WxUserId))
                {
                    // 发送审批的消息给提交者
                    wx.SendWxMsg(WxUserId, "审批通知", "您编号为:" + codeList[i] + "的审批单据已被财务审批,审批人为:"
                                 + dict["account_approver"] + ",结果为:" + dict["account_result"] + ",意见为:" + dict["account_opinion"] + ",请知悉"
                                 , "http://yelioa.top/mMySubmittedReimburse.aspx?docCode=" + codeList[i]);
                }

                // 审批拒绝的需要把关联的发票一起拒绝
                if ("拒绝" == dict["account_result"].ToString())
                {
                    string sql = string.Format("update yl_reimburse_detail set status = '拒绝', opinion = '关联的移动报销单据被拒绝' where code like '%{0}%'", codeList[i]);

                    // 删除关联差旅申请
                    sql += string.Format("delete from wf_form_差旅申请 where reimburseCode = '{0}';", codeList[i]);

                    // 删除关联借款单 并把借款单的金额还原
                    DataTable dt = SqlHelper.Find(string.Format("select * from yl_reimburse_loan where ReimburseCode = '{0}'", codeList[i])).Tables[0];

                    sql += string.Format("delete from yl_reimburse_loan where ReimburseCode = '{0}';", codeList[i]);

                    foreach (DataRow dr in dt.Rows)
                    {
                        decimal amount   = Decimal.Parse(dr["amount"].ToString());
                        string  tempCode = dr["docCode"].ToString();

                        sql += string.Format("update wf_form_借款单 set remainAmount = remainAmount + {0} where docCode = '{1}';", amount, tempCode);
                    }

                    SqlHelper.Exce(sql);
                }
            }
        }
        return(res);
    }