<?php 
	ini_set('display_errors', '1');
	//error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE & ~E_WARNING);
	error_reporting(E_ALL);
	require (CONFIG.'dbconnect.php');
	require (PAGE_CONTENT.$PageContent);

	if(isset($_COOKIE["WizSellKrugerrand"])){
		$data = json_decode($_COOKIE['WizSellKrugerrand']);
		$data = json_decode(json_encode($data), True);
	}
	else
		$data = null;
	//20190617 - Change Sell KR and Buy KR pages to use new table web_retail_pricing. -Gael
	//$pdo = $SA->query("SELECT GoldPriceZARPerOz FROM web_gold_pricing ORDER BY ID DESC LIMIT 1");
	$pdo = $SA->query("SELECT GoldPriceZARPerOz, SellToUsSpread FROM web_retail_pricing ORDER BY ID DESC LIMIT 1");
	$pdo->execute();
	$results = $pdo->fetch();
	$KrugerRandTotalPriceZAR = number_format((float)$results['GoldPriceZARPerOz'] + ((float)$results['GoldPriceZARPerOz'] * ((float)$results['SellToUsSpread']/100)) , 2);
	//var_dump($KrugerRandTotalPriceZAR);
	$sellPrice = str_replace(",", "", $KrugerRandTotalPriceZAR);

	$oneOunce = number_format($sellPrice * (float)$data["sell_krugerrand_quantity"], 2, ".", ",");
	$oneHalfOunce = number_format(($sellPrice/2) * (float)$data["sell_krugerrand_quantity_2"], 2, ".", ",");
	$oneQuarterOunce = number_format(($sellPrice/4) * (float)$data["sell_krugerrand_quantity_3"], 2, ".", ",");
	$oneTenthOunce = number_format(($sellPrice/10) * (float)$data["sell_krugerrand_quantity_4"], 2, ".", ",");

	$oneOunceWeight = number_format(1 * (float)$data["sell_krugerrand_quantity"], 2, ".", ",");
	$oneHalfOunceWeight = number_format((1/2) * (float)$data["sell_krugerrand_quantity_2"], 2, ".", ",");
	$oneQuarterOunceWeight = number_format((1/4) * (float)$data["sell_krugerrand_quantity_3"], 2, ".", ",");
	$oneTenthOunceWeight = number_format((1/10) * (float)$data["sell_krugerrand_quantity_4"], 2, ".", ",");


	//print_rr($_SESSION);

	function print_rr($v){
	  echo "<PRE>";
	  print_r($v);
	  echo "</PRE>";
	}

	$data["totalNumberCoins"] = $data['sell_krugerrand_quantity'] + $data['sell_krugerrand_quantity_2'] + $data['sell_krugerrand_quantity_3'] + $data['sell_krugerrand_quantity_4'];

	$data["dblTotalCoinWeight"] = number_format($data["dblTotalCoinWeight"], 2, ".", ",");

	$data["dblDBCoinWeight"] = str_replace(",", "", $data["dblTotalCoinWeight"]);
	$data["dblDBCurrentSellPrice"] = str_replace(",", "", $data["dblCurrentSellPrice"]);
	$data["dblDBTotalSellPrice"] = str_replace(",", "", $data["dblTotalSellPrice"]);
?>

<div id="<?php echo $pageID;?>" class="page-wrapper row">
	<div class="investment-comparison col s12" style="background-color: #f8f7fb;">
		<div class="content-wrap">
			<div class="row">
		    	<div class="col s12">
			      <ul class="tabs">
			        <li class="tab col s3"><span>Sell To Us</span></li>
			        <li class="tab col s3"><span>Seller Details</span></li>
			        <li class="tab col s3" style="border-bottom: 2px solid #3b1c5f;"><span>Review & Submit</span></li>
			      </ul>
		    	</div>
		  	</div>
		  	<form id="frmKruggerSell">
		  		<input type="hidden" id="strOneOunce" value="<?php echo $oneOunce; ?>">
		  		<input type="hidden" id="strOneHalfOunce" value="<?php echo $oneHalfOunce;?>">
		  		<input type="hidden" id="strOneQuarterOunce" value="<?php echo $oneQuarterOunce;?>">
		  		<input type="hidden" id="strOneTenthOunce" value="<?php echo $oneTenthOunce;?>">


		  		<input type="hidden" id="sell_krugerrand_first_name" value="<?php echo $data['sell_krugerrand_first_name'];?>">
				<input type="hidden" id="sell_krugerrand_last_name" value="<?php echo $data['sell_krugerrand_last_name'] ;?>" >
				<input type="hidden" id="sell_krugerrand_email" value="<?php echo $data['sell_krugerrand_email'] ;?>" >
				<input type="hidden" id="sell_krugerrand_id_number" value="<?php echo $data['sell_krugerrand_id_number'] ;?>" >
				<input type="hidden" id="sell_krugerrand_telephone" value="<?php echo $data['sell_krugerrand_telephone'] ;?>" >
				<input type="hidden" id="sell_krugerrand_mobile" value="<?php echo $data['sell_krugerrand_mobile'] ;?>" >
				<input type="hidden" id="location" name="location" value="<?php echo $data['location'] ;?>">
				<input type="hidden" id="sell_krugerrand_address_line_one" value="<?php echo $data['sell_krugerrand_address_line_one'] ;?>" >
				<input type="hidden" id="sell_krugerrand_address_line_two" value="<?php echo $data['sell_krugerrand_address_line_two'] ;?>" >
				<input type="hidden" id="sell_krugerrand_city" value="<?php echo $data['sell_krugerrand_city'] ;?>">
				<input type="hidden" id="sell_krugerrand_postal_code" value="<?php echo $data['sell_krugerrand_postal_code'];?>">
				<input type="hidden" id="dblTotalCoinWeight" value="<?php echo $data['dblDBCoinWeight'] ;?>">
				<input type="hidden" id="dblCurrentSellPrice" value="<?php echo $data['dblDBCurrentSellPrice'] ;?>">
				<input type="hidden" id="dblTotalSellPrice" value="<?php echo $data['dblDBTotalSellPrice'] ;?>">
				<input type="hidden" id="sell_krugerrand_quantity" value="<?php echo $data['sell_krugerrand_quantity'] ;?>">
				<input type="hidden" id="sell_krugerrand_quantity_2" value="<?php echo $data['sell_krugerrand_quantity_2'];?>">
				<input type="hidden" id="sell_krugerrand_quantity_3" value="<?php echo $data['sell_krugerrand_quantity_3'];?>">
				<input type="hidden" id="sell_krugerrand_quantity_4" value="<?php echo $data['sell_krugerrand_quantity_4'];?>">
				<input type="hidden" id="sell_krugerrand_notes" value="<?php echo $data['sell_krugerrand_notes'];?>">
			  	<div id="krugerrand-continer-all" class="investment-continer-all  col s12" style="background-color: #f8f7fb;">
				  	<div class="col s12 investment-calculator-container">
				      <div class="content-wrap" style="border: 0;">
				    		<div>
						      <h2 class="center-align intro-head-type"><?php echo $resultsHeading; ?></h2>
						      <p  class="center-align  intro-txt-type"><?php echo $resultsSubHeading; ?></p>
						      <div class='row'>
		                     <div class='col m5 s12'>
		                     	 <div class="investment-illustration-circle" style="margin: 0 auto;">
								         <p class="alrightsansmedium intro-head-type circle-init-amount" style='text-align: center; vertical-align: middle; line-height: 0px; font-size: 30px; padding-bottom: 150px;'>R <?php echo $data["dblTotalSellPrice"];?></p>
								      </div>
		                     </div>
		                     <div class='col m7 s12'>
		                        <table class='table-no-padding bordered ' border='1'>
		                           <thead>
		                              <tr>
		                              	<th width="">Denomination</th>
		                                 <th width=''></th>
		                                 <th style='text-align:right'>No. Coins</th>
		                                 <th style='text-align:right'>Coin Weight</th>
		                                 <th style='text-align:right'>Total</th>
		                              </tr>
		                           </thead>
		                           <tbody>
		                           <tr>
		                           	<td style='text-align:left'>Full Ounce</td>
		                           	<td style='text-align:center;'>x</td>
		                              <td style='text-align:right;' id='intOneOunce'><?php echo $data['sell_krugerrand_quantity'];?></td>
		                              <td style='text-align:right'><?php echo $oneOunceWeight;?></td>
		                              <td style='text-align:right' id='dblOneOunce'>R <?php echo $oneOunce; ?></td>
		                           </tr>
		                           <tr>
		                           	<td style='text-align:left'>Half Ounce</td>
		                           	<td style='text-align:center;'>x</td>
		                              <td style='text-align:right;' id='intHalfOunce'><?php echo $data['sell_krugerrand_quantity_2'];?></td>
		                              <td style='text-align:right'><?php echo $oneHalfOunceWeight;?></td>
		                              <td style='text-align:right' id='dblHalfOunce'>R <?php echo $oneHalfOunce;?></td>
		                           </tr>
		                           <tr>
		                           	<td style='text-align:left'>Quarter Ounce</td>
		                           	<td style='text-align:center;'>x</td>
		                              <td style='text-align:right;' id='intQuarterOunce' ><?php echo $data['sell_krugerrand_quantity_3'];?></td>
		                              <td style='text-align:right'><?php echo $oneQuarterOunceWeight;?></td>
		                              <td style='text-align:right' id='dblQuarterOunce'>R <?php echo $oneQuarterOunce;?></td>
		                           </tr>
		                           <tr>
		                           	<td style='text-align:left'>Tenth Ounce</td>
		                           	<td style='text-align:center;'>x</td>
		                              <td style='text-align:right;' id='intTenthOunce'><?php echo $data['sell_krugerrand_quantity_4'];?></td>
		                              <td style='text-align:right'><?php echo $oneTenthOunceWeight;?></td>
		                              <td style='text-align:right' id='dblTenthOunce'>R <?php echo $oneTenthOunce;?></td>
		                           </tr>
		                           </tbody>
		                           <tfoot>
		                              <tr>
		                              	<th style='font-size:12px; padding:5px; text-align:left;'>Current Sell Price</th>
		                                 <th style='font-size:12px; padding:5px; text-align:left; width:10%'></th>
		                                 <th style='font-size:12px; padding:5px; text-align:right'>Total Coins</th>
		                                 
		                                 <th style='font-size:12px; padding:5px; text-align:right;'>Total Coin Weight</th>
		                                 <th style='font-size:12px; padding:5px; text-align:right;'>Total Sell Price</th>
		                              </tr>
		                              <tr>
		                              	<td id='dblCurrentSellPriceReview'>R <?php echo $data["dblCurrentSellPrice"];?></td>
		                              	<td style='text-align:center;'>x</td>
		                                 <td id='intCoinTotalReview' style='text-align:right;'><?php echo $data["totalNumberCoins"];?></td>
		                                 <td style='text-align:right; font-size: 16px;color:#B09068;' id='dblTotalReview'>
		                                 	<?php echo $data["dblTotalCoinWeight"];?>
		                                 </td>
		                                 <td style='text-align:right; font-size: 16px;color:#B09068;' id='dblTotalReview'>R <?php echo $data["dblTotalSellPrice"];?></td>
		                              </tr>
		                           <tfoot>
		                        </table>
		                        <br>
		                     </div>
		                     <div class='col m12 s12 offset-m2'>
		                        <br>
		                        <p><?php echo $resultsSubHeading2; ?></p>
		                        <p><?php echo $resultsSubHeading3; ?></p>
		                     </div>
	                  </div>
				 	 	</div><!-- content-wrap -->
				  	</div>
				</div>
				
				<span class="krugerrand-price-info" style="padding: 0 20px 5px 106px;clear: both;float:right;">
					<a href="<?php echo $SiteUrl ;?>/krugerrand/sell/index.php?seller-details" class="btn btn-default">Back</a>
					<button id="krugerrandSellCalcOver" class="btn btn-success" style="background-color: #3b1c5f;">Submit</button>
				</span>
			</form>
		</div><!-- content wrap -->
	</div><!-- investment-comparison -->

</div><!--  page-wrapper  -->
