/** * Execute the console command. * * @return mixed */ public function fire() { $delivereds = Orderlog::where('appname', '=', Config::get('jex.tracker_app'))->where('status', '=', 'delivered')->orderBy('deliveryId', 'desc')->orderBy('created_at', 'desc')->groupBy('deliveryId')->get(array('deliveryId', 'merchantTransId', 'deliverytime')); /* $pendingan = Orderlog::where('appname','=',Config::get('jex.tracker_app')) ->where('pendingCount','!=', strval(0)) ->orderBy('created_at','desc') ->orderBy('deliveryId','desc') ->groupBy('deliveryNote') ->get(array( 'deliveryId', 'deliveryNote','status' )); */ $count = 0; $data = ''; foreach ($delivereds as $d) { $shipment = \Shipment::where('delivery_id', '=', $d->deliveryId)->first(); if ($shipment) { if (date('Y-m-d', strtotime($d->deliverytime)) != date('Y-m-d', strtotime($shipment->deliverytime))) { //print $d->deliveryId." ".$d->deliverytime." ".$shipment->deliverytime."\r\n"; $data .= '"' . $d->deliveryId . '","' . $d->merchantTransId . '","' . $d->deliverytime . '","' . $shipment->deliverytime . '"' . "\r\n"; $shipment->deliverytime = $d->deliverytime; $shipment->save(); $count++; } } } print $data; //print "\r\ndifferent date : ".$count; /* $pc = array(); foreach ($pendingan as $p) { if(isset($pc[$p->deliveryId])){ if($p->status == 'pending'){ $pc[$p->deliveryId] = $pc[$p->deliveryId] + 1; } }else{ $pc[$p->deliveryId] = 1; } } */ //print_r($pc); /* foreach($pc as $d=>$c){ //print $d->deliveryId." ".$d->deliverytime."\r\n"; $count++; $shipment = \Shipment::where('delivery_id','=',$d)->first(); if($shipment){ $shipment->pending_count = $c; //$shipment->status = 'delivered'; //$shipment->deliverytime = $d->deliverytime; //$shipment->save(); } //print_r($d->toArray()); } */ print "\r\n" . $count; }
/** * Execute the console command. * * @return mixed */ public function fire() { $shipped = Shipment::where('deliverytime', 'like', '2016-01-11%')->get(); //print_r($shipped); foreach ($shipped as $shipment) { $is_there = Geolog::where('datetimestamp', '=', $shipment->deliverytime)->where('deliveryId', '=', $shipment->delivery_id)->where('sourceSensor', '=', 'gps')->get(); if ($is_there) { print_r($is_there); $stay = array_pop($is_there->toArray()); foreach ($is_there as $there) { print 'there' . "\r\n"; print_r($there); //$there->remove(); } print 'stay' . "\r\n"; print_r($stay); if ($stay) { $stay->latitude = doubleval($shipment->latitude); $stay->longitude = doubleval($shipment->longitude); //$stay->save(); } } } /* $dbox = Orderlog::where('pickupStatus','=',Config::get('jayon.trans_status_pickup')) ->where('pickuptime','!=','0000-00-00 00:00:00') ->orderBy('created_at','desc') //->groupBy('created_at') ->get(); if($dbox){ print count($dbox)."\r\n"; foreach($dbox as $dbx){ print_r(array($dbx->pickupStatus, $dbx->pickuptime) ); $ship = Shipment::where('delivery_id','=',$dbx->deliveryId) ->where('pickuptime','!=','0000-00-00 00:00:00') ->first(); if($ship){ print 'before : '.$ship->pickup_status."\r\n"; print 'before : '.$ship->pickuptime."\r\n"; $pickuptime = ($dbx->pickuptime == '0000-00-00 00:00:00')? date('Y-m-d H:i:s', $dbx->created_at->sec ) :$dbx->pickuptime; $ship->pickup_status = $dbx->pickupStatus; $ship->pickuptime = $pickuptime; $ship->save(); //print_r( $ship->toArray()); print 'after : '.$ship->pickup_status."\r\n"; print 'after : '.$ship->pickuptime."\r\n"; } } } */ }
public function postLast() { $in = Input::get(); $orderid = trim($in['orderId']); $orderff = trim($in['orderFf']); $delivery_id = trim($in['delivery_id']); if (isset($in['delivery_id'])) { $order = Shipment::where('fulfillment_code', '=', $orderff)->where('no_sales_order', '=', $orderid)->where('delivery_id', '=', $delivery_id)->orderBy('pick_up_date', 'desc')->first(); } else { $order = Shipment::where('fulfillment_code', '=', $orderff)->where('no_sales_order', '=', $orderid)->orderBy('pick_up_date', 'desc')->first(); } $statuses = array(); if ($order) { if ($order->logistic_type == 'external') { $conf = Config::get('cs.' . $order->consignee_olshop_cust); if (!isset($conf['status'])) { $conf = Config::get('cs.default'); } $mdl = Threeplstatuses::where($conf['awb'], '=', strval($order->{$conf['order_awb']}))->where(function ($q) use($order) { $q->where('consignee_olshop_cust', '=', strval($order->consignee_olshop_cust))->orWhere('consignee_logistic_id', '=', strval($order->consignee_olshop_cust)); }); if (count($conf['group']) > 0) { foreach ($conf['group'] as $g) { $mdl = $mdl->groupBy($g); } } $mdl = $mdl->orderBy($conf['order'], 'desc'); if ($conf['status'] == 'single') { //$statuses = $mdl->take(1)->timeout(-1)->get(); $statuses = $mdl->timeout(-1)->first(); } else { if (count($conf['get']) > 0) { $statuses = $mdl->timeout(-1)->get($conf['get']); } else { $statuses = $mdl->timeout(-1)->get(); } } if ($statuses) { $statuses = $statuses->toArray(); } else { $statuses = array(); } //print_r($statuses); } $order->picList = $this->picList($order); } return View::make('cs.lastdetail')->with('order', $order)->with('status', $statuses)->render(); }
/** * Execute the console command. * * @return mixed */ public function fire() { $count = Shipment::where('consignee_olshop_cust', '=', '1400000655')->where('logistic_status', 'regexp', '/^DELIVERED/i')->where('status', '!=', 'delivered')->count(); print $count; $orders = Shipment::where('consignee_olshop_cust', '=', '1400000655')->where('logistic_status', 'regexp', '/^DELIVERED/i')->where('status', '!=', 'delivered')->get(); foreach ($orders as $ord) { //print_r($ord->toArray()); $lstat = $ord->logistic_raw_status; //print_r($lstat); $ord->status = 'delivered'; $ord->delivered_time = $lstat['delivered_date'] . ' ' . $lstat['delivered_time']; print $ord->delivered_time . ' ' . $ord->status . "\r\n"; //$ord->save(); } $fl_status = Shipment::distinct('logistic_status')->where('logistic', '=', 'FL')->get(); print_r($fl_status->toArray()); // }
/** * Execute the console command. * * @return mixed */ public function fire() { $orders = Shipment::where('buyerdeliveryzone', '=', '')->orderBy('created', 'desc')->get(); if ($orders) { $cities = array(); foreach ($orders as $order) { $cities[] = $order->buyerdeliverycity; } $cities = array_unique($cities); $districts = Coverage::whereIn('city', $cities)->get(); $district_list = array(); foreach ($districts as $d) { $district_list[$d->city][] = $d->district; if (strpos($d->city, 'Jakarta')) { $district['Jakarta'][] = $d->district; } } //print_r($district_list); $matches = 0; foreach ($orders as $order) { print $order->delivery_id . ' ' . $order->buyerdeliverycity . ' ' . $order->buyerdeliveryzone . "\r\n"; if (isset($district_list[$order->buyerdeliverycity])) { $cd = $district_list[$order->buyerdeliverycity]; print_r($cd); foreach ($cd as $d) { if (preg_match('/' . $d . '/i', $order->shipping_address)) { print $d . ' ================' . "\r\n"; print 'match ' . $d . ' for ' . $order->delivery_id . ' ' . $order->shipping_address; print "\r\n"; $order->buyerdeliveryzone = $d; $order->save(); $matches++; } # code... } } } print 'found ' . $matches . ' matches'; } else { print 'nothing to fill in'; } }
/** * Display a listing of the resource. * * @return Response */ public function index() { $key = Input::get('key'); $order_id = Input::get('orderid'); $ff_id = Input::get('ffid'); 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) { if ($order_id != '' && $ff_id != '') { $order = \Shipment::where('merchant_trans_id', '=', trim($order_id))->where('fulfillment_code', '=', trim($ff_id))->where('application_key', '=', trim($key))->first(); } else { if ($order_id != '' && $ff_id == '') { $order = \Shipment::where('merchant_trans_id', '=', trim($order_id))->where('application_key', '=', trim($key))->first(); } else { $order = false; } } if ($order) { //print_r($order); $actor = 'merchant id :' . $app->merchant_id; \Event::fire('log.api', array($this->controller_name, 'post', $actor, 'awb ' . $order->delivery_id)); return \Response::json(array('status' => 'OK', 'awb' => $order->delivery_id, 'timestamp' => date('Y-m-d H:i:s', time()), 'pending' => $order->pending_count, 'order_status' => $order->status, 'note' => $order->delivery_note)); } else { $actor = 'merchant id :' . $app->merchant_id; \Event::fire('log.api', array($this->controller_name, 'post', $actor, 'order not found')); return \Response::json(array('status' => 'ERR:NOTFOUND', 'timestamp' => time(), 'message' => 'Record Not Found')); } } 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')); } // }
/** * Execute the console command. * * @return mixed */ public function fire() { $logistic_id = 'CGKN00027'; $logistic = Logistic::where('consignee_olshop_cust', '=', $logistic_id)->first(); if (Prefs::isRunning($this->name)) { $l = array(); $l['ts'] = new MongoDate(); $l['error'] = 'process already running'; $l['consignee_logistic_id'] = $logistic->logistic_code; $l['consignee_olshop_cust'] = $logistic_id; Threeplstatuserror::insert($l); die('process already running'); } $orders = Shipment::where('awb', '!=', '')->where('bucket', '=', Config::get('jayon.bucket_tracker'))->where(function ($sq) { $sq->where('status', '!=', 'delivered')->where('status', '!=', 'undelivered')->where('status', '!=', 'canceled')->where('status', '!=', 'returned'); })->where('logistic_type', '=', 'external')->where('consignee_olshop_cust', '=', $logistic_id)->get(); $res = array(); print 'count ' . count($orders->toArray()); if ($orders && count($orders->toArray()) > 0) { $req = array(); foreach ($orders as $ord) { //$req[] = array('order_id'=>$ord->no_sales_order.'-'.$ord->consignee_olshop_orderid,'awb'=>$ord->awb); $req[] = array('order_id' => $ord->consignee_olshop_orderid, 'awb' => $ord->consignee_olshop_orderid); } $client = new GuzzleClient(); //TO DO : Send data in chunk $reqchunks = array_chunk($req, 100); foreach ($reqchunks as $rq) { $this->sendData($rq, $client, $logistic, $logistic_id); } } else { print 'Empty order list' . "\r\n"; } $actor = $this->name; Event::fire('log.api', array('JayaStatusDaemon', 'get', $actor, 'JAYA STATUS PULL')); }
public function postShipmentlist() { $in = Input::get(); $city = $in['city']; $date = $in['date']; $pick_up_date = new MongoDate(strtotime($date)); $shipments = Shipment::where('pick_up_date', '=', $pick_up_date)->where('status', '=', Config::get('jayon.trans_status_admin_dated'))->where('consignee_olshop_city', '=', $city)->get(); $shipments = $shipments->toArray(); for ($i = 0; $i < count($shipments); $i++) { $shipments[$i]['pick_up_date'] = date('Y-m-d', $shipments[$i]['pick_up_date']->sec); } $city = trim($city); $devices = Device::where('city', 'regex', new MongoRegex('/' . $city . '/i'))->where(function ($on) { $on->where('is_on', '=', 1)->orWhere('is_on', '=', strval(1)); })->get(); $caps = array(); foreach ($devices as $d) { $caps[$d->key]['identifier'] = $d->identifier; $caps[$d->key]['key'] = $d->key; $caps[$d->key]['city'] = $d->city; $caps[$d->key]['count'] = Shipment::where('device_key', $d->key)->where('pick_up_date', $pick_up_date)->count(); } return Response::json(array('result' => 'OK', 'shipment' => $shipments, 'device' => $caps)); //print_r($caps); }
public function dupeFF($data) { $count = Shipment::where('consignee_olshop_orderid', '=', $data['consignee_olshop_orderid'])->count(); $ccount = 0; if ($count > 1) { $ccount = Shipment::where('consignee_olshop_orderid', '=', $data['consignee_olshop_orderid'])->where('status', '=', Config::get('jayon.trans_status_canceled'))->count(); return '<span class="red">' . $data['consignee_olshop_orderid'] . '</span>' . '<div class="badge pull-right">' . ($count - 1) . ' dup.</div>' . '<div class="badge pull-right">' . $ccount . ' canceled</div>'; } else { return $data['consignee_olshop_orderid']; } }
/** * 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); }
/** * Display a listing of the resource. * * @return Response */ public function index() { date_default_timezone_set('Asia/Jakarta'); $key = Input::get('key'); $order_id = Input::get('orderid'); $ff_id = Input::get('ffid'); $is_dev = Input::get('dev'); if (is_null($is_dev) || $is_dev == '') { $is_dev = 0; } if (is_null($key) || $key == '' || $key != $this->g21_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')); } $date_from = Input::get('from'); $date_to = Input::get('to'); if (is_null($date_from) || $date_from == '') { $date_from = new \MongoDate(strtotime(date('Y-m-d', time()) . ' 00:00:00')); } else { $date_from = new \MongoDate(strtotime($date_from . ' 00:00:00')); } if (is_null($date_to) || $date_to == '') { $date_to = new \MongoDate(strtotime(date('Y-m-d', time()) . ' 23:59:59')); } else { $date_to = new \MongoDate(strtotime($date_to . ' 23:59:59')); } //$logistic = \Logistic::where('api_key','=',$key)->first(); $logistic = \Logistic::where('consignee_olshop_cust', '=', $this->g21_id)->first(); $logistic_id = $logistic->consignee_olshop_cust; $orders = \Shipment::where('awb', '!=', '')->where('logistic_type', '=', 'external')->where('consignee_olshop_cust', '=', $logistic_id)->where(function ($q) { $q->where('status', '=', \Config::get('jayon.trans_status_admin_dated'))->orWhere('status', '=', \Config::get('jayon.trans_status_confirmed')); })->where(function ($qd) use($date_from, $date_to) { $qd->whereBetween('pick_up_date', array($date_from, $date_to)); })->where(function ($q) { $q->where('uploaded', '!=', 1)->orWhere('uploaded', 'exists', false); })->get(); $orderres = clone $orders; $orders = $orders->toArray(); $orderlist = array(); for ($n = 0; $n < count($orders); $n++) { $o = $orders[$n]; $entry = array(); $entry['awb'] = $o['awb']; $entry['remark'] = '-'; if (isset($o['consignee_olshop_addr'])) { $con_address = str_replace(array("\r", "\n"), ' ', $o['consignee_olshop_addr']); } else { $con_address = ''; } $consignee = array('cn_name' => $o['consignee_olshop_name'], 'address' => $con_address, 'district' => $o['district'], 'city' => $o['consignee_olshop_city'], 'province' => $o['consignee_olshop_region'], 'country' => $o['consignee_olshop_region'], 'phone' => $o['consignee_olshop_phone']); $insurance = 'NO'; if (isset($o['consignee_olshop_inst_amt'])) { if ($o['consignee_olshop_inst_amt'] == '' || is_null($o['consignee_olshop_inst_amt'])) { $insurance = 'NO'; } else { $insurance = 'YES'; } } //if($o['pick_up_date'] instanceOf MongoDate){ $pickupdate = date('Y-m-d', $o['pick_up_date']->sec); //}else{ // $pickupdate = $o['pick_up_date']; //} $o['cod'] = isset($o['cod']) ? $o['cod'] : 0; $order = array('orderid' => $o['no_sales_order'] . '-' . $o['fulfillment_code'], 'actweight' => $o['w_v'], 'pieces' => $o['number_of_package'], 'items' => array('itemname' => $o['consignee_olshop_desc']), 'goodsval' => $o['cod'], 'insurance' => $insurance, 'cod' => $o['cod'] == 0 ? '0' : '1', 'pickupdate' => $pickupdate, 'service' => $o['consignee_olshop_service']); $shipper = array('merchant' => 'Bilna.com', 'merchant_address' => 'Kawasan Pergudangan PT. WIDYA SAKTI KUSUMA Jl. Raya Bekasi KM 28 ( Jl. Wahab Affan ) Pondok Ungu, Medan Satria, Bekasi 17132', 'merchant_district' => 'Medan Satria', 'merchant_city' => 'Bekasi', 'merchant_province' => 'Jawa Barat', 'merchant_country' => 'Indonesia', 'merchant_phone' => '02129022132', 'merchant_contact' => 'Bilna CS'); $entry['consignee'] = $consignee; $entry['order'] = $order; $entry['shipper'] = $shipper; $orderlist[] = $entry; } if ($is_dev != 1) { foreach ($orderres as $ord) { $ord->uploaded = 1; $ord->save(); } } $reslog = $orderlist; $reslog['timestamp'] = new \MongoDate(); $reslog['consignee_logistic_id'] = $logistic->logistic_code; $reslog['consignee_olshop_cust'] = $logistic->consignee_olshop_cust; \Threepluploadlog::insert($reslog); $actor = $key; \Event::fire('log.api', array($this->controller_name, 'get', $actor, 'G21 PULL DATA')); return $orderlist; // }
public function getEffDates($year, $week) { $model = new Shipment(); $start = $model->where(DB::raw('year(ordertime)'), '=', $year)->where(DB::raw('weekofyear(ordertime)'), '=', $week)->min(DB::raw('date(ordertime)')); $end = $model->where(DB::raw('year(ordertime)'), '=', $year)->where(DB::raw('weekofyear(ordertime)'), '=', $week)->max(DB::raw('date(ordertime)')); return array($start, $end); }
/** * Execute the console command. * * @return mixed */ public function fire() { //$base_url = 'http://localhost/jexadmin/public/api/v1/service/status'; $base_url = 'http://api.sap-express.com/api/tracking/list/ref/'; //$base_url = 'http://182.23.64.151/serverapi.sap/api/tracking/list/id/'; $base_url = 'http://api.sap-express.com/api/tracking/list'; $logistic_id = 'CGKN00284'; $delivery_trigger = 'DELIVERED'; $returned_trigger = 'UNDELIVERED'; $logistic = Logistic::where('consignee_olshop_cust', '=', $logistic_id)->first(); if (Prefs::isRunning($this->name)) { $l = array(); $l['ts'] = new MongoDate(); $l['error'] = 'process already running'; $l['consignee_logistic_id'] = $logistic->logistic_code; $l['consignee_olshop_cust'] = $logistic_id; Threeplstatuserror::insert($l); die('process already running'); } $orders = Shipment::where('awb', '!=', '')->where('bucket', '=', Config::get('jayon.bucket_tracker'))->where(function ($sq) { $sq->where('status', '!=', 'delivered')->where('status', '!=', 'undelivered')->where('status', '!=', 'canceled')->where('status', '!=', 'returned'); })->where('logistic_type', '=', 'external')->where('consignee_olshop_cust', '=', $logistic_id)->get(); if ($orders && count($orders->toArray()) > 0) { $req = array(); foreach ($orders as $ord) { //$req[] = array('awb'=>$ord->awb); //$client = new GuzzleClient(); //$request = $client->get($url, array()); //$request->setAuth('sapclientapi', 'SAPCLIENTAPI_2014'); //$response = $request->send(); //print $response->getBody(); //$url = $base_url.$ord->consignee_olshop_orderid; $username = '******'; $password = '******'; $url = $base_url . '?ref=' . $ord->consignee_olshop_orderid; print $url; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERPWD, "{$username}:{$password}"); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); //$result = curl_exec($ch); if (!($result = curl_exec($ch))) { die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch)); } $status_code = curl_getinfo($ch); //get status code //$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //get status code curl_close($ch); //print $result; $res = json_decode($result, true); $reslog = $res; $reslog['timestamp'] = new MongoDate(); $reslog['consignee_logistic_id'] = $logistic->logistic_code; $reslog['consignee_olshop_cust'] = $logistic_id; Threeplstatuslog::insert($reslog); print_r($res); if (isset($res['cn_no'])) { $pre = clone $ord; $ls = $res['laststatus']; if ($ls['status'] == $delivery_trigger) { $ord->status = Config::get('jayon.trans_status_mobile_delivered'); $ord->position = 'CUSTOMER'; } if ($ls['status'] == $returned_trigger) { $ord->status = Config::get('jayon.trans_status_mobile_return'); } //$ord->district = $ls->district; $ord->logistic_status = $ls['status']; $ord->logistic_status_ts = $ls['time']; $ord->logistic_raw_status = $ls; $ord->save(); $ts = new MongoDate(); $hdata = array(); $hdata['historyTimestamp'] = $ts; $hdata['historyAction'] = 'api_shipment_change_status'; $hdata['historySequence'] = 1; $hdata['historyObjectType'] = 'shipment'; $hdata['historyObject'] = $ord->toArray(); $hdata['actor'] = $this->name; $hdata['actor_id'] = ''; //History::insert($hdata); $sdata = array(); $sdata['timestamp'] = $ts; $sdata['action'] = 'api_shipment_change_status'; $sdata['reason'] = 'api_update'; $sdata['objectType'] = 'shipment'; $sdata['object'] = $ord->toArray(); $sdata['preObject'] = $pre->toArray(); $sdata['actor'] = $this->name; $sdata['actor_id'] = ''; Shipmentlog::insert($sdata); $this->saveStatus($res, $logistic->logistic_code, $logistic_id); } Logger::api($this->name, $ord->consignee_olshop_orderid, $res); } /* $awblist = json_decode($response->getBody()); $awbs = array(); $ffs = array(); foreach ($awblist as $awb) { $awbarray[] = trim($awb->awb); $awbs[$awb->awb] = $awb; } $orderlist = Shipment::whereIn('awb', $awbarray)->get(); foreach($orderlist as $order){ $pre = clone $order; if( $awbs[$order->awb]->status == $delivery_trigger){ $order->status = Config::get('jayon.trans_status_mobile_delivered'); $order->position = 'CUSTOMER'; } if($awbs[$order->awb]->status == $returned_trigger){ $order->status = Config::get('jayon.trans_status_mobile_return'); } $order->district = $awbs[$order->awb]->district; $order->logistic_status = $awbs[$order->awb]->status; $order->logistic_status_ts = $awbs[$order->awb]->timestamp; $order->logistic_raw_status = $awbs[$order->awb]; $order->save(); $ts = new MongoDate(); $hdata = array(); $hdata['historyTimestamp'] = $ts; $hdata['historyAction'] = 'api_shipment_change_status'; $hdata['historySequence'] = 1; $hdata['historyObjectType'] = 'shipment'; $hdata['historyObject'] = $order->toArray(); $hdata['actor'] = $this->name; $hdata['actor_id'] = ''; History::insert($hdata); $sdata = array(); $sdata['timestamp'] = $ts; $sdata['action'] = 'api_shipment_change_status'; $sdata['reason'] = 'api_update'; $sdata['objectType'] = 'shipment'; $sdata['object'] = $order->toArray(); $sdata['preObject'] = $pre->toArray(); $sdata['actor'] = $this->name; $sdata['actor_id'] = ''; Shipmentlog::insert($sdata); } */ } else { print 'Empty order list' . "\r\n"; } $actor = $this->name; Event::fire('log.api', array('SapStatusDaemon', 'get', $actor, 'SAP STATUS PULL')); }
public function postAssigncourier() { //courier_name:Shia Le Beouf //courier_id:5605512bccae5b64010041b6 //device_key:0f56deadbc6df60740ef5e2c576876b0e3310f7d //device_name:JY-002 //pickup_date:28-09-2 $in = Input::get(); $pickup_date = new MongoDate(strtotime($in['pickup_date'])); $shipments = Shipment::where('device_key', '=', $in['device_key'])->where('pick_up_date', '=', $pickup_date)->where('status', '=', Config::get('jayon.trans_status_admin_zoned'))->get(); //print_r($shipments->toArray()); $ts = new MongoDate(); foreach ($shipments as $sh) { $pre = clone $sh; $sh->bucket = Config::get('jayon.bucket_tracker'); $sh->status = Config::get('jayon.trans_status_admin_courierassigned'); $sh->courier_id = $in['courier_id']; $sh->courier_name = $in['courier_name']; $sh->save(); $hdata = array(); $hdata['historyTimestamp'] = $ts; $hdata['historyAction'] = 'assign_courier'; $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'] = 'assign_courier'; $sdata['reason'] = 'initial'; $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); //print_r($sh); } return Response::json(array('result' => 'OK', 'shipment' => $shipments)); }
/** * Display a listing of the resource. * * @return Response */ public function index() { date_default_timezone_set('Asia/Jakarta'); $key = Input::get('key'); $order_id = Input::get('orderid'); $ff_id = Input::get('ffid'); $is_dev = Input::get('dev'); if (is_null($is_dev) || $is_dev == '') { $is_dev = 0; } 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')); } $logistic = \Logistic::where('api_key', '=', $key)->first(); $logistic_id = $logistic->consignee_olshop_cust; $orders = \Shipment::where('awb', '!=', '')->where('logistic_type', '=', 'external')->where('status', '=', \Config::get('jayon.trans_status_admin_dated'))->where('consignee_olshop_cust', '=', $logistic_id)->where(function ($q) { $q->where('uploaded', '!=', 1)->orWhere('uploaded', 'exists', false); })->get(); $orderres = clone $orders; $orders = $orders->toArray(); $orderlist = array(); for ($n = 0; $n < count($orders); $n++) { $o = $orders[$n]; $entry = array(); $entry['hawb'] = $o['awb']; $entry['remark'] = '-'; $consignee = array('cn_name' => $o['consignee_olshop_name'], 'address' => str_replace(array("\r", "\n"), ' ', $o['consignee_olshop_addr']), 'distric' => $o['district'], 'city' => $o['consignee_olshop_city'], 'province' => $o['consignee_olshop_region'], 'country' => $o['consignee_olshop_region'], 'phone' => $o['consignee_olshop_phone']); $insurance = 'NO'; if (isset($o['consignee_olshop_inst_amt'])) { if ($o['consignee_olshop_inst_amt'] == '' || is_null($o['consignee_olshop_inst_amt'])) { $insurance = 'NO'; } else { $insurance = 'YES'; } } //if($o['pick_up_date'] instanceOf MongoDate){ $pickupdate = date('Y-m-d', $o['pick_up_date']->sec); //}else{ // $pickupdate = $o['pick_up_date']; //} $o['cod'] = isset($o['cod']) ? $o['cod'] : 0; $order = array('orderid' => $o['no_sales_order'] . '-' . $o['fulfillment_code'], 'actweight' => '0', 'pieces' => $o['number_of_package'], 'items' => array('itemname' => $o['consignee_olshop_desc']), 'goodsval' => $o['cod'], 'assoption' => $insurance, 'cod' => $o['cod'] == 0 ? '0' : '1', 'pubrate' => '0', 'pickupdate' => $pickupdate, 'service' => $o['consignee_olshop_service']); $shipper = array('merchant' => 'Bilna.com', 'merchant_address' => 'Kawasan Pergudangan PT. WIDYA SAKTI KUSUMA Jl. Raya Bekasi KM 28 ( Jl. Wahab Affan ) Pondok Ungu, Medan Satria, Bekasi 17132', 'merchant_distric' => 'Medan Satria', 'merchant_city' => 'Bekasi', 'merchant_province' => 'Jawa Barat', 'merchant_country' => 'Indonesia', 'merchant_phone' => '02129022132', 'merchant_contact' => 'Bilna CS'); $entry['consignee'] = $consignee; $entry['order'] = $order; $entry['shipper'] = $shipper; /* array ( '_id' => new MongoId("564c5dedccae5b110f0041f7"), 'awb' => '007735-17-112015-00146067', 'bucket' => 'tracker', 'cod' => 127000, 'consignee_olshop_addr' => 'bagus sulaiman jl.bakti rt.004 rw.008 no.10b cililitan kramatjati 13640 Jakarta Timur JK 13640 Indonesia', 'consignee_olshop_city' => 'Jakarta Timur', 'consignee_olshop_cust' => '7735', 'consignee_olshop_desc' => 'Susu dan Perlengkapan Bayi', 'consignee_olshop_name' => '106191 bagus sulaiman', 'consignee_olshop_orderid' => '334975', 'consignee_olshop_phone' => '81317857612', 'consignee_olshop_region' => 'JK', 'consignee_olshop_service' => 'COD', 'consignee_olshop_zip' => '13640', 'contact' => '106191 bagus sulaiman', 'courier_id' => '', 'courier_name' => '', 'courier_status' => 'at_initial_node', 'createdDate' => new MongoDate(1447845357, 699000), 'created_at' => '2015-11-18 18:15:20', 'delivery_id' => '18-112015-JEJVV', 'delivery_type' => 'REG', 'device_id' => '', 'device_key' => '', 'device_name' => '', 'district' => '', 'email' => '*****@*****.**', 'fulfillment_code' => '334975', 'lastUpdate' => new MongoDate(1447845357, 699000), 'logistic' => 'JEX', 'logistic_raw_status' => array ( 'awb' => '007735-17-112015-00146067', 'timestamp' => '2015-11-19 11:18:23', 'pending' => '0', 'status' => 'delivered', 'note' => 'iwan 12.05', ), 'logistic_status' => 'delivered', 'logistic_status_ts' => '2015-11-19 11:18:23', 'logistic_type' => 'external', 'no_sales_order' => '100364363', 'number_of_package' => '1', 'order_id' => '100364363', 'pending_count' => new MongoInt64(0), 'pick_up_date' => new MongoDate(1447952400, 0), 'pickup_status' => 'to_be_picked_up', 'position' => 'CUSTOMER', 'status' => 'delivered', 'trip' => new MongoInt64(1), 'updated_at' => new MongoDate(1447931897, 898000), 'w_v' => '0.9', 'warehouse_status' => 'at_initial_node', ) */ $orderlist[] = $entry; } if ($is_dev != 1) { foreach ($orderres as $ord) { $ord->uploaded = 1; $ord->save(); } } $actor = $key; \Event::fire('log.api', array($this->controller_name, 'get', $actor, 'FL PULL DATA')); return $orderlist; // }
public function dupeFF($data) { $count = Shipment::where('consignee_olshop_orderid', '=', $data['consignee_olshop_orderid'])->where('status', '!=', Config::get('jayon.trans_status_canceled'))->count(); if ($count > 1) { return '<span class="red">' . $data['consignee_olshop_orderid'] . '</span>'; } else { return $data['consignee_olshop_orderid']; } }
/** * Execute the console command. * * @return mixed */ public function fire() { $wsdl = "http://api.rpxholding.com/wsdl/rpxwsdl.php?wsdl"; //$client = new SoapClient($wsdl); $username = '******'; $password = '******'; SoapWrapper::add(function ($service) use($wsdl, $username, $password) { $service->name('trackAWB')->wsdl($wsdl)->trace(true)->cache(WSDL_CACHE_NONE); // Optional: Set the WSDL cache //->options(['user' => $username, 'password' => $password, 'format'=>'JSON' ]); // Optional: Set some extra options }); $logistic_id = 'B234-JKT'; $delivery_trigger = 'DELIVERED'; $returned_trigger = 'UNDELIVERED'; $logistic = Logistic::where('consignee_olshop_cust', '=', $logistic_id)->first(); $orders = Shipment::where('awb', '!=', '')->where('bucket', '=', Config::get('jayon.bucket_tracker'))->where('status', '!=', 'delivered')->where('logistic_type', '=', 'external')->where('consignee_olshop_cust', '=', $logistic_id)->get(); if ($orders && count($orders->toArray()) > 0) { $req = array(); foreach ($orders as $ord) { $username = $logistic->api_user; $password = $logistic->api_pass; $data = [$username, $password, '8979867812376', 'JSON']; //string $user, string $password, string $awb, string $format SoapWrapper::service('trackAWB', function ($service) use($data) { var_dump($service->getFunctions()); print $service->call('getTrackingAWB', $data); //print_r($service->call('getTrackingAWB', [$data])); }); $res = json_decode($result, true); $reslog = $res; $reslog['timestamp'] = new MongoDate(); $reslog['consignee_logistic_id'] = $logistic->logistic_code; $reslog['consignee_olshop_cust'] = $logistic_id; Threeplstatuslog::insert($reslog); print_r($res); if (isset($res['cn_no'])) { $pre = clone $ord; $ls = $res['laststatus']; if ($ls['status'] == $delivery_trigger) { $ord->status = Config::get('jayon.trans_status_mobile_delivered'); $ord->position = 'CUSTOMER'; } if ($ls['status'] == $returned_trigger) { $ord->status = Config::get('jayon.trans_status_mobile_return'); } //$ord->district = $ls->district; $ord->logistic_status = $ls['status']; $ord->logistic_status_ts = $ls['time']; $ord->logistic_raw_status = $ls; $ord->save(); $ts = new MongoDate(); $hdata = array(); $hdata['historyTimestamp'] = $ts; $hdata['historyAction'] = 'api_shipment_change_status'; $hdata['historySequence'] = 1; $hdata['historyObjectType'] = 'shipment'; $hdata['historyObject'] = $ord->toArray(); $hdata['actor'] = $this->name; $hdata['actor_id'] = ''; History::insert($hdata); $sdata = array(); $sdata['timestamp'] = $ts; $sdata['action'] = 'api_shipment_change_status'; $sdata['reason'] = 'api_update'; $sdata['objectType'] = 'shipment'; $sdata['object'] = $ord->toArray(); $sdata['preObject'] = $pre->toArray(); $sdata['actor'] = $this->name; $sdata['actor_id'] = ''; Shipmentlog::insert($sdata); $this->saveStatus($res, $logistic->logistic_code, $logistic_id); } } } else { print 'Empty order list' . "\r\n"; } $actor = $this->name; Event::fire('log.api', array('RPXStatusDaemon', 'get', $actor, 'RPX STATUS PULL')); // }
/** * Execute the console command. * * @return mixed */ public function fire() { $logistic_id = '3758'; $delivery_trigger = $this->kjktstatus['DELIVERED']; $returned_trigger = $this->kjktstatus['RETURNED']; $undelivered_trigger = $this->kjktstatus['UNDELIVERED']; $logistic = Logistic::where('consignee_olshop_cust', '=', $logistic_id)->first(); if (Prefs::isRunning($this->name)) { $l = array(); $l['ts'] = new MongoDate(); $l['error'] = 'process already running'; $l['consignee_logistic_id'] = $logistic->logistic_code; $l['consignee_olshop_cust'] = $logistic_id; Threeplstatuserror::insert($l); die('process already running'); } if ($logistic) { } else { die('logistic data not found'); } $orders = Shipment::where('awb', '!=', '')->where('bucket', '=', Config::get('jayon.bucket_tracker'))->where(function ($sq) { $sq->where('status', '!=', 'delivered')->where('status', '!=', 'canceled')->where('status', '!=', 'undelivered')->where('status', '!=', 'returned'); })->where('logistic_type', '=', 'external')->where('consignee_olshop_cust', '=', $logistic_id)->get(); if ($orders && count($orders->toArray()) > 0) { $req = array(); foreach ($orders as $ord) { $result = $this->sendRequest($ord->awb, $logistic); $res = json_decode($result, true); $reslog = $res; $reslog['timestamp'] = new MongoDate(); $reslog['consignee_logistic_id'] = $logistic->logistic_code; $reslog['consignee_olshop_cust'] = $logistic_id; Threeplstatuslog::insert($reslog); print_r($res); if (isset($res['result_code']) && $res['result_code'] == 1) { $ord = Shipment::where('awb', '=', $res['data']['order_no'])->orderBy('created_at', 'desc')->first(); if ($ord) { $pre = clone $ord; $laststat = $res['data']; $lst = intval(trim($laststat['status_code'])); if (in_array($lst, $delivery_trigger)) { $ord->status = \Config::get('jayon.trans_status_mobile_delivered'); $ord->position = 'CUSTOMER'; } if (in_array($lst, $returned_trigger)) { $ord->status = \Config::get('jayon.trans_status_mobile_return'); } /* if( in_array( $lst , $undelivered_trigger) ){ $ord->status = \Config::get('jayon.trans_status_undelivered'); } */ //$ord->district = $ls->district; $ord->logistic_status = $laststat['status_description']; $ord->logistic_status_ts = date('Y-m-d H:i:s', time()); $ord->logistic_raw_status = $laststat; $ord->save(); $ts = new MongoDate(); $hdata = array(); $hdata['historyTimestamp'] = $ts; $hdata['historyAction'] = 'api_shipment_change_status'; $hdata['historySequence'] = 1; $hdata['historyObjectType'] = 'shipment'; $hdata['historyObject'] = $ord->toArray(); $hdata['actor'] = $this->name; $hdata['actor_id'] = ''; //History::insert($hdata); $sdata = array(); $sdata['timestamp'] = $ts; $sdata['action'] = 'api_shipment_change_status'; $sdata['reason'] = 'api_update'; $sdata['objectType'] = 'shipment'; $sdata['object'] = $ord->toArray(); $sdata['preObject'] = $pre->toArray(); $sdata['actor'] = $this->name; $sdata['actor_id'] = ''; Shipmentlog::insert($sdata); $this->saveStatus($res, $logistic->logistic_code, $logistic_id); } } Logger::api($this->name, $ord->awb, $res); } } else { print 'Empty order list' . "\r\n"; } $actor = $this->name; Event::fire('log.api', array('KurirJKTStatusDaemon', 'get', $actor, 'KurirJKT STATUS PULL')); /* Array ( [result_code] => 1 [result_description] => success [data] => Array ( [order_no] => 2240 [order_date] => 2015-02-27 09:19:37 [service_name] => SAME DAY SERVICE [status_code] => 3 [status_description] => Terkirim [pickup_date] => 2015-02-27 00:00:00 [delivered_date] => 2015-02-27 12:45:00 [pickup_name] => Ibu Mei [pickup_addess] => RS Siloam Hospital Kebon Jeruk, Lt. 1 Medical Checkup, Jl. Raya Perjuangan Kav. 8 Kebon Jeruk Jakarta Barat DKI Jakarta No. Ponsel: 085713331787 No. Kantor/Rumah: 02153695676 [destionation_name] => Ibu Stiyati [destionation_addess] => AIA Financial Menara Falma Lt. 18, Jl. HR Rasuna Said Blok X-2 Kav. 6 Jakarta Selatan DKI Jakarta No. Ponsel: No. Kantor/Rumah: [recipient_name] => bayu [kurir_name] => Fachrul [kurir_longitude] => [kurir_latitude] => [last_update] => 2015-02-27 12:45:00 ) ) */ }
/** * Execute the console command. * * @return mixed */ public function fire() { //$base_url = 'http://localhost/jexadmin/public/api/v1/service/status'; $base_url = 'http://www.jayonexpress.com/jexadmin/api/v1/service/status'; $logistic_id = '7735'; $delivery_trigger = 'delivered'; $returned_trigger = 'returned'; $canceled_trigger = 'canceled'; $logistic = Logistic::where('consignee_olshop_cust', '=', $logistic_id)->first(); $orders = Shipment::where('awb', '!=', '')->where('bucket', '=', Config::get('jayon.bucket_tracker'))->where('status', '!=', 'delivered')->where('logistic_type', '=', 'external')->where('consignee_olshop_cust', '=', $logistic_id)->get(); if ($orders && count($orders->toArray()) > 0) { $req = array(); foreach ($orders as $ord) { $req[] = array('awb' => $ord->awb); } $req[] = array('awb' => '007735-16-122015-00155749'); $client = new GuzzleClient(); $response = $client->request('POST', $base_url, array('json' => $req, 'query' => array('key' => $logistic->api_key))); //print( $response->getBody() ); $awblist = json_decode($response->getBody()); $reslog = $awblist; $reslog['consignee_logistic_id'] = $logistic->logistic_code; $reslog['consignee_olshop_cust'] = $logistic_id; Threeplstatuslog::insert($reslog); $this->saveStatus($awblist, $logistic->logistic_code, $logistic_id); $awbs = array(); $ffs = array(); foreach ($awblist as $awb) { $awbarray[] = trim($awb->awb); $awbs[$awb->awb] = $awb; } print_r($awbs); $orderlist = Shipment::whereIn('awb', $awbarray)->get(); foreach ($orderlist as $order) { $pre = clone $order; if ($awbs[$order->awb]->status == $delivery_trigger) { $order->status = Config::get('jayon.trans_status_mobile_delivered'); $order->delivered_time = $awbs[$order->awb]->delivery_time; $order->position = 'CUSTOMER'; } if ($awbs[$order->awb]->status == $returned_trigger) { $order->status = Config::get('jayon.trans_status_mobile_return'); } if ($awbs[$order->awb]->status == $canceled_trigger) { $order->status = Config::get('jayon.trans_status_canceled'); } $order->district = $awbs[$order->awb]->district; $order->logistic_status = $awbs[$order->awb]->status; $order->logistic_status_ts = $awbs[$order->awb]->timestamp; $order->logistic_raw_status = $awbs[$order->awb]; $order->logistic_delivered_time = $awbs[$order->awb]->delivery_time; $order->logistic_pickup_time = $awbs[$order->awb]->pickup_time; $order->logistic_last_note = $awbs[$order->awb]->note; $order->save(); $ts = new MongoDate(); $hdata = array(); $hdata['historyTimestamp'] = $ts; $hdata['historyAction'] = 'api_shipment_change_status'; $hdata['historySequence'] = 1; $hdata['historyObjectType'] = 'shipment'; $hdata['historyObject'] = $order->toArray(); $hdata['actor'] = $this->name; $hdata['actor_id'] = ''; //History::insert($hdata); $sdata = array(); $sdata['timestamp'] = $ts; $sdata['action'] = 'api_shipment_change_status'; $sdata['reason'] = 'api_update'; $sdata['objectType'] = 'shipment'; $sdata['object'] = $order->toArray(); $sdata['preObject'] = $pre->toArray(); $sdata['actor'] = $this->name; $sdata['actor_id'] = ''; Shipmentlog::insert($sdata); } Logger::api($this->name, $req, $awblist); } else { print 'Empty order list' . "\r\n"; } $actor = $this->name; Event::fire('log.api', array('JexStatusDaemon', 'get', $actor, 'JEX STATUS PULL')); }
/** * Execute the console command. * * @return mixed */ public function fire() { date_default_timezone_set('Asia/Jakarta'); //$base_url = 'http://103.14.21.47:8579/sp_sap2.gvm'; // XML $base_url = 'http://103.14.21.47:8579/sp_sap_json.gvm'; // JSON //$base_url = 'https://103.14.21.47:8879/sp_sap.gvm'; //$base_url = 'http://localhost/jexadmin/public/api/v1/service/awb'; $logistic_id = 'CGKN00284'; $logistic = Logistic::where('consignee_olshop_cust', '=', $logistic_id)->first(); $orders = Shipment::where('awb', '=', '')->where('logistic_type', '=', 'external')->where('status', '=', Config::get('jayon.trans_status_admin_dated'))->where('consignee_olshop_cust', '=', $logistic_id)->get(); if ($orders && count($orders->toArray()) > 0) { $req = array(); foreach ($orders as $ord) { $req = array('orderid' => $ord->consignee_olshop_orderid, 'awb' => 0, 'invoice' => $ord->no_sales_order, 'address' => str_replace(array("\r", "\n"), ' ', $ord->consignee_olshop_addr), 'name' => $ord->consignee_olshop_name, 'province' => $ord->consignee_olshop_province == '' ? 'NA' : $ord->consignee_olshop_province, 'cod' => $ord->cod, 'volumes' => 1, 'chargeable' => $ord->cod, 'actualweight' => $ord->w_v, 'volumeweight' => $ord->w_v, 'partner' => 'Bilna', 'city' => $ord->consignee_olshop_city, 'userid' => 5490188, 'passwd' => 5351); $formatter = Formatter::make($req, Formatter::ARR); try { //$response = $client->request('POST', $base_url , array('json'=>$req, 'query'=>array('key'=> $logistic->api_key ) ) ); //$data_string = $formatter->toXml(); //$data_string = str_replace(array('<xml>','</xml>'), array('<sap>','</sap>'), $data_string); //print $data_string; $data_string = json_encode($req); $url = $base_url; //.'?key='.$logistic->api_key; $ch = curl_init($url); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, "5490188:5351"); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($data_string))); $result = curl_exec($ch); //$awblist = json_decode($response->getBody()); //$parser = new Parser(); //$res = $parser->xml($result); $res = json_decode($result, true); /* Array ( [invoice] => X100350935 [status] => 00 [awb] => KWLM151209162715 [orderid] => TEST320476XT [message] => Success, your request xml have been success. [trx_id] => 121505091627 ) */ //print_r($res); if (isset($res['status']) && strval($res['status']) == '00') { $pre = clone $ord; if (isset($res['awb']) && $res['awb'] != '') { $ord->awb = isset($res['awb']) ? $res['awb'] : ''; //$ord->awb = $awbs[$ord->fulfillment_code]; //$ord->bucket = Config::get('jayon.bucket_tracker'); //$ord->position = '3PL'; $ord->trx_id = isset($res['trx_id']) ? $res['trx_id'] : ''; $ord->uploaded = 1; $ord->save(); $ts = new MongoDate(); $hdata = array(); $hdata['historyTimestamp'] = $ts; $hdata['historyAction'] = 'api_shipment_change_awb'; $hdata['historySequence'] = 1; $hdata['historyObjectType'] = 'shipment'; $hdata['historyObject'] = $ord->toArray(); $hdata['actor'] = $this->name; $hdata['actor_id'] = ''; //History::insert($hdata); $sdata = array(); $sdata['timestamp'] = $ts; $sdata['action'] = 'api_shipment_change_awb'; $sdata['reason'] = 'api_update'; $sdata['objectType'] = 'shipment'; $sdata['object'] = $ord; $sdata['preObject'] = $pre; $sdata['actor'] = $this->name; $sdata['actor_id'] = ''; Shipmentlog::insert($sdata); } } //$awblist = json_decode($result); //print $result; //die(); /* $awbs = array(); $ffs = array(); foreach ($awblist as $awb) { $ffs[] = $awb->ff_id; $awbs[$awb->ff_id] = $awb->awb; } $orderlist = Shipment::whereIn('fulfillment_code', $ffs)->get(); foreach($orderlist as $order){ $pre = clone $order; $order->awb = $awbs[$order->fulfillment_code]; //$order->bucket = Config::get('jayon.bucket_tracker'); $order->position = '3PL'; $order->uploaded = 1; $order->save(); $ts = new MongoDate(); $hdata = array(); $hdata['historyTimestamp'] = $ts; $hdata['historyAction'] = 'api_shipment_change_awb'; $hdata['historySequence'] = 1; $hdata['historyObjectType'] = 'shipment'; $hdata['historyObject'] = $order->toArray(); $hdata['actor'] = $this->name; $hdata['actor_id'] = ''; History::insert($hdata); $sdata = array(); $sdata['timestamp'] = $ts; $sdata['action'] = 'api_shipment_change_awb'; $sdata['reason'] = 'api_update'; $sdata['objectType'] = 'shipment'; $sdata['object'] = $order->toArray(); $sdata['preObject'] = $pre->toArray(); $sdata['actor'] = $this->name; $sdata['actor_id'] = ''; Shipmentlog::insert($sdata); } */ } catch (Exception $e) { print $e; } } // end order loop //$req = $orders->toArray(); //print json_encode($req); //die(); //$client = new GuzzleClient(['defaults'=>['exceptions'=>false]]); } else { print 'Empty order list' . "\r\n"; } $actor = $this->name; Event::fire('log.api', array('JexAwbDaemon', 'get', $actor, 'SAP PUSH DATA AWB PULL')); }
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')); } }
/** * Execute the console command. * * @return mixed */ public function fire() { $logistic_id = 'B234-JKT'; $delivery_trigger = $this->e21status['DELIVERED']; $returned_trigger = $this->e21status['RETURNED']; $undelivered_trigger = $this->e21status['UNDELIVERED']; $logistic = Logistic::where('consignee_olshop_cust', '=', $logistic_id)->first(); if (Prefs::isRunning($this->name)) { $l = array(); $l['ts'] = new MongoDate(); $l['error'] = 'process already running'; $l['consignee_logistic_id'] = $logistic->logistic_code; $l['consignee_olshop_cust'] = $logistic_id; Threeplstatuserror::insert($l); die('process already running'); } if ($logistic) { } else { die('logistic data not found'); } $token = ''; $token_file = public_path() . '/storage/21oauth.key'; if (file_exists($token_file)) { $token = file_get_contents(public_path() . '/storage/21oauth.key'); } if ($token == '') { $token = $this->getToken($logistic); } else { $token = json_decode($token); if (isset($token->access_token)) { $token = $token->access_token; } } $orders = Shipment::where('awb', '!=', '')->where('bucket', '=', Config::get('jayon.bucket_tracker'))->where(function ($sq) { $sq->where('status', '!=', 'delivered')->where('status', '!=', 'undelivered')->where('status', '!=', 'canceled')->where('status', '!=', 'returned'); })->where('logistic_type', '=', 'external')->where('consignee_olshop_cust', '=', $logistic_id)->get(); if ($orders && count($orders->toArray()) > 0) { $req = array(); foreach ($orders as $ord) { $result = $this->sendRequest($ord->awb, $logistic, $token); $res = json_decode($result, true); if (isset($res['code']) && ($res['code'] == '0' || $res['code'] == 0)) { print 'reset token' . "\r\n"; $token = $this->getToken($logistic); $res = $this->sendRequest($ord->awb, $logistic, $token); $res = json_decode($result, true); } $reslog = $res; $reslog['timestamp'] = new MongoDate(); $reslog['consignee_logistic_id'] = $logistic->logistic_code; $reslog['consignee_olshop_cust'] = $logistic_id; Threeplstatuslog::insert($reslog); print_r($res); if (isset($res['shipment'])) { $ord = Shipment::where('awb', '=', $res['shipment']['code'])->orderBy('created_at', 'desc')->first(); if ($ord) { $pre = clone $ord; $laststat = $res['shipment']['statuses']; $laststat = array_pop($laststat); $lst = trim($laststat['status']); if (in_array($lst, $delivery_trigger) || $lst == 'RECEIVED') { $ord->status = \Config::get('jayon.trans_status_mobile_delivered'); $ord->position = 'CUSTOMER'; } if (in_array($lst, $returned_trigger) || $lst == 'RETURN') { $ord->status = \Config::get('jayon.trans_status_mobile_return'); } if (in_array($lst, $undelivered_trigger) || $lst == 'NOT DELIVERED') { $ord->status = \Config::get('jayon.trans_status_undelivered'); } //$ord->district = $ls->district; $ord->logistic_status = $laststat['status']; $ord->logistic_status_ts = $laststat['datetime']; $ord->logistic_raw_status = $laststat; $ord->save(); $ts = new MongoDate(); $hdata = array(); $hdata['historyTimestamp'] = $ts; $hdata['historyAction'] = 'api_shipment_change_status'; $hdata['historySequence'] = 1; $hdata['historyObjectType'] = 'shipment'; $hdata['historyObject'] = $ord->toArray(); $hdata['actor'] = $this->name; $hdata['actor_id'] = ''; //History::insert($hdata); $sdata = array(); $sdata['timestamp'] = $ts; $sdata['action'] = 'api_shipment_change_status'; $sdata['reason'] = 'api_update'; $sdata['objectType'] = 'shipment'; $sdata['object'] = $ord->toArray(); $sdata['preObject'] = $pre->toArray(); $sdata['actor'] = $this->name; $sdata['actor_id'] = ''; Shipmentlog::insert($sdata); $this->saveStatus($res, $logistic->logistic_code, $logistic_id); } } Logger::api($this->name, $ord->awb, $res); } } else { print 'Empty order list' . "\r\n"; } $actor = $this->name; Event::fire('log.api', array('E21StatusDaemon', 'get', $actor, 'E21 STATUS PULL')); }
/** * Execute the console command. * * @return mixed */ public function fire() { date_default_timezone_set('Asia/Jakarta'); $base_url = 'http://www.jayonexpress.com/jexadmin/api/v1/service/awb'; //$base_url = 'http://localhost/jexadmin/public/api/v1/service/awb'; $logistic_id = '7735'; $logistic = Logistic::where('consignee_olshop_cust', '=', $logistic_id)->first(); $orders = Shipment::where('awb', '=', '')->where('logistic_type', '=', 'external')->where(function ($q) { $q->where('status', '=', \Config::get('jayon.trans_status_admin_dated'))->orWhere('status', '=', \Config::get('jayon.trans_status_confirmed')); })->where('consignee_olshop_cust', '=', $logistic_id)->where(function ($q) { $q->where('consignee_olshop_service', '=', 'COD')->orWhere('consignee_olshop_service', '=', 'CCOD'); })->get(); if ($orders && count($orders->toArray()) > 0) { $req = array(); /* foreach($orders as $ord){ $req[] = array('order_id'=>$ord->no_sales_order, 'ff_id'=>$ord->consignee_olshop_orderid); } */ $req = $orders->toArray(); $reslog = $req; $reslog['timestamp'] = new \MongoDate(); $reslog['consignee_logistic_id'] = $logistic->logistic_code; $reslog['consignee_olshop_cust'] = $logistic->consignee_olshop_cust; Threepluploadlog::insert($reslog); //print json_encode($req); //die(); //$client = new GuzzleClient(['defaults'=>['exceptions'=>false]]); try { print_r($req); //$response = $client->request('POST', $base_url , array('json'=>$req, 'query'=>array('key'=> $logistic->api_key ) ) ); $data_string = json_encode($req); $url = $base_url . '?key=' . $logistic->api_key; $ch = curl_init($url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($data_string))); $result = curl_exec($ch); //$awblist = json_decode($response->getBody()); $awblist = json_decode($result); print $result; //die(); $awbs = array(); $ffs = array(); foreach ($awblist as $awb) { $ffs[] = $awb->ff_id; $awbs[$awb->ff_id] = $awb->awb; } $orderlist = Shipment::whereIn('fulfillment_code', $ffs)->get(); foreach ($orderlist as $order) { $pre = clone $order; $order->awb = $awbs[$order->fulfillment_code]; //$order->bucket = Config::get('jayon.bucket_tracker'); $order->position = '3PL'; $order->uploaded = 1; $order->save(); $ts = new MongoDate(); $hdata = array(); $hdata['historyTimestamp'] = $ts; $hdata['historyAction'] = 'api_shipment_change_awb'; $hdata['historySequence'] = 1; $hdata['historyObjectType'] = 'shipment'; $hdata['historyObject'] = $order->toArray(); $hdata['actor'] = $this->name; $hdata['actor_id'] = ''; //History::insert($hdata); $sdata = array(); $sdata['timestamp'] = $ts; $sdata['action'] = 'api_shipment_change_awb'; $sdata['reason'] = 'api_update'; $sdata['objectType'] = 'shipment'; $sdata['object'] = $order->toArray(); $sdata['preObject'] = $pre->toArray(); $sdata['actor'] = $this->name; $sdata['actor_id'] = ''; print_r($sdata); //try{ Shipmentlog::insert($sdata); //}catch(Exception $e){ // print_r($e); //} } } catch (Exception $e) { print $e; } } else { print 'Empty order list' . "\r\n"; } $actor = $this->name; Event::fire('log.api', array('JexAwbDaemon', 'get', $actor, 'JEX PUSH DATA AWB PULL')); }
/** * 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')); } }
public function postReassigndevice() { //courier_name:Shia Le Beouf //courier_id:5605512bccae5b64010041b6 //device_key:0f56deadbc6df60740ef5e2c576876b0e3310f7d //device_name:JY-002 //pickup_date:28-09-2 $in = Input::get(); $shipments = Shipment::whereIn('delivery_id', $in['ship_ids'])->get(); $device = Device::where('key', '=', $in['device'])->first()->toArray(); //print_r($shipments->toArray()); foreach ($shipments as $sh) { $cr = Shipment::where('device_key', '=', $in['device'])->where('pick_up_date', '=', $sh->pick_up_date)->orderBy('pick_up_date', 'desc')->first(); //print_r($dev); $ts = new MongoDate(); if ($cr) { $sh->courier_name = $cr->courier_name; $sh->courier_id = $cr->courier_id; } $sh->device_key = $device['key']; $sh->device_id = $device['_id']; $sh->device_name = $device['identifier']; $sh->last_action_ts = $ts; $sh->last_action = 'Change Device'; $sh->last_reason = $in['reason']; $sh->save(); //print_r(Auth::user()); $hdata = array(); $hdata['historyTimestamp'] = $ts; $hdata['historyAction'] = 'change_device'; $hdata['historySequence'] = 1; $hdata['historyObjectType'] = 'shipment'; $hdata['historyObject'] = $sh->toArray(); $hdata['actor'] = Auth::user()->fullname; $hdata['actor_id'] = Auth::user()->_id; //print_r($hdata); History::insert($hdata); $sdata = array(); $sdata['timestamp'] = $ts; $sdata['action'] = 'change_device'; $sdata['reason'] = $in['reason']; $sdata['objectType'] = 'shipment'; $sdata['object'] = $sh->toArray(); $sdata['actor'] = Auth::user()->fullname; $sdata['actor_id'] = Auth::user()->_id; Shipmentlog::insert($sdata); //print_r($sh); } return Response::json(array('result' => 'OK', 'shipment' => $shipments)); }
public function postWv() { $json = \Input::json(); try { $json = $json->all(); $res = array(); foreach ($json as $j) { $ord = \Shipment::where('delivery_id', '=', $j['awb'])->first(); if ($ord) { if ($ord->actual_weight == '' || is_null($ord->actual_weight)) { $ord->actual_weight = $j['w_v']; $ord->save(); $res[] = array('awb' => $j['awb'], 'status' => 'updated'); } else { $res[] = array('awb' => $j['awb'], 'status' => 'not updated'); } } else { $res[] = array('awb' => $j['awb'], 'status' => 'not found'); } } return \Response::json($res); } catch (Exception $e) { //print $e->getMessage(); return \Response::json(array('err' => 'json error')); } }
/** * 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); }