This commit is contained in:
mmrbnjd
2024-09-08 17:23:33 +03:30
parent 745412ee56
commit b81c950c39
9 changed files with 468 additions and 126 deletions

View File

@@ -1,4 +1,5 @@
using Back.Common; using Back.Common;
using Back.Data.Contracts;
using Back.Data.Models; using Back.Data.Models;
using Back.Services; using Back.Services;
using Back.Validations; using Back.Validations;
@@ -10,6 +11,7 @@ using Shared.DTOs;
using System.Net; using System.Net;
using System.Runtime.ConstrainedExecution; using System.Runtime.ConstrainedExecution;
using System.Security.Cryptography; using System.Security.Cryptography;
using static Shared.DTOs._TaxPayer;
namespace Back.Controllers namespace Back.Controllers
{ {
@@ -31,8 +33,13 @@ namespace Back.Controllers
_servInvoice = servInvoice; _servInvoice = servInvoice;
} }
[HttpGet("PaymentMethods")]
public async Task<ActionResult<List<IdName<string>>>> PaymentMethods()
{
return Ok(await _servpay.GetPaymentMethods());
}
[HttpPost("AddPay")] [HttpPost("AddPay")]
public async Task<ActionResult<bool>> AddItem([FromBody] InvoiceItemAction<InvoicePaymentDTO> model) public async Task<ActionResult<InvoicePaymentDTO>> AddItem([FromBody] InvoiceItemAction<InvoicePaymentDTO> model)
{ {
//-----GetUserAndCompany //-----GetUserAndCompany
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID"); var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
@@ -49,12 +56,15 @@ namespace Back.Controllers
if (invoice == null) if (invoice == null)
return BadRequest(new List<string> { "invoice notFound..." }); return BadRequest(new List<string> { "invoice notFound..." });
//-------------pmt
List<Back.Data.Models.Coding> codings = await _servInvoice.GetCodingPMT();
//-----------------------
invoice.LastChangeUserID = Convert.ToInt32(UserID); invoice.LastChangeUserID = Convert.ToInt32(UserID);
if (await _servInvoice.UpdateInvoice(invoice)) if (await _servInvoice.UpdateInvoice(invoice))
{ {
return Ok(await _servpay.Add(new Data.Models.InvoicePayment var item = await _servpay.Add(new Data.Models.InvoicePayment
{ {
InvoiceID = model.invoiceID, InvoiceID = model.invoiceID,
acn = model.item.acn, acn = model.item.acn,
@@ -68,7 +78,21 @@ namespace Back.Controllers
trn = model.item.trn, trn = model.item.trn,
})); });
return Ok(item!=null ?new InvoicePaymentDTO
{
ID = item.ID,
acn = item.acn,
iinn = item.acn,
pcn = item.acn,
PaymentDateTime = item.PaymentDateTime.ShamciToFormatShamci(),
pid = item.pid,
pmt = item.pmt,
pv = item.pv,
trmn = item.trmn,
trn = item.acn,
paymentMethod = item.pmt.HasValue ? codings.Where(w => w.Code == item.pmt.Value.ToString()).Select(s => s.Title).FirstOrDefault() : null,
} :null);
} }
else return BadRequest(new List<string> { "خطایی رخ داده" }); else return BadRequest(new List<string> { "خطایی رخ داده" });
@@ -124,7 +148,29 @@ namespace Back.Controllers
item.trn = model.item.trn; item.trn = model.item.trn;
if (await _servInvoice.UpdateInvoice(invoice)) if (await _servInvoice.UpdateInvoice(invoice))
return Ok(await _servpay.Update(item)); {
var modelout = await _servpay.Update(item);
//-------------pmt
List<Back.Data.Models.Coding> codings = await _servInvoice.GetCodingPMT();
//-----------------------
return Ok(modelout!=null ? new InvoicePaymentDTO
{
ID = modelout.ID,
acn = modelout.acn,
iinn = modelout.acn,
pcn = modelout.acn,
PaymentDateTime = modelout.PaymentDateTime.ShamciToFormatShamci(),
pid = modelout.pid,
pmt = modelout.pmt,
pv = modelout.pv,
trmn = modelout.trmn,
trn = modelout.acn,
paymentMethod = modelout.pmt.HasValue ? codings.Where(w => w.Code == modelout.pmt.Value.ToString()).Select(s => s.Title).FirstOrDefault() : null,
} : null);
}
else else
return BadRequest(new List<string> { "خطایی رخ داده" }); return BadRequest(new List<string> { "خطایی رخ داده" });

View File

@@ -82,6 +82,7 @@ builder.Services.AddScoped<ServPromotion>();
builder.Services.AddScoped<ServOrders>(); builder.Services.AddScoped<ServOrders>();
builder.Services.AddScoped<ServPricing>(); builder.Services.AddScoped<ServPricing>();
builder.Services.AddScoped<ServWalt>(); builder.Services.AddScoped<ServWalt>();
builder.Services.AddScoped<AUInvoicePayValidation>();
builder.Services.AddScoped(c => new mpNuget.RestClient("09119660045", "C54S2")); builder.Services.AddScoped(c => new mpNuget.RestClient("09119660045", "C54S2"));
string origins = "OriginTaxPayer"; string origins = "OriginTaxPayer";

View File

@@ -10,15 +10,20 @@ namespace Back.Services
public class servInvoice public class servInvoice
{ {
private readonly IAsyncRepository<Invoice> _invoiceRepo; private readonly IAsyncRepository<Invoice> _invoiceRepo;
private readonly IAsyncRepository<Coding> _CodingRepo;
private readonly IAsyncRepository<InvoiceStatusChang> _invoiceStatusChangPaymentRepo; private readonly IAsyncRepository<InvoiceStatusChang> _invoiceStatusChangPaymentRepo;
private readonly CheckPermission _checkPermission; private readonly CheckPermission _checkPermission;
public servInvoice(IAsyncRepository<Invoice> invoiceRepo, CheckPermission checkPermission public servInvoice(IAsyncRepository<Invoice> invoiceRepo, CheckPermission checkPermission
, IAsyncRepository<InvoiceStatusChang> invoiceStatusChangPaymentRepo) , IAsyncRepository<InvoiceStatusChang> invoiceStatusChangPaymentRepo, IAsyncRepository<Coding> codingRepo)
{ {
_invoiceStatusChangPaymentRepo = invoiceStatusChangPaymentRepo; _invoiceStatusChangPaymentRepo = invoiceStatusChangPaymentRepo;
_invoiceRepo = invoiceRepo; _invoiceRepo = invoiceRepo;
_checkPermission = checkPermission; _checkPermission = checkPermission;
_CodingRepo = codingRepo;
}
public async Task<List<Coding>> GetCodingPMT()
{
return await _CodingRepo.Get(w => w.FildID == 71).ToListAsync();
} }
public async Task<InvoiceDTO?> GetInvoice(int CompanyID, int ID, bool notloaddelete = true) public async Task<InvoiceDTO?> GetInvoice(int CompanyID, int ID, bool notloaddelete = true)
{ {
@@ -33,18 +38,16 @@ namespace Back.Services
} }
#endregion #endregion
//----------------------- //-----------------------
var item= await invok var item = await invok.Include(inc => inc.invoiceDetails) .ThenInclude(inc => inc.cODItem).ThenInclude(inc => inc.CODUnit).Include(inc => inc.Customer)
.Include(inc => inc.invoiceDetails) .Include(inc => inc.sentTax).Include(inc => inc.payments).Include(inc => inc.pattern).ThenInclude(inc => inc.BillType).FirstOrDefaultAsync();
.ThenInclude(inc => inc.cODItem)
.ThenInclude(inc => inc.CODUnit)
.Include(inc => inc.Customer)
.Include(inc => inc.sentTax)
.Include(inc => inc.payments)
.Include(inc => inc.pattern)
.ThenInclude(inc => inc.BillType)
.FirstOrDefaultAsync(); //-------------pmt
return new InvoiceDTO() List<Coding> codings = new List<Coding>();
if (item != null)
codings =await GetCodingPMT();
//-----------------------
return new InvoiceDTO()
{ {
IsDeleted = item.IsDeleted, IsDeleted = item.IsDeleted,
@@ -66,33 +69,33 @@ namespace Back.Services
tvam = item.tvam, tvam = item.tvam,
Udate = item.Udate.ShamciToFormatShamci(), Udate = item.Udate.ShamciToFormatShamci(),
inno = item.inno, inno = item.inno,
InvoiceSendTaxs = item.sentTax.OrderBy(o => o.ID).Select(s => new SentTaxDto() InvoiceSendTaxs = item.sentTax.OrderBy(o => o.ID).Select(s => new SentTaxDto()
{ {
Date = s.Date.ShamciToFormatShamci(), Date = s.Date.ShamciToFormatShamci(),
Time = s.Time, Time = s.Time,
ID = s.ID, ID = s.ID,
InvoiceID = s.InvoiceID, InvoiceID = s.InvoiceID,
SentStatus = s.SentStatus, SentStatus = s.SentStatus,
InvoiceType = s.InvoiceType, InvoiceType = s.InvoiceType,
msgInvoiceType = s.InvoiceType.GetEnumDisplayName(), msgInvoiceType = s.InvoiceType.GetEnumDisplayName(),
msgSentStatus = s.SentStatus.GetEnumDisplayName() msgSentStatus = s.SentStatus.GetEnumDisplayName()
}).ToList(), }).ToList(),
items = item.invoiceDetails.OrderBy(o => o.ID).Select(x => new InvoiceItemDTO() items = item.invoiceDetails.OrderBy(o => o.ID).Select(x => new InvoiceItemDTO()
{ {
ID = x.ID, ID = x.ID,
CODID = x.CODID, CODID = x.CODID,
adis = x.adis, adis = x.adis,
am = x.am.Value, am = x.am.Value,
dis = x.dis, dis = x.dis,
fee = x.fee.Value, fee = x.fee.Value,
mu = x.unitTitle, mu = x.unitTitle,
sstt = x.sstt, sstt = x.sstt,
tsstam = x.tsstam, tsstam = x.tsstam,
vam = x.vam, vam = x.vam,
vra = x.vra, vra = x.vra,
prdis = x.prdis prdis = x.prdis
}).ToList(), }).ToList(),
payments = payments =
item.payments.OrderBy(o => o.ID).Select(x => new InvoicePaymentDTO() item.payments.OrderBy(o => o.ID).Select(x => new InvoicePaymentDTO()
{ {
ID = x.ID, ID = x.ID,
@@ -104,9 +107,10 @@ namespace Back.Services
pmt = x.pmt, pmt = x.pmt,
pv = x.pv, pv = x.pv,
trmn = x.trmn, trmn = x.trmn,
trn = x.acn trn = x.acn,
paymentMethod = x.pmt.HasValue ? codings.Where(w=>w.Code== x.pmt.Value.ToString()).Select(s=>s.Title).FirstOrDefault() : null,
}).ToList() }).ToList()
}; };
} }
@@ -144,7 +148,7 @@ namespace Back.Services
.ThenInclude(inc => inc.CODUnit) .ThenInclude(inc => inc.CODUnit)
//.Include(inc => inc.payments) //.Include(inc => inc.payments)
.Include(inc => inc.pattern) .Include(inc => inc.pattern)
.OrderByDescending(o=>o.ID) .OrderByDescending(o => o.ID)
.Select(s => new InvoiceGridDTO() .Select(s => new InvoiceGridDTO()
{ {
@@ -232,7 +236,7 @@ namespace Back.Services
.Include(inc => inc.sentTax) .Include(inc => inc.sentTax)
.Include(inc => inc.pattern) .Include(inc => inc.pattern)
.Include(inc => inc.invoice) .Include(inc => inc.invoice)
.Include(inc=>inc.payments) .Include(inc => inc.payments)
.FirstOrDefaultAsync(); .FirstOrDefaultAsync();
} }
public async Task<bool> DeleteInvoice(Invoice item) public async Task<bool> DeleteInvoice(Invoice item)

View File

@@ -9,17 +9,19 @@ namespace Back.Services
public class servInvoicePayment public class servInvoicePayment
{ {
private readonly IAsyncRepository<InvoicePayment> _Repo; private readonly IAsyncRepository<InvoicePayment> _Repo;
public servInvoicePayment(IAsyncRepository<InvoicePayment> Repo) private readonly IAsyncRepository<Coding> _CodingRepo;
public servInvoicePayment(IAsyncRepository<InvoicePayment> Repo, IAsyncRepository<Coding> CodingRepo)
{ {
_Repo = Repo; _Repo = Repo;
_CodingRepo = CodingRepo;
} }
public async Task<bool> Add(InvoicePayment item) public async Task<InvoicePayment> Add(InvoicePayment item)
{ {
return await _Repo.AddBoolResultAsync(item); return await _Repo.AddAsync(item);
} }
public async Task<bool> Update(InvoicePayment item) public async Task<InvoicePayment> Update(InvoicePayment item)
{ {
return await _Repo.UpdateAsync(item); return await _Repo.UpdateByObjAsync(item);
} }
public async Task<bool> Delete(InvoicePayment item) public async Task<bool> Delete(InvoicePayment item)
{ {
@@ -40,6 +42,15 @@ namespace Back.Services
{ {
return await _Repo.Get(w => w.InvoiceID == invoiceID && w.ID == ID && w.invoice.CompanyID == companyID).FirstOrDefaultAsync(); return await _Repo.Get(w => w.InvoiceID == invoiceID && w.ID == ID && w.invoice.CompanyID == companyID).FirstOrDefaultAsync();
} }
public async Task<List<IdName<string>>> GetPaymentMethods()
{
return await _CodingRepo.Get(w => w.FildID == 71)
.Select(s=>new IdName<string>
{
ID=s.Code,Title=s.Title
}).ToListAsync();
}
} }
} }

View File

@@ -23,29 +23,7 @@ namespace Back.Validations
}); });
}); });
When(m => m.Item4 == eActionValidation.update || m.Item4 == eActionValidation.add, () =>
{
RuleFor(r => r.Item3).Custom((model, context) =>
{
if (model.pmt.HasValue && model.pmt.Value > 0 && model.pmt.Value < 9)
{
}
else context.AddFailure("روش پرداخت مشخص نشده");
});
//RuleFor(r => r).Custom(async (model, context) =>
//{
// if (model.Item3.dis != null && model.Item3.dis > 0)
// if (model.Item3.dis > model.Item3.am * model.Item3.fee)
// context.AddFailure("مبلغ تخفیف نمی تواند از (تعداد * مبلغ واحد) بیشتر باشد");
//});
});
RuleFor(r => r) RuleFor(r => r)
.Custom((model, context) => .Custom((model, context) =>
{ {
@@ -61,7 +39,33 @@ namespace Back.Validations
if (model.Item4 == eActionValidation.update || model.Item4 == eActionValidation.add) if (model.Item4 == eActionValidation.update || model.Item4 == eActionValidation.add)
{ {
var totalpay = invoice.payments.Sum(s => s.pv).GetValueOrDefault() + model.Item3.pv; var totalpay = invoice.payments.Sum(s => s.pv).GetValueOrDefault() + model.Item3.pv;
if (totalpay > invoice.tbill) context.AddFailure("مجموع مبلغ پرداختی میبایست از مجموع صورتحساب کوچکتر باشد."); if (totalpay > invoice.tbill) context.AddFailure("مجموع مبلغ پرداختی نمی تواند از مجموع صورتحساب بیشتر باشد.");
else
{
if (model.Item3.pmt.HasValue && model.Item3.pmt.Value > 0 && model.Item3.pmt.Value < 9)
{
if (string.IsNullOrEmpty(model.Item3.PaymentDateTime))
{
context.AddFailure("تاریخ نمیتواند خالی باشد");
}
else
{
string paydate = model.Item3.PaymentDateTime.Replace("/", "");
if (paydate.Length == 8 && int.TryParse(paydate, out int _paydate))
{
if (Convert.ToInt32(invoice.InvoiceDate) > _paydate)
{
context.AddFailure("تاریخ پرداخت نمیتواند از تاریخ صورتحساب عقبتر باشد");
}
}
else context.AddFailure("تاریخ صحیح نمی باشد");
}
}
else context.AddFailure("روش پرداخت مشخص نشده");
}
} }

View File

@@ -131,6 +131,7 @@ namespace Shared.DTOs
//روش پرداخت //روش پرداخت
[MaxLength(2)] [MaxLength(2)]
public int? pmt { get; set; } public int? pmt { get; set; }
public string? paymentMethod { get; set; }
//شماره پیگیری/شماره مرجع //شماره پیگیری/شماره مرجع
[MaxLength(14)] [MaxLength(14)]
public string? trn { get; set; } public string? trn { get; set; }

View File

@@ -1,81 +1,331 @@
@using Shared.DTOs @using Front.Services
@using Shared.DTOs
@inject Fixedvalues fv;
@inject HttpClientController hc;
<Grid @ref="grid" <Grid @ref="grid"
TItem="InvoicePaymentDTO" TItem="InvoicePaymentDTO"
Class="table table-hover table-bordered table-striped mt-3" Class="table table-hover table-bordered table-striped mt-3"
Data="payments"> Data="invoice.payments"
OnRowClick="OnRowClick">
<GridColumns> <GridColumns>
<GridColumn TItem="InvoicePaymentDTO" HeaderText="شناسه" PropertyName="ID"> <GridColumn TItem="InvoicePaymentDTO" TextAlignment="Alignment.Center" HeaderTextAlignment="Alignment.Center" HeaderText="شماره سوییچ پرداخت" PropertyName="iinn">
@context.ID
</GridColumn>
<GridColumn TItem="InvoicePaymentDTO" HeaderText="شماره سوییچ پرداخت" PropertyName="iinn">
@context.iinn @context.iinn
</GridColumn> </GridColumn>
<GridColumn TItem="InvoicePaymentDTO" HeaderText="شماره پذیرنده فروشگاهی" PropertyName="acn"> <GridColumn TItem="InvoicePaymentDTO" TextAlignment="Alignment.Center" HeaderTextAlignment="Alignment.Center" HeaderText="شماره پذیرنده فروشگاهی" PropertyName="acn">
@context.acn @context.acn
</GridColumn> </GridColumn>
<GridColumn TItem="InvoicePaymentDTO" HeaderText="شماره پایانه" PropertyName="trmn"> <GridColumn TItem="InvoicePaymentDTO" TextAlignment="Alignment.Center" HeaderTextAlignment="Alignment.Center" HeaderText="شماره پایانه" PropertyName="trmn">
@context.trmn @context.trmn
</GridColumn> </GridColumn>
<GridColumn TItem="InvoicePaymentDTO" HeaderText="روش پرداخت" PropertyName="pmt"> <GridColumn TItem="InvoicePaymentDTO" TextAlignment="Alignment.Center" HeaderTextAlignment="Alignment.Center" HeaderText="روش پرداخت" PropertyName="paymentMethod">
@context.pmt @context.paymentMethod
</GridColumn> </GridColumn>
<GridColumn TItem="InvoicePaymentDTO" HeaderText="شماره پیگیری/شماره مرجع" PropertyName="trn"> <GridColumn TItem="InvoicePaymentDTO" TextAlignment="Alignment.Center" HeaderTextAlignment="Alignment.Center" HeaderText="شماره پیگیری/شماره مرجع" PropertyName="trn">
@context.trn @context.trn
</GridColumn> </GridColumn>
<GridColumn TItem="InvoicePaymentDTO" HeaderText="شماره کارت پرداخت کننده" PropertyName="pcn"> <GridColumn TItem="InvoicePaymentDTO" TextAlignment="Alignment.Center" HeaderTextAlignment="Alignment.Center" HeaderText="شماره کارت" PropertyName="pcn">
@context.pcn @context.pcn
</GridColumn> </GridColumn>
<GridColumn TItem="InvoicePaymentDTO" HeaderText="شماره/شناسه ملی/کد فراگیر اتباع غیر ایرانی پرداخت کننده" PropertyName="pid"> <GridColumn TItem="InvoicePaymentDTO" TextAlignment="Alignment.Center" HeaderTextAlignment="Alignment.Center" HeaderText="شماره/شناسه ملی/کد فراگیر اتباع غیر ایرانی" PropertyName="pid">
@context.pid @context.pid
</GridColumn> </GridColumn>
<GridColumn TItem="InvoicePaymentDTO" HeaderText="تاریخ" PropertyName="PaymentDateTime"> <GridColumn TItem="InvoicePaymentDTO" TextAlignment="Alignment.Center" HeaderTextAlignment="Alignment.Center" HeaderText="تاریخ" PropertyName="PaymentDateTime">
@context.PaymentDateTime @context.PaymentDateTime
</GridColumn> </GridColumn>
<GridColumn TItem="InvoicePaymentDTO" HeaderText="مبلغ" PropertyName="pv"> <GridColumn TItem="InvoicePaymentDTO" TextAlignment="Alignment.Center" HeaderTextAlignment="Alignment.Center" HeaderText="مبلغ" PropertyName="pv">
@context.pv??.ToString("N0") @context.pv??.ToString("N0")
</GridColumn> </GridColumn>
</GridColumns> </GridColumns>
</Grid> </Grid>
<div class="row g-3">
<div class="form-group col-md-1">
@if (add)
{
<label class="col-sm-6 col-form-label">جدید</label>
}
else
{
<label class="col-sm-6 col-form-label">اطلاعات پرداخت</label>
}
@code { </div>
[Parameter] public ICollection<InvoicePaymentDTO> payments { get; set; } <div class="form-group col-md-11">
Grid<InvoicePaymentDTO> grid = default!; <hr class="hr" />
</div>
</div>
<div class="row g-3">
<div class="form-group col-md-4">
<label class="col-sm-6 col-form-label">شماره سوییچ پرداخت</label>
<InputText onkeypress="return event.charCode &gt;= 48 &amp;&amp; event.charCode &lt;= 57" style="text-align: center" maxlength="9" class="form-control" @bind-Value="item.iinn" Placeholder="شماره سوییچ پرداخت" />
</div>
<div class="form-group col-md-4">
<label class="col-sm-6 col-form-label">شماره پذیرنده فروشگاهی</label>
<InputText onkeypress="return event.charCode &gt;= 48 &amp;&amp; event.charCode &lt;= 57" style="text-align: center" maxlength="14" type="text" class="form-control" @bind-Value="item.acn" Placeholder="شماره پذیرنده فروشگاهی" />
</div>
<div class="form-group col-md-4">
<label class="col-sm-6 col-form-label">شماره پایانه</label>
<InputText onkeypress="return event.charCode &gt;= 48 &amp;&amp; event.charCode &lt;= 57" style="text-align: center" maxlength="8" type="text" class="form-control" @bind-Value="item.trmn" Placeholder="شماره پایانه" />
</div>
</div>
<div class="row g-3">
<div class="form-group col-md-4">
<label class="col-sm-4 col-form-label" for="inputinvoicepmt">روش پرداخت</label>
<select @bind="item.pmt" class="form-control" aria-label="Default select example" id="inputinvoicepmt">
@if (!item.pmt.HasValue)
{
<option value="0" style="color: #b5b5b5" selected>انتخاب کنید...</option>
}
else
{
<option value="0" style="color: #b5b5b5">انتخاب کنید...</option>
}
protected override void OnInitialized() @if (pmts != null)
{
foreach (var _item in pmts)
{
if (item.pmt == Convert.ToInt32(_item.ID))
{
<option value="@_item.ID" selected>@_item.Title</option>
}
else
{
<option value="@_item.ID">@_item.Title</option>
}
}
}
</select>
</div>
<div class="form-group col-md-4">
<label class="col-sm-6 col-form-label">شماره پیگیری/شماره مرجع</label>
<InputText onkeypress="return event.charCode &gt;= 48 &amp;&amp; event.charCode &lt;= 57" style="text-align: center" maxlength="14" type="text" class="form-control" @bind-Value="item.trn" Placeholder="شماره پیگیری/شماره مرجع" />
</div>
<div class="form-group col-md-4">
<label class="col-sm-6 col-form-label">شماره کارت</label>
<InputText onkeypress="return event.charCode &gt;= 48 &amp;&amp; event.charCode &lt;= 57" style="text-align: center" maxlength="16" type="text" class="form-control" @bind-Value="item.pcn" Placeholder="شماره کارت" />
</div>
</div>
<div class="row g-3">
<div class="form-group col-md-4">
<label class="col-sm-10 col-form-label">شماره/شناسه ملی/کد فراگیر اتباع غیر ایرانی</label>
<InputText onkeypress="return event.charCode &gt;= 48 &amp;&amp; event.charCode &lt;= 57" style="text-align: center" maxlength="12" type="text" class="form-control" @bind-Value="item.pid" Placeholder="شماره/شناسه ملی/کد فراگیر اتباع غیر ایرانی" />
</div>
<div class="form-group col-md-4">
<label class="col-sm-6 col-form-label">تاریخ</label>
<InputText type="text" style="text-align: center" class="form-control" @bind-Value="item.PaymentDateTime" Placeholder="تاریخ" />
</div>
<div class="form-group col-md-4">
<label class="col-sm-6 col-form-label">مبلغ</label>
<CurrencyInput TValue="long?" @bind-Value="item.pv" Locale="fa-Ir" Placeholder="مبلغ" style="text-align: center" />
</div>
</div>
<div class="row g-3">
@if (add)
{ {
// payments = new List<InvoicePaymentDTO>(); <div class="form-group col-md-2">
<Button class="mt-3" Color="ButtonColor.Success" @onclick="AddPay" Type="ButtonType.Button">
جدید
</Button>
</div>
}
else
{
<div class="form-group col-md-2">
<Button class="mt-3" Color="ButtonColor.Info" @onclick="AddPay" Type="ButtonType.Button">
ویرایش
</Button>
</div>
<div class="form-group col-md-2">
<Button class="mt-3" Color="ButtonColor.Danger" @onclick="AddPay" Type="ButtonType.Button">
حذف
</Button>
</div>
<div class="form-group col-md-2">
<Button class="mt-3" Color="ButtonColor.Primary" @onclick="cancell" Type="ButtonType.Button">
انصزاف
</Button>
</div>
}
} }
// private async Task AddEmployee() </div>
// {
// // for the same employees collection, we are adding an object
// // explicit grid refresh required
// employees!.Add(CreateEmployee());
// await grid.RefreshDataAsync();
// }
// private void AddEmployee2() @* alert *@
// { <div class="row">
// // creates a shallow copy <Alert hidden="@Hidealert" Color="@alertColor" Dismissable="false">
// var emps = employees!.GetRange(0, employees.Count); <Icon Name="@alertIconName" class="me-2"></Icon>
// emps.Add(CreateEmployee()); @alertMessage
// // now employees variable has a new reference. So no need to refresh the grid explicitly </Alert>
// // explicit grid refresh is not required
// employees = emps;
// }
// private Employee1 CreateEmployee() </div>
// { @code {
// var emp = new Employee1(); bool add = true;
// emp.Id = employees!.Max(x => x.Id) + 1; [Parameter] public InvoiceDTO invoice { get; set; }
// emp.Name = $"Employee {emp.Id}"; Grid<InvoicePaymentDTO> grid = default!;
// emp.Designation = $"QA Engineer {emp.Id}"; InvoicePaymentDTO item;
// emp.DOJ = new DateOnly(new Random().Next(1970, 2000), new Random().Next(1, 12), new Random().Next(1, 25)); List<IdName<string>> pmts;
// emp.IsActive = true; // alert
// return emp; AlertColor alertColor = AlertColor.Primary;
// } IconName alertIconName = IconName.CheckCircleFill;
bool Hidealert = true;
string alertMessage = "";
protected override async Task OnParametersSetAsync()
{
item = new InvoicePaymentDTO();
pmts = await fv.GetPaymentMethods();
await base.OnParametersSetAsync();
}
}
@functions {
private async Task OnRowClick(GridRowEventArgs<InvoicePaymentDTO> args)
{
item = args.Item;
add = false;
}
async Task cancell()
{
add = true;
item = new InvoicePaymentDTO();
}
async Task AddPay()
{
if (await Validation())
{
var rsp = await hc.Post<InvoicePaymentDTO>("InvoicePayment/AddPay", item);
if (rsp.IsSuccessStatusCode)
{
var request = await rsp.Content.ReadFromJsonAsync<InvoicePaymentDTO>();
if (request != null && request.ID.HasValue)
{
invoice.payments.Add(request);
await grid.RefreshDataAsync();
item = new InvoicePaymentDTO();
}
else ShowDangerAlert("خطایی در اجرای عملیات رخ داده");
}
else
{
var request = await rsp.Content.ReadFromJsonAsync<List<string>>();
ShowDangerAlert(request[0]);
}
}
}
async Task UpdatePay()
{
if (await Validation())
{
var rsp = await hc.Put<InvoicePaymentDTO>("InvoicePayment/UpdatePay", item);
if (rsp.IsSuccessStatusCode)
{
var request = await rsp.Content.ReadFromJsonAsync<InvoicePaymentDTO>();
if (request != null && request.ID.HasValue)
{
invoice.payments.Add(request);
await grid.RefreshDataAsync();
item = new InvoicePaymentDTO();
}
else ShowDangerAlert("خطایی در اجرای عملیات رخ داده");
}
else
{
var request = await rsp.Content.ReadFromJsonAsync<List<string>>();
ShowDangerAlert(request[0]);
}
}
}
async Task DeletePay()
{
if (item.ID.HasValue)
{
var rsp = await hc.Delete($"InvoicePayment/DeletePay/{item.ID.Value}");
if (rsp.IsSuccessStatusCode)
{
var request = await rsp.Content.ReadFromJsonAsync<bool>();
if (request)
{
invoice.payments.Add(item);
await grid.RefreshDataAsync();
item = new InvoicePaymentDTO();
}
else ShowDangerAlert("خطایی در اجرای عملیات رخ داده");
}
else
{
var request = await rsp.Content.ReadFromJsonAsync<List<string>>();
ShowDangerAlert(request[0]);
}
}
}
private void ShowSuccessAlert(string msg)
{
Hidealert = false;
alertColor = AlertColor.Success;
alertIconName = IconName.CheckCircleFill;
alertMessage = msg;
}
private void ShowDangerAlert(string msg)
{
Hidealert = false;
alertColor = AlertColor.Danger;
alertIconName = IconName.ExclamationTriangleFill;
alertMessage = msg;
}
async Task<bool> Validation()
{
if (invoice.tbill < invoice.payments.Sum(s => s.pv) + item.pv)
{
ShowDangerAlert("مجموع مبلغ پرداختی نمی تواند از مجموع صورتحساب بیشتر باشد.");
return false;
}
if (item.pmt.HasValue && item.pmt.Value > 0 && item.pmt.Value < 9)
{
if (string.IsNullOrEmpty(item.PaymentDateTime))
{
ShowDangerAlert("تاریخ نمیتواند خالی باشد");
return false;
}
else
{
string paydate = item.PaymentDateTime.Replace("/", "");
if (paydate.Length == 8 && int.TryParse(paydate, out int _paydate))
{
if (Convert.ToInt32(invoice.InvoiceDate.Replace("/", "")) > _paydate)
{
ShowDangerAlert("تاریخ پرداخت نمیتواند از تاریخ صورتحساب عقبتر باشد");
return false;
}
}
else { ShowDangerAlert("تاریخ صحیح نمی باشد"); return false; }
}
}
else { ShowDangerAlert("روش پرداخت مشخص نشده"); return false; }
return true;
}
} }

View File

@@ -12,6 +12,7 @@ namespace Front
public readonly HttpClientController _hc; public readonly HttpClientController _hc;
private List<ForCustomerSearch>? Cus = null; private List<ForCustomerSearch>? Cus = null;
private List<IdName<int>>? Patterns = null; private List<IdName<int>>? Patterns = null;
private List<IdName<string>>? PaymentMethods = null;
private List<IdName<int>>? Patternsbyinp = null; private List<IdName<int>>? Patternsbyinp = null;
private List<IdName<int>>? BillTypes = null; private List<IdName<int>>? BillTypes = null;
private List<IdName<int>>? UnitsbyUnitTaxID = null; private List<IdName<int>>? UnitsbyUnitTaxID = null;
@@ -71,6 +72,20 @@ namespace Front
return Patterns; return Patterns;
} }
public async Task<List<IdName<string>>?> GetPaymentMethods()
{
if (PaymentMethods == null)
{
var request = await _hc.Get($"InvoicePayment/PaymentMethods");
if (request.IsSuccessStatusCode)
{
PaymentMethods = await request.Content.ReadFromJsonAsync<List<IdName<string>>>();
}
}
return PaymentMethods;
}
public async Task<List<IdName<int>>?> GetPatternsbyinp() public async Task<List<IdName<int>>?> GetPatternsbyinp()
{ {
if (Patternsbyinp == null) if (Patternsbyinp == null)

View File

@@ -366,7 +366,7 @@
</div> </div>
<br /> <br />
<div class="row g-3"> <div class="row g-3">
@if (!invoice.IsDeleted && invoice.invoiceType != InvoiceType.Bidding && SendInvoice) @if (!invoice.IsDeleted && invoice.invoiceType != InvoiceType.Bidding && SendInvoice)
{ {
<div class="form-group col-md-2"> <div class="form-group col-md-2">
@@ -469,6 +469,8 @@
{ {
if (InvoiceID.HasValue) if (InvoiceID.HasValue)
{ {
modal.Size = ModalSize.Large;
var parameters = new Dictionary<string, object>(); var parameters = new Dictionary<string, object>();
parameters.Add("InvoiceID", InvoiceID); parameters.Add("InvoiceID", InvoiceID);
@@ -481,6 +483,14 @@
} }
private async Task OnClickPayment() private async Task OnClickPayment()
{ {
if (invoice!=null)
{
modal.Size = ModalSize.ExtraLarge;
var parameters = new Dictionary<string, object>();
parameters.Add("invoice", invoice);
await modal.ShowAsync<CUSComponent.InvoicePays>("پرداختی ها", parameters: parameters);
}
} }
private async Task CopyInvoice() private async Task CopyInvoice()