Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "ordem_de_servico": [
- {
- "oser_numero_os": 23940493,
- "oser_address_name": NAME;
- ordem_de_servico:
- {
- "oser_numero_os":23940493,
- "oser_dt_abertura":"28/03/2018",
- "servico":{
- "serv_cod_servico":60,
- "serv_descr_servico":"CORTE POR DEBITO"
- },
- "cliente":{
- "clie_ident_cliente":638617,
- "nome":"MARIA APARECIDA FERREIRA DO NASCIMENTO"
- },
- "unidade_consumidora":{
- "unid_ident_uc":2436434,
- "logr_nome_logr_expandido":"R JOSE GUIMARAES"
- },
- "faturas":[
- {
- "total_fatura":"88.44",
- "ftcd_mes_ano_fatmto":"2017-04-01"
- },
- {
- "total_fatura":"45.16",
- "ftcd_mes_ano_fatmto":"2017-03-01"
- }
- ]
- }
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "webservice";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- // Read JSON file
- $json = file_get_contents('oss.json');
- //Decode JSON
- $json_data = json_decode($json,true);
- foreach($json_data['ordens_de_servico'] as $key => $value){
- $os = $value["oser_numero_os"];
- $data_abertura = $value["oser_dt_abertura"];
- foreach($json_data['ordens_de_servico'][$key]['faturas'] as $index => $row){
- $valorParcelas = $row["total_fatura"];
- $sql = "SELECT numero_os FROM os WHERE numero_os = '$os'";
- $result = $conn->query($sql);
- if ($result->num_rows > 0) {
- echo "PULAR FATURA"."<p>";
- }else {
- $sql = "INSERT INTO faturas (valorParcelas, numero_os) VALUES ('$valorParcelas', '$os')";
- if ($conn->query($sql) === TRUE) {
- echo "<strong>".$valorParcelas." - FATURA OK"."</strong>"."<p>";
- } else {
- echo "Error Fatura";
- }
- }
- }
- $sql = "SELECT numero_os FROM os WHERE numero_os = '$os'";
- $result = $conn->query($sql);
- if ($result->num_rows > 0) {
- echo "PULAR"."<p>";
- }
- else{
- $sql = "INSERT INTO os (numero_os, data_abertura) VALUES ('$os', '$data_abertura')";
- if ($conn->query($sql) === TRUE) {
- echo "<strong>".$os." - GRAVADO"."</strong>"."<p>";
- } else {
- echo "Error";
- }
- }
- }
- $conn->close();
- ?>
Add Comment
Please, Sign In to add comment