From ed8365df494b796145f8a5272c7f956055a2d244 Mon Sep 17 00:00:00 2001 From: Jonathan Miller Date: Sat, 20 Jun 2026 23:25:37 -0500 Subject: [PATCH 1/5] =?UTF-8?q?Add=20WarrantyHelper=20=E2=80=94=20warranty?= =?UTF-8?q?=20status,=20claim=20processing,=20expiry=20alerts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Helper/WarrantyHelper.php | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 source/packages/plg_system_mokosuitefield/src/Helper/WarrantyHelper.php diff --git a/source/packages/plg_system_mokosuitefield/src/Helper/WarrantyHelper.php b/source/packages/plg_system_mokosuitefield/src/Helper/WarrantyHelper.php new file mode 100644 index 0000000..c1f3eb0 --- /dev/null +++ b/source/packages/plg_system_mokosuitefield/src/Helper/WarrantyHelper.php @@ -0,0 +1,95 @@ +get(DatabaseInterface::class); + + $db->setQuery($db->getQuery(true) + ->select('e.id, e.serial_number, e.model, e.install_date') + ->select('e.warranty_start, e.warranty_end, e.warranty_provider, e.warranty_type') + ->from($db->quoteName('#__mokosuitefield_equipment', 'e')) + ->where('e.id = ' . (int) $equipmentId)); + $equipment = $db->loadObject(); + + if (!$equipment) return (object) ['found' => false]; + + $now = new \DateTime('today'); + $warrantyEnd = $equipment->warranty_end ? new \DateTime($equipment->warranty_end) : null; + + $equipment->under_warranty = $warrantyEnd && $now <= $warrantyEnd; + $equipment->days_remaining = $warrantyEnd ? max(0, (int) $now->diff($warrantyEnd)->format('%r%a')) : null; + $equipment->warranty_expired = $warrantyEnd && $now > $warrantyEnd; + + // Get claim history + $db->setQuery($db->getQuery(true) + ->select('COUNT(*) AS total_claims, COALESCE(SUM(claim_amount), 0) AS total_claimed') + ->from('#__mokosuitefield_warranty_claims') + ->where('equipment_id = ' . (int) $equipmentId)); + $claims = $db->loadObject(); + + $equipment->total_claims = (int) ($claims->total_claims ?? 0); + $equipment->total_claimed = (float) ($claims->total_claimed ?? 0); + + return $equipment; + } + + /** + * Submit a warranty claim. + */ + public static function submitClaim(int $equipmentId, int $woId, string $description, float $claimAmount): object + { + $warranty = self::checkWarranty($equipmentId); + + if (!$warranty->found ?? true) return (object) ['success' => false, 'error' => 'Equipment not found']; + if (!$warranty->under_warranty) return (object) ['success' => false, 'error' => 'Warranty expired']; + + $db = Factory::getContainer()->get(DatabaseInterface::class); + $now = Factory::getDate()->toSql(); + + $claim = (object) [ + 'equipment_id' => $equipmentId, + 'wo_id' => $woId, + 'description' => $description, + 'claim_amount' => $claimAmount, + 'status' => 'submitted', + 'submitted_at' => $now, + 'submitted_by' => Factory::getApplication()->getIdentity()->id, + ]; + + $db->insertObject('#__mokosuitefield_warranty_claims', $claim, 'id'); + return (object) ['success' => true, 'claim_id' => (int) $claim->id]; + } + + /** + * Get equipment with warranties expiring within N days. + */ + public static function getExpiringSoon(int $days = 90): array + { + $db = Factory::getContainer()->get(DatabaseInterface::class); + + $db->setQuery($db->getQuery(true) + ->select('e.*, l.name AS location_name, cd.name AS customer_name') + ->from($db->quoteName('#__mokosuitefield_equipment', 'e')) + ->join('LEFT', $db->quoteName('#__mokosuitefield_locations', 'l') . ' ON l.id = e.location_id') + ->join('LEFT', $db->quoteName('#__contact_details', 'cd') . ' ON cd.id = e.contact_id') + ->where($db->quoteName('e.warranty_end') . ' IS NOT NULL') + ->where($db->quoteName('e.warranty_end') . ' BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL ' . (int) $days . ' DAY)') + ->order('e.warranty_end ASC')); + + return $db->loadObjectList() ?: []; + } +} -- 2.52.0 From 2a1ca75d2cf6b9b2ff71cbc693b827b709b8479e Mon Sep 17 00:00:00 2001 From: "gitea-actions[bot]" Date: Sun, 21 Jun 2026 04:25:50 +0000 Subject: [PATCH 2/5] chore(version): auto-bump patch 01.03.01-dev [skip ci] --- .mokogitea/workflows/issue-branch.yml | 2 +- source/pkg_mokosuitefield.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.mokogitea/workflows/issue-branch.yml b/.mokogitea/workflows/issue-branch.yml index 75a6963..1a81115 100644 --- a/.mokogitea/workflows/issue-branch.yml +++ b/.mokogitea/workflows/issue-branch.yml @@ -5,7 +5,7 @@ # FILE INFORMATION # DEFGROUP: Gitea.Workflow # INGROUP: mokocli.Automation -# VERSION: 01.00.00 +# VERSION: 01.03.01 # BRIEF: Auto-create feature branch when an issue is opened name: "Universal: Issue Branch" diff --git a/source/pkg_mokosuitefield.xml b/source/pkg_mokosuitefield.xml index b592cd8..566d231 100644 --- a/source/pkg_mokosuitefield.xml +++ b/source/pkg_mokosuitefield.xml @@ -2,7 +2,7 @@ Package - MokoSuite Field mokosuitefield - 01.03.00 + 01.03.01 2026-06-12 Moko Consulting hello@mokoconsulting.tech -- 2.52.0 From ec1618c425c030c92720df5f9b9594432380d3f6 Mon Sep 17 00:00:00 2001 From: "gitea-actions[bot]" Date: Sun, 21 Jun 2026 04:25:58 +0000 Subject: [PATCH 3/5] chore(version): pre-release bump to 01.03.02-dev [skip ci] --- .mokogitea/workflows/issue-branch.yml | 2 +- source/pkg_mokosuitefield.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.mokogitea/workflows/issue-branch.yml b/.mokogitea/workflows/issue-branch.yml index 1a81115..e813c4e 100644 --- a/.mokogitea/workflows/issue-branch.yml +++ b/.mokogitea/workflows/issue-branch.yml @@ -5,7 +5,7 @@ # FILE INFORMATION # DEFGROUP: Gitea.Workflow # INGROUP: mokocli.Automation -# VERSION: 01.03.01 +# VERSION: 01.03.02 # BRIEF: Auto-create feature branch when an issue is opened name: "Universal: Issue Branch" diff --git a/source/pkg_mokosuitefield.xml b/source/pkg_mokosuitefield.xml index 566d231..e53bd5e 100644 --- a/source/pkg_mokosuitefield.xml +++ b/source/pkg_mokosuitefield.xml @@ -2,7 +2,7 @@ Package - MokoSuite Field mokosuitefield - 01.03.01 + 01.03.02 2026-06-12 Moko Consulting hello@mokoconsulting.tech -- 2.52.0 From c8b1b32b7122d75333f0250147b445ccf209c37f Mon Sep 17 00:00:00 2001 From: Jonathan Miller Date: Sat, 20 Jun 2026 23:38:25 -0500 Subject: [PATCH 4/5] fix: warranty claim operator precedence bug + WO validation --- .../src/Helper/WarrantyHelper.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/source/packages/plg_system_mokosuitefield/src/Helper/WarrantyHelper.php b/source/packages/plg_system_mokosuitefield/src/Helper/WarrantyHelper.php index c1f3eb0..093fef5 100644 --- a/source/packages/plg_system_mokosuitefield/src/Helper/WarrantyHelper.php +++ b/source/packages/plg_system_mokosuitefield/src/Helper/WarrantyHelper.php @@ -54,9 +54,16 @@ class WarrantyHelper { $warranty = self::checkWarranty($equipmentId); - if (!$warranty->found ?? true) return (object) ['success' => false, 'error' => 'Equipment not found']; + if (empty($warranty->id)) return (object) ['success' => false, 'error' => 'Equipment not found']; if (!$warranty->under_warranty) return (object) ['success' => false, 'error' => 'Warranty expired']; + // Verify work order exists and is linked to this equipment + $db->setQuery($db->getQuery(true)->select('id')->from('#__mokosuitefield_work_orders') + ->where('id = ' . (int) $woId)); + if (!(int) $db->loadResult()) { + return (object) ['success' => false, 'error' => 'Invalid work order']; + } + $db = Factory::getContainer()->get(DatabaseInterface::class); $now = Factory::getDate()->toSql(); -- 2.52.0 From b2472ddcdc8f396e40c8c0fa2b6f50f57c0b8b19 Mon Sep 17 00:00:00 2001 From: "gitea-actions[bot]" Date: Sun, 21 Jun 2026 04:39:45 +0000 Subject: [PATCH 5/5] chore(version): auto-bump patch 01.03.03-dev [skip ci] --- .mokogitea/workflows/issue-branch.yml | 2 +- source/pkg_mokosuitefield.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.mokogitea/workflows/issue-branch.yml b/.mokogitea/workflows/issue-branch.yml index e813c4e..028fad8 100644 --- a/.mokogitea/workflows/issue-branch.yml +++ b/.mokogitea/workflows/issue-branch.yml @@ -5,7 +5,7 @@ # FILE INFORMATION # DEFGROUP: Gitea.Workflow # INGROUP: mokocli.Automation -# VERSION: 01.03.02 +# VERSION: 01.03.03 # BRIEF: Auto-create feature branch when an issue is opened name: "Universal: Issue Branch" diff --git a/source/pkg_mokosuitefield.xml b/source/pkg_mokosuitefield.xml index e53bd5e..3808d75 100644 --- a/source/pkg_mokosuitefield.xml +++ b/source/pkg_mokosuitefield.xml @@ -2,7 +2,7 @@ Package - MokoSuite Field mokosuitefield - 01.03.02 + 01.03.03 2026-06-12 Moko Consulting hello@mokoconsulting.tech -- 2.52.0