SHARE
TWEET

Untitled

a guest Sep 22nd, 2019 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php namespace App\Http\Controllers;
  2.  
  3. use Session;
  4. use Request;
  5. use DB;
  6. use CRUDBooster;
  7.  
  8. use App\Models\RequestModel;
  9. use App\Models\RequestCustomerModel;
  10. use App\Models\CustomerModel;
  11.  
  12. class AdminCpiTrxRequestController extends \crocodicstudio\crudbooster\controllers\CBController
  13. {
  14.  
  15.     public function cbInit()
  16.     {
  17.  
  18.             # START CONFIGURATION DO NOT REMOVE THIS LINE
  19.             $this->title_field = "id";
  20.             $this->limit = "10";
  21.             $this->orderby = "id,desc";
  22.             $this->global_privilege = false;
  23.             $this->button_table_action = true;
  24.             $this->button_bulk_action = false;
  25.             $this->button_action_style = "button_icon";
  26.             $this->button_add = true;
  27.             $this->button_edit = false;
  28.             $this->button_delete = false;
  29.             $this->button_detail = false;
  30.             $this->button_show = true;
  31.             $this->button_filter = true;
  32.             $this->button_import = false;
  33.             $this->button_export = false;
  34.             $this->table = "cpi_trx_request";
  35.             # END CONFIGURATION DO NOT REMOVE THIS LINE
  36.  
  37.             # START COLUMNS DO NOT REMOVE THIS LINE
  38.             // $this->col = [];
  39.             $this->col[] = ["label"=>"Tanggal","name"=>"request_date"];
  40.             $this->col[] = ["label"=>"Tipe","name"=>"type", 'callback_php'=>'($row->type==REQUEST_TYPE_SO)?"<span class=\"label label-primary\">SO</span>":"<span class=\"label label-info\">QUO</span>"'];
  41.             $this->col[] = ["label"=>"No SO/QUO", "name"=>"request_number"];
  42.             $this->col[] = ["label"=>"Customer", "name"=>"id", "callback_php"=>'$this->customers($row->id)'];
  43.             $this->col[] = ["label"=>"Jumlah Permohonan","name"=>"amount", 'callback_php'=>' "Rp.".number_format($row->amount)'];
  44.             $this->col[] = ["label"=>"Status","name"=>"status", 'callback_php'=>'($row->status=="1")?"<span class=\"label label-success\">Permohonan Baru</span>":"<span class=\"label label-danger\">Disetujui</span>"'];
  45.             // $this->col[] = ["label"=>"Jatuh Tempo","name"=>"due_date"];
  46.             // $this->col[] = ["label"=>"Sales Kemarin","name"=>"sales_before"];
  47.             // $this->col[] = ["label"=>"Transfer Kemarin","name"=>"transfer_before"];
  48.             # END COLUMNS DO NOT REMOVE THIS LINE
  49.  
  50.             # START FORM DO NOT REMOVE THIS LINE
  51.             $this->form = [];
  52.             $this->form[] = ['label'=>'Tanggal Permohonan','name'=>'request_date','type'=>'text','validation'=>'required','width'=>'col-sm-10','readonly'=>'1','value'=>date("Y-m-d H:i:s")];
  53.             $this->form[] = ['label'=>'Tipe','name'=>'type','type'=>'radio','validation'=>'required|integer|min:0','width'=>'col-sm-10','dataenum'=>'1|SO;2|QUO'];
  54.             $this->form[] = ['label'=>'No SO/QUO','name'=>'request_number','type'=>'text','validation'=>'required|min:1','width'=>'col-sm-10'];
  55.             $this->form[] = ['label'=>'Technical Support','name'=>'request_by','type'=>'select2','validation'=>'required|integer|min:0','width'=>'col-sm-10','datatable'=>'cpi_mst_employee,name'];
  56.             $this->form[] = ['label'=>'Owner','name'=>'owner_id','type'=>'select2','validation'=>'required','width'=>'col-sm-10','datatable'=>'cpi_mst_owner,owner_name'];
  57.             $this->form[] = ['label'=>'Customer','name'=>'customer_ids[]','type'=>'select2','width'=>'col-sm-10','datatable'=>'cpi_mst_customer,owner_id'];
  58.             $this->form[] = ['label'=>'Jumlah Permohonan','name'=>'amount','type'=>'number','validation'=>'required|integer','width'=>'col-sm-10'];
  59.             $this->form[] = ['label'=>'Jatuh Tempo','name'=>'due_date','type'=>'number','validation'=>'required|integer','width'=>'col-sm-10'];
  60.             $this->form[] = ['label'=>'Sales Kemarin','name'=>'sales_before','type'=>'number','validation'=>'required|integer','width'=>'col-sm-10'];
  61.             $this->form[] = ['label'=>'Transfer Kemarin','name'=>'transfer_before','type'=>'number','validation'=>'required|integer','width'=>'col-sm-10'];
  62.             $this->form[] = ['label'=>'Credit Limit Total','name'=>'credit_limit_total','type'=>'number','validation'=>'required|integer','width'=>'col-sm-10'];
  63.             $this->form[] = ['label'=>'Credit Limit Digunakan','name'=>'credit_limit_used','type'=>'number','validation'=>'required|integer','width'=>'col-sm-10'];
  64.             $this->form[] = ['label'=>'Credit Term Waktu','name'=>'credit_term_waktu','type'=>'number','validation'=>'required|integer|min:0','width'=>'col-sm-10'];
  65.             $this->form[] = ['label'=>'Credit Term Berjalan','name'=>'credit_term_berjalan','type'=>'number','validation'=>'required|integer|min:0','width'=>'col-sm-10'];
  66.             # END FORM DO NOT REMOVE THIS LINE
  67.  
  68.             # OLD START FORM
  69.             //$this->form = [];
  70.             //$this->form[] = ['label'=>'Tanggal Permohonan','name'=>'request_date','type'=>'text','validation'=>'required','width'=>'col-sm-10','readonly'=>'1','value'=>date("Y-m-d H:i:s")];
  71.             //$this->form[] = ['label'=>'Tipe','name'=>'type','type'=>'radio','validation'=>'required|integer|min:0','width'=>'col-sm-10','dataenum'=>'1|SO;2|QUO'];
  72.             //$this->form[] = ['label'=>'No SO/QUO','name'=>'request_number','type'=>'text','validation'=>'required|min:1','width'=>'col-sm-10'];
  73.             //$this->form[] = ['label'=>'Technical Support','name'=>'request_by','type'=>'select2','validation'=>'required|integer|min:0','width'=>'col-sm-10','datatable'=>'cms_users,name'];
  74.             //$this->form[] = ['label'=>'Owner','name'=>'owner_id','type'=>'select2','validation'=>'required','width'=>'col-sm-10','datatable'=>'cpi_mst_owner,owner_name'];
  75.             //$this->form[] = ['label'=>'Customer','name'=>'customer_ids[]','type'=>'select2','width'=>'col-sm-10','datatable'=>'cpi_mst_customer,name'];
  76.             //$this->form[] = ['label'=>'Jumlah Permohonan','name'=>'amount','type'=>'number','validation'=>'required|integer','width'=>'col-sm-10'];
  77.             //$this->form[] = ['label'=>'Jatuh Tempo','name'=>'due_date','type'=>'number','validation'=>'required|integer','width'=>'col-sm-10'];
  78.             //$this->form[] = ['label'=>'Sales Kemarin','name'=>'sales_before','type'=>'number','validation'=>'required|integer','width'=>'col-sm-10'];
  79.             //$this->form[] = ['label'=>'Transfer Kemarin','name'=>'transfer_before','type'=>'number','validation'=>'required|integer','width'=>'col-sm-10'];
  80.             //$this->form[] = ['label'=>'Credit Limit Total','name'=>'credit_limit_total','type'=>'number','validation'=>'required|integer','width'=>'col-sm-10'];
  81.             //$this->form[] = ['label'=>'Credit Limit Digunakan','name'=>'credit_limit_used','type'=>'number','validation'=>'required|integer','width'=>'col-sm-10'];
  82.             //$this->form[] = ['label'=>'Credit Term Waktu','name'=>'credit_term_waktu','type'=>'number','validation'=>'required|integer|min:0','width'=>'col-sm-10'];
  83.             //$this->form[] = ['label'=>'Credit Term Berjalan','name'=>'credit_term_berjalan','type'=>'number','validation'=>'required|integer|min:0','width'=>'col-sm-10'];
  84.             # OLD END FORM
  85.  
  86.             /*
  87.         | ----------------------------------------------------------------------
  88.         | Sub Module
  89.         | ----------------------------------------------------------------------
  90.         | @label          = Label of action
  91.         | @path           = Path of sub module
  92.         | @foreign_key    = foreign key of sub table/module
  93.         | @button_color   = Bootstrap Class (primary,success,warning,danger)
  94.         | @button_icon    = Font Awesome Class
  95.         | @parent_columns = Sparate with comma, e.g : name,created_at
  96.         |
  97.         */
  98.         $this->sub_module = array();
  99.  
  100.         /*
  101.         | ----------------------------------------------------------------------
  102.         | Add More Action Button / Menu
  103.         | ----------------------------------------------------------------------
  104.         | @label       = Label of action
  105.         | @url         = Target URL, you can use field alias. e.g : [id], [name], [title], etc
  106.         | @icon        = Font awesome class icon. e.g : fa fa-bars
  107.         | @color       = Default is primary. (primary, warning, succecss, info)
  108.         | @showIf      = If condition when action show. Use field alias. e.g : [id] == 1
  109.         |
  110.         */
  111.         $this->addaction[] = ['url'=>CRUDBooster::mainpath('detail/[id]'),'icon'=>'fa fa-eye','color'=>'primary'];
  112.         $this->addaction[] = ['url'=>CRUDBooster::mainpath('edit/[id]'),'icon'=>'fa fa-pencil','color'=>'success','showIf'=>"[status] == '1'"];
  113.         $this->addaction[] = ['url'=>CRUDBooster::mainpath('delete/[id]'),'icon'=>'fa fa-trash','color'=>'warning','showIf'=>"[status] == '1'", 'confirmation' => true];
  114.  
  115.  
  116.  
  117.         /*
  118.         | ----------------------------------------------------------------------
  119.         | Add More Button Selected
  120.         | ----------------------------------------------------------------------
  121.         | @label       = Label of action
  122.         | @icon        = Icon from fontawesome
  123.         | @name        = Name of button
  124.         | Then about the action, you should code at actionButtonSelected method
  125.         |
  126.         */
  127.         $this->button_selected = array();
  128.  
  129.  
  130.         /*
  131.         | ----------------------------------------------------------------------
  132.         | Add alert message to this module at overheader
  133.         | ----------------------------------------------------------------------
  134.         | @message = Text of message
  135.         | @type    = warning,success,danger,info
  136.         |
  137.         */
  138.         $this->alert = array();
  139.  
  140.  
  141.         /*
  142.         | ----------------------------------------------------------------------
  143.         | Add more button to header button
  144.         | ----------------------------------------------------------------------
  145.         | @label = Name of button
  146.         | @url   = URL Target
  147.         | @icon  = Icon from Awesome.
  148.         |
  149.         */
  150.         $this->index_button = array();
  151.  
  152.  
  153.         /*
  154.         | ----------------------------------------------------------------------
  155.         | Customize Table Row Color
  156.         | ----------------------------------------------------------------------
  157.         | @condition = If condition. You may use field alias. E.g : [id] == 1
  158.         | @color = Default is none. You can use bootstrap success,info,warning,danger,primary.
  159.         |
  160.         */
  161.         $this->table_row_color = array();
  162.  
  163.  
  164.         /*
  165.         | ----------------------------------------------------------------------
  166.         | You may use this bellow array to add statistic at dashboard
  167.         | ----------------------------------------------------------------------
  168.         | @label, @count, @icon, @color
  169.         |
  170.         */
  171.         $this->index_statistic = array();
  172.  
  173.  
  174.         /*
  175.         | ----------------------------------------------------------------------
  176.         | Add javascript at body
  177.         | ----------------------------------------------------------------------
  178.         | javascript code in the variable
  179.         | $this->script_js = "function() { ... }";
  180.         |
  181.         */
  182.         $this->script_js = "";
  183.  
  184.  
  185.         /*
  186.         | ----------------------------------------------------------------------
  187.         | Include HTML Code before index table
  188.         | ----------------------------------------------------------------------
  189.         | html code to display it before index table
  190.         | $this->pre_index_html = "<p>test</p>";
  191.         |
  192.         */
  193.         $this->pre_index_html = null;
  194.  
  195.  
  196.         /*
  197.         | ----------------------------------------------------------------------
  198.         | Include HTML Code after index table
  199.         | ----------------------------------------------------------------------
  200.         | html code to display it after index table
  201.         | $this->post_index_html = "<p>test</p>";
  202.         |
  203.         */
  204.         $this->post_index_html = null;
  205.  
  206.  
  207.         /*
  208.         | ----------------------------------------------------------------------
  209.         | Include Javascript File
  210.         | ----------------------------------------------------------------------
  211.         | URL of your javascript each array
  212.         | $this->load_js[] = asset("myfile.js");
  213.         |
  214.         */
  215.         $this->load_js =
  216.         [
  217.             asset("js/request-form.js"),
  218.             asset("js/request-index.js")
  219.         ];
  220.  
  221.  
  222.         /*
  223.         | ----------------------------------------------------------------------
  224.         | Add css style at body
  225.         | ----------------------------------------------------------------------
  226.         | css code in the variable
  227.         | $this->style_css = ".style{....}";
  228.         |
  229.         */
  230.         $this->style_css = "
  231.             input[type=number]::-webkit-inner-spin-button,
  232.             input[type=number]::-webkit-outer-spin-button {
  233.             -webkit-appearance: none;
  234.             margin: 0;
  235.             }
  236.         ";
  237.  
  238.  
  239.         /*
  240.         | ----------------------------------------------------------------------
  241.         | Include css File
  242.         | ----------------------------------------------------------------------
  243.         | URL of your css each array
  244.         | $this->load_css[] = asset("myfile.css");
  245.         |
  246.         */
  247.         $this->load_css = array();
  248.  
  249.  
  250.     }
  251.  
  252.  
  253.     /*
  254.     | ----------------------------------------------------------------------
  255.     | Hook for button selected
  256.     | ----------------------------------------------------------------------
  257.     | @id_selected = the id selected
  258.     | @button_name = the name of button
  259.     |
  260.     */
  261.     public function actionButtonSelected($id_selected, $button_name)
  262.     {
  263.         //Your code here
  264.  
  265.     }
  266.  
  267.  
  268.     /*
  269.     | ----------------------------------------------------------------------
  270.     | Hook for manipulate query of index result
  271.     | ----------------------------------------------------------------------
  272.     | @query = current sql query
  273.     |
  274.     */
  275.     public function hook_query_index(&$query)
  276.     {
  277.         //Your code here
  278.  
  279.     }
  280.  
  281.     /*
  282.     | ----------------------------------------------------------------------
  283.     | Hook for manipulate row of index table html
  284.     | ----------------------------------------------------------------------
  285.     |
  286.     */
  287.     public function hook_row_index($column_index, &$column_value)
  288.     {
  289.         //Your code here
  290.     }
  291.  
  292.     /*
  293.     | ----------------------------------------------------------------------
  294.     | Hook for manipulate data input before add data is execute
  295.     | ----------------------------------------------------------------------
  296.     | @arr
  297.     |
  298.     */
  299.     public function hook_before_add(&$postdata)
  300.     {
  301.         //
  302.     }
  303.  
  304.     /*
  305.     | ----------------------------------------------------------------------
  306.     | Hook for execute command after add public static function called
  307.     | ----------------------------------------------------------------------
  308.     | @id = last insert id
  309.     |
  310.     */
  311.     public function hook_after_add($id)
  312.     {
  313.         //Your code here
  314.     }
  315.  
  316.     /*
  317.     | ----------------------------------------------------------------------
  318.     | Hook for manipulate data input before update data is execute
  319.     | ----------------------------------------------------------------------
  320.     | @postdata = input post data
  321.     | @id       = current id
  322.     |
  323.     */
  324.     public function hook_before_edit(&$postdata, $id)
  325.     {
  326.         //Your code here
  327.  
  328.     }
  329.  
  330.     /*
  331.     | ----------------------------------------------------------------------
  332.     | Hook for execute command after edit public static function called
  333.     | ----------------------------------------------------------------------
  334.     | @id       = current id
  335.     |
  336.     */
  337.     public function hook_after_edit($id)
  338.     {
  339.         //Your code here
  340.  
  341.     }
  342.  
  343.     /*
  344.     | ----------------------------------------------------------------------
  345.     | Hook for execute command before delete public static function called
  346.     | ----------------------------------------------------------------------
  347.     | @id       = current id
  348.     |
  349.     */
  350.     public function hook_before_delete($id)
  351.     {
  352.         //Your code here
  353.  
  354.     }
  355.  
  356.     /*
  357.     | ----------------------------------------------------------------------
  358.     | Hook for execute command after delete public static function called
  359.     | ----------------------------------------------------------------------
  360.     | @id       = current id
  361.     |
  362.     */
  363.     public function hook_after_delete($id)
  364.     {
  365.         //Your code here
  366.  
  367.     }
  368.  
  369.     public function customers($id)
  370.     {
  371.         $customerString = "";
  372.  
  373.         $customers = RequestCustomerModel::where('request_id', '=', $id)
  374.             ->where('deleted', '!=', 1)
  375.             ->get();
  376.  
  377.         if($customers->count() > 0){
  378.             $i = 0;
  379.  
  380.             foreach($customers as $customer){
  381.                 $customerName = CustomerModel::find($customer->customer_id)->name;
  382.                 if($i++ < $customers->count()-1 && $customerName != null){
  383.                     $customerString = $customerString.$customerName.", ";
  384.                 } else if(true && $customerName != null){
  385.                     $customerString = $customerString.$customerName;
  386.                 }
  387.             }
  388.  
  389.             return $customerString;
  390.         } else{
  391.             return "-";
  392.         }
  393.     }
  394.  
  395.     public function getIndex() {
  396.         //First, Add an auth
  397.         //  if(!CRUDBooster::isView()) CRUDBooster::redirect(CRUDBooster::adminPath(),trans('crudbooster.denied_access'));
  398.  
  399.         //Create your own query
  400.         $request = RequestModel::orderby('status','asc');
  401.  
  402.         $data = [];
  403.         $data['page_title'] = 'Permohonan';
  404.         $customerCombinedString = "";
  405.  
  406.         //--- Search's scripts start from here ---
  407.  
  408.         if(Request::get('q') != null){
  409.             $query = Request::get('q');
  410.  
  411.             //mencari kesamaan pada kolom customer
  412.             $customerId = CustomerModel::where('name', 'like', '%' . $query . '%')->first();
  413.  
  414.             $i = 0;
  415.             if(isset($customerId)){
  416.                 $customers = RequestCustomerModel::where('customer_id', $customerId->id)
  417.                     ->where('deleted', '!=', 1)
  418.                     ->get();
  419.  
  420.                 foreach($customers as $customer){
  421.                     $rc = $customer->request_id;
  422.                     $request = $request->orWhere('id', $rc);
  423.                     $data['customers'][$i++] = $this->customers($rc);
  424.                 }
  425.             } else {
  426.                 $i = 0;
  427.                 foreach($request->get() as $row){
  428.                     $data['customers'][$i++] = $this->customers($row->id);
  429.                 }
  430.  
  431.                 //mencari kesamaan pada kolom request_date, request_number, amount
  432.                 $request = $request->orWhere('request_date', 'like', '%' . date('Y-m-d H:i:s', strtotime($query)) . '%')
  433.                 ->orWhere('request_number', 'like', '%' . $query . '%')
  434.                 ->orWhere('amount', 'like', '%' . $query . '%');
  435.  
  436.                 //mencari kesamaan pada kolom tipe
  437.                 if(strtoupper($query) == 'SO'){
  438.                     $request = $request->orWhere('type', REQUEST_TYPE_SO);
  439.                 } else if(strtoupper($query) == 'QUO'){
  440.                     $request = $request->orWhere('type', REQUEST_TYPE_QUO);
  441.                 }
  442.  
  443.                 //mencari kesamaan pada kolom status
  444.                 if(stripos('permohonan baru', strtolower($query)) !== false){
  445.                     $request = $request->orWhere('status', REQUEST_STATUS_NEW);
  446.                 } else if(stripos('disetujui', strtolower($query)) !== false){
  447.                     $request = $request->orWhere('status', REQUEST_STATUS_APPROVED);
  448.                 } else if(stripos('ditolak', strtolower($query)) !== false){
  449.                     $request = $request->orWhere('status', REQUEST_STATUS_REJECTED);
  450.                 } else if(stripos('diteruskan', strtolower($query)) !== false){
  451.                     $request = $request->orWhere('status', REQUEST_STATUS_FORWARDED);
  452.                 }
  453.             }
  454.         } else {
  455.             $i = 0;
  456.             foreach($request->get() as $row){
  457.                 $data['customers'][$i++] = $this->customers($row->id);
  458.             }
  459.  
  460.             //kondisi pilih owner sesuai ts
  461.             if ($request->status == 2) {
  462.                 $data['approver'] = Employee::find($request->approved_by);
  463.             } else if ($request->status == 3){
  464.                 $data['rejecter'] = Employee::find($request->rejected_by);
  465.             } else if ($request->status == 1 && $request->forward_counter > 0){
  466.                 $data['forward_to'] = Employee::find($request->forwarded_to);
  467.             }
  468.            
  469.            
  470.         }
  471.  
  472.         //--- Search's scripts ended here ---
  473.  
  474.         //--- Filter's scripts starts here ---
  475.         if(Request::get('filter') !== null){
  476.             $filters = Request::get('filter');
  477.             foreach($filters as $filter){
  478.                 if($filter == 1){
  479.                     $request->where('type', REQUEST_TYPE_SO);
  480.                 } else if($filter == 2){
  481.                     $request->orWhere('type', REQUEST_TYPE_QUO);
  482.                 } else if($filter == 3){
  483.                     $request->where('status', REQUEST_STATUS_NEW);
  484.                 } else if($filter == 4){
  485.                     $request->orWhere('status', REQUEST_STATUS_APPROVED);
  486.                 } else if($filter == 5){
  487.                     $request->orWhere('status', REQUEST_STATUS_REJECTED);
  488.                 } else if($filter == 6){
  489.                     $request->orWhere('status', REQUEST_STATUS_FORWARDED);
  490.                 }
  491.             }
  492.         }
  493.         //--- Filter's scripts ended here ---
  494.  
  495.         $request = $request->orderby('status','asc')->paginate(10);
  496.  
  497.         $data['result'] = $request;
  498.  
  499.         //Create a view. Please use `cbView` method instead of view method from laravel.
  500.         $this->cbView('Custom_CRUDBooster.request_index',$data);
  501.     }
  502.  
  503.     public function getEdit($id)
  504.     {
  505.         $request = RequestModel::find($id);
  506.  
  507.         if($request->status != REQUEST_STATUS_NEW){
  508.             CRUDBooster::redirect(CRUDBooster::adminPath(),"Anda tidak dapat merubah data ini!");
  509.         }
  510.  
  511.         $data = [];
  512.         $data['page_title'] = 'Edit Data';
  513.         $data['row'] = $request;
  514.  
  515.         //Please use cbView method instead view method from laravel
  516.         $this->cbView('crudbooster::default.form',$data);
  517.     }
  518.  
  519.     public function getDetail($id){
  520.         try {
  521.             $data = [];
  522.             $data['page_title'] = 'Detail Permohonan';
  523.             $selectedData = RequestModel::find($id);
  524.  
  525.             if(isset($selectedData)) {
  526.                 $request_by = DB::table('cpi_mst_employee')->where('id', $selectedData->request_by)->first()->name;
  527.                 $owner = DB::table('cpi_mst_owner')->where('id', $selectedData->owner_id)->first()->owner_name;
  528.  
  529.                 $selectedData->request_by = $request_by;
  530.                 $selectedData->owner_id = $owner;
  531.  
  532.                 $selectedData->amount = "Rp.".number_format($selectedData->amount);
  533.                 $selectedData->due_date = "Rp.".number_format($selectedData->due_date);
  534.                 $selectedData->sales_before = "Rp.".number_format($selectedData->sales_before);
  535.                 $selectedData->transfer_before = "Rp.".number_format($selectedData->transfer_before);
  536.  
  537.                 $customers = RequestCustomerModel::
  538.                     join('cpi_mst_customer', 'cpi_trx_request_customer.customer_id', '=', 'cpi_mst_customer.id')
  539.                     ->select('cpi_mst_customer.name')
  540.                     ->where('cpi_trx_request_customer.request_id', '=', $selectedData->id)
  541.                     ->where('cpi_trx_request_customer.deleted', '!=', 1)
  542.                     ->get();
  543.  
  544.                 $data['data'] = $selectedData;
  545.                 $data['customers'] = $customers;
  546.                 //CRUDBooster auth
  547.                 if(!CRUDBooster::isView()){
  548.                     CRUDBooster::denyAccess();
  549.                 }
  550.  
  551.                 $this->cbView('Custom_CRUDBooster.request_detail',$data);
  552.             } else {
  553.                 Log::error('Data permohonan (request) tidak ditemukan!');
  554.                 return redirect()->back();
  555.             }
  556.         } catch (Exception $e) {
  557.             Log::error('Terjadi error! Message: ' . $e->getMessage());
  558.             return redirect()->back();
  559.         }
  560.     }
  561.  
  562.     public function postAddSave(){
  563.         try {
  564.             $request_id = RequestModel::create([
  565.                 'request_number'=> Request::get('request_number'),
  566.                 'request_date'=> Request::get('request_date'),
  567.                 'request_by'=> (int)Request::get('request_by'),
  568.                 'assignee_user_id'=> (int)Request::get('request_by'),
  569.                 'owner_id' => (int)Request::get('owner_id'),
  570.                 'type'=> (int)Request::get('type'),
  571.                 'status'=>1,
  572.                 'amount'=> Request::get('amount'),
  573.                 'due_date'=> Request::get('due_date'),
  574.                 'sales_before'=> Request::get('sales_before'),
  575.                 'transfer_before'=> Request::get('transfer_before'),
  576.                 'credit_limit_total'=> Request::get('credit_limit_total'),
  577.                 'credit_limit_used'=> Request::get('credit_limit_used'),
  578.                 'credit_term_waktu'=> Request::get('credit_term_waktu'),
  579.                 'credit_term_berjalan'=> Request::get('credit_term_berjalan')
  580.             ])->id;
  581.  
  582.             foreach(Request::get('customer_ids') as $customer_id){
  583.                 RequestCustomerModel::create([
  584.                     'request_id' => $request_id,
  585.                     'customer_id' => $customer_id,
  586.                     'deleted' => 0
  587.                 ]);
  588.             }
  589.  
  590.             return redirect('/admin/cpi_trx_request?m=5');
  591.         } catch (\Exception $e) {
  592.             return redirect()->back();
  593.         }
  594.     }
  595.  
  596.     public function postEditSave($id){
  597.         $requestData = RequestModel::find($id);
  598.         try {
  599.             $requestData->request_number = Request::get('request_number');
  600.             $requestData->request_date = Request::get('request_date');
  601.             $requestData->request_by = Request::get('request_by');
  602.             $requestData->owner_id = Request::get('owner_id');
  603.             $requestData->type = Request::get('type');
  604.             $requestData->status = 1;
  605.             $requestData->amount = Request::get('amount');
  606.             $requestData->due_date = Request::get('due_date');
  607.             $requestData->sales_before = Request::get('sales_before');
  608.             $requestData->transfer_before = Request::get('transfer_before');
  609.             $requestData->credit_limit_total = Request::get('credit_limit_total');
  610.             $requestData->credit_limit_used = Request::get('credit_limit_used');
  611.             $requestData->credit_term_waktu = Request::get('credit_term_waktu');
  612.             $requestData->credit_term_berjalan = Request::get('credit_term_berjalan');
  613.  
  614.             $requestData->save();
  615.             if(Request::get('customer_ids') !== null){
  616.                 $requestcustomer = RequestCustomerModel::where('request_id', $id)->delete();
  617.                 foreach(Request::get('customer_ids') as $customer_id){
  618.                     RequestCustomerModel::create([
  619.                         'request_id' => $id,
  620.                         'customer_id' => $customer_id,
  621.                         'deleted' => 0
  622.                     ]);
  623.                 }
  624.             }
  625.  
  626.             if(Request::get('return_url')) {
  627.                 CRUDBooster::redirect(Request::get('return_url'),trans("crudbooster.alert_update_data_success"),'success');
  628.             }else{
  629.                 if(Request::get('submit') == trans('crudbooster.button_save_more')) {
  630.                     CRUDBooster::redirect(CRUDBooster::mainpath('add'),trans("crudbooster.alert_update_data_success"),'success');
  631.                 }else{
  632.                     CRUDBooster::redirect(CRUDBooster::mainpath(),trans("crudbooster.alert_update_data_success"),'success');
  633.                 }
  634.             }
  635.         } catch (\Exception $e) {
  636.             return redirect()->back();
  637.         }
  638.     }
  639.  
  640.     public function getDelete($id){
  641.         $employee = RequestModel::find($id);
  642.  
  643.         $customers = RequestCustomerModel::where('request_id', $employee->id);
  644.  
  645.         if($customers !== null){
  646.             $customers->delete();
  647.         }
  648.  
  649.         $employee->delete();
  650.  
  651.         $url = Request::get('return_url')?:CRUDBooster::referer();
  652.  
  653.         CRUDBooster::redirect($url,trans("crudbooster.alert_delete_data_success"),'success');
  654.     }
  655.     //By the way, you can still create your own method in here... :)
  656.  
  657.  
  658. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top