cancel
Showing results for 
Search instead for 
Did you mean: 

backend-Invoicegrid not working correctly for mass action

SOLVED

backend-Invoicegrid not working correctly for mass action

Hello,

 

I am facing a problem:

 

I have written an extension for a massaction in the Sales_Order_Invoice_Grid.
When I select an Invoice in the backend and execute the extension I wrote, the extension gets another invoiceobject than I selected in the backend?!?!

has anyone a hint for this problem?

 

<?php
namespace Hebein\Exporter\Controller\Adminhtml\Invoice;
use Magento\Backend\App\Action\Context;
use Magento\Ui\Component\MassAction\Filter;
use Magento\Framework\Controller\ResultFactory;
use Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction;
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;

class massExportInvoice extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction
{
    const ADMIN_RESOURCE = 'Invoice';
    /**
     * @var \Magento\Catalog\Api\ProductRepositoryInterface
     */
    protected $productRepository;

    /**
     * @var \Magento\Ui\Component\MassAction\Filter $filter
     */
    protected $filter;

    /**
     * @var \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory
     */
    protected $collectionfactory;



        public function __construct(Context $context, Filter $filter, CollectionFactory $collection)
            {
                parent::__construct($context, $filter);
                $this->collectionfactory = $collection;
                $this->context=$context;
                $this->filter=$filter;
                }


        protected function massAction(\Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection $in_collection)
        {
                nix;

        }

        public function execute()
        {
                echo "<table style=\"width:100%\" border=\"1\"><tr><th>Invoice#</th><th>order#</th><th>Bezeichnung</th><th>Value</th></tr>";
                $collection = $this->filter->getCollection($this->collectionfactory->create());
                foreach ($collection as $invoice)
                {
                        echo "<tr>";
                        //$order=$invoice->getOrder();
                        //if ($order===null) echo "NULL";
                        //var_dump($taxinfo);
                        echo "<th>". $invoiceID=$invoice->getIncrementId()."</th>";
                        echo "<th> ".$orderID=$invoice->getIncrementID();
                        $adress=$invoice->getShippingAddress();
                        echo "<br/>COUNTRY:   ".$country=$adress->getCountryId();
                        echo "<br/>invoice GT:   ".$gt=$invoice->getGrandTotal();
                        echo "<br/> WHRG:  ".$invoice->getOrderCurrencyCode ()."</th>";
                        echo "</tr>";
                                 echo "<tr><th></th><th></th><th>SHIP INCL TAX: </th><th>".$invoice->getShippingAmount()."</th></tr>";
                                echo "<tr><th></th><th></th><th>SHIP TAX:</th><th> ".$invoice->getShippingTaxAmount()."</th></tr>";
                                echo "<tr><th></th><th></th><th>SHIP TAX PERCENT:</th><th> ".$invoice->getShippingTax()."</th></tr>";
                                echo "<tr><th></th><th></th><th>SHIP TAX PERCENT CALC:</th><th> ".round(($invoice->getShippingTaxAmount()/$invoice->getShippingAmount())*100,0)."</th></tr>";

                        foreach ($invoice->getAllItems() as $item)
                        {
                                echo "<tr><th></th><th></th><th>gBTI:</th><th>".$item->getBaseTaxInvoiced()."</th></tr>";
                                echo "<tr><th></th><th></th><th>gTA:</th><th> ".$item->getTaxAmount()."</th></tr>";
                                //echo "gBTI: ".$item->getBaseTaxInvoiced();
                                //echo "gBTI: ".$item->getBaseTaxInvoiced();
                                echo "<tr><th></th><th></th><th>netto:</th><th> ".$item->getBaseSubtotal()."</th></tr>";
                                echo "<tr><th></th><th></th><th>brutto:</th><th> ".$item->getBaseSubtotalInclTax()."</th></tr>";
                                echo "<tr><th></th><th></th><th>Price incl.</th><th>".$item->getPriceInclTax ()."</th></tr>";
                                echo "<tr><th></th><th></th><th>Price</th><th> ".$item->getPrice ()."</th></tr>";
                                echo "<tr><th></th><th></th><th>ROW TOTAL</th><th>".$item->getRowTotal()."</th></tr>";
                                echo "<tr><th></th><th></th><th>ROW TOTAL incl.</th><th>".$item->getRowTotalInclTax ()."</th></tr>";
                                echo "<tr><th></th><th></th><th>TAX PERCENT</th><th>".$item->getTaxPercent ()."</th></tr>";




                                //getKonto (TAX,COUNTRY,SOURCE);
                        }
                }
                echo "</table>";
        }
}

 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: backend-Invoicegrid not working correctly for mass action

Seems like your system running with di compile.

Please remove generated/code and generated/meatadata folder and try it.

Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

View solution in original post

3 REPLIES 3

Re: backend-Invoicegrid not working correctly for mass action

Hello @kornblumenapo

 

you mention wrong collection factory.

 

use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;

 

Replace with 

use Magento\Sales\Model\ResourceModel\Order\Invoice\CollectionFactory;

 

If it will help you then Mark as Solution.


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: backend-Invoicegrid not working correctly for mass action

Now I get

 

Fatal error: Uncaught TypeError: Argument 3 passed to Hebein\Exporter\Controller\Adminhtml\Invoice\massExportInvoice::__construct() must be an instance of Magento\Sales\Model\ResourceModel\Order\Invoice\CollectionFactory, instance of Magento\Sales\Model\ResourceModel\Order\CollectionFactory given

Re: backend-Invoicegrid not working correctly for mass action

Seems like your system running with di compile.

Please remove generated/code and generated/meatadata folder and try it.

Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer