116 lines
4.7 KiB
C#
116 lines
4.7 KiB
C#
![]() |
using Back.Data.Contracts;
|
|||
|
using Back.Data.Models;
|
|||
|
using Shared.DTOs.Serch;
|
|||
|
using Shared.DTOs;
|
|||
|
using Back.Common;
|
|||
|
using Microsoft.EntityFrameworkCore;
|
|||
|
|
|||
|
namespace Back.Services
|
|||
|
{
|
|||
|
public class servInvoice
|
|||
|
{
|
|||
|
private readonly IAsyncRepository<Invoice> _invoiceRepo;
|
|||
|
private readonly IAsyncRepository<InvoiceItem> _invoiceItemRepo;
|
|||
|
private readonly IAsyncRepository<InvoicePayment> _invoicePaymentRepo;
|
|||
|
private readonly CheckPermission _checkPermission;
|
|||
|
public servInvoice(IAsyncRepository<Invoice> invoiceRepo
|
|||
|
, IAsyncRepository<InvoiceItem> invoiceItemRepo
|
|||
|
, IAsyncRepository<InvoicePayment> invoicePaymentRepo, CheckPermission checkPermission)
|
|||
|
{
|
|||
|
_invoiceItemRepo = invoiceItemRepo;
|
|||
|
_invoiceRepo = invoiceRepo;
|
|||
|
_invoicePaymentRepo = invoicePaymentRepo;
|
|||
|
_checkPermission = checkPermission;
|
|||
|
|
|||
|
}
|
|||
|
public async Task<PagingDto<InvoiceDTO>?> GetInvoices(int CompanyID, ItemSerchGetInvoices itemSerch)
|
|||
|
{
|
|||
|
#region AdvancedSearch
|
|||
|
var invok = _invoiceRepo
|
|||
|
.Get(w => w.CompanyID == CompanyID && !w.IsDeleted);
|
|||
|
|
|||
|
if (itemSerch.InvoiceID != null)
|
|||
|
invok = invok.Where(w => w.ID == itemSerch.InvoiceID);
|
|||
|
|
|||
|
if (itemSerch.CustomerID != null)
|
|||
|
invok = invok.Where(w => w.CustomerID == itemSerch.CustomerID);
|
|||
|
|
|||
|
if (itemSerch.invoiceType != null)
|
|||
|
invok = invok.Where(w => w.invoiceType == itemSerch.invoiceType);
|
|||
|
|
|||
|
if (itemSerch.Title != null)
|
|||
|
invok = invok.Where(w => w.Title.Contains(itemSerch.Title));
|
|||
|
//foreach (InputObj item in inputObjs)
|
|||
|
// invok = invok.Where(ExMethod.GetFunc<Customer>(item.Param, item.Value));
|
|||
|
|
|||
|
#endregion
|
|||
|
//-----------------------
|
|||
|
return await invok
|
|||
|
.Include(inc => inc.invoiceDetails)
|
|||
|
.Include(inc => inc.payments)
|
|||
|
.Select(s => new InvoiceDTO()
|
|||
|
{
|
|||
|
PatternID= s.PatternID,
|
|||
|
CustomerID = s.CustomerID,
|
|||
|
CustomerName = s.Customer.FullName,
|
|||
|
ID = s.ID,
|
|||
|
InvoiceDate = s.InvoiceDate.ShamciToFormatShamci(),
|
|||
|
invoiceTypeTitle = s.invoiceType.GetEnumDisplayName(),
|
|||
|
invoiceType = s.invoiceType,
|
|||
|
Title = s.Title,
|
|||
|
InvoicIssueDate = s.InvoicIssueDate.ShamciToFormatShamci(),
|
|||
|
BillReference = s.BillReference,
|
|||
|
tbill = s.tbill,
|
|||
|
Des = s.Des,
|
|||
|
PreparedtoSendtoTax = s.PreparedtoSendtoTax,
|
|||
|
tdis = s.tdis,
|
|||
|
tvam = s.tvam,
|
|||
|
Udate = s.Udate.ShamciToFormatShamci(),
|
|||
|
items = s.invoiceDetails.OrderBy(o => o.ID).Select(x => new InvoiceItemDTO()
|
|||
|
{
|
|||
|
ID = x.ID,
|
|||
|
CODID = x.CODID,
|
|||
|
adis = x.adis,
|
|||
|
am = x.am.Value,
|
|||
|
dis = x.dis,
|
|||
|
fee = x.fee.Value,
|
|||
|
mu = x.mu,
|
|||
|
sstt = x.sstt,
|
|||
|
tsstam = x.tsstam,
|
|||
|
vam = x.am,
|
|||
|
vra = x.vra
|
|||
|
}).ToList(),
|
|||
|
payments = s.payments.OrderBy(o => o.ID).Select(x => new InvoicePaymentDTO()
|
|||
|
{
|
|||
|
ID = x.ID,
|
|||
|
acn = x.acn,
|
|||
|
iinn = x.acn,
|
|||
|
pcn = x.acn,
|
|||
|
pdt = x.pdt,
|
|||
|
pid = x.pid,
|
|||
|
pmt = x.pmt,
|
|||
|
pv = x.pv,
|
|||
|
trmn = x.trmn,
|
|||
|
trn = x.acn
|
|||
|
}).ToList(),
|
|||
|
})
|
|||
|
.Paging(itemSerch.PageIndex, itemSerch.PageSize);
|
|||
|
}
|
|||
|
public async Task<bool> ExistInvoiceByInvoiceID(int CompanyID,int InvoiceID)
|
|||
|
{
|
|||
|
return await _invoiceRepo.Get(w => w.ID == InvoiceID && w.CompanyID == CompanyID && !w.IsDeleted).AnyAsync();
|
|||
|
|
|||
|
}
|
|||
|
public async Task<bool> AddInvoice(Invoice invoice)
|
|||
|
{
|
|||
|
invoice.Cdate = DateTime.Now.ConvertMiladiToShamsi();
|
|||
|
invoice.Udate = DateTime.Now.ConvertMiladiToShamsi();
|
|||
|
invoice.PreparedtoSendtoTax = false;
|
|||
|
|
|||
|
if(await _checkPermission.ExtensionofAccess(invoice.CompanyID.Value, 3, "-1"))
|
|||
|
return await _invoiceRepo.AddBoolResultAsync(invoice);
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|