<?php
require_once(PATH_TABLES . "customer/CustomerSoftwareTable.php");
require_once(PATH_MODELS . "base/MasterBase.php");

class CustomerSoftwareClass extends MasterBase
{
    function __construct($db)
    {
        $this->db       = $db;
        $this->tbl      = CustomerSoftwareTable::C_TABLE;
        $this->fldid2   = CustomerSoftwareTable::C_ID;
        $this->fldid    = CustomerSoftwareTable::C_CUS_SOFTWARE_ID;
    }
    function __destruct()
    {
    }

    function getCustomerSoftware($id)
    {
        $sql = "SELECT " .
                    " cus.".CustomerSoftwareTable::C_CUS_SOFTWARE_ID.",".
                    " cus.".CustomerSoftwareTable::C_SOFTWARE.",".
                    " soft.".SoftwareTable::C_DESC.",".
                    " cus.".CustomerSoftwareTable::C_VERSION.",".
                    " cus.".CustomerSoftwareTable::C_USER.",".
                    " cus.".CustomerSoftwareTable::C_TYPE.",".
                    " cus.".CustomerSoftwareTable::C_LIVE_DATE.",".
                    " cus.".CustomerSoftwareTable::C_RENEW_DATE."".
                " FROM " . CustomerSoftwareTable::C_TABLE . " cus " .
                " LEFT JOIN " . SoftwareTable::C_TABLE . " soft ON soft." . SoftwareTable::C_ID . " = cus." . CustomerSoftwareTable::C_SOFTWARE .
                " WHERE " . CustomerSoftwareTable::C_ID . " = " . $id;
        
        $rows = $this->db->getTable($sql);

        if (!is_null($rows) && count($rows) > 0) {
            return $rows;
        }

        return null;
    }

    function deleteCustomerSoftwareBySoftwareId($id, $contactId)
    {
        $sql = "DELETE FROM " . CustomerSoftwareTable::C_TABLE .
            " WHERE " . CustomerSoftwareTable::C_ID . " = " . $id;

        return $this->db->executeSql($sql);
    }
    function deleteCustomerSoftware($id)
    {
        $sql = "DELETE FROM " . CustomerSoftwareTable::C_TABLE .
            " WHERE " . CustomerSoftwareTable::C_ID . " = " . $id;

        return $this->db->executeSql($sql);
    }
}
