|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 1 - NORMAL
|
|
|
|
|
* 29 - EM PROSPEC<EFBFBD><EFBFBD>O
|
|
|
|
|
* 30 - LEAD
|
|
|
|
|
*/
|
|
|
|
|
include("bd.php");
|
|
|
|
|
include("util/util.php");
|
|
|
|
|
$path = "/var/lib/asterisk/procVendas.log";
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$reg = GetCliente(ConsultaVendaMais());
|
|
|
|
|
if ($reg) {
|
|
|
|
|
GravaLog(sprintf("[%s] Registros alterados: %s \n", date('Y-m-d H:i:s'), $reg), $path);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception $ex) {
|
|
|
|
|
GravaLog($ex->getMessage(), $path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ConsultaVendaMais() {
|
|
|
|
|
$query = "exec sip_cliente_prevenda";
|
|
|
|
|
$data = getConnection($query);
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function GetCliente($clientes) {
|
|
|
|
|
global $dbcon;
|
|
|
|
|
$reg = 0;
|
|
|
|
|
$sql = "";
|
|
|
|
|
|
|
|
|
|
$query = "SELECT client_out_id
|
|
|
|
|
FROM pbx_cliente a
|
|
|
|
|
INNER JOIN pbx_campanha_contato_status b ON b.ctst_id = a.client_status::INT
|
|
|
|
|
WHERE (data_lead IS NULL OR data_cliente IS NULL) AND ctst_id = 21 ";
|
|
|
|
|
|
|
|
|
|
$result = pg_query($dbcon, $query);
|
|
|
|
|
$data = pg_fetch_all($result);
|
|
|
|
|
|
|
|
|
|
if (pg_last_error()) {
|
|
|
|
|
throw new Exception("Nao foi possivel realizar a consulta no banco de dados!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!$data) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($clientes as $cli) {
|
|
|
|
|
foreach ($data as $c) {
|
|
|
|
|
if ($c['client_out_id'] == $cli['cliente_id']) {
|
|
|
|
|
if ($cli['cliente_status_id'] == 30) {
|
|
|
|
|
$sql .= sprintf("UPDATE pbx_cliente SET data_lead = NOW() WHERE client_out_id = %s AND client_documento = %s; \n", QuotedStr($c['client_out_id']), QuotedStr($cli['cgc_cpf']));
|
|
|
|
|
$reg++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($cli['cliente_status_id'] == 1) {
|
|
|
|
|
$sql .= sprintf("UPDATE pbx_cliente SET data_cliente = NOW() WHERE client_out_id = %s AND client_documento = %s; \n", QuotedStr($c['client_out_id']), QuotedStr($cli['cgc_cpf']));
|
|
|
|
|
$reg++;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($sql) {
|
|
|
|
|
pg_query($dbcon, $sql);
|
|
|
|
|
if (pg_last_error()) {
|
|
|
|
|
throw new Exception("Nao foi possivel realizar a consulta no banco de dados!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $reg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getConnection($query) {
|
|
|
|
|
$connection = mssql_connect('192.168.115.28', 'integracao', 'SimpleS_root');
|
|
|
|
|
mssql_select_db('VendaMaisDB_simplesip');
|
|
|
|
|
$result = mssql_query($query, $connection);
|
|
|
|
|
$return = array();
|
|
|
|
|
while ($data = mssql_fetch_array($result)) {
|
|
|
|
|
$return[] = $data;
|
|
|
|
|
}
|
|
|
|
|
return $return;
|
|
|
|
|
}
|
|
|
|
|
|