-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/CS2TP36/team-project
- Loading branch information
Showing
86 changed files
with
3,550 additions
and
1,587 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Laravel | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
laravel-tests: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e | ||
with: | ||
php-version: '8.3' | ||
- uses: actions/checkout@v4 | ||
- name: Copy .env | ||
run: php -r "file_exists('.env') || copy('.env.example', '.env');" | ||
- name: Install Dependencies | ||
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist | ||
- name: Generate key | ||
run: php artisan key:generate | ||
- name: Directory Permissions | ||
run: chmod -R 777 storage bootstrap/cache | ||
- name: Create Database | ||
run: | | ||
mkdir -p database | ||
touch database/database.sqlite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,5 @@ yarn-error.log | |
/.vscode | ||
/.zed | ||
/.vs | ||
**/.DS_Store | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace App\Charts; | ||
|
||
use App\Models\IndividualOrder; | ||
use App\Models\Product; | ||
use marineusde\LarapexCharts\Charts\LineChart AS OriginalLineChart; | ||
use marineusde\LarapexCharts\Options\XAxisOption; | ||
|
||
// class for creating a stock sales chart for a specified product | ||
class StockSalesChart | ||
{ | ||
public function build(Product $product): OriginalLineChart | ||
{ | ||
// an array for storing the date of the last 14 days | ||
$last14days = [now()->day]; | ||
for ($i = 1; $i < 14; $i++) { | ||
$last14days[] = now()->subDays($i)->day; | ||
} // [14,13,12,11,10,9,8,7,6,5,4,3,2,1] | ||
$last14days = array_reverse($last14days); // [1,2,3,4,5,6,7,8,9,10,11,12,13,14] | ||
// get number of sales from each of the last 14 days | ||
$salesPerDay = []; | ||
foreach ($last14days as $day) { | ||
$salesPerDay[] = IndividualOrder::all()->where('product_id', $product->id)->where('created_at', $day)->count(); | ||
} // [1,2,3,4,5,6,7,8,9,10,11,12,13,14] | ||
// now roughly calculate the stock level for each of the last 14 days | ||
$salesPerDay = array_reverse($salesPerDay); // [14,13,12,11,10,9,8,7,6,5,4,3,2,1] | ||
$stockCount = $product->stock; | ||
$stockLevel = [$stockCount]; | ||
foreach ($salesPerDay as $sales) { | ||
$stockCount += $sales; | ||
$stockLevel[] = $stockCount; | ||
} // [14,13,12,11,10,9,8,7,6,5,4,3,2,1] | ||
$stockLevel = array_reverse($stockLevel); // [1,2,3,4,5,6,7,8,9,10,11,12,13,14] | ||
|
||
// returns the built chart with the required data | ||
return (new OriginalLineChart) | ||
->setTitle('Daily Stock levels for ' . $product->name) | ||
->setSubtitle('Last 14 days') | ||
->addData('Stock level', $stockLevel) | ||
->setXAxisOption(new XAxisOption($last14days)); | ||
} | ||
} |
Binary file not shown.
89 changes: 89 additions & 0 deletions
89
app/Http/Controllers/Admin/ProductManagementController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Admin; | ||
|
||
use App\Http\Controllers\Controller; | ||
use Illuminate\Http\Request; | ||
use App\Models\Product; | ||
use App\Models\Category; | ||
use Illuminate\Support\Str; | ||
use App\Models\ProductImage; | ||
|
||
|
||
|
||
|
||
class ProductManagementController extends Controller | ||
{ | ||
public function index() | ||
{ | ||
$products = Product::paginate(10); | ||
return view('pages.admin.admin_product_page', compact('products')); | ||
} | ||
|
||
public function create() | ||
{ | ||
$categories = Category::all(); // Fetch all categories | ||
return view('pages.admin.create_product', compact('categories')); | ||
} | ||
|
||
public function store(Request $request) | ||
{ | ||
$request->validate([ | ||
'name' => 'required|string|max:255', | ||
'price' => 'required|numeric|min:0', | ||
'category_id' => 'required|exists:categories,id', | ||
'colour' => 'nullable|string', | ||
'description' => 'nullable|string', | ||
'mens' => 'required|boolean', | ||
'stock' => 'required|integer|min:0', | ||
'images.*' => 'nullable|image|mimes:jpeg,png,jpg,gif|max:2048', | ||
]); | ||
|
||
$product = Product::create($request->except('images')); | ||
|
||
if ($request->hasFile('images')) { | ||
foreach ($request->file('images') as $image) { | ||
// Generate a unique file name using UUID | ||
$imageName = Str::uuid() . '.' . $image->getClientOriginalExtension(); | ||
$image->move(public_path('images/productImage'), $imageName); | ||
|
||
// Store the image in `product_images` table | ||
ProductImage::create([ | ||
'product_id' => $product->id, | ||
'image_name' => $imageName, | ||
]); | ||
} | ||
} | ||
|
||
return redirect()->route('admin.products.index')->with('success', 'Product created successfully.'); | ||
} | ||
|
||
public function edit(Product $product) | ||
{ | ||
return view('pages.admin.edit_product', compact('product')); | ||
} | ||
|
||
|
||
|
||
public function update(Request $request, Product $product) | ||
{ | ||
$request->validate([ | ||
'name' => 'required|string|max:255', | ||
'price' => 'required|numeric|min:0', | ||
'category_id' => 'required|exists:categories,id', | ||
]); | ||
|
||
$product->update($request->all()); | ||
|
||
return redirect()->route('admin.products.index')->with('success', 'Product updated successfully.'); | ||
} | ||
|
||
public function destroy(Product $product) | ||
{ | ||
ProductImage::where('product_id', $product->id)->delete(); | ||
|
||
$product->delete(); | ||
|
||
return redirect()->route('admin.products.index')->with('success', 'Product deleted successfully.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace App\Http\Emailers; | ||
|
||
use App\Models\ContactItem; | ||
|
||
// a class for sending the confirmation email for contact form | ||
class ContactEmailer extends Emailer | ||
{ | ||
public function __construct() | ||
{ | ||
$this->name = 'support'; | ||
} | ||
// constructs and sends the confirmation email based on provided contactItem | ||
public function sendConfirmation(ContactItem $contactItem): bool | ||
{ | ||
// set all the details for the email | ||
$to = $contactItem->email; | ||
$subject = 'SportsWear - Thanks for contacting us!'; | ||
$message = 'Hello ' . $contactItem->name . ', we have received your message and will get back to you as soon as possible. Your message: ' . $contactItem->message; | ||
// send the email | ||
return $this->sendEmail($to, $subject, $message); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace App\Http\Emailers; | ||
|
||
use Mailgun\Mailgun; | ||
|
||
// a class for sending emails | ||
class Emailer | ||
{ | ||
public string $name; | ||
// name goes to the sender address {name}@something | ||
public function __construct($name) | ||
{ | ||
$this->name = $name; | ||
} | ||
public function sendEmail($to, $subject, $message): bool | ||
{ | ||
try { | ||
// connect to mailgun API (need to put api key in the .env file) | ||
$mg = Mailgun::create(env('MAILGUN_SECRET'), "https://api.eu.mailgun.net"); | ||
// send email | ||
$mg->messages()->send('mail.thesportswear.website', [ | ||
'from' => $this->name . "@mail.thesportswear.website", | ||
'to' => $to, | ||
'subject' => $subject, | ||
'text' => $message | ||
]); | ||
return true; | ||
} catch (\Exception $e) { | ||
return false; | ||
} | ||
} | ||
} |
Oops, something went wrong.