Compare commits
10 Commits
version/01.07.00
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| d7e6ec338e | |||
| 162298f8f9 | |||
| be03793478 | |||
| 4d4bd0c906 | |||
| b209d019a9 | |||
| 181d5f1450 | |||
| 1bbba00200 | |||
| 54a9f10630 | |||
| 4ec90d38f2 | |||
| 0e385fcb9c |
@@ -5,7 +5,7 @@
|
||||
# FILE INFORMATION
|
||||
# DEFGROUP: Gitea.Workflow
|
||||
# INGROUP: mokocli.Automation
|
||||
# VERSION: 01.07.00
|
||||
# VERSION: 01.08.02
|
||||
# BRIEF: Auto-create feature branch when an issue is opened
|
||||
|
||||
name: "Universal: Issue Branch"
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
namespace Moko\Plugin\System\MokoSuiteField\Helper;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\Database\DatabaseInterface;
|
||||
|
||||
/**
|
||||
* Customer satisfaction — post-service surveys, NPS scoring, technician ratings.
|
||||
*/
|
||||
class CustomerSatisfactionHelper
|
||||
{
|
||||
/**
|
||||
* Record a post-service survey response.
|
||||
*/
|
||||
public static function recordSurvey(int $workOrderId, int $contactId, int $rating, ?string $comment = null): object
|
||||
{
|
||||
if ($rating < 1 || $rating > 5) {
|
||||
throw new \InvalidArgumentException('Rating must be 1-5.');
|
||||
}
|
||||
|
||||
$db = Factory::getContainer()->get(DatabaseInterface::class);
|
||||
|
||||
// Prevent duplicate surveys per work order
|
||||
$db->setQuery($db->getQuery(true)
|
||||
->select('id')
|
||||
->from('#__mokosuitefield_surveys')
|
||||
->where('work_order_id = ' . (int) $workOrderId)
|
||||
->where('contact_id = ' . (int) $contactId));
|
||||
|
||||
if ($db->loadResult()) {
|
||||
return (object) ['success' => false, 'error' => 'Survey already submitted for this work order'];
|
||||
}
|
||||
|
||||
$filter = \Joomla\Filter\InputFilter::getInstance();
|
||||
|
||||
$survey = (object) [
|
||||
'work_order_id' => $workOrderId,
|
||||
'contact_id' => $contactId,
|
||||
'rating' => $rating,
|
||||
'comment' => $comment !== null ? $filter->clean($comment, 'STRING') : null,
|
||||
'nps_score' => $rating >= 4 ? 'promoter' : ($rating >= 3 ? 'passive' : 'detractor'),
|
||||
'created_at' => Factory::getDate()->toSql(),
|
||||
];
|
||||
|
||||
$db->insertObject('#__mokosuitefield_surveys', $survey, 'id');
|
||||
|
||||
return (object) ['success' => true, 'survey_id' => (int) $survey->id];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get NPS (Net Promoter Score) for a period.
|
||||
*/
|
||||
public static function getNps(string $from = '', string $to = ''): object
|
||||
{
|
||||
$from = $from ?: date('Y-01-01');
|
||||
$to = $to ?: date('Y-m-d');
|
||||
|
||||
if (!\DateTime::createFromFormat('Y-m-d', $from) || !\DateTime::createFromFormat('Y-m-d', $to)) {
|
||||
throw new \InvalidArgumentException('Date parameters must be Y-m-d format.');
|
||||
}
|
||||
|
||||
$db = Factory::getContainer()->get(DatabaseInterface::class);
|
||||
|
||||
$db->setQuery($db->getQuery(true)
|
||||
->select('COUNT(*) AS total_responses')
|
||||
->select('SUM(CASE WHEN rating >= 4 THEN 1 ELSE 0 END) AS promoters')
|
||||
->select('SUM(CASE WHEN rating = 3 THEN 1 ELSE 0 END) AS passives')
|
||||
->select('SUM(CASE WHEN rating <= 2 THEN 1 ELSE 0 END) AS detractors')
|
||||
->select('AVG(rating) AS avg_rating')
|
||||
->from('#__mokosuitefield_surveys')
|
||||
->where('DATE(created_at) BETWEEN ' . $db->quote($from) . ' AND ' . $db->quote($to)));
|
||||
|
||||
$stats = $db->loadObject();
|
||||
$total = (int) ($stats->total_responses ?? 0);
|
||||
$promoterPct = $total > 0 ? (int) $stats->promoters / $total * 100 : 0;
|
||||
$detractorPct = $total > 0 ? (int) $stats->detractors / $total * 100 : 0;
|
||||
|
||||
return (object) [
|
||||
'nps' => round($promoterPct - $detractorPct),
|
||||
'total_responses' => $total,
|
||||
'promoters' => (int) ($stats->promoters ?? 0),
|
||||
'passives' => (int) ($stats->passives ?? 0),
|
||||
'detractors' => (int) ($stats->detractors ?? 0),
|
||||
'avg_rating' => round((float) ($stats->avg_rating ?? 0), 1),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get technician satisfaction rankings.
|
||||
*/
|
||||
public static function getTechnicianRankings(int $limit = 20): array
|
||||
{
|
||||
$db = Factory::getContainer()->get(DatabaseInterface::class);
|
||||
|
||||
$db->setQuery($db->getQuery(true)
|
||||
->select('t.id AS tech_id, cd.name AS tech_name')
|
||||
->select('COUNT(s.id) AS survey_count')
|
||||
->select('AVG(s.rating) AS avg_rating')
|
||||
->select('SUM(CASE WHEN s.rating >= 4 THEN 1 ELSE 0 END) AS five_star_count')
|
||||
->from($db->quoteName('#__mokosuitefield_surveys', 's'))
|
||||
->join('INNER', $db->quoteName('#__mokosuitefield_work_orders', 'wo') . ' ON wo.id = s.work_order_id')
|
||||
->join('INNER', $db->quoteName('#__mokosuitefield_technicians', 't') . ' ON t.id = wo.technician_id')
|
||||
->join('LEFT', $db->quoteName('#__contact_details', 'cd') . ' ON cd.id = t.contact_id')
|
||||
->group('t.id, cd.name')
|
||||
->having('COUNT(s.id) >= 3')
|
||||
->order('avg_rating DESC'), 0, min(max(1, $limit), 100));
|
||||
|
||||
$results = $db->loadObjectList() ?: [];
|
||||
|
||||
foreach ($results as &$r) {
|
||||
$r->avg_rating = round((float) $r->avg_rating, 1);
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
@@ -47,8 +47,9 @@ class TruckStockHelper
|
||||
$db->setQuery($db->getQuery(true)
|
||||
->update('#__mokosuitefield_truck_stock')
|
||||
->set('quantity = quantity - ' . (float) $qty)
|
||||
->where('vehicle_id = ' . $vehicleId)
|
||||
->where('product_id = ' . $productId));
|
||||
->where('vehicle_id = ' . (int) $vehicleId)
|
||||
->where('product_id = ' . (int) $productId)
|
||||
->where('quantity >= ' . (float) $qty));
|
||||
$db->execute();
|
||||
|
||||
return $db->getAffectedRows() > 0;
|
||||
@@ -58,7 +59,11 @@ class TruckStockHelper
|
||||
{
|
||||
$db = Factory::getContainer()->get(DatabaseInterface::class);
|
||||
|
||||
$db->setQuery("INSERT INTO #__mokosuitefield_truck_stock (vehicle_id, product_id, quantity, last_restocked) VALUES ({$vehicleId}, {$productId}, {$qty}, CURDATE()) ON DUPLICATE KEY UPDATE quantity = quantity + {$qty}, last_restocked = CURDATE()");
|
||||
$db->setQuery(
|
||||
'INSERT INTO #__mokosuitefield_truck_stock (vehicle_id, product_id, quantity, last_restocked)'
|
||||
. ' VALUES (' . (int) $vehicleId . ', ' . (int) $productId . ', ' . (float) $qty . ', CURDATE())'
|
||||
. ' ON DUPLICATE KEY UPDATE quantity = quantity + ' . (float) $qty . ', last_restocked = CURDATE()'
|
||||
);
|
||||
$db->execute();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,14 +57,14 @@ class WarrantyHelper
|
||||
if (empty($warranty->id)) 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);
|
||||
|
||||
// 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) [
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<extension type="package" method="upgrade">
|
||||
<name>Package - MokoSuite Field</name>
|
||||
<packagename>mokosuitefield</packagename>
|
||||
<version>01.07.00</version>
|
||||
<version>01.08.02</version>
|
||||
<creationDate>2026-06-12</creationDate>
|
||||
<author>Moko Consulting</author>
|
||||
<authorEmail>hello@mokoconsulting.tech</authorEmail>
|
||||
|
||||
Reference in New Issue
Block a user