00001 <?php
00002
00007 class oxImex extends oxBase
00008 {
00009
00019 public function exportLexwareArticles($iStart, $iLines, $sFilepath)
00020 {
00021 $myConfig = $this->getConfig();
00022 $oDb = oxDb::getDb();
00023
00024 $sArticleTable = getViewName('oxarticles');
00025
00026 $sSelect = "select count(oxid) from $sArticleTable ";
00027 $iSize = (int) $oDb->getOne($sSelect);
00028
00029 if ($iStart < $iSize) {
00030 $fp = fopen($sFilepath, "ab");
00031 if (!$iStart) {
00032
00033 fwrite($fp, "\"Artikelnummer\";\"Bezeichnung\";\"Einheit\";\"Gewicht\";\"Matchcode\";\"Preis pro Anzahl\";\"Warengruppe\";\"Warengr.-Kurzbez.\";\"Warengr.-Steuersatz\";\"Warengr.-Konto Inland\";\"Warengr.-Konto Ausland\";\"Warengr.-Konto EG\";\"Preis 1\";\"Preis 2\";\"Preis 3\";\"Preis I/1\";\"Preis I/2\";\"Preis I/3\";\"Preis II/1\";\"Preis II/2\";\"Preis II/3\";\"Preis III/1\";\"Preis III/2\";\"Preis III/3\";\"B/N\";\"Lagerartikel\";\"EK 1\";\"W�hrung EK1\";\"EK 2\";\"W�hrung EK2\";\"Staffelmenge 1\";\"Staffelmenge 2\";\"Staffelmenge 3\";\"Lieferantennummer 1\";\"Lieferantennummer 2\";\"Bestellmenge Lf.1\";\"Bestellmenge Lf.2\";\"Bestellnr. Lf.1\";\"Bestellnr. Lf.2\";\"Lieferzeit Lf.1\";\"Lieferzeit Lf.2\";\"Lagerbestand\";\"Mindestbestand\";\"Lagerort\";\"Bestellte Menge\";\"St�ckliste\";\"Internet\";\"Text\"\r\n");
00034 }
00035 $oldMode = $oDb->setFetchMode(oxDb::FETCH_MODE_ASSOC);
00036 $sSelect = "select * from $sArticleTable ";
00037 $rs = $oDb->selectLimit($sSelect, $iLines, $iStart);
00038 $oDb->setFetchMode($oldMode);
00039
00040 while (!$rs->EOF) {
00041 $oArticle = oxNew("oxarticle");
00042 $blAdmin = $this->isAdmin();
00043
00044 $this->setAdminMode(false);
00045 $oArticle->load($rs->fields['OXID']);
00046 $this->setAdminMode($blAdmin);
00047
00048 $sSelect = "select oxtitle from " . $oArticle->getViewName() . " where oxid = " . $oDb->quote($oArticle->oxarticles__oxparentid->value);
00049 $oTitle = $oDb->getOne($sSelect);
00050 if ($oTitle != false && strlen($oTitle)) {
00051 $nTitle = $this->interForm($oTitle);
00052 } else {
00053 $nTitle = $this->interForm($oArticle->oxarticles__oxtitle->value);
00054 }
00055
00056
00057 $sToFile = $oArticle->oxarticles__oxartnum->value
00058
00059 . ";" . $nTitle . " " . $this->interForm($oArticle->oxarticles__oxvarselect->value)
00060 . ";" . "Stueck"
00061 . ";" . $oArticle->oxarticles__oxweight->value
00062 . ";" . $oArticle->oxarticles__oxartnum->value
00063 . ";" . "1,000"
00064 . ";"
00065 . ";"
00066 . ";"
00067 . ";"
00068 . ";"
00069 . ";"
00070 . ";" . number_format($oArticle->oxarticles__oxprice->value, 2, '.', '')
00071 . ";"
00072 . ";"
00073 . ";"
00074 . ";"
00075 . ";"
00076 . ";"
00077 . ";"
00078 . ";"
00079 . ";"
00080 . ";"
00081 . ";"
00082 . ";"
00083 . ";"
00084
00085
00086 . ";" . number_format($oArticle->oxarticles__oxbprice->value, 2, '.', '')
00087 . ";"
00088 . ";"
00089 . ";"
00090 . ";"
00091 . ";"
00092 . ";"
00093 . ";"
00094 . ";"
00095 . ";"
00096 . ";"
00097 . ";"
00098 . ";"
00099 . ";"
00100 . ";"
00101 . ";" . $oArticle->oxarticles__oxstock->value
00102 . ";"
00103 . ";"
00104 . ";"
00105 . ";"
00106 . ";1"
00107 . ";" . $this->interForm($oArticle->oxarticles__oxshortdesc->value . $oArticle->getLongDesc())
00108 . ";";
00109 $sToFile .= "\r\n";
00110
00111 fwrite($fp, $sToFile);
00112 $rs->moveNext();
00113 }
00114
00115 fclose($fp);
00116
00117 return true;
00118 }
00119
00120 return false;
00121
00122 }
00123
00131 public function interFormSimple($nValue)
00132 {
00133 $nValue = str_replace("\r", "", $nValue);
00134 $nValue = str_replace("\n", " ", $nValue);
00135 $nValue = str_replace('"', '""', $nValue);
00136
00137 return $nValue;
00138 }
00139
00149 public function interForm($nValue, $oObj = null)
00150 {
00151
00152
00153 $aFieldTypesToSkip = array("text", "oxshortdesc", "oxlongdesc");
00154 $blSkipStrpTags = false;
00155 if ($oObj != null) {
00156
00157
00158
00159
00160
00161
00162 if (in_array($oObj->fldtype, $aFieldTypesToSkip) || in_array($oObj->fldname, $aFieldTypesToSkip)) {
00163 $blSkipStripTags = true;
00164 }
00165 }
00166
00167
00168
00169
00170 $oStr = getStr();
00171 if ($oStr->strpos($nValue, "&") !== false && $oStr->strpos($nValue, ";") == false) {
00172 $nValue = str_replace("&", "&", $nValue);
00173 }
00174
00175 $nValue = str_replace(" ", " ", $nValue);
00176 $nValue = str_replace("ä", "�", $nValue);
00177 $nValue = str_replace("ö", "�", $nValue);
00178 $nValue = str_replace("ü", "�", $nValue);
00179 $nValue = str_replace("Ä", "�", $nValue);
00180 $nValue = str_replace("Ö", "�", $nValue);
00181 $nValue = str_replace("Ü", "�", $nValue);
00182 $nValue = str_replace("ß", "�", $nValue);
00183
00184
00185
00186
00187 $nValue = str_replace("& ", "& ", $nValue);
00188
00189 $nValue = str_replace("\"", "'", $nValue);
00190 $nValue = str_replace("(", "'", $nValue);
00191 $nValue = str_replace(")", "'", $nValue);
00192 $nValue = str_replace("\r\n", "", $nValue);
00193 $nValue = str_replace("\n", "", $nValue);
00194
00195 if (!$blSkipStripTags) {
00196 $nValue = strip_tags($nValue);
00197 }
00198
00199 return $nValue;
00200 }
00201
00209 public function internPrice($nPrice)
00210 {
00211 $nPrice = $this->interForm($nPrice);
00212 $nPrice = number_format((double) $nPrice, 2, '.', '');
00213
00214 return $nPrice;
00215 }
00216
00225 public function exportLexwareOrders($iFromOrderNr = "", $iToOrderNr = "")
00226 {
00227
00228 $myConfig = $this->getConfig();
00229
00230 $sNewLine = "\r\n";
00231
00232 $sSelect = "select * from oxorder where 1 ";
00233
00234 if ($iFromOrderNr !== "") {
00235 $iFromOrderNr = (int) $iFromOrderNr;
00236 $sSelect .= "and oxordernr >= $iFromOrderNr ";
00237 }
00238
00239 if ($iToOrderNr !== "") {
00240 $iToOrderNr = (int) $iToOrderNr;
00241 $sSelect .= "and oxordernr <= $iToOrderNr ";
00242 }
00243
00244 $oOrderlist = oxNew("oxlist");
00245 $oOrderlist->init("oxorder");
00246 $oOrderlist->selectString($sSelect);
00247
00248 if (!$oOrderlist->count()) {
00249 return null;
00250 }
00251
00252 $sCharset = $this->_getCharset();
00253
00254 $sExport = "<?xml version=\"1.0\" encoding=\"{$sCharset}\"?>$sNewLine";
00255 $sExport .= "<Bestellliste>$sNewLine";
00256 $sRet = $sExport;
00257
00258 foreach ($oOrderlist as $oOrder) {
00259
00260 $dOrderCurRate = (double) $oOrder->oxorder__oxcurrate->value;
00261
00262 $oUser = oxNew("oxuser");
00263 $oUser->load($oOrder->oxorder__oxuserid->value);
00264
00265 $sExport = "<Bestellung " . $this->_convertStr("zur�ckgestellt") . "=\"Nein\" bearbeitet=\"Nein\" " . $this->_convertStr("�bertragen") . "=\"Nein\">$sNewLine";
00266 $sExport .= "<Bestellnummer>" . $oOrder->oxorder__oxordernr->value . "</Bestellnummer>$sNewLine";
00267 $sExport .= "<Rechnungsnummer>" . $oOrder->oxorder__oxbillnr->value . "</Rechnungsnummer>$sNewLine";
00268 $sExport .= "<Standardwaehrung>978</Standardwaehrung>$sNewLine";
00269 $sExport .= "<Bestelldatum>$sNewLine";
00270 $sDBDate = oxRegistry::get("oxUtilsDate")->formatDBDate($oOrder->oxorder__oxorderdate->value);
00271 $sExport .= "<Datum>" . substr($sDBDate, 0, 10) . "</Datum>$sNewLine";
00272 $sExport .= "<Zeit>" . substr($sDBDate, 11, 8) . "</Zeit>$sNewLine";
00273 $sExport .= "</Bestelldatum>$sNewLine";
00274 $sExport .= "<Kunde>$sNewLine";
00275
00276 $sExport .= "<Kundennummer>" .
00277 "</Kundennummer>$sNewLine";
00278 $sExport .= "<Firmenname>" . $this->interForm($oOrder->oxorder__oxbillcompany->value) . "</Firmenname>$sNewLine";
00279 $sExport .= "<Anrede>" . $this->interForm(oxRegistry::getLang()->translateString($oOrder->oxorder__oxbillsal->value)) . "</Anrede>$sNewLine";
00280 $sExport .= "<Vorname>" . $this->interForm($oOrder->oxorder__oxbillfname->value) . "</Vorname>$sNewLine";
00281 $sExport .= "<Name>" . $this->interForm($oOrder->oxorder__oxbilllname->value) . "</Name>$sNewLine";
00282 $sExport .= "<Strasse>" . $this->interForm($oOrder->oxorder__oxbillstreet->value) . " " . $this->interForm($oOrder->oxorder__oxbillstreetnr->value) . "</Strasse>$sNewLine";
00283 $sExport .= "<PLZ>" . $this->interForm($oOrder->oxorder__oxbillzip->value) . "</PLZ>$sNewLine";
00284 $sExport .= "<Ort>" . $this->interForm($oOrder->oxorder__oxbillcity->value) . "</Ort>$sNewLine";
00285 $sExport .= "<Bundesland>" . "" . "</Bundesland>$sNewLine";
00286 $sExport .= "<Land>" . $this->interForm($oOrder->oxorder__oxbillcountry->value) . "</Land>$sNewLine";
00287 $sExport .= "<Email>" . $this->interForm($oOrder->oxorder__oxbillemail->value) . "</Email>$sNewLine";
00288 $sExport .= "<Telefon>" . $this->interForm($oOrder->oxorder__oxbillfon->value) . "</Telefon>$sNewLine";
00289 $sExport .= "<Telefon2>" . $this->interForm($oUser->oxuser__oxprivfon->value) . "</Telefon2>$sNewLine";
00290 $sExport .= "<Fax>" . $this->interForm($oOrder->oxorder__oxbillfax->value) . "</Fax>$sNewLine";
00291
00292 $sDelComp = "";
00293 $sDelfName = "";
00294 $sDellName = "";
00295 $sDelStreet = "";
00296 $sDelZip = "";
00297 $sDelCity = "";
00298 $sDelCountry = "";
00299
00300
00301 if ($oOrder->oxorder__oxdellname->value) {
00302 $sDelComp = $oOrder->oxorder__oxdelcompany->value;
00303 $sDelfName = $oOrder->oxorder__oxdelfname->value;
00304 $sDellName = $oOrder->oxorder__oxdellname->value;
00305 $sDelStreet = $oOrder->oxorder__oxdelstreet->value . " " . $oOrder->oxorder__oxdelstreetnr->value;
00306 $sDelZip = $oOrder->oxorder__oxdelzip->value;
00307 $sDelCity = $oOrder->oxorder__oxdelcity->value;
00308 $sDelCountry = $oOrder->oxorder__oxdelcountry->value;
00309 }
00310
00311 $sExport .= "<Lieferadresse>$sNewLine";
00312 $sExport .= "<Firmenname>" . $this->interForm($sDelComp) . "</Firmenname>$sNewLine";
00313 $sExport .= "<Vorname>" . $this->interForm($sDelfName) . "</Vorname>$sNewLine";
00314 $sExport .= "<Name>" . $this->interForm($sDellName) . "</Name>$sNewLine";
00315 $sExport .= "<Strasse>" . $this->interForm($sDelStreet) . "</Strasse>$sNewLine";
00316 $sExport .= "<PLZ>" . $this->interForm($sDelZip) . "</PLZ>$sNewLine";
00317 $sExport .= "<Ort>" . $this->interForm($sDelCity) . "</Ort>$sNewLine";
00318 $sExport .= "<Bundesland>" . "" . "</Bundesland>$sNewLine";
00319 $sExport .= "<Land>" . $this->interForm($sDelCountry) . "</Land>$sNewLine";
00320 $sExport .= "</Lieferadresse>$sNewLine";
00321 $sExport .= "<Matchcode>" . $this->interForm($oOrder->oxorder__oxbilllname->value) . ", " . $this->interForm($oOrder->oxorder__oxbillfname->value) . "</Matchcode>$sNewLine";
00322
00323
00324 $sCountry = strtolower($oUser->oxuser__oxcountryid->value);
00325 $aHomeCountry = $myConfig->getConfigParam('aHomeCountry');
00326 $sSteuerbar = (is_array($aHomeCountry) && in_array($sCountry, $aHomeCountry)) ? "ja" : "nein";
00327
00328 $sExport .= "<fSteuerbar>" . $this->interForm($sSteuerbar) . "</fSteuerbar>$sNewLine";
00329 $sExport .= "</Kunde>$sNewLine";
00330 $sExport .= "<Artikelliste>$sNewLine";
00331 $sRet .= $sExport;
00332
00333 $dSumNetPrice = 0;
00334 $dSumBrutPrice = 0;
00335
00336 $oOrderArticles = $oOrder->getOrderArticles(true);
00337 foreach ($oOrderArticles as $oOrderArt) {
00338
00339 $dVATSet = array_search($oOrderArt->oxorderarticles__oxvat->value, $myConfig->getConfigParam('aLexwareVAT'));
00340 $sExport = " <Artikel>$sNewLine";
00341
00342 $sExport .= " <Artikelzusatzinfo><Nettostaffelpreis></Nettostaffelpreis></Artikelzusatzinfo>$sNewLine";
00343 $sExport .= " <SteuersatzID>" . $dVATSet . "</SteuersatzID>$sNewLine";
00344 $sExport .= " <Steuersatz>" . $this->internPrice($oOrderArt->oxorderarticles__oxvat->value / 100) . "</Steuersatz>$sNewLine";
00345 $sExport .= " <Artikelnummer>" . $oOrderArt->oxorderarticles__oxartnum->value . "</Artikelnummer>$sNewLine";
00346 $sExport .= " <Anzahl>" . $oOrderArt->oxorderarticles__oxamount->value . "</Anzahl>$sNewLine";
00347 $sExport .= " <Produktname>" . $this->interForm($oOrderArt->oxorderarticles__oxtitle->value);
00348 if ($oOrderArt->oxorderarticles__oxselvariant->value) {
00349 $sExport .= "/" . $oOrderArt->oxorderarticles__oxselvariant->value;
00350 }
00351 $sExport .= " </Produktname>$sNewLine";
00352 $sExport .= " <Rabatt>0.00</Rabatt>$sNewLine";
00353
00354 $dUnitPrice = $oOrderArt->oxorderarticles__oxbrutprice->value / $oOrderArt->oxorderarticles__oxamount->value;
00355 if ($dOrderCurRate > 0) {
00356 $dUnitPrice /= $dOrderCurRate;
00357 }
00358 $sExport .= " <Preis>" . $this->internPrice($dUnitPrice) . "</Preis>$sNewLine";
00359 $sExport .= " </Artikel>$sNewLine";
00360 $sRet .= $sExport;
00361
00362 $dSumNetPrice += $oOrderArt->oxorderarticles__oxnetprice->value;
00363 $dSumBrutPrice += $oOrderArt->oxorderarticles__oxbrutprice->value;
00364 }
00365
00366 $dDiscount = $oOrder->oxorder__oxvoucherdiscount->value + $oOrder->oxorder__oxdiscount->value;
00367 $dDelCost = $oOrder->oxorder__oxdelcost->value;
00368 $dPaymentCost = $oOrder->oxorder__oxpaycost->value;
00369 if ($dOrderCurRate > 0) {
00370 $dDiscount /= $dOrderCurRate;
00371 $dSumNetPrice /= $dOrderCurRate;
00372 $dDelCost /= $dOrderCurRate;
00373 $dSumBrutPrice /= $dOrderCurRate;
00374 $dPaymentCost /= $dOrderCurRate;
00375 }
00376 $sExport = "<GesamtRabatt>" . $this->internPrice($dDiscount) . "</GesamtRabatt>$sNewLine";
00377 $sExport .= "<GesamtNetto>" . $this->internPrice($dSumNetPrice) . "</GesamtNetto>$sNewLine";
00378 $sExport .= "<Lieferkosten>" . $this->internPrice($dDelCost) . "</Lieferkosten>$sNewLine";
00379 $sExport .= "<Zahlungsartkosten>" . $this->internPrice($dPaymentCost) . "</Zahlungsartkosten>$sNewLine";
00380 $sExport .= "<GesamtBrutto>" . $this->internPrice($dSumBrutPrice) . "</GesamtBrutto>$sNewLine";
00381 $sExport .= "<Bemerkung>" . strip_tags($oOrder->oxorder__oxremark->value) . "</Bemerkung>$sNewLine";
00382 $sRet .= $sExport;
00383
00384 $sExport = "</Artikelliste>$sNewLine";
00385
00386 $sExport .= "<Zahlung>$sNewLine";
00387 $oPayment = oxNew("oxpayment");
00388 $oPayment->load($oOrder->oxorder__oxpaymenttype->value);
00389
00390 $sExport .= "<Art>" . $oPayment->oxpayments__oxdesc->value . "</Art>$sNewLine";
00391 $sExport .= "</Zahlung>$sNewLine";
00392
00393 $sExport .= "</Bestellung>$sNewLine";
00394 $sRet .= $sExport;
00395
00396 $oOrder->oxorder__oxexport->setValue(1);
00397 $oOrder->save();
00398 }
00399 $sExport = "</Bestellliste>$sNewLine";
00400 $sRet .= $sExport;
00401
00402 return $sRet;
00403 }
00404
00410 protected function _getCharset()
00411 {
00412 return oxRegistry::getLang()->translateString('charset');
00413 }
00414
00422 protected function _convertStr($sStr)
00423 {
00424 $sCharset = $this->_getCharset();
00425
00426 if ($sCharset == 'ISO-8859-15') {
00427 return $sStr;
00428 }
00429
00430 return $sStr = iconv('ISO-8859-15', $sCharset, $sStr);
00431 }
00432 }