WebAPI/Controllers/XSGL/Xs_ExceptiveCheckRequestBillController.cs
@@ -37,14 +37,14 @@
            {
                List<object> columnNameList = new List<object>();
                //查看权限
                //if (!DBUtility.ClsPub.Security_Log("Gy_ProjectStage_Query", 1, false, user))
                //{
                //    objJsonResult.code = "0";
                //    objJsonResult.count = 0;
                //    objJsonResult.Message = "无查看权限!";
                //    objJsonResult.data = null;
                //    return objJsonResult;
                //}
                if (!DBUtility.ClsPub.Security_Log("Xs_ExceptiveCheckRequestBill_Query", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无查看权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (sWhere == null || sWhere.Equals(""))
                {
@@ -217,7 +217,15 @@
                }
                //进行 会计期间 结账 的判断和控制
                int sYear = 0;
                int sPeriod = 0;
                DateTime HDate = DateTime.Now;
                if (DBUtility.Xt_BaseBillFun.Fun_AllowYearPeriod(HDate, ref sYear, ref sPeriod, ref s) == false)
                {
                    objJsonResult.Message = s;
                    return objJsonResult;
                }
                //保存
                //保存完毕后处理
@@ -350,6 +358,16 @@
                    return objJsonResult;
                }
                //进行 会计期间 结账 的判断和控制
                int sYear = 0;
                int sPeriod = 0;
                DateTime HDate = DateTime.Now;
                if (DBUtility.Xt_BaseBillFun.Fun_AllowYearPeriod(HDate, ref sYear, ref sPeriod, ref s) == false)
                {
                    objJsonResult.Message = s;
                    return objJsonResult;
                }
                oCN.BeginTran();
                oCN.RunProc("delete from Xs_ExceptiveCheckRequestBillMain where HInterID = " + HInterID);
@@ -359,7 +377,7 @@
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.Message = "您已删除单据号为" + BillOld.omodel.HBillNo + "的特批申请单!";
                objJsonResult.data = null;
                return objJsonResult;
            }
@@ -468,15 +486,96 @@
                //进行需要进行的审核/反审核操作
                if (IsAudit == 0) //审核提交
                {
                    //进行 会计期间 结账 的判断和控制
                    string s = "";
                    int sYear = 0;
                    int sPeriod = 0;
                    DateTime HDate = DateTime.Now;
                    if (DBUtility.Xt_BaseBillFun.Fun_AllowYearPeriod(HDate, ref sYear, ref sPeriod, ref s) == false)
                    {
                        objJsonResult.Message = s;
                        return objJsonResult;
                    }
                    oCN.BeginTran();
                    //检验源单是否存在
                    string sql = "";
                    if(oBill.omodel.HMainSourceBillType == "1401")
                    {
                        sql = "select * from Xs_SeOrderBillMain as a " +
                        "inner join Xs_SeOrderBillSub as b on a.HInterID = b.HInterID " +
                        "where a.HInterID = " + oBill.omodel.HMainSourceInterID;
                        ds = oCN.RunProcReturn(sql, "Xs_SeOrderBill");
                        if (ds == null || ds.Tables[0].Rows.Count == 0)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "审核失败!原因:源单-销售订单不存在!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        else if (int.Parse(ds.Tables[0].Rows[0]["HBillStatus"].ToString()) > 1)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "审核失败!原因:源单-销售订单未处于创建状态!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                    }
                    else if(oBill.omodel.HMainSourceBillType == "1205")
                    {
                        sql = "select * from Kf_ICStockBillMain as a " +
                        "inner join Kf_ICStockBillSub as b on a.HInterID = b.HInterID " +
                        "where a.HInterID = " + oBill.omodel.HMainSourceInterID;
                        ds = oCN.RunProcReturn(sql, "Kf_ICStockBill");
                        if (ds == null || ds.Tables[0].Rows.Count == 0)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "审核失败!原因:源单-销售出库单不存在!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        else if (int.Parse(ds.Tables[0].Rows[0]["HBillStatus"].ToString()) > 1)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "审核失败!原因:源单-销售出库单未处于创建状态!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                    }
                    else if (oBill.omodel.HMainSourceBillType == "1425")
                    {
                        objJsonResult = AuditXs_ExceptiveCheckRequestBill_CheckSeOrderChangeBill(oBill.omodel.HMainSourceInterID);
                        if (objJsonResult.code != "1")
                        {
                            return objJsonResult;
                        }
                        //反写销售订单数据
                        sql = "exec h_p_IF_SeOrderBill_ReWriteBySeOrderChangeBill " + oBill.omodel.HMainSourceInterID;
                        oCN.RunProc(sql);
                    }
                    else
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "审核失败!原因:源单不明确!!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    //反写源单单据状态
                    string sql = "exec h_p_Xs_ExceptiveCheckRequestBill_ReWriteSourceStatus " + oBill.omodel.HMainSourceInterID + ",'" + oBill.omodel.HMainSourceBillType + "','" + CurUserName + "'";
                    sql = "exec h_p_Xs_ExceptiveCheckRequestBill_ReWriteSourceStatus " + oBill.omodel.HMainSourceInterID + ",'" + oBill.omodel.HMainSourceBillType + "','" + CurUserName + "'";
                    oCN.RunProc(sql);
                    if (oBill.CheckBill(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo) == true)
                    {
                    {
                        oCN.Commit();
                        objJsonResult.code = "1";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "审核成功";
@@ -496,6 +595,18 @@
                }
                if (IsAudit == 1) //反审核提交
                {
                    //进行 会计期间 结账 的判断和控制
                    string s = "";
                    int sYear = 0;
                    int sPeriod = 0;
                    DateTime HDate = DateTime.Now;
                    if (DBUtility.Xt_BaseBillFun.Fun_AllowYearPeriod(HDate, ref sYear, ref sPeriod, ref s) == false)
                    {
                        objJsonResult.Message = s;
                        return objJsonResult;
                    }
                    //反审核提交AbandonCheck
                    if (oBill.AbandonCheck(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo) == true)
                    {
@@ -527,6 +638,115 @@
                return objJsonResult;
            }
        }
        #region 审核特批申请单反写销售订单变更单状态数据检验
        public json AuditXs_ExceptiveCheckRequestBill_CheckSeOrderChangeBill(long HInterID)
        {
            try
            {
                Int64 lngBillKey = 0;
                lngBillKey = DBUtility.ClsPub.isLong(HInterID);                                         //对HInterID进行类型的转换
                DAL.ClsXs_SeOrderChangeBill oBill = new DAL.ClsXs_SeOrderChangeBill();                  //销售订单变更单实例化单据操作类,用于进行相关操作
                DAL.ClsXs_SeOrderBill oBillSource = new DAL.ClsXs_SeOrderBill();                        //销售订单实例化单据操作类,用于进行相关操作
                //针对需要进行的操作,检验当前单据的状态是否支持需要进行的操作
                if (oBill.ShowBill(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo))                    //根据HInterID获取销售订单变更单单据的数据
                {
                    if (!oBillSource.ShowBill(oBill.DetailColl[0].HSourceInterID, ref DBUtility.ClsPub.sExeReturnInfo))  //判断销售订单变更单的源单-销售订单是否存在并获取数据
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "审核失败!原因:源单-销售订单变更单的源单-销售订单不存在!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    if (oBill.omodel.HBillStatus > 1)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "审核失败!原因:源单-销售订单变更单不为‘创建’状态!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    if (oBillSource.omodel.HBillStatus != 2)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "审核失败!原因:源单-销售订单变更单的源单-销售订单不为‘已审核’状态!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    //检验子表数据
                    string errorMessage = "";
                    DateTime today = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));                   //当日日期
                    double HRelationQty = 0;                                                                //源单-销售订单关联数量(销售出库数量)
                    foreach (Model.ClsXs_SeOrderChangeBillSub oSub in oBill.DetailColl)
                    {
                        string sql = "select * from Xs_SeOrderBillSub where HInterID = " + oSub.HSourceInterID + " and HEntryID = " + oSub.HSourceEntryID;
                        ds = oCN.RunProcReturn(sql, "Xs_SeOrderBillSub");
                        if (ds.Tables[0].Rows.Count == 0)
                        {
                            errorMessage += "源单-销售订单变更单:第" + oSub.HEntryID + "行物料在源单-销售订单中不存在!";
                        }
                        else
                        {
                            //获取销售订单变更单中对应物料在源单-销售订单中的关联数量
                            HRelationQty = double.Parse(ds.Tables[0].Rows[0]["HRelationQty"].ToString());
                            //判断物料新数量是否小于源单单据中对应物料的关联数量
                            if (oSub.HQty_New < HRelationQty)
                            {
                                errorMessage += "源单-销售订单变更单:第" + oSub.HEntryID + "行物料新数量小于源单-销售订单被关联数量!";
                            }
                            //判断新交货日期是否早于当日
                            if (oSub.HDate_New.CompareTo(today) < 0)
                            {
                                errorMessage += "源单-销售订单变更单:第" + oSub.HEntryID + "行新交货日期早于当日!";
                            }
                        }
                    }
                    if (errorMessage != "")
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "审核失败!原因:" + errorMessage;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = null;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    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
        #endregion
        #region 特批申请单 关闭/反关闭