नई पूरी तरह से कस्टम रिपोर्ट बनाना


22

अधिकांश मैगनेटो रिपोर्ट बिल्डिंग फ़ोरम, ब्लॉग्स, ट्यूटोरियल्स इत्यादि सभी एक मौजूदा मैगनेटो रिपोर्ट लेने पर ध्यान केंद्रित करते हैं और या तो इसे कॉपी या एक्सटेंड करते हैं। इनमें से अधिकांश ग्रिड हैं जो एक विशिष्ट डेटासेट से लिंक करते हैं और उन सभी में मानक फ़िल्टर शामिल हैं जैसे कि / से लेकर तिथि और अवधि (कुछ रिपोर्टों पर प्लस अतिरिक्त फ़िल्टर)।

हालाँकि, कस्टम फ़िल्टर के साथ पूरी तरह से कस्टम रिपोर्ट बनाने के तरीके के बारे में बहुत कम जानकारी है।

उदाहरण के लिए, एक ग्राहक दो कस्टम फ़िल्टर के साथ एक रिपोर्ट चाहेगा जो केवल दो सरल एकत्रित मैट्रिक्स पर रिपोर्ट करता है


1
संसाधनों के लिए सिर्फ एक संदर्भ: stackoverflow.com/questions/7030255/…
B00MER

यहां तक ​​कि मेरे लिए एक ही रिक्त पृष्ठ दिखाने के लिए, कृपया सुझाव दें कि क्या करें।

जवाबों:


22

सबसे पहले, आपको एक कस्टम मॉड्यूल उत्पन्न करने की आवश्यकता है, निम्नलिखित फाइलें बनाएं:

    /app/etc/modules/Mycompany_Mymodule.xml 
    /app/design/adminhtml/default/default/layout/mymodule.xml 
    /app/code/local/Mycompany/Mymodule/Block/adminhtml/Mymodule/Grid.php
    /app/code/local/Mycompany/Mymodule/Block/adminhtml/Mymodule.php 
    /app/code/local/Mycompany/Mymodule/Block/Mymodule.php 
    /app/code/local/Mycompany/Mymodule/controllers/Adminhtml/MymoduleController.php 
    /app/code/local/Mycompany/Mymodule/etc/config.xml 
    /app/code/local/Mycompany/Mymodule/Helper/Data.php 
    /app/code/local/Mycompany/Mymodule/Model/Mymodule.php

/App/etc/modules/Mycompany_Mymodule.xml पर अपने मॉड्यूल को परिभाषित करें :

<?xml version="1.0"?>
<config>
    <modules>
        <Mycompany_Mymodule>
            <active>true</active>
            <codePool>local</codePool>
        </Mycompany_Mymodule>
    </modules>
</config>

लेआउट फ़ाइल को पूरा करें जो व्यवस्थापक दृश्य को अपडेट करेगा (मैं हमेशा ऐसा पहले करता हूं क्योंकि मैं इसे भूलना नहीं चाहता)। /app/design/adminhtml/default/default/layout/mymodule.xml

<?xml version="1.0"?>
<layout version="0.1.0">
    <mymodule_adminhtml_mymodule_index>
        <reference name="content">
            <block type="mymodule/adminhtml_mymodule" name="mymodule" />
        </reference>
    </mymodule_adminhtml_mymodule_index>
</layout>

इस सामग्री /app/code/local/Mycompany/Mymodule/etc/config.xml के साथ कॉन्फ़िगरेशन फ़ाइल बनाएं :

<?xml version="1.0"?>
<!-- 
/**
 * @category   Mycompany
 * @package    Mycompany_Mymodule
 * @author     Damian Alberto Pastorini
 */
 -->
<config>
    <modules>
        <Mycompany_Mymodule>
            <version>0.1.0</version>
        </Mycompany_Mymodule>
    </modules>
    <admin>
        <routers>
            <mymodule>
                <use>admin</use>
                <args>
                    <module>Mycompany_Mymodule</module>
                    <frontName>mymodule</frontName>
                </args>
            </mymodule>
        </routers>
    </admin>
    <adminhtml>
        <menu>
            <report>
                <children>
                    <mymodule translate="title" module="mymodule">
                        <title>Mymodule Report</title>
                        <action>mymodule/adminhtml_mymodule</action>
                    </mymodule>
                </children>
            </report>
        </menu>
        <acl>
            <resources>
                <all>
                    <title>Allow Everything</title>
                </all>
                <admin>
                    <children>
                        <report>
                            <children>
                                <mymodule translate="title" module="mymodule">
                                    <title>Mymodule Report</title>
                                    <action>mymodule/adminhtml_mymodule</action>
                                </mymodule>
                            </children>
                        </report>
                    </children>
                </admin>
            </resources>
        </acl>
        <layout>
            <updates>
                <mymodule>
                    <file>mymodule.xml</file>
                </mymodule>
            </updates>
        </layout>
    </adminhtml>
    <global>
        <models>
            <mymodule>
                <class>Mycompany_Mymodule_Model</class>
                <resourceModel>mymodule</resourceModel>
            </mymodule>
        </models>
        <resources>
            <mymodule_setup>
                <setup>
                    <module>Mycompany_Mymodule</module>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </mymodule_setup>
            <mymodule_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </mymodule_write>
            <mymodule_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </mymodule_read>
        </resources>
        <blocks>
            <mymodule>
                <class>Mycompany_Mymodule_Block</class>
            </mymodule>
        </blocks>
        <helpers>
            <mymodule>
                <class>Mycompany_Mymodule_Helper</class>
            </mymodule>
        </helpers>
    </global>
</config>

यहां हम कंट्रोलर, मेन्यू एक्सेस और परमिशन, मॉडल, ब्लॉक और हेल्पर को परिभाषित करते हैं।

ग्रिड बनाएं और सभी कॉलम /app/code/local/Mycompany/Mymodule/Block/adminhtml/Mymodule/Grid.php निर्दिष्ट करें :

<?php
 class Mycompany_Mymodule_Block_Adminhtml_Mymodule_Grid extends Mage_Adminhtml_Block_Report_Grid {

public function __construct() {
    parent::__construct();
    $this->setId('mymoduleGrid');
    $this->setDefaultSort('created_at');
    $this->setDefaultDir('ASC');
    $this->setSaveParametersInSession(true);
    $this->setSubReportSize(false);
}

protected function _prepareCollection() {
    parent::_prepareCollection();
    $this->getCollection()->initReport('mymodule/mymodule');
    return $this;
}

protected function _prepareColumns() {
    $this->addColumn('ordered_qty', array(
        'header'    =>Mage::helper('reports')->__('Quantity Ordered'),
        'align'     =>'right',
        'index'     =>'ordered_qty',
        'total'     =>'sum',
        'type'      =>'number'
    ));
    $this->addColumn('item_id', array(
        'header' => Mage::helper('mymodule')->__('Item ID'),
        'align' => 'right',
        'index' => 'item_id',
        'type'  => 'number',
        'total' => 'sum',
    ));
    $this->addExportType('*/*/exportCsv', Mage::helper('mymodule')->__('CSV'));
    $this->addExportType('*/*/exportXml', Mage::helper('mymodule')->__('XML'));
    return parent::_prepareColumns();
}

public function getRowUrl($row) {
    return false;
}

public function getReport($from, $to) {
    if ($from == '') {
        $from = $this->getFilter('report_from');
    }
    if ($to == '') {
        $to = $this->getFilter('report_to');
    }
    $totalObj = Mage::getModel('reports/totals');
    $totals = $totalObj->countTotals($this, $from, $to);
    $this->setTotals($totals);
    $this->addGrandTotals($totals);
    return $this->getCollection()->getReport($from, $to);
}
}

यह फ़ाइल स्पष्ट है, लेकिन मैं आपको विशिष्ट लाइनों के बारे में कुछ सुझाव देता हूं:

// यह लाइन डेटा प्राप्त करने के लिए उपयोग करने के लिए मॉडल को इंगित करती है।

$this->getCollection()->initReport('mymodule/mymodule'); // it's used to indicate that this field must be totalized at the end. 
'total' =>'sum', // this is executed when you click on the rows grid, in case you return false (like the example) nothing will happen when you click on the rows grid. 
public function getRowUrl($row) {

अगले चरण के लिए, ग्रिड कंटेनर ब्लॉक बनाएं /app/code/local/Mycompany/Mymodule/Block/adminhtml/Mymodule.php :

<?php
 class Mycompany_Mymodule_Block_Adminhtml_Mymodule extends Mage_Adminhtml_Block_Widget_Grid_Container {

public function __construct() {
    $this->_controller = 'adminhtml_mymodule';
    $this->_blockGroup = 'mymodule';
    $this->_headerText = Mage::helper('mymodule')->__('Mymodule Report');
    parent::__construct();
    $this->_removeButton('add');
}
}

यहाँ हम ऐड बटन को हटाने के लिए इस लाइन को जोड़ते हैं: // यह हमेशा parent::__construct();लाइन के बाद होना चाहिए ।$this->_removeButton('add');

ब्लॉक कंटेनर /app/code/local/Mycompany/Mymodule/Block/Mymodule.php बनाएँ :

<?php
 class Mycompany_Mymodule_Block_Mymodule extends Mage_Core_Block_Template {

public function _prepareLayout() {
    return parent::_prepareLayout();
}

public function getMymodule() {
    if (!$this->hasData('mymodule')) {
        $this->setData('mymodule', Mage::registry('mymodule'));
    }
    return $this->getData('mymodule');
} 
}

नियंत्रक /app/code/local/Mycompany/Mymodule/controllers/Adminhtml/MymoduleController.php बनाएं :

<?php

 class Mycompany_Mymodule_Adminhtml_MymoduleController extends Mage_Adminhtml_Controller_Action {

protected function _initAction() {
    $this->loadLayout();
    return $this;
}

public function indexAction() {
    $this->_initAction()
            ->renderLayout();
}

public function exportCsvAction() {
    $fileName = 'mymodule.csv';
    $content = $this->getLayout()->createBlock('mymodule/adminhtml_mymodule_grid')
                    ->getCsv();
    $this->_sendUploadResponse($fileName, $content);
}

public function exportXmlAction() {
    $fileName = 'mymodule.xml';
    $content = $this->getLayout()->createBlock('mymodule/adminhtml_mymodule_grid')
                    ->getXml();
    $this->_sendUploadResponse($fileName, $content);
}

protected function _sendUploadResponse($fileName, $content, $contentType='application/octet-stream') {
    $response = $this->getResponse();
    $response->setHeader('HTTP/1.1 200 OK', '');
    $response->setHeader('Pragma', 'public', true);
    $response->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
    $response->setHeader('Content-Disposition', 'attachment; filename=' . $fileName);
    $response->setHeader('Last-Modified', date('r'));
    $response->setHeader('Accept-Ranges', 'bytes');
    $response->setHeader('Content-Length', strlen($content));
    $response->setHeader('Content-type', $contentType);
    $response->setBody($content);
    $response->sendResponse();
    die;
}
}

फिर खाली सहायक /app/code/local/Mycompany/Mymodule/Helper/Data.php :

<?php
class Mycompany_Mymodule_Helper_Data extends Mage_Core_Helper_Abstract
{

}

और अंतिम के लिए हम मॉडल बनाते हैं जो डेटा /app/code/local/Mycompany/Mymodule/Model/Mymodule.php लाएगा :

 <?php
    class Mycompany_Mymodule_Model_Mymodule extends Mage_Reports_Model_Mysql4_Order_Collection
{
    function __construct() {
        parent::__construct();
        $this->setResourceModel('sales/order_item');
        $this->_init('sales/order_item','item_id');
   }

    public function setDateRange($from, $to) {
        $this->_reset();
        $this->getSelect()
             ->joinInner(array(
                 'i' => $this->getTable('sales/order_item')),
                 'i.order_id = main_table.entity_id'
                 )
             ->where('i.parent_item_id is null')
             ->where("i.created_at BETWEEN '".$from."' AND '".$to."'")
             ->where('main_table.state = \'complete\'')
             ->columns(array('ordered_qty' => 'count(distinct `main_table`.`entity_id`)'));
        // uncomment next line to get the query log:
        // Mage::log('SQL: '.$this->getSelect()->__toString());
        return $this;
    }

    public function setStoreIds($storeIds)
    {
        return $this;
    }

    }
    ?>

यह एक कस्टम मॉडल है जो मैगेंटो कोर मॉडल से डेटा प्राप्त करता है, यहां आप किसी भी मॉडल को परिभाषित कर सकते हैं या यदि आपको पहले से ही अपना डीबी / टेबल मिल गया है, तो आप इसे से रिपोर्ट डेटा प्राप्त कर सकते हैं। // यह पंक्ति डिफ़ॉल्ट रूप से आने वाली मूल क्वेरी को रीसेट करती है।$this->_reset();

मैंने इन सभी फ़ाइलों को जोड़ने की कोशिश की लेकिन एक बार जब मैं रिपोर्ट के नए मेनू आइटम पर क्लिक करता हूं तो एक खाली पृष्ठ दिखाई देता है।


1
यह खाली पृष्ठ दिखा रहा है। इसे हल करने के लिए कोई विचार?
502_गीक

यह किसी रिक्त पृष्ठ के साथ कोई अद्यतन करता है?
येहुडा श्वार्ट्ज

बस एक संपादन में डाल दिया और महसूस किया कि मैं एक बेवकूफ हूँ! कृपया इसे स्वीकार न करें :)
Wildcard27

किसी ने इस रिक्त पृष्ठ समस्या को हल किया?
जॉन फोंसेका

मैं बिक्री आदेश आइटम रिपोर्ट उत्पन्न करना चाहता हूं कि मुझे क्या बदलाव करना है?
जिग्स परमार

1

नीचे दिए गए पथ के अनुसार फ़ोल्डर adminhtmlका नाम बदलें Adminhtml:

एप्लिकेशन / कोड / स्थानीय / mycompany / Mymodule / ब्लॉक / adminhtml / Mymodule.php

हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.