mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-01 12:19:28 +00:00
This commit is contained in:
@@ -0,0 +1,295 @@
|
||||
<?php
|
||||
/* Copyright (C) 2010 Technikum-Wien
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Authors: Christian Paminger <christian.paminger@technikum-wien.at>,
|
||||
* Andreas Oesterreicher <andreas.oesterreicher@technikum-wien.at> and
|
||||
* Karl Burkhart <burkhart@technikum-wien.at>.
|
||||
*/
|
||||
/**
|
||||
* Klasse WaWi Bestelldetail
|
||||
*/
|
||||
require_once(dirname(__FILE__).'/basis_db.class.php');
|
||||
|
||||
class wawi_bestelldetail extends basis_db
|
||||
{
|
||||
public $bestelldetail_id; // serial
|
||||
public $bestellung_id; // integer
|
||||
public $position; // integer
|
||||
public $menge; // integer
|
||||
public $verpackungseinheit; // char
|
||||
public $beschreibung; // text
|
||||
public $artikelnummer; // char
|
||||
public $preisprove; // numeric
|
||||
public $mwst; // numeric
|
||||
public $erhalten; // bool
|
||||
public $sort; // integer
|
||||
public $text; // bool
|
||||
public $insertamum; // timestamp
|
||||
public $insertvon; // char
|
||||
public $updateamum; // timestamp
|
||||
public $updatevon; // char
|
||||
|
||||
public $result = array();
|
||||
public $user;
|
||||
public $new;
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @param unknown_type $bestelldetail_id
|
||||
*/
|
||||
public function __construct($bestelldetail_id = null)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
if(!is_null($bestelldetail_id))
|
||||
$this->load($bestelldetail_id);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @param unknown_type $bestelldetail_id
|
||||
*/
|
||||
public function load($bestelldetail_id)
|
||||
{
|
||||
if(!is_numeric($bestelldetail_id))
|
||||
{
|
||||
$this->errormsg ='Keine gültige Bestell ID.';
|
||||
return false;
|
||||
}
|
||||
|
||||
$qry = 'SELECT * FROM wawi.tbl_bestelldetail WHERE bestelldetail_id = '.$this->addslashes($bestelldetail_id).';';
|
||||
|
||||
if(!$this->db_query($qry))
|
||||
{
|
||||
$this->errormsg = 'Fehler bei Datenbankabfrage.';
|
||||
return false;
|
||||
}
|
||||
|
||||
if($row = $this->db_fetch_object())
|
||||
{
|
||||
$this->bestelldetail_id = $row->bestelldetail_id;
|
||||
$this->bestellung_id = $row->bestellung_id;
|
||||
$this->positoin = $row->position;
|
||||
$this->menge = $row->menge;
|
||||
$this->verpackungseinheit = $row->verpackungseinheit;
|
||||
$this->beschreibung = $row->beschreibung;
|
||||
$this->artikelnummer = $row->artikelnummer;
|
||||
$this->preisprove = $row->preisprove;
|
||||
$this->mwst = $row->mwst;
|
||||
$this->erhalten = $row->erhalten;
|
||||
$this->sort = $row->sort;
|
||||
$this->text = $row->text;
|
||||
$this->insertamum = $row->insertamum;
|
||||
$this->insertvon = $row->insertvon;
|
||||
$this->updateamum = $row->updateamum;
|
||||
$this->updatevon = $row->updatevon;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
*/
|
||||
public function getAll()
|
||||
{
|
||||
$qry ='SELECT * FROM wawi.tbl_bestelldetail;';
|
||||
|
||||
if(!$this->db_query($qry))
|
||||
{
|
||||
$this->errormsg = 'Fehler bei Datenbankabfrage.';
|
||||
return false;
|
||||
}
|
||||
while($row = $this->db_fetch_object())
|
||||
{
|
||||
$detail = new wawi_bestelldetail();
|
||||
|
||||
$detail->bestelldetail_id = $row->bestelldetail_id;
|
||||
$detail->bestellung_id = $row->bestellung_id;
|
||||
$detail->positoin = $row->position;
|
||||
$detail->menge = $row->menge;
|
||||
$detail->verpackungseinheit = $row->verpackungseinheit;
|
||||
$detail->beschreibung = $row->beschreibung;
|
||||
$detail->artikelnummer = $row->artikelnummer;
|
||||
$detail->preisprove = $row->preisprove;
|
||||
$detail->mwst = $row->mwst;
|
||||
$detail->erhalten = $row->erhalten;
|
||||
$detail->sort = $row->sort;
|
||||
$detail->text = $row->text;
|
||||
$detail->insertamum = $row->insertamum;
|
||||
$detail->insertvon = $row->insertvon;
|
||||
$detail->updateamum = $row->updateamum;
|
||||
$detail->updatevon = $row->updatevon;
|
||||
|
||||
$detail->result = $detail;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @param unknown_type $bestelldetail_id
|
||||
*/
|
||||
public function delete($bestelldetail_id)
|
||||
{
|
||||
if(!is_numeric($bestelldetail_id))
|
||||
{
|
||||
$this->errormsg = 'Keine gültige Bestell ID.';
|
||||
return false;
|
||||
}
|
||||
|
||||
$qry = 'DELETE FROM wawi.tbl_bestelldetail WHERE bestelldetail_id ='.$this->addslashes($bestelldetail_id).';';
|
||||
|
||||
if(!$this->db_query($qry))
|
||||
{
|
||||
$this->errormsg = 'Fehler beim löschen des Betstelldetails.';
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
*/
|
||||
public function validate()
|
||||
{
|
||||
|
||||
if(!is_numeric($this->bestelldetail_id))
|
||||
{
|
||||
$this->errormsg = "Bestelldetail_id fehlerhaft.";
|
||||
return false;
|
||||
}
|
||||
if(!is_numeric($this->bestellung_id))
|
||||
{
|
||||
$this->errormsg = "Bestellung_id fehlerhaft.";
|
||||
return false;
|
||||
}
|
||||
if(!is_numeric($this->position))
|
||||
{
|
||||
$this->errormsg = "Position fehlerhaft.";
|
||||
return false;
|
||||
}
|
||||
if(!is_numeric($this->menge))
|
||||
{
|
||||
$this->errormsg = "Menge fehlerhaft.";
|
||||
return false;
|
||||
}
|
||||
if(mb_strlen($this->verpackungseinheit)>16)
|
||||
{
|
||||
$this->errormsg ="Verpackungseinheit fehlerhaft.";
|
||||
return false;
|
||||
}
|
||||
if(mb_strlen($this->artikelnummer)>32)
|
||||
{
|
||||
$this->errormsg ="Artikelnummer fehlerhaft.";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function save()
|
||||
{
|
||||
if(!$this->validate())
|
||||
return false;
|
||||
|
||||
if($this->new)
|
||||
{
|
||||
// insert
|
||||
$qry ='BEGIN; INSERT INTO wawi.tbl_bestelldetail (bestellung_id, position, menge, verpackungseinheit, beschreibung, artikelnummer,
|
||||
preisprove, mwst, erhalten, sort, text, insertamum, insertvon, updateamum, updatevon) VALUES ('.
|
||||
$this->addslashes($this->bestellung_id).', '.
|
||||
$this->addslashes($this->position).', '.
|
||||
$this->addslashes($this->menge).', '.
|
||||
$this->addslashes($this->verpackungseinheit).', '.
|
||||
$this->addslashes($this->beschreibung).', '.
|
||||
$this->addslashes($this->artikelnummer).', '.
|
||||
$this->addslashes($this->preisprove).', '.
|
||||
$this->addslashes($this->mwst).', '.
|
||||
$this->addslashes($this->erhalten).', '.
|
||||
$this->addslashes($this->sort).', '.
|
||||
$this->addslashes($this->text).', '.
|
||||
$this->addslashes($this->insertamum).', '.
|
||||
$this->addslashes($this->insertvon).', '.
|
||||
$this->addslashes($this->updateamum).', '.
|
||||
$this->addslashes($this->updatevon).'); ';
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// Update
|
||||
$qry = 'UPDATE wawi.tbl_bestellung SET
|
||||
bestellung_id = '.$this->bestellung_id.',
|
||||
position = '.$this->position.',
|
||||
menge = '.$this->menge.',
|
||||
verpackungseinheit = '.$this->verpackungseinheit.',
|
||||
beschreibung = '.$this->beschreibung.',
|
||||
artikelnummer = '.$this->artikelnummer.',
|
||||
preisprove = '.$this->preisprove.',
|
||||
mwst = '.$this->mwst.',
|
||||
erhalten = '.$this->erhalten.',
|
||||
sort = '.$this->sort.',
|
||||
text = '.$this->text.',
|
||||
insertamum = '.$this->insertamum.',
|
||||
insertvon = '.$this->insertvon.',
|
||||
updateamum = '.$this->updateamum.',
|
||||
updatevon = '.$this->updatevon.' WHERE bestelldetail_id = '.$this->bestelldetail_id.';';
|
||||
}
|
||||
|
||||
if($this->db_query($qry))
|
||||
{
|
||||
if($this->new)
|
||||
{
|
||||
//aktuelle Sequence holen
|
||||
$qry="SELECT currval('seq_bestelldetail_bestelldetail_id') as id;";
|
||||
if($this->db_query($qry))
|
||||
{
|
||||
if($row = $this->db_fetch_object())
|
||||
{
|
||||
$this->bestelldetail_id = $row->id;
|
||||
$this->db_query('COMMIT');
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db_query('ROLLBACK');
|
||||
$this->errormsg = "Fehler beim Auslesen der Sequence";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db_query('ROLLBACK');
|
||||
$this->errormsg = 'Fehler beim Auslesen der Sequence';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return $this->bestelldetail_id;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -50,8 +50,8 @@ class wawi_bestellung extends basis_db
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @param unknown_type $bestellung_id
|
||||
* Konstruktor
|
||||
* @param bestellung_id der Bestellung die geladen werden soll (Default=null)
|
||||
*/
|
||||
public function __construct($bestellung_id = null)
|
||||
{
|
||||
@@ -64,8 +64,8 @@ class wawi_bestellung extends basis_db
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @param unknown_type $bestellung_id
|
||||
* Lädt die Bestellung mit der Übergebenen ID
|
||||
* @param $bestellung_id der zu ladenden Bestellung
|
||||
*/
|
||||
public function load($bestellung_id)
|
||||
{
|
||||
@@ -113,7 +113,7 @@ class wawi_bestellung extends basis_db
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* Gibt alle Bestellungen zurück
|
||||
*/
|
||||
public function getAll()
|
||||
{
|
||||
@@ -154,8 +154,188 @@ class wawi_bestellung extends basis_db
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @param unknown_type $bestellung_id
|
||||
* Übernimmt die Parameter (Formular --> Bestellung suchen) und gibt die gefundenen Bestellungen zurück
|
||||
* @param $bestellnr
|
||||
* @param $titel
|
||||
* @param $evon
|
||||
* @param $ebis
|
||||
* @param $bvon
|
||||
* @param $bbis
|
||||
* @param $firma_id
|
||||
* @param $oe_kurzbz
|
||||
* @param $konto_id
|
||||
* @param $mitarbeiter_uid
|
||||
* @param $rechnung
|
||||
*/
|
||||
public function getAllSearch($bestellnr, $titel, $evon, $ebis, $bvon, $bbis, $firma_id, $oe_kurzbz, $konto_id, $mitarbeiter_uid, $rechnung )
|
||||
{
|
||||
$first = true;
|
||||
$qry = "SELECT distinct on (bestellung.bestellung_id) *, status.updateamum as update, bestellung.updatevon as update_von, bestellung.insertamum as insert, bestellung.insertvon as insert_von
|
||||
FROM
|
||||
wawi.tbl_bestellung bestellung
|
||||
|
||||
LEFT JOIN wawi.tbl_bestellung_bestellstatus status USING (bestellung_id)
|
||||
LEFT JOIN wawi.tbl_kostenstelle kostenstelle USING (kostenstelle_id)
|
||||
LEFT JOIN public.tbl_organisationseinheit orgaeinheit ON (orgaeinheit.oe_kurzbz = kostenstelle.oe_kurzbz) ";
|
||||
|
||||
if ($bestellnr != '')
|
||||
{
|
||||
if($first == true)
|
||||
{
|
||||
$qry.= 'where ';
|
||||
$first = false;
|
||||
}
|
||||
else
|
||||
$qry.= ' and ';
|
||||
$qry.= " UPPER(bestellung.bestell_nr) LIKE UPPER('%$bestellnr%')";
|
||||
}
|
||||
if ($titel != '')
|
||||
{
|
||||
if($first == true)
|
||||
{
|
||||
$qry.= 'where ';
|
||||
$first = false;
|
||||
}
|
||||
else
|
||||
$qry.= ' and ';
|
||||
$qry.= " UPPER(bestellung.titel) LIKE UPPER('%$titel%')";
|
||||
}
|
||||
if ($evon != '')
|
||||
{
|
||||
if($first == true)
|
||||
{
|
||||
$qry.= 'where ';
|
||||
$first = false;
|
||||
}
|
||||
else
|
||||
$qry.= ' and ';
|
||||
$qry.= ' bestellung.insertamum > date('.$this->addslashes($evon).')';
|
||||
}
|
||||
if ($ebis != '')
|
||||
{
|
||||
if($first == true)
|
||||
{
|
||||
$qry.= 'where ';
|
||||
$first = false;
|
||||
}
|
||||
else
|
||||
$qry.= ' and ';
|
||||
$qry.= ' bestellung.insertamum < '.$this->addslashes($ebis);
|
||||
}
|
||||
if ($bvon != '')
|
||||
{
|
||||
if($first == true)
|
||||
{
|
||||
$qry.= 'where ';
|
||||
$first = false;
|
||||
}
|
||||
else
|
||||
$qry.= ' and ';
|
||||
$qry.= " status.bestellstatus_kurzbz = 'Bestellung' and status.insertamum > ".$this->addslashes($bvon);
|
||||
}
|
||||
if ($bbis != '')
|
||||
{
|
||||
if($first == true)
|
||||
{
|
||||
$qry.= 'where ';
|
||||
$first = false;
|
||||
}
|
||||
else
|
||||
$qry.= ' and ';
|
||||
$qry.= " status.bestellstatus_kurzbz = 'Bestellung' and status.insertamum < ".$this->addslashes($bbis);
|
||||
}
|
||||
if ($firma_id != '')
|
||||
{
|
||||
if($first == true)
|
||||
{
|
||||
$qry.= 'where ';
|
||||
$first = false;
|
||||
}
|
||||
else
|
||||
$qry.= ' and ';
|
||||
$qry.= ' bestellung.firma_id = '.$this->addslashes($firma_id);
|
||||
}
|
||||
if ($oe_kurzbz != '')
|
||||
{
|
||||
if($first == true)
|
||||
{
|
||||
$qry.= 'where ';
|
||||
$first = false;
|
||||
}
|
||||
else
|
||||
$qry.= ' and ';
|
||||
$qry.= ' orgaeinheit.oe_kurzbz = '.$this->addslashes($oe_kurzbz);
|
||||
}
|
||||
if ($konto_id != '')
|
||||
{
|
||||
if($first == true)
|
||||
{
|
||||
$qry.= 'where ';
|
||||
$first = false;
|
||||
}
|
||||
else
|
||||
$qry.= ' and ';
|
||||
$qry.= ' bestellung.konto_id = '.$this->addslashes($konto_id);
|
||||
}
|
||||
if ($mitarbeiter_uid != '')
|
||||
{
|
||||
if($first == true)
|
||||
{
|
||||
$qry.= 'where ';
|
||||
$first = false;
|
||||
}
|
||||
else
|
||||
$qry.= ' and ';
|
||||
$qry.= ' bestellung.updatevon = '.$this->addslashes($mitarbeiter_uid);
|
||||
}
|
||||
if($rechnung)
|
||||
{
|
||||
if($first == true)
|
||||
{
|
||||
$qry.= 'where ';
|
||||
$first = false;
|
||||
}
|
||||
else
|
||||
$qry.= ' and ';
|
||||
$qry.= ' not exists (Select bestellung.bestellung_id from wawi.tbl_rechnung rechnung where rechnung.bestellung_id=bestellung.bestellung_id)';
|
||||
}
|
||||
echo $qry;
|
||||
if(!$this->db_query($qry))
|
||||
{
|
||||
$this->errormsg = "Fehler bei der Datenbankabfrage.";
|
||||
return false;
|
||||
}
|
||||
|
||||
while($row = $this->db_fetch_object())
|
||||
{
|
||||
$bestellung = new wawi_bestellung();
|
||||
|
||||
$bestellung->bestellung_id = $row->bestellung_id;
|
||||
$bestellung->kostenstelle_id = $row->kostenstelle_id;
|
||||
$bestellung->konto_id = $row->konto_id;
|
||||
$bestellung->firma_id = $row->firma_id;
|
||||
$bestellung->lieferadresse = $row->lieferadresse;
|
||||
$bestellung->rechnungsadresse = $row->rechnungsadresse;
|
||||
$bestellung->freigegeben = $row->freigegeben;
|
||||
$bestellung->bestell_nr = $row->bestell_nr;
|
||||
$bestellung->titel = $row->titel;
|
||||
$bestellung->bemerkung = $row->bemerkung;
|
||||
$bestellung->liefertermin = $row->liefertermin;
|
||||
$bestellung->updateamum = $row->update;
|
||||
$bestellung->updatevon = $row->update_von;
|
||||
$bestellung->insertamum = $row->insert;
|
||||
$bestellung->insertvon = $row->insert_von;
|
||||
$bestellung->ext_id = $row->ext_id;
|
||||
|
||||
$this->result[] = $bestellung;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Löscht die Bestellung mit der Übergebenen ID
|
||||
* @param $bestellung_id Bestellung die gelöscht werden soll
|
||||
*/
|
||||
public function delete($bestellung_id)
|
||||
{
|
||||
@@ -177,7 +357,7 @@ class wawi_bestellung extends basis_db
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* Prüft ob Richtige Daten eingegeben/vorhanden sind
|
||||
*/
|
||||
public function validate()
|
||||
{
|
||||
@@ -237,7 +417,7 @@ class wawi_bestellung extends basis_db
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* Speichert eine neue Besetellung in die Datenbank oder Updated eine bestehende
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
@@ -284,7 +464,7 @@ class wawi_bestellung extends basis_db
|
||||
updateamum = '.$this->addslashes($this->updateamum).',
|
||||
insertamum = '.$this->addslashes($this->insertamum).',
|
||||
insertvon = '.$this->addslashes($this->insertvon).',
|
||||
ext_id = '.$this->addslashes($this->ext_id);
|
||||
ext_id = '.$this->addslashes($this->ext_id).' WHERE bestellung_id = '.$this->bestellung_id.';';
|
||||
}
|
||||
if($this->db_query($qry))
|
||||
{
|
||||
@@ -320,4 +500,35 @@ class wawi_bestellung extends basis_db
|
||||
}
|
||||
return $this->bestellung_id;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* Rechnet den Bruttopreis einer Rechnung aus
|
||||
* @param $bestellung_id dessen Bruttopreis ausgerechnet werden soll
|
||||
*/
|
||||
public function getBrutto($bestellung_id)
|
||||
{
|
||||
$brutto = 0;
|
||||
$qry_brutto= "select sum(brutto) as brutto
|
||||
from
|
||||
(select detail.menge, detail.preisprove, detail.mwst, sum(detail.menge * detail.preisprove) * ((100+detail.mwst)/100) as brutto
|
||||
from
|
||||
wawi.tbl_bestellung as bestellung, wawi.tbl_bestelldetail as detail
|
||||
where
|
||||
bestellung.bestellung_id = detail.bestellung_id and bestellung.bestellung_id =".$bestellung_id." group by detail.menge, detail.preisprove, detail.mwst) as b;";
|
||||
|
||||
if($this->db_query($qry_brutto))
|
||||
{
|
||||
if($row = $this->db_fetch_object())
|
||||
{
|
||||
$brutto = $row->brutto;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
$this->errormsg =" Fehler bei der Berechnung des Bruttobetrages.";
|
||||
}
|
||||
return $brutto;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user