Untitled
unknown
plain_text
2 years ago
5.2 kB
10
Indexable
<?php
namespace App\Repositories\TransactionByQuota;
use App\Models\TransactionByQuota;
use App\Repositories\Repository;
use Auth;
use DB;
use Carbon\Carbon;
use File;
use Illuminate\Support\Carbon as SupportCarbon;
use Illuminate\Support\Facades\Storage;
class TransactionByQuotaRepository extends Repository
{
/**
* @const RELATIONS
*
* Relaciones del repositorio
*
*/
const RELATIONS = [
// 'tarjeta.afiliado'
];
/**
* TransactionByQuotaRepository constructor.
*
*/
public function __construct(TransactionByQuota $model)
{
parent::__construct($model, self::RELATIONS);
}
/**
* This PHP fa provided in an object.
*
* @param object data is an object that contains the data needed to create a new record in
* the database. The object should have the following properties: cedula, nombre1, nombre2,
* apellido1, apellido2, correo, and telefono. These properties represent the personal information
* of a person.
*
* @return the result of creating a new record in the database using the `create` method of the
* model. The data for the new record is being passed as an associative array with keys `cedula`,
* `nombre1`, `nombre2`, `apellido1`, `apellido2`, `correo`, and `telefono`.
*/
public function createNew(object $data, $cuenta_afiliado)
{
$image1 = $this->base64_to_jpeg($data->file_factura,'tmp.jpg');
$image2 = $this->base64_to_jpeg($data->file_ci_afiliado,'tmp.jpg');
$path_factura = $this->saveFileCuotaTransaccion($image1 );
$path_ci_afiliado = $this->saveFileCuotaTransaccion($$image2);
return $this->model::with('statusAfiliado', 'cuentaAfiliados')->create([
'serie' => $data->serie,
'factura' => $data->factura,
'observacion' => $data->observacion,
'pago_contado' => doubleEncryption($data->pago_contado),
'emision' => $data->emision ?? Carbon::now()->format('Y-m-d'),
'monto_factura' => doubleEncryption($data->monto_factura),
'monto_credito' => doubleEncryption($data->monto_credito),
'sucursal_id' => $data->sucursal_id,
'user_id' => $data->user_id ?? Auth::id(),
'cuenta_id' => $cuenta_afiliado->id,
'url_factura' => Storage::disk('transaccion')->url($path_factura),
'path_factura' => $path_factura,
'url_photo_afiliado' => Storage::disk('transaccion')->url($path_ci_afiliado),
'path_photo_afiliado' => $path_ci_afiliado,
]);
}
private function saveFileCuotaTransaccion($file)
{
$path = $file->store('transacciones', 'transaccion');
return $path;
}
private function base64_to_jpeg($base64_string, $output_file) {
$prueba = file_put_contents($output_file, file_get_contents($base64_string));
$filename_path = md5(time().uniqid()).".jpg";
// $decoded=base64_decode($base64_string);
// dd($decoded);
$path = Storage::disk('transaccion')->put($filename_path, $prueba);
return $path;
}
/**
* It returns a query builder object with a nested relationship, and then it queries the database
* again to get the first result of the query builder object, and then it gets the nested
* relationship of the first result, and then it gets the nested relationship of the nested
* relationship, and then it compares the nested relationship of the nested relationship of the
* first result of the query builder object with the document and type parameters
*
* @param invoice The invoice number
* @param document The document number of the user
* @param type is the type of document, in this case it's a cedula (national id)
*
* @return A query builder object.
*/
public function searchInvoice($invoice, string $serie = null)
{
$user = Auth::user();
return $this->model::where([
['factura', $invoice],
["serie", $serie],
['sucursal_id', is_null($user->sucursal_id) ? 1 : $user->sucursal_id]
])->first();
// if(!isset($query))
// {
// return true;
// }else{
// $afiliado = $query->tarjeta->afiliado;
// dd(doubleDecryption($afiliado->aficedula) == $document && $afiliado->afitipoid = $type) ? true : false;
// return (doubleDecryption($afiliado->aficedula) == $document && $afiliado->afitipoid = $type) ? true : false;
// }
}
public function findById($id)
{
return $this->model::with(self::RELATIONS)->where('id', $id)->with(self::RELATIONS)->first();
}
public function findByAccountId($id)
{
return $this->model::with(self::RELATIONS)->where('cuenta_id', $id)->get();
}
public function index()
{
return $this->model::with(self::RELATIONS)
->whereDate('created_at', Carbon::now()->format('Y-m-d'))
->where('sucursal_id', Auth::user()->sucursal_id)
->get()->map->format();
}
}
Editor is loading...
Leave a Comment