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
00169 $this->line( 15, $iStartPos + 1, 195, $iStartPos + 1 );
00170 $sNetSum = oxLang::getInstance()->formatCurrency( $this->_oData->oxorder__oxtotalnetsum->value, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00171 $this->text( 45, $iStartPos + 4, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_ALLPRICENETTO' ) );
00172 $this->text( 195 - $this->_oPdf->getStringWidth( $sNetSum ), $iStartPos + 4, $sNetSum );
00173
00174
00175 $iCtr = 0;
00176 foreach ( $this->_oData->getVats() as $iVATPercent => $dVATValue ) {
00177 $iStartPos += 4 * $iCtr;
00178 $sVATSum = oxLang::getInstance()->formatCurrency( $dVATValue * $this->_oData->getCurrency()->rate, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00179 $this->text( 45, $iStartPos + 8, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_ZZGLVAT' ).$iVATPercent.$this->_oData->translate( 'ORDER_OVERVIEW_PDF_PERCENTSUM' ) );
00180 $this->text( 195 - $this->_oPdf->getStringWidth( $sVATSum ), $iStartPos + 8, $sVATSum );
00181 $iCtr++;
00182 }
00183
00184
00185 $sBrutPrice = oxLang::getInstance()->formatCurrency( $this->_oData->oxorder__oxtotalbrutsum->value, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00186 $this->text( 45, $iStartPos + 12, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_ALLPRICEBRUTTO' ) );
00187 $this->text( 195 - $this->_oPdf->getStringWidth( $sBrutPrice ), $iStartPos + 12, $sBrutPrice );
00188 $iStartPos++;
00189
00190
00191 $this->line( 45, $iStartPos + 13, 195, $iStartPos + 13 );
00192 $iStartPos += 5;
00193 }
00194
00202 protected function _setTotalCostsWithDiscount( &$iStartPos )
00203 {
00204
00205 $this->line( 15, $iStartPos + 1, 195, $iStartPos + 1 );
00206
00207
00208 $sBrutPrice = oxLang::getInstance()->formatCurrency( $this->_oData->oxorder__oxtotalbrutsum->value, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00209 $this->text( 45, $iStartPos + 4, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_ALLPRICEBRUTTO' ) );
00210 $this->text( 195 - $this->_oPdf->getStringWidth( $sBrutPrice ), $iStartPos + 4, $sBrutPrice );
00211
00212
00213 $this->line( 45, $iStartPos + 5, 195, $iStartPos + 5 );
00214
00215
00216 $dDiscountVal = $this->_oData->oxorder__oxdiscount->value;
00217 if ( $dDiscountVal > 0 ) {
00218 $dDiscountVal *= -1;
00219 }
00220 $sDiscount = oxLang::getInstance()->formatCurrency( $dDiscountVal, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00221 $this->text( 45, $iStartPos + 8, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_DISCOUNT' ) );
00222 $this->text( 195 - $this->_oPdf->getStringWidth( $sDiscount ), $iStartPos + 8, $sDiscount );
00223 $iStartPos++;
00224
00225
00226 $this->line( 45, $iStartPos + 8, 195, $iStartPos + 8 );
00227 $iStartPos += 4;
00228
00229
00230 $sNetSum = oxLang::getInstance()->formatCurrency( $this->_oData->oxorder__oxtotalnetsum->value, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00231 $this->text( 45, $iStartPos + 8, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_ALLPRICENETTO' ) );
00232 $this->text( 195 - $this->_oPdf->getStringWidth( $sNetSum ), $iStartPos + 8, $sNetSum );
00233
00234
00235 $iCtr = 0;
00236 foreach ( $this->_oData->getVats() as $iVATPercent => $dVATValue ) {
00237 $iStartPos += 4 * $iCtr;
00238 $sVATSum = oxLang::getInstance()->formatCurrency( $dVATValue * $this->_oData->getCurrency()->rate, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00239 $this->text( 45, $iStartPos + 12, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_ZZGLVAT' ).$iVATPercent.$this->_oData->translate('ORDER_OVERVIEW_PDF_PERCENTSUM' ) );
00240 $this->text( 195 - $this->_oPdf->getStringWidth( $sVATSum ), $iStartPos + 12, $sVATSum );
00241 $iCtr++;
00242 }
00243 $iStartPos += 4;
00244 }
00245
00253 protected function _setVoucherInfo( &$iStartPos )
00254 {
00255 $dVoucher = 0;
00256 if ( $this->_oData->oxorder__oxvoucherdiscount->value ) {
00257 $dDiscountVal = $this->_oData->oxorder__oxvoucherdiscount->value;
00258 if ( $dDiscountVal > 0 ) {
00259 $dDiscountVal *= -1;
00260 }
00261 $sPayCost = oxLang::getInstance()->formatCurrency( $dDiscountVal, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00262 $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_VOUCHER' ) );
00263 $this->text( 195 - $this->_oPdf->getStringWidth( $sPayCost ), $iStartPos, $sPayCost );
00264 $iStartPos += 4;
00265 }
00266
00267 $iStartPos++;
00268 }
00269
00277 protected function _setDeliveryInfo( &$iStartPos )
00278 {
00279 $sAddString = '';
00280 if ( $this->_oData->oxorder__oxdelvat->value ) {
00281
00282
00283 $sDelCostNetto = oxLang::getInstance()->formatCurrency( $this->_oData->getOrderDeliveryPrice()->getNettoPrice(), $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00284 $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_SHIPCOST' ).' '.$this->_oData->translate('ORDER_OVERVIEW_PDF_NETTO' ) );
00285 $this->text( 195 - $this->_oPdf->getStringWidth( $sDelCostNetto ), $iStartPos, $sDelCostNetto );
00286 $iStartPos += 4;
00287
00288
00289 $sDelCostVAT = oxLang::getInstance()->formatCurrency( $this->_oData->getOrderDeliveryPrice()->getVATValue(), $this->_oData->getCurrency()).' '.$this->_oData->getCurrency()->name;
00290 $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_ZZGLVAT' ).$this->_oData->oxorder__oxdelvat->value.$this->_oData->translate( 'ORDER_OVERVIEW_PDF_PERCENTSUM' ) );
00291 $this->text( 195 - $this->_oPdf->getStringWidth( $sDelCostVAT ), $iStartPos, $sDelCostVAT );
00292 $iStartPos += 4;
00293
00294 $sAddString = ' '.$this->_oData->translate( 'ORDER_OVERVIEW_PDF_BRUTTO' );
00295
00296
00297 $this->line( 45, $iStartPos - 3, 195, $iStartPos - 3 );
00298 $iStartPos++;
00299 }
00300
00301
00302
00303
00304 if ( $this->_oData->oxorder__oxstorno->value ) {
00305 $this->_oData->oxorder__oxdelcost->setValue(0);
00306 }
00307
00308 $sDelCost = oxLang::getInstance()->formatCurrency( $this->_oData->oxorder__oxdelcost->value, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00309 $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_SHIPCOST' ).$sAddString );
00310 $this->text( 195 - $this->_oPdf->getStringWidth( $sDelCost ), $iStartPos, $sDelCost );
00311 }
00312
00320 protected function _setWrappingInfo( &$iStartPos )
00321 {
00322 if ( $this->_oData->oxorder__oxwrapcost->value ) {
00323 $sAddString = '';
00324
00325
00326 if ( $this->_oData->oxorder__oxwrapvat->value ) {
00327
00328
00329 $iStartPos += 5;
00330 $sWrapCostNetto = oxLang::getInstance()->formatCurrency( $this->_oData->getOrderWrappingPrice()->getNettoPrice(), $this->_oData->getCurrency()).' '.$this->_oData->getCurrency()->name;
00331 $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_WRAPPING' ).' '.$this->_oData->translate( 'ORDER_OVERVIEW_PDF_NETTO' ) );
00332 $this->text( 195 - $this->_oPdf->getStringWidth( $sWrapCostNetto ), $iStartPos, $sWrapCostNetto );
00333
00334
00335 $iStartPos += 4;
00336 $sWrapCostVAT = oxLang::getInstance()->formatCurrency( $this->_oData->getOrderWrappingPrice()->getVATValue(), $this->_oData->getCurrency()).' '.$this->_oData->getCurrency()->name;
00337 $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_ZZGLVAT' ).$this->_oData->oxorder__oxwrapvat->value.$this->_oData->translate( 'ORDER_OVERVIEW_PDF_PERCENTSUM' ) );
00338 $this->text( 195 - $this->_oPdf->getStringWidth( $sWrapCostVAT ), $iStartPos, $sWrapCostVAT );
00339
00340 $sAddString = ' '.$this->_oData->translate( 'ORDER_OVERVIEW_PDF_BRUTTO' );
00341
00342
00343 $iStartPos += 4;
00344 $this->line(45, $iStartPos - 3, 195, $iStartPos - 3);
00345 }
00346 $iStartPos += 4;
00347
00348
00349 $sWrapCost = oxLang::getInstance()->formatCurrency( $this->_oData->oxorder__oxwrapcost->value, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00350 $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_WRAPPING' ).$sAddString );
00351 $this->text( 195 - $this->_oPdf->getStringWidth( $sWrapCost ), $iStartPos, $sWrapCost );
00352 $iStartPos++;
00353 }
00354 }
00355
00363 protected function _setPaymentInfo( &$iStartPos )
00364 {
00365 if ( $this->_oData->oxorder__oxpayvat->value ) {
00366
00367
00368 $iStartPos += 4;
00369 $sPayCostNetto = oxLang::getInstance()->formatCurrency( $this->_oData->getOrderPaymentPrice()->getNettoPrice(), $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00370 $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_PAYMENTIMPACT' ).' '.$this->_oData->translate( 'ORDER_OVERVIEW_PDF_NETTO' ) );
00371 $this->text( 195 - $this->_oPdf->getStringWidth( $sPayCostNetto ), $iStartPos, $sPayCostNetto );
00372
00373
00374 $iStartPos += 4;
00375 $sPayCostVAT = oxLang::getInstance()->formatCurrency( $this->_oData->getOrderPaymentPrice()->getVATValue(), $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00376 $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_ZZGLVAT' ).$this->_oData->oxorder__oxpayvat->value.$this->_oData->translate( 'ORDER_OVERVIEW_PDF_PERCENTSUM' ) );
00377 $this->text( 195 - $this->_oPdf->getStringWidth( $sPayCostVAT ), $iStartPos, $sPayCostVAT );
00378
00379 }
00380
00381
00382 if ( $this->_oData->oxorder__oxstorno->value ) {
00383 $this->_oData->oxorder__oxpaycost->setValue(0);
00384 }
00385
00386
00387 $iStartPos += 4;
00388 $sPayCost = oxLang::getInstance()->formatCurrency( $this->_oData->oxorder__oxpaycost->value, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00389 $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_PAYMENTIMPACT' ) );
00390 $this->text( 195 - $this->_oPdf->getStringWidth( $sPayCost ), $iStartPos, $sPayCost );
00391
00392 $iStartPos++;
00393 }
00394
00402 protected function _setGrandTotalPriceInfo( &$iStartPos )
00403 {
00404
00405 $this->font( 'Arial', 'B', 10 );
00406 if ( $this->_oData->oxorder__oxdelvat->value || $this->_oData->oxorder__oxwrapvat->value || $this->_oData->oxorder__oxpayvat->value ) {
00407
00408
00409 $sTotalNetSum = oxLang::getInstance()->formatCurrency( $this->_oData->getOrderNetSum(), $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00410 $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_ALLSUM_NET' ) );
00411 $this->text( 195 - $this->_oPdf->getStringWidth( $sTotalNetSum ), $iStartPos, $sTotalNetSum );
00412 $iStartPos += 4;
00413 }
00414
00415
00416 $sTotalOrderSum = oxLang::getInstance()->formatCurrency( $this->_oData->oxorder__oxtotalordersum->value, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00417 $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_ALLSUM' ) );
00418 $this->text( 195 - $this->_oPdf->getStringWidth( $sTotalOrderSum ), $iStartPos, $sTotalOrderSum );
00419 $iStartPos += 2;
00420 }
00421
00429 protected function _setPaymentMethodInfo( &$iStartPos )
00430 {
00431 $oPayment = oxNew( 'oxpayment' );
00432 $oPayment->loadInLang( $this->_oData->getSelectedLang(), $this->_oData->oxorder__oxpaymenttype->value );
00433
00434 $text = $this->_oData->translate( 'ORDER_OVERVIEW_PDF_SELPAYMENT' ).$oPayment->oxpayments__oxdesc->value;
00435 $this->font( 'Arial', '', 10 );
00436 $this->text( 15, $iStartPos + 4, $text );
00437 $iStartPos += 4;
00438 }
00439
00447 protected function _setPayUntilInfo( &$iStartPos )
00448 {
00449 $text = $this->_oData->translate( 'ORDER_OVERVIEW_PDF_PAYUPTO' ).date( 'd.m.Y', mktime( 0, 0, 0, date ( 'm' ), date ( 'd' ) + 7, date( 'Y' ) ) );
00450 $this->font( 'Arial', '', 10 );
00451 $this->text( 15, $iStartPos + 4, $text );
00452 $iStartPos += 4;
00453 }
00454
00462 public function generate( $iStartPos )
00463 {
00464
00465 $this->font( 'Arial', '', 10 );
00466 $siteH = $iStartPos;
00467
00468
00469 if ( !$this->_oData->oxorder__oxdiscount->value ) {
00470 $this->_setTotalCostsWithoutDiscount( $siteH );
00471 } else {
00472 $this->_setTotalCostsWithDiscount( $siteH );
00473 }
00474
00475 $siteH += 12;
00476
00477
00478 $this->_setVoucherInfo( $siteH );
00479
00480
00481 if ( $this->_oData->oxorder__oxdiscount->value || $this->_oData->oxorder__oxvoucherdiscount->value ) {
00482 $this->line( 45, $siteH - 3, 195, $siteH - 3 );
00483 }
00484
00485
00486 $this->_setDeliveryInfo( $siteH );
00487
00488
00489 $this->_setWrappingInfo( $siteH );
00490
00491
00492 $this->_setPaymentInfo( $siteH );
00493
00494
00495 $this->line( 15, $siteH, 195, $siteH );
00496 $siteH += 4;
00497
00498
00499 $this->_setGrandTotalPriceInfo( $siteH );
00500
00501
00502 $this->line( 15, $siteH, 195, $siteH );
00503 $siteH += 4;
00504
00505
00506 $this->_setPaymentMethodInfo( $siteH );
00507
00508
00509 $this->_setPayUntilInfo( $siteH );
00510
00511 return $siteH - $iStartPos;
00512 }
00513 }
00514
00518 class MyOrder extends MyOrder_parent
00519 {
00520
00525 protected $_iSelectedLang = 0;
00526
00531 protected $_oActShop = null;
00532
00537 protected $_aVATs = array();
00538
00543 protected $_oCur = null;
00544
00550 protected function _getActShop()
00551 {
00552
00553 if ( $this->_oActShop !== null )
00554 return $this->_oActShop;
00555
00556 $this->_oActShop = oxNew( 'oxshop' );
00557 $this->_oActShop->load( $this->getConfig()->getShopId() );
00558
00559 return $this->_oActShop;
00560 }
00561
00569 public function translate( $sString )
00570 {
00571 return oxLang::getInstance()->translateString( $sString, $this->_iSelectedLang );
00572 }
00573
00581 public function pdfFooter( $oPdf )
00582 {
00583
00584 $oShop = $this->_getActShop();
00585
00586 $oPdf->line( 15, 272, 195, 272 );
00587
00588
00589 $oPdf->setFont( 'Arial', '', 7 );
00590 $oPdf->text( 15, 275, strip_tags( $oShop->oxshops__oxcompany->value ) );
00591 $oPdf->text( 15, 278, strip_tags( $oShop->oxshops__oxfname->value ).' '. strip_tags( $oShop->oxshops__oxlname->value ) );
00592 $oPdf->text( 15, 281, strip_tags( $oShop->oxshops__oxstreet->value ) );
00593 $oPdf->text( 15, 284, strip_tags( $oShop->oxshops__oxzip->value ).' '. strip_tags( $oShop->oxshops__oxcity->value ) );
00594 $oPdf->text( 15, 287, strip_tags( $oShop->oxshops__oxcountry->value ) );
00595
00596
00597 $oPdf->text( 85, 275, $this->translate( 'ORDER_OVERVIEW_PDF_PHONE' ).strip_tags( $oShop->oxshops__oxtelefon->value ) );
00598 $oPdf->text( 85, 278, $this->translate( 'ORDER_OVERVIEW_PDF_FAX' ).strip_tags( $oShop->oxshops__oxtelefax->value ) );
00599 $oPdf->text( 85, 281, strip_tags( $oShop->oxshops__oxurl->value ) );
00600 $oPdf->text( 85, 284, strip_tags( $oShop->oxshops__oxorderemail->value ) );
00601
00602
00603 $oPdf->text( 150, 275, strip_tags( $oShop->oxshops__oxbankname->value ) );
00604 $oPdf->text( 150, 278, $this->translate( 'ORDER_OVERVIEW_PDF_ACCOUNTNR' ).strip_tags( $oShop->oxshops__oxbanknumber->value ) );
00605 $oPdf->text( 150, 281, $this->translate( 'ORDER_OVERVIEW_PDF_BANKCODE' ).strip_tags( $oShop->oxshops__oxbankcode->value ) );
00606 $oPdf->text( 150, 284, strip_tags( $oShop->oxshops__oxvatnumber->value ) );
00607 $oPdf->text( 150, 287, '' );
00608 }
00609
00617 public function pdfHeaderPlus( $oPdf )
00618 {
00619
00620
00621 $this->pdfHeader( $oPdf );
00622
00623
00624 $oPdf->setFont( 'Arial', '', 8 );
00625 $oPdf->text( 15, 50, $this->translate( 'ORDER_OVERVIEW_PDF_AMOUNT' ) );
00626 $oPdf->text( 30, 50, $this->translate( 'ORDER_OVERVIEW_PDF_ARTID') );
00627 $oPdf->text( 45, 50, $this->translate( 'ORDER_OVERVIEW_PDF_DESC' ) );
00628 $oPdf->text( 160, 50, $this->translate( 'ORDER_OVERVIEW_PDF_UNITPRICE' ) );
00629 $sText = $this->translate( 'ORDER_OVERVIEW_PDF_ALLPRICE' );
00630 $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), 50, $sText );
00631
00632
00633 $oPdf->line( 15, 52, 195, 52 );
00634
00635 return 56;
00636 }
00637
00645 public function pdfHeader( $oPdf )
00646 {
00647
00648 $oPdf->addPage();
00649
00650
00651 $oShop = $this->_getActShop();
00652
00653
00654 $myConfig = $this->getConfig();
00655 $aSize = getimagesize( $myConfig->getAbsImageDir().'/pdf_logo.jpg' );
00656 $iMargin = 195 - $aSize[0] * 0.2;
00657 $oPdf->setLink( $oShop->oxshops__oxurl->value );
00658 $oPdf->image( $myConfig->getAbsImageDir().'/pdf_logo.jpg', $iMargin, 10, $aSize[0] * 0.2, $aSize[1] * 0.2, '', $oShop->oxshops__oxurl->value );
00659 return 14 + $aSize[1] * 0.2;
00660 }
00661
00670 public function genPdf( $sFilename, $iSelLang = 0 )
00671 {
00672
00673 $this->_iSelectedLang = $iSelLang;
00674
00675
00676 if ( !$this->oxorder__oxinvoicenr->value ) {
00677 $this->oxorder__oxinvoicenr->setValue($this->getInvoiceNum());
00678 $this->save();
00679 }
00680
00681
00682 $oPdf = oxNew( 'oxPDF' );
00683 $oPdf->open();
00684
00685
00686 $this->pdfHeader( $oPdf );
00687
00688
00689 switch ( oxConfig::getParameter( 'pdftype' ) ) {
00690 case 'dnote':
00691 $this->exportDeliveryNote( $oPdf );
00692 break;
00693 default:
00694 $this->exportStandart( $oPdf );
00695 }
00696
00697
00698 $this->pdfFooter( $oPdf );
00699
00700
00701 $oPdf->output( $sFilename, true );
00702 }
00703
00704
00712 protected function _setBillingAddressToPdf( $oPdf )
00713 {
00714 $oPdf->setFont( 'Arial', '', 10 );
00715 $oPdf->text( 15, 59, $this->oxorder__oxbillsal->value );
00716 $oPdf->text( 15, 63, $this->oxorder__oxbilllname->value.' '.$this->oxorder__oxbillfname->value );
00717 $oPdf->text( 15, 67, $this->oxorder__oxbillcompany->value );
00718 $oPdf->text( 15, 71, $this->oxorder__oxbillstreet->value.' '.$this->oxorder__oxbillstreetnr->value );
00719 $oPdf->setFont( 'Arial', 'B', 10 );
00720 $oPdf->text( 15, 75, $this->oxorder__oxbillzip->value.' '.$this->oxorder__oxbillcity->value );
00721 $oPdf->setFont( 'Arial', '', 10 );
00722 $oPdf->text( 15, 79, $this->oxorder__oxbillcountry->value );
00723 }
00724
00732 protected function _setDeliveryAddressToPdf( $oPdf )
00733 {
00734 $oPdf->setFont( 'Arial', '', 6 );
00735 $oPdf->text( 15, 87, $this->translate( 'ORDER_OVERVIEW_PDF_DELIVERYADDRESS' ) );
00736 $oPdf->setFont( 'Arial', '', 10 );
00737 $oPdf->text( 15, 91, $this->oxorder__oxdelsal->value );
00738 $oPdf->text( 15, 95, $this->oxorder__oxdellname->value.' '.$this->oxorder__oxdelfname->value );
00739 $oPdf->text( 15, 99, $this->oxorder__oxdelcompany->value );
00740 $oPdf->text( 15, 103, $this->oxorder__oxdelstreet->value.' '.$this->oxorder__oxdelstreetnr->value );
00741 $oPdf->setFont( 'Arial', 'B', 10 );
00742 $oPdf->text( 15, 107, $this->oxorder__oxdelzip->value.' '.$this->oxorder__oxdelcity->value );
00743 $oPdf->setFont( 'Arial', '', 10 );
00744 $oPdf->text( 15, 111, $this->oxorder__oxdelcountry->value );
00745 }
00746
00756 protected function _setOrderArticlesToPdf( $oPdf, &$iStartPos, $blShowPrice = true )
00757 {
00758 if (!$this->_oArticles) {
00759 $this->_oArticles = $this->getOrderArticles(true);
00760 }
00761
00762
00763 foreach ( $this->_oArticles as $key => $oOrderArt ) {
00764
00765
00766 if ( $iStartPos > 243 ) {
00767 $this->pdffooter( $oPdf );
00768 $iStartPos = $this->pdfheaderplus( $oPdf );
00769 $oPdf->setFont( 'Arial', '', 10 );
00770 } else {
00771 $iStartPos = $iStartPos + 4;
00772 }
00773
00774
00775 $oPdf->text( 20 - $oPdf->getStringWidth( $oOrderArt->oxorderarticles__oxamount->value ), $iStartPos, $oOrderArt->oxorderarticles__oxamount->value );
00776
00777
00778 $oPdf->setFont( 'Arial', '', 8 );
00779 $oPdf->text( 28, $iStartPos, $oOrderArt->oxorderarticles__oxartnum->value );
00780
00781
00782 $oPdf->setFont( 'Arial', '', 10 );
00783 $oPdf->text( 45, $iStartPos, substr( strip_tags( $this->_replaceExtendedChars( $oOrderArt->oxorderarticles__oxtitle->value, true ) ), 0, 58 ) );
00784
00785 if ( $blShowPrice ) {
00786
00787
00788 $sText = oxLang::getInstance()->formatCurrency( $oOrderArt->oxorderarticles__oxbprice->value, $this->_oCur ).' '.$this->_oCur->name;
00789 $oPdf->text( 163 - $oPdf->getStringWidth( $sText ), $iStartPos, $sText );
00790
00791
00792 $sText = oxLang::getInstance()->formatCurrency( $oOrderArt->oxorderarticles__oxbrutprice->value, $this->_oCur ).' '.$this->_oCur->name;
00793 $oPdf->text( 184 - $oPdf->getStringWidth( $sText ), $iStartPos, $sText );
00794
00795
00796 $oPdf->text( 195 - $oPdf->getStringWidth( $oOrderArt->oxorderarticles__oxvat->value ), $iStartPos, $oOrderArt->oxorderarticles__oxvat->value );
00797
00798
00799 if ( !isset( $this->_aVATs[$oOrderArt->oxorderarticles__oxvat->value] ) ) {
00800 $this->_aVATs[$oOrderArt->oxorderarticles__oxvat->value] = 0;
00801 }
00802 $this->_aVATs[$oOrderArt->oxorderarticles__oxvat->value] += $oOrderArt->oxorderarticles__oxvatprice->value;
00803 }
00804
00805
00806 if ( $oOrderArt->oxorderarticles__oxselvariant->value ) {
00807 $iStartPos = $iStartPos + 4;
00808 $oPdf->text( 45, $iStartPos, substr( $oOrderArt->oxorderarticles__oxselvariant->value, 0, 58 ) );
00809 }
00810
00811 }
00812 }
00813
00821 public function exportStandart( $oPdf )
00822 {
00823
00824 $myConfig = $this->getConfig();
00825
00826 $this->_oCur = $myConfig->getCurrencyObject( $this->oxorder__oxcurrency->value );
00827 if ( !$this->_oCur ) {
00828 $this->_oCur = $myConfig->getActShopCurrencyObject();
00829 }
00830
00831
00832 $oShop = $this->_getActShop();
00833
00834
00835 $oPdf->setFont( 'Arial', '', 6 );
00836 $oPdf->text( 15, 55, $oShop->oxshops__oxname->value.' - '.$oShop->oxshops__oxstreet->value.' - '.$oShop->oxshops__oxzip->value.' - '.$oShop->oxshops__oxcity->value );
00837
00838
00839 $this->_setBillingAddressToPdf( $oPdf );
00840
00841
00842 if ( $this->oxorder__oxdelsal->value ) {
00843 $this->_setDeliveryAddressToPdf( $oPdf );
00844 }
00845
00846
00847 $oUser = oxNew( 'oxuser' );
00848 $oUser->load( $this->oxorder__oxuserid->value );
00849
00850
00851 $sText = $this->translate( 'ORDER_OVERVIEW_PDF_FILLONPAYMENT' );
00852 $oPdf->setFont( 'Arial', '', 5 );
00853 $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), 55, $sText );
00854
00855
00856 $sCustNr = $this->translate( 'ORDER_OVERVIEW_PDF_CUSTNR').' '.$oUser->oxuser__oxcustnr->value;
00857 $oPdf->setFont( 'Arial', '', 7 );
00858 $oPdf->text( 195 - $oPdf->getStringWidth( $sCustNr ), 59, $sCustNr );
00859
00860
00861 if ( $this->oxorder__oxdelsal->value ) {
00862 $iTop = 115;
00863 } else {
00864 $iTop = 91;
00865 }
00866
00867
00868 $sText = $oShop->oxshops__oxcity->value.', '.date( 'd.m.Y' );
00869 $oPdf->setFont( 'Arial', '', 10 );
00870 $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), $iTop + 8, $sText );
00871
00872
00873 if ( $oShop->oxshops__oxvatnumber->value ) {
00874 $sText = $this->translate( 'ORDER_OVERVIEW_PDF_TAXIDNR' ).' '.$oShop->oxshops__oxvatnumber->value;
00875 $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), $iTop + 12, $sText );
00876 $iTop += 8;
00877 }
00878
00879
00880 $sText = $this->translate( 'ORDER_OVERVIEW_PDF_COUNTNR' ).' '.$this->oxorder__oxinvoicenr->value;
00881 $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), $iTop + 8, $sText );
00882
00883
00884 if ( $this->oxorder__oxstorno->value == 1 ) {
00885 $this->oxorder__oxordernr->setValue( $this->oxorder__oxordernr->getRawValue() . ' '.$this->translate( 'ORDER_OVERVIEW_PDF_STORNO' ), oxField::T_RAW );
00886 }
00887
00888
00889 $oPdf->setFont( 'Arial', '', 12 );
00890 $oPdf->text( 15, $iTop, $this->translate( 'ORDER_OVERVIEW_PDF_PURCHASENR' ).' '.$this->oxorder__oxordernr->value );
00891
00892
00893 $oPdf->setFont( 'Arial', '', 10 );
00894 $aOrderDate = explode( ' ', $this->oxorder__oxorderdate->value );
00895 $sOrderDate = oxUtilsDate::getInstance()->formatDBDate( $aOrderDate[0]);
00896 $oPdf->text( 15, $iTop + 8, $this->translate( 'ORDER_OVERVIEW_PDF_ORDERSFROM' ).$sOrderDate.$this->translate( 'ORDER_OVERVIEW_PDF_ORDERSAT' ).$oShop->oxshops__oxurl->value );
00897 $iTop += 16;
00898
00899
00900 $oPdf->setFont( 'Arial', '', 8 );
00901 $oPdf->text( 15, $iTop, $this->translate( 'ORDER_OVERVIEW_PDF_AMOUNT' ) );
00902 $oPdf->text( 30, $iTop, $this->translate( 'ORDER_OVERVIEW_PDF_ARTID' ) );
00903 $oPdf->text( 45, $iTop, $this->translate( 'ORDER_OVERVIEW_PDF_DESC' ) );
00904 $oPdf->text( 148, $iTop, $this->translate( 'ORDER_OVERVIEW_PDF_UNITPRICE' ) );
00905 $oPdf->text( 168, $iTop, $this->translate( 'ORDER_OVERVIEW_PDF_ALLPRICE' ) );
00906 $sText = $this->translate( 'ORDER_OVERVIEW_PDF_VAT' );
00907 $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), $iTop, $sText );
00908
00909
00910 $iTop += 2;
00911 $oPdf->line( 15, $iTop, 195, $iTop );
00912
00913
00914 $siteH = $iTop;
00915 $oPdf->setFont( 'Arial', '', 10 );
00916
00917
00918 $this->_setOrderArticlesToPdf( $oPdf, $siteH, true );
00919
00920
00921 $oArtSumm = new PdfArticleSummary( $this, $oPdf );
00922 $iHeight = $oArtSumm->generate( $siteH );
00923 if ( $siteH + $iHeight > 258 ) {
00924 $this->pdfFooter( $oPdf );
00925 $iTop = $this->pdfHeader( $oPdf );
00926 $oArtSumm->ajustHeight( $iTop - $siteH );
00927 $siteH = $iTop;
00928 }
00929
00930 $oArtSumm->run( $oPdf );
00931 $siteH += $iHeight + 8;
00932
00933 $oPdf->text( 15, $siteH, $this->translate( 'ORDER_OVERVIEW_PDF_GREETINGS' ) );
00934 }
00935
00943 public function exportDeliveryNote( $oPdf )
00944 {
00945 $myConfig = $this->getConfig();
00946 $oShop = $this->_getActShop();
00947
00948
00949 $this->_oCur = $myConfig->getCurrencyObject( $this->oxorder__oxcurrency->value );
00950 if ( !isset( $this->_oCur ) ) {
00951 $this->_oCur = $myConfig->getActShopCurrencyObject();
00952 }
00953
00954
00955 $oPdf->setFont( 'Arial', '', 6 );
00956 $oPdf->text( 15, 55, $oShop->oxshops__oxname->value.' - '.$oShop->oxshops__oxstreet->value.' - '.$oShop->oxshops__oxzip->value.' - '.$oShop->oxshops__oxcity->value );
00957
00958
00959 $oPdf->setFont( 'Arial', '', 10 );
00960 if ( $this->oxorder__oxdelsal->value ) {
00961 $oPdf->text( 15, 59, $this->oxorder__oxdelsal->value );
00962 $oPdf->text( 15, 63, $this->oxorder__oxdellname->value.' '.$this->oxorder__oxdelfname->value );
00963 $oPdf->text( 15, 67, $this->oxorder__oxdelcompany->value );
00964 $oPdf->text( 15, 71, $this->oxorder__oxdelstreet->value.' '.$this->oxorder__oxdelstreetnr->value );
00965 $oPdf->setFont( 'Arial', 'B', 10 );
00966 $oPdf->text( 15, 75, $this->oxorder__oxdelzip->value.' '.$this->oxorder__oxdelcity->value );
00967 $oPdf->setFont( 'Arial', '', 10 );
00968 $oPdf->text( 15, 79, $this->oxorder__oxdelcountry->value );
00969 } else {
00970 $this->_setBillingAddressToPdf( $oPdf );
00971 }
00972
00973
00974 $oUser = oxNew( 'oxuser' );
00975 $oUser->load( $this->oxorder__oxuserid->value );
00976
00977
00978 $sText = $this->translate( 'ORDER_OVERVIEW_PDF_FILLONPAYMENT' );
00979 $oPdf->setFont( 'Arial', '', 5 );
00980 $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), 70, $sText );
00981
00982
00983 $sCustNr = $this->translate( 'ORDER_OVERVIEW_PDF_CUSTNR' ).' '.$oUser->oxuser__oxcustnr->value;
00984 $oPdf->setFont( 'Arial', '', 7 );
00985 $oPdf->text( 195 - $oPdf->getStringWidth( $sCustNr ), 73, $sCustNr );
00986
00987
00988 $sText = $oShop->oxshops__oxcity->value.', '.date( 'd.m.Y' );
00989 $oPdf->setFont( 'Arial', '', 10 );
00990 $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), 95, $sText );
00991
00992 $iTop = 99;
00993
00994 if ( $oShop->oxshops__oxvatnumber->value ) {
00995 $sText = $this->translate( 'ORDER_OVERVIEW_PDF_TAXIDNR' ).' '.$oShop->oxshops__oxvatnumber->value;
00996 $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), $iTop, $sText );
00997 $iTop += 4;
00998 }
00999
01000
01001 $sText = $this->translate( 'ORDER_OVERVIEW_PDF_COUNTNR' ).' '.$this->oxorder__oxinvoicenr->value;
01002 $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), $iTop, $sText );
01003
01004
01005 if ( $this->oxorder__oxstorno->value == 1 ) {
01006 $this->oxorder__oxordernr->setValue( $this->oxorder__oxordernr->getRawValue() . ' '.$this->translate( 'ORDER_OVERVIEW_PDF_STORNO' ), oxField::T_RAW );
01007 }
01008
01009
01010 $oPdf->setFont( 'Arial', '', 12 );
01011 $oPdf->text( 15, 108, $this->translate( 'ORDER_OVERVIEW_PDF_DELIVNOTE' ).' '.$this->oxorder__oxordernr->value );
01012
01013
01014 $aOrderDate = explode( ' ', $this->oxorder__oxorderdate->value );
01015 $sOrderDate = oxUtilsDate::getInstance()->formatDBDate( $aOrderDate[0]);
01016 $oPdf->setFont( 'Arial', '', 10 );
01017 $oPdf->text(15, 119, $this->translate( 'ORDER_OVERVIEW_PDF_ORDERSFROM' ).$sOrderDate.$this->translate( 'ORDER_OVERVIEW_PDF_ORDERSAT' ).$oShop->oxshops__oxurl->value );
01018
01019
01020 $oPdf->setFont( 'Arial', '', 8 );
01021 $oPdf->text( 15, 128, $this->translate( 'ORDER_OVERVIEW_PDF_AMOUNT' ) );
01022 $oPdf->text( 30, 128, $this->translate( 'ORDER_OVERVIEW_PDF_ARTID' ) );
01023 $oPdf->text( 45, 128, $this->translate( 'ORDER_OVERVIEW_PDF_DESC' ) );
01024
01025
01026 $oPdf->line( 15, 130, 195, 130 );
01027
01028
01029 $oPdf->setFont( 'Arial', '', 10 );
01030 $siteH = 130;
01031
01032
01033 $this->_setOrderArticlesToPdf( $oPdf, $siteH, false );
01034
01035
01036 $oPdf->line( 15, $siteH + 2, 195, $siteH + 2 );
01037 $siteH += 4;
01038
01039
01040 $oPdf->setFont( 'Arial', '', 10 );
01041 $text = $this->translate( 'ORDER_OVERVIEW_PDF_PAYUPTO' ).date( 'd.m.Y', mktime( 0, 0, 0, date ( 'm' ), date ( 'd' ) + 7, date( 'Y' ) ) );
01042 $oPdf->text( 15, $siteH + 4, $text );
01043 }
01044
01054 protected function _replaceExtendedChars( $sValue, $blReverse = false )
01055 {
01056
01057
01058
01059
01060
01061
01062 $aReplace = array( chr(169) => "©", chr(128) => "€", "\"" => """, "'" => "'");
01063
01064
01065
01066 if ($blReverse) {
01067 $aTransTbl = get_html_translation_table (HTML_ENTITIES);
01068 $aTransTbl = array_flip ($aTransTbl) + array_flip ($aReplace);
01069 $sValue = strtr($sValue, $aTransTbl);
01070 $sValue = preg_replace('/\&\#([0-9]+)\;/me', "chr('\\1')", $sValue);
01071 }
01072
01073 return $sValue;
01074 }
01075
01081 public function getVats()
01082 {
01083 return $this->_aVATs;
01084 }
01085
01091 public function getCurrency()
01092 {
01093 return $this->_oCur;
01094 }
01095
01101 public function getSelectedLang()
01102 {
01103 return $this->_iSelectedLang;
01104 }
01105
01111 public function getOrderArticles( $blStorno = false )
01112 {
01113 if ( $this->_oArticles == null ) {
01114
01115 $this->_oArticles = oxNew( 'oxlist' );
01116 $this->_oArticles->init( 'oxorderarticle' );
01117
01118 $sSelect = 'select oxorderarticles.* from oxorderarticles where oxorderarticles.oxorderid="'.$this->getId().'"';
01119 if ( $blStorno ) {
01120 $sSelect.= ' and oxstorno = 0';
01121 }
01122 $sSelect.= ' order by oxorderarticles.oxartid';
01123 $this->_oArticles->selectString( $sSelect );
01124 }
01125
01126 return $this->_oArticles;
01127 }
01128 }