<?php

include $_SERVER['DOCUMENT_ROOT'] . "/classes/autoload.php";

if ($_POST['cost'] == "") {
    $_POST['cost'] = 0.0;
}
if ($_POST['retail'] == "") {
    $_POST['retail'] = 0.0;
}
if ($_POST['contractors'] == "") {
    $_POST['contractors'] = 0.0;
}
if ($_POST['shops'] == "") {
    $_POST['shops'] = 0.0;
}


$client_id = $db->query("stock", "UPDATE `stock` SET `name`='{$_POST['name']}', `cost`='" . number_format(str_replace(',', '.', preg_replace('/[^\d\.\-]/', '', $_POST['cost'])), 2, '.', '') . "', `retail`='" . number_format(str_replace(',', '.', preg_replace('/[^\d\.\-]/', '', $_POST['retail'])), 2, '.', '') . "', `unit_of_measure`='{$_POST['unit_of_measure']}', `status`='{$_POST['status']}', `supplier_id`='{$_POST['supplier_id']}',`code` = '{$_POST['code']}',`contractors` = '" . number_format(str_replace(',', '.', preg_replace('/[^\d\.\-]/', '', $_POST['contractors'])), 2, '.', '') . "',`shops` =  '" . number_format(str_replace(',', '.', preg_replace('/[^\d\.\-]/', '', $_POST['shops'])), 2, '.', '') . "',`stock_categories` =  '{$_POST['stock_categories']}' WHERE `record_id`={$_POST['record_id']}");
if ($client_id > 0) {
    header("location: home.php");
}