 <link href="<?php echo base_url(); ?>assets/select/chosen.min.css" rel="stylesheet" media="screen">
	
		   
		   		   <script src="<?php echo base_url(); ?>assets/select/chosen.jquery.min.js"></script>

            
        <script type="text/javascript"> 


			function printDiv(divName) {
     var printContents = document.getElementById(divName).innerHTML;
     var originalContents = document.body.innerHTML;

    // document.body.innerHTML = printContents.fontsize(12);
     window.print();

	 if( window.print()) {
         window.location.href = "../user/recorddelivery";
		alert(" printing...........");
    }else {

	
		      return      window.location.href = "../user/recorddelivery";

		    // document.body.innerHTML = originalContents;

	}
}


  $(document).on("click", "#viewbtn", function()
        {
          var categoryid = $(this).data('id');
		  $("#categoryid").val(categoryid); 
		   
 
		    var status = $(this).data('status');
		   $("#mystatus").val(status); 
		   
		     var description = $(this).data('description');
		   $("#mydescription").val(description); 
		 
		var shipping = $(this).data('shipping');
		   $("#shipping").val(shipping);
		   var qty = $(this).data('qty');
		   $("#qty").val(qty); 
		   	var branch = $(this).data('branch');
		   $("#branch").val(branch);
		   var ordereddate = $(this).data('ordereddate');
		   $("#ordereddate").val(ordereddate); 
		   var profit = $(this).data('profit');
		   $("#profit").val(profit); 

			var code = $(this).data('code');
		   $("#code").val(code);
		   var description = $(this).data('description');
		   $("#mydescription").val(description); 
		   	var myserial = $(this).data('serial');
		   $("#myserial").val(myserial);
		   var name = $(this).data('name');
		   $("#name").val(name); 
		   	var myorderno = $(this).data('orderno');
		   $("#myorderno").val(myorderno);
		   var staff = $(this).data('staff');
		   $("#staff").val(staff); 
		   	var supplier = $(this).data('supplier');
		   $("#supplier").val(supplier);
		   var buyingprice = $(this).data('buyingprice');
		   $("#buyingprice").val(buyingprice); 
		   	var sellingprice = $(this).data('sellingprice');
		   $("#sellingprice").val(sellingprice);
		   var commission = $(this).data('commission');
		   $("#commission").val(commission); 
		     var commissionrate = $(this).data('commissionrate');
		   $("#commissionrate").val(commissionrate); 
		    var myitemid = $(this).data('itemid');
		   $("#myitemid").val(myitemid); 
		  
		   
        });











		
        $(this).ready( function() {  
            $("#id").autocomplete({  
 
                minLength: 1,  
                source:   
                function(req, add){  
                    $.ajax({  
                        url: "<?php echo base_url(); ?>Systemusers/lookup",  
                        dataType: 'json',  
                        type: 'POST',  
                        data: req,  
                        success:      
                        function(data){  
                            if(data.response =="true"){  
                                add(data.message);  
                                console.log(data);
                            }  
                        },  
                    });  
                },  
                     
            });  
        });  
		
		
			
		 $(document).on("click", "#managebtndelete", function()
        {
          var itemid = $(this).data('id');
		  $("#itemid1").val(itemid); 
		  
		  
		   
        });
		
		  $(document).on("click", "#editbtn", function()
        {
          var mycategoryid = $(this).data('id');
		  $("#mycategoryid").val(mycategoryid); 
		     var serial = $(this).data('serial');
		   $("#serial").val(serial); 
 
		    var status = $(this).data('status');
		   $("#status").val(status); 
		   
		     var description = $(this).data('description');
		   $("#description").val(description); 
		 
		  
		  
		   
        });
		
			
		 
        </script>
		
		
		
		
		   <script>
		
			
		  $(function() {
<!--             $(".datepicker").datepicker(); -->
<!--             $(".uniform_on").uniform() -->;
            $(".chzn-select").chosen();
   <!--          $('.textarea').wysihtml5(); -->

        });
		
		
		
        </script>
		
		
		
		
	   	  <style type="text/css">
  
  

    #printable { display: none; }

    #myprint { display: none; }
#print{  	


    background-repeat: no-repeat;
	font-size;12px;
  
    


}


#sale{  	
background-image:url(images/add.png) ;

    background-repeat: no-repeat;
  
    width:100px; height:50px;


}
    
    @media print
    {
    	#non-printable { display: none; }
    	#printableArea { display: block; font-size:16; width:100%; }
		    	#myprint { display: block; font-size:16; width:100%; }
				 #printable { display: block; }

    }
    </style>
 
 <div class="row">
  
   	

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

  <?php

			function formatMoney($number, $fractional=false) {
						if ($fractional) {
							$number = sprintf('%.2f', $number);
						}
						while (true) {
							$replaced = preg_replace('/(-?\d+)(\d\d\d)/', '$1,$2', $number);
							if ($replaced != $number) {
								$number = $replaced;
							} else {
								break;
							}
						}
						return $number;
					}
 		  $dateposted=date("Y-m-d H:i:s");

				echo $this->session->flashdata('msg'); 
   $session_data = $this->session->userdata('logged_in');

      $mydate=date("Y-m-d H:i:s");
 $date = Date('Y-m-d') ;
		 	 $year = Date('Y') ;
		  $month = Date('m') ;
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
$data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
		 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];	
    $add=$this->usermodel->populatuserpermissionsdataarray('recorddelivery','add',$userid);
	$view=$this->usermodel->populatuserpermissionsdataarray('recorddelivery','view',$userid);
  $delete=$this->usermodel->populatuserpermissionsdataarray('recorddelivery','delete',$userid);
	$update=$this->usermodel->populatuserpermissionsdataarray('recorddelivery','update',$userid);

$changestatus=$this->usermodel->populatuserpermissionsdataarray('recorddelivery','changestatus',$userid);
	$report=$this->usermodel->populatuserpermissionsdataarray('recorddelivery','report',$userid);
  $Dispatched=$this->usermodel->populatuserpermissionsdataarray('recorddelivery','Dispatched',$userid);
	$FailedDelivery=$this->usermodel->populatuserpermissionsdataarray('recorddelivery','FailedDelivery',$userid);
$ReturnedandReceived=$this->usermodel->populatuserpermissionsdataarray('recorddelivery','ReturnedandReceived',$userid);
	$Delivered=$this->usermodel->populatuserpermissionsdataarray('recorddelivery','Delivered',$userid);
  $Claimraised=$this->usermodel->populatuserpermissionsdataarray('recorddelivery','Claimraised',$userid);
	$ClaimOK=$this->usermodel->populatuserpermissionsdataarray('recorddelivery','ClaimOK',$userid);

$ClaimDamaged=$this->usermodel->populatuserpermissionsdataarray('recorddelivery','ClaimDamaged',$userid);
	
     echo $this->session->flashdata('productmsg'); 
$imgid = rand(100, 990000).time();

  ?>

  
		<div class="panel panel-default" data-collapsed="0" >
        	<div class="panel-heading" id="non-printable">
            	<div class="panel-title" id="redcolor" >
            		<i class="entypo-plus-circled"></i>
				 <span class="pull-center"> Record delivery </span>
	  
				 	  				 <a href="<?php echo base_url();?>user/viewpurchases" class="btn btn-info"> Back to purchases</a>
				 <a href="<?php echo base_url();?>user/recorddelivery" class="btn btn-info"> Back to Delivery</a>

				 				 	  <a data-toggle='modal' data-target='#deliveryModal' class="btn btn-default"> Delivery Report</a>
				 	  				     				 <a href="<?php echo base_url();?>user/viewserialnumbers" class="btn btn-default"> View all Serial No </a>

									 
									 <a href="<?php echo base_url();?>user/recorddelivery" class="btn btn-info"> Refresh</a>

									 
									 <div class="pull-right">
				 	<form name="print" method="post" action="">

<input type="submit" id="print"  accesskey="p" class="btn btn-primary"  name="print"onclick="printDiv('printableArea')" value="print report!" />
</form>
</div>
            	</div>
            </div>
			<div class="panel-body">
					<div class="col-md-12" ID="non-printable">
        <?php 
		
        $attr = array("class" => "form-horizontal", "role" => "form", "id" => "search", "name" => "search");
        echo form_open("user/postdelivery", $attr);?>
            <div class="form-group">
			
          
					<input type="hidden" name="type" value="product"id="type" class="form-control" required placeholder="Enter type">
				<input type="hidden" name="view" value="user/recorddelivery"id="view" class="form-control" required placeholder="Enter view">
	
				
						 
			
				
					<select class="form-control" name="status" required style="display:none">
	
		<option value=""  >---Select Status---</option>
		<option value="Dispatched" selected="Dispatched"  >Dispatched</option>
	
<!--	<option value="Returned"  >Returned</option>
		<option value="Failed"  >Failed Delivery</option>
		<option value="Delivered"  >Delivered</option>
		<option value="Returned and Received"  >Returned and Received</option>
-->
	

</select>
				
				
				
				
				
				 
				 
			
			 
			 <div class="col-md-2">
			 Serial / Code<br>
		  		<input type="text" name="code" value="<?php echo set_value('code'); ?>" class="form-control" required placeholder="Enter Code /Serial">

			</div>

			
			       <div class="col-md-1">
				   			Order No<br>

				<input type="text" name="orderno" value="<?php echo set_value('orderno'); ?>"  class="form-control"  placeholder="order number">
                </div>
					
								       <div class="col-md-1">
									   			 Quantity<br>


									<input type="text" name="qty" value="1"  class="form-control" required  placeholder="Quantity">
									</div>

								<div class="col-md-2">
									   			 Category<br>

				<input type="hidden" name="commission" required value="0"  class="form-control"  placeholder="Commission">
									
									
									<select class="chzn-select" name="category"style="width:150px" required>

	<option value=""  >---Select Category---</option>

	
	<?php 
					 
			//$allsuppliers =  $this->usermodel->populatemysupplier($companyid);
	
									$category  = $this->usermodel->populatealldatanoarraythree('productcategory','commission >',0,'id >',0,'companyid', $companyid);

if(is_array($category)) {

   foreach($category as $categoryrow){

   //echo $courserow->coursename;
    ?>
					<option value="<?=  $categoryrow->id;   ?>"><?=  $categoryrow->name; ?></option>



	<?php

}} else {
    echo 'No supplier available.';
}
	
?>
</select>
		               
												<input type="hidden" name="shipping" required value="0"  class="form-control"  placeholder="Enter shipping cost">
	
									
									
									
									</div>

									   

			 
			 
			 
			 
			 
			 
			       <div class="col-md-1">
				   									   			 Customer<br>

		<select class="chzn-select" name="supplier"style="width:100px" >

	<option value=""  >---Select customer---</option>

	
	<?php 
					 
			//$allsuppliers =  $this->usermodel->populatemysupplier($companyid);
	
									$allsuppliers  = $this->usermodel->populatealldatanoarrayorderby('people','company','ASC','category','member','companyid', $companyid);

	
if(is_array($allsuppliers)) {

   foreach($allsuppliers as $suppliersrow){

   //echo $courserow->coursename;
    ?>
					<option value="<?=  $suppliersrow->id;   ?>"><?=  $suppliersrow->company ."(". $suppliersrow->firstname ."- ".$suppliersrow->phone.")"; ?></option>



	<?php

}} else {
    echo 'No supplier available.';
}
	
?>
</select>
		                </div>
				



				
				
				
				
		 
				 
               
				
				 <div class="col-md-2">
				 									   			 Date<br>

				
                    <input class="form-control"  id="ordereddate" name="ordereddate" placeholder="Enter Date" type="text" value="<?php echo $dateposted; ?>" />

					
				 
				 
                </div>
				
				
				
				
				
				 <div class="col-md-1">
										   			 Staff<br>

	<select class="chzn-select" name="staff"style="width:100%" required>

						<?php
		 			//$myusers = $this->usermodel->populatealldatanoarrayorderbydata('people', 'id',$userid,'status',1,'firstname','ASC');

									 			$myusers = $this->usermodel->populateall('people', 'id',$userid,'id >',0,'category','user');

					
					
						
if(is_array($myusers)) {

   foreach($myusers as $allrow){

   //echo $courserow->coursename;
    ?>
					<option  selected="selected" value="  <?=  $allrow->id;   ?>"><?=  $allrow->firstname ."- ".$allrow->surname ."(". $allrow->email.")"; ?></option>



	<?php

}} else {
    echo 'No user available.';
}
	
		 if($viewallcollections==true){
			 			$allusers = $this->usermodel->populatealldatanoarraythree('people', 'companyid',$companyid,'status',1,'category','user');

			 			//$allusers = $this->usermodel->populatealldatanoarrayorderbydata('people', 'companyid',$companyid,'status',1,'firstname','ASC');

			 		//$allusers= $this->usermodel->populatealldatawhere('people','firstname','ASC','companyid',$companyid);

			//$allusers = $this->usermodel->populateall('people', 'companyid',$companyid);
	

 }
  ?>

	
	
	
	<?php 
				
				
	

	
if(is_array($allusers)) {

   foreach($allusers as $userrow){

   //echo $courserow->coursename;
    ?>
					<option value="<?=  $userrow->id;   ?>"><?=  $userrow->firstname ."- ".$userrow->surname ."(". $userrow->email.")"; ?></option>



	<?php

}} else {
    echo 'No user available.';
}
	
?>
</select>
		
						<span class="text-danger"><?php echo form_error('userid'); ?>

	    </div>
				
				
				
		 <div class="col-md-1">
		 									   			  Branch<br>

	<select class="form-control" name="branch"  id="branch" required>
	
	

					<option value="Main"  >Main Store</option>

	<?php 
					 
					 		$maincategory = $this->usermodel->populateall('branch','companyid',$companyid);


							


if(is_array($maincategory)) {

   foreach($maincategory as $maincategoryrow){

   //echo $courserow->coursename;
    ?>
					<option selected="selected" value="<?=  $maincategoryrow->id;   ?>"><?=  $maincategoryrow->name; ?></option>



	<?php

}} else {
    echo 'No main counter available.';
}
	
?>
</select>
		

		

  </div>	
  
  
	
				
				
				
				
				
				
				
                <div class="col-md-1">
													   			 Add<br>

				<?php
						 if($add==true){
			 
			 ?>
	         <button type="submit"  value="product" name="btn_adddelivery" class="btn btn-info"> Save   </button>

<?php
 }else{

 }
  ?>

                </div>
				 
            </div>
        <?php echo form_close(); ?>
		
		
        </div>	

	<div class="col-md-12">
        <?php 
		$mypage=0;
		if(isset($page)) {$mypage=$page;}else{$mypage=0;}
        $attr = array("class" => "form-horizontal", "role" => "form", "id" => "search", "name" => "search");
        echo form_open("user/searchserials", $attr);?>
            <div class="form-group">
			                    <input name="page" placeholder="page" type="text" value="<?php echo set_value('page',$mypage); ?>" />

                <div class="col-md-3">
                    <input class="form-control" autofocus id="searchterm" name="searchterm" placeholder="Search for product by name, code,description.." type="text" value="<?php echo set_value('searchterm'); ?>" />
                </div>
				
					   <div class="col-md-2">
				   <select class="form-control"name="searchtype"  >
	
	<option value=""  >---Select way of search items---</option>

   <option value="all" selected="selected" >All/General</option>

   <option value="Specific"  >Specific item</option>

   

</select>		
	
                </div>
                <div class="col-md-3">
                    <input id="btn_search" name="btn_search" type="submit" class="btn btn-default" value="Search" />
                    <a href="<?php echo base_url(). "user/recorddelivery"; ?>" class="btn btn-default">Refresh</a>
                                   <a href="<?php echo base_url(). "Systemusers/recorddelivery/".$mypage; ?>" class="btn btn-info">Back</a>

			   </div>
				 
            </div>
        <?php echo form_close(); ?>

        </div>
					
								
								
														<table id="printableArea" class="table table-bordered " width="100%" >

		
		
		
		
		
		
		
		
		
			 <?php
			 
			 if(isset($configuration[0]['businessname'])) {
				 ?>
			 	 
									 <tr>
			 <td colspan="14" width="100%">
	<center>
					
										<?php $bussinessname=$configuration[0]['businessname']; if(isset($bussinessname)) {echo   $bussinessname; }?>
										<BR><B>DELIVERY REPORT</B>
		</center>	
		</td>
		</tr>
		
							<?php
			 }
							?>
								<tr>

								<th>Code</th>
																<th> Serial No</th>

								<th>Item Name</th>
									<th>B Price</th>
									<th>S Price</th>

								<th> Qty </th>
								<th> Comm </th>
								<th> Delivery </th>
								<th> Profit </th>

								<th>Order No</th>
								<th>Status</th>
								<th>Staff</th>
								<th>Company</th>
						<th>Branch</th>
								<th>Date Issued</th>
								<th>Updated </th>

								<th>More</th>

								</tr>
								
								
	

	
		
 
 
 	<?php
 
 
 
 
   $i=0;

		
 if(!is_array($delivery)) {
	  echo "<tr  style='margin-bottom:0px;margin-top:0px;' '>";
      echo "<td colspan='5'>";
    echo"There is no data found..";
    echo "</td>";
   echo "</tr>";

			 }else{
	   $totalprofit=0;

 $ttbprice=0;
  $ttsprice=0;
						
		 $totalqty=0;
		 $totalsp=0;
		 $totalbp=0;
		 $totalcom=0;
		 $totalshiping=0;
				foreach ($delivery as $c){
	
		 $totalsp=$totalsp+$c->sellingprice;
		 $totalbp=$totalbp+$c->buyingprice;
		 $totalcom=$totalcom+$c->commission;
		 $totalshiping=$totalshiping+$c->shipping;
		 		 $totalprofit=$totalprofit+$c->profit;

	
             ?>
									
										 
										
											<tr>
											 <td>
											 
											<?php echo $c->code ; ?> 
  </td>
  
  <td>
		
							<?php echo $c->serial ; ?>				

		
</td>
			 <td>
			 <?php echo $c->name ; ?>

  </td>
  								
													    
  
  <td>
   <?php echo $c->buyingprice ;
   
   ?>
   

  </td>
												
						<td>
						
							<?php echo $c->sellingprice ; ?>				
											
					
											
											
											
											
											
</td>
	<td>
													
													
													
							<?php echo $c->qty ;


		 $totalqty=$totalqty+$c->qty;

		?>				



													
													</td>
			
			<td>

		<?php
							echo formatMoney($c->commission, true);

		?>				


		
</td>	
<td>
		
							<?php 
							echo formatMoney($c->shipping, true);

							?>				

		
</td>


<td>
		
							<?php 
							
							echo formatMoney($c->profit, true);
							?>				

		
</td>






<td>
		
							<?php echo $c->orderno ; ?>				

		
</td>

<td>
							<?php 
							
							if(($c->status=="Dispatched")||($c->status=="Failed Delivery")||($c->status=="Claim raised")){
							echo $c->status ;
							$currentdate=date('Y-m-d H:i:s');

							$finaldate = strtotime(date($c->ordereddate));
									$mycurrentdate = strtotime(date($currentdate));

									$secs = $mycurrentdate-$finaldate;// == <seconds between the two times>
									$days = $secs / 86400;
							 $finaldays=round($days,0);
							 
							
							
							
							?>				

			<?php 
			
			if($finaldays < 7){
			
			?>
			<div class="btn-success">
			<?php  echo $finaldays ; 	?>
			</div>
			<?php
			}else if(($finaldays< 14) || ($finaldays<21)) {
		?>
			<div class="btn-warning">
			<?php  echo $finaldays ; 	?>
			</div>
			<?php
			
			}else if($finaldays >=21){
			?>
			<div class="btn-danger">
			<?php  echo $finaldays."Overdue" ; 	?>
			</div>
			<?php
			}
			
							}else{
														echo $c->status ;
	
							}
			?>	
		
</td>	

						<td><?php 
						
						 $mydatetype="";
						if(isset($datetype)){
							$mydatetype=$datetype;
						}else{
														$mydatetype="yes";

						}
if($mydatetype=="no"){
		$customer=$c->myid ;
}else{
	$customer=$c->staff ;	
}
					

$mycustomer=$this->usermodel->populateallarray('people','id', $customer);


			echo$myname=$mycustomer[0]['firstname'];

 ?></td>		


						<td>
						<?php  $customer=$c->supplier ;

$mycustomer=$this->usermodel->populateallarray('people','id', $customer);


			echo$myname=$mycustomer[0]['company'];

 ?>
 </td >
    <td>
												 
	<?php 
					// $branch="";
					 $branch=$c->branch;

					 $branch= $this->usermodel->populateall('branch','id',$branch);



if(is_array($branch)) {

   foreach($branch as $branchrow){

   echo $branchrow->name;
 
 
}} else {
    echo 'General.';
}
	
?>
												 
	 </td>
 
					<td> <?php echo $c->ordereddate ; ?>	</td>

								<td> <?php

  $myuserid=$c->myid ;

$updatedby=$this->usermodel->populateallarray('people','id', $myuserid);
echo $c->updatedate ; 
if($myuserid==0){
		$myname=$updatedby[0]['firstname'];

}else{
					echo" By:".$myname=$updatedby[0]['firstname'];

}


							
								
								
								
								?>	</td>

			 <td> 

 
 
					<div class="btn-group">
                                    <button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
                                        More <span class="caret"></span>
                                    </button>
									
                                    <ul class="dropdown-menu dropdown-default pull-right" role="menu">
                                        
                                        <!-- teacher EDITING LINK -->
                                      <?php 

									if($changestatus==true)
										{
									 ?>
	
													  <li> 

	 <a class="btn btn-primary editbtn" id="editbtn"   data-serial='<?php echo  $c->serial;?>' data-status='<?php echo  $c->status;?>' data-description='<?php echo  $c->description;?>'  data-id='<?php echo  $c->id;?>' data-toggle='modal' data-target='#editProductModel'> 	 

                                                <i class="glyphicon glyphicon-pencil"></i>
																Change status
                                                </a>
                                                        </li>
									<?php 

										}
									 ?>
	 

														  <li class="divider"></li>

														
	
<?php 

if($update==true)
	{
 ?>
				
														
												  <li> 

	 <a class="btn btn-primary viewbtn" id="viewbtn" data-itemid='<?php echo  $c->itemid;?>' data-profit='<?php echo  $c->profit;?>' data-commissionrate='<?php echo  $c->commissionrate;?>' data-status='<?php echo  $c->status;?>' data-ordereddate='<?php echo  $c->ordereddate;?>'data-shipping='<?php echo  $c->shipping;?>' data-qty='<?php echo  $c->qty;?>'data-branch='<?php echo  $c->branch;?>'data-buyingprice='<?php echo  $c->buyingprice;?>'data-sellingprice='<?php echo  $c->sellingprice;?>'data-commission='<?php echo  $c->commission;?>'data-orderno='<?php echo  $c->orderno;?>'data-staff='<?php echo  $c->staff;?>'data-supplier='<?php echo  $c->supplier;?>'data-code='<?php echo  $c->code;?>'data-serial='<?php echo  $c->serial;?>'data-name='<?php echo  $c->name;?>'
 data-description='<?php echo  $c->description;?>'  data-id='<?php echo  $c->id;?>' data-toggle='modal' data-target='#viewProductModel'> 	 

                                                <i class="glyphicon glyphicon-pencil"></i>
																Update Details
                                                </a>
                                                        </li>			
														
<?php

	}
?>													
														
														
														
														
										 <li class="divider"></li>

	
<?php 

if($delete==true)
	{
 ?>
	
											  <li> 
										 <a class="btn btn-danger managebtn" id="managebtndelete"		 data-id='<?php echo  $c->id;?>'    data-toggle='modal' data-target='#myDelete<?php  $c->id; ?>'>	 


                                                <i class="glyphicon glyphicon-pencil"></i>
																Delete
                                                </a>
                                                        </li>
														<?php 

	}
 ?>
	
									
									
                                        <li class="divider"></li>
                                        
                                        <!-- teacher DELETION LINK -->
                                        
                                    </ul>
										
                                </div>
</td>

<?php
		}

?>
		

 </tr>
 
 <?php
		}

?>

 						<tr border="1" background="green">
									<td colspan="3"><center><b>Expected  Amount:</td>
				<td>					
		<b><center><?php if(isset($totalbp)) {echo formatMoney($totalbp, true);  }?></center></b>
		
		</td>
					<td><b><center><?php if(isset($totalsp)) {echo formatMoney($totalsp, true);  }?></center></b></td>

						<td>  <b><?php if(isset($totalqty)) {echo formatMoney($totalqty, true);  }?><b></td>


			<td>  <b><?php if(isset($totalcom)) {echo formatMoney($totalcom, true);  }?><b></td>

			
		
			
			<td>  <b><?php if(isset($totalshiping)) {echo formatMoney($totalshiping, true);  }?><b></td>

			<td>  <b><?php if(isset($totalprofit)) {echo formatMoney($totalprofit, true);  }?><b></td>


		
	<td id="non-printable" colspan="7"></td>
</tr>
 

</table>								
		
													


  <div class="col-md-12 text-center">    <?php if(isset($links)) {echo   $links; }; ?>
	<span style="color:red; font-size:20px"><?php  if(isset($total_rows)) {echo   $total_rows." Recods in the system. "; } ;?>    </span>



        </div>						
						
								

								
				</div>	
			</div>			
					
					
			

<div id="viewProductModel" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Update Delivery </h4>
      </div>
      <div class="modal-body">
      
	  	

				<?PHP
//$session_data = $this->session->userdata('logged_in');



				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/updatepostdelivery' , array('class' => 'form-horizontal form-groups-bordered validate', 'enctype' => 'multipart/form-data'));
				 if(validation_errors()):?>
<div class='alert alert-danger text-center'><?php echo validation_errors(); ?></div>
<?php endif;?>
	<input type="hidden" name="page"   value="<?php if(isset($page)) {echo $page; }?>"  class="form-control">

	<input type="hidden" name="mycategoryid" value=""id="categoryid" class="form-control" required placeholder="Enter mycategoryid">
					  			<input type="hidden" name="profit" value=""id="profit" class="form-control" required placeholder="Enter mycategoryid">
	  		

					
  
  <div class="form-group">
    <label for="inputstatus" class="col-sm-2 control-label">Product Status?</label>
    <div class="col-sm-10">
	<select class="form-control" name="status" id="mystatus" required>
			<option value="" selected="selected" ></option>

		<option value=""  >---Select Product Status---</option>
		
<?php
 if($Dispatched==true){
 ?>
 				<option value="Dispatched"   >Dispatched</option>

<?php
 }
 ?>
 <?php
 if($FailedDelivery==true){
 ?>
 				<option value="Failed Delivery"   >Failed Delivery</option>

<?php
 }
 ?>
 <?php
 if($ReturnedandReceived==true){
 ?>
 				<option value="Returned and Received"  >Returned and Received</option>

<?php
 }
 ?>
 <?php
 if($Delivered==true){
 ?>
 		<option value="Delivered"  >Delivered</option>

<?php
 }
 ?>
 <?php
 if($Claimraised==true){
 ?>
 						<option value="Claim raised"  >Claim raised</option>

<?php
 }
 ?>
 <?php
 if($ClaimOK==true){
 ?>
 												<option value="Claim OK"  >Claim raised OK</option>

<?php
 }
 ?>
 
  <?php
 if($ClaimDamaged==true){
 ?>
 												<option value="Claim Damaged"  >Claim raised Damaged</option>

<?php
 }
 ?>
 



</select>
		
						<span class="text-danger"><?php echo form_error('status'); ?>

	</div>
  </div>
  	

  
				<input type="hidden" name="view" value="user/recorddelivery"id="view" class="form-control" required placeholder="Enter view">
	

	<div class="form-group">
    <label for="inputcode" class="col-sm-2 control-label">	 Code</label>
    <div class="col-sm-10">
	
		  		<input type="text" readonly name="code" id="code"value="<?php echo set_value('code'); ?>" class="form-control" required placeholder="Enter Product Code">
		 
				
		<span class="text-danger"> <?php echo form_error('code'); ?>
		
		</span>
	</div>
  </div>
<div class="form-group">
    <label for="inputserial" class="col-sm-2 control-label">	 Serial NO</label>
    <div class="col-sm-10">
	
		  		<input type="text" readonly id="myserial" name="serial" value="<?php echo set_value('serial'); ?>" class="form-control" required placeholder="Enter serial Number">
		 
				
		<span class="text-danger"> <?php echo form_error('serial'); ?>
		
		</span>
	</div>
  </div>
	<div class="form-group">
    <label for="inputname" class="col-sm-2 control-label">	 Name</label>
    <div class="col-sm-10">
		
				<input type="text" id="name" name="name" value="<?php echo set_value('name') ;?>"  class="form-control" required placeholder="Enter  product name">

		<span class="text-danger"> <?php echo form_error('name'); ?>
		
		</span>
	</div>
  </div>
  
  
  
  
		<div class="form-group">
    <label for="inputorderno" class="col-sm-2 control-label">	Order Number</label>
    <div class="col-sm-10">

				<input type="text" id="myorderno" name="orderno" value="<?php echo set_value('orderno'); ?>"  class="form-control"  placeholder="Enter order number">
			
		<span class="text-danger"> <?php echo form_error('orderno'); ?>
		
		</span>
	</div>
  </div>
	
	
  
  

  

  
  
  
  
<div class="form-group">
    <label for="inputuser" class="col-sm-2 control-label">User?</label>
    <div class="col-sm-10">
	<select class="form-control" name="staff" id="staff"  required>
	
	<option value=""  selected="selected"></option>
	<option value=""  >---Select user---</option>

	
	
	<?php 
				
				
	
	 			//$allusers = $this->usermodel->populatealldatanoarraythree('people', 'userid',$userid,'status',1,'category','user');
			$allusers = $this->usermodel->populatealldatanoarraythree('people', 'companyid',$companyid,'status',1,'category','user');

	
if(is_array($allusers)) {

   foreach($allusers as $userrow){

   //echo $courserow->coursename;
    ?>
						<option value="<?=  $userrow->id;   ?>"><?=  $userrow->firstname ."- ".$userrow->surname ."(". $userrow->email.")"; ?></option>




	<?php

}} else {
    echo 'No user available.';
}
	
?>
</select>
		
						<span class="text-danger"><?php echo form_error('people'); ?>

	</div>
  </div>

  

  
     <div class="form-group">
    <label for="inputsupplier" class="col-sm-2 control-label">supplier?</label>
    <div class="col-sm-10">
	<select class="form-control" name="supplier" id="supplier"   required>
	
	<option value=""  >---Select supplier---</option>

	
	<?php 
					 
			//$allsuppliers =  $this->usermodel->populatemysupplier($companyid);
										$allsuppliers  = $this->usermodel->populatealldatanoarrayorderby('people','company','ASC','category','member','companyid', $companyid);


	
if(is_array($allsuppliers)) {

   foreach($allsuppliers as $suppliersrow){

   //echo $courserow->coursename;
    ?>
					<option value="<?=  $suppliersrow->id;   ?>"><?=  $suppliersrow->company ."(". $suppliersrow->firstname ."- ".$suppliersrow->phone.")"; ?></option>



	<?php

}} else {
    echo 'No supplier available.';
}
	
?>
</select>
		
						<span class="text-danger"><?php echo form_error('supplier'); ?>

	</div>
  </div>
  
  
  
  
  
  
  
  
  
  
	<div class="form-group">
    <label for="inputbuyingprice" class="col-sm-2 control-label">Unit (B.)Price</label>
    <div class="col-sm-10">

				<input type="text" required id="buyingprice" name="buyingprice" value="<?php echo set_value('buyingprice'); ?>"  class="form-control"  placeholder="Enter buying price">
			
		<span class="text-danger"> <?php echo form_error('buyingprice'); ?>
		
		</span>
	</div>
  </div>
  	
	
	
	<div class="form-group">
    <label for="inputsellingprice" class="col-sm-2 control-label">	Regular (S.)  Price</label>
    <div class="col-sm-10">

				<input type="text" id="sellingprice" name="sellingprice" required value="<?php echo set_value('sellingprice'); ?>"  class="form-control"  placeholder="Enter selling price">
			
		<span class="text-danger"> <?php echo form_error('sellingprice'); ?>
		
		</span>
	</div>
  </div>
	
  		<div class="form-group">
    <label for="inputcommissionrate" class="col-sm-2 control-label">	Commission Rate</label>
    <div class="col-sm-10">

				<input type="text" id="commissionrate"  name="commissionrate" required value="<?php echo set_value('commissionrate'); ?>"  class="form-control"  placeholder="Enter commission rate">
			
		<span class="text-danger"> <?php echo form_error('commissionrate'); ?>
		
		</span>
	</div>
  </div>
	<div class="form-group">
    <label for="inputcommission" class="col-sm-2 control-label">	Commission</label>
    <div class="col-sm-10">

				<input type="text" id="commission"  name="commission" required value="<?php echo set_value('commission'); ?>"  class="form-control"  placeholder="Enter commission">
			
		<span class="text-danger"> <?php echo form_error('commission'); ?>
		
		</span>
	</div>
  </div>
	
	<div class="form-group">
    <label for="inputshipping" class="col-sm-2 control-label">	Shipping cost contribution</label>
    <div class="col-sm-10">

				<input type="text" id="shipping" name="shipping" required value="<?php echo set_value('shipping'); ?>"  class="form-control"  placeholder="Enter shipping cost">
			
		<span class="text-danger"> <?php echo form_error('shipping'); ?>
		
		</span>
	</div>
  </div>
	
	
	<div class="form-group">
    <label for="inputqty" class="col-sm-2 control-label">	Quantity</label>
    <div class="col-sm-10">

				<input type="text" id="qty" name="qty" value=""  class="form-control" required  placeholder="Enter quantity in stock">
			
		<span class="text-danger"> <?php echo form_error('qty'); ?>
		
		</span>
	</div>
  </div>
  	

  <div class="form-group">
    <label for="inputbranch" class="col-sm-2 control-label">From Branch?</label>
    <div class="col-sm-10">
	<select class="form-control" name="branch" id="branch"  required>
	
	<option value="" selected="selected" >---Select Branch/Counter Name to dispatch--</option>
	<option value="no"  >Dont Dispatch to Stocklist directly</option>

	
	<?php 
					 
					 		$maincategory = $this->usermodel->populateall('branch','companyid',$companyid);


							


if(is_array($maincategory)) {

   foreach($maincategory as $maincategoryrow){

   //echo $courserow->coursename;
    ?>
					<option  selected="selected" value="<?=  $maincategoryrow->id;   ?>"><?=  $maincategoryrow->name; ?></option>



	<?php

}} else {
    echo 'No Branch/Counter.';
}
	
?>
</select>
		

		
	</div>
  </div>
  
  
  	
		
	<div class="form-group">
    <label for="inputdescription" class="col-sm-2 control-label">	Description</label>
    <div class="col-sm-10">

				<textarea name="description" id="mydescription" value="<?php echo set_value('description'); ?>"  class="form-control"  placeholder="Enter description"></textarea>
			
		<span class="text-danger"> <?php echo form_error('description'); ?>
		
		</span>
	</div>
  </div>
	
	
	
		
		
	<div class="form-group">
    <label for="inputitemid" class="col-sm-2 control-label">	Activity Logs</label>
    <div class="col-sm-10">

				<textarea readonly name="itemid" id="myitemid" value="<?php echo set_value('itemid'); ?>"  class="form-control"  placeholder="Enter loggs"></textarea>
			
		<span class="text-danger"> <?php echo form_error('itemid'); ?>
		
		</span>
	</div>
  </div>
	
	
	
	
	
	
	

  	
	
	
	<div class="form-group">
    <label for="inputordereddate" class="col-sm-2 control-label">	Dispatch date </label>
    <div class="col-sm-10">

				<input type="text"   id="ordereddate" name="ordereddate" value="<?php echo set_value('ordereddate',$dateposted); ?>"  class="form-control"   placeholder="Enter ordered  date">
			
		<span class="text-danger"> Enter  date  if any<?php echo form_error('ordereddate'); ?>
		
		</span>
	</div>
  </div>
	
	
	
	
	
	
	
	

	

	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="delivery" name="btn_updatedeliverydetails" class="btn btn-primary"> Update Delivery    </button>

    </div>
  </div>
  					<?php echo form_close();?>
			</div>							   
				
									
							
								
			<div class="modal-footer">

    

				</div>

		</div>
	    </div>
    </div>




			
			
			

<div id="editProductModel" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Update Delivery status</h4>
      </div>
      <div class="modal-body">
      
	  	

				<?PHP
//$session_data = $this->session->userdata('logged_in');

///

				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/updatedeliverystatus' , array('class' => 'form-horizontal form-groups-bordered validate', 'enctype' => 'multipart/form-data'));
				 if(validation_errors()):?>
<div class='alert alert-danger text-center'><?php echo validation_errors(); ?></div>
<?php endif;?>
	<input type="hidden" name="mycategoryid" value=""id="mycategoryid" class="form-control" required placeholder="Enter mycategoryid">
	<input type="hidden" name="page"   value="<?php if(isset($page)) {echo $page; }?>"  class="form-control">


					
  
  <div class="form-group">
    <label for="inputstatus" class="col-sm-2 control-label">Product Status?</label>
    <div class="col-sm-10">
	<select class="form-control" name="status" id="status" required>
			<option value="" selected="selected" ></option>

		<option value=""  >---Select Product Status---</option>
				
<?php
 if($Dispatched==true){
 ?>
 				<option value="Dispatched"   >Dispatched</option>

<?php
 }
 ?>
 <?php
 if($FailedDelivery==true){
 ?>
 				<option value="Failed Delivery"   >Failed Delivery</option>

<?php
 }
 ?>
 <?php
 if($ReturnedandReceived==true){
 ?>
 				<option value="Returned and Received"  >Returned and Received</option>

<?php
 }
 ?>
 <?php
 if($Delivered==true){
 ?>
 		<option value="Delivered"  >Delivered</option>

<?php
 }
 ?>
 <?php
 if($Claimraised==true){
 ?>
 						<option value="Claim raised"  >Claim raised</option>

<?php
 }
 ?>
 <?php
 if($ClaimOK==true){
 ?>
 												<option value="Claim OK"  >Claim raised OK</option>

<?php
 }
 ?>
 
  <?php
 if($ClaimDamaged==true){
 ?>
 												<option value="Claim Damaged"  >Claim raised Damaged</option>

<?php
 }
 ?>
 

</select>
		
						<span class="text-danger"><?php echo form_error('status'); ?>

	</div>
  </div>
  	

  

	<div class="form-group">
    <label for="inputdescription" class="col-sm-2 control-label">	Description</label>
    <div class="col-sm-10">

				<textarea name="description" value="<?php echo set_value('description'); ?>"  id="description" class="form-control"  placeholder="Enter description"></textarea>
			
		<span class="text-danger"> <?php echo form_error('description'); ?>
		
		</span>
	</div>
  </div>
		<div class="form-group">
    <label for="inputserial" class="col-sm-2 control-label">	Serial No</label>
    <div class="col-sm-10">

 <input type="text" class="form-control"  readonly id="serial"name="serial" class="table" placeholder="serial Number" value="">
			
		<span class="text-danger"> <?php echo form_error('serial'); ?>
		
		</span>
	</div>
  </div>

	

	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="delivery" name="btn_updatestatusdelivery" class="btn btn-primary"> Update Delivery Status   </button>

    </div>
  </div>
  					<?php echo form_close();?>
			</div>							   
				
									
							
								
			<div class="modal-footer">

    

				</div>

		</div>
	    </div>
    </div>













			<div id="myDelete" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Cancel</h4>
      </div>
      <div class="modal-body">
        <h3>Are you sure you want to Cancel this item? </h3>
      </div>
      <div class="modal-footer">
	  	

     
		<?PHP
				$session_data = $this->session->userdata('logged_in');
 echo $this->session->flashdata('deletemsg'); 

		
                 echo form_open('user/deletebyid' , array('class' => 'form-horizontal ', 'enctype' => 'multipart/form-data'));
				 if(validation_errors()):?>
<div class='alert alert-danger text-center'><?php echo validation_errors(); ?></div>
<?php endif;?>
 <input type="hidden" id="table"name="table" class="table" placeholder="view" value="delivery">

				<input type="hidden" name="view" value="user/recorddelivery" id="view" class="form-control" required placeholder="Enter view">

 <input type="hidden" id="itemid1"name="itemid" class="itemid" placeholder="itemid" value=""><br>
 <button type="button" class="btn btn-default" data-dismiss="modal">No</button>
 		  	         <button type="submit" name="btn_delete" value="deletebyid" class="btn btn-danger"> Delete  </button>

	<?php echo form_close();?>
      </div>
    </div>

  </div>

  </div>	

	
 






	
			<div id="deliveryModal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Delivery Report</h4>
      </div>
      <div class="modal-body">
      
	  	

				<?PHP
//$session_data = $this->session->userdata('logged_in');
					  $mydate=date("Y-m-d H:i:s");
					  $frommydate=date("Y-m-d 00:00:00");

				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/viewdeliveryreport' , array('class' => 'form-horizontal form-groups-bordered validate', 'enctype' => 'multipart/form-data'));
				 if(validation_errors()):?>
<div class='alert alert-danger text-center'><?php echo validation_errors(); ?></div>
<?php endif;?>

	
	
	 <div class="form-group">
    <label for="inputdaterange" class="col-sm-2 control-label">Use date range?</label>
    <div class="col-sm-10">
	<select class="form-control" name="daterange" required>
	
	<option value=""  >---Do  you want a specific period---</option>
			<option value="yes"   >--Yes,I want to view between specific dates---</option>

		<option value="no"  selected="selected" >--No, I want to view everything---</option>

</select>
		

	</div>
  </diV>
		
	 <div class="form-group">
    <label for="inputdatetype" class="col-sm-2 control-label">Select date type</label>
    <div class="col-sm-10">
	<select class="form-control" name="datetype" required>
	
	<option value=""  >---Specify the date to use---</option>
			<option value="yes"  selected="selected"  >Use Original dates</option>

			<option value="no"   >Use Updated/current dates---</option>

</select>
		

	</div>
  </diV>
	
  <div class="form-group">
    <label for="inputfromdate" class="col-sm-2 control-label">From Date </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="fromdate" value="<?php echo set_value('fromdate',$frommydate); ?>" class="form-control" required placeholder="Enter start date">
		 
				
		<span class="text-danger"> <?php echo form_error('fromdate'); ?>
		
		</span>
	</div>
  </div>
  
  	<div class="form-group">
    <label for="inputtodate" class="col-sm-2 control-label">	To Date </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="todate" value="<?php echo set_value('todate',$mydate); ?>" class="form-control" required placeholder="Enter End date">
		 
				
		<span class="text-danger"> <?php echo form_error('todate'); ?>
		
		</span>
	</div>
  </div>
  
  
    <div class="form-group">
    <label for="inputsupplier" class="col-sm-2 control-label">supplier?</label>
    <div class="col-sm-10">
	<select class="form-control" name="supplier" required>
	
	<option value=""  >---Select supplier---</option>

		<option value="all" selected="selected"  >--I want view all/any supplier---</option>
	<?php 
					 
			$mysuppliers =  $this->usermodel->populatemysupplier($companyid);
	

	
if(is_array($mysuppliers)) {

   foreach($mysuppliers as $suppliersrow){

   //echo $courserow->coursename;
    ?>
					<option value="<?=  $suppliersrow->id;   ?>"><?=  $suppliersrow->company ."(". $suppliersrow->firstname ."- ".$suppliersrow->phone.")"; ?></option>



	<?php

}} else {
    echo 'No supplier available.';
}
	
?>
</select>
		
						<span class="text-danger"><?php echo form_error('supplier'); ?>

	</div>
  </div>
  

	   <div class="form-group">
    <label for="inputvattype" class="col-sm-2 control-label"> Status?</label>
    <div class="col-sm-10">
		<select class="form-control" name="status" required>
			<option value="all" selected="selected" > ---All Status---</option>

					<option value="Dispatched"   >Dispatched</option>

	

				<option value="Failed Delivery"   >Failed Delivery</option>
				<option value="Returned and Received"  >Returned and Received</option>

		<option value="Delivered"  >Delivered</option>
						<option value="Claim raised"  >Claim raised</option>

 												<option value="Claim Damaged"  >Claim raised Damaged</option>


	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	

</select>
		
						<span class="text-danger"><?php echo form_error('vattype'); ?>

	</div>
  </div>
  
	 <div class="form-group">
    <label for="inputdownload" class="col-sm-2 control-label">Download?</label>
    <div class="col-sm-10">
	<select class="form-control" name="download" required>
	
	<option value=""  >---Select your option---</option>

		<option value="no" selected="selected" >--I want to view the delivery---</option>
			<option value="yes"  >--I want to download the delivery---</option>

</select>
		

	</div>
  </diV>
	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="event" name="btn_addevent" class="btn btn-default"> View Delivery  </button>

    </div>
  </div>
  					<?php echo form_close();?>
			</div>							   
				
									
							
								
			<div class="modal-footer">

    

				</div>

		</div>
	    </div>
    </div>	
	
	
	
	
			
					
					
			
		</div>
	    </div>
    
			
	

 
















