");
$this->app->Location->execute("Location: index.php?module=versandpakete&action=list&msg=$msg");
}
// Flag lieferschein for versand
$sql = "UPDATE lieferschein SET versand_status = 1 WHERE id = ".$lieferschein." AND versand_status = 0";
$this->app->DB->Update($sql);
// Check if there is an unused paket waiting...
$sql = "SELECT
v.id,
lieferschein_ohne_pos,
l.id AS lieferschein_mit_pos
FROM
versandpakete v
LEFT JOIN versandpaket_lieferschein_position vlp ON vlp.versandpaket = v.id
LEFT JOIN lieferschein_position lp ON vlp.lieferschein_position = lp.id
LEFT JOIN lieferschein l on l.id = lp.lieferschein
WHERE
v.status = 'neu' AND
l.id IS NULL AND
v.lieferschein_ohne_pos = ".$lieferschein."
LIMIT 1
";
$waiting_paket = $this->app->DB->SelectArr($sql);
if (!empty($waiting_paket)) {
// Use existing
$msg = $this->app->erp->base64_url_encode("
Versandpaket Paket Nr. ".$waiting_paket[0]['id']." wurde zugeordnet.
");
$this->app->Location->execute("Location: index.php?module=versandpakete&action=add&id=".$waiting_paket[0]['id']."&lieferschein=".$lieferschein."&msg=$msg");
}
else {
// Create new paket and add the given lieferschein
$sql = "INSERT INTO versandpakete (status, lieferschein_ohne_pos, versender) VALUES ('neu',".$lieferschein.",'".$this->app->User->GetName()."')";
$this->app->DB->Insert($sql);
$id = $this->app->DB->GetInsertId();
$msg = $this->app->erp->base64_url_encode("
");
$this->app->Location->execute("Location: index.php?module=versandpakete&action=edit&id=".$id."&msg=$msg");
}
$lieferschein_belegnr = $this->app->erp->ReplaceLieferschein(false, $lieferschein, false); // Parameters: Target db?, value, from form?
$input['lieferschein'] = $lieferschein;
} else {
}
}
$this->app->erp->SeriennummernCheckLieferscheinWarnung(lieferschein_id: $lieferschein);
// Check if other users are editing this id
if($this->app->erp->DisableModul('versandpakete',$id))
{
return;
}
$artikel_input = $this->app->Secure->GetPOST('artikel');
$artikel = $this->app->erp->ReplaceArtikel(true, $artikel_input,true); // Parameters: Target db?, value, from form?
$menge = $this->app->Secure->GetPOST('menge');
$this->app->Tpl->Set('ID', $id);
$submit = $this->app->Secure->GetPOST('submit');
// Check Status
$sql = "SELECT status, lieferschein_ohne_pos FROM versandpakete WHERE id = ".$id." LIMIT 1";
$result = $this->app->DB->SelectArr($sql);
if ($result[0]['status'] != 'neu') {
return;
}
switch ($submit) {
case 'hinzufuegen':
if ($menge <= 0) {
$msg = "
Falsche Mengenangabe.
";
break;
}
// Find a matching lieferschein_position
$sql = "SELECT
lp.id AS lp_id,
MAX(lp.menge) AS lp_menge,
SUM(vlp.menge) AS v_menge
FROM lieferschein_position lp
INNER JOIN artikel a ON lp.artikel = a.id
LEFT JOIN versandpaket_lieferschein_position vlp ON vlp.lieferschein_position = lp.id
WHERE lp.lieferschein = ".$lieferschein." AND lp.artikel = ".$artikel." AND a.lagerartikel
GROUP BY lp.id
";
$lieferschein_positionen = $this->app->DB->SelectArr($sql);
if (empty($lieferschein_positionen)) {
$msg = "
";
}
break;
case 'lieferschein_komplett_hinzufuegen':
// Find all lieferschein_position
$sql = "SELECT
lp.id AS lp_id,
MAX(lp.menge) AS lp_menge,
SUM(vlp.menge) AS v_menge
FROM lieferschein_position lp
INNER JOIN artikel a ON lp.artikel = a. id
LEFT JOIN versandpaket_lieferschein_position vlp ON vlp.lieferschein_position = lp.id
WHERE lp.lieferschein = ".$lieferschein." AND a.lagerartikel
GROUP BY lp.id
";
$lieferschein_positionen = $this->app->DB->SelectArr($sql);
if (empty($lieferschein_positionen)) {
$msg = "
Keine passende Lieferscheinposition gefunden.
";
break;
}
$buchmenge_gesamt = 0;
foreach($lieferschein_positionen as $lieferschein_position) {
$buchmenge = $lieferschein_position['lp_menge']-$lieferschein_position['v_menge'];
if ($buchmenge <= 0) {
continue;
}
$buchmenge_gesamt += $buchmenge;
$sql = "INSERT INTO versandpaket_lieferschein_position (versandpaket, lieferschein_position, menge) VALUES (".$id.",".$lieferschein_position['lp_id'].",".$buchmenge.") ON DUPLICATE KEY UPDATE menge = menge+'".$buchmenge."'";
$this->app->DB->Insert($sql);
}
if ($buchmenge_gesamt > 0) {
$msg = $this->app->erp->base64_url_encode("
Lieferschein hinzugefügt.
");
$this->app->Location->execute("Location: index.php?module=versandpakete&action=edit&id=".$id."&msg=$msg");
}
break;
}
$this->app->Tpl->Set('LIEFERSCHEIN', $lieferschein_belegnr);
$this->app->Tpl->Set('LIEFERSCHEIN_ID', $lieferschein);
$this->app->Tpl->Set('VERSANDPAKET_ID', $id);
$this->app->YUI->AutoComplete("artikel", "artikelnummerbeleg",0,"&doctype=lieferschein&doctypeid=".$lieferschein);
// For transfer to tablesearch
$this->app->User->SetParameter('versandpakete_lieferschein', $lieferschein);
$this->app->User->SetParameter('versandpakete_versandpaket', $id);
$complete = $this->versandpakete_check_completion($lieferschein,null);
if ($complete === true) {
$this->app->Tpl->addMessage('success', 'Lieferung vollständig in Paketen.', false, 'MESSAGE');
}
else {
$this->app->Tpl->addMessage('info', 'Lieferung unvollständig.', false, 'MESSAGE');
}
$this->app->YUI->TableSearch('LIEFERSCHEININHALT', 'versandpakete_lieferschein_paket_list', "show", "", "", basename(__FILE__), __CLASS__);
$this->app->YUI->TableSearch('PAKETINHALT', 'versandpakete_paketinhalt_list', "show", "", "", basename(__FILE__), __CLASS__);
$this->app->Tpl->Add('MESSAGE', $msg);
$this->app->Tpl->Parse('PAGE', "versandpakete_add.tpl");
}
// null if versandpaket not associated with lieferschein
function versandpakete_check_completion($lieferung, $versandpaket) : ?bool {
if (!empty($lieferung)) {
$sql_where_lieferung = " AND l.id = ".$lieferung;
} else {
$sql_join_lieferschein = "
INNER JOIN (
SELECT DISTINCT
lieferschein
FROM
versandpaket_lieferschein_position vlp
INNER JOIN lieferschein_position lp ON vlp.lieferschein_position = lp.id
WHERE versandpaket = ".$versandpaket."
) lieferschein_filter
ON lieferschein_filter.lieferschein = lp.lieferschein
";
}
$sql_lieferschein_mengen = "
SELECT
belegnr,
lp.id lieferschein_position,
menge lmenge
FROM
lieferschein_position lp
INNER JOIN
artikel a ON a.id = lp.artikel
INNER JOIN
lieferschein l on l.id = lp.lieferschein
".$sql_join_lieferschein."
WHERE
a.lagerartikel
".$sql_where_lieferung."
GROUP BY
lp.id
";
// Check completion
$sql_versandmengen = "
SELECT
v.id versandpaket,
lieferschein_position,
SUM(menge) vmenge
FROM
versandpaket_lieferschein_position vlp
INNER JOIN
versandpakete v ON v.id = vlp.versandpaket
WHERE
v.status <> 'storniert'
GROUP BY
lieferschein_position
";
$sql_intermediate = "
SELECT
vmengen.versandpaket,
GROUP_CONCAT(DISTINCT lmengen.belegnr SEPARATOR ', ') lieferscheine,
SUM(lmenge) lmenge,
SUM(vmenge) vmenge
FROM
(".$sql_lieferschein_mengen.") lmengen
LEFT JOIN
(".$sql_versandmengen.") vmengen
ON lmengen.lieferschein_position = vmengen.lieferschein_position
";
$sql = "
SELECT
*,
".$this->app->YUI->IconsSQL_versandpaket()." icons
FROM
(".$sql_intermediate.") final INNER JOIN versandpakete v ON v.id = final.versandpaket
";
$completion = $this->app->DB->SelectArr($sql);
if (!empty($completion)) {
if ($completion[0]['lmenge'] == $completion[0]['vmenge']) {
return(true);
} else {
return(false);
}
} else {
return(null);
}
}
function versandpakete_minidetail() {
$id = $this->app->Secure->GetGET('id');
$table = new EasyTable($this->app);
$table->Query("SELECT SQL_CALC_FOUND_ROWS
l.belegnr as Lieferschein,
lp.sort as Pos,
a.name_de as Artikel,
a.nummer as `Artikel-Nr.`,
".$this->app->erp->FormatMenge('lp.menge')." as `Menge Lieferschein`,
".$this->app->erp->FormatMenge('SUM(vlp.menge)')." as `Menge Paket`
FROM
versandpakete v
INNER JOIN versandpaket_lieferschein_position vlp ON
v.id = vlp.versandpaket
INNER JOIN lieferschein_position lp ON
vlp.lieferschein_position = lp.id
INNER JOIN lieferschein l ON
lp.lieferschein = l.id
INNER JOIN artikel a ON
lp.artikel = a.id
WHERE vlp.versandpaket = ".$id."
GROUP BY
l.belegnr, lp.id
ORDER BY l.belegnr, lp.sort
");
$table->DisplayNew('TABLE', 'Menge Paket', 'noAction');
$this->app->Tpl->Output('table.tpl');
$this->app->ExitXentral();
}
function versandpakete_minidetaillieferschein() {
$id = $this->app->Secure->GetGET('id');
$table = new EasyTable($this->app);
$paket_link = array(
'',
['sql' => 'versandpaket'],
''
);
$table->Query("
SELECT
lp.sort AS Pos,
lp.bezeichnung,
".$this->app->erp->FormatMenge('lp.menge')." AS 'Menge',
".$this->app->erp->FormatMenge('SUM(vlp.menge)')." AS 'Menge in Versandpaketen',
GROUP_CONCAT(DISTINCT ".$this->app->erp->ConcatSQL($paket_link)." SEPARATOR ', ')
FROM
lieferschein l
INNER JOIN lieferschein_position lp ON lp.lieferschein = l.id
INNER JOIN artikel a ON lp.artikel = a.id
LEFT JOIN versandpaket_lieferschein_position vlp ON vlp.lieferschein_position = lp.id
WHERE l.id = ".$id." AND a.lagerartikel
GROUP BY lp.id"
);
$table->DisplayNew('TABLE', 'Paket', 'noAction');
$this->app->Tpl->Output('table.tpl');
$this->app->ExitXentral();
}
function versandpakete_paketmarke()
{
$id = $this->app->Secure->GetGET('id');
$this->app->erp->MenuEintrag("index.php?module=versandpakete&action=edit&id=".$id, "Zurück");
$this->versandpakete_menu();
$this->app->Tpl->Set('TABTEXT',"Paketmarke");
$versandart = $this->app->DB->SelectRow("SELECT va.id, va.modul FROM versandpakete vp INNER JOIN versandarten va ON vp.versandart = va.type WHERE vp.id = ".$id." LIMIT 1");
if (empty($versandart['modul']) || empty($versandart['id'])) {
$this->app->Tpl->addMessage('error', 'Bitte zuerst eine gültige Versandart auswählen', false, 'PAGE');
return;
}
$lieferschein = $this->app->DB->SelectRow("SELECT * FROM (".self::SQL_VERSANDPAKETE_LIEFERSCHEIN.") temp WHERE versandpaket = ".$id." LIMIT 1");
$versandmodul = $this->app->erp->LoadVersandModul($versandart['modul'], $versandart['id']);
$sql = "
SELECT
SUM(COALESCE(a.gewicht,0)*vlp.menge)
FROM
artikel a
INNER JOIN lieferschein_position lp ON
a.id = lp.artikel
INNER JOIN
versandpaket_lieferschein_position vlp ON
vlp.lieferschein_position = lp.id
WHERE vlp.versandpaket = ".$id."
";
$gewicht = $this->app->DB->Select($sql);
$versandmodul->Paketmarke('TAB1', docType: 'lieferschein', docId: $lieferschein['lieferschein'], versandpaket: $id, gewicht: $gewicht);
$this->app->Tpl->Parse('PAGE',"tabview.tpl");
}
/**
* Get all paramters from html form and save into $input
*/
public function GetInput(): array {
$input = array();
$input['gewicht'] = $this->app->Secure->GetPOST('gewicht');
$input['bemerkung'] = $this->app->Secure->GetPOST('bemerkung');
$input['tracking'] = $this->app->Secure->GetPOST('tracking');
$input['tracking_link'] = $this->app->Secure->GetPOST('tracking_link');
return $input;
}
static function versandpakete_lieferstatus_sql($app) {
$dropnbox = "'' AS `open`, CONCAT('') AS `auswahl`";
$sql_lieferschein_position = "
SELECT
l.id,
p.abkuerzung AS projekt,
l.belegnr,
l.name,
lp.menge lmenge,
SUM(vlp.menge) vmenge,
GROUP_CONCAT(vop.id) vop,
BIT_OR(COALESCE(v.status,0) IN ('versendet')) AS eins_versendet,
BIT_AND(COALESCE(v.status,0) IN ('versendet')) AS alle_versendet,
BIT_OR(COALESCE(v.status,0) IN ('abgeschlossen')) AS eins_abgeschlossen,
BIT_AND(COALESCE(v.status,0) IN ('abgeschlossen')) AS alle_abgeschlossen
FROM
lieferschein l
INNER JOIN lieferschein_position lp ON lp.lieferschein = l.id
LEFT JOIN versandpaket_lieferschein_position vlp ON vlp.lieferschein_position = lp.id
LEFT JOIN versandpakete v ON vlp.versandpaket = v.id
LEFT JOIN versandpakete vop ON vop.lieferschein_ohne_pos = l.id
LEFT JOIN projekt p ON p.id = l.projekt
WHERE
l.versand_status <> 0 AND
l.belegnr <> '' AND
(v.status <> 'storniert' OR v.status IS NULL)
GROUP BY lp.id
";
$sql_lieferschein = "
SELECT
id,
projekt,
belegnr,
name,
SUM(lmenge) lmenge,
SUM(COALESCE(vmenge,0)) vmenge,
eins_versendet,
alle_versendet,
eins_abgeschlossen,
alle_abgeschlossen,
vop
FROM (
".$sql_lieferschein_position."
) lp
GROUP BY id
";
$sql = "
SELECT SQL_CALC_FOUND_ROWS
id,
".$dropnbox.",
CONCAT('',belegnr,''),
name,
".$app->erp->FormatMenge("lmenge").",
".$app->erp->FormatMenge("vmenge").",
projekt,
".$app->YUI->IconsSQL_lieferung().",
if(vmenge > 0 OR vop IS NOT NULL,CONCAT('Conf->WFconf['defaulttheme']}/images/forward.svg\" title=\"Pakete anzeigen\" border=\"0\">'),''),
id,
alle_abgeschlossen
FROM (
".$sql_lieferschein."
) l
";
return($sql);
}
}