<?php
class Sale_inside
{
	public function __construct()
	{
		
		?>
        <script language="javascript" src="js/index_2.js?t=<?=time();?>" type="text/javascript"></script>
        <script language="javascript" src="js/index_extra2.js?t=<?=time();?>" type="text/javascript"></script>
		
		<script language="javascript" src="js/sugestion2.js?t=<?=time();?>" type="text/javascript">
        
			
        </script>
        
        <?php
	}
	
	function common_select($table,$fields,$matchField,$code,$class,$sel,$function,$id,$displayName,$value)
	{
		if($matchField=="")
		 	$qry = "SELECT ".$fields." FROM $table";
		else 
			$qry = "SELECT ".$fields." FROM ".$table." WHERE ".$matchField."='".$code."'";
			
		//echo $qry;
		$res=mysql_query($qry);
		
		$out = '<select id="'.$id.'" name="'.$id.'" class="'.$class.'" '.$function.'>';
		$out .='<option value="" >--Select--</option>';
		
		while($result=mysql_fetch_array($res))
		{	
			if(strtolower($result[$value])==strtolower($sel))
				$out .='<option value="'.$result[$value].'" selected="selected">'.$result[$displayName].'</option>';
			else
				$out .='<option value="'.$result[$value].'" >'.$result[$displayName].'</option>';
		}
		$out .= '</select>';
		return $out;	
	}
			
	/*-------------------------------------------------------------------------------------KMS list----*/
	
	public function showSale_insideList()
	{
	?>
    <script type="text/javascript" language="javascript">
		$(function() { $("#date_1").datepicker({dateFormat: 'dd-mm-yy'}); });
		$(function() { $("#date_2").datepicker({dateFormat: 'dd-mm-yy'}); });		
		$(function() { $("#date").datepicker({dateFormat: 'dd-mm-yy'}); });		
	</script>
    <style>

#result {

	height:20px;

	font-size:16px;

	font-family:Arial, Helvetica, sans-serif;

	color:#333;

	padding:5px;

	margin-bottom:0px;

	background-color:#FFFF99;

}

 

.suggestionsBox {

	position: absolute;

	left: 0px;

	top:0px;

	margin: 6px 0px 0px 0px;

	width: 300px;

	padding:0px;

	background-color: #000;

	border-top: 3px solid #000;

	color: #fff;

	z-index:999!important;

	

}

.suggestionList {

	margin: 0px;

	padding: 0px;

	z-index:3000 !important;

}

.suggestionList ul li {

	list-style:none;

	margin: 0px;

	padding: 6px;

	border-bottom:1px dotted #666;

	cursor: pointer;

	z-index:3000 !important;

}

.suggestionList ul li:hover {

	background-color: #FC3;

	color:#000;

}

ul {

	font-family:Arial, Helvetica, sans-serif;

	font-size:11px;

	color:#FFF;

	padding:0;

	margin:0;

	z-index:3000 !important;

}



.load{

background-image:url(loader.gif);

background-position:right;

background-repeat:no-repeat;

}



.suggest {

	position:relative;

	z-index:20;

}



    </style>
    <div style="clear:both;"></div>
	
            <div class="atstextfield-wrapper">	
                <div class="textfieldtab">
                  <h92>Direct Sale</h92>
                </div>
                <div class="textfieldtab">
                </div> 
                <input type="hidden" id="ref_id" value="<?=$_REQUEST['ref_id'];?>"  />
                <?php $_SESSION['customer_ref_id'] = $_REQUEST['ref_id'];?>
               <div class="textfieldtab-two" style="width:300px;height:25px;">Search: 
                    <input type="text" id="searchtext" />
                </div>
               
                 <div class="textfieldtab" > 
						 
                         <select id="payment_status2" style="display:none;"  > 
                          <option value="3"  selected="selected">All</option>
                          <option value="1">Pending</option>
                          <option value="2">Done</option>
                          
                        </select>
                        </div>
                  <div class="textfieldtab" > 
						Shipping Status
                         <select id="shipping_status2"  > 
                          <option value="4"  selected="selected">All</option>
                          <option value="1">Pending</option>
                         
                          <option value="2">Delivered</option>
                          
                        </select>
                        </div>      
                   <div class="textfieldtab" > 
						 
                         <select id="order_status2"  style="display:none;" > 
                          <option value="5"  >All</option>
                          <option value="1" selected="selected" >New or Confirmed</option>
                          <option value="2">New</option>
                          <option value="3">Confirmed</option>
                          <option value="4">Fake Order</option>
                          
                        </select>
                        </div>   
                        <div class="textfieldtab">
                 
                           From:<input type="text" class="date_feild" id="s_date_from" name="s_date_from" value="<? echo date("d-m-Y");?>"/>
                           To:<input type="text"  class="date_feild" id="s_date_to" name="s_date_to" value="<? echo date("d-m-Y");?>"/>			
                        </div>
                <div class="textfieldtab">
                    <input name="" type="image" src="../../main_images/search_btt1.png" onclick="Sale_insideDetails()" />
                </div>
            </div>    
            <div style="clear:both;"></div>
            <div id="main_result_div">
            <script language="javascript" type="text/javascript">Sale_insideDetails();</script>
            </div>
    
    
    <?php
	}
	
	//Add 
		public function add_edit($data='',$error="")
		{
			
			$data['id'] = $data['code'];
			
			if($data['date'])
				$date = $data['date'];
			else
				$date = date("d-m-Y");
				
		?>
            <div id="add_edit">
                <form action="" name="add_edit_form" id="add_edit_form" >
              	<div id="add_edit">
                <?php if($data['id']>0) { ?>
                	<input type="hidden" name="task2" id="task2" value="update"  />
                    <input type="hidden" name="id" id="id" value="<?=$data['id'];?>"  />
                   <?php }else{ ?>
                   <input type="hidden"  name="task2" id="task2" value="Add"  />
                   <input type="hidden" name="id" id="id" value=""  />
                   <?php } ?>
                   
                </div>
                <table id="" cellspacing="0" style="border-top:10px solid #777;">
    		    <tr>
                   	<th colspan="4"><?php if($data['id']>0) echo 'Edit Sale'; else echo 'Add New Sale'; ?></th>
                </tr>
                
                <tr>
                   	<td >Customer Type :  </td>
                    <td colspan="3">
                    
                    
                    <select name="customer_type" id="customer_type"  class="mandatory" >
                    	 
                        <option value="old" <?=($data['customer_type']=='self' or $data['customer_type']=='')?'selected="selected"':'';?>>Existing Customer</option>
                        <option value="new" >New Customer</option>
                        
                       <!-- <option value="new" <?=($data['payment']=='ship')?'selected="selected"':'';?>> New customer</option>-->
                        </select>                         </td>
                </tr>
                 
                 
                
                 <tr class="old">
                   	<td >Customer code :  </td>
                    <td colspan="3"><?php $name='customer_code';?><input type="text" id="<?=$name;?>" name="<?=$name;?>" value="<?=$data[$name];?>" style="width:200px;" maxlength="90" class="mandatory oldf" /></td>
                </tr>
                  
                 <tr  >
                   	<td >Customer Details : </td>
                    <td colspan="3"><span style="font-size:13px;" id="res_jbc"></span></td>
                 </tr>
                 <tr>
                    <td  style="border-top:2px solid #333333; " colspan="4"></td>
                </tr>
                
                <?php $name='policy_code';?><input type="text" id="<?=$name;?>" name="<?=$name;?>" value="<?=$data[$name];?>" style=" visibility:hidden;"     readonly="readonly"  />
                
                
                 <tr>
                   	<td >Billing Name :  </td>
                    <td ><?php $name='name';?><input type="text" id="<?=$name;?>" name="<?=$name;?>" value="<?=$data[$name];?>" style="width:200px; background-color:#FEFAE2" maxlength="90" class="mandatory" readonly="readonly"  /></td>
                    <td >Billing Mobile Number : </td>
                    <td ><?php $name='mobile';?><input  type="text" id="<?=$name;?>" name="<?=$name;?>" value="<?=$data[$name];?>" style="width:200px;background-color:#FEFAE2" maxlength="10" readonly="readonly" class="mandatory numaric" /></td>
                 </tr>
                 
                 <tr>
                   	<td >Billing Address (Line 1) </td>
                    <td colspan="3"><?php $name='add_1';?><input type="text" id="<?=$name;?>" name="<?=$name;?>" value="<?=$data[$name];?>" style="width:90%;" maxlength="90" class="mandatory" /></td>
                </tr>
                 
                
                <tr style="border:3px dotted #999999;">
                   	<td   >Billing Address (Line 2) </td>
                    <td   colspan="3"><?php $name='add_2';?><input type="text" id="<?=$name;?>" name="<?=$name;?>" value="<?=$data[$name];?>" style="width:90%;" maxlength="90" class="" /></td>
                </tr>
                
                 <tr   >
                   	<td >Billing City :  </td>
                    <td ><?php $name='city';?><input type="text" id="<?=$name;?>" name="<?=$name;?>" value="<?=$data[$name];?>" style="width:200px; background-color:#FEFAE2" maxlength="90"   class="mandatory"   /></td>
                    <td >Billing State : </td>
                    <td ><?php $name='state';?><input  type="text" id="<?=$name;?>" name="<?=$name;?>" value="<?=$data[$name];?>" style="width:200px;background-color:#FEFAE2" maxlength="20" class="mandatory"      /></td>
                 </tr>
                 
                  <tr   >
                   	<td >Billing Country :  </td>
                    <td ><?php $name='country';?><input type="text" id="<?=$name;?>" name="<?=$name;?>" value="<?=$data[$name];?>" style="width:200px; background-color:#FEFAE2" maxlength="90" class="mandatory"   /></td>
                    <td >Billing Postal Code : </td>
                    <td ><?php $name='postal_code';?><input  type="text" id="<?=$name;?>" name="<?=$name;?>" value="<?=$data[$name];?>" style="width:200px;background-color:#FEFAE2" maxlength="10" class="mandatory numaric" /></td>
                 </tr>
                 <tr>
                    <td  style="border-bottom:2px solid #333333; " colspan="4"><label><input type="checkbox" id="shipping_same" name="shipping_same" <?=($data['shipping_same']==1 or $data['shipping_same']=='')?'checked="checked"':'';?> value="1"> <strong>Shipping Address is same as Billing Address </strong></label></td>
                </tr>
                 <tr class="shipping_cl">
                   	<td >Shipping Name :  </td>
                    <td ><?php $name='shipping_name';?><input type="text" id="<?=$name;?>" name="<?=$name;?>" value="<?=$data[$name];?>" style="width:200px; background-color:#FEFAE2" maxlength="90" class="mandatory  ship" readonly="readonly"  /></td>
                    <td >Shipping Mobile Number : </td>
                    <td ><?php $name='shipping_mobile';?><input  type="text" id="<?=$name;?>" name="<?=$name;?>" value="<?=$data[$name];?>" style="width:200px;background-color:#FEFAE2" maxlength="10" readonly="readonly" class="mandatory numaric  ship" /></td>
                 </tr>
                 
                 <tr class="shipping_cl">
                   	<td >Shipping Address (Line 1) </td>
                    <td colspan="3"><?php $name='shipping_add_1';?><input type="text" id="<?=$name;?>" name="<?=$name;?>" value="<?=$data[$name];?>" style="width:90%;" maxlength="90" class="mandatory  ship" /></td>
                </tr>
                 
                
                <tr  class="shipping_cl" style="border:3px dotted #999999;">
                   	<td   >Shipping Address (Line 2) </td>
                    <td   colspan="3"><?php $name='shipping_add_2';?><input type="text" id="<?=$name;?>" name="<?=$name;?>" value="<?=$data[$name];?>" style="width:90%;" maxlength="90" class=" " /></td>
                </tr>
                
                 <tr   class="shipping_cl" >
                   	<td >Shipping City :  </td>
                    <td ><?php $name='shipping_city';?><input type="text" id="<?=$name;?>" name="<?=$name;?>" value="<?=$data[$name];?>" style="width:200px; background-color:#FEFAE2" maxlength="90"    class="mandatory ship"     /></td>
                    <td >Shipping State : </td>
                    <td ><?php $name='shipping_state';?><input  type="text" id="<?=$name;?>" name="<?=$name;?>" value="<?=$data[$name];?>" style="width:200px;background-color:#FEFAE2" maxlength="20" class="mandatory ship"      /></td>
                 </tr>
                 
                  <tr  class="shipping_cl"  >
                   	<td >Shipping Country :  </td>
                    <td ><?php $name='shipping_country';?><input type="text" id="<?=$name;?>" name="<?=$name;?>" value="<?=$data[$name];?>" style="width:200px; background-color:#FEFAE2" maxlength="90" class="mandatory ship"   /></td>
                    <td >Shipping Postal Code : </td>
                    <td ><?php $name='shipping_postal_code';?><input  type="text" id="<?=$name;?>" name="<?=$name;?>" value="<?=$data[$name];?>" style="width:200px;background-color:#FEFAE2" maxlength="10" class="mandatory numaric ship" /></td>
                 </tr>
                 <tr>
                    <td  style="border-bottom:2px solid #333333; " colspan="4"></td>
                </tr>
                
                
              <tr>
                   	<td valign="top" >Products :</td>
                    <td colspan="3">
                    
                       <table width="100%" border="0" cellspacing="0" cellpadding="2">

  <tr>

    <th width="4%">SNo.</th>

    <th width="87%"  >Product</th>

    <th width="9%">Price</th>
    <th width="9%">Qty </th>
    <th width="9%">Total</th>
    </tr>

  <?php

  $k=1;

  

  $total = 0;

  $sql_product = "SELECT * FROM despatch_details  WHERE purchase_code='".$data['code']."' and   purchase_code>0	  ";
  $row_product = mysql_query($sql_product);
  while($row_p = mysql_fetch_assoc($row_product))
  {

  ?>

  <tr>

    <td valign="top" id="sr_<?=$k;?>"><?=$k;?></td>

    <td valign="top"><input name="product_code_<?=$k;?>" id="product_code_<?=$k;?>" value="<?=$row_p['product_code'];?>" type="hidden" class="codes" /><input name="product_<?=$k;?>"  <?=$disabled;?> id="product_<?=$k;?>" value="<?=$row_p['product_name'];?>" style="width:600px;" type="text" onkeyup="suggest_product(<?=$k;?>,this.value);" onblur="fill_product(<?=$k;?>,'');"    />
     
     <div  id="product_detail_<?=$k;?>"></div>
      
      
       
      <div id="suggest_<?=$k;?>"  class="suggest"> <div class="suggestionsBox" id="suggestions_<?=$k;?>" style="display:none;"> <img src="arrow.png" style="position: relative; top: -12px; left: 30px;" alt="upArrow" />
        
        <div class="suggestionList" id="suggestionsList_<?=$k;?>"> &nbsp; </div>
        
        </div>
      </div>      </td>
	<td valign="top"><input name="product_price_<?=$k;?>"  <?=$disabled;?> id="product_price_<?=$k;?>" style="width:90px; text-align:center;" value="<?=abs($row_p['price']);?>" type="txt" class="numaric" />
    <input name="product_price_<?=$k;?>"  <?=$disabled;?> id="product_price_<?=$k;?>" style="width:60px; text-align:center; display:none;" value="<?=abs($row_p['price']);?>" type="txt" class="numaric" />    </td>
    
    <td valign="top"><input name="product_qty_<?=$k;?>"  <?=$disabled;?> id="product_qty_<?=$k;?>" style="width:90px; text-align:center;" value="<?=abs($row_p['qty']);?>" type="txt" class="numaric" /></td>
   </tr> 
    <?php 

  $k++;

  }

  

  while($k<=10) { ?>

  <tr>

    <td valign="top" id="sr_<?=$k;?>"><?=$k;?></td>

    <td valign="top"><input name="product_code_<?=$k;?>" id="product_code_<?=$k;?>" value="<?=$row_p['product_code'];?>" type="hidden" class="codes" /><input name="product_<?=$k;?>"  <?=$disabled;?> id="product_<?=$k;?>" value="<?=$row_p['product_name'];?>" style="width:400px;" type="text" onkeyup="suggest_product(<?=$k;?>,this.value);"  onblur="fill_product(<?=$k;?>,'');"    />
      <div  id="product_detail_<?=$k;?>"></div>
      <div id="suggest_<?=$k;?>"  class="suggest"> <div class="suggestionsBox" id="suggestions_<?=$k;?>" style="display:none;"> <img src="arrow.png" style="position: relative; top: -12px; left: 30px;" alt="upArrow" />
        
        <div class="suggestionList" id="suggestionsList_<?=$k;?>"> &nbsp; </div>
        
        </div>
      </div>    </td> 
	<td valign="top"><input name="product_ourprice_<?=$k;?>"  <?=$disabled;?> id="product_ourprice_<?=$k;?>" style="width:120px; text-align:center;" value="<?=abs($row_p['ourprice']);?>" type="txt" class="numaric" readonly="readonly"/>
    <input name="product_price_<?=$k;?>"  <?=$disabled;?> id="product_price_<?=$k;?>" style="width:90px; text-align:center; display:none;" value="<?=abs($row_p['price']);?>" type="txt" class="numaric" />    </td>
    
    <td valign="top"><input name="product_qty_<?=$k;?>"  <?=$disabled;?> id="product_qty_<?=$k;?>" style="width:60px; text-align:center;" value="<?=abs($row_p['qty']);?>" type="txt" class="numaric qty" /></td>
    
    <td valign="top"><input name="product_total_<?=$k;?>"  <?=$disabled;?> id="product_total_<?=$k;?>" style="width:120px; text-align:center;" value="<?=abs($row_p['ourprice'] * $row_p['qty']);?>" readonly="readonly" type="txt" class="numaric" /></td>
   </tr> 
<input name="product_total_before_tax_<?=$k;?>"  <?=$disabled;?> id="product_total_before_tax_<?=$k;?>" style=" display:none;" value="<?=abs($row_p['ourprice'] * $row_p['qty']);?>" readonly="readonly" type="txt" class="numaric" />
  

  

  <?php 
  $total+= ($row_p['ourprice'] * $row_p['qty']);
  $k++; } ?>

   <tr>
        <td colspan="4" style="text-align:right;color:#000; font-size:14px; "  >Sub Total : </td> 
        <td  colspan="2" style="text-align:right; color:#000; font-size:14px;"  id="t_amount"></td>
   </tr>   
   
   <tr>
    	<td colspan="6" style="text-align:right;color:#F00;  font-size:14px; " id="promotional_wallet_place"></td> 
   </tr>
   
   
   	<tr>

    <td colspan="6" style="text-align:right;color:#F00;  font-size:14px; " id="booking_list"></td> 
   </tr>
   
   
<tr>

    <td colspan="4" style="text-align:right;color:#F00;  font-size:14px; " id="offer_name">Adjustment for Policies</td>
 
    <td  colspan="2" style="text-align:right; color:#F00; font-size:14px;"  id="offer_amount"></td>
   </tr>
   
   <tr>
        <td colspan="4" style="text-align:right;color:#000; font-size:14px; font-weight:bold; "  >Shipping : </td> 
        <td  colspan="2" style="text-align:right; color:#000; font-size:14px; font-weight:bold;"  ><input style="text-align:right; color:#0000CC" type="text" id="shipping" name="shipping" class="policy_dis2" value="0"></td>
   </tr>
   
   <tr>
        <td colspan="4" style="text-align:right;color:#000; font-size:14px; font-weight:bold; "  >Sub Total after Discount before TAX : </td> 
        <td  colspan="2" style="text-align:right; color:#000; font-size:14px; font-weight:bold;"  id="t_amount_bt"></td>
   </tr>
   
   <tr>
        <td colspan="4" style="text-align:right;color:#000099; font-size:14px; "  >GST (3%) : </td> 
        <td  colspan="2" style="text-align:right; color:#000099; font-size:14px;"  id="t_tax"></td>
   </tr>
   

   
   
<tr>

    <td colspan="4" style="text-align:right;font-size:14px;">Payable Order Total : </td>
 
    <td  colspan="2"><input name="order_total"  <?=$disabled;?> id="order_total" style="width:150px; border:0px; background-color:#FFFF00; font-size:16px; font-weight:bold;text-align:right;" value="<?=abs($total);?>" type="txt" class="numaric" readonly="readonly" /></td>
   </tr>
</table><input name="pro_list" id="pro_list" value="10" type="hidden"  />                    </td>
                </tr>
                
                <tr>
                    
                    <td colspan="8">
                    <HR/>                    </td>
                </tr>
                 <tr>
                   	<td valign="top" >Product Taking for Self/other :</td>
                    <td>
                    <select name="product_taking_for" id="product_taking_for"  class="mandatory" >
                    	<option value="" >--Product Taking for--</option>
                        <option value="self" <?=($data['product_taking']=='self')?'selected="selected"':'';?>>Self</option>
                        <option value="other" <?=($data['product_taking']=='other')?'selected="selected"':'';?>>Other</option>
                        </select>
                    	
                     
                    
                    	<br />
                    	<br />
                    	<table width="500px;" border="0" cellspacing="0" cellpadding="0" class="shipping">
                        <tr>
                        	<th colspan="2">Who is taking Product?</th>
                        </tr>
                        <tr>
                   	<td valign="top" >Receiver Name :</td>
                    <td><?php $name='receiver_name';?><input type="text" id="<?=$name;?>" name="<?=$name;?>" value="<?=$data[$name];?>" style="width:200px;" maxlength="240" class="shippingf" /></td>
                </tr>
                <tr>
                   	<td valign="top" >Receiver Mobile :</td>
                    <td><?php $name='receiver_mobile';?><input type="text" id="<?=$name;?>" name="<?=$name;?>" value="<?=$data[$name];?>" style="width:200px;" maxlength="240" class="shippingf" /></td>
                </tr>
                
                
                <tr>
                   	<td valign="top" >OTP sent to Owner :</td>
                    <td><?php $name='otp';?><input type="text" id="<?=$name;?>" name="<?=$name;?>" value="<?=$data[$name];?>" style="width:50px;" maxlength="240" class="shippingf" />
<button id="send_otp" type="button" name="send_otp">Send One time password</button><br /><span id="opt_msg"></span></td>
                </tr>
                
                
                
                
          		  
</table>

                    </td>
                
                </tr> 
                
                <tr>
                   	<td valign="top" >Payment :</td>
                    <td colspan="3">
                    <select name="payment" id="payment"  class="mandatory" >
                    	<option value="" >--Payment Option--</option>
                        <option value="cash" <?=($data['payment']=='self')?'selected="selected"':'';?>>CASH</option>
                        <option value="other" <?=($data['payment']=='ship')?'selected="selected"':'';?>>Other</option>
                        </select>
                    	
                     
                    
                    	<br />
                    	<br />
                    	<table width="500px;" border="0" cellspacing="0" cellpadding="0" class="payment">
                        <tr>
                        	<th colspan="2">Payment Details</th>
                        </tr>
                        <tr>
                   	<td valign="top" >Received Mode:</td>
                    <td><?php $name='payment_mode';?><input type="text" id="<?=$name;?>" name="<?=$name;?>" value="<?=($data[$name])?$data[$name]:'Demmand Draft';?>" style="width:200px;" maxlength="240" class="paymentf" /></td>
                </tr>
                <tr>
                   	<td valign="top" >Ch/DD/Bank Number :</td>
                    <td><?php $name='dd_no';?><input type="text" id="<?=$name;?>" name="<?=$name;?>" value="<?=$data[$name];?>" style="width:200px;" maxlength="90" class="paymentf" /></td>
                </tr>
</table>                    </td>
                </tr>
                <tr>
                   	<td valign="top" >Remarks :</td>
                    <td colspan="3">
                    <textarea id="remarks"    name="remarks" style="width:300px; height:100px;"  error_name="text_message " class=" mandatory text_200" ><?=$data['remarks'];?></textarea>                    </td>
                </tr>
                
                <tr class="agree" style="display:none;">
                   	<td valign="top" ></td>
                    <td colspan="3" style="background-color:#FF0;">
                     <input type="checkbox" id="agree" name="agree" value="1"> I have Checked All above info and product requirement is correct.                    </td>
                </tr>
                <tr style="padding: 10px;">
                	<td></td>
                    <td colspan="3"><span id="res" class="sucess_2"><?=$error;?></span></td>
                </tr>
                <tr style="padding: 10px;">
                	<td style="width:120px;">&nbsp;</td>
                    <td colspan="3">
                    	<button type="button" id="btnInsertPro" name="btnInsertPro" onClick="addNew_Key()"><?php if($data['id']>0) echo 'Update Record'; else echo 'Save New Sale'; ?></button>&nbsp;&nbsp;&nbsp;&nbsp;<button type="button" id="as" name="as" onClick="Sale_insideDetails()">Go Back</button>                    </td>
                </tr>
            </table>
		</form>
        </div>
        
        </div>
        <?php
	}
	public function add_edit_view($data='',$error="")
		{
			
			$data['id'] = $data['code'];
			
			
			 
			$order =  $data;
				$q = "SELECT * FROM customer_order_items WHERE order_no='".$data['code']."' ORDER BY sort_id ";
			$qr = mysql_query($q) or die('Error: '.mysql_error());
			
				
		?>
            <div id="add_edit">
                <form  name="add_edit_form" id="add_edit_form" method="post" enctype="multipart/form-data" action='../ajaximage/ajaximage.php' >
              	<div id="add_edit">
                <?php if($data['id']>0) { ?>
                	<input type="hidden" name="task2" id="task2" value="update"  />
                    <input type="hidden" name="id" id="id" value="<?=$data['id'];?>"  />
                   <?php }else{ ?>
                   <input type="hidden"  name="task2" id="task2" value="Add"  />
                   <input type="hidden" name="id" id="id" value=""  />
                   <?php } ?>
                   
                </div>
                <table id="" cellspacing="0" style="border-top:10px solid #777; width:850px;">
    		    <tr>
                   	<th colspan="2"><?php if($data['id']>0) echo 'Edit Customer Order'; else echo 'Add New Customer Order'; ?></th>
                </tr>
                <tr>
                <td>
                <table id="" cellspacing="0" style="border-top:10px solid #777;">
                <tr>
                                        <td colspan="2" bgcolor="#FFFFFF">
                                            <?php
											
											if($order['code'])
												$cust = $order;
			?>
            
            <center><H2>Order No : <?=$order['order_no'];?></H2></center> 
            <div style="float:left; width:400px; border:1px dotted #CCCCCC; padding:10px;">
            
            <span class="bold_marron">Billing Address</span><br />
                                            <b><?=$cust['billing_name'];?></b><br />
 
<?=$cust['billing_mobile'];?><br />

 											<?=$cust['billing_add_1'];?>, <?=$cust['billing_add_2'];?><br />
                                            <?=$cust['billing_city'];?>, <?=$cust['billing_state'];?>, <?=$cust['billing_country'];?> - <?=$cust['billing_pin_code'];?> 
            
            <br />
<br />
  <span class="bold_marron">Shipping Address</span><br />
                                            <b><?=$cust['shipping_name'];?></b><br />
<?=$cust['shipping_mobile'];?><br />

 											<?=$cust['shipping_add_1'];?>, <?=$cust['shipping_add_2'];?><br />
                                            <?=$cust['shipping_city'];?>, <?=$cust['shipping_state'];?>, <?=$cust['shipping_country'];?> - <?=$cust['shipping_pin_code'];?> 
            <br />
<br />
            
            </div>
            
            
            <div style="float:right; width:400px; border:1px dotted #CCCCCC; padding:10px;">
            
            <span class="bold_marron">Order No </span> : <b><?=$cust['order_no'];?></b><br />
            Order Date : <?=date("d-M-Y",strtotime($cust['c_date']));?><br />
			IP Address : <?=$cust['ip'];?>
</div>

<div style="float:right; width:400px; border:1px dotted #CCCCCC; padding:10px; margin-top:10px;">
            <span class="">Payment Option </span> : <b>  <?php if($cust['payment_type']=='ew') echo 'JAYNOB E-Wallet/Shopping E-Wallet';?> </b><br />
<br />
            <span class="">Payment Status</span> : <b>  DONE<?php ($cust['payment_status']==0)?'<span style="color:#F00;">Pending</span>':'Done';?> </b><br />
<br />

            <span class="">Shipping Status</span> : <b>   <?php if($data['shiping_status']==0) echo '<span style="color:#F00;">Pending</span>';
			
			 	 elseif($data['shiping_status']==1)
			  	echo '<span style="color:#00F;">SENT</span>';
				else echo 'Done';?></b>
</div>
          
            
             
                                        <br /><br />

                                        <table width="1101" border="0" align="center" cellpadding="0" cellspacing="0" style="border-collapse:collapse; float:left;" >
                                          <tr class="text_2">
                                            <td width="27" align="right" style="border:1px solid #CCC; padding:2px;"><strong>Sr.</strong></td>
                                            <td width="97" align="right" style="border:1px solid #CCC; padding:2px;"><strong>Code</strong></td>
                                            <td width="549" style="border:1px solid #CCC; padding:2px;"><strong>Product</strong></td>
                                            
                                            <td width="144" align="right" style="border:1px solid #CCC; padding:2px;text-align:right!important;"><strong>Price/Unit</strong></td>
                                            <td width="97" align="right" style="border:1px solid #CCC; padding:2px;text-align:right!important;"><strong>Tax</strong></td>
                                            <td width="97" align="right" style="border:1px solid #CCC; padding:2px;text-align:right!important;"><strong>Quantity</strong></td>
                                            <td width="90" align="right" style="border:1px solid #CCC; padding:2px;text-align:right!important;"><strong>Price</strong></td>
                                          </tr>
                                          <?php
										  
								 
									 
										 
						
						
								$i=1;
								$total=0;
								while($s=mysql_fetch_assoc($qr))
								{
									//echo '<PRE/>';
									//print_r($s);
									
								  ?>
                                          <tr class="text_2">
                                            <td align="right" style="border:1px solid #CCC; padding:2px;"><?=$i; ?></td>
                                            <td align="right" style="border:1px solid #CCC; padding:2px;"><?=$s['product_sku']; ?></td>
                                            <td style="border:1px solid #CCC; padding:2px;"><?=strtoupper($s['product_name']);?><br />
<span style="color:#0066FF;">Certificate # <?=$s['certificate_number'];?></span><BR/><span style="color:#0066FF;"><?=$s['product_size'];?></span></td>
                                            <td align="right" style="border:1px solid #CCC; padding:2px;text-align:right!important;"><span style="width:70px;"  class="price_strick"><?php if($s['mrp']>$s['our_price'] and $s['our_price']>0){ echo '<span class="WebRupee">Rs. </span>'.$s['mrp']; $saving += ($s['mrp']-$s['our_price'])*$s['qty']; } ?> </span>
                                            <span style="width:80px; text-align:right;">&nbsp;&nbsp;<span class="WebRupee">Rs. </span> <?=$s['our_price'];?></span>                                            </td>
                                            <td align="right" style="border:1px solid #CCC; padding:2px;text-align:right!important;"><?=$tax=($s['t_cgst']+$s['t_sgst']+$s['t_igst']);?></td>
                                            <td align="right" style="border:1px solid #CCC; padding:2px;text-align:right!important;"> 
                                            <?=$s['qty'];?>                                            </td>
                                            <td align="right" style="border:1px solid #CCC; padding:2px; text-align:right!important;">
											<span class="WebRupee">Rs. </span><?=$s['qty']*($s['our_price']+$tax);?>											 </td>
                                          </tr>
                                       
                                   <?php 
								   $total+=($s['qty']*($s['our_price']+$tax));
									$i++;
									} 
								?>    
                                          </table>
                                         
                                          <div style=" float:right; width:400px; text-align:right; padding-right:10px;  line-height:20px;">
          Sub Total : <span class="WebRupee">Rs. </span><?=$total;?><br />
           <?php if($order['discount']>0){ ?><p style="text-align:right; color:#F00;">
			Discount( <?=$order['discount_name'];?> ) : <span class="WebRupee">Rs. </span>-<?=round(($order['discount']),2);?><br />  
            </p>
            <?php 
			//$total = $total - $order['discount'];
		  }
		  
		  
		  $t_before = ($total-$order['discount']);
		  
		  ?>
          
          <?php if($order['code']>76){ ?>
            <p style="text-align:right; color:#F00;">
			Adjustment ( <?=$order['policy_remarks'];?> ) : <span class="WebRupee">Rs. </span>-<?=round(($order['policy_amount']),2);?><br />  
            </p> 
            <?php 
			$order['discount']+=$order['policy_amount'];
			} 
			
			$tax=($order['t_cgst']+$order['t_sgst']+$order['t_igst']);
			?>
            
          
           Shipping Charges(+) : <span class="WebRupee">Rs. </span><?=$order['shiping'];?><br />
           Total : <span class="WebRupee">Rs. </span><?=round(($order['paid_after_did']-$tax),2);?><br />
           
           <?php 
		   
		     $aa=round(($t_before*3)/100,2);
		//	 $s = "UPDATE customer_orders SET tax='".$aa."' WHERE code='".$data['code']."' ";
			// echo '<BR/>'.$s;
			// mysql_query($s);
			 
			 $paid= round($t_before - $order['policy_amount'] +  $aa);
			//  $s = "UPDATE customer_orders SET paid_after_did='".$paid."' WHERE code='".$data['code']."' ";
		//	  mysql_query($s);
			//  echo '<BR/>'.$s;
			 
			 
		   if($order['cgst']>0){ ?> CGST (<?=$order['cgst'];?>%) : <span class="WebRupee">Rs. </span><?=$order['t_cgst'];?>
           <strong><?php $a=round(($t_before*$order['cgst'])/100,2);
		 //  $s = "UPDATE customer_orders SET t_cgst='".$a."' WHERE code='".$data['code']."' ";
		 //  echo '<BR/>'.$s;
		  // mysql_query($s);
		   ?></strong>
           <br /><?php } ?>
           <?php if($order['sgst']>0){ ?> SGST (<?=$order['sgst'];?>%) : <span class="WebRupee">Rs. </span><?=$order['t_sgst'];?>
            <strong><?php $a=round(($t_before*$order['sgst'])/100,2);
			// $s = "UPDATE customer_orders SET t_sgst='".$a."' WHERE code='".$data['code']."' ";
		 //  echo '<BR/>'.$s;
		  // mysql_query($s);
			?></strong>
           <br /><?php } ?>
           <?php if($order['igst']>0){ ?> IGST (<?=$order['igst'];?>%) : <span class="WebRupee">Rs. </span><?=$order['t_igst'];?>
            <strong><?php $a=round(($t_before*$order['igst'])/100,2);
			// $s = "UPDATE customer_orders SET t_igst='".$a."' WHERE code='".$data['code']."' ";
		 // echo '<BR/>'.$s;
		 //  mysql_query($s);
			?></strong>
           <br /><?php } ?>
           
           <?php if($order['code']<=76){ ?>
            <p style="text-align:right; color:#F00;">
			Adjustment ( <?=$order['policy_remarks'];?> ) : <span class="WebRupee">Rs. </span>-<?=round(($order['policy_amount']),2);?><br />  
            </p> 
            <?php } ?>
           
          <strong>Net Amount Payable : <span class="WebRupee">Rs. </span><?=round($order['paid_after_did'],2);?><br /></strong>
          

          
          
          </div>
         
         
           

          
          
                                        <br /> </td>
                                        </tr>
			     <tr>
			       <td width="16%" align="left" valign="middle" >Shipping Status*</td>
			       <td width="84%" align="left" valign="top"> <strong><?php if($data['shiping_status']=="0") echo 'Pending'; else echo 'Sent'; ?></strong>
			         &nbsp;</td>
			       </tr>
			     <tr>
			       <td align="left" valign="top" >Shipping  Remarks</td>
			       <td align="left" valign="top"><textarea readonly="readonly" name="shipping_details" id="shipping_details" cols="45" rows="5"><?=$data['shiping_remarks'];?>
                 </textarea></td>
                <tr style="padding: 10px;">
                	<td></td>
                    <td><span id="res" class="sucess_2"><?=$error;?></span></td>
                </tr>
                <tr style="padding: 10px;">
                	<td style="width:120px;">&nbsp;</td>
                    <td>
                    	<button type="button" id="as" name="as" onClick="Sale_insideDetails()">Go Back</button>
                        
                          </td>
                </tr>
            </table>
		</form>
        </div>
        
        </div>
        <?php
	}
}

?>
</div>
