<script src="<?php echo base_url();?>assets/ckeditor/ckeditor.js"></script>
<script src="<?php echo base_url();?>assets/ckfinder/ckfinder.js"></script>

 <?php 
 if($_POST)
 {
	$bill_cnsgnr_id 				=		set_value('bill_cnsgnr_id',$_POST['bill_cnsgnr_id']);
	$bill_cnsgne_id 				=		set_value('bill_cnsgne_id',$_POST['bill_cnsgne_id']);
	$bill_notify_id 				=		set_value('bill_notify_id',$_POST['bill_notify_id']);
    $bill_notify_party2             =       set_value('bill_notify_party2',$_POST['bill_notify_party2']);
	$bill_brnch_id 				    =		set_value('bill_brnch_id',$_POST['bill_brnch_id']);
	$bill_port_id 				    =		set_value('bill_port_id',$_POST['bill_port_id']);
	$bill_company_id 				=		set_value('bill_company_id',$_POST['bill_company_id']);
    $pre_carriage                   =       set_value('pre_carriage',$_POST['pre_carriage']);
    $place_receipt                  =       set_value('place_receipt',$_POST['place_receipt']);
    $ocean_vessel                   =       set_value('ocean_vessel',$_POST['ocean_vessel']);
    $voyage                         =       set_value('voyage',$_POST['voyage']);
    $port_of_loading                =       set_value('port_of_loading',$_POST['port_of_loading']);
    $place_of_delivery              =       set_value('place_of_delivery',$_POST['place_of_delivery']);
    $no_of_bl                       =       set_value('no_of_bl',$_POST['no_of_bl']);
    $freight_payment                =       set_value('freight_payment',$_POST['freight_payment']);
    $freight_charges                =       set_value('freight_charges',$_POST['freight_charges']);
    $delivery_of_goods              =       set_value('delivery_of_goods',$_POST['delivery_of_goods']);
    $place_issue                    =       set_value('place_issue',$_POST['place_issue']);
	// $bill_products 				=		set_value('bill_products',$_POST['content']);
    $date_of_issue                  =       set_value('date_of_issue',$_POST['date_of_issue']);
    $container_no                   =       set_value('container_no',$_POST['container_no']);
    $goods                          =       set_value('goods',$_POST['goods']);
    $gross_weight                   =       set_value('gross_weight',$_POST['gross_weight']);
    $cube_measure                   =       set_value('cube_measure',$_POST['cube_measure']);
    $temp_cntrl                     =       set_value('temp_cntrl',$_POST['temp_cntrl']);
    $desc_goods                     =       set_value('desc_goods',$_POST['desc_goods']);
	
}
else
{
	$bill_cnsgnr_id 				=		$edit_bill->bill_cnsgnr_id;
	$bill_cnsgne_id 				=		$edit_bill->bill_cnsgne_id;
	$bill_notify_id 				=		$edit_bill->bill_notify_id;
    $bill_notify_party2             =       $edit_bill->bill_notify_party2;
	$bill_brnch_id 				    =		$edit_bill->bill_brnch_id;
	$bill_port_id 				    =		$edit_bill->bill_port_id;
	$bill_company_id 				=		$edit_bill->bill_company_id;
    $pre_carriage                   =       $edit_bill->pre_carriage;
    $place_receipt                  =       $edit_bill->place_receipt;
    $ocean_vessel                   =       $edit_bill->ocean_vessel;
    $voyage                         =       $edit_bill->voyage;
    $port_of_loading                =       $edit_bill->port_of_loading;
    $place_of_delivery              =       $edit_bill->place_of_delivery;
    $no_of_bl                       =       $edit_bill->no_of_bl;
    $freight_payment                =       $edit_bill->freight_payment;
    $freight_charges                =       $edit_bill->freight_charges;
    $delivery_of_goods              =       $edit_bill->delivery_of_goods;
    $place_issue                    =       $edit_bill->place_issue;
    // $bill_products 				=		$edit_bill->bill_products;
	$date_of_issue                  =       $edit_bill->date_of_issue;
    $container_no                   =       $edit_bill->container_no;
    $goods                          =       $edit_bill->goods;
    $gross_weight                   =       $edit_bill->gross_weight;
    $cube_measure                   =       $edit_bill->cube_measure;
    $temp_cntrl                     =       $edit_bill->temp_cntrl;
    $desc_goods                     =       $edit_bill->desc_goods;
    $get_branch_name                = $branch_name->branch_name;
}
 ?>
 <div class="box-body">
 	<div style="color:red;" class="error"><strong><?php if($this->session->flashdata('error')){ echo $this->session->flashdata('error');} ?></strong></div>
    <form role="form" id="edit_bill" name="edit_bill" action="<?php echo base_url();?>Generate_bill/edit_bill/<?php echo $bill_id;?>" method="post">
    	<input type="hidden" id="bill_id" name="bill_id" value="<?php echo $bill_id;?>">
        
        <div class="col-md-4">
            
            <div class="form-group">
                <label>Branch Name</label>
                <input type="text"  value="<?php echo $get_branch_name;?>" class="form-control" disabled>
                <input type="hidden" value="<?php echo $bill_brnch_id;?>" id="bill_brnch_id" name="bill_brnch_id">
                <!--  <select class="form-control select2" id="bill_brnch_id" name="bill_brnch_id" disabled>
                 <option value="">Select Branch Name</option>
                    <?php foreach($branch_drpdwn as $row)
                    {?>
                        <option value="<?php echo $row['branch_id'];?>" <?php if($row['branch_id']==$bill_brnch_id)echo "selected";?>><?php echo $row['branch_name'];?></option>
                     <?php }?> -->

                
               <!--  <input type="hidden" value="<?php //echo $row['branch_id'];?>" id="bill_brnch_id" name="bill_brnch_id"> -->
                <input type="hidden" name="branch_bill_no" id="branch_bill_no" class="branch_bill_no">
               
             
            </div>

            <div class="form-group">
                <label>Consignee Name</label>&nbsp;&nbsp;&nbsp;<span style="color:red;font-weight: 900;">*</span><?php echo form_error('bill_cnsgne_id');?>
                <select class="form-control select2" id="bill_cnsgne_id" name="bill_cnsgne_id" tabindex="4">
                    <option value="">Select Consignee Name</option>
                    <?php foreach($consignee_drpdwn as $row)
                    {?>
                        <option value="<?php echo $row['consignee_id'];?>" <?php if($row['consignee_id']==$bill_cnsgne_id)echo "selected";?>><?php echo $row['consignee_name'];?></option>
                    <?php }?>
                </select>
            </div>

            <div class="form-group">
                <label>Place Of Receipt</label>
                <textarea class="form-control place_receipt" name="place_receipt" id="place_receipt" tabindex="7"><?php echo $place_receipt;?></textarea>
            </div>

            <div class="form-group">
                <label>Voy No.</label>&nbsp;&nbsp;&nbsp;<span style="color:red;font-weight: 900;">*</span><?php echo form_error('voyage');?>
                <textarea class="form-control voyage" name="voyage" id="voyage" tabindex="10"><?php echo $voyage;?></textarea>
            </div>

            <div class="form-group">
                <label>Number of Original Bills Of Lading</label>
                <textarea class="form-control no_of_bl" name="no_of_bl" id="no_of_bl" tabindex="13"><?php echo $no_of_bl;?></textarea>
            </div>

            <div class="form-group">
                <label>Description of Goods & Pkgs.</label>
                <textarea class="form-control goods" name="desc_goods" id="desc_goods" tabindex="16"><?php echo $desc_goods;?></textarea>
            </div>

            <div class="form-group">
                <label>Temperature Control Instructions:</label>
                <textarea class="form-control gross_weight" name="temp_cntrl" id="temp_cntrl" tabindex="19"><?php echo $temp_cntrl;?></textarea>
            </div>

            <div class="form-group">
                <label>Place Of Issue</label>&nbsp;&nbsp;&nbsp;<span style="color:red;font-weight: 900;">*</span><?php echo form_error('place_issue');?>
                <textarea class="form-control place_issue" name="place_issue" id="place_issue" tabindex="22"><?php echo $place_issue;?></textarea>
            </div>
        </div>

        <div class="col-md-4">

            <div class="form-group">
                <label>Company Name</label>
                <select class="form-control select2" id="bill_company_id" name="bill_company_id" tabindex="2">
                    <option value="">Select Company Name</option>
                   	<?php foreach($company_drpdwn as $row)
                  	{?>
                        <option value="<?php echo $row['cmp_id'];?>" <?php if($row['cmp_id']==$bill_company_id)echo "selected";?>><?php echo $row['cmp_name'];?></option>
                    <?php }?>
                </select>
                <input type="hidden" value="<?php echo $row['cmp_id'];?>" id="bill_company_id" name="bill_company_id">                
            </div>

            <div class="form-group">
                <label>Notify Party 1</label>
                <select class="form-control select2" id="bill_notify_id" name="bill_notify_id" tabindex="5">
                    <option value="">Select Notify Name</option>
                    <?php foreach($notify_drpdwn as $row)
                    {?>
                        <option value="<?php echo $row['notify_id'];?>" <?php if($row['notify_id']==$bill_notify_id)echo "selected";?>><?php echo $row['notify_name'];?></option>
                    <?php }?>
                </select>
            </div>


            <div class="form-group">
                <label>Port Of Loading</label>&nbsp;&nbsp;&nbsp;<span style="color:red;font-weight: 900;">*</span><?php echo form_error('port_of_loading');?>
                <textarea class="form-control port_of_loading" name="port_of_loading" id="port_of_loading" tabindex="8"><?php echo $port_of_loading;?></textarea>
            </div>


            <div class="form-group">
                <label>Port of Discharge</label>&nbsp;&nbsp;&nbsp;<span style="color:red;font-weight: 900;">*</span><?php echo form_error('bill_port_id');?>
                <select class="form-control select2" id="bill_port_id" name="bill_port_id" tabindex="11">
                    <option value="">Select Port Name</option>
                    <?php foreach($portname_drpdwn as $row)
                    {?>
                        <option value="<?php echo $row['port_of_dis_id'];?>" <?php if($row['port_of_dis_id']==$bill_port_id)echo "selected";?>><?php echo $row['port_of_dis_name'];?></option>
                    <?php }?>
                </select>
            </div>


            <div class="form-group">
                <label style="margin-top: 27px;">Container Number & Seal Number</label>&nbsp;&nbsp;&nbsp;<span style="color:red;font-weight: 900;">*</span><?php echo form_error('container_no');?>
                <textarea class="form-control container_no" name="container_no" id="container_no" tabindex="14"><?php echo $container_no;?></textarea>
            </div>


            <div class="form-group">
                <label>Gross Weight (KGS)</label>
                <textarea class="form-control gross_weight" name="gross_weight" id="gross_weight" tabindex="17"><?php echo $gross_weight;?></textarea>
            </div>

             <div class="form-group">
                <label>Freight Details, Charges etc:</label>
                <textarea class="form-control freight_charges" name="freight_charges" id="freight_charges" tabindex="20"><?php echo $freight_charges;?></textarea>
            </div>

             <div class="form-group">
                <label>Date Of Issue</label>&nbsp;&nbsp;&nbsp;<span style="color:red;font-weight: 900;">*</span><?php echo form_error('date_of_issue');?>
                <input type="date" name="date_of_issue" id="date_of_issue" value="<?php echo $date_of_issue?>" class="form-control" tabindex="23">
                <!-- <textarea class="form-control freight_charges" name="date_of_issue" id="date_of_issue"></textarea> -->
            </div>

        </div>

        <div class="col-md-4">

             <div class="form-group">
                <label>Shipper</label>&nbsp;&nbsp;&nbsp;<span style="color:red;font-weight: 900;">*</span><?php echo form_error('bill_cnsgnr_id');?>
                <select class="form-control select2" id="bill_cnsgnr_id" name="bill_cnsgnr_id" tabindex="3">
                    <option value="">Select Shipper/Exporter Name</option>
                    <?php foreach($consignor_drpdwn as $row)
                    {?>
                        <option value="<?php echo $row['consignor_id'];?>" <?php if($row['consignor_id']==$bill_cnsgnr_id)echo "selected";?>><?php echo $row['consignor_name'];?></option>
                    <?php }?>
                </select>
            </div>

             <div class="form-group">
                <label>Notify Party 2</label>
                <select class="form-control select2" id="bill_notify_party2" name="bill_notify_party2" tabindex="6">
                    <option value="">Select Notify Name</option>
                    <?php foreach($notify_drpdwn as $row)
                    {?>
                        <option value="<?php echo $row['notify_id'];?>" <?php if($row['notify_id']==$bill_notify_party2)echo "selected";?>><?php echo $row['notify_name'];?></option>
                    <?php }?>
                </select>
            </div>

            <div class="form-group">
                <label>Vessel</label>&nbsp;&nbsp;&nbsp;<span style="color:red;font-weight: 900;">*</span><?php echo form_error('ocean_vessel');?>
                <textarea class="form-control ocean_vessel" name="ocean_vessel" id="ocean_vessel" tabindex="9"><?php echo $ocean_vessel;?></textarea>
            </div>

            <div class="form-group">
                <label>Place Of Delivery</label>&nbsp;&nbsp;&nbsp;<span style="color:red;font-weight: 900;">*</span><?php echo form_error('place_of_delivery');?>
                <textarea class="form-control place_of_delivery" name="place_of_delivery" id="place_of_delivery" tabindex="12"><?php echo $place_of_delivery;?></textarea>
            </div>

            <div class="form-group">
                <label>No.of Pkgs, or Shipping Units</label>
                <textarea class="form-control goods" name="goods" id="goods" tabindex="15"><?php echo $goods;?></textarea>
            </div>

            <div class="form-group">
                <label>Measurement (CBM)</label>
                <textarea class="form-control cube_measure" name="cube_measure" id="cube_measure" tabindex="18"><?php echo $cube_measure;?></textarea>
            </div>

            <div class="form-group">
                <label>Delivery Agent</label>
                <textarea class="form-control delivery_of_goods" name="delivery_of_goods" id="delivery_of_goods" tabindex="21"><?php echo $delivery_of_goods;?></textarea>
            </div>

        </div>



            <!-- 
            <div class="form-group">
                <label>Pre-Carriage by</label>
                <textarea class="form-control pre_carriage" name="pre_carriage" id="pre_carriage"><?php echo $pre_carriage;?></textarea>
            </div> -->

           <!--   <div class="form-group">
                <label>Freight Payment at</label>&nbsp;&nbsp;&nbsp;<span style="color:red;font-weight: 900;">*</span><?php echo form_error('freight_payment');?>
                <textarea class="form-control freight_payment" name="freight_payment" id="freight_payment"><?php echo $freight_payment;?></textarea>
            </div> -->

        <div class="col-md-12">
        &nbsp;
        </div>
       <!--   <div class="col-md-12">
         <label>Products Details</label>
         	<textarea class="form-control" name="content"><?php echo $bill_products;?></textarea>
         <?php  //echo $this->ckeditor->editor("textarea name","default textarea value");?>
            
        </div> -->



	   
    	
            <div class="form-group">
            	
            	<div class="col-md-6" style="padding-top: 30px;"><input type="submit" id="submit" name="submit" class="btn btn-info submit" value="Save">
            	<a href="<?php echo base_url()?>Generate_bill/generate_bill"><button type="button" class="btn btn-warning">Cancel</button></a></div>
            </div>
	    </div>
    	<!-- <div class="col-md-4 form-group has-warning">
    		<h4><label>Recently Listed Company</label></h4>
    		<div class="box box-warning">
			    <table class="table table-bordered table-hover">
			        <thead>
			            <tr>
			                <th>Name</th>
			                <th>Place Of Loading</th>
			                <th>Short Code</th>
			            </tr>
			        </thead>
			        <tbody>
	        			<?php if(count($recent_list)!=0)
	        			{
	        				foreach($recent_list as $row)
	        				{?>
		    					<tr>
		    						<td><a href="<?php echo base_url();?>General_masters/edit_company/<?php echo $row['cmp_id'];?>"><strong><?php echo $row['cmp_name'];?></strong></a></td>
		    						<td><?php echo $row['cmp_pol'];?></td>
		    						<td><?php echo $row['cmp_shrt_code'];?></td>
		    					</tr>
	        				<?php }
	        			}
	        			else
	        			{?>
	        				<tr><td colspan="3">Data Not Found</td></tr>
	        			<?php }?>
			        </tbody>
			    </table>
			    <a class="text-red" href="<?php echo base_url();?>General_masters/company"><strong>View All Company Lists</strong></a>
		    </div>
	    </div> -->
	</form>
    <!-- /.box-body -->
</div>
<script> 

	CKEDITOR.editorConfig = function( config ) {
		config.toolbar  = [ { name: 'basicstyles', items: [ 'Font','FontSize','Bold','Italic','Underline','Strike','Subscript','Superscript'] }]
	};
    CKEDITOR.replace( 'content' );


</script>
<script type="text/javascript">


 $(function()
    {



        //setTimeout(branch_select);
        //setTimeout(company_select);
        setTimeout(consignor_select);
        setTimeout(consignee_select);
        setTimeout(notify_select);
        setTimeout(portname_select);
    });
    function branch_select()
    {
        $("#bill_brnch_id").select2({
            ajax: { 
                dataType: 'json', 
                url: '<?php echo base_url();?>Generate_bill/get_branch',
                cache: true,
                data: function (params) 
                    {
                        return {
                            q: params.term
                        }
                    }
            }
        });
    }

    function company_select()
    {
        $("#bill_company_id").select2({
            ajax: { 
                dataType: 'json', 
                url: '<?php echo base_url();?>Generate_bill/get_company',
                cache: true,
                data: function (params) 
                    {
                        return {
                            q: params.term
                        }
                    }
            }
        });
   }

 	function consignor_select()
    {
        $("#bill_cnsgnr_id").select2({
            ajax: { 
                dataType: 'json', 
                url: '<?php echo base_url();?>Generate_bill/get_consignor',
                cache: true,
                data: function (params) 
                    {
                        return {
                            q: params.term
                        }
                    }
            }
        });
    }
    function consignee_select()
    {
        $("#bill_cnsgne_id").select2({
            ajax: { 
                dataType: 'json', 
                url: '<?php echo base_url();?>Generate_bill/get_consignee',
                cache: true,
                data: function (params) 
                    {
                        return {
                            q: params.term
                        }
                    }
            }
        });
    }
	function notify_select()
	    {
	        $("#bill_notify_id").select2({
	            ajax: { 
	                dataType: 'json', 
	                url: '<?php echo base_url();?>Generate_bill/get_notify',
	                cache: true,
	                data: function (params) 
	                    {
	                        return {
	                            q: params.term
	                        }
	                    }
	            }
	        });
	    }
	function portname_select()
		    {
		        $("#bill_port_id").select2({
		            ajax: { 
		                dataType: 'json', 
		                url: '<?php echo base_url();?>Generate_bill/get_portname',
		                cache: true,
		                data: function (params) 
		                    {
		                        return {
		                            q: params.term
		                        }
		                    }
		            }
		        });
		    }
    

   // var branch_bill_no = $('.branch_bill_no').val();
    //console.log(branch_bill_no);

    
    // $('.submit').click(function(e){

    //     var branch_bill_no = $('.branch_bill_no').val();
    //     console.log(branch_bill_no);
    //     $.ajax({
    //         type: "POST",
    //         url: "<?php echo base_url();?>Generate_bill/insert_branch_bill_no",
    //         data : {branch_bill_no:branch_bill_no},
    //         success: function(msg){

    //         }
    //     });
    // });


	
</script>
