faizadie

controller

Mar 5th, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.52 KB | None | 0 0
  1.  public function saveApprovals_post()
  2.     {
  3.         $param = file_get_contents('php://input');
  4.         $param = json_decode($param);
  5.         $msg = $app = $reason = array();
  6.         $app = array_map(function($str){ if(substr($str->name, 0, 3) == 'app' || substr($str->name, 0, 3) == 'rej') return $str; }, $param);
  7.         $app = array_values(array_filter($app, function($val){ return $val !== null; }));
  8.         $reason = array_map(function($str){ if(substr($str->name, 0, 6) == 'reason') return $str; }, $param);
  9.         $reason = array_values(array_filter($reason, function($val){ return $val !== null; }));
  10.         for ($i=0; $i < count($app) ; $i++) {
  11.             if ($app[$i]->value != '') {
  12.                 $gettime = date('Y-m-d H:i:s');
  13.                 if ($app[$i]->value == 'Approved') {
  14.                     $data = [
  15.                         'receive_status'    => '1',
  16.                         'receive_user_id'   => $this->data['user']['userid'],
  17.                         'receive_time'      => $gettime,
  18.                         'updated_at'        => $gettime
  19.                     ];
  20.                 }elseif ($app[$i]->value == 'Rejected') {
  21.                     for ($k=0; $k < count($reason) ; $k++) {
  22.                         if ($reason[$i]->value != '') {
  23.                             $data = [
  24.                                 'reject'            => '1',
  25.                                 'reject_user_id'    => $this->data['user']['userid'],
  26.                                 'reason_reject'     => $reason[$i]->value,
  27.                                 'reject_time'       => $gettime,
  28.                                 'updated_at'        => $gettime
  29.                             ];
  30.                         }
  31.                     }
  32.                 }
  33.  
  34.                 $idShipmentNumber = explode('-', $app[$i]->name)[1];
  35.                 $IdRlspGet = $this->db->select('ms_remote_lsp_shipment.id as shipment_id, ms_remote_lsp_shipment.shipment_number,remote_lsp.id,remote_lsp.vendor_id,remote_lsp.ms_sparepart_id,remote_lsp.region_id,remote_lsp.dop_id,remote_lsp.ne_id')->join('ms_remote_lsp_shipment','ms_remote_lsp_shipment.id = remote_lsp.remote_lsp_shipment_id')->where('remote_lsp.id',$idShipmentNumber)->get('remote_lsp')->row();
  36.                 $id = explode('-', $app[$i]->name)[1];
  37.  
  38.                 $this->db->reset_query();
  39.                 if ($this->db->where('id',$id)->update('remote_lsp',$data)) {
  40.                     $msg[] = array('msg' => 'success', 'msg_value' => 'Success! Request '.explode('-', $app[$i]->name)[1].' Approved Or Rejected!');
  41.                     // set attachment
  42.                         // exit;
  43.  
  44.                     // end set attachment
  45.                 }else{
  46.                     $msg[] = array('msg' => 'success', 'msg_value' => 'Failed! Request '.explode('-', $app[$i]->name)[1].' Approved Or Rejected!');
  47.                 }
  48.             }
  49.         }
  50.         // insert attachment
  51.         $getVendor = $this->db->select('vendor_name,phone,email')->where('ms_vendor_id',$IdRlspGet->vendor_id)->get('ms_vendor')->row();
  52.         $attachment = $this->setAttachmentVendor($idShipmentNumber,$IdRlspGet,$gettime,$getVendor);
  53.         $this->db->insert('mail_remote_lsp',$attachment);
  54.         // end insert attachment
  55.         $this->db->reset_query();
  56.         // insert attachment two
  57.         $attachtw = $this->setAttachmentApr($idShipmentNumber,$IdRlspGet,$gettime,$getVendor);
  58.         $this->db->insert('mail_remote_lsp',$attachtw);
  59.         // end insert attachment two
  60.  
  61.         echo json_encode($msg);
  62.     }
Add Comment
Please, Sign In to add comment