f-tex default.tex fuer die neue Variable template_meta.tmpfile angepasst
[kivitendo-erp.git] / olcom / erpexport.php
1 <?
2 /***************************************************************
3 * $Id: erpexport.php,v 1.1 2004/06/29 08: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.0
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 xtcomm() {
18                         document.fld.PN.value="products_model"; document.fld.partnumber.checked=true;
19                         document.fld.BEZ.value="products_name"; document.fld.desctiption.checked=true;
20                         document.fld.GEWICHT.value="products_weight"; document.fld.weight.checked=true;
21                         document.fld.MWST.value="products_tax"; document.fld.rate.checked=true;
22                         document.fld.VK.value="products_price"; document.fld.sellprice.checked=true;
23                         document.fld.PG.value="categories_name"; document.fld.partsgroup.checked=true;
24                         document.fld.BESCHR.value="products_description"; document.fld.notes.checked=true;
25                         document.fld.LAGER.value="products_quantity"; 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="xtcomm";
31                 }
32         //-->
33         </script>
34 <body>
35
36 <?php
37 require_once "DB.php";
38 require_once "./conf.php";
39 $db=DB::connect($ERPdns);
40 if (!$db) dbFehler("",$db->getDebugInfo());
41 if (DB::isError($db)) {
42         dbFehler("",$db->getDebugInfo());
43         die ($db->getDebugInfo());
44 };
45 /****************************************************
46 * dbFehler
47 * in: sql,err = string
48 * out:
49 * Fehlermeldungen ausgeben
50 *****************************************************/
51 function dbFehler($sql,$err) {
52 global $showErr;
53         if ($showErr)
54                 echo "</td></tr></table><font color='red'>$sql : $err</font><br>";
55 }
56
57 function shopartikel() {
58 global $db;
59         $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 ";
60         $sql.="parts P left join partsgroup PG on  PG.id=P.partsgroup_id ";
61         $sql.="left join chart c on c.id = P.income_accno_id ";
62         $sql.="left join tax T on T.taxkey=C.taxkey_id ";
63         $sql.="where shop = 't'";
64         $rs=$db->getAll($sql,DB_FETCHMODE_ASSOC);
65         return $rs;
66 }
67 if ($_POST["export"]) {
68         $data=shopartikel();
69         $delim=($_POST["deli"])?$_POST["deli"]:",";
70         if (get_magic_quotes_gpc()) {
71                 $crln = stripslashes($_POST["crln"]);
72         }
73         $crln = str_replace('\\r', "\015", $crln);
74         $crln = str_replace('\\n', "\012", $crln);
75         $crln = str_replace('\\t', "\011", $crln);
76         $encl=$_POST["encl"];
77         $i=0;
78         $f=fopen($ERPdir,"w");
79         if ($_POST["partnumber"])       {$header.=$_POST["PN"].$delim; };
80         if ($_POST["desctiption"])      {$header.=$_POST["BEZ"].$delim; };
81         if ($_POST["unit"])             {$header.=$_POST["EINHEIT"].$delim; };
82         if ($_POST["onhand"])           {$header.=$_POST["LAGER"].$delim; };
83         if ($_POST["weight"])           {$header.=$_POST["GEWICHT"].$delim; };
84         if ($_POST["rate"])             {$header.=$_POST["MWST"].$delim; };
85         if ($_POST["sellprice"])        {$header.=$_POST["VK"].$delim; };
86         if ($_POST["listprice"])        {$header.=$_POST["EK"].$delim; };
87         if ($_POST["priceupdate"])      {$header.=$_POST["PDATE"].$delim; };
88         if ($_POST["partsgroup"])       {$header.=$_POST["PG"].$delim; };
89         if ($_POST["notes"])            {$header.=$_POST["BESCHR"].$delim; };
90         if ($_POST["image"])            {$header.=$_POST["IMAGE"].$delim; };
91         $header=substr($header,0,-1);
92 ?>
93 <table class="liste">
94 <!-- BEGIN Artikel -->
95 <?      $i=0;
96         $f=fopen($ERPdir,"w");
97         if ($_POST["head"]) fputs($f,$header.$crln);
98         foreach($data as $zeile) {
99                 $file=""; $html="";
100                 if ($_POST["shop"]=="pepper") {
101                         if (preg_match("/^\[.*\].*/",$zeile["partsgroup"])) { $PG=$zeile["partsgroup"]; }
102                         else { $PG="[".$zeile["partsgroup"]."]"; };
103                         $mwst=$zeile["rate"]*100;
104                 } else if ($_POST["shop"]=="oscomm") {
105                         $mwst=sprintf("%01.4f",($zeile["rate"]*100));
106                         $PG=$zeile["partsgroup"];
107                 } else {
108                         $PG=$zeile["partsgroup"];
109                         $mwst=$zeile["rate"]*100;
110                 };
111                 $LineCol = $bgcol[$i%2+1];
112                 if ($_POST["partnumber"])       {$file.=$encl.$zeile["partnumber"].$encl.$delim; $html.="<td>".$zeile["partnumber"]."</td>";};
113                 if ($_POST["desctiption"])      {$file.=$encl.strtr($zeile["description"],chr(13).chr(10),"  ").$encl.$delim; $html.="<td>".$zeile["description"]."</td>";};
114                 if ($_POST["unit"])                     {$file.=$encl.$zeile["unit"].$encl.$delim; $html.="<td>".$zeile["unit"]."</td>";};
115                 if ($_POST["onhand"])                   {$file.=$encl.$zeile["onhand"].$encl.$delim; $html.="<td>".$zeile["onhand"]."</td>";};
116                 if ($_POST["weight"])           {$file.=$encl.$zeile["weight"].$encl.$delim; $html.="<td>".$zeile["weight"]."</td>";};
117                 if ($_POST["rate"])                     {$file.=$encl.$mwst.$encl.$delim; $html.="<td>".$mwst."</td>";};
118                 if ($_POST["sellprice"])        {$file.=$encl.(sprintf("%02.2f",$zeile["sellprice"])).$encl.$delim; $html.="<td>".(sprintf("%02.2f",$zeile["sellprice"]))."</td>";};
119                 if ($_POST["listprice"])        {$file.=$encl.(sprintf("%02.2f",$zeile["listprice"])).$encl.$delim; $html.="<td>".(sprintf("%02.2f",$zeile["listprice"]))."</td>";};
120                 if ($_POST["partsgroup"])       {$file.=$encl.$PG.$encl.$delim; $html.="<td>".$zeile["partsgroup"]."</td>";};
121                 if ($_POST["notes"])            {$file.=$encl.strtr($zeile["notes"],chr(13).chr(10),"  ").$encl.$delim; $html.="<td>".$zeile["notes"]."</td>";};
122                 if ($_POST["image"])            {$file.=$encl.$zeile["image"].$encl.$delim; $html.="<td>".$zeile["image"]."</td>";};
123                 $i++;
124                 fputs($f,substr($file,0,-1).$crln);
125                 if ($_POST["show"]) {
126 ?>
127         <tr  class="smal" onMouseover="this.bgColor='#FF0000';" onMouseout="this.bgColor='<?= $LineCol ?>';" bgcolor="<?= $LineCol ?>">
128                 <?= $html ?>
129         </tr>
130 <?              }
131         }
132 ?>
133 <!-- END Artikel -->
134 </table>
135 Anzahl der Artikel: <?= $i ?><br>
136 Export am : <?= date("d.m.Y : H:i") ?><br>
137 download <a href="tmp/shopartikel.csv">Exportfile</a><br><hr>
138 <?
139         fclose($f);
140 } // if ($export)
141 ?>
142 Export der Shopartikel aus Lx-ERP <br>
143 M&ouml;gliche Felder
144 <form name="fld" action="erpexport.php" method="post">
145 <input type="hidden" name="shop" value="">
146 <table>
147         <tr>
148                 <td><input type="checkbox" name="partnumber" value="1">Artikelnummer</td>
149                 <td><input type="checkbox" name="desctiption" value="1">Bezeichnung</td>
150                 <td><input type="checkbox" name="unit" value="1">Einheit</td>
151                 <td><input type="checkbox" name="weight" value="1">Gewicht</td>
152         </tr>
153         <tr>
154                 <td><input type="text" name="PN" size="23"></td>
155                 <td><input type="text" name="BEZ" size="23"></td>
156                 <td><input type="text" name="EINHEIT" size="23"></td>
157                 <td><input type="text" name="GEWICHT" size="23"></td>
158         </tr>
159         <tr><td colspan=5></td></tr>
160         <tr>
161                 <td><input type="checkbox" name="sellprice" value="1">Verkaufspreis</td>
162                 <td><input type="checkbox" name="listprice" value="1">Listenpreis</td>
163                 <td><input type="checkbox" name="onhand" value="1">Lagerbestand</td>
164                 <td><input type="checkbox" name="rate" value="1">MwSt</td>
165         </tr>
166         <tr>
167                 <td><input type="text" name="VK" size="23"></td>
168                 <td><input type="text" name="EK" size="23"></td>
169                 <td><input type="text" name="LAGER" size="23"></td>
170                 <td><input type="text" name="MWST" size="23"></td>
171         </tr>
172         <tr><td colspan=5></td></tr>
173         <tr>
174                 <td><input type="checkbox" name="partsgroup" value="1">Gruppe</td>
175                 <td><input type="checkbox" name="notes" value="1">Beschreibung</td>
176                 <td><input type="checkbox" name="image" value="1">Bild</td>
177                 <td><input type="checkbox" name="show" value="1" checked>HTML-Anzeige</td>
178         </tr>
179         <tr>
180                 <td><input type="text" name="PG" size="23"></td>
181                 <td><input type="text" name="BESCHR" size="23"></td>
182                 <td><input type="text" name="IMAGE" size="23"></td>
183                 <td></td>
184         </tr>
185         <tr>
186                 <td>Feldtrenner <input type="text" name="deli" size="2" value=","></td>
187                 <td>Feldumrahmung <input type="text" name="encl" size="2" value="&quot;"></td>
188                 <td>Zeilenende <input type="text" name="crln" size="2" value="\n"></td>
189                 <td><input type="checkbox" name="head" value="1" checked>Headline</td>
190         </tr>
191         <tr>
192                 <td colspan=5><input type="submit" name="export" value="Export"> <input type="button" name="xsc" value="xtCommerce" onClick="xtcomm()"></td>
193         </tr>
194 </table>
195 <a href="trans.php">zur&uuml;ck</a>
196 </form>
197 </body>
198 </html>