public static function getNotes($delivery_id, $as_array = true) { $notes = Deliverynote::where('deliveryId', '=', $delivery_id)->orderBy('mtimestamp', 'desc')->get(); if ($as_array) { return $notes->toArray(); } else { $list = '<ul class="note_list">'; foreach ($notes as $note) { $list .= '<li>'; $list .= '<b>' . $note->status . '</b><br />'; $list .= $note->datetimestamp . '<br />'; $list .= $note->note; $list .= '</li>'; } $list .= '</ul>'; return $list; } }
/** * Store a newly created resource in storage. * * @return Response */ public function postNote() { $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) { if (isset($j['logId'])) { if (isset($j['datetimestamp'])) { $j['mtimestamp'] = new \MongoDate(strtotime($j['datetimestamp'])); } $log = \Deliverynote::where('logId', $j['logId'])->first(); if ($log) { $result[] = array('status' => 'OK', 'timestamp' => time(), 'message' => $j['logId']); } else { \Deliverynote::insert($j); $result[] = array('status' => 'OK', 'timestamp' => time(), 'message' => $j['logId']); } } } //print_r($result); //die(); $actor = $user->identifier . ' : ' . $user->devname; \Event::fire('log.api', array($this->controller_name, 'get', $actor, 'sync note')); return Response::json($result); }
/** * Store a newly created resource in storage. * * @return Response */ public function postNote() { 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' => $image_id)); } $json = \Input::all(); $batch = \Input::get('batch'); $result = array(); foreach ($json as $j) { if (isset($j['logId'])) { $j['appname'] = $appname; if (isset($j['datetimestamp'])) { $j['mtimestamp'] = new \MongoDate(strtotime($j['datetimestamp'])); } $log = \Deliverynote::where('logId', $j['logId'])->first(); if ($log) { $result[] = array('status' => 'OK', 'timestamp' => time(), 'message' => $j['logId']); } else { \Deliverynote::insert($j); $result[] = array('status' => 'OK', 'timestamp' => time(), 'message' => $j['logId']); } $pending = \Deliverynote::where('deliveryId', '=', $j['deliveryId'])->where('status', '=', 'pending')->count(); if ($pending > 0) { $ord = \Shipment::where('delivery_id', '=', $j['deliveryId'])->first(); $ord->pending_count = $pending; $ord->save(); } } } //print_r($result); //die(); $actor = $user->identifier . ' : ' . $user->devname; \Event::fire('log.api', array($this->controller_name, 'get', $actor, 'sync note')); return Response::json($result); }