myorder.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class PdfBlock
00007 {
00008 
00013     protected $_aCache = array();
00014 
00023     protected function _toCache( $sFunc, $aParams )
00024     {
00025         $oItem = new stdClass();
00026         $oItem->sFunc   = $sFunc;
00027         $oItem->aParams = $aParams;
00028         $this->_aCache[]  = $oItem;
00029     }
00030 
00038     public function run( $oPdf )
00039     {
00040         foreach ( $this->_aCache as $oItem ) {
00041             $sFn = $oItem->sFunc;
00042             switch ( count( $oItem->aParams ) ) {
00043                 case 0:
00044                     $oPdf->$sFn();
00045                     break;
00046                 case 1:
00047                     $oPdf->$sFn( $oItem->aParams[0]);
00048                     break;
00049                 case 2:
00050                     $oPdf->$sFn( $oItem->aParams[0], $oItem->aParams[1] );
00051                     break;
00052                 case 3:
00053                     $oPdf->$sFn( $oItem->aParams[0], $oItem->aParams[1], $oItem->aParams[2]);
00054                     break;
00055                 case 4:
00056                     $oPdf->$sFn( $oItem->aParams[0], $oItem->aParams[1], $oItem->aParams[2], $oItem->aParams[3]);
00057                     break;
00058             }
00059         }
00060     }
00061 
00072     public function line( $iLPos, $iLHeight, $iRPos, $iRHeight )
00073     {
00074         $this->_toCache( 'Line', array( $iLPos, $iLHeight, $iRPos, $iRHeight ) );
00075     }
00076 
00086     public function text( $iLPos, $iLHeight, $sString )
00087     {
00088         $this->_toCache( 'Text', array( $iLPos, $iLHeight, $sString ) );
00089     }
00090 
00100     public function font( $sType, $sWeight, $sSize )
00101     {
00102         $this->_toCache( 'SetFont', array( $sType, $sWeight, $sSize ) );
00103     }
00104 
00112     public function ajustHeight( $iDelta )
00113     {
00114         foreach ( $this->_aCache as $key => $oItem ) {
00115             switch ( $oItem->sFunc ) {
00116                 case 'Line':
00117                     $this->_aCache[$key]->aParams[3] += $iDelta;
00118                     $this->_aCache[$key]->aParams[1] += $iDelta;
00119                     break;
00120                 case 'Text':
00121                     $this->_aCache[$key]->aParams[1] += $iDelta;
00122                     break;
00123                 default:;
00124             }
00125         }
00126     }
00127 }
00128 
00132 class PdfArticleSummary extends PdfBlock
00133 {
00134 
00139     protected $_oData = null;
00140 
00145     protected $_oPdf = null;
00146 
00155     public function __construct( $oData, $oPdf )
00156     {
00157         $this->_oData = $oData;
00158         $this->_oPdf = $oPdf;
00159     }
00160 
00168     protected function _setTotalCostsWithoutDiscount( &$iStartPos )
00169     {
00170         // products netto price
00171         $this->line( 15, $iStartPos + 1, 195, $iStartPos + 1 );
00172         $sNetSum = oxLang::getInstance()->formatCurrency( $this->_oData->oxorder__oxtotalnetsum->value, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00173         $this->text( 45, $iStartPos + 4, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_ALLPRICENETTO' ) );
00174         $this->text( 195 - $this->_oPdf->getStringWidth( $sNetSum ), $iStartPos + 4, $sNetSum );
00175 
00176         // #345 - product VAT info
00177         $iCtr = 0;
00178         foreach ( $this->_oData->getVats() as $iVATPercent => $dVATValue ) {
00179             $iStartPos += 4 * $iCtr;
00180             $sVATSum = oxLang::getInstance()->formatCurrency( $dVATValue * $this->_oData->getCurrency()->rate, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00181             $this->text( 45, $iStartPos + 8, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_ZZGLVAT' ).$iVATPercent.$this->_oData->translate( 'ORDER_OVERVIEW_PDF_PERCENTSUM' ) );
00182             $this->text( 195 - $this->_oPdf->getStringWidth( $sVATSum ), $iStartPos + 8, $sVATSum );
00183             $iCtr++;
00184         }
00185 
00186         // products brutto price
00187         $sBrutPrice = oxLang::getInstance()->formatCurrency( $this->_oData->oxorder__oxtotalbrutsum->value, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00188         $this->text( 45, $iStartPos + 12, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_ALLPRICEBRUTTO' ) );
00189         $this->text( 195 - $this->_oPdf->getStringWidth( $sBrutPrice ), $iStartPos + 12, $sBrutPrice );
00190         $iStartPos++;
00191 
00192         // line separator
00193         $this->line( 45, $iStartPos + 13, 195, $iStartPos + 13 );
00194         $iStartPos += 5;
00195     }
00196 
00204     protected function _setTotalCostsWithDiscount( &$iStartPos )
00205     {
00206         // line separator
00207         $this->line( 15, $iStartPos + 1, 195, $iStartPos + 1 );
00208 
00209         // products brutto price
00210         $sBrutPrice = oxLang::getInstance()->formatCurrency( $this->_oData->oxorder__oxtotalbrutsum->value, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00211         $this->text( 45, $iStartPos + 4, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_ALLPRICEBRUTTO' ) );
00212         $this->text( 195 - $this->_oPdf->getStringWidth( $sBrutPrice ), $iStartPos + 4, $sBrutPrice );
00213 
00214         // line separator
00215         $this->line( 45, $iStartPos + 5, 195, $iStartPos + 5 );
00216 
00217         // discount
00218         $dDiscountVal = $this->_oData->oxorder__oxdiscount->value;
00219         if ( $dDiscountVal > 0 ) {
00220             $dDiscountVal *= -1;
00221         }
00222         $sDiscount = oxLang::getInstance()->formatCurrency( $dDiscountVal, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00223         $this->text( 45, $iStartPos + 8, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_DISCOUNT' ) );
00224         $this->text( 195 - $this->_oPdf->getStringWidth( $sDiscount ), $iStartPos + 8, $sDiscount );
00225         $iStartPos++;
00226 
00227         // line separator
00228         $this->line( 45, $iStartPos + 8, 195, $iStartPos + 8 );
00229         $iStartPos += 4;
00230 
00231         // products netto price
00232         $sNetSum = oxLang::getInstance()->formatCurrency( $this->_oData->oxorder__oxtotalnetsum->value, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00233         $this->text( 45, $iStartPos + 8, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_ALLPRICENETTO' ) );
00234         $this->text( 195 - $this->_oPdf->getStringWidth( $sNetSum ), $iStartPos + 8, $sNetSum );
00235 
00236         // #345 - product VAT info
00237         $iCtr = 0;
00238         foreach ( $this->_oData->getVats() as $iVATPercent => $dVATValue ) {
00239             $iStartPos += 4 * $iCtr;
00240             $sVATSum = oxLang::getInstance()->formatCurrency( $dVATValue * $this->_oData->getCurrency()->rate, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00241             $this->text( 45, $iStartPos + 12, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_ZZGLVAT' ).$iVATPercent.$this->_oData->translate('ORDER_OVERVIEW_PDF_PERCENTSUM' ) );
00242             $this->text( 195 - $this->_oPdf->getStringWidth( $sVATSum ), $iStartPos + 12, $sVATSum );
00243             $iCtr++;
00244         }
00245         $iStartPos += 4;
00246     }
00247 
00255     protected function _setVoucherInfo( &$iStartPos )
00256     {
00257         $dVoucher = 0;
00258         if ( $this->_oData->oxorder__oxvoucherdiscount->value ) {
00259             $dDiscountVal = $this->_oData->oxorder__oxvoucherdiscount->value;
00260             if ( $dDiscountVal > 0 ) {
00261                 $dDiscountVal *= -1;
00262             }
00263             $sPayCost = oxLang::getInstance()->formatCurrency( $dDiscountVal, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00264             $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_VOUCHER' ) );
00265             $this->text( 195 - $this->_oPdf->getStringWidth( $sPayCost ), $iStartPos, $sPayCost );
00266             $iStartPos += 4;
00267         }
00268 
00269         $iStartPos++;
00270     }
00271 
00279     protected function _setDeliveryInfo( &$iStartPos )
00280     {
00281         $sAddString = '';
00282         if ( $this->_oData->oxorder__oxdelvat->value ) {
00283 
00284             // delivery netto
00285             $sDelCostNetto = oxLang::getInstance()->formatCurrency( $this->_oData->getOrderDeliveryPrice()->getNettoPrice(), $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00286             $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_SHIPCOST' ).' '.$this->_oData->translate('ORDER_OVERVIEW_PDF_NETTO' ) );
00287             $this->text( 195 - $this->_oPdf->getStringWidth( $sDelCostNetto ), $iStartPos, $sDelCostNetto );
00288             $iStartPos += 4;
00289 
00290             // delivery VAT
00291             $sDelCostVAT = oxLang::getInstance()->formatCurrency( $this->_oData->getOrderDeliveryPrice()->getVATValue(), $this->_oData->getCurrency()).' '.$this->_oData->getCurrency()->name;
00292             $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_ZZGLVAT' ).$this->_oData->oxorder__oxdelvat->value.$this->_oData->translate( 'ORDER_OVERVIEW_PDF_PERCENTSUM' ) );
00293             $this->text( 195 - $this->_oPdf->getStringWidth( $sDelCostVAT ), $iStartPos, $sDelCostVAT );
00294             $iStartPos += 4;
00295 
00296             $sAddString = ' '.$this->_oData->translate( 'ORDER_OVERVIEW_PDF_BRUTTO' );
00297 
00298             // drawing line separator
00299             $this->line( 45, $iStartPos - 3, 195, $iStartPos - 3 );
00300             $iStartPos++;
00301         }
00302 
00303         // delivery costs
00304 
00305         // if canceled order, reset value
00306         if ( $this->_oData->oxorder__oxstorno->value ) {
00307             $this->_oData->oxorder__oxdelcost->setValue(0);
00308         }
00309 
00310         $sDelCost = oxLang::getInstance()->formatCurrency( $this->_oData->oxorder__oxdelcost->value, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00311         $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_SHIPCOST' ).$sAddString );
00312         $this->text( 195 - $this->_oPdf->getStringWidth( $sDelCost ), $iStartPos, $sDelCost );
00313     }
00314 
00322     protected function _setWrappingInfo( &$iStartPos )
00323     {
00324         if ( $this->_oData->oxorder__oxwrapcost->value ) {
00325             $sAddString = '';
00326 
00327             //displaying wrapping VAT info
00328             if ( $this->_oData->oxorder__oxwrapvat->value ) {
00329 
00330                 // wrapping netto
00331                 $iStartPos += 5;
00332                 $sWrapCostNetto = oxLang::getInstance()->formatCurrency( $this->_oData->getOrderWrappingPrice()->getNettoPrice(), $this->_oData->getCurrency()).' '.$this->_oData->getCurrency()->name;
00333                 $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_WRAPPING' ).' '.$this->_oData->translate( 'ORDER_OVERVIEW_PDF_NETTO' ) );
00334                 $this->text( 195 - $this->_oPdf->getStringWidth( $sWrapCostNetto ), $iStartPos, $sWrapCostNetto );
00335 
00336                 //wrapping VAT
00337                 $iStartPos += 4;
00338                 $sWrapCostVAT = oxLang::getInstance()->formatCurrency( $this->_oData->getOrderWrappingPrice()->getVATValue(), $this->_oData->getCurrency()).' '.$this->_oData->getCurrency()->name;
00339                 $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_ZZGLVAT' ).$this->_oData->oxorder__oxwrapvat->value.$this->_oData->translate( 'ORDER_OVERVIEW_PDF_PERCENTSUM' ) );
00340                 $this->text( 195 - $this->_oPdf->getStringWidth( $sWrapCostVAT ), $iStartPos, $sWrapCostVAT );
00341 
00342                 $sAddString = ' '.$this->_oData->translate( 'ORDER_OVERVIEW_PDF_BRUTTO' );
00343 
00344                 // drawing line separator
00345                 $iStartPos += 4;
00346                 $this->line(45, $iStartPos - 3, 195, $iStartPos - 3);
00347             }
00348             $iStartPos += 4;
00349 
00350             // wrapping cost
00351             $sWrapCost = oxLang::getInstance()->formatCurrency( $this->_oData->oxorder__oxwrapcost->value, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00352             $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_WRAPPING' ).$sAddString );
00353             $this->text( 195 - $this->_oPdf->getStringWidth( $sWrapCost ), $iStartPos, $sWrapCost );
00354             $iStartPos++;
00355         }
00356     }
00357 
00365     protected function _setPaymentInfo( &$iStartPos )
00366     {
00367         if ( $this->_oData->oxorder__oxpayvat->value ) {
00368 
00369             // payment netto
00370             $iStartPos += 4;
00371             $sPayCostNetto = oxLang::getInstance()->formatCurrency( $this->_oData->getOrderPaymentPrice()->getNettoPrice(), $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00372             $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_PAYMENTIMPACT' ).' '.$this->_oData->translate( 'ORDER_OVERVIEW_PDF_NETTO' ) );
00373             $this->text( 195 - $this->_oPdf->getStringWidth( $sPayCostNetto ), $iStartPos, $sPayCostNetto );
00374 
00375             // payment VAT
00376             $iStartPos += 4;
00377             $sPayCostVAT = oxLang::getInstance()->formatCurrency( $this->_oData->getOrderPaymentPrice()->getVATValue(), $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00378             $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_ZZGLVAT' ).$this->_oData->oxorder__oxpayvat->value.$this->_oData->translate( 'ORDER_OVERVIEW_PDF_PERCENTSUM' ) );
00379             $this->text( 195 - $this->_oPdf->getStringWidth( $sPayCostVAT ), $iStartPos, $sPayCostVAT );
00380 
00381         }
00382 
00383         // if canceled order, reset value
00384         if ( $this->_oData->oxorder__oxstorno->value ) {
00385             $this->_oData->oxorder__oxpaycost->setValue(0);
00386         }
00387 
00388         // payment costs
00389         $iStartPos += 4;
00390         $sPayCost = oxLang::getInstance()->formatCurrency( $this->_oData->oxorder__oxpaycost->value, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00391         $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_PAYMENTIMPACT' ) );
00392         $this->text( 195 - $this->_oPdf->getStringWidth( $sPayCost ), $iStartPos, $sPayCost );
00393 
00394         $iStartPos++;
00395     }
00396 
00404     protected function _setGrandTotalPriceInfo( &$iStartPos )
00405     {
00406         // total netto price (A. very unprecise, impossible to count because of many factors)
00407         $this->font( 'Arial', 'B', 10 );
00408         if ( $this->_oData->oxorder__oxdelvat->value || $this->_oData->oxorder__oxwrapvat->value || $this->_oData->oxorder__oxpayvat->value ) {
00409 
00410             // collecting total net price
00411             $sTotalNetSum = oxLang::getInstance()->formatCurrency( $this->_oData->getOrderNetSum(), $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00412             $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_ALLSUM_NET' ) );
00413             $this->text( 195 - $this->_oPdf->getStringWidth( $sTotalNetSum ), $iStartPos, $sTotalNetSum );
00414             $iStartPos += 4;
00415         }
00416 
00417         // total order sum
00418         $sTotalOrderSum = oxLang::getInstance()->formatCurrency( $this->_oData->oxorder__oxtotalordersum->value, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00419         $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_ALLSUM' ) );
00420         $this->text( 195 - $this->_oPdf->getStringWidth( $sTotalOrderSum ), $iStartPos, $sTotalOrderSum );
00421         $iStartPos += 2;
00422     }
00423 
00431     protected function _setPaymentMethodInfo( &$iStartPos )
00432     {
00433         $oPayment = oxNew( 'oxpayment' );
00434         $oPayment->loadInLang( $this->_oData->getSelectedLang(), $this->_oData->oxorder__oxpaymenttype->value );
00435 
00436         $text = $this->_oData->translate( 'ORDER_OVERVIEW_PDF_SELPAYMENT' ).$oPayment->oxpayments__oxdesc->value;
00437         $this->font( 'Arial', '', 10 );
00438         $this->text( 15, $iStartPos + 4, $text );
00439         $iStartPos += 4;
00440     }
00441 
00449     protected function _setPayUntilInfo( &$iStartPos )
00450     {
00451         $text = $this->_oData->translate( 'ORDER_OVERVIEW_PDF_PAYUPTO' ).date( 'd.m.Y', mktime( 0, 0, 0, date ( 'm' ), date ( 'd' ) + 7, date( 'Y' ) ) );
00452         $this->font( 'Arial', '', 10 );
00453         $this->text( 15, $iStartPos + 4, $text );
00454         $iStartPos += 4;
00455     }
00456 
00464     public function generate( $iStartPos )
00465     {
00466 
00467         $this->font( 'Arial', '', 10 );
00468         $siteH = $iStartPos;
00469 
00470         // #1147 discount for vat must be displayed
00471         if ( !$this->_oData->oxorder__oxdiscount->value ) {
00472             $this->_setTotalCostsWithoutDiscount( $siteH );
00473         } else {
00474             $this->_setTotalCostsWithDiscount( $siteH );
00475         }
00476 
00477         $siteH += 12;
00478 
00479         // voucher info
00480         $this->_setVoucherInfo( $siteH );
00481 
00482         // additional line separator
00483         if ( $this->_oData->oxorder__oxdiscount->value || $this->_oData->oxorder__oxvoucherdiscount->value ) {
00484             $this->line( 45, $siteH - 3, 195, $siteH - 3 );
00485         }
00486 
00487         // delivery info
00488         $this->_setDeliveryInfo( $siteH );
00489 
00490         // wrapping info
00491         $this->_setWrappingInfo( $siteH );
00492 
00493         // payment info
00494         $this->_setPaymentInfo( $siteH );
00495 
00496         // separating line
00497         $this->line( 15, $siteH, 195, $siteH );
00498         $siteH += 4;
00499 
00500         // total order sum
00501         $this->_setGrandTotalPriceInfo( $siteH );
00502 
00503         // separating line
00504         $this->line( 15, $siteH, 195, $siteH );
00505         $siteH += 4;
00506 
00507         // payment method
00508         $this->_setPaymentMethodInfo( $siteH );
00509 
00510         // pay until ...
00511         $this->_setPayUntilInfo( $siteH );
00512 
00513         return $siteH - $iStartPos;
00514     }
00515 }
00516 
00520 class MyOrder extends MyOrder_parent
00521 {
00522 
00527     protected $_iSelectedLang = 0;
00528 
00533     protected $_oActShop = null;
00534 
00539     protected $_aVATs = array();
00540 
00545     protected $_oCur = null;
00546 
00552     protected function _getActShop()
00553     {
00554         // shop is allready loaded
00555         if ( $this->_oActShop !== null )
00556             return $this->_oActShop;
00557 
00558         $this->_oActShop = oxNew( 'oxshop' );
00559         $this->_oActShop->load( $this->getConfig()->getShopId() );
00560 
00561         return $this->_oActShop;
00562     }
00563 
00571     public function translate( $sString )
00572     {
00573         return oxLang::getInstance()->translateString( $sString, $this->_iSelectedLang );
00574     }
00575 
00583     public function pdfFooter( $oPdf )
00584     {
00585 
00586         $oShop = $this->_getActShop();
00587 
00588         $oPdf->line( 15, 272, 195, 272 );
00589 
00590         /* column 1 - company name, shop owner info, shop address */
00591         $oPdf->setFont( 'Arial', '', 7 );
00592         $oPdf->text( 15, 275, strip_tags( $oShop->oxshops__oxcompany->value ) );
00593         $oPdf->text( 15, 278, strip_tags( $oShop->oxshops__oxfname->value ).' '. strip_tags( $oShop->oxshops__oxlname->value ) );
00594         $oPdf->text( 15, 281, strip_tags( $oShop->oxshops__oxstreet->value ) );
00595         $oPdf->text( 15, 284, strip_tags( $oShop->oxshops__oxzip->value ).' '. strip_tags( $oShop->oxshops__oxcity->value ) );
00596         $oPdf->text( 15, 287, strip_tags( $oShop->oxshops__oxcountry->value ) );
00597 
00598         /* column 2 - phone, fax, url, email address */
00599         $oPdf->text( 85, 275, $this->translate( 'ORDER_OVERVIEW_PDF_PHONE' ).strip_tags( $oShop->oxshops__oxtelefon->value ) );
00600         $oPdf->text( 85, 278, $this->translate( 'ORDER_OVERVIEW_PDF_FAX' ).strip_tags( $oShop->oxshops__oxtelefax->value ) );
00601         $oPdf->text( 85, 281, strip_tags( $oShop->oxshops__oxurl->value ) );
00602         $oPdf->text( 85, 284, strip_tags( $oShop->oxshops__oxorderemail->value ) );
00603 
00604         /* column 3 - bank information */
00605         $oPdf->text( 150, 275, strip_tags( $oShop->oxshops__oxbankname->value ) );
00606         $oPdf->text( 150, 278, $this->translate( 'ORDER_OVERVIEW_PDF_ACCOUNTNR' ).strip_tags( $oShop->oxshops__oxbanknumber->value ) );
00607         $oPdf->text( 150, 281, $this->translate( 'ORDER_OVERVIEW_PDF_BANKCODE' ).strip_tags( $oShop->oxshops__oxbankcode->value ) );
00608         $oPdf->text( 150, 284, strip_tags( $oShop->oxshops__oxvatnumber->value ) );
00609         $oPdf->text( 150, 287, '' );
00610     }
00611 
00619     public function pdfHeaderPlus( $oPdf )
00620     {
00621 
00622         // new page with shop logo
00623         $this->pdfHeader( $oPdf );
00624 
00625         // column names
00626         $oPdf->setFont( 'Arial', '', 8 );
00627         $oPdf->text( 15, 50, $this->translate( 'ORDER_OVERVIEW_PDF_AMOUNT' ) );
00628         $oPdf->text( 30, 50, $this->translate( 'ORDER_OVERVIEW_PDF_ARTID') );
00629         $oPdf->text( 45, 50, $this->translate( 'ORDER_OVERVIEW_PDF_DESC' ) );
00630         $oPdf->text( 160, 50, $this->translate( 'ORDER_OVERVIEW_PDF_UNITPRICE' ) );
00631         $sText = $this->translate( 'ORDER_OVERVIEW_PDF_ALLPRICE' );
00632         $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), 50, $sText );
00633 
00634         // line separator
00635         $oPdf->line( 15, 52, 195, 52 );
00636 
00637         return 56;
00638     }
00639 
00647     public function pdfHeader( $oPdf )
00648     {
00649         // adding new page ...
00650         $oPdf->addPage();
00651 
00652         // loading active shop
00653         $oShop = $this->_getActShop();
00654 
00655         //logo
00656         $myConfig = $this->getConfig();
00657         $aSize    = getimagesize( $myConfig->getAbsImageDir().'/pdf_logo.jpg' );
00658         $iMargin  = 195 - $aSize[0] * 0.2;
00659         $oPdf->setLink( $oShop->oxshops__oxurl->value );
00660         $oPdf->image( $myConfig->getAbsImageDir().'/pdf_logo.jpg', $iMargin, 10, $aSize[0] * 0.2, $aSize[1] * 0.2, '', $oShop->oxshops__oxurl->value );
00661         return 14 + $aSize[1] * 0.2;
00662     }
00663 
00672     public function genPdf( $sFilename, $iSelLang = 0 )
00673     {
00674         // setting pdf language
00675         $this->_iSelectedLang = $iSelLang;
00676 
00677         // setting invoice number
00678         if ( !$this->oxorder__oxinvoicenr->value ) {
00679             $this->oxorder__oxinvoicenr->setValue($this->getInvoiceNum());
00680             $this->save();
00681         }
00682 
00683         // initiating pdf engine
00684         $oPdf = oxNew( 'oxPDF' );
00685         $oPdf->open();
00686 
00687         // adding header
00688         $this->pdfHeader( $oPdf );
00689 
00690         // adding info data
00691         switch ( oxConfig::getParameter( 'pdftype' ) ) {
00692             case 'dnote':
00693                 $this->exportDeliveryNote( $oPdf );
00694                 break;
00695             default:
00696                 $this->exportStandart( $oPdf );
00697         }
00698 
00699         // adding footer
00700         $this->pdfFooter( $oPdf );
00701 
00702         // outputting file to browser
00703         $oPdf->output( $sFilename, true );
00704     }
00705 
00706 
00714     protected function _setBillingAddressToPdf( $oPdf )
00715     {
00716         $oPdf->setFont( 'Arial', '', 10 );
00717         $oPdf->text( 15, 59, $this->oxorder__oxbillsal->value );
00718         $oPdf->text( 15, 63, $this->oxorder__oxbilllname->value.' '.$this->oxorder__oxbillfname->value );
00719         $oPdf->text( 15, 67, $this->oxorder__oxbillcompany->value );
00720         $oPdf->text( 15, 71, $this->oxorder__oxbillstreet->value.' '.$this->oxorder__oxbillstreetnr->value );
00721         $oPdf->setFont( 'Arial', 'B', 10 );
00722         $oPdf->text( 15, 75, $this->oxorder__oxbillzip->value.' '.$this->oxorder__oxbillcity->value );
00723         $oPdf->setFont( 'Arial', '', 10 );
00724         $oPdf->text( 15, 79, $this->oxorder__oxbillcountry->value );
00725     }
00726 
00734     protected function _setDeliveryAddressToPdf( $oPdf )
00735     {
00736         $oPdf->setFont( 'Arial', '', 6 );
00737         $oPdf->text( 15, 87, $this->translate( 'ORDER_OVERVIEW_PDF_DELIVERYADDRESS' ) );
00738         $oPdf->setFont( 'Arial', '', 10 );
00739         $oPdf->text( 15, 91, $this->oxorder__oxdelsal->value );
00740         $oPdf->text( 15, 95, $this->oxorder__oxdellname->value.' '.$this->oxorder__oxdelfname->value );
00741         $oPdf->text( 15, 99, $this->oxorder__oxdelcompany->value );
00742         $oPdf->text( 15, 103, $this->oxorder__oxdelstreet->value.' '.$this->oxorder__oxdelstreetnr->value );
00743         $oPdf->setFont( 'Arial', 'B', 10 );
00744         $oPdf->text( 15, 107, $this->oxorder__oxdelzip->value.' '.$this->oxorder__oxdelcity->value );
00745         $oPdf->setFont( 'Arial', '', 10 );
00746         $oPdf->text( 15, 111, $this->oxorder__oxdelcountry->value );
00747     }
00748 
00758     protected function _setOrderArticlesToPdf( $oPdf, &$iStartPos, $blShowPrice = true )
00759     {
00760         if (!$this->_oArticles) {
00761             $this->_oArticles = $this->getOrderArticles(true);
00762         }
00763 
00764         // product list
00765         foreach ( $this->_oArticles as $key => $oOrderArt ) {
00766 
00767             // starting a new page ...
00768             if ( $iStartPos > 243 ) {
00769                 $this->pdffooter( $oPdf );
00770                 $iStartPos = $this->pdfheaderplus( $oPdf );
00771                 $oPdf->setFont( 'Arial', '', 10 );
00772             } else {
00773                 $iStartPos = $iStartPos + 4;
00774             }
00775 
00776             // sold amount
00777             $oPdf->text( 20 - $oPdf->getStringWidth( $oOrderArt->oxorderarticles__oxamount->value ), $iStartPos, $oOrderArt->oxorderarticles__oxamount->value );
00778 
00779             // product number
00780             $oPdf->setFont( 'Arial', '', 8 );
00781             $oPdf->text( 28, $iStartPos, $oOrderArt->oxorderarticles__oxartnum->value );
00782 
00783             // product title
00784             $oPdf->setFont( 'Arial', '', 10 );
00785             $oPdf->text( 45, $iStartPos, substr( strip_tags( $this->_replaceExtendedChars( $oOrderArt->oxorderarticles__oxtitle->value, true ) ), 0, 58 ) );
00786 
00787             if ( $blShowPrice ) {
00788 
00789                 // product price
00790                 $sText = oxLang::getInstance()->formatCurrency( $oOrderArt->oxorderarticles__oxbprice->value, $this->_oCur ).' '.$this->_oCur->name;
00791                 $oPdf->text( 163 - $oPdf->getStringWidth( $sText ), $iStartPos, $sText );
00792 
00793                 // total product price
00794                 $sText = oxLang::getInstance()->formatCurrency( $oOrderArt->oxorderarticles__oxbrutprice->value, $this->_oCur ).' '.$this->_oCur->name;
00795                 $oPdf->text( 184 - $oPdf->getStringWidth( $sText ), $iStartPos, $sText );
00796 
00797                 // product VAT percent
00798                 $oPdf->text( 195 - $oPdf->getStringWidth( $oOrderArt->oxorderarticles__oxvat->value ), $iStartPos, $oOrderArt->oxorderarticles__oxvat->value );
00799 
00800                 // calculating product VAT info
00801                 if ( !isset( $this->_aVATs[$oOrderArt->oxorderarticles__oxvat->value] ) ) {
00802                     $this->_aVATs[$oOrderArt->oxorderarticles__oxvat->value] = 0;
00803                 }
00804                 $this->_aVATs[$oOrderArt->oxorderarticles__oxvat->value] += $oOrderArt->oxorderarticles__oxvatprice->value;
00805             }
00806 
00807             // additional variant info
00808             if ( $oOrderArt->oxorderarticles__oxselvariant->value ) {
00809                 $iStartPos = $iStartPos + 4;
00810                 $oPdf->text( 45, $iStartPos, substr( $oOrderArt->oxorderarticles__oxselvariant->value, 0, 58 ) );
00811             }
00812 
00813         }
00814     }
00815 
00823     public function exportStandart( $oPdf )
00824     {
00825         // preparing order curency info
00826         $myConfig = $this->getConfig();
00827 
00828         $this->_oCur = $myConfig->getCurrencyObject( $this->oxorder__oxcurrency->value );
00829         if ( !$this->_oCur ) {
00830             $this->_oCur = $myConfig->getActShopCurrencyObject();
00831         }
00832 
00833         // loading active shop
00834         $oShop = $this->_getActShop();
00835 
00836         // shop information
00837         $oPdf->setFont( 'Arial', '', 6 );
00838         $oPdf->text( 15, 55, $oShop->oxshops__oxname->value.' - '.$oShop->oxshops__oxstreet->value.' - '.$oShop->oxshops__oxzip->value.' - '.$oShop->oxshops__oxcity->value );
00839 
00840         // billing address
00841         $this->_setBillingAddressToPdf( $oPdf );
00842 
00843         // delivery address
00844         if ( $this->oxorder__oxdelsal->value ) {
00845             $this->_setDeliveryAddressToPdf( $oPdf );
00846         }
00847 
00848         // loading user
00849         $oUser = oxNew( 'oxuser' );
00850         $oUser->load( $this->oxorder__oxuserid->value );
00851 
00852         // user info
00853         $sText = $this->translate( 'ORDER_OVERVIEW_PDF_FILLONPAYMENT' );
00854         $oPdf->setFont( 'Arial', '', 5 );
00855         $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), 55, $sText );
00856 
00857         // customer number
00858         $sCustNr = $this->translate( 'ORDER_OVERVIEW_PDF_CUSTNR').' '.$oUser->oxuser__oxcustnr->value;
00859         $oPdf->setFont( 'Arial', '', 7 );
00860         $oPdf->text( 195 - $oPdf->getStringWidth( $sCustNr ), 59, $sCustNr );
00861 
00862         // setting position if delivery address is used
00863         if ( $this->oxorder__oxdelsal->value ) {
00864             $iTop = 115;
00865         } else {
00866             $iTop = 91;
00867         }
00868 
00869         // shop city
00870         $sText = $oShop->oxshops__oxcity->value.', '.date( 'd.m.Y' );
00871         $oPdf->setFont( 'Arial', '', 10 );
00872         $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), $iTop + 8, $sText );
00873 
00874         // shop VAT number
00875         if ( $oShop->oxshops__oxvatnumber->value ) {
00876             $sText = $this->translate( 'ORDER_OVERVIEW_PDF_TAXIDNR' ).' '.$oShop->oxshops__oxvatnumber->value;
00877             $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), $iTop + 12, $sText );
00878             $iTop += 8;
00879         }
00880 
00881         // invoice number
00882         $sText = $this->translate( 'ORDER_OVERVIEW_PDF_COUNTNR' ).' '.$this->oxorder__oxinvoicenr->value;
00883         $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), $iTop + 8, $sText );
00884 
00885         // marking if order is canceled
00886         if ( $this->oxorder__oxstorno->value == 1 ) {
00887             $this->oxorder__oxordernr->value .= '   '.$this->translate( 'ORDER_OVERVIEW_PDF_STORNO' );
00888         }
00889 
00890         // order number
00891         $oPdf->setFont( 'Arial', '', 12 );
00892         $oPdf->text( 15, $iTop, $this->translate( 'ORDER_OVERVIEW_PDF_PURCHASENR' ).' '.$this->oxorder__oxordernr->value );
00893 
00894         // order date
00895         $oPdf->setFont( 'Arial', '', 10 );
00896         $aOrderDate = explode( ' ', $this->oxorder__oxorderdate->value );
00897         $sOrderDate = $aOrderDate[0];
00898         $oPdf->text( 15, $iTop + 8, $this->translate( 'ORDER_OVERVIEW_PDF_ORDERSFROM' ).$sOrderDate.$this->translate( 'ORDER_OVERVIEW_PDF_ORDERSAT' ).$oShop->oxshops__oxurl->value );
00899         $iTop += 16;
00900 
00901         // product info header
00902         $oPdf->setFont( 'Arial', '', 8 );
00903         $oPdf->text( 15, $iTop, $this->translate( 'ORDER_OVERVIEW_PDF_AMOUNT' ) );
00904         $oPdf->text( 30, $iTop, $this->translate( 'ORDER_OVERVIEW_PDF_ARTID' ) );
00905         $oPdf->text( 45, $iTop, $this->translate( 'ORDER_OVERVIEW_PDF_DESC' ) );
00906         $oPdf->text( 148, $iTop, $this->translate( 'ORDER_OVERVIEW_PDF_UNITPRICE' ) );
00907         $oPdf->text( 168, $iTop, $this->translate( 'ORDER_OVERVIEW_PDF_ALLPRICE' ) );
00908         $sText = $this->translate( 'ORDER_OVERVIEW_PDF_VAT' );
00909         $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), $iTop, $sText );
00910 
00911         // separator line
00912         $iTop += 2;
00913         $oPdf->line( 15, $iTop, 195, $iTop );
00914 
00915         // #345
00916         $siteH = $iTop;
00917         $oPdf->setFont( 'Arial', '', 10 );
00918 
00919         // order articles
00920         $this->_setOrderArticlesToPdf( $oPdf, $siteH, true );
00921 
00922         // generating pdf file
00923         $oArtSumm = new PdfArticleSummary( $this, $oPdf );
00924         $iHeight = $oArtSumm->generate( $siteH );
00925         if ( $siteH + $iHeight > 258 ) {
00926             $this->pdfFooter( $oPdf );
00927             $iTop = $this->pdfHeader( $oPdf );
00928             $oArtSumm->ajustHeight( $iTop - $siteH );
00929             $siteH = $iTop;
00930         }
00931 
00932         $oArtSumm->run( $oPdf );
00933         $siteH += $iHeight + 8;
00934 
00935         $oPdf->text( 15, $siteH, $this->translate( 'ORDER_OVERVIEW_PDF_GREETINGS' ) );
00936     }
00937 
00945     public function exportDeliveryNote( $oPdf )
00946     {
00947         $myConfig = $this->getConfig();
00948         $oShop    = $this->_getActShop();
00949 
00950         // loading order currency info
00951         $this->_oCur = $myConfig->getCurrencyObject( $this->oxorder__oxcurrency->value );
00952         if ( !isset( $this->_oCur ) ) {
00953             $this->_oCur = $myConfig->getActShopCurrencyObject();
00954         }
00955 
00956         // shop info
00957         $oPdf->setFont( 'Arial', '', 6 );
00958         $oPdf->text( 15, 55, $oShop->oxshops__oxname->value.' - '.$oShop->oxshops__oxstreet->value.' - '.$oShop->oxshops__oxzip->value.' - '.$oShop->oxshops__oxcity->value );
00959 
00960         // delivery address
00961         $oPdf->setFont( 'Arial', '', 10 );
00962         if ( $this->oxorder__oxdelsal->value ) {
00963             $oPdf->text( 15, 59, $this->oxorder__oxdelsal->value );
00964             $oPdf->text( 15, 63, $this->oxorder__oxdellname->value.' '.$this->oxorder__oxdelfname->value );
00965             $oPdf->text( 15, 67, $this->oxorder__oxdelcompany->value );
00966             $oPdf->text( 15, 71, $this->oxorder__oxdelstreet->value.' '.$this->oxorder__oxdelstreetnr->value );
00967             $oPdf->setFont( 'Arial', 'B', 10 );
00968             $oPdf->text( 15, 75, $this->oxorder__oxdelzip->value.' '.$this->oxorder__oxdelcity->value );
00969             $oPdf->setFont( 'Arial', '', 10 );
00970             $oPdf->text( 15, 79, $this->oxorder__oxdelcountry->value );
00971         } else { // no delivery address - billing address is used for delivery
00972             $this->_setBillingAddressToPdf( $oPdf );
00973         }
00974 
00975         // loading user info
00976         $oUser = oxNew( 'oxuser' );
00977         $oUser->load( $this->oxorder__oxuserid->value );
00978 
00979         // user info
00980         $sText = $this->translate( 'ORDER_OVERVIEW_PDF_FILLONPAYMENT' );
00981         $oPdf->setFont( 'Arial', '', 5 );
00982         $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), 70, $sText );
00983 
00984         // customer number
00985         $sCustNr = $this->translate( 'ORDER_OVERVIEW_PDF_CUSTNR' ).' '.$oUser->oxuser__oxcustnr->value;
00986         $oPdf->setFont( 'Arial', '', 7 );
00987         $oPdf->text( 195 - $oPdf->getStringWidth( $sCustNr ), 73, $sCustNr );
00988 
00989         // shops city
00990         $sText = $oShop->oxshops__oxcity->value.', '.date( 'd.m.Y' );
00991         $oPdf->setFont( 'Arial', '', 10 );
00992         $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), 95, $sText );
00993 
00994         $iTop = 99;
00995         // shop VAT number
00996         if ( $oShop->oxshops__oxvatnumber->value ) {
00997             $sText = $this->translate( 'ORDER_OVERVIEW_PDF_TAXIDNR' ).' '.$oShop->oxshops__oxvatnumber->value;
00998             $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), $iTop, $sText );
00999             $iTop += 4;
01000         }
01001 
01002         // invoice number
01003         $sText = $this->translate( 'ORDER_OVERVIEW_PDF_COUNTNR' ).' '.$this->oxorder__oxinvoicenr->value;
01004         $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), $iTop, $sText );
01005 
01006         // canceled order marker
01007         if ( $this->oxorder__oxstorno->value == 1 ) {
01008             $this->oxorder__oxordernr->value .= '   '.$this->translate( 'ORDER_OVERVIEW_PDF_STORNO' );
01009         }
01010 
01011         // order number
01012         $oPdf->setFont( 'Arial', '', 12 );
01013         $oPdf->text( 15, 108, $this->translate( 'ORDER_OVERVIEW_PDF_DELIVNOTE' ).' '.$this->oxorder__oxordernr->value );
01014 
01015         // order date
01016         $aOrderDate = explode( ' ', $this->oxorder__oxorderdate->value );
01017         $sOrderDate = $aOrderDate[0];
01018         $oPdf->setFont( 'Arial', '', 10 );
01019         $oPdf->text(15, 119, $this->translate( 'ORDER_OVERVIEW_PDF_ORDERSFROM' ).$sOrderDate.$this->translate( 'ORDER_OVERVIEW_PDF_ORDERSAT' ).$oShop->oxshops__oxurl->value );
01020 
01021         // product info header
01022         $oPdf->setFont( 'Arial', '', 8 );
01023         $oPdf->text( 15, 128, $this->translate( 'ORDER_OVERVIEW_PDF_AMOUNT' ) );
01024         $oPdf->text( 30, 128, $this->translate( 'ORDER_OVERVIEW_PDF_ARTID' ) );
01025         $oPdf->text( 45, 128, $this->translate( 'ORDER_OVERVIEW_PDF_DESC' ) );
01026 
01027         // line separator
01028         $oPdf->line( 15, 130, 195, 130 );
01029 
01030         // product list
01031         $oPdf->setFont( 'Arial', '', 10 );
01032         $siteH = 130;
01033 
01034         // order articles
01035         $this->_setOrderArticlesToPdf( $oPdf, $siteH, false );
01036 
01037         // sine separator
01038         $oPdf->line( 15, $siteH + 2, 195, $siteH + 2 );
01039         $siteH += 4;
01040 
01041         // payment date
01042         $oPdf->setFont( 'Arial', '', 10 );
01043         $text = $this->translate( 'ORDER_OVERVIEW_PDF_PAYUPTO' ).date( 'd.m.Y', mktime( 0, 0, 0, date ( 'm' ), date ( 'd' ) + 7, date( 'Y' ) ) );
01044         $oPdf->text( 15, $siteH + 4, $text );
01045     }
01046 
01056     protected function _replaceExtendedChars( $sValue, $blReverse = false )
01057     {
01058         // we need to replace this for compatibility with XHTML
01059         // as this function causes a lot of trouble with editor
01060         // we switch it off, even if this means that fields do not validate through xhtml
01061         // return $sValue;
01062 
01063         // we need to replace this for compatibility with XHTML
01064         $aReplace = array( chr(169) => "&copy;", chr(128) => "&euro;", "\"" => "&quot;", "'" => "&#039;");
01065 
01066         // #899C reverse html entities and references transformation is used in invoicepdf module
01067         // so this part must be enabled. Now it works with html references like &#123;
01068         if ($blReverse) {   // replace now
01069             $aTransTbl = get_html_translation_table (HTML_ENTITIES);
01070             $aTransTbl = array_flip ($aTransTbl) + array_flip ($aReplace);
01071             $sValue = strtr($sValue, $aTransTbl);
01072             $sValue = preg_replace('/\&\#([0-9]+)\;/me', "chr('\\1')", $sValue);
01073         }
01074 
01075         return $sValue;
01076     }
01077 
01083     public function getVats()
01084     {
01085         return $this->_aVATs;
01086     }
01087 
01093     public function getCurrency()
01094     {
01095         return $this->_oCur;
01096     }
01097 
01103     public function getSelectedLang()
01104     {
01105         return $this->_iSelectedLang;
01106     }
01107 
01113     public function getOrderArticles( $blStorno = false )
01114     {
01115         if ( $this->_oArticles == null ) {
01116             // order articles
01117             $this->_oArticles = oxNew( 'oxlist' );
01118             $this->_oArticles->init( 'oxorderarticle' );
01119 
01120             $sSelect = 'select oxorderarticles.* from oxorderarticles where oxorderarticles.oxorderid="'.$this->getId().'"';
01121             if ( $blStorno ) {
01122                 $sSelect.= ' and oxstorno = 0';
01123             }
01124             $sSelect.= ' order by oxorderarticles.oxartid';
01125             $this->_oArticles->selectString( $sSelect );
01126         }
01127 
01128         return $this->_oArticles;
01129     }
01130 }

Generated on Fri Dec 19 14:20:29 2008 for OXID eShop CE by  doxygen 1.5.5