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
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
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
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
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
00209 $this->line( 15, $iStartPos + 1, 195, $iStartPos + 1 );
00210
00211
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
00217 $this->line( 45, $iStartPos + 5, 195, $iStartPos + 5 );
00218
00219
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
00230 $this->line( 45, $iStartPos + 8, 195, $iStartPos + 8 );
00231 $iStartPos += 4;
00232
00233
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
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
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
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
00302 $this->line( 45, $iStartPos - 3, 195, $iStartPos - 3 );
00303 $iStartPos++;
00304 }
00305
00306
00307
00308
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
00332 if ( $this->_oData->oxorder__oxwrapvat->value ) {
00333
00334
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
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
00349 $iStartPos += 4;
00350 $this->line(45, $iStartPos - 3, 195, $iStartPos - 3);
00351 }
00352 $iStartPos += 4;
00353
00354
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
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
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
00389 if ( $this->_oData->oxorder__oxstorno->value ) {
00390 $this->_oData->oxorder__oxpaycost->setValue(0);
00391 }
00392
00393
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
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
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
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
00478 if ( !$this->_oData->oxorder__oxdiscount->value ) {
00479 $this->_setTotalCostsWithoutDiscount( $siteH );
00480 } else {
00481 $this->_setTotalCostsWithDiscount( $siteH );
00482 }
00483
00484 $siteH += 12;
00485
00486
00487 $this->_setVoucherInfo( $siteH );
00488
00489
00490 if ( $this->_oData->oxorder__oxdiscount->value || $this->_oData->oxorder__oxvoucherdiscount->value ) {
00491 $this->line( 45, $siteH - 3, 195, $siteH - 3 );
00492 }
00493
00494
00495 $this->_setDeliveryInfo( $siteH );
00496
00497
00498 $this->_setWrappingInfo( $siteH );
00499
00500
00501 $this->_setPaymentInfo( $siteH );
00502
00503
00504 $this->line( 15, $siteH, 195, $siteH );
00505 $siteH += 4;
00506
00507
00508 $this->_setGrandTotalPriceInfo( $siteH );
00509
00510
00511 $this->line( 15, $siteH, 195, $siteH );
00512 $siteH += 4;
00513
00514
00515 $this->_setPaymentMethodInfo( $siteH );
00516
00517
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
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
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
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
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
00630 $this->pdfHeader( $oPdf );
00631
00632
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
00642 $oPdf->line( 15, 52, 195, 52 );
00643
00644 return 56;
00645 }
00646
00654 public function pdfHeader( $oPdf )
00655 {
00656
00657 $oPdf->addPage();
00658
00659
00660 $oShop = $this->_getActShop();
00661
00662
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
00682 $this->_iSelectedLang = $iSelLang;
00683
00684
00685 if ( !$this->oxorder__oxbillnr->value ) {
00686 $this->oxorder__oxbillnr->setValue($this->getNextBillNum());
00687 $this->save();
00688 }
00689
00690
00691 $oPdf = oxNew( 'oxPDF' );
00692 $oPdf->open();
00693
00694
00695 $this->pdfHeader( $oPdf );
00696
00697
00698 switch ( oxConfig::getParameter( 'pdftype' ) ) {
00699 case 'dnote':
00700 $this->exportDeliveryNote( $oPdf );
00701 break;
00702 default:
00703 $this->exportStandart( $oPdf );
00704 }
00705
00706
00707 $this->pdfFooter( $oPdf );
00708
00709
00710 $oPdf->output( $sFilename, true );
00711 }
00712
00713
00721 protected function _setBillingAddressToPdf( $oPdf )
00722 {
00723 $oPdf->setFont( 'Arial', '', 10 );
00724 $oPdf->text( 15, 59, $this->oxorder__oxbillsal->value );
00725 $oPdf->text( 15, 63, $this->oxorder__oxbilllname->value.' '.$this->oxorder__oxbillfname->value );
00726 $oPdf->text( 15, 67, $this->oxorder__oxbillcompany->value );
00727 $oPdf->text( 15, 71, $this->oxorder__oxbillstreet->value.' '.$this->oxorder__oxbillstreetnr->value );
00728 $oPdf->setFont( 'Arial', 'B', 10 );
00729 $oPdf->text( 15, 75, $this->oxorder__oxbillzip->value.' '.$this->oxorder__oxbillcity->value );
00730 $oPdf->setFont( 'Arial', '', 10 );
00731 $oPdf->text( 15, 79, $this->oxorder__oxbillcountry->value );
00732 }
00733
00741 protected function _setDeliveryAddressToPdf( $oPdf )
00742 {
00743 $oPdf->setFont( 'Arial', '', 6 );
00744 $oPdf->text( 15, 87, $this->translate( 'ORDER_OVERVIEW_PDF_DELIVERYADDRESS' ) );
00745 $oPdf->setFont( 'Arial', '', 10 );
00746 $oPdf->text( 15, 91, $this->oxorder__oxdelsal->value );
00747 $oPdf->text( 15, 95, $this->oxorder__oxdellname->value.' '.$this->oxorder__oxdelfname->value );
00748 $oPdf->text( 15, 99, $this->oxorder__oxdelcompany->value );
00749 $oPdf->text( 15, 103, $this->oxorder__oxdelstreet->value.' '.$this->oxorder__oxdelstreetnr->value );
00750 $oPdf->setFont( 'Arial', 'B', 10 );
00751 $oPdf->text( 15, 107, $this->oxorder__oxdelzip->value.' '.$this->oxorder__oxdelcity->value );
00752 $oPdf->setFont( 'Arial', '', 10 );
00753 $oPdf->text( 15, 111, $this->oxorder__oxdelcountry->value );
00754 }
00755
00765 protected function _setOrderArticlesToPdf( $oPdf, &$iStartPos, $blShowPrice = true )
00766 {
00767 if (!$this->_oArticles) {
00768 $this->_oArticles = $this->getOrderArticles(true);
00769 }
00770
00771
00772 foreach ( $this->_oArticles as $key => $oOrderArt ) {
00773
00774
00775 if ( $iStartPos > 243 ) {
00776 $this->pdffooter( $oPdf );
00777 $iStartPos = $this->pdfheaderplus( $oPdf );
00778 $oPdf->setFont( 'Arial', '', 10 );
00779 } else {
00780 $iStartPos = $iStartPos + 4;
00781 }
00782
00783
00784 $oPdf->text( 20 - $oPdf->getStringWidth( $oOrderArt->oxorderarticles__oxamount->value ), $iStartPos, $oOrderArt->oxorderarticles__oxamount->value );
00785
00786
00787 $oPdf->setFont( 'Arial', '', 8 );
00788 $oPdf->text( 28, $iStartPos, $oOrderArt->oxorderarticles__oxartnum->value );
00789
00790
00791 $oPdf->setFont( 'Arial', '', 10 );
00792 $oPdf->text( 45, $iStartPos, substr( strip_tags( $this->_replaceExtendedChars( $oOrderArt->oxorderarticles__oxtitle->value, true ) ), 0, 58 ) );
00793
00794 if ( $blShowPrice ) {
00795 $oLang = oxLang::getInstance();
00796
00797
00798 $sText = $oLang->formatCurrency( $oOrderArt->oxorderarticles__oxbprice->value, $this->_oCur ).' '.$this->_oCur->name;
00799 $oPdf->text( 163 - $oPdf->getStringWidth( $sText ), $iStartPos, $sText );
00800
00801
00802 $sText = $oLang->formatCurrency( $oOrderArt->oxorderarticles__oxbrutprice->value, $this->_oCur ).' '.$this->_oCur->name;
00803 $oPdf->text( 184 - $oPdf->getStringWidth( $sText ), $iStartPos, $sText );
00804
00805
00806 $oPdf->text( 195 - $oPdf->getStringWidth( $oOrderArt->oxorderarticles__oxvat->value ), $iStartPos, $oOrderArt->oxorderarticles__oxvat->value );
00807
00808
00809 if ( !isset( $this->_aVATs[$oOrderArt->oxorderarticles__oxvat->value] ) ) {
00810 $this->_aVATs[$oOrderArt->oxorderarticles__oxvat->value] = 0;
00811 }
00812 $this->_aVATs[$oOrderArt->oxorderarticles__oxvat->value] += $oOrderArt->oxorderarticles__oxvatprice->value;
00813 }
00814
00815
00816 if ( $oOrderArt->oxorderarticles__oxselvariant->value ) {
00817 $iStartPos = $iStartPos + 4;
00818 $oPdf->text( 45, $iStartPos, substr( $oOrderArt->oxorderarticles__oxselvariant->value, 0, 58 ) );
00819 }
00820
00821 }
00822 }
00823
00831 public function exportStandart( $oPdf )
00832 {
00833
00834 $myConfig = $this->getConfig();
00835
00836 $this->_oCur = $myConfig->getCurrencyObject( $this->oxorder__oxcurrency->value );
00837 if ( !$this->_oCur ) {
00838 $this->_oCur = $myConfig->getActShopCurrencyObject();
00839 }
00840
00841
00842 $oShop = $this->_getActShop();
00843
00844
00845 $oPdf->setFont( 'Arial', '', 6 );
00846 $oPdf->text( 15, 55, $oShop->oxshops__oxname->value.' - '.$oShop->oxshops__oxstreet->value.' - '.$oShop->oxshops__oxzip->value.' - '.$oShop->oxshops__oxcity->value );
00847
00848
00849 $this->_setBillingAddressToPdf( $oPdf );
00850
00851
00852 if ( $this->oxorder__oxdelsal->value ) {
00853 $this->_setDeliveryAddressToPdf( $oPdf );
00854 }
00855
00856
00857 $oUser = oxNew( 'oxuser' );
00858 $oUser->load( $this->oxorder__oxuserid->value );
00859
00860
00861 $sText = $this->translate( 'ORDER_OVERVIEW_PDF_FILLONPAYMENT' );
00862 $oPdf->setFont( 'Arial', '', 5 );
00863 $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), 55, $sText );
00864
00865
00866 $sCustNr = $this->translate( 'ORDER_OVERVIEW_PDF_CUSTNR').' '.$oUser->oxuser__oxcustnr->value;
00867 $oPdf->setFont( 'Arial', '', 7 );
00868 $oPdf->text( 195 - $oPdf->getStringWidth( $sCustNr ), 59, $sCustNr );
00869
00870
00871 if ( $this->oxorder__oxdelsal->value ) {
00872 $iTop = 115;
00873 } else {
00874 $iTop = 91;
00875 }
00876
00877
00878 $sText = $oShop->oxshops__oxcity->value.', '.date( 'd.m.Y' );
00879 $oPdf->setFont( 'Arial', '', 10 );
00880 $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), $iTop + 8, $sText );
00881
00882
00883 if ( $oShop->oxshops__oxvatnumber->value ) {
00884 $sText = $this->translate( 'ORDER_OVERVIEW_PDF_TAXIDNR' ).' '.$oShop->oxshops__oxvatnumber->value;
00885 $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), $iTop + 12, $sText );
00886 $iTop += 8;
00887 }
00888
00889
00890 $sText = $this->translate( 'ORDER_OVERVIEW_PDF_COUNTNR' ).' '.$this->oxorder__oxbillnr->value;
00891 $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), $iTop + 8, $sText );
00892
00893
00894 if ( $this->oxorder__oxstorno->value == 1 ) {
00895 $this->oxorder__oxordernr->setValue( $this->oxorder__oxordernr->getRawValue() . ' '.$this->translate( 'ORDER_OVERVIEW_PDF_STORNO' ), oxField::T_RAW );
00896 }
00897
00898
00899 $oPdf->setFont( 'Arial', '', 12 );
00900 $oPdf->text( 15, $iTop, $this->translate( 'ORDER_OVERVIEW_PDF_PURCHASENR' ).' '.$this->oxorder__oxordernr->value );
00901
00902
00903 $oPdf->setFont( 'Arial', '', 10 );
00904 $aOrderDate = explode( ' ', $this->oxorder__oxorderdate->value );
00905 $sOrderDate = oxUtilsDate::getInstance()->formatDBDate( $aOrderDate[0]);
00906 $oPdf->text( 15, $iTop + 8, $this->translate( 'ORDER_OVERVIEW_PDF_ORDERSFROM' ).$sOrderDate.$this->translate( 'ORDER_OVERVIEW_PDF_ORDERSAT' ).$oShop->oxshops__oxurl->value );
00907 $iTop += 16;
00908
00909
00910 $oPdf->setFont( 'Arial', '', 8 );
00911 $oPdf->text( 15, $iTop, $this->translate( 'ORDER_OVERVIEW_PDF_AMOUNT' ) );
00912 $oPdf->text( 30, $iTop, $this->translate( 'ORDER_OVERVIEW_PDF_ARTID' ) );
00913 $oPdf->text( 45, $iTop, $this->translate( 'ORDER_OVERVIEW_PDF_DESC' ) );
00914 $oPdf->text( 148, $iTop, $this->translate( 'ORDER_OVERVIEW_PDF_UNITPRICE' ) );
00915 $oPdf->text( 168, $iTop, $this->translate( 'ORDER_OVERVIEW_PDF_ALLPRICE' ) );
00916 $sText = $this->translate( 'ORDER_OVERVIEW_PDF_VAT' );
00917 $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), $iTop, $sText );
00918
00919
00920 $iTop += 2;
00921 $oPdf->line( 15, $iTop, 195, $iTop );
00922
00923
00924 $siteH = $iTop;
00925 $oPdf->setFont( 'Arial', '', 10 );
00926
00927
00928 $this->_setOrderArticlesToPdf( $oPdf, $siteH, true );
00929
00930
00931 $oArtSumm = new PdfArticleSummary( $this, $oPdf );
00932 $iHeight = $oArtSumm->generate( $siteH );
00933 if ( $siteH + $iHeight > 258 ) {
00934 $this->pdfFooter( $oPdf );
00935 $iTop = $this->pdfHeader( $oPdf );
00936 $oArtSumm->ajustHeight( $iTop - $siteH );
00937 $siteH = $iTop;
00938 }
00939
00940 $oArtSumm->run( $oPdf );
00941 $siteH += $iHeight + 8;
00942
00943 $oPdf->text( 15, $siteH, $this->translate( 'ORDER_OVERVIEW_PDF_GREETINGS' ) );
00944 }
00945
00953 public function exportDeliveryNote( $oPdf )
00954 {
00955 $myConfig = $this->getConfig();
00956 $oShop = $this->_getActShop();
00957
00958
00959 $this->_oCur = $myConfig->getCurrencyObject( $this->oxorder__oxcurrency->value );
00960 if ( !isset( $this->_oCur ) ) {
00961 $this->_oCur = $myConfig->getActShopCurrencyObject();
00962 }
00963
00964
00965 $oPdf->setFont( 'Arial', '', 6 );
00966 $oPdf->text( 15, 55, $oShop->oxshops__oxname->value.' - '.$oShop->oxshops__oxstreet->value.' - '.$oShop->oxshops__oxzip->value.' - '.$oShop->oxshops__oxcity->value );
00967
00968
00969 $oPdf->setFont( 'Arial', '', 10 );
00970 if ( $this->oxorder__oxdelsal->value ) {
00971 $oPdf->text( 15, 59, $this->oxorder__oxdelsal->value );
00972 $oPdf->text( 15, 63, $this->oxorder__oxdellname->value.' '.$this->oxorder__oxdelfname->value );
00973 $oPdf->text( 15, 67, $this->oxorder__oxdelcompany->value );
00974 $oPdf->text( 15, 71, $this->oxorder__oxdelstreet->value.' '.$this->oxorder__oxdelstreetnr->value );
00975 $oPdf->setFont( 'Arial', 'B', 10 );
00976 $oPdf->text( 15, 75, $this->oxorder__oxdelzip->value.' '.$this->oxorder__oxdelcity->value );
00977 $oPdf->setFont( 'Arial', '', 10 );
00978 $oPdf->text( 15, 79, $this->oxorder__oxdelcountry->value );
00979 } else {
00980 $this->_setBillingAddressToPdf( $oPdf );
00981 }
00982
00983
00984 $oUser = oxNew( 'oxuser' );
00985 $oUser->load( $this->oxorder__oxuserid->value );
00986
00987
00988 $sText = $this->translate( 'ORDER_OVERVIEW_PDF_FILLONPAYMENT' );
00989 $oPdf->setFont( 'Arial', '', 5 );
00990 $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), 70, $sText );
00991
00992
00993 $sCustNr = $this->translate( 'ORDER_OVERVIEW_PDF_CUSTNR' ).' '.$oUser->oxuser__oxcustnr->value;
00994 $oPdf->setFont( 'Arial', '', 7 );
00995 $oPdf->text( 195 - $oPdf->getStringWidth( $sCustNr ), 73, $sCustNr );
00996
00997
00998 $sText = $oShop->oxshops__oxcity->value.', '.date( 'd.m.Y' );
00999 $oPdf->setFont( 'Arial', '', 10 );
01000 $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), 95, $sText );
01001
01002 $iTop = 99;
01003
01004 if ( $oShop->oxshops__oxvatnumber->value ) {
01005 $sText = $this->translate( 'ORDER_OVERVIEW_PDF_TAXIDNR' ).' '.$oShop->oxshops__oxvatnumber->value;
01006 $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), $iTop, $sText );
01007 $iTop += 4;
01008 }
01009
01010
01011 $sText = $this->translate( 'ORDER_OVERVIEW_PDF_COUNTNR' ).' '.$this->oxorder__oxbillnr->value;
01012 $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), $iTop, $sText );
01013
01014
01015 if ( $this->oxorder__oxstorno->value == 1 ) {
01016 $this->oxorder__oxordernr->setValue( $this->oxorder__oxordernr->getRawValue() . ' '.$this->translate( 'ORDER_OVERVIEW_PDF_STORNO' ), oxField::T_RAW );
01017 }
01018
01019
01020 $oPdf->setFont( 'Arial', '', 12 );
01021 $oPdf->text( 15, 108, $this->translate( 'ORDER_OVERVIEW_PDF_DELIVNOTE' ).' '.$this->oxorder__oxordernr->value );
01022
01023
01024 $aOrderDate = explode( ' ', $this->oxorder__oxorderdate->value );
01025 $sOrderDate = oxUtilsDate::getInstance()->formatDBDate( $aOrderDate[0]);
01026 $oPdf->setFont( 'Arial', '', 10 );
01027 $oPdf->text(15, 119, $this->translate( 'ORDER_OVERVIEW_PDF_ORDERSFROM' ).$sOrderDate.$this->translate( 'ORDER_OVERVIEW_PDF_ORDERSAT' ).$oShop->oxshops__oxurl->value );
01028
01029
01030 $oPdf->setFont( 'Arial', '', 8 );
01031 $oPdf->text( 15, 128, $this->translate( 'ORDER_OVERVIEW_PDF_AMOUNT' ) );
01032 $oPdf->text( 30, 128, $this->translate( 'ORDER_OVERVIEW_PDF_ARTID' ) );
01033 $oPdf->text( 45, 128, $this->translate( 'ORDER_OVERVIEW_PDF_DESC' ) );
01034
01035
01036 $oPdf->line( 15, 130, 195, 130 );
01037
01038
01039 $oPdf->setFont( 'Arial', '', 10 );
01040 $siteH = 130;
01041
01042
01043 $this->_setOrderArticlesToPdf( $oPdf, $siteH, false );
01044
01045
01046 $oPdf->line( 15, $siteH + 2, 195, $siteH + 2 );
01047 $siteH += 4;
01048
01049
01050 $oPdf->setFont( 'Arial', '', 10 );
01051 $text = $this->translate( 'ORDER_OVERVIEW_PDF_PAYUPTO' ).date( 'd.m.Y', mktime( 0, 0, 0, date ( 'm' ), date ( 'd' ) + 7, date( 'Y' ) ) );
01052 $oPdf->text( 15, $siteH + 4, $text );
01053 }
01054
01064 protected function _replaceExtendedChars( $sValue, $blReverse = false )
01065 {
01066
01067
01068
01069
01070
01071
01072 $aReplace = array( chr(169) => "©", chr(128) => "€", "\"" => """, "'" => "'");
01073
01074
01075
01076 if ($blReverse) {
01077 $aTransTbl = get_html_translation_table (HTML_ENTITIES);
01078 $aTransTbl = array_flip ($aTransTbl) + array_flip ($aReplace);
01079 $sValue = strtr($sValue, $aTransTbl);
01080 $sValue = preg_replace('/\&\#([0-9]+)\;/me', "chr('\\1')", $sValue);
01081 }
01082
01083 return $sValue;
01084 }
01085
01091 public function getVats()
01092 {
01093 return $this->_aVATs;
01094 }
01095
01101 public function getCurrency()
01102 {
01103 return $this->_oCur;
01104 }
01105
01111 public function getSelectedLang()
01112 {
01113 return $this->_iSelectedLang;
01114 }
01115
01121 public function getOrderArticles( $blStorno = false )
01122 {
01123 if ( $this->_oArticles == null ) {
01124
01125 $this->_oArticles = oxNew( 'oxlist' );
01126 $this->_oArticles->init( 'oxorderarticle' );
01127
01128 $sSelect = 'select oxorderarticles.* from oxorderarticles where oxorderarticles.oxorderid="'.$this->getId().'"';
01129 if ( $blStorno ) {
01130 $sSelect.= ' and oxstorno = 0';
01131 }
01132 $sSelect.= ' order by oxorderarticles.oxartid';
01133 $this->_oArticles->selectString( $sSelect );
01134 }
01135
01136 return $this->_oArticles;
01137 }
01138 }