malasho, who was helping me with this is busy and im wondering if anyone else can help me here. This is the full file.
[php]
<?php
include 'dbc.php';
page_protect();
$err = array();
$jobid = '';
$vat_at = $site_settings['taxrate'];
//Add job
if(isset($_POST["submit"]) && $_POST["submit"] == "Add Job"){
$customername = filter($_POST["customer"]);
$add1 = filter($_POST["address1"]);
$add2 = filter($_POST["address2"]);
$add3 = filter($_POST["address3"]);
$pc = filter($_POST["postcode"]);
$to = filter(esec($_POST['to']));
$from = filter(esec($_POST['from']));
$items = filter($_POST['item']);
$del = filter($_POST['delivery']);
$jobid = filter($_POST["jid"]);
$customer_id = $_POST['customerid'];
$quote = $_POST['quote'];
$totalvat = $_POST['totalvat'];
$grandtotal = $_POST['grandtotal'];
$linetotal = $_POST['linetotal'];
if (!IsPostcode($pc)){
$err[] = "Please enter a valid postcode!";
}
if ($pc == ''){
$err[] = "Please enter postcode!";
}
if ($add1 == ''){
$err[] = "Please enter an address!";
}
if ($to == ''){
$err[] = "Please enter a to date!";
}
if ($from == ''){
$err[] = "Please enter a from date!";
}
if ($customer_id == ''){
$err[] = "Please enter a customer!";
}
if(empty($err)){
$sql2 = "INSERT INTO jobs (job_id, contact_name, phone, address1, address2, address3, postcd, customer_id, mobile, comments, dateadded, email, customer_id, quote, before_vat, vat, full_total) VALUES ('$jobid', '$customername', '$phone', '$add1', '$add2', '$add3', '$pc', '$name', '$mobile', '$comments', '$date', '$email', '$customer_id', '$quote', '$linetotal', '$totalvat', '$grandtotal')";
foreach($item as $value){
$i = ltrim($value['code'], "0");
$q = $value['q'];
$d = $value['desc'];
$p = $value['price'];
$bv = $value['bv'];
$vat = $value['vat'];
$subtotal = $value['bv'];
$sql = "INSERT INTO job_items (job_id, quantity, product_id, unit_price, description, before_vat, vat, subtotal) VALUES ('$jobid', '$q', '$i', '$p', '$d', '$bv', '$vat', '$subtotal');";
$result = mysql_query($sql);
}
$result2 = mysql_query($sql2);
$sql3 = "UPDATE customers SET jobid = CONCAT_WS(',',jobid,'$jobid') WHERE customer_id = '$customer_id'";
$result3 = mysql_query($sql3);
if($result2)
{
$success = "Job added with ID: $jobid";
} else {
$err[] = 'Could not add job: ' . mysql_error();
}
}
}
if(isset($_POST['action']) && $_POST['action'] == "Update Invoice"){
$item = $_POST['item'];
$delivery = $_POST['delivery'];
$customername = $_POST['customer'];
$customerid = $_POST['customerid'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$address3 = $_POST['address3'];
$postcode = $_POST['postcode'];
$jobid = $_POST['jid'];
$from = $_POST['from'];
$to = $_POST['to'];
}
?>
<?php echo $site_settings['site_name'];?> Management System
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script type='text/javascript' src='js/jquery.autocomplete.js'></script>
</head>
<body>
<div id="wrapper">
<div id="header">
<div id="logo">
<h1><a href=""><?php echo $site_settings['site_name'];?> Management System</a></h1>
</div>
<!-- Menu start -->
<div id="menu">
<ul>
<?php include('inc/menu.php');?>
</ul>
<br class="clearfix" />
</div>
<!-- menu end -->
</div>
<div id="page">
<!-- Content start -->
<div id="content">
<div class="post">
<h2>Welcome <?php echo $_SESSION['user_name'];?></h2>
<h3>Job Add</h3>
<?php
if(!empty($err)) {
echo "<div class=\"err\">";
foreach ($err as $e) {
echo "$e <br/>";
}
echo "</div><br/><br/>";
}
if($success != ''){
echo "<div class=\"msg\">$success <br></div><br/><br/>";
}
?>
<form action="add_job.php" method="post">
<p><label for="customer">Contact Name </label><input name="customer" type="text" size="30" value="<?php echo $customername;?>" class="form-text" id="customer" />
<input name="customerid" type="hidden" value="<?php echo $customerid;?>" class="customerid" id="customerid"/> </p>
<p><label for="jobid">Job ID / Quote ID</label>
<input name="jid" type="text" value="<?php if($jobid == ''){ echo jobnum();} else {echo $jobid;} ?>" class="form-text" />
</p>
<p><label for="address">Venu Address </label><input name="address1" type="text" class="form-text" value="<?php echo $address1; ?>"/>
<label for="address2"> </label><input name="address2" type="text" class="form-text" value="<?php echo $address2; ?>"/>
<label for="address3"> </label><input name="address3" type="text" class="form-text" value="<?php echo $address3; ?>"/>
<label for="postcode">Postcode </label><input name="postcode" type="text" class="form-text" value="<?php echo $postcode; ?>"/>
</p>
<p><label for="from">Dates Hired From:</label><input name="from" id="from" type="text" class="form-text" value="<?php echo $from; ?>"/><label for="to">To:</label><input name="to" id="to"type="text" class="form-text" value="<?php echo $to; ?>"/></p>
<p><label for="equipment">Equipment</label>
<table id="invoiceitems" class="gridtable">
<thead>
<tr>
<th><strong>Item ID</strong></th>
<th><strong>Description</strong></th>
<th><strong>Cost</strong></th>
<th><strong>Qty</strong></th>
<th><strong>Nett</strong></th>
<th><strong>VAT</strong></th>
<th><strong>Gross</strong></th>
</tr>
</thead>
<tbody>
<tr class="noborder">
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<?php
$linetotal = 0;
$totalvat = 0;
$grandtotal = 0;
echo count($item);
for($l=0; $l<count($item); $l++){
?>
<tr>
<td><?php echo $item[$l]['code']; ?> <input type="hidden" name="item[<?php echo $l; ?>][code]" value="<?php echo $item[$l]['code']; ?>" /></td>
<td><?php echo $item[$l]['desc']; ?> <input type="hidden" name="item[<?php echo $l; ?>][desc]" value="<?php echo $item[$l]['desc']; ?>" /></td>
<td><?php echo $site_settings['currency'].number_format($item[$l]['price'],2); ?> <input type="hidden" name="item[<?php echo $l; ?>][price]" value="<?php echo $item[$l]['price']; ?>" /></td>
<td><?php echo $item[$l]['q']; ?> <input type="hidden" name="item[<?php echo $l; ?>][q]" value="<?php echo $item[$l]['q']; ?>" /></td>
<?php $bfvat = $item[$l]['price']*$item[$l]['q']; ?>
<td><?php echo $site_settings['currency'].number_format($bfvat,2); ?> <input type="hidden" name="item[<?php echo $l; ?>][bv]" value="<?php echo $bfvat; ?>" /></td>
<?php $vat = $bfvat*($vat_at/100); ?>
<td><?php echo $site_settings['currency'].number_format($vat,2); ?> <input type="hidden" name="item[<?php echo $l; ?>][vat]" value="<?php echo $vat; ?>" /></td>
<?php $subtotal = $vat + $bfvat; ?>
<td><?php echo $site_settings['currency'].number_format($subtotal,2); ?> <input type="hidden" name="item[<?php echo $l; ?>][subtotal]" value="<?php echo $subtotal; ?>" /></td>
</tr>
<?php
$linetotal += $item[$l]['bv']+$delivery['price'];
$totalvat += ($linetotal+$delivery['price'])*($vat_at/100);
$grandtotal = $linetotal + $totalvat;
}
?>
</tbody>
<tfoot>
<tr>
<td><input type="text" name="item[<?php echo count($item);?>][code]" id="code" class="form-text-price" value="" readonly/></td>
<td><input type="text" name="item[<?php echo count($item);?>][desc]" id="desc" class="form-text" value="" /></td>
<td><input type="text" name="item[<?php echo count($item);?>][price]" id="price" class="form-text-price" value="0.00" readonly/></td>
<td><input type="text" name="item[<?php echo count($item);?>][q]" id="q" class="form-text-q" value="0" /></td>
<td> </td><td> </td><td><input name="action" type="submit" value="Update Invoice" class="form-submit"></td>
</tr>
<tr>
<td><strong>Delivery</strong></td>
<td><input type="text" name="delivery[desc]" id="del-desc" class="form-text" value="" /></td>
<td><input type="text" name="delivery[price]" id="del-price" class="form-text-price" value="0.00" readonly/></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><strong>Delivery Cost:</strong><?php echo $delivery['desc']; ?> <input type="hidden" name="delivery[desc]" value="<?php echo $delivery['desc']; ?>" /></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td><?php echo $site_settings['currency'].number_format($delivery['price'],2); ?> <input type="hidden" name="delivery[price]" value="<?php echo $delivery['price']; ?>" /></td>
</tr>
<tr>
<td> </td>
<td><strong>Subtotal:</strong></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td><?php echo $site_settings['currency'].number_format($linetotal,2); ?><input type="hidden" name="linttotal" value="<?php echo $linetotal; ?>" /></td>
</tr>
<tr>
<td> </td>
<td><strong>Vat total:</strong></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td><?php echo $site_settings['currency'].number_format($totalvat,2); ?><input type="hidden" name="totalvat" value="<?php echo $totalvat; ?>" /></td>
</tr>
<tr>
<td> </td>
<td><strong>Grand total:</strong></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td><?php echo $site_settings['currency'].number_format($grandtotal,2); ?> <input type="hidden" name="grandtotal" value="<?php echo $grandtotal; ?>" /></td>
</tr>
</tfoot>
</table>
</p>
<p><label for="quote">Quote or Job</label>
<select name="quote">
<option value="1">Quote</option>
<option value="0">Job</option>
</select>
</p>
<p align="center"><input name="submit" class="form-submit" type="submit" value="Add Job" /></p>
</form>
<?php var_dump($delivery); ?>
</div>
<br class="clearfix" />
</div>
<!-- Content end -->
<!-- Side Bar start -->
<div id="sidebar">
<div class="post">
<h3>Up and coming jobs</h3>
<p>
Dignissim cum iaculis malesuada dolor egestas nec nascetur. Praesent montes laoreet augue duis posuere. Magnis mus pellentesque sollicitudin nisl libero.
</p>
</div>
</div>
<!-- Side Bar end -->
<br class="clearfix" />
</div>
</div>
<!-- Footer start -->
<div id="footer">
© <?php echo date('Y '); echo $site_settings['site_name']; ?> | System by <a href="http://www.kalaxhosting.co.uk/">Kalax Hosting and Design</a>
</div>
<!-- Footer end -->
</body>
[/php]
THe problems are the delivery details dont save anything but it sets the array though, it doesn’t count the first row of the form when you add a row for the items. If anyone wants access to the script PM me and I will send over the login details for you to see. [/code]