using Admin.NET.Core;
|
using Admin.NET.Core.QualityControl.Enum;
|
using Admin.NET.Core.WareHouse.Enum;
|
using iWareSql.MyDbContext;
|
using System;
|
using System.Collections.Generic;
|
using System.Globalization;
|
using System.Linq;
|
|
namespace Admin.NET.Application
|
{
|
public class MyCommonHelper
|
{
|
|
/// <summary>
|
/// 生产配餐单备注计划生产月 转换日期格式,/将 格式ddmm 转换为日期类型
|
/// </summary>
|
/// <param name="str"></param>
|
/// <returns></returns>
|
public static DateTime ConvertToDateTimeForDDMMByKittingRemark(string str)
|
{
|
try
|
{
|
//将 格式dd/mm/yyyy 转换为日期类型
|
str = str.Trim();
|
if (str.Length != 6)//牧野约定备注日期填6位罗马数字 比如:202403
|
{
|
throw new System.Exception($"日期类型格式不正确,应该是长度6位的年月罗马数字,实际是{str}!");
|
}
|
var year = str.Substring(0, 4); //前4位是年纷
|
var month = str.Substring(str.Length - 2);//后两位是月份
|
|
int i_month, i_year = 0;
|
bool isSu = int.TryParse(month, out i_month);
|
if (isSu == false)
|
{
|
throw new System.Exception($"月'{month}'格式不正确!");
|
}
|
isSu = int.TryParse(year, out i_year);
|
if (isSu == false)
|
{
|
throw new System.Exception($"年'{year}'格式不正确!");
|
}
|
|
|
if (i_month < 1 || i_month > 12)
|
{
|
throw new System.Exception($"月'{i_month}'不在正确范围内!");
|
}
|
|
|
string dateString = string.Format("{0}-{1}",//得到日期字符串
|
year, month);
|
|
|
DateTime result = DateTime.ParseExact(dateString, "yyyy-MM", CultureInfo.InvariantCulture);
|
return result;
|
}
|
catch (Exception ex)
|
{
|
|
throw new System.Exception($"日期{str}转换异常:" + ex.Message);
|
}
|
}
|
|
/// <summary>
|
/// 获取展示用的生产配餐单备注计划生产月字符串
|
/// </summary>
|
/// <param name="PlannedProductionYear"></param>
|
/// <param name="PlannedProductionMonth"></param>
|
/// <returns></returns>
|
public static string GetPlannedProductionDate(int PlannedProductionYear, int PlannedProductionMonth)
|
{
|
if (PlannedProductionYear > 0 && PlannedProductionMonth > 0)
|
{
|
string year = PlannedProductionYear.ToString();
|
string month = PlannedProductionMonth.ToString();
|
if (month.Length == 1) // 单月前面补全0
|
{
|
month = "0" + month;
|
}
|
return month + "-" + year;
|
}
|
|
|
return string.Empty;
|
}
|
|
/// <summary>
|
/// 根据物料编号获取物料基础信息 【Editby shaocx,2023-07-25】
|
/// </summary>
|
/// <param name="_ware_materialRep"></param>
|
/// <param name="materialCode"></param>
|
/// <returns></returns>
|
public static ware_material GetWareMaterialInfo(MyDbContext dbContext, string materialCode)
|
{
|
var material = dbContext.ware_material.Where(x => x.Code == materialCode).FirstOrDefault();
|
if (material == null)
|
{
|
throw new System.Exception($"物料基础信息没有找到物料编号为{materialCode}的信息!");
|
}
|
return material;
|
}
|
|
/// <summary>
|
/// 根据物料编号获取物料基础信息 【Editby shaocx,2023-07-25】
|
/// </summary>
|
/// <param name="_ware_materialRep"></param>
|
/// <param name="materialCode"></param>
|
/// <returns></returns>
|
public static ware_material GetWareMaterialInfo( List<ware_material> _list, string materialCode)
|
{
|
var material = _list.Where(x => x.Code == materialCode).FirstOrDefault();
|
if (material == null)
|
{
|
throw new System.Exception($"物料基础信息没有找到物料编号为{materialCode}的信息!");
|
}
|
return material;
|
}
|
|
/// <summary>
|
/// 根据物料编号获取物料基础信息 【Editby shaocx,2023-07-25】
|
/// </summary>
|
/// <param name="_ware_materialRep"></param>
|
/// <param name="materialCode"></param>
|
/// <returns></returns>
|
public static List<ware_material> GetWareMaterialInfoList(MyDbContext dbContext)
|
{
|
var material = dbContext.ware_material.ToList();
|
return material;
|
}
|
|
/// <summary>
|
/// 获取发货记录 不能用于撤销
|
/// </summary>
|
/// <param name="ware_material"></param>
|
/// <param name="_deliveryOrderDetails"></param>
|
/// <param name="records"></param>
|
/// <param name="orderNo"></param>
|
/// <param name="sortingNo"></param>
|
/// <param name="equipment"></param>
|
/// <param name="process"></param>
|
/// <param name="img"></param>
|
/// <param name="deliveryRecordInput"></param>
|
/// <returns></returns>
|
public static WareDeliveryInfo GetWareDeliveryRecord(
|
MyDbContext dbContext,
|
ref List<ware_common_sap_delivery_info> ware_common_sap_delivery_infos,
|
ware_material ware_material,
|
List<ware_container_vs_material> records,
|
string orderNo,
|
string sortingNo,
|
string equipment,
|
string process,
|
string img, ware_orders_details ordersDetail)
|
{
|
List<ware_delivery_record> ware_delivery_records = new List<ware_delivery_record>();
|
|
WareDeliveryInfo returnInfo = new WareDeliveryInfo();
|
|
returnInfo.WareDeliveryRecords = new List<ware_delivery_record>();
|
|
var orderType = SysAllOrderTypeEnum.生产出库单;
|
foreach (var item in records)
|
{
|
long Id = Yitter.IdGenerator.YitIdHelper.NextId();
|
|
var ware_delivery_record = new ware_delivery_record()
|
{
|
Id = Id,
|
MaterialCode = ordersDetail.WareMaterialCode,
|
MaterialName = ware_material.Name,
|
Quantity = (decimal)item.Quantity,
|
OrderNo = orderNo,
|
BatchNo = item.BarNo,
|
Sap_Location = item.Sap_Location,
|
SortingNo = sortingNo,
|
Equipment = equipment,
|
Process = process,
|
OrderType = (int)orderType,
|
Unit = ware_material.Unit,//单位
|
LineNumber = ordersDetail.LineNumber,//行号
|
SAP_ConfirmStatus = (int)EnumSAPConfirmStatus.待发送,
|
SAP_CancelConfirmStatus = (int)EnumSAPCancelConfirmStatus.未撤销,
|
//这两个字段必须赋值!
|
OrderDetailId = ordersDetail.Id,//订单详情id
|
//SortOrderDetailId = deliveryRecordInput.SortOrderDetailId,
|
MaterialResvItem = ordersDetail.MaterialResvItem,//Kitting 单预约行号
|
MaterialResvNo = ordersDetail.MaterialResvNo,//Kitting 单预约号
|
SubOrderNo = ordersDetail.SubOrderNo,//Kitting 单号
|
ImgPath = img,
|
CancelStatus = (int)EnumCancelStatus.未撤销,//默认未撤销
|
//增加一些事项 【Editby shaocx,2023-08-02】
|
CheckStatus = item.CheckStatus,
|
SupplierNo = item.SupplierNo,
|
SupplierName = item.SupplierName,
|
PurchaseOrderDetailId = item.PurchaseOrderDetailId,
|
RecordInsertTime = item.RecordInsertTime,
|
|
|
|
Costcenter = ordersDetail.Costcenter//成本中心
|
|
};
|
ware_delivery_records.Add(ware_delivery_record);
|
|
DO_GetWareDeliveryInfo(ref ware_common_sap_delivery_infos, orderType, ware_material, ordersDetail, ware_delivery_record);
|
}
|
returnInfo.WareDeliveryRecords.AddRange(ware_delivery_records);
|
|
return returnInfo;
|
}
|
|
|
#region 根据发货记录创建sap推送发货记录
|
|
/// <summary>
|
/// 根据发货记录创建sap推送发货记录 可以用于撤销-DeliveryOrderDetails
|
/// </summary>
|
/// <param name="ware_common_sap_delivery_infos"></param>
|
/// <param name="orderType"></param>
|
/// <param name="ware_material"></param>
|
/// <param name="ordersDetail"></param>
|
/// <param name="ware_delivery_record"></param>
|
public static void DO_GetWareDeliveryInfo(ref List<ware_common_sap_delivery_info> ware_common_sap_delivery_infos, SysAllOrderTypeEnum orderType, ware_material ware_material,
|
ware_orders_details ordersDetail, ware_delivery_record ware_delivery_record)
|
{
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
}
|