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 {
|
||||||
|
|
||||||
@@ -1432,7 +1435,8 @@ public function update_barcode_item()
|
|||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
|
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 |