add select imposicion datatable

This commit is contained in:
amazuecos
2025-04-21 08:32:21 +02:00
parent b318721b90
commit 969966ac78
9 changed files with 127 additions and 74 deletions

View File

@ -106,6 +106,11 @@ class Imposiciones extends BaseController
{ {
if ($imposicion_id) { if ($imposicion_id) {
$bodyData = $this->request->getPost(); $bodyData = $this->request->getPost();
if(isset($bodyData["imposicion_esquema_id"])){
if($bodyData["imposicion_esquema_id"] == ""){
$bodyData["imposicion_esquema_id"] = null;
}
}
$status = $this->model->update($imposicion_id, $bodyData); $status = $this->model->update($imposicion_id, $bodyData);
if ($status) { if ($status) {
$imposicionEntity = $this->model->find($imposicion_id); $imposicionEntity = $this->model->find($imposicion_id);
@ -148,6 +153,7 @@ class Imposiciones extends BaseController
{ {
$q = $this->model->queryDatatable(); $q = $this->model->queryDatatable();
return DataTable::of($q) return DataTable::of($q)
->add('esquema', fn($q) => ["imposicionId" => $q->id,"esquemaId" => $q->esquemaId, "esquemaName" => $q->esquemaName])
->add( ->add(
'action', 'action',
fn($q) => "<div class='btn-group btn-group-md gap-2 w-100 d-flex justify-space-between'>" . ImposicionModel::datatable_buttons($q->id) . "</div>" fn($q) => "<div class='btn-group btn-group-md gap-2 w-100 d-flex justify-space-between'>" . ImposicionModel::datatable_buttons($q->id) . "</div>"

View File

@ -15,9 +15,10 @@ class AddFkEsquemaImposiciones extends Migration
"imposicion_esquema_id" => [ "imposicion_esquema_id" => [
"type" => "INT", "type" => "INT",
"unsigned" => true, "unsigned" => true,
"null" => true
] ]
]); ]);
$this->forge->addForeignKey(["imposicion_esquema_id"],"imposicion_esquemas",["id"]); $this->forge->addForeignKey(["imposicion_esquema_id"],"imposicion_esquemas",["id"],'SET NULL','SET NULL');
$this->forge->processIndexes("lg_imposiciones"); $this->forge->processIndexes("lg_imposiciones");
} }

View File

@ -93,7 +93,7 @@ class ImposicionEsquemaModel extends Model
"id", "id",
"name", "name",
"svg_schema as description" "svg_schema as description"
]); ])->where('deleted_at', null);
if ($q) { if ($q) {
$query->orLike("name", $q); $query->orLike("name", $q);
} }

View File

@ -143,14 +143,18 @@ class ImposicionModel extends BaseModel
{ {
return $this->builder() return $this->builder()
->select([ ->select([
"id", "lg_imposiciones.id",
"ancho", "lg_imposiciones.ancho",
"alto", "lg_imposiciones.alto",
"unidades", "lg_imposiciones.unidades",
"maquina", "lg_imposiciones.maquina",
"orientacion", "lg_imposiciones.orientacion",
"etiqueta" "lg_imposiciones.etiqueta",
])->where('deleted_at', null); "imposicion_esquemas.id as esquemaId",
"imposicion_esquemas.name as esquemaName"
])
->join("imposicion_esquemas","imposicion_esquemas.id = lg_imposiciones.imposicion_esquema_id","left")
->where('lg_imposiciones.deleted_at', null);
} }
public static function datatable_buttons(int $id) public static function datatable_buttons(int $id)
{ {

View File

@ -1,4 +1,5 @@
<?= $this->include('themes/_commonPartialsBs/datatables') ?> <?= $this->include('themes/_commonPartialsBs/datatables') ?>
<?= $this->include("themes/_commonPartialsBs/select2bs5") ?>
<?= $this->include('themes/_commonPartialsBs/sweetalert') ?> <?= $this->include('themes/_commonPartialsBs/sweetalert') ?>
<?= $this->extend('themes/vuexy/main/defaultlayout') ?> <?= $this->extend('themes/vuexy/main/defaultlayout') ?>
<?= $this->section('content'); ?> <?= $this->section('content'); ?>
@ -31,6 +32,7 @@
<th><?= lang('Imposiciones.orientacion') ?></th> <th><?= lang('Imposiciones.orientacion') ?></th>
<th><?= lang('Imposiciones.maquina') ?></th> <th><?= lang('Imposiciones.maquina') ?></th>
<th><?= lang('Imposiciones.etiqueta') ?></th> <th><?= lang('Imposiciones.etiqueta') ?></th>
<th><?= lang('Imposiciones.imposicion_esquema') ?></th>
<th class="text-nowrap"><?= lang('Basic.global.Action') ?></th> <th class="text-nowrap"><?= lang('Basic.global.Action') ?></th>
</tr> </tr>
</thead> </thead>

View File

@ -1,3 +1,6 @@
import ClassSelect from "../select2.js";
import Ajax from "../ajax.js";
class ImposicionDatatable { class ImposicionDatatable {
constructor(domItem) { constructor(domItem) {
@ -10,6 +13,7 @@ class ImposicionDatatable {
{ data: 'orientacion', searchable: true, sortable: true }, { data: 'orientacion', searchable: true, sortable: true },
{ data: 'maquina', searchable: true, sortable: true }, { data: 'maquina', searchable: true, sortable: true },
{ data: 'etiqueta', searchable: true, sortable: true }, { data: 'etiqueta', searchable: true, sortable: true },
{ data: 'esquema', searchable: true, sortable: true, render: this.renderImposicionEsquemaCell.bind(this) },
{ data: 'action', searchable: true, sortable: true }, { data: 'action', searchable: true, sortable: true },
] ]
this.datatableEsquemaColumns = [ this.datatableEsquemaColumns = [
@ -27,7 +31,7 @@ class ImposicionDatatable {
bottomEnd: 'paging' bottomEnd: 'paging'
}, },
columnDefs: [ columnDefs: [
{ className: 'dt-center', targets: '_all' }, { className: 'dt-center', targets: [0, 1, 2, 3, 4, 5, 6] },
], ],
serverSide: true, serverSide: true,
pageLength: 25, pageLength: 25,
@ -36,30 +40,44 @@ class ImposicionDatatable {
}, },
columns: this.datatableColumns, columns: this.datatableColumns,
ajax: '/imposiciones/datatable', ajax: '/imposiciones/datatable',
}); createdRow: (row, data, dataIndex) => {
this.createSelectImposicion(row, data)
} }
initEsquema() {
this.datatableEsquema = this.item.DataTable({
processing: true,
layout: {
topStart: 'pageLength',
topEnd: 'search',
bottomStart: 'info',
bottomEnd: 'paging'
},
columnDefs: [
{ className: 'dt-center', targets: '_all' },
],
serverSide: true,
pageLength: 25,
language: {
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
},
columns: this.datatableEsquemaColumns,
ajax: '/imposiciones/esquema/datatable',
}); });
// this.datatable.on("draw.dt", this.createSelectImposicion.bind(this))
this.item.on("change", ".imposicion-esquema-select", this.handleChangeImposicionEsquema.bind(this))
} }
renderImposicionEsquemaCell(d, t) {
return `<select name="imposicion_esquema_id" data-id="${d.imposicionId}" class="select2 form-control imposicion-esquema-select" data-input>
</select>`
}
createSelectImposicion(row, data) {
let selectEsquema = new ClassSelect($(row).find(".imposicion-esquema-select"), '/imposiciones/esquema/select', 'Seleccione un esquema', true)
selectEsquema.init()
if (data.esquema.esquemaId) {
selectEsquema.setOption(data.esquema.esquemaId, data.esquema.esquemaName)
}
}
handleChangeImposicionEsquema(event) {
let imposicionId = $(event.currentTarget).data("id")
let ajax = new Ajax(`/imposiciones/${imposicionId}`,
{
"imposicion_esquema_id": $(event.currentTarget).val(),
},
null,
this.handleChangeImposicionEsquemaSuccess.bind(this),
this.handleChangeImposicionEsquemaError.bind(this))
if (imposicionId) {
ajax.post()
}
}
handleChangeImposicionEsquemaSuccess(response) {
popSuccessAlert(response.message)
}
handleChangeImposicionEsquemaError() { }
} }

View File

@ -4,7 +4,12 @@ import ImposicionEsquemaDrawing from '../imposicionEsquemaDrawing.js';
class ImposicionEsquemaForm { class ImposicionEsquemaForm {
constructor(domItem) { constructor(domItem) {
this.item = domItem this.item = domItem
if ($("#imposicion-esquema-drawing").length > 0) {
this.drawing = new ImposicionEsquemaDrawing($("#imposicion-esquema-drawing")) this.drawing = new ImposicionEsquemaDrawing($("#imposicion-esquema-drawing"))
} else {
this.drawing = null
}
this.modelId = this.item.data("id"); this.modelId = this.item.data("id");
this.btnSubmitUpdateImposicion = this.item.find("#btnSubmitUpdateImposicionEsquema") this.btnSubmitUpdateImposicion = this.item.find("#btnSubmitUpdateImposicionEsquema")
this.btnSubmitNewImposicion = this.item.find("#btnSubmitNewImposicionEsquema") this.btnSubmitNewImposicion = this.item.find("#btnSubmitNewImposicionEsquema")
@ -29,6 +34,8 @@ class ImposicionEsquemaForm {
} }
init() { init() {
if (this.drawing) {
this.drawing.setOrientation($("#esquema-orientacion").val())
this.item.on("change", "#esquema-rows", (event) => { this.item.on("change", "#esquema-rows", (event) => {
let rows = $(event.currentTarget).val() let rows = $(event.currentTarget).val()
this.drawing.setRows(rows) this.drawing.setRows(rows)
@ -56,6 +63,7 @@ class ImposicionEsquemaForm {
this.initNew() this.initNew()
} }
} }
}
initNew() { initNew() {
this.btnSubmitUpdateImposicion.on("click", this.handleNew.bind(this)) this.btnSubmitUpdateImposicion.on("click", this.handleNew.bind(this))
} }
@ -156,6 +164,7 @@ class ImposicionEsquemaForm {
this.disable() this.disable()
this.item.find(".invalid-feedback").remove() this.item.find(".invalid-feedback").remove()
this.btnSubmitNewImposicion.addClass("d-none") this.btnSubmitNewImposicion.addClass("d-none")
this.btnSubmitUpdateImposicion.addClass("d-none")
popSuccessAlert(response.message) popSuccessAlert(response.message)
} }
postErrorNew(error) { postErrorNew(error) {

View File

@ -14,7 +14,11 @@ class ImposicionEsquemaDrawing {
this.offsetY = this.rectangleDimensions.height + 20 this.offsetY = this.rectangleDimensions.height + 20
this.offsetCosidoX = this.rectangleCosidoDimensions.width + 20 this.offsetCosidoX = this.rectangleCosidoDimensions.width + 20
this.offsetCosidoY = this.rectangleCosidoDimensions.height + 20 this.offsetCosidoY = this.rectangleCosidoDimensions.height + 20
this.dw = null
if (this.item.length > 0) {
this.dw = new Two(this.params).appendTo(this.item[0]) this.dw = new Two(this.params).appendTo(this.item[0])
}
this.rows = 1 this.rows = 1
this.columns = 1 this.columns = 1
this.rotativa = false this.rotativa = false
@ -141,6 +145,7 @@ class ImposicionEsquemaDrawing {
this.vectorShapes.push(vector) this.vectorShapes.push(vector)
} }
drawSchema() { drawSchema() {
this.remove(); this.remove();
for (let index = 0; index < this.rows; index++) { for (let index = 0; index < this.rows; index++) {
if (this.cosido) { if (this.cosido) {
@ -157,7 +162,12 @@ class ImposicionEsquemaDrawing {
this.dw.update() this.dw.update()
} }
getSVG() { getSVG() {
if (this.dw) {
return this.dw.renderer.domElement.outerHTML return this.dw.renderer.domElement.outerHTML
} else {
return null
}
} }
} }

View File

@ -20,6 +20,9 @@ class Imposicion {
this.imposicionEsquemaDatatable.init() this.imposicionEsquemaDatatable.init()
this.itemTable.on("click", ".imposicion-delete", this.deleteRow.bind(this)) this.itemTable.on("click", ".imposicion-delete", this.deleteRow.bind(this))
this.itemEsquemaTable.on("click", ".imposicion-esquema-delete", this.deleteEsquemaRow.bind(this)) this.itemEsquemaTable.on("click", ".imposicion-esquema-delete", this.deleteEsquemaRow.bind(this))
this.imposicionEsquemaForm = new ImposicionEsquemaForm(this.itemEsquemaForm)
this.imposicionForm = new ImposicionForm(this.itemForm)
} }
edit() { edit() {
@ -47,7 +50,7 @@ class Imposicion {
alertConfirmationDelete().then((result) => { alertConfirmationDelete().then((result) => {
if (result.isConfirmed) { if (result.isConfirmed) {
this.imposicionEsquemaForm.handleDelete(modelId) this.imposicionEsquemaForm.handleDelete(modelId)
this.imposicionEsquemaDatatable.datatableEsquema.ajax.reload() this.imposicionEsquemaDatatable.datatable.ajax.reload()
} }
}) })
} }