Update besar apk finance

This commit is contained in:
Wian Drs
2026-09-11 16:03:00 +07:00
parent d42483b350
commit 4ef15c22ae
897 changed files with 98056 additions and 15979 deletions
+32 -42
View File
@@ -1,7 +1,7 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Kodebarang extends CI_Controller {
class Kodebarang extends MY_Controller {
public function __construct()
{
@@ -25,7 +25,7 @@ class Kodebarang extends CI_Controller {
// =========================
public function get_data()
{
$data = $this->db->order_by('id', 'DESC')->get('kode_barang')->result();
$data = $this->db->where('company_id',(int)$this->session->userdata('company_id'))->order_by('id', 'DESC')->get('kode_barang')->result();
$result = [];
$no = 1;
@@ -38,11 +38,10 @@ class Kodebarang extends CI_Controller {
(int)$row->limit_stock,
strtoupper($row->tracking_type ?? 'UNIT'),
strtolower($row->need_serial_number ?? 'false') === 'true' ? 'Ya' : 'Tidak',
(int)($row->allocate_purchase_cost ?? 0) === 1 ? 'Ya' : 'Tidak',
$row->unit ?? 'PCS',
'
<button class="btn btn-sm btn-secondary btn-editkode" data-id="'.$row->id.'">Edit</button>
<button class="btn btn-sm btn-danger btn-delete" data-id="'.$row->id.'">Delete</button>
'
(int)$row->is_active===1?'<span class="status-chip status-approved">Aktif</span>':'<span class="status-chip status-rejected">Nonaktif</span>',
($this->session->userdata('role')==='Admin'||check_permission('items','can_update'))?'<button class="btn btn-sm btn-outline-primary btn-editkode" data-id="'.$row->id.'"><i class="bi bi-pencil"></i> Ubah</button>':'-'
];
}
@@ -55,7 +54,7 @@ class Kodebarang extends CI_Controller {
public function detail($id)
{
echo json_encode(
$this->db->get_where('kode_barang',['id'=>$id])->row()
$this->db->get_where('kode_barang',['id'=>$id,'company_id'=>(int)$this->session->userdata('company_id')])->row()
);
}
@@ -69,7 +68,9 @@ class Kodebarang extends CI_Controller {
$limit_stock = (int)$this->input->post('limit_stock');
$tracking_type = strtoupper(trim($this->input->post('tracking_type')));
$need_serial_number = strtolower(trim($this->input->post('need_serial_number')));
$allocate_purchase_cost = $this->input->post('allocate_purchase_cost') ? 1 : 0;
$unit = trim($this->input->post('unit'));
$is_active = $this->input->post('is_active') ? 1 : 0;
if(!$nama || !$kode){
echo json_encode(['status'=>false,'message'=>'Kode dan nama wajib diisi']);
@@ -91,7 +92,7 @@ class Kodebarang extends CI_Controller {
return;
}
$exists = $this->db->get_where('kode_barang', ['kode_barang' => $kode])->num_rows();
$exists = $this->db->get_where('kode_barang', ['kode_barang' => $kode,'company_id'=>(int)$this->session->userdata('company_id')])->num_rows();
if($exists > 0){
echo json_encode(['status'=>false,'message'=>'Kode barang sudah digunakan']);
return;
@@ -99,12 +100,15 @@ class Kodebarang extends CI_Controller {
$this->db->insert('kode_barang', [
'kode_barang' => $kode,
'company_id' => (int)$this->session->userdata('company_id'),
'nama' => $nama,
'created_at' => date('Y-m-d H:i:s'),
'limit_stock' => $limit_stock,
'tracking_type' => $tracking_type,
'need_serial_number' => $need_serial_number,
'unit' => $unit
'allocate_purchase_cost' => $allocate_purchase_cost,
'unit' => $unit,
'is_active' => $is_active
]);
log_activity(
@@ -128,7 +132,9 @@ class Kodebarang extends CI_Controller {
$limit_stock = (int)$this->input->post('limit_stock');
$tracking_type = strtoupper(trim($this->input->post('tracking_type')));
$need_serial_number = strtolower(trim($this->input->post('need_serial_number')));
$allocate_purchase_cost = $this->input->post('allocate_purchase_cost') ? 1 : 0;
$unit = trim($this->input->post('unit'));
$is_active = $this->input->post('is_active') ? 1 : 0;
if(!$id || !$nama || !$kode){
echo json_encode(['status'=>false,'message'=>'ID, kode dan nama wajib diisi']);
@@ -152,6 +158,7 @@ class Kodebarang extends CI_Controller {
$exists = $this->db
->where('kode_barang', $kode)
->where('company_id',(int)$this->session->userdata('company_id'))
->where('id !=', $id)
->get('kode_barang')
->num_rows();
@@ -161,13 +168,15 @@ class Kodebarang extends CI_Controller {
return;
}
$this->db->where('id',$id)->update('kode_barang', [
$this->db->where(array('id'=>$id,'company_id'=>(int)$this->session->userdata('company_id')))->update('kode_barang', [
'kode_barang' => $kode,
'nama' => $nama,
'limit_stock' => $limit_stock,
'tracking_type' => $tracking_type,
'need_serial_number' => $need_serial_number,
'unit' => $unit
'allocate_purchase_cost' => $allocate_purchase_cost,
'unit' => $unit,
'is_active' => $is_active
]);
log_activity(
@@ -185,44 +194,25 @@ class Kodebarang extends CI_Controller {
// =========================
public function delete($id)
{
$row = $this->db->get_where('kode_barang', ['id'=>$id])->row();
if(!$row){
echo json_encode([
'status'=>false,
'message'=>'Data kode barang tidak ditemukan'
]);
return;
if (strtoupper($this->input->method()) !== 'POST') {
$this->output->set_status_header(405);
} else {
$this->output->set_status_header(409);
}
// cek relasi ke items (mengacu ke kode_id)
$cek = $this->db->get_where('items',['kode_id'=>$id])->num_rows();
if($cek > 0){
echo json_encode([
'status'=>false,
'message'=>'Kode barang tidak bisa dihapus karena masih dipakai item'
]);
return;
}
$this->db->delete('kode_barang',['id'=>$id]);
log_activity(
'kode_barang',
'delete',
'Hapus kode barang ID: ' . $id . ' (' . $row->kode_barang . ' - ' . $row->nama . ')',
'success'
);
echo json_encode(['status'=>true,'message'=>'Kode barang berhasil dihapus']);
return $this->output
->set_content_type('application/json')
->set_output(json_encode(array(
'status' => false,
'message' => 'Jenis/Kode Barang tidak dapat dihapus. Nonaktifkan melalui tombol Ubah.'
)));
}
public function list()
{
echo json_encode(
$this->db->get('kode_barang')->result()
$this->db->where(array('company_id'=>(int)$this->session->userdata('company_id'),'is_active'=>1))->get('kode_barang')->result()
);
}
}
}