new Estimation

This commit is contained in:
Martijn Scheepers
2023-04-04 13:30:49 +02:00
parent 4f6e7d9f17
commit f4cd7b40fd
7 changed files with 196 additions and 60 deletions

View File

@@ -302,18 +302,6 @@ namespace Manut_Test_Blazor.Data
item.Prodid = $"{item.Prodid.TrimEnd()} ^{item.PkProdid}";
AddProduct(item);
//if (duplicateDone.Contains(item.Prodid.TrimEnd().ReplaceLineEndings()) == false)
//{
// AddProduct(item);
// duplicateDone.Add(item.Prodid.TrimEnd().ReplaceLineEndings());
//}
//else
//{
// item.Prodid = $"{item.Prodid.TrimEnd()} #{item.PkProdid}";
// AddProduct(item);
//}
}
else
{
@@ -334,13 +322,14 @@ namespace Manut_Test_Blazor.Data
if (item.Prodid.StartsWith('€'))
{
Estimation estimation = new()
{
EstimationCode = item.Prodid.TrimEnd().ReplaceLineEndings().Replace("€", "").Replace(" ", ""),
Description = item.Desc.TrimEnd(),
Date = DateOnly.FromDateTime(item.Regdate),
};
_partsdbContext.Estimations.Add(estimation);
return;
//Estimation estimation = new()
//{
// EstimationCode = item.Prodid.TrimEnd().ReplaceLineEndings().Replace("€", "").Replace(" ", ""),
// Description = item.Desc.TrimEnd(),
// Date = DateOnly.FromDateTime(item.Regdate),
//};
//_partsdbContext.Estimations.Add(estimation);
}
else
{
@@ -444,29 +433,7 @@ namespace Manut_Test_Blazor.Data
return decimal.Round(margin, 2);
}
private void AddPartsToEstimation(int id, Estimation estimation)
{
var parts = _mamutdbContext.GStrucs.Where(x => x.FkStrucid == id).Include(p => p.FkComponentNavigation).ToList();
foreach (var item in parts)
{
//Debug.WriteLine($" Parts mamut |{item.FkComponentNavigation.Prodid.TrimEnd()}|");
EstimationPart part = new()
{
Estimation = estimation,
Quantity = item.Count,
Product = _partsdbContext.Products.Where(x => x.ProductCode == item.FkComponentNavigation.Prodid.TrimEnd()).SingleOrDefault(),
};
if (part.Product.ProductCode.StartsWith("* ARB"))
{
part.Quantity /= 4;
}
Debug.WriteLine($" Parts partsDB {part.Estimation.EstimationCode} - {part.Product?.ProductCode} - {part.Quantity}");
_partsdbContext.EstimationParts.Add(part);
}
}
private void AddPartsToProduct(int id, Product product)
{
var parts = _mamutdbContext.GStrucs.Where(x => x.FkStrucid == id).Include(p => p.FkComponentNavigation).ToList();
@@ -512,16 +479,16 @@ namespace Manut_Test_Blazor.Data
}
_partsdbContext.SaveChanges();
foreach (var est in _partsdbContext.Estimations.ToList())
{
GProd? mamutProduct = _mamutdbContext.GProds
.Where(p => p.Prodid.TrimEnd().Replace("€", "").Replace(" ", "") == est.EstimationCode)
.SingleOrDefault();
//foreach (var est in _partsdbContext.Estimations.ToList())
//{
// GProd? mamutProduct = _mamutdbContext.GProds
// .Where(p => p.Prodid.TrimEnd().Replace("€", "").Replace(" ", "") == est.EstimationCode)
// .SingleOrDefault();
Debug.WriteLine($"Estimation {mamutProduct.Prodid}");
AddPartsToEstimation(mamutProduct.PkProdid, est);
}
_partsdbContext.SaveChanges();
// Debug.WriteLine($"Estimation {mamutProduct.Prodid}");
// AddPartsToEstimation(mamutProduct.PkProdid, est);
//}
//_partsdbContext.SaveChanges();
}
@@ -596,5 +563,117 @@ namespace Manut_Test_Blazor.Data
}
}
public void ConvertEstimations()
{
var products = _mamutdbContext.GProds.Where(a => a.Inactive == false).ToList();
foreach (var item in products)
{
if (item.Prodid.StartsWith('€'))
{
//Debug.WriteLine($"Estimation {item.Prodid}");
Estimation estimation = new()
{
Code = item.Prodid.TrimEnd().ReplaceLineEndings().Replace("€", "").Replace(" ", ""),
//ReferenceCode = item.Salenote?.TrimEnd(),
Description = item.Desc.TrimEnd().ReplaceLineEndings(" "),
Date = DateOnly.FromDateTime(item.Regdate),
};
if (item.Salenote != null)
{
estimation.ReferenceCode = item.Salenote.TrimEnd().ReplaceLineEndings(" ");
if (estimation.ReferenceCode.Length >= 100)
{
throw new Exception("too long");
}
}
string zip = estimation.Code.Substring(0, estimation.Code.IndexOf("-"));
//Debug.WriteLine($"Zipcode = {zip}");
Customer cust;
if (zip == "5501LA010")
{
cust = _partsdbContext.Customers.Where(c => c.CustomerCode.StartsWith("5501LA010-POB")).SingleOrDefault();
}
else
{
cust = _partsdbContext.Customers.Where(c => c.CustomerCode.StartsWith(zip)).SingleOrDefault();
}
if (cust == null)
{
Customer newCust = new()
{
CustomerCode = zip,
};
_partsdbContext.Customers.Add(newCust);
estimation.Customer = newCust;
}
else
{
estimation.Customer = cust;
}
Debug.WriteLine($"Estimation {estimation.Code} - |{estimation.ReferenceCode}| - |{estimation.Customer.CustomerCode}| - |{estimation.Description}|");
_partsdbContext.Estimations.Add(estimation);
}
}
_partsdbContext.SaveChanges();
foreach (var est in _partsdbContext.Estimations.ToList())
{
Debug.WriteLine($"PartsDB {est.Code}");
GProd? mamutProduct = _mamutdbContext.GProds
.Where(p => p.Prodid.TrimEnd().Replace("€", "").Replace(" ", "") == est.Code)
.SingleOrDefault();
Debug.WriteLine($"Estimation {mamutProduct.Prodid}");
AddPartsToEstimation(mamutProduct.PkProdid, est);
}
_partsdbContext.SaveChanges();
foreach (var est in _partsdbContext.Estimations.ToList())
{
Debug.WriteLine($"PartsDB {est.Code}");
string bla = est.Code.Substring(est.Code.IndexOf("-") + 1);
Debug.WriteLine($"---- Code = {bla}");
est.Code = bla;
}
_partsdbContext.SaveChanges();
}
private void AddPartsToEstimation(int id, Estimation estimation)
{
var parts = _mamutdbContext.GStrucs.Where(x => x.FkStrucid == id).Include(p => p.FkComponentNavigation).ToList();
foreach (var item in parts)
{
//Debug.WriteLine($" Parts mamut |{item.FkComponentNavigation.Prodid.TrimEnd()}|");
EstimationPart part = new()
{
Estimation = estimation,
Quantity = item.Count,
Product = _partsdbContext.Products.Where(x => x.ProductCode == item.FkComponentNavigation.Prodid.TrimEnd()).SingleOrDefault(),
};
var products = _partsdbContext.Products.Where(x => x.ProductCode == item.FkComponentNavigation.Prodid.TrimEnd());
if (part.Product.ProductCode.StartsWith("* ARB"))
{
part.Quantity /= 4;
}
Debug.WriteLine($" Parts partsDB {part.Estimation.Code} - {part.Product?.ProductCode} - {part.Quantity}");
_partsdbContext.EstimationParts.Add(part);
}
}
}
}

View File

@@ -48,6 +48,8 @@ namespace PartsDB.models.DB
public ICollection<ServiceTag>? ServiceTags { get; set; }
public ICollection<Estimation>? Estimations { get; set; }
[NotMapped]
public string FullCustomerCode
{

View File

@@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace PartsDB.models.DB
{
@@ -7,9 +8,14 @@ namespace PartsDB.models.DB
[Key]
public int Id { get; set; }
[Required]
[ForeignKey("CustomerId")]
public Customer? Customer { get; set; }
[MaxLength(50)]
public string EstimationCode { get; set; } = string.Empty;
public string Code { get; set; } = string.Empty;
[MaxLength(100)]
public string ReferenceCode { get; set; } = string.Empty;
[Required]
[MaxLength(100)]
@@ -20,5 +26,14 @@ namespace PartsDB.models.DB
public ICollection<EstimationPart>? PartsList { get; set; }
//[NotMapped]
//public string EstimationCode
//{
// get
// {
// return $"{Customer?.CustomerCode}-{Code}";
// }
//}
}
}

View File

@@ -108,9 +108,17 @@ namespace PartsDB.models.DB
entity.ToTable("Estimations");
entity.Property(e => e.Id).HasColumnName("Id");
entity.Property(e => e.EstimationCode)
.HasMaxLength(50)
.HasColumnName("EstimationCode");
entity.HasOne(d => d.Customer)
.WithMany(b => b.Estimations)
.HasForeignKey("CustomerId");
entity.Property(i => i.Code)
.HasMaxLength(50)
.HasColumnName("Code");
entity.Property(d => d.ReferenceCode)
.HasMaxLength(50)
.HasColumnName("ReferenceCode");
entity.Property(e => e.Description)
.HasMaxLength(100)

View File

@@ -31,8 +31,6 @@ namespace PartsDB.models.DB
public Vendor? Vendor { get; set; }
public decimal? PricePiecePurchase()
{
if (Product?.Quantity != 0)

View File

@@ -24,6 +24,9 @@
<button @onclick="dbConvertService.AddVendors">
Convert add vendors
</button>
<button @onclick="dbConvertService.ConvertEstimations">
Convert Estimations
</button>
<br />
<hr />
@@ -46,5 +49,6 @@
dbConvertService.ConvertProducts();
dbConvertService.AddParts();
dbConvertService.AddVendors();
//dbConvertService.ConvertEstimations();
}
}

View File

@@ -1,9 +1,39 @@
@page "/"
@inject Data.DBConvertService mamutConvertService
@inject Data.HardwareDBConverter hardwareDbConverter
<PageTitle>Index</PageTitle>
<h1>Hello, world!</h1>
<h1>Convert databases</h1>
Welcome to your new app.
<button @onclick="AllConvert">
Convert All db's
</button>
<SurveyPrompt Title="How is Blazor working for you?" />
@code {
private async Task AllConvert()
{
Debug.WriteLine("Start converting all Mamut DB");
mamutConvertService.ConvertVendors();
mamutConvertService.ConvertGroups();
mamutConvertService.ConvertPackunits();
mamutConvertService.ConvertBrands();
mamutConvertService.ConvertProducts();
mamutConvertService.AddParts();
mamutConvertService.AddVendors();
Debug.WriteLine("Start converting all Hardware DB");
await hardwareDbConverter.ConvertCustomers();
hardwareDbConverter.ConvertLocations();
hardwareDbConverter.ConvertServiceTagTypes();
hardwareDbConverter.ConvertServiceTagFields();
hardwareDbConverter.ConvertServiceTags();
hardwareDbConverter.ConvertServiceTagData();
hardwareDbConverter.ConvertSerials();
//mamutConvertService.ConvertEstimations();
}
}