|
Server : Apache System : Linux server.mata-lashes.com 3.10.0-1160.90.1.el7.x86_64 #1 SMP Thu May 4 15:21:22 UTC 2023 x86_64 User : matalashes ( 1004) PHP Version : 8.1.29 Disable Function : NONE Directory : /home/matalashes/.trash/app.bak17jan25/Controllers/Ic/ |
Upload File : |
<?php
namespace App\Controllers\Ic;
use \App\Controllers\Ps\PS_Controller;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
use App\Libraries\Ps\Mylibpublic;
use App\Models\UploadModel;
class Terimabarangproic extends PS_Controller
{
private $id_column_name = 'mb_id';
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger); // TODO: Change the autogenerated stub
parent::setPageTitleBreadcrumb(true, 'List Penerimaan Barang', array('l1' => 'Terima Barang FGI', 'l2' => 'List Penerimaan Barang'));
parent::setURLActionTable($this->class);
parent::setContentView($this->class);
parent::setBaseContAndModel($this->class, 'KirimBarangPro');
// $this->validation_input = $this->validation->setRules([
// "tkb_mkt_npbdno" => [
// 'label' => 'No NPBD',
// 'rules' => 'required',
// ]
// ]);
}
public function index()
{
parent::filterStoreLoad();
// parent::indexLoad();
$this->session->set('trash', false);
$this->session->set('keyword', '');
$start = date('Y-m-01');
$end = date('Y-m-t');
if ($_POST) {
$start = $this->request->getVar('start');
$end = $this->request->getVar('end');
}
$dtl = new \App\Models\KirimBarangPro();
$pagination = $dtl->where('deleted_at', null)
->where('tkb_pro_status!=', 0)
// ->where('date(created_at) >=', $start)
// ->where('date(created_at) <=', $end)
->findAll();
$this->view_data['_data'] = $pagination;
$this->view_data['start'] = $start;
$this->view_data['end'] = $end;
$this->render->viewAdmin($this->content_views['table_view'], $this);
}
public function action($state = '', $id = '')
{
$id = $this->myLib->reveal_id($id);
if ($id == 'override404') {
return redirect()->route('override404');
}
$barang = new \App\Models\MasterBarang();
$this->view_data['_barang'] = $barang->where('deleted_at', null)->findAll();
if ($state == 'add') {
} else if ($state == 'edit') {
// parent::stateEdit($id);
$mdl = $this->myLib->getNewModel($this->models['base_model']);
$_data = $mdl->find($id);
$this->view_data['state'] = 'edit';
$this->view_data['button'] = 'Simpan';
$this->view_data['id'] = $id;
$this->view_data['_data'] = $_data;
$this->view_data['upload_data'] = $this->upload_data;
if ($_POST) {
// if (!$this->validation_input->withRequest($this->request)->run()) {
// $this->view_data['error'] = true;
// $this->view_data['message'] = 'Ada kesalahan dalam pengisian form!';
// $this->view_data['error_list'] = $this->validation_input->getErrors();
// } else {
unset($_POST['id']);
$item = count($this->request->getVar('item'));
$i = $this->request->getVar('item');
$q = $this->request->getVar('qty');
$p = $this->request->getVar('pob');
$f = $this->request->getVar('fpro');
$b = $this->request->getVar('bulumata');
// $qd = $this->request->getVar('received');
$tkb_pro_item = array();
$sum = 0;
for ($j=0; $j < $item; $j++) {
$data = array(
'item' => $i[$j],
'qty' => $q[$j],
'pob' => $p[$j],
'fpro' => $f[$j],
'bulumata' => $b[$j],
);
array_push($tkb_pro_item, $data);
}
$_datamodel['tkb_pro_item'] = json_encode($tkb_pro_item);
if(isset($_POST['terima'])){
$_datamodel['tkb_pro_status'] = 1;
$_datamodel['tkb_pro_status_ic'] = 1;
for ($j=0; $j < $item; $j++) {
$barang = new \App\Models\MasterBarang();
$_barang = $barang->where('mb_id', $i[$j])->where('deleted_at', null)->first();
if(isset($_barang)){
//update data
$decrease_stok_wip = (int)$_barang->mb_stok_wip - (int)$q[$j];
$increase_stok_fig = (int)$_barang->mb_stok_fig + (int)$q[$j];
$datamodel = array(
'mb_stok_wip' => $decrease_stok_wip,
'mb_stok_fig' => $increase_stok_fig,
);
$barang->update($_barang->mb_id, $datamodel);
}
}
}
if(isset($_POST['tolak'])){
$_datamodel['tkb_pro_status'] = 2;
$_datamodel['tkb_pro_status_ic'] = 2;
}
try {
if (!$mdl->update($id, $_datamodel)) {
throw new \CodeIgniter\Database\Exceptions\DatabaseException();
} else {
$this->setMessage(false, true, $this->msgLib->scs_edit());
}
} catch (Exception $e) {
$this->setMessage(true, false, $this->msglib->err_edit());
}
// }
}
$this->render->viewAdmin($this->content_views['form_edit_view'], $this);
} else if ($state == 'delete') {
parent::stateDelete($id);
} else if ($state == 'restore') {
parent::stateRestore($this->id_column_name, $id);
} else if ($state == 'deletepermanent') {
parent::stateDeletePermanent($this->id_column_name, $id);
} else if ($state == 'view') {
parent::stateView($id);
} else {
return redirect()->route('override404');
}
}
public function trash()
{
parent::filterStoreLoad();
parent::trashView();
}
public function upload_file($name)
{
$file = $this->request->getFile($name);
$newName = $file->getRandomName();
$file->move(WRITEPATH.'uploads', $newName);
$inputFileName = WRITEPATH.'uploads/' . $newName;
log_message('alert',$inputFileName);
return $inputFileName;
}
}