everseiko/application/controllers/form.php

558 lines
15 KiB
PHP
Raw Normal View History

2020-01-02 23:02:57 +07:00
<?php
class Form extends CI_Controller{
function __Construct()
{
parent ::__construct();
$this->load->model('M_form');
}
function index()
{
if($this->auth->CI->session->userdata('is_log_in')){
$this->load->view('vForm2');
}
else{
$this->load->view('vlogin');
}
$array_items = array('status' => '', 'tipe' => '', 'message' => '');
$this->session->unset_userdata($array_items);
}
//view form untuk admin
function view_form($action,$id)
{
$data['action']=$action;
//$data['form']=$this->M_form->getVisit($id);
$data['id']= $id;
$this->load->view('vReview', $data);
}
//get
function getDataAjax($id)
{
//$id = 7;
$data['customer'] = $this->M_form->getCust($id);
$data['visit'] = $this->M_form->getVisit($id);
$data['vehicle'] = $this->M_form->getVehicle($id);
$data['purchase'] = $this->M_form->getPurchase($id);
$data['recommendation'] = $this->M_form->getRecommendation($id);
$data['pictures'] = $this->M_form->getPictures($id);
echo JSON_ENCODE($data);
}
//load customer name
function searchcustomer($clu)
{
$data = $this->M_form->searchcustomer($clu);
echo JSON_ENCODE($data);
}
//update status isApprove form
function isApprove($id)
{
$cds = array (
'1' => $this->input->POST('modalcb1'),
'2' => $this->input->POST('modalcb2'),
'3' => $this->input->POST('modalcb3')
);
$cds = array_filter($cds, 'strlen');
$cds = implode(',' ,$cds);
$data = array (
'id_customer' => $this->input->POST('ID'),
'tier' => $this->input->POST('tier'),
'customer_data_status' => $cds,
'isApprove' => 1
);
$this->M_form->isApprove($data, $id);
$notif = array(
'status' => '1',
'tipe' => 'alert-success',
'message' => '<strong>Well Done</strong> | Form is approved'
);
$this->session->set_userdata($notif);
redirect('user','refresh');
}
//updateform
function updateform($id)
{
$notif = array(
'status' => '1',
'tipe' => 'alert-success',
'message' => '<strong>Well Done</strong> | Form Updated'
);
$this->session->set_userdata($notif);
redirect('user','refresh');
}
//submit form
function form_submit()
{
//customer
$datacustomer = array (
'id' => '',
'id_user' => '',
'nama' => $this->input->POST('cdCusName'),
'tipe' => $this->input->POST('rbCd2')
);
//visit
$nature_bisnis = array (
'1' => $this->input->POST('cdCb_1'),
'2' => $this->input->POST('cdCb_2'),
'3' => $this->input->POST('cdCb_3'),
'4' => $this->input->POST('cdCb_4'),
'5' => $this->input->POST('cdCb_5'),
'6' => $this->input->POST('cdCb_6'),
'7' => $this->input->POST('cdCb_7')
);
$nature_bisnis = array_filter($nature_bisnis, 'strlen');
$nature_bisnis = implode(',' ,$nature_bisnis);
$type_of_loads ="";
$type_of_loads = array (
'1' => $this->input->POST('vdCb_1'),
'2' => $this->input->POST('vdCb_2'),
'3' => $this->input->POST('vdCb_3'),
'4' => $this->input->POST('vdCb_4'),
'5' => $this->input->POST('vdCb_5'),
'6' => $this->input->POST('vdCb_6')
);
$type_of_loads = array_filter($type_of_loads, 'strlen');
$type_of_loads = implode(',' ,$type_of_loads);
$tyre_brands = array (
'1' => $this->input->POST('tpCb_1'),
'2' => $this->input->POST('tpCb_2'),
'3' => $this->input->POST('tpCb_3'),
'4' => $this->input->POST('tpCb_4'),
'5' => $this->input->POST('tpCb_5'),
'6' => $this->input->POST('tpCb_6'),
'7' => $this->input->POST('tpCb_7'),
'8' => $this->input->POST('tpCb_8'),
'9' => $this->input->POST('tpCb_9'),
'10' => $this->input->POST('tpCb_10'),
'11' => $this->input->POST('tpCb_11'),
'12' => $this->input->POST('tpCb_12'),
'13' => $this->input->POST('tpCb_13'),
'14' => $this->input->POST('tpCb_14'),
'15' => $this->input->POST('tpCb_15')
);
$tyre_brands = array_filter($tyre_brands, 'strlen');
$tyre_brands = implode(',' ,$tyre_brands);
$tyre_purchase = array (
'1' => $this->input->POST('tpCb2_1'),
'2' => $this->input->POST('tpCb2_2')
);
$tyre_purchase = array_filter($tyre_purchase, 'strlen');
$tyre_purchase = implode(',' ,$tyre_purchase);
$tire_types = array (
'1' => $this->input->POST('tpCb3_1'),
'2' => $this->input->POST('tpCb3_2'),
'3' => $this->input->POST('tpCb3_3'),
'4' => $this->input->POST('tpCb3_4')
);
$tire_types = array_filter($tire_types, 'strlen');
$tire_types = implode(',' ,$tire_types);
$cond_front = array (
'1' => $this->input->POST('cb31'),
'2' => $this->input->POST('cb32')
);
$cond_front = array_filter($cond_front, 'strlen');
$cond_front = implode(',' ,$cond_front);
$cond_rear = array (
'1' => $this->input->POST('cb41'),
'2' => $this->input->POST('cb42')
);
$cond_rear = array_filter($cond_rear, 'strlen');
$cond_rear = implode(',' ,$cond_rear);
if ($this->input->POST('rbCd')=="Other")$method = $this->input->POST('rbCdO');
else $method = $this->input->POST('rbCd');
$datavisit = array (
'id' => '',
'longitude' => '',
'latitude' => '',
'province' => $this->input->POST('cdProvince'),
'kota' => $this->input->POST('cdKota'),
'date_visit' => date('Y-m-d H:j:s'),
'id_staff' => '',
'id_customer' => '',
'visit_status' => $method,
'head_address' => $this->input->POST('cdOffice'),
'head_phone' => $this->input->POST('cdTelp'),
'branch_address' => $this->input->POST('cdBranch'),
'branch_phone' => $this->input->POST('cdTelp2'),
'cp_name' => $this->input->POST('cdcpname'),
'cp_phone' => $this->input->POST('cdcpphone'),
'nature_bisnis' => $nature_bisnis,
'loads' => $type_of_loads,
'destination' => $this->input->POST('vdDest'),
'road_condition_good' => $this->input->POST('vdgoro'),
'road_condition_toll' => $this->input->POST('vdtoro'),
'road_condition_bad' => $this->input->POST('vdbaro'),
'road_condition_other' => $this->input->POST('vdothers'),
'tire_brands' => $tyre_brands,
'tire_purchases' => $tyre_purchase,
'tire_types' => $tire_types,
'tire_other' => '',
'mileage_method' => $this->input->POST('trRb'),
'mileage_front' => $this->input->POST('trmfront'),
'mileage_rear' => $this->input->POST('trmrear'),
'mileage_detail' => $this->input->POST('trmdetails'),
'purchase_method' => $this->input->POST('trRb2'),
'purchase_number' => $this->input->POST(''),
'psi_front' => $this->input->POST('trfpsi'),
'condition_front' => $cond_rear,
'psi_rear' => $this->input->POST('trrpsi'),
'condition_rear' => $cond_front,
'otr' => $this->input->POST('trotr'),
'problem' => $this->input->POST('trproblem'),
'notes' => '',
'pictures' => '',
'sender' => $this->input->POST('cdSos'),
'customer' => $this->input->POST('cdCusName'),
'tier' => '',
'customer_data_status' => '',
'qty' => '',
'category' => ''
);
//customer vehicle
$datavehicle = '';
$i = 0;
if ($this->input->POST('vdTr4')!='')
{
$datavehicle[$i] = array (
'id' => '',
'id_visit' => '',
'category' => 'Truck',
'type' => 'Light',
'qty' => $this->input->POST('vdTr4'),
'total_tire' => '4',
'load_weight' => $this->input->POST('vdTr4wt')
);
$i++;
}
if ($this->input->POST('vdTr6')!='')
{
$datavehicle[$i] = array (
'id' => '',
'id_visit' => '',
'category' => 'Truck',
'type' => 'Light',
'qty' => $this->input->POST('vdTr6'),
'total_tire' => '6',
'load_weight' => $this->input->POST('vdTr6wt')
);
$i++;
}
if ($this->input->POST('vdTr10')!='')
{
$datavehicle[$i] = array (
'id' => '',
'id_visit' => '',
'category' => 'Truck',
'type' => 'Light',
'qty' => $this->input->POST('vdTr10'),
'total_tire' => '10',
'load_weight' => $this->input->POST('vdTr10wt')
);
$i++;
}
if ($this->input->POST('vdLt6')!='')
{
$datavehicle[$i] = array (
'id' => '',
'id_visit' => '',
'category' => 'Truck',
'type' => 'Normal',
'qty' => $this->input->POST('vdLt6'),
'total_tire' => '6',
'load_weight' => $this->input->POST('vdLt6wt')
);
$i++;
}
if ($this->input->POST('vdLt8')!='')
{
$datavehicle[$i] = array (
'id' => '',
'id_visit' => '',
'category' => 'Truck',
'type' => 'Normal',
'qty' => $this->input->POST('vdLt8'),
'total_tire' => '8',
'load_weight' => $this->input->POST('vdLt8wt')
);
$i++;
}
if ($this->input->POST('vdLt10')!='')
{
$datavehicle[$i] = array (
'id' => '',
'id_visit' => '',
'category' => 'Truck',
'type' => 'Normal',
'qty' => $this->input->POST('vdLt10'),
'total_tire' => '10',
'load_weight' => $this->input->POST('vdLt10wt')
);
$i++;
}
if ($this->input->POST('vdLt12')!='')
{
$datavehicle[$i] = array (
'id' => '',
'id_visit' => '',
'category' => 'Truck',
'type' => 'Normal',
'qty' => $this->input->POST('vdLt12'),
'total_tire' => '12',
'load_weight' => $this->input->POST('vdLt12wt')
);
$i++;
}
if ($this->input->POST('vdLt14')!='')
{
$datavehicle[$i] = array (
'id' => '',
'id_visit' => '',
'category' => 'Truck',
'type' => 'Normal',
'qty' => $this->input->POST('vdLt14'),
'total_tire' => '14',
'load_weight' => $this->input->POST('vdLt14wt')
);
$i++;
}
if ($this->input->POST('vdLt18')!='')
{
$datavehicle[$i] = array (
'id' => '',
'id_visit' => '',
'category' => 'Truck',
'type' => 'Normal',
'qty' => $this->input->POST('vdLt18'),
'total_tire' => '18',
'load_weight' => $this->input->POST('vdLt18wt')
);
$i++;
}
if ($this->input->POST('vdLtot')!='')
{
$datavehicle[$i] = array (
'id' => '',
'id_visit' => '',
'category' => 'Truck',
'type' => 'Normal',
'qty' => $this->input->POST('vdLtot'),
'total_tire' => '-1',
'load_weight' => $this->input->POST('vdLtotwt')
);
$i++;
}
/*
'otr1Type' => $this->input->POST('vdQtrType'),
'otr1Qty' => $this->input->POST('vdQtrQty'),
'otr1Tyre' => $this->input->POST('vdQtrTyre')
*/
//purchase
$countpurchase = 0;
$purchase = array (
'MRFp' => $this->input->POST('pattern'),
'MRFs' => $this->input->POST('size'),
'MRFq' => $this->input->POST('qty'),
'OTHb' => $this->input->POST('obrand'),
'OTHp' => $this->input->POST('opattern'),
'OTHs' => $this->input->POST('osize'),
'OTHq' => $this->input->POST('oqty')
);
//$mrfc = $this->input->POST('MRFcount');
$count = count($purchase['MRFp']);
for ($k = 0 ; $k < $count ; $k++)
{
$datapurchase[$countpurchase] = array (
'id' => '',
'id_visit' => '',
'brand' => 'MRF',
'pattern' => $purchase['MRFp'][$k],
'size' => $purchase['MRFs'][$k],
'qty' => $purchase['MRFq'][$k]
);
$countpurchase++;
}
$count2 = count($purchase['OTHp']);
$v = 0;
for ($n = 0 ; $n < $count2 ; $n++)
{
$datapurchase[$countpurchase] = array (
'id' => '',
'id_visit' => '',
'brand' => $purchase['OTHb'][$v],
'pattern' => $purchase['OTHp'][$n],
'size' => $purchase['OTHs'][$n],
'qty' => $purchase['OTHq'][$n]
);
$countpurchase++;
$v++;
}
//recommendation
$countrcm = 0;
$recommend = array (
'pattern' => $this->input->POST('rpattern'),
'size' => $this->input->POST('rsize'),
'remark' => $this->input->POST('rremark')
);
$count3 = count($recommend['pattern']);;
for ($n = 0 ; $n < $count3 ; $n++)
{
$datarecommended[$countrcm] = array (
'id' => '',
'id_visit' => '',
'pattern' => $recommend['pattern'][$n],
'size' => $recommend['size'][$n],
'remark' => $recommend['remark'][$n],
);
$countrcm++;
}
$data = array(
'customer' => $datacustomer,
'visit' => $datavisit,
'vehicle' => $datavehicle,
'purchase' => $datapurchase,
'recommendation' => $datarecommended
);
//$this->submit_form($data);
echo JSON_ENCODE($data);
}
//insert
function submit_form($data)
{
//customer
$idc = 4;
$idc = $this->M_form->insertcustomer($data['customer']);
//visit
$data['visit']['id_customer'] = $idc;
$idv = 3;
$idv = $this->M_form->insertvisit($data['visit']);
//vehicle
for ($i=0;$i<count($data['vehicle']);$i++)
{
$data['vehicle'][$i]['id_visit'] = $idv;
}
for ($j = 0 ; $j < $i ; $j++)
{
$this->M_form->insertvehicle($data['vehicle'][$j]);
}
//purchase
for ($i=0;$i<count($data['purchase']);$i++)
{
$data['purchase'][$i]['id_visit'] = $idv;
}
for ($j = 0 ; $j < count($data['purchase']) ; $j++)
{
$this->M_form->insertpurchase($data['purchase'][$j]);
}
//recommendation
for ($i=0;$i<count($data['recommendation']);$i++)
{
$data['recommendation'][$i]['id_visit'] = $idv;
}
for ($j = 0 ; $j < count($data['recommendation']) ; $j++)
{
$this->M_form->insertrecommended($data['recommendation'][$j]);
}
$notif = array(
'status' => '1',
'tipe' => 'alert-success',
'message' => '<strong>Well Done</strong> | Form is Submitted'
);
$this->session->set_userdata($notif);
redirect('user','refresh');
//echo JSON_ENCODE($data);
}
function addSellout()
{
$data = array (
'id_customer' => $this->input->POST('ID'),
'customer' => $this->input->POST('customer'),
'bulan' => $this->input->POST('bulan'),
'tahun' => $this->input->POST('tahun'),
'qty' => $this->input->POST('qty')
);
$this->M_form->newSellout($data);
$notif = array(
'status' => '1',
'tipe' => 'alert-success',
'message' => '<strong>Well Done</strong> | Selling out added'
);
$this->session->set_userdata($notif);
redirect('user','refresh');
}
function addVolume()
{
$data = array (
'id' => '',
'dealer' => $this->input->POST('dealer'),
'area' => $this->input->POST('area'),
'region' => $this->input->POST('region'),
'province' => $this->input->POST('province'),
'date' => $this->input->POST('date'),
'target' => $this->input->POST('target'),
'previous_stock'=> $this->input->POST('prevstock'),
'actual' => $this->input->POST('actual'),
'sellout' => $this->input->POST('sellout'),
'order' => $this->input->POST('order'),
'pattern' => $this->input->POST('pattern')
);
$data['current_stock'] = $data['previous_stock']+$data['actual']-$data['sellout'];
$pattern = $this->input->POST('pattern');
if(($pattern== ("7.50-16 M77")) or ($pattern==("7.50-16 SLUG")) or ($pattern==("7.50-16 SM95")))
{
$data['category'] = 'Light Truck';
}
else $data['category'] = 'Truck';
$data['service_level'] = $data['actual'] / $data['order'];
//echo JSON_ENCODE($data);
$this->M_form->newVolume($data);
$notif = array(
'status' => '1',
'tipe' => 'alert-success',
'message' => '<strong>Well Done</strong> | Volume added'
);
$this->session->set_userdata($notif);
redirect('user','refresh');
}
function loadwilayah()
{
$data = $this->M_form->getwilayah();
echo JSON_ENCODE($data);
}
}