Skip to content

Commit

Permalink
Merge branch 'main' into feat/incidences-javascript
Browse files Browse the repository at this point in the history
  • Loading branch information
0x1026 authored Nov 18, 2024
2 parents 5082041 + b4b3f18 commit 3e85452
Show file tree
Hide file tree
Showing 27 changed files with 587 additions and 175 deletions.
118 changes: 62 additions & 56 deletions docker/database/start-scripts/0-init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ create table pruning_types (
created_at timestamp default current_timestamp
);

--* Points and zones
--* Points, zones and routes
create table points (
id int auto_increment primary key,
latitude decimal(10, 7) not null,
Expand All @@ -82,6 +82,15 @@ create table zones (
constraint UC_Zone unique (name, postal_code)
);

create table routes (
id int auto_increment primary key,
distance float,
point_id int,
travel_time int,
created_at timestamp default current_timestamp,
foreign key (point_id) references points(id)
);

--* Elements and incidences
create table elements (
id int auto_increment primary key,
Expand Down Expand Up @@ -109,79 +118,76 @@ create table incidences (
foreign key (element_id) references elements(id)
);

--TODO: tasks, routes and works
--* Work orders, tasks and reports
create table work_orders (
id int auto_increment primary key,
name varchar(255),
contract_id int,
created_at timestamp default current_timestamp,
updated_at timestamp,
deleted_at timestamp
deleted_at timestamp,
foreign key (contract_id) references contracts(id)
);

create table parts (
create table tasks (
id int auto_increment primary key,
observation varchar(255),
quantity int,
fuel decimal,
picture varchar(255)
work_order_id int not null,
notes varchar(255),
created_at timestamp default current_timestamp,
deleted_at timestamp,
foreign key (work_order_id) references work_orders(id)
);

create table routes (
create table tasks_workers (
id int auto_increment primary key,
distance float,
point_id int,
travel_time int,
created_at timestamp default current_timestamp,
foreign key (point_id) references points(id)
task_id int,
worker_id int,
foreign key (task_id) references tasks(id),
foreign key (worker_id) references workers(id)
);

create table tasks (
create table tasks_zones (
id int auto_increment primary key,
task_name varchar(255),
work_order_id int,
description varchar(255),
element_id int,
machine_id int,
route_id int,
part_id int,
history_id int,
task_id int,
zone_id int,
foreign key (task_id) references tasks(id),
foreign key (zone_id) references zones(id)
);

create table tasks_tasktypes (
id int auto_increment primary key,
task_id int,
tasktype_id int,
foreign key (task_id) references tasks(id),
foreign key (tasktype_id) references task_types(id)
);

create table work_reports (
id int primary key,
observation varchar(255),
spent_fuel decimal,
photo varchar(255),
created_at timestamp default current_timestamp,
updated_at timestamp,
deleted_at timestamp,
foreign key (work_order_id) references work_orders(id),
foreign key (element_id) references elements(id),
foreign key (machine_id) references machines(id),
foreign key (route_id) references routes(id),
foreign key (part_id) references parts(id)
foreign key (id) references work_orders(id)
);

create table task_workers (
--* Sensors and sensor history
create table sensors (
id int auto_increment primary key,
task_id int,
worker_id int,
zone_id int not null,
model varchar(255),
class varchar(255),
is_active boolean,
created_at timestamp default current_timestamp,
foreign key (task_id) references tasks(id),
foreign key (worker_id) references workers(id)
foreign key (zone_id) references zones(id)
);

--* FUTURE: sensors and sensor history
-- create table sensors (
-- id int auto_increment primary key,
-- entidad_vegetal int,
-- element_id int,
-- model varchar(255),
-- operative boolean,
-- class varchar(255),
-- created_at timestamp default current_timestamp,
-- foreign key (element_id) references elements(id)
-- );
--
-- create table sensor_history (
-- id int auto_increment primary key,
-- sensor_id int,
-- temperature float,
-- humedad float,
-- inclination float,
-- created_at timestamp default current_timestamp,
-- foreign key (sensor_id) references sensors(id)
-- );
create table sensor_history (
id int auto_increment primary key,
sensor_id int not null,
temperature float,
humidity float,
inclination float,
created_at timestamp default current_timestamp,
foreign key (sensor_id) references sensors(id)
);
66 changes: 40 additions & 26 deletions docker/database/start-scripts/1-seed.sql
Original file line number Diff line number Diff line change
@@ -1,62 +1,76 @@
-- Insert sample roles (Admin, Manager, Worker)
--* Roles, users, contracts and machines
INSERT INTO roles (name) VALUES
('Administrador'),
('Gerente'),
('Trabajador');

-- Insert sample workers (Spanish users)
INSERT INTO workers (company, name, dni, password, email, role_id, created_at, updated_at, deleted_at) VALUES
('TechCorp', 'Carlos García', '12345678A', 'hashedpassword1', '[email protected]', 1, NOW(), NOW(), NULL), -- Admin
('InnovaTech', 'Ana Martínez', '23456789B', 'hashedpassword2', '[email protected]', 2, NOW(), NOW(), NULL), -- Manager
('DesignWorks', 'José Rodríguez', '34567890C', 'hashedpassword3', '[email protected]', 3, NOW(), NOW(), NULL); -- Worker

-- Insert sample tree types
INSERT INTO tree_types (family, genus, species) VALUES
('Fagaceae', 'Quercus', 'Quercus robur'),
('Pinaceae', 'Pinus', 'Pinus sylvestris'),
('Sapindaceae', 'Acer', 'Acer campestre');

-- Insert sample contracts
('TechCorp', 'Carlos García', '12345678A', 'hashedpassword1', '[email protected]', 1, NOW(), NOW(), NULL),
('InnovaTech', 'Ana Martínez', '23456789B', 'hashedpassword2', '[email protected]', 2, NOW(), NOW(), NULL),
('DesignWorks', 'José Rodríguez', '34567890C', 'hashedpassword3', '[email protected]', 3, NOW(), NOW(), NULL);
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);

-- Insert sample task types
INSERT INTO machines (name, max_basket_size) VALUES
('Cesta elevadora', 200.00),
('Plataforma elevadora', 300.00),
('Tijera elevadora', 400.00);
--* Tree, task and pruning types
INSERT INTO tree_types (family, genus, species) VALUES
('Fagaceae', 'Quercus', 'Quercus robur'),
('Pinaceae', 'Pinus', 'Pinus sylvestris'),
('Sapindaceae', 'Acer', 'Acer campestre');
INSERT INTO task_types (name) VALUES
('Abono arbustos'),
('Podar setos'),
('Abono setos');

-- Insert sample pruning types
INSERT INTO pruning_types (name, description) VALUES
('A', 'Poda de mantenimiento en árbol tipo A, caduco, de p.c. entre 41/80 cm.'),
('B', 'Poda de mantenimiento en árbol tipo B, caduco, de p.c. mayor de 81 cm.'),
('C', 'Poda de mantenimiento en árbol tipo C, perenne, de p.c. entre 41/60 cm.');

-- Insert sample points
--* Points and zones
INSERT INTO points (latitude, longitude) VALUES
(40.416775, -3.703790),
(40.416776, -3.703795),
(40.416777, -3.703800);

-- Insert sample zones
INSERT INTO zones (name, postal_code, point_id) VALUES
('Zona 1', '46001', 1),
('Zona 2', '46002', 2),
('Zona 3', '46003', 3);

-- Insert sample elements
--* Elements and incidences
INSERT INTO elements (name, zone_id, point_id, tree_type_id) VALUES
('Árbol 1', 1, 1, 1),
('Árbol 2', 2, 2, 2),
('Árbol 3', 3, 3, 3);

-- Insert sample incidences
INSERT INTO incidences (name, element_id, description) VALUES
('Rama caída', 1, 'Rama caída en el suelo'),
('Banco roto', 2, 'Banco roto en el parque'),
('Fuente sin agua', 3, 'Fuente sin agua en el parque'),
('Árbol enfermo', 1, 'Árbol con signos de enfermedad'),
('Banco pintado', 2, 'Banco pintado con grafitis'),
('Fuente con fuga', 3, 'Fuente con fuga de agua');
--TODO: tasks, routes and works
INSERT INTO work_orders (contract_id) VALUES
(1),
(2),
(3);

INSERT INTO tasks (work_order_id, notes) VALUES
(1, 'Poda de mantenimiento en árbol tipo A, caduco, de p.c. entre 41/80 cm.'),
(2, 'Poda de mantenimiento en árbol tipo B, caduco, de p.c. entre 50/100 cm.'),
(3, 'Poda de mantenimiento en árbol tipo C, caduco, de p.c. entre 60/120 cm.');

INSERT INTO tasks_zones (task_id, zone_id) VALUES
(1, 1),
(2, 2),
(3, 3);

INSERT INTO tasks_tasktypes (task_id, tasktype_id) VALUES
(1, 1),
(2, 2),
(3, 3);

INSERT INTO tasks_workers (task_id, worker_id) VALUES
(1, 1),
(2, 2),
(3, 3);
60 changes: 60 additions & 0 deletions src/app/Controllers/CWorkOrder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
namespace App\Controllers;

use App\Core\View;
use App\Models\MWorkOrder;
class CWorkOrder
{
public function findAll()
{
$orders = MWorkOrder::findAll();
View::render([
"view" => "order/index",
"title" => "Order",
"layout" => "MainLayout",
"data" => ["orders" => $orders]
]);
}

public function find()
{
$id = $_GET['id'];
$order = MWorkOrder::find($id);
View::render([
"view" => "order",
"title" => "Order",
"layout" => "MainLayout",
"data" => ["order" => $order]
]);
}

public function indexCreate()
{
$orders = MWorkOrder::findAll();
View::render([
"view" => "order/create",
"title" => "Create Order",
"layout" => "MainLayout",
"data" => ["orders" => $orders]
]);
}

public function save()
{
$order = new MWorkOrder();

$order->save();
}

public function delete()
{
$id = $_GET['id'];
$order = MWorkOrder::find($id);
$order->delete();
}

public function update()
{

}
}
Loading

0 comments on commit 3e85452

Please sign in to comment.