myorder.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class PdfBlock
00007 {
00012     protected $_aCache = array();
00013 
00022     protected function _toCache( $sFunc, $aParams )
00023     {
00024         $oItem = new stdClass();
00025         $oItem->sFunc   = $sFunc;
00026         $oItem->aParams = $aParams;
00027         $this->_aCache[]  = $oItem;
00028     }
00029 
00037     public function run( $oPdf )
00038     {
00039         foreach ( $this->_aCache as $oItem ) {
00040             $sFn = $oItem->sFunc;
00041             switch ( count( $oItem->aParams ) ) {
00042                 case 0:
00043                     $oPdf->$sFn();
00044                     break;
00045                 case 1:
00046                     $oPdf->$sFn( $oItem->aParams[0]);
00047                     break;
00048                 case 2:
00049                     $oPdf->$sFn( $oItem->aParams[0], $oItem->aParams[1] );
00050                     break;
00051                 case 3:
00052                     $oPdf->$sFn( $oItem->aParams[0], $oItem->aParams[1], $oItem->aParams[2]);
00053                     break;
00054                 case 4:
00055                     $oPdf->$sFn( $oItem->aParams[0], $oItem->aParams[1], $oItem->aParams[2], $oItem->aParams[3]);
00056                     break;
00057             }
00058         }
00059     }
00060 
00071     public function line( $iLPos, $iLHeight, $iRPos, $iRHeight )
00072     {
00073         $this->_toCache( 'Line', array( $iLPos, $iLHeight, $iRPos, $iRHeight ) );
00074     }
00075 
00085     public function text( $iLPos, $iLHeight, $sString )
00086     {
00087         $this->_toCache( 'Text', array( $iLPos, $iLHeight, $sString ) );
00088     }
00089 
00099     public function font( $sType, $sWeight, $sSize )
00100     {
00101         $this->_toCache( 'SetFont', array( $sType, $sWeight, $sSize ) );
00102     }
00103 
00111     public function ajustHeight( $iDelta )
00112     {
00113         foreach ( $this->_aCache as $key => $oItem ) {
00114             switch ( $oItem->sFunc ) {
00115                 case 'Line':
00116                     $this->_aCache[$key]->aParams[3] += $iDelta;
00117                     $this->_aCache[$key]->aParams[1] += $iDelta;
00118                     break;
00119                 case 'Text':
00120                     $this->_aCache[$key]->aParams[1] += $iDelta;
00121                     break;
00122             }
00123         }
00124     }
00125 }
00126 
00130 class PdfArticleSummary extends PdfBlock
00131 {
00132 
00137     protected $_oData = null;
00138 
00143     protected $_oPdf = null;
00144 
00153     public function __construct( $oData, $oPdf )
00154     {
00155         $this->_oData = $oData;
00156         $this->_oPdf = $oPdf;
00157     }
00158 
00166     protected function _setTotalCostsWithoutDiscount( &$iStartPos )
00167     {
00168         $oLang = oxLang::getInstance();
00169 
00170         // products netto price
00171         $this->line( 15, $iStartPos + 1, 195, $iStartPos + 1 );
00172         $sNetSum = $oLang->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 = $oLang->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 = $oLang->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         $oLang = oxLang::getInstance();
00207 
00208         // line separator
00209         $this->line( 15, $iStartPos + 1, 195, $iStartPos + 1 );
00210 
00211         // products brutto price
00212         $sBrutPrice = $oLang->formatCurrency( $this->_oData->oxorder__oxtotalbrutsum->value, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00213         $this->text( 45, $iStartPos + 4, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_ALLPRICEBRUTTO' ) );
00214         $this->text( 195 - $this->_oPdf->getStringWidth( $sBrutPrice ), $iStartPos + 4, $sBrutPrice );
00215 
00216         // line separator
00217         $this->line( 45, $iStartPos + 5, 195, $iStartPos + 5 );
00218 
00219         // discount
00220         $dDiscountVal = $this->_oData->oxorder__oxdiscount->value;
00221         if ( $dDiscountVal > 0 ) {
00222             $dDiscountVal *= -1;
00223         }
00224         $sDiscount = $oLang->formatCurrency( $dDiscountVal, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00225         $this->text( 45, $iStartPos + 8, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_DISCOUNT' ) );
00226         $this->text( 195 - $this->_oPdf->getStringWidth( $sDiscount ), $iStartPos + 8, $sDiscount );
00227         $iStartPos++;
00228 
00229         // line separator
00230         $this->line( 45, $iStartPos + 8, 195, $iStartPos + 8 );
00231         $iStartPos += 4;
00232 
00233         // products netto price
00234         $sNetSum = $oLang->formatCurrency( $this->_oData->oxorder__oxtotalnetsum->value, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00235         $this->text( 45, $iStartPos + 8, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_ALLPRICENETTO' ) );
00236         $this->text( 195 - $this->_oPdf->getStringWidth( $sNetSum ), $iStartPos + 8, $sNetSum );
00237 
00238         // #345 - product VAT info
00239         $iCtr = 0;
00240         foreach ( $this->_oData->getVats() as $iVATPercent => $dVATValue ) {
00241             $iStartPos += 4 * $iCtr;
00242             $sVATSum = $oLang->formatCurrency( $dVATValue * $this->_oData->getCurrency()->rate, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00243             $this->text( 45, $iStartPos + 12, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_ZZGLVAT' ).$iVATPercent.$this->_oData->translate('ORDER_OVERVIEW_PDF_PERCENTSUM' ) );
00244             $this->text( 195 - $this->_oPdf->getStringWidth( $sVATSum ), $iStartPos + 12, $sVATSum );
00245             $iCtr++;
00246         }
00247         $iStartPos += 4;
00248     }
00249 
00257     protected function _setVoucherInfo( &$iStartPos )
00258     {
00259         $dVoucher = 0;
00260         if ( $this->_oData->oxorder__oxvoucherdiscount->value ) {
00261             $dDiscountVal = $this->_oData->oxorder__oxvoucherdiscount->value;
00262             if ( $dDiscountVal > 0 ) {
00263                 $dDiscountVal *= -1;
00264             }
00265             $sPayCost = oxLang::getInstance()->formatCurrency( $dDiscountVal, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00266             $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_VOUCHER' ) );
00267             $this->text( 195 - $this->_oPdf->getStringWidth( $sPayCost ), $iStartPos, $sPayCost );
00268             $iStartPos += 4;
00269         }
00270 
00271         $iStartPos++;
00272     }
00273 
00281     protected function _setDeliveryInfo( &$iStartPos )
00282     {
00283         $oLang = oxLang::getInstance();
00284         $sAddString = '';
00285         if ( $this->_oData->oxorder__oxdelvat->value ) {
00286 
00287             // delivery netto
00288             $sDelCostNetto = $oLang->formatCurrency( $this->_oData->getOrderDeliveryPrice()->getNettoPrice(), $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00289             $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_SHIPCOST' ).' '.$this->_oData->translate('ORDER_OVERVIEW_PDF_NETTO' ) );
00290             $this->text( 195 - $this->_oPdf->getStringWidth( $sDelCostNetto ), $iStartPos, $sDelCostNetto );
00291             $iStartPos += 4;
00292 
00293             // delivery VAT
00294             $sDelCostVAT = $oLang->formatCurrency( $this->_oData->getOrderDeliveryPrice()->getVATValue(), $this->_oData->getCurrency()).' '.$this->_oData->getCurrency()->name;
00295             $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_ZZGLVAT' ).$this->_oData->oxorder__oxdelvat->value.$this->_oData->translate( 'ORDER_OVERVIEW_PDF_PERCENTSUM' ) );
00296             $this->text( 195 - $this->_oPdf->getStringWidth( $sDelCostVAT ), $iStartPos, $sDelCostVAT );
00297             $iStartPos += 4;
00298 
00299             $sAddString = ' '.$this->_oData->translate( 'ORDER_OVERVIEW_PDF_BRUTTO' );
00300 
00301             // drawing line separator
00302             $this->line( 45, $iStartPos - 3, 195, $iStartPos - 3 );
00303             $iStartPos++;
00304         }
00305 
00306         // delivery costs
00307 
00308         // if canceled order, reset value
00309         if ( $this->_oData->oxorder__oxstorno->value ) {
00310             $this->_oData->oxorder__oxdelcost->setValue(0);
00311         }
00312 
00313         $sDelCost = $oLang->formatCurrency( $this->_oData->oxorder__oxdelcost->value, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00314         $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_SHIPCOST' ).$sAddString );
00315         $this->text( 195 - $this->_oPdf->getStringWidth( $sDelCost ), $iStartPos, $sDelCost );
00316     }
00317 
00325     protected function _setWrappingInfo( &$iStartPos )
00326     {
00327         if ( $this->_oData->oxorder__oxwrapcost->value ) {
00328             $sAddString = '';
00329             $oLang = oxLang::getInstance();
00330 
00331             //displaying wrapping VAT info
00332             if ( $this->_oData->oxorder__oxwrapvat->value ) {
00333 
00334                 // wrapping netto
00335                 $iStartPos += 5;
00336                 $sWrapCostNetto = $oLang->formatCurrency( $this->_oData->getOrderWrappingPrice()->getNettoPrice(), $this->_oData->getCurrency()).' '.$this->_oData->getCurrency()->name;
00337                 $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_WRAPPING' ).' '.$this->_oData->translate( 'ORDER_OVERVIEW_PDF_NETTO' ) );
00338                 $this->text( 195 - $this->_oPdf->getStringWidth( $sWrapCostNetto ), $iStartPos, $sWrapCostNetto );
00339 
00340                 //wrapping VAT
00341                 $iStartPos += 4;
00342                 $sWrapCostVAT = $oLang->formatCurrency( $this->_oData->getOrderWrappingPrice()->getVATValue(), $this->_oData->getCurrency()).' '.$this->_oData->getCurrency()->name;
00343                 $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_ZZGLVAT' ).$this->_oData->oxorder__oxwrapvat->value.$this->_oData->translate( 'ORDER_OVERVIEW_PDF_PERCENTSUM' ) );
00344                 $this->text( 195 - $this->_oPdf->getStringWidth( $sWrapCostVAT ), $iStartPos, $sWrapCostVAT );
00345 
00346                 $sAddString = ' '.$this->_oData->translate( 'ORDER_OVERVIEW_PDF_BRUTTO' );
00347 
00348                 // drawing line separator
00349                 $iStartPos += 4;
00350                 $this->line(45, $iStartPos - 3, 195, $iStartPos - 3);
00351             }
00352             $iStartPos += 4;
00353 
00354             // wrapping cost
00355             $sWrapCost = $oLang->formatCurrency( $this->_oData->oxorder__oxwrapcost->value, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00356             $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_WRAPPING' ).$sAddString );
00357             $this->text( 195 - $this->_oPdf->getStringWidth( $sWrapCost ), $iStartPos, $sWrapCost );
00358             $iStartPos++;
00359         }
00360     }
00361 
00369     protected function _setPaymentInfo( &$iStartPos )
00370     {
00371         $oLang = oxLang::getInstance();
00372         if ( $this->_oData->oxorder__oxpayvat->value ) {
00373 
00374             // payment netto
00375             $iStartPos += 4;
00376             $sPayCostNetto = $oLang->formatCurrency( $this->_oData->getOrderPaymentPrice()->getNettoPrice(), $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00377             $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_PAYMENTIMPACT' ).' '.$this->_oData->translate( 'ORDER_OVERVIEW_PDF_NETTO' ) );
00378             $this->text( 195 - $this->_oPdf->getStringWidth( $sPayCostNetto ), $iStartPos, $sPayCostNetto );
00379 
00380             // payment VAT
00381             $iStartPos += 4;
00382             $sPayCostVAT = $oLang->formatCurrency( $this->_oData->getOrderPaymentPrice()->getVATValue(), $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00383             $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_ZZGLVAT' ).$this->_oData->oxorder__oxpayvat->value.$this->_oData->translate( 'ORDER_OVERVIEW_PDF_PERCENTSUM' ) );
00384             $this->text( 195 - $this->_oPdf->getStringWidth( $sPayCostVAT ), $iStartPos, $sPayCostVAT );
00385 
00386         }
00387 
00388         // if canceled order, reset value
00389         if ( $this->_oData->oxorder__oxstorno->value ) {
00390             $this->_oData->oxorder__oxpaycost->setValue(0);
00391         }
00392 
00393         // payment costs
00394         $iStartPos += 4;
00395         $sPayCost = $oLang->formatCurrency( $this->_oData->oxorder__oxpaycost->value, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00396         $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_PAYMENTIMPACT' ) );
00397         $this->text( 195 - $this->_oPdf->getStringWidth( $sPayCost ), $iStartPos, $sPayCost );
00398 
00399         $iStartPos++;
00400     }
00401 
00409     protected function _setGrandTotalPriceInfo( &$iStartPos )
00410     {
00411         $oLang = oxLang::getInstance();
00412 
00413         // total netto price (A. very unprecise, impossible to count because of many factors)
00414         $this->font( 'Arial', 'B', 10 );
00415         if ( $this->_oData->oxorder__oxdelvat->value || $this->_oData->oxorder__oxwrapvat->value || $this->_oData->oxorder__oxpayvat->value ) {
00416 
00417             // collecting total net price
00418             $sTotalNetSum = $oLang->formatCurrency( $this->_oData->getOrderNetSum(), $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00419             $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_ALLSUM_NET' ) );
00420             $this->text( 195 - $this->_oPdf->getStringWidth( $sTotalNetSum ), $iStartPos, $sTotalNetSum );
00421             $iStartPos += 4;
00422         }
00423 
00424         // total order sum
00425         $sTotalOrderSum = $oLang->formatCurrency( $this->_oData->oxorder__oxtotalordersum->value, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00426         $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_ALLSUM' ) );
00427         $this->text( 195 - $this->_oPdf->getStringWidth( $sTotalOrderSum ), $iStartPos, $sTotalOrderSum );
00428         $iStartPos += 2;
00429     }
00430 
00438     protected function _setPaymentMethodInfo( &$iStartPos )
00439     {
00440         $oPayment = oxNew( 'oxpayment' );
00441         $oPayment->loadInLang( $this->_oData->getSelectedLang(), $this->_oData->oxorder__oxpaymenttype->value );
00442 
00443         $text = $this->_oData->translate( 'ORDER_OVERVIEW_PDF_SELPAYMENT' ).$oPayment->oxpayments__oxdesc->value;
00444         $this->font( 'Arial', '', 10 );
00445         $this->text( 15, $iStartPos + 4, $text );
00446         $iStartPos += 4;
00447     }
00448 
00456     protected function _setPayUntilInfo( &$iStartPos )
00457     {
00458         $text = $this->_oData->translate( 'ORDER_OVERVIEW_PDF_PAYUPTO' ).date( 'd.m.Y', mktime( 0, 0, 0, date ( 'm' ), date ( 'd' ) + 7, date( 'Y' ) ) );
00459         $this->font( 'Arial', '', 10 );
00460         $this->text( 15, $iStartPos + 4, $text );
00461         $iStartPos += 4;
00462     }
00463 
00471     public function generate( $iStartPos )
00472     {
00473 
00474         $this->font( 'Arial', '', 10 );
00475         $siteH = $iStartPos;
00476 
00477         // #1147 discount for vat must be displayed
00478         if ( !$this->_oData->oxorder__oxdiscount->value ) {
00479             $this->_setTotalCostsWithoutDiscount( $siteH );
00480         } else {
00481             $this->_setTotalCostsWithDiscount( $siteH );
00482         }
00483 
00484         $siteH += 12;
00485 
00486         // voucher info
00487         $this->_setVoucherInfo( $siteH );
00488 
00489         // additional line separator
00490         if ( $this->_oData->oxorder__oxdiscount->value || $this->_oData->oxorder__oxvoucherdiscount->value ) {
00491             $this->line( 45, $siteH - 3, 195, $siteH - 3 );
00492         }
00493 
00494         // delivery info
00495         $this->_setDeliveryInfo( $siteH );
00496 
00497         // wrapping info
00498         $this->_setWrappingInfo( $siteH );
00499 
00500         // payment info
00501         $this->_setPaymentInfo( $siteH );
00502 
00503         // separating line
00504         $this->line( 15, $siteH, 195, $siteH );
00505         $siteH += 4;
00506 
00507         // total order sum
00508         $this->_setGrandTotalPriceInfo( $siteH );
00509 
00510         // separating line
00511         $this->line( 15, $siteH, 195, $siteH );
00512         $siteH += 4;
00513 
00514         // payment method
00515         $this->_setPaymentMethodInfo( $siteH );
00516 
00517         // pay until ...
00518         $this->_setPayUntilInfo( $siteH );
00519 
00520         return $siteH - $iStartPos;
00521     }
00522 }
00523 
00527 class MyOrder extends MyOrder_parent
00528 {
00529 
00534     protected $_iSelectedLang = 0;
00535 
00540     protected $_oActShop = null;
00541 
00546     protected $_aVATs = array();
00547 
00552     protected $_oCur = null;
00553 
00559     protected function _getActShop()
00560     {
00561         // shop is allready loaded
00562         if ( $this->_oActShop !== null )
00563             return $this->_oActShop;
00564 
00565         $this->_oActShop = oxNew( 'oxshop' );
00566         $this->_oActShop->load( $this->getConfig()->getShopId() );
00567 
00568         return $this->_oActShop;
00569     }
00570 
00578     public function translate( $sString )
00579     {
00580         return oxLang::getInstance()->translateString( $sString, $this->_iSelectedLang );
00581     }
00582 
00590     public function pdfFooter( $oPdf )
00591     {
00592 
00593         $oShop = $this->_getActShop();
00594 
00595         $oPdf->line( 15, 272, 195, 272 );
00596 
00597         /* column 1 - company name, shop owner info, shop address */
00598         $oPdf->setFont( 'Arial', '', 7 );
00599         $oPdf->text( 15, 275, strip_tags( $oShop->oxshops__oxcompany->value ) );
00600         $oPdf->text( 15, 278, strip_tags( $oShop->oxshops__oxfname->value ).' '. strip_tags( $oShop->oxshops__oxlname->value ) );
00601         $oPdf->text( 15, 281, strip_tags( $oShop->oxshops__oxstreet->value ) );
00602         $oPdf->text( 15, 284, strip_tags( $oShop->oxshops__oxzip->value ).' '. strip_tags( $oShop->oxshops__oxcity->value ) );
00603         $oPdf->text( 15, 287, strip_tags( $oShop->oxshops__oxcountry->value ) );
00604 
00605         /* column 2 - phone, fax, url, email address */
00606         $oPdf->text( 85, 275, $this->translate( 'ORDER_OVERVIEW_PDF_PHONE' ).strip_tags( $oShop->oxshops__oxtelefon->value ) );
00607         $oPdf->text( 85, 278, $this->translate( 'ORDER_OVERVIEW_PDF_FAX' ).strip_tags( $oShop->oxshops__oxtelefax->value ) );
00608         $oPdf->text( 85, 281, strip_tags( $oShop->oxshops__oxurl->value ) );
00609         $oPdf->text( 85, 284, strip_tags( $oShop->oxshops__oxorderemail->value ) );
00610 
00611         /* column 3 - bank information */
00612         $oPdf->text( 150, 275, strip_tags( $oShop->oxshops__oxbankname->value ) );
00613         $oPdf->text( 150, 278, $this->translate( 'ORDER_OVERVIEW_PDF_ACCOUNTNR' ).strip_tags( $oShop->oxshops__oxbanknumber->value ) );
00614         $oPdf->text( 150, 281, $this->translate( 'ORDER_OVERVIEW_PDF_BANKCODE' ).strip_tags( $oShop->oxshops__oxbankcode->value ) );
00615         $oPdf->text( 150, 284, strip_tags( $oShop->oxshops__oxvatnumber->value ) );
00616         $oPdf->text( 150, 287, '' );
00617     }
00618 
00626     public function pdfHeaderPlus( $oPdf )
00627     {
00628 
00629         // new page with shop logo
00630         $this->pdfHeader( $oPdf );
00631 
00632         // column names
00633         $oPdf->setFont( 'Arial', '', 8 );
00634         $oPdf->text( 15, 50, $this->translate( 'ORDER_OVERVIEW_PDF_AMOUNT' ) );
00635         $oPdf->text( 30, 50, $this->translate( 'ORDER_OVERVIEW_PDF_ARTID') );
00636         $oPdf->text( 45, 50, $this->translate( 'ORDER_OVERVIEW_PDF_DESC' ) );
00637         $oPdf->text( 160, 50, $this->translate( 'ORDER_OVERVIEW_PDF_UNITPRICE' ) );
00638         $sText = $this->translate( 'ORDER_OVERVIEW_PDF_ALLPRICE' );
00639         $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), 50, $sText );
00640 
00641         // line separator
00642         $oPdf->line( 15, 52, 195, 52 );
00643 
00644         return 56;
00645     }
00646 
00654     public function pdfHeader( $oPdf )
00655     {
00656         // adding new page ...
00657         $oPdf->addPage();
00658 
00659         // loading active shop
00660         $oShop = $this->_getActShop();
00661 
00662         //logo
00663         $myConfig = $this->getConfig();
00664         $aSize    = getimagesize( $myConfig->getAbsImageDir().'/pdf_logo.jpg' );
00665         $iMargin  = 195 - $aSize[0] * 0.2;
00666         $oPdf->setLink( $oShop->oxshops__oxurl->value );
00667         $oPdf->image( $myConfig->getAbsImageDir().'/pdf_logo.jpg', $iMargin, 10, $aSize[0] * 0.2, $aSize[1] * 0.2, '', $oShop->oxshops__oxurl->value );
00668         return 14 + $aSize[1] * 0.2;
00669     }
00670 
00679     public function genPdf( $sFilename, $iSelLang = 0 )
00680     {
00681         // setting pdf language
00682         $this->_iSelectedLang = $iSelLang;
00683 
00684         // setting invoice number
00685         if ( !$this->oxorder__oxbillnr->value ) {
00686             $this->oxorder__oxbillnr->setValue($this->getNextBillNum());
00687             $this->save();
00688         }
00689 
00690         // initiating pdf engine
00691         $oPdf = oxNew( 'oxPDF' );
00692         $oPdf->setPrintHeader( false );
00693         $oPdf->open();
00694 
00695         // adding header
00696         $this->pdfHeader( $oPdf );
00697 
00698         // adding info data
00699         switch ( oxConfig::getParameter( 'pdftype' ) ) {
00700             case 'dnote':
00701                 $this->exportDeliveryNote( $oPdf );
00702                 break;
00703             default:
00704                 $this->exportStandart( $oPdf );
00705         }
00706 
00707         // adding footer
00708         $this->pdfFooter( $oPdf );
00709 
00710         // outputting file to browser
00711         $oPdf->output( $sFilename, 'I' );
00712     }
00713 
00714 
00722     protected function _setBillingAddressToPdf( $oPdf )
00723     {
00724         $oPdf->setFont( 'Arial', '', 10 );
00725         $oPdf->text( 15, 59, $this->oxorder__oxbillsal->value );
00726         $oPdf->text( 15, 63, $this->oxorder__oxbilllname->value.' '.$this->oxorder__oxbillfname->value );
00727         $oPdf->text( 15, 67, $this->oxorder__oxbillcompany->value );
00728         $oPdf->text( 15, 71, $this->oxorder__oxbillstreet->value.' '.$this->oxorder__oxbillstreetnr->value );
00729         $oPdf->setFont( 'Arial', 'B', 10 );
00730         $oPdf->text( 15, 75, $this->oxorder__oxbillzip->value.' '.$this->oxorder__oxbillcity->value );
00731         $oPdf->setFont( 'Arial', '', 10 );
00732         $oPdf->text( 15, 79, $this->oxorder__oxbillcountry->value );
00733     }
00734 
00742     protected function _setDeliveryAddressToPdf( $oPdf )
00743     {
00744         $oPdf->setFont( 'Arial', '', 6 );
00745         $oPdf->text( 15, 87, $this->translate( 'ORDER_OVERVIEW_PDF_DELIVERYADDRESS' ) );
00746         $oPdf->setFont( 'Arial', '', 10 );
00747         $oPdf->text( 15, 91, $this->oxorder__oxdelsal->value );
00748         $oPdf->text( 15, 95, $this->oxorder__oxdellname->value.' '.$this->oxorder__oxdelfname->value );
00749         $oPdf->text( 15, 99, $this->oxorder__oxdelcompany->value );
00750         $oPdf->text( 15, 103, $this->oxorder__oxdelstreet->value.' '.$this->oxorder__oxdelstreetnr->value );
00751         $oPdf->setFont( 'Arial', 'B', 10 );
00752         $oPdf->text( 15, 107, $this->oxorder__oxdelzip->value.' '.$this->oxorder__oxdelcity->value );
00753         $oPdf->setFont( 'Arial', '', 10 );
00754         $oPdf->text( 15, 111, $this->oxorder__oxdelcountry->value );
00755     }
00756 
00766     protected function _setOrderArticlesToPdf( $oPdf, &$iStartPos, $blShowPrice = true )
00767     {
00768         if (!$this->_oArticles) {
00769             $this->_oArticles = $this->getOrderArticles(true);
00770         }
00771 
00772         // product list
00773         foreach ( $this->_oArticles as $key => $oOrderArt ) {
00774 
00775             // starting a new page ...
00776             if ( $iStartPos > 243 ) {
00777                 $this->pdffooter( $oPdf );
00778                 $iStartPos = $this->pdfheaderplus( $oPdf );
00779                 $oPdf->setFont( 'Arial', '', 10 );
00780             } else {
00781                 $iStartPos = $iStartPos + 4;
00782             }
00783 
00784             // sold amount
00785             $oPdf->text( 20 - $oPdf->getStringWidth( $oOrderArt->oxorderarticles__oxamount->value ), $iStartPos, $oOrderArt->oxorderarticles__oxamount->value );
00786 
00787             // product number
00788             $oPdf->setFont( 'Arial', '', 8 );
00789             $oPdf->text( 28, $iStartPos, $oOrderArt->oxorderarticles__oxartnum->value );
00790 
00791             // product title
00792             $oPdf->setFont( 'Arial', '', 10 );
00793             $oPdf->text( 45, $iStartPos, substr( strip_tags( $this->_replaceExtendedChars( $oOrderArt->oxorderarticles__oxtitle->value, true ) ), 0, 58 ) );
00794 
00795             if ( $blShowPrice ) {
00796                 $oLang = oxLang::getInstance();
00797 
00798                 // product price
00799                 $sText = $oLang->formatCurrency( $oOrderArt->oxorderarticles__oxbprice->value, $this->_oCur ).' '.$this->_oCur->name;
00800                 $oPdf->text( 163 - $oPdf->getStringWidth( $sText ), $iStartPos, $sText );
00801 
00802                 // total product price
00803                 $sText = $oLang->formatCurrency( $oOrderArt->oxorderarticles__oxbrutprice->value, $this->_oCur ).' '.$this->_oCur->name;
00804                 $oPdf->text( 184 - $oPdf->getStringWidth( $sText ), $iStartPos, $sText );
00805 
00806                 // product VAT percent
00807                 $oPdf->text( 195 - $oPdf->getStringWidth( $oOrderArt->oxorderarticles__oxvat->value ), $iStartPos, $oOrderArt->oxorderarticles__oxvat->value );
00808 
00809                 // calculating product VAT info
00810                 if ( !isset( $this->_aVATs[$oOrderArt->oxorderarticles__oxvat->value] ) ) {
00811                     $this->_aVATs[$oOrderArt->oxorderarticles__oxvat->value] = 0;
00812                 }
00813                 $this->_aVATs[$oOrderArt->oxorderarticles__oxvat->value] += $oOrderArt->oxorderarticles__oxvatprice->value;
00814             }
00815 
00816             // additional variant info
00817             if ( $oOrderArt->oxorderarticles__oxselvariant->value ) {
00818                 $iStartPos = $iStartPos + 4;
00819                 $oPdf->text( 45, $iStartPos, substr( $oOrderArt->oxorderarticles__oxselvariant->value, 0, 58 ) );
00820             }
00821 
00822         }
00823     }
00824 
00832     public function exportStandart( $oPdf )
00833     {
00834         // preparing order curency info
00835         $myConfig = $this->getConfig();
00836 
00837         $this->_oCur = $myConfig->getCurrencyObject( $this->oxorder__oxcurrency->value );
00838         if ( !$this->_oCur ) {
00839             $this->_oCur = $myConfig->getActShopCurrencyObject();
00840         }
00841 
00842         // loading active shop
00843         $oShop = $this->_getActShop();
00844 
00845         // shop information
00846         $oPdf->setFont( 'Arial', '', 6 );
00847         $oPdf->text( 15, 55, $oShop->oxshops__oxname->value.' - '.$oShop->oxshops__oxstreet->value.' - '.$oShop->oxshops__oxzip->value.' - '.$oShop->oxshops__oxcity->value );
00848 
00849         // billing address
00850         $this->_setBillingAddressToPdf( $oPdf );
00851 
00852         // delivery address
00853         if ( $this->oxorder__oxdelsal->value ) {
00854             $this->_setDeliveryAddressToPdf( $oPdf );
00855         }
00856 
00857         // loading user
00858         $oUser = oxNew( 'oxuser' );
00859         $oUser->load( $this->oxorder__oxuserid->value );
00860 
00861         // user info
00862         $sText = $this->translate( 'ORDER_OVERVIEW_PDF_FILLONPAYMENT' );
00863         $oPdf->setFont( 'Arial', '', 5 );
00864         $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), 55, $sText );
00865 
00866         // customer number
00867         $sCustNr = $this->translate( 'ORDER_OVERVIEW_PDF_CUSTNR').' '.$oUser->oxuser__oxcustnr->value;
00868         $oPdf->setFont( 'Arial', '', 7 );
00869         $oPdf->text( 195 - $oPdf->getStringWidth( $sCustNr ), 59, $sCustNr );
00870 
00871         // setting position if delivery address is used
00872         if ( $this->oxorder__oxdelsal->value ) {
00873             $iTop = 115;
00874         } else {
00875             $iTop = 91;
00876         }
00877 
00878         // shop city
00879         $sText = $oShop->oxshops__oxcity->value.', '.date( 'd.m.Y' );
00880         $oPdf->setFont( 'Arial', '', 10 );
00881         $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), $iTop + 8, $sText );
00882 
00883         // shop VAT number
00884         if ( $oShop->oxshops__oxvatnumber->value ) {
00885             $sText = $this->translate( 'ORDER_OVERVIEW_PDF_TAXIDNR' ).' '.$oShop->oxshops__oxvatnumber->value;
00886             $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), $iTop + 12, $sText );
00887             $iTop += 8;
00888         } else {
00889             $iTop += 4;
00890         }
00891 
00892         // invoice number
00893         $sText = $this->translate( 'ORDER_OVERVIEW_PDF_COUNTNR' ).' '.$this->oxorder__oxbillnr->value;
00894         $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), $iTop + 8, $sText );
00895 
00896         // marking if order is canceled
00897         if ( $this->oxorder__oxstorno->value == 1 ) {
00898             $this->oxorder__oxordernr->setValue( $this->oxorder__oxordernr->getRawValue() . '   '.$this->translate( 'ORDER_OVERVIEW_PDF_STORNO' ), oxField::T_RAW );
00899         }
00900 
00901         // order number
00902         $oPdf->setFont( 'Arial', '', 12 );
00903         $oPdf->text( 15, $iTop, $this->translate( 'ORDER_OVERVIEW_PDF_PURCHASENR' ).' '.$this->oxorder__oxordernr->value );
00904 
00905         // order date
00906         $oPdf->setFont( 'Arial', '', 10 );
00907         $aOrderDate = explode( ' ', $this->oxorder__oxorderdate->value );
00908         $sOrderDate = oxUtilsDate::getInstance()->formatDBDate( $aOrderDate[0]);
00909         $oPdf->text( 15, $iTop + 8, $this->translate( 'ORDER_OVERVIEW_PDF_ORDERSFROM' ).$sOrderDate.$this->translate( 'ORDER_OVERVIEW_PDF_ORDERSAT' ).$oShop->oxshops__oxurl->value );
00910         $iTop += 16;
00911 
00912         // product info header
00913         $oPdf->setFont( 'Arial', '', 8 );
00914         $oPdf->text( 15, $iTop, $this->translate( 'ORDER_OVERVIEW_PDF_AMOUNT' ) );
00915         $oPdf->text( 30, $iTop, $this->translate( 'ORDER_OVERVIEW_PDF_ARTID' ) );
00916         $oPdf->text( 45, $iTop, $this->translate( 'ORDER_OVERVIEW_PDF_DESC' ) );
00917         $oPdf->text( 148, $iTop, $this->translate( 'ORDER_OVERVIEW_PDF_UNITPRICE' ) );
00918         $oPdf->text( 168, $iTop, $this->translate( 'ORDER_OVERVIEW_PDF_ALLPRICE' ) );
00919         $sText = $this->translate( 'ORDER_OVERVIEW_PDF_VAT' );
00920         $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), $iTop, $sText );
00921 
00922         // separator line
00923         $iTop += 2;
00924         $oPdf->line( 15, $iTop, 195, $iTop );
00925 
00926         // #345
00927         $siteH = $iTop;
00928         $oPdf->setFont( 'Arial', '', 10 );
00929 
00930         // order articles
00931         $this->_setOrderArticlesToPdf( $oPdf, $siteH, true );
00932 
00933         // generating pdf file
00934         $oArtSumm = new PdfArticleSummary( $this, $oPdf );
00935         $iHeight = $oArtSumm->generate( $siteH );
00936         if ( $siteH + $iHeight > 258 ) {
00937             $this->pdfFooter( $oPdf );
00938             $iTop = $this->pdfHeader( $oPdf );
00939             $oArtSumm->ajustHeight( $iTop - $siteH );
00940             $siteH = $iTop;
00941         }
00942 
00943         $oArtSumm->run( $oPdf );
00944         $siteH += $iHeight + 8;
00945 
00946         $oPdf->text( 15, $siteH, $this->translate( 'ORDER_OVERVIEW_PDF_GREETINGS' ) );
00947     }
00948 
00956     public function exportDeliveryNote( $oPdf )
00957     {
00958         $myConfig = $this->getConfig();
00959         $oShop    = $this->_getActShop();
00960 
00961         // loading order currency info
00962         $this->_oCur = $myConfig->getCurrencyObject( $this->oxorder__oxcurrency->value );
00963         if ( !isset( $this->_oCur ) ) {
00964             $this->_oCur = $myConfig->getActShopCurrencyObject();
00965         }
00966 
00967         // shop info
00968         $oPdf->setFont( 'Arial', '', 6 );
00969         $oPdf->text( 15, 55, $oShop->oxshops__oxname->value.' - '.$oShop->oxshops__oxstreet->value.' - '.$oShop->oxshops__oxzip->value.' - '.$oShop->oxshops__oxcity->value );
00970 
00971         // delivery address
00972         $oPdf->setFont( 'Arial', '', 10 );
00973         if ( $this->oxorder__oxdelsal->value ) {
00974             $oPdf->text( 15, 59, $this->oxorder__oxdelsal->value );
00975             $oPdf->text( 15, 63, $this->oxorder__oxdellname->value.' '.$this->oxorder__oxdelfname->value );
00976             $oPdf->text( 15, 67, $this->oxorder__oxdelcompany->value );
00977             $oPdf->text( 15, 71, $this->oxorder__oxdelstreet->value.' '.$this->oxorder__oxdelstreetnr->value );
00978             $oPdf->setFont( 'Arial', 'B', 10 );
00979             $oPdf->text( 15, 75, $this->oxorder__oxdelzip->value.' '.$this->oxorder__oxdelcity->value );
00980             $oPdf->setFont( 'Arial', '', 10 );
00981             $oPdf->text( 15, 79, $this->oxorder__oxdelcountry->value );
00982         } else { // no delivery address - billing address is used for delivery
00983             $this->_setBillingAddressToPdf( $oPdf );
00984         }
00985 
00986         // loading user info
00987         $oUser = oxNew( 'oxuser' );
00988         $oUser->load( $this->oxorder__oxuserid->value );
00989 
00990         // user info
00991         $sText = $this->translate( 'ORDER_OVERVIEW_PDF_FILLONPAYMENT' );
00992         $oPdf->setFont( 'Arial', '', 5 );
00993         $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), 70, $sText );
00994 
00995         // customer number
00996         $sCustNr = $this->translate( 'ORDER_OVERVIEW_PDF_CUSTNR' ).' '.$oUser->oxuser__oxcustnr->value;
00997         $oPdf->setFont( 'Arial', '', 7 );
00998         $oPdf->text( 195 - $oPdf->getStringWidth( $sCustNr ), 73, $sCustNr );
00999 
01000         // shops city
01001         $sText = $oShop->oxshops__oxcity->value.', '.date( 'd.m.Y' );
01002         $oPdf->setFont( 'Arial', '', 10 );
01003         $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), 95, $sText );
01004 
01005         $iTop = 99;
01006         // shop VAT number
01007         if ( $oShop->oxshops__oxvatnumber->value ) {
01008             $sText = $this->translate( 'ORDER_OVERVIEW_PDF_TAXIDNR' ).' '.$oShop->oxshops__oxvatnumber->value;
01009             $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), $iTop, $sText );
01010             $iTop += 4;
01011         }
01012 
01013         // invoice number
01014         $sText = $this->translate( 'ORDER_OVERVIEW_PDF_COUNTNR' ).' '.$this->oxorder__oxbillnr->value;
01015         $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), $iTop, $sText );
01016 
01017         // canceled order marker
01018         if ( $this->oxorder__oxstorno->value == 1 ) {
01019             $this->oxorder__oxordernr->setValue( $this->oxorder__oxordernr->getRawValue() . '   '.$this->translate( 'ORDER_OVERVIEW_PDF_STORNO' ), oxField::T_RAW );
01020         }
01021 
01022         // order number
01023         $oPdf->setFont( 'Arial', '', 12 );
01024         $oPdf->text( 15, 108, $this->translate( 'ORDER_OVERVIEW_PDF_DELIVNOTE' ).' '.$this->oxorder__oxordernr->value );
01025 
01026         // order date
01027         $aOrderDate = explode( ' ', $this->oxorder__oxorderdate->value );
01028         $sOrderDate = oxUtilsDate::getInstance()->formatDBDate( $aOrderDate[0]);
01029         $oPdf->setFont( 'Arial', '', 10 );
01030         $oPdf->text(15, 119, $this->translate( 'ORDER_OVERVIEW_PDF_ORDERSFROM' ).$sOrderDate.$this->translate( 'ORDER_OVERVIEW_PDF_ORDERSAT' ).$oShop->oxshops__oxurl->value );
01031 
01032         // product info header
01033         $oPdf->setFont( 'Arial', '', 8 );
01034         $oPdf->text( 15, 128, $this->translate( 'ORDER_OVERVIEW_PDF_AMOUNT' ) );
01035         $oPdf->text( 30, 128, $this->translate( 'ORDER_OVERVIEW_PDF_ARTID' ) );
01036         $oPdf->text( 45, 128, $this->translate( 'ORDER_OVERVIEW_PDF_DESC' ) );
01037 
01038         // line separator
01039         $oPdf->line( 15, 130, 195, 130 );
01040 
01041         // product list
01042         $oPdf->setFont( 'Arial', '', 10 );
01043         $siteH = 130;
01044 
01045         // order articles
01046         $this->_setOrderArticlesToPdf( $oPdf, $siteH, false );
01047 
01048         // sine separator
01049         $oPdf->line( 15, $siteH + 2, 195, $siteH + 2 );
01050         $siteH += 4;
01051 
01052         // payment date
01053         $oPdf->setFont( 'Arial', '', 10 );
01054         $text = $this->translate( 'ORDER_OVERVIEW_PDF_PAYUPTO' ).date( 'd.m.Y', mktime( 0, 0, 0, date ( 'm' ), date ( 'd' ) + 7, date( 'Y' ) ) );
01055         $oPdf->text( 15, $siteH + 4, $text );
01056     }
01057 
01067     protected function _replaceExtendedChars( $sValue, $blReverse = false )
01068     {
01069         // we need to replace this for compatibility with XHTML
01070         // as this function causes a lot of trouble with editor
01071         // we switch it off, even if this means that fields do not validate through xhtml
01072         // return $sValue;
01073 
01074         // we need to replace this for compatibility with XHTML
01075         $aReplace = array( chr(169) => "&copy;", chr(128) => "&euro;", "\"" => "&quot;", "'" => "&#039;");
01076 
01077         // #899C reverse html entities and references transformation is used in invoicepdf module
01078         // so this part must be enabled. Now it works with html references like &#123;
01079         if ($blReverse) {   // replace now
01080             $aTransTbl = get_html_translation_table (HTML_ENTITIES);
01081             $aTransTbl = array_flip ($aTransTbl) + array_flip ($aReplace);
01082             $sValue = strtr($sValue, $aTransTbl);
01083             $sValue = preg_replace('/\&\#([0-9]+)\;/me', "chr('\\1')", $sValue);
01084         }
01085 
01086         return $sValue;
01087     }
01088 
01094     public function getVats()
01095     {
01096         return $this->_aVATs;
01097     }
01098 
01104     public function getCurrency()
01105     {
01106         return $this->_oCur;
01107     }
01108 
01114     public function getSelectedLang()
01115     {
01116         return $this->_iSelectedLang;
01117     }
01118 
01124     public function getOrderArticles( $blStorno = false )
01125     {
01126         if ( $this->_oArticles == null ) {
01127             // order articles
01128             $this->_oArticles = oxNew( 'oxlist' );
01129             $this->_oArticles->init( 'oxorderarticle' );
01130 
01131             $sSelect = 'select oxorderarticles.* from oxorderarticles where oxorderarticles.oxorderid="'.$this->getId().'"';
01132             if ( $blStorno ) {
01133                 $sSelect.= ' and oxstorno = 0';
01134             }
01135             $sSelect.= ' order by oxorderarticles.oxartid';
01136             $this->_oArticles->selectString( $sSelect );
01137         }
01138 
01139         return $this->_oArticles;
01140     }
01141 }

Generated on Tue Sep 29 16:45:15 2009 for OXID eShop CE by  doxygen 1.5.5