<?php 
include('../include/session.php');

date_default_timezone_set('Africa/Khartoum');
$entryDate = date("Y-m-d H:i:s",time()-3600); 



$job_no = $_GET['job_no'];
$project_no_edit = $_GET['project_no_text'];
$project_place_edit = $_GET['project_place_text'];
$order_date_edit = $_GET['order_date'];
$del_date_edit = $_GET['deliver_date'];
$value_edit = $_GET['job_value_text'];
$designer_edit = $_GET['designer_select'];
$roof_cover_edit = $_GET['roof_cover_select'];
$install_edit = $_GET['install_group'];
$roof_pitch_edit = $_GET['roof_pitch_text'];
$max_overhang_edit = $_GET['overhang_text'];
$roof_area_edit = $_GET['roof_area_text'];
$floor_area_edit = $_GET['floor_area_text'];
$quote_note_edit = $_GET['notes_text'];

$table_name = $_SESSION['db_prefix']."_captured_jobs";
$job_query = "SELECT * FROM $table_name WHERE job_no = '".$job_no."' ";
$job_result = mySQL_query($job_query);
$project_no = mysql_result($job_result, 0, "project_no");
$project_place = mysql_result($job_result, 0, "project_place");
$designer = mysql_result($job_result, 0, "designer");
$roof_cover = mysql_result($job_result, 0, "roof_cover");
$roof_pitch = mysql_result($job_result, 0, "roof_pitch");
$max_overhang = mysql_result($job_result, 0, "max_overhang");
$roof_area = mysql_result($job_result, 0, "roof_area");
$floor_area = mysql_result($job_result, 0, "floor_area");
$quote_note = mysql_result($job_result, 0, "quote_note");
$value = mysql_result($job_result, 0, "value");
$order_date = mysql_result($job_result, 0, "date");
$del_date = mysql_result($job_result, 0, "del_date");
$install = mysql_result($job_result, 0, "install_by");

echo $install_edit;
	
if ($project_no_edit!=$project_no) {
		    $table_name = $_SESSION['db_prefix']."_tracking_production";
			$trackingQuery = "INSERT INTO $table_name (entry_date, user, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '80', '".$job_no."', 'project no','".$project_no."', '".$project_no_edit."' )";
			$trackingResult = mySQL_query($trackingQuery);
}

if ($project_place_edit!=$project_place) {
		    $table_name = $_SESSION['db_prefix']."_tracking_production";
			$trackingQuery = "INSERT INTO $table_name (entry_date, user, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '80', '".$job_no."', 'project place'  ,'".$project_place."', '".$project_place_edit."' )";
			$trackingResult = mySQL_query($trackingQuery);
}

if ($designer_edit!=$designer) {
		    $table_name = $_SESSION['db_prefix']."_tracking_production";
			$trackingQuery = "INSERT INTO $table_name (entry_date, user, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '80', '".$job_no."', 'designer' ,'".$designer."', '".$designer_edit."' )";
			$trackingResult = mySQL_query($trackingQuery);
}

if ($roof_cover_edit!=$roof_cover) {
		    $table_name = $_SESSION['db_prefix']."_tracking_production";
			$trackingQuery = "INSERT INTO $table_name (entry_date, user, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '80', '".$job_no."', 'roof cover' ,'".$roof_cover."', '".$roof_cover_edit."' )";
			$trackingResult = mySQL_query($trackingQuery);
}

if ($roof_pitch_edit!=$roof_pitch) {
		    $table_name = $_SESSION['db_prefix']."_tracking_production";
			$trackingQuery = "INSERT INTO $table_name (entry_date, user, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '80', '".$job_no."', 'roof pitch' ,'".$roof_pitch."', '".$roof_pitch_edit."' )";
			$trackingResult = mySQL_query($trackingQuery);
}

if ($max_overhang_edit!=$max_overhang) {
		    $table_name = $_SESSION['db_prefix']."_tracking_production";
			$trackingQuery = "INSERT INTO $table_name (entry_date, user, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '80', '".$job_no."', 'max overhang' ,'".$max_overhang."', '".$max_overhang_edit."' )";
			$trackingResult = mySQL_query($trackingQuery);
}

if ($roof_area_edit!=$roof_area) {
		    $table_name = $_SESSION['db_prefix']."_tracking_production";
			$trackingQuery = "INSERT INTO $table_name (entry_date, user, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '80', '".$job_no."', 'roof area' ,'".$roof_area."', '".$roof_area_edit."' )";
			$trackingResult = mySQL_query($trackingQuery);
}

if ($floor_area_edit!=$floor_area) {
		    $table_name = $_SESSION['db_prefix']."_tracking_production";
			$trackingQuery = "INSERT INTO $table_name (entry_date, user, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '80', '".$job_no."', 'floor area' ,'".$floor_area."', '".$floor_area_edit."' )";
			$trackingResult = mySQL_query($trackingQuery);
}

if ($quote_note_edit!=$quote_note) {
		    $table_name = $_SESSION['db_prefix']."_tracking_production";
			$trackingQuery = "INSERT INTO $table_name (entry_date, user, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '80', '".$job_no."', 'note' ,'".$quote_note."', '".$quote_note_edit."' )";
			$trackingResult = mySQL_query($trackingQuery);
}

if ($value_edit!=$value) {
		    $table_name = $_SESSION['db_prefix']."_tracking_production";
			$trackingQuery = "INSERT INTO $table_name (entry_date, user, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '80', '".$job_no."', 'value' ,'".$value."', '".$value_edit."' )";
			$trackingResult = mySQL_query($trackingQuery);
}

if ($order_date_edit!=$order_date) {
		    $table_name = $_SESSION['db_prefix']."_tracking_production";
			$trackingQuery = "INSERT INTO $table_name (entry_date, user, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '80', '".$job_no."', 'order date' ,'".$order_date."', '".$order_date_edit."' )";
			$trackingResult = mySQL_query($trackingQuery);
}

if ($del_date_edit!=$del_date) {
		    $table_name = $_SESSION['db_prefix']."_tracking_production";
			$trackingQuery = "INSERT INTO $table_name (entry_date, user, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '80', '".$job_no."', 'delivery date' ,'".$del_date."', '".$del_date_edit."' )";
			$trackingResult = mySQL_query($trackingQuery);
}

if ($install_edit!=$install) {
		    $table_name = $_SESSION['db_prefix']."_tracking_production";
			$trackingQuery = "INSERT INTO $table_name (entry_date, user, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '80', '".$job_no."', 'installation' ,'".$install."', '".$install_edit."' )";
			$trackingResult = mySQL_query($trackingQuery);
}

$table_name = $_SESSION['db_prefix']."_captured_jobs";
$captured_query = "UPDATE $table_name SET project_no = '".$project_no_edit."', project_place = '".$project_place_edit."', designer = '".$designer_edit."', roof_cover = '".$roof_cover_edit."', roof_pitch = '".$roof_pitch_edit."', max_overhang = '".$max_overhang_edit."', roof_area = '".$roof_area_edit."', floor_area = '".$floor_area_edit."', quote_note = '".$quote_note_edit."', value = '".$value_edit."', date = '".$order_date_edit."', del_date = '".$del_date_edit."', install_by = '".$install_edit."' WHERE job_no = '".$job_no."' ";
execsql($captured_query);


//$_SESSION['edit_start']=0;

		if (isset($_GET['save_close_button']) )
	   { ?>
       <script>
	  window.location="../production/production_main.php";
		</script>
        <?php		 
	   }
	          
       if (isset($_GET['save_button']) )
	   {  ?>
       <script>
	     window.location="job_details_edit.php?job_no=<?php echo $job_no?>"
	   </script>
        <?php		 
	   }
	   ?>

