<?php $user_id=$this->session->userdata('user_id');
if(!$user_id){
  redirect('user/login_view', 'refresh');
}
 $bankname=$this->db->query("select * from bank_name where status=1 and buisness_id='$b_type'  
      limit 1 ");
    $data='';
    foreach ($bankname->result() as $key => $name){
        $bname=$name->id;
    }
 $currentyear=date('Y');

?>

<!DOCTYPE html>
<html lang="en">
<?php
$this->load->view('head.php');
?>

<body class="dashboard">
  <div id="wrapper">

    <div class="admin-title">
      <div class="row">
        <?php $this->load->view('header.php'); ?>
      </div>
    </div>

    <div class="content-area">
      <div class="row">
       
          <div class="admin-menu">
            <?php $this->load->view('sidebar.php'); ?>
          </div>
       
      <div class="content-menu">
            <div class="panel-heading" role="tab" id="panelOne">
    <h2 style="display:inline-block;">Welcome to Dashboard</h2>
        <div class="col-sm-12 yearlyfilter">
         <select class="form-control yearManufactured" name="yearManufactured" >  
          
         <?php
         foreach(range(2019, (int)date("Y")) as $year) {
             if($currentyear==$year){
                 $activeyear='selected';
             }
             else{
                $activeyear=''; 
             }
            echo "<option value='".$year."' ".$activeyear.">".$year."</option>\n\r";
          }

         ?>
        </select>  
        </div>
        </div>
          </div>
          <div class="main-content">

    <div class="btn-controls">

  
        
 <div id="collapseOne" class="panel-collapse main-box" role="tabpanel" aria-labelledby="headingOne" >
     <div id="chartContainer" >
         
         <?php foreach($graphdata as $key=> $report) {?>
       <div class="btn-box small span3 monthlyreport <?php echo $report['label'];?> <?php echo $report['signal']; ?>">
          <h2><?php echo $report['label'];?></h2>
           
            <div class="row">
              <div class="result-info">
                <p > Sale </p>
                <strong class="sale<?php echo $report['label'];  ?>"><?php echo ($report['sale'].' €');?></strong>
              </div>
                <div class="result-info">
                <p> Purchases </p>
                 <strong class="pur<?php echo $report['label'];  ?>"><?php echo ($report['purchases'].' €');?></strong>
              </div>
                 <div class="result-info">
                <p> Paid </p>
                 <strong class="paid<?php echo $report['label'];  ?>"><?php echo ($report['paid'].' €');?></strong>
              </div>
            </div>
          </div>
         <?php } ?>
     
     </div>

<div class="btn-box-row row-fluid">
  <div class="span12">
    <div class="row-fluid">
      <div class="span12">
        <div class="btn-box small span3">
          <h4>Income and Loss</h4>
<select id="filterprofit" class="homepagefilter">
  <option value="This Month" selected><a href="#">This Month </a></option>
  <option value="Last Month"><a href="#">Last Month </a></option>
  <option value="This Year"><a href="#">This Year </a></option>
  <option value="Last Year"><a href="#">Last Year </a></option>
 <option value="Custom Search"> Custom Search</option>
</select>
<div id="myFilter" style="display:none;">
    <input type="date" class="filterdatefrom">
    <input type="date" class="filterdateto">
    <input type="submit" value="search" onclick="filtercustom()">
</div>


            <div class="row">
              <div class="col-xs-12 col-md-12 col-md-12 top-row">
                <p ><strong class="income">0€</strong> Net income  </p>
              </div>
            </div>

            <div class="row">
              <div class="text-con">
                <p> <strong class="sale"></strong>Sale </p>
                <p> <strong class="purchases"></strong>Purchases</p>
                <p> <strong class="paid"></strong>Paid</p>
              </div>
              <div class="color-con">
                <ul class="blue">
                  <li>blue</li>
                  <li>blue</li>
                  <li>blue</li>
                </ul>
              </div>
            </div>


          </div>

          <div class="btn-box small span3">
            <h4>Expenses</h4>
              <select class="expense">
   
  <option value="This Month" selected><a href="#">This Month </a></option>
  <option value="Last Month"><a href="#">Last Month </a></option>
  <option value="This Year"><a href="#">This Year </a></option>
  <option value="Last Year"><a href="#">Last Year </a></option>
 <option value="Custom Search"><a href="#">Custom Search </a></option>
</select>
<div id="expensemyFilter" style="display:none;">
    <input type="date" class="expensefilterdatefrom">
    <input type="date" class="expensefilterdateto">
    <input type="submit" value="search" onclick="expensefiltercustom()">
</div>

              <div class="row">
                <div class="col-xs-12 col-md-12 col-md-12 top-row">
                  <p ><strong class="total_expenseweak">0€</strong><span >Total</span></p>
                </div>
              </div>

              <div class="row">
                <div class="text-con">
                  <p> <strong class="emp_expenseweak">0€</strong>Employers </p>
                  <p> <strong class="last_expenseweak">0€</strong>Expenses  </p>
                </div>
                <div class="color-con">
                  <ul class="green">
                    <li>green</li>
                    <li>green</li>
                    <li>green</li> 
                  </ul>
                </div>
              </div>
            </div>


            <div class="btn-box small span3"><h4>Loan</h4 >
              <div class="row">
                <div class="col-xs-12 col-md-12 col-md-12 ">
                  <p> <strong><?php  if($totalloan['totalloan']) echo ((($totalloan['totalloan']))); else echo '0.00';?>&nbsp;€</strong>Total Loan </p>
                 
                </div>
                  <div class="banktable table-responsive col-xs-12 col-md-12">
                    <table class="table">
                      <?php foreach($totalloan['totalloancat'] as $key=> $totalloancat){ ?>
                         <tr>
                             <td><strong><?php echo $key;?></strong></td>
                             <td><strong><?php echo $totalloancat;?>&nbsp;€</strong></td>
                           </tr>
                      <?php } ?>
                   </table>
                    </div>
              </div>

              <div class="row">
                <div class="text-reportcon ">
                  <p> <strong><?php if($payloan) echo ((($payloan['totalpayloan']))); else echo '0.00'; ?>&nbsp; €</strong>Paid Loan </p>
                  
                </div>
                  <div class="banktable table-responsive col-xs-12 col-md-12">
                    <table class="table">
                      <?php foreach($payloan['totalpayloancat'] as $key=> $totalpayloancat){ ?>
                         <tr>
                             <td><strong><?php echo $key;?></strong></td>
                             <td><strong><?php echo $totalpayloancat;?>&nbsp;€</strong></td>
                           </tr>
                      <?php } ?>
                   </table>
                    </div>
                <div class="color-con">
                  <ul class="black">
                    <li>red</li>
                    <li>blue</li>
                    <li>black</li>
                  </ul>
                </div>
              </div>
            </div>


            <div class="btn-box small span3">
              <h4>Account</h4 >
              <div class="row">
                <div class="col-xs-12 col-md-12 col-md-12 top-row">
                  <p> <strong><?php echo number_format($bankamount,2); ?>&nbsp;€</strong>Total Amount </p>
                </div>
              </div>

              <div class="row">
                  <div class="banktable table-responsive col-xs-12 col-md-12">
                    <table class="table">
                      <?php foreach($allbankamount as $bank=> $bankamount){ ?>
                         <tr>
                             <td><strong><?php echo $bank;?></strong></td>
                             <td><strong><?php echo number_format($bankamount,2);?>&nbsp;€</strong></td>
                           </tr>
                      <?php } ?>
                   </table>
                    </div>
             
                <div class="color-con">
                  <ul class="red">
                    <li>black</li>
                    <li>black</li>
                    <li>black</li>
                  </ul>
                </div>
              </div>


            </div>
          
           <!--19-12-18-->
            <div class="btn-box small span3 profit">
            <h4 >Net Profit</h4>
              <select class="netexpense">

  <option value="This Month" selected><a href="#">This Month </a></option>
  <option value="Last Month"><a href="#">Last Month </a></option>
  <option value="This Year"><a href="#">This Year </a></option>
  <option value="Last Year"><a href="#">Last Year </a></option>
 <option value="Custom Search"><a href="#">Custom Search </a></option>
</select>
<div id="netexpensemyFilter" style="display:none; position: relative;
    top: -16px;">
    <input type="date" class="netexpensefilterdatefrom">
    <input type="date" class="netexpensefilterdateto">
    <input type="submit" value="search" onclick="netexpensefiltercustom()">
</div>

              <div class="row">
               
                <div class="col-xs-12 col-md-12 col-md-12 top-row">
                  <p ><strong class="nettotal_expenseweak">0€</strong><span>Total</span></p>
                  
                </div>
               
              </div>
                <div class="col-sm-12 unpaidsec">
                <div class="unpaidrow">
                  <p> <strong><?php  if($unpaidpurchases) echo (number_format(($unpaidpurchases),2)); else echo '0.00';?>&nbsp;€</strong>Due Purchases </p>
                   <p> <strong><?php if($unpaidwholesale) echo (number_format(($unpaidwholesale),2)); else echo '0.00'; ?>&nbsp; €</strong>Due sale </p>
                </div>
                </div>
              <div class="row">
                <div class="text-con">
                  <p> <strong class="netemp_expenseweak">0€</strong>Net Income  </p>
                  <p> <strong class="netlast_expenseweak">0€</strong>Total Expense  </p>
                </div>
                <div class="color-con">
                  <ul class="green">
                    <li>green</li>
                    <li>green</li>
                    <li>green</li> 
                  </ul>
                </div>
              </div>
            </div>
           <!-- 19-12-18-->
           <?php $totalincome=($totalprofit+$unpaidwholesale); $totalincomeprofit=($totalincome-$unpaidpurchases); 
          if($totalincomeprofit < 0){
            $sty_back='background:red';
          }
          
            ?>
           <div class="btn-box small span3" style="<?php echo $sty_back ;?>">
              <h4>Total Profit </h4 >
              <div class="row">
                <div class="col-xs-12 col-md-12 col-md-12 top-row">
                  <p> <strong><?php  echo number_format($totalincomeprofit,2); ?>&nbsp;€</strong>Total Amount </p>
                </div>
              </div>

           


            </div>
            
          </div>
        </div>
      </div>



    </div>
    </div>
  </div>

 



</div>



</div>
</div>
      <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script type="text/javascript" src="<?= base_url() ?>assets/admin/js/bootstrap.min.js"></script>
      

<!--  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />-->
  <script src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
  <script src="https://cdn.datatables.net/1.10.15/js/dataTables.bootstrap.min.js"></script>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/css/bootstrap-datepicker.css" />
  <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/js/bootstrap-datepicker.js"></script>
<!--  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>-->

</div>
  <?php $this->load->view('footer.php'); ?>



    <script>
        function exportdate(min,max){
            $("#datefrom").val(min);
             $("#dateto").val(max);
            
        }
    </script>
<script>
    $(function() {
  $("#filterprofit").on("change", function() {
     
    $(".filtervalue").text($("#filterprofit").val());
     
      
     
         profit($("#filterprofit").val());  
     
  }).trigger("change");
      
});
    </script>
 
    <script>
    $(function() {
  $(".expense").on("change", function() {
    $(".expenseweak").text($(".expense").val());
       expensedash($(".expense").val());
  }).trigger("change");
       
});
        
    </script>
    <script>
          $(function() {
  $(".netexpense").on("change", function() {
    $(".netexpenseweak").text($(".netexpense").val());
       netexpensedash($(".netexpense").val());
  }).trigger("change");
       
});
    </script>
    <script>
        function profit(value){
           
            if(value=='Custom Search'){
              $("#myFilter").fadeIn('slow');  
            }
  else{
      $("#myFilter").fadeOut('slow');
             $.ajax({
             url: "<?php echo base_url()?>sale/profit", 
            type: "POST",
            data    : {'uristring':value},
                 dataType: 'json',
                   success: function(data){
                 $(".income").text((data.netincome).toLocaleString(undefined, {minimumFractionDigits: 2}) +' €');
                $(".purchases").text((data.purchases).toLocaleString(undefined, {minimumFractionDigits: 2})+' €');
                $(".sale").text((data.sale).toLocaleString(undefined, {minimumFractionDigits: 2}) +' €');
                $(".paid").text((data.paid).toLocaleString(undefined, {minimumFractionDigits: 2}) +' €');
     // $("#checkboxarea").html(data.html);
                
            }
        });
        }
        }
    </script>
       <script>
        function expensedash(expenseweak){
           if(expenseweak=='Custom Search'){
               
              $("#expensemyFilter").fadeIn('slow');  
            }
  else{
      $("#expensemyFilter").fadeOut('slow');
              $.ajax({
                  url: "<?php echo base_url()?>sale/expense", 
            type: "POST",
            data    : {'uristring':expenseweak},
                 dataType: 'json',
            success: function(data){
                 $(".total_expenseweak").text((data.netincome).toLocaleString(undefined, {minimumFractionDigits: 2}) +' €');
                        $(".last_expenseweak").text((data.expense).toLocaleString(undefined, {minimumFractionDigits: 2}) +' €');
                $(".emp_expenseweak").text((data.worker).toLocaleString(undefined, {minimumFractionDigits: 2}) +' €');
                          //$(".emp_expenseweek").text(data.netincome +' €');
                       // $(".purchases").text(data.purchases +' €');
                //$(".sale").text(data.sale +' €');
     // $("#checkboxarea").html(data.html);
                
            }
        });
  }
        }
    </script>
     <script>
        function netexpensedash(expenseweak){
           if(expenseweak=='Custom Search'){
               
              $("#netexpensemyFilter").fadeIn('slow');  
            }
  else{
      $("#netexpensemyFilter").fadeOut('slow');
              $.ajax({
                  url: "<?php echo base_url()?>sale/netexpense", 
            type: "POST",
            data    : {'uristring':expenseweak},
                 dataType: 'json',
            success: function(data){
                 $(".nettotal_expenseweak").text((data.netincome).toLocaleString(undefined, {minimumFractionDigits: 2}) +' €');
                        $(".netlast_expenseweak").text((data.totalexpense).toLocaleString(undefined, {minimumFractionDigits: 2}) +' €');
                $(".netemp_expenseweak").text((data.totalsale).toLocaleString(undefined, {minimumFractionDigits: 2}) +' €');
                          //$(".emp_expenseweek").text(data.netincome +' €');
                       // $(".purchases").text(data.purchases +' €');
                //$(".sale").text(data.sale +' €');
     // $("#checkboxarea").html(data.html);
                
            }
        });
  }
        }
    </script>
     <script>
        function expensefiltercustom(){
          var from=  $(".expensefilterdatefrom").val();
             var to=  $(".expensefilterdateto").val();
            $.ajax({
                  url: "<?php echo base_url()?>sale/expense", 
            type: "POST",
            data    : {'from':from,'to':to},
                 dataType: 'json',
            success: function(data){
                
                 $(".total_expenseweak").text((data.netincome).toLocaleString(undefined, {minimumFractionDigits: 2}) +' €');
                        $(".last_expenseweak").text((data.expense).toLocaleString(undefined, {minimumFractionDigits: 2}) +' €');
                $(".emp_expenseweak").text((data.worker).toLocaleString(undefined, {minimumFractionDigits: 2}) +' €'); 
            }
        });
        }
    </script>
    <script>
        function netexpensefiltercustom(){
          var from=  $(".netexpensefilterdatefrom").val();
             var to=  $(".netexpensefilterdateto").val();
            $.ajax({
                  url: "<?php echo base_url()?>sale/netexpense", 
            type: "POST",
            data    : {'from':from,'to':to},
                 dataType: 'json',
            success: function(data){
                
                 $(".nettotal_expenseweak").text((data.netincome).toLocaleString(undefined, {minimumFractionDigits: 2}) +' €');
                        $(".netlast_expenseweak").text((data.totalexpense).toLocaleString(undefined, {minimumFractionDigits: 2}) +' €');
                $(".netemp_expenseweak").text((data.totalsale).toLocaleString(undefined, {minimumFractionDigits: 2}) +' €'); 
            }
        });
        }
    </script>
    <script>
        function filtercustom(){
          var from=  $(".filterdatefrom").val();
             var to=  $(".filterdateto").val();
            $.ajax({
                  url: "<?php echo base_url()?>sale/profit", 
            type: "POST",
            data    : {'from':from,'to':to},
                 dataType: 'json',
            success: function(data){
                
                $(".income").text((data.netincome).toLocaleString(undefined, {minimumFractionDigits: 2}) +' €');
                $(".purchases").text((data.purchases).toLocaleString(undefined, {minimumFractionDigits: 2}) +' €');
                $(".sale").text((data.sale).toLocaleString(undefined, {minimumFractionDigits: 2}) +' €'); 
            }
        });
        }
    </script>

   
      <script>
        function page(value){
    
    $('#pagelimit').val(value);
       $.ajax({
              url: "<?php echo base_url()?>user/pagelimit",
            type: "POST",
            data    : {'limit':value},
                 dataType: 'json',
            success: function(data){
             $('#pagevalue').val(data.limit);
            }
        });
}

    </script>
            <script>
        
   var st = $('.tabfilterprofit');

st.change(function(){
 var text=($(this).val());
   
   $(".tabfiltervalue").text(text);
   tabprofit(text);
});
      
            </script>
            <script>
        function tabprofit(value){
        
                var id = $('#tabbank').val();
           
           $.ajax({
              url: "<?php echo base_url()?>user/dashtabfilter",
            type: "POST",
            data    : {'text':value,'tabid':id,},
                 dataType: 'json',
            success: function(data){
                
                $(".totalprofit").text((data.totalprofit).toLocaleString(undefined, {minimumFractionDigits: 2}) +' €');
                $(".totaldebit").text((data.totaldebit).toLocaleString(undefined, {minimumFractionDigits: 2}) +' €');
                $(".totalcradit").text((data.totalcradit).toLocaleString(undefined, {minimumFractionDigits: 2}) +' €');
            }
        });
            
        }
        $('.p-btn.search').on('click', function(){
  $('.dash-tab .dataTables_filter').slideToggle('fast');
});
    </script>
    <script>
       $( ".panelshowhide" ).click(function() {
           $( '#panelOne').toggleClass( "active" );
           $( "#collapseOne" ).slideToggle( "slow" );
          });
    </script>
       <script>
       $(".yearManufactured").on("change", function() {
           var year=$(this).val();
            $.ajax({
              url: "<?php echo base_url()?>user/yearfilter",
            type: "POST",
            data    : {'year':year},
             dataType: 'json',
            success: function(data){
               // var obj = $.parseJSON( data );
                $.each(data, function( index, value ) {
                    if(value['signal']){
                       $('.'+value['label']+'').addClass('redsignal');
                       }
                    else{
                        
                      $('.'+value['label']+'').removeClass('redsignal');  
                    }
                   $('.sale'+value['label']).text(value['sale']+' €');
                    $('.pur'+value['label']).text(value['purchases']+' €');
                    $('.paid'+value['label']).text(value['paid']+' €');
                });
             
            }
        });
          });
    </script>
    
<style>
.table{
  width: 61%; 
}
.dataTables_filter{
width: 20%;
margin-left: -106px;
}
.text-reportcon{
    padding-left: 17px;
    padding-top: 10px;   
}
</style>
</body>

</html>
