- 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>
83 lines
2.3 KiB
PHP
83 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
use DateTime;
|
|
|
|
class OrderItems extends Model
|
|
{
|
|
protected $table = 'orders_item';
|
|
protected $allowedFields = ['order_id', 'product_id', 'puissance', 'rate', 'amount','qty'];
|
|
|
|
public function insertOrderItem($data)
|
|
{
|
|
return $this->insert($data);
|
|
}
|
|
|
|
public function getOrdersItemData($order_id = null)
|
|
{
|
|
if (!$order_id) {
|
|
return false;
|
|
}
|
|
|
|
return $this->where('order_id', $order_id)->findAll();
|
|
}
|
|
|
|
public function getAllSoldProductToday($startDate = null, $endDate = null, $storeId = null, $userId = null) {
|
|
$builder = $this->select('
|
|
COUNT(orders_item.id) as total_product_sold,
|
|
(SELECT SUM(products.qty) FROM products) as total_unsold_product
|
|
')
|
|
->join('orders', 'orders_item.order_id = orders.id');
|
|
|
|
if (!empty($startDate) || !empty($endDate) || !empty($storeId) || !empty($userId)) {
|
|
if (!empty($startDate)) {
|
|
$builder->where('DATE(orders.date_time) >=', $startDate);
|
|
}
|
|
if (!empty($endDate)) {
|
|
$builder->where('DATE(orders.date_time) <=', $endDate);
|
|
}
|
|
} else {
|
|
$builder->where('DATE(orders.date_time)', date('Y-m-d'));
|
|
}
|
|
|
|
if (!empty($storeId)) {
|
|
$builder->where('orders.store_id', $storeId);
|
|
}
|
|
if (!empty($userId)) {
|
|
$builder->where('orders.user_id', $userId);
|
|
}
|
|
|
|
return $builder->get()->getRow();
|
|
}
|
|
|
|
public function getSumOrdersItemData($order_id = null)
|
|
{
|
|
if (!$order_id) {
|
|
return 0;
|
|
}
|
|
|
|
return $this->where('order_id', $order_id)->countAllResults();
|
|
}
|
|
|
|
public function updateOrderItem(int $id, array $data)
|
|
{
|
|
return $this->where('order_id', $id)
|
|
->set($data)
|
|
->update();
|
|
}
|
|
|
|
public function getProductIds(array $orderIds): array
|
|
{
|
|
if (empty($orderIds)) {
|
|
return [];
|
|
}
|
|
|
|
$items = $this->select('product_id')
|
|
->whereIn('order_id', $orderIds)
|
|
->findAll();
|
|
|
|
return array_column($items, 'product_id');
|
|
}
|
|
} |