function openDepositModal(mode, workplaceId, currency, title, valueLocalization, apiUrl, errorTitle, locOk, locCancel, onSuccess) {
    $().customModal({
        id: "deposit-modal",
        destroyOnClose: true,
        title: title,
        showCloseButton: true,
        type: "modal",
        minHeight: "220px",
        maxWidth: "400px",
        content: "<div class=' m-t-md'><label class='col-xs-3 label-level'>" + valueLocalization + "</label><div class='col-xs-9'><div class='input-group'><input class='form-control numberInput text-right' id='deposit-input' value='0,00' autocomplete='off' /><span class='input-group-addon'>" + currency + "</span></div></div></div>",
        buttons: [
            {
                icon: 'fa fa-times',
                text: !locCancel ? $("#CancelLoc").val() : locCancel,
                closeOnAction: true,
                type: 'ghost'
            },
            {
                icon: 'fa fa-check',
                text: !locOk ? $("#LocOk").val() : locOk,
                closeOnAction: false,
                type: 'primary',
                action: async function () {
                    $("#deposit-modal .custom-modal-body #deposit-input").removeClass("text-danger");
                    $("#deposit-modal .custom-modal-body #deposit-input").parent().removeClass("has-error");

                    let value = toNumber($("#deposit-modal .custom-modal-body #deposit-input").val());
                    if (mode && mode.trim() === 'I' && value < 0) {
                        $("#deposit-modal .custom-modal-body #deposit-input").addClass("text-danger");
                        $("#deposit-modal .custom-modal-body #deposit-input").parent().addClass("has-error");
                        return;
                    }

                    await registerDeposit(mode, value, workplaceId, apiUrl, errorTitle, onSuccess);
                    $("#deposit-modal").customModal("close");
                }
            }
        ]
    });
}

async function registerDeposit(mode, depositValue, workplaceId, url, errorTitle, onSuccess) {
    if (mode && mode.trim() === 'W' && depositValue > 0)
        depositValue = depositValue * -1;

    await $.ajax({
        method: "POST",
        url: url,
        data: { workPlaceId: workplaceId, amount: formatDisplay(2, depositValue, true) },
        success: function (data) {
            if (!data || !data.IsSuccessful) {
                showErrorModal(errorTitle, data.Errors + ".");
            }
            else {
                onSuccess();
            }
        },
        error: function () {
            showErrorModal(errorTitle, $("#LocGeneralError").val() + ".");
        }
    });
}

function showErrorModal(title, text) {
    $().customModal({
        destroyOnClose: true,
        title: title,
        showCloseButton: true,
        type: "error",
        text: text,
        buttons: [
            {
                icon: 'fa fa-check',
                text: $("#LocOk").val() ? $("#LocOk").val() : "Ok",
                closeOnAction: true,
                type: 'primary'
            }
        ]
    });
}