<?php
/**********************************************************************

***********************************************************************/
function write_work_plan($selected, $date, $item_code, $target_qty, $order_qty, $status=0)
{
	$date = date2sql($date);
    if($selected!="")
		$sql = "UPDATE ".TB_PREF."production_planing SET
	 	tran_date = ".db_escape($date).",
	 	item = ".db_escape($item_code).",
	 	target_qty = ".db_escape($target_qty).",
	 	order_qty = ".db_escape($order_qty).",
	 	status = ".db_escape($status)."
        	WHERE id = ".db_escape($selected);
    else
		$sql = "INSERT INTO ".TB_PREF."production_planing
			(tran_date, item, target_qty,order_qty,status) VALUES( ".db_escape($date).",
	  		".db_escape($item_code).", ".db_escape($target_qty).", ".db_escape($order_qty).", ".db_escape($status).")";
   // display_error($sql);
	db_query($sql,"an production_planing could not be updated/addes");
}




function get_all_work_plan($BeforeDate, $AfterDate) {

	$before_date = date2sql($BeforeDate);
	$after_date = date2sql($AfterDate);
    $sql = "SELECT * FROM ".TB_PREF."production_planing WHERE";
	// if (!$all) $sql .= " WHERE !inactive";
	$sql .= " tran_date >= '". $after_date . "'
		AND tran_date <= '" . $before_date . "' ORDER BY id";
		// display_error($sql);
    return  db_query($sql, "could not get production_planing");
}



function get_work_plan($id){

 
  $sql=" SELECT * FROM ".TB_PREF."production_planing WHERE id=".db_escape($id);
  $res = db_query($sql);
  
  return db_fetch($res); 

}