⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Help!! How to use arithmetic on add field using callback??



arissurya

arissurya
  • profile picture
  • Member

Posted 13 September 2016 - 17:01 PM

So i have a script like this...

 

 public function  stock ()
    {
        $crud = new grocery_CRUD();
        
        $crud->set_theme('flexigrid');
        $crud->set_table('stock');
        $crud->columns('no','keterangan','qtyStock','priceStock','totalStock','qtyIn','priceIN','totalIn','qtyOut','priceOut','totalOut','qtySaldo','priceSaldo',totalSaldo');
         
        $crud->fields(('no','keterangan','qtyStock','priceStock','totalStock','qtyIn','priceIN','totalIn','qtyOut','priceOut','totalOut','qtySaldo','priceSaldo',totalSaldo');

 

);
        
        $output = $crud->render();
 
        $this->_example_output($output);
    }
   

and the issue is i want to edit the field with a arithmetic value.. l

 

example..

 

when i input data on totalStock, it will automaticaly have a function  qtyStock */(multiplication) priceStock = totalStock and same with totalIn, totalOut and totalSaldo..

 

how do i do that??

 


arissurya

arissurya
  • profile picture
  • Member

Posted 13 September 2016 - 17:38 PM

$crud->callback_before_insert(array($this,'perkalian'));

 

 

  public function perkalian($post_array)
{

      if(isset($post_array['qtyPersediaan'],$post_array['hargaPersediaan']))
      {
          $post_array['jumlahPersediaan'] = $post_array['qtyPersediaan'] + ['hargaPersediaan'];

      }

      return $post_array;
}
   

 

 

i write this code but not working.. :(

 

Anybody can help?