private string HnQuotaInvoiceOrcTest() { string fpdm = Request.Form["fpdm"]; string fphm = Request.Form["fphm"]; return(ReceiptValidate.JlQuotaInvoice(fpdm, fphm)); }
private string submit() { List <string> codeList = JsonHelper.DeserializeJsonToList <string>(Request.Params["code"]); List <JObject> receiptList = JsonHelper.DeserializeJsonToList <JObject>(Request.Params["receipt"]); string batchNo = Request.Form["batchNo"].ToString(); string receiptDesc = Request.Form["receiptDesc"].ToString(); JObject result = new JObject(); // 返回结果jobject string codeString = ""; foreach (string code in codeList) { codeString += code + ","; } double totalReceiptAmount = 0.0; Boolean isReSubmit = false; // 生成批次号 if (string.IsNullOrEmpty(batchNo)) { batchNo = Guid.NewGuid().ToString("N"); } else { isReSubmit = true; } foreach (JObject temp in receiptList) { temp["code"] = codeString; temp["status"] = "已提交"; temp["createTime"] = DateTime.Now; temp["batchNo"] = batchNo; temp["receiptDesc"] = receiptDesc; temp["submitterId"] = userInfo.userId.ToString(); DataTable dt = new DataTable(); // 发票公司税号校验 if (!string.IsNullOrEmpty(temp["sellerRegisterNum"].ToString())) { string sellerRegisterNum = temp["sellerRegisterNum"].ToString(); string checkRegisterNumSql = string.Format("select 1 from company_register_num t1 left join yl_reimburse t2 on t1.companyName = t2.fee_company " + "where t1.registerNum = '{0}' and t2.code = '{1}'", sellerRegisterNum, codeString.Split(',')[0]); DataTable checkRegisterNumTable = SqlHelper.Find(checkRegisterNumSql).Tables[0]; if (checkRegisterNumTable.Rows.Count == 0) { result.Add("code", 400); result.Add("msg", string.Format("发票税号:{0},与所选公司不匹配!", sellerRegisterNum)); return(result.ToString()); } } // 发票查重 if (temp["receiptCode"].ToString() != "" && temp["receiptCode"].ToString() != "") { string checkDuplicateSql = string.Format("select 1 from yl_reimburse_detail where receiptCode = '{0}' and receiptNum = '{1}' and status != '拒绝' and status != '草稿'", temp["receiptCode"], temp["receiptNum"]); DataTable checkDuplicateDt = SqlHelper.Find(checkDuplicateSql).Tables[0]; if (checkDuplicateDt.Rows.Count > 0) { result.Add("code", 400); result.Add("msg", string.Format("发票代码:{0},发票号码:{1},此发票重复使用!", temp["receiptCode"], temp["receiptNum"])); return(result.ToString()); } } // 发票验真伪 if (temp["feeType"] != null && (temp["feeType"].ToString() == "出租车票" || temp["feeType"].ToString() == "通用机打发票" || temp["feeType"].ToString() == "定额发票" || temp["feeType"].ToString() == "汽车票") && temp["receiptNum"].ToString() != temp["receiptCode"].ToString()) { string province = temp["receiptPlace"].ToString(); if (!province.Contains("北京") && !province.Contains("上海") && !province.Contains("天津") && !province.Contains("重庆")) { province = province.Substring(0, province.IndexOf("省")); } string validateMsg = ""; if (province == "江西") { //validateMsg = ReceiptValidate.JxHandWriting(temp["receiptNum"].ToString(), temp["receiptCode"].ToString()); //JObject tempJObject = JObject.Parse(validateMsg); //if (tempJObject.Property("LX") == null || tempJObject.Property("LX").ToString() == "") //{ // result.Add("code", 400); // result.Add("msg", string.Format("发票代码:{0},发票号码:{1},此发票与税务机关信息不符,请确定发票代码和发票号码后重新提交!", temp["receiptCode"], temp["receiptNum"])); // return result.ToString(); //} } else if (province == "湖南") { validateMsg = ReceiptValidate.HnQuotaInvoice(temp["receiptCode"].ToString(), temp["receiptNum"].ToString()); JObject tempJObject = JObject.Parse(validateMsg); if (tempJObject["status"].ToString() == "0") { result.Add("code", 400); result.Add("msg", string.Format("发票代码:{0},发票号码:{1},此发票与税务机关信息不符,请确定发票代码和发票号码后重新提交!", temp["receiptCode"], temp["receiptNum"])); return(result.ToString()); } } } // 费用标准控制 UserInfo user = (UserInfo)Session["user"]; if (user.userName != "李茂龙") { string temp_sql = string.Format("select post from users where userId = '{0}';", user.userId); string relativePerson = temp["relativePerson"].ToString(); temp_sql += string.Format("select post from users where userName = '******';", relativePerson); temp_sql += string.Format("select department from v_user_department_post where userId = '{0}'", user.userId); DataSet ds = SqlHelper.Find(temp_sql); dt = ds.Tables[0]; if (dt != null && dt.Rows.Count > 0) { string startTm = temp["activityDate"].ToString(); string endTm = string.IsNullOrEmpty(temp["activityEndDate"].ToString()) ? temp["activityDate"].ToString() : temp["activityEndDate"].ToString(); string post = dt.Rows[0][0].ToString(); double receiptAmount = double.Parse(temp["receiptAmount"].ToString()); DateTime d1 = Convert.ToDateTime(endTm); DateTime d2 = Convert.ToDateTime(startTm); DateTime d3 = Convert.ToDateTime(string.Format("{0}-{1}-{2}", d1.Year, d1.Month, d1.Day)); DateTime d4 = Convert.ToDateTime(string.Format("{0}-{1}-{2}", d2.Year, d2.Month, d2.Day)); double interval_time = (d3 - d4).Days + 1; //double interval_time = Convert.ToDateTime(endTm).Subtract(Convert.ToDateTime(startTm)).Days + 1; ///// 差旅费算头算尾 int endHour = Convert.ToDateTime(endTm).Hour; int startHour = Convert.ToDateTime(startTm).Hour; if (endHour <= 12) { interval_time -= 0.5; } if (startHour >= 12 && startHour <= 18) { interval_time -= 0.5; } else if (startHour > 18) { interval_time -= 1; } // 此处实报实销和出差补贴是反的 方便页面显示 if (temp["receiptType"].ToString() == "实报实销") { dt = ds.Tables[2]; string userDepartmentName = dt.Rows[0][0].ToString(); if (userDepartmentName.Contains("营销中心")) { if (!post.Contains("经理") && !post.Contains("总监") && !post.Contains("副总经理") && !post.Contains("总经理")) { if (receiptAmount > 80 * interval_time) { result.Add("code", 400); result.Add("msg", "出差补贴不能超过一天80"); return(result.ToString()); } } else { if (receiptAmount > 150 * interval_time) { result.Add("code", 400); result.Add("msg", "出差补贴不能超过一天150"); return(result.ToString()); } } } else { if (receiptAmount > 80 * interval_time) { result.Add("code", 400); result.Add("msg", "出差补贴不能超过一天80"); return(result.ToString()); } } } else if (temp["receiptType"].ToString() == "住宿费") { // 比较提交人的岗位和同行人的岗位 按大的计算 dt = ds.Tables[1]; if (dt != null && dt.Rows.Count > 0) { string relativePost = dt.Rows[0][0].ToString(); if (relativePost == "总经理") { post = "总经理"; } else if (relativePost == "副总经理") { if (post != "总经理") { post = relativePost; } } else if (relativePost.Contains("总监")) { if (post != "总经理" && post != "副总经理") { post = relativePost; } } else if (relativePost.Contains("经理")) { if (post != "总经理" && post != "副总经理" && !post.Contains("总监")) { post = relativePost; } } else if (relativePost.Contains("主管")) { if (post != "总经理" && post != "副总经理" && !post.Contains("总监") && !post.Contains("经理")) { post = relativePost; } } else { post = relativePost; } } // 住宿费算头不算尾 //interval_time = Convert.ToDateTime(endTm).Subtract(Convert.ToDateTime(startTm)).Days; d1 = Convert.ToDateTime(endTm); d2 = Convert.ToDateTime(startTm); d3 = Convert.ToDateTime(string.Format("{0}-{1}-{2}", d1.Year, d1.Month, d1.Day)); d4 = Convert.ToDateTime(string.Format("{0}-{1}-{2}", d2.Year, d2.Month, d2.Day)); interval_time = (d3 - d4).Days; if (post.Contains("总经理")) { } else if (post.Contains("副总经理")) { if (checkCityLevel(temp["receiptPlace"].ToString()) == "1" || checkCityLevel(temp["receiptPlace"].ToString()) == "2") { if (receiptAmount > 360 * interval_time) { result.Add("code", 400); result.Add("msg", "住宿费不能超过一晚360"); return(result.ToString()); } } else if (checkCityLevel(temp["receiptPlace"].ToString()) == "3" || checkCityLevel(temp["receiptPlace"].ToString()) == "4") { if (receiptAmount > 280 * interval_time) { result.Add("code", 400); result.Add("msg", "住宿费不能超过一晚280"); return(result.ToString()); } } } else if (post.Contains("总监")) { if (checkCityLevel(temp["receiptPlace"].ToString()) == "1" || checkCityLevel(temp["receiptPlace"].ToString()) == "2") { if (receiptAmount > 280 * interval_time) { result.Add("code", 400); result.Add("msg", "住宿费不能超过一晚280"); return(result.ToString()); } } else if (checkCityLevel(temp["receiptPlace"].ToString()) == "3" || checkCityLevel(temp["receiptPlace"].ToString()) == "4") { if (receiptAmount > 220 * interval_time) { result.Add("code", 400); result.Add("msg", "住宿费不能超过一晚220"); return(result.ToString()); } } } else if (post.Contains("经理")) { if (checkCityLevel(temp["receiptPlace"].ToString()) == "1") { if (receiptAmount > 220 * interval_time) { result.Add("code", 400); result.Add("msg", "住宿费不能超过一晚220"); return(result.ToString()); } } else if (checkCityLevel(temp["receiptPlace"].ToString()) == "2") { if (receiptAmount > 180 * interval_time) { result.Add("code", 400); result.Add("msg", "住宿费不能超过一晚180"); return(result.ToString()); } } else if (checkCityLevel(temp["receiptPlace"].ToString()) == "3") { if (receiptAmount > 150 * interval_time) { result.Add("code", 400); result.Add("msg", "住宿费不能超过一晚150"); return(result.ToString()); } } else if (checkCityLevel(temp["receiptPlace"].ToString()) == "4") { if (receiptAmount > 120 * interval_time) { result.Add("code", 400); result.Add("msg", "住宿费不能超过一晚120"); return(result.ToString()); } } } else if (post.Contains("主管")) { if (checkCityLevel(temp["receiptPlace"].ToString()) == "1") { if (receiptAmount > 200 * interval_time) { result.Add("code", 400); result.Add("msg", "住宿费不能超过一晚200"); return(result.ToString()); } } else if (checkCityLevel(temp["receiptPlace"].ToString()) == "2") { if (receiptAmount > 160 * interval_time) { result.Add("code", 400); result.Add("msg", "住宿费不能超过一晚160"); return(result.ToString()); } } else if (checkCityLevel(temp["receiptPlace"].ToString()) == "3") { if (receiptAmount > 130 * interval_time) { result.Add("code", 400); result.Add("msg", "住宿费不能超过一晚130"); return(result.ToString()); } } else if (checkCityLevel(temp["receiptPlace"].ToString()) == "4") { if (receiptAmount > 110 * interval_time) { result.Add("code", 400); result.Add("msg", "住宿费不能超过一晚110"); return(result.ToString()); } } } else { if (checkCityLevel(temp["receiptPlace"].ToString()) == "1") { if (receiptAmount > 180 * interval_time) { result.Add("code", 400); result.Add("msg", "住宿费不能超过一晚180"); return(result.ToString()); } } else if (checkCityLevel(temp["receiptPlace"].ToString()) == "2") { if (receiptAmount > 150 * interval_time) { result.Add("code", 400); result.Add("msg", "住宿费不能超过一晚150"); return(result.ToString()); } } else if (checkCityLevel(temp["receiptPlace"].ToString()) == "3") { if (receiptAmount > 120 * interval_time) { result.Add("code", 400); result.Add("msg", "住宿费不能超过一晚120"); return(result.ToString()); } } else if (checkCityLevel(temp["receiptPlace"].ToString()) == "4") { if (receiptAmount > 100 * interval_time) { result.Add("code", 400); result.Add("msg", "住宿费不能超过一晚100"); return(result.ToString()); } } } } } } // 计算税率 if (temp["receiptPerson"].ToString() != "" && temp["receiptPerson"].ToString() != "无") { dt = SqlHelper.Find(string.Format("select 1 from users where userName = '******'", temp["receiptPerson"].ToString())).Tables[0]; if (dt.Rows.Count > 0 && (temp["receiptType"].ToString().Equals("出差车船费") || temp["receiptType"].ToString().Equals("培训费"))) { if (temp["feeType"].ToString().Equals("火车票")) { temp["receiptTax"] = Math.Round(double.Parse(temp["receiptAmount"].ToString()) / 1.09 * 0.09, 3); } else if (temp["feeType"].ToString().Equals("飞机票")) { temp["receiptTax"] = Math.Round((double.Parse(temp["receiptAmount"].ToString()) - 50) / 1.09 * 0.09, 3); } else if (temp["feeType"].ToString().Equals("汽车票")) { temp["receiptTax"] = Math.Round(double.Parse(temp["receiptAmount"].ToString()) / 1.03 * 0.03, 3); } } if (dt.Rows.Count == 0) { if (temp["receiptType"].ToString().Equals("出差车船费") || temp["receiptType"].ToString().Equals("住宿费") || temp["receiptType"].ToString().Equals("出差补贴")) { result.Add("code", 400); result.Add("msg", "外部人员不能报销差旅费"); return(result.ToString()); } } } totalReceiptAmount += double.Parse(temp["receiptAmount"].ToString()); } string sql = ""; if (isReSubmit) { // 如果是被拒绝后重新提交 则删除之前记录再新增 sql += string.Format("delete from yl_reimburse_detail where batchNo = '{0}';", batchNo); } sql += SqlHelper.GetInsertString(receiptList, "yl_reimburse_detail"); string msg = SqlHelper.Exce(sql); if (msg.Contains("操作成功")) { result.Add("code", 200); result.Add("msg", batchNo); // 更新单据可用额度 foreach (string code in codeList) { double remain_fee_amount = double.Parse(SqlHelper.Find(string.Format("select remain_fee_amount from yl_reimburse where code = '{0}'", code)).Tables[0].Rows[0][0].ToString()); string tempSql = ""; if (remain_fee_amount >= totalReceiptAmount) { tempSql = string.Format("update yl_reimburse set remain_fee_amount = {0} where code = '{1}';", (remain_fee_amount - totalReceiptAmount), code); tempSql += string.Format("delete from yl_reimburse_detail_relevance where batchNo = '{0}' and reimburseCode = '{1}';", batchNo, code); tempSql += string.Format("insert into yl_reimburse_detail_relevance (batchNo,reimburseCode,amount) values ('{0}','{1}',{2});", batchNo, code, totalReceiptAmount); SqlHelper.Exce(tempSql); break; } else { tempSql = string.Format("update yl_reimburse set remain_fee_amount = {0} where code = '{1}';", 0, code); tempSql += string.Format("delete from yl_reimburse_detail_relevance where batchNo = '{0}' and reimburseCode = '{1}';", batchNo, code); tempSql += string.Format("insert into yl_reimburse_detail_relevance (batchNo,reimburseCode,amount) values ('{0}','{1}',{2});", batchNo, code, remain_fee_amount); totalReceiptAmount -= remain_fee_amount; SqlHelper.Exce(tempSql); } } UserInfo user = (UserInfo)Session["user"]; // 发送审批消息给财务进行审批 WxNetSalesHelper wxNetSalesHelper = new WxNetSalesHelper("v5afj_CYpboe-JWNOrCU0Cy-xP5krFq6cWYM9KZfe4o", "发票上报", "1000020"); //// 给待审批人发送消息 wxNetSalesHelper.GetJsonAndSendWxMsg("18100661|19080720", "请及时审批 提交人为:" + user.userName + "的发票,谢谢!", "http://yelioa.top//mApprovalReimburseDetail.aspx", "1000020"); //// 给提交人发送消息 wxNetSalesHelper.GetJsonAndSendWxMsg(user.wechatUserId, "您的发票信息已提交 请耐心等待财务审批", "http://yelioa.top//mMySubmittedReimburseDetail.aspx", "1000020"); } else { result.Add("code", 500); result.Add("msg", msg); } return(result.ToString()); }