...
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
using Back.Data.Contracts;
|
using Back.Data.Contracts;
|
||||||
using Back.Data.Models;
|
using Back.Data.Models;
|
||||||
using Back.Services;
|
using Back.Services;
|
||||||
|
using Back.Services.Warehouse;
|
||||||
using Back.Validations;
|
using Back.Validations;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
@@ -9,6 +10,7 @@ using Microsoft.AspNetCore.Http.HttpResults;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Shared.DTOs;
|
using Shared.DTOs;
|
||||||
using Shared.DTOs.Serch;
|
using Shared.DTOs.Serch;
|
||||||
|
using Shared.Enums;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace Back.Controllers
|
namespace Back.Controllers
|
||||||
@@ -25,20 +27,22 @@ namespace Back.Controllers
|
|||||||
private readonly servTaxPayer _servTaxPayer;
|
private readonly servTaxPayer _servTaxPayer;
|
||||||
private readonly servReport _servReport;
|
private readonly servReport _servReport;
|
||||||
private readonly IAsyncRepository<rptQueue> _rptQueueRepository;
|
private readonly IAsyncRepository<rptQueue> _rptQueueRepository;
|
||||||
public InvoiceController(servInvoice servInvoice, servUser servUser
|
private readonly RemittanceService _remittanceService;
|
||||||
, AddOrUpdateInvoiceValidation validationInvoice
|
private readonly WarehouseService _warehouseService;
|
||||||
, servTaxPayer servTaxPayer, IConfiguration configuration
|
|
||||||
, IAsyncRepository<rptQueue> rptQueueRepository, servReport servReport)
|
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;
|
_servInvoice = servInvoice;
|
||||||
_servUser = servUser;
|
_servUser = servUser;
|
||||||
_validationInvoice = validationInvoice;
|
_validationInvoice = validationInvoice;
|
||||||
_configuration = configuration;
|
|
||||||
_servTaxPayer = servTaxPayer;
|
_servTaxPayer = servTaxPayer;
|
||||||
|
_servReport = servReport;
|
||||||
_rptQueueRepository = rptQueueRepository;
|
_rptQueueRepository = rptQueueRepository;
|
||||||
|
_remittanceService = remittanceService;
|
||||||
|
_warehouseService = warehouseService;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("GetAll")]
|
[HttpPost("GetAll")]
|
||||||
public async Task<ActionResult<PagingDto<InvoiceGridDTO>?>> GetAll([FromBody] ItemSerchGetInvoices itemSerch)
|
public async Task<ActionResult<PagingDto<InvoiceGridDTO>?>> GetAll([FromBody] ItemSerchGetInvoices itemSerch)
|
||||||
{
|
{
|
||||||
@@ -203,6 +207,7 @@ namespace Back.Controllers
|
|||||||
invoice.Des = item.Des;
|
invoice.Des = item.Des;
|
||||||
invoice.LastChangeUserID = Convert.ToInt32(UserID);
|
invoice.LastChangeUserID = Convert.ToInt32(UserID);
|
||||||
|
|
||||||
|
|
||||||
return Ok(await _servInvoice.UpdateInvoice(invoice));
|
return Ok(await _servInvoice.UpdateInvoice(invoice));
|
||||||
}
|
}
|
||||||
[HttpDelete("Delete/{ID}")]
|
[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);
|
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);
|
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.Common;
|
||||||
using Back.Data.Models;
|
using Back.Data.Models;
|
||||||
using Back.Services;
|
using Back.Services;
|
||||||
|
using Back.Services.Warehouse;
|
||||||
using Back.Validations;
|
using Back.Validations;
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
@@ -21,6 +22,7 @@ namespace Back.Controllers
|
|||||||
private readonly servUser _servUser;
|
private readonly servUser _servUser;
|
||||||
private readonly AUInvoiceItemValidation _validationInvoiceItem;
|
private readonly AUInvoiceItemValidation _validationInvoiceItem;
|
||||||
private readonly servInvoice _servInvoice;
|
private readonly servInvoice _servInvoice;
|
||||||
|
private readonly RemittanceService _remittanceService;
|
||||||
public InvoiceItemController(servInvoiceItem servInvoiceItem, AUInvoiceItemValidation validationInvoiceItem
|
public InvoiceItemController(servInvoiceItem servInvoiceItem, AUInvoiceItemValidation validationInvoiceItem
|
||||||
, servUser servUser, servInvoice servInvoice)
|
, servUser servUser, servInvoice servInvoice)
|
||||||
{
|
{
|
||||||
@@ -61,6 +63,13 @@ namespace Back.Controllers
|
|||||||
|
|
||||||
if (await _servInvoice.UpdateInvoice(invoice))
|
if (await _servInvoice.UpdateInvoice(invoice))
|
||||||
{
|
{
|
||||||
|
if (await _remittanceService.HasaRemittance(model.invoiceID, model.item.CODID))
|
||||||
|
{
|
||||||
|
//check mojodi
|
||||||
|
//add
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return Ok(await _servInvoiceItem.Add(new InvoiceItem
|
return Ok(await _servInvoiceItem.Add(new InvoiceItem
|
||||||
{
|
{
|
||||||
am = model.item.am,
|
am = model.item.am,
|
||||||
@@ -155,7 +164,15 @@ namespace Back.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (await _servInvoice.UpdateInvoice(invoice))
|
if (await _servInvoice.UpdateInvoice(invoice))
|
||||||
|
{
|
||||||
|
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));
|
return Ok(await _servInvoiceItem.Update(invoiceitem));
|
||||||
|
}
|
||||||
|
|
||||||
else return BadRequest(new List<string> { "خطایی رخ داده" });
|
else return BadRequest(new List<string> { "خطایی رخ داده" });
|
||||||
|
|
||||||
@@ -195,7 +212,12 @@ namespace Back.Controllers
|
|||||||
|
|
||||||
|
|
||||||
if (await _servInvoice.UpdateInvoice(invoiceitem.invoice))
|
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));
|
return Ok(await _servInvoiceItem.Delete(invoiceitem));
|
||||||
|
}
|
||||||
|
|
||||||
else return BadRequest(new List<string> { "خطایی رخ داده" });
|
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;
|
||||||
using Back.Services.Warehouse;
|
using Back.Services.Warehouse;
|
||||||
|
using Back.Validations.Warehouse.Receipt;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
@@ -17,6 +19,19 @@ namespace Back.Controllers.Warehouse
|
|||||||
{
|
{
|
||||||
private readonly ReceiptService _receiptService;
|
private readonly ReceiptService _receiptService;
|
||||||
private readonly servUser _servUser;
|
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}")]
|
[HttpGet("{ItemID}")]
|
||||||
public async Task<IActionResult> Get(int ItemID)
|
public async Task<IActionResult> Get(int ItemID)
|
||||||
{
|
{
|
||||||
@@ -38,8 +53,19 @@ namespace Back.Controllers.Warehouse
|
|||||||
[HttpPost("ADD")]
|
[HttpPost("ADD")]
|
||||||
public async Task<IActionResult> AddReceipt(ReceiptDto item)
|
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
|
// validate ADD
|
||||||
var newmodel = await _receiptService.ADD(item);
|
var newmodel = await _receiptService.ADD(item, CompanyID);
|
||||||
if (newmodel != null) return Ok(newmodel);
|
if (newmodel != null) return Ok(newmodel);
|
||||||
else return BadRequest(new List<string> { "خطا در صدور" });
|
else return BadRequest(new List<string> { "خطا در صدور" });
|
||||||
}
|
}
|
||||||
@@ -47,7 +73,16 @@ namespace Back.Controllers.Warehouse
|
|||||||
[HttpPut("Update")]
|
[HttpPut("Update")]
|
||||||
public async Task<IActionResult> UpdateReceipt(ReceiptDto item)
|
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);
|
var Updatemodel = await _receiptService.Update(item);
|
||||||
if (Updatemodel != null) return Ok(Updatemodel);
|
if (Updatemodel != null) return Ok(Updatemodel);
|
||||||
else return BadRequest(new List<string> { "خطا در ویرایش" });
|
else return BadRequest(new List<string> { "خطا در ویرایش" });
|
||||||
@@ -61,6 +96,11 @@ namespace Back.Controllers.Warehouse
|
|||||||
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
|
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
|
||||||
var CompanyID = user.RolUsers.First().CompanyID;
|
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);
|
var Deletemodel = await _receiptService.Delete(ItemID, CompanyID);
|
||||||
if (Deletemodel) return Ok();
|
if (Deletemodel) return Ok();
|
||||||
else return BadRequest(new List<string> { "خطا در حذف" });
|
else return BadRequest(new List<string> { "خطا در حذف" });
|
||||||
|
@@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Http;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Shared.DTOs.Warehouse;
|
using Shared.DTOs.Warehouse;
|
||||||
using Shared.Enums;
|
using Shared.Enums;
|
||||||
|
using Back.Validations.Warehouse.Remittance;
|
||||||
|
|
||||||
namespace Back.Controllers.Warehouse
|
namespace Back.Controllers.Warehouse
|
||||||
{
|
{
|
||||||
@@ -13,6 +14,20 @@ namespace Back.Controllers.Warehouse
|
|||||||
{
|
{
|
||||||
private readonly RemittanceService _treanceService;
|
private readonly RemittanceService _treanceService;
|
||||||
private readonly servUser _servUser;
|
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}")]
|
[HttpGet("{ItemID}")]
|
||||||
public async Task<IActionResult> Get(int ItemID)
|
public async Task<IActionResult> Get(int ItemID)
|
||||||
{
|
{
|
||||||
@@ -34,7 +49,17 @@ namespace Back.Controllers.Warehouse
|
|||||||
[HttpPost("ADD")]
|
[HttpPost("ADD")]
|
||||||
public async Task<IActionResult> Add(RemittanceDto item)
|
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);
|
var newmodel = await _treanceService.ADD(item);
|
||||||
if (newmodel != null) return Ok(newmodel);
|
if (newmodel != null) return Ok(newmodel);
|
||||||
else return BadRequest(new List<string> { "خطا در صدور" });
|
else return BadRequest(new List<string> { "خطا در صدور" });
|
||||||
@@ -43,7 +68,16 @@ namespace Back.Controllers.Warehouse
|
|||||||
[HttpPut("Update")]
|
[HttpPut("Update")]
|
||||||
public async Task<IActionResult> Update(RemittanceDto item)
|
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);
|
var Updatemodel = await _treanceService.Update(item);
|
||||||
if (Updatemodel != null) return Ok(Updatemodel);
|
if (Updatemodel != null) return Ok(Updatemodel);
|
||||||
else return BadRequest(new List<string> { "خطا در ویرایش" });
|
else return BadRequest(new List<string> { "خطا در ویرایش" });
|
||||||
@@ -57,6 +91,11 @@ namespace Back.Controllers.Warehouse
|
|||||||
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
|
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
|
||||||
var CompanyID = user.RolUsers.First().CompanyID;
|
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);
|
var Deletemodel = await _treanceService.Delete(ItemID, CompanyID);
|
||||||
if (Deletemodel) return Ok();
|
if (Deletemodel) return Ok();
|
||||||
else return BadRequest(new List<string> { "خطا در حذف" });
|
else return BadRequest(new List<string> { "خطا در حذف" });
|
||||||
|
@@ -9,12 +9,13 @@ namespace Back.Data.Models.Warehouse
|
|||||||
{
|
{
|
||||||
public int ID { get; set; }
|
public int ID { get; set; }
|
||||||
public int CODID { get; set; }
|
public int CODID { get; set; }
|
||||||
public int Count { get; set; }
|
public decimal Count { get; set; }
|
||||||
public string Date { get; set; }
|
public string Date { get; set; }
|
||||||
public bool ForSale { get; set; }
|
public bool ForSale { get; set; }
|
||||||
public TypeReceipt Type { get; set; }
|
public TypeReceipt Type { get; set; }
|
||||||
public string info { get; set; }
|
public string info { get; set; }
|
||||||
|
public bool Deleted { get; set; }
|
||||||
|
public int? InvoiceID { get; set; }
|
||||||
[ForeignKey("CODID")]
|
[ForeignKey("CODID")]
|
||||||
public CODItem cODItem { get; set; }
|
public CODItem cODItem { get; set; }
|
||||||
}
|
}
|
||||||
|
@@ -9,10 +9,12 @@ namespace Back.Data.Models.Warehouse
|
|||||||
{
|
{
|
||||||
public int ID { get; set; }
|
public int ID { get; set; }
|
||||||
public int CODID { get; set; }
|
public int CODID { get; set; }
|
||||||
public int Count { get; set; }
|
public decimal Count { get; set; }
|
||||||
public string Date { get; set; }
|
public string Date { get; set; }
|
||||||
public TypeRemittance Type { get; set; }
|
public TypeRemittance Type { get; set; }
|
||||||
public string info { get; set; }
|
public string info { get; set; }
|
||||||
|
public int? InvoiceID { get; set; }
|
||||||
|
public bool Deleted { get; set; }
|
||||||
|
|
||||||
[ForeignKey("CODID")]
|
[ForeignKey("CODID")]
|
||||||
public CODItem cODItem { get; set; }
|
public CODItem cODItem { get; set; }
|
||||||
|
@@ -88,6 +88,14 @@ builder.Services.AddScoped<ReceiptService>();
|
|||||||
builder.Services.AddScoped<RemittanceService>();
|
builder.Services.AddScoped<RemittanceService>();
|
||||||
builder.Services.AddScoped<WarehouseService>();
|
builder.Services.AddScoped<WarehouseService>();
|
||||||
builder.Services.AddScoped<servReport>();
|
builder.Services.AddScoped<servReport>();
|
||||||
|
builder.Services.AddScoped<Back.Validations.Warehouse.Receipt.ADDValidation>();
|
||||||
|
builder.Services.AddScoped<Back.Validations.Warehouse.Receipt.UpdateValidation>();
|
||||||
|
builder.Services.AddScoped<Back.Validations.Warehouse.Receipt.DeleteValidation>();
|
||||||
|
|
||||||
|
builder.Services.AddScoped<Back.Validations.Warehouse.Remittance.ADDValidation>();
|
||||||
|
builder.Services.AddScoped<Back.Validations.Warehouse.Remittance.UpdateValidation>();
|
||||||
|
builder.Services.AddScoped<Back.Validations.Warehouse.Remittance.DeleteValidation>();
|
||||||
|
|
||||||
builder.Services.AddScoped(c => new mpNuget.RestClient("09119660045", "C54S2"));
|
builder.Services.AddScoped(c => new mpNuget.RestClient("09119660045", "C54S2"));
|
||||||
|
|
||||||
string origins = "OriginTaxPayer";
|
string origins = "OriginTaxPayer";
|
||||||
|
@@ -216,6 +216,7 @@ namespace Back.Services
|
|||||||
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
//--------Tax---------
|
||||||
#region TaxPayer
|
#region TaxPayer
|
||||||
public async Task<bool> AllowSendTaxPayerInCompany(int CompanyID)
|
public async Task<bool> AllowSendTaxPayerInCompany(int CompanyID)
|
||||||
{
|
{
|
||||||
@@ -236,5 +237,14 @@ namespace Back.Services
|
|||||||
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
//--------Invoice---------
|
||||||
|
#region Warehouse
|
||||||
|
public async Task<bool> AllowAddReceiptInCompany(int CompanyID, int Allowednumber = 1)
|
||||||
|
{
|
||||||
|
int PermissionID = 18;
|
||||||
|
return await AllowPermissionInCompany(CompanyID, PermissionID, Allowednumber);
|
||||||
|
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -10,13 +10,19 @@ namespace Back.Services.Warehouse
|
|||||||
public class ReceiptService
|
public class ReceiptService
|
||||||
{
|
{
|
||||||
private readonly IAsyncRepository<Receipt> _ReceiptRepo;
|
private readonly IAsyncRepository<Receipt> _ReceiptRepo;
|
||||||
|
private readonly CheckPermission _checkPermission;
|
||||||
|
|
||||||
public ReceiptService(IAsyncRepository<Receipt> ReceiptRepo)
|
public ReceiptService(IAsyncRepository<Receipt> receiptRepo, CheckPermission checkPermission)
|
||||||
{
|
{
|
||||||
_ReceiptRepo = ReceiptRepo;
|
_ReceiptRepo = receiptRepo;
|
||||||
|
_checkPermission = checkPermission;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ReceiptDto?> ADD(ReceiptDto item)
|
public async Task<ReceiptDto?> ADD(ReceiptDto item, int CompanyID)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (await _checkPermission.ExtensionofAccess(CompanyID, 18, "-1"))
|
||||||
{
|
{
|
||||||
var model = new Receipt()
|
var model = new Receipt()
|
||||||
{
|
{
|
||||||
@@ -26,6 +32,7 @@ namespace Back.Services.Warehouse
|
|||||||
ForSale = item.ForSale,
|
ForSale = item.ForSale,
|
||||||
info = item.info,
|
info = item.info,
|
||||||
Type = item.Type,
|
Type = item.Type,
|
||||||
|
Deleted = false
|
||||||
};
|
};
|
||||||
var returnmodel = await _ReceiptRepo.AddAsync(model);
|
var returnmodel = await _ReceiptRepo.AddAsync(model);
|
||||||
if (returnmodel != null)
|
if (returnmodel != null)
|
||||||
@@ -38,6 +45,17 @@ namespace Back.Services.Warehouse
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
public async Task<ReceiptDto?> Update(ReceiptDto item)
|
public async Task<ReceiptDto?> Update(ReceiptDto item)
|
||||||
{
|
{
|
||||||
var model= await _ReceiptRepo.Get(w => w.ID == item.ID).FirstOrDefaultAsync();
|
var model= await _ReceiptRepo.Get(w => w.ID == item.ID).FirstOrDefaultAsync();
|
||||||
@@ -60,13 +78,13 @@ namespace Back.Services.Warehouse
|
|||||||
public async Task<bool> Delete(int itemID,int CompanyID)
|
public async Task<bool> Delete(int itemID,int CompanyID)
|
||||||
{
|
{
|
||||||
var model = await _ReceiptRepo.Get(w => w.ID == itemID && w.cODItem.CompanyID==CompanyID).FirstOrDefaultAsync();
|
var model = await _ReceiptRepo.Get(w => w.ID == itemID && w.cODItem.CompanyID==CompanyID).FirstOrDefaultAsync();
|
||||||
|
model.Deleted= true;
|
||||||
return await _ReceiptRepo.DeleteAsync(model);
|
return await _ReceiptRepo.UpdateAsync(model);
|
||||||
|
|
||||||
}
|
}
|
||||||
public async Task<ReceiptDto?> Get(int itemID, int CompanyID)
|
public async Task<ReceiptDto?> Get(int itemID, int CompanyID)
|
||||||
{
|
{
|
||||||
return await _ReceiptRepo.Get(w => w.ID == itemID && w.cODItem.CompanyID == CompanyID)
|
return await _ReceiptRepo.Get(w => w.ID == itemID && w.cODItem.CompanyID == CompanyID && !w.Deleted)
|
||||||
.Include(inc=>inc.cODItem)
|
.Include(inc=>inc.cODItem)
|
||||||
.Select(s=>new ReceiptDto()
|
.Select(s=>new ReceiptDto()
|
||||||
{
|
{
|
||||||
@@ -87,7 +105,7 @@ namespace Back.Services.Warehouse
|
|||||||
}
|
}
|
||||||
public async Task<List<ReceiptDto>?> GetAll(int CompanyID, TypeReceipt? Type=null, int CODID=0)
|
public async Task<List<ReceiptDto>?> GetAll(int CompanyID, TypeReceipt? Type=null, int CODID=0)
|
||||||
{
|
{
|
||||||
var request = _ReceiptRepo.Get(w => w.cODItem.CompanyID == CompanyID);
|
var request = _ReceiptRepo.Get(w => w.cODItem.CompanyID == CompanyID && !w.Deleted);
|
||||||
if (Type != null)
|
if (Type != null)
|
||||||
request = request.Where(w => w.Type == Type);
|
request = request.Where(w => w.Type == Type);
|
||||||
|
|
||||||
|
@@ -24,6 +24,7 @@ namespace Back.Services.Warehouse
|
|||||||
Count = item.Count,
|
Count = item.Count,
|
||||||
info = item.info,
|
info = item.info,
|
||||||
Type = item.Type,
|
Type = item.Type,
|
||||||
|
Deleted=false
|
||||||
};
|
};
|
||||||
var returnmodel = await _ReceiptRepo.AddAsync(model);
|
var returnmodel = await _ReceiptRepo.AddAsync(model);
|
||||||
if (returnmodel != null)
|
if (returnmodel != null)
|
||||||
@@ -36,6 +37,10 @@ namespace Back.Services.Warehouse
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public async Task AddRange(List<Remittance> items)
|
||||||
|
{
|
||||||
|
await _ReceiptRepo.AddRangeAsync(items);
|
||||||
|
}
|
||||||
public async Task<RemittanceDto?> Update(RemittanceDto item)
|
public async Task<RemittanceDto?> Update(RemittanceDto item)
|
||||||
{
|
{
|
||||||
var model = await _ReceiptRepo.Get(w => w.ID == item.ID).FirstOrDefaultAsync();
|
var model = await _ReceiptRepo.Get(w => w.ID == item.ID).FirstOrDefaultAsync();
|
||||||
@@ -44,6 +49,7 @@ namespace Back.Services.Warehouse
|
|||||||
model.Count = item.Count;
|
model.Count = item.Count;
|
||||||
model.info = item.info;
|
model.info = item.info;
|
||||||
model.Type = item.Type;
|
model.Type = item.Type;
|
||||||
|
|
||||||
var returnmodel = await _ReceiptRepo.UpdateAsync(model);
|
var returnmodel = await _ReceiptRepo.UpdateAsync(model);
|
||||||
if (returnmodel)
|
if (returnmodel)
|
||||||
{
|
{
|
||||||
@@ -56,14 +62,14 @@ namespace Back.Services.Warehouse
|
|||||||
}
|
}
|
||||||
public async Task<bool> Delete(int itemID, int CompanyID)
|
public async Task<bool> Delete(int itemID, int CompanyID)
|
||||||
{
|
{
|
||||||
var model = await _ReceiptRepo.Get(w => w.ID == itemID && w.cODItem.CompanyID == CompanyID).FirstOrDefaultAsync();
|
var model = await _ReceiptRepo.Get(w => w.ID == itemID && w.cODItem.CompanyID == CompanyID && !w.Deleted).FirstOrDefaultAsync();
|
||||||
|
model.Deleted = true;
|
||||||
return await _ReceiptRepo.DeleteAsync(model);
|
return await _ReceiptRepo.UpdateAsync(model);
|
||||||
|
|
||||||
}
|
}
|
||||||
public async Task<RemittanceDto?> Get(int itemID, int CompanyID)
|
public async Task<RemittanceDto?> Get(int itemID, int CompanyID)
|
||||||
{
|
{
|
||||||
return await _ReceiptRepo.Get(w => w.ID == itemID && w.cODItem.CompanyID == CompanyID)
|
return await _ReceiptRepo.Get(w => w.ID == itemID && w.cODItem.CompanyID == CompanyID && !w.Deleted)
|
||||||
.Include(inc => inc.cODItem)
|
.Include(inc => inc.cODItem)
|
||||||
.Select(s => new RemittanceDto()
|
.Select(s => new RemittanceDto()
|
||||||
{
|
{
|
||||||
@@ -83,7 +89,7 @@ namespace Back.Services.Warehouse
|
|||||||
}
|
}
|
||||||
public async Task<List<RemittanceDto>?> GetAll(int CompanyID, TypeRemittance? Type = null, int CODID = 0)
|
public async Task<List<RemittanceDto>?> GetAll(int CompanyID, TypeRemittance? Type = null, int CODID = 0)
|
||||||
{
|
{
|
||||||
var request = _ReceiptRepo.Get(w => w.cODItem.CompanyID == CompanyID);
|
var request = _ReceiptRepo.Get(w => w.cODItem.CompanyID == CompanyID && !w.Deleted);
|
||||||
if (Type != null)
|
if (Type != null)
|
||||||
request = request.Where(w => w.Type == Type);
|
request = request.Where(w => w.Type == Type);
|
||||||
|
|
||||||
@@ -108,6 +114,20 @@ namespace Back.Services.Warehouse
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
public async Task<bool> HasaRemittance(int InvoiceID)
|
||||||
|
{
|
||||||
|
return await _ReceiptRepo.Get(w => w.InvoiceID == InvoiceID && !w.Deleted).AnyAsync();
|
||||||
|
}
|
||||||
|
public async Task<bool> HasaRemittance(int InvoiceID,int CODID)
|
||||||
|
{
|
||||||
|
return await _ReceiptRepo.Get(w => w.InvoiceID == InvoiceID && w.CODID==CODID && !w.Deleted).AnyAsync();
|
||||||
|
}
|
||||||
|
public async Task DeleteByInvoiceIDandCODID(int InvoiceID, int CODID)
|
||||||
|
{
|
||||||
|
var model = await _ReceiptRepo.Get(w => w.InvoiceID == InvoiceID && w.CODID == CODID && !w.Deleted).FirstOrDefaultAsync();
|
||||||
|
model.Deleted = true;
|
||||||
|
await _ReceiptRepo.UpdateAsync(model);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@@ -25,7 +25,7 @@ namespace Back.Services.Warehouse
|
|||||||
}
|
}
|
||||||
public async Task<PagingDto<CirculationDto>> Circulation(int CompanyID,string date="",int CODID=0,int PageIndex=1,int PageSize=5)
|
public async Task<PagingDto<CirculationDto>> Circulation(int CompanyID,string date="",int CODID=0,int PageIndex=1,int PageSize=5)
|
||||||
{
|
{
|
||||||
var RequestRemittance = _RemittanceRepo.Get(w => w.cODItem.CompanyID == CompanyID)
|
var RequestRemittance = _RemittanceRepo.Get(w => w.cODItem.CompanyID == CompanyID && !w.Deleted)
|
||||||
.Select(s=>new CirculationDto
|
.Select(s=>new CirculationDto
|
||||||
{
|
{
|
||||||
CODID=s.CODID,
|
CODID=s.CODID,
|
||||||
@@ -42,7 +42,7 @@ namespace Back.Services.Warehouse
|
|||||||
if (CODID!=0)
|
if (CODID!=0)
|
||||||
RequestRemittance = RequestRemittance.Where(w => w.CODID == CODID);
|
RequestRemittance = RequestRemittance.Where(w => w.CODID == CODID);
|
||||||
//-----------
|
//-----------
|
||||||
var RequestReceipt = _ReceiptRepo.Get(w => w.cODItem.CompanyID == CompanyID)
|
var RequestReceipt = _ReceiptRepo.Get(w => w.cODItem.CompanyID == CompanyID && !w.Deleted)
|
||||||
.Select(s => new CirculationDto
|
.Select(s => new CirculationDto
|
||||||
{
|
{
|
||||||
CODID = s.CODID,
|
CODID = s.CODID,
|
||||||
@@ -64,10 +64,10 @@ namespace Back.Services.Warehouse
|
|||||||
//list.AddRange(await RequestRemittance.ToListAsync());
|
//list.AddRange(await RequestRemittance.ToListAsync());
|
||||||
//return await list.OrderByDescending(o=>o.Date).AsQueryable().Paging(PageIndex, PageSize);
|
//return await list.OrderByDescending(o=>o.Date).AsQueryable().Paging(PageIndex, PageSize);
|
||||||
}
|
}
|
||||||
public async Task<int> Inventory(int CompanyID,int CODID)
|
public async Task<decimal> Inventory(int CompanyID,int CODID)
|
||||||
{
|
{
|
||||||
var CReceipt=await _ReceiptRepo.Get(w => w.cODItem.CompanyID == CompanyID && w.CODID == CODID && w.ForSale ).SumAsync(s => s.Count);
|
var CReceipt=await _ReceiptRepo.Get(w => w.cODItem.CompanyID == CompanyID && w.CODID == CODID && w.ForSale && !w.Deleted).SumAsync(s => s.Count);
|
||||||
var CRemittance=await _RemittanceRepo.Get(w => w.cODItem.CompanyID == CompanyID && w.CODID == CODID ).SumAsync(s => s.Count);
|
var CRemittance=await _RemittanceRepo.Get(w => w.cODItem.CompanyID == CompanyID && w.CODID == CODID && !w.Deleted).SumAsync(s => s.Count);
|
||||||
return CReceipt - CRemittance;
|
return CReceipt - CRemittance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
45
Back/Validations/Warehouse/Receipt/ADDValidation.cs
Normal file
45
Back/Validations/Warehouse/Receipt/ADDValidation.cs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
using Back.Data.Contracts;
|
||||||
|
using FluentValidation;
|
||||||
|
using Shared.DTOs.Warehouse;
|
||||||
|
using Net.Pkcs11Interop.Common;
|
||||||
|
using Back.Services;
|
||||||
|
using Back.Data.Models;
|
||||||
|
|
||||||
|
namespace Back.Validations.Warehouse.Receipt
|
||||||
|
{
|
||||||
|
public class ADDValidation : AbstractValidator<Tuple<ReceiptDto,int>>
|
||||||
|
{
|
||||||
|
public ADDValidation(ServCOD servCOD, CheckPermission checkPermission)
|
||||||
|
{
|
||||||
|
// کالا مدنظر برای شرکت است
|
||||||
|
CascadeMode = CascadeMode.Stop;
|
||||||
|
|
||||||
|
RuleFor(model => model)
|
||||||
|
.Custom((model, context) => {
|
||||||
|
if (servCOD.ExistCodByCompanyID(model.Item1.CODID, model.Item2).Result)
|
||||||
|
context.AddFailure("کد کالا یافت نشد");
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
RuleFor(model => model.Item1.Count)
|
||||||
|
.Custom((model, context) => {
|
||||||
|
if (model <= 0)
|
||||||
|
context.AddFailure("تعداد نمیتواند صفر یا کمتر از صفر باشد");
|
||||||
|
});
|
||||||
|
|
||||||
|
RuleFor(model => model.Item1.info)
|
||||||
|
.Custom((model, context) => {
|
||||||
|
if (string.IsNullOrEmpty(model))
|
||||||
|
context.AddFailure("توضیحی برای رسید در نظر بگیرید");
|
||||||
|
});
|
||||||
|
|
||||||
|
RuleFor(r => r.Item2)
|
||||||
|
.Custom((CompanyID, context) =>
|
||||||
|
{
|
||||||
|
if (!checkPermission.AllowAddReceiptInCompany(CompanyID).Result)
|
||||||
|
context.AddFailure("اضافه کردن رسید محدود شده است");
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
30
Back/Validations/Warehouse/Receipt/DeleteValidation.cs
Normal file
30
Back/Validations/Warehouse/Receipt/DeleteValidation.cs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
using FluentValidation;
|
||||||
|
using Shared.DTOs.Warehouse;
|
||||||
|
using Back.Data.Models.Warehouse;
|
||||||
|
using Back.Data.Contracts;
|
||||||
|
using Back.Services.Warehouse;
|
||||||
|
using Back.Services;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace Back.Validations.Warehouse.Receipt
|
||||||
|
{
|
||||||
|
public class DeleteValidation : AbstractValidator<Tuple<int, int>>
|
||||||
|
{
|
||||||
|
public DeleteValidation(IAsyncRepository<Back.Data.Models.Warehouse.Receipt> _ReceiptRepo, WarehouseService warehouseService)
|
||||||
|
{
|
||||||
|
RuleFor(model => model)
|
||||||
|
.Custom((model, context) =>
|
||||||
|
{
|
||||||
|
var ORGitem = _ReceiptRepo.Get(w => w.ID == model.Item1 && w.cODItem.CompanyID == model.Item2 && !w.Deleted).Include(i => i.cODItem).FirstOrDefault();
|
||||||
|
if (ORGitem == null)
|
||||||
|
context.AddFailure("رسید یافت نشد");
|
||||||
|
|
||||||
|
var Inventory = warehouseService.Inventory(model.Item2, ORGitem.CODID).Result;
|
||||||
|
if (Inventory - ORGitem.Count < 0)
|
||||||
|
{
|
||||||
|
context.AddFailure($"حذف رسید روی موجودی کالا {ORGitem.cODItem.Title} تاثیر میگذارد و آن را منفی میکند");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
78
Back/Validations/Warehouse/Receipt/UpdateValidation.cs
Normal file
78
Back/Validations/Warehouse/Receipt/UpdateValidation.cs
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
using Back.Data.Contracts;
|
||||||
|
using Back.Services;
|
||||||
|
using Back.Services.Warehouse;
|
||||||
|
using FluentValidation;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.IdentityModel.Tokens;
|
||||||
|
using Shared.DTOs.Warehouse;
|
||||||
|
|
||||||
|
namespace Back.Validations.Warehouse.Receipt
|
||||||
|
{
|
||||||
|
public class UpdateValidation : AbstractValidator<Tuple<ReceiptDto, int>>
|
||||||
|
{
|
||||||
|
public UpdateValidation(IAsyncRepository<Back.Data.Models.Warehouse.Receipt> _ReceiptRepo, ServCOD servCOD, WarehouseService warehouseService)
|
||||||
|
{
|
||||||
|
CascadeMode = CascadeMode.Stop;
|
||||||
|
RuleFor(model => model)
|
||||||
|
.Custom((model, context) =>
|
||||||
|
{
|
||||||
|
var ORGitem = _ReceiptRepo.Get(w => w.ID == model.Item1.ID && !w.Deleted).Include(i => i.cODItem).FirstOrDefault();
|
||||||
|
if (ORGitem.InvoiceID.HasValue)
|
||||||
|
{
|
||||||
|
context.AddFailure("رسید فاکتور قایل ویرایش نیست");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ORGitem == null)
|
||||||
|
context.AddFailure("رسید یافت نشد");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (ORGitem.CODID != model.Item1.CODID)
|
||||||
|
{
|
||||||
|
if (servCOD.ExistCodByCompanyID(model.Item1.CODID, model.Item2).Result)
|
||||||
|
context.AddFailure("کد کالا یافت نشد");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (ORGitem.CODID != model.Item1.CODID)
|
||||||
|
{
|
||||||
|
|
||||||
|
context.AddFailure("در رسید امکان ویرایش کالا انکان پذیر نیست");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ((ORGitem.Count > model.Item1.Count && ORGitem.ForSale && !model.Item1.ForSale) ||
|
||||||
|
ORGitem.Count > model.Item1.Count)
|
||||||
|
{
|
||||||
|
var ekh = ORGitem.Count - model.Item1.Count;
|
||||||
|
var Inventory = warehouseService.Inventory(model.Item2, ORGitem.CODID).Result;
|
||||||
|
if ((Inventory - ekh) < 0)
|
||||||
|
{
|
||||||
|
context.AddFailure($"این تغییرات روی موجودی کالا {ORGitem.cODItem.Title} تاثیر میگذارد و آن را منفی میکند");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (ORGitem.ForSale && !model.Item1.ForSale)
|
||||||
|
{
|
||||||
|
var Inventory = warehouseService.Inventory(model.Item2, ORGitem.CODID).Result;
|
||||||
|
if (Inventory - ORGitem.Count < 0)
|
||||||
|
{
|
||||||
|
context.AddFailure($"این تغییرات روی موجودی کالا {ORGitem.cODItem.Title} تاثیر میگذارد و آن را منفی میکند");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(model.Item1.info))
|
||||||
|
{
|
||||||
|
context.AddFailure("توضیحی برای رسید در نظر بگیرید");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
42
Back/Validations/Warehouse/Remittance/ADDValidation.cs
Normal file
42
Back/Validations/Warehouse/Remittance/ADDValidation.cs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
using Back.Services;
|
||||||
|
using Back.Services.Warehouse;
|
||||||
|
using FluentValidation;
|
||||||
|
using Shared.DTOs.Warehouse;
|
||||||
|
|
||||||
|
namespace Back.Validations.Warehouse.Remittance
|
||||||
|
{
|
||||||
|
public class ADDValidation : AbstractValidator<Tuple<RemittanceDto, int>>
|
||||||
|
{
|
||||||
|
public ADDValidation(ServCOD servCOD, WarehouseService warehouseService)
|
||||||
|
{
|
||||||
|
CascadeMode = CascadeMode.Stop;
|
||||||
|
|
||||||
|
RuleFor(model => model)
|
||||||
|
.Custom((model, context) =>
|
||||||
|
{
|
||||||
|
if (servCOD.ExistCodByCompanyID(model.Item1.CODID, model.Item2).Result)
|
||||||
|
context.AddFailure("کد کالا یافت نشد");
|
||||||
|
});
|
||||||
|
|
||||||
|
RuleFor(model => model.Item1.Count)
|
||||||
|
.Custom((model, context) => {
|
||||||
|
if (model <= 0)
|
||||||
|
context.AddFailure("تعداد نمیتواند صفر یا کمتر از صفر باشد");
|
||||||
|
});
|
||||||
|
|
||||||
|
RuleFor(model => model.Item1.info)
|
||||||
|
.Custom((model, context) => {
|
||||||
|
if (string.IsNullOrEmpty(model))
|
||||||
|
context.AddFailure("توضیحی برای رسید در نظر بگیرید");
|
||||||
|
});
|
||||||
|
|
||||||
|
RuleFor(model => model)
|
||||||
|
.Custom((model, context) =>
|
||||||
|
{
|
||||||
|
var inv = warehouseService.Inventory(model.Item2, model.Item1.CODID).Result;
|
||||||
|
if (inv < model.Item1.Count)
|
||||||
|
context.AddFailure("موجودی کمتر از مقدار حواله می باشد");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
22
Back/Validations/Warehouse/Remittance/DeleteValidation.cs
Normal file
22
Back/Validations/Warehouse/Remittance/DeleteValidation.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
using Back.Data.Contracts;
|
||||||
|
using Back.Services.Warehouse;
|
||||||
|
using FluentValidation;
|
||||||
|
using Shared.DTOs.Warehouse;
|
||||||
|
|
||||||
|
namespace Back.Validations.Warehouse.Remittance
|
||||||
|
{
|
||||||
|
public class DeleteValidation : AbstractValidator<Tuple<int, int>>
|
||||||
|
{
|
||||||
|
public DeleteValidation(IAsyncRepository<Back.Data.Models.Warehouse.Remittance> _Repo)
|
||||||
|
{
|
||||||
|
RuleFor(model => model)
|
||||||
|
.Custom((model, context) =>
|
||||||
|
{
|
||||||
|
var ORGitem = _Repo.Get(w => w.ID == model.Item1 && w.cODItem.CompanyID == model.Item2 && !w.Deleted).FirstOrDefault();
|
||||||
|
if (ORGitem == null)
|
||||||
|
context.AddFailure("حواله یافت نشد");
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
55
Back/Validations/Warehouse/Remittance/UpdateValidation.cs
Normal file
55
Back/Validations/Warehouse/Remittance/UpdateValidation.cs
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
using Back.Data.Contracts;
|
||||||
|
using Back.Services.Warehouse;
|
||||||
|
using Back.Services;
|
||||||
|
using FluentValidation;
|
||||||
|
using Shared.DTOs.Warehouse;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace Back.Validations.Warehouse.Remittance
|
||||||
|
{
|
||||||
|
public class UpdateValidation : AbstractValidator<Tuple<RemittanceDto, int>>
|
||||||
|
{
|
||||||
|
public UpdateValidation(IAsyncRepository<Back.Data.Models.Warehouse.Remittance> _Repo, ServCOD servCOD, WarehouseService warehouseService)
|
||||||
|
{
|
||||||
|
CascadeMode = CascadeMode.Stop;
|
||||||
|
RuleFor(model => model)
|
||||||
|
.Custom((model, context) => {
|
||||||
|
var ORGitem = _Repo.Get(w => w.ID == model.Item1.ID && !w.Deleted).Include(i => i.cODItem).FirstOrDefault();
|
||||||
|
if (ORGitem.InvoiceID.HasValue)
|
||||||
|
{
|
||||||
|
context.AddFailure("حواله فاکتور قایل ویرایش نیست");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ORGitem == null)
|
||||||
|
context.AddFailure("حواله یافت نشد");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (ORGitem.CODID != model.Item1.CODID)
|
||||||
|
{
|
||||||
|
|
||||||
|
context.AddFailure("در حئاله امکان ویرایش کالا انکان پذیر نیست");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( (ORGitem.Count < model.Item1.Count))
|
||||||
|
{
|
||||||
|
var Inventory = warehouseService.Inventory(model.Item2, model.Item1.CODID).Result;
|
||||||
|
if (Inventory - (model.Item1.Count - ORGitem.Count) < 0)
|
||||||
|
{
|
||||||
|
context.AddFailure($"این تغییرات روی موجودی کالا تاثیر میگذارد و آن را منفی میکند");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.Item1.info))
|
||||||
|
{
|
||||||
|
context.AddFailure("توضیحی برای حواله در نظر بگیرید");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -20,7 +20,7 @@ namespace Shared.DTOs.Warehouse
|
|||||||
{
|
{
|
||||||
public int CODID { get; set; }
|
public int CODID { get; set; }
|
||||||
public string? CODTitle { get; set; }
|
public string? CODTitle { get; set; }
|
||||||
public int Count { get; set; }
|
public decimal Count { get; set; }
|
||||||
public string Date { get; set; }
|
public string Date { get; set; }
|
||||||
public bool? ForSale { get; set; }
|
public bool? ForSale { get; set; }
|
||||||
public string ModelTypeTitle { get; set; }
|
public string ModelTypeTitle { get; set; }
|
||||||
|
@@ -12,10 +12,11 @@ namespace Shared.DTOs.Warehouse
|
|||||||
public int? ID { get; set; }
|
public int? ID { get; set; }
|
||||||
public int CODID { get; set; }
|
public int CODID { get; set; }
|
||||||
public string? CODTitle { get; set; }
|
public string? CODTitle { get; set; }
|
||||||
public int Count { get; set; }
|
public decimal Count { get; set; }
|
||||||
public string Date { get; set; }
|
public string Date { get; set; }
|
||||||
public bool ForSale { get; set; }
|
public bool ForSale { get; set; }
|
||||||
public TypeReceipt Type { get; set; }
|
public TypeReceipt Type { get; set; }
|
||||||
public string info { get; set; }
|
public string info { get; set; }
|
||||||
|
public int? InvoiceID { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -12,9 +12,10 @@ namespace Shared.DTOs.Warehouse
|
|||||||
public int? ID { get; set; }
|
public int? ID { get; set; }
|
||||||
public int CODID { get; set; }
|
public int CODID { get; set; }
|
||||||
public string CODTitle { get; set; }
|
public string CODTitle { get; set; }
|
||||||
public int Count { get; set; }
|
public decimal Count { get; set; }
|
||||||
public string Date { get; set; }
|
public string Date { get; set; }
|
||||||
public TypeRemittance Type { get; set; }
|
public TypeRemittance Type { get; set; }
|
||||||
public string info { get; set; }
|
public string info { get; set; }
|
||||||
|
public int? InvoiceID { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user