SGGL_SHJ/SGGL/BLL/CLGL/TwInputmasterService.cs

373 lines
16 KiB
C#
Raw Normal View History

2024-09-18 10:48:34 +08:00
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()
2024-09-24 20:38:50 +08:00
join auditperson in Funs.DB.Person_Persons on x.AuditMan equals auditperson.PersonId into auditpersons
from auditperson in auditpersons.DefaultIfEmpty()
2024-11-07 16:22:03 +08:00
join warehouseperson in Funs.DB.Person_Persons on x.WarehouseMan equals warehouseperson.PersonId into warehousepersons
from warehouseperson in warehousepersons.DefaultIfEmpty()
2024-09-18 10:48:34 +08:00
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)) &&
2024-09-24 20:38:50 +08:00
(string.IsNullOrEmpty(table.InOutPlanMasterId) || x.InOutPlanMasterId.Contains(table.InOutPlanMasterId)) &&
2024-09-18 10:48:34 +08:00
(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,
2024-09-24 20:38:50 +08:00
ReqUnitName = unit.UnitName,
AuditMan = x.AuditMan,
AuditManName = auditperson.PersonName,
AuditDate = x.AuditDate,
2024-11-07 16:22:03 +08:00
Remark = x.Remark,
WarehouseMan = x.WarehouseMan,
WarehouseManName = warehouseperson.PersonName,
WarehouseDate = x.WarehouseDate
2024-09-18 10:48:34 +08:00
};
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,
2024-09-24 20:38:50 +08:00
StateString = TwConst.StateMap.FirstOrDefault(y => y.Value == x.State).Key,
AuditMan = x.AuditMan,
AuditManName = x.AuditManName,
AuditDate = x.AuditDate,
2024-11-07 16:22:03 +08:00
Remark=x.Remark,
WarehouseMan = x.WarehouseMan,
WarehouseDate = x.WarehouseDate,
WarehouseManName= x.WarehouseManName
2024-09-18 10:48:34 +08:00
};
}
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,
2024-09-24 20:38:50 +08:00
StateString = TwConst.StateMap.FirstOrDefault(y => y.Value == x.State).Key,
AuditMan = x.AuditMan,
AuditManName = x.AuditManName,
AuditDate = x.AuditDate,
2024-11-07 16:22:03 +08:00
Remark = x.Remark,
WarehouseMan = x.WarehouseMan,
WarehouseDate = x.WarehouseDate,
WarehouseManName= x.WarehouseManName
2024-09-18 10:48:34 +08:00
}).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,
2024-09-24 20:38:50 +08:00
AuditMan= newtable.AuditMan,
AuditDate = newtable.AuditDate,
2024-11-07 16:22:03 +08:00
Remark = newtable.Remark,
WarehouseMan= newtable.WarehouseMan,
WarehouseDate = newtable.WarehouseDate
2024-09-18 10:48:34 +08:00
};
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;
2024-09-24 20:38:50 +08:00
table.AuditMan = newtable.AuditMan;
table.AuditDate = newtable.AuditDate;
table.Remark = newtable.Remark;
2024-11-07 16:22:03 +08:00
table.WarehouseMan = newtable.WarehouseMan;
table.WarehouseDate = newtable.WarehouseDate;
2024-09-18 10:48:34 +08:00
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>
2024-09-27 18:17:21 +08:00
public static void GenInMasterByPlanId(string planId, List<Model.Tw_InputDetail> detailLists,string remark)
2024-09-18 10:48:34 +08:00
{
//获取计划单
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,
2024-11-07 16:22:03 +08:00
CreateDate = plan.CreateDate,
2024-09-18 10:48:34 +08:00
ReqUnitId = plan.ReqUnitId,
2024-11-07 16:22:03 +08:00
AuditMan = plan.AuditMan,
2024-09-24 20:38:50 +08:00
AuditDate = plan.AuditDate,
2024-11-07 16:22:03 +08:00
Remark= remark,
WarehouseMan = plan.WarehouseMan,
WarehouseDate = plan.WarehouseDate
2024-09-18 10:48:34 +08:00
};
2025-02-18 17:38:49 +08:00
master.CusBillCode = GetCusBillCode(plan.WeldTaskCode, (TwConst.TypeInt)plan.TypeInt,
(BLL.TwConst.Category)plan.Category, plan.CusBillCode);
2024-09-18 10:48:34 +08:00
Add(master);
//生成明细
2024-09-24 20:38:50 +08:00
foreach (var detail in detailLists)
2024-09-18 10:48:34 +08:00
{
var detailTable = new Model.Tw_InputDetail()
{
Id = Guid.NewGuid().ToString(),
InputMasterId = master.Id,
MaterialCode = detail.MaterialCode,
2024-09-24 20:38:50 +08:00
PlanNum = detail.PlanNum,
ActNum = detail.ActNum,
SortIndex = detail.SortIndex,
2024-09-18 10:48:34 +08:00
};
2024-09-24 20:38:50 +08:00
TwInputdetailService.Add(detailTable);
TwMaterialstockService.UpdateStockNum(master.ProjectId, detail.MaterialCode, master.WarehouseCode, TwConst.InOutType., detailTable.ActNum);
2024-09-18 10:48:34 +08:00
}
var planTable =TwInOutplanmasterService.GetById(plan.Id);
if (planTable != null)
{
planTable.State = (int)TwConst.State.;
TwInOutplanmasterService.Update(planTable);
}
2024-09-18 10:48:34 +08:00
}
/// <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);
}
2025-02-18 17:38:49 +08:00
/// <summary>
/// 获取入库单编号
/// </summary>
/// <param name="taskCode"></param>
/// <param name="typeInt"></param>
/// <param name="category"></param>
/// <returns></returns>
/// <param name="planCusBillCode"></param>
public static string GetCusBillCode(string taskCode, TwConst.TypeInt typeInt, TwConst.Category category, string planCusBillCode = "")
2024-09-18 10:48:34 +08:00
{
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";
}
2025-02-18 17:38:49 +08:00
break;
case TwConst.TypeInt.:
cusBillCode = planCusBillCode.Replace("-AP-", "-GI-");
break;
case TwConst.TypeInt.:
cusBillCode = planCusBillCode.Replace("-AP", ""); ;
2024-09-18 10:48:34 +08:00
break;
}
return cusBillCode;
}
}
}