Esempio n. 1
0
 public static function getNotes($delivery_id, $as_array = true)
 {
     $notes = Deliverynote::where('deliveryId', '=', $delivery_id)->orderBy('mtimestamp', 'desc')->get();
     if ($as_array) {
         return $notes->toArray();
     } else {
         $list = '<ul class="note_list">';
         foreach ($notes as $note) {
             $list .= '<li>';
             $list .= '<b>' . $note->status . '</b><br />';
             $list .= $note->datetimestamp . '<br />';
             $list .= $note->note;
             $list .= '</li>';
         }
         $list .= '</ul>';
         return $list;
     }
 }
Esempio n. 2
0
 public function getIndex()
 {
     set_time_limit(0);
     $this->title = 'Data Tool';
     $this->place_action = 'none';
     $this->show_select = false;
     $this->can_add = false;
     $this->is_report = true;
     Breadcrumbs::addCrumb('Data Tool', URL::to(strtolower($this->controller_name)));
     $this->additional_filter = View::make(strtolower($this->controller_name) . '.addfilter')->with('submit_url', 'datatool')->render();
     $db = Config::get('lundin.main_db');
     if (is_null($this->report_filter_input)) {
         $in = Input::all();
     } else {
         $in = $this->report_filter_input;
     }
     //$company = $in['acc-company'];
     //device=&courier=&logistic=&date-from=2015-10-24
     //print_r($in);
     $period_from = isset($in['date-from']) ? $in['date-from'] : '';
     $period_to = isset($in['date-to']) ? $in['date-to'] : '';
     $device = isset($in['device']) ? $in['device'] : '';
     $courier = isset($in['courier']) ? $in['courier'] : '';
     $merchant = isset($in['merchant']) ? $in['merchant'] : '';
     $logistic = isset($in['logistic']) ? $in['logistic'] : '';
     $city = isset($in['city']) ? $in['city'] : '';
     $zone = isset($in['zone']) ? $in['zone'] : '';
     $pendingcount = isset($in['pending-count']) ? $in['pending-count'] : '';
     $timebase = isset($in['time-base']) ? $in['time-base'] : 'delivery_order_active.created';
     $status = isset($in['status']) ? $in['status'] : '';
     $courierstatus = isset($in['courier-status']) ? $in['courier-status'] : '';
     $pickupstatus = isset($in['pickup-status']) ? $in['pickup-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 */
     $mtab = Config::get('jayon.assigned_delivery_table');
     $model = $this->model;
     $model = $model->select('assignment_date', 'ordertime', 'pickuptime', 'deliverytime', 'delivery_note', 'pending_count', 'recipient_name', 'delivery_id', $mtab . '.merchant_id as merchant_id', 'cod_bearer', 'delivery_bearer', 'buyer_name', 'buyerdeliveryzone', 'buyerdeliverycity', 'c.fullname as courier_name', $mtab . '.phone', $mtab . '.mobile1', $mtab . '.mobile2', 'merchant_trans_id', 'fulfillment_code', 'm.merchantname as merchant_name', 'm.fullname as fullname', 'a.application_name as app_name', 'a.domain as domain ', 'delivery_type', 'shipping_address', 'status', 'pickup_status', 'warehouse_status', 'cod_cost', 'delivery_cost', 'total_price', 'total_tax', 'total_discount')->leftJoin('members as m', Config::get('jayon.incoming_delivery_table') . '.merchant_id', '=', 'm.id')->leftJoin('applications as a', Config::get('jayon.assigned_delivery_table') . '.application_id', '=', 'a.id')->leftJoin('devices as d', Config::get('jayon.assigned_delivery_table') . '.device_id', '=', 'd.id')->leftJoin('couriers as c', Config::get('jayon.assigned_delivery_table') . '.courier_id', '=', 'c.id');
     /*
     $model = $model
         ->where(function($q){
             $q->where('status',Config::get('jayon.trans_status_mobile_delivered'))
                 //->where('status',Config::get('jayon.trans_status_admin_courierassigned'))
                 ->orWhere('status',Config::get('jayon.trans_status_new'))
                 ->orWhere('status',Config::get('jayon.trans_status_rescheduled'))
                 ->orWhere('status',Config::get('jayon.trans_status_mobile_return'));
     
         });
     */
     if ($pendingcount == '' || is_null($pendingcount)) {
     } else {
         if ($pendingcount == 4) {
             $model = $model->where('pending_count', '>', $pendingcount);
         } else {
             $model = $model->where('pending_count', '=', $pendingcount);
         }
     }
     if ($status == '' || is_null($status)) {
         //$status = Config::get('jex.data_tool_default_status');
     } else {
         $status = explode(',', $status);
         $model = $model->where(function ($qs) use($status) {
             $qs->whereIn('status', $status);
         });
     }
     if ($courierstatus == '' || is_null($courierstatus)) {
     } else {
         $courierstatus = explode(',', $courierstatus);
         $model = $model->whereIn('courier_status', $courierstatus);
     }
     if ($pickupstatus == '' || is_null($pickupstatus)) {
     } else {
         $pickupstatus = explode(',', $pickupstatus);
         $model = $model->whereIn('pickup_status', $pickupstatus);
     }
     /*
     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(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', time());
         $dateto = date('Y-m-d 23:59:59', time());
     } 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, $timebase) {
             $q->whereBetween($timebase, array($datefrom, $dateto));
         });
     }
     if ($merchant == '' || is_null($merchant)) {
     } else {
         $model = $model->where(Config::get('jayon.incoming_delivery_table') . '.merchant_id', '=', $merchant);
     }
     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);
     }
     if ($city == '' || is_null($city)) {
     } else {
         $model = $model->where('buyerdeliverycity', 'like', '%' . $city . '%');
     }
     if ($zone == '' || is_null($zone)) {
     } else {
         $model = $model->where('buyerdeliveryzone', 'like', '%' . $zone . '%');
     }
     $actualresult = $model->orderBy($timebase, 'desc')->get();
     $tattrs = array('width' => '100%', 'class' => 'table table-bordered table-striped');
     $thead = array();
     $thead[] = array(array('value' => 'No.', 'attr' => ''), array('value' => 'TOKO ONLINE', 'attr' => ''), array('value' => 'Type', 'attr' => ''), array('value' => 'Tgl Upload', 'attr' => ''), array('value' => 'Tgl Pick Up', 'attr' => ''), array('value' => 'Tgl Penugasan Terakhir <br />( Last Assignment Date )', 'attr' => ''), array('value' => 'Tgl Kirim', 'attr' => ''), array('value' => 'Pick Up -> Diterima', 'attr' => ''), array('value' => 'Kirim -> Diterima', 'attr' => ''), array('value' => 'Tgl Diterima', 'attr' => ''), array('value' => 'Status', 'attr' => ''), array('value' => 'Pending', 'attr' => ''), array('value' => 'Catatan', 'attr' => ''), array('value' => 'ALAMAT', 'attr' => ''), array('value' => 'Kecamatan', 'attr' => ''), array('value' => 'Kota', 'attr' => ''), array('value' => 'Delivery ID', 'attr' => ''), array('value' => 'No Kode Penjualan Toko', 'attr' => ''), array('value' => 'Fulfillment ID', 'attr' => ''));
     /*
     
     $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" '),
         );
     */
     $seq = 1;
     $total_billing = 0;
     $total_delivery = 0;
     $total_cod = 0;
     $d = 0;
     $gt = 0;
     $lastdate = '';
     $courier_name = '';
     $order2assigndays = 0;
     $assign2deliverydays = 0;
     $order2deliverydays = 0;
     $pickup2deliverydays = 0;
     $csv_data = array();
     $dids = array();
     foreach ($actualresult as $ar) {
         $dids[] = $ar->delivery_id;
     }
     $details = Deliverylog::whereIn('delivery_id', $dids)->where(function ($q) {
         $q->where('notes', '!=', '')->orWhere('req_note', '!=', '');
     })->orderBy('timestamp', 'desc')->get()->toArray();
     $dlist = array();
     foreach ($details as $dt) {
         $dlist[$dt['delivery_id']][] = $dt;
     }
     $denotes = Deliverynote::whereIn('deliveryId', $dids)->orderBy('mtimestamp', 'desc')->get()->toArray();
     foreach ($denotes as $dt) {
         $dlist[$dt['deliveryId']][] = $dt;
     }
     $tabdata = array();
     $cntcod = 0;
     $cntccod = 0;
     $cntdo = 0;
     $cntps = 0;
     $return = 0;
     $valid_pickups = 0;
     foreach ($actualresult as $r) {
         $details = isset($dlist[$r->delivery_id]) ? $dlist[$r->delivery_id] : array();
         $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 = (int) $total;
         $dsc = (int) $dsc;
         $tax = (int) $tax;
         $dc = (int) $dc;
         $cod = (int) $cod;
         $payable = 0;
         $otime = date('Y-m-d', strtotime($r->ordertime));
         $ptime = date('Y-m-d', strtotime($r->pickuptime));
         $dtime = date('Y-m-d', strtotime($r->deliverytime));
         $ordertime = new DateTime($otime);
         //print_r($details);
         $notes = '';
         $event_seq = 0;
         $first_assignment = false;
         foreach ($details as $d) {
             $n = '';
             if (isset($d['api_event'])) {
                 if ($d['api_event'] == 'admin_change_status') {
                     $n = $d['req_note'];
                 } else {
                     if ($d['notes'] != '') {
                         $n = $d['notes'];
                     }
                 }
                 if ($n != '' && $d['status'] != 'syncnote') {
                     $notes .= $d['timestamp'] . '<br />';
                     $notes .= '<b>' . $d['status'] . '</b><br />';
                     $notes .= $n . '<br /><br />';
                 }
                 if ($d['status'] == Config::get('jayon.trans_status_admin_courierassigned')) {
                     if ($event_seq > 0) {
                         $first_assignment = $d;
                     }
                 }
             } else {
                 if ($d['note'] != '') {
                     $n = $d['note'];
                 }
                 if ($n != '') {
                     $notes .= $d['datetimestamp'] . '<br />';
                     $notes .= '<b>' . $d['status'] . '</b><br />';
                     $notes .= $n . '<br /><br />';
                 }
             }
             $event_seq++;
         }
         if ($first_assignment) {
             $assignment_date = new DateTime($first_assignment['timestamp']);
             $assignment_date->add(new DateInterval('P1D'));
         } else {
             $assignment_date = new DateTime($r->assignment_date);
         }
         $deliverytime = new DateTime($dtime);
         $pickuptime = new DateTime($ptime);
         $order2assign = $ordertime->diff($assignment_date);
         $assign2delivery = $assignment_date->diff($deliverytime);
         $pickup2delivery = $pickuptime->diff($deliverytime);
         $order2delivery = $ordertime->diff($deliverytime);
         if (is_null($r->deliverytime) || $r->deliverytime == '' || $r->deliverytime == '0000-00-00 00:00:00') {
             $assign2delivery->d = 0;
             $order2delivery->d = 0;
             $pickup2delivery->d = 0;
             $order2assigndays += (int) $order2assign->d;
         } else {
             $order2assigndays += (int) $order2assign->d;
             $assign2deliverydays += (int) $assign2delivery->d;
             $order2deliverydays += (int) $order2delivery->d;
         }
         if (is_null($pickuptime) || $pickuptime == '' || $r->pickuptime == '' || $r->pickuptime == '0000-00-00 00:00:00') {
             //$r->pickuptime = $assignment_date->add(new DateInterval('P1D'))->format('Y-m-d');
             //$pickuptime = new DateTime($r->pickuptime);
             //$pickup2delivery = $pickuptime->diff($deliverytime);
             $pickup2delivery->d = 0;
             $pickup2deliverydays += (int) $pickup2delivery->d;
         } else {
             //$valid_pickups++;
             $pickup2deliverydays += (int) $pickup2delivery->d;
             $valid_pickups++;
         }
         $d = 0;
         $gt = 0;
         $cntcod = $r->delivery_type == 'COD' ? $cntcod + 1 : $cntcod;
         $cntccod = $r->delivery_type == 'CCOD' ? $cntccod + 1 : $cntccod;
         $cntdo = $r->delivery_type == 'Delivery Only' ? $cntdo + 1 : $cntdo;
         $cntps = $r->delivery_type == 'PS' ? $cntps + 1 : $cntps;
         $cntreturn = $r->status == 'returned' ? $return + 1 : $return;
         //print_r($details);
         /*
         $notes = '';
         foreach($details as $d )
         {
             $n = '';
             $admin = true;
             if($d['api_event'] == 'admin_change_status'){
                 $n = $d['req_note'];
             }else{
                 if($d['notes'] != ''){
                     $n = $d['notes'];
                 }
                 $admin = false;
             }
         
             $isadmin = ($admin)?' [admin]':'';
             if($n != '' && $d['status'] != 'syncnote'){
                 $notes .= $d['timestamp'].$isadmin.'<br />';
                 $notes .= '<b>'.$d['status'].'</b><br />';
                 $notes .= $n.'<br />';
             }
         
         }
         */
         /*
         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->merchant_name, 'attr' => ''), array('value' => $r->delivery_type, 'attr' => ''), array('value' => $r->ordertime, 'attr' => ''), array('value' => $r->pickuptime, 'attr' => ''), array('value' => $r->assignment_date, 'attr' => ''), array('value' => $assignment_date->format('Y-m-d'), 'attr' => ''), array('value' => $pickup2delivery->d, 'attr' => ''), array('value' => $assign2delivery->d, 'attr' => ''), array('value' => $r->deliverytime, 'attr' => ''), array('value' => $r->status, 'attr' => ''), array('value' => $r->pending_count, 'attr' => ''), array('value' => $notes, 'attr' => ''), array('value' => $r->recipient_name . ' | ' . str_replace(array(",", '"', "\n", "\r"), '', $r->shipping_address) . ' ' . $this->split_phone($r->phone) . ' ' . $this->split_phone($r->mobile1) . ' ' . $this->split_phone($r->mobile2), 'attr' => ''), array('value' => $r->buyerdeliveryzone, 'attr' => ''), array('value' => $r->buyerdeliverycity, 'attr' => ''), array('value' => $r->delivery_id, 'attr' => ''), array('value' => $this->hide_trx($r->merchant_trans_id), 'attr' => ''), array('value' => $r->fulfillment_code, 'attr' => ''));
         $seq++;
     }
     $valid_pickups = $valid_pickups > 0 ? $valid_pickups : 1;
     $avgdata = array(array('value' => 'Rata-rata<br />( dlm satuan hari )', 'attr' => 'colspan="7"'), array('value' => number_format($pickup2deliverydays / $valid_pickups, 2, ',', '.'), 'attr' => 'style="font-size:18px;font-weight:bold;"'), array('value' => number_format($assign2deliverydays / $seq, 2, ',', '.'), 'attr' => 'style="font-size:18px;font-weight:bold;"'), array('value' => '', 'attr' => 'colspan="11"'));
     array_unshift($tabdata, $avgdata);
     array_push($tabdata, $avgdata);
     $mtable = new HtmlTable($tabdata, $tattrs, $thead);
     $tables[] = $mtable->build();
     $this->table_raw = $tables;
     $report_header_data = array('cod' => $cntcod, 'ccod' => $cntccod, 'do' => $cntdo, 'ps' => $cntps, 'return' => $return, 'avg' => number_format($assign2deliverydays / $seq, 2, ',', '.'));
     if ($this->print == true || $this->pdf == true) {
         return array('tables' => $tables, 'report_header_data' => $report_header_data);
     } else {
         return parent::reportPageGenerator();
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function postNote()
 {
     $key = \Input::get('key');
     //$user = \Apiauth::user($key);
     $user = \Device::where('key', '=', $key)->first();
     if (!$user) {
         $actor = 'no id : no name';
         \Event::fire('log.api', array($this->controller_name, 'post', $actor, 'device not found, upload image failed'));
         return \Response::json(array('status' => 'ERR:NODEVICE', 'timestamp' => time(), 'message' => 'Device Unregistered'));
     }
     $json = \Input::all();
     $batch = \Input::get('batch');
     $result = array();
     foreach ($json as $j) {
         if (isset($j['logId'])) {
             if (isset($j['datetimestamp'])) {
                 $j['mtimestamp'] = new \MongoDate(strtotime($j['datetimestamp']));
             }
             $log = \Deliverynote::where('logId', $j['logId'])->first();
             if ($log) {
                 $result[] = array('status' => 'OK', 'timestamp' => time(), 'message' => $j['logId']);
             } else {
                 \Deliverynote::insert($j);
                 $result[] = array('status' => 'OK', 'timestamp' => time(), 'message' => $j['logId']);
             }
         }
     }
     //print_r($result);
     //die();
     $actor = $user->identifier . ' : ' . $user->devname;
     \Event::fire('log.api', array($this->controller_name, 'get', $actor, 'sync note'));
     return Response::json($result);
 }
Esempio n. 4
0
 public function saveDeliveryNote($status, $note, $timestamp, $order)
 {
     $d = new Deliverynote();
     $d->datetimestamp = date('Y-m-d H:i:s', $timestamp->sec);
     $d->deliveryId = $order->delivery_id;
     $d->deviceId = $order->device_id;
     $d->deviceKey = $order->device_key;
     $d->extId = $order->_id;
     $d->logId = '-';
     $d->note = $note;
     $d->status = $status;
     $d->timestamp = $timestamp->sec;
     $d->mtimestamp = $timestamp;
     $d->save();
 }
function get_do_pdf()
{
    require_once 'include/tcpdf/pdf.php';
    require_once 'include/tcpdf/pdfconfig.php';
    require_once 'include/database/PearDatabase.php';
    require_once 'modules/Deliverynote/Deliverynote.php';
    require_once 'modules/Invoice/Invoice.php';
    require_once 'modules/SalesOrder/SalesOrder.php';
    require_once 'modules/Deliverynote/language/en_us.lang.php';
    global $adb, $app_strings, $current_user, $mod_strings;
    // would you like and end page?  1 for yes 0 for no
    $endpage = "1";
    $id = $_REQUEST['src_record'];
    // scott	Print_r($_REQUEST);
    //retreiving the vtiger_invoice info
    $focus = new Deliverynote();
    $focus->retrieve_entity_info($_REQUEST['src_record'], "Deliverynote");
    //	$focus->retrieve_entity_info($_REQUEST['LinkTo'],"SalesOrder");
    $focus->apply_field_security();
    // scott Print_r($focus->column_fields);
    $productlist = $focus->column_fields["ProductList"];
    $customerpo = $focus->column_fields["CustomerPO"];
    $dn_number = $focus->column_fields["dn_sequence"];
    $inv_no = $focus->column_fields['LinkTo'];
    // scott	Print($productlist);
    $focus = new SalesOrder();
    $focus->retrieve_entity_info($inv_no, "SalesOrder");
    //scott	Print_r($focus);
    $sql = "select currency_symbol from vtiger_currency_info where id=?";
    $result = $adb->pquery($sql, array($focus->column_fields['currency_id']));
    $currency_symbol = $adb->query_result($result, 0, 'currency_symbol');
    // **************** BEGIN POPULATE DATA ********************
    // populate data
    if ($focus->column_fields["quote_id"] != '') {
        $quote_name = getQuoteName($focus->column_fields["quote_id"]);
    } else {
        $quote_name = '';
    }
    if ($focus->column_fields["account_id"] != '') {
        $account_name = getAccountName($focus->column_fields["account_id"]);
    } else {
        $account_name = '';
    }
    $contact_phone = '';
    if ($focus->column_fields["contact_id"] != '') {
        $contact_name = getContactName($focus->column_fields["contact_id"]);
        $contact_phone = getContactPhone($focus->column_fields["contact_id"]);
    } else {
        $contact_name = '';
    }
    $po_name = $focus->column_fields["purchaseorder"];
    $subject = $focus->column_fields["subject"];
    //scott
    $job_number = $focus->column_fields["subject"];
    $valid_till = $focus->column_fields["duedate"];
    $valid_till = getValidDisplayDate($valid_till);
    $bill_street = $focus->column_fields["bill_street"];
    $bill_city = $focus->column_fields["bill_city"];
    $bill_state = $focus->column_fields["bill_state"];
    $bill_code = $focus->column_fields["bill_code"];
    $bill_country = $focus->column_fields["bill_country"];
    $contact_name = getContactName($focus->column_fields["contact_id"]);
    $ship_street = $focus->column_fields["ship_street"];
    $ship_city = $focus->column_fields["ship_city"];
    $ship_state = $focus->column_fields["ship_state"];
    $ship_code = $focus->column_fields["ship_code"];
    $ship_country = $focus->column_fields["ship_country"];
    $conditions = from_html($focus->column_fields["terms_conditions"]);
    $description = from_html($focus->column_fields["description"]);
    $status = $focus->column_fields["sostatus"];
    // Company information
    $add_query = "select * from vtiger_organizationdetails";
    $result = $adb->pquery($add_query, array());
    $num_rows = $adb->num_rows($result);
    if ($num_rows > 0) {
        $org_name = $adb->query_result($result, 0, "organizationname");
        $org_address = $adb->query_result($result, 0, "address");
        $org_city = $adb->query_result($result, 0, "city");
        $org_state = $adb->query_result($result, 0, "state");
        $org_country = $adb->query_result($result, 0, "country");
        $org_code = $adb->query_result($result, 0, "code");
        $org_phone = $adb->query_result($result, 0, "phone");
        $org_fax = $adb->query_result($result, 0, "fax");
        $org_website = $adb->query_result($result, 0, "website");
        $logo_name = $adb->query_result($result, 0, "logoname");
    }
    //Population of Product Details - Starts
    //we can cut and paste the following lines in a file and include that file here is enough. For that we have to put a new common file. we will do this later
    //NOTE : Removed currency symbols and added with Grand Total text. it is enough to show the currency symbol in one place
    //we can also get the NetTotal, Final Discount Amount/Percent, Adjustment and GrandTotal from the array $associated_products[1]['final_details']
    //get the Associated Products for this Invoice
    $focus->id = $focus->column_fields["record_id"];
    $associated_products = getAssociatedProducts("SalesOrder", $focus);
    $num_products = count($associated_products);
    //This $final_details array will contain the final total, discount, Group Tax, S&H charge, S&H taxes and adjustment
    $final_details = $associated_products[1]['final_details'];
    //getting the Net Total
    $price_subtotal = number_format($final_details["hdnSubTotal"], 2, '.', ',');
    //Final discount amount/percentage
    $discount_amount = $final_details["discount_amount_final"];
    $discount_percent = $final_details["discount_percentage_final"];
    if ($discount_amount != "") {
        $price_discount = number_format($discount_amount, 2, '.', ',');
    } else {
        if ($discount_percent != "") {
            //This will be displayed near Discount label - used in include/fpdf/templates/body.php
            $final_price_discount_percent = "(" . number_format($discount_percent, 2, '.', ',') . " %)";
            $price_discount = number_format($discount_percent * $final_details["hdnSubTotal"] / 100, 2, '.', ',');
        } else {
            $price_discount = "0.00";
        }
    }
    //Adjustment
    $price_adjustment = number_format($final_details["adjustment"], 2, '.', ',');
    //Grand Total
    $price_total = number_format($final_details["grandTotal"], 2, '.', ',');
    //To calculate the group tax amount
    if ($final_details['taxtype'] == 'group') {
        $group_tax_total = $final_details['tax_totalamount'];
        $price_salestax = number_format($group_tax_total, 2, '.', ',');
        $group_total_tax_percent = '0.00';
        $group_tax_details = $final_details['taxes'];
        for ($i = 0; $i < count($group_tax_details); $i++) {
            $group_total_tax_percent = $group_total_tax_percent + $group_tax_details[$i]['percentage'];
        }
    }
    //S&H amount
    $sh_amount = $final_details['shipping_handling_charge'];
    $price_shipping = number_format($sh_amount, 2, '.', ',');
    //S&H taxes
    $sh_tax_details = $final_details['sh_taxes'];
    $sh_tax_percent = '0.00';
    for ($i = 0; $i < count($sh_tax_details); $i++) {
        $sh_tax_percent = $sh_tax_percent + $sh_tax_details[$i]['percentage'];
    }
    $sh_tax_amount = $final_details['shtax_totalamount'];
    $price_shipping_tax = number_format($sh_tax_amount, 2, '.', ',');
    $prod_line = array();
    $lines = 0;
    $prod_item = explode(",", $productlist);
    //updated by scott
    $num_products = count($prod_item);
    // updated by scott
    if ($productlist == '') {
        $num_products = count($associated_products);
        //if product list empty
        for ($k = 1; $k <= $num_products; $k++) {
            $prod_item[$k - 1] = $k;
        }
        //	Print_r($prod_item);
    }
    //	Print_r($prod_item);
    //	Print($num_products);
    //This is to get all prodcut details as row basis
    //	Print_r($associated_products);
    for ($k = 1, $j = $k - 1; $k <= $num_products; $k++, $j++) {
        $i = $prod_item[$k - 1];
        $product_name[$i] = $associated_products[$i]['productName' . $i];
        $subproduct_name[$i] = split("<br>", $associated_products[$i]['subprod_names' . $i]);
        //$prod_description[$i] = $associated_products[$i]['productDescription'.$i];
        $comment[$i] = $associated_products[$i]['comment' . $i];
        $product_id[$i] = $associated_products[$i]['hdnProductId' . $i];
        $qty[$i] = $associated_products[$i]['qty' . $i];
        $unit_price[$i] = number_format($associated_products[$i]['unitPrice' . $i], 2, '.', ',');
        $list_price[$i] = number_format($associated_products[$i]['listPrice' . $i], 2, '.', ',');
        $list_pricet[$i] = $associated_products[$i]['listPrice' . $i];
        $discount_total[$i] = $associated_products[$i]['discountTotal' . $i];
        //aded for 5.0.3 pdf changes
        $product_code[$i] = $associated_products[$i]['hdnProductcode' . $i];
        $taxable_total = $qty[$i] * $list_pricet[$i] - $discount_total[$i];
        $producttotal = $taxable_total;
        $total_taxes = '0.00';
        if ($focus->column_fields["hdnTaxType"] == "individual") {
            $total_tax_percent = '0.00';
            //This loop is to get all tax percentage and then calculate the total of all taxes
            for ($tax_count = 0; $tax_count < count($associated_products[$i]['taxes']); $tax_count++) {
                $tax_percent = $associated_products[$i]['taxes'][$tax_count]['percentage'];
                $total_tax_percent = $total_tax_percent + $tax_percent;
                $tax_amount = $taxable_total * $tax_percent / 100;
                $total_taxes = $total_taxes + $tax_amount;
            }
            $producttotal = $taxable_total + $total_taxes;
            $product_line[$j]["Tax"] = number_format($total_taxes, 2, '.', ',') . "\n ({$total_tax_percent} %) ";
            $price_salestax += $total_taxes;
        }
        $prod_total[$i] = number_format($producttotal, 2, '.', ',');
        $product_line[$j]["Count"] = $i . ".";
        $product_line[$j]["Product Code"] = $product_code[$i];
        $product_line[$j]["Qty"] = $qty[$i];
        $product_line[$j]["Units"] = "test";
        //scott $qty[$i];
        $product_line[$j]["Price"] = $list_price[$i];
        $product_line[$j]["Discount"] = $discount_total[$i];
        $product_line[$j]["Total"] = $prod_total[$i];
        $lines++;
        $product_line[$j]["Product Name"] = decode_html($product_name[$i]);
        $prod_line[$j] = 1;
        for ($count = 0; $count < count($subproduct_name[$i]); $count++) {
            if ($lines % 24 != 0) {
                $product_line[$j]["Product Name"] .= "\n" . decode_html($subproduct_name[$i][$count]);
                $prod_line[$j]++;
            } else {
                $j++;
                $product_line[$j]["Product Name"] = decode_html($product_name[$i]);
                $product_line[$j]["Product Name"] .= "\n" . decode_html($subproduct_name[$i][$count]);
                $prod_line[$j] = 2;
                $lines++;
            }
            $lines++;
        }
        if ($comment[$i] != '') {
            $product_line[$j]["Product Name"] .= "\n" . decode_html($comment[$i]);
            $prod_line[$j]++;
            $lines++;
        }
    }
    $price_salestax = number_format($price_salestax, 2, '.', ',');
    //echo '<pre>Product Details ==>';print_r($product_line);echo '</pre>';
    //echo '<pre>';print_r($associated_products);echo '</pre>';
    //Population of Product Details - Ends
    // ************************ END POPULATE DATA ***************************8
    $page_num = '1';
    $pdf = new PDF('P', 'mm', 'A4');
    $pdf->Open();
    //	$num_pages=ceil(($num_products/$products_per_page));
    //STARTS - Placement of products in pages as per the lines count
    $lines_per_page = "24";
    $prod_cnt = 0;
    $num_pages = ceil($lines / $lines_per_page);
    $tmp = 0;
    for ($count = 0; $count < $num_pages; $count++) {
        for ($k = $tmp; $k < $j; $k++) {
            if ($prod_cnt != 24) {
                $products[$count][] = $k;
                $prod_cnt += $prod_line[$k];
            } else {
                $tmp = $k;
                $prod_cnt = 0;
                break;
            }
        }
    }
    //ENDS - Placement of products in pages as per the lines count
    $current_product = 0;
    for ($l = 0; $l < $num_pages; $l++) {
        $line = array();
        if ($num_pages == $page_num) {
            $lastpage = 1;
        }
        /*while($current_product != $page_num*$products_per_page)
        		{
        			$line[]=$product_line[$current_product];
        			$current_product++;
        		}/*/
        foreach ($products[$l] as $index => $key) {
            $line[] = $product_line[$key];
        }
        $pdf->AddPage();
        include "modules/Deliverynote/pdf_templates/header.php";
        include "modules/Deliverynote/pdf_templates/dobody.php";
        //if bottom > 145 then we skip the Description and T&C in every page and display only in lastpage
        //if you want to display the description and T&C in each page then set the display_desc_tc='true' and bottom <= 145 in pdfconfig.php
        if ($display_desc_tc == 'true') {
            if ($bottom <= 145) {
                include "modules/Deliverynote/pdf_templates/footer.php";
            }
        }
        $page_num++;
        //scott last page remove:	if (($endpage) && ($lastpage))
        //scott last page remove:	{
        //scott last page remove:		$pdf->AddPage();
        //scott last page remove:		include("modules/Deliverynote/pdf_templates/header.php");
        //scott last page remove:		include("modules/Deliverynote/pdf_templates/lastpage/body.php");
        //scott last page remove:		include("modules/Deliverynote/pdf_templates/lastpage/footer.php");
        //scott last page remove:	}
    }
    return $pdf;
}
Esempio n. 6
0
 /**
  * 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);
 }