
var pharmacyjs_file = function () {

    var hosturl = $('#hosturl').val();
    var path = $('#path').val();
    var deletewhenedit = function () {

        //remove the selected
        $('.delinedit').live('click', function () {
            //check for edit
            var editcheck = $(this).attr('data-edit');
            var itemid = $(this).attr('data-id');
            var urlgo = $(this).attr('data-link');
            var bill_id = $(this).attr('data-bill');
            if (editcheck == 0) {

                //here will delete by ajax

                $.post(hosturl + "/controllers/" + urlgo + ".php?ac=delup", {itemid: itemid, bill_id: bill_id}, function (data) {

                    if (data) {
                        var shortCutFunction = 'success';
                        var msg = 'The element has been deleted successfully';
                        var title = 'Success';
                    } else {
                        var shortCutFunction = 'error';
                        var msg = 'Sorry , an error has been occured ';
                        var title = 'Error';
                    }
                    toastr.options = {
                        closeButton: $('#closeButton').prop('checked'),
                        debug: $('#debugInfo').prop('checked'),
                        positionClass: $('#positionGroup input:checked').val() || 'toast-top-right',
                        onclick: null
                    };
                    var $toast = toastr[shortCutFunction](msg, title);
                })
            }

            $(this).parent().parent().remove();
        })
    }

    var invoicemodelview = function () {
        $('#invoicemodelview').live('click', function () {
            var iditem = $(this).attr('data-id');
            var hosturl = $('#hosturl').val();

            $.post(hosturl + "/controllers/buys.php?ac=invoice", {itemid: iditem}, function (data) {
                // alert(data)
                $('#full').html(data);
                $('#full').modal('show');
            });

        });
    }

    $('body').on('change', '.updateAmount', function ()
    {
        var id = $(this).attr("data-id");
        var colName = $(this).attr("data-colName");
        var tableName = $(this).attr("data-tableName");
        var value = $(this).val();


        $.post(hosturl + '/controllers/receipt.php?ac=update', {id: id, value: value, tableName: tableName, colName: colName}, function (res)
        {

        });
    });


    var cashingreceipt = function () {
        $('.presscashing').click(function () {
            var amount = $("#amount").val();
            var currentbalance = $("#currentbalance").val();
            if (amount > currentbalance) {

            }

        });
    }
    var getallids = function () {
        $('.selectoncedrug').live('change', function () {
            var myid = "";
            $('.elementID').each(function () {
                if ($(this).is(":selected")) {
                    myid += $(this).val();
                    myid += ",";
                }
            });

            myid = myid.substr(0, myid.length - 1);
            $.post(hosturl + '/controllers/buys.php?ac=drugsselected', {myid: myid, hidehtml: 1}, function (data) {
                $('#drugsload').html(data);
            });
        });
    }


    var fffffff = function () {
        $('.userstuff').live('Change', function () {
            alert('kkskdskdks');
        })
    }

    var printinvoice = function () {
        $('#printinvoivce').live('click', function () {
            $.print("#adv_containter_invoice");
        });
    };

    return {
//main function to initiate the module
        init: function () {

            deletewhenedit();
            getallids();
            cashingreceipt();
            invoicemodelview();
            //alluserstuffshown();
            //edithead();
            //headupdate();
            fffffff();
            printinvoice();


        }

    };
}();















/////////////////////////////////////* Amr *///////////////////////////////////////////

$(".select2me").change(function () {
    var inputs = $(this).closest('table').find(':input');
    inputs.eq(inputs.index(this) + 1).focus();
});
