Merge pull request #3 from lapieza-dev/alejandro

configuracion de nfc y export exel
This commit is contained in:
Jose Sanchez
2023-08-08 11:19:17 -04:00
committed by GitHub
8 changed files with 495 additions and 2 deletions

View File

@@ -0,0 +1,17 @@
<?php
namespace App\Exports;
use App\Models\NfcVoucher;
use Maatwebsite\Excel\Concerns\FromCollection;
class NfcVoucherExportsCollection implements FromCollection
{
/**
* @return \Illuminate\Support\Collection
*/
public function collection()
{
return NfcVoucher::all();
}
}

View File

@@ -0,0 +1,73 @@
<?php
namespace App\Exports;
use App\Models\NfcVoucher;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
use Maatwebsite\Excel\Concerns\WithStyles;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use PhpOffice\PhpSpreadsheet\Style\Fill;
class NfcVoucherExportsView implements FromView, WithStyles
{
protected $nfc_vouchers;
public function __construct($nfc_vouchers)
{
$this->nfc_vouchers = $nfc_vouchers;
}
public function view(): View
{
return view('seller.pos.exports.nfc_chourches', [
'nfc_vouchers' => $this->nfc_vouchers
]);
}
//estilos de exel
public function styles(Worksheet $sheet)
{
$nfc_vouchersCount = count($this->nfc_vouchers);
// Aplica los estilos a la tabla en Excel
$sheet->getStyle('A1:H1')->getFont()->setBold(true);
$sheet->getStyle('A1:H1')->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setRGB('DDDDDD');
$sheet->getStyle('A2:H' . ($nfc_vouchersCount + 1))->getAlignment()->setWrapText(true);
// Ajusta automáticamente el ancho de las columnas
foreach(range('A', 'H') as $column) {
$sheet->getColumnDimension($column)->setAutoSize(true);
}
// Agrega líneas alternas de color a las filas
for ($row = 2; $row <= $nfc_vouchersCount + 1; $row += 2) {
$sheet->getStyle('A' . $row . ':H' . $row)->applyFromArray([
'fill' => [
'fillType' => Fill::FILL_SOLID,
'startColor' => [
'rgb' => 'F2F2F2' // Color gris claro
]
],
'borders' => [
'allBorders' => [
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
'color' => ['rgb' => '000000'] // Color negro
]
]
]);
}
// Agrega bordes a todas las celdas
$sheet->getStyle('A1:H' . ($nfc_vouchersCount + 1))->applyFromArray([
'borders' => [
'allBorders' => [
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
'color' => ['rgb' => '000000'] // Color negro
]
]
]);
}
}

View File

@@ -0,0 +1,135 @@
<?php
namespace App\Http\Controllers;
use App\Exports\NfcVoucherExportsCollection;
use App\Exports\NfcVoucherExportsView;
use App\Models\NfcVoucher;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Maatwebsite\Excel\Facades\Excel;
class NfcVouchersController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request, NfcVoucher $nfc_voucher)
{
$validatedData = $request->validate([
'nfc_type' => 'required',
'nfc_following' => 'required',
'nfc_expiration' => 'required|date',
'nfc_amount' => 'required|numeric',
'nfc_next' => 'required',
'nfc_select' => 'required|in:active,deactivated',
]);
// Guardar los datos en la base de datos
DB::beginTransaction();
try {
$nfc_voucher->nfc_type = $validatedData['nfc_type'];
$nfc_voucher->nfc_following = $validatedData['nfc_following'];
$nfc_voucher->nfc_expiration = $validatedData['nfc_expiration'];
$nfc_voucher->nfc_amount = $validatedData['nfc_amount'];
$nfc_voucher->nfc_next = $validatedData['nfc_next'];
$nfc_voucher->nfc_select = $validatedData['nfc_select'];
$nfc_voucher->save();
DB::commit();
// Redireccionar o mostrar un mensaje de éxito
// Redireccionar a la ruta '/pos-activation'
return redirect()->route('pos.configuration')->with('toast_success', '¡Política de empresa creada con éxito!');
} catch (\Exception $e) {
DB::rollback();
// Manejar el error y mostrar un mensaje de error
//
}
}
/**
* Display the specified resource.
*
* @param \App\Models\NfcVoucher $nfcVoucher
* @return \Illuminate\Http\Response
*/
public function show(NfcVoucher $nfcVoucher)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Models\NfcVoucher $nfcVoucher
* @return \Illuminate\Http\Response
*/
public function edit(NfcVoucher $nfcVoucher)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\NfcVoucher $nfcVoucher
* @return \Illuminate\Http\Response
*/
public function update(Request $request, NfcVoucher $nfcVoucher)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param \App\Models\NfcVoucher $nfcVoucher
* @return \Illuminate\Http\Response
*/
public function collection()
{
return Excel::download(new NfcVoucherExportsCollection, 'Nfc_Voucher.xlsx');
}
public function view()
{
// return Excel::download(new NfcVoucherExportsView, 'Nfc_Voucher.xlsx');
$nfc_vouchers = NfcVoucher::latest()->get();// Obtén los datos de la tabla desde tu controlador o modelo
return Excel::download(new NfcVoucherExportsView($nfc_vouchers), 'nfc_vouchers.xlsx');
}
}

View File

@@ -17,6 +17,7 @@ use Mail;
use App\Mail\InvoiceEmailManager;
use App\Http\Resources\PosProductCollection;
use App\Models\Country;
use App\Models\NfcVoucher;
use App\Models\State;
use App\Utility\CategoryUtility;
use App\Utility\FontUtility;
@@ -365,7 +366,12 @@ class PosController extends Controller
public function configuration()
{
return view('seller.pos.pos_activation');
//AQUI AGREGO LA CONSULTA donde traigo los comprobantes desde el ultimo que agrego que se muestre primero
$nfc_vouchers = $nfc_vouchers = NfcVoucher::latest()->get();
return view('seller.pos.pos_activation', compact('nfc_vouchers'));
}
public function invoice($id)

22
app/Models/NfcVoucher.php Normal file
View File

@@ -0,0 +1,22 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class NfcVoucher extends Model
{
use HasFactory;
protected $fillable = [
'nfc_type',
'nfc_following',
'nfc_expiration',
'nfc_amount',
'nfc_next',
'nfc_select',
'nfc_used',
'user_id',
];
}

View File

@@ -0,0 +1,41 @@
<table id="nfc_vouchers_table" class="table table-striped">
<thead>
<tr>
<th>ID</th>
<th>NFC Tipo</th>
<th>NFC Siguiente</th>
<th>NFC Vencimiento</th>
<th>NFC Cantidad</th>
<th>NFC Próximo</th>
<th>NFC Estado</th>
<th>NFC Usado</th>
</tr>
</thead>
<tbody>
@foreach($nfc_vouchers as $nfc_voucher)
<tr>
<td>{{ $nfc_voucher->id }}</td>
<td>{{ $nfc_voucher->nfc_type }}</td>
<td>{{ $nfc_voucher->nfc_following }}</td>
<td>{{ $nfc_voucher->nfc_expiration }}</td>
<td>{{ $nfc_voucher->nfc_amount }}</td>
<td>{{ $nfc_voucher->nfc_next }}</td>
<td>
@if($nfc_voucher->nfc_select == 'active')
Activo
@elseif($nfc_voucher->nfc_select == 'deactivated')
Desactivado
@endif
</td>
<td>
@if($nfc_voucher->nfc_used == 'not_use')
No usado
@elseif($nfc_voucher->nfc_used == 'in_use')
En uso
@endif
</td>
</tr>
@endforeach
</tbody>
</table>

View File

@@ -29,7 +29,192 @@
</div>
</div>
</div>
<div class="col-lg-8">
<div class="card">
<div class="card-header">
<h5 class="mb-0 h6">{{ translate('Lista de comprobantes fiscales') }}</h5>
<div class="float-right">
{{-- <a class="btn btn-info" href="{{ route('pos.configuration.collection') }}">Exportar (Collection)</a> --}}
<a class="btn btn-success" href="{{ route('pos.configuration.view') }}">Exportar en excel</a>
<button class="btn btn-primary" data-toggle="modal" data-target="#agregarModal">Agregar</button>
</div>
</div>
<div class="card-body ">
<table id="nfc_vouchers_table" class="table table-striped">
<thead>
<tr>
<th>ID</th>
<th>NFC Tipo</th>
<th>NFC Siguiente</th>
<th>NFC Vencimiento</th>
<th>NFC Cantidad</th>
<th>NFC Próximo</th>
<th>NFC Estado</th>
<th>NFC Usado</th>
</tr>
</thead>
<tbody>
@foreach($nfc_vouchers as $nfc_voucher)
<tr>
<td>{{ $nfc_voucher->id }}</td>
<td>{{ $nfc_voucher->nfc_type }}</td>
<td>{{ $nfc_voucher->nfc_following }}</td>
<td>{{ $nfc_voucher->nfc_expiration }}</td>
<td>{{ $nfc_voucher->nfc_amount }}</td>
<td>{{ $nfc_voucher->nfc_next }}</td>
<td>
@if($nfc_voucher->nfc_select == 'active')
Activo
@elseif($nfc_voucher->nfc_select == 'deactivated')
Desactivado
@endif
</td>
<td>
@if($nfc_voucher->nfc_used == 'not_use')
No usado
@elseif($nfc_voucher->nfc_used == 'in_use')
En uso
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
<div class="modal fade" id="agregarModal" tabindex="-1" role="dialog" aria-labelledby="agregarModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="agregarModalLabel">Agregar Comprobante Fiscal</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<form class="form-horizontal" action="{{ route('pos.configuration.store') }}" method="POST">
@csrf
<div class="modal-body">
<!-- Contenido del modal -->
<div class="form-group row">
<div class="form-group col-md-3">
<label for="nfc_type">Selección del tipo</label>
<select class="form-control @error('nfc_type') is-invalid @enderror" name="nfc_type" id="nfc_type">
<option value="" selected>Seleccione nfc</option>
<option value="B01">B01</option>
<option value="B02">B02</option>
<option value="B15">B15</option>
</select>
@error('nfc_type')
<div class="invalid-feedback">{{ $message }}</div>
@enderror
</div>
<div class="form-group col-md-5">
<label for="nfc_following">Siguientes 8 caracteres</label>
<input type="number" class="form-control @error('nfc_following') is-invalid @enderror" name="nfc_following" id="nfc_following" placeholder="">
@error('nfc_following')
<div class="invalid-feedback">{{ $message }}</div>
@enderror
</div>
<div class="form-group col-md-4">
<label for="nfc_expiration">Fecha de vencimiento</label>
<input type="date" class="form-control @error('nfc_expiration') is-invalid @enderror" name="nfc_expiration" id="nfc_expiration" placeholder="">
@error('nfc_expiration')
<div class="invalid-feedback">{{ $message }}</div>
@enderror
</div>
</div>
<div class="form-group row">
<div class="form-group col-md-5">
<label for="nfc_amount">Cantidad de comprobantes</label>
<input type="number" class="form-control @error('nfc_amount') is-invalid @enderror" name="nfc_amount" id="nfc_amount" placeholder="">
@error('nfc_amount')
<div class="invalid-feedback">{{ $message }}</div>
@enderror
</div>
<div class="form-group col-md-4">
<label for="nfc_next">Próximo NFC a emitir</label>
<input type="number" class="form-control @error('nfc_next') is-invalid @enderror" name="nfc_next" id="nfc_next" placeholder="">
@error('nfc_next')
<div class="invalid-feedback">{{ $message }}</div>
@enderror
</div>
<div class="form-group col-md-3" style="top: 23px">
<div class="custom-control @error('nfc_select') is-invalid @enderror custom-radio">
<input type="radio" class="custom-control-input" id="customControlValidation2" name="nfc_select" value="active">
<label class="custom-control-label" for="customControlValidation2">Activar NFC</label>
</div>
<div class="custom-control custom-radio mb-3">
<input type="radio" class="custom-control-input" id="customControlValidation3" name="nfc_select" value="deactivated">
<label class="custom-control-label" for="customControlValidation3">Desactivar NFC</label>
</div>
@error('nfc_select')
<div class="invalid-feedback">{{ $message }}</div>
@enderror
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cerrar</button>
<button type="submit" id="guardar-btn" class="btn btn-primary">Guardar</button>
</div>
</form>
</div>
</div>
</div>
{{-- @dd($nfc_vouchers) --}}
{{-- --}}
</div>
@endsection
@push('styles')
<link rel="stylesheet" type="text/css"
href="https://cdn.datatables.net/v/bs5/dt-1.13.1/r-2.4.0/datatables.min.css" />
@endpush
@push('scripts')
<script type="text/javascript" src="https://cdn.datatables.net/v/bs5/dt-1.13.1/r-2.4.0/datatables.min.js"></script>
<script>
$(document).ready(function() {
$('#nfc_vouchers_table').DataTable({
responsive: true,
"autoWidth": false,
language: {
searchPlaceholder: "Buscar...",
search: "",
url: "//cdn.datatables.net/plug-ins/1.13.1/i18n/es-ES.json",
},
order: [[0, 'desc']] // Ordenar por la primera columna (fecha de creación) en orden descendente
});
});
</script>
@endpush

View File

@@ -13,6 +13,7 @@
use App\Http\Controllers\PosController;
use App\Http\Controllers\BusinessSettingsController;
use App\Http\Controllers\NfcVouchersController;
use App\Http\Controllers\Seller\PosController as SellerPosController;
Route::controller(PosController::class)->group(function () {
@@ -37,6 +38,9 @@ Route::group(['prefix' => 'admin', 'middleware' => ['auth', 'admin']], function
Route::get('/pos-activation', 'configuration')->name('poin-of-sales.activation');
Route::get('/pos/thermal-printer/{order_id}', 'invoice')->name('admin.invoice.thermal_printer');
});
//
});
//Seller
@@ -44,8 +48,18 @@ Route::group(['prefix' => 'seller', 'middleware' => ['seller', 'verified']], fun
Route::controller(SellerPosController::class)->group(function () {
Route::get('/pos', 'index')->name('poin-of-sales.seller_index');
Route::get('/pos/thermal-printer/{order_id}', 'invoice')->name('seller.invoice.thermal_printer');
//aqui esta el index o lista de NFC
Route::get('/pos-activation', 'configuration')->name('pos.configuration');
Route::get('/pos/products', 'search')->name('pos.search_seller_product');
});
Route::post('/pos-configuration', [BusinessSettingsController::class, 'update'])->name('seller_business_settings.update');
Route::post('/pos-configuration', [BusinessSettingsController::class, 'update'])->name('seller_business_settings.update');
//configuracion de los comprobantes NFC
//CREAR NFC
Route::post('/nfc_store', [NfcVouchersController::class, 'store'])->name('pos.configuration.store');
//EXPORTAR por exel
Route::get('/nfc_configuration/collection', [NfcVouchersController::class, 'collection'])->name('pos.configuration.collection');
Route::get('/nfc_configuration/view', [NfcVouchersController::class, 'view'])->name('pos.configuration.view');
});