From b7ede349929b44bd664d059728919f6c8eede66a Mon Sep 17 00:00:00 2001 From: ch <37327@LLOOCCY> Date: 星期四, 30 三月 2023 09:39:44 +0800 Subject: [PATCH] 1 --- WebAPI/Controllers/生产管理/生产任务单/Sc_ICMOBillController.cs | 1625 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 1,622 insertions(+), 3 deletions(-) diff --git "a/WebAPI/Controllers/\347\224\237\344\272\247\347\256\241\347\220\206/\347\224\237\344\272\247\344\273\273\345\212\241\345\215\225/Sc_ICMOBillController.cs" "b/WebAPI/Controllers/\347\224\237\344\272\247\347\256\241\347\220\206/\347\224\237\344\272\247\344\273\273\345\212\241\345\215\225/Sc_ICMOBillController.cs" index f578874..9a42063 100644 --- "a/WebAPI/Controllers/\347\224\237\344\272\247\347\256\241\347\220\206/\347\224\237\344\272\247\344\273\273\345\212\241\345\215\225/Sc_ICMOBillController.cs" +++ "b/WebAPI/Controllers/\347\224\237\344\272\247\347\256\241\347\220\206/\347\224\237\344\272\247\344\273\273\345\212\241\345\215\225/Sc_ICMOBillController.cs" @@ -1,4 +1,7 @@ -锘縰sing Newtonsoft.Json.Linq; +锘縰sing Model; +using Model.鐢熶骇绠$悊; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using Pub_Class; using System; using System.Collections; @@ -16,17 +19,816 @@ public class Sc_ICMOBillController : ApiController { public DBUtility.ClsPub.Enum_BillStatus BillStatus; - private json objJsonResult = new json(); + private json objJsonResult = new json(); SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); DataSet ds; + + //鑾峰彇绯荤粺鍙傛暟 + Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter(); + public DAL.ClsSc_ICMOBill BillOld = new DAL.ClsSc_ICMOBill(); + + #region 鐢熶骇浠诲姟鍗� 淇濆瓨/缂栬緫鍔熻兘 + [Route("Sc_ICMOBill/ICMOBillEdit")] + [HttpPost] + public object ICMOBillEdit([FromBody] JObject sMainSub) + { + try + { + var _value = sMainSub["sMainSub"].ToString(); + string msg1 = _value.ToString(); + oCN.BeginTran(); + //淇濆瓨涓昏〃 + objJsonResult = AddBillMain(msg1); + if (objJsonResult.code == "0") + { + oCN.RollBack(); + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = objJsonResult.Message; + objJsonResult.data = null; + return objJsonResult; + } + oCN.Commit(); + objJsonResult.code = "1"; + objJsonResult.count = 1; + objJsonResult.Message = "鍗曟嵁淇濆瓨鎴愬姛锛�"; + objJsonResult.data = null; + return objJsonResult; + + } + catch (Exception e) + { + oCN.RollBack(); + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "淇濆瓨澶辫触锛�" + e.ToString(); + objJsonResult.data = null; + return objJsonResult; + } + } + + public json AddBillMain(string msg1) + { + string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); + string msg2 = sArray[0].ToString(); //涓昏〃鏁版嵁 + string msg3 = sArray[1].ToString(); //瀛愯〃鏁版嵁 + int OperationType = int.Parse(sArray[2].ToString()); // 鏁版嵁绫诲瀷 1娣诲姞 3淇敼 + string user = sArray[3].ToString(); + + try + { + if (!DBUtility.ClsPub.Security_Log("Sc_ICMOBill_Edit", 1, false, user)) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "鏃犱繚瀛樻潈闄愶紒"; + objJsonResult.data = null; + return objJsonResult; + } + + msg2 = "[" + msg2.ToString() + "]"; + List<ClsSc_ICMOBillMain> mainList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsSc_ICMOBillMain>>(msg2); + + long HInterID = mainList[0].HInterID;//閫掑叆type寰楀埌鐨勫崟鎹甀D + string HBillNo = mainList[0].HBillNo;//閫掑叆type寰楀埌鐨勫崟鎹彿 + long HPRDORGID = mainList[0].HPRDORGID;//缁勭粐 + DateTime HDate = mainList[0].HDate;//鏃ユ湡 + string HRemark = mainList[0].HRemark;//澶囨敞 + string HSeOrderBillNo = mainList[0].HSeOrderBillNo;//閿�鍞鍗曞彿 + long HSeOrderInterID = mainList[0].HSeOrderInterID;//閿�鍞涓籭d + long HSeOrderEntryID = mainList[0].HSeOrderEntryID;//閿�鍞瀛恑d + long HEmpID = mainList[0].HEmpID;//涓氬姟鍛� + long HCusID = mainList[0].HCusID;//瀹㈡埛 + long HCenterID = mainList[0].HCenterID;//宸ヤ綔涓績 + double? HPlanQty = mainList[0].HPlanQty == null ? 0 : mainList[0].HPlanQty;//璁″垝鏁伴噺 + string HMaker = user;//鍒跺崟浜� + + long HISENTRUST = mainList[0].HISENTRUST == null ? 0 : mainList[0].HISENTRUST;//缁勭粐鍙楁墭鍔犲伐 + long HISREWORK = mainList[0].HISREWORK == null ? 0 : mainList[0].HISREWORK;//鏄惁杩斿伐 + + ds = oCN.RunProcReturn("select * from h_v_IF_ICMOBillList where hmainid=" + HInterID + " and 鍗曟嵁鍙�='" + HBillNo + "'", "h_v_IF_ICMOBillList"); + + if ((OperationType == 1 || OperationType == 2) && ds.Tables[0].Rows.Count == 0)//鏂板 + { + //涓昏〃 + oCN.RunProc(@"Insert Into Sc_ICMOBillMain + (HBillType,HBillStatus,HInterID,HBillNo,HDate,HPRDORGID + ,HYear,HPeriod,HRemark,HMaker,HMakeDate + ,HSeOrderBillNo,HSeOrderInterID,HSeOrderEntryID,HEmpID,HCusID + ,HCenterID,HPlanQty,HDeptID,HMaterID,HUnitID,HBomID,HPlanBeginDate,HPlanEndDate,HISENTRUST,HISREWORK) + values('3710',1," + HInterID + ",'" + HBillNo + "','" + HDate + "'," + HPRDORGID + + "," + DateTime.Now.Year + "," + DateTime.Now.Month + ",'" + HRemark + "','" + HMaker + "',getdate()" + + ",'" + HSeOrderBillNo + "'," + HSeOrderInterID + "," + HSeOrderEntryID + "," + HEmpID + "," + HCusID + + "," + HCenterID + "," + HPlanQty + ",0,0,0,0,'',''" + "," + HISENTRUST + "," + HISREWORK + ") "); + } + else if (OperationType == 3 || ds.Tables[0].Rows.Count != 0) + { + if (ds.Tables[0].Rows[0]["瀹℃牳浜�"].ToString() != "") + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "鍗曟嵁宸插鏍�,涓嶅厑璁镐慨鏀�!"; + objJsonResult.data = null; + return objJsonResult; + } + + //淇敼 + oCN.RunProc("update Sc_ICMOBillMain set " + + "HRemark='" + HRemark + "', HChecker='" + HMaker + "', HCheckDate=getdate()" + + ", HSeOrderBillNo='" + HSeOrderBillNo + "', HSeOrderInterID=" + HSeOrderInterID + ", HSeOrderEntryID=" + HSeOrderEntryID + ", HEmpID=" + HEmpID + ", HCusID=" + HCusID + "" + + ", HCenterID=" + HCenterID + ", HPlanQty=" + HPlanQty + " where HInterID=" + HInterID); + + //鍒犻櫎瀛愯〃 + oCN.RunProc("delete from Sc_ICMOBillSub where HInterID='" + HInterID + "'"); + } + //淇濆瓨瀛愯〃 + objJsonResult = AddBillSub(msg3, HInterID, OperationType); + + if (objJsonResult.code == "0") + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = objJsonResult.Message; + objJsonResult.data = null; + return objJsonResult; + } + + //淇敼瀛楁 HSTOCKINORGID + oCN.RunProc("update Sc_ICMOBillSub set HSTOCKINORGID=" + HPRDORGID + " where HInterID=" + HInterID); + + objJsonResult.code = "1"; + objJsonResult.count = 1; + objJsonResult.Message = null; + objJsonResult.data = null; + return objJsonResult; + } + catch (Exception e) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "Exception锛�" + e.ToString(); + objJsonResult.data = null; + return objJsonResult; + } + } + + public json AddBillSub(string msg3, long HInterID, int OperationType) + { + List<ClsSc_ICMOBillSub> DetailColl = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsSc_ICMOBillSub>>(msg3); + + string HINSTOCKTYPE = DetailColl[0].HINSTOCKTYPE == null ? "''" : DetailColl[0].HINSTOCKTYPE; //鍏ュ簱绫诲瀷, + long HCHECKPRODUCT = DetailColl[0].HCHECKPRODUCT == null ? 0 : DetailColl[0].HCHECKPRODUCT; //浜у搧妫�楠�, + string HQAIP = DetailColl[0].HQAIP == null ? "''" : DetailColl[0].HQAIP; //绱ф�ユ斁琛�, + long HISBACKFLUSH = DetailColl[0].HISBACKFLUSH == null ? 0 : DetailColl[0].HISBACKFLUSH; //鍊掑啿棰嗘枡, + string HREQSRC = DetailColl[0].HREQSRC == null ? "''" : DetailColl[0].HREQSRC; //闇�姹傛潵婧�, + double HSTOCKINQUASELAUXQTY = DetailColl[0].HSTOCKINQUASELAUXQTY == null ? 0 : DetailColl[0].HSTOCKINQUASELAUXQTY; //鍚堟牸鍝佸叆搴撻�夊崟鏁伴噺, + long HSeOrderEntrySEQ = DetailColl[0].HSeOrderEntrySEQ == null ? 0 : DetailColl[0].HSeOrderEntrySEQ; //閿�鍞鍗曡鍙�, + string HPROJECTNO = DetailColl[0].HPROJECTNO == null ? "''" : DetailColl[0].HPROJECTNO; //椤圭洰缂栧彿, + long HPRODUCTTYPE = DetailColl[0].HPRODUCTTYPE == null ? 0 : DetailColl[0].HPRODUCTTYPE; //浜у搧绫诲瀷, + double HCOSTRATE = DetailColl[0].HCOSTRATE == null ? 0 : DetailColl[0].HCOSTRATE; // 鏉冮噸, + long HBASEUNITID = DetailColl[0].HBASEUNITID == null ? 0 : DetailColl[0].HBASEUNITID; //鍩烘湰璁¢噺鍗曚綅, + + int i = 0; + foreach (ClsSc_ICMOBillSub oSub in DetailColl) + { + i++; + if (oSub.HQty <= 0 || oSub.HQty == null) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "绗�" + i + "琛岋紝鏁伴噺涓嶈兘涓�0鎴栬�呭皬浜�0"; + objJsonResult.data = null; + return objJsonResult; + } + + if (oSub.HMaterID == 0) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "绗�" + i + "琛岋紝鐗╂枡涓嶈兘涓虹┖"; + objJsonResult.data = null; + return objJsonResult; + } + + //if (oSub.HSourceID == 0) + //{ + // objJsonResult.code = "0"; + // objJsonResult.count = 0; + // objJsonResult.Message = "绗�" + i + "琛岋紝鐢熶骇璧勬簮涓嶈兘涓虹┖"; + // objJsonResult.data = null; + // return objJsonResult; + //} + + if (oSub.HDeptID == 0) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "绗�" + i + "琛�,鐢熶骇杞﹂棿涓嶈兘涓虹┖"; + objJsonResult.data = null; + return objJsonResult; + } + + if (oSub.HUnitID == 0) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "绗�" + i + "琛岋紝璁¢噺鍗曚綅涓嶈兘涓虹┖"; + objJsonResult.data = null; + return objJsonResult; + } + + oCN.RunProc($@"Insert into Sc_ICMOBillSub + (HInterID,HENTRYID,HQty + ,HPlanBeginDate,HPlanEndDate + ,HBeginDate,HEndDate + ,HMaterID,HUnitID,HRemark,HSourceID,HDeptID,HSTATUS + ,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney + ,HINSTOCKTYPE,HCHECKPRODUCT,HQAIP,HISBACKFLUSH,HREQSRC,HSTOCKINQUASELAUXQTY,HSeOrderEntrySEQ,HPROJECTNO,HPRODUCTTYPE,HCOSTRATE,HBASEUNITID + ,HSTOCKINORGID) + values({HInterID},{i},{(oSub.HQty == null ? 0 : oSub.HQty)} + ,'{(oSub.HPlanBeginDate == null ? DateTime.Now.ToString("yyyy-MM-dd") : oSub.HPlanBeginDate.ToString())}','{(oSub.HPlanEndDate == null ? DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") : oSub.HPlanEndDate.ToString())}' + ,'{(oSub.HPlanBeginDate == null ? DateTime.Now.ToString("yyyy-MM-dd") : oSub.HPlanBeginDate.ToString())}','{(oSub.HPlanEndDate == null ? DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") : oSub.HPlanEndDate.ToString())}' + ,{oSub.HMaterID},{oSub.HUnitID},'{oSub.HRemark}',{oSub.HSourceID},{oSub.HDeptID},{oSub.HSTATUS} + ,0,0,'','',0,0,{HINSTOCKTYPE},{HCHECKPRODUCT},{HQAIP},{HISBACKFLUSH},{HREQSRC},{HSTOCKINQUASELAUXQTY},{HSeOrderEntrySEQ},{HPROJECTNO},{HPRODUCTTYPE},{HCOSTRATE},{HBASEUNITID},{oSub.HSTOCKINORGID})"); + } + + objJsonResult.code = "1"; + objJsonResult.count = 1; + objJsonResult.Message = null; + objJsonResult.data = null; + return objJsonResult; + } + #endregion + + [Route("Sc_ICMOBill/ICMOBillSaveApi")] + [HttpPost] + public object ICMOBillSaveApi([FromBody] JObject sMainSub) + { + try + { + //LogService.Write(sMainSub.ToString()); + var model = sMainSub["model"].ToString(); + var entry = sMainSub["model"]["HENTRY"].ToString(); + var _model = sMainSub["model"]["HPPBOMMAINENTRY"].ToString(); + var _entry = sMainSub["model"]["HPPBOMSUBENTRY"].ToString(); + model = "[" + model.ToString() + "]"; + List<ClsSc_ICMOBillMain> mainList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsSc_ICMOBillMain>>(model); + List<ClsSc_ICMOBillSub> subList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsSc_ICMOBillSub>>(entry); + List<ClsSc_PPBomBillMain> _mainList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsSc_PPBomBillMain>>(_model); + List<ClsSc_PPBomBillSub> _subList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsSc_PPBomBillSub>>(_entry); + string sql = string.Empty; + oCN.BeginTran(); + sql = $"delete Sc_ICMOBillMain where HinterID = {mainList[0].HInterID}"; + oCN.RunProc(sql); + sql = $"delete Sc_ICMOBillSub where HinterID = {mainList[0].HInterID}"; + oCN.RunProc(sql); + //涓昏〃 + oCN.RunProc(@"Insert Into Sc_ICMOBillMain + (HBillType,HInterID,HBillNo,HDate,HPRDORGID + ,HYear,HPeriod,HRemark,HMaker,HMakeDate + ,HSeOrderBillNo,HSeOrderInterID,HSeOrderEntryID,HEmpID,HCusID + ,HCenterID,HPlanQty,HDeptID,HMaterID,HUnitID,HBomID,HPlanBeginDate,HPlanEndDate,HBillStatus) + values('3710'," + mainList[0].HInterID + ",'" + mainList[0].HBillNo + "','" + mainList[0].HDate + "'," + mainList[0].HPRDORGID + + "," + DateTime.Now.Year + "," + DateTime.Now.Month + ",'" + mainList[0].HRemark + "','" + mainList[0].HMaker + "',getdate()" + + ",'" + mainList[0].HSeOrderBillNo + "'," + mainList[0].HSeOrderInterID + "," + mainList[0].HSeOrderEntryID + "," + mainList[0].HEmpID + "," + mainList[0].HCusID + + "," + mainList[0].HCenterID + "," + mainList[0].HPlanQty + ",0,0,0,0,'','',2) "); + //淇濆瓨涓昏〃 + foreach (var oSub in subList) + { + oCN.RunProc($@"Insert into Sc_ICMOBillSub + (HInterID,HENTRYID,HQty + ,HPlanBeginDate,HPlanEndDate + ,HBeginDate,HEndDate + ,HMaterID,HUnitID,HRemark,HSourceID,HDeptID,HSTATUS + ,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney + ,HCOSTRATE,HISBACKFLUSH,HBatchNo,HBomID,HCHECKPRODUCT,HSEQ) + values({oSub.HInterID},{oSub.HEntryID},{(oSub.HQty == null ? 0 : oSub.HQty)} + ,'{(oSub.HPlanBeginDate == null ? DateTime.Now.ToString("yyyy-MM-dd") : oSub.HPlanBeginDate.ToString())}','{(oSub.HPlanEndDate == null ? DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") : oSub.HPlanEndDate.ToString())}' + ,'{(oSub.HPlanBeginDate == null ? DateTime.Now.ToString("yyyy-MM-dd") : oSub.HPlanBeginDate.ToString())}','{(oSub.HPlanEndDate == null ? DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") : oSub.HPlanEndDate.ToString())}' + ,{oSub.HMaterID},{oSub.HUnitID},'{oSub.HRemark}',{oSub.HSourceID},{oSub.HDeptID},4 + ,0,0,'','',0,0 + ,{oSub.HCOSTRATE},{oSub.HISBACKFLUSH},'{oSub.HBatchNo}',{oSub.HBomID},{oSub.HCHECKPRODUCT},{oSub.HSEQ})"); + } + + foreach (var _item in _mainList) + { + //鐢熶骇鐢ㄦ枡娓呭崟 + sql = $"delete Sc_PPBomBillMain where HinterID = {_item.HInterID}"; + oCN.RunProc(sql); + sql = $"delete Sc_PPBomBillSub where HinterID = {_item.HInterID}"; + oCN.RunProc(sql); + //涓昏〃 + oCN.RunProc(@"Insert Into Sc_PPBomBillMain + (HInterID,HYear,HPeriod,HBillType,HBillSubType,HDate,HBillNo,HBillStatus,HICMOInterID + ,HICMOEntryID,HMaterID,HUnitID,HQty,HDeptID,HMaker,HMakeDate,HChecker,HCheckDate + ,HSeOrderBillNo,HSeOrderInterID,HSeOrderEntryID,HPRDORGID,HENTRUSTORGID,HPARENTOWNERID + ,HPARENTOWNERTYPEID,HERPInterID,HERPBillType,HSeOrderEntrySEQ,HICMOEntrySEQ,HREQSRC) + values(" + _item.HInterID + "," + DateTime.Now.Year + "," + DateTime.Now.Month + ",'" + 3720 + "','" + + _item.HBillSubType + "','" + _item.HDate + "','" + _item.HBillNo + "','" + _item.HBillStatus + "'," + _item.HICMOInterID + + "," + _item.HICMOEntryID + ",'" + _item.HMaterID + "'," + _item.HUnitID + "," + _item.HQty + "," + _item.HDeptID + + ",'" + _item.HMaker + "','" + _item.HMakeDate + "','" + _item.HChecker + "','" + _item.HCheckDate + "','" + _item.HSeOrderBillNo + "'," + _item.HSeOrderInterID + "," + _item.HSeOrderEntryID + "," + _item.HPRDORGID + "," + _item.HENTRUSTORGID + "," + _item.HPARENTOWNERID + ",'" + + _item.HPARENTOWNERTYPEID + "'," + _item.HERPInterID + ",'" + _item.HERPBillType + "'," + _item.HSeOrderEntrySEQ + "," + _item.HICMOEntrySEQ + ",'" + _item.HREQSRC + "')"); + } + foreach (var oSub in _subList) + { + oCN.RunProc($@"Insert into Sc_PPBomBillSub + (HInterID,HEntryID,HMaterID,HMaterNumber,HUnitID,HUnitNumber,HSPID,HQty,HQtyMust,HWHID,HRemark + ,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HICMOInterID,HICMOEntryID,HICMOBillNo + ,HCHILDSUPPLYORGID,HSUPPLYORGID,HENTRUSTPICKORGID,HSRCTRANSORGID,HGROUPBYOWNERID,HOWNERID,HOWNERTYPEID + ,HRelationQty,HMoveStockQty,HAuxPropID,HBatchNO,HMTONo,HQtyScrap,HERPInterID,HERPEntryID + ,HBackRelationQty,HNumerator,HDenominator,HBASEUNITID,HProcessID,HICMOENTRYSEQ,HPROJECTNO + ,HOPERID,HSEQ,HSTOCKSTATUSID,HLOT,HOPTQUEUE,HRESERVETYPE,HSelPickedQty,HSELPRCDRETURNQTY,HProcName) + values('{oSub.HInterID}','{oSub.HEntryID}','{oSub.HMaterID}','{oSub.HMaterNumber}','{oSub.HUnitID}','{oSub.HUnitNumber}','{oSub.HSPID}','{oSub.HQty}' + ,'{oSub.HQtyMust}','{oSub.HWHID}','{oSub.HRemark}','{oSub.HSourceInterID}','{oSub.HSourceEntryID}','{oSub.HSourceBillNo}','{oSub.HSourceBillType}','{oSub.HICMOInterID}','{oSub.HICMOEntryID}','{oSub.HICMOBillNo}','{oSub.HCHILDSUPPLYORGID}','{oSub.HSUPPLYORGID}','{oSub.HENTRUSTPICKORGID}','{oSub.HSRCTRANSORGID}','{oSub.HGROUPBYOWNERID}','{oSub.HOWNERID}','{oSub.HOWNERTYPEID}','{oSub.HRelationQty}','{oSub.HMoveStockQty}','{oSub.HAuxPropID}','{oSub.HBatchNO}','{oSub.HMTONo}','{Convert.ToDecimal(oSub.HQtyScrap)}','{oSub.HERPInterID}','{oSub.HERPEntryID}','{oSub.HBackRelationQty}','{oSub.HNumerator}','{oSub.HDenominator}','{oSub.HBASEUNITID}','{oSub.HProcessID}','{oSub.HICMOENTRYSEQ}','{oSub.HPROJECTNO}','{oSub.HOPERID}','{oSub.HSEQ}','{oSub.HSTOCKSTATUSID}','{oSub.HLOT}','{oSub.HOPTQUEUE}','{oSub.HRESERVETYPE}','{oSub.HSelPickedQty}','{oSub.HSELPRCDRETURNQTY}','{oSub.HProcName}')"); + } + oCN.Commit(); + objJsonResult.code = "1"; + objJsonResult.count = 1; + objJsonResult.Message = "鍗曟嵁淇濆瓨鎴愬姛锛�"; + objJsonResult.data = null; + return objJsonResult; + + } + catch (Exception e) + { + LogService.Write(e.Message.ToString()); + oCN.RollBack(); + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "淇濆瓨澶辫触锛�" + e.ToString(); + objJsonResult.data = null; + return objJsonResult; + } + + } + + + #region 鐢熶骇浠诲姟鍗�(鏃犲垪琛�) 淇濆瓨/缂栬緫鍔熻兘 + [Route("Sc_ICMOBill/ICMOBillEdit_NoTable")] + [HttpPost] + public object ICMOBillEdit_NoTable([FromBody] JObject sMainSub) + { + try + { + var _value = sMainSub["sMainSub"].ToString(); + string msg1 = _value.ToString(); + oCN.BeginTran(); + //淇濆瓨涓昏〃 + objJsonResult = AddBillMain_NoTable(msg1); + if (objJsonResult.code == "0") + { + oCN.RollBack(); + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = objJsonResult.Message; + objJsonResult.data = null; + return objJsonResult; + } + oCN.Commit(); + objJsonResult.code = "1"; + objJsonResult.count = 1; + objJsonResult.Message = "鍗曟嵁淇濆瓨鎴愬姛锛�"; + objJsonResult.data = null; + return objJsonResult; + + } + catch (Exception e) + { + oCN.RollBack(); + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "淇濆瓨澶辫触锛�" + e.ToString(); + objJsonResult.data = null; + return objJsonResult; + } + } + + public json AddBillMain_NoTable(string msg1) + { + string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); + string msg2 = sArray[0].ToString(); //涓昏〃鏁版嵁 + int OperationType = int.Parse(sArray[1].ToString()); // 鏁版嵁绫诲瀷 1娣诲姞 3淇敼 + string user = sArray[2].ToString(); + int HEntryID = int.Parse(sArray[3].ToString()); + + try + { + if (!DBUtility.ClsPub.Security_Log("Sc_ICMOBill_Edit", 1, false, user)) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "鏃犱繚瀛樻潈闄愶紒"; + objJsonResult.data = null; + return objJsonResult; + } + + var msg3 = msg2.ToString(); + msg2 = "[" + msg2.ToString() + "]"; + List<ClsSc_ICMOBillMain> mainList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsSc_ICMOBillMain>>(msg2); + + long HInterID = mainList[0].HInterID;//閫掑叆type寰楀埌鐨勫崟鎹甀D + string HBillNo = mainList[0].HBillNo;//閫掑叆type寰楀埌鐨勫崟鎹彿 + long HPRDORGID = mainList[0].HPRDORGID;//缁勭粐 + DateTime HDate = mainList[0].HDate;//鏃ユ湡 + string HRemark = mainList[0].HRemark;//澶囨敞 + string HSeOrderBillNo = mainList[0].HSeOrderBillNo;//閿�鍞鍗曞彿 + long HSeOrderInterID = mainList[0].HSeOrderInterID;//閿�鍞涓籭d + long HSeOrderEntryID = mainList[0].HSeOrderEntryID;//閿�鍞瀛恑d + long HEmpID = mainList[0].HEmpID;//涓氬姟鍛� + long HCusID = mainList[0].HCusID;//瀹㈡埛 + long HCenterID = mainList[0].HCenterID;//宸ヤ綔涓績 + long HBomID = mainList[0].HBomID;//bom + //double? HPlanQty = mainList[0].HPlanQty == null ? 0 : mainList[0].HPlanQty;//璁″垝鏁伴噺 + string HMaker = user;//鍒跺崟浜� + + ds = oCN.RunProcReturn("select * from h_v_IF_ICMOBillList where hmainid=" + HInterID + " and 鍗曟嵁鍙�='" + HBillNo + "'", "h_v_IF_ICMOBillList"); + + if ((OperationType == 1 || OperationType == 2) && ds.Tables[0].Rows.Count == 0)//鏂板 + { + //涓昏〃 + oCN.RunProc(@"Insert Into Sc_ICMOBillMain + (HBillType,HBillStatus,HInterID,HBillNo,HDate,HPRDORGID + ,HYear,HPeriod,HRemark,HMaker,HMakeDate + ,HSeOrderBillNo,HSeOrderInterID,HSeOrderEntryID,HEmpID,HCusID + ,HCenterID,HPlanQty,HDeptID,HMaterID,HUnitID,HBomID,HPlanBeginDate,HPlanEndDate) + values('3710',1," + HInterID + ",'" + HBillNo + "','" + HDate + "'," + HPRDORGID + + "," + DateTime.Now.Year + "," + DateTime.Now.Month + ",'" + HRemark + "','" + HMaker + "',getdate()" + + ",'" + HSeOrderBillNo + "'," + HSeOrderInterID + "," + HSeOrderEntryID + "," + HEmpID + "," + HCusID + + "," + HCenterID + ",0,0,0,0," + HBomID + ",'','') "); + } + else if (OperationType == 3 || ds.Tables[0].Rows.Count != 0) + { + if (ds.Tables[0].Rows[0]["瀹℃牳浜�"].ToString() != "") + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "鍗曟嵁宸插鏍�,涓嶅厑璁镐慨鏀�!"; + objJsonResult.data = null; + return objJsonResult; + } + + //淇敼 + oCN.RunProc("update Sc_ICMOBillMain set " + + "HRemark='" + HRemark + "', HUpDater='" + HMaker + "', HUpDateDate=getdate()" + + ", HSeOrderBillNo='" + HSeOrderBillNo + "', HSeOrderInterID=" + HSeOrderInterID + ", HSeOrderEntryID=" + HSeOrderEntryID + ", HEmpID=" + HEmpID + ", HCusID=" + HCusID + "" + + ", HCenterID=" + HCenterID + ",HBomID=" + HBomID + " where HInterID=" + HInterID); + + //鍒犻櫎瀛愯〃 + oCN.RunProc("delete from Sc_ICMOBillSub where HInterID='" + HInterID + "' and HEntryID='" + HEntryID + "'"); + } + //淇濆瓨瀛愯〃 + objJsonResult = AddBillSub_NoTable(msg3, HInterID, OperationType, HEntryID); + + if (objJsonResult.code == "0") + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = objJsonResult.Message; + objJsonResult.data = null; + return objJsonResult; + } + + objJsonResult.code = "1"; + objJsonResult.count = 1; + objJsonResult.Message = null; + objJsonResult.data = null; + return objJsonResult; + } + catch (Exception e) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "Exception锛�" + e.ToString(); + objJsonResult.data = null; + return objJsonResult; + } + } + + public json AddBillSub_NoTable(string msg3, long HInterID, int OperationType,int HEntryID) + { + ClsSc_ICMOBillSub oSub = Newtonsoft.Json.JsonConvert.DeserializeObject<ClsSc_ICMOBillSub>(msg3); + if (oSub.HQty <= 0 || oSub.HQty == null) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "鏁伴噺涓嶈兘涓�0鎴栬�呭皬浜�0"; + objJsonResult.data = null; + return objJsonResult; + } + + if (oSub.HMaterID == 0) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "鐗╂枡涓嶈兘涓虹┖"; + objJsonResult.data = null; + return objJsonResult; + } + + if (oSub.HDeptID == 0) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "鐢熶骇杞﹂棿涓嶈兘涓虹┖"; + objJsonResult.data = null; + return objJsonResult; + } + + if (oSub.HUnitID == 0) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "璁¢噺鍗曚綅涓嶈兘涓虹┖"; + objJsonResult.data = null; + return objJsonResult; + } + + //if (oSub.HBomID == 0) + //{ + // objJsonResult.code = "0"; + // objJsonResult.count = 0; + // objJsonResult.Message = "BOM涓嶈兘涓虹┖"; + // objJsonResult.data = null; + // return objJsonResult; + //} + + oCN.RunProc($@"Insert into Sc_ICMOBillSub + (HInterID,HENTRYID,HQty + ,HPlanBeginDate,HPlanEndDate + ,HBeginDate,HEndDate + ,HMaterID,HUnitID,HRemark,HSourceID,HDeptID,HSTATUS + ,HBomID,HEntryCusID,HSTOCKINORGID + ,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney + ,HAuxQty,HAuxUnit,HWidth,HWeight) + values({HInterID},{HEntryID},{(oSub.HQty == null ? 0 : oSub.HQty)} + ,'{(oSub.HPlanBeginDate == null ? DateTime.Now.ToString("yyyy-MM-dd") : oSub.HPlanBeginDate.ToString())}','{(oSub.HPlanEndDate == null ? DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") : oSub.HPlanEndDate.ToString())}' + ,'{(oSub.HBeginDate == null ? DateTime.Now.ToString("yyyy-MM-dd") : oSub.HBeginDate.ToString())}','{(oSub.HEndDate == null ? DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") : oSub.HEndDate.ToString())}' + ,{oSub.HMaterID},{oSub.HUnitID},'{oSub.HRemark}',{oSub.HSourceID},{oSub.HDeptID},{oSub.HSTATUS} + ,{oSub.HBomID} ,{oSub.HCusID} ,{oSub.HSTOCKINORGID} + ,0,0,'','',0,0 + ,{oSub.HAuxQty},{oSub.HAuxUnit},{oSub.HWidth},{oSub.HWeight})"); + + + objJsonResult.code = "1"; + objJsonResult.count = 1; + objJsonResult.Message = null; + objJsonResult.data = null; + return objJsonResult; + } + #endregion + + #region 鐢熶骇浠诲姟鍗曞鏍�/鍙嶅鏍稿姛鑳� + [Route("Sc_ICMOBill/CheckSc_ICMOReportBill")] + [HttpGet] + public object CheckSc_ICMOReportBill(string HInterID,int Type, string user) + { + try + { + //鍒ゆ柇鏄惁鏈夊垹闄ゆ潈闄� + if (!DBUtility.ClsPub.Security_Log("Sc_ICMOBill_Check", 1, false, user)) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "鏃犳潈闄愬鏍�!"; + objJsonResult.data = null; + return objJsonResult; + } + + if (string.IsNullOrWhiteSpace(HInterID)) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "HInterID涓虹┖锛�"; + objJsonResult.data = null; + return objJsonResult; + } + + ClsPub.CurUserName = user; + oCN.BeginTran();//寮�濮嬩簨鍔� + + //Type 1 瀹℃牳 2 鍙嶅鏍� + if (Type == 1) + { + if (!BillOld.CheckBill(int.Parse(HInterID), ref ClsPub.sExeReturnInfo)) + { + objJsonResult.code = "0"; + objJsonResult.count = 1; + objJsonResult.Message = "瀹℃牳澶辫触!鍘熷洜:" + ClsPub.sExeReturnInfo; + objJsonResult.data = null; + return objJsonResult; + } + } + else + { + if (BillOld.AbandonCheck(int.Parse(HInterID), ref ClsPub.sExeReturnInfo)) + { + SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); + DataSet DSet = oCn.RunProcReturn("exec h_p_Sc_ICMOBill_AbandonCheckCtrl " + int.Parse(HInterID), "h_p_Sc_ICMOBill_AbandonCheckCtrl"); + //if (DBUtility.ClsPub.isInt(DSet.Tables[0].Rows[0]["Hback"]) != 0) + //{ + // objJsonResult.code = "0"; + // objJsonResult.count = 1; + // objJsonResult.Message = "璇ヤ换鍔″崟宸蹭笅鎺ㄦ祦杞崱锛屼笉鍏佽鍙嶅鏍�" + DBUtility.ClsPub.isStrNull(DSet.Tables[0].Rows[0]["HBackRemark"]); + // objJsonResult.data = null; + // return objJsonResult; + //} + } + else + { + objJsonResult.code = "0"; + objJsonResult.count = 1; + objJsonResult.Message = "瀹℃牳澶辫触!鍘熷洜:" + ClsPub.sExeReturnInfo; + objJsonResult.data = null; + return objJsonResult; + } + } + + oCN.Commit();//鎻愪氦浜嬪姟 + + objJsonResult.code = "0"; + objJsonResult.count = 1; + objJsonResult.Message = "鎵ц鎴愬姛锛�"; + objJsonResult.data = null; + return objJsonResult; ; + + } + catch (Exception e) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "鎵ц澶辫触锛�" + e.ToString(); + objJsonResult.data = null; + return objJsonResult; + } + } + #endregion + + #region 鐢熶骇浠诲姟鍗曞叧闂�/鍙嶅叧闂姛鑳� + [Route("Sc_ICMOBill/CloseSc_ICMOReportBill")] + [HttpGet] + public object CloseSc_ICMOReportBill(string HInterID, int Type, string user) + { + try + { + //鍒ゆ柇鏄惁鏈夊垹闄ゆ潈闄� + if (!DBUtility.ClsPub.Security_Log("Sc_ICMOBill_Close", 1, false, user)) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "鏃犳潈闄愬叧闂�!"; + objJsonResult.data = null; + return objJsonResult; + } + + if (string.IsNullOrWhiteSpace(HInterID)) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "HInterID涓虹┖锛�"; + objJsonResult.data = null; + return objJsonResult; + } + + ClsPub.CurUserName = user; + + oCN.BeginTran();//寮�濮嬩簨鍔� + + //Type 1 鍏抽棴 2 鍙嶅叧闂� + if (Type == 1) + { + if (!BillOld.CloseBill(int.Parse(HInterID), ref ClsPub.sExeReturnInfo)) + { + objJsonResult.code = "0"; + objJsonResult.count = 1; + objJsonResult.Message = "鍏抽棴澶辫触!鍘熷洜:" + ClsPub.sExeReturnInfo; + objJsonResult.data = null; + return objJsonResult; + } + } + else + { + if (!BillOld.CancelClose(int.Parse(HInterID), ref ClsPub.sExeReturnInfo)) + { + objJsonResult.code = "0"; + objJsonResult.count = 1; + objJsonResult.Message = "鍙嶅叧闂け璐�!鍘熷洜:" + ClsPub.sExeReturnInfo; + objJsonResult.data = null; + return objJsonResult; + } + } + + oCN.Commit();//鎻愪氦浜嬪姟 + + objJsonResult.code = "0"; + objJsonResult.count = 1; + objJsonResult.Message = "鎵ц鎴愬姛锛�"; + objJsonResult.data = null; + return objJsonResult; ; + + } + catch (Exception e) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "鎵ц澶辫触锛�" + e.ToString(); + objJsonResult.data = null; + return objJsonResult; + } + } + #endregion + + #region 鐢熶骇浠诲姟鍗曚綔搴�/鍙嶄綔搴熷姛鑳� + [Route("Sc_ICMOBill/CancellSc_ICMOReportBill")] + [HttpGet] + public object CancellSc_ICMOReportBill(string HInterID, int Type, string user) + { + try + { + //鍒ゆ柇鏄惁鏈夊垹闄ゆ潈闄� + if (!DBUtility.ClsPub.Security_Log("Sc_ICMOBill_Delete", 1, false, user)) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "鏃犳潈闄愪綔搴�!"; + objJsonResult.data = null; + return objJsonResult; + } + + if (string.IsNullOrWhiteSpace(HInterID)) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "HInterID涓虹┖锛�"; + objJsonResult.data = null; + return objJsonResult; + } + + ClsPub.CurUserName = user; + + oCN.BeginTran();//寮�濮嬩簨鍔� + + //Type 1 浣滃簾 2 鍙嶄綔搴� + if (Type == 1) + { + if (!BillOld.Cancelltion(int.Parse(HInterID), ref ClsPub.sExeReturnInfo)) + { + objJsonResult.code = "0"; + objJsonResult.count = 1; + objJsonResult.Message = "浣滃簾澶辫触!鍘熷洜:" + ClsPub.sExeReturnInfo; + objJsonResult.data = null; + return objJsonResult; + } + } + else + { + if (!BillOld.AbandonCancelltion(int.Parse(HInterID), ref ClsPub.sExeReturnInfo)) + { + objJsonResult.code = "0"; + objJsonResult.count = 1; + objJsonResult.Message = "鍙嶄綔搴熷け璐�!鍘熷洜:" + ClsPub.sExeReturnInfo; + objJsonResult.data = null; + return objJsonResult; + } + } + + oCN.Commit();//鎻愪氦浜嬪姟 + + objJsonResult.code = "0"; + objJsonResult.count = 1; + objJsonResult.Message = "鎵ц鎴愬姛锛�"; + objJsonResult.data = null; + return objJsonResult; ; + + } + catch (Exception e) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "鎵ц澶辫触锛�" + e.ToString(); + objJsonResult.data = null; + return objJsonResult; + } + } + #endregion + #region 鐢熶骇浠诲姟鍗曞垹闄ゅ姛鑳� [Route("Sc_ICMOBill/DeltetSc_ICMOReportBill")] [HttpGet] - public object DeltetSc_ICMOReportBill(string HInterID) + public object DeltetSc_ICMOReportBill(string HInterID, string user) { try { + //鍒ゆ柇鏄惁鏈夊垹闄ゆ潈闄� + if (!DBUtility.ClsPub.Security_Log("Sc_ICMOBill_Drop", 1, false, user)) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "鏃犳潈闄愬垹闄�!"; + objJsonResult.data = null; + return objJsonResult; + } + if (string.IsNullOrWhiteSpace(HInterID)) { objJsonResult.code = "0"; @@ -45,7 +847,18 @@ objJsonResult.data = null; return objJsonResult; ; } + + if (int.Parse(ds.Tables[0].Rows[0]["HBillStatus"].ToString()) > 1) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "鍗曟嵁涓嶆槸鏈鏍哥姸鎬�,涓嶅厑璁稿垹闄わ紒"; + objJsonResult.data = null; + return objJsonResult; ; + } + oCN.RunProc("delete from Sc_ICMOBillMain where HInterID=" + HInterID); + oCN.RunProc("delete from Sc_ICMOBillSub where HInterID=" + HInterID); oCN.Commit();//鎻愪氦浜嬪姟 objJsonResult.code = "0"; objJsonResult.count = 1; @@ -65,8 +878,814 @@ } #endregion + #region 鐢熶骇浠诲姟鍗曡幏鍙栬溅闂� + [Route("Sc_ICMOBill/GetHDeptList")] + [HttpGet] + public object GetHDeptList() + { + try + { + DataSet oDs = new DataSet(); + //========== + oDs = oCN.RunProcReturn("select HItemID,HName from Gy_Department", "Gy_Department"); + objJsonResult.code = "1"; + objJsonResult.count = 1; + objJsonResult.Message = "鑾峰彇鎴愬姛锛�"; + objJsonResult.data = oDs.Tables[0]; + return objJsonResult; ; + } + catch (Exception e) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "鍒犻櫎澶辫触锛�" + e.ToString(); + objJsonResult.data = null; + return objJsonResult; + } + } + #endregion + + #region 澧欏挃瑁呯鍗曞洖杞︿簨浠� + [Route("Sc_ICMOBill/QK_PackingBillByXSBill")] + [HttpGet] + public object QK_PackingBillByXSBill(string HBillNo) + { + try + { + //string sql = string.Format(@"select a.HInterID,a.HBillNo,b.HEntryID,b.HMaterID,m.HNumber HMaterNumber,m.HName HMaterName, b.HUnitID,u.HName HUnitName,b.HQty HPlanQty,b.HQty HSPlanQty, + // a.HCusID, c.HName HCusName,a.HEmpID,e.HName HEmpName,b.HDeptID,d.HName HDeptName,a.HPlanEndDate,0 HMinQty,0 HTotalQty,0 HSpsQty,a.HSeOrderBillNo,a.HRemark + // from Sc_ICMOBillMain a + // left join Sc_ICMOBillSub b on a.HInterID=b.HInterID + // left join Gy_Material m on b.HMaterID=m.HItemID + // left join Gy_Unit u on b.HUnitID=u.HItemID + // left join Gy_Customer c on a.HCusID=c.HItemID + // left join Gy_Employee e on a.HEmpID=e.HItemID + // left join Gy_Department d on a.HDeptID=d.HItemID + // where b.HInterID=(select HICMOInterID from Sc_PPBomBillMain where HBillNo='" + HBillNo + "')"); + string sql = string.Format(@"select a.HInterID,a.HBillNo,b.HMaterID,b.HEntryID, m.HNumber HMaterNumber, m.HName HMaterName, b.HUnitID,u.HName HUnitName,b.HQty HPlanQty,b.HQty HSPlanQty,a.HCusID, c.HName HCusName, + a.HEmpID,e.HName HEmpName,b.HDeptID,d.HName HDeptName,a.HPlanEndDate,0 HMinQty,0 HTotalQty,0 HSpsQty,a.HSeOrderBillNo,a.HRemark, + fo.FBILLNO FBillNo,fo.F_ZZZZ_TEXT7 FLXName,fo.FRECEIVEADDRESS FInAddress,fmn.FNAME FMaterName,fo1.F_ZZZZ_TEXT FBZFS,fu.FDATAVALUE FHX, + fu1.FDATAVALUE FQK,fo1.F_ZZZZ_WBBZ1 FWBBZ + from Sc_ICMOBillMain a + left join Sc_ICMOBillSub b on a.HInterID=b.HInterID + left join Gy_Material m on b.HMaterID=m.HItemID + left join Gy_Unit u on b.HUnitID=u.HItemID + left join Gy_Customer c on a.HCusID=c.HItemID + left join Gy_Employee e on a.HEmpID=e.HItemID + left join Gy_Department d on a.HDeptID=d.HItemID + left join AIS20200908101915zs..T_PRD_MOENTRY f1 on b.HERPEntryID=f1.FENTRYID + left join AIS20200908101915zs..T_SAL_ORDERENTRY fo1 on f1.FSaleOrderEntryId=fo1.FENTRYID + left join AIS20200908101915zs..T_SAL_ORDER fo on fo1.FID=fo.FID + left join AIS20200908101915zs..T_BD_MATERIAL fm1 on fo1.FSUBMATERIALNUMBER=fm1.FMATERIALID + left join AIS20200908101915zs..T_BD_MATERIAL_L fmn on fo1.FSUBMATERIALNUMBER=fmn.FMATERIALID + LEFT JOIN AIS20200908101915zs..T_BAS_ASSISTANTDATAENTRY_L fu1 on fo1.F_ZZZZ_ASSISTANT1=fu1.FENTRYID + LEFT JOIN AIS20200908101915zs..T_BAS_ASSISTANTDATAENTRY_L fu on fo1.F_ZZZZ_ASSISTANT2=fu.FENTRYID + where b.HInterID=(select HICMOInterID from Sc_PPBomBillMain where HBillNo='" + HBillNo + "')"); + + ds = oCN.RunProcReturn(sql, "Sc_ICMOBillMain"); + if (ds.Tables[0].Rows.Count != 0 || ds != null) + { + objJsonResult.code = "1"; + objJsonResult.count = 1; + objJsonResult.Message = "鑾峰彇鎴愬姛锛�"; + objJsonResult.data = ds.Tables[0]; + return objJsonResult; + } + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "鏆傛棤瀵瑰簲鐨勯攢鍞槑缁嗭紒"; + objJsonResult.data = ds.Tables[0]; + return objJsonResult; + } + catch (Exception e) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "鑾峰彇澶辫触锛�" + e.ToString(); + objJsonResult.data = null; + return objJsonResult; + } + } + #endregion + + #region 澧欏挃瑁呯鍗曟暣绠辩敓鎴� + [Route("Sc_ICMOBill/QK_PackingBillSavePack")] + [HttpPost] + public object QK_PackingBillSavePack([FromBody] JObject msg) + { + var _value = msg["msg"].ToString(); + string msg1 = _value.ToString(); + string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); + string msg2 = sArray[0].ToString();//琛ㄦ牸鏁版嵁 + string msg3 = sArray[1].ToString();//鐧诲綍浜� + string msg5 = sArray[2].ToString();//鐧诲綍缁勭粐 + string msg6 = sArray[3].ToString();//鏍囪 + string msg7 = sArray[4].ToString();//褰撳墠鐢ㄦ枡娓呭崟 + + ListModels oListModels = new ListModels(); + DataSet ds = new DataSet(); + ds = oCN.RunProcReturn("select * from Xt_ORGANIZATIONS where HItemID=" + msg5, "Xt_ORGANIZATIONS"); + string OrgNum = ds.Tables[0].Rows[0]["HNumber"].ToString();//缁勭粐浠g爜 + DataSet d = oCN.RunProcReturn("select HRemark from Sc_PPBomBillMain where HBillNo='" + msg7 + "'", "Sc_ICMOBillMain");//鏌ユ壘璇ョ敤鏂欐竻鍗曚笂娆$敓鎴愮殑绠卞彿(HRemark瀛樻斁绠卞彿) + DataSet Ds1 = new DataSet(); + try + { + //琛ㄤ綋鏁版嵁 + //鎸� },{鏉ユ媶鍒嗘暟缁� //鍘绘帀銆愬拰銆� + msg2 = msg2.Replace("\\", ""); + msg2 = msg2.Replace("\n", ""); //\n + //msg2 = msg2.Replace("'", "鈥�"); + List<Models.ClsQK_PackingBill> ls = new List<Models.ClsQK_PackingBill>(); + ls = oListModels.getObjectByJson_QK_PackingBill(msg2); + //鑾峰彇骞存湀鏃ュ苟鎷兼帴鎴愬瓧绗︿覆 + string year = DateTime.Now.Year.ToString(); + string month = DateTime.Now.Month.ToString(); + string day = DateTime.Now.Day.ToString(); + string nowDate = year + month + day; + //string materid = ""; + //long sum = 0; + //if (msg4 == "ZZ") + //{ + string FID = ""; + int LSH; + string LSH2; + string TM = ""; + int XH = Convert.ToInt32(d.Tables[0].Rows[0]["HRemark"].ToString() == "" ? 0 : Convert.ToInt32(d.Tables[0].Rows[0]["HRemark"].ToString())); + + foreach (Models.ClsQK_PackingBill oItemSub in ls) + { + //鏍规嵁鐢熸垚鏉℃暟鐢熸垚鐩稿簲鏁伴噺鏉$爜 + for (int i = 0; i < oItemSub.HTotalQty; i++) + { + long HInterID = DBUtility.ClsPub.CreateBillID_Prod("85", ref DBUtility.ClsPub.sExeReturnInfo); + string sTMNumber = OrgNum + oItemSub.HMaterNumber + nowDate; + Ds1 = oCN.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo"); //鑾峰彇鏈�澶ф祦姘村彿 + LSH = ClsPub.isInt(Ds1.Tables[0].Rows[0][0]);// + LSH = LSH + 1; + LSH2 = LSH.ToString(); + while (LSH2.Length < 6) + { + LSH2 = "0" + LSH2; + } + TM = sTMNumber + LSH2; + + if (msg6 == "ZZ") + { + XH = XH + 1; + } + else if (msg6 == "PZ" && ls.IndexOf(oItemSub) == 0) + { + XH = XH + 1; + } + + //鑾峰彇鍐呯爜 + oCN.RunProc("insert into Gy_BarCodeBill (HEntryID,HBarCode,HBarCodeType,HMaterID,HUnitID,HQty" + + ",HBatchNo,HSupID,HGroupID,HMaker,HMakeDate,HPrintQty,HinitQty" + + ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HEndQty " + + ",HBarcodeQtys,HBarcodeNo,HDeptID,HWhID,HSPID,HRemark " + + ",HCusID,HCusType,HEndDate,HWorkLineName,HBarCodeDate " + + ",HSTOCKORGID,HOWNERID,HSeOrderBillNo,HInterID " + + ",HGiveAwayFlag " + + ",HMaterName,HMaterModel,HPinfan,HAuxPropID,HMTONo,HInnerBillNo " + + ") values (" + i + + ",'" + TM + "','鍞竴鏉$爜'," + oItemSub.HMaterID.ToString() + "," + oItemSub.HUnitID.ToString() + "," + oItemSub.HMinQty.ToString() + + ",'',0,0,'" + msg3 + "',getdate(),0," + oItemSub.HMinQty.ToString() + + ", " + oItemSub.HInterID.ToString() + "," + oItemSub.HEntryID.ToString() + ",'" + oItemSub.HBillNo + "','3710',''" + + ",1,1," + oItemSub.HDeptID.ToString() + ",0,0,'" + XH + "'" + + ", " + oItemSub.HCusID.ToString() + ",'',getdate(),'',getdate()" + + ", " + msg5.ToString() + "," + OrgNum.ToString() + ",'" + oItemSub.HSeOrderBillNo.ToString() + "'," + HInterID.ToString() + + ",0" + + ",'" + oItemSub.HMaterName + "','','',0,'','')"); + + oCN.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'"); + + } + oCN.RunProc("update Sc_ICMOBillSub set HQty=" + oItemSub.HSpsQty + " where HEntryID=" + oItemSub.HEntryID); + oCN.RunProc("update Sc_PPBomBillMain set HRemark=" + XH + " where HBillNo='" + msg7 + "'"); + DataSet Dsn = oCN.RunProcReturn("select top " + oItemSub.HTotalQty + " HItemID from Gy_BarCodeBill order by HItemID desc", "Gy_BarCodeBill"); //鑾峰彇鏈�澶ф祦姘村彿 + for (int i = 0; i < oItemSub.HTotalQty; i++) + { + FID = FID + Dsn.Tables[0].Rows[i][0] + ","; + } + } + objJsonResult.code = FID; + objJsonResult.count = 1; + objJsonResult.Message = "鏁磋鐢熸垚鎴愬姛锛�"; + objJsonResult.data = 1; + return objJsonResult; + //} + //else + //{ + // var HInterID = DBUtility.ClsPub.CreateBillID("3783", ref DBUtility.ClsPub.sExeReturnInfo); + // var HBillNo = DBUtility.ClsPub.CreateBillCode("3783", ref DBUtility.ClsPub.sExeReturnInfo, true); + // oCN.BeginTran(); + // foreach (Models.ClsQK_PackingBill oItemSub in ls) + // { + // sum += oItemSub.HMinQty; + // materid = oItemSub.HMaterNumber; + // //鑾峰彇鍐呯爜 + // long HInterID2 = DBUtility.ClsPub.CreateBillID_Prod("85", ref DBUtility.ClsPub.sExeReturnInfo); + // //鐢熸垚鍞竴鏉$爜 鏉$爜鍓嶇紑 = 缁勭粐浠g爜 + 鐗╂枡浠g爜 + 骞� + 鏈� + 鏃� + // string sTMNumber = OrgNum + oItemSub.HMaterNumber + nowDate; + // Ds1 = oCN.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo"); //鑾峰彇鏈�澶ф祦姘村彿 + // LSH = ClsPub.isInt(Ds1.Tables[0].Rows[0][0]);//鍞竴鐮� + // //鎻掑叆鏉$爜妗f + // oCN.RunProc("insert into Gy_BarCodeBill (HBarCode,HBarCodeType,HMaterID,HUnitID,HQty" + + // ",HBatchNo,HSupID,HGroupID,HMaker,HMakeDate,HPrintQty,HinitQty" + + // ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HEndQty " + + // ",HBarcodeQtys,HBarcodeNo,HDeptID,HWhID,HSPID,HRemark " + + // ",HCusID,HCusType,HEndDate,HWorkLineName,HBarCodeDate " + + // ",HSTOCKORGID,HOWNERID,HSeOrderBillNo,HInterID " + + // ",HGiveAwayFlag " + + // ",HMaterName,HMaterModel,HPinfan,HAuxPropID,HMTONo,HInnerBillNo " + + // ") values (" + // + "'" + LSH + "','鍞竴鏉$爜'," + oItemSub.HMaterID.ToString() + "," + oItemSub.HUnitID.ToString() + "," + oItemSub.HMinQty.ToString() + // + ",'',0,0,'" + msg3 + "',getdate(),0," + oItemSub.HMinQty.ToString() + // + ", " + oItemSub.HInterID.ToString() + "," + oItemSub.HInterID.ToString() + ",'" + oItemSub.HBillNo + "','3710',''" + // + ",1,1," + oItemSub.HDeptID.ToString() + ",0,0,''" + // + ", " + oItemSub.HCusID.ToString() + ",'',getdate(),'',getdate()" + // + ", " + msg5.ToString() + "," + OrgNum.ToString() + ",''," + HInterID2.ToString() + // + ",0" + // + ",'" + oItemSub.HMaterName + "','','',0,'','')"); + // //鎻掑叆缁勬墭鍗曞瓙琛� + // string sql = string.Format(@"insert into Sc_PackUnionBillSub(HInterID,HEntryID,HCloseMan,HCloseType,HRemark, + // HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType, + // HRelationQty,HRelationMoney,HMaterID,HUnitID,HQty,HSourceID,HEquipID,HGroupID,HWorkerID, + // HScanDate,HBarCode,HBarCode_Pack) + // values(" + HInterID + ",'','',0,'鑷姩缁戝畾'," + oItemSub.HInterID + ",'','" + oItemSub.HBillNo + "','3710'," + + // "0,0," + oItemSub.HMaterID + "," + oItemSub.HUnitID + "," + oItemSub.HPlanQty + ", 0,0,0,0," + + // "getdate(),'" + LSH + "','" + HBillNo + "')"); + // //鏇存敼鐢熶骇璁㈠崟鐨勬暟閲� + // string sql1 = string.Format(@"update Sc_ICMOBillSub set HQty=" + oItemSub.HSpsQty + " where HInterID=" + oItemSub.HInterID); + + // oCN.RunProc(sql); + // oCN.RunProc(sql1); + // } + // //鐢熸垚缁勬墭鍗曚富琛� + // string sql2 = string.Format(@"Insert Sc_PackUnionBillMain(HYear,HPeriod,HBillType,HInterID,HDate,HBillNo,HBillStatus,HCheckItemNowID,HCheckItemNextID, + // HRemark,HBacker,HChecker,HMaker,HMakeDate,HUpDater,HCloseMan,HCloseType,HDeleteMan,HICMOInterID,HICMOBillNo, + // HBarCode_Pack,HMaterID,HUnitID,HWeight,HMWeight,HPWeight, + // HProdOrgID,HDeptID,HEmpID,HSNum,HPackNum,HBarCode_Cus,HBatchNo,HBillSubType) + // values('2022',1,'3783'," + HInterID + ",getdate(),'" + HBillNo + "',1,0,0," + + // "'鑷姩缁戝畾','','', '" + msg3 + "',getdate(),'','',0,'',0,0,'" + + // HBillNo + "',0,0,0,0,0," + + // "0,0,0,0,0,'','','')"); + // oCN.RunProc(sql2); + // //鍐嶆鐢熸垚鍞竴鐮� + // //鑾峰彇鍐呯爜 + // long HInterID3 = DBUtility.ClsPub.CreateBillID_Prod("85", ref DBUtility.ClsPub.sExeReturnInfo); + // //鐢熸垚鍞竴鏉$爜 鏉$爜鍓嶇紑 = 缁勭粐浠g爜 + 鐗╂枡浠g爜 + 骞� + 鏈� + 鏃� + // string sTMNumber1 = OrgNum + materid + nowDate; + // Ds1 = oCN.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber1 + "'", "h_p_WMS_GetMaxNo"); //鑾峰彇鏈�澶ф祦姘村彿 + // int LSH1 = ClsPub.isInt(Ds1.Tables[0].Rows[0][0]);//鍞竴鐮� + // string sql3 = string.Format(@"insert into Gy_BarCodeBill (HBarCode,HBarCodeType,HMaterID,HUnitID,HQty" + + // ",HBatchNo,HSupID,HGroupID,HMaker,HMakeDate,HPrintQty,HinitQty" + + // ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HEndQty " + + // ",HBarcodeQtys,HBarcodeNo,HDeptID,HWhID,HSPID,HRemark " + + // ",HCusID,HCusType,HEndDate,HWorkLineName,HBarCodeDate " + + // ",HSTOCKORGID,HOWNERID,HSeOrderBillNo,HInterID " + + // ",HGiveAwayFlag " + + // ",HMaterName,HMaterModel,HPinfan,HAuxPropID,HMTONo,HInnerBillNo " + + // ") values (" + // + "'" + LSH1 + "','鍞竴鏉$爜','" + materid.ToString() + "',0," + sum.ToString() + // + ",'',0,0,'" + msg3 + "',getdate(),0," + sum.ToString() + // + ", 0,0,'" + HBillNo + "','3710',''," + // + sum.ToString() + "," + HInterID.ToString() + ",0,0,0,''" + // + ",0,'',getdate(),'',getdate()" + // + ", " + msg5.ToString() + "," + OrgNum.ToString() + ",''," + HInterID3.ToString() + // + ",0" + // + ",'','','',0,'','')"); + + // oCN.RunProc(sql3); + // oCN.Commit(); + // objJsonResult.code = "1"; + // objJsonResult.count = 1; + // objJsonResult.Message = "鎷艰鐢熸垚鎴愬姛"; + // objJsonResult.data = null; + // return objJsonResult; + //} + + } + catch (Exception e) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "鑾峰彇澶辫触锛�" + e.ToString(); + objJsonResult.data = null; + return objJsonResult; + } + } + #endregion + + # region[澧欏挃瑁呯鐐瑰嚮涓昏〃甯﹀嚭浠庤〃] + [Route("Sc_ICMOBillController/QK_GetPackingBillListByMainID")] + [HttpGet] + public object QK_GetPackingBillListByMainID(string HInterID) + { + + DataSet ds; + try + { + SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); + //鑾峰彇淇濆吇椤圭洰缂栬緫鏁版嵁 + string sql = string.Format(@"select a.HInterID hmainid,a.HBarCode,a.HBillType,a.HBarCodeType, + a.HMaterID,m.HName HMaterName,a.HUnitID,u.HName HUnitName, + a.HEmpID,e.HName HEmpName,a.HDeptID,d.HItemID HDeptName,P.HBarCode_Pack, + a.HMakeDate 鍒跺崟鏃ユ湡,a.HMaker 鍒跺崟浜� + from Gy_BarCodeBill a + left join Gy_Material m on a.HMaterID=m.HItemID + left join Gy_Unit u on a.HUnitID=u.HItemID + left join Gy_Employee e on a.HEmpID=e.HItemID + left join Gy_Department d on a.HDeptID=d.HItemID + left join Sc_PackUnionBillMain p on a.HSourceInterID=p.HInterID + where a.HBarCode in(select HBarCode from Sc_PackUnionBillSub where HInterID= + (select HBarcodeNo from Gy_BarCodeBill where HItemID='" + HInterID + "'))"); + ds = oCN.RunProcReturn(sql, "Sc_PackUnionBillSub"); + + objJsonResult.code = "0"; + objJsonResult.count = 1; + objJsonResult.Message = "鑾峰彇淇℃伅鎴愬姛锛�"; + objJsonResult.data = ds.Tables[0]; + } + catch (Exception e) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "娌℃湁杩斿洖浠讳綍璁板綍锛�" + e.ToString(); + objJsonResult.data = null; + } + return objJsonResult; + } + #endregion + + #region[澧欏挃瑁呯鍒楄〃] + /// <summary> + /// 澧欏挃瑁呯鍒楄〃 + /// </summary> + /// <returns></returns> + [Route("Sc_ICMOBillController/QK_GetPackingBillList")] + [HttpGet] + public object QK_GetPackingBillList(string sWhere) + { + try + { + + ds = QK_GetPackingBillList_s(sWhere); + + //if (ds.Tables[0].Rows.Count != 0 || ds != null) + //{ + objJsonResult.code = "1"; + objJsonResult.count = 1; + objJsonResult.Message = "Sucess锛�"; + objJsonResult.data = ds.Tables[0]; + return objJsonResult; + //} + //else + //{ + //objJsonResult.code = "0"; + //objJsonResult.count = 0; + //objJsonResult.Message = "鏃犳暟鎹�"; + //objJsonResult.data = null; + //return objJsonResult; + //} + } + catch (Exception ex) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "娌℃湁杩斿洖浠讳綍璁板綍锛�" + ex.ToString(); + objJsonResult.data = null; + return objJsonResult; + } + } + + #region sql璇彞 + + + public static DataSet QK_GetPackingBillList_s(string sWhere) + { + ; + if (sWhere == null || sWhere.Equals("")) + { + return new SQLHelper.ClsCN().RunProcReturn("select * from h_v_QK_PackedBillList order by 鍒跺崟鏃ユ湡 desc", "h_v_QK_PackedBillList"); + } + else + { + string sql1 = "select * from h_v_QK_PackedBillList where HBarCodeType='鍞竴鏉$爜' "; + string sql = sql1 + sWhere + " order by 鍒跺崟鏃ユ湡 desc"; + return new SQLHelper.ClsCN().RunProcReturn(sql, "h_v_QK_PackedBillList"); + + } + //return new SQLHelper.ClsCN().RunProcReturn("select * from h_v_Sc_MouldMaintainBillList ", "h_v_Sc_MouldMaintainBillList"); + } + #endregion + + #endregion + + #region[澧欏挃瑁呯鍒楄〃-鍒犻櫎] + /// <summary> + /// 澧欏挃瑁呯鍒楄〃-鍒犻櫎 + /// </summary> + /// <param name="HInterID">鏉$爜妗f涓昏〃涓籌D锛堝敮涓�锛�</param> + /// <param name="Flag">鏍囪瘑</param> + /// <returns></returns> + [Route("Sc_ICMOBillController/DeleteQK_GetPackingBillList")] + [HttpGet] + public object DeleteQK_GetPackingBillList(string HInterID, string Flag) + { + try + { + oCN.BeginTran(); + if (Flag == "0") + { + DataSet ds = new DataSet(); + ds = oCN.RunProcReturn("select * from Gy_BarCodeBill where HItemID=" + HInterID, "Gy_BarCodeBill"); + DataRow dr = ds.Tables[0].Rows[0]; + string sql = string.Format(@"delete from Gy_BarCodeBill where HItemID=" + HInterID); + string sql1 = string.Format(@"update Sc_ICMOBillSub set HQty=HQty+" + dr["HQty"] + " where HEntryID=(select HSourceEntryID from Gy_BarCodeBill where HItemID=" + HInterID + ")"); + oCN.RunProc(sql1); + oCN.RunProc(sql); + } + else + { + //閫氳繃鏉$爜id鎵惧埌鎵樻潯鐮侊紝閫氳繃鎵樻潯鐮佹壘鍒扮粍鎵樺崟瀛愯〃涓殑鍞竴鐮� + string sql2 = "select HBarCode from Sc_PackUnionBillSub where HInterID=(select HBarcodeNo from Gy_BarCodeBill where HItemID=" + HInterID + ")"; + //string sql2 = "select HBarCode from Sc_PackUnionBillSub where HInterID=(select HBarcodeNo from Gy_BarCodeBill where HItemID=3250)"; + DataSet ds1 = oCN.RunProcReturn(sql2, "Sc_PackUnionBillSub"); + DataTable dt = ds1.Tables[0]; + //閬嶅巻鎵惧埌鐨勫敮涓�鐮佸垹闄ゆ潯鐮佹。妗堥噷鐨勭浉鍏虫暟鎹紝鍚屾椂閫氳繃鍞竴鐮佺殑婧愬崟鎵惧埌鐢熶骇璁㈠崟鏇存敼鐢熶骇璁㈠崟鐨勬暟閲� + if (dt.Rows.Count > 0) + { + foreach (DataRow dr in dt.Rows) + { + DataSet ds = new DataSet(); + ds = oCN.RunProcReturn("select * from Gy_BarCodeBill where HBarCode='" + dr["HBarCode"].ToString() + "'", "Gy_BarCodeBill"); + DataRow dr1 = ds.Tables[0].Rows[0]; + + string sql = string.Format(@"delete from Gy_BarCodeBill where HBarCode='" + dr["HBarCode"].ToString() + "'"); + string sql1 = string.Format(@"update Sc_ICMOBillSub set HQty=HQty+" + dr1["HQty"] + " where HEntryID=(select HSourceEntryID from Gy_BarCodeBill where HBarCode='" + dr["HBarCode"].ToString() + "')"); + oCN.RunProc(sql1); + oCN.RunProc(sql); + } + } + + //閬嶅巻瀹屽悗鍒犻櫎閫氳繃鏉$爜id鎵惧埌鎵樻潯鐮侊紝閫氳繃鎵樻潯鐮佹壘鍒扮粍鎵樺崟瀛愯〃鐨勬暟鎹紝浠ュ強涓昏〃鏁版嵁 + string sql3 = string.Format(@"delect from Sc_PackUnionBillSub where HInterID=(select HBarcodeNo from Gy_BarCodeBill where HItemID=" + HInterID); + string sql4 = string.Format(@"delect from Sc_PackUnionBillMain where HInterID=(select HBarcodeNo from Gy_BarCodeBill where HItemID=" + HInterID); + //鍒犻櫎鏈�澶х殑鍚堟垚鐨勫敮涓�鐮� + string sql5 = string.Format(@"delete from Gy_BarCodeBill where HItemID=" + HInterID); + oCN.RunProc(sql3); + oCN.RunProc(sql4); + oCN.RunProc(sql5); + } + oCN.Commit(); + objJsonResult.code = "1"; + objJsonResult.count = 1; + objJsonResult.Message = "鍒犻櫎鎴愬姛"; + objJsonResult.data = null; + return objJsonResult; + + } + catch (Exception ex) + { + oCN.RollBack(); + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "鍒犻櫎澶辫触" + ex.ToString(); + objJsonResult.data = null; + return objJsonResult; + } + } + #endregion + + + #region [鍚屾鍗曟嵁] + [Route("Sc_ICMOBill/Sc_ICMOBillViewApi")] + [HttpGet] + public json Sc_ICMOBillViewApi(string BillNo, string BillType) + { + string sql = string.Empty; + string sReturn = ""; + if (oSystemParameter.ShowBill(ref sReturn) == true) + { + //绯荤粺鍙傛暟鏄惁涓虹鏈変簯妯″紡,N涓哄叕鏈変簯妯″紡锛孻涓虹鏈変簯妯″紡 + if (oSystemParameter.omodel.WMS_CloudMode == "Y") + { + #region [绉佹湁浜戞ā寮忥紝鐩存帴璋冪敤鏁版嵁搴撳瓨鍌ㄨ繃绋嬫洿鏂癩 + try + { + oCN.BeginTran(); + SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); + DataSet DS = oCn.RunProcReturn("exec h_p_WMS_ERPSourceBillToLocal '" + BillNo + "','" + BillType + "'", "h_p_WMS_ERPSourceBillToLocal"); + if (DS == null) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "鍗曟嵁鍚屾澶辫触"; + objJsonResult.data = null; + return objJsonResult; + } + else + { + if (DBUtility.ClsPub.isStrNull(DS.Tables[0].Rows[0]["HBack"]) == "2") + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "ERP涓笉瀛樺湪璇ュ崟鎹彿"; + objJsonResult.data = null; + return objJsonResult; + } + else + { + objJsonResult.code = "1"; + objJsonResult.count = 1; + objJsonResult.Message = "鍗曟嵁鍚屾鎴愬姛"; + 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 + } + else + { + #region [鍏湁浜戞ā寮忥紝璋冪敤WEBAPI鐨勬柟寮忚繘琛屾洿鏂癩 + var json = new + { + CreateOrgId = 0, + Number = BillNo, + Id = "" + }; + #region [閲戣澏閮ㄥ垎] + //鐧诲綍閲戣澏 + var loginRet = InvokeHelper.Login(); + var isSuccess = JObject.Parse(loginRet)["LoginResultType"].Value<int>(); + //鍒ゆ柇鏄惁鐧诲綍鎴愬姛 + if (isSuccess < 0) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = loginRet; + objJsonResult.data = null; + return objJsonResult; + } + //鏌ョ湅 鑾峰彇鏁版嵁 + var _result = InvokeHelper.View("PRD_MO", JsonConvert.SerializeObject(json)); + var _saveObj = JObject.Parse(_result); + //鍒ゆ柇鏁版嵁鏄惁鑾峰彇鎴愬姛 + if (_saveObj["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper() != "TRUE") + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "閲戣澏鐢熶骇浠诲姟鍗曞悓姝ュけ璐sonRoot锛�" + _result; + objJsonResult.data = null; + return objJsonResult; + } + + #endregion + //鑾峰彇涓昏〃鏁版嵁 + DataSet Ds; + Int64 InterID = 0; + Ds = oCN.RunProcReturn("select * from Sc_ICMOBillMain where HBillNo = '" + BillNo + "'", "Sc_ICMOBillMain"); + if (Ds.Tables[0].Rows.Count != 0 && ClsPub.isLong(Ds.Tables[0].Rows[0]["HInterID"].ToString()) != 0) + { + InterID = ClsPub.isLong(Ds.Tables[0].Rows[0]["HInterID"].ToString()); + } + + #region [涓昏〃鏁版嵁璧嬪�糫 + var jsonData = new + { + HInterID = _saveObj["Result"]["Result"]["Id"], + HYear = DateTime.Now.Year, + HPeriod = DateTime.Now.Month, + HBillType = 3710, + HDate = _saveObj["Result"]["Result"]["Date"], + HBillNo = _saveObj["Result"]["Result"]["BillNo"], + HBillStatus = _saveObj["Result"]["Result"]["ApproverId_Id"].ToString() == Convert.ToString(0) ? 1 : 2, + HEMPID = 0, + HRoutingInterID = 0, + HPlanQty = 1, + HRelationQty = 0, + HPlanBeginDate = _saveObj["Result"]["Result"]["Date"], + HPlanEndDate = DateTime.Now.ToString(), + HBeginDate = _saveObj["Result"]["Result"]["Date"], + HEndDate = DateTime.Now.ToString(), + HMaterID = 0, + HUnitID = 0, + HBomID = 0, + HBatchNo = "", + HSourceInterID = 0, + HSourceEntryID = 0, + HSourceBillNo = "", + HSourceBillType = "", + HSeOrderInterID = 0, + HSeOrderEntryID = 0, + HSeOrderBillNo = "", + HPRDORGID = _saveObj["Result"]["Result"]["PrdOrgId_Id"], + HENTRUSTORGID = _saveObj["Result"]["Result"]["ENTrustOrgId_Id"], + HOWNERID = _saveObj["Result"]["Result"]["OwnerId_Id"], + HOWNERTYPEID = _saveObj["Result"]["Result"]["OwnerTypeId"], + HCusID = 0, + HDeptID = _saveObj["Result"]["Result"]["WorkShopID_Id"].ToString() == null ? 0 : _saveObj["Result"]["Result"]["WorkShopID_Id"], + HRemark = "CLOUD瀵煎叆", + HMTONo = "", + HERPInterID = _saveObj["Result"]["Result"]["Id"], + HERPBillType = _saveObj["Result"]["Result"]["BillType_Id"], + HMaker = _saveObj["Result"]["Result"]["CreatorId"]["Name"], + HMakeDate = _saveObj["Result"]["Result"]["CreateDate"], + HChecker = _saveObj["Result"]["Result"]["ApproverId"]["Name"], + HCheckDate = _saveObj["Result"]["Result"]["ApproveDate"], + HBillSubType = _saveObj["Result"]["Result"]["IsRework"] = true ? 1 : 0, + HISENTRUST = _saveObj["Result"]["Result"]["IsEntrust"], + HISREWORK = _saveObj["Result"]["Result"]["IsRework"] + }; + #endregion + // 鍒犻櫎涓昏〃瀵瑰簲鏁版嵁 + sql = $"delete from Sc_ICMOBillMain where HInterID = " + InterID; + oCN.RunProc(sql); + + //鎻掑叆涓昏〃 + sql = $@" + insert into Sc_ICMOBillMain + (HInterID,HYear,HPeriod,HBillType,HDate + ,HBillNo,HBillStatus,HEMPID,HRoutingInterID + ,HPlanQty,HRelationQty,HPlanBeginDate,HPlanEndDate,HBeginDate,HEndDate + ,HMaterID,HUnitID,HBomID,HBatchNo + ,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HSeOrderInterID,HSeOrderEntryID,HSeOrderBillNo + ,HPRDORGID,HENTRUSTORGID,HOWNERID,HOWNERTYPEID + ,HCusID,HDeptID,HRemark,HMTONo,HERPInterID,HERPBillType + ,HMaker,HMakeDate,HChecker,HCheckDate + ,HBillSubType,HISENTRUST,HISREWORK + ) + values + ({jsonData.HInterID},{jsonData.HYear},{jsonData.HPeriod},{jsonData.HBillType},'{jsonData.HDate}','{jsonData.HBillNo}', + {jsonData.HBillStatus},{jsonData.HEMPID},{jsonData.HRoutingInterID},{jsonData.HPlanQty},{jsonData.HRelationQty}, + '{jsonData.HPlanBeginDate}', '{jsonData.HPlanEndDate}','{jsonData.HBeginDate}','{jsonData.HEndDate}',{jsonData.HMaterID}, + {jsonData.HUnitID},{jsonData.HBomID},'{jsonData.HBatchNo}',{jsonData.HSourceInterID},{jsonData.HSourceEntryID}, + '{jsonData.HSourceBillNo}','{jsonData.HSourceBillType}',{jsonData.HSeOrderInterID}, {jsonData.HSeOrderEntryID},'{jsonData.HSeOrderBillNo}', + {jsonData.HPRDORGID},{jsonData.HENTRUSTORGID},{jsonData.HOWNERID},'{jsonData.HOWNERTYPEID}',{jsonData.HCusID},{jsonData.HDeptID}, + '{jsonData.HRemark}','{jsonData.HMTONo}',{jsonData.HERPInterID},'{jsonData.HERPBillType}','{jsonData.HMaker}','{jsonData.HMakeDate}', + '{jsonData.HChecker}','{jsonData.HCheckDate}','{jsonData.HBillSubType}','{jsonData.HISENTRUST}','{jsonData.HISREWORK}')"; + + oCN.RunProc(sql); + + #region [鐢宠瀛愯〃鍙橀噺] + var dataArr = _saveObj["Result"]["Result"]["TreeEntity"]; + + DataSet Cs; + double RelationQty = 0; + #endregion + int i = 0; + + // 鑾峰彇瀛愯〃鏁版嵁 + Cs = oCN.RunProcReturn("select * from Sc_ICMOBillSub where HInterID = " + InterID, "Sc_ICMOBillSub"); + // 鍒犻櫎瀛愯〃瀵瑰簲鏁版嵁 + sql = $"delete from Sc_ICMOBillSub where HInterID = " + InterID; + oCN.RunProc(sql); + + foreach (var oSub in dataArr) + { + #region [瀛愯〃鏁版嵁璧嬪�糫 + + if (Cs.Tables[0].Rows.Count != 0 && ClsPub.isLong(Cs.Tables[0].Rows[0]["HInterID"].ToString()) != 0) + { + RelationQty = ClsPub.isDoule(Cs.Tables[0].Rows[i]["HRelationQty"].ToString()); + + i++; + } + + var subData = new + { + HInterID = _saveObj["Result"]["Result"]["Id"], + HENTRYID = oSub["Id"], + HSEQ = oSub["Seq"], + HQty = oSub["Qty"], + HQTYMUST = oSub["Qty"], + HRelationQty = RelationQty, + HRelationMoney = 0, + HPlanBeginDate = oSub["IdPlanStartDate"], + HPlanEndDate = oSub["PlanFinishDate"], + HBeginDate = oSub["StartDate"], + HEndDate = oSub["FinishDate"], + HBomID = oSub["BomId_Id"], + HRemark = "CLOUD瀵煎叆", + HMaterID = oSub["MaterialId_Id"], + HUnitID = oSub["UnitId_Id"], + HWHID = oSub["StockId_Id"], + HSPID = oSub["StockLocId_Id"], + HPROCID = oSub["ProcessId_Id"], + HDEPTID = oSub["WorkShopID_Id"], + HBatchNo = oSub["Lot_Text"], + HSourceInterID = oSub["SrcBillId"], + HSourceEntryID = oSub["SrcBillEntryId"], + HSourceBillNo = oSub["SrcBillNo"], + HSourceBillType = oSub["SrcBillType"], + HSeOrderInterID = oSub["SaleOrderId"], + HSeOrderEntryID = oSub["SaleOrderEntryId"], + HSeOrderBillNo = oSub["SaleOrderNo"], + HSTOCKINORGID = oSub["StockInOrgId_Id"], + HINSTOCKOWNERID = oSub["InStockOwnerId_Id"], + HINSTOCKOWNERTYPEID = oSub["InStockOwnerTypeId"], + HREQUESTORGID = oSub["RequestOrgId_Id"], + HPlanMode = 0, + HMTONo = oSub["MTONo"], + HERPInterID = _saveObj["Result"]["Result"]["Id"], + HERPEntryID = oSub["Id"], + HSTATUS = oSub["Status"], + HEntryCusID = 0, + HICMOReportRelationQty = oSub["RepQuaSelAuxQty"], + HAuxPropID = oSub["AuxPropId_Id"], + HProdMaterCode = "", + HCusShortName = "", + HCusNeedMaterial = "", + HPlanSendGoodsDate = "", + HProdMaterName = "", + HWorkRemark = "", + HImportNote = "", + HCusName = "", + HInstockQty_Max = 0, + HInstockQty_Min = 0, + HPickLabel = "", + HPickLabelNumber = oSub["StockInLimitH"], + HCusNumber = oSub["StockInLimitL"], + HINSTOCKTYPE = oSub["InStockType"], + HCHECKPRODUCT = oSub["CheckProduct"], + HQAIP = oSub["QAIP"], + HISBACKFLUSH = oSub["ISBACKFLUSH"], + HREQSRC = oSub["ReqSrc"], + HSTOCKINQUASELAUXQTY = oSub["StockInQuaSelAuxQty"], + HSeOrderEntrySEQ = oSub["SaleOrderEntrySeq"], + HPROJECTNO = oSub["ProjectNo"], + HPRODUCTTYPE = oSub["ProductType"], + HCOSTRATE = oSub["CostRate"], + HBASEUNITID = oSub["BaseUnitId_Id"], + }; + #endregion + + //鎻掑叆瀛愯〃 + sql = $@" + insert into Sc_ICMOBillSub + (HInterID,HENTRYID,HSEQ,HQty,HQTYMUST,HRelationQty,HRelationMoney + ,HPlanBeginDate,HPlanEndDate,HBeginDate,HEndDate,HBomID,HRemark + ,HMaterID,HUnitID,HWHID,HSPID,HPROCID,HDEPTID,HBatchNo + ,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType + ,HSeOrderInterID,HSeOrderEntryID,HSeOrderBillNo + ,HSTOCKINORGID,HINSTOCKOWNERID,HINSTOCKOWNERTYPEID,HREQUESTORGID + ,HPlanMode,HMTONo,HERPInterID,HERPEntryID,HSTATUS + ,HEntryCusID,HICMOReportRelationQty,HAuxPropID,HProdMaterCode,HCusShortName + ,HCusNeedMaterial,HPlanSendGoodsDate,HProdMaterName,HWorkRemark,HImportNote,HCusName + ,HInstockQty_Max,HInstockQty_Min,HPickLabel,HPickLabelNumber,HCusNumber + ,HINSTOCKTYPE,HCHECKPRODUCT,HQAIP,HISBACKFLUSH,HREQSRC,HSTOCKINQUASELAUXQTY + ,HSeOrderEntrySEQ,HPROJECTNO,HPRODUCTTYPE,HCOSTRATE,HBASEUNITID + ) + values + ({subData.HInterID},{subData.HENTRYID},{subData.HSEQ},{subData.HQty},{subData.HQTYMUST},{subData.HRelationQty}, + {subData.HRelationMoney},'{subData.HPlanBeginDate}','{subData.HPlanEndDate}','{subData.HBeginDate}','{subData.HEndDate}',{subData.HBomID}, + '{subData.HRemark}',{subData.HMaterID},{subData.HUnitID},{subData.HWHID},{subData.HSPID},{subData.HPROCID},{subData.HDEPTID}, + '{subData.HBatchNo}',{subData.HSourceInterID},{subData.HSourceEntryID},'{subData.HSourceBillNo}','{subData.HSourceBillType}', + {subData.HSeOrderInterID},{subData.HSeOrderEntryID},'{subData.HSeOrderBillNo}',{subData.HSTOCKINORGID},{subData.HINSTOCKOWNERID}, + '{subData.HINSTOCKOWNERTYPEID}',{subData.HREQUESTORGID},'{subData.HPlanMode}','{subData.HMTONo}',{subData.HERPInterID}, + {subData.HERPEntryID},{subData.HSTATUS},{subData.HEntryCusID},{subData.HICMOReportRelationQty},{subData.HAuxPropID}, + '{subData.HProdMaterCode}','{subData.HCusShortName}','{subData.HCusNeedMaterial}','{subData.HPlanSendGoodsDate}', + '{subData.HProdMaterName}','{subData.HWorkRemark}','{subData.HImportNote}','{subData.HCusName}',{subData.HInstockQty_Max}, + {subData.HInstockQty_Min},'{subData.HPickLabel}',{subData.HPickLabelNumber},{subData.HCusNumber},'{subData.HINSTOCKTYPE}', + '{subData.HCHECKPRODUCT}','{subData.HQAIP}','{subData.HISBACKFLUSH}','{subData.HREQSRC}',{subData.HSTOCKINQUASELAUXQTY}, + {subData.HSeOrderEntrySEQ},'{subData.HPROJECTNO}','{subData.HPRODUCTTYPE}',{subData.HCOSTRATE},{subData.HBASEUNITID})"; + + oCN.RunProc(sql); + } + + + objJsonResult.code = "1"; + objJsonResult.count = 1; + objJsonResult.Message = "鍗曟嵁鍚屾鎴愬姛锛�"; + objJsonResult.data = null; + return objJsonResult; + + #endregion + } + } + else + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "鍗曟嵁璇诲彇澶辫触锛�"; + objJsonResult.data = null; + return objJsonResult; + } + } + #endregion } } \ No newline at end of file -- Gitblit v1.9.1