<?php
$acedemic_session='';
$particulars='';
$account_head_type='';
$date='';
$amount='';
$description='';
$record_id='';
$attachment="";
$title='';
if($id){
    // echo $id;
    $table='accounts_ledger ';
    $get_record_data=$this->AccountsModel->get_item_data($id,$table);
    if($get_record_data){
        foreach($get_record_data as $record_data){
            $record_id=$record_data['id'];
            $acedemic_session=$record_data['acedemic_session'];
            $particulars=$record_data['particulars_id'];
            $account_head_type=$record_data['type'];
            $date=$record_data['date'];
            $amount=$record_data['amount'];
            $description=$record_data['description'];
            $attachment=$record_data['attachment'];
        }
    }
    $title='Update Record';
}else{
    $title='Add New Record';
}

?>



<script src="https://cdn.ckeditor.com/4.11.1/standard/ckeditor.js"></script>

<!--<script src="//cdn.ckeditor.com/4.11.1/standard/ckeditor.js"></script>-->
<div class="container-fluid bg-white">
    <div class="row">
        <div class="col-sm-12 pt-3 pb-3">
            <ul class="breadcrumb">
                <li class="breadcrumb-item"><a href="<?php echo base_url(); ?>Welcome">Home</a></li>
                <li class="breadcrumb-item"><a href="<?php echo base_url(); ?>Accounts">Accounts</a></li>
                <li class="breadcrumb-item">Account Heads</li>
            </ul>
            
            <form method="post" action="#" class="form-outer" enctype="multipart/form-data">
                <div class="w-100">
                <h1 class="main-heading text-center"><?php echo $title; ?></h1><hr>
                <?php 
                if($success){
                ?>
                <div class="alert alert-success"><?php echo $success; ?></div>
                <?php
                }
                if($error){
                ?>
                <div class="alert alert-danger"><?php echo $error; ?></div>
                <?php
                }
                ?>
                <div class="form-group w-50">
                    <label>Acedemic Session</label>
                    <input type="hidden" name="record_id" value="<?php echo $record_id; ?>">
                    <select class="form-control" name="acedemic_session" required>
                        <?php
                        $acedemic_session_table='academic_session_details';
                        $all_acedemic_sessions=$this->AccountsModel->get_active_data($acedemic_session_table);
                        if($all_acedemic_sessions){
                            foreach($all_acedemic_sessions as $acedemic_session_data){
                        ?>
                        <option value="<?php echo $acedemic_session_data['id']; ?>"><?php echo $acedemic_session_data['year_long']; ?></option>
                        <?php
                            }
                        }
                        ?>
                    </select>
                </div>
                <div class="form-group w-50">
                    <label>Particulars</label>
                    <select class="form-control" name="particulars" required>
                        <option value="">-- Select Account Head --</option>
                        <?php
                        $table='account_heads';
                        $all_particulars=$this->AccountsModel->get_active_data($table);
                        if($all_particulars){
                            foreach($all_particulars as $data){
                        ?>
                        <option value="<?php echo $data['id']; ?>" <?php if($particulars == $data['id'] ){ echo "selected"; } ?>><?php echo $data['head']; ?></option>
                        <?php
                            }
                        }
                        ?>
                    </select>
                </div>
                
                <div class="form-group w-50">
                    <label>Record Type</label>
                    <select class="form-control" name="account_head_type">
                        <option value="debit" <?php if($account_head_type == "debit"){ echo "selected"; }?>>Debit</option>
                        <option value="credit" <?php if($account_head_type == "credit"){ echo "selected"; }?>>Credit</option>    
                    </select>
                </div>
                <div class="form-group w-50">
                    <label>Date</label>
                    <input type="date" name="date" class="form-control" value="<?php if($date){ echo $date; }  ?>">
                </div>
                <div class="form-group w-50">
                    <label>Amount</label>
                    <input type="number" class="form-control" name="amount" placeholder="Amount" step="any" value="<?php echo $amount; ?>">
                </div>
                <div class="form-group w-50">
                    <label>Attachment</label>
                    <input type="file" class="form-control" name="attachment" >
                    <input type="hidden" name="attachment_old" value="<?php echo $attachment; ?>">
                </div>
                <div class="form-group w-100">
                    <label>Description</label>
                    <!--<input type="text" name="description" class="form-control  " placeholder="Description">-->
                    <textarea name="description" placeholder="Description" class="ckeditor form-control"><?php if($description){ echo $description; } ?></textarea>
                </div>
                <div class="form-group w-50">
                    <button type="submit" name="add_new_record" class="btn btn-sm btn-success"><?php echo $title; ?></button>
                </div>
                
                </div>
            </form>
            
            
        </div>
    </div>
</div>
