motorbike/app/Models/Reports.php
andrymodeste 38d37a0987 feat: modifications et corrections du 03-04-2026
- Bouton impression conditionnel : 2 boutons (Facture + BL) si 1 produit, 1 bouton (BL) si plusieurs produits
- Ajout filtres (date, point de vente, utilisateur) sur la page Rapports principale
- Ajout filtres (date, point de vente) sur la page Rapports/Stock pour les 3 tableaux
- Remplacement affichage "UGS" par "N° SERIE" dans toutes les pages
- Mise en page facture avec remise : titre FACTURE repositionné, tableau plus compact
- Correction remise commandes multi-produits : total_price recevait un tableau au lieu d'un nombre
- SuperAdmin voit toutes les remises (tous statuts) au lieu de seulement "En attente"

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 08:49:40 +02:00

89 lines
2.5 KiB
PHP

<?php
namespace App\Models;
use CodeIgniter\Model;
class Reports extends Model
{
/**
* table name
* @var string
*/
protected $table = 'orders';
/**
* total month
* @return array<int|string>
*/
private function months()
{
return ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
}
/**
* Getting the year of the orders (paid_status = 1 or 3)
* @return array
*/
public function getOrderYear()
{
$result = $this->whereIn('paid_status', [1, 3])->findAll(); // ← CHANGÉ ICI
$return_data = array_map(function($v) {
return date('Y', strtotime($v['date_time']));
}, $result);
return array_values(array_unique($return_data));
}
/**
* Getting the order reports based on the year and months
* @param mixed $year
* @return array<array>
*/
public function getOrderData($year, $startDate = null, $endDate = null, $storeId = null, $userId = null)
{
if ($year) {
$months = $this->months();
// Fetch orders with paid_status = 1 or 3
$builder = $this->whereIn('paid_status', [1, 3]);
if (!empty($storeId)) {
$builder->where('store_id', $storeId);
}
if (!empty($userId)) {
$builder->where('user_id', $userId);
}
if (!empty($startDate)) {
$builder->where('DATE(date_time) >=', $startDate);
}
if (!empty($endDate)) {
$builder->where('DATE(date_time) <=', $endDate);
}
$result = $builder->findAll();
$final_data = [];
foreach ($months as $month) {
$get_mon_year = $year . '-' . $month;
$final_data[$get_mon_year] = [];
foreach ($result as $v) {
$month_year = date('Y-m', strtotime($v['date_time']));
if ($get_mon_year == $month_year) {
if (!empty($v['discount']) && $v['discount'] > 0) {
$v['amount_to_display'] = $v['discount'];
} else {
$v['amount_to_display'] = $v['gross_amount'];
}
$final_data[$get_mon_year][] = $v;
}
}
}
return $final_data;
}
return [];
}
}