Compare commits

...

2 Commits

Author SHA1 Message Date
David Štaleker
25e98d63ec Klavzule 2023-06-23 14:17:57 +02:00
David Štaleker
d0fa4db3d8 Klavzule 2023-06-23 10:10:25 +02:00
10 changed files with 557 additions and 9 deletions

View File

@@ -0,0 +1,33 @@
using System.Reflection;
using System;
using System.Collections.Generic;
using System.Linq;
namespace EveryThing.Classess
{
public static class Global
{
public static T GetAttributeOfType<T>(this Enum iEnumType) where T : System.Attribute
{
var type = iEnumType.GetType();
var memberInfo = type.GetMember(iEnumType.ToString());
var atributi = memberInfo[0].GetCustomAttributes(typeof(T), false);
return (atributi.Length > 0) ? (T)atributi[0] : null;
}
public static List<(int EnumValue, T EnumAttribute)> GetEnumListClass<T>(this Type iEnumType,
bool iUseOrder = false) where T : System.Attribute
{
List<(int EnumValue, T EnumAttribute)> titleValue = new();
foreach (var tempEnumValue in Enum.GetValues(iEnumType).Cast<Enum>())
{
object tempObject = GetAttributeOfType<T>(tempEnumValue);
titleValue.Add((Convert.ToInt32(tempEnumValue), (T)tempObject));
}
return titleValue.ToList();
}
}
}

View File

@@ -48,6 +48,8 @@ namespace EveryThing.Data
public DbSet<CodeTableItem> CodeTableItems { get; set; }
public DbSet<Invoice> Invoices { get; set; }
public DbSet<InvoiceItem> InvoiceItems { get; set; }
public DbSet<CodeTablePrePostText> CodeTablePrePostText { get; set; }
public DbSet<CodeTablePrePostTextLink> CodeTablePrePostTextLink { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{

View File

@@ -21,6 +21,11 @@ namespace EveryThing.Models.CodeTable
[Display(Name = "Vsebina")]
public string Content { get; set; }
[NotMapped]
public string ContentDisplay => Content == null ? "" : Content.Length >= 30
? Content.Substring(0, 30)
: Content;
// ForeingKey
public CodeTableCompany Company { get; set; }

View File

@@ -0,0 +1,204 @@
@page "{handler?}"
@model EveryThing.Pages.CodeTablePrePostText.AddEditModel
@{
ViewData["Title"] = "Urejanje klavzule";
Layout = "~/Pages/Layouts/_Layout.cshtml";
}
<!-- Editor -->
<link rel="stylesheet" href="~/vendor/libs/quill/typography.css" asp-append-version="true" />
<link rel="stylesheet" href="~/vendor/libs/quill/editor.css" asp-append-version="true" />
<link rel="stylesheet" href="~/vendor/libs/select2/select2.css" asp-append-version="true" />
<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">Nalog /</span>
@if (Model.PrePostText.IdPrePostText > 0)
{
<span>Urejanje</span>
}
else
{
<span>Vnos</span>
}
</span>
</h4>
<div class="nav-tabs-top nav-responsive-sm">
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link active" data-toggle="tab" href="#item-basic">Osnovni podatki</a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane fade show active" id="item-basic">
<form method="post" data-ajax="true" data-ajax-method="post" asp-page-handler="order" data-ajax-complete="orderPostCompleted" onsubmit="handleEditors()">
<div class="card-body">
<input id="inputIdPrePostText" type="hidden" asp-for="PrePostText.IdPrePostText" />
<input type="hidden" asp-for="PrePostText.IdCompanyFk" />
<div class="row">
<div class="col-6">
<h4>Vsebina</h4>
<div class="form-group mb-0">
<input type="hidden" id="value-content" asp-for="@Model.PrePostText.Content"/>
<div id="editor-content" style="height: 250px">
@Html.Raw(Model.PrePostText.Content)
</div>
<span asp-validation-for="PrePostText.Content" class="text-danger"></span>
</div>
</div>
<div class="col-6">
<h4>Vezave</h4>
<div class="row">
<div class="col-6">
<h5>Uvodno</h5>
<table class="table card-table">
<tbody id="tableBodyLinksPreText">
</tbody>
</table>
</div>
<div class="col-6">
<h5>Zaključno</h5>
<table class="table card-table">
<tbody id="tableBodyLinksPostText">
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="card-footer py-3 text-right">
@if (Model.PrePostText.IdPrePostText > 0)
{
<button id="savePrePostText" type="submit" class="btn btn-primary">Shrani</button>
}
else
{
<button id="savePrePostText" type="submit" class="btn btn-primary">Dodaj</button>
}
<a asp-page="Index" class="btn btn-default">Prekliči</a>
</div>
</form>
</div>
</div>
</div>
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
@Html.AntiForgeryToken()
@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
<!-- Editor -->
<script src="~/vendor/libs/quill/quill.js" asp-append-version="true"></script>
<script src="~/vendor/libs/select2/select2.js" asp-append-version="true"></script>
<script>
var Block = Quill.import('blots/block');
Block.tagName = 'DIV';
Quill.register(Block, true);
var laddaSaveOrder = Ladda.create(document.querySelector('#savePrePostText'));
let editorContent;
function handleEditors() {
document.getElementById('value-content').value = editorContent.root.innerHTML;
}
$(document).ready(function () {
$('.select2').select2();
editorContent = new Quill('#editor-content', { modules: { toolbar: [['bold', 'italic', 'underline'], ['color'], [{ 'list': 'ordered' }, { 'list': 'bullet' }], ['align'], ['clean']] }, theme: 'snow' });
loadLinks();
});
orderPostCompleted = function (xhr) {
laddaSaveOrder.stop();
location.replace('AddEdit?Id=' + xhr.responseJSON.id);
};
function loadLinks() {
let idPrePostText = parseInt($('#inputIdPrePostText').val());
if (idPrePostText <= 0) {
return;
}
$.blockUI();
$.ajax({
type: "GET",
url: "AddEdit/?handler=LinksTable",
data: {
idPrePostText
},
success: function (data) {
$.unblockUI();
if (data.successful) {
$('#tableBodyLinksPreText').html(data.tableLinksPreText);
$('#tableBodyLinksPostText').html(data.tableLinksPostText);
$('.chb-link').on('change',
function() {
toggleLink(this);
});
} else {
console.log(data);
Swal.fire('Napaka pri branju povezav',
data.error,
'error');
}
},
error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr);
alert(xhr.responseText);
$.unblockUI();
}
});
}
let disableToggleLink = false;
function toggleLink(checkbox) {
if (disableToggleLink) {
return;
}
let row = $(checkbox).parent().parent();
let link = $(row).attr('data-link');
let type = $(row).attr('data-type');
let idPrePostTextLink = $(row).attr('data-idlink');
let idPrePostText = parseInt($('#inputIdPrePostText').val());
$.blockUI();
$.ajax({
type: "POST",
beforeSend: function(xhr) {
xhr.setRequestHeader("XSRF-TOKEN",
$('input:hidden[name="__RequestVerificationToken"]').val());
},
url: "AddEdit/?handler=LinkToggle",
data: { idPrePostText, link, type, idPrePostTextLink },
success: function(data) {
$.unblockUI();
if (data.successful) {
disableToggleLink = true;
$(checkbox).prop("checked", data.idLink > 0);
disableToggleLink = false;
} else {
console.log(data);
Swal.fire('Napaka pri vnosu povezave',
data.error,
'error');
}
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.responseText);
$.unblockUI();
}
});
}
</script>
}

View File

@@ -0,0 +1,181 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading;
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 DocumentFormat.OpenXml.Spreadsheet;
using EveryThing.Models.CodeTable;
using EveryThing.Classess;
namespace EveryThing.Pages.CodeTablePrePostText
{
[Authorize(Roles = "Administrator,TransportThingUser,InvoicingUser")]
public class AddEditModel : PageModel
{
private readonly ApplicationDbContext _context;
private readonly UserManager<IdentityApplicationUser> _userManager;
public AddEditModel(ApplicationDbContext context, UserManager<IdentityApplicationUser> userManager)
{
_context = context;
_userManager = userManager;
}
[BindProperty]
public Models.CodeTable.CodeTablePrePostText PrePostText { get; set; }
public async Task<IActionResult> OnGetAsync(int? id)
{
var user = _userManager.GetUserAsync(User).Result;
if (id == null)
{
PrePostText = new Models.CodeTable.CodeTablePrePostText
{
Content = "",
IdCompanyFk = user.IdCompanyFk
};
return Page();
}
PrePostText = await _context.CodeTablePrePostText
.FirstOrDefaultAsync(m => m.IdPrePostText == id && m.IdCompanyFk == user.IdCompanyFk);
if (PrePostText == null)
{
return NotFound();
}
return Page();
}
public async Task<IActionResult> OnPostOrderAsync()
{
System.Diagnostics.Debug.WriteLine("OnPostOrderAsync");
var user = _userManager.GetUserAsync(User).Result;
if (!ModelState.IsValid)
{
ViewData["IdPartnerFk"] = new SelectList(_context.CodeTablePartners.Where(x => x.IdCompanyFk == user.IdCompanyFk), "IdPartner", "Title");
ViewData["IdVehicleFk"] = new SelectList(_context.Vehicles.Where(x => x.IdCompanyFk == user.IdCompanyFk), "IdVehicle", "RegistrationNumber");
return Page();
}
PrePostText.Content = PrePostText.Content.Replace("<div><br></div>", "");
if (PrePostText.IdPrePostText > 0)
{
_context.Attach(PrePostText).State = EntityState.Modified;
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!PrePostTextExists(PrePostText.IdPrePostText))
{
return NotFound();
}
else
{
throw;
}
}
return Page();
}
// OrderNumber and OrderYear
_context.CodeTablePrePostText.Add(PrePostText);
await _context.SaveChangesAsync();
return new JsonResult(new { id = PrePostText.IdPrePostText});
}
private bool PrePostTextExists(int id)
{
return _context.CodeTablePrePostText.Any(e => e.IdPrePostText == id);
}
public IActionResult OnGetLinksTable(int idPrePostText)
{
var insertedLinks = _context.CodeTablePrePostTextLink
.Where(x => x.IdPrePostTextFk == idPrePostText);
var tableLinksPreText = new StringBuilder();
typeof(CodeTablePrePostTextLink.LinkEnum).GetEnumListClass<DisplayAttribute>().ForEach(link =>
{
var insertedLink = insertedLinks.FirstOrDefault(x => (int)x.Link == link.EnumValue && x.Type == CodeTablePrePostTextLink.TypeEnum.PreText);
tableLinksPreText.Append($"<tr data-link='{link.EnumValue}' data-type='{(int)CodeTablePrePostTextLink.TypeEnum.PreText}' data-idlink='{insertedLink?.IdPrePostTextLink ?? 0}'>");
tableLinksPreText.Append($"<td><input type='checkbox' class='chb-link' {((insertedLink?.IdPrePostTextLink ?? 0) > 0 ? "checked='checked'" : "")}/></td>");
tableLinksPreText.Append($"<td>{link.EnumAttribute.Name}</td>");
tableLinksPreText.Append("</tr>");
});
var tableLinksPostText = new StringBuilder();
typeof(CodeTablePrePostTextLink.LinkEnum).GetEnumListClass<DisplayAttribute>().ForEach(link =>
{
var insertedLink = insertedLinks.FirstOrDefault(x => (int)x.Link == link.EnumValue && x.Type == CodeTablePrePostTextLink.TypeEnum.PostText);
tableLinksPostText.Append($"<tr data-link='{link.EnumValue}' data-type='{(int)CodeTablePrePostTextLink.TypeEnum.PostText}' data-idlink='{insertedLink?.IdPrePostTextLink ?? 0}'>");
tableLinksPostText.Append($"<td><input type='checkbox' class='chb-link' {((insertedLink?.IdPrePostTextLink ?? 0) > 0 ? "checked='checked'" : "")}/></td>");
tableLinksPostText.Append($"<td>{link.EnumAttribute.Name}</td>");
tableLinksPostText.Append("</tr>");
});
return new JsonResult(new { tableLinksPreText = tableLinksPreText.ToString(), tableLinksPostText = tableLinksPostText.ToString(), successful = true });
}
public IActionResult OnPostLinkToggle(int idPrePostText, int link, int type, int idPrePostTextLink)
{
var user = _userManager.GetUserAsync(User).Result;
var idLink = 0;
var exitingLink =
_context.CodeTablePrePostTextLink.FirstOrDefault(x => x.IdPrePostTextLink == idPrePostTextLink && x.IdPrePostTextFk == idPrePostText);
if (exitingLink != null)
{
_context.CodeTablePrePostTextLink.Remove(exitingLink);
_context.SaveChanges();
}
else
{
var newLink = new CodeTablePrePostTextLink
{
IdPrePostTextFk = idPrePostText,
Link = (CodeTablePrePostTextLink.LinkEnum)link,
Type = (CodeTablePrePostTextLink.TypeEnum)type
};
_context.CodeTablePrePostTextLink.Add(newLink);
_context.SaveChanges();
idLink = newLink.IdPrePostTextLink;
}
return new JsonResult(new { error = "", successful = true, idLink });
}
}
}

View File

@@ -0,0 +1,67 @@
@page
@model EveryThing.Pages.CodeTablePrePostText.IndexModel
@{
ViewData["Title"] = "Klavzule";
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">Klavzule /</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 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 klavzul
</h6>
<table class="table card-table">
<thead>
<tr>
<th>
Klavzula
</th>
<th style="width: 80px;"></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.PrePostTexts)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.ContentDisplay)
</td>
<td class="text-right">
<a class="btn btn-xs icon-btn btn-outline-secondary borderless" asp-page="AddEdit" asp-route-id="@item.IdPrePostText" data-toggle="tooltip" data-placement="top" title="Urejanje" data-state="secondary"><i class="fas fa-pencil-alt"></i></a>
</td>
</tr>
}
</tbody>
</table>
<div class="card-footer py-3 text-right">
<a asp-page="AddEdit" class="btn btn-primary">Vnos nove</a>
</div>
</div>
@section Scripts {
<script>
$('[data-toggle="tooltip"]').tooltip({container: 'table'});
</script>
}

View File

@@ -0,0 +1,49 @@
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.EntityFrameworkCore;
using EveryThing.Data;
using EveryThing.Models;
using EveryThing.Models.Transport;
using Microsoft.AspNetCore.Authorization;
namespace EveryThing.Pages.CodeTablePrePostText
{
[Authorize(Roles = "Administrator,TransportThingUser,InvoicingUser")]
public class IndexModel : PageModel
{
private readonly EveryThing.Data.ApplicationDbContext _context;
private readonly UserManager<IdentityApplicationUser> _userManager;
public IndexModel(EveryThing.Data.ApplicationDbContext context, UserManager<IdentityApplicationUser> userManager)
{
_context = context;
_userManager = userManager;
}
public IList<Models.CodeTable.CodeTablePrePostText> PrePostTexts { get;set; }
public async Task OnGetAsync(string searchString)
{
ViewData["SearchString"] = searchString;
var user = _userManager.GetUserAsync(User).Result;
PrePostTexts = await _context.CodeTablePrePostText
.Where(x => x.IdCompanyFk == user.IdCompanyFk)
.OrderByDescending(x => x.Content)
.ToListAsync();
if (!string.IsNullOrEmpty(searchString))
{
PrePostTexts = PrePostTexts.Where(x => x.Content == searchString).ToList();
}
}
}
}

View File

@@ -125,6 +125,13 @@
<a asp-page="/CodeTableVehicleFuelTypes/Index" class="sidenav-link"><i class="sidenav-icon fas fa-gas-pump"></i><div>Vrste goriva</div></a>
</li>
}
@if (User.IsInRole("Administrator") || User.IsInRole("TransportThingUser") || User.IsInRole("InvoicingUser"))
{
<li class="sidenav-item@(currentPage.StartsWith("/CodeTableVehicle/") ? " active" : "")">
<a asp-page="/CodeTablePrePostText/Index" class="sidenav-link"><i class="sidenav-icon fas fa-sticky-note"></i><div>Klavzule</div></a>
</li>
}
}
@*<li class="sidenav-item@(currentPage.StartsWith("/CodeTable") ? " active open" : "")">
<a href="javascript:void(0)" class="sidenav-link sidenav-toggle"><i class="sidenav-icon fas fa-bars"></i><div>Ostali šifranti</div></a>

View File

@@ -51,7 +51,7 @@
<div class="col-6">
<div class="form-group">
<label asp-for="TransportLoadingOrder.IdPartnerFk" class="form-label"></label>
<select asp-for="TransportLoadingOrder.IdPartnerFk" class="form-control" asp-items="ViewBag.IdPartnerFk"></select>
<select asp-for="TransportLoadingOrder.IdPartnerFk" class="form-control select2" asp-items="ViewBag.IdPartnerFk"></select>
</div>
</div>
<div class="col-6 text-right">

View File

@@ -13,6 +13,7 @@ using EveryThing.Data;
using EveryThing.Models;
using EveryThing.Models.Transport;
using DocumentFormat.OpenXml.Spreadsheet;
using EveryThing.Models.CodeTable;
namespace EveryThing.Pages.TransportLoadingOrder
{
@@ -45,18 +46,17 @@ namespace EveryThing.Pages.TransportLoadingOrder
if (id == null)
{
var prePostTexts = _context.CodeTablePrePostTextLink
.Include(x => x.CodeTablePrePostText)
.Where(x => x.CodeTablePrePostText.IdCompanyFk == user.IdCompanyFk
&& x.Link == CodeTablePrePostTextLink.LinkEnum.TransportLoadingOrder);
TransportLoadingOrder = new Models.Transport.TransportLoadingOrder
{
OrderCity = _context.CodeTableCompanies.Single(x => x.IdCompany == user.IdCompanyFk).City,
OrderDate = DateTime.Now,
PostText = "<div>Prejemnik se obvezuje izvršiti prevoz po navodilih iz naročila. Prevoz se mora izvršiti v skladu z določili CRM konvencije. " +
"Prevoznik zagotavlja zavarovano prevozniško odgovornost. V primeru, da naročenega prevoza ne opravite po navodilih, Vas bomo bremenili za " +
"vse nastale stroške. Vse morebitne spore v zvezi s tem naročilom rešuje Okrožno sodišče v Slovenj Gradcu.</div><br/>" +
"Plačilo: <b>60 dni</b> po prejemu računana e-mail: <b>eracuni@trans-fer.si</b><br/>" +
"Original račun pošljite po pošti, poleg računa priložite 2 (dva) izvoda ožigosanega CMR " +
"z datumom in podpisom prejemnika.<br/>" +
"Direkten kontakt s stranko brez našega soglasja je PREPOVEDAN!<br/>" +
"<div>Račun</div>"
PreText = string.Join("<br/>", prePostTexts.Where(x => x.Type == CodeTablePrePostTextLink.TypeEnum.PreText).Select(x => x.CodeTablePrePostText.Content)),
PostText = string.Join("<br/>", prePostTexts.Where(x => x.Type == CodeTablePrePostTextLink.TypeEnum.PostText).Select(x => x.CodeTablePrePostText.Content))
};
TransportLoadingOrderLoadUnload = new TransportLoadingOrderLoadUnload();