|
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.bak300125/Controllers/Sc/ |
Upload File : |
<?php
namespace App\Controllers\Sc;
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 Kirimbarangsc 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 Outstanding Barang', array('l1' => 'Kirim Barang', 'l2' => 'List Outstanding Barang'));
parent::setURLActionTable($this->class);
parent::setContentView($this->class);
parent::setBaseContAndModel($this->class, 'KirimBarangMkt');
$this->validation_input = $this->validation->setRules([
"tkb_mkt_pibno" => [
'label' => 'No PIB',
'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_mkt !=', 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') {
$this->mylib = new Mylibpublic();
$this->view_data['state'] = 'add';
$this->view_data['button'] = 'Simpan';
$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']);
$_mdl = $this->myLib->getNewModel($this->models['base_model']);
$_datamodel = array();
$_datamodel['tkb_mkt_status_sc'] = 0;
if(isset($_POST['kirim'])){
$_datamodel['tkb_mkt_status_sc'] = 1;
sendEmail('noreplyptmata@gmail.com', 'Pengiriman Bahan baku SC', 'SC melakukan pengiriman bahan baku baru');
}
$_datamodel['tkb_mkt_pibno'] = $this->request->getVar('tkb_mkt_pibno');
$_datamodel['tkb_mkt_pibdate'] = $this->request->getVar('tkb_mkt_pibdate');
$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');
$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);
try {
if (!$_mdl->save($_datamodel)) {
throw new \CodeIgniter\Database\Exceptions\DatabaseException();
} else {
$this->setMessage(false, true, $this->msgLib->scs_add());
}
} catch (Exception $e) {
$this->setMessage(true, false, $this->msgLib->err_add());
}
}
}
$this->render->viewAdmin($this->content_views['form_add_view'], $this);
} 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_status_sc'] = 0;
if(isset($_POST['kirim'])){
$_datamodel['tkb_mkt_status_sc'] = 1;
sendEmail('noreplyptmata@gmail.com', 'Pengiriman Bahan baku SC', 'SC melakukan pengiriman bahan baku baru');
}
$_datamodel['tkb_mkt_pibno'] = $this->request->getVar('tkb_mkt_pibno');
$_datamodel['tkb_mkt_pibdate'] = $this->request->getVar('tkb_mkt_pibdate');
//Upload File
$file = $this->request->getFile('userfile1');
if ($file->isValid()){
$newName = $file->getRandomName();
$file->move(FCPATH.'assets/uploads/sc_document', $newName);
$_datamodel['tkb_mkt_doc1'] = $newName;
}
$file2 = $this->request->getFile('userfile2');
if ($file2->isValid()){
$newName2 = $file2->getRandomName();
$file2->move(FCPATH.'assets/uploads/sc_document', $newName2);
$_datamodel['tkb_mkt_doc2'] = $newName2;
}
$file3 = $this->request->getFile('userfile3');
if ($file3->isValid()){
$newName3 = $file3->getRandomName();
$file3->move(FCPATH.'assets/uploads/sc_document', $newName3);
$_datamodel['tkb_mkt_doc3'] = $newName3;
}
$file4 = $this->request->getFile('userfile4');
if ($file4->isValid()){
$newName4 = $file4->getRandomName();
$file4->move(FCPATH.'assets/uploads/sc_document', $newName4);
$_datamodel['tkb_mkt_doc4'] = $newName4;
}
$file5 = $this->request->getFile('userfile5');
if ($file5->isValid()){
$newName5 = $file5->getRandomName();
$file5->move(FCPATH.'assets/uploads/sc_document', $newName5);
$_datamodel['tkb_mkt_doc5'] = $newName5;
}
$file6 = $this->request->getFile('userfile6');
if ($file6->isValid()){
$newName6 = $file6->getRandomName();
$file6->move(FCPATH.'assets/uploads/sc_document', $newName6);
$_datamodel['tkb_mkt_doc6'] = $newName6;
}
$file7 = $this->request->getFile('userfile7');
if ($file7->isValid()){
$newName7 = $file7->getRandomName();
$file7->move(FCPATH.'assets/uploads/sc_document', $newName7);
$_datamodel['tkb_mkt_doc7'] = $newName7;
}
$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');
$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);
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 checkpassword()
{
$confirm_password = $_POST['cp'];
$brg = new \App\Models\MasterPasskeu();
$_brg = $brg->first();
$password = $_brg->mpkeu_pass;
if($confirm_password == $password){
echo json_encode(array(
"statusCode"=>200
));
}else{
echo json_encode(array(
"statusCode"=>400
));
}
}
}