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,7 +41,8 @@ namespace Back.Validations
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
When(m => m.Item3 == eActionValidation.add || m.Item3 == eActionValidation.update, () =>
|
||||
{
|
||||
RuleFor(r => r.Item2.Title)
|
||||
.NotNull().WithMessage("عنوان نمی تواند خالی باشد")
|
||||
.NotEmpty().WithMessage("عنوان نمی تواند خالی باشد")
|
||||
@@ -50,14 +51,14 @@ namespace Back.Validations
|
||||
RuleFor(r => r.Item2.PatternID)
|
||||
.Custom((PatternID, context) =>
|
||||
{
|
||||
if (PatternID!=null && PatternID > 0 && !patternRepo.Get(w => w.Status && w.ID == PatternID).AnyAsync().Result)
|
||||
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)
|
||||
if (model.Item2.CustomerID == null || model.Item2.CustomerID <= 0)
|
||||
context.AddFailure("برای صدور صورتحساب باید مشتری تعریف شود");
|
||||
|
||||
else if (!servCustomer.ExistCustomerByCustomerID(model.Item2.CustomerID, model.Item1).Result)
|
||||
@@ -83,6 +84,7 @@ namespace Back.Validations
|
||||
else if (InvoicIssueDate.Trim().ToMiladi() > DateTime.Now)
|
||||
context.AddFailure("تاریخ صدور صورتحساب نمی تواند از امروز جلوتر باشد");
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -56,7 +56,7 @@
|
||||
@if (InvoiceID == 0 || InvoiceID == null ? false : true && !invoice.IsDeleted)
|
||||
{
|
||||
<div class="row g-3">
|
||||
|
||||
<div class="form-group col-md-9">
|
||||
<div class="multi-button">
|
||||
@switch (invoice.invoiceType)
|
||||
{
|
||||
@@ -88,10 +88,17 @@
|
||||
break; *@
|
||||
}
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="form-group col-md-3">
|
||||
<div class="multi-button">
|
||||
<Button class="button" style="color:white;" @onclick="CopyInvoice" id="sbg"><span>کپی صورتحساب</span></Button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<br />
|
||||
@if (invoice.InvoiceSendTaxs.Count > 0)
|
||||
{
|
||||
@@ -465,6 +472,28 @@
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
private async Task CopyInvoice()
|
||||
{
|
||||
|
||||
var rsp = await hc.Post($"Invoice/CopyInvoice/{InvoiceID}");
|
||||
if (rsp.IsSuccessStatusCode)
|
||||
{
|
||||
var resinvoice = await rsp.Content.ReadFromJsonAsync<InvoiceDTO>();
|
||||
if (resinvoice != null)
|
||||
{
|
||||
invoice = resinvoice;
|
||||
InvoiceID = resinvoice.ID;
|
||||
ShowSuccessAlert("صورتحساب جدید با موفقیت ایجاد شد");
|
||||
}
|
||||
else ShowDangerAlert("خطایی در اجرای عملیات رخ داده");
|
||||
}
|
||||
else
|
||||
{
|
||||
var request = await rsp.Content.ReadFromJsonAsync<List<string>>();
|
||||
ShowDangerAlert(request[0]);
|
||||
}
|
||||
|
||||
}
|
||||
private async Task ChangeStatus(int type)
|
||||
{
|
||||
|
@@ -136,6 +136,10 @@ code {
|
||||
background-color: rgb(242 42 42);
|
||||
border: 1px solid rgb(242 42 42);
|
||||
}
|
||||
#sbg {
|
||||
background-color: rgb(122, 188, 188);
|
||||
border: 1px solid rgb(122, 188, 188);
|
||||
}
|
||||
#sred1 {
|
||||
background-color: #ff7373;
|
||||
border: 1px solid #ff7373;
|
||||
|
Reference in New Issue
Block a user