using System;
using System.Data.Entity;
using System.Linq;
using System.Threading.Tasks;
using Abp.Domain.Repositories;
using IwbZero.Helper;
using ShwasherSys.CompanyInfo;
using ShwasherSys.Inspection;
using ShwasherSys.Order;
namespace ShwasherSys
{
///
/// 订单类型
///
public class OrderTypeDefinition
{
///
/// 内销
///
public const int InSale = 1;
///
/// 外销
///
public const int OutSale = 2;
///
/// 换货
///
public const int Exchange = 3;
public static async Task GetNewOrderNo(IRepository orderHeaderRepository)
{
string lcRetVal = "";
DateTime loTemp = DateTime.Parse(DateTime.Now.Year + "-" + DateTime.Now.Month + "-01");
loTemp = loTemp.AddSeconds(-1);
var order =await orderHeaderRepository.GetAll().Where(i => i.TimeCreated > loTemp).OrderByDescending(i => i.Id).FirstOrDefaultAsync();
if (order!=null)
{
int liTempNo = 0;
liTempNo = Convert.ToInt32(order.Id);
liTempNo++;
lcRetVal = liTempNo.ToString();
if (lcRetVal.Length < 10)
{
lcRetVal = "0" + lcRetVal;
}
}
else
{
DateTime loDate = DateTime.Today;
int liMonth = loDate.Date.Month;
string lcMonth = liMonth < 10 ? "0" + liMonth : liMonth.ToString();
lcRetVal = loDate.Date.Year + lcMonth + "0001";
}
return lcRetVal;
}
}
///
/// 产品类型定义
///
public class ProductTypeDefinition
{
///
/// 半成品
///
public const int Semi = 2;
///
/// 成品
///
public const int Finish = 1;
public static async Task GetDisProductNo(IRepository repository,int type)
{
string startNo = $"{DateTime.Now:yyMMdd}";
var lastEntity = await repository.GetAll().Where(a => a.DisqualifiedNo.StartsWith(startNo)).OrderByDescending(a => a.Id)
.FirstOrDefaultAsync();
int noLength = 4, index = 0;
if (lastEntity != null)
{
var entityNo = lastEntity.DisqualifiedNo;
index = Convert.ToInt32(entityNo.Substring(entityNo.Length - noLength));
}
index++;
string no = $"{startNo}{type}{index.LeftPad(noLength)}";
if ((await repository.CountAsync(a=>a.DisqualifiedNo==no)) > 0)
{
no = await GetDisProductNo(repository,type);
}
return no;
}
}
public class DisProductStateDefinition
{
///
/// 未处理
///
public const int NoHandle = 1;
///
/// 降级使用
///
public const int Downgrade = 2;
///
/// 报废处理
///
public const int Scrapped = 3;
///
/// 不报废降级
///
public const int ScrappedDowngrade = 4;
///
/// 返工反镀
///
public const int AntiPlating = 5;
///
/// 正常退货(无需检验)
///
public const int NormalReturn = 6;
///
/// 已降级
///
public const int DowngradeHandled = 8;
///
/// 已报废
///
public const int ScrappedHandled = 9;
///
/// 外购退货
///
public const int OutPurchaseReturnGood = 10;
///
/// 特殊采购(特采)
///
public const int SpecialPurchase = 11;
}
public class LicenseTypeDefinition
{
///
/// 公司证照
///
public const string Company = "公司证照";
///
/// 员工证照
///
public const string Employee = "员工证照";
///
/// 设备证照
///
public const string Device = "设备证照";
///
/// 文书存档
///
public const string Document = "文书存档";
///
/// 其他
///
public const string Other = "其他";
}
///
/// 维护设备类型
///
public class MaintainTypeDefinition
{
///
/// 模具
///
public const int Mold = 1;
///
/// 设备
///
public const int Device = 2;
///
/// 其他
///
public const int Other = 3;
public static async Task GetMoldNo(IRepository repository)
{
string startNo = "SDA";
var lastEntity = await repository.GetAll().Where(a => a.No.StartsWith(startNo)).OrderByDescending(a => a.Id)
.FirstOrDefaultAsync();
int noLength=6,index = 0;
if (lastEntity!=null)
{
var entityNo = lastEntity.No;
index = Convert.ToInt32(entityNo.Substring(entityNo.Length - noLength));
}
index++;
string no = $"{startNo}{index.LeftPad(noLength)}";
if ((await repository.CountAsync(a=>a.No==no)) > 0)
{
no = await GetMoldNo(repository);
}
return no;
}
public static async Task GetDeviceNo(IRepository repository)
{
string startNo = "SDB";
var lastEntity = await repository.GetAll().Where(a => a.No.StartsWith(startNo)).OrderByDescending(a => a.Id)
.FirstOrDefaultAsync();
int noLength=6,index = 0;
if (lastEntity!=null)
{
var entityNo = lastEntity.No;
index = Convert.ToInt32(entityNo.Substring(entityNo.Length - noLength));
}
index++;
string no = $"{startNo}{index.LeftPad(noLength)}";
if ((await repository.CountAsync(a=>a.No==no)) > 0)
{
no = await GetDeviceNo(repository);
}
return no;
}
public static async Task GetDeviceMgPlanNo(IRepository repository,int type)
{
string typeStr = type == 1 ? "SDA" : type == 2 ? "SDB" : "SDZ";
string startNo = $"{typeStr}{DateTime.Now:yyMMdd}";
var lastEntity = await repository.GetAll().Where(a => a.No.StartsWith(startNo)).OrderByDescending(a => a.Id)
.FirstOrDefaultAsync();
int noLength=4,index = 0;
if (lastEntity!=null)
{
var entityNo = lastEntity.No;
index = Convert.ToInt32(entityNo.Substring(entityNo.Length - noLength));
}
index++;
string no = $"{startNo}{index.LeftPad(noLength)}";
if ((await repository.CountAsync(a=>a.No==no)) > 0)
{
no = await GetDeviceMgPlanNo(repository,type);
}
return no;
}
public static async Task GetMaintainRecordNo(IRepository repository,int type)
{
string startNo = $"{DateTime.Now:yyMM}";
var lastEntity = await repository.GetAll().Where(a => a.Id.StartsWith(startNo)).OrderByDescending(a => a.Id)
.FirstOrDefaultAsync();
int noLength=5,index = 0;
if (lastEntity!=null)
{
var entityNo = lastEntity.Id;
index = Convert.ToInt32(entityNo.Substring(entityNo.Length - noLength));
}
index++;
string no = $"{startNo}{type}{index.LeftPad(noLength)}";
if ((await repository.CountAsync(a=>a.Id==no)) > 0)
{
no = await GetMaintainRecordNo(repository,type);
}
return no;
}
}
///
/// 维护记录状态
///
public class MaintainStateDefinition
{
///
/// 新建
///
public const int New = 1;
///
/// 开始
///
public const int Start = 2;
///
/// 完成
///
public const int Complete = 3;
///
/// 结束
///
public const int End = 4;
public static string GetTypeName(int type)
{
var str = "";
switch (type)
{
case 1:
str = "新建";
break;
case 2:
str = "开始";
break;
case 3:
str = "完成";
break;
case 4:
str = "结束";
break;
}
return str;
}
}
public class WorkTypeDefinition
{
///
/// 生产
///
public const int Product = 1;
///
/// 包装
///
public const int Package = 2;
///
/// 包装核件
///
public const int VerifyPackage = 3;
///
/// 模具维护
///
public const int MoldMg = 4;
///
/// 设备维护
///
public const int DeviceMg = 5;
public static string GetWorkTypeName(int type)
{
var str = "";
switch (type)
{
case 1:
str = "车间生产";
break;
case 2:
str = "包装负责";
break;
case 3:
str = "包装核件";
break;
case 4:
str = "模具维护";
break;
case 5:
str = "设备维护";
break;
}
return str;
}
public static async Task GetPerformanceNo(IRepository repository,int type)
{
string startNo = $"{DateTime.Now:yyMMdd}";
var lastEntity = await repository.GetAll().Where(a => a.PerformanceNo.StartsWith(startNo)).OrderByDescending(a => a.Id)
.FirstOrDefaultAsync();
int noLength=5,index = 0;
if (lastEntity!=null)
{
var entityNo = lastEntity.PerformanceNo;
index = Convert.ToInt32(entityNo.Substring(entityNo.Length - noLength));
}
index++;
string no = $"{startNo}{type}{index.LeftPad(noLength)}";
if ((await repository.CountAsync(a=>a.PerformanceNo==no)) > 0)
{
no = await GetPerformanceNo(repository,type);
}
return no;
}
}
public class InspectConfirmStateDefinition
{
///
/// 未确认
///
public const int New = 1;
///
/// 已确认
///
public const int Confirm = 2;
public static async Task GetReportNo(IRepository repository)
{
string startNo = $"{DateTime.Now:yyMM}";
var lastEntity = await repository.GetAll().Where(a => a.ProductInspectReportNo.StartsWith(startNo)&& a.ProductInspectReportNo.Length<20).OrderByDescending(a => a.Id)
.FirstOrDefaultAsync();
int noLength = 6, index = 0;
if (lastEntity != null)
{
var entityNo = lastEntity.ProductInspectReportNo;
index = Convert.ToInt32(entityNo.Substring(entityNo.Length - noLength));
}
index++;
string no = $"{startNo}{index.LeftPad(noLength)}";
if ((await repository.CountAsync(a=>a.ProductInspectReportNo==no)) > 0)
{
no = await GetReportNo(repository);
}
return no;
}
}
public class StoreHouseType
{
///
/// 成品仓库
///
public const int Finish = 1;
///
/// 半成品仓库
///
public const int SemiFinish = 2;
///
/// 原材料仓库
///
public const int Rm = 3;
}
//1:新建 2:盘点中 3:盘点完成 4:取消关闭
public class InventoryCheckState
{
public const int New = 1;
public const int Checking = 2;
public const int Finish = 3;
public const int Closed = 4;
}
//1:生产检验不合格 2:退货检验不合格
public class DisqualifiedType
{
public const int ProductionCheck = 1;
public const int ReturnCheck = 2;
}
///
/// 退货/换货
///
public class ReturnGoodType
{
public const int Return = 1;
public const int Change = 2;
}
///
/// 退货单状态
///
public class ReturnGoodStateDefinition
{
///
/// 新建
///
public const int New = 1;
///
/// 检验中
///
public const int Check = 2;
///
/// 已检验
///
public const int HasChecked = 3;
///
/// 申请退款
///
public const int RefundApply = 4;
///
/// 确认退款
///
public const int RefundConfirm = 5;
///
/// 结束
///
public const int End = 9;
}
///
///发票类型
///
public class InvoiceTypeDefinition
{
///
/// 正常发票
///
public const int Normal = 0;
///
/// 红冲发票(退款)
///
public const int RedReturn = 1;
///
/// 红冲发票(少收)
///
public const int RedLess = 2;
///
/// 红冲发票(多收)
///
public const int RedOver = 3;
}
///
/// 订单明细紧急程度
///
public class OrderItemEmergencyLevel
{
///
/// 正常(默认)
///
public const int Normal = 1;
///
/// 紧急
///
public const int Urge = 2;
///
/// 延期
///
public const int Delay = 3;
}
}