- 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

@@ -11,6 +11,7 @@ using EveryThing.Data;
using EveryThing.Models;
using EveryThing.Models.CodeTable;
using EveryThing.Models.Project;
using EveryThing.Models.Invoice;
using Microsoft.EntityFrameworkCore;
namespace EveryThing.Pages.Projects
@@ -46,6 +47,8 @@ namespace EveryThing.Pages.Projects
ViewData["IdMaterialSupplierFk"] = new SelectList(_context.CodeTablePartners
.Where(x => x.IdCompanyFk == user.IdCompanyFk && x.Active && x.Supplier)
.OrderBy(x => x.Title), "IdPartner", "Title");
ViewData["IdCodeTableOperationFk"] = new SelectList(_context.CodeTableOperations
.OrderBy(x => x.Title), "Id", "Title");
ViewData["Edit"] = edit;
@@ -55,11 +58,29 @@ namespace EveryThing.Pages.Projects
.Include(x => x.ProjectPart)
.ThenInclude(x => x.Project)
.FirstOrDefault(x => x.IdProjectPartItem == idProjectPartItem);
if (ProjectPartItem == null)
{
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
{
@@ -68,6 +89,8 @@ namespace EveryThing.Pages.Projects
NumberOfSets = 1,
IdProjectPartFk = idProjectPart
};
ProjectPartItemOperations = new List<ProjectPartItemOperation>();
CooperationInvoiceItems = new List<InvoiceItem>();
}
if (idArticleCopyFrom != null)
@@ -101,6 +124,10 @@ namespace EveryThing.Pages.Projects
[BindProperty]
public int IdProject { get; set; }
public IList<ProjectPartItemOperation> ProjectPartItemOperations { get; set; }
public IList<InvoiceItem> CooperationInvoiceItems { get; set; }
public async Task<IActionResult> OnPostAsync(bool edit)
{
if (!ModelState.IsValid)
@@ -158,5 +185,149 @@ namespace EveryThing.Pages.Projects
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 });
}
}
}