22122025
This commit is contained in:
parent
b1ef2963b6
commit
b41ec0be0a
@ -11,9 +11,9 @@ class Mecanicien extends Model
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'reparations';
|
||||
protected $primaryKey = 'reparation_id'; // Primary key of your table
|
||||
protected $allowedFields = ['user_id', 'produit_id', 'reparation_statut', 'reparation_observation', 'reparation_debut', 'reparation_fin']; // Fields allowed for insert/update
|
||||
protected $useTimestamps = false; // Set to true if your table has `created_at` and `updated_at` columns
|
||||
protected $primaryKey = 'reparation_id';
|
||||
protected $allowedFields = ['user_id', 'produit_id', 'reparation_statut', 'reparation_observation', 'reparation_debut', 'reparation_fin','store_id'];
|
||||
protected $useTimestamps = false;
|
||||
|
||||
public function createRepation(array $data)
|
||||
{
|
||||
@ -21,31 +21,29 @@ class Mecanicien extends Model
|
||||
}
|
||||
|
||||
public function getReparation(int $id = null)
|
||||
{
|
||||
$session = session();
|
||||
$user = $session->get('user');
|
||||
if ($user['group_name'] == "SuperAdmin" || $user['group_name'] == "Direction") {
|
||||
$reparation = $this->select('reparations.reparation_id as reparationsID, reparations.user_id, reparations.reparation_statut, reparations.produit_id, reparations.reparation_observation, reparations.reparation_debut, reparations.reparation_fin, users.*, products.*')
|
||||
->join('users', 'reparations.user_id = users.id')
|
||||
->join('products', 'reparations.produit_id = products.id')
|
||||
->findAll();
|
||||
} else {
|
||||
if ($id !== null) {
|
||||
{
|
||||
$session = session();
|
||||
$user = $session->get('user');
|
||||
if ($user['group_name'] == "SuperAdmin" || $user['group_name'] == "Direction") {
|
||||
$reparation = $this->select('reparations.reparation_id as reparationsID, reparations.user_id, reparations.reparation_statut, reparations.produit_id, reparations.reparation_observation, reparations.reparation_debut, reparations.reparation_fin, users.*, products.*')
|
||||
->join('users', 'reparations.user_id = users.id')
|
||||
->join('products', 'reparations.produit_id = products.id')
|
||||
->where('users.id', $id)
|
||||
->findAll();
|
||||
->join('users', 'reparations.user_id = users.id')
|
||||
->join('products', 'reparations.produit_id = products.id')
|
||||
->findAll();
|
||||
} else {
|
||||
|
||||
$reparation = [];
|
||||
if ($id !== null) {
|
||||
$reparation = $this->select('reparations.reparation_id as reparationsID, reparations.user_id, reparations.reparation_statut, reparations.produit_id, reparations.reparation_observation, reparations.reparation_debut, reparations.reparation_fin, users.*, products.*')
|
||||
->join('users', 'reparations.user_id = users.id')
|
||||
->join('products', 'reparations.produit_id = products.id')
|
||||
->where('users.id', $id)
|
||||
->findAll();
|
||||
} else {
|
||||
$reparation = [];
|
||||
}
|
||||
}
|
||||
|
||||
return $reparation;
|
||||
}
|
||||
|
||||
return $reparation;
|
||||
}
|
||||
|
||||
|
||||
public function getReparationSingle(int $id)
|
||||
{
|
||||
$reparation = $this->select('reparations.reparation_id as reparationsID, reparations.user_id, reparations.reparation_statut, reparations.reparation_statut, reparations.produit_id, reparations.reparation_observation, reparations.reparation_debut, reparations.reparation_fin, users.*, products.*')
|
||||
@ -53,7 +51,6 @@ class Mecanicien extends Model
|
||||
->join('products', 'reparations.produit_id = products.id')
|
||||
->where('reparations.reparation_id', $id)
|
||||
->first();
|
||||
// return $this->where('user_id', $id)->findAll();
|
||||
|
||||
return $reparation;
|
||||
}
|
||||
@ -75,22 +72,43 @@ class Mecanicien extends Model
|
||||
->get()
|
||||
->getRow();
|
||||
}
|
||||
public function getReparationWithFilters(int $id = null, $startDate = null, $endDate = null, $pvente = null)
|
||||
|
||||
/**
|
||||
* ✅ NOUVELLE MÉTHODE : Filtrage par mécanicien au lieu de magasin
|
||||
* @param int|null $id ID de l'utilisateur connecté
|
||||
* @param string|null $startDate Date de début
|
||||
* @param string|null $endDate Date de fin
|
||||
* @param int|null $mecanicId ID du mécanicien à filtrer
|
||||
* @return array
|
||||
*/
|
||||
public function getReparationWithFilters(int $id = null, $startDate = null, $endDate = null, $mecanicId = null)
|
||||
{
|
||||
$session = session();
|
||||
$user = $session->get('user');
|
||||
|
||||
$builder = $this->select('reparations.reparation_id as reparationsID, reparations.user_id, reparations.reparation_statut, reparations.produit_id, reparations.reparation_observation, reparations.reparation_debut, reparations.reparation_fin, users.*, products.*, stores.name as store_name')
|
||||
$builder = $this->select('
|
||||
reparations.reparation_id as reparationsID,
|
||||
reparations.user_id,
|
||||
reparations.reparation_statut,
|
||||
reparations.produit_id,
|
||||
reparations.reparation_observation,
|
||||
reparations.reparation_debut,
|
||||
reparations.reparation_fin,
|
||||
users.*,
|
||||
products.*,
|
||||
stores.name as store_name,
|
||||
COALESCE(reparations.store_id, products.store_id) as final_store_id
|
||||
')
|
||||
->join('users', 'reparations.user_id = users.id')
|
||||
->join('products', 'reparations.produit_id = products.id')
|
||||
->join('stores', 'products.store_id = stores.id', 'left'); // ✅ JOINTURE AVEC MAGASINS
|
||||
->join('stores', 'COALESCE(reparations.store_id, products.store_id) = stores.id', 'left');
|
||||
|
||||
// Filtre par utilisateur si pas admin
|
||||
if ($user['group_name'] != "SuperAdmin" && $user['group_name'] != "Direction" && $user['group_name'] != "DAF") {
|
||||
$builder->where('users.id', $id);
|
||||
}
|
||||
|
||||
// ✅ APPLIQUER LES FILTRES PAR DATE
|
||||
// ✅ FILTRE PAR DATEs
|
||||
if (!empty($startDate) && !empty($endDate)) {
|
||||
$builder->where('DATE(reparations.reparation_debut) >=', $startDate);
|
||||
$builder->where('DATE(reparations.reparation_debut) <=', $endDate);
|
||||
@ -100,13 +118,13 @@ class Mecanicien extends Model
|
||||
$builder->where('DATE(reparations.reparation_debut) <=', $endDate);
|
||||
}
|
||||
|
||||
// ✅ FILTRE PAR POINT DE VENTE
|
||||
if (!empty($pvente) && $pvente !== 'TOUS') {
|
||||
$builder->where('stores.name', $pvente);
|
||||
// ✅ FILTRE PAR MÉCANICIEN (remplace le filtre magasin)
|
||||
if (!empty($mecanicId)) {
|
||||
$builder->where('reparations.user_id', $mecanicId);
|
||||
}
|
||||
|
||||
$builder->orderBy('reparations.reparation_debut', 'DESC');
|
||||
|
||||
return $builder->findAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user