pluck('value', 'setting') ->toArray(); return [ 'CoverageAPIKey' => $settings['CoverageAPIKey'] ?? '', 'DefaultConnectionType' => $settings['DefaultConnectionType'] ?? 'all', 'EnableDebugMode' => $settings['EnableDebugMode'] ?? '0', 'RICAStoragePath' => $settings['RICAStoragePath'] ?? '/assets/rica_documents/', 'RICARequired' => $settings['RICARequired'] ?? '1', ]; } catch (\Exception $e) { // Return default values if the table doesn't exist yet return [ 'CoverageAPIKey' => '', 'DefaultConnectionType' => 'all', 'EnableDebugMode' => '0', 'RICAStoragePath' => '/assets/rica_documents/', 'RICARequired' => '1', ]; } } // Function to save module configuration function axxesstheme_saveConfig($config) { foreach ($config as $key => $value) { Capsule::table('axxesstheme_settings')->updateOrInsert( ['setting' => $key], ['value' => $value, 'updated_at' => date('Y-m-d H:i:s')] ); } } // Function to get product groups function axxesstheme_getProductGroups() { try { return Capsule::table('tblproductgroups') ->orderBy('order') ->get(); } catch (\Exception $e) { return []; } } // Function to get products function axxesstheme_getProducts() { try { return Capsule::table('tblproducts') ->join('tblpricing', 'tblproducts.id', '=', 'tblpricing.relid') ->leftJoin('axxesstheme_products', 'tblproducts.id', '=', 'axxesstheme_products.product_id') ->where('tblpricing.type', 'product') ->select('tblproducts.*', 'tblpricing.*', 'axxesstheme_products.*') ->get(); } catch (\Exception $e) { return []; } } // Function to get RICA records function axxesstheme_getRicaRecords() { try { return Capsule::table('axxesstheme_rica') ->join('tblorders', 'axxesstheme_rica.order_id', '=', 'tblorders.id') ->join('tblusers', 'axxesstheme_rica.user_id', '=', 'tblusers.id') ->select( 'axxesstheme_rica.*', 'tblorders.ordernum', 'tblusers.firstname', 'tblusers.lastname', 'tblusers.email' ) ->orderBy('axxesstheme_rica.created_at', 'desc') ->get(); } catch (\Exception $e) { return []; } } // Function to update RICA status function axxesstheme_updateRicaStatus($ricaId, $status, $notes = null) { try { $update = [ 'status' => $status, 'updated_at' => date('Y-m-d H:i:s'), ]; if ($notes) { $update['notes'] = $notes; } Capsule::table('axxesstheme_rica') ->where('id', $ricaId) ->update($update); return ['success' => true]; } catch (\Exception $e) { return ['success' => false, 'message' => $e->getMessage()]; } } // Function to check if all required tables exist function axxesstheme_checkTables() { $requiredTables = [ 'axxesstheme_settings', 'axxesstheme_products', 'axxesstheme_rica' ]; foreach ($requiredTables as $table) { if (!Capsule::schema()->hasTable($table)) { return false; } } return true; }