...
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
using Back.Common;
|
||||
using Back.Data.Models;
|
||||
using Back.Services;
|
||||
using Back.Services.Warehouse;
|
||||
using Back.Validations;
|
||||
using FluentValidation;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
@@ -21,6 +22,7 @@ namespace Back.Controllers
|
||||
private readonly servUser _servUser;
|
||||
private readonly AUInvoiceItemValidation _validationInvoiceItem;
|
||||
private readonly servInvoice _servInvoice;
|
||||
private readonly RemittanceService _remittanceService;
|
||||
public InvoiceItemController(servInvoiceItem servInvoiceItem, AUInvoiceItemValidation validationInvoiceItem
|
||||
, servUser servUser, servInvoice servInvoice)
|
||||
{
|
||||
@@ -31,7 +33,7 @@ namespace Back.Controllers
|
||||
|
||||
}
|
||||
[HttpPost("AddItem")]
|
||||
public async Task<ActionResult<bool>> AddItem([FromBody]InvoiceItemAction<InvoiceItemDTO> model)
|
||||
public async Task<ActionResult<bool>> AddItem([FromBody] InvoiceItemAction<InvoiceItemDTO> model)
|
||||
{
|
||||
//-----GetUserAndCompany
|
||||
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
|
||||
@@ -48,7 +50,7 @@ namespace Back.Controllers
|
||||
if (invoice == null)
|
||||
return BadRequest(new List<string> { "invoice notFound..." });
|
||||
|
||||
if (invoice.invoiceType==InvoiceType.Repair)
|
||||
if (invoice.invoiceType == InvoiceType.Repair)
|
||||
{
|
||||
return BadRequest(new List<string> { "امکان افزودن کالا جدید در صورتحساب اصلاحی وجود ندارد" });
|
||||
}
|
||||
@@ -61,14 +63,21 @@ namespace Back.Controllers
|
||||
|
||||
if (await _servInvoice.UpdateInvoice(invoice))
|
||||
{
|
||||
if (await _remittanceService.HasaRemittance(model.invoiceID, model.item.CODID))
|
||||
{
|
||||
//check mojodi
|
||||
//add
|
||||
}
|
||||
|
||||
|
||||
return Ok(await _servInvoiceItem.Add(new InvoiceItem
|
||||
{
|
||||
am=model.item.am,
|
||||
fee=model.item.fee,
|
||||
dis=model.item.dis,
|
||||
CODID=model.item.CODID,
|
||||
InvoiceID=model.invoiceID,
|
||||
|
||||
am = model.item.am,
|
||||
fee = model.item.fee,
|
||||
dis = model.item.dis,
|
||||
CODID = model.item.CODID,
|
||||
InvoiceID = model.invoiceID,
|
||||
|
||||
}));
|
||||
}
|
||||
else return BadRequest(new List<string> { "خطایی رخ داده" });
|
||||
@@ -89,10 +98,10 @@ namespace Back.Controllers
|
||||
if (invoice == null)
|
||||
return BadRequest(new List<string> { "invoice notFound..." });
|
||||
|
||||
|
||||
|
||||
//-----Validaton
|
||||
var resultValidationmodel = await _validationInvoiceItem.ValidateAsync(Tuple.Create(user.RolUsers.First().CompanyID, model.invoiceID, model.item, eActionValidation.update));
|
||||
|
||||
//-----Validaton
|
||||
var resultValidationmodel = await _validationInvoiceItem.ValidateAsync(Tuple.Create(user.RolUsers.First().CompanyID, model.invoiceID, model.item, eActionValidation.update));
|
||||
if (!resultValidationmodel.IsValid)
|
||||
{
|
||||
if (invoice.invoiceType != InvoiceType.BackFrmSale || (invoice.invoiceType != InvoiceType.BackFrmSale
|
||||
@@ -100,14 +109,14 @@ namespace Back.Controllers
|
||||
{
|
||||
return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var invoiceitem=await _servInvoiceItem.Getinvoiceitem(user.RolUsers.First().CompanyID, model.invoiceID, model.item.ID.Value);
|
||||
|
||||
|
||||
var invoiceitem = await _servInvoiceItem.Getinvoiceitem(user.RolUsers.First().CompanyID, model.invoiceID, model.item.ID.Value);
|
||||
if (invoiceitem == null)
|
||||
return BadRequest(new List<string> { "invoice Item notFound..." });
|
||||
|
||||
@@ -139,13 +148,13 @@ namespace Back.Controllers
|
||||
}
|
||||
|
||||
|
||||
if (invoice.invoiceType==InvoiceType.BackFrmSale && invoiceitem.am < model.item.am)
|
||||
if (invoice.invoiceType == InvoiceType.BackFrmSale && invoiceitem.am < model.item.am)
|
||||
return BadRequest(new List<string> { "در صورتحساب برگشت از فروش تعداد آیتم فقط میتواند کاهشی باشد" });
|
||||
|
||||
|
||||
invoice.LastChangeUserID = Convert.ToInt32(UserID);
|
||||
|
||||
if (invoice.invoiceType == InvoiceType.BackFrmSale)
|
||||
invoiceitem.am = model.item.am;
|
||||
invoiceitem.am = model.item.am;
|
||||
else
|
||||
{
|
||||
invoiceitem.am = model.item.am;
|
||||
@@ -155,8 +164,16 @@ namespace Back.Controllers
|
||||
}
|
||||
|
||||
if (await _servInvoice.UpdateInvoice(invoice))
|
||||
return Ok(await _servInvoiceItem.Update(invoiceitem));
|
||||
|
||||
{
|
||||
if (await _remittanceService.HasaRemittance(invoiceitem.invoice.ID, invoiceitem.CODID))
|
||||
{
|
||||
await _remittanceService.DeleteByInvoiceIDandCODID(invoiceitem.invoice.ID, invoiceitem.CODID);
|
||||
//check mojodi
|
||||
//add
|
||||
}
|
||||
return Ok(await _servInvoiceItem.Update(invoiceitem));
|
||||
}
|
||||
|
||||
else return BadRequest(new List<string> { "خطایی رخ داده" });
|
||||
|
||||
|
||||
@@ -176,13 +193,13 @@ namespace Back.Controllers
|
||||
return NotFound(new List<string> { "invoice Item notFound..." });
|
||||
|
||||
//-----Validaton
|
||||
var resultValidationmodel = await _validationInvoiceItem.ValidateAsync(Tuple.Create(user.RolUsers.First().CompanyID, invoiceitem.InvoiceID.Value, new InvoiceItemDTO(), eActionValidation.delete)) ;
|
||||
var resultValidationmodel = await _validationInvoiceItem.ValidateAsync(Tuple.Create(user.RolUsers.First().CompanyID, invoiceitem.InvoiceID.Value, new InvoiceItemDTO(), eActionValidation.delete));
|
||||
if (!resultValidationmodel.IsValid)
|
||||
return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList());
|
||||
|
||||
|
||||
|
||||
if (invoiceitem.invoice.invoiceType == InvoiceType.Repair )
|
||||
if (invoiceitem.invoice.invoiceType == InvoiceType.Repair)
|
||||
{
|
||||
return BadRequest(new List<string> { "در صورتحساب اصلاجی نمیتوان کالا را حذف کذد" });
|
||||
}
|
||||
@@ -192,16 +209,21 @@ namespace Back.Controllers
|
||||
}
|
||||
invoiceitem.invoice.LastChangeUserID = Convert.ToInt32(UserID);
|
||||
|
||||
|
||||
|
||||
|
||||
if (await _servInvoice.UpdateInvoice(invoiceitem.invoice))
|
||||
{
|
||||
if (await _remittanceService.HasaRemittance(invoiceitem.invoice.ID, invoiceitem.CODID))
|
||||
await _remittanceService.DeleteByInvoiceIDandCODID(invoiceitem.invoice.ID, invoiceitem.CODID);
|
||||
|
||||
return Ok(await _servInvoiceItem.Delete(invoiceitem));
|
||||
}
|
||||
|
||||
else return BadRequest(new List<string> { "خطایی رخ داده" });
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,8 @@
|
||||
using Back.Data.Models;
|
||||
using Back.Common;
|
||||
using Back.Data.Models;
|
||||
using Back.Services;
|
||||
using Back.Services.Warehouse;
|
||||
using Back.Validations.Warehouse.Receipt;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -17,6 +19,19 @@ namespace Back.Controllers.Warehouse
|
||||
{
|
||||
private readonly ReceiptService _receiptService;
|
||||
private readonly servUser _servUser;
|
||||
private readonly ADDValidation _addvalidation;
|
||||
private readonly UpdateValidation _updatevalidation;
|
||||
private readonly DeleteValidation _deletevalidation;
|
||||
|
||||
public ReceiptController(ReceiptService receiptService, servUser servUser, ADDValidation addvalidation, UpdateValidation updatevalidation, DeleteValidation deletevalidation)
|
||||
{
|
||||
_receiptService = receiptService;
|
||||
_servUser = servUser;
|
||||
_addvalidation = addvalidation;
|
||||
_updatevalidation = updatevalidation;
|
||||
_deletevalidation = deletevalidation;
|
||||
}
|
||||
|
||||
[HttpGet("{ItemID}")]
|
||||
public async Task<IActionResult> Get(int ItemID)
|
||||
{
|
||||
@@ -38,8 +53,19 @@ namespace Back.Controllers.Warehouse
|
||||
[HttpPost("ADD")]
|
||||
public async Task<IActionResult> AddReceipt(ReceiptDto item)
|
||||
{
|
||||
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;
|
||||
|
||||
//-----Validaton
|
||||
var resultValidationmodel = await _addvalidation.ValidateAsync(Tuple.Create(item,CompanyID));
|
||||
if (!resultValidationmodel.IsValid)
|
||||
return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList());
|
||||
|
||||
|
||||
// validate ADD
|
||||
var newmodel = await _receiptService.ADD(item);
|
||||
var newmodel = await _receiptService.ADD(item, CompanyID);
|
||||
if (newmodel != null) return Ok(newmodel);
|
||||
else return BadRequest(new List<string> { "خطا در صدور" });
|
||||
}
|
||||
@@ -47,7 +73,16 @@ namespace Back.Controllers.Warehouse
|
||||
[HttpPut("Update")]
|
||||
public async Task<IActionResult> UpdateReceipt(ReceiptDto item)
|
||||
{
|
||||
// validate Update
|
||||
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;
|
||||
|
||||
//-----Validaton
|
||||
var resultValidationmodel = await _updatevalidation.ValidateAsync(Tuple.Create(item, CompanyID));
|
||||
if (!resultValidationmodel.IsValid)
|
||||
return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList());
|
||||
|
||||
var Updatemodel = await _receiptService.Update(item);
|
||||
if (Updatemodel != null) return Ok(Updatemodel);
|
||||
else return BadRequest(new List<string> { "خطا در ویرایش" });
|
||||
@@ -61,6 +96,11 @@ namespace Back.Controllers.Warehouse
|
||||
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
|
||||
var CompanyID = user.RolUsers.First().CompanyID;
|
||||
|
||||
//-----Validaton
|
||||
var resultValidationmodel = await _deletevalidation.ValidateAsync(Tuple.Create(ItemID, CompanyID));
|
||||
if (!resultValidationmodel.IsValid)
|
||||
return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList());
|
||||
|
||||
var Deletemodel = await _receiptService.Delete(ItemID, CompanyID);
|
||||
if (Deletemodel) return Ok();
|
||||
else return BadRequest(new List<string> { "خطا در حذف" });
|
||||
|
@@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Shared.DTOs.Warehouse;
|
||||
using Shared.Enums;
|
||||
using Back.Validations.Warehouse.Remittance;
|
||||
|
||||
namespace Back.Controllers.Warehouse
|
||||
{
|
||||
@@ -13,6 +14,20 @@ namespace Back.Controllers.Warehouse
|
||||
{
|
||||
private readonly RemittanceService _treanceService;
|
||||
private readonly servUser _servUser;
|
||||
|
||||
private readonly ADDValidation _addvalidation;
|
||||
private readonly UpdateValidation _updatevalidation;
|
||||
private readonly DeleteValidation _deletevalidation;
|
||||
|
||||
public RemittanceController(RemittanceService treanceService, servUser servUser, ADDValidation addvalidation, UpdateValidation updatevalidation, DeleteValidation deletevalidation)
|
||||
{
|
||||
_treanceService = treanceService;
|
||||
_servUser = servUser;
|
||||
_addvalidation = addvalidation;
|
||||
_updatevalidation = updatevalidation;
|
||||
_deletevalidation = deletevalidation;
|
||||
}
|
||||
|
||||
[HttpGet("{ItemID}")]
|
||||
public async Task<IActionResult> Get(int ItemID)
|
||||
{
|
||||
@@ -34,7 +49,17 @@ namespace Back.Controllers.Warehouse
|
||||
[HttpPost("ADD")]
|
||||
public async Task<IActionResult> Add(RemittanceDto item)
|
||||
{
|
||||
// validate ADD
|
||||
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;
|
||||
|
||||
//-----Validaton
|
||||
var resultValidationmodel = await _addvalidation.ValidateAsync(Tuple.Create(item, CompanyID));
|
||||
if (!resultValidationmodel.IsValid)
|
||||
return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList());
|
||||
|
||||
|
||||
var newmodel = await _treanceService.ADD(item);
|
||||
if (newmodel != null) return Ok(newmodel);
|
||||
else return BadRequest(new List<string> { "خطا در صدور" });
|
||||
@@ -43,7 +68,16 @@ namespace Back.Controllers.Warehouse
|
||||
[HttpPut("Update")]
|
||||
public async Task<IActionResult> Update(RemittanceDto item)
|
||||
{
|
||||
// validate Update
|
||||
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;
|
||||
|
||||
//-----Validaton
|
||||
var resultValidationmodel = await _updatevalidation.ValidateAsync(Tuple.Create(item, CompanyID));
|
||||
if (!resultValidationmodel.IsValid)
|
||||
return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList());
|
||||
|
||||
var Updatemodel = await _treanceService.Update(item);
|
||||
if (Updatemodel != null) return Ok(Updatemodel);
|
||||
else return BadRequest(new List<string> { "خطا در ویرایش" });
|
||||
@@ -57,6 +91,11 @@ namespace Back.Controllers.Warehouse
|
||||
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
|
||||
var CompanyID = user.RolUsers.First().CompanyID;
|
||||
|
||||
//-----Validaton
|
||||
var resultValidationmodel = await _deletevalidation.ValidateAsync(Tuple.Create(ItemID, CompanyID));
|
||||
if (!resultValidationmodel.IsValid)
|
||||
return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList());
|
||||
|
||||
var Deletemodel = await _treanceService.Delete(ItemID, CompanyID);
|
||||
if (Deletemodel) return Ok();
|
||||
else return BadRequest(new List<string> { "خطا در حذف" });
|
||||
|
Reference in New Issue
Block a user