319 lines
13 KiB
C#
319 lines
13 KiB
C#
|
|
using FineUIPro;
|
|||
|
|
using Model;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text;
|
|||
|
|
|
|||
|
|
|
|||
|
|
namespace BLL
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
public static class TwInputmasterService
|
|||
|
|
{
|
|||
|
|
#region 获取列表
|
|||
|
|
/// <summary>
|
|||
|
|
/// 记录数
|
|||
|
|
/// </summary>
|
|||
|
|
public static int Count
|
|||
|
|
{
|
|||
|
|
get;
|
|||
|
|
set;
|
|||
|
|
}
|
|||
|
|
public static IQueryable<Model.Tw_InOutMasterOutput> GetModle(Model.Tw_InOutMasterOutput table)
|
|||
|
|
{
|
|||
|
|
var q = from x in Funs.DB.Tw_InputMaster
|
|||
|
|
join person in Funs.DB.Person_Persons on x.CreateMan equals person.PersonId into persons
|
|||
|
|
from person in persons.DefaultIfEmpty()
|
|||
|
|
join unit in Funs.DB.Base_Unit on x.ReqUnitId equals unit.UnitId into units
|
|||
|
|
from unit in units.DefaultIfEmpty()
|
|||
|
|
where
|
|||
|
|
(string.IsNullOrEmpty(table.Id) || x.Id.Contains(table.Id)) &&
|
|||
|
|
(string.IsNullOrEmpty(table.ProjectId) || x.ProjectId.Contains(table.ProjectId)) &&
|
|||
|
|
(string.IsNullOrEmpty(table.CusBillCode) || x.CusBillCode.Contains(table.CusBillCode)) &&
|
|||
|
|
(string.IsNullOrEmpty(table.WarehouseCode) || x.WarehouseCode.Contains(table.WarehouseCode)) &&
|
|||
|
|
(string.IsNullOrEmpty(table.CreateMan) || x.CreateMan.Contains(table.CreateMan)) &&
|
|||
|
|
(string.IsNullOrEmpty(table.ReqUnitId) || x.ReqUnitId.Contains(table.ReqUnitId)) &&
|
|||
|
|
(table.TypeInt == null || x.TypeInt == table.TypeInt) &&
|
|||
|
|
(table.Category == null || x.Category == table.Category) &&
|
|||
|
|
(table.State == null || x.State == table.State)
|
|||
|
|
select new Model.Tw_InOutMasterOutput
|
|||
|
|
{
|
|||
|
|
Id = x.Id,
|
|||
|
|
ProjectId = x.ProjectId,
|
|||
|
|
CusBillCode = x.CusBillCode,
|
|||
|
|
InOutPlanMasterId = x.InOutPlanMasterId,
|
|||
|
|
WarehouseCode = x.WarehouseCode,
|
|||
|
|
Source = x.Source,
|
|||
|
|
Category = x.Category,
|
|||
|
|
TypeInt = x.TypeInt,
|
|||
|
|
State = x.State,
|
|||
|
|
CreateMan = x.CreateMan,
|
|||
|
|
CreateManName = person.PersonName,
|
|||
|
|
CreateDate = x.CreateDate,
|
|||
|
|
ReqUnitId = x.ReqUnitId,
|
|||
|
|
ReqUnitName = unit.UnitName,
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
return q;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 获取分页列表
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="table"></param>
|
|||
|
|
/// <param name="grid1"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static IEnumerable GetListData(Model.Tw_InOutMasterOutput table, Grid grid1)
|
|||
|
|
{
|
|||
|
|
var q = GetModle(table);
|
|||
|
|
Count = q.Count();
|
|||
|
|
if (Count == 0)
|
|||
|
|
{
|
|||
|
|
return null;
|
|||
|
|
}
|
|||
|
|
var result = q.Skip(grid1.PageSize * grid1.PageIndex).Take(grid1.PageSize).ToList();
|
|||
|
|
// q = SortConditionHelper.SortingAndPaging(q, Grid1.SortField, Grid1.SortDirection, Grid1.PageIndex, Grid1.PageSize);
|
|||
|
|
return from x in result
|
|||
|
|
select new Model.Tw_InOutMasterOutput
|
|||
|
|
{
|
|||
|
|
Id = x.Id,
|
|||
|
|
ProjectId = x.ProjectId,
|
|||
|
|
CusBillCode = x.CusBillCode,
|
|||
|
|
InOutPlanMasterId = x.InOutPlanMasterId,
|
|||
|
|
WarehouseCode = x.WarehouseCode,
|
|||
|
|
Source = x.Source,
|
|||
|
|
TypeInt = x.TypeInt,
|
|||
|
|
State = x.State,
|
|||
|
|
CreateMan = x.CreateMan,
|
|||
|
|
CreateManName = x.CreateManName,
|
|||
|
|
CreateDate = x.CreateDate,
|
|||
|
|
ReqUnitId = x.ReqUnitId,
|
|||
|
|
ReqUnitName = x.ReqUnitName,
|
|||
|
|
Category = x.Category,
|
|||
|
|
CategoryString = TwConst.CategoryMap.FirstOrDefault(y => y.Value == x.Category).Key,
|
|||
|
|
TypeString = TwConst.TypeIntMap.FirstOrDefault(y => y.Value == x.TypeInt).Key,
|
|||
|
|
StateString = TwConst.StateMap.FirstOrDefault(y => y.Value == x.State).Key
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public static List<Tw_InOutMasterOutput> GetListData(Model.Tw_InOutMasterOutput table )
|
|||
|
|
{
|
|||
|
|
var q = GetModle(table);
|
|||
|
|
Count = q.Count();
|
|||
|
|
if (Count == 0)
|
|||
|
|
{
|
|||
|
|
return null;
|
|||
|
|
}
|
|||
|
|
var result = q.ToList();
|
|||
|
|
// q = SortConditionHelper.SortingAndPaging(q, Grid1.SortField, Grid1.SortDirection, Grid1.PageIndex, Grid1.PageSize);
|
|||
|
|
return (from x in result
|
|||
|
|
select new Model.Tw_InOutMasterOutput
|
|||
|
|
{
|
|||
|
|
Id = x.Id,
|
|||
|
|
ProjectId = x.ProjectId,
|
|||
|
|
CusBillCode = x.CusBillCode,
|
|||
|
|
InOutPlanMasterId = x.InOutPlanMasterId,
|
|||
|
|
WarehouseCode = x.WarehouseCode,
|
|||
|
|
Source = x.Source,
|
|||
|
|
TypeInt = x.TypeInt,
|
|||
|
|
State = x.State,
|
|||
|
|
CreateMan = x.CreateMan,
|
|||
|
|
CreateManName = x.CreateManName,
|
|||
|
|
CreateDate = x.CreateDate,
|
|||
|
|
ReqUnitId = x.ReqUnitId,
|
|||
|
|
ReqUnitName = x.ReqUnitName,
|
|||
|
|
Category = x.Category,
|
|||
|
|
CategoryString = TwConst.CategoryMap.FirstOrDefault(y => y.Value == x.Category).Key,
|
|||
|
|
TypeString = TwConst.TypeIntMap.FirstOrDefault(y => y.Value == x.TypeInt).Key,
|
|||
|
|
StateString = TwConst.StateMap.FirstOrDefault(y => y.Value == x.State).Key
|
|||
|
|
}).ToList();
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
public static Model.Tw_InputMaster GetById(string Id)
|
|||
|
|
{
|
|||
|
|
return Funs.DB.Tw_InputMaster.FirstOrDefault(x => x.Id == Id);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
public static void Add(Model.Tw_InputMaster newtable)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
Model.Tw_InputMaster table = new Model.Tw_InputMaster
|
|||
|
|
{
|
|||
|
|
Id = newtable.Id,
|
|||
|
|
ProjectId = newtable.ProjectId,
|
|||
|
|
InOutPlanMasterId = newtable.InOutPlanMasterId,
|
|||
|
|
CusBillCode = newtable.CusBillCode,
|
|||
|
|
WarehouseCode = newtable.WarehouseCode,
|
|||
|
|
Category = newtable.Category,
|
|||
|
|
Source = newtable.Source,
|
|||
|
|
TypeInt = newtable.TypeInt,
|
|||
|
|
State = newtable.State,
|
|||
|
|
CreateMan = newtable.CreateMan,
|
|||
|
|
CreateDate = newtable.CreateDate,
|
|||
|
|
ReqUnitId = newtable.ReqUnitId,
|
|||
|
|
};
|
|||
|
|
Funs.DB.Tw_InputMaster.InsertOnSubmit(table);
|
|||
|
|
Funs.DB.SubmitChanges();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public static void Update(Model.Tw_InputMaster newtable)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
Model.Tw_InputMaster table = Funs.DB.Tw_InputMaster.FirstOrDefault(x => x.Id == newtable.Id);
|
|||
|
|
if (table != null)
|
|||
|
|
{
|
|||
|
|
table.Id = newtable.Id;
|
|||
|
|
table.ProjectId = newtable.ProjectId;
|
|||
|
|
table.InOutPlanMasterId = newtable.InOutPlanMasterId;
|
|||
|
|
table.CusBillCode = newtable.CusBillCode;
|
|||
|
|
table.WarehouseCode = newtable.WarehouseCode;
|
|||
|
|
table.Category = newtable.Category;
|
|||
|
|
table.Source = newtable.Source;
|
|||
|
|
table.TypeInt = newtable.TypeInt;
|
|||
|
|
table.State = newtable.State;
|
|||
|
|
table.CreateMan = newtable.CreateMan;
|
|||
|
|
table.CreateDate = newtable.CreateDate;
|
|||
|
|
table.ReqUnitId = newtable.ReqUnitId;
|
|||
|
|
Funs.DB.SubmitChanges();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
public static void DeleteById(string Id)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
Model.Tw_InputMaster table = Funs.DB.Tw_InputMaster.FirstOrDefault(x => x.Id == Id);
|
|||
|
|
if (table != null)
|
|||
|
|
{
|
|||
|
|
Funs.DB.Tw_InputMaster.DeleteOnSubmit(table);
|
|||
|
|
Funs.DB.SubmitChanges();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 根据计划单生成入库单
|
|||
|
|
/// </summary>
|
|||
|
|
public static void GenInMasterByPlanId(string planId)
|
|||
|
|
{
|
|||
|
|
//获取计划单
|
|||
|
|
var planQueryModel = new Tw_InOutMasterOutput();
|
|||
|
|
planQueryModel.Id = planId;
|
|||
|
|
var plan = TwInOutplanmasterService.GetListData(planQueryModel).FirstOrDefault();
|
|||
|
|
if (plan == null || plan.State!= (int)TwConst.State.已审核)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
//判断是否已经生成过入库单
|
|||
|
|
var queryIsExitInMaster = new Tw_InOutMasterOutput();
|
|||
|
|
queryIsExitInMaster.InOutPlanMasterId = planId;
|
|||
|
|
queryIsExitInMaster.TypeInt = plan.TypeInt;
|
|||
|
|
queryIsExitInMaster.Category = plan.Category;
|
|||
|
|
var IsExitInMaster = GetModle(queryIsExitInMaster).FirstOrDefault();
|
|||
|
|
if (IsExitInMaster != null)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
//生成入库单
|
|||
|
|
var master = new Model.Tw_InputMaster()
|
|||
|
|
{
|
|||
|
|
Id = Guid.NewGuid().ToString(),
|
|||
|
|
InOutPlanMasterId = plan.Id,
|
|||
|
|
ProjectId = plan.ProjectId,
|
|||
|
|
WarehouseCode = plan.WarehouseCode,
|
|||
|
|
Source = plan.Source,
|
|||
|
|
TypeInt = plan.TypeInt,
|
|||
|
|
Category = plan.Category,
|
|||
|
|
State = (int)TwConst.State.已完成,
|
|||
|
|
CreateMan = plan.CreateMan,
|
|||
|
|
CreateDate = DateTime.Now,
|
|||
|
|
ReqUnitId = plan.ReqUnitId,
|
|||
|
|
};
|
|||
|
|
if ((TwConst.TypeInt)plan.TypeInt!= TwConst.TypeInt.采购入库)
|
|||
|
|
{
|
|||
|
|
master.CusBillCode = GetCusBillCodeByTaskCode(plan.WeldTaskCode, (TwConst.TypeInt)plan.TypeInt,
|
|||
|
|
(BLL.TwConst.Category)plan.Category);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
Add(master);
|
|||
|
|
//生成明细
|
|||
|
|
Tw_InOutDetailOutput query = new Tw_InOutDetailOutput();
|
|||
|
|
query.InOutPlanMasterId= planId;
|
|||
|
|
var details = TwInOutplandetailService.GetByModle(query).ToList();
|
|||
|
|
foreach (var detail in details)
|
|||
|
|
{
|
|||
|
|
var detailTable = new Model.Tw_InputDetail()
|
|||
|
|
{
|
|||
|
|
Id = Guid.NewGuid().ToString(),
|
|||
|
|
InputMasterId = master.Id,
|
|||
|
|
MaterialCode = detail.MaterialCode,
|
|||
|
|
PlanNum = detail.PlanNum,
|
|||
|
|
ActNum = detail.PlanNum,
|
|||
|
|
};
|
|||
|
|
TwInputdetailService.Add(detailTable);
|
|||
|
|
TwMaterialstockService.UpdateStockNum(master.ProjectId, detail.MaterialCode, master.WarehouseCode, TwConst.InOutType.入库, detailTable.ActNum);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
plan.State= (int)TwConst.State.已完成;
|
|||
|
|
TwInOutplanmasterService.Update(plan);
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 根据计划单撤销入库单
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="planId"></param>
|
|||
|
|
public static void RevokeGenInMasterByPlanId(string planId)
|
|||
|
|
{
|
|||
|
|
//校验计划单状态
|
|||
|
|
var plan = TwInOutplanmasterService.GetById(planId);
|
|||
|
|
if (plan == null || plan.State != (int)TwConst.State.已完成)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
//获取入库单
|
|||
|
|
Tw_InOutMasterOutput query = new Tw_InOutMasterOutput();
|
|||
|
|
query.InOutPlanMasterId = planId;
|
|||
|
|
var master = GetModle(query).FirstOrDefault();
|
|||
|
|
if (master == null)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
DeleteById(master.Id); //删除入库单
|
|||
|
|
//删除明细
|
|||
|
|
Tw_InOutDetailOutput queryDetail = new Tw_InOutDetailOutput();
|
|||
|
|
queryDetail.InputMasterId = master.Id;
|
|||
|
|
var details = TwInputdetailService.GetByModle(queryDetail).ToList();
|
|||
|
|
foreach (var detail in details)
|
|||
|
|
{
|
|||
|
|
TwInputdetailService.DeleteById(detail.Id);
|
|||
|
|
//撤销入库,即减去库存
|
|||
|
|
TwMaterialstockService.UpdateStockNum(master.ProjectId,detail.MaterialCode, master.WarehouseCode,TwConst.InOutType.出库, detail.ActNum);
|
|||
|
|
}
|
|||
|
|
plan.State = (int)TwConst.State.已审核;
|
|||
|
|
TwInOutplanmasterService.Update(plan);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
public static string GetCusBillCodeByTaskCode(string taskCode, TwConst.TypeInt typeInt, TwConst.Category category)
|
|||
|
|
{
|
|||
|
|
string cusBillCode = "";
|
|||
|
|
switch (typeInt)
|
|||
|
|
{
|
|||
|
|
case TwConst.TypeInt.退料入库:
|
|||
|
|
if (category == TwConst.Category.管段)
|
|||
|
|
{
|
|||
|
|
cusBillCode = taskCode + "-GI-P01-RE01";
|
|||
|
|
}
|
|||
|
|
else if (category == TwConst.Category.管件)
|
|||
|
|
{
|
|||
|
|
cusBillCode = taskCode + "-GI-PF01-RE01";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
return cusBillCode;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|