mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
añadida la funcionalidad de borrar en cascada las tarifas envio. Corregido error en editor (campo nombre)
This commit is contained in:
@ -12,6 +12,8 @@ use App\Models\Compras\ProveedorModel;
|
|||||||
use App\Models\Compras\ProveedorTipoModel;
|
use App\Models\Compras\ProveedorTipoModel;
|
||||||
|
|
||||||
use App\Models\Tarifas\TarifaEnvioModel;
|
use App\Models\Tarifas\TarifaEnvioModel;
|
||||||
|
use App\Models\Tarifas\TarifaEnvioPrecioModel;
|
||||||
|
use App\Models\Tarifas\TarifaEnvioZonaModel;
|
||||||
|
|
||||||
class Tarifasenvios extends \App\Controllers\GoBaseResourceController {
|
class Tarifasenvios extends \App\Controllers\GoBaseResourceController {
|
||||||
|
|
||||||
@ -226,6 +228,48 @@ class Tarifasenvios extends \App\Controllers\GoBaseResourceController {
|
|||||||
} // end function edit(...)
|
} // end function edit(...)
|
||||||
|
|
||||||
|
|
||||||
|
// JJO
|
||||||
|
public function delete($id = null)
|
||||||
|
{
|
||||||
|
if (!empty(static::$pluralObjectNameCc) && !empty(static::$singularObjectNameCc)) {
|
||||||
|
$objName = mb_strtolower(lang(ucfirst(static::$pluralObjectNameCc).'.'.static::$singularObjectNameCc));
|
||||||
|
} else {
|
||||||
|
$objName = lang('Basic.global.record');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->soft_delete){
|
||||||
|
|
||||||
|
if (!$this->model->delete($id)) {
|
||||||
|
return $this->failNotFound(lang('Basic.global.deleteError', [$objName]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$datetime = (new \CodeIgniter\I18n\Time("now"));
|
||||||
|
|
||||||
|
|
||||||
|
$zonaModel = new TarifaEnvioZonaModel();
|
||||||
|
$zonaResult = $zonaModel->removeAllZonasLineas($id, $datetime, $this->delete_flag);
|
||||||
|
|
||||||
|
$precioModel = new TarifaEnvioPrecioModel();
|
||||||
|
$precioResult = $precioModel->removeAllPrecioLineas($id, $datetime, $this->delete_flag);
|
||||||
|
|
||||||
|
$rawResult = $this->model->where('id',$id)
|
||||||
|
->set(['deleted_at' => $datetime->format('Y-m-d H:i:s'),
|
||||||
|
'is_deleted' => $this->delete_flag])
|
||||||
|
->update();
|
||||||
|
|
||||||
|
if (!$rawResult && !$precioResult && !$zonaResult) {
|
||||||
|
return $this->failNotFound(lang('Basic.global.deleteError', [$objName]));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// $message = lang('Basic.global.deleteSuccess', [$objName]); IMN commented
|
||||||
|
$message = lang('Basic.global.deleteSuccess', [lang('Basic.global.record')]);
|
||||||
|
$response = $this->respondDeleted(['id' => $id, 'msg' => $message]);
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function datatable() {
|
public function datatable() {
|
||||||
if ($this->request->isAJAX()) {
|
if ($this->request->isAJAX()) {
|
||||||
|
|||||||
@ -209,43 +209,6 @@ class Tarifasenvioszonas extends \App\Controllers\GoBaseResourceController {
|
|||||||
} // end function edit(...)
|
} // end function edit(...)
|
||||||
|
|
||||||
|
|
||||||
public function delete($id = null)
|
|
||||||
{
|
|
||||||
if (!empty(static::$pluralObjectNameCc) && !empty(static::$singularObjectNameCc)) {
|
|
||||||
$objName = mb_strtolower(lang(ucfirst(static::$pluralObjectNameCc).'.'.static::$singularObjectNameCc));
|
|
||||||
} else {
|
|
||||||
$objName = lang('Basic.global.record');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$this->soft_delete){
|
|
||||||
|
|
||||||
if (!$this->model->delete($id)) {
|
|
||||||
return $this->failNotFound(lang('Basic.global.deleteError', [$objName]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
$datetime = (new \CodeIgniter\I18n\Time("now"));
|
|
||||||
|
|
||||||
$precioModel = new TarifaEnvioPrecioModel();
|
|
||||||
$precioResult = $precioModel->removeAllPrecioLineas($id, $datetime, $this->delete_flag);
|
|
||||||
|
|
||||||
$rawResult = $this->model->where('id',$id)
|
|
||||||
->set(['deleted_at' => $datetime->format('Y-m-d H:i:s'),
|
|
||||||
'is_deleted' => $this->delete_flag])
|
|
||||||
->update();
|
|
||||||
|
|
||||||
if (!$rawResult && !$precioResult) {
|
|
||||||
return $this->failNotFound(lang('Basic.global.deleteError', [$objName]));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// $message = lang('Basic.global.deleteSuccess', [$objName]); IMN commented
|
|
||||||
$message = lang('Basic.global.deleteSuccess', [lang('Basic.global.record')]);
|
|
||||||
$response = $this->respondDeleted(['id' => $id, 'msg' => $message]);
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function datatable_editor()
|
public function datatable_editor()
|
||||||
{
|
{
|
||||||
if ($this->request->isAJAX()) {
|
if ($this->request->isAJAX()) {
|
||||||
@ -255,6 +218,13 @@ class Tarifasenvioszonas extends \App\Controllers\GoBaseResourceController {
|
|||||||
// Build our Editor instance and process the data coming from _POST
|
// Build our Editor instance and process the data coming from _POST
|
||||||
$response = Editor::inst($db, 'tarifas_envios_zonas')
|
$response = Editor::inst($db, 'tarifas_envios_zonas')
|
||||||
->fields(
|
->fields(
|
||||||
|
Field::inst('nombre')
|
||||||
|
->validator('Validate::required', array(
|
||||||
|
'message' => lang('TarifasEnviosZonas.validation.nombre.required'))
|
||||||
|
)
|
||||||
|
->validator(Validate::maxLen(50), array(
|
||||||
|
'message' => lang('TarifasEnviosZonas.validation.nombre.max_length'))
|
||||||
|
),
|
||||||
Field::inst('cp_inicial')
|
Field::inst('cp_inicial')
|
||||||
->validator('Validate::required', array(
|
->validator('Validate::required', array(
|
||||||
'message' => lang('TarifasEnviosZonas.validation.cp_inicial.required'))
|
'message' => lang('TarifasEnviosZonas.validation.cp_inicial.required'))
|
||||||
|
|||||||
@ -196,13 +196,13 @@ class TarifaEnvioPrecioModel extends \App\Models\GoBaseModel
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeAllPrecioLineas($zona_id = -1, $datetime = null, $delete_flag=1){
|
public function removeAllPrecioLineas($tarifa_envio_id = -1, $datetime = null, $delete_flag=1){
|
||||||
|
|
||||||
$builder = $this->db
|
$builder = $this->db
|
||||||
->table($this->table)
|
->table($this->table)
|
||||||
->set(['deleted_at' => $datetime->format('Y-m-d H:i:s'),
|
->set(['deleted_at' => $datetime->format('Y-m-d H:i:s'),
|
||||||
'is_deleted' => $delete_flag])
|
'is_deleted' => $delete_flag])
|
||||||
->where('tarifa_envio_id',$zona_id)
|
->where('tarifa_envio_id',$tarifa_envio_id)
|
||||||
->update();
|
->update();
|
||||||
|
|
||||||
return $builder;
|
return $builder;
|
||||||
|
|||||||
@ -125,4 +125,16 @@ class TarifaEnvioZonaModel extends \App\Models\GoBaseModel
|
|||||||
->orLike("t1.importe_fijo", $search)
|
->orLike("t1.importe_fijo", $search)
|
||||||
->groupEnd();
|
->groupEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function removeAllZonasLineas($tarifa_envio_id = -1, $datetime = null, $delete_flag=1){
|
||||||
|
|
||||||
|
$builder = $this->db
|
||||||
|
->table($this->table)
|
||||||
|
->set(['deleted_at' => $datetime->format('Y-m-d H:i:s'),
|
||||||
|
'is_deleted' => $delete_flag])
|
||||||
|
->where('tarifa_envio_id',$tarifa_envio_id)
|
||||||
|
->update();
|
||||||
|
|
||||||
|
return $builder;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user