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

//--------------------------------------------------------------------------------------------------

function add_lt_header($date_, $reference, $location_to, 
                        $location_from, $project_id, $movement_type, 
                        $linked_field_type, $linked_field_id, $memo_, 
                        $stmple_items)
{
	$lt_date = date2sql($date_);
    $created_on = date('Y-m-d H:i:s');
    $created_by = $_SESSION['wa_current_user']->user;
        
	$sql = "INSERT INTO ".TB_PREF."stock_transfers(tran_date, reference,"
                        . " location_from, location_to, "
                        . " project_id, movement_type, "
                        . " linked_field_type, linked_field_id, "
                        . " comments, sample_items, "
                        . " created_by, created_on) "
                . "VALUES (".db_escape($lt_date).", ".db_escape($reference).", "
                        .db_escape($location_from).", ".db_escape($location_to).", "
                        .db_escape($project_id).", ".db_escape($movement_type).", "
                        .db_escape($linked_field_type).", ".db_escape($linked_field_id).", "
                        .db_escape($memo_).", ".db_escape($stmple_items).", "
                        .db_escape($created_by).", ".db_escape($created_on).")";

    $error_msg = "The location transfer record could not be inserted";

	db_query($sql, $error_msg);

	return db_insert_id();
}

function get_stock_transfers_header($trans_no)
{
    $sql = "SELECT 
                st.*,
                lf.location_name location_from_name,
                lt.location_name location_to_name,
                pm.description project_description,
                u.real_name requestor_name
            FROM ".TB_PREF."stock_transfers st 
                INNER JOIN ".TB_PREF."projects_master pm ON 
                    st.project_id = pm.project_id 
                INNER JOIN ".TB_PREF."locations lf ON 
                    st.location_from = lf.loc_code 
                INNER JOIN ".TB_PREF."locations lt ON 
                    st.location_to = lt.loc_code     
                INNER JOIN ".TB_PREF."users u ON 
                     st.created_by = u.id 
                
            WHERE  
                st.id = ".  db_escape($trans_no);
    
    $result = db_query($sql,"The location transfer record could not be retreived");

    return db_fetch($result);
}
?>