<div class="modal-content">
   <div class="modal-header">
      <h4 class="modal-title">{{__('income.income-form.update-title')}}</h4>
   </div>
      <form class="simcy-form" action="{{ url('Income@update') }}" data-parsley-validate="" method="POST" loader="true">
   <div class="modal-body">
         <div class="form-group">
            <div class="row">
               <div class="col-md-12">
                  <label>{{__('income.income-form.label.title')}}</label>
                  <input type="text" class="form-control" name="title" value="{{$income->title}}" placeholder="{{__('income.income-form.placeholder.title')}}">
                  <input type="hidden" name="csrf-token" value="{{csrf_token()}}" />
                  <input type="hidden" name="incomeid" value="{{$income->id}}" />
               </div>
            </div>
         </div>
         <div class="form-group">
            <div class="row">
               <div class="col-md-12">
                  <label>{{__('income.income-form.label.amount')}}</label>
                  <span class="input-prefix">{{ currency() }}</span>
                  <input type="number" class="form-control prefix" value="{{$income->amount}}" name="amount" placeholder="{{__('income.income-form.placeholder.amount')}}">
               </div>
            </div>
         </div>
         <div class="form-group">
            <div class="row">
               <div class="col-md-12">
                  <label>{{__('income.income-form.label.account')}}</label>
                  <select class="form-control select2" name="account">
                     <option value="0" @if($income->account == '0') selected @endif>
                        {{__('income.income-form.account.other')}}</option>
                    @if(!empty($accounts))
                    @foreach($accounts as $account)
                     <option value="{{ $account->id }}" @if( $income->account == $account->id ) selected @endif>{{ $account->name }}</option>
                    @endforeach
                    @endif
                  </select>
               </div>
            </div>
         </div>
         <div class="form-group">
            <div class="row">
               <div class="col-md-12 ">
                  <label>{{__('income.income-form.label.category')}}</label>
                  <select class="form-control select2" name="category">
                     @if(!empty($incomecategories))
                           @foreach($incomecategories as $incomecategory)
                              <option value="{{ $incomecategory->id }}" @if($income->category == $incomecategory->id) selected @endif>{{ $incomecategory->name }} </option>
                           @endforeach
                     @endif
                     <option value="00" @if($income->category == '0') selected @endif>
                        {{__('income.income-form.group.other')}} </option>
                  </select>
               </div>
            </div>
         </div>
         <div class="form-group">
            <div class="row">
               <div class="col-md-12">
                  <label>{{__('income.income-form.label.date')}}</label>
                  <input type="text" class="form-control datepicker-dynamic" value="{{date('m/d/Y', strtotime($income->income_date))}}" name="income_date" placeholder="{{__('income.income-form.placeholder.date')}}">
               </div>
            </div>
         </div>
         <div class="form-group">
            <div class="row">
                <div class="col-md-12">
                    <label>{{__('income.income-form.label.note')}}</label>
                    <input type="text" class="form-control" name="note" value="{{ $income->note}}" placeholder="{{__('income.income-form.placeholder.note')}}">
                </div>
            </div>
        </div>
        @if ((env("ALLOW_ATTACHMENTS") == "Enabled") && empty($income->attachment))
        <div class="form-group">
            <div class="row">
                <div class="col-md-12">
                    <label>{{__('expenses.expense-form.label.attachment')}}</label> 
                    <div name="incomecroppie">
                        <input type="file" name="incomeimage_attachment" id="incomeimage_attachment" class="croppie" crop-width="800" crop-height="800" accept="image/*" onchange='incomeHideFileAttachment()'>
                    </div>
                <div name="incomefile_attachment_label">
                    {{__('income.income-form.label.pdf')}}</div>
                <input type="file" class="form-control" name="incomefile_attachment" id="incomefile_attachment"  accept="application/pdf" onchange='incomeHideCroppie()'>
                </div>
            </div>
            <button type="button" class="btn btn-danger btn-sm" name="incomeclearButton" onclick="incomeClearAttachment()" style="display: none">{{__('income.income-form.label.clear')}}</button>
        </div>
        @endif
   </div>
      <div class="modal-footer">
         <button type="button" class="btn btn-default" data-dismiss="modal">{{__('income.button.close')}}</button>
         <button type="submit" class="btn btn-primary">{{__('income.button.update-income')}}</button>
      </div>
   </form>
</div>
<script type="text/javascript">
   $('.datepicker-dynamic').datepicker({
          autoclose: true
      });
      
      croppify();
      
      function incomeHideCroppie() {
               $('[name=incomecroppie]').hide();
               $('[name=incomefile_attachment_label]').hide();
               $('[name=incomeclearButton]').show();
        }
        function incomeHideFileAttachment() {
               $('[name=incomefile_attachment]').hide();
               $('[name=incomefile_attachment_label]').hide();
               $('[name=incomeclearButton]').show();
        }

        function incomeClearAttachment() {

            $('[name=incomefile_attachment]').val('');
            $('[name=incomeimage_attachment]').val('');
            $('[name=incomecroppie]').show();
            $('[name=incomefile_attachment]').show();
            $('[name=incomefile_attachment_label]').show();
            $('[name=incomeclearButton]').hide();

            $('[name=incomeimage_attachment]').removeClass('ready');
            $('[name=incomeimage_attachment]').html("");

            $('[class=croppie-output]').attr("src","data:image/png;base64,[encoded data, 7000 characters]");
        }

</script>