public function __construct() { //$this->model = "Member"; $this->controller_name = strtolower(str_replace('Controller', '', get_class())); $this->sql_table_name = \Config::get('jayon.incoming_delivery_table'); $this->sql_connection = 'mysql'; $this->model = \DB::connection($this->sql_connection)->table($this->sql_table_name); }
public function lastBoxStatus($device_key, $delivery_id, $fulfillment_code, $box_id) { $last = \Boxstatus::where('deliveryId', '=', $delivery_id)->where('deviceKey', '=', $device_key)->where('appname', '=', \Config::get('jex.tracker_app'))->where('boxId', '=', strval($box_id))->orderBy('mtimestamp', 'desc')->first(); //print_r($last); if ($last) { return $last->status; } else { return 'out'; } }
/** * Store a newly created resource in storage. * * @return Response */ public function postFiles() { $key = Input::get('key'); $user = \Apiauth::user($key); $parent_id = Input::get('parid'); $parent_class = Input::get('parclass'); $image_id = Input::get('img'); $ns = Input::get('ns'); $rstring = str_random(15); $result = ''; $destinationPath = realpath('storage/media') . '/' . $rstring; if (isset($_FILES['file'])) { $file = $_FILES['file']; $filename = $file['name']; $filemime = $file['type']; $filesize = $file['size']; $extension = '.jpg'; //if you need extension of the file $tmp_name = $file['tmp_name']; $filename = str_replace(\Config::get('kickstart.invalidchars'), '-', $filename); //$uploadSuccess = $file->move($destinationPath, $filename); @move_uploaded_file($tmp_name, $destinationPath . '/' . $filename); $is_image = true; $is_audio = false; $is_video = false; $is_pdf = false; $is_doc = false; $is_image = $this->isImage($filemime); $is_audio = $this->isAudio($filemime); $is_video = $this->isVideo($filemime); $is_pdf = $this->isPdf($filemime); if (!($is_image || $is_audio || $is_video || $is_pdf)) { $is_doc = true; } else { $is_doc = false; } if ($is_image) { $ps = \Config::get('picture.sizes'); $thumbnail = \Image::make($destinationPath . '/' . $filename)->fit($ps['thumbnail']['width'], $ps['thumbnail']['height'])->save($destinationPath . '/th_' . $filename); $medium = \Image::make($destinationPath . '/' . $filename)->fit($ps['medium']['width'], $ps['medium']['height'])->save($destinationPath . '/med_' . $filename); $large = \Image::make($destinationPath . '/' . $filename)->fit($ps['large']['width'], $ps['large']['height'])->save($destinationPath . '/lrg_' . $filename); $full = \Image::make($destinationPath . '/' . $filename)->save($destinationPath . '/full_' . $filename); $image_size_array = array('thumbnail_url' => \URL::to('storage/media/' . $rstring . '/' . $ps['thumbnail']['prefix'] . $filename), 'large_url' => \URL::to('storage/media/' . $rstring . '/' . $ps['large']['prefix'] . $filename), 'medium_url' => \URL::to('storage/media/' . $rstring . '/' . $ps['medium']['prefix'] . $filename), 'full_url' => \URL::to('storage/media/' . $rstring . '/' . $ps['full']['prefix'] . $filename)); } else { if ($is_audio) { $thumbnail_url = \URL::to('images/audio.png'); } elseif ($is_video) { $thumbnail_url = \URL::to('images/video.png'); } else { $thumbnail_url = \URL::to('images/media.png'); } $image_size_array = array('thumbnail_url' => $thumbnail_url, 'large_url' => '', 'medium_url' => '', 'full_url' => ''); } $item = array('ns' => $ns, 'parent_id' => $parent_id, 'parent_class' => $parent_class, 'url' => \URL::to('storage/media/' . $rstring . '/' . $filename), 'temp_dir' => $destinationPath, 'file_id' => $rstring, 'is_image' => $is_image, 'is_audio' => $is_audio, 'is_video' => $is_video, 'is_pdf' => $is_pdf, 'is_doc' => $is_doc, 'name' => $filename, 'type' => $filemime, 'size' => $filesize, 'deleted' => 0, 'createdDate' => new \MongoDate(), 'lastUpdate' => new \MongoDate()); foreach ($image_size_array as $k => $v) { $item[$k] = $v; } $item['_id'] = new \MongoId($image_id); $im = \Uploaded::find($image_id); if ($im) { } else { \Uploaded::insertGetId($item); } $actor = $user->fullname . ' : ' . $user->email; \Event::fire('log.api', array($this->controller_name, 'post', $actor, 'upload image')); return \Response::json(array('status' => 'OK', 'timestamp' => time(), 'message' => $image_id)); } $actor = $user->fullname . ' : ' . $user->email; \Event::fire('log.api', array($this->controller_name, 'post', $actor, 'upload image failed')); return \Response::json(array('status' => 'ERR:NOFILE', 'timestamp' => time(), 'message' => $image_id)); }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $key = Input::get('key'); $json = Input::all(); //print_r($json); /* ->join('members as m','d.merchant_id=m.id','left') ->where('assignment_date',$indate) ->where('device_id',$dev->id) ->and_() ->group_start() ->where('status',$this->config->item('trans_status_admin_courierassigned')) ->or_() ->group_start() ->where('status',$this->config->item('trans_status_new')) ->where('pending_count >', 0) ->group_end() ->group_end() */ if (is_null($key) || $key == '') { $actor = 'no id : no name'; \Event::fire('log.api', array($this->controller_name, 'post', $actor, 'empty key')); return \Response::json(array('status' => 'ERR:EMPTYKEY', 'timestamp' => time(), 'message' => 'Empty Key')); } $app = \Application::where('key', '=', $key)->first(); if ($app) { $model = new \Shipment(); $merchant_id = $app->merchant_id; $result = array(); foreach ($json as $j) { if (is_array($j)) { if (isset($j['awb'])) { $awb = $j['awb']; $m = $model->where('delivery_id', '=', trim($awb))->first(); /* ->where(function($q){ $q->where('status','=', \Config::get('jayon.trans_status_tobeconfirmed') ) ->orWhere(function($qp){ $qp->where('status','=',\Config::get('jayon.trans_status_new')) ->where('pending_count','=',0); }); })->first(); */ if ($m) { if ($m->status == \Config::get('jayon.trans_status_tobeconfirmed') || $m->status == \Config::get('jayon.trans_status_new') && $m->pending_count == 0) { $m->status = \Config::get('jayon.trans_status_confirmed'); $m->save(); } $result[] = array('awb' => $m->delivery_id, 'status' => $m->status); } } } } if (empty($result)) { $result = array('status' => 'ERR:NOMATCH', 'message' => 'No Match Found'); } else { $result = array('status' => 'OK', 'message' => 'Confirmation Success', 'data' => $result); } //print_r($result); //die(); $actor = $app->key . ' : ' . $app->merchant_id; \Event::fire('log.api', array($this->controller_name, 'post', $actor, 'awb search with array')); return Response::json($result); } else { $actor = 'no id : no name'; \Event::fire('log.api', array($this->controller_name, 'post', $actor, 'account not found')); return \Response::json(array('status' => 'ERR:INVALIDACC', 'timestamp' => time(), 'message' => 'Invalid Account')); } }
/** * @name login() * @param string user * @param sring pwd * @method POST */ public function login() { $userfield = \Config::get('kickstart.user_field'); $passwordfield = \Config::get('kickstart.password_field'); if (Input::has('user') && Input::has('pwd')) { $retVal = array("status" => "ERR", "msg" => "Invalid username or password."); try { $user = \User::where($userfield, '=', Input::get('user'))->firstorFail(); if ($user) { if (Hash::check(Input::get('pwd'), $user->{$passwordfield})) { $sessionKey = md5(time() . $user->email . $user->_id . "momumu<-Salt?"); $user->sessionKey = $sessionKey; $user->save(); $userarray = $user->toArray(); //$userarray['createdDate'] = date('Y-m-d H:i:s',$userarray['createdDate']->sec); $userarray['lastUpdate'] = date('Y-m-d H:i:s', $userarray['lastUpdate']->sec); $userarray['mongoid'] = $userarray['_id']; unset($userarray['password']); unset($userarray['_id']); unset($userarray['_token']); unset($userarray['session_key']); $retVal = array_merge(array("status" => "OK", "msg" => "Login Success.", "key" => $sessionKey), $userarray); $actor = $user->fullname . ' - ' . $user->email; \Event::fire('log.api', array($this->controller_name, 'login', $actor, 'logged in')); } } else { $actor = Input::get('user'); \Event::fire('log.api', array($this->controller_name, 'login', $actor, 'user not found')); } } catch (ModelNotFoundException $e) { } return Response::json($retVal); } }
/** * Store a newly created resource in storage. * * @return Response */ public function postOrder() { $key = \Input::get('key'); //$user = \Apiauth::user($key); $user = \Device::where('key', '=', $key)->first(); if (!$user) { $actor = 'no id : no name'; \Event::fire('log.api', array($this->controller_name, 'post', $actor, 'device not found, upload image failed')); return \Response::json(array('status' => 'ERR:NODEVICE', 'timestamp' => time(), 'message' => 'Device Unregistered')); } $json = \Input::all(); $batch = \Input::get('batch'); $result = array(); foreach ($json as $j) { //$j['mtimestamp'] = new \MongoDate(time()); if (is_array($j)) { $olog = new \Orderlog(); foreach ($j as $k => $v) { $olog->{$k} = $v; } $olog->mtimestamp = new \MongoDate(time()); $r = $olog->save(); $shipment = \Shipment::where('delivery_id', '=', $olog->deliveryId)->first(); if ($shipment) { //$shipment->status = $olog->status; $shipment->courier_status = $olog->courierStatus; $shipment->pending_count = new \MongoInt32($olog->pendingCount); if ($olog->courierStatus == \Config::get('jayon.trans_cr_oncr') || $olog->courierStatus == \Config::get('jayon.trans_cr_oncr_partial')) { $shipment->pickup_status = \Config::get('jayon.trans_status_pickup'); } $shipment->save(); } if ($r) { $result[] = array('status' => 'OK', 'timestamp' => time(), 'message' => 'log inserted'); } else { $result[] = array('status' => 'NOK', 'timestamp' => time(), 'message' => 'insertion failed'); } } } //print_r($result); //die(); $actor = $user->identifier . ' : ' . $user->devname; \Event::fire('log.api', array($this->controller_name, 'get', $actor, 'sync scan log')); return Response::json($result); }
/** * Store a newly created resource in storage. * * @return Response */ public function postPickuporder() { date_default_timezone_set('Asia/Jakarta'); $key = \Input::get('key'); $appname = \Input::has('app') ? \Input::get('app') : 'app.name'; //$user = \Apiauth::user($key); $user = \Device::where('key', '=', $key)->first(); if (!$user) { $actor = 'no id : no name'; \Event::fire('log.api', array($this->controller_name, 'post', $actor, 'device not found, upload image failed')); return \Response::json(array('status' => 'ERR:NODEVICE', 'timestamp' => time(), 'message' => 'Device Unregistered')); } $json = \Input::all(); $batch = \Input::get('batch'); $result = array(); foreach ($json as $j) { //$j['mtimestamp'] = new \MongoDate(time()); if (is_array($j)) { $olog = new \Orderlog(); foreach ($j as $k => $v) { $olog->{$k} = $v; } $olog->mtimestamp = new \MongoDate(time()); $olog->appname = $appname; $olog->deviceActor = isset($user->identifier) ? $user->identifier : ''; $olog->pickupDevId = $user->identifier; if ($olog->disposition == $key && isset($user->node_id)) { $olog->position = $user->node_id; } $r = $olog->save(); $shipment = \Shipment::where('delivery_id', '=', $olog->deliveryId)->first(); if ($shipment) { //$check = $this->checkPickedUp($olog->deliveryId, 'pickupStatus' ,'sudah diambil' ,\Config::get('jex.pickup_app') , $user->identifier ); $changes = false; if ($olog->pickuptime == '' || $olog->pickuptime == '0000-00-00 00:00:00') { $pickuptime = date('Y-m-d H:i:s', time()); } else { $pickuptime = $olog->pickuptime; } $shipment->pickup_dev_id = $user->identifier; $shipment->pickup_status = $olog->pickupStatus; $shipment->pickuptime = $pickuptime; if (trim($olog->deliveryNote) != '') { $shipment->delivery_note = trim($olog->deliveryNote); } if ($olog->pickupStatus == \Config::get('jayon.trans_status_pickup')) { $changes = true; } else { if ($olog->pickupStatus == \Config::get('jayon.trans_status_no_pickup')) { if (trim($olog->deliveryNote) != '') { $changes = true; } } } if ($changes == true) { $shipment->save(); } /* //order currently already pick up if($shipment->pickup_status == \Config::get('jayon.trans_status_pickup')){ if($olog->pickupStatus == \Config::get('jayon.trans_status_pickup')){ if(trim($olog->deliveryNote) != ''){ $shipment->delivery_note = trim($olog->deliveryNote); } $shipment->pickup_status = $olog->pickupStatus; $shipment->pickuptime = $pickuptime; $changes = true; }else{ // tries to cancel pick up // Note should not empty if(trim($olog->deliveryNote) != ''){ //OK , allow status change if( trim($olog->deliveryNote) != '' ){ $shipment->delivery_note = trim($olog->deliveryNote); } $shipment->pickup_status = $olog->pickupStatus; $shipment->pickuptime = $pickuptime; $changes = true; } } }else{ if($olog->pickupStatus == \Config::get('jayon.trans_status_pickup')){ if( trim($olog->deliveryNote) != '' ){ $shipment->delivery_note = trim($olog->deliveryNote); } $shipment->pickup_status = $olog->pickupStatus; $shipment->pickuptime = $pickuptime; $changes = true; }else{ } } */ //if($shipment->pickup_status != \Config::get('jayon.trans_status_pickup') || // ($olog->pickupStatus != \Config::get('jayon.trans_status_pickup') && trim($olog->deliveryNote) != '' ) //){ /* if($olog->pickup_status == \Config::get('jayon.trans_status_pickup') || ($olog->pickupStatus != \Config::get('jayon.trans_status_pickup') && trim($olog->deliveryNote) != '' ) ){ $shipment->pickup_status = $olog->pickupStatus; if( $olog->pickupStatus == \Config::get('jayon.trans_status_pickup')){ if($olog->pickuptime == '' || $olog->pickuptime == '0000-00-00 00:00:00' ){ $pickuptime = date('Y-m-d H:i:s',time()); }else{ $pickuptime = $olog->pickuptime; } if( trim($olog->deliveryNote) != '' ){ $shipment->delivery_note = trim($olog->deliveryNote); } if($shipment->pickuptime == '' || $shipment->pickuptime == '0000-00-00 00:00:00' ){ $shipment->pickuptime = $pickuptime; } $shipment->pickup_dev_id = $user->identifier; } $shipment->save(); } */ //$shipment->status = $olog->status; } if ($r) { $result[] = array('status' => 'OK', 'timestamp' => time(), 'message' => 'log inserted'); } else { $result[] = array('status' => 'NOK', 'timestamp' => time(), 'message' => 'insertion failed'); } } } //print_r($result); //die(); $actor = $user->identifier . ' : ' . $user->devname; \Event::fire('log.api', array($this->controller_name, 'get', $actor, 'sync scan log')); return Response::json($result); }