Compare commits
8 Commits
b58cda3e4e
...
develop
Author | SHA1 | Date | |
---|---|---|---|
c582efcf77 | |||
f7bd54b1c2 | |||
93aa4b0576 | |||
c898bcf1d4 | |||
52e922685d | |||
71e10c52bd | |||
e672ac48a7 | |||
4f7241e146 |
4
.db.env.sample
Normal file
4
.db.env.sample
Normal file
@ -0,0 +1,4 @@
|
||||
MYSQL_ROOT_PASSWORD=password
|
||||
MYSQL_DATABASE=database
|
||||
MYSQL_USER=user
|
||||
MYSQL_PASSWORD=password
|
3
.ui.env.sample
Normal file
3
.ui.env.sample
Normal file
@ -0,0 +1,3 @@
|
||||
DEBUG=true
|
||||
BASE_URL=http://localhost:8080
|
||||
API_URL=http://localhost:8081
|
@ -41,4 +41,10 @@ class Facturas {
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function add_venta(Request $request, Response $response, $id_factura): Response {
|
||||
$post = $request->getParsedBody();
|
||||
$factura = Model::factory(FacturaProyectoOperador::class)->find_one($id_factura);
|
||||
$output = $factura->addVenta($post);
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
||||
|
@ -44,12 +44,14 @@ class Proyectos {
|
||||
}
|
||||
public function operadores(Request $request, Response $response, $id_proyecto): Response {
|
||||
$proyecto = Model::factory(Proyecto::class)->find_one($id_proyecto);
|
||||
error_log(var_export($proyecto->operadores(), true));
|
||||
$output = [
|
||||
'proyecto' => $proyecto->as_array(),
|
||||
'operadores' => $proyecto->operadores() ? array_map(function($item) {
|
||||
if ($item) {
|
||||
return $item->as_array();
|
||||
}
|
||||
$arr = $item->as_array();
|
||||
$arr['agente_tipo'] = $item->agente_tipo()->as_array();
|
||||
$arr['agente_tipo']['agente'] = $arr['operador'] = $item->agente_tipo()->agente()->as_array();
|
||||
return $arr;
|
||||
}, $proyecto->operadores()) : null
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
|
@ -28,4 +28,20 @@ class Ventas {
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function facturas(Request $request, Response $response, $id_venta): Response {
|
||||
$venta = Model::factory(Venta::class)->find_one($id_venta);
|
||||
if (!$venta) {
|
||||
return $this->withJson($response, ['venta' =>null, 'facturas' => null]);
|
||||
}
|
||||
$output = [
|
||||
'venta' => $venta->as_array(),
|
||||
'facturas' => null
|
||||
];
|
||||
if ($venta->facturas() !== null) {
|
||||
$output['facturas'] = array_map(function($item) {
|
||||
return $item->as_array();
|
||||
}, $venta->facturas());
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ server {
|
||||
location ~ \.php$ {
|
||||
try_files $uri =404;
|
||||
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
||||
fastcgi_pass backend:9000;
|
||||
fastcgi_pass operadores-backend:9000;
|
||||
fastcgi_index index.php;
|
||||
include fastcgi_params;
|
||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||
|
@ -10,6 +10,7 @@ $app->group('/facturas', function($app) {
|
||||
});
|
||||
$app->group('/factura/{id_factura}', function($app) {
|
||||
$app->group('/ventas', function($app) {
|
||||
$app->post('/add[/]', [Facturas::class, 'add_venta']);
|
||||
$app->get('[/]', [Facturas::class, 'ventas']);
|
||||
});
|
||||
});
|
||||
|
@ -8,5 +8,8 @@ $app->group('/venta/{id_venta}', function($app) {
|
||||
$app->group('/operador', function($app) {
|
||||
$app->get('[/]', [Ventas::class, 'operador']);
|
||||
});
|
||||
$app->group('/facturas', function($app) {
|
||||
$app->get('[/]', [Ventas::class, 'facturas']);
|
||||
});
|
||||
$app->get('[/]', [Ventas::class, 'show']);
|
||||
});
|
||||
|
@ -7,7 +7,7 @@ return [
|
||||
'engine' => 'mysql',
|
||||
'name' => $_ENV['MYSQL_DATABASE'],
|
||||
'host' => (object) [
|
||||
'name' => 'db'
|
||||
'name' => $_ENV['MYSQL_HOST']
|
||||
],
|
||||
'user' => (object) [
|
||||
'name' => $_ENV['MYSQL_USER'],
|
||||
|
@ -83,6 +83,10 @@ class FacturaProyectoOperador extends Model {
|
||||
];
|
||||
return $output;
|
||||
}
|
||||
public function addVenta($data) {
|
||||
$data['factura_id'] = $this->id;
|
||||
return FacturaVenta::add($data);
|
||||
}
|
||||
|
||||
public function as_array() {
|
||||
$arr = parent::as_array();
|
||||
|
@ -27,6 +27,37 @@ class FacturaVenta extends Model {
|
||||
return $this->venta;
|
||||
}
|
||||
|
||||
public static function add($data) {
|
||||
$fields = [
|
||||
'factura_id',
|
||||
'venta_id',
|
||||
'valor'
|
||||
];
|
||||
$input = array_intersect_key($data, array_combine($fields, $fields));
|
||||
$validate = [
|
||||
'factura_id',
|
||||
'venta_id'
|
||||
];
|
||||
$orm = Model::factory(FacturaVenta::class);
|
||||
foreach ($validate as $field) {
|
||||
$orm = $orm->where($field, $input[$field]);
|
||||
}
|
||||
$factura = $orm->find_one();
|
||||
$created = false;
|
||||
$found = true;
|
||||
if (!$factura) {
|
||||
$found = false;
|
||||
$factura = FacturaVenta::create($input);
|
||||
$created = $factura->save();
|
||||
}
|
||||
return [
|
||||
'input' => $input,
|
||||
'factura' => $factura->as_array(),
|
||||
'new' => !$found,
|
||||
'created' => $created
|
||||
];
|
||||
}
|
||||
|
||||
public function as_array() {
|
||||
$arr = parent::as_array();
|
||||
$arr['factura'] = $this->factura()->as_array();
|
||||
|
@ -45,12 +45,10 @@ class Proyecto extends Model {
|
||||
public function operadores() {
|
||||
if ($this->operadores === null) {
|
||||
$pas = $this->has_many(ProyectoAgente::class, 'proyecto')->find_many();
|
||||
$operadores = [];
|
||||
foreach ($pas as $pa) {
|
||||
$id = $pa->agente_tipo()->agente()->id;
|
||||
$operadores []= Model::factory(Operador::class)->find_one($id);
|
||||
}
|
||||
$this->operadores = $operadores;
|
||||
$pas = array_filter($pas, function($pa) {
|
||||
return ($pa->agente_tipo()->tipo() === 'operador');
|
||||
});
|
||||
$this->operadores = $pas;
|
||||
}
|
||||
return $this->operadores;
|
||||
}
|
||||
|
@ -20,11 +20,4 @@ class Unidad extends Model {
|
||||
}
|
||||
return $this->proyecto_tipo_unidad;
|
||||
}
|
||||
protected $facturas;
|
||||
public function facturas() {
|
||||
if ($this->facturas === null) {
|
||||
$this->facturas = $this->has_many(FacturaUnidad::class, 'unidad_id')->find_many();
|
||||
}
|
||||
return $this->facturas;
|
||||
}
|
||||
}
|
||||
|
@ -72,16 +72,26 @@ class Venta extends Model {
|
||||
}
|
||||
return $this->comision;
|
||||
}
|
||||
protected $facturas;
|
||||
public function facturas() {
|
||||
if ($this->facturas === null) {
|
||||
$this->facturas = $this->has_many(FacturaVenta::class, 'venta_id')->find_many();
|
||||
}
|
||||
return $this->facturas;
|
||||
}
|
||||
|
||||
public function as_array() {
|
||||
$arr = parent::as_array();
|
||||
$arr['propietario'] = $this->propietario()->as_array();
|
||||
$arr['propiedad'] = $this->propiedad()->as_array();
|
||||
$arr['valor'] = '$ ' . number_format($this->valor_uf, 2, ',', '.');
|
||||
$arr['valor'] = [
|
||||
'valor' => $this->valor_uf,
|
||||
'formateado' => number_format($this->valor_uf, 2, ',', '.') . ' UF'
|
||||
];
|
||||
if ($this->operador()) {
|
||||
$arr['operador'] = $this->operador()->as_array();
|
||||
$arr['comision'] = (array) $this->comision();
|
||||
$arr['comision']['formateada'] = '$ ' . number_format($this->comision()->total, 2, ',', '.');
|
||||
$arr['comision']['formateada'] = number_format($this->comision()->total, 2, ',', '.') . ' UF';
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
|
@ -1,68 +1,83 @@
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
backend-proxy:
|
||||
container_name: backend_proxy
|
||||
operadores-backend-proxy:
|
||||
profiles:
|
||||
- operadores
|
||||
container_name: operadores_api
|
||||
image: nginx
|
||||
volumes:
|
||||
- ./api/:/app/
|
||||
- ./api/nginx.conf:/etc/nginx/conf.d/default.conf
|
||||
- ./logs/api/:/var/log/nginx/
|
||||
- ${OPERADORES_PATH:-.}/api/:/app/
|
||||
- ${OPERADORES_PATH:-.}/api/nginx.conf:/etc/nginx/conf.d/default.conf
|
||||
- ./logs/operadores/api/:/var/log/nginx/
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- 8081:80
|
||||
- 8001:80
|
||||
depends_on:
|
||||
- backend
|
||||
backend:
|
||||
container_name: backend
|
||||
- operadores-backend
|
||||
operadores-backend:
|
||||
profiles:
|
||||
- operadores
|
||||
container_name: operadores_backend
|
||||
restart: unless-stopped
|
||||
image: php
|
||||
build:
|
||||
context: ./api
|
||||
context: ${OPERADROES_PATH:-.}/api
|
||||
dockerfile: PHP.Dockerfile
|
||||
env_file: .db.env
|
||||
env_file: ${OPERADORES_PATH:-.}/.db.env
|
||||
volumes:
|
||||
- ./api/:/app/
|
||||
depends_on:
|
||||
- db
|
||||
- ${OPERADORES_PATH:-.}/api/:/app/
|
||||
# depends_on:
|
||||
# - db
|
||||
|
||||
frontend-proxy:
|
||||
container_name: frontend_proxy
|
||||
operadores-frontend-proxy:
|
||||
profiles:
|
||||
- operadores
|
||||
container_name: operadores_ui
|
||||
image: nginx
|
||||
volumes:
|
||||
- ./ui/:/app/
|
||||
- ./ui/nginx.conf:/etc/nginx/conf.d/default.conf
|
||||
- ./logs/ui/:/var/log/nginx/
|
||||
- ${OPERADORES_PATH:-.}/ui/:/app/
|
||||
- ${OPERADORES_PATH:-.}/ui/nginx.conf:/etc/nginx/conf.d/default.conf
|
||||
- ./logs/operadores/ui/:/var/log/nginx/
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- 8080:80
|
||||
- 8000:80
|
||||
depends_on:
|
||||
- frontend
|
||||
frontend:
|
||||
container_name: frontend
|
||||
- operadores-frontend
|
||||
operadores-frontend:
|
||||
profiles:
|
||||
- operadores
|
||||
container_name: operadores_frontend
|
||||
restart: unless-stopped
|
||||
image: php:ui
|
||||
build:
|
||||
context: ./ui
|
||||
context: ${OPERADORES_PATH:-.}/ui
|
||||
dockerfile: PHP.Dockerfile
|
||||
env_file: .ui.env
|
||||
env_file: ${OPERADORES_PATH:-.}/.ui.env
|
||||
volumes:
|
||||
- ./ui/:/app/
|
||||
- ${OPERADORES_PATH:-.}/ui/:/app/
|
||||
#
|
||||
# db:
|
||||
# image: mariadb
|
||||
# volumes:
|
||||
# - database:/var/lib/mysql
|
||||
# env_file: .db.env
|
||||
# adminer:
|
||||
# image: adminer
|
||||
# environment:
|
||||
# ADMINER_PLUGINS: "dump-json edit-foreign enum-option json-column"
|
||||
# ADMINER_DESIGN: "dracula"
|
||||
# volumes:
|
||||
# - ./adminer/plugins-enabled/:/var/www/html/plugins-enabled/
|
||||
# ports:
|
||||
# - 8082:8080
|
||||
# depends_on:
|
||||
# - db
|
||||
#
|
||||
#volumes:
|
||||
# database:
|
||||
|
||||
db:
|
||||
image: mariadb
|
||||
volumes:
|
||||
- database:/var/lib/mysql
|
||||
env_file: .db.env
|
||||
adminer:
|
||||
image: adminer
|
||||
environment:
|
||||
ADMINER_PLUGINS: "dump-json edit-foreign enum-option json-column"
|
||||
ADMINER_DESIGN: "dracula"
|
||||
volumes:
|
||||
- ./adminer/plugins-enabled/:/var/www/html/plugins-enabled/
|
||||
ports:
|
||||
- 8082:8080
|
||||
depends_on:
|
||||
- db
|
||||
|
||||
volumes:
|
||||
database:
|
||||
networks:
|
||||
default:
|
||||
external: true
|
||||
name: incoviba_network
|
||||
|
@ -13,7 +13,7 @@ server {
|
||||
location ~ \.php$ {
|
||||
try_files $uri =404;
|
||||
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
||||
fastcgi_pass frontend:9000;
|
||||
fastcgi_pass operadores-frontend:9000;
|
||||
fastcgi_index index.php;
|
||||
include fastcgi_params;
|
||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||
|
@ -328,6 +328,7 @@
|
||||
facturas.asignar($(e.target)).then(() => {
|
||||
$(e.target).trigger('reset')
|
||||
$(this.id).modal('toggle')
|
||||
$(this.id).modal('hide')
|
||||
})
|
||||
return false
|
||||
})
|
||||
|
@ -23,18 +23,26 @@
|
||||
@include('layout.menu.informes')
|
||||
</li>
|
||||
|
||||
<li role="presentation" class="dropdown">
|
||||
<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">
|
||||
Herramientas <span class="caret"></span>
|
||||
</a>
|
||||
@include('layout.menu.herramientas')
|
||||
</li>
|
||||
<li rol="presentation" class="dropdown">
|
||||
<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">
|
||||
Operadores <span class="caret"></span>
|
||||
</a>
|
||||
@include('layout.menu.operadores')
|
||||
</li>
|
||||
|
||||
<li role="presentation" class="dropdown">
|
||||
<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">
|
||||
Operadores <span class="caret"></span>
|
||||
</a>
|
||||
@include('layout.menu.operadores')
|
||||
</li>
|
||||
|
||||
<li role="presentation" class="dropdown">
|
||||
<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">
|
||||
Herramientas <span class="caret"></span>
|
||||
</a>
|
||||
@include('layout.menu.herramientas')
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
<li role="presentation" class="dropdown">
|
||||
|
@ -6,6 +6,6 @@
|
||||
<a href="{{$urls->base}}/ventas">Ventas</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{{$urls->base}}/informe">Informe</a>
|
||||
<a href="{{$urls->base}}/facturas">Informe</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
@ -53,6 +53,60 @@
|
||||
})
|
||||
}
|
||||
}
|
||||
class Facturas {
|
||||
constructor(venta_id) {
|
||||
this.venta_id = venta_id
|
||||
this.facturas = []
|
||||
}
|
||||
get() {
|
||||
return $.ajax({
|
||||
url: '{{$urls->api}}/venta/' + this.venta_id + '/facturas',
|
||||
method: 'get',
|
||||
dataType: 'json'
|
||||
}).then((data) => {
|
||||
if (data.facturas === null || data.facturas.length == 0) {
|
||||
return
|
||||
}
|
||||
this.facturas = data.facturas
|
||||
this.draw()
|
||||
})
|
||||
}
|
||||
draw() {
|
||||
const parent = $('#' + this.venta_id)
|
||||
let tbody = parent.find('tbody')
|
||||
if (tbody.length == 0) {
|
||||
tbody = $('<tbody></tbody>')
|
||||
const table = $('<table></table>').attr('class', 'table').append(
|
||||
$('<thead></thead>').append(
|
||||
$('<tr></tr>').append(
|
||||
$('<th></th>').html('Factura')
|
||||
).append(
|
||||
$('<th></th>').html('Emisor')
|
||||
).append(
|
||||
$('<th></th>').html('Fecha')
|
||||
).append(
|
||||
$('<th></th>').html('Valor')
|
||||
)
|
||||
)
|
||||
).append(tbody)
|
||||
parent.append(table)
|
||||
}
|
||||
tbody.html('')
|
||||
$.each(this.facturas, (i, el) => {
|
||||
tbody.append(
|
||||
$('<tr></tr>').append(
|
||||
$('<td></td>').html(el.factura.factura)
|
||||
).append(
|
||||
$('<td></td>').html(el.factura.operador.descripcion)
|
||||
).append(
|
||||
$('<td></td>').html(el.factura.fecha.formateada)
|
||||
).append(
|
||||
$('<td></td>').html(el.valor.formateado)
|
||||
)
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
const ventas = {
|
||||
id: '#ventas',
|
||||
data: [],
|
||||
@ -69,9 +123,9 @@
|
||||
this.draw()
|
||||
})
|
||||
},
|
||||
facturas: (unidad) => {
|
||||
facturas: (venta) => {
|
||||
return $.ajax({
|
||||
url: '{{$urls->api}}/unidad/' + unidad + '/facturas',
|
||||
url: '{{$urls->api}}/venta/' + venta + '/facturas',
|
||||
method: 'get',
|
||||
dataType: 'json'
|
||||
})
|
||||
@ -86,34 +140,26 @@
|
||||
).append(
|
||||
$('<td></td>').html(el.propietario.nombre_completo)
|
||||
).append(
|
||||
$('<td></td>').attr('class', 'text-right').html(el.valor)
|
||||
$('<td></td>').attr('class', 'text-right').html(el.valor.formateado)
|
||||
)
|
||||
if (el.operador) {
|
||||
row.append(
|
||||
$('<td></td>').html(el.operador.descripcion)
|
||||
).append(
|
||||
$('<td></td>').attr('class', 'text-right').html(el.comision.formateada)
|
||||
).append(
|
||||
$('<td></td>').attr('id', el.propiedad.unidades[0].id)
|
||||
)
|
||||
this.get().facturas(el.propiedad.unidades[0].id).then((data) => {
|
||||
const td = $('td#' + data.unidad.id)
|
||||
if (data.facturas === null || data.facturas.length == 0) {
|
||||
return
|
||||
}
|
||||
$.each(data.facturas, (k, it) => {
|
||||
console.debug(it)
|
||||
})
|
||||
})
|
||||
} else {
|
||||
row.append(
|
||||
$('<td></td>')
|
||||
).append(
|
||||
$('<td></td>')
|
||||
).append(
|
||||
$('<td></td>')
|
||||
)
|
||||
}
|
||||
row.append(
|
||||
$('<td></td>').attr('id', el.id)
|
||||
)
|
||||
this.data[i].facturas = new Facturas(el.id)
|
||||
this.data[i].facturas.get()
|
||||
parent.append(row)
|
||||
})
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
return [
|
||||
'debug' => $_ENV['DEBUG'],
|
||||
'folders' => function() {
|
||||
$arr = ['base' => dirname(__DIR__, 2)];
|
||||
$arr['resources'] = implode(DIRECTORY_SEPARATOR, [
|
||||
|
Reference in New Issue
Block a user