Truncated data for the vlrDesconto Laravel column

Asked

Viewed 99 times

2

I’m trying to save field with formatting by jqueryMaskMoney, but this giving truncated data error

 $("#desconto01").maskMoney({thousands: ".", decimal: ","});

Error:

inserir a descrição da imagem aqui

CONTROLLER

 public function store(Request $request){

  // try{
  //   DB::beginTransaction();
    $dados = new MapaCompra;
    $mytime = Carbon::now('America/Sao_Paulo');
    $dados->data=$mytime->toDateTimeString(); 
    $dados->infadicionais=$request->get('infadicionais');             
    $dados->orc01=$request->get('orc01');             
    $dados->orc02=$request->get('orc02');             
    $dados->orc03=$request->get('orc03');             
    $dados->codpg01=$request->get('codpg01');             
    $dados->codpg02=$request->get('codpg02');             
    $dados->codpg03=$request->get('codpg03');             
    $dados->obs01=$request->get('obs01');             
    $dados->obs02=$request->get('obs02');             
    $dados->obs03=$request->get('obs03');             
    $dados->desconto01=$request->get('desconto01');             
    $dados->desconto02=$request->get('desconto02');             
    $dados->desconto03=$request->get('desconto03');             
    $dados->idforn01=$request->get('idforn01');             
    $dados->idforn02=$request->get('idforn02');             
    $dados->idforn03=$request->get('idforn03');             
    $dados->acrescimo01=$request->get('acrescimo01');             
    $dados->acrescimo02=$request->get('acrescimo02');             
    $dados->acrescimo03=$request->get('acrescimo03');             
    $dados->status='AA';
    $dados->data_status=$mytime->toDateTimeString(); 
    $dados->empresa_id=$request->session()->get('idempresa');     
    $dados->user_id=Auth::user()->id;   
    $dados->ativo='a';       
    $dados->save();

    // $idproduto=$request->get('idproduto');
    // $qnt=$request->get('qnt');
    // $detalhes=$request->get('detalhe');
    // $idcentrocusto=$request->get('idcentrocusto');        

    // $cont = 0;
    // while($cont < count($idproduto)){
    //   $detalhe = new SolicitacaoDet();
    //   $detalhe->idsolicitacao=$solicitacoes->idsolicitacao;
    //   $detalhe->idproduto=$idproduto[$cont];
    //   $detalhe->qnt=$qnt[$cont];
    //   $detalhe->detalhe=$detalhes[$cont];
    //   $detalhe->idcentrocusto=$idcentrocusto[$cont];         
    //   $detalhe->save();
    //   $cont=$cont+1;
    // }

  //   DB::commit();

  // }catch(\Exception $e){
  //   DB::rollback();
  // }

  return Redirect::to('compra/mapacompra');

MY QUOTATION SCREEN inserir a descrição da imagem aqui

  • When saving this data it needs to be converted for example: 1.000,00 for 1000.00. This is an example, but since you didn’t put in the code part it gets complicated to say something else, if you can put in the code of controller

  • Thank you for the return. In my Controlle I get it so $data->discount01=$request->get('discount01');

  • put the controller code man

1 answer

1


Truncated data, is because, the value passed is higher than what is configured in the database and also needs to convert the value that is in the Brazilian format to American, example:

$dados->desconto01 = 0;
$desconto01 = $request->get('desconto01');
$desconto01 = str_replace('.','',$desconto01);
$desconto01 = str_replace(',','.',$desconto01);
if (is_numeric($desconto01))
{
    $dados->desconto01 = $desconto01;
}

Roughly it is so, can be made a helper or function to automate, example simple of a function with default value:

function number_decimal($valor, $default = 0)
{
    $valor = str_replace('.','',$valor);
    $valor = str_replace(',','.',$valor);
    if (is_numeric($valor))
    {
        return $valor;
    }
    return $default;
}

then just call

$dados->desconto01 = number_decimal($request->get('desconto01'));      
  • do this in the controller or better in the view via javascript? What suits me?

  • i would do the following, a function to convert this to backend (controller). @frodrigues

  • I tested this code in the controller yet gave error.

  • @frodrigues which error?

  • Same error Truncated data for column discounted 01.

  • Check it out, how is this database configured? the field discounted 01 as you configured? @frodrigues

  • I’m using type = decimal(19.4)

  • the value you’re going through in this $desconto01 is which? exemplifie @frodrigues

  • I’m doing tests with scores (10.00), hundreds (100.00) and thousands (1,000.00) and values with cents (10.50 or 100.50 or 1.050.50)

  • Virgilio worked yes $discount01 = $request->get('discounted 01'); $discount01 = str_replace('.','',$discounted 01); $discount01 = str_replace(','.',$discounted 01); if (is_numeric($discounted 01)) { $given->discounted 01=$discounted 01; }

  • corrected an error my typing here. Now how could this function have several data to handle and a very large insertion

  • @frodrigues left an example!

  • Show ran blz. Thank you;

Show 8 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.