everseiko/application/models/M_form.php
2020-01-02 23:02:57 +07:00

211 lines
4.2 KiB
PHP

<?php
class M_form extends CI_Model{
function insertcustomer($data)
{
$this->db->insert('customer',$data);
return $this->db->insert_id();
}
function insertvisit($data)
{
$this->db->insert('visit',$data);
return $this->db->insert_id();
}
function insertvehicle($data)
{
$this->db->insert('customer_vehicle',$data);
return $this->db->affected_rows();
}
function insertrecommended($data)
{
$this->db->insert('recommendation',$data);
return $this->db->affected_rows();
}
function insertpurchase($data)
{
$this->db->insert('purchase',$data);
return $this->db->affected_rows();
}
function getFormSaved()
{
$query=$this->db->query("SELECT * FROM `visit` WHERE `isApprove` = '1' ORDER BY id DESC");
return $query->result();
}
function getFormPending()
{
$query=$this->db->query("SELECT * FROM `visit` WHERE `isApprove` = '0' ORDER BY id DESC");
return $query->result();
}
function getVisit($id)
{
$q="SELECT * FROM visit WHERE id='$id'";
$query=$this->db->query($q);
return $query->row();
}
function getCust($id)
{
$sql="SELECT * FROM customer WHERE id = (SELECT id_customer FROM visit WHERE id='$id')";
$query=$this->db->query($sql);
return $query->row();
}
function getVehicle($id)
{
$sql="SELECT * FROM customer_vehicle WHERE id_visit='$id'";
//$query=$this->db->query($q);
$sql = mysql_query($sql);
while ($array = mysql_fetch_assoc($sql)) {
$rs[] = $array;
}
if (empty($rs))
{
$rs = '';
}
return $rs;
//return $query->row();
}
function getPurchase($id)
{
$sql="SELECT * FROM purchase WHERE id_visit='$id'";
//$query=$this->db->query($q);
$sql = mysql_query($sql);
while ($array = mysql_fetch_assoc($sql)) {
$rs[] = $array;
}
if (empty($rs))
{
$rs = '';
}
return $rs;
//return $query->row();
}
function getRecommendation($id)
{
$sql="SELECT * FROM recommendation WHERE id_visit='$id'";
//$query=$this->db->query($q);
$sql = mysql_query($sql);
while ($array = mysql_fetch_assoc($sql)) {
$rs[] = $array;
}
if (empty($rs))
{
$rs = '';
}
return $rs;
//return $query->row();
}
function getPictures($id)
{
$sql="SELECT * FROM pictures WHERE id_visit='$id'";
//$query=$this->db->query($q);
$sql = mysql_query($sql);
while ($array = mysql_fetch_assoc($sql)) {
$rs[] = $array;
}
if (empty($rs))
{
$rs = '';
}
return $rs;
}
function isApprove($data, $id)
{
$idc = $this->getCustomer($id);
$this->updateCustomer($idc['id_customer'],$data['id_customer']);
$this->db->where('id', $id);
$this->db->update('visit', $data);
}
function getCustomer($id)
{
$sql="SELECT id_customer FROM visit WHERE id='$id'";
$sql = mysql_query($sql);
//echo $sql;
$rs = mysql_fetch_assoc($sql);
return $rs;
}
function updateCustomer($idc,$id)
{
$data = array (
'id_customer' => $id
);
$this->db->where('id', $idc);
$this->db->update('customer', $data);
}
function searchcustomer($clue)
{
$sql="SELECT id,nama FROM customer WHERE nama like '%$clue%'";
//$query=$this->db->query($q);
$sql = mysql_query($sql);
while ($array = mysql_fetch_assoc($sql)) {
$rs[] = $array;
}
if (empty($rs))
{
$rs = '';
}
return $rs;
}
function newUser($data)
{
$this->db->insert('user',$data);
return $this->db->affected_rows();
}
function getUser()
{
$query=$this->db->query("SELECT * FROM `user`");
return $query->result();
}
function delete_user($id)
{
$query=$this->db->query("DELETE FROM user WHERE username='$id'");
}
function getSellout()
{
$query=$this->db->query("SELECT * FROM `sellingout`");
return $query->result();
}
function newSellout($data)
{
$this->db->insert('sellingout',$data);
return $this->db->affected_rows();
}
function getVolume()
{
$query=$this->db->query("SELECT * FROM `volume`");
return $query->result();
}
function newVolume($data)
{
$this->db->insert('volume',$data);
return $this->db->affected_rows();
}
function getWilayah()
{
$query=$this->db->query("SELECT * FROM `wilayah`");
return $query->result();
}
}