1
cwjbxqmz
2023-10-07 45f7b5664b7acd74b693ba374c4d77fd11db4f5a
WebAPI/Controllers/XSGL/Xs_SeOrderBillController.cs
@@ -18,6 +18,7 @@
        //获取系统参数
        Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
        public DBUtility.ClsPub.Enum_BillStatus BillStatus;
        public DAL.ClsXs_SeOrderBill BillOld = new DAL.ClsXs_SeOrderBill();
        private json objJsonResult = new json();
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
@@ -433,6 +434,84 @@
            }
        }
        #region [同步插件]
        [Route("Xs_SeOrderBill/Xs_SeOrderBillSaveApi")]
        [HttpPost]
        public object Xs_SeOrderBillSaveApi([FromBody] JObject sMainSub)
        {
            try
            {
                //LogService.Write("销售订单同步,保存方法执行完成异常:" + sMainSub.ToString());
                var model = sMainSub["model"].ToString();
                var entry = sMainSub["model"]["HENTRY"].ToString();
                model = "[" + model.ToString() + "]";
                LogService.Write("销售订单同步 sMainSub:" + sMainSub);
                List<ClsXs_SeOrderBillMain> mainList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsXs_SeOrderBillMain>>(model);
                List<ClsXs_SeOrderBillSub> subList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsXs_SeOrderBillSub>>(entry);
                string sql = string.Empty;
                oCN.BeginTran();
                sql = $"delete Xs_SeOrderBillMain where HinterID = {mainList[0].HInterID}";
                oCN.RunProc(sql);
                sql = $"delete Xs_SeOrderBillSub where HinterID = {mainList[0].HInterID}";
                oCN.RunProc(sql);
                //主表
                oCN.RunProc(@"Insert Into Xs_SeOrderBillMain
                        (HInterID,HYear,HPeriod,HBillType,HBillSubType,HDate
                       ,HBillNo,HBillStatus
                       ,HAddress,HSSID,HSSDate,HCusID,HCurID,HExRate
                       ,HEmpID,HManagerID,HDeptID,HExplanation,HRemark,HInnerBillNo
                       ,HChecker,HCheckDate,HMaker,HMakeDate,HCloseMan,HCloseDate
                       ,HERPInterID,HERPBillType,HSALEORGID,HSALEGROUPID,HRECEIVEID,HSETTLEID
                       ,HCHARGEID,HHEADLOCID,HRECCONTACTID,HCORRESPONDORGID,HBUSINESSTYPE)
                        values(" + mainList[0].HInterID + "," + DateTime.Now.Year + "," + DateTime.Now.Month + ",'" + 1401 + "','" +
                    mainList[0].HBillSubType + "','" + mainList[0].HDate + "','" + mainList[0].HBillNo + "','" + mainList[0].HBillStatus + "','" + mainList[0].HAddress + "'," + mainList[0].HSSID +
                    ",'" + mainList[0].HSSDate + "'," + mainList[0].HCusID + "," + mainList[0].HCurID + "," + mainList[0].HExRate + "," + mainList[0].HEmpID + "," + mainList[0].HManagerID + "," + mainList[0].HDeptID + ",'" + mainList[0].HExplanation + "','" + mainList[0].HRemark + "','" +
                    mainList[0].HInnerBillNo + "','" + mainList[0].HChecker + "','" + mainList[0].HCheckDate + "','" + mainList[0].HMaker + "','" + mainList[0].HMakeDate + "','"
                     + mainList[0].HCloseMan + "','" + mainList[0].HCloseDate + "'," + mainList[0].HERPInterID + ",'"
                    + mainList[0].HERPBillType + "'," + mainList[0].HSALEORGID + "," + mainList[0].HSALEGROUPID + "," + mainList[0].HRECEIVEID + "," + mainList[0].HSETTLEID + "," + mainList[0].HCHARGEID + "," + mainList[0].HHEADLOCID + "," + mainList[0].HRECCONTACTID + "," + mainList[0].HCORRESPONDORGID + ",'" + mainList[0].HBUSINESSTYPE + "'" + ")");
                //保存子表
                foreach (var oSub in subList)
                {
                    sql = $@"
Insert into Xs_SeOrderBillSub
(HInterID,HEntryID,HMaterID,HUnitID,HQty,HPrice
   ,HTaxPrice,HDiscountRate,HRelTaxPrice,HMoney,HTaxRate,HTaxMoney
   ,HLineTotal,HlineTotalBB,HDate,HOutStockQty,HInvoiceQty,HRemark
   ,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType
   ,HRelationQty,HPropertyID,HBatChNo,HAuxPropID,HMTONo
   ,HERPInterID,HERPEntryID,HBackRelationQty,HWhID,HSPID
   ,HSTOCKORGID,HOWNERID,HOWNERTYPEID,HMAPID,HSTOCKUNITID,HBASEUNITID
   ,HBFLOWID,HSETTLEORGID,HTAXCOMBINATION,HPRICEUNITID,HISFREE,HPRICECOEFFICIENT
   ,HSYSPRICE,HLIMITDOWNPRICE,HPARENTMATID,HROWTYPE,HROWID,HPARENTROWID
   ,HDELIVERYCONTROL,HLOCALCURRID,HEXCHANGETYPEID,HSETTLECURRID,HSETTLEMODEID
   ,HRECCONDITIONID,HISINCLUDEDTAX,HISPRICEEXCLUDETAX,HEXCHANGERATE,HTAXRATEID
   ,HCOSTPERCENT,HVAT,HSELLERWITHHOLDING,HBUYERWITHHOLDING,HPRICELISTENTRY)
values('{oSub.HInterID}','{oSub.HEntryID}','{oSub.HMaterID}','{oSub.HUnitID}','{oSub.HQty}','{oSub.HPrice}','{oSub.HTaxPrice}','{oSub.HDiscountRate}','{oSub.HRelTaxPrice}','{oSub.HMoney}','{oSub.HTaxRate}','{oSub.HTaxMoney}','{oSub.HLineTotal}','{oSub.HlineTotalBB}','{oSub.HDate}','{oSub.HOutStockQty}','{oSub.HInvoiceQty}','{oSub.HRemark}','{oSub.HSourceInterID}','{oSub.HSourceEntryID}','{oSub.HSourceBillNo}','{oSub.HSourceBillType}','{oSub.HRelationQty}','{oSub.HPropertyID}','{oSub.HBatChNo}','{oSub.HAuxPropID}','{oSub.HMTONo}','{oSub.HERPInterID}','{oSub.HERPEntryID}','{oSub.HBackRelationQty}','{oSub.HWhID}','{oSub.HSPID}','{oSub.HSTOCKORGID}','{oSub.HOWNERID}','{oSub.HOWNERTYPEID}','{oSub.HMAPID}','{oSub.HSTOCKUNITID}','{oSub.HBASEUNITID}','{oSub.HBFLOWID}','{oSub.HSETTLEORGID}','{oSub.HTAXCOMBINATION}','{oSub.HPRICEUNITID}','{oSub.HISFREE}','{oSub.HPRICECOEFFICIENT}','{oSub.HSYSPRICE}','{oSub.HLIMITDOWNPRICE}','{oSub.HPARENTMATID}','{oSub.HROWTYPE}','{oSub.HROWID}','{oSub.HPARENTROWID}','{oSub.HDELIVERYCONTROL}','{oSub.HLOCALCURRID}','{oSub.HEXCHANGETYPEID}','{oSub.HSETTLECURRID}','{oSub.HSETTLEMODEID}','{oSub.HRECCONDITIONID}','{oSub.HISINCLUDEDTAX}','{oSub.HISPRICEEXCLUDETAX}','{oSub.HEXCHANGERATE}','{oSub.HTAXRATEID}','{oSub.HCOSTPERCENT}','{oSub.HVAT}','{oSub.HSELLERWITHHOLDING}','{oSub.HBUYERWITHHOLDING}','{oSub.HPRICELISTENTRY}')";
                    oCN.RunProc(sql);
                }
                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;
            }
        }
        #endregion
        #region [同步单据]
        [Route("Xs_SeOrderBill/Xs_SeOrderBillViewApi")]
        [HttpGet]
@@ -520,7 +599,7 @@
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "金蝶收料通知单同步失败jsonRoot:" + _result;
                        objJsonResult.Message = "金蝶销售订单同步失败jsonRoot:" + _result;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
@@ -753,5 +832,239 @@
        }
        #endregion
        #region 销售订单审核/反审核功能
        [Route("Xs_SeOrderBill/CheckXs_SeOrderBill")]
        [HttpGet]
        public object CheckXs_SeOrderBill(string HInterID, int Type, string user)
        {
            try
            {
                //判断是否有删除权限
                if (!DBUtility.ClsPub.Security_Log("Xs_SeOrderBill_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("Xs_SeOrderBill/CloseXs_SeOrderBill")]
        [HttpGet]
        public object CloseXs_SeOrderBill(string HInterID, int Type, string user)
        {
            try
            {
                //判断是否有删除权限
                if (!DBUtility.ClsPub.Security_Log("Xs_SeOrderBill_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("Xs_SeOrderBill/CancellXs_SeOrderBill")]
        [HttpGet]
        public object CancellXs_SeOrderBill(string HInterID, int Type, string user)
        {
            try
            {
                //判断是否有删除权限
                if (!DBUtility.ClsPub.Security_Log("Xs_SeOrderBill_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
    }
}