<modification>
<name><![CDATA[<font color="#0000"><b>EC Advanced Report</font>]]></name>
<version>2.0.0</version>
<link>http://ecomteck.com</link>
<author>ecomteck</author>
<code>ec_advanced_reports</code>

<file path="admin/controller/common/menu.php">
        <operation>
            <search position="replace">
                 <![CDATA[ $this->load->language('common/menu');  ]]>
            </search>
            <add>
             <![CDATA[
                $this->load->language('common/menu');
                $this->language->load('module/ecadvancedreports');
                /*
                $this->load->model('setting/extension');
                $extensions = $this->model_setting_extension->getInstalled('module');
                $data['ecadvancedreports_installed'] = false;
                if(in_array("ecadvancedreports", $extensions)){
                    $data['ecadvancedreports_installed'] = true;
                }*/

                $data['text_ecadvancedreports_reports'] = $this->language->get('text_ecadvancedreports_advanced_reports');
                $data['text_sales_by_customer_group'] = $this->language->get("text_sales_by_customer_group");
                $data['text_sales_by_customer_company'] = $this->language->get("text_sales_by_customer_company");
                $data['text_report_sale_order'] = $this->language->get("text_report_sale_order");
                $data['text_sales_by_product'] = $this->language->get("text_sales_by_product");
                $data['text_advanced'] = $this->language->get("text_advanced");
                $data['text_report_sale_tax'] = $this->language->get("text_report_sale_tax");
                $data['text_report_sale_shipping'] = $this->language->get("text_report_sale_shipping");
                $data['text_report_sale_return'] = $this->language->get("text_report_sale_return");
                $data['text_report_sale_coupon'] = $this->language->get("text_report_sale_coupon");
                $data['text_product'] = $this->language->get("text_product");
                $data['text_report_product_viewed'] = $this->language->get("text_report_product_viewed");
                $data['text_report_product_purchased'] = $this->language->get("text_report_product_purchased");
                $data['text_customer'] = $this->language->get("text_customer");
                $data['text_report_customer_online'] = $this->language->get("text_report_customer_online");
                $data['text_report_customer_order'] = $this->language->get("text_report_customer_order");
                $data['text_report_customer_reward'] = $this->language->get("text_report_customer_reward");
                $data['text_report_customer_credit'] = $this->language->get("text_report_customer_credit");
                $data['text_report_affiliate_commission'] = $this->language->get("text_report_affiliate_commission");
                $data['text_affiliate'] = $this->language->get("text_affiliate");
                $data['text_report_sale_by_country'] = $this->language->get("text_report_sale_by_country");
                $data['text_report_customer_by_city'] = $this->language->get("heading_title_customer_city");
                $data['text_report_customer_by_country'] = $this->language->get("heading_title_customer_country");
                $data['text_report_sale_by_hour'] = $this->language->get("text_report_sale_by_hour");
                $data['text_report_sale_by_day_of_week'] = $this->language->get("text_report_sale_by_day_of_week");
                $data['text_report_sale_by_product'] = $this->language->get("text_report_sale_by_product");
                $data['text_report_sale_by_manufacturer'] = $this->language->get("text_report_sale_by_manufacturer");
                $data['text_report_sale_statistic'] = $this->language->get("text_report_sale_statistic");
                $data['text_report_sale_by_coupon_code'] = $this->language->get("text_report_sale_by_coupon_code");
                $data['text_report_sale_by_payment_type'] = $this->language->get("text_report_sale_by_payment_type");
                $data['text_report_sale_by_zip_code'] = $this->language->get("text_report_sale_by_zip_code");
                $data['text_report_sale_by_state'] = $this->language->get("text_report_sale_by_state");
                $data['text_report_sale_report'] = $this->language->get("text_report_sale_report");
                $data['text_report_product_bestseller'] = $this->language->get("text_report_product_bestseller");
                $data['text_report_sale_category'] = $this->language->get("text_report_sale_category");
                $data['text_report_sale_by_profit'] = $this->language->get("text_report_sale_by_profit");
                $data['text_report_product_profit'] = $this->language->get("text_report_product_profit");
                $data['text_report_user_activity'] = $this->language->get("text_report_user_activity");
                $data['text_report_customer_purchase'] = $this->language->get("text_report_customer_purchase");
                $data['text_report_product'] = $this->language->get("text_report_product");
                $data['text_report_product_notsold'] = $this->language->get("text_report_product_notsold");
                $data['text_report_top_customer'] = $this->language->get("text_report_top_customer");
                $data['text_report_product_inventory'] = $this->language->get("text_report_product_inventory");
                $data['text_report_customer'] = $this->language->get("text_report_customer");
                $data['text_report_customer_notorder'] = $this->language->get("text_report_customer_notorder");
                $data['text_earnings'] = $this->language->get("text_earnings");

                /*Links to report pages*/
                $data['link_report_earnings'] = $this->url->link('ecadvancedreports/earnings', 'current=1&token=' . $this->session->data['token'], 'SSL');
                $data['link_to_sales_by_customer_group'] = $this->url->link('ecadvancedreports/customer_group', 'token=' . $this->session->data['token'], 'SSL');
                $data['link_to_sales_by_product'] = $this->url->link('ecadvancedreports/product', 'token=' . $this->session->data['token'], 'SSL');
                $data['link_report_bestseller'] = $this->url->link('ecadvancedreports/product_bestseller', 'token=' . $this->session->data['token'], 'SSL');
                $data['link_report_sale_by_country'] = $this->url->link('ecadvancedreports/sale_country', 'token=' . $this->session->data['token'], 'SSL');
                $data['link_report_sale_coupon'] = $this->url->link('ecadvancedreports/sale_coupon', 'token=' . $this->session->data['token'], 'SSL');
                $data['link_report_sale_statistic'] = $this->url->link('ecadvancedreports/sale_statistics', 'token=' . $this->session->data['token'], 'SSL');
                $data['link_report_sale_zip_code'] = $this->url->link('ecadvancedreports/sale_zipcode', 'token=' . $this->session->data['token'], 'SSL');
                $data['link_report_sale_state'] = $this->url->link('ecadvancedreports/sale_state', 'token=' . $this->session->data['token'], 'SSL');
                $data['link_report_sale_payment_type'] = $this->url->link('ecadvancedreports/sale_payment', 'token=' . $this->session->data['token'], 'SSL');
                $data['link_report_customer_by_city'] = $this->url->link('ecadvancedreports/customer_city', 'token=' . $this->session->data['token'], 'SSL');
                $data['link_report_customer_by_country'] = $this->url->link('ecadvancedreports/customer_country', 'token=' . $this->session->data['token'], 'SSL');
                $data['link_report_sale_order'] = $this->url->link('ecadvancedreports/sale_order', 'token=' . $this->session->data['token'], 'SSL');
                $data['link_report_sale_by_manufacturer'] = $this->url->link('ecadvancedreports/sale_manufacturer', 'token=' . $this->session->data['token'], 'SSL');
                $data['link_report_sale_by_category'] = $this->url->link('ecadvancedreports/category', 'token=' . $this->session->data['token'], 'SSL');
                $data['link_report_sale_by_hour'] = $this->url->link('ecadvancedreports/sale_hour', 'token=' . $this->session->data['token'], 'SSL');
                $data['link_report_sale_by_day_week'] = $this->url->link('ecadvancedreports/sale_day_week', 'token=' . $this->session->data['token'], 'SSL');
                $data['link_to_sales_by_profit'] = $this->url->link('ecadvancedreports/sale_profit', 'token=' . $this->session->data['token'], 'SSL');
                $data['link_report_customer_purchase'] = $this->url->link('ecadvancedreports/customer_purchase', 'token=' . $this->session->data['token'], 'SSL');
                $data['link_report_sale_report'] = $this->url->link('ecadvancedreports/sale_report', 'token=' . $this->session->data['token'], 'SSL');
                $data['link_report_user_activity'] = $this->url->link('ecadvancedreports/user_activity', 'token=' . $this->session->data['token'], 'SSL');
                $data['link_report_product'] = $this->url->link('ecadvancedreports/report_product', 'token=' . $this->session->data['token'], 'SSL');
                $data['link_report_top_customer'] = $this->url->link('ecadvancedreports/top_customer', 'token=' . $this->session->data['token'], 'SSL');
                $data['link_report_customer'] = $this->url->link('ecadvancedreports/customer', 'token=' . $this->session->data['token'], 'SSL');
                $data['link_report_customer_notorder'] = $this->url->link('ecadvancedreports/customer_not_order', 'token=' . $this->session->data['token'], 'SSL');
                $data['link_report_product_inventory'] = $this->url->link('ecadvancedreports/product_inventory', 'token=' . $this->session->data['token'], 'SSL');
                $data['link_to_sales_by_customer_company'] = $this->url->link('ecadvancedreports/customer_company', 'token=' . $this->session->data['token'], 'SSL');
                $data['link_report_product_notsold'] = $this->url->link('ecadvancedreports/product_notsold', 'token=' . $this->session->data['token'], 'SSL');
                /*Links to report pages*/

              ]]>
            </add>  
        </operation>        
</file>     
<file path="admin/view/template/common/menu.tpl">
        <operation>
            <search position="replace">
                 <![CDATA[ <li id="reports"> ]]>
            </search>
            <add>
             <![CDATA[
                  <li><a class="parent"><i class="fa fa-bar-chart-o fa-fw"></i> <span><?php echo $text_ecadvancedreports_reports; ?></span></a>
                        <ul>
                            <li><a class="parent"><?php echo $text_advanced; ?></a>
                                <ul>
                                  <li><a href="<?php echo $link_report_sale_order; ?>"><?php echo $text_report_sale_order; ?></a></li>
                                  <li><a href="<?php echo $link_to_sales_by_customer_group; ?>"><?php echo $text_sales_by_customer_group; ?></a></li>
                                  <li><a href="<?php echo $link_to_sales_by_customer_company; ?>"><?php echo $text_sales_by_customer_company; ?></a></li>
                                  <li><a href="<?php echo $link_report_customer; ?>"><?php echo $text_report_customer; ?></a></li>
                                  <li><a href="<?php echo $link_report_customer_notorder; ?>"><?php echo $text_report_customer_notorder; ?></a></li>
                                  <li><a href="<?php echo $link_report_sale_by_country; ?>"><?php echo $text_report_sale_by_country; ?></a></li>
                                  
                                  <li><a href="<?php echo $link_report_sale_by_hour; ?>"><?php echo $text_report_sale_by_hour; ?></a></li>
                                  <li><a href="<?php echo $link_report_sale_by_day_week; ?>"><?php echo $text_report_sale_by_day_of_week; ?></a></li>
                                  <li><a href="<?php echo $link_report_user_activity; ?>"><?php echo $text_report_user_activity; ?></a></li>
                                  <li><a href="<?php echo $link_report_sale_report; ?>"><?php echo $text_report_sale_report; ?></a></li>
                                  <li><a href="<?php echo $link_to_sales_by_product; ?>"><?php echo $text_report_sale_by_product; ?></a></li>
                                  <!--<li><a href="<?php echo $link_to_sales_by_profit; ?>"><?php echo $text_report_sale_by_profit; ?></a></li>-->
                                  <li><a href="<?php echo $link_report_sale_by_category; ?>"><?php echo $text_report_sale_category; ?></a></li>
                                  <li><a href="<?php echo $link_report_sale_by_manufacturer; ?>"><?php echo $text_report_sale_by_manufacturer; ?></a></li>
                                  <li><a href="<?php echo $link_report_sale_statistic; ?>"><?php echo $text_report_sale_statistic; ?></a></li>
                                  <li><a href="<?php echo $link_report_sale_coupon; ?>"><?php echo $text_report_sale_by_coupon_code; ?></a></li>
                                  <li><a href="<?php echo $link_report_sale_payment_type; ?>"><?php echo $text_report_sale_by_payment_type; ?></a></li>
                                  <li><a href="<?php echo $link_report_sale_state; ?>"><?php echo $text_report_sale_by_state; ?></a></li>
                                  <li><a href="<?php echo $link_report_sale_zip_code; ?>"><?php echo $text_report_sale_by_zip_code; ?></a></li>
                                </ul>
                            </li>
                            <li><a class="parent"><?php echo $text_product; ?></a>
                                <ul>
                                    <li><a href="<?php echo $link_report_product; ?>"><?php echo $text_report_product; ?></a></li>
                                    <li><a href="<?php echo $link_report_product_inventory; ?>"><?php echo $text_report_product_inventory; ?></a></li>
                                    <li><a href="<?php echo $link_report_bestseller; ?>"><?php echo $text_report_product_bestseller; ?></a></li>
                                    <li><a href="<?php echo $link_report_product_notsold; ?>"><?php echo $text_report_product_notsold; ?></a></li>
                                </ul>
                            </li>
                            <li><a class="parent"><?php echo $text_customer; ?></a>
                                <ul>
                                  <li><a href="<?php echo $link_report_top_customer; ?>"><?php echo $text_report_top_customer; ?></a></li>
                                  <li><a href="<?php echo $link_report_customer_by_city; ?>"><?php echo $text_report_customer_by_city; ?></a></li>
                                  <li><a href="<?php echo $link_report_customer_by_country; ?>"><?php echo $text_report_customer_by_country; ?></a></li>

                                </ul>
                            </li>
                            <li><a href="<?php echo $link_report_earnings; ?>"><?php echo $text_earnings; ?></a></li>
                        </ul>   
                  </li> 
                  <li id="reports">
              ]]>
            </add>  
        </operation>
</file>
<!-- End Add menu item flashsale on admin panel -->
<file path="admin/controller/catalog/product.php">
        <operation>
            <search position="replace"><![CDATA[$data['tab_general'] = $this->language->get('tab_general');]]></search>
            <add><![CDATA[
                $this->language->load('module/ecadvancedreports');
                $show_sales_tab = $this->config->get('ecadvancedreports_enable_sales_tab');
                $data['ec_show_sales_tab'] = false;

                if($show_sales_tab) {
                    $data['ec_show_sales_tab'] = true;
                }
                $data['current_product_id'] = isset($this->request->get['product_id'])?$this->request->get['product_id']:0;
                $data['page'] = isset($this->request->get['page'])?$this->request->get['page']:1;
                $data["tab_product_orders_link"] = $this->language->get("tab_product_orders_link");
                $data['tab_general'] = $this->language->get('tab_general');
                ]]></add>
        </operation>
    </file>
    <file path="admin/view/template/catalog/product_form.tpl">
        <operation>
            <search position="replace"><![CDATA[var image_row = <?php echo $image_row; ?>;]]></search>
            <add><![CDATA[
                <?php if ((isset($ec_show_sales_tab) && $ec_show_sales_tab) && $current_product_id) { ?>
                    function showTabOrders(){
                        var product_id = '<?php echo $current_product_id; ?>';
                        var page = '<?php echo $page; ?>';
                        $.ajax({
                            type: 'GET',
                            url: 'index.php?route=module/ecadvancedreports/getReports&token=<?php echo $token; ?>&product_id='+product_id+'&page='+page,
                            dataType: 'html',
                            success: function(data) {
                                //add the button to nav
                                $('<li><a href="#tab-product-orders" data-toggle="tab"><?php echo $tab_product_orders_link; ?></a></li>').hide().appendTo($(".nav-tabs:first")).fadeIn(1000);
                                $('#tab-general').before(data);
                                $('#tabs a').tabs();
                            },
                            failure: function(){

                            },
                            error: function() {

                            }
                        });
                        
                    }

                    $(document).ready(function(){
                        showTabOrders();
                    });


                <?php } ?>

                var image_row = <?php echo $image_row; ?>;
                ]]></add>
        </operation>
        <operation>
            <search position="replace"><![CDATA[<label class="col-sm-2 control-label" for="input-price"><?php echo $entry_price; ?></label>]]></search>
            <add><![CDATA[
                <label class="col-sm-2 control-label" for="input-cost"><span data-toggle="tooltip" title="<?php echo $help_cost; ?>"><?php echo $entry_cost; ?></span></label>
                <div class="col-sm-10">
                  <input type="text" name="cost" value="<?php echo isset($cost)?$cost:''; ?>" placeholder="<?php echo $entry_cost; ?>" id="input-cost" class="form-control" />
                </div>
              </div>
               <div class="form-group">
                <label class="col-sm-2 control-label" for="input-price"><?php echo $entry_price; ?></label>
                ]]></add>
        </operation>
    </file>
    <file path="admin/controller/catalog/product.php">
        <operation>
            <search position="replace"><![CDATA[protected function getForm() {]]></search>
            <add><![CDATA[
              protected function getForm() {
                $data['entry_cost'] = $this->language->get('entry_cost');
                $data['help_cost'] = $this->language->get('help_cost');
                ]]></add>
        </operation>
        <operation>
            <search position="replace"><![CDATA[$this->load->model('setting/store');]]></search>
            <add><![CDATA[
                $this->load->model('setting/store');

                if (isset($this->request->post['cost'])) {
                    $data['cost'] = $this->request->post['cost'];
                } elseif (!empty($product_info)) {
                    $data['cost'] = isset($product_info['cost'])?$product_info['cost']:'';
                } else {
                    $data['cost'] = '';
                }
                ]]></add>
        </operation>
    </file>
    <file path="admin/model/catalog/product.php">
        <operation>
            <search position="replace"><![CDATA[public function getProducts($data = array()) {]]></search>
            <add><![CDATA[
                public function alterProductField() {
                    $sql = "SELECT COLUMN_NAME 
                            FROM INFORMATION_SCHEMA.COLUMNS
                            WHERE Table_Schema = '".DB_DATABASE."' AND TABLE_NAME = '".DB_PREFIX."product' AND COLUMN_NAME = 'cost'";

                    $query = $this->db->query( $sql );
                    if( count($query->rows) <= 0 ){ 
                        $sql ="ALTER TABLE `".DB_PREFIX."product`
                                            ADD (`cost` decimal(15,4) DEFAULT 0.0000)";
                        $query = $this->db->query( $sql );
                    }
                }
                public function getProducts($data = array()) {
                ]]></add>
        </operation>
        <operation>
            <search position="replace"><![CDATA[if (isset($data['image'])) {]]></search>
            <add><![CDATA[
                if (isset($data['cost'])) {
                    $this->alterProductField();
                    $cost = isset($data['cost'])?(float)$data['cost']:'';
                    $this->db->query("UPDATE " . DB_PREFIX . "product SET `cost` = '" . $cost . "' WHERE product_id = '" . (int)$product_id . "'");
                }
                if (isset($data['image'])) {
            ]]></add>
        </operation>
    </file>
    <file path="admin/language/english/catalog/product.php">
        <operation>
            <search position="replace"><![CDATA[$_['heading_title']          = 'Products';]]></search>
            <add><![CDATA[
                $_['heading_title']          = 'Products';

                $_['entry_cost']             = 'Cost';
                $_['help_cost']             = 'Cost = total cost of the product.';
                
            ]]></add>
      </operation>
    </file>
</modification>