<?php
require_once('functions.php');

//$user=$_SESSION['user'];
require_once('mysql.php');
	

$p=mysqli_real_escape_string($dbc,trim($_POST['p']));
$m=mysqli_real_escape_string($dbc,trim($_POST['m']));
$qty=mysqli_real_escape_string($dbc,trim($_POST['qty']));
$price=mysqli_real_escape_string($dbc,trim($_POST['price']));
$sal=mysqli_real_escape_string($dbc,trim($_POST['gg']));
 //echo $m;
 $dv=$qty*$price;
 $fjk="select total_p ,type from sales where sale_id='$sal'";
    $gpp=mysqli_query($dbc,$fjk);
	$tot=mysqli_fetch_array($gpp);
	   $tota=$tot['total_p'];
	   $typ=$tot['type'];
	  // $fjk="select cust from x_report where receipt='$m' and type='$typ'";
      //$fo=mysqli_query($dbc,$fjk);
	   // $rew=mysqli_fetch_array($fo);
		 //  $di=$rew['cust'];
	      // $vcc="update accounts set debt =debt-'$tota' where id='$di' limit 1"; 
		  //$up=mysqli_query($dbc,$vcc);
 
   
	 //   $vc="update accounts set debt =debt+'$dv' where id='$di' limit 1"; 
	//	  $up=mysqli_query($dbc,$vc);
		 // $ji="update x_report set amount=amount-'$tota' where receipt='$m' and type='$typ' limit 1";
		   //  $xe=mysqli_query($dbc,$ji);
			 ///$jii="update x_report set amount=amount+'$dv' where receipt='$m' and type='$typ' limit 1";
		     //$xee=mysqli_query($dbc,$jii);
	    $con=mysqli_connect("localhost","vosmcyqy_gtr","n7Y8RY765@@!|3@PLasd","vosmcyqy_rots");
			 $sa="update sales set qty='$qty', price='$price',total_p='$dv', prof='$dv', p_name='$p' where sale_id='$sal' limit 1";
   $kiu=mysqli_query($dbc,$sa);
   	 $sal="update sales set qty='$qty', price='$price',total_p='$dv', prof='$dv', p_name='$p' where sale_id='$sal' and src='AFRICANA SHOP' limit 1";
   $kiu=mysqli_query($con,$sal);
 $pdu= "update ledgers set debit='$dv', qty='$qty', price='$price' where invoice='$m' and description='$p' and debit>0";
	 
 $sql=mysqli_query($dbc,$pdu);	
 $pd= "update ledgers set credit='$dv', qty='$qty' ,price='$price' where invoice='$m' and description='$p' and credit>0";
	 
  $sqd=mysqli_query($dbc,$pd);	

mysqli_close($dbc);
mysqli_close($con);
  header("location: sale_r.php");
	
?>