<?php

function add_stock_uom($stock_id, $uom) {
    $sql = "REPLACE INTO `" . TB_PREF . "stock_uom` SET  `stock_id`=" . db_escape($stock_id) . ", "
            . "`uom`=" . db_escape($uom);
    return db_query($sql, "cannot set stock UOM");
}

function get_stock_uom($stock_id) {
    $sql = "select * from `" . TB_PREF . "stock_uom` where  `stock_id`=" . db_escape($stock_id);
    $result = db_query($sql, "could query stock UOM");

    return db_fetch($result);
}

function add_stock_trans($order_items, $location, $date_, $reference) {
    $date = date2sql($date_);
    $trans_no = get_next_trans_no(ST_LOCTRANSFER);

    foreach ($order_items as $line_item) {

        $sql = "INSERT INTO " . TB_PREF . "stock_control (stock_id, type, loc_code,
		trans_date, reference, qty, memo, trans_no) VALUES ("
                . db_escape($line_item->stock_id) . ", " . db_escape($line_item->trans_type) . ", "
                . db_escape($location) . ", '$date', "
                . db_escape($reference) . ", "
                . db_escape($line_item->quantity) . ", " . db_escape($line_item->memo) . ", " . db_escape($trans_no). ")";

        db_query($sql, "The stock transaction record cannot be inserted");
    }

    return db_insert_id();
}
