mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
añadidos presupuestos en cliente
This commit is contained in:
@ -20,6 +20,8 @@ use App\Models\Presupuestos\PresupuestoPreimpresionesModel;
|
||||
use App\Models\Presupuestos\PresupuestoServiciosExtraModel;
|
||||
use App\Services\PresupuestoService;
|
||||
use App\Services\PresupuestoClienteService;
|
||||
use Hermawan\DataTables\DataTable;
|
||||
use CodeIgniter\I18n\Time;
|
||||
use Exception;
|
||||
|
||||
class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
||||
@ -1684,6 +1686,91 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
||||
}
|
||||
|
||||
|
||||
public function tablaClienteForm()
|
||||
{
|
||||
|
||||
$clienteId = $this->request->getGet('cliente_id') ?? -1;
|
||||
|
||||
$q = $this->model->getPresupuestosClienteForm($clienteId);
|
||||
|
||||
$searchValue = $this->request->getGet('fecha') ?? '';
|
||||
if (!empty($searchValue)) {
|
||||
// Extraer las fechas del formato "YYYY-MM-DD|YYYY-MM-DD"
|
||||
$dates = explode('|', $searchValue);
|
||||
if (count($dates) == 2) {
|
||||
$q->where('p.created_at >=', $dates[0] . ' 00:00:00')
|
||||
->where('p.created_at <=', $dates[1] . ' 23:59:59');
|
||||
}
|
||||
}
|
||||
|
||||
$result = DataTable::of($q)
|
||||
->edit(
|
||||
'fecha',
|
||||
fn($q) => $q->fecha?Time::createFromFormat("Y-m-d H:i:s", $q->fecha)->format("d/m/Y"):""
|
||||
)
|
||||
->edit(
|
||||
'estado', fn($q) => match ($q->estado) {
|
||||
"1" => lang('Presupuestos.borrador'),
|
||||
"2" => lang('Presupuestos.confirmado'),
|
||||
default => '--'
|
||||
}
|
||||
)->add("action", callback: function ($q) {
|
||||
return '
|
||||
<div class="btn-group btn-group-sm">
|
||||
<a href="javascript:void(0);"><i class="ti ti-eye ti-sm btn-edit mx-2" data-id="' . $q->id . '"></i></a>
|
||||
</div>
|
||||
';
|
||||
|
||||
});
|
||||
|
||||
return $result->toJson(returnAsObject: true) ;
|
||||
}
|
||||
|
||||
public function obtenerTotalPresupuestosCliente($cliente_id){
|
||||
|
||||
$error = false;
|
||||
$result = [
|
||||
'total_impresion' => 0,
|
||||
'total_maquetacion' => 0,
|
||||
];
|
||||
$data = $this->model
|
||||
->where('presupuestos.cliente_id', $cliente_id)
|
||||
->select('SUM(presupuestos.total_aceptado) as total')
|
||||
->groupBy('presupuestos.cliente_id')->get()->getResultObject();
|
||||
if(count($data) > 0){
|
||||
$result['total_impresion'] = round(floatval($data[0]->total), 2);
|
||||
}
|
||||
else{
|
||||
$error = true;
|
||||
}
|
||||
$result['total'] = $result['total_impresion'] + $result['total_maquetacion'];
|
||||
return $this->respond(['status' => $error?'error':'success', 'totales' => $result]);
|
||||
}
|
||||
|
||||
public function obtenerTotalPedidosCliente($cliente_id){
|
||||
|
||||
$error = false;
|
||||
$result = [
|
||||
'total_impresion' => 0,
|
||||
'total_maquetacion' => 0,
|
||||
];
|
||||
$data = $this->model
|
||||
->where('presupuestos.cliente_id', $cliente_id)->whereNotIn('pedidos.estado', ['cancelado'])
|
||||
->select('SUM(pedidos.total_precio) as total')
|
||||
->join('pedidos_linea', 'pedidos_linea.pedido_id = pedidos.id')
|
||||
->join('presupuestos', 'presupuestos.id = pedidos_linea.presupuesto_id')
|
||||
->groupBy('presupuestos.cliente_id')->get()->getResultObject();
|
||||
if(count($data) > 0){
|
||||
$result['total_impresion'] = round(floatval($data[0]->total), 2);
|
||||
}
|
||||
else{
|
||||
$error = true;
|
||||
}
|
||||
$result['total'] = $result['total_impresion'] + $result['total_maquetacion'];
|
||||
return $this->respond(['status' => $error?'error':'success', 'totales' => $result]);
|
||||
}
|
||||
|
||||
|
||||
protected function getClienteListItems($selId = null)
|
||||
{
|
||||
$data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Clientes.cliente'))])];
|
||||
|
||||
Reference in New Issue
Block a user