From 47e77f9fac1155c536b2b87fec552c7fcce66fa6 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Mon, 01 Jun 2026 18:06:34 +0000
Subject: [PATCH] =Timeline block fixes. Next up: adding article schema classes
---
inc/importers/JaneAppSalesImporter.php | 30 ++++++++++++++++++++++--------
1 files changed, 22 insertions(+), 8 deletions(-)
diff --git a/inc/importers/JaneAppSalesImporter.php b/inc/importers/JaneAppSalesImporter.php
index 16fc8e8..a071406 100644
--- a/inc/importers/JaneAppSalesImporter.php
+++ b/inc/importers/JaneAppSalesImporter.php
@@ -1,8 +1,8 @@
<?php
-
-namespace JVBase\managers;
+namespace JVBase\importers;
use WP_Error;
+use JVBase\managers\ReferralManager;
if (!defined('ABSPATH')) {
exit;
@@ -13,7 +13,7 @@
*
* Imports sales/treatment data from JaneApp CSV exports and updates referral tracking
*/
-class JaneSalesImporter
+class JaneAppSalesImporter
{
protected $wpdb;
protected string $jane_clients_table;
@@ -22,6 +22,7 @@
protected string $rewards_table;
protected ReferralManager $referral_manager;
protected array $import_stats = [];
+ protected array $skipped_details = [];
// CSV column mapping
protected array $column_map = [
@@ -65,9 +66,9 @@
*
* @param string $file_path Path to the CSV file
* @param array $options Import options
- * @return array Import results with stats and errors
+ * @return array|WP_Error Import results with stats and errors
*/
- public function importFromCSV(string $file_path, array $options = []): array
+ public function importFromCSV(string $file_path, array $options = []): array|WP_Error
{
// Initialize stats
$this->import_stats = [
@@ -102,6 +103,9 @@
return new WP_Error('invalid_csv', 'CSV file is empty or invalid');
}
+ // Trim whitespace from headers to handle inconsistent CSV formats
+ $headers = array_map('trim', $headers);
+
// Map column indices
$column_indices = $this->mapColumnIndices($headers);
if (is_wp_error($column_indices)) {
@@ -109,12 +113,17 @@
return $column_indices;
}
+ // Get Patient column index for error reporting
+ $patient_name_index = array_search('Patient', $headers);
+
// Start transaction for data integrity
$this->wpdb->query('START TRANSACTION');
try {
// Process each row
+ $row_number = 1; // Header is row 1, data starts at row 2
while (($row = fgetcsv($handle)) !== false) {
+ $row_number++;
$this->import_stats['total_rows']++;
$result = $this->processSalesRow($row, $column_indices, [
@@ -122,10 +131,15 @@
]);
if (is_wp_error($result)) {
- $this->import_stats['errors'][] = [
- 'row' => $this->import_stats['total_rows'],
- 'error' => $result->get_error_message()
+ $error_data = [
+ 'row' => $row_number,
+ 'patient_guid' => trim($row[$column_indices['patient_guid']] ?? 'Unknown'),
+ 'patient_name' => trim($row[$patient_name_index] ?? 'Unknown'),
+ 'item' => trim($row[$column_indices['item']] ?? 'Unknown'),
+ 'reason' => $result->get_error_message()
];
+
+ $this->import_stats['errors'][] = $error_data;
$this->import_stats['skipped']++;
} else {
$this->import_stats['processed']++;
--
Gitblit v1.10.0