subiendo codigo fuente
commit
7230a6c89e
@ -0,0 +1,18 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_size = 4
|
||||
indent_style = space
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[*.{yml,yaml}]
|
||||
indent_size = 2
|
||||
|
||||
[docker-compose.yml]
|
||||
indent_size = 4
|
@ -0,0 +1,59 @@
|
||||
APP_NAME=Laravel
|
||||
APP_ENV=local
|
||||
APP_KEY=
|
||||
APP_DEBUG=true
|
||||
APP_URL=http://localhost
|
||||
|
||||
LOG_CHANNEL=stack
|
||||
LOG_DEPRECATIONS_CHANNEL=null
|
||||
LOG_LEVEL=debug
|
||||
|
||||
DB_CONNECTION=mysql
|
||||
DB_HOST=127.0.0.1
|
||||
DB_PORT=3306
|
||||
DB_DATABASE=laravel
|
||||
DB_USERNAME=root
|
||||
DB_PASSWORD=
|
||||
|
||||
BROADCAST_DRIVER=log
|
||||
CACHE_DRIVER=file
|
||||
FILESYSTEM_DISK=local
|
||||
QUEUE_CONNECTION=sync
|
||||
SESSION_DRIVER=file
|
||||
SESSION_LIFETIME=120
|
||||
|
||||
MEMCACHED_HOST=127.0.0.1
|
||||
|
||||
REDIS_HOST=127.0.0.1
|
||||
REDIS_PASSWORD=null
|
||||
REDIS_PORT=6379
|
||||
|
||||
MAIL_MAILER=smtp
|
||||
MAIL_HOST=mailpit
|
||||
MAIL_PORT=1025
|
||||
MAIL_USERNAME=null
|
||||
MAIL_PASSWORD=null
|
||||
MAIL_ENCRYPTION=null
|
||||
MAIL_FROM_ADDRESS="hello@example.com"
|
||||
MAIL_FROM_NAME="${APP_NAME}"
|
||||
|
||||
AWS_ACCESS_KEY_ID=
|
||||
AWS_SECRET_ACCESS_KEY=
|
||||
AWS_DEFAULT_REGION=us-east-1
|
||||
AWS_BUCKET=
|
||||
AWS_USE_PATH_STYLE_ENDPOINT=false
|
||||
|
||||
PUSHER_APP_ID=
|
||||
PUSHER_APP_KEY=
|
||||
PUSHER_APP_SECRET=
|
||||
PUSHER_HOST=
|
||||
PUSHER_PORT=443
|
||||
PUSHER_SCHEME=https
|
||||
PUSHER_APP_CLUSTER=mt1
|
||||
|
||||
VITE_APP_NAME="${APP_NAME}"
|
||||
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
|
||||
VITE_PUSHER_HOST="${PUSHER_HOST}"
|
||||
VITE_PUSHER_PORT="${PUSHER_PORT}"
|
||||
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
|
||||
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
|
@ -0,0 +1,11 @@
|
||||
* text=auto eol=lf
|
||||
|
||||
*.blade.php diff=html
|
||||
*.css diff=css
|
||||
*.html diff=html
|
||||
*.md diff=markdown
|
||||
*.php diff=php
|
||||
|
||||
/.github export-ignore
|
||||
CHANGELOG.md export-ignore
|
||||
.styleci.yml export-ignore
|
@ -0,0 +1,19 @@
|
||||
/.phpunit.cache
|
||||
/node_modules
|
||||
/public/build
|
||||
/public/hot
|
||||
/public/storage
|
||||
/storage/*.key
|
||||
/vendor
|
||||
.env
|
||||
.env.backup
|
||||
.env.production
|
||||
.phpunit.result.cache
|
||||
Homestead.json
|
||||
Homestead.yaml
|
||||
auth.json
|
||||
npm-debug.log
|
||||
yarn-error.log
|
||||
/.fleet
|
||||
/.idea
|
||||
/.vscode
|
@ -0,0 +1,66 @@
|
||||
<p align="center"><a href="https://laravel.com" target="_blank"><img src="https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg" width="400" alt="Laravel Logo"></a></p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://github.com/laravel/framework/actions"><img src="https://github.com/laravel/framework/workflows/tests/badge.svg" alt="Build Status"></a>
|
||||
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/dt/laravel/framework" alt="Total Downloads"></a>
|
||||
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/v/laravel/framework" alt="Latest Stable Version"></a>
|
||||
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/l/laravel/framework" alt="License"></a>
|
||||
</p>
|
||||
|
||||
## About Laravel
|
||||
|
||||
Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as:
|
||||
|
||||
- [Simple, fast routing engine](https://laravel.com/docs/routing).
|
||||
- [Powerful dependency injection container](https://laravel.com/docs/container).
|
||||
- Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage.
|
||||
- Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent).
|
||||
- Database agnostic [schema migrations](https://laravel.com/docs/migrations).
|
||||
- [Robust background job processing](https://laravel.com/docs/queues).
|
||||
- [Real-time event broadcasting](https://laravel.com/docs/broadcasting).
|
||||
|
||||
Laravel is accessible, powerful, and provides tools required for large, robust applications.
|
||||
|
||||
## Learning Laravel
|
||||
|
||||
Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework.
|
||||
|
||||
You may also try the [Laravel Bootcamp](https://bootcamp.laravel.com), where you will be guided through building a modern Laravel application from scratch.
|
||||
|
||||
If you don't feel like reading, [Laracasts](https://laracasts.com) can help. Laracasts contains thousands of video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library.
|
||||
|
||||
## Laravel Sponsors
|
||||
|
||||
We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the [Laravel Partners program](https://partners.laravel.com).
|
||||
|
||||
### Premium Partners
|
||||
|
||||
- **[Vehikl](https://vehikl.com/)**
|
||||
- **[Tighten Co.](https://tighten.co)**
|
||||
- **[WebReinvent](https://webreinvent.com/)**
|
||||
- **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)**
|
||||
- **[64 Robots](https://64robots.com)**
|
||||
- **[Curotec](https://www.curotec.com/services/technologies/laravel/)**
|
||||
- **[Cyber-Duck](https://cyber-duck.co.uk)**
|
||||
- **[DevSquad](https://devsquad.com/hire-laravel-developers)**
|
||||
- **[Jump24](https://jump24.co.uk)**
|
||||
- **[Redberry](https://redberry.international/laravel/)**
|
||||
- **[Active Logic](https://activelogic.com)**
|
||||
- **[byte5](https://byte5.de)**
|
||||
- **[OP.GG](https://op.gg)**
|
||||
|
||||
## Contributing
|
||||
|
||||
Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions).
|
||||
|
||||
## Code of Conduct
|
||||
|
||||
In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct).
|
||||
|
||||
## Security Vulnerabilities
|
||||
|
||||
If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [taylor@laravel.com](mailto:taylor@laravel.com). All security vulnerabilities will be promptly addressed.
|
||||
|
||||
## License
|
||||
|
||||
The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
|
@ -0,0 +1,20 @@
|
||||
|
||||
php artisan make:model adminUsuarios -mc
|
||||
php artisan make:model almacen -mc
|
||||
php artisan make:model bienes -mc
|
||||
php artisan make:model metas -mc
|
||||
php artisan make:model neaBienes -mc
|
||||
php artisan make:model neaEntradas -mc
|
||||
php artisan make:model obras -mc
|
||||
php artisan make:model pecosaBienes -mc
|
||||
php artisan make:model pecosaPedidos -mc
|
||||
php artisan make:model sedes -mc
|
||||
php artisan make:model trabajadores -mc
|
||||
|
||||
php artisan make:model inventarioInicial -mc
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
/**
|
||||
* Define the application's command schedule.
|
||||
*/
|
||||
protected function schedule(Schedule $schedule): void
|
||||
{
|
||||
// $schedule->command('inspire')->hourly();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the commands for the application.
|
||||
*/
|
||||
protected function commands(): void
|
||||
{
|
||||
$this->load(__DIR__.'/Commands');
|
||||
|
||||
require base_path('routes/console.php');
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Throwable;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
/**
|
||||
* The list of the inputs that are never flashed to the session on validation exceptions.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $dontFlash = [
|
||||
'current_password',
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
|
||||
/**
|
||||
* Register the exception handling callbacks for the application.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
$this->reportable(function (Throwable $e) {
|
||||
//
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AlmacenController extends Controller
|
||||
{
|
||||
//
|
||||
}
|
@ -0,0 +1,223 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Tymon\JWTAuth\Facades\JWTAuth;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
class AuthController extends Controller
|
||||
{
|
||||
|
||||
public function listEnableData(Request $request)
|
||||
{
|
||||
try {
|
||||
$data = DB::table('users')
|
||||
->where('users.status', 1)
|
||||
->get();
|
||||
|
||||
return response()->json([
|
||||
'data' => $data,
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
public function listDisableData(Request $request)
|
||||
{
|
||||
try {
|
||||
$data = DB::table('users')
|
||||
->where('users.status', 0)
|
||||
->get();
|
||||
|
||||
return response()->json([
|
||||
'data' => $data,
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function show(Request $request, $id)
|
||||
{
|
||||
try {
|
||||
$data = DB::table('users')
|
||||
->where('users.id', $id)
|
||||
->get();
|
||||
|
||||
return response()->json([
|
||||
'data' => $data,
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
public function register(Request $request)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'name' => 'required|string|max:255',
|
||||
'fullname',
|
||||
'fullname2',
|
||||
'role',
|
||||
'email' => 'required|string|email|max:255|unique:users',
|
||||
'password' => 'required|string|min:6',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json($validator->errors(), 400);
|
||||
}
|
||||
|
||||
$user = User::create([
|
||||
'name' => $request->name,
|
||||
'email' => $request->email,
|
||||
'fullname' => $request->fullname,
|
||||
'fullname2' => $request->fullname2,
|
||||
'role' => $request->role,
|
||||
'password' => Hash::make($request->password),
|
||||
]);
|
||||
|
||||
$token = JWTAuth::fromUser($user);
|
||||
|
||||
return response()->json(compact('user', 'token'), 201);
|
||||
}
|
||||
|
||||
public function updateProfile(Request $request)
|
||||
{
|
||||
$user = auth()->user(); // Obtener el usuario autenticado
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'name' => 'sometimes|string|max:255',
|
||||
'fullname' => 'sometimes|string|max:255',
|
||||
'fullname2' => 'sometimes|string|max:255',
|
||||
'email' => 'sometimes|string|email|max:255|unique:users,email,' . $user->id,
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json($validator->errors(), 422);
|
||||
}
|
||||
|
||||
$user->update($request->only(['name', 'fullname', 'fullname2', 'role', 'email']));
|
||||
|
||||
return response()->json(['message' => 'Perfil actualizado con éxito', 'user' => $user],201);
|
||||
}
|
||||
|
||||
public function updatePassword(Request $request)
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'current_password' => 'required|string',
|
||||
'new_password' => 'required|string|min:6|confirmed',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json($validator->errors(), 422);
|
||||
}
|
||||
|
||||
// Verificar si la contraseña actual es correcta
|
||||
if (!Hash::check($request->current_password, $user->password)) {
|
||||
return response()->json(['error' => 'La contraseña actual es incorrecta'], 400);
|
||||
}
|
||||
|
||||
// Actualizar la contraseña
|
||||
$user->update([
|
||||
'password' => Hash::make($request->new_password),
|
||||
]);
|
||||
|
||||
return response()->json(['message' => 'Contraseña actualizada con éxito'],201);
|
||||
}
|
||||
|
||||
|
||||
public function login(Request $request)
|
||||
{
|
||||
// Validar los datos de entrada
|
||||
$validator = Validator::make($request->all(), [
|
||||
'email' => 'required|email',
|
||||
'password' => 'required',
|
||||
]);
|
||||
|
||||
// Si la validación falla, devolver una respuesta con los errores
|
||||
if ($validator->fails()) {
|
||||
return response()->json(['error' => $validator->errors()], 422);
|
||||
}
|
||||
$credentials = $request->only('email', 'password');
|
||||
|
||||
try {
|
||||
if (!$token = JWTAuth::attempt($credentials)) {
|
||||
return response()->json(['error' => 'Credenciales incorrectas o Acceso inautorizado'], 401);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['valid' => $e->getMessage()], 401);
|
||||
}
|
||||
// Obtener el usuario autenticado
|
||||
$user = Auth::user();
|
||||
|
||||
// Verificar si el usuario tiene al menos un rol asignado
|
||||
if ($user->roles->isEmpty()) {
|
||||
return response()->json(['error' => 'No tienes un rol asignado, contacta al administrador'], 403);
|
||||
}
|
||||
|
||||
if (!$user->status) {
|
||||
return response()->json(['error' => 'Tu cuenta está desactivada, contacta al administrador'], 403);
|
||||
}
|
||||
return response()->json(compact('token'), 201);
|
||||
}
|
||||
|
||||
public function logout()
|
||||
{
|
||||
JWTAuth::invalidate(JWTAuth::getToken());
|
||||
|
||||
return response()->json(['message' => 'Successfully logged out'], 201);
|
||||
}
|
||||
|
||||
public function me(Request $request)
|
||||
{
|
||||
try {
|
||||
$user = $request->user();
|
||||
$permissions = $user->getAllPermissions()->pluck('name'); // Spatie
|
||||
|
||||
return response()->json([
|
||||
'user' => $user,
|
||||
'permissions' => $permissions,
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['valid' => false], 401);
|
||||
}
|
||||
}
|
||||
|
||||
public function verifyToken(Request $request)
|
||||
{
|
||||
try {
|
||||
// Verificar si el token es válido
|
||||
$user = JWTAuth::parseToken()->authenticate();
|
||||
return response()->json(['valid' => true, 'user' => $user]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['valid' => false], 401);
|
||||
}
|
||||
}
|
||||
|
||||
public function refreshToken(Request $request)
|
||||
{
|
||||
try {
|
||||
$refreshToken = $request->input('refresh_token');
|
||||
|
||||
// Verificar el refresh token en la base de datos
|
||||
$user = User::where('refresh_token', $refreshToken)->first();
|
||||
|
||||
if (!$user) {
|
||||
return response()->json(['error' => 'Invalid refresh token'], 401);
|
||||
}
|
||||
|
||||
// Generar un nuevo token JWT
|
||||
$token = JWTAuth::fromUser($user);
|
||||
|
||||
// Devolver el nuevo token
|
||||
return response()->json(compact('token'));
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Could not refresh token'], 500);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,272 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class BienesController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('bienes vista')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => '"Lo sentimos, pero no tiene autorización para realizar esta acción."'], 403);
|
||||
}
|
||||
try {
|
||||
$query = DB::table('bienes')
|
||||
->join('unidad_medidas as un', 'bienes.id_unidad_medida', '=', 'un.id')
|
||||
->select('bienes.*', 'un.nombre as unidad_nombre');
|
||||
|
||||
// Búsqueda dinámica
|
||||
if ($request->has('search')) {
|
||||
$search = $request->input('search');
|
||||
$query->where('bienes.codigo', 'like', "%$search%")
|
||||
->orWhere('bienes.descripcion', 'like', "%$search%")
|
||||
->orWhere('bienes.marca', 'like', "%$search%")
|
||||
->orWhere('un.nombre', 'like', "%$search%");
|
||||
}
|
||||
|
||||
// Obtener los resultados sin paginación
|
||||
$data = $query->get();
|
||||
|
||||
// Devolver la respuesta JSON con los datos
|
||||
return response()->json([
|
||||
'data' => $data,
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['valid' => false, 'error' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
// public function listEnable(Request $request)
|
||||
// {
|
||||
// try {
|
||||
// $data = DB::table('bienes')
|
||||
// ->join('unidad_medidas as un', 'bienes.id_unidad_medida', '=', 'un.id')
|
||||
// ->select('bienes.*', 'un.nombre as unidad_nombre')
|
||||
// ->where('bienes.status', 1)->get();
|
||||
|
||||
// return response()->json([
|
||||
// 'data' => $data,
|
||||
// ], 201);
|
||||
// } catch (\Exception $e) {
|
||||
// return response()->json(['valid' => false, 'error' => $e->getMessage()], 500);
|
||||
// }
|
||||
// }
|
||||
|
||||
public function listEnable(Request $request)
|
||||
{
|
||||
try {
|
||||
// $page = $request->input('page', 1); // Página actual, por defecto 1
|
||||
//it = $request->input('limit', 10); // Cantidad de registros por página
|
||||
// $offset = ($page - 1) * $limit; // Cálculo del offset
|
||||
|
||||
// Obtener los datos paginados
|
||||
$data= DB::table('bienes')
|
||||
->join('unidad_medidas as un', 'bienes.id_unidad_medida', '=', 'un.id')
|
||||
->select('bienes.*', 'un.nombre as unidad_nombre')
|
||||
->where('bienes.status', 1)
|
||||
->get();
|
||||
|
||||
///tal = $query->count(); // Obtener total de registros
|
||||
/// $data = $query->offset($offset)->limit($limit)->get(); // Obtener registros paginados
|
||||
|
||||
return response()->json([
|
||||
'data' => $data,
|
||||
//total' => $total, // Enviar total de registros
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['valid' => false, 'error' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function listEnableData(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('bienes vista')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => '"Lo sentimos, pero no tiene autorización para realizar esta acción."'], 403);
|
||||
}
|
||||
|
||||
try {
|
||||
$data = DB::table('bienes')
|
||||
->join('unidad_medidas as un', 'bienes.id_unidad_medida', '=', 'un.id')
|
||||
->select('bienes.*', 'un.nombre as unidad_nombre')
|
||||
->where('bienes.status', 1)
|
||||
->get();
|
||||
|
||||
return response()->json(['data' => $data], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['valid' => false, 'error' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function listDisableData(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('bienes vista')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => '"Lo sentimos, pero no tiene autorización para realizar esta acción."'], 403);
|
||||
}
|
||||
|
||||
try {
|
||||
$data = DB::table('bienes')
|
||||
->join('unidad_medidas as un', 'bienes.id_unidad_medida', '=', 'un.id')
|
||||
->select('bienes.*', 'un.nombre as unidad_nombre')
|
||||
->where('bienes.status', 0)->get();
|
||||
|
||||
return response()->json([
|
||||
'data' => $data,
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['valid' => false, 'error' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('bienes crear')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => '"Lo sentimos, pero no tiene autorización para realizar esta acción."'], 403);
|
||||
}
|
||||
try {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'codigo' => 'required',
|
||||
'descripcion' => 'required|string',
|
||||
'marca' => 'required|string',
|
||||
'id_unidad_medida' => 'required|string',
|
||||
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
return response()->json($validator->errors(), 422);
|
||||
}
|
||||
|
||||
DB::table('bienes')->insert([
|
||||
'id' => Str::uuid(),
|
||||
'codigo' => $request->codigo,
|
||||
'descripcion' => $request->descripcion,
|
||||
'marca' => $request->marca,
|
||||
'id_unidad_medida' => $request->id_unidad_medida,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
return response()->json(['mensaje' => 'Bien creada'], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function show(Request $request, $id)
|
||||
{
|
||||
|
||||
if (!auth()->user()->hasPermissionTo('bienes vista')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => '"Lo sentimos, pero no tiene autorización para realizar esta acción."'], 403);
|
||||
}
|
||||
//$query = DB::table('unidad_medidas')->where('id', $id)->first();
|
||||
try {
|
||||
|
||||
$query = DB::table('bienes')
|
||||
->join('unidad_medidas as un', 'bienes.id_unidad_medida', '=', 'un.id')
|
||||
->select('bienes.*', 'un.nombre as unidad_nombre')->where('bienes.id', $id)->first();
|
||||
|
||||
// Devolver la respuesta JSON con los datos
|
||||
return response()->json([
|
||||
'data' => $query,
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('bienes editar')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => '"Lo sentimos, pero no tiene autorización para realizar esta acción."'], 403);
|
||||
}
|
||||
try {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'codigo' => 'required',
|
||||
'descripcion' => 'required|string',
|
||||
'marca' => 'required|string',
|
||||
'id_unidad_medida' => 'required|string',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json($validator->errors(), 422);
|
||||
}
|
||||
|
||||
$updated = DB::table('bienes')
|
||||
->where('id', $id)
|
||||
->update([
|
||||
'codigo' => $request->codigo,
|
||||
'descripcion' => $request->descripcion,
|
||||
'marca' => $request->marca,
|
||||
'id_unidad_medida' => $request->id_unidad_medida,
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
if ($updated) {
|
||||
return response()->json(['mensaje' => 'Bien actualizada'], 201);
|
||||
} else {
|
||||
return response()->json(['mensaje' => 'Bien no encontrada'], 404);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function enable(Request $request)
|
||||
{
|
||||
//
|
||||
if (!auth()->user()->hasPermissionTo('bienes habilitar')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => '"Lo sentimos, pero no tiene autorización para realizar esta acción."'], 403);
|
||||
}
|
||||
try {
|
||||
$id = $request->input('id'); // Obtener el ID del body
|
||||
|
||||
if (!$id) {
|
||||
return response()->json(['error' => 'ID requerido'], 400);
|
||||
}
|
||||
$updated = DB::table('bienes')
|
||||
->where('id', $id)
|
||||
->update([
|
||||
'status' => 1,
|
||||
]);
|
||||
|
||||
if ($updated) {
|
||||
return response()->json(['mensaje' => 'Bien habilitado'], 201);
|
||||
} else {
|
||||
return response()->json(['mensaje' => 'Bien no encontrada'], 404);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function disable(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('bienes deshabilitar')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => '"Lo sentimos, pero no tiene autorización para realizar esta acción."'], 403);
|
||||
}
|
||||
try {
|
||||
$id = $request->input('id'); // Obtener el ID del body
|
||||
|
||||
if (!$id) {
|
||||
return response()->json(['error' => 'ID requerido'], 400);
|
||||
}
|
||||
$updated = DB::table('bienes')
|
||||
->where('id', $id)
|
||||
->update([
|
||||
'status' => 0,
|
||||
]);
|
||||
|
||||
if ($updated) {
|
||||
return response()->json(['mensaje' => 'Bien deshabilitado'], 201);
|
||||
} else {
|
||||
return response()->json(['mensaje' => 'Bien no encontrada'], 404);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, ValidatesRequests;
|
||||
}
|
@ -0,0 +1,379 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\inventarioInicial;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class InventarioInicialController extends Controller
|
||||
{
|
||||
//
|
||||
public function index(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('inventario vista')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => '"Lo sentimos, pero no tiene autorización para realizar esta acción."'], 403);
|
||||
}
|
||||
try {
|
||||
$query = DB::table('inventario_inicials')
|
||||
->select(
|
||||
'inventario_inicials.*',
|
||||
'bienes.descripcion as bien_descripcion',
|
||||
'bienes.marca',
|
||||
'unidad_medidas.nombre as unidad_medida'
|
||||
)
|
||||
->join('bienes', 'bienes.id', '=', 'inventario_inicials.bienes_id')
|
||||
->join('unidad_medidas', 'unidad_medidas.id', '=', 'bienes.id_unidad_medida');
|
||||
|
||||
if ($request->has('search')) {
|
||||
$search = $request->input('search');
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('inventario_inicials.descripcion', 'like', "%$search%")
|
||||
->orWhere('bienes.descripcion', 'like', "%$search%")
|
||||
->orWhere('bienes.marca', 'like', "%$search%")
|
||||
->orWhere('unidad_medidas.nombre', 'like', "%$search%")
|
||||
->orWhere('inventario_inicials.id', 'like', "%$search%");
|
||||
});
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'data' => $query->get(),
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['valid' => $e], 401);
|
||||
}
|
||||
}
|
||||
|
||||
public function generarReporteInventario(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('inventario reporte')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Usted no está autorizado'], 403);
|
||||
}
|
||||
ini_set('memory_limit', '512M');
|
||||
|
||||
// $request->validate([
|
||||
// 'fecha_desde' => 'required|date',
|
||||
// 'fecha_hasta' => 'required|date|after_or_equal:fecha_desde',
|
||||
// ]);
|
||||
try {
|
||||
|
||||
|
||||
// $añoDesde = Carbon::parse($request->input('fecha_desde'))->year;
|
||||
// $añoHasta = Carbon::parse($request->input('fecha_hasta'))->year;
|
||||
|
||||
// Filtrar registros por rango de fechas
|
||||
$registros = DB::table('inventario_inicials')
|
||||
->select(
|
||||
'inventario_inicials.*',
|
||||
'bienes.codigo as bien_codigo',
|
||||
'bienes.descripcion as bien_descripcion',
|
||||
'bienes.marca',
|
||||
'inventario_inicials.cuenta',
|
||||
'unidad_medidas.nombre as unidad_medida',
|
||||
DB::raw('ROUND(inventario_inicials.cantidad, 4) as cantidad'),
|
||||
DB::raw('ROUND(inventario_inicials.precio, 4) as precio'),
|
||||
DB::raw('ROUND(inventario_inicials.cantidad * inventario_inicials.precio, 4) as valor_total')
|
||||
)
|
||||
->join('bienes', 'bienes.id', '=', 'inventario_inicials.bienes_id')
|
||||
->join('unidad_medidas', 'unidad_medidas.id', '=', 'bienes.id_unidad_medida')
|
||||
->orderBy('bienes.descripcion', 'asc')
|
||||
->get();
|
||||
// Generar PDF con MPDF
|
||||
$mpdf = new \Mpdf\Mpdf([
|
||||
'mode' => 'utf-8',
|
||||
'format' => 'A4-P',
|
||||
'margin_left' => 8,
|
||||
'margin_right' => 8,
|
||||
'margin_top' => 45,
|
||||
'margin_bottom' => 35,
|
||||
]);
|
||||
|
||||
$imgLogo = public_path('assets/images/UNAP.png');
|
||||
$htmlHeader = view('reporteInventario._header', compact('imgLogo'))->render();
|
||||
$mpdf->SetHTMLHeader($htmlHeader, '0');
|
||||
$htmlFooter = view('reporteInventario._footer')->render();
|
||||
$mpdf->SetHTMLFooter($htmlFooter, '0');
|
||||
// Renderizar la vista de PDF
|
||||
// Renderizar la vista en partes más pequeñas
|
||||
$html = view('reporteInventario.index', compact('registros'))->render();
|
||||
|
||||
// Dividir en partes y escribir por fragmentos
|
||||
$chunks = str_split($html, 25000); // Dividir cada 50,000 caracteres
|
||||
|
||||
foreach ($chunks as $chunk) {
|
||||
$mpdf->WriteHTML($chunk);
|
||||
}
|
||||
|
||||
return response()->streamDownload(function () use ($mpdf) {
|
||||
$mpdf->Output('reporte_inventario_inicial.pdf', 'D'); // 'D' fuerza la descarga
|
||||
}, 'reporte_inventario_inicial.pdf');
|
||||
} catch (\Exception $e) { // Especifica el tipo de excepción si es necesario
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function listEnable()
|
||||
{
|
||||
try {
|
||||
$data = DB::table('inventario_inicials')
|
||||
->select(
|
||||
'inventario_inicials.*',
|
||||
'bienes.descripcion as bien_descripcion',
|
||||
'bienes.marca',
|
||||
'unidad_medidas.nombre as unidad_medida'
|
||||
)
|
||||
->join('bienes', 'bienes.id', '=', 'inventario_inicials.bienes_id')
|
||||
->join('unidad_medidas', 'unidad_medidas.id', '=', 'bienes.id_unidad_medida')
|
||||
->where('inventario_inicials.status', 1)->get();
|
||||
// $data = DB::table('inventario_inicials')->where('status', 1)->get();
|
||||
return response()->json(['data' => $data], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['valid' => $e], 500);
|
||||
}
|
||||
}
|
||||
public function listEnableData()
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('inventario vista')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => '"Lo sentimos, pero no tiene autorización para realizar esta acción."'], 403);
|
||||
}
|
||||
try {
|
||||
$data = DB::table('inventario_inicials')
|
||||
->select(
|
||||
'inventario_inicials.*',
|
||||
'bienes.descripcion as bien_descripcion',
|
||||
'bienes.marca',
|
||||
'unidad_medidas.nombre as unidad_medida'
|
||||
)
|
||||
->join('bienes', 'bienes.id', '=', 'inventario_inicials.bienes_id')
|
||||
->join('unidad_medidas', 'unidad_medidas.id', '=', 'bienes.id_unidad_medida')
|
||||
->where('inventario_inicials.status', 1)->get();
|
||||
// $data = DB::table('inventario_inicials')->where('status', 1)->get();
|
||||
return response()->json(['data' => $data], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['valid' => $e], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function listDisableData()
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('inventario vista')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => '"Lo sentimos, pero no tiene autorización para realizar esta acción."'], 403);
|
||||
}
|
||||
try {
|
||||
$data = DB::table('inventario_inicials')
|
||||
->select(
|
||||
'inventario_inicials.*',
|
||||
'bienes.descripcion as bien_descripcion',
|
||||
'bienes.marca',
|
||||
'unidad_medidas.nombre as unidad_medida'
|
||||
)
|
||||
->join('bienes', 'bienes.id', '=', 'inventario_inicials.bienes_id')
|
||||
->join('unidad_medidas', 'unidad_medidas.id', '=', 'bienes.id_unidad_medida')
|
||||
->where('inventario_inicials.status', 0)->get();
|
||||
return response()->json(['data' => $data], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['valid' => false], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function listInventarioBienes()
|
||||
{
|
||||
try {
|
||||
$query = DB::table('inventario_inicials')
|
||||
->join('bienes as b', 'b.id', '=', 'inventario_inicials.bienes_id')
|
||||
->join('unidad_medidas as m', 'm.id', '=', 'b.id_unidad_medida')
|
||||
->select('inventario_inicials.*', 'b.descripcion','m.nombre as nombre_medida')
|
||||
->get(); // Usa first() si solo esperas un resultado
|
||||
|
||||
return response()->json(['data' => $query], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => $e], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function listInventarioBienesConStock()
|
||||
{
|
||||
try {
|
||||
$query = DB::table('inventario_inicials')
|
||||
->join('bienes as b', 'b.id', '=', 'inventario_inicials.bienes_id')
|
||||
->join('unidad_medidas as m', 'm.id', '=', 'b.id_unidad_medida')
|
||||
->select('inventario_inicials.*', 'b.descripcion','m.nombre as nombre_medida')
|
||||
->where('inventario_inicials.status', 1)
|
||||
->where('inventario_inicials.cantidad','>', 0)
|
||||
->get(); // Usa first() si solo esperas un resultado
|
||||
|
||||
return response()->json(['data' => $query], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => $e], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('inventario crear')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
try {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'descripcion' => 'nullable|string',
|
||||
'bienes_id' => 'required|string',
|
||||
'cuenta' => 'required|string|regex:/^\d{10}$/',
|
||||
'cantidad' => 'required|numeric',
|
||||
'cantidad_inicial' => 'required|numeric',
|
||||
'precio' => 'required|numeric',
|
||||
'fecha_registro' => 'required|string',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json($validator->errors(), 422);
|
||||
}
|
||||
|
||||
DB::table('inventario_inicials')->insert([
|
||||
'id' => Str::uuid(),
|
||||
'descripcion' => $request->descripcion,
|
||||
'bienes_id' => $request->bienes_id,
|
||||
'cuenta' => $request->cuenta,
|
||||
'cantidad' => $request->cantidad,
|
||||
'cantidad_inicial' => $request->cantidad_inicial,
|
||||
'precio' => $request->precio,
|
||||
'fecha_registro' => $request->fecha_registro,
|
||||
'status' => 1,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
return response()->json(['mensaje' => 'Inventario inicial creado'], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('inventario vista')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => '"Lo sentimos, pero no tiene autorización para realizar esta acción."'], 403);
|
||||
}
|
||||
try {
|
||||
$data = DB::table('inventario_inicials')
|
||||
->select(
|
||||
'inventario_inicials.*',
|
||||
'bienes.descripcion as bien_descripcion',
|
||||
'bienes.marca',
|
||||
'unidad_medidas.nombre as unidad_medida'
|
||||
)
|
||||
->join('bienes', 'bienes.id', '=', 'inventario_inicials.bienes_id')
|
||||
->join('unidad_medidas', 'unidad_medidas.id', '=', 'bienes.id_unidad_medida')
|
||||
->where('inventario_inicials.id', $id)
|
||||
->first();
|
||||
|
||||
return response()->json(['data' => $data], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('inventario editar')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => '"Lo sentimos, pero no tiene autorización para realizar esta acción."'], 403);
|
||||
}
|
||||
try {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'descripcion' => 'nullable|string',
|
||||
// 'bienes_id' => 'nullable|string', // no lo requerimos por que no queremos actualizarlo
|
||||
'cuenta' => 'required|string|regex:/^\d{10}$/',
|
||||
'cantidad' => 'required|numeric',
|
||||
'cantidad_inicial' => 'required|numeric',
|
||||
'precio' => 'required|numeric',
|
||||
'fecha_registro' => 'required|string',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json($validator->errors(), 422);
|
||||
}
|
||||
|
||||
$updated = DB::table('inventario_inicials')
|
||||
->where('id', $id)
|
||||
->update([
|
||||
'descripcion' => $request->descripcion,
|
||||
// 'bienes_id' => $request->bienes_id, //para no cambiar el item ya seleccionado
|
||||
'cuenta' => $request->cuenta,
|
||||
'cantidad' => $request->cantidad,
|
||||
'cantidad_inicial' => $request->cantidad_inicial,
|
||||
'precio' => $request->precio,
|
||||
'fecha_registro' => $request->fecha_registro,
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
if ($updated) {
|
||||
return response()->json(['mensaje' => 'Inventario inicial actualizado'], 201);
|
||||
} else {
|
||||
return response()->json(['mensaje' => 'Inventario inicial no encontrado'], 404);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function disable(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('inventario deshabilitar')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => '"Lo sentimos, pero no tiene autorización para realizar esta acción."'], 403);
|
||||
}
|
||||
$id = $request->input('id'); // Obtener el ID del body
|
||||
|
||||
if (!$id) {
|
||||
return response()->json(['error' => 'ID requerido'], 400);
|
||||
}
|
||||
|
||||
try {
|
||||
$updated = DB::table('inventario_inicials')
|
||||
->where('id', $id)
|
||||
->update(['status' => 0]);
|
||||
|
||||
if ($updated) {
|
||||
return response()->json(['mensaje' => 'Inventario inicial deshabilitado'], 201);
|
||||
} else {
|
||||
return response()->json(['mensaje' => 'Inventario inicial no encontrado'], 404);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
public function enable(Request $request)
|
||||
{
|
||||
|
||||
if (!auth()->user()->hasPermissionTo('inventario habilitar')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => '"Lo sentimos, pero no tiene autorización para realizar esta acción."'], 403);
|
||||
}
|
||||
$id = $request->input('id'); // Obtener el ID del body
|
||||
|
||||
if (!$id) {
|
||||
return response()->json(['error' => 'ID requerido'], 400);
|
||||
}
|
||||
|
||||
try {
|
||||
$updated = DB::table('inventario_inicials')
|
||||
->where('id', $id)
|
||||
->update(['status' => 1]);
|
||||
|
||||
if ($updated) {
|
||||
return response()->json(['mensaje' => 'Inventario inicial habilitado'], 201);
|
||||
} else {
|
||||
return response()->json(['mensaje' => 'Inventario inicial no encontrado'], 404);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,242 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
class MetasController extends Controller
|
||||
{
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('metas vista')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
try {
|
||||
$query = DB::table('metas')
|
||||
->select('id', 'meta_1', 'meta_2', 'obra');
|
||||
|
||||
// Búsqueda dinámica
|
||||
if ($request->has('search')) {
|
||||
$search = $request->input('search');
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('meta_1', 'like', "%{$search}%")
|
||||
->orWhere('meta_2', 'like', "%{$search}%")
|
||||
->orWhere('obra', 'like', "%{$search}%");
|
||||
});
|
||||
}
|
||||
|
||||
// Obtener los resultados sin paginación
|
||||
$data = $query->get();
|
||||
|
||||
// Devolver la respuesta JSON con los datos
|
||||
return response()->json([
|
||||
'data' => $data,
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error en el servidor'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function listEnable(Request $request)
|
||||
{
|
||||
try {
|
||||
$data = DB::table('metas')
|
||||
->where('metas.status', 1)
|
||||
->get();
|
||||
|
||||
return response()->json([
|
||||
'data' => $data,
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function listEnableData(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('metas vista')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
try {
|
||||
$data = DB::table('metas')
|
||||
->where('metas.status', 1)
|
||||
->get();
|
||||
|
||||
return response()->json([
|
||||
'data' => $data,
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
public function listDisableData(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('metas vista')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
|
||||
try {
|
||||
$data = DB::table('metas')
|
||||
->where('metas.status', 0)
|
||||
->get();
|
||||
|
||||
return response()->json([
|
||||
'data' => $data,
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('metas crear')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
try {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'meta_1' => '',
|
||||
'meta_2' => '',
|
||||
'obra' => 'required|string',
|
||||
'residente' => '',
|
||||
'almacenario' => '',
|
||||
'asistente_administativo' => '',
|
||||
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
return response()->json($validator->errors(), 422);
|
||||
}
|
||||
|
||||
DB::table('metas')->insert([
|
||||
'id' => Str::uuid(),
|
||||
'meta_1' => $request->meta_1,
|
||||
'meta_2' => $request->meta_2,
|
||||
'obra' => $request->obra,
|
||||
'residente' => $request->residente,
|
||||
'almacenario' => $request->almacenario,
|
||||
'asistente_administativo' => $request->asistente_administativo,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
return response()->json(['mensaje' => 'metas creada'], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function show(Request $request, $id)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('metas vista')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
try {
|
||||
$data = DB::table('metas')
|
||||
->where('metas.id', $id)
|
||||
->first();
|
||||
|
||||
return response()->json([
|
||||
'data' => $data,
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('metas editar')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
try {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'meta_1' => 'required',
|
||||
'meta_2' => 'required|string',
|
||||
'obra' => 'required|string',
|
||||
'residente' => 'required|string',
|
||||
'almacenario' => 'required|string',
|
||||
'asistente_administativo' => 'required|string',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json($validator->errors(), 422);
|
||||
}
|
||||
|
||||
$updated = DB::table('metas')
|
||||
->where('id', $id)
|
||||
->update([
|
||||
'meta_1' => $request->meta_1,
|
||||
'meta_2' => $request->meta_2,
|
||||
'obra' => $request->obra,
|
||||
'residente' => $request->residente,
|
||||
'almacenario' => $request->almacenario,
|
||||
'asistente_administativo' => $request->asistente_administativo,
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
if ($updated) {
|
||||
return response()->json(['mensaje' => 'metas actualizada'], 201);
|
||||
} else {
|
||||
return response()->json(['mensaje' => 'metas no encontrada'], 404);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function enable(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('metas habilitar')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
$id = $request->input('id'); // Obtener el ID del body
|
||||
|
||||
if (!$id) {
|
||||
return response()->json(['error' => 'ID requerido'], 400);
|
||||
}
|
||||
|
||||
try {
|
||||
$updated = DB::table('metas')
|
||||
->where('id', $id)
|
||||
->update(['status' => 1]);
|
||||
|
||||
if ($updated) {
|
||||
return response()->json(['mensaje' => 'metas Habilitado'], 201);
|
||||
} else {
|
||||
return response()->json(['mensaje' => 'metas no encontrada'], 404);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
public function disable(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('metas deshabilitar')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
$id = $request->input('id'); // Obtener el ID del body
|
||||
|
||||
if (!$id) {
|
||||
return response()->json(['error' => 'ID requerido'], 400);
|
||||
}
|
||||
|
||||
try {
|
||||
$updated = DB::table('metas')
|
||||
->where('id', $id)
|
||||
->update(['status' => 0]);
|
||||
|
||||
if ($updated) {
|
||||
return response()->json(['mensaje' => 'metas deshabilitada'], 201);
|
||||
} else {
|
||||
return response()->json(['mensaje' => 'metas no encontrada'], 404);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class NeaBienes2023Controller extends Controller
|
||||
{
|
||||
//
|
||||
}
|
@ -0,0 +1,387 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\neaBienes;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class NeaBienesController extends Controller
|
||||
{
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
try {
|
||||
|
||||
// $query = DB::table('nea_bienes');
|
||||
$query = DB::table('nea_bienes')
|
||||
->join('bienes as bien', 'nea_bienes.bienes_id', '=', 'bien.id')
|
||||
->select('nea_bienes.*', 'bien.descripcion as bienes');
|
||||
|
||||
// Búsqueda dinámica
|
||||
if ($request->has('search')) {
|
||||
$search = $request->input('search');
|
||||
$query->where('nea_bienes.fecha_registro', 'like', "%$search%")
|
||||
->orWhere('nea_bienes.cuenta_contable', 'like', "%$search%")
|
||||
->orWhere('nea_bienes.precio', 'like', "%$search%");
|
||||
}
|
||||
|
||||
|
||||
// Obtener los resultados sin paginación
|
||||
$data = $query->get();
|
||||
|
||||
// Devolver la respuesta JSON con los datos
|
||||
return response()->json([
|
||||
'data' => $data,
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['valid' => false], 401);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store_uno(Request $request)
|
||||
{
|
||||
try {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'nea_entradas_id' => 'required|string',
|
||||
'bienes_id' => 'required|string',
|
||||
'cantidad_inicial' => 'required',
|
||||
'cantidad' => 'required',
|
||||
'id_unidad_medida' => 'required',
|
||||
'fte_fto' => 'required',
|
||||
'precio' => 'required',
|
||||
'cuenta_contable' => 'required',
|
||||
'fecha_registro' => 'required',
|
||||
// 'status' => 'required',
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
return response()->json($validator->errors(), 422);
|
||||
}
|
||||
|
||||
DB::table('obras')->insert([
|
||||
'id' => Str::uuid(),
|
||||
'nea_entradas_id' => $request->nea_entradas_id,
|
||||
'bienes_id' => $request->bienes_id,
|
||||
'cantidad_inicial' => $request->cantidad_inicial,
|
||||
'cantidad' => $request->cantidad,
|
||||
'id_unidad_medida' => $request->id_unidad_medida,
|
||||
'fte_fto' => $request->fte_fto,
|
||||
'precio' => $request->precio,
|
||||
'cuenta_contable' => $request->cuenta_contable,
|
||||
'fecha_registro' => $request->fecha_registro,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
return response()->json(['mensaje' => 'nea bienes creado'], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function store(Request $request) //store multiple
|
||||
{
|
||||
|
||||
if (!auth()->user()->hasPermissionTo('neas agregar bienes')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
try {
|
||||
// Definir las reglas de validación
|
||||
$rules = [
|
||||
'registros' => 'required|array',
|
||||
'registros.*.nea_entradas_id' => 'required',
|
||||
'registros.*.bienes_id' => 'required',
|
||||
'registros.*.cantidad_inicial' => 'required|numeric',
|
||||
'registros.*.cantidad' => 'required|numeric',
|
||||
'registros.*.id_unidad_medida' => 'required',
|
||||
'registros.*.fte_fto' => 'required',
|
||||
'registros.*.precio' => 'required|numeric',
|
||||
'registros.*.cuenta_contable' => 'required',
|
||||
'registros.*.fecha_registro' => 'required|date',
|
||||
];
|
||||
|
||||
// Mensajes personalizados para los errores de validación
|
||||
$messages = [
|
||||
'registros.required' => 'El campo registros es obligatorio.',
|
||||
'registros.array' => 'El campo registros debe ser un arreglo.',
|
||||
'registros.*.nea_entradas_id.required' => 'El campo nea_entradas_id es obligatorio.',
|
||||
'registros.*.bienes_id.required' => 'El campo bienes_id es obligatorio.',
|
||||
'registros.*.cantidad_inicial.required' => 'El campo cantidad_inicial es obligatorio.',
|
||||
'registros.*.cantidad.required' => 'El campo cantidad es obligatorio.',
|
||||
'registros.*.id_unidad_medida.required' => 'El campo id_unidad_medida es obligatorio.',
|
||||
'registros.*.fte_fto.required' => 'El campo fte_fto es obligatorio.',
|
||||
'registros.*.precio.required' => 'El campo precio es obligatorio.',
|
||||
'registros.*.cuenta_contable.required' => 'El campo cuenta_contable es obligatorio.',
|
||||
'registros.*.fecha_registro.required' => 'El campo fecha_registro es obligatorio.',
|
||||
];
|
||||
|
||||
// Validar los datos
|
||||
$validator = Validator::make($request->all(), $rules, $messages);
|
||||
|
||||
// Si la validación falla, devolver los errores
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Errores de validación',
|
||||
'errors' => $validator->errors()
|
||||
], 422); // Código HTTP 422 para errores de validación
|
||||
}
|
||||
|
||||
// Obtener los datos validados
|
||||
$data = $validator->validated();
|
||||
|
||||
// Agregar UUID a cada registro antes de insertarlo
|
||||
foreach ($data['registros'] as &$registro) {
|
||||
$registro['id'] = (string) Str::uuid();
|
||||
}
|
||||
|
||||
// Insertar los registros en la base de datos
|
||||
neaBienes::insert($data['registros']);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Registros guardados correctamente'
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
// Manejar excepciones generales
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Error en el servidor',
|
||||
'error' => $e->getMessage() // Devuelve el mensaje de la excepción
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(Request $request, $id)
|
||||
{
|
||||
//$query = DB::table('unidad_medidas')->where('id', $id)->first();
|
||||
try {
|
||||
|
||||
$query = DB::table('nea_bienes')->where('id', $id)->first();
|
||||
|
||||
// Devolver la respuesta JSON con los datos
|
||||
return response()->json([
|
||||
'data' => $query,
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function showBienesEntrada(Request $request, $id)
|
||||
{
|
||||
try {
|
||||
$query = DB::table('nea_entradas')
|
||||
->join('nea_bienes', 'nea_bienes.nea_entradas_id', '=', 'nea_entradas.id')
|
||||
->join('bienes', 'bienes.id', '=', 'nea_bienes.bienes_id')
|
||||
->select(
|
||||
'bienes.descripcion',
|
||||
'nea_bienes.*',
|
||||
'nea_bienes.id_unidad_medida as medida_salida',
|
||||
DB::raw("DATE_FORMAT(nea_bienes.fecha_registro, '%Y-%m-%d') as fecha_registro"),
|
||||
'nea_entradas.codigo',
|
||||
'nea_entradas.oficio',
|
||||
'nea_entradas.documento'
|
||||
)
|
||||
->where('nea_entradas.id', $id)
|
||||
->get(); // O usa first() si solo esperas un resultado
|
||||
|
||||
|
||||
return response()->json(['data' => $query], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function showBienesEntradaEnable(Request $request, $id)
|
||||
{
|
||||
try {
|
||||
$query = DB::table('nea_entradas')
|
||||
->join('nea_bienes', 'nea_bienes.nea_entradas_id', '=', 'nea_entradas.id')
|
||||
->join('bienes', 'bienes.id', '=', 'nea_bienes.bienes_id')
|
||||
->select(
|
||||
'bienes.descripcion',
|
||||
'nea_bienes.*',
|
||||
'nea_bienes.id_unidad_medida as medida_salida',
|
||||
DB::raw("DATE_FORMAT(nea_bienes.fecha_registro, '%Y-%m-%d') as fecha_registro"),
|
||||
'nea_entradas.codigo',
|
||||
'nea_entradas.oficio',
|
||||
'nea_entradas.documento'
|
||||
)
|
||||
->where('nea_entradas.id', $id)
|
||||
->where('nea_bienes.status', 1)
|
||||
->get(); // O usa first() si solo esperas un resultado
|
||||
|
||||
|
||||
return response()->json(['data' => $query], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function listEntradasBienes()
|
||||
{
|
||||
try {
|
||||
$query = DB::table('nea_bienes')
|
||||
->join('bienes as b', 'b.id', '=', 'nea_bienes.bienes_id')
|
||||
->join('nea_entradas as ne', 'ne.id', '=', 'nea_bienes.nea_entradas_id')
|
||||
->join('unidad_medidas as m', 'm.id', '=', 'nea_bienes.id_unidad_medida')
|
||||
->select('nea_bienes.*', 'b.descripcion','b.codigo as codigo_bien', 'ne.codigo', 'm.nombre as nombre_medida')
|
||||
->get(); // Usa first() si solo esperas un resultado
|
||||
|
||||
return response()->json(['data' => $query], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function listEntradasBienesConStock()
|
||||
{
|
||||
try {
|
||||
$query = DB::table('nea_bienes')
|
||||
->join('bienes as b', 'b.id', '=', 'nea_bienes.bienes_id')
|
||||
->join('nea_entradas as ne', 'ne.id', '=', 'nea_bienes.nea_entradas_id')
|
||||
->join('unidad_medidas as m', 'm.id', '=', 'nea_bienes.id_unidad_medida')
|
||||
->select('nea_bienes.*', 'b.descripcion','b.codigo as codigo_bien', 'ne.codigo', 'm.nombre as nombre_medida')
|
||||
->where('nea_bienes.status', 1)
|
||||
->where('nea_bienes.cantidad', '>', 0)
|
||||
->get(); // Usa first() si solo esperas un resultado
|
||||
|
||||
return response()->json(['data' => $query], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('neas actualizar bienes')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
try {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'nea_entradas_id' => 'required|string',
|
||||
'bienes_id' => 'required|string',
|
||||
'cantidad_inicial' => 'required',
|
||||
'cantidad' => 'required',
|
||||
'id_unidad_medida' => 'required',
|
||||
'fte_fto' => 'required',
|
||||
'precio' => 'required',
|
||||
'cuenta_contable' => 'required',
|
||||
'fecha_registro' => 'required',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json($validator->errors(), 422);
|
||||
}
|
||||
|
||||
$updated = DB::table('nea_bienes')
|
||||
->where('id', $id)
|
||||
->update([
|
||||
'nea_entradas_id' => $request->nea_entradas_id,
|
||||
'bienes_id' => $request->bienes_id,
|
||||
'cantidad_inicial' => $request->cantidad_inicial,
|
||||
'cantidad' => $request->cantidad,
|
||||
'id_unidad_medida' => $request->id_unidad_medida,
|
||||
'fte_fto' => $request->fte_fto,
|
||||
'precio' => $request->precio,
|
||||
'cuenta_contable' => $request->cuenta_contable,
|
||||
'fecha_registro' => $request->fecha_registro,
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
if ($updated) {
|
||||
return response()->json(['mensaje' => 'Nea bienes actualizado'], 201);
|
||||
} else {
|
||||
return response()->json(['mensaje' => 'Nea bienes no encontradao'], 404);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(neaBienes $obras): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function enable(Request $request)
|
||||
{
|
||||
$id = $request->input('id'); // Obtener el ID del body
|
||||
try {
|
||||
|
||||
$updated = DB::table('nea_bienes')
|
||||
->where('id', $id)
|
||||
->update([
|
||||
'status' => 1,
|
||||
]);
|
||||
|
||||
if ($updated) {
|
||||
return response()->json(['mensaje' => 'Nea bienes actualizado'], 201);
|
||||
} else {
|
||||
return response()->json(['mensaje' => 'Nea bienes no encontrado'], 404);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
public function disable(Request $request)
|
||||
{
|
||||
$id = $request->input('id'); // Obtener el ID del body
|
||||
|
||||
try {
|
||||
|
||||
$updated = DB::table('nea_bienes')
|
||||
->where('id', $id)
|
||||
->update([
|
||||
'status' => 0,
|
||||
]);
|
||||
|
||||
if ($updated) {
|
||||
return response()->json(['mensaje' => 'Nea bienes actualizado'], 201);
|
||||
} else {
|
||||
return response()->json(['mensaje' => 'Nea bienes no encontrado G'], 404);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// $updated = DB::table('nea_bienes')
|
||||
// ->where('id', $id)
|
||||
// ->update([
|
||||
// 'status' => 0,
|
||||
// ]);
|
||||
// $updated = DB::table('nea_bienes');
|
||||
|
||||
// $idPecosaultimoRegistro = DB::table('pecosa_bienes')
|
||||
// ->where('nea_bien_id', $id)
|
||||
// ->orderBy('created_at', 'desc')
|
||||
// ->first();
|
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class NeaEntradas2023Controller extends Controller
|
||||
{
|
||||
//
|
||||
}
|
@ -0,0 +1,409 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\neaEntradas;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class NeaEntradasController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('neas vista')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
try {
|
||||
|
||||
|
||||
// $query = DB::table('nea_entradas');
|
||||
$query = DB::table('nea_entradas')
|
||||
->join('metas as met', 'nea_entradas.id_meta', '=', 'met.id')
|
||||
->join('trabajadores as trab', 'nea_entradas.id_trabajadores', '=', 'trab.id')
|
||||
->select('nea_entradas.*', 'met.obra as metas', 'trab.nombre as trabajador');
|
||||
|
||||
// Búsqueda dinámica
|
||||
if ($request->has('search')) {
|
||||
$search = $request->input('search');
|
||||
$query->where('nea_entradas.codigo', 'like', "%$search%")
|
||||
->orWhere('nea_entradas.tipo_de_sede', 'like', "%$search%")
|
||||
->orWhere('nea_entradas.tipo_de_ingreso', 'like', "%$search%")
|
||||
->orWhere('nea_entradas.recibido_por', 'like', "%$search%");
|
||||
}
|
||||
|
||||
|
||||
// Obtener los resultados sin paginación
|
||||
$data = $query->get();
|
||||
|
||||
// Devolver la respuesta JSON con los datos
|
||||
return response()->json([
|
||||
'data' => $data,
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['valid' => false], 401);
|
||||
}
|
||||
}
|
||||
|
||||
public function listEnable()
|
||||
{
|
||||
try {
|
||||
// $query = DB::table('nea_entradas');
|
||||
$data = DB::table('nea_entradas')
|
||||
->join('metas as met', 'nea_entradas.id_meta', '=', 'met.id')
|
||||
->join('trabajadores as trab', 'nea_entradas.id_trabajadores', '=', 'trab.id')
|
||||
->select('nea_entradas.*', 'met.obra as metas', 'trab.nombre as trabajador')
|
||||
->orderBy('nea_entradas.fecha_de_nea', 'desc') // Agrega orden si aplica
|
||||
->where('nea_entradas.status', 1)->get();
|
||||
|
||||
// Devolver la respuesta JSON con los datos
|
||||
return response()->json([
|
||||
'data' => $data,
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
public function listEnableData()
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('neas vista')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
try {
|
||||
// $query = DB::table('nea_entradas');
|
||||
$data = DB::table('nea_entradas')
|
||||
->join('metas as met', 'nea_entradas.id_meta', '=', 'met.id')
|
||||
->join('trabajadores as trab', 'nea_entradas.id_trabajadores', '=', 'trab.id')
|
||||
->select('nea_entradas.*', 'met.obra as metas', 'trab.nombre as trabajador')
|
||||
->orderBy('nea_entradas.fecha_de_nea', 'desc') // Agrega orden si aplica
|
||||
->where('nea_entradas.status', 1)->get();
|
||||
|
||||
// Devolver la respuesta JSON con los datos
|
||||
return response()->json([
|
||||
'data' => $data,
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
public function listDisableData()
|
||||
{
|
||||
|
||||
if (!auth()->user()->hasPermissionTo('neas vista')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
try {
|
||||
|
||||
// $query = DB::table('nea_entradas');
|
||||
$data = DB::table('nea_entradas')
|
||||
->join('metas as met', 'nea_entradas.id_meta', '=', 'met.id')
|
||||
->join('trabajadores as trab', 'nea_entradas.id_trabajadores', '=', 'trab.id')
|
||||
->select('nea_entradas.*', 'met.obra as metas', 'trab.nombre as trabajador')
|
||||
->orderBy('nea_entradas.fecha_de_nea', 'desc') // Agrega orden si aplica
|
||||
->where('nea_entradas.status', 0)->get();
|
||||
|
||||
// Devolver la respuesta JSON con los datos
|
||||
return response()->json([
|
||||
'data' => $data,
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('neas crear')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
try {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'id_trabajadores' => 'required',
|
||||
'tipo_de_sede' => 'required',
|
||||
'tipo_de_ingreso' => 'required',
|
||||
'recibido_por' => 'required',
|
||||
'id_meta' => 'required',
|
||||
'tipo_de_moneda' => 'required',
|
||||
'tipo_de_almacen' => 'required',
|
||||
'documento' => 'required',
|
||||
'tipo_de_cambio' => 'required',
|
||||
'tipo_de_uso' => 'required',
|
||||
'oficio' => 'required',
|
||||
'fecha_de_nea' => 'required',
|
||||
'fecha_de_registro' => 'required',
|
||||
// 'status' => 'required',
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
return response()->json($validator->errors(), 422);
|
||||
}
|
||||
|
||||
$year = date('Y');
|
||||
// Buscar el último código del año actual
|
||||
$ultimoCodigo = DB::table('nea_entradas')
|
||||
->where('codigo', 'like', "%-$year")
|
||||
->orderByDesc('codigo')
|
||||
->first();
|
||||
if ($ultimoCodigo) {
|
||||
// Extraer el número y sumarle 1
|
||||
$ultimoNumero = intval(explode('-', $ultimoCodigo->codigo)[0]);
|
||||
$nuevoNumero = str_pad($ultimoNumero + 1, 4, '0', STR_PAD_LEFT);
|
||||
} else {
|
||||
// Si no hay registros en el año, empezar desde 0001
|
||||
$nuevoNumero = '0001';
|
||||
}
|
||||
$codigo = "$nuevoNumero-$year";
|
||||
|
||||
DB::table('nea_entradas')->insert([
|
||||
'id' => Str::uuid(),
|
||||
'codigo' => $codigo,
|
||||
'id_trabajadores' => $request->id_trabajadores,
|
||||
'tipo_de_sede' => $request->tipo_de_sede,
|
||||
'tipo_de_ingreso' => $request->tipo_de_ingreso,
|
||||
'recibido_por' => $request->recibido_por,
|
||||
'id_meta' => $request->id_meta,
|
||||
'tipo_de_moneda' => $request->tipo_de_moneda,
|
||||
'tipo_de_almacen' => $request->tipo_de_almacen,
|
||||
'documento' => $request->documento,
|
||||
'tipo_de_cambio' => $request->tipo_de_cambio,
|
||||
'tipo_de_uso' => $request->tipo_de_uso,
|
||||
'oficio' => $request->oficio,
|
||||
'fecha_de_nea' => $request->fecha_de_nea,
|
||||
'fecha_de_registro' => $request->fecha_de_registro,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
return response()->json(['mensaje' => 'nea entradas creado'], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => $e], 500);
|
||||
}
|
||||
}
|
||||
|
||||
// public function store(Request $request)
|
||||
// {
|
||||
// $data = $request->validate([
|
||||
// 'registros' => 'required|array',
|
||||
// 'registros.*.codigo' => 'required',
|
||||
// 'registros.*.id_trabajadores' => 'required',
|
||||
// 'registros.*.tipo_de_sede' => 'required',
|
||||
// 'registros.*.tipo_de_ingreso' => 'required',
|
||||
// 'registros.*.recibido_por' => 'required',
|
||||
// 'registros.*.id_meta' => 'required',
|
||||
// 'registros.*.tipo_de_moneda' => 'required',
|
||||
// 'registros.*.tipo_de_almacen' => 'required',
|
||||
// 'registros.*.documento' => 'required',
|
||||
// 'registros.*.tipo_de_cambio' => 'required',
|
||||
// 'registros.*.tipo_de_uso' => 'required',
|
||||
// 'registros.*.oficio' => 'required',
|
||||
// 'registros.*.fecha_de_nea' => 'required',
|
||||
// 'registros.*.fecha_de_registro' => 'required',
|
||||
|
||||
|
||||
// ]);
|
||||
|
||||
// // Agregar UUID a cada registro antes de insertarlo
|
||||
// foreach ($data['registros'] as &$registro) {
|
||||
// $registro['id'] = (string) Str::uuid();
|
||||
// }
|
||||
|
||||
// // Insertar los registros en la base de datos
|
||||
// neaEntradas::insert($data['registros']);
|
||||
|
||||
// return response()->json(['message' => 'Registros guardados correctamente'], 201);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(Request $request, $id)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('neas vista')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
//$query = DB::table('unidad_medidas')->where('id', $id)->first();
|
||||
try {
|
||||
|
||||
$query = DB::table('nea_entradas')
|
||||
->where('id', $id)
|
||||
->selectRaw("nea_entradas.*, DATE_FORMAT(fecha_de_nea, '%Y-%m-%d') as fecha_de_nea, DATE_FORMAT(fecha_de_registro, '%Y-%m-%d') as fecha_de_registro")
|
||||
->first();
|
||||
|
||||
// Devolver la respuesta JSON con los datos
|
||||
return response()->json([
|
||||
'data' => $query,
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(neaEntradas $obras)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('neas editar')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
try {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'id_trabajadores' => 'required|string',
|
||||
'tipo_de_sede' => 'required',
|
||||
'tipo_de_ingreso' => 'required',
|
||||
'recibido_por' => 'required',
|
||||
'id_meta' => 'required',
|
||||
'tipo_de_moneda' => 'required',
|
||||
'tipo_de_almacen' => 'required',
|
||||
'documento' => 'required',
|
||||
'tipo_de_cambio' => 'required',
|
||||
'tipo_de_uso' => 'required',
|
||||
'oficio' => 'required',
|
||||
'fecha_de_nea' => 'required',
|
||||
'fecha_de_registro' => 'required',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json($validator->errors(), 422);
|
||||
}
|
||||
|
||||
$updated = DB::table('nea_entradas')
|
||||
->where('id', $id)
|
||||
->update([
|
||||
'id_trabajadores' => $request->id_trabajadores,
|
||||
'tipo_de_sede' => $request->tipo_de_sede,
|
||||
'tipo_de_ingreso' => $request->tipo_de_ingreso,
|
||||
'recibido_por' => $request->recibido_por,
|
||||
'id_meta' => $request->id_meta,
|
||||
'tipo_de_moneda' => $request->tipo_de_moneda,
|
||||
'tipo_de_almacen' => $request->tipo_de_almacen,
|
||||
'documento' => $request->documento,
|
||||
'tipo_de_cambio' => $request->tipo_de_cambio,
|
||||
'tipo_de_uso' => $request->tipo_de_uso,
|
||||
'oficio' => $request->oficio,
|
||||
'fecha_de_nea' => $request->fecha_de_nea,
|
||||
'fecha_de_registro' => $request->fecha_de_registro,
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
if ($updated) {
|
||||
return response()->json(['mensaje' => 'Nea entradas actualizado'], 201);
|
||||
} else {
|
||||
return response()->json(['mensaje' => 'Nea entradas no encontradao'], 404);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(neaEntradas $obras): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function disable(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('neas deshabilitar')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
$id = $request->input('id'); // Obtener el ID del body
|
||||
|
||||
if (!$id) {
|
||||
return response()->json(['error' => 'ID requerido'], 400);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
$updated = DB::table('nea_entradas')
|
||||
->where('id', $id)
|
||||
->update([
|
||||
'status' => 0,
|
||||
]);
|
||||
|
||||
if ($updated) {
|
||||
return response()->json(['mensaje' => 'Nea entradas deshabilitado'], 201);
|
||||
} else {
|
||||
return response()->json(['mensaje' => 'Nea entradas no encontrado'], 404);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function enable(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('neas habilitar')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
$id = $request->input('id'); // Obtener el ID del body
|
||||
|
||||
if (!$id) {
|
||||
return response()->json(['error' => 'ID requerido'], 400);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
$updated = DB::table('nea_entradas')
|
||||
->where('id', $id)
|
||||
->update([
|
||||
'status' => 1,
|
||||
]);
|
||||
|
||||
if ($updated) {
|
||||
return response()->json(['mensaje' => 'Nea entradas deshabilitado'], 201);
|
||||
} else {
|
||||
return response()->json(['mensaje' => 'Nea entradas no encontrado'], 404);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function habilitados(Request $request)
|
||||
{
|
||||
$id = $request->input('id'); // Obtener el ID del body
|
||||
|
||||
if (!$id) {
|
||||
return response()->json(['error' => 'ID requerido'], 400);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
$updated = DB::table('nea_entradas')
|
||||
->where('id', $id)
|
||||
->update([
|
||||
'status' => 1,
|
||||
]);
|
||||
|
||||
if ($updated) {
|
||||
return response()->json(['mensaje' => 'Nea entradas habilitado'], 201);
|
||||
} else {
|
||||
return response()->json(['mensaje' => 'Nea entradas no encontrado'], 404);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,186 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\obras;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class ObrasController extends Controller
|
||||
{
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
try {
|
||||
|
||||
$query = DB::table('obras');
|
||||
|
||||
// Búsqueda dinámica
|
||||
if ($request->has('search')) {
|
||||
$search = $request->input('search');
|
||||
$query->where('obras', 'like', "%$search%")
|
||||
->orWhere('id', 'like', "%$search%");
|
||||
}
|
||||
|
||||
// Obtener los resultados sin paginación
|
||||
$data = $query->get();
|
||||
|
||||
// Devolver la respuesta JSON con los datos
|
||||
return response()->json([
|
||||
'data' => $data,
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['valid' => false], 401);
|
||||
}
|
||||
}
|
||||
// public function index(Request $request)
|
||||
// {
|
||||
// try {
|
||||
// $perPage = $request->input('per_page', 5);
|
||||
// $page = $request->input('page', 1);
|
||||
// $query = DB::table('unidad_medidas');
|
||||
|
||||
// // Búsqueda dinámica
|
||||
// if ($request->has('search')) {
|
||||
// $search = $request->input('search');
|
||||
// $query->where('nombre', 'like', "%$search%")
|
||||
// ->orWhere('abreviatura', 'like', "%$search%")
|
||||
// ->orWhere('id', 'like', "%$search%");
|
||||
// }
|
||||
|
||||
// $users = $query->paginate($perPage, ['*'], 'page', $page);
|
||||
|
||||
// return response()->json([
|
||||
// 'data' => $users->items(),
|
||||
// 'total' => $users->total(),
|
||||
// 'current_page' => $users->currentPage(),
|
||||
// 'per_page' => $users->perPage(),
|
||||
// ], 200);
|
||||
// } catch (\Exception $e) {
|
||||
// return response()->json(['valid' => false], 401);
|
||||
// }
|
||||
// }
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
try{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'obras' => 'required|string',
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
return response()->json($validator->errors(), 422);
|
||||
}
|
||||
|
||||
DB::table('obras')->insert([
|
||||
'id' => Str::uuid(),
|
||||
'obras' => $request->obras,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
return response()->json(['mensaje' => 'obras creado'], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(Request $request, $id)
|
||||
{
|
||||
//$query = DB::table('unidad_medidas')->where('id', $id)->first();
|
||||
try {
|
||||
|
||||
$query = DB::table('obras')->where('id', $id)->first();
|
||||
|
||||
// Devolver la respuesta JSON con los datos
|
||||
return response()->json([
|
||||
'data' => $query,
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(obras $obras)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
try {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'obras' => 'required|string',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json($validator->errors(), 422);
|
||||
}
|
||||
|
||||
$updated = DB::table('obras')
|
||||
->where('id', $id)
|
||||
->update([
|
||||
'obras' => $request->obras,
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
if ($updated) {
|
||||
return response()->json(['mensaje' => 'obras actualizado'], 201);
|
||||
} else {
|
||||
return response()->json(['mensaje' => 'obras no encontradao'], 404);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(obras $obras): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function disable(Request $request, $id)
|
||||
{
|
||||
try {
|
||||
|
||||
$updated = DB::table('obras')
|
||||
->where('id', $id)
|
||||
->update([
|
||||
'status' => 0,
|
||||
]);
|
||||
|
||||
if ($updated) {
|
||||
return response()->json(['mensaje' => 'obras actualizado'], 201);
|
||||
} else {
|
||||
return response()->json(['mensaje' => 'obras no encontrado'], 404);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,623 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class PdfReportesController extends Controller
|
||||
{
|
||||
//
|
||||
|
||||
public function reportInventarioPDF(Request $request)
|
||||
{
|
||||
|
||||
try {
|
||||
//dd($datas);
|
||||
$mpdf = new \Mpdf\Mpdf([
|
||||
'mode' => 'utf-8',
|
||||
'format' => 'A4-P',
|
||||
'margin_left' => 8,
|
||||
'margin_right' => 8,
|
||||
'margin_top' => 50, //define el tamaño del header
|
||||
'margin_bottom' => 54, //define el tamaño del footer
|
||||
]);
|
||||
//
|
||||
$imgLogo = public_path('assets/images/UNAP.png');
|
||||
$htmlHeader = view('reporteInventario._header', compact('imgLogo'))->render();
|
||||
|
||||
$mpdf->SetHTMLHeader($htmlHeader, '0');
|
||||
|
||||
$htmlFooter = view('reporteInventario._footer', compact('imgLogo'))->render();
|
||||
|
||||
$mpdf->SetHTMLFooter($htmlFooter, '0');
|
||||
// Agregar contenido al PDF (puedes añadir tu contenido aquí)
|
||||
$html = view('reporteInventario.index', compact('datas'))->render();
|
||||
$mpdf->WriteHTML($html);
|
||||
// Nombre del archivo PDF generado
|
||||
// Salida del PDF como respuesta HTTP
|
||||
$filename = 'report.pdf';
|
||||
return response()->streamDownload(function () use ($mpdf) {
|
||||
$mpdf->Output();
|
||||
}, $filename);
|
||||
//$mpdf->Output();
|
||||
} catch (\Exception $e) { // Especifica el tipo de excepción si es necesario
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function reportNeaPDF(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('neas reporte')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => '"Lo sentimos, pero no tiene autorización para realizar esta acción."'], 403);
|
||||
}
|
||||
|
||||
$request->validate([
|
||||
'idNeaEntrada' => 'required',
|
||||
]);
|
||||
|
||||
$idNeaEntrada = $request->input('idNeaEntrada');
|
||||
try {
|
||||
|
||||
$dataHeader = DB::table('nea_entradas')
|
||||
->join('trabajadores as t1', 't1.id', '=', 'nea_entradas.id_trabajadores')
|
||||
->join('metas as m1', 'm1.id', '=', 'nea_entradas.id_meta')
|
||||
->where('nea_entradas.id', $idNeaEntrada)
|
||||
->selectRaw("
|
||||
nea_entradas.*,
|
||||
CONCAT(t1.nombre, ' ', t1.apellido_paterno, ' ', t1.apellido_materno) AS entregado_por,
|
||||
m1.obra,
|
||||
DATE_FORMAT(fecha_de_nea, '%Y-%m-%d') AS fecha_de_nea,
|
||||
DATE_FORMAT(fecha_de_registro, '%Y-%m-%d') AS fecha_de_registro")->first();
|
||||
|
||||
$neaBienes = DB::table('nea_bienes')
|
||||
->select(
|
||||
'nea_bienes.cantidad_inicial',
|
||||
'nea_bienes.fte_fto',
|
||||
'nea_bienes.precio',
|
||||
'nea_bienes.cuenta_contable',
|
||||
'unidad_medidas.nombre as nombre_medida',
|
||||
'bienes.descripcion',
|
||||
DB::raw('FORMAT(nea_bienes.precio * nea_bienes.cantidad, 4) AS precio_total')
|
||||
|
||||
)
|
||||
->join('unidad_medidas', 'unidad_medidas.id', '=', 'nea_bienes.id_unidad_medida')
|
||||
->join('bienes', 'bienes.id', '=', 'nea_bienes.bienes_id')
|
||||
->where('nea_bienes.nea_entradas_id', $idNeaEntrada)
|
||||
->where('nea_bienes.status', 1)
|
||||
->get();
|
||||
|
||||
$total = collect($neaBienes)->sum(fn($item) => (float) str_replace(',', '', $item->precio_total));
|
||||
$totalPrecio = number_format($total, 4);
|
||||
|
||||
$mpdf = new \Mpdf\Mpdf([
|
||||
'mode' => 'utf-8',
|
||||
'format' => 'A4-L',
|
||||
'margin_left' => 8,
|
||||
'margin_right' => 8,
|
||||
'margin_top' => 65, //define el tamaño del header
|
||||
'margin_bottom' => 36, //define el tamaño del footer
|
||||
]);
|
||||
//
|
||||
$imgLogo = public_path('assets/images/UNAP.png');
|
||||
$htmlHeader = view('reporteNea._header', compact('imgLogo', 'dataHeader'))->render();
|
||||
|
||||
$mpdf->SetHTMLHeader($htmlHeader, '0');
|
||||
|
||||
$htmlFooter = view('reporteNea._footer', compact('imgLogo'))->render();
|
||||
|
||||
$mpdf->SetHTMLFooter($htmlFooter, '0');
|
||||
$pages = array_chunk($neaBienes->toArray(), 15);
|
||||
|
||||
|
||||
foreach ($pages as $index => $pageData) {
|
||||
$startIndex = $index * 15 + 1; // índice de inicio para esta página (1, 16, 31, etc.)
|
||||
|
||||
// Agregar contenido al PDF (puedes añadir tu contenido aquí)
|
||||
$html = view('reporteNea.index', compact('pageData', 'totalPrecio', 'startIndex'))->render();
|
||||
$mpdf->WriteHTML($html);
|
||||
|
||||
// Si no es la última página, agregar una nueva página
|
||||
if ($index < count($pages) - 1) {
|
||||
$mpdf->AddPage();
|
||||
}
|
||||
}
|
||||
// Nombre del archivo PDF generado
|
||||
// Salida del PDF como respuesta HTTP
|
||||
$filename = 'report.pdf';
|
||||
return response()->streamDownload(function () use ($mpdf) {
|
||||
$mpdf->Output();
|
||||
}, $filename);
|
||||
//$mpdf->Output();
|
||||
} catch (\Exception $e) { // Especifica el tipo de excepción si es necesario
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function reportPecosaPDF(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('pecosas reporte')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => '"Lo sentimos, pero no tiene autorización para realizar esta acción."'], 403);
|
||||
}
|
||||
|
||||
$request->validate([
|
||||
'idPecosaPedido' => 'required',
|
||||
]);
|
||||
|
||||
$idPecosaPedido = $request->input('idPecosaPedido');
|
||||
|
||||
try {
|
||||
//dd($datas);
|
||||
$dataHeader = DB::table('pecosa_pedidos')
|
||||
->select(
|
||||
'pecosa_pedidos.*',
|
||||
'm.meta_1',
|
||||
'm.meta_2',
|
||||
'm.obra',
|
||||
DB::raw("CONCAT(t1.nombre, ' ', t1.apellido_paterno, ' ', t1.apellido_materno) AS nombre_completo_trabajador1"),
|
||||
DB::raw("CONCAT(t2.nombre, ' ', t2.apellido_paterno, ' ', t2.apellido_materno) AS nombre_completo_trabajador2")
|
||||
)
|
||||
->join('metas as m', 'm.id', '=', 'pecosa_pedidos.id_metas')
|
||||
->join('trabajadores as t1', 't1.id', '=', 'pecosa_pedidos.id_trabajadores')
|
||||
->join('trabajadores as t2', 't2.id', '=', 'pecosa_pedidos.id_trabajadores2')
|
||||
->where('pecosa_pedidos.id', $idPecosaPedido)
|
||||
->first();
|
||||
|
||||
|
||||
///
|
||||
|
||||
$results1 = DB::table('pecosa_bienes')
|
||||
->select(
|
||||
'pecosa_bienes.descripcion',
|
||||
'pecosa_bienes.cantidad',
|
||||
'pecosa_bienes.observaciones',
|
||||
'u.nombre AS nombre_medida',
|
||||
'b.descripcion AS bien_descripcion',
|
||||
'n.cuenta_contable',
|
||||
'n.precio',
|
||||
DB::raw('FORMAT(n.precio * pecosa_bienes.cantidad, 4) AS precio_total')
|
||||
)
|
||||
->join('nea_bienes as n', 'n.id', '=', 'pecosa_bienes.nea_bien_id')
|
||||
->join('bienes as b', 'b.id', '=', 'n.bienes_id')
|
||||
->leftJoin('unidad_medidas as u', 'u.id', '=', 'pecosa_bienes.id_unidad_medida')
|
||||
->where('pecosa_bienes.id_pecosa_pedido', $idPecosaPedido)
|
||||
->where('pecosa_bienes.status', 1);
|
||||
|
||||
$results2 = DB::table('pecosa_bienes')
|
||||
->select(
|
||||
'pecosa_bienes.descripcion',
|
||||
'pecosa_bienes.cantidad',
|
||||
'pecosa_bienes.observaciones',
|
||||
'u.nombre AS nombre_medida',
|
||||
'b.descripcion AS bien_descripcion',
|
||||
'i.cuenta AS cuenta_contable',
|
||||
'i.precio AS precio',
|
||||
DB::raw('FORMAT(i.precio * pecosa_bienes.cantidad, 4) AS precio_total')
|
||||
)
|
||||
->join('inventario_inicials as i', 'i.id', '=', 'pecosa_bienes.id_inventario_inicial')
|
||||
->join('bienes as b', 'b.id', '=', 'i.bienes_id')
|
||||
->leftJoin('unidad_medidas as u', 'u.id', '=', 'pecosa_bienes.id_unidad_medida')
|
||||
->where('pecosa_bienes.id_pecosa_pedido', $idPecosaPedido)
|
||||
->where('pecosa_bienes.status', 1);
|
||||
|
||||
|
||||
$resultsBienes = $results1->union($results2)->get();
|
||||
$total = collect($resultsBienes)->sum(fn($item) => (float) str_replace(',', '', $item->precio_total));
|
||||
$totalPrecio = number_format($total, 4);
|
||||
// dd($totalPrecio);
|
||||
//$total = $resultsBienes->sum(fn($item) => (float) $item->precio_total);
|
||||
|
||||
$mpdf = new \Mpdf\Mpdf([
|
||||
'mode' => 'utf-8',
|
||||
'format' => 'A4-L',
|
||||
'margin_left' => 8,
|
||||
'margin_right' => 8,
|
||||
'margin_top' => 75, //define el tamaño del header
|
||||
'margin_bottom' => 34, //define el tamaño del footer
|
||||
]);
|
||||
//
|
||||
$imgLogo = public_path('assets/images/UNAP.png');
|
||||
$htmlHeader = view('reportePecosa._header', compact('imgLogo', 'dataHeader'))->render();
|
||||
|
||||
$mpdf->SetHTMLHeader($htmlHeader, '0');
|
||||
|
||||
$htmlFooter = view('reportePecosa._footer', compact('imgLogo'))->render();
|
||||
|
||||
$mpdf->SetHTMLFooter($htmlFooter, '0');
|
||||
|
||||
$pages = array_chunk($resultsBienes->toArray(), 15);
|
||||
|
||||
|
||||
foreach ($pages as $index => $pageData) {
|
||||
$startIndex = $index * 15 + 1; // índice de inicio para esta página (1, 16, 31, etc.)
|
||||
|
||||
// Agregar contenido al PDF (puedes añadir tu contenido aquí)
|
||||
$html = view('reportePecosa.index', compact('pageData', 'totalPrecio', 'startIndex'))->render();
|
||||
$mpdf->WriteHTML($html);
|
||||
|
||||
// Si no es la última página, agregar una nueva página
|
||||
if ($index < count($pages) - 1) {
|
||||
$mpdf->AddPage();
|
||||
}
|
||||
}
|
||||
|
||||
// // Agregar contenido al PDF (puedes añadir tu contenido aquí)
|
||||
// $html = view('reportePecosa.index', compact('resultsBienes', 'totalPrecio'))->render();
|
||||
// $mpdf->WriteHTML($html);
|
||||
|
||||
// Nombre del archivo PDF generado
|
||||
// Salida del PDF como respuesta HTTP
|
||||
$filename = 'report.pdf';
|
||||
return response()->streamDownload(function () use ($mpdf) {
|
||||
$mpdf->Output();
|
||||
}, $filename);
|
||||
//$mpdf->Output();
|
||||
} catch (\Exception $e) { // Especifica el tipo de excepción si es necesario
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function reportPecosa2023PDF(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('pecosas reporte')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => '"Lo sentimos, pero no tiene autorización para realizar esta acción."'], 403);
|
||||
}
|
||||
$request->validate([
|
||||
'idPecosaPedido' => 'required',
|
||||
]);
|
||||
|
||||
$idPecosaPedido = $request->input('idPecosaPedido');
|
||||
|
||||
try {
|
||||
//dd($datas);
|
||||
$dataHeader = DB::table('pecosa_2023_pedidos')
|
||||
->select(
|
||||
'pecosa_2023_pedidos.*',
|
||||
'm.meta_1',
|
||||
'm.meta_2',
|
||||
'm.obra',
|
||||
DB::raw("CONCAT(t1.nombre, ' ', t1.apellido_paterno, ' ', t1.apellido_materno) AS nombre_completo_trabajador1"),
|
||||
DB::raw("CONCAT(t2.nombre, ' ', t2.apellido_paterno, ' ', t2.apellido_materno) AS nombre_completo_trabajador2")
|
||||
)
|
||||
->join('metas as m', 'm.id', '=', 'pecosa_2023_pedidos.id_metas')
|
||||
->join('trabajadores as t1', 't1.id', '=', 'pecosa_2023_pedidos.id_trabajadores')
|
||||
->join('trabajadores as t2', 't2.id', '=', 'pecosa_2023_pedidos.id_trabajadores2')
|
||||
->where('pecosa_2023_pedidos.id', $idPecosaPedido)
|
||||
->first();
|
||||
|
||||
|
||||
///
|
||||
|
||||
$results1 = DB::table('pecosa_2023_bienes')
|
||||
->select(
|
||||
'pecosa_2023_bienes.descripcion',
|
||||
'pecosa_2023_bienes.cantidad',
|
||||
'pecosa_2023_bienes.observaciones',
|
||||
'u.nombre AS nombre_medida',
|
||||
'b.descripcion AS bien_descripcion',
|
||||
'n.cuenta_contable',
|
||||
'n.precio',
|
||||
DB::raw('FORMAT(n.precio * pecosa_2023_bienes.cantidad, 4) AS precio_total')
|
||||
)
|
||||
->join('nea_bienes as n', 'n.id', '=', 'pecosa_2023_bienes.nea_bien_id')
|
||||
->join('bienes as b', 'b.id', '=', 'n.bienes_id')
|
||||
->leftJoin('unidad_medidas as u', 'u.id', '=', 'pecosa_2023_bienes.id_unidad_medida')
|
||||
->where('pecosa_2023_bienes.id_pecosa_2023_pedidos', $idPecosaPedido);
|
||||
|
||||
$results2 = DB::table('pecosa_2023_bienes')
|
||||
->select(
|
||||
'pecosa_2023_bienes.descripcion',
|
||||
'pecosa_2023_bienes.cantidad',
|
||||
'pecosa_2023_bienes.observaciones',
|
||||
'u.nombre AS nombre_medida',
|
||||
'b.descripcion AS bien_descripcion',
|
||||
'i.cuenta AS cuenta_contable',
|
||||
'i.precio AS precio',
|
||||
DB::raw('FORMAT(i.precio * pecosa_2023_bienes.cantidad, 4) AS precio_total')
|
||||
)
|
||||
->join('2023_inventario_inicials as i', 'i.id', '=', 'pecosa_2023_bienes.id_2023_inventario_inicial')
|
||||
->join('bienes as b', 'b.id', '=', 'i.bienes_id')
|
||||
->leftJoin('unidad_medidas as u', 'u.id', '=', 'pecosa_2023_bienes.id_unidad_medida')
|
||||
->where('pecosa_2023_bienes.id_pecosa_2023_pedidos', $idPecosaPedido);
|
||||
|
||||
$resultsBienes = $results1->union($results2)->get();
|
||||
$total = collect($resultsBienes)->sum(fn($item) => (float) str_replace(',', '', $item->precio_total));
|
||||
$totalPrecio = number_format($total, 4);
|
||||
// dd($totalPrecio);
|
||||
//$total = $resultsBienes->sum(fn($item) => (float) $item->precio_total);
|
||||
|
||||
$mpdf = new \Mpdf\Mpdf([
|
||||
'mode' => 'utf-8',
|
||||
'format' => 'A4-L',
|
||||
'margin_left' => 8,
|
||||
'margin_right' => 8,
|
||||
'margin_top' => 65, //define el tamaño del header
|
||||
'margin_bottom' => 44, //define el tamaño del footer
|
||||
]);
|
||||
//
|
||||
$imgLogo = public_path('assets/images/UNAP.png');
|
||||
$htmlHeader = view('reportePecosa2023._header', compact('imgLogo', 'dataHeader'))->render();
|
||||
|
||||
$mpdf->SetHTMLHeader($htmlHeader, '0');
|
||||
|
||||
$htmlFooter = view('reportePecosa2023._footer', compact('imgLogo'))->render();
|
||||
|
||||
$mpdf->SetHTMLFooter($htmlFooter, '0');
|
||||
|
||||
$pages = array_chunk($resultsBienes->toArray(), 15);
|
||||
|
||||
|
||||
foreach ($pages as $index => $pageData) {
|
||||
// Agregar contenido al PDF (puedes añadir tu contenido aquí)
|
||||
$startIndex = $index * 15 + 1; // índice de inicio para esta página (1, 16, 31, etc.)
|
||||
|
||||
$html = view('reportePecosa2023.index', compact('pageData', 'totalPrecio', 'startIndex'))->render();
|
||||
$mpdf->WriteHTML($html);
|
||||
|
||||
// Si no es la última página, agregar una nueva página
|
||||
if ($index < count($pages) - 1) {
|
||||
$mpdf->AddPage();
|
||||
}
|
||||
}
|
||||
|
||||
$filename = 'report.pdf';
|
||||
return response()->streamDownload(function () use ($mpdf) {
|
||||
$mpdf->Output();
|
||||
}, $filename);
|
||||
//$mpdf->Output();
|
||||
} catch (\Exception $e) { // Especifica el tipo de excepción si es necesario
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function reportPecosaListaDetalladaPDF(Request $request)
|
||||
{
|
||||
|
||||
$version = $request->input('version');
|
||||
$unidad_ejecutora = $request->input('unidad_ejecutora');
|
||||
$numero_identificacion = $request->input('numero_identificacion');
|
||||
$tipo_presupuesto = $request->input('tipo_presupuesto');
|
||||
$startDate = $request->input('fecha_desde');
|
||||
$endDate = $request->input('fecha_hasta');
|
||||
|
||||
// dd($year);
|
||||
// Si las fechas no se reciben en la solicitud, se asignan automáticamente las fechas para el año actual
|
||||
if (!$startDate && !$endDate) {
|
||||
$startDate = now()->startOfYear()->toDateString();
|
||||
$endDate = now()->endOfYear()->toDateString(); // Asigna el último día del año actual
|
||||
}
|
||||
$year = Carbon::parse($startDate)->year;
|
||||
|
||||
try {
|
||||
|
||||
$reportData = collect(); // Aquí almacenamos todos los pedidos procesados
|
||||
|
||||
if ($year <= 2023) {
|
||||
|
||||
DB::table('pecosa_2023_pedidos')
|
||||
->select(
|
||||
'pecosa_2023_pedidos.id',
|
||||
'pecosa_2023_pedidos.codigo',
|
||||
'pecosa_2023_pedidos.dependencias',
|
||||
DB::raw("DATE_FORMAT(pecosa_2023_pedidos.fecha, '%Y-%m-%d') AS fecha"),
|
||||
'm.meta_1',
|
||||
'm.meta_2',
|
||||
'm.obra',
|
||||
DB::raw("CONCAT(t1.nombre, ' ', t1.apellido_paterno, ' ', t1.apellido_materno) AS trabajador1"),
|
||||
DB::raw("CONCAT(t2.nombre, ' ', t2.apellido_paterno, ' ', t2.apellido_materno) AS trabajador2")
|
||||
)
|
||||
->join('metas as m', 'm.id', '=', 'pecosa_2023_pedidos.id_metas')
|
||||
->join('trabajadores as t1', 't1.id', '=', 'pecosa_2023_pedidos.id_trabajadores')
|
||||
->join('trabajadores as t2', 't2.id', '=', 'pecosa_2023_pedidos.id_trabajadores2')
|
||||
->whereBetween('pecosa_2023_pedidos.fecha', [$startDate, $endDate]) // Filtro por rango de fechas
|
||||
->orderByRaw(sql: "SUBSTRING_INDEX(pecosa_2023_pedidos.codigo, '-', -1) ASC, LPAD(SUBSTRING_INDEX(pecosa_2023_pedidos.codigo, '-', 1), 4, '0') ASC")
|
||||
->chunk(100, function ($pedidosChunk) use (&$reportData) {
|
||||
foreach ($pedidosChunk as $pedido) {
|
||||
// Consulta 1: desde nea_bienes
|
||||
$results1 = DB::table('pecosa_2023_bienes')
|
||||
->select(
|
||||
'b.codigo as codigo',
|
||||
'pecosa_2023_bienes.descripcion',
|
||||
'pecosa_2023_bienes.cantidad',
|
||||
'pecosa_2023_bienes.observaciones',
|
||||
'u.nombre AS nombre_medida',
|
||||
'b.descripcion AS bien_descripcion',
|
||||
'b.marca AS marca_bien',
|
||||
'n.cuenta_contable',
|
||||
'n.precio',
|
||||
DB::raw('n.precio * pecosa_2023_bienes.cantidad AS precio_total')
|
||||
)
|
||||
->where('pecosa_2023_bienes.id_pecosa_2023_pedidos', $pedido->id)
|
||||
->join('nea_bienes as n', 'n.id', '=', 'pecosa_2023_bienes.nea_bien_id')
|
||||
->join('bienes as b', 'b.id', '=', 'n.bienes_id')
|
||||
->leftJoin('unidad_medidas as u', 'u.id', '=', 'pecosa_2023_bienes.id_unidad_medida');
|
||||
|
||||
// Consulta 2: desde inventario_inicials
|
||||
$results2 = DB::table('pecosa_2023_bienes')
|
||||
->select(
|
||||
'b.codigo as codigo',
|
||||
'pecosa_2023_bienes.descripcion',
|
||||
'pecosa_2023_bienes.cantidad',
|
||||
'pecosa_2023_bienes.observaciones',
|
||||
'u.nombre AS nombre_medida',
|
||||
'b.descripcion AS bien_descripcion',
|
||||
'b.marca AS marca_bien',
|
||||
'i.cuenta AS cuenta_contable',
|
||||
'i.precio AS precio',
|
||||
DB::raw('i.precio * pecosa_2023_bienes.cantidad AS precio_total')
|
||||
)
|
||||
->where('pecosa_2023_bienes.id_pecosa_2023_pedidos', $pedido->id)
|
||||
->join('2023_inventario_inicials as i', 'i.id', '=', 'pecosa_2023_bienes.id_2023_inventario_inicial')
|
||||
->join('bienes as b', 'b.id', '=', 'i.bienes_id')
|
||||
->leftJoin('unidad_medidas as u', 'u.id', '=', 'pecosa_2023_bienes.id_unidad_medida');
|
||||
|
||||
// Ejecutamos ambas con unionAll para incluir todo
|
||||
$bienes = $results1->unionAll($results2)->get();
|
||||
|
||||
// Calcular total de precio por pedido
|
||||
$total = collect($bienes)->sum(fn($item) => (float) str_replace(',', '', $item->precio_total));
|
||||
|
||||
// Asignamos al objeto
|
||||
$pedido->total_precio = number_format($total, 4);
|
||||
$pedido->dataBienes = $bienes;
|
||||
|
||||
// Guardamos en colección final
|
||||
$reportData->push($pedido);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
DB::table('pecosa_pedidos')
|
||||
->select(
|
||||
'pecosa_pedidos.id',
|
||||
'pecosa_pedidos.codigo',
|
||||
'pecosa_pedidos.dependencias',
|
||||
DB::raw("DATE_FORMAT(pecosa_pedidos.fecha, '%Y-%m-%d') AS fecha"),
|
||||
'm.meta_1',
|
||||
'm.meta_2',
|
||||
'm.obra',
|
||||
DB::raw("CONCAT(t1.nombre, ' ', t1.apellido_paterno, ' ', t1.apellido_materno) AS trabajador1"),
|
||||
DB::raw("CONCAT(t2.nombre, ' ', t2.apellido_paterno, ' ', t2.apellido_materno) AS trabajador2")
|
||||
)
|
||||
->join('metas as m', 'm.id', '=', 'pecosa_pedidos.id_metas')
|
||||
->join('trabajadores as t1', 't1.id', '=', 'pecosa_pedidos.id_trabajadores')
|
||||
->join('trabajadores as t2', 't2.id', '=', 'pecosa_pedidos.id_trabajadores2')
|
||||
->whereBetween('pecosa_pedidos.fecha', [$startDate, $endDate]) // Filtro por rango de fechas
|
||||
->orderByRaw(sql: "SUBSTRING_INDEX(pecosa_pedidos.codigo, '-', -1) ASC, LPAD(SUBSTRING_INDEX(pecosa_pedidos.codigo, '-', 1), 4, '0') ASC")
|
||||
->chunk(100, function ($pedidosChunk) use (&$reportData) {
|
||||
foreach ($pedidosChunk as $pedido) {
|
||||
// Consulta 1: desde nea_bienes
|
||||
$results1 = DB::table('pecosa_bienes')
|
||||
->select(
|
||||
'b.codigo as codigo',
|
||||
'pecosa_bienes.descripcion',
|
||||
'pecosa_bienes.cantidad',
|
||||
'pecosa_bienes.observaciones',
|
||||
'u.nombre AS nombre_medida',
|
||||
'b.descripcion AS bien_descripcion',
|
||||
'b.marca AS marca_bien',
|
||||
'n.cuenta_contable',
|
||||
'n.precio',
|
||||
DB::raw('n.precio * pecosa_bienes.cantidad AS precio_total')
|
||||
)
|
||||
->where('pecosa_bienes.id_pecosa_pedido', $pedido->id)
|
||||
->join('nea_bienes as n', 'n.id', '=', 'pecosa_bienes.nea_bien_id')
|
||||
->join('bienes as b', 'b.id', '=', 'n.bienes_id')
|
||||
->leftJoin('unidad_medidas as u', 'u.id', '=', 'pecosa_bienes.id_unidad_medida');
|
||||
|
||||
// Consulta 2: desde inventario_inicials
|
||||
$results2 = DB::table('pecosa_bienes')
|
||||
->select(
|
||||
'b.codigo as codigo',
|
||||
'pecosa_bienes.descripcion',
|
||||
'pecosa_bienes.cantidad',
|
||||
'pecosa_bienes.observaciones',
|
||||
'u.nombre AS nombre_medida',
|
||||
'b.descripcion AS bien_descripcion',
|
||||
'b.marca AS marca_bien',
|
||||
'i.cuenta AS cuenta_contable',
|
||||
'i.precio AS precio',
|
||||
DB::raw('i.precio * pecosa_bienes.cantidad AS precio_total')
|
||||
)
|
||||
->where('pecosa_bienes.id_pecosa_pedido', $pedido->id)
|
||||
->join('inventario_inicials as i', 'i.id', '=', 'pecosa_bienes.id_inventario_inicial')
|
||||
->join('bienes as b', 'b.id', '=', 'i.bienes_id')
|
||||
->leftJoin('unidad_medidas as u', 'u.id', '=', 'pecosa_bienes.id_unidad_medida');
|
||||
|
||||
// Ejecutamos ambas con unionAll para incluir todo
|
||||
$bienes = $results1->unionAll($results2)->get();
|
||||
|
||||
// Calcular total de precio por pedido
|
||||
$total = collect($bienes)->sum(fn($item) => (float) str_replace(',', '', $item->precio_total));
|
||||
|
||||
// Asignamos al objeto
|
||||
$pedido->total_precio = number_format($total, 4);
|
||||
$pedido->dataBienes = $bienes;
|
||||
|
||||
// Guardamos en colección final
|
||||
$reportData->push($pedido);
|
||||
}
|
||||
});
|
||||
// $reportData = $reportData1->unionAll($reportData0)->get();
|
||||
// $reportData = collect($reportData)->sortBy(function ($item) {
|
||||
// // Separamos el código en dos partes: número y año
|
||||
// [$numero, $anio] = explode('-', $item->codigo);
|
||||
|
||||
// // Convertimos ambos en enteros para ordenación correcta
|
||||
// return ((int)$anio * 10000) + (int)$numero;
|
||||
// })->values();
|
||||
|
||||
// dd($reportData);
|
||||
$mpdf = new \Mpdf\Mpdf([
|
||||
'mode' => 'utf-8',
|
||||
'format' => 'A4-L',
|
||||
'margin_left' => 8,
|
||||
'margin_right' => 8,
|
||||
'margin_top' => 45, //define el tamaño del header
|
||||
'margin_bottom' => 34, //define el tamaño del footer
|
||||
]);
|
||||
//
|
||||
|
||||
|
||||
$imgLogo = public_path('assets/images/UNAP.png');
|
||||
$htmlHeader = view(
|
||||
'reportPecosaListaDetallada._header',
|
||||
compact(
|
||||
'endDate',
|
||||
'startDate',
|
||||
'tipo_presupuesto',
|
||||
'numero_identificacion',
|
||||
'unidad_ejecutora',
|
||||
'imgLogo',
|
||||
'version'
|
||||
)
|
||||
)->render();
|
||||
|
||||
$mpdf->SetHTMLHeader($htmlHeader, '0');
|
||||
|
||||
$htmlFooter = view('reportPecosaListaDetallada._footer', compact('imgLogo'))->render();
|
||||
|
||||
$mpdf->SetHTMLFooter($htmlFooter, '0');
|
||||
// Agregar contenido al PDF (puedes añadir tu contenido aquí)
|
||||
// $html = view('reportPecosaListaDetallada.index', compact('reportData'))->render();
|
||||
// $mpdf->WriteHTML($html);
|
||||
ini_set('memory_limit', '512M');
|
||||
|
||||
$view = view('reportPecosaListaDetallada.index', compact('reportData'));
|
||||
foreach (str_split($view->render(), 500000) as $chunk) { // Fragmentos de 500KB
|
||||
$mpdf->WriteHTML($chunk);
|
||||
}
|
||||
// Nombre del archivo PDF generado
|
||||
// Salida del PDF como respuesta HTTP
|
||||
$filename = 'report.pdf';
|
||||
return response()->streamDownload(function () use ($mpdf) {
|
||||
$mpdf->Output();
|
||||
}, $filename);
|
||||
//$mpdf->Output();
|
||||
} catch (\Exception $e) { // Especifica el tipo de excepción si es necesario
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class Pecosa2023BieneController extends Controller
|
||||
{
|
||||
//
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
class Pecosa2023PedidoController extends Controller
|
||||
{
|
||||
//
|
||||
|
||||
public function listEnable()
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('pecosas vista')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
try {
|
||||
$data = DB::table('pecosa_2023_pedidos')
|
||||
->select(
|
||||
'pecosa_2023_pedidos.*',
|
||||
'm.meta_1',
|
||||
'm.meta_2',
|
||||
'm.obra',
|
||||
DB::raw("CONCAT(t1.nombre, ' ', t1.apellido_paterno, ' ', t1.apellido_materno) AS nombre_completo_trabajador1"),
|
||||
DB::raw("CONCAT(t2.nombre, ' ', t2.apellido_paterno, ' ', t2.apellido_materno) AS nombre_completo_trabajador2")
|
||||
)
|
||||
->join('metas as m', 'm.id', '=', 'pecosa_2023_pedidos.id_metas')
|
||||
->join('trabajadores as t1', 't1.id', '=', 'pecosa_2023_pedidos.id_trabajadores')
|
||||
->join('trabajadores as t2', 't2.id', '=', 'pecosa_2023_pedidos.id_trabajadores2')
|
||||
->orderByRaw("SUBSTRING_INDEX(codigo, '-', -1) DESC, LPAD(SUBSTRING_INDEX(codigo, '-', 1), 4, '0') DESC")
|
||||
->where('pecosa_2023_pedidos.status', 1)
|
||||
->get();
|
||||
|
||||
|
||||
return response()->json(['data' => $data], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['valid' => false], 401);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,769 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Models\pecosaBienes;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
use App\Models\inventarioInicial;
|
||||
use App\Models\neaBienes;
|
||||
|
||||
class PecosaBienesController extends Controller
|
||||
{
|
||||
|
||||
|
||||
public function listPecosaBienes(Request $request)
|
||||
{
|
||||
|
||||
try {
|
||||
|
||||
$neaQuery = DB::table('pecosa_bienes as pb')
|
||||
->join('pecosa_pedidos as pd', 'pb.id_pecosa_pedido', '=', 'pd.id')
|
||||
->join('nea_bienes', 'pb.nea_bien_id', '=', 'nea_bienes.id')
|
||||
->join('bienes', 'nea_bienes.bienes_id', '=', 'bienes.id')
|
||||
->join('unidad_medidas', 'bienes.id_unidad_medida', '=', 'unidad_medidas.id')
|
||||
->select(
|
||||
'pd.codigo as codigo_pedido',
|
||||
'bienes.descripcion',
|
||||
'unidad_medidas.nombre as unidad_medida',
|
||||
'bienes.codigo as codigo_bien',
|
||||
'nea_bienes.cantidad',
|
||||
'nea_bienes.precio',
|
||||
DB::raw('(nea_bienes.cantidad * nea_bienes.precio) as valor_total'),
|
||||
'pb.observaciones'
|
||||
);
|
||||
|
||||
// Segunda parte: con inventario_inicials
|
||||
$inventarioQuery = DB::table('pecosa_bienes as pb')
|
||||
->join('pecosa_pedidos as pd', 'pb.id_pecosa_pedido', '=', 'pd.id')
|
||||
->join('inventario_inicials', 'pb.id_inventario_inicial', '=', 'inventario_inicials.id')
|
||||
->join('bienes', 'inventario_inicials.bienes_id', '=', 'bienes.id')
|
||||
->join('unidad_medidas', 'bienes.id_unidad_medida', '=', 'unidad_medidas.id')
|
||||
->select(
|
||||
'pd.codigo as codigo_pedido',
|
||||
'bienes.descripcion',
|
||||
'unidad_medidas.nombre as unidad_medida',
|
||||
'bienes.codigo as codigo_bien',
|
||||
'inventario_inicials.cantidad',
|
||||
'inventario_inicials.precio',
|
||||
DB::raw('(inventario_inicials.cantidad * inventario_inicials.precio) as valor_total'),
|
||||
'pb.observaciones'
|
||||
);
|
||||
|
||||
// Unir ambas
|
||||
$data = $neaQuery->unionAll($inventarioQuery)->get();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Lista de Pecosa Bienes',
|
||||
'data' => $data
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Error en el servidor',
|
||||
'error' => $e->getMessage() // Devuelve el mensaje de la excepción
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function store_inventario(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('pecosas agregar inventario bienes')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
try {
|
||||
$rules = [
|
||||
'registros' => 'required|array',
|
||||
'registros.*.id_pecosa_pedido' => 'nullable',
|
||||
'registros.*.id_inventario_inicial' => 'nullable',
|
||||
'registros.*.descripcion' => 'nullable',
|
||||
'registros.*.cantidad' => 'required|numeric',
|
||||
'registros.*.id_unidad_medida' => 'required',
|
||||
'registros.*.observaciones' => 'required',
|
||||
'registros.*.fecha' => 'required|date',
|
||||
];
|
||||
|
||||
$messages = [
|
||||
'registros.required' => 'El campo registros es obligatorio.',
|
||||
'registros.array' => 'El campo registros debe ser un arreglo.',
|
||||
'registros.*.nea_bien_id.exists' => 'El nea_bien_id no existe en la base de datos.',
|
||||
];
|
||||
|
||||
// Validación
|
||||
$validator = Validator::make($request->all(), $rules, $messages);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Errores de validación',
|
||||
'errors' => $validator->errors()
|
||||
], 422);
|
||||
}
|
||||
|
||||
$data = $validator->validated();
|
||||
|
||||
foreach ($data['registros'] as &$registro) {
|
||||
$registro['id'] = (string) Str::uuid(); // Generar UUID
|
||||
|
||||
if (!empty($registro['id_inventario_inicial'])) {
|
||||
// Si el ID de inventario inicial existe, actualizar la cantidad
|
||||
$inventario = inventarioInicial::find($registro['id_inventario_inicial']);
|
||||
|
||||
if ($inventario) {
|
||||
$inventario->cantidad -= $registro['cantidad'];
|
||||
|
||||
if ($inventario->cantidad < 0) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => "No hay suficiente stock para el bien."
|
||||
], 400);
|
||||
}
|
||||
|
||||
$inventario->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Insertar en PecosaBienes
|
||||
PecosaBienes::insert($data['registros']);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Registros guardados correctamente'
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Error en el servidor',
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function store_nea_bienes(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('pecosas agregar neas bienes')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
try {
|
||||
$rules = [
|
||||
'registros' => 'required|array',
|
||||
'registros.*.id_pecosa_pedido' => 'nullable',
|
||||
'registros.*.nea_bien_id' => 'nullable|exists:nea_bienes,id', // Validar existencia en la tabla
|
||||
'registros.*.descripcion' => 'nullable',
|
||||
'registros.*.cantidad' => 'required|numeric',
|
||||
'registros.*.id_unidad_medida' => 'required',
|
||||
'registros.*.observaciones' => 'required',
|
||||
'registros.*.fecha' => 'required|date',
|
||||
];
|
||||
|
||||
$messages = [
|
||||
'registros.required' => 'El campo registros es obligatorio.',
|
||||
'registros.array' => 'El campo registros debe ser un arreglo.',
|
||||
'registros.*.nea_bien_id.exists' => 'El nea_bien_id no existe en la base de datos.',
|
||||
];
|
||||
|
||||
// Validación
|
||||
$validator = Validator::make($request->all(), $rules, $messages);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Errores de validación',
|
||||
'errors' => $validator->errors()
|
||||
], 422);
|
||||
}
|
||||
|
||||
$data = $validator->validated();
|
||||
|
||||
foreach ($data['registros'] as &$registro) {
|
||||
$registro['id'] = (string) Str::uuid(); // Generar UUID
|
||||
|
||||
if (!empty($registro['nea_bien_id'])) {
|
||||
// Si el ID de nea bien existe, actualizar la cantidad
|
||||
$inventario_neas = neaBienes::find($registro['nea_bien_id']);
|
||||
|
||||
if ($inventario_neas) {
|
||||
$inventario_neas->cantidad -= $registro['cantidad'];
|
||||
|
||||
if ($inventario_neas->cantidad < 0) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => "No hay suficiente stock."
|
||||
], 400);
|
||||
}
|
||||
|
||||
$inventario_neas->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Insertar en PecosaBienes
|
||||
PecosaBienes::insert($data['registros']);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Registros guardados correctamente'
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Error en el servidor',
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function listNeasBienes(Request $request, $id)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('pecosas vista')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
try {
|
||||
$data = DB::table('pecosa_bienes as p')
|
||||
->join('nea_bienes as n', 'n.id', '=', 'p.nea_bien_id')
|
||||
->join('bienes as b', 'b.id', '=', 'n.bienes_id')
|
||||
->join('unidad_medidas as u', 'u.id', '=', 'b.id_unidad_medida')
|
||||
|
||||
->select(
|
||||
'b.descripcion AS descripcion_bien',
|
||||
'n.cantidad as cantidad_stock',
|
||||
'u.nombre as nombre_medida',
|
||||
'p.*',
|
||||
'p.id_unidad_medida AS medida_salida',
|
||||
DB::raw("DATE_FORMAT(p.fecha, '%Y-%m-%d') as fecha_registro"),
|
||||
'p.descripcion as descripcion_pecosa_bien'
|
||||
)
|
||||
->where('p.id_pecosa_pedido', $id)
|
||||
->get();
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Lista de NEAS de bienes',
|
||||
'data' => $data
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Error en el servidor',
|
||||
'error' => $e->getMessage() // Devuelve el mensaje de la excepción
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function listNeasBienesEnable(Request $request, $id)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('pecosas vista')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
try {
|
||||
$data = DB::table('pecosa_bienes as p')
|
||||
->join('nea_bienes as n', 'n.id', '=', 'p.nea_bien_id')
|
||||
->join('bienes as b', 'b.id', '=', 'n.bienes_id')
|
||||
->join('unidad_medidas as u', 'u.id', '=', 'b.id_unidad_medida')
|
||||
|
||||
->select(
|
||||
'b.descripcion AS descripcion_bien',
|
||||
'n.cantidad as cantidad_stock',
|
||||
'u.nombre as nombre_medida',
|
||||
'p.*',
|
||||
'p.id_unidad_medida AS medida_salida',
|
||||
DB::raw("DATE_FORMAT(p.fecha, '%Y-%m-%d') as fecha_registro"),
|
||||
'p.descripcion as descripcion_pecosa_bien'
|
||||
)
|
||||
->where('p.id_pecosa_pedido', $id)
|
||||
->where('p.status', 1) // Solo los registros habilitados
|
||||
->get();
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Lista de NEAS de bienes',
|
||||
'data' => $data
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Error en el servidor',
|
||||
'error' => $e->getMessage() // Devuelve el mensaje de la excepción
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function listInventarioBienes(Request $request, $id)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('pecosas vista')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
try {
|
||||
$data = DB::table('pecosa_bienes as p')
|
||||
->join('inventario_inicials as n', 'n.id', '=', 'p.id_inventario_inicial')
|
||||
->join('bienes as b', 'b.id', '=', 'n.bienes_id')
|
||||
->join('unidad_medidas as u', 'u.id', '=', 'b.id_unidad_medida')
|
||||
|
||||
->select(
|
||||
'b.descripcion AS descripcion_bien',
|
||||
'n.cantidad as cantidad_stock',
|
||||
'u.nombre as nombre_medida',
|
||||
'p.*',
|
||||
'p.id_unidad_medida AS medida_salida',
|
||||
DB::raw("DATE_FORMAT(p.fecha, '%Y-%m-%d') as fecha_registro"),
|
||||
'p.descripcion as descripcion_pecosa_bien'
|
||||
)
|
||||
->where('p.id_pecosa_pedido', $id)
|
||||
->get();
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Lista de Inevntario de bienes',
|
||||
'data' => $data
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Error en el servidor',
|
||||
'error' => $e->getMessage() // Devuelve el mensaje de la excepción
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function listInventarioBienesEnable(Request $request, $id)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('pecosas vista')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
try {
|
||||
$data = DB::table('pecosa_bienes as p')
|
||||
->join('inventario_inicials as n', 'n.id', '=', 'p.id_inventario_inicial')
|
||||
->join('bienes as b', 'b.id', '=', 'n.bienes_id')
|
||||
->join('unidad_medidas as u', 'u.id', '=', 'b.id_unidad_medida')
|
||||
|
||||
->select(
|
||||
'b.descripcion AS descripcion_bien',
|
||||
'n.cantidad as cantidad_stock',
|
||||
'u.nombre as nombre_medida',
|
||||
'p.*',
|
||||
'p.id_unidad_medida AS medida_salida',
|
||||
DB::raw("DATE_FORMAT(p.fecha, '%Y-%m-%d') as fecha_registro"),
|
||||
'p.descripcion as descripcion_pecosa_bien'
|
||||
)
|
||||
->where('p.id_pecosa_pedido', $id)
|
||||
->where('p.status', 1) // Solo los registros habilitados
|
||||
->get();
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Lista de Inevntario de bienes',
|
||||
'data' => $data
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Error en el servidor',
|
||||
'error' => $e->getMessage() // Devuelve el mensaje de la excepción
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
public function update_inventario(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('pecosas actualizar inventario bienes')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
try {
|
||||
$rules = [
|
||||
'registros' => 'required|array',
|
||||
'registros.*.id' => 'required|exists:pecosa_bienes,id',
|
||||
'registros.*.id_inventario_inicial' => 'required',
|
||||
'registros.*.descripcion' => 'string',
|
||||
'registros.*.cantidad' => 'required|numeric',
|
||||
'registros.*.id_unidad_medida' => 'required',
|
||||
'registros.*.observaciones' => 'required',
|
||||
'registros.*.fecha' => 'required|date',
|
||||
];
|
||||
|
||||
$messages = [
|
||||
'registros.required' => 'El campo registros es obligatorio.',
|
||||
'registros.array' => 'El campo registros debe ser un arreglo.',
|
||||
'registros.*.id.exists' => 'El ID del bien no existe en la base de datos.',
|
||||
];
|
||||
|
||||
// Validación
|
||||
$validator = Validator::make($request->all(), $rules, $messages);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Errores de validación',
|
||||
'errors' => $validator->errors()
|
||||
], 422);
|
||||
}
|
||||
|
||||
$data = $validator->validated();
|
||||
|
||||
// Depurar los datos antes de continuar
|
||||
\Log::info('Datos recibidos para actualizar:', $data);
|
||||
// dd($data); // Descomenta esta línea si quieres ver los datos en la respuesta API
|
||||
|
||||
foreach ($data['registros'] as $registro) {
|
||||
// Buscar el registro en la base de datos
|
||||
$pecosaBien = PecosaBienes::find($registro['id']);
|
||||
|
||||
if (!$pecosaBien) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Registro no encontrado con ID: ' . $registro['id']
|
||||
], 404);
|
||||
}
|
||||
$temp_cantidad = $pecosaBien->cantidad;
|
||||
if (!empty($registro['id_inventario_inicial'])) {
|
||||
$inventario = InventarioInicial::find($registro['id_inventario_inicial']);
|
||||
if ($inventario) {
|
||||
// ✅ Primero, restaurar la cantidad anterior en el inventario
|
||||
$inventario->cantidad += $temp_cantidad;
|
||||
|
||||
// ✅ Luego, restar la nueva cantidad
|
||||
$inventario->cantidad -= floatval($registro['cantidad']);
|
||||
|
||||
// ⚠️ Verificar que no haya stock negativo
|
||||
if ($inventario->cantidad < 0) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => "No hay suficiente stock para el bien con ID: " . $registro['id']
|
||||
], 400);
|
||||
}
|
||||
|
||||
$inventario->save();
|
||||
}
|
||||
}
|
||||
//dd($registro['cantidad']);
|
||||
// Actualizar los datos del bien
|
||||
$pecosaBien->update([
|
||||
'descripcion' => $registro['descripcion'],
|
||||
'cantidad' => $registro['cantidad'],
|
||||
'id_unidad_medida' => $registro['id_unidad_medida'],
|
||||
'observaciones' => $registro['observaciones'],
|
||||
'fecha' => $registro['fecha'],
|
||||
]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Registros actualizados correctamente'
|
||||
], 201);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Error en el servidor',
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function update_nea_bienes(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('pecosas actualizar neas bienes')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
try {
|
||||
$rules = [
|
||||
'registros' => 'required|array',
|
||||
'registros.*.id' => 'required|exists:pecosa_bienes,id', // Agregar esta línea
|
||||
'registros.*.nea_bien_id' => 'required|exists:nea_bienes,id',
|
||||
'registros.*.descripcion' => 'string',
|
||||
'registros.*.cantidad' => 'required|numeric',
|
||||
'registros.*.id_unidad_medida' => 'required',
|
||||
'registros.*.observaciones' => 'required',
|
||||
'registros.*.fecha' => 'required|date',
|
||||
];
|
||||
|
||||
|
||||
$messages = [
|
||||
'registros.required' => 'El campo registros es obligatorio.',
|
||||
'registros.array' => 'El campo registros debe ser un arreglo.',
|
||||
'registros.*.nea_bien_id.exists' => 'El nea_bien_id no existe en la base de datos.',
|
||||
];
|
||||
|
||||
// Validación
|
||||
$validator = Validator::make($request->all(), $rules, $messages);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Errores de validación',
|
||||
'errors' => $validator->errors()
|
||||
], 422);
|
||||
}
|
||||
$data = $validator->validated();
|
||||
|
||||
// Depurar los datos antes de continuar
|
||||
\Log::info('Datos recibidos para actualizar:', $data);
|
||||
|
||||
$data = $validator->validated();
|
||||
|
||||
foreach ($data['registros'] as &$registro) {
|
||||
if (!isset($registro['id'])) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'El campo id no está presente en el registro'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$pecosaBien = PecosaBienes::find($registro['id']);
|
||||
|
||||
if (!$pecosaBien) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Registro no encontrado con ID: ' . $registro['id']
|
||||
], 404);
|
||||
}
|
||||
$temp_cantidad = $pecosaBien->cantidad;
|
||||
|
||||
if (!empty($registro['nea_bien_id'])) {
|
||||
// Si el ID de nea bien existe, actualizar la cantidad
|
||||
$inventario_neas = neaBienes::find($registro['nea_bien_id']);
|
||||
|
||||
if ($inventario_neas) {
|
||||
|
||||
// ✅ Primero, restaurar la cantidad anterior en el inventario
|
||||
$inventario_neas->cantidad += $temp_cantidad;
|
||||
|
||||
// ✅ Luego, restar la nueva cantidad
|
||||
$inventario_neas->cantidad -= floatval($registro['cantidad']);
|
||||
|
||||
// $inventario_neas->cantidad -= $registro['cantidad'];
|
||||
|
||||
if ($inventario_neas->cantidad < 0) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => "No hay suficiente stock."
|
||||
], 400);
|
||||
}
|
||||
|
||||
$inventario_neas->save();
|
||||
}
|
||||
}
|
||||
|
||||
// Actualizar los datos del bien
|
||||
$pecosaBien->update([
|
||||
'descripcion' => $registro['descripcion'],
|
||||
'cantidad' => $registro['cantidad'],
|
||||
'id_unidad_medida' => $registro['id_unidad_medida'],
|
||||
'observaciones' => $registro['observaciones'],
|
||||
'fecha' => $registro['fecha'],
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Registros guardados correctamente'
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => $e->getMessage(),
|
||||
'message' => 'Error en el servidor',
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function disableNeaBien(Request $request)
|
||||
{
|
||||
$idNeaBien = $request->input('nea_bien_id'); // Obtener el ID del body
|
||||
$idPecosaBien = $request->input('pecosa_bien_id');
|
||||
|
||||
try {
|
||||
|
||||
$ultimoRegistro = DB::table('pecosa_bienes')->where('id', $idPecosaBien)
|
||||
->orderBy('created_at', 'desc')
|
||||
->first();
|
||||
|
||||
if (!$ultimoRegistro) {
|
||||
return response()->json(['mensaje' => 'No se encontró ningún registro en pecosa_bienes'], 404);
|
||||
}
|
||||
|
||||
// Obtener el registro de nea_bienes
|
||||
$neaBien = DB::table('nea_bienes')->where('id', $idNeaBien)->first();
|
||||
|
||||
if (!$neaBien) {
|
||||
return response()->json(['mensaje' => 'Nea bienes no encontrado'], 404);
|
||||
}
|
||||
|
||||
// Sumar la cantidad del último registro de pecosa_bienes a nea_bienes
|
||||
$nuevaCantidad = $neaBien->cantidad + $ultimoRegistro->cantidad;
|
||||
|
||||
// Actualizar la cantidad y cambiar el estado a inactivo (status = 0)
|
||||
$updated = DB::table('nea_bienes')
|
||||
->where('id', $idNeaBien)
|
||||
->update([
|
||||
'cantidad' => $nuevaCantidad,
|
||||
]);
|
||||
$updatedPecosa = DB::table('pecosa_bienes')
|
||||
->where('id', $idPecosaBien)
|
||||
->update([
|
||||
'status' => 0,
|
||||
]);
|
||||
if ($updated) {
|
||||
return response()->json(['mensaje' => 'Nea bienes actualizado'], 201);
|
||||
} else {
|
||||
return response()->json(['mensaje' => 'Nea bienes no encontrado'], 404);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function enableNeaBien(Request $request)
|
||||
{
|
||||
$idNeaBien = $request->input('nea_bien_id'); // Obtener el ID del body
|
||||
$idPecosaBien = $request->input('pecosa_bien_id');
|
||||
|
||||
try {
|
||||
|
||||
$ultimoRegistro = DB::table('pecosa_bienes')->where('id', $idPecosaBien)
|
||||
->orderBy('created_at', 'desc')
|
||||
->first();
|
||||
|
||||
if (!$ultimoRegistro) {
|
||||
return response()->json(['mensaje' => 'No se encontró ningún registro en pecosa_bienes'], 404);
|
||||
}
|
||||
|
||||
// Obtener el registro de nea_bienes
|
||||
$neaBien = DB::table('nea_bienes')->where('id', $idNeaBien)->first();
|
||||
|
||||
if (!$neaBien) {
|
||||
return response()->json(['mensaje' => 'Nea bienes no encontrado'], 404);
|
||||
}
|
||||
|
||||
if ($ultimoRegistro->cantidad > $neaBien->cantidad || $neaBien->cantidad <= 0) {
|
||||
return response()->json(['mensaje' => 'La cantidad excede al stock disponible'], 400);
|
||||
}
|
||||
|
||||
// Sumar la cantidad del último registro de pecosa_bienes a nea_bienes
|
||||
$nuevaCantidad = $neaBien->cantidad - $ultimoRegistro->cantidad;
|
||||
|
||||
// Actualizar la cantidad y cambiar el estado a inactivo (status = 0)
|
||||
$updated = DB::table('nea_bienes')
|
||||
->where('id', $idNeaBien)
|
||||
->update([
|
||||
'cantidad' => $nuevaCantidad,
|
||||
]);
|
||||
$updatedPecosa = DB::table('pecosa_bienes')
|
||||
->where('id', $idPecosaBien)
|
||||
->update([
|
||||
'status' => 1,
|
||||
]);
|
||||
if ($updated) {
|
||||
return response()->json(['mensaje' => 'Nea bienes actualizado'], 201);
|
||||
} else {
|
||||
return response()->json(['mensaje' => 'Nea bienes no encontrado'], 404);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function disableInevntarioBien(Request $request)
|
||||
{
|
||||
$idInventarioBien = $request->input('inventario_bien_id'); // Obtener el ID del body
|
||||
$idPecosaBien = $request->input('pecosa_bien_id');
|
||||
|
||||
try {
|
||||
|
||||
$ultimoRegistro = DB::table('pecosa_bienes')->where('id', $idPecosaBien)
|
||||
->orderBy('created_at', 'desc')
|
||||
->first();
|
||||
|
||||
if (!$ultimoRegistro) {
|
||||
return response()->json(['mensaje' => 'No se encontró ningún registro en pecosa_bienes'], 404);
|
||||
}
|
||||
|
||||
// Obtener el registro de nea_bienes
|
||||
$InventarioBien = DB::table('inventario_inicials')->where('id', $idInventarioBien)->first();
|
||||
|
||||
if (!$InventarioBien) {
|
||||
return response()->json(['mensaje' => 'Inventario bienes no encontrado'], 404);
|
||||
}
|
||||
|
||||
// Sumar la cantidad del último registro de pecosa_bienes a nea_bienes
|
||||
$nuevaCantidad = $InventarioBien->cantidad + $ultimoRegistro->cantidad;
|
||||
|
||||
// Actualizar la cantidad y cambiar el estado a inactivo (status = 0)
|
||||
$updated = DB::table('inventario_inicials')
|
||||
->where('id', $idInventarioBien)
|
||||
->update([
|
||||
'cantidad' => $nuevaCantidad,
|
||||
]);
|
||||
$updatedPecosa = DB::table('pecosa_bienes')
|
||||
->where('id', $idPecosaBien)
|
||||
->update([
|
||||
'status' => 0,
|
||||
]);
|
||||
if ($updated) {
|
||||
return response()->json(['mensaje' => 'Inventario bienes actualizado'], 201);
|
||||
} else {
|
||||
return response()->json(['mensaje' => 'Inventario bienes no encontrado'], 404);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function enableInventarioBien(Request $request)
|
||||
{
|
||||
$idInventarioBien = $request->input('inventario_bien_id'); // Obtener el ID del body
|
||||
$idPecosaBien = $request->input('pecosa_bien_id');
|
||||
|
||||
try {
|
||||
|
||||
$ultimoRegistro = DB::table('pecosa_bienes')->where('id', $idPecosaBien)
|
||||
->orderBy('created_at', 'desc')
|
||||
->first();
|
||||
|
||||
if (!$ultimoRegistro) {
|
||||
return response()->json(['mensaje' => 'No se encontró ningún registro en pecosa_bienes'], 404);
|
||||
}
|
||||
|
||||
// Obtener el registro de nea_bienes
|
||||
$inventarioBien = DB::table('inventario_inicials')->where('id', $idInventarioBien)->first();
|
||||
|
||||
if (!$inventarioBien) {
|
||||
return response()->json(['mensaje' => 'Invenetario bienes no encontrado'], 404);
|
||||
}
|
||||
|
||||
if ($ultimoRegistro->cantidad > $inventarioBien->cantidad || $inventarioBien->cantidad <= 0) {
|
||||
return response()->json(['mensaje' => 'La cantidad excede al stock disponible'], 400);
|
||||
}
|
||||
|
||||
// Sumar la cantidad del último registro de pecosa_bienes a nea_bienes
|
||||
$nuevaCantidad = $inventarioBien->cantidad - $ultimoRegistro->cantidad;
|
||||
|
||||
// Actualizar la cantidad y cambiar el estado a inactivo (status = 0)
|
||||
$updated = DB::table('inventario_inicials')
|
||||
->where('id', $idInventarioBien)
|
||||
->update([
|
||||
'cantidad' => $nuevaCantidad,
|
||||
]);
|
||||
$updatedPecosa = DB::table('pecosa_bienes')
|
||||
->where('id', $idPecosaBien)
|
||||
->update([
|
||||
'status' => 1,
|
||||
]);
|
||||
if ($updated) {
|
||||
return response()->json(['mensaje' => 'Inventario bienes actualizado'], 201);
|
||||
} else {
|
||||
return response()->json(['mensaje' => 'Inventario bienes no encontrado'], 404);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,275 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
class PecosaPedidosController extends Controller
|
||||
{
|
||||
//
|
||||
public function index(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('pecosas vista')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
try {
|
||||
$query = DB::table('pecosa_pedidos')
|
||||
->select(
|
||||
'pecosa_pedidos.*',
|
||||
'm.meta_1',
|
||||
'm.meta_2',
|
||||
'm.obra',
|
||||
DB::raw("CONCAT(t1.nombre, ' ', t1.apellido_paterno, ' ', t1.apellido_materno) AS nombre_completo_trabajador1"),
|
||||
DB::raw("CONCAT(t2.nombre, ' ', t2.apellido_paterno, ' ', t2.apellido_materno) AS nombre_completo_trabajador2")
|
||||
)
|
||||
->join('metas as m', 'm.id', '=', 'pecosa_pedidos.id_metas')
|
||||
->join('trabajadores as t1', 't1.id', '=', 'pecosa_pedidos.id_trabajadores')
|
||||
->join('trabajadores as t2', 't2.id', '=', 'pecosa_pedidos.id_trabajadores2')
|
||||
->orderByRaw("SUBSTRING_INDEX(codigo, '-', -1) DESC, LPAD(SUBSTRING_INDEX(codigo, '-', 1), 4, '0') DESC");
|
||||
|
||||
if ($request->has('search')) {
|
||||
$search = $request->input('search');
|
||||
$query->where('pecosa_pedidos.codigo', 'like', "%$search%")
|
||||
->orWhere('nombre_completo_trabajador1', 'like', "%$search%")
|
||||
->orWhere('nombre_completo_trabajador2', 'like', "%$search%")
|
||||
->orWhere('pecosa_pedidos.id', 'like', "%$search%");
|
||||
|
||||
}
|
||||
|
||||
return response()->json(['data' => $query->get()], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['valid' => false], 401);
|
||||
}
|
||||
}
|
||||
|
||||
public function listEnable()
|
||||
{
|
||||
|
||||
try {
|
||||
$data = DB::table('pecosa_pedidos')
|
||||
->select(
|
||||
'pecosa_pedidos.*',
|
||||
'm.meta_1',
|
||||
'm.meta_2',
|
||||
'm.obra',
|
||||
DB::raw("CONCAT(t1.nombre, ' ', t1.apellido_paterno, ' ', t1.apellido_materno) AS nombre_completo_trabajador1"),
|
||||
DB::raw("CONCAT(t2.nombre, ' ', t2.apellido_paterno, ' ', t2.apellido_materno) AS nombre_completo_trabajador2")
|
||||
)
|
||||
->join('metas as m', 'm.id', '=', 'pecosa_pedidos.id_metas')
|
||||
->join('trabajadores as t1', 't1.id', '=', 'pecosa_pedidos.id_trabajadores')
|
||||
->join('trabajadores as t2', 't2.id', '=', 'pecosa_pedidos.id_trabajadores2')
|
||||
->orderByRaw("SUBSTRING_INDEX(codigo, '-', -1) DESC, LPAD(SUBSTRING_INDEX(codigo, '-', 1), 4, '0') DESC")
|
||||
->where('pecosa_pedidos.status', 1)
|
||||
->get();
|
||||
|
||||
|
||||
return response()->json(['data' => $data], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['valid' => false], 401);
|
||||
}
|
||||
}
|
||||
|
||||
public function listDisable()
|
||||
{
|
||||
|
||||
|
||||
try {
|
||||
$data = DB::table('pecosa_pedidos')
|
||||
->select(
|
||||
'pecosa_pedidos.*',
|
||||
'm.meta_1',
|
||||
'm.meta_2',
|
||||
'm.obra',
|
||||
DB::raw("CONCAT(t1.nombre, ' ', t1.apellido_paterno, ' ', t1.apellido_materno) AS nombre_completo_trabajador1"),
|
||||
DB::raw("CONCAT(t2.nombre, ' ', t2.apellido_paterno, ' ', t2.apellido_materno) AS nombre_completo_trabajador2")
|
||||
)
|
||||
->join('metas as m', 'm.id', '=', 'pecosa_pedidos.id_metas')
|
||||
->join('trabajadores as t1', 't1.id', '=', 'pecosa_pedidos.id_trabajadores')
|
||||
->join('trabajadores as t2', 't2.id', '=', 'pecosa_pedidos.id_trabajadores2')
|
||||
->orderByRaw("SUBSTRING_INDEX(codigo, '-', -1) DESC, LPAD(SUBSTRING_INDEX(codigo, '-', 1), 4, '0') DESC")
|
||||
->where('pecosa_pedidos.status', 1)
|
||||
->get();
|
||||
|
||||
|
||||
return response()->json(['data' => $data], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['valid' => false], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('pecosas crear')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
try {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'id_trabajadores' => 'nullable|string',
|
||||
'id_trabajadores2' => 'nullable|string',
|
||||
'id_metas' => 'nullable|string',
|
||||
'dependencias' => 'required|string',
|
||||
'tipo_de_sede' => 'nullable|string',
|
||||
'fecha' => 'required|date',
|
||||
'almacen' => 'required|string',
|
||||
'oficio' => 'required|string',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json($validator->errors(), 422);
|
||||
}
|
||||
|
||||
$year = date('Y');
|
||||
// Buscar el último código del año actual
|
||||
$ultimoCodigo = DB::table('pecosa_pedidos')
|
||||
->where('codigo', 'like', "%-$year")
|
||||
->orderByDesc('codigo')
|
||||
->first();
|
||||
if ($ultimoCodigo) {
|
||||
// Extraer el número y sumarle 1
|
||||
$ultimoNumero = intval(explode('-', $ultimoCodigo->codigo)[0]);
|
||||
$nuevoNumero = str_pad($ultimoNumero + 1, 4, '0', STR_PAD_LEFT);
|
||||
} else {
|
||||
// Si no hay registros en el año, empezar desde 0001
|
||||
$nuevoNumero = '0001';
|
||||
}
|
||||
$codigo = "$nuevoNumero-$year";
|
||||
|
||||
|
||||
DB::table('pecosa_pedidos')->insert([
|
||||
'id' => Str::uuid(),
|
||||
'codigo' => $codigo,
|
||||
'id_trabajadores' => $request->id_trabajadores,
|
||||
'id_trabajadores2' => $request->id_trabajadores2,
|
||||
'id_metas' => $request->id_metas,
|
||||
'dependencias' => $request->dependencias,
|
||||
'tipo_de_sede' => $request->tipo_de_sede,
|
||||
'fecha' => $request->fecha,
|
||||
'almacen' => $request->almacen,
|
||||
'oficio' => $request->oficio,
|
||||
'status' => 1,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
return response()->json(['mensaje' => 'Pedido creado'], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('pecosas vista')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
try {
|
||||
$query = DB::table('pecosa_pedidos')
|
||||
->select(
|
||||
'pecosa_pedidos.*',
|
||||
'm.meta_1',
|
||||
'm.meta_2',
|
||||
'm.obra',
|
||||
DB::raw("DATE_FORMAT(pecosa_pedidos.fecha, '%Y-%m-%d') as fecha"),
|
||||
DB::raw("CONCAT(t1.nombre, ' ', t1.apellido_paterno, ' ', t1.apellido_materno) AS nombre_completo_trabajador1"),
|
||||
DB::raw("CONCAT(t2.nombre, ' ', t2.apellido_paterno, ' ', t2.apellido_materno) AS nombre_completo_trabajador2")
|
||||
)
|
||||
->join('metas as m', 'm.id', '=', 'pecosa_pedidos.id_metas')
|
||||
->join('trabajadores as t1', 't1.id', '=', 'pecosa_pedidos.id_trabajadores')
|
||||
->join('trabajadores as t2', 't2.id', '=', 'pecosa_pedidos.id_trabajadores2')
|
||||
->where('pecosa_pedidos.id', $id)
|
||||
->first();
|
||||
|
||||
return response()->json(['data' => $query], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('pecosas editar')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
try {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'codigo' => 'nullable|string',
|
||||
'id_trabajadores' => 'nullable|string',
|
||||
'id_trabajadores2' => 'nullable|string',
|
||||
'id_metas' => 'nullable|string',
|
||||
'dependencias' => 'required|string',
|
||||
'tipo_de_sede' => 'nullable|string',
|
||||
'fecha' => 'required|date',
|
||||
'almacen' => 'required|string',
|
||||
'oficio' => 'required|string',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json($validator->errors(), 422);
|
||||
}
|
||||
|
||||
$updated = DB::table('pecosa_pedidos')
|
||||
->where('id', $id)
|
||||
->update($request->only(['codigo', 'id_trabajadores', 'id_trabajadores2', 'id_metas', 'dependencias', 'tipo_de_sede', 'fecha', 'almacen', 'oficio', 'updated_at' => now()]));
|
||||
|
||||
if ($updated) {
|
||||
return response()->json(['mensaje' => 'Pedido actualizado'], 201);
|
||||
} else {
|
||||
return response()->json(['mensaje' => 'Pedido no encontrado'], 404);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function disable(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('pecosas editar')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
$id = $request->input('id'); // Obtener el ID del body
|
||||
|
||||
if (!$id) {
|
||||
return response()->json(['error' => 'ID requerido'], 400);
|
||||
}
|
||||
|
||||
try {
|
||||
$updated = DB::table('pecosa_pedidos')
|
||||
->where('id', $id)
|
||||
->update(['status' => 0]);
|
||||
|
||||
if ($updated) {
|
||||
return response()->json(['mensaje' => 'Pedido deshabilitado'], 201);
|
||||
} else {
|
||||
return response()->json(['mensaje' => 'Pedido no encontrado'], 404);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function enable(Request $request)
|
||||
{
|
||||
$id = $request->input('id'); // Obtener el ID del body
|
||||
|
||||
if (!$id) {
|
||||
return response()->json(['error' => 'ID requerido'], 400);
|
||||
}
|
||||
|
||||
try {
|
||||
$updated = DB::table('pecosa_pedidos')
|
||||
->where('id', $id)
|
||||
->update(['status' => 1]);
|
||||
|
||||
if ($updated) {
|
||||
return response()->json(['mensaje' => 'Pedido deshabilitado'], 201);
|
||||
} else {
|
||||
return response()->json(['mensaje' => 'Pedido no encontrado'], 404);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class ReporteController extends Controller
|
||||
{
|
||||
public function getStockReport()
|
||||
{
|
||||
$year = Carbon::now()->year;
|
||||
$today = Carbon::now()->toDateString();
|
||||
|
||||
|
||||
$neasBienesSinStock = DB::table('nea_bienes')
|
||||
->where('cantidad', 0)
|
||||
->count();
|
||||
|
||||
$invBienesSinStock = DB::table('inventario_inicials')
|
||||
->where('cantidad', 0)
|
||||
->count();
|
||||
|
||||
$neasBienesConStock = DB::table('nea_bienes')
|
||||
->where('cantidad', '>', 0)
|
||||
->count();
|
||||
|
||||
$invBienesConStock = DB::table('inventario_inicials')
|
||||
->where('cantidad', '>', 0)
|
||||
->count();
|
||||
|
||||
// Contar registros en la tabla `pecosa_pedidos` con el año actual en `codigo`
|
||||
$cantidadPecosa = DB::table('pecosa_pedidos')
|
||||
// ->whereRaw("SUBSTRING_INDEX(codigo, '-', -1) = ?", [$year])
|
||||
->count();
|
||||
|
||||
// Contar registros en la tabla `nea_entradas` con el año actual en `codigo`
|
||||
$cantidadNeas = DB::table('nea_entradas')
|
||||
// ->whereRaw("SUBSTRING_INDEX(codigo, '-', -1) = ?", [$year])
|
||||
->count();
|
||||
|
||||
return response()->json([
|
||||
'year' => $year,
|
||||
'neas_bienes_sin_stock' => $neasBienesSinStock,
|
||||
'inv_bienes_sin_stock' => $invBienesSinStock,
|
||||
'neas_bienes_con_stock' => $neasBienesConStock,
|
||||
'inv_bienes_con_stock' => $invBienesConStock,
|
||||
'cantidad_pecosa' => $cantidadPecosa,
|
||||
'cantidad_neas' => $cantidadNeas,
|
||||
]);
|
||||
}
|
||||
}
|
@ -0,0 +1,218 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\User;
|
||||
use Spatie\Permission\Models\Role;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Exception;
|
||||
|
||||
class RoleController extends Controller
|
||||
{
|
||||
|
||||
public function assignPermissionsToRole(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('usuarios administrar usuarios')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => '"Lo sentimos, pero no tiene autorización para realizar esta acción."'], 403);
|
||||
}
|
||||
try {
|
||||
$request->validate([
|
||||
'user_id' => 'required|exists:users,id',
|
||||
'permissions' => 'required|array',
|
||||
'permissions.*' => 'string|exists:permissions,name'
|
||||
]);
|
||||
$user = User::findOrFail($request->user_id); // Buscar usuario por ID
|
||||
/// $role = Role::findByName($request->role); // Especifica el guard
|
||||
//$user->syncPermissions($request->permissions);
|
||||
foreach ($request->permissions as $permission) {
|
||||
$user->givePermissionTo($permission);
|
||||
}
|
||||
return response()->json(['message' => 'Permisos asignados correctamente'], 201);
|
||||
} catch (Exception $e) {
|
||||
return response()->json(['error' => 'Error al asignar permisos', 'message' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function removePermissionsUser(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('usuarios administrar usuarios')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => '"Lo sentimos, pero no tiene autorización para realizar esta acción."'], 403);
|
||||
}
|
||||
try {
|
||||
$request->validate([
|
||||
'user_id' => 'required|exists:users,id',
|
||||
'permissions' => 'required|array',
|
||||
'permissions.*' => 'string|exists:permissions,name'
|
||||
]);
|
||||
$user = User::findOrFail($request->user_id); // Buscar usuario por ID
|
||||
/// $role = Role::findByName($request->role); // Especifica el guard
|
||||
$user->revokePermissionTo($request->permissions);
|
||||
|
||||
return response()->json(['message' => 'Permisos asignados correctamente'], 201);
|
||||
} catch (Exception $e) {
|
||||
return response()->json(['error' => 'Error al asignar permisos', 'message' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
// obtener permisos de un usuario
|
||||
public function getUserPermissions($id)
|
||||
{
|
||||
|
||||
try {
|
||||
$user = User::findOrFail($id);
|
||||
return response()->json($user->getPermissionNames(), 201);
|
||||
} catch (Exception $e) {
|
||||
return response()->json(['error' => 'Error al asignar permisos', 'message' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
// Obtener permisos de un rol
|
||||
public function getPermissionsByRole($roleName)
|
||||
{
|
||||
try {
|
||||
$role = Role::findByName($roleName);
|
||||
$permissions = $role->permissions->pluck('name'); // Lista de permisos
|
||||
|
||||
return response()->json(['role' => $roleName, 'permissions' => $permissions], 201);
|
||||
} catch (Exception $e) {
|
||||
return response()->json(['error' => 'Error al obtener permisos', 'message' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
public function getAllPermissions()
|
||||
{
|
||||
try {
|
||||
$permissions = Permission::pluck('name'); // Obtiene todos los permisos
|
||||
|
||||
return response()->json(['permissions' => $permissions], 201);
|
||||
} catch (Exception $e) {
|
||||
return response()->json(['error' => 'Error al obtener permisos', 'message' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
// Quitar permisos a un rol
|
||||
public function removePermissionsFromRole(Request $request)
|
||||
{
|
||||
try {
|
||||
$request->validate([
|
||||
'role' => 'required|string|exists:roles,name',
|
||||
'permissions' => 'required|array',
|
||||
'permissions.*' => 'string|exists:permissions,name'
|
||||
]);
|
||||
|
||||
$role = Role::findByName($request->role);
|
||||
$role->revokePermissionTo($request->permissions); // Elimina permisos específicos
|
||||
|
||||
return response()->json(['message' => 'Permisos eliminados correctamente']);
|
||||
} catch (Exception $e) {
|
||||
return response()->json(['error' => 'Error al eliminar permisos', 'message' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
public function createRole(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('usuarios administrar usuarios')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => '"Lo sentimos, pero no tiene autorización para realizar esta acción."'], 403);
|
||||
}
|
||||
try {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'name' => 'required|string|unique:roles,name'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json($validator->errors(), 422);
|
||||
}
|
||||
|
||||
Role::create(['name' => $request->name]);
|
||||
|
||||
return response()->json(['message' => 'Rol creado correctamente'], 201);
|
||||
} catch (Exception $e) {
|
||||
return response()->json(['error' => 'Error al crear el rol', 'message' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function updateRole(Request $request, $id)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('usuarios administrar usuarios')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => '"Lo sentimos, pero no tiene autorización para realizar esta acción."'], 403);
|
||||
}
|
||||
try {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'name' => 'required|string|unique:roles,name,' . $id
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json($validator->errors(), 422);
|
||||
}
|
||||
|
||||
$role = Role::findOrFail($id);
|
||||
$role->update(['name' => $request->name]);
|
||||
|
||||
return response()->json(['message' => 'Rol actualizado correctamente'], 201);
|
||||
} catch (Exception $e) {
|
||||
return response()->json(['error' => 'Error al actualizar el rol', 'message' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function getIdRole(Request $request, $id)
|
||||
{
|
||||
try {
|
||||
|
||||
$role = Role::findOrFail($id);
|
||||
return response()->json(['data' => $role], 201);
|
||||
} catch (Exception $e) {
|
||||
return response()->json(['error' => 'Error al actualizar el rol', 'message' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function listEnableData(Request $request)
|
||||
{
|
||||
try {
|
||||
|
||||
$data = DB::table('roles')
|
||||
->get();
|
||||
|
||||
return response()->json(['data' => $data], 201);
|
||||
} catch (Exception $e) {
|
||||
return response()->json(['error' => 'Error al crear el rol', 'message' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
// Crear un usuario y asignarle un rol
|
||||
public function createUserWithRole(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('usuarios administrar usuarios')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => '"Lo sentimos, pero no tiene autorización para realizar esta acción."'], 403);
|
||||
}
|
||||
try {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'name' => 'required|string',
|
||||
'email' => 'required|email|unique:users,email',
|
||||
'fullname' => 'required|string',
|
||||
'fullname2' => 'required|string',
|
||||
'role' => 'required|string|exists:roles,name',
|
||||
'password' => 'required|string|min:6'
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
return response()->json($validator->errors(), 422);
|
||||
}
|
||||
$user = User::create([
|
||||
'name' => $request->name,
|
||||
'email' => $request->email,
|
||||
'fullname' => $request->fullname,
|
||||
'fullname2' => $request->fullname2,
|
||||
'role' => $request->role,
|
||||
'password' => Hash::make($request->password)
|
||||
]);
|
||||
|
||||
// Asignar rol al usuario
|
||||
$user->assignRole($request->role);
|
||||
|
||||
return response()->json(['message' => 'Usuario creado y rol asignado'], 201);
|
||||
} catch (Exception $e) {
|
||||
return response()->json(['error' => 'Error al crear usuario', 'message' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,198 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
use App\Models\sedes;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class SedesController extends Controller
|
||||
{
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
try {
|
||||
|
||||
$query = DB::table('sedes');
|
||||
|
||||
// Búsqueda dinámica
|
||||
if ($request->has('search')) {
|
||||
$search = $request->input('search');
|
||||
$query->where('sede', 'like', "%$search%")
|
||||
->orWhere('responsable', 'like', "%$search%")
|
||||
->orWhere('id', 'like', "%$search%");
|
||||
}
|
||||
|
||||
// Obtener los resultados sin paginación
|
||||
$data = $query->get();
|
||||
|
||||
// Devolver la respuesta JSON con los datos
|
||||
return response()->json([
|
||||
'data' => $data,
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['valid' => false], 401);
|
||||
}
|
||||
}
|
||||
// public function index(Request $request)
|
||||
// {
|
||||
// try {
|
||||
// $perPage = $request->input('per_page', 5);
|
||||
// $page = $request->input('page', 1);
|
||||
// $query = DB::table('unidad_medidas');
|
||||
|
||||
// // Búsqueda dinámica
|
||||
// if ($request->has('search')) {
|
||||
// $search = $request->input('search');
|
||||
// $query->where('nombre', 'like', "%$search%")
|
||||
// ->orWhere('abreviatura', 'like', "%$search%")
|
||||
// ->orWhere('id', 'like', "%$search%");
|
||||
// }
|
||||
|
||||
// $users = $query->paginate($perPage, ['*'], 'page', $page);
|
||||
|
||||
// return response()->json([
|
||||
// 'data' => $users->items(),
|
||||
// 'total' => $users->total(),
|
||||
// 'current_page' => $users->currentPage(),
|
||||
// 'per_page' => $users->perPage(),
|
||||
// ], 200);
|
||||
// } catch (\Exception $e) {
|
||||
// return response()->json(['valid' => false], 401);
|
||||
// }
|
||||
// }
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
try{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'cuenta_de_costo' => 'required|string',
|
||||
'descripcion' => 'required|string',
|
||||
'sede' => 'required|string',
|
||||
'responsable' => 'required|string',
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
return response()->json($validator->errors(), 422);
|
||||
}
|
||||
|
||||
DB::table('sedes')->insert([
|
||||
'id' => Str::uuid(),
|
||||
'cuenta_de_costo' => $request->cuenta_de_costo,
|
||||
'descripcion' => $request->descripcion,
|
||||
'sede' => $request->sede,
|
||||
'responsable' => $request->responsable,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
return response()->json(['mensaje' => 'Sede creado'], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(Request $request, $id)
|
||||
{
|
||||
//$query = DB::table('unidad_medidas')->where('id', $id)->first();
|
||||
try {
|
||||
|
||||
$query = DB::table('sedes')->where('id', $id)->first();
|
||||
|
||||
// Devolver la respuesta JSON con los datos
|
||||
return response()->json([
|
||||
'data' => $query,
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(sedes $sedes)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
try {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'cuenta_de_costo' => 'required|string',
|
||||
'descripcion' => 'required|string',
|
||||
'sede' => 'required|string',
|
||||
'responsable' => 'required|string',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json($validator->errors(), 422);
|
||||
}
|
||||
|
||||
$updated = DB::table('sedes')
|
||||
->where('id', $id)
|
||||
->update([
|
||||
'cuenta_de_costo' => $request->cuenta_de_costo,
|
||||
'descripcion' => $request->descripcion,
|
||||
'sede' => $request->sede,
|
||||
'responsable' => $request->responsable,
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
if ($updated) {
|
||||
return response()->json(['mensaje' => 'Sede actualizado'], 201);
|
||||
} else {
|
||||
return response()->json(['mensaje' => 'Sede no encontradao'], 404);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(sedes $sedes): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function disable(Request $request, $id)
|
||||
{
|
||||
try {
|
||||
|
||||
$updated = DB::table('sedes')
|
||||
->where('id', $id)
|
||||
->update([
|
||||
'status' => 0,
|
||||
]);
|
||||
|
||||
if ($updated) {
|
||||
return response()->json(['mensaje' => 'Sede actualizado'], 201);
|
||||
} else {
|
||||
return response()->json(['mensaje' => 'Sede no encontrado'], 404);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,277 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\trabajadores;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class TrabajadoresController extends Controller
|
||||
{
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('trabajadores vista')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
try {
|
||||
|
||||
$query = DB::table('trabajadores');
|
||||
|
||||
// Búsqueda dinámica
|
||||
if ($request->has('search')) {
|
||||
$search = $request->input('search');
|
||||
$query->where('nombre', 'like', "%$search%")
|
||||
->orWhere('apellido_paterno', 'like', "%$search%")
|
||||
->orWhere('apellido_materno', 'like', "%$search%")
|
||||
->orWhere('dni', 'like', "%$search%")
|
||||
->orWhere('id', 'like', "%$search%");
|
||||
}
|
||||
|
||||
// Obtener los resultados sin paginación
|
||||
$data = $query->get();
|
||||
|
||||
// Devolver la respuesta JSON con los datos
|
||||
return response()->json([
|
||||
'data' => $data,
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['valid' => false], 401);
|
||||
}
|
||||
}
|
||||
// public function index(Request $request)
|
||||
// {
|
||||
// try {
|
||||
// $perPage = $request->input('per_page', 5);
|
||||
// $page = $request->input('page', 1);
|
||||
// $query = DB::table('unidad_medidas');
|
||||
|
||||
// // Búsqueda dinámica
|
||||
// if ($request->has('search')) {
|
||||
// $search = $request->input('search');
|
||||
// $query->where('nombre', 'like', "%$search%")
|
||||
// ->orWhere('abreviatura', 'like', "%$search%")
|
||||
// ->orWhere('id', 'like', "%$search%");
|
||||
// }
|
||||
|
||||
// $users = $query->paginate($perPage, ['*'], 'page', $page);
|
||||
|
||||
// return response()->json([
|
||||
// 'data' => $users->items(),
|
||||
// 'total' => $users->total(),
|
||||
// 'current_page' => $users->currentPage(),
|
||||
// 'per_page' => $users->perPage(),
|
||||
// ], 200);
|
||||
// } catch (\Exception $e) {
|
||||
// return response()->json(['valid' => false], 401);
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
public function listEnable(Request $request)
|
||||
{
|
||||
try {
|
||||
|
||||
$data = DB::table('trabajadores')
|
||||
->where('trabajadores.status', 1)
|
||||
->get();
|
||||
// Devolver la respuesta JSON con los datos
|
||||
return response()->json([
|
||||
'data' => $data,
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['valid' => false], 401);
|
||||
}
|
||||
}
|
||||
public function listEnableData(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('trabajadores vista')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
try {
|
||||
|
||||
$data = DB::table('trabajadores')
|
||||
->where('trabajadores.status', 1)
|
||||
->get();
|
||||
// Devolver la respuesta JSON con los datos
|
||||
return response()->json([
|
||||
'data' => $data,
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['valid' => false], 401);
|
||||
}
|
||||
}
|
||||
public function listDisableData(Request $request)
|
||||
{
|
||||
|
||||
if (!auth()->user()->hasPermissionTo('trabajadores vista')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
try {
|
||||
|
||||
$data = DB::table('trabajadores')
|
||||
->where('trabajadores.status', 0)
|
||||
->get();
|
||||
// Devolver la respuesta JSON con los datos
|
||||
return response()->json([
|
||||
'data' => $data,
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['valid' => false], 401);
|
||||
}
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('trabajadores crear')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
try{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'dni' => 'required|numeric|digits:8',
|
||||
'nombre' => 'required|string',
|
||||
'apellido_paterno' => 'required|string',
|
||||
'apellido_materno' => 'required|string',
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
return response()->json($validator->errors(), 422);
|
||||
}
|
||||
|
||||
DB::table('trabajadores')->insert([
|
||||
'id' => Str::uuid(),
|
||||
'dni' => $request->dni,
|
||||
'nombre' => $request->nombre,
|
||||
'apellido_paterno' => $request->apellido_paterno,
|
||||
'apellido_materno' => $request->apellido_materno,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
return response()->json(['mensaje' => 'Trabajador creado'], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function show(Request $request, $id)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('trabajadores vista')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
//$query = DB::table('unidad_medidas')->where('id', $id)->first();
|
||||
try {
|
||||
|
||||
$query = DB::table('trabajadores')->where('id', $id)->first();
|
||||
|
||||
// Devolver la respuesta JSON con los datos
|
||||
return response()->json([
|
||||
'data' => $query,
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('trabajadores editar')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
try {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'dni' => 'required|string',
|
||||
'nombre' => 'required|string',
|
||||
'apellido_paterno' => 'required|string',
|
||||
'apellido_materno' => 'required|string',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json($validator->errors(), 422);
|
||||
}
|
||||
|
||||
$updated = DB::table('trabajadores')
|
||||
->where('id', $id)
|
||||
->update([
|
||||
'dni' => $request->dni,
|
||||
'nombre' => $request->nombre,
|
||||
'apellido_paterno' => $request->apellido_paterno,
|
||||
'apellido_materno' => $request->apellido_materno,
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
if ($updated) {
|
||||
return response()->json(['mensaje' => 'Trabajadores actualizado'], 201);
|
||||
} else {
|
||||
return response()->json(['mensaje' => 'Trabajador no encontradao'], 404);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy(trabajadores $trabajadores)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function disable(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('trabajadores deshabilitar')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
$id = $request->input('id'); // Obtener el ID del body
|
||||
|
||||
if (!$id) {
|
||||
return response()->json(['error' => 'ID requerido'], 400);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
$updated = DB::table('trabajadores')
|
||||
->where('id', $id)
|
||||
->update([
|
||||
'status' => 0,
|
||||
]);
|
||||
|
||||
if ($updated) {
|
||||
return response()->json(['mensaje' => 'Trabajador deshabilitado'], 201);
|
||||
} else {
|
||||
return response()->json(['mensaje' => 'Trabajador no encontrado'], 404);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function enable(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('trabajadores habilitar')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
$id = $request->input('id'); // Obtener el ID del body
|
||||
|
||||
if (!$id) {
|
||||
return response()->json(['error' => 'ID requerido'], 400);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
$updated = DB::table('trabajadores')
|
||||
->where('id', $id)
|
||||
->update([
|
||||
'status' => 1,
|
||||
]);
|
||||
|
||||
if ($updated) {
|
||||
return response()->json(['mensaje' => 'Trabajador habilitado'], 201);
|
||||
} else {
|
||||
return response()->json(['mensaje' => 'Trabajador no encontrado'], 404);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,231 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\UnidadMedida;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class UnidadMedidaController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
|
||||
// if (!auth()->user()->hasPermissionTo(permission: 'unidad de medida vista')) {
|
||||
// return response()->json(['valid' => false, 'error' => 'Usted no esta autorizado'], 403);
|
||||
// }
|
||||
if (!auth()->user()->hasPermissionTo('unidad_medida vista')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
try {
|
||||
$query = DB::table('unidad_medidas');
|
||||
// Búsqueda dinámica
|
||||
if ($request->has('search')) {
|
||||
$search = $request->input('search');
|
||||
$query->where('nombre', 'like', "%$search%")
|
||||
->orWhere('abreviatura', 'like', "%$search%")
|
||||
->orWhere('id', 'like', "%$search%");
|
||||
}
|
||||
// Obtener los resultados sin paginación
|
||||
$data = $query->get();
|
||||
// Devolver la respuesta JSON con los datos
|
||||
return response()->json([
|
||||
'data' => $data,
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['valid' => false], 401);
|
||||
}
|
||||
}
|
||||
public function listEnable(Request $request)
|
||||
{
|
||||
|
||||
try {
|
||||
$data = DB::table('unidad_medidas')
|
||||
->where('status', 1)
|
||||
->get();
|
||||
|
||||
return response()->json([
|
||||
'data' => $data,
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['valid' => false, 'error' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function listEnableData(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('unidad_medida vista')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
try {
|
||||
$data = DB::table('unidad_medidas')
|
||||
->where('status', 1)
|
||||
->get();
|
||||
|
||||
return response()->json([
|
||||
'data' => $data,
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['valid' => false, 'error' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
public function listDisableData(Request $request)
|
||||
{
|
||||
|
||||
if (!auth()->user()->hasPermissionTo('unidad_medida vista')) { // Corregido nombre del permiso
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
try {
|
||||
$data = DB::table('unidad_medidas')
|
||||
->where('status', 0)
|
||||
->get();
|
||||
|
||||
return response()->json([
|
||||
'data' => $data,
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['valid' => false, 'error' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('unidad_medida crear')) { // Corregido
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
try {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'nombre' => 'required|string',
|
||||
'abreviatura' => 'required|string',
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
return response()->json($validator->errors(), 422);
|
||||
}
|
||||
|
||||
DB::table('unidad_medidas')->insert([
|
||||
'id' => Str::uuid(),
|
||||
'nombre' => $request->nombre,
|
||||
'abreviatura' => $request->abreviatura,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
return response()->json(['mensaje' => 'Unidad de medida creada'], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function show(Request $request, $id)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('unidad_medida vista')) { // Corregido
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
//$query = DB::table('unidad_medidas')->where('id', $id)->first();
|
||||
try {
|
||||
$query = DB::table('unidad_medidas')->where('id', $id)->first();
|
||||
// Devolver la respuesta JSON con los datos
|
||||
return response()->json([
|
||||
'data' => $query,
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('unidad_medida editar')) { // Corregido
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
|
||||
try {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'nombre' => 'required|string',
|
||||
'abreviatura' => 'required|string',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json($validator->errors(), 422);
|
||||
}
|
||||
|
||||
$updated = DB::table('unidad_medidas')
|
||||
->where('id', $id)
|
||||
->update([
|
||||
'nombre' => $request->nombre,
|
||||
'abreviatura' => $request->abreviatura,
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
if ($updated) {
|
||||
return response()->json(['mensaje' => 'Unidad de medida actualizada'], 201);
|
||||
} else {
|
||||
return response()->json(['mensaje' => 'Unidad de medida no encontrada'], 404);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function disable(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('unidad_medida deshabilitar')) { // Corregido
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
$id = $request->input('id'); // Obtener el ID del body
|
||||
|
||||
if (!$id) {
|
||||
return response()->json(['error' => 'ID requerido'], 400);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
$updated = DB::table('unidad_medidas')
|
||||
->where('id', $id)
|
||||
->update([
|
||||
'status' => 0,
|
||||
]);
|
||||
|
||||
if ($updated) {
|
||||
return response()->json(['mensaje' => 'Unidad de medida deshabilitada'], 201);
|
||||
} else {
|
||||
return response()->json(['mensaje' => 'Unidad de medida no encontrada'], 404);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function enable(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('unidad_medida habilitar')) { // Corregido
|
||||
return response()->json(['valid' => false, 'error' => 'Lo sentimos, pero no tiene autorización para realizar esta acción.'], 403);
|
||||
}
|
||||
$id = $request->input('id'); // Obtener el ID del body
|
||||
|
||||
if (!$id) {
|
||||
return response()->json(['error' => 'ID requerido'], 400);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
$updated = DB::table('unidad_medidas')
|
||||
->where('id', $id)
|
||||
->update([
|
||||
'status' => 1,
|
||||
]);
|
||||
|
||||
if ($updated) {
|
||||
return response()->json(['mensaje' => 'Unidad de medida habilitada'], 201);
|
||||
} else {
|
||||
return response()->json(['mensaje' => 'Unidad de medida no encontrada'], 404);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Error Server'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http;
|
||||
|
||||
use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
||||
|
||||
class Kernel extends HttpKernel
|
||||
{
|
||||
/**
|
||||
* The application's global HTTP middleware stack.
|
||||
*
|
||||
* These middleware are run during every request to your application.
|
||||
*
|
||||
* @var array<int, class-string|string>
|
||||
*/
|
||||
protected $middleware = [
|
||||
// \App\Http\Middleware\TrustHosts::class,
|
||||
\App\Http\Middleware\TrustProxies::class,
|
||||
\Illuminate\Http\Middleware\HandleCors::class,
|
||||
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||
\App\Http\Middleware\TrimStrings::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's route middleware groups.
|
||||
*
|
||||
* @var array<string, array<int, class-string|string>>
|
||||
*/
|
||||
protected $middlewareGroups = [
|
||||
'web' => [
|
||||
\App\Http\Middleware\EncryptCookies::class,
|
||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
],
|
||||
|
||||
'api' => [
|
||||
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
|
||||
\Illuminate\Routing\Middleware\ThrottleRequests::class.':api',
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's middleware aliases.
|
||||
*
|
||||
* Aliases may be used instead of class names to conveniently assign middleware to routes and groups.
|
||||
*
|
||||
* @var array<string, class-string|string>
|
||||
*/
|
||||
protected $middlewareAliases = [
|
||||
'auth' => \App\Http\Middleware\Authenticate::class,
|
||||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
||||
'auth.session' => \Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
|
||||
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
|
||||
'precognitive' => \Illuminate\Foundation\Http\Middleware\HandlePrecognitiveRequests::class,
|
||||
'signed' => \App\Http\Middleware\ValidateSignature::class,
|
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
||||
];
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class Authenticate extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the path the user should be redirected to when they are not authenticated.
|
||||
*/
|
||||
protected function redirectTo(Request $request): ?string
|
||||
{
|
||||
return $request->expectsJson() ? null : route('login');
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
|
||||
|
||||
class EncryptCookies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the cookies that should not be encrypted.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware;
|
||||
|
||||
class PreventRequestsDuringMaintenance extends Middleware
|
||||
{
|
||||
/**
|
||||
* The URIs that should be reachable while maintenance mode is enabled.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class RedirectIfAuthenticated
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, string ...$guards): Response
|
||||
{
|
||||
$guards = empty($guards) ? [null] : $guards;
|
||||
|
||||
foreach ($guards as $guard) {
|
||||
if (Auth::guard($guard)->check()) {
|
||||
return redirect(RouteServiceProvider::HOME);
|
||||
}
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
|
||||
|
||||
class TrimStrings extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the attributes that should not be trimmed.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
'current_password',
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Http\Middleware\TrustHosts as Middleware;
|
||||
|
||||
class TrustHosts extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the host patterns that should be trusted.
|
||||
*
|
||||
* @return array<int, string|null>
|
||||
*/
|
||||
public function hosts(): array
|
||||
{
|
||||
return [
|
||||
$this->allSubdomainsOfApplicationUrl(),
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Http\Middleware\TrustProxies as Middleware;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TrustProxies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The trusted proxies for this application.
|
||||
*
|
||||
* @var array<int, string>|string|null
|
||||
*/
|
||||
protected $proxies;
|
||||
|
||||
/**
|
||||
* The headers that should be used to detect proxies.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $headers =
|
||||
Request::HEADER_X_FORWARDED_FOR |
|
||||
Request::HEADER_X_FORWARDED_HOST |
|
||||
Request::HEADER_X_FORWARDED_PORT |
|
||||
Request::HEADER_X_FORWARDED_PROTO |
|
||||
Request::HEADER_X_FORWARDED_AWS_ELB;
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Routing\Middleware\ValidateSignature as Middleware;
|
||||
|
||||
class ValidateSignature extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the query string parameters that should be ignored.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
// 'fbclid',
|
||||
// 'utm_campaign',
|
||||
// 'utm_content',
|
||||
// 'utm_medium',
|
||||
// 'utm_source',
|
||||
// 'utm_term',
|
||||
];
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
|
||||
|
||||
class VerifyCsrfToken extends Middleware
|
||||
{
|
||||
/**
|
||||
* The URIs that should be excluded from CSRF verification.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Traits\UUID;
|
||||
|
||||
class UnidadMedida extends Model
|
||||
{
|
||||
use HasFactory, UUID;
|
||||
protected $fillable = [
|
||||
];
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Tymon\JWTAuth\Contracts\JWTSubject;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use Spatie\Permission\Traits\HasRoles;
|
||||
|
||||
class User extends Authenticatable implements JWTSubject
|
||||
{
|
||||
use HasApiTokens, HasFactory, Notifiable, HasRoles;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'fullname',
|
||||
'fullname2',
|
||||
'role',
|
||||
'password',
|
||||
];
|
||||
protected $guard_name = 'api'; // Asegura que esto está definido
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
|
||||
public function getJWTIdentifier()
|
||||
{
|
||||
return $this->getKey();
|
||||
}
|
||||
|
||||
public function getJWTCustomClaims()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class almacen extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class bienes extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class inventarioInicial extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'inventario_inicials'; // Asegúrate de que el nombre de la tabla sea correcto
|
||||
|
||||
protected $fillable = [
|
||||
'id', // 👈 Agregar este campo
|
||||
'descripcion',
|
||||
'bienes_id',
|
||||
'cuenta',
|
||||
'cantidad',
|
||||
'cantidad_inicial',
|
||||
'precio',
|
||||
'fecha_registro',
|
||||
'status'
|
||||
];
|
||||
|
||||
public $incrementing = false; // 👈 Indica que el ID no es autoincremental
|
||||
protected $keyType = 'string'; // 👈 Indica que el ID es de tipo string (UUID)
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class metas extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class neaBienes extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class neaEntradas extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class nea_bienes2023 extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class nea_entradas2023 extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class obras extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class pecosaBienes extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'descripcion',
|
||||
'cantidad',
|
||||
'id_unidad_medida',
|
||||
'observaciones',
|
||||
'fecha'
|
||||
];
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class pecosaPedidos extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class pecosa_2023_biene extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class pecosa_2023_pedido extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class pecosa_pedidos2023 extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class sedes extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Traits\UUID;
|
||||
|
||||
class trabajadores extends Model
|
||||
{
|
||||
use HasFactory, UUID;
|
||||
protected $fillable = [
|
||||
];
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
// use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
||||
|
||||
class AuthServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The model to policy mappings for the application.
|
||||
*
|
||||
* @var array<class-string, class-string>
|
||||
*/
|
||||
protected $policies = [
|
||||
//
|
||||
];
|
||||
|
||||
/**
|
||||
* Register any authentication / authorization services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Broadcast;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class BroadcastServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
Broadcast::routes();
|
||||
|
||||
require base_path('routes/channels.php');
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
|
||||
class EventServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The event to listener mappings for the application.
|
||||
*
|
||||
* @var array<class-string, array<int, class-string>>
|
||||
*/
|
||||
protected $listen = [
|
||||
Registered::class => [
|
||||
SendEmailVerificationNotification::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Register any events for your application.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if events and listeners should be automatically discovered.
|
||||
*/
|
||||
public function shouldDiscoverEvents(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Cache\RateLimiting\Limit;
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The path to your application's "home" route.
|
||||
*
|
||||
* Typically, users are redirected here after authentication.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public const HOME = '/home';
|
||||
|
||||
/**
|
||||
* Define your route model bindings, pattern filters, and other route configuration.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
RateLimiter::for('api', function (Request $request) {
|
||||
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
|
||||
});
|
||||
|
||||
$this->routes(function () {
|
||||
Route::middleware('api')
|
||||
->prefix('api')
|
||||
->group(base_path('routes/api.php'));
|
||||
|
||||
Route::middleware('web')
|
||||
->group(base_path('routes/web.php'));
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
trait UUID
|
||||
{
|
||||
protected static function boot ()
|
||||
{
|
||||
// Boot other traits on the Model
|
||||
parent::boot();
|
||||
|
||||
/**
|
||||
* Listen for the creating event on the user model.
|
||||
* Sets the 'id' to a UUID using Str::uuid() on the instance being created
|
||||
*/
|
||||
static::creating(function ($model) {
|
||||
if ($model->getKey() === null) {
|
||||
$model->setAttribute($model->getKeyName(), Str::uuid()->toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Tells the database not to auto-increment this field
|
||||
public function getIncrementing ()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Helps the application specify the field type in the database
|
||||
public function getKeyType ()
|
||||
{
|
||||
return 'string';
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
define('LARAVEL_START', microtime(true));
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Register The Auto Loader
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Composer provides a convenient, automatically generated class loader
|
||||
| for our application. We just need to utilize it! We'll require it
|
||||
| into the script here so that we do not have to worry about the
|
||||
| loading of any of our classes manually. It's great to relax.
|
||||
|
|
||||
*/
|
||||
|
||||
require __DIR__.'/vendor/autoload.php';
|
||||
|
||||
$app = require_once __DIR__.'/bootstrap/app.php';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Run The Artisan Application
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When we run the console application, the current CLI command will be
|
||||
| executed in this console and the response sent back to a terminal
|
||||
| or another output device for the developers. Here goes nothing!
|
||||
|
|
||||
*/
|
||||
|
||||
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
|
||||
|
||||
$status = $kernel->handle(
|
||||
$input = new Symfony\Component\Console\Input\ArgvInput,
|
||||
new Symfony\Component\Console\Output\ConsoleOutput
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Shutdown The Application
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Once Artisan has finished running, we will fire off the shutdown events
|
||||
| so that any final work may be done by the application before we shut
|
||||
| down the process. This is the last thing to happen to the request.
|
||||
|
|
||||
*/
|
||||
|
||||
$kernel->terminate($input, $status);
|
||||
|
||||
exit($status);
|
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Create The Application
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The first thing we will do is create a new Laravel application instance
|
||||
| which serves as the "glue" for all the components of Laravel, and is
|
||||
| the IoC container for the system binding all of the various parts.
|
||||
|
|
||||
*/
|
||||
|
||||
$app = new Illuminate\Foundation\Application(
|
||||
$_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Bind Important Interfaces
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Next, we need to bind some important interfaces into the container so
|
||||
| we will be able to resolve them when needed. The kernels serve the
|
||||
| incoming requests to this application from both the web and CLI.
|
||||
|
|
||||
*/
|
||||
|
||||
$app->singleton(
|
||||
Illuminate\Contracts\Http\Kernel::class,
|
||||
App\Http\Kernel::class
|
||||
);
|
||||
|
||||
$app->singleton(
|
||||
Illuminate\Contracts\Console\Kernel::class,
|
||||
App\Console\Kernel::class
|
||||
);
|
||||
|
||||
$app->singleton(
|
||||
Illuminate\Contracts\Debug\ExceptionHandler::class,
|
||||
App\Exceptions\Handler::class
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Return The Application
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This script returns the application instance. The instance is given to
|
||||
| the calling script so we can separate the building of the instances
|
||||
| from the actual running of the application and sending responses.
|
||||
|
|
||||
*/
|
||||
|
||||
return $app;
|
@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
@ -0,0 +1,69 @@
|
||||
{
|
||||
"name": "laravel/laravel",
|
||||
"type": "project",
|
||||
"description": "The skeleton application for the Laravel framework.",
|
||||
"keywords": ["laravel", "framework"],
|
||||
"license": "MIT",
|
||||
"require": {
|
||||
"php": "^8.1",
|
||||
"guzzlehttp/guzzle": "^7.2",
|
||||
"laravel/framework": "^10.10",
|
||||
"laravel/sanctum": "^3.3",
|
||||
"laravel/tinker": "^2.8",
|
||||
"mpdf/mpdf": "^8.2",
|
||||
"spatie/laravel-permission": "^6.16",
|
||||
"tymon/jwt-auth": "^2.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"fakerphp/faker": "^1.9.1",
|
||||
"laravel/pint": "^1.0",
|
||||
"laravel/sail": "^1.18",
|
||||
"mockery/mockery": "^1.4.4",
|
||||
"nunomaduro/collision": "^7.0",
|
||||
"phpunit/phpunit": "^10.1",
|
||||
"spatie/laravel-ignition": "^2.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"App\\": "app/",
|
||||
"Database\\Factories\\": "database/factories/",
|
||||
"Database\\Seeders\\": "database/seeders/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Tests\\": "tests/"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"post-autoload-dump": [
|
||||
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
|
||||
"@php artisan package:discover --ansi"
|
||||
],
|
||||
"post-update-cmd": [
|
||||
"@php artisan vendor:publish --tag=laravel-assets --ansi --force"
|
||||
],
|
||||
"post-root-package-install": [
|
||||
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
|
||||
],
|
||||
"post-create-project-cmd": [
|
||||
"@php artisan key:generate --ansi"
|
||||
]
|
||||
},
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"dont-discover": []
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"optimize-autoloader": true,
|
||||
"preferred-install": "dist",
|
||||
"sort-packages": true,
|
||||
"allow-plugins": {
|
||||
"pestphp/pest-plugin": true,
|
||||
"php-http/discovery": true
|
||||
}
|
||||
},
|
||||
"minimum-stability": "stable",
|
||||
"prefer-stable": true
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,188 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Name
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This value is the name of your application. This value is used when the
|
||||
| framework needs to place the application's name in a notification or
|
||||
| any other location as required by the application or its packages.
|
||||
|
|
||||
*/
|
||||
|
||||
'name' => env('APP_NAME', 'Laravel'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Environment
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This value determines the "environment" your application is currently
|
||||
| running in. This may determine how you prefer to configure various
|
||||
| services the application utilizes. Set this in your ".env" file.
|
||||
|
|
||||
*/
|
||||
|
||||
'env' => env('APP_ENV', 'production'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Debug Mode
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When your application is in debug mode, detailed error messages with
|
||||
| stack traces will be shown on every error that occurs within your
|
||||
| application. If disabled, a simple generic error page is shown.
|
||||
|
|
||||
*/
|
||||
|
||||
'debug' => (bool) env('APP_DEBUG', false),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application URL
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This URL is used by the console to properly generate URLs when using
|
||||
| the Artisan command line tool. You should set this to the root of
|
||||
| your application so that it is used when running Artisan tasks.
|
||||
|
|
||||
*/
|
||||
|
||||
'url' => env('APP_URL', 'http://localhost'),
|
||||
|
||||
'asset_url' => env('ASSET_URL'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Timezone
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify the default timezone for your application, which
|
||||
| will be used by the PHP date and date-time functions. We have gone
|
||||
| ahead and set this to a sensible default for you out of the box.
|
||||
|
|
||||
*/
|
||||
|
||||
'timezone' => 'UTC',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Locale Configuration
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The application locale determines the default locale that will be used
|
||||
| by the translation service provider. You are free to set this value
|
||||
| to any of the locales which will be supported by the application.
|
||||
|
|
||||
*/
|
||||
|
||||
'locale' => 'en',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Fallback Locale
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The fallback locale determines the locale to use when the current one
|
||||
| is not available. You may change the value to correspond to any of
|
||||
| the language folders that are provided through your application.
|
||||
|
|
||||
*/
|
||||
|
||||
'fallback_locale' => 'en',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Faker Locale
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This locale will be used by the Faker PHP library when generating fake
|
||||
| data for your database seeds. For example, this will be used to get
|
||||
| localized telephone numbers, street address information and more.
|
||||
|
|
||||
*/
|
||||
|
||||
'faker_locale' => 'en_US',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Encryption Key
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This key is used by the Illuminate encrypter service and should be set
|
||||
| to a random, 32 character string, otherwise these encrypted strings
|
||||
| will not be safe. Please do this before deploying an application!
|
||||
|
|
||||
*/
|
||||
|
||||
'key' => env('APP_KEY'),
|
||||
|
||||
'cipher' => 'AES-256-CBC',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Maintenance Mode Driver
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| These configuration options determine the driver used to determine and
|
||||
| manage Laravel's "maintenance mode" status. The "cache" driver will
|
||||
| allow maintenance mode to be controlled across multiple machines.
|
||||
|
|
||||
| Supported drivers: "file", "cache"
|
||||
|
|
||||
*/
|
||||
|
||||
'maintenance' => [
|
||||
'driver' => 'file',
|
||||
// 'store' => 'redis',
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Autoloaded Service Providers
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The service providers listed here will be automatically loaded on the
|
||||
| request to your application. Feel free to add your own services to
|
||||
| this array to grant expanded functionality to your applications.
|
||||
|
|
||||
*/
|
||||
|
||||
'providers' => ServiceProvider::defaultProviders()->merge([
|
||||
/*
|
||||
* Package Service Providers...
|
||||
*/
|
||||
|
||||
/*
|
||||
* Application Service Providers...
|
||||
*/
|
||||
App\Providers\AppServiceProvider::class,
|
||||
App\Providers\AuthServiceProvider::class,
|
||||
// App\Providers\BroadcastServiceProvider::class,
|
||||
App\Providers\EventServiceProvider::class,
|
||||
App\Providers\RouteServiceProvider::class,
|
||||
])->toArray(),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Class Aliases
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This array of class aliases will be registered when this application
|
||||
| is started. However, feel free to register as many as you wish as
|
||||
| the aliases are "lazy" loaded so they don't hinder performance.
|
||||
|
|
||||
*/
|
||||
|
||||
'aliases' => Facade::defaultAliases()->merge([
|
||||
// 'Example' => App\Facades\Example::class,
|
||||
])->toArray(),
|
||||
|
||||
];
|
@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Authentication Defaults
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the default authentication "guard" and password
|
||||
| reset options for your application. You may change these defaults
|
||||
| as required, but they're a perfect start for most applications.
|
||||
|
|
||||
*/
|
||||
|
||||
'defaults' => [
|
||||
'guard' => 'web',
|
||||
'passwords' => 'users',
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Authentication Guards
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Next, you may define every authentication guard for your application.
|
||||
| Of course, a great default configuration has been defined for you
|
||||
| here which uses session storage and the Eloquent user provider.
|
||||
|
|
||||
| All authentication drivers have a user provider. This defines how the
|
||||
| users are actually retrieved out of your database or other storage
|
||||
| mechanisms used by this application to persist your user's data.
|
||||
|
|
||||
| Supported: "session"
|
||||
|
|
||||
*/
|
||||
|
||||
'guards' => [
|
||||
'web' => [
|
||||
'driver' => 'session',
|
||||
'provider' => 'users',
|
||||
],
|
||||
|
||||
'api' => [
|
||||
'driver' => 'jwt', // Usar JWT para autenticación
|
||||
'provider' => 'users',
|
||||
],
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| User Providers
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| All authentication drivers have a user provider. This defines how the
|
||||
| users are actually retrieved out of your database or other storage
|
||||
| mechanisms used by this application to persist your user's data.
|
||||
|
|
||||
| If you have multiple user tables or models you may configure multiple
|
||||
| sources which represent each model / table. These sources may then
|
||||
| be assigned to any extra authentication guards you have defined.
|
||||
|
|
||||
| Supported: "database", "eloquent"
|
||||
|
|
||||
*/
|
||||
|
||||
'providers' => [
|
||||
'users' => [
|
||||
'driver' => 'eloquent',
|
||||
'model' => App\Models\User::class,
|
||||
],
|
||||
|
||||
// 'users' => [
|
||||
// 'driver' => 'database',
|
||||
// 'table' => 'users',
|
||||
// ],
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Resetting Passwords
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| You may specify multiple password reset configurations if you have more
|
||||
| than one user table or model in the application and you want to have
|
||||
| separate password reset settings based on the specific user types.
|
||||
|
|
||||
| The expiry time is the number of minutes that each reset token will be
|
||||
| considered valid. This security feature keeps tokens short-lived so
|
||||
| they have less time to be guessed. You may change this as needed.
|
||||
|
|
||||
| The throttle setting is the number of seconds a user must wait before
|
||||
| generating more password reset tokens. This prevents the user from
|
||||
| quickly generating a very large amount of password reset tokens.
|
||||
|
|
||||
*/
|
||||
|
||||
'passwords' => [
|
||||
'users' => [
|
||||
'provider' => 'users',
|
||||
'table' => 'password_reset_tokens',
|
||||
'expire' => 60,
|
||||
'throttle' => 60,
|
||||
],
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Confirmation Timeout
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may define the amount of seconds before a password confirmation
|
||||
| times out and the user is prompted to re-enter their password via the
|
||||
| confirmation screen. By default, the timeout lasts for three hours.
|
||||
|
|
||||
*/
|
||||
|
||||
'password_timeout' => 10800,
|
||||
|
||||
];
|
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Broadcaster
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the default broadcaster that will be used by the
|
||||
| framework when an event needs to be broadcast. You may set this to
|
||||
| any of the connections defined in the "connections" array below.
|
||||
|
|
||||
| Supported: "pusher", "ably", "redis", "log", "null"
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('BROADCAST_DRIVER', 'null'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Broadcast Connections
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may define all of the broadcast connections that will be used
|
||||
| to broadcast events to other systems or over websockets. Samples of
|
||||
| each available type of connection are provided inside this array.
|
||||
|
|
||||
*/
|
||||
|
||||
'connections' => [
|
||||
|
||||
'pusher' => [
|
||||
'driver' => 'pusher',
|
||||
'key' => env('PUSHER_APP_KEY'),
|
||||
'secret' => env('PUSHER_APP_SECRET'),
|
||||
'app_id' => env('PUSHER_APP_ID'),
|
||||
'options' => [
|
||||
'cluster' => env('PUSHER_APP_CLUSTER'),
|
||||
'host' => env('PUSHER_HOST') ?: 'api-'.env('PUSHER_APP_CLUSTER', 'mt1').'.pusher.com',
|
||||
'port' => env('PUSHER_PORT', 443),
|
||||
'scheme' => env('PUSHER_SCHEME', 'https'),
|
||||
'encrypted' => true,
|
||||
'useTLS' => env('PUSHER_SCHEME', 'https') === 'https',
|
||||
],
|
||||
'client_options' => [
|
||||
// Guzzle client options: https://docs.guzzlephp.org/en/stable/request-options.html
|
||||
],
|
||||
],
|
||||
|
||||
'ably' => [
|
||||
'driver' => 'ably',
|
||||
'key' => env('ABLY_KEY'),
|
||||
],
|
||||
|
||||
'redis' => [
|
||||
'driver' => 'redis',
|
||||
'connection' => 'default',
|
||||
],
|
||||
|
||||
'log' => [
|
||||
'driver' => 'log',
|
||||
],
|
||||
|
||||
'null' => [
|
||||
'driver' => 'null',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Cache Store
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the default cache connection that gets used while
|
||||
| using this caching library. This connection is used when another is
|
||||
| not explicitly specified when executing a given caching function.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('CACHE_DRIVER', 'file'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Cache Stores
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may define all of the cache "stores" for your application as
|
||||
| well as their drivers. You may even define multiple stores for the
|
||||
| same cache driver to group types of items stored in your caches.
|
||||
|
|
||||
| Supported drivers: "apc", "array", "database", "file",
|
||||
| "memcached", "redis", "dynamodb", "octane", "null"
|
||||
|
|
||||
*/
|
||||
|
||||
'stores' => [
|
||||
|
||||
'apc' => [
|
||||
'driver' => 'apc',
|
||||
],
|
||||
|
||||
'array' => [
|
||||
'driver' => 'array',
|
||||
'serialize' => false,
|
||||
],
|
||||
|
||||
'database' => [
|
||||
'driver' => 'database',
|
||||
'table' => 'cache',
|
||||
'connection' => null,
|
||||
'lock_connection' => null,
|
||||
],
|
||||
|
||||
'file' => [
|
||||
'driver' => 'file',
|
||||
'path' => storage_path('framework/cache/data'),
|
||||
'lock_path' => storage_path('framework/cache/data'),
|
||||
],
|
||||
|
||||
'memcached' => [
|
||||
'driver' => 'memcached',
|
||||
'persistent_id' => env('MEMCACHED_PERSISTENT_ID'),
|
||||
'sasl' => [
|
||||
env('MEMCACHED_USERNAME'),
|
||||
env('MEMCACHED_PASSWORD'),
|
||||
],
|
||||
'options' => [
|
||||
// Memcached::OPT_CONNECT_TIMEOUT => 2000,
|
||||
],
|
||||
'servers' => [
|
||||
[
|
||||
'host' => env('MEMCACHED_HOST', '127.0.0.1'),
|
||||
'port' => env('MEMCACHED_PORT', 11211),
|
||||
'weight' => 100,
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
'redis' => [
|
||||
'driver' => 'redis',
|
||||
'connection' => 'cache',
|
||||
'lock_connection' => 'default',
|
||||
],
|
||||
|
||||
'dynamodb' => [
|
||||
'driver' => 'dynamodb',
|
||||
'key' => env('AWS_ACCESS_KEY_ID'),
|
||||
'secret' => env('AWS_SECRET_ACCESS_KEY'),
|
||||
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
|
||||
'table' => env('DYNAMODB_CACHE_TABLE', 'cache'),
|
||||
'endpoint' => env('DYNAMODB_ENDPOINT'),
|
||||
],
|
||||
|
||||
'octane' => [
|
||||
'driver' => 'octane',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Cache Key Prefix
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When utilizing the APC, database, memcached, Redis, or DynamoDB cache
|
||||
| stores there might be other applications using the same cache. For
|
||||
| that reason, you may prefix every cache key to avoid collisions.
|
||||
|
|
||||
*/
|
||||
|
||||
'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache_'),
|
||||
|
||||
];
|
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Cross-Origin Resource Sharing (CORS) Configuration
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may configure your settings for cross-origin resource sharing
|
||||
| or "CORS". This determines what cross-origin operations may execute
|
||||
| in web browsers. You are free to adjust these settings as needed.
|
||||
|
|
||||
| To learn more: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
|
||||
|
|
||||
*/
|
||||
|
||||
'paths' => ['api/*', 'sanctum/csrf-cookie'],
|
||||
|
||||
'allowed_methods' => ['*'],
|
||||
|
||||
'allowed_origins' => ['*'],
|
||||
|
||||
'allowed_origins_patterns' => [],
|
||||
|
||||
'allowed_headers' => ['*'],
|
||||
|
||||
'exposed_headers' => [],
|
||||
|
||||
'max_age' => 0,
|
||||
|
||||
'supports_credentials' => false,
|
||||
|
||||
];
|
@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Database Connection Name
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify which of the database connections below you wish
|
||||
| to use as your default connection for all database work. Of course
|
||||
| you may use many connections at once using the Database library.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('DB_CONNECTION', 'mysql'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Database Connections
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here are each of the database connections setup for your application.
|
||||
| Of course, examples of configuring each database platform that is
|
||||
| supported by Laravel is shown below to make development simple.
|
||||
|
|
||||
|
|
||||
| All database work in Laravel is done through the PHP PDO facilities
|
||||
| so make sure you have the driver for your particular database of
|
||||
| choice installed on your machine before you begin development.
|
||||
|
|
||||
*/
|
||||
|
||||
'connections' => [
|
||||
|
||||
'sqlite' => [
|
||||
'driver' => 'sqlite',
|
||||
'url' => env('DATABASE_URL'),
|
||||
'database' => env('DB_DATABASE', database_path('database.sqlite')),
|
||||
'prefix' => '',
|
||||
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
|
||||
],
|
||||
|
||||
'mysql' => [
|
||||
'driver' => 'mysql',
|
||||
'url' => env('DATABASE_URL'),
|
||||
'host' => env('DB_HOST', '127.0.0.1'),
|
||||
'port' => env('DB_PORT', '3306'),
|
||||
'database' => env('DB_DATABASE', 'forge'),
|
||||
'username' => env('DB_USERNAME', 'forge'),
|
||||
'password' => env('DB_PASSWORD', ''),
|
||||
'unix_socket' => env('DB_SOCKET', ''),
|
||||
'charset' => 'utf8mb4',
|
||||
'collation' => 'utf8mb4_unicode_ci',
|
||||
'prefix' => '',
|
||||
'prefix_indexes' => true,
|
||||
'strict' => true,
|
||||
'engine' => null,
|
||||
'options' => extension_loaded('pdo_mysql') ? array_filter([
|
||||
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
|
||||
]) : [],
|
||||
],
|
||||
|
||||
'pgsql' => [
|
||||
'driver' => 'pgsql',
|
||||
'url' => env('DATABASE_URL'),
|
||||
'host' => env('DB_HOST', '127.0.0.1'),
|
||||
'port' => env('DB_PORT', '5432'),
|
||||
'database' => env('DB_DATABASE', 'forge'),
|
||||
'username' => env('DB_USERNAME', 'forge'),
|
||||
'password' => env('DB_PASSWORD', ''),
|
||||
'charset' => 'utf8',
|
||||
'prefix' => '',
|
||||
'prefix_indexes' => true,
|
||||
'search_path' => 'public',
|
||||
'sslmode' => 'prefer',
|
||||
],
|
||||
|
||||
'sqlsrv' => [
|
||||
'driver' => 'sqlsrv',
|
||||
'url' => env('DATABASE_URL'),
|
||||
'host' => env('DB_HOST', 'localhost'),
|
||||
'port' => env('DB_PORT', '1433'),
|
||||
'database' => env('DB_DATABASE', 'forge'),
|
||||
'username' => env('DB_USERNAME', 'forge'),
|
||||
'password' => env('DB_PASSWORD', ''),
|
||||
'charset' => 'utf8',
|
||||
'prefix' => '',
|
||||
'prefix_indexes' => true,
|
||||
// 'encrypt' => env('DB_ENCRYPT', 'yes'),
|
||||
// 'trust_server_certificate' => env('DB_TRUST_SERVER_CERTIFICATE', 'false'),
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Migration Repository Table
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This table keeps track of all the migrations that have already run for
|
||||
| your application. Using this information, we can determine which of
|
||||
| the migrations on disk haven't actually been run in the database.
|
||||
|
|
||||
*/
|
||||
|
||||
'migrations' => 'migrations',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Redis Databases
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Redis is an open source, fast, and advanced key-value store that also
|
||||
| provides a richer body of commands than a typical key-value system
|
||||
| such as APC or Memcached. Laravel makes it easy to dig right in.
|
||||
|
|
||||
*/
|
||||
|
||||
'redis' => [
|
||||
|
||||
'client' => env('REDIS_CLIENT', 'phpredis'),
|
||||
|
||||
'options' => [
|
||||
'cluster' => env('REDIS_CLUSTER', 'redis'),
|
||||
'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'),
|
||||
],
|
||||
|
||||
'default' => [
|
||||
'url' => env('REDIS_URL'),
|
||||
'host' => env('REDIS_HOST', '127.0.0.1'),
|
||||
'username' => env('REDIS_USERNAME'),
|
||||
'password' => env('REDIS_PASSWORD'),
|
||||
'port' => env('REDIS_PORT', '6379'),
|
||||
'database' => env('REDIS_DB', '0'),
|
||||
],
|
||||
|
||||
'cache' => [
|
||||
'url' => env('REDIS_URL'),
|
||||
'host' => env('REDIS_HOST', '127.0.0.1'),
|
||||
'username' => env('REDIS_USERNAME'),
|
||||
'password' => env('REDIS_PASSWORD'),
|
||||
'port' => env('REDIS_PORT', '6379'),
|
||||
'database' => env('REDIS_CACHE_DB', '1'),
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Filesystem Disk
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify the default filesystem disk that should be used
|
||||
| by the framework. The "local" disk, as well as a variety of cloud
|
||||
| based disks are available to your application. Just store away!
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('FILESYSTEM_DISK', 'local'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Filesystem Disks
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may configure as many filesystem "disks" as you wish, and you
|
||||
| may even configure multiple disks of the same driver. Defaults have
|
||||
| been set up for each driver as an example of the required values.
|
||||
|
|
||||
| Supported Drivers: "local", "ftp", "sftp", "s3"
|
||||
|
|
||||
*/
|
||||
|
||||
'disks' => [
|
||||
|
||||
'local' => [
|
||||
'driver' => 'local',
|
||||
'root' => storage_path('app'),
|
||||
'throw' => false,
|
||||
],
|
||||
|
||||
'public' => [
|
||||
'driver' => 'local',
|
||||
'root' => storage_path('app/public'),
|
||||
'url' => env('APP_URL').'/storage',
|
||||
'visibility' => 'public',
|
||||
'throw' => false,
|
||||
],
|
||||
|
||||
's3' => [
|
||||
'driver' => 's3',
|
||||
'key' => env('AWS_ACCESS_KEY_ID'),
|
||||
'secret' => env('AWS_SECRET_ACCESS_KEY'),
|
||||
'region' => env('AWS_DEFAULT_REGION'),
|
||||
'bucket' => env('AWS_BUCKET'),
|
||||
'url' => env('AWS_URL'),
|
||||
'endpoint' => env('AWS_ENDPOINT'),
|
||||
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
|
||||
'throw' => false,
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Symbolic Links
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may configure the symbolic links that will be created when the
|
||||
| `storage:link` Artisan command is executed. The array keys should be
|
||||
| the locations of the links and the values should be their targets.
|
||||
|
|
||||
*/
|
||||
|
||||
'links' => [
|
||||
public_path('storage') => storage_path('app/public'),
|
||||
],
|
||||
|
||||
];
|
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Hash Driver
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the default hash driver that will be used to hash
|
||||
| passwords for your application. By default, the bcrypt algorithm is
|
||||
| used; however, you remain free to modify this option if you wish.
|
||||
|
|
||||
| Supported: "bcrypt", "argon", "argon2id"
|
||||
|
|
||||
*/
|
||||
|
||||
'driver' => 'bcrypt',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Bcrypt Options
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify the configuration options that should be used when
|
||||
| passwords are hashed using the Bcrypt algorithm. This will allow you
|
||||
| to control the amount of time it takes to hash the given password.
|
||||
|
|
||||
*/
|
||||
|
||||
'bcrypt' => [
|
||||
'rounds' => env('BCRYPT_ROUNDS', 12),
|
||||
'verify' => true,
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Argon Options
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify the configuration options that should be used when
|
||||
| passwords are hashed using the Argon algorithm. These will allow you
|
||||
| to control the amount of time it takes to hash the given password.
|
||||
|
|
||||
*/
|
||||
|
||||
'argon' => [
|
||||
'memory' => 65536,
|
||||
'threads' => 1,
|
||||
'time' => 4,
|
||||
'verify' => true,
|
||||
],
|
||||
|
||||
];
|
@ -0,0 +1,301 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of jwt-auth.
|
||||
*
|
||||
* (c) Sean Tymon <tymon148@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| JWT Authentication Secret
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Don't forget to set this in your .env file, as it will be used to sign
|
||||
| your tokens. A helper command is provided for this:
|
||||
| `php artisan jwt:secret`
|
||||
|
|
||||
| Note: This will be used for Symmetric algorithms only (HMAC),
|
||||
| since RSA and ECDSA use a private/public key combo (See below).
|
||||
|
|
||||
*/
|
||||
|
||||
'secret' => env('JWT_SECRET'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| JWT Authentication Keys
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The algorithm you are using, will determine whether your tokens are
|
||||
| signed with a random string (defined in `JWT_SECRET`) or using the
|
||||
| following public & private keys.
|
||||
|
|
||||
| Symmetric Algorithms:
|
||||
| HS256, HS384 & HS512 will use `JWT_SECRET`.
|
||||
|
|
||||
| Asymmetric Algorithms:
|
||||
| RS256, RS384 & RS512 / ES256, ES384 & ES512 will use the keys below.
|
||||
|
|
||||
*/
|
||||
|
||||
'keys' => [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Public Key
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| A path or resource to your public key.
|
||||
|
|
||||
| E.g. 'file://path/to/public/key'
|
||||
|
|
||||
*/
|
||||
|
||||
'public' => env('JWT_PUBLIC_KEY'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Private Key
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| A path or resource to your private key.
|
||||
|
|
||||
| E.g. 'file://path/to/private/key'
|
||||
|
|
||||
*/
|
||||
|
||||
'private' => env('JWT_PRIVATE_KEY'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Passphrase
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The passphrase for your private key. Can be null if none set.
|
||||
|
|
||||
*/
|
||||
|
||||
'passphrase' => env('JWT_PASSPHRASE'),
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| JWT time to live
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Specify the length of time (in minutes) that the token will be valid for.
|
||||
| Defaults to 1 hour.
|
||||
|
|
||||
| You can also set this to null, to yield a never expiring token.
|
||||
| Some people may want this behaviour for e.g. a mobile app.
|
||||
| This is not particularly recommended, so make sure you have appropriate
|
||||
| systems in place to revoke the token if necessary.
|
||||
| Notice: If you set this to null you should remove 'exp' element from 'required_claims' list.
|
||||
|
|
||||
*/
|
||||
|
||||
'ttl' => env('JWT_TTL', 1440),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Refresh time to live
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Specify the length of time (in minutes) that the token can be refreshed
|
||||
| within. I.E. The user can refresh their token within a 2 week window of
|
||||
| the original token being created until they must re-authenticate.
|
||||
| Defaults to 2 weeks.
|
||||
|
|
||||
| You can also set this to null, to yield an infinite refresh time.
|
||||
| Some may want this instead of never expiring tokens for e.g. a mobile app.
|
||||
| This is not particularly recommended, so make sure you have appropriate
|
||||
| systems in place to revoke the token if necessary.
|
||||
|
|
||||
*/
|
||||
|
||||
'refresh_ttl' => env('JWT_REFRESH_TTL', 20160),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| JWT hashing algorithm
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Specify the hashing algorithm that will be used to sign the token.
|
||||
|
|
||||
*/
|
||||
|
||||
'algo' => env('JWT_ALGO', Tymon\JWTAuth\Providers\JWT\Provider::ALGO_HS256),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Required Claims
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Specify the required claims that must exist in any token.
|
||||
| A TokenInvalidException will be thrown if any of these claims are not
|
||||
| present in the payload.
|
||||
|
|
||||
*/
|
||||
|
||||
'required_claims' => [
|
||||
'iss',
|
||||
'iat',
|
||||
'exp',
|
||||
'nbf',
|
||||
'sub',
|
||||
'jti',
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Persistent Claims
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Specify the claim keys to be persisted when refreshing a token.
|
||||
| `sub` and `iat` will automatically be persisted, in
|
||||
| addition to the these claims.
|
||||
|
|
||||
| Note: If a claim does not exist then it will be ignored.
|
||||
|
|
||||
*/
|
||||
|
||||
'persistent_claims' => [
|
||||
// 'foo',
|
||||
// 'bar',
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Lock Subject
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This will determine whether a `prv` claim is automatically added to
|
||||
| the token. The purpose of this is to ensure that if you have multiple
|
||||
| authentication models e.g. `App\User` & `App\OtherPerson`, then we
|
||||
| should prevent one authentication request from impersonating another,
|
||||
| if 2 tokens happen to have the same id across the 2 different models.
|
||||
|
|
||||
| Under specific circumstances, you may want to disable this behaviour
|
||||
| e.g. if you only have one authentication model, then you would save
|
||||
| a little on token size.
|
||||
|
|
||||
*/
|
||||
|
||||
'lock_subject' => true,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Leeway
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This property gives the jwt timestamp claims some "leeway".
|
||||
| Meaning that if you have any unavoidable slight clock skew on
|
||||
| any of your servers then this will afford you some level of cushioning.
|
||||
|
|
||||
| This applies to the claims `iat`, `nbf` and `exp`.
|
||||
|
|
||||
| Specify in seconds - only if you know you need it.
|
||||
|
|
||||
*/
|
||||
|
||||
'leeway' => env('JWT_LEEWAY', 0),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Blacklist Enabled
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| In order to invalidate tokens, you must have the blacklist enabled.
|
||||
| If you do not want or need this functionality, then set this to false.
|
||||
|
|
||||
*/
|
||||
|
||||
'blacklist_enabled' => env('JWT_BLACKLIST_ENABLED', true),
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------------
|
||||
| Blacklist Grace Period
|
||||
| -------------------------------------------------------------------------
|
||||
|
|
||||
| When multiple concurrent requests are made with the same JWT,
|
||||
| it is possible that some of them fail, due to token regeneration
|
||||
| on every request.
|
||||
|
|
||||
| Set grace period in seconds to prevent parallel request failure.
|
||||
|
|
||||
*/
|
||||
|
||||
'blacklist_grace_period' => env('JWT_BLACKLIST_GRACE_PERIOD', 0),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Cookies encryption
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| By default Laravel encrypt cookies for security reason.
|
||||
| If you decide to not decrypt cookies, you will have to configure Laravel
|
||||
| to not encrypt your cookie token by adding its name into the $except
|
||||
| array available in the middleware "EncryptCookies" provided by Laravel.
|
||||
| see https://laravel.com/docs/master/responses#cookies-and-encryption
|
||||
| for details.
|
||||
|
|
||||
| Set it to true if you want to decrypt cookies.
|
||||
|
|
||||
*/
|
||||
|
||||
'decrypt_cookies' => false,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Providers
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Specify the various providers used throughout the package.
|
||||
|
|
||||
*/
|
||||
|
||||
'providers' => [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| JWT Provider
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Specify the provider that is used to create and decode the tokens.
|
||||
|
|
||||
*/
|
||||
|
||||
'jwt' => Tymon\JWTAuth\Providers\JWT\Lcobucci::class,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Authentication Provider
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Specify the provider that is used to authenticate users.
|
||||
|
|
||||
*/
|
||||
|
||||
'auth' => Tymon\JWTAuth\Providers\Auth\Illuminate::class,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Storage Provider
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Specify the provider that is used to store tokens in the blacklist.
|
||||
|
|
||||
*/
|
||||
|
||||
'storage' => Tymon\JWTAuth\Providers\Storage\Illuminate::class,
|
||||
|
||||
],
|
||||
|
||||
];
|
@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
use Monolog\Handler\NullHandler;
|
||||
use Monolog\Handler\StreamHandler;
|
||||
use Monolog\Handler\SyslogUdpHandler;
|
||||
use Monolog\Processor\PsrLogMessageProcessor;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Log Channel
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option defines the default log channel that gets used when writing
|
||||
| messages to the logs. The name specified in this option should match
|
||||
| one of the channels defined in the "channels" configuration array.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('LOG_CHANNEL', 'stack'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Deprecations Log Channel
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the log channel that should be used to log warnings
|
||||
| regarding deprecated PHP and library features. This allows you to get
|
||||
| your application ready for upcoming major versions of dependencies.
|
||||
|
|
||||
*/
|
||||
|
||||
'deprecations' => [
|
||||
'channel' => env('LOG_DEPRECATIONS_CHANNEL', 'null'),
|
||||
'trace' => false,
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Log Channels
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may configure the log channels for your application. Out of
|
||||
| the box, Laravel uses the Monolog PHP logging library. This gives
|
||||
| you a variety of powerful log handlers / formatters to utilize.
|
||||
|
|
||||
| Available Drivers: "single", "daily", "slack", "syslog",
|
||||
| "errorlog", "monolog",
|
||||
| "custom", "stack"
|
||||
|
|
||||
*/
|
||||
|
||||
'channels' => [
|
||||
'stack' => [
|
||||
'driver' => 'stack',
|
||||
'channels' => ['single'],
|
||||
'ignore_exceptions' => false,
|
||||
],
|
||||
|
||||
'single' => [
|
||||
'driver' => 'single',
|
||||
'path' => storage_path('logs/laravel.log'),
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
|
||||
'daily' => [
|
||||
'driver' => 'daily',
|
||||
'path' => storage_path('logs/laravel.log'),
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'days' => 14,
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
|
||||
'slack' => [
|
||||
'driver' => 'slack',
|
||||
'url' => env('LOG_SLACK_WEBHOOK_URL'),
|
||||
'username' => 'Laravel Log',
|
||||
'emoji' => ':boom:',
|
||||
'level' => env('LOG_LEVEL', 'critical'),
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
|
||||
'papertrail' => [
|
||||
'driver' => 'monolog',
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'handler' => env('LOG_PAPERTRAIL_HANDLER', SyslogUdpHandler::class),
|
||||
'handler_with' => [
|
||||
'host' => env('PAPERTRAIL_URL'),
|
||||
'port' => env('PAPERTRAIL_PORT'),
|
||||
'connectionString' => 'tls://'.env('PAPERTRAIL_URL').':'.env('PAPERTRAIL_PORT'),
|
||||
],
|
||||
'processors' => [PsrLogMessageProcessor::class],
|
||||
],
|
||||
|
||||
'stderr' => [
|
||||
'driver' => 'monolog',
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'handler' => StreamHandler::class,
|
||||
'formatter' => env('LOG_STDERR_FORMATTER'),
|
||||
'with' => [
|
||||
'stream' => 'php://stderr',
|
||||
],
|
||||
'processors' => [PsrLogMessageProcessor::class],
|
||||
],
|
||||
|
||||
'syslog' => [
|
||||
'driver' => 'syslog',
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'facility' => LOG_USER,
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
|
||||
'errorlog' => [
|
||||
'driver' => 'errorlog',
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
|
||||
'null' => [
|
||||
'driver' => 'monolog',
|
||||
'handler' => NullHandler::class,
|
||||
],
|
||||
|
||||
'emergency' => [
|
||||
'path' => storage_path('logs/laravel.log'),
|
||||
],
|
||||
],
|
||||
|
||||
];
|
@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Mailer
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the default mailer that is used to send any email
|
||||
| messages sent by your application. Alternative mailers may be setup
|
||||
| and used as needed; however, this mailer will be used by default.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('MAIL_MAILER', 'smtp'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Mailer Configurations
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may configure all of the mailers used by your application plus
|
||||
| their respective settings. Several examples have been configured for
|
||||
| you and you are free to add your own as your application requires.
|
||||
|
|
||||
| Laravel supports a variety of mail "transport" drivers to be used while
|
||||
| sending an e-mail. You will specify which one you are using for your
|
||||
| mailers below. You are free to add additional mailers as required.
|
||||
|
|
||||
| Supported: "smtp", "sendmail", "mailgun", "ses", "ses-v2",
|
||||
| "postmark", "log", "array", "failover", "roundrobin"
|
||||
|
|
||||
*/
|
||||
|
||||
'mailers' => [
|
||||
'smtp' => [
|
||||
'transport' => 'smtp',
|
||||
'url' => env('MAIL_URL'),
|
||||
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
|
||||
'port' => env('MAIL_PORT', 587),
|
||||
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
|
||||
'username' => env('MAIL_USERNAME'),
|
||||
'password' => env('MAIL_PASSWORD'),
|
||||
'timeout' => null,
|
||||
'local_domain' => env('MAIL_EHLO_DOMAIN'),
|
||||
],
|
||||
|
||||
'ses' => [
|
||||
'transport' => 'ses',
|
||||
],
|
||||
|
||||
'postmark' => [
|
||||
'transport' => 'postmark',
|
||||
// 'message_stream_id' => null,
|
||||
// 'client' => [
|
||||
// 'timeout' => 5,
|
||||
// ],
|
||||
],
|
||||
|
||||
'mailgun' => [
|
||||
'transport' => 'mailgun',
|
||||
// 'client' => [
|
||||
// 'timeout' => 5,
|
||||
// ],
|
||||
],
|
||||
|
||||
'sendmail' => [
|
||||
'transport' => 'sendmail',
|
||||
'path' => env('MAIL_SENDMAIL_PATH', '/usr/sbin/sendmail -bs -i'),
|
||||
],
|
||||
|
||||
'log' => [
|
||||
'transport' => 'log',
|
||||
'channel' => env('MAIL_LOG_CHANNEL'),
|
||||
],
|
||||
|
||||
'array' => [
|
||||
'transport' => 'array',
|
||||
],
|
||||
|
||||
'failover' => [
|
||||
'transport' => 'failover',
|
||||
'mailers' => [
|
||||
'smtp',
|
||||
'log',
|
||||
],
|
||||
],
|
||||
|
||||
'roundrobin' => [
|
||||
'transport' => 'roundrobin',
|
||||
'mailers' => [
|
||||
'ses',
|
||||
'postmark',
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Global "From" Address
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| You may wish for all e-mails sent by your application to be sent from
|
||||
| the same address. Here, you may specify a name and address that is
|
||||
| used globally for all e-mails that are sent by your application.
|
||||
|
|
||||
*/
|
||||
|
||||
'from' => [
|
||||
'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
|
||||
'name' => env('MAIL_FROM_NAME', 'Example'),
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Markdown Mail Settings
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| If you are using Markdown based email rendering, you may configure your
|
||||
| theme and component paths here, allowing you to customize the design
|
||||
| of the emails. Or, you may simply stick with the Laravel defaults!
|
||||
|
|
||||
*/
|
||||
|
||||
'markdown' => [
|
||||
'theme' => 'default',
|
||||
|
||||
'paths' => [
|
||||
resource_path('views/vendor/mail'),
|
||||
],
|
||||
],
|
||||
|
||||
];
|
@ -0,0 +1,202 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'models' => [
|
||||
|
||||
/*
|
||||
* When using the "HasPermissions" trait from this package, we need to know which
|
||||
* Eloquent model should be used to retrieve your permissions. Of course, it
|
||||
* is often just the "Permission" model but you may use whatever you like.
|
||||
*
|
||||
* The model you want to use as a Permission model needs to implement the
|
||||
* `Spatie\Permission\Contracts\Permission` contract.
|
||||
*/
|
||||
|
||||
'permission' => Spatie\Permission\Models\Permission::class,
|
||||
|
||||
/*
|
||||
* When using the "HasRoles" trait from this package, we need to know which
|
||||
* Eloquent model should be used to retrieve your roles. Of course, it
|
||||
* is often just the "Role" model but you may use whatever you like.
|
||||
*
|
||||
* The model you want to use as a Role model needs to implement the
|
||||
* `Spatie\Permission\Contracts\Role` contract.
|
||||
*/
|
||||
|
||||
'role' => Spatie\Permission\Models\Role::class,
|
||||
|
||||
],
|
||||
|
||||
'table_names' => [
|
||||
|
||||
/*
|
||||
* When using the "HasRoles" trait from this package, we need to know which
|
||||
* table should be used to retrieve your roles. We have chosen a basic
|
||||
* default value but you may easily change it to any table you like.
|
||||
*/
|
||||
|
||||
'roles' => 'roles',
|
||||
|
||||
/*
|
||||
* When using the "HasPermissions" trait from this package, we need to know which
|
||||
* table should be used to retrieve your permissions. We have chosen a basic
|
||||
* default value but you may easily change it to any table you like.
|
||||
*/
|
||||
|
||||
'permissions' => 'permissions',
|
||||
|
||||
/*
|
||||
* When using the "HasPermissions" trait from this package, we need to know which
|
||||
* table should be used to retrieve your models permissions. We have chosen a
|
||||
* basic default value but you may easily change it to any table you like.
|
||||
*/
|
||||
|
||||
'model_has_permissions' => 'model_has_permissions',
|
||||
|
||||
/*
|
||||
* When using the "HasRoles" trait from this package, we need to know which
|
||||
* table should be used to retrieve your models roles. We have chosen a
|
||||
* basic default value but you may easily change it to any table you like.
|
||||
*/
|
||||
|
||||
'model_has_roles' => 'model_has_roles',
|
||||
|
||||
/*
|
||||
* When using the "HasRoles" trait from this package, we need to know which
|
||||
* table should be used to retrieve your roles permissions. We have chosen a
|
||||
* basic default value but you may easily change it to any table you like.
|
||||
*/
|
||||
|
||||
'role_has_permissions' => 'role_has_permissions',
|
||||
],
|
||||
|
||||
'column_names' => [
|
||||
/*
|
||||
* Change this if you want to name the related pivots other than defaults
|
||||
*/
|
||||
'role_pivot_key' => null, // default 'role_id',
|
||||
'permission_pivot_key' => null, // default 'permission_id',
|
||||
|
||||
/*
|
||||
* Change this if you want to name the related model primary key other than
|
||||
* `model_id`.
|
||||
*
|
||||
* For example, this would be nice if your primary keys are all UUIDs. In
|
||||
* that case, name this `model_uuid`.
|
||||
*/
|
||||
|
||||
'model_morph_key' => 'model_id',
|
||||
|
||||
/*
|
||||
* Change this if you want to use the teams feature and your related model's
|
||||
* foreign key is other than `team_id`.
|
||||
*/
|
||||
|
||||
'team_foreign_key' => 'team_id',
|
||||
],
|
||||
|
||||
/*
|
||||
* When set to true, the method for checking permissions will be registered on the gate.
|
||||
* Set this to false if you want to implement custom logic for checking permissions.
|
||||
*/
|
||||
|
||||
'register_permission_check_method' => true,
|
||||
|
||||
/*
|
||||
* When set to true, Laravel\Octane\Events\OperationTerminated event listener will be registered
|
||||
* this will refresh permissions on every TickTerminated, TaskTerminated and RequestTerminated
|
||||
* NOTE: This should not be needed in most cases, but an Octane/Vapor combination benefited from it.
|
||||
*/
|
||||
'register_octane_reset_listener' => false,
|
||||
|
||||
/*
|
||||
* Events will fire when a role or permission is assigned/unassigned:
|
||||
* \Spatie\Permission\Events\RoleAttached
|
||||
* \Spatie\Permission\Events\RoleDetached
|
||||
* \Spatie\Permission\Events\PermissionAttached
|
||||
* \Spatie\Permission\Events\PermissionDetached
|
||||
*
|
||||
* To enable, set to true, and then create listeners to watch these events.
|
||||
*/
|
||||
'events_enabled' => false,
|
||||
|
||||
/*
|
||||
* Teams Feature.
|
||||
* When set to true the package implements teams using the 'team_foreign_key'.
|
||||
* If you want the migrations to register the 'team_foreign_key', you must
|
||||
* set this to true before doing the migration.
|
||||
* If you already did the migration then you must make a new migration to also
|
||||
* add 'team_foreign_key' to 'roles', 'model_has_roles', and 'model_has_permissions'
|
||||
* (view the latest version of this package's migration file)
|
||||
*/
|
||||
|
||||
'teams' => false,
|
||||
|
||||
/*
|
||||
* The class to use to resolve the permissions team id
|
||||
*/
|
||||
'team_resolver' => \Spatie\Permission\DefaultTeamResolver::class,
|
||||
|
||||
/*
|
||||
* Passport Client Credentials Grant
|
||||
* When set to true the package will use Passports Client to check permissions
|
||||
*/
|
||||
|
||||
'use_passport_client_credentials' => false,
|
||||
|
||||
/*
|
||||
* When set to true, the required permission names are added to exception messages.
|
||||
* This could be considered an information leak in some contexts, so the default
|
||||
* setting is false here for optimum safety.
|
||||
*/
|
||||
|
||||
'display_permission_in_exception' => false,
|
||||
|
||||
/*
|
||||
* When set to true, the required role names are added to exception messages.
|
||||
* This could be considered an information leak in some contexts, so the default
|
||||
* setting is false here for optimum safety.
|
||||
*/
|
||||
|
||||
'display_role_in_exception' => false,
|
||||
|
||||
/*
|
||||
* By default wildcard permission lookups are disabled.
|
||||
* See documentation to understand supported syntax.
|
||||
*/
|
||||
|
||||
'enable_wildcard_permission' => false,
|
||||
|
||||
/*
|
||||
* The class to use for interpreting wildcard permissions.
|
||||
* If you need to modify delimiters, override the class and specify its name here.
|
||||
*/
|
||||
// 'permission.wildcard_permission' => Spatie\Permission\WildcardPermission::class,
|
||||
|
||||
/* Cache-specific settings */
|
||||
|
||||
'cache' => [
|
||||
|
||||
/*
|
||||
* By default all permissions are cached for 24 hours to speed up performance.
|
||||
* When permissions or roles are updated the cache is flushed automatically.
|
||||
*/
|
||||
|
||||
'expiration_time' => \DateInterval::createFromDateString('24 hours'),
|
||||
|
||||
/*
|
||||
* The cache key used to store all permissions.
|
||||
*/
|
||||
|
||||
'key' => 'spatie.permission.cache',
|
||||
|
||||
/*
|
||||
* You may optionally indicate a specific cache driver to use for permission and
|
||||
* role caching using any of the `store` drivers listed in the cache.php config
|
||||
* file. Using 'default' here means to use the `default` set in cache.php.
|
||||
*/
|
||||
|
||||
'store' => 'default',
|
||||
],
|
||||
];
|
@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Queue Connection Name
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Laravel's queue API supports an assortment of back-ends via a single
|
||||
| API, giving you convenient access to each back-end using the same
|
||||
| syntax for every one. Here you may define a default connection.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('QUEUE_CONNECTION', 'sync'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Queue Connections
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may configure the connection information for each server that
|
||||
| is used by your application. A default configuration has been added
|
||||
| for each back-end shipped with Laravel. You are free to add more.
|
||||
|
|
||||
| Drivers: "sync", "database", "beanstalkd", "sqs", "redis", "null"
|
||||
|
|
||||
*/
|
||||
|
||||
'connections' => [
|
||||
|
||||
'sync' => [
|
||||
'driver' => 'sync',
|
||||
],
|
||||
|
||||
'database' => [
|
||||
'driver' => 'database',
|
||||
'table' => 'jobs',
|
||||
'queue' => 'default',
|
||||
'retry_after' => 90,
|
||||
'after_commit' => false,
|
||||
],
|
||||
|
||||
'beanstalkd' => [
|
||||
'driver' => 'beanstalkd',
|
||||
'host' => 'localhost',
|
||||
'queue' => 'default',
|
||||
'retry_after' => 90,
|
||||
'block_for' => 0,
|
||||
'after_commit' => false,
|
||||
],
|
||||
|
||||
'sqs' => [
|
||||
'driver' => 'sqs',
|
||||
'key' => env('AWS_ACCESS_KEY_ID'),
|
||||
'secret' => env('AWS_SECRET_ACCESS_KEY'),
|
||||
'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'),
|
||||
'queue' => env('SQS_QUEUE', 'default'),
|
||||
'suffix' => env('SQS_SUFFIX'),
|
||||
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
|
||||
'after_commit' => false,
|
||||
],
|
||||
|
||||
'redis' => [
|
||||
'driver' => 'redis',
|
||||
'connection' => 'default',
|
||||
'queue' => env('REDIS_QUEUE', 'default'),
|
||||
'retry_after' => 90,
|
||||
'block_for' => null,
|
||||
'after_commit' => false,
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Job Batching
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The following options configure the database and table that store job
|
||||
| batching information. These options can be updated to any database
|
||||
| connection and table which has been defined by your application.
|
||||
|
|
||||
*/
|
||||
|
||||
'batching' => [
|
||||
'database' => env('DB_CONNECTION', 'mysql'),
|
||||
'table' => 'job_batches',
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Failed Queue Jobs
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| These options configure the behavior of failed queue job logging so you
|
||||
| can control which database and table are used to store the jobs that
|
||||
| have failed. You may change them to any database / table you wish.
|
||||
|
|
||||
*/
|
||||
|
||||
'failed' => [
|
||||
'driver' => env('QUEUE_FAILED_DRIVER', 'database-uuids'),
|
||||
'database' => env('DB_CONNECTION', 'mysql'),
|
||||
'table' => 'failed_jobs',
|
||||
],
|
||||
|
||||
];
|
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Stateful Domains
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Requests from the following domains / hosts will receive stateful API
|
||||
| authentication cookies. Typically, these should include your local
|
||||
| and production domains which access your API via a frontend SPA.
|
||||
|
|
||||
*/
|
||||
|
||||
'stateful' => explode(',', env('SANCTUM_STATEFUL_DOMAINS', sprintf(
|
||||
'%s%s',
|
||||
'localhost,localhost:3000,127.0.0.1,127.0.0.1:8000,::1',
|
||||
Sanctum::currentApplicationUrlWithPort()
|
||||
))),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Sanctum Guards
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This array contains the authentication guards that will be checked when
|
||||
| Sanctum is trying to authenticate a request. If none of these guards
|
||||
| are able to authenticate the request, Sanctum will use the bearer
|
||||
| token that's present on an incoming request for authentication.
|
||||
|
|
||||
*/
|
||||
|
||||
'guard' => ['web'],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Expiration Minutes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This value controls the number of minutes until an issued token will be
|
||||
| considered expired. This will override any values set in the token's
|
||||
| "expires_at" attribute, but first-party sessions are not affected.
|
||||
|
|
||||
*/
|
||||
|
||||
'expiration' => null,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Token Prefix
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Sanctum can prefix new tokens in order to take advantage of numerous
|
||||
| security scanning initiatives maintained by open source platforms
|
||||
| that notify developers if they commit tokens into repositories.
|
||||
|
|
||||
| See: https://docs.github.com/en/code-security/secret-scanning/about-secret-scanning
|
||||
|
|
||||
*/
|
||||
|
||||
'token_prefix' => env('SANCTUM_TOKEN_PREFIX', ''),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Sanctum Middleware
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When authenticating your first-party SPA with Sanctum you may need to
|
||||
| customize some of the middleware Sanctum uses while processing the
|
||||
| request. You may change the middleware listed below as required.
|
||||
|
|
||||
*/
|
||||
|
||||
'middleware' => [
|
||||
'authenticate_session' => Laravel\Sanctum\Http\Middleware\AuthenticateSession::class,
|
||||
'encrypt_cookies' => App\Http\Middleware\EncryptCookies::class,
|
||||
'verify_csrf_token' => App\Http\Middleware\VerifyCsrfToken::class,
|
||||
],
|
||||
|
||||
];
|
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Third Party Services
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This file is for storing the credentials for third party services such
|
||||
| as Mailgun, Postmark, AWS and more. This file provides the de facto
|
||||
| location for this type of information, allowing packages to have
|
||||
| a conventional file to locate the various service credentials.
|
||||
|
|
||||
*/
|
||||
|
||||
'mailgun' => [
|
||||
'domain' => env('MAILGUN_DOMAIN'),
|
||||
'secret' => env('MAILGUN_SECRET'),
|
||||
'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'),
|
||||
'scheme' => 'https',
|
||||
],
|
||||
|
||||
'postmark' => [
|
||||
'token' => env('POSTMARK_TOKEN'),
|
||||
],
|
||||
|
||||
'ses' => [
|
||||
'key' => env('AWS_ACCESS_KEY_ID'),
|
||||
'secret' => env('AWS_SECRET_ACCESS_KEY'),
|
||||
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
|
||||
],
|
||||
|
||||
];
|
@ -0,0 +1,214 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Session Driver
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the default session "driver" that will be used on
|
||||
| requests. By default, we will use the lightweight native driver but
|
||||
| you may specify any of the other wonderful drivers provided here.
|
||||
|
|
||||
| Supported: "file", "cookie", "database", "apc",
|
||||
| "memcached", "redis", "dynamodb", "array"
|
||||
|
|
||||
*/
|
||||
|
||||
'driver' => env('SESSION_DRIVER', 'file'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Lifetime
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify the number of minutes that you wish the session
|
||||
| to be allowed to remain idle before it expires. If you want them
|
||||
| to immediately expire on the browser closing, set that option.
|
||||
|
|
||||
*/
|
||||
|
||||
'lifetime' => env('SESSION_LIFETIME', 120),
|
||||
|
||||
'expire_on_close' => false,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Encryption
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option allows you to easily specify that all of your session data
|
||||
| should be encrypted before it is stored. All encryption will be run
|
||||
| automatically by Laravel and you can use the Session like normal.
|
||||
|
|
||||
*/
|
||||
|
||||
'encrypt' => false,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session File Location
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When using the native session driver, we need a location where session
|
||||
| files may be stored. A default has been set for you but a different
|
||||
| location may be specified. This is only needed for file sessions.
|
||||
|
|
||||
*/
|
||||
|
||||
'files' => storage_path('framework/sessions'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Database Connection
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When using the "database" or "redis" session drivers, you may specify a
|
||||
| connection that should be used to manage these sessions. This should
|
||||
| correspond to a connection in your database configuration options.
|
||||
|
|
||||
*/
|
||||
|
||||
'connection' => env('SESSION_CONNECTION'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Database Table
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When using the "database" session driver, you may specify the table we
|
||||
| should use to manage the sessions. Of course, a sensible default is
|
||||
| provided for you; however, you are free to change this as needed.
|
||||
|
|
||||
*/
|
||||
|
||||
'table' => 'sessions',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Cache Store
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| While using one of the framework's cache driven session backends you may
|
||||
| list a cache store that should be used for these sessions. This value
|
||||
| must match with one of the application's configured cache "stores".
|
||||
|
|
||||
| Affects: "apc", "dynamodb", "memcached", "redis"
|
||||
|
|
||||
*/
|
||||
|
||||
'store' => env('SESSION_STORE'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Sweeping Lottery
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Some session drivers must manually sweep their storage location to get
|
||||
| rid of old sessions from storage. Here are the chances that it will
|
||||
| happen on a given request. By default, the odds are 2 out of 100.
|
||||
|
|
||||
*/
|
||||
|
||||
'lottery' => [2, 100],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Cookie Name
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may change the name of the cookie used to identify a session
|
||||
| instance by ID. The name specified here will get used every time a
|
||||
| new session cookie is created by the framework for every driver.
|
||||
|
|
||||
*/
|
||||
|
||||
'cookie' => env(
|
||||
'SESSION_COOKIE',
|
||||
Str::slug(env('APP_NAME', 'laravel'), '_').'_session'
|
||||
),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Cookie Path
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The session cookie path determines the path for which the cookie will
|
||||
| be regarded as available. Typically, this will be the root path of
|
||||
| your application but you are free to change this when necessary.
|
||||
|
|
||||
*/
|
||||
|
||||
'path' => '/',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Cookie Domain
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may change the domain of the cookie used to identify a session
|
||||
| in your application. This will determine which domains the cookie is
|
||||
| available to in your application. A sensible default has been set.
|
||||
|
|
||||
*/
|
||||
|
||||
'domain' => env('SESSION_DOMAIN'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| HTTPS Only Cookies
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| By setting this option to true, session cookies will only be sent back
|
||||
| to the server if the browser has a HTTPS connection. This will keep
|
||||
| the cookie from being sent to you when it can't be done securely.
|
||||
|
|
||||
*/
|
||||
|
||||
'secure' => env('SESSION_SECURE_COOKIE'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| HTTP Access Only
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Setting this value to true will prevent JavaScript from accessing the
|
||||
| value of the cookie and the cookie will only be accessible through
|
||||
| the HTTP protocol. You are free to modify this option if needed.
|
||||
|
|
||||
*/
|
||||
|
||||
'http_only' => true,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Same-Site Cookies
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option determines how your cookies behave when cross-site requests
|
||||
| take place, and can be used to mitigate CSRF attacks. By default, we
|
||||
| will set this value to "lax" since this is a secure default value.
|
||||
|
|
||||
| Supported: "lax", "strict", "none", null
|
||||
|
|
||||
*/
|
||||
|
||||
'same_site' => 'lax',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Partitioned Cookies
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Setting this value to true will tie the cookie to the top-level site for
|
||||
| a cross-site context. Partitioned cookies are accepted by the browser
|
||||
| when flagged "secure" and the Same-Site attribute is set to "none".
|
||||
|
|
||||
*/
|
||||
|
||||
'partitioned' => false,
|
||||
|
||||
];
|
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| View Storage Paths
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Most templating systems load templates from disk. Here you may specify
|
||||
| an array of paths that should be checked for your views. Of course
|
||||
| the usual Laravel view path has already been registered for you.
|
||||
|
|
||||
*/
|
||||
|
||||
'paths' => [
|
||||
resource_path('views'),
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Compiled View Path
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option determines where all the compiled Blade templates will be
|
||||
| stored for your application. Typically, this is within the storage
|
||||
| directory. However, as usual, you are free to change this value.
|
||||
|
|
||||
*/
|
||||
|
||||
'compiled' => env(
|
||||
'VIEW_COMPILED_PATH',
|
||||
realpath(storage_path('framework/views'))
|
||||
),
|
||||
|
||||
];
|
@ -0,0 +1 @@
|
||||
*.sqlite*
|
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
|
||||
*/
|
||||
class UserFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The current password being used by the factory.
|
||||
*/
|
||||
protected static ?string $password;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->name(),
|
||||
'email' => fake()->unique()->safeEmail(),
|
||||
'email_verified_at' => now(),
|
||||
'password' => static::$password ??= Hash::make('password'),
|
||||
'remember_token' => Str::random(10),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the model's email address should be unverified.
|
||||
*/
|
||||
public function unverified(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'email_verified_at' => null,
|
||||
]);
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('users', function (Blueprint $table) {
|
||||
$table->id();
|
||||
// $table->string('user');
|
||||
$table->string('name');
|
||||
$table->string('fullname');
|
||||
$table->string('fullname2');
|
||||
$table->string('role');
|
||||
$table->string('email')->unique();
|
||||
$table->timestamp('email_verified_at')->nullable();
|
||||
$table->string('password');
|
||||
$table->rememberToken();
|
||||
$table->boolean('status')->default(1);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('users');
|
||||
}
|
||||
};
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('password_reset_tokens', function (Blueprint $table) {
|
||||
$table->string('email')->primary();
|
||||
$table->string('token');
|
||||
$table->timestamp('created_at')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('password_reset_tokens');
|
||||
}
|
||||
};
|
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('failed_jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('uuid')->unique();
|
||||
$table->text('connection');
|
||||
$table->text('queue');
|
||||
$table->longText('payload');
|
||||
$table->longText('exception');
|
||||
$table->timestamp('failed_at')->useCurrent();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('failed_jobs');
|
||||
}
|
||||
};
|
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('personal_access_tokens', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->morphs('tokenable');
|
||||
$table->string('name');
|
||||
$table->string('token', 64)->unique();
|
||||
$table->text('abilities')->nullable();
|
||||
$table->timestamp('last_used_at')->nullable();
|
||||
$table->timestamp('expires_at')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('personal_access_tokens');
|
||||
}
|
||||
};
|
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('trabajadores', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->string("dni",length: 8);
|
||||
$table->string("nombre",50);
|
||||
$table->string("apellido_paterno",50);
|
||||
$table->string("apellido_materno",50);
|
||||
$table->boolean('status')->default(1);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('trabajadores');
|
||||
}
|
||||
};
|
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('almacens', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->text('descripcion');
|
||||
$table->boolean('status')->default(1);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('almacens');
|
||||
}
|
||||
};
|
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('unidad_medidas', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->string('nombre');
|
||||
$table->string('abreviatura')->nullable();
|
||||
$table->boolean('status')->default(1);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('unidad_medidas');
|
||||
}
|
||||
};
|
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('bienes', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->string('codigo');
|
||||
$table->text('descripcion');
|
||||
$table->string('marca');
|
||||
$table->string('id_unidad_medida')->nullable();
|
||||
$table->boolean('status')->default(1);
|
||||
$table->timestamps();
|
||||
$table->foreign('id_unidad_medida')->references('id')->on('unidad_medidas')->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('bienes');
|
||||
}
|
||||
};
|
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('sedes', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->decimal("cuenta_de_costo",11,0);
|
||||
$table->text("descripcion");
|
||||
$table->string("sede");
|
||||
$table->string("responsable");
|
||||
$table->boolean('status')->default(1);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('sedes');
|
||||
}
|
||||
};
|
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('inventario_inicials', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->string('descripcion')->nullable();
|
||||
$table->string('bienes_id')->nullable(); // Asegúrate de crear la columna primero
|
||||
$table->string('cuenta', 10)->change(); //cambiamos de integer a varchar
|
||||
$table->decimal('cantidad', 10, 4);
|
||||
$table->decimal('cantidad_inicial', 10, 4);
|
||||
$table->decimal('precio', 10, 4);
|
||||
$table->string('fecha_registro');
|
||||
$table->boolean('status')->default(1);
|
||||
$table->timestamps();
|
||||
$table->foreign('bienes_id')->references('id')->on('bienes')->onDelete('cascade');
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('inventario_inicials');
|
||||
}
|
||||
};
|
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('metas', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->text('meta_1')->nullable();;
|
||||
$table->text('meta_2')->nullable();;
|
||||
$table->text('obra')->nullable();;
|
||||
$table->string('residente')->nullable();
|
||||
$table->string('almacenario')->nullable();
|
||||
$table->string('asistente_administativo')->nullable();
|
||||
// $table->foreign('id_residente')->references('id')->on('trabajadores')
|
||||
// ->onDelete('set null');
|
||||
// $table->string('id_almacenario')->references('id')->on('trabajadores')
|
||||
// ->onDelete('set null');
|
||||
// $table->foreign('id_asistente_adm')->references('id')->on('trabajadores')
|
||||
// ->onDelete('set null');
|
||||
$table->boolean('status')->default(1);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('metas');
|
||||
}
|
||||
};
|
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('obras', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->string('obras')->nullable(); //yo le hubiera puesto descripcion
|
||||
$table->boolean('status')->default(1);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('obras');
|
||||
}
|
||||
};
|
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('nea_entradas', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->string('codigo')->nullable();
|
||||
|
||||
$table->string('id_trabajadores')->nullable();
|
||||
|
||||
$table->string('tipo_de_sede')->nullable();
|
||||
$table->string('tipo_de_ingreso')->nullable();
|
||||
$table->string('recibido_por')->nullable();
|
||||
$table->string('id_meta')->nullable();
|
||||
|
||||
$table->string('tipo_de_moneda')->nullable();
|
||||
$table->string('tipo_de_almacen')->nullable();
|
||||
$table->string('documento')->nullable();
|
||||
$table->string('tipo_de_cambio')->nullable();
|
||||
$table->string('tipo_de_uso')->nullable();
|
||||
$table->string('oficio')->nullable();
|
||||
$table->dateTime('fecha_de_nea')->nullable();
|
||||
$table->dateTime('fecha_de_registro')->nullable();
|
||||
$table->boolean('status')->default(1);
|
||||
$table->timestamps();
|
||||
|
||||
$table->foreign('id_trabajadores')->references('id')->on('trabajadores')
|
||||
->onDelete('set null');
|
||||
// $table->foreign('tipo_de_sede')->references('id')->on('sedes')
|
||||
// ->onDelete('set null');
|
||||
$table->foreign('id_meta')->references('id')->on('metas')
|
||||
->onDelete('set null');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('nea_entradas');
|
||||
}
|
||||
};
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue