diff --git a/upgrade/data/db_schema.json b/upgrade/data/db_schema.json index a2194ad5..bc58f6c4 100644 --- a/upgrade/data/db_schema.json +++ b/upgrade/data/db_schema.json @@ -111403,7 +111403,7 @@ "Comment": "" }, { - "Field": "sachkonto", + "Field": "kontorahmen", "Type": "int(11)", "Collation": null, "Null": "NO", diff --git a/www/pages/ajax.php b/www/pages/ajax.php index 2a8cb88b..4bf54912 100644 --- a/www/pages/ajax.php +++ b/www/pages/ajax.php @@ -2489,7 +2489,7 @@ select a.kundennummer, (SELECT name FROM adresse a2 WHERE a2.kundennummer = a.ku $adresse = $this->app->DB->Select("SELECT id FROM adresse WHERE lieferantennummer = '".$lieferant[0]."' AND lieferantennummer <> '' LIMIT 1"); } $beleg = str_replace('lieferanten','',$filtername); - $arr = $this->app->DB->SelectArr("SELECT CONCAT(id,' ',if(belegnr <> '',belegnr,'ENTWURF'),' ',lieferantennummer,' ',name) as name FROM $beleg WHERE (belegnr LIKE '%$term%' OR name LIKE '%$term%' OR lieferantennummer LIKE '$%term%') AND (status = 'angelegt' OR status = 'freigegeben') + $arr = $this->app->DB->SelectArr("SELECT CONCAT(id,' ',if(belegnr <> '',belegnr,'ENTWURF'),' ',lieferantennummer,' ',name) as name FROM $beleg WHERE (belegnr <> '') AND (belegnr LIKE '%$term%' OR name LIKE '%$term%' OR lieferantennummer LIKE '$%term%') AND (status = 'angelegt' OR status = 'freigegeben') ".($adresse?" AND adresse = '$adresse' ":'')." ".$this->app->erp->ProjektRechte('projekt')." ORDER by belegnr LIMIT 20" ); $carr = !empty($arr)?count($arr):0; diff --git a/www/pages/content/verbindlichkeit_edit.tpl b/www/pages/content/verbindlichkeit_edit.tpl index 615ceb94..1dfbbf50 100644 --- a/www/pages/content/verbindlichkeit_edit.tpl +++ b/www/pages/content/verbindlichkeit_edit.tpl @@ -1,7 +1,7 @@
@@ -21,7 +21,7 @@ [STATUSICONS]
- +
@@ -82,7 +82,7 @@ - + {|Betrag Positionen brutto|}: @@ -90,7 +90,7 @@ - + {|Betrag Positionen netto|}: @@ -122,6 +122,14 @@ + + + {|Bestellung|}: + + + + + {|Waren-/Leistungsprüfung (Einkauf)|}: @@ -129,7 +137,8 @@ - + + Wird automatisch gesetzt wenn Positionen vollständig @@ -196,11 +205,9 @@ -
[MINIDETAIL]
diff --git a/www/pages/content/verbindlichkeit_positionen.tpl b/www/pages/content/verbindlichkeit_positionen.tpl new file mode 100644 index 00000000..800d670a --- /dev/null +++ b/www/pages/content/verbindlichkeit_positionen.tpl @@ -0,0 +1,83 @@ +[POSITIONENMESSAGE] +
+
+
+
+
+
+ Offene Artikel aus Wareneingängen: +
+
+
{|Filter|}
+
    +
  • + + +
  • +
+
+
+ [PAKETDISTRIBUTION] +
+
+
+
+
+
+ + {|Aktionen|} + + + +
+
+
+
+
+
+
+
+
+
+
+
+ [POSITIONEN] +
+
+
+
+
+ + {|Aktionen|} + + + + + + + + + + + + + + + +
 {|alle markieren|}
Sachkonto: 
Steuersatz: 
+
+
+
+
+
+
+ diff --git a/www/pages/verbindlichkeit.php b/www/pages/verbindlichkeit.php index 6ba4f72f..594f9c60 100644 --- a/www/pages/verbindlichkeit.php +++ b/www/pages/verbindlichkeit.php @@ -20,6 +20,7 @@ class Verbindlichkeit { $this->app->ActionHandler("edit", "verbindlichkeit_edit"); $this->app->ActionHandler("positionen", "verbindlichkeit_positionen"); $this->app->ActionHandler("delete", "verbindlichkeit_delete"); + $this->app->ActionHandler("deletepos", "verbindlichkeit_deletepos"); $this->app->ActionHandler("dateien", "verbindlichkeit_dateien"); $this->app->ActionHandler("inlinepdf", "verbindlichkeit_inlinepdf"); $this->app->ActionHandler("positioneneditpopup", "verbindlichkeit_positioneneditpopup"); @@ -175,6 +176,232 @@ class Verbindlichkeit { $moreinfo = true; // Allow drop down details $menucol = 1; // For moredata + break; + case 'verbindlichkeit_paketdistribution_list': + $allowed['verbindlichkeit_paketdistribution_list'] = array('list'); + + $id = $app->Secure->GetGET('id'); + if (empty($id)) { + break; + } + + $verbindlichkeit = $app->DB->SelectArr("SELECT v.adresse, v.rechnung, b.belegnr FROM verbindlichkeit v LEFT JOIN bestellung b ON b.id = v.bestellung WHERE v.id = ".$id)[0]; + + $lieferant = $verbindlichkeit['adresse']; + $bestellnummer = $verbindlichkeit['belegnr']; + $rechnung = $verbindlichkeit['rechnung']; + + $heading = array('Paket-Nr.','Paket-Pos.', 'Bestellung', 'Lieferschein', 'Rechnung', 'Artikel-Nr.','Artikel','Menge','Menge offen','Eingabe','Preis',''); + $width = array( '1%', '1%', '5%', '5%', '5%', '5%', '20%', '2%', '1%', '1%', '1%', '1%'); + + $findcols = array('id','belegnr'); + $searchsql = array('p.nummer', 'p.name', 'p.bemerkung'); + + $alignright = array(8,9,11); + + $defaultorder = 1; + $defaultorderdesc = 0; + + $offen_menge = "TRIM(IF( + pd.menge > COALESCE(vp.menge,0), + pd.menge - COALESCE(vp.menge,0), + 0 + ))+0"; + + $auswahl = array ( + ' 'pd.id'], + '" hidden/>', + ['sql' => 'pd.id'], + '', + '' + ); + + $werte = array ( + '' + ); + + $preise = array ( + '' + ); + + $artikellink = array ( + '', + ['sql' => 'art.nummer'], + '' + ); + + $paketlink = array ( + '', + ['sql' => 'pa.id'], + '' + ); + + $where = "offen_menge > 0"; + + // Toggle filters + $this->app->Tpl->Add('JQUERYREADY', "$('#passende').click( function() { fnFilterColumn1( 0 ); } );"); + + for ($r = 1;$r <= 1;$r++) { + $this->app->Tpl->Add('JAVASCRIPT', ' + function fnFilterColumn' . $r . ' ( i ) + { + if(oMoreData' . $r . $name . '==1) + oMoreData' . $r . $name . ' = 0; + else + oMoreData' . $r . $name . ' = 1; + + $(\'#' . $name . '\').dataTable().fnFilter( + \'\', + i, + 0,0 + ); + } + '); + } + + $more_data1 = $this->app->Secure->GetGET("more_data1"); + if ($more_data1 == 1) { + $innerwhere .= " AND (b.belegnr LIKE '%".$bestellnummer."%' OR pa.renr LIKE '%".$rechnung."%')"; + } else { + } + // END Toggle filters + + + + $sql = " + SELECT SQL_CALC_FOUND_ROWS * FROM ( + SELECT + pa.id pa, + ".$this->app->erp->ConcatSQL($paketlink).", + ".$this->app->erp->ConcatSQL($auswahl)." AS auswahl, + if(b.belegnr LIKE '%".$bestellnummer."%',CONCAT('',b.belegnr,''),b.belegnr) AS belegnr, + pa.lsnr, + if(pa.renr LIKE '%".$rechnung."%',CONCAT('',pa.renr,''),pa.renr) AS renr, + ".$this->app->erp->ConcatSQL($artikellink).", + art.name_de, + pd.menge, + IF( + pd.menge > COALESCE(vp.menge,0), + pd.menge - COALESCE(vp.menge,0), + 0 + ) offen_menge, + ".$this->app->erp->ConcatSQL($werte).", + ".$this->app->erp->ConcatSQL($preise)." + FROM + paketannahme pa + INNER JOIN paketdistribution pd ON + pd.paketannahme = pa.id + INNER JOIN artikel art ON + art.id = pd.artikel + LEFT JOIN adresse adr ON + adr.id = pa.adresse + LEFT JOIN bestellung_position bp ON + bp.id = pd.bestellung_position + LEFT JOIN bestellung b ON + b.id = bp.bestellung + LEFT JOIN( + SELECT + paketdistribution, + SUM(menge) AS menge + FROM + verbindlichkeit_position vp + GROUP BY + paketdistribution + ) vp + ON + vp.paketdistribution = pd.id + WHERE pa.adresse = ".$lieferant." AND pd.vorlaeufig IS NULL".$innerwhere." + ) temp + "; + + $count = ""; +// $groupby = ""; + + break; + case 'verbindlichkeit_positionen': + + $allowed['verbindlichkeit_positionen'] = array('list'); + + $id = $app->Secure->GetGET('id'); + $freigabe = $app->DB->Select("SELECT freigabe FROM verbindlichkeit WHERE id = ".$id); + +// $heading = array('Paket-Nr.','Paket-Pos.', 'Bestellung', 'Artikel-Nr.','Artikel','Menge','Preis','Steuersatz','Sachkonto','Menü',''); + $heading = array('', 'Paket-Nr.','Paket-Pos.', 'Bestellung', 'Artikel-Nr.','Artikel','Menge','Preis','Steuersatz abw.','Sachkonto abw.'); + $width = array( '1%','1%', '1%' , '2%', '2%', '16%', '1%', '1%', '1%', '3%', '1%', '1%'); + + $findcols = array('id','id'); + $searchsql = array('p.nummer', 'p.name', 'p.bemerkung'); + + $alignright = array(6,7,8,9); + + $defaultorder = 1; + $defaultorderdesc = 0; + + if (empty($freigabe)) { + $deletepos = array ( + ' 'vp.id'], + '")>', + 'Conf->WFconf['defaulttheme'].'/images/delete.svg\" border=\"0\">' + ); + $heading[] = 'Menü'; + } else { + $deletepos = array(''); + } + $heading[] = ''; + + $box = "CONCAT('') AS `auswahl`"; + + $sql = " + SELECT SQL_CALC_FOUND_ROWS + vp.id, + $box, + pd.paketannahme, + pd.id paket_position, + b.belegnr, + art.nummer, + art.name_de, + vp.menge, + vp.preis, + vp.steuersatz, + CONCAT(skv.sachkonto,' ',skv.beschriftung), + ".$this->app->erp->ConcatSQL($deletepos)." + FROM + verbindlichkeit_position vp + INNER JOIN verbindlichkeit v ON + v.id = vp.verbindlichkeit + INNER JOIN paketdistribution pd ON + pd.id = vp.paketdistribution + INNER JOIN artikel art ON + art.id = pd.artikel + INNER JOIN adresse adr ON + adr.id = v.adresse + LEFT JOIN bestellung_position bp ON pd.bestellung_position = bp.id + LEFT JOIN bestellung b ON b.id = bp.bestellung + LEFT JOIN kontorahmen skv ON skv.id = vp.kontorahmen + "; + + $where = "vp.verbindlichkeit = ".$id; + + $count = ""; + break; } @@ -263,16 +490,21 @@ class Verbindlichkeit { $this->verbindlichkeit_list(); } + public function verbindlichkeit_deletepos() { + $id = (int) $this->app->Secure->GetGET('id'); + $verbindlichkeit = $this->app->DB->Select("SELECT verbindlichkeit FROM verbindlichkeit_position WHERE id ='{$id}'"); + $this->app->DB->Delete("DELETE vp FROM verbindlichkeit_position vp INNER JOIN verbindlichkeit v ON v.id = vp.verbindlichkeit WHERE vp.id = '{$id}' AND v.freigabe <> 1"); + header("Location: index.php?module=verbindlichkeit&action=edit&id=$verbindlichkeit#tabs-2"); + } + /* * Edit verbindlichkeit item * If id is empty, create a new one */ - function verbindlichkeit_edit() { + function verbindlichkeit_edit($einkauf_automatik_aus = false) { $id = $this->app->Secure->GetGET('id'); - $this->app->YUI->AARLGPositionen(true); // create iframe with positionen action - // Check if other users are editing this id if($this->app->erp->DisableModul('artikel',$id)) { @@ -292,65 +524,145 @@ class Verbindlichkeit { $input['status'] = 'angelegt'; } - if ($submit != '') + switch($submit) { + case 'speichern': + // Write to database + // Add checks here + $schreibschutz = $this->app->DB->Select("SELECT schreibschutz FROM verbindlichkeit WHERE id =".$id); - // Write to database - // Add checks here - $schreibschutz = $this->app->DB->Select("SELECT schreibschutz FROM verbindlichkeit WHERE id =".$id); + if ($schreibschutz) { + $internebemerkung = $input['internebemerkung']; + $projekt = $input['projekt']; + $kostenstelle = $input['kostenstelle']; + unset($input); + $input['internebemerkung'] = $internebemerkung; + $input['projekt'] = $this->app->erp->ReplaceProjekt(true,$projekt,true); + $input['kostenstelle'] = $this->app->DB->Select("SELECT id FROM kostenstellen WHERE nummer = '".$kostenstelle."'"); + } else { + $input['adresse'] = $this->app->erp->ReplaceLieferantennummer(true,$input['adresse'],true); // Parameters: Target db?, value, from form? + $input['rechnungsdatum'] = $this->app->erp->ReplaceDatum(true,$input['rechnungsdatum'],true); // Parameters: Target db?, value, from form? + $input['eingangsdatum'] = $this->app->erp->ReplaceDatum(true,$input['eingangsdatum'],true); // Parameters: Target db?, value, from form? + $input['skontobis'] = $this->app->erp->ReplaceDatum(true,$input['skontobis'],true); // Parameters: Target db?, value, from form? + $input['zahlbarbis'] = $this->app->erp->ReplaceDatum(true,$input['zahlbarbis'],true); // Parameters: Target db?, value, from form? + $input['projekt'] = $this->app->erp->ReplaceProjekt(true,$input['projekt'],true); + $input['kostenstelle'] = $this->app->DB->Select("SELECT id FROM kostenstellen WHERE nummer = '".$input['kostenstelle']."'"); + $input['projekt'] = $this->app->erp->ReplaceBestellung(true,$input['bestellung'],true); + if(empty($input['projekt']) && !empty($input['adresse'])) { + $input['projekt'] = $this->app->erp->GetCreateProjekt($input['adresse']); + } - if ($schreibschutz) { - $internebemerkung = $input['internebemerkung']; - $projekt = $input['projekt']; - $kostenstelle = $input['kostenstelle']; - unset($input); - $input['internebemerkung'] = $internebemerkung; - $input['projekt'] = $this->app->erp->ReplaceProjekt(true,$projekt,true); - $input['kostenstelle'] = $this->app->DB->Select("SELECT id FROM kostenstellen WHERE nummer = '".$kostenstelle."'"); - } else { - $input['adresse'] = $this->app->erp->ReplaceLieferantennummer(true,$input['adresse'],true); // Parameters: Target db?, value, from form? - $input['rechnungsdatum'] = $this->app->erp->ReplaceDatum(true,$input['rechnungsdatum'],true); // Parameters: Target db?, value, from form? - $input['eingangsdatum'] = $this->app->erp->ReplaceDatum(true,$input['eingangsdatum'],true); // Parameters: Target db?, value, from form? - $input['skontobis'] = $this->app->erp->ReplaceDatum(true,$input['skontobis'],true); // Parameters: Target db?, value, from form? - $input['zahlbarbis'] = $this->app->erp->ReplaceDatum(true,$input['zahlbarbis'],true); // Parameters: Target db?, value, from form? - $input['projekt'] = $this->app->erp->ReplaceProjekt(true,$input['projekt'],true); - $input['kostenstelle'] = $this->app->DB->Select("SELECT id FROM kostenstellen WHERE nummer = '".$input['kostenstelle']."'"); - if(empty($input['projekt']) && !empty($input['adresse'])) { - $input['projekt'] = $this->app->erp->GetCreateProjekt($input['adresse']); + if (!empty($input['adresse'])) { + $steuertyp = $this->app->DB->Select("SELECT ust_befreit FROM adresse WHERE id = ".$input['adresse']); + + if ($steuertyp > 0) { + $input['steuersatz_normal'] = '0'; + $input['steuersatz_ermaessigt'] = '0'; + } else { + $input['steuersatz_normal'] = $this->app->erp->Firmendaten("steuersatz_normal"); + $input['steuersatz_ermaessigt'] = $this->app->erp->Firmendaten("steuersatz_ermaessigt"); + } + } + + } + + $columns = "id, "; + $values = "$id, "; + $update = ""; + + $fix = ""; + + foreach ($input as $key => $value) { + $columns = $columns.$fix.$key; + $values = $values.$fix."'".$value."'"; + $update = $update.$fix.$key." = '$value'"; + + $fix = ", "; } - } - $columns = "id, "; - $values = "$id, "; - $update = ""; - - $fix = ""; + // echo($columns."
"); + // echo($values."
"); + // echo($update."
"); - foreach ($input as $key => $value) { - $columns = $columns.$fix.$key; - $values = $values.$fix."'".$value."'"; - $update = $update.$fix.$key." = '$value'"; + $sql = "INSERT INTO verbindlichkeit (".$columns.") VALUES (".$values.") ON DUPLICATE KEY UPDATE ".$update; - $fix = ", "; - } + // echo($sql); -// echo($columns."
"); -// echo($values."
"); -// echo($update."
"); + $this->app->DB->Update($sql); - $sql = "INSERT INTO verbindlichkeit (".$columns.") VALUES (".$values.") ON DUPLICATE KEY UPDATE ".$update; + if ($id == 'NULL') { + $id = $this->app->DB->GetInsertID(); + $msg = $this->app->erp->base64_url_encode("
Das Element wurde erfolgreich angelegt.
"); + header("Location: index.php?module=verbindlichkeit&action=edit&id=$id&msg=$msg"); + } else { + $this->app->Tpl->Set('MESSAGE', "
Die Einstellungen wurden erfolgreich übernommen.
"); + } + break; + case 'positionen_hinzufuegen': -// echo($sql); + $freigabeeinkauf = $this->app->DB->Select("SELECT freigabe FROM verbindlichkeit WHERE id =".$id); + if ($freigabeeinkauf) { + break; + } - $this->app->DB->Update($sql); + // Process multi action + $ids = $this->app->Secure->GetPOST('ids'); + $werte = $this->app->Secure->GetPOST('werte'); + $preise = $this->app->Secure->GetPOST('preise'); + $umsatzsteuern = $this->app->Secure->GetPOST('umsatzsteuer'); + $artikel = $this->app->Secure->GetPOST('artikel'); - if ($id == 'NULL') { - $id = $this->app->DB->GetInsertID(); - $msg = $this->app->erp->base64_url_encode("
Das Element wurde erfolgreich angelegt.
"); - header("Location: index.php?module=verbindlichkeit&action=edit&id=$id&msg=$msg"); - } else { - $this->app->Tpl->Set('MESSAGE', "
Die Einstellungen wurden erfolgreich übernommen.
"); - } + foreach ($ids as $key => $paketdistribution) { + $menge = $werte[$key]; + + if ($menge <= 0) { + continue; + } + + $preis = $preise[$key]; + $umsatzsteuer = $umsatzsteuern[$key]; + $ein_artikel = $artikel[$key]; + + $sql = "INSERT INTO verbindlichkeit_position (verbindlichkeit,paketdistribution, menge, preis, umsatzsteuer, artikel) VALUES ($id, $paketdistribution, $menge, $preis, '$umsatzsteuer', $ein_artikel)"; + + $this->app->DB->Insert($sql); + + } + break; + case 'positionen_sachkonto_speichern': + + $rechnungsfreigabe = $this->app->DB->Select("SELECT rechnungsfreigabe FROM verbindlichkeit WHERE id =".$id); + if ($rechnungsfreigabe) { + break; + } + // Process multi action + $ids = $this->app->Secure->GetPOST('auswahl'); + if (!is_array($ids)) { + break; + } + $sachkonto = $this->app->Secure->GetPOST('positionen_sachkonto'); + $kontorahmen = $this->app->erp->ReplaceKontorahmen(true,$sachkonto,false); + $sql = "update verbindlichkeit_position SET kontorahmen = '".$kontorahmen."' WHERE id IN (".implode(',',$ids).")"; + $this->app->DB->Update($sql); + break; + case 'positionen_steuersatz_speichern': + + $rechnungsfreigabe = $this->app->DB->Select("SELECT rechnungsfreigabe FROM verbindlichkeit WHERE id =".$id); + if ($rechnungsfreigabe) { + break; + } + // Process multi action + $ids = $this->app->Secure->GetPOST('auswahl'); + if (!is_array($ids)) { + break; + } + $steuersatz = $this->app->Secure->GetPOST('positionen_steuersatz'); + if (!is_numeric($steuersatz)) { + $steuersatz = 'NULL'; + } + $sql = "update verbindlichkeit_position SET steuersatz = ".$steuersatz." WHERE id IN (".implode(',',$ids).")"; + $this->app->DB->Update($sql); + break; } @@ -469,15 +781,27 @@ class Verbindlichkeit { $position['steuersatz_berechnet'] = $tmpsteuersatz; $position['steuertext_berechnet'] = $tmpsteuertext; $position['steuererloes_berechnet'] = $erloes; - + $betrag_netto += ($position['menge']*$position['preis']); $betrag_brutto += ($position['menge']*$position['preis'])*(1+($tmpsteuersatz/100)); } - + $this->app->Tpl->Set('BETRAGNETTO', $betrag_netto); $this->app->Tpl->Set('BETRAGBRUTTOPOS', round($betrag_brutto,2)); + if ($verbindlichkeit_from_db['betrag'] == round($betrag_brutto,2)) { + if (!$verbindlichkeit_from_db['freigabe'] && !$einkauf_automatik_aus) { + $this->app->DB->Update("UPDATE verbindlichkeit SET freigabe = 1 WHERE id = ".$id); + $verbindlichkeit_from_db['freigabe'] = 1; + $this->app->erp->BelegProtokoll("verbindlichkeit",$id,"Verbindlichkeit automatisch freigegeben (Einkauf)"); + $this->app->YUI->Message('success',"Verbindlichkeit automatisch freigegeben (Einkauf)"); + } + $this->app->Tpl->Set('POSITIONENMESSAGE', '
Positionen vollständig
'); + } else { + $this->app->Tpl->Set('POSITIONENMESSAGE', '
Positionen nicht vollständig. Bruttobetrag '.$verbindlichkeit_from_db['betrag'].', Summe Positionen (brutto) '.round($betrag_brutto,2).', Summe Positionen (netto) '.round($betrag_netto,2).'
'); + } + $this->app->Tpl->Set('BETRAGDISABLED', 'disabled'); } @@ -493,9 +817,9 @@ class Verbindlichkeit { */ - if ($verbindlichkeit_from_db['schreibschutz']) { + if ($verbindlichkeit_from_db['rechnungsfreigabe']) { $this->app->Tpl->Set('SAVEDISABLED','disabled'); - $this->app->Tpl->Set('MESSAGE',"
Diese Verbindlichkeit ist schreibgeschützt und darf daher nicht mehr bearbeitet werden! 
"); + $this->app->Tpl->Set('MESSAGE',"
Diese Verbindlichkeit ist schreibgeschützt und darf daher nicht mehr bearbeitet werden! 
"); } if (empty($verbindlichkeit_from_db['adresse'] || $verbindlichkeit_from_db['status'] == 'angelegt')) { @@ -506,9 +830,12 @@ class Verbindlichkeit { if ($verbindlichkeit_from_db['freigabe']) { $this->app->Tpl->Set('FREIGABEEINKAUFHIDDEN','hidden'); + $this->app->Tpl->Set('EINKAUFINFOHIDDEN','hidden'); + $this->app->Tpl->Set('POSITIONHINZUFUEGENHIDDEN','hidden'); } else { $this->app->Tpl->Set('RUECKSETZENEINKAUFHIDDEN','hidden'); - } + } + if ($verbindlichkeit_from_db['rechnungsfreigabe']) { $this->app->Tpl->Set('FREIGABEBUCHHALTUNGHIDDEN','hidden'); } else { @@ -550,6 +877,9 @@ class Verbindlichkeit { $this->app->Tpl->Set('ADRESSE', $this->app->erp->ReplaceLieferantennummer(false,$verbindlichkeit_from_db['adresse'],false)); // Convert ID to form display + $this->app->Tpl->Set('BESTELLUNG',$this->app->erp->ReplaceBestellung(false,$verbindlichkeit_from_db['bestellung'],false)); + $this->app->YUI->AutoComplete("bestellung", "lieferantenbestellung",0,"&adresse=".$verbindlichkeit_from_db['adresse']); + $this->app->YUI->CkEditor("internebemerkung"); $anzahldateien = $this->app->erp->AnzahlDateien("verbindlichkeit",$id); @@ -561,6 +891,16 @@ class Verbindlichkeit { $this->app->Tpl->Set('INLINEPDF', 'Keine Dateien vorhanden.'); } + if (empty($verbindlichkeit_from_db['freigabe'])) { + $this->app->YUI->TableSearch('PAKETDISTRIBUTION', 'verbindlichkeit_paketdistribution_list', "show", "", "", basename(__FILE__), __CLASS__); + } + + // -- POSITIONEN + $this->app->YUI->AutoComplete("positionen_sachkonto", "sachkonto", 1); + $this->app->YUI->TableSearch('POSITIONEN', 'verbindlichkeit_positionen', "show", "", "", basename(__FILE__), __CLASS__); + $this->app->Tpl->Parse('POSITIONENTAB', "verbindlichkeit_positionen.tpl"); + // -- POSITIONEN + $this->verbindlichkeit_minidetail('MINIDETAIL',false); $this->app->Tpl->Parse('PAGE', "verbindlichkeit_edit.tpl"); @@ -583,6 +923,7 @@ class Verbindlichkeit { $input['zahlungsweise'] = $this->app->Secure->GetPOST('zahlungsweise'); $input['eingangsdatum'] = $this->app->Secure->GetPOST('eingangsdatum'); $input['rechnungsdatum'] = $this->app->Secure->GetPOST('rechnungsdatum'); + $input['bestellung'] = $this->app->Secure->GetPOST('bestellung'); $input['freigabe'] = $this->app->Secure->GetPOST('freigabe')?'1':'0'; $input['rechnungsfreigabe'] = $this->app->Secure->GetPOST('rechnungsfreigabe')?'1':'0'; $input['kostenstelle'] = $this->app->Secure->GetPOST('kostenstelle'); @@ -614,7 +955,7 @@ class Verbindlichkeit { } $this->app->Tpl->Set('KURZUEBERSCHRIFT2',"$name Verbindlichkeit $belegnr"); - if ($invoiceArr['status'] === 'angelegt' || $invoiceArr['schreibschutz'] != 1) { + if ($invoiceArr['status'] === 'angelegt' || empty($invoiceArr['status'])) { $this->app->erp->MenuEintrag("index.php?module=verbindlichkeit&action=freigabe&id=$id",'Freigabe'); } } @@ -666,73 +1007,7 @@ class Verbindlichkeit { } $this->app->ExitXentral(); } - - function verbindlichkeit_positionen() { - $this->app->YUI->AARLGPositionen(false); // Render positionen editable into iframe - } - - function verbindlichkeit_positioneneditpopup() { - $cmd = $this->app->Secure->GetGET('cmd'); - if($cmd === 'getopenaccordions') - { - $accordions = $this->app->Secure->GetPOST('accordions'); - $accordions = explode('*|*',$accordions); - foreach($accordions as $k => $v) - { - if(empty($v)) - { - unset($accordions[$k]); - }else{ - $accordions[$k] = 'verbindlichkeit_accordion'.$v; - } - } - $ret = []; - if(!empty($accordions)) - { - $accordions = $this->app->User->GetParameter($accordions); - if(!empty($accordions)) - { - foreach($accordions as $v) - { - if(!empty($v['value'])) - { - $ret['accordions'][] = str_replace('verbindlichkeit_accordion','',$v['name']); - } - } - } - } - echo json_encode($ret); - $this->app->ExitXentral(); - } - if($cmd === 'setaccordion') - { - $name = $this->app->Secure->GetPOST('name'); - $active = $this->app->Secure->GetPOST('active'); - $this->app->User->SetParameter('verbindlichkeit_accordion'.$name, $active); - echo json_encode(array('success'=>1)); - $this->app->ExitXentral(); - } - $id = $this->app->Secure->GetGET('id'); - $fmodul = $this->app->Secure->GetGET('fmodul'); - $artikel= $this->app->DB->Select("SELECT artikel FROM verbindlichkeit_position WHERE id='$id' LIMIT 1"); - - // nach page inhalt des dialogs ausgeben - $filename = 'widgets/widget.auftag_position_custom.php'; - if(is_file($filename)) - { - include_once $filename; - $widget = new WidgetVerbindlichkeit_positionCustom($this->app,'PAGE'); - } else { - $widget = new WidgetVerbindlichkeit_position($this->app,'PAGE'); - } - - $sid= $this->app->DB->Select("SELECT verbindlichkeit FROM verbindlichkeit_position WHERE id='$id' LIMIT 1"); - $widget->form->SpecialActionAfterExecute('close_refresh', - "index.php?module=verbindlichkeit&action=positionen&id=$sid&fmodul=$fmodul"); - $widget->Edit(); - $this->app->BuildNavigation=false; - } - + function verbindlichkeit_freigabe() { $id = $this->app->Secure->GetGET('id'); @@ -748,7 +1023,7 @@ class Verbindlichkeit { $id = $this->app->Secure->GetGET('id'); $gotoedit = true; } - $sql = "UPDATE verbindlichkeit SET freigabe = 1 WHERE id=".$id; + $sql = "UPDATE verbindlichkeit SET freigabe = 1, schreibschutz = 1 WHERE id=".$id; $this->app->DB->Update($sql); $this->app->erp->BelegProtokoll("verbindlichkeit",$id,"Verbindlichkeit freigegeben (Einkauf)"); if ($gotoedit) { @@ -790,11 +1065,11 @@ class Verbindlichkeit { $id = $this->app->Secure->GetGET('id'); $gotoedit = true; } - $sql = "UPDATE verbindlichkeit SET freigabe = 0 WHERE id=".$id; + $sql = "UPDATE verbindlichkeit SET freigabe = 0, schreibschutz = 0 WHERE id=".$id; $this->app->DB->Update($sql); $this->app->erp->BelegProtokoll("verbindlichkeit",$id,"Verbindlichkeit rückgesetzt (Einkauf)"); if ($gotoedit) { - $this->verbindlichkeit_edit(); + $this->verbindlichkeit_edit(true); } } @@ -865,7 +1140,6 @@ class Verbindlichkeit { v.skontofestsetzen, v.freigabe, v.freigabemitarbeiter, - v.bestellung, p.abkuerzung AS projekt, v.teilprojekt, v.auftrag, @@ -914,6 +1188,86 @@ class Verbindlichkeit { $verbindlichkeit_from_db = $result[0]; } + $positionen = $this->app->DB->SelectArr("SELECT vp.id, + vp.sort, + art.name_de, + art.nummer, + vp.menge, + vp.preis, + vp.steuersatz, + if (skv.sachkonto <> 0, + CONCAT(skv.sachkonto,' ',skv.beschriftung), + ( + if (skart.sachkonto <> 0, + CONCAT(skart.sachkonto,' ',skart.beschriftung, ' (Artikel)'), + CONCAT(skadr.sachkonto,' ',skadr.beschriftung, ' (Adresse)') + ) + ) + ) AS sachkonto, + '' + FROM verbindlichkeit_position vp + INNER JOIN artikel art ON art.id = vp.artikel + LEFT JOIN verbindlichkeit v ON v.id = vp.verbindlichkeit + LEFT JOIN adresse adr ON adr.id = v.adresse + LEFT JOIN kontorahmen skv ON skv.id = vp.kontorahmen + LEFT JOIN kontorahmen skart ON skart.id = art.kontorahmen + LEFT JOIN kontorahmen skadr ON skadr.id = adr.kontorahmen + WHERE verbindlichkeit='$id' + ORDER by vp.sort ASC"); + + $tmp = new EasyTable($this->app); + $tmp->headings = array('Pos.','Artikel-Nr.','Artikel','Menge','Preis','Steuersatz','WIRDUNTENGEFÜLLTWARUMAUCHIMMER'); + $betrag_netto = 0; + $betrag_brutto = 0; + $steuer_normal = 0; + $steuer_ermaessigt = 0; + foreach ($positionen as $position) { + + $tmpsteuersatz = null; + $tmpsteuertext = null; + $erloes = null; + + $this->app->erp->GetSteuerPosition("verbindlichkeit",$position['id'],$tmpsteuersatz,$tmpsteuertext,$erloes); + + $position['steuersatz_berechnet'] = $tmpsteuersatz; + $position['steuertext_berechnet'] = $tmpsteuertext; + $position['steuererloes_berechnet'] = $erloes; + + $betrag_netto += ($position['menge']*$position['preis']); + $betrag_brutto += ($position['menge']*$position['preis'])*(1+($tmpsteuersatz/100)); + + $row = array( + $position['sort'], + $position['nummer'], + $position['name_de'], + $position['menge'], + $position['preis'], + $position['steuersatz_berechnet'], + $position['sachkonto'] + ); + $tmp->AddRow($row); + } + + $row = array( + '', + '', + '', + '', + 'Betrag Positionen netto', + 'Betrag Positionen brutto' + ); + $tmp->AddRow($row); + $row = array( + '', + '', + '', + '', + round($betrag_netto,2), + round($betrag_brutto,2) + ); + $tmp->AddRow($row); + $tmp->DisplayNew('ARTIKEL',"Sachkonto","noAction"); + $tmp = new EasyTable($this->app); $tmp->Query("SELECT zeit,bearbeiter,grund FROM verbindlichkeit_protokoll WHERE verbindlichkeit='$id' ORDER by zeit DESC",0,""); $tmp->DisplayNew('PROTOKOLL',"Protokoll","noAction");