Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
daim2k5 committed Jun 2, 2013
2 parents 550dc77 + 85889ef commit d95d990
Show file tree
Hide file tree
Showing 17 changed files with 1,179 additions and 619 deletions.
114 changes: 114 additions & 0 deletions app/code/community/FireGento/Pdf/Block/Adminhtml/ColumnOrder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php
/**
* Firegento
*
* @category Block
* @package FireGento_Pdf
* @author FireGento Team <team@firegento.com>
* @copyright 2013 FireGento Team (http://www.firegento.de). All rights served.
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
class Firegento_Pdf_Block_Adminhtml_ColumnOrder
extends Mage_Adminhtml_Block_System_Config_Form_Field
{
protected $sortableListHtml = '';

protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
{
return '
<style>.orderable_config li {list-style: disc inside; cursor:move;}</style>
<p>' . $this->__('Define the order by moving the following items using your mouse:') . '<p>
<ul id="' . $element->getHtmlId() . '_list" class="orderable_config">
' . $this->_getSortableListHtml($element) . '
</ul>
<input type="hidden" value="' . $element->getValue() . '" name="' . $element->getName() . '" id="' . $element->getHtmlId() . '">
<script type="text/javascript">
Sortable.create("' . $element->getHtmlId() . '_list", {
onUpdate: function() {
var inheritCheckbox = $("' . $element->getHtmlId() . '_inherit");
if (inheritCheckbox) {
inheritCheckbox.checked=false;
}
var newOrder="";
$A(this.element.children).each(function(item){
var current = $(item).attributes["data-column"].value;
if ("disabled" == current) {
$("' . $element->getHtmlId() . '").value = newOrder;
} else {
if (0 < newOrder.length) {
newOrder+=",";
}
newOrder+=current;
}
});
validateSortableWidth();
}
});
validateSortableWidth = function () {
var newWidth=0;
console.log("Calculation columns width");
$A($("' . $element->getHtmlId() . '_list").children).each(function(item){
var current = $(item).attributes["data-column"].value;
if ($(item.attributes["data-width"])) {
newWidth += parseInt($(item).attributes["data-width"].value);
} else if ("disabled" == current) {
console.log(newWidth);
if (240 < newWidth) {
$("' . $element->getHtmlId() . '_warning").innerHTML = "' . $this->__('Caution: Your columns may overlap!') . '";
$("' . $element->getHtmlId() . '_warning").show();
} else {
$("' . $element->getHtmlId() . '_warning").hide();
}
}
});
};
validateSortableWidth();
</script>
';
}

protected function _getSortableListHtml(Varien_Data_Form_Element_Abstract $element)
{
$availableItems = array(
'price_incl_tax' => array('width' => 60, 'label' => $this->__('Price (incl. tax)')),
'price' => array('width' => 60, 'label' => $this->__('Price')),
'qty' => array('width' => 40, 'label' => $this->__('Qty')),
'subtotal_incl_tax' => array('width' => 70, 'label' => $this->__('Subtotal (incl. tax)')),
'subtotal' => array('width' => 50, 'label' => $this->__('Subtotal')),
'tax' => array('width' => 50, 'label' => $this->__('Tax amount')),
'tax_rate' => array('width' => 50, 'label' => $this->__('Tax rate')),
);
$activeItems = array();
foreach (explode(',', $element->getValue()) as $item) {
$item = trim($item);
if (array_key_exists($item, $availableItems)) {
$activeItems[$item] = $availableItems[$item];
unset($availableItems[$item]);
}
}

$this->_addListItems($activeItems);
$this->sortableListHtml .= '<li id="pdf-column-disabled" data-column="disabled" style="list-style:none">
<div id="' . $element->getHtmlId() . '_warning" style="display:none" class="validation-advice"></div>
<br />
' . $this->__('not to be listed') . '
</li>';
$this->_addListItems($availableItems);

return $this->sortableListHtml;
}

protected function _addListItems($items)
{
foreach ($items as $name=>$item) {
$this->sortableListHtml .= sprintf(
'<li id="pdf-column-%s" data-column="%s" data-width="%s">%s</li>',
$name,
$name,
$item['width'],
$item['label']
);
}
return $this;
}
}
153 changes: 16 additions & 137 deletions app/code/community/FireGento/Pdf/Model/Creditmemo.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,156 +31,35 @@
* @version $Id:$
* @since 0.1.0
*/
class FireGento_Pdf_Model_Creditmemo extends FireGento_Pdf_Model_Abstract
class FireGento_Pdf_Model_Creditmemo
{

public function __construct()
{
parent::__construct();
$this->setMode('creditmemo');
}

/**
* Return PDF document
*
* @param array $creditmemos
* @return Zend_Pdf
* The actual PDF engine responsible for rendering the file.
* @var Mage_Sales_Model_Order_Pdf_Abstract
*/
public function getPdf($creditmemos = array())
{
$this->_beforeGetPdf();
$this->_initRenderer('creditmemo');

$pdf = new Zend_Pdf();
$this->_setPdf($pdf);

$style = new Zend_Pdf_Style();
$this->_setFontBold($style, 10);

// pagecounter is 0 at the beginning, because it is incremented in newPage()
$this->pagecounter = 0;

foreach ($creditmemos as $creditmemo) {
if ($creditmemo->getStoreId()) {
Mage::app()->getLocale()->emulate($creditmemo->getStoreId());
Mage::app()->setCurrentStore($creditmemo->getStoreId());
}
$page = $this->newPage();
private $_engine;

$order = $creditmemo->getOrder();

// Add logo
$this->insertLogo($page, $creditmemo->getStore());

// Add billing address
$this->y = 692;
$this->insertBillingAddress($page, $order);

// Add sender address
$this->y = 705;
$this->_insertSenderAddessBar($page);

// Add head
$this->y = 592;
$this->insertHeader($page, $order, $creditmemo);

// Add footer
$this->_addFooter($page, $creditmemo->getStore());

/* Add table head */
$this->_setFontRegular($page, 9);
$this->y = 562;
$this->_drawHeader($page);

$this->y -=20;

$position = 0;
protected function getEngine()
{
if (!$this->_engine) {
$modelClass = Mage::getStoreConfig('sales_pdf/creditmemo/engine');
$engine = Mage::getModel($modelClass);

/* Add body */
foreach ($creditmemo->getAllItems() as $item){
if ($item->getOrderItem()->getParentItem()) {
continue;
}
/* Draw item */
$position++;
$this->_drawItem($item, $page, $order, $position);
$page = end($pdf->pages);
if (!$engine) {
// Fallback to Magento standard creditmemo layout.
$engine = new Mage_Sales_Model_Order_Pdf_Creditmemo();
}

/* add line after items */
$page->drawLine($this->margin['left'], $this->y + 5, $this->margin['right'], $this->y + 5);

/* Add totals */
$page = $this->insertTotals($page, $creditmemo);

/* add note */
$page = $this->_insertNote($page, $order, $creditmemo);
$this->_engine = $engine;
}

$this->_afterGetPdf();

if ($creditmemo->getStoreId()) {
Mage::app()->getLocale()->revert();
}
return $pdf;
return $this->_engine;
}

/**
* Draw table header for product items
*
* @param Zend_Pdf_Page $page
* @return void
*/
protected function _drawHeader(Zend_Pdf_Page $page)
{
$page->setFillColor($this->colors['grey1']);
$page->setLineColor($this->colors['grey1']);
$page->setLineWidth(1);
$page->drawRectangle($this->margin['left'], $this->y, $this->margin['right'], $this->y - 15);

$page->setFillColor($this->colors['black']);
$font = $this->_setFontRegular($page, 9);

$this->y -= 11;
$page->drawText(Mage::helper('firegento_pdf')->__('Pos'), $this->margin['left'] + 3, $this->y, $this->encoding);
$page->drawText(Mage::helper('firegento_pdf')->__('No.'), $this->margin['left'] + 25, $this->y, $this->encoding);
$page->drawText(Mage::helper('firegento_pdf')->__('Description'), $this->margin['left'] + 120, $this->y, $this->encoding);

$singlePrice = Mage::helper('firegento_pdf')->__('Price (excl. tax)');
$page->drawText($singlePrice, $this->margin['right'] - 153 - $this->widthForStringUsingFontSize($singlePrice, $font, 9), $this->y, $this->encoding);

$page->drawText(Mage::helper('firegento_pdf')->__('Qty'), $this->margin['left'] + 360, $this->y, $this->encoding);

$taxLabel = Mage::helper('firegento_pdf')->__('Tax');
$page->drawText($taxLabel, $this->margin['right'] - 65 - $this->widthForStringUsingFontSize($taxLabel, $font, 9), $this->y, $this->encoding);

$totalLabel = Mage::helper('firegento_pdf')->__('Total');
$page->drawText($totalLabel, $this->margin['right'] - 10 - $this->widthForStringUsingFontSize($totalLabel, $font, 10), $this->y, $this->encoding);
}

/**
* Initialize renderer process.
*
* @param string $type
* @return void
*/
protected function _initRenderer($type)
public function getPdf($creditmemos = array())
{
parent::_initRenderer($type);

$this->_renderers['default'] = array(
'model' => 'firegento_pdf/items_default',
'renderer' => null
);
$this->_renderers['grouped'] = array(
'model' => 'firegento_pdf/items_grouped',
'renderer' => null
);
$this->_renderers['bundle'] = array(
'model' => 'firegento_pdf/items_bundle',
'renderer' => null
);
return $this->getEngine()->getPdf($creditmemos);
}

}

Loading

0 comments on commit d95d990

Please sign in to comment.