beginTransaction(); try { $stmt = db()->prepare("INSERT INTO suppliers (tenant_id, name, type, contact_info) VALUES (?, ?, ?, ?)"); while (($row = fgetcsv($handle)) !== false) { $rowCount++; $data = []; foreach ($expected as $col) { $data[$col] = isset($columnMap[$col]) && isset($row[$columnMap[$col]]) ? trim($row[$columnMap[$col]]) : ''; } if (empty($data['name'])) { $skippedCount++; $results[] = "Row $rowCount: Skipped (Missing Name)"; continue; } // Default type if invalid if (!in_array($data['type'], ['supplier', 'contractor'])) { $data['type'] = 'supplier'; } $stmt->execute([ 1, // Hardcoded tenant_id $data['name'], $data['type'], $data['contact_info'] ]); $importCount++; } db()->commit(); $message = "Import completed successfully. $importCount suppliers imported, $skippedCount skipped."; } catch (Exception $e) { db()->rollBack(); $error = 'Database error: ' . $e->getMessage(); } } fclose($handle); } } include 'includes/header.php'; ?>

Import Suppliers

Download Template
Max file size: 2MB. Only .csv files are allowed.
Import Instructions
  1. Download the CSV template using the button above.
  2. Fill in your supplier data. The name field is required.
  3. The type field should be either 'supplier' or 'contractor'.
  4. Save the file as a CSV and upload it.
Existing suppliers with the same name will be added as new entries.
Import Logs