olshop/application/models/Transaction.php

65 lines
1.8 KiB
PHP
Raw Normal View History

2020-01-02 23:12:35 +07:00
<?php
class Transaction extends CI_Model{
function get_all(){
$query = $this->db->get('transaksi');
return $query->row();
//return $query->result_array();
}
function get_order()
{
$q = "SELECT s.transaksi as id,p.nama,p.kota_kab,p.provinsi,sum(s.qty) as jumlah,";
$q .= "t.total_harga,DATE_FORMAT(t.tanggal_order,'%d %b %Y') as tgl,t.status ";
$q .= "FROM sales s ";
$q .= "LEFT JOIN profil p ON s.pembeli = p.id ";
$q .= "LEFT JOIN transaksi t ON s.transaksi = t.id ";
$q .= "WHERE t.type = 'ONLINE' ";
$q .= "GROUP BY s.transaksi;";
$query = $this->db->query($q);
return $query->result_array();
}
function get_single_order($id)
{
$query = $this->db->get_where('sales', array('transaksi' => $id),1);
$idp = $query->result_array();
$query = $this->db->get_where('profil', array('id' => $idp[0]['pembeli']));
$result['profil'] = $query->result_array();
$query = $this->db->get_where('transaksi', array('id' => $id));
$result['transaksi'] = $query->result_array();
$q = "SELECT b.nama,s.qty,b.harga FROM sales s ";
$q .= "LEFT JOIN barang b ON s.barang=b.id ";
$q .= "WHERE s.transaksi=".$id.";";
$query = $this->db->query($q);
$result['barang'] = $query->result_array();
return $result;
}
function pending_order()
{
$this->db->select('count(*) as ttl');
$query = $this->db->get_where('transaksi', array('status' => 'pending','type' => 'online'));
return $query->row();
}
function update_order($id,$status)
{
$this->db->set('status', $status);
$this->db->where('id', $id);
$this->db->update('transaksi');
}
function tambah_trans($data)
{
if($this->db->insert('transaksi',$data)){
return $this->db->insert_id();
}else return 0;
}
function tambah_sales($data)
{
return $this->db->insert('sales',$data);
}
}
?>