Bestellvorschlag now working

This commit is contained in:
OpenXE 2023-01-08 18:51:29 +01:00
parent 3c7e189acb
commit f76400e248
2 changed files with 158 additions and 74 deletions

View File

@ -321,6 +321,86 @@ FROM
}
}
break;
case 'bestellungen_erzeugen':
$auswahl = $this->app->Secure->GetPOST('auswahl');
$selectedIds = [];
if(empty($auswahl)) {
$msg = '<div class="error">Bitte Artikel ausw&auml;hlen.</div>';
break;
}
if(!empty($auswahl)) {
foreach ($auswahl as $selectedId) {
$selectedId = (int) $selectedId;
if ($selectedId > 0) {
$selectedIds[] = $selectedId;
}
}
}
$menge_input = $this->app->Secure->GetPOSTArray();
$mengen = array();
foreach ($selectedIds as $artikel_id) {
foreach ($menge_input as $key => $menge) {
if ((strpos($key,'menge_') === 0) && ($menge !== '')) {
$artikel = substr($key,'6');
if ($menge > 0 && $artikel == $artikel_id) {
$mengen[] = array('id' => $artikel,'menge' => $menge);
}
}
}
}
$mengen_pro_adresse = array();
foreach ($mengen as $menge) {
$sql = "SELECT adresse FROM artikel WHERE id = ".$menge['id'];
$adresse = $this->app->DB->Select($sql);
if (!empty($adresse)) {
$index = array_search($adresse, array_column($mengen_pro_adresse,'adresse'));
if ($index !== false) {
$mengen_pro_adresse[$index]['positionen'][] = $menge;
} else {
$mengen_pro_adresse[] = array('adresse' => $adresse,'positionen' => array($menge));
}
}
}
$angelegt = 0;
foreach ($mengen_pro_adresse as $bestelladresse) {
$bestellid = $this->app->erp->CreateBestellung($bestelladresse);
if (!empty($bestellid)) {
$angelegt++;
$this->app->erp->LoadBestellungStandardwerte($bestellid,$bestelladresse['adresse']);
$this->app->erp->BestellungProtokoll($bestellid,"Bestellung angelegt");
foreach ($bestelladresse['positionen'] as $position) {
$preisid = $this->app->erp->Einkaufspreis($position['id'], $position['menge'], $bestelladresse['adresse']);
if ($preisid == null) {
$artikelohnepreis = $position['id'];
} else {
$artikelohnepreis = null;
}
$this->app->erp->AddBestellungPosition(
$bestellid,
$preisid,
$position['menge'],
$datum,
'',
$artikelohnepreis
);
}
$this->app->erp->BestellungNeuberechnen($bestellid);
}
}
$msg .= "<div class=\"success\">Es wurden $angelegt Bestellungen angelegt.</div>";
break;
}
$this->app->erp->MenuEintrag("index.php?module=bestellvorschlag&action=list", "&Uuml;bersicht");
@ -331,6 +411,8 @@ FROM
$this->app->Tpl->Set('MONATE_ABSATZ',$monate_absatz);
$this->app->Tpl->Set('MONATE_VORAUS',$monate_voraus);
$this->app->Tpl->Set('MESSAGE',$msg);
$this->app->YUI->TableSearch('TAB1', 'bestellvorschlag_list', "show", "", "", basename(__FILE__), __CLASS__);
$this->app->Tpl->Parse('PAGE', "bestellvorschlag_list.tpl");
}

View File

@ -1,81 +1,83 @@
<div id="tabs-1">
[MESSAGE]
<form action="" method="post">
<div class="row">
<div class="row-height">
<div class="col-xs-14 col-md-4 col-md-height">
<div class="inside inside-full-height">
<fieldset>
<table width="100%" border="0" class="mkTableFormular">
<legend>{|Einstellungen|}</legend>
<div id="tabs">
<div id="tabs-1">
[MESSAGE]
<form action="" method="post">
<div class="row">
<div class="row-height">
<div class="col-xs-14 col-md-4 col-md-height">
<div class="inside inside-full-height">
<fieldset>
<table width="100%" border="0" class="mkTableFormular">
<legend>{|Einstellungen|}</legend>
<td>{|Absatz ber&uuml;cksichtigen (Monate)|}:</td>
<td><input type="number" min="0" name="monate_absatz" id="monate_absatz" value="[MONATE_ABSATZ]" size="20""></td>
</tr>
<tr>
<td>{|Vorausplanen (Monate)|}:</td>
<td><input type="number" min="0" name="monate_voraus" id="monate_voraus" value="[MONATE_VORAUS]" size="20""></td>
</tr>
</table>
</fieldset>
</div>
</div>
<div class="col-xs-14 col-md-8 col-md-height">
<div class="inside inside-full-height">
</div>
</div>
<div class="col-xs-14 col-md-2 col-md-height">
<div class="inside inside-full-height">
<fieldset>
<table width="100%" border="0" class="mkTableFormular">
<legend>Aktionen</legend>
<tr>
<td><button name="submit" class="ui-button-icon" style="width:100%;" value="loeschen">{|Zur&uuml;cksetzen|}</button></td>
</tr>
<tr>
<td><button name="submit" class="ui-button-icon" style="width:100%;" value="speichern">{|Speichern|}</button></td>
</tr>
<tr>
<td><button name"submit" class="ui-button-icon" style="width:100%;" value="bestellungen_erzeugen">{|Bestellungen erzeugen|}</button></td>
</tr>
</table>
</fieldset>
</div>
</div>
</div>
</div>
<div class="row">
<div class="row-height">
<div class="col-xs-14 col-md-6 col-md-height">
<div class="inside inside-full-height">
[TAB1]
<fieldset>
<table>
<tr>
<td>
<input type="checkbox" value="1" id="autoalle" />&nbsp;alle markieren&nbsp;
</td>
</tr>
</table>
</fieldset>
</div>
</div>
</div>
</div>
</form>
[TAB1NEXT]
<td>{|Absatz ber&uuml;cksichtigen (Monate)|}:</td>
<td><input type="number" min="0" name="monate_absatz" id="monate_absatz" value="[MONATE_ABSATZ]" size="20""></td>
</tr>
<tr>
<td>{|Vorausplanen (Monate)|}:</td>
<td><input type="number" min="0" name="monate_voraus" id="monate_voraus" value="[MONATE_VORAUS]" size="20""></td>
</tr>
</table>
</fieldset>
</div>
</div>
<div class="col-xs-14 col-md-8 col-md-height">
<div class="inside inside-full-height">
</div>
</div>
<div class="col-xs-14 col-md-2 col-md-height">
<div class="inside inside-full-height">
<fieldset>
<table width="100%" border="0" class="mkTableFormular">
<legend>Aktionen</legend>
<tr>
<td><button name="submit" class="ui-button-icon" style="width:100%;" value="loeschen">{|Zur&uuml;cksetzen|}</button></td>
</tr>
<tr>
<td><button name="submit" class="ui-button-icon" style="width:100%;" value="speichern">{|Speichern|}</button></td>
</tr>
<tr>
<td><button name="submit" class="ui-button-icon" style="width:100%;" value="bestellungen_erzeugen">{|Bestellungen erzeugen|}</button></td>
</tr>
</table>
</fieldset>
</div>
</div>
</div>
</div>
<div class="row">
<div class="row-height">
<div class="col-xs-14 col-md-6 col-md-height">
<div class="inside inside-full-height">
[TAB1]
<fieldset>
<table>
<tr>
<td>
<input type="checkbox" value="1" id="autoalle" />&nbsp;alle markieren&nbsp;
</td>
</tr>
</table>
</fieldset>
</div>
</div>
</div>
</div>
</form>
[TAB1NEXT]
</div>
</div>
<script>
<script>
$('#autoalle').on('change',function(){
var wert = $(this).prop('checked');
$('#bestellvorschlag_list').find('input[type="checkbox"]').prop('checked',wert);
$('#bestellvorschlag_list').find('input[type="checkbox"]').first().trigger('change');
});
</script>
$('#autoalle').on('change',function(){
var wert = $(this).prop('checked');
$('#bestellvorschlag_list').find('input[type="checkbox"]').prop('checked',wert);
$('#bestellvorschlag_list').find('input[type="checkbox"]').first().trigger('change');
});
</script>