Prvi commit
This commit is contained in:
54
EveryThing/Pages/Projects/Create.cshtml
Normal file
54
EveryThing/Pages/Projects/Create.cshtml
Normal file
@@ -0,0 +1,54 @@
|
||||
@page
|
||||
@model EveryThing.Pages.Projects.CreateModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Nov projekt";
|
||||
Layout = "~/Pages/Layouts/_Layout.cshtml";
|
||||
}
|
||||
|
||||
<form method="post">
|
||||
|
||||
<h4 class="d-flex justify-content-between align-items-center w-100 font-weight-bold py-1 mb-4">
|
||||
<span>
|
||||
<span class="text-muted font-weight-light">Projekt /</span> Nov
|
||||
</span>
|
||||
</h4>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<div class="card">
|
||||
<h6 class="card-header">
|
||||
Podatki projekta
|
||||
</h6>
|
||||
<div class="card-body">
|
||||
<div class="form-group">
|
||||
<label asp-for="Project.Title" class="form-label"></label>
|
||||
<input autocomplete="off" asp-for="Project.Title" class="form-control" />
|
||||
<span asp-validation-for="Project.Title" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Project.IdPartnerFk" class="control-label"></label>
|
||||
<select asp-for="Project.IdPartnerFk" class="form-control" asp-items="ViewBag.IdPartnerFk"></select>
|
||||
<span asp-validation-for="Project.IdPartnerFk" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Project.Description" class="form-label"></label>
|
||||
<input autocomplete="off" asp-for="Project.Description" class="form-control" />
|
||||
<span asp-validation-for="Project.Description" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer py-3 text-right">
|
||||
<button type="submit" class="btn btn-primary">Dodaj projekt</button>
|
||||
<a asp-page="Index" class="btn btn-default">Prekliči</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
||||
|
||||
</form>
|
||||
|
||||
@section Scripts {
|
||||
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
|
||||
}
|
||||
69
EveryThing/Pages/Projects/Create.cshtml.cs
Normal file
69
EveryThing/Pages/Projects/Create.cshtml.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using EveryThing.Data;
|
||||
using EveryThing.Models;
|
||||
using EveryThing.Models.Project;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
namespace EveryThing.Pages.Projects
|
||||
{
|
||||
[Authorize(Roles = "Administrator,ProjecThingUser")]
|
||||
public class CreateModel : PageModel
|
||||
{
|
||||
private readonly ApplicationDbContext _context;
|
||||
private readonly UserManager<IdentityApplicationUser> _userManager;
|
||||
private readonly SignInManager<IdentityApplicationUser> _loginManager;
|
||||
private readonly RoleManager<IdentityApplicationRole> _roleManager;
|
||||
|
||||
public CreateModel(ApplicationDbContext context, UserManager<IdentityApplicationUser> userManager, SignInManager<IdentityApplicationUser> loginManager, RoleManager<IdentityApplicationRole> roleManager)
|
||||
{
|
||||
_context = context;
|
||||
_userManager = userManager;
|
||||
_loginManager = loginManager;
|
||||
_roleManager = roleManager;
|
||||
}
|
||||
|
||||
public IActionResult OnGet()
|
||||
{
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
|
||||
ViewData["IdPartnerFk"] = new SelectList(_context.CodeTablePartners.Where(x => x.IdCompanyFk == user.IdCompanyFk && x.Active), "IdPartner", "Title");
|
||||
|
||||
return Page();
|
||||
}
|
||||
|
||||
[BindProperty]
|
||||
public Models.Project.Project Project { get; set; }
|
||||
|
||||
public async Task<IActionResult> OnPostAsync()
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return Page();
|
||||
}
|
||||
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
|
||||
Project.IdCompanyFk = user.IdCompanyFk;
|
||||
Project.Status = ProjectStatus.Opened;
|
||||
|
||||
Project.ProjectYear = DateTime.Now.Year;
|
||||
var items = _context.Projects
|
||||
.Where(x => x.IdCompanyFk == user.IdCompanyFk
|
||||
&& x.ProjectYear == Project.ProjectYear).ToList();
|
||||
|
||||
Project.ProjectNumber = items.Count <= 0 ? 1 : items.Max(x => x.ProjectNumber) + 1;
|
||||
|
||||
_context.Projects.Add(Project);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return RedirectToPage("./Edit", new { id = Project.IdProject });
|
||||
}
|
||||
}
|
||||
}
|
||||
250
EveryThing/Pages/Projects/CreateEditPartItem.cshtml
Normal file
250
EveryThing/Pages/Projects/CreateEditPartItem.cshtml
Normal file
@@ -0,0 +1,250 @@
|
||||
@page
|
||||
@using EveryThing.Models.Project
|
||||
@model EveryThing.Pages.Projects.CreateEditPartItemModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Nov del projekta";
|
||||
Layout = "~/Pages/Layouts/_Layout.cshtml";
|
||||
}
|
||||
<link rel="stylesheet" href="~/vendor/libs/select2/select2.css" asp-append-version="true" />
|
||||
|
||||
|
||||
<form method="post">
|
||||
|
||||
<h4 class="d-flex justify-content-between align-items-center w-100 font-weight-bold py-1 mb-4">
|
||||
<span>
|
||||
<span class="text-muted font-weight-light">Projekt /</span>
|
||||
@if ((bool)ViewData["Edit"])
|
||||
{
|
||||
<span> Urejanje pozicije dela projekta</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span> Nova pozicija dela projekta</span>
|
||||
}
|
||||
|
||||
</span>
|
||||
</h4>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<div class="card">
|
||||
<h6 class="card-header">
|
||||
Podatki pozicije
|
||||
@if ((bool)ViewData["Edit"])
|
||||
{
|
||||
<i>@Model.ProjectPartItem.ProjectPartNumberFormatted</i>
|
||||
}
|
||||
</h6>
|
||||
<div class="card-body">
|
||||
<input type="hidden" asp-for="ProjectPartItem.IdProjectPartFk" />
|
||||
<input type="hidden" asp-for="IdProject" />
|
||||
<input type="hidden" asp-for="ProjectPartItem.IdProjectPartItem" />
|
||||
<input type="hidden" asp-for="ProjectPartItem.ProjectPartItemNumber" />
|
||||
<input type="hidden" asp-for="@ViewData["Edit"]" name="edit" />
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="form-group">
|
||||
<label asp-for="ProjectPartItem.IdItemFk" class="form-label"></label>
|
||||
<div class="form-row">
|
||||
<div class="col-12">
|
||||
<select id="selCodeTableItem" asp-for="ProjectPartItem.IdItemFk" class="form-control select2" asp-items="ViewBag.IdItemFk"></select>
|
||||
<button class="btn btn-success" type="button" onclick="copyDataFromLastPartItem();">Napolni prejšnje</button>
|
||||
<button class="btn btn-primary" type="button" onclick="addNewCodeTableItem();">Novi artikel</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<div class="form-group">
|
||||
<label asp-for="ProjectPartItem.NumberOfItems" class="form-label"></label>
|
||||
<input asp-for="ProjectPartItem.NumberOfItems" class="form-control" />
|
||||
<span asp-validation-for="ProjectPartItem.NumberOfItems" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<div class="form-group">
|
||||
<label asp-for="ProjectPartItem.NumberOfSets" class="form-label"></label>
|
||||
<input asp-for="ProjectPartItem.NumberOfSets" class="form-control" />
|
||||
<span asp-validation-for="ProjectPartItem.NumberOfSets" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="form-group">
|
||||
<label asp-for="ProjectPartItem.IdMaterialFk" class="form-label"></label>
|
||||
<div class="form-row">
|
||||
<div class="col-9">
|
||||
<select id="selCodeTableItemMaterial" asp-for="ProjectPartItem.IdMaterialFk" class="form-control select2" asp-items="ViewBag.IdMaterialFk"></select>
|
||||
</div>
|
||||
<div class="col-3">
|
||||
<button class="btn btn-primary" type="button" onclick="addNewCodeTableItemMaterial();">Novi material</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="form-group">
|
||||
<label asp-for="ProjectPartItem.MaterialDimensions" class="form-label"></label>
|
||||
<input asp-for="ProjectPartItem.MaterialDimensions" class="form-control" />
|
||||
<span asp-validation-for="ProjectPartItem.MaterialDimensions" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="form-group">
|
||||
<label asp-for="ProjectPartItem.IdMaterialSupplierFk" class="form-label"></label>
|
||||
<select asp-for="ProjectPartItem.IdMaterialSupplierFk" class="form-control select2" asp-items="ViewBag.IdMaterialSupplierFk"></select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<div class="form-group">
|
||||
<label asp-for="ProjectPartItem.MaterialPrice" class="form-label"></label>
|
||||
<input asp-for="ProjectPartItem.MaterialPrice" class="form-control" />
|
||||
<span asp-validation-for="ProjectPartItem.MaterialPrice" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<div class="form-group">
|
||||
<label asp-for="ProjectPartItem.WorkPrice" class="form-label"></label>
|
||||
<input asp-for="ProjectPartItem.WorkPrice" class="form-control" />
|
||||
<span asp-validation-for="ProjectPartItem.WorkPrice" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<div class="form-group">
|
||||
<label asp-for="ProjectPartItem.SellingPrice" class="form-label"></label>
|
||||
<input asp-for="ProjectPartItem.SellingPrice" class="form-control" />
|
||||
<span asp-validation-for="ProjectPartItem.SellingPrice" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<div class="form-group">
|
||||
<label asp-for="ProjectPartItem.DeliveryDate" class="form-label"></label>
|
||||
@Html.TextBoxFor(m => m.ProjectPartItem.DeliveryDate, "{0:yyyy-MM-dd}", new { @class = "form-control", type = "date" })
|
||||
<span asp-validation-for="ProjectPartItem.DeliveryDate" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<div class="form-group">
|
||||
<label asp-for="ProjectPartItem.Status" class="form-label"></label>
|
||||
<select asp-for="ProjectPartItem.Status" asp-items="Html.GetEnumSelectList<ProjectPartItemStatus>()" class="form-control">
|
||||
<option>Izberite status</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<div class="form-group">
|
||||
<label asp-for="ProjectPartItem.ShippingDate" class="form-label"></label>
|
||||
@Html.TextBoxFor(m => m.ProjectPartItem.ShippingDate, "{0:yyyy-MM-dd}", new { @class = "form-control", type = "date" })
|
||||
<span asp-validation-for="ProjectPartItem.ShippingDate" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer py-3 text-right">
|
||||
@if (ViewData["Edit"] != null && (bool)ViewData["Edit"])
|
||||
{
|
||||
<button type="submit" class="btn btn-primary">Shrani</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<button type="submit" class="btn btn-primary">Dodaj del projekta</button>
|
||||
}
|
||||
|
||||
<a asp-page="Edit" asp-route-id="@ViewBag.IdProject" class="btn btn-default">Prekliči</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
||||
<div id="divModalCodetableItemAddEditPlaceholder"></div>
|
||||
@Html.AntiForgeryToken()
|
||||
</form>
|
||||
|
||||
@section Scripts {
|
||||
@{
|
||||
await Html.RenderPartialAsync("_ValidationScriptsPartial");
|
||||
}
|
||||
<script src="~/js/codeTableItemHelper.js?v=3" asp-append-version="true"></script>
|
||||
<script src="~/vendor/libs/select2/select2.js" asp-append-version="true"></script>
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('[data-toggle="tooltip"]').tooltip({ container: 'table' });
|
||||
$('.select2').select2();
|
||||
});
|
||||
|
||||
function addNewCodeTableItem() {
|
||||
codeTableItemAddEdit('#divModalCodetableItemAddEditPlaceholder',
|
||||
false,
|
||||
null,
|
||||
(idCodeTableItem) => {
|
||||
refreshCodeTableItems('#selCodeTableItem', idCodeTableItem, 0);
|
||||
});
|
||||
}
|
||||
|
||||
function addNewCodeTableItemMaterial() {
|
||||
codeTableItemAddEdit('#divModalCodetableItemAddEditPlaceholder',
|
||||
false,
|
||||
null,
|
||||
(idCodeTableItem) => {
|
||||
refreshCodeTableItems('#selCodeTableItemMaterial', idCodeTableItem, 1);
|
||||
},
|
||||
null,
|
||||
1);
|
||||
}
|
||||
|
||||
function refreshCodeTableItems(selector, idToSelect, type) {
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "CreateEditPartItem/?handler=CodeTableItems",
|
||||
data: {
|
||||
type
|
||||
},
|
||||
success: function(data) {
|
||||
console.log(data);
|
||||
$(selector).empty();
|
||||
$(data.items).each(function() {
|
||||
$(selector).append($("<option></option>").val(this.value).html(this.text));
|
||||
});
|
||||
$(selector).val(idToSelect).trigger('change');
|
||||
},
|
||||
error: function(xhr, ajaxOptions, thrownError) {
|
||||
console.log(xhr);
|
||||
alert(xhr.responseText);
|
||||
$.unblockUI();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function copyDataFromLastPartItem() {
|
||||
let params = new URLSearchParams(window.location.search);
|
||||
let idProjectPartItem = params.get('idProjectPartItem');
|
||||
let idProject = params.get('idProject');
|
||||
let idProjectPart = params.get('idProjectPart');
|
||||
let edit = params.get('edit');
|
||||
|
||||
let idArticle = $('#selCodeTableItem').val();
|
||||
if (isNaN(parseInt(idArticle))) {
|
||||
return;
|
||||
}
|
||||
|
||||
location.replace(`CreateEditPartItem?idProjectPartItem=${idProjectPartItem}&idProject=${idProject}&idProjectPart=${idProjectPart}&edit=${edit}&idArticleCopyFrom=${idArticle}`);
|
||||
}
|
||||
|
||||
</script>
|
||||
}
|
||||
162
EveryThing/Pages/Projects/CreateEditPartItem.cshtml.cs
Normal file
162
EveryThing/Pages/Projects/CreateEditPartItem.cshtml.cs
Normal file
@@ -0,0 +1,162 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using EveryThing.Data;
|
||||
using EveryThing.Models;
|
||||
using EveryThing.Models.CodeTable;
|
||||
using EveryThing.Models.Project;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace EveryThing.Pages.Projects
|
||||
{
|
||||
[Authorize(Roles = "Administrator,ProjecThingUser")]
|
||||
public class CreateEditPartItemModel : PageModel
|
||||
{
|
||||
private readonly ApplicationDbContext _context;
|
||||
private readonly UserManager<IdentityApplicationUser> _userManager;
|
||||
private readonly SignInManager<IdentityApplicationUser> _loginManager;
|
||||
private readonly RoleManager<IdentityApplicationRole> _roleManager;
|
||||
|
||||
public CreateEditPartItemModel(ApplicationDbContext context, UserManager<IdentityApplicationUser> userManager, SignInManager<IdentityApplicationUser> loginManager, RoleManager<IdentityApplicationRole> roleManager)
|
||||
{
|
||||
_context = context;
|
||||
_userManager = userManager;
|
||||
_loginManager = loginManager;
|
||||
_roleManager = roleManager;
|
||||
}
|
||||
|
||||
public IActionResult OnGet(int idProject, int idProjectPart, bool edit, int? idProjectPartItem, int? idArticleCopyFrom)
|
||||
{
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
|
||||
IdProject = idProject;
|
||||
ViewData["IdProject"] = idProject;
|
||||
ViewData["IdItemFk"] = new SelectList(_context.CodeTableItems
|
||||
.Where(x => x.IdCompanyFk == user.IdCompanyFk && x.Active && x.CodeTableItemType == CodeTableItemType.Product)
|
||||
.OrderBy(x => x.Title), "IdItem", "Title");
|
||||
ViewData["IdMaterialFk"] = new SelectList(_context.CodeTableItems
|
||||
.Where(x => x.IdCompanyFk == user.IdCompanyFk && x.Active && x.CodeTableItemType == CodeTableItemType.Material)
|
||||
.OrderBy(x => x.Title), "IdItem", "Title");
|
||||
ViewData["IdMaterialSupplierFk"] = new SelectList(_context.CodeTablePartners
|
||||
.Where(x => x.IdCompanyFk == user.IdCompanyFk && x.Active && x.Supplier)
|
||||
.OrderBy(x => x.Title), "IdPartner", "Title");
|
||||
|
||||
ViewData["Edit"] = edit;
|
||||
|
||||
if (edit)
|
||||
{
|
||||
ProjectPartItem = _context.ProjectPartItems
|
||||
.Include(x => x.ProjectPart)
|
||||
.ThenInclude(x => x.Project)
|
||||
.FirstOrDefault(x => x.IdProjectPartItem == idProjectPartItem);
|
||||
|
||||
if (ProjectPartItem == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ProjectPartItem = new ProjectPartItem
|
||||
{
|
||||
NumberOfSets = 1,
|
||||
IdProjectPartFk = idProjectPart
|
||||
};
|
||||
}
|
||||
|
||||
if (idArticleCopyFrom != null)
|
||||
{
|
||||
var item = _context.ProjectPartItems
|
||||
.OrderByDescending(x => x.DateModified)
|
||||
.ThenByDescending(x => x.IdProjectPartItem)
|
||||
.FirstOrDefault(x => x.IdItemFk == idArticleCopyFrom && (!edit || x.IdProjectPartFk != ProjectPartItem.IdProjectPartFk));
|
||||
|
||||
if (item != null)
|
||||
{
|
||||
ProjectPartItem.IdItemFk = item.IdItemFk;
|
||||
ProjectPartItem.NumberOfItems = item.NumberOfItems;
|
||||
ProjectPartItem.NumberOfSets = item.NumberOfSets;
|
||||
ProjectPartItem.IdMaterialFk = item.IdMaterialFk;
|
||||
ProjectPartItem.MaterialDimensions = item.MaterialDimensions;
|
||||
ProjectPartItem.IdMaterialSupplierFk = item.IdMaterialSupplierFk;
|
||||
ProjectPartItem.MaterialPrice = item.MaterialPrice;
|
||||
ProjectPartItem.WorkPrice = item.WorkPrice;
|
||||
ProjectPartItem.SellingPrice = item.SellingPrice;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return Page();
|
||||
}
|
||||
|
||||
[BindProperty]
|
||||
public Models.Project.ProjectPartItem ProjectPartItem { get; set; }
|
||||
|
||||
[BindProperty]
|
||||
public int IdProject { get; set; }
|
||||
|
||||
public async Task<IActionResult> OnPostAsync(bool edit)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return Page();
|
||||
}
|
||||
ProjectPartItem.DateModified = DateTime.Now;
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
if (!edit)
|
||||
{
|
||||
ProjectPartItem.Status = ProjectPartItemStatus.Opened;
|
||||
|
||||
var items = _context.ProjectPartItems
|
||||
.Where(x => x.IdProjectPartFk == ProjectPartItem.IdProjectPartFk).ToList();
|
||||
|
||||
ProjectPartItem.ProjectPartItemNumber = items.Count <= 0 ? 1 : items.Max(x => x.ProjectPartItemNumber) + 1;
|
||||
_context.ProjectPartItems.Add(ProjectPartItem);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
_context.Attach(ProjectPartItem).State = EntityState.Modified;
|
||||
|
||||
try
|
||||
{
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
if (!ProjectPartItemExists(ProjectPartItem.IdProjectPartItem))
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return RedirectToPage("./Edit", new { id = IdProject });
|
||||
}
|
||||
|
||||
private bool ProjectPartItemExists(int id)
|
||||
{
|
||||
return _context.ProjectPartItems.Any(e => e.IdProjectPartItem == id);
|
||||
}
|
||||
|
||||
public IActionResult OnGetCodeTableItems(int type)
|
||||
{
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
var codeTableItemType = (CodeTableItemType)type;
|
||||
|
||||
var items = new SelectList(_context.CodeTableItems
|
||||
.Where(x => x.IdCompanyFk == user.IdCompanyFk && x.Active && x.CodeTableItemType == codeTableItemType)
|
||||
.OrderBy(x => x.Title), "IdItem", "Title");
|
||||
|
||||
return new JsonResult(new { items = items });
|
||||
}
|
||||
}
|
||||
}
|
||||
55
EveryThing/Pages/Projects/CreatePart.cshtml
Normal file
55
EveryThing/Pages/Projects/CreatePart.cshtml
Normal file
@@ -0,0 +1,55 @@
|
||||
@page
|
||||
@model EveryThing.Pages.Projects.CreatePartModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Nov del projekta";
|
||||
Layout = "~/Pages/Layouts/_Layout.cshtml";
|
||||
}
|
||||
|
||||
<form method="post">
|
||||
|
||||
<h4 class="d-flex justify-content-between align-items-center w-100 font-weight-bold py-1 mb-4">
|
||||
<span>
|
||||
<span class="text-muted font-weight-light">Projekt /</span> Nov del
|
||||
</span>
|
||||
</h4>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<div class="card">
|
||||
<h6 class="card-header">
|
||||
Podatki dela projekta
|
||||
</h6>
|
||||
<div class="card-body">
|
||||
<input type="hidden" asp-for="ProjectPart.IdProjectFk" />
|
||||
<div class="form-group">
|
||||
<label asp-for="ProjectPart.Title" class="form-label"></label>
|
||||
<input autocomplete="off" asp-for="ProjectPart.Title" class="form-control"/>
|
||||
<span asp-validation-for="ProjectPart.Title" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="ProjectPart.Description" class="form-label"></label>
|
||||
<input autocomplete="off" asp-for="ProjectPart.Description" class="form-control"/>
|
||||
<span asp-validation-for="ProjectPart.Description" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="ProjectPart.PathOfPlans" class="form-label"></label>
|
||||
<input autocomplete="off" asp-for="ProjectPart.PathOfPlans" class="form-control"/>
|
||||
<span asp-validation-for="ProjectPart.PathOfPlans" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer py-3 text-right">
|
||||
<button type="submit" class="btn btn-primary">Dodaj del projekta</button>
|
||||
<a asp-page="Edit" asp-route-id="@ViewBag.IdProject" class="btn btn-default">Prekliči</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
||||
|
||||
</form>
|
||||
|
||||
@section Scripts {
|
||||
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
|
||||
}
|
||||
69
EveryThing/Pages/Projects/CreatePart.cshtml.cs
Normal file
69
EveryThing/Pages/Projects/CreatePart.cshtml.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using EveryThing.Data;
|
||||
using EveryThing.Models;
|
||||
using EveryThing.Models.Project;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
namespace EveryThing.Pages.Projects
|
||||
{
|
||||
[Authorize(Roles = "Administrator,ProjecThingUser")]
|
||||
public class CreatePartModel : PageModel
|
||||
{
|
||||
private readonly ApplicationDbContext _context;
|
||||
private readonly UserManager<IdentityApplicationUser> _userManager;
|
||||
private readonly SignInManager<IdentityApplicationUser> _loginManager;
|
||||
private readonly RoleManager<IdentityApplicationRole> _roleManager;
|
||||
|
||||
public CreatePartModel(ApplicationDbContext context, UserManager<IdentityApplicationUser> userManager, SignInManager<IdentityApplicationUser> loginManager, RoleManager<IdentityApplicationRole> roleManager)
|
||||
{
|
||||
_context = context;
|
||||
_userManager = userManager;
|
||||
_loginManager = loginManager;
|
||||
_roleManager = roleManager;
|
||||
}
|
||||
|
||||
public IActionResult OnGet(int idProject)
|
||||
{
|
||||
ViewData["IdProject"] = idProject;
|
||||
|
||||
ProjectPart = new ProjectPart
|
||||
{
|
||||
IdProjectFk = idProject
|
||||
};
|
||||
|
||||
return Page();
|
||||
}
|
||||
|
||||
[BindProperty]
|
||||
public Models.Project.ProjectPart ProjectPart { get; set; }
|
||||
|
||||
public async Task<IActionResult> OnPostAsync()
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return Page();
|
||||
}
|
||||
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
|
||||
ProjectPart.Status = ProjectPartStatus.Opened;
|
||||
|
||||
var items = _context.ProjectParts
|
||||
.Where(x => x.IdProjectFk == ProjectPart.IdProjectFk).ToList();
|
||||
|
||||
ProjectPart.ProjectPartNumber = items.Count <= 0 ? 1 : items.Max(x => x.ProjectPartNumber) + 1;
|
||||
|
||||
_context.ProjectParts.Add(ProjectPart);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return RedirectToPage("./Edit", new { id = ProjectPart.IdProjectFk });
|
||||
}
|
||||
}
|
||||
}
|
||||
71
EveryThing/Pages/Projects/CreatePartItemImportExcel.cshtml
Normal file
71
EveryThing/Pages/Projects/CreatePartItemImportExcel.cshtml
Normal file
@@ -0,0 +1,71 @@
|
||||
@page
|
||||
@using EveryThing.Models.Project
|
||||
@model EveryThing.Pages.Projects.CreatePartItemImportExcelModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Uvoz pozicij dela projekta";
|
||||
Layout = "~/Pages/Layouts/_Layout.cshtml";
|
||||
}
|
||||
|
||||
<form method="post">
|
||||
|
||||
<h4 class="d-flex justify-content-between align-items-center w-100 font-weight-bold py-1 mb-4">
|
||||
<span>
|
||||
<span class="text-muted font-weight-light">Projekt /</span> Uvoz pozicij dela projekta
|
||||
</span>
|
||||
</h4>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<div class="card">
|
||||
<h6 class="card-header">
|
||||
Povezovanje excel z pozicijo
|
||||
</h6>
|
||||
<div class="card-body">
|
||||
<input type="hidden" asp-for="IdProjectPart" />
|
||||
<input type="hidden" asp-for="IdProject" />
|
||||
<input type="hidden" asp-for="FileName" />
|
||||
<input type="hidden" asp-for="SelectedItems" name="selectedItems" class="inp-selected-items" />
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
@{
|
||||
foreach (var item in Model.ExcelItems)
|
||||
{
|
||||
<div class="form-group">
|
||||
<label class="control-label">@item.Name</label>
|
||||
<select data-index="@item.CellIndex" class="form-control select-item" asp-items="ViewBag.ProjectPartItems"></select>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer py-3 text-right">
|
||||
<button type="submit" class="btn btn-primary" onclick="prepareData(); return true;">Potrdi</button>
|
||||
<a asp-page="Edit" asp-route-id="IdProject" class="btn btn-default">Prekliči</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
||||
|
||||
</form>
|
||||
|
||||
@section Scripts {
|
||||
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
|
||||
|
||||
<script type="text/javascript">
|
||||
function prepareData(){
|
||||
let data = "";
|
||||
$('.select-item').each(function(index, element) {
|
||||
let value = $(element).val();
|
||||
if (value !== '') {
|
||||
let dataIndex = $(element).attr("data-index");
|
||||
data += `${dataIndex};${value}#`;
|
||||
}
|
||||
});
|
||||
$('.inp-selected-items').val(data);
|
||||
}
|
||||
</script>
|
||||
}
|
||||
199
EveryThing/Pages/Projects/CreatePartItemImportExcel.cshtml.cs
Normal file
199
EveryThing/Pages/Projects/CreatePartItemImportExcel.cshtml.cs
Normal file
@@ -0,0 +1,199 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using EveryThing.Data;
|
||||
using EveryThing.Models;
|
||||
using EveryThing.Models.Project;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.IO;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using ClosedXML.Excel;
|
||||
|
||||
namespace EveryThing.Pages.Projects
|
||||
{
|
||||
[Authorize(Roles = "Administrator,ProjecThingUser")]
|
||||
public class CreatePartItemImportExcelModel : PageModel
|
||||
{
|
||||
private readonly IWebHostEnvironment _hostingEnvironment;
|
||||
private readonly ApplicationDbContext _context;
|
||||
private readonly UserManager<IdentityApplicationUser> _userManager;
|
||||
private readonly SignInManager<IdentityApplicationUser> _loginManager;
|
||||
private readonly RoleManager<IdentityApplicationRole> _roleManager;
|
||||
|
||||
public CreatePartItemImportExcelModel(ApplicationDbContext context, UserManager<IdentityApplicationUser> userManager, SignInManager<IdentityApplicationUser> loginManager, RoleManager<IdentityApplicationRole> roleManager, IWebHostEnvironment environment)
|
||||
{
|
||||
_context = context;
|
||||
_userManager = userManager;
|
||||
_loginManager = loginManager;
|
||||
_roleManager = roleManager;
|
||||
_hostingEnvironment = environment;
|
||||
}
|
||||
|
||||
[BindProperty]
|
||||
public int IdProject { get; set; }
|
||||
[BindProperty]
|
||||
public int IdProjectPart { get; set; }
|
||||
[BindProperty]
|
||||
public string FileName { get; set; }
|
||||
[BindProperty]
|
||||
public List<ExcelItem> ExcelItems { get; set; }
|
||||
[BindProperty]
|
||||
public string SelectedItems { get; set; }
|
||||
|
||||
public IActionResult OnGet(int idProject, int idProjectPart, string fileName)
|
||||
{
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
|
||||
IdProject = idProject;
|
||||
IdProjectPart = idProjectPart;
|
||||
FileName = fileName;
|
||||
|
||||
var tmpList = typeof(Models.Project.ProjectPartItem).GetProperties()
|
||||
.Where(x => x.GetCustomAttributes(true).Length > 0 && x.GetCustomAttributes(true).Any(y => y.GetType() == typeof(System.ComponentModel.DataAnnotations.DisplayAttribute)))
|
||||
.Select(x => new
|
||||
{
|
||||
Name = x.Name,
|
||||
Display = ((System.ComponentModel.DataAnnotations.DisplayAttribute)x.GetCustomAttributes(true).First(y => y.GetType() == typeof(System.ComponentModel.DataAnnotations.DisplayAttribute))).Name
|
||||
}).ToList();
|
||||
tmpList.Insert(0, new { Name = "", Display = "Ni izbrano" });
|
||||
|
||||
ViewData["ProjectPartItems"] = new SelectList(tmpList, "Name", "Display");
|
||||
|
||||
ExcelItems = new List<ExcelItem>();
|
||||
string path = Path.Combine(_hostingEnvironment.WebRootPath, "Uploads");
|
||||
|
||||
var xlWorkbook = new XLWorkbook(Path.Combine(path, fileName));
|
||||
|
||||
//ONLY FIRST LIST
|
||||
var worksheet = xlWorkbook.Worksheet(1);
|
||||
|
||||
int i = 1;
|
||||
if (!worksheet.Row(i).IsEmpty())
|
||||
{
|
||||
IXLRow row = worksheet.Row(i);
|
||||
int j = 1;
|
||||
while (!row.Cell(j).IsEmpty())
|
||||
{
|
||||
var cellData = row.Cell(j).Value;
|
||||
|
||||
ExcelItems.Add(new ExcelItem
|
||||
{
|
||||
CellIndex = j,
|
||||
Name = cellData.ToString(),
|
||||
});
|
||||
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
return Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostAsync(string selectedItems)
|
||||
{
|
||||
if (selectedItems == "")
|
||||
{
|
||||
return Page(); //TODO Error
|
||||
}
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
|
||||
var excelItems = new List<ExcelItem>();
|
||||
|
||||
var items = selectedItems.Split('#');
|
||||
foreach (var item in items)
|
||||
{
|
||||
var itemData = item.Split(';');
|
||||
if (itemData.Length != 2)
|
||||
continue;
|
||||
|
||||
excelItems.Add(new ExcelItem
|
||||
{
|
||||
CellIndex = Convert.ToInt32(itemData[0]),
|
||||
Name = itemData[1],
|
||||
});
|
||||
}
|
||||
|
||||
string path = Path.Combine(_hostingEnvironment.WebRootPath, "Uploads");
|
||||
|
||||
var xlWorkbook = new XLWorkbook(Path.Combine(path, FileName));
|
||||
|
||||
//ONLY FIRST LIST
|
||||
var worksheet = xlWorkbook.Worksheet(1);
|
||||
|
||||
var currentPositionNumber = _context.ProjectPartItems
|
||||
.Where(x => x.IdProjectPartFk == IdProjectPart).Max(x => x.ProjectPartItemNumber);
|
||||
|
||||
if (currentPositionNumber <= 0)
|
||||
currentPositionNumber = 0;
|
||||
|
||||
int i = 2;//Skip header
|
||||
while (!worksheet.Row(i).IsEmpty())
|
||||
{
|
||||
currentPositionNumber++;
|
||||
IXLRow row = worksheet.Row(i);
|
||||
var newPosition = new Models.Project.ProjectPartItem
|
||||
{
|
||||
IdProjectPartFk = IdProjectPart,
|
||||
NumberOfItems = 1,
|
||||
NumberOfSets = 1,
|
||||
IdMaterialSupplierFk = _context.CodeTablePartners.First().IdPartner,
|
||||
ProjectPartItemNumber = currentPositionNumber
|
||||
};
|
||||
|
||||
foreach (var excelItem in excelItems)
|
||||
{
|
||||
if (row.Cell(excelItem.CellIndex) == null)
|
||||
continue;
|
||||
|
||||
string value = row.Cell(excelItem.CellIndex).Value.ToString();
|
||||
|
||||
if (excelItem.Name == "IdItemFk"
|
||||
|| excelItem.Name == "IdMaterialFk")
|
||||
{
|
||||
var completableItem = _context.CodeTableItems.FirstOrDefault(x => x.Title == value && x.Active == true);
|
||||
if (completableItem == null)
|
||||
{
|
||||
//Add new if not exists
|
||||
completableItem = new Models.CodeTable.CodeTableItem
|
||||
{
|
||||
Active = true,
|
||||
IdCompanyFk = user.IdCompanyFk,
|
||||
Title = value
|
||||
};
|
||||
_context.CodeTableItems.Add(completableItem);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
if (excelItem.Name == "IdItemFk")
|
||||
newPosition.IdItemFk = completableItem.IdItem;
|
||||
else
|
||||
newPosition.IdMaterialFk = completableItem.IdItem;
|
||||
}
|
||||
else
|
||||
{
|
||||
var propertyInfo = newPosition.GetType().GetProperties().First(x => x.Name == excelItem.Name);
|
||||
object propertyValue = Convert.ChangeType(value, Nullable.GetUnderlyingType(propertyInfo.PropertyType) ?? propertyInfo.PropertyType);
|
||||
propertyInfo.SetValue(newPosition, propertyValue);
|
||||
}
|
||||
}
|
||||
_context.ProjectPartItems.Add(newPosition);
|
||||
await _context.SaveChangesAsync();
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
return RedirectToPage("./Edit", new {id = IdProject});
|
||||
}
|
||||
|
||||
public class ExcelItem
|
||||
{
|
||||
public int CellIndex { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
50
EveryThing/Pages/Projects/CreatePartItemUploadExcel.cshtml
Normal file
50
EveryThing/Pages/Projects/CreatePartItemUploadExcel.cshtml
Normal file
@@ -0,0 +1,50 @@
|
||||
@page
|
||||
@using EveryThing.Models.Project
|
||||
@model EveryThing.Pages.Projects.CreatePartItemUploadExcelModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Uvoz pozicij dela projekta";
|
||||
Layout = "~/Pages/Layouts/_Layout.cshtml";
|
||||
}
|
||||
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
|
||||
<h4 class="d-flex justify-content-between align-items-center w-100 font-weight-bold py-1 mb-4">
|
||||
<span>
|
||||
<span class="text-muted font-weight-light">Projekt /</span> Uvoz pozicij dela projekta
|
||||
</span>
|
||||
</h4>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<div class="card">
|
||||
<h6 class="card-header">
|
||||
Podatki pozicije
|
||||
</h6>
|
||||
<div class="card-body">
|
||||
<input type="hidden" asp-for="IdProjectPart" name="idProjectPart" />
|
||||
<input type="hidden" asp-for="IdProject" name="idProject"/>
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="form-group">
|
||||
<input type="file" name="postedFiles" multiple/>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer py-3 text-right">
|
||||
<input type="submit" class="btn btn-primary" value="Naloži excel" asp-page-handler="Upload" />
|
||||
<a asp-page="Edit" asp-route-id="IdProject" class="btn btn-default">Prekliči</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
||||
|
||||
</form>
|
||||
|
||||
@section Scripts {
|
||||
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
|
||||
}
|
||||
126
EveryThing/Pages/Projects/CreatePartItemUploadExcel.cshtml.cs
Normal file
126
EveryThing/Pages/Projects/CreatePartItemUploadExcel.cshtml.cs
Normal file
@@ -0,0 +1,126 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using EveryThing.Data;
|
||||
using EveryThing.Models;
|
||||
using EveryThing.Models.Project;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.IO;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
|
||||
namespace EveryThing.Pages.Projects
|
||||
{
|
||||
[Authorize(Roles = "Administrator,ProjecThingUser")]
|
||||
public class CreatePartItemUploadExcelModel : PageModel
|
||||
{
|
||||
private readonly IWebHostEnvironment _hostingEnvironment;
|
||||
private readonly ApplicationDbContext _context;
|
||||
private readonly UserManager<IdentityApplicationUser> _userManager;
|
||||
private readonly SignInManager<IdentityApplicationUser> _loginManager;
|
||||
private readonly RoleManager<IdentityApplicationRole> _roleManager;
|
||||
|
||||
public CreatePartItemUploadExcelModel(ApplicationDbContext context, UserManager<IdentityApplicationUser> userManager, SignInManager<IdentityApplicationUser> loginManager, RoleManager<IdentityApplicationRole> roleManager, IWebHostEnvironment environment)
|
||||
{
|
||||
_context = context;
|
||||
_userManager = userManager;
|
||||
_loginManager = loginManager;
|
||||
_roleManager = roleManager;
|
||||
_hostingEnvironment = environment;
|
||||
}
|
||||
|
||||
|
||||
[BindProperty]
|
||||
public IFormFile File { get; set; }
|
||||
[BindProperty]
|
||||
public int IdProject { get; set; }
|
||||
[BindProperty]
|
||||
public int IdProjectPart { get; set; }
|
||||
|
||||
|
||||
public IActionResult OnGet(int idProject, int idProjectPart)
|
||||
{
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
|
||||
IdProject = idProject;
|
||||
IdProjectPart = idProjectPart;
|
||||
|
||||
|
||||
return Page();
|
||||
}
|
||||
|
||||
//public async Task<IActionResult> OnPostAsync()
|
||||
//{
|
||||
// if (!ModelState.IsValid)
|
||||
// {
|
||||
// return Page();
|
||||
// }
|
||||
// string uploads = Path.Combine(_hostingEnvironment.WebRootPath, "uploads");
|
||||
|
||||
// if (File.Length > 0)
|
||||
// {
|
||||
// string filePath = Path.Combine(uploads, File.FileName);
|
||||
// using (Stream fileStream = new FileStream(filePath, FileMode.Create))
|
||||
// {
|
||||
// await File.CopyToAsync(fileStream);
|
||||
// }
|
||||
// }
|
||||
|
||||
// return RedirectToPage("./Edit");
|
||||
//}
|
||||
|
||||
//public async Task<IActionResult> OnPostUploadAsync(List<IFormFile> files)
|
||||
//{
|
||||
// long size = files.Sum(f => f.Length);
|
||||
|
||||
// foreach (var formFile in files)
|
||||
// {
|
||||
// if (formFile.Length > 0)
|
||||
// {
|
||||
// var filePath = Path.GetTempFileName();
|
||||
// System.Diagnostics.Debug.WriteLine(filePath);
|
||||
// using (var stream = System.IO.File.Create(filePath))
|
||||
// {
|
||||
// await formFile.CopyToAsync(stream);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Process uploaded files
|
||||
// // Don't rely on or trust the FileName property without validation.
|
||||
|
||||
// return RedirectToPage("./Edit");
|
||||
//}
|
||||
|
||||
public async Task<IActionResult> OnPostUpload(int idProject, int idProjectPart, List<IFormFile> postedFiles)
|
||||
{
|
||||
if (postedFiles == null
|
||||
|| postedFiles.Count != 1)
|
||||
{
|
||||
return Page();//TODO return error
|
||||
}
|
||||
string path = Path.Combine(_hostingEnvironment.WebRootPath, "Uploads");
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
|
||||
List<string> uploadedFiles = new List<string>();
|
||||
|
||||
var postedFile = postedFiles[0];
|
||||
|
||||
string fileName = Guid.NewGuid().ToString().Replace("-", "_") + Path.GetExtension(postedFile.FileName);
|
||||
using (FileStream stream = new FileStream(Path.Combine(path, fileName), FileMode.Create))
|
||||
{
|
||||
postedFile.CopyTo(stream);
|
||||
uploadedFiles.Add(fileName);
|
||||
}
|
||||
return RedirectToPage("./CreatePartItemImportExcel", new { idProject = idProject, idProjectPart = idProjectPart, fileName = fileName});
|
||||
}
|
||||
}
|
||||
}
|
||||
53
EveryThing/Pages/Projects/Delete.cshtml
Normal file
53
EveryThing/Pages/Projects/Delete.cshtml
Normal file
@@ -0,0 +1,53 @@
|
||||
@page
|
||||
@model EveryThing.Pages.Projects.DeleteModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Delete";
|
||||
Layout = "~/Pages/Layouts/_Layout.cshtml";
|
||||
}
|
||||
|
||||
<h1>Delete</h1>
|
||||
|
||||
<h3>Are you sure you want to delete this?</h3>
|
||||
<div>
|
||||
<h4>Project</h4>
|
||||
<hr />
|
||||
<dl class="row">
|
||||
<dt class="col-sm-2">
|
||||
@Html.DisplayNameFor(model => model.Project.Title)
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@Html.DisplayFor(model => model.Project.Title)
|
||||
</dd>
|
||||
<dt class="col-sm-2">
|
||||
@Html.DisplayNameFor(model => model.Project.Description)
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@Html.DisplayFor(model => model.Project.Description)
|
||||
</dd>
|
||||
<dt class="col-sm-2">
|
||||
@Html.DisplayNameFor(model => model.Project.Status)
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@Html.DisplayFor(model => model.Project.Status)
|
||||
</dd>
|
||||
<dt class="col-sm-2">
|
||||
@Html.DisplayNameFor(model => model.Project.FinishedDate)
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@Html.DisplayFor(model => model.Project.FinishedDate)
|
||||
</dd>
|
||||
<dt class="col-sm-2">
|
||||
@Html.DisplayNameFor(model => model.Project.Company)
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@Html.DisplayFor(model => model.Project.Company.Bank)
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<form method="post">
|
||||
<input type="hidden" asp-for="Project.IdProject" />
|
||||
<input type="submit" value="Delete" class="btn btn-danger" /> |
|
||||
<a asp-page="./Index">Back to List</a>
|
||||
</form>
|
||||
</div>
|
||||
62
EveryThing/Pages/Projects/Delete.cshtml.cs
Normal file
62
EveryThing/Pages/Projects/Delete.cshtml.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using EveryThing.Data;
|
||||
using EveryThing.Models.Project;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
namespace EveryThing.Pages.Projects
|
||||
{
|
||||
[Authorize(Roles = "Administrator,ProjecThingUser")]
|
||||
public class DeleteModel : PageModel
|
||||
{
|
||||
private readonly EveryThing.Data.ApplicationDbContext _context;
|
||||
|
||||
public DeleteModel(EveryThing.Data.ApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
[BindProperty]
|
||||
public Models.Project.Project Project { get; set; }
|
||||
|
||||
public async Task<IActionResult> OnGetAsync(int? id)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
Project = await _context.Projects
|
||||
.Include(p => p.Company).FirstOrDefaultAsync(m => m.IdProject == id);
|
||||
|
||||
if (Project == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
return Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostAsync(int? id)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
Project = await _context.Projects.FindAsync(id);
|
||||
|
||||
if (Project != null)
|
||||
{
|
||||
_context.Projects.Remove(Project);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
return RedirectToPage("./Index");
|
||||
}
|
||||
}
|
||||
}
|
||||
50
EveryThing/Pages/Projects/Details.cshtml
Normal file
50
EveryThing/Pages/Projects/Details.cshtml
Normal file
@@ -0,0 +1,50 @@
|
||||
@page
|
||||
@model EveryThing.Pages.Projects.DetailsModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Details";
|
||||
Layout = "~/Pages/Layouts/_Layout.cshtml";
|
||||
}
|
||||
|
||||
<h1>Details</h1>
|
||||
|
||||
<div>
|
||||
<h4>Project</h4>
|
||||
<hr />
|
||||
<dl class="row">
|
||||
<dt class="col-sm-2">
|
||||
@Html.DisplayNameFor(model => model.Project.Title)
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@Html.DisplayFor(model => model.Project.Title)
|
||||
</dd>
|
||||
<dt class="col-sm-2">
|
||||
@Html.DisplayNameFor(model => model.Project.Description)
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@Html.DisplayFor(model => model.Project.Description)
|
||||
</dd>
|
||||
<dt class="col-sm-2">
|
||||
@Html.DisplayNameFor(model => model.Project.Status)
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@Html.DisplayFor(model => model.Project.Status)
|
||||
</dd>
|
||||
<dt class="col-sm-2">
|
||||
@Html.DisplayNameFor(model => model.Project.FinishedDate)
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@Html.DisplayFor(model => model.Project.FinishedDate)
|
||||
</dd>
|
||||
<dt class="col-sm-2">
|
||||
@Html.DisplayNameFor(model => model.Project.Company)
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@Html.DisplayFor(model => model.Project.Company.Bank)
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div>
|
||||
<a asp-page="./Edit" asp-route-id="@Model.Project.IdProject">Edit</a> |
|
||||
<a asp-page="./Index">Back to List</a>
|
||||
</div>
|
||||
43
EveryThing/Pages/Projects/Details.cshtml.cs
Normal file
43
EveryThing/Pages/Projects/Details.cshtml.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using EveryThing.Data;
|
||||
using EveryThing.Models.Project;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
namespace EveryThing.Pages.Projects
|
||||
{
|
||||
[Authorize(Roles = "Administrator,ProjecThingUser")]
|
||||
public class DetailsModel : PageModel
|
||||
{
|
||||
private readonly EveryThing.Data.ApplicationDbContext _context;
|
||||
|
||||
public DetailsModel(EveryThing.Data.ApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public Models.Project.Project Project { get; set; }
|
||||
|
||||
public async Task<IActionResult> OnGetAsync(int? id)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
Project = await _context.Projects
|
||||
.Include(p => p.Company).FirstOrDefaultAsync(m => m.IdProject == id);
|
||||
|
||||
if (Project == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
return Page();
|
||||
}
|
||||
}
|
||||
}
|
||||
79
EveryThing/Pages/Projects/DetailsPartItem.cshtml
Normal file
79
EveryThing/Pages/Projects/DetailsPartItem.cshtml
Normal file
@@ -0,0 +1,79 @@
|
||||
@using System.Globalization
|
||||
@model EveryThing.Models.Project.ProjectPartItem
|
||||
|
||||
<tr data-idpartitem="@Model.IdProjectPartItem">
|
||||
<td style="width: 20px;">
|
||||
@if(Model.Status != Models.Project.ProjectPartItemStatus.Shipped)
|
||||
{
|
||||
<input type="checkbox" class="form-control" name="projectPartItem" style="width:15px; height:15px; margin: 0px;"/>
|
||||
}
|
||||
</td>
|
||||
<td>
|
||||
@if (Model.Item != null)
|
||||
{
|
||||
<a data-idcodetableitem="@Model.Item.IdItem" href="javascript:;" onclick="editCodetableItem(this)">@Html.DisplayFor(modelItem => Model.Item.Title)</a>
|
||||
}
|
||||
else
|
||||
{
|
||||
@Html.DisplayFor(modelItem => Model.IdItemFk)
|
||||
}
|
||||
<br/>
|
||||
@(Model.ProjectPartNumberFormatted)
|
||||
</td>
|
||||
<td>
|
||||
@if (Model.Material != null)
|
||||
{
|
||||
<a data-idcodetableitem="@Model.Material.IdItem" href="javascript:;" onclick="editCodetableItem(this)">@Html.DisplayFor(modelItem => Model.Material.Title)</a>
|
||||
}
|
||||
else
|
||||
{
|
||||
@Html.DisplayFor(modelItem => Model.IdMaterialFk)
|
||||
}
|
||||
-
|
||||
@Html.DisplayFor(modelItem => Model.MaterialSupplier.Title)
|
||||
@*@Html.DisplayFor(modelItem => Model.MaterialSupplier.Title)*@
|
||||
<br/>
|
||||
@Html.DisplayFor(modelItem => Model.MaterialDimensions)
|
||||
</td>
|
||||
<td class="table-number">
|
||||
@(Model.NumberOfItems.ToString("0.00", new CultureInfo("sl-SI")))
|
||||
<br/>
|
||||
@(Model.NumberOfSets.ToString("0.00", new CultureInfo("sl-SI")))
|
||||
</td>
|
||||
<td class="table-number">
|
||||
@(Model.MaterialPrice.ToString("0.00", new CultureInfo("sl-SI")))
|
||||
<br/>
|
||||
@(Model.MaterialValue.ToString("0.00", new CultureInfo("sl-SI")))
|
||||
</td>
|
||||
<td class="table-number">
|
||||
@(Model.WorkPrice.ToString("0.00", new CultureInfo("sl-SI")))
|
||||
<br />
|
||||
@(Model.WorkValue.ToString("0.00", new CultureInfo("sl-SI")))
|
||||
</td>
|
||||
<td class="table-number">
|
||||
@(Model.CostPrice.ToString("0.00", new CultureInfo("sl-SI")))
|
||||
<br />
|
||||
@(Model.CostValue.ToString("0.00", new CultureInfo("sl-SI")))
|
||||
</td>
|
||||
<td class="table-number">
|
||||
@(Model.DifferenceInPrice.ToString("0.00", new CultureInfo("sl-SI")))
|
||||
<br />
|
||||
@(Model.DifferenceInPricePercentage.ToString("0.00", new CultureInfo("sl-SI")))%
|
||||
</td>
|
||||
<td class="table-number">
|
||||
@(Model.SellingPrice.ToString("0.00", new CultureInfo("sl-SI")))
|
||||
<br />
|
||||
@(Model.SellingValue.ToString("0.00", new CultureInfo("sl-SI")))
|
||||
</td>
|
||||
<td style="width: 100px">
|
||||
@Html.DisplayFor(modelItem => Model.Status)
|
||||
<br/>
|
||||
@Html.DisplayFor(modelItem => Model.DeliveryDate)
|
||||
</td>
|
||||
<td class="text-right" style="width: 90px;">
|
||||
<a asp-page="CreateEditPartItem" asp-route-idProjectPartItem="@Model.IdProjectPartItem" asp-route-idProject="@Model.ProjectPart.IdProjectFk" asp-route-idProjectPart="@Model.IdProjectPartFk" asp-route-edit="@true" class="btn btn-xs icon-btn btn-outline-secondary borderless" data-state="secondary"><i class="far fa-edit"></i></a>
|
||||
<a class="btn btn-xs icon-btn btn-outline-secondary borderless" data-state="secondary" href='javascript:;'><i class="fas fa-pencil-alt" hx-get="@Url.Page("Edit", "EditPartItem", new {id = Model.IdProjectPartItem})" hx-swap="outerHTML" hx-target="closest tr"></i></a>
|
||||
<a class="btn btn-xs icon-btn btn-outline-danger borderless" data-state="danger" href='javascript:;' onclick="deletePartItem(this)"><i class="fas fa-times"></i></a>
|
||||
<a style="display: none;" id="btnTblCancel_@(Model.IdProjectPartItem.ToString())" href='javascript:;' class="btn btn-xs icon-btn btn-outline-danger borderless" data-state="danger" hx-get="@Url.Page("Edit", "DetailPartItem", new { id = Model.IdProjectPartItem })" hx-swap="outerHTML" hx-target="closest tr"><i class="fas fa-ban"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
1299
EveryThing/Pages/Projects/Edit.cshtml
Normal file
1299
EveryThing/Pages/Projects/Edit.cshtml
Normal file
File diff suppressed because it is too large
Load Diff
744
EveryThing/Pages/Projects/Edit.cshtml.cs
Normal file
744
EveryThing/Pages/Projects/Edit.cshtml.cs
Normal file
@@ -0,0 +1,744 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using EveryThing.Data;
|
||||
using EveryThing.Models;
|
||||
using EveryThing.Models.Project;
|
||||
using System.Text.Json;
|
||||
using EveryThing.Models.CodeTable;
|
||||
using DocumentFormat.OpenXml.InkML;
|
||||
using EveryThing.Models.Invoice;
|
||||
using EveryThing.Models.Vehicle;
|
||||
using static EveryThing.Pages.CodeTableVehicleFuelTypes.IndexModel;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using NuGet.Packaging;
|
||||
|
||||
namespace EveryThing.Pages.Projects
|
||||
{
|
||||
[Authorize(Roles = "Administrator,ProjecThingUser")]
|
||||
public class EditModel : PageModel
|
||||
{
|
||||
public class EditProjectPartData
|
||||
{
|
||||
public ProjectPartItem Item { get; set; }
|
||||
|
||||
public SelectList SelectListItems { get; set; }
|
||||
public SelectList SelectListMaterials { get; set; }
|
||||
public SelectList SelectListSuppliers { get; set; }
|
||||
|
||||
}
|
||||
private readonly ApplicationDbContext _context;
|
||||
private readonly UserManager<IdentityApplicationUser> _userManager;
|
||||
private readonly SignInManager<IdentityApplicationUser> _loginManager;
|
||||
private readonly RoleManager<IdentityApplicationRole> _roleManager;
|
||||
|
||||
public EditModel(ApplicationDbContext context, UserManager<IdentityApplicationUser> userManager, SignInManager<IdentityApplicationUser> loginManager, RoleManager<IdentityApplicationRole> roleManager)
|
||||
{
|
||||
_context = context;
|
||||
_userManager = userManager;
|
||||
_loginManager = loginManager;
|
||||
_roleManager = roleManager;
|
||||
}
|
||||
|
||||
[BindProperty]
|
||||
public Models.Project.Project Project { get; set; }
|
||||
public IList<ProjectPart> Parts { get; set; }
|
||||
public IList<ProjectPartItem> PartItems { get; set; }
|
||||
public IList<Models.Invoice.Invoice> Invoices { get; set; }
|
||||
public IList<Models.File> FilesProject { get; set; }
|
||||
public IList<Models.File> FilesProjectParts { get; set; }
|
||||
|
||||
public async Task<IActionResult> OnGetAsync(int? id)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
|
||||
ViewData["IdPartnerFk"] = new SelectList(_context.CodeTablePartners
|
||||
.Where(x => x.IdCompanyFk == user.IdCompanyFk && x.Active && x.Buyer)
|
||||
.OrderBy(x => x.Title), "IdPartner", "Title");
|
||||
|
||||
Project = await _context.Projects.FirstOrDefaultAsync(m => m.IdProject == id && m.IdCompanyFk == user.IdCompanyFk);
|
||||
|
||||
if (Project == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
Parts = await _context.ProjectParts
|
||||
.Include(c => c.ProjectPartProjectPartItem)
|
||||
.ThenInclude(x => x.MaterialSupplier)
|
||||
.Include(c => c.ProjectPartProjectPartItem)
|
||||
.ThenInclude(x => x.Material)
|
||||
.Include(c => c.ProjectPartProjectPartItem)
|
||||
.ThenInclude(x => x.Item)
|
||||
.Where(x => x.IdProjectFk == id)
|
||||
.OrderBy(x => x.ProjectPartNumber).ThenBy(x => x.IdProjectPart)
|
||||
.ToListAsync();
|
||||
|
||||
Invoices = await _context.Invoices
|
||||
.Include(x => x.Partner)
|
||||
.Include(x => x.InvoiceInvoiceItem)
|
||||
.ThenInclude(x => x.ProjectPartItem)
|
||||
.ThenInclude(x => x.ProjectPart)
|
||||
.Where(x => x.InvoiceInvoiceItem.Any(x => x.ProjectPartItem.ProjectPart.IdProjectFk == id))
|
||||
.OrderBy(x => x.InvoiceYear).ThenBy(x => x.InvoiceNumber)
|
||||
.ToListAsync();
|
||||
|
||||
FilesProject = await _context.Files
|
||||
.Where(x => x.IdCompanyFk == user.IdCompanyFk
|
||||
&& x.IdReferenceFk == Project.IdProject
|
||||
&& x.FileType == FileType.Project)
|
||||
.ToListAsync();
|
||||
|
||||
FilesProjectParts = await _context.Files
|
||||
.Where(x => x.IdCompanyFk == user.IdCompanyFk
|
||||
&& Parts.Select(x => x.IdProjectPart).Contains(x.IdReferenceFk)
|
||||
&& x.FileType == FileType.ProjectPart)
|
||||
.ToListAsync();
|
||||
|
||||
return Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostAsync()
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return Page();
|
||||
}
|
||||
|
||||
_context.Attach(Project).State = EntityState.Modified;
|
||||
|
||||
try
|
||||
{
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
if (!ProjectExists(Project.IdProject))
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return RedirectToPage("./Edit", new { id = Project.IdProject});
|
||||
}
|
||||
|
||||
private bool ProjectExists(int id)
|
||||
{
|
||||
return _context.Projects.Any(e => e.IdProject == id);
|
||||
}
|
||||
|
||||
public IActionResult OnGetEditPartItem(int id)
|
||||
{
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
|
||||
var item = _context.ProjectPartItems
|
||||
.Include(x => x.MaterialSupplier)
|
||||
.Include(x => x.Item)
|
||||
.Include(x => x.Material)
|
||||
.Include(x => x.ProjectPart)
|
||||
.ThenInclude(x => x.Project)
|
||||
.First(x => x.IdProjectPartItem == id);
|
||||
var selListItems = new SelectList(_context.CodeTableItems.Where(x => x.IdCompanyFk == user.IdCompanyFk && x.Active && x.CodeTableItemType == CodeTableItemType.Product).OrderBy(x => x.Title), "IdItem", "Title");
|
||||
var selListMaterials = new SelectList(_context.CodeTableItems.Where(x => x.IdCompanyFk == user.IdCompanyFk && x.Active && x.CodeTableItemType == CodeTableItemType.Material).OrderBy(x => x.Title), "IdItem", "Title");
|
||||
var selListSuppliers = new SelectList(_context.CodeTablePartners.Where(x => x.IdCompanyFk == user.IdCompanyFk && x.Active && x.Supplier).OrderBy(x => x.Title), "IdPartner", "Title");
|
||||
|
||||
|
||||
return Partial("EditPartItem", new EditProjectPartData
|
||||
{
|
||||
Item = item,
|
||||
SelectListItems = selListItems,
|
||||
SelectListMaterials = selListMaterials,
|
||||
SelectListSuppliers = selListSuppliers
|
||||
});
|
||||
}
|
||||
|
||||
public IActionResult OnGetDetailPartItem(int id)
|
||||
{
|
||||
var item = _context.ProjectPartItems
|
||||
.Include(x => x.ProjectPart)
|
||||
.Include(x => x.MaterialSupplier)
|
||||
.Include(x => x.Item)
|
||||
.Include(x => x.Material)
|
||||
.Include(x => x.ProjectPart)
|
||||
.ThenInclude(x => x.Project)
|
||||
.First(x => x.IdProjectPartItem == id);
|
||||
|
||||
return Partial("DetailsPartItem", item);
|
||||
}
|
||||
|
||||
public IActionResult OnPostCreateOrder(string itemsJson, bool inquiry)
|
||||
{
|
||||
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();
|
||||
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 => ((!inquiry && x.State == Models.Invoice.Invoice.InvoiceState.New) || (inquiry && x.State == Models.Invoice.Invoice.InvoiceState.Inquiry))
|
||||
&& x.Type == Models.Invoice.Invoice.InvoiceType.Order
|
||||
//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.Order, ref newInvoice, _context);
|
||||
newInvoice.IdPartnerFk = idSupplier;
|
||||
newInvoice.Date = DateTime.Now.Date;
|
||||
if (inquiry)
|
||||
newInvoice.State = Invoice.InvoiceState.Inquiry;
|
||||
|
||||
_context.Invoices.Add(newInvoice);
|
||||
_context.SaveChanges();
|
||||
idInvoice = newInvoice.IdInvoice;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Add to existing invoice
|
||||
idInvoice = invoice.IdInvoice;
|
||||
}
|
||||
|
||||
foreach (var projectPartItem in items.Where(x => 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 * projectPartItem.NumberOfSets
|
||||
Quantity = projectPartItem.NumberOfItems
|
||||
};
|
||||
_context.InvoiceItems.Add(newInvoiceItem);
|
||||
}
|
||||
_context.SaveChanges();
|
||||
}
|
||||
|
||||
return new JsonResult(new { error = "", successful = true, idInvoice});
|
||||
}
|
||||
|
||||
public IActionResult OnPostCreateDeliveryNote(string itemsJson)
|
||||
{
|
||||
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();
|
||||
|
||||
if (!items.Any())
|
||||
return new OkResult();
|
||||
|
||||
var idPartner = items.First().ProjectPart.Project.IdPartnerFk;
|
||||
|
||||
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.DeliveryNote
|
||||
//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 == idPartner);
|
||||
|
||||
int idInvoice;
|
||||
if (invoice == null)
|
||||
{
|
||||
//Create new invoice
|
||||
var newInvoice = new Models.Invoice.Invoice();
|
||||
Pages.Invoices.CreateModel.SetNewInvoice(user.IdCompanyFk, Models.Invoice.Invoice.InvoiceType.DeliveryNote, ref newInvoice, _context);
|
||||
newInvoice.IdPartnerFk = idPartner;
|
||||
newInvoice.Date = DateTime.Now.Date;
|
||||
newInvoice.DateOfDispatch = DateTime.Now.Date;
|
||||
newInvoice.BuyersOrderNumber = items.First().ProjectPart.Project.BuyersOrderNumber;
|
||||
|
||||
_context.Invoices.Add(newInvoice);
|
||||
_context.SaveChanges();
|
||||
idInvoice = newInvoice.IdInvoice;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Add to existing invoice
|
||||
idInvoice = invoice.IdInvoice;
|
||||
}
|
||||
|
||||
foreach (var projectPartItem in items)
|
||||
{
|
||||
var newInvoiceItem = new Models.Invoice.InvoiceItem
|
||||
{
|
||||
Discount = 0,
|
||||
IdInvoiceFk = idInvoice,
|
||||
IdProjectPartItem = projectPartItem.IdProjectPartItem,
|
||||
IdItemFk = projectPartItem.IdItemFk,
|
||||
ItemDescription = "",
|
||||
Note = "",
|
||||
Price = projectPartItem.SellingPrice,
|
||||
//Quantity = projectPartItem.NumberOfItems * projectPartItem.NumberOfSets
|
||||
Quantity = projectPartItem.NumberOfItems * projectPartItem.NumberOfSets
|
||||
};
|
||||
projectPartItem.Status = ProjectPartItemStatus.Shipped;
|
||||
projectPartItem.ShippingDate = DateTime.Now;
|
||||
|
||||
_context.InvoiceItems.Add(newInvoiceItem);
|
||||
}
|
||||
_context.SaveChanges();
|
||||
|
||||
return new OkResult();
|
||||
}
|
||||
|
||||
public IActionResult OnPostUpdatePartItem(int idItem, string json)
|
||||
{
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
|
||||
var tmpItem = JsonSerializer.Deserialize<ProjectPartItem>(json);
|
||||
|
||||
var item = _context.ProjectPartItems
|
||||
.Include(x => x.ProjectPart)
|
||||
.ThenInclude(x => x.Project)
|
||||
.FirstOrDefault(x => x.IdProjectPartItem == idItem
|
||||
&& x.ProjectPart.Project.IdCompanyFk == user.IdCompanyFk);
|
||||
|
||||
if (item == null)
|
||||
{
|
||||
return new JsonResult(new { error = $"Project part item with id {idItem} not exists!", successful = false});
|
||||
}
|
||||
|
||||
item.DateModified = DateTime.Now;
|
||||
item.IdItemFk = tmpItem.IdItemFk;
|
||||
item.NumberOfSets = tmpItem.NumberOfSets;
|
||||
item.NumberOfItems = tmpItem.NumberOfItems;
|
||||
item.IdMaterialFk = tmpItem.IdMaterialFk;
|
||||
item.MaterialDimensions = tmpItem.MaterialDimensions;
|
||||
item.IdMaterialSupplierFk = tmpItem.IdMaterialSupplierFk;
|
||||
item.MaterialPrice = tmpItem.MaterialPrice;
|
||||
item.WorkPrice = tmpItem.WorkPrice;
|
||||
item.Status = tmpItem.Status;
|
||||
item.DeliveryDate = tmpItem.DeliveryDate;
|
||||
item.SellingPrice = tmpItem.SellingPrice;
|
||||
_context.SaveChanges();
|
||||
|
||||
return new JsonResult(new { error = "", successful = true });
|
||||
}
|
||||
|
||||
public IActionResult OnDeletePartItem(int idPartItem)
|
||||
{
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
|
||||
var successful = true;
|
||||
var error = "";
|
||||
|
||||
var item = _context.ProjectPartItems
|
||||
.Include(x=>x.ProjectPart)
|
||||
.ThenInclude(x => x.Project)
|
||||
.Include(x=> x.InvoiceItem)
|
||||
.FirstOrDefault(x => x.IdProjectPartItem == idPartItem
|
||||
&& x.ProjectPart.Project.IdCompanyFk == user.IdCompanyFk);
|
||||
|
||||
if (item == null)
|
||||
{
|
||||
return new JsonResult(new { error = $"Project part item with id {idPartItem} not exists!", successful = false });
|
||||
}
|
||||
|
||||
if (item.InvoiceItem.Count > 0)
|
||||
{
|
||||
return new JsonResult(new { error = $"Pozicija ima povezane fakture!\nBrisanje ni možno!", successful = false });
|
||||
}
|
||||
|
||||
_context.ProjectPartItems.Remove(item);
|
||||
_context.SaveChanges();
|
||||
|
||||
return new JsonResult(new { error = "", successful = true});
|
||||
}
|
||||
|
||||
public IActionResult OnPostCopyProjectPart(int idProjectPart)
|
||||
{
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
bool successful = true;
|
||||
string error = "";
|
||||
|
||||
var projectPart = _context.ProjectParts
|
||||
.Include(x => x.Project)
|
||||
.Where(x => x.Project.IdCompanyFk == user.IdCompanyFk)
|
||||
.FirstOrDefault(x => x.IdProjectPart == idProjectPart);
|
||||
if (projectPart != null)
|
||||
{
|
||||
|
||||
var newProjectPart = new ProjectPart
|
||||
{
|
||||
IdProjectFk = projectPart.IdProjectFk,
|
||||
Description = projectPart.Description,
|
||||
//FinishedDate = item.FinishedDate,
|
||||
PathOfPlans = projectPart.PathOfPlans,
|
||||
ShippedDate = projectPart.ShippedDate,
|
||||
Status = projectPart.Status,
|
||||
Title = projectPart.Title,
|
||||
ProjectPartNumber = _context.ProjectParts.Where(x => x.IdProjectFk == projectPart.IdProjectFk).Max(x => x.ProjectPartNumber) + 1
|
||||
};
|
||||
|
||||
if (newProjectPart.ProjectPartNumber <= 0)
|
||||
newProjectPart.ProjectPartNumber = 1;
|
||||
|
||||
_context.ProjectParts.Add(newProjectPart);
|
||||
|
||||
_context.SaveChanges();
|
||||
|
||||
var projectPartItemCounter = 1;
|
||||
foreach (var projectPartItem in _context.ProjectPartItems.Where(x => x.IdProjectPartFk == projectPart.IdProjectPart))
|
||||
{
|
||||
var newProjectPartItem = new ProjectPartItem
|
||||
{
|
||||
IdItemFk = projectPartItem.IdItemFk,
|
||||
IdMaterialFk = projectPartItem.IdMaterialFk,
|
||||
IdMaterialSupplierFk = projectPartItem.IdMaterialSupplierFk,
|
||||
IdProjectPartFk = newProjectPart.IdProjectPart,
|
||||
MaterialDimensions = projectPartItem.MaterialDimensions,
|
||||
MaterialPrice = projectPartItem.MaterialPrice,
|
||||
NumberOfItems = projectPartItem.NumberOfItems,
|
||||
NumberOfItemsFinished = projectPartItem.NumberOfItemsFinished,
|
||||
WorkPrice = projectPartItem.WorkPrice,
|
||||
NumberOfSets = projectPartItem.NumberOfSets,
|
||||
Status = ProjectPartItemStatus.Opened,
|
||||
ProjectPartItemNumber = projectPartItemCounter
|
||||
};
|
||||
_context.ProjectPartItems.Add(newProjectPartItem);
|
||||
|
||||
projectPartItemCounter++;
|
||||
}
|
||||
_context.SaveChanges();
|
||||
}
|
||||
else
|
||||
{
|
||||
successful = false;
|
||||
error = $"Project part with ID: {idProjectPart} not found";
|
||||
}
|
||||
|
||||
return new JsonResult(new { error, successful });
|
||||
}
|
||||
|
||||
public IActionResult OnGetProjectPart(int idProjectPart)
|
||||
{
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
|
||||
var successful = true;
|
||||
var error = "";
|
||||
var inUse = false;
|
||||
|
||||
var projectPart = _context.ProjectParts
|
||||
.Include(x => x.Project)
|
||||
.Include(x => x.ProjectPartProjectPartItem)
|
||||
.ThenInclude(x => x.InvoiceItem)
|
||||
.FirstOrDefault(x => x.IdProjectPart == idProjectPart
|
||||
&& x.Project.IdCompanyFk == user.IdCompanyFk);
|
||||
|
||||
if (projectPart == null)
|
||||
{
|
||||
successful = false;
|
||||
error = $"Project part with ID: {idProjectPart} not found";
|
||||
}
|
||||
else
|
||||
{
|
||||
inUse = projectPart.ProjectPartProjectPartItem.Any(x => x.InvoiceItem.Count > 0);
|
||||
//Cene se json zacikla neki IDK.
|
||||
projectPart.Project = null;
|
||||
projectPart.ProjectPartProjectPartItem = null;
|
||||
}
|
||||
|
||||
return new JsonResult(new { projectPart, error, successful, inUse });
|
||||
}
|
||||
|
||||
public IActionResult OnGetProjectPriceDetails(int idProject)
|
||||
{
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
|
||||
var successful = true;
|
||||
var error = "";
|
||||
|
||||
var projectPartItems = _context.ProjectPartItems
|
||||
.Include(x => x.ProjectPart)
|
||||
.ThenInclude(x => x.Project)
|
||||
.Where(x => x.ProjectPart.IdProjectFk == idProject && x.ProjectPart.Project.IdCompanyFk == user.IdCompanyFk)
|
||||
.ToList();
|
||||
|
||||
var totals = new
|
||||
{
|
||||
parts = projectPartItems
|
||||
.GroupBy(x => x.ProjectPart)
|
||||
.Select(x => new
|
||||
{
|
||||
idProjectPart = x.Key.IdProjectPart,
|
||||
text = $"Strošek delo: <b>{x.Sum(y => y.WorkValue).ToString("#,###,##0.00", new CultureInfo("sl-SI"))} €</b>"
|
||||
+ $"<br/>Strošek material: <b>{x.Sum(y => y.MaterialValue).ToString("#,###,##0.00", new CultureInfo("sl-SI"))} €</b>"
|
||||
+ $"<br/>Strošek skupaj: <b>{x.Sum(y => y.WorkValue + y.MaterialValue).ToString("#,###,##0.00", new CultureInfo("sl-SI"))} €</b>"
|
||||
+ $"<br/>Prodajna vrednost: <b>{x.Sum(y => y.SellingValue).ToString("#,###,##0.00", new CultureInfo("sl-SI"))} €</b>"
|
||||
+ $"<br/>Razlika: <b>{x.Sum(y => y.DifferenceInPriceValue).ToString("#,###,##0.00", new CultureInfo("sl-SI"))} €</b>"
|
||||
}).ToList(),
|
||||
project = new
|
||||
{
|
||||
text = $"Strošek delo: <b>{projectPartItems.Sum(y => y.WorkValue).ToString("#,###,##0.00", new CultureInfo("sl-SI"))} €</b>"
|
||||
+ $"<br/>Strošek material: <b>{projectPartItems.Sum(y => y.MaterialValue).ToString("#,###,##0.00", new CultureInfo("sl-SI"))} €</b>"
|
||||
+ $"<br/>Strošek skupaj: <b>{projectPartItems.Sum(y => y.WorkValue + y.MaterialValue).ToString("#,###,##0.00", new CultureInfo("sl-SI"))} €</b>"
|
||||
+ $"<br/>Prodajna vrednost: <b>{projectPartItems.Sum(y => y.SellingValue).ToString("#,###,##0.00", new CultureInfo("sl-SI"))} €</b>"
|
||||
+ $"<br/>Razlika: <b>{projectPartItems.Sum(y => y.DifferenceInPriceValue).ToString("#,###,##0.00", new CultureInfo("sl-SI"))} €</b>"
|
||||
},
|
||||
};
|
||||
|
||||
return new JsonResult(new { totals, error, successful });
|
||||
}
|
||||
|
||||
public IActionResult OnDeleteProjectPart(int idProjectPart)
|
||||
{
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
var successful = true;
|
||||
var error = "";
|
||||
|
||||
var projectPart = _context.ProjectParts
|
||||
.Include(x => x.Project)
|
||||
.FirstOrDefault(x => x.IdProjectPart == idProjectPart
|
||||
&& x.Project.IdCompanyFk == user.IdCompanyFk);
|
||||
|
||||
if (projectPart != null)
|
||||
{
|
||||
foreach (var projectPartItem in _context.ProjectPartItems.Where(x => x.IdProjectPartFk == projectPart.IdProjectPart).ToList())
|
||||
{
|
||||
_context.ProjectPartItems.Remove(projectPartItem);
|
||||
}
|
||||
_context.ProjectParts.Remove(projectPart);
|
||||
_context.SaveChanges();
|
||||
|
||||
projectPart.Project = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
successful = false;
|
||||
error = $"Project part with ID: {idProjectPart} not found";
|
||||
}
|
||||
|
||||
return new JsonResult(new { projectPart, error, successful });
|
||||
}
|
||||
|
||||
public IActionResult OnPostProjectPartAddMarginOnAllPositions(int idProjectPart, double value)
|
||||
{
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
var successful = true;
|
||||
var error = "";
|
||||
|
||||
var projectPart = _context.ProjectParts
|
||||
.Include(x => x.Project)
|
||||
.FirstOrDefault(x => x.IdProjectPart == idProjectPart
|
||||
&& x.Project.IdCompanyFk == user.IdCompanyFk);
|
||||
|
||||
if (projectPart != null)
|
||||
{
|
||||
var items = _context.ProjectPartItems
|
||||
.Where(x => x.IdProjectPartFk == projectPart.IdProjectPart);
|
||||
|
||||
foreach (var item in items)
|
||||
{
|
||||
var costs = Convert.ToDouble(item.MaterialPrice) + Convert.ToDouble(item.WorkPrice);
|
||||
var newDifferenceInPricePercentage = item.DifferenceInPricePercentage + value;
|
||||
|
||||
item.SellingPrice = Convert.ToSingle(costs * (newDifferenceInPricePercentage + 100.0) / 100.0);
|
||||
}
|
||||
|
||||
_context.SaveChanges();
|
||||
}
|
||||
else
|
||||
{
|
||||
successful = false;
|
||||
error = $"Project part with ID: {idProjectPart} not found";
|
||||
}
|
||||
|
||||
return new JsonResult(new { error, successful });
|
||||
}
|
||||
|
||||
public IActionResult OnPostProjectPartNewSaleValueForAllPositions(int idProjectPart, double value)
|
||||
{
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
var successful = true;
|
||||
var error = "";
|
||||
|
||||
var projectPart = _context.ProjectParts
|
||||
.Include(x => x.Project)
|
||||
.FirstOrDefault(x => x.IdProjectPart == idProjectPart
|
||||
&& x.Project.IdCompanyFk == user.IdCompanyFk);
|
||||
|
||||
if (projectPart != null)
|
||||
{
|
||||
var items = _context.ProjectPartItems
|
||||
.Where(x => x.IdProjectPartFk == projectPart.IdProjectPart);
|
||||
|
||||
var totalCost = _context.ProjectPartItems
|
||||
.Where(x => x.IdProjectPartFk == projectPart.IdProjectPart)
|
||||
.ToList()
|
||||
.Sum(x => x.CostValue);
|
||||
|
||||
var coefficient = Math.Round(value,2) / Math.Round(totalCost, 2);
|
||||
|
||||
foreach (var item in items)
|
||||
{
|
||||
if (item.NumberOfItems * item.NumberOfSets == 0)
|
||||
item.SellingPrice = 0;
|
||||
else
|
||||
item.SellingPrice = Convert.ToSingle(Math.Round((coefficient * item.CostValue) / (item.NumberOfItems * item.NumberOfSets), 8));
|
||||
}
|
||||
|
||||
_context.SaveChanges();
|
||||
}
|
||||
else
|
||||
{
|
||||
successful = false;
|
||||
error = $"Project part with ID: {idProjectPart} not found";
|
||||
}
|
||||
|
||||
return new JsonResult(new { error, successful });
|
||||
}
|
||||
|
||||
public IActionResult OnPostCreateInvoice(string itemsJson)
|
||||
{
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
|
||||
var itemsId = JsonSerializer.Deserialize<List<int>>(itemsJson);
|
||||
|
||||
var deliveryNotes = _context.Invoices
|
||||
.Include(x => x.InvoiceInvoiceItem)
|
||||
.Where(x => itemsId.Contains(x.IdInvoice)).ToList();
|
||||
|
||||
if (!deliveryNotes.Any())
|
||||
return new JsonResult(new { successful = false, error = "Delivery notes not found!" });
|
||||
|
||||
var idPartner = deliveryNotes.First().IdPartnerFk;
|
||||
|
||||
var newInvoice = new Models.Invoice.Invoice();
|
||||
Pages.Invoices.CreateModel.SetNewInvoice(user.IdCompanyFk, Models.Invoice.Invoice.InvoiceType.Invoice, ref newInvoice, _context);
|
||||
newInvoice.IdPartnerFk = idPartner;
|
||||
newInvoice.Date = DateTime.Now.Date;
|
||||
newInvoice.DateOfDispatch = deliveryNotes.Min(x => x.DateOfDispatch);
|
||||
newInvoice.BuyersOrderNumber = deliveryNotes.First().BuyersOrderNumber;
|
||||
|
||||
_context.Invoices.Add(newInvoice);
|
||||
_context.SaveChanges();
|
||||
var idInvoice = newInvoice.IdInvoice;
|
||||
|
||||
foreach (var deliveryNote in deliveryNotes)
|
||||
{
|
||||
foreach (var invoiceItem in deliveryNote.InvoiceInvoiceItem)
|
||||
{
|
||||
var newInvoiceItem = new InvoiceItem
|
||||
{
|
||||
Discount = invoiceItem.Discount,
|
||||
IdInvoiceFk = idInvoice,
|
||||
IdProjectPartItem = invoiceItem.IdProjectPartItem,
|
||||
IdItemFk = invoiceItem.IdItemFk,
|
||||
ItemDescription = invoiceItem.ItemDescription,
|
||||
Note = invoiceItem.Note,
|
||||
Price = invoiceItem.Price,
|
||||
Quantity = invoiceItem.Quantity,
|
||||
IdInvoiceItemJoinFk = invoiceItem.IdInvoiceItem
|
||||
};
|
||||
invoiceItem.State = InvoiceItem.InvoiceItemState.Closed;
|
||||
|
||||
_context.InvoiceItems.Add(newInvoiceItem);
|
||||
}
|
||||
|
||||
deliveryNote.State = Invoice.InvoiceState.Closed;
|
||||
|
||||
}
|
||||
_context.SaveChanges();
|
||||
|
||||
return new JsonResult(new { successful = true, error = "", idInvoice });
|
||||
}
|
||||
|
||||
public IActionResult OnPostCreateOfferFromProject(int idProject, string itemsJson)
|
||||
{
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
|
||||
var itemsId = JsonSerializer.Deserialize<List<int>>(itemsJson);
|
||||
|
||||
var project = _context.Projects
|
||||
.Include(x => x.Partner)
|
||||
.Include(x => x.ProjectProjectPart)
|
||||
.ThenInclude(x => x.ProjectPartProjectPartItem)
|
||||
.FirstOrDefault(x => x.IdProject == idProject );
|
||||
|
||||
if (project == null)
|
||||
return new JsonResult(new { successful = false, error = "Project not found!" });
|
||||
|
||||
var idPartner = project.IdPartnerFk;
|
||||
|
||||
var newInvoice = new Invoice();
|
||||
Pages.Invoices.CreateModel.SetNewInvoice(user.IdCompanyFk, Invoice.InvoiceType.BuyersOrder, ref newInvoice, _context);
|
||||
newInvoice.IdPartnerFk = idPartner;
|
||||
newInvoice.Date = DateTime.Now.Date;
|
||||
newInvoice.DateOfDispatch = project.ProjectProjectPart.Min(x => x.ProjectPartProjectPartItem.Where(x => itemsId.Contains(x.IdProjectPartItem)).Min(y => y.DeliveryDate));
|
||||
newInvoice.State = Invoice.InvoiceState.Offer;
|
||||
newInvoice.BuyersOrderNumber = "";
|
||||
|
||||
_context.Invoices.Add(newInvoice);
|
||||
_context.SaveChanges();
|
||||
var idInvoice = newInvoice.IdInvoice;
|
||||
|
||||
foreach (var projectPart in project.ProjectProjectPart.OrderBy(x => x.ProjectPartNumber))
|
||||
{
|
||||
foreach (var projectPartItem in projectPart.ProjectPartProjectPartItem.Where(x => itemsId.Contains(x.IdProjectPartItem)).OrderBy(x => x.ProjectPartItemNumber))
|
||||
{
|
||||
var newInvoiceItem = new InvoiceItem
|
||||
{
|
||||
IdProjectPartItem = projectPartItem.IdProjectPartItem,
|
||||
Discount = 0,
|
||||
IdInvoiceFk = idInvoice,
|
||||
IdItemFk = projectPartItem.IdItemFk,
|
||||
ItemDescription = projectPartItem.MaterialDimensions,
|
||||
Note = "",
|
||||
Price = projectPartItem.SellingPrice,
|
||||
Quantity = projectPartItem.NumberOfItems * projectPartItem.NumberOfSets
|
||||
};
|
||||
|
||||
_context.InvoiceItems.Add(newInvoiceItem);
|
||||
}
|
||||
|
||||
}
|
||||
_context.SaveChanges();
|
||||
|
||||
return new JsonResult(new { successful = true, error = "", idInvoice });
|
||||
}
|
||||
}
|
||||
}
|
||||
79
EveryThing/Pages/Projects/EditPart.cshtml
Normal file
79
EveryThing/Pages/Projects/EditPart.cshtml
Normal file
@@ -0,0 +1,79 @@
|
||||
@page
|
||||
@using EveryThing.Models.Project
|
||||
@model EveryThing.Pages.Projects.EditPartModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Urejanje dela projekta";
|
||||
Layout = "~/Pages/Layouts/_Layout.cshtml";
|
||||
}
|
||||
|
||||
<form method="post">
|
||||
|
||||
<h4 class="d-flex justify-content-between align-items-center w-100 font-weight-bold py-1 mb-4">
|
||||
<span>
|
||||
<span class="text-muted font-weight-light">Projekt /</span> Urejanje dela projekta
|
||||
</span>
|
||||
</h4>
|
||||
|
||||
<div class="row mb-4">
|
||||
<div class="col-4">
|
||||
<div class="card">
|
||||
<h6 class="card-header">
|
||||
Podatki dela projekta
|
||||
</h6>
|
||||
<div class="card-body">
|
||||
<input type="hidden" asp-for="ProjectPart.IdProjectPart" />
|
||||
<input type="hidden" asp-for="ProjectPart.IdProjectFk" />
|
||||
<input type="hidden" asp-for="ProjectPart.ProjectPartNumber" />
|
||||
<div class="form-group">
|
||||
<label asp-for="ProjectPart.Title" class="form-label"></label>
|
||||
<input asp-for="ProjectPart.Title" class="form-control" />
|
||||
<span asp-validation-for="ProjectPart.Title" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="ProjectPart.Description" class="form-label"></label>
|
||||
<input asp-for="ProjectPart.Description" class="form-control" />
|
||||
<span asp-validation-for="ProjectPart.Description" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="ProjectPart.PathOfPlans" class="form-label"></label>
|
||||
<input autocomplete="off" asp-for="ProjectPart.PathOfPlans" class="form-control"/>
|
||||
<span asp-validation-for="ProjectPart.PathOfPlans" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">
|
||||
<div class="form-group">
|
||||
<label asp-for="ProjectPart.Status" class="form-label"></label>
|
||||
<select asp-for="ProjectPart.Status" asp-items="Html.GetEnumSelectList<ProjectPartStatus>()" class="form-control">
|
||||
<option>Izberite status</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<div class="form-group">
|
||||
<label asp-for="ProjectPart.ShippedDate" class="form-label"></label>
|
||||
<input asp-for="ProjectPart.ShippedDate" class="form-control" />
|
||||
<span asp-validation-for="ProjectPart.ShippedDate" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<div class="form-group">
|
||||
<label asp-for="ProjectPart.FinishedDate" class="form-label"></label>
|
||||
<input asp-for="ProjectPart.FinishedDate" class="form-control" />
|
||||
<span asp-validation-for="ProjectPart.FinishedDate" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer py-3 text-right">
|
||||
<button type="submit" class="btn btn-primary">Shrani</button>
|
||||
<a asp-page="Edit" asp-route-id="@ViewBag.IdProject" class="btn btn-default">Prekliči</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@section Scripts {
|
||||
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
|
||||
}
|
||||
90
EveryThing/Pages/Projects/EditPart.cshtml.cs
Normal file
90
EveryThing/Pages/Projects/EditPart.cshtml.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using EveryThing.Data;
|
||||
using EveryThing.Models;
|
||||
using EveryThing.Models.Project;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
namespace EveryThing.Pages.Projects
|
||||
{
|
||||
[Authorize(Roles = "Administrator,ProjecThingUser")]
|
||||
public class EditPartModel : PageModel
|
||||
{
|
||||
private readonly ApplicationDbContext _context;
|
||||
private readonly UserManager<IdentityApplicationUser> _userManager;
|
||||
private readonly SignInManager<IdentityApplicationUser> _loginManager;
|
||||
private readonly RoleManager<IdentityApplicationRole> _roleManager;
|
||||
|
||||
public EditPartModel(ApplicationDbContext context, UserManager<IdentityApplicationUser> userManager, SignInManager<IdentityApplicationUser> loginManager, RoleManager<IdentityApplicationRole> roleManager)
|
||||
{
|
||||
_context = context;
|
||||
_userManager = userManager;
|
||||
_loginManager = loginManager;
|
||||
_roleManager = roleManager;
|
||||
}
|
||||
|
||||
[BindProperty]
|
||||
public ProjectPart ProjectPart { get; set; }
|
||||
|
||||
public async Task<IActionResult> OnGetAsync(int? id)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
|
||||
ProjectPart = await _context.ProjectParts.FirstOrDefaultAsync(m => m.IdProjectPart == id);
|
||||
|
||||
if (ProjectPart == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
ViewData["IdProject"] = ProjectPart.IdProjectFk;
|
||||
|
||||
return Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostAsync()
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return Page();
|
||||
}
|
||||
|
||||
_context.Attach(ProjectPart).State = EntityState.Modified;
|
||||
|
||||
try
|
||||
{
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
if (!ProjectExists(ProjectPart.IdProjectPart))
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return RedirectToPage("./Edit",new { id = ProjectPart.IdProjectFk });
|
||||
}
|
||||
|
||||
private bool ProjectExists(int id)
|
||||
{
|
||||
return _context.ProjectParts.Any(e => e.IdProjectPart == id);
|
||||
}
|
||||
}
|
||||
}
|
||||
53
EveryThing/Pages/Projects/EditPartItem.cshtml
Normal file
53
EveryThing/Pages/Projects/EditPartItem.cshtml
Normal file
@@ -0,0 +1,53 @@
|
||||
@model EveryThing.Pages.Projects.EditModel.EditProjectPartData
|
||||
|
||||
<tr data-iditem="@(Model.Item.IdProjectPartItem)">
|
||||
@using (Html.BeginForm("UpdatePartItem", "Edit", FormMethod.Post))
|
||||
{
|
||||
<input type="hidden" asp-for="Item.IdProjectPartItem" />
|
||||
<td class="table-eddit" style="width: 20px;">
|
||||
</td>
|
||||
<td class="table-eddit">
|
||||
<select id="selTblItem_@(Model.Item.IdProjectPartItem.ToString())" asp-for="Item.IdItemFk" class="form-control select2" asp-items="Model.SelectListItems" style="width: 100%"></select>
|
||||
@(Model.Item.ProjectPartNumberFormatted)
|
||||
</td>
|
||||
<td class="table-eddit">
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<select id="selTblMaterial_@(Model.Item.IdProjectPartItem.ToString())" asp-for="Item.IdMaterialFk" class="form-control select2" asp-items="Model.SelectListMaterials" style="width: 50% !important"></select>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<select id="selTblMaterialSupplier_@(Model.Item.IdProjectPartItem.ToString())" asp-for="Item.IdMaterialSupplierFk" class="form-control select2" asp-items="Model.SelectListSuppliers" style="width: 50% !important"></select>
|
||||
</div>
|
||||
</div>
|
||||
<input id="inpTblMaterialDimensions_@(Model.Item.IdProjectPartItem.ToString())" asp-for="Item.MaterialDimensions" class="form-control" style="width: 100%"/>
|
||||
</td>
|
||||
<td class="table-eddit table-number-edit">
|
||||
<input id="inpTblNumberOfItems_@(Model.Item.IdProjectPartItem.ToString())" asp-for="Item.NumberOfItems" class="form-control" style="width: 100%" />
|
||||
<input id="inpTblNumberOfSets_@(Model.Item.IdProjectPartItem.ToString())" asp-for="Item.NumberOfSets" class="form-control" style="width: 100%" />
|
||||
</td>
|
||||
<td class="table-eddit table-price-edit">
|
||||
<input id="inpTblMaterialPrice_@(Model.Item.IdProjectPartItem.ToString())" asp-for="Item.MaterialPrice" class="form-control inp-tbl-edit-calculate-difference-in-price" style="width: 100%" />
|
||||
</td>
|
||||
<td class="table-eddit table-price-edit">
|
||||
<input id="inpTblWrokPrice_@(Model.Item.IdProjectPartItem.ToString())" asp-for="Item.WorkPrice" class="form-control inp-tbl-edit-calculate-difference-in-price" style="width:100%" />
|
||||
</td>
|
||||
<td class="table-eddit table-price-edit">
|
||||
<input id="inpTblCostPrice_@(Model.Item.IdProjectPartItem.ToString())" asp-for="Item.CostPrice" class="form-control" readonly="readonly" style="width:100%" />
|
||||
</td>
|
||||
<td class="table-eddit table-price-edit">
|
||||
<input id="inpTblDifferenceInPrice_@(Model.Item.IdProjectPartItem.ToString())" asp-for="Item.DifferenceInPricePercentage" class="form-control inp-tbl-edit-calculate-price" style="width:100%" />
|
||||
</td>
|
||||
<td class="table-eddit table-price-edit">
|
||||
<input id="inpTblSellingPrice_@(Model.Item.IdProjectPartItem.ToString())" asp-for="Item.SellingPrice" class="form-control inp-tbl-edit-calculate-difference-in-price" style="width:100%" />
|
||||
</td>
|
||||
<td class="table-eddit" style="width: 120px !important;">
|
||||
<select id="selTblStatus_@(Model.Item.IdProjectPartItem.ToString())" asp-for="Item.Status" asp-items="Html.GetEnumSelectList<EveryThing.Models.Project.ProjectPartItemStatus>()" class="form-control" style="width: 100%">
|
||||
</select>
|
||||
@Html.TextBoxFor(m => m.Item.DeliveryDate, "{0:yyyy-MM-dd}", new { @class = "form-control", type = "date", id = "inpTblDeliveryDate_" + Model.Item.IdProjectPartItem.ToString() })
|
||||
</td>
|
||||
<td class="text-right table-eddit" style="width: 70px;">
|
||||
<a class="btn btn-xs icon-btn btn-outline-success borderless" href='javascript:;' data-state="success" data-iditem="@(Model.Item.IdProjectPartItem)" onclick="updatePartItem(this)"><i class="fas fa-check"></i></a>
|
||||
<a id="btnTblCancel_@(Model.Item.IdProjectPartItem.ToString())" href='javascript:;' class="btn btn-xs icon-btn btn-outline-danger borderless" data-state="danger" hx-get="@Url.Page("Edit", "DetailPartItem", new { id = Model.Item.IdProjectPartItem })" hx-swap="outerHTML" hx-target="closest tr"><i class="fas fa-ban"></i></a>
|
||||
</td>
|
||||
}
|
||||
</tr>
|
||||
230
EveryThing/Pages/Projects/Index.cshtml
Normal file
230
EveryThing/Pages/Projects/Index.cshtml
Normal file
@@ -0,0 +1,230 @@
|
||||
@page
|
||||
@using EveryThing.Models.Project
|
||||
@model EveryThing.Pages.Projects.IndexModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Projekti";
|
||||
Layout = "~/Pages/Layouts/_Layout.cshtml";
|
||||
}
|
||||
|
||||
<h4 class="d-flex justify-content-between align-items-center w-100 font-weight-bold py-1 mb-4">
|
||||
<span>
|
||||
<span class="text-muted font-weight-light">Projekti /</span> Pregled
|
||||
</span>
|
||||
</h4>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12 mb-2 text-right">
|
||||
<form method="get">
|
||||
<div class="btn-group">
|
||||
<input class="form-control" type="text" name="searchString" value="@ViewData["SearchString"]" placeholder="Iskanje..." autocomplete="off">
|
||||
<select asp-for="Year" class="form-control" asp-items="ViewBag.Years"></select>
|
||||
<div class="btn-group" title="Columns">
|
||||
<button class="btn btn-secondary dropdown-toggle" type="button" data-toggle="dropdown" aria-label="Nastavitve" title="Nastavitve">
|
||||
<i class="opacity-75 ion ion-md-apps"></i>
|
||||
<span class="caret"></span>
|
||||
</button>
|
||||
<div class="dropdown-menu dropdown-menu-right">
|
||||
<label class="dropdown-item">
|
||||
<input type="checkbox" name="openProjects" @ViewData["OpenProjects"]> <span>Odprti</span>
|
||||
</label>
|
||||
<label class="dropdown-item">
|
||||
<input type="checkbox" name="inProductionProjects" @ViewData["InProductionProjects"]> <span>V izdelavi</span>
|
||||
</label>
|
||||
<label class="dropdown-item">
|
||||
<input type="checkbox" name="finishedProjects" @ViewData["FinishedProjects"]> <span>Zaključeni projekti</span>
|
||||
</label>
|
||||
<label class="dropdown-item">
|
||||
<input type="checkbox" name="offerProjects" @ViewData["OffersProjects"]> <span>Ponudbe</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-secondary" aria-label="Osveži" title="Osveži">
|
||||
<i class="opacity-75 ion ion-md-refresh"></i>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
|
||||
<h6 class="card-header">
|
||||
Seznam projektov
|
||||
</h6>
|
||||
|
||||
<table class="table card-table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 150px;">
|
||||
@Html.DisplayNameFor(model => model.Project[0].ProjectNumberFormatted)
|
||||
</th>
|
||||
<th style="width: 200px;">
|
||||
@Html.DisplayNameFor(model => model.Project[0].Title)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Project[0].IdPartnerFk)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Project[0].Description)
|
||||
</th>
|
||||
<th style="width: 140px">
|
||||
@Html.DisplayNameFor(model => model.Project[0].FirstDeliveryDateString)
|
||||
</th>
|
||||
<th style="width: 100px">
|
||||
@Html.DisplayNameFor(model => model.Project[0].Status)
|
||||
</th>
|
||||
<th style="width: 110px;"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in Model.Project)
|
||||
{
|
||||
<tr data-idproject="@item.IdProject" data-title="@item.Title">
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.ProjectNumberFormatted)
|
||||
</td>
|
||||
<td>
|
||||
<a asp-page="Edit" asp-route-id="@item.IdProject">@Html.DisplayFor(modelItem => item.Title)</a>
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Partner.Title)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Description)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.FirstDeliveryDateString)
|
||||
</td>
|
||||
<td>
|
||||
@switch (item.Status)
|
||||
{
|
||||
case ProjectStatus.Finished:
|
||||
<span class='badge badge-success'>@Html.DisplayFor(modelItem => item.Status)</span>
|
||||
break;
|
||||
case ProjectStatus.InProduction:
|
||||
<span class='badge badge-warning'>@Html.DisplayFor(modelItem => item.Status)</span>
|
||||
break;
|
||||
case ProjectStatus.Offer:
|
||||
<span class='badge badge-default'>@Html.DisplayFor(modelItem => item.Status)</span>
|
||||
break;
|
||||
default:
|
||||
<span class='badge badge-info'>@Html.DisplayFor(modelItem => item.Status)</span>
|
||||
break;
|
||||
}
|
||||
</td>
|
||||
<td class="text-right">
|
||||
<a class="btn btn-xs icon-btn btn-outline-secondary borderless" asp-page="Edit" asp-route-id="@item.IdProject" data-toggle="tooltip" data-placement="top" title="Urejanje" data-state="secondary"><i class="fas fa-pencil-alt"></i></a>
|
||||
<a data-idproject="@item.IdProject" class="btn btn-xs icon-btn btn-outline-secondary borderless" data-toggle="tooltip" data-placement="top" title="Kopiraj projekt" data-state="secondary" href="javascript:;" onclick="copyProject(this);"><i class="far fa-copy"></i></a>
|
||||
<a class="btn btn-xs icon-btn btn-outline-danger borderless" data-state="danger" href='javascript:;' onclick="deleteProject(this)" data-toggle="tooltip" data-placement="top" title="Izbriši"><i class="fas fa-times"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="card-footer py-3 text-right">
|
||||
<a asp-page="Create" class="btn btn-primary">Vnos projekta</a>
|
||||
</div>
|
||||
</div>
|
||||
@Html.AntiForgeryToken()
|
||||
@section Scripts {
|
||||
<script>
|
||||
$('[data-toggle="tooltip"]').tooltip({container: 'table'});
|
||||
|
||||
function deleteProject(element) {
|
||||
let row = $(element).parent().parent();
|
||||
let idProject = $(row).attr('data-idproject');
|
||||
let title = $(row).attr('data-title');
|
||||
|
||||
Swal.fire({
|
||||
title: `Izbrišem projekt ${title}?`,
|
||||
text: "Tega dejanja ni možno razveljaviti!",
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: '#3085d6',
|
||||
cancelButtonColor: '#d33',
|
||||
confirmButtonText: 'Da, izbriši!',
|
||||
cancelButtonText: 'Prekliči!'
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
$.blockUI();
|
||||
$.ajax({
|
||||
type: "DELETE",
|
||||
beforeSend: function (xhr) {
|
||||
xhr.setRequestHeader("XSRF-TOKEN",
|
||||
$('input:hidden[name="__RequestVerificationToken"]').val());
|
||||
},
|
||||
url: "/Projects/Index/?handler=Project",
|
||||
data: {
|
||||
idProject
|
||||
},
|
||||
success: function (data) {
|
||||
$.unblockUI();
|
||||
if (data.successful) {
|
||||
$(row).remove();
|
||||
} else {
|
||||
console.log(data);
|
||||
Swal.fire('Napaka pri brisanju projekta',
|
||||
data.error,
|
||||
'error');
|
||||
}
|
||||
|
||||
},
|
||||
error: function (xhr, ajaxOptions, thrownError) {
|
||||
console.log(xhr);
|
||||
alert(xhr.responseText);
|
||||
$.unblockUI();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function copyProject(element) {
|
||||
let idProject = $(element).attr('data-idproject');
|
||||
|
||||
Swal.fire({
|
||||
title: `Kopiram projekt?`,
|
||||
text: "Tega dejanja ni možno razveljaviti!",
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: '#3085d6',
|
||||
cancelButtonColor: '#d33',
|
||||
confirmButtonText: 'Da, kopiraj!',
|
||||
cancelButtonText: 'Prekliči!'
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
$.blockUI();
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
beforeSend: function (xhr) {
|
||||
xhr.setRequestHeader("XSRF-TOKEN",
|
||||
$('input:hidden[name="__RequestVerificationToken"]').val());
|
||||
},
|
||||
url: "/Projects/Index/?handler=CopyProject",
|
||||
data: {
|
||||
idProject
|
||||
},
|
||||
success: function (data) {
|
||||
$.unblockUI();
|
||||
if (data.successful) {
|
||||
location.reload();
|
||||
} else {
|
||||
Swal.fire('Napaka pri kopiranju projekta',
|
||||
data.error,
|
||||
'error');
|
||||
}
|
||||
|
||||
},
|
||||
error: function (xhr, ajaxOptions, thrownError) {
|
||||
console.log(xhr);
|
||||
alert(xhr.responseText);
|
||||
$.unblockUI();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
}
|
||||
252
EveryThing/Pages/Projects/Index.cshtml.cs
Normal file
252
EveryThing/Pages/Projects/Index.cshtml.cs
Normal file
@@ -0,0 +1,252 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using EveryThing.Data;
|
||||
using EveryThing.Models;
|
||||
using EveryThing.Models.Project;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using DocumentFormat.OpenXml.Bibliography;
|
||||
|
||||
namespace EveryThing.Pages.Projects
|
||||
{
|
||||
[Authorize(Roles = "Administrator,ProjecThingUser")]
|
||||
public class IndexModel : PageModel
|
||||
{
|
||||
private readonly ApplicationDbContext _context;
|
||||
private readonly UserManager<IdentityApplicationUser> _userManager;
|
||||
|
||||
public IndexModel(ApplicationDbContext context, UserManager<IdentityApplicationUser> userManager)
|
||||
{
|
||||
_context = context;
|
||||
_userManager = userManager;
|
||||
}
|
||||
|
||||
public IList<Project> Project { get;set; }
|
||||
public string Year { get; set; }
|
||||
|
||||
|
||||
public async Task OnGetAsync(string searchString, string finishedProjects, string openProjects, string offerProjects, string inProductionProjects, string year)
|
||||
{
|
||||
ViewData["SearchString"] = searchString;
|
||||
ViewData["FinishedProjects"] = finishedProjects == "on" ? "checked" : "";
|
||||
ViewData["OpenProjects"] = openProjects == "on" ? "checked" : "";
|
||||
ViewData["OffersProjects"] = offerProjects == "on" ? "checked" : "";
|
||||
ViewData["InProductionProjects"] = inProductionProjects == "on" ? "checked" : "";
|
||||
|
||||
Year = year;
|
||||
Year ??= DateTime.Now.Year.ToString();
|
||||
|
||||
ViewData["Years"] = new SelectList(Enumerable.Range(2022, (DateTime.Now.Year - 2022) + 2));
|
||||
|
||||
Project = new List<Project>();
|
||||
|
||||
await _context.Projects
|
||||
.Include(p => p.Company)
|
||||
.Include(p => p.Partner)
|
||||
.Include(x => x.ProjectProjectPart)
|
||||
.ThenInclude(x => x.ProjectPartProjectPartItem)
|
||||
.Where(x => x.ProjectYear == Convert.ToInt32(Year))
|
||||
.ForEachAsync(x =>
|
||||
{
|
||||
x.FirstDeliveryDate = x.ProjectProjectPart.Max(y => y.ProjectPartProjectPartItem
|
||||
.Where(a => a.Status == ProjectPartItemStatus.InProduction ||
|
||||
a.Status == ProjectPartItemStatus.Opened).Max(z => z.DeliveryDate)) == null
|
||||
? DateTime.MaxValue
|
||||
: x.ProjectProjectPart.Max(y =>
|
||||
y.ProjectPartProjectPartItem.Where(a =>
|
||||
a.Status == ProjectPartItemStatus.InProduction ||
|
||||
a.Status == ProjectPartItemStatus.Opened).Max(z => z.DeliveryDate));
|
||||
Project.Add(x);
|
||||
});
|
||||
|
||||
Project = Project.OrderBy(x => (int)x.Status)
|
||||
.ThenBy(x => x.FirstDeliveryDate)
|
||||
.ToList();
|
||||
|
||||
var listStatus = new List<ProjectStatus>();
|
||||
// Active companies
|
||||
if (!string.IsNullOrEmpty(finishedProjects)
|
||||
&& finishedProjects == "on")
|
||||
{
|
||||
listStatus.Add(ProjectStatus.Finished);
|
||||
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(openProjects)
|
||||
&& openProjects == "on")
|
||||
{
|
||||
listStatus.Add(ProjectStatus.Opened);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(offerProjects)
|
||||
&& offerProjects == "on")
|
||||
{
|
||||
listStatus.Add(ProjectStatus.Offer);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(inProductionProjects)
|
||||
&& inProductionProjects == "on")
|
||||
{
|
||||
listStatus.Add(ProjectStatus.InProduction);
|
||||
}
|
||||
|
||||
if (listStatus.Count > 0)
|
||||
{
|
||||
Project = Project.Where(s => listStatus.Contains(s.Status)).ToList();
|
||||
}
|
||||
|
||||
// Search string
|
||||
if (!string.IsNullOrEmpty(searchString))
|
||||
{
|
||||
Project = Project
|
||||
.Where(s => s.Title.Contains(searchString, StringComparison.InvariantCultureIgnoreCase)
|
||||
|| s.Partner.Title.Contains(searchString, StringComparison.InvariantCultureIgnoreCase)
|
||||
|| (s.Description != null && s.Description.Contains(searchString, StringComparison.InvariantCultureIgnoreCase))
|
||||
|| s.ProjectNumberFormatted.Contains(searchString, StringComparison.CurrentCultureIgnoreCase))
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public IActionResult OnDeleteProject(int idProject)
|
||||
{
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
bool successful = true;
|
||||
string error = "";
|
||||
|
||||
var project = _context.Projects
|
||||
.Include(x => x.ProjectProjectPart)
|
||||
.ThenInclude(x => x.ProjectPartProjectPartItem)
|
||||
.ThenInclude(x => x.InvoiceItem)
|
||||
.Where(x => x.IdCompanyFk == user.IdCompanyFk)
|
||||
.FirstOrDefault(x => x.IdProject == idProject);
|
||||
|
||||
|
||||
if (project == null)
|
||||
{
|
||||
successful = false;
|
||||
error = $"Project with ID: {idProject} not found";
|
||||
}
|
||||
else if (project.ProjectProjectPart.Any(x => x.ProjectPartProjectPartItem.Any(x => x.InvoiceItem.Count > 0)))
|
||||
{
|
||||
successful = false;
|
||||
error = $"Projekt ima vezane dokumente fakturiranja!\nBrisanje ni možno!";
|
||||
}
|
||||
else
|
||||
{
|
||||
var projectParts = _context.ProjectParts.Where(x => x.IdProjectFk == idProject).ToList();
|
||||
|
||||
for (int i = 0; i < projectParts.Count(); i++)
|
||||
{
|
||||
var part = projectParts[i];
|
||||
var projectPartItems = _context.ProjectPartItems.Where(x => x.IdProjectPartFk == part.IdProjectPart).ToList();
|
||||
|
||||
for (int j = 0; j < projectPartItems.Count; j++)
|
||||
{
|
||||
_context.ProjectPartItems.Remove(projectPartItems[j]);
|
||||
}
|
||||
|
||||
_context.ProjectParts.Remove(part);
|
||||
}
|
||||
_context.Projects.Remove(project);
|
||||
_context.SaveChanges();
|
||||
}
|
||||
|
||||
return new JsonResult(new { idProject = idProject, error = error, successful = successful });
|
||||
}
|
||||
|
||||
public IActionResult OnPostCopyProject(int idProject)
|
||||
{
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
bool successful = true;
|
||||
string error = "";
|
||||
|
||||
var project = _context.Projects
|
||||
.FirstOrDefault(x => x.IdCompanyFk == user.IdCompanyFk && x.IdProject == idProject);
|
||||
|
||||
if (project != null)
|
||||
{
|
||||
var newProject = new Project
|
||||
{
|
||||
IdCompanyFk = user.IdCompanyFk,
|
||||
Status = ProjectStatus.Opened,
|
||||
BuyersOrderNumber = project.BuyersOrderNumber,
|
||||
Description = project.Description,
|
||||
IdPartnerFk = project.IdPartnerFk,
|
||||
ProjectYear = DateTime.Now.Year,
|
||||
ProjectNumber = _context.Projects.Where(x => x.IdCompanyFk == user.IdCompanyFk && x.ProjectYear == DateTime.Now.Year).Max(x => x.ProjectNumber) + 1,
|
||||
Title = project.Title,
|
||||
};
|
||||
|
||||
if (newProject.ProjectNumber <= 0)
|
||||
newProject.ProjectNumber = 1;
|
||||
|
||||
_context.Projects.Add(newProject);
|
||||
|
||||
_context.SaveChanges();
|
||||
|
||||
var projectParts = _context.ProjectParts.Where(x => x.IdProjectFk == project.IdProject)
|
||||
.OrderBy(x => x.ProjectPartNumber).ThenBy(x => x.IdProjectFk).ToList();
|
||||
|
||||
var projectPartCounter = 1;
|
||||
foreach (var projectPart in projectParts)
|
||||
{
|
||||
var newProjectPart = new ProjectPart
|
||||
{
|
||||
IdProjectFk = newProject.IdProject,
|
||||
Description = projectPart.Description,
|
||||
//FinishedDate = item.FinishedDate,
|
||||
PathOfPlans = projectPart.PathOfPlans,
|
||||
ShippedDate = projectPart.ShippedDate,
|
||||
Status = projectPart.Status,
|
||||
Title = projectPart.Title,
|
||||
ProjectPartNumber = projectPartCounter
|
||||
};
|
||||
|
||||
_context.ProjectParts.Add(newProjectPart);
|
||||
|
||||
_context.SaveChanges();
|
||||
|
||||
var projectPartItemCounter = 1;
|
||||
foreach (var projectPartItem in _context.ProjectPartItems.Where(x => x.IdProjectPartFk == projectPart.IdProjectPart).ToList())
|
||||
{
|
||||
var newProjectPartItem = new ProjectPartItem
|
||||
{
|
||||
IdItemFk = projectPartItem.IdItemFk,
|
||||
IdMaterialFk = projectPartItem.IdMaterialFk,
|
||||
IdMaterialSupplierFk = projectPartItem.IdMaterialSupplierFk,
|
||||
IdProjectPartFk = newProjectPart.IdProjectPart,
|
||||
MaterialDimensions = projectPartItem.MaterialDimensions,
|
||||
MaterialPrice = projectPartItem.MaterialPrice,
|
||||
NumberOfItems = projectPartItem.NumberOfItems,
|
||||
NumberOfItemsFinished = projectPartItem.NumberOfItemsFinished,
|
||||
WorkPrice = projectPartItem.WorkPrice,
|
||||
NumberOfSets = projectPartItem.NumberOfSets,
|
||||
Status = ProjectPartItemStatus.Opened,
|
||||
SellingPrice = projectPartItem.SellingPrice,
|
||||
ProjectPartItemNumber = projectPartItemCounter
|
||||
};
|
||||
_context.ProjectPartItems.Add(newProjectPartItem);
|
||||
|
||||
projectPartItemCounter++;
|
||||
}
|
||||
_context.SaveChanges();
|
||||
|
||||
projectPartCounter++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
successful = false;
|
||||
error = $"Project with ID: {idProject} not found";
|
||||
}
|
||||
|
||||
return new JsonResult(new { error, successful });
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user