Sh3ll
OdayForums


Server : Apache
System : Linux 145.162.205.92.host.secureserver.net 5.14.0-611.45.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Apr 1 05:56:53 EDT 2026 x86_64
User : tradze ( 1001)
PHP Version : 8.1.34
Disable Function : NONE
Directory :  /home/tradze/public_html/public/themes/admin/assets/admin/invoices/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/tradze/public_html/public/themes/admin/assets/admin/invoices/invoice.js
/**
 * Created by Concept24Online
 */

var Invoices = function () {

    var CSRF_TOKEN = $('input[name="_token"]').val();

    var handleFormElements = function(){
        if ($('.select2').length>0)
            $('.select2').select2();

        if ($('.select2filter').length>0)
            $(".select2filter").select2({
                placeholder: 'Status'
            });

        $('.date-picker').datepicker({
            orientation: "left",
            autoclose: true,
            format: 'dd-mm-yyyy',
        });

        if ($('.wysihtml5').size() > 0) {
            $('.wysihtml5').wysihtml5({
                "stylesheets": ["../../assets/global/plugins/bootstrap-wysihtml5/wysiwyg-color.css"]
            });
        }
    };

    var handleInvoice = function(){

        var $invoice_date = $("#invoice_date");
        var $invoice_duedate = $("#invoice_duedate");
        var $tax = $("#tax");
        var cart_message = $("#cart_message");
        var new_item = $("#new_item");

        //hide cart_message element
        // cart_message.hide();
        // cart_message.text('');
        //end search product

        //add new item
        $('#add_item').click(function(){

            var $item = $("#new_item");
            $item.closest('.row').removeClass('alert-danger').removeClass('alert-success').removeClass('alert');

            if ($item.val()==0){
                $item.closest('.row').addClass('alert alert-danger');
                return;
            }

            $.ajax({
                url: "cart/add",
                type: 'post',
                dataType: 'json',
                data: {_token: CSRF_TOKEN,'newitem':$item.val(),'tax_id':$tax.val()},
                beforeSend: function() {

                },
                complete: function() {},
                error: function(data) {
                    var response = jQuery.parseJSON(data.responseText);
                    cart_message.text('');

                    $.each(response,function(index,value){
                        cart_message.append("<div>"+value+"</div>");
                    });
                    $("#cart_message").show();
                },
                success: function(data) {
                    display_cart();
                    $("#new_item").val('');
                }
            });
        });
        //end add new item

        //update item
        $(document).on('blur', '.item_update',function(event){
            var $item = $(this);
            var $item_id = $item.attr('id');

            if ($item_id==0){
                return;
            }

            $update=1;
            if ($item.attr('name').indexOf('description') >-1 || $item.attr('name').indexOf('um')>-1 || $item.attr('name').indexOf('name')>-1)
                $update=0;

            update_cart_pos($item_id,$update);

        });

        $(document).on('paste', '.item_update', function(e)
        {
            var $item = $(this);
            var $item_id = $item.attr('id');

            if ($item_id==0){
                return;
            }

            $update=1;
            if ($item.attr('name').indexOf('description') >-1 || $item.attr('name').indexOf('um')>-1 || $item.attr('name').indexOf('name')>-1)
                $update=0;

            $item.text($(e.currentTarget).val());
            update_cart_pos($item_id,$update);
        });
        //end update item

        /**
         * Update cart data for each item
         * @param $item_id
         */
        function update_cart_pos($item_id,$update)
        {
            var name = $("#item_"+$item_id).find('input[name="name"]').val();
            var desc = $("#item_"+$item_id).find('input[name="description"]').val();
            var um = $("#item_"+$item_id).find('input[name="um"]').val();
            var qty = $("#item_"+$item_id).find('input[name="quantity"]').val();
            var price = $("#item_"+$item_id).find('input[name="price"]').val();
            
            $.ajax({
                url: "cart/edit",
                type: 'post',
                dataType: 'json',
                data: {
                    _token: CSRF_TOKEN,
                    'id':$item_id,
                    'name':name,
                    'desc':desc,
                    'um':um,
                    'price':price,
                    'quantity':qty,
                },
                beforeSend: function() {

                },
                complete: function() {},
                success: function(data) {
                    if ($update==1)
                        display_cart();
                }
            });
        }
        //end method update cart position

        /**
         * Update cart items with exchange rate
         * @param $value
         */
        function update_cart_ex_rate($value)
        {
            $.ajax({
                url: "cart/update_field_value",
                type: 'post',
                dataType: 'json',
                data: {
                    _token: CSRF_TOKEN,
                    'field':'exchange_rate',
                    'value':$value,
                },
                beforeSend: function() {

                },
                complete: function() {},
                success: function(data) {
                    display_cart();
                }
            });
        } //end methoid update cart exchange rate

        /**
         * Remove all cart content
         */
        function remove_cart_contents()
        {
            $.ajax({
                url: "cart/clear",
                type: 'post',
                dataType: 'json',
                data: {_token: CSRF_TOKEN},
                beforeSend: function() {

                },
                complete: function() {},
                success: function(data) {
                    display_cart();
                }
            });
        }

        //delete item
        $(document).on("click", '.del_item', function(event) {
            var $item = $(this);
            var $item_id = $item.attr('id');
            if ($item_id==0){
                return;
            }

            $.ajax({
                url: "cart/delete",
                type: 'post',
                dataType: 'json',
                data: {_token: CSRF_TOKEN,'id':$item_id},
                beforeSend: function() {

                },
                complete: function() {},
                success: function(data) {
                    $("#item_"+$item_id).remove();
                    display_cart();
                }
            });
        });
        //end delete item

        //display cart contents
        function display_cart()
        {
            //get contents with ajax request
            $.ajax({
                url: "cart/contents",
                type: 'get',
                dataType: 'json',
                complete: function() {},
                success: function(data) {
                    var $el = $("#invoice_contents tbody");
                    $el.html(data.html);
                    handleSortableProducts();
                }
            });
        }
        //end display cart contents

    };

    var handleSortableProducts = function () {

        $.widget("ui.productsortable", $.extend(true, {}, $.ui.sortable.prototype, {
            _init: function () {
                this.element.data('sortable', this.element.data('customsortable'));
                return $.ui.sortable.prototype._init.apply(this, arguments);
            }, serialize: function (o) {
                var items = $(".tbody-sortable tr");
                this._getItemsAsjQuery(o && o.connected);
                var str = [];
                o = o || {};
                $(items).each(function () {
                    if (typeof $(this).attr('id') !== 'undefined'){
                        str.push($(o.item || $(this)).attr('itemid'));
                    }

                });
                return str;
            }
        }));
        if ($(".tbody-sortable").length > 0) {
            $(".tbody-sortable").productsortable({
                items : $(".tbody-sortable tr:not(.no-sort)"),
                update: function (event, ui) {
                    var data = $(".tbody-sortable").productsortable("serialize", {});
                    console.log(data);

                    $.ajax({
                        url: "cart/orderitems",
                        type: 'post',
                        dataType: 'json',
                        data: {_token: CSRF_TOKEN, items: data},
                    });
                    // $.ajax({
                    //     data: {ids: data},
                    //     type: 'POST',
                    //     url: BASE_URL + 'admin/catalog/products/set_prod_order'
                    // });
                }
            }).disableSelection();
        }

    }

    //payments
    var handlePayments = function(){

        $(document).on('click', '.add_payment',function(event) {

            var $item = $(this);
            var $item_id = $item.attr('invoice_id');
            var $amount = $item.attr('payment-amount');
            var $date = $item.attr('payment-date');
            console.log($amount+'|'+$date);

            if ($item_id == 0) {
                return;
            }
            $("#modal_sett_error").text('');
            $("#modal_sett_error").hide();
            $("#add_payment_modal").find('input[name="invoice_id"]').val($item_id);
            $("#add_payment_modal").find('input[name="amount"]').val($amount);
            $("#add_payment_modal").find('input[name="payment_date"]').val($date);
            $("#add_payment_modal").modal({ keyboard: false });
        });

        if ($("#add_payment_modal").length>0){
            $("#modal_sett_error").hide();
        }

        $("#cancel_add_payment").click(function(){
            $("#add_payment_modal").modal('hide');
            $("#add_payment_modal").find('input[name="invoice_id"]').val(0);
            $("#modal_sett_error").text('');
            $("#modal_sett_error").hide();
        });

        $("#form_add_payment").submit(function(e){
            e.preventDefault();
            var url = $(this).attr('action');

            $.ajax({
                url: url,
                type: 'post',
                dataType: 'json',
                data: $(this).serialize(),
                beforeSend : function(){
                    $("#modal_sett_error").text('');
                    $("#modal_sett_error").hide();
                },
                error: function(data) {
                    var response = jQuery.parseJSON(data.responseText);
                    $("#modal_sett_error").text('');
                    $.each(response,function(index,value){
                        $("#modal_sett_error").append("<div>"+value[0]+"</div>");
                    });
                    $("#modal_sett_error").show();
                },
                success: function(data) {
                    $("#modal_sett_error").hide();
                    //$("#add_payment_modal").find('input[name="invoice_id"]').val(0);
                    window.location.reload(true);
                }
            });
        })


        /*display payments modal*/
        $(document).on('click', '.openmodal',function(event) {
            var $target = $(this).attr('data-target');
            $("#"+$target).modal();
        });

        //delete payment
        // $(document).on('click','.payment_delete', function(e){
        //     e.preventDefault();
        //     var url = $(this).attr('url');
        //     var id = $(this).attr('id');
        //
        //     $.ajax({
        //         url: url,
        //         headers: {'X-CSRF-TOKEN': CSRF_TOKEN},
        //         type: 'post',
        //         dataType: 'json',
        //         data: {'id':id},
        //         beforeSend : function(){
        //         },
        //         error: function(data) {
        //             console.log('action error');
        //         },
        //         success: function(data) {
        //             //scroll top
        //             $("body").scrollTop();
        //
        //             //refresh the page
        //             location.reload(true);
        //         }
        //     }); //end ajax
        // });

    };

    return {
        //main function to initiate the module
        init: function () {
            handleFormElements();
            handleSortableProducts();
            handleInvoice();
        },
        initList: function(){
            handlePayments();
        }

    };

}();



ZeroDay Forums Mini