/***************************************************************
* $Id: erpexport.php,v 1.1 2004/06/29 08:50:30 hli Exp $
*Author: Holger Lindemann
*Copyright: (c) 2004 Lx-System
*License: non free
*eMail: info@lx-system.de
*Version: 1.0.0
*ERP: Lx-Office ERP
***************************************************************/
?>
	
Lx-ERP Export der Shopartikel
	
	
getDebugInfo());
if (DB::isError($db)) {
	dbFehler("",$db->getDebugInfo());
	die ($db->getDebugInfo());
};
/****************************************************
* dbFehler
* in: sql,err = string
* out:
* Fehlermeldungen ausgeben
*****************************************************/
function dbFehler($sql,$err) {
global $showErr;
	if ($showErr)
		echo "$sql : $err
";
}
function shopartikel() {
global $db;
	$sql ="SELECT P.partnumber,P.description,P.unit,P.weight,t.rate,P.sellprice,P.listprice,P.priceupdate,PG.partsgroup,P.notes,P.image,P.onhand FROM ";
	$sql.="parts P left join partsgroup PG on  PG.id=P.partsgroup_id ";
	$sql.="left join chart c on c.id = P.income_accno_id ";
	$sql.="left join tax T on T.taxkey=C.taxkey_id ";
	$sql.="where shop = 't'";
	$rs=$db->getAll($sql,DB_FETCHMODE_ASSOC);
	return $rs;
}
if ($_POST["export"]) {
	$data=shopartikel();
	$delim=($_POST["deli"])?$_POST["deli"]:",";
	if (get_magic_quotes_gpc()) {
		$crln = stripslashes($_POST["crln"]);
	}
	$crln = str_replace('\\r', "\015", $crln);
	$crln = str_replace('\\n', "\012", $crln);
	$crln = str_replace('\\t', "\011", $crln);
	$encl=$_POST["encl"];
	$i=0;
	$f=fopen($ERPdir,"w");
	if ($_POST["partnumber"])	{$header.=$_POST["PN"].$delim; };
	if ($_POST["desctiption"])	{$header.=$_POST["BEZ"].$delim; };
	if ($_POST["unit"])		{$header.=$_POST["EINHEIT"].$delim; };
	if ($_POST["onhand"])		{$header.=$_POST["LAGER"].$delim; };
	if ($_POST["weight"])		{$header.=$_POST["GEWICHT"].$delim; };
	if ($_POST["rate"])		{$header.=$_POST["MWST"].$delim; };
	if ($_POST["sellprice"])	{$header.=$_POST["VK"].$delim; };
	if ($_POST["listprice"])	{$header.=$_POST["EK"].$delim; };
	if ($_POST["priceupdate"])	{$header.=$_POST["PDATE"].$delim; };
	if ($_POST["partsgroup"])	{$header.=$_POST["PG"].$delim; };
	if ($_POST["notes"])		{$header.=$_POST["BESCHR"].$delim; };
	if ($_POST["image"])		{$header.=$_POST["IMAGE"].$delim; };
	$header=substr($header,0,-1);
?>
	$i=0;
	$f=fopen($ERPdir,"w");
	if ($_POST["head"]) fputs($f,$header.$crln);
	foreach($data as $zeile) {
		$file=""; $html="";
		if ($_POST["shop"]=="pepper") {
			if (preg_match("/^\[.*\].*/",$zeile["partsgroup"])) { $PG=$zeile["partsgroup"]; }
			else { $PG="[".$zeile["partsgroup"]."]"; };
			$mwst=$zeile["rate"]*100;
		} else if ($_POST["shop"]=="oscomm") {
			$mwst=sprintf("%01.4f",($zeile["rate"]*100));
			$PG=$zeile["partsgroup"];
		} else {
			$PG=$zeile["partsgroup"];
			$mwst=$zeile["rate"]*100;
		};
		$LineCol = $bgcol[$i%2+1];
		if ($_POST["partnumber"])	{$file.=$encl.$zeile["partnumber"].$encl.$delim; $html.="| ".$zeile["partnumber"]." | ";};
		if ($_POST["desctiption"])	{$file.=$encl.strtr($zeile["description"],chr(13).chr(10),"  ").$encl.$delim; $html.="".$zeile["description"]." | ";};
		if ($_POST["unit"])			{$file.=$encl.$zeile["unit"].$encl.$delim; $html.="".$zeile["unit"]." | ";};
		if ($_POST["onhand"])			{$file.=$encl.$zeile["onhand"].$encl.$delim; $html.="".$zeile["onhand"]." | ";};
		if ($_POST["weight"])		{$file.=$encl.$zeile["weight"].$encl.$delim; $html.="".$zeile["weight"]." | ";};
		if ($_POST["rate"])			{$file.=$encl.$mwst.$encl.$delim; $html.="".$mwst." | ";};
		if ($_POST["sellprice"])	{$file.=$encl.(sprintf("%02.2f",$zeile["sellprice"])).$encl.$delim; $html.="".(sprintf("%02.2f",$zeile["sellprice"]))." | ";};
		if ($_POST["listprice"])	{$file.=$encl.(sprintf("%02.2f",$zeile["listprice"])).$encl.$delim; $html.="".(sprintf("%02.2f",$zeile["listprice"]))." | ";};
		if ($_POST["partsgroup"])	{$file.=$encl.$PG.$encl.$delim; $html.="".$zeile["partsgroup"]." | ";};
		if ($_POST["notes"])		{$file.=$encl.strtr($zeile["notes"],chr(13).chr(10),"  ").$encl.$delim; $html.="".$zeile["notes"]." | ";};
		if ($_POST["image"])		{$file.=$encl.$zeile["image"].$encl.$delim; $html.="".$zeile["image"]." | ";};
		$i++;
		fputs($f,substr($file,0,-1).$crln);
		if ($_POST["show"]) {
?>
	
		= $html ?>
	
 		}
	}
?>
Anzahl der Artikel: = $i ?>
Export am : = date("d.m.Y : H:i") ?>
download Exportfile
	fclose($f);
} // if ($export)
?>
Export der Shopartikel aus Lx-ERP 
Mögliche Felder