diff --git a/include/wawi_bestellung.class.php b/include/wawi_bestellung.class.php index 93e164cd3..66ac056fc 100644 --- a/include/wawi_bestellung.class.php +++ b/include/wawi_bestellung.class.php @@ -167,7 +167,7 @@ class wawi_bestellung extends basis_db * @param $mitarbeiter_uid * @param $rechnung */ - public function getAllSearch($bestellnr, $titel, $evon, $ebis, $bvon, $bbis, $firma_id, $oe_kurzbz, $konto_id, $mitarbeiter_uid, $rechnung, $filter_firma) + public function getAllSearch($bestellnr, $titel, $evon, $ebis, $bvon, $bbis, $firma_id, $oe_kurzbz, $konto_id, $mitarbeiter_uid, $rechnung, $filter_firma, $kostenstelle_id=null) { $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 @@ -176,141 +176,48 @@ class wawi_bestellung extends basis_db 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) "; + LEFT JOIN public.tbl_organisationseinheit orgaeinheit ON (orgaeinheit.oe_kurzbz = kostenstelle.oe_kurzbz) + WHERE 1=1 "; 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 ($filter_firma != '') - { - if($first == true) - { - $qry.= 'where '; - $first = false; - } - else - $qry.= ' or '; - $qry.= ' bestellung.firma_id = '.$this->addslashes($filter_firma); - } - 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)'; - } + $qry.= " AND UPPER(bestellung.bestell_nr) LIKE UPPER('%".addslashes($bestellnr)."%')"; + if ($titel != '') + $qry.= " AND UPPER(bestellung.titel) LIKE UPPER('%".addslashes($titel)."%')"; + + if ($evon != '') + $qry.= ' AND bestellung.insertamum > date('.$this->addslashes($evon).')'; + + if ($ebis != '') + $qry.= ' AND bestellung.insertamum < '.$this->addslashes($ebis); + + if ($bvon != '') + $qry.= " AND status.bestellstatus_kurzbz = 'Bestellung' and status.datum > ".$this->addslashes($bvon); + + if ($bbis != '') + $qry.= " AND status.bestellstatus_kurzbz = 'Bestellung' and status.datum < ".$this->addslashes($bbis); + + if ($firma_id != '') + $qry.= ' AND bestellung.firma_id = '.$this->addslashes($firma_id); + + if ($filter_firma != '') + $qry.= ' AND bestellung.firma_id = '.$this->addslashes($filter_firma); + + if ($oe_kurzbz != '') + $qry.= ' AND orgaeinheit.oe_kurzbz = '.$this->addslashes($oe_kurzbz); + + if ($konto_id != '') + $qry.= ' AND bestellung.konto_id = '.$this->addslashes($konto_id); + + if ($mitarbeiter_uid != '') + $qry.= ' AND bestellung.updatevon = '.$this->addslashes($mitarbeiter_uid); + + if($rechnung) + $qry.= ' AND not exists (Select bestellung.bestellung_id from wawi.tbl_rechnung rechnung where rechnung.bestellung_id=bestellung.bestellung_id)'; + + if($kostenstelle_id!='') + $qry.= ' AND kostenstelle_id='.$this->addslashes($kostenstelle_id); + echo $qry; if(!$this->db_query($qry)) { $this->errormsg = "Fehler bei der Datenbankabfrage."; diff --git a/include/wawi_rechnung.class.php b/include/wawi_rechnung.class.php index d0643185c..6c9ab112e 100644 --- a/include/wawi_rechnung.class.php +++ b/include/wawi_rechnung.class.php @@ -129,7 +129,7 @@ class wawi_rechnung extends basis_db $first = true; $qry = " SELECT - distinct on (tbl_rechnung.rechnung_id) tbl_rechnung.* + distinct on (tbl_rechnung.rechnung_id) tbl_rechnung.*, tbl_bestellung.bestell_nr FROM wawi.tbl_rechnung LEFT JOIN wawi.tbl_bestellung USING (bestellung_id) @@ -206,6 +206,8 @@ class wawi_rechnung extends basis_db $obj->insertamum = $row->insertamum; $obj->insertvon = $row->insertvon; + $obj->bestell_nr = $row->bestell_nr; + $this->result[] = $obj; } return true; @@ -508,4 +510,44 @@ class wawi_rechnung extends basis_db return false; } } + + /** + * Liefert die Anzahl der Rechnungen zu einer Bestellung + * + * @param $bestellung_id + * @return Anzahl der Rechnungen oder false im Fehlerfall + */ + public function count($bestellung_id) + { + $qry = "SELECT count(*) as anzahl FROM wawi.tbl_rechnung WHERE bestellung_id='".addslashes($bestellung_id)."'"; + + if($result = $this->db_query($qry)) + { + if($row = $this->db_fetch_object($result)) + { + return $row->anzahl; + } + else + { + $this->errormsg='Fehler beim Laden der Daten'; + return false; + } + } + else + { + $this->errormsg = 'Fehler beim Laden der Daten'; + return false; + } + } + + public function getBrutto($rechnung_id) + { + $this->loadBetraege($rechnung_id); + $brutto=0; + foreach($this->result as $row) + { + $brutto += ($row->betrag*($row->mwst+100)/100); + } + return $brutto; + } } \ No newline at end of file diff --git a/skin/tablesort.css b/skin/tablesort.css index d3249912d..06f5c4bf4 100644 --- a/skin/tablesort.css +++ b/skin/tablesort.css @@ -1,7 +1,7 @@ /* tables */ table.tablesorter { font-family:arial; - background-color: white; + /*background-color: white;*/ margin:10px 0pt 15px; font-size: 8pt; width: 100%; diff --git a/skin/wawi.css b/skin/wawi.css index 70d92b6bc..489ff28c5 100644 --- a/skin/wawi.css +++ b/skin/wawi.css @@ -114,4 +114,20 @@ table.dark td .number { text-align: right; -} \ No newline at end of file +} + +option.rechnung_nichtfreigegeben +{ + background-color: lightred; +} + +option.rechnung_freigegebenvorhanden +{ + background-color: lightyellow; +} + +option.rechnung_freigegeben +{ + background-color: lightgreen; +} + \ No newline at end of file diff --git a/wawi/rechnung.php b/wawi/rechnung.php index 583b1fc11..37553d14e 100644 --- a/wawi/rechnung.php +++ b/wawi/rechnung.php @@ -298,31 +298,45 @@ if($aktion == 'suche') echo " Rechnungsnr. - Bestell_ID - Typ + Bestell_Nr Rechnungsdatum Buchungstext + Brutto Freigegeben Letzte Änderung \n"; - + $brutto_gesamt=0; foreach($rechnung->result as $row) { + $obj = new wawi_rechnung(); + $brutto = $obj->getBrutto($row->rechnung_id); + $brutto = round($brutto,2); + $brutto_gesamt +=$brutto; //Zeilen der Tabelle ausgeben echo "\n"; echo " rechnung_id\" title=\"Bearbeiten\"> rechnung_id\" onclick='return conf_del()' title='Löschen'> "; echo ''.$row->rechnungsnr."\n"; - echo ''.$row->bestellung_id."\n"; - echo ''.$row->rechnungstyp_kurzbz."\n"; + echo ''.$row->bestell_nr."\n"; echo ''.$date->formatDatum($row->rechnungsdatum, 'd.m.Y')."\n"; echo ''.$row->buchungstext."\n"; + echo ''.number_format($brutto,2,".","")."\n"; echo ''.$freigegeben=($row->freigegeben=='t')?'ja':'nein'."\n"; echo ''.$date->formatDatum($row->updateamum,'d.m.Y H:i:s').' '.$row->updatevon ."\n"; echo "\n"; } - echo "\n"; + echo ' + + + + + + Summe + '.number_format($brutto_gesamt,2).' + + + '; } else echo "Fehler bei der Abfrage!"; @@ -335,28 +349,21 @@ elseif($aktion == 'new') { if(!$rechte->isBerechtigt('wawi/rechnung',null,'sui')) die('Sie haben keine Berechtigung zum Anlegen von Rechnungen'); + + echo '

Rechnung Neu

'; + echo '
'; + echo ''; + echo ''; - echo ''; - echo ''; - echo '
'; + echo ''; } + echo ''; + echo ''; + echo ''; } elseif($aktion == 'save') @@ -505,16 +512,17 @@ if($aktion=='update') if(!$bestellung->load($rechnung->bestellung_id)) die('Diese Rechnung ist keiner gueltigen Bestellung zugeordnet'); + $bestellung_id=$bestellung->bestellung_id; if(!$kostenstelle->load($bestellung->kostenstelle_id)) die('Die Rechnung bzw Bestellung ist keiner gueltigen Kostenstelle zugeordnet'); - + if(!$konto->load($bestellung->konto_id)) die('Die Rechnung bzw Bestellung ist keim gueltigen Konto zugeordnet'); if(!$firma->load($bestellung->firma_id)) die('Die Rechnung bzw Bestellung ist keiner gueltigen Firma zugeordnet'); - $oe_kurzbz=$kostenstelle->oe_kurzbz; + $kostenstelle_id=$bestellung->kostenstelle_id; echo ' @@ -531,195 +539,229 @@ if($aktion=='update')
'; } - elseif(isset($_GET['oe_kurzbz'])) + elseif(isset($_GET['kostenstelle_id'])) { echo '

Rechnung Neu

'; - $rechnung_id=''; - $oe_kurzbz = $_GET['oe_kurzbz']; + $rechnung_id=''; + $bestellung_id=''; + $kostenstelle_id = $_GET['kostenstelle_id']; + } + elseif(isset($_GET['bestellung_id'])) + { + echo '

Rechnung Neu

'; + $bestellung_id=$_GET['bestellung_id']; + $rechnung_id=''; + if(!$bestellung->load($bestellung_id)) + die('Bestellung existiert nicht'); + $kostenstelle_id=$bestellung->kostenstelle_id; } else { die('ungueltige parameter'); } - echo ' -
-
- - - - - - - - - - - - + + + + +
RechnungsnummerRechnungsdatum   BestellungTyp
- - - - + + + + + + + + + + + - + + + + + + + + + + + - - - - - -
RechnungsnummerRechnungsdatum (tt.mm.JJJJ)  BestellungTyp
+ + + + - - + + +
 
+ Buchungstext
+ +
+ Buchungsdatum (tt.mm.JJJJ)
+ + +
+ + + + + + + + + '; + + + //Vorhandenen Betraege anzeigen + $betraege = new wawi_rechnung(); + $betraege->loadBetraege($rechnung->rechnung_id); + + $i=0; + foreach($betraege->result as $row) + { + echo getBetragRow($i, $row->rechnungsbetrag_id, $row->bezeichnung, $row->betrag, $row->mwst); + $i++; + } + + //Unten eine Leere Zeile hinzufuegen + echo getBetragRow($i); + + echo ' + + + + + + + + + + + +
BezeichnungBetrag NettoMwSt
Summe Netto:
Summe Brutto:
+ -
- - - - - - - - - '; - - - //Vorhandenen Betraege anzeigen - $betraege = new wawi_rechnung(); - $betraege->loadBetraege($rechnung->rechnung_id); - - $i=0; - foreach($betraege->result as $row) - { - echo getBetragRow($i, $row->rechnungsbetrag_id, $row->bezeichnung, $row->betrag, $row->mwst); - $i++; - } - - //Unten eine Leere Zeile hinzufuegen - echo getBetragRow($i); - - echo ' - - - - - - - - - - - -
BezeichnungBetrag NettoMwSt
Summe Netto:
Summe Brutto:
- -
- '; + netto = Math.round(netto*100)/100; + brutto = Math.round(brutto*100)/100; + $("#netto").html(netto); + $("#brutto").html(brutto); + } + + $(document).ready(function() + { + summe(); + }); + + +
+ '; }