Пример #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $dbox = Boxstatus::where('appname', '=', Config::get('jex.tracker_app'))->where('deliveryStatus', '=', Config::get('jayon.trans_status_mobile_delivered'))->get();
     if ($dbox) {
         foreach ($dbox as $dbx) {
             print 'box status : ' . $dbx->deliveryId . ' ' . $dbx->boxId . ' ' . $dbx->deliveryStatus . "\r\n";
             $box = Box::where('delivery_id', '=', $dbx->deliveryId)->where(function ($q) use($dbx) {
                 $q->where('box_id', '=', intval($dbx->boxId))->orWhere('box_id', '=', strval($dbx->boxId));
             })->first();
             if ($box) {
                 print 'box before : ' . $box->delivery_id . ' ' . $box->box_id . ' ' . $box->deliveryStatus . "\r\n";
                 $box->deliveryStatus = $dbx->deliveryStatus;
                 print 'box after : ' . $box->delivery_id . ' ' . $box->box_id . ' ' . $box->deliveryStatus . "\r\n";
                 $box->save();
             }
         }
     }
 }
Пример #2
0
 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';
     }
 }
Пример #3
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function postBoxstatus()
 {
     $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) {
         if (isset($j['logId'])) {
             if (isset($j['datetimestamp'])) {
                 $j['mtimestamp'] = new \MongoDate(strtotime($j['datetimestamp']));
             }
             $log = \Boxstatus::where('logId', $j['logId'])->first();
             if ($log) {
                 $result[] = array('status' => 'OK', 'timestamp' => time(), 'message' => $j['logId']);
             } else {
                 /*
                                     $bs = array();
                                     foreach($j as $k=>$v){
                                         $bs[$this->camel_to_underscore($k)] = $v;
                                     }*/
                 $j['appname'] = $appname;
                 \Boxstatus::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 scan log'));
     return Response::json($result);
 }
Пример #4
0
 public function postChangestatus()
 {
     $in = Input::get();
     $results = Box::whereIn('_id', $in['box_ids'])->get();
     $delivery_status = $in['delivery_status'];
     $courier_status = $in['courier_status'];
     $warehouse_status = $in['warehouse_status'];
     $position = $in['position'];
     $note = $in['note'];
     date_default_timezone_set('Asia/Jakarta');
     $res = false;
     $ts = new MongoDate();
     $setpendingcount = array();
     foreach ($results as $bx) {
         $prebx = clone $bx;
         $sh = Shipment::where('delivery_id', '=', $bx->delivery_id)->first();
         //$sh->pick_up_date = new MongoDate(strtotime($in['date'])) ;
         if ($sh) {
             $pre = clone $sh;
             if (is_null($delivery_status) || $delivery_status == '') {
             } else {
                 $sh->status = $delivery_status;
                 $sh->last_action_ts = $ts;
                 $sh->last_action = 'Change Status by Admin';
                 $sh->last_reason = $in['reason'];
                 $this->saveDeliveryNote($delivery_status, $note, $ts, $sh);
                 if ($delivery_status == Config::get('jayon.trans_status_mobile_pending')) {
                     if (in_array($sh->delivery_id, $setpendingcount)) {
                     } else {
                         $sh->pending_count = $sh->pending_count + 1;
                     }
                     $setpendingcount[] = $sh->delivery_id;
                     $setpendingcount = array_unique($setpendingcount);
                 }
             }
             if (is_null($courier_status) || $courier_status == '') {
             } else {
                 $sh->courier_status = $courier_status;
             }
             if (is_null($warehouse_status) || $warehouse_status == '') {
             } else {
                 $sh->warehouse_status = $warehouse_status;
             }
             if (is_null($position) || $position == '') {
             } else {
                 $sh->position = $position;
             }
             $sh->last_action_ts = $ts;
             $sh->last_action = 'Change Status';
             $sh->last_reason = $in['reason'];
             $sh->save();
             $hdata = array();
             $hdata['historyTimestamp'] = $ts;
             $hdata['historyAction'] = 'change_status';
             $hdata['historySequence'] = 1;
             $hdata['historyObjectType'] = 'shipment';
             $hdata['historyObject'] = $sh->toArray();
             $hdata['actor'] = Auth::user()->fullname;
             $hdata['actor_id'] = Auth::user()->_id;
             History::insert($hdata);
             $sdata = array();
             $sdata['timestamp'] = $ts;
             $sdata['action'] = 'change_status';
             $sdata['reason'] = $in['reason'];
             $sdata['objectType'] = 'shipment';
             $sdata['object'] = $sh->toArray();
             $sdata['preObject'] = $pre->toArray();
             $sdata['actor'] = Auth::user()->fullname;
             $sdata['actor_id'] = Auth::user()->_id;
             Shipmentlog::insert($sdata);
         }
         if (is_null($delivery_status) || $delivery_status == '') {
         } else {
             $bx->deliveryStatus = $delivery_status;
         }
         if (is_null($courier_status) || $courier_status == '') {
         } else {
             $bx->courierStatus = $courier_status;
         }
         if (is_null($warehouse_status) || $warehouse_status == '') {
         } else {
             $bx->warehouseStatus = $warehouse_status;
         }
         if (is_null($position) || $position == '') {
         } else {
             $bx->position = $position;
         }
         $bx->save();
         $hdata = array();
         $hdata['historyTimestamp'] = $ts;
         $hdata['historyAction'] = 'change_status';
         $hdata['historySequence'] = 1;
         $hdata['historyObjectType'] = 'box';
         $hdata['historyObject'] = $bx->toArray();
         $hdata['actor'] = Auth::user()->fullname;
         $hdata['actor_id'] = Auth::user()->_id;
         History::insert($hdata);
         $sdata = array();
         $sdata['timestamp'] = $ts;
         $sdata['action'] = 'change_status';
         $sdata['reason'] = $in['reason'];
         $sdata['objectType'] = 'box';
         $sdata['object'] = $bx->toArray();
         $sdata['preObject'] = $prebx->toArray();
         $sdata['actor'] = Auth::user()->fullname;
         $sdata['actor_id'] = Auth::user()->_id;
         Shipmentlog::insert($sdata);
         $bs = array();
         $bs['boxId'] = $bx->box_id;
         $bs['datetimestamp'] = date('Y-m-d H:i:s', $ts->sec);
         $bs['deliveryId'] = $bx->delivery_id;
         $bs['dest'] = 'hub';
         $bs['deviceId'] = Auth::user()->fullname;
         $bs['deviceKey'] = Auth::user()->_id;
         $bs['disposition'] = $sh->position;
         $bs['extId'] = $bx->_id;
         $bs['fulfillmentCode'] = $bx->fulfillment_code;
         $bs['logId'] = '';
         $bs['merchantTransId'] = $bx->order_id;
         $bs['src'] = 'admin';
         $bs['status'] = $bx->deliveryStatus;
         $bs['timestamp'] = $ts->sec;
         $bs['uploaded'] = 0;
         $bs['id'] = 0;
         $bs['tableName'] = 'BOX_STATUS';
         $bs['mtimestamp'] = $ts;
         Boxstatus::insert($bs);
         $bl = array();
         $bl['boxId'] = '4';
         $bl['datetimestamp'] = date('Y-m-d H:i:s', $ts->sec);
         $bl['deliveryId'] = $bx->delivery_id;
         $bl['fulfillmentCode'] = $bx->fulfillment_code;
         $bl['merchantTransId'] = $bx->order_id;
         $bl['status'] = 'out';
         $bl['timestamp'] = $ts->sec;
         $bl['id'] = 0;
         $bl['tableName'] = 'BOX_ID';
         $bl['mtimestamp'] = $ts;
         Boxid::insert($bl);
     }
     $res = true;
     //}
     if ($res) {
         return Response::json(array('result' => 'OK:CHGSTAT'));
     } else {
         return Response::json(array('result' => 'ERR:CHGSTATFAILED'));
     }
 }
Пример #5
0
 public static function save_box($delivery_id, $merchant_trans_id, $fulfillment_code, $count)
 {
     $affected = Box::where('delivery_id', '=', $delivery_id)->where('merchant_trans_id', '=', $merchant_trans_id)->where('fulfillment_code', '=', $fulfillment_code)->delete();
     for ($i = 0; $i < $count; $i++) {
         $bd = new Box();
         $bd->delivery_id = $delivery_id;
         $bd->merchant_trans_id = $merchant_trans_id;
         $bd->fulfillment_code = $fulfillment_code;
         $bd->box_id = $i + 1;
         $bd->save();
         $bds = new Boxstatus();
         $bds->delivery_id = $delivery_id;
         $bds->merchant_trans_id = $merchant_trans_id;
         $bds->fulfillment_code = $fulfillment_code;
         $bds->box_id = $i + 1;
         $bds->timestamp = date('Y-m-d H:i:s', time());
         $bds->save();
     }
 }