<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<?php 
//print_r($categories);die();
?>
<div class="box">
    <div class="box-header">
        <h2 class="blue"><i class="fa-fw fa fa-plus"></i><?= lang('add_transaction') ?></h2>
    </div>
    <div class="box-content">
        <div class="row">
            <div class="col-lg-12">
			<?php 
                $attrib = array('data-toggle' => 'validator', 'role' => 'form');
                echo admin_form_open_multipart("transaction/save", $attrib)
                ?>

                <div class="col-md-5">
					<div class="form-group">
                        <?= lang("transaction_type", "type") ?>
						<?php
                        $opty = array('types'  =>'Select Type','income' => lang('income'), 'expense' => lang('expense'),'customer_deposit' => lang('customer_deposit'), 'supplier_deposit' => lang('supplier_deposit'));
                        echo form_dropdown('type', $opty, (isset($_POST['type']) ? $_POST['type'] :""), 'class="form-control" id="type"  required="required"');
                        ?>
						
                    </div>
                   <div id="inc">
                    <div class="form-group">
                                    <?= lang("warehouse", "powarehouse"); ?>
                                    <?php
                                    $wh[''] = '';
                                    foreach ($warehouses as $warehouse) {
                                        $wh[$warehouse->id] = $warehouse->name;
                                    }
                                    echo form_dropdown('warehouse', $wh, (isset($_POST['warehouse']) ? $_POST['warehouse'] : $Settings->default_warehouse), 'id="powarehouse" class="form-control input-tip select" data-placeholder="' . lang("select") . ' ' . lang("warehouse") . '" required="required" style="width:100%;" ');
                                    ?>
                                </div>
					<div class="form-group">
                            <?= lang("description", "description"); ?>
                        <?php echo form_textarea('description', (isset($_POST['description']) ? $_POST['description'] : ""), 'class="form-control" id="description" style="margin-top: 10px; height: 100px;" '); ?>
					</div>
					<div class="form-group">
					
					
                        <?= lang("Account", "Account") ?> <b>*</b>
                       <select name="Account" class="form-control tip">
  <optgroup label="Cash and Bank">
  <?php if($account){ 
                    foreach ($account as $acct) {
						if($acct->type == 5){
						?>
						 <option value="<?=$acct->id;?>"><?= $acct->Name;?></option>
                       <?php 
						}
                    }
                } ?>
   </optgroup>
  <optgroup label="Business Owner Contribution">
     <?php  if($accounts){
                    foreach ($accounts as $accts) {
						
						if($accts->type == 17){
						?>
						 <option value="<?=$accts->id;?>"><?= $accts->Name;?></option>
                       <?php 
						}
                    }
                } ?>
  </optgroup>  
</select>
					 </div>
					  <div class="form-group">
                                    <?= lang("date", "date"); ?>
                                    <?php echo form_input('datee', (isset($_POST['date']) ? $_POST['date'] : ""), 'class="form-control input-tip datetime" '); ?>
                     </div>
                     
                      <div class="form-group">
                                    <?= lang("Payment entry date", "payment entry date"); ?>
                                    <?php echo form_input('datee_inc', (isset($_POST['date']) ? $_POST['date'] : ""), 'class="form-control input-tip datetime" '); ?>
                     </div>
                     
                     <div class="form-group">
                            <?= lang("Voucher Number", "voucher"); ?>
                        <?php echo form_input('voucher', (isset($_POST['voucher']) ? $_POST['voucher'] : ""), 'class="form-control tip"'); ?>
					</div>
                     
					<div class="form-group all">
                        <?= lang("amount", "amount") ?> 
                        <?= form_input('amounts', (isset($_POST['amount']) ? $_POST['amount'] : ""), 'class="form-control tip" ') ?>
                    </div>
				
 <div class="form-group">
                         <?= lang('category', 'category'); ?>
						
                <select  name="category" class="form-control tip">
  <optgroup label="Asset">
  <?php  if ($categories) {
                    foreach ($categories as $category) {
						if($category->account_category == 2){
						?>
						 <option value="<?=$category->id;?>"><?= $category->Name;?></option>
                       <?php 
						}
                    }
                } ?>
   </optgroup>
  <optgroup label="Liabilities">
    <?php  if ($categories) {
                    foreach ($categories as $category) {
						if($category->account_category == 3){
						?>
						 <option value="<?=$category->id;?>"><?= $category->Name;?></option>
                       <?php 
						}
                    }
                } ?>
  </optgroup>
  <optgroup label="Income">
  <?php  if ($categories) {
                    foreach ($categories as $category) {
						if($category->account_category == 4){
						?>
						 <option value="<?=$category->id;?>"><?= $category->Name;?></option>
                       <?php 
						}
                    }
                } ?>
   </optgroup>
  <optgroup label="Equity">
    <?php  if ($categories) {
                    foreach ($categories as $category) {
						if($category->account_category == 6){
						?>
						 <option value="<?=$category->id;?>"><?= $category->Name;?></option>
                       <?php 
						}
                    }
                } ?>
  </optgroup>
</select>
             </div>
			 
			 
					<div class="form-group">
                        <?= lang("deposit/withdrawal", "deposit/withdrawal") ?>
						<?php
                       // $opty = array(''  =>'Select Type','deposit' => lang('deposit'), 'withdrawal' => lang('withdrawal'));
                       // echo form_dropdown('deposit/withdrawal', $opty, (isset($_POST['deposit/withdrawal']) ? $_POST['deposit/withdrawal'] :""), 'class="form-control"   required="required"');
					   ?>
						 <?= form_input('deposit/withdrawal', (isset($_POST['deposit/withdrawal']) ? $_POST['deposit/withdrawal'] : ""), 'class="form-control tip" id="deposit" required="required" readonly') ?>
                    </div>
					
					
					<div class="row" id="bt">
                           
					<div class="col-md-12">
                        <div class="form-group">
                            <?= lang("note", "note"); ?>
                        <?php echo form_textarea('notee', (isset($_POST['note']) ? $_POST['note'] : ""), 'class="form-control"  style="margin-top: 10px; height: 100px;" '); ?>
						</div>
                    </div>
					</div>
					</div>
					 <div id="expen">
                    <div class="form-group">
                                    <?= lang("warehouse", "powarehouse"); ?>
                                    <?php
                                    $wh[''] = '';
                                    foreach ($warehouses as $warehouse) {
                                        $wh[$warehouse->id] = $warehouse->name;
                                    }
                                    echo form_dropdown('warehouse', $wh, (isset($_POST['warehouse']) ? $_POST['warehouse'] : $Settings->default_warehouse), 'id="powarehouse" class="form-control input-tip select" data-placeholder="' . lang("select") . ' ' . lang("warehouse") . '" required="required" style="width:100%;" ');
                                    ?>
                                </div>
					<div class="form-group">
                            <?= lang("description", "description"); ?>
                        <?php echo form_textarea('description', (isset($_POST['description']) ? $_POST['description'] : ""), 'class="form-control" id="description" style="margin-top: 10px; height: 100px;" '); ?>
					</div>
					<div class="form-group">
					
					
                        <?= lang("Account", "Account") ?> <b>*</b>
                       <select name="Account" class="form-control tip">
  <optgroup label="Cash and Bank">
  <?php if($account){ 
                    foreach ($account as $account) {
						if($account->type == 5){
						?>
						 <option value="<?=$account->id;?>"><?= $account->Name;?></option>
                       <?php 
						}
                    }
                } ?>
   </optgroup>
  <optgroup label="Business Owner Contribution">
     <?php  if($accounts){
                    foreach ($accounts as $accounts) {
						
						if($accounts->type == 17){
						?>
						 <option value="<?=$accounts->id;?>"><?= $accounts->Name;?></option>
                       <?php 
						}
                    }
                } ?>
  </optgroup>  
</select>
					 </div>
					  <div class="form-group">
                                    <?= lang("date", "date"); ?>
                                    <?php echo form_input('dates', (isset($_POST['date']) ? $_POST['date'] : ""), 'class="form-control input-tip datetime" '); ?>
                     </div>
                     
                     
                      <div class="form-group">
                                    <?= lang("Payment entry date", "payment entry date"); ?>
                                    <?php echo form_input('dates_exp', (isset($_POST['date']) ? $_POST['date'] : ""), 'class="form-control input-tip datetime" '); ?>
                     </div>
                     
                     <div class="form-group">
                            <?= lang("Voucher Number", "voucher"); ?>
                        <?php echo form_input('voucher_exp', (isset($_POST['voucher']) ? $_POST['voucher'] : ""), 'class="form-control tip"'); ?>
					</div>
                     
					<div class="form-group all">
                        <?= lang("amount", "amount") ?> 
                        <?= form_input('amoun', (isset($_POST['amount']) ? $_POST['amount'] : ""), 'class="form-control tip"  ') ?>
                    </div>
				    	<div class="form-group all">
                        <?= lang("VAT", "VAT") ?> 
                        <?= form_input('vat', (isset($_POST['vat']) ? $_POST['vat'] : ""), 'class="form-control"  ') ?>
                    </div>
			 
					 <div class="form-group">
                         <?= lang('category', 'category'); ?>
						
                <select  name="cate" class="form-control tip">
  <optgroup label="Asset">
  <?php  if ($categor) {
                    foreach ($categor as $category) {
						if($category->account_category == 2){
						?>
						 <option value="<?=$category->id;?>"><?= $category->Name;?></option>
                       <?php 
						}
                    }
                } ?>
   </optgroup>
  <optgroup label="Liabilities">
    <?php  if ($categor) {
                    foreach ($categor as $category) {
						if($category->account_category == 3){
						?>
						 <option value="<?=$category->id;?>"><?= $category->Name;?></option>
                       <?php 
						}
                    }
                } ?>
  </optgroup>
  <optgroup label="Expense">
  <?php  if ($categor) {
                    foreach ($categor as $category) {
						if($category->account_category == 5){
						?>
						 <option value="<?=$category->id;?>"><?= $category->Name;?></option>
                       <?php 
						}
                    }
                } ?>
   </optgroup>
  <optgroup label="Equity">
    <?php  if ($categor) {
                    foreach ($categor as $category) {
						if($category->account_category == 6){
						?>
						 <option value="<?=$category->id;?>"><?= $category->Name;?></option>
                       <?php 
						}
                    }
                } ?>
  </optgroup>
</select>
             </div>
			 <div class="form-group">
                        <?= lang("deposit/withdrawal", "deposit/withdrawal") ?>
						<?php
                       // $opty = array(''  =>'Select Type','deposit' => lang('deposit'), 'withdrawal' => lang('withdrawal'));
                       // echo form_dropdown('deposit/withdrawal', $opty, (isset($_POST['deposit/withdrawal']) ? $_POST['deposit/withdrawal'] :""), 'class="form-control"   required="required"');
					   ?>
						 <?= form_input('deposit/withdrawal', (isset($_POST['deposit/withdrawal']) ? $_POST['deposit/withdrawal'] : ""), 'class="form-control tip" id="withdrawal" required="required" readonly') ?>
                    </div>
					
					<div class="row" id="bt">
                           
					<div class="col-md-12">
                        <div class="form-group">
                            <?= lang("note", "note"); ?>
                        <?php echo form_textarea('noted', (isset($_POST['note']) ? $_POST['note'] : ""), 'class="form-control"  style="margin-top: 10px; height: 100px;" '); ?>
						</div>
                    </div>
					</div>
					</div>
					<div id="depos">
                        
                       
                    <div class="form-group">
                        <?php echo lang('date', 'date'); ?>
                        <div class="controls">
                            <?php echo form_input('date', set_value('date', date($dateFormats['php_ldate'])), 'class="form-control datetime" '); ?>
                        </div>
                    </div>
                    
                    <div class="form-group">
                        <?php echo lang('Payment entry date', 'cust_date'); ?>
                        <div class="controls">
                            <?php echo form_input('cust_date', set_value('cust_date', date($dateFormats['php_ldate'])), 'class="form-control datetime" '); ?>
                        </div>
                    </div>
                    
                    <div class="form-group">
                            <?= lang("Voucher Number", "voucher"); ?>
                        <?php echo form_input('voucher_cust', (isset($_POST['voucher']) ? $_POST['voucher'] : ""), 'class="form-control tip"'); ?>
						</div>
                    
                    <div class="form-group">
                        <?= lang("customer", "customer"); ?>
                        <?php
                        $list[''] = "";
                        foreach ($customerlist as $customer) {//print_r($customer);
                            $list[$customer->id] = $customer->company;
                        }//rint_r($list);
                        echo form_dropdown('customer', $list, (isset($_POST['customer']) ? $_POST['customer'] : ''), 'class="form-control select"  placeholder="' . lang("select") . " " . lang("customer") . '" required="required" style="width:100%"')
                        ?>
                    </div>
                    
                    <div class="form-group">
                        <h2>Category</h2>
                        <?php
                        $listall[''] = "";
                        foreach ($categories_list as $cat) {//print_r($customer);
                            $listall[$cat->id] = $cat->name;
                        }//rint_r($list);
                        echo form_dropdown('category_id', $listall, (isset($_POST['category_id']) ? $_POST['category_id'] : ''), 'class="form-control select"  placeholder="' . lang("select") . " " . lang("category") . '"  style="width:100%"')
                        ?>
                    </div>
                    
                    	<div class="form-group">
                        <?= lang("type", "type") ?>
						<?php
                        $opty = array('types'  =>'Select Type','deposit' => lang('Deposit'), 'OpeningBalance' => lang('Opening Balance'));
                        echo form_dropdown('cust_type', $opty, (isset($_POST['cust_type']) ? $_POST['cust_type'] :""), 'class="form-control" id="cust_type"  required="required"');
                        ?>
						
                    </div>
                    <div class="form-group">
                        <?php echo lang('amount', 'amount'); ?>
                        <div class="controls">
                            <?php echo form_input('amouns', '', 'class="form-control" '); ?>
                        </div>
                    </div>

                    <div class="form-group">
                        <?php echo lang('Paid_by', 'paid_by'); ?>
                        <div class="controls">
                            <?php echo form_input('paided_by','', 'class="form-control" id="paid_by"'); ?>
                        </div>
                    </div>

                    <div class="form-group">
                        <?php echo lang('note', 'note'); ?>
                        <div class="controls">
                            <?php echo form_textarea('noter', '', 'class="form-control" id="note"'); ?>
                        </div>
                    </div>
				
                </div>
						<div id="suppl">
                        
                    <div class="form-group">
                        <h2>Category</h2>
                        <?php
                        $listall[''] = "";
                        foreach ($categories_list as $cat) {//print_r($customer);
                            $listall[$cat->id] = $cat->name;
                        }//rint_r($list);
                        echo form_dropdown('id', $listall, (isset($_POST['id']) ? $_POST['id'] : ''), 'class="form-control select"  placeholder="' . lang("select") . " " . lang("category") . '" required="required" style="width:100%"')
                        ?>
                    </div>
                    
                    <div class="form-group">
                        <?php echo lang('date', 'date'); ?>
                        <div class="controls">
                            <?php echo form_input('date', set_value('date', date($dateFormats['php_ldate'])), 'class="form-control datetime" '); ?>
                        </div>
                    </div>
                    
                     <div class="form-group">
                        <?php echo lang('Payment entry date', 'sup_date'); ?>
                        <div class="controls">
                            <?php echo form_input('sup_date', set_value('sup_date', date($dateFormats['php_ldate'])), 'class="form-control datetime" '); ?>
                        </div>
                    </div>
                    <div class="form-group">
                            <?= lang("Voucher Number", "voucher"); ?>
                        <?php echo form_input('voucher_sup', (isset($_POST['voucher']) ? $_POST['voucher'] : ""), 'class="form-control tip"'); ?>
				    </div>
                    
                    <div class="form-group">
                        <?= lang("supplier", "supplier"); ?>
                        <?php
                        $lists[''] = "";
                        foreach ($suppllist as $supp) {//print_r($customer);
                            $lists[$supp->id] = $supp->name;
                        }//rint_r($list);
                        echo form_dropdown('supplier', $lists, (isset($_POST['supplier']) ? $_POST['supplier'] : ''), 'class="form-control select"  placeholder="' . lang("select") . " " . lang("supplier") . '" required="required" style="width:100%"')
                        ?>
                    </div>

                    <div class="form-group">
                        <?php echo lang('amount', 'amount'); ?>
                        <div class="controls">
                            <?php echo form_input('amounted', set_value('amount'), 'class="form-control" '); ?>
                        </div>
                    </div>

                    <div class="form-group">
                        <?php echo lang('Paid_by', 'paid_by'); ?>
                        <div class="controls">
                            <?php echo form_input('paid_by', set_value('paid_by'), 'class="form-control" id="paid_by"'); ?>
                        </div>
                    </div>

                    <div class="form-group">
                        <?php echo lang('note', 'note'); ?>
                        <div class="controls">
                            <?php echo form_textarea('notes', set_value('note'), 'class="form-control" id="note"'); ?>
                        </div>
                    </div>
				
                </div>
					
					<div class="form-group">
                        <?php echo form_submit('save_transaction', $this->lang->line("save_transaction"), 'class="btn btn-primary"'); ?>
                    </div>
                    
            
                    </div>
				</div>
				
                <input type="hidden" name="test" id="test">
            <?= form_close(); ?>

            </div>

        </div>
    </div>

<script type="text/javascript"> 
  $(document).ready(function () {
	$('#type').change(function () {
            var t = $(this).val();
            if (t !== 'deposit') {
                $('.deposit').slideUp();
                $('#account').iCheck('uncheck');
				$('#method').slideUp();
				
            } else {
                $('.deposit').slideDown();
                $('#account').iCheck('check');
               
				
            }
            if (t !== 'account_transfer') {
                $('.account_transfer').slideUp();
             
			} else {
                $('.account_transfer').slideDown();
               
				$('#promo').slideDown();
			}
			if (t !== 'accounts_receivable' && t !== 'accounts_payable') {
               $('#method').slideDown();
			}
		});

       });
</script>
<script type="text/javascript">

document.addEventListener('DOMContentLoaded', function() {
     $("#expen").hide(); 
          $("#depos").hide();
          $("#inc").hide();
            $("#suppl").hide();
}, false);
$(document).ready(function(){
 
    $('#type').on('change', function() {
         var doc = document.getElementById("type").value;
       
      if ( doc == 'income')
      {
         var result ='deposit';
		document.getElementById("deposit").value = result;
        $("#inc").show();
         $("#depos").hide();
          $("#expen").hide();
           $("#suppl").hide();
      }
       if ( doc == 'expense')
      {
          var result ='withdrawal';
			document.getElementById("withdrawal").value = result;
        $("#expen").show();
         $("#depos").hide();
          $("#inc").hide();
           $("#suppl").hide();
      }
        if ( doc == 'customer_deposit')
      {
        $("#expen").hide();
         $("#depos").show();
          $("#inc").hide();
           $("#suppl").hide();
      }
       if ( doc == 'supplier_deposit')
      {
        $("#expen").hide();
         $("#depos").hide();
          $("#inc").hide();
           $("#suppl").show();
      }
      document.getElementById("test").value = doc;
    });
});

</script>
<script type="text/javascript">
$(document).ready(function () {
    $('#category').change(function () {
        //var doc = document.getElementById("type").value;
        //alert("You selected " + doc.options[doc.selectedIndex].value);
		//alert(sum);
		var sum = document.getElementById("category").value;
		alert(sum);
		
		
		
    });
});

</script>
