added server, This is for the local DB and backend
This commit is contained in:
468
server/application/controllers/Api.php
Normal file
468
server/application/controllers/Api.php
Normal file
@ -0,0 +1,468 @@
|
||||
<?php
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header('Access-Control-Allow-Methods: GET, POST, DELETE, PUT');
|
||||
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization , X-Authorization , X-Auth-Token');
|
||||
header("Access-Control-Expose-Headers: Content-Length, X-JSON");
|
||||
header('Access-Control-Allow-Credentials: true');
|
||||
header('Content-Type: application/json');
|
||||
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
|
||||
use chriskacerguis\RestServer\RestController;
|
||||
|
||||
class Api extends RestController
|
||||
{
|
||||
var $server_url;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('model');;
|
||||
// $this->db->query("SET sql_mode = '' ");
|
||||
date_default_timezone_set("Asia/Kuala_Lumpur");
|
||||
$this->server_url = 'http://localhost/ilham/server2/api/';
|
||||
}
|
||||
|
||||
public function index_get()
|
||||
{
|
||||
$this->response(['message' => 'Halo Bosku'], 200);
|
||||
// redirect(base_url());
|
||||
|
||||
}
|
||||
|
||||
// --------------------------------dibawah khusus untuk admin -----------------------------//
|
||||
|
||||
public function login_user_get()
|
||||
{
|
||||
$username = $this->get('username');
|
||||
$password = $this->get('password');
|
||||
|
||||
$cek_data = $this->model->tampil_data_where('tb_login', array('username' => $username, 'password' => md5($password)))->result();
|
||||
|
||||
// if count $cek_data > 0, then response success , else response error
|
||||
if (count($cek_data) > 0) {
|
||||
$cek_user = $this->model->custom_query("SELECT * FROM tb_user a join tb_login b on a.no_user = b.no_user where a.no_user=" . $cek_data[0]->no_user)->result();
|
||||
$this->response(['status' => 'success', 'data' => $cek_user[0]], 200);
|
||||
} else {
|
||||
$this->response(['status' => 'error', 'message' => 'Username atau Password Salah'], 400);
|
||||
}
|
||||
|
||||
// $this->response(['status' => true, 'message' =>$username], 200);
|
||||
}
|
||||
|
||||
public function cek_user_get()
|
||||
{
|
||||
$username = $this->get('username');
|
||||
$password = $this->get('password');
|
||||
$no_user = $this->get('id');
|
||||
|
||||
$cek_data = $this->model->custom_query("SELECT * FROM tb_user a join tb_login b on a.no_user = b.no_user where a.no_user=" . $no_user . " and username='" . $username . "' and password='" . $password . "'")->result();
|
||||
|
||||
// if count $cek_data > 0, then response success , else response error
|
||||
if (count($cek_data) > 0) {
|
||||
|
||||
$this->response(['status' => 'success'], 200);
|
||||
} else {
|
||||
$this->response(['status' => 'error'], 400);
|
||||
}
|
||||
|
||||
$this->response(['status' => true, 'message' => 'sini_dia'], 200);
|
||||
}
|
||||
|
||||
|
||||
public function tambah_produk_post()
|
||||
{
|
||||
$foto = $_FILES['foto'];
|
||||
$data = json_decode($this->post('data'), true);
|
||||
$data_to_db = $data;
|
||||
|
||||
// remove $data['pembelian_stok']
|
||||
unset($data_to_db['pembelian_stok']);
|
||||
unset($data_to_db['bertanggungjawab']);
|
||||
|
||||
|
||||
|
||||
$cek_data = $this->model->tampil_data_where('tb_barang', ['kode_barang' => $data_to_db['kode_barang']])->result();
|
||||
|
||||
// if count $cek_data > 0, then response success , else response error
|
||||
if (count($cek_data) > 0) {
|
||||
$this->response(['status' => 'error'], 400);
|
||||
} else {
|
||||
$this->model->insert('tb_barang', $data_to_db);
|
||||
$cek_barang = $this->model->tampil_data_where('tb_barang', $data_to_db)->result()[0];
|
||||
|
||||
// $cek_id = $this->model->cek_last_ai('tb_kategori');
|
||||
$dir = "img/" . $cek_barang->no_barang . '/';
|
||||
if (is_dir($dir) === false) {
|
||||
mkdir($dir);
|
||||
}
|
||||
move_uploaded_file($foto['tmp_name'], $dir . $foto['name']);
|
||||
|
||||
unset($data['foto']);
|
||||
|
||||
$this->model->insert('tb_log_history', ['no_barang' => $cek_barang->no_barang, 'status' => "Penambahan Produk Baru", "waktu" => date("Y-m-d H:i:s"), "ket" => json_encode($data)]);
|
||||
|
||||
$cek_history = $this->model->custom_query("SELECT * FROM tb_log_history where no_barang=" . $cek_barang->no_barang . " order by no_log desc")->result()[0];
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// $file_name_with_full_path = realpath("img/".$cek_barang->no_barang."/".$data_to_db['foto']);
|
||||
// $postimg = array('myfile' => '@' . $file_name_with_full_path);
|
||||
$data_to_server_db['foto'] = new CurlFile("img/" . $cek_barang->no_barang . "/" . $data_to_db['foto'], 'image/jpg', $data_to_db['foto']);
|
||||
$data_to_server_db['data'] = json_encode($cek_barang);
|
||||
$data_to_server_db['history'] = json_encode($cek_history);
|
||||
|
||||
$headers = array("Content-Type:multipart/form-data");
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_to_server_db);
|
||||
curl_setopt($ch, CURLOPT_USERPWD, "Kicap_karan:bb10c6d9f01ec0cb16726b59e36c2f73");
|
||||
// curl_setopt($ch, CURLOPT_HEADER, 1);
|
||||
curl_setopt($ch, CURLOPT_URL, $this->server_url . 'tambah_produk');
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
$data = curl_exec($ch);
|
||||
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
if ($httpcode == 200) {
|
||||
$stat = 'success';
|
||||
$this->model->update('tb_barang', ['no_barang' => $cek_barang->no_barang], ['ke_db_online' => 'Sudah']);
|
||||
$this->model->update('tb_log_history', ['no_log' => $cek_history->no_log], ['ke_db_online' => 'Sudah']);
|
||||
} else {
|
||||
$stat = 'error';
|
||||
}
|
||||
|
||||
// sleep(5);
|
||||
$this->response(['status' => $cek_barang, 'stat' => $stat, 'data_server' => $data], 200);
|
||||
// $this->response(['status' => $this->server_url], 200);
|
||||
}
|
||||
|
||||
// $this->response(['status' => true, 'message' => $cek_data], 200);
|
||||
}
|
||||
|
||||
public function get_produk_get()
|
||||
{
|
||||
$no_produk = $this->get('id');
|
||||
$cek_data = $this->model->tampil_data_where('tb_barang', ['no_barang' => $no_produk])->result();
|
||||
|
||||
// if count $cek_data > 0, then response success , else response error
|
||||
if (count($cek_data) > 0) {
|
||||
$this->response(['status' => 'success', 'data' => $cek_data[0]], 200);
|
||||
} else {
|
||||
$this->response(['status' => 'error', 'message' => 'Produk tidak ditemukan'], 400);
|
||||
}
|
||||
// $this->response(['status' => $no_produk], 200);
|
||||
}
|
||||
|
||||
public function tambah_stok_put()
|
||||
{
|
||||
$no_produk = $this->put('id');
|
||||
$data = $this->put('data');
|
||||
$cek_data = $this->model->tampil_data_where('tb_barang', ['no_barang' => $no_produk])->result();
|
||||
|
||||
// if count $cek_data > 0, then response success , else response error
|
||||
if (count($cek_data) > 0) {
|
||||
$this->model->update('tb_barang', ['no_barang' => $no_produk], ['jumlah' => $data['total_stok']]);
|
||||
$this->model->insert('tb_log_history', ['no_barang' => $no_produk, 'status' => "Penambahan Stok", "waktu" => date("Y-m-d H:i:s"), "ket" => json_encode($data)]);
|
||||
|
||||
$cek_history = $this->model->custom_query("SELECT * FROM tb_log_history where no_barang=" . $no_produk . " order by no_log desc")->result()[0];
|
||||
$cek_barang = $this->model->tampil_data_where('tb_barang', ['no_barang' => $no_produk])->result()[0];
|
||||
|
||||
$data_to_server_db['foto'] = new CurlFile("img/" . $cek_barang->no_barang . "/" . $cek_barang->foto, 'image/jpg', $cek_barang->foto);
|
||||
$data_to_server_db['data'] = json_encode($cek_barang);
|
||||
$data_to_server_db['history'] = json_encode($cek_history);
|
||||
|
||||
$headers = array("Content-Type:multipart/form-data");
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_to_server_db);
|
||||
curl_setopt($ch, CURLOPT_USERPWD, "Kicap_karan:bb10c6d9f01ec0cb16726b59e36c2f73");
|
||||
// curl_setopt($ch, CURLOPT_HEADER, 1);
|
||||
curl_setopt($ch, CURLOPT_URL, $this->server_url . 'tambah_stok');
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
$data = curl_exec($ch);
|
||||
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
if ($httpcode == 200) {
|
||||
$stat = 'success';
|
||||
$this->model->update('tb_barang', ['no_barang' => $cek_barang->no_barang], ['ke_db_online' => 'Sudah']);
|
||||
$this->model->update('tb_log_history', ['no_log' => $cek_history->no_log], ['ke_db_online' => 'Sudah']);
|
||||
} else {
|
||||
$stat = 'error';
|
||||
}
|
||||
|
||||
// $this->response(['status' => 'success', 'stat' => $stat,'data' => $data], 200);
|
||||
$this->response(['status' => 'success', 'stat' => $stat, 'server' => $data], 200);
|
||||
} else {
|
||||
$this->response(['status' => 'error', 'message' => 'Produk tidak ditemukan'], 400);
|
||||
}
|
||||
}
|
||||
|
||||
public function edit_detail_produk_post()
|
||||
{
|
||||
$no_produk = $this->post('id');
|
||||
$data = json_decode($this->post('data'), true);
|
||||
$cek_foto = $this->post('cek_foto');
|
||||
$foto = ($cek_foto == 'tiada') ? null : $_FILES['foto'];
|
||||
$cek_data = $this->model->tampil_data_where('tb_barang', ['no_barang' => $no_produk])->result();
|
||||
|
||||
// if count $cek_data > 0, then response success , else response error
|
||||
if (count($cek_data) > 0) {
|
||||
$this->model->update('tb_barang', ['no_barang' => $no_produk], ["nama" => $data['nama_baru'], "harga_jual" => $data['harga_baru'], "foto" => $data['foto_baru']]);
|
||||
if ($cek_foto == 'ada') {
|
||||
$dir = "img/" . $no_produk . '/';
|
||||
//delete all file in $dir
|
||||
$files = glob($dir . '*'); // get all file names
|
||||
foreach ($files as $file) { // iterate files
|
||||
if (is_file($file))
|
||||
unlink($file); // delete file
|
||||
}
|
||||
|
||||
//upload new file
|
||||
move_uploaded_file($foto['tmp_name'], $dir . $foto['name']);
|
||||
}
|
||||
$this->model->insert('tb_log_history', ['no_barang' => $no_produk, 'status' => "Edit Detail Produk", "waktu" => date("Y-m-d H:i:s"), "ket" => json_encode($data)]);
|
||||
$cek_history = $this->model->custom_query("SELECT * FROM tb_log_history where no_barang=" . $no_produk . " order by no_log desc")->result()[0];
|
||||
|
||||
$data_to_server_db['foto'] = new CurlFile("img/" . $no_produk . "/" . $foto['name'], 'image/jpg', $foto['name']);
|
||||
$data_to_server_db['data'] = json_encode($cek_data[0]);
|
||||
$data_to_server_db['history'] = json_encode($cek_history);
|
||||
$data_to_server_db['cek_foto'] = $cek_foto;
|
||||
|
||||
$headers = array("Content-Type:multipart/form-data");
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_to_server_db);
|
||||
curl_setopt($ch, CURLOPT_USERPWD, "Kicap_karan:bb10c6d9f01ec0cb16726b59e36c2f73");
|
||||
// curl_setopt($ch, CURLOPT_HEADER, 1);
|
||||
curl_setopt($ch, CURLOPT_URL, $this->server_url . 'edit_detail_produk');
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
$data = curl_exec($ch);
|
||||
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
if ($httpcode == 200) {
|
||||
$stat = 'success';
|
||||
$this->model->update('tb_barang', ['no_barang' => $no_produk], ['ke_db_online' => 'Sudah']);
|
||||
$this->model->update('tb_log_history', ['no_log' => $cek_history->no_log], ['ke_db_online' => 'Sudah']);
|
||||
} else {
|
||||
$stat = 'error';
|
||||
}
|
||||
|
||||
$this->response(['status' => 'success', 'stat' => $stat], 200);
|
||||
} else {
|
||||
$this->response(['status' => 'error', 'message' => 'Produk tidak ditemukan'], 400);
|
||||
}
|
||||
|
||||
// $this->response(['status' => $foto], 200);
|
||||
}
|
||||
|
||||
public function cari_produk_get()
|
||||
{
|
||||
$id = $this->get('id');
|
||||
$cek_data = $this->model->custom_query("SELECT * FROM tb_barang where kode_barang like '%" . $id . "%' or nama like '" . $id . "'")->result();
|
||||
|
||||
// if (count($cek_data) > 0) {
|
||||
// $this->response(['status' => 'success', 'data' => $cek_data], 200);
|
||||
// } else {
|
||||
// $this->response(['status' => 'error', 'message' => 'Produk tidak ditemukan'], 400);
|
||||
// }
|
||||
|
||||
$this->response(['status' => 'success', 'data' => $cek_data], 200);
|
||||
}
|
||||
|
||||
public function penjualan_post()
|
||||
{
|
||||
$data = $this->post('data');
|
||||
|
||||
|
||||
$array_penjualan = json_decode($data['ket'], true);
|
||||
//loop array penjualan
|
||||
$data_to_server_db['data_barang'] = [];
|
||||
$data_to_server_db['history_barang'] = [];
|
||||
|
||||
foreach ($array_penjualan as $key => $value) {
|
||||
|
||||
$cek_barang = $this->model->tampil_data_where('tb_barang', ['no_barang' => $value['id']])->result()[0];
|
||||
$jumlah_stok_sebelumnya = $cek_barang->jumlah;
|
||||
$jumlah_stok_sekarang = $jumlah_stok_sebelumnya - $value['jumlah'];
|
||||
$array_penjualan[$key]['jumlah_stok_sebelumnya'] = $jumlah_stok_sebelumnya;
|
||||
$array_penjualan[$key]['jumlah_stok_sekarang'] = $jumlah_stok_sekarang;
|
||||
$this->model->update('tb_barang', ['no_barang' => $value['id']], ['jumlah' => $jumlah_stok_sekarang]);
|
||||
$array_to_db = array(
|
||||
'jumlah_pembelian' => $value['jumlah'],
|
||||
'harga_jual' => $value['harga_jual'],
|
||||
'stok_sebelumnya' => $jumlah_stok_sebelumnya,
|
||||
'stok_sekarang' => $jumlah_stok_sekarang,
|
||||
'total_harga' => $value['total'],
|
||||
);
|
||||
$this->model->insert('tb_log_history', ['no_barang' => $value['id'], 'status' => "Penjualan Barang Spesifik", "ket" => json_encode($array_to_db)]);
|
||||
$cek_history_barang['ini_' . $key] = $this->model->custom_query("SELECT * FROM tb_log_history where no_barang =" . $value['id'] . " order by no_log desc")->result()[0];
|
||||
$cek_barang = $this->model->tampil_data_where('tb_barang', ['no_barang' => $value['id']])->result()[0];
|
||||
$fotonya = new CurlFile(
|
||||
"img/" . $cek_barang->no_barang . "/" . $cek_barang->foto,
|
||||
'image/jpg',
|
||||
$cek_barang->foto
|
||||
);
|
||||
//push data to $data_to_server_db
|
||||
|
||||
array_push($data_to_server_db['data_barang'], $cek_barang);
|
||||
array_push($data_to_server_db['history_barang'], $cek_history_barang['ini_' . $key]);
|
||||
// array_push($data_to_server_db['foto'], $fotonya);
|
||||
$data_to_server_db['foto[' . $key . ']'] = $fotonya;
|
||||
}
|
||||
$data['ket'] = $array_penjualan;
|
||||
unset($data['status']);
|
||||
|
||||
$data = array('status' => 'Penjualan Produk', 'ket' => json_encode($data));
|
||||
// $datanya_lagi = $data;
|
||||
|
||||
$this->model->insert('tb_log_history', $data);
|
||||
$cek_history = $this->model->custom_query("SELECT * FROM tb_log_history order by no_log desc")->result()[0];
|
||||
$data_to_server_db['data_barang'] = json_encode($data_to_server_db['data_barang']);
|
||||
$data_to_server_db['history_barang'] = json_encode($data_to_server_db['history_barang']);
|
||||
$data_to_server_db['history'] = json_encode($cek_history);
|
||||
|
||||
// $data_to_server_db['hehe'] = 'hehe';
|
||||
|
||||
$headers = array("Content-Type:multipart/form-data");
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_to_server_db);
|
||||
curl_setopt($ch, CURLOPT_USERPWD, "Kicap_karan:bb10c6d9f01ec0cb16726b59e36c2f73");
|
||||
// curl_setopt($ch, CURLOPT_HEADER, 1);
|
||||
curl_setopt($ch, CURLOPT_URL, $this->server_url . 'penjualan');
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
$data = curl_exec($ch);
|
||||
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
if ($httpcode == 200) {
|
||||
$stat = 'success';
|
||||
foreach ($array_penjualan as $key => $value) {
|
||||
$this->model->update('tb_barang', ['no_barang' => $value['id']], ['ke_db_online' => 'Sudah']);
|
||||
$this->model->update('tb_log_history', ['no_log' => $cek_history_barang['ini_' . $key]->no_log], ['ke_db_online' => 'Sudah']);
|
||||
}
|
||||
$this->model->update('tb_log_history', ['no_log' => $cek_history->no_log], ['ke_db_online' => 'Sudah']);
|
||||
} else {
|
||||
$stat = 'error';
|
||||
}
|
||||
|
||||
$this->response(['status' => 'success', 'stat' => $stat], 200);
|
||||
}
|
||||
|
||||
public function laporan_get()
|
||||
{
|
||||
$bulan = $this->get('bulan');
|
||||
$tahun = $this->get('tahun');
|
||||
|
||||
$cek_data = $this->model->custom_query("SELECT * FROM tb_log_history where status != 'Penjualan Barang Spesifik' and MONTH(waktu) = $bulan and YEAR(waktu) = $tahun")->result();
|
||||
|
||||
foreach ($cek_data as $key => $value) {
|
||||
if ($value->status != 'Penjualan Produk') {
|
||||
$cek_produk = $this->model->tampil_data_where('tb_barang', ['no_barang' => $value->no_barang])->result()[0];
|
||||
$cek_data[$key]->foto = $cek_produk->foto;
|
||||
$cek_data[$key]->kode_barang = $cek_produk->kode_barang;
|
||||
} else {
|
||||
$cek_data[$key]->kode_barang = "-";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->response(['status' => 'success', 'data' => $cek_data], 200);
|
||||
}
|
||||
|
||||
|
||||
public function laporan_detail_get()
|
||||
{
|
||||
$id = $this->get('id');
|
||||
// $tahun = $this->get('tahun');
|
||||
|
||||
$cek_data = $this->model->tampil_data_where('tb_log_history', ['no_log' => $id])->result();
|
||||
|
||||
if (count($cek_data) > 0) {
|
||||
$this->response(['status' => 'success', 'data' => $cek_data[0]], 200);
|
||||
} else {
|
||||
$this->response(['status' => 'error', 'data' => 'Data tidak ditemukan'], 400);
|
||||
}
|
||||
}
|
||||
|
||||
public function update_laporan_post()
|
||||
{
|
||||
$cek_barang = $this->model->tampil_data_where('tb_barang', ['ke_db_online' => 'Belum'])->result();
|
||||
|
||||
$data_to_server_db['cek_data_barang'] = 'tiada';
|
||||
$data_to_server_db['cek_data_history'] = 'tiada';
|
||||
|
||||
if (count($cek_barang) > 0) {
|
||||
$data_to_server_db['cek_data_barang'] = 'ada';
|
||||
$data_to_server_db['data_barang'] = [];
|
||||
foreach ($cek_barang as $key => $value) {
|
||||
$fotonya = new CurlFile(
|
||||
"img/" . $value->no_barang . "/" . $value->foto,
|
||||
'image/jpg',
|
||||
$value->foto
|
||||
);
|
||||
$data_to_server_db['foto[' . $key . ']'] = $fotonya;
|
||||
array_push($data_to_server_db['data_barang'], $value);
|
||||
}
|
||||
$data_to_server_db['data_barang'] = json_encode($data_to_server_db['data_barang']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$cek_history = $this->model->tampil_data_where('tb_log_history', ['ke_db_online' => 'Belum'])->result();
|
||||
if(count($cek_history) > 0){
|
||||
$data_to_server_db['history'] = [];
|
||||
$data_to_server_db['cek_data_history'] = 'ada';
|
||||
foreach ($cek_history as $key => $value) {
|
||||
array_push($data_to_server_db['history'], $value);
|
||||
}
|
||||
$data_to_server_db['history'] = json_encode($data_to_server_db['history']);
|
||||
}
|
||||
|
||||
// foreach ($cek_history as $key => $value) {
|
||||
// array_push($data_to_server_db['history'], $value);
|
||||
// }
|
||||
// $data_to_server_db['history'] = json_encode($data_to_server_db['history']);
|
||||
|
||||
if($data_to_server_db['cek_data_barang'] == 'ada' || $data_to_server_db['cek_data_history'] == 'ada'){
|
||||
$headers = array("Content-Type:multipart/form-data");
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_to_server_db);
|
||||
curl_setopt($ch, CURLOPT_USERPWD, "Kicap_karan:bb10c6d9f01ec0cb16726b59e36c2f73");
|
||||
// curl_setopt($ch, CURLOPT_HEADER, 1);
|
||||
curl_setopt($ch, CURLOPT_URL, $this->server_url . 'update_laporan');
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
$data = curl_exec($ch);
|
||||
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
if($httpcode == 200){
|
||||
$stat = 'success';
|
||||
foreach ($cek_barang as $key => $value) {
|
||||
$this->model->update('tb_barang', ['no_barang' => $value->no_barang], ['ke_db_online' => 'Sudah']);
|
||||
}
|
||||
foreach ($cek_history as $key => $value) {
|
||||
$this->model->update('tb_log_history', ['no_log' => $value->no_log], ['ke_db_online' => 'Sudah']);
|
||||
}
|
||||
}else{
|
||||
$stat = 'error';
|
||||
}
|
||||
}else{
|
||||
$stat = 'already';
|
||||
}
|
||||
|
||||
|
||||
$this->response(['status' => 'success','stat' => $stat, 'data' => $data_to_server_db], 200);
|
||||
// $this->response(['status' => 'success', 'data' => $data_to_server_db], 200);
|
||||
}
|
||||
}
|
||||
272
server/application/controllers/Home.php
Normal file
272
server/application/controllers/Home.php
Normal file
@ -0,0 +1,272 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Home extends CI_Controller {
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('model');
|
||||
$this->load->model('m_tabel_ss');
|
||||
}
|
||||
|
||||
function index(){
|
||||
if ($this->input->post('proses') == "get_produk") {
|
||||
$list = $this->m_tabel_ss->get_datatables(array('kode_barang','nama','jumlah','harga_jual'),array('kode_barang','nama','jumlah','harga_jual',null),array('no' => 'desc'),"tb_barang",null,null,"*");
|
||||
$data = array();
|
||||
$no = $_POST['start'];
|
||||
foreach ($list as $field) {
|
||||
|
||||
$no++;
|
||||
$row = array();
|
||||
// $row[] = $no;
|
||||
$row[] = $field->kode_barang;
|
||||
$row[] = $field->nama;
|
||||
$row[] = $field->jumlah;
|
||||
$row[] = $field->harga_jual;
|
||||
$row[] = '<button class="btn btn-sm round btn-outline-primary" onclick="cek_stok_produk('.$field->no_barang.')" title="Tambah Stok Produk"><span class="sr-only"></span> <i class="fa fa-edit"></i></button> <a class="example-image-link" href="'.base_url("img/".$field->no_barang."/".$field->foto).'" data-lightbox="example-1">
|
||||
<button class="btn btn-sm round btn-outline-success" title="Lihat Foto Produk '.$field->kode_barang.'"> <span class="sr-only"></span> <i class="fa fa-file-image-o"></i> </button> </a> <button class="btn btn-sm round btn-outline-info" onclick="cek_laporan('.$field->no_barang.')" title="Lihat Laporan Produk"> <span class="sr-only"></span>
|
||||
<i class="fa fa-list"></i> </button> <button class="btn btn-sm round btn-outline-primary" onclick="cek_detail_barang('.$field->no_barang.')" title="Edit Detail Barang '.$field->kode_barang.'"><span class="sr-only"></span> <i class="fa fa-pencil-square"></i></button>';
|
||||
$data[] = $row;
|
||||
}
|
||||
|
||||
$output = array(
|
||||
"draw" => $_POST['draw'],
|
||||
"recordsTotal" => $this->m_tabel_ss->count_all("tb_barang",null,null,"*"),
|
||||
"recordsFiltered" => $this->m_tabel_ss->count_filtered(array('kode_barang','nama','jumlah','harga_jual'),array('kode_barang','nama','jumlah','harga_jual',null),array('no' => 'desc'),"tb_barang",null,null,"*"),
|
||||
"data" => $data,
|
||||
);
|
||||
//output dalam format JSON
|
||||
echo json_encode($output);
|
||||
}
|
||||
|
||||
if ($this->input->post('proses') == "get_produk_laporan") {
|
||||
$list = $this->m_tabel_ss->get_datatables(array('no_barang','status','waktu'),array('waktu','status','ket',),array('no_log' => 'desc'),"tb_log_history",null,['no_barang' => $this->input->post('id')],"*");
|
||||
$data = array();
|
||||
$no = $_POST['start'];
|
||||
foreach ($list as $field) {
|
||||
$json = json_decode($field->ket);
|
||||
$text = null;
|
||||
if($field->status == 'Penambahan Produk Baru'){
|
||||
$text = ' Kode Barang : '.$json->kode_barang.'<br>Nama Barang : '.$json->nama.'<br>Harga Jual : Rp. '.$json->harga_jual.'<br>Jumlah : '.$json->jumlah.'<br>Pembelian Stok : Rp. '.$json->pembelian_stok;
|
||||
}else if($field->status == 'Penambahan Stok'){
|
||||
$text = 'Penambahan Stok: '.$json->penambahan_stok.'<br>Harga Pembelian Stok : Rp. '.$json->harga_pembelian_stok.'<br>Jumlah Stok Sebelumnya : '.$json->jumlah_stok_sebelumnya.'<br>Total Stok : '.$json->total_stok;#region;
|
||||
}else if($field->status == 'Edit Detail Produk'){
|
||||
$nama = ($json->nama_lama == $json->nama_baru) ? null : 'Nama : '.$json->nama_lama.' => '.$json->nama_baru;
|
||||
$harga = ($json->harga_lama == $json->harga_baru) ? null : 'Harga : Rp. '.$json->harga_lama.' => Rp. '.$json->harga_baru;
|
||||
$foto = ($json->foto_lama == $json->foto_baru) ? null : 'Foto : '.$json->foto_lama.' => '.$json->foto_baru;
|
||||
$text = $nama.(($harga != null)?'<br>':null).$harga.(($foto != null)?'<br>':null).$foto;
|
||||
}else if($field->status == 'Penjualan Barang Spesifik'){
|
||||
$text = "Jumlah Pembelian : ".$json->jumlah_pembelian."<br>Harga Jual : Rp. ".$json->harga_jual."<br>Total Penjualan : Rp. ".$json->total_harga."<br>Stok Sebelumnya : ".$json->stok_sebelumnya."<br>Stok Terbaru : ".$json->stok_sekarang;
|
||||
}
|
||||
|
||||
|
||||
$no++;
|
||||
$row = array();
|
||||
// $row[] = $no;
|
||||
$row[] = $field->waktu;
|
||||
$row[] = ($field->status == "Penjualan Barang Spesifik") ? "Penjualan Produk" :$field->status;
|
||||
$row[] = $text;
|
||||
$data[] = $row;
|
||||
}
|
||||
|
||||
|
||||
$output = array(
|
||||
"draw" => $_POST['draw'],
|
||||
"recordsTotal" => $this->m_tabel_ss->count_all("tb_log_history",null,['no_barang' => $this->input->post('id')],"*"),
|
||||
"recordsFiltered" => $this->m_tabel_ss->count_filtered(array('no_barang','status','waktu'),array('waktu','status','ket',),array('no_log' => 'desc'),"tb_log_history",null,['no_barang' => $this->input->post('id')],"*"),
|
||||
"data" => $data,
|
||||
);
|
||||
//output dalam format JSON
|
||||
echo json_encode($output);
|
||||
}
|
||||
|
||||
if ($this->input->post('proses') == "get_laporan") {
|
||||
$list = $this->m_tabel_ss->get_datatables(array('no_barang','status','waktu'),array('waktu','status',null,null,null,null),array('no_log' => 'desc'),"tb_log_history",null,"status !='Penjualan Barang Spesifik' ","*");
|
||||
$data = array();
|
||||
$no = $_POST['start'];
|
||||
foreach ($list as $field) {
|
||||
$json = json_decode($field->ket);
|
||||
$text = null;
|
||||
$stok_sebelumnya = "-";
|
||||
$stok_terbaru = "-";
|
||||
$kode_barang = '-';
|
||||
if($field->status == 'Penambahan Produk Baru'){
|
||||
$text = ' Kode Barang : '.$json->kode_barang.'<br>Nama Barang : '.$json->nama.'<br>Harga Jual : Rp. '.$json->harga_jual.'<br>Jumlah : '.$json->jumlah.'<br>Pembelian Stok : Rp. '.$json->pembelian_stok;
|
||||
$stok_sebelumnya = '-';
|
||||
$stok_terbaru = $json->jumlah;
|
||||
}else if($field->status == 'Penambahan Stok'){
|
||||
$text = 'Penambahan Stok: '.$json->penambahan_stok.'<br>Harga Pembelian Stok : Rp. '.$json->harga_pembelian_stok.'<br>Jumlah Stok Sebelumnya : '.$json->jumlah_stok_sebelumnya.'<br>Total Stok : '.$json->total_stok;
|
||||
$stok_sebelumnya = $json->jumlah_stok_sebelumnya;
|
||||
$stok_terbaru = $json->total_stok;
|
||||
}else if($field->status == 'Edit Detail Produk'){
|
||||
$nama = ($json->nama_lama == $json->nama_baru) ? null : 'Nama : '.$json->nama_lama.' => '.$json->nama_baru;
|
||||
$harga = ($json->harga_lama == $json->harga_baru) ? null : 'Harga : Rp. '.$json->harga_lama.' => Rp. '.$json->harga_baru;
|
||||
$foto = ($json->foto_lama == $json->foto_baru) ? null : 'Foto : '.$json->foto_lama.' => '.$json->foto_baru;
|
||||
$text = $nama.(($harga != null)?'<br>':null).$harga.(($foto != null)?'<br>':null).$foto;
|
||||
}else if($field->status == 'Penjualan Produk'){
|
||||
$text = '<button class="btn btn-primary btn-sm text-center"
|
||||
onclick="info_penjualan('.$field->no_log.')">Info Penjualan</button>';
|
||||
}
|
||||
|
||||
if($field->status != 'Penjualan Produk'){
|
||||
$cek_data = $this->model->tampil_data_where('tb_barang',array('no_barang' => $field->no_barang))->result()[0];
|
||||
$kode_barang = $cek_data->kode_barang;
|
||||
}
|
||||
|
||||
$no++;
|
||||
$row = array();
|
||||
// $row[] = $no;
|
||||
$row[] = $field->waktu;
|
||||
$row[] = $field->status;
|
||||
$row[] = $kode_barang;
|
||||
$row[] = $stok_sebelumnya;
|
||||
$row[] = $stok_terbaru;
|
||||
$row[] = $text;
|
||||
$data[] = $row;
|
||||
}
|
||||
|
||||
|
||||
$output = array(
|
||||
"draw" => $_POST['draw'],
|
||||
"recordsTotal" => $this->m_tabel_ss->count_all("tb_log_history",null,"status !='Penjualan Barang Spesifik' ","*"),
|
||||
"recordsFiltered" => $this->m_tabel_ss->count_filtered(array('no_barang','status','waktu'),array('waktu','status',null,null,null,null),array('no_log' => 'desc'),"tb_log_history",null,"status !='Penjualan Barang Spesifik' ","*"),
|
||||
"data" => $data,
|
||||
);
|
||||
//output dalam format JSON
|
||||
echo json_encode($output);
|
||||
}
|
||||
|
||||
|
||||
////// dibawah simpan untuk referensi ////
|
||||
if ($this->input->post('proses') == "table_list_guru_simpanan_wajib") {
|
||||
$list = $this->m_tabel_ss->get_datatables(array('nik_user','nama'),array(null, 'nik_user','nama',null,null,null),array('tanggaL_daftar' => 'desc'),"tb_user",null,['status' => 'aktif'],"*");
|
||||
$data = array();
|
||||
$no = $_POST['start'];
|
||||
function date_simpanan_wajib($a,$b)
|
||||
{
|
||||
return strcmp($a['tanggal_simpanan'],$b['tanggal_simpanan']);
|
||||
}
|
||||
foreach ($list as $field) {
|
||||
|
||||
|
||||
$simpanan_wajib = json_decode($field->simpanan_wajib,true) ?? null;
|
||||
if($simpanan_wajib != null){
|
||||
|
||||
|
||||
/// atur kembali array berdasarkan tanggal
|
||||
usort($simpanan_wajib , 'date_simpanan_wajib');
|
||||
end($simpanan_wajib);
|
||||
$key = key($simpanan_wajib);
|
||||
$simpanan_wajib = $simpanan_wajib[$key];
|
||||
////pilih array yg terakhir dari key
|
||||
|
||||
}
|
||||
|
||||
$no++;
|
||||
$row = array();
|
||||
$row[] = $no;
|
||||
$row[] = $field->nik_user;
|
||||
$row[] = $field->nama;
|
||||
$row[] = $simpanan_wajib['tanggal_simpanan'] ?? 'Belum Pernah Melakukan Simpanan Wajib ';
|
||||
$row[] = ($simpanan_wajib) ? 'Rp. '.number_format( $simpanan_wajib['simpanan']) : '-';
|
||||
$row[] = '<center><button type="button" onclick="detail_user('.$field->nik_user.')" class="btn btn-primary btn-circle btn-sm waves-effect waves-light"><i class="ico fa fa-edit"></i></button></center>';
|
||||
$data[] = $row;
|
||||
}
|
||||
|
||||
$output = array(
|
||||
"draw" => $_POST['draw'],
|
||||
"recordsTotal" => $this->m_tabel_ss->count_all("tb_user",null,['status' => 'aktif'],"*"),
|
||||
"recordsFiltered" => $this->m_tabel_ss->count_filtered(array('nik_user','nama'),array(null, 'nik_user','nama',null,null,null),array('tanggaL_daftar' => 'desc'),"tb_user",null,['status' => 'aktif'],"*"),
|
||||
"data" => $data,
|
||||
);
|
||||
//output dalam format JSON
|
||||
echo json_encode($output);
|
||||
}
|
||||
//// diatas simpan untuk referensi ////
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
function coba(){
|
||||
print_r('coba');
|
||||
}
|
||||
|
||||
// function coba2(){
|
||||
// $i = 1;
|
||||
// $bulan = '02';
|
||||
// $tahun = '2021';
|
||||
// $cek_data = $this->model->tampil_data_keseluruhan('tb_user')->result();
|
||||
|
||||
// // $array_simpnanan_wajib_detail =[];
|
||||
// $data=null;
|
||||
// foreach ($cek_data as $key => $value) {
|
||||
// $ket_simpanan_wajib = json_decode($value->simpanan_wajib,true) ?? null;
|
||||
|
||||
|
||||
// if ($ket_simpanan_wajib !=null) {
|
||||
// foreach ($ket_simpanan_wajib as $key1 => $value1) {
|
||||
// $datetime = new DateTime($value1['tanggal_simpanan']);
|
||||
// $bulannya = $datetime->format('m');
|
||||
// $tahunnya = $datetime->format('Y');
|
||||
|
||||
// if($bulannya == $bulan and $tahunnya == $tahun){
|
||||
// $data[$i]['nik_user'] = $value->nik_user;
|
||||
// $data[$i]['nama'] = $value->nama;
|
||||
// $data[$i]['tanggal_simpanan'] = $value1['tanggal_simpanan'];
|
||||
// $data[$i]['simpanan'] = $value1['simpanan'];
|
||||
// $i ++;
|
||||
// }
|
||||
|
||||
|
||||
// }
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
// // print_r($data);
|
||||
|
||||
|
||||
|
||||
// function date_simpanan($a,$b)
|
||||
// {
|
||||
// return strcmp($a['tanggal_simpanan'],$b['tanggal_simpanan']);
|
||||
// }
|
||||
|
||||
// if($data != null){
|
||||
// // $ket = json_decode($cek_data[0]->simpanan_wajib,true);
|
||||
|
||||
// $ii = 1;
|
||||
// /// atur kembali array berdasarkan tanggal
|
||||
// usort($data , 'date_simpanan');
|
||||
// foreach ($data as $key => $value) {
|
||||
// $data1[$ii]['no'] = $ii;
|
||||
// $data1[$ii]['nik'] = $value['nik_user'];
|
||||
// $data1[$ii]['nama'] = $value['nama'];
|
||||
// $data1[$ii]['tanggal_simpanan'] = $value['tanggal_simpanan'];
|
||||
// $data1[$ii]['simpanan'] = 'Rp. '. number_format($value['simpanan']);
|
||||
// // $data[$ii]['foto'] = $value['foto'];
|
||||
|
||||
// $ii++;
|
||||
|
||||
// }
|
||||
// // print_r($data1);
|
||||
// $out = array_values($data1);
|
||||
// echo json_encode($out);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// echo json_encode(array());
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
25
server/application/controllers/Welcome.php
Normal file
25
server/application/controllers/Welcome.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Welcome extends CI_Controller {
|
||||
|
||||
/**
|
||||
* Index Page for this controller.
|
||||
*
|
||||
* Maps to the following URL
|
||||
* http://example.com/index.php/welcome
|
||||
* - or -
|
||||
* http://example.com/index.php/welcome/index
|
||||
* - or -
|
||||
* Since this controller is set as the default controller in
|
||||
* config/routes.php, it's displayed at http://example.com/
|
||||
*
|
||||
* So any other public methods not prefixed with an underscore will
|
||||
* map to /index.php/welcome/<method_name>
|
||||
* @see https://codeigniter.com/user_guide/general/urls.html
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->load->view('welcome_message');
|
||||
}
|
||||
}
|
||||
11
server/application/controllers/index.html
Normal file
11
server/application/controllers/index.html
Normal file
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user