<?php

ob_start();
require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include ('includes/function.php');

$zroot = $_SESSION["zdir"];
$zdb = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn, $zdb);

$keycond = "";
$maindb = $_REQUEST['maindb'];
$vouchno = $_REQUEST['vouchno'];

$getqry = mysqli_query($conn, "SELECT *,date_format('%d-%m-%Y',vouchdt) as vouchdt FROM `$maindb` where vouchno ='$vouchno'") or die(mysqli_error($conn));
$fetqry = mysqli_fetch_array($getqry);

$party = $fetqry['party'];
$invno = $fetqry['invno'];
$vouchdt = $fetqry['vouchdt'];
$totalamount = $fetqry['totalamount'];

//$querycomp = mysqli_query($conn, "SELECT * FROM $zroot.`company`") or die(mysqli_error($conn));
//$fetcmpname = mysqli_fetch_object($querycomp)or die(mysqli_error($conn));
////$mcmpname = mysqli_real_escape_string($conn, $fetcmpname->compname);
//$mcmpname = mysqli_real_escape_string($conn, $fetcmpname->compname);
//$mtel = mysqli_real_escape_string($conn, $fetcmpname->htel);

$qrygrp = mysqli_query($conn, "select name, mobile,mobile2 from accmast where `accode` = '$party'") or die(mysqli_error($conn));
$fetgrp = mysqli_fetch_array($qrygrp);

$custname = $fetgrp['name'];
$custmobile = $fetgrp['mobile'];
$custmobile2 = $fetgrp['mobile2'];
//echo $custmobile;
$admin = $_SESSION["admin_" . $dbname];

//$success = false;


if (!empty($custmobile)) {

    $mobile = "9223403870,$custmobile,$custmobile2";

    $msgtech = "New Invoice Generated No. " . $invno . " Dt. " . $vouchdt . "Amount Rs." . $totalamount . ". Arfa Bags " . "( " . $custname . " )";

    $user = "ARFABG";
    $password = "Arfabg@2022";
    $senderid = "ARFABG";
    $url = "http://vas.mobilogi.com/api.php?";

    $mobilenumbers = $mobnum;

    $messagetech = urlencode($msgtech);
//    browse($messagetech);
    $chtech = curl_init();
    if (!$chtech) {
        die("Couldn't initialize a cURL handle");
    }
    $rettech = curl_setopt($chtech, CURLOPT_URL, $url);

    curl_setopt($chtech, CURLOPT_POST, 1);
    curl_setopt($chtech, CURLOPT_POSTFIELDS, "username=$user&password=$password&route=1&sender=$senderid&mobile[]=$mobile&message[]=$messagetech&templateid=1207166480663583198");
    $rettech = curl_setopt($chtech, CURLOPT_RETURNTRANSFER, true);

    $curlresponsetech = curl_exec($chtech);
    if (curl_errno($chtech)) {
//        echo 'curl error : ' . curl_error($chtech);
    }
    if (empty($rettech)) {

        die(curl_error($chtech));
        curl_close($chtech);
    } else {
        $infotech = curl_getinfo($chtech);
        curl_close($chtech);

//        echo $curlresponsetech;
    }


    $rows = array();
    $rows = array('success' => $succ);
    header("Content-type: application\json");
    echo json_encode($rows);
//    }
}