Sök betalningar, fördela på mottagare under sökt period

This commit is contained in:
2023-09-12 22:12:45 +02:00
parent 2b6e48c3ef
commit de6e196809
8 changed files with 356 additions and 16 deletions

View File

@ -7,12 +7,19 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinFormDi.UserControls;
using WinFormDiApp.BL.Helpers;
using WinFormDiApp.BL.Models;
using WinFormDiApp.BLI;
namespace WinFormDiApp
{
public partial class frmSearchData : Form
{
private class AccCount : AccountRecord
{
public int NoOfRecs { get; set; }
}
private readonly IAccountRecordRepository _accountRecordRepository;
public frmSearchData(IAccountRecordRepository accountRecordRepository)
@ -25,5 +32,70 @@ namespace WinFormDiApp
{
this.Close();
}
private void btnStartSearch_Click(object sender, EventArgs e)
{
flpPanel1.Controls.Clear();
var result = _accountRecordRepository.GetAllAccBetweenDates(dtpFrom.Value, dtpTo.Value);
var aggregates = aggegateAccounts(result);
foreach (var account in aggregates)
{
var ucCustV = createAndFillUCcv(account);
flpPanel1.Controls.Add(ucCustV);
}
}
private ucCustomerValue createAndFillUCcv(AccCount account)
{
var result = new ucCustomerValue();
result.Amount = String.Format("{0:0.00}", account.Belopp).adjustRight();
result.Receiver = account.Mottagare;
result.Number = Convert.ToString(account.NoOfRecs);
return result;
}
private IEnumerable<AccCount> aggegateAccounts(IEnumerable<AccountRecord> result)
{
List<AccCount> Localresult = new List<AccCount>();
string oldMott = string.Empty;
AccCount wrkRec = null;
foreach (var accountRecord in result)
{
if (accountRecord.Mottagare == oldMott)
{
wrkRec.Belopp += accountRecord.Belopp;
wrkRec.NoOfRecs++;
}
else
{
oldMott = accountRecord.Mottagare;
if (wrkRec != null)
{
Localresult.Add(wrkRec);
wrkRec = AddAccountRecord(accountRecord);
}
else
{
wrkRec = AddAccountRecord(accountRecord);
}
}
}
Localresult.Add(wrkRec);
return Localresult;
}
private AccCount AddAccountRecord(AccountRecord accountRecord)
{
AccCount acc = new AccCount();
acc.NoOfRecs = 1;
acc.BetalDatum = accountRecord.BetalDatum;
acc.Stored = accountRecord.Stored;
acc.Mottagare = accountRecord.Mottagare;
acc.Konto = accountRecord.Konto;
acc.Avisering = accountRecord.Avisering;
acc.Belopp = accountRecord.Belopp;
acc.Id = accountRecord.Id;
return acc;
}
}
}