--- erp_item.module	2011-03-03 12:33:11.000000000 +0200
+++ erp_item.module.org	2011-03-19 13:32:36.000000000 +0200
@@ -277,12 +277,23 @@
             '#maxlength' => 128,
             '#default_value' => $node->supp_code);
 
-    $form['supplier_details']['buy_price'] =
-      array('#type' => 'textfield',
-            '#title' => t('Buy Price(ex)'),
-            '#size' => 10,
-            '#maxlength' => 10,
-            '#default_value' => erp_currency($node->buy_price));
+    if (module_exists('erp_tax')) {
+        $form['supplier_details']['buy_price'] =
+	  array('#type' => 'textfield',
+		'#title' => t('Buy Price(ex)'),
+		'#field_prefix' => erp_symbol(),
+		'#size' => 10,
+		'#maxlength' => 10,
+		'#default_value' => erp_currency($node->buy_price));
+    } else {
+	$form['supplier_details']['buy_price'] =
+          array('#type' => 'textfield',
+		'#title' => t('Buy Price'),
+		'#field_prefix' => erp_symbol(),
+		'#size' => 10,
+		'#maxlength' => 10,
+		'#default_value' => erp_currency($node->buy_price));
+    }
   }
 
   $form['sale_details'] =
@@ -293,22 +304,32 @@
           '#tree' => FALSE,
           '#suffix' => '</div>');
 
-  $rrp_price = erp_currency(array_pop(module_invoke_all('erp_tax_inc_amount', $node->rrp_price)));
+  if (module_exists('erp_tax')) {
+    $rrp_price = erp_currency(array_pop(module_invoke_all('erp_tax_inc_amount', $node->rrp_price)));
+  } else {
+    $rrp_price = erp_currency($node->rrp_price);
+  }
 
   $form['sale_details']['rrp_price'] =
     array('#type' => 'textfield',
           '#title' => t('RRP Price'),
           '#size' => 10,
           '#maxlength' => 10,
+          '#field_prefix' => erp_symbol(),
           '#default_value' => $rrp_price);
 
-  $sell_price = erp_currency(array_pop(module_invoke_all('erp_tax_inc_amount', $node->sell_price)));
+  if (module_exists('erp_tax')) {
+    $sell_price = erp_currency(array_pop(module_invoke_all('erp_tax_inc_amount', $node->sell_price)));
+  } else {
+    $sell_price = erp_currency($node->sell_price);
+  }
 
   $form['sale_details']['sell_price'] =
     array('#type' => 'textfield',
           '#title' => t('Sell Price'),
           '#size' => 10,
           '#maxlength' => 10,
+          '#field_prefix' => erp_symbol(),
           '#default_value' => $sell_price);
 
   $form['sale_details']['active'] =
@@ -377,12 +398,14 @@
     }
   }
 
-  if (!$node->tax_ex) {
-    // Convert prices back to ex tax
-    $node->buy_price = round(array_pop(module_invoke_all('erp_tax_ex_amount', $node->buy_price)), 2);
-    $node->rrp_price = round(array_pop(module_invoke_all('erp_tax_ex_amount', $node->rrp_price)), 2);
-    $node->sell_price = round(array_pop(module_invoke_all('erp_tax_ex_amount', $node->sell_price)), 2);
-  }
+    if (module_exists('erp_tax')) {
+      if (!$node->tax_ex) {
+	// Convert prices back to ex tax
+	$node->buy_price = round(array_pop(module_invoke_all('erp_tax_ex_amount', $node->buy_price)), 2);
+	$node->rrp_price = round(array_pop(module_invoke_all('erp_tax_ex_amount', $node->rrp_price)), 2);
+	$node->sell_price = round(array_pop(module_invoke_all('erp_tax_ex_amount', $node->sell_price)), 2);
+      }
+    }
 
   drupal_write_record('erp_item', $node);
 }
@@ -405,12 +428,14 @@
     }
   }
 
-  if (!$node->tax_ex) {
-    // Convert prices back to ex tax
-    $node->buy_price = round(array_pop(module_invoke_all('erp_tax_ex_amount', $node->buy_price)), 2);
-    $node->rrp_price = round(array_pop(module_invoke_all('erp_tax_ex_amount', $node->rrp_price)), 2);
-    $node->sell_price = round(array_pop(module_invoke_all('erp_tax_ex_amount', $node->sell_price)), 2);
-  }
+    if (module_exists('erp_tax')) {
+	if (!$node->tax_ex) {
+	    // Convert prices back to ex tax
+	    $node->buy_price = round(array_pop(module_invoke_all('erp_tax_ex_amount', $node->buy_price)), 2);
+	    $node->rrp_price = round(array_pop(module_invoke_all('erp_tax_ex_amount', $node->rrp_price)), 2);
+	    $node->sell_price = round(array_pop(module_invoke_all('erp_tax_ex_amount', $node->sell_price)), 2);
+	}
+    }
 
   drupal_write_record('erp_item', $node, array('nid'));
 }
@@ -481,13 +506,22 @@
     }
   }
 
-  $rrp_price = array_pop(module_invoke_all('erp_tax_inc_amount', $node->rrp_price));
+  if (module_exists('erp_tax')) {
+	$rrp_price = array_pop(module_invoke_all('erp_tax_inc_amount', $node->rrp_price));
+  } else {
+	//$rrp_price = erp_currency($node->rrp_price);
+	$rrp_price = $node->rrp_price;
+  }
 
   $output .= '<div class="rrp-price">';
   $output .= t('RRP Price: ') . erp_symbol() . erp_currency($rrp_price);
   $output .= '</div>';
 
-  $sell_price = array_pop(module_invoke_all('erp_tax_inc_amount', $node->sell_price));
+  if (module_exists('erp_tax')) {
+    $sell_price = array_pop(module_invoke_all('erp_tax_inc_amount', $node->sell_price));
+  } else {
+    $sell_price = $node->sell_price;
+  }
 
   $output .= '<div class="our-price">';
   $output .= t('Sell Price: ') . erp_symbol() . erp_currency($sell_price);
@@ -548,16 +582,32 @@
       $alternate = node_load($row['nid']);
       $found = TRUE;
 
-      $alternate_rrp_price = array_pop(module_invoke_all('erp_tax_inc_amount', $alternate->rrp_price));
-      $alternate_sell_price = array_pop(module_invoke_all('erp_tax_inc_amount', $alternate->sell_price));
-
-      $alternatives[] = array(
-        l($alternate->supplier, 'node/'. $alternate->supplier_nid),
-        l(shrink($row['title'], 50), 'node/'. $row['nid']),
-        erp_symbol() . erp_currency($alternate->buy_price),
-        erp_symbol() . erp_currency($alternate_rrp_price),
-        erp_symbol() . erp_currency($alternate_sell_price)
-      );
+      if (module_exists('erp_tax')) {
+        $alternate_rrp_price = array_pop(module_invoke_all('erp_tax_inc_amount', $alternate->rrp_price));
+        $alternate_sell_price = array_pop(module_invoke_all('erp_tax_inc_amount', $alternate->sell_price));
+      } else
+      {
+        $alternate_rrp_price = $alternate->rrp_price;
+        $alternate_sell_price = $alternate->sell_price;
+      }
+
+	if (user_access('item wholesale')) {
+          $alternatives[] = array(
+	    l($alternate->supplier, 'node/'. $alternate->supplier_nid),
+    	    l(shrink($row['title'], 50), 'node/'. $row['nid']),
+            erp_symbol() . erp_currency($alternate->buy_price),
+	    erp_symbol() . erp_currency($alternate_rrp_price),
+    	    erp_symbol() . erp_currency($alternate_sell_price)
+          );
+    } else {
+          $alternatives[] = array(
+	    l($alternate->supplier, 'node/'. $alternate->supplier_nid),
+    	    l(shrink($row['title'], 50), 'node/'. $row['nid']),
+            //erp_symbol() . erp_currency($alternate->buy_price),
+            erp_symbol() . erp_currency($alternate_rrp_price),
+	    erp_symbol() . erp_currency($alternate_sell_price)
+	  );
+    }
       $nids[$row['nid']] = $row['nid'];
     }
 
@@ -581,7 +631,11 @@
   if ($found) {
     $output .= '<div class="erp_alternatives">';
     $output .= '<p><strong>Possible alternatives</strong><br />';
-    $output .= theme('table', array(t('Supplier'), t('Item'), t('Buy price'), t('RRP price'), t('Sell price')), $alternatives);
+    if (user_access('item wholesale')) {
+	$output .= theme('table', array(t('Supplier'), t('Item'), t('Buy price'), t('RRP price'), t('Sell price')), $alternatives);
+    } else {
+    	$output .= theme('table', array(t('Supplier'), t('Item'), t('RRP price'), t('Sell price')), $alternatives);
+    }
     $output .= '</p></div>';
   }
 
@@ -707,12 +761,18 @@
     		$amount = $row['sell_price'];
     	}
 
-      // apply tax
-      $amount = erp_tax_erp_tax_inc_amount($amount);
+      if (module_exists('erp_tax')) {
+        // apply tax
+        $amount = erp_tax_erp_tax_inc_amount($amount);
+      }
       return $amount;
     }
     else {
-      return erp_tax_erp_tax_inc_amount($row[$type .'_price']);
+      if (module_exists('erp_tax')) {
+        return erp_tax_erp_tax_inc_amount($row[$type .'_price']);
+      } else {
+        return $row[$type .'_price'];
+      }
     }
   }
   else {
@@ -877,9 +937,11 @@
     if ($item->serial || $item->store_nid) {
       $item->code .= ' - #'. $store->title .'@'. $item->serial .'#';
     }
-    $item->rrp_price = erp_currency(array_pop(module_invoke_all('erp_tax_inc_amount', $item->rrp_price)));
-    $item->sell_price = erp_currency(array_pop(module_invoke_all('erp_tax_inc_amount', $item->sell_price)));
-    $item->buy_price = erp_currency(array_pop(module_invoke_all('erp_tax_inc_amount', $item->buy_price)));
+    if (module_exists('erp_tax')) {
+	$item->rrp_price = erp_currency(array_pop(module_invoke_all('erp_tax_inc_amount', $item->rrp_price)));
+	$item->sell_price = erp_currency(array_pop(module_invoke_all('erp_tax_inc_amount', $item->sell_price)));
+	$item->buy_price = erp_currency(array_pop(module_invoke_all('erp_tax_inc_amount', $item->buy_price)));
+    }
     if ($type == 'buy') {
       $code = check_plain($item->code) .' - '. check_plain($item->title) .' - '. check_plain($item->buy_price);
     }
