| using Model; | 
| using Newtonsoft.Json; | 
| using Newtonsoft.Json.Linq; | 
| using Pub_Class; | 
| using System; | 
| using System.Collections; | 
| using System.Collections.Generic; | 
| using System.Data; | 
| using System.Data.SqlClient; | 
| using System.Web.Http; | 
| using WebAPI.Models; | 
| using SyntacticSugar.constant; | 
|   | 
| namespace WebAPI.Controllers | 
| { | 
|     //销售核销 | 
|     public class Xs_SellOutBillList_SecController : ApiController | 
|     { | 
|         //获取系统参数 | 
|         Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter(); | 
|         public DBUtility.ClsPub.Enum_BillStatus BillStatus; | 
|   | 
|   | 
|         private json objJsonResult = new json(); | 
|         SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); | 
|         DataSet ds; | 
|   | 
|         #region 通用查询方法 | 
|         [Route("CommonModel/searchMethod")] | 
|         [HttpGet] | 
|         public object searchMethod(string sql,string user,string ModRightNameCheck) | 
|         { | 
|             try | 
|             { | 
|                  | 
|                 //判断查询权限 | 
|                 if (ModRightNameCheck !=null&&ModRightNameCheck != "") | 
|                 { | 
|                     if (!DBUtility.ClsPub.Security_Log(ModRightNameCheck, 1, false, user)) | 
|                     { | 
|                         objJsonResult.code = "0"; | 
|                         objJsonResult.count = 0; | 
|                         objJsonResult.Message = "无权限查询!"; | 
|                         objJsonResult.data = null; | 
|                         return objJsonResult; | 
|                     } | 
|                 } | 
|   | 
|                 ds = oCN.RunProcReturn(sql, sql); | 
|   | 
|                 //获取列信息 | 
|                 List<object> columnNameList = new List<object>(); //定义声明变量 ,把通过 new List<object>()创建的 实例,赋值给变量 | 
|                 foreach (DataColumn col in ds.Tables[0].Columns)//遍历ds中第一个表(Tables[0])的所有列(Columns)每次循环中,col变量会持有当前列的引用 | 
|                 { | 
|                     Type dataType = col.DataType; //获取当前数据类型传入 自定义变量datadataType | 
|                     string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}"; //字符串拼接         // 将列名和数据类型信息拼接成一个JSON格式的字符串 | 
|                     columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名 | 
|                 } | 
|   | 
|   | 
|                 objJsonResult.code = "1"; | 
|                 objJsonResult.count = 1; | 
|                 objJsonResult.Message = "Sucess!"; | 
|                 objJsonResult.data = ds.Tables[0]; | 
|                 objJsonResult.list = columnNameList;//将columnNameList赋值给objJsonResult的list属性 | 
|                 return objJsonResult; | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 objJsonResult.code = "0"; | 
|                 objJsonResult.count = 0; | 
|                 objJsonResult.Message = "Exception!" + e.ToString(); | 
|                 objJsonResult.data = null; | 
|                 return objJsonResult; | 
|             } | 
|         } | 
|         #endregion | 
|   | 
|         #region 通用方法 | 
|         [Route("CommonModel/commonMethod")] | 
|         [HttpGet] | 
|         public object commonMethod(string sql, string user, string ModRightNameCheck) | 
|         { | 
|             try | 
|             { | 
|   | 
|                 //判断查询权限 | 
|                 if (ModRightNameCheck != null && ModRightNameCheck != "") | 
|                 { | 
|                     if (!DBUtility.ClsPub.Security_Log(ModRightNameCheck, 1, false, user)) | 
|                     { | 
|                         objJsonResult.code = "0"; | 
|                         objJsonResult.count = 0; | 
|                         objJsonResult.Message = "无权限查询!"; | 
|                         objJsonResult.data = null; | 
|                         return objJsonResult; | 
|                     } | 
|                 } | 
|   | 
|                 oCN.RunProc(sql); | 
|   | 
|                 objJsonResult.code = "1"; | 
|                 objJsonResult.count = 1; | 
|                 objJsonResult.Message = "Sucess!"; | 
|                 objJsonResult.data = null; | 
|                 return objJsonResult; | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 objJsonResult.code = "0"; | 
|                 objJsonResult.count = 0; | 
|                 objJsonResult.Message = "Exception!" + e.ToString(); | 
|                 objJsonResult.data = null; | 
|                 return objJsonResult; | 
|             } | 
|         } | 
|         #endregion | 
|   | 
|         #region 加入单据到待核销队列 | 
|         [Route("Xs_SellOutBillList_Sec/addBillToWaitSecList")] | 
|         [HttpGet] | 
|         public object addBillToWaitSecList(int hmainid, string user) | 
|         { | 
|             try | 
|             { | 
|                 string sql = "select * from Kf_ICStockBillMain where HBillType = '1205' and HInterID = " + hmainid; | 
|                 ds = oCN.RunProcReturn(sql, "Kf_ICStockBillMain"); | 
|   | 
|                 string sql1 = "insert into Xs_SellOutBillList_Sec(HMaker,HMakeDate,HMainSourceInterID,MainSourceBillNo,HMainSourceBillType) " + | 
|                     " values(" + | 
|                     "'" + user + "'" + | 
|                     "," + "getdate()" + "" + | 
|                     "," + hmainid + "" + | 
|                     ",'" + ds.Tables[0].Rows[0]["HBillNo"].ToString() + "'" + | 
|                     ",'" + "1205" + "'" + | 
|                     ")"; | 
|                 oCN.RunProc(sql1); | 
|   | 
|                 objJsonResult.code = "1"; | 
|                 objJsonResult.count = 1; | 
|                 objJsonResult.Message = "Sucess!"; | 
|                 objJsonResult.data = null; | 
|                 return objJsonResult; | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 objJsonResult.code = "0"; | 
|                 objJsonResult.count = 0; | 
|                 objJsonResult.Message = "Exception!" + e.ToString(); | 
|                 objJsonResult.data = null; | 
|                 return objJsonResult; | 
|             } | 
|         } | 
|         #endregion | 
|   | 
|         #region 核销生成应收单 | 
|         [Route("Xs_SellOutBillList_Sec/SecToReceivableBill")] | 
|         [HttpGet] | 
|         public object SecToReceivableBill(string hmainidList, string user) | 
|         { | 
|             oCN.BeginTran(); | 
|             try | 
|             { | 
|                 //将待核销列表中的数据标记为已核销 | 
|                 string sql0 = $"update Xs_SellOutBillList_Sec set HSecEmp = '{user}',HSecTime = getdate() where HMainSourceInterID in ({hmainidList})"; | 
|                 oCN.RunProc(sql0); | 
|   | 
|                 //生成应付单 | 
|                 string sql = $"select * from h_v_IF_SellOutBillList_EditInit where hmainid in ({ hmainidList})"; | 
|                 ds = oCN.RunProcReturn(sql, "h_v_IF_SellOutBillList_EditInit"); | 
|                 DAL.ClsXs_ReceivableBill oBill = new DAL.ClsXs_ReceivableBill(); | 
|                 oBill.omodel.HInterID = DBUtility.ClsPub.CreateBillID("1426", ref DBUtility.ClsPub.sExeReturnInfo); | 
|                 oBill.omodel.HBillNo = DBUtility.ClsPub.CreateBillCode_Prod("1426", ref DBUtility.ClsPub.sExeReturnInfo,false); | 
|                 oBill.omodel.HDate = DateTime.Now; | 
|                 oBill.omodel.HPeriod = DateTime.Now.Month; | 
|                 oBill.omodel.HYear = DateTime.Now.Year; | 
|                 oBill.omodel.HMainSourceInterID = 0; | 
|                 oBill.omodel.HMainSourceEntryID = 0; | 
|                 oBill.omodel.HMainSourceBillNo = ""; | 
|                 oBill.omodel.HMainSourceBillType = "1205"; | 
|                 oBill.omodel.HMaker = user; | 
|                 oBill.omodel.HMakeDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); | 
|                 oBill.omodel.HSSID = 0; | 
|                 oBill.omodel.HSellSID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HSellSID"]); | 
|                 oBill.omodel.HReceiveDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); | 
|                 oBill.omodel.HCusID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HSupID"]); | 
|                 oBill.omodel.HCurID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HCurID"]); | 
|                 oBill.omodel.HExRate = DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[0]["汇率"]); | 
|                 oBill.omodel.HEmpID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HEmpID"]); | 
|                 oBill.omodel.HMangerID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HManagerID"]); | 
|                 oBill.omodel.HDeptID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HDeptID"]); | 
|                 oBill.omodel.HExplanation = ""; | 
|                 oBill.omodel.HInnerBillNo = ""; | 
|                 oBill.omodel.HRemark = ""; | 
|                 oBill.omodel.HPriceType = ""; | 
|                 oBill.omodel.HProjectID = 0; | 
|   | 
|                 for(int i = 0; i < ds.Tables[0].Rows.Count; i++) | 
|                 { | 
|                     Model.ClsXs_ReceivableBillSub oItemSub = new Model.ClsXs_ReceivableBillSub(); | 
|                     oItemSub.HInterID = oBill.omodel.HInterID; | 
|                     oItemSub.HEntryID = (i + 1); | 
|                     oItemSub.HBillNo_bak = oBill.omodel.HBillNo; | 
|                     oItemSub.HMaterID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[i]["HMaterID"]); | 
|                     oItemSub.HUnitID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[i]["HUnitID"]); | 
|                     oItemSub.HQty = DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[i]["数量"]); | 
|                     oItemSub.HPrice = DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[i]["单价"]); | 
|                     oItemSub.HTaxPrice = DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[i]["含税单价"]); | 
|                     oItemSub.HDiscountRate = 1; | 
|                     oItemSub.HRelTaxPrice = DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[i]["含税单价"]); | 
|                     oItemSub.HTaxRate = DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[i]["税率"]); | 
|                     oItemSub.HTaxMoney = DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[i]["税率"]) * DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[0]["金额"]); | 
|                     oItemSub.HlineTotal = DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[i]["价税合计"]); | 
|                     oItemSub.HlineTotalBB = DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[i]["价税合计"]) * oBill.omodel.HExRate; | 
|                     oItemSub.HMoney = DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[i]["金额"]); | 
|                     oItemSub.HMoneyBB = DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[i]["金额"]) * oBill.omodel.HExRate; | 
|                     oItemSub.HRemark = ""; | 
|                     oItemSub.HSourceInterID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[i]["hmainid"]); | 
|                     oItemSub.HSourceEntryID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[i]["hsubid"]); | 
|                     oItemSub.HSourceBillNo =  DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["单据号"]); | 
|                     oItemSub.HSourceBillType = "1205"; | 
|                     oItemSub.HRelationQty = 0; | 
|                     oItemSub.HRelationMoney = 0; | 
|   | 
|                     oBill.DetailColl.Add(oItemSub); | 
|                 } | 
|   | 
|                 bool bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo); | 
|   | 
|                 if (bResult) | 
|                 { | 
|                     oCN.Commit(); | 
|                     objJsonResult.code = "0"; | 
|                     objJsonResult.count = 1; | 
|                     objJsonResult.Message = "核销成功!"; | 
|                     objJsonResult.data = 1; | 
|                     return objJsonResult; | 
|                 } | 
|                 else | 
|                 { | 
|                     oCN.RollBack(); | 
|                     objJsonResult.code = "0"; | 
|                     objJsonResult.count = 0; | 
|                     objJsonResult.Message = "核销失败!" + DBUtility.ClsPub.sExeReturnInfo; | 
|                     objJsonResult.data = 1; | 
|                     return objJsonResult; | 
|                 } | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 oCN.RollBack(); | 
|                 objJsonResult.code = "0"; | 
|                 objJsonResult.count = 0; | 
|                 objJsonResult.Message = "Exception!" + e.ToString(); | 
|                 objJsonResult.data = null; | 
|                 return objJsonResult; | 
|             } | 
|         } | 
|         #endregion | 
|     } | 
| } |