mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-19 16:02:15 +00:00
This commit is contained in:
+178
-71
@@ -26,28 +26,21 @@ require_once(dirname(__FILE__).'/basis_db.class.php');
|
||||
|
||||
class wawi_konto extends basis_db
|
||||
{
|
||||
public $new; // boolean
|
||||
public $result = array(); // adresse Objekt
|
||||
public $new; // boolean
|
||||
public $result = array(); // Konto Objekt
|
||||
public $user; // string
|
||||
|
||||
//Tabellenspalten
|
||||
public $adresse_id; // integer
|
||||
public $person_id; // integer
|
||||
public $name; // string
|
||||
public $strasse; // string
|
||||
public $plz; // string
|
||||
public $ort; // string
|
||||
public $gemeinde; // string
|
||||
public $nation; // string
|
||||
public $typ; // string
|
||||
public $heimatadresse; // boolean
|
||||
public $zustelladresse; // boolean
|
||||
public $firma_id; // integer
|
||||
public $updateamum; // timestamp
|
||||
public $updatevon; // string
|
||||
public $insertamum; // timestamp
|
||||
public $insertvon; // string
|
||||
public $ext_id; // integer
|
||||
|
||||
public $konto_id; // integer
|
||||
public $kontonr; // string
|
||||
public $beschreibung = array(); // string array
|
||||
public $kurzbz; // string
|
||||
public $aktiv; // boolean
|
||||
public $insertamum; // timestamp
|
||||
public $insertvon; // string
|
||||
public $updateamum; // timestamp
|
||||
public $updatevon; // string
|
||||
|
||||
/**
|
||||
* Konstruktor
|
||||
* @param $konto_id ID des Kontos das geladen werden soll (Default=null)
|
||||
@@ -75,7 +68,7 @@ class wawi_konto extends basis_db
|
||||
}
|
||||
|
||||
//Daten aus der Datenbank lesen
|
||||
$qry = "SELECT * FROM wawi.tbl_konto WHERE konto_id='".addslashes($konto_id)."'";
|
||||
$qry = "SELECT *, beschreibung[1] as beschreibung_ger, beschreibung[2] as beschreibung_eng FROM wawi.tbl_konto WHERE konto_id='".addslashes($konto_id)."'";
|
||||
|
||||
if(!$this->db_query($qry))
|
||||
{
|
||||
@@ -86,9 +79,15 @@ class wawi_konto extends basis_db
|
||||
if($row = $this->db_fetch_object())
|
||||
{
|
||||
$this->konto_id = $row->konto_id;
|
||||
$this->kontonr = $row->kontonr;
|
||||
$this->beschreibung[1] = $row->beschreibung_ger;
|
||||
$this->beschreibung[2] = $row->beschreibung_eng;
|
||||
$this->kurzbz = $row->kurzbz;
|
||||
$this->aktiv = ($row->aktiv=='t'?true:false);
|
||||
|
||||
//...
|
||||
$this->insertamum = $row->insertamum;
|
||||
$this->insertvon = $row->insertvon;
|
||||
$this->updateamum = $row->updateamum;
|
||||
$this->updatevon = $row->updatevon;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -108,10 +107,10 @@ class wawi_konto extends basis_db
|
||||
public function getAll($aktiv=null, $order='beschreibung DESC')
|
||||
{
|
||||
//Daten aus der Datenbank lesen
|
||||
$qry = 'SELECT * FROM wawi.tbl_konto';
|
||||
$qry = 'SELECT *, beschreibung[1] as beschreibung_ger, beschreibung[2] as beschreibung_eng FROM wawi.tbl_konto';
|
||||
if(!is_null($aktiv))
|
||||
{
|
||||
$qry.='WHERE aktiv='.($aktiv?'true':'false');
|
||||
$qry.=' WHERE aktiv='.($aktiv?'true':'false');
|
||||
}
|
||||
|
||||
if($order!='')
|
||||
@@ -128,7 +127,15 @@ class wawi_konto extends basis_db
|
||||
$obj = new wawi_konto();
|
||||
|
||||
$obj->konto_id = $row->konto_id;
|
||||
//...
|
||||
$obj->kontonr = $row->kontonr;
|
||||
$obj->beschreibung[1] = $row->beschreibung_ger;
|
||||
$obj->beschreibung[2] = $row->beschreibung_eng;
|
||||
$obj->kurzbz = $row->kurzbz;
|
||||
$obj->aktiv = ($row->aktiv=='t'?true:false);
|
||||
$obj->insertamum = $row->insertamum;
|
||||
$obj->insertvon = $row->insertvon;
|
||||
$obj->updateamum = $row->updateamum;
|
||||
$obj->updatevon = $row->updatevon;
|
||||
|
||||
$this->result[] = $obj;
|
||||
}
|
||||
@@ -142,12 +149,35 @@ class wawi_konto extends basis_db
|
||||
*/
|
||||
protected function validate()
|
||||
{
|
||||
if(mb_strlen($this->bezeichnung)>265)
|
||||
if(mb_strlen($this->kontonr)>32)
|
||||
{
|
||||
$this->errormsg = 'Kontonummer darf nicht laenger als 32 Zeichen sein.';
|
||||
}
|
||||
|
||||
if(mb_strlen($this->beschreibung[1])>256)
|
||||
{
|
||||
$this->errormsg = 'Bezeichnung darf nicht laenger als 256 Zeichen sein.';
|
||||
return false;
|
||||
}
|
||||
|
||||
if(mb_strlen($this->beschreibung[2])>256)
|
||||
{
|
||||
$this->errormsg = 'Bezeichnung darf nicht laenger als 256 Zeichen sein.';
|
||||
return false;
|
||||
}
|
||||
|
||||
if(mb_strlen($this->kurzbz)>32)
|
||||
{
|
||||
$this->errormsg = 'Kurzbezeichnung darf nicht laenger als 32 Zeichen sein.';
|
||||
return false;
|
||||
}
|
||||
|
||||
if(is_bool($this->aktiv)!= true)
|
||||
{
|
||||
$this->errormsg = 'Aktiv ist nicht gesetzt.';
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->errormsg = '';
|
||||
return true;
|
||||
}
|
||||
@@ -155,7 +185,7 @@ class wawi_konto extends basis_db
|
||||
/**
|
||||
* Speichert den aktuellen Datensatz in die Datenbank
|
||||
* Wenn $neu auf true gesetzt ist wird ein neuer Datensatz angelegt
|
||||
* andernfalls wird der Datensatz mit der ID in $adresse_id aktualisiert
|
||||
* andernfalls wird der Datensatz mit der ID in $konto_id aktualisiert
|
||||
* @param $new wenn true wird ein Insert durchgefuehrt, wenn false ein Update
|
||||
* und wenn null wird das new-Objekt der Klasse verwendet
|
||||
* @return true wenn ok, false im Fehlerfall
|
||||
@@ -172,46 +202,36 @@ class wawi_konto extends basis_db
|
||||
if($this->new)
|
||||
{
|
||||
//Neuen Datensatz einfuegen
|
||||
$qry='BEGIN;INSERT INTO public.tbl_adresse (person_id, name, strasse, plz, typ, ort, nation, insertamum, insertvon,
|
||||
gemeinde, heimatadresse, zustelladresse, firma_id, updateamum, updatevon, ext_id) VALUES('.
|
||||
$this->addslashes($this->person_id).', '.
|
||||
$this->addslashes($this->name).', '.
|
||||
$this->addslashes($this->strasse).', '.
|
||||
$this->addslashes($this->plz).', '.
|
||||
$this->addslashes(trim($this->typ)).', '.
|
||||
$this->addslashes($this->ort).', '.
|
||||
$this->addslashes($this->nation).', now(), '.
|
||||
$qry='BEGIN;INSERT INTO wawi.tbl_konto (kontonr, beschreibung, kurzbz, aktiv, insertamum,
|
||||
insertvon, updateamum, updatevon) VALUES('.
|
||||
$this->addslashes($this->kontonr).', '.
|
||||
"ARRAY[".$this->addslashes($this->beschreibung[1]).", ".$this->addslashes($this->beschreibung[2])."] ,".
|
||||
$this->addslashes($this->kurzbz).', '.
|
||||
($this->aktiv?'true':'false').', '.
|
||||
$this->addslashes($this->insertamum).', '.
|
||||
$this->addslashes($this->insertvon).', '.
|
||||
$this->addslashes($this->gemeinde).', '.
|
||||
($this->heimatadresse?'true':'false').', '.
|
||||
($this->zustelladresse?'true':'false').', '.
|
||||
($this->firma_id!=null?$this->addslashes($this->firma_id):'null').', now(), '.
|
||||
$this->addslashes($this->updatevon).', '.
|
||||
$this->addslashes($this->ext_id).');';
|
||||
$this->addslashes($this->updateamum).', '.
|
||||
$this->addslashes($this->updatevon).');';
|
||||
}
|
||||
else
|
||||
{
|
||||
//Pruefen ob adresse_id eine gueltige Zahl ist
|
||||
if(!is_numeric($this->adresse_id))
|
||||
//Pruefen ob konto_id eine gueltige Zahl ist
|
||||
if(!is_numeric($this->konto_id))
|
||||
{
|
||||
$this->errormsg = 'adresse_id muss eine gültige Zahl sein: '.$this->adresse_id."\n";
|
||||
$this->errormsg = 'konto_id muss eine gültige Zahl sein: '.$this->konto_id."\n";
|
||||
return false;
|
||||
}
|
||||
$qry='UPDATE public.tbl_adresse SET'.
|
||||
' person_id='.$this->addslashes($this->person_id).', '.
|
||||
' name='.$this->addslashes($this->name).', '.
|
||||
' strasse='.$this->addslashes($this->strasse).', '.
|
||||
' plz='.$this->addslashes($this->plz).', '.
|
||||
' typ='.$this->addslashes(trim($this->typ)).', '.
|
||||
' ort='.$this->addslashes($this->ort).', '.
|
||||
' nation='.$this->addslashes($this->nation).', '.
|
||||
' gemeinde='.$this->addslashes($this->gemeinde).', '.
|
||||
' firma_id='.$this->addslashes($this->firma_id).','.
|
||||
' updateamum= now(), '.
|
||||
' updatevon='.$this->addslashes($this->updatevon).', '.
|
||||
' heimatadresse='.($this->heimatadresse?'true':'false').', '.
|
||||
' zustelladresse='.($this->zustelladresse?'true':'false').' '.
|
||||
'WHERE adresse_id='.$this->adresse_id.';';
|
||||
$qry='UPDATE wawi.tbl_konto SET'.
|
||||
' kontonr='.$this->addslashes($this->kontonr).', '.
|
||||
' beschreibung[1]='.$this->addslashes($this->beschreibung[1]).', '.
|
||||
' beschreibung[2]='.$this->addslashes($this->beschreibung[2]).', '.
|
||||
' kurzbz='.$this->addslashes($this->kurzbz).', '.
|
||||
' aktiv='.($this->aktiv?'true':'false').', '.
|
||||
' insertamum='.$this->addslashes($this->insertamum).', '.
|
||||
' insertvon='.$this->addslashes($this->insertvon).', '.
|
||||
' updateamum='.$this->addslashes($this->updateamum).', '.
|
||||
' updatevon='.$this->addslashes($this->updatevon).' '.
|
||||
' WHERE konto_id='.$this->konto_id.';';
|
||||
}
|
||||
|
||||
if($this->db_query($qry))
|
||||
@@ -219,12 +239,12 @@ class wawi_konto extends basis_db
|
||||
if($this->new)
|
||||
{
|
||||
//naechste ID aus der Sequence holen
|
||||
$qry="SELECT currval('public.tbl_adresse_adresse_id_seq') as id;";
|
||||
$qry="SELECT currval('wawi.seq_konto_konto_id') as id;";
|
||||
if($this->db_query($qry))
|
||||
{
|
||||
if($row = $this->db_fetch_object())
|
||||
{
|
||||
$this->adresse_id = $row->id;
|
||||
$this->konto_id = $row->id;
|
||||
$this->db_query('COMMIT');
|
||||
}
|
||||
else
|
||||
@@ -245,28 +265,28 @@ class wawi_konto extends basis_db
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->errormsg = 'Fehler beim Speichern des Adress-Datensatzes';
|
||||
$this->errormsg = $qry;
|
||||
return false;
|
||||
}
|
||||
return $this->adresse_id;
|
||||
return $this->konto_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loescht den Datenensatz mit der ID die uebergeben wird
|
||||
* @param $adresse_id ID die geloescht werden soll
|
||||
* @param $konto_id ID die geloescht werden soll
|
||||
* @return true wenn ok, false im Fehlerfall
|
||||
*/
|
||||
public function delete($adresse_id)
|
||||
public function delete($konto_id)
|
||||
{
|
||||
//Pruefen ob adresse_id eine gueltige Zahl ist
|
||||
if(!is_numeric($adresse_id) || $adresse_id == '')
|
||||
//Pruefen ob konto_id eine gueltige Zahl ist
|
||||
if(!is_numeric($konto_id) || $konto_id == '')
|
||||
{
|
||||
$this->errormsg = 'adresse_id muss eine gültige Zahl sein'."\n";
|
||||
$this->errormsg = 'konto_id muss eine gültige Zahl sein'."\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
//loeschen des Datensatzes
|
||||
$qry="DELETE FROM public.tbl_adresse WHERE adresse_id='".addslashes($adresse_id)."';";
|
||||
$qry="DELETE FROM wawi.tbl_konto WHERE konto_id='".addslashes($konto_id)."';";
|
||||
|
||||
if($this->db_query($qry))
|
||||
{
|
||||
@@ -278,5 +298,92 @@ class wawi_konto extends basis_db
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Liefert alle Konten die den Kriterien entsprechen
|
||||
* @param $filter String nach dem gefiltert wird
|
||||
* @param $order Sortierkriterium
|
||||
* @return array mit Konten oder false wenn ein Fehler auftritt
|
||||
*/
|
||||
public function getKonto($filter, $order='konto_id')
|
||||
{
|
||||
$sql_query = "SELECT
|
||||
*, beschreibung[1] as beschreibung_ger, beschreibung[2] as beschreibung_eng
|
||||
FROM
|
||||
wawi.tbl_konto";
|
||||
|
||||
if($filter!='')
|
||||
{
|
||||
$sql_query.=" where lower(beschreibung[1]) LIKE lower('%".addslashes($filter)."%') OR
|
||||
lower(kontonr) LIKE lower('%".addslashes($filter)."%') OR
|
||||
lower(kurzbz) LIKE lower('%".addslashes($filter)."%')";
|
||||
|
||||
}
|
||||
|
||||
$sql_query .= " ORDER BY $order";
|
||||
$sql_query .=";";
|
||||
/*if($filter=='')
|
||||
$sql_query .= " LIMIT 30";*/
|
||||
|
||||
if($this->db_query($sql_query))
|
||||
{
|
||||
while($row = $this->db_fetch_object())
|
||||
{
|
||||
$obj = new wawi_konto();
|
||||
|
||||
$obj->konto_id = $row->konto_id;
|
||||
$obj->kontonr = $row->kontonr;
|
||||
$obj->beschreibung[1] = $row->beschreibung_ger;
|
||||
$obj->beschreibung[2] = $row->beschreibung_eng;
|
||||
$obj->kurzbz = $row->kurzbz;
|
||||
$obj->aktiv = ($row->aktiv=='t'?true:false);
|
||||
$obj->insertamum = $row->insertamum;
|
||||
$obj->insertvon = $row->insertvon;
|
||||
$obj->updateamum = $row->updateamum;
|
||||
$obj->updatevon = $row->updatevon;
|
||||
|
||||
$this->result[] = $obj;
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->errormsg = $this->db_last_error();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* loescht konto mit der id1 und legt dessen bestellungen und kostenstellen auf konto mit der id2 um
|
||||
* @param $id1 konto_id des radiobuttons
|
||||
* @param $id2 konto_id des radiobuttons
|
||||
* @return true wenn ok, false im Fehlerfall
|
||||
*/
|
||||
public function zusammenlegen($id1, $id2)
|
||||
{
|
||||
|
||||
$msg='';
|
||||
$sql_query_upd1="BEGIN;";
|
||||
$sql_query_upd1.="UPDATE wawi.tbl_bestellung SET konto_id='$id2' WHERE konto_id='$id1'; ";
|
||||
$sql_query_upd1.="UPDATE wawi.tbl_konto_kostenstelle SET konto_id='$id2' WHERE konto_id='$id1'; ";
|
||||
|
||||
$sql_query_upd1.="DELETE FROM wawi.tbl_konto WHERE konto_id='$id1';";
|
||||
|
||||
if($this->db_query($sql_query_upd1))
|
||||
{
|
||||
$this->db_query("COMMIT;");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db_query("ROLLBACK;");
|
||||
$this->errormsg = "fehler beim Update aufgetreten";
|
||||
return false;
|
||||
}
|
||||
$id1=0;
|
||||
$id2=0;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user