154 lines
7.9 KiB
C#
154 lines
7.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using FaKrosnoDataModel;
|
|
using SytelineSaAppDataModel;
|
|
|
|
namespace SynchronizeOrdersWithMissingQty
|
|
{
|
|
public static class Extensions
|
|
{
|
|
public static bool IsEqualTo(this ScheduleOrderDetail source, ScheduleOrderDetail other)
|
|
{
|
|
return source.ShipperProductCode == other.ShipperProductCode &&
|
|
source.SalesChannelProductCode == other.SalesChannelProductCode &&
|
|
source.ScheduleOrder.OrderID == other.ScheduleOrder.OrderID &&
|
|
source.RecipientCode == other.RecipientCode &&
|
|
source.ScheduleOrder.Recipient.PurchaserID == other.ScheduleOrder.Recipient.PurchaserID;
|
|
}
|
|
|
|
public static bool Have(this IList<ScheduleOrderDetail> source, ScheduleOrderDetail other)
|
|
{
|
|
return source.Any(x => x.IsEqualTo(other));
|
|
}
|
|
|
|
public static bool IsEqualTo(this PlannedQty plannedQty, ScheduleOrderDetailDetail other)
|
|
{
|
|
return plannedQty.ScheduleOrderDetail.ShipperProductCode == other.ScheduleOrderDetail.ShipperProductCode &&
|
|
plannedQty.ScheduleOrderDetail.SalesChannelProductCode ==
|
|
other.ScheduleOrderDetail.SalesChannelProductCode &&
|
|
plannedQty.ScheduleOrderDetail.ScheduleOrder.OrderID ==
|
|
other.ScheduleOrderDetail.ScheduleOrder.OrderID &&
|
|
plannedQty.RecipientCode == other.ScheduleOrderDetail.RecipientCode &&
|
|
plannedQty.Recipient.Purchaser.Id ==
|
|
other.ScheduleOrderDetail.ScheduleOrder.Recipient.Purchaser.Id &&
|
|
plannedQty.DateFrom.Date == other.DateFrom.Date && plannedQty.DateTo.Date == other.DateTo.Date;
|
|
}
|
|
|
|
public static bool Have(this IList<PlannedQty> plannedQuantities, ScheduleOrderDetailDetail other)
|
|
{
|
|
return plannedQuantities.Any(x => x.IsEqualTo(other));
|
|
}
|
|
|
|
public static bool IsEqualTo(this PlannedQty plannedQty, PlannedQty other)
|
|
{
|
|
return plannedQty.ScheduleOrderDetail.ShipperProductCode == other.ScheduleOrderDetail.ShipperProductCode &&
|
|
plannedQty.ScheduleOrderDetail.SalesChannelProductCode ==
|
|
other.ScheduleOrderDetail.SalesChannelProductCode &&
|
|
plannedQty.ScheduleOrderDetail.ScheduleOrder.OrderID ==
|
|
other.ScheduleOrderDetail.ScheduleOrder.OrderID &&
|
|
plannedQty.RecipientCode == other.ScheduleOrderDetail.RecipientCode &&
|
|
plannedQty.Recipient.Purchaser.Id ==
|
|
other.ScheduleOrderDetail.ScheduleOrder.Recipient.Purchaser.Id &&
|
|
plannedQty.DateFrom.Date == other.DateFrom.Date && plannedQty.DateTo.Date == other.DateTo.Date;
|
|
}
|
|
|
|
public static bool Have(this IList<PlannedQty> plannedQuantities, PlannedQty other)
|
|
{
|
|
return plannedQuantities.Any(x => x.IsEqualTo(other));
|
|
}
|
|
|
|
public static PlannedQty GeneratePlannedQty(this ScheduleOrderDetail scheduleOrderDetail,
|
|
DateTime plannedSendingDate, DateTime createdDate, IList<Recipient> recipients, int newPlannedNumber,
|
|
IList<CustomerTp> customers)
|
|
{
|
|
return new PlannedQty
|
|
{
|
|
DateFrom = plannedSendingDate,
|
|
DateTo = plannedSendingDate,
|
|
ScheduleOrderDetailId = scheduleOrderDetail.Id,
|
|
ScheduleOrderDetail = scheduleOrderDetail,
|
|
Recipient = scheduleOrderDetail.ScheduleOrder.Recipient,
|
|
LastUpdateDate = scheduleOrderDetail.ScheduleOrder.LastUpdateDate,
|
|
Qty = int.Parse(scheduleOrderDetail.ScheduleOrderDetailMisc.First(y => y.Type == "QTY_83" &&
|
|
DateTime.Parse(y.Label.Split(' ').Last()).Date == plannedSendingDate.Date).Value),
|
|
SccType = scheduleOrderDetail.ScheduleOrderDetailDetail.FirstOrDefault()?.SccType,
|
|
SccDesc = scheduleOrderDetail.ScheduleOrderDetailDetail.FirstOrDefault()?.SccDesc,
|
|
QtyType = scheduleOrderDetail.ScheduleOrderDetailDetail.FirstOrDefault()?.QtyType,
|
|
QtyDesc =
|
|
$"LATE: {scheduleOrderDetail.ScheduleOrderDetailDetail.FirstOrDefault()?.QtyDesc}",
|
|
Status = "new",
|
|
CreatedDate = createdDate,
|
|
RecipientCode = scheduleOrderDetail.RecipientCode,
|
|
RecipientId =
|
|
recipients.FirstOrDefault(x => x.RecipientCode == scheduleOrderDetail.RecipientCode)?.Id ??
|
|
scheduleOrderDetail.ScheduleOrder.Recipient.Id,
|
|
PlannedNumber = newPlannedNumber,
|
|
OrderId = scheduleOrderDetail.ScheduleOrder.OrderID,
|
|
CustomerCode = customers.FirstOrDefault(x => x.TpCode == scheduleOrderDetail.RecipientCode)
|
|
?.CustomerNumber
|
|
};
|
|
}
|
|
|
|
public static PlannedQty GeneratePlannedQty(this ScheduleOrderDetailDetail scheduleOrderDetailDetail,
|
|
DateTime plannedSendingDate, DateTime createdDate, IList<Recipient> recipients, int newPlannedNumber,
|
|
IList<CustomerTp> customers)
|
|
{
|
|
return new PlannedQty
|
|
{
|
|
DateFrom = plannedSendingDate,
|
|
DateTo = plannedSendingDate,
|
|
ScheduleOrderDetailId = scheduleOrderDetailDetail.ScheduleOrderDetail.Id,
|
|
ScheduleOrderDetail = scheduleOrderDetailDetail.ScheduleOrderDetail,
|
|
Recipient = scheduleOrderDetailDetail.ScheduleOrderDetail.ScheduleOrder.Recipient,
|
|
LastUpdateDate = scheduleOrderDetailDetail.ScheduleOrderDetail.ScheduleOrder.LastUpdateDate,
|
|
Qty = scheduleOrderDetailDetail.Qty,
|
|
SccType = scheduleOrderDetailDetail.SccType,
|
|
SccDesc = scheduleOrderDetailDetail.SccDesc,
|
|
QtyType = scheduleOrderDetailDetail.QtyType,
|
|
QtyDesc = scheduleOrderDetailDetail.QtyDesc,
|
|
Status = "new",
|
|
CreatedDate = createdDate,
|
|
RecipientCode = scheduleOrderDetailDetail.ScheduleOrderDetail.RecipientCode,
|
|
RecipientId =
|
|
recipients.FirstOrDefault(x =>
|
|
x.RecipientCode == scheduleOrderDetailDetail.ScheduleOrderDetail.RecipientCode)?.Id ??
|
|
scheduleOrderDetailDetail.ScheduleOrderDetail.ScheduleOrder.Recipient.Id,
|
|
PlannedNumber = newPlannedNumber,
|
|
OrderId = scheduleOrderDetailDetail.ScheduleOrderDetail.ScheduleOrder.OrderID,
|
|
CustomerCode = customers
|
|
.FirstOrDefault(x => x.TpCode == scheduleOrderDetailDetail.ScheduleOrderDetail.RecipientCode)
|
|
?.CustomerNumber
|
|
};
|
|
}
|
|
|
|
public static PlannedQty GenerateCopy(this PlannedQty plannedQty, DateTime plannedSendingDate,
|
|
DateTime createdDate, int newPlannedNumber)
|
|
{
|
|
return new PlannedQty
|
|
{
|
|
DateFrom = plannedSendingDate,
|
|
DateTo = plannedSendingDate,
|
|
ScheduleOrderDetailId = plannedQty.ScheduleOrderDetailId,
|
|
ScheduleOrderDetail = plannedQty.ScheduleOrderDetail,
|
|
Recipient = plannedQty.Recipient,
|
|
LastUpdateDate = plannedQty.LastUpdateDate,
|
|
Qty = plannedQty.Qty,
|
|
SccType = plannedQty.SccType,
|
|
SccDesc = plannedQty.SccDesc,
|
|
QtyType = plannedQty.QtyType,
|
|
QtyDesc = plannedQty.QtyDesc,
|
|
Status = "new",
|
|
CreatedDate = createdDate,
|
|
RecipientCode = plannedQty.RecipientCode,
|
|
RecipientId = plannedQty.RecipientId,
|
|
PlannedNumber = newPlannedNumber,
|
|
OrderId = plannedQty.OrderId,
|
|
CustomerCode = plannedQty.CustomerCode
|
|
};
|
|
}
|
|
}
|
|
}
|