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) {
$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);
if ($status) {
$imposicionEntity = $this->model->find($imposicion_id);
@ -148,6 +153,7 @@ class Imposiciones extends BaseController
{
$q = $this->model->queryDatatable();
return DataTable::of($q)
->add('esquema', fn($q) => ["imposicionId" => $q->id,"esquemaId" => $q->esquemaId, "esquemaName" => $q->esquemaName])
->add(
'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>"

View File

@ -15,9 +15,10 @@ class AddFkEsquemaImposiciones extends Migration
"imposicion_esquema_id" => [
"type" => "INT",
"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");
}

View File

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

View File

@ -143,14 +143,18 @@ class ImposicionModel extends BaseModel
{
return $this->builder()
->select([
"id",
"ancho",
"alto",
"unidades",
"maquina",
"orientacion",
"etiqueta"
])->where('deleted_at', null);
"lg_imposiciones.id",
"lg_imposiciones.ancho",
"lg_imposiciones.alto",
"lg_imposiciones.unidades",
"lg_imposiciones.maquina",
"lg_imposiciones.orientacion",
"lg_imposiciones.etiqueta",
"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)
{

View File

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

View File

@ -1,3 +1,6 @@
import ClassSelect from "../select2.js";
import Ajax from "../ajax.js";
class ImposicionDatatable {
constructor(domItem) {
@ -10,6 +13,7 @@ class ImposicionDatatable {
{ data: 'orientacion', searchable: true, sortable: true },
{ data: 'maquina', 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 },
]
this.datatableEsquemaColumns = [
@ -27,7 +31,7 @@ class ImposicionDatatable {
bottomEnd: 'paging'
},
columnDefs: [
{ className: 'dt-center', targets: '_all' },
{ className: 'dt-center', targets: [0, 1, 2, 3, 4, 5, 6] },
],
serverSide: true,
pageLength: 25,
@ -36,30 +40,44 @@ class ImposicionDatatable {
},
columns: this.datatableColumns,
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 {
constructor(domItem) {
this.item = domItem
if ($("#imposicion-esquema-drawing").length > 0) {
this.drawing = new ImposicionEsquemaDrawing($("#imposicion-esquema-drawing"))
} else {
this.drawing = null
}
this.modelId = this.item.data("id");
this.btnSubmitUpdateImposicion = this.item.find("#btnSubmitUpdateImposicionEsquema")
this.btnSubmitNewImposicion = this.item.find("#btnSubmitNewImposicionEsquema")
@ -29,6 +34,8 @@ class ImposicionEsquemaForm {
}
init() {
if (this.drawing) {
this.drawing.setOrientation($("#esquema-orientacion").val())
this.item.on("change", "#esquema-rows", (event) => {
let rows = $(event.currentTarget).val()
this.drawing.setRows(rows)
@ -56,6 +63,7 @@ class ImposicionEsquemaForm {
this.initNew()
}
}
}
initNew() {
this.btnSubmitUpdateImposicion.on("click", this.handleNew.bind(this))
}
@ -156,6 +164,7 @@ class ImposicionEsquemaForm {
this.disable()
this.item.find(".invalid-feedback").remove()
this.btnSubmitNewImposicion.addClass("d-none")
this.btnSubmitUpdateImposicion.addClass("d-none")
popSuccessAlert(response.message)
}
postErrorNew(error) {

View File

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

View File

@ -20,6 +20,9 @@ class Imposicion {
this.imposicionEsquemaDatatable.init()
this.itemTable.on("click", ".imposicion-delete", this.deleteRow.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() {
@ -47,7 +50,7 @@ class Imposicion {
alertConfirmationDelete().then((result) => {
if (result.isConfirmed) {
this.imposicionEsquemaForm.handleDelete(modelId)
this.imposicionEsquemaDatatable.datatableEsquema.ajax.reload()
this.imposicionEsquemaDatatable.datatable.ajax.reload()
}
})
}