Files
SHERPA/SHERPA.BBM.UI/Components/ResourcesEditor.razor
T
2021-12-02 16:34:30 +01:00

298 lines
9.9 KiB
Plaintext

@using SHERPA.BBM.UI.Data
@using SHERPA.BBM.UI.Components;
@using CORE.DbModels
@inject BBM_EFService BBMService
<div class="card">
<div class="card-header bg-info text-light">
<b>Modifica</b>
</div>
<div class="card-body small">
<EditForm Model="@_currItem">
<DataAnnotationsValidator />
<Blazorise.ValidationSummary />
<div class="row">
<div class="col-12 col-lg-2">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">
<span class="oi oi-tag" aria-hidden="true"></span>
</span>
</div>
<select @bind="@currResType" class="form-control form-control-sm">
@foreach (var value in Enum.GetValues(typeof(BbmResType)))
{
<option>@value</option>
}
</select>
</div>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">
<span class="fas fa-tags" aria-hidden="true"></span>
</span>
</div>
<select @bind="@SelTagId" class="form-control form-control-sm">
<option value="0">--- Tutti ---</option>
@foreach (var item in tagsList)
{
<option value="@item.TagId">@item.CodTag</option>
}
</select>
</div>
</div>
<div class="col-12 col-lg-4">
<div class="form-group">
<label for="itemSel">Item:</label>
<InputSelect @bind-Value="@SelectedItemId" id="itemSel" class="form-control form-control-sm" title="Oggetto offerta">
@foreach (var item in itemsList)
{
<option value="@item.ItemId">@item.ResType | @item.Descript | @item.UnitPrice.ToString("C2")/@item.UM</option>
}
</InputSelect>
</div>
</div>
<div class="col-12 col-lg-6">
<div class="form-group">
<label for="qtyPrev">Note:</label>
<InputText id="note" @bind-Value="_currItem.Note" class="form-control form-control-sm text-right" title="Note (note risorsa)" />
</div>
</div>
<div class="col-6 col-lg-2 text-right">
<div class="form-group">
<label for="qtyPrev">Qta Prevista (GPW):</label>
<InputNumber id="qtyPrev" @bind-Value="_currItem.QtyPrev" class="form-control form-control-sm text-right" title="Qta Prevista (Budget GPW se ore)" />
</div>
</div>
<div class="col-6 col-lg-2 text-right">
<div class="form-group">
<label for="qtyOff">Qta Offerta:</label>
<InputNumber id="qtyOff" @bind-Value="SelQtyOff" class="form-control form-control-sm text-right" title="Qta Offerta" />
</div>
</div>
<div class="col-6 col-lg-2 text-right">
<div class="form-group">
<label for="unitPriceOff">Prezzo Unitario €:</label>
<InputNumber id="unitPriceOff" @bind-Value="SelPriceOff" class="form-control form-control-sm text-right" title="Prezzo unitario offerto" />
</div>
</div>
<div class="col-6 col-lg-2 text-right">
<div class="form-group">
<label for="unitPriceOff">Sconto €:</label>
<InputNumber id="PriceReduction" @bind-Value="_currItem.PriceReduction" class="form-control form-control-sm text-right" title="Sconto complessivo" />
</div>
</div>
<div class="col-6 col-lg-2 text-right">
<div class="form-group">
<label for="unitPriceOff">Sconto %:</label>
<InputNumber id="PercReduction" @bind-Value="SelPercRed" step="0.0001" class="form-control form-control-sm text-right" title="Sconto percentuale" />
</div>
</div>
<div class="col-6 col-lg-2 text-right">
<div class="form-group">
<label for="unitPriceOff">Importo Finale €:</label>
<InputNumber id="FinalPrice" @bind-Value="_currItem.FinalPrice" class="form-control form-control-sm text-right" title="Prezzo finale offerto" />
</div>
</div>
<div class="col-6 col-lg-3">
<label for="btnSave"></label>
<input type="submit" class="btn btn-sm btn-success btn-block" value="Save" @onclick="saveUpdate" />
</div>
<div class="col-6 col-lg-3 align-bottom">
<label for="btnCancel"></label>
<button type="button" class="btn btn-sm btn-warning btn-block" value="Cancel" @onclick="cancelUpdate">Cancel</button>
</div>
</div>
</EditForm>
</div>
</div>
@code {
private List<CORE.DbModels.ItemsModel> itemsList;
private List<CORE.DbModels.TagModel> tagsList;
protected CORE.DbModels.ResourcesModel _currItem = new ResourcesModel();
[Parameter]
public CORE.DbModels.ResourcesModel currItem
{
get
{
return _currItem = null;
}
set
{
_currItem = value;
}
}
protected BbmResType _currResType = BbmResType.ND;
[Parameter]
public BbmResType currResType
{
get
{
return _currResType;
}
set
{
_currResType = value;
ReloadAllData().ConfigureAwait(false);
}
}
protected int _selTagId = 0;
protected int SelTagId
{
get
{
return _selTagId;
}
set
{
_selTagId = value;
ReloadAllData().ConfigureAwait(false);
}
}
protected int SelectedItemId
{
get
{
int answ = 0;
if (_currItem != null)
{
answ = _currItem.ItemId;
}
return answ;
}
set
{
_currItem.ItemId = value;
// verifico e imposto valori di conseguenza...
var selTask = BBMService.ItemFind(value);
if (selTask != null)
{
_currItem.UnitPriceOff = selTask.Result.UnitPrice;
_currItem.FinalPrice = _currItem.UnitPriceOff * _currItem.QtyOff;
}
}
}
protected double SelQtyOff
{
get
{
double answ = 0;
if (_currItem != null)
{
answ = _currItem.QtyOff;
}
return answ;
}
set
{
_currItem.QtyOff = value;
// verifico e imposto valori di conseguenza...
var selTask = BBMService.ItemFind(_currItem.ItemId);
if (selTask != null)
{
_currItem.UnitPriceOff = selTask.Result.UnitPrice;
_currItem.FinalPrice = _currItem.UnitPriceOff * _currItem.QtyOff;
}
}
}
protected double SelPriceOff
{
get
{
double answ = 0;
if (_currItem != null)
{
answ = _currItem.UnitPriceOff;
}
return answ;
}
set
{
_currItem.UnitPriceOff = value;
// verifico e imposto valori di conseguenza...
var selTask = BBMService.ItemFind(_currItem.ItemId);
if (selTask != null)
{
_currItem.FinalPrice = _currItem.UnitPriceOff * _currItem.QtyOff;
}
}
}
protected double SelPercRed
{
get
{
double answ = 0;
if (_currItem != null)
{
answ = _currItem.PercReduction;
}
return answ;
}
set
{
// se > 1 --> divido per 100...
value = value > 1 ? value / 100 : value;
_currItem.PercReduction = value;
}
}
[Parameter]
public EventCallback<int> DataReset { get; set; }
[Parameter]
public EventCallback<int> DataUpdated { get; set; }
private async Task saveUpdate()
{
if (_currItem != null)
{
BBMService.ResourceUpdate(_currItem);
await DataUpdated.InvokeAsync(1);
}
else
{
Console.WriteLine("Resource null!");
}
}
private async Task cancelUpdate()
{
await DataReset.InvokeAsync(0);
}
protected override async Task OnInitializedAsync()
{
await ReloadAllData();
}
protected async Task ReloadAllData()
{
tagsList = await BBMService.TagsGetAll(TagType.Items);
var rawItems = await BBMService.ItemsGetAsync("", currResType, "");
// filtro x tag se necessario...
if (SelTagId != 0)
{
itemsList = rawItems
.Where(x => x.TagNav.Any(t => t.TagId==SelTagId))
.ToList();
}
else
{
itemsList = rawItems;
}
}
}