var id_pro = 0;
var count_pro = 0;
function sys(s)
{
    if(s == 0)
    {
        var txt = `
        <div class="row">           
          <table id="Table1" class="mdl-data-table dataTable" cellspacing="0" width="100%">
           <thead style="">
                  <tr>
                      <th>اسم العميل</th>
                      <th>رقم الكرت</th>
                      <th>القيمة</th>
                      <th>اسم الموظف</th>
                      <th>التاريخ</th>
                      <th>الوقت</th>
                      <th></th>
                  </tr>
              </thead>
                <tbody>
                <tfoot>
            </tfoot>
                </tbody>
          </table>
       </div>`;
       $('#pg_body').html(txt);
       
        var dataTable = $('#Table1').DataTable( {
                    columnDefs: [
            {
                targets: [ 0, 1, 2 ],
                className: 'mdl-data-table__cell--non-numeric'
        }],
            "processing": true,
            "serverSide": true,
            "ajax":{
                url :"model/class/sys_1.php",
                type: "POST",  
                dataType:"JSON",
                error: function(){
                    
                }
            }
        } );
        $('#Table1').DataTable();
        get_page();
    }   
    if(s == 1)
    {
        var txt = `
        <div class="row">           
          <table id="Table1" class="mdl-data-table dataTable" cellspacing="0" width="100%">
           <thead style="">
                  <tr>
                      <th>اسم المصروف</th>
                      <th>القيمة</th>
                      <th>اسم الموظف</th>
                      <th>الملاحظات</th>
                      <th>التاريخ</th>
                      <th>الوقت</th>
                      <th></th>
                  </tr>
              </thead>
                <tbody>
                <tfoot>
            </tfoot>
                </tbody>
          </table>
       </div>`;
       $('#pg_body').html(txt);
       
        var dataTable = $('#Table1').DataTable( {
                    columnDefs: [
            {
                targets: [ 0, 1, 2 ],
                className: 'mdl-data-table__cell--non-numeric'
        }],
            "processing": true,
            "serverSide": true,
            "ajax":{
                url :"model/class/sys_2.php",
                type: "POST",  
                dataType:"JSON",
                error: function(){
                    
                }
            }
        } );
        $('#Table1').DataTable();
    }
    if(s == 2)
    {
        var txt = `
        <div class="row">           
          <table id="Table1" class="mdl-data-table dataTable" cellspacing="0" width="100%">
           <thead style="">
                  <tr>
                      <th>اسم الايراد</th>
                      <th>القيمة</th>
                      <th>اسم الموظف</th>
                      <th>الملاحظات</th>
                      <th>التاريخ</th>
                      <th>الوقت</th>
                      <th></th>
                  </tr>
              </thead>
                <tbody>
                <tfoot>
            </tfoot>
                </tbody>
          </table>
       </div>`;
       $('#pg_body').html(txt);
       
        var dataTable = $('#Table1').DataTable( {
                    columnDefs: [
            {
                targets: [ 0, 1, 2 ],
                className: 'mdl-data-table__cell--non-numeric'
        }],
            "processing": true,
            "serverSide": true,
            "ajax":{
                url :"model/class/sys_3.php",
                type: "POST",  
                dataType:"JSON",
                error: function(){
                    
                }
            }
        } );
        $('#Table1').DataTable();
        get_page();
    }
    if(s == 3)
    {
        var txt = `
        <div class="row">           
          <table id="Table1" class="mdl-data-table dataTable" cellspacing="0" width="100%">
           <thead style="">
                  <tr>
                      <th>اسم الخدمة</th>
                      <th>القيمة</th>
                      <th>اسم الموظف</th>
                      <th>الملاحظات</th>
                      <th>التاريخ</th>
                      <th>الوقت</th>
                      <th></th>
                  </tr>
              </thead>
                <tbody>
                <tfoot>
            </tfoot>
                </tbody>
          </table>
       </div>`;
       $('#pg_body').html(txt);
       
        var dataTable = $('#Table1').DataTable( {
                    columnDefs: [
            {
                targets: [ 0, 1, 2 ],
                className: 'mdl-data-table__cell--non-numeric'
        }],
            "processing": true,
            "serverSide": true,
            "ajax":{
                url :"model/class/sys_4.php",
                type: "POST",  
                dataType:"JSON",
                error: function(){
                    
                }
            }
        } );
        $('#Table1').DataTable();
        get_page();
    }
    if(s == 4)
    {
        var txt = `
        <div class="row">           
          <table id="Table1" class="mdl-data-table dataTable" cellspacing="0" width="100%">
           <thead style="">
             <tr>
                <th>اسم الصنف</th>
                <th>العدد</th>
                <th>السعر قبل الخصم</th>
                <th>الخصم</th>
                <th>السعر بعد الخصم</th>
                <th>الملاحظات</th>
                <th>اسم الموظف</th>
                <th>الوقت</th>
                <th></th>
            </tr>
              </thead>
                <tbody>
                </tbody>
          </table>
       </div>`;
       $('#pg_body').html(txt);
       
        var dataTable = $('#Table1').DataTable( {
                    columnDefs: [
            {
                targets: [ 0, 1, 2 ],
                className: 'mdl-data-table__cell--non-numeric'
        }],
            "processing": true,
            "serverSide": true,
            "ajax":{
                url :"model/class/sys_5.php",
                type: "POST",  
                dataType:"JSON",
                error: function(){
                    
                }
            }
        } );
        $('#Table1').DataTable();
        get_page();
    }
    if(s == 5)
    {
        var txt = `
        <div class="row">           
          <table id="Table1" class="mdl-data-table dataTable" cellspacing="0" width="100%">
           <thead style="">
             <tr>
                <th>اسم العميل</th>
                <th>رقم الكرت</th>
                <th>تاريخ التحضير</th>
                <th>وقت التحضير</th>
                <th></th>
            </tr>
              </thead>
                <tbody>
                </tbody>
          </table>
       </div>`;
       $('#pg_body').html(txt);
       
        var dataTable = $('#Table1').DataTable( {
                    columnDefs: [
            {
                targets: [ 0, 1, 2 ],
                className: 'mdl-data-table__cell--non-numeric'
        }],
            "processing": true,
            "serverSide": true,
            "ajax":{
                url :"model/class/sys_6.php",
                type: "POST",  
                dataType:"JSON",
                error: function(){
                    
                }
            }
        } );
        $('#Table1').DataTable();
        get_page();
    }
    if(s == 6)
    {
        var txt = `
        <div class="row">           
          <table id="Table1" class="mdl-data-table dataTable" cellspacing="0" width="100%">
           <thead style="">
             <tr>
                <th>اسم الصنف</th>
                <th>اسم القسم</th>
                <th>الكمية</th>
                <th></th>
            </tr>
              </thead>
                <tbody>
                </tbody>
          </table>
       </div>`;
       $('#pg_body').html(txt);
       
        var dataTable = $('#Table1').DataTable( {
                    columnDefs: [
            {
                targets: [ 0, 1, 2 ],
                className: 'mdl-data-table__cell--non-numeric'
        }],
            "processing": true,
            "serverSide": true,
            "ajax":{
                url :"model/class/sys_7.php",
                type: "POST",  
                dataType:"JSON",
                error: function(){
                    
                }
            }
        } );
        $('#Table1').DataTable();     
        get_page();   
    }
    if(s == 7)
    {
        $.ajax({
            url:"model/backup.php",
            type:"POST",
            dataType:"JSON",
            data:{},
            success:function()
            {
                success();
            }
        })
    }
    if(s == 8)
    {
        var txt = "select * from `sys` where `id_sys` = '1'";
        $.ajax({
            url:"model/class/class.php",
            type:"POST",
            dataType:"JSON",
            data:{txt:txt,type:1},
            success:function(data)
            {
                $('#sys_mode').modal('show');
                if(data[0].type_sys == 0)
                {
                    $('#mode_1').prop("checked","true");
                    //$('#mode_2').prop("checked","false");
                }else{
                    $('#mode_2').prop("checked","true");
                   // $('#mode_1').prop("checked","false");                 
                }
            }
        })
    }
    if(s == 9)
    {
        var txt = `
        <div class="row">           
          <table id="Table1" class="mdl-data-table dataTable" cellspacing="0" width="100%">
           <thead style="">
             <tr>
                <th>اسم العميل</th>
                <th>رقم الكرت</th>
                <th>باقى الحصص</th>
                <th>باقى الاموال</th>
                <th>تاريخ التجديد</th>
                <th></th>
            </tr>
              </thead>
                <tbody>
                </tbody>
          </table>
       </div>`;
       $('#pg_body').html(txt);
       
        var dataTable = $('#Table1').DataTable( {
                    columnDefs: [
            {
                targets: [ 0, 1, 2 ],
                className: 'mdl-data-table__cell--non-numeric'
        }],
            "processing": true,
            "serverSide": true,
            "ajax":{
                url :"model/class/sys_8.php",
                type: "POST",  
                dataType:"JSON",
                error: function(){
                    
                }
            }
        } );
        $('#Table1').DataTable(); 
        get_page();
    }
    if(s == 10)
    {
        $('#change_date').modal('show');
    }
}
function del_table(id,table)
{
    if(table == 0)
    {
        var td = "stock_mony";
        var col = "id_stock_mony";
        $.ajax({
            url:"model/class/class.php",
            type:"POST",
            dataType:"JSON",
            data:{txt:id,type:4},
            success:function()
            {
                var txt = "delete from `"+td+"` where `"+col+"` = '"+id+"'";
                $.ajax({
                    url:"model/class/class.php",
                    type:'POST',
                    dataType:"JSON",
                    data:{txt:txt,type:0},
                    success:function()
                    {
                        success();
                    }
                })
            }
        })
    }
    if(table == 1)
    {
        var td = "exp_mony";
        var col = "id_exp_mony";  
        var txt = "delete from `"+td+"` where `"+col+"` = '"+id+"'";
        $.ajax({
            url:"model/class/class.php",
            type:"POST",
            dataType:"JSON",
            data:{txt:txt,type:0},
            success:function()
            {
                success();
            }
        })   
    }
    if(table == 2)
    {
        var td = "inp_mony";
        var col = "id_inp_mony";  
        var txt = "delete from `"+td+"` where `"+col+"` = '"+id+"'";
        $.ajax({
            url:"model/class/class.php",
            type:"POST",
            dataType:"JSON",
            data:{txt:txt,type:0},
            success:function()
            {
                success();
            }
        })   
    }
    if(table == 3)
    {
        var td = "mony";
        var col = "id_mony";  
        var txt = "delete from `"+td+"` where `"+col+"` = '"+id+"'";
        $.ajax({
            url:"model/class/class.php",
            type:"POST",
            dataType:"JSON",
            data:{txt:txt,type:0},
            success:function()
            {
                success();
            }
        })   
    }
    if(table == 4)
    {
        var td = "sales";
        var col = "id_sales";  
        $.ajax({
            url:"model/class/class.php",
            type:"POST",
            dataType:"JSON",
            data:{txt:id,type:5},
            success:function()
            {
                var txt = "delete from `"+td+"` where `"+col+"` = '"+id+"'";
                $.ajax({
                    url:"model/class/class.php",
                    type:"POST",
                    dataType:"JSON",
                    data:{txt:txt,type:0},
                    success:function()
                    {
                        success();
                    }
                })  
            } 
        })
    }
    if(table == 5)
    {
        var td = "sales";
        var col = "id_sales";  
        $.ajax({
            url:"model/class/class.php",
            type:"POST",
            dataType:"JSON",
            data:{txt:id,type:5},
            success:function()
            {
                var txt = "delete from `"+td+"` where `"+col+"` = '"+id+"'";
                $.ajax({
                    url:"model/class/class.php",
                    type:"POST",
                    dataType:"JSON",
                    data:{txt:txt,type:0},
                    success:function()
                    {
                        success();
                    }
                })  
            } 
        })
    }
    if(table == 6)
    {
        var txt = "select * from `table_day` left join `cus` on `cus`.`id_cus` = `table_day`.`id_cus` left join `member` on `member`.`id_member` = `cus`.`id_member` where `table_day`.`id_table_day` = '"+id+"'";
        var td = "table_day";
        var col = "id_table_day";  
        $.ajax({
            url:"model/class/class.php",
            type:"POST",
            dataType:"JSON",
            data:{txt:txt,type:1},
            success:function(data)
            {
                //alert("ok");
                var new_s = parseFloat(Number(data[0].count_s) + 1);
                if(data[0].type_member != 1)
                {
                    var txt = "update `cus` set `count_s` = '"+new_s+"' where `id_cus` = '"+data[0].id_cus+"'";
                    $.ajax({
                        url:"model/class/class.php",
                        type:"POST",
                        dataType:"JSON",
                        data:{txt:txt,type:0},
                        success:function()
                        {
                            //alert("ok");
                            var txt = "delete from `"+td+"` where `"+col+"` = '"+id+"'";
                            $.ajax({
                                url:"model/class/class.php",
                                type:"POST",
                                dataType:"JSON",
                                data:{txt:txt,type:0},
                                success:function()
                                {
                                    success();
                                }
                            })              
                        }
                    }) 
                }else{
                    var txt = "delete from `"+td+"` where `"+col+"` = '"+id+"'";
                    $.ajax({
                        url:"model/class/class.php",
                        type:"POST",
                        dataType:"JSON",
                        data:{txt:txt,type:0},
                        success:function()
                        {
                           //alert("else");
                            success();
                        }
                    }) 
                }
 
            } 
        })     
    }
}

function update_pro_sys(id,count)
{
    id_pro = id;
    count_pro = count;
    $('#i_pro_sys').modal('show');
    $('#i_c_pro_sys').val(count);
}
function in_pro_sys()
{
    var c = $('#i_c_pro_sys').val();
    var txt = "update `pro` set `stock_pro` = '"+c+"' where `id_pro` = '"+id_pro+"'";
    $.ajax({
        url:"model/class/class.php",
        type:"POST",
        dataType:"JSON",
        data:{txt:txt,type:0},
        success:function()
        {
            success();
        }
    })
}
function save_mode_sys(type)
{
	type_color = type;
    var txt = "update `sys` set `type_sys` = '"+type+"' where `id_sys` = '1'";
    $.ajax({
        url:"model/class/class.php",
        type:"POST",
        dataType:"JSON",
        data:{txt:txt,type:0},
        success:function()
        {
            get_page();
        }
    })
}
function save_change_date()
{
    var date = $('#date_change').val();
    date_today = date;
    $('#ul_date').text(date_today);
    $('#change_date').modal('hide');
}