oximex.php

Go to the documentation of this file.
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                 // first time, write header
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                 // TODO: this place could be optimized. please check what we can do.
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 // Artikelnummer
00058                            //.";".$this->interForm($oArticle->oxarticles__oxshortdesc->value." ".$oArticle->oxarticles__oxvarselect->value) // Bezeichnung
00059                            . ";" . $nTitle . " " . $this->interForm($oArticle->oxarticles__oxvarselect->value) // Bezeichnung
00060                            . ";" . "Stueck" // Einheit
00061                            . ";" . $oArticle->oxarticles__oxweight->value // Gewicht
00062                            . ";" . $oArticle->oxarticles__oxartnum->value // Matchcode
00063                            . ";" . "1,000" // Preis pro Anzahl
00064                            . ";" // Warengruppe
00065                            . ";" // Warengr.-Kurzbez.
00066                            . ";" // Warengr.-Steuersatz
00067                            . ";" // Warengr.-Konto Inland
00068                            . ";" // Warengr.-Konto Ausland
00069                            . ";" // Warengr.-Konto EG
00070                            . ";" . number_format($oArticle->oxarticles__oxprice->value, 2, '.', '') // Preis 1
00071                            . ";" // Preis 2
00072                            . ";" // Preis 3
00073                            . ";" // Preis I/1
00074                            . ";" // Preis I/2
00075                            . ";" // Preis I/3
00076                            . ";" // Preis II/1
00077                            . ";" // Preis II/2
00078                            . ";" // Preis II/3
00079                            . ";" // Preis III/1
00080                            . ";" // Preis III/2
00081                            . ";" // Preis III/3
00082                            . ";" // B/N
00083                            . ";" // Lagerartikel
00084                            //.";".number_format($oArticle->oxarticles__oxtprice->value, 2, '.', '')// EK 1
00085                            // #343 fix
00086                            . ";" . number_format($oArticle->oxarticles__oxbprice->value, 2, '.', '') // EK 1
00087                            . ";" // W�hrung EK1
00088                            . ";" // EK 2
00089                            . ";" // W�hrung EK2
00090                            . ";" // Staffelmenge 1
00091                            . ";" // Staffelmenge 2
00092                            . ";" // Staffelmenge 3
00093                            . ";" // Lieferantennummer 1
00094                            . ";" // Lieferantennummer 2
00095                            . ";" // Bestellmenge Lf.1
00096                            . ";" // Bestellmenge Lf.2
00097                            . ";" // Bestellnr. Lf.1
00098                            . ";" // Bestellnr. Lf.2
00099                            . ";" // Lieferzeit Lf.1
00100                            . ";" // Lieferzeit Lf.2
00101                            . ";" . $oArticle->oxarticles__oxstock->value // Lagerbestand
00102                            . ";" // Mindestbestand
00103                            . ";" // Lagerort
00104                            . ";" // Bestellte Menge
00105                            . ";" // St�ckliste
00106                            . ";1" // Internet
00107                            . ";" . $this->interForm($oArticle->oxarticles__oxshortdesc->value . $oArticle->getLongDesc()) // Text
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     { // thnx to Volker D�rk for this function and his help here
00151 
00152         // #387A skipping conversion for fields where info must be passed in original format
00153         $aFieldTypesToSkip = array("text", "oxshortdesc", "oxlongdesc");
00154         $blSkipStrpTags = false;
00155         if ($oObj != null) {
00156             // using object field "fldtype", to skip processing because usually
00157             // this type of field is used for HTML text
00158             //
00159             // you may change field to "fldname" and add to $aFieldTypesToSkip
00160             // "oxlongdesc" value to skip only longdesc field
00161             //
00162             if (in_array($oObj->fldtype, $aFieldTypesToSkip) || in_array($oObj->fldname, $aFieldTypesToSkip)) {
00163                 $blSkipStripTags = true;
00164             }
00165         }
00166 
00167         //removing simple & (and not  &uuml; chars)
00168         //(not full just a simple check for existing customers for cases like Johnson&Johnson)
00169 
00170         $oStr = getStr();
00171         if ($oStr->strpos($nValue, "&") !== false && $oStr->strpos($nValue, ";") == false) {
00172             $nValue = str_replace("&", "&amp;", $nValue);
00173         }
00174 
00175         $nValue = str_replace("&nbsp;", " ", $nValue);
00176         $nValue = str_replace("&auml;", "�", $nValue);
00177         $nValue = str_replace("&ouml;", "�", $nValue);
00178         $nValue = str_replace("&uuml;", "�", $nValue);
00179         $nValue = str_replace("&Auml;", "�", $nValue);
00180         $nValue = str_replace("&Ouml;", "�", $nValue);
00181         $nValue = str_replace("&Uuml;", "�", $nValue);
00182         $nValue = str_replace("&szlig;", "�", $nValue);
00183 
00184         // usually & symbol goes (or should go) like that:
00185         // "& text...", so we predict that this is a rule
00186         // and replace it with special HTML code
00187         $nValue = str_replace("& ", "&amp; ", $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     { // thnx to Volker D�rk for this function and his help here
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         // thnx to Volker D�rk for this function and his help here
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             // Convert each amount of money with currency rate of the order
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>" . /*$this->interForm($oUser->oxuser__oxcustnr->value).*/
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             // lieferadresse
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             // ermitteln ob steuerbar oder nicht
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                 //$sExport .= "   <Artikelzusatzinfo><Nettostaffelpreis>".$this->InternPrice( $oOrderArt->oxorderarticles__oxnetprice->value)."</Nettostaffelpreis></Artikelzusatzinfo>$sNewLine";
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 }