Update gestione spsotamento negoziazioni

This commit is contained in:
Samuele Locatelli
2024-02-10 12:32:32 +01:00
parent a3c8f0b65a
commit f810f0bdee
5 changed files with 694 additions and 0 deletions
@@ -8,6 +8,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
namespace SHERPA.BBM.CORE.Controllers
{
@@ -1696,6 +1697,51 @@ namespace SHERPA.BBM.CORE.Controllers
return dbResult;
}
/// <summary>
/// Sposta negoziazione nel basket indicato
/// </summary>
/// <param name="NegotiationId"></param>
/// <param name="BasketId"></param>
/// <returns></returns>
public bool NegotiationMoveBasket(int negotiationId, int basketId)
{
bool done = false;
using (SHERPABBMContext dbCtx = new SHERPABBMContext(_configuration))
{
try
{
var currData = dbCtx
.DbSetNegotiations
.Where(x => x.NegotiationId == negotiationId)
.FirstOrDefault();
if (currData != null)
{
// recupero eventuali ordini di questa negoziazione
var orderAssociated = dbCtx
.DbSetOrders
.Where(x => x.NegotiationId == currData.NegotiationId)
.ToList();
// aggiorno ordini al NUOVO basket!
foreach (var item in orderAssociated)
{
item.BasketId = basketId;
dbCtx.Entry(item).State = EntityState.Modified;
}
currData.BasketId = basketId;
dbCtx.Entry(currData).State = EntityState.Modified;
}
dbCtx.SaveChanges();
done = true;
}
catch (Exception exc)
{
LogException("Eccezione in NegotiationMoveBasket", exc);
}
}
return done;
}
public int NegotiationsCount()
{
int answ = 0;
@@ -0,0 +1,42 @@
@using SHERPA.BBM.UI.Data
@inject BBM_EFService BBMService
@inject MessageService MessageService
<table class="table table-sm table-striped ">
<thead>
<tr>
<th></th>
<th>Cod</th>
<th>Descrizione</th>
<th class="text-right">Importo</th>
<th class="text-right">Fatturazione</th>
</tr>
</thead>
<tbody>
@foreach (var record in ListRecords)
{
<tr class="@checkSelect(@record.NegotiationId)">
<td class="text-nowrap">
<button class="btn btn-sm btn-info" @onclick="() => Move(record)"><span class="fas fa-arrows-alt-h"></span></button>
</td>
<td>
<div>@record.RagSoc</div>
<div>@record.CodNegotiation</div>
<div class="small">@record.DataIns.ToString("ddd yyyy.MM.dd HH:mm")</div>
</td>
<td>
<div>@record.Descript</div>
<div class="small">@record.NumDocs</div>
</td>
<td class="text-right text-nowrap" title="Importo"><b>@record.Importo.ToString("C2")</b></td>
<td class="text-right text-nowrap" title="Fatturato"><b>@record.Fatturato.ToString("C2")</b></td>
</tr>
}
</tbody>
</table>
<div class="small">
<DataPager PageSize="numRecord" currPage="currPage" numRecordChanged="ForceReload" numPageChanged="ForceReloadPage" totalCount="totalCount" showLoading="isLoading" />
</div>
@@ -0,0 +1,176 @@
using Microsoft.AspNetCore.Components;
using SHERPA.BBM.CORE.DbModels;
namespace SHERPA.BBM.UI.Components
{
public partial class NegotMovList
{
#region Public Properties
[Parameter]
public int AnnoSel { get; set; } = 0;
[Parameter]
public int CustomerId { get; set; } = 0;
[Parameter]
public EventCallback<int> MoveRequested { get; set; }
[Parameter]
public int BaskIdSour
{
get
{
return baskIdSour;
}
set
{
baskIdSour = value;
// condiziono visualizzazione...
var pUpd = Task.Run(async () => await ReloadAllData());
pUpd.Wait();
}
}
#endregion Public Properties
#region Public Methods
public string btnFromState(bool isActive)
{
string answ = isActive ? "btn-success" : "btn-outline-warning";
return answ;
}
public string checkSelect(int NegotId)
{
string answ = "";
if (currItem != null)
{
try
{
answ = (currItem.NegotiationId == NegotId) ? "table-info" : "";
}
catch
{
}
}
return answ;
}
public async void OnSeachUpdated()
{
await InvokeAsync(() =>
{
Task task = UpdateData();
StateHasChanged();
});
}
public string tooltipFromState(bool isActive)
{
string answ = isActive ? "Attivo" : "Imposta Attivo";
return answ;
}
#endregion Public Methods
#region Protected Fields
protected int totalCount = 0;
#endregion Protected Fields
#region Protected Methods
protected async Task ForceReload(int newNum)
{
numRecord = newNum;
await ReloadAllData();
}
protected async Task ForceReloadPage(int newNum)
{
currPage = newNum;
await ReloadAllData();
}
protected async Task Move(vNegotiationsDataModel currRecord)
{
// riporto richiesta spostamento
await MoveRequested.InvokeAsync(currRecord.NegotiationId);
}
protected override async Task OnInitializedAsync()
{
MessageService.ShowSearch = true;
MessageService.SearchVal = "";
MessageService.EA_SearchUpdated += OnSeachUpdated;
await ReloadAllData();
}
protected async Task ReloadAllData()
{
await updateTable();
}
protected void ResetData()
{
if (currItem != null)
{
BBMService.rollBackEdit(currItem);
}
currItem = null;
}
protected async Task UpdateData()
{
currItem = null;
await ReloadAllData();
}
protected async Task updateTable()
{
SearchRecords = await BBMService.NegotiationsGetAsync(AnnoSel, 0, CustomerId, BaskIdSour, MessageService.SearchVal);
totalCount = SearchRecords.Count();
ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList();
}
#endregion Protected Methods
#region Private Fields
private bool _showAllDoc = false;
private vNegotiationsDataModel? currItem = null;
private bool isLoading = false;
private List<vNegotiationsDataModel> ListRecords = new List<vNegotiationsDataModel>();
private List<vNegotiationsDataModel> SearchRecords = new List<vNegotiationsDataModel>();
#endregion Private Fields
#region Private Properties
private int baskIdSour { get; set; } = 0;
private int currPage { get; set; } = 1;
private int numRecord { get; set; } = 10;
private bool ShowAllDoc
{
get
{
return _showAllDoc;
}
set
{
_showAllDoc = value;
updateTable().ConfigureAwait(false);
}
}
#endregion Private Properties
}
}
+150
View File
@@ -0,0 +1,150 @@
@page "/NegotMover"
@using SHERPA.BBM.UI.Components
@using SHERPA.BBM.UI.Data
@using CORE.DbModels
@inject BBM_EFService BBMService
<div class="card">
<div class="card-header">
<div class="row">
<div class="col-8">
<h4><span class="fas fa-exchange-alt pr-3" aria-hidden="true"></span> Spostamento Trattative</h4>
</div>
<div class="col-4 text-right">
<div class="input-group input-group-sm">
<div class="input-group-prepend">
<span class="input-group-text">
<span class="oi oi-calendar" aria-hidden="true"></span>
</span>
</div>
<select @bind="@YearSel" class="form-control form-control-sm">
<option value="0">--- Tutti ---</option>
@foreach (var item in yearsList)
{
<option value="@item">@item</option>
}
</select>
<div class="input-group-append">
<button class="@cssBtnResYear" @onclick="ResetYear"><i class="fas fa-undo"></i></button>
</div>
</div>
</div>
</div>
</div>
<div class="card-body">
@if (isLoading)
{
<div class="w-100">
<LoadingData DisplayMode="LoadingData.SpinMode.Normal" DisplaySize="LoadingData.CtrlSize.Large"></LoadingData>
</div>
}
else
{
<div class="row">
<div class="col-6">
<div class="d-flex flex-column small">
<div class="py-1">
<div class="row">
<div class="col-4">
<label>Cliente:</label>
<div class="input-group input-group-sm">
<div class="input-group-prepend">
<span class="input-group-text">
<span class="fas fa-users" aria-hidden="true"></span>
</span>
</div>
<select @bind="@SelCustomerIdSx" class="form-control form-control">
@foreach (var item in CustomersList)
{
<option value="@item.CustomerId">@item.RagSoc</option>
}
</select>
<div class="input-group-append">
<button class="@cssBtnResCustSx" @onclick="ResetCustSx"><i class="fas fa-undo"></i></button>
</div>
</div>
</div>
<div class="col-8">
<label>Basket:</label>
<div class="input-group input-group-sm">
<div class="input-group-prepend">
<span class="input-group-text">
<span class="oi oi-basket" aria-hidden="true"></span>
</span>
</div>
<select @bind="@SelBasketIdSx" class="form-control form-control">
<option value="1">-- Tutti ---</option>
@foreach (var item in BasketListSx)
{
<option value="@item.BasketId">@item.CodBasket - @item.Descript</option>
}
</select>
<div class="input-group-append">
<button class="@cssBtnResBaskSx" @onclick="ResetBasketSx"><i class="fas fa-undo"></i></button>
</div>
</div>
</div>
</div>
</div>
</div>
<NegotMovList AnnoSel="@YearSel" BaskIdSour="@SelBasketIdSx" MoveRequested="moveRight"></NegotMovList>
</div>
<div class="col-6">
<div class="d-flex flex-column small">
<div class="py-1">
<div class="row">
<div class="col-4">
<label>Cliente:</label>
<div class="input-group input-group-sm">
<div class="input-group-prepend">
<span class="input-group-text">
<span class="fas fa-users" aria-hidden="true"></span>
</span>
</div>
<select @bind="@SelCustomerIdDx" class="form-control form-control">
@foreach (var item in CustomersList)
{
<option value="@item.CustomerId">@item.RagSoc</option>
}
</select>
<div class="input-group-append">
<button class="@cssBtnResCustDx" @onclick="ResetCustDx"><i class="fas fa-undo"></i></button>
</div>
</div>
</div>
<div class="col-8">
<label>Basket:</label>
<div class="input-group input-group-sm">
<div class="input-group-prepend">
<span class="input-group-text">
<span class="oi oi-basket" aria-hidden="true"></span>
</span>
</div>
<select @bind="@SelBasketIdDx" class="form-control form-control">
<option value="1">--- Tutti ---</option>
@if (BasketListDx != null)
{
@foreach (var item in BasketListDx)
{
<option value="@item.BasketId">@item.CodBasket - @item.Descript</option>
}
}
</select>
<div class="input-group-append">
<button class="@cssBtnResBaskDx" @onclick="ResetBasketDx"><i class="fas fa-undo"></i></button>
</div>
</div>
</div>
</div>
</div>
</div>
<NegotMovList AnnoSel="@YearSel" BaskIdSour="@SelBasketIdDx" MoveRequested="moveLeft"></NegotMovList>
</div>
</div>
}
</div>
</div>
+280
View File
@@ -0,0 +1,280 @@
using Microsoft.AspNetCore.Components;
using SHERPA.BBM.CORE.DbModels;
using SHERPA.BBM.UI.Data;
namespace SHERPA.BBM.UI.Pages
{
public partial class NegotMover : IDisposable
{
#region Public Methods
public void Dispose()
{
BBMService.ReloadRequest -= BBMService_ReloadRequest;
}
#endregion Public Methods
#region Protected Fields
protected int _dxBaskId = 1;
protected int _dxCustId = 1;
protected int _dxNegoId = 1;
protected int _sxBaskId = 1;
protected int _sxCustId = 1;
protected int _sxNegoId = 1;
#endregion Protected Fields
#region Protected Properties
[Inject]
protected MessageService MService { get; set; } = null!;
protected int YearSel
{
get => yearSel;
set
{
if (yearSel != value)
{
yearSel = value;
// condiziono visualizzazione...
var pUpd = Task.Run(async () => await ReloadAllData());
pUpd.Wait();
}
}
}
#endregion Protected Properties
#region Protected Methods
protected async Task moveLeft(int currIdx)
{
if (SelBasketIdSx > 0)
{
// eseguo spostamento...
await BBMService.NegotiationMoveBasket(currIdx, SelBasketIdSx);
}
}
protected async Task moveRight(int currIdx)
{
if (SelBasketIdDx > 0)
{
// eseguo spostamento...
await BBMService.NegotiationMoveBasket(currIdx, SelBasketIdDx);
}
}
protected override async Task OnInitializedAsync()
{
isLoading = true;
BBMService.ReloadRequest += BBMService_ReloadRequest;
await Task.Delay(1);
MService.NotifyHeadChanged();
await ReloadAllData();
isLoading = false;
}
protected async Task ReloadDataDx()
{
CustomersList = await BBMService.CustomersGetAll("");
BasketListDx = await BBMService.BasketsGetAsync(1, YearSel);
}
protected async Task ReloadDataSx()
{
CustomersList = await BBMService.CustomersGetAll("");
BasketListSx = await BBMService.BasketsGetAsync(1, YearSel);
}
#endregion Protected Methods
#region Private Fields
private List<vBasketsDataModel> BasketListDx = new List<vBasketsDataModel>();
private List<vBasketsDataModel> BasketListSx = new List<vBasketsDataModel>();
private List<CustomersModel> CustomersList = new List<CustomersModel>();
private int yearSel = 0;
private List<int> yearsList = new List<int>();
#endregion Private Fields
#region Private Properties
private string cssBtnResBaskDx
{
get => SelBasketIdDx == 1 ? "btn btn-secondary" : "btn btn-primary";
}
private string cssBtnResBaskSx
{
get => SelBasketIdSx == 1 ? "btn btn-secondary" : "btn btn-primary";
}
private string cssBtnResCustDx
{
get => SelCustomerIdDx == 1 ? "btn btn-secondary" : "btn btn-primary";
}
private string cssBtnResCustSx
{
get => SelCustomerIdSx == 1 ? "btn btn-secondary" : "btn btn-primary";
}
private string cssBtnResYear
{
get => YearSel == 0 ? "btn btn-secondary" : "btn btn-primary";
}
private bool isLoading { get; set; } = false;
private int SelBasketIdDx
{
get
{
return _dxBaskId;
}
set
{
_dxBaskId = value;
// condiziono visualizzazione...
var pUpd = Task.Run(async () => await ReloadDataDx());
pUpd.Wait();
}
}
private int SelBasketIdSx
{
get
{
return _sxBaskId;
}
set
{
_sxBaskId = value;
// condiziono visualizzazione...
var pUpd = Task.Run(async () => await ReloadDataSx());
pUpd.Wait();
}
}
private int SelCustomerIdDx
{
get
{
return _dxCustId;
}
set
{
_dxCustId = value;
// condiziono visualizzazione...
var pUpd = Task.Run(async () => await ReloadDataDx());
pUpd.Wait();
}
}
private int SelCustomerIdSx
{
get
{
return _sxCustId;
}
set
{
_sxCustId = value;
// condiziono visualizzazione...
var pUpd = Task.Run(async () => await ReloadDataSx());
pUpd.Wait();
}
}
#endregion Private Properties
#region Private Methods
private async void BBMService_ReloadRequest(object? sender, EventArgs e)
{
ReloadEventArgs currArgs = (ReloadEventArgs)e;
if (!string.IsNullOrEmpty(currArgs.ReloadMessage))
{
await ReloadAllData();
await InvokeAsync(StateHasChanged);
}
}
private async Task ReloadAllData()
{
yearsList = await BBMService.DocsYears();
await ReloadDataSx();
await ReloadDataDx();
}
private async Task ResetBasketDx()
{
if (SelBasketIdDx != 1)
{
SelBasketIdDx = 1;
await Task.Delay(1);
}
}
private async Task ResetBasketSx()
{
if (SelBasketIdSx != 1)
{
SelBasketIdSx = 1;
await Task.Delay(1);
}
}
private async Task ResetCustDx()
{
if (SelCustomerIdDx != 1)
{
SelCustomerIdDx = 1;
await Task.Delay(1);
}
}
private async Task ResetCustSx()
{
if (SelCustomerIdSx != 1)
{
SelCustomerIdSx = 1;
await Task.Delay(1);
}
}
private async Task ResetYear()
{
if (YearSel != 0)
{
YearSel = 0;
await Task.Delay(1);
}
}
private string trimTxt(string txtOrig, int maxChar)
{
string answ = txtOrig;
if (txtOrig.Length > maxChar)
{
answ = $"{txtOrig.Substring(0, maxChar - 3)}...";
}
return answ;
}
#endregion Private Methods
}
}