Cybernetikz_Salesreport - Version 0.1.0

Version Notes

Custom Reporting with Product and Billing/Shipping info. Easy searchable option by order date and status.

Download this release

Release Info

Developer CyberNetikz
Extension Cybernetikz_Salesreport
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

app/code/local/Cybernetikz/Salesreport/Helper/Data.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Author : Cybernetikz
4
+ * Author Email: info@cybernetikz.com
5
+ * Blog : http://blog.cybernetikz.com
6
+ * Website : http://www.cybernetikz.com
7
+ */
8
+
9
+ class Cybernetikz_Salesreport_Helper_Data extends Mage_Core_Helper_Abstract {
10
+ const REPORT_NAME = "salesreports/reportsetting/report_name";
11
+ const REPORT_ADDRESS = "salesreports/reportsetting/report_address";
12
+
13
+ public function getReportName($store = null){
14
+ return Mage::getStoreConfig(self::REPORT_NAME, $store);
15
+ }
16
+
17
+ public function getReportAddress($store = null){
18
+ return Mage::getStoreConfig(self::REPORT_ADDRESS, $store);
19
+ }
20
+ }
app/code/local/Cybernetikz/Salesreport/Model/Address.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Author : Cybernetikz
4
+ * Author Email: info@cybernetikz.com
5
+ * Blog : http://blog.cybernetikz.com
6
+ * Website : http://www.cybernetikz.com
7
+ */
8
+
9
+ class Cybernetikz_Salesreport_Model_Address {
10
+ public function toOptionArray()
11
+ {
12
+ return array(
13
+ array('value'=>'billing', 'label'=>Mage::helper('salesreport')->__('Billing Address')),
14
+ array('value'=>'shipping', 'label'=>Mage::helper('salesreport')->__('Shipping Address'))
15
+ );
16
+ }
17
+ }
app/code/local/Cybernetikz/Salesreport/controllers/Adminhtml/SalesController.php ADDED
@@ -0,0 +1,213 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Author : Cybernetikz
4
+ * Author Email: info@cybernetikz.com
5
+ * Blog : http://blog.cybernetikz.com
6
+ * Website : http://www.cybernetikz.com
7
+ */
8
+
9
+ class Cybernetikz_Salesreport_Adminhtml_SalesController extends Mage_Adminhtml_Controller_Action
10
+ {
11
+ public function indexAction()
12
+ {
13
+ $this->loadLayout()->renderLayout();
14
+ }
15
+
16
+ public function reportmanageAction()
17
+ {
18
+ $this->loadLayout()->renderLayout();
19
+ }
20
+
21
+ public function exportCsvAction()
22
+ {
23
+ if ($data = $this->getRequest()->getPost()) {
24
+
25
+ $orserstatus = "";
26
+
27
+ /*====================== Start Code for magento Orders product =====================*/
28
+ //echo "<pre>";
29
+ $reportaddress = Mage::helper('salesreport')->getReportAddress();
30
+ $addtess_title = ($reportaddress=="billing")?"Billing":"Shipping";
31
+ $orders_csv_row ="Period,Order Id,Item Name,Qty,Unit Price,Row Total,$addtess_title Name,Email,Street Address,City,State,Postcode,Country";
32
+ $orders_csv_row.="\n";
33
+
34
+ $to=$_REQUEST['to'];
35
+ $from=$_REQUEST['from'];
36
+
37
+ $to_date = date('Y-m-d' . ' 00:00:00', strtotime($to));
38
+ $from_date = date('Y-m-d' . ' 00:00:00', strtotime($from));
39
+
40
+
41
+ if($_REQUEST['show_order_statuses']>0){
42
+ $orserstatus = $_REQUEST['order_statuses'];
43
+ $orders = Mage::getResourceModel('sales/order_collection')
44
+ ->addAttributeToSelect('*')
45
+ ->addFieldToFilter('created_at', array('from'=>$from_date, 'to'=>$to_date))
46
+ ->addFieldToFilter('status', $orserstatus)
47
+ ->load();
48
+ }else{
49
+ $orders = Mage::getResourceModel('sales/order_collection')
50
+ ->addAttributeToSelect('*')
51
+ ->addFieldToFilter('created_at', array('from'=>$from_date, 'to'=>$to_date))
52
+ ->load();
53
+ }
54
+
55
+ $i=0;
56
+ foreach($orders as $key=>$single_order) {
57
+ //print_r($single_order);
58
+ //exit;
59
+ $thisId = $single_order->getId();
60
+ $myOrder=Mage::getModel('sales/order');
61
+ $myOrder->load($thisId);
62
+
63
+ //Some random fields
64
+ if($reportaddress=="billing"){
65
+
66
+ $country_id = utf8_decode($myOrder->getBillingAddress()->getCountryId());
67
+ $country = Mage::getModel('directory/country')->load($country_id)->getName();
68
+
69
+ $name = utf8_decode($myOrder->getBillingAddress()->getFirstname()." ".$myOrder->getBillingAddress()->getLastname());
70
+
71
+ $billingaddress = $myOrder->getBillingAddress()->getStreet();
72
+ $address = utf8_decode($billingaddress[0]).", ".utf8_decode($billingaddress[1]);
73
+
74
+ $city=utf8_decode($myOrder->getBillingAddress()->getCity());
75
+
76
+ $region=utf8_decode($myOrder->getBillingAddress()->getRegion());
77
+
78
+ $postcode =utf8_decode($myOrder->getBillingAddress()->getPostcode());
79
+
80
+ }else{
81
+
82
+ $country_id = utf8_decode($myOrder->getShippingAddress()->getCountryId());
83
+ $country = Mage::getModel('directory/country')->load($country_id)->getName();
84
+
85
+ $name = utf8_decode($myOrder->getShippingAddress()->getFirstname()." ".$myOrder->getShippingAddress()->getLastname());
86
+
87
+ $billingaddress = $myOrder->getShippingAddress()->getStreet();
88
+ $address = utf8_decode($billingaddress[0]).", ".utf8_decode($billingaddress[1]);
89
+
90
+ $city=utf8_decode($myOrder->getShippingAddress()->getCity());
91
+
92
+ $region=utf8_decode($myOrder->getShippingAddress()->getRegion());
93
+
94
+ $postcode =utf8_decode($myOrder->getShippingAddress()->getPostcode());
95
+ }
96
+
97
+ $myOrder->loadByIncrementId($myOrder->getIncrementId());
98
+ //$payment_method = $myOrder->getPayment()->getMethodInstance()->getTitle();
99
+ $store = Mage::app()->getStore();
100
+ $items = $myOrder->getItemsCollection();
101
+ $ic=1;
102
+ $countitems=0;
103
+
104
+ $item_line="";
105
+ foreach ($items as $itemId => $item){
106
+
107
+ if($item->getQtyToInvoice()!=0):
108
+ $itemorderqty = $item->getQtyToInvoice();
109
+ else:
110
+ $itemorderqty = round($item->getQtyOrdered());
111
+ endif;
112
+
113
+ if($item->getParentItemId() && round($item->getOriginalPrice())==0){
114
+ $parentitem = $order->getItemById($item->getParentItemId());
115
+
116
+ $originalprice = $parentitem->getOriginalPrice();
117
+
118
+ $subtotal = ($parentitem->getOriginalPrice()*$itemorderqty);
119
+
120
+ $discountamount=0;
121
+ if(round($parentitem->getDiscountAmount())!=0){
122
+ $discountamount=$parentitem->getDiscountAmount();
123
+ $subtotal=($subtotal-$discountamount);
124
+ }
125
+
126
+ $subtotal = number_format($subtotal,2);
127
+
128
+ $eachitemdiscountamount = ($discountamount/$itemorderqty);
129
+ $discountamount = number_format($eachitemdiscountamount,2);
130
+
131
+ $taxpercent = $parentitem->getTaxPercent();
132
+
133
+ $eachitemvat = $vatamount_eachproduct/$itemorderqty;
134
+ $totalvatdisamount = $eachitemvat+$eachitemdiscountamount;
135
+ $net_price = round($originalprice-($totalvatdisamount),2);
136
+ }else{
137
+ $originalprice = $item->getOriginalPrice();
138
+
139
+ $subtotal = ($item->getOriginalPrice()*$itemorderqty);
140
+
141
+ $discountamount=0;
142
+ if(round($item->getDiscountAmount())!=0){
143
+ $discountamount=$item->getDiscountAmount();
144
+ $subtotal=($subtotal-$discountamount);
145
+ }
146
+
147
+ $subtotal = number_format($subtotal,2);
148
+
149
+ $eachitemdiscountamount = ($discountamount/$itemorderqty);
150
+ $discountamount = number_format($eachitemdiscountamount,2);
151
+
152
+ $taxpercent = $item->getTaxPercent();
153
+
154
+ $eachitemvat = $vatamount_eachproduct/$itemorderqty;
155
+ $totalvatdisamount = $eachitemvat+$eachitemdiscountamount;
156
+ $net_price = round($originalprice-($totalvatdisamount),2);
157
+ }
158
+
159
+ $customer_email = "";
160
+ if($custoer_id = $myOrder->getCustomerId()){
161
+ $customer = Mage::getModel('customer/customer')->load($custoer_id);
162
+ $customer_email = $customer->getEmail();
163
+ }
164
+
165
+ if(empty($customer_email)){
166
+ $customer_email=$myOrder->getCustomerEmail();
167
+ }
168
+
169
+ //echo $myOrder->getCreatedAt();
170
+ //exit;
171
+ $datarow = array(date("d/m/Y",strtotime($myOrder->getCreatedAt())), $myOrder->getIncrementId(), utf8_decode($item->getName()), $itemorderqty, utf8_decode($net_price),$subtotal,$name,$customer_email,$address,$city,$region,$postcode,$country);
172
+
173
+ //print_r($csvtitles);
174
+ $line = "";
175
+ $comma = "";
176
+ foreach($datarow as $titlename) {
177
+ $line .= $comma . str_replace(array(','),array(""), $titlename);
178
+ $comma = ",";
179
+ }
180
+
181
+ $line .= "\n";
182
+
183
+ $orders_csv_row .=$line;
184
+
185
+ }
186
+ }
187
+ $reportname = Mage::helper('salesreport')->getReportName();
188
+ $fileName = $reportname.'.csv';
189
+ //print_r($orders_csv_row);
190
+ //exit;
191
+ $this->_sendUploadResponse($fileName, $orders_csv_row);
192
+
193
+ }
194
+ }
195
+
196
+ protected function _sendUploadResponse($fileName, $content, $contentType='application/octet-stream')
197
+ {
198
+ $response = $this->getResponse();
199
+ $response->setHeader('HTTP/1.1 200 OK','');
200
+ $response->setHeader('Pragma', 'public', true);
201
+ $response->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
202
+ $response->setHeader('Content-Disposition', 'attachment; filename='.$fileName);
203
+ $response->setHeader('Last-Modified', date('r'));
204
+ $response->setHeader('Accept-Ranges', 'bytes');
205
+ $response->setHeader('Content-Length', strlen($content));
206
+ $response->setHeader('Content-type', $contentType);
207
+ $response->setBody($content);
208
+ $response->sendResponse();
209
+ die;
210
+ }
211
+
212
+
213
+ }
app/code/local/Cybernetikz/Salesreport/etc/adminhtml.xml ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Magento admin config
5
+ *
6
+ * @author Magento
7
+ */
8
+ -->
9
+ <config>
10
+ <menu>
11
+ <report>
12
+ <children>
13
+ <salesreport translate="title" module="salesreport">
14
+ <title>Custom Sales Report</title>
15
+ <sort_order>60</sort_order>
16
+ <action>salesreport/adminhtml_sales/reportmanage</action>
17
+ </salesreport>
18
+ </children>
19
+ </report>
20
+ </menu>
21
+
22
+ <acl>
23
+ <resources>
24
+ <admin>
25
+ <children>
26
+ <salesreport>
27
+ <salesreport_adminform>
28
+ <title>Custom Sales Reports</title>
29
+ </salesreport_adminform>
30
+ </salesreport>
31
+ <system>
32
+ <children>
33
+ <config>
34
+ <children>
35
+ <salesreports translate="label" module="salesreport">
36
+ <label>Custom Sales Report</label>
37
+ <sort_order>500</sort_order>
38
+ </salesreports>
39
+ </children>
40
+ </config>
41
+ </children>
42
+ </system>
43
+ </children>
44
+ </admin>
45
+ </resources>
46
+ </acl>
47
+ </config>
app/code/local/Cybernetikz/Salesreport/etc/config.xml ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Cybernetikz_Salesreport>
5
+ <version>0.1.0</version>
6
+ </Cybernetikz_Salesreport>
7
+ </modules>
8
+
9
+ <global>
10
+ <models>
11
+ <salesreport>
12
+ <class>Cybernetikz_Salesreport_Model</class>
13
+ </salesreport>
14
+ </models>
15
+ <helpers>
16
+ <salesreport>
17
+ <class>Cybernetikz_Salesreport_Helper</class>
18
+ </salesreport>
19
+ </helpers>
20
+ </global>
21
+
22
+ <admin>
23
+ <routers>
24
+ <salesreport>
25
+ <use>admin</use>
26
+ <args>
27
+ <module>Cybernetikz_Salesreport</module>
28
+ <frontName>salesreport</frontName>
29
+ </args>
30
+ </salesreport>
31
+ </routers>
32
+ </admin>
33
+
34
+ <adminhtml>
35
+ <layout>
36
+ <updates>
37
+ <salesreport>
38
+ <file>salesreport.xml</file>
39
+ </salesreport>
40
+ </updates>
41
+ </layout>
42
+ </adminhtml>
43
+
44
+ <default>
45
+ <salesreports>
46
+ <reportsetting>
47
+ <report_name>SalesReport</report_name>
48
+ <report_address>shipping</report_address>
49
+ </reportsetting>
50
+ </salesreports>
51
+ </default>
52
+ </config>
app/code/local/Cybernetikz/Salesreport/etc/system.xml ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <sections>
3
+ <salesreports translate="label" module="salesreport">
4
+ <label>Custom Sales Report</label>
5
+ <tab>sales</tab>
6
+ <sort_order>500</sort_order>
7
+ <show_in_default>1</show_in_default>
8
+ <show_in_website>1</show_in_website>
9
+ <show_in_store>1</show_in_store>
10
+
11
+ <groups>
12
+ <reportsetting translate="label" module="salesreport">
13
+ <label>Report Settings</label>
14
+ <frontend_type>text</frontend_type>
15
+ <sort_order>10</sort_order>
16
+ <show_in_default>1</show_in_default>
17
+ <show_in_website>1</show_in_website>
18
+ <show_in_store>1</show_in_store>
19
+ <fields>
20
+ <report_name translate="label">
21
+ <label>Report File Name</label>
22
+ <frontend_type>text</frontend_type>
23
+ <comment>Please enter report file name. Please don't include file extension i.e .csv. Example: SalesReport</comment>
24
+ <sort_order>10</sort_order>
25
+ <show_in_default>1</show_in_default>
26
+ <show_in_website>1</show_in_website>
27
+ <show_in_store>1</show_in_store>
28
+ </report_name>
29
+ <report_address translate="label">
30
+ <label>Report Use Address</label>
31
+ <frontend_type>select</frontend_type>
32
+ <source_model>salesreport/address</source_model>
33
+ <comment>Please select order address you want to use in your report.</comment>
34
+ <sort_order>20</sort_order>
35
+ <show_in_default>1</show_in_default>
36
+ <show_in_website>1</show_in_website>
37
+ <show_in_store>1</show_in_store>
38
+ </report_address>
39
+ </fields>
40
+ </reportsetting>
41
+ </groups>
42
+ </salesreports>
43
+ </sections>
44
+ </config>
app/design/adminhtml/default/default/layout/salesreport.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout>
3
+ <salesreport_adminhtml_sales_reportmanage>
4
+ <update handle="salesreport_sales_reportmanage"/>
5
+ <reference name="content">
6
+ <block type="adminhtml/template" name="sales" template="salesreport/reportmanage.phtml"/>
7
+ </reference>
8
+ </salesreport_adminhtml_sales_reportmanage>
9
+ </layout>
app/design/adminhtml/default/default/template/salesreport/reportmanage.phtml ADDED
@@ -0,0 +1,387 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $to="";
3
+ $from="";
4
+ $show_order_statuses = 0;
5
+ $orserstatus = "";
6
+
7
+ $result_order = 0;
8
+
9
+ if(!empty($_REQUEST['from']) && !empty($_REQUEST['to'])){
10
+ /*====================== Start Code for Magento Orders Product =====================*/
11
+ //echo "<pre>";
12
+ $orders_row = array();
13
+
14
+ $to=$_REQUEST['to'];
15
+ $from=$_REQUEST['from'];
16
+
17
+ $to_date = date('Y-m-d' . ' 00:00:00', strtotime($to));
18
+ $from_date = date('Y-m-d' . ' 00:00:00', strtotime($from));
19
+
20
+
21
+ if($_REQUEST['show_order_statuses']>0){
22
+ $orserstatus = $_REQUEST['order_statuses'];
23
+ //print_r($orserstatus);
24
+ //exit;
25
+ $orders = Mage::getResourceModel('sales/order_collection')
26
+ ->addAttributeToSelect('*')
27
+ ->addFieldToFilter('created_at', array('from'=>$from_date, 'to'=>$to_date))
28
+ ->addFieldToFilter('status', $orserstatus)
29
+ ->load();
30
+ }else{
31
+ $orders = Mage::getResourceModel('sales/order_collection')
32
+ ->addAttributeToSelect('*')
33
+ ->addFieldToFilter('created_at', array('from'=>$from_date, 'to'=>$to_date))
34
+ ->load();
35
+ }
36
+
37
+ $show_order_statuses=$_REQUEST['show_order_statuses'];
38
+
39
+ $result_order = $orders->count();
40
+
41
+ $i=0;
42
+ foreach($orders as $key=>$single_order) {
43
+ //print_r($single_order);
44
+ //exit;
45
+ $thisId = $single_order->getId();
46
+ $myOrder=Mage::getModel('sales/order');
47
+ $myOrder->load($thisId);
48
+
49
+ //Some random fields
50
+ $reportaddress = Mage::helper('salesreport')->getReportAddress();
51
+ if($reportaddress=="billing"){
52
+
53
+ $country_id = utf8_decode($myOrder->getBillingAddress()->getCountryId());
54
+ $country = Mage::getModel('directory/country')->load($country_id)->getName();
55
+
56
+ $name = utf8_decode($myOrder->getBillingAddress()->getFirstname()." ".$myOrder->getBillingAddress()->getLastname());
57
+
58
+ $billingaddress = $myOrder->getBillingAddress()->getStreet();
59
+ $address = utf8_decode($billingaddress[0]).", ".utf8_decode($billingaddress[1]);
60
+
61
+ $city=utf8_decode($myOrder->getBillingAddress()->getCity());
62
+
63
+ $region=utf8_decode($myOrder->getBillingAddress()->getRegion());
64
+
65
+ $postcode =utf8_decode($myOrder->getBillingAddress()->getPostcode());
66
+
67
+ }else{
68
+
69
+ $country_id = utf8_decode($myOrder->getShippingAddress()->getCountryId());
70
+ $country = Mage::getModel('directory/country')->load($country_id)->getName();
71
+
72
+ $name = utf8_decode($myOrder->getShippingAddress()->getFirstname()." ".$myOrder->getShippingAddress()->getLastname());
73
+
74
+ $billingaddress = $myOrder->getShippingAddress()->getStreet();
75
+ $address = utf8_decode($billingaddress[0]).", ".utf8_decode($billingaddress[1]);
76
+
77
+ $city=utf8_decode($myOrder->getShippingAddress()->getCity());
78
+
79
+ $region=utf8_decode($myOrder->getShippingAddress()->getRegion());
80
+
81
+ $postcode =utf8_decode($myOrder->getShippingAddress()->getPostcode());
82
+ }
83
+
84
+ $myOrder->loadByIncrementId($myOrder->getIncrementId());
85
+ //$payment_method = $myOrder->getPayment()->getMethodInstance()->getTitle();
86
+ //$store = Mage::app()->getStore();
87
+ //$orders=Mage::getModel('sales/mysql4_order_collection');
88
+ //$allIds=$orders->getAllIds();
89
+ //$order = Mage::getModel('sales/order')->load($thisId);
90
+
91
+
92
+ $items = $myOrder->getItemsCollection();
93
+ $ic=1;
94
+ $countitems=0;
95
+
96
+ $item_line="";
97
+ foreach ($items as $itemId => $item){
98
+
99
+ if($item->getQtyToInvoice()!=0):
100
+ $itemorderqty = $item->getQtyToInvoice();
101
+ else:
102
+ $itemorderqty = round($item->getQtyOrdered());
103
+ endif;
104
+
105
+ //Order Current Item
106
+ //$_helper = Mage::helper('catalog/output');
107
+ //$_product = Mage::getModel('catalog/product')->load($item->getProductId());
108
+
109
+ if($item->getParentItemId() && round($item->getOriginalPrice())==0){
110
+ $parentitem = $order->getItemById($item->getParentItemId());
111
+ //print_r($item->getData());
112
+ //print_r($parentitem->getData());
113
+ //exit;
114
+ $originalprice = $parentitem->getOriginalPrice();
115
+
116
+ $subtotal = ($parentitem->getOriginalPrice()*$itemorderqty);
117
+
118
+ $discountamount=0;
119
+ if(round($parentitem->getDiscountAmount())!=0){
120
+ $discountamount=$parentitem->getDiscountAmount();
121
+ $subtotal=($subtotal-$discountamount);
122
+ }
123
+
124
+ $subtotal = number_format($subtotal,2);
125
+
126
+ $eachitemdiscountamount = ($discountamount/$itemorderqty);
127
+ $discountamount = number_format($eachitemdiscountamount,2);
128
+
129
+ $taxpercent = $parentitem->getTaxPercent();
130
+
131
+ $eachitemvat = $vatamount_eachproduct/$itemorderqty;
132
+ $totalvatdisamount = $eachitemvat+$eachitemdiscountamount;
133
+ $net_price = round($originalprice-($totalvatdisamount),2);
134
+
135
+ }else{
136
+ $originalprice = $item->getOriginalPrice();
137
+
138
+ $subtotal = ($item->getOriginalPrice()*$itemorderqty);
139
+
140
+ $discountamount=0;
141
+ if(round($item->getDiscountAmount())!=0){
142
+ $discountamount=$item->getDiscountAmount();
143
+ $subtotal=($subtotal-$discountamount);
144
+ }
145
+
146
+ $subtotal = number_format($subtotal,2);
147
+
148
+ $eachitemdiscountamount = ($discountamount/$itemorderqty);
149
+ $discountamount = number_format($eachitemdiscountamount,2);
150
+
151
+ $taxpercent = $item->getTaxPercent();
152
+
153
+ $eachitemvat = $vatamount_eachproduct/$itemorderqty;
154
+ $totalvatdisamount = $eachitemvat+$eachitemdiscountamount;
155
+ $net_price = round($originalprice-($totalvatdisamount),2);
156
+
157
+ }
158
+
159
+ /*echo $originalprice."<br />";
160
+ echo $discountamount."<br />";
161
+ echo $subtotal;
162
+ exit;*/
163
+
164
+ $customer_email = "";
165
+ if($custoer_id = $myOrder->getCustomerId()){
166
+ $customer = Mage::getModel('customer/customer')->load($custoer_id);
167
+ $customer_email = $customer->getEmail();
168
+ }
169
+
170
+ if(empty($customer_email)){
171
+ $customer_email=$myOrder->getCustomerEmail();
172
+ }
173
+
174
+ $orders_row[] = array(date("d/m/Y",strtotime($myOrder->getCreatedAt())), $myOrder->getIncrementId(), utf8_decode($item->getName()), $itemorderqty, utf8_decode($net_price),$subtotal,$name,$customer_email,$address,$city,$region,$postcode,$country);
175
+
176
+ }
177
+ }
178
+ }
179
+
180
+ ?>
181
+
182
+ <div id="anchor-content" class="middle">
183
+ <div id="page:main-container">
184
+ <div class="content-header">
185
+ <table cellspacing="0">
186
+ <tbody>
187
+ <tr>
188
+ <td style="width:50%;"><h3 class="icon-head head-report-sales-sales"><?php echo $this->__("Custom Sales Order Report");?></h3></td>
189
+ <td class="form-buttons"><button style="" onclick="filterFormSubmit.submit()" class="scalable " type="button" id="id_<?php echo Mage::getSingleton('core/session')->getFormKey() ?>"><span>Show Report</span></button></td>
190
+ </tr>
191
+ </tbody>
192
+ </table>
193
+ </div>
194
+ <div>
195
+ <div class="entry-edit">
196
+ <form method="get" action="<?php echo Mage::helper('core/url')->getCurrentUrl();?>" id="filter_form">
197
+ <?php /*?><input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" /><?php */?>
198
+ <div class="entry-edit-head">
199
+ <h4 class="icon-head head-edit-form fieldset-legend">Filter</h4>
200
+ <div class="form-buttons"></div>
201
+ </div>
202
+ <div id="sales_report_base_fieldset" class="fieldset">
203
+ <div class="hor-scroll">
204
+ <table cellspacing="0" class="form-list">
205
+ <tbody>
206
+ <tr>
207
+ <td class="label"><label for="sales_report_from">From <span class="required">*</span></label></td>
208
+ <td class="value"><input type="text" style="width:110px !important;" class=" required-entry input-text" title="From" value="<?php echo $from; ?>" id="sales_report_from" name="from" />
209
+ <img style="" title="Select Date" id="sales_report_from_trig" class="v-middle" alt="" src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);?>skin/adminhtml/default/default/images/grid-cal.gif">
210
+ <script type="text/javascript">
211
+ //<![CDATA[
212
+ Calendar.setup({
213
+ inputField: "sales_report_from",
214
+ ifFormat: "%m/%e/%y",
215
+ showsTime: false,
216
+ button: "sales_report_from_trig",
217
+ align: "Bl",
218
+ singleClick : true
219
+ });
220
+ //]]>
221
+ </script></td>
222
+ </tr>
223
+ <tr>
224
+ <td class="label"><label for="sales_report_to">To <span class="required">*</span></label></td>
225
+ <td class="value"><input type="text" style="width:110px !important;" class=" required-entry input-text" title="To" value="<?php echo $to; ?>" id="sales_report_to" name="to" />
226
+ <img style="" title="Select Date" id="sales_report_to_trig" class="v-middle" alt="" src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);?>skin/adminhtml/default/default/images/grid-cal.gif">
227
+ <script type="text/javascript">
228
+ //<![CDATA[
229
+ Calendar.setup({
230
+ inputField: "sales_report_to",
231
+ ifFormat: "%m/%e/%y",
232
+ showsTime: false,
233
+ button: "sales_report_to_trig",
234
+ align: "Bl",
235
+ singleClick : true
236
+ });
237
+ //]]>
238
+ </script></td>
239
+ </tr>
240
+ <tr>
241
+ <td class="label"><label for="sales_report_show_order_statuses">Order Status</label></td>
242
+ <td class="value"><select class=" select" name="show_order_statuses" id="sales_report_show_order_statuses">
243
+ <option <?php echo ($show_order_statuses==0)?'selected="selected"':''; ?> value="0">Any</option>
244
+ <option <?php echo ($show_order_statuses==1)?'selected="selected"':''; ?> value="1">Specified</option>
245
+ </select>
246
+ <p id="note_show_order_statuses" class="note"><span>Applies to Any of the Specified Order Statuses</span></p></td>
247
+ </tr>
248
+ <tr id="" style="display: none;">
249
+ <td class="label"></td>
250
+ <td class="value">
251
+ <select multiple="multiple" class=" select multiselect" size="10" name="order_statuses[]" id="sales_report_order_statuses">
252
+ <option <?php if(in_array('pending',$orserstatus)){echo 'selected="selected"';}?> value="pending">Pending</option>
253
+ <option <?php if(in_array('processing',$orserstatus)){echo 'selected="selected"';}?> value="processing">Processing</option>
254
+ <option <?php if(in_array('holded',$orserstatus)){echo 'selected="selected"';}?> value="holded">On Hold</option>
255
+ <option <?php if(in_array('complete',$orserstatus)){echo 'selected="selected"';}?> value="complete">Complete</option>
256
+ <option <?php if(in_array('closed',$orserstatus)){echo 'selected="selected"';}?> value="closed">Closed</option>
257
+ <option <?php if(in_array('canceled',$orserstatus)){echo 'selected="selected"';}?> value="canceled">Canceled</option>
258
+ <option <?php if(in_array('fraud',$orserstatus)){echo 'selected="selected"';}?> value="fraud">Suspected Fraud</option>
259
+ <option <?php if(in_array('payment_review',$orserstatus)){echo 'selected="selected"';}?> value="payment_review">Payment Review</option>
260
+ </select></td>
261
+ </tr>
262
+ </tbody>
263
+ </table>
264
+ </div>
265
+ </div>
266
+ </form>
267
+ </div>
268
+ <script type="text/javascript">
269
+ //<![CDATA[
270
+ var filterFormSubmit = new varienForm('filter_form');
271
+ //]]>
272
+ </script>
273
+ <script type="text/javascript"> new FormElementDependenceController({"sales_report_order_statuses":{"sales_report_show_order_statuses":"1"}}); </script>
274
+ </div>
275
+
276
+ <div>
277
+ <?php if($result_order>0){?>
278
+ <table cellspacing="0" class="actions">
279
+ <tbody>
280
+ <tr>
281
+ <td class="pager">&nbsp;</td>
282
+ <td class="export a-right">
283
+ <form method="post" action="<?php echo $this->getUrl('*/*/exportCsv')?>" id="csv_form">
284
+ <input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" />
285
+ <input type="hidden" value="<?php echo $from; ?>" id="sales_report_from" name="from" />
286
+ <input type="hidden" value="<?php echo $to; ?>" id="sales_report_to" name="to" />
287
+ <select name="show_order_statuses" style="display:none;">
288
+ <option <?php echo ($show_order_statuses==0)?'selected="selected"':''; ?> value="0">Any</option>
289
+ <option <?php echo ($show_order_statuses==1)?'selected="selected"':''; ?> value="1">Specified</option>
290
+ </select>
291
+
292
+ <select multiple="multiple" name="order_statuses[]" style="display:none;">
293
+ <option <?php if(in_array('pending',$orserstatus)){echo 'selected="selected"';}?> value="pending">Pending</option>
294
+ <option <?php if(in_array('processing',$orserstatus)){echo 'selected="selected"';}?> value="processing">Processing</option>
295
+ <option <?php if(in_array('holded',$orserstatus)){echo 'selected="selected"';}?> value="holded">On Hold</option>
296
+ <option <?php if(in_array('complete',$orserstatus)){echo 'selected="selected"';}?> value="complete">Complete</option>
297
+ <option <?php if(in_array('closed',$orserstatus)){echo 'selected="selected"';}?> value="closed">Closed</option>
298
+ <option <?php if(in_array('canceled',$orserstatus)){echo 'selected="selected"';}?> value="canceled">Canceled</option>
299
+ <option <?php if(in_array('fraud',$orserstatus)){echo 'selected="selected"';}?> value="fraud">Suspected Fraud</option>
300
+ <option <?php if(in_array('payment_review',$orserstatus)){echo 'selected="selected"';}?> value="payment_review">Payment Review</option>
301
+ </select>
302
+
303
+ </form>
304
+ <script type="text/javascript">
305
+ //<![CDATA[
306
+ var csvFormSubmit = new varienForm('csv_form');
307
+ //]]>
308
+ </script>
309
+ </td>
310
+ <td class="filter-actions a-right">
311
+ <img class="v-middle" alt="" src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);?>skin/adminhtml/default/default/images/icon_export.gif">&nbsp; Export to:
312
+ <select style="width:8em;" id="sales_order_grid_export" name="sales_order_grid_export">
313
+ <option value="<?php echo $this->getUrl('*/*/exportCsv')?>">CSV</option>
314
+ </select>
315
+ <button onclick="csvFormSubmit.submit()" class="scalable task" type="button"><span>Export</span></button>
316
+
317
+ <?php /*?><button onclick="printResult()" class="scalable task" type="button"><span>Print</span></button><?php */?>
318
+ </td>
319
+ </tr>
320
+ </tbody>
321
+ </table>
322
+ <?php } ?>
323
+ <div id="id_<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" class="print_<?php echo Mage::getSingleton('core/session')->getFormKey() ?>">
324
+ <div class="grid">
325
+ <div class="hor-scroll">
326
+ <table cellspacing="0" id="id_<?php echo Mage::getSingleton('core/session')->getFormKey() ?>_table" class="data">
327
+ <colgroup>
328
+ <col>
329
+ <col>
330
+ <col>
331
+ <col>
332
+ <col>
333
+ <col>
334
+ <col>
335
+ <col>
336
+ <col>
337
+ <col>
338
+ <col>
339
+ <col>
340
+ <col>
341
+ </colgroup>
342
+ <thead>
343
+ <tr class="headings">
344
+ <th class=" no-link"><span class="nobr">Period</span></th>
345
+ <th class=" no-link"><span class="nobr">Order Id</span></th>
346
+ <th class=" no-link"><span class="nobr">Item Name</span></th>
347
+ <th class=" no-link"><span class="nobr">Qty</span></th>
348
+ <th class=" no-link"><span class="nobr">Unit Price</span></th>
349
+ <th class=" no-link"><span class="nobr">Row Total</span></th>
350
+ <th class=" no-link"><span class="nobr"><?php echo ($reportaddress=="billing")?"Billing":"Shipping"; ?> Name</span></th>
351
+ <th class=" no-link"><span class="nobr">Email</span></th>
352
+ <th class=" no-link"><span class="nobr">Street Address</span></th>
353
+ <th class=" no-link"><span class="nobr">City</span></th>
354
+ <th class=" no-link"><span class="nobr">State</span></th>
355
+ <th class=" no-link"><span class="nobr">Postcode</span></th>
356
+ <th class=" no-link"><span class="nobr">Country</span></th>
357
+ </tr>
358
+ </thead>
359
+ <tbody id="">
360
+ <?php
361
+ if(count($orders_row)>0){
362
+ foreach($orders_row as $singlerows){
363
+ if(!empty($singlerows)){
364
+ echo "<tr>";
365
+ foreach($singlerows as $value){
366
+ ?>
367
+ <td><?php echo $value;?></td>
368
+ <?php
369
+ }
370
+ echo "</tr>";
371
+ }
372
+ }
373
+ }else{
374
+ ?>
375
+ <tr class="even">
376
+ <td colspan="13" class="empty-text a-center">No records found.</td>
377
+ </tr>
378
+ <?php } ?>
379
+ </tbody>
380
+
381
+ </table>
382
+ </div>
383
+ </div>
384
+ </div>
385
+ </div>
386
+ </div>
387
+ </div>
app/etc/modules/Cybernetikz_Salesreport.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Cybernetikz_Salesreport>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ </Cybernetikz_Salesreport>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Cybernetikz_Salesreport</name>
4
+ <version>0.1.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL 3.0)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Custom Reporting with Product and Billing/Shipping info. Easy searchable option by order date and status.</summary>
10
+ <description>&lt;h3&gt;Custom Reporting&lt;/h3&gt;&#xD;
11
+ &lt;p&gt;&lt;a href="http://www.cybernetikz.com/" title="CyberNetikz"&gt;CyberNetikz&lt;/a&gt; - Custom Reporting extension very easy to use and install. Admin user can get sales report with products information (Like Product Name, Quantity, Unit Price, Row Total) and Billing/Shipping Information (Like Name,Email,Street Address,City,State,Postcode,Country)&lt;/p&gt;&#xD;
12
+ &lt;h3&gt;Installation &amp; Use&lt;/h3&gt;&#xD;
13
+ &lt;p&gt;You can easily install extension via Magento Connect. After intall this extension you will able use from &lt;strong&gt;Admin Panel -&gt; Reports -&gt; Custom Sales Report&lt;/strong&gt;&lt;/p&gt;&#xD;
14
+ &lt;h3&gt;Support&lt;/h3&gt;&#xD;
15
+ &lt;p&gt;&lt;a href="mailto:info@cybernetikz.com"&gt;info@cybernetikz.com&lt;/a&gt;&lt;/p&gt;</description>
16
+ <notes>Custom Reporting with Product and Billing/Shipping info. Easy searchable option by order date and status.</notes>
17
+ <authors><author><name>CyberNetikz</name><user>CyberNetikz</user><email>admin@cybernetikz.com</email></author></authors>
18
+ <date>2013-04-04</date>
19
+ <time>07:19:15</time>
20
+ <contents><target name="magelocal"><dir name="Cybernetikz"><dir name="Salesreport"><dir name="Helper"><file name="Data.php" hash="01219c696266e745ee0ed668291834ae"/></dir><dir name="Model"><file name="Address.php" hash="c577974ece6d53e50be92a66ff255369"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="SalesController.php" hash="53636f86cd6cba9b3b9743189e7c3bf4"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="7869a17d9efd1b3e4cd47c711b9d7ef7"/><file name="config.xml" hash="56bfeef6ce6386a53b8fc4c676575276"/><file name="system.xml" hash="9319c372d05d6a2825f049ab3dc48662"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Cybernetikz_Salesreport.xml" hash="9f019cd8c8002124305625477cba472c"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="salesreport.xml" hash="3bc3565551291ad72e0ba329c0d9913d"/></dir><dir name="template"><dir name="salesreport"><file name="reportmanage.phtml" hash="f38a6c8d65da0b082e47cf91b6a74613"/></dir></dir></dir></dir></dir></target></contents>
21
+ <compatible/>
22
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
23
+ </package>