3

I'm assuming invoice.php is the correct file. I want to have the discounts as line items instead of the aggregate total near the order totals. Where does this pull from?

protected function _drawHeader(Zend_Pdf_Page $page)
    {
        /* Add table head */
        $this->_setFontRegular($page, 10);
        $page->setFillColor(new Zend_Pdf_Color_RGB(0.93, 0.92, 0.92));
        $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
        $page->setLineWidth(0.5);
        $page->drawRectangle(25, $this->y, 570, $this->y -15);
        $this->y -= 10;
        $page->setFillColor(new Zend_Pdf_Color_RGB(0, 0, 0));

        //columns headers
        $lines[0][] = array(
            'text' => Mage::helper('sales')->__('Products'),
            'feed' => 35
        );

        $lines[0][] = array(
            'text'  => Mage::helper('sales')->__('SKU'),
            'feed'  => 290,
            'align' => 'right'
        );

        $lines[0][] = array(
            'text'  => Mage::helper('sales')->__('Qty'),
            'feed'  => 435,
            'align' => 'right'
        );

        $lines[0][] = array(
            'text'  => Mage::helper('sales')->__('Price'),
            'feed'  => 360,
            'align' => 'right'
        );

        $lines[0][] = array(
            'text'  => Mage::helper('sales')->__('Tax'),
            'feed'  => 495,
            'align' => 'right'
        );

        $lines[0][] = array(
            'text'  => Mage::helper('sales')->__('Subtotal'),
            'feed'  => 565,
            'align' => 'right'
        );

        $lineBlock = array(
            'lines'  => $lines,
            'height' => 5
        );

        $this->drawLineBlocks($page, array($lineBlock), array('table_header' => true));
        $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
        $this->y -= 20;
    }

1 Answer 1

1

First change your header

Change this

   $lines[0][] = array(
       'text'  => Mage::helper('sales')->__('Subtotal'),
       'feed'  => 565,
       'align' => 'right'
   );

to this

   $lines[0][] = array(
       'text'  => Mage::helper('sales')->__('Discount'),
       'feed'  => 565,
       'align' => 'right'
   );

and then in this file app/code/core/Mage/Sales/Model/Order/Pdf/Items/Invoice/Default.php in the method draw()

change this

   foreach ($prices as $priceData){
       if (isset($priceData['label'])) {
           // draw Price label
           $lines[$i][] = array(
               'text'  => $priceData['label'],
               'feed'  => $feedPrice,
               'align' => 'right'
           );
           // draw Subtotal label
           $lines[$i][] = array(
               'text'  => $priceData['label'],
               'feed'  => $feedSubtotal,
               'align' => 'right'
           );
           $i++;
       }
       // draw Price
       $lines[$i][] = array(
           'text'  => $priceData['price'],
           'feed'  => $feedPrice,
           'font'  => 'bold',
           'align' => 'right'
       );
       // draw Subtotal
       $lines[$i][] = array(
           'text'  => $priceData['subtotal'],
           'feed'  => $feedSubtotal,
           'font'  => 'bold',
           'align' => 'right'
       );
       $i++;
   }

to this (disable printing the subtotals)

   foreach ($prices as $priceData){
       if (isset($priceData['label'])) {
           // draw Price label
           $lines[$i][] = array(
               'text'  => $priceData['label'],
               'feed'  => $feedPrice,
               'align' => 'right'
           );
           $i++;
       }
       // draw Price
       $lines[$i][] = array(
           'text'  => $priceData['price'],
           'feed'  => $feedPrice,
           'font'  => 'bold',
           'align' => 'right'
       );
       $i++;
   }

and add this after the // draw Tax code block (this will print the discount)

   // draw discount
   $lines[0][] = array(
       'text'  => $item->getData('discount_amount'),
       'feed'  => 565,
       'font'  => 'bold',
       'align' => 'right'
   );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.