sumberdaya.php
5.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Example
*
* This is an example of a few basic user interaction methods you could use
* all done with a hardcoded array.
*
* @package CodeIgniter
* @subpackage Rest Server
* @category Controller
* @author Phil Sturgeon
* @link http://philsturgeon.co.uk/code/
*/
// This can be removed if you use __autoload() in config.php OR use Modular Extensions
require APPPATH.'/libraries/REST_Controller.php';
class Sumberdaya extends REST_Controller
{
function __construct(){
parent::__construct();
$this->load->database();
}
function index_get()
{
// $id = $this->get('id');
// if ($this->get('id') == '') {
// $user = $this->db->get('pmlocal_jenissdy')->result();
// } else {
// $this->db->where('id_jenissdy', $id);
// $user = $this->db->get('pmlocal_jenissdy')->result();
// }
$data = array(
'kode_master_sumberdaya' => 'A57 *(3 Digit)', // 3digit
'nama_master_sumberdaya' => 'Beton Readymix Aditive (Khusus) Type 1',
'kode_jenis_sumberdaya' => 'A5 *(2 Digit)', // 2digit
'nama_jenis_sumberdaya' => 'READYMIX CONCRETE',
'tipe_sumberdaya' => 'Material/Alat/Upah/Subkontraktor',
);
if($data)
{
$this->response($data, 200); // 200 being the HTTP response code
}
else
{
$this->response(array('error' => 'Jenis Sumberdaya could not be found'), 404);
}
}
function index_post() {
$data = array(
'kode_master_sumberdaya' => trim($this->post('kode_master_sumberdaya')), // 3digit
'nama_master_sumberdaya' => $this->post('nama_master_sumberdaya'),
'kode_jenis_sumberdaya' => trim($this->post('kode_jenis_sumberdaya')), // 2digit
'nama_jenis_sumberdaya' => $this->post('nama_jenis_sumberdaya'),
'tipe_sumberdaya' => trim($this->post('tipe_sumberdaya')),
);
if($data['kode_master_sumberdaya'] == '' ){
$this->response(array('error' => 'Kode Master Sumberdaya could not empty!'), 404);
}else{
$this->db->where('kd_sdymaster', $data['kode_master_sumberdaya']);
$count = $this->db->get('pmlocal_sdymaster')->num_rows();
if ($count > 0){
$this->response(array('error' => 'Kode Master Sumberdaya Sudah ada!'), 404);
}
}
if($data['nama_master_sumberdaya'] == '' ){
$this->response(array('error' => 'Nama Master Sumberdaya could not empty!'), 404);
}
if($data['nama_jenis_sumberdaya'] == '' ){
$this->response(array('error' => 'Nama Jenis Sumberdaya could not empty!'), 404);
}
if($data['tipe_sumberdaya'] == '' ){
$this->response(array('error' => 'Tipe Sumberdaya could not empty!'), 404);
}else{
$query = $this->db->query("SELECT * FROM resource_type WHERE LOWER(tpname)='".strtolower($data['tipe_sumberdaya'])."' ");
if ($query->num_rows() == 0){
$this->response(array('error' => 'Tipe Sumberdaya Tidak Terdaftar!'), 404);
}
}
if($data['kode_jenis_sumberdaya'] == '' ){
$this->response(array('error' => 'Kode Jenis Sumberdaya could not empty!'), 404);
}else{
$this->db->where('kd_jenissdy', $data['kode_jenis_sumberdaya']);
$count = $this->db->get('pmlocal_jenissdy')->num_rows();
$datatipe = array(
'id_jenissdy' => $this->db->query('SELECT MAX(id_jenissdy)+1 AS maxid FROM pmlocal_jenissdy')->row()->maxid,
'kd_jenissdy' => trim($this->post('kode_jenis_sumberdaya')), // 2digit
'nama_jenissdy' => $this->post('nama_jenis_sumberdaya'),
);
$inserttipe = true;
if ($count == 0){
$inserttipe = $this->db->insert('pmlocal_jenissdy', $datatipe);
}
}
//tipe sumberdaya
$tipe = $query->row_array();
if ($inserttipe){
$data = array(
'id_sdymaster' => $this->db->query('SELECT MAX(id_sdymaster)+1 AS maxid FROM pmlocal_sdymaster')->row()->maxid,
'kd_sdymaster' => trim($this->post('kode_master_sumberdaya')), // 3digit
'nama_sdymaster' => $this->post('nama_master_sumberdaya'),
'kd_jenissdy' => trim($this->post('kode_jenis_sumberdaya')), // 2digit
'rtid' => $tipe['rtid']
);
$insert = $this->db->insert('pmlocal_sdymaster', $data);
if ($insert) {
$this->response(array('status' => 'success', 200));
} else {
$this->response(array('status' => 'fail', 502));
}
}else {
$this->response(array('status' => 'fail insert jenis sumberdaya', 502));
}
}
function user_post()
{
//$this->some_model->updateUser( $this->get('id') );
$message = array('id' => $this->get('id'), 'name' => $this->post('name'), 'email' => $this->post('email'), 'message' => 'ADDED!');
$this->response($message, 200); // 200 being the HTTP response code
}
function user_delete()
{
//$this->some_model->deletesomething( $this->get('id') );
$message = array('id' => $this->get('id'), 'message' => 'DELETED!');
$this->response($message, 200); // 200 being the HTTP response code
}
function sumberdaya_get()
{
// $id = $this->get('id');
// print_r($id);exit;
$user = $this->db->get('pmlocal_jenissdy')->result();
if($users)
{
$data['hasil'] = $this->response($users, 200); // 200 being the HTTP response code
}
else
{
$data['hasil'] = $this->response(array('error' => 'Couldn\'t find any users!'), 404);
}
// return $hasil;
$this->load->view('content',$data);
}
public function send_post()
{
var_dump($this->request->body);
}
public function send_put()
{
var_dump($this->put('foo'));
}
}