[php] yyyy
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
- class AssetRegistration {
- public static function listCompany($req) {
- $page = $req['page'] ? (int)($req['page']) : 1;
- $rows = $req['rows'] ? (int)($req['rows']) : 100;
- $start = (($rows * $page) - $rows);
- $q = $req['q'] ? $req['q'] : '';
- $current = $req['current'] ? $req['current'] : 0;
- $id = $req['id'] ? $req['id'] : 0;
- $primary = "com.id";
- $condition = "
- ".($id ? " AND $primary = $id " : '')."
- ".($q ? " AND (com.name LIKE '%$q%' ) " : "")."
- AND com.asset_code <> ''
- ";
- $data = " com.* ";
- $table = " tb_company AS com ";
- $join = " ";
- $orderby = " ORDER BY $primary DESC ";
- $limit = $req['page'] == 0 || $req['page'] == "0" ? '' : " LIMIT $start,$rows ";
- $UNION = !$q ? ($current ? "UNION ( SELECT $data FROM $table $join WHERE $primary = $current ) " : "") : "";
- $sql = "SELECT COUNT($primary) AS total FROM $table $join WHERE 1 $condition";
- $res['total'] = $GLOBALS['conn']->getOne($sql);
- $sql = "( SELECT $data FROM $table $join WHERE 1 $condition $orderby $limit ) $UNION ";
- $res['rows'] = $GLOBALS['conn']->getAll($sql);
- return $res;
- }
- public static function listTPM($req) {
- $page = $req['page'] ? (int)($req['page']) : 1;
- $rows = $req['rows'] ? (int)($req['rows']) : 10;
- $start = (($rows * $page) - $rows);
- $q = $req['q'] ? $req['q'] : '';
- $current = $req['current'] ? $req['current'] : 0;
- $id = $req['id'] ? $req['id'] : 0;
- $primary = "tpm.id";
- $condition = "
- ".($id ? " AND $primary = $id " : '')."
- ".($q ? " AND ( OR tpm.name_th LIKE '%$q%' OR tpm.code LIKE '%$q%' )" : "")."
- ";
- $data = "
- tpm.id AS id,
- tpm.code AS code,
- tpm.name_th AS title,
- tpm.status AS status,
- '0' AS isRemove
- ";
- $table = " tb_tpm_inventory AS tpm ";
- $join = " ";
- $orderby = " ORDER BY $primary DESC ";
- $limit = $req['page'] == 0 || $req['page'] == "0" ? '' : " LIMIT $start,$rows ";
- $UNION = !$q ? ($current ? "UNION ( SELECT $data FROM $table $join WHERE $primary = $current ) " : "") : "";
- $sql = "SELECT COUNT($primary) AS total FROM $table $join WHERE 1 $condition";
- $res['total'] = $GLOBALS['conn']->getOne($sql);
- $sql = "( SELECT $data FROM $table $join WHERE 1 $condition $orderby $limit ) $UNION ";
- $res['rows'] = $GLOBALS['conn']->getAll($sql);
- return $res;
- }
- public static function listCST($req) {
- $page = $req['page'] ? (int)($req['page']) : 1;
- $rows = $req['rows'] ? (int)($req['rows']) : 10;
- $start = (($rows * $page) - $rows);
- $q = $req['q'] ? $req['q'] : '';
- $current = $req['current'] ? $req['current'] : 0;
- $id = $req['id'] ? $req['id'] : 0;
- $primary = "cst.id";
- $condition = "
- ".($id ? " AND $primary = $id " : '')."
- ".($q ? " AND ( OR cst.code LIKE '%$q%' OR cst.title LIKE '%$q%' )" : "")."
- ";
- $data = "
- cst.id AS id,
- cst.code AS code,
- cst.title AS title,
- '' AS status,
- cst.is_remove AS isRemove
- ";
- $table = " tb_cst_inventory_item AS cst ";
- $join = " ";
- $orderby = " ORDER BY $primary DESC ";
- $limit = $req['page'] == 0 || $req['page'] == "0" ? '' : " LIMIT $start,$rows ";
- $UNION = !$q ? ($current ? "UNION ( SELECT $data FROM $table $join WHERE $primary = $current ) " : "") : "";
- $sql = "SELECT COUNT($primary) AS total FROM $table $join WHERE 1 $condition";
- $res['total'] = $GLOBALS['conn']->getOne($sql);
- $sql = "( SELECT $data FROM $table $join WHERE 1 $condition $orderby $limit ) $UNION ";
- $res['rows'] = $GLOBALS['conn']->getAll($sql);
- return $res;
- }
- public static function listHRM($req) {
- $page = $req['page'] ? (int)($req['page']) : 1;
- $rows = $req['rows'] ? (int)($req['rows']) : 10;
- $start = (($rows * $page) - $rows);
- $q = $req['q'] ? $req['q'] : '';
- $current = $req['current'] ? $req['current'] : 0;
- $id = $req['id'] ? $req['id'] : 0;
- $primary = "hrm.id";
- $condition = "
- ".($id ? " AND $primary = $id " : '')."
- ".($q ? " AND ( OR hrm.code LIKE '%$q%' OR hrm.name LIKE '%$q%' )" : "")."
- ";
- $data = "
- hrm.id AS id,
- hrm.code AS code,
- hrm.name AS title,
- hrm.status AS status,
- '0' AS isRemove
- ";
- $table = " tb_global_inventory AS hrm ";
- $join = " ";
- $orderby = " ORDER BY $primary DESC ";
- $limit = $req['page'] == 0 || $req['page'] == "0" ? '' : " LIMIT $start,$rows ";
- $UNION = !$q ? ($current ? "UNION ( SELECT $data FROM $table $join WHERE $primary = $current ) " : "") : "";
- $sql = "SELECT COUNT($primary) AS total FROM $table $join WHERE 1 $condition";
- $res['total'] = $GLOBALS['conn']->getOne($sql);
- $sql = "( SELECT $data FROM $table $join WHERE 1 $condition $orderby $limit ) $UNION ";
- $res['rows'] = $GLOBALS['conn']->getAll($sql);
- return $res;
- }
- public static function listITS($req) {
- $page = $req['page'] ? (int)($req['page']) : 1;
- $rows = $req['rows'] ? (int)($req['rows']) : 10;
- $start = (($rows * $page) - $rows);
- $q = $req['q'] ? $req['q'] : '';
- $current = $req['current'] ? $req['current'] : 0;
- $id = $req['id'] ? $req['id'] : 0;
- $primary = "its.id";
- $condition = "
- ".($id ? " AND $primary = $id " : '')."
- ".($q ? " AND ( its.code LIKE '%$q%' OR its.title LIKE '%$q%' OR its.model LIKE '%$q%' )" : "")."
- ";
- $data = "
- its.id AS id,
- its.code AS code,
- its.model AS title,
- its.status AS status,
- its.isRemove AS isRemove
- ";
- $table = " tb_its_inventory AS its ";
- $join = " ";
- $orderby = " ORDER BY $primary DESC ";
- $limit = $req['page'] == 0 || $req['page'] == "0" ? '' : " LIMIT $start,$rows ";
- $UNION = !$q ? ($current ? "UNION ( SELECT $data FROM $table $join WHERE $primary = $current ) " : "") : "";
- $sql = "SELECT COUNT($primary) AS total FROM $table $join WHERE 1 $condition";
- $res['total'] = $GLOBALS['conn']->getOne($sql);
- $sql = "( SELECT $data FROM $table $join WHERE 1 $condition $orderby $limit ) $UNION ";
- $res['rows'] = $GLOBALS['conn']->getAll($sql);
- return $res;
- }
- public static function listQAS($req) {
- $page = $req['page'] ? (int)($req['page']) : 1;
- $rows = $req['rows'] ? (int)($req['rows']) : 10;
- $start = (($rows * $page) - $rows);
- $q = $req['q'] ? $req['q'] : '';
- $current = $req['current'] ? $req['current'] : 0;
- $id = $req['id'] ? $req['id'] : 0;
- $primary = "qas.id";
- $condition = "
- ".($id ? " AND $primary = $id " : '')."
- ".($q ? " AND ( qas.code LIKE '%$q%' OR qas.title LIKE '%$q%' OR qas.model LIKE '%$q%' )" : "")."
- ";
- $data = "
- qas.id AS id,
- qas.code AS code,
- qas.title AS title,
- qas.status AS status,
- '0' AS isRemove
- ";
- $table = " tb_qas_inventory AS qas ";
- $join = " ";
- $orderby = " ORDER BY $primary DESC ";
- $limit = $req['page'] == 0 || $req['page'] == "0" ? '' : " LIMIT $start,$rows ";
- $UNION = !$q ? ($current ? "UNION ( SELECT $data FROM $table $join WHERE $primary = $current ) " : "") : "";
- $sql = "SELECT COUNT($primary) AS total FROM $table $join WHERE 1 $condition";
- $res['total'] = $GLOBALS['conn']->getOne($sql);
- $sql = "( SELECT $data FROM $table $join WHERE 1 $condition $orderby $limit ) $UNION ";
- $res['rows'] = $GLOBALS['conn']->getAll($sql);
- return $res;
- }
- public static function listType($req) {
- $page = $req['page'] ? (int)($req['page']) : 1;
- $rows = $req['rows'] ? (int)($req['rows']) : 99999;
- $start = (($rows * $page) - $rows);
- $q = $req['q'] ? $req['q'] : '';
- $current = $req['current'] ? $req['current'] : 0;
- $id = $req['id'] ? $req['id'] : 0;
- $primary = "id";
- $condition = "
- ".($id ? " AND $primary = $id " : '')."
- ".($q ? " AND ( title LIKE '%$q%' OR title_eng LIKE '%$q%' )" : "")."
- ";
- $data = " * ";
- $table = " tb_asset_type ";
- $join = " ";
- $orderby = " ORDER BY $primary DESC ";
- $limit = $req['page'] == 0 || $req['page'] == "0" ? '' : " LIMIT $start,$rows ";
- $UNION = !$q ? ($current ? "UNION ( SELECT $data FROM $table $join WHERE $primary = $current ) " : "") : "";
- $sql = "SELECT COUNT($primary) AS total FROM $table $join WHERE 1 $condition";
- $res['total'] = $GLOBALS['conn']->getOne($sql);
- $sql = "( SELECT $data FROM $table $join WHERE 1 $condition $orderby $limit ) $UNION ";
- $res['rows'] = $GLOBALS['conn']->getAll($sql);
- return $res;
- }
- public static function listSub($req) {
- $page = $req['page'] ? (int)($req['page']) : 1;
- $rows = $req['rows'] ? (int)($req['rows']) : 99999;
- $start = (($rows * $page) - $rows);
- $q = $req['q'] ? $req['q'] : '';
- $current = $req['current'] ? $req['current'] : 0;
- $id = $req['id'] ? $req['id'] : 0;
- if (!$req['type']) {
- return array('rows'=>array(),'total'=>0);
- }
- $primary = "id";
- $condition = "
- ".($id ? " AND $primary = $id " : '')."
- ".($q ? " AND ( title LIKE '%$q%' OR description LIKE '%$q%' )" : "")."
- AND status <> 'remove'
- ";
- $data = " * ";
- $table = " tb_asset_category ";
- $join = " ";
- $orderby = " ORDER BY $primary DESC ";
- $limit = $req['page'] == 0 || $req['page'] == "0" ? '' : " LIMIT $start,$rows ";
- $UNION = !$q ? ($current ? "UNION ( SELECT $data FROM $table $join WHERE $primary = $current ) " : "") : "";
- $sql = "SELECT COUNT($primary) AS total FROM $table $join WHERE 1 $condition";
- $res['total'] = $GLOBALS['conn']->getOne($sql);
- $sql = "( SELECT $data FROM $table $join WHERE 1 $condition $orderby $limit ) $UNION ";
- $res['rows'] = $GLOBALS['conn']->getAll($sql);
- return $res;
- }
- public static function list($req) {
- $page = $req['page'] ? (int)($req['page']) : 1;
- $rows = $req['rows'] ? (int)($req['rows']) : 100;
- $start = (($rows * $page) - $rows);
- $q = $req['q'] ? $req['q'] : '';
- $current = $req['current'] ? $req['current'] : 0;
- $id = $req['id'] ? $req['id'] : 0;
- $primary = "ar.id";
- $condition = "
- ".($id ? " AND $primary = $id " : "")."
- ".($q ? " AND ( ar.title LIKE '%$q%' OR ar.code LIKE '%$q%' ) " : "")."
- ".($req['fromDate'] ? " AND ar.entry_date >= '".$req['fromDate']." 00:00:00' " : "")."
- ".($req['toDate'] ? " AND ar.entry_date <= '".$req['toDate']." 23:59:59' " : "")."
- ".($req['owner'] ? " AND dep.code LIKE '%".$req['owner']."%' ": "")."
- ".($req['code'] ? " AND ar.code LIKE '%".$req['code']."%' " : "")."
- ".($req['title'] ? " AND ar.title LIKE '%".$req['title']."%' " : "")."
- ".($req['status'] ? " AND ar.status = '%".$req['status']."%' " : "")."
- AND ar.status <> 'remove'
- ";
- $data = "
- ar.*,
- DATE_FORMAT(ar.entry_date, '%Y-%m-%d') AS entry_date,
- DATE_FORMAT(ar.update_date, '%Y-%m-%d') AS update_date,
- ar.code AS code,
- CONCAT(entry_em.firstname,' ',entry_em.lastname) AS entryFullname,
- dep.code AS depCode,
- dep.title AS depTitle,
- ( CASE
- WHEN dep.code = 'TPM' THEN (SELECT code FROM tb_tpm_inventory AS tpm WHERE ar.asset = tpm.id)
- WHEN dep.code = 'CST' THEN (SELECT code FROM tb_cst_inventory_item AS cst WHERE ar.asset = cst.id)
- WHEN dep.code = 'HRM' THEN (SELECT code FROM tb_global_inventory AS hrm WHERE ar.asset = hrm.id)
- WHEN dep.code = 'ITS' THEN (SELECT code FROM tb_its_inventory AS its WHERE ar.asset = its.id)
- WHEN dep.code = 'QAS' THEN (SELECT code FROM tb_qas_inventory AS qas WHERE ar.asset = qas.id)
- ELSE ''
- END ) AS assetCode,
- ( CASE
- WHEN dep.code = 'TPM' THEN (SELECT status FROM tb_tpm_inventory AS tpm WHERE ar.asset = tpm.id)
- WHEN dep.code = 'CST' THEN ''
- WHEN dep.code = 'HRM' THEN (SELECT status FROM tb_global_inventory AS hrm WHERE ar.asset = hrm.id)
- WHEN dep.code = 'ITS' THEN (SELECT status FROM tb_its_inventory AS its WHERE ar.asset = its.id)
- WHEN dep.code = 'QAS' THEN (SELECT status FROM tb_qas_inventory AS qas WHERE ar.asset = qas.id)
- ELSE ''
- END ) AS assetStatus
- ";
- $table = " tb_asset_registration AS ar ";
- $join = "
- LEFT JOIN tb_employee AS entry_em ON entry_em.id = ar.entry_by
- LEFT JOIN tb_department AS dep ON dep.id = ar.owner
- ";
- $orderby = " ORDER BY $primary DESC ";
- $limit = $req['page'] == 0 || $req['page'] == "0" ? '' : " LIMIT $start,$rows ";
- $UNION = !$q ? ($current ? "UNION ( SELECT $data FROM $table $join WHERE $primary = $current ) " : "") : "";
- $sql = "SELECT COUNT($primary) AS total FROM $table $join WHERE 1 $condition";
- $res['total'] = $GLOBALS['conn']->getOne($sql);
- $sql = "( SELECT $data FROM $table $join WHERE 1 $condition $orderby $limit ) $UNION ";
- $res['rows'] = $GLOBALS['conn']->getAll($sql);
- return $res;
- }
- public static function insert($req) {
- $res = array('success' => false, 'errorMsg' => '');
- $req['entry_date'] = date('Y-m-d h:i:s');
- $req['entry_by'] = $_SESSION['user']['id'];
- if ($GLOBALS['conn']->AutoExecute('tb_asset_registration', $req, 'INSERT')){
- $req['id'] = $GLOBALS['conn']->insert_id();
- $res['row'] = $req;
- $res['status'] = true;
- } else {
- $res['errorMsg'] = $GLOBALS['conn']->mysql_error();
- }
- return $res;
- }
- public static function save($req) {
- $res = array('success' => false, 'errorMsg' => '');
- if (empty($req['id'])) {
- $res['errorMsg'] = "Error : object without id";
- return $res;
- }
- unset($req['current']);
- $req['update_by'] = $_SESSION['user']['id'];
- $req['update_date'] = date('Y-m-d h:i:s');
- if ($GLOBALS['conn']->autoExecute('tb_asset_registration', $req, 'UPDATE', 'id=' . $req['id'])){
- $res['row'] = $req;
- $res['success'] = true;
- } else {
- $res['errorMsg'] = $GLOBALS['conn']->mysql_error();
- }
- return $res;
- }
- public static function remove($req) {
- $req = array(
- 'id' => $req['id'],
- 'status' => 'remove'
- );
- AssetRegistration::save($req);
- }
- }
Editor
You can edit this paste and save as new: