
<script type="application/javascript">
			
$(document).ready(function() {
        $('select').select2();
         $.each($(".select2-container"), function (i, n) {
                    $(n).next().show().fadeTo(0, 0).height("0px").css("left", "auto"); // make the original select visible for validation engine and hidden for us
                    $(n).prepend($(n).next());
                    $(n).delay(500).queue(function () {
                        $(this).removeClass("validate[required]"); //remove the class name from select2 container(div), so that validation engine dose not validate it
                        $(this).dequeue();
                    });
                });	
        jQuery('.datepicker2').datepicker({
            dateFormat: 'dd-mm-yy',
            changeMonth: true,
            changeYear: true
        });

        $("table.editable").on("click", ".edit", function() {
            var eRow = $(this).parents('tr');
            var eState = $(this).attr('data-state');

            if (eState == null) {
                $(this).html('Save');
                eState = 1;
            }
            if (eState == 1)
                $(this).attr('data-state', '2');
            else {
                $(this).removeAttr('data-state');
                $(this).html('Edit');
            }
        });



    });



function refreshSupplier(){
            //<span style="color:#85c420;">'+modTxt+"</span>
  $.ajax({
    type: "POST",
    url: "<?php echo base_url() ?>supplier/refreshSupplier",
    success: function(data) {
    
       var resul = eval ("(" + data + ")"); 
               var n=resul.records.length;
               var i=0;
               var opt='' +
          '<option></option>';
                for (i=0;i<n;i++)
                  if(resul.records[i].gstRegNo != ''){
                    opt=opt + '<option value="' + resul.records[i].id + '">' + resul.records[i].supplierName + ' (GST)</option>';
                  }else{
                    opt=opt + '<option value="' + resul.records[i].id + '">' + resul.records[i].supplierName + '</option>';
                  }
      $('#supplier').empty();
              $('#supplier').append(opt);
    }
     });
   
}


function saveData(me){
	//var formNo =  $('#formNo').val();
	var historicalID =  me;
	var supplierID =  $('#supplier').val();
	var createdDate =  $('#createdDate').val();
	var suppInvoiceNo =  $('#supinvoicenumber').val();
	var amount =  accounting.unformat($('#amount').val());
	
	var postData = {
		//'formNo' : formNo,
		'historicalID' : historicalID,
		'suppID' : supplierID,
		'createdDate' : createdDate,
		'suppInvoiceNo' : suppInvoiceNo,
		'amount' : amount,
	};
	$.ajax({
		type: "POST",
		dataType: "json",
		url: "<?php echo base_url()?>historicalInvoice/saveHistoricalSuppInvoice",
		data: postData ,
		success: function(content){
			if(content.status == "success") {
				alert('Data successfully saved');
				window.location.href = "<?php echo base_url()?>historicalinvoice/historicalSupplierInvoice";
			}
		}
	});
	
}

function changeNumberFormat(){
	var changeAmount = accounting.formatNumber($('#amount').val(),2);
	$('#amount').val(changeAmount);
	
}
</script>

<div id="content"> 
    <div class="wrap">
        <div class="head">
            <div class="info">
                <!--<h1><?php echo element('compName', $this->session->userdata('logged_in')) ?> [ 
				<?php echo element('compNo', $this->session->userdata('logged_in')) ?> ]</h1>-->
                <ul class="breadcrumb">
                    <li><a href='<?php echo base_url() . "home" ?>'><?php echo $this->lang->line('dashboard') ?></a> <span class="divider">-</span></li>
                    <li><a href='<?php echo base_url() . "AccountPayables/home" ?>'> <?php echo $this->lang->line('module') ?></a> <span class="divider">-</span></li>
                    <li class="active"><?php echo $this->lang->line('cust') ?></li>
                </ul>
            </div>
            <div class="search">
                <form action="<?php echo base_url() ?>admin/search" method="post">
                    <input name="search_text" type="text" placeholder="search..."/>                                
                    <button type="submit"><span class="i-magnifier"></span></button>
                </form>
            </div> 
        </div><!-- head --> 
        <div class="content" id="grid_content_1">
            <form id="parchaseDetailForm" action="#">    
            <input type="hidden" value="null" id="purchaseInvoiceId" />
				<div class="block">
					<div class="head">
						<h2><?php echo $this->lang->line('titlelist') ?></h2>
						<!--<ul class="buttons">
							<li><a href="#" class="block_toggle"><span class="i-arrow-down-3"></span></a></li>
						</ul>-->
					</div><!-- head -->
					<div class="content">
						<div class="row-fluid scRow">                            
							<div class="span6 scCol">
								<div class="block ns" id="grid_block_1">
									
                                    <!--<div class="controls-row">
										<div class="span4"><?php //echo $this->lang->line('formNo') ?></div>
										<div class="span2">
											<input class="span12 validate[required]" id="formNo" name="formNo" value='<?php echo "$formNo"; ?>' 
												style="color:red;" type="text" placeholder="Form number ...">
										</div>
										<div class="span6">
											<input  class="span11"   type="text" id="invID" placeholder="Serial" disabled="disabled">
										</div>
									</div> <!-- row -->
                                    
									<div class="controls-row">
										<div class="span4"><?php echo $this->lang->line('suppName') ?></div>
										<div class="span8">
													<select class="span10 validate[required]" id="supplier">
                                                    <?php
														if($historicalSuppInvoice == ''){
                                                    		echo"<option>Please Select</option>";
														}
														else{
														?>
															<option value="<?php echo $historicalSuppInvoice->supplierID; ?>"> <?php echo $historicalSuppInvoice->supplierName; echo ($historicalSuppInvoice->gstRegNo != '' && $historicalSuppInvoice->gstRegNo != '0')?' (GST)':''; ?></option>
														<?php
                                                        }
													?>
                        							<?php
                        							if ($supplier != '') {
                        								foreach ($supplier as $row) {
                        								?>
															<option value="<?php echo $row->ID; ?>"> <?php echo $row->supplierName; echo ($row->gstRegNo != '' && $row->gstRegNo != '0')?' (GST)':''; ?></option>
														<?php
														}
													}
													?>
													</select>
													<div class="btn-group span1">
														<button class="btn-icon btn-small dropdown-toggle" data-toggle="dropdown">
															<span class="i-arrow-down-2"></span>
														</button>
														<ul class="dropdown-menu">
															<!-- dropdown menu links -->
															<li><a target="_blank" href="<?php echo base_url() ?>supplier/SupplierNew"  id="btnNewSupplier">
																<i class="i-plus-3"></i> <?php echo $this->lang->line('addNewSupplier') ?></a></li>
															<li><a href="#" onclick="refreshSupplier()" id="btnNewSupplier">
																<i class="i-ccw "></i><?php echo $this->lang->line('refreshlist') ?></a></li>
														</ul>
													</div>
										</div>
									</div> <!-- row -->
                                    
									<div class="controls-row">
										<div class="span4"><?php echo $this->lang->line('date') ?></div>
										<div class="span8">
											<div class="input-prepend span10"><span class="add-on span2"><i class="i-calendar"></i></span>
											<?php
											$data = array(
												'name' => 'createdDate',
												'id' => 'createdDate',
												'type' => 'text',
												'onkeydown' => 'return false',
												'class' => 'span10 datepicker2 validate[required] financhk',);
												if($historicalSuppInvoice->invoiceDate == ''){
													echo form_input($data, date("d-m-Y"));
												}
												else{
													echo form_input($data, date("d-m-Y", strtotime($historicalSuppInvoice->invoiceDate)));
												}
											?>
											</div>
										</div>
									</div> <!-- row -->
									
									                                
									<div class="controls-row">
										<div class="span4"><?php echo $this->lang->line('supplierInvoiceNo') ?></div>
										<div class="span8">
                                        <?php
											if($historicalSuppInvoice == ''){
												echo" <input id='supinvoicenumber' class='span10 validate[required]' type='text' placeholder='Supplier Invoice Number'>";
											}
											else{
												echo" <input id='supinvoicenumber' class='span10 validate[required]' type='text' value='".$historicalSuppInvoice->supplierInvoiceNo."'>";
											}
										?>
										</div><!-- span -->
									</div> <!-- row -->
                                    
                                    <div class="controls-row">
										<div class="span4"><?php echo $this->lang->line('amount') ?></div>
										<div class="span8">
                                        <?php
											if($historicalSuppInvoice == ''){
												echo"<input id='amount' class='span10 validate[required]' type='text' onblur='changeNumberFormat()'>";
											}
											else{
												echo"<input id='amount' class='span10 validate[required]' type='text' onblur='changeNumberFormat()' value='".number_format($historicalSuppInvoice->totalAmount,2)."'>";
											}
										?>
										</div><!-- span -->
									</div> <!-- row -->
                                    
								</div><!-- grid block 1-->
                            </div><!-- scCol -->
						</div><!-- row-fluid scRow-->
					</div><!-- content np -->
                
					<div class="content np">    
                    	<div class="footer">
                        	<div class="side fr">
                        		<div class="btn-group">
                                	<button id="" onclick="saveData(<?php echo $historicalID ?>)" class="btn-icon btn-success-form" type="button"><?php echo $this->lang->line('submit') ?></button>
                                </div>
                            </div>
                        </div>                                    
                    </div>
				
                
			</div><!-- block -->
			
			
				
			 
            </form>
        </div><!-- grid 1 -->
    </div><!-- wrap -->
</div><!-- content -->



