public function pickup($shp_id)
{
if (!$this->is_logged) {
redirect("user/login");
}
try {
$user_id = $this->user_model->get_current_user_id();
$shiping_data = $this->shipping_model->get_shipment($shp_id);
$shiping_data['fromaddr'] = $this->address_model->get_addr_combo('Sender');
$shiping_data['scountry'] = $this->address_model->get_country_combo();
if ($shiping_data['shp_user'] == $user_id) {
$shipment = \EasyPost\Shipment::retrieve($shiping_data['shp_ep_ref']);
$btnschedule = $this->input->post('btnschedule');
if (!empty($btnschedule)) {
$selfromaddr = $this->input->post('selfromaddr');
$country_code = $this->address_model->get_iso_code_from_country($this->input->post('txtscountry'));
$data = array('adr_name' => $this->input->post('txtsname'), 'adr_contact' => $this->input->post('txtscontact'), 'adr_street1' => $this->input->post('txtsstr1'), 'adr_street2' => $this->input->post('txtsstr2'), 'adr_city' => $this->input->post('txtscity'), 'adr_state' => $this->input->post('txtsstate'), 'adr_country' => $country_code, 'adr_phone' => $this->input->post('txtsphone'), 'adr_zip' => $this->input->post('txtszip'), 'adr_email' => $this->input->post('txtsemail'), 'adr_type' => 'Sender', 'adr_userid' => $user_id);
if (empty($selfromaddr)) {
$selfromaddr = $this->address_model->insert_addr($data);
} else {
$savesaddr = $this->input->post('savesaddr');
if (!empty($savesaddr)) {
$where = array('adr_id' => $selfromaddr);
$this->address_model->update_addr($data, $where);
}
}
$faddr = $this->address_model->get_booking_addr($selfromaddr);
$from_address = \EasyPost\Address::create_and_verify(array('name' => $faddr['adr_contact'], 'street1' => $faddr['adr_street1'], 'street2' => $faddr['adr_street2'], 'city' => $faddr['city_name'], 'state' => $faddr['state_name'], 'zip' => $faddr['adr_zip'], 'country' => 'US', 'phone' => $faddr['adr_phone'], 'email' => $faddr['adr_email']));
$instructions = $this->input->post('txtins');
$min_date = $shiping_data['shp_date'] . " " . $this->input->post('txtrtime') . ":00";
$max_date = $shiping_data['shp_date'] . " " . $this->input->post('txtctime') . ":00";
$data = array('address' => $from_address, 'shipment' => $shipment, 'max_datetime' => $max_date, 'min_datetime' => $min_date, 'instructions' => $instructions);
$pickup = \EasyPost\Pickup::create($data);
$response = $pickup->buy(array('carrier' => 'DHLExpress'));
$response = $response->__toArray(true);
$shpdata = array('shp_pickupid' => $response['id'], 'shp_pickupconf' => $response['confirmation'], 'shp_scheduled' => 1);
$where = array('shp_id' => $shp_id);
$this->shipping_model->update($shpdata, $where);
$data['message'] = 'Pickup Information Updated..';
$this->load->template('history', $data);
return;
}
} else {
die('Access Denied...');
}
} catch (Exception $ex) {
$shiping_data['error'] = $ex->getMessage();
}
$this->load->template("pickup", $shiping_data);
}