Update Controller Items karena ada bug
@@ -5,7 +5,7 @@ application/config/database.php
|
|||||||
application/controllers/Dbcompare.php
|
application/controllers/Dbcompare.php
|
||||||
.htaccess
|
.htaccess
|
||||||
|
|
||||||
uploads/temp_qr/*.png
|
uploads/temp_qr/*
|
||||||
|
|
||||||
application/cache/*
|
application/cache/*
|
||||||
!application/cache/index.html
|
!application/cache/index.html
|
||||||
|
|||||||
@@ -540,6 +540,7 @@ class Items extends CI_Controller {
|
|||||||
$btnDelete = '<button class="btn btn-danger btn-sm btn-delete m-1" data-id="'.htmlspecialchars($row->id, ENT_QUOTES, 'UTF-8').'">Delete</button>';
|
$btnDelete = '<button class="btn btn-danger btn-sm btn-delete m-1" data-id="'.htmlspecialchars($row->id, ENT_QUOTES, 'UTF-8').'">Delete</button>';
|
||||||
$btnInsertSn = '<a href="'.base_url('items/item_barcodes/'.$row->id).'" class="btn btn-secondary btn-sm m-1">Barcode</a>';
|
$btnInsertSn = '<a href="'.base_url('items/item_barcodes/'.$row->id).'" class="btn btn-secondary btn-sm m-1">Barcode</a>';
|
||||||
$btnPrintBarcode = '<button class="btn btn-secondary btn-sm btn-print m-1" data-id="'.htmlspecialchars($row->id, ENT_QUOTES, 'UTF-8').'"><i class="bi bi-printer"></i> Print Barcode</button>';
|
$btnPrintBarcode = '<button class="btn btn-secondary btn-sm btn-print m-1" data-id="'.htmlspecialchars($row->id, ENT_QUOTES, 'UTF-8').'"><i class="bi bi-printer"></i> Print Barcode</button>';
|
||||||
|
$btnPost = '<button class="btn btn-success btn-sm btn-updatePosting m-1" data-id="'.htmlspecialchars($row->id, ENT_QUOTES, 'UTF-8').'">Posting</button>';
|
||||||
|
|
||||||
if ($row->need_serial_number == 'true') {
|
if ($row->need_serial_number == 'true') {
|
||||||
|
|
||||||
@@ -564,8 +565,10 @@ class Items extends CI_Controller {
|
|||||||
if ($row->status == 'draft') {
|
if ($row->status == 'draft') {
|
||||||
if ($total_sn == $done_sn) {
|
if ($total_sn == $done_sn) {
|
||||||
$btnSN = $btnInsertSn . $btnPrintBarcode;
|
$btnSN = $btnInsertSn . $btnPrintBarcode;
|
||||||
|
$btnPostview = $btnPost;
|
||||||
} else {
|
} else {
|
||||||
$btnSN = $btnInsertSn ;
|
$btnSN = $btnInsertSn ;
|
||||||
|
$btnPostview = '';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$btnSN = $btnPrintBarcode;
|
$btnSN = $btnPrintBarcode;
|
||||||
@@ -574,11 +577,11 @@ class Items extends CI_Controller {
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
$btnSN = $btnPrintBarcode;
|
$btnSN = $btnPrintBarcode;
|
||||||
|
$btnPostview = $btnPost;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($row->status == 'draft'){
|
if($row->status == 'draft'){
|
||||||
$btnPost = '<button class="btn btn-success btn-sm btn-updatePosting m-1" data-id="'.htmlspecialchars($row->id, ENT_QUOTES, 'UTF-8').'">Posting</button>';
|
$action = $btnDetail . $btnPostview . $btnDelete . $btnSN;
|
||||||
$action = $btnDetail . $btnPost . $btnDelete . $btnSN;
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@@ -1424,114 +1427,144 @@ class Items extends CI_Controller {
|
|||||||
echo json_encode($data);
|
echo json_encode($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update_barcode_item()
|
public function update_barcode_item()
|
||||||
{
|
{
|
||||||
$items = $this->db
|
$items = $this->db
|
||||||
->select("
|
->select("
|
||||||
i.id,
|
i.id,
|
||||||
i.nama_barang,
|
i.nama_barang,
|
||||||
i.stok,
|
i.stok,
|
||||||
i.kode_detail,
|
i.kode_detail,
|
||||||
kb.tracking_type
|
kb.tracking_type,
|
||||||
")
|
kb.kode_barang
|
||||||
->from('items i')
|
")
|
||||||
->join('kode_barang kb', 'kb.id=i.kode_id')
|
->from('items i')
|
||||||
->where('i.status', 'active')
|
->join('kode_barang kb', 'kb.id=i.kode_id')
|
||||||
->get()
|
->where('i.status', 'active')
|
||||||
->result();
|
->get()
|
||||||
|
->result();
|
||||||
|
|
||||||
$this->db->trans_begin();
|
$this->db->trans_begin();
|
||||||
|
|
||||||
foreach ($items as $item) {
|
foreach ($items as $item) {
|
||||||
|
|
||||||
// ===========================================
|
// ===========================================
|
||||||
// Hitung jumlah barcode yang seharusnya
|
// Qty per barcode
|
||||||
// ===========================================
|
// ===========================================
|
||||||
|
|
||||||
if ($item->tracking_type == 'UNIT') {
|
if ($item->tracking_type == 'UNIT') {
|
||||||
$target = (int)$item->stok;
|
$qty_per_barcode = 1;
|
||||||
} else {
|
} else {
|
||||||
$target = (int)floor($item->stok / 1000);
|
$qty_per_barcode = ($item->kode_barang == 'FO1') ? 1000 : 2000;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===========================================
|
||||||
|
// Jumlah barcode yang seharusnya
|
||||||
|
// ===========================================
|
||||||
|
|
||||||
|
$target = (int) ceil($item->stok / $qty_per_barcode);
|
||||||
|
|
||||||
|
if ($target <= 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===========================================
|
||||||
|
// Jumlah barcode yang sudah ada
|
||||||
|
// ===========================================
|
||||||
|
|
||||||
|
$barcode_exist = $this->db
|
||||||
|
->where('item_id', $item->id)
|
||||||
|
->count_all_results('item_barcodes');
|
||||||
|
|
||||||
|
if ($barcode_exist >= $target) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===========================================
|
||||||
|
// Total qty barcode yang sudah ada
|
||||||
|
// ===========================================
|
||||||
|
|
||||||
|
$qty_existing = $this->db
|
||||||
|
->select_sum('qty_awal')
|
||||||
|
->where('item_id', $item->id)
|
||||||
|
->get('item_barcodes')
|
||||||
|
->row();
|
||||||
|
|
||||||
|
$qty_existing = (float) ($qty_existing->qty_awal ?? 0);
|
||||||
|
|
||||||
|
// Sisa stok yang belum memiliki barcode
|
||||||
|
$qty_remaining = $item->stok - $qty_existing;
|
||||||
|
|
||||||
|
if ($qty_remaining <= 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$need = $target - $barcode_exist;
|
||||||
|
|
||||||
|
for ($i = 1; $i <= $need; $i++) {
|
||||||
|
|
||||||
|
// Barcode terakhir akan berisi sisa stok
|
||||||
|
$qty = min($qty_per_barcode, $qty_remaining);
|
||||||
|
|
||||||
|
$barcode = strtoupper($item->kode_detail) . '-' . strtoupper(bin2hex(random_bytes(2)));
|
||||||
|
|
||||||
|
// =============================
|
||||||
|
// Insert Barcode
|
||||||
|
// =============================
|
||||||
|
|
||||||
|
$this->db->insert('item_barcodes', [
|
||||||
|
'item_id' => $item->id,
|
||||||
|
'barcode' => $barcode,
|
||||||
|
'warehouse_id' => null,
|
||||||
|
'qty_awal' => $qty,
|
||||||
|
'qty_sisa' => $qty,
|
||||||
|
'status' => 'available'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$barcode_id = $this->db->insert_id();
|
||||||
|
|
||||||
|
// =============================
|
||||||
|
// Insert Movement
|
||||||
|
// =============================
|
||||||
|
|
||||||
|
$this->db->insert('item_movements', [
|
||||||
|
'item_id' => $item->id,
|
||||||
|
'barcode_id' => $barcode_id,
|
||||||
|
'qty' => $qty,
|
||||||
|
'from_type' => 'supplier',
|
||||||
|
'from_id' => null,
|
||||||
|
'to_type' => 'warehouse',
|
||||||
|
'to_id' => null,
|
||||||
|
'movement_type' => 'purchase',
|
||||||
|
'reference_type' => 'system_generate',
|
||||||
|
'reference_id' => null,
|
||||||
|
'notes' => 'Generate barcode otomatis'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$qty_remaining -= $qty;
|
||||||
|
|
||||||
|
if ($qty_remaining <= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($target <= 0) {
|
if ($this->db->trans_status() === FALSE) {
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ===========================================
|
$this->db->trans_rollback();
|
||||||
// Barcode yang sudah ada
|
|
||||||
// ===========================================
|
|
||||||
|
|
||||||
$barcode_exist = $this->db
|
echo json_encode([
|
||||||
->where('item_id', $item->id)
|
'status' => false,
|
||||||
->count_all_results('item_barcodes');
|
'message' => 'Gagal generate barcode.'
|
||||||
|
|
||||||
if ($barcode_exist >= $target) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$need = $target - $barcode_exist;
|
|
||||||
|
|
||||||
for ($i = 1; $i <= $need; $i++) {
|
|
||||||
|
|
||||||
$barcode = strtoupper($item->kode_detail) . '-' . strtoupper(bin2hex(random_bytes(2)));
|
|
||||||
|
|
||||||
$qty = ($item->tracking_type == 'UNIT')
|
|
||||||
? 1
|
|
||||||
: 1000;
|
|
||||||
|
|
||||||
// =============================
|
|
||||||
// Insert Barcode
|
|
||||||
// =============================
|
|
||||||
|
|
||||||
$this->db->insert('item_barcodes', [
|
|
||||||
'item_id' => $item->id,
|
|
||||||
'barcode' => $barcode,
|
|
||||||
'warehouse_id' => null,
|
|
||||||
'qty_awal' => $qty,
|
|
||||||
'qty_sisa' => $qty,
|
|
||||||
'status' => 'available'
|
|
||||||
]);
|
|
||||||
|
|
||||||
$barcode_id = $this->db->insert_id();
|
|
||||||
|
|
||||||
// =============================
|
|
||||||
// Insert Movement
|
|
||||||
// =============================
|
|
||||||
|
|
||||||
$this->db->insert('item_movements', [
|
|
||||||
'item_id' => $item->id,
|
|
||||||
'barcode_id' => $barcode_id,
|
|
||||||
'qty' => $qty,
|
|
||||||
'from_type' => 'supplier',
|
|
||||||
'from_id' => null,
|
|
||||||
'to_type' => 'warehouse',
|
|
||||||
'to_id' => null,
|
|
||||||
'movement_type' => 'purchase',
|
|
||||||
'reference_type' => 'system_generate',
|
|
||||||
'reference_id' => null,
|
|
||||||
'notes' => 'Generate barcode otomatis'
|
|
||||||
]);
|
]);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->db->trans_status() == false) {
|
$this->db->trans_commit();
|
||||||
|
|
||||||
$this->db->trans_rollback();
|
|
||||||
|
|
||||||
echo json_encode([
|
echo json_encode([
|
||||||
'status' => false,
|
'status' => true,
|
||||||
'message' => 'Gagal generate barcode.'
|
'message' => 'Barcode berhasil diperbarui.'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->db->trans_commit();
|
|
||||||
|
|
||||||
echo json_encode([
|
|
||||||
'status' => true,
|
|
||||||
'message' => 'Barcode berhasil diperbarui.'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Before Width: | Height: | Size: 243 B |
|
Before Width: | Height: | Size: 243 B |
|
Before Width: | Height: | Size: 243 B |
|
Before Width: | Height: | Size: 237 B |
|
Before Width: | Height: | Size: 241 B |
|
Before Width: | Height: | Size: 241 B |
|
Before Width: | Height: | Size: 243 B |
|
Before Width: | Height: | Size: 242 B |
|
Before Width: | Height: | Size: 248 B |
|
Before Width: | Height: | Size: 239 B |
|
Before Width: | Height: | Size: 237 B |
|
Before Width: | Height: | Size: 242 B |
|
Before Width: | Height: | Size: 242 B |
|
Before Width: | Height: | Size: 239 B |
|
Before Width: | Height: | Size: 242 B |
|
Before Width: | Height: | Size: 247 B |
|
Before Width: | Height: | Size: 245 B |
|
Before Width: | Height: | Size: 243 B |
|
Before Width: | Height: | Size: 243 B |
|
Before Width: | Height: | Size: 240 B |
|
Before Width: | Height: | Size: 244 B |
|
Before Width: | Height: | Size: 247 B |
|
Before Width: | Height: | Size: 242 B |
|
Before Width: | Height: | Size: 242 B |
|
Before Width: | Height: | Size: 240 B |
|
Before Width: | Height: | Size: 238 B |
|
Before Width: | Height: | Size: 231 B |
|
Before Width: | Height: | Size: 241 B |
|
Before Width: | Height: | Size: 236 B |
|
Before Width: | Height: | Size: 243 B |
|
Before Width: | Height: | Size: 235 B |
|
Before Width: | Height: | Size: 237 B |
|
Before Width: | Height: | Size: 243 B |
|
Before Width: | Height: | Size: 238 B |
|
Before Width: | Height: | Size: 241 B |
|
Before Width: | Height: | Size: 231 B |
|
Before Width: | Height: | Size: 241 B |
|
Before Width: | Height: | Size: 243 B |
|
Before Width: | Height: | Size: 243 B |
|
Before Width: | Height: | Size: 245 B |
|
Before Width: | Height: | Size: 244 B |
|
Before Width: | Height: | Size: 242 B |
|
Before Width: | Height: | Size: 244 B |
|
Before Width: | Height: | Size: 242 B |
|
Before Width: | Height: | Size: 244 B |
|
Before Width: | Height: | Size: 242 B |
|
Before Width: | Height: | Size: 241 B |
|
Before Width: | Height: | Size: 242 B |
|
Before Width: | Height: | Size: 240 B |
|
Before Width: | Height: | Size: 236 B |
|
Before Width: | Height: | Size: 244 B |
|
Before Width: | Height: | Size: 244 B |
|
Before Width: | Height: | Size: 243 B |
|
Before Width: | Height: | Size: 242 B |
|
Before Width: | Height: | Size: 246 B |
|
Before Width: | Height: | Size: 245 B |
|
Before Width: | Height: | Size: 243 B |
|
Before Width: | Height: | Size: 245 B |
|
Before Width: | Height: | Size: 244 B |
|
Before Width: | Height: | Size: 244 B |
|
Before Width: | Height: | Size: 243 B |
|
Before Width: | Height: | Size: 244 B |
|
Before Width: | Height: | Size: 244 B |
|
Before Width: | Height: | Size: 246 B |
|
Before Width: | Height: | Size: 250 B |
|
Before Width: | Height: | Size: 243 B |
|
Before Width: | Height: | Size: 244 B |
|
Before Width: | Height: | Size: 242 B |
|
Before Width: | Height: | Size: 243 B |
|
Before Width: | Height: | Size: 247 B |
|
Before Width: | Height: | Size: 244 B |
|
Before Width: | Height: | Size: 244 B |
|
Before Width: | Height: | Size: 244 B |
|
Before Width: | Height: | Size: 241 B |
|
Before Width: | Height: | Size: 238 B |
|
Before Width: | Height: | Size: 243 B |
|
Before Width: | Height: | Size: 240 B |
|
Before Width: | Height: | Size: 247 B |
|
Before Width: | Height: | Size: 245 B |
|
Before Width: | Height: | Size: 243 B |
|
Before Width: | Height: | Size: 244 B |
|
Before Width: | Height: | Size: 240 B |
|
Before Width: | Height: | Size: 245 B |
|
Before Width: | Height: | Size: 244 B |
|
Before Width: | Height: | Size: 248 B |
|
Before Width: | Height: | Size: 245 B |
|
Before Width: | Height: | Size: 248 B |
|
Before Width: | Height: | Size: 243 B |
|
Before Width: | Height: | Size: 249 B |
|
Before Width: | Height: | Size: 244 B |
|
Before Width: | Height: | Size: 248 B |
|
Before Width: | Height: | Size: 247 B |
|
Before Width: | Height: | Size: 239 B |
|
Before Width: | Height: | Size: 242 B |
|
Before Width: | Height: | Size: 247 B |
|
Before Width: | Height: | Size: 246 B |
|
Before Width: | Height: | Size: 246 B |
|
Before Width: | Height: | Size: 245 B |