1
ch
2023-03-30 b7ede349929b44bd664d059728919f6c8eede66a
WebAPI/Controllers/Éú²ú¹ÜÀí/Éú²úÈÎÎñµ¥/Sc_ICMOBillController.cs
@@ -23,6 +23,10 @@
        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]
@@ -108,17 +112,27 @@
                {
                    //主表
                    oCN.RunProc(@"Insert Into Sc_ICMOBillMain   
                        (HBillType,HInterID,HBillNo,HDate,HPRDORGID
                        (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'," + HInterID + ",'" + HBillNo + "','" + HDate + "'," + HPRDORGID +
                        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 + "" +
@@ -138,6 +152,9 @@
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                //修改字段 HSTOCKINORGID
                oCN.RunProc("update Sc_ICMOBillSub set HSTOCKINORGID=" + HPRDORGID + " where HInterID=" + HInterID);
                objJsonResult.code = "1";
                objJsonResult.count = 1;
@@ -168,7 +185,7 @@
            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;         //产品类型,
            long HCOSTRATE = DetailColl[0].HCOSTRATE == null ? 0 : DetailColl[0].HCOSTRATE;         // æƒé‡,
            double HCOSTRATE = DetailColl[0].HCOSTRATE == null ? 0 : DetailColl[0].HCOSTRATE;         // æƒé‡,
            long HBASEUNITID = DetailColl[0].HBASEUNITID == null ? 0 : DetailColl[0].HBASEUNITID;       //基本计量单位,
            int i = 0;
@@ -226,12 +243,13 @@
               ,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)
                ,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})");
                       ,0,0,'','',0,0,{HINSTOCKTYPE},{HCHECKPRODUCT},{HQAIP},{HISBACKFLUSH},{HREQSRC},{HSTOCKINQUASELAUXQTY},{HSeOrderEntrySEQ},{HPROJECTNO},{HPRODUCTTYPE},{HCOSTRATE},{HBASEUNITID},{oSub.HSTOCKINORGID})");
            }
            objJsonResult.code = "1";
@@ -248,6 +266,7 @@
        {
            try
            {
                //LogService.Write(sMainSub.ToString());
                var model = sMainSub["model"].ToString();
                var entry = sMainSub["model"]["HENTRY"].ToString();
                var _model = sMainSub["model"]["HPPBOMMAINENTRY"].ToString();
@@ -281,12 +300,14 @@
                ,HPlanBeginDate,HPlanEndDate
               ,HBeginDate,HEndDate
                ,HMaterID,HUnitID,HRemark,HSourceID,HDeptID,HSTATUS
            ,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney)
            ,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)");
                       ,0,0,'','',0,0
                ,{oSub.HCOSTRATE},{oSub.HISBACKFLUSH},'{oSub.HBatchNo}',{oSub.HBomID},{oSub.HCHECKPRODUCT},{oSub.HSEQ})");
                }
                foreach (var _item in _mainList)
@@ -318,7 +339,7 @@
               ,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}')");
                ,'{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";
@@ -330,6 +351,7 @@
            }
            catch (Exception e)
            {
                LogService.Write(e.Message.ToString());
                oCN.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
@@ -337,6 +359,7 @@
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
@@ -386,6 +409,7 @@
            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
            {
@@ -423,27 +447,37 @@
                {
                    //主表
                    oCN.RunProc(@"Insert Into Sc_ICMOBillMain   
                        (HBillType,HInterID,HBillNo,HDate,HPRDORGID
                        (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'," + HInterID + ",'" + HBillNo + "','" + HDate + "'," + HPRDORGID +
                        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 + "', HChecker='" + HMaker + "', HCheckDate=getdate()" +
                                "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 + "'");
                    oCN.RunProc("delete from Sc_ICMOBillSub where HInterID='" + HInterID + "' and HEntryID='" + HEntryID + "'");
                }
                //保存子表
                objJsonResult = AddBillSub_NoTable(msg3, HInterID, OperationType);
                objJsonResult = AddBillSub_NoTable(msg3, HInterID, OperationType, HEntryID);
                if (objJsonResult.code == "0")
                {
@@ -470,7 +504,7 @@
            }
        }
        public json AddBillSub_NoTable(string msg3, long HInterID, int OperationType)
        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)
@@ -509,28 +543,30 @@
                return objJsonResult;
            }
            if (oSub.HBomID == 0)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "BOM不能为空";
                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
            ,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney)
                 values({HInterID},1,{(oSub.HQty == null ? 0 : oSub.HQty)}
                ,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}
                       ,0,0,'','',0,0)");
                 ,{oSub.HBomID}  ,{oSub.HCusID} ,{oSub.HSTOCKINORGID}
                       ,0,0,'','',0,0
                ,{oSub.HAuxQty},{oSub.HAuxUnit},{oSub.HWidth},{oSub.HWeight})");
            objJsonResult.code = "1";
@@ -540,6 +576,241 @@
            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")]
@@ -576,6 +847,16 @@
                    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();//提交事务
@@ -1080,5 +1361,331 @@
        #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为公有云模式,Y为私有云模式
                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 = "金蝶生产任务单同步失败jsonRoot:" + _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
    }
}