");
}
break;
}
// Load values again from database
$dropnbox = "'' AS `open`, CONCAT('') AS `auswahl`";
$result = $this->app->DB->SelectArr("SELECT SQL_CALC_FOUND_ROWS v.id, $dropnbox, ".$this->app->erp->FormatDate('datum')." as datum, v.versand, v.nr, v.tracking, v.versender, v.gewicht, v.bemerkung, v.status, v.id FROM versandpakete v"." WHERE id=$id");
foreach ($result[0] as $key => $value) {
$this->app->Tpl->Set(strtoupper($key), $value);
}
// Check for only one delivery adress
$this->app->YUI->AutoComplete("lieferschein", "lieferschein");
$sql = "SELECT DISTINCT a.name, l.adresse FROM (".self::SQL_VERSANDPAKETE_LIEFERSCHEIN.") vpl INNER JOIN lieferschein l ON vpl.lieferschein = l.id INNER JOIN adresse a ON l.adresse = a.id WHERE vpl.versandpaket = ".$id;
$adress_check = $this->app->DB->SelectArr($sql);
if (!empty($adress_check)) {
if (count($adress_check) != 1) {
// More than one adress for the packet -> error
} else {
$this->app->Tpl->Set('ADRESSE', $adress_check[0]['name']);
$this->app->YUI->AutoComplete("lieferschein", "kundenlieferschein",0,"&adresse=".$adress_check[0]['adresse']);
}
}
$sql = "SELECT lieferschein_ohne_pos FROM versandpakete WHERE id = ".$id;
$lieferschein_ohne_pos = $this->app->DB->SelectArr($sql);
if (!empty($lieferschein_ohne_pos[0]['lieferschein_ohne_pos'])) {
$this->app->Tpl->Set('LIEFERSCHEIN_ADD_POS_HIDDEN', 'hidden');
}
if ($result[0]['status'] != self::VERSANDPAKETE_STATUS_NEU) {
$this->app->Tpl->Set('LIEFERSCHEIN_ADD_POS_HIDDEN', 'hidden');
$this->app->Tpl->Set('LIEFERSCHEIN_POS_HIDDEN', 'hidden');
}
$this->app->YUI->TableSearch('PAKETINHALT', 'versandpakete_paketinhalt_list', "show", "", "", basename(__FILE__), __CLASS__);
$this->app->Tpl->Parse('PAGE', "versandpakete_edit.tpl");
}
function versandpakete_add() {
$this->versandpakete_menu();
$id = $this->app->Secure->GetGET('id');
if (empty($id)) {
$lieferschein = $this->app->Secure->GetGET('lieferschein');
if (empty($lieferschein)) {
$msg = $this->app->erp->base64_url_encode("
Kein Lieferschein angegeben.
");
header("Location: index.php?module=versandpakete&action=list&msg=$msg");
} else {
$lieferschein_belegnr = $this->app->erp->ReplaceLieferschein(false, $lieferschein, false); // Parameters: Target db?, value, from form?
/* Create new paket and add the given lieferschein */
$sql = "INSERT INTO versandpakete (status) VALUES ('".self::VERSANDPAKETE_STATUS_NEU."')";
$this->app->DB->Insert($sql);
$id = $this->app->DB->GetInsertId();
}
} else { // $id not empty
$lieferschein_input = $this->app->Secure->GetPOST('lieferschein');
$lieferschein = $this->app->erp->ReplaceLieferschein(true, $lieferschein_input, true); // Parameters: Target db?, value, from form?
$lieferschein_belegnr = $this->app->erp->ReplaceLieferschein(false, $lieferschein_input, true); // Parameters: Target db?, value, from form?
if (empty($lieferschein_input)) {
$msg = $this->app->erp->base64_url_encode("
Kein Lieferschein angegeben.
");
header("Location: index.php?module=versandpakete&action=edit&id=".$id."&msg=$msg");
}
}
// 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);
$input = $this->GetInput();
$submit = $this->app->Secure->GetPOST('submit');
// Check Status
$sql = "SELECT status FROM versandpakete WHERE id = ".$id." LIMIT 1";
$result = $this->app->DB->SelectArr($sql);
if ($result[0]['status'] != self::VERSANDPAKETE_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
LEFT JOIN versandpaket_lieferschein_position vlp ON vlp.lieferschein_position = lp.id
WHERE lp.lieferschein = ".$lieferschein." AND lp.artikel = ".$artikel."
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
LEFT JOIN versandpaket_lieferschein_position vlp ON vlp.lieferschein_position = lp.id
WHERE lp.lieferschein = ".$lieferschein."
GROUP BY lp.id
";
$lieferschein_positionen = $this->app->DB->SelectArr($sql);
if (empty($lieferschein_positionen)) {
$msg = "
Keine passende Lieferscheinposition gefunden.
";
break;
}
foreach($lieferschein_positionen as $lieferschein_position) {
$buchmenge = $lieferschein_position['lp_menge']-$lieferschein_position['v_menge'];
$sql = "INSERT INTO versandpaket_lieferschein_position (versandpaket, lieferschein_position, menge) VALUES (".$id.",".$lieferschein_position['lp_id'].",".$buchmenge.") ON DUPLICATE KEY UPDATE menge = '".$buchmenge."'";
$this->app->DB->Insert($sql);
}
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);
$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->Set('MESSAGE', $msg);
$this->app->Tpl->Parse('PAGE', "versandpakete_add.tpl");
}
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();
}
/**
* Get all paramters from html form and save into $input
*/
public function GetInput(): array {
$input = array();
//$input['EMAIL'] = $this->app->Secure->GetPOST('email');
$input['versand'] = $this->app->Secure->GetPOST('versand');
$input['nr'] = $this->app->Secure->GetPOST('nr');
$input['tracking'] = $this->app->Secure->GetPOST('tracking');
$input['versender'] = $this->app->Secure->GetPOST('versender');
$input['gewicht'] = $this->app->Secure->GetPOST('gewicht');
$input['bemerkung'] = $this->app->Secure->GetPOST('bemerkung');
$input['status'] = $this->app->Secure->GetPOST('status');
return $input;
}
/*
* Set all fields in the page corresponding to $input
*/
function SetInput($input) {
// $this->app->Tpl->Set('EMAIL', $input['email']);
$this->app->Tpl->Set('VERSAND', $input['versand']);
$this->app->Tpl->Set('NR', $input['nr']);
$this->app->Tpl->Set('TRACKING', $input['tracking']);
$this->app->Tpl->Set('VERSENDER', $input['versender']);
$this->app->Tpl->Set('GEWICHT', $input['gewicht']);
$this->app->Tpl->Set('BEMERKUNG', $input['bemerkung']);
$this->app->Tpl->Set('STATUS', $input['status']);
}
}