|
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 Terimabarangic 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', 'l2' => 'List Penerimaan Barang'));
parent::setURLActionTable($this->class);
parent::setContentView($this->class);
parent::setBaseContAndModel($this->class, 'KirimBarangMkt');
// $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\KirimBarangMkt();
$pagination = $dtl->where('deleted_at', null)
->where('tkb_mkt_status_sc', 1)
// ->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']);
$_datamodel['tkb_mkt_npbdno'] = $this->request->getVar('tkb_mkt_npbdno');
$_datamodel['tkb_mkt_npbddate'] = $this->request->getVar('tkb_mkt_npbddate');
// $_datamodel['tkb_mkt_doc1'] = $this->upload_file('userfile1');
$item = count($this->request->getVar('item'));
$i = $this->request->getVar('item');
$q = $this->request->getVar('qty');
$se = $this->request->getVar('seri');
$ni = $this->request->getVar('nilai');
// $qd = $this->request->getVar('received');
$tkb_mkt_item = array();
$sum = 0;
for ($j=0; $j < $item; $j++) {
$data = array(
'item' => $i[$j],
'qty' => $q[$j],
'seri' => $se[$j],
'nilai' => $ni[$j],
'qty_diterima' => 0,
);
array_push($tkb_mkt_item, $data);
}
$_datamodel['tkb_mkt_item'] = json_encode($tkb_mkt_item);
if(isset($_POST['terima'])){
$_datamodel['tkb_mkt_status_ic'] = 1;
$_datamodel['tkb_mkt_status_mkt'] = 2;
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
$updated_stok = (int)$_barang->mb_stok_bahanbaku + (int)$q[$j];
$datamodel = array(
'mb_stok_bahanbaku' => $updated_stok,
);
$barang->update($_barang->mb_id, $datamodel);
}
}
}
if(isset($_POST['tolak'])){
$_datamodel['tkb_mkt_status_ic'] = 2;
$_datamodel['tkb_mkt_status_mkt'] = 3;
sendEmail('noreplyptmata@gmail.com', 'Pengiriman Bahan baku Ditolak IC', 'IC menolak pengiriman');
}
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;
}
}