295 lines
9.2 KiB
PHP
295 lines
9.2 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
class Android_automation_job_details extends Admin_Controller
|
|
{
|
|
|
|
public $viewData = array();
|
|
public $pagePerItem = 50;
|
|
public $statusOptions = [
|
|
'Inactive' => '0',
|
|
'Active' => '1',
|
|
];
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
// Load model
|
|
$this->load->model('android_automation_job_detail_model', 'android_automation_job_detail');
|
|
$this->load->model('transport_provider_model', 'transport_provider');
|
|
$this->load->model('automation_job_model', 'automation_job');
|
|
$this->load->helper('pagination');
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$this->load->helper(array('url'));
|
|
|
|
//get query string filter
|
|
$filterData = $this->input->get();
|
|
$queryString = $this->input->server('QUERY_STRING');
|
|
|
|
$pagingUrl = empty($queryString) ? uri_string() : uri_string() . '?' . $queryString;
|
|
$pagingUrl = remove_querystring_var($pagingUrl, 'page');
|
|
|
|
$data = $this->android_automation_job_detail->getAndroidAutomationJobDetail(
|
|
[
|
|
'transport_provider_id' => !empty($filterData['transport_provider_id'])
|
|
? $filterData['transport_provider_id']
|
|
: '',
|
|
'job_id' => empty($filterData['job_id'])
|
|
? ''
|
|
: $filterData['job_id'],
|
|
'uuid' => empty($filterData['uuid'])
|
|
? ''
|
|
: $filterData['uuid'],
|
|
'name' => empty($filterData['name'])
|
|
? ''
|
|
: $filterData['name'],
|
|
'service_id' => empty($filterData['service_id'])
|
|
? ''
|
|
: $filterData['service_id'],
|
|
'page' => isset($filterData['page']) ? $filterData['page'] : 1
|
|
]
|
|
);
|
|
|
|
$transport_provider = [];
|
|
// Change data to array for display
|
|
foreach ($data['transport_providers'] as $tp) {
|
|
$transport_provider[] = (array) $tp;
|
|
}
|
|
$this->viewData['transport_provider'] = $transport_provider;
|
|
|
|
$data['list'] = array_map(function($item) {
|
|
|
|
$item['quote_date'] = $this->formatDate($item['quote_date']);
|
|
return $item;
|
|
|
|
}, $data['list']);
|
|
|
|
$this->viewData['list'] = $data['list'];
|
|
$this->viewData['statusOptions'] = $this->statusOptions;
|
|
$this->viewData['filterData'] = $filterData;
|
|
$this->viewData['pagination'] = initPagination($this->pagePerItem, $data['totalItems'], $data['page'], $pagingUrl);
|
|
$this->renderAdminPage('android_automation_job_details/list', $this->viewData);
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
$this->load->helper(array('form', 'url'));
|
|
$this->viewData['statusOptions'] = $this->statusOptions;
|
|
$this->viewData['android_automation_job_detail'] = null;
|
|
$this->renderAdminPage('android_automation_job_details/create', $this->viewData);
|
|
}
|
|
|
|
public function store()
|
|
{
|
|
$this->load->helper(array('form', 'url'));
|
|
$this->load->library('form_validation');
|
|
|
|
$inputData = $this->getFormData();
|
|
|
|
$this->viewData['android_automation_job_detail'] = $inputData;
|
|
$this->viewData['statusOptions'] = $this->statusOptions;
|
|
$this->setAndroidAutomationJobDetailCreationRules();
|
|
|
|
if ($this->form_validation->run() == false) {
|
|
$this->renderAdminPage('android_automation_job_details/create', $this->viewData);
|
|
return;
|
|
}
|
|
|
|
$res = $this->android_automation_job_detail->createAndroidAutomationJobDetail($inputData);
|
|
|
|
if ($res['status'] == 'success') {
|
|
$this->session->set_flashdata('success', isset($res['message']) ? $res['message'] : 'Create success.');
|
|
redirect('/android_automation_job_details');
|
|
} else {
|
|
$this->session->set_flashdata('error', isset($res['message']) ? $res['message'] : 'Create fail.');
|
|
$this->renderAdminPage('android_automation_job_details/create', $this->viewData);
|
|
return;
|
|
}
|
|
}
|
|
|
|
private function formatDate($date) {
|
|
|
|
return (new DateTime($date))->format('Y-m-d');
|
|
|
|
}
|
|
|
|
public function edit($id)
|
|
{
|
|
$this->load->helper(array('form', 'url'));
|
|
$res = $this->android_automation_job_detail->getAndroidAutomationJobDetailByID($id);
|
|
|
|
if ($res['data']) {
|
|
$res['data']['quote_date'] = $this->formatDate($res['data']['quote_date']);
|
|
}
|
|
|
|
$this->viewData['android_automation_job_detail'] = isset($res['data']) ? $res['data'] : [];
|
|
$this->viewData['statusOptions'] = $this->statusOptions;
|
|
$this->viewData['id'] = $id;
|
|
$this->renderAdminPage('android_automation_job_details/edit', $this->viewData);
|
|
}
|
|
|
|
public function update($id)
|
|
{
|
|
|
|
$this->load->helper(array('form', 'url'));
|
|
$this->load->library('form_validation');
|
|
|
|
$inputData = $this->getFormData();
|
|
|
|
$this->viewData['statusOptions'] = $this->statusOptions;
|
|
$this->viewData['android_automation_job_detail'] = $inputData;
|
|
$this->viewData['id'] = $id;
|
|
$this->setAndroidAutomationJobDetailCreationRules();
|
|
|
|
if ($this->form_validation->run() == false) {
|
|
$this->renderAdminPage('android_automation_job_details/edit', $this->viewData);
|
|
return;
|
|
}
|
|
|
|
$res = $this->android_automation_job_detail->updateAndroidAutomationJobDetailById($id, $inputData);
|
|
|
|
if ($res['status'] == 'success') {
|
|
$this->session->set_flashdata('success', isset($res['message']) ? $res['message'] : 'Create success');
|
|
redirect('/android_automation_job_details');
|
|
} else {
|
|
$this->session->set_flashdata('error', $res['message']);
|
|
$this->renderAdminPage('android_automation_job_details/edit', $this->viewData);
|
|
return;
|
|
}
|
|
}
|
|
|
|
public function remove($param)
|
|
{
|
|
$res = $this->android_automation_job_detail->removeAndroidAutomationJobDetailById($param);
|
|
if (!$res['success'] != 'success') {
|
|
$this->viewData['errMsg'] = isset($res['message']) ? $res['message'] : 'Something went wrong. Please try again later.';
|
|
$this->renderAdminPage('android_automation_job_details', $this->viewData);
|
|
return;
|
|
}
|
|
|
|
redirect('/android_automation_job_details');
|
|
}
|
|
|
|
protected function renderAdminPage($page_name, $data)
|
|
{
|
|
$this->load->view('admin/view_admin_header', $data);
|
|
$this->load->view($page_name, $data);
|
|
$this->load->view('admin/view_admin_footer', $data);
|
|
}
|
|
|
|
private function getFormData()
|
|
{
|
|
return [
|
|
'job_id' => $this->input->post('job_id'),
|
|
'icon_info' => $this->input->post('icon_info'),
|
|
'name' => $this->input->post('name'),
|
|
'icon_url' => $this->input->post('icon_url'),
|
|
'descriptor' => $this->input->post('descriptor'),
|
|
'warning_message' => $this->input->post('warning_message'),
|
|
'uuid' => $this->input->post('uuid'),
|
|
'series_id' => $this->input->post('series_id'),
|
|
'service_id' => $this->input->post('service_id'),
|
|
'additional_booking_fee' => $this->input->post('additional_booking_fee'),
|
|
'advance_booking_fee' => $this->input->post('advance_booking_fee'),
|
|
'low_estimate' => $this->input->post('low_estimate'),
|
|
'high_estimate' => $this->input->post('high_estimate'),
|
|
'fixed' => $this->input->post('fixed'),
|
|
'quote_date' => $this->input->post('quote_date'),
|
|
];
|
|
}
|
|
|
|
private function setAndroidAutomationJobDetailCreationRules()
|
|
{
|
|
$config = [
|
|
[
|
|
'field' => 'job_id',
|
|
'label' => 'Job ID',
|
|
'rules' => 'required',
|
|
],
|
|
[
|
|
'field' => 'icon_info',
|
|
'label' => 'Icon Info',
|
|
'rules' => 'required',
|
|
],
|
|
[
|
|
'field' => 'name',
|
|
'label' => 'Nmae',
|
|
'rules' => 'required',
|
|
],
|
|
[
|
|
'field' => 'icon_url',
|
|
'label' => 'Icon Url',
|
|
'rules' => 'required',
|
|
],
|
|
[
|
|
'field' => 'descriptor',
|
|
'label' => 'Descriptor',
|
|
'rules' => 'required'
|
|
],
|
|
[
|
|
'field' => 'warning_message',
|
|
'label' => 'Warning Message',
|
|
'rules' => 'required',
|
|
],
|
|
[
|
|
'field' => 'uuid',
|
|
'label' => 'UUID',
|
|
'rules' => 'required',
|
|
],
|
|
[
|
|
'field' => 'series_id',
|
|
'label' => 'Series ID',
|
|
'rules' => 'required',
|
|
],
|
|
[
|
|
'field' => 'service_id',
|
|
'label' => 'Service ID',
|
|
'rules' => 'required',
|
|
],
|
|
[
|
|
'field' => 'additional_booking_fee',
|
|
'label' => 'Additional Booking Fee',
|
|
'rules' => 'required',
|
|
],
|
|
[
|
|
'field' => 'advance_booking_fee',
|
|
'label' => 'Advance Booking Fee',
|
|
'rules' => 'required',
|
|
],
|
|
[
|
|
'field' => 'low_estimate',
|
|
'label' => 'Low Estimate',
|
|
'rules' => 'required',
|
|
],
|
|
[
|
|
'field' => 'high_estimate',
|
|
'label' => 'High Estimate',
|
|
'rules' => 'required',
|
|
],
|
|
[
|
|
'field' => 'fixed',
|
|
'label' => 'Fixed',
|
|
'rules' => 'required',
|
|
],
|
|
[
|
|
'field' => 'quote_date',
|
|
'label' => 'Quote Date',
|
|
'rules' => 'required',
|
|
]
|
|
];
|
|
|
|
$this->form_validation->set_rules($config);
|
|
}
|
|
|
|
public function getTransportProviderByName() {
|
|
|
|
$name = $this->input->get()['q'];
|
|
$res = $this->transport_provider->getTransportProviderByName($name);
|
|
|
|
echo json_encode($res);
|
|
}
|
|
}
|