1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34: class Mage_Sales_Model_Order_Pdf_Invoice extends Mage_Sales_Model_Order_Pdf_Abstract
35: {
36: 37: 38: 39: 40: 41:
42: protected function (Zend_Pdf_Page $page)
43: {
44:
45: $this->_setFontRegular($page, 10);
46: $page->setFillColor(new Zend_Pdf_Color_RGB(0.93, 0.92, 0.92));
47: $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
48: $page->setLineWidth(0.5);
49: $page->drawRectangle(25, $this->y, 570, $this->y -15);
50: $this->y -= 10;
51: $page->setFillColor(new Zend_Pdf_Color_RGB(0, 0, 0));
52:
53:
54: $lines[0][] = array(
55: 'text' => Mage::helper('sales')->__('Products'),
56: 'feed' => 35
57: );
58:
59: $lines[0][] = array(
60: 'text' => Mage::helper('sales')->__('SKU'),
61: 'feed' => 290,
62: 'align' => 'right'
63: );
64:
65: $lines[0][] = array(
66: 'text' => Mage::helper('sales')->__('Qty'),
67: 'feed' => 435,
68: 'align' => 'right'
69: );
70:
71: $lines[0][] = array(
72: 'text' => Mage::helper('sales')->__('Price'),
73: 'feed' => 360,
74: 'align' => 'right'
75: );
76:
77: $lines[0][] = array(
78: 'text' => Mage::helper('sales')->__('Tax'),
79: 'feed' => 495,
80: 'align' => 'right'
81: );
82:
83: $lines[0][] = array(
84: 'text' => Mage::helper('sales')->__('Subtotal'),
85: 'feed' => 565,
86: 'align' => 'right'
87: );
88:
89: $lineBlock = array(
90: 'lines' => $lines,
91: 'height' => 5
92: );
93:
94: $this->drawLineBlocks($page, array($lineBlock), array('table_header' => true));
95: $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
96: $this->y -= 20;
97: }
98:
99: 100: 101: 102: 103: 104:
105: public function getPdf($invoices = array())
106: {
107: $this->_beforeGetPdf();
108: $this->_initRenderer('invoice');
109:
110: $pdf = new Zend_Pdf();
111: $this->_setPdf($pdf);
112: $style = new Zend_Pdf_Style();
113: $this->_setFontBold($style, 10);
114:
115: foreach ($invoices as $invoice) {
116: if ($invoice->getStoreId()) {
117: Mage::app()->getLocale()->emulate($invoice->getStoreId());
118: Mage::app()->setCurrentStore($invoice->getStoreId());
119: }
120: $page = $this->newPage();
121: $order = $invoice->getOrder();
122:
123: $this->insertLogo($page, $invoice->getStore());
124:
125: $this->insertAddress($page, $invoice->getStore());
126:
127: $this->insertOrder(
128: $page,
129: $order,
130: Mage::getStoreConfigFlag(self::XML_PATH_SALES_PDF_INVOICE_PUT_ORDER_ID, $order->getStoreId())
131: );
132:
133: $this->insertDocumentNumber(
134: $page,
135: Mage::helper('sales')->__('Invoice # ') . $invoice->getIncrementId()
136: );
137:
138: $this->_drawHeader($page);
139:
140: foreach ($invoice->getAllItems() as $item){
141: if ($item->getOrderItem()->getParentItem()) {
142: continue;
143: }
144:
145: $this->_drawItem($item, $page, $order);
146: $page = end($pdf->pages);
147: }
148:
149: $this->insertTotals($page, $invoice);
150: if ($invoice->getStoreId()) {
151: Mage::app()->getLocale()->revert();
152: }
153: }
154: $this->_afterGetPdf();
155: return $pdf;
156: }
157:
158: 159: 160: 161: 162: 163:
164: public function newPage(array $settings = array())
165: {
166:
167: $page = $this->_getPdf()->newPage(Zend_Pdf_Page::SIZE_A4);
168: $this->_getPdf()->pages[] = $page;
169: $this->y = 800;
170: if (!empty($settings['table_header'])) {
171: $this->_drawHeader($page);
172: }
173: return $page;
174: }
175: }
176: