Added support for tax included prices in transactions.
[fa-stable.git] / purchasing / includes / db / grn_db.inc
index e0284cec532cc69ee6c8c10afe08e205035d3dfd..a73efa6fcc3e20a36384adb62991815bd5ce71d2 100644 (file)
     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
 ***********************************************************************/
 //------------------- update average material cost ------------------------------------------ Joe Hunt Mar-03-2008
-
 function update_average_material_cost($supplier, $stock_id, $price, $qty, $date, $adj_only=false)
 {
+       // probably this function should be optimized
+       // passing transaction cart as argument. This would
+       // save a couple of db calls like get_supplier()
+       
+       $supp = get_supplier($supplier);
        if ($supplier != null)
-               $currency = get_supplier_currency($supplier);
+               $currency = $supp['curr_code'];
        else
                $currency = null;
+
+       if ($supp['tax_included'])
+               $price = get_tax_free_price_for_item($stock_id, $price, $supp['tax_group_id'],
+                       $supp['tax_included']);
+
        $dec = user_price_dec();
        price_decimal_format($price, $dec);
        $price = round2($price, $dec);