Trong models : Sales_models  thêm 1 function

public function getAllSaleByCompanyID($id)
  {
    
    $this->db->select('sales.date,sale_items.product_name ,sale_items.quantity,sale_items.product_unit_code,product_variants.name')
      ->join('sale_items','sales.id = sale_items.sale_id','left')
      ->join('product_variants','sale_items.option_id = product_variants.id','left')
      ->order_by('sales.date', 'DESC')
      ->where('sales.customer_id',$id);
      
    $q = $this->db->get('sales',10);
     if ($q->num_rows() > 0) {
            foreach (($q->result()) as $row) {
                $data[] = $row;
            }
            return $data;
        }
    
  }

Trong Controllers : Customers thêm vào function views($id = NULL)

$data_sale = $this->sales_model->getAllSaleByCompanyID($id);
$this->data['data_sale'] = $data_sale;

và trong function __construct() thêm

$this->load->admin_model('sales_model');

 

Trong views thêm :

<?php if ($data_sale) { ?>
          <h2>Lịch sử mua hàng</h2>
          <table class="table table-striped table-bordered" style="margin-bottom:0;">
            <thead>
              <tr>
                <td>Ngày mua</td>
                <td>Sản phẩm</td>
                <td>Số lượng</td>
              </tr>
              </thead>
            <tbody>
              <?php
              foreach ($data_sale as $row){
              
              ?>
              <tr>
                <td><?= $row->date; ?></td>
                <td><?= $row->product_name; ?>(<?= $row->name;?>)</strong></td>
                <td><?= $row->quantity; ?></strong></td>
              </tr>
            <?php
              }
            ?>
            </tbody>
          </table>
        <?php 		
        }
        ?>

Ở đoạn :<div class=”modal-body”>

Posted in dev

Leave a Reply

Your email address will not be published. Required fields are marked *