<?php

include_once 'db_functions.php'; 
$db = new DB_Functions(); 
$json = $_REQUEST["collectJSON"];
if (get_magic_quotes_gpc()){ 
	$json = stripslashes($json); 
}

$dc = new DB_Connect();         
$link1 = $dc->connect();
//Decode JSON into an Array 
$data = json_decode($json); 
//print_r($data);
//Util arrays to create response JSON 
$a=array();
$b=array();

for($i=0; $i<count($data) ; $i++) {
	//Store User into MySQL DB 
	$res = $db->save_collect($data[$i]->retailer_code,$data[$i]->collection_mode,$data[$i]->collection_amt,$data[$i]->collection_date,$data[$i]->remark,$data[$i]->collect_by,$data[$i]->sub_collection_mode,$data[$i]->trnDate,$data[$i]->trnNo,$data[$i]->chequeDate,$data[$i]->chequeNo);
	//Based on inserttion, create JSON response     
 	array_push($a,$res);  
}
//Post JSON response back to Android Application 
echo json_encode($a); 

$retailer_code=$data[0]->retailer_code;
$collect_by=$data[0]->collect_by;
$collection_amt=$data[0]->collection_amt;

$sql_store="select location_code from location_master where sale_person='".$collect_by."' and locationtype='STR'";
		$rs_store=mysqli_query($link1,$sql_store) or die(mysqli_error($link1));
		$row_store=mysqli_fetch_assoc($rs_store);
		$storecode=$row_store['location_code'];
		$wh_row=mysqli_fetch_assoc(mysqli_query($link1,"select wh_location from map_wh_location where status='Y' and location_code='".$storecode."'"));
if($wh_row['wh_location']!=''){
$wh_loc=$wh_row['wh_location'];
}else{
$wh_loc="FIX00017";
}	

$loc_name=$db->getAnyDetails($retailer_code,"locationname","location_code","location_master",$link1);	
   
$saleperson=$db->getAnyDetails($collect_by,"empname","loginid","hrms_employe_master",$link1);
  $mob=$db->getAnyDetails($retailer_code,"contactno1","location_code","location_master",$link1);
    $outstanding_amt=$db->getoustanding($wh_loc,$retailer_code,$link1);  
     

          if($mob!=''){
            $sms=urlencode("Dear ".$loc_name.", your payment through ".$collection_mode." of ".$collection_amt." was received by our Fixx A Phone representative ".$saleperson." on ".date("d-m-Y")." and your current outstanding is ".$outstanding_amt.". If paid through Cheque, it will be subjected to clearance. Thank you for being with us.");
	
            $loc_mobile="91".$mob;
            $whatsapp_url="https://dash.whatybot.com/api/send.php?client_id=1dab36d0d031244f64c38887f4cf99e9&instance=a3fd513d06500166cb9985c224492799&number=".$loc_mobile."&message=".$sms."&type=text";
            
     $contents1 =file_get_contents($whatsapp_url);
     
     $mobile="918984500147";
            $whatsapp_url2="https://dash.whatybot.com/api/send.php?client_id=1dab36d0d031244f64c38887f4cf99e9&instance=a3fd513d06500166cb9985c224492799&number=".$mobile."&message=".$sms."&type=text";
            
     $contents2 =file_get_contents($whatsapp_url2);
     
      if($collect_by=='FIUSR015'){
        $mobile3="919938662066";
    }else if($collect_by=='FIEMP0045'){
        $mobile3="917008833232";
    }        
  if($mobile3!=''){          
   $whatsapp_url3="https://dash.whatybot.com/api/send.php?client_id=1dab36d0d031244f64c38887f4cf99e9&instance=a3fd513d06500166cb9985c224492799&number=".$mobile3."&message=".$sms."&type=text";
            $contents3 =file_get_contents($whatsapp_url3);
  }
     
            
          }


?>


