コード例 #1
0
ファイル: order.php プロジェクト: OmondiKevin/ADT
 public function get_orders($type = "cdrr", $period_begin = "")
 {
     $columns = array('#', '#ID', 'Period Beginning', 'Status', 'Facility Name', 'Options');
     $facility_table = 'sync_facility';
     $facility_name = 'f.name';
     $conditions = '';
     $facilities = '';
     $results = array();
     $user_facilities = User_Facilities::getHydratedFacilityList($this->session->userdata("user_id"));
     if (!empty($user_facilities)) {
         $facilities = implode(',', json_decode($user_facilities['facility'], TRUE));
     }
     if ($period_begin != "" && $type == "cdrr") {
         $conditions = "AND c.period_begin='{$period_begin}'";
     }
     if ($period_begin != "" && $type == "maps") {
         $conditions = "AND m.period_begin='{$period_begin}'";
     }
     if ($period_begin == 0 && $type == "cdrr") {
         $conditions = "";
     }
     if ($period_begin == 0 && $type == "maps") {
         $conditions = "";
     }
     if ($facilities) {
         if ($type == "cdrr") {
             $sql = "SELECT c.id,IF(c.code='D-CDRR',CONCAT('D-CDRR#',c.id),CONCAT('F-CDRR#',c.id)) as cdrr_id,c.period_begin,LCASE(c.status) as status_name,{$facility_name} as facility_name\n\t\t\t\t\t    FROM cdrr c\n\t\t\t\t\t    LEFT JOIN {$facility_table} f ON f.id=c.facility_id\n\t\t\t\t\t    WHERE facility_id IN({$facilities})\n\t\t\t\t\t    AND c.status NOT LIKE '%deleted%'\n\t\t\t\t\t    {$conditions}\n\t\t\t\t\t    ORDER BY c.period_begin desc";
         } else {
             if ($type == "maps") {
                 $sql = "SELECT m.id,IF(m.code='D-MAPS',CONCAT('D-MAPS#',m.id),CONCAT('F-MAPS#',m.id)) as maps_id,m.period_begin,LCASE(m.status) as status_name,{$facility_name} as facility_name\n\t\t\t\t\t\tFROM maps m\n\t\t\t\t\t\tLEFT JOIN {$facility_table} f ON f.id=m.facility_id\n\t\t\t\t\t\tWHERE facility_id IN({$facilities})\n\t\t\t\t\t\tAND m.status NOT LIKE '%deleted%'\n\t\t\t\t\t\t{$conditions}\n\t\t\t\t\t\tORDER BY m.period_begin desc";
             }
         }
         $query = $this->db->query($sql);
         $results = $query->result_array();
     }
     if ($period_begin != "") {
         echo $this->generate_table($columns, $results, $type);
     } else {
         if ($period_begin != 0) {
             echo $this->generate_table($columns, $results, $type);
         } else {
             return $this->generate_table($columns, $results, $type);
         }
     }
 }
コード例 #2
0
ファイル: order.php プロジェクト: OmondiKevin/ADT_MTRH
 public function get_orders($type = "cdrr", $period_begin = "")
 {
     $columns = array('#', '#ID', 'Period Beginning', 'Status', 'Facility Name', 'Options');
     $facility_code = $this->session->userdata('facility');
     $supplier = $this->get_supplier($facility_code);
     $facility_table = "sync_facility";
     $facility_name = "f.name";
     $conditions = "";
     $user_facilities = User_Facilities::getHydratedFacilityList($this->session->userdata("api_id"));
     $facilities = json_decode($user_facilities['facility'], TRUE);
     $facilities = implode(",", $facilities);
     if ($period_begin != "" && $type == "cdrr") {
         $conditions = "AND c.period_begin='{$period_begin}'";
     }
     if ($period_begin != "" && $type == "maps") {
         $conditions = "AND m.period_begin='{$period_begin}'";
     }
     if ($period_begin == 0 && $type == "cdrr") {
         $conditions = "";
     }
     if ($period_begin == 0 && $type == "maps") {
         $conditions = "";
     }
     if ($type == "cdrr") {
         $sql = "SELECT c.id,IF(c.code='D-CDRR',CONCAT('D-CDRR#',c.id),CONCAT('F-CDRR#',c.id)) as cdrr_id,c.period_begin,LCASE(c.status) as status_name,{$facility_name} as facility_name\n\t\t\t\t    FROM cdrr c\n\t\t\t\t    LEFT JOIN {$facility_table} f ON f.id=c.facility_id\n\t\t\t\t    WHERE facility_id IN({$facilities})\n\t\t\t\t    AND c.status NOT LIKE '%deleted%'\n\t\t\t\t    {$conditions}\n\t\t\t\t    ORDER BY c.period_begin desc";
     } else {
         if ($type == "maps") {
             $sql = "SELECT m.id,IF(m.code='D-MAPS',CONCAT('D-MAPS#',m.id),CONCAT('F-MAPS#',m.id)) as maps_id,m.period_begin,LCASE(m.status) as status_name,{$facility_name} as facility_name\n\t\t\t\t\tFROM maps m\n\t\t\t\t\tLEFT JOIN {$facility_table} f ON f.id=m.facility_id\n\t\t\t\t\tWHERE facility_id IN({$facilities})\n\t\t\t\t\tAND m.status NOT LIKE '%deleted%'\n\t\t\t\t\t{$conditions}\n\t\t\t\t\tORDER BY m.period_begin desc";
         } else {
             if ($type == "aggregate") {
                 $facility_type = Facilities::getType($facility_code);
                 $sql = "";
                 $columns = array('#', 'Facility Name', 'Period Beginning', 'Options');
                 if ($facility_type > 1 && $supplier == "KEMSA") {
                     $sql = "SELECT c.period_begin as id,sf.name as facility_name,c.period_begin,c.id as cdrr_id,m.id as maps_id,c.facility_id as facility_id,f.facilitycode as facility_code\n\t\t\t\t\t\tFROM cdrr c \n\t\t\t\t\t\tLEFT JOIN maps m ON (c.facility_id=m.facility_id) AND (c.period_begin=m.period_begin) AND (c.period_end=m.period_end)\n\t\t\t\t\t\tLEFT JOIN sync_facility sf ON sf.id=c.facility_id \n\t\t\t\t\t\tLEFT JOIN facilities f ON f.facilitycode=sf.code\n\t\t\t\t\t\tWHERE c.code = 'D-CDRR' \n\t\t\t\t\t\tAND m.code='D-MAPS'\n\t\t\t\t\t\tAND LCASE(c.status) NOT IN('prepared','review','deleted')\n\t\t\t\t\t\tAND LCASE(m.status) NOT IN('prepared','review','deleted')\n\t\t\t\t\t\tAND c.facility_id IN({$facilities})\n\t\t\t\t\t\tGROUP BY c.period_begin\n\t                    ORDER BY c.period_begin desc";
                 }
             }
         }
     }
     if ($sql != "") {
         $query = $this->db->query($sql);
         $results = $query->result_array();
     } else {
         $results = array();
     }
     if ($period_begin != "") {
         echo $this->generate_table($columns, $results, $type);
     } else {
         if ($period_begin != 0) {
             echo $this->generate_table($columns, $results, $type);
         } else {
             return $this->generate_table($columns, $results, $type);
         }
     }
 }