get_variable('CODCLI', true); __logStr("Consulta Debito de Cliente", "Codigo do Cliente: " . print_r($codCli, true), $script, true); $result = consultaPendencia($codCli); __logStr("Consulta Debito de Cliente", "Informacoes do Cliente: " . print_r($result, true), $script, true); $atraso = verificaAtraso($result); __logStr("Consulta Debito de Cliente", "Informacoes de Pendencia: " . print_r($atraso, true), $script, true); if (substr($atraso, 0, 2) == 'OK') { $agi->exec_goto(GetUra('URA_SELECIONA_FILA_2019')); } elseif ($atraso == "Pendente nao bloqueado") { $agi->exec_goto(GetAnuncio('inadimplente_nao_bloqueado')); } elseif ($atraso == "Bloqueado") { $agi->exec_goto(GetUra('URA_EFETUA_DESBLOQUEIO')); } } catch (Exception $ex) { $reg_msg = $ex->getMessage(); $reg_status_exec = 'Er'; __logStr("Consulta Debito de Cliente", $reg_msg . " Codigo do cliente: $codCli", $script, true); } @AtualizaIntegracao($uid, $reg_retorno, $reg_msg, $reg_status_exec, $retorno_cliente); if (!$dadosIntegra) { @grava_dadosIntegra($reg_retorno); } function consultaPendencia($param) { try { $url = 'http://191.242.216.10/server.php'; // $_user = rawurlencode('25AM0LAY9Y'); // $_passwd = rawurlencode('25AM0LAZMK'); $_user = rawurlencode('25AT0ME5TF'); $_passwd = rawurlencode('25AT0ME6C4'); $_consulta = '01FATURAS1'; $_formato_padrao = 'X'; $xml = '' . "\n"; $xml .= "\n"; $xml .= "view.execute\n"; $xml .= "\n"; $xml .= '' . "\n"; $xml .= "\n"; $xml .= "\n"; $xml .= "\n"; $xml .= "\n"; $xml .= '' . "\n"; $xml .= "\n"; $xml .= "\n"; $xml .= "\n"; $xml .= "\n"; $xml .= '' . "\n"; $xml .= "\n"; $xml .= "\n"; $xml .= "\n"; $xml .= "\n"; $xml .= '' . "\n"; $xml .= "\n"; $xml .= "\n"; $xml .= "\n"; $xml .= "\n"; $xml .= '' . "\n"; $xml .= "\n"; $xml .= "\n"; $xml .= "\n"; $xml .= "\n"; $xml .= "\n"; $xml .= ""; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: text/xml; charset=utf-8', 'Content-Length: ' . strlen($xml))); $result = curl_exec($ch); $curlError = curl_error($ch); if (!empty($curlError)) { curl_close($ch); throw new Exception("HTTP error ocurred: $curlError"); } $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($httpCode != 200) { throw new Exception("HTTP error ocurred, number: $httpCode"); } if ($result == '') { throw new Exception("Void Response"); } $xml = simplexml_load_string($result); $arDados = $xml->params->param[1]->value->DOMElement->result->row; foreach ($arDados as $arInfo) { $contas[] = objectToArray($arInfo); } foreach ($contas as $arTratado) { if (strripos($arTratado['status_plano'], 'Cancelado') === false) { $trat[] = array_filter($arTratado); } } foreach ($trat as $valores) { if (strripos($valores['status_plano'], 'Suspenso') != false) { return "Cliente Bloqueado"; } } foreach ($trat as $values) { if (!is_date($values['data_baixa'])) { $datas[] = array( "data_lan" => $values['data_lan'], "data_ven" => $values['data_ven'], "data_baixa" => $values['data_baixa'], "codfat" => $values['codfat'][0], "status_plano" => $values['status_plano'] ); } } $mesAtu = date("m"); foreach ($datas as $values) { $arData = explode("/", $values['data_ven']); if (($arData[1] > $mesAtu)) { continue; } $faturasTratadas[] = array( "data_ven" => $arData[0]."/".$arData[1]."/".$arData[2], "codfat" => $values['codfat'], "data_baixa" => $values['data_baixa'] ); } if(count($faturasTratadas) > 2){ $faturasPendentes = array_slice($faturasTratadas,1); } return empty($faturasPendentes) ? $faturasTratadas : $faturasPendentes; } catch (Exception $ex) { $msg = $ex->getMessage(); return $msg; } } function objectToArray($d) { if (is_object($d)) { $d = get_object_vars($d); } if (is_array($d)) { return array_map(__FUNCTION__, $d); } else { return $d; } } function dateDiff($dateParam) { $dateIni = strtotime(date('Y-m-d')); $dateParam = date(strtotime(str_replace('/', '-', $dateParam))); $diff = ($dateIni - $dateParam); $days = (int) floor($diff / (60 * 60 * 24)); return $days; } function verificaAtraso($param) { try { if ($param == "Cliente Bloqueado") { return "Bloqueado"; } if (empty($param)) { return "OK - Cliente em dia"; } foreach ($param as $dados) { foreach ($dados as $value) { if (is_date($value)) { $result = dateDiff($value); if ($result > 15) { return "Pendente nao bloqueado"; } elseif ($result > 45) { return "Bloqueado"; } else { return "OK - Cliente em dia"; } } } } } catch (Exception $ex) { return $ex->getMessage(); } } ?>