mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
falta rellenar presupuesto
This commit is contained in:
@ -38,29 +38,43 @@ class Presupuestodirecciones extends \App\Controllers\GoBaseResourceController
|
||||
{
|
||||
if ($this->request->isAJAX()) {
|
||||
$reqData = $this->request->getPost();
|
||||
if (!isset($reqData['draw']) || !isset($reqData['columns'])) {
|
||||
$errstr = 'No data available in response to this specific request.';
|
||||
$response = $this->respond(Collection::datatable([], 0, 0, $errstr), 400, $errstr);
|
||||
return $response;
|
||||
|
||||
if( is_null($reqData['tipo']?? null)){
|
||||
if (!isset($reqData['draw']) || !isset($reqData['columns'])) {
|
||||
$errstr = 'No data available in response to this specific request.';
|
||||
$response = $this->respond(Collection::datatable([], 0, 0, $errstr), 400, $errstr);
|
||||
return $response;
|
||||
}
|
||||
$start = $reqData['start'] ?? 0;
|
||||
$length = 30;
|
||||
$search = $reqData['search']['value'];
|
||||
$requestedOrder = $reqData['order']['0']['column'] ?? 1;
|
||||
$order = PresupuestoDireccionesModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 1];
|
||||
$dir = $reqData['order']['0']['dir'] ?? 'asc';
|
||||
|
||||
$id_P = $reqData['presupuesto_id'] ?? -1;
|
||||
|
||||
|
||||
$resourceData = $this->model->getResource($search, $id_P)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
|
||||
|
||||
|
||||
return $this->respond(Collection::datatable(
|
||||
$resourceData,
|
||||
$this->model->getResource()->countAllResults(),
|
||||
$this->model->getResource("", $id_P)->countAllResults()
|
||||
));
|
||||
}
|
||||
$start = $reqData['start'] ?? 0;
|
||||
$length = 30;
|
||||
$search = $reqData['search']['value'];
|
||||
$requestedOrder = $reqData['order']['0']['column'] ?? 1;
|
||||
$order = PresupuestoDireccionesModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 1];
|
||||
$dir = $reqData['order']['0']['dir'] ?? 'asc';
|
||||
else if($reqData['tipo']=='get_tarifa'){
|
||||
$peso = $reqData['peso'] ?? 0;
|
||||
$paisId = $reqData['paisId'] ?? 0;
|
||||
$cp = $reqData['cp'] ?? 0;
|
||||
$tipo_envio = $reqData['tipo_envio'] ?? null;
|
||||
|
||||
$id_P = $reqData['presupuesto_id'] ?? -1;
|
||||
$model = model('App\Models\Tarifas\TarifaEnvioModel');
|
||||
return $this->respond($model->getTarifaEnvio($paisId, $cp, $peso, $tipo_envio));
|
||||
}
|
||||
|
||||
|
||||
$resourceData = $this->model->getResource($search, $id_P)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
|
||||
|
||||
|
||||
return $this->respond(Collection::datatable(
|
||||
$resourceData,
|
||||
$this->model->getResource()->countAllResults(),
|
||||
$this->model->getResource("", $id_P)->countAllResults()
|
||||
));
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
|
||||
@ -239,7 +239,14 @@ class Tarifasenviosprecios extends \App\Controllers\GoBaseResourceController {
|
||||
->validator('Validate::numeric', array(
|
||||
'message' => lang('TarifasEnviosPrecios.validation.peso_max.decimal'))
|
||||
),
|
||||
Field::inst('precio')
|
||||
Field::inst('precio_min')
|
||||
->validator('Validate::required', array(
|
||||
'message' => lang('TarifasEnviosPrecios.validation.precio.required'))
|
||||
)
|
||||
->validator('Validate::numeric', array(
|
||||
'message' => lang('TarifasEnviosPrecios.validation.precio.decimal'))
|
||||
),
|
||||
Field::inst('precio_max')
|
||||
->validator('Validate::required', array(
|
||||
'message' => lang('TarifasEnviosPrecios.validation.precio.required'))
|
||||
)
|
||||
|
||||
@ -17,9 +17,9 @@ class Test extends BaseController
|
||||
|
||||
public function index()
|
||||
{
|
||||
$model = model('App\Models\Clientes\ClienteDireccionesModel');
|
||||
$model = model('App\Models\Tarifas\TarifaEnvioPrecioModel');
|
||||
echo '<pre>';
|
||||
var_dump($model->getDireccion(1));
|
||||
var_dump($model->getEnvioPrecio(2, 1.5, "cajas"));
|
||||
echo '</pre>';
|
||||
}
|
||||
|
||||
|
||||
@ -12,7 +12,8 @@ class TarifaEnvioPrecioEntity extends \CodeIgniter\Entity\Entity
|
||||
"tipo_envio" => null,
|
||||
"peso_min" => null,
|
||||
"peso_max" => null,
|
||||
"precio" => null,
|
||||
"precio_min" => null,
|
||||
"precio_max" => null,
|
||||
"precio_adicional" => 0,
|
||||
"margen" => 0,
|
||||
"user_created_id" => 0,
|
||||
@ -26,7 +27,8 @@ class TarifaEnvioPrecioEntity extends \CodeIgniter\Entity\Entity
|
||||
"proveedor_id" => "int",
|
||||
"peso_min" => "float",
|
||||
"peso_max" => "float",
|
||||
"precio" => "float",
|
||||
"precio_min" => "float",
|
||||
"precio_max" => "float",
|
||||
"precio_adicional" => "float",
|
||||
"margen" => "float",
|
||||
"user_created_id" => "int",
|
||||
|
||||
@ -18,6 +18,7 @@ return [
|
||||
'cantidad' => 'Cantidad',
|
||||
'precio' => 'Precio',
|
||||
'saveDirection' => 'Guardar en direcciones de cliente',
|
||||
'entregaPieCalle' => 'Entrega a pie de calle',
|
||||
'validation' => [
|
||||
'max_length' => 'Max. valor caracteres alcanzado',
|
||||
'required' => 'Campo obligatorio',
|
||||
|
||||
@ -12,7 +12,9 @@ return [
|
||||
'palets' => 'Palets',
|
||||
'pesoMax' => 'Peso Max',
|
||||
'pesoMin' => 'Peso Min',
|
||||
'precio' => 'Precio peso mín.',
|
||||
'precio' => 'Precio',
|
||||
'precio_min' => 'Precio peso mín.',
|
||||
'precio_max' => 'Precio peso max.',
|
||||
'precioAdicional' => 'Precio Kg Adicional',
|
||||
'margen' => 'Margen',
|
||||
'proveedorId' => 'Proveedor',
|
||||
|
||||
@ -90,4 +90,35 @@ class TarifaEnvioModel extends \App\Models\GoBaseModel
|
||||
->orLike("t2.nombre", $search)
|
||||
->groupEnd();
|
||||
}
|
||||
|
||||
public function getTarifaEnvio($paisId, string $cp, $peso, $tipo_envio){
|
||||
// Si el pais es españa se tienen que tener en cuenta los postales
|
||||
// Se busca primero la tarifa a la que corresponde
|
||||
$builder = $this->db->table($this->table . " t1")
|
||||
->select("t1.id AS tarifa_envio_id, t2.importe_fijo as importe_fijo")
|
||||
->join("tarifas_envios_zonas t2", "t1.id = t2.tarifa_envio_id")
|
||||
->where("t1.pais_id", $paisId)
|
||||
->where("t1.is_deleted", 0)
|
||||
->where("t2.is_deleted", 0);
|
||||
|
||||
if($paisId == 1) {// España
|
||||
$builder->where("CAST(t2.cp_inicial AS UNSIGNED)<=", intval($cp))
|
||||
->where("CAST(t2.cp_final AS UNSIGNED) >=", intval($cp));
|
||||
}
|
||||
$tarifas = $builder->get()->getResultObject();
|
||||
|
||||
$resultado = [];
|
||||
|
||||
$model = model('App\Models\Tarifas\TarifaEnvioPrecioModel');
|
||||
foreach($tarifas as $tarifa){
|
||||
$precio_tarifas = $model->getEnvioPrecio($tarifa->tarifa_envio_id, $peso, $tipo_envio);
|
||||
foreach($precio_tarifas as $precio_tarifa){
|
||||
$precio_tarifa->importe_fijo = $tarifa->importe_fijo;
|
||||
array_push($resultado, $precio_tarifa);
|
||||
}
|
||||
}
|
||||
|
||||
return $resultado;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,9 +17,10 @@ class TarifaEnvioPrecioModel extends \App\Models\GoBaseModel
|
||||
1 => "t1.tipo_envio",
|
||||
2 => "t1.peso_min",
|
||||
3 => "t1.peso_max",
|
||||
4 => "t1.precio",
|
||||
5 => "t1.precio_adicional",
|
||||
5 => "t1.margen"
|
||||
4 => "t1.precio_min",
|
||||
5 => "t1.precio_max",
|
||||
6 => "t1.precio_adicional",
|
||||
7 => "t1.margen"
|
||||
];
|
||||
|
||||
protected $allowedFields = [
|
||||
@ -28,7 +29,8 @@ class TarifaEnvioPrecioModel extends \App\Models\GoBaseModel
|
||||
"tipo_envio",
|
||||
"peso_min",
|
||||
"peso_max",
|
||||
"precio",
|
||||
"precio_min",
|
||||
"precio_max",
|
||||
"precio_adicional",
|
||||
"margen",
|
||||
"deleted_at",
|
||||
@ -54,7 +56,11 @@ class TarifaEnvioPrecioModel extends \App\Models\GoBaseModel
|
||||
"label" => "TarifasEnviosPrecios.pesoMin",
|
||||
"rules" => "required|decimal",
|
||||
],
|
||||
"precio" => [
|
||||
"precio_min" => [
|
||||
"label" => "TarifasEnviosPrecios.precio",
|
||||
"rules" => "required|decimal",
|
||||
],
|
||||
"precio_max" => [
|
||||
"label" => "TarifasEnviosPrecios.precio",
|
||||
"rules" => "required|decimal",
|
||||
],
|
||||
@ -81,7 +87,11 @@ class TarifaEnvioPrecioModel extends \App\Models\GoBaseModel
|
||||
"decimal" => "TarifasEnviosPrecios.validation.peso_min.decimal",
|
||||
"required" => "TarifasEnviosPrecios.validation.peso_min.required",
|
||||
],
|
||||
"precio" => [
|
||||
"precio_min" => [
|
||||
"decimal" => "TarifasEnviosPrecios.validation.precio.decimal",
|
||||
"required" => "TarifasEnviosPrecios.validation.precio.required",
|
||||
],
|
||||
"precio_max" => [
|
||||
"decimal" => "TarifasEnviosPrecios.validation.precio.decimal",
|
||||
"required" => "TarifasEnviosPrecios.validation.precio.required",
|
||||
],
|
||||
@ -131,7 +141,7 @@ class TarifaEnvioPrecioModel extends \App\Models\GoBaseModel
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
->select(
|
||||
"t1.id AS id, t1.tipo_envio AS tipo_envio, t1.peso_min AS peso_min, t1.peso_max AS peso_max, t1.precio AS precio,
|
||||
"t1.id AS id, t1.tipo_envio AS tipo_envio, t1.peso_min AS peso_min, t1.peso_max AS peso_max, t1.precio_min AS precio_min, t1.precio_max AS precio_max,
|
||||
t1.precio_adicional AS precio_adicional, t1.margen AS margen, t2.id AS tarifa_envio, t3.id AS proveedor_id, t3.nombre AS proveedor"
|
||||
);
|
||||
$builder->join("tarifas_envios_zonas t2", "t1.tarifa_envio_id = t2.id", "left");
|
||||
@ -148,14 +158,16 @@ class TarifaEnvioPrecioModel extends \App\Models\GoBaseModel
|
||||
->like("t1.tipo_envio", $search)
|
||||
->orLike("t1.peso_min", $search)
|
||||
->orLike("t1.peso_max", $search)
|
||||
->orLike("t1.precio", $search)
|
||||
->orLike("t1.precio_min", $search)
|
||||
->orLike("t1.precio_max", $search)
|
||||
->orLike("t1.precio_adicional", $search)
|
||||
->orLike("t1.margen", $search)
|
||||
->orLike("t3.nombre", $search)
|
||||
->orLike("t1.tipo_envio", $search)
|
||||
->orLike("t1.peso_min", $search)
|
||||
->orLike("t1.peso_max", $search)
|
||||
->orLike("t1.precio", $search)
|
||||
->orLike("t1.precio_min", $search)
|
||||
->orLike("t1.precio_max", $search)
|
||||
->orLike("t1.precio_adicional", $search)
|
||||
->orLike("t1.margen", $search)
|
||||
->orLike("t3.nombre", $search)
|
||||
@ -207,4 +219,42 @@ class TarifaEnvioPrecioModel extends \App\Models\GoBaseModel
|
||||
|
||||
return $builder;
|
||||
}
|
||||
|
||||
public function getEnvioPrecio($tarifa_envio_id, $peso, $tipo_envio){
|
||||
// primero se checkea que el peso no sea mayor
|
||||
// que el valor mas grande
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
->selectMax('t1.peso_max')
|
||||
->where('t1.tipo_envio', $tipo_envio)
|
||||
->where("t1.tarifa_envio_id", $tarifa_envio_id)
|
||||
->where('t1.is_deleted', 0);
|
||||
$peso_maximo = $builder->get()->getResult();
|
||||
if(count($peso_maximo) > 0)
|
||||
$peso_maximo = floatval($peso_maximo[0]->peso_max);
|
||||
else // no hay resultados
|
||||
return [];
|
||||
|
||||
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
->select(
|
||||
"t1.id AS id, t1.tipo_envio AS tipo_envio, t1.peso_min AS peso_min, t1.peso_max AS peso_max, t1.precio_min AS precio_min, t1.precio_max AS precio_max,
|
||||
t1.precio_adicional AS precio_adicional, t1.margen AS margen, t2.id AS proveedor_id, t2.nombre AS proveedor"
|
||||
);
|
||||
$builder->join("lg_proveedores t2", "t1.proveedor_id = t2.id", "left");
|
||||
$builder->where("t1.tarifa_envio_id", $tarifa_envio_id);
|
||||
$builder->where("t1.tipo_envio", $tipo_envio);
|
||||
$builder->where('t1.is_deleted', 0);
|
||||
|
||||
if($peso_maximo<$peso){
|
||||
$builder->where('t1.peso_max', $peso_maximo);
|
||||
}
|
||||
else{
|
||||
$builder->where('t1.peso_min <=', $peso);
|
||||
$builder->where('t1.peso_max >=', $peso);
|
||||
}
|
||||
|
||||
return $builder->get()->getResultObject();
|
||||
}
|
||||
}
|
||||
|
||||
@ -423,8 +423,14 @@
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
data.lines.forEach((line) => {
|
||||
|
||||
$('#proveedor_enc_' + line[0].tarifa_id).off('change')
|
||||
$('#proveedor_enc_' + line[0].tarifa_id).val(line[0].proveedor_id)
|
||||
if(line[0].hasOwnProperty('proveedor_id'))
|
||||
$('#proveedor_enc_' + line[0].tarifa_id).val(line[0].proveedor_id)
|
||||
else{
|
||||
$('#proveedor_enc_' + line[0].tarifa_id).empty()
|
||||
.append('<option selected="selected" value="' + line[0].proveedor_id + '">' + '<?= lang("Presupuestos.no_disponible") ?>' + '</option>')
|
||||
}
|
||||
$('#precio_unidad_encuadernado_' + line[0].tarifa_id).text(parseFloat(line[0].precio_unidad).toFixed(2))
|
||||
$('#precio_total_encuadernado_' + line[0].tarifa_id).val(parseFloat(line[0].total).toFixed(2))
|
||||
$('#enc_margen_' + line[0].tarifa_id).val(parseFloat(line[0].margen).toFixed(2))
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
<div class="modal-dialog modal-lg modal-simple">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h4 id="labelTitleConfirmDialog" class="modal-title"><?= lang('PresupuestosDirecciones.nuevaTitle') ?></h4>
|
||||
<h4 id="labelTitleConfirmDialog" class="modal-title"><?= lang('PresupuestosDirecciones.direccionTitle') ?></h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
|
||||
@ -120,6 +120,13 @@
|
||||
|
||||
</div> <!-- //.row -->
|
||||
|
||||
<div class="col-md-12 col-lg-6 pl-4">
|
||||
<div class="form-check form-switch mb-2">
|
||||
<input class="form-check-input" type="checkbox" id="add_entregaPieCalle" name="add_entregaPieCalle" tabindex="10" value="1" >
|
||||
<label class="form-check-label" for="add_entregaPieCalle"><?= lang('PresupuestosDirecciones.entregaPieCalle') ?></label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-12 col-lg-6 pl-4">
|
||||
<div class="form-check form-switch mb-2">
|
||||
<input class="form-check-input" type="checkbox" id="add_saveDirection" name="add_saveDirection" tabindex="10" value="1" >
|
||||
@ -136,7 +143,7 @@
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button id="saveAdd"
|
||||
<button id="saveDireccionEnvio"
|
||||
type="button"
|
||||
class="btn btn-primary"
|
||||
>Guardar</button>
|
||||
@ -157,10 +164,56 @@ $('#cancelAdd').on('click', function(){
|
||||
})
|
||||
|
||||
|
||||
$('#saveAdd').on('click', function(){
|
||||
$('#saveDireccionEnvio').on('click', function(){
|
||||
|
||||
if(validate_fields()){
|
||||
|
||||
var peso_total_libro = 0
|
||||
|
||||
$('#tableLineasPresupuesto tbody tr:visible ').each(function(){
|
||||
peso_total_libro += parseFloat($('#' + this.id + '_peso').val())
|
||||
})
|
||||
const peso_envio = peso_total_libro*parseInt($('#add_cantidad').val())/1000.0
|
||||
|
||||
|
||||
$.post( '<?= route_to('dataTableOfPresupuestoDirecciones') ?>',
|
||||
{
|
||||
tipo: "get_tarifa",
|
||||
peso: peso_envio,
|
||||
paisId: $("#add_pais_id").val(),
|
||||
cp: $('#add_cp').val(),
|
||||
tipo_envio: $('#add_entregaPieCalle').is(":checked")?'palets':'cajas'
|
||||
})
|
||||
.done(function( data ) {
|
||||
|
||||
});
|
||||
|
||||
// Se guarda la dirección
|
||||
if($('#add_saveDirection').is(":checked")){
|
||||
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
function validate_fields(){
|
||||
|
||||
$( ".error-text-form" ).remove();
|
||||
|
||||
var returnValue = false
|
||||
|
||||
$("input.new-address").each( function() {
|
||||
if($('#' + this.id).val().length == 0 && $('#' + this.id).css('display') != 'none'){
|
||||
$('#' + this.id).after(
|
||||
"<p style='font-size: 11px !important;" +
|
||||
"padding: 0 !important; " +
|
||||
"color: #b11f1f !important;' " +
|
||||
"class='error-text-form'>" +'<?= lang('PresupuestosDirecciones.validation.required'); ?>' + '</p>')
|
||||
}
|
||||
returnValue = true
|
||||
})
|
||||
return returnValue
|
||||
}
|
||||
|
||||
|
||||
$('#add_saveDirection').change(function() {
|
||||
if(this.checked) {
|
||||
@ -273,6 +326,7 @@ $('#addressForm').on('hidden.bs.modal', function () {
|
||||
$('#add_email').val("")
|
||||
$('#add_direccion').val("")
|
||||
$("#add_pais_id").val("").change()
|
||||
$("#add_clientedAdd").val("").change()
|
||||
$("#add_ccaa").val("").change()
|
||||
$('#add_municipio').val("")
|
||||
$('#add_provincia').val("")
|
||||
|
||||
@ -62,7 +62,7 @@
|
||||
if(key == 13) // the enter key code
|
||||
{ e.preventDefault()
|
||||
if($('#addressForm').hasClass('show')){
|
||||
$("#saveAdd").click();
|
||||
$("#saveDireccionEnvio").click();
|
||||
|
||||
}else{
|
||||
$('#saveForm').click();
|
||||
|
||||
@ -80,7 +80,8 @@
|
||||
<th><?= lang('TarifasEnviosPrecios.tipoEnvio') ?></th>
|
||||
<th><?= lang('TarifasEnviosPrecios.pesoMin') ?></th>
|
||||
<th><?= lang('TarifasEnviosPrecios.pesoMax') ?></th>
|
||||
<th><?= lang('TarifasEnviosPrecios.precio') ?></th>
|
||||
<th><?= lang('TarifasEnviosPrecios.precio_min') ?></th>
|
||||
<th><?= lang('TarifasEnviosPrecios.precio_max') ?></th>
|
||||
<th><?= lang('TarifasEnviosPrecios.precioAdicional') ?></th>
|
||||
<th><?= lang('TarifasEnviosPrecios.margen') ?></th>
|
||||
<th style="min-width:100px"></th>
|
||||
@ -348,7 +349,9 @@ const lastColNr2 = $('#tableOfPrecios').find("tr:first th").length - 1;
|
||||
}, {
|
||||
name: "peso_max"
|
||||
}, {
|
||||
name: "precio"
|
||||
name: "precio_min"
|
||||
}, {
|
||||
name: "precio_max"
|
||||
}, {
|
||||
name: "precio_adicional",
|
||||
def: 0
|
||||
@ -453,7 +456,8 @@ const lastColNr2 = $('#tableOfPrecios').find("tr:first th").length - 1;
|
||||
},
|
||||
{ 'data': 'peso_min' },
|
||||
{ 'data': 'peso_max' },
|
||||
{ 'data': 'precio' },
|
||||
{ 'data': 'precio_min' },
|
||||
{ 'data': 'precio_max' },
|
||||
{ 'data': 'precio_adicional' },
|
||||
{ 'data': 'margen' },
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user