|
|
@@ -8,21 +8,21 @@ class Bill
|
|
|
{
|
|
|
$this->db = new Database();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
function create($bill_id, $value)
|
|
|
{
|
|
|
$query = "INSERT INTO ".$this->db->bill_table." VALUES('".$bill_id."'";
|
|
|
for($i = 0; $i < count($value); $i++)
|
|
|
$query .= ", '".$value[$i]."'";
|
|
|
$query .= ")";
|
|
|
-
|
|
|
+
|
|
|
$this->db->query($query);
|
|
|
-
|
|
|
+
|
|
|
$query = "SELECT bill_id from ".$this->db->bill_table." ORDER BY bill_id DESC";
|
|
|
$tmp = $this->db->fetchRows($this->db->query($query));
|
|
|
return $tmp[0][0];
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
function update($bill_id, $value)
|
|
|
{
|
|
|
$query = "UPDATE ".$this->db->bill_table." SET ";
|
|
|
@@ -31,30 +31,30 @@ class Bill
|
|
|
$query .= "date='".$value[2]."', ";
|
|
|
$query .= "assistant_id='".$value[3]."', ";
|
|
|
$query .= "bill_number='".$value[4]."' ";
|
|
|
-
|
|
|
+
|
|
|
$query .= "WHERE bill_id='".$bill_id."'";
|
|
|
$this->db->query($query);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
function setNumber($bill_id)
|
|
|
{
|
|
|
$data = $this->get($bill_id);
|
|
|
-
|
|
|
+
|
|
|
$query = "UPDATE ".$this->db->bill_table." SET ";
|
|
|
$query .= "bill_number='".$this->getNextFreeNumberByAssistant($data[0][4])."' ";
|
|
|
-
|
|
|
+
|
|
|
$query .= "WHERE bill_id='".$bill_id."'";
|
|
|
-
|
|
|
+
|
|
|
$this->db->query($query);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
function delete($bill_id)
|
|
|
{
|
|
|
$query = "DELETE FROM ".$this->db->bill_table." WHERE bill_id='$bill_id'";
|
|
|
-
|
|
|
+
|
|
|
$this->db->query($query);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
function get($bill_id = "", $row_names = array(), $search = "")
|
|
|
{
|
|
|
if($bill_id == "")
|
|
|
@@ -68,35 +68,35 @@ class Bill
|
|
|
$query .= ", ".$row_names[$i];
|
|
|
$query .= " FROM ".$this->db->bill_table.", ".$this->db->customer_table;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$query .= " WHERE bill.customer_id=customer.customer_id ";
|
|
|
if($search != "")
|
|
|
$query .= " AND ( ".$search." )";
|
|
|
-
|
|
|
+
|
|
|
$query .= " ORDER BY bill_number ASC";
|
|
|
-
|
|
|
+
|
|
|
return $this->db->fetchRows($this->db->query($query));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
$query = "SELECT * FROM ".$this->db->bill_table." WHERE bill_id='".$bill_id."'";
|
|
|
$query .= " ORDER BY bill_number ASC";
|
|
|
-
|
|
|
+
|
|
|
return $this->db->fetchRows($this->db->query($query));
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
function getNextFreeNumberByAssistant($assistant_id)
|
|
|
{
|
|
|
$query = "SELECT bill_number FROM ".$this->db->bill_table." WHERE assistant_id='".$assistant_id."' ORDER BY bill_number DESC";
|
|
|
$result = $this->db->fetchRows($this->db->query($query));
|
|
|
return $result[0][0]+1;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
function hasTimestamp($timestamp)
|
|
|
{
|
|
|
$query = "SELECT * FROM ".$this->db->bill_table." WHERE timestamp='".$timestamp."'";
|
|
|
-
|
|
|
+
|
|
|
if(count($this->db->fetchRows($this->db->query($query))) > 0)
|
|
|
return True;
|
|
|
else
|