prvi
This commit is contained in:
63
EveryThing/Pages/CodeTableItems/AddEditItemModal.cshtml
Normal file
63
EveryThing/Pages/CodeTableItems/AddEditItemModal.cshtml
Normal file
@@ -0,0 +1,63 @@
|
||||
@model EveryThing.Pages.CodeTableItems.IndexModel.AddEditCodeTableItem
|
||||
|
||||
<div class="modal" tabindex="-1" role="dialog" id="divModalAddEditCodeTableItem">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="modalAddEditCodeTableItemTitle">Dodajanje novega artikla</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<input id="inpModalAddEditCodeTableItemIdCodeTableItem" type="hidden" asp-for="@Model.IdCodeTableItem" />
|
||||
<input id="inpModalAddEditCodeTableItemEdit" type="hidden" asp-for="@Model.Edit" />
|
||||
<div class="form-group">
|
||||
<label asp-for="Item.Title" class="control-label"></label>
|
||||
<input id="inpModalAddEditCodeTableItemTitle" asp-for="Item.Title" class="form-control" />
|
||||
<span asp-validation-for="Item.Title" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Item.Description" class="control-label"></label>
|
||||
<input id="inpModalAddEditCodeTableItemDescription" asp-for="Item.Description" class="form-control" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Item.CodeTableItemType" class="control-label"></label>
|
||||
<select id="selModalAddEditCodeTableItemType" asp-for="Item.CodeTableItemType" asp-items="Html.GetEnumSelectList<EveryThing.Models.CodeTable.CodeTableItemType>()" class="form-control" style="width: 100%">
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group form-check">
|
||||
<label class="form-check-label">
|
||||
<input id="inpModalAddEditCodeTableItemActive" class="form-check-input" asp-for="Item.Active" /> @Html.DisplayNameFor(model => model.Item.Active)
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
Cena delo: <b>@Model.WorkPrice €</b>
|
||||
<br />Cena material: <b>@Model.WorkPrice €</b>
|
||||
<br />Cena skupaj: <b>@Model.TotalPrice €</b>
|
||||
<br />Prodajna cena: <b>@Model.SellingPrice €</b>
|
||||
<br />Razlika: <b>@Model.DifferenceInPricePercentage %</b>
|
||||
</div>
|
||||
@if (Model.Files != null && Model.Files.Count > 0)
|
||||
{
|
||||
<div class="form-group">
|
||||
@foreach (var file in Model.Files)
|
||||
{
|
||||
<div data-idfile="@file.IdFile">
|
||||
<a download href="@Url.Page("/Files/Upload", "DownloadFile", new { idFile = file.IdFile, idReferenceFk = file.IdReferenceFk, fileTypeInt = (int)file.FileType})" class="btn btn-xs icon-btn btn-outline-secondary borderless" data-toggle="tooltip" data-placement="top" title="Prenos" data-state="secondary"><i class="fas fa-download"></i></a>
|
||||
@Html.DisplayFor(modelItem => file.Title)
|
||||
<a class="btn btn-xs icon-btn btn-outline-danger borderless" data-state="danger" href='javascript:;' onclick="codeTableItemDeleteFile(this)"><i class="fas fa-times"></i></a>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a id="btnModalAddEditCodeTableItemAddFile" asp-page="/Files/Upload" asp-route-idReferenceFk="@Model.IdCodeTableItem" asp-route-fileType="@Models.FileType.CodeTableItem" class="btn btn-primary pull-right">Priloži datoteko</a>
|
||||
<button id="btnModalAddEditCodeTableItemConfirm" type="button" class="btn btn-primary">Shrani</button>
|
||||
<button id="btnModalAddEditCodeTableItemCancel" type="button" class="btn btn-secondary">Prekliči</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
126
EveryThing/Pages/CodeTableItems/Index.cshtml
Normal file
126
EveryThing/Pages/CodeTableItems/Index.cshtml
Normal file
@@ -0,0 +1,126 @@
|
||||
@page
|
||||
@model EveryThing.Pages.CodeTableItems.IndexModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Index";
|
||||
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">Artikli /</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">
|
||||
<button id="btnSubmit" type="submit" class="btn btn-secondary" aria-label="Osveži" title="Osveži">
|
||||
<i class="opacity-75 ion ion-md-refresh"></i>
|
||||
</button>
|
||||
<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="finishedProjects" @ViewData["FinishedProjects"]> <span>Aktivni artikli</span>
|
||||
</label>
|
||||
</div>*@
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
|
||||
<h6 class="card-header">
|
||||
Seznam artiklov
|
||||
</h6>
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Item[0].Title)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Item[0].Description)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Item[0].CodeTableItemType)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Item[0].Active)
|
||||
</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in Model.Item)
|
||||
{
|
||||
<tr data-idCodeTableItem="@item.IdItem">
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Title)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Description)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.CodeTableItemType)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Active)
|
||||
</td>
|
||||
<td class="text-right">
|
||||
<a class="btn btn-xs icon-btn btn-outline-secondary borderless" href="javascript:;" onclick="editCodeTableItem(this);" data-toggle="tooltip" data-placement="top" title="Urejanje" data-state="secondary"><i class="fas fa-pencil-alt"></i></a>
|
||||
<a class="btn btn-xs icon-btn btn-outline-danger borderless" data-state="danger" href='javascript:;' onclick="deleteCodeTableItem(this)"><i class="fas fa-times"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="card-footer py-3 text-right">
|
||||
<button type="button" class="btn btn-primary" onclick="addNewCodeTableItem();" >Vnos artikla</button>
|
||||
</div>
|
||||
<div id="divModalCodetableItemAddEditPlaceholder"></div>
|
||||
</div>
|
||||
@Html.AntiForgeryToken()
|
||||
|
||||
@section Scripts {
|
||||
|
||||
<script src="~/js/codeTableItemHelper.js?v=3" asp-append-version="true"></script>
|
||||
<script src="~/js/fileHelper.js?v=1" asp-append-version="true"></script>
|
||||
|
||||
<script>
|
||||
$('[data-toggle="tooltip"]').tooltip({container: 'table'});
|
||||
|
||||
function addNewCodeTableItem() {
|
||||
codeTableItemAddEdit('#divModalCodetableItemAddEditPlaceholder', false, null, (idCodeTableItem) => {
|
||||
document.getElementById('btnSubmit').click();
|
||||
});
|
||||
}
|
||||
|
||||
function editCodeTableItem(element) {
|
||||
let idCodeTableItem = parseInt($(element).parent().parent().attr('data-idCodeTableItem'));
|
||||
|
||||
codeTableItemAddEdit('#divModalCodetableItemAddEditPlaceholder', true, idCodeTableItem, (idCodeTableItem) => {
|
||||
document.getElementById('btnSubmit').click();
|
||||
});
|
||||
}
|
||||
|
||||
function deleteCodeTableItem(element) {
|
||||
let row = $(element).parent().parent();
|
||||
let idCodeTableItem = parseInt(row.attr('data-idCodeTableItem'));
|
||||
|
||||
codeTableItemDelete(idCodeTableItem, (idCodeTableItem) => {
|
||||
row.remove();
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
||||
}
|
||||
228
EveryThing/Pages/CodeTableItems/Index.cshtml.cs
Normal file
228
EveryThing/Pages/CodeTableItems/Index.cshtml.cs
Normal file
@@ -0,0 +1,228 @@
|
||||
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.CodeTable;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.VisualStudio.Debugger.Contracts;
|
||||
using System.Globalization;
|
||||
|
||||
namespace EveryThing.Pages.CodeTableItems
|
||||
{
|
||||
[Authorize(Roles = "Administrator,InvoicingUser,ProjecThingUser")]
|
||||
public class IndexModel : PageModel
|
||||
{
|
||||
public class AddEditCodeTableItem
|
||||
{
|
||||
public CodeTableItem Item { get; set; }
|
||||
public bool Edit { get; set; }
|
||||
public int IdCodeTableItem { get; set; }
|
||||
public IList<File> Files { get; set; }
|
||||
public string MaterialPrice { get; set; }
|
||||
public string WorkPrice { get; set; }
|
||||
public string TotalPrice { get; set; }
|
||||
public string SellingPrice { get; set; }
|
||||
public string DifferenceInPricePercentage { get; set; }
|
||||
|
||||
}
|
||||
|
||||
private readonly ApplicationDbContext _context;
|
||||
private readonly UserManager<IdentityApplicationUser> _userManager;
|
||||
private readonly SignInManager<IdentityApplicationUser> _loginManager;
|
||||
private readonly RoleManager<IdentityApplicationRole> _roleManager;
|
||||
|
||||
public IndexModel(ApplicationDbContext context, UserManager<IdentityApplicationUser> userManager, SignInManager<IdentityApplicationUser> loginManager, RoleManager<IdentityApplicationRole> roleManager)
|
||||
{
|
||||
_context = context;
|
||||
_userManager = userManager;
|
||||
_loginManager = loginManager;
|
||||
_roleManager = roleManager;
|
||||
}
|
||||
|
||||
public IList<CodeTableItem> Item { get;set; }
|
||||
|
||||
public async Task OnGetAsync(string searchString)
|
||||
{
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
|
||||
ViewData["SearchString"] = searchString;
|
||||
|
||||
Item = await _context.CodeTableItems
|
||||
.Where(x => x.IdCompanyFk == user.IdCompanyFk)
|
||||
.Include(j => j.Company).ToListAsync();
|
||||
|
||||
if (!string.IsNullOrEmpty(searchString))
|
||||
{
|
||||
Item = Item.Where(s => s.Title.Contains(searchString, StringComparison.InvariantCultureIgnoreCase)
|
||||
|| (s.Description != null && s.Description.Contains(searchString, StringComparison.InvariantCultureIgnoreCase))).ToList();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public IActionResult OnGetCodeTableItemModal(bool edit, int idCodeTableItem, int codeTableItemType)
|
||||
{
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
|
||||
CodeTableItem item = null;
|
||||
IList<File> files = null;
|
||||
var materialPrice = 0d;
|
||||
var workPrice = 0d;
|
||||
var sellingPrice = 0d;
|
||||
var differenceInPricePercentage = 0d;
|
||||
|
||||
if (edit)
|
||||
{
|
||||
item = _context.CodeTableItems
|
||||
.Where(x => x.IdCompanyFk == user.IdCompanyFk)
|
||||
.FirstOrDefault(x => x.IdItem == idCodeTableItem);
|
||||
|
||||
files = _context.Files
|
||||
.Where(x => x.IdCompanyFk == user.IdCompanyFk
|
||||
&& x.IdReferenceFk == item.IdItem
|
||||
&& x.FileType == FileType.CodeTableItem)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
if (item == null)
|
||||
{
|
||||
item = new CodeTableItem();
|
||||
item.Active = true;
|
||||
item.CodeTableItemType = (CodeTableItemType)codeTableItemType;
|
||||
}
|
||||
else
|
||||
{
|
||||
var projectPartItem = _context.ProjectPartItems
|
||||
.OrderByDescending(x => x.DateModified)
|
||||
.ThenByDescending(x => x.IdProjectPartItem)
|
||||
.FirstOrDefault(x => x.IdItemFk == item.IdItem);
|
||||
|
||||
if (projectPartItem != null)
|
||||
{
|
||||
materialPrice = projectPartItem.MaterialPrice;
|
||||
workPrice = projectPartItem.WorkPrice;
|
||||
sellingPrice = projectPartItem.SellingPrice;
|
||||
differenceInPricePercentage = projectPartItem.DifferenceInPricePercentage;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return Partial("AddEditItemModal", new AddEditCodeTableItem
|
||||
{
|
||||
Item = item,
|
||||
Edit = edit,
|
||||
IdCodeTableItem = idCodeTableItem,
|
||||
Files = files,
|
||||
MaterialPrice = materialPrice.ToString("#,###,##0.00", new CultureInfo("sl-SI")),
|
||||
SellingPrice = sellingPrice.ToString("#,###,##0.00", new CultureInfo("sl-SI")),
|
||||
TotalPrice = (materialPrice + workPrice).ToString("#,###,##0.00", new CultureInfo("sl-SI")),
|
||||
WorkPrice = workPrice.ToString("#,###,##0.00", new CultureInfo("sl-SI")),
|
||||
DifferenceInPricePercentage = differenceInPricePercentage.ToString("#,###,##0.00", new CultureInfo("sl-SI"))
|
||||
});
|
||||
}
|
||||
|
||||
public IActionResult OnGetCodeTableItem(int idCodeTableItem)
|
||||
{
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
|
||||
bool successful = true;
|
||||
string error = "";
|
||||
bool itemInUse = false;
|
||||
|
||||
CodeTableItem item = _context.CodeTableItems
|
||||
.Where(x => x.IdCompanyFk == user.IdCompanyFk)
|
||||
.Include(x => x.ItemProjectPartItem)
|
||||
.Include(x => x.ItemProjectPartItemMaterial)
|
||||
.Include(x => x.InvoiceItem)
|
||||
.FirstOrDefault(x => x.IdItem == idCodeTableItem);
|
||||
|
||||
if (item == null)
|
||||
{
|
||||
successful = false;
|
||||
error = $"Codetable item with ID: {idCodeTableItem} not found";
|
||||
}
|
||||
else
|
||||
{
|
||||
itemInUse = item.ItemProjectPartItem.Count > 0 || item.ItemProjectPartItemMaterial.Count > 0 || item.InvoiceItem.Count > 0;
|
||||
//Cene se json zacikla neki IDK.
|
||||
item.ItemProjectPartItem = null;
|
||||
item.ItemProjectPartItemMaterial = null;
|
||||
item.InvoiceItem = null;
|
||||
}
|
||||
|
||||
return new JsonResult(new { item = item, error = error, successful = successful, itemInUse = itemInUse });
|
||||
}
|
||||
|
||||
public IActionResult OnPostCodeTableItem(string title, string description, bool active, bool edit, int idCodeTableItem, int codeTableItemType)
|
||||
{
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
bool successful = true;
|
||||
string error = "";
|
||||
if (edit)
|
||||
{
|
||||
var item = _context.CodeTableItems
|
||||
.Where(x => x.IdCompanyFk == user.IdCompanyFk)
|
||||
.FirstOrDefault(x => x.IdItem == idCodeTableItem);
|
||||
if (item != null)
|
||||
{
|
||||
item.Title = title;
|
||||
item.Description = description;
|
||||
item.Active = active;
|
||||
item.CodeTableItemType = (CodeTableItemType)codeTableItemType;
|
||||
_context.SaveChanges();
|
||||
}
|
||||
else
|
||||
{
|
||||
successful = false;
|
||||
error = $"Codetable item with ID: {idCodeTableItem} not found";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var item = new CodeTableItem
|
||||
{
|
||||
Title = title,
|
||||
Description = description,
|
||||
Active = active,
|
||||
IdCompanyFk = user.IdCompanyFk,
|
||||
CodeTableItemType = (CodeTableItemType)codeTableItemType
|
||||
};
|
||||
_context.CodeTableItems.Add(item);
|
||||
_context.SaveChanges();
|
||||
|
||||
idCodeTableItem = item.IdItem;
|
||||
}
|
||||
|
||||
return new JsonResult(new { idCodeTableItem = idCodeTableItem, error = error, successful = successful });
|
||||
}
|
||||
|
||||
public IActionResult OnDeleteCodeTableItem(int idCodeTableItem)
|
||||
{
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
bool successful = true;
|
||||
string error = "";
|
||||
|
||||
var item = _context.CodeTableItems
|
||||
.Where(x => x.IdCompanyFk == user.IdCompanyFk)
|
||||
.FirstOrDefault(x => x.IdItem == idCodeTableItem);
|
||||
if (item != null)
|
||||
{
|
||||
_context.CodeTableItems.Remove(item);
|
||||
_context.SaveChanges();
|
||||
}
|
||||
else
|
||||
{
|
||||
successful = false;
|
||||
error = $"Codetable item with ID: {idCodeTableItem} not found";
|
||||
}
|
||||
|
||||
return new JsonResult(new { idCodeTableItem = idCodeTableItem, error = error, successful = successful });
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user