示例#1
0
文件: Cell.php 项目: grlf/eyedock
 public function render(Am_Pdf_Page_Decorator $page, $x, $y)
 {
     if ($font = $this->getProperty('font')) {
         $fontTmp = $page->getFont();
         $fontSizeTmp = $page->getFontSize();
         $page->setFont($font['face'], $font['size']);
     }
     $lineHeight = $page->getFont()->getLineHeight() / 100;
     $lineBegin = $y - $this->getPadding(self::TOP) - $lineHeight;
     $width = $this->getWidth() - $this->getPadding(self::LEFT) - $this->getPadding(self::RIGHT);
     switch ($this->getProperty('align', Am_Pdf_Page_Decorator::ALIGN_LEFT)) {
         case Am_Pdf_Page_Decorator::ALIGN_LEFT:
             $lineEnd = $page->drawTextWithFixedWidth($this->content, $x + 1 + $this->getPadding(self::LEFT), $lineBegin, $width);
             break;
         case Am_Pdf_Page_Decorator::ALIGN_RIGHT:
             $lineEnd = $page->drawTextWithFixedWidth($this->content, $x + $this->getWidth() - 1 - $this->getPadding(self::RIGHT), $lineBegin, $width, 'UTF-8', Am_Pdf_Page_Decorator::ALIGN_RIGHT);
             break;
     }
     $rowHeight = $lineBegin - $lineEnd;
     if ($font) {
         $page->setFont($fontTmp, $fontSizeTmp);
     }
     $shape = $this->getProperty('shape', array('type' => Zend_Pdf_Page::SHAPE_DRAW_STROKE, 'color' => new Zend_Pdf_Color_Html('#cccccc')));
     return array('x' => $x, 'y' => $y, 'width' => $this->getWidth(), 'height' => $rowHeight + $this->getPadding(self::BOTTOM) + $this->getPadding(self::TOP), 'shape' => $shape);
 }
示例#2
0
 public function render(Am_Pdf_Page_Decorator $page, $x, $y)
 {
     $this->width = $this->width ? $this->width : $page->getWidth() - $x;
     $rowNum = 1;
     foreach ($this->getRows() as $row) {
         $row->setTable($this);
         $row->setWidth($this->width - $this->getMargin(self::LEFT) - $this->getMargin(self::RIGHT));
         $row->addStyle($this->getStyleForRow($rowNum));
         $row->render($page, $x + $this->getMargin(self::LEFT), $y - $this->getMargin(self::TOP));
         $y = $y - $row->getHeight($page);
         $rowNum++;
     }
     return $y;
 }
示例#3
0
 public function drawDefaultTemplate(Zend_Pdf $pdf)
 {
     $pointer = $this->getPaperHeight() - 20;
     $page = new Am_Pdf_Page_Decorator($pdf->pages[0]);
     if (!($ic = $this->getDi()->config->get('invoice_contacts'))) {
         $ic = $this->getDi()->config->get('site_title') . '<br>' . $this->getDi()->config->get('root_url');
     }
     $page->setFont($this->getFontRegular(), 10);
     $invoice_logo_id = $this->getDi()->config->get('invoice_logo');
     if ($invoice_logo_id && ($upload = $this->getDi()->uploadTable->load($invoice_logo_id, false))) {
         if (file_exists($upload->getFullPath())) {
             $image = null;
             switch ($upload->getType()) {
                 case 'image/png':
                     $image = new Zend_Pdf_Resource_Image_Png($upload->getFullPath());
                     break;
                 case 'image/jpeg':
                     $image = new Zend_Pdf_Resource_Image_Jpeg($upload->getFullPath());
                     break;
                 case 'image/tiff':
                     $image = new Zend_Pdf_Resource_Image_Tiff($upload->getFullPath());
                     break;
             }
             if ($image) {
                 $page->drawImage($image, 20, $pointer - 100, 220, $pointer);
             }
         }
     }
     $page->drawTextWithFixedWidth($ic, $this->getPaperWidth() - 20, $pointer, 400, 'UTF-8', Am_Pdf_Page_Decorator::ALIGN_RIGHT);
     $pointer -= 110;
     $page->drawLine(20, $pointer, $this->getPaperWidth() - 20, $pointer);
     $page->nl($pointer);
     $page->nl($pointer);
     return $pointer;
 }
示例#4
0
 protected function drawBorder(Am_Pdf_Page_Decorator $page, $x, $y)
 {
     $rowHeight = $page->getFont()->getLineHeight() / 100;
     $shape = $this->getProperty('shape', array('type' => Zend_Pdf_Page::SHAPE_DRAW_STROKE, 'color' => new Zend_Pdf_Color_Html('#cccccc')));
     $page->setLineColor($shape['color']);
     $page->setFillColor($shape['color']);
     $page->drawRectangle($x, $y, $x + $this->getWidth(), $y + $rowHeight + $this->getPadding(self::BOTTOM) + $this->getPadding(self::TOP), $shape['type']);
     $page->setFillColor(new Zend_Pdf_Color_Html('#000000'));
 }
示例#5
0
 public function render()
 {
     $invoice = $this->invoice;
     $payment = $this->payment;
     $user = $invoice->getUser();
     $pdf = $this->createPdfTemplate();
     $event = new Am_Event(Am_Event::PDF_INVOICE_BEFORE_RENDER, array('amPdfInvoice' => $this, 'pdf' => $pdf, 'invoice' => $invoice, 'payment' => $payment, 'user' => $user));
     $event->setReturn(false);
     $this->getDi()->hook->call($event);
     // If event processing already rendered the Pdf.
     if ($event->getReturn() === true) {
         return $pdf->render();
     }
     $width_num = 30;
     $width_qty = 40;
     $width_price = 80;
     $width_total = 120;
     $padd = 20;
     $left = $padd;
     $right = $this->getPaperWidth() - $padd;
     $fontH = $this->getFontRegular();
     $fontHB = $this->getFontBold();
     $styleBold = array('font' => array('face' => $fontHB, 'size' => 10));
     $page = new Am_Pdf_Page_Decorator($pdf->pages[0]);
     $page->setFont($fontH, 10);
     $pointer = $this->getPointer();
     $pointerL = $pointerR = $pointer;
     $leftCol = new stdClass();
     $leftCol->invoiceNumber = ___('Corrective Invoice Number: ') . $payment->getDisplayInvoiceId();
     $leftCol->recInvoiceNumber = ___('Rectifies Invoice Number: ') . $this->getOrigPayment()->getDisplayInvoiceId();
     $leftCol->date = ___('Date: ') . amDate($payment->dattm);
     if ($user->tax_id) {
         $leftCol->taxId = ___('EU VAT ID: ') . $user->tax_id;
     }
     $this->getDi()->hook->call(Am_Event::PDF_INVOICE_COL_LEFT, array('col' => $leftCol, 'invoice' => $invoice, 'payment' => $payment, 'user' => $user));
     foreach ($leftCol as $line) {
         $page->drawText($line, $left, $pointerL);
         $page->nl($pointerL);
     }
     $rightCol = new stdClass();
     $rightCol->name = $invoice->getName();
     $rightCol->email = $invoice->getEmail();
     $rightCol->address = implode(', ', array_filter(array($invoice->getStreet(), $invoice->getCity())));
     $rightCol->country = implode(', ', array_filter(array($this->getState($invoice), $invoice->getZip(), $this->getCountry($invoice))));
     $this->getDi()->hook->call(Am_Event::PDF_INVOICE_COL_RIGHT, array('col' => $rightCol, 'invoice' => $invoice, 'payment' => $payment, 'user' => $user));
     foreach ($rightCol as $line) {
         $page->drawText($line, $right, $pointerR, 'UTF-8', Am_Pdf_Page_Decorator::ALIGN_RIGHT);
         $page->nl($pointerR);
     }
     $pointer = min($pointerR, $pointerL);
     $p = new stdClass();
     $p->value =& $pointer;
     $this->getDi()->hook->call(Am_Event::PDF_INVOICE_BEFORE_TABLE, array('page' => $page, 'pointer' => $p, 'invoice' => $invoice, 'payment' => $payment, 'user' => $user));
     $table = new Am_Pdf_Table();
     $table->setMargin($padd, $padd, $padd, $padd);
     $table->setStyleForRow(1, array('shape' => array('type' => Zend_Pdf_Page::SHAPE_DRAW_STROKE, 'color' => new Zend_Pdf_Color_Html("#cccccc")), 'font' => array('face' => $fontHB, 'size' => 10)));
     $table->setStyleForColumn(1, array('align' => 'right', 'width' => $width_num));
     $table->setStyleForColumn(3, array('align' => 'right', 'width' => $width_qty));
     $table->setStyleForColumn(4, array('align' => 'right', 'width' => $width_price));
     $table->setStyleForColumn(5, array('align' => 'right', 'width' => $width_total));
     $table->addRow(array(___('#'), ___('Subscription/Product Title'), ___('Qty'), ___('Unit Price'), ___('Total Price')));
     $num = 0;
     foreach ($invoice->getItems() as $p) {
         /* @var $p InvoiceItem */
         $table->addRow(array(++$num . '.', $p->item_title, $p->qty, $invoice->getCurrency($this->isFirstPayment() ? $p->first_price : $p->second_price), $invoice->getCurrency($this->isFirstPayment() ? $p->getFirstSubtotal() : $p->getSecondSubtotal())));
     }
     $pointer = $page->drawTable($table, 0, $pointer);
     $table = new Am_Pdf_Table();
     $table->setMargin($padd, $padd, $padd, $padd);
     $table->setStyleForColumn(2, array('align' => 'right', 'width' => $width_total));
     $subtotal = $this->isFirstPayment() ? $invoice->first_subtotal : $invoice->second_subtotal;
     $total = $this->isFirstPayment() ? $invoice->first_total : $invoice->second_total;
     if ($subtotal != $total) {
         $table->addRow(array(___('Subtotal'), $invoice->getCurrency($subtotal)))->addStyle($styleBold);
     }
     if ($this->isFirstPayment() && $invoice->first_discount > 0 || !$this->isFirstPayment() && $invoice->second_discount > 0) {
         $table->addRow(array(___('Coupon Discount'), $invoice->getCurrency($this->isFirstPayment() ? $invoice->first_discount : $invoice->second_discount)));
     }
     $table->addRow(array(___('Total'), $invoice->getCurrency($total)))->addStyle($styleBold);
     $table->addRow(array(___('Taxable Income'), "-" . $invoice->getCurrency($this->getOrigPayment()->amount - $this->getOrigPayment()->tax)))->addStyle($styleBold);
     if ($this->getOrigPayment()->tax > 0) {
         $table->addRow(array(___('Tax') . " " . $invoice->tax_rate . "%", "-" . $invoice->getCurrency($this->getOrigPayment()->tax)))->addStyle($styleBold);
     }
     $table->addRow(array(___('Amount Paid'), $invoice->getCurrency(sprintf("%.2f", $this->getOrigPayment()->amount - $this->payment->amount))))->addStyle(array('font' => array('face' => $fontHB, 'size' => 10)));
     $x = $this->getPaperWidth() - ($width_qty + $width_price + $width_total) - 2 * $padd;
     $pointer = $page->drawTable($table, $x, $pointer);
     $page->nl($pointer);
     $page->nl($pointer);
     if (!$this->getDi()->config->get('invoice_do_not_include_terms')) {
         $termsText = new Am_TermsText($invoice);
         $page->drawTextWithFixedWidth(___('Subscription Terms') . ': ' . $termsText, $left, $pointer, $this->getPaperWidth() - 2 * $padd);
         $page->nl($pointer);
     }
     $p = new stdClass();
     $p->value =& $pointer;
     $this->getDi()->hook->call(Am_Event::PDF_INVOICE_AFTER_TABLE, array('page' => $page, 'pointer' => $p, 'invoice' => $invoice, 'payment' => $payment, 'user' => $user));
     if (!$this->getDi()->config->get('invoice_custom_template') || !$this->getDi()->uploadTable->load($this->getDi()->config->get('invoice_custom_template'))) {
         if ($ifn = $this->getDi()->config->get('invoice_footer_note')) {
             $tmpl = new Am_SimpleTemplate();
             $tmpl->assignStdVars();
             $tmpl->assign('user', $user);
             $tmpl->assign('invoice', $invoice);
             $ifn = $tmpl->render($ifn);
             $page->nl($pointer);
             $page->drawTextWithFixedWidth($ifn, $left, $pointer, $this->getPaperWidth() - 2 * $padd);
         }
     }
     return $pdf->render();
 }
示例#6
0
 public function render()
 {
     $invoice = $this->invoice;
     $pdf = $this->createPdfTemplate();
     $padd = 20;
     $left = $padd;
     $right = $this->getPaperWidth() - $padd;
     $fontH = $this->getFontRegular();
     $fontHB = $this->getFontBold();
     $styleBold = array('font' => array('face' => $fontHB, 'size' => 12));
     $page = new Am_Pdf_Page_Decorator($pdf->pages[0]);
     $page->setFont($fontH, 12);
     $pointer = $this->getPointer();
     $pointerL = $pointerR = $pointer;
     $page->drawText('Invoice Number: ' . $invoice->public_id, $left, $pointerL);
     $page->nl($pointerL);
     $page->drawText('Date: ' . amDatetime($invoice->tm_added), $left, $pointerL);
     $page->nl($pointerL);
     $page->setFont($fontHB, 12);
     $page->drawText($invoice->getName(), $right, $pointerR, null, Am_Pdf_Page_Decorator::ALIGN_RIGHT);
     $page->setFont($fontH, 12);
     $page->nl($pointerR);
     $page->drawText($invoice->getEmail(), $right, $pointerR, null, Am_Pdf_Page_Decorator::ALIGN_RIGHT);
     $page->nl($pointerR);
     $page->drawText('', $right, $pointerR, null, Am_Pdf_Page_Decorator::ALIGN_RIGHT);
     $page->nl($pointerR);
     $page->drawText(implode(', ', array_filter(array($invoice->getStreet(), $invoice->getCity()))), $right, $pointerR, null, Am_Pdf_Page_Decorator::ALIGN_RIGHT);
     $page->nl($pointerR);
     $page->drawText(implode(', ', array_filter(array($this->getState($invoice), $invoice->getZip(), $this->getCountry($invoice)))), $right, $pointerR, null, Am_Pdf_Page_Decorator::ALIGN_RIGHT);
     $page->nl($pointerR);
     $pointer = min($pointerR, $pointerL);
     $page->nl($pointer);
     $table = new Am_Pdf_Table();
     $table->setMargin($padd, $padd, $padd, $padd);
     $table->setStyleForRow(1, array('shape' => array('type' => Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE, 'color' => new Zend_Pdf_Color_Html("#cccccc")), 'font' => array('face' => $fontHB, 'size' => 12)));
     $table->setStyleForColumn(2, array('align' => 'right', 'width' => 80));
     $table->addRow(array(___('Subscription/Product Title'), ___('Price')));
     foreach ($invoice->getItems() as $p) {
         $table->addRow(array($p->item_title, $invoice->getCurrency($p->getFirstSubtotal())));
     }
     $table->addRow(array(___('Subtotal'), $invoice->getCurrency($invoice->first_subtotal)))->addStyle($styleBold);
     if ($invoice->first_discount > 0) {
         $table->addRow(array(___('Coupon Discount'), $invoice->getCurrency($invoice->first_discount)));
     }
     if ($invoice->first_tax > 0) {
         $table->addRow(array(___('Tax Amount'), $invoice->getCurrency($invoice->first_tax)));
     }
     $table->addRow(array(___('Total'), $invoice->getCurrency($invoice->first_total)))->addStyle($styleBold);
     $pointer = $page->drawTable($table, 0, $pointer);
     $page->nl($pointer);
     $termsText = new Am_TermsText($invoice);
     $page->drawTextWithFixedWidth(___('Subscription Terms') . ': ' . $termsText, $left, $pointer, $this->getPaperWidth() - 2 * $padd);
     $page->nl($pointer);
     if (!$this->getDi()->config->get('invoice_custom_template') || !$this->getDi()->uploadTable->load($this->getDi()->config->get('invoice_custom_template'))) {
         if ($ifn = $this->getDi()->config->get('invoice_footer_note')) {
             $page->nl($pointer);
             $page->drawTextWithFixedWidth($ifn, $left, $pointer, $this->getPaperWidth() - 2 * $padd);
         }
     }
     return $pdf->render();
 }