copy invoice
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
{
|
||||
add,
|
||||
update,
|
||||
delete
|
||||
delete,
|
||||
copy
|
||||
}
|
||||
}
|
||||
|
@@ -131,7 +131,11 @@ namespace Back.Controllers
|
||||
Invoice invoice = await _servInvoice.GetInvoiceByInvoiceID(user.RolUsers.First().CompanyID, item.ID.Value);
|
||||
if (invoice == null)
|
||||
return BadRequest(new List<string> { "invoice notFound..." });
|
||||
|
||||
if (invoice.PatternID != item.PatternID && invoice.invoice!=null)
|
||||
{
|
||||
return BadRequest(new List<string> { "این صورتحساب دارای مرجع می باشد"+'\n'+
|
||||
"امکان تغییر الگو امکان پذیر نیست"});
|
||||
}
|
||||
if (invoice.PatternID != item.PatternID || invoice.CustomerID != item.CustomerID
|
||||
|| invoice.InvoicIssueDate != item.InvoicIssueDate || invoice.InvoiceDate != item.InvoiceDate)
|
||||
{
|
||||
@@ -352,6 +356,56 @@ namespace Back.Controllers
|
||||
}
|
||||
|
||||
|
||||
return NoContent();
|
||||
|
||||
}
|
||||
[HttpPost("CopyInvoice/{InvoiceID}")]// ok
|
||||
public async Task<ActionResult<InvoiceDTO>> CopyInvoice(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));
|
||||
|
||||
|
||||
|
||||
Invoice? Invoice = await _servInvoice.GetInvoiceByInvoiceID(user.RolUsers.First().CompanyID, InvoiceID);
|
||||
if (Invoice == null) return NotFound();
|
||||
|
||||
//-----Validaton
|
||||
var resultValidationmodel = await _validationInvoice.ValidateAsync(Tuple.Create(user.RolUsers.First().CompanyID, new NUInvoiceDTO(), eActionValidation.copy));
|
||||
if (!resultValidationmodel.IsValid)
|
||||
return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList());
|
||||
|
||||
|
||||
var result = await _servInvoice.AddInvoice(new Invoice()
|
||||
{
|
||||
|
||||
Title = Invoice.Title,
|
||||
Des = Invoice.Des,
|
||||
invoiceType = InvoiceType.Bidding,
|
||||
CustomerID = Invoice.CustomerID,
|
||||
CompanyID = Invoice.CompanyID,
|
||||
InvoicIssueDate = Invoice.InvoicIssueDate.Replace("/", ""),
|
||||
InvoiceDate = Invoice.InvoicIssueDate.Replace("/", ""),
|
||||
LastChangeUserID = Convert.ToInt32(UserID),
|
||||
BillReference = Invoice.ID,
|
||||
IsDeleted = false,
|
||||
PatternID = Invoice.PatternID,
|
||||
setm = Invoice.setm,
|
||||
invoiceDetails = Invoice.invoiceDetails.Select(s => new InvoiceItem
|
||||
{
|
||||
CODID = s.CODID,
|
||||
am = s.am,
|
||||
fee = s.fee,
|
||||
dis = s.dis,
|
||||
|
||||
}).ToList()
|
||||
}, true);
|
||||
if (result > 0)
|
||||
return Ok(await _servInvoice.GetInvoice(user.RolUsers.First().CompanyID, result));
|
||||
|
||||
|
||||
return NoContent();
|
||||
|
||||
}
|
||||
|
@@ -43,7 +43,8 @@ namespace Back.Validations
|
||||
});
|
||||
RuleFor(r => r.Item3.am)
|
||||
.NotEmpty().WithMessage("تعداد مشخص نشده")
|
||||
.NotNull().WithMessage("تعداد مشخص نشده");
|
||||
.NotNull().WithMessage("تعداد مشخص نشده")
|
||||
.LessThanOrEqualTo(0).WithMessage("تعداد نمی تواند صفر یا کمتر باشد");
|
||||
|
||||
RuleFor(r => r.Item3.fee)
|
||||
.NotEmpty().WithMessage("مبلغ واحد مشخص نشده")
|
||||
|
@@ -30,7 +30,7 @@ namespace Back.Validations
|
||||
});
|
||||
|
||||
});
|
||||
When(m => m.Item3 == eActionValidation.add, () =>
|
||||
When(m => m.Item3 == eActionValidation.add || m.Item3 == eActionValidation.copy, () =>
|
||||
{
|
||||
RuleFor(r => r.Item1)
|
||||
.Custom((CompanyID, context) =>
|
||||
@@ -41,48 +41,50 @@ namespace Back.Validations
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
RuleFor(r => r.Item2.Title)
|
||||
When(m => m.Item3 == eActionValidation.add || m.Item3 == eActionValidation.update, () =>
|
||||
{
|
||||
RuleFor(r => r.Item2.Title)
|
||||
.NotNull().WithMessage("عنوان نمی تواند خالی باشد")
|
||||
.NotEmpty().WithMessage("عنوان نمی تواند خالی باشد")
|
||||
.MinimumLength(3).WithMessage("عنوان حداقل باید 3 کاراکتر باشد");
|
||||
|
||||
RuleFor(r => r.Item2.PatternID)
|
||||
.Custom((PatternID, context) =>
|
||||
{
|
||||
if (PatternID!=null && PatternID > 0 && !patternRepo.Get(w => w.Status && w.ID == PatternID).AnyAsync().Result)
|
||||
context.AddFailure("الگوی صورتحساب معتبر نیست");
|
||||
});
|
||||
|
||||
RuleFor(r => r)
|
||||
.Custom((model, context) =>
|
||||
{
|
||||
if (model.Item2.CustomerID == null || model.Item2.CustomerID <=0)
|
||||
context.AddFailure("برای صدور صورتحساب باید مشتری تعریف شود");
|
||||
|
||||
else if (!servCustomer.ExistCustomerByCustomerID(model.Item2.CustomerID, model.Item1).Result)
|
||||
context.AddFailure("مشتری یافت نشد");
|
||||
});
|
||||
|
||||
RuleFor(r => r.Item2.InvoiceDate)
|
||||
.Custom((InvoiceDate, context) =>
|
||||
RuleFor(r => r.Item2.PatternID)
|
||||
.Custom((PatternID, context) =>
|
||||
{
|
||||
if (string.IsNullOrEmpty(InvoiceDate))
|
||||
context.AddFailure("تاریخ ایجاد صورتحساب نمی تواند خالی باشد");
|
||||
|
||||
else if (InvoiceDate.Trim().ToMiladi() > DateTime.Now)
|
||||
context.AddFailure("تاریخ ایجاد صورتحساب نمی تواند از امروز جلوتر باشد");
|
||||
if (PatternID != null && PatternID > 0 && !patternRepo.Get(w => w.Status && w.ID == PatternID).AnyAsync().Result)
|
||||
context.AddFailure("الگوی صورتحساب معتبر نیست");
|
||||
});
|
||||
|
||||
RuleFor(r => r.Item2.InvoicIssueDate)
|
||||
.Custom((InvoicIssueDate, context) =>
|
||||
RuleFor(r => r)
|
||||
.Custom((model, context) =>
|
||||
{
|
||||
if (string.IsNullOrEmpty(InvoicIssueDate))
|
||||
context.AddFailure("تاریخ صدور صورتحساب نمی تواند خالی باشد");
|
||||
if (model.Item2.CustomerID == null || model.Item2.CustomerID <= 0)
|
||||
context.AddFailure("برای صدور صورتحساب باید مشتری تعریف شود");
|
||||
|
||||
else if (InvoicIssueDate.Trim().ToMiladi() > DateTime.Now)
|
||||
context.AddFailure("تاریخ صدور صورتحساب نمی تواند از امروز جلوتر باشد");
|
||||
else if (!servCustomer.ExistCustomerByCustomerID(model.Item2.CustomerID, model.Item1).Result)
|
||||
context.AddFailure("مشتری یافت نشد");
|
||||
});
|
||||
|
||||
RuleFor(r => r.Item2.InvoiceDate)
|
||||
.Custom((InvoiceDate, context) =>
|
||||
{
|
||||
if (string.IsNullOrEmpty(InvoiceDate))
|
||||
context.AddFailure("تاریخ ایجاد صورتحساب نمی تواند خالی باشد");
|
||||
|
||||
else if (InvoiceDate.Trim().ToMiladi() > DateTime.Now)
|
||||
context.AddFailure("تاریخ ایجاد صورتحساب نمی تواند از امروز جلوتر باشد");
|
||||
});
|
||||
|
||||
RuleFor(r => r.Item2.InvoicIssueDate)
|
||||
.Custom((InvoicIssueDate, context) =>
|
||||
{
|
||||
if (string.IsNullOrEmpty(InvoicIssueDate))
|
||||
context.AddFailure("تاریخ صدور صورتحساب نمی تواند خالی باشد");
|
||||
|
||||
else if (InvoicIssueDate.Trim().ToMiladi() > DateTime.Now)
|
||||
context.AddFailure("تاریخ صدور صورتحساب نمی تواند از امروز جلوتر باشد");
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user