+function import_inventory($filename)
+{
+ global $debug;
+
+ $data = array();
+
+ $handle = fopen($filename, "r");
+
+ if ($handle == false) {
+ echo "Cannot open file: " . $filename . "\n";
+ exit(1);
+ }
+
+ while (($row = fgetcsv($handle, 1024, ',')) !== false) {
+ $num = count($row);
+
+ if ($num < 2) {
+ /* Ligne vide. */
+ continue;
+ }
+
+ $data[] = $row;
+ }
+
+ fclose($handle);
+
+ return $data;
+}
+
+/*
+ * If a part is found in inventory file, exclude it from BOM.
+ *
+ * If the customer P/N is empty, try to match by manufacturer P/N instead.
+ */
+function find_part_in_inventory($inventory, $bom_customer_pn, $bom_manufacturer_pn)
+{
+ foreach ($inventory as $key => $row) {
+ $inv_customer_pn = $row[0];
+
+ if ($bom_customer_pn !== "") {
+ $match = $bom_customer_pn;
+ } else if ($bom_manufacturer_pn !== "") {
+ $match = $bom_manufacturer_pn;
+ } else {
+ echo "Error: Need at least one of customer or manufacturer P/N\n";
+ exit(1);
+ }
+
+ if ($inv_customer_pn == $match) {
+ return true;
+ }
+ }
+
+ return false;
+}
+