<?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 from sales where number='$m' and p_name='$p' and sale_id='$sal'";
    $gpp=mysqli_query($dbc,$fjk);
	$tot=mysqli_fetch_array($gpp);
	   $tota=$tot['total_p'];
	   $fjk="select cust from x_report where receipt='$m' and type='INVOICE'";
      $fo=mysqli_query($dbc,$fjk);
	    $rew=mysqli_fetch_array($fo);
		   $di=$rew['cust'];
	     
		  $ji="update x_report set amount=amount-'$tota' where receipt='$m' and type='INVOICE' limit 1";
		     $xe=mysqli_query($dbc,$ji);
			 $jii="update x_report set amount=amount+'$dv' where receipt='$m' and type='INVOICE' limit 1";
		     $xee=mysqli_query($dbc,$jii);
			 $sa="update sales set qty='$qty', price='$price',total_p='$dv', prof='$dv' where number='$m' and p_name='$p'";
   $kiu=mysqli_query($dbc,$sa);
       $con=mysqli_connect("localhost","vosmcyqy_gtr","n7Y8RY765@@!|3@PLasd","vosmcyqy_rots");
		
		 $sak="update sales set qty='$qty', price='$price',total_p='$dv', prof='$dv' where number='$m' and p_name='$p' and src='AFRICANA SHOP'";
   $kik=mysqli_query($dbc,$sak);
	 $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: edd_pri.php");
	
?>