Skip to content

Instantly share code, notes, and snippets.

@SAFAD
Forked from anonymous/rashid
Created February 16, 2014 17:36
Show Gist options
  • Save SAFAD/9037734 to your computer and use it in GitHub Desktop.
Save SAFAD/9037734 to your computer and use it in GitHub Desktop.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Haddadin Trading</title>
</head>
<?php include("header.php");
?>
<?php
if(isset($_POST['select'])) {
$items = '';
$i = 0;
foreach($_POST['item_name'] as $item_name) {
$item_description = $_POST['item_description'][$i];
$item_price = $_POST['item_price'][$i];
$item_quantity = $_POST['item_quantity'][$i];
$item_sum = $_POST['item_sum'][$i];
$query = mysqli_query($con, "SELECT * FROM items WHERE `Description` = '$item_description' AND `Price` = '$item_price' AND `QTY` = '$item_quantity'");
$search_for = mysqli_fetch_array($query) or die(mysql_error());
if($search_for['TID'] > 0) {
$items .= "$search_for[TID],";
} else {
$insert = mysqli_query($con, "INSERT INTO items(Description, Price, QTY, Sum) VALUES('$item_description', '$item_price', '$item_quantity', '$item_sum')") or die(mysql_error());
$query = mysqli_query($con, "SELECT TID FROM items ORDER BY TID DESC") or die(mysql_error());
$get_last_row = mysqli_fetch_array($query2);
$items .= $get_last_row['id']+',';
}
$i++;
}
$insert = mysqli_query($con, "INSERT INTO invoices(Date, Payment, Refund, Heavy, Seals, InvoiceNo, CID, Note, Items) VALUES('..', '$_POST[three]', '$_POST[four]', '$_POST[five]', '$_POST[six]', '..', '..', '..', '$items' )") or die(mysqli_error($con));
if($insert) {
echo '<h1>Inserted Successfully</h1>';
} else {
echo 'An error has occured';
}
}
?>
<h2 align="center">Add Invoice </h2>
<p align="center">&nbsp;</p>
<h3 align="center">&nbsp;</h3>
<div align="center">
<table width="715" border="0">
<tr>
<td width="331"><div align="center"><img src="data/invoice.png" alt="" width="256" height="256" /></div></td>
<td width="374"><form id="form1" method="post" action="invoiceadd.php">
<h3>&nbsp;</h3>
<h3><strong>Invoice Type :
<label for="select">Select:</label>
<select name="select" id="select">
<option>Sales Invoice</option>
<option>Refund </option>
</select>
</strong></h3>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h3>Name :
<input name="one" type="text" id="one2" size="45" />
</h3>
<p>&nbsp;</p>
<h3><strong>Invoice Number:
<input type="text" name="six2" id="six3" />
</strong></h3>
<h3 align="left">&nbsp;</h3>
<h3 align="left">Date :
<label for="two"></label>
<input name="two" type="text" id="two" size="45" />
</h3>
<h3 align="center">&nbsp;</h3>
<table width="329" border="0">
<tr>
<td width="319" bgcolor="#3AD41B"><h3><strong>Payment :
<input name="three" type="text" id="three2" value="0.00" />
JD </strong></h3></td>
</tr>
</table>
<h3 align="left">&nbsp;</h3>
<h3 align="left">Refund :
<label for="four"></label>
<input name="four" type="text" id="four" value="0.00" />
JD</h3>
<h3 align="left">&nbsp;</h3>
<h3 align="left">Heavy :
<label for="five"></label>
<input type="text" name="five" id="five" />
</h3>
<h3 align="left">&nbsp;</h3>
<h3 align="left">Seals :
<label for="six"></label>
<input type="text" name="six" id="six" />
</h3>
<p align="left">&nbsp;</p>
<h2>Items</h2>
Description , QTY , Price , (QTY*PRICE for each item)
<table width="500" border="1">
<thead style="background:#DDD;"><tr><td>Item Name</td><td>Description</td><td>Price</td><td>Quantity</td><td>Total Price</td></tr></thead>
<tbody id="adding_area">
</tbody>
</table>
<a id="add_item" style="cursor:pointer">Add Item</a>
<script src="jquery.js" type="text/javascript"></script>
<script>
$(function() {
$("#add_item").click(function() {
$("#adding_area").append("<tr><td><input type='text' name='item_name[]' /></td><td><input type='text' name='item_description[]' /></td><td><input type='number' name='item_price[]' /></td><td><input type='number' name='item_quantity[]' /></td><td><input type='number' name='item_sum[]' /></td></tr>");
});
});
</script>
<h3 align="left">&nbsp;</h3>
<h3 align="left">
<input type="submit" name="button" id="button" value="Submit" />
</h3>
<p>&nbsp;</p>
<p>&nbsp;</p>
</form></td>
</tr>
</table>
</div>
<p>&nbsp;</p>
<p align="center">&nbsp;</p>
<p align="center">&nbsp;</p>
<p align="center">&nbsp;</p>
<p align="center">&nbsp;</p>
<?php include ("footer.php"); ?>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment