Help with a consecutive PHP

0

Good morning!

I have a problem with a function.

I have a table called def_client

| nombre | apellido| no_cart|
| ------ |---------| ------:|
| Globe  | Negro   | 98     |
| Scala  | Azul    | 489    |
| Palais | Granate | 66079  |

I have a table called def_consecutive

| rango  | desde   | hasta  |contador|
| ------ |---------| ------:|--------|
| z1     | 01      | 99     |21240   |
| z2     | 400     | 499    |492883  |
| z4     | 60000   | 69999  |35437   |

I need that when a client is added it is assigned to a range and the counter of that range increases.

I need to do the function that makes me update the counter increasing in one I have this but it is not working.

public function putAddConsecutiveClient($noCarteraSap)
{

    $sql ="SELECT iddef_consecutivo, rango_numeros, contador FROM def_consecutivo WHERE :no_cartera_sap  BETWEEN desde AND hasta";
    $modelConsecutivo =  $this->getResponseQueryOne($sql, ["no_cartera_sap"=>$noCarteraSap]);

    if (!empty($modelConsecutivo)) {
        return 'Error al relizar la actualizacion';
    }    
    $modelConsecutivo->contador = $modelConsecutivo->contador + 1; 
    if ($modelConsecutivo->save($modelConsecutivo)) {

        return $this->updateAction($modelConsecutivo);
    } else {
        return 'Error al agregar cliente';
    }

    return $this->getResponseQueryOne($sql,["contador"=>$modelConsecutivo]);
}

I hope you can help me with this thing that is already making me crazy.

    
asked by Luis Enrique Gómez Pérez 08.12.2018 в 16:54
source

0 answers