如何在杂货店的一些逻辑操作后插入数据

i am very new to grocery crud.i have facing some problem with logical operation on insert_before_callback

i have a product table,when i will sell a product it will check the availability of the product.if the its available then it will insert it to the database

        $crud = new grocery_CRUD();
    //$crud->set_subject('Guards');
    $this->grocery_crud->set_table('chalan')
        ->set_subject('Chalan')
        //->fields('Date','cid','pid','voucher','qnty','Amount','Paid Amount','Due Amount','Remarks')
        ->columns('cdate','cid','eid','pid','voucher','qnty','price','Amount','paid','Due Amount','Check','remark')
        ->display_as('cdate','Date')
        ->display_as('check','Check')
        ->display_as('cid','Customer Name')
        ->display_as('voucher','Chalan No.')
        ->display_as('eid','Employee Name')
        ->display_as('pid','Item Name')
        ->display_as('qnty','Quantity')
        ->display_as('price','Price')
        ->display_as('remark','Remark')
        ->set_relation('eid','employee','name')
        ->set_relation('cid','Customer','name')
        ->set_relation('pid','product','name')
        ->callback_column('Amount',array($this,'_total_amount'))
        ->callback_column('Due Amount',array($this,'_due_amount'))
        ->set_rules('qnty','Quantity','numeric')
        ->set_rules('eid','Employee','String')
        ->set_rules('pid','Product','String')
        ->set_rules('qnty','Quantity','numeric')
        ->set_rules('cdate','Date','date')
        ->callback_before_insert(array($this,'_checkAvaiability'))
        ->unset_delete();
    //$crud->display_as('sec_guard_master_id','Guard Name');
    $output = $this->grocery_crud->render();
    //$data['viewName']="welcome";
    $this->load->view('search',$output);

here is my logic for _checkAvaiability

function _checkAvaiability($post_array){
    $total=100; // just for test
    if($post_array['qnty']>$total){
        return false;
    }
}

it runs without any filtering and always insert the data though the product exceed the total value.it will be vry helpful if some one fix this

Note that callback_before_insert does NOT has the behavior of stoping the insert if you return false (in fact, this callback must return an array containing the values that will be used in the insert operation that will happen right after the callback´s processing).

If you need some logic validation before a insert (in order to not allow it´s execution based on yours logic) there two things you could do:

1) Create a custom validation rule and add it using set_rules http://www.grocerycrud.com/documentation/options_functions/set_rules

I think this is probalby easier to do

2) You could implement a totally custom insert operation using the callback_insert. This callback escapes the auto insert of the CRUD, and runs only the inserted callback.

http://www.grocerycrud.com/documentation/options_functions/callback_insert