v7‰PNG  IHDR Ÿ f Õ†C1 sRGB ®Îé gAMA ± üa pHYs à ÃÇo¨d GIDATx^íÜL”÷ð÷Yçªö("Bh_ò«®¸¢§q5kÖ*:þ0A­ºšÖ¥]VkJ¢M»¶f¸±8\k2íll£1]q®ÙÔ‚ÆT Page/Decorator.php000064400000006413152101613070010053 0ustar00_imp = $page; } /** * * @return Zend_Pdf_Page * */ public function getImp() { return $this->_imp; } public function nl(&$pointer) { $pointer-=$this->getSpacing(); } protected function getSpacing() { return floor($this->getFontSize() * 1.3); } public function __call($name, $arguments) { return call_user_func_array(array( $this->getImp(), $name ), $arguments); } public function drawTable(Am_Pdf_Table $table, $x, $y) { return $table->render($this, $x, $y); } public function drawText($text, $x, $y, $charEncoding = 'UTF-8', $align = self::ALIGN_LEFT) { $text = trim($text); switch ($align) { case self::ALIGN_RIGHT : $x = $x - $this->widthForString($text); break; case self::ALIGN_CENTER : $x = $x - ($this->widthForString($text) / 2); break; case self::ALIGN_LEFT : default: //nop break; } $this->getImp()->drawText($text, $x, $y, $charEncoding); } public function drawTextWithFixedWidth($text, $x, $y, $width, $charEncoding = 'UTF-8', $align = self::ALIGN_LEFT) { //$text = str_replace(array("\n", "\r"), array('', ''), $text); $text = preg_replace('/\ {2,}/i', ' ', $text); $text_parts = preg_split("##", $text); foreach ($text_parts as $text) { $text = explode(' ', $text); $line = ''; foreach ($text as $word) { $line .= ' ' . $word; if ($this->widthForString($line) > $width) { $line = substr($line, 0, strlen($line) - (strlen($word) + 1)); $this->drawText($line, $x, $y, $charEncoding, $align); $this->nl($y); $line = $word; } } $this->drawText($line, $x, $y, $charEncoding, $align); $this->nl($y); } return $y; } public function widthForString($string) { $font = $this->getFont(); $fontSize = $this->getFontSize(); $drawingString = iconv('UTF-8', 'UTF-16BE//IGNORE', $string); $characters = array(); for ($i = 0; $i < strlen($drawingString); $i++) { $characters[] = (ord($drawingString[$i++]) << 8) | ord($drawingString[$i]); } $glyphs = $font->glyphNumbersForCharacters($characters); $widths = $font->widthsForGlyphs($glyphs); $stringWidth = (array_sum($widths) / $font->getUnitsPerEm()) * $fontSize; return $stringWidth; } }Table.php000064400000007126152101613070006306 0ustar00 0, self::RIGHT => 0, self::BOTTOM => 0, self::LEFT => 0 ); public function __construct($newPageCallback = null, $newPageThreshold = 0) { $this->newPageCallback = $newPageCallback; $this->newPageThreshold = $newPageThreshold; } public function setData($data) { $this->data = $data; foreach($data as $rowData) { $row = new Am_Pdf_Row(); $row->setData($rowData); $this->rows[] = $row; } } public function setStyleForColumn($colNum, $style) { $this->stylesColl[$colNum] = $style; } public function setStyleForRow($rowNum, $style) { $this->stylesRow[$rowNum] = $style; } public function getStyleForRow($rowNum) { if (isset($this->stylesRow[$rowNum])) { return $this->stylesRow[$rowNum]; } else { return array(); } } public function getStyleForColumn($colNum) { if (isset($this->stylesColl[$colNum])) { return $this->stylesColl[$colNum]; } else { return array(); } } public function setMargin($top=0, $right=0, $bottom=0, $left=0) { $this->margin = array( self::TOP => $top, self::RIGHT => $right, self::BOTTOM => $bottom, self::LEFT => $left ); } public function getMargin($side) { return $this->margin[$side]; } /** * @param array $rowData * @return Am_Pdf_Row */ public function addRow($rowData) { $row = new Am_Pdf_Row(); $row->setData(is_array($rowData) ? $rowData : func_get_args()); $this->rows[] = $row; return $row; } public function setWidth($width) { $this->width = $width; } protected function getRows() { return $this->rows; } protected function newPage(Am_Pdf_Page_Decorator $page, &$y) { return $this->newPageCallback ? call_user_func_array($this->newPageCallback, array($page, &$y)) : $page; } public function render(Am_Pdf_Page_Decorator $page, $x, $y) { $this->width = $this->width ? $this->width : $page->getWidth() - $x; $y = $y - $this->getMargin(self::TOP); $x = $x + $this->getMargin(self::LEFT); $rowNum = 1; $shadowPage = new Am_Pdf_Page_Decorator(clone $page->getImp()); $shadowPage->setFont($page->getFont(), $page->getFontSize()); 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($shadowPage, $x, $y); $needHeight = $row->getHeight($shadowPage); if ($y - $needHeight < $this->newPageThreshold) { $page = $this->newPage($page, $y); } $row->render($page, $x, $y); $y = $y - $row->getHeight($page); $rowNum++; } return $y; } } Cell.php000064400000006100152101613070006125 0ustar00 0, self::RIGHT => 0, self::BOTTOM => 0, self::LEFT => 0 ); public function __construct($content) { $this->content = $content; } public function setStyle($styles) { $this->styles = $styles; } public function setWidth($width) { $this->width = $width; } public function setPadding($top=0, $right=0, $bottom=0, $left=0) { $this->padding = array( self::TOP => $top, self::RIGHT => $right, self::BOTTOM => $bottom, self::LEFT => $left ); } public function getPadding($side) { return $this->padding[$side]; } public function getWidth() { return $this->width; } 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); } protected function getProperty($propName, $default = null) { if (isset($this->styles[$propName])) { return $this->styles[$propName]; } else { return $default; } } }Row.php000064400000006307152101613070006026 0ustar00styles = $styles; } public function addStyle($styles) { $this->styles = array_merge($this->styles, $styles); } public function getStyle() { return $this->styles; } public function setTable($table) { $this->table = $table; } protected function getCells() { return $this->cells; } protected function getCellsCount() { return count($this->cells); } public function setWidth($width) { $this->width = $width; } public function getWidth() { return $this->width; } protected function getWidths() { $res = array(); for ($i=1; $i<=$this->getCellsCount(); $i++) { $styles = $this->table->getStyleForColumn($i); if (isset($styles['width'])) { $res[] = $styles['width']; } } return $res; } protected function getColWidth($colNum) { $styles = $this->table->getStyleForColumn($colNum); if (isset($styles['width'])) { return $styles['width']; } else { $widths = $this->getWidths(); $w = floor(($this->getWidth()-array_sum($widths))/ ($this->getCellsCount() - count($widths))); $wl = $this->getWidth() - array_sum($widths) - $w*($this->getCellsCount() - count($widths) -1); return $this->getCellsCount() == $colNum ? $wl : $w; } } public function render(Am_Pdf_Page_Decorator $page, $x, $y) { $cellWidth = floor($this->getWidth()/$this->getCellsCount()); $colNum = 1; $cellBorder = array(); $maxHeight = 0; foreach ($this->getCells() as $cell) { $cellWidth = $this->getColWidth($colNum); $cell->setWidth($cellWidth); $cell->setPadding(5,5,5,5); $cell->setStyle( array_merge( $this->table->getStyleForColumn($colNum), $this->getStyle() ) ); $border = $cell->render($page, $x, $y); $maxHeight = max($maxHeight, $border['height']); $cellBorder[] = $border; $x = $x + $cellWidth; $colNum++; } $this->height = $maxHeight; foreach ($cellBorder as $border) { extract($border, EXTR_OVERWRITE); $page->setLineColor($shape['color']); $page->setFillColor($shape['color']); $page->drawRectangle($x, $y, $x + $width, $y - $maxHeight, $shape['type']); $page->setFillColor(new Zend_Pdf_Color_Html('#000000')); } } public function getHeight($page) { return $this->height; } public function setData($data) { $this->data = $data; foreach($data as $cellData) { $cell = new Am_Pdf_Cell($cellData); $this->cells[] = $cell; } } }Invoice/Col.php000064400000003511152101613070007362 0ustar00$token = $text; return $token; } function prepend($text, $token = null) { $ref = key((array)$this); $ref ? $this->addBefore($text, $ref, $token) : $this->add($text, $token); } function remove($token) { foreach ((array)$token as $t) { unset($this->$t); } } function clear() { foreach (get_object_vars($this) as $token => $value) { unset($this->$token); } } function addBefore($text, $ref, $token = null) { $f = false; foreach ((array)$this as $prop => $val) { if ($prop == $ref) { $token = $token ?: uniqid(); $this->$token = $text; $f = true; } if ($f) { unset($this->$prop); $this->$prop = $val; } } return $token; } function addAfter($text, $ref, $token = null) { $f = false; foreach ((array)$this as $prop => $val) { if ($prop == $ref) { $token = $token ?: uniqid(); $this->$token = $text; $f = true; continue; } if ($f) { unset($this->$prop); $this->$prop = $val; } } return $token; } function moveBefore($token, $ref) { $_ = $this->$token; unset($this->$token); return $this->addBefore($_, $ref, $token); } function moveAfter($token, $ref) { $_ = $this->$token; unset($this->$token); return $this->addAfter($_, $ref, $token); } }Invoice/Abstract.php000064400000014167152101613070010421 0ustar00di = $di; } /** * @return Am_Di */ function getDi() { return $this->di ? $this->di : Am_Di::getInstance(); } public function getPaperWidth() { return $this->getDi()->config->get('invoice_format', self::PAPER_FORMAT_LETTER) == self::PAPER_FORMAT_LETTER ? Am_Pdf_Page_Decorator::PAGE_LETTER_WIDTH : Am_Pdf_Page_Decorator::PAGE_A4_WIDTH; } public function getPaperHeight() { return $this->getDi()->config->get('invoice_format', self::PAPER_FORMAT_LETTER) == self::PAPER_FORMAT_LETTER ? Am_Pdf_Page_Decorator::PAGE_LETTER_HEIGHT : Am_Pdf_Page_Decorator::PAGE_A4_HEIGHT; } public function drawDefaultTemplate(Zend_Pdf $pdf) { $padd = 40; $pointer = $this->getPaperHeight() - $padd; $page = new Am_Pdf_Page_Decorator($pdf->pages[0]); if (!($ic = $this->getDi()->config->get('invoice_contacts'))) { $ic = $this->getDi()->config->get('site_title') . '
' . $this->getDi()->config->get('root_url'); } $page->setFont($this->getFontRegular(), 10); $invoice_logo_id = $this->getDi()->config->get('invoice_logo'); $yi = $pointer; 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) { $gh = 100; $gw = 200; $h = $image->getPixelHeight(); $w = $image->getPixelWidth(); $nh = $gh; $nw = ceil($w * $gh / $h); if ($nw > $gw) { $nw = $gw; $nh = ceil($h * $gw / $w); } $page->drawImage($image, $padd, $pointer - $nh, $nw + $padd, $pointer); $yi = $pointer - $nh; } } } $yt = $page->drawTextWithFixedWidth($ic, $this->getPaperWidth() - $padd, $pointer, 400, 'UTF-8', Am_Pdf_Page_Decorator::ALIGN_RIGHT); $pointer = min($yt, $yi) - 10; $page->drawLine($padd, $pointer, $this->getPaperWidth() - $padd, $pointer); $page->nl($pointer); $page->nl($pointer); return $pointer; } /** * @return Zend_Pdf */ public function createPdfTemplate() { if ($this->getDi()->config->get('invoice_custom_template') && ($upload = $this->getDi()->uploadTable->load($this->getDi()->config->get('invoice_custom_template')))) { $pdf = Zend_Pdf::load($upload->getFullPath()); $this->pointer = $this->getPaperHeight() - $this->getDi()->config->get('invoice_skip', 150); } else { $pdf = new Zend_Pdf(); $pdf->pages[0] = $pdf->newPage($this->getDi()->config->get('invoice_format', Zend_Pdf_Page::SIZE_LETTER)); $this->pointer = $this->drawDefaultTemplate($pdf); } return $pdf; } //can be called only after createPdfTemplate public function getPointer() { return $this->pointer; } public function getFontRegular() { if ($this->getDi()->config->get('invoice_custom_ttf') && ($upload = $this->getDi()->uploadTable->load($this->getDi()->config->get('invoice_custom_ttf')))) { return Zend_Pdf_Font::fontWithPath($upload->getFullPath()); } else { return Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA); } } public function getFontBold() { if ($this->getDi()->config->get('invoice_custom_ttfbold') && ($upload = $this->getDi()->uploadTable->load($this->getDi()->config->get('invoice_custom_ttfbold')))) { return Zend_Pdf_Font::fontWithPath($upload->getFullPath()); } else { return Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD); } } public function getFileName() { $filename = $this->getDi()->config->get('invoice_filename', 'amember-invoice-%public_id%.pdf'); $filename = str_replace('%payment.date%', date('Y-m-d', amstrtotime($this->payment->dattm)), $filename); $tmp = new Am_SimpleTemplate(); $tmp->assign('public_id', $this->invoice->public_id); $tmp->assign('receipt_id', $this->payment->receipt_id); $tmp->assign('display_id', $this->payment->display_invoice_id); $tmp->assign('payment', $this->payment); $tmp->assign('invoice', $this->invoice); $tmp->assign('user', $this->invoice->getUser()); return $tmp->render($filename); } abstract function render(); public function getState(Invoice $invoice) { $state = $this->getDi()->stateTable->findFirstByState($invoice->getState()); return $state ? $state->title : $invoice->getState(); } public function getCountry(Invoice $invoice) { $country = $this->getDi()->countryTable->findFirstByCountry($invoice->getCountry()); return $country ? $country->title : $invoice->getCountry(); } }Invoice/InvoicePayment.php000064400000027707152101613070011614 0ustar00invoice = $payment->getInvoice(); $this->payment = $payment; } public function isFirstPayment() { return $this->payment->isFirst(); } 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 = 40; $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 Am_Pdf_Invoice_Col(); $leftCol->invoiceNumber = ___('Invoice Number: ') . $payment->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 Am_Pdf_Invoice_Col(); $rightCol->name = $invoice->getName(); $rightCol->email = $invoice->getEmail(); $rightCol->address = $invoice->getStreet1(); if ($invoice->getStreet2()) { $rightCol->address2 = $invoice->getStreet2(); } $rightCol->city = sprintf("%s, %s %s", $invoice->getCity(), $invoice->getState(), $invoice->getZip()); $rightCol->country = $this->getCountry($invoice); $this->getDi()->hook->call(Am_Event::PDF_INVOICE_COL_RIGHT, array( 'col' => $rightCol, 'invoice' => $invoice, 'payment' => $payment, 'user' => $user )); $lineLength = 0; foreach ($rightCol as $line) { $lineLength = max($lineLength, $page->widthForString($line)); } foreach ($rightCol as $line) { $page->drawText($line, $right - $lineLength, $pointerR, 'UTF-8'); $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 )); if ($this->getDi()->config->get('invoice_include_access')) { $pointer = $this->renderAccess($page, $pointer); } $table = new Am_Pdf_Table(); $table->setMargin($padd, $padd, 0, $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(//num 1, array( 'align' => 'right', 'width' => $width_num ) ); $table->setStyleForColumn(//qty 3, array( 'align' => 'right', 'width' => $width_qty ) ); $table->setStyleForColumn(//price 4, array( 'align' => 'right', 'width' => $width_price ) ); $table->setStyleForColumn(//total 5, array( 'align' => 'right', 'width' => $width_total ) ); $table->addRow( ___('#'), ___('Subscription/Product Title'), ___('Qty'), ___('Unit Price'), ___('Total Price')); $num = 0; foreach ($invoice->getItems() as $p) { $item_title = $p->item_title; $options = array(); foreach($p->getOptions() as $optKey => $opt) { $options[] = sprintf('%s: %s', $opt['optionLabel'], is_array($opt['valueLabel']) ? implode(',', $opt['valueLabel']) : $opt['valueLabel']); } if ($options) { $item_title .= sprintf(' (%s)', implode(', ', $options)); } /* @var $p InvoiceItem */ $table->addRow(array( ++$num . '.', $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/2, $padd, 0, $padd); $table->setStyleForColumn(2, array( 'align' => 'right', 'width' => $width_total )); $table->setStyleForColumn(1, array( 'align' => 'right', )); $subtotal = (float) ($this->isFirstPayment() ? $invoice->first_subtotal : $invoice->second_subtotal); $total = (float) ($this->isFirstPayment() ? $invoice->first_total : $invoice->second_total); $discount = (float) ($this->isFirstPayment() ? $invoice->first_discount : $invoice->second_discount); $shipping = (float) ($this->isFirstPayment() ? $invoice->first_shipping : $invoice->second_shipping); $tax = (float) ($this->isFirstPayment() ? $invoice->first_tax : $invoice->second_tax); if ($discount || $shipping) { $table->addRow(___('Subtotal'), $invoice->getCurrency($subtotal)) ->addStyle($styleBold); } if ($discount) { $table->addRow(___('Discount'), $invoice->getCurrency($discount)); } if ($shipping) { $table->addRow(___('Shipping'), $invoice->getCurrency($shipping)); } if ($tax || (Am_Di::getInstance()->plugins_tax->getEnabled() && $this->getDi()->config->get('invoice_always_tax'))) { $table->addRow(___('Taxable Subtotal'), $invoice->getCurrency($subtotal - $discount)); $table->addRow(___('Tax Amount') . sprintf(' (%s%%)', $invoice->tax_rate), $invoice->getCurrency($tax)); } $table->addRow(___('Total'), $invoice->getCurrency($total)) ->addStyle($styleBold); if (!$this->getDi()->config->get('different_invoice_for_refunds') || !(defined('AM_ADMIN') && AM_ADMIN)) { $refunds = $this->getDi()->invoiceRefundTable->findBy(array('invoice_payment_id' => $payment->pk())); if ($refunds) { $refunds_total = 0; foreach ($refunds as $r) { $refunds_total += $r->amount; $table->addRow(___('Refund') . "
" . amDate($r->dattm) . " " . amTime($r->dattm) . "", "-" . $invoice->getCurrency($r->amount)) ->addStyle(array( 'font' => array( 'face' => $fontHB, 'size' => 10))); } $table->addRow(___('Amount Paid'), $invoice->getCurrency(sprintf("%.2f", $payment->amount - $refunds_total))) ->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); $tmpl->assign('payment', $payment); $ifn = $tmpl->render($ifn); $page->nl($pointer); $page->drawTextWithFixedWidth($ifn, $left, $pointer, $this->getPaperWidth() - 2 * $padd); } } return $pdf->render(); } public function renderAccess($page, $pointer) { $invoice = $this->invoice; //if user is not approved there is no access records $accessrecords = $invoice->getAccessRecords(); if (!$accessrecords) { return $pointer; } $payment = $this->payment; $padd = 40; $width_date = 120; $fontHB = $this->getFontBold(); $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(//from 2, array( 'width' => $width_date ) ); $table->setStyleForColumn(//to 3, array( 'width' => $width_date ) ); $table->addRow( ___('Subscription/Product Title'), ___('Begin'), ___('Expire')); $productOptions = $this->getDi()->productTable ->getProductTitles(array_map(function($a) {return $a->product_id;}, $accessrecords)); foreach ($accessrecords as $a) { /* @var $a Access */ if ($a->invoice_payment_id != $payment->pk()) { continue; } $table->addRow($productOptions[$a->product_id], amDate($a->begin_date), ($a->expire_date == Am_Period::MAX_SQL_DATE) ? ___('Lifetime') : ($a->expire_date == Am_Period::RECURRING_SQL_DATE ? ___('Recurring') : amDate($a->expire_date))); } return $page->drawTable($table, 0, $pointer); } }Invoice/InvoiceRefund.php000064400000024752152101613070011417 0ustar00invoice = $refund->getInvoice(); $this->payment = $refund; } 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 = 40; $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 Am_Pdf_Invoice_Col(); $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 Am_Pdf_Invoice_Col(); $rightCol->name = $invoice->getName(); $rightCol->email = $invoice->getEmail(); $rightCol->address = $invoice->getStreet1(); if ($invoice->getStreet2()) { $rightCol->address2 = $invoice->getStreet2(); } $rightCol->city = sprintf("%s, %s %s", $invoice->getCity(), $invoice->getState(), $invoice->getZip()); $rightCol->country = $this->getCountry($invoice); $this->getDi()->hook->call(Am_Event::PDF_INVOICE_COL_RIGHT, array( 'col' => $rightCol, 'invoice' => $invoice, 'payment' => $payment, 'user' => $user )); $lineLength = 0; foreach ($rightCol as $line) { $lineLength = max($lineLength, $page->widthForString($line)); } foreach ($rightCol as $line) { $page->drawText($line, $right - $lineLength, $pointerR, 'UTF-8'); $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, 0, $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(//num 1, array( 'align' => 'right', 'width' => $width_num ) ); $table->setStyleForColumn(//qty 3, array( 'align' => 'right', 'width' => $width_qty ) ); $table->setStyleForColumn(//price 4, array( 'align' => 'right', 'width' => $width_price ) ); $table->setStyleForColumn(//total 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) { $item_title = $p->item_title; $options = array(); foreach($p->getOptions() as $optKey => $opt) { $options[] = sprintf('%s: %s', $opt['optionLabel'], is_array($opt['valueLabel']) ? implode(',', $opt['valueLabel']) : $opt['valueLabel']); } if ($options) { $item_title .= sprintf(' (%s)', implode(', ', $options)); } /* @var $p InvoiceItem */ $table->addRow(array( ++$num . '.', $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/2, $padd, 0, $padd); $table->setStyleForColumn( 2, array( 'align' => 'right', 'width' => $width_total ) ); $table->setStyleForColumn(1, array( 'align' => 'right', )); $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(); } function isFirstPayment() { return $this->getOrigPayment()->isFirst(); } /** * * @return InvoicePayment */ function getOrigPayment() { if (empty($this->origPayment)) { if($this->payment->invoice_payment_id) { $this->origPayment = $this->getDi()->invoicePaymentTable->load($this->payment->invoice_payment_id); } else { // Refund is not assigned to payment, get last payment which was not refunded.. $payments = $this->getDi()->invoicePaymentTable->selectObjects("" . "SELECT p.*, r.invoice_refund_id " . "FROM ?_invoice_payment p LEFT JOIN ?_invoice_refund r " . "ON p.invoice_payment_id = r.invoice_payment_id " . "WHERE p.invoice_id=? AND p.dattm <= ? " . "HAVING r.invoice_refund_id IS NULL " . "ORDER BY p.dattm DESC", $this->payment->invoice_id, $this->payment->dattm); $this->origPayment = $payments[0]; } } return $this->origPayment; } }Invoice.php000064400000000761152101613070006651 0ustar00