<?php
session_start();
require_once('includes/config.php'); 
require_once('email.php');
$tablename=$_POST['table'];
$id=$_POST['id'];
$status=$_POST['status'];
$sql="UPDATE ".$tablename." SET job_status='$status' WHERE `id`='$id'";
$exe=$con->query($sql);
if($exe){
if($status==2){
 $result=$con->query("SELECT vendor_id,commission,id,payment_mode from ".$tablename."  WHERE `id`='$id'");
 $orderrow=mysqli_fetch_array($result);
 $vendor_id=$orderrow['vendor_id'];
 $commission=$orderrow['commission'];
 $id=$orderrow['id'];
 $payment_mode=$orderrow['payment_mode'];
 $created=date("Y-m-d H:i:s");
 if($payment_mode=='cod' && $commission>0){
 $query=mysqli_query($con,"insert into wallet SET user_id='".$vendor_id."',debit='".$commission."',description='Amount debited successfully for order #$id',created='".$created."'");
 $getvendor=$con->query("SELECT * FROM user_details WHERE user_id='$vendor_id'");
$getrow=mysqli_fetch_array($getvendor);
$html=' <h1>Hi '.$getrow['name'].',</h1><p>Your wallet amount <b>'.$commission.'</b> has been debited successfully for order ID #'.$id.'</p>';
sendemail($getrow['email'],"₹$commission has been debited in your wallet",$html);
 }
}
}
?>			