Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Controller/EditReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ protected function createViews(): void
// añadimos la pestaña de filtros
$this->createViewsFilterLines();

// añadimos la pestaña de informes relacionados
// añadimos la pestaña de Informes relacionados
$this->createViewsRelatedReports();
}

Expand Down
2 changes: 1 addition & 1 deletion Controller/ListReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private function getTablesWithDate(): array
* Se debe usar una transaction desde fuera (por si no se crea correctamente).
*
* El nombre de la pizarra es "Tablero de $column sobre el campo de fecha $table."
* Se crearán informes con altura 250 y ancho 6 en la pizarra con los siguientes nombres:
* Se crearán Informes con altura 250 y ancho 6 en la pizarra con los siguientes nombres:
* - "$tabla, $campo / hora" (Si es timestamp)
* - "$tabla, $campo / semana"
* - "$tabla, $campo / mese"
Expand Down
2 changes: 1 addition & 1 deletion Extension/Controller/EditAgente.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function execAfterAction(): Closure
return;
}

// generemos los informes
// generemos los Informes
$code = $this->getModel()->primaryColumnValue();
if (empty($code)) {
Tools::log()->warning('no-agent-code');
Expand Down
2 changes: 1 addition & 1 deletion Extension/Controller/EditCliente.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function execAfterAction(): Closure
return;
}

// generemos los informes
// generemos los Informes
$code = $this->getModel()->primaryColumnValue();
if (empty($code)) {
Tools::log()->warning('no-customer-code');
Expand Down
2 changes: 1 addition & 1 deletion Extension/Controller/EditProveedor.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function execAfterAction(): Closure
return;
}

// generemos los informes
// generemos los Informes
$code = $this->getModel()->primaryColumnValue();
if (empty($code)) {
Tools::log()->warning('no-supplier-code');
Expand Down
2 changes: 1 addition & 1 deletion Extension/Controller/EditUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function execAfterAction(): Closure
return;
}

// generemos los informes
// generemos los Informes
$code = $this->getModel()->primaryColumnValue();
if (empty($code)) {
Tools::log()->warning('no-user-code');
Expand Down
78 changes: 78 additions & 0 deletions Init.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
use FacturaScripts\Core\Base\DataBase;
use FacturaScripts\Core\Template\InitClass;
use FacturaScripts\Core\Tools;
use FacturaScripts\Core\Model\Role;
use FacturaScripts\Core\Model\RoleAccess;
use FacturaScripts\Core\Where;
use FacturaScripts\Dinamic\Model\BalanceAccount;
use FacturaScripts\Dinamic\Model\BalanceCode;
use FacturaScripts\Dinamic\Model\Empresa;
Expand Down Expand Up @@ -51,6 +54,7 @@ public function update(): void
// migramos los datos antiguos
$this->migrateOldBalances();
$this->migrateOldReports();
$this->createRoleForPlugin();
}

private function copyBalancePymes(): bool
Expand Down Expand Up @@ -208,4 +212,78 @@ private function migrateOldReports(): void
}
}
}

private function createRoleForPlugin(): void
{
$roleName = 'Informes';

new Role();
new RoleAccess();

$dataBase = new DataBase();
$dataBase->beginTransaction();

// creates the role if not exists
$role = new Role();
if (false === $role->load($roleName)) {
$role->codrole = $role->descripcion = $roleName;
if (false === $role->save()) {
// rollback and exit on fail
$dataBase->rollback();
return;
}
}

// checks the role permissions
$nameControllers = [];

// scan Controller and Extension/Controller for pagenames
$dirs = [__DIR__ . '/Controller', __DIR__ . '/Extension/Controller'];
foreach ($dirs as $dir) {
if (!is_dir($dir)) {
continue;
}
foreach (scandir($dir) as $file) {
if (!is_file($dir . DIRECTORY_SEPARATOR . $file)) {
continue;
}
if (substr($file, -4) !== '.php') {
continue;
}
$name = pathinfo($file, PATHINFO_FILENAME);
// filter by allowed prefixes
if (preg_match('/^(Edit|List|Report|Dashboard)/', $name)) {
$nameControllers[] = $name;
}
}
}
$nameControllers = array_unique($nameControllers);

foreach ($nameControllers as $nameController) {
$roleAccess = new RoleAccess();
$where = [
Where::eq('codrole', $roleName),
Where::eq('pagename', $nameController)
];
if ($roleAccess->loadWhere($where)) {
// permission exists? Then skip
continue;
}

// creates the permission if not exists
$roleAccess->allowdelete = true;
$roleAccess->allowupdate = true;
$roleAccess->codrole = $roleName;
$roleAccess->pagename = $nameController;
$roleAccess->onlyownerdata = false;
if (false === $roleAccess->save()) {
// rollback and exit on fail
$dataBase->rollback();
return;
}
}

// without problems = Commit
$dataBase->commit();
}
}
22 changes: 11 additions & 11 deletions Lib/Informes/ReportGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static function generate(): int
{
$total = 0;

// creamos los informes
// creamos los Informes
$tables = ['contactos', 'clientes', 'facturascli', 'albaranescli', 'pedidoscli', 'presupuestoscli', 'serviciosat',
'proveedores', 'facturasprov', 'albaranesprov', 'pedidosprov', 'presupuestosprov'];
foreach ($tables as $table) {
Expand All @@ -79,7 +79,7 @@ public static function generateForAgent(string $codagente): int
return $total;
}

// creamos los informes
// creamos los Informes
$tables = ['facturascli', 'albaranescli', 'pedidoscli', 'presupuestoscli'];
foreach ($tables as $table) {
$total += static::generateReportsTotalByAgent($table, $agent);
Expand Down Expand Up @@ -113,7 +113,7 @@ public static function generateForCustomer(string $codcliente): int
return $total;
}

// creamos los informes
// creamos los Informes
$tables = ['facturascli', 'albaranescli', 'pedidoscli', 'presupuestoscli'];
foreach ($tables as $table) {
$total += static::generateReportsTotalByCustomer($table, $customer);
Expand Down Expand Up @@ -147,7 +147,7 @@ public static function generateForSupplier(string $codproveedor): int
return $total;
}

// creamos los informes
// creamos los Informes
$tables = ['facturasprov', 'albaranesprov', 'pedidosprov', 'presupuestosprov'];
foreach ($tables as $table) {
$total += static::generateReportsTotalBySupplier($table, $supplier);
Expand Down Expand Up @@ -181,7 +181,7 @@ public static function generateForUser(string $username): int
return $total;
}

// creamos los informes
// creamos los Informes
$tables = ['facturascli', 'albaranescli', 'pedidoscli', 'presupuestoscli', 'facturasprov', 'albaranesprov',
'pedidosprov', 'presupuestosprov'];
foreach ($tables as $table) {
Expand Down Expand Up @@ -309,7 +309,7 @@ protected static function generateBoard(string $name, string $tag, array $report
return false;
}

// añadimos los informes
// añadimos los Informes
$pos = 1;
foreach ($report_tags as $r_tag) {
$report = new Report();
Expand Down Expand Up @@ -625,7 +625,7 @@ protected static function generateReportsTotalByWarehouse(string $table_name): i
{
$total = 0;

// si solamente hay un almacén, no es necesario crear informes por almacén
// si solamente hay un almacén, no es necesario crear Informes por almacén
if (count(Almacenes::all()) <= 1) {
return $total;
}
Expand Down Expand Up @@ -799,7 +799,7 @@ protected static function generateReportsFechaAlta(string $table_name): int
if ($reportMonths->save()) {
$total++;

// guardamos los informes para futuras referencias
// guardamos los Informes para futuras referencias
self::$table_reports[$table_name][] = $reportMonths;
}
}
Expand All @@ -819,7 +819,7 @@ protected static function generateReportsFechaAlta(string $table_name): int
if ($reportYears->save()) {
$total++;

// guardamos los informes para futuras referencias
// guardamos los Informes para futuras referencias
self::$table_reports[$table_name][] = $reportYears;
}
}
Expand Down Expand Up @@ -847,7 +847,7 @@ protected static function generateReportsFechaTotal(string $table_name): int
if ($reportMonths->save()) {
$total++;

// guardamos los informes para futuras referencias
// guardamos los Informes para futuras referencias
self::$table_reports[$table_name][] = $reportMonths;
}
}
Expand All @@ -869,7 +869,7 @@ protected static function generateReportsFechaTotal(string $table_name): int
if ($reportYears->save()) {
$total++;

// guardamos los informes para futuras referencias
// guardamos los Informes para futuras referencias
self::$table_reports[$table_name][] = $reportYears;
}
}
Expand Down
Loading