22122025
This commit is contained in:
parent
b1ef2963b6
commit
b41ec0be0a
@ -11,9 +11,9 @@ class Mecanicien extends Model
|
|||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $table = 'reparations';
|
protected $table = 'reparations';
|
||||||
protected $primaryKey = 'reparation_id'; // Primary key of your table
|
protected $primaryKey = 'reparation_id';
|
||||||
protected $allowedFields = ['user_id', 'produit_id', 'reparation_statut', 'reparation_observation', 'reparation_debut', 'reparation_fin']; // Fields allowed for insert/update
|
protected $allowedFields = ['user_id', 'produit_id', 'reparation_statut', 'reparation_observation', 'reparation_debut', 'reparation_fin','store_id'];
|
||||||
protected $useTimestamps = false; // Set to true if your table has `created_at` and `updated_at` columns
|
protected $useTimestamps = false;
|
||||||
|
|
||||||
public function createRepation(array $data)
|
public function createRepation(array $data)
|
||||||
{
|
{
|
||||||
@ -37,7 +37,6 @@ class Mecanicien extends Model
|
|||||||
->where('users.id', $id)
|
->where('users.id', $id)
|
||||||
->findAll();
|
->findAll();
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
$reparation = [];
|
$reparation = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -45,7 +44,6 @@ class Mecanicien extends Model
|
|||||||
return $reparation;
|
return $reparation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getReparationSingle(int $id)
|
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.*')
|
$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')
|
->join('products', 'reparations.produit_id = products.id')
|
||||||
->where('reparations.reparation_id', $id)
|
->where('reparations.reparation_id', $id)
|
||||||
->first();
|
->first();
|
||||||
// return $this->where('user_id', $id)->findAll();
|
|
||||||
|
|
||||||
return $reparation;
|
return $reparation;
|
||||||
}
|
}
|
||||||
@ -75,22 +72,43 @@ class Mecanicien extends Model
|
|||||||
->get()
|
->get()
|
||||||
->getRow();
|
->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();
|
$session = session();
|
||||||
$user = $session->get('user');
|
$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('users', 'reparations.user_id = users.id')
|
||||||
->join('products', 'reparations.produit_id = products.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
|
// Filtre par utilisateur si pas admin
|
||||||
if ($user['group_name'] != "SuperAdmin" && $user['group_name'] != "Direction" && $user['group_name'] != "DAF") {
|
if ($user['group_name'] != "SuperAdmin" && $user['group_name'] != "Direction" && $user['group_name'] != "DAF") {
|
||||||
$builder->where('users.id', $id);
|
$builder->where('users.id', $id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ✅ APPLIQUER LES FILTRES PAR DATE
|
// ✅ FILTRE PAR DATEs
|
||||||
if (!empty($startDate) && !empty($endDate)) {
|
if (!empty($startDate) && !empty($endDate)) {
|
||||||
$builder->where('DATE(reparations.reparation_debut) >=', $startDate);
|
$builder->where('DATE(reparations.reparation_debut) >=', $startDate);
|
||||||
$builder->where('DATE(reparations.reparation_debut) <=', $endDate);
|
$builder->where('DATE(reparations.reparation_debut) <=', $endDate);
|
||||||
@ -100,9 +118,9 @@ class Mecanicien extends Model
|
|||||||
$builder->where('DATE(reparations.reparation_debut) <=', $endDate);
|
$builder->where('DATE(reparations.reparation_debut) <=', $endDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ✅ FILTRE PAR POINT DE VENTE
|
// ✅ FILTRE PAR MÉCANICIEN (remplace le filtre magasin)
|
||||||
if (!empty($pvente) && $pvente !== 'TOUS') {
|
if (!empty($mecanicId)) {
|
||||||
$builder->where('stores.name', $pvente);
|
$builder->where('reparations.user_id', $mecanicId);
|
||||||
}
|
}
|
||||||
|
|
||||||
$builder->orderBy('reparations.reparation_debut', 'DESC');
|
$builder->orderBy('reparations.reparation_debut', 'DESC');
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user