Categories
CMS Development Magento

Magento 2 Remove Total from report table

I have overridden the Sales report in my custom report file but I want to remove footer which is automatically added that I don’t need how to remove that footerenter image description here

My layout xml file is

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <update handle="reports_sales"/>
    <body>
        <referenceContainer name="page.main.actions">
            <block class="Magento\Backend\Block\Store\Switcher" template="Magento_Backend::store/switcher.phtml"
                   name="store.switcher">
                <action method="setStoreVarName">
                    <argument name="var_name" xsi:type="string">store_ids</argument>
                </action>
                <arguments>
                    <argument name="switch_websites" xsi:type="string">1</argument>
                    <argument name="switch_store_groups" xsi:type="string">1</argument>
                    <argument name="switch_store_views" xsi:type="string">1</argument>
                    <argument name="default_selection_name" xsi:type="string" translate="true">All Websites</argument>
                </arguments>
            </block>
        </referenceContainer>
        <referenceContainer name="footer" remove="true"/>

        <referenceContainer name="content">

            <block class="Magento\Framework\View\Element\Template" template="Vendor_Module::test.phtml" name="mtnotice">

            </block>
            <!--<block class="Vendor/Module\Block\Adminhtml\Sales\MyCustomReport"-->
                   <!--template="Magento_Reports::report/grid/container.phtml" name="sales.report.grid.container">-->
              <!---->
            <block class="Vendor/Module\Block\Adminhtml\Sales\MyCustomReport"
                   template="Magento_Reports::report/grid/container.phtml" name="sales.report.grid.container">

            <block class="Vendor/Module\Block\Adminhtml\Form" name="grid.filter.form">
                    <action method="setFieldVisibility">
                        <argument name="field" xsi:type="string">report_type</argument>
                        <argument name="visibility" xsi:type="string">0</argument>
                    </action>
                    <action method="setFieldVisibility">
                        <argument name="field" xsi:type="string">show_order_statuses</argument>
                        <argument name="visibility" xsi:type="string">0</argument>
                    </action>
                    <action method="setFieldVisibility">
                        <argument name="field" xsi:type="string">order_statuses</argument>
                        <argument name="visibility" xsi:type="string">0</argument>
                    </action>
                </block>
            </block>

        </referenceContainer>
    </body>
</page>

My gird.php file to render grid

<?php

namespace Vendor\Module\Block\Adminhtml\Sales\Mycustomreport;

use Magento\Backend\Block\Widget\Grid\Extended;
use Magento\Backend\Block\Template\Context;
use Magento\Backend\Helper\Data;
use Vendor\Module\Model\MarketingFactory;
use Vendor\Module\Model\MarketingDataFactory;
use Vendor\Module\Model\CancelFactory;
use Vendor\Module\Model\PriceFactory;
use Magento\Framework\Module\Manager;
use Vendor\Module\Block\Adminhtml\Status;


/**
 * Class Grid
 * @package Vendor\Module\Block\Adminhtml\Sales\Mycustomreport
 */
class Grid extends Extended
{

    /**
     * @var bool
     */
    protected $_countTotals = true;
    /**
     * @var \Magento\Framework\Module\Manager
     */
    protected $moduleManager;

    /**
     * @var \Vendor\Module\Model\brandwisereportFactory
     */
    protected $marketingFactory;

    /**
     * @var \Vendor\Module\Model\Status
     */
    protected $marketingDataFactory;

    /**
     * @var CancelFactory
     */
    protected $cancelFactory;
    /**
     * @var PriceFactory
     */
    protected $priceFactory;
    /**
     * @var Status
     */
    protected $options;

    /**
     * @param \Magento\Backend\Block\Template\Context $context
     * @param \Magento\Backend\Helper\Data $backendHelper
     * @param \Vendor\Module\Model\brandwisereportFactory $brandwisereportFactory
     * @param \Vendor\Module\Model\Status $status
     * @param \Magento\Framework\Module\Manager $moduleManager
     * @param array $data
     *
     * @SuppressWarnings(PHPMD.ExcessiveParameterList)
     */
    public function __construct(
        Context $context,
        Data $backendHelper,
        MarketingFactory $marketingFactory,
        MarketingDataFactory $marketingDataFactory,
        CancelFactory $cancelFactory,
        PriceFactory $priceFactory,
        Status $options,

        Manager $moduleManager,

        array $data = []
    )
    {
        $this->marketingFactory = $marketingFactory;
        $this->marketingDataFactory = $marketingDataFactory;
        $this->cancelFactory = $cancelFactory;
        $this->priceFactory = $priceFactory;
        $this->moduleManager = $moduleManager;
        $this->options = $options;
        parent::__construct($context, $backendHelper, $data);
    }

    /**
     * @return void
     */
    protected function _construct()
    {
        parent::_construct();
        $this->setId('id');
        // $this->setDefaultSort('submitdate');
        $this->setDefaultDir('DESC');
        $this->setSaveParametersInSession(true);
        $this->setUseAjax(false);
        //$this->setVarNameFilter('post_filter');
        $this->setFilterVisibility(false);

    }

    /**
     * @return \Magento\Framework\DataObject
     */
    public function getTotals()
    {
        $totals = new \Magento\Framework\DataObject;

        $fields = array(
            'sum_qty_ordered' => 0,
            'base_price' => 0,
            'total_amount' => 0
        );
        foreach ($this->getCollection() as $item) {
            foreach ($fields as $field => $value) {
                $fields[$field] += $item->getData($field);
            }
        }
        $fields['name'] = 'Totals';
        $totals->setData($fields);

        return $totals;
    }


    /**
     * @return $this
     */
    protected function _prepareCollection()
    {
        $filterData = $this->getFilterData();


        //$collection = $this->marketingFactory->create()->getCollection();
        $preApproveNo = $filterData['prapproveno'];
        $claimType = $filterData['claim_type'];
        $frmdate = date('Y-m-d 00:00:00', strtotime($filterData['from']));
        $todate = date('Y-m-d 23:59:59', strtotime($filterData['to']));
        /*
         * claimType = 1 = Marketing
         * claimType = 2 = Price
         */
        $collection = [];
        if(!empty($preApproveNo)) {
            if ($claimType == 1) {
                $collection = $this->marketingFactory->create()->getCollection()
                    ->addFieldToFilter('prapproveno', ['eq' => $preApproveNo])
                    ->addFieldToFilter('submitdate', ['gteq' => $frmdate])
                    ->addFieldToFilter('submitdate', ['lteq' => $todate]);
            } else if ($claimType == 2) {
                $collection = $this->cancelFactory->create()->getCollection()
                    ->addFieldToFilter('prior_number', ['eq' => $preApproveNo])
                    ->addFieldToFilter('submit_date', ['gteq' => $frmdate])
                    ->addFieldToFilter('submit_date', ['lteq' => $todate]);
            }
        }
        else{
            if ($claimType == 1) {
                $collection = $this->marketingFactory->create()->getCollection()
                    ->addFieldToFilter('submitdate', ['gteq' => $frmdate])
                    ->addFieldToFilter('submitdate', ['lteq' => $todate]);
            } else if ($claimType == 2) {
                $collection = $this->cancelFactory->create()->getCollection()
                    ->addFieldToFilter('submit_date', ['gteq' => $frmdate])
                    ->addFieldToFilter('submit_date', ['lteq' => $todate]);
            }
        }

        /********************** This code will apply filter on grid collection *****/
        //$collection->filterOrder();

        $this->setCollection($collection);

        parent::_prepareCollection();

        return $this;
    }

    /**
     * @return $this
     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
     */
    protected function _prepareColumns()
    {
        $filterData = $this->getFilterData();
        $cliamtype = $filterData['claim_type'];

        if ($cliamtype == 1) {

            try {

                $this->addColumn(
                    'prapproveno',
                    [
                        'header' => __('Prior Number'),
                        'index' => 'prapproveno',
                        'filter' => false
                    ]
                );

                $this->addColumn(
                    'submitdate',
                    [
                        'header' => __('Submit Date'),
                        'type' => 'date',
                        'index' => 'submitdate',
                        'filter' => false
                    ]
                );

                $this->addColumn(
                    'status',
                    [
                        'header' => __('Status'),
                        'type' => 'text',
                        'index' => 'status',
                        'values' => $this->options->getOptionArray(),
                        'filter' => false,
                    ]
                );

                $this->addColumn(
                    'chnlmanager',
                    [
                        'header' => __('Chanel Manager'),
                        'type' => 'text',
                        'index' => 'chnlmanager',
                        'filter' => false
                    ]
                );

                $this->addColumn(
                    'company',
                    [
                        'header' => __('Company'),
                        'type' => 'text',
                        'index' => 'company',
                        'values' => [1 => "Microsoft 1", 0 => "Google"],
                        'filter' => false
                    ]
                );

                $this->addColumn(
                    'avpno',
                    [
                        'header' => __('Avp Reseller'),
                        'type' => 'text',
                        'index' => 'avpno',
                        'filter' => false
                    ]
                );
                $this->addColumn(
                    'mttotal',
                    [
                        'header' => __('Total'),
                        'type' => 'text',
                        'index' => 'mttotal',
                        'filter' => false,
                        'renderer' => 'Vendor\Module\Block\Adminhtml\Blog\Renderer\Marketingdata'
                    ]
                );

            } catch (\Exception $e) {

            }
        } else if ($cliamtype == 2) {

            try {

                $this->addColumn(
                    'prior_number',
                    [
                        'header' => __('Prior Number'),
                        'index' => 'prior_number',
                        'filter' => false
                    ]
                );

                $this->addColumn(
                    'submit_date',
                    [
                        'header' => __('Submit Date'),
                        'type' => 'date',
                        'index' => 'submit_date',
                        'filter' => false
                    ]
                );

                $this->addColumn(
                    'status',
                    [
                        'header' => __('Status'),
                        'type' => 'text',
                        'index' => 'status',

                        'filter' => false
                    ]
                );

                $this->addColumn(
                    'chanel_manager',
                    [
                        'header' => __('Chanel Manager'),
                        'type' => 'text',
                        'index' => 'chanel_manager',
                        'filter' => false
                    ]
                );

                $this->addColumn(
                    'company',
                    [
                        'header' => __('Company'),
                        'type' => 'text',
                        'index' => 'company',

                        'filter' => false
                    ]
                );

                $this->addColumn(
                    'avpreseller',
                    [
                        'header' => __('Avp Reseller'),
                        'type' => 'text',
                        'index' => 'avpreseller',
                        'filter' => false
                    ]
                );
                $this->addColumn(
                    'mttotal',
                    [
                        'header' => __('Total value'),
                        'type' => 'text',
                        'index' => 'mttotal',
                        'filter' => false,
                        'renderer' => 'Vendor\Module\Block\Adminhtml\Blog\Renderer\Pricedata'
                    ]
                );


                $this->addColumn(
                    'price_protection_end',
                    [
                        'header' => __('Price Protection End'),
                        'type' => 'text',
                        'index' => 'price_protection_end',
                        'filter' => false
                    ]
                );


            } catch (\Exception $e) {

            }

        }

        $this->addExportType($this->getUrl('marketing/report_sales/ExportMyCustomReportCsv', ['_current' => true]), __('CSV'));
        $this->addExportType($this->getUrl('marketing/report_sales/ExportMyCustomReportExcel', ['_current' => true]), __('Excel XML'));

        return parent::_prepareColumns();
    }


    /**
     * @return string
     */
    public function getGridUrl()
    {
        return $this->getUrl('marketing/*/index', ['_current' => true]);
    }

    /**
     * @param \Vendor\Module\Model\brandwisereport|\Magento\Framework\Object $row
     * @return string
     */
    public function getRowUrl($row)
    {
        return '#';
    }
}

if i remove or comment getTotals() function it gives me error that i already tried. Thank You.

Leave a Reply

Your email address will not be published. Required fields are marked *