+ Timeout logout
+ Pred kreiranjem povpraševanja vprašaj za partnerja + Prikaz TOP 100 (predolgo nalaga) + Dodaj Sorovec na Urejanje Artikla (zadnji surovec) + V Urejanju artikla popravi opis v pot dokumentov + Kooperant
This commit is contained in:
@@ -37,6 +37,8 @@
|
||||
<br />Cena skupaj: <b>@Model.TotalPrice €</b>
|
||||
<br />Prodajna cena: <b>@Model.SellingPrice €</b>
|
||||
<br />Razlika: <b>@Model.DifferenceInPricePercentage %</b>
|
||||
<br />Material: <b>@Model.Material </b>
|
||||
<br />Dimenzije surovca: <b>@Model.MaterialDimensions </b>
|
||||
</div>
|
||||
@if (Model.Files != null && Model.Files.Count > 0)
|
||||
{
|
||||
|
||||
@@ -29,7 +29,8 @@ namespace EveryThing.Pages.CodeTableItems
|
||||
public string TotalPrice { get; set; }
|
||||
public string SellingPrice { get; set; }
|
||||
public string DifferenceInPricePercentage { get; set; }
|
||||
|
||||
public string MaterialDimensions { get; set; }
|
||||
public string Material { get; set; }
|
||||
}
|
||||
|
||||
private readonly ApplicationDbContext _context;
|
||||
@@ -51,17 +52,29 @@ namespace EveryThing.Pages.CodeTableItems
|
||||
{
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
|
||||
ViewData["SearchString"] = searchString;
|
||||
ViewData["SearchString"] = searchString ?? "";
|
||||
|
||||
var search = !string.IsNullOrEmpty(searchString);
|
||||
|
||||
Item = await _context.CodeTableItems
|
||||
.Where(x => x.IdCompanyFk == user.IdCompanyFk)
|
||||
.Include(j => j.Company).ToListAsync();
|
||||
.Where(x => x.IdCompanyFk == user.IdCompanyFk
|
||||
&& EF.Functions.Like(x.Title, $"%{searchString}%")
|
||||
|| EF.Functions.Like(x.Description, $"%{searchString}%"))
|
||||
.Include(j => j.Company).Take(100).ToListAsync();
|
||||
|
||||
if (!string.IsNullOrEmpty(searchString))
|
||||
{
|
||||
Item = Item.Where(s => s.Title.Contains(searchString, StringComparison.InvariantCultureIgnoreCase)
|
||||
|| (s.Description != null && s.Description.Contains(searchString, StringComparison.InvariantCultureIgnoreCase))).ToList();
|
||||
}
|
||||
//Item = await _context.CodeTableItems
|
||||
// .Where(x => x.IdCompanyFk == user.IdCompanyFk
|
||||
// && (!search
|
||||
// || EF.Functions.Like(x.Title, $"%{searchString}%")
|
||||
// || (x.Description != null
|
||||
// && EF.Functions.Like(x.Description, $"%{searchString}%"))))
|
||||
// .Include(j => j.Company).Take(100).ToListAsync();
|
||||
|
||||
//if ()
|
||||
//{
|
||||
// Item = Item.Where(s => s.Title.Contains(searchString, StringComparison.InvariantCultureIgnoreCase)
|
||||
// || (s.Description != null && s.Description.Contains(searchString, StringComparison.InvariantCultureIgnoreCase))).ToList();
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
@@ -75,6 +88,8 @@ namespace EveryThing.Pages.CodeTableItems
|
||||
var workPrice = 0d;
|
||||
var sellingPrice = 0d;
|
||||
var differenceInPricePercentage = 0d;
|
||||
var materialDimensions = "";
|
||||
var material = "";
|
||||
|
||||
if (edit)
|
||||
{
|
||||
@@ -98,6 +113,7 @@ namespace EveryThing.Pages.CodeTableItems
|
||||
else
|
||||
{
|
||||
var projectPartItem = _context.ProjectPartItems
|
||||
.Include(x => x.Material)
|
||||
.OrderByDescending(x => x.DateModified)
|
||||
.ThenByDescending(x => x.IdProjectPartItem)
|
||||
.FirstOrDefault(x => x.IdItemFk == item.IdItem);
|
||||
@@ -108,6 +124,8 @@ namespace EveryThing.Pages.CodeTableItems
|
||||
workPrice = projectPartItem.WorkPrice;
|
||||
sellingPrice = projectPartItem.SellingPrice;
|
||||
differenceInPricePercentage = projectPartItem.DifferenceInPricePercentage;
|
||||
materialDimensions = projectPartItem.MaterialDimensions;
|
||||
material = projectPartItem.Material.Title;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +140,9 @@ namespace EveryThing.Pages.CodeTableItems
|
||||
SellingPrice = sellingPrice.ToString("#,###,##0.00", new CultureInfo("sl-SI")),
|
||||
TotalPrice = (materialPrice + workPrice).ToString("#,###,##0.00", new CultureInfo("sl-SI")),
|
||||
WorkPrice = workPrice.ToString("#,###,##0.00", new CultureInfo("sl-SI")),
|
||||
DifferenceInPricePercentage = differenceInPricePercentage.ToString("#,###,##0.00", new CultureInfo("sl-SI"))
|
||||
DifferenceInPricePercentage = differenceInPricePercentage.ToString("#,###,##0.00", new CultureInfo("sl-SI")),
|
||||
MaterialDimensions = materialDimensions,
|
||||
Material = material
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using EveryThing.Data;
|
||||
using EveryThing.Data;
|
||||
using EveryThing.Models;
|
||||
using EveryThing.Models.CodeTable;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.Data.SqlClient;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EveryThing.Pages.CodeTablePartners
|
||||
{
|
||||
@@ -49,5 +51,30 @@ namespace EveryThing.Pages.CodeTablePartners
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public IActionResult OnGetPartners(bool? suppliers)
|
||||
{
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
|
||||
var successful = true;
|
||||
var error = "";
|
||||
|
||||
var partners = _context.CodeTablePartners
|
||||
.Where(x => x.IdCompanyFk == user.IdCompanyFk);
|
||||
|
||||
if (suppliers != null)
|
||||
partners = partners.Where(x => x.Supplier == suppliers);
|
||||
|
||||
var sbJson = new StringBuilder();
|
||||
|
||||
foreach (var codeTablePartner in partners)
|
||||
{
|
||||
if (sbJson.Length > 0)
|
||||
sbJson.Append(",");
|
||||
sbJson.Append($"\"{codeTablePartner.IdPartner}\": \"{codeTablePartner.Title}\"");
|
||||
}
|
||||
|
||||
return new JsonResult(new { jsonPartners = $"{{{sbJson}}}", error = error, successful = successful });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,9 @@
|
||||
case 3:
|
||||
<i>Naročila kupcev</i>
|
||||
break;
|
||||
case 4:
|
||||
<i>Kooperacije</i>
|
||||
break;
|
||||
default:
|
||||
<i>Fakture</i>
|
||||
break;
|
||||
|
||||
@@ -56,6 +56,9 @@
|
||||
case 3:
|
||||
<i>Naročila kupcev</i>
|
||||
break;
|
||||
case 4:
|
||||
<i>Kooperacije</i>
|
||||
break;
|
||||
default:
|
||||
<i>Fakture</i>
|
||||
break;
|
||||
@@ -145,6 +148,9 @@
|
||||
case 3:
|
||||
<i>Naročilo kupca</i>
|
||||
break;
|
||||
case 4:
|
||||
<i>Kooperacija</i>
|
||||
break;
|
||||
default:
|
||||
<i>Faktura</i>
|
||||
break;
|
||||
|
||||
@@ -13,6 +13,7 @@ using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using EveryThing.Models.Project;
|
||||
using System.Text.Json;
|
||||
using EveryThing.Models.Invoice;
|
||||
using static EveryThing.Pages.Projects.EditModel;
|
||||
|
||||
namespace EveryThing.Pages.Invoices
|
||||
@@ -106,10 +107,26 @@ namespace EveryThing.Pages.Invoices
|
||||
return Page();
|
||||
}
|
||||
|
||||
//var oldInvoice = _context.Invoices.FirstOrDefault(x => x.IdInvoice == Invoice.IdInvoice);
|
||||
|
||||
var statusChanged = true;//oldInvoice == null || oldInvoice.State != Invoice.State;
|
||||
|
||||
Invoice.PostText = Invoice.PostText.Replace("<div><br></div>", "");
|
||||
Invoice.PreText = Invoice.PreText.Replace("<div><br></div>", "");
|
||||
|
||||
_context.Attach(Invoice).State = EntityState.Modified;
|
||||
|
||||
if (Invoice.Type == Invoice.InvoiceType.Cooperation
|
||||
&& statusChanged
|
||||
&& Invoice.State == Invoice.InvoiceState.Closed)
|
||||
{
|
||||
await _context.InvoiceItems
|
||||
.Where(x => x.IdInvoiceFk == Invoice.IdInvoice)
|
||||
.Include(invoiceItem => invoiceItem.ProjectPartItem).ForEachAsync(x =>
|
||||
{
|
||||
x.ProjectPartItem.Status = ProjectPartItemStatus.Finished;
|
||||
});
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
@@ -23,6 +23,9 @@
|
||||
case 3:
|
||||
<i>Naročila kupcev</i>
|
||||
break;
|
||||
case 4:
|
||||
<i>Kooperacije</i>
|
||||
break;
|
||||
default:
|
||||
<i>Fakture</i>
|
||||
break;
|
||||
@@ -127,7 +130,27 @@
|
||||
</table>
|
||||
|
||||
<div class="card-footer py-3 text-right">
|
||||
<a asp-page="Create" asp-route-type="@ViewData["Type"]" class="btn btn-primary">Vnos fakture</a>
|
||||
<a asp-page="Create" asp-route-type="@ViewData["Type"]" class="btn btn-primary">@switch (@ViewData["Type"])
|
||||
{
|
||||
case 1:
|
||||
<i>Vnos naročila dobaviteljem</i>
|
||||
break;
|
||||
case 0:
|
||||
<i>Vnos računa</i>
|
||||
break;
|
||||
case 2:
|
||||
<i>Vnos dobavnice</i>
|
||||
break;
|
||||
case 3:
|
||||
<i>Vnos naročila kupcev</i>
|
||||
break;
|
||||
case 4:
|
||||
<i>Vnos kooperacije</i>
|
||||
break;
|
||||
default:
|
||||
<i>Vnos fakture</i>
|
||||
break;
|
||||
}</a>
|
||||
</div>
|
||||
</div>
|
||||
@Html.AntiForgeryToken()
|
||||
|
||||
@@ -50,6 +50,9 @@
|
||||
case 3:
|
||||
<i>Naročila kupcev</i>
|
||||
break;
|
||||
case 4:
|
||||
<i>Kooperacija</i>
|
||||
break;
|
||||
default:
|
||||
<i>Fakture</i>
|
||||
break;
|
||||
|
||||
@@ -172,6 +172,9 @@ namespace EveryThing.Pages.Invoices
|
||||
case Invoice.InvoiceType.DeliveryNote:
|
||||
Translation.InvoiceType = "Dobavnica";
|
||||
break;
|
||||
case Invoice.InvoiceType.Cooperation:
|
||||
Translation.InvoiceType = "Kooperacija";
|
||||
break;
|
||||
default:
|
||||
Translation.InvoiceType = "Faktura";
|
||||
break;
|
||||
@@ -231,6 +234,9 @@ namespace EveryThing.Pages.Invoices
|
||||
case Invoice.InvoiceType.DeliveryNote:
|
||||
Translation.InvoiceType = "Lieferschein";
|
||||
break;
|
||||
case Invoice.InvoiceType.Cooperation:
|
||||
Translation.InvoiceType = "Zusammenarbeit";
|
||||
break;
|
||||
default:
|
||||
Translation.InvoiceType = "Faktura";
|
||||
break;
|
||||
|
||||
@@ -70,6 +70,9 @@
|
||||
<li class="sidenav-item@(currentPage.StartsWith("/Invoices/") && ViewData["Type"]?.ToString() == "2" ? " active" : "")">
|
||||
<a asp-page="/Invoices/Index" asp-route-type="2" class="sidenav-link"><i class="sidenav-icon fas fa-file"></i><div>Dobavnice </div></a>
|
||||
</li>
|
||||
<li class="sidenav-item@(currentPage.StartsWith("/Invoices/") && ViewData["Type"]?.ToString() == "4" ? " active" : "")">
|
||||
<a asp-page="/Invoices/Index" asp-route-type="4" class="sidenav-link"><i class="sidenav-icon fas fa-hands-helping"></i><div>Kooperacije </div></a>
|
||||
</li>
|
||||
}
|
||||
@*<li class="sidenav-item">
|
||||
<a asp-page="/Index" class="sidenav-link"><i class="sidenav-icon fas fa-ruler"></i><div>Planiranje</div></a>
|
||||
|
||||
@@ -164,6 +164,9 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" data-toggle="tab" href="#files-project-part">Datoteke del projekta</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" data-toggle="tab" href="#invoice-cooperatioins">Koop.</a>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="tab-content">
|
||||
<div class="tab-pane tab-panel-invoices fade show active" id="invoice-orders">
|
||||
@@ -464,36 +467,99 @@
|
||||
<div class="card-body" style="padding: 0.5rem">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Naziv
|
||||
</th>
|
||||
<th>
|
||||
Datum
|
||||
</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>
|
||||
Naziv
|
||||
</th>
|
||||
<th>
|
||||
Datum
|
||||
</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var file in Model.FilesProjectParts)
|
||||
{
|
||||
<tr class="invoice-row" data-idparts="@file.IdReferenceFk" data-idfile="@file.IdFile">
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => file.Title)
|
||||
</td>
|
||||
<td style="width: 180px">
|
||||
@Html.DisplayFor(x => file.DateOfUpload)
|
||||
</td>
|
||||
<td class="text-right" style="width: 80px">
|
||||
<a download href="@Url.Page("/Files/Upload", "DownloadFile", new { idFile = file.IdFile, idReferenceFk = file.IdReferenceFk, fileTypeInt = (int)file.FileType})" class="btn btn-xs icon-btn btn-outline-secondary borderless" data-toggle="tooltip" data-placement="top" title="Prenos" data-state="secondary"><i class="fas fa-download"></i></a>
|
||||
<a class="btn btn-xs icon-btn btn-outline-danger borderless" data-state="danger" href='javascript:;' onclick="deleteFile(this)"><i class="fas fa-times"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
@foreach (var file in Model.FilesProjectParts)
|
||||
{
|
||||
<tr class="invoice-row" data-idparts="@file.IdReferenceFk" data-idfile="@file.IdFile">
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => file.Title)
|
||||
</td>
|
||||
<td style="width: 180px">
|
||||
@Html.DisplayFor(x => file.DateOfUpload)
|
||||
</td>
|
||||
<td class="text-right" style="width: 80px">
|
||||
<a download href="@Url.Page("/Files/Upload", "DownloadFile", new { idFile = file.IdFile, idReferenceFk = file.IdReferenceFk, fileTypeInt = (int)file.FileType})" class="btn btn-xs icon-btn btn-outline-secondary borderless" data-toggle="tooltip" data-placement="top" title="Prenos" data-state="secondary"><i class="fas fa-download"></i></a>
|
||||
<a class="btn btn-xs icon-btn btn-outline-danger borderless" data-state="danger" href='javascript:;' onclick="deleteFile(this)"><i class="fas fa-times"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tab-pane tab-panel-invoices fade show" id="invoice-cooperatioins">
|
||||
<div class="card-body" style="padding: 0.5rem">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
#
|
||||
</th>
|
||||
<th>
|
||||
Partner
|
||||
</th>
|
||||
<th>
|
||||
Datum
|
||||
</th>
|
||||
<th>
|
||||
Datum odpreme
|
||||
</th>
|
||||
<th>
|
||||
Status
|
||||
</th>
|
||||
<th><a href="Javascript:;" class="btn btn-sm btn-primary" onclick="showAllInvoices();">Pokaži vse</a></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var invoice in Model.Invoices.Where(x => x.Type == Invoice.InvoiceType.Cooperation))
|
||||
{
|
||||
<tr class="invoice-row" data-idparts="@string.Join(",", invoice.InvoiceInvoiceItem.Select(x => x.ProjectPartItem.IdProjectPartFk))">
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => invoice.InvoiceYear) - @Html.DisplayFor(modelItem => invoice.InvoiceNumber)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(x => invoice.Partner.Title)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(x => invoice.Date)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(x => invoice.DateOfDispatch)
|
||||
</td>
|
||||
<td>
|
||||
@switch (invoice.State)
|
||||
{
|
||||
case Models.Invoice.Invoice.InvoiceState.Closed:
|
||||
<span class='badge badge-success'>@Html.DisplayFor(modelItem => invoice.State)</span>
|
||||
break;
|
||||
case Models.Invoice.Invoice.InvoiceState.Confirmed:
|
||||
<span class='badge badge-warning'>@Html.DisplayFor(modelItem => invoice.State)</span>
|
||||
break;
|
||||
default:
|
||||
<span class='badge badge-info'>@Html.DisplayFor(modelItem => invoice.State)</span>
|
||||
break;
|
||||
}
|
||||
</td>
|
||||
<td class="text-right">
|
||||
<a class="btn btn-xs icon-btn btn-outline-primary borderless" asp-page="/Invoices/Print" asp-route-id="@invoice.IdInvoice" data-toggle="tooltip" data-placement="top" title="Tiskanje" data-state="primary"><i class="ion ion-md-print"></i></a>
|
||||
<a class="btn btn-xs icon-btn btn-outline-secondary borderless" asp-page="/Invoices/Edit" asp-route-id="@invoice.IdInvoice" data-toggle="tooltip" data-placement="top" title="Urejanje" data-state="secondary"><i class="fas fa-pencil-alt"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -663,8 +729,9 @@
|
||||
<div class="card-footer py-3">
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<button class="btn btn-success" onclick="createOrder(false); return false;">Kreiraj naročilo</button>
|
||||
<button class="btn btn-success" onclick="createOrder(true); return false;">Kreiraj povpraševanje</button>
|
||||
<button class="btn btn-success" onclick="createOrderSelectPartner(false); return false;">Kreiraj naročilo</button>
|
||||
<button class="btn btn-success" onclick="createOrderSelectPartner(true); return false;">Kreiraj povpraševanje</button>
|
||||
<button class="btn btn-info" onclick="createCooperationSelectPartner(); return false;">Kreiraj kooperacijo</button>
|
||||
<button class="btn btn-primary" onclick="createInvoice(); return false;">Kreiraj dobavnico</button>
|
||||
|
||||
</div>
|
||||
@@ -778,8 +845,57 @@
|
||||
function tooltips() {
|
||||
$('[data-toggle="tooltip"]').tooltip();
|
||||
}
|
||||
function createOrderSelectPartner(inquiry) {
|
||||
$.blockUI();
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "/CodeTablePartners/Index/?handler=Partners",
|
||||
data: {
|
||||
suppliers: true
|
||||
},
|
||||
success: function (data) {
|
||||
$.unblockUI();
|
||||
if (data.successful) {
|
||||
console.log(data.jsonPartners);
|
||||
(async () => {
|
||||
|
||||
const { value: idPartner } = await Swal.fire({
|
||||
title: 'Izberi partnerja',
|
||||
input: 'select',
|
||||
inputOptions: JSON.parse(data.jsonPartners),
|
||||
inputPlaceholder: 'Samodejno',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Potrdi',
|
||||
cancelButtonText: 'Prekliči',
|
||||
inputValidator: (value) => {
|
||||
return new Promise((resolve) => {
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
createOrder(inquiry, idPartner);
|
||||
})();
|
||||
} else {
|
||||
console.log(data);
|
||||
Swal.fire('Napaka pri pridobivanju partnerjev',
|
||||
data.error,
|
||||
'error');
|
||||
}
|
||||
|
||||
},
|
||||
error: function (xhr, ajaxOptions, thrownError) {
|
||||
console.log(xhr);
|
||||
alert(xhr.responseText);
|
||||
$.unblockUI();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function createOrder(inquiry, idPartner) {
|
||||
if (idPartner == null || idPartner == undefined || isNaN(idPartner))
|
||||
idPartner = 0;
|
||||
|
||||
function createOrder(inquiry) {
|
||||
let object = getSelectedPartItems();
|
||||
|
||||
if (object.length <= 0) {
|
||||
@@ -794,7 +910,7 @@
|
||||
$('input:hidden[name="__RequestVerificationToken"]').val());
|
||||
},
|
||||
url: "Edit/?handler=CreateOrder",
|
||||
data: { itemsJson: JSON.stringify(object), inquiry: inquiry },
|
||||
data: { itemsJson: JSON.stringify(object), inquiry: inquiry, idPartner: idPartner },
|
||||
success: function(data) {
|
||||
if (data.successful) {
|
||||
if (inquiry) {
|
||||
@@ -814,6 +930,92 @@
|
||||
});
|
||||
}
|
||||
|
||||
function createCooperationSelectPartner() {
|
||||
$.blockUI();
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "/CodeTablePartners/Index/?handler=Partners",
|
||||
data: {
|
||||
suppliers: true
|
||||
},
|
||||
success: function (data) {
|
||||
$.unblockUI();
|
||||
if (data.successful) {
|
||||
console.log(data.jsonPartners);
|
||||
(async () => {
|
||||
|
||||
const { value: idPartner } = await Swal.fire({
|
||||
title: 'Izberi partnerja',
|
||||
input: 'select',
|
||||
inputOptions: JSON.parse(data.jsonPartners),
|
||||
inputPlaceholder: 'Izberi partnerja',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Potrdi',
|
||||
cancelButtonText: 'Prekliči',
|
||||
inputValidator: (value) => {
|
||||
return new Promise((resolve) => {
|
||||
if (value) {
|
||||
resolve();
|
||||
} else {
|
||||
resolve("Partner ni izbran!");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
if (idPartner) {
|
||||
createCooperation(idPartner);
|
||||
}
|
||||
|
||||
})();
|
||||
} else {
|
||||
console.log(data);
|
||||
Swal.fire('Napaka pri pridobivanju partnerjev',
|
||||
data.error,
|
||||
'error');
|
||||
}
|
||||
|
||||
},
|
||||
error: function (xhr, ajaxOptions, thrownError) {
|
||||
console.log(xhr);
|
||||
alert(xhr.responseText);
|
||||
$.unblockUI();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function createCooperation(idPartner) {
|
||||
if (idPartner == null || idPartner == undefined || isNaN(idPartner))
|
||||
idPartner = 0;
|
||||
|
||||
let object = getSelectedPartItems();
|
||||
|
||||
if (object.length <= 0) {
|
||||
alert("Izberi pozicije!");
|
||||
return;
|
||||
}
|
||||
$.blockUI();
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
beforeSend: function(xhr) {
|
||||
xhr.setRequestHeader("XSRF-TOKEN",
|
||||
$('input:hidden[name="__RequestVerificationToken"]').val());
|
||||
},
|
||||
url: "Edit/?handler=CreateCooperation",
|
||||
data: { itemsJson: JSON.stringify(object), idPartner: idPartner },
|
||||
success: function(data) {
|
||||
if (data.successful) {
|
||||
window.location.href = '/Invoices/Edit?id=' + data.idInvoice;
|
||||
} else {
|
||||
}
|
||||
|
||||
},
|
||||
error: function(xhr, ajaxOptions, thrownError) {
|
||||
alert(xhr.responseText);
|
||||
$.unblockUI();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function createInvoice() {
|
||||
let object = getSelectedPartItems();
|
||||
|
||||
|
||||
@@ -183,7 +183,7 @@ namespace EveryThing.Pages.Projects
|
||||
return Partial("DetailsPartItem", item);
|
||||
}
|
||||
|
||||
public IActionResult OnPostCreateOrder(string itemsJson, bool inquiry)
|
||||
public IActionResult OnPostCreateCooperation(string itemsJson, int idPartner)
|
||||
{
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
|
||||
@@ -197,6 +197,83 @@ namespace EveryThing.Pages.Projects
|
||||
var suppliers = _context.ProjectPartItems
|
||||
.Where(x => itemsId.Contains(x.IdProjectPartItem))
|
||||
.Select(x => x.IdMaterialSupplierFk).Distinct().ToList();
|
||||
|
||||
if (idPartner > 0) //vse na izbranega partnerja
|
||||
suppliers = new List<int?> { idPartner };
|
||||
|
||||
var idInvoice = -1;
|
||||
|
||||
foreach (var idSupplier in suppliers)
|
||||
{
|
||||
var invoice = _context.Invoices
|
||||
.Include(x => x.InvoiceInvoiceItem)
|
||||
.ThenInclude(x => x.ProjectPartItem)
|
||||
.ThenInclude(x => x.ProjectPart)
|
||||
.Where(x => x.State == Models.Invoice.Invoice.InvoiceState.New
|
||||
&& x.Type == Models.Invoice.Invoice.InvoiceType.Cooperation
|
||||
//Ce ze kateri item obstaja na dobavnici
|
||||
&& x.InvoiceInvoiceItem.Any(invoiceItem => items.Select(item => item.ProjectPart.IdProjectFk).Contains(invoiceItem.ProjectPartItem.ProjectPart.IdProjectFk)))
|
||||
.FirstOrDefault(x => x.IdPartnerFk == idSupplier);
|
||||
|
||||
|
||||
if (invoice == null)
|
||||
{
|
||||
//Create new invoice
|
||||
var newInvoice = new Models.Invoice.Invoice();
|
||||
Pages.Invoices.CreateModel.SetNewInvoice(user.IdCompanyFk, Models.Invoice.Invoice.InvoiceType.Cooperation, ref newInvoice, _context);
|
||||
newInvoice.IdPartnerFk = idSupplier;
|
||||
newInvoice.Date = DateTime.Now.Date;
|
||||
|
||||
_context.Invoices.Add(newInvoice);
|
||||
_context.SaveChanges();
|
||||
idInvoice = newInvoice.IdInvoice;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Add to existing invoice
|
||||
idInvoice = invoice.IdInvoice;
|
||||
}
|
||||
|
||||
foreach (var projectPartItem in items.Where(x => idPartner > 0 || //ce damo vse na izbranega partnerja
|
||||
x.IdMaterialSupplierFk == idSupplier))
|
||||
{
|
||||
var newInvoiceItem = new Models.Invoice.InvoiceItem
|
||||
{
|
||||
Discount = 0,
|
||||
IdInvoiceFk = idInvoice,
|
||||
IdProjectPartItem = projectPartItem.IdProjectPartItem,
|
||||
IdItemFk = projectPartItem.IdMaterialFk,
|
||||
ItemDescription = projectPartItem.MaterialDimensions,
|
||||
Note = "",
|
||||
Price = projectPartItem.MaterialPrice,
|
||||
Quantity = projectPartItem.NumberOfItems
|
||||
};
|
||||
_context.InvoiceItems.Add(newInvoiceItem);
|
||||
}
|
||||
_context.SaveChanges();
|
||||
}
|
||||
|
||||
return new JsonResult(new { error = "", successful = true, idInvoice });
|
||||
}
|
||||
|
||||
public IActionResult OnPostCreateOrder(string itemsJson, bool inquiry, int idPartner)
|
||||
{
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
|
||||
var itemsId = JsonSerializer.Deserialize<List<int>>(itemsJson);
|
||||
|
||||
var items = _context.ProjectPartItems
|
||||
.Include(x => x.ProjectPart)
|
||||
.ThenInclude(x => x.Project)
|
||||
.Where(x => itemsId.Contains(x.IdProjectPartItem)).ToList();
|
||||
|
||||
var suppliers = _context.ProjectPartItems
|
||||
.Where(x => itemsId.Contains(x.IdProjectPartItem))
|
||||
.Select(x => x.IdMaterialSupplierFk).Distinct().ToList();
|
||||
|
||||
if (idPartner > 0) //vse na izbranega partnerja
|
||||
suppliers = new List<int?> { idPartner };
|
||||
|
||||
var idInvoice = -1;
|
||||
|
||||
foreach (var idSupplier in suppliers)
|
||||
@@ -232,7 +309,8 @@ namespace EveryThing.Pages.Projects
|
||||
idInvoice = invoice.IdInvoice;
|
||||
}
|
||||
|
||||
foreach (var projectPartItem in items.Where(x => x.IdMaterialSupplierFk == idSupplier))
|
||||
foreach (var projectPartItem in items.Where(x => idPartner > 0 || //ce damo vse na izbranega partnerja
|
||||
x.IdMaterialSupplierFk == idSupplier))
|
||||
{
|
||||
var newInvoiceItem = new Models.Invoice.InvoiceItem
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user