update asset delete
This commit is contained in:
@@ -202,10 +202,22 @@ class Asset extends CI_Controller {
|
|||||||
|
|
||||||
$this->db->trans_start();
|
$this->db->trans_start();
|
||||||
|
|
||||||
|
// stock log keluar per item
|
||||||
|
$this->db->insert('stock_logs',[
|
||||||
|
'item_id' => $item_id,
|
||||||
|
'warehouse_id' => '1', // default gudang
|
||||||
|
'qty' => $qty,
|
||||||
|
'tipe' => 'keluar',
|
||||||
|
'keterangan' => 'Pemindahan barang ke asset tanggal ' . $tanggal . ' - (' . $keterangan . ')'
|
||||||
|
]);
|
||||||
|
$stock_log_id = $this->db->insert_id();
|
||||||
|
$this->update_item_stok($item_id);
|
||||||
|
|
||||||
// INSERT ASSET
|
// INSERT ASSET
|
||||||
$this->db->insert('assets',[
|
$this->db->insert('assets',[
|
||||||
'item_id' => $item_id,
|
'item_id' => $item_id,
|
||||||
'barcode_id' => $barcode_id,
|
'barcode_id' => $barcode_id,
|
||||||
|
'stock_log_id' => $stock_log_id,
|
||||||
'kode_asset' => 'AST-'.time(),
|
'kode_asset' => 'AST-'.time(),
|
||||||
'nama_asset' => $nama_asset,
|
'nama_asset' => $nama_asset,
|
||||||
'harga_per_unit' => $harga,
|
'harga_per_unit' => $harga,
|
||||||
@@ -240,6 +252,8 @@ class Asset extends CI_Controller {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// END - Item Movement & item barcodes update status
|
||||||
|
|
||||||
$total_sisa = $itemBar->qty_sisa - $qty;
|
$total_sisa = $itemBar->qty_sisa - $qty;
|
||||||
$status_bar = ($total_sisa == 0) ? 'installed' : 'available';
|
$status_bar = ($total_sisa == 0) ? 'installed' : 'available';
|
||||||
|
|
||||||
@@ -284,11 +298,6 @@ class Asset extends CI_Controller {
|
|||||||
'kredit' => $nilai_perolehan
|
'kredit' => $nilai_perolehan
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// UPDATE STOK ITEM (kurangi sesuai qty)
|
|
||||||
$this->db->where('id', $item_id)
|
|
||||||
->set('stok', 'stok-'.$qty, FALSE)
|
|
||||||
->update('items');
|
|
||||||
|
|
||||||
// MUTATION DARI GUDANG
|
// MUTATION DARI GUDANG
|
||||||
$this->db->insert('asset_mutations',[
|
$this->db->insert('asset_mutations',[
|
||||||
'asset_id' => $asset_id,
|
'asset_id' => $asset_id,
|
||||||
@@ -315,7 +324,12 @@ class Asset extends CI_Controller {
|
|||||||
$lokasi_asset_id = (int)$this->input->post('lokasi_asset');
|
$lokasi_asset_id = (int)$this->input->post('lokasi_asset');
|
||||||
$keterangan = $this->input->post('keterangan');
|
$keterangan = $this->input->post('keterangan');
|
||||||
|
|
||||||
$this->db->trans_start();
|
$asset = $this->db->get_where('assets',['id'=>$id])->row();
|
||||||
|
|
||||||
|
if(!$asset){
|
||||||
|
echo json_encode(['status'=>false,'message'=>'Asset tidak ditemukan']);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'nama_asset' => $nama_asset,
|
'nama_asset' => $nama_asset,
|
||||||
@@ -323,17 +337,18 @@ class Asset extends CI_Controller {
|
|||||||
'keterangan' => $keterangan
|
'keterangan' => $keterangan
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if($asset->barcode_id && $asset->item_id){
|
||||||
|
$data = [
|
||||||
|
'lokasi_asset_id' => $lokasi_asset_id,
|
||||||
|
'keterangan' => $keterangan
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->trans_start();
|
||||||
|
|
||||||
$this->db->where('id',$id);
|
$this->db->where('id',$id);
|
||||||
$this->db->update('assets',$data);
|
$this->db->update('assets',$data);
|
||||||
|
|
||||||
// MUTATION EDIT
|
|
||||||
$this->db->insert('asset_mutations',[
|
|
||||||
'asset_id' => $id,
|
|
||||||
'tipe' => 'penambahan',
|
|
||||||
'nilai' => 0,
|
|
||||||
'keterangan' => 'Edit asset: '.$nama_asset
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->db->trans_complete();
|
$this->db->trans_complete();
|
||||||
|
|
||||||
if ($this->db->trans_status()) {
|
if ($this->db->trans_status()) {
|
||||||
@@ -351,9 +366,27 @@ class Asset extends CI_Controller {
|
|||||||
$keterangan = $this->input->post('keterangan');
|
$keterangan = $this->input->post('keterangan');
|
||||||
|
|
||||||
$asset = $this->db->get_where('assets',['id'=>$id])->row();
|
$asset = $this->db->get_where('assets',['id'=>$id])->row();
|
||||||
|
$itemBar = $this->db->get_where('item_barcodes',['id'=>$asset->barcode_id])->row();
|
||||||
|
|
||||||
|
if($alasan == 'dijual' || $alasan == 'rusak' ){
|
||||||
|
echo json_encode(['status'=>false,'message'=>'Alasan <b>' .strtoupper($alasan).'</b> tidak bisa digunakan, Karena fitur belum tersedia. Silahkan pilih alasan lain.']);
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
$this->db->trans_start();
|
$this->db->trans_start();
|
||||||
|
|
||||||
|
if ($asset->barcode_id && $asset->item_id) {
|
||||||
|
// Update item_barcodes status to 'available' if it was linked to this asset
|
||||||
|
$qty_sisa = $asset->qty + $itemBar->qty_sisa;
|
||||||
|
|
||||||
|
$this->db->where('id', $asset->barcode_id)
|
||||||
|
->update('item_barcodes', ['status' => 'available', 'qty_sisa' => $qty_sisa]);
|
||||||
|
$this->db->delete('stock_logs', ['id'=>$asset->stock_log_id]);
|
||||||
|
$this->update_item_stok($asset->item_id);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Hapus journal
|
// Hapus journal
|
||||||
$journals = $this->db->get_where('journals', ['ref_type'=>'assets', 'ref_id'=>$id])->result();
|
$journals = $this->db->get_where('journals', ['ref_type'=>'assets', 'ref_id'=>$id])->result();
|
||||||
foreach($journals as $j){
|
foreach($journals as $j){
|
||||||
@@ -455,4 +488,18 @@ class Asset extends CI_Controller {
|
|||||||
->result();
|
->result();
|
||||||
echo json_encode($data);
|
echo json_encode($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function update_item_stok($item_id)
|
||||||
|
{
|
||||||
|
$stok = $this->db->query("
|
||||||
|
SELECT COALESCE(SUM(qty * IF(tipe='masuk',1,-1)),0) as stok
|
||||||
|
FROM stock_logs
|
||||||
|
WHERE item_id = ?
|
||||||
|
", [$item_id])->row()->stok;
|
||||||
|
|
||||||
|
$this->db->where('id', $item_id)
|
||||||
|
->update('items', [
|
||||||
|
'stok' => $stok
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -66,7 +66,7 @@ class Generateinvoice extends CI_Controller {
|
|||||||
$detail = $this->db
|
$detail = $this->db
|
||||||
->where('invoice_id', $invoice_id)
|
->where('invoice_id', $invoice_id)
|
||||||
->order_by('tanggal', 'ASC')
|
->order_by('tanggal', 'ASC')
|
||||||
->order_by('id', 'DESC')
|
->order_by('id', 'ASC')
|
||||||
->get('invoice_details')
|
->get('invoice_details')
|
||||||
->result_array();
|
->result_array();
|
||||||
|
|
||||||
|
|||||||
@@ -536,7 +536,7 @@ class Invoices extends CI_Controller {
|
|||||||
$this->db->join('item_barcodes', 'item_barcodes.id = invoice_details.barcode_id', 'left');
|
$this->db->join('item_barcodes', 'item_barcodes.id = invoice_details.barcode_id', 'left');
|
||||||
$this->db->where('invoice_details.invoice_id', $id);
|
$this->db->where('invoice_details.invoice_id', $id);
|
||||||
$this->db->order_by('tanggal','ASC');
|
$this->db->order_by('tanggal','ASC');
|
||||||
$this->db->order_by('id','DESC');
|
$this->db->order_by('id','ASC');
|
||||||
|
|
||||||
$data = $this->db->get()->result();
|
$data = $this->db->get()->result();
|
||||||
|
|
||||||
|
|||||||
@@ -214,9 +214,9 @@
|
|||||||
<input type="hidden" id="delete_id">
|
<input type="hidden" id="delete_id">
|
||||||
<label>Pilih Alasan:</label>
|
<label>Pilih Alasan:</label>
|
||||||
<select id="delete_alasan" class="form-control">
|
<select id="delete_alasan" class="form-control">
|
||||||
<option value="dijual_untung">Dijual (Untung)</option>
|
<option value="dijual">Dijual</option>
|
||||||
<option value="dijual_rugi">Dijual (Rugi)</option>
|
<option value="rusak">Asset Rusak</option>
|
||||||
<option value="dihapus">Dihapus</option>
|
<option value="dihapus">Dihapus (Salah Input)</option>
|
||||||
</select>
|
</select>
|
||||||
<label class="mt-2">Keterangan:</label>
|
<label class="mt-2">Keterangan:</label>
|
||||||
<textarea id="delete_keterangan" class="form-control" rows="3" placeholder="Alasan detail penghapusan..."></textarea>
|
<textarea id="delete_keterangan" class="form-control" rows="3" placeholder="Alasan detail penghapusan..."></textarea>
|
||||||
@@ -559,6 +559,8 @@ $('#btnConfirmDelete').click(function(){
|
|||||||
$('#modalDelete').modal('hide');
|
$('#modalDelete').modal('hide');
|
||||||
table.ajax.reload(null,false);
|
table.ajax.reload(null,false);
|
||||||
Swal.fire('Berhasil','Asset berhasil dihapus','success');
|
Swal.fire('Berhasil','Asset berhasil dihapus','success');
|
||||||
|
}else{
|
||||||
|
Swal.fire('Error',res.message || 'Gagal menghapus asset','error');
|
||||||
}
|
}
|
||||||
},'json').always(()=>{
|
},'json').always(()=>{
|
||||||
btn.prop('disabled', false).html('Hapus');
|
btn.prop('disabled', false).html('Hapus');
|
||||||
|
|||||||
Reference in New Issue
Block a user