- Dodati operacije na pozicijo dela projekta

- Dodatna tabela z operacijami in stanjem (končano/nekončano)
  - šifrant operacij - možnost določevanje privzetih operacij

- Opombe na pozicij dela projekta

- Pogled kooperacij na poziciji dela projekta
  - Izpisano številka kooperacije in kooperant
This commit is contained in:
2026-02-28 09:37:13 +01:00
parent 7d64e423c3
commit 9d0fb30bf0
15 changed files with 3774 additions and 56 deletions

View File

@@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -52,6 +52,8 @@ namespace EveryThing.Data
public DbSet<CodeTableItem> CodeTableItems { get; set; } public DbSet<CodeTableItem> CodeTableItems { get; set; }
public DbSet<Invoice> Invoices { get; set; } public DbSet<Invoice> Invoices { get; set; }
public DbSet<InvoiceItem> InvoiceItems { get; set; } public DbSet<InvoiceItem> InvoiceItems { get; set; }
public DbSet<CodeTableOperation> CodeTableOperations { get; set; }
public DbSet<ProjectPartItemOperation> ProjectPartItemOperations { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder)
{ {
@@ -125,6 +127,20 @@ namespace EveryThing.Data
modelBuilder.Entity<CodeTableItem>().HasMany(t => t.ItemProjectPartItemMaterial).WithOne(t => t.Material).OnDelete(DeleteBehavior.Restrict); modelBuilder.Entity<CodeTableItem>().HasMany(t => t.ItemProjectPartItemMaterial).WithOne(t => t.Material).OnDelete(DeleteBehavior.Restrict);
modelBuilder.Entity<Invoice>().HasMany(t => t.InvoiceInvoiceItem).WithOne(t => t.Invoice).OnDelete(DeleteBehavior.Restrict); modelBuilder.Entity<Invoice>().HasMany(t => t.InvoiceInvoiceItem).WithOne(t => t.Invoice).OnDelete(DeleteBehavior.Restrict);
modelBuilder.Entity<Project>().HasMany(t => t.Invoices).WithOne(t => t.Project).OnDelete(DeleteBehavior.Restrict); modelBuilder.Entity<Project>().HasMany(t => t.Invoices).WithOne(t => t.Project).OnDelete(DeleteBehavior.Restrict);
modelBuilder.Entity<ProjectPartItemOperation>()
.HasOne(t => t.Operation)
.WithMany(t => t.ProjectPartItemOperation)
.HasForeignKey(t => t.IdCodeTableOperationFk)
.OnDelete(DeleteBehavior.Restrict);
modelBuilder.Entity<ProjectPartItemOperation>()
.HasOne(t => t.ProjectPartItem)
.WithMany(t => t.ProjectPartItemOperation)
.HasForeignKey(t => t.IdProjectPartItemFk)
.OnDelete(DeleteBehavior.Restrict);
//modelBuilder.Entity<CodeTableOperation>().HasMany(t => t.ProjectPartItemOperations).WithMany(t => t.Operation).OnDelete(DeleteBehavior.Restrict);
} }
} }
} }

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,140 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace EveryThing.Migrations
{
public partial class _17 : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Invoices_Projects_ProjectIdProject",
table: "Invoices");
migrationBuilder.DropIndex(
name: "IX_Invoices_ProjectIdProject",
table: "Invoices");
migrationBuilder.DropColumn(
name: "ProjectIdProject",
table: "Invoices");
migrationBuilder.AddColumn<string>(
name: "Note",
table: "ProjectPartItems",
type: "longtext",
nullable: true)
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "CodeTableOperations",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Title = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
Default = table.Column<bool>(type: "tinyint(1)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_CodeTableOperations", x => x.Id);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "ProjectPartItemOperations",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
IdProjectPartItemFk = table.Column<int>(type: "int", nullable: false),
IdCodeTableOperationFk = table.Column<int>(type: "int", nullable: false),
Finished = table.Column<bool>(type: "tinyint(1)", nullable: false),
Order = table.Column<short>(type: "smallint", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ProjectPartItemOperations", x => x.Id);
table.ForeignKey(
name: "FK_ProjectPartItemOperations_CodeTableOperations_IdCodeTableOpe~",
column: x => x.IdCodeTableOperationFk,
principalTable: "CodeTableOperations",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_ProjectPartItemOperations_ProjectPartItems_IdProjectPartItem~",
column: x => x.IdProjectPartItemFk,
principalTable: "ProjectPartItems",
principalColumn: "IdProjectPartItem",
onDelete: ReferentialAction.Restrict);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateIndex(
name: "IX_Invoices_IdProjectFk",
table: "Invoices",
column: "IdProjectFk");
migrationBuilder.CreateIndex(
name: "IX_ProjectPartItemOperations_IdCodeTableOperationFk",
table: "ProjectPartItemOperations",
column: "IdCodeTableOperationFk");
migrationBuilder.CreateIndex(
name: "IX_ProjectPartItemOperations_IdProjectPartItemFk",
table: "ProjectPartItemOperations",
column: "IdProjectPartItemFk");
migrationBuilder.AddForeignKey(
name: "FK_Invoices_Projects_IdProjectFk",
table: "Invoices",
column: "IdProjectFk",
principalTable: "Projects",
principalColumn: "IdProject",
onDelete: ReferentialAction.Restrict);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Invoices_Projects_IdProjectFk",
table: "Invoices");
migrationBuilder.DropTable(
name: "ProjectPartItemOperations");
migrationBuilder.DropTable(
name: "CodeTableOperations");
migrationBuilder.DropIndex(
name: "IX_Invoices_IdProjectFk",
table: "Invoices");
migrationBuilder.DropColumn(
name: "Note",
table: "ProjectPartItems");
migrationBuilder.AddColumn<int>(
name: "ProjectIdProject",
table: "Invoices",
type: "int",
nullable: true);
migrationBuilder.CreateIndex(
name: "IX_Invoices_ProjectIdProject",
table: "Invoices",
column: "ProjectIdProject");
migrationBuilder.AddForeignKey(
name: "FK_Invoices_Projects_ProjectIdProject",
table: "Invoices",
column: "ProjectIdProject",
principalTable: "Projects",
principalColumn: "IdProject",
onDelete: ReferentialAction.Restrict);
}
}
}

View File

@@ -318,6 +318,24 @@ namespace EveryThing.Migrations
b.ToTable("CodeTableJobs"); b.ToTable("CodeTableJobs");
}); });
modelBuilder.Entity("EveryThing.Models.CodeTable.CodeTableOperation", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<bool>("Default")
.HasColumnType("tinyint(1)");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("longtext");
b.HasKey("Id");
b.ToTable("CodeTableOperations");
});
modelBuilder.Entity("EveryThing.Models.CodeTable.CodeTablePartner", b => modelBuilder.Entity("EveryThing.Models.CodeTable.CodeTablePartner", b =>
{ {
b.Property<int>("IdPartner") b.Property<int>("IdPartner")
@@ -713,9 +731,6 @@ namespace EveryThing.Migrations
b.Property<string>("PreText") b.Property<string>("PreText")
.HasColumnType("longtext"); .HasColumnType("longtext");
b.Property<int?>("ProjectIdProject")
.HasColumnType("int");
b.Property<int>("State") b.Property<int>("State")
.HasColumnType("int"); .HasColumnType("int");
@@ -728,7 +743,7 @@ namespace EveryThing.Migrations
b.HasIndex("IdPartnerFk"); b.HasIndex("IdPartnerFk");
b.HasIndex("ProjectIdProject"); b.HasIndex("IdProjectFk");
b.ToTable("Invoices"); b.ToTable("Invoices");
}); });
@@ -900,6 +915,9 @@ namespace EveryThing.Migrations
b.Property<float>("MaterialPrice") b.Property<float>("MaterialPrice")
.HasColumnType("float"); .HasColumnType("float");
b.Property<string>("Note")
.HasColumnType("longtext");
b.Property<float>("NumberOfItems") b.Property<float>("NumberOfItems")
.HasColumnType("float"); .HasColumnType("float");
@@ -937,6 +955,33 @@ namespace EveryThing.Migrations
b.ToTable("ProjectPartItems"); b.ToTable("ProjectPartItems");
}); });
modelBuilder.Entity("EveryThing.Models.Project.ProjectPartItemOperation", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<bool>("Finished")
.HasColumnType("tinyint(1)");
b.Property<int>("IdCodeTableOperationFk")
.HasColumnType("int");
b.Property<int>("IdProjectPartItemFk")
.HasColumnType("int");
b.Property<short>("Order")
.HasColumnType("smallint");
b.HasKey("Id");
b.HasIndex("IdCodeTableOperationFk");
b.HasIndex("IdProjectPartItemFk");
b.ToTable("ProjectPartItemOperations");
});
modelBuilder.Entity("EveryThing.Models.Transport.TransportLoadingOrder", b => modelBuilder.Entity("EveryThing.Models.Transport.TransportLoadingOrder", b =>
{ {
b.Property<int>("IdTransportLoadingOrder") b.Property<int>("IdTransportLoadingOrder")
@@ -1823,7 +1868,7 @@ namespace EveryThing.Migrations
b.HasOne("EveryThing.Models.Project.Project", "Project") b.HasOne("EveryThing.Models.Project.Project", "Project")
.WithMany("Invoices") .WithMany("Invoices")
.HasForeignKey("ProjectIdProject") .HasForeignKey("IdProjectFk")
.OnDelete(DeleteBehavior.Restrict); .OnDelete(DeleteBehavior.Restrict);
b.Navigation("Company"); b.Navigation("Company");
@@ -1925,6 +1970,25 @@ namespace EveryThing.Migrations
b.Navigation("ProjectPart"); b.Navigation("ProjectPart");
}); });
modelBuilder.Entity("EveryThing.Models.Project.ProjectPartItemOperation", b =>
{
b.HasOne("EveryThing.Models.CodeTable.CodeTableOperation", "Operation")
.WithMany("ProjectPartItemOperation")
.HasForeignKey("IdCodeTableOperationFk")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.HasOne("EveryThing.Models.Project.ProjectPartItem", "ProjectPartItem")
.WithMany("ProjectPartItemOperation")
.HasForeignKey("IdProjectPartItemFk")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("Operation");
b.Navigation("ProjectPartItem");
});
modelBuilder.Entity("EveryThing.Models.Transport.TransportLoadingOrder", b => modelBuilder.Entity("EveryThing.Models.Transport.TransportLoadingOrder", b =>
{ {
b.HasOne("EveryThing.Models.CodeTable.CodeTableCompany", "Company") b.HasOne("EveryThing.Models.CodeTable.CodeTableCompany", "Company")
@@ -2354,6 +2418,11 @@ namespace EveryThing.Migrations
b.Navigation("JobEmployee"); b.Navigation("JobEmployee");
}); });
modelBuilder.Entity("EveryThing.Models.CodeTable.CodeTableOperation", b =>
{
b.Navigation("ProjectPartItemOperation");
});
modelBuilder.Entity("EveryThing.Models.CodeTable.CodeTablePartner", b => modelBuilder.Entity("EveryThing.Models.CodeTable.CodeTablePartner", b =>
{ {
b.Navigation("Invoice"); b.Navigation("Invoice");
@@ -2394,6 +2463,8 @@ namespace EveryThing.Migrations
modelBuilder.Entity("EveryThing.Models.Project.ProjectPartItem", b => modelBuilder.Entity("EveryThing.Models.Project.ProjectPartItem", b =>
{ {
b.Navigation("InvoiceItem"); b.Navigation("InvoiceItem");
b.Navigation("ProjectPartItemOperation");
}); });
modelBuilder.Entity("EveryThing.Models.Transport.TransportLoadingOrder", b => modelBuilder.Entity("EveryThing.Models.Transport.TransportLoadingOrder", b =>

View File

@@ -0,0 +1,23 @@
using EveryThing.Models.Project;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace EveryThing.Models.CodeTable
{
public class CodeTableOperation
{
[Key]
public int Id { get; set; }
[Required]
[Display(Name = "Naziv")]
public string Title { get; set; }
[Display(Name = "Privzeta operacija")]
public bool Default { get; set; }
[InverseProperty("Operation")]
public virtual ICollection<ProjectPartItemOperation> ProjectPartItemOperation { get; set; }
}
}

View File

@@ -77,7 +77,7 @@ namespace EveryThing.Models.Invoice
[Display(Name = "Partner")] [Display(Name = "Partner")]
public int? IdPartnerFk { get; set; } public int? IdPartnerFk { get; set; }
[ForeignKey("Projekt")] [ForeignKey("Project")]
[Display(Name = "Projekt")] [Display(Name = "Projekt")]
public int? IdProjectFk { get; set; } public int? IdProjectFk { get; set; }
@@ -146,7 +146,7 @@ namespace EveryThing.Models.Invoice
public CodeTableCompany Company { get; set; } public CodeTableCompany Company { get; set; }
public CodeTablePartner Partner { get; set; } public CodeTablePartner Partner { get; set; }
public Project.Project Project{ get; set; } public Project.Project Project { get; set; }
// InvoicePart // InvoicePart
[InverseProperty("Invoice")] [InverseProperty("Invoice")]

View File

@@ -6,6 +6,7 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using EveryThing.Models.CodeTable; using EveryThing.Models.CodeTable;
using EveryThing.Models.Invoice; using EveryThing.Models.Invoice;
using JetBrains.Annotations;
namespace EveryThing.Models.Project namespace EveryThing.Models.Project
{ {
@@ -161,6 +162,9 @@ namespace EveryThing.Models.Project
[Display(Name = "Spremenjeno")] [Display(Name = "Spremenjeno")]
public DateTime DateModified { get; set; } = DateTime.Now; public DateTime DateModified { get; set; } = DateTime.Now;
[Display(Name = "Opomba")]
public string Note { get; set; } = "";
[Required] [Required]
public int ProjectPartItemNumber { get; set; } = 0; public int ProjectPartItemNumber { get; set; } = 0;
@@ -177,5 +181,8 @@ namespace EveryThing.Models.Project
//Invoice item //Invoice item
[InverseProperty("ProjectPartItem")] [InverseProperty("ProjectPartItem")]
public virtual ICollection<InvoiceItem> InvoiceItem { get; set; } public virtual ICollection<InvoiceItem> InvoiceItem { get; set; }
[InverseProperty("ProjectPartItem")]
public virtual ICollection<ProjectPartItemOperation> ProjectPartItemOperation { get; set; }
} }
} }

View File

@@ -0,0 +1,31 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using EveryThing.Models.CodeTable;
namespace EveryThing.Models.Project
{
public class ProjectPartItemOperation
{
[Key]
public int Id { get; set; }
[Required]
[ForeignKey("ProjectPartItem")]
public int IdProjectPartItemFk { get; set; }
[Required]
[ForeignKey("Operation")]
public int IdCodeTableOperationFk { get; set; }
[Required]
public bool Finished { get; set; }
[Required]
public short Order { get; set; }
public CodeTableOperation Operation { get; set; }
public ProjectPartItem ProjectPartItem { get; set; }
}
}

View File

@@ -0,0 +1,32 @@
@model EveryThing.Pages.CodeTableOperations.IndexModel.AddEditCodeTableOperation
<div class="modal" tabindex="-1" role="dialog" id="divModalAddEditCodeTableOperation">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="modalAddEditCodeTableOperationTitle">Dodajanje nove operacije</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<input id="inpModalAddEditCodeTableOperationIdCodeTableOperation" type="hidden" asp-for="@Model.IdCodeTableOperation" />
<input id="inpModalAddEditCodeTableOperationEdit" type="hidden" asp-for="@Model.Edit" />
<div class="form-group">
<label asp-for="Operation.Title" class="control-label"></label>
<input id="inpModalAddEditCodeTableOperationTitle" asp-for="Operation.Title" class="form-control" />
<span asp-validation-for="Operation.Title" class="text-danger"></span>
</div>
<div class="form-group form-check">
<label class="form-check-label">
<input id="inpModalAddEditCodeTableOperationDefault" class="form-check-input" asp-for="Operation.Default" /> @Html.DisplayNameFor(model => model.Operation.Default)
</label>
</div>
</div>
<div class="modal-footer">
<button id="btnModalAddEditCodeTableOperationConfirm" type="button" class="btn btn-primary">Shrani</button>
<button id="btnModalAddEditCodeTableOperationCancel" type="button" class="btn btn-secondary">Prekliči</button>
</div>
</div>
</div>
</div>

View File

@@ -0,0 +1,112 @@
@page
@model EveryThing.Pages.CodeTableOperations.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">Operacije /</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 operacij
</h6>
<table class="table">
<thead>
<tr>
<th class="w-100">
@Html.DisplayNameFor(model => model.Operation[0].Title)
</th>
<th class="text-right" style="white-space: nowrap; width: 1%;">
@Html.DisplayNameFor(model => model.Operation[0].Default)
</th>
<th class="text-right" style="white-space: nowrap; width: 1%;"></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.Operation)
{
<tr data-idCodeTableOperation="@item.Id">
<td>
@Html.DisplayFor(modelItem => item.Title)
</td>
<td class="text-right" style="white-space: nowrap; width: 1%;">
@Html.DisplayFor(modelItem => item.Default)
</td>
<td class="text-right" style="white-space: nowrap; width: 1%;">
<a class="btn btn-xs icon-btn btn-outline-secondary borderless" href="javascript:;" onclick="editCodeTableOperation(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="deleteCodeTableOperation(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="addNewCodeTableOperation();" >Vnos operacije</button>
</div>
<div id="divModalCodeTableOperationAddEditPlaceholder"></div>
</div>
@Html.AntiForgeryToken()
@section Scripts {
<script src="~/js/codeTableOperationHelper.js" asp-append-version="true"></script>
<script>
$('[data-toggle="tooltip"]').tooltip({container: 'table'});
function addNewCodeTableOperation() {
codeTableOperationAddEdit('#divModalCodeTableOperationAddEditPlaceholder', false, null, (idCodeTableOperation) => {
document.getElementById('btnSubmit').click();
});
}
function editCodeTableOperation(element) {
let idCodeTableOperation = parseInt($(element).parent().parent().attr('data-idCodeTableOperation'));
codeTableOperationAddEdit('#divModalCodeTableOperationAddEditPlaceholder', true, idCodeTableOperation, (idCodeTableOperation) => {
document.getElementById('btnSubmit').click();
});
}
function deleteCodeTableOperation(element) {
let row = $(element).parent().parent();
let idCodeTableOperation = parseInt(row.attr('data-idCodeTableOperation'));
codeTableOperationDelete(idCodeTableOperation, (idCodeTableOperation) => {
row.remove();
});
}
</script>
}

View File

@@ -0,0 +1,168 @@
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.CodeTableOperations
{
[Authorize(Roles = "Administrator,InvoicingUser,ProjecThingUser")]
public class IndexModel : PageModel
{
public class AddEditCodeTableOperation
{
public CodeTableOperation Operation { get; set; }
public bool Edit { get; set; }
public int IdCodeTableOperation { 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<CodeTableOperation> Operation { get; set; }
public async Task OnGetAsync(string searchString)
{
var user = _userManager.GetUserAsync(User).Result;
ViewData["SearchString"] = searchString ?? "";
var search = !string.IsNullOrEmpty(searchString);
var query = _context.CodeTableOperations.AsQueryable();
if (search)
{
query = query.Where(x => EF.Functions.Like(x.Title, $"%{searchString}%"));
}
Operation = await query
.OrderByDescending(x => x.Id)
.Take(100)
.ToListAsync();
}
public IActionResult OnGetCodeTableOperationModal(bool edit, int idCodeTableOperation)
{
CodeTableOperation operation = null;
if (edit)
{
operation = _context.CodeTableOperations
.FirstOrDefault(x => x.Id == idCodeTableOperation);
}
operation ??= new CodeTableOperation();
return Partial("AddEditOperationModal", new AddEditCodeTableOperation
{
Operation = operation,
Edit = edit,
IdCodeTableOperation = idCodeTableOperation
});
}
public IActionResult OnPostCodeTableOperation(string title, bool defaultValue, bool edit, int idCodeTableOperation)
{
var successful = true;
var error = "";
if (edit)
{
var operation = _context.CodeTableOperations
.FirstOrDefault(x => x.Id == idCodeTableOperation);
if (operation != null)
{
operation.Title = title;
operation.Default = defaultValue;
_context.SaveChanges();
}
else
{
successful = false;
error = $"Code-table operation with ID: {idCodeTableOperation} not found";
}
}
else
{
var operation = new CodeTableOperation
{
Title = title,
Default = defaultValue
};
_context.CodeTableOperations.Add(operation);
_context.SaveChanges();
idCodeTableOperation = operation.Id;
}
return new JsonResult(new { idCodeTableOperation, error, successful });
}
public IActionResult OnGetCodeTableOperation(int idCodeTableOperation)
{
var successful = true;
var error = "";
var inUse = false;
var operation = _context.CodeTableOperations
.Include(x => x.ProjectPartItemOperation)
.FirstOrDefault(x => x.Id == idCodeTableOperation);
if (operation == null)
{
successful = false;
error = $"Code-table operation with ID: {idCodeTableOperation} not found";
}
else
{
inUse = operation.ProjectPartItemOperation != null && operation.ProjectPartItemOperation.Count > 0;
operation.ProjectPartItemOperation = null;
}
return new JsonResult(new { operation, error, successful, inUse });
}
public IActionResult OnDeleteCodeTableOperation(int idCodeTableOperation)
{
var successful = true;
var error = "";
var operation = _context.CodeTableOperations
.FirstOrDefault(x => x.Id == idCodeTableOperation);
if (operation != null)
{
_context.CodeTableOperations.Remove(operation);
_context.SaveChanges();
}
else
{
successful = false;
error = $"Code-table operation with ID: {idCodeTableOperation} not found";
}
return new JsonResult(new { idCodeTableOperation, error, successful });
}
}
}

View File

@@ -74,50 +74,12 @@
<a asp-page="/Invoices/Index" asp-route-type="4" class="sidenav-link"><i class="sidenav-icon fas fa-hands-helping"></i><div>Kooperacije </div></a> <a asp-page="/Invoices/Index" asp-route-type="4" class="sidenav-link"><i class="sidenav-icon fas fa-hands-helping"></i><div>Kooperacije </div></a>
</li> </li>
} }
@*<li class="sidenav-item">
<a asp-page="/Index" class="sidenav-link"><i class="sidenav-icon fas fa-ruler"></i><div>Planiranje</div></a>
</li>
<li class="sidenav-item">
<a asp-page="/Index" class="sidenav-link"><i class="sidenav-icon fas fa-dolly"></i><div>Prevoznice</div></a>
</li>*@
@*<li class="sidenav-divider mb-1"></li>
<li class="sidenav-header small font-weight-semibold">VOZNI PARK</li>
<li class="sidenav-item">
<a asp-page="/Index" class="sidenav-link"><i class="sidenav-icon fas fa-wrench"></i><div>Delovni nalogi</div></a>
</li>
<li class="sidenav-item">
<a asp-page="/Index" class="sidenav-link"><i class="sidenav-icon fas fa-cogs"></i><div>Servisi</div></a>
</li>
<li class="sidenav-item">
<a asp-page="/Index" class="sidenav-link"><i class="sidenav-icon fas fa-tasks"></i><div>Pregledi</div></a>
</li>
<li class="sidenav-item@(currentPage.StartsWith("/Management/Issues/") ? " active" : "")">
<a asp-page="/Management/Issues/Index" class="sidenav-link"><i class="sidenav-icon fas fa-exclamation-triangle"></i><div>Napake</div></a>
</li>
<li class="sidenav-item@(currentPage.StartsWith("/Vehicle/VehicleFueling/") ? " active" : "")">
<a asp-page="/Vehicle/VehicleFueling/Index" class="sidenav-link"><i class="sidenav-icon fas fa-gas-pump"></i><div>Gorivo</div></a>
</li>*@
@if (User.IsInRole("Administrator") || User.IsInRole("ProjecThingUser") || User.IsInRole("InvoicingUser") || User.IsInRole("TransportThingUser")) @if (User.IsInRole("Administrator") || User.IsInRole("ProjecThingUser") || User.IsInRole("InvoicingUser") || User.IsInRole("TransportThingUser"))
{ {
<li class="sidenav-divider mb-1"></li> <li class="sidenav-divider mb-1"></li>
<li class="sidenav-header small font-weight-semibold">ŠIFRANTI</li> <li class="sidenav-header small font-weight-semibold">ŠIFRANTI</li>
@*<li class="sidenav-item@(currentPage.StartsWith("/CodeTableEmployees/") ? " active" : "")">
<a asp-page="/CodeTableEmployees/Index" class="sidenav-link"><i class="sidenav-icon fas fa-users"></i><div>Zaposleni</div></a>
</li>*@
@*<li class="sidenav-item@(currentPage.StartsWith("/CodeTables/Vehicles/") ? " active" : "")">
<a asp-page="/Employees/Index" class="sidenav-link"><i class="sidenav-icon fas fa-truck"></i><div>Vozni park</div></a>
</li>*@
<li class="sidenav-item@(currentPage.StartsWith("/CodeTablePartners/") ? " active" : "")"> <li class="sidenav-item@(currentPage.StartsWith("/CodeTablePartners/") ? " active" : "")">
<a asp-page="/CodeTablePartners/Index" class="sidenav-link"><i class="sidenav-icon fas fa-handshake"></i><div>Partnerji</div></a> <a asp-page="/CodeTablePartners/Index" class="sidenav-link"><i class="sidenav-icon fas fa-handshake"></i><div>Partnerji</div></a>
</li> </li>
@@ -126,6 +88,9 @@
<li class="sidenav-item@(currentPage.StartsWith("/CodeTableItems/") ? " active" : "")"> <li class="sidenav-item@(currentPage.StartsWith("/CodeTableItems/") ? " active" : "")">
<a asp-page="/CodeTableItems/Index" class="sidenav-link"><i class="sidenav-icon fas fa-box"></i><div>Artikli</div></a> <a asp-page="/CodeTableItems/Index" class="sidenav-link"><i class="sidenav-icon fas fa-box"></i><div>Artikli</div></a>
</li> </li>
<li class="sidenav-item@(currentPage.StartsWith("/CodeTableOperations/") ? " active" : "")">
<a asp-page="/CodeTableOperations/Index" class="sidenav-link"><i class="sidenav-icon fas fa-wrench"></i><div>Operacije</div></a>
</li>
} }
@if (User.IsInRole("Administrator") || User.IsInRole("TransportThingUser")) @if (User.IsInRole("Administrator") || User.IsInRole("TransportThingUser"))
{ {

View File

@@ -13,7 +13,7 @@
<h4 class="d-flex justify-content-between align-items-center w-100 font-weight-bold py-1 mb-4"> <h4 class="d-flex justify-content-between align-items-center w-100 font-weight-bold py-1 mb-4">
<span> <span>
<span class="text-muted font-weight-light">Projekt /</span> <span class="text-muted font-weight-light">Projekt /</span>
@if ((bool)ViewData["Edit"]) @if ((bool)ViewData["Edit"])
{ {
<span>&nbsp;Urejanje pozicije dela projekta</span> <span>&nbsp;Urejanje pozicije dela projekta</span>
@@ -22,7 +22,7 @@
{ {
<span>&nbsp;Nova pozicija dela projekta</span> <span>&nbsp;Nova pozicija dela projekta</span>
} }
</span> </span>
</h4> </h4>
@@ -46,9 +46,11 @@
<div class="col-12"> <div class="col-12">
<div class="form-group"> <div class="form-group">
<label asp-for="ProjectPartItem.IdItemFk" class="form-label"></label> <label asp-for="ProjectPartItem.IdItemFk" class="form-label"></label>
<div class="form-row"> <div class="form-row align-items-end">
<div class="col-12"> <div class="col">
<select id="selCodeTableItem" asp-for="ProjectPartItem.IdItemFk" class="form-control select2" asp-items="ViewBag.IdItemFk"></select> <select id="selCodeTableItem" asp-for="ProjectPartItem.IdItemFk" class="form-control select2" asp-items="ViewBag.IdItemFk"></select>
</div>
<div class="col-auto">
<button class="btn btn-success" type="button" onclick="copyDataFromLastPartItem();">Napolni prejšnje</button> <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> <button class="btn btn-primary" type="button" onclick="addNewCodeTableItem();">Novi artikel</button>
</div> </div>
@@ -76,11 +78,11 @@
<div class="col-12"> <div class="col-12">
<div class="form-group"> <div class="form-group">
<label asp-for="ProjectPartItem.IdMaterialFk" class="form-label"></label> <label asp-for="ProjectPartItem.IdMaterialFk" class="form-label"></label>
<div class="form-row"> <div class="form-row align-items-end">
<div class="col-9"> <div class="col">
<select id="selCodeTableItemMaterial" asp-for="ProjectPartItem.IdMaterialFk" class="form-control select2" asp-items="ViewBag.IdMaterialFk"></select> <select id="selCodeTableItemMaterial" asp-for="ProjectPartItem.IdMaterialFk" class="form-control select2" asp-items="ViewBag.IdMaterialFk"></select>
</div> </div>
<div class="col-3"> <div class="col-auto">
<button class="btn btn-primary" type="button" onclick="addNewCodeTableItemMaterial();">Novi material</button> <button class="btn btn-primary" type="button" onclick="addNewCodeTableItemMaterial();">Novi material</button>
</div> </div>
</div> </div>
@@ -153,6 +155,15 @@
</div> </div>
</div> </div>
</div> </div>
<div class="row">
<div class="col-12">
<div class="form-group">
<label asp-for="ProjectPartItem.Note" class="form-label"></label>
<textarea asp-for="ProjectPartItem.Note" class="form-control" rows="3"></textarea>
</div>
</div>
</div>
</div> </div>
<div class="card-footer py-3 text-right"> <div class="card-footer py-3 text-right">
@if (ViewData["Edit"] != null && (bool)ViewData["Edit"]) @if (ViewData["Edit"] != null && (bool)ViewData["Edit"])
@@ -161,13 +172,93 @@
} }
else else
{ {
<button type="submit" class="btn btn-primary">Dodaj del projekta</button> <button type="submit" class="btn btn-primary">Dodaj pozicijo dela projekta</button>
} }
<a asp-page="Edit" asp-route-id="@ViewBag.IdProject" class="btn btn-default">Prekliči</a> <a asp-page="Edit" asp-route-id="@ViewBag.IdProject" class="btn btn-default">Prekliči</a>
</div> </div>
</div> </div>
</div> </div>
<div class="col-6">
<div class="card">
<h6 class="card-header">
Operacije
</h6>
<div class="card-body">
@if (ViewData["Edit"] != null && (bool)ViewData["Edit"])
{
<div class="form-row align-items-end mb-3">
<div class="col">
<label class="form-label" for="selProjectPartItemOperation">Naziv</label>
<select id="selProjectPartItemOperation" class="form-control select2" asp-items="ViewBag.IdCodeTableOperationFk"></select>
</div>
<div class="col-auto">
<button type="button" class="btn btn-primary" onclick="addProjectPartItemOperation();">Dodaj</button>
<button type="button" class="btn btn-success" onclick="addDefaultOperations();">Dodaj privzete</button>
</div>
</div>
}
<table class="table">
<thead>
<tr>
<th class="w-100">Naziv</th>
<th class="text-right" style="white-space: nowrap; width: 1%;">Končano</th>
<th class="text-right" style="white-space: nowrap; width: 1%;"></th>
</tr>
</thead>
<tbody>
@foreach (var operation in Model.ProjectPartItemOperations)
{
<tr data-id="@operation.Id" data-id-code-table-operation="@operation.IdCodeTableOperationFk">
<td>
@Html.DisplayFor(modelItem => operation.Operation.Title)
</td>
<td class="text-right" style="white-space: nowrap; width: 1%;">
<input type="checkbox" @(operation.Finished ? "checked" : "") onchange="toggleOperationFinished(@operation.Id, this);" />
</td>
<td class="text-right" style="white-space: nowrap; width: 1%;">
<a class="btn btn-xs icon-btn btn-outline-secondary borderless" href="javascript:;" onclick="moveOperation(@operation.Id, 'up', this);" title="Gor"><i class="fas fa-arrow-up"></i></a>
<a class="btn btn-xs icon-btn btn-outline-secondary borderless" href="javascript:;" onclick="moveOperation(@operation.Id, 'down', this);" title="Dol"><i class="fas fa-arrow-down"></i></a>
<a class="btn btn-xs icon-btn btn-outline-danger borderless" data-state="danger" href="javascript:;" onclick="deleteProjectPartItemOperation(@operation.Id, this);" title="Izbriši"><i class="fas fa-times"></i></a>
</td>
</tr>
}
</tbody>
</table>
</div>
</div>
<div class="card">
<h6 class="card-header">
Kooperacije
</h6>
<div class="card-body">
<table class="table">
<thead>
<tr>
<th style="white-space: nowrap; width: 1%;">Številka</th>
<th>Partner</th>
<th style="white-space: nowrap; width: 1%;"></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.CooperationInvoiceItems)
{
<tr>
<td style="white-space: nowrap;">@item.Invoice.InvoiceNumberFormatted</td>
<td>@item.Invoice.Partner?.Title</td>
<td class="text-right" style="white-space: nowrap; width: 1%;">
<a class="btn btn-xs icon-btn btn-outline-primary borderless" asp-page="/Invoices/Print" asp-route-id="@item.Invoice.IdInvoice" data-toggle="tooltip" data-placement="top" title="Tiskanje" data-state="primary"><i class="ion ion-md-print"></i></a>
<a class="btn btn-xs icon-btn btn-outline-secondary borderless" asp-page="/Invoices/Edit" asp-route-id="@item.Invoice.IdInvoice" data-toggle="tooltip" data-placement="top" title="Urejanje" data-state="secondary"><i class="fas fa-pencil-alt"></i></a>
</td>
</tr>
}
</tbody>
</table>
</div>
</div>
</div>
</div> </div>
<div asp-validation-summary="ModelOnly" class="text-danger"></div> <div asp-validation-summary="ModelOnly" class="text-danger"></div>
@@ -246,5 +337,209 @@
location.replace(`CreateEditPartItem?idProjectPartItem=${idProjectPartItem}&idProject=${idProject}&idProjectPart=${idProjectPart}&edit=${edit}&idArticleCopyFrom=${idArticle}`); location.replace(`CreateEditPartItem?idProjectPartItem=${idProjectPartItem}&idProject=${idProject}&idProjectPart=${idProjectPart}&edit=${edit}&idArticleCopyFrom=${idArticle}`);
} }
function moveOperation(idProjectPartItemOperation, direction, element) {
let row = $(element).closest('tr');
$.ajax({
type: "POST",
beforeSend: function(xhr) {
xhr.setRequestHeader("XSRF-TOKEN",
$('input:hidden[name="__RequestVerificationToken"]').val());
},
url: "CreateEditPartItem/?handler=MoveOperation",
data: {
idProjectPartItemOperation,
direction
},
success: function(data) {
if (data.successful) {
if (direction === 'up') {
let prev = row.prev('tr');
if (prev.length) {
row.insertBefore(prev);
}
} else {
let next = row.next('tr');
if (next.length) {
row.insertAfter(next);
}
}
}
},
error: function(xhr, ajaxOptions, thrownError) {
console.log(xhr);
alert(xhr.responseText);
}
});
}
function toggleOperationFinished(idProjectPartItemOperation, checkbox) {
$.ajax({
type: "POST",
beforeSend: function(xhr) {
xhr.setRequestHeader("XSRF-TOKEN",
$('input:hidden[name="__RequestVerificationToken"]').val());
},
url: "CreateEditPartItem/?handler=ToggleProjectPartItemOperationFinished",
data: {
idProjectPartItemOperation
},
success: function(data) {
if (!data.successful) {
Swal.fire('Napaka pri posodabljanju operacije', data.error, 'error');
checkbox.checked = !checkbox.checked;
}
},
error: function(xhr, ajaxOptions, thrownError) {
console.log(xhr);
alert(xhr.responseText);
checkbox.checked = !checkbox.checked;
}
});
}
function deleteProjectPartItemOperation(idProjectPartItemOperation, element) {
let row = $(element).closest('tr');
Swal.fire({
title: 'Izbrišem operacijo?',
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) {
$.ajax({
type: "DELETE",
beforeSend: function(xhr) {
xhr.setRequestHeader("XSRF-TOKEN",
$('input:hidden[name="__RequestVerificationToken"]').val());
},
url: "CreateEditPartItem/?handler=ProjectPartItemOperation",
data: {
idProjectPartItemOperation
},
success: function(data) {
if (data.successful) {
let operationName = row.find('td:first').text().trim();
let operationId = row.data('idCodeTableOperation');
$('#selProjectPartItemOperation').append($('<option></option>').val(operationId).html(operationName));
row.remove();
$('#selProjectPartItemOperation').trigger('change');
} else {
Swal.fire('Napaka pri brisanju operacije', data.error, 'error');
}
},
error: function(xhr, ajaxOptions, thrownError) {
console.log(xhr);
alert(xhr.responseText);
}
});
}
});
}
function addDefaultOperations() {
let idProjectPartItem = parseInt($('#ProjectPartItem_IdProjectPartItem').val());
if (isNaN(idProjectPartItem)) {
return;
}
$.blockUI();
$.ajax({
type: "POST",
beforeSend: function(xhr) {
xhr.setRequestHeader("XSRF-TOKEN",
$('input:hidden[name="__RequestVerificationToken"]').val());
},
url: "CreateEditPartItem/?handler=AddDefaultOperations",
data: {
idProjectPartItem
},
success: function(data) {
$.unblockUI();
if (data.successful) {
$.each(data.operations, function(i, op) {
let row = `<tr data-id="${op.idProjectPartItemOperation}" data-id-code-table-operation="${op.idCodeTableOperation}">
<td>${op.title}</td>
<td class="text-right" style="white-space: nowrap; width: 1%;">
<input type="checkbox" onchange="toggleOperationFinished(${op.idProjectPartItemOperation}, this);" />
</td>
<td class="text-right" style="white-space: nowrap; width: 1%;">
<a class="btn btn-xs icon-btn btn-outline-secondary borderless" href="javascript:;" onclick="moveOperation(${op.idProjectPartItemOperation}, 'up', this);" title="Gor"><i class="fas fa-arrow-up"></i></a>
<a class="btn btn-xs icon-btn btn-outline-secondary borderless" href="javascript:;" onclick="moveOperation(${op.idProjectPartItemOperation}, 'down', this);" title="Dol"><i class="fas fa-arrow-down"></i></a>
<a class="btn btn-xs icon-btn btn-outline-danger borderless" data-state="danger" href="javascript:;" onclick="deleteProjectPartItemOperation(${op.idProjectPartItemOperation}, this);" title="Izbriši"><i class="fas fa-times"></i></a>
</td>
</tr>`;
$('table.table tbody').append(row);
$('#selProjectPartItemOperation option[value="' + op.idCodeTableOperation + '"]').remove();
});
$('#selProjectPartItemOperation').trigger('change');
} else {
Swal.fire('Napaka pri dodajanju privzetih operacij', data.error, 'error');
}
},
error: function(xhr, ajaxOptions, thrownError) {
console.log(xhr);
alert(xhr.responseText);
$.unblockUI();
}
});
}
function addProjectPartItemOperation() {
let idProjectPartItem = parseInt($('#ProjectPartItem_IdProjectPartItem').val());
let idCodeTableOperation = parseInt($('#selProjectPartItemOperation').val());
if (isNaN(idProjectPartItem) || isNaN(idCodeTableOperation)) {
Swal.fire('Izberite operacijo.');
return;
}
$.blockUI();
$.ajax({
type: "POST",
beforeSend: function(xhr) {
xhr.setRequestHeader("XSRF-TOKEN",
$('input:hidden[name="__RequestVerificationToken"]').val());
},
url: "CreateEditPartItem/?handler=ProjectPartItemOperation",
data: {
idProjectPartItem,
idCodeTableOperation
},
success: function(data) {
$.unblockUI();
if (data.successful){
let id = data.idProjectPartItemOperation;
let row = `<tr data-id="${id}" data-id-code-table-operation="${idCodeTableOperation}">
<td>${data.title}</td>
<td class="text-right" style="white-space: nowrap; width: 1%;">
<input type="checkbox" onchange="toggleOperationFinished(${id}, this);" />
</td>
<td class="text-right" style="white-space: nowrap; width: 1%;">
<a class="btn btn-xs icon-btn btn-outline-secondary borderless" href="javascript:;" onclick="moveOperation(${id}, 'up', this);" title="Gor"><i class="fas fa-arrow-up"></i></a>
<a class="btn btn-xs icon-btn btn-outline-secondary borderless" href="javascript:;" onclick="moveOperation(${id}, 'down', this);" title="Dol"><i class="fas fa-arrow-down"></i></a>
<a class="btn btn-xs icon-btn btn-outline-danger borderless" data-state="danger" href="javascript:;" onclick="deleteProjectPartItemOperation(${id}, this);" title="Izbriši"><i class="fas fa-times"></i></a>
</td>
</tr>`;
$('table.table tbody').append(row);
$('#selProjectPartItemOperation option[value="' + idCodeTableOperation + '"]').remove();
$('#selProjectPartItemOperation').trigger('change');
} else {
Swal.fire('Napaka pri dodajanju operacije',
data.error,
'error');
}
},
error: function(xhr, ajaxOptions, thrownError) {
console.log(xhr);
alert(xhr.responseText);
$.unblockUI();
}
});
}
</script> </script>
} }

View File

@@ -11,6 +11,7 @@ using EveryThing.Data;
using EveryThing.Models; using EveryThing.Models;
using EveryThing.Models.CodeTable; using EveryThing.Models.CodeTable;
using EveryThing.Models.Project; using EveryThing.Models.Project;
using EveryThing.Models.Invoice;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace EveryThing.Pages.Projects namespace EveryThing.Pages.Projects
@@ -46,6 +47,8 @@ namespace EveryThing.Pages.Projects
ViewData["IdMaterialSupplierFk"] = new SelectList(_context.CodeTablePartners ViewData["IdMaterialSupplierFk"] = new SelectList(_context.CodeTablePartners
.Where(x => x.IdCompanyFk == user.IdCompanyFk && x.Active && x.Supplier) .Where(x => x.IdCompanyFk == user.IdCompanyFk && x.Active && x.Supplier)
.OrderBy(x => x.Title), "IdPartner", "Title"); .OrderBy(x => x.Title), "IdPartner", "Title");
ViewData["IdCodeTableOperationFk"] = new SelectList(_context.CodeTableOperations
.OrderBy(x => x.Title), "Id", "Title");
ViewData["Edit"] = edit; ViewData["Edit"] = edit;
@@ -55,11 +58,29 @@ namespace EveryThing.Pages.Projects
.Include(x => x.ProjectPart) .Include(x => x.ProjectPart)
.ThenInclude(x => x.Project) .ThenInclude(x => x.Project)
.FirstOrDefault(x => x.IdProjectPartItem == idProjectPartItem); .FirstOrDefault(x => x.IdProjectPartItem == idProjectPartItem);
if (ProjectPartItem == null) if (ProjectPartItem == null)
{ {
return NotFound(); return NotFound();
} }
ProjectPartItemOperations = _context.ProjectPartItemOperations
.Include(x => x.Operation)
.Where(x => x.IdProjectPartItemFk == ProjectPartItem.IdProjectPartItem)
.OrderBy(x => x.Order)
.ToList();
var usedOperationIds = ProjectPartItemOperations.Select(x => x.IdCodeTableOperationFk).ToList();
ViewData["IdCodeTableOperationFk"] = new SelectList(_context.CodeTableOperations
.Where(x => !usedOperationIds.Contains(x.Id))
.OrderBy(x => x.Title), "Id", "Title");
CooperationInvoiceItems = _context.InvoiceItems
.Include(x => x.Invoice)
.ThenInclude(x => x.Partner)
.Where(x => x.IdProjectPartItem == ProjectPartItem.IdProjectPartItem
&& x.Invoice.Type == Invoice.InvoiceType.Cooperation)
.ToList();
} }
else else
{ {
@@ -68,6 +89,8 @@ namespace EveryThing.Pages.Projects
NumberOfSets = 1, NumberOfSets = 1,
IdProjectPartFk = idProjectPart IdProjectPartFk = idProjectPart
}; };
ProjectPartItemOperations = new List<ProjectPartItemOperation>();
CooperationInvoiceItems = new List<InvoiceItem>();
} }
if (idArticleCopyFrom != null) if (idArticleCopyFrom != null)
@@ -101,6 +124,10 @@ namespace EveryThing.Pages.Projects
[BindProperty] [BindProperty]
public int IdProject { get; set; } public int IdProject { get; set; }
public IList<ProjectPartItemOperation> ProjectPartItemOperations { get; set; }
public IList<InvoiceItem> CooperationInvoiceItems { get; set; }
public async Task<IActionResult> OnPostAsync(bool edit) public async Task<IActionResult> OnPostAsync(bool edit)
{ {
if (!ModelState.IsValid) if (!ModelState.IsValid)
@@ -158,5 +185,149 @@ namespace EveryThing.Pages.Projects
return new JsonResult(new { items = items }); return new JsonResult(new { items = items });
} }
public IActionResult OnPostProjectPartItemOperation(int idProjectPartItem, int idCodeTableOperation)
{
var maxOrder = _context.ProjectPartItemOperations
.Where(x => x.IdProjectPartItemFk == idProjectPartItem)
.Select(x => (short?)x.Order)
.Max() ?? 0;
var operation = new ProjectPartItemOperation
{
IdProjectPartItemFk = idProjectPartItem,
IdCodeTableOperationFk = idCodeTableOperation,
Finished = false,
Order = (short)(maxOrder + 1)
};
_context.ProjectPartItemOperations.Add(operation);
_context.SaveChanges();
var title = _context.CodeTableOperations
.Where(x => x.Id == idCodeTableOperation)
.Select(x => x.Title)
.FirstOrDefault();
return new JsonResult(new { successful = true, idProjectPartItemOperation = operation.Id, title });
}
public IActionResult OnPostToggleProjectPartItemOperationFinished(int idProjectPartItemOperation)
{
var successful = true;
var error = "";
var operation = _context.ProjectPartItemOperations
.FirstOrDefault(x => x.Id == idProjectPartItemOperation);
if (operation != null)
{
operation.Finished = !operation.Finished;
_context.SaveChanges();
}
else
{
successful = false;
error = $"Operation with ID: {idProjectPartItemOperation} not found";
}
return new JsonResult(new { successful, error, finished = operation?.Finished });
}
public IActionResult OnDeleteProjectPartItemOperation(int idProjectPartItemOperation)
{
var successful = true;
var error = "";
var operation = _context.ProjectPartItemOperations
.FirstOrDefault(x => x.Id == idProjectPartItemOperation);
if (operation != null)
{
_context.ProjectPartItemOperations.Remove(operation);
_context.SaveChanges();
}
else
{
successful = false;
error = $"Operation with ID: {idProjectPartItemOperation} not found";
}
return new JsonResult(new { successful, error, idProjectPartItemOperation });
}
public IActionResult OnPostAddDefaultOperations(int idProjectPartItem)
{
var existingOperationIds = _context.ProjectPartItemOperations
.Where(x => x.IdProjectPartItemFk == idProjectPartItem)
.Select(x => x.IdCodeTableOperationFk)
.ToList();
var defaultOperations = _context.CodeTableOperations
.Where(x => x.Default && !existingOperationIds.Contains(x.Id))
.OrderBy(x => x.Title)
.ToList();
var added = new List<object>();
var maxOrder = _context.ProjectPartItemOperations
.Where(x => x.IdProjectPartItemFk == idProjectPartItem)
.Select(x => (short?)x.Order)
.Max() ?? 0;
foreach (var op in defaultOperations)
{
maxOrder++;
var newOp = new ProjectPartItemOperation
{
IdProjectPartItemFk = idProjectPartItem,
IdCodeTableOperationFk = op.Id,
Finished = false,
Order = maxOrder
};
_context.ProjectPartItemOperations.Add(newOp);
_context.SaveChanges();
added.Add(new { idProjectPartItemOperation = newOp.Id, idCodeTableOperation = op.Id, title = op.Title });
}
return new JsonResult(new { successful = true, operations = added });
}
public IActionResult OnPostMoveOperation(int idProjectPartItemOperation, string direction)
{
var operation = _context.ProjectPartItemOperations
.FirstOrDefault(x => x.Id == idProjectPartItemOperation);
if (operation == null)
return new JsonResult(new { successful = false, error = "Operation not found" });
ProjectPartItemOperation neighbor;
if (direction == "up")
{
neighbor = _context.ProjectPartItemOperations
.Where(x => x.IdProjectPartItemFk == operation.IdProjectPartItemFk && x.Order < operation.Order)
.OrderByDescending(x => x.Order)
.FirstOrDefault();
}
else
{
neighbor = _context.ProjectPartItemOperations
.Where(x => x.IdProjectPartItemFk == operation.IdProjectPartItemFk && x.Order > operation.Order)
.OrderBy(x => x.Order)
.FirstOrDefault();
}
if (neighbor == null)
return new JsonResult(new { successful = true });
var temp = operation.Order;
operation.Order = neighbor.Order;
neighbor.Order = temp;
_context.SaveChanges();
return new JsonResult(new { successful = true });
}
} }
} }

View File

@@ -0,0 +1,162 @@
//ce jamra da ne najde post je treba dati @Html.AntiForgeryToken() v page
function codeTableOperationAddEdit(placeholderSelector, edit, idCodeTableOperation, onAddEdit, onCancel){
$.blockUI();
$.ajax({
type: "GET",
url: "/CodeTableOperations/Index/?handler=CodeTableOperationModal",
data: { edit: edit, idCodeTableOperation: edit ? idCodeTableOperation : -1 },
success: function(data) {
$.unblockUI();
$(placeholderSelector).html(data);
if (edit){
$('#modalAddEditCodeTableOperationTitle').html(`Urejanje operacije: ${$('#inpModalAddEditCodeTableOperationTitle').val()}`);
$('#btnModalAddEditCodeTableOperationConfirm').html('Shrani');
} else {
$('#modalAddEditCodeTableOperationTitle').html('Dodajanje nove operacije');
$('#btnModalAddEditCodeTableOperationConfirm').html('Dodaj');
}
$('#btnModalAddEditCodeTableOperationConfirm').off();
$('#btnModalAddEditCodeTableOperationCancel').off();
//Save to db
$('#btnModalAddEditCodeTableOperationConfirm').on('click', () =>{
let title = $('#inpModalAddEditCodeTableOperationTitle').val();
let defaultValue = $('#inpModalAddEditCodeTableOperationDefault').is(':checked');
let edit = $('#inpModalAddEditCodeTableOperationEdit').val() === 'true';
let idCodeTableOperation = parseInt($('#inpModalAddEditCodeTableOperationIdCodeTableOperation').val());
if (title === '' || title === null){
Swal.fire('Zahtevano polje naziv!');
return;
}
$.blockUI();
$.ajax({
type: "POST",
beforeSend: function(xhr) {
xhr.setRequestHeader("XSRF-TOKEN",
$('input:hidden[name="__RequestVerificationToken"]').val());
},
url: "/CodeTableOperations/Index/?handler=CodeTableOperation",
data: {
title,
defaultValue,
edit,
idCodeTableOperation
},
success: function(data) {
$.unblockUI();
if (data.successful){
$("#divModalAddEditCodeTableOperation").modal('hide');
if (onAddEdit != null){
onAddEdit(data.idCodeTableOperation);
}
} else {
Swal.fire('Napaka pri dodajanju/posodabljanju',
data.error,
'error');
}
},
error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr);
alert(xhr.responseText);
$.unblockUI();
}
});
});
//Cancel
$('#btnModalAddEditCodeTableOperationCancel').on('click', () =>{
$("#divModalAddEditCodeTableOperation").modal('hide');
if (onCancel != null){
onCancel();
}
});
$("#divModalAddEditCodeTableOperation").modal('show');
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.responseText);
$.unblockUI();
}
});
}
function codeTableOperationDelete(idCodeTableOperation, onDelete, onCancel){
$.blockUI();
$.ajax({
type: "GET",
url: "/CodeTableOperations/Index/?handler=CodeTableOperation",
data: {
idCodeTableOperation
},
success: function(data) {
$.unblockUI();
if (data.successful){
if (data.inUse){
Swal.fire('Operacija je v uporabi!',
'Brisanje ni možno!',
'warning');
return;
}
Swal.fire({
title: `Izbrišem operacijo ${data.operation.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: "/CodeTableOperations/Index/?handler=CodeTableOperation",
data: {
idCodeTableOperation
},
success: function(data) {
$.unblockUI();
if (data.successful){
if (onDelete != null){
onDelete(data.idCodeTableOperation);
}
} else {
Swal.fire('Napaka pri brisanju operacije',
data.error,
'error');
}
},
error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr);
alert(xhr.responseText);
$.unblockUI();
}
});
} else{
if (onCancel != null){
onCancel();
}
}
});
} else {
Swal.fire('Napaka pri branju operacije',
data.error,
'error');
}
},
error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr);
alert(xhr.responseText);
$.unblockUI();
}
});
}