diff --git a/docker/database/start-scripts/0-init.sql b/docker/database/start-scripts/0-init.sql
index 7131a11e..732e2d3f 100644
--- a/docker/database/start-scripts/0-init.sql
+++ b/docker/database/start-scripts/0-init.sql
@@ -81,7 +81,7 @@ CREATE TABLE contracts (
invoice_paid float,
created_at timestamp default current_timestamp,
deleted_at timestamp,
- updated_at timestamp,
+ updated_at timestamp
);
create table work_orders (
diff --git a/docker/database/start-scripts/1-seed.sql b/docker/database/start-scripts/1-seed.sql
index 12c4e424..478e036e 100644
--- a/docker/database/start-scripts/1-seed.sql
+++ b/docker/database/start-scripts/1-seed.sql
@@ -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);
\ No newline at end of file
diff --git a/src/app/Controllers/ContractController.php b/src/app/Controllers/ContractController.php
index 7c732616..cd4388b0 100644
--- a/src/app/Controllers/ContractController.php
+++ b/src/app/Controllers/ContractController.php
@@ -2,14 +2,15 @@
namespace App\Controllers;
+use App\Core\BaseController;
use App\Core\View;
use App\Models\Contract;
-class ContractController
+class ContractController implements BaseController
{
- public function index()
+ public function get()
{
- $contracts = Contract::getAll();
+ $contracts = Contract::findAll();
View::render([
"view" => "Contracts",
"title" => "Contracts",
@@ -17,4 +18,8 @@ public function index()
"data" => ["contracts" => $contracts]
]);
}
+
+ public function post() {}
+ public function put() {}
+ public function delete() {}
}
\ No newline at end of file
diff --git a/src/app/Models/Contract.php b/src/app/Models/Contract.php
index 98547ca3..6d63d922 100644
--- a/src/app/Models/Contract.php
+++ b/src/app/Models/Contract.php
@@ -2,132 +2,33 @@
namespace App\Models;
-use App\Core\Database;
-use PDO;
-use PDOException;
+use App\Core\BaseModel;
-class Contract
+class Contract extends BaseModel
{
- private $id;
- private $contract_type;
- private $start_date;
- private $end_date;
- private $salary;
-
- // Constructor per inicialitzar les propietats
- public function __construct($data = [])
- {
- foreach ($data as $key => $value) {
- $this->$key = $value;
- }
- }
-
- // Mètode per obtenir tots els contractes
- public static function getAll()
- {
- $query = "SELECT * FROM contracts";
- $results = Database::prepareAndExecute($query);
- foreach ($results as $key => $value) {
- $results[$key] = new self($value);
- }
- return $results;
- }
-
- // Mètode per obtenir un contracte per ID
- public static function findById($id)
- {
- $query = "SELECT * FROM contracts WHERE id = :id";
- $results = Database::prepareAndExecute($query, ['id' => $id]);
-
- return $results ? new self($results[0]) : null;
- }
-
- // Mètode per guardar un nou contracte
- public function save()
- {
- $query = "INSERT INTO contracts (contract_type, start_date, end_date, salary)
- VALUES (:contract_type, :start_date, :end_date, :salary)";
- $params = [
- 'contract_type' => $this->contract_type,
- 'start_date' => $this->start_date,
- 'end_date' => $this->end_date,
- 'salary' => $this->salary,
- ];
-
- return Database::prepareAndExecute($query, $params);
- }
-
- // Mètode per actualitzar un contracte existent
- public function update()
- {
- $query = "UPDATE contracts SET contract_type = :contract_type, start_date = :start_date,
- end_date = :end_date, salary = :salary WHERE id = :id";
- $params = [
- 'contract_type' => $this->contract_type,
- 'start_date' => $this->start_date,
- 'end_date' => $this->end_date,
- 'salary' => $this->salary,
- 'id' => $this->id,
- ];
-
- return Database::prepareAndExecute($query, $params);
- }
-
- // Mètode per esborrar un contracte
- public function delete()
- {
- $query = "DELETE FROM contracts WHERE id = :id";
- return Database::prepareAndExecute($query, ['id' => $this->id]);
- }
-
- // Getters i setters
- public function getId()
- {
- return $this->id;
- }
-
- public function getContractType()
- {
- return $this->contract_type;
- }
-
- public function getStartDate()
- {
- return $this->start_date;
- }
-
- public function getEndDate()
- {
- return $this->end_date;
- }
-
- public function getSalary()
- {
- return $this->salary;
- }
-
- public function setId($id)
- {
- $this->id = $id;
- }
-
- public function setContractType($contract_type)
- {
- $this->contract_type = $contract_type;
- }
-
- public function setStartDate($start_date)
- {
- $this->start_date = $start_date;
- }
-
- public function setEndDate($end_date)
- {
- $this->end_date = $end_date;
- }
-
- public function setSalary($salary)
- {
- $this->salary = $salary;
+ 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;
}
}
diff --git a/src/app/Models/TreeType.php b/src/app/Models/TreeType.php
index e59f8f1f..359a9d20 100644
--- a/src/app/Models/TreeType.php
+++ b/src/app/Models/TreeType.php
@@ -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';
}
diff --git a/src/app/Views/Contracts.php b/src/app/Views/Contracts.php
index 6679ad4b..021129a3 100644
--- a/src/app/Views/Contracts.php
+++ b/src/app/Views/Contracts.php
@@ -3,20 +3,26 @@
ID
- Contract Type
+ Name
Start Date
End Date
- Salary
+ Invoice proposed
+ Invoice agreed
+ Invoice paid
+ Created at