Globale Variablen nach %::lx_office_conf verschoben
[kivitendo-erp.git] / pepper / erpexport.php
1 <?
2 /***************************************************************
3 * $Id: erpexport.php  2006/02/06 13:50:30 hli Exp $
4 *Author: Holger Lindemann
5 *Copyright: (c) 2004 Lx-System
6 *License: non free
7 *eMail: info@lx-system.de
8 *Version: 1.0.1
9 *ERP: Lx-Office ERP
10 ***************************************************************/
11 ?>
12 <html>
13         <head><title>Lx-ERP Export der Shopartikel</title>
14         <link type="text/css" REL="stylesheet" HREF="css/main.css"></link>
15         <script language="JavaScript">
16         <!--
17                 function pepper() {
18                         document.fld.PN.value="Artikel-Nr"; document.fld.partnumber.checked=true;
19                         document.fld.BEZ.value="Name"; document.fld.desctiption.checked=true;
20                         document.fld.GEWICHT.value="Gewicht"; document.fld.weight.checked=true;
21                         document.fld.MWST.value="MwSt-Satz"; document.fld.rate.checked=true;
22                         document.fld.VK.value="Preis"; document.fld.sellprice.checked=true;
23                         document.fld.PG.value="Kategorien"; document.fld.partsgroup.checked=true;
24                         document.fld.BESCHR.value="Beschreibung"; document.fld.notes.checked=true;
25                         document.fld.PG.value="Lagerbestand"; document.fld.onhand.checked=true;
26                         document.fld.encl.value="";
27                         document.fld.deli.value=";";
28                         document.fld.crln.value="\\n";
29                         document.fld.head.checked=true;
30                         document.fld.shop.value="pepper";
31                 }
32         //-->
33         </script>
34 <body>
35
36 <?php
37 require_once "DB.php";
38 require_once "conf.php";
39
40 $db=DB::connect($ERPdns);
41 if (!$db) dbFehler("",$db->getDebugInfo());
42 if (DB::isError($db)) {
43         dbFehler("",$db->getDebugInfo());
44         die ($db->getDebugInfo());
45 };
46 /****************************************************
47 * dbFehler
48 * in: sql,err = string
49 * out:
50 * Fehlermeldungen ausgeben
51 *****************************************************/
52 function dbFehler($sql,$err) {
53 global $showErr;
54         if ($showErr)
55                 echo "</td></tr></table><font color='red'>$sql : $err</font><br>";
56 }
57
58 function shopartikel() {
59 global $db;
60         $sql ="SELECT P.partnumber,P.description,P.unit,P.weight,t.rate,P.sellprice,P.listprice,P.priceupdate,PG.partsgroup,P.notes,P.image FROM ";
61         $sql.="parts P left join partsgroup PG on  PG.id=P.partsgroup_id ";
62         $sql.="left join chart c on c.id = P.income_accno_id ";
63         $sql.="left join tax T on T.taxkey=C.taxkey_id ";
64         $sql.="where shop = 't'";
65         $rs=$db->getAll($sql,DB_FETCHMODE_ASSOC);
66         return $rs;
67 }
68 if ($_POST["export"]) {
69         $data=shopartikel();
70         $delim=($_POST["deli"])?$_POST["deli"]:",";
71         if (get_magic_quotes_gpc()) {
72                 $crln = stripslashes($_POST["crln"]);
73         }
74         $crln = str_replace('\\r', "\015", $crln);
75         $crln = str_replace('\\n', "\012", $crln);
76         $crln = str_replace('\\t', "\011", $crln);
77         $encl=$_POST["encl"];
78         $i=0;
79         $f=fopen($ERPdir,"w");
80         if ($_POST["partnumber"])       {$header.=$_POST["PN"].$delim; };
81         if ($_POST["desctiption"])      {$header.=$_POST["BEZ"].$delim; };
82         if ($_POST["unit"])                     {$header.=$_POST["EINHEIT"].$delim; };
83         if ($_POST["weight"])           {$header.=$_POST["GEWICHT"].$delim; };
84         if ($_POST["onhand"])           {$header.=$_POST["LAGER"].$delim; };
85         if ($_POST["rate"])                     {$header.=$_POST["MWST"].$delim; };
86         if ($_POST["sellprice"])        {$header.=$_POST["VK"].$delim; };
87         if ($_POST["listprice"])        {$header.=$_POST["EK"].$delim; };
88         if ($_POST["priceupdate"])      {$header.=$_POST["PDATE"].$delim; };
89         if ($_POST["partsgroup"])       {$header.=$_POST["PG"].$delim; };
90         if ($_POST["notes"])            {$header.=$_POST["BESCHR"].$delim; };
91         if ($_POST["image"])            {$header.=$_POST["IMAGE"].$delim; };
92         $header=substr($header,0,-1);
93 ?>
94 <table class="liste">
95 <!-- BEGIN Artikel -->
96 <?
97 function downloadImage($image,$name) {
98 global $ERPftphost,$ERPftpuser,$ERPftppwd,$ERPimgdir, $maxSize, $iconSize;
99         $conn_id = ftp_connect($ERPftphost);
100         ftp_login($conn_id,$ERPftpuser,$ERPftppwd);
101         $src=$ERPimgdir."/".$image;
102         $typ=substr($image,strrpos($image,"."));
103         echo "tmp/".$name."_gr$typ $src";
104         $upload=ftp_get($conn_id,"tmp/".$name."_gr$typ","$src",FTP_BINARY);
105         ftp_quit($conn_id);
106         if (!$upload) { echo "Ftp download war fehlerhaft!"; return false; };
107         echo "convert  -resize $iconSize tmp/".$name."_gr$typ tmp/".$name."_kl$typ";
108         exec("convert  -resize $iconSize tmp/".$name."_gr$typ tmp/".$name."_kl$typ",$aus,$rc);
109         print_r($aus); echo "!$rc!";
110 }
111         $i=0;
112         $f=fopen($ERPdir,"w");
113         if ($_POST["head"]) fputs($f,$header.$crln);
114         foreach($data as $zeile) {
115                 $file=""; $html="";
116                 if ($_POST["shop"]=="pepper") {
117                         if (preg_match("/^\[.*\].*/",$zeile["partsgroup"])) { $PG=$zeile["partsgroup"]; }
118                         else { $PG="[".$zeile["partsgroup"]."]"; };
119                         $mwst=$zeile["rate"]*100;
120                 } else if ($_POST["shop"]=="oscomm") {
121                         $mwst=sprintf("%01.4f",($zeile["rate"]*100));
122                         $PG=$zeile["partsgroup"];
123                 } else {
124                         $PG=$zeile["partsgroup"];
125                         $mwst=$zeile["rate"]*100;
126                 };
127                 $LineCol = $bgcol[$i%2+1];
128                 if ($_POST["partnumber"])       {$file.=$encl.$zeile["partnumber"].$encl.$delim; $html.="<td>".$zeile["partnumber"]."</td>";};
129                 if ($_POST["desctiption"])      {$file.=$encl.strtr($zeile["description"],chr(13).chr(10),"  ").$encl.$delim; $html.="<td>".$zeile["description"]."</td>";};
130                 if ($_POST["unit"])                     {$file.=$encl.$zeile["unit"].$encl.$delim; $html.="<td>".$zeile["unit"]."</td>";};
131                 if ($_POST["onhand"])                   {$file.=$encl.$zeile["onhand"].$encl.$delim; $html.="<td>".$zeile["onhand"]."</td>";};
132                 if ($_POST["weight"])           {$file.=$encl.$zeile["weight"].$encl.$delim; $html.="<td>".$zeile["weight"]."</td>";};
133                 if ($_POST["rate"])                     {$file.=$encl.$mwst.$encl.$delim; $html.="<td>".$mwst."</td>";};
134                 if ($_POST["sellprice"])        {$file.=$encl.(sprintf("%02.2f",$zeile["sellprice"])).$encl.$delim; $html.="<td>".(sprintf("%02.2f",$zeile["sellprice"]))."</td>";};
135                 if ($_POST["listprice"])        {$file.=$encl.(sprintf("%02.2f",$zeile["listprice"])).$encl.$delim; $html.="<td>".(sprintf("%02.2f",$zeile["listprice"]))."</td>";};
136                 if ($_POST["priceupdate"])      {$file.=$encl.$zeile["priceupdate"].$encl.$delim; $html.="<td>".$zeile["priceupdate"]."</td>";};
137                 if ($_POST["partsgroup"])       {$file.=$encl.$PG.$encl.$delim; $html.="<td>".$zeile["partsgroup"]."</td>";};
138                 if ($_POST["notes"])            {$file.=$encl.strtr($zeile["notes"],chr(13).chr(10),"  ").$encl.$delim; $html.="<td>".$zeile["notes"]."</td>";};
139                 if ($_POST["image"])            {$file.=$encl.$zeile["image"].$encl.$delim; $html.="<td>".$zeile["image"]."</td>";};
140                 $i++;
141                 fputs($f,substr($file,0,-1).$crln);
142                 if ($zeile["image"] && $_POST["image"]) { downloadImage($zeile["image"],$zeile["partnumber"]); }
143                 if ($_POST["show"]) {
144 ?>
145         <tr  class="smal" onMouseover="this.bgColor='#FF0000';" onMouseout="this.bgColor='<?= $LineCol ?>';" bgcolor="<?= $LineCol ?>">
146                 <?= $html ?>
147         </tr>
148 <?              }
149         }
150 ?>
151 <!-- END Artikel -->
152 </table>
153 Anzahl der Artikel: <?= $i ?><br>
154 Export am : <?= date("d.m.Y : H:i") ?><br>
155 download <a href="tmp/shopartikel.csv">Exportfile</a><br><hr>
156 <?
157         fclose($f);
158 } // if ($export)
159 ?>
160 Export der Shopartikel aus Lx-ERP <br>
161 M&ouml;gliche Felder
162 <form name="fld" action="erpexport.php" method="post">
163 <input type="hidden" name="shop" value="">
164 <table>
165         <tr>
166                 <td><input type="checkbox" name="partnumber" value="1">Artikelnummer</td>
167                 <td><input type="checkbox" name="desctiption" value="1">Bezeichnung</td>
168                 <td><input type="checkbox" name="unit" value="1">Einheit</td>
169                 <td><input type="checkbox" name="weight" value="1">Gewicht</td>
170         </tr>
171         <tr>
172                 <td><input type="text" name="PN" size="23"></td>
173                 <td><input type="text" name="BEZ" size="23"></td>
174                 <td><input type="text" name="EINHEIT" size="23"></td>
175                 <td><input type="text" name="GEWICHT" size="23"></td>
176         </tr>
177         <tr><td colspan=5></td></tr>
178         <tr>
179                 <td><input type="checkbox" name="sellprice" value="1">Verkaufspreis</td>
180                 <td><input type="checkbox" name="listprice" value="1">Listenpreis</td>
181                 <td><input type="checkbox" name="onhand" value="1">Lagerbestand</td>
182                 <td><input type="checkbox" name="rate" value="1">MwSt</td>
183         </tr>
184         <tr>
185                 <td><input type="text" name="VK" size="23"></td>
186                 <td><input type="text" name="EK" size="23"></td>
187                 <td><input type="text" name="LAGER" size="23"></td>
188                 <td><input type="text" name="MWST" size="23"></td>
189         </tr>
190         <tr><td colspan=5></td></tr>
191         <tr>
192                 <td><input type="checkbox" name="partsgroup" value="1">Gruppe</td>
193                 <td><input type="checkbox" name="notes" value="1">Beschreibung</td>
194                 <td><input type="checkbox" name="image" value="1">Bild</td>
195                 <td><input type="checkbox" name="show" value="1" checked>HTML-Anzeige</td>
196         </tr>
197         <tr>
198                 <td><input type="text" name="PG" size="23"></td>
199                 <td><input type="text" name="BESCHR" size="23"></td>
200                 <td><input type="text" name="IMAGE" size="23"></td>
201                 <td></td>
202         </tr>
203         <tr>
204                 <td>Feldtrenner <input type="text" name="deli" size="2" value=","></td>
205                 <td>Feldumrahmung <input type="text" name="encl" size="2" value="&quot;"></td>
206                 <td>Zeilenende <input type="text" name="crln" size="2" value="\n"></td>
207                 <td><input type="checkbox" name="head" value="1" checked>Headline</td>
208         </tr>
209         <tr>
210                 <td colspan=5><input type="submit" name="export" value="Export"> <input type="button" name="pep" value="Peppershop" onClick="pepper()"> <input type="button" name="osc" value="osCommerce" onClick="oscomm()"></td>
211         </tr>
212 </table>
213 <a href="trans.php">zur&uuml;ck</a>
214 </form>
215 </body>
216 </html>