First, sorry for my English
----------------------------------
hi, helpme with a problem.
public function ver_prog_riego(){ $crud = new grocery_CRUD(); $crud->set_table('riego_calend') ->set_subject('Calendario de Riego') ->columns('bloq_cod','calend_linea','calend_ha','calend_precip','calend_horario','calend_d1','calend_d2','calend_d3','calend_d4','calend_d5','calend_d6','calend_d7','calend_total','calend_mt3') ->display_as('bloq_cod','Sector de Riego') ->display_as('calend_linea','LÃnea') ->display_as('calend_ha','Has.') ->display_as('calend_precip','Precipitación (Mt3/Hr/Ha)') ->display_as('calend_horario','Inicio/Termino') ->display_as('calend_d1', 'Lu') ->display_as('calend_d2', 'Ma') ->display_as('calend_d3', 'Mi') ->display_as('calend_d4', 'Ju') ->display_as('calend_d5', 'Vi') ->display_as('calend_d6', 'Sa') ->display_as('calend_d7', 'Do'); ->display_as('calend_total', 'Total Horas') ->display_as('calend_mt3', 'Mt3/Ha.'); $crud->where('calend_key','key150'); $crud->unset_read(); $crud->unset_add(); $crud->unset_delete(); $crud->set_relation('bloq_cod','bloques','bloq_nom'); $crud->fields('bloq_cod','calend_linea','calend_ha','calend_precip','calend_horario','calend_d1','calend_d2','calend_d3','calend_d4','calend_d5','calend_d6','calend_d7','calend_total','calend_mt3'); $state = $crud->getState(); if($state == 'edit'){ $crud->field_type('calend_precip','readonly'); $crud->field_type('bloq_cod','readonly'); $crud->field_type('calend_linea','readonly'); $crud->field_type('calend_ha','readonly'); $crud->field_type('calend_total','readonly'); $crud->field_type('calend_mt3','readonly'); } $crud->callback_before_update(array($this,'totales_calendar_callback')); $output = $crud->render(); $this->load->view('view_prog2.php',$output); } function totales_calendar_callback($post_array, $primary_key) { $horas = $post_array['calend_d1']+$post_array['calend_d2']+$post_array['calend_d3']+$post_array['calend_d4']+$post_array['calend_d5']+$post_array['calend_d6']+$post_array['calend_d7']; $precip = $post_array['calend_precip']; $post_array['calend_total'] = $horas; $post_array['calend_mt3'] = $$horas * $precip; return $post_array; }
all ok... edit, save and show grid, the problem is when calculating '$post_array['calend_mt3'] = $horas * $precip;' ... not done..!!!!
I tested :
function with and without '$primary_key' ----> FAIL
$post_array['calend_mt3'] = $post_array['calend_total'] * $post_array['calend_precip'] ----> FAIL
$post_array['calend_mt3'] = $horas * $post_array['calend_precip'] ----> FAIL
$post_array['calend_mt3'] = $post_array['calend_total'] * $precip ----> FAIL
$post_array['calend_mt3'] = $horas * $precip ----> FAIL
$precip = = $horas * $precip ----> FAIL
and all variant. FAIL
reviewing and testing many options for that calculation I could see that value of "$post_array['calend_precip']" never enter to function callback and take 'null' on this. But in the grid the value field 'calend_precip' appears correctly...!!!!
Finally found that erasing '$crud->field_type('calend_precip','readonly')' WORK...!!!
but I need that field in 'readonly'.
I do not understand why '$post_array['calend_total'] = $horas' is calculated correctly if used in the same way that 'calend_precip'
all the field have the same type 'decimal(10,2)'
Best regards..
P.L.