Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function saveApprovals_post()
- {
- $param = file_get_contents('php://input');
- $param = json_decode($param);
- $msg = $app = $reason = array();
- $app = array_map(function($str){ if(substr($str->name, 0, 3) == 'app' || substr($str->name, 0, 3) == 'rej') return $str; }, $param);
- $app = array_values(array_filter($app, function($val){ return $val !== null; }));
- $reason = array_map(function($str){ if(substr($str->name, 0, 6) == 'reason') return $str; }, $param);
- $reason = array_values(array_filter($reason, function($val){ return $val !== null; }));
- for ($i=0; $i < count($app) ; $i++) {
- if ($app[$i]->value != '') {
- $gettime = date('Y-m-d H:i:s');
- if ($app[$i]->value == 'Approved') {
- $data = [
- 'receive_status' => '1',
- 'receive_user_id' => $this->data['user']['userid'],
- 'receive_time' => $gettime,
- 'updated_at' => $gettime
- ];
- }elseif ($app[$i]->value == 'Rejected') {
- for ($k=0; $k < count($reason) ; $k++) {
- if ($reason[$i]->value != '') {
- $data = [
- 'reject' => '1',
- 'reject_user_id' => $this->data['user']['userid'],
- 'reason_reject' => $reason[$i]->value,
- 'reject_time' => $gettime,
- 'updated_at' => $gettime
- ];
- }
- }
- }
- $idShipmentNumber = explode('-', $app[$i]->name)[1];
- $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();
- $id = explode('-', $app[$i]->name)[1];
- $this->db->reset_query();
- if ($this->db->where('id',$id)->update('remote_lsp',$data)) {
- $msg[] = array('msg' => 'success', 'msg_value' => 'Success! Request '.explode('-', $app[$i]->name)[1].' Approved Or Rejected!');
- // set attachment
- // exit;
- // end set attachment
- }else{
- $msg[] = array('msg' => 'success', 'msg_value' => 'Failed! Request '.explode('-', $app[$i]->name)[1].' Approved Or Rejected!');
- }
- }
- }
- // insert attachment
- $getVendor = $this->db->select('vendor_name,phone,email')->where('ms_vendor_id',$IdRlspGet->vendor_id)->get('ms_vendor')->row();
- $attachment = $this->setAttachmentVendor($idShipmentNumber,$IdRlspGet,$gettime,$getVendor);
- $this->db->insert('mail_remote_lsp',$attachment);
- // end insert attachment
- $this->db->reset_query();
- // insert attachment two
- $attachtw = $this->setAttachmentApr($idShipmentNumber,$IdRlspGet,$gettime,$getVendor);
- $this->db->insert('mail_remote_lsp',$attachtw);
- // end insert attachment two
- echo json_encode($msg);
- }
Add Comment
Please, Sign In to add comment