@ -22,6 +22,87 @@ class SortieCaisseController extends AdminController
}
private $mapping = [
// superadmin
"Achat de matériel informatique" => [
'source_fond' => 'Budget Directionnel',
'initiateur_demande' => 'SuperAdmin'
],
"Achat équipement de sécurité" => [
'source_fond' => 'Budget Directionnel',
'initiateur_demande' => 'SuperAdmin'
],
"Achat mobilier de bureau" => [
'source_fond' => 'Budget Directionnel',
'initiateur_demande' => 'SuperAdmin'
],
"Paiement salaire des collaborateurs" => [
'source_fond' => 'Budget Directionnel',
'initiateur_demande' => 'SuperAdmin'
],
"Cotisation sociales" => [
'source_fond' => 'Budget Directionnel',
'initiateur_demande' => 'SuperAdmin'
],
"Remboursement d'avance moto" => [
'source_fond' => 'Budget Directionnel',
'initiateur_demande' => 'SuperAdmin'
],
"Payement prime ou endemnité" => [
'source_fond' => 'Budget Directionnel',
'initiateur_demande' => 'SuperAdmin'
],
"Paiement sous-traitant" => [
'source_fond' => 'Budget Directionnel',
'initiateur_demande' => 'SuperAdmin'
],
"Frais de formation" => [
'source_fond' => 'Budget Directionnel',
'initiateur_demande' => 'SuperAdmin'
],
"Paiement loyer" => [
'source_fond' => 'Budget Directionnel',
'initiateur_demande' => 'SuperAdmin'
],
"Frais de formation externe" => [
'source_fond' => 'Budget Directionnel',
'initiateur_demande' => 'SuperAdmin'
],
"Abonnement internet" => [
'source_fond' => 'Budget Directionnel',
'initiateur_demande' => 'SuperAdmin'
],
"Entretien locaux" => [
'source_fond' => 'Budget Directionnel',
'initiateur_demande' => 'SuperAdmin'
],
"Paiement fournisseur" => [
'source_fond' => 'Budget Directionnel',
'initiateur_demande' => 'SuperAdmin'
],
"Remboursement de frais" => [
'source_fond' => 'Budget Directionnel',
'initiateur_demande' => 'SuperAdmin'
],
"Paiement assurance" => [
'source_fond' => 'Budget Directionnel',
'initiateur_demande' => 'SuperAdmin'
],
"Réparation immobilisation" => [
'source_fond' => 'Budget Directionnel',
'initiateur_demande' => 'SuperAdmin'
],
"DVD" => [
'source_fond' => 'Budget Directionnel',
'initiateur_demande' => 'SuperAdmin'
],
"Déclaration fiscale - Déclaration d'impôts" => [
'source_fond' => 'Budget Directionnel',
'initiateur_demande' => 'SuperAdmin'
],
"Enregistrement des contrats de bail au centre fiscal" => [
'source_fond' => 'Budget Directionnel',
'initiateur_demande' => 'SuperAdmin'
],
// ----- Raisons Admin -----
"Achat de matériel informatique" => [
'source_fond' => 'Budget Directionnel',
@ -243,7 +324,7 @@ class SortieCaisseController extends AdminController
$users = $session->get('user');
// ✅ Vérifier si l'utilisateur est DAF ou Direction UNIQUEMENT
$canManage = in_array($users['group_name'], ['Direction', 'DAF']);
$canManage = in_array($users['group_name'], ['Direction', 'DAF','SuperAdmin' ]);
$isCaissiere = $users['group_name'] === 'Caissière';
$result = [
@ -289,7 +370,7 @@ class SortieCaisseController extends AdminController
$buttons // Les caissières ne verront PAS les boutons (car $canManage = false)
];
}
elseif ($users["group_name"] === "Direction" || $users["group_name"] === "DAF") {
elseif ($users["group_name"] === "Direction" || $users["group_name"] === "DAF" ||$users["group_name"] === "SuperAdmin" ) {
$result['data'][$key] = [
$value['id_sortie'],
number_format($value['montant_retire'], 0, '.', ' '),
@ -328,6 +409,10 @@ class SortieCaisseController extends AdminController
* ✅ NOUVELLE MÉTHODE : Marquer un décaissement comme payé
* Accessible uniquement par les caissières
*/
/**
* ✅ CORRECTION COMPLÈTE : Marquer un décaissement comme payé
* Accessible uniquement par les caissières
*/
public function markAsPaid($id_sortie)
{
// Vérifier que l'utilisateur est une caissière
@ -371,7 +456,8 @@ class SortieCaisseController extends AdminController
$result = $SortieCaisse->updateSortieCaisse($id_sortie, $data);
if ($result) {
// Créer une notification pour DAF et Direction DU MÊME STORE
// ✅ Créer une notification pour TOUS les DAF, Direction et SuperAdmin
try {
if (class_exists('App\Controllers\NotificationController')) {
$Notification = new NotificationController();
@ -379,29 +465,50 @@ class SortieCaisseController extends AdminController
$message = "💰 Décaissement payé - " . $montant . " Ar< br > " .
"Motif: " . $decaissement['motif'] . "< br > " .
"Caissière: " . $users['firstname'] . ' ' . $users['lastname'] . "< br > " .
"Store: " . $this->returnStoreName($users['store_id']);
"Store: " . $this->returnStoreName($decaissement['store_id']);
// ✅ Récupérer TOUS les stores
$Stores = new Stores();
$allStores = $Stores->getActiveStore();
// ✅ Notifier la Direction DU MÊME STORE
// ✅ Notifier Direction, DAF et SuperAdmin de TOUS les stores
if (is_array($allStores) & & count($allStores) > 0) {
foreach ($allStores as $store) {
// Notifier Direction
$Notification->createNotification(
$message,
"Direction",
(int)$users['store_id'], // ✅ Store ID de la caissière
(int)$store['id'],
'sortieCaisse'
);
// ✅ Notifier le DAF DU MÊME STORE
// Notifier DAF
$Notification->createNotification(
$message,
"DAF",
(int)$users['store_id'], // ✅ Store ID de la caissière
(int)$store['id'],
'sortieCaisse'
);
// Notifier SuperAdmin
$Notification->createNotification(
$message,
"SuperAdmin",
(int)$store['id'],
'sortieCaisse'
);
}
}
}
} catch (\Exception $e) {
// Logger l'erreur mais continuer
log_message('error', 'Erreur notification markAsPaid: ' . $e->getMessage());
}
return $this->response->setJSON([
'success' => true,
'messages' => '✅ Décaissement marqué comme < strong > PAYÉ< / strong > < br > ' .
'Direction et DAF de ' . $this->returnStoreName($users['store_id']) . ' ont été notifiés.< br > ' .
'Tous les Direction, DAF et SuperAdmin ont été notifiés.< br > ' .
'Montant: ' . number_format($decaissement['montant_retire'], 0, ',', ' ') . ' Ar'
]);
@ -413,14 +520,13 @@ class SortieCaisseController extends AdminController
}
} catch (\Exception $e) {
log_message('error', 'Erreur markAsPaid: ' . $e->getMessage());
log_message('error', 'Erreur markAsPaid: ' . $e->getMessage() . ' | Ligne: ' . $e->getLin e());
return $this->response->setJSON([
'success' => false,
'messages' => 'Erreur serveur: ' . $e->getMessage()
]);
}
}
public function fetchSortieCaisseData1()
{
helper(['url', 'form']);
@ -436,7 +542,7 @@ class SortieCaisseController extends AdminController
$users = $session->get('user');
// ✅ Vérifier si l'utilisateur est DAF ou Direction UNIQUEMENT
$canManage = in_array($users['group_name'], ['Direction', 'DAF']);
$canManage = in_array($users['group_name'], ['Direction', 'DAF','SuperAdmin' ]);
$isCaissiere = $users['group_name'] === 'Caissière';
$result = [
@ -481,7 +587,7 @@ class SortieCaisseController extends AdminController
$buttons // Les caissières ne verront PAS les boutons
];
}
elseif ($users["group_name"] === "Direction" || $users["group_name"] === "DAF") {
elseif ($users["group_name"] === "Direction" || $users["group_name"] === "DAF" || $users["group_name"] === "SuperAdmin" ) {
$result['data'][$key] = [
$value['id_sortie'],
number_format($value['montant_retire'], 0, '.', ' '),
@ -591,10 +697,10 @@ class SortieCaisseController extends AdminController
}
// Recouvrements
$total_recouvrement_me = 0; // Mvola -> Espèce
$total_recouvrement_be = 0; // Banque -> Espèce
$total_recouvrement_bm = 0; // Banque -> Mvola
$total_recouvrement_mb = 0; // Mvola -> Banque
$total_recouvrement_me = 0;
$total_recouvrement_be = 0;
$total_recouvrement_bm = 0;
$total_recouvrement_mb = 0;
if (is_object($totalRecouvrement)) {
$total_recouvrement_me = isset($totalRecouvrement->me) ? (float) $totalRecouvrement->me : 0;
@ -621,14 +727,12 @@ class SortieCaisseController extends AdminController
}
// CALCUL DES SOLDES DISPONIBLES PAR MODE DE PAIEMENT
// Espèce: Orders + Recouvrements entrants - Sorties en espèce
$total_espece_disponible = $total_espece1 +
$total_espece2 +
$total_recouvrement_me +
$total_recouvrement_be -
$total_sortie_espece;
// MVOLA: Orders - Recouvrements sortants + Recouvrements entrants - Sorties MVOLA
$total_mvola_disponible = $total_mvola1 +
$total_mvola2 -
$total_recouvrement_me -
@ -636,7 +740,6 @@ class SortieCaisseController extends AdminController
$total_recouvrement_bm -
$total_sortie_mvola;
// Virement: Orders - Recouvrements sortants + Recouvrements entrants - Sorties virement
$total_virement_disponible = $total_virement1 +
$total_virement2 -
$total_recouvrement_be -
@ -742,8 +845,8 @@ class SortieCaisseController extends AdminController
$data['date_visa_chef_service'] = $this->request->getPost('date_visa_chef_service') ?? null;
$data['visa_direction'] = $this->request->getPost('visa_direction') ?? '';
$data['date_visa_direction'] = $this->request->getPost('date_visa_direction') ?? null;
$data['visa_conseil'] = $this->request->getPost('visa_conseil ') ?? '';
$data['date_visa_conseil'] = $this->request->getPost('date_visa_conseil ') ?? null;
$data['visa_superAdmin'] = $this->request->getPost('visa_superAdmin ') ?? '';
$data['date_visa_superAdmin'] = $this->request->getPost('date_visa_superAdmin ') ?? null;
$data['observations'] = $this->request->getPost('observations') ?? '';
}
@ -767,25 +870,49 @@ class SortieCaisseController extends AdminController
$result = $model->addSortieCaisse($data);
if ($result) {
// Notification UNIQUEMENT pour la Direction du même store
// ✅ Notification pour TOUS les Direction, DAF et SuperAdmin
try {
if (class_exists('App\Controllers\NotificationController')) {
$Notification = new NotificationController();
// ✅ Notifier UNIQUEMENT la Direction du store concerné
$message = "Nouvelle demande de décaissement de " .
number_format($montant_retire, 0, ',', ' ') . " Ar (" . $mode_paiement . ")< br > " .
"Store: " . $this->returnStoreName($user['store_id']) . "< br > " .
"Demandeur: " . $user['firstname'] . ' ' . $user['lastname'];
// ✅ Récupérer TOUS les stores
$Stores = new Stores();
$allStores = $Stores->getActiveStore();
// ✅ Notifier Direction, DAF et SuperAdmin de TOUS les stores
if (is_array($allStores) & & count($allStores) > 0) {
foreach ($allStores as $store) {
$Notification->createNotification(
"Nouvelle demande de décaissement de " . number_format($montant_retire, 0, ',', ' ') . " Ar (" . $mode_paiement . ")",
$message ,
"Direction",
(int)$user['store_id'], // ✅ Store ID du créateur
(int)$store['id'],
'sortieCaisse'
);
// ✅ Notifier aussi le DAF du même store (si vous avez des DAF par store)
$Notification->createNotification(
"Nouvelle demande de décaissement de " . number_format($montant_retire, 0, ',', ' ') . " Ar (" . $mode_paiement . ")",
$message ,
"DAF",
(int)$user['store_id'], // ✅ Store ID du créateur
(int)$store['id'],
'sortieCaisse'
);
$Notification->createNotification(
$message,
"SuperAdmin",
(int)$store['id'],
'sortieCaisse'
);
}
}
}
} catch (\Exception $e) {
log_message('error', 'Erreur notification createSortieCaisse: ' . $e->getMessage());
// Continue même si la notification échoue
}
return $this->response->setJSON([
@ -793,7 +920,7 @@ class SortieCaisseController extends AdminController
'messages' => 'Décaissement de ' . number_format($montant_retire, 0, ',', ' ') . ' Ar créé avec succès< br > ' .
'Mode de paiement: ' . $mode_paiement . '< br > ' .
'Nouveau solde ' . $mode_paiement_label . ': ' . number_format($fonds_disponible - $montant_retire, 0, ',', ' ') . ' Ar< br > ' .
'< em > Notification envoyée à la Direction de ' . $this->returnStoreName($user['store_id']) . ' < / em > '
'< em > Notification envoyée à tous les Direction, DAF et SuperAdmin < / em > '
]);
} else {
@ -1096,15 +1223,15 @@ class SortieCaisseController extends AdminController
switch ($statut) {
case "Valider":
$message = "✅ Votre décaissement a été validé par la Direction de " . $this->returnStoreName($store_id);
$message = "✅ Votre décaissement a été validé par la Direction< br > Store: " . $this->returnStoreName($store_id);
$Notification->createNotification($message, "Caissière", (int)$store_id, 'sortieCaisse');
break;
case "Refuser":
$message = "❌ Votre décaissement a été refusé par la Direction de " . $this->returnStoreName($store_id) . "< br > Raison: " . $this->request->getPost('admin_raison');
$message = "❌ Votre décaissement a été refusé par la Direction< br > Store: " . $this->returnStoreName($store_id) . "< br > Raison: " . $this->request->getPost('admin_raison');
$Notification->createNotification($message, "Caissière", (int)$store_id, 'sortieCaisse');
break;
case "En attente":
$message = "⏳ Votre décaissement a été mis en attente par la Direction de " . $this->returnStoreName($store_id);
$message = "⏳ Votre décaissement a été mis en attente par la Direction< br > Store: " . $this->returnStoreName($store_id);
$Notification->createNotification($message, "Caissière", (int)$store_id, 'sortieCaisse');
break;
}