<?php
namespace App\Controllers;
use Config\Services;

class Addengdescription extends BaseController{
    private $dbHandle;

    public function index(){
        $this->dbHandle   = \Config\Database::connect();
        $dataToReturn = [];

        $now = time();
        $engseatingarr = explode('|',$this->request->getVar('englayout'));
         
        $data = [
            'make' => $this->request->getVar('make'),
            'engine' => strtoupper($this->request->getVar('engine')),
            'capacity' => floatval($this->request->getVar('capacity')),
            'inlitres' => number_format(floatval($this->request->getVar('capacity')) / 1000, 1) ,
            'fueltype' => $this->request->getVar('fueltype'),
            'englayout' => $engseatingarr[0],
            'noofplugs' => $engseatingarr[1],
            'note' => $this->request->getVar('note'),
            'personnel' => $this->request->getVar('personnel'),
            'transactdate' => date('Y-m-d H:i:s', $now)
        ];
        
        $this->dbHandle->table('enginedescriptions')->insert($data);
        $E = $this->dbHandle->error();
        $dataToReturn['status'] = $E['code'];

        return json_encode($dataToReturn, JSON_HEX_APOS | JSON_HEX_QUOT);
    }
}