Added CustomerEdiTranslate and new way to get CustomerOrderNumber. Added CustomerOrderLine, EdiCustomerOrderTranslate to SytelineSaAppDataModel

This commit is contained in:
2023-01-02 17:32:59 +01:00
parent f14867d0dc
commit 822d7e3535
8 changed files with 368 additions and 26 deletions

View File

@@ -54,21 +54,7 @@ namespace ClientEdiOrdersGenerator.DataProvider
throw;
}
}
public EdiOrderTranslation CreateEdiOrderTranslation(ScheduleOrder scheduleOrder, string status,
string logMessage)
{
return new EdiOrderTranslation
{
ScheduleOrderId = scheduleOrder.Id,
CreatedDate = DateTime.Now,
LastUpdateDate = scheduleOrder.LastUpdateDate,
LogData = logMessage,
ItemsCount = scheduleOrder.ScheduleOrderDetail.Count,
Status = status
};
}
public ISet<int> GetErrorSalesOrderIds()
{
return _faKrosnoDataContext.EdiOrderTranslations.Where(x => x.Status == "Error")

View File

@@ -1,4 +1,5 @@
using System;
using FaKrosnoDataModel;
using System;
using System.Collections.Generic;
using System.Data.Entity.Validation;
using System.Linq;
@@ -74,6 +75,20 @@ namespace ClientEdiOrdersGenerator.DataProvider
?.RowPointer;
}
public IList<CustomerOrder> GetCustomerOrders(string customerNumber, int customerSequenceNumber,
string customerPo)
{
return _sytelineSaAppDataContext.CustomerOrders.Where(x =>
x.CustomerNumber == customerNumber && x.CustomerSequenceNumber == customerSequenceNumber &&
x.CustomerPoNumber == customerPo && x.Status.ToUpper() == "O").ToList();
}
public IList<CustomerOrderLine> GeCustomerOrderLines(string customerOrderNumber)
{
return _sytelineSaAppDataContext.CustomerOrderLines.Where(x => x.CustomerOrderNumber == customerOrderNumber)
.ToList();
}
public int RemoveEdiOrder(EdiCustomerOrder ediCustomerOrder)
{
_sytelineSaAppDataContext.EdiCustomerOrders.Remove(ediCustomerOrder);
@@ -109,5 +124,30 @@ namespace ClientEdiOrdersGenerator.DataProvider
throw;
}
}
public void SaveEdiOrderTranslations(IList<EdiCustomerOrderTranslate> ediCustomerOrderTranslations)
{
_sytelineSaAppDataContext.EdiCustomerOrderTranslations.AddRange(ediCustomerOrderTranslations);
try
{
_sytelineSaAppDataContext.SaveChanges();
}
catch (DbEntityValidationException e)
{
foreach (var eve in e.EntityValidationErrors)
{
Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
eve.Entry.Entity.GetType().Name, eve.Entry.State);
foreach (var ve in eve.ValidationErrors)
{
Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage);
}
}
throw;
}
}
}
}

View File

@@ -20,7 +20,7 @@ namespace ClientEdiOrdersGenerator.Steps.SendOrders
CustomerNumber = customerTp.CustomerNumber,
Type = "B",
CustomerSequence = customerTp.CustomerSequenceNumber,
EstimatedNumber = null,
EstimatedNumber = orderNumber,
CustomerPoNumber = $"{scheduleOrder.PoNum:0000000}",
TransactionCode = "BPO",
Phone = customer.Phone1,

View File

@@ -1,6 +1,7 @@
using ClientEdiOrdersGenerator.DataProvider;
using FaKrosnoDataModel;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using SytelineSaAppDataModel;
@@ -22,7 +23,8 @@ namespace ClientEdiOrdersGenerator.Steps.SendOrders
IList<EdiCustomerOrderLine> ediCustomerOrderLines = new List<EdiCustomerOrderLine>();
IList<EdiCustomerOrderLineItem> ediCustomerOrderLineItems = new List<EdiCustomerOrderLineItem>();
IList<EdiOrderTranslation> ediOrderTranslations = new List<EdiOrderTranslation>();
IList<EdiCustomerOrderTranslate> ediCustomerOrderTranslations = new List<EdiCustomerOrderTranslate>();
FaKrosnoDataProvider faKrosnoDataProvider = new FaKrosnoDataProvider(new FaKrosnoDataContext());
SytelineDataProvider sytelineDataProvider = new SytelineDataProvider(new SytelineSaAppDataContext());
@@ -53,7 +55,7 @@ namespace ClientEdiOrdersGenerator.Steps.SendOrders
if (customerTp == null)
{
scheduleOrdersByRecipient.ToList().ForEach(x =>
ediOrderTranslations.Add(faKrosnoDataProvider.CreateEdiOrderTranslation(x, "Error",
ediOrderTranslations.Add(CreateEdiOrderTranslation(x, "Error",
$"Dla klienta {scheduleOrdersByRecipient.Key.RecipientDesc} brakuje rekordu w bazie 'cust_tp'")));
continue;
@@ -64,7 +66,7 @@ namespace ClientEdiOrdersGenerator.Steps.SendOrders
if (customer == null)
{
scheduleOrdersByRecipient.ToList().ForEach(x =>
ediOrderTranslations.Add(faKrosnoDataProvider.CreateEdiOrderTranslation(x, "Error",
ediOrderTranslations.Add(CreateEdiOrderTranslation(x, "Error",
$"Dla klienta {scheduleOrdersByRecipient.Key.RecipientDesc} brakuje rekordu w bazie 'customer'")));
continue;
}
@@ -83,8 +85,7 @@ namespace ClientEdiOrdersGenerator.Steps.SendOrders
if (removedCounter == 0)
{
ediOrderTranslations.Add(faKrosnoDataProvider.CreateEdiOrderTranslation(scheduleOrder,
"Error",
ediOrderTranslations.Add(CreateEdiOrderTranslation(scheduleOrder, "Error",
$"Istnieje już zamówienie {scheduleOrder.Id}/{scheduleOrder.PoNum}/{scheduleOrder.Recipient.RecipientDesc} w bazie 'edi_co'. Błąd przy usuwaniu!"));
continue;
@@ -105,7 +106,7 @@ namespace ClientEdiOrdersGenerator.Steps.SendOrders
if (customerOrderRowPointer != null)
{
ediOrderTranslations.Add(faKrosnoDataProvider.CreateEdiOrderTranslation(scheduleOrder, "Error",
ediOrderTranslations.Add(CreateEdiOrderTranslation(scheduleOrder, "Error",
$"Istnieje już zamówienie {scheduleOrder.Id}/{scheduleOrder.PoNum}/{scheduleOrder.Recipient.RecipientDesc} w bazie 'co', które nie jest EDI"));
continue;
@@ -160,12 +161,20 @@ namespace ClientEdiOrdersGenerator.Steps.SendOrders
.Where(x => x.CustomerOrderNumber == ediCustomerOrder.CustomerOrderNumber)
.Sum(x => x.QtyOrdered * x.Price);
EdiCustomerOrderTranslate ediCustomerOrderTranslate = GenerateEdiCustomerOrderTranslate(customerTp,
scheduleOrder, sytelineDataProvider, ediCustomerOrder.CustomerOrderNumber);
ediCustomerOrders.Add(ediCustomerOrder);
ediOrderTranslations.Add(faKrosnoDataProvider.CreateEdiOrderTranslation(scheduleOrder,
"Exportowane", "Eksport zakończony poprawnie"));
ediOrderTranslations.Add(CreateEdiOrderTranslation(scheduleOrder, "Exportowane",
"Eksport zakończony poprawnie"));
if (ediCustomerOrderTranslate != null)
{
ediCustomerOrderTranslations.Add(ediCustomerOrderTranslate);
}
}
}
if (ediCustomerOrders.Any())
{
sytelineDataProvider.SaveData(ediCustomerOrders, ediCustomerOrderLines, ediCustomerOrderLineItems);
@@ -175,6 +184,76 @@ namespace ClientEdiOrdersGenerator.Steps.SendOrders
{
faKrosnoDataProvider.SaveEdiOrderTranslations(ediOrderTranslations);
}
if (ediCustomerOrderTranslations.Any())
{
sytelineDataProvider.SaveEdiOrderTranslations(ediCustomerOrderTranslations);
}
}
private EdiOrderTranslation CreateEdiOrderTranslation(ScheduleOrder scheduleOrder, string status,
string logMessage)
{
return new EdiOrderTranslation
{
ScheduleOrderId = scheduleOrder.Id,
CreatedDate = DateTime.Now,
LastUpdateDate = scheduleOrder.LastUpdateDate,
LogData = logMessage,
ItemsCount = scheduleOrder.ScheduleOrderDetail.Count,
Status = status
};
}
private EdiCustomerOrderTranslate GenerateEdiCustomerOrderTranslate(CustomerTp customerTp,
ScheduleOrder scheduleOrder, SytelineDataProvider sytelineDataProvider, string ediCustomerOrderNumber)
{
IList<CustomerOrder> customerOrders = sytelineDataProvider.GetCustomerOrders(customerTp.CustomerNumber,
customerTp.CustomerSequenceNumber, scheduleOrder.PoNum);
IDictionary<CustomerOrder, IList<CustomerOrderLine>> customerOrderLinesByOrder =
new ConcurrentDictionary<CustomerOrder, IList<CustomerOrderLine>>();
customerOrders.AsParallel().WithDegreeOfParallelism(5).ForAll(customerOrder =>
{
customerOrderLinesByOrder.Add(customerOrder,
sytelineDataProvider.GeCustomerOrderLines(customerOrder.CustomerOrderNumber));
});
IDictionary<CustomerOrder, int> orderNumbersWithMarks = new Dictionary<CustomerOrder, int>();
foreach (KeyValuePair<CustomerOrder, IList<CustomerOrderLine>> customerOrderLines in
customerOrderLinesByOrder)
{
int mark = 0;
foreach (ScheduleOrderDetail scheduleOrderDetail in scheduleOrder.ScheduleOrderDetail)
{
if (customerOrderLines.Value.Any(x => x.Item == scheduleOrderDetail.ShipperProductCode))
{
mark++;
}
}
orderNumbersWithMarks.Add(customerOrderLines.Key, mark);
}
if (orderNumbersWithMarks.Any(x => x.Value > 0))
{
CustomerOrder customerOrder = orderNumbersWithMarks.OrderByDescending(x => x.Value).First().Key;
return new EdiCustomerOrderTranslate
{
CoCoNum = customerOrder.CustomerOrderNumber,
CoEdiOrder = 1,
CoRowPointer = customerOrder.RowPointer,
CoTakenBy = customerOrder.TakenBy,
CoType = customerOrder.Type,
EdiCoCoNum = ediCustomerOrderNumber
};
}
return null;
}
}
}

View File

@@ -0,0 +1,151 @@
namespace SytelineSaAppDataModel
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Spatial;
[Table("co_bln")]
public partial class CustomerOrderLine
{
[Key]
[Column("co_num", Order = 0)]
[StringLength(10)]
public string CustomerOrderNumber { get; set; }
[Key]
[Column("co_line", Order = 1)]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public short CustomerOrderLineNumber { get; set; }
[Required]
[StringLength(30)]
[Column("item")]
public string Item { get; set; }
[StringLength(30)]
[Column("cust_item")]
public string CustomerItem { get; set; }
[StringLength(40)]
[Column("feat_str")]
public string FeatStr { get; set; }
[Column("blanket_qty")]
public decimal BlanketQty { get; set; }
[Column("eff_date")]
public DateTime? EffectiveDate { get; set; }
[Column("exp_date")]
public DateTime? ExpirationDate { get; set; }
[Column("cont_price")]
public decimal? ContPrice { get; set; }
[StringLength(1)]
[Column("stat")]
public string Status { get; set; }
[Column("promise_date")]
public DateTime? PromiseDate { get; set; }
[StringLength(3)]
[Column("pricecode")]
public string PriceCode { get; set; }
[StringLength(3)]
[Column("u_m")]
public string Uom { get; set; }
[Column("blanket_qty_conv")]
public decimal BlanketQtyConv { get; set; }
[Column("cont_price_conv")]
public decimal? ContPriceConv { get; set; }
[StringLength(8)]
[Column("ship_site")]
public string ShipSite { get; set; }
[Column("NoteExistsFlag")]
public byte NoteExistsFlag { get; set; }
[Column("RecordDate")]
public DateTime RecordDate { get; set; }
[Column("RowPointer")]
public Guid RowPointer { get; set; }
[StringLength(40)]
[Column("description")]
public string Description { get; set; }
[StringLength(12)]
[Column("config_id")]
public string ConfigId { get; set; }
[Required]
[StringLength(30)]
[Column("CreatedBy")]
public string CreatedBy { get; set; }
[Required]
[StringLength(30)]
[Column("UpdatedBy")]
public string UpdatedBy { get; set; }
[Column("CreateDate")]
public DateTime CreateDate { get; set; }
[Column("InWorkflow")]
public byte InWorkflow { get; set; }
[Column("print_kit_components")]
public byte PrintKitComponents { get; set; }
[StringLength(12)]
[Column("non_inv_acct")]
public string NonInvAcct { get; set; }
[StringLength(4)]
[Column("non_inv_acct_unit1")]
public string NonInvAcctUnitOne { get; set; }
[StringLength(4)]
[Column("non_inv_acct_unit2")]
public string NonInvAcctUnitTwo { get; set; }
[StringLength(4)]
[Column("non_inv_acct_unit3")]
public string NonInvAcctUnitThree { get; set; }
[StringLength(4)]
[Column("non_inv_acct_unit4")]
public string NonInvAcctUnitFour { get; set; }
[Column("cost_conv")]
public decimal? CostConv { get; set; }
[Column("days_shipped_before_due_date_tolerance")]
public short? DaysShippedBeforeDueDateTolerance { get; set; }
[Column("days_shipped_after_due_date_tolerance")]
public short? DaysShippedAfterDueDateTolerance { get; set; }
[Column("shipped_over_ordered_qty_tolerance")]
public decimal? ShippedOverOrderedQtyTolerance { get; set; }
[Column("shipped_under_ordered_qty_tolerance")]
public decimal? ShippedUnderOrderedQtyTolerance { get; set; }
[StringLength(7)]
[Column("manufacturer_id")]
public string ManufacturerId { get; set; }
[StringLength(30)]
[Column("manufacturer_item")]
public string ManufacturerItem { get; set; }
}
}

View File

@@ -0,0 +1,42 @@
namespace SytelineSaAppDataModel
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Spatial;
[Table("edi_co_translate")]
public partial class EdiCustomerOrderTranslate
{
[Key]
[Column("Id")]
public Guid Id { get; set; }
[Column("CoEdiOrder")]
public byte CoEdiOrder { get; set; }
[Column("CoRowPointer")]
public Guid CoRowPointer { get; set; }
[Required]
[StringLength(50)]
[Column("CoCoNum")]
public string CoCoNum { get; set; }
[Required]
[StringLength(1)]
[Column("CoType")]
public string CoType { get; set; }
[Required]
[StringLength(15)]
[Column("CoTakenBy")]
public string CoTakenBy { get; set; }
[Required]
[StringLength(10)]
[Column("EdiCoCoNum")]
public string EdiCoCoNum { get; set; }
}
}

View File

@@ -25,6 +25,8 @@ namespace SytelineSaAppDataModel
public virtual DbSet<MaterialTransaction> MaterialTransactions { get; set; }
public virtual DbSet<ItemCustomerPriceAll> ItemPrices { get; set; }
public virtual DbSet<CustomerOrder> CustomerOrders { get; set; }
public virtual DbSet<EdiCustomerOrderTranslate> EdiCustomerOrderTranslations { get; set; }
public virtual DbSet<CustomerOrderLine> CustomerOrderLines { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
@@ -1023,6 +1025,46 @@ namespace SytelineSaAppDataModel
modelBuilder.Entity<CustomerOrder>()
.Property(e => e.ShippedUnderOrderedQtyTolerance)
.HasPrecision(7, 4);
modelBuilder.Entity<EdiCustomerOrderTranslate>()
.Property(e => e.CoCoNum)
.IsUnicode(false);
modelBuilder.Entity<EdiCustomerOrderTranslate>()
.Property(e => e.CoType)
.IsFixedLength();
modelBuilder.Entity<CustomerOrderLine>()
.Property(e => e.BlanketQty)
.HasPrecision(20, 8);
modelBuilder.Entity<CustomerOrderLine>()
.Property(e => e.ContPrice)
.HasPrecision(20, 8);
modelBuilder.Entity<CustomerOrderLine>()
.Property(e => e.Status)
.IsFixedLength();
modelBuilder.Entity<CustomerOrderLine>()
.Property(e => e.BlanketQtyConv)
.HasPrecision(20, 8);
modelBuilder.Entity<CustomerOrderLine>()
.Property(e => e.ContPriceConv)
.HasPrecision(20, 8);
modelBuilder.Entity<CustomerOrderLine>()
.Property(e => e.CostConv)
.HasPrecision(20, 8);
modelBuilder.Entity<CustomerOrderLine>()
.Property(e => e.ShippedOverOrderedQtyTolerance)
.HasPrecision(7, 4);
modelBuilder.Entity<CustomerOrderLine>()
.Property(e => e.ShippedUnderOrderedQtyTolerance)
.HasPrecision(7, 4);
}
}
}

View File

@@ -59,6 +59,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CustomerOrderLine.cs" />
<Compile Include="CustomerOrder.cs" />
<Compile Include="CustomerAddress.cs" />
<Compile Include="Customer.cs" />
@@ -66,6 +67,7 @@
<Compile Include="EdiCustomerOrder.cs" />
<Compile Include="EdiCustomerOrderLine.cs" />
<Compile Include="EdiCustomerOrderLineItem.cs" />
<Compile Include="EdiCustomerOrderTranslate.cs" />
<Compile Include="Item.cs" />
<Compile Include="ItemCustom.cs" />
<Compile Include="ItemCustomerPriceAll.cs" />