mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
trabajando en el form de cliente
This commit is contained in:
@ -79,7 +79,25 @@ class Pedido extends \App\Controllers\BaseResourceController
|
||||
}
|
||||
|
||||
public function edit($id=null){
|
||||
echo "Edit";
|
||||
|
||||
if ($id == null) :
|
||||
return $this->redirect2listView();
|
||||
endif;
|
||||
$id = filter_var($id, FILTER_SANITIZE_URL);
|
||||
$pedidoEntity = $this->model->find($id);
|
||||
|
||||
if ($pedidoEntity == false) :
|
||||
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Pedidos.pedido')), $id]);
|
||||
return $this->redirect2listView('sweet-error', $message);
|
||||
endif;
|
||||
|
||||
$this->obtenerDatosFormulario($pedidoEntity);
|
||||
|
||||
$this->viewData['pedidoEntity'] = $pedidoEntity;
|
||||
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('Pedidos.moduleTitle') . ' ' . lang('Basic.global.edit3');
|
||||
|
||||
return $this->displayForm(__METHOD__, $id);
|
||||
}
|
||||
|
||||
public function datatable(){
|
||||
@ -96,7 +114,7 @@ class Pedido extends \App\Controllers\BaseResourceController
|
||||
$length = $reqData['length'] ?? 5;
|
||||
$search = $reqData['search']['value'];
|
||||
$requestedOrder = $reqData['order']['0']['column'] ?? 0;
|
||||
$order = PedidoModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 0];
|
||||
$order = PedidoModel::SORTABLE_TODOS[$requestedOrder >= 0 ? $requestedOrder : 0];
|
||||
$dir = $reqData['order']['0']['dir'] ?? 'asc';
|
||||
|
||||
$resourceData = $this->model->getResource($search)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
|
||||
@ -111,5 +129,19 @@ class Pedido extends \App\Controllers\BaseResourceController
|
||||
}
|
||||
}
|
||||
|
||||
private function obtenerDatosFormulario(&$pedidoEntity){
|
||||
|
||||
$pedidoLineaModel = model('\App\Models\Pedidos\PedidoLineaModel');
|
||||
$clienteModel = model('\App\Models\Clientes\ClienteModel');
|
||||
$presupuestoModel = model('\App\Models\Presupuestos\PresupuestoModel');
|
||||
|
||||
$linea = $pedidoLineaModel->where('pedido_id', $pedidoEntity->id)->first();
|
||||
// los clientes son los mismos para todas las lineas de un mismo presupuesto
|
||||
$presupuesto = $presupuestoModel->find($linea->presupuesto_id);
|
||||
$cliente = $clienteModel->find($presupuesto->cliente_id);
|
||||
|
||||
$pedidoEntity->cliente = $cliente->nombre;
|
||||
$pedidoEntity->cliente_id = $cliente->id;
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,6 +20,7 @@ use Exception;
|
||||
|
||||
use function PHPUnit\Framework\containsOnly;
|
||||
|
||||
|
||||
class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
{
|
||||
protected $modelName = "PresupuestoModel";
|
||||
@ -787,6 +788,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
|
||||
if ($confirmar) {
|
||||
$model_presupuesto->confirmarPresupuesto($id);
|
||||
$this->crearPedido($id);
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
@ -889,6 +891,44 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
* Funciones auxiliares
|
||||
*
|
||||
**********************/
|
||||
public function crearPedido($presupuesto_id)
|
||||
{
|
||||
$model_pedido = model('App\Models\Pedidos\PedidoModel');
|
||||
$model_pedido_linea = model('App\Models\Pedidos\PedidoLineaModel');
|
||||
$model_cliente = model('App\Models\Clientes\ClienteModel');
|
||||
|
||||
$model_presupuesto = new PresupuestoModel();
|
||||
$datos_presupuesto = $model_presupuesto->find($presupuesto_id);
|
||||
|
||||
$id_linea = 0;
|
||||
|
||||
$data_pedido = [
|
||||
'total_precio' => $datos_presupuesto->total_aceptado,
|
||||
'total_tirada' => $datos_presupuesto->tirada,
|
||||
'estado' => $model_cliente->creditoDisponible($datos_presupuesto->cliente_id) ? "produccion" : "validacion",
|
||||
'user_created_id' => auth()->user()->id,
|
||||
'user_updated_id' => auth()->user()->id,
|
||||
];
|
||||
|
||||
$pedido_id = $model_pedido->insert($data_pedido);
|
||||
if($pedido_id){
|
||||
$data_pedido_linea = [
|
||||
"pedido_id" => $pedido_id,
|
||||
"presupuesto_id" => $presupuesto_id,
|
||||
"ubicacion_id" => 1, // safetak por defecto
|
||||
"user_created_id" => auth()->user()->id,
|
||||
"user_updated_id" => auth()->user()->id,
|
||||
];
|
||||
$id_linea = $model_pedido_linea->insert($data_pedido_linea);
|
||||
}
|
||||
|
||||
if($id_linea != 0 && $pedido_id != 0){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
protected function borrarRelacionesPresupuesto($id)
|
||||
{
|
||||
// Se borran las lineas de presupuesto
|
||||
|
||||
Reference in New Issue
Block a user