Update Controller Items karena ada bug
@@ -5,7 +5,7 @@ application/config/database.php
|
||||
application/controllers/Dbcompare.php
|
||||
.htaccess
|
||||
|
||||
uploads/temp_qr/*.png
|
||||
uploads/temp_qr/*
|
||||
|
||||
application/cache/*
|
||||
!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>';
|
||||
$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>';
|
||||
$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') {
|
||||
|
||||
@@ -564,8 +565,10 @@ class Items extends CI_Controller {
|
||||
if ($row->status == 'draft') {
|
||||
if ($total_sn == $done_sn) {
|
||||
$btnSN = $btnInsertSn . $btnPrintBarcode;
|
||||
$btnPostview = $btnPost;
|
||||
} else {
|
||||
$btnSN = $btnInsertSn ;
|
||||
$btnPostview = '';
|
||||
}
|
||||
} else {
|
||||
$btnSN = $btnPrintBarcode;
|
||||
@@ -574,11 +577,11 @@ class Items extends CI_Controller {
|
||||
} else {
|
||||
|
||||
$btnSN = $btnPrintBarcode;
|
||||
$btnPostview = $btnPost;
|
||||
}
|
||||
|
||||
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 . $btnPost . $btnDelete . $btnSN;
|
||||
$action = $btnDetail . $btnPostview . $btnDelete . $btnSN;
|
||||
|
||||
} else {
|
||||
|
||||
@@ -1424,114 +1427,144 @@ class Items extends CI_Controller {
|
||||
echo json_encode($data);
|
||||
}
|
||||
|
||||
public function update_barcode_item()
|
||||
{
|
||||
$items = $this->db
|
||||
->select("
|
||||
i.id,
|
||||
i.nama_barang,
|
||||
i.stok,
|
||||
i.kode_detail,
|
||||
kb.tracking_type
|
||||
")
|
||||
->from('items i')
|
||||
->join('kode_barang kb', 'kb.id=i.kode_id')
|
||||
->where('i.status', 'active')
|
||||
->get()
|
||||
->result();
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
foreach ($items as $item) {
|
||||
|
||||
// ===========================================
|
||||
// Hitung jumlah barcode yang seharusnya
|
||||
// ===========================================
|
||||
|
||||
if ($item->tracking_type == 'UNIT') {
|
||||
$target = (int)$item->stok;
|
||||
} else {
|
||||
$target = (int)floor($item->stok / 1000);
|
||||
public function update_barcode_item()
|
||||
{
|
||||
$items = $this->db
|
||||
->select("
|
||||
i.id,
|
||||
i.nama_barang,
|
||||
i.stok,
|
||||
i.kode_detail,
|
||||
kb.tracking_type,
|
||||
kb.kode_barang
|
||||
")
|
||||
->from('items i')
|
||||
->join('kode_barang kb', 'kb.id=i.kode_id')
|
||||
->where('i.status', 'active')
|
||||
->get()
|
||||
->result();
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
foreach ($items as $item) {
|
||||
|
||||
// ===========================================
|
||||
// Qty per barcode
|
||||
// ===========================================
|
||||
|
||||
if ($item->tracking_type == 'UNIT') {
|
||||
$qty_per_barcode = 1;
|
||||
} else {
|
||||
$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) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// ===========================================
|
||||
// Barcode yang sudah ada
|
||||
// ===========================================
|
||||
|
||||
$barcode_exist = $this->db
|
||||
->where('item_id', $item->id)
|
||||
->count_all_results('item_barcodes');
|
||||
|
||||
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'
|
||||
|
||||
if ($this->db->trans_status() === FALSE) {
|
||||
|
||||
$this->db->trans_rollback();
|
||||
|
||||
echo json_encode([
|
||||
'status' => false,
|
||||
'message' => 'Gagal generate barcode.'
|
||||
]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->db->trans_status() == false) {
|
||||
|
||||
$this->db->trans_rollback();
|
||||
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
echo json_encode([
|
||||
'status' => false,
|
||||
'message' => 'Gagal generate barcode.'
|
||||
'status' => true,
|
||||
'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 |