I am trying to add data in 2 tables. In the first table there are only 3 columns "Cheque start date","No of cheque" and "Amount"
and in the 2nd table i want to insert 'cheque_date','amount','pay_to' and "created_on" but in the 2nd table i want to insert these data "No of cheque" times, and 'cheque_date' will increase +1 month for each cheque for this i have written this code:
public function bulk_cheque(){
$crud = new grocery_CRUD();
$crud -> set_theme('datatables');
$crud -> set_table('bulk_cheques');
$crud -> add_fields('cheque_start_date', 'no_of_cheque','amount');
$crud -> callback_after_insert(array($this, 'create_all_cheques'));
$output = $crud -> render();
$this -> _example_output($output);
}
public function create_all_cheques($post_array, $primary_key){
$date=$post_array['cheque_start_date'];
$pay_to=$this->db->get('config')->row_array();
for($i=0;$i>$post_array['no_of_cheque'];$i++) {
$date=date('Y-m-d', strtotime("+1 months", strtotime($date)));
$data_array=array(
'cheque_date'=>$date,
'amount'=>$post_array['amount'],
'pay_to'=>$pay_to['pay_to'],
"created_on" => date('Y-m-d H:i:s')
);
var_dump($data_array);
$this->db->insert('cheques',$data_array);
}
return true;
}