<?php
function get_api_customer($id) {
    $customer = get_customer($id);
    $sales_type = get_sales_type($customer['sales_type']);
    $dimension = get_dimension($customer['dimension_id'],true);
    $dimension2 = get_dimension($customer['dimension2_id'],true);
    $payment_terms = get_payment_terms($customer['payment_terms']);
    $customer['sales_type'] = $sales_type;
    $customer['dimension'] = $dimension?$dimension:null;
    $customer['dimension2'] = $dimension2?$dimension2:null;
    $customer['payment_terms'] = $payment_terms?$payment_terms:null;
    return $customer;
}

function get_api_branch($id) {
    $branch = get_branch($id);
    $location = get_inventory_location($branch['default_location']);
    $branch['default_location'] = $location?$location:null;
    return $branch;
}

function get_api_item($id,$tax_group){
    $item = get_item($id);
    $item['sales_price'] = get_price($item['stock_id'], get_company_currency(), "1");
    $item['tax_rate'] = get_item_tax($item['stock_id'], $tax_group);
    return $item;
}

function get_sales_type_by_name($sales_type)
{
	$sql = "SELECT * FROM ".TB_PREF."sales_types WHERE sales_type=".db_escape($sales_type);
	
	$result = db_query($sql, "could not get sales type");
	
	return db_fetch($result);
}