367 lines
16 KiB
C#
367 lines
16 KiB
C#
using FineUIPro;
|
|
using Model;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
|
|
namespace BLL
|
|
{
|
|
/// <summary>
|
|
/// 入库单逻辑层
|
|
/// </summary>
|
|
public static class TwOutputmasterService
|
|
{
|
|
#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_OutputMaster
|
|
join y in Funs.DB.Tw_InOutPlanMaster on x.InOutPlanMasterId equals y.Id into yy
|
|
from y in yy.DefaultIfEmpty()
|
|
//join z in Funs.DB.HJGL_WeldTask on y.WeldTaskId equals z.WeldTaskId into zz
|
|
//from z in zz.DefaultIfEmpty()
|
|
join person in Funs.DB.Person_Persons on x.CreateMan equals person.PersonId into persons
|
|
from person in persons.DefaultIfEmpty()
|
|
join auditperson in Funs.DB.Person_Persons on x.AuditMan equals auditperson.PersonId into auditpersons
|
|
from auditperson in auditpersons.DefaultIfEmpty()
|
|
join warehouseperson in Funs.DB.Person_Persons on x.WarehouseMan equals warehouseperson.PersonId into warehousepersons
|
|
from warehouseperson in warehousepersons.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.InOutPlanMasterId) || x.InOutPlanMasterId .Contains(table.InOutPlanMasterId)) &&
|
|
(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)) &&
|
|
(string.IsNullOrEmpty(table.UnitWorkId) || y.WeldTaskId.Contains(table.UnitWorkId)) &&
|
|
(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,
|
|
Category = x.Category,
|
|
Source = x.Source,
|
|
TypeInt = x.TypeInt,
|
|
State = x.State,
|
|
CreateMan = x.CreateMan,
|
|
CreateManName = person.PersonName,
|
|
CreateDate = x.CreateDate,
|
|
ReqUnitId = x.ReqUnitId,
|
|
ReqUnitName = unit.UnitName,
|
|
WeldTaskId = y.WeldTaskId,
|
|
AuditMan = x.AuditMan,
|
|
AuditManName = auditperson.PersonName,
|
|
AuditDate = x.AuditDate,
|
|
WarehouseMan = x.WarehouseMan,
|
|
WarehouseDate = x.WarehouseDate,
|
|
WarehouseManName = warehouseperson.PersonName
|
|
};
|
|
|
|
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();
|
|
return from x in result
|
|
select new Model.Tw_InOutMasterOutput
|
|
{
|
|
Id = x.Id,
|
|
ProjectId = x.ProjectId,
|
|
CusBillCode = x.CusBillCode,
|
|
WarehouseCode = x.WarehouseCode,
|
|
InOutPlanMasterId = x.InOutPlanMasterId,
|
|
Source = x.Source,
|
|
TypeInt = x.TypeInt,
|
|
State = x.State,
|
|
Category= x.Category,
|
|
CreateMan = x.CreateMan,
|
|
CreateManName = x.CreateManName,
|
|
CreateDate = x.CreateDate,
|
|
ReqUnitId = x.ReqUnitId,
|
|
ReqUnitName = x.ReqUnitName,
|
|
TypeString = TwConst.TypeIntMap.FirstOrDefault(y => y.Value == x.TypeInt).Key,
|
|
StateString = TwConst.StateMap.FirstOrDefault(y => y.Value == x.State).Key,
|
|
CategoryString = TwConst.CategoryMap.FirstOrDefault(y => y.Value == x.Category).Key,
|
|
WeldTaskId = x.WeldTaskId,
|
|
WeldTaskCode = x.WeldTaskId != null ? x.WeldTaskId.Contains('|') ? Funs.DB.HJGL_WeldTask.FirstOrDefault(e => e.UnitWorkId == x.WeldTaskId.Split('|')[0].ToString() && e.UnitId == x.WeldTaskId.Split('|')[1].ToString() && e.TaskDate.Value.Date == Convert.ToDateTime(x.WeldTaskId.Split('|')[2].ToString()).Date)?.TaskCode : "" : "",
|
|
AuditMan = x.AuditMan,
|
|
AuditManName = x.AuditManName,
|
|
AuditDate = x.AuditDate,
|
|
WarehouseMan = x.WarehouseMan,
|
|
WarehouseManName = x.WarehouseManName,
|
|
WarehouseDate = x.WarehouseDate
|
|
|
|
};
|
|
}
|
|
|
|
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();
|
|
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,
|
|
Category = x.Category,
|
|
CreateMan = x.CreateMan,
|
|
CreateManName = x.CreateManName,
|
|
CreateDate = x.CreateDate,
|
|
ReqUnitId = x.ReqUnitId,
|
|
ReqUnitName = x.ReqUnitName,
|
|
TypeString = TwConst.TypeIntMap.FirstOrDefault(y => y.Value == x.TypeInt).Key,
|
|
StateString = TwConst.StateMap.FirstOrDefault(y => y.Value == x.State).Key,
|
|
CategoryString = TwConst.CategoryMap.FirstOrDefault(y => y.Value == x.Category).Key,
|
|
WeldTaskId = x.WeldTaskId,
|
|
WeldTaskCode = x.WeldTaskId != null ? x.WeldTaskId.Contains('|') ? Funs.DB.HJGL_WeldTask.FirstOrDefault(e => e.UnitWorkId == x.WeldTaskId.Split('|')[0].ToString() && e.UnitId == x.WeldTaskId.Split('|')[1].ToString() && e.TaskDate.Value.Date == Convert.ToDateTime(x.WeldTaskId.Split('|')[2].ToString()).Date)?.TaskCode : "" : "",
|
|
AuditMan = x.AuditMan,
|
|
AuditManName = x.AuditManName,
|
|
AuditDate = x.AuditDate,
|
|
WarehouseMan = x.WarehouseMan,
|
|
WarehouseManName = x.WarehouseManName,
|
|
WarehouseDate = x.WarehouseDate
|
|
|
|
}).ToList();
|
|
}
|
|
|
|
#endregion
|
|
|
|
public static Model.Tw_OutputMaster GetTw_OutputMasterById(string Id)
|
|
{
|
|
return Funs.DB.Tw_OutputMaster.FirstOrDefault(x => x.Id == Id);
|
|
}
|
|
|
|
public static void Add(Model.Tw_OutputMaster newtable)
|
|
{
|
|
|
|
Model.Tw_OutputMaster table = new Model.Tw_OutputMaster
|
|
{
|
|
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,
|
|
AuditMan = newtable.AuditMan,
|
|
AuditDate = newtable.AuditDate,
|
|
WarehouseMan = newtable.WarehouseMan,
|
|
WarehouseDate = newtable.WarehouseDate,
|
|
};
|
|
Funs.DB.Tw_OutputMaster.InsertOnSubmit(table);
|
|
Funs.DB.SubmitChanges();
|
|
}
|
|
|
|
public static void Update(Model.Tw_OutputMaster newtable)
|
|
{
|
|
|
|
Model.Tw_OutputMaster table = Funs.DB.Tw_OutputMaster.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;
|
|
table.AuditMan = newtable.AuditMan;
|
|
table.AuditDate = newtable.AuditDate;
|
|
table.WarehouseMan = newtable.WarehouseMan;
|
|
table.WarehouseDate = newtable.WarehouseDate;
|
|
Funs.DB.SubmitChanges();
|
|
}
|
|
|
|
}
|
|
public static void DeleteById(string Id)
|
|
{
|
|
|
|
Model.Tw_OutputMaster table = Funs.DB.Tw_OutputMaster.FirstOrDefault(x => x.Id == Id);
|
|
if (table != null)
|
|
{
|
|
Funs.DB.Tw_OutputMaster.DeleteOnSubmit(table);
|
|
Funs.DB.SubmitChanges();
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据计划单生成出库单
|
|
/// </summary>
|
|
public static void GenOutMasterByPlanId(string planId, List<Model.Tw_OutputDetail> detailLists)
|
|
{
|
|
//获取出库单
|
|
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;
|
|
var IsExitInMaster = GetModle(queryIsExitInMaster).FirstOrDefault();
|
|
if (IsExitInMaster != null)
|
|
{
|
|
return;
|
|
}
|
|
//生成出库单
|
|
var master = new Model.Tw_OutputMaster()
|
|
{
|
|
Id = Guid.NewGuid().ToString(),
|
|
InOutPlanMasterId = plan.Id,
|
|
ProjectId = plan.ProjectId,
|
|
CusBillCode = GetCusBillCodeByTaskCode(plan.WeldTaskCode, (TwConst.TypeInt)plan.TypeInt, (BLL.TwConst.Category)plan.Category),
|
|
WarehouseCode = plan.WarehouseCode,
|
|
Category = plan.Category,
|
|
Source = plan.Source,
|
|
TypeInt = plan.TypeInt,
|
|
State = (int)TwConst.State.已完成,
|
|
CreateMan = plan.CreateMan,
|
|
CreateDate = plan.CreateDate,
|
|
ReqUnitId = plan.ReqUnitId,
|
|
AuditMan = plan.AuditMan,
|
|
AuditDate = plan.AuditDate,
|
|
WarehouseMan = plan.WarehouseMan,
|
|
WarehouseDate = plan.WarehouseDate
|
|
};
|
|
Add(master);
|
|
//生成出库单明细
|
|
foreach (var detail in detailLists)
|
|
{
|
|
var detailTable = new Model.Tw_OutputDetail()
|
|
{
|
|
Id = Guid.NewGuid().ToString(),
|
|
OutputMasterId = master.Id,
|
|
MaterialCode = detail.MaterialCode,
|
|
PlanNum = detail.PlanNum,
|
|
ActNum = detail.ActNum,
|
|
};
|
|
TwOutputdetailService.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 string RevokeGenOutMasterByPlanId(string planId)
|
|
{
|
|
string result = "";
|
|
Tw_InOutMasterOutput query = new Tw_InOutMasterOutput();
|
|
query.InOutPlanMasterId = planId;
|
|
var master = GetModle(query).FirstOrDefault();
|
|
if (master == null)
|
|
{
|
|
result = "未找到对应的出库单";
|
|
return result;
|
|
}
|
|
DeleteById(master.Id); //删除出库单
|
|
//删除明细
|
|
Tw_InOutDetailOutput queryDetail = new Tw_InOutDetailOutput();
|
|
queryDetail.OutputMasterId = master.Id;
|
|
var details = TwOutputdetailService.GetByModle(queryDetail).ToList();
|
|
foreach (var detail in details)
|
|
{
|
|
TwOutputdetailService.DeleteById(detail.Id);
|
|
//撤销出库,即增加库存
|
|
TwMaterialstockService.UpdateStockNum(master.ProjectId, detail.MaterialCode, master.WarehouseCode, TwConst.InOutType.入库, detail.ActNum);
|
|
}
|
|
var planModel= TwInOutplanmasterService.GetById(planId);
|
|
planModel.State= (int)TwConst.State.已审核;
|
|
TwInOutplanmasterService.Update(planModel);
|
|
return result;
|
|
}
|
|
|
|
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";
|
|
}
|
|
else if (category == TwConst.Category.管件)
|
|
{
|
|
cusBillCode = taskCode + "-GI-PF01";
|
|
}
|
|
|
|
break;
|
|
case TwConst.TypeInt.补料出库:
|
|
if (category == TwConst.Category.管段)
|
|
{
|
|
cusBillCode = taskCode + "-GI-P01-SI01";
|
|
}
|
|
else if (category == TwConst.Category.管件)
|
|
{
|
|
cusBillCode = taskCode + "-GI-PF01-SI01";
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
return cusBillCode;
|
|
}
|
|
|
|
|
|
}
|
|
} |