HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/vhost/disk-apps/demo.sports-crowd.com/public/js/inventory_tweaks.js
function create() {
    $("#form_create").validator("update");
    $("#form_create")
        .validator("update")
        .on("submit", function (e) {
            if (e.isDefaultPrevented()) {
            } else {
                e.preventDefault();

                let product_id = $("#form_create select[name='product_id']").val();
                let attribute_select = $("#form_create select[name='product_attribute_id'] option");
                let inventory_movement_type_id = $("#inventory_movement_type_id").val();

                inventory_movement_type_id = parseInt(
                    inventory_movement_type_id
                );

                // Validar que se indique un producto
                if (!product_id) {
                    swal("Error", Lang.get("messagesClient.inventory_tweaks.error_product"), "error");
                    return;
                }

                if (!inventory_movement_type_id) {
                    swal("Error", Lang.get("messagesClient.inventory_tweaks.error_inventory_type_id"), "error");
                    return;
                }

                // Validar que en caso de poderse, se indique un atributo.
                if (attribute_select.length > 0) {
                    if (!$(" #form_create select[name='product_attribute_id']").val()) {
                        swal("Error", Lang.get("messagesClient.inventory_tweaks.error_product_attribute"), "error");
                        return;
                    }
                }

                $("#btn-create").addClass("displayNone");
                $("#spinnerButton").removeClass("displayNone");

                var info = {
                    product_id,
                    product_attribute_id: $(" #form_create select[name='product_attribute_id']").val(),
                    quantity: $("#form_create input[name='quantity']").val(),
                    description: $("#form_create input[name='description']").val(),
                    product_attribute_value: $("#product_attribute_id").find(":selected").data("value"),
                    product_attribute_sku: $("#product_attribute_id").find(":selected").data("sku"),
                    product_attribute_real_id: $("#product_attribute_id").find(":selected").data("product-attribute-id"),
                    inventory_movement_type_id,
                    store_type: localStorage.getItem("storeType")
                };

                swal(Lang.get("messagesClient.inventory_tweaks.create"), {
                    buttons: {
                        cancel: "No",
                        Ok: true,
                    },
                }).then((val) => {
                    if (val == "Ok") {
                        $.ajax({
                            url: "/inventory_tweaks",
                            type: "POST",
                            contentType: "application/json",
                            headers: {
                                "X-CSRF-TOKEN": $(
                                    'meta[name="csrf-token"]'
                                ).attr("content"),
                                "Content-Type": "application/json",
                            },
                            data: JSON.stringify(info),
                            success: function (r) {
                                if (r.r) {
                                    if (r.type == "error") {
                                        swal("Advertencia", "No se puede modificar esa cantidad", "warning");
                                        $("#btn-create").removeClass("displayNone");
                                        $("#spinnerButton").addClass("displayNone");
                                        return;
                                    } else {
                                        swal(r.m, {
                                            icon: "success",
                                            buttons: {
                                                Ok: true,
                                            },
                                        }).then((val) => {
                                            if (val == "Ok") {
                                                $(location).attr(
                                                    "href",
                                                    "/inventory_tweaks/" + localStorage.getItem("storeType")
                                                );
                                            }
                                        });
                                    }
                                } else {
                                    swal("Error", r.m, "error");
                                    $("#btn-create").removeClass("displayNone");
                                    $("#spinnerButton").addClass("displayNone");
                                }
                            },
                            error: function (e) {
                                swal("Error", "¡Hubo un Error al crear!", "error");
                                $("#btn-create").removeClass("displayNone");
                                $("#spinnerButton").addClass("displayNone");
                            },
                        });
                    } else {
                        $("#btn-create").removeClass("displayNone");
                        $("#spinnerButton").addClass("displayNone");
                    }
                });
            }
        });
}

function findAttributes() {
    var product_id = $("#product_id").val();

    // Elimino atributos anteriores.
    var selectProductAttributes = $("#product_attribute_id");
    selectProductAttributes.empty();

    $.ajax({
        url: "/inventory_tweaks/attributes_product/" + product_id,
        type: "GET",
        contentType: "application/json",
        headers: {
            "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
            "Content-Type": "application/json",
        },
        success: function (r) {
            if (r.length > 0) {
                for (var i = 0; i < r.length; i++) {
                    selectProductAttributes.append(
                        `<option value="${r[i].attribute.id}" data-value="${r[i].value}" data-sku="${r[i].sku}"  data-product-attribute-id="${r[i].id}">${r[i].sku} - ${r[i].attribute.name} - ${r[i].value}</option>`
                    );
                }
            } else {
                selectProductAttributes.empty();
            }
        },
    });
}