Location: PHPKode > projects > Template Parser Engine > cls/clsDTA.php
<?
/*
clsColor.php definiert CSS3 Farben und konvertiert RGB<->HTML
Copyright (C) 2004 Thomas Meinusch

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.
*/

#http://python.lickert.net/dtaus/#x1-40002
class DTA{

  var $typ   = "LK";  // LK, GK
	var $name  = "";
  var $knr   = "";
  var $blz   = "";
  var $bank  = "";
  var $zweck = "";
	var $trans = array();

	#************************************************************


	// Konstruktor

	function DTA($typ, $name, $kontonr, $blz, $bank, $zweck) {
		$this->typ=$typ;
		$this->name=$this->fchar($name);
		$this->kontonr=$kontonr;
		$this->blz=$blz;
		$this->bank=$this->fchar($bank);
		$this->zweck=$this->fchar($zweck);
		return $this;
	}

	function addTrans($vorname,$nachname,$kundnr,$kontonr,$blz,$bank,$betrag,$info=""){
		$this->trans[]=array(
			'vorname' => $this->fchar($vorname),
			'nachname' => $this->fchar($nachname),
			'kundnr' => $kundnr,
			'kontonr' => $kontonr,
			'blz' => $blz,
			'bank' => $this->fchar($bank),
			'betrag' => $betrag,
			'info' => $this->fchar($info)
		);
	}

	function fchar($text){
		$str=strtoupper($text);
		$str=str_replace("ä","ae",$str);
		$str=str_replace("ö","oe",$str);
		$str=str_replace("ü","ue",$str);
		$str=str_replace("Ä","AE",$str);
		$str=str_replace("Ö","OE",$str);
		$str=str_replace("Ü","UE",$str);
		$str=str_replace("ß","SS",$str);
		return strtoupper($str);
	}

	function getHead(){
		$head="0128A".$this->typ; // 1+2+3. 0128A LK/GK fix 
		$head.=str_pad($this->blz,8,"0"); // 4. BLZ
		$head.=str_pad("",8,"0"); // 5. 8 mal "0"
		$head.=str_pad(substr($this->name,0,27),27," "); // 6. Auftraggeber
		$head.=date('dmy'); // 7. Datum
		$head.=str_pad("",4," "); // 8. 4 mal " "
		$head.=str_pad($this->kontonr,10,"0",STR_PAD_LEFT); // 9. Kontonr
		$head.=str_pad("",10,"0"); // 10. Referenznummer des Einreichers/Angabe freigestellt
		$head.=str_pad("",15," ").str_pad("",8," ").str_pad("",24," "); // 11 Leer=15+24, Fähligkeit TTMMJJJJ
		$head.=1; // Währung, 1=Euro
		$head.="\n"; // Zeilen Ende
		return $head;
	}

	function getBody(){
		$body="";
		$pos=1;
		foreach($this->trans as $satz){
			$body.="0216C"; // 1+2. Satzlänge max. 622 Byte, C fix 
			$body.=str_pad("",8,"0"); // 3. erstbeteiligtes Institut, freigestellt
			$body.=str_pad($satz['blz'],8,"0"); // 4. BLZ
			$body.=str_pad($satz['kontonr'],10,"0",STR_PAD_LEFT); // 5. Kontonummer rechtsb.
			$body.="0".str_pad($satz['kundnr'],11,"0",STR_PAD_LEFT)."0"; // 6. BANKINTERN 13Stellig, geändert auf 11Stl. eigene nr 0 vorne und hinten
			$body.="05000"; // 7. Textschlüssel???? 3+2
			$body.="0"; // 8. BANKINTERN
			$body.=str_pad("",11,"0"); // 9. DM-Betrag
			$body.=str_pad($this->blz,8,"0"); // 10. BLZ Auftraggeber
			$body.=str_pad($this->kontonr,10,"0",STR_PAD_LEFT); // 11. Kontonr Auftraggeber
			$body.=str_pad($satz['betrag']*100,11,"0",STR_PAD_LEFT); // 12. Betrag in EuroCent EEEEEEEEECC
			$body.=str_pad("",3," "); // 13. reserve
			$name=$satz['vorname']." ".$satz['nachname'];
			$body.=str_pad(substr($name,0,27),27," ",STR_PAD_LEFT).str_pad("",8," "); // 14. Überweisungsempfänger + 8x" " reserve
			$body.="\n"; // Zeilen Ende

			$gname=$this->name;
			$body.=str_pad(substr($gname,0,27),27," "); // 15. Auftraggeber
			$zweck=$satz['info'];
			if(!$zweck) $zweck=$this->zweck;
			$body.=str_pad(substr($zweck,0,27),27," "); // 16. Zweck
			$body.="1  "; // 17. Währung, 1=Euro
			$anz=floor(strlen($gname)/27)+floor(strlen($zweck)/27)+floor(strlen($name)/27);
			$anz=min(15,$anz);
			$body.=str_pad($anz,2,"0",STR_PAD_LEFT); // 18. 00 = kein Erweiterungsteil, 01 - 15 = Anzahl der Erweiterungsteile

			$ges=0;
			for($i=0;$i<$anz;$i++){
				$x=0;
				if(strlen($name)>27){
					$name=substr($name,27);
					$body.="01"; // 19. Art=Name des Zahlungspflichtigen
					$body.=str_pad($name,27,27," ",STR_PAD_LEFT); // 20. Name des Zahlungspflichtigen
					$x++;
				}
				if(strlen($zweck)>27){
					$zweck=substr($zweck,27);
					$body.="02"; // 19. Art=Verwendungszweck
					$body.=str_pad($zweck,27," ",STR_PAD_LEFT); // 20. Verwendungszweck
					$x++;
				}
				if($x<2 && strlen($gname)>27){
					$gname=substr($gname,27);
					$body.="03"; // 19. Art=Name
					$body.=str_pad($gname,27," ",STR_PAD_LEFT); // 20. Name
					$x++;
				}
				$ges+=$x;
				//if(substr($name,27).substr($zweck,27).substr($gname,27))
				//echo "$x - $ges - $anz<br >";
				if($x) $body.="00".str_pad("",27," ").str_pad("",11," "); // 21. Leerzeichen
			}
			$body.="\n"; // Zeilen Ende
		}
		$pos++;
		return $body;
	}

	function getFoot(){
		$foot="0128E"; // 1+2. 0128E fix
		$foot.=str_pad("",5," "); // 3. reserve
		$foot.=str_pad(count($this->trans),7,"0",STR_PAD_LEFT); // 4. Anzahl
		$foot.=str_pad("",13,"0"); // 5. Summe DM
		$sumeur=$sumknr=$sumblz=0;
		foreach($this->trans as $line){
			$sumeur+=$line['betrag'];
			$sumknr+=$line['kontonr'];
			$sumblz+=$line['blz'];
		}
		$foot.=str_pad($sumknr,17,"0",STR_PAD_LEFT); // 6. Summe der Kontonummern
		$foot.=str_pad($sumblz,17,"0",STR_PAD_LEFT); // 7. Summe der Bankleitzahlen
		$foot.=str_pad($sumeur*100,13,"0",STR_PAD_LEFT); // 8. Summe der Euro-Beträge
		$foot.=str_pad("",51," "); //9. Abgrenzung des Satzabschnittes
		return $foot;
	}
};

///////// Test
$x= new DTA('LK','Jodelverein Holladriö 1863 e.V.','123456','99988811','Nord-Ostschwäbische Sandbank', 'Mitgliedsbeitrag 2003');

#Name:Vorname:MNr:Kto:BLZ:Bank:Beitragshöhe
# Musterfrau:Silke:1:123456789:77733322:Gartenbank Südwest:15  
# Mustermann:Egon:2:987654321:55544422:Zahlnix-Bank:30:Beitrag 2002 und 2003
$x->addTrans('Silke','Musterfrau',1,'123456789','77733322','Gartenbank Südwest',15);
$x->addTrans('Egon','Mustermann',2,'987654321','55544422','Zahlnix-Bank',30,'Beitrag 2002 und 2003');
echo $x->getHead();
echo $x->getBody();
echo $x->getFoot();
?>
Return current item: Template Parser Engine