Skip to content

Commit

Permalink
feat(contract): add Contract (#69)
Browse files Browse the repository at this point in the history
Introduce a new Contract MVC for managing Contracts. Modify the element
table to meet the updated requirements, ensuring proper data handling
and integrity.
0x1026 authored Nov 16, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents cb4fc8b + b2fdde2 commit 2982182
Showing 6 changed files with 109 additions and 1 deletion.
14 changes: 14 additions & 0 deletions docker/database/start-scripts/0-init.sql
Original file line number Diff line number Diff line change
@@ -70,6 +70,20 @@ create table workers (
foreign key (role_id) references roles(id)
);


CREATE TABLE contracts (
id int auto_increment primary key,
name varchar(255),
start_date DATE,
end_date DATE,
invoice_proposed float,
invoice_agreed float,
invoice_paid float,
created_at timestamp default current_timestamp,
deleted_at timestamp,
updated_at timestamp
);

create table work_orders (
id int auto_increment primary key,
name varchar(255),
5 changes: 5 additions & 0 deletions docker/database/start-scripts/1-seed.sql
Original file line number Diff line number Diff line change
@@ -16,3 +16,8 @@ INSERT INTO tree_types (family, genus, species) VALUES
('Pinaceae', 'Pinus', 'Pinus sylvestris'),
('Sapindaceae', 'Acer', 'Acer campestre');

-- Insert sample contracts
INSERT INTO contracts (name, start_date, end_date, invoice_proposed, invoice_agreed, invoice_paid) VALUES
('Ayuntamiento de Valencia', '2021-01-01', '2021-12-31', 1000.00, 900.00, 900.00),
('Administración General del Estado', '2021-01-01', '2021-12-31', 2000.00, 1800.00, 1800.00),
('Ayuntamiento de Carlet', '2021-01-01', '2021-12-31', 3000.00, 2700.00, 2700.00);
25 changes: 25 additions & 0 deletions src/app/Controllers/ContractController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Controllers;

use App\Core\BaseController;
use App\Core\View;
use App\Models\Contract;

class ContractController implements BaseController
{
public function get()
{
$contracts = Contract::findAll();
View::render([
"view" => "Contracts",
"title" => "Contracts",
"layout" => "MainLayout",
"data" => ["contracts" => $contracts]
]);
}

public function post() {}
public function put() {}
public function delete() {}
}
34 changes: 34 additions & 0 deletions src/app/Models/Contract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace App\Models;

use App\Core\BaseModel;

class Contract extends BaseModel
{
public $name;
public $start_date;
public $end_date;
public $invoice_proposed;
public $invoice_agreed;
public $invoice_paid;
public $created_at;

protected static function getTableName()
{
return 'contracts';
}

protected static function mapDataToModel($data) {
$contract = new Contract();
$contract->id = $data['id'];
$contract->name = $data['name'];
$contract->start_date = $data['start_date'];
$contract->end_date = $data['end_date'];
$contract->invoice_proposed = $data['invoice_proposed'];
$contract->invoice_agreed = $data['invoice_agreed'];
$contract->invoice_paid = $data['invoice_paid'];
$contract->created_at = $data['created_at'];
return $contract;
}
}
2 changes: 1 addition & 1 deletion src/app/Models/TreeType.php
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ class TreeType extends BaseModel
public string $genus;
public string $species;

protected static function getTableName(): string
protected static function getTableName()
{
return 'tree_types';
}
30 changes: 30 additions & 0 deletions src/app/Views/Contracts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<div class="overflow-x-auto">
<table class="min-w-full bg-white border border-gray-300 rounded-lg shadow-md">
<thead>
<tr class="bg-gray-100 text-left">
<th class="px-4 py-2 border-b">ID</th>
<th class="px-4 py-2 border-b">Name</th>
<th class="px-4 py-2 border-b">Start Date</th>
<th class="px-4 py-2 border-b">End Date</th>
<th class="px-4 py-2 border-b">Invoice proposed</th>
<th class="px-4 py-2 border-b">Invoice agreed</th>
<th class="px-4 py-2 border-b">Invoice paid</th>
<th class="px-4 py-2 border-b">Created at</th>
</tr>
</thead>
<tbody>
<?php foreach ($contracts as $contract): ?>
<tr class="hover:bg-gray-50">
<td class="px-4 py-2 border-b"><?php echo $contract->getId(); ?></td>
<td class="px-4 py-2 border-b"><?php echo $contract->name; ?></td>
<td class="px-4 py-2 border-b"><?php echo $contract->start_date; ?></td>
<td class="px-4 py-2 border-b"><?php echo $contract->end_date; ?></td>
<td class="px-4 py-2 border-b"><?php echo $contract->invoice_proposed; ?></td>
<td class="px-4 py-2 border-b"><?php echo $contract->invoice_agreed; ?></td>
<td class="px-4 py-2 border-b"><?php echo $contract->invoice_paid; ?></td>
<td class="px-4 py-2 border-b"><?php echo $contract->created_at; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>

0 comments on commit 2982182

Please sign in to comment.