/// <summary> /// PDA提交JSON转换成List对象 /// </summary> /// <param name="ModelListJson"></param> /// <returns></returns> protected override List <T_InStockDetailInfo> GetModelListByJson(string UserJson, string ModelListJson) { LogNet.LogInfo("SaveT_InStockDetailADF---" + ModelListJson); int IsQuality = 0; string strUserNo = string.Empty; List <T_InStockDetailInfo> modelList = JSONHelper.JsonToObject <List <T_InStockDetailInfo> >(ModelListJson); UserModel user = JSONHelper.JsonToObject <UserModel>(UserJson); modelList.ForEach(t => t.ReceiveQty = t.ScanQty); modelList = modelList.Where(t => t.ReceiveQty > 0).ToList(); //IsQuality = GetIsQuality(modelList[0]); IsQuality = GetIsQualityByVoucherType(modelList[0]); string StrongHoldCode = ""; string StrongHoldCodeName = ""; T_WareHouse_DB TWareHouseDB = new T_WareHouse_DB(); TWareHouseDB.GetStrongholdcode(user.ReceiveWareHouseNo, ref StrongHoldCode, ref StrongHoldCodeName); modelList.ForEach(t => { t.IsQuality = IsQuality; foreach (var itemBarCode in t.lstBarCode) { //成品入库单做一个调拨的操作 if (t.VoucherType == 50) { T_Material_DB MaterialDB = new T_Material_DB(); itemBarCode.MaterialNoID = MaterialDB.GetMaterialNoid(itemBarCode.MaterialNo, "0300"); } else { T_Material_DB MaterialDB = new T_Material_DB(); itemBarCode.MaterialNoID = MaterialDB.GetMaterialNoid(itemBarCode.MaterialNo, StrongHoldCode); } } }); //if (TOOL.RegexMatch.isExists(user.UserNo) == true) //{ // strUserNo = user.UserNo.Substring(0, user.UserNo.Length - 1); //} //else //{ // strUserNo = user.UserNo; //} ////确定过账人,根据登录账户以及操作的订单据点来确定 //User_DB _db = new User_DB(); //string strPostUser = _db.GetPostAccountByUserNo(strUserNo, modelList[0].StrongHoldCode); foreach (var item in modelList) { if (item.lstBarCode != null && item.lstBarCode.Count() > 0) { item.SupPrdBatch = item.lstBarCode.FirstOrDefault().SupPrdBatch; item.SupPrdDate = item.lstBarCode.FirstOrDefault().SupPrdDate; item.StrSupPrdDate = item.lstBarCode.FirstOrDefault().SupPrdDate.ToShortDateString(); item.BatchNo = item.lstBarCode.FirstOrDefault().BatchNo; //item.IsSpcBatch=="Y"?item.FromBatchNo: item.lstBarCode.FirstOrDefault().BatchNo; item.ReceiveWareHouseNo = user.ReceiveWareHouseNo; item.ReceiveAreaNo = string.Empty; item.ReceiveUserNo = user.UserNo;// strPostUser; item.FromErpWarehouse = user.ReceiveWareHouseNo; item.ToErpAreaNo = string.Empty; item.ToBatchNo = item.BatchNo; //item.PostUser = user.UserNo; item.PostUser = user.UserName; item.StrEDate = item.lstBarCode.FirstOrDefault().EDate.ToString("yyyy/MM/dd"); } //item..PostDate = Convert.ToDateTime(DateTime.Now.ToString("yyyy/MM/dd")); } return(modelList); }
// 获取盘点库存信息 public JsonResult GetCheckStock(DividPage page, T_StockInfoEX model) { try { if (string.IsNullOrEmpty(model.WarehouseNo)) { return(Json(new { Result = 0, ResultValue = "仓库不能为空!" }, JsonRequestBehavior.AllowGet)); } T_WareHouse_DB TWareHouseDB = new T_WareHouse_DB(); string StrongHoldCode = ""; string StrongHoldCodeName = ""; TWareHouseDB.GetStrongholdcode(model.WarehouseNo, ref StrongHoldCode, ref StrongHoldCodeName); string strErrMsg = string.Empty; List <T_StockInfoEX> wms_stock = new List <T_StockInfoEX>(); Query_DB db = new Query_DB(); if (db.GetStockCombineInfo2(model, ref wms_stock, ref strErrMsg)) { if (wms_stock == null || wms_stock.Count == 0) { return(Json(new { Result = 0, ResultValue = "查询库存为空!" }, JsonRequestBehavior.AllowGet)); } T_Material_Batch_Func FUNC = new T_Material_Batch_Func(); List <U9Stock> erp_stock = FUNC.GetStockInfo(model.WarehouseNo, StrongHoldCode, model.MaterialNo); //wms数据和erp数据对账 for (int i = 0; i < wms_stock.Count; i++) { if (erp_stock != null && erp_stock.Count > 0) { for (int j = 0; j < erp_stock.Count; j++) { if (wms_stock[i].MaterialNo == erp_stock[j].MaterialNo && wms_stock[i].BatchNo == erp_stock[j].BatchNo) { wms_stock[i].U9MaterialNo = erp_stock[i].MaterialNo; wms_stock[i].U9BatchNo = erp_stock[i].BatchNo; wms_stock[i].U9Qty = erp_stock[j].Qty; erp_stock[j].IsAmount = 1; } } } } if (erp_stock != null && erp_stock.Count > 0) { //没匹配的u9数据 for (int i = 0; i < erp_stock.Count; i++) { if (erp_stock[i].IsAmount != 1) { wms_stock.Add(new T_StockInfoEX() { U9MaterialNo = erp_stock[i].MaterialNo, U9BatchNo = erp_stock[i].BatchNo, U9Qty = erp_stock[i].Qty, Qty = 0 }); } } } return(Json(new { Result = 1, Data = wms_stock }, JsonRequestBehavior.AllowGet)); } return(Json(new { Result = 0, ResultValue = strErrMsg }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { Result = 0, ResultValue = ex.ToString() }, JsonRequestBehavior.AllowGet)); } }
//保存盘点单 public JsonResult SaveCheck(T_StockInfoEX model) { try { if (string.IsNullOrEmpty(model.WarehouseNo)) { return(Json(new { state = false }, JsonRequestBehavior.AllowGet)); } T_WareHouse_DB TWareHouseDB = new T_WareHouse_DB(); string StrongHoldCode = ""; string StrongHoldCodeName = ""; TWareHouseDB.GetStrongholdcode(model.WarehouseNo, ref StrongHoldCode, ref StrongHoldCodeName); Check_DB checkdb = new Check_DB(); string ErrorMsg = ""; if (!checkdb.CheckIsSvae(model.MaterialNo, model.WarehouseNo, ref ErrorMsg)) { return(Json(new { state = false, ErrMsg = "待发或者待收库区有该物料不能生成盘点单!【" + ErrorMsg + "】" }, JsonRequestBehavior.AllowGet)); } string strErrMsg = string.Empty; List <T_StockInfoEX> lsttask = new List <T_StockInfoEX>(); Query_DB db = new Query_DB(); if (!db.GetStockCombineInfo2(model, ref lsttask, ref strErrMsg)) { return(Json(new { Result = 0, ErrMsg = strErrMsg }, JsonRequestBehavior.AllowGet)); } if (model.Check == "0") { //检验WMS库存和U9是否一致 T_Material_Batch_Func FUNC = new T_Material_Batch_Func(); List <U9Stock> erp_stock = FUNC.GetStockInfo(model.WarehouseNo, StrongHoldCode, model.MaterialNo); bool isOk = true; lsttask.ForEach(itemWMS => { if (erp_stock.FindAll(itemerp => { return(itemerp.MaterialNo == itemWMS.MaterialNo && itemerp.BatchNo == itemWMS.BatchNo && itemerp.Qty == itemWMS.Qty); }).Count != 1) { isOk = false; } }); if (!isOk) { return(Json(new { state = false, ErrMsg = "WMS库存和U9不匹配不能生成盘点单!" }, JsonRequestBehavior.AllowGet)); } } Check_Model cm = new Check_Model(); //cm.REMARKS = strremark + txt_remarkD.Text + txt_remark.Text; cm.CHECKSTATUS = "新建"; cm.CREATER = currentUser.UserNo; cm.CHECKDESC = "明盘"; string ErrMsg = ""; if (checkdb.SaveCheck2(cm, lsttask, ref ErrMsg)) { return(Json(new { state = true }, JsonRequestBehavior.AllowGet)); } return(Json(new { state = false }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { state = false, ErrMsg = ex.ToString() }, JsonRequestBehavior.AllowGet)); } }
protected override List <string> GetSaveModelListSql(UserModel user, List <T_InStockDetailInfo> modelList, string strPost = "") { string StrongHoldCode = ""; string StrongHoldCodeName = ""; T_WareHouse_DB TWareHouseDB = new T_WareHouse_DB(); TWareHouseDB.GetStrongholdcode(user.ReceiveWareHouseNo, ref StrongHoldCode, ref StrongHoldCodeName); string strSql1 = string.Empty; string strSql2 = string.Empty; string strSql3 = string.Empty; string strSql4 = string.Empty; string strSql5 = string.Empty; string strSql6 = string.Empty; string strSql7 = string.Empty; string strSql8 = string.Empty; string strSql9 = string.Empty; string strSql10 = string.Empty; string TaskNo = string.Empty; int TaskTransID = 0; if (modelList == null || modelList.Count == 0) { return(null); } if (modelList[0].VoucherType == 35) { return(null); } int taskid = base.GetTableIDBySqlServer("t_task");//GetTableID("seq_task_id"); List <string> lstSql = new List <string>(); if (modelList.Count() > 0) { //string TaskNoID = base.GetTableID("seq_task_no").ToString(); //TaskNo = "T" + System.DateTime.Now.ToString("yyyyMMdd") + TaskNoID.PadLeft(4, '0'); //string TaskNoID = base.GetTableIDBySqlServer("t_task").ToString(); TaskNo = base.GetNewOrderNo("D", "t_task", ""); modelList.ForEach(t => t.TaskNo = TaskNo); } else { modelList.ForEach(t => t.TaskNo = ""); } foreach (var item in modelList) { strSql1 = "update t_Instockdetail set Receiveqty = (isnull( Receiveqty,0) + '" + item.ScanQty + "') ," + " OPERATORUSERNO = '" + user.UserNo + "', Operatordatetime = getdate() , materialnoid = '" + item.MaterialNoID + "' where id ='" + item.ID + "'"; lstSql.Add(strSql1);// remainqty = (case when (isnull( remainqty,0) - '" + item.ScanQty + "') <= 0 then 0 else isnull( remainqty,0) - '" + item.ScanQty + "' end), strSql2 = "update t_Instockdetail set Linestatus = (case when isnull( Receiveqty,0)< isnull( Instockqty,0) and isnull( Receiveqty,0)<>0 then 2" + "when isnull( Receiveqty,0) >= isnull( Instockqty,0) then 3 end ) where id = '" + item.ID + "'"; lstSql.Add(strSql2); foreach (var itemBarCode in item.lstBarCode) { item.IsQuality = 3;//库存状态改为合格 //成品入库单做一个调拨的操作 if (modelList[0].VoucherType == 50) { //T_Material_DB MaterialDB = new T_Material_DB(); //int intMaterialnoid = MaterialDB.GetMaterialNoid(itemBarCode.MaterialNo, "0300"); strSql8 = "update t_stock set status='" + item.IsQuality + "', warehouseid= '" + user.WarehouseID + "',houseid='" + user.ReceiveHouseID + "',areaid='" + user.ReceiveAreaID + "',STRONGHOLDCODE='0300',STRONGHOLDNAME='营销中心',MATERIALNOID=" + itemBarCode.MaterialNoID + " where serialno='" + itemBarCode.SerialNo + "'"; } else { //T_Material_DB MaterialDB = new T_Material_DB(); //int intMaterialnoid = MaterialDB.GetMaterialNoid(itemBarCode.MaterialNo, StrongHoldCode); strSql8 = "insert into t_stock(spec,serialno,Materialno,materialdesc,qty,status,isdel,Creater,Createtime,batchno,unit,unitname,Palletno," + "islimitstock,materialnoid,warehouseid,houseid,areaid,Receivestatus,barcode,STRONGHOLDCODE,STRONGHOLDNAME,COMPANYCODE,EDATE,SUPCODE,SUPNAME," + "SUPPRDBATCH,Isquality,Stocktype,ean,BARCODETYPE,projectNo,TracNo,MaterialDoc)" + "values ('" + itemBarCode.spec + "','" + itemBarCode.SerialNo + "','" + itemBarCode.MaterialNo + "','" + itemBarCode.MaterialDesc + "','" + itemBarCode.Qty + "','" + item.IsQuality + "','1'" + ",'" + user.UserNo + "',getdate(),'" + itemBarCode.BatchNo + "','" + item.Unit + "','" + item.UnitName + "'" + ",(select palletno from t_Palletdetail where serialno = '" + itemBarCode.SerialNo + "'),'1','" + itemBarCode.MaterialNoID + "'" + ", '" + user.WarehouseID + "','" + user.ReceiveHouseID + "','" + user.ReceiveAreaID + "','1','" + itemBarCode.BarCode + "','" + StrongHoldCode + "', " + " '" + StrongHoldCodeName + "','" + itemBarCode.CompanyCode + "','" + itemBarCode.EDate + "','" + item.SupplierNo + "','" + item.SupplierName + "'," + "'" + itemBarCode.SupPrdBatch + "','3' ,'1','" + itemBarCode.EAN + "','" + itemBarCode.BarcodeType + "','" + (itemBarCode.ProjectNo == null ? "" : itemBarCode.ProjectNo) + "','" + (itemBarCode.TracNo == null ? "" : itemBarCode.TracNo) + "','" + modelList[0].MaterialDoc + "' )"; } lstSql.Add(strSql8); //TaskTransID = base.GetTableIDBySqlServerTaskTrans("t_tasktrans"); TaskTransID = 999999; strSql10 = "insert into t_tasktrans(id, Serialno,towarehouseid,Tohouseid, Toareaid, Materialno, Materialdesc, Supcuscode, " + "Supcusname, Qty, Tasktype, Vouchertype, Creater, Createtime,TaskdetailsId, Unit, Unitname,materialnoid," + "erpvoucherno,voucherno,barcode,STRONGHOLDCODE,STRONGHOLDNAME,COMPANYCODE,SUPPRDBATCH,EDATE,TASKNO,batchno,ToWarehouseNo,ToHouseNo,ToAreaNo,ToWarehouseName)" + " values ('" + TaskTransID + "','" + itemBarCode.SerialNo + "','" + user.WarehouseID + "','" + user.ReceiveHouseID + "'," + "'" + user.ReceiveAreaID + "','" + itemBarCode.MaterialNo + "','" + itemBarCode.MaterialDesc + "','" + item.SupplierNo + "','" + item.SupplierName + "'," + " '" + itemBarCode.Qty + "','4',(select top 1 vouchertype from t_Instock where voucherno = '" + item.VoucherNo + "') ,'" + user.UserName + "',getdate(),'" + item.ID + "'," + "'" + item.Unit + "','" + item.UnitName + "','" + itemBarCode.MaterialNoID + "','" + item.ErpVoucherNo + "','" + item.VoucherNo + "','" + itemBarCode.BarCode + "'," + "'" + StrongHoldCode + "','" + StrongHoldCodeName + "','" + item.CompanyCode + "','" + itemBarCode.SupPrdBatch + "'" + " ,'" + itemBarCode.EDate + "','" + TaskNo + "','" + itemBarCode.BatchNo + "','" + user.ReceiveWareHouseNo + "','" + user.ReceiveHouseNo + "','" + user.ReceiveAreaNo + "','" + user.ReceiveWareHouseName + "') "; lstSql.Add(strSql10); } } strSql3 = "update t_Instock set Status = 2 where id = '" + modelList[0].HeaderID + "'"; lstSql.Add(strSql3); strSql4 = " update t_Instock set Status = 3 where " + " id in(select b.Headerid from t_Instockdetail b group by b.Headerid having(max(isnull(linestatus,1)) = 3 and min(isnull(linestatus,1))=3) and b.Headerid = '" + modelList[0].HeaderID + "')" + "and id = '" + modelList[0].HeaderID + "'"; lstSql.Add(strSql4); //List<T_InStockDetailInfo> NewModelList = GroupInstockDetailList(modelList); 合并相同物料行 List <T_InStockDetailInfo> NewModelList = modelList;//不合并相同物料行 ////ymh 查询单据类型 //T_InStock_Func func = new T_InStock_Func(); //T_InStockInfo InStockInfoModel = new T_InStockInfo() { ID = modelList[0].HeaderID }; //string strmsg = ""; //func.GetModelByID(ref InStockInfoModel, ref strmsg); //是否生成上架任务的配置 //if (!(user.ISVWAREHOUSE == 0 && InStockInfoModel.VoucherType != 39)) if (!(user.ISVWAREHOUSE == 0 && modelList[0].VoucherType != 39)) { //汇总生成上架任务不汇总收货数据 foreach (var item in NewModelList) { //taskqty》QualityQty strSql6 = "insert into t_Taskdetails (headerid,Materialno,materialdesc,QualityQty,Remainqty,LineStatus,Creater,Createtime,Unit,Unitname,erpvoucherno,materialnoid,toareano,voucherno," + "STRONGHOLDCODE,STRONGHOLDNAME,COMPANYCODE,batchno,Productbatch,Supprdbatch,Frombatchno,Fromerpareano,Fromerpwarehouse,isdel,iarrsid,TracNo,ErpId)" + "values('" + taskid + "','" + item.MaterialNo + "','" + item.MaterialDesc + "','" + item.ScanQty + "','" + item.ScanQty + "'," + "'1','" + user.UserNo + "',getdate(),'" + item.Unit + "','" + item.UnitName + "','" + item.ErpVoucherNo + "','" + item.MaterialNoID + "','" + user.ReceiveAreaID + "','" + item.VoucherNo + "'," + "'" + item.StrongHoldCode + "','" + item.StrongHoldName + "','" + item.CompanyCode + "','" + item.BatchNo + "'," + "'" + item.ProductBatch + "','" + item.SupPrdBatch + "'," + "'" + item.BatchNo + "','" + user.ReceiveAreaNo + "','" + user.ReceiveWareHouseNo + "','1','" + item.iarrsid + "','" + item.TracNo + "','" + item.ErpId + "')"; lstSql.Add(strSql6); } if (NewModelList != null && NewModelList.Count() > 0) { //ymh到货单特殊处理,其他单据不过帐:Vouchertype strSql5 = "set IDENTITY_INSERT t_task on;insert into t_task (id,Vouchertype,tasktype,Taskno,Supcusname,status,Taskissued,Receiveuserno,Createtime,supcuscode,Creater,InStockID," + "erpvoucherno,plant,plantname,movetype,Taskissueduser,voucherno,STRONGHOLDCODE,STRONGHOLDNAME,COMPANYCODE,ERPCREATER,VOUDATE,VOUUSER,ERPSTATUS,ERPNOTE,erpinvoucherno,WAREHOUSEID,erpvouchertype,isdel,ErpId)" + "select '" + taskid + "', case Vouchertype when 39 then 39 else 888 end as Vouchertype,'1','" + TaskNo + "', Suppliername , '1',getdate(),'" + user.UserNo + "',getdate(), Supplierno,'" + user.UserNo + "', Id," + " Erpvoucherno, Plant, Plantname, Movetype,'" + user.UserNo + "',voucherno,STRONGHOLDCODE,STRONGHOLDNAME,COMPANYCODE,ERPCREATER,VOUDATE,VOUUSER,ERPSTATUS,ERPNOTE,'" + NewModelList[0].MaterialDoc + "'" + " ,'" + user.WarehouseID + "','" + modelList[0].ERPVoucherType + "','1',ErpId from t_Instock a where id = '" + modelList[0].HeaderID + "' set IDENTITY_INSERT t_task off;"; lstSql.Add(strSql5); } } return(lstSql); }