configuracion de nfc y export exel

This commit is contained in:
Jose Sanchez
2023-08-08 11:01:11 -04:00
parent 79422c66b8
commit edd191b4be
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',
];
}