How to limit the sum of records to a column up to an X value? [closed]

0

I have two tables:

  • Customers : Save customer data, such as: ID, Name, Points .

  • Sales : Registers the sales made by each customer, like: Customer_ID, Service ( 10 minutes for example ), among others.

  • I would like to see that in the Points field of the Customers table the services are registered until they reach X amount, if it exceeds that amount (for example 90) it updates it to Zero for the next sale.

        
    asked by c3media 26.03.2017 в 13:09
    source

    2 answers

    0
    function bonus_data($data)
    {
    
    date_default_timezone_set('America/Bogota');
    $t = $data["params"]["reference_no"];
    $client_id = $data["params"]["customer_id"];
    $venta = $data["params"]["sale_status"];
    
    global $h;
    $res = $h->execute_query("select id, name, company, award_points from sma_companies WHERE id = '$client_id'");
    #phpgrid_error($h->con->errormsg());
    $arr = $res->GetRows();
    #phpgrid_error($arr);
    $puntos = $arr[0]["award_points"];
    $nombre_cliente = $arr[0]["company"];
    $documento = $arr[0]["name"];
    
    if($venta == 'Bono'){
    $acu = $puntos - 180;
        $h->execute_query("UPDATE sma_companies SET award_points = '$acu' WHERE id = '$client_id'");
    } else {
        $acu = $puntos + $t;
        $h->execute_query("UPDATE sma_companies SET award_points = '$acu' WHERE id = '$client_id'");
    }
    }
    
        
    answered by 11.11.2018 / 08:22
    source
    -1

    this is my function:

    function bonus_data($data)
    {
        $t = $data["params"]["reference_no"];
        $client_id = $data["params"]["customer_id"];
        global $h;
        $h->execute_query("select award_points from sma_companies WHERE id = '$client_id'");
        $puntos = $h;
    
    if ($puntos < "180") {
        $t=$data["params"]["reference_no"];
        global $h;
        $h->execute_query("UPDATE sma_companies SET award_points = '$t' + '$puntos' WHERE id = '$client_id'");
        } 
        else 
        if ($puntos > "180")
        {
        $t=$data["params"]["reference_no"];
        global $h;
        $h->execute_query("UPDATE sma_companies SET award_points = '$t' WHERE id = '$client_id'");
    }
    }
    

    The problem is that it only updates me when I insert the record (points), but it is not asking me the last record (points) to accumulate it with the current one.

    Thanks for your help in this regard!

        
    answered by 29.03.2017 в 02:45