scanning serial nummern

This commit is contained in:
Stoyan Zlatev
2023-05-11 09:31:14 +02:00
parent 720247e48b
commit d39ac8988b
20 changed files with 507 additions and 376 deletions
@@ -21,13 +21,13 @@
public async Task<ModelResult> SerialScannedAsync(string serialNo)
{
const string TEST_STATE = "30";
const string TEST_STATE = "25";
var watermeterTestPassed = this.sqlClient
.FirstOrDefault(
query: $@"
SELECT [PS].[AuftragNr]
, CASE WHEN MAX([APS].[StatusFertigung]) = '{TEST_STATE}'
, CASE WHEN MAX([APS].[StatusFertigung]) > '{TEST_STATE}'
THEN CAST(1 AS BIT)
ELSE CAST(0 AS BIT) END
FROM [PalettenScan] AS [PS]
@@ -57,14 +57,18 @@
AND (REPLACE([APS].[KundeneigeneSerienNr], ' ', '') = [PS].[SerienNr]
OR CAST([APS].[SerienNr] AS VARCHAR) = [PS].[SerienNr])
WHERE [PS].[AuftragNr] = @{nameof(orderNo)}
AND [APS].[StatusFertigung] = '{TEST_STATE}'
AND [APS].[StatusFertigung] > '{TEST_STATE}'
AND [PS].[ID] IS NULL",
parameters: parameters => parameters.Add(nameof(orderNo), orderNo),
reader: reader => reader.GetValue<int>());
if (unpackedWatermeterCount == 0)
{
return await this.smtpClient.SendAsync("Subject", "Html Body", "from", "1", "2");
return await this.smtpClient.SendAsync(
subject: "Subject",
body: "Html or text body",
from: "laa_production@xylem.com",
to: new[] { "Roland.Drabesch@Xylem.com", "Stoyan.Zlatev@Xylem.com" });
}
}
@@ -3,6 +3,9 @@
using MailKit.Net.Smtp;
using MimeKit;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
@@ -13,27 +16,40 @@
public SMTPClient(SMTPSettings settings)
=> this.settings = settings;
public async Task<bool> SendAsync(string subject, string body, string from, params string[] to)
public async Task<bool> SendAsync(string subject, string body, string from, IEnumerable<string> to)
{
//using (var client = new SmtpClient())
//{
// await client.AuthenticateAsync(this.settings.Username, this.settings.Password);
// await client.ConnectAsync(this.settings.Host, this.settings.Port);
try
{
using (var client = new SmtpClient())
{
await client.AuthenticateAsync(this.settings.Username, this.settings.Password);
await client.ConnectAsync(this.settings.Host, this.settings.Port);
// var message = new MimeMessage
// {
// Subject = subject,
// Body = new BodyBuilder
// {
// HtmlBody = body
// }.ToMessageBody()
// };
// var sender = MailboxAddress.Parse(from);
// var recipients = to.Select(x => MailboxAddress.Parse(x));
// var response = await client.SendAsync(message, sender, recipients);
//}
var message = new MimeMessage
{
Subject = subject,
Body = new BodyBuilder
{
HtmlBody = body
}.ToMessageBody(),
};
message.From.Add(MailboxAddress.Parse(from));
message.To.Add(MailboxAddress.Parse(to.FirstOrDefault()));
message.Cc.AddRange(to.Skip(1).Select(x => MailboxAddress.Parse(x)));
return await Task.FromResult(true);
var response = await client.SendAsync(message);
File.AppendAllLines("smtp.log", new[] { $"[SMTP_RESPONSE] {response}" });
}
return true;
}
catch (Exception e)
{
File.AppendAllLines("smtp.log", new[] { $"[SMTP_ERROR] {e.Message}" });
return false;
}
}
}
}
@@ -3,8 +3,8 @@
"DefaultConnection": "Data Source=SLASQL01.emea.sensus.net;Initial Catalog=Auftrag;Password=ServiceParingfile;Persist Security Info=True;User ID=ServiceParingfile;"
},
"SMTPSettings": {
"Host": "",
"Port": 0,
"Host": "smtp.xylem.com",
"Port": 587,
"Username": "",
"Password": ""
}
@@ -1,17 +1,18 @@
namespace LaaProductionWeb.Services.Interfaces
{
using LaaProductionWeb.Services.Models;
using System.Collections.Generic;
public interface IShipmentsService : ITransient
{
OrderScanModel DeletePalletEntry(int id);
int GetPalletsCount(OrderScanModel model);
byte[] LoadBatchBuffer(OrderScanModel model);
PalletsBatchModel LoadBatchModel(OrderScanModel model);
IEnumerable<int> LoadPallets(OrderScanModel model);
Result UpdateBatchModel(OrderScanModel model);
}
}
@@ -11,7 +11,7 @@
=> this.batchModel = batchModel;
public string ClientName
=> this.batchModel.ClientName;
=> this.batchModel.Customer;
public int OrderNr
=> this.batchModel.OrderNr;
@@ -21,17 +21,5 @@
public IEnumerable<PalletPosition> Positions
=> this.batchModel.Positions;
public int TotlalItemsCount
=> this.batchModel.TotlalItemsCount;
public int ItemsCount
=> this.batchModel.ItemsCount;
public SerialNr[] Items
=> this.batchModel
.Items
.Where(x => x.IsScaned)
.ToArray();
}
}
@@ -8,7 +8,7 @@
public int ProductionOrderNr { get; set; }
public string ClientName { get; set; }
public string Customer { get; set; }
public string Nr
=> this.OrderNr > 0
@@ -1,5 +1,6 @@
namespace LaaProductionWeb.Services.Models
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
@@ -13,7 +14,7 @@
public int PalletsCount { get; set; }
[Display(Name = "Paletten-Nr.")]
public int PalletNr { get; set; } = 1;
public int PalletNr { get; set; }
public IDictionary<int, bool> Pallets { get; set; }
= new Dictionary<int, bool> { { 1, false } };
@@ -21,16 +22,21 @@
public string PrintUrl
=> $"~/Shipments/Print?ordernr={this.OrderNr}&positionnr={this.PositionNr}&palletnr={this.PalletNr}";
public string DownloadUrl
=> $"~/Shipments/Download?ordernr={this.OrderNr}&positionnr={this.PositionNr}&palletnr={this.PalletNr}";
public string PalletUrl
=> $"~/Shipments/Pallet?ordernr={this.OrderNr}&positionnr={this.PositionNr}";
public void UpdatePalletsCount(int palletsCount)
public void UpdatePallets(IEnumerable<int> pallets)
{
this.PalletsCount = palletsCount;
this.Pallets = Enumerable
.Range(1, palletsCount)
.ToDictionary(x => x, x => false);
this.Pallets[this.PalletNr] = true;
this.Pallets = pallets.ToDictionary(x => x, x => x == this.PalletNr);
if (this.PalletNr == 0)
{
this.PalletNr = this.Pallets.Keys.Last();
}
else if (!this.Pallets.ContainsKey(this.PalletNr))
{
this.Pallets[this.PalletNr] = true;
}
}
}
}
@@ -1,5 +1,8 @@
namespace LaaProductionWeb.Services.Models
{
using System;
using System.Collections.Generic;
public class PalletPosition
{
public int PositionNr { get; set; }
@@ -7,5 +10,10 @@
public string Description { get; set; }
public int ItemsCount { get; set; }
public int TotalItemsCount { get; set; }
public IEnumerable<SerialNr> Items { get; set; }
= Array.Empty<SerialNr>();
}
}
@@ -2,26 +2,17 @@
{
using System;
using System.Collections.Generic;
using System.Linq;
public class PalletsBatchModel
{
public string ClientName { get; set; }
public string Customer { get; set; }
public int OrderNr { get; set; }
public int ProductionOrderNr { get; set; }
public int TotlalItemsCount { get; set; }
public string AdditionalText { get; set; }
public int ItemsCount
=> this.Positions.Sum(x => x.ItemsCount);
public IEnumerable<SerialNr> Items { get; set; }
= Array.Empty<SerialNr>();
public IEnumerable<PalletPosition> Positions { get; set; }
= Array.Empty<PalletPosition>();
}
@@ -2,17 +2,7 @@
{
public class SerialNr
{
private int id;
public int Id
{
get => this.id;
set
{
this.id = value;
this.IsScaned = this.id > 0;
}
}
public int Id { get; set; }
public int Nr { get; set; }
@@ -20,10 +10,10 @@
public int? PalletNr { get; set; }
public string ClientNr { get; set; }
public string CustomerNr { get; set; }
public bool IsScaned { get; set; }
public string BarcodeNr => this.ClientNr ?? $"{this.Nr}";
public string BarcodeNr => this.CustomerNr ?? $"{this.Nr}";
}
}
@@ -24,14 +24,14 @@
WHERE [AlleAuftragPositionen].[Versand_Ist_datum] IS NOT NULL
AND [AlleAuftragPositionen].[AuftragNr] LIKE @{nameof(search)}
ORDER BY [AlleAuftragPositionen].[AuftragNr]
, [AlleAuftragPositionen].[FertigungsauftragNr]
, [Kunde].[Name]",
, [AlleAuftragPositionen].[FertigungsauftragNr]
, [Kunde].[Name]",
parameters: parameters => parameters.Add(nameof(search), $"%{search}%"),
reader: reader => new OrderInfoModel
{
OrderNr = reader.GetValue<int>(0),
ProductionOrderNr = reader.GetValue<int>(1),
ClientName = reader.GetValue<string>(2),
OrderNr = reader.GetValue<int>(),
ProductionOrderNr = reader.GetValue<int>(),
Customer = reader.GetString(),
});
return new OrdersFoundModel(ordersFound);
@@ -8,10 +8,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
/// <summary>
///
/// </summary>
public class ShipmentsService : IShipmentsService
{
private readonly ISqlClient sqlClient;
@@ -25,34 +22,12 @@
if (orderScanModel != null)
{
var updated = this.UpdatePalletsNr(orderScanModel);
var updated = this.UpdatePalletsNr(orderScanModel.OrderNr ?? 0);
}
return orderScanModel;
}
public int GetPalletsCount(OrderScanModel model)
{
var palletsCount = this.sqlClient.FirstOrDefault(
query: $@"
SELECT COUNT(1)
FROM (SELECT [PalettenNr] AS [PalletNr]
, COUNT([SerienNr]) AS [Count]
FROM [PalettenScan]
WHERE [AuftragNr] = @{nameof(model.OrderNr)}
AND (@{nameof(model.PositionNr)} IS NULL
OR [PositionNr] = @{nameof(model.PositionNr)})
GROUP BY [PalettenNr])
AS [Paletten]
WHERE [Count] > 0",
parameters: parameters => parameters
.Add(nameof(model.OrderNr), model.OrderNr)
.Add(nameof(model.PositionNr), model.PositionNr),
reader: reader => reader.GetValue<int>(0));
return Math.Max(palletsCount, 1);
}
public byte[] LoadBatchBuffer(OrderScanModel model)
{
var palletLoad = this.sqlClient.ExecuteReader(
@@ -78,124 +53,188 @@
return Encoding.UTF8.GetBytes($"Pallet Nr.,Serial Nr.{Environment.NewLine}{csvContent}");
}
public IEnumerable<SerialNr> LoadBatchItems(OrderScanModel model)
=> this.sqlClient.ExecuteReader(
query: $@"
SELECT DISTINCT
[PalettenScan].[ID] -- 0
, [AuftragPositionSerienNr].[SerienNr] -- 1
, REPLACE(RTRIM(LTRIM([AuftragPositionSerienNr].[KundeneigeneSerienNr])), ' ', '') -- 2
, [PalettenScan].[PalettenNr] -- 3
, CAST(CASE WHEN [PalettenScan].[ID] IS NULL THEN 0 ELSE 1 END AS BIT) -- 4
, ISNULL([PalettenScan].[PositionNr], [AuftragPositionSerienNr].[PositionNr]) -- 5
FROM [AuftragPositionSerienNr]
LEFT JOIN [PalettenScan]
ON [PalettenScan].[AuftragNr] = [AuftragPositionSerienNr].[AuftragNr]
AND [PalettenScan].[PositionNr] = [AuftragPositionSerienNr].[PositionNr]
AND [PalettenScan].[SerienNr] = REPLACE(RTRIM(LTRIM([AuftragPositionSerienNr].[KundeneigeneSerienNr])), ' ', '')
WHERE [AuftragPositionSerienNr].[AuftragNr] = @{nameof(model.OrderNr)}
AND (@{nameof(model.PositionNr)} IS NULL
OR [AuftragPositionSerienNr].[PositionNr] = @{nameof(model.PositionNr)})
AND ([PalettenScan].[PalettenNr] = @{nameof(model.PalletNr)}
OR [PalettenScan].[PalettenNr] IS NULL)",
parameters: parameters => parameters
.Add(nameof(model.OrderNr), model.OrderNr)
.Add(nameof(model.PositionNr), model.PositionNr)
.Add(nameof(model.PalletNr), model.PalletNr),
reader: reader => new SerialNr
{
Id = reader.GetValue<int>(0),
Nr = reader.GetValue<int>(1),
ClientNr = reader.GetString(2),
PalletNr = reader.GetValue<short>(3),
IsScaned = reader.GetValue<bool>(4),
PositionNr = reader.GetValue<int>(5),
})
.OrderByDescending(x => x.IsScaned)
.ThenBy(x => x.PositionNr)
.ThenBy(x => x.ClientNr);
public PalletsBatchModel LoadBatchModel(OrderScanModel model)
{
const string orderNr = nameof(model.OrderNr);
const string palNr = nameof(model.PalletNr);
var batchModel = new PalletsBatchModel();
var pallets = this.LoadPallets(model);
model.UpdatePallets(pallets);
var batchModel = this.sqlClient.FirstOrDefault(
query: $@"
SELECT TOP 1
[Auftrag].[AuftragNr] -- 0
, [Auftrag].[FertigungsauftragNr] -- 1
, (SELECT SUM([AAP].[Menge])
FROM [AlleAuftragPositionen] AS [AAP]
WHERE [AAP].[AuftragNr] = [Auftrag].[AuftragNr]) -- 2
, [Kunde].[Name] -- 3
, [Auftrag].[ZusatzText] -- 4
FROM [AlleAuftragPositionen] AS [Auftrag]
JOIN [Kunde] ON [Kunde].[KundenNr] = [Auftrag].[KundenNr]
WHERE [Auftrag].[AuftragNr] = @{nameof(model.OrderNr)}
AND (@{nameof(model.PositionNr)} IS NULL
OR [Auftrag].[PositionNr] = @{nameof(model.PositionNr)})
ORDER BY [Auftrag].[FertigungsauftragNr] DESC",
parameters: parameters => parameters
.Add(nameof(model.OrderNr), model.OrderNr)
.Add(nameof(model.PositionNr), model.PositionNr),
reader: reader => new PalletsBatchModel
{
OrderNr = reader.GetValue<int>(0),
ProductionOrderNr = reader.GetValue<int>(1),
TotlalItemsCount = reader.GetValue<int>(2),
ClientName = reader.GetValue<string>(3),
AdditionalText = reader.GetValue<string>(4),
})
?? new PalletsBatchModel();
if (batchModel.OrderNr > 0)
if (model != null && model.OrderNr != null)
{
batchModel.Items = this.LoadBatchItems(model);
batchModel.Positions = this.LoadBatchPositions(model, orderNr, palNr);
batchModel = this.LoadBatchModel(model.OrderNr, model.PositionNr, model.PalletNr);
if (model.PositionNr != null && !batchModel.Positions.Any())
{
batchModel = this.LoadBatchModel(model.OrderNr, model.PositionNr, null);
}
}
return batchModel;
}
private IEnumerable<PalletPosition> LoadBatchPositions(OrderScanModel model, string orderNr, string palNr)
=> this.sqlClient.ExecuteReader($@"
SELECT DISTINCT
[Auftrag].[PositionNr]
, COUNT(1)
, [Identnr].[Typ]
, [Identnr].[Typzusatz]
, [Identnr].[Nennweite]
FROM [Identnr]
JOIN [AlleAuftragPositionen] AS [Auftrag]
ON [Auftrag].[IdentNr] = [Identnr].[IdentNr]
JOIN [PalettenScan]
ON [PalettenScan].[AuftragNr] = [Auftrag].[AuftragNr]
AND [PalettenScan].[PositionNr] = [Auftrag].[PositionNr]
AND [PalettenScan].[PalettenNr] = @{palNr}
WHERE [Auftrag].[AuftragNr] = @{orderNr}
GROUP BY [Auftrag].[PositionNr]
, [Identnr].[Typ]
, [Identnr].[Typzusatz]
, [Identnr].[Nennweite]
ORDER BY [Auftrag].[PositionNr] ",
parameters => parameters
.Add(orderNr, model.OrderNr)
.Add(palNr, model.PalletNr),
positionReader => new PalletPosition
private PalletsBatchModel LoadBatchModel(int? orderNo, int? posNo, int? palletNo)
=> this.sqlClient.FirstOrDefault(
query: $@"
SELECT TOP 1
[AAP].[AuftragNr]
, [AAP].[FertigungsauftragNr]
, [Kunde].[Name]
, [AAP].[ZusatzText]
FROM [AlleAuftragPositionen] AS [AAP]
JOIN [Kunde] ON [Kunde].[KundenNr] = [AAP].[KundenNr]
WHERE [AAP].[AuftragNr] = @{nameof(orderNo)}
AND (@{nameof(posNo)} IS NULL
OR [AAP].[PositionNr] = @{nameof(posNo)})
ORDER BY [AAP].[FertigungsauftragNr] DESC",
parameters: parameters => parameters
.Add(nameof(orderNo), orderNo)
.Add(nameof(posNo), posNo),
reader: reader => new PalletsBatchModel
{
PositionNr = positionReader.GetValue<short>(0),
ItemsCount = positionReader.GetValue<int>(1),
Description = string
.Join(" ", new[]
{
positionReader.GetString(2),
positionReader.GetString(3),
positionReader.GetString(4),
}
.Where(x => !string.IsNullOrWhiteSpace(x)))
OrderNr = reader.GetValue<int>(),
ProductionOrderNr = reader.GetValue<int>(),
Customer = reader.GetString(),
AdditionalText = reader.GetString(),
Positions = this.LoadBatchPositions(orderNo, posNo, palletNo)
})
?? new PalletsBatchModel();
private IEnumerable<PalletPosition> LoadBatchPositions(int? orderNo, int? posNo, int? palletNo)
=> this.sqlClient.ExecuteReader(
query: $@"SELECT [AAP].[PositionNr] AS [Pos]
, [Identnr].[Typ] AS [Typ]
, [Identnr].[Typzusatz] AS [Typzusatz]
, [Identnr].[Nennweite] AS [Nennweite]
, (SELECT COUNT(1)
FROM [PalettenScan] AS [x]
WHERE [x].[AuftragNr] = [PS].[AuftragNr]
AND [x].[PositionNr] = [PS].[PositionNr]
AND [x].[PalettenNr] = [PS].[PalettenNr]) AS [Count]
, (SELECT TOP 1 [Menge]
FROM [AlleAuftragPositionen] AS [x]
WHERE [x].[AuftragNr] = [AAP].[AuftragNr]
AND [x].[PositionNr] = [AAP].[PositionNr]) AS [TotalCount]
FROM [Identnr]
JOIN [AlleAuftragPositionen] AS [AAP]
ON [AAP].[IdentNr] = [Identnr].[IdentNr]
LEFT JOIN [PalettenScan] AS [PS]
ON [PS].[AuftragNr] = [AAP].[AuftragNr]
AND [PS].[PositionNr] = [AAP].[PositionNr]
WHERE [AAP].[AuftragNr] = @{nameof(orderNo)}
AND (@{nameof(palletNo)} IS NULL
OR [PS].[PalettenNr] = @{nameof(palletNo)})
AND (@{nameof(posNo)} IS NULL
OR [AAP].[PositionNr] = @{nameof(posNo)})
GROUP BY [AAP].[AuftragNr]
, [PS].[AuftragNr]
, [AAP].[PositionNr]
, [PS].[PositionNr]
, [Identnr].[Typ]
, [Identnr].[Typzusatz]
, [Identnr].[Nennweite]
, [PS].[PalettenNr]
ORDER BY [AAP].[PositionNr]",
parameters: parameters => parameters
.Add(nameof(orderNo), orderNo)
.Add(nameof(posNo), posNo)
.Add(nameof(palletNo), palletNo),
reader: reader => new PalletPosition
{
PositionNr = reader.GetValue<short>(),
Description = string
.Join(" ", new[]
{
reader.GetString(),
reader.GetString(),
reader.GetString(),
}
.Where(x => !string.IsNullOrWhiteSpace(x))),
ItemsCount = reader.GetValue<int>(),
TotalItemsCount = reader.GetValue<int>(),
Items = this.LoadBatchItems(orderNo, posNo, palletNo),
});
private IEnumerable<SerialNr> LoadBatchItems(int? orderNo, int? posNo, int? palletNo)
=> this.sqlClient.ExecuteReader(
query: $@"SELECT DISTINCT
[x].[Id]
, [x].[PositionNr]
, [x].[SerienNr]
, [x].[CustomerSerienNr]
, [x].[PalettenNr]
, [x].[IsScanned]
FROM (SELECT [PS].[ID] AS [Id]
, ISNULL([PS].[PositionNr], [APS].[PositionNr]) AS [PositionNr]
, [APS].[SerienNr] AS [SerienNr]
, REPLACE(RTRIM(LTRIM([APS].[KundeneigeneSerienNr])), ' ', '') AS [CustomerSerienNr]
, [PS].[PalettenNr] AS [PalettenNr]
, CAST(CASE WHEN [PS].[ID] IS NULL THEN 0 ELSE 1 END AS BIT) AS [IsScanned]
FROM [AuftragPositionSerienNr] AS [APS]
LEFT JOIN [PalettenScan] AS [PS]
ON [PS].[AuftragNr] = [APS].[AuftragNr]
AND [PS].[PositionNr] = [APS].[PositionNr]
AND [PS].[SerienNr] = REPLACE(RTRIM(LTRIM([APS].[KundeneigeneSerienNr])), ' ', '')
WHERE [APS].[AuftragNr] = @{nameof(orderNo)}
AND ([PS].[PalettenNr] IS NULL
OR @{nameof(palletNo)} IS NULL
OR [PS].[PalettenNr] = @{nameof(palletNo)})
AND (@{nameof(posNo)} IS NULL
OR [APS].[PositionNr] = @{nameof(posNo)}))
AS [x]
ORDER BY [x].[IsScanned] DESC
, [x].[PositionNr]
, [x].[CustomerSerienNr]
, [x].[SerienNr]",
parameters: parameters => parameters
.Add(nameof(orderNo), orderNo)
.Add(nameof(posNo), posNo)
.Add(nameof(palletNo), palletNo),
reader: reader => new SerialNr
{
Id = reader.GetValue<int>(),
PositionNr = reader.GetValue<int>(),
Nr = reader.GetValue<int>(),
CustomerNr = reader.GetString(),
PalletNr = reader.GetValue<short>(),
IsScaned = reader.GetValue<bool>(),
});
public IEnumerable<int> LoadPallets(OrderScanModel model)
{
this.UpdatePalletsNr(model.OrderNr ?? 0);
var pallets = this.sqlClient.ExecuteReader(
query: $@"SELECT DISTINCT [PS].[PalettenNr]
FROM [PalettenScan] AS [PS]
WHERE [PS].[AuftragNr] = @{nameof(model.OrderNr)}
AND (@{nameof(model.PositionNr)} IS NULL
OR [PS].[PositionNr] = @{nameof(model.PositionNr)})
ORDER BY [PS].[PalettenNr]",
parameters: parameters => parameters
.Add(nameof(model.OrderNr), model.OrderNr)
.Add(nameof(model.PositionNr), model.PositionNr),
reader: reader => (int)reader.GetValue<short>());
if (!pallets.Any())
{
return this.sqlClient.ExecuteReader(
query: $@"SELECT CAST(ISNULL(MAX([PS].[PalettenNr])
, (SELECT ISNULL(MAX([PS].[PalettenNr]), 1)
FROM [PalettenScan] AS [PS]
WHERE [PS].[AuftragNr] = @{nameof(model.OrderNr)})) AS INT)
FROM [PalettenScan] AS [PS]
WHERE [PS].[AuftragNr] = @{nameof(model.OrderNr)}
AND (@{nameof(model.PositionNr)} IS NULL
OR [PS].[PositionNr] = @{nameof(model.PositionNr)})",
parameters: parameters => parameters
.Add(nameof(model.OrderNr), model.OrderNr)
.Add(nameof(model.PositionNr), model.PositionNr),
reader: reader => reader.GetValue<int>());
}
return pallets;
}
public Result UpdateBatchModel(OrderScanModel model)
{
if (!string.IsNullOrWhiteSpace(model.SerialNr))
@@ -215,6 +254,9 @@
{
model.SerialNr = orderIdentity.ClientSerialNr;
model.PositionNr = orderIdentity.PositionNr;
var nextPalletNr = this.NextPallet(model.OrderNr.Value);
model.PalletNr = Math.Min(model.PalletNr, nextPalletNr);
}
var rowsAffected = this.InsertPalletEntry(model);
@@ -225,6 +267,12 @@
return false;
}
private int NextPallet(int orderno)
=> this.sqlClient.FirstOrDefault(
query: $@"SELECT MAX([PalettenNr]) + 1 FROM [PalettenScan] WHERE [AuftragNr] = @{nameof(orderno)}",
parameters: parameters => parameters.Add(nameof(orderno), orderno),
reader: reader => reader.GetValue<int>());
private OrderScanModel DeletePalletEntryById(int id)
=> this.sqlClient.FirstOrDefault(
query: $@"
@@ -296,40 +344,27 @@
SELECT CAST(CASE WHEN [PalettenScan].[ID] IS NULL THEN 0 ELSE 1 END AS BIT)
FROM [PalettenScan]
WHERE [PalettenScan].[AuftragNr] = @{nameof(orderNr)}
AND [PalettenScan].[SerienNr] = @{nameof(serialNr)}",
AND [PalettenScan].[SerienNr] = @{nameof(serialNr)}
OR @{nameof(serialNr)} LIKE '%' + (REPLACE(RTRIM(LTRIM([AuftragPositionSerienNr].[KundeneigeneSerienNr])), ' ', '')) + '%'",
parameters => parameters
.Add(nameof(orderNr), orderNr)
.Add(nameof(serialNr), serialNr),
reader => reader.GetValue<bool>(0));
private bool UpdatePalletsNr(OrderScanModel model)
=> this.sqlClient.FirstOrDefault($@"
BEGIN TRANSACTION
------------------------------------------------------------------------
DECLARE @rowsByAuftragPosition INT = (
SELECT COUNT(1)
FROM [PalettenScan]
WHERE [AuftragNr] = @{nameof(model.OrderNr)}
AND [PositionNr] = @{nameof(model.PositionNr)})
------------------------------------------------------------------------
UPDATE [PalettenScan]
SET [PalettenNr] = [OrderedPallets].[NewPalletNr]
FROM [PalettenScan]
JOIN (SELECT [ID]
, [PalettenNr]
, DENSE_RANK() OVER(ORDER BY [PalettenNr]) AS [NewPalletNr]
FROM [PalettenScan]
WHERE [AuftragNr] = @{nameof(model.OrderNr)}
AND [PositionNr] = @{nameof(model.PositionNr)})
AS [OrderedPallets]
ON [PalettenScan].[ID] = [OrderedPallets].[ID]
------------------------------------------------------------------------
IF @rowsByAuftragPosition = @@ROWCOUNT
BEGIN SELECT CAST(1 AS BIT); COMMIT; END
ELSE BEGIN SELECT CAST(0 AS BIT); ROLLBACK; END",
parameters => parameters
.Add(nameof(model.OrderNr), model.OrderNr)
.Add(nameof(model.PositionNr), model.PositionNr),
reader => reader.GetValue<bool>(0));
reader => reader.GetValue<bool>());
private bool UpdatePalletsNr(int orderNo)
=> this.sqlClient.ExecuteNonQuery(
query: $@"UPDATE [PalettenScan]
SET [PalettenNr] = [P2].[RowNumber]
FROM [PalettenScan] AS [P1]
JOIN (SELECT [P].[PalettenNr]
, ROW_NUMBER() OVER (ORDER BY [P].[PalettenNr]) AS [RowNumber]
FROM (SELECT DISTINCT
[PalettenNr]
FROM [PalettenScan]
WHERE [AuftragNr] = @{nameof(orderNo)})
AS [P])
AS [P2]
ON [P2].[PalettenNr] = [P1].[PalettenNr]",
parameters: parameters => parameters.Add(nameof(orderNo), orderNo)) == 1;
}
}
@@ -1,6 +1,9 @@
namespace LaaProductionWeb.App_Infrastructure
{
using Newtonsoft.Json;
using System;
using System.Net;
using System.Web;
public class SessionUser
@@ -25,14 +28,16 @@
{
public static int UserId(this HttpContextBase httpContext)
{
var cookieUserId = httpContext
.Request
.Cookies
.Get(nameof(SessionUser))
?.Value ?? string.Empty;
var cookies = httpContext.Request.Cookies;
var userCookie = cookies.Get(nameof(SessionUser));
var cookieUserId = userCookie?.Value ?? string.Empty;
if (int.TryParse(cookieUserId, out int userId))
{
userCookie.Expires = DateTime.Now.AddSeconds(ApplicationSettings.LoginTimeout);
cookies.Set(userCookie);
return userId;
}
@@ -57,17 +62,58 @@
public static void SignOut(this HttpContextBase httpContext)
{
var cookieUserId = httpContext
.Request
.Response
.Cookies
.Get(nameof(SessionUser))
?.Value ?? string.Empty;
}
const string DATA = nameof(DATA);
public static void SetUserData(this HttpContextBase httpContext, object data)
{
if (data != null)
{
var userId = httpContext.UserId();
var json = JsonConvert.SerializeObject(data);
var encoded = WebUtility.UrlEncode(json);
var cookie = new HttpCookie($"{DATA}_{userId}")
{
Value = encoded,
Expires = DateTime.Now.AddHours(7)
};
httpContext.Response.Cookies.Set(cookie);
}
}
public static T GetUserData<T>(this HttpContextBase httpContext)
{
var userId = httpContext.UserId();
var cookie = httpContext.Request.Cookies.Get($"{DATA}_{userId}");
if (cookie != null && cookie.Value != null)
{
try
{
var json = WebUtility.UrlDecode(cookie.Value);
return JsonConvert.DeserializeObject<T>(json);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
return default(T);
}
const string URL_REFERER = nameof(URL_REFERER);
public static void SetUrlReferer(this HttpContextBase httpContext)
=> httpContext
.Request
.Response
.Cookies
.Add(new HttpCookie(URL_REFERER, $"{httpContext.Request.Url}"));
@@ -9,6 +9,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net;
using System.Threading.Tasks;
using System.Web.Mvc;
using SystemFile = System.IO.File;
@@ -17,17 +19,40 @@
public class ShipmentsController : Controller
{
private readonly IShipmentsService shipmentsService;
private readonly IHttpService httpService;
public ShipmentsController(IShipmentsService shipmentsService)
=> this.shipmentsService = shipmentsService;
public ShipmentsController(IShipmentsService shipmentsService, IHttpService httpService)
{
this.shipmentsService = shipmentsService;
this.httpService = httpService;
}
[HttpGet]
public ActionResult Index()
=> this.View(new ShipmentModel());
public ActionResult Index()
{
var shipmentModel = new ShipmentModel();
var orderScanModel = this.HttpContext.GetUserData<OrderScanModel>();
if (orderScanModel != null)
{
shipmentModel = new ShipmentModel(orderScanModel);
}
return this.View(shipmentModel);
}
[HttpPost]
public ActionResult Index(ShipmentModel model)
=> this.View(model);
public ActionResult Index(ShipmentModel model)
{
this.HttpContext.SetUserData(model.OrderScanModel as OrderScanModel);
return this.View(model);
}
[HttpGet]
public ActionResult Pallet(OrderScanModel model)
=> this.View(nameof(this.Index), new ShipmentModel(model));
public ActionResult Batch(OrderScanModel model)
{
@@ -39,17 +64,26 @@
return this.PartialView(batchModel);
}
public ActionResult Scan(OrderScanModel model)
[HttpGet]
public ActionResult Print(OrderScanModel model)
{
var palletsCount = this.shipmentsService.GetPalletsCount(model);
var batchModel = this.shipmentsService.LoadBatchModel(model);
var batchPrintModel = new BatchPrintModel(batchModel);
model.UpdatePalletsCount(palletsCount);
return this.View(batchPrintModel);
}
public ActionResult Scan(OrderScanModel model)
{
var pallets = this.shipmentsService.LoadPallets(model);
model.UpdatePallets(pallets);
return this.PartialView(model);
}
[HttpPost]
public ActionResult ScanPost(OrderScanModel model)
public async Task<ActionResult> ScanPost(OrderScanModel model)
{
if (this.ModelState.IsValid)
{
@@ -61,7 +95,11 @@
if (result)
{
await this.httpService.GetAsync($"/Shipment/Scanned/Serial/{WebUtility.UrlEncode(model.SerialNr)}");
model.SerialNr = default(string);
this.HttpContext.SetUserData(model);
}
else
{
@@ -79,15 +117,6 @@
return this.View(nameof(this.Index), new ShipmentModel(orderScanModel));
}
[HttpGet]
public ActionResult Print(OrderScanModel model)
{
var batchModel = this.shipmentsService.LoadBatchModel(model);
var batchPrintModel = new BatchPrintModel(batchModel);
return this.View(batchPrintModel);
}
[HttpGet]
public ActionResult Download(OrderScanModel model)
@@ -112,7 +141,7 @@
{
if (additionalText.Contains(kvp.Key))
{
batchModel.ClientName = kvp.Value;
batchModel.Customer = kvp.Value;
break;
}
@@ -18,8 +18,8 @@
<UseIISExpress>true</UseIISExpress>
<Use64BitIISExpress />
<IISExpressSSLPort />
<IISExpressAnonymousAuthentication>disabled</IISExpressAnonymousAuthentication>
<IISExpressWindowsAuthentication>enabled</IISExpressWindowsAuthentication>
<IISExpressAnonymousAuthentication>enabled</IISExpressAnonymousAuthentication>
<IISExpressWindowsAuthentication>disabled</IISExpressWindowsAuthentication>
<IISExpressUseClassicPipelineMode />
<UseGlobalApplicationHostFile />
<NuGetPackageImportStamp>
@@ -2,5 +2,5 @@
@foreach (var order in this.Model)
{
<li><a class="dropdown-item" href="#@order.Nr,@order.ProductionOrderNr">@($"{order.OrderNr, 10} / {order.ProductionOrderNr, 10}") - @order.ClientName</a></li>
<li><a class="dropdown-item" href="#@order.Nr,@order.ProductionOrderNr">@($"{order.OrderNr, 10} / {order.ProductionOrderNr, 10}") - @order.Customer</a></li>
}
@@ -2,7 +2,7 @@
@model PalletsBatchModel
@if (!string.IsNullOrWhiteSpace(this.Model.ClientName))
@if (!string.IsNullOrWhiteSpace(this.Model.Customer))
{
<div class="d-flex justify-content-center">
<div id="batch" class="print-page border rounded shadow-sm mt-5 p-5">
@@ -10,34 +10,38 @@
<table class="table table-borderless">
<tr>
<th colspan="2" class="fs-5">Paletten Begleitschein</th>
<th colspan="2" class="fs-5">@this.Model.ClientName</th>
<th colspan="2" class="fs-5">@this.Model.Customer</th>
</tr>
<tr>
<th class="py-1 white-space-nowrap">Kunden-Auftrag</th>
<td class="py-1">@this.Model.OrderNr</td>
<th class="py-1 white-space-nowrap">Fertigungsauftrags-Nr.</th>
<td class="py-1">@this.Model.ProductionOrderNr</td>
<th class="white-space-nowrap">Kunden-Auftrag</th>
<td class="">@this.Model.OrderNr</td>
<th class="white-space-nowrap">Fertigungsauftrags-Nr.</th>
<td class="">@this.Model.ProductionOrderNr</td>
</tr>
@{
var isFirst = true;
foreach (var position in this.Model.Positions)
{
<tr>
<th class="py-1">@(isFirst ? "Position Nr" : string.Empty)</th>
<td class="py-1">@position.PositionNr</td>
<th class="py-1">@(isFirst ? "Bezeichnung" : string.Empty)</th>
<td class="py-1">@position.Description</td>
</tr>
isFirst = false;
}
}
<tr>
<th class="py-1 white-space-nowrap">Palettemenge</th>
<td class="py-1">@this.Model.ItemsCount</td>
<th class="py-1 white-space-nowrap">Auftragsmenge</th>
<td class="py-1">@this.Model.TotlalItemsCount</td>
<tr class="border-top">
<td class="p-0 small" colspan="4">
<table class="table table-borderless">
<tr>
<th class="text-end">Pos</th>
<th >Bezeichnung</th>
<th class="text-end">Menge</th>
<th class="text-end">Bestellmenge</th>
</tr>
@foreach (var pos in this.Model.Positions)
{
<tr>
<td class="text-end">@pos.PositionNr</td>
<td >@pos.Description</td>
<td class="text-end">@pos.ItemsCount</td>
<td class="text-end">@pos.TotalItemsCount</td>
</tr>
}
<tr class="border-top">
<td colspan="3" class="text-end fw-bold">Palettenmenge: @this.Model.Positions.Sum(x => x.ItemsCount)</td>
<td colspan="1"></td>
</tr>
</table>
</td>
</tr>
</table>
<table class="table table-borderless table-striped">
@@ -54,7 +58,7 @@
@{
var count = 1;
foreach (var item in this.Model.Items)
foreach (var item in this.Model.Positions.SelectMany(x => x.Items))
{
<tr class="is_scaned_@(item.IsScaned ? 1 : 0)">
<td class="va-middle @(item.IsScaned ? null : "text-secondary")">@(count++).</td>
@@ -73,7 +73,7 @@
orderNrMenu.innerHTML = null;
let orderNr = orderNrInput.value;
if (orderNr && orderNr.length > 3) {
fetch(`@this.Url.Action("Orders", "Search")?search=${orderNr}?search=${orderNr}`)
fetch(`@this.Url.Action("Orders", "Search")?search=${orderNr}`)
.then(response => response.text())
.then(data => ordersAutocomplete(data))
.catch(error => console.log(error));
@@ -115,9 +115,7 @@
}
});
orderNrInput.oninput = function () {
setTimeout(onOrderNrInput, 50);
};
orderNrInput.oninput = onOrderNrInput;
positionNrInput.setAttribute('data-bs-toggle', 'dropdown');
positionNrInput.setAttribute('aria-expanded', 'false');
@@ -2,9 +2,6 @@
@{
this.Layout = "~/Views/Shared/_PrintLayout.cshtml";
var items = this.Model.Items;
var itemsLength = items.Length;
}
<table class="table table-borderless table-striped">
@@ -18,31 +15,35 @@
<th colspan="2" class="fs-4">@this.Model.ClientName</th>
</tr>
<tr>
<td class="py-0 white-space-nowrap">Kunden-Auftrag</td>
<td class="py-0 fw-normal">@this.Model.OrderNr</td>
<td class="py-0 white-space-nowrap">Fertigungsauftrags-Nr.</td>
<td class="py-0 fw-normal">@this.Model.ProductionOrderNr</td>
<td class="white-space-nowrap">Kunden-Auftrag</td>
<td class="fw-normal">@this.Model.OrderNr</td>
<td class="white-space-nowrap">Fertigungsauftrags-Nr.</td>
<td class="fw-normal">@this.Model.ProductionOrderNr</td>
</tr>
@{
var isFirst = true;
foreach (var position in this.Model.Positions)
{
<tr>
<td class="py-0">@(isFirst ? "Position Nr" : string.Empty)</td>
<td class="py-0 fw-normal">@position.PositionNr</td>
<td class="py-0">@(isFirst ? "Bezeichnung" : string.Empty)</td>
<td class="py-0 fw-normal">@position.Description</td>
</tr>
isFirst = false;
}
}
<tr>
<td class="py-0 white-space-nowrap">Palettenmenge</td>
<td class="py-0 fw-normal">@this.Model.ItemsCount</td>
<td class="py-0 white-space-nowrap">Auftragsmenge</td>
<td class="py-0 fw-normal">@this.Model.TotlalItemsCount</td>
<tr class="border-top">
<td class="p-0 small" colspan="4">
<table class="table table-borderless">
<tr>
<th class="text-end">Pos</th>
<th >Bezeichnung</th>
<th class="text-end">Menge</th>
<th class="text-end">Bestellmenge</th>
</tr>
@foreach (var pos in this.Model.Positions)
{
<tr>
<td class="fw-normal text-end">@pos.PositionNr</td>
<td class="fw-normal ">@pos.Description</td>
<td class="fw-normal text-end">@pos.ItemsCount</td>
<td class="fw-normal text-end">@pos.TotalItemsCount</td>
</tr>
}
<tr class="border-top">
<td colspan="3" class="text-end fw-bold">Palettenmenge: @this.Model.Positions.Sum(x => x.ItemsCount)</td>
<td colspan="1"></td>
</tr>
</table>
</td>
</tr>
</thead>
</table>
@@ -58,28 +59,22 @@
</tr>
</thead>
<tbody>
@for (var i = 0; i < itemsLength; i += 2)
{
var ni = i + 1;
var item = items[i];
@{
var items = this.Model
.Positions
.SelectMany(x => x.Items
.Where(i => i.IsScaned))
.ToList();
var itemsCount = items.Count;
<tr>
<td class="fs-5">@(i + 1).</td>
<td class="fs-5">@item.PositionNr</td>
<td class="py-0">
<svg class="barcode"
jsbarcode-height="70"
jsbarcode-format="auto"
jsbarcode-displayValue="true"
jsbarcode-textMargin="0"
jsbarcode-background="transparent"
jsbarcode-value="@item.BarcodeNr" />
</td>
@if (ni < itemsLength)
{
var nitem = items[ni];
<td class="fs-5" >@(ni + 1).</td>
<td class="fs-5">@nitem.PositionNr</td>
for (var i = 0; i < itemsCount; i += 2)
{
var ni = i + 1;
var item = items[i];
<tr>
<td class="fs-5">@(i + 1).</td>
<td class="fs-5">@item.PositionNr</td>
<td class="py-0">
<svg class="barcode"
jsbarcode-height="70"
@@ -87,16 +82,31 @@
jsbarcode-displayValue="true"
jsbarcode-textMargin="0"
jsbarcode-background="transparent"
jsbarcode-value="@nitem.BarcodeNr" />
jsbarcode-value="@item.BarcodeNr" />
</td>
}
else
{
<td></td>
<td></td>
<td></td>
}
</tr>
@if (ni < itemsCount)
{
var nitem = items[ni];
<td class="fs-5">@(ni + 1).</td>
<td class="fs-5">@nitem.PositionNr</td>
<td class="py-0">
<svg class="barcode"
jsbarcode-height="70"
jsbarcode-format="auto"
jsbarcode-displayValue="true"
jsbarcode-textMargin="0"
jsbarcode-background="transparent"
jsbarcode-value="@nitem.BarcodeNr" />
</td>
}
else
{
<td></td>
<td></td>
<td></td>
}
</tr>
}
}
</tbody>
</table>
@@ -9,39 +9,44 @@
<form id="scan_form" action="~/Shipments/ScanPost" method="post" autocomplete="off">
@this.Html.HiddenFor(x => x.OrderNr)
@this.Html.HiddenFor(x => x.PositionNr)
@this.Html.HiddenFor(x => x.PalletsCount)
@this.Html.HiddenFor(x => x.PalletNr)
<div class="d-flex flex-wrap">
@foreach (var pallet in this.Model.Pallets)
{
var css = pallet.Key != this.Model.PalletNr
? "btn btn-outline-success"
: "btn btn-success";
var css = pallet.Key == this.Model.PalletNr
? "btn btn-success"
: "btn btn-outline-success";
var id = $"pallet_{pallet.Key}";
<label for="@id" class="@css mb-3 me-3">@pallet.Key</label>
<input id="@id" name="@nameof(this.Model.PalletNr)" value="@pallet.Key" class="d-none" type="submit" />
<a class="@css mb-3 me-3" href="@this.Url.Content($"{this.Model.PalletUrl}&palletnr={pallet.Key}")">@pallet.Key</a>
}
@{
var nextPalletNr = this.Model.Pallets.Keys.LastOrDefault() + 1;
}
<a class="btn btn-outline-success mb-3 me-3" href="@this.Url.Content($"{this.Model.PalletUrl}&palletnr={nextPalletNr}")">
<i class="bi bi-plus-square"></i>
</a>
<a class="btn btn-outline-secondary mb-3 me-3" href="@this.Url.Content(this.Model.PrintUrl)" target="_blank">
<i class="bi bi-printer"></i> Druckvorschau
</a>
<a class="btn btn-outline-secondary mb-3 me-3" href="@this.Url.Content(this.Model.DownloadUrl)">
<i class="bi bi-filetype-csv"></i> Herunterladen
</a>
</div>
<div class="input-group">
<div class="form-floating w-auto">
@this.Html.TextBoxFor(x => x.SerialNr, new { id = "serial_nr", @class = "form-control form-control-success text-center", placeholder = "0000000000" })
@this.Html.LabelFor(x => x.SerialNr, new { @for = "serial_nr", @class = "text-smallcaps" })
@if (this.IsPost)
{
this.Html.ValidationMessageFor(x => x.SerialNr, string.Empty, new { @class = "small text-danger mt-0" });
}
</div>
<div class="form-floating">
@this.Html.TextBoxFor(x => x.PalletNr, new { id = "pallet_nr", @class = "form-control form-control-success text-center", placeholder = "0" })
@this.Html.LabelFor(x => x.PalletNr, new { @for = "pallet_nr", @class = "text-smallcaps" })
<input class="form-control form-control-success disabled readonly text-center" value="@this.Model.PalletNr" readonly disabled />
@this.Html.LabelFor(x => x.PalletNr)
</div>
</div>
@if (this.IsPost)
{
this.Html.ValidationMessageFor(x => x.SerialNr, string.Empty, new { @class = "small text-danger mt-0" });
}
@if (this.TempData.TryGetValue(nameof(this.Model.SerialNr), out object errorMessage))
{
<div class="text-danger small">