added server2, This is use in online server for the notification to boss mobile app

This commit is contained in:
kicap1992
2022-01-31 05:20:45 +08:00
parent 10d958015f
commit 89ee6fbb90
487 changed files with 212589 additions and 0 deletions

View File

@ -0,0 +1,362 @@
<?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
{
function __construct()
{
parent::__construct();
$this->load->model('model');;
// $this->db->query("SET sql_mode = '' ");
date_default_timezone_set("Asia/Kuala_Lumpur");
}
public function index_get()
{
$this->response(['message' => 'Halo Bosku'], 200);
// redirect(base_url());
}
// --------------------------------dibawah khusus untuk admin -----------------------------//
public function coba_post()
{
$file = $_FILES['myfile'];
$dir = "img/hehe/";
if (is_dir($dir) === false) {
mkdir($dir);
}
move_uploaded_file($file['tmp_name'], $dir . $file['name']);
// $file = $this->post('Id');
$this->response(['message' => $file], 200);
}
public function tambah_produk_post()
{
$foto = $_FILES['foto'];
$data = json_decode($this->post('data'), true);
unset($data['ke_db_online']);
$history = json_decode($this->post('history'), true);
unset($history['ke_db_online']);
$dir = "img/" . $data['no_barang'] . "/";
if (is_dir($dir) === false) {
mkdir($dir);
}
move_uploaded_file($foto['tmp_name'], $dir . $foto['name']);
$this->model->insert('tb_barang', $data);
$this->model->insert('tb_log_history', $history);
$this->response(['message' => 'tambah produk', 'data' => $history], 200);
}
public function tambah_stok_post()
{
$foto = $_FILES['foto'];
$data = json_decode($this->post('data'), true);
unset($data['ke_db_online']);
$history = json_decode($this->post('history'), true);
unset($history['ke_db_online']);
$jumlah_stok = json_decode($history['ket'], true);
$jumlah_stok = $jumlah_stok['total_stok'];
$cek_data = $this->model->tampil_data_where('tb_barang', ['no_barang' => $data['no_barang']])->result();
if (count($cek_data) > 0) {
} else {
$dir = "img/" . $data['no_barang'] . "/";
if (is_dir($dir) === false) {
mkdir($dir);
}
move_uploaded_file($foto['tmp_name'], $dir . $foto['name']);
$this->model->insert('tb_barang', $data);
}
$this->model->insert('tb_log_history', $history);
$this->model->update('tb_barang', array('no_barang' => $history['no_barang']), array('jumlah' => $jumlah_stok));
$this->response(['message' => 'tambah stok'], 200);
// $this->response(['message' => 'tambah produk', 'data' => $history], 200);
}
public function edit_detail_produk_post()
{
$foto = $_FILES['foto'];
$data = json_decode($this->post('data'), true);
unset($data['ke_db_online']);
$history = json_decode($this->post('history'), true);
unset($history['ke_db_online']);
$cek_foto = $this->post('cek_foto');
$cek_data = $this->model->tampil_data_where('tb_barang', ['no_barang' => $data['no_barang']])->result();
if (count($cek_data) > 0) {
if ($cek_foto == 'ada') {
$dir = "img/" . $data['no_barang'] . "/";
if (is_dir($dir) === false) {
mkdir($dir);
}
//delete all file in folder
$files = glob($dir . '*'); // get all file names
foreach ($files as $file) { // iterate files
if (is_file($file))
unlink($file); // delete file
}
move_uploaded_file($foto['tmp_name'], $dir . $foto['name']);
// $this->model->insert('tb_barang', $data);
}
} else {
$dir = "img/" . $data['no_barang'] . "/";
if (is_dir($dir) === false) {
mkdir($dir);
}
move_uploaded_file($foto['tmp_name'], $dir . $foto['name']);
$this->model->insert('tb_barang', $data);
}
$this->model->insert('tb_log_history', $history);
$this->model->update('tb_barang', array('no_barang' => $data['no_barang']), $data);
$this->response(['message' => 'edit_detail'], 200);
}
public function penjualan_post()
{
$data_barang = json_decode($this->post('data_barang'), true);
$history_barang = json_decode($this->post('history_barang'), true);
$foto = $_FILES['foto'];
$countfoto = count($foto['name']);
for ($i = 0; $i < $countfoto; $i++) {
$cek_barang = $this->model->tampil_data_where('tb_barang', ['no_barang' => $data_barang[$i]['no_barang']])->result();
unset($data_barang[$i]['ke_db_online']);
unset($history_barang[$i]['ke_db_online']);
if (count($cek_barang) > 0) {
} else {
$this->model->insert('tb_barang', $data_barang[$i]);
$dir = "img/penjualan/" . $foto['name'][$i] . '/';
if (is_dir($dir) === false) {
mkdir($dir);
}
move_uploaded_file($foto['tmp_name'][$i], $dir . $foto['name'][$i]);
}
# code...
}
foreach ($data_barang as $key => $value) {
// unset($value['ke_db_online']);
$this->model->update('tb_barang', array('no_barang' => $value['no_barang']), $value);
$this->model->insert('tb_log_history', $history_barang[$key]);
}
$history = json_decode($this->post('history'), true);
unset($history['ke_db_online']);
$this->model->insert('tb_log_history', $history);
$this->response(['message' => $data_barang[0]], 200);
}
public function update_laporan_post()
{
$cek_data_barang = $this->post('cek_data_barang');
if ($cek_data_barang == 'ada') {
$data_barang = json_decode($this->post('data_barang'), true);
$foto = $_FILES['foto'];
foreach ($data_barang as $key => $value) {
unset($data_barang[$key]['ke_db_online']);
$cek_barang = $this->model->tampil_data_where('tb_barang', ['no_barang' => $value['no_barang']])->result();
if (count($cek_barang) > 0) {
$this->model->update('tb_barang', array('no_barang' => $value['no_barang']), $data_barang[$key]);
} else {
$this->model->insert('tb_barang', $data_barang[$key]);
}
$dir = "img/" . $value['no_barang'] . '/';
if (is_dir($dir) === false) {
mkdir($dir);
}
move_uploaded_file($foto['tmp_name'][$key], $dir . $foto['name'][$key]);
}
}
$cek_data_history = $this->post('cek_data_history');
if ($cek_data_history == 'ada') {
$history = json_decode($this->post('history'), true);
foreach ($history as $key => $value) {
unset($history[$key]['ke_db_online']);
$cek_history = $this->model->tampil_data_where('tb_log_history', ['no_log' => $value['no_log']])->result();
if (count($cek_history) > 0) {
$this->model->update('tb_log_history', array('no_log' => $value['no_log']), $history[$key]);
} else {
$this->model->insert('tb_log_history', $history[$key]);
}
}
}
$this->response(['message' => $cek_data_barang], 200);
}
public function login_user_get(){
$username = $this->get('username');
$password = md5($this->get('password'));
$cek_data = $this->model->tampil_data_where('tb_login', ['username' => $username, 'password' => $password])->result();
if (count($cek_data) > 0) {
$this->response(['message' => 'login_berhasil','data' => $cek_data[0]], 200);
} else {
$this->response(['message' => 'login_gagal'], 401);
}
// $this->response(['message' => $cek_data], 200);
}
public function ambil_laporan_get(){
$tanggal = $this->get('tanggal');
$bulan = $this->get('bulan');
$tahun = $this->get('tahun');
$filter = $this->get('filter');
if($tanggal != null || $tanggal != ''){
if($filter != null || $filter != ''){
$cek_data = $this->model->custom_query("SELECT * FROM tb_log_history where status != 'Penjualan Barang Spesifik' and DATE(waktu) = DATE('".$tanggal."') and (waktu like '%".$filter."%' or status like '%".$filter."%') order by waktu desc")->result();
}else{
$cek_data = $this->model->custom_query("SELECT * FROM tb_log_history where status != 'Penjualan Barang Spesifik' and DATE(waktu) = DATE('".$tanggal."') order by waktu desc")->result();
}
}else{
if($filter != null || $filter != ''){
$cek_data = $this->model->custom_query("SELECT * FROM tb_log_history where status != 'Penjualan Barang Spesifik' and MONTH(waktu) = $bulan and YEAR(waktu) = $tahun and (waktu like '%".$filter."%' or status like '%".$filter."%') order by waktu desc")->result();
}else{
$cek_data = $this->model->custom_query("SELECT * FROM tb_log_history where status != 'Penjualan Barang Spesifik' and MONTH(waktu) = $bulan and YEAR(waktu) = $tahun order by waktu desc")->result();
}
}
$this->response(['status' => 'success', 'data' => $cek_data], 200);
}
public function ambil_laporan_detail_get(){
$no_log = $this->get('no_log');
$cek_data = $this->model->tampil_data_where('tb_log_history', ['no_log' => $no_log])->result();
$this->response(['status' => 'success', 'data' => $cek_data], 200);
}
public function ambil_produk_all_get(){
$page = $this->get('page');
$cekfilter = $this->get('cekfilter');
$filter = $this->get('filter');
$data_all = $this->model->tampil_data_keseluruhan('tb_barang')->result();
if($page == '1'){
$page = (int)$page - 1;
}else{
$page = ((int)$page - 1) * 10;
}
if($cekfilter == 'ada'){
$data_all = $this->model->custom_query("SELECT * FROM `tb_barang` WHERE nama like '%$filter%' or kode_barang like '%$filter%'")->result();
$cek_data = $this->model->custom_query("SELECT * FROM `tb_barang` WHERE nama like '%$filter%' or kode_barang like '%$filter%' LIMIT $page, 10")->result();
}else if($cekfilter == 'tiada'){
$cek_data = $this->model->custom_query("SELECT * FROM `tb_barang` LIMIT $page, 10")->result();
}
$this->response(['status' => 'success','ceil' => count($data_all), 'data' => $cek_data ], 200);
}
public function ambil_log_produk_detail_get(){
$page = $this->get('page');
$no_barang = $this->get('no_barang');
$cekfilter = $this->get('haha');
$filter = $this->get('filter');
$data_all = $this->model->tampil_data_where('tb_log_history',['no_barang' => $no_barang])->result();
if($page == '1'){
$page = (int)$page - 1;
}else{
$page = ((int)$page - 1) * 10;
}
if($cekfilter == 'ada'){
$data_all = $this->model->custom_query("SELECT * FROM `tb_log_history` WHERE no_barang = '$no_barang' and (waktu like '%$filter%' or status like '%$filter%')")->result();
$cek_data = $this->model->custom_query("SELECT * FROM `tb_log_history` WHERE no_barang=$no_barang and (waktu like '%$filter%' or status like '%$filter%') order by waktu desc LIMIT $page, 10")->result();
}else if($cekfilter == 'tiada'){
$cek_data = $this->model->custom_query("SELECT * FROM `tb_log_history` WHERE no_barang=$no_barang order by waktu desc LIMIT $page, 10")->result();
}
$this->response(['status' => 'success','page' => $page,'ceil' => count($data_all), 'data' => $cek_data , 'filter' => $filter, 'cek_filter' => $cekfilter], 200);
}
public function ambil_produk_detail_get(){
$no_barang = $this->get('no_barang');
$cek_data = $this->model->tampil_data_where('tb_barang',['no_barang' => $no_barang ])->result()[0];
$this->response(['status' => 'success', 'data' => $cek_data ], 200);
}
public function ambil_laporan_all_get(){
$page = $this->get('page');
$cekfilter = $this->get('haha');
$filter = $this->get('filter');
$data_all = $this->model->custom_query("SELECT * FROM `tb_log_history` WHERE status != 'Penjualan Barang Spesifik'")->result();
if($page == '1'){
$page = (int)$page - 1;
}else{
$page = ((int)$page - 1) * 10;
}
if($cekfilter == 'ada'){
$data_all = $this->model->custom_query("SELECT * FROM `tb_log_history` WHERE status != 'Penjualan Barang Spesifik' and (waktu like '%$filter%' or status like '%$filter%')")->result();
$cek_data = $this->model->custom_query("SELECT * FROM `tb_log_history` WHERE status != 'Penjualan Barang Spesifik' and (waktu like '%$filter%' or status like '%$filter%') order by waktu desc LIMIT $page, 10")->result();
}else if($cekfilter == 'tiada'){
$cek_data = $this->model->custom_query("SELECT * FROM `tb_log_history` WHERE status != 'Penjualan Barang Spesifik' order by waktu desc LIMIT $page, 10")->result();
}
$this->response(['status' => 'success','page' => $page,'ceil' => count($data_all), 'data' => $cek_data , 'filter' => $filter, 'cek_filter' => $cekfilter], 200);
}
public function cek_datanya_get(){
$cek_data = $this->model->custom_query("SELECT no_log FROM tb_log_history WHERE dibaca = 'Belum' and status !='Penjualan Barang Spesifik'")->result();
// $nilai = (count($cek_data) > 0) ? "ada datanya di server" : "tiada datanya di server";
$this->response(['status' => 'success', 'data' => $cek_data], 200);
}
public function laporan_read_get(){
$no_log = $this->get('no_log');
$this->model->update('tb_log_history',['no_log' => $no_log],['dibaca' => 'Sudah']);
// $nilai = (count($cek_data) > 0) ? "ada datanya di server" : "tiada datanya di server";
$this->response(['status' => 'success', 'data' => $no_log], 200);
}
public function laporan_read_all_get(){
// $no_log = $this->get('no_log');
$this->model->custom_query("UPDATE tb_log_history SET dibaca = 'Sudah'");
// $nilai = (count($cek_data) > 0) ? "ada datanya di server" : "tiada datanya di server";
$this->response(['status' => 'success'], 200);
}
}

View File

@ -0,0 +1,214 @@
<?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>&nbsp;<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>&nbsp;<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' => '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;
}
$no++;
$row = array();
// $row[] = $no;
$row[] = $field->waktu;
$row[] = $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' => 'desc'),"tb_log_history",null,['no_barang' => $this->input->post('id')],"*"),
"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 ////
while (true) {
print_r("hehe");
}
}
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());
// }
// }
}

View 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');
}
}

View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>