<?php
include("../public/impOpreation.php");
include("../library/uploadImages.php");
$do = $_GET['do'];
$today = date("Y-m-d H:i:s");
$date = date("Y-m-d");

if (empty($do)) {  
    $smarty->display("header.html");

    $allChasis = R::getCol('SELECT chassisNo from productserial join buybill on buybillid = billid where chassisNo != "" and del = 0 and conditions = 0');
    $smarty->assign('allChasis', $allChasis);
    
    $smarty->display("carchasisview/add.html");
    $smarty->display("footer.html");
}else if ($do == 'savedata') {
    $oldChasis = filter_input(INPUT_POST, 'oldChasis');
    $chasis = filter_input(INPUT_POST, 'chasis');
    try {
        if ($oldChasis && $chasis)
        {
            echo 222;
            R::debug(true);
            R::exec('UPDATE productserial SET chassisNo = "'.$chasis.'" WHERE chassisNo = "'.$oldChasis.'"');
            R::exec('UPDATE carfile SET chasis = "'.$chasis.'" WHERE chasis = "'.$oldChasis.'"');
            R::exec('UPDATE cars SET chasisno = "'.$chasis.'" WHERE chasisno = "'.$oldChasis.'"');
            R::exec('UPDATE cartracking SET chasis = "'.$chasis.'" WHERE chasis = "'.$oldChasis.'"');
            R::exec('UPDATE commentclient SET chasis = "'.$chasis.'" WHERE chasis = "'.$oldChasis.'"');
            R::exec('UPDATE importcontract SET chasisno = "'.$chasis.'" WHERE chasisno = "'.$oldChasis.'"');
            R::exec('UPDATE expenses SET chasis = "'.$chasis.'" WHERE chasis = "'.$oldChasis.'"');
            R::exec('UPDATE sellbill SET carchase = "'.$chasis.'" WHERE carchase = "'.$oldChasis.'"');
            R::exec('UPDATE shippingfile SET chasis = "'.$chasis.'" WHERE chasis = "'.$oldChasis.'"');
        }
        header("location:carChasisController.php");
    } catch (Exception $e) {
        header("location:carChasisController.php");
    }
}



