Skip to content
This repository was archived by the owner on Jul 20, 2026. It is now read-only.

Commit e593756

Browse files
Merge pull request #77 from TheRefraction/hotfix-homepage
Hotfix homepage
2 parents 38e1089 + f4dc7fd commit e593756

12 files changed

Lines changed: 428 additions & 37 deletions

File tree

src/app/controllers/HomeController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ class HomeController {
33
public function home() {
44
require_once __DIR__ . '/../views/home.php';
55
}
6+
67
public function gdpr() {
78
require_once __DIR__ . '/../views/gdpr.php';
89
}
Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,55 @@
11
<?php
22

3-
class InvoiceController
4-
{
5-
private $dbConnection;
3+
require_once __DIR__ . '/../models/Invoice.php';
4+
5+
class InvoiceController {
6+
private $invoiceModel;
67

78
public function __construct(PDO $dbConnection) {
8-
$this->dbConnection = $dbConnection;
9+
$this->invoiceModel = new Invoice($dbConnection);
910
}
11+
1012
public function invoices() {
11-
if (!isset($_SESSION['user_id'])) {
13+
$accountId = $_SESSION['user_id'] ?? null;
14+
15+
if (!isset($accountId)) {
1216
header('Location: /sign-in');
1317
exit;
1418
}
15-
require_once __DIR__ . '/../models/Invoice.php';
16-
$invoiceModel = new Invoice($this->dbConnection);
17-
$accountId = $_SESSION['user_id'];
18-
$invoices = $invoiceModel->getInvoicesByAccountId($accountId);
19+
20+
$invoices = $this->invoiceModel->getInvoicesByAccountId($accountId);
1921
$title = 'My Invoices';
2022
require_once __DIR__ . '/../views/invoices.php';
2123
}
24+
25+
public function invoiceData($id) {
26+
$accountId = $_SESSION['user_id'] ?? null;
27+
28+
if (!isset($accountId)) {
29+
http_response_code(401);
30+
header('Content-Type: application/json; charset=utf-8');
31+
echo json_encode(['error' => 'Unauthorized']);
32+
return;
33+
}
34+
35+
$invoiceId = (int) $id;
36+
if ($invoiceId <= 0) {
37+
http_response_code(400);
38+
header('Content-Type: application/json; charset=utf-8');
39+
echo json_encode(['error' => 'Invalid invoice id']);
40+
return;
41+
}
42+
43+
$invoice = $this->invoiceModel->getInvoiceDetailsByIdAndAccountId($invoiceId, (int) $accountId);
44+
45+
if (!$invoice) {
46+
http_response_code(404);
47+
header('Content-Type: application/json; charset=utf-8');
48+
echo json_encode(['error' => 'Invoice not found']);
49+
return;
50+
}
51+
52+
header('Content-Type: application/json; charset=utf-8');
53+
echo json_encode($invoice, JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION);
54+
}
2255
}

src/app/models/Invoice.php

Lines changed: 166 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
<?php
2+
23
require_once __DIR__ . '/BaseModel.php';
3-
class Invoice extends BaseModel
4-
{
4+
5+
/**
6+
* Invoice model for managing invoices, including retrieval of invoices by account ID.
7+
* This model also handles the association of invoice status and payment mode for better invoice management.
8+
*/
9+
class Invoice extends BaseModel {
10+
/**
11+
* Retrieves all invoices associated with a specific account ID, including their status and payment mode.
12+
*
13+
* @param int $accountId The ID of the account for which to retrieve invoices.
14+
* @return array An array of invoice objects, each containing invoice details along with status and payment mode information.
15+
*/
516
public function getInvoicesByAccountId($accountId) {
617
$query = "SELECT i.*,
718
s.name AS status_name,
@@ -19,4 +30,157 @@ public function getInvoicesByAccountId($accountId) {
1930

2031
return $stmt->fetchAll(PDO::FETCH_OBJ);
2132
}
33+
34+
35+
public function createInvoice($accountId, $cart, $statusId, $paymentId, $addressId) {
36+
$query = "INSERT INTO invoice (total, account_id, payment_id, status_id, billing_address_id)
37+
VALUES (:total, :accountId, :paymentId, :statusId, :addressId)";
38+
39+
$stmt = $this->conn->prepare($query);
40+
41+
$stmt->bindValue(':accountId', $accountId, PDO::PARAM_INT);
42+
$stmt->bindValue(':total', 0.0);
43+
$stmt->bindValue(':statusId', $statusId, PDO::PARAM_INT);
44+
$stmt->bindValue(':paymentId', $paymentId, PDO::PARAM_INT);
45+
$stmt->bindValue(':addressId', $addressId, PDO::PARAM_INT);
46+
47+
$stmt->execute();
48+
49+
$invoiceId = $this->conn->lastInsertId();
50+
$total = 0.0;
51+
52+
// Insert invoice lines for each product in the cart
53+
$products = $cart['products'] ?? [];
54+
foreach ($products as $productId => $product) {
55+
$query = "INSERT INTO invoice_line (unit_price, quantity, invoice_id, product_id, menu_id)
56+
VALUES (:unitPrice, :quantity, :invoiceId, :productId, NULL)";
57+
58+
$productPrice = $product['price'];
59+
$productQuantity = $product['quantity'];
60+
$productOptions = $product['options'] ?? [];
61+
62+
$stmt = $this->conn->prepare($query);
63+
64+
$stmt->bindValue(':unitPrice', $productPrice);
65+
$stmt->bindValue(':invoiceId', $invoiceId, PDO::PARAM_INT);
66+
$stmt->bindValue(':productId', $productId, PDO::PARAM_INT);
67+
$stmt->bindValue(':quantity', $productQuantity, PDO::PARAM_INT);
68+
69+
$stmt->execute();
70+
71+
$invoiceLineId = $this->conn->lastInsertId();
72+
73+
$optionsTotal = 0.0;
74+
75+
// Insert product options for the invoice line
76+
foreach ($productOptions as $option) {
77+
$query = "INSERT INTO invoice_line_product_option (invoice_line_id, product_option_id, unit_price_delta, quantity)
78+
VALUES (:invoiceLineId, :optionId, :unitPriceDelta, :quantity)";
79+
80+
$optionId = $option['id'];
81+
$optionPriceDelta = $option['price_delta'];
82+
$optionQuantity = $option['quantity'];
83+
84+
$stmt = $this->conn->prepare($query);
85+
86+
$stmt->bindValue(':invoiceLineId', $invoiceLineId, PDO::PARAM_INT);
87+
$stmt->bindValue(':optionId', $optionId, PDO::PARAM_INT);
88+
$stmt->bindValue(':unitPriceDelta', $optionPriceDelta);
89+
$stmt->bindValue(':quantity', $optionQuantity, PDO::PARAM_INT);
90+
91+
$stmt->execute();
92+
93+
$optionsTotal += $optionPriceDelta * $optionQuantity;
94+
}
95+
96+
$total += ($productPrice + $optionsTotal) * $productQuantity;
97+
}
98+
99+
// Add menu items to the invoice
100+
$menus = $cart['menus'] ?? [];
101+
foreach ($menus as $menuId => $menu) {
102+
$query = "INSERT INTO invoice_line (unit_price, quantity, invoice_id, product_id, menu_id)
103+
VALUES (:unitPrice, :quantity, :invoiceId, NULL, :menuId)";
104+
105+
$menuPrice = $menu['price'];
106+
$menuQuantity = $menu['quantity'];
107+
$menuItems = $menu['items'] ?? [];
108+
109+
$stmt = $this->conn->prepare($query);
110+
111+
$stmt->bindValue(':unitPrice', $menuPrice);
112+
$stmt->bindValue(':invoiceId', $invoiceId, PDO::PARAM_INT);
113+
$stmt->bindValue(':menuId', $menuId, PDO::PARAM_INT);
114+
$stmt->bindValue(':quantity', $menuQuantity, PDO::PARAM_INT);
115+
116+
$stmt->execute();
117+
118+
$invoiceLineId = $this->conn->lastInsertId();
119+
120+
// Insert menu items for the invoice line
121+
foreach ($menuItems as $item) {
122+
/* price and price_delta are used for redundancy
123+
$menuPrice should already include the price of the items,
124+
but we store it for easier retrieval when displaying the invoice*/
125+
$itemId = $item['id'];
126+
$itemPrice = $item['price'];
127+
$itemDelta = $item['price_delta'];
128+
$itemQuantity = $item['quantity'];
129+
130+
$query = "INSERT INTO invoice_line_menu_item (invoice_line_id, product_id, unit_price, unit_price_delta, quantity)
131+
VALUES (:invoiceLineId, :itemId, :unitPrice, :unitPriceDelta, :quantity)";
132+
133+
$stmt = $this->conn->prepare($query);
134+
135+
$stmt->bindValue(':invoiceLineId', $invoiceLineId, PDO::PARAM_INT);
136+
$stmt->bindValue(':itemId', $itemId, PDO::PARAM_INT);
137+
$stmt->bindValue(':unitPrice', $itemPrice);
138+
$stmt->bindValue(':unitPriceDelta', $itemDelta);
139+
$stmt->bindValue(':quantity', $itemQuantity, PDO::PARAM_INT);
140+
141+
$stmt->execute();
142+
143+
// Insert product options for the menu item
144+
$menuOptions = $item['options'] ?? [];
145+
$optionsTotal = 0.0;
146+
147+
foreach ($menuOptions as $option) {
148+
$query = "INSERT INTO invoice_line_product_option (invoice_line_id, product_option_id, unit_price_delta, quantity)
149+
VALUES (:invoiceLineId, :optionId, :unitPriceDelta, :quantity)";
150+
151+
$optionId = $option['id'];
152+
$optionPriceDelta = $option['price_delta'];
153+
$optionQuantity = $option['quantity'];
154+
155+
$stmt = $this->conn->prepare($query);
156+
157+
$stmt->bindValue(':invoiceLineId', $invoiceLineId, PDO::PARAM_INT);
158+
$stmt->bindValue(':optionId', $optionId, PDO::PARAM_INT);
159+
$stmt->bindValue(':unitPriceDelta', $optionPriceDelta);
160+
$stmt->bindValue(':quantity', $optionQuantity, PDO::PARAM_INT);
161+
162+
$stmt->execute();
163+
164+
$optionsTotal += $optionPriceDelta * $optionQuantity;
165+
}
166+
}
167+
168+
$total += ($menuPrice + $optionsTotal) * $menuQuantity;
169+
}
170+
171+
// Update the invoice total
172+
$query = "UPDATE invoice
173+
SET total = :total
174+
WHERE id = :invoiceId";
175+
176+
$stmt = $this->conn->prepare($query);
177+
178+
$stmt->bindValue(':total', $total);
179+
$stmt->bindValue(':invoiceId', $invoiceId, PDO::PARAM_INT);
180+
$stmt->execute();
181+
182+
return $invoiceId;
183+
}
184+
185+
22186
}

src/app/views/gdpr.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,4 @@
7373
</div>
7474
</main>
7575

76-
<?php include 'partials/footer.php'; ?>
76+
<?php include 'partials/footer.php'; ?>

src/app/views/home.php

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,73 @@
22

33
<main class="container py-5">
44
<div class="mb-5">
5-
<h1 class="text-pourpre fw-bold">Bienvenue à EFES KEBAB</h1>
5+
<h1 class="text-pourpre fw-bold">Bienvenue à EFFES KEBAB</h1>
66
<p class="lead">Découvrez nos plats savoureux !</p>
77
</div>
88

99
<div class="row">
10+
<!-- Section Horaires -->
1011
<div class="col-md-6 mb-4">
11-
<h3 class="border-bottom pb-2">Horaires</h3>
12-
<ul class="list-unstyled">
13-
<li><strong>Lundi - Samedi :</strong> 11:00 – 14:00 | 18:00 – 00:00</li>
14-
<li><strong>Dimanche :</strong> 17:00 – 00:00</li>
15-
</ul>
12+
<h3 class="border-bottom pb-2">Nos Horaires</h3>
13+
14+
<div class="mt-3">
15+
<p>
16+
<span class="badge rounded-pill bg-success">Lundi - Samedi</span><br>
17+
<strong class="ms-2">11:00 – 14:00 | 18:00 – 00:00</strong>
18+
</p>
19+
20+
<p>
21+
<span class="badge rounded-pill bg-success">Dimanche</span><br>
22+
<strong class="ms-2">17:00 – 00:00</strong>
23+
</p>
24+
25+
<div class="row mt-4 g-2">
26+
<div class="col-6">
27+
<div class="p-2 border rounded bg-light text-center">
28+
<span class="d-block fw-bold text-pourpre">SUR PLACE</span>
29+
<small>Ambiance chaleureuse</small>
30+
</div>
31+
</div>
32+
<div class="col-6">
33+
<div class="p-2 border rounded bg-light text-center">
34+
<span class="d-block fw-bold text-pourpre">À EMPORTER</span>
35+
<small>Prêt en 15 min</small>
36+
</div>
37+
</div>
38+
</div>
39+
</div>
1640
</div>
1741

1842
<div class="col-md-6">
1943
<h3 class="border-bottom pb-2">Photos & Infos</h3>
20-
<p>Découvrez nos nouvelles pizzas !</p>
21-
<div class="bg-light p-5 text-center border rounded">
22-
Espace Photo
44+
<div class="bg-light p-5 border rounded">
45+
<img src="/assets/images/Firefox_kebab.jpg" alt="un monsieur tres heureux avec son double kebab" width="200">
2346
</div>
2447
</div>
2548
</div>
26-
<div class="row">
27-
<h3 class="border-bottom pb-2"></h3>
28-
<p style="text-align: justify;">Une soirée réussie avec des plats turcs ? – Nos plats sont fraîchement préparés dans une ambiance accueillante. Découvrez le « Efes Resto », et laissez vous séduire par de nombreux plats succulents. Dégustez nos spécialités halal et découvrez la grande diversité de ces plats. Nous voulons vous aider à faire attention à votre santé et vous sensibiliser à l’importance d’une alimentation saine et gourmande. Profitez des rayons du soleil sur notre terrasse très belle. </p>
49+
<div class="row mt-4">
50+
<div class="col-12">
51+
<h3 class="border-bottom pb-2">À propos de Effes Kebab</h3>
52+
53+
<p class="text-justify">
54+
Envie d'une escapade gourmande aux saveurs de la Turquie ? Bienvenue chez <strong>Effes Kebab</strong>, où chaque plat est une invitation au voyage. Dans un cadre accueillant et convivial, nous vous proposons une cuisine généreuse, préparée avec passion et des ingrédients rigoureusement sélectionnés.
55+
</p>
56+
57+
<h4 class="mt-4 mb-3">Pourquoi nous rendre visite ?</h4>
58+
59+
<ul class="list-unstyled">
60+
<li class="mb-3">
61+
<strong>• Spécialités Traditionnelles :</strong> Découvrez le véritable goût du kebab et de nombreuses spécialités halal, cuisinées selon des recettes authentiques pour ravir les amateurs de gastronomie turque.
62+
</li>
63+
<li class="mb-3">
64+
<strong>• Fraîcheur & Équilibre :</strong> Nous mettons un point d'honneur à allier plaisir et bien-être. Savourez des plats équilibrés, riches en saveurs, qui prouvent qu'une alimentation gourmande peut aussi être saine.
65+
</li>
66+
<li class="mb-3">
67+
<strong>• Ambiance Unique :</strong> Que ce soit pour un repas rapide ou une soirée détendue, profitez de notre atmosphère chaleureuse. Dès l'arrivée des beaux jours, notre terrasse ensoleillée vous accueille pour un moment de détente privilégié en plein air.
68+
</li>
69+
</ul>
70+
</div>
2971
</div>
3072
</main>
3173

32-
<?php include 'partials/footer.php'; ?>
74+
<?php include 'partials/footer.php'; ?>

0 commit comments

Comments
 (0)