var reportTripsModule = (function () {

    $(".report-submit-pdf").click(function () {
        //alert(base_url);
        //window.location.assign("http://localhost/outsource/CRM_Inventory_UD19122018(JK)/reportTripsPDF.php?startDate=&endDate=&vehicle=1&drivername=null","_blank");

        var selectspare= $('select#selectspare').val();
        var url =base_url+"stockExplosivePDF.php?spare="+selectspare;
        window.open(url, '_blank');
      });
    
    $('body').on('click','button.datewise-submit-sale',function(){
        
        var selectspare= $('select#selectspare').val();
        
            var dataTable =  $('#StockSpareDashboard').DataTable( {
                responsive: {
                    details: {
                     renderer: function ( api, rowIdx ) {
                     var data = api.cells( rowIdx, ':hidden' ).eq(0).map( function ( cell ) {
                         var header = $( api.column( cell.column ).header() );
                         return  '<p style="color:#00A">'+header.text()+' : '+api.cell( cell ).data()+'</p>';
                     } ).toArray().join('');        
                     return data ?    $('<table/>').append( data ) :    false;
                     }
                    }
                },
                processing: true,
                serverSide: true,				
                aaSorting: [[0, 'desc']],
                destroy: true,
                ajax: {
                    url : "stockexplosivegriddata.php",
                    type: 'POST',
                    data:  {
                        selectspare    : selectspare
                    }
                }
            });

                       
        // } else if(fromDate && toDate && selecttripvehicle) { 

        //     var dataTable =  $('#reportTripsTDashboard').DataTable( {
        //         responsive: {
        //             details: {
        //              renderer: function ( api, rowIdx ) {
        //              var data = api.cells( rowIdx, ':hidden' ).eq(0).map( function ( cell ) {
        //                  var header = $( api.column( cell.column ).header() );
        //                  return  '<p style="color:#00A">'+header.text()+' : '+api.cell( cell ).data()+'</p>';
        //              } ).toArray().join('');        
        //              return data ?    $('<table/>').append( data ) :    false;
        //              }
        //             }
        //         },
        //         processing: true,
        //         serverSide: true,				
        //         aaSorting: [[0, 'desc']],
        //         destroy: true,
        //         ajax: {
        //             url : "reportTripsgriddata.php",
        //             type: 'POST',
        //             data:  {
        //                 userpermissionEdit   : $("input.reportTrips-edit").val(),
        //                 userpermissionDelete : $("input.reportTrips-delete").val(),
        //                 tripfromDate    : fromDate,
        //                 triptoDate      : toDate,
        //                 tripvehicle     : $('select#selecttripvehicle').val(),
        //                 tripdrivername  : ''
        //             }
        //         }
        //     });



        // } else if(fromDate && toDate && selecttripvehicle && selecttripdrivername) { 

        // } else if(selecttripvehicle) { 

        //     var dataTable =  $('#reportTripsTDashboard').DataTable( {
        //         responsive: {
        //             details: {
        //              renderer: function ( api, rowIdx ) {
        //              var data = api.cells( rowIdx, ':hidden' ).eq(0).map( function ( cell ) {
        //                  var header = $( api.column( cell.column ).header() );
        //                  return  '<p style="color:#00A">'+header.text()+' : '+api.cell( cell ).data()+'</p>';
        //              } ).toArray().join('');        
        //              return data ?    $('<table/>').append( data ) :    false;
        //              }
        //             }
        //         },
        //         processing: true,
        //         serverSide: true,				
        //         aaSorting: [[0, 'desc']],
        //         destroy: true,
        //         ajax: {
        //             url : "reportTripsgriddata.php",
        //             type: 'POST',
        //             data:  {
        //                 userpermissionEdit   : $("input.reportTrips-edit").val(),
        //                 userpermissionDelete : $("input.reportTrips-delete").val(),
        //                 tripfromDate    : '',
        //                 triptoDate      : '',
        //                 tripvehicle     : selecttripvehicle,
        //                 tripdrivername  : ''
        //             }
        //         }
        //     });

        // } else if(fromDate && toDate && selecttripdrivername) { 

        // } else if(selecttripvehicle && selecttripdrivername) { 
            
        // }

    });
    
    
    $('body').on('change', 'select.select-purchase-category', function(){

        var trip_category = $('#trip_category').val();
    if(trip_category == 'transportation'){
        $('#reportTripsEDashboard').hide();
        $('#reportTripsEDashboard_wrapper').hide();        
        $('#reportTripsTDashboard_wrapper').show();
        $('#reportTripsTDashboard').show();

        var dataTable =  $('#reportTripsTDashboard').DataTable( {
            responsive: {
                details: {
                 renderer: function ( api, rowIdx ) {
                 var data = api.cells( rowIdx, ':hidden' ).eq(0).map( function ( cell ) {
                     var header = $( api.column( cell.column ).header() );
                     return  '<p style="color:#00A">'+header.text()+' : '+api.cell( cell ).data()+'</p>';
                 } ).toArray().join('');
    
                 return data ?    $('<table/>').append( data ) :    false;
                 }
                }
            },
            processing: true,
            serverSide: true,				
            aaSorting: [[0, 'desc']],
            destroy: true,
            ajax: {
             url : "reportTripsgriddata.php",
             type: 'POST',
             data:  {
                userpermissionEdit   : $("input.reportTrips-edit").val(),
                userpermissionDelete : $("input.reportTrips-delete").val(),
                purchaseinvoiceCategory : $(this).val()
    
    
         }
         }
         } );

    } else if(trip_category == 'equipment'){
        $('#reportTripsTDashboard').hide();
        $('#reportTripsTDashboard_wrapper').hide();
        $('#reportTripsEDashboard_wrapper').show();
        $('#reportTripsEDashboard').show();


        var dataTable =  $('#reportTripsEDashboard').DataTable( {
            responsive: {
                details: {
                 renderer: function ( api, rowIdx ) {
                 var data = api.cells( rowIdx, ':hidden' ).eq(0).map( function ( cell ) {
                     var header = $( api.column( cell.column ).header() );
                     return  '<p style="color:#00A">'+header.text()+' : '+api.cell( cell ).data()+'</p>';
                 } ).toArray().join('');
    
                 return data ?    $('<table/>').append( data ) :    false;
                 }
                }
            },
            processing: true,
            serverSide: true,				
            aaSorting: [[0, 'desc']],
            destroy: true,
            ajax: {
             url : "reportTripsgriddata.php",
             type: 'POST',
             data:  {
                userpermissionEdit   : $("input.reportTrips-edit").val(),
                userpermissionDelete : $("input.reportTrips-delete").val(),
                 purchaseinvoiceCategory : $(this).val()
    
    
         }
         }
         } );

        
    }


        
 



    });


})();