OPENCART учет прибыли

OPENCART
------------
учет прибыли

1.Добавил поле в базу, в таблицу order
Имя:cost
Тип:decimal(15,4)
По дефолту:0.0000
2.В admin/view/template/report/sale.tpl
2.1

<thead>
        <tr>
          <td class="left"><?php echo $column_date_start; ?></td>
          <td class="left"><?php echo $column_date_end; ?></td>
          <td class="right"><?php echo $column_orders; ?></td>
  <td class="right"><?php echo $column_total; ?></td>
        </tr>
      </thead>
      <tbody>
        <?php if ($orders) { ?>
        <?php foreach ($orders as $order) { ?>
        <tr>
          <td class="left"><?php echo $order['date_start']; ?></td>
          <td class="left"><?php echo $order['date_end']; ?></td>
          <td class="right"><?php echo $order['orders']; ?></td>
          <td class="right"><?php echo $order['total']; ?></td>
        </tr>
        <?php } ?>
        <?php } else { ?>
        <tr>
          <td class="center" colspan="5"><?php echo $text_no_results; ?></td>
        </tr>
        <?php } ?>

на
        <thead>
        <tr>
          <td class="left"><?php echo $column_date_start; ?></td>
          <td class="left"><?php echo $column_date_end; ?></td>
          <td class="right"><?php echo $column_orders; ?></td>
          <td class="right"><?php echo $column_cost; ?></td>
  <td class="right"><?php echo $column_total; ?></td>
        </tr>
      </thead>
      <tbody>
        <?php if ($orders) { ?>
        <?php foreach ($orders as $order) { ?>
        <tr>
          <td class="left"><?php echo $order['date_start']; ?></td>
          <td class="left"><?php echo $order['date_end']; ?></td>
          <td class="right"><?php echo $order['orders']; ?></td>
  <td class="right"><?php echo $order['cost']; ?></td>
          <td class="right"><?php echo $order['total']; ?></td>
        </tr>
        <?php } ?>
        <tr>
          <td class="right" colspan="3"><b><?php echo $column_total; ?></b></td>
  <td class="right"><b><?php echo $cost_total; ?></b></td>
          <td class="right"><b><?php echo $total_total; ?></b></td>
        </tr>
<tr>
          <td class="right" colspan="4"><b><?php echo $column_profit; ?></b></td>
          <td class="right"><b><?php echo $profit; ?></b></td>
        </tr>
        <?php } else { ?>
        <tr>
          <td class="center" colspan="5"><?php echo $text_no_results; ?></td>
        </tr>
        <?php } ?>

-----------------------------------------
3.B admin/controler/report/sale.php
3.1
foreach ($results as $result) {
$this->data['orders'][] = array(
'date_start' => date($this->language->get('date_format_short'), strtotime($result['date_start'])),
'date_end'   => date($this->language->get('date_format_short'), strtotime($result['date_end'])),
'orders'     => $result['orders'],
'total'      => $this->currency->format($result['total'], $this->config->get('config_currency'))
);
}

на
$this->data['cost_total']=0;
$this->data['total_total']=0;
foreach ($results as $result) {
$this->data['cost_total'] += $result['cost'];
$this->data['total_total'] += $result['total'];
$this->data['orders'][] = array(
'date_start' => date($this->language->get('date_format_short'), strtotime($result['date_start'])),
'date_end'   => date($this->language->get('date_format_short'), strtotime($result['date_end'])),
'orders'     => $result['orders'],
'cost'      => $this->currency->format($result['cost'], $this->config->get('config_currency')),
'total'      => $this->currency->format($result['total'], $this->config->get('config_currency'))
);
}
$this->data['profit'] = $this->currency->format($this->data['total_total'] - $this->data['cost_total'], $this->config->get('config_currency'));
$this->data['cost_total'] = $this->currency->format($this->data['cost_total'], $this->config->get('config_currency'));
$this->data['total_total'] = $this->currency->format($this->data['total_total'], $this->config->get('config_currency'));
$this->data['column_profit'] = $this->language->get('column_profit');
$this->data['column_cost'] = $this->language->get('column_cost');

-------------------------------------------------------

4.B admin/module/report/sale.php
4.1

$sql = "SELECT MIN(date_added) AS date_start, MAX(date_added) AS date_end, COUNT(*) AS orders, SUM(total) AS total FROM `" . DB_PREFIX . "order`";

на
$sql = "SELECT MIN(date_added) AS date_start, MAX(date_added) AS date_end, COUNT(*) AS orders, SUM(total) AS total, SUM(cost) AS cost FROM `" . DB_PREFIX . "order`";

-----------------------------------------------------
5 В catalog/model/checkout/order.php
5.1
$this->db->query("INSERT INTO `" . DB_PREFIX . "order` SET store_id = '" . (int)$data['store_id'] . "', store_name = '" . $this->db->escape($data['store_name']) . "', store_url = '" . $this->db->escape($data['store_url']) . "', customer_id = '" . (int)$data['customer_id'] . "', customer_group_id = '" . (int)$data['customer_group_id'] . "', firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', email = '" . $this->db->escape($data['email']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', fax = '" . $this->db->escape($data['fax']) . "', total = '" . (float)$data['total'] . "', language_id = '" . (int)$data['language_id'] . "', currency = '" . $this->db->escape($data['currency']) . "', currency_id = '" . (int)$data['currency_id'] . "', value = '" . (float)$data['value'] . "', coupon_id = '" . (int)$data['coupon_id'] . "', ip = '" . $this->db->escape($data['ip']) . "', shipping_firstname = '" . $this->db->escape($data['shipping_firstname']) . "', shipping_lastname = '" . $this->db->escape($data['shipping_lastname']) . "', shipping_company = '" . $this->db->escape($data['shipping_company']) . "', shipping_address_1 = '" . $this->db->escape($data['shipping_address_1']) . "', shipping_address_2 = '" . $this->db->escape($data['shipping_address_2']) . "', shipping_city = '" . $this->db->escape($data['shipping_city']) . "', shipping_postcode = '" . $this->db->escape($data['shipping_postcode']) . "', shipping_zone = '" . $this->db->escape($data['shipping_zone']) . "', shipping_zone_id = '" . (int)$data['shipping_zone_id'] . "', shipping_country = '" . $this->db->escape($data['shipping_country']) . "', shipping_country_id = '" . (int)$data['shipping_country_id'] . "', shipping_address_format = '" . $this->db->escape($data['shipping_address_format']) . "', shipping_method = '" . $this->db->escape($data['shipping_method']) . "', payment_firstname = '" . $this->db->escape($data['payment_firstname']) . "', payment_lastname = '" . $this->db->escape($data['payment_lastname']) . "', payment_company = '" . $this->db->escape($data['payment_company']) . "', payment_address_1 = '" . $this->db->escape($data['payment_address_1']) . "', payment_address_2 = '" . $this->db->escape($data['payment_address_2']) . "', payment_city = '" . $this->db->escape($data['payment_city']) . "', payment_postcode = '" . $this->db->escape($data['payment_postcode']) . "', payment_zone = '" . $this->db->escape($data['payment_zone']) . "', payment_zone_id = '" . (int)$data['payment_zone_id'] . "', payment_country = '" . $this->db->escape($data['payment_country']) . "', payment_country_id = '" . (int)$data['payment_country_id'] . "', payment_address_format = '" . $this->db->escape($data['payment_address_format']) . "', payment_method = '" . $this->db->escape($data['payment_method']) . "', comment = '" . $this->db->escape($data['comment']) . "', date_modified = NOW(), date_added = NOW()");

на
$this->db->query("INSERT INTO `" . DB_PREFIX . "order` SET store_id = '" . (int)$data['store_id'] . "', store_name = '" . $this->db->escape($data['store_name']) . "', store_url = '" . $this->db->escape($data['store_url']) . "', customer_id = '" . (int)$data['customer_id'] . "', customer_group_id = '" . (int)$data['customer_group_id'] . "', firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', email = '" . $this->db->escape($data['email']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', fax = '" . $this->db->escape($data['fax']) . "', total = '" . (float)$data['total'] . "', cost = '" . (float)$data['cost'] . "', language_id = '" . (int)$data['language_id'] . "', currency = '" . $this->db->escape($data['currency']) . "', currency_id = '" . (int)$data['currency_id'] . "', value = '" . (float)$data['value'] . "', coupon_id = '" . (int)$data['coupon_id'] . "', ip = '" . $this->db->escape($data['ip']) . "', shipping_firstname = '" . $this->db->escape($data['shipping_firstname']) . "', shipping_lastname = '" . $this->db->escape($data['shipping_lastname']) . "', shipping_company = '" . $this->db->escape($data['shipping_company']) . "', shipping_address_1 = '" . $this->db->escape($data['shipping_address_1']) . "', shipping_address_2 = '" . $this->db->escape($data['shipping_address_2']) . "', shipping_city = '" . $this->db->escape($data['shipping_city']) . "', shipping_postcode = '" . $this->db->escape($data['shipping_postcode']) . "', shipping_zone = '" . $this->db->escape($data['shipping_zone']) . "', shipping_zone_id = '" . (int)$data['shipping_zone_id'] . "', shipping_country = '" . $this->db->escape($data['shipping_country']) . "', shipping_country_id = '" . (int)$data['shipping_country_id'] . "', shipping_address_format = '" . $this->db->escape($data['shipping_address_format']) . "', shipping_method = '" . $this->db->escape($data['shipping_method']) . "', payment_firstname = '" . $this->db->escape($data['payment_firstname']) . "', payment_lastname = '" . $this->db->escape($data['payment_lastname']) . "', payment_company = '" . $this->db->escape($data['payment_company']) . "', payment_address_1 = '" . $this->db->escape($data['payment_address_1']) . "', payment_address_2 = '" . $this->db->escape($data['payment_address_2']) . "', payment_city = '" . $this->db->escape($data['payment_city']) . "', payment_postcode = '" . $this->db->escape($data['payment_postcode']) . "', payment_zone = '" . $this->db->escape($data['payment_zone']) . "', payment_zone_id = '" . (int)$data['payment_zone_id'] . "', payment_country = '" . $this->db->escape($data['payment_country']) . "', payment_country_id = '" . (int)$data['payment_country_id'] . "', payment_address_format = '" . $this->db->escape($data['payment_address_format']) . "', payment_method = '" . $this->db->escape($data['payment_method']) . "', comment = '" . $this->db->escape($data['comment']) . "', date_modified = NOW(), date_added = NOW()");

---------------------------------------------------------
6 В system/library/cart.php
6.1
      $product_data[$key] = array(
        'key'          => $key,
        'product_id'   => $product_query->row['product_id'],
        'name'         => $product_query->row['name'],
        'model'        => $product_query->row['model'],
'shipping'     => $product_query->row['shipping'],
        'image'        => $product_query->row['image'],
        'option'       => $option_data,
'download'     => $download_data,
        'quantity'     => $quantity,
        'minimum'      => $product_query->row['minimum'],
'subtract'     => $product_query->row['subtract'],
'stock'        => $stock,
        'price'        => ($price + $option_price),
        'total'        => ($price + $option_price) * $quantity,
        'tax_class_id' => $product_query->row['tax_class_id'],
        'weight'       => $product_query->row['weight'],
        'weight_class' => $product_query->row['weight_class'],
        'length'       => $product_query->row['length'],
'width'        => $product_query->row['width'],
'height'       => $product_query->row['height'],
        'length_class' => $product_query->row['length_class']
      );

на
$cost = $product_query->row['cost'];
      $product_data[$key] = array(
        'key'          => $key,
        'product_id'   => $product_query->row['product_id'],
        'name'         => $product_query->row['name'],
        'model'        => $product_query->row['model'],
'shipping'     => $product_query->row['shipping'],
        'image'        => $product_query->row['image'],
        'option'       => $option_data,
'download'     => $download_data,
        'quantity'     => $quantity,
        'minimum'      => $product_query->row['minimum'],
'subtract'     => $product_query->row['subtract'],
'stock'        => $stock,
        'price'        => ($price + $option_price),
        'total'        => ($price + $option_price) * $quantity,
'cost'        => ($cost + $option_price) * $quantity,
        'tax_class_id' => $product_query->row['tax_class_id'],
        'weight'       => $product_query->row['weight'],
        'weight_class' => $product_query->row['weight_class'],
        'length'       => $product_query->row['length'],
'width'        => $product_query->row['width'],
'height'       => $product_query->row['height'],
        'length_class' => $product_query->row['length_class']
      );

-------------------------------------------------------------------------------
7 в catalog/controller/checkout/guest_step_3.php и confirm.php
foreach ($this->cart->getProducts() as $product) {
      $option_data = array();

      foreach ($product['option'] as $option) {
        $option_data[] = array(
'product_option_value_id' => $option['product_option_value_id'],   
          'name'                    => $option['name'],
          'value'                   => $option['value'],
  'prefix'                  => $option['prefix']
        );
      }

      $product_data[] = array(
        'product_id' => $product['product_id'],
'name'       => $product['name'],
        'model'      => $product['model'],
        'option'     => $option_data,
'download'   => $product['download'],
'quantity'   => $product['quantity'],
'subtract'   => $product['subtract'],
'price'      => $product['price'],
        'total'      => $product['total'],
'tax'        => $this->tax->getRate($product['tax_class_id'])
      );
    }

$data['products'] = $product_data;
$data['totals'] = $total_data;
$data['comment'] = $this->session->data['comment'];
$data['total'] = $total;
$data['language_id'] = $this->config->get('config_language_id');
$data['currency_id'] = $this->currency->getId();
$data['currency'] = $this->currency->getCode();
$data['value'] = $this->currency->getValue($this->currency->getCode());

на
$cost=0;
foreach ($this->cart->getProducts() as $product) {
      $option_data = array();

      foreach ($product['option'] as $option) {
        $option_data[] = array(
'product_option_value_id' => $option['product_option_value_id'],   
          'name'                    => $option['name'],
          'value'                   => $option['value'],
  'prefix'                  => $option['prefix']
        );
      }

      $product_data[] = array(
        'product_id' => $product['product_id'],
'name'       => $product['name'],
        'model'      => $product['model'],
        'option'     => $option_data,
'download'   => $product['download'],
'quantity'   => $product['quantity'],
'subtract'   => $product['subtract'],
'price'      => $product['price'],
        'total'      => $product['total'],
'tax'        => $this->tax->getRate($product['tax_class_id'])
      );
$cost += $product['cost'];
    }

$data['products'] = $product_data;
$data['totals'] = $total_data;
$data['comment'] = $this->session->data['comment'];
$data['total'] = $total;
$data['cost'] = $cost;
$data['language_id'] = $this->config->get('config_language_id');
$data['currency_id'] = $this->currency->getId();
$data['currency'] = $this->currency->getCode();
$data['value'] = $this->currency->getValue($this->currency->getCode());

----------------------------------------------------------------------------------------------