Sales_Report - Version 1.0.0

Version Notes

This is the first stable version of the extension.

Download this release

Release Info

Developer Manthan
Extension Sales_Report
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/local/Sitegurus/Pincode/Block/Adminhtml/Pincode.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Sitegurus_Pincode_Block_Adminhtml_Pincode extends Mage_Adminhtml_Block_Widget_Grid_Container
3
+ {
4
+ public function __construct()
5
+ {
6
+ $this->_controller = 'adminhtml_pincode';
7
+ $this->_blockGroup = 'pincode';
8
+ $this->_headerText = Mage::helper('pincode')->__('Pincode Manager');
9
+ $this->_addButtonLabel = Mage::helper('pincode')->__('Add Pincode');
10
+ parent::__construct();
11
+ }
12
+ }
app/code/local/Sitegurus/Pincode/Block/Adminhtml/Pincode/Edit.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Sitegurus_Pincode_Block_Adminhtml_Pincode_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+
9
+ $this->_objectId = 'id';
10
+ $this->_blockGroup = 'pincode';
11
+ $this->_controller = 'adminhtml_pincode';
12
+
13
+ $this->_updateButton('save', 'label', Mage::helper('pincode')->__('Save Pincode'));
14
+ $this->_updateButton('delete', 'label', Mage::helper('pincode')->__('Delete Pincode'));
15
+
16
+ $this->_addButton('saveandcontinue', array(
17
+ 'label' => Mage::helper('adminhtml')->__('Save And Continue Edit'),
18
+ 'onclick' => 'saveAndContinueEdit()',
19
+ 'class' => 'save',
20
+ ), -100);
21
+
22
+ $this->_formScripts[] = "
23
+ function toggleEditor() {
24
+ if (tinyMCE.getInstanceById('pincode_content') == null) {
25
+ tinyMCE.execCommand('mceAddControl', false, 'pincode_content');
26
+ } else {
27
+ tinyMCE.execCommand('mceRemoveControl', false, 'pincode_content');
28
+ }
29
+ }
30
+
31
+ function saveAndContinueEdit(){
32
+ editForm.submit($('edit_form').action+'back/edit/');
33
+ }
34
+ ";
35
+ }
36
+
37
+ public function getHeaderText()
38
+ {
39
+ if( Mage::registry('pincode_data') && Mage::registry('pincode_data')->getId() ) {
40
+ return Mage::helper('pincode')->__("Edit Pincode '%s'", $this->htmlEscape(Mage::registry('pincode_data')->getTitle()));
41
+ } else {
42
+ return Mage::helper('pincode')->__('Add Pincode');
43
+ }
44
+ }
45
+ }
app/code/local/Sitegurus/Pincode/Block/Adminhtml/Pincode/Edit/Form.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Sitegurus_Pincode_Block_Adminhtml_Pincode_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
4
+ {
5
+ protected function _prepareForm()
6
+ {
7
+ $form = new Varien_Data_Form(array(
8
+ 'id' => 'edit_form',
9
+ 'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
10
+ 'method' => 'post',
11
+ 'enctype' => 'multipart/form-data'
12
+ )
13
+ );
14
+
15
+ $form->setUseContainer(true);
16
+ $this->setForm($form);
17
+ return parent::_prepareForm();
18
+ }
19
+ }
app/code/local/Sitegurus/Pincode/Block/Adminhtml/Pincode/Edit/Tab/Form.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Sitegurus_Pincode_Block_Adminhtml_Pincode_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
4
+ {
5
+ protected function _prepareForm()
6
+ {
7
+ $form = new Varien_Data_Form();
8
+ $this->setForm($form);
9
+ $fieldset = $form->addFieldset('pincode_form', array('legend'=>Mage::helper('pincode')->__('Pincode information')));
10
+
11
+ $fieldset->addField('area_name', 'text', array(
12
+ 'label' => Mage::helper('pincode')->__('Area Name'),
13
+ 'class' => 'required-entry',
14
+ 'required' => true,
15
+ 'name' => 'area_name',
16
+ ));
17
+
18
+
19
+
20
+ $fieldset->addField('pin_code', 'text', array(
21
+ 'label' => Mage::helper('pincode')->__('PinCode(Add comma saperated pin codes)'),
22
+ 'class' => 'required-entry',
23
+ 'required' => true,
24
+ 'name' => 'pin_code',
25
+ ));
26
+
27
+
28
+ $fieldset->addField('status', 'select', array(
29
+ 'label' => Mage::helper('pincode')->__('Status'),
30
+ 'name' => 'status',
31
+ 'values' => array(
32
+ array(
33
+ 'value' => 1,
34
+ 'label' => Mage::helper('pincode')->__('Enabled'),
35
+ ),
36
+
37
+ array(
38
+ 'value' => 2,
39
+ 'label' => Mage::helper('pincode')->__('Disabled'),
40
+ ),
41
+ ),
42
+ ));
43
+
44
+
45
+
46
+ if ( Mage::getSingleton('adminhtml/session')->getPincodeData() )
47
+ {
48
+ $form->setValues(Mage::getSingleton('adminhtml/session')->getPincodeData());
49
+ Mage::getSingleton('adminhtml/session')->setPincodeData(null);
50
+ } elseif ( Mage::registry('pincode_data') ) {
51
+ $form->setValues(Mage::registry('pincode_data')->getData());
52
+ }
53
+ return parent::_prepareForm();
54
+ }
55
+ }
app/code/local/Sitegurus/Pincode/Block/Adminhtml/Pincode/Edit/Tabs.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Sitegurus_Pincode_Block_Adminhtml_Pincode_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
4
+ {
5
+
6
+ public function __construct()
7
+ {
8
+ parent::__construct();
9
+ $this->setId('pincode_tabs');
10
+ $this->setDestElementId('edit_form');
11
+ $this->setTitle(Mage::helper('pincode')->__('Pincode Information'));
12
+ }
13
+
14
+ protected function _beforeToHtml()
15
+ {
16
+ $this->addTab('form_section', array(
17
+ 'label' => Mage::helper('pincode')->__('Pincode Information'),
18
+ 'title' => Mage::helper('pincode')->__('Pincode Information'),
19
+ 'content' => $this->getLayout()->createBlock('pincode/adminhtml_pincode_edit_tab_form')->toHtml(),
20
+ ));
21
+
22
+ return parent::_beforeToHtml();
23
+ }
24
+ }
app/code/local/Sitegurus/Pincode/Block/Adminhtml/Pincode/Grid.php ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Sitegurus_Pincode_Block_Adminhtml_Pincode_Grid extends Mage_Adminhtml_Block_Widget_Grid
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+ $this->setId('pincodeGrid');
9
+ $this->setDefaultSort('pincode_id');
10
+ $this->setDefaultDir('ASC');
11
+ $this->setSaveParametersInSession(true);
12
+ }
13
+
14
+ protected function _prepareCollection()
15
+ {
16
+ $collection = Mage::getModel('pincode/pincode')->getCollection();
17
+ $this->setCollection($collection);
18
+ return parent::_prepareCollection();
19
+ }
20
+
21
+ protected function _prepareColumns()
22
+ {
23
+ $this->addColumn('pincode_id', array(
24
+ 'header' => Mage::helper('pincode')->__('ID'),
25
+ 'align' =>'right',
26
+ 'width' => '50px',
27
+ 'index' => 'pincode_id',
28
+ ));
29
+
30
+
31
+ $this->addColumn('area_name', array(
32
+ 'header' => Mage::helper('pincode')->__('Area'),
33
+ 'align' =>'left',
34
+ 'index' => 'area_name',
35
+ ));
36
+
37
+
38
+ $this->addColumn('pin_code', array(
39
+ 'header' => Mage::helper('pincode')->__('PinCode'),
40
+ 'align' =>'left',
41
+ 'index' => 'pin_code',
42
+ ));
43
+
44
+ /*
45
+ $this->addColumn('content', array(
46
+ 'header' => Mage::helper('pincode')->__('Item Content'),
47
+ 'width' => '150px',
48
+ 'index' => 'content',
49
+ ));
50
+ */
51
+
52
+ $this->addColumn('status', array(
53
+ 'header' => Mage::helper('pincode')->__('Status'),
54
+ 'align' => 'left',
55
+ 'width' => '80px',
56
+ 'index' => 'status',
57
+ 'type' => 'options',
58
+ 'options' => array(
59
+ 1 => 'Enabled',
60
+ 2 => 'Disabled',
61
+ ),
62
+ ));
63
+
64
+ $this->addColumn('action',
65
+ array(
66
+ 'header' => Mage::helper('pincode')->__('Action'),
67
+ 'width' => '100',
68
+ 'type' => 'action',
69
+ 'getter' => 'getId',
70
+ 'actions' => array(
71
+ array(
72
+ 'caption' => Mage::helper('pincode')->__('Edit'),
73
+ 'url' => array('base'=> '*/*/edit'),
74
+ 'field' => 'id'
75
+ )
76
+ ),
77
+ 'filter' => false,
78
+ 'sortable' => false,
79
+ 'index' => 'stores',
80
+ 'is_system' => true,
81
+ ));
82
+
83
+ $this->addExportType('*/*/exportCsv', Mage::helper('pincode')->__('CSV'));
84
+ $this->addExportType('*/*/exportXml', Mage::helper('pincode')->__('XML'));
85
+
86
+ return parent::_prepareColumns();
87
+ }
88
+
89
+ protected function _prepareMassaction()
90
+ {
91
+ $this->setMassactionIdField('pincode_id');
92
+ $this->getMassactionBlock()->setFormFieldName('pincode');
93
+
94
+ $this->getMassactionBlock()->addItem('delete', array(
95
+ 'label' => Mage::helper('pincode')->__('Delete'),
96
+ 'url' => $this->getUrl('*/*/massDelete'),
97
+ 'confirm' => Mage::helper('pincode')->__('Are you sure?')
98
+ ));
99
+
100
+ $statuses = Mage::getSingleton('pincode/status')->getOptionArray();
101
+
102
+ array_unshift($statuses, array('label'=>'', 'value'=>''));
103
+ $this->getMassactionBlock()->addItem('status', array(
104
+ 'label'=> Mage::helper('pincode')->__('Change status'),
105
+ 'url' => $this->getUrl('*/*/massStatus', array('_current'=>true)),
106
+ 'additional' => array(
107
+ 'visibility' => array(
108
+ 'name' => 'status',
109
+ 'type' => 'select',
110
+ 'class' => 'required-entry',
111
+ 'label' => Mage::helper('pincode')->__('Status'),
112
+ 'values' => $statuses
113
+ )
114
+ )
115
+ ));
116
+ return $this;
117
+ }
118
+
119
+ public function getRowUrl($row)
120
+ {
121
+ return $this->getUrl('*/*/edit', array('id' => $row->getId()));
122
+ }
123
+
124
+ }
app/code/local/Sitegurus/Pincode/Block/Pincode.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Sitegurus_Pincode_Block_Pincode extends Mage_Core_Block_Template
3
+ {
4
+ public function _prepareLayout()
5
+ {
6
+ return parent::_prepareLayout();
7
+ }
8
+
9
+ public function getPincode()
10
+ {
11
+ if (!$this->hasData('pincode')) {
12
+ $this->setData('pincode', Mage::registry('pincode'));
13
+ }
14
+ return $this->getData('pincode');
15
+
16
+ }
17
+ }
app/code/local/Sitegurus/Pincode/Helper/Data.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Sitegurus_Pincode_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+
6
+ }
app/code/local/Sitegurus/Pincode/Model/Mysql4/Pincode.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Sitegurus_Pincode_Model_Mysql4_Pincode extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ // Note that the pincode_id refers to the key field in your database table.
8
+ $this->_init('pincode/pincode', 'pincode_id');
9
+ }
10
+ }
app/code/local/Sitegurus/Pincode/Model/Mysql4/Pincode/Collection.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Sitegurus_Pincode_Model_Mysql4_Pincode_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('pincode/pincode');
9
+ }
10
+ }
app/code/local/Sitegurus/Pincode/Model/Pincode.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Sitegurus_Pincode_Model_Pincode extends Mage_Core_Model_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('pincode/pincode');
9
+ }
10
+ }
app/code/local/Sitegurus/Pincode/Model/Status.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Sitegurus_Pincode_Model_Status extends Varien_Object
4
+ {
5
+ const STATUS_ENABLED = 1;
6
+ const STATUS_DISABLED = 2;
7
+
8
+ static public function getOptionArray()
9
+ {
10
+ return array(
11
+ self::STATUS_ENABLED => Mage::helper('pincode')->__('Enabled'),
12
+ self::STATUS_DISABLED => Mage::helper('pincode')->__('Disabled')
13
+ );
14
+ }
15
+ }
app/code/local/Sitegurus/Pincode/controllers/Adminhtml/PincodeController.php ADDED
@@ -0,0 +1,370 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ <?php
3
+
4
+ class Sitegurus_Pincode_Adminhtml_PincodeController extends Mage_Adminhtml_Controller_action
5
+ {
6
+
7
+ protected function _initAction() {
8
+ //DebugBreak();
9
+ $this->loadLayout()
10
+ ->_setActiveMenu('pincode/items')
11
+ ->_addBreadcrumb(Mage::helper('adminhtml')->__('Pincode Manager'), Mage::helper('adminhtml')->__('Pincode Manager'));
12
+
13
+ return $this;
14
+ }
15
+
16
+ public function indexAction() {
17
+
18
+ $this->_initAction()
19
+ ->renderLayout();
20
+ }
21
+
22
+ public function salesreportAction() {
23
+
24
+ $this->loadLayout();
25
+
26
+ //create a text block with the name of "example-block"
27
+ $block = $this->getLayout()
28
+ ->createBlock('core/template')
29
+ ->setTemplate('pincode/sales_report.phtml');
30
+
31
+ $this->_addContent($block);
32
+
33
+ $this->renderLayout();
34
+
35
+ }
36
+
37
+
38
+ public function postsalesAction()
39
+ {
40
+ //DebugBreak();
41
+ $post = $this->getRequest()->getPost();
42
+ $area_name = $post['myform']['myfield'];
43
+ try {
44
+ if (empty($post)) {
45
+ Mage::throwException($this->__('Invalid form data.'));
46
+ }
47
+
48
+
49
+ $this->loadLayout();
50
+ $block = $this->getLayout()->createBlock('core/template')->setTemplate('pincode/sales_report.phtml');
51
+ $this->_addContent($block);
52
+ $this->renderLayout();
53
+
54
+ $message = $this->__('Sales orders based on Area are as below:');
55
+ Mage::getSingleton('adminhtml/session')->addSuccess($message);
56
+ } catch (Exception $e) {
57
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
58
+ }
59
+ //$this->_redirect('*/*/salesreport');
60
+ }
61
+
62
+ public function exportordersAction(){
63
+ //DebugBreak();
64
+ $file_path = Mage::getBaseDir().'/var/export/sales_order_export.csv';
65
+ $mage_csv = new Varien_File_Csv();
66
+ $information_row = array();
67
+ $area_name = $this->getRequest()->getParam('area-name');
68
+ $from_date = $this->getRequest()->getParam('from-date');
69
+ $to_date = $this->getRequest()->getParam('to-date');
70
+
71
+ $data[0]['area'] = 'Area';
72
+ $data[0]['date'] = 'Date';
73
+ $data[0]['count'] = 'Total Orders';
74
+ $data[0]['subtotal'] = 'Subtotal';
75
+ $data[0]['invoiced'] = 'Invoiced';
76
+ $data[0]['refunded'] = 'Refunded';
77
+ $data[0]['tax_amount'] = 'Tax amount';
78
+ $data[0]['shipping_amount'] = 'Shipping Amount';
79
+ $data[0]['discounts'] = 'Discounts';
80
+ $data[0]['cancelled'] = 'Cancelled';
81
+
82
+
83
+
84
+ if($area_name == "All Areas"){
85
+ //DebugBreak();
86
+ $collection = Mage::getModel('pincode/pincode')->getCollection();
87
+ $i = 1;
88
+ foreach($collection as $collection_area){
89
+ $area_names[] = $collection_area->getData('area_name');}
90
+ foreach($area_names as $area_name){
91
+
92
+ $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
93
+ $read= Mage::getSingleton('core/resource')->getConnection('core_read');
94
+ $sql1 = "SELECT pin_code FROM pincode where area_name='".$area_name."'";
95
+ $res = $read->fetchRow($sql1);
96
+ $pincode = $res['pin_code'];
97
+ $sql2 = "SELECT count(postcode),email FROM sales_flat_order_address where postcode in (".$pincode.") and address_type='billing' group by sales_flat_order_address.postcode";
98
+ $res1 = $read->fetchRow($sql2);
99
+
100
+ $sql3 = "select count(sales_flat_order_address.postcode),sum(sales_flat_order.subtotal),sum(sales_flat_order.base_subtotal_invoiced),sum(sales_flat_order.subtotal_refunded),sum(sales_flat_order.base_shipping_tax_amount),sum(sales_flat_order.shipping_amount),sum(sales_flat_order.discount_amount),sum(sales_flat_order.subtotal_canceled),date(sales_flat_order.created_at) from sales_flat_order,sales_flat_order_address where sales_flat_order_address.parent_id = sales_flat_order.entity_id and sales_flat_order_address.postcode in (".$pincode.")and sales_flat_order_address.address_type='billing' and date(sales_flat_order.created_at) between '".$from_date."' and '".$to_date."' group by sales_flat_order_address.postcode,date(sales_flat_order.created_at)";
101
+ $ress2 = $read->fetchAll($sql3);
102
+ foreach($ress2 as $res2){
103
+ //DebugBreak();
104
+ $data[$i]['area'] = $area_name;
105
+ $data[$i]['date'] = $res2['date(sales_flat_order.created_at)'];
106
+ $data[$i]['count'] = $res2['count(sales_flat_order_address.postcode)'];
107
+ $data[$i]['subtotal'] = $res2['sum(sales_flat_order.subtotal)'];
108
+ $data[$i]['invoiced'] = $res2['sum(sales_flat_order.base_subtotal_invoiced)'];
109
+ $data[$i]['refunded'] = $res2['sum(sales_flat_order.subtotal_refunded)'];
110
+ $data[$i]['tax_amount'] = $res2['sum(sales_flat_order.base_shipping_tax_amount)'];
111
+ $data[$i]['shipping_amount'] = $res2['sum(sales_flat_order.shipping_amount)'];
112
+ $data[$i]['discounts'] = $res2['sum(sales_flat_order.discount_amount)'];
113
+ $data[$i]['cancelled'] = $res2['sum(sales_flat_order.subtotal_canceled)'];
114
+
115
+
116
+ $orders_placed[] = $res2['count(sales_flat_order_address.postcode)'];
117
+ $subtotal[] = $res2['sum(sales_flat_order.subtotal)'];
118
+ $base_subtotal_invoiced[] = $res2['sum(sales_flat_order.base_subtotal_invoiced)'];
119
+ $subtotal_refunded[] = $res2['sum(sales_flat_order.subtotal_refunded)'];
120
+ $base_shipping_tax_amount[] = $res2['sum(sales_flat_order.base_shipping_tax_amount)'];
121
+ $shipping_amount[] = $res2['sum(sales_flat_order.shipping_amount)'];
122
+ $discount_amount[] = $res2['sum(sales_flat_order.discount_amount)'];
123
+ $subtotal_canceled[] = $res2['sum(sales_flat_order.subtotal_canceled)'];
124
+
125
+ $i++;
126
+ }
127
+ $data[$i]['area'] = 'Total';
128
+ $data[$i]['date'] = ' ';
129
+ $data[$i]['count'] = array_sum($orders_placed);
130
+ $data[$i]['subtotal'] = array_sum($subtotal);
131
+ $data[$i]['invoiced'] = array_sum($base_subtotal_invoiced);
132
+ $data[$i]['refunded'] = array_sum($subtotal_refunded);
133
+ $data[$i]['tax_amount'] = array_sum($base_shipping_tax_amount);
134
+ $data[$i]['shipping_amount'] = array_sum($shipping_amount);
135
+ $data[$i]['discounts'] = array_sum($discount_amount);
136
+ $data[$i]['cancelled'] = array_sum($subtotal_canceled);
137
+
138
+
139
+ }
140
+ foreach($data as $val)
141
+ $information_row[] = $val;
142
+
143
+ }
144
+ else{
145
+ $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
146
+ $read= Mage::getSingleton('core/resource')->getConnection('core_read');
147
+ $sql1 = "SELECT pin_code FROM pincode where area_name='".$area_name."'";
148
+ $res = $read->fetchRow($sql1);
149
+ $pincode = $res['pin_code'];
150
+ $sql2 = "SELECT count(postcode),email FROM sales_flat_order_address where postcode in (".$pincode.") and address_type='billing' group by sales_flat_order_address.postcode";
151
+ $res1 = $read->fetchRow($sql2);
152
+ $sql3 = "select count(sales_flat_order_address.postcode),sum(sales_flat_order.subtotal),sum(sales_flat_order.base_subtotal_invoiced),sum(sales_flat_order.subtotal_refunded),sum(sales_flat_order.base_shipping_tax_amount),sum(sales_flat_order.shipping_amount),sum(sales_flat_order.discount_amount),sum(sales_flat_order.subtotal_canceled),date(sales_flat_order.created_at) from sales_flat_order,sales_flat_order_address where sales_flat_order_address.parent_id = sales_flat_order.entity_id and sales_flat_order_address.postcode in (".$pincode.")and sales_flat_order_address.address_type='billing' and date(sales_flat_order.created_at) between '".$from_date."' and '".$to_date."' group by sales_flat_order_address.postcode,date(sales_flat_order.created_at)";
153
+ $ress2 = $read->fetchAll($sql3);
154
+ $i = 1;
155
+ foreach($ress2 as $res2){
156
+
157
+ $data[$i]['area'] = $area_name;
158
+ $data[$i]['date'] = $res2['date(sales_flat_order.created_at)'];
159
+ $data[$i]['count'] = $res2['count(sales_flat_order_address.postcode)'];
160
+ $data[$i]['subtotal'] = $res2['sum(sales_flat_order.subtotal)'];
161
+ $data[$i]['invoiced'] = $res2['sum(sales_flat_order.base_subtotal_invoiced)'];
162
+ $data[$i]['refunded'] = $res2['sum(sales_flat_order.subtotal_refunded)'];
163
+ $data[$i]['tax_amount'] = $res2['sum(sales_flat_order.base_shipping_tax_amount)'];
164
+ $data[$i]['shipping_amount'] = $res2['sum(sales_flat_order.shipping_amount)'];
165
+ $data[$i]['discounts'] = $res2['sum(sales_flat_order.discount_amount)'];
166
+ $data[$i]['cancelled'] = $res2['sum(sales_flat_order.subtotal_canceled)'];
167
+
168
+
169
+ $orders_placed[] = $res2['count(sales_flat_order_address.postcode)'];
170
+ $subtotal[] = $res2['sum(sales_flat_order.subtotal)'];
171
+ $base_subtotal_invoiced[] = $res2['sum(sales_flat_order.base_subtotal_invoiced)'];
172
+ $subtotal_refunded[] = $res2['sum(sales_flat_order.subtotal_refunded)'];
173
+ $base_shipping_tax_amount[] = $res2['sum(sales_flat_order.base_shipping_tax_amount)'];
174
+ $shipping_amount[] = $res2['sum(sales_flat_order.shipping_amount)'];
175
+ $discount_amount[] = $res2['sum(sales_flat_order.discount_amount)'];
176
+ $subtotal_canceled[] = $res2['sum(sales_flat_order.subtotal_canceled)'];
177
+
178
+ $i++;
179
+ }
180
+
181
+ $data[$i]['area'] = 'Total';
182
+ $data[$i]['date'] = ' ';
183
+ $data[$i]['count'] = array_sum($orders_placed);
184
+ $data[$i]['subtotal'] = array_sum($subtotal);
185
+ $data[$i]['invoiced'] = array_sum($base_subtotal_invoiced);
186
+ $data[$i]['refunded'] = array_sum($subtotal_refunded);
187
+ $data[$i]['tax_amount'] = array_sum($base_shipping_tax_amount);
188
+ $data[$i]['shipping_amount'] = array_sum($shipping_amount);
189
+ $data[$i]['discounts'] = array_sum($discount_amount);
190
+ $data[$i]['cancelled'] = array_sum($subtotal_canceled);
191
+
192
+ foreach($data as $val)
193
+ $information_row[] = $val;
194
+
195
+ }
196
+
197
+ //$data = array();
198
+
199
+
200
+
201
+ $mage_csv->saveData($file_path, $information_row);
202
+ $message = $this->__('CSV is exported');
203
+ Mage::getSingleton('adminhtml/session')->addSuccess($message);
204
+ $this->_redirect('*/*/salesreport');
205
+ }
206
+
207
+ public function editAction() {
208
+ $id = $this->getRequest()->getParam('id');
209
+ $model = Mage::getModel('pincode/pincode')->load($id);
210
+
211
+ if ($model->getId() || $id == 0) {
212
+ $data = Mage::getSingleton('adminhtml/session')->getFormData(true);
213
+ if (!empty($data)) {
214
+ $model->setData($data);
215
+ }
216
+
217
+ Mage::register('pincode_data', $model);
218
+
219
+ $this->loadLayout();
220
+ $this->_setActiveMenu('pincode/items');
221
+
222
+ $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Pincode Manager'), Mage::helper('adminhtml')->__('Pincode Manager'));
223
+ $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Pincode News'), Mage::helper('adminhtml')->__('Pincode News'));
224
+
225
+ $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
226
+
227
+ $this->_addContent($this->getLayout()->createBlock('pincode/adminhtml_pincode_edit'))
228
+ ->_addLeft($this->getLayout()->createBlock('pincode/adminhtml_pincode_edit_tabs'));
229
+
230
+ $this->renderLayout();
231
+ } else {
232
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('pincode')->__('Pincode does not exist'));
233
+ $this->_redirect('*/*/');
234
+ }
235
+ }
236
+
237
+ public function newAction() {
238
+ //DebugBreak();
239
+ //$this->_forward('edit');
240
+ $this->editAction();
241
+ }
242
+
243
+ public function saveAction() {
244
+ if ($data = $this->getRequest()->getPost()) {
245
+
246
+ if(isset($_FILES['filename']['name']) && $_FILES['filename']['name'] != '') {
247
+ try {
248
+ /* Starting upload */
249
+ $uploader = new Varien_File_Uploader('filename');
250
+
251
+ // Any extention would work
252
+ $uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));
253
+ $uploader->setAllowRenameFiles(false);
254
+
255
+ // Set the file upload mode
256
+ // false -> get the file directly in the specified folder
257
+ // true -> get the file in the product like folders
258
+ // (file.jpg will go in something like /media/f/i/file.jpg)
259
+ $uploader->setFilesDispersion(false);
260
+
261
+ // We set media as the upload dir
262
+ $path = Mage::getBaseDir('media') . DS ;
263
+ $uploader->save($path, $_FILES['filename']['name'] );
264
+
265
+ } catch (Exception $e) {
266
+
267
+ }
268
+
269
+ //this way the name is saved in DB
270
+ $data['filename'] = $_FILES['filename']['name'];
271
+ }
272
+
273
+
274
+ $model = Mage::getModel('pincode/pincode');
275
+ $model->setData($data)
276
+ ->setId($this->getRequest()->getParam('id'));
277
+
278
+ try {
279
+ if ($model->getCreatedTime == NULL || $model->getUpdateTime() == NULL) {
280
+ $model->setCreatedTime(now())
281
+ ->setUpdateTime(now());
282
+ } else {
283
+ $model->setUpdateTime(now());
284
+ }
285
+
286
+ $model->save();
287
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('pincode')->__('Pincode was successfully saved'));
288
+ Mage::getSingleton('adminhtml/session')->setFormData(false);
289
+
290
+ if ($this->getRequest()->getParam('back')) {
291
+ $this->_redirect('*/*/edit', array('id' => $model->getId()));
292
+ return;
293
+ }
294
+ $this->_redirect('*/*/');
295
+ return;
296
+ } catch (Exception $e) {
297
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
298
+ Mage::getSingleton('adminhtml/session')->setFormData($data);
299
+ $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
300
+ return;
301
+ }
302
+ }
303
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('pincode')->__('Unable to find Pincode to save'));
304
+ $this->_redirect('*/*/');
305
+ }
306
+
307
+ public function deleteAction() {
308
+ if( $this->getRequest()->getParam('id') > 0 ) {
309
+ try {
310
+ $model = Mage::getModel('pincode/pincode');
311
+
312
+ $model->setId($this->getRequest()->getParam('id'))
313
+ ->delete();
314
+
315
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Pincode was successfully deleted'));
316
+ $this->_redirect('*/*/');
317
+ } catch (Exception $e) {
318
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
319
+ $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
320
+ }
321
+ }
322
+ $this->_redirect('*/*/');
323
+ }
324
+
325
+ public function massDeleteAction() {
326
+ $pincodeIds = $this->getRequest()->getParam('pincode');
327
+ if(!is_array($pincodeIds)) {
328
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select Pincode(s)'));
329
+ } else {
330
+ try {
331
+ foreach ($pincodeIds as $pincodeId) {
332
+ $pincode = Mage::getModel('pincode/pincode')->load($pincodeId);
333
+ $pincode->delete();
334
+ }
335
+ Mage::getSingleton('adminhtml/session')->addSuccess(
336
+ Mage::helper('adminhtml')->__(
337
+ 'Total of %d record(s) were successfully deleted', count($pincodeIds)
338
+ )
339
+ );
340
+ } catch (Exception $e) {
341
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
342
+ }
343
+ }
344
+ $this->_redirect('*/*/index');
345
+ }
346
+
347
+ public function massStatusAction()
348
+ {
349
+ $pincodeIds = $this->getRequest()->getParam('pincode');
350
+ if(!is_array($pincodeIds)) {
351
+ Mage::getSingleton('adminhtml/session')->addError($this->__('Please select Pincode(s)'));
352
+ } else {
353
+ try {
354
+ foreach ($pincodeIds as $pincodeId) {
355
+ $pincode = Mage::getSingleton('pincode/pincode')
356
+ ->load($pincodeId)
357
+ ->setStatus($this->getRequest()->getParam('status'))
358
+ ->setIsMassupdate(true)
359
+ ->save();
360
+ }
361
+ $this->_getSession()->addSuccess(
362
+ $this->__('Total of %d record(s) were successfully updated', count($pincodeIds))
363
+ );
364
+ } catch (Exception $e) {
365
+ $this->_getSession()->addError($e->getMessage());
366
+ }
367
+ }
368
+ $this->_redirect('*/*/index');
369
+ }
370
+ }
app/code/local/Sitegurus/Pincode/controllers/IndexController.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Sitegurus_Pincode_IndexController extends Mage_Core_Controller_Front_Action
3
+ {
4
+ public function indexAction()
5
+ {
6
+ $this->loadLayout();
7
+ $this->renderLayout();
8
+ }
9
+ }
app/code/local/Sitegurus/Pincode/etc/config.xml ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Sitegurus_Pincode>
5
+ <version>0.1.0</version>
6
+ </Sitegurus_Pincode>
7
+ </modules>
8
+ <frontend>
9
+ <routers>
10
+ <pincode>
11
+ <use>standard</use>
12
+ <args>
13
+ <module>Sitegurus_Pincode</module>
14
+ <frontName>pincode</frontName>
15
+ </args>
16
+ </pincode>
17
+ </routers>
18
+ <layout>
19
+ <updates>
20
+ <pincode>
21
+ <file>pincode.xml</file>
22
+ </pincode>
23
+ </updates>
24
+ </layout>
25
+ </frontend>
26
+ <admin>
27
+ <routers>
28
+ <pincode>
29
+ <use>admin</use>
30
+ <args>
31
+ <module>Sitegurus_Pincode</module>
32
+ <frontName>pincode</frontName>
33
+ </args>
34
+ </pincode>
35
+ </routers>
36
+ </admin>
37
+ <adminhtml>
38
+ <menu>
39
+ <pincode module="pincode">
40
+ <title>Manage Areawise Sales Report</title>
41
+ <sort_order>71</sort_order>
42
+ <children>
43
+ <items module="pincode">
44
+ <title>Manage Pincodes</title>
45
+ <sort_order>0</sort_order>
46
+ <action>pincode/adminhtml_pincode</action>
47
+ </items>
48
+
49
+ <manage module="pincode">
50
+ <title>Sales Reports</title>
51
+ <sort_order>1</sort_order>
52
+ <action>pincode/adminhtml_pincode/salesreport</action>
53
+ </manage>
54
+ </children>
55
+ </pincode>
56
+ </menu>
57
+ <acl>
58
+ <resources>
59
+ <all>
60
+ <title>Allow Everything</title>
61
+ </all>
62
+ <admin>
63
+ <children>
64
+ <Sitegurus_Pincode>
65
+ <title>Pincode Module</title>
66
+ <sort_order>10</sort_order>
67
+ </Sitegurus_Pincode>
68
+ </children>
69
+ </admin>
70
+ </resources>
71
+ </acl>
72
+ <layout>
73
+ <updates>
74
+ <pincode>
75
+ <file>pincode.xml</file>
76
+ </pincode>
77
+ </updates>
78
+ </layout>
79
+ </adminhtml>
80
+ <global>
81
+ <models>
82
+ <pincode>
83
+ <class>Sitegurus_Pincode_Model</class>
84
+ <resourceModel>pincode_mysql4</resourceModel>
85
+ </pincode>
86
+ <pincode_mysql4>
87
+ <class>Sitegurus_Pincode_Model_Mysql4</class>
88
+ <entities>
89
+ <pincode>
90
+ <table>pincode</table>
91
+ </pincode>
92
+ </entities>
93
+ </pincode_mysql4>
94
+ </models>
95
+ <resources>
96
+ <pincode_setup>
97
+ <setup>
98
+ <module>Sitegurus_Pincode</module>
99
+ </setup>
100
+ <connection>
101
+ <use>core_setup</use>
102
+ </connection>
103
+ </pincode_setup>
104
+ <pincode_write>
105
+ <connection>
106
+ <use>core_write</use>
107
+ </connection>
108
+ </pincode_write>
109
+ <pincode_read>
110
+ <connection>
111
+ <use>core_read</use>
112
+ </connection>
113
+ </pincode_read>
114
+ </resources>
115
+ <blocks>
116
+ <pincode>
117
+ <class>Sitegurus_Pincode_Block</class>
118
+ </pincode>
119
+ </blocks>
120
+ <helpers>
121
+ <pincode>
122
+ <class>Sitegurus_Pincode_Helper</class>
123
+ </pincode>
124
+ </helpers>
125
+ </global>
126
+ </config>
app/code/local/Sitegurus/Pincode/sql/pincode_setup/mysql4-install-0.1.0.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+
5
+ $installer->startSetup();
6
+
7
+ $installer->run("
8
+
9
+ -- DROP TABLE IF EXISTS {$this->getTable('pincode')};
10
+ CREATE TABLE {$this->getTable('pincode')} (
11
+ `pincode_id` int(11) unsigned NOT NULL auto_increment,
12
+ `area_name` varchar(255) NOT NULL default '',
13
+ `pin_code` varchar(255) NOT NULL default '',
14
+ `status` smallint(6) NOT NULL default '0',
15
+ `created_time` datetime NULL,
16
+ `update_time` datetime NULL,
17
+ PRIMARY KEY (`pincode_id`)
18
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
19
+
20
+ ");
21
+
22
+ $installer->endSetup();
app/design/adminhtml/default/default/layout/pincode.xml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <pincode_adminhtml_pincode_index>
4
+ <reference name="content">
5
+ <block type="pincode/adminhtml_pincode" name="pincode" />
6
+ </reference>
7
+ </pincode_adminhtml_pincode_index>
8
+ <action method="addItem"><type>js_css</type><name>calendar/calendar-win2k-1.css</name><params></params></action>
9
+ <action method="addItem"><type>js</type><name>calendar/calendar.js</name></action>
10
+ <action method="addItem"><type>js</type><name>calendar/calendar-setup.js</name></action>
11
+ <block type="core/html_calendar" name="head.calendar" as="calendar" template="page/js/calendar.phtml"></block>
12
+ </layout>
app/design/adminhtml/default/default/template/pincode/sales_report.phtml ADDED
@@ -0,0 +1,296 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="content-header">
2
+ <table cellspacing="0" class="grid-header">
3
+ <tr>
4
+ <td><h3><?php echo $this->__('Sales Report')?></h3></td>
5
+ <td><button onclick="exportOrders.submit()" class="scalable save" type="button"><span>Export Orders</span></button></td>
6
+ <td class="a-right">
7
+ <button onclick="editForm.submit()" class="scalable save" type="button"><span>Submit to check Sales Report</span></button>
8
+ </td>
9
+ </tr>
10
+ </table>
11
+ </div>
12
+ <div class="entry-edit">
13
+ <form id="edit_form" name="edit_form" method="post" action="<?php echo $this->getUrl('*/*/postsales')?>">
14
+ <input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" />
15
+
16
+ <h4 class="icon-head head-edit-form fieldset-legend"><?php echo$this->__('Insert Area to get sales report')?></h4>
17
+ <fieldset id="my-fieldset">
18
+ <table cellspacing="0" class="form-list">
19
+ <tr>
20
+ <?php
21
+ //DebugBreak();
22
+ $post = $this->getRequest()->getPost();
23
+ ?>
24
+ <td class="label"><?php echo $this->__('Insert Area name')?> <span class="required">*</span></td>
25
+ <td class="input-ele"><select class=" required-entry required-entry select" name="myform[myfield]">
26
+
27
+
28
+
29
+ <option value=""><?php echo $this->__("Please Select")?></option>
30
+ <option value="All Areas" <?php
31
+ $post = $this->getRequest()->getPost();
32
+ if($post){
33
+ $a_name = $post['myform']['myfield'];
34
+
35
+ if($a_name == "All Areas"){?> selected="All Areas"<?php }}?>><?php echo $this->__("All Areas")?></option>
36
+ <?php
37
+ //DebugBreak();
38
+ $collection = Mage::getModel('pincode/pincode')->getCollection();
39
+ foreach($collection as $collection_area){
40
+ $area_name = $collection_area->getData('area_name');
41
+
42
+ ?>
43
+ <option value="<?php echo $area_name?>" <?php
44
+
45
+ $post = $this->getRequest()->getPost();
46
+ if($post){
47
+ $a_name = $post['myform']['myfield'];
48
+
49
+ if($a_name == $area_name){?> selected="<?php echo $area_name?>"<?php }}?>><?php echo $area_name?></option>
50
+ <?php
51
+ }
52
+ ?>
53
+ </select></td>
54
+ </tr>
55
+
56
+ <tr>
57
+
58
+ <td style="padding-bottom: 10px;"><label for="from-date" style="padding-left: 5px;"><?php echo $this->__('From Date') ?></label><span class="required">*</span></td>
59
+ <td>
60
+ <input name="from-date" id="_dob" value="<?php if($post){echo $post['from-date']; }?>" type="text" class="required-entry input-text" style="width:110px !important;">
61
+ <img title="Select date" id="_dob_trig" src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN)."adminhtml/default/default/images/grid-cal.gif";?>" class="v-middle">
62
+
63
+ </td>
64
+ </tr>
65
+
66
+ <tr>
67
+
68
+ <td><label for="to-date" style="padding-left: 5px;"><?php echo $this->__('To Date') ?></label><span class="required">*</span></td>
69
+ <td>
70
+ <input name="to-date" id="_dob1" value="<?php if($post){echo $post['to-date']; }?>" type="text" class="required-entry input-text" style="width:110px !important;">
71
+ <img title="Select date" id="_dob_trig1" src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN)."adminhtml/default/default/images/grid-cal.gif";?>" class="v-middle">
72
+
73
+ </td>
74
+ </tr>
75
+
76
+
77
+ </table>
78
+ </fieldset>
79
+ </form>
80
+
81
+ <?php
82
+ $post = $this->getRequest()->getPost();
83
+ if($post){
84
+ $a_name = $post['myform']['myfield'];
85
+ $from_date = $post['from-date'];
86
+ $to_date = $post['to-date'];
87
+ ?>
88
+
89
+ <form id="export_orders" name="export_orders" method="post" action="<?php echo $this->getUrl('*/*/exportorders')?>">
90
+ <input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" />
91
+
92
+ <input name="area-name" type="hidden" value="<?php echo $a_name; ?>">
93
+ <input name="from-date" type="hidden" value="<?php echo $from_date; ?>">
94
+ <input name="to-date" type="hidden" value="<?php echo $to_date; ?>">
95
+
96
+ </form>
97
+ <?php
98
+ }
99
+ ?>
100
+
101
+ <?php
102
+ function generateRow($area_name,$res2){
103
+ ?>
104
+ <tr class="even pointer">
105
+ <td><?php echo $area_name; ?></td>
106
+ <td><?php echo $res2['date(sales_flat_order.created_at)']; ?>
107
+ <td><?php echo $res2['count(sales_flat_order_address.postcode)']; ?></td>
108
+ <td><?php
109
+ if($res2['sum(sales_flat_order.subtotal)'] == NULL){
110
+ $res2['sum(sales_flat_order.subtotal)'] = 0.0000;
111
+ }
112
+ echo $res2['sum(sales_flat_order.subtotal)']; ?></td>
113
+ <td><?php
114
+ if($res2['sum(sales_flat_order.base_subtotal_invoiced)'] == NULL){
115
+ $res2['sum(sales_flat_order.base_subtotal_invoiced)'] =0.0000;
116
+ }
117
+ echo $res2['sum(sales_flat_order.base_subtotal_invoiced)']; ?></td>
118
+ <td><?php
119
+ if($res2['sum(sales_flat_order.subtotal_refunded)'] == NULL){
120
+ $res2['sum(sales_flat_order.subtotal_refunded)'] = 0.0000;
121
+ }
122
+
123
+ echo $res2['sum(sales_flat_order.subtotal_refunded)']; ?></td>
124
+ <td><?php
125
+ if($res2['sum(sales_flat_order.base_shipping_tax_amount)'] == NULL){
126
+ $res2['sum(sales_flat_order.base_shipping_tax_amount)'] = 0.0000;
127
+ }
128
+ echo $res2['sum(sales_flat_order.base_shipping_tax_amount)']; ?></td>
129
+ <td><?php
130
+ if($res2['sum(sales_flat_order.shipping_amount)'] == NULL){
131
+ $res2['sum(sales_flat_order.shipping_amount)'] = 0.0000;
132
+ }
133
+ echo $res2['sum(sales_flat_order.shipping_amount)']; ?></td>
134
+ <td><?php
135
+ if($res2['sum(sales_flat_order.discount_amount)'] == NULL){
136
+ $res2['sum(sales_flat_order.discount_amount)'] = 0.0000;
137
+ }
138
+ echo $res2['sum(sales_flat_order.discount_amount)']; ?></td>
139
+ <td><?php
140
+ if($res2['sum(sales_flat_order.subtotal_canceled)'] == NULL){
141
+ $res2['sum(sales_flat_order.subtotal_canceled)'] = 0.0000;
142
+ }
143
+
144
+ echo $res2['sum(sales_flat_order.subtotal_canceled)']; ?></td>
145
+
146
+ </tr>
147
+
148
+
149
+ <?php }?>
150
+
151
+ <?php
152
+
153
+ function getPinCode($area_name){
154
+ $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
155
+ $read= Mage::getSingleton('core/resource')->getConnection('core_read');
156
+ $sql1 = "SELECT pin_code FROM pincode where area_name='".$area_name."'";
157
+ $res = $read->fetchRow($sql1);
158
+
159
+ return $res['pin_code'];
160
+ }
161
+
162
+ function getInformation($pincode,$from_date,$to_date){
163
+ //DebugBreak();
164
+ $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
165
+ $read= Mage::getSingleton('core/resource')->getConnection('core_read');
166
+
167
+ $sql3 = "select count(sales_flat_order_address.postcode),sum(sales_flat_order.subtotal),sum(sales_flat_order.base_subtotal_invoiced),sum(sales_flat_order.subtotal_refunded),sum(sales_flat_order.base_shipping_tax_amount),sum(sales_flat_order.shipping_amount),sum(sales_flat_order.discount_amount),sum(sales_flat_order.subtotal_canceled),date(sales_flat_order.created_at) from sales_flat_order,sales_flat_order_address where sales_flat_order_address.parent_id = sales_flat_order.entity_id and sales_flat_order_address.postcode in (".$pincode.")and sales_flat_order_address.address_type='billing' and date(sales_flat_order.created_at) between '".$from_date."' and '".$to_date."' group by sales_flat_order_address.postcode,date(sales_flat_order.created_at)";
168
+ $arr['res2'] = $read->fetchAll($sql3);
169
+ return $arr;
170
+
171
+ }
172
+ ?>
173
+
174
+ <?php
175
+ //DebugBreak();
176
+ $post = $this->getRequest()->getPost();
177
+ if($post){ ?>
178
+
179
+ <div class="grid">
180
+ <table border="1px" style="border: 1px solid #CCCCCC;color: #000000;text-align: center;width: 1287px;">
181
+ <tr class="headings" style="font-weight: bold;">
182
+ <td>Area Name</td>
183
+ <td>Date</td>
184
+ <td>Total Ordered</td>
185
+ <td>Subtotal</td>
186
+ <td>Invoiced</td>
187
+ <td>Refunded</td>
188
+ <td>Tax amount</td>
189
+ <td>Shipping Amount</td>
190
+ <td>Discounts</td>
191
+ <td>Cancelled</td>
192
+
193
+ </tr>
194
+
195
+ <?php
196
+
197
+
198
+ $area_name = $post['myform']['myfield'];
199
+ if($area_name == "All Areas"){
200
+ $area_name = array();
201
+ $collection = Mage::getModel('pincode/pincode')->getCollection();
202
+ foreach($collection as $collection_area){
203
+ $area_names[] = $collection_area->getData('area_name');
204
+
205
+ foreach($area_names as $area_name){
206
+
207
+ $pincode = getPinCode($area_name);
208
+
209
+ $result = getInformation($pincode,$post['from-date'],$post['to-date']);
210
+
211
+ }
212
+
213
+ foreach($result['res2'] as $res){
214
+ $orders_placed[] = $res['count(sales_flat_order_address.postcode)'];
215
+ $subtotal[] = $res['sum(sales_flat_order.subtotal)'];
216
+ $base_subtotal_invoiced[] = $res['sum(sales_flat_order.base_subtotal_invoiced)'];
217
+ $subtotal_refunded[] = $res['sum(sales_flat_order.subtotal_refunded)'];
218
+ $base_shipping_tax_amount[] = $res['sum(sales_flat_order.base_shipping_tax_amount)'];
219
+ $shipping_amount[] = $res['sum(sales_flat_order.shipping_amount)'];
220
+ $discount_amount[] = $res['sum(sales_flat_order.discount_amount)'];
221
+ $subtotal_canceled[] = $res['sum(sales_flat_order.subtotal_canceled)'];
222
+
223
+
224
+ generateRow($area_name,$res);
225
+ }
226
+ }
227
+ }
228
+
229
+ else{
230
+
231
+ $pincode = getPinCode($area_name);
232
+
233
+ $result = getInformation($pincode,$post['from-date'],$post['to-date']);
234
+ foreach($result['res2'] as $res){
235
+
236
+ $orders_placed[] = $res['count(sales_flat_order_address.postcode)'];
237
+ $subtotal[] = $res['sum(sales_flat_order.subtotal)'];
238
+ $base_subtotal_invoiced[] = $res['sum(sales_flat_order.base_subtotal_invoiced)'];
239
+ $subtotal_refunded[] = $res['sum(sales_flat_order.subtotal_refunded)'];
240
+ $base_shipping_tax_amount[] = $res['sum(sales_flat_order.base_shipping_tax_amount)'];
241
+ $shipping_amount[] = $res['sum(sales_flat_order.shipping_amount)'];
242
+ $discount_amount[] = $res['sum(sales_flat_order.discount_amount)'];
243
+ $subtotal_canceled[] = $res['sum(sales_flat_order.subtotal_canceled)'];
244
+
245
+ generateRow($area_name,$res);
246
+ }
247
+ }
248
+ ?>
249
+ <tfoot>
250
+ <tr class="totals">
251
+ <td style="font-weight: bold;">Total</td>
252
+ <td style="font-weight: bold;"></td>
253
+ <td style="font-weight: bold;"><?php echo array_sum($orders_placed); ?></td>
254
+ <td style="font-weight: bold;"><?php echo array_sum($subtotal); ?></td>
255
+ <td style="font-weight: bold;"><?php echo array_sum($base_subtotal_invoiced); ?></td>
256
+ <td style="font-weight: bold;"><?php echo array_sum($subtotal_refunded); ?></td>
257
+ <td style="font-weight: bold;"><?php echo array_sum($base_shipping_tax_amount); ?></td>
258
+ <td style="font-weight: bold;"><?php echo array_sum($shipping_amount); ?></td>
259
+ <td style="font-weight: bold;"><?php echo array_sum($discount_amount); ?></td>
260
+ <td style="font-weight: bold;"><?php echo array_sum($subtotal_canceled); ?></td>
261
+ </tr>
262
+ </tfoot>
263
+ </table>
264
+
265
+ </div>
266
+ <?php
267
+ }
268
+
269
+ ?>
270
+
271
+
272
+ </div>
273
+ <script type="text/javascript">
274
+ var editForm = new varienForm('edit_form');
275
+ var exportOrders = new varienForm('export_orders');
276
+ </script>
277
+
278
+ <script type="text/javascript">
279
+ //<![CDATA[
280
+ Calendar.setup({
281
+ inputField : '_dob',
282
+ ifFormat : '%Y-%m-%e',
283
+ button : '_dob_trig',
284
+ align : 'Bl',
285
+ singleClick : true
286
+ });
287
+
288
+ Calendar.setup({
289
+ inputField : '_dob1',
290
+ ifFormat : '%Y-%m-%e',
291
+ button : '_dob_trig1',
292
+ align : 'Bl',
293
+ singleClick : true
294
+ });
295
+ //]]>
296
+ </script>
app/design/adminhtml/default/default/template/pincode/sales_report_bkp.phtml ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="content-header">
2
+ <table cellspacing="0" class="grid-header">
3
+ <tr>
4
+ <td><h3><?=$this->__('Sales Report')?></h3></td>
5
+ <td class="a-right">
6
+ <button onclick="editForm.submit()" class="scalable save" type="button"><span>Submit to check Sales Report</span></button>
7
+ </td>
8
+ </tr>
9
+ </table>
10
+ </div>
11
+ <div class="entry-edit">
12
+ <form id="edit_form" name="edit_form" method="post" action="<?=$this->getUrl('*/*/postsales')?>">
13
+ <input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" />
14
+
15
+ <h4 class="icon-head head-edit-form fieldset-legend"><?=$this->__('Insert Area to get sales report')?></h4>
16
+ <fieldset id="my-fieldset">
17
+ <table cellspacing="0" class="form-list">
18
+ <tr>
19
+ <td class="label"><?=$this->__('Insert Area name')?> <span class="required">*</span></td>
20
+ <!--<td class="input-ele"><input class="input-text required-entry" name="myform[myfield]" /></td>-->
21
+ <td class="input-ele"><select class=" required-entry required-entry select" name="myform[myfield]">
22
+ <option value=""><?php echo $this->__("Please Select")?></option>
23
+ <?php
24
+ //DebugBreak();
25
+ $collection = Mage::getModel('pincode/pincode')->getCollection();
26
+ foreach($collection as $collection_area){
27
+ $area_name = $collection_area->getData('area_name');
28
+
29
+ ?>
30
+ <option value="<?php echo $area_name?>"><?php echo $area_name?></option>
31
+ <?php
32
+ }
33
+ ?>
34
+ </select></td>
35
+ </tr>
36
+ </table>
37
+ </fieldset>
38
+ </form>
39
+
40
+
41
+ <?php
42
+ //DebugBreak();
43
+ $post = $this->getRequest()->getPost();
44
+ if($post){
45
+ $area_name = $post['myform']['myfield'];
46
+
47
+ $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
48
+ $read= Mage::getSingleton('core/resource')->getConnection('core_read');
49
+
50
+ $sql1 = "SELECT pin_code FROM pincode where area_name='".$area_name."'";
51
+ $res = $read->fetchRow($sql1);
52
+ if($res == FALSE){
53
+ echo "No record found";
54
+ }
55
+ else{
56
+ $pin_codes = explode(',',$res['pin_code']);
57
+
58
+
59
+ $sql2 = "SELECT count(postcode),email FROM sales_flat_order_address where postcode in (".$res['pin_code'].") and address_type='billing'";
60
+ $res1 = $read->fetchRow($sql2);
61
+
62
+
63
+ //DebugBreak();
64
+ $sql3 = "select sum(sales_flat_order.subtotal),sum(sales_flat_order.base_subtotal_invoiced),sum(sales_flat_order.subtotal_refunded),sum(sales_flat_order.base_shipping_tax_amount),sum(sales_flat_order.shipping_amount),sum(sales_flat_order.discount_amount),sum(sales_flat_order.subtotal_canceled) from sales_flat_order,sales_flat_order_address where sales_flat_order_address.parent_id = sales_flat_order.entity_id and sales_flat_order_address.postcode in (".$res['pin_code'].")and sales_flat_order_address.address_type='billing' ";
65
+ $res2 = $read->fetchRow($sql3);
66
+
67
+ ?>
68
+
69
+ <table border="1px" style="border: 1px solid #CCCCCC;color: #000000;text-align: center;width: 1287px;">
70
+ <tr class="headings" style="font-weight: bold;">
71
+ <td>Area Name</td>
72
+ <td>Ordered Items</td>
73
+ <td>Subtotal</td>
74
+ <td>Invoiced</td>
75
+ <td>Refunded</td>
76
+ <td>Tax amount</td>
77
+ <td>Shipping Amount</td>
78
+ <td>Discounts</td>
79
+ <td>Cancelled</td>
80
+ </tr>
81
+
82
+ <tr class="even pointer">
83
+ <td><?php echo $area_name; ?></td>
84
+ <td><?php echo $res1['count(postcode)']; ?></td>
85
+ <td><?php
86
+ if($res2['sum(sales_flat_order.subtotal)'] == NULL){
87
+ $res2['sum(sales_flat_order.subtotal)'] = 0.0000;
88
+ }
89
+ echo $res2['sum(sales_flat_order.subtotal)']; ?></td>
90
+ <td><?php
91
+ if($res2['sum(sales_flat_order.base_subtotal_invoiced)'] == NULL){
92
+ $res2['sum(sales_flat_order.base_subtotal_invoiced)'] =0.0000;
93
+ }
94
+ echo $res2['sum(sales_flat_order.base_subtotal_invoiced)']; ?></td>
95
+ <td><?php
96
+ if($res2['sum(sales_flat_order.subtotal_refunded)'] == NULL){
97
+ $res2['sum(sales_flat_order.subtotal_refunded)'] = 0.0000;
98
+ }
99
+
100
+ echo $res2['sum(sales_flat_order.subtotal_refunded)']; ?></td>
101
+ <td><?php
102
+ if($res2['sum(sales_flat_order.base_shipping_tax_amount)'] == NULL){
103
+ $res2['sum(sales_flat_order.base_shipping_tax_amount)'] = 0.0000;
104
+ }
105
+ echo $res2['sum(sales_flat_order.base_shipping_tax_amount)']; ?></td>
106
+ <td><?php
107
+ if($res2['sum(sales_flat_order.shipping_amount)'] == NULL){
108
+ $res2['sum(sales_flat_order.shipping_amount)'] = 0.0000;
109
+ }
110
+ echo $res2['sum(sales_flat_order.shipping_amount)']; ?></td>
111
+ <td><?php
112
+ if($res2['sum(sales_flat_order.discount_amount)'] == NULL){
113
+ $res2['sum(sales_flat_order.discount_amount)'] = 0.0000;
114
+ }
115
+ echo $res2['sum(sales_flat_order.discount_amount)']; ?></td>
116
+ <td><?php
117
+ if($res2['sum(sales_flat_order.subtotal_canceled)'] == NULL){
118
+ $res2['sum(sales_flat_order.subtotal_canceled)'] = 0.0000;
119
+ }
120
+
121
+ echo $res2['sum(sales_flat_order.subtotal_canceled)']; ?></td>
122
+
123
+ </tr>
124
+ </table>
125
+ <?php
126
+
127
+ }
128
+ }
129
+ ?>
130
+
131
+
132
+ </div>
133
+ <script type="text/javascript">
134
+ var editForm = new varienForm('edit_form');
135
+ </script>
136
+
app/etc/modules/Sitegurus_Pincode.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Sitegurus_Pincode>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ </Sitegurus_Pincode>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Sales_Report</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL) </license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Area Wise Sales Report extension allows admin to add Pin Codes and Areas from admin interface and get the report of total sale in particular area.</summary>
10
+ <description>This extension allows admin to manage (Add/Update/Delete) Pin code and Areas from admin interface and depending on that information admin can have detailed report of the total sell in particular areas with a filter of Date (From - To date).</description>
11
+ <notes>This is the first stable version of the extension.</notes>
12
+ <authors><author><name>Manthan</name><user>manthanext</user><email>manthan18121989@gmail.com</email></author></authors>
13
+ <date>2013-11-21</date>
14
+ <time>07:38:37</time>
15
+ <contents><target name="magelocal"><dir name="Sitegurus"><dir name="Pincode"><dir name="Block"><dir name="Adminhtml"><dir name="Pincode"><dir name="Edit"><file name="Form.php" hash="315e488ed8862b2470a70abfab746adc"/><dir name="Tab"><file name="Form.php" hash="7f7f18b14e3dbed57ab8be5e76e1f93d"/></dir><file name="Tabs.php" hash="a25cd23c11d2bb10916c55de1cd7dee3"/></dir><file name="Edit.php" hash="f801ebe2b94882f92e89608a36911a6a"/><file name="Grid.php" hash="dc2c1d81f216ad8eb4e540d1ff5fbdd6"/></dir><file name="Pincode.php" hash="a04b25b745be2f898d8b6abc258fcb59"/></dir><file name="Pincode.php" hash="3b7e393170fc4aaadf3a02946385eaa0"/></dir><dir name="Helper"><file name="Data.php" hash="e5ee846f31970a8bc322210bae4ceb09"/></dir><dir name="Model"><dir name="Mysql4"><dir name="Pincode"><file name="Collection.php" hash="3f3ab1a36a7867f69ea0ef8a9861d573"/></dir><file name="Pincode.php" hash="df7f84310351d169d2a57bf87f281f9b"/></dir><file name="Pincode.php" hash="910ef76739e2ab23bf6e201a99df7abb"/><file name="Status.php" hash="ab5df1a5f08b8fab1eaaf13a93639057"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="PincodeController.php" hash="1a2d7151886a024f73b2b50166ec3814"/></dir><file name="IndexController.php" hash="2062fb83647d1b55a0c2f1440f0d3520"/></dir><dir name="etc"><file name="config.xml" hash="1afd3c22dc6f762725456ec615633a23"/></dir><dir name="sql"><dir name="pincode_setup"><file name="mysql4-install-0.1.0.php" hash="d97a69e6ccebb9bbf2bf620a6206755f"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="pincode.xml" hash="334c1c090c1232a0c49337d3220aa3b3"/></dir><dir name="template"><dir name="pincode"><file name="sales_report.phtml" hash="c7eb296a83ccda93d816be129eb642fb"/><file name="sales_report_bkp.phtml" hash="01a11687c17b8504180cc43133994242"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Sitegurus_Pincode.xml" hash="b73cfbed670632fc7423c15294d1d5c9"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.0.0</min><max>5.4.0</max></php></required></dependencies>
18
+ </package>