|
|
@ -341,6 +341,7 @@ class OrderController extends AdminController |
|
|
$posts = $this->request->getPost('product[]'); |
|
|
$posts = $this->request->getPost('product[]'); |
|
|
$rates = $this->request->getPost('rate_value[]'); |
|
|
$rates = $this->request->getPost('rate_value[]'); |
|
|
$amounts = $this->request->getPost('amount_value[]'); |
|
|
$amounts = $this->request->getPost('amount_value[]'); |
|
|
|
|
|
$puissances = $this->request->getPost('puissance[]'); // ✅ AJOUTER CETTE LIGNE |
|
|
$discount = (float)$this->request->getPost('discount') ?? 0; |
|
|
$discount = (float)$this->request->getPost('discount') ?? 0; |
|
|
$gross_amount = $this->calculGross($amounts); |
|
|
$gross_amount = $this->calculGross($amounts); |
|
|
|
|
|
|
|
|
@ -400,13 +401,14 @@ class OrderController extends AdminController |
|
|
'service_charge_rate' => 0, |
|
|
'service_charge_rate' => 0, |
|
|
'vat_charge_rate' => 0, |
|
|
'vat_charge_rate' => 0, |
|
|
'vat_charge' => 0, |
|
|
'vat_charge' => 0, |
|
|
'net_amount' => $net_amount, // ✅ Net amount = tranches OU montant_a_payer |
|
|
'net_amount' => $net_amount, |
|
|
'discount' => $discount, |
|
|
'discount' => $discount, |
|
|
'paid_status' => 2, // Toujours En Attente au départ |
|
|
'paid_status' => 2, |
|
|
'user_id' => $user_id, |
|
|
'user_id' => $user_id, |
|
|
'amount_value' => $amounts, |
|
|
'amount_value' => $amounts, |
|
|
'gross_amount' => $gross_amount, |
|
|
'gross_amount' => $gross_amount, |
|
|
'rate_value' => $rates, |
|
|
'rate_value' => $rates, |
|
|
|
|
|
'puissance' => $puissances, // ✅ AJOUTER CETTE LIGNE |
|
|
'store_id' => $users['store_id'], |
|
|
'store_id' => $users['store_id'], |
|
|
'tranche_1' => $tranche_1, |
|
|
'tranche_1' => $tranche_1, |
|
|
'tranche_2' => $tranche_2, |
|
|
'tranche_2' => $tranche_2, |
|
|
@ -596,19 +598,46 @@ public function markAsDelivered() |
|
|
$FourchettePrix = new \App\Models\FourchettePrix(); |
|
|
$FourchettePrix = new \App\Models\FourchettePrix(); |
|
|
$fourchette = $FourchettePrix->where('product_id', $product_id)->first(); |
|
|
$fourchette = $FourchettePrix->where('product_id', $product_id)->first(); |
|
|
|
|
|
|
|
|
|
|
|
// ✅ Extraire la puissance - Plusieurs méthodes |
|
|
|
|
|
$puissance_extracted = ''; |
|
|
|
|
|
|
|
|
|
|
|
// Méthode 1: Chercher dans le champ puissance de la BD |
|
|
|
|
|
if (!empty($product_data['puissance'])) { |
|
|
|
|
|
$puissance_extracted = $product_data['puissance']; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Méthode 2: Chercher à la fin du nom (format: |150) |
|
|
|
|
|
if (empty($puissance_extracted) && !empty($product_data['name'])) { |
|
|
|
|
|
if (preg_match('/\|(\d+)(?:cc)?$/i', $product_data['name'], $matches)) { |
|
|
|
|
|
$puissance_extracted = $matches[1]; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Méthode 3: Chercher n'importe où dans le nom (format: 150cc ou 150 CC) |
|
|
|
|
|
if (empty($puissance_extracted) && !empty($product_data['name'])) { |
|
|
|
|
|
if (preg_match('/(\d+)\s*cc/i', $product_data['name'], $matches)) { |
|
|
|
|
|
$puissance_extracted = $matches[1]; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Log pour debug (à retirer en production) |
|
|
|
|
|
log_message('info', 'Product ID: ' . $product_id . ' - Puissance: ' . $puissance_extracted); |
|
|
|
|
|
|
|
|
$response = [ |
|
|
$response = [ |
|
|
'id' => $product_data['id'], |
|
|
'id' => $product_data['id'], |
|
|
'sku' => $product_data['sku'], |
|
|
'sku' => $product_data['sku'], |
|
|
'name' => $product_data['name'], |
|
|
'name' => $product_data['name'], |
|
|
'prix_vente' => $product_data['prix_vente'], |
|
|
'prix_vente' => $product_data['prix_vente'], |
|
|
'prix_minimal' => $fourchette ? $fourchette['prix_minimal'] : 0, |
|
|
'prix_minimal' => $fourchette ? $fourchette['prix_minimal'] : 0, |
|
|
|
|
|
'puissance' => $puissance_extracted, |
|
|
|
|
|
'numero_de_moteur' => $product_data['numero_de_moteur'] ?? '', |
|
|
]; |
|
|
]; |
|
|
|
|
|
|
|
|
return $this->response->setJSON($response); |
|
|
return $this->response->setJSON($response); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $this->response->setJSON(['error' => 'Product ID missing']); |
|
|
|
|
|
} |
|
|
public function getTableProductRow() |
|
|
public function getTableProductRow() |
|
|
{ |
|
|
{ |
|
|
$Products = new Products(); |
|
|
$Products = new Products(); |
|
|
@ -617,7 +646,19 @@ public function markAsDelivered() |
|
|
$store_id = $users['store_id']; |
|
|
$store_id = $users['store_id']; |
|
|
|
|
|
|
|
|
$product_data = $Products->getProductData2($store_id); |
|
|
$product_data = $Products->getProductData2($store_id); |
|
|
die(var_dump($product_data)); |
|
|
|
|
|
|
|
|
// ✅ Nettoyer les données pour ne pas afficher la puissance dans le select |
|
|
|
|
|
foreach ($product_data as &$product) { |
|
|
|
|
|
// Extraire la puissance si elle est dans le nom |
|
|
|
|
|
if (!empty($product['name']) && preg_match('/\|(\d+)(?:cc)?$/i', $product['name'], $matches)) { |
|
|
|
|
|
// Stocker la puissance séparément |
|
|
|
|
|
if (empty($product['puissance'])) { |
|
|
|
|
|
$product['puissance'] = $matches[1]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return $this->response->setJSON($product_data); |
|
|
return $this->response->setJSON($product_data); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -628,7 +669,6 @@ public function markAsDelivered() |
|
|
$data['page_title'] = $this->pageTitle; |
|
|
$data['page_title'] = $this->pageTitle; |
|
|
$validation = \Config\Services::validation(); |
|
|
$validation = \Config\Services::validation(); |
|
|
|
|
|
|
|
|
// ✅ NOUVELLE VÉRIFICATION : Bloquer UNIQUEMENT si statut = Validé (1) ou Validé et Livré (3) |
|
|
|
|
|
$Orders = new Orders(); |
|
|
$Orders = new Orders(); |
|
|
$current_order = $Orders->getOrdersData($id); |
|
|
$current_order = $Orders->getOrdersData($id); |
|
|
|
|
|
|
|
|
@ -637,14 +677,11 @@ public function markAsDelivered() |
|
|
return redirect()->to('orders/'); |
|
|
return redirect()->to('orders/'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// ✅ Bloquer UNIQUEMENT les statuts 1 (Validé) et 3 (Validé et Livré) |
|
|
|
|
|
// Le statut 0 (Refusé) et 2 (En Attente) restent modifiables |
|
|
|
|
|
if (in_array($current_order['paid_status'], [1, 3])) { |
|
|
if (in_array($current_order['paid_status'], [1, 3])) { |
|
|
session()->setFlashData('errors', 'Cette commande ne peut plus être modifiée car elle est déjà validée ou livrée.'); |
|
|
session()->setFlashData('errors', 'Cette commande ne peut plus être modifiée car elle est déjà validée ou livrée.'); |
|
|
return redirect()->to('orders/'); |
|
|
return redirect()->to('orders/'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Règles de validation |
|
|
|
|
|
$validation->setRules([ |
|
|
$validation->setRules([ |
|
|
'product' => 'required' |
|
|
'product' => 'required' |
|
|
]); |
|
|
]); |
|
|
@ -663,7 +700,6 @@ public function markAsDelivered() |
|
|
|
|
|
|
|
|
if ($this->request->getMethod() === 'post' && $validation->run($validationData)) { |
|
|
if ($this->request->getMethod() === 'post' && $validation->run($validationData)) { |
|
|
|
|
|
|
|
|
// ✅ DOUBLE VÉRIFICATION avant l'update |
|
|
|
|
|
$current_order_check = $Orders->getOrdersData($id); |
|
|
$current_order_check = $Orders->getOrdersData($id); |
|
|
if (in_array($current_order_check['paid_status'], [1, 3])) { |
|
|
if (in_array($current_order_check['paid_status'], [1, 3])) { |
|
|
session()->setFlashData('errors', 'Cette commande ne peut plus être modifiée car elle est déjà validée ou livrée.'); |
|
|
session()->setFlashData('errors', 'Cette commande ne peut plus être modifiée car elle est déjà validée ou livrée.'); |
|
|
@ -672,14 +708,12 @@ public function markAsDelivered() |
|
|
|
|
|
|
|
|
$old_paid_status = $current_order['paid_status']; |
|
|
$old_paid_status = $current_order['paid_status']; |
|
|
|
|
|
|
|
|
// ✅ Statut payé pour COMMERCIALE reste toujours "En attente" |
|
|
|
|
|
if ($role === 'COMMERCIALE') { |
|
|
if ($role === 'COMMERCIALE') { |
|
|
$paid_status = 2; |
|
|
$paid_status = 2; |
|
|
} else { |
|
|
} else { |
|
|
$paid_status = $this->request->getPost('paid_status'); |
|
|
$paid_status = $this->request->getPost('paid_status'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Gestion remise |
|
|
|
|
|
$discount = $this->request->getPost('discount'); |
|
|
$discount = $this->request->getPost('discount'); |
|
|
$original_discount = $this->request->getPost('original_discount'); |
|
|
$original_discount = $this->request->getPost('original_discount'); |
|
|
if ($discount === '' || $discount === null) { |
|
|
if ($discount === '' || $discount === null) { |
|
|
@ -703,6 +737,7 @@ public function markAsDelivered() |
|
|
'product_sold' => true, |
|
|
'product_sold' => true, |
|
|
'rate_value' => $this->request->getPost('rate_value'), |
|
|
'rate_value' => $this->request->getPost('rate_value'), |
|
|
'amount_value' => $this->request->getPost('amount_value'), |
|
|
'amount_value' => $this->request->getPost('amount_value'), |
|
|
|
|
|
'puissance' => $this->request->getPost('puissance'), // ✅ AJOUT PUISSANCE |
|
|
'tranche_1' => $role !== 'COMMERCIALE' ? $this->request->getPost('tranche_1') : null, |
|
|
'tranche_1' => $role !== 'COMMERCIALE' ? $this->request->getPost('tranche_1') : null, |
|
|
'tranche_2' => $role !== 'COMMERCIALE' ? $this->request->getPost('tranche_2') : null, |
|
|
'tranche_2' => $role !== 'COMMERCIALE' ? $this->request->getPost('tranche_2') : null, |
|
|
'order_payment_mode' => $role !== 'COMMERCIALE' ? $this->request->getPost('order_payment_mode_1') : null, |
|
|
'order_payment_mode' => $role !== 'COMMERCIALE' ? $this->request->getPost('order_payment_mode_1') : null, |
|
|
@ -715,7 +750,6 @@ public function markAsDelivered() |
|
|
|
|
|
|
|
|
$Notification = new NotificationController(); |
|
|
$Notification = new NotificationController(); |
|
|
|
|
|
|
|
|
// Notification pour la sécurité si commande validée |
|
|
|
|
|
if ($old_paid_status == 2 && $paid_status == 1) { |
|
|
if ($old_paid_status == 2 && $paid_status == 1) { |
|
|
$customer_name = $this->request->getPost('customer_name'); |
|
|
$customer_name = $this->request->getPost('customer_name'); |
|
|
$bill_no = $current_order['bill_no']; |
|
|
$bill_no = $current_order['bill_no']; |
|
|
@ -728,7 +762,6 @@ public function markAsDelivered() |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Gestion demande de remise |
|
|
|
|
|
if ((float)$discount > 0) { |
|
|
if ((float)$discount > 0) { |
|
|
$productData = new Products(); |
|
|
$productData = new Products(); |
|
|
$product_data_results = []; |
|
|
$product_data_results = []; |
|
|
@ -775,7 +808,6 @@ public function markAsDelivered() |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Si GET ou validation échoue |
|
|
|
|
|
$company = $Company->getCompanyData(1); |
|
|
$company = $Company->getCompanyData(1); |
|
|
$data['company_data'] = $company; |
|
|
$data['company_data'] = $company; |
|
|
$data['is_vat_enabled'] = ($company['vat_charge_value'] > 0); |
|
|
$data['is_vat_enabled'] = ($company['vat_charge_value'] > 0); |
|
|
@ -783,10 +815,8 @@ public function markAsDelivered() |
|
|
|
|
|
|
|
|
$orders_data = $Orders->getOrdersData($id); |
|
|
$orders_data = $Orders->getOrdersData($id); |
|
|
|
|
|
|
|
|
// ✅ Ajouter un flag pour désactiver le formulaire UNIQUEMENT pour les statuts 1 et 3 |
|
|
|
|
|
$data['is_editable'] = !in_array($orders_data['paid_status'], [1, 3]); |
|
|
$data['is_editable'] = !in_array($orders_data['paid_status'], [1, 3]); |
|
|
|
|
|
|
|
|
// Montant tranches |
|
|
|
|
|
$orders_data['montant_tranches'] = (!empty($orders_data['discount']) && $orders_data['discount'] > 0) |
|
|
$orders_data['montant_tranches'] = (!empty($orders_data['discount']) && $orders_data['discount'] > 0) |
|
|
? $orders_data['discount'] |
|
|
? $orders_data['discount'] |
|
|
: $orders_data['gross_amount']; |
|
|
: $orders_data['gross_amount']; |
|
|
@ -805,7 +835,6 @@ public function markAsDelivered() |
|
|
return $this->render_template('orders/edit', $data); |
|
|
return $this->render_template('orders/edit', $data); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function lookOrder(int $id) |
|
|
public function lookOrder(int $id) |
|
|
{ |
|
|
{ |
|
|
$this->verifyRole('viewOrder'); |
|
|
$this->verifyRole('viewOrder'); |
|
|
@ -1027,10 +1056,14 @@ public function markAsDelivered() |
|
|
|
|
|
|
|
|
foreach ($orders_items as $item) { |
|
|
foreach ($orders_items as $item) { |
|
|
$product_data = $Products->getProductData($item['product_id']); |
|
|
$product_data = $Products->getProductData($item['product_id']); |
|
|
|
|
|
|
|
|
|
|
|
// ✅ PRIORITÉ À LA PUISSANCE DE LA COMMANDE |
|
|
|
|
|
$puissance_affichee = !empty($item['puissance']) ? $item['puissance'] : ($product_data['puissance'] ?? ''); |
|
|
|
|
|
|
|
|
$html .= '<tr> |
|
|
$html .= '<tr> |
|
|
<td>' . esc($product_data['sku']) . '</td> |
|
|
<td>' . esc($product_data['sku']) . '</td> |
|
|
<td>' . esc($product_data['numero_de_moteur']) . '</td> |
|
|
<td>' . esc($product_data['numero_de_moteur']) . '</td> |
|
|
<td><input type="text" name="customField" placeholder="Remplir ici" style="border: none; outline: none; width: 100%;" value="' . esc($product_data['puissance']) . '"></td> |
|
|
<td><input type="text" value="' . esc($puissance_affichee) . '"></td> ✅ |
|
|
<td style="text-align:right;">' . number_format((float) $item['amount'], 2, '.', ' ') . '</td> |
|
|
<td style="text-align:right;">' . number_format((float) $item['amount'], 2, '.', ' ') . '</td> |
|
|
</tr>'; |
|
|
</tr>'; |
|
|
} |
|
|
} |
|
|
@ -1124,6 +1157,9 @@ public function markAsDelivered() |
|
|
foreach ($orders_items as $index => $item) { |
|
|
foreach ($orders_items as $index => $item) { |
|
|
$product_data = $Products->getProductData($item['product_id']); |
|
|
$product_data = $Products->getProductData($item['product_id']); |
|
|
|
|
|
|
|
|
|
|
|
// ✅ PRIORITÉ À LA PUISSANCE DE LA COMMANDE (si modifiée), sinon celle du produit |
|
|
|
|
|
$puissance_affichee = !empty($item['puissance']) ? $item['puissance'] : ($product_data['puissance'] ?? ''); |
|
|
|
|
|
|
|
|
echo '<!DOCTYPE html> |
|
|
echo '<!DOCTYPE html> |
|
|
<html lang="fr"> |
|
|
<html lang="fr"> |
|
|
<head> |
|
|
<head> |
|
|
@ -1224,7 +1260,7 @@ public function markAsDelivered() |
|
|
<tr> |
|
|
<tr> |
|
|
<td>' . esc($product_data['sku']) . '</td> |
|
|
<td>' . esc($product_data['sku']) . '</td> |
|
|
<td>' . esc($product_data['numero_de_moteur']) . '</td> |
|
|
<td>' . esc($product_data['numero_de_moteur']) . '</td> |
|
|
<td><input type="text" value="' . esc($product_data['puissance']) . '" placeholder="Remplir ici"></td> |
|
|
<td><input type="text" value="' . esc($puissance_affichee) . '" placeholder="Remplir ici"></td> |
|
|
<td style="text-align:right;">' . number_format((float)$item['amount'], 2, '.', ' ') . '</td> |
|
|
<td style="text-align:right;">' . number_format((float)$item['amount'], 2, '.', ' ') . '</td> |
|
|
</tr> |
|
|
</tr> |
|
|
</tbody> |
|
|
</tbody> |
|
|
@ -1282,7 +1318,6 @@ public function markAsDelivered() |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function remove() |
|
|
public function remove() |
|
|
{ |
|
|
{ |
|
|
$this->verifyRole('deleteOrder'); |
|
|
$this->verifyRole('deleteOrder'); |
|
|
@ -1349,28 +1384,24 @@ public function markAsDelivered() |
|
|
|
|
|
|
|
|
public function print3(int $id) |
|
|
public function print3(int $id) |
|
|
{ |
|
|
{ |
|
|
// Vérification du rôle |
|
|
|
|
|
$this->verifyRole('viewOrder'); |
|
|
$this->verifyRole('viewOrder'); |
|
|
|
|
|
|
|
|
if (!$id) { |
|
|
if (!$id) { |
|
|
return $this->response->setStatusCode(400, 'ID manquant'); |
|
|
return $this->response->setStatusCode(400, 'ID manquant'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Instanciation des modèles |
|
|
|
|
|
$Orders = new Orders(); |
|
|
$Orders = new Orders(); |
|
|
$Company = new Company(); |
|
|
$Company = new Company(); |
|
|
$OrderItems = new OrderItems(); |
|
|
$OrderItems = new OrderItems(); |
|
|
$Products = new Products(); |
|
|
$Products = new Products(); |
|
|
|
|
|
|
|
|
// Récupération des données |
|
|
|
|
|
$order_data = $Orders->getOrdersData($id); |
|
|
$order_data = $Orders->getOrdersData($id); |
|
|
$items = $OrderItems->getOrdersItemData($id); |
|
|
$items = $OrderItems->getOrdersItemData($id); |
|
|
$company_info = $Company->getCompanyData(1); |
|
|
$company_info = $Company->getCompanyData(1); |
|
|
|
|
|
|
|
|
// Statut de paiement |
|
|
|
|
|
$paid_status = $order_data['paid_status'] == 1 |
|
|
$paid_status = $order_data['paid_status'] == 1 |
|
|
? "<span style='color: green; font-weight: bold;'>Payé</span>" |
|
|
? "<span style='color: green; font-weight: bold;'>Validé</span>" |
|
|
: "<span style='color: red; font-weight: bold;'>Non payé</span>"; |
|
|
: "<span style='color: red; font-weight: bold;'>Refusé</span>"; |
|
|
|
|
|
|
|
|
// STYLE COMMUN |
|
|
// STYLE COMMUN |
|
|
$style = ' |
|
|
$style = ' |
|
|
@ -1386,24 +1417,27 @@ public function print3(int $id) |
|
|
table { width:100%; border-collapse:collapse; margin-top:15px; } |
|
|
table { width:100%; border-collapse:collapse; margin-top:15px; } |
|
|
th, td { border:1px solid #ddd; padding:8px; text-align:left; } |
|
|
th, td { border:1px solid #ddd; padding:8px; text-align:left; } |
|
|
th { background:#e9ecef; } |
|
|
th { background:#e9ecef; } |
|
|
.summary { |
|
|
input { border:none; outline:none; width:100%; font-size:14px; background:transparent; } |
|
|
width: 80%; |
|
|
.summary { width: 80%; margin: 20px 0; margin-right: 0; } |
|
|
margin: 20px 0; |
|
|
|
|
|
margin-right: 0; |
|
|
|
|
|
} |
|
|
|
|
|
.summary th, .summary td { border:none; padding:4px; text-align:right; } |
|
|
.summary th, .summary td { border:none; padding:4px; text-align:right; } |
|
|
.summary th { text-align:left; } |
|
|
.summary th { text-align:left; } |
|
|
@media print { |
|
|
@media print { |
|
|
body { font-size: 14px; font-family: Arial, sans-serif, margin: 1cm; } |
|
|
body { font-size: 14px; font-family: Arial, sans-serif; margin: 1cm; } |
|
|
|
|
|
|
|
|
@page { margin: 0; } |
|
|
@page { margin: 0; } |
|
|
* { -webkit-print-color-adjust:exact; print-color-adjust:exact; } } |
|
|
* { -webkit-print-color-adjust:exact; print-color-adjust:exact; } |
|
|
|
|
|
} |
|
|
</style> |
|
|
</style> |
|
|
'; |
|
|
'; |
|
|
|
|
|
|
|
|
// --- FACTURES : Une par produit --- |
|
|
// --- FACTURES : Une par produit --- |
|
|
foreach ($items as $item) { |
|
|
foreach ($items as $item) { |
|
|
$product_data = $Products->getProductData($item['product_id']); |
|
|
$product_data = $Products->getProductData($item['product_id']); |
|
|
|
|
|
|
|
|
|
|
|
// ✅ PRIORITÉ À LA PUISSANCE DE LA COMMANDE |
|
|
|
|
|
$puissance_affichee = !empty($item['puissance']) |
|
|
|
|
|
? $item['puissance'] |
|
|
|
|
|
: (!empty($product_data['puissance']) ? $product_data['puissance'] : ''); |
|
|
|
|
|
|
|
|
$unitPrice = (float)$item['amount']; |
|
|
$unitPrice = (float)$item['amount']; |
|
|
$quantity = isset($item['qty']) ? (int)$item['qty'] : 1; |
|
|
$quantity = isset($item['qty']) ? (int)$item['qty'] : 1; |
|
|
$subtotal = $unitPrice * $quantity; |
|
|
$subtotal = $unitPrice * $quantity; |
|
|
@ -1438,34 +1472,34 @@ public function print3(int $id) |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
|
|
|
<table> |
|
|
<table> |
|
|
<thead><tr><th>Marque</th><th>Moteur</th><th>Puissance</th><th>Prix unitaire</th></tr></thead> |
|
|
<thead><tr><th>Marque</th><th>Moteur</th><th>Puissance (CC)</th><th>Prix unitaire</th></tr></thead> |
|
|
<tbody> |
|
|
<tbody> |
|
|
<tr> |
|
|
<tr> |
|
|
<td>' . esc($product_data['sku']) . '</td> |
|
|
<td>' . esc($product_data['sku']) . '</td> |
|
|
<td>' . esc($product_data['numero_de_moteur']) . '</td> |
|
|
<td>' . esc($product_data['numero_de_moteur']) . '</td> |
|
|
<td>' . esc($product_data['puissance']) . '</td> |
|
|
<td><input type="text" value="' . esc($puissance_affichee) . '" readonly></td> |
|
|
<td>' . number_format($unitPrice, 2, '.', ' ') . '</td> |
|
|
<td>' . number_format($unitPrice, 2, '.', ' ') . '</td> |
|
|
</tr> |
|
|
</tr> |
|
|
</tbody> |
|
|
</tbody> |
|
|
</table> |
|
|
</table> |
|
|
|
|
|
|
|
|
<table class="table summary"> |
|
|
<table class="table summary"> |
|
|
<tr><th>Total:</th><td></td></tr> |
|
|
<tr><th>Total HT:</th><td>' . number_format($subtotal, 2, '.', ' ') . ' Ar</td></tr> |
|
|
<tr><th>TVA (20%):</th><td></td></tr> |
|
|
<tr><th>TVA (20%):</th><td>' . number_format($vatAmount, 2, '.', ' ') . ' Ar</td></tr> |
|
|
<tr><th>Réduction:</th><td></td></tr> |
|
|
<tr><th>Réduction:</th><td>' . number_format($discount, 2, '.', ' ') . ' Ar</td></tr> |
|
|
<tr><th>Total à payer:</th><td><strong></strong></td></tr> |
|
|
<tr><th>Total à payer:</th><td><strong>' . number_format($totalNet, 2, '.', ' ') . ' Ar</strong></td></tr> |
|
|
<tr><th>Statut:</th><td></td></tr>'; |
|
|
<tr><th>Statut:</th><td>' . $paid_status . '</td></tr>'; |
|
|
|
|
|
|
|
|
if (!empty($order_data['order_payment_mode'])) { |
|
|
if (!empty($order_data['order_payment_mode'])) { |
|
|
echo '<tr><th>Mode de paiement:</th><td></td></tr>'; |
|
|
echo '<tr><th>Mode de paiement:</th><td>' . esc($order_data['order_payment_mode']) . '</td></tr>'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (!empty($order_data['tranche_1'])) { |
|
|
if (!empty($order_data['tranche_1'])) { |
|
|
echo '<tr><th>Tranche 1:</th><td></td></tr>'; |
|
|
echo '<tr><th>Tranche 1:</th><td>' . number_format((float)$order_data['tranche_1'], 2, '.', ' ') . ' Ar</td></tr>'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (!empty($order_data['tranche_2'])) { |
|
|
if (!empty($order_data['tranche_2'])) { |
|
|
echo '<tr><th>Tranche 2:</th><td></td></tr>'; |
|
|
echo '<tr><th>Tranche 2:</th><td>' . number_format((float)$order_data['tranche_2'], 2, '.', ' ') . ' Ar</td></tr>'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
echo '</table> |
|
|
echo '</table> |
|
|
@ -1513,7 +1547,7 @@ public function print3(int $id) |
|
|
<tr> |
|
|
<tr> |
|
|
<th>Marque</th> |
|
|
<th>Marque</th> |
|
|
<th>Moteur</th> |
|
|
<th>Moteur</th> |
|
|
<th>Puissance</th> |
|
|
<th>Puissance (CC)</th> |
|
|
<th>Prix</th> |
|
|
<th>Prix</th> |
|
|
</tr> |
|
|
</tr> |
|
|
</thead> |
|
|
</thead> |
|
|
@ -1522,11 +1556,18 @@ public function print3(int $id) |
|
|
$total_ht = 0; |
|
|
$total_ht = 0; |
|
|
foreach ($items as $item) { |
|
|
foreach ($items as $item) { |
|
|
$product_data = $Products->getProductData($item['product_id']); |
|
|
$product_data = $Products->getProductData($item['product_id']); |
|
|
|
|
|
|
|
|
|
|
|
// ✅ PRIORITÉ À LA PUISSANCE DE LA COMMANDE |
|
|
|
|
|
$puissance_affichee = !empty($item['puissance']) |
|
|
|
|
|
? $item['puissance'] |
|
|
|
|
|
: (!empty($product_data['puissance']) ? $product_data['puissance'] : ''); |
|
|
|
|
|
|
|
|
$total_ht += (float)$item['amount']; |
|
|
$total_ht += (float)$item['amount']; |
|
|
|
|
|
|
|
|
echo '<tr> |
|
|
echo '<tr> |
|
|
<td>' . esc($product_data['sku']) . '</td> |
|
|
<td>' . esc($product_data['sku']) . '</td> |
|
|
<td>' . esc($product_data['numero_de_moteur']) . '</td> |
|
|
<td>' . esc($product_data['numero_de_moteur']) . '</td> |
|
|
<td><input type="text" value="' . esc($product_data['puissance']) . '" style="border:none;width:100%;outline:none;"></td> |
|
|
<td><input type="text" value="' . esc($puissance_affichee) . '" style="border:none;width:100%;outline:none;"></td> |
|
|
<td style="text-align:right;">' . number_format((float)$item['amount'], 2, '.', ' ') . '</td> |
|
|
<td style="text-align:right;">' . number_format((float)$item['amount'], 2, '.', ' ') . '</td> |
|
|
</tr>'; |
|
|
</tr>'; |
|
|
} |
|
|
} |
|
|
@ -1534,30 +1575,29 @@ public function print3(int $id) |
|
|
$tva = $total_ht * 0.2; |
|
|
$tva = $total_ht * 0.2; |
|
|
$total_ttc = $total_ht + $tva - $order_data['discount']; |
|
|
$total_ttc = $total_ht + $tva - $order_data['discount']; |
|
|
|
|
|
|
|
|
echo '</tbody>'; |
|
|
echo '</tbody> |
|
|
echo ' </table> |
|
|
</table> |
|
|
|
|
|
|
|
|
<table class="table summary"> |
|
|
<table class="table summary"> |
|
|
<tr><th>Total:</th><td>' . number_format($total_ht, 2, '.', ' ') . '</td></tr> |
|
|
<tr><th>Total HT:</th><td>' . number_format($total_ht, 2, '.', ' ') . ' Ar</td></tr> |
|
|
<tr><th>TVA:</th><td>' . number_format($tva, 2, '.', ' ') . '</td></tr> |
|
|
<tr><th>TVA (20%):</th><td>' . number_format($tva, 2, '.', ' ') . ' Ar</td></tr> |
|
|
<tr><th>Réduction:</th><td>' . number_format($order_data['discount'], 2, '.', ' ') . '</td></tr> |
|
|
<tr><th>Réduction:</th><td>' . number_format($order_data['discount'], 2, '.', ' ') . ' Ar</td></tr> |
|
|
<tr><th>Total à payer:</th><td><strong>' . number_format($total_ttc, 2, '.', ' ') . '</strong></td></tr> |
|
|
<tr><th>Total à payer:</th><td><strong>' . number_format($total_ttc, 2, '.', ' ') . ' Ar</strong></td></tr> |
|
|
</table>'; |
|
|
</table> |
|
|
|
|
|
|
|
|
echo '<div style="display: flex; justify-content: space-around; margin-top: 5%;"> |
|
|
<div style="display: flex; justify-content: space-around; margin-top: 5%;"> |
|
|
<div><p style="font-weight:bold;">L\'acheteur</p></div> |
|
|
<div><p style="font-weight:bold;">L\'acheteur</p></div> |
|
|
<div><p style="font-weight:bold;">Le vendeur</p></div> |
|
|
<div><p style="font-weight:bold;">Le vendeur</p></div> |
|
|
</div>'; |
|
|
</div> |
|
|
|
|
|
|
|
|
echo'<div class="invoice-footer"> |
|
|
<div class="invoice-footer"> |
|
|
Merci pour votre commande !<br> |
|
|
Merci pour votre commande !<br> |
|
|
<strong style="color:white;">Original</strong> |
|
|
<strong style="color:white;">Original</strong> |
|
|
</div>'; |
|
|
</div> |
|
|
echo '</div>'; |
|
|
</div> |
|
|
echo '</body>'; |
|
|
</body> |
|
|
echo'</html>'; |
|
|
</html>'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// PRINT5 - Facture détaillée avec conditions générales |
|
|
// PRINT5 - Facture détaillée avec conditions générales |
|
|
// ==================================== |
|
|
// ==================================== |
|
|
public function print5(int $id) |
|
|
public function print5(int $id) |
|
|
@ -1664,9 +1704,6 @@ public function print5(int $id) |
|
|
|
|
|
|
|
|
$prixAffiche = ($discount > 0) ? $discount : $details['prix']; |
|
|
$prixAffiche = ($discount > 0) ? $discount : $details['prix']; |
|
|
|
|
|
|
|
|
$html .= ' |
|
|
|
|
|
<tr> |
|
|
|
|
|
<td>'.esc($details['product_name']); |
|
|
|
|
|
|
|
|
|
|
|
// Afficher le commentaire s'il existe |
|
|
// Afficher le commentaire s'il existe |
|
|
if (!empty($details['commentaire'])) { |
|
|
if (!empty($details['commentaire'])) { |
|
|
@ -1703,13 +1740,14 @@ public function print5(int $id) |
|
|
|
|
|
|
|
|
$prixAffiche = ($discount > 0) ? $discount : $details['prix']; |
|
|
$prixAffiche = ($discount > 0) ? $discount : $details['prix']; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$html .= ' |
|
|
$html .= ' |
|
|
<tr> |
|
|
<tr> |
|
|
<td>'.esc($details['marque']).'</td> |
|
|
<td>'.esc($details['marque']).'</td> |
|
|
<td>'.esc($details['product_name']).'</td> |
|
|
<td>'.esc($details['product_name']).'</td> |
|
|
<td>'.esc($details['numero_moteur']).'</td> |
|
|
<td>'.esc($details['numero_moteur']).'</td> |
|
|
<td>'.esc($details['numero_chassis']).'</td> |
|
|
<td>'.esc($details['numero_chassis']).'</td> |
|
|
<td>'.esc($details['puissance']).'</td> |
|
|
<td>'.esc($details['puissance']).'</td> <!-- ✅ ICI --> |
|
|
<td class="right">'.number_format($prixAffiche, 0, '', ' ').'</td> |
|
|
<td class="right">'.number_format($prixAffiche, 0, '', ' ').'</td> |
|
|
</tr>'; |
|
|
</tr>'; |
|
|
} |
|
|
} |
|
|
@ -1824,7 +1862,7 @@ private function numberToWords(int $num): string |
|
|
// millions et plus |
|
|
// millions et plus |
|
|
$m = intdiv($n, 1000000); |
|
|
$m = intdiv($n, 1000000); |
|
|
$rest = $n % 1000000; |
|
|
$rest = $n % 1000000; |
|
|
$millionText = $m > 1 ? $convert($m) . ' million' : 'million'; |
|
|
$millionText = $m > 1 ? $convert($m) . ' million' : 'un million'; |
|
|
// pas de 's' à million en francais |
|
|
// pas de 's' à million en francais |
|
|
return $millionText . ($rest ? ' ' . $convert($rest) : ''); |
|
|
return $millionText . ($rest ? ' ' . $convert($rest) : ''); |
|
|
}; |
|
|
}; |
|
|
@ -1833,7 +1871,6 @@ private function numberToWords(int $num): string |
|
|
$words = $convert($num); |
|
|
$words = $convert($num); |
|
|
return trim($words) . ' ariary'; |
|
|
return trim($words) . ' ariary'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* ✅ NOUVELLE MÉTHODE : Vérifier si une commande provient d'une avance "sur mer" |
|
|
* ✅ NOUVELLE MÉTHODE : Vérifier si une commande provient d'une avance "sur mer" |
|
|
*/ |
|
|
*/ |
|
|
@ -1908,7 +1945,7 @@ private function getOrderItemDetails($item) |
|
|
'marque' => $brandName, |
|
|
'marque' => $brandName, |
|
|
'numero_moteur' => $product['numero_de_moteur'] ?? '', |
|
|
'numero_moteur' => $product['numero_de_moteur'] ?? '', |
|
|
'numero_chassis' => $product['chasis'] ?? $product['sku'] ?? '', |
|
|
'numero_chassis' => $product['chasis'] ?? $product['sku'] ?? '', |
|
|
'puissance' => $product['puissance'] ?? '', |
|
|
'puissance' => !empty($item['puissance']) ? $item['puissance'] : ($product['puissance'] ?? ''), // ✅ Priorité à la commande |
|
|
'commentaire' => '', |
|
|
'commentaire' => '', |
|
|
'prix' => (float)$item['amount'] |
|
|
'prix' => (float)$item['amount'] |
|
|
]; |
|
|
]; |
|
|
|