Update Controller Items karena ada bug

This commit is contained in:
Prod-Panel
2026-07-12 16:55:48 +00:00
parent 81e35f56a0
commit c7ec369234
222 changed files with 140 additions and 107 deletions
+1 -1
View File
@@ -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
+49 -16
View File
@@ -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,15 +1427,16 @@ 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') ->from('items i')
->join('kode_barang kb', 'kb.id=i.kode_id') ->join('kode_barang kb', 'kb.id=i.kode_id')
@@ -1445,21 +1449,27 @@ public function update_barcode_item()
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) { if ($target <= 0) {
continue; continue;
} }
// =========================================== // ===========================================
// Barcode yang sudah ada // Jumlah barcode yang sudah ada
// =========================================== // ===========================================
$barcode_exist = $this->db $barcode_exist = $this->db
@@ -1470,15 +1480,33 @@ public function update_barcode_item()
continue; 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; $need = $target - $barcode_exist;
for ($i = 1; $i <= $need; $i++) { for ($i = 1; $i <= $need; $i++) {
$barcode = strtoupper($item->kode_detail) . '-' . strtoupper(bin2hex(random_bytes(2))); // Barcode terakhir akan berisi sisa stok
$qty = min($qty_per_barcode, $qty_remaining);
$qty = ($item->tracking_type == 'UNIT') $barcode = strtoupper($item->kode_detail) . '-' . strtoupper(bin2hex(random_bytes(2)));
? 1
: 1000;
// ============================= // =============================
// Insert Barcode // Insert Barcode
@@ -1512,10 +1540,16 @@ public function update_barcode_item()
'reference_id' => null, 'reference_id' => null,
'notes' => 'Generate barcode otomatis' 'notes' => 'Generate barcode otomatis'
]); ]);
$qty_remaining -= $qty;
if ($qty_remaining <= 0) {
break;
}
} }
} }
if ($this->db->trans_status() == false) { if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback(); $this->db->trans_rollback();
@@ -1523,7 +1557,6 @@ public function update_barcode_item()
'status' => false, 'status' => false,
'message' => 'Gagal generate barcode.' 'message' => 'Gagal generate barcode.'
]); ]);
return; return;
} }
@@ -1533,5 +1566,5 @@ public function update_barcode_item()
'status' => true, 'status' => true,
'message' => 'Barcode berhasil diperbarui.' 'message' => 'Barcode berhasil diperbarui.'
]); ]);
} }
} }
Binary file not shown.

Before

Width:  |  Height:  |  Size: 243 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 243 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 243 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 237 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 241 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 241 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 243 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 242 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 248 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 239 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 237 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 242 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 242 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 239 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 242 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 247 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 245 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 243 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 243 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 240 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 244 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 247 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 242 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 242 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 240 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 238 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 231 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 241 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 236 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 243 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 235 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 237 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 243 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 238 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 241 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 231 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 241 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 243 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 243 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 245 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 244 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 242 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 244 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 242 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 244 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 242 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 241 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 242 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 240 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 236 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 244 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 244 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 243 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 242 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 246 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 245 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 243 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 245 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 244 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 244 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 243 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 244 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 244 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 246 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 250 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 243 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 244 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 242 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 243 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 247 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 244 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 244 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 244 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 241 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 238 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 243 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 240 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 247 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 245 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 243 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 244 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 240 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 245 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 244 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 248 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 245 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 248 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 243 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 249 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 244 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 248 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 247 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 239 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 242 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 247 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 246 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 246 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 245 B

Some files were not shown because too many files have changed in this diff Show More