Skip to content

Commit 5c842be

Browse files
committed
Adds Income and Expense modal
1 parent f7495e7 commit 5c842be

10 files changed

+286
-27
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@ MoneyMint is a simple app for tracking expenses, budgeting, and getting an overv
66
<img alt="MoneyMint" src="https://github.com/phpfour/moneymint/assets/171715/e91cb8ef-507a-4b34-9e7e-ad42fa25fad4" style="max-width: 100%;">
77
</p>
88

9+
## Installation
10+
- Clone the repository
11+
- cd moneymint
12+
- composer install or composer update
13+
- cp .env.example .env
14+
- Set up .env file
15+
- php artisan key:generate
16+
- php artisan migrate:fresh --seed
17+
- php artisan serve
18+
19+
In new terminal
20+
- npm i
21+
- npm run dev
22+
923
## Contributing
1024

1125
Thank you for considering contributing to the project! Please fork this project and open a pull request against the `main` branch.

app/Http/Controllers/DashboardController.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22

33
namespace App\Http\Controllers;
44

5+
use App\Models\Transaction;
6+
use Illuminate\View\View;
7+
58
class DashboardController extends Controller
69
{
7-
public function index()
10+
public function index(): View
811
{
9-
return view('app');
12+
$transactionList = Transaction::all(); // Fetch all income records from the database
13+
14+
return view('app', compact('transactionList'));
1015
}
1116
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use App\Models\Transaction;
6+
use Illuminate\Http\Request;
7+
8+
class TransactionController extends Controller
9+
{
10+
11+
public function store(Request $request)
12+
{
13+
Transaction::create($request->all());
14+
return redirect('/');
15+
}
16+
}

app/Models/Transaction.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
6+
use Illuminate\Database\Eloquent\Factories\HasFactory;
7+
use Illuminate\Database\Eloquent\Model;
8+
use Illuminate\Database\Eloquent\SoftDeletes;
9+
10+
class Transaction extends Model
11+
{
12+
use HasFactory,SoftDeletes;
13+
14+
protected $guarded =[];
15+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::create('transactions', function (Blueprint $table) {
15+
$table->id();
16+
$table->string('title');
17+
$table->string('description');
18+
$table->double('credit', 10, 2);
19+
$table->double('debit', 10, 2);
20+
$table->string('status');
21+
$table->timestamps();
22+
$table->softDeletes();
23+
});
24+
}
25+
26+
/**
27+
* Reverse the migrations.
28+
*/
29+
public function down(): void
30+
{
31+
Schema::dropIfExists('transaction');
32+
}
33+
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('transactions', function (Blueprint $table) {
15+
$table->double('credit', 10, 2)->default(0)->nullable()->change();
16+
$table->double('debit', 10, 2)->default(0)->nullable()->change();
17+
$table->string('description')->nullable()->change();
18+
});
19+
}
20+
21+
/**
22+
* Reverse the migrations.
23+
*/
24+
public function down(): void
25+
{
26+
Schema::table('transactions', function (Blueprint $table) {
27+
$table->double('credit', 10, 2)->change();
28+
$table->double('debit', 10, 2)->change();
29+
$table->string('description')->change();
30+
});
31+
}
32+
};

database/seeders/DatabaseSeeder.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,9 @@ public function run(): void
1818
// 'name' => 'Test User',
1919
// 'email' => '[email protected]',
2020
// ]);
21+
22+
$this->call([
23+
TransactionSeeder::class,
24+
]);
2125
}
2226
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Database\Seeders;
4+
5+
use App\Models\Transaction;
6+
use Faker\Factory;
7+
use Illuminate\Database\Seeder;
8+
9+
class TransactionSeeder extends Seeder
10+
{
11+
/**
12+
* Run the database seeds.
13+
*
14+
* @return void
15+
*/
16+
public function run()
17+
{
18+
for ($i=0; $i <2; $i++) {
19+
Transaction::create([
20+
'title' => Factory::create()->name(),
21+
'description' => Factory::create()->text(),
22+
'credit' => rand(100,10000),
23+
'status' => Factory::create()->randomElement(['Success', 'Failed', 'Pending'])
24+
]);
25+
}
26+
for ($i=0; $i <3; $i++) {
27+
Transaction::create([
28+
'title' => Factory::create()->name(),
29+
'description' => Factory::create()->text(),
30+
'debit' => rand(100,10000),
31+
'status' => Factory::create()->randomElement(['Success', 'Failed', 'Pending'])
32+
]);
33+
}
34+
}
35+
}

resources/views/app.blade.php

Lines changed: 124 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
</div>
5252
</div>
5353
<div class="mt-6 flex space-x-3 md:ml-4 md:mt-0">
54-
<button type="button" class="inline-flex items-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50">Add Income</button>
55-
<button type="button" class="inline-flex items-center rounded-md bg-cyan-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-cyan-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-cyan-600">Add Expense</button>
54+
<button type="button" class="inline-flex items-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50" onclick="openIncomeModal()">Add Income</button>
55+
<button type="button" class="inline-flex items-center rounded-md bg-cyan-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-cyan-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-cyan-600" onclick="openExpenseModal()">Add Expense</button>
5656
</div>
5757
</div>
5858
</div>
@@ -143,29 +143,43 @@
143143
</tr>
144144
</thead>
145145
<tbody class="divide-y divide-gray-200 bg-white">
146-
<tr class="bg-white">
147-
<td class="w-full max-w-0 whitespace-nowrap px-6 py-4 text-sm text-gray-900">
148-
<div class="flex">
149-
<a href="#" class="group inline-flex space-x-2 truncate text-sm">
150-
<svg class="h-5 w-5 flex-shrink-0 text-gray-400 group-hover:text-gray-500" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
151-
<path fill-rule="evenodd" d="M1 4a1 1 0 011-1h16a1 1 0 011 1v8a1 1 0 01-1 1H2a1 1 0 01-1-1V4zm12 4a3 3 0 11-6 0 3 3 0 016 0zM4 9a1 1 0 100-2 1 1 0 000 2zm13-1a1 1 0 11-2 0 1 1 0 012 0zM1.75 14.5a.75.75 0 000 1.5c4.417 0 8.693.603 12.749 1.73 1.111.309 2.251-.512 2.251-1.696v-.784a.75.75 0 00-1.5 0v.784a.272.272 0 01-.35.25A49.043 49.043 0 001.75 14.5z" clip-rule="evenodd" />
152-
</svg>
153-
<p class="truncate text-gray-500 group-hover:text-gray-900">Payment to Molly Sanders</p>
154-
</a>
155-
</div>
156-
</td>
157-
<td class="whitespace-nowrap px-6 py-4 text-right text-sm text-gray-500">
158-
<span class="font-medium text-gray-900">$20,000</span>
159-
USD
160-
</td>
161-
<td class="hidden whitespace-nowrap px-6 py-4 text-sm text-gray-500 md:block">
162-
<span class="inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium bg-green-100 text-green-800 capitalize">success</span>
163-
</td>
164-
<td class="whitespace-nowrap px-6 py-4 text-right text-sm text-gray-500">
165-
<time datetime="2020-07-11">July 11, 2020</time>
166-
</td>
167-
</tr>
146+
@foreach($transactionList as $transaction)
147+
<tr class="bg-white">
148+
<td class="w-full max-w-0 whitespace-nowrap px-6 py-4 text-sm text-gray-900">
149+
<div class="flex">
150+
<a href="#" class="group inline-flex space-x-2 truncate text-sm">
151+
<svg class="h-5 w-5 flex-shrink-0 text-gray-400 group-hover:text-gray-500" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
152+
<path fill-rule="evenodd" d="M1 4a1 1 0 011-1h16a1 1 0 011 1v8a1 1 0 01-1 1H2a1 1 0 01-1-1V4zm12 4a3 3 0 11-6 0 3 3 0 016 0zM4 9a1 1 0 100-2 1 1 0 000 2zm13-1a1 1 0 11-2 0 1 1 0 012 0zM1.75 14.5a.75.75 0 000 1.5c4.417 0 8.693.603 12.749 1.73 1.111.309 2.251-.512 2.251-1.696v-.784a.75.75 0 00-1.5 0v.784a.272.272 0 01-.35.25A49.043 49.043 0 001.75 14.5z" clip-rule="evenodd" />
153+
</svg>
154+
<p class="truncate text-gray-500 group-hover:text-gray-900">{{ $transaction->title }}</p>
155+
</a>
156+
</div>
157+
</td>
158+
<td class="whitespace-nowrap px-6 py-4 text-right text-sm text-gray-500">
159+
<span class="font-medium text-gray-900">${{ number_format($transaction->credit > 0 ? $transaction->credit : $transaction->debit, 0, '.', ',') }}</span>
160+
USD
161+
</td>
162+
<td class="hidden whitespace-nowrap px-6 py-4 text-sm text-gray-500 md:block">
163+
<span class="inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium
164+
@if($transaction->status === 'Success')
165+
bg-green-100 text-green-800
166+
@elseif($transaction->status === 'Failed')
167+
bg-red-100 text-red-800
168+
@elseif($transaction->status === 'Pending')
169+
bg-yellow-100 text-yellow-800
170+
@else
171+
bg-gray-100 text-gray-800
172+
@endif
173+
capitalize">
174+
{{ $transaction->status }}
175+
</span>
176+
</td>
168177

178+
<td class="whitespace-nowrap px-6 py-4 text-right text-sm text-gray-500">
179+
<time datetime="2020-07-11">{{$transaction->created_at->format('F j, Y')}}</time>
180+
</td>
181+
</tr>
182+
@endforeach
169183
<!-- More transactions... -->
170184
</tbody>
171185
</table>
@@ -195,5 +209,91 @@
195209
</main>
196210
</div>
197211
</div>
212+
213+
<!-- Add Income Modal -->
214+
<div id="incomeModal" class="fixed inset-0 z-10 flex items-center justify-center bg-black bg-opacity-50 hidden">
215+
<div class="bg-white p-6 rounded-md shadow-md" style="width: 30%;">
216+
<h2 class="text-lg font-semibold mb-4">Add Income</h2>
217+
<form action="{{ route('transaction.store') }}" method="POST">
218+
@csrf
219+
<div class="mb-4">
220+
<label for="title" class="block font-semibold">Title <span class="text-red-500">*</span></label>
221+
<input type="text" name="title" id="title" required class="w-full border rounded-md px-3 py-2">
222+
</div>
223+
<div class="mb-4">
224+
<label for="description" class="block font-semibold">Description</label>
225+
<textarea name="description" id="description" class="w-full border rounded-md px-3 py-2"></textarea>
226+
</div>
227+
<div class="mb-4" style="width: 25%">
228+
<label for="credit" class="block font-semibold">Credit</label>
229+
<input type="number" name="credit" id="credit" class="w-full border rounded-md px-3 py-2">
230+
</div>
231+
<div class="mb-4" style="width: 25%">
232+
<label for="status" class="block font-semibold">Status</label>
233+
<select name="status" id="status" class="w-full border rounded-md px-3 py-2">
234+
<option value="Success">Success</option>
235+
<option value="Failed">Failed</option>
236+
<option value="Pending">Pending</option>
237+
</select>
238+
</div>
239+
<div class="flex justify-end">
240+
<button type="submit" class="px-4 py-2 bg-cyan-600 text-white font-semibold rounded-md hover:bg-cyan-500 mr-2" onclick="closeIncomeModal()">Submit</button>
241+
<button type="button" class="px-4 py-2 bg-gray-300 text-gray-900 font-semibold rounded-md hover:bg-gray-400" onclick="closeIncomeModal()">Cancel</button>
242+
</div>
243+
</form>
244+
</div>
245+
</div>
246+
247+
<!-- Add Expense Modal -->
248+
<div id="expenseModal" class="fixed inset-0 z-10 flex items-center justify-center bg-black bg-opacity-50 hidden">
249+
<div class="bg-white p-6 rounded-md shadow-md" style="width: 30%;">
250+
<h2 class="text-lg font-semibold mb-4">Add Expense</h2>
251+
<form action="{{ route('transaction.store') }}" method="POST">
252+
@csrf
253+
<div class="mb-4">
254+
<label for="title" class="block font-semibold">Title <span class="text-red-500">*</span></label>
255+
<input type="text" name="title" id="title" required class="w-full border rounded-md px-3 py-2">
256+
</div>
257+
<div class="mb-4">
258+
<label for="description" class="block font-semibold">Description</label>
259+
<textarea name="description" id="description" class="w-full border rounded-md px-3 py-2"></textarea>
260+
</div>
261+
<div class="mb-4" style="width: 25%">
262+
<label for="credit" class="block font-semibold">Debit</label>
263+
<input type="number" name="credit" id="debit" class="w-full border rounded-md px-3 py-2">
264+
</div>
265+
<div class="mb-4" style="width: 25%">
266+
<label for="status" class="block font-semibold">Status</label>
267+
<select name="status" id="status" class="w-full border rounded-md px-3 py-2">
268+
<option value="Success">Success</option>
269+
<option value="Failed">Failed</option>
270+
<option value="Pending">Pending</option>
271+
</select>
272+
</div>
273+
<div class="flex justify-end">
274+
<button type="submit" class="px-4 py-2 bg-cyan-600 text-white font-semibold rounded-md hover:bg-cyan-500 mr-2" onclick="closeExpenseModal()">Submit</button>
275+
<button type="button" class="px-4 py-2 bg-gray-300 text-gray-900 font-semibold rounded-md hover:bg-gray-400" onclick="closeExpenseModal()">Cancel</button>
276+
</div>
277+
</form>
278+
</div>
279+
</div>
280+
198281
</body>
199282
</html>
283+
<script>
284+
function openIncomeModal() {
285+
document.getElementById('incomeModal').classList.remove('hidden');
286+
}
287+
288+
function closeIncomeModal() {
289+
document.getElementById('incomeModal').classList.add('hidden');
290+
}
291+
292+
function openExpenseModal() {
293+
document.getElementById('expenseModal').classList.remove('hidden');
294+
}
295+
296+
function closeExpenseModal() {
297+
document.getElementById('expenseModal').classList.add('hidden');
298+
}
299+
</script>

routes/web.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use App\Http\Controllers\DashboardController;
4+
use App\Http\Controllers\TransactionController;
35
use Illuminate\Support\Facades\Route;
46

57
/*
@@ -13,5 +15,8 @@
1315
|
1416
*/
1517

16-
Route::get('/', [\App\Http\Controllers\DashboardController::class, 'index'])
18+
Route::get('/', [DashboardController::class, 'index'])
1719
->name('dashboard');
20+
21+
Route::post('/transaction', [TransactionController::class, 'store'])
22+
->name('transaction.store');

0 commit comments

Comments
 (0)