You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
222 lines
7.1 KiB
222 lines
7.1 KiB
<?php
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class SortieCaisse extends Model
|
|
{
|
|
/**
|
|
* table name
|
|
* @var string
|
|
*/
|
|
protected $table = 'sortie_caisse';
|
|
protected $primaryKey = 'id_sortie'; // Primary key column
|
|
// Dans le fichier App/Models/SortieCaisse.php
|
|
// Mettre à jour le tableau $allowedFields
|
|
|
|
protected $allowedFields = [
|
|
'montant_retire',
|
|
'date_retrait',
|
|
'motif',
|
|
'commentaire',
|
|
'fournisseur',
|
|
'nif_cin',
|
|
'statistique',
|
|
'telephone',
|
|
'code_postal',
|
|
'preuve_achat',
|
|
'sortie_personnel',
|
|
'source_fond',
|
|
'initiateur_demande',
|
|
'statut',
|
|
'user_id',
|
|
'store_id',
|
|
'mime_type',
|
|
'admin_raison',
|
|
// Champs pour le formulaire IM1
|
|
'nom_demandeur',
|
|
'fonction_demandeur',
|
|
'mode_paiement',
|
|
'montant_lettre',
|
|
'date_demande',
|
|
'reference',
|
|
// ✅ NOUVEAU CHAMP
|
|
'date_paiement_effectif', // Date à laquelle la caissière a effectué le paiement
|
|
// Champs pour le formulaire IM2/IM3
|
|
'numero_fiche',
|
|
'date_fiche',
|
|
'service_demandeur',
|
|
'objet_depense',
|
|
'nature_depense',
|
|
'montant_estime',
|
|
'mode_reglement',
|
|
'date_paiement_prevue',
|
|
'justificatifs',
|
|
'visa_demandeur',
|
|
'date_visa_demandeur',
|
|
'visa_chef_service',
|
|
'date_visa_chef_service',
|
|
'visa_direction',
|
|
'date_visa_direction',
|
|
'visa_conseil',
|
|
'date_visa_conseil',
|
|
'observations'
|
|
];
|
|
public function getAllSortieCaisse()
|
|
{
|
|
try {
|
|
$session = session();
|
|
$users = $session->get('user');
|
|
if ($users['group_name'] === 'Direction') {
|
|
return $this
|
|
->select('*')
|
|
->orderBy('date_retrait', 'DESC')
|
|
->findAll();
|
|
}
|
|
|
|
if ($users['group_name'] === 'Conseil') {
|
|
return $this
|
|
->select('*')
|
|
->orderBy('date_retrait', 'DESC')
|
|
->findAll();
|
|
}
|
|
|
|
if($users["group_name"]==="Caissière"){
|
|
return $this
|
|
->select('*')
|
|
->where('user_id', $users['id'])
|
|
->orderBy('date_retrait', 'DESC')
|
|
->findAll();
|
|
}
|
|
return $this
|
|
->select('*')
|
|
->where('user_id', $users['id'])
|
|
->orderBy('date_retrait', 'DESC')
|
|
->findAll();
|
|
} catch (\Exception $e) {
|
|
log_message('error', 'Erreur lors de la récupération des sorties caisse : ' . $e->getMessage());
|
|
return [];
|
|
}
|
|
}
|
|
|
|
public function getAllSortieCaisse1()
|
|
{
|
|
try {
|
|
$session = session();
|
|
$users = $session->get('user');
|
|
if ($users['group_name'] === 'Direction') {
|
|
return $this
|
|
->select('*')
|
|
->join('user_group', 'user_group.user_id = sortie_caisse.user_id')
|
|
->where('user_group.group_id', 7)
|
|
->orderBy('date_retrait', 'DESC')
|
|
->findAll();
|
|
}
|
|
|
|
if ($users['group_name'] === 'Conseil') {
|
|
return $this
|
|
->select('*')
|
|
->join('user_group', 'user_group.user_id = sortie_caisse.user_id')
|
|
->where('user_group.group_id', 6)
|
|
->orderBy('date_retrait', 'DESC')
|
|
->findAll();
|
|
}
|
|
|
|
if($users["group_name"]==="Caissière"){
|
|
return $this
|
|
->select('*')
|
|
->where('user_id', $users['id'])
|
|
->orderBy('date_retrait', 'DESC')
|
|
->findAll();
|
|
}
|
|
return $this
|
|
->select('*')
|
|
->where('user_id', $users['id'])
|
|
->orderBy('date_retrait', 'DESC')
|
|
->findAll();
|
|
} catch (\Exception $e) {
|
|
log_message('error', 'Erreur lors de la récupération des sorties caisse : ' . $e->getMessage());
|
|
return [];
|
|
}
|
|
}
|
|
|
|
public function addSortieCaisse(array $data) {
|
|
try {
|
|
return $this->insert($data);
|
|
} catch (\Exception $e) {
|
|
log_message('error', 'Erreur lors de l\'ajout de la sortie : ' . $e->getMessage());
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public function updateSortieCaisse(int $id, array $data) {
|
|
if ($id <= 0) {
|
|
log_message('error', 'ID invalide pour la mise à jour de la sortie caisse : ' . $id);
|
|
return false;
|
|
}
|
|
|
|
try {
|
|
return $this->update($id, $data);
|
|
} catch (\Exception $e) {
|
|
log_message('error', 'Erreur lors de la mise à jour du recouvrement : ' . $e->getMessage());
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public function getSortieCaisseSingle(int $id)
|
|
{
|
|
$reparation = $this->select('*')
|
|
->where('id_sortie', $id)
|
|
->first();
|
|
return $reparation;
|
|
}
|
|
|
|
public function getTotalSortieCaisse() {
|
|
$session = session();
|
|
$users = $session->get('user');
|
|
$isAdmin = in_array($users['group_name'], ['Conseil', 'Direction']);
|
|
|
|
if ($isAdmin) {
|
|
try {
|
|
return $this->select('
|
|
SUM(CASE WHEN mode_paiement = "En espèce" THEN montant_retire ELSE 0 END) AS total_espece,
|
|
SUM(CASE WHEN mode_paiement = "MVOLA" THEN montant_retire ELSE 0 END) AS total_mvola,
|
|
SUM(CASE WHEN mode_paiement = "Virement Bancaire" THEN montant_retire ELSE 0 END) AS total_virement,
|
|
SUM(montant_retire) AS mr
|
|
')
|
|
->whereIn('statut', ['Valider', 'Payé'])
|
|
->get()
|
|
->getRowObject();
|
|
} catch (\Exception $e) {
|
|
log_message('error', 'Erreur getTotalSortieCaisse (Admin) : ' . $e->getMessage());
|
|
return (object)[
|
|
'total_espece' => 0,
|
|
'total_mvola' => 0,
|
|
'total_virement' => 0,
|
|
'mr' => 0
|
|
];
|
|
}
|
|
} else {
|
|
try {
|
|
return $this->select('
|
|
SUM(CASE WHEN mode_paiement = "En espèce" THEN montant_retire ELSE 0 END) AS total_espece,
|
|
SUM(CASE WHEN mode_paiement = "MVOLA" THEN montant_retire ELSE 0 END) AS total_mvola,
|
|
SUM(CASE WHEN mode_paiement = "Virement Bancaire" THEN montant_retire ELSE 0 END) AS total_virement,
|
|
SUM(montant_retire) AS mr
|
|
')
|
|
->where('store_id', $users['store_id'])
|
|
->whereIn('statut', ['Valider', 'Payé'])
|
|
->get()
|
|
->getRowObject();
|
|
} catch (\Exception $e) {
|
|
log_message('error', 'Erreur getTotalSortieCaisse (Store) : ' . $e->getMessage());
|
|
return (object)[
|
|
'total_espece' => 0,
|
|
'total_mvola' => 0,
|
|
'total_virement' => 0,
|
|
'mr' => 0
|
|
];
|
|
}
|
|
}
|
|
}
|
|
}
|