Weighing: Do not ignore gross and tare weight and show it on DeliveryNote

This commit is contained in:
2024-07-22 17:10:36 +02:00
parent 1141331608
commit fd0ed97305
26 changed files with 159 additions and 96 deletions

View File

@ -1,8 +1,10 @@
using Elwig.Helpers;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text.Json.Nodes;
namespace Elwig.Models.Entities {
[Table("delivery_part"), PrimaryKey("Year", "DId", "DPNr")]
@ -99,8 +101,26 @@ namespace Elwig.Models.Entities {
[Column("scale_id")]
public string? ScaleId { get; set; }
[Column("weighing_id")]
public string? WeighingId { get; set; }
[Column("weighing_data")]
public string? WeighingData { get; set; }
[NotMapped]
public (string? Id, int? Gross, int? Tare, int? Net, DateOnly? Date, TimeOnly? Time) WeighingInfo {
get {
try {
var obj = JsonNode.Parse(WeighingData!)!.AsObject();
return (
obj["id"]?.AsValue().GetValue<string>(),
obj["gross_weight"]?.AsValue().GetValue<int>(),
obj["tare_weight"]?.AsValue().GetValue<int>(),
obj["net_weight"]?.AsValue().GetValue<int>(),
DateOnly.TryParseExact(obj["date"]?.AsValue().GetValue<string>(), "yyyy-MM-dd", out var d) ? d : null,
TimeOnly.TryParseExact(obj["time"]?.AsValue().GetValue<string>(), ["HH:mm:ss", "HH:mm"], out var t) ? t : null
);
} catch {
return (null, null, null, null, null, null);
}
}
}
[Column("weighing_reason")]
public string? WeighingReason { get; set; }