function checkcurrentpwd(val){
    $.ajax({
        url: $("#url_path").val()+"/checkadminpassword"+"/"+val,
        method:"get",
        success: function( data ) {
            console.log(data);
            if(data==1){
                 var msg = $("#cpwd").val();
                alert(msg);
                $("#oldPassword").val("");
            }
        }
    });
}

function checkbothpassword(val){
    console.log(val);
    var msg = $("#newpwd").val();    
    var newpassword = $("#newPassword").val();
    if(newpassword!=val){
        alert(msg);
        $("#newPassword").val("");
        $("#confirmPassword").val("");
    }
}
function delete_record(url){
    var msg = $("#record").val();
    if (confirm(msg)) {   
         if($("#is_demo").val()=='0'){
            alert("This function is currently disable as it is only a demo website, in your admin it will work perfect");
         }else{
            window.location.href = url; 
         }                   
    } else {
        window.location.reload();
    }
}


$(document).ready(function () {
    $('#OrdersTable').DataTable({
        processing: true,
        serverSide: true,
        ajax: $("#url_path").val() + '/ManagerOrdersTable',
        columns: [{
                data: 'id',
                name: 'id'
            },{
                data: 'name',
                name: 'name'
            },{
                data: 'address',
                name: 'address'
            },{
                data: 'datetime',
                name: 'datetime'
            },{
                data: 'payment_method',
                name: 'payment_method'
            },{
                data: 'paid_amount',
                name: 'paid_amount'
            },{
                data: 'more',
                name: 'more'
            },{
                data: 'print',
                name: 'print'
            },{
                data: 'status',
                name: 'status'
            },{
                data: 'action',
                name: 'action'
            }
        ],
        columnDefs: [{
            targets: 6,
            render: function (data) { 
                    return '<a href="javascript::void(0)" onclick="moreinfo('+data+')" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#normalmodal">More</a>';          
            }
        },{
            targets: 7,
            render: function (data) {
                    var path = $("#url_path").val()+"/managerprintorders"+"/"+data;
                    return '<a href="'+path+'" target="_blank" class="btn btn-primary">print</a>';               
            }
        }],
        order: [
            [0, "DESC"]
        ]
    });
});

$(document).ready(function () {
    $('#TodayOrdersTable').DataTable({
        processing: true,
        serverSide: true,
        ajax: $("#url_path").val() + '/TodayManagerOrdersTable',
        columns: [{
                data: 'id',
                name: 'id'
            },{
                data: 'name',
                name: 'name'
            },{
                data: 'address',
                name: 'address'
            },{
                data: 'datetime',
                name: 'datetime'
            },{
                data: 'payment_method',
                name: 'payment_method'
            },{
                data: 'paid_amount',
                name: 'paid_amount'
            },{
                data: 'more',
                name: 'more'
            },{
                data: 'print',
                name: 'print'
            },{
                data: 'status',
                name: 'status'
            },{
                data: 'action',
                name: 'action'
            }
        ],
        columnDefs: [{
            targets: 6,
            render: function (data) { 
                    return '<a href="javascript::void(0)" onclick="moreinfo('+data+')" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#normalmodal">More</a>';          
            }
        },{
            targets: 7,
            render: function (data) {
                    var path = $("#url_path").val()+"/managerprintorders"+"/"+data;
                    return '<a href="'+path+'" target="_blank" class="btn btn-primary">print</a>';               
            }
        }],
        order: [
            [0, "DESC"]
        ]
    });
});

function moreinfo(id){
        $.ajax({
            url: $("#url_path").val()+"/getmanagerorderdetails"+"/"+id,
            success: function( data ) {
                var str = JSON.parse(data);
                $("#order_no").html(str.data.id);
                $("#customer_name").html(str.userinfo.name);
                $("#email").html(str.userinfo.email);
                $("#address").html(str.data.useraddressdetails.address);
                $("#order_place_date").html(str.data.orderplace_date);
                $("#payment_method").html(str.data.payment_method);
                $("#date").html(str.data.date);
                $("#time").html(str.data.time);
                var txt = "";
                for(var i=0;i<str.data.orderdata.length;i++){
                    var mrp = str.data.orderdata[i].mrp;
                    var price = str.data.orderdata[i].price;
                    txt = txt +'<tr><td>'+str.data.orderdata[i].memberdetails.name+' | '+str.data.orderdata[i].memberdetails.relation+'</br>'+str.data.orderdata[i].memberdetails.gender+'</td><td>Name : '+str.data.orderdata[i].item_name+'</br>Parameters : '+str.data.orderdata[i].parameter+'</br>MRP : '+str.currency+mrp.toFixed(2)+'</br>Price : '+str.currency+price.toFixed(2)+'</td><td>'+str.currency+price.toFixed(2)+'</td></tr>';
                }
                var subtotal = str.data.subtotal;
                var txtchr = str.data.tax;
                var finalamount = str.data.final_total;
                $("#tableinfo").html(txt);
                $("#subtotal").html(str.currency+subtotal.toFixed(2));
                $("#txt_charge").html(str.currency+txtchr.toFixed(2));
                $("#total").html(str.currency+finalamount.toFixed(2));
            }
        });

}



function rejectorder(id){
  
  $("#rejectorderurl").attr("action",$("#url_path").val()+"/change_order_status"+"/"+id+"/3");
}

function completeorder(id){
    $("#com_order_id").val(id);

}