diff --git a/.mokogitea/workflows/issue-branch.yml b/.mokogitea/workflows/issue-branch.yml index 75a6963..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.00.00 +# VERSION: 01.03.03 # BRIEF: Auto-create feature branch when an issue is opened name: "Universal: Issue Branch" 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..093fef5 --- /dev/null +++ b/source/packages/plg_system_mokosuitefield/src/Helper/WarrantyHelper.php @@ -0,0 +1,102 @@ +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 (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(); + + $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() ?: []; + } +} diff --git a/source/pkg_mokosuitefield.xml b/source/pkg_mokosuitefield.xml index b592cd8..3808d75 100644 --- a/source/pkg_mokosuitefield.xml +++ b/source/pkg_mokosuitefield.xml @@ -2,7 +2,7 @@ Package - MokoSuite Field mokosuitefield - 01.03.00 + 01.03.03 2026-06-12 Moko Consulting hello@mokoconsulting.tech