142 lines
4.9 KiB
Text
142 lines
4.9 KiB
Text
@page "/contracts"
|
|
@using Umogen.Core;
|
|
@using Umogen.Core.Models;
|
|
@inject IJSRuntime js
|
|
@inject DataContext db
|
|
@using Microsoft.EntityFrameworkCore;
|
|
|
|
<PageTitle>Umowy</PageTitle>
|
|
|
|
<h2 class="text-center">Umowy</h2>
|
|
|
|
<div class="container">
|
|
<form>
|
|
<div class="row justify-content-center align-items-center g-2">
|
|
<div class="col mb-3">
|
|
<label for="employer" class="form-label">Pracodawca (PESEL lub NIP)</label>
|
|
<Autocomplete Value="@_employerId" AcceptedValues="GetEmployers()" Change="ChgEmployer" />
|
|
<span class="validation-message">@(employer == null ? "" : $"{employer.GetName()}")</span>
|
|
</div>
|
|
<div class="col mb-3">
|
|
<label for="employee" class="form-label">Pracownik (PESEL)</label>
|
|
<Autocomplete Value="@_employeeId" AcceptedValues="GetEmployees()" Change="ChgEmployee" />
|
|
<span class="validation-message">@(employee == null ? "" : $"{employee.Name} {employee.Surname}")</span>
|
|
</div>
|
|
</div>
|
|
<div class="row justify-content-center align-items-center g-2">
|
|
<div class="col mb-3">
|
|
<label for="validity" class="form-label">Okres trwania [dni]</label>
|
|
<input type="text" class="form-control" id="validity" @onchange="ChgValidity" value="@_validityText">
|
|
</div>
|
|
<div class="col mb-3">
|
|
<label for="value" class="form-label">Wynagrodzenie [PLN]</label>
|
|
<input type="number" class="form-control" id="value" @bind-value="_payment">
|
|
</div>
|
|
</div>
|
|
<div class="col mb-3">
|
|
<label for="query" class="form-label">Dane (NLP)</label>
|
|
<input type="text" class="form-control" id="query" @bind-value="_query">
|
|
</div>
|
|
<div class="container">
|
|
<button disabled="@disB" type="button" @onclick="Process" class="btn btn-primary">Rozpocznij</button>
|
|
<span hidden="@(!disB)" class="loader"></span>
|
|
<span hidden="@(!disB)" class="output-box">@output</span>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
|
|
@code {
|
|
private string _employerId = "", _employeeId = "";
|
|
private Person? employee;
|
|
private IEntity? employer;
|
|
private string _query = "";
|
|
private ValidTime _validity;
|
|
private decimal _payment;
|
|
private string output = "";
|
|
private bool disB = false;
|
|
|
|
private async Task ChgEmployer(ChangeEventArgs e)
|
|
{
|
|
_employerId = (string)e.Value!;
|
|
employer = await db.Persons.AsNoTracking().SingleOrDefaultAsync(s => s.Pesel == _employerId) as IEntity ?? await
|
|
db.Companies.AsNoTracking().SingleOrDefaultAsync(s => s.Nip == _employerId);
|
|
StateHasChanged();
|
|
}
|
|
|
|
private async Task ChgEmployee(ChangeEventArgs e)
|
|
{
|
|
_employeeId = (string)e.Value!;
|
|
employee = await db.Persons.AsNoTracking().SingleOrDefaultAsync(s => s.Pesel == _employeeId);
|
|
}
|
|
|
|
private string _validityText = "";
|
|
|
|
private async Task ChgValidity(ChangeEventArgs e)
|
|
{
|
|
string val = (string)e.Value!;
|
|
_validityText = val;
|
|
StateHasChanged();
|
|
|
|
var now = DateTime.Now;
|
|
|
|
if (!TimeSpan.TryParse(val, out TimeSpan span))
|
|
{
|
|
_validityText = "nieokreślony";
|
|
_validity = ValidTime.Invalid;
|
|
}
|
|
|
|
if (span.TotalDays < 1)
|
|
{
|
|
_validityText = "nieokreślony";
|
|
_validity = ValidTime.Invalid;
|
|
StateHasChanged();
|
|
return;
|
|
}
|
|
|
|
_validityText = $"{span.TotalDays} d";
|
|
_validity = new ValidTime(now, span);
|
|
}
|
|
|
|
private IEnumerable<(string, string)> GetEmployers()
|
|
{
|
|
var pers = db.Persons.AsNoTracking().AsEnumerable().Select(p => ($"{p.Name} {p.Surname}", p.Pesel));
|
|
var comp = db.Companies.AsNoTracking().AsEnumerable().Select(c => (c.Name, c.Nip!));
|
|
|
|
return pers.Union(comp);
|
|
}
|
|
|
|
private IEnumerable<(string, string)> GetEmployees()
|
|
{
|
|
return db.Persons.AsNoTracking().AsEnumerable().Select(p => ($"{p.Name} {p.Surname}", p.Pesel));
|
|
}
|
|
|
|
private async Task Process()
|
|
{
|
|
disB = true;
|
|
this.StateHasChanged();
|
|
await Task.Yield();
|
|
|
|
output = string.Empty;
|
|
using UmoEngine eng = new();
|
|
UmoProcess proc = new(eng);
|
|
Thread.Yield();
|
|
|
|
await foreach (var str in proc.Ask(_query + $" wynagrodzenie {_payment} zł"))
|
|
{
|
|
output += str;
|
|
Console.Write(str);
|
|
this.StateHasChanged();
|
|
}
|
|
|
|
var anal = System.Text.Json.JsonSerializer.Deserialize<UmoAnalModel>(output, Umogen.JSON_OPTS);
|
|
UmoDocumentResult res = new(null, employee, employer, _validity, _payment,
|
|
anal);
|
|
|
|
var bytes = await res.ProcessPdf(Path.Combine(Environment.GetEnvironmentVariable("UMO_TEMPLATES")!,
|
|
anal.Doctype.TemplateDoc()));
|
|
await js.InvokeVoidAsync("blobby", bytes);
|
|
|
|
disB = false;
|
|
this.StateHasChanged();
|
|
}
|
|
}
|