mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
guardando direcciones ferro en presupuesto cliente
This commit is contained in:
@ -319,6 +319,7 @@ $routes->group('clienteusuarios', ['namespace' => 'App\Controllers\Clientes'], f
|
||||
$routes->group('misdirecciones', ['namespace' => 'App\Controllers\Clientes'], function ($routes) {
|
||||
$routes->get('', 'Clientedirecciones::index', ['as' => 'clientedireccionesIndex']);
|
||||
$routes->get('get/(:num)', 'Clientedirecciones::get/$1', ['as' => 'get']);
|
||||
$routes->get('getId', 'Clientedirecciones::getDireccionIdFromData');
|
||||
$routes->get('getDireccionPresupuesto/(:num)', 'Clientedirecciones::getDireccionPresupuesto/$1', ['as' => 'getDireccionPresupuesto']);
|
||||
$routes->post('add', 'Clientedirecciones::add', ['as' => 'newClientedirecciones']);
|
||||
$routes->get('getSelect2', 'Clientedirecciones::getSelect2', ['as' => 'listaClientedirecciones']);
|
||||
|
||||
@ -215,13 +215,13 @@ class Clientedirecciones extends \App\Controllers\BaseResourceController
|
||||
{
|
||||
try {
|
||||
$resourceData = $this->model->getDireccion($id);
|
||||
$response = (object)[
|
||||
$response = (object) [
|
||||
'error' => false,
|
||||
'data' => $resourceData
|
||||
];
|
||||
return $this->respond($response);
|
||||
} catch (\Exception $e) {
|
||||
$response = (object)[
|
||||
$response = (object) [
|
||||
'error' => true,
|
||||
'message' => $e->getMessage()
|
||||
];
|
||||
@ -229,22 +229,61 @@ class Clientedirecciones extends \App\Controllers\BaseResourceController
|
||||
}
|
||||
}
|
||||
|
||||
public function getDireccionIdFromData()
|
||||
{
|
||||
$data = $this->request->getGet('data') ?? [];
|
||||
$cliente_id = $this->request->getGet('cliente_id') ?? -1;
|
||||
$att = $data['att'] ?? "";
|
||||
$direccion = $data['direccion'] ?? "";
|
||||
$cp = $data['cp'] ?? "";
|
||||
$municipio = $data['municipio'] ?? "";
|
||||
$provincia = $data['provincia'] ?? "";
|
||||
$pais_id = $data['pais_id'] ?? -1;
|
||||
$email = $data['email'] ?? "";
|
||||
$telefono = $data['telefono'] ?? "";
|
||||
try {
|
||||
$model = model('App\Models\Clientes\ClienteDireccionesModel');
|
||||
$id = $model->select('id')
|
||||
->where('att', $att)
|
||||
->where('direccion', $direccion)
|
||||
->where('cp', $cp)
|
||||
->where('municipio', $municipio)
|
||||
->where('provincia', $provincia)
|
||||
->where('pais_id', $pais_id)
|
||||
->where('email', $email)
|
||||
->where('telefono', $telefono)
|
||||
->where('cliente_id', $cliente_id)
|
||||
->get()
|
||||
->getResultObject();
|
||||
|
||||
if (count($id) > 0) {
|
||||
$id = $id[0]->id;
|
||||
} else {
|
||||
$id = null;
|
||||
}
|
||||
return $id;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
throw new \RuntimeException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function getDireccionPresupuesto($id)
|
||||
{
|
||||
try {
|
||||
$model = model('App\Models\Presupuestos\PresupuestoDireccionesModel');
|
||||
$resourceData = $model->getDireccion($id);
|
||||
if(count($resourceData) > 0){
|
||||
if (count($resourceData) > 0) {
|
||||
$resourceData[0]->direccionId = $id;
|
||||
}
|
||||
|
||||
$response = (object)[
|
||||
|
||||
$response = (object) [
|
||||
'error' => false,
|
||||
'data' => $resourceData
|
||||
];
|
||||
return $this->respond($response);
|
||||
} catch (\Exception $e) {
|
||||
$response = (object)[
|
||||
$response = (object) [
|
||||
'error' => true,
|
||||
'message' => $e->getMessage()
|
||||
];
|
||||
@ -400,11 +439,11 @@ class Clientedirecciones extends \App\Controllers\BaseResourceController
|
||||
protected function getComunidadAutonomaListItems($selId = null)
|
||||
{
|
||||
$data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('ComunidadesAutonomas.comunidadAutonoma'))])];
|
||||
if (!is_null($selId)) :
|
||||
if (!is_null($selId)):
|
||||
$comunidadAutonomaModel = model('App\Models\Configuracion\ComunidadAutonomaModel');
|
||||
|
||||
$selOption = $comunidadAutonomaModel->where('id', $selId)->findColumn('nombre');
|
||||
if (!empty($selOption)) :
|
||||
if (!empty($selOption)):
|
||||
$data[$selId] = $selOption[0];
|
||||
endif;
|
||||
endif;
|
||||
@ -414,11 +453,11 @@ class Clientedirecciones extends \App\Controllers\BaseResourceController
|
||||
protected function getProvinciaListItems($selId = null)
|
||||
{
|
||||
$data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Provincias.provincia'))])];
|
||||
if (!empty($selId)) :
|
||||
if (!empty($selId)):
|
||||
$provinciaModel = model('App\Models\Configuracion\ProvinciaModel');
|
||||
|
||||
$selOption = $provinciaModel->where('id', $selId)->findColumn('nombre');
|
||||
if (!empty($selOption)) :
|
||||
if (!empty($selOption)):
|
||||
$data[$selId] = $selOption[0];
|
||||
endif;
|
||||
endif;
|
||||
|
||||
@ -1065,6 +1065,9 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
|
||||
$direcciones = $reqData['direcciones'] ?? [];
|
||||
|
||||
$direccionesFP1 = $reqData['direccionesFP1'] ?? [];
|
||||
$direccionesFP2 = $reqData['direccionesFP2'] ?? [];
|
||||
|
||||
if ($tipo != "")
|
||||
$tipo_impresion_id = $this->getTipoImpresion($tipo, $cubierta['tipoCubierta']);
|
||||
else
|
||||
@ -1557,6 +1560,14 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
}
|
||||
}
|
||||
|
||||
if (count($direccionesFP1) > 0) {
|
||||
$this->guardarLineaEnvio($id, $direccionesFP1, $peso_libro, true);
|
||||
|
||||
}
|
||||
if (count($direccionesFP2) > 0) {
|
||||
$this->guardarLineaEnvio($id, $direccionesFP2, $peso_libro, true);
|
||||
}
|
||||
|
||||
if ($confirmar) {
|
||||
$model_presupuesto->confirmarPresupuesto($id);
|
||||
PresupuestoService::crearPedido($id);
|
||||
@ -1860,12 +1871,13 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
}
|
||||
|
||||
|
||||
protected function guardarLineaEnvio($presupuestoId, $direccion, $peso_libro)
|
||||
protected function guardarLineaEnvio($presupuestoId, $direccion, $peso_libro, $coste_cero = false)
|
||||
{
|
||||
|
||||
$unidades = intval($direccion['unidades']);
|
||||
$peso_envio = $peso_libro * $unidades / 1000.0;
|
||||
|
||||
|
||||
$data = $this->getCosteEnvio(
|
||||
$direccion['direccion'],
|
||||
$peso_libro,
|
||||
@ -1879,7 +1891,11 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
$data->presupuesto_id = $presupuestoId;
|
||||
$data->tarifa_id = $data->id;
|
||||
unset($data->id);
|
||||
$data->precio = $data->coste;
|
||||
if($coste_cero) {
|
||||
$data->coste = 0;
|
||||
} else {
|
||||
$data->precio = $data->coste;
|
||||
}
|
||||
unset($data->coste);
|
||||
$data->entregaPieCalle = ($direccion['entregaPalets'] == 'false' || $direccion['entregaPalets'] == 0) ? 0 : 1;
|
||||
unset($data->tipo);
|
||||
@ -3625,9 +3641,9 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
|
||||
foreach ($data as $servicio) {
|
||||
$id = "service_extra_" . $servicio->id;
|
||||
|
||||
|
||||
$tarifa_excluyente = false;
|
||||
if(str_contains(strtolower($servicio->nombre), 'ferro') || str_contains(strtolower($servicio->nombre), 'prototipo')) {
|
||||
if (str_contains(strtolower($servicio->nombre), 'ferro') || str_contains(strtolower($servicio->nombre), 'prototipo')) {
|
||||
$tarifa_excluyente = true;
|
||||
}
|
||||
$atributo_excluyente = $tarifa_excluyente ? 'data-tarifa-extra-excluyente="1"' : '';
|
||||
|
||||
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
namespace App\Database\Migrations;
|
||||
|
||||
use CodeIgniter\Database\Migration;
|
||||
|
||||
class DireccionesFerroPrototipo extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
// Insertar nuevo campo: lomo_maximo_espiral
|
||||
$this->forge->addColumn('presupuesto_direcciones', [
|
||||
'num_ferro_prototipo' => [
|
||||
'type' => 'INT',
|
||||
'constraint' => 3,
|
||||
'null' => false,
|
||||
'default' => '0',
|
||||
'description' => 'numero de ferro/prototipo',
|
||||
],
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$this->db->table('presupuesto_direcciones')->whereIn('name', [
|
||||
'num_ferro_prototipo',
|
||||
'lomo_maximo_wireo'
|
||||
])->delete();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user