This commit is contained in:
2026-01-19 18:02:55 +01:00
parent 87044adcb0
commit 30f87f26da
19 changed files with 10631 additions and 3773 deletions

View File

@@ -1,54 +1,126 @@
@page
@model EveryThing.Pages.Invoices.CreateItemModel
<h4>Faktura</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form method="post">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<input type="hidden" asp-for="@ViewData["IdInvoice"]" name="idInvoice"/>
<div class="form-group">
<label asp-for="InvoiceItem.IdItemFk" class="control-label"></label>
<select asp-for="InvoiceItem.IdItemFk" class="form-control" asp-items="ViewBag.Items"></select>
<span asp-validation-for="InvoiceItem.IdItemFk" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="InvoiceItem.ItemDescription" class="control-label"></label>
<textarea asp-for="InvoiceItem.ItemDescription" class="form-control"></textarea>
<span asp-validation-for="InvoiceItem.ItemDescription" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="InvoiceItem.Quantity" class="control-label"></label>
<input asp-for="InvoiceItem.Quantity" class="form-control" />
<span asp-validation-for="InvoiceItem.Quantity" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="InvoiceItem.Price" class="control-label"></label>
<input asp-for="InvoiceItem.Price" class="form-control" />
<span asp-validation-for="InvoiceItem.Price" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="InvoiceItem.Discount" class="control-label"></label>
<input asp-for="InvoiceItem.Discount" class="form-control" />
<span asp-validation-for="InvoiceItem.Discount" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="InvoiceItem.Note" class="control-label"></label>
<textarea asp-for="InvoiceItem.Note" class="form-control" ></textarea>
<span asp-validation-for="InvoiceItem.Note" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Shrani" class="btn btn-primary" />
</div>
</form>
</div>
</div>
@section Styles
{
<link rel="stylesheet" href="~/vendor/libs/select2/select2.css" asp-append-version="true" />
<style type="text/css">
textarea{
resize:none;
overflow-y:auto;
}
</style>
}
<form method="post">
<input type="hidden" asp-for="InvoiceItem.IdInvoiceFk" />
<input type="hidden" asp-for="InvoiceItem.IdInvoiceItem" />
<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">
@Model.Invoice.InvoiceTypeHeaderString
/
@Model.Invoice.InvoiceNumberFormatted
/
</span>
@if ((bool)ViewData["Edit"])
{
<span>Urejanje pozicije</span>
}
else
{
<span>&nbsp;Nova pozicija</span>
}
</span>
</h4>
<div class="row">
<div class="col-6">
<div class="card">
<h6 class="card-header">
Podatki pozicije
</h6>
<div class="card-body">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<input type="hidden" asp-for="@ViewData["IdInvoice"]" name="idInvoice"/>
<div class="form-group">
<label asp-for="InvoiceItem.IdItemFk" class="control-label"></label>
<select asp-for="InvoiceItem.IdItemFk" class="form-control select2" asp-items="ViewBag.Items">
<option value=""></option>
</select>
<span asp-validation-for="InvoiceItem.IdItemFk" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="InvoiceItem.ItemDescription" class="control-label"></label>
<textarea asp-for="InvoiceItem.ItemDescription" class="form-control" rows="6"></textarea>
<span asp-validation-for="InvoiceItem.ItemDescription" class="text-danger"></span>
</div>
<div class="form-group">
<div class="row">
<div class="col-4">
<label asp-for="InvoiceItem.Quantity" class="control-label"></label>
<input asp-for="InvoiceItem.Quantity" class="form-control"/>
<span asp-validation-for="InvoiceItem.Quantity" class="text-danger"></span>
</div>
<div class="col-4">
<label asp-for="InvoiceItem.Price" class="control-label"></label>
<input asp-for="InvoiceItem.Price" class="form-control"/>
<span asp-validation-for="InvoiceItem.Price" class="text-danger"></span>
</div>
<div class="col-4">
<label asp-for="InvoiceItem.Discount" class="control-label"></label>
<input asp-for="InvoiceItem.Discount" class="form-control"/>
<span asp-validation-for="InvoiceItem.Discount" class="text-danger"></span>
</div>
</div>
</div>
<div class="form-group">
<label asp-for="InvoiceItem.Note" class="control-label"></label>
<textarea asp-for="InvoiceItem.Note" class="form-control" rows="6"></textarea>
<span asp-validation-for="InvoiceItem.Note" class="text-danger"></span>
</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 pozicijo</button>
}
<a class="btn btn-default" asp-page="./Edit" asp-route-id="@ViewData["IdInvoice"]">Prekliči</a>
</div>
</div>
</div>
</div>
</form>
<div>
<a class="btn btn-default" asp-page="./Edit" asp-route-id="@ViewData["IdInvoice"]">Nazaj</a>
</div>
@section Scripts {
<script src="~/vendor/libs/select2/select2.js" asp-append-version="true"></script>
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
<script type="text/javascript">
$(document).ready(function() {
$('.select2').select2({
placeholder: 'Artikel ni izbran',
allowClear: true
});
// Forced check on load: if the value is null/empty, reset the dropdown
if (!$('#InvoiceItem_IdItemFk').val()) {
$('#InvoiceItem_IdItemFk').val(null).trigger('change');
}
});
</script>
}

View File

@@ -1,14 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using EveryThing.Data;
using EveryThing.Models;
using EveryThing.Models.Invoice;
using EveryThing.Models.Project;
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 Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Authorization;
using Microsoft.CodeAnalysis.Differencing;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace EveryThing.Pages.Invoices
{
@@ -28,20 +32,41 @@ namespace EveryThing.Pages.Invoices
_roleManager = roleManager;
}
public IActionResult OnGet(int idInvoice)
[BindProperty]
public Models.Invoice.InvoiceItem InvoiceItem { get; set; }
public Models.Invoice.Invoice Invoice { get; set; }
public IActionResult OnGet(int idInvoice, bool? edit = null, int? idInvoiceItem = null)
{
var user = _userManager.GetUserAsync(User).Result;
ViewData["IdInvoice"] = idInvoice;
Invoice = _context.Invoices.FirstOrDefault(x => x.IdInvoice == idInvoice);
if (Invoice == null)
return NotFound();
ViewData["Items"] = new SelectList(_context.CodeTableItems.Where(x => x.IdCompanyFk == user.IdCompanyFk && x.Active), "IdItem", "Title");
ViewData["Edit"] = edit ?? false;
if (edit ?? false)
{
InvoiceItem = _context.InvoiceItems.FirstOrDefault(x => x.IdInvoiceItem == idInvoiceItem);
if (InvoiceItem == null)
return NotFound();
}
else
{
InvoiceItem = new InvoiceItem
{
IdInvoiceFk = idInvoice
};
}
return Page();
}
[BindProperty]
public Models.Invoice.InvoiceItem InvoiceItem { get; set; }
public async Task<IActionResult> OnPostAsync(int idInvoice)
public async Task<IActionResult> OnPostAsync(bool edit)
{
if (!ModelState.IsValid)
{
@@ -50,12 +75,36 @@ namespace EveryThing.Pages.Invoices
var user = _userManager.GetUserAsync(User).Result;
InvoiceItem.IdInvoiceFk = idInvoice;
if (!edit)
{
_context.InvoiceItems.Add(InvoiceItem);
await _context.SaveChangesAsync();
}
else
{
_context.Attach(InvoiceItem).State = EntityState.Modified;
_context.InvoiceItems.Add(InvoiceItem);
await _context.SaveChangesAsync();
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!InvoiceItemExists(InvoiceItem.IdInvoiceItem))
{
return NotFound();
}
return RedirectToPage("./Edit", new { id = idInvoice });
throw;
}
}
return RedirectToPage("./Edit", new { id = InvoiceItem.IdInvoiceFk });
}
private bool InvoiceItemExists(int id)
{
return _context.InvoiceItems.Any(e => e.IdProjectPartItem == id);
}
}
}

View File

@@ -42,28 +42,9 @@
<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">
@switch (ViewData["Type"])
{
case 1:
<i>Naročila dobaviteljem</i>
break;
case 0:
<i>Računi</i>
break;
case 2:
<i>Dobavnice</i>
break;
case 3:
<i>Naročila kupcev</i>
break;
case 4:
<i>Kooperacije</i>
break;
default:
<i>Fakture</i>
break;
}
/</span> Urejanje
@Model.Invoice.InvoiceTypeHeaderString
/
</span> Urejanje
</span>
</h4>
<hr />

View File

@@ -84,6 +84,7 @@ namespace EveryThing.Pages.Invoices
var user = _userManager.GetUserAsync(User).Result;
ViewData["Type"] = (int)Invoice.Type;
ViewData["IdPartnerFk"] = new SelectList(_context.CodeTablePartners.Where(x => x.IdCompanyFk == user.IdCompanyFk && x.Active), "IdPartner", "Title");
ViewData["States"] = new SelectList(Enum.GetValues(typeof(Models.Invoice.Invoice.InvoiceState))

View File

@@ -12,7 +12,8 @@
<td class="table-number">@Html.DisplayFor(x => Model.TotalValue)</td>
<td class="table-status">@Html.DisplayFor(modelItem => Model.State)</td>
<td class="text-right" style="width: 70px;">
<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", "InvoiceItemEdit", new {id = Model.IdInvoiceItem})" hx-swap="outerHTML" hx-target="closest tr"></i></a>
<a class="btn btn-xs icon-btn btn-outline-secondary borderless" data-state="secondary" asp-page="CreateItem" asp-route-idInvoice="@Model.Invoice.IdInvoice" asp-route-edit="true" asp-route-idInvoiceItem="@Model.IdInvoiceItem"><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="deleteInvoiceItem(this)"><i class="fas fa-times"></i></a>
</td>
</tr>

View File

@@ -170,21 +170,28 @@
@(Model.InvoiceItems.IndexOf(item) + 1)
</td>
<td>
@Html.DisplayFor(x => item.Item.Title)
@if (Model.Invoice.Type != Models.Invoice.Invoice.InvoiceType.Order && !string.IsNullOrEmpty(item.ItemDescription))
@if (!string.IsNullOrEmpty(item.Item?.Title))
{
<br/>
<small>
@Html.DisplayFor(x => item.ItemDescription)
</small>
@Html.DisplayFor(x => item.Item.Title)
@if (Model.Invoice.Type != Models.Invoice.Invoice.InvoiceType.Order && !string.IsNullOrEmpty(item.ItemDescription))
{
<br/>
<small>
@Html.DisplayFor(x => item.ItemDescription)
</small>
}
@if (Model.Invoice.Type == Models.Invoice.Invoice.InvoiceType.Invoice)
{
<br/>
<small>
@Model.Translation.DeliveryNote
<b>@Html.DisplayFor(x => item.InvoiceItemJoin.Invoice.InvoiceNumberFormatted)</b>
</small>
}
}
@if (Model.Invoice.Type == Models.Invoice.Invoice.InvoiceType.Invoice)
else
{
<br/>
<small>
@Model.Translation.DeliveryNote
<b>@Html.DisplayFor(x => item.InvoiceItemJoin.Invoice.InvoiceNumberFormatted)</b>
</small>
@Html.DisplayFor(x => item.ItemDescription)
}
</td>
<td class="text-right">@Html.DisplayFor(x => item.Quantity)</td>

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
@@ -21,20 +21,20 @@ namespace EveryThing.Pages.Invoices
{
public class PrintTranslation
{
public string Email { get; set; } = "E-pošta";
public string Email { get; set; } = "E-pošta";
public string Telephone { get; set; } = "Tel.";
public string IdTax { get; set; } = "ID za DDV";
public string Iban { get; set; } = "IBAN";
public string SwiftBic { get; set; } = "SWIFT/BIC";
public string InvoiceType { get; set; } = "Faktura";
public string Number { get; set; } = "št.";
public string Number { get; set; } = "št.";
public string Date { get; set; } = "Datum";
public string OrderNumber { get; set; } = "Številka naroèila";
public string DeliveryNote { get; set; } = "Številka dobavnice:";
public string OrderNumber { get; set; } = "Številka naročila";
public string DeliveryNote { get; set; } = "Številka dobavnice:";
public string DeliveryTime { get; set; } = "Dobavni rok";
public string DateOfDispatch { get; set; } = "Datum odpreme";
public string Article { get; set; } = "Artikel";
public string Quantity { get; set; } = "Kolièina";
public string Quantity { get; set; } = "Količina";
public string Price { get; set; } = "Cena";
public string Amount { get; set; } = "Znesek";
public string Dimensions { get; set; } = "Dimenzije";
@@ -49,7 +49,7 @@ namespace EveryThing.Pages.Invoices
{
[Display(Name = "Slovensko")]
Slovenian = 1,
[Display(Name = "Nemško")]
[Display(Name = "Nemško")]
German = 2
}
@@ -155,19 +155,19 @@ namespace EveryThing.Pages.Invoices
}
else if (Invoice.State == Invoice.InvoiceState.Inquiry)
{
Translation.InvoiceType = "Povpraševanje";
Translation.InvoiceType = "Povpraševanje";
}
else if (Invoice.State == Invoice.InvoiceState.OfferConfirmation)
{
Translation.InvoiceType = "Potrditev naroèila";
Translation.InvoiceType = "Potrditev naročila";
}
else
{
Translation.InvoiceType = "Naroèilo";
Translation.InvoiceType = "Naročilo";
}
break;
case Invoice.InvoiceType.Invoice:
Translation.InvoiceType = "Raèun";
Translation.InvoiceType = "Račun";
break;
case Invoice.InvoiceType.DeliveryNote:
Translation.InvoiceType = "Dobavnica";
@@ -181,7 +181,7 @@ namespace EveryThing.Pages.Invoices
}
if (invoiceState == Invoice.InvoiceState.Offer)
Translation.OrderNumber = "Št. povpraševanja.";
Translation.OrderNumber = "Št. povpraševanja.";
break;
case PrintTranslationLanguage.German:
Translation = new PrintTranslation
@@ -191,20 +191,20 @@ namespace EveryThing.Pages.Invoices
Date = "Datum",
DateOfDispatch = "Lieferdatum",
DeliveryTime = "Lieferdatum",
Dimensions = "Maße",
Dimensions = "Maße",
Director = "Direktor",
Email = "Email",
Iban = "IBAN",
IdTax = "Ihre UID Nr.",
Number = "Num.",
OrderNumber = invoiceState == Invoice.InvoiceState.Offer ? "Anfrage No." : "Bestellnummer",
Price = "Preis(€)",
Price = "Preis(€)",
Quantity = "Menge(Stk)",
SwiftBic = "SWIFT/BIC",
Total = "Gesamtsumme",
Project = "Projekt",
Issued = "Bearbeiter:",
Received = "Empfänger:",
Received = "Empfänger:",
DeliveryNote = "Lieferschein:"
};
switch (Invoice.Type)
@@ -221,7 +221,7 @@ namespace EveryThing.Pages.Invoices
}
else if (Invoice.State == Invoice.InvoiceState.OfferConfirmation)
{
Translation.InvoiceType = "Auftragsbestätigung";
Translation.InvoiceType = "Auftragsbestätigung";
}
else
{