seriennummern rework to new table structure lieferschein

This commit is contained in:
OpenXE 2024-08-03 20:11:59 +02:00
parent ad37693818
commit 39c78c52c1
5 changed files with 314 additions and 134 deletions

View File

@ -12945,12 +12945,8 @@ DROP TABLE IF EXISTS `seriennummern`;
CREATE TABLE `seriennummern` ( CREATE TABLE `seriennummern` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`seriennummer` varchar(255) NOT NULL, `seriennummer` varchar(255) NOT NULL,
`adresse` int(11) NOT NULL,
`artikel` int(11) NOT NULL, `artikel` int(11) NOT NULL,
`beschreibung` varchar(255) NOT NULL, `beschreibung` varchar(255) NOT NULL,
`lieferung` date NOT NULL,
`lieferschein` int(11) NOT NULL,
`lieferscheinpos` int(11) NOT NULL,
`bearbeiter` varchar(255) NOT NULL, `bearbeiter` varchar(255) NOT NULL,
`logdatei` datetime NOT NULL, `logdatei` datetime NOT NULL,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)

View File

@ -91433,17 +91433,6 @@
"Privileges": "select,insert,update,references", "Privileges": "select,insert,update,references",
"Comment": "" "Comment": ""
}, },
{
"Field": "adresse",
"Type": "int(11)",
"Collation": null,
"Null": "NO",
"Key": "",
"Default": null,
"Extra": "",
"Privileges": "select,insert,update,references",
"Comment": ""
},
{ {
"Field": "artikel", "Field": "artikel",
"Type": "int(11)", "Type": "int(11)",
@ -91477,39 +91466,6 @@
"Privileges": "select,insert,update,references", "Privileges": "select,insert,update,references",
"Comment": "" "Comment": ""
}, },
{
"Field": "lieferung",
"Type": "date",
"Collation": null,
"Null": "NO",
"Key": "",
"Default": null,
"Extra": "",
"Privileges": "select,insert,update,references",
"Comment": ""
},
{
"Field": "lieferschein",
"Type": "int(11)",
"Collation": null,
"Null": "NO",
"Key": "",
"Default": null,
"Extra": "",
"Privileges": "select,insert,update,references",
"Comment": ""
},
{
"Field": "lieferscheinpos",
"Type": "int(11)",
"Collation": null,
"Null": "NO",
"Key": "",
"Default": null,
"Extra": "",
"Privileges": "select,insert,update,references",
"Comment": ""
},
{ {
"Field": "bearbeiter", "Field": "bearbeiter",
"Type": "varchar(255)", "Type": "varchar(255)",
@ -91553,6 +91509,106 @@
} }
] ]
}, },
{
"name": "seriennummern_lieferschein_position",
"collation": "utf8mb3_general_ci",
"type": "BASE TABLE",
"columns": [
{
"Field": "id",
"Type": "int(11)",
"Collation": null,
"Null": "NO",
"Key": "PRI",
"Default": null,
"Extra": "auto_increment",
"Privileges": "select,insert,update,references",
"Comment": ""
},
{
"Field": "seriennummer",
"Type": "int(11)",
"Collation": null,
"Null": "NO",
"Key": "",
"Default": null,
"Extra": "",
"Privileges": "select,insert,update,references",
"Comment": ""
},
{
"Field": "lieferschein_position",
"Type": "int(11)",
"Collation": null,
"Null": "NO",
"Key": "",
"Default": null,
"Extra": "",
"Privileges": "select,insert,update,references",
"Comment": ""
}
],
"keys": [
{
"Key_name": "PRIMARY",
"Index_type": "BTREE",
"columns": [
"id"
],
"Non_unique": ""
}
]
},
{
"name": "seriennummern_paketdistribution",
"collation": "utf8mb3_general_ci",
"type": "BASE TABLE",
"columns": [
{
"Field": "id",
"Type": "int(11)",
"Collation": null,
"Null": "NO",
"Key": "PRI",
"Default": null,
"Extra": "auto_increment",
"Privileges": "select,insert,update,references",
"Comment": ""
},
{
"Field": "seriennummer",
"Type": "int(11)",
"Collation": null,
"Null": "NO",
"Key": "",
"Default": null,
"Extra": "",
"Privileges": "select,insert,update,references",
"Comment": ""
},
{
"Field": "paketdistribution",
"Type": "int(11)",
"Collation": null,
"Null": "NO",
"Key": "",
"Default": null,
"Extra": "",
"Privileges": "select,insert,update,references",
"Comment": ""
}
],
"keys": [
{
"Key_name": "PRIMARY",
"Index_type": "BTREE",
"columns": [
"id"
],
"Non_unique": ""
}
]
},
{ {
"name": "seriennummern_log", "name": "seriennummern_log",
"collation": "utf8mb3_general_ci", "collation": "utf8mb3_general_ci",

View File

@ -150,6 +150,11 @@
<fieldset> <fieldset>
<legend>{|<!--Legend for this form area goes here>-->Aktionen|}</legend> <legend>{|<!--Legend for this form area goes here>-->Aktionen|}</legend>
<table width="100%" border="0" class="mkTableFormular"> <table width="100%" border="0" class="mkTableFormular">
<tr>
<td>
<input type="checkbox" name="allowold" id="allowold" value="1" [PRIO] size="20">{|Ausgelieferte erlauben|}
</td>
</tr>
<tr> <tr>
<td> <td>
<button name="submit" value="speichern" class="ui-button-icon" style="width:100%;">Speichern</button> <button name="submit" value="speichern" class="ui-button-icon" style="width:100%;">Speichern</button>

View File

@ -22,7 +22,7 @@
</tr> </tr>
<tr> <tr>
<td> <td>
{|Seriennummern verf&uuml;gbar|}: {|Seriennummern eingelagert|}:
</td> </td>
<td> <td>
<input type="text" value="[ANZVORHANDEN]" size="40" disabled> <input type="text" value="[ANZVORHANDEN]" size="40" disabled>
@ -68,7 +68,17 @@
</span> </span>
</label> </label>
<label for="verfuegbar"> <label for="verfuegbar">
{|Nur verf&uuml;gbare|} {|Nur eingelagerte|}
</label>
</li>
<li class="filter-item">
<label for="ausgelagert" class="switch">
<input type="checkbox" id="ausgelagert" />
<span class="slider round">
</span>
</label>
<label for="ausgelagert">
{|Nur ausgelagerte|}
</label> </label>
</li> </li>
<li class="filter-item"> <li class="filter-item">

View File

@ -33,13 +33,13 @@ class Seriennummern {
switch ($name) { switch ($name) {
case "seriennummern_list": case "seriennummern_list":
$allowed['seriennummern_list'] = array('list'); $allowed['seriennummern_list'] = array('list');
$heading = array('','','Nummer','Artikel', 'Seriennummer','Erfasst am','Eingelagert','Adresse','Lieferschein','Lieferdatum', 'Men&uuml;'); $heading = array('','','Artikel-Nr.','Artikel', 'Seriennummer','Erfasst am','Eingelagert','Adresse','Lieferschein','Lieferdatum', 'Men&uuml;');
$width = array('1%','1%','10%'); // Fill out manually later $width = array('1%','1%','10%'); // Fill out manually later
// columns that are aligned right (numbers etc) // columns that are aligned right (numbers etc)
// $alignright = array(4,5,6,7,8); // $alignright = array(4,5,6,7,8);
$findcols = array('s.id','s.id', 'a.nummer', 'a.name_de', 's.seriennummer','s.datum','s.eingelagert','ad.name','l.belegnr','l.datum','s.id'); $findcols = array('s.id','s.id', 'a.nummer', 'a.name_de', 's.seriennummer','s.datum','s.eingelagert','lh.adresse_name','lh.belegnr','lh.datum','s.id');
$searchsql = array('a.nummer', 'a.name_de', 's.seriennummer'); $searchsql = array('a.nummer', 'a.name_de', 's.seriennummer');
$defaultorder = 1; $defaultorder = 1;
@ -57,40 +57,68 @@ class Seriennummern {
$menu = "<table cellpadding=0 cellspacing=0><tr><td nowrap>" . "<a href=\"#\" onclick=DeleteDialog(\"index.php?module=seriennummern&action=delete&id=%value%\");>" . "<img src=\"themes/{$app->Conf->WFconf['defaulttheme']}/images/delete.svg\" border=\"0\"></a>" . "</td></tr></table>"; $menu = "<table cellpadding=0 cellspacing=0><tr><td nowrap>" . "<a href=\"#\" onclick=DeleteDialog(\"index.php?module=seriennummern&action=delete&id=%value%\");>" . "<img src=\"themes/{$app->Conf->WFconf['defaulttheme']}/images/delete.svg\" border=\"0\"></a>" . "</td></tr></table>";
$sql = " $lieferschein_link = array(
SELECT SQL_CALC_FOUND_ROWS '<a href="index.php?module=lieferschein&action=edit&id=',
s.id, ['sql' => 'lh.lieferschein'],
$dropnbox, '">',
CONCAT('<a href=\"index.php?module=artikel&action=edit&id=',a.id,'\">',a.nummer,'</a>') as nummer, ['sql' => 'lh.belegnr'],
a.name_de, '</a>',
s.seriennummer, );
".$app->erp->FormatDate("s.datum").",
if(s.eingelagert,'Ja','Nein'), $sql_columns = "
ad.name, s.id,
l.belegnr, $dropnbox,
".$app->erp->FormatDate("l.datum").", CONCAT('<a href=\"index.php?module=artikel&action=edit&id=',a.id,'\">',a.nummer,'</a>') as nummer,
s.id a.name_de,
FROM s.seriennummer,
".$app->erp->FormatDate("s.datum").",
if(s.eingelagert,'Ja','Nein'),
lh.adresse_name,
".$app->erp->ConcatSQL($lieferschein_link).",
".$app->erp->FormatDate("lh.datum").",
s.id
";
$sql_tables = "
seriennummern s seriennummern s
INNER JOIN INNER JOIN
artikel a ON s.artikel = a.id artikel a ON s.artikel = a.id
LEFT JOIN LEFT JOIN (
lieferschein_position lp ON lp.id = s.lieferscheinpos SELECT DISTINCT
LEFT JOIN slp.seriennummer,
lieferschein l ON l.id = lp.lieferschein a.id adresse,
LEFT JOIN a.name adresse_name,
adresse ad ON ad.id = l.adresse l.datum,
l.id lieferschein,
l.belegnr
FROM
seriennummern_lieferschein_position slp
INNER JOIN lieferschein_position lp ON
lp.id = slp.lieferschein_position
INNER JOIN lieferschein l ON
l.id = lp.lieferschein
INNER JOIN adresse a ON
a.id = l.adresse
ORDER BY
l.datum
DESC
,
l.id
DESC
) lh ON lh.seriennummer = s.id
"; ";
$artikel_id = $app->User->GetParameter('seriennummern_artikel_id'); $artikel_id = $app->User->GetParameter('seriennummern_artikel_id');
$where = "(a.id = '".$artikel_id."' OR '".$artikel_id."' = '')"; $where = "(a.id = '".$artikel_id."' OR '".$artikel_id."' = '')";
$count = "SELECT COUNT(DISTINCT s.id) FROM ".$sql_tables." WHERE ".$where;
// Toggle filters // Toggle filters
$app->Tpl->Add('JQUERYREADY', "$('#verfuegbar').click( function() { fnFilterColumn1( 0 ); } );"); $app->Tpl->Add('JQUERYREADY', "$('#verfuegbar').click( function() { fnFilterColumn1( 0 ); } );");
$app->Tpl->Add('JQUERYREADY', "$('#versendet').click( function() { fnFilterColumn2( 0 ); } );"); $app->Tpl->Add('JQUERYREADY', "$('#ausgelagert').click( function() { fnFilterColumn2( 0 ); } );");
$app->Tpl->Add('JQUERYREADY', "$('#versendet').click( function() { fnFilterColumn3( 0 ); } );");
for ($r = 1;$r <= 2;$r++) { for ($r = 1;$r <= 3;$r++) {
$app->Tpl->Add('JAVASCRIPT', ' $app->Tpl->Add('JAVASCRIPT', '
function fnFilterColumn' . $r . ' ( i ) function fnFilterColumn' . $r . ' ( i )
{ {
@ -116,17 +144,27 @@ class Seriennummern {
$more_data2 = $app->Secure->GetGET("more_data2"); $more_data2 = $app->Secure->GetGET("more_data2");
if ($more_data2 == 1) { if ($more_data2 == 1) {
$where .= " AND s.lieferscheinpos <> 0"; $where .= " AND s.eingelagert = 0";
} else { } else {
} }
$count = "SELECT count(DISTINCT s.id) FROM seriennummern s LEFT JOIN artikel a on a.id = s.artikel WHERE $where"; $more_data3 = $app->Secure->GetGET("more_data3");
// $groupby = ""; if ($more_data3 == 1) {
$where .= " AND lh.seriennummer IS NOT NULL";
} else {
}
$groupby = "GROUP BY s.id";
$sql = "SELECT SQL_CALC_FOUND_ROWS ".$sql_columns." FROM ".$sql_tables;
// echo($sql." WHERE ".$where." ".$groupby);
// echo($count);
break; break;
case "seriennummern_artikel_list": case "seriennummern_artikel_list":
$allowed['seriennummern_artikel_list'] = array('list'); $allowed['seriennummern_artikel_list'] = array('list');
$heading = array('','', 'Nummer', 'Artikel', 'Lagermenge', 'Nummern verf&uuml;gbar', 'Nummern ausgeliefert', 'Nummern gesamt', 'Men&uuml;',''); $heading = array('','', 'Artikel-Nr.', 'Artikel', 'Lagermenge', 'Nummern verf&uuml;gbar', 'Nummern ausgeliefert', 'Nummern gesamt', 'Men&uuml;','');
$width = array('1%','1%','10%'); // Fill out manually later $width = array('1%','1%','10%'); // Fill out manually later
// columns that are aligned right (numbers etc) // columns that are aligned right (numbers etc)
@ -139,7 +177,7 @@ class Seriennummern {
$defaultorder = 1; $defaultorder = 1;
$defaultorderdesc = 0; $defaultorderdesc = 0;
$aligncenter = array(); $aligncenter = array();
$alignright = array(); $alignright = array(5,6,7,8,9);
$numbercols = array(); $numbercols = array();
$sumcol = array(); $sumcol = array();
@ -168,8 +206,8 @@ class Seriennummern {
CONCAT('<a href=\"index.php?module=artikel&action=edit&id=',a.id,'\">',a.nummer,'</a>') as nummer, CONCAT('<a href=\"index.php?module=artikel&action=edit&id=',a.id,'\">',a.nummer,'</a>') as nummer,
a.name_de, a.name_de,
".$app->erp->FormatMenge('auf_lager.anzahl').", ".$app->erp->FormatMenge('auf_lager.anzahl').",
SUM(if(s.eingelagert <> 0,1,0)), SUM(if(s.eingelagert = 1,1,0)),
SUM(if(s.lieferscheinpos <> 0,1,0)), SUM(if(s.eingelagert = 0,1,0)),
SUM(if(s.id IS NULL,0,1)), SUM(if(s.id IS NULL,0,1)),
".$app->erp->ConcatSQL($menu_link).", ".$app->erp->ConcatSQL($menu_link).",
a.id a.id
@ -196,8 +234,11 @@ class Seriennummern {
"; ";
$where = "a.seriennummern <> 'keine' AND a.seriennummern <> ''"; $where = "a.seriennummern <> 'keine' AND a.seriennummern <> ''";
$count = "SELECT count(DISTINCT a.id) FROM artikel a WHERE $where";
$groupby = "GROUP BY a.id"; $groupby = "GROUP BY a.id";
$count = "SELECT count(DISTINCT a.id) FROM artikel a WHERE ".$where;
// echo($sql." WHERE ".$where." ".$groupby);
// echo($count);
break; break;
case "seriennummern_lieferscheine_list": case "seriennummern_lieferscheine_list":
@ -206,7 +247,7 @@ class Seriennummern {
$width = array('1%','1%','10%'); // Fill out manually later $width = array('1%','1%','10%'); // Fill out manually later
// columns that are aligned right (numbers etc) // columns that are aligned right (numbers etc)
// $alignright = array(4,5,6,7,8); $alignright = array(6,7,8,9);
$findcols = array('l.id','l.id', 'l.belegnr', 'l.datum', 'adr.name', 'null', 'null', 'null', 'null', 'null'); $findcols = array('l.id','l.id', 'l.belegnr', 'l.datum', 'adr.name', 'null', 'null', 'null', 'null', 'null');
$searchsql = array('l.belegnr'); $searchsql = array('l.belegnr');
@ -214,7 +255,6 @@ class Seriennummern {
$defaultorder = 1; $defaultorder = 1;
$defaultorderdesc = 0; $defaultorderdesc = 0;
$aligncenter = array(); $aligncenter = array();
$alignright = array();
$numbercols = array(); $numbercols = array();
$sumcol = array(); $sumcol = array();
@ -230,31 +270,48 @@ class Seriennummern {
'</a>', '</a>',
); );
$lieferschein_link = array(
'<a href="index.php?module=lieferschein&action=edit&id=',
['sql' => 'l.id'],
'">',
['sql' => 'l.belegnr'],
'</a>',
);
$sql = "SELECT SQL_CALC_FOUND_ROWS $sql = "SELECT SQL_CALC_FOUND_ROWS
l.id, l.id,
$dropnbox, $dropnbox,
l.belegnr, ".$app->erp->ConcatSQL($lieferschein_link).",
".$app->erp->FormatDate("l.datum").", ".$app->erp->FormatDate("l.datum").",
adr.name, adr.name,
".$app->erp->FormatMengeFuerFormular("SUM(menge)").", ".$app->erp->FormatMengeFuerFormular("menge").",
".$app->erp->FormatMengeFuerFormular("COUNT(s.id)").", SUM(if(slp.id IS NULL,0,1)),
".$app->erp->FormatMengeFuerFormular("SUM(menge)-COUNT(s.id)").", ".$app->erp->FormatMengeFuerFormular("menge-SUM(if(slp.id IS NULL,0,1))").",
".$app->erp->ConcatSQL($menu_link).", ".$app->erp->ConcatSQL($menu_link).",
l.id l.id
FROM FROM
lieferschein_position lp lieferschein_position lp
LEFT JOIN seriennummern_lieferschein_position slp
ON slp.lieferschein_position = lp.id
INNER JOIN lieferschein l ON INNER JOIN lieferschein l ON
l.id = lp.lieferschein l.id = lp.lieferschein
INNER JOIN artikel a ON INNER JOIN artikel a ON
a.id = lp.artikel a.id = lp.artikel
INNER JOIN adresse adr ON INNER JOIN adresse adr ON
adr.id = l.adresse adr.id = l.adresse
LEFT JOIN seriennummern s ON
lp.id = s.lieferscheinpos
"; ";
$where = "(a.seriennummern <> 'keine') AND (l.datum >= (SELECT MIN(datum) FROM seriennummern WHERE artikel = a.id))"; $where = "(a.seriennummern <> 'keine') AND (l.datum >= (SELECT MIN(datum) FROM seriennummern WHERE artikel = a.id))";
$count = ""; $count = "SELECT COUNT(DISTINCT lp.lieferschein) FROM
lieferschein_position lp
LEFT JOIN seriennummern_lieferschein_position slp
ON slp.lieferschein_position = lp.id
INNER JOIN lieferschein l ON
l.id = lp.lieferschein
INNER JOIN artikel a ON
a.id = lp.artikel
"." WHERE ".$where;
$groupby = "GROUP BY l.id"; $groupby = "GROUP BY l.id";
break; break;
} }
@ -299,6 +356,29 @@ class Seriennummern {
} }
} }
function seriennummern_delivery_note_check_and_message($lieferschein_id) {
$check_delivery_notes = $this->seriennummern_check_delivery_notes($lieferschein_id);
if (!empty($check_delivery_notes)) {
$lieferschein_minus_id_links = array();
$lieferschein_plus_id_links = array();
foreach ($check_delivery_notes as $lieferschein_id) {
if ($lieferschein_id['anzahl_nummern'] < $lieferschein_id['menge']) {
$lieferschein_minus_id_links[] = '<a href="index.php?module=seriennummern&action=enter&lieferschein='.$lieferschein_id['id'].'">'.$lieferschein_id['nummer'].'</a>';
}
else if ($lieferschein_id['anzahl_nummern'] > $lieferschein_id['menge']) {
$lieferschein_plus_id_links[] = '<a href="index.php?module=seriennummern&action=nummern_list&lieferschein='.$lieferschein_id['id'].'">'.$lieferschein_id['nummer'].'</a>';
}
}
if (!empty($lieferschein_minus_id_links)) {
$this->app->YUI->Message('warning','Seriennummern fehlen f&uuml;r Lieferschein: '.implode(', ',$lieferschein_minus_id_links));
}
if (!empty($lieferschein_plus_id_links)) {
$this->app->YUI->Message('warning','Seriennummern Überschuss f&uuml;r Lieferschein: '.implode(', ',$lieferschein_plus_id_links));
}
}
}
function seriennummern_nummern_list() { function seriennummern_nummern_list() {
$this->seriennummern_menu(); $this->seriennummern_menu();
@ -342,6 +422,7 @@ class Seriennummern {
} }
$this->seriennummern_check_and_message($artikel_id); $this->seriennummern_check_and_message($artikel_id);
$this->seriennummern_delivery_note_check_and_message(null);
$this->app->YUI->TableSearch('TAB1', 'seriennummern_list', "show", "", "", basename(__FILE__), __CLASS__); $this->app->YUI->TableSearch('TAB1', 'seriennummern_list', "show", "", "", basename(__FILE__), __CLASS__);
@ -351,6 +432,7 @@ class Seriennummern {
function seriennummern_artikel_list() { function seriennummern_artikel_list() {
$this->seriennummern_menu(); $this->seriennummern_menu();
$this->seriennummern_check_and_message(null); $this->seriennummern_check_and_message(null);
$this->seriennummern_delivery_note_check_and_message(null);
$this->app->YUI->TableSearch('TAB1', 'seriennummern_artikel_list', "show", "", "", basename(__FILE__), __CLASS__); $this->app->YUI->TableSearch('TAB1', 'seriennummern_artikel_list', "show", "", "", basename(__FILE__), __CLASS__);
@ -360,6 +442,7 @@ class Seriennummern {
function seriennummern_lieferscheine_list() { function seriennummern_lieferscheine_list() {
$this->seriennummern_menu(); $this->seriennummern_menu();
$this->seriennummern_check_and_message(null); $this->seriennummern_check_and_message(null);
$this->seriennummern_delivery_note_check_and_message(null);
$this->app->YUI->TableSearch('TAB1', 'seriennummern_lieferscheine_list', "show", "", "", basename(__FILE__), __CLASS__); $this->app->YUI->TableSearch('TAB1', 'seriennummern_lieferscheine_list', "show", "", "", basename(__FILE__), __CLASS__);
@ -369,11 +452,11 @@ class Seriennummern {
public function seriennummern_delete() { public function seriennummern_delete() {
$id = (int) $this->app->Secure->GetGET('id'); $id = (int) $this->app->Secure->GetGET('id');
if ($this->app->DB->Select("SELECT id FROM `seriennummern` WHERE `id` = '{$id}' AND `lieferscheinpos` = 0")) { if (!$this->app->DB->Select("SELECT id FROM `seriennummern_lieferschein_position` WHERE `seriennummer` = '{$id}'")) {
$this->app->DB->Delete("DELETE FROM `seriennummern` WHERE `id` = '{$id}' AND `lieferscheinpos` = 0"); $this->app->DB->Delete("DELETE FROM `seriennummern` WHERE `id` = '{$id}'");
$this->app->Tpl->addMessage('error', 'Der Eintrag wurde gel&ouml;scht'); $this->app->Tpl->addMessage('error', 'Der Eintrag wurde gel&ouml;scht');
} else { } else {
$this->app->Tpl->addMessage('error', 'Der Eintrag kann nicht gel&ouml;scht werden!'); $this->app->Tpl->addMessage('error', 'Der Eintrag kann nicht gel&ouml;scht werden da eine Lieferscheinzuordnung existiert!');
} }
$this->seriennummern_nummern_list(); $this->seriennummern_nummern_list();
} }
@ -382,12 +465,14 @@ class Seriennummern {
$this->app->erp->MenuEintrag("index.php?module=seriennummern&action=list", "Zur&uuml;ck zur &Uuml;bersicht"); $this->app->erp->MenuEintrag("index.php?module=seriennummern&action=list", "Zur&uuml;ck zur &Uuml;bersicht");
$artikel_id = (int) $this->app->Secure->GetGET('artikel'); $artikel_id = (int) $this->app->Secure->GetGET('artikel');
$lieferschein_id = (int) $this->app->Secure->GetGET('lieferschein');
$artikel = $this->app->DB->SelectRow("SELECT name_de, nummer FROM artikel WHERE id ='".$artikel_id."'"); $artikel = $this->app->DB->SelectRow("SELECT name_de, nummer FROM artikel WHERE id ='".$artikel_id."'");
$this->app->Tpl->SetText('KURZUEBERSCHRIFT1','Erfassen'); $this->app->Tpl->SetText('KURZUEBERSCHRIFT1','Erfassen');
$this->app->Tpl->SetText('KURZUEBERSCHRIFT2',$artikel['name_de']." (Artikel ".$artikel['nummer'].")"); $this->app->Tpl->SetText('KURZUEBERSCHRIFT2',$artikel['name_de']." (Artikel ".$artikel['nummer'].")");
$allowold = $this->app->Secure->GetPOST('allowold');
$submit = $this->app->Secure->GetPOST('submit'); $submit = $this->app->Secure->GetPOST('submit');
$seriennummern = array(); $seriennummern = array();
@ -403,6 +488,8 @@ class Seriennummern {
break; break;
case 'speichern': case 'speichern':
$seriennummern_not_written = array(); $seriennummern_not_written = array();
$seriennummern_already_exist = array();
$seriennummern_old_not_allowed = array();
foreach ($seriennummern as $seriennummer) { foreach ($seriennummern as $seriennummer) {
$seriennummer = trim($seriennummer); $seriennummer = trim($seriennummer);
@ -411,18 +498,40 @@ class Seriennummern {
continue; continue;
} }
$sql = "INSERT INTO seriennummern (seriennummer, artikel, logdatei, eingelagert) VALUES ('".$this->app->DB->real_escape_string($seriennummer)."', '".$artikel_id."', CURRENT_TIMESTAMP, 1)"; $sql = "SELECT id, eingelagert FROM seriennummern WHERE seriennummer = '".$this->app->DB->real_escape_string($seriennummer)."' AND artikel = '".$artikel_id."'";
try { $check_existing = $this->app->DB->SelectRow($sql);
$this->app->DB->Insert($sql);
} catch (mysqli_sql_exception $e) { if (empty($check_existing)) { // New serial
$error = true; $sql = "INSERT INTO seriennummern (seriennummer, artikel, logdatei, eingelagert) VALUES ('".$this->app->DB->real_escape_string($seriennummer)."', '".$artikel_id."', CURRENT_TIMESTAMP, 1)";
$seriennummern_not_written[] = $seriennummer; try {
$this->app->DB->Insert($sql);
} catch (mysqli_sql_exception $e) {
$error = true;
$seriennummern_not_written[] = $seriennummer;
}
} else {
if ($check_existing['eingelagert']) { // Old serial, already here
$seriennummern_already_exist[] = $seriennummer;
} else { // Old serial, returning
if ($allowold) {
$sql = "UPDATE seriennummern SET eingelagert = 1, logdatei = CURRENT_TIMESTAMP WHERE seriennummer = '".$this->app->DB->real_escape_string($seriennummer)."' AND artikel = '".$artikel_id."'";
$this->app->DB->Update($sql);
} else {
$seriennummern_old_not_allowed[] = $seriennummer;
}
}
} }
} }
if ($error) { if (!empty($seriennummern_already_exist)) {
$this->app->Tpl->addMessage('error', 'Einige Seriennummern konnten nicht gespeichert werden.'); $this->app->Tpl->addMessage('error', 'Seriennummern existieren bereits: '.implode(', ',$seriennummern_already_exist));
} }
$seriennummern = $seriennummern_not_written; if (!empty($seriennummern_old_not_allowed)) {
$this->app->Tpl->addMessage('error', 'Seriennummern bereits ausgeliefert: '.implode(', ',$seriennummern_old_not_allowed));
}
if (!empty($seriennummern_not_written)) {
$this->app->Tpl->addMessage('error', 'Seriennummern konnten nicht gespeichert werden: '.implode(', ',$seriennummern_not_written));
}
$seriennummern = array_merge($seriennummern_not_written, $seriennummern_already_exist, $seriennummern_old_not_allowed);
break; break;
case 'assistent': case 'assistent':
$praefix = $this->app->Secure->GetPOST('praefix'); $praefix = $this->app->Secure->GetPOST('praefix');
@ -508,11 +617,9 @@ class Seriennummern {
LEFT JOIN( LEFT JOIN(
SELECT SELECT
artikel, artikel,
COUNT(id) anzahl SUM(if(eingelagert,1,0)) anzahl
FROM FROM
seriennummern seriennummern
WHERE
lieferscheinpos = 0
GROUP BY GROUP BY
artikel artikel
) nummern_verfuegbar ) nummern_verfuegbar
@ -530,29 +637,35 @@ class Seriennummern {
* Check if all delivery notes have serials * Check if all delivery notes have serials
* Return array of delivery note positions and head information * Return array of delivery note positions and head information
*/ */
public function seriennummern_check_deliver_notes($lieferschein_id = null) : array { public function seriennummern_check_delivery_notes($lieferschein_id = null) : array {
$sql = " $sql = "
SELECT SELECT SQL_CALC_FOUND_ROWS
l.id lieferschein, l.id,
l.datum, l.belegnr nummer,
l.belegnr lieferschein_belegnr, menge,
lp.id lieferschein_position, SUM(IF(slp.id IS NULL, 0, 1)) menge_nummern
a.nummer, FROM
menge, lieferschein_position lp
COUNT(s.id) anzahl_nummern, LEFT JOIN seriennummern_lieferschein_position slp ON
GROUP_CONCAT(s.seriennummer) slp.lieferschein_position = lp.id
FROM INNER JOIN lieferschein l ON
lieferschein_position lp l.id = lp.lieferschein
INNER JOIN lieferschein l ON INNER JOIN artikel a ON
l.id = lp.lieferschein a.id = lp.artikel
INNER JOIN artikel a ON WHERE
a.id = lp.artikel (a.seriennummern <> 'keine') AND(
LEFT JOIN seriennummern s ON l.datum >=(
lp.id = s.lieferscheinpos SELECT
WHERE (l.id = '".$lieferschein_id."' OR '".$lieferschein_id."' = '') MIN(datum)
GROUP BY FROM
lp.id seriennummern
HAVING menge > anzahl_nummern WHERE
artikel = a.id
)
) AND (l.id = '".$lieferschein_id."' OR '".$lieferschein_id."' = '')
GROUP BY
l.id
HAVING menge > menge_nummern
"; ";
$result = $this->app->DB->SelectArr($sql); $result = $this->app->DB->SelectArr($sql);
@ -617,8 +730,8 @@ class Seriennummern {
* Check if numbers need to be entered after stock removal, if yes, create notification * Check if numbers need to be entered after stock removal, if yes, create notification
*/ */
public function seriennummern_check_and_message_delivery_note_removed(int $lieferschein_id) { public function seriennummern_check_and_message_delivery_note_removed(int $lieferschein_id) {
$check_deliver_notes = $this->seriennummern_check_deliver_notes($lieferschein_id); $check_delivery_notes = $this->seriennummern_check_delivery_notes($lieferschein_id);
if (!empty($check_deliver_notes)) { if (!empty($check_delivery_notes)) {
$this->seriennummern_create_notification_lieferschein($lieferschein_id, 'enter', 'Seriennummern','Bitte Seriennummern f&uuml;r Lieferschein erfassen','Zur Eingabe'); $this->seriennummern_create_notification_lieferschein($lieferschein_id, 'enter', 'Seriennummern','Bitte Seriennummern f&uuml;r Lieferschein erfassen','Zur Eingabe');
} }
} }