...
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using Back.Data.Contracts;
|
||||
using Back.Data.Models;
|
||||
using Back.Services;
|
||||
using Back.Services.Warehouse;
|
||||
using Back.Validations;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -9,6 +10,7 @@ using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Shared.DTOs;
|
||||
using Shared.DTOs.Serch;
|
||||
using Shared.Enums;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Back.Controllers
|
||||
@@ -25,20 +27,22 @@ namespace Back.Controllers
|
||||
private readonly servTaxPayer _servTaxPayer;
|
||||
private readonly servReport _servReport;
|
||||
private readonly IAsyncRepository<rptQueue> _rptQueueRepository;
|
||||
public InvoiceController(servInvoice servInvoice, servUser servUser
|
||||
, AddOrUpdateInvoiceValidation validationInvoice
|
||||
, servTaxPayer servTaxPayer, IConfiguration configuration
|
||||
, IAsyncRepository<rptQueue> rptQueueRepository, servReport servReport)
|
||||
private readonly RemittanceService _remittanceService;
|
||||
private readonly WarehouseService _warehouseService;
|
||||
|
||||
public InvoiceController(IConfiguration configuration, servInvoice servInvoice, servUser servUser, AddOrUpdateInvoiceValidation validationInvoice, servTaxPayer servTaxPayer, servReport servReport, IAsyncRepository<rptQueue> rptQueueRepository, RemittanceService remittanceService, WarehouseService warehouseService)
|
||||
{
|
||||
_servReport= servReport;
|
||||
_configuration = configuration;
|
||||
_servInvoice = servInvoice;
|
||||
_servUser = servUser;
|
||||
_validationInvoice = validationInvoice;
|
||||
_configuration = configuration;
|
||||
_servTaxPayer = servTaxPayer;
|
||||
_servReport = servReport;
|
||||
_rptQueueRepository = rptQueueRepository;
|
||||
|
||||
_remittanceService = remittanceService;
|
||||
_warehouseService = warehouseService;
|
||||
}
|
||||
|
||||
[HttpPost("GetAll")]
|
||||
public async Task<ActionResult<PagingDto<InvoiceGridDTO>?>> GetAll([FromBody] ItemSerchGetInvoices itemSerch)
|
||||
{
|
||||
@@ -203,6 +207,7 @@ namespace Back.Controllers
|
||||
invoice.Des = item.Des;
|
||||
invoice.LastChangeUserID = Convert.ToInt32(UserID);
|
||||
|
||||
|
||||
return Ok(await _servInvoice.UpdateInvoice(invoice));
|
||||
}
|
||||
[HttpDelete("Delete/{ID}")]
|
||||
@@ -610,6 +615,63 @@ namespace Back.Controllers
|
||||
string base64= await _servReport.CreateImage(result, user?.RolUsers.First().Company.Logo==null ?"":Convert.ToBase64String(user?.RolUsers.First().Company.Logo), user?.RolUsers.First().Company.Name);
|
||||
return Ok(base64);
|
||||
}
|
||||
|
||||
[HttpPost("IssuingRemittance/{InvoiceID}")]
|
||||
public async Task<ActionResult<string>> IssuingRemittance(int InvoiceID)
|
||||
{
|
||||
//-----GetUserAndCompany
|
||||
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
|
||||
var UserID = claim.Value;
|
||||
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
|
||||
|
||||
var CompanyID = user?.RolUsers.First().CompanyID;
|
||||
|
||||
if (!await _servInvoice.ExistInvoiceByInvoiceID(CompanyID.Value, InvoiceID))
|
||||
return NotFound();
|
||||
|
||||
if (await _remittanceService.HasaRemittance(InvoiceID))
|
||||
{
|
||||
return BadRequest(new List<string>() { "این صورتحساب حواله دارد" });
|
||||
}
|
||||
else
|
||||
{
|
||||
List<string> errors = new List<string>();
|
||||
var result = await _servInvoice.GetInvoice(user.RolUsers.First().CompanyID, InvoiceID);
|
||||
//check
|
||||
foreach (var item in result.items
|
||||
.GroupBy(i => i.CODID).Select(g => new { CODID = g.Key,TotalAm = g.Sum(i => i.am) }))
|
||||
{
|
||||
var Inventory =await _warehouseService.Inventory(CompanyID.Value, item.CODID);
|
||||
if (Inventory - item.TotalAm <= 0 )
|
||||
{
|
||||
errors.Add($"مقدار کالا {item.CODID} کمتر از درخواست شماست");
|
||||
}
|
||||
}
|
||||
if (errors.Count==0)
|
||||
{
|
||||
//save
|
||||
await _remittanceService.AddRange(result.items.Select(s => new Data.Models.Warehouse.Remittance()
|
||||
{
|
||||
CODID = s.CODID,
|
||||
Count = s.am,
|
||||
Date = DateTime.Now.ConvertMiladiToShamsi(),
|
||||
info = $"حواله خودکار از صورتحساب {InvoiceID}",
|
||||
Type = TypeRemittance.Sale,
|
||||
InvoiceID = InvoiceID,
|
||||
Deleted = false,
|
||||
}).ToList());
|
||||
return Ok();
|
||||
}
|
||||
else
|
||||
{
|
||||
return BadRequest(errors);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user