Hello Friends , I am new in Grocery CRud and Codeignitor,
I want to Generate Error in callback_before_insert and show on add page,
in sale_item page i am asking for sale_item.quantity and that quantity i am comparing with item_stock.quantity if sale_item.quantity is greater than item_stock.quantity then i want to generate error in call_back_before_insert and show error to the user..
public function m_item_sale()
{
$this->checksession();
try{
$crud = new Extension_grocery_CRUD();
$crud->set_theme('datatables');
$crud->set_table('m_item_sale');
$data['title']="Sale";
$crud->set_relation('item_id','m_item','name');
$crud->display_as('item_id','Item');
$crud->set_subject('Item Sale');
$crud->callback_before_insert(array($this, '_callback_before_insert'));
if($data['message_insert_error']=="yes")
{
$crud->set_lang_string('error_message','Cannot add the record');
}
$output = $crud->render();
$this->_example_output($output);
}
catch(Exception $e)
{
show_error($e->getMessage().' --- '.$e->getTraceAsString());
}
}
function _callback_before_insert($post_array)
{
try{
$post_array['date']= date('Y-m-d');
$this->db->select('qty');
$query = $this->db->get_where('m_item', array('id' => $post_array['item_id']));
$acct = $query->row_array();
if($acct['qty']>=$post_array['qty']){
$data = array(
'qty' => $acct['qty']-$post_array['qty'],
);
$where = array(
'id' => $post_array['item_id']
);
$this->db->where($where);
$this->db->update('m_item',$data);
return $post_array ;
}
else
{
return false ;
}
}
catch(Exception $e)
{
}
}