[php] yyyy

Viewer

  1.   class AssetRegistration {
  2.     public static function listCompany($req) {
  3.       $page = $req['page'] ? (int)($req['page']) : 1;
  4.       $rows = $req['rows'] ? (int)($req['rows']) : 100;
  5.       $start = (($rows * $page) - $rows);
  6.  
  7.       $q = $req['q'] ? $req['q'] : '';
  8.       $current = $req['current'] ? $req['current'] : 0;
  9.       $id = $req['id'] ? $req['id'] : 0;
  10.  
  11.       $primary = "com.id";
  12.  
  13.       $condition = 
  14.         ".($id " AND $primary = $id " : '')."
  15.         ".($q " AND (com.name LIKE '%$q%' ) " : "").
  16.         AND com.asset_code <> ''
  17.       ";
  18.  
  19.       $data = " com.* ";
  20.  
  21.       $table = " tb_company AS com ";
  22.       $join = " ";
  23.  
  24.       $orderby = " ORDER BY $primary DESC ";
  25.       $limit = $req['page'] == 0 || $req['page'] == "0" ? '' : " LIMIT $start,$rows ";
  26.       $UNION = !$q ($current "UNION ( SELECT $data FROM $table $join WHERE $primary = $current ) " : "") : "";
  27.     
  28.       $sql = "SELECT COUNT($primary) AS total FROM $table $join WHERE 1 $condition";
  29.       $res['total'] = $GLOBALS['conn']->getOne($sql);
  30.  
  31.       $sql = "( SELECT $data FROM $table $join WHERE 1 $condition $orderby $limit ) $UNION ";
  32.       $res['rows'] = $GLOBALS['conn']->getAll($sql);
  33.  
  34.       return $res;
  35.     }
  36.     public static function listTPM($req) {
  37.       $page = $req['page'] ? (int)($req['page']) : 1;
  38.       $rows = $req['rows'] ? (int)($req['rows']) : 10;
  39.       $start = (($rows * $page) - $rows);
  40.  
  41.       $q = $req['q'] ? $req['q'] : '';
  42.       $current = $req['current'] ? $req['current'] : 0;
  43.       $id = $req['id'] ? $req['id'] : 0;
  44.  
  45.       $primary = "tpm.id";
  46.  
  47.       $condition = 
  48.         ".($id " AND $primary = $id " : '')."
  49.         ".($q " AND ( OR tpm.name_th LIKE '%$q%' OR tpm.code LIKE '%$q%' )" : "")."
  50.       ";
  51.  
  52.       $data = "
  53.         tpm.id AS id,
  54.         tpm.code AS code,
  55.         tpm.name_th AS title,
  56.         tpm.status AS status,
  57.         '0' AS isRemove
  58.       ";
  59.  
  60.       $table = " tb_tpm_inventory AS tpm ";
  61.       $join = " ";
  62.  
  63.       $orderby = " ORDER BY $primary DESC ";
  64.       $limit = $req['page'] == 0 || $req['page'] == "0" ? '' : " LIMIT $start,$rows ";
  65.       $UNION = !$q ($current "UNION ( SELECT $data FROM $table $join WHERE $primary = $current ) " : "") : "";
  66.     
  67.       $sql = "SELECT COUNT($primary) AS total FROM $table $join WHERE 1 $condition";
  68.       $res['total'] = $GLOBALS['conn']->getOne($sql);
  69.  
  70.       $sql = "( SELECT $data FROM $table $join WHERE 1 $condition $orderby $limit ) $UNION ";
  71.       $res['rows'] = $GLOBALS['conn']->getAll($sql);
  72.  
  73.       return $res;
  74.     }
  75.     public static function listCST($req) {
  76.       $page = $req['page'] ? (int)($req['page']) : 1;
  77.       $rows = $req['rows'] ? (int)($req['rows']) : 10;
  78.       $start = (($rows * $page) - $rows);
  79.  
  80.       $q = $req['q'] ? $req['q'] : '';
  81.       $current = $req['current'] ? $req['current'] : 0;
  82.       $id = $req['id'] ? $req['id'] : 0;
  83.  
  84.       $primary = "cst.id";
  85.  
  86.       $condition = 
  87.       ".($id " AND $primary = $id " : '')."
  88.       ".($q " AND ( OR cst.code LIKE '%$q%' OR cst.title LIKE '%$q%' )" : "")."
  89.       ";
  90.  
  91.       $data = "
  92.         cst.id AS id, 
  93.         cst.code AS code, 
  94.         cst.title AS title,
  95.         '' AS status,
  96.         cst.is_remove AS isRemove
  97.       ";
  98.  
  99.       $table = " tb_cst_inventory_item AS cst ";
  100.       $join = " ";
  101.  
  102.       $orderby = " ORDER BY $primary DESC ";
  103.       $limit = $req['page'] == 0 || $req['page'] == "0" ? '' : " LIMIT $start,$rows ";
  104.       $UNION = !$q ($current "UNION ( SELECT $data FROM $table $join WHERE $primary = $current ) " : "") : "";
  105.     
  106.       $sql = "SELECT COUNT($primary) AS total FROM $table $join WHERE 1 $condition";
  107.       $res['total'] = $GLOBALS['conn']->getOne($sql);
  108.  
  109.       $sql = "( SELECT $data FROM $table $join WHERE 1 $condition $orderby $limit ) $UNION ";
  110.       $res['rows'] = $GLOBALS['conn']->getAll($sql);
  111.  
  112.       return $res;
  113.     }
  114.     public static function listHRM($req) {
  115.       $page = $req['page'] ? (int)($req['page']) : 1;
  116.       $rows = $req['rows'] ? (int)($req['rows']) : 10;
  117.       $start = (($rows * $page) - $rows);
  118.  
  119.       $q = $req['q'] ? $req['q'] : '';
  120.       $current = $req['current'] ? $req['current'] : 0;
  121.       $id = $req['id'] ? $req['id'] : 0;
  122.  
  123.       $primary = "hrm.id";
  124.  
  125.       $condition = 
  126.         ".($id " AND $primary = $id " : '')."
  127.         ".($q " AND ( OR hrm.code LIKE '%$q%' OR hrm.name LIKE '%$q%' )" : "")."
  128.       ";
  129.  
  130.       $data = "
  131.         hrm.id AS id, 
  132.         hrm.code AS code, 
  133.         hrm.name AS title,
  134.         hrm.status AS status,
  135.         '0' AS isRemove
  136.       ";
  137.  
  138.       $table = " tb_global_inventory AS hrm ";
  139.       $join = " ";
  140.  
  141.       $orderby = " ORDER BY $primary DESC ";
  142.       $limit = $req['page'] == 0 || $req['page'] == "0" ? '' : " LIMIT $start,$rows ";
  143.       $UNION = !$q ($current "UNION ( SELECT $data FROM $table $join WHERE $primary = $current ) " : "") : "";
  144.     
  145.       $sql = "SELECT COUNT($primary) AS total FROM $table $join WHERE 1 $condition";
  146.       $res['total'] = $GLOBALS['conn']->getOne($sql);
  147.  
  148.       $sql = "( SELECT $data FROM $table $join WHERE 1 $condition $orderby $limit ) $UNION ";
  149.       $res['rows'] = $GLOBALS['conn']->getAll($sql);
  150.  
  151.       return $res;
  152.     }
  153.     public static function listITS($req) {
  154.       $page = $req['page'] ? (int)($req['page']) : 1;
  155.       $rows = $req['rows'] ? (int)($req['rows']) : 10;
  156.       $start = (($rows * $page) - $rows);
  157.  
  158.       $q = $req['q'] ? $req['q'] : '';
  159.       $current = $req['current'] ? $req['current'] : 0;
  160.       $id = $req['id'] ? $req['id'] : 0;
  161.  
  162.       $primary = "its.id";
  163.  
  164.       $condition = 
  165.         ".($id " AND $primary = $id " : '')."
  166.         ".($q " AND ( its.code LIKE '%$q%' OR its.title LIKE '%$q%' OR its.model LIKE '%$q%' )" : "")."
  167.       ";
  168.  
  169.       $data = "
  170.         its.id AS id, 
  171.         its.code AS code, 
  172.         its.model AS title,
  173.         its.status AS status,
  174.         its.isRemove AS isRemove
  175.       ";
  176.  
  177.       $table = " tb_its_inventory AS its ";
  178.       $join = " ";
  179.  
  180.  
  181.       $orderby = " ORDER BY $primary DESC ";
  182.       $limit = $req['page'] == 0 || $req['page'] == "0" ? '' : " LIMIT $start,$rows ";
  183.       $UNION = !$q ($current "UNION ( SELECT $data FROM $table $join WHERE $primary = $current ) " : "") : "";
  184.     
  185.       $sql = "SELECT COUNT($primary) AS total FROM $table $join WHERE 1 $condition";
  186.       $res['total'] = $GLOBALS['conn']->getOne($sql);
  187.  
  188.       $sql = "( SELECT $data FROM $table $join WHERE 1 $condition $orderby $limit ) $UNION ";
  189.       $res['rows'] = $GLOBALS['conn']->getAll($sql);
  190.  
  191.       return $res;
  192.  
  193.     }
  194.     public static function listQAS($req) {
  195.       $page = $req['page'] ? (int)($req['page']) : 1;
  196.       $rows = $req['rows'] ? (int)($req['rows']) : 10;
  197.       $start = (($rows * $page) - $rows);
  198.  
  199.       $q = $req['q'] ? $req['q'] : '';
  200.       $current = $req['current'] ? $req['current'] : 0;
  201.       $id = $req['id'] ? $req['id'] : 0;
  202.  
  203.       $primary = "qas.id";
  204.  
  205.       $condition = 
  206.         ".($id " AND $primary = $id " : '').
  207.         ".($q " AND ( qas.code LIKE '%$q%' OR qas.title LIKE '%$q%' OR qas.model LIKE '%$q%' )" : "")."
  208.       ";
  209.  
  210.       $data = "
  211.         qas.id AS id, 
  212.         qas.code AS code, 
  213.         qas.title AS title,
  214.         qas.status AS status,
  215.         '0' AS isRemove
  216.       ";
  217.  
  218.       $table = " tb_qas_inventory AS qas ";
  219.       $join = " ";
  220.  
  221.       $orderby = " ORDER BY $primary DESC ";
  222.       $limit = $req['page'] == 0 || $req['page'] == "0" ? '' : " LIMIT $start,$rows ";
  223.       $UNION = !$q ($current "UNION ( SELECT $data FROM $table $join WHERE $primary = $current ) " : "") : "";
  224.     
  225.       $sql = "SELECT COUNT($primary) AS total FROM $table $join WHERE 1 $condition";
  226.       $res['total'] = $GLOBALS['conn']->getOne($sql);
  227.  
  228.       $sql = "( SELECT $data FROM $table $join WHERE 1 $condition $orderby $limit ) $UNION ";
  229.       $res['rows'] = $GLOBALS['conn']->getAll($sql);
  230.  
  231.       return $res;
  232.     }
  233.     public static function listType($req) {
  234.       $page = $req['page'] ? (int)($req['page']) : 1;
  235.       $rows = $req['rows'] ? (int)($req['rows']) : 99999;
  236.       $start = (($rows * $page) - $rows);
  237.  
  238.       $q = $req['q'] ? $req['q'] : '';
  239.       $current = $req['current'] ? $req['current'] : 0;
  240.       $id = $req['id'] ? $req['id'] : 0;
  241.  
  242.       $primary = "id";
  243.  
  244.       $condition = 
  245.         ".($id " AND $primary = $id " : '').
  246.         ".($q " AND ( title LIKE '%$q%' OR title_eng LIKE '%$q%' )" : "")."
  247.       ";
  248.  
  249.       $data = " * ";
  250.  
  251.       $table = " tb_asset_type ";
  252.       $join = " ";
  253.  
  254.       $orderby = " ORDER BY $primary DESC ";
  255.       $limit = $req['page'] == 0 || $req['page'] == "0" ? '' : " LIMIT $start,$rows ";
  256.       $UNION = !$q ($current "UNION ( SELECT $data FROM $table $join WHERE $primary = $current ) " : "") : "";
  257.     
  258.       $sql = "SELECT COUNT($primary) AS total FROM $table $join WHERE 1 $condition";
  259.       $res['total'] = $GLOBALS['conn']->getOne($sql);
  260.  
  261.       $sql = "( SELECT $data FROM $table $join WHERE 1 $condition $orderby $limit ) $UNION ";
  262.       $res['rows'] = $GLOBALS['conn']->getAll($sql);
  263.  
  264.       return $res;
  265.     }
  266.     public static function listSub($req) {
  267.       $page = $req['page'] ? (int)($req['page']) : 1;
  268.       $rows = $req['rows'] ? (int)($req['rows']) : 99999;
  269.       $start = (($rows * $page) - $rows);
  270.  
  271.       $q = $req['q'] ? $req['q'] : '';
  272.       $current = $req['current'] ? $req['current'] : 0;
  273.       $id = $req['id'] ? $req['id'] : 0;
  274.  
  275.       if (!$req['type']) {
  276.         return array('rows'=>array(),'total'=>0);
  277.       }
  278.  
  279.       $primary = "id";
  280.  
  281.       $condition = 
  282.         ".($id " AND $primary = $id " : '').
  283.         ".($q " AND ( title LIKE '%$q%' OR description LIKE '%$q%' )" : "")."
  284.         AND status <> 'remove'
  285.       ";
  286.  
  287.       $data = " * ";
  288.  
  289.       $table = " tb_asset_category ";
  290.       $join = " ";
  291.  
  292.       $orderby = " ORDER BY $primary DESC ";
  293.       $limit = $req['page'] == 0 || $req['page'] == "0" ? '' : " LIMIT $start,$rows ";
  294.       $UNION = !$q ($current "UNION ( SELECT $data FROM $table $join WHERE $primary = $current ) " : "") : "";
  295.     
  296.       $sql = "SELECT COUNT($primary) AS total FROM $table $join WHERE 1 $condition";
  297.       $res['total'] = $GLOBALS['conn']->getOne($sql);
  298.  
  299.       $sql = "( SELECT $data FROM $table $join WHERE 1 $condition $orderby $limit ) $UNION ";
  300.       $res['rows'] = $GLOBALS['conn']->getAll($sql);
  301.  
  302.       return $res;
  303.     }
  304.     public static function list($req) {
  305.       $page = $req['page'] ? (int)($req['page']) : 1;
  306.       $rows = $req['rows'] ? (int)($req['rows']) : 100;
  307.       $start = (($rows * $page) - $rows);
  308.  
  309.       $q = $req['q'] ? $req['q'] : '';
  310.       $current = $req['current'] ? $req['current'] : 0;
  311.       $id = $req['id'] ? $req['id'] : 0;
  312.  
  313.       $primary = "ar.id";
  314.  
  315.       $condition = 
  316.         ".($id " AND $primary = $id " : "").
  317.         ".($q " AND ( ar.title LIKE '%$q%' OR ar.code LIKE '%$q%' ) " : "").
  318.         ".($req['fromDate'] ? " AND ar.entry_date >= '".$req['fromDate']." 00:00:00' " : "")."
  319.         ".($req['toDate'] ? " AND ar.entry_date <= '".$req['toDate']." 23:59:59' " : "")."
  320.         ".($req['owner'] ? " AND dep.code LIKE '%".$req['owner']."%' ": "")."
  321.         ".($req['code'] ? " AND ar.code LIKE '%".$req['code']."%' " : "")."
  322.         ".($req['title'] ? " AND ar.title LIKE '%".$req['title']."%' " : "")."
  323.         ".($req['status'] ? " AND ar.status = '%".$req['status']."%' " : "")."
  324.         AND ar.status <> 'remove' 
  325.       ";
  326.  
  327.       $data = "
  328.         ar.*,
  329.         DATE_FORMAT(ar.entry_date, '%Y-%m-%d') AS entry_date,
  330.         DATE_FORMAT(ar.update_date, '%Y-%m-%d') AS update_date,
  331.         ar.code AS code,
  332.         CONCAT(entry_em.firstname,' ',entry_em.lastname) AS entryFullname,
  333.         dep.code AS depCode, 
  334.         dep.title AS depTitle,
  335.         ( CASE
  336.           WHEN dep.code = 'TPM' THEN (SELECT code FROM tb_tpm_inventory AS tpm WHERE ar.asset = tpm.id)
  337.           WHEN dep.code = 'CST' THEN (SELECT code FROM tb_cst_inventory_item AS cst WHERE ar.asset = cst.id)
  338.           WHEN dep.code = 'HRM' THEN (SELECT code FROM tb_global_inventory AS hrm WHERE ar.asset = hrm.id)
  339.           WHEN dep.code = 'ITS' THEN (SELECT code FROM tb_its_inventory AS its WHERE ar.asset = its.id)
  340.           WHEN dep.code = 'QAS' THEN (SELECT code FROM tb_qas_inventory AS qas WHERE ar.asset = qas.id)
  341.           ELSE ''
  342.         END ) AS assetCode,
  343.         ( CASE
  344.           WHEN dep.code = 'TPM' THEN (SELECT status FROM tb_tpm_inventory AS tpm WHERE ar.asset = tpm.id)
  345.           WHEN dep.code = 'CST' THEN ''
  346.           WHEN dep.code = 'HRM' THEN (SELECT status FROM tb_global_inventory AS hrm WHERE ar.asset = hrm.id)
  347.           WHEN dep.code = 'ITS' THEN (SELECT status FROM tb_its_inventory AS its WHERE ar.asset = its.id)
  348.           WHEN dep.code = 'QAS' THEN (SELECT status FROM tb_qas_inventory AS qas WHERE ar.asset = qas.id)
  349.           ELSE ''
  350.         END ) AS assetStatus
  351.       ";
  352.  
  353.       $table = " tb_asset_registration AS ar ";
  354.       $join = "
  355.           LEFT JOIN tb_employee AS entry_em ON entry_em.id = ar.entry_by
  356.           LEFT JOIN tb_department AS dep ON dep.id = ar.owner
  357.         ";
  358.  
  359.         $orderby = " ORDER BY $primary DESC ";
  360.         $limit = $req['page'] == 0 || $req['page'] == "0" ? '' : " LIMIT $start,$rows ";
  361.         $UNION = !$q ($current "UNION ( SELECT $data FROM $table $join WHERE $primary = $current ) " : "") : "";
  362.       
  363.         $sql = "SELECT COUNT($primary) AS total FROM $table $join WHERE 1 $condition";
  364.         $res['total'] = $GLOBALS['conn']->getOne($sql);
  365.   
  366.         $sql = "( SELECT $data FROM $table $join WHERE 1 $condition $orderby $limit ) $UNION ";
  367.         $res['rows'] = $GLOBALS['conn']->getAll($sql);
  368.   
  369.         return $res;
  370.     }
  371.     public static function insert($req) {
  372.       $res = array('success' => false, 'errorMsg' => '');
  373.       $req['entry_date'] = date('Y-m-d h:i:s');
  374.       $req['entry_by'] = $_SESSION['user']['id'];
  375.       if ($GLOBALS['conn']->AutoExecute('tb_asset_registration', $req, 'INSERT')){
  376.         $req['id'] = $GLOBALS['conn']->insert_id();
  377.         $res['row'] = $req;
  378.         $res['status'] = true;
  379.     
  380.       } else {
  381.         $res['errorMsg'] = $GLOBALS['conn']->mysql_error();
  382.       }
  383.       return $res;
  384.     }
  385.     public static function save($req) {
  386.       $res = array('success' => false, 'errorMsg' => '');
  387.       if (empty($req['id'])) {
  388.         $res['errorMsg'] = "Error : object without id";
  389.         return $res;
  390.       }
  391.       unset($req['current']);
  392.       $req['update_by'] = $_SESSION['user']['id'];
  393.       $req['update_date'] = date('Y-m-d h:i:s');
  394.  
  395.       
  396.  
  397.       if ($GLOBALS['conn']->autoExecute('tb_asset_registration', $req, 'UPDATE', 'id=' . $req['id'])){
  398.         $res['row'] = $req;
  399.         $res['success'] = true;
  400.       } else {
  401.         $res['errorMsg'] = $GLOBALS['conn']->mysql_error();
  402.       }
  403.       return $res;
  404.     }
  405.     public static function remove($req) {
  406.       $req = array(
  407.         'id' => $req['id'],
  408.         'status' => 'remove'
  409.       );
  410.       AssetRegistration::save($req);
  411.     }
  412.   }

Editor

You can edit this paste and save as new:


File Description
  • yyyy
  • Paste Code
  • 24 Jan-2022
  • 14.92 Kb
You can Share it: