public function getIndex()
 {
     $this->title = 'Manifest Pengiriman Harian - To Device / Logistic';
     $this->place_action = 'none';
     $this->show_select = false;
     $this->can_add = false;
     $this->is_report = true;
     Breadcrumbs::addCrumb('Manifest', URL::to(strtolower($this->controller_name)));
     $this->additional_filter = View::make('shared.addfilter')->with('submit_url', 'devmanifest')->render();
     $db = Config::get('lundin.main_db');
     $company = Input::get('acc-company');
     //device=&courier=&logistic=&date-from=2015-10-24
     $period_from = Input::get('date-from');
     $period_to = Input::get('acc-period-to');
     $device = Input::get('device');
     $courier = Input::get('courier');
     $logistic = Input::get('logistic');
     $status = Input::get('status');
     $courierstatus = Input::get('courier-status');
     if ($period_to == '' || is_null($period_to)) {
         $period_to = date('Y-m-d', time());
     }
     if ($period_from == '' || is_null($period_from)) {
         $period_from = date('Y-m-d', time());
     }
     $this->def_order_by = 'TRANS_DATETIME';
     $this->def_order_dir = 'DESC';
     $this->place_action = 'none';
     $this->show_select = false;
     /* Start custom queries */
     $model = $this->model;
     if ($status == '' || is_null($status)) {
         $status = Config::get('jayon.devmanifest_default_status');
     } else {
         $status = explode(',', $status);
     }
     if (empty($status)) {
         $exstatus = Config::get('jayon.devmanifest_default_excl_status');
         if (!empty($exstatus)) {
             //$model = $model->whereNotIn('status', $exstatus);
         }
     } else {
         //$model = $model->whereIn('status', $status);
     }
     /*
     if($courierstatus == '' || is_null($courierstatus) ){
         $courierstatus = Config::get('jayon.devmanifest_default_courier_status');
     }else{
         $courierstatus = explode(',', $courierstatus);
     }
     
     if(empty($courierstatus)){
         $excrstatus = Config::get('jayon.devmanifest_default_excl_courier_status');
     
         if(!empty($excrstatus)){
             $model = $model->whereNotIn('courier_status', $excrstatus);
         }
     }else{
         $model = $model->whereIn('courier_status', $courierstatus);
     }
     */
     if ($period_from == '' || is_null($period_from)) {
         $datefrom = date('Y-m-d 00:00:00', strtotime($period_from));
         $dateto = date('Y-m-d 23:59:59', strtotime($period_to));
     } else {
         $datefrom = date('Y-m-d 00:00:00', strtotime($period_from));
         $dateto = date('Y-m-d 23:59:59', strtotime($period_to));
         $model = $model->where(function ($q) use($datefrom, $dateto) {
             $q->whereBetween('assignment_date', array($datefrom, $dateto));
         });
     }
     if ($device == '' || is_null($device)) {
     } else {
         $model = $model->where('device_id', '=', $device);
     }
     if ($courier == '' || is_null($courier)) {
     } else {
         $model = $model->where('courier_id', '=', $courier);
     }
     if ($logistic == '' || is_null($logistic)) {
     } else {
         $model = $model->where('logistic', '=', $logistic);
     }
     /*
     ->where('status',$this->config->item('trans_status_admin_courierassigned'))
     ->or_where('status',$this->config->item('trans_status_mobile_pickedup'))
     ->or_where('status',$this->config->item('trans_status_mobile_enroute'))
     ->or_()
         ->group_start()
             ->where('status',$this->config->item('trans_status_new'))
             ->where('pending_count >', 0)
         ->group_end()
     */
     $model = $model->where(function ($qr) {
         $qr->where('status', Config::get('jayon.trans_status_admin_courierassigned'))->orWhere('status', Config::get('jayon.trans_status_mobile_pickedup'))->orWhere('status', Config::get('jayon.trans_status_mobile_enroute'))->orWhere(function ($q) {
             $q->where('status', Config::get('jayon.trans_status_new'))->where('pending_count', '>', 0);
         });
     });
     $actualresult = $model->get();
     $tattrs = array('width' => '100%', 'class' => 'table table-bordered table-striped');
     $thead = array();
     $thead[] = array(array('value' => 'No.', 'attr' => ''), array('value' => 'Zone', 'attr' => ''), array('value' => 'TOKO ONLINE', 'attr' => ''), array('value' => 'Type', 'attr' => ''), array('value' => 'Status', 'attr' => ''), array('value' => 'KEPADA', 'attr' => ''), array('value' => 'Total Price', 'attr' => ''), array('value' => 'Delivery Charge', 'attr' => ''), array('value' => 'COD Surcharge', 'attr' => ''), array('value' => 'Total Charge', 'attr' => ''), array('value' => 'ALAMAT', 'attr' => ''), array('value' => 'Phone', 'attr' => ''), array('value' => 'No Kode Penjualan Toko', 'attr' => ''), array('value' => 'PENERIMA PAKET', 'attr' => 'colspan="2"'));
     $thead[] = array(array('value' => 'Mohon tunjukkan kartu identitas untuk di foto sebagai bagian bukti penerimaan', 'attr' => 'style="text-align:center;" colspan="13"'), array('value' => 'TANDA TANGAN', 'attr' => ''), array('value' => 'NAMA', 'attr' => 'class="bold center" style="width:50px" '));
     $tabdata = array();
     $seq = 1;
     $total_billing = 0;
     $total_delivery = 0;
     $total_cod = 0;
     $d = 0;
     $gt = 0;
     $lastdate = '';
     $courier_name = '';
     $counts = array('Delivery Only' => 0, 'COD' => 0, 'CCOD' => 0, 'PS' => 0, 'pending' => 0);
     foreach ($actualresult as $r) {
         $counts[$r->delivery_type] += 1;
         if ($r->pending_count > 0) {
             $counts['pending'] += 1;
         }
         $courier_name = $r->courier_name;
         //$total = str_replace(array(',','.'), '', $r->total_price);
         //$dsc = str_replace(array(',','.'), '', $r->total_discount);
         //$tax = str_replace(array(',','.'), '',$r->total_tax);
         //$dc = str_replace(array(',','.'), '',$r->delivery_cost);
         //$cod = str_replace(array(',','.'), '',$r->cod_cost);
         $total = $r->total_price;
         $dsc = $r->total_discount;
         $tax = $r->total_tax;
         $dc = $r->delivery_cost;
         $cod = $r->cod_cost;
         $total = is_nan((double) $total) ? 0 : (double) $total;
         $dsc = is_nan((double) $dsc) ? 0 : (double) $dsc;
         $tax = is_nan((double) $tax) ? 0 : (double) $tax;
         $dc = is_nan((double) $dc) ? 0 : (double) $dc;
         $cod = is_nan((double) $cod) ? 0 : (double) $cod;
         $payable = 0;
         //$details = $this->db->
         //where('delivery_id',$r->delivery_id)->order_by('unit_sequence','asc')->get($this->config->item('delivery_details_table'));
         //$details = $details->result_array();
         $details = Deliverydetail::where('delivery_id', '=', $r->delivery_id)->orderBy('unit_sequence', 'asc')->get()->toArray();
         $d = 0;
         $gt = 0;
         foreach ($details as $value => $key) {
             $u_total = $key['unit_total'];
             $u_discount = $key['unit_discount'];
             $gt += is_nan((double) $u_total) ? 0 : (double) $u_total;
             $d += is_nan((double) $u_discount) ? 0 : (double) $u_discount;
         }
         if ($gt == 0) {
             if ($total > 0 && $payable) {
                 $gt = $total;
             }
         }
         $payable = $gt;
         $total_delivery += (double) $dc;
         $total_cod += (double) $cod;
         $total_billing += (double) $payable;
         $db = '';
         if ($r->delivery_bearer == 'merchant') {
             $dc = 0;
             $db = 'M';
         } else {
             $db = 'B';
         }
         //force all DO to zero
         $cb = '';
         if ($r->cod_bearer == 'merchant') {
             $cod = 0;
             $cb = 'M';
         } else {
             $cb = 'B';
         }
         $codclass = '';
         if ($r->delivery_type == 'COD' || $r->delivery_type == 'CCOD') {
             $chg = $gt - $dsc + $tax + $dc + $cod;
             //$chg = $gt + $dc + $cod;
             $codclass = 'cod';
         } else {
             $dc = 0;
             $cod = 0;
             $chg = $dc;
         }
         $fcode = $r->fulfillment_code == '' ? '' : '<hr />' . $r->fulfillment_code;
         $phone_dupe = $r->same_phone == 1 ? 'class="dupe"' : '';
         $email_dupe = $r->same_email == 1 ? 'class="dupe"' : '';
         $tabdata[] = array(array('value' => $seq, 'attr' => ''), array('value' => $r->buyerdeliveryzone, 'attr' => ''), array('value' => $r->merchant_name, 'attr' => ''), array('value' => $r->delivery_type, 'attr' => 'class="currency ' . $codclass . '" '), array('value' => $r->status . '<br /><br />' . $r->pickup_status . '<br /><br />' . $r->warehouse_status, 'attr' => ''), array('value' => $r->buyer_name, 'attr' => ''), array('value' => $payable == 0 ? 0 : Ks::idr($payable), 'attr' => 'class="currency ' . $codclass . '" '), array('value' => $dc == 0 ? 0 : Ks::idr($dc), 'attr' => 'class="currency ' . $codclass . '" style="position:relative;"'), array('value' => $cod == 0 ? 0 : Ks::idr($cod), 'attr' => 'class="currency ' . $codclass . '" style="position:relative;"'), array('value' => $chg == 0 ? 0 : Ks::idr($chg), 'attr' => 'class="currency ' . $codclass . '" '), array('value' => $r->shipping_address, 'attr' => ''), array('value' => '<span ' . $phone_dupe . ' >' . $this->split_phone($r->phone) . '<br />' . $this->split_phone($r->mobile1) . '<br />' . $this->split_phone($r->mobile2) . '</span>', 'attr' => ''), array('value' => $this->hide_trx($r->merchant_trans_id) . $fcode . '<br/>' . $this->date_did($r->delivery_id), 'attr' => 'class="currency cod"'), array('value' => '', 'attr' => ''), array('value' => '', 'attr' => ''));
         $seq++;
     }
     $mtable = new HtmlTable($tabdata, $tattrs, $thead);
     $tables[] = $mtable->build();
     $this->table_raw = $tables;
     if ($this->print == true || $this->pdf == true) {
         return $tables;
     } else {
         return parent::reportPageGenerator();
     }
 }
Example #2
0
 public function order_save($indata, $api_key, $transaction_id)
 {
     date_default_timezone_set('Asia/Jakarta');
     $args = '';
     //$api_key = $this->get('key');
     //$transaction_id = $this->get('trx');
     if (is_null($api_key)) {
         $result = json_encode(array('status' => 'ERR:NOKEY', 'timestamp' => now()));
         return $result;
     } else {
         $app = \Prefs::get_key_info(trim($api_key));
         if ($app == false) {
             $result = json_encode(array('status' => 'ERR:INVALIDKEY', 'timestamp' => now()));
             return $result;
         } else {
             //$in = $this->input->post('transaction_detail');
             //$in = file_get_contents('php://input');
             $in = $indata;
             //print $in;
             $buyer_id = 1;
             $args = 'p=' . $in;
             $in = json_decode($in);
             //print "order input to save: \r\n";
             //print_r($in);
             $is_new = false;
             $in->phone = isset($in->phone) && $in->phone != '' ? \Prefs::normalphone($in->phone) : '';
             $in->mobile1 = isset($in->mobile1) && $in->mobile1 != '' ? \Prefs::normalphone($in->mobile1) : '';
             $in->mobile2 = isset($in->mobile2) && $in->mobile2 != '' ? \Prefs::normalphone($in->mobile2) : '';
             if (isset($in->buyer_id) && $in->buyer_id != '' && $in->buyer_id > 1) {
                 $buyer_id = $in->buyer_id;
                 $is_new = false;
             } else {
                 if ($in->email == '' || $in->email == '-' || !isset($in->email) || $in->email == 'noemail') {
                     $in->email = 'noemail';
                     $is_new = true;
                     if (trim($in->phone . $in->mobile1 . $in->mobile2) != '') {
                         if ($buyer = \Prefs::check_phone($in->phone, $in->mobile1, $in->mobile2)) {
                             $buyer_id = $buyer['id'];
                             $is_new = false;
                         }
                     }
                 } else {
                     if ($buyer = \Prefs::check_email($in->email)) {
                         $buyer_id = $buyer['id'];
                         $is_new = false;
                     } else {
                         if ($buyer = \Prefs::check_phone($in->phone, $in->mobile1, $in->mobile2)) {
                             $buyer_id = $buyer['id'];
                             $is_new = false;
                         }
                     }
                 }
             }
             if (isset($in->merchant_trans_id) && $in->merchant_trans_id != "") {
                 $transaction_id = $in->merchant_trans_id;
             }
             if ($is_new) {
                 $random_string = str_random(5);
                 $buyer_username = substr(strtolower(str_replace(' ', '', $in->buyer_name)), 0, 6) . $random_string;
                 $dataset['username'] = $buyer_username;
                 $dataset['email'] = $in->email;
                 $dataset['phone'] = $in->phone;
                 $dataset['mobile1'] = $in->mobile1;
                 $dataset['mobile2'] = $in->mobile2;
                 $dataset['fullname'] = $in->buyer_name;
                 $password = str_random(8);
                 $dataset['password'] = $password;
                 $dataset['created'] = date('Y-m-d H:i:s', time());
                 /*
                 $dataset['province'] =
                 $dataset['mobile']
                 */
                 $dataset['street'] = $in->shipping_address;
                 $dataset['district'] = $in->buyerdeliveryzone;
                 $dataset['city'] = $in->buyerdeliverycity;
                 $dataset['country'] = 'Indonesia';
                 $dataset['zip'] = isset($in->zip) ? $in->zip : '';
                 //$buyer_id = $this->register_buyer($dataset);
                 $is_new = true;
             }
             $order['created'] = date('Y-m-d H:i:s', time());
             $order['ordertime'] = date('Y-m-d H:i:s', time());
             $order['application_id'] = $app->id;
             $order['application_key'] = $app->key;
             $order['buyer_id'] = $buyer_id;
             $order['merchant_id'] = $app->merchant_id;
             $order['merchant_trans_id'] = trim($transaction_id);
             $order['buyer_name'] = $in->buyer_name;
             $order['recipient_name'] = $in->recipient_name;
             $order['email'] = $in->email;
             $order['directions'] = $in->directions;
             //$order['dir_lat'] = $in->dir_lat;
             //$order['dir_lon'] = $in->dir_lon;
             $order['buyerdeliverytime'] = $in->buyerdeliverytime;
             $order['buyerdeliveryslot'] = $in->buyerdeliveryslot;
             $order['buyerdeliveryzone'] = $in->buyerdeliveryzone;
             $order['buyerdeliverycity'] = is_null($in->buyerdeliverycity) || $in->buyerdeliverycity == '' ? 'Jakarta' : $in->buyerdeliverycity;
             $order['currency'] = $in->currency;
             $order['total_price'] = isset($in->total_price) ? $in->total_price : 0;
             $order['total_discount'] = isset($in->total_discount) ? $in->total_discount : 0;
             $order['total_tax'] = isset($in->total_tax) ? $in->total_tax : 0;
             if (in_array(strtoupper(trim($in->delivery_type)), array('COD', 'CCOD', 'PS', 'DO', 'DELIVERY ONLY'))) {
                 $in->delivery_type = 'COD';
             }
             $order['delivery_type'] = $in->delivery_type;
             if ($in->delivery_type == 'DO' || $in->delivery_type == 'Delivery Only') {
                 $order['cod_cost'] = 0;
             } else {
                 $order['cod_cost'] = \Prefs::get_cod_tariff($order['total_price'], $app->id);
             }
             $order['box_count'] = isset($in->box_count) ? $in->box_count : 1;
             $order['pending_count'] = isset($in->pending_count) ? $in->pending_count : 0;
             $order['delivery_note'] = isset($in->delivery_note) ? $in->delivery_note : '';
             $order['shipping_address'] = $in->shipping_address;
             $order['shipping_zip'] = $in->shipping_zip;
             $order['phone'] = $in->phone;
             $order['mobile1'] = $in->mobile1;
             $order['mobile2'] = $in->mobile2;
             $order['status'] = $in->status;
             $order['width'] = $in->width;
             $order['height'] = $in->height;
             $order['length'] = $in->length;
             $order['weight'] = isset($in->weight) ? $in->weight : 0;
             $order['actual_weight'] = isset($in->actual_weight) ? $in->actual_weight : 0;
             $order['delivery_cost'] = $order['weight'];
             $order['cod_bearer'] = isset($in->cod_bearer) ? $in->cod_bearer : 'merchant';
             $order['delivery_bearer'] = isset($in->delivery_bearer) ? $in->delivery_bearer : 'merchant';
             $order['cod_method'] = isset($in->cod_method) ? $in->cod_method : 'cash';
             $order['ccod_method'] = isset($in->ccod_method) ? $in->ccod_method : 'full';
             $order['fulfillment_code'] = isset($in->fulfillment_code) ? $in->fulfillment_code : '';
             // check out who is bearing the cost
             if ($order['delivery_type'] == 'COD' || $order['delivery_type'] == 'CCOD') {
                 if ($order['delivery_bearer'] == 'merchant') {
                     $dcost = 0;
                 } else {
                     $dcost = $order['delivery_cost'];
                 }
                 if ($order['cod_bearer'] == 'merchant') {
                     $codcost = 0;
                 } else {
                     $codcost = $order['cod_cost'];
                 }
                 $order['chargeable_amount'] = $order['total_price'] + $dcost + $codcost;
             } else {
                 if ($order['delivery_bearer'] == 'merchant') {
                     $dcost = 0;
                 } else {
                     $dcost = $order['delivery_cost'];
                 }
                 $order['chargeable_amount'] = $dcost;
             }
             if (isset($in->show_shop)) {
                 $order['show_shop'] = $in->show_shop;
             }
             if (isset($in->show_merchant)) {
                 $order['show_merchant'] = $in->show_merchant;
             }
             $order['is_api'] = 1;
             $ship = new \Shipment();
             foreach ($order as $k => $v) {
                 $ship->{$k} = $v;
             }
             $ship->save();
             $sequence = $ship->id;
             if (isset($in->delivery_id)) {
                 if (is_null($in->delivery_id) || $in->delivery_id == '') {
                     $delivery_id = \Prefs::get_delivery_id($sequence, $app->merchant_id);
                 } else {
                     $delivery_id = \Prefs::get_delivery_id($sequence, $app->merchant_id, $in->delivery_id);
                 }
             } else {
                 $delivery_id = \Prefs::get_delivery_id($sequence, $app->merchant_id);
             }
             $ship->delivery_id = $delivery_id;
             //print_r($ship);
             $ship->save();
             //die();
             if (isset($in->box_count)) {
                 $box_count = $in->box_count;
             } else {
                 $box_count = 1;
             }
             \Prefs::save_box($delivery_id, trim($transaction_id), $order['fulfillment_code'], $box_count);
             $nedata['fullname'] = $in->buyer_name;
             $nedata['merchant_trx_id'] = trim($transaction_id);
             $nedata['delivery_id'] = $delivery_id;
             $nedata['merchantname'] = $app->application_name;
             $nedata['app'] = $app;
             $order['delivery_id'] = $delivery_id;
             $buyer_id = \Prefs::save_buyer($order);
             /*
             $this->db->where('id',$sequence)->update($this->config->item('incoming_delivery_table'),array('delivery_id'=>$delivery_id));
             */
             /*
                 $this->table_tpl = array(
                     'table_open' => '<table border="0" cellpadding="4" cellspacing="0" class="dataTable">'
                 );
                 $this->table->set_template($this->table_tpl);
             
             
                 $this->table->set_heading(
                     'No.',
                     'Description',
                     'Quantity',
                     'Total'
                     ); // Setting headings for the table
             */
             $d = 0;
             $gt = 0;
             if ($in->trx_detail) {
                 $seq = 0;
                 foreach ($in->trx_detail as $it) {
                     $item = new \Deliverydetail();
                     $item->ordertime = $order['ordertime'];
                     $item->delivery_id = $delivery_id;
                     $item->unit_sequence = $seq++;
                     $item->unit_description = $it->unit_description;
                     $item->unit_price = $it->unit_price;
                     $item->unit_quantity = $it->unit_quantity;
                     $item->unit_total = $it->unit_total;
                     $item->unit_discount = $it->unit_discount;
                     $item->save();
                     /*
                     $this->table->add_row(
                         (int)$item['unit_sequence'] + 1,
                         $item['unit_description'],
                         $item['unit_quantity'],
                         $item['unit_total']
                     );
                     
                     $u_total = str_replace(array(',','.'), '', $item['unit_total']);
                     $u_discount = str_replace(array(',','.'), '', $item['unit_discount']);
                     $gt += (int)$u_total;
                     $d += (int)$u_discount;
                     */
                 }
                 $total = isset($in->total_price) && $in->total_price > 0 ? $in->total_price : 0;
                 $total = str_replace(array(',', '.'), '', $total);
                 $total = (int) $total;
                 $gt = $total < $gt ? $gt : $total;
                 $disc = isset($in->total_discount) ? $in->total_discount : 0;
                 $tax = isset($in->total_tax) ? $in->total_tax : 0;
                 $cod = isset($in->cod_cost) ? $in->cod_cost : 'Paid by merchant';
                 $disc = str_replace(array(',', '.'), '', $disc);
                 $tax = str_replace(array(',', '.'), '', $tax);
                 $cod = str_replace(array(',', '.'), '', $cod);
                 $disc = (int) $disc;
                 $tax = (int) $tax;
                 $cod = (int) $cod;
                 $chg = $gt - $disc + $tax + $cod;
                 /*
                 $this->table->add_row(
                     '',
                     '',
                     'Total Price',
                     number_format($gt,2,',','.')
                 );
                 
                 $this->table->add_row(
                     '',
                     '',
                     'Total Discount',
                     number_format($disc,2,',','.')
                 );
                 
                 $this->table->add_row(
                     '',
                     '',
                     'Total Tax',
                     number_format($tax,2,',','.')
                 );
                 
                 
                 if($cod == 0){
                     $this->table->add_row(
                         '',
                         '',
                         'COD Charges',
                         'Paid by Merchant'
                     );
                 }else{
                     $this->table->add_row(
                         '',
                         '',
                         'COD Charges',
                         number_format($cod,2,',','.')
                     );
                 }
                 
                 
                 $this->table->add_row(
                     '',
                     '',
                     'Total Charges',
                     number_format($chg,2,',','.')
                 );
                 
                 $nedata['detail'] = $this->table;
                 
                 
                 $result = json_encode(array('status'=>'OK:ORDERPOSTED','timestamp'=>now(),'delivery_id'=>$delivery_id,'buyer_id'=>$buyer_id));
                 */
                 //return $ship->toArray();
             } else {
                 //$nedata['detail'] = false;
                 //$result = json_encode(array('status'=>'OK:ORDERPOSTEDNODETAIL','timestamp'=>now(),'delivery_id'=>$delivery_id));
                 //return $order;
             }
             return $ship->toArray();
             //print_r($app);
             /*
             
                             if($app->notify_on_new_order == 1){
                                 send_notification('New Delivery Order - Jayon Express COD Service',$in->email,$app->cc_to,$app->reply_to,'order_submit',$nedata,null);
                             }
             
                             if($is_new == true){
                                 $edata['fullname'] = $dataset['fullname'];
                                 $edata['username'] = $buyer_username;
                                 $edata['password'] = $password;
                                 if($app->notify_on_new_member == 1 && $in->email != 'noemail'){
                                     send_notification('New Member Registration - Jayon Express COD Service',$in->email,null,null,'new_member',$edata,null);
                                 }
             
                             }*/
         }
     }
     //$this->log_access($api_key, __METHOD__ ,$result,$args);
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $key = Input::get('key');
     $deliverydate = Input::get('date');
     $until = Input::get('until');
     if (is_null($until) || $until == '') {
         $until = date('Y-m-d', time());
     }
     /*
                         ->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()
     */
     $dev = \Device::where('key', '=', $key)->first();
     //print_r($dev);
     $txtab = \Config::get('jayon.incoming_delivery_table');
     /*
     $orders = $this->model
                 ->select(
                         \DB::raw(
                             \Config::get('jayon.incoming_delivery_table').'.* ,'.
                             \Config::get('jayon.jayon_members_table').'.merchantname as merchant_name ,'.
                             \Config::get('jayon.applications_table').'.application_name as app_name ,'.
                             '('.$txtab.'.width * '.$txtab.'.height * '.$txtab.'.length ) as volume'
                         )
                 )
                 ->leftJoin(\Config::get('jayon.jayon_members_table'), \Config::get('jayon.incoming_delivery_table').'.merchant_id', '=', \Config::get('jayon.jayon_members_table').'.id' )
                 ->leftJoin(\Config::get('jayon.applications_table'), \Config::get('jayon.incoming_delivery_table').'.application_id', '=', \Config::get('jayon.applications_table').'.id' )
     
                 ->where('device_id','=',$dev->id)
                 ->where('assignment_date','=',$deliverydate)
     
                 ->where(function($q){
                     $q->where('status','=', \Config::get('jayon.trans_status_new') )
                         ->orWhere(function($ql){
                             $ql->where('status','=', \Config::get('jayon.trans_status_new') )
                                 ->where('pending_count','>',0);
                         });
                 })
                 ->orderBy('ordertime','desc')
                 ->get();
     */
     $orders = $this->model->select(\DB::raw(\Config::get('jayon.incoming_delivery_table') . '.* ,' . \Config::get('jayon.jayon_couriers_table') . '.fullname as courier ,' . \Config::get('jayon.jayon_devices_table') . '.identifier as device ,' . \Config::get('jayon.jayon_members_table') . '.merchantname as merchant_name ,' . \Config::get('jayon.applications_table') . '.application_name as app_name ,' . '(' . $txtab . '.width * ' . $txtab . '.height * ' . $txtab . '.length ) as volume'))->leftJoin(\Config::get('jayon.jayon_couriers_table'), \Config::get('jayon.incoming_delivery_table') . '.courier_id', '=', \Config::get('jayon.jayon_couriers_table') . '.id')->leftJoin(\Config::get('jayon.jayon_devices_table'), \Config::get('jayon.incoming_delivery_table') . '.device_id', '=', \Config::get('jayon.jayon_devices_table') . '.id')->leftJoin(\Config::get('jayon.jayon_members_table'), \Config::get('jayon.incoming_delivery_table') . '.merchant_id', '=', \Config::get('jayon.jayon_members_table') . '.id')->leftJoin(\Config::get('jayon.applications_table'), \Config::get('jayon.incoming_delivery_table') . '.application_id', '=', \Config::get('jayon.applications_table') . '.id')->where(function ($query) use($deliverydate, $until) {
         $query->where('pickup_status', '=', \Config::get('jayon.trans_status_tobepickup'))->where('status', '!=', \Config::get('jayon.trans_status_canceled'))->where('status', '!=', \Config::get('jayon.trans_status_mobile_delivered'))->whereBetween('ordertime', array($deliverydate . ' 00:00:00', $until . ' 23:59:59'));
         //->where('ordertime','>=',$deliverydate.' 00:00:00');
         /*
                             ->orWhere('status','=', \Config::get('jayon.trans_status_mobile_pickedup') )
                             ->orWhere('status','=', \Config::get('jayon.trans_status_mobile_enroute') )
                             ->orWhere(function($q){
                                     $q->where('status', \Config::get('jayon.trans_status_new'))
                                         ->where(\Config::get('jayon.incoming_delivery_table').'.pending_count', '>', 0);
                             })*/
     })->orderBy('ordertime', 'desc')->get();
     $total_billing = 0;
     $total_delivery = 0;
     $total_cod = 0;
     $norders = array();
     for ($n = 0; $n < count($orders); $n++) {
         $or = new \stdClass();
         foreach ($orders[$n] as $k => $v) {
             $nk = $this->underscoreToCamelCase($k);
             if (in_array($nk, $this->order_unset)) {
             } else {
                 $or->{$nk} = is_null($v) ? '' : $v;
             }
         }
         $or->extId = $or->id;
         unset($or->id);
         $bc = \Box::where('delivery_id', '=', $or->deliveryId)->count();
         if ($bc == 0) {
             $this->createBox($or->deliveryId, $or->merchantTransId, $or->fulfillmentCode, $or->boxCount);
         }
         $or->boxList = $this->boxList('delivery_id', $or->deliveryId, $key, $or->merchantId);
         $or->boxObjects = $this->boxList('delivery_id', $or->deliveryId, $key, $or->merchantId, true);
         $or->merchantObject = $this->merchantObject($or->merchantId);
         /* chargeable */
         $total = doubleval($or->totalPrice);
         $dsc = doubleval($or->totalDiscount);
         $tax = doubleval($or->totalTax);
         $dc = doubleval($or->deliveryCost);
         $cod = doubleval($or->codCost);
         $total = is_nan($total) ? 0 : $total;
         $dsc = is_nan($dsc) ? 0 : $dsc;
         $tax = is_nan($tax) ? 0 : $tax;
         $dc = is_nan($dc) ? 0 : $dc;
         $cod = is_nan($cod) ? 0 : $cod;
         //print $total.' '.$dsc.' '.$tax.' '.$dc.' '.$cod."\r\n";
         $payable = 0;
         $details = \Deliverydetail::where('delivery_id', '=', $or->deliveryId)->orderBy('unit_sequence', 'asc')->get();
         $details = $details->toArray();
         $d = 0;
         $gt = 0;
         foreach ($details as $value => $key) {
             $u_total = doubleval($key['unit_total']);
             $u_discount = doubleval($key['unit_discount']);
             $gt += is_nan($u_total) ? 0 : $u_total;
             $d += is_nan($u_discount) ? 0 : $u_discount;
         }
         if ($gt == 0) {
             if ($total > 0 && $payable) {
                 $gt = $total;
             }
         }
         //print $gt.' '.$dsc.' '.$tax.' '.$dc.' '.$cod."\r\n";
         $payable = $gt;
         $db = '';
         if ($or->deliveryBearer == 'merchant') {
             $dc = 0;
         }
         //force all DO to zero
         $cb = '';
         if ($or->codBearer == 'merchant') {
             $cod = 0;
         }
         $codclass = '';
         if ($or->deliveryType == 'COD' || $or->deliveryType == 'CCOD') {
             $chg = $gt - $dsc + $tax + $dc + $cod;
         } else {
             $dc = 0;
             $cod = 0;
             $chg = $dc;
         }
         $or->totalPrice = strval($payable);
         $or->deliveryCost = strval($dc);
         $or->codCost = strval($cod);
         $or->chargeableAmount = strval($chg);
         $orders[$n] = $or;
         //$norders[] = $or;
     }
     $actor = $key;
     \Event::fire('log.api', array($this->controller_name, 'get', $actor, 'logged out'));
     return $orders;
     //
 }