<?php
header('Content-Type: text/html; charset=utf-8');
include("con.php"); //insert data server
try {
// read from products table
$sqlproducts = "SELECT product_name, product_number FROM products ORDER BY product_name ASC";
$stmt1 = $pdo->prepare($sqlproducts);
$stmt1->execute();
$resultsproducts = $stmt1->fetchAll(PDO::FETCH_ASSOC);
// read from suppliers table
$sqlsuppliers = "SELECT supplier_name, ID FROM suppliers ORDER BY supplier_name ASC";
$stmt2 = $pdo->prepare($sqlsuppliers);
$stmt2->execute();
$resultssupliers = $stmt2->fetchAll(PDO::FETCH_ASSOC);
if($_SERVER['REQUEST_METHOD'] == 'POST') {
$pdo->beginTransaction();
$prodnumber = $_REQUEST["output"];
$suppliernumber = $_REQUEST["output1"];
$amount = $_POST['amount'];
$project_number = 0;
$amount_out = 0;
/*
echo "Prod:";
echo $prodnumber;
echo '<br>';
echo "Supplier:";
echo $suppliernumber;
echo '<br>';
echo "Amount:";
echo $amount;
echo '<br>';
*/
if(empty($prodnumber) || empty($suppliernumber) || empty($amount)) {
?>
<div id="dialog-message" title="שגיאה">
<p align="right">
<span class="ui-icon ui-icon-circle-close" style="float:right; margin:0 7px 50px 0;"></span>
יש למלא את כל השדות
</p>
</div>
<?php
} else {
$sql = "INSERT INTO inventory_stock (product_number, supplier_ID, project_number, amount_in, amount_out) VALUES (:product_number, :supplier_ID, :project_number, :amount_in, :amount_out)";
$stmt = $pdo->prepare($sql);
$stmt->execute(['product_number' => $prodnumber, 'supplier_ID' => $suppliernumber, 'project_number' => $project_number, 'amount_in' => $amount, 'amount_out' => $amount_out]);
$pdo->commit();
?>
<div id="dialog-message" title="הצלחה">
<p align="right" >
<span class="ui-icon ui-icon-circle-check" style="float:right; margin:0 7px 50px 0;"></span>
נקלט בהצלחה
</p>
</div>
<?php
}
}
$prodnumber = "";
$suppliernumber = "";
$amount = "";
}
catch(Exception $e){
$pdo->rollBack();
?>
<div id="dialog-message" title="שגיאה">
<p align="right">
<span class="ui-icon ui-icon-circle-close" style="float:right; margin:0 7px 50px 0;"></span>
שגיאה! לא נעשה עדכון
</p>
</div>
<?php
echo "<br>" . 'N° : '.$e->getCode();
echo "<br>" . 'Error : '.$e->getMessage();
$pdo = null;
}
?>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel = "stylesheet" type = "text/css" href = "myStyle.css"/>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<title>הכנסה למלאי</title>
<style>
.form-control {
border: -1px solid #ccc;
text-align: right;
}
</style>
</head>
<body>
<form action="" method="POST" class="form-style-9">
<div align="right">
<H1 align="right">מלאי נכנס</H1>
<ul>
<li>
<!-- שם מוצר ושמירת המק"ט -->
<select class="field-style field-split align-left" name='productsnumber' onChange='outputValue(this)'>
<option value='' selected disabled>בחר מוצר</option>
<?php foreach($resultsproducts as $row)
{
echo "<option value='" . $row['product_number'] . "'>" . $row['product_name'] . "</option>";
}?>
</select>
<input type='hidden' id='output' name='output' readonly />
</li>
<li>
<!-- שם הספק -->
<select class="field-style field-split align-right" name='suppliersnumber' onChange='outputValue1(this)'>
<option value='' selected disabled>בחר שם הספק</option>
<?php foreach($resultssupliers as $row)
{
echo "<option value='" . $row['ID'] . "'>" . $row['supplier_name'] . "</option>";
}?>
</select>
<input type='hidden' id='output1' name='output1' readonly />
<input type="number" name="amount" placeholder="הכנס כמות" class="field-style field-split align-left " />
<li>
<input type="submit" value="הכנס מלאי חדש" style = "font-size:20px; float:right">
</li>
</ul>
</div>
</form>
</body>
</html>
<script>
function outputValue(item)
{
document.getElementById('output').value = item.value;
}
function outputValue1(item)
{
document.getElementById('output1').value = item.value;
}
$( function(){
$( "#dialog-message" ).dialog({
modal: true,
buttons: {
Ok: function() {
$( this ).dialog( "close" );
}
}
});
});
</script>
Comments