/** * * @param type $invid * @param type $woid * @param type $alasan * @return type */ function batalFakturService($invid, $woid, $alasan) { $result = array(); $this->db->trans_begin(); $pembatalan = array('btl_kode' => $invid, 'btl_tgl' => date('Y-m-d'), 'btl_alasan' => $alasan, 'btl_cbid' => ses_cabang, 'btl_createby' => ses_username, 'btl_createon' => date('Y-m-d H:i:s')); $this->db->INSERT('tb_pembatalan', $pembatalan); // UPDATE INVOICE $this->db->where('invid', $invid); $this->db->update('svc_invoice', array('inv_status' => 1)); // UPDATE WO $this->db->where('woid', $woid); $this->db->update('svc_wo', array('wo_inv_status' => 0)); // UPDATE SUPPLY $this->db->where('spp_woid', $woid); $this->db->update('spa_supply', array('spp_faktur' => 0, 'spp_tagihan' => 0)); if ($this->db->trans_status() === TRUE) { $this->db->trans_commit(); $result['result'] = true; $result['kode'] = $invid; $result['msg'] = sukses("Berhasil membatalkan wo"); } else { $this->db->trans_rollback(); $result['result'] = false; $result['kode'] = ''; $result['msg'] = error("Gagal membatalkan wo"); } return $result; }
/** * * @param type $sppid * @param type $alasan * @return type */ function batalSupply($sppid, $alasan, $jenis) { $result = array(); $this->db->trans_begin(); // UPDATE SUPPLY $this->db->where('sppid', $sppid); $this->db->update('spa_supply', array('spp_status' => 1, 'spp_tgl_batal' => date('Y-m-d H:i:s'), 'spp_alasan_batal' => $alasan, 'spp_batalby' => ses_username)); if ($jenis != 'so') { $sql = $this->db->query("SELECT * FROM spa_supply_det WHERE dsupp_sppid = '{$sppid}'"); foreach ($sql->result_array() as $value) { $barang = $this->db->query("SELECT * FROM spa_inventory WHERE inveid = '" . $value['dsupp_inveid'] . "' FOR UPDATE"); $row = $barang->row_array(); $hpp = ($row['inve_qty'] * $row['inve_hpp'] + $value['dsupp_subtotal_hpp']) / ($row['inve_qty'] + $value['dsupp_qty']); //INSERT KARTU STOCK $kartuStock = array('ks_tgl' => date('Y-m-d H:i:s'), 'ks_cbid' => ses_cabang, 'ks_inveid' => $value['dsupp_inveid'], 'ks_in' => $value['dsupp_qty'], 'ks_type' => 'BS', 'ks_hpp' => $hpp, 'ks_debit' => $value['dsupp_subtotal_hpp'], 'ks_saldo' => $value['dsupp_subtotal_hpp'] + $row['inve_saldo'], 'ks_total' => $row['inve_qty'] + $value['dsupp_qty']); $this->db->INSERT('spa_kartu_stock', $kartuStock); // UDPATE INVENTORY $this->db->query("UPDATE spa_inventory SET inve_qty = inve_qty + " . $value['dsupp_qty'] . ",inve_hpp = {$hpp}, inve_saldo = inve_saldo + " . $value['dsupp_subtotal_hpp'] . " WHERE inveid = '" . $value['dsupp_inveid'] . "'"); } } if ($this->db->trans_status() === TRUE) { $this->db->trans_commit(); $result['result'] = true; $result['kode'] = $sppid; $result['msg'] = sukses("Berhasil membatalkan supply"); } else { $this->db->trans_rollback(); $result['result'] = false; $result['kode'] = ''; $result['msg'] = error("Gagal membatalkan supply"); } return $result; }
function saveFakturService($data, $wo, $jasa) { $this->db->trans_begin(); $tahun = substr(date('Y'), 2, 2); $id = NUM_INVOICE . $tahun . sprintf("%08s", $this->getCounter(NUM_INVOICE . $tahun)); $data['invid'] = $id; $this->db->INSERT('svc_invoice', $data); // UPDATE WO $this->db->where('woid', $wo['woid']); $this->db->update('svc_wo', $wo); // UPDATE SUPPLY $this->db->query("UPDATE spa_supply SET spp_faktur = 1 WHERE spp_woid = '" . $wo['woid'] . "'"); // SIMPAN WO JASA if (count($jasa) > 0) { foreach ($jasa as $d) { $d['dinv_invid'] = $id; $this->db->INSERT('svc_invoice_det', $d); } } if ($this->db->trans_status() === TRUE) { $this->db->trans_commit(); $result['result'] = true; $result['kode'] = $id; $result['msg'] = sukses("Berhasil menyimpan faktur service"); } else { $this->db->trans_rollback(); $result['result'] = false; $result['kode'] = $id; $result['msg'] = error("Gagal menyimpan faktur service"); } return $result; }
public function saveReturJual($data) { $this->db->trans_begin(); $tahun = date('y'); $result = array(); $data['rtjid'] = NUM_RETUR_BELI_UNIT . $tahun . sprintf("%08s", $this->getCounter(NUM_RETUR_BELI_UNIT . $tahun)); $str = $this->db->insert('pen_retjual', $data); $this->db->query("UPDATE ms_car SET msc_ready_stock = 1 WHERE mscid = '" . $data['rtj_mscid'] . "'"); if (!$str) { $errMessage = $this->db->_error_message(); if (strpos($errMessage, "duplicate key value") == TRUE) { $this->db->trans_rollback(); $result['result'] = false; $result['kode'] = ''; $result['msg'] = error("Nomer Retur '" . $data['rtj_nomer'] . "' Sudah Terdaftar"); return $result; } } $mutasi = array('mut_mscid' => $data['rtj_mscid'], 'mut_desc' => 'Retur Jual', 'mut_cbid' => ses_cabang, 'mut_nomer' => $data['rtj_nomer'], 'mut_nomerid' => $data['rtjid'], 'mut_inout' => 'in', 'mut_tgl' => date('Y-m-d H:i:s')); $this->db->insert('pen_mutasi', $mutasi); if ($this->db->trans_status() == TRUE) { $this->db->trans_commit(); $result['result'] = true; $result['kode'] = ''; $result['msg'] = sukses("Berhasil menyimpan Retur"); } else { $this->db->trans_rollback(); $result['result'] = false; $result['kode'] = ''; $result['msg'] = error("Gagal menyimpan Retur"); } return $result; }
/** * * @param string $data * @param type $detail * @return type * @throws Exception */ function saveAdjustmentStock($data, $detail) { $result = array(); try { $this->db->trans_begin(); $tahun = substr(date('Y'), 2, 2); $id = sprintf("%08s", $this->getCounter(NUM_ADJUSTMENT_STOCK . $tahun)); $data['adjid'] = NUM_ADJUSTMENT_STOCK . $tahun . $id; $str = $this->db->INSERT('spa_adjustment', $data); if (!$str) { $errMessage = $this->db->_error_message(); if (strpos($errMessage, "duplicate key value") == TRUE) { $this->db->trans_rollback(); $result['result'] = false; $result['kode'] = ''; $result['msg'] = error("Nomer '" . $data['adj_nomer'] . "' Sudah Terdaftar"); return $result; } } foreach ($detail as $value) { $value['dadj_adjid'] = NUM_ADJUSTMENT_STOCK . $tahun . $id; $insert = $this->db->INSERT('spa_adjustment_det', $value); if (!$insert) { throw new Exception($this->db->_error_message()); } } if ($this->db->trans_status() === TRUE) { $this->db->trans_commit(); $result['result'] = true; $result['kode'] = NUM_ADJUSTMENT_STOCK . $tahun . $id; $result['msg'] = sukses("Berhasil menyimpan adjustment stock"); } else { $this->db->trans_rollback(); $result['result'] = false; $result['kode'] = ''; $result['msg'] = error("Gagal menyimpan adjustment stock"); } } catch (Exception $ex) { $result['result'] = false; $result['kode'] = ""; $result['msg'] = error(str_replace("ERROR: ", "", $ex->getMessage())); $this->db->trans_rollback(); } return $result; }