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 $iVat => $dVatPrice ) {
00179 $iStartPos += 4 * $iCtr;
00180 $sVATSum = $oLang->formatCurrency( $dVatPrice, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00181 $this->text( 45, $iStartPos + 8, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_ZZGLVAT' ).$iVat.$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 $iVat => $dVatPrice ) {
00241 $iStartPos += 4 * $iCtr;
00242 $sVATSum = $oLang->formatCurrency( $dVatPrice, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00243 $this->text( 45, $iStartPos + 12, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_ZZGLVAT' ).$iVat.$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 if ( $this->_oData->oxorder__oxpaycost->value ) {
00395 $iStartPos += 4;
00396 $sPayCost = $oLang->formatCurrency( $this->_oData->oxorder__oxpaycost->value, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00397 $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_PAYMENTIMPACT' ) );
00398 $this->text( 195 - $this->_oPdf->getStringWidth( $sPayCost ), $iStartPos, $sPayCost );
00399 }
00400
00401 $iStartPos++;
00402 }
00403
00411 protected function _setGrandTotalPriceInfo( &$iStartPos )
00412 {
00413 $oLang = oxLang::getInstance();
00414
00415
00416 $this->font( 'Arial', 'B', 10 );
00417 if ( $this->_oData->oxorder__oxdelvat->value || $this->_oData->oxorder__oxwrapvat->value || $this->_oData->oxorder__oxpayvat->value ) {
00418
00419
00420 $sTotalNetSum = $oLang->formatCurrency( $this->_oData->getOrderNetSum(), $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00421 $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_ALLSUM_NET' ) );
00422 $this->text( 195 - $this->_oPdf->getStringWidth( $sTotalNetSum ), $iStartPos, $sTotalNetSum );
00423 $iStartPos += 4;
00424 }
00425
00426
00427 $sTotalOrderSum = $oLang->formatCurrency( $this->_oData->oxorder__oxtotalordersum->value, $this->_oData->getCurrency() ).' '.$this->_oData->getCurrency()->name;
00428 $this->text( 45, $iStartPos, $this->_oData->translate( 'ORDER_OVERVIEW_PDF_ALLSUM' ) );
00429 $this->text( 195 - $this->_oPdf->getStringWidth( $sTotalOrderSum ), $iStartPos, $sTotalOrderSum );
00430 $iStartPos += 2;
00431 }
00432
00440 protected function _setPaymentMethodInfo( &$iStartPos )
00441 {
00442 $oPayment = oxNew( 'oxpayment' );
00443 $oPayment->loadInLang( $this->_oData->getSelectedLang(), $this->_oData->oxorder__oxpaymenttype->value );
00444
00445 $text = $this->_oData->translate( 'ORDER_OVERVIEW_PDF_SELPAYMENT' ).$oPayment->oxpayments__oxdesc->value;
00446 $this->font( 'Arial', '', 10 );
00447 $this->text( 15, $iStartPos + 4, $text );
00448 $iStartPos += 4;
00449 }
00450
00458 protected function _setPayUntilInfo( &$iStartPos )
00459 {
00460 $text = $this->_oData->translate( 'ORDER_OVERVIEW_PDF_PAYUPTO' ).date( 'd.m.Y', mktime( 0, 0, 0, date ( 'm' ), date ( 'd' ) + 7, date( 'Y' ) ) );
00461 $this->font( 'Arial', '', 10 );
00462 $this->text( 15, $iStartPos + 4, $text );
00463 $iStartPos += 4;
00464 }
00465
00473 public function generate( $iStartPos )
00474 {
00475
00476 $this->font( 'Arial', '', 10 );
00477 $siteH = $iStartPos;
00478
00479
00480 if ( !$this->_oData->oxorder__oxdiscount->value ) {
00481 $this->_setTotalCostsWithoutDiscount( $siteH );
00482 } else {
00483 $this->_setTotalCostsWithDiscount( $siteH );
00484 }
00485
00486 $siteH += 12;
00487
00488
00489 $this->_setVoucherInfo( $siteH );
00490
00491
00492 if ( $this->_oData->oxorder__oxdiscount->value || $this->_oData->oxorder__oxvoucherdiscount->value ) {
00493 $this->line( 45, $siteH - 3, 195, $siteH - 3 );
00494 }
00495
00496
00497 $this->_setDeliveryInfo( $siteH );
00498
00499
00500 $this->_setWrappingInfo( $siteH );
00501
00502
00503 $this->_setPaymentInfo( $siteH );
00504
00505
00506 $this->line( 15, $siteH, 195, $siteH );
00507 $siteH += 4;
00508
00509
00510 $this->_setGrandTotalPriceInfo( $siteH );
00511
00512
00513 $this->line( 15, $siteH, 195, $siteH );
00514 $siteH += 4;
00515
00516
00517 $this->_setPaymentMethodInfo( $siteH );
00518
00519
00520 $this->_setPayUntilInfo( $siteH );
00521
00522 return $siteH - $iStartPos;
00523 }
00524 }
00525
00529 class MyOrder extends MyOrder_parent
00530 {
00531
00536 protected $_iSelectedLang = 0;
00537
00542 protected $_oActShop = null;
00543
00548 protected $_aVATs = array();
00549
00554 protected $_oCur = null;
00555
00561 protected function _getActShop()
00562 {
00563
00564 if ( $this->_oActShop !== null )
00565 return $this->_oActShop;
00566
00567 $this->_oActShop = oxNew( 'oxshop' );
00568 $this->_oActShop->load( $this->getConfig()->getShopId() );
00569
00570 return $this->_oActShop;
00571 }
00572
00580 public function translate( $sString )
00581 {
00582 return oxLang::getInstance()->translateString( $sString, $this->_iSelectedLang );
00583 }
00584
00592 public function pdfFooter( $oPdf )
00593 {
00594
00595 $oShop = $this->_getActShop();
00596
00597 $oPdf->line( 15, 272, 195, 272 );
00598
00599
00600 $oPdf->setFont( 'Arial', '', 7 );
00601 $oPdf->text( 15, 275, strip_tags( $oShop->oxshops__oxcompany->getRawValue() ) );
00602 $oPdf->text( 15, 278, strip_tags( $oShop->oxshops__oxfname->getRawValue() ).' '. strip_tags( $oShop->oxshops__oxlname->getRawValue() ) );
00603 $oPdf->text( 15, 281, strip_tags( $oShop->oxshops__oxstreet->getRawValue() ) );
00604 $oPdf->text( 15, 284, strip_tags( $oShop->oxshops__oxzip->value ).' '. strip_tags( $oShop->oxshops__oxcity->getRawValue() ) );
00605 $oPdf->text( 15, 287, strip_tags( $oShop->oxshops__oxcountry->getRawValue() ) );
00606
00607
00608 $oPdf->text( 85, 275, $this->translate( 'ORDER_OVERVIEW_PDF_PHONE' ).strip_tags( $oShop->oxshops__oxtelefon->value ) );
00609 $oPdf->text( 85, 278, $this->translate( 'ORDER_OVERVIEW_PDF_FAX' ).strip_tags( $oShop->oxshops__oxtelefax->value ) );
00610 $oPdf->text( 85, 281, strip_tags( $oShop->oxshops__oxurl->value ) );
00611 $oPdf->text( 85, 284, strip_tags( $oShop->oxshops__oxorderemail->value ) );
00612
00613
00614 $oPdf->text( 150, 275, strip_tags( $oShop->oxshops__oxbankname->getRawValue() ) );
00615 $oPdf->text( 150, 278, $this->translate( 'ORDER_OVERVIEW_PDF_ACCOUNTNR' ).strip_tags( $oShop->oxshops__oxbanknumber->value ) );
00616 $oPdf->text( 150, 281, $this->translate( 'ORDER_OVERVIEW_PDF_BANKCODE' ).strip_tags( $oShop->oxshops__oxbankcode->value ) );
00617 $oPdf->text( 150, 284, strip_tags( $oShop->oxshops__oxvatnumber->value ) );
00618 $oPdf->text( 150, 287, '' );
00619 }
00620
00628 public function pdfHeaderPlus( $oPdf )
00629 {
00630
00631
00632 $this->pdfHeader( $oPdf );
00633
00634
00635 $oPdf->setFont( 'Arial', '', 8 );
00636 $oPdf->text( 15, 50, $this->translate( 'ORDER_OVERVIEW_PDF_AMOUNT' ) );
00637 $oPdf->text( 30, 50, $this->translate( 'ORDER_OVERVIEW_PDF_ARTID') );
00638 $oPdf->text( 45, 50, $this->translate( 'ORDER_OVERVIEW_PDF_DESC' ) );
00639 $oPdf->text( 160, 50, $this->translate( 'ORDER_OVERVIEW_PDF_UNITPRICE' ) );
00640 $sText = $this->translate( 'ORDER_OVERVIEW_PDF_ALLPRICE' );
00641 $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), 50, $sText );
00642
00643
00644 $oPdf->line( 15, 52, 195, 52 );
00645
00646 return 56;
00647 }
00648
00656 public function pdfHeader( $oPdf )
00657 {
00658
00659 $oPdf->addPage();
00660
00661
00662 $oShop = $this->_getActShop();
00663
00664
00665 $myConfig = $this->getConfig();
00666 $aSize = getimagesize( $myConfig->getAbsImageDir().'/pdf_logo.jpg' );
00667 $iMargin = 195 - $aSize[0] * 0.2;
00668 $oPdf->setLink( $oShop->oxshops__oxurl->value );
00669 $oPdf->image( $myConfig->getAbsImageDir().'/pdf_logo.jpg', $iMargin, 10, $aSize[0] * 0.2, $aSize[1] * 0.2, '', $oShop->oxshops__oxurl->value );
00670 return 14 + $aSize[1] * 0.2;
00671 }
00672
00681 public function genPdf( $sFilename, $iSelLang = 0 )
00682 {
00683
00684 $this->_iSelectedLang = $iSelLang;
00685
00686
00687 if ( !$this->oxorder__oxbillnr->value ) {
00688 $this->oxorder__oxbillnr->setValue($this->getNextBillNum());
00689 $this->save();
00690 }
00691
00692
00693 $oPdf = oxNew( 'oxPDF' );
00694 $oPdf->setPrintHeader( false );
00695 $oPdf->open();
00696
00697
00698 $this->pdfHeader( $oPdf );
00699
00700
00701 switch ( oxConfig::getParameter( 'pdftype' ) ) {
00702 case 'dnote':
00703 $this->exportDeliveryNote( $oPdf );
00704 break;
00705 default:
00706 $this->exportStandart( $oPdf );
00707 }
00708
00709
00710 $this->pdfFooter( $oPdf );
00711
00712
00713 $oPdf->output( $sFilename, 'I' );
00714 }
00715
00716
00724 protected function _setBillingAddressToPdf( $oPdf )
00725 {
00726 $oLang = oxLang::getInstance();
00727 $sSal = $this->oxorder__oxbillsal->value;
00728 try {
00729 $sSal = $oLang->translateString($this->oxorder__oxbillsal->value, $this->_iSelectedLang);
00730 } catch (Exception $e) {
00731 }
00732 $oPdf->setFont( 'Arial', '', 10 );
00733 $oPdf->text( 15, 59, $sSal);
00734 $oPdf->text( 15, 63, $this->oxorder__oxbilllname->getRawValue().' '.$this->oxorder__oxbillfname->getRawValue() );
00735 $oPdf->text( 15, 67, $this->oxorder__oxbillcompany->getRawValue() );
00736 $oPdf->text( 15, 71, $this->oxorder__oxbillstreet->getRawValue().' '.$this->oxorder__oxbillstreetnr->value );
00737 $oPdf->setFont( 'Arial', 'B', 10 );
00738 $oPdf->text( 15, 75, $this->oxorder__oxbillzip->value.' '.$this->oxorder__oxbillcity->getRawValue() );
00739 $oPdf->setFont( 'Arial', '', 10 );
00740 $oPdf->text( 15, 79, $this->oxorder__oxbillcountry->getRawValue() );
00741 }
00742
00750 protected function _setDeliveryAddressToPdf( $oPdf )
00751 {
00752 $oLang = oxLang::getInstance();
00753 $sSal = $this->oxorder__oxdelsal->value;
00754 try {
00755 $sSal = $oLang->translateString($this->oxorder__oxdelsal->value, $this->_iSelectedLang);
00756 } catch (Exception $e) {
00757 }
00758 $oPdf->setFont( 'Arial', '', 6 );
00759 $oPdf->text( 15, 87, $this->translate( 'ORDER_OVERVIEW_PDF_DELIVERYADDRESS' ) );
00760 $oPdf->setFont( 'Arial', '', 10 );
00761 $oPdf->text( 15, 91, $sSal);
00762 $oPdf->text( 15, 95, $this->oxorder__oxdellname->getRawValue().' '.$this->oxorder__oxdelfname->getRawValue() );
00763 $oPdf->text( 15, 99, $this->oxorder__oxdelcompany->getRawValue() );
00764 $oPdf->text( 15, 103, $this->oxorder__oxdelstreet->getRawValue().' '.$this->oxorder__oxdelstreetnr->value );
00765 $oPdf->setFont( 'Arial', 'B', 10 );
00766 $oPdf->text( 15, 107, $this->oxorder__oxdelzip->value.' '.$this->oxorder__oxdelcity->getRawValue() );
00767 $oPdf->setFont( 'Arial', '', 10 );
00768 $oPdf->text( 15, 111, $this->oxorder__oxdelcountry->getRawValue() );
00769 }
00770
00780 protected function _setOrderArticlesToPdf( $oPdf, &$iStartPos, $blShowPrice = true )
00781 {
00782 if (!$this->_oArticles) {
00783 $this->_oArticles = $this->getOrderArticles(true);
00784 }
00785
00786 $oCurr = $this->getCurrency();
00787
00788
00789 foreach ( $this->_oArticles as $key => $oOrderArt ) {
00790
00791
00792 if ( $iStartPos > 243 ) {
00793 $this->pdffooter( $oPdf );
00794 $iStartPos = $this->pdfheaderplus( $oPdf );
00795 $oPdf->setFont( 'Arial', '', 10 );
00796 } else {
00797 $iStartPos = $iStartPos + 4;
00798 }
00799
00800
00801 $oPdf->text( 20 - $oPdf->getStringWidth( $oOrderArt->oxorderarticles__oxamount->value ), $iStartPos, $oOrderArt->oxorderarticles__oxamount->value );
00802
00803
00804 $oPdf->setFont( 'Arial', '', 8 );
00805 $oPdf->text( 28, $iStartPos, $oOrderArt->oxorderarticles__oxartnum->value );
00806
00807
00808 $oPdf->setFont( 'Arial', '', 10 );
00809 $oPdf->text( 45, $iStartPos, substr( strip_tags( $this->_replaceExtendedChars( $oOrderArt->oxorderarticles__oxtitle->getRawValue(), true ) ), 0, 58 ) );
00810
00811 if ( $blShowPrice ) {
00812 $oLang = oxLang::getInstance();
00813
00814
00815 if ( !isset( $this->_aVATs[$oOrderArt->oxorderarticles__oxvat->value] ) ) {
00816 $this->_aVATs[$oOrderArt->oxorderarticles__oxvat->value] = 0;
00817 }
00818
00819 if ( $oOrderArt->oxorderarticles__oxamount->value > 0 ) {
00820 $this->_aVATs[$oOrderArt->oxorderarticles__oxvat->value] += ( $oOrderArt->oxorderarticles__oxvatprice->value * $oCurr->rate );
00821 }
00822
00823
00824 $oPdf->text( 150 - $oPdf->getStringWidth( $oOrderArt->oxorderarticles__oxvat->value ), $iStartPos, $oOrderArt->oxorderarticles__oxvat->value );
00825
00826
00827 $sText = $oLang->formatCurrency( $oOrderArt->oxorderarticles__oxbprice->value, $this->_oCur ).' '.$this->_oCur->name;
00828 $oPdf->text( 173 - $oPdf->getStringWidth( $sText ), $iStartPos, $sText );
00829
00830
00831 $sText = $oLang->formatCurrency( $oOrderArt->oxorderarticles__oxbrutprice->value, $this->_oCur ).' '.$this->_oCur->name;
00832 $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), $iStartPos, $sText );
00833
00834 }
00835
00836
00837 if ( $oOrderArt->oxorderarticles__oxselvariant->value ) {
00838 $iStartPos = $iStartPos + 4;
00839 $oPdf->text( 45, $iStartPos, substr( $oOrderArt->oxorderarticles__oxselvariant->value, 0, 58 ) );
00840 }
00841
00842 }
00843 }
00844
00852 public function exportStandart( $oPdf )
00853 {
00854
00855 $myConfig = $this->getConfig();
00856
00857 $this->_oCur = $myConfig->getCurrencyObject( $this->oxorder__oxcurrency->value );
00858 if ( !$this->_oCur ) {
00859 $this->_oCur = $myConfig->getActShopCurrencyObject();
00860 }
00861
00862
00863 $oShop = $this->_getActShop();
00864
00865
00866 $oPdf->setFont( 'Arial', '', 6 );
00867 $oPdf->text( 15, 55, $oShop->oxshops__oxname->getRawValue().' - '.$oShop->oxshops__oxstreet->getRawValue().' - '.$oShop->oxshops__oxzip->value.' - '.$oShop->oxshops__oxcity->getRawValue() );
00868
00869
00870 $this->_setBillingAddressToPdf( $oPdf );
00871
00872
00873 if ( $this->oxorder__oxdelsal->value ) {
00874 $this->_setDeliveryAddressToPdf( $oPdf );
00875 }
00876
00877
00878 $oUser = oxNew( 'oxuser' );
00879 $oUser->load( $this->oxorder__oxuserid->value );
00880
00881
00882 $sText = $this->translate( 'ORDER_OVERVIEW_PDF_FILLONPAYMENT' );
00883 $oPdf->setFont( 'Arial', '', 5 );
00884 $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), 55, $sText );
00885
00886
00887 $sCustNr = $this->translate( 'ORDER_OVERVIEW_PDF_CUSTNR').' '.$oUser->oxuser__oxcustnr->value;
00888 $oPdf->setFont( 'Arial', '', 7 );
00889 $oPdf->text( 195 - $oPdf->getStringWidth( $sCustNr ), 59, $sCustNr );
00890
00891
00892 if ( $this->oxorder__oxdelsal->value ) {
00893 $iTop = 115;
00894 } else {
00895 $iTop = 91;
00896 }
00897
00898
00899 $sText = $oShop->oxshops__oxcity->getRawValue().', '.date( 'd.m.Y' );
00900 $oPdf->setFont( 'Arial', '', 10 );
00901 $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), $iTop + 8, $sText );
00902
00903
00904 if ( $oShop->oxshops__oxvatnumber->value ) {
00905 $sText = $this->translate( 'ORDER_OVERVIEW_PDF_TAXIDNR' ).' '.$oShop->oxshops__oxvatnumber->value;
00906 $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), $iTop + 12, $sText );
00907 $iTop += 8;
00908 } else {
00909 $iTop += 4;
00910 }
00911
00912
00913 $sText = $this->translate( 'ORDER_OVERVIEW_PDF_COUNTNR' ).' '.$this->oxorder__oxbillnr->value;
00914 $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), $iTop + 8, $sText );
00915
00916
00917 if ( $this->oxorder__oxstorno->value == 1 ) {
00918 $this->oxorder__oxordernr->setValue( $this->oxorder__oxordernr->getRawValue() . ' '.$this->translate( 'ORDER_OVERVIEW_PDF_STORNO' ), oxField::T_RAW );
00919 }
00920
00921
00922 $oPdf->setFont( 'Arial', '', 12 );
00923 $oPdf->text( 15, $iTop, $this->translate( 'ORDER_OVERVIEW_PDF_PURCHASENR' ).' '.$this->oxorder__oxordernr->value );
00924
00925
00926 $oPdf->setFont( 'Arial', '', 10 );
00927 $aOrderDate = explode( ' ', $this->oxorder__oxorderdate->value );
00928 $sOrderDate = oxUtilsDate::getInstance()->formatDBDate( $aOrderDate[0]);
00929 $oPdf->text( 15, $iTop + 8, $this->translate( 'ORDER_OVERVIEW_PDF_ORDERSFROM' ).$sOrderDate.$this->translate( 'ORDER_OVERVIEW_PDF_ORDERSAT' ).$oShop->oxshops__oxurl->value );
00930 $iTop += 16;
00931
00932
00933 $oPdf->setFont( 'Arial', '', 8 );
00934 $oPdf->text( 15, $iTop, $this->translate( 'ORDER_OVERVIEW_PDF_AMOUNT' ) );
00935 $oPdf->text( 30, $iTop, $this->translate( 'ORDER_OVERVIEW_PDF_ARTID' ) );
00936 $oPdf->text( 45, $iTop, $this->translate( 'ORDER_OVERVIEW_PDF_DESC' ) );
00937 $oPdf->text( 145, $iTop, $this->translate( 'ORDER_OVERVIEW_PDF_VAT' ) );
00938 $oPdf->text( 158, $iTop, $this->translate( 'ORDER_OVERVIEW_PDF_UNITPRICE' ) );
00939 $sText = $this->translate( 'ORDER_OVERVIEW_PDF_ALLPRICE' );
00940 $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), $iTop, $sText );
00941
00942
00943 $iTop += 2;
00944 $oPdf->line( 15, $iTop, 195, $iTop );
00945
00946
00947 $siteH = $iTop;
00948 $oPdf->setFont( 'Arial', '', 10 );
00949
00950
00951 $this->_setOrderArticlesToPdf( $oPdf, $siteH, true );
00952
00953
00954 $oArtSumm = new PdfArticleSummary( $this, $oPdf );
00955 $iHeight = $oArtSumm->generate( $siteH );
00956 if ( $siteH + $iHeight > 258 ) {
00957 $this->pdfFooter( $oPdf );
00958 $iTop = $this->pdfHeader( $oPdf );
00959 $oArtSumm->ajustHeight( $iTop - $siteH );
00960 $siteH = $iTop;
00961 }
00962
00963 $oArtSumm->run( $oPdf );
00964 $siteH += $iHeight + 8;
00965
00966 $oPdf->text( 15, $siteH, $this->translate( 'ORDER_OVERVIEW_PDF_GREETINGS' ) );
00967 }
00968
00976 public function exportDeliveryNote( $oPdf )
00977 {
00978 $myConfig = $this->getConfig();
00979 $oShop = $this->_getActShop();
00980
00981 $oLang = oxLang::getInstance();
00982 $sSal = $this->oxorder__oxdelsal->value;
00983 try {
00984 $sSal = $oLang->translateString($this->oxorder__oxdelsal->value, $this->_iSelectedLang);
00985 } catch (Exception $e) {
00986 }
00987
00988
00989 $this->_oCur = $myConfig->getCurrencyObject( $this->oxorder__oxcurrency->value );
00990 if ( !isset( $this->_oCur ) ) {
00991 $this->_oCur = $myConfig->getActShopCurrencyObject();
00992 }
00993
00994
00995 $oPdf->setFont( 'Arial', '', 6 );
00996 $oPdf->text( 15, 55, $oShop->oxshops__oxname->getRawValue().' - '.$oShop->oxshops__oxstreet->getRawValue().' - '.$oShop->oxshops__oxzip->value.' - '.$oShop->oxshops__oxcity->getRawValue() );
00997
00998
00999 $oPdf->setFont( 'Arial', '', 10 );
01000 if ( $this->oxorder__oxdelsal->value ) {
01001 $oPdf->text( 15, 59, $sSal );
01002 $oPdf->text( 15, 63, $this->oxorder__oxdellname->getRawValue().' '.$this->oxorder__oxdelfname->getRawValue() );
01003 $oPdf->text( 15, 67, $this->oxorder__oxdelcompany->getRawValue() );
01004 $oPdf->text( 15, 71, $this->oxorder__oxdelstreet->getRawValue().' '.$this->oxorder__oxdelstreetnr->value );
01005 $oPdf->setFont( 'Arial', 'B', 10 );
01006 $oPdf->text( 15, 75, $this->oxorder__oxdelzip->value.' '.$this->oxorder__oxdelcity->getRawValue() );
01007 $oPdf->setFont( 'Arial', '', 10 );
01008 $oPdf->text( 15, 79, $this->oxorder__oxdelcountry->getRawValue() );
01009 } else {
01010
01011 $this->_setBillingAddressToPdf( $oPdf );
01012 }
01013
01014
01015 $oUser = oxNew( 'oxuser' );
01016 $oUser->load( $this->oxorder__oxuserid->value );
01017
01018
01019 $sText = $this->translate( 'ORDER_OVERVIEW_PDF_FILLONPAYMENT' );
01020 $oPdf->setFont( 'Arial', '', 5 );
01021 $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), 70, $sText );
01022
01023
01024 $sCustNr = $this->translate( 'ORDER_OVERVIEW_PDF_CUSTNR' ).' '.$oUser->oxuser__oxcustnr->value;
01025 $oPdf->setFont( 'Arial', '', 7 );
01026 $oPdf->text( 195 - $oPdf->getStringWidth( $sCustNr ), 73, $sCustNr );
01027
01028
01029 $sText = $oShop->oxshops__oxcity->getRawValue().', '.date( 'd.m.Y' );
01030 $oPdf->setFont( 'Arial', '', 10 );
01031 $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), 95, $sText );
01032
01033 $iTop = 99;
01034
01035 if ( $oShop->oxshops__oxvatnumber->value ) {
01036 $sText = $this->translate( 'ORDER_OVERVIEW_PDF_TAXIDNR' ).' '.$oShop->oxshops__oxvatnumber->value;
01037 $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), $iTop, $sText );
01038 $iTop += 4;
01039 }
01040
01041
01042 $sText = $this->translate( 'ORDER_OVERVIEW_PDF_COUNTNR' ).' '.$this->oxorder__oxbillnr->value;
01043 $oPdf->text( 195 - $oPdf->getStringWidth( $sText ), $iTop, $sText );
01044
01045
01046 if ( $this->oxorder__oxstorno->value == 1 ) {
01047 $this->oxorder__oxordernr->setValue( $this->oxorder__oxordernr->getRawValue() . ' '.$this->translate( 'ORDER_OVERVIEW_PDF_STORNO' ), oxField::T_RAW );
01048 }
01049
01050
01051 $oPdf->setFont( 'Arial', '', 12 );
01052 $oPdf->text( 15, 108, $this->translate( 'ORDER_OVERVIEW_PDF_DELIVNOTE' ).' '.$this->oxorder__oxordernr->value );
01053
01054
01055 $aOrderDate = explode( ' ', $this->oxorder__oxorderdate->value );
01056 $sOrderDate = oxUtilsDate::getInstance()->formatDBDate( $aOrderDate[0]);
01057 $oPdf->setFont( 'Arial', '', 10 );
01058 $oPdf->text(15, 119, $this->translate( 'ORDER_OVERVIEW_PDF_ORDERSFROM' ).$sOrderDate.$this->translate( 'ORDER_OVERVIEW_PDF_ORDERSAT' ).$oShop->oxshops__oxurl->value );
01059
01060
01061 $oPdf->setFont( 'Arial', '', 8 );
01062 $oPdf->text( 15, 128, $this->translate( 'ORDER_OVERVIEW_PDF_AMOUNT' ) );
01063 $oPdf->text( 30, 128, $this->translate( 'ORDER_OVERVIEW_PDF_ARTID' ) );
01064 $oPdf->text( 45, 128, $this->translate( 'ORDER_OVERVIEW_PDF_DESC' ) );
01065
01066
01067 $oPdf->line( 15, 130, 195, 130 );
01068
01069
01070 $oPdf->setFont( 'Arial', '', 10 );
01071 $siteH = 130;
01072
01073
01074 $this->_setOrderArticlesToPdf( $oPdf, $siteH, false );
01075
01076
01077 $oPdf->line( 15, $siteH + 2, 195, $siteH + 2 );
01078 $siteH += 4;
01079
01080
01081 $oPdf->setFont( 'Arial', '', 10 );
01082 $text = $this->translate( 'ORDER_OVERVIEW_PDF_PAYUPTO' ).date( 'd.m.Y', mktime( 0, 0, 0, date ( 'm' ), date ( 'd' ) + 7, date( 'Y' ) ) );
01083 $oPdf->text( 15, $siteH + 4, $text );
01084 }
01085
01095 protected function _replaceExtendedChars( $sValue, $blReverse = false )
01096 {
01097
01098
01099
01100
01101
01102
01103 $aReplace = array( chr(169) => "©", chr(128) => "€", "\"" => """, "'" => "'");
01104
01105
01106
01107 if ($blReverse) {
01108
01109 $aTransTbl = get_html_translation_table (HTML_ENTITIES);
01110 $aTransTbl = array_flip ($aTransTbl) + array_flip ($aReplace);
01111 $sValue = strtr($sValue, $aTransTbl);
01112 $sValue = getStr()->preg_replace('/\&\#([0-9]+)\;/me', "chr('\\1')", $sValue);
01113 }
01114
01115 return $sValue;
01116 }
01117
01123 public function getVats()
01124 {
01125
01126 $aVats = $this->getProductVats( false );
01127
01128
01129 return ( is_array( $aVats ) && count( $aVats ) ) ? $aVats : $this->_aVATs;
01130 }
01131
01137 public function getCurrency()
01138 {
01139 return $this->_oCur;
01140 }
01141
01147 public function getSelectedLang()
01148 {
01149 return $this->_iSelectedLang;
01150 }
01151
01159 public function getOrderArticles( $blStorno = false )
01160 {
01161 if ( $this->_oArticles == null ) {
01162
01163 $this->_oArticles = oxNew( 'oxlist' );
01164 $this->_oArticles->init( 'oxorderarticle' );
01165
01166 $sSelect = 'select oxorderarticles.* from oxorderarticles where oxorderarticles.oxorderid="'.$this->getId().'"';
01167 if ( $blStorno ) {
01168 $sSelect.= ' and oxstorno = 0';
01169 }
01170 $sSelect.= ' order by oxorderarticles.oxartid';
01171 $this->_oArticles->selectString( $sSelect );
01172 }
01173
01174 return $this->_oArticles;
01175 }
01176 }