HOME


Mini Shell 1.0
DIR: /home/islapiiu/sites/shiny/class/
Upload File :
Current File : /home/islapiiu/sites/shiny/class/Invoice.php
<?php

/**
 * Description of Invoice
 *
 * @author sublime
 */
class Invoice {

    public $id;
    public $date;
    public $created_at;
    public $customer;
    public $customer_address;
    public $customer_phone;
    public $function_date;
    public $number_of_pax;

    public function __construct($id) {
        if ($id) {

            $query = "SELECT "
                    . "`id`,"
                    . "`date`,"
                    . "`created_at`,"
                    . "`customer`,"
                    . "`customer_address`,"
                    . "`customer_phone`,"
                    . "`function_date`,"
                    . "`number_of_pax`"
                    . " FROM "
                    . "`invoice`"
                    . " WHERE "
                    . "`id`=" . $id;

            $db = new Database();

            $result = mysql_fetch_array($db->readQuery($query));

            $this->id = $result['id'];
            $this->date = $result['date'];
            $this->created_at = $result['created_at'];
            $this->customer = $result['customer'];
            $this->customer_address = $result['customer_address'];
            $this->customer_phone = $result['customer_phone'];
            $this->function_date = $result['function_date'];
            $this->number_of_pax = $result['number_of_pax'];

            return $result;
        }
    }

    public function create() {

        $query = "INSERT INTO `invoice` ("
                . "date, "
                . "created_at, "
                . "customer, "
                . "customer_address, "
                . "customer_phone, "
                . "function_date, "
                . "number_of_pax"
                . ") VALUES  ("
                . "'" . $this->date . "',"
                . " '" . $this->created_at . "',"
                . " '" . $this->customer . "',"
                . " '" . $this->customer_address . "',"
                . " '" . $this->customer_phone . "',"
                . " '" . $this->function_date . "',"
                . " '" . $this->number_of_pax . "'"
                . ")";

        $db = new Database();

        $result = $db->readQuery($query);
        if ($result) {
            $last_id = mysql_insert_id();
            return $this->__construct($last_id);
        } else {
            return FALSE;
        }
    }

    public function all() {

        $query = "SELECT * FROM `invoice`";
        $db = new Database();
        $result = $db->readQuery($query);
        $array_res = array();

        while ($row = mysql_fetch_array($result)) {
            array_push($array_res, $row);
        }

        return $array_res;
    }

    public function filter($date_from, $date_to, $invoice) {


        $w = array();
        $where = '';

        if (!empty($date_from)) {
            if (!empty($date_from) && !empty($date_to)) {
                $w[] = "`date` BETWEEN '" . $date_from . "' AND '" . $date_to . "' ";
            } else {
                $w[] = "`date` = '" . $date_from . "'";
            }
        }

        if (!empty($invoice)) {
            $w[] = "`id` = '" . $invoice . "'";
        }

        if (count($w)) {
            $where = 'WHERE ' . implode(' AND ', $w);
        }

        $query = "SELECT * FROM `invoice` " . $where . " ORDER BY `id` ASC";

        $db = new Database();
        $result = $db->readQuery($query);
        $array_res = array();

        while ($row = mysql_fetch_array($result)) {
            array_push($array_res, $row);
        }

        return $array_res;
    }

}