From b7860ae337c66fe1c1a96db57aeadb20b39da344 Mon Sep 17 00:00:00 2001
From: yusijie <ysj@hz-kingdee.com>
Date: 星期四, 20 三月 2025 15:45:18 +0800
Subject: [PATCH] 添康排产子表耗用时间调整;器具领用出库单优化

---
 WebAPI/Controllers/SCGL/Sc_PPBomBillController.cs |  662 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 656 insertions(+), 6 deletions(-)

diff --git a/WebAPI/Controllers/SCGL/Sc_PPBomBillController.cs b/WebAPI/Controllers/SCGL/Sc_PPBomBillController.cs
index fc30b37..5f3ddc6 100644
--- a/WebAPI/Controllers/SCGL/Sc_PPBomBillController.cs
+++ b/WebAPI/Controllers/SCGL/Sc_PPBomBillController.cs
@@ -1,4 +1,5 @@
 锘縰sing Model.鐢熶骇绠$悊;
+using Newtonsoft.Json;
 using Newtonsoft.Json.Linq;
 using Pub_Class;
 using System;
@@ -14,6 +15,8 @@
     //鐢熶骇鐢ㄦ枡Controller
     public class Sc_PPBomBillController : ApiController
     {
+        //鑾峰彇绯荤粺鍙傛暟
+        Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
         public DBUtility.ClsPub.Enum_BillStatus BillStatus;
 
         private json objJsonResult = new json();
@@ -28,10 +31,11 @@
         /// </summary>
         [Route("Sc_PPBomBill/list")]
         [HttpGet]
-        public object list(string sWhere,string user)
+        public object list(string sWhere, string user)
         {
             try
             {
+                List<object> a = new List<object>();
                 //鍒ゆ柇鏄惁鏈夋煡璇㈡潈闄�
                 if (!DBUtility.ClsPub.Security_Log("Sc_PPBomBillList_Query", 1, false, user))
                 {
@@ -49,8 +53,14 @@
                 else
                 {
                     string sql1 = "select * from h_v_IF_PPBomBillList where 1 = 1 ";
-                    string sql = sql1 + sWhere+ " order by hmainid desc ";
+                    string sql = sql1 + sWhere + " order by hmainid desc ";
                     ds = oCN.RunProcReturn(sql, "h_v_IF_PPBomBillList");
+                }
+                foreach (DataColumn col in ds.Tables[0].Columns)//閬嶅巻ds涓涓�涓〃锛圱ables[0]锛夌殑鎵�鏈夊垪锛圕olumns锛夋瘡娆″惊鐜腑锛宑ol鍙橀噺浼氭寔鏈夊綋鍓嶅垪鐨勫紩鐢�
+                {
+                    Type dataType = col.DataType; //鑾峰彇褰撳墠鏁版嵁绫诲瀷浼犲叆 鑷畾涔夊彉閲廳atadataType
+                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}"; //瀛楃涓叉嫾鎺�         // 灏嗗垪鍚嶅拰鏁版嵁绫诲瀷淇℃伅鎷兼帴鎴愪竴涓狫SON鏍煎紡鐨勫瓧绗︿覆
+                    a.Add(JsonConvert.DeserializeObject(ColmString));//鑾峰彇鍒癉ataColumn鍒楀璞$殑鍒楀悕
                 }
 
                 //if (ds.Tables[0].Rows.Count != 0 || ds != null)
@@ -59,6 +69,7 @@
                 objJsonResult.count = 1;
                 objJsonResult.Message = "Sucess锛�";
                 objJsonResult.data = ds.Tables[0];
+                objJsonResult.list = a;
                 return objJsonResult;
                 //}
                 //else
@@ -80,7 +91,102 @@
             }
         }
 
+        [Route("Sc_PPBomBill/Editlist")]
+        [HttpGet]
+        public object Editlist(string sWhere)
+        {
+            try
+            {
+                List<object> a = new List<object>();
+                //鍒ゆ柇鏄惁鏈夋煡璇㈡潈闄�
+               
 
+                if (sWhere == null || sWhere.Equals(""))
+                {
+                    ds = oCN.RunProcReturn("select * from h_v_IF_PPBomBillList order by hmainid desc ", "h_v_IF_PPBomBillList");
+                }
+                else
+                {
+                    string sql1 = "select * from h_v_IF_PPBomBillList where 1 = 1 ";
+                    string sql = sql1 + sWhere + " order by hmainid desc ";
+                    ds = oCN.RunProcReturn(sql, "h_v_IF_PPBomBillList");
+                }
+                foreach (DataColumn col in ds.Tables[0].Columns)//閬嶅巻ds涓涓�涓〃锛圱ables[0]锛夌殑鎵�鏈夊垪锛圕olumns锛夋瘡娆″惊鐜腑锛宑ol鍙橀噺浼氭寔鏈夊綋鍓嶅垪鐨勫紩鐢�
+                {
+                    Type dataType = col.DataType; //鑾峰彇褰撳墠鏁版嵁绫诲瀷浼犲叆 鑷畾涔夊彉閲廳atadataType
+                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}"; //瀛楃涓叉嫾鎺�         // 灏嗗垪鍚嶅拰鏁版嵁绫诲瀷淇℃伅鎷兼帴鎴愪竴涓狫SON鏍煎紡鐨勫瓧绗︿覆
+                    a.Add(JsonConvert.DeserializeObject(ColmString));//鑾峰彇鍒癉ataColumn鍒楀璞$殑鍒楀悕
+                }
+
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "Sucess锛�";
+                objJsonResult.data = ds.Tables[0];
+                objJsonResult.list = a;
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+
+
+        #region 鐢熶骇鐢ㄦ枡娓呭崟鍒楄〃鍒嗛〉鍒楄〃
+        [Route("Sc_PPBomBill/page")]
+        [HttpGet]
+        public object page(string sWhere, string user,int page,int size)
+        {
+            try
+            {
+                List<object> columnNameList = new List<object>();
+                //缂栬緫鏉冮檺
+                if (!DBUtility.ClsPub.Security_Log_second("Sc_PPBomBillList_Query", 1, false, user))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鏃犳煡鐪嬫潈闄愶紒";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+                if (sWhere == null || sWhere.Equals(""))
+                {
+                    ds = oCN.RunProcReturn("exec h_p_Sc_PPBomBillList " + page + "," + size + "," + "''", "h_p_Sc_PPBomBillList");
+                }
+                else
+                {
+                    ds = oCN.RunProcReturn("exec h_p_Sc_PPBomBillList " + page + "," + size + ",'"  + sWhere + "'", "h_p_Sc_PPBomBillList");
+                }
+
+                //娣诲姞鍒楀悕
+                foreach (DataColumn col in ds.Tables[0].Columns)
+                {
+                    Type dataType = col.DataType;
+                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
+                    columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//鑾峰彇鍒癉ataColumn鍒楀璞$殑鍒楀悕
+                }
+
+                objJsonResult.code = "1";
+                objJsonResult.count = int.Parse(ds.Tables[1].Rows[0]["count"].ToString());
+                objJsonResult.Message = "Sucess锛�";
+                objJsonResult.list = columnNameList;
+                objJsonResult.data = ds.Tables[0];
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
 
         #region 鐢熶骇鐢ㄦ枡娓呭崟 瀹℃牳/鍙嶅鏍�
         [Route("Sc_PPBomBill/DeOrAuditBill")]
@@ -148,7 +254,7 @@
                 {
                     objJsonResult.code = "0";
                     objJsonResult.count = 0;
-                    objJsonResult.Message = "鍗曟嵁涓嶅瓨鍦�,鍘熷洜:"+DBUtility.ClsPub.sExeReturnInfo;
+                    objJsonResult.Message = "鍗曟嵁涓嶅瓨鍦�,鍘熷洜:" + DBUtility.ClsPub.sExeReturnInfo;
                     objJsonResult.data = null;
                     return objJsonResult;
                 }
@@ -219,7 +325,7 @@
             catch (Exception e)
             {
                 sReturn = e.Message;
-                throw(e);
+                throw (e);
             }
         }
         //鍙嶅鏍�
@@ -240,6 +346,216 @@
                 throw (e);
             }
         }
+        #endregion
+
+        #region 鐢熶骇鐢ㄦ枡鍗� 淇濆瓨/缂栬緫鍔熻兘 鏂版柟娉�
+        [Route("Sc_PPBomBill/sc_PPBomBillAdd")]
+        [HttpPost]
+        public object sc_PPBomBillAdd([FromBody] JObject sMainSub)
+        {
+            var _value = sMainSub["sMainSub"].ToString();
+            string msg1 = _value.ToString();
+            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
+         
+            try
+            {
+                string msg2 = sArray[0].ToString(); //涓昏〃鏁版嵁
+                string msg3 = sArray[1].ToString(); //瀛愯〃鏁版嵁
+                int OperationType = int.Parse(sArray[2].ToString()); // 鏁版嵁绫诲瀷 1娣诲姞 3淇敼
+                string user = sArray[3].ToString();
+
+                //鍒ゆ柇鏄惁鏈夌紪杈戞潈闄�
+                if (!DBUtility.ClsPub.Security_Log("QC_TestSampleCheckBill_Edit", 1, false, user))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鏃犵紪杈戞潈闄�!";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                ClsSc_PPBomBillMain list = Newtonsoft.Json.JsonConvert.DeserializeObject<ClsSc_PPBomBillMain>(msg2);
+                string BillType = "3720";
+                string HBillSubType = "3720";
+                long HInterID = list.HInterID;//閫掑叆type寰楀埌鐨勫崟鎹甀D
+                string HBillNo = list.HBillNo;//閫掑叆type寰楀埌鐨勫崟鎹彿
+                int HBillStatus = 1;
+                string HMaker = user;//鍒跺崟浜�
+                int HYear = DateTime.Now.Year;
+                double HPeriod = DateTime.Now.Month;
+                long HICMOInterID = list.HICMOInterID;//浠诲姟鍗旾D
+                long HICMOEntryID = list.HICMOEntryID;//浠诲姟鍗旾D
+                string HICMOBillNo = list.HICMOBillNo;//浠诲姟鍗旾D
+                long HMaterID = list.HMaterID;//浜у搧ID
+                long HUnitID = list.HUnitID;//璁¢噺鍗曚綅
+                long HPRDORGID = list.HPRDORGID;//缁勭粐ID
+                long HICMOEntrySEQ = list.HICMOEntrySEQ; 
+                DateTime HDate = list.HDate; 
+                double HQty = list.HQty;
+                long HDeptID = list.HDeptID;
+                string HRemark = list.HRemark;
+                string HChecker = "";
+                string HCheckDate = "";
+                string HSeOrderBillNo = "";
+                long HSeOrderInterID = 0;
+                long HSeOrderEntryID = 0;
+                long HENTRUSTORGID = 0;
+                long HPARENTOWNERID = 0;
+                long HPARENTOWNERTYPEID = 0;
+                long HERPInterID = 0;
+                long HSeOrderEntrySEQ = 0;
+                string HERPBillType = "";
+                string HREQSRC = "";
+
+                oCN.BeginTran();
+                if (OperationType== 1)
+                {
+                    ds = oCN.RunProcReturn("select * from Sc_PPBomBillMain where HBillNo='" + HBillNo + "'", "Sc_PPBomBillMain");
+                    if (ds.Tables[0].Rows.Count == 1)
+                    {
+                        oCN.RollBack();
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = "鍗曟嵁鍙烽噸澶嶏紒";
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                    //涓昏〃
+                    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,HRemark)
+                        values(" + HInterID + "," + DateTime.Now.Year + "," + DateTime.Now.Month + ",'" + BillType + "','" +
+                    HBillSubType + "','" + HDate + "','" + HBillNo + "','" + HBillStatus + "'," + HICMOInterID +
+                    "," + HICMOEntryID + ",'" + HMaterID + "'," + HUnitID + "," + HQty + "," + HDeptID +
+                    ",'" + HMaker + "',getdate(),'" + HChecker + "','" + HCheckDate + "','" + HSeOrderBillNo + "'," + HSeOrderInterID + "," + HSeOrderEntryID + "," + HPRDORGID + "," + HENTRUSTORGID + "," + HPARENTOWNERID + "," +
+                    HPARENTOWNERTYPEID + "," + HERPInterID + ",'" + HERPBillType + "'," + HSeOrderEntrySEQ + "," + HICMOEntrySEQ + ",'" + HREQSRC + "','"+ HRemark + "')");
+                }
+                else  if (OperationType == 3 )
+                { //淇敼
+                    oCN.RunProc("update Sc_PPBomBillMain  set " +
+                                "HRemark='" + HRemark + "', HChecker='" + HMaker + "', HCheckDate=getdate()" +
+                                ",HDeptID=" + HDeptID + ",HICMOInterID=" + HICMOInterID + ",HICMOEntryID=" + HICMOEntryID + ",HMaterID=" + HMaterID + ",HUnitID=" + HUnitID + ",HICMOEntrySEQ=" + HICMOEntrySEQ + " ,HQty=" + HQty + " where HInterID=" + HInterID);
+
+                    //鍒犻櫎瀛愯〃
+                    oCN.RunProc("delete from Sc_PPBomBillSub where HInterID='" + HInterID + "'");
+                }
+                else
+                {
+                    oCN.RollBack();
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鎿嶄綔绫诲瀷鏃犳晥锛�";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                List<ClsSc_PPBomBillSub> DetailColl = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsSc_PPBomBillSub>>(msg3);
+                int i = 0;
+                foreach (ClsSc_PPBomBillSub oSub in DetailColl)
+                {
+                    i++;
+                    string HMaterNumber = oSub.HMaterNumber;
+                    string HUnitNumber = oSub.HUnitNumber;
+                    long HQtyMust = 0;
+                    long HSourceInterID = oSub.HSourceInterID;
+                    long HSourceEntryID = oSub.HSourceEntryID;
+                    long HCHILDSUPPLYORGID = oSub.HCHILDSUPPLYORGID;
+                    long HSUPPLYORGID = oSub.HSUPPLYORGID;
+                    long HENTRUSTPICKORGID = oSub.HENTRUSTPICKORGID;
+                    long HSRCTRANSORGID = oSub.HSRCTRANSORGID;
+                    long HGROUPBYOWNERID = oSub.HGROUPBYOWNERID;
+                    long HOWNERID = oSub.HOWNERID;
+                    long HAuxPropID = oSub.HAuxPropID;
+                    long HERPEntryID = oSub.HERPEntryID;
+                    long HProcessID = oSub.HProcessID;
+                    long HICMOENTRYSEQ = oSub.HICMOENTRYSEQ;
+                    long HOPERID = oSub.HOPERID;
+                    long HSEQ = i;
+                    long HSTOCKSTATUSID = oSub.HSTOCKSTATUSID;
+                    long HOPTQUEUE = oSub.HOPTQUEUE;
+                    long HLOT = oSub.HLOT;
+                    long HRESERVETYPE = oSub.HRESERVETYPE;
+                    string HOWNERTYPEID = oSub.HOWNERTYPEID;
+                    double HRelationQty = oSub.HRelationQty;
+                    double HMoveStockQty = oSub.HMoveStockQty;
+                    double HQtyScrap = oSub.HQtyScrap;
+                    double HBackRelationQty = oSub.HBackRelationQty;
+                    double HNumerator = oSub.HNumerator;
+                    double HDenominator = oSub.HDenominator;
+                    double HSelPickedQty = oSub.HSelPickedQty;
+                    double HSELPRCDRETURNQTY = oSub.HSELPRCDRETURNQTY;
+                    string HSourceBillNo = oSub.HSourceBillNo;
+                    string HSourceBillType = oSub.HSourceBillType;
+                    string HBatchNO = oSub.HBatchNO;
+                    string HMTONo = oSub.HMTONo;
+                    string HPROJECTNO = oSub.HPROJECTNO;
+
+                    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.HUnitID == 0)
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = "绗�" + i + "琛岋紝璁¢噺鍗曚綅涓嶈兘涓虹┖";
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+
+                    Int64 NewHEntryID = i;
+
+                    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) 
+                 values({HInterID},{NewHEntryID},{oSub.HMaterID},'{HMaterNumber}',{oSub.HUnitID},'{HUnitNumber}',{oSub.HSPID},{(oSub.HQty == null ? 0 : oSub.HQty)}
+                ,{HQtyMust},{oSub.HWHID},'{oSub.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},{oSub.HBASEUNITID},{HProcessID},{HICMOENTRYSEQ},'{HPROJECTNO}',{HOPERID},{HSEQ},{HSTOCKSTATUSID},{HLOT},{HOPTQUEUE},{HRESERVETYPE},{HSelPickedQty},{HSELPRCDRETURNQTY})");
+                }
+
+
+
+                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 = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+
+       
+
         #endregion
 
         #region 鐢熶骇鐢ㄦ枡鍗� 淇濆瓨/缂栬緫鍔熻兘
@@ -409,7 +725,7 @@
 
             DateTime dt = DateTime.Now;
 
-            long HQtyMust = DetailColl2[0].HQtyMust == null ? 0 : DetailColl2[0].HQtyMust; //搴斿彂鏁伴噺
+            decimal HQtyMust = DetailColl2[0].HQtyMust == null ? 0 : DetailColl2[0].HQtyMust; //搴斿彂鏁伴噺
             double HNumerator = DetailColl2[0].HNumerator == null ? 0 : DetailColl2[0].HNumerator;  //鍒嗗瓙
             double HDenominator = DetailColl2[0].HDenominator == null ? 0 : DetailColl2[0].HDenominator;  //鍒嗘瘝
             double HQtyScrap = DetailColl2[0].HQtyScrap == null ? 0 : DetailColl2[0].HQtyScrap;  //鎹熻�楃巼
@@ -514,7 +830,7 @@
                 {
                     NewHEntryID = ClsPub.isLong(Cs.Tables[0].Rows[0]["HEntryID"].ToString());
                     NewHEntryID += 1;
-                }            
+                }
 
 
                 oCN.RunProc($@"Insert into Sc_PPBomBillSub 
@@ -536,6 +852,67 @@
             return objJsonResult;
         }
 
+        [Route("Sc_PPBomBill/Sc_PPBomBillSaveApi")]
+        [HttpPost]
+        public object Sc_PPBomBillSaveApi([FromBody] JObject sMainSub)
+        {
+            try
+            {
+                var model = sMainSub["model"].ToString();
+                var entry = sMainSub["model"]["HENTRY"].ToString();
+               
+
+                model = "[" + model.ToString() + "]";
+                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_PPBomBillMain where HinterID = {mainList[0].HInterID}";
+                oCN.RunProc(sql);
+                sql = $"delete Sc_PPBomBillSub where HinterID = {mainList[0].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(" + mainList[0].HInterID + "," + DateTime.Now.Year + "," + DateTime.Now.Month + ",'" + 3720 + "','" +
+                mainList[0].HBillSubType + "','" + mainList[0].HDate + "','" + mainList[0].HBillNo + "','" + mainList[0].HBillStatus + "'," + mainList[0].HICMOInterID +
+                "," + mainList[0].HICMOEntryID + ",'" + mainList[0].HMaterID + "'," + mainList[0].HUnitID + "," + mainList[0].HQty + "," + mainList[0].HDeptID +
+                ",'" + mainList[0].HMaker + "','" + mainList[0].HMakeDate + "','" + mainList[0].HChecker + "','" + mainList[0].HCheckDate + "','" + mainList[0].HSeOrderBillNo + "'," + mainList[0].HSeOrderInterID + "," + mainList[0].HSeOrderEntryID + "," + mainList[0].HPRDORGID + "," + mainList[0].HENTRUSTORGID + "," + mainList[0].HPARENTOWNERID + ",'" +
+                mainList[0].HPARENTOWNERTYPEID + "'," + mainList[0].HERPInterID + ",'" + mainList[0].HERPBillType + "'," + mainList[0].HSeOrderEntrySEQ + "," + mainList[0].HICMOEntrySEQ + ",'" + mainList[0].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}','{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)
+            {
+                oCN.RollBack();
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "淇濆瓨澶辫触锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
         #endregion
 
         /// <summary>
@@ -569,5 +946,278 @@
             }
         }
 
+        #region [鍚屾鍗曟嵁]
+        [Route("Sc_PPBomBill/Sc_PPBomBillViewApi")]
+        [HttpGet]
+        public json Sc_PPBomBillViewApi(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_PPBOM", 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_PPBomBillMain where HBillNo = '" + BillNo + "'", "Sc_PPBomBillMain");
+                    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 = 3720,
+                        HBillSubType = 3720,
+                        HDate = _saveObj["Result"]["Result"]["CreateDate"],
+                        HBillNo = _saveObj["Result"]["Result"]["BillNo"],
+                        HBillStatus         = _saveObj["Result"]["Result"]["ApproverId_Id"].ToString() == Convert.ToString(0) ? 1 : 2,
+                        HICMOInterID        = _saveObj["Result"]["Result"]["MoId"],
+                        HICMOEntryID        = _saveObj["Result"]["Result"]["MOEntryID"],
+                        HMaterID            = _saveObj["Result"]["Result"]["MaterialID_Id"],
+                        HUnitID             = _saveObj["Result"]["Result"]["UnitID_Id"],
+                        HQty                = _saveObj["Result"]["Result"]["Qty"],
+                        HDeptID             = _saveObj["Result"]["Result"]["WorkshopID_Id"],
+                        HMaker              = _saveObj["Result"]["Result"]["CreatorId"]["Name"],
+                        HMakeDate           = _saveObj["Result"]["Result"]["CreateDate"],
+                        HChecker            = _saveObj["Result"]["Result"]["ApproverId"]["Name"],
+                        HCheckDate          = _saveObj["Result"]["Result"]["ApproveDate"],
+                        HSeOrderBillNo      = _saveObj["Result"]["Result"]["SALEORDERNO"],
+                        HSeOrderInterID     = _saveObj["Result"]["Result"]["SaleOrderId"],
+                        HSeOrderEntryID     = _saveObj["Result"]["Result"]["SaleOrderEntryId"],
+                        HPRDORGID           = _saveObj["Result"]["Result"]["PrdOrgId_Id"],
+                        HENTRUSTORGID       = _saveObj["Result"]["Result"]["EntrustOrgId_Id"],
+                        HPARENTOWNERID      = _saveObj["Result"]["Result"]["ParentOwnerId_Id"],
+                        HPARENTOWNERTYPEID  = _saveObj["Result"]["Result"]["ParentOwnerTypeId"],
+                        HREQSRC             = _saveObj["Result"]["Result"]["ReqSrc"],
+                        HERPInterID = _saveObj["Result"]["Result"]["Id"],
+                        HERPBillType              = "PPBOM",
+                        HSeOrderEntrySEQ          = _saveObj["Result"]["Result"]["SaleOrderEntrySeq"],
+                        HICMOEntrySEQ = _saveObj["Result"]["Result"]["MOEntrySeq"]
+                    };
+                    #endregion
+                    // 鍒犻櫎涓昏〃瀵瑰簲鏁版嵁
+                    sql = $"delete from Sc_PPBomBillMain where HInterID = " + InterID;
+                    oCN.RunProc(sql);
+
+                    //鎻掑叆涓昏〃
+                    sql = $@"
+                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,HREQSRC
+	            ,HERPInterID,HERPBillType,HSeOrderEntrySEQ,HICMOEntrySEQ
+                 )
+                values
+                ({jsonData.HInterID},{jsonData.HYear},{jsonData.HPeriod},{jsonData.HBillType},{jsonData.HBillSubType},
+                '{jsonData.HDate}','{jsonData.HBillNo}',{jsonData.HBillStatus},{jsonData.HICMOInterID},{jsonData.HICMOEntryID},
+                {jsonData.HMaterID},{jsonData.HUnitID},{jsonData.HQty},{jsonData.HDeptID},'{jsonData.HMaker}','{jsonData.HMakeDate}','{jsonData.HChecker}',
+                '{jsonData.HCheckDate}','{jsonData.HSeOrderBillNo}',{jsonData.HSeOrderInterID},{jsonData.HSeOrderEntryID},{jsonData.HPRDORGID},
+                {jsonData.HENTRUSTORGID},{jsonData.HPARENTOWNERID},'{jsonData.HPARENTOWNERTYPEID}','{jsonData.HREQSRC}',{jsonData.HERPInterID},
+                '{jsonData.HERPBillType}',{jsonData.HSeOrderEntrySEQ},'{jsonData.HICMOEntrySEQ}')";
+
+                    oCN.RunProc(sql);
+
+                    #region [鐢宠瀛愯〃鍙橀噺]
+                    var dataArr = _saveObj["Result"]["Result"]["PPBomEntry"];
+
+                    DataSet Cs;
+                    double RelationQty = 0;
+                    #endregion
+                    int i = 0;
+
+                    // 鑾峰彇瀛愯〃鏁版嵁
+                    Cs = oCN.RunProcReturn("select * from Sc_PPBomBillSub where HInterID = " + InterID, "Sc_PPBomBillSub");
+                    // 鍒犻櫎瀛愯〃瀵瑰簲鏁版嵁
+                    sql = $"delete from Sc_PPBomBillSub 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"],
+                            HMaterID = oSub["MaterialID_Id"],
+                            HUnitID           = oSub["UnitID_Id"],
+                            HQty              = oSub["NeedQty"],
+                            HQtyMust          = oSub["NeedQty"],
+                            HWHID             = oSub["StockID_Id"],
+                            HRemark           = "CLOUD瀵煎叆",
+                            HSourceInterID    = oSub["MoId"],
+                            HSourceEntryID    = oSub["MoEntryId"],
+                            HSourceBillNo     = oSub["MoBillNo"],
+                            HSourceBillType   = 3710,
+                            HICMOInterID      = oSub["MoId"],
+                            HICMOEntryID      = oSub["MoEntryId"],
+                            HICMOBillNo       = oSub["MoBillNo"],
+                            HCHILDSUPPLYORGID = oSub["ChildSupplyOrgId_Id"],
+                            HSUPPLYORGID      = oSub["SupplyOrg_Id"],
+                            HENTRUSTPICKORGID = oSub["EntrustPickOrgId_Id"],
+                            HSRCTRANSORGID    = oSub["SrcTransOrgId_Id"],
+                            HGROUPBYOWNERID   = oSub["GroupByOwnerId_Id"],
+                            HOWNERID          = oSub["OwnerID_Id"],
+                            HOWNERTYPEID      = oSub["OwnerTypeId"],
+                            HRelationQty      = Convert.ToInt32(oSub["SelPickedQty"]) - Convert.ToInt32(oSub["SelPrcdReturnQty"]),
+                            HMoveStockQty     = oSub["SelTranslateQty"],
+                            HAuxPropID        = oSub["AuxPropID_Id"],
+                            HBatchNO          = oSub["Lot_Text"],
+                            HMTONo            = oSub["MTONO"],
+                            HQtyScrap               = Convert.ToInt32(oSub["BaseNumerator"]) / Convert.ToInt32(oSub["BaseDenominator"]),
+                            HERPInterID             = _saveObj["Result"]["Result"]["Id"],
+                            HERPEntryID             = oSub["Id"],
+                            HBackRelationQty        = oSub["WipQty"],
+                            HNumerator              = oSub["Numerator"],
+                            HDenominator             = oSub["Denominator"],
+                            HBASEUNITID             = oSub["BaseUnitID_Id"],
+                            HProcessID              = oSub["ProcessID_Id"],
+                            HICMOENTRYSEQ           = oSub["MoEntrySeq"],
+                            HPROJECTNO              = oSub["ProjectNO"],
+                            HOPERID                 = oSub["OperID"],
+                            HSEQ                    = oSub["Seq"],
+                            HSTOCKSTATUSID          = oSub["StockStatusId_Id"],
+                            HLOT                    = oSub["Lot_Id"],
+                            HOPTQUEUE               = oSub["OptQueue"],
+                            HRESERVETYPE            = oSub["ReserveType"],
+                            HSelPickedQty           = oSub["SelPickedQty"],
+                            HSELPRCDRETURNQTY = oSub["SelPrcdReturnQty"],
+                        };
+                        #endregion                       
+
+                        //鎻掑叆瀛愯〃
+                        sql = $@"
+                 insert into Sc_PPBomBillSub
+                 (HInterID,HEntryID,HMaterID,HUnitID,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
+                 )
+                 values
+                 ({subData.HInterID},{subData.HEntryID},{subData.HMaterID},{subData.HUnitID},{subData.HQty},{subData.HQtyMust},{subData.HWHID},'{subData.HRemark}',{subData.HSourceInterID},{subData.HSourceEntryID},'{subData.HSourceBillNo}','{subData.HSourceBillType}',{subData.HICMOInterID},{subData.HICMOEntryID},'{subData.HICMOBillNo}',{subData.HCHILDSUPPLYORGID},{subData.HSUPPLYORGID},{subData.HENTRUSTPICKORGID},{subData.HSRCTRANSORGID},{subData.HGROUPBYOWNERID},{subData.HOWNERID},'{subData.HOWNERTYPEID}',{subData.HRelationQty},{subData.HMoveStockQty},{subData.HAuxPropID},'{subData.HBatchNO}','{subData.HMTONo}',{subData.HQtyScrap},{subData.HERPInterID},{subData.HERPEntryID},{subData.HBackRelationQty},'{subData.HNumerator}','{subData.HDenominator}',{subData.HBASEUNITID},{subData.HProcessID},{subData.HICMOENTRYSEQ},'{subData.HPROJECTNO}',{subData.HOPERID},{subData.HSEQ},{subData.HSTOCKSTATUSID},{subData.HLOT},{subData.HOPTQUEUE},'{subData.HRESERVETYPE}',{subData.HSelPickedQty},{subData.HSELPRCDRETURNQTY}
+                  )";
+
+                        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