
@extends('adminlte::page')
 
 @section('content')
 <?php Fun::lang()?>
    <div class="title-page">
        <div class="page-bar">
            <ul class="page-breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> Dashboard</a></li>
              <li><a href="#">Report Accounting</a></li>
              <li><a href="#">Report Income Statment</a></li>
            </ul>
        </div>
    </div>
 <div class="page">
     <div class="top-content">
          <div class="row">
              <div class="col-sm-12 col-xs-12">
                  <div class="title-add">
                    <div class="pull-left">
                        <h3>Report Income Statment</h3>
                    </div>
                </div>
              </div>
          </div>
      </div>
              <form action="#" method="POST">
                  <div class="form-search">
                    <div class="row">
                      <div class="col-xs-12 col-sm-6 col-md-6">
                        <div class="form-group">
                          <strong>Start Date</strong>
                          {!! Form::text('start_date', date("Y-m-d",strtotime("first day of this month")), array('placeholder' => 'Start Date','class' => 'form-control date_picker start_date','autocomplete' => 'off')) !!}
                        </div>
                      </div>
                      <div class="col-xs-12 col-sm-6 col-md-6">
                        <div class="form-group">
                          <strong>End Date</strong>
                          {!! Form::text('end_date', date("Y-m-d",strtotime("last day of this month")), array('placeholder' => 'End Date','class' => 'form-control date_picker end_date','autocomplete' => 'off')) !!}
                        </div>
                      </div>
                      
                    <div class="col-xs-12 col-sm-12 col-md-12 text-right">
                        <button type="button" class="button_primary btn-sm search" onclick="searching()"><span class="fa fa-search"> Search</span></button>
                  </div>
                </div>
              </div>
            {!! Form::close() !!}
     


     <div class="page-wrapper">
        <div class="row">
            <div class="col-md-12">
                <div class="portlet light bordered">
                    <div class="portlet-body" style="font-size:30px">
                        <div class="print">
                            <div align="center" style="font-size: 16px;text-decoration: underline;color: #06F;font-weight: bold;">Report Income Statement</div>
                            <ul>
                                <ul>
                                    <li style="color:#3914AF;font-weight: bold;font-size:16px">Sale Revenues</li>
                                    <ul class="income">
                                        @foreach($incomes as $value)
                                        <li style="font-weight: bold;font-size:16px">
                                            <span>{{$value->journal_acccode}} {{$value->acc_name}}</span>
                                            <span style="float: right;padding-right: 49%;">${{$value->income}}</span>
                                        </li>
                                        @endforeach()
                                    </ul>
                                </ul>
                                <br>
                                <ul>
                                    <li style="color:#3914AF;font-weight: bold;font-size:16px">Expense</li>
                                    <ul class="expense">
                                        @foreach($expenses as $value)
                                        <li style="font-weight: bold;font-size:16px">
                                            <span>{{$value->journal_acccode}} {{$value->acc_name}}</span>
                                            <span style="float: right;padding-right: 49%;">${{$value->expense}}</span>
                                        </li>
                                        @endforeach()
                                    </ul>
                                </ul>
                                <br>
                                <li style="color:red;font-weight: bold;">
                                    <span style="color:red;font-weight: bold;font-size:20px">Net Income</span>
                                    <span style="float: right;padding-right: 47%;font-weight: bold;font-size:20px" class="total">${{number_format($net_income,2)}}</span>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    </div>


@endsection


@section('js')
<script type="text/javascript" src="{{asset('assets/controller/income-satement.js')}}"></script>
<script type="text/javascript">

    function searching(){

        var start_date = $('.start_date').val();
        var end_date = $('.end_date').val();
        $('.income').empty();
        $('.expense').empty();
        $('.total').empty();
        var income ='';
        var expense ='';
        $.ajax({
            method:'POST',
            dataType:'json',
            url: '/realty/accouting-income-statement-search',
            async: false,
            data: {
                _token: "{{ csrf_token() }}",
                start_date: start_date,
                end_date: end_date,
            },
            success: function (response) { 
                $.each(response['income'], function (index, val) {  
                    income = `<li style="font-weight: bold;font-size:16px">
                                <span>${val.journal_acccode} ${val.acc_name}</span>
                                <span style="float: right;padding-right: 49%;">${val.income}</span>
                             </li>`;
                });
                $.each(response['expense'], function (index, val) {  
                    expense = `<li style="font-weight: bold;font-size:16px">
                                <span>${val.journal_acccode} ${val.acc_name}</span>
                                <span style="float: right;padding-right: 49%;">${val.expense}</span>
                             </li>`;
                });
                $('.income').append(income);
                $('.expense').append(expense);
                $('.total').html("$"+parseFloat(response.net_income).toFixed(2));
          },

        });
       
    }
</script>
@endsection

