Topic: retrieve tax from item

Hi.

I need to create a function in PHP but I'm not very familiar.
Can you help?

What I need is to pass to a function the stock_id (from stock_master.stock_id) and get the value of tax_types.rate associated.

I understand that for a PHP programmer is a walk in the park but I'm not such a thing.

Thanks for any help you may provide.

Best,
Carlo

2 (edited by apmuthu 03/13/2015 02:50:31 pm)

Re: retrieve tax from item

The SQL is:

SELECT tt.rate
FROM `0_stock_master` sm LEFT JOIN `0_tax_types` tt
        ON (`sm`.`tax_type_id` = `tt`.`id`)
WHERE stock_id="MY_ITEM";

Tax rates are not that straightforward. The items may be having different tax rates depending on the actual invoice where a Customer may have tax overrides.

Attached is the ERD for the SQL provided here.

Will the function get_item_tax_type_for_item($stock_id)

function get_item_tax_type_for_item($stock_id)
{
    $sql = "SELECT ".TB_PREF."item_tax_types.* FROM ".TB_PREF."item_tax_types,".TB_PREF."stock_master WHERE 
        ".TB_PREF."stock_master.stock_id=".db_escape($stock_id)."
        AND ".TB_PREF."item_tax_types.id=".TB_PREF."stock_master.tax_type_id";
    
    $result = db_query($sql, "could not get item tax type");
    
    return db_fetch($result);    
}

in lines 61 to 70 intaxes/db/item_tax_types_db.inc suffice or would you like to clone it by replacing the sql?

Post's attachments

stock_id_TO_tax_rate.png 9.5 kb, file has never been downloaded. 

You don't have the permssions to download the attachments of this post.