<commit_before><?php
class Return_model extends CI_Model {

    public function __construct()
    {
        parent:: __construct();
    }

    public function return_items_to_inventory($item, $person, $reason, $userid, $ischecked)
    {
        $quant = count($item);

        $this->db->select('dist_id')
            ->where_in('item_det_id',$item);
        $query = $this->db->get('item_detail');
        $row = $query->row_array();
        $distid = intval($row['dist_id']) ;


        $this->db->select('dept_id');
        $this->db->where('dist_id',$distid);
        $query = $this->db->get('distribution');
        $row = $query->row_array();
        $deptid = intval($row['dept_id']) ;

        $this->db->where('dist_id',$distid);
        $this->db->set('quantity','quantity-'.$quant,FALSE);
        $this->db->update("distribution");

        if ($ischecked == 'yes') {
            $this->db->set('dist_id',null);
            $this->db->set('item_status','defective');
            $this->db->where_in('item_det_id',$item);
            $this->db->update('item_detail');
        } else {
            $this->db->set('dist_id',null);
            $this->db->set('item_status','returned');
            $this->db->where_in('item_det_id',$item);
            $this->db->update('item_detail');
        }
        

        $this->db->set('quantity','quantity+'.$quant,FALSE);
        $this->db->update('item');

        $data = array();
        foreach($item as $item_det_id)
        {
            $data[] = array('reason'=>$reason,
                'dept_id' => $deptid,
                'item_det_id' =>$item_det_id['item_det_id'],
                'return_person' => $person,
                'dist_id' => $distid,
                'user_id' => $userid);<commit_msg>return bug fix<commit_after><?php
class Return_model extends CI_Model {

    public function __construct()
    {
        parent:: __construct();
    }

    public function return_items_to_inventory($item, $person, $reason, $userid, $ischecked)
    {
        $quant = count($item);
        $this->db->select('dist_id');
        $this->db->where_in('item_det_id', $item);
        $query = $this->db->get('item_detail');
        $distids = $query->result_array();

        $dept_ids = array();
        $dist_ids = array();
        foreach ($distids as $dist_id) {
            $this->db->where('dist_id',$dist_id['dist_id']);
            $this->db->set('quantity','quantity-1',FALSE);
            $this->db->update("distribution");

            $this->db->select('dept_id');
            $this->db->where('dist_id',$dist_id['dist_id']);
            $query = $this->db->get('distribution');
            $row = $query->row_array();
            $deptid = intval($row['dept_id']) ;
            array_push($dept_ids, $deptid);
            array_push($dist_ids, $dist_id['dist_id']);
        }

        if ($ischecked == 'yes') {
            $this->db->set('dist_id',null);
            $this->db->set('item_status','defective');
            $this->db->where_in('item_det_id',$item);
            $this->db->update('item_detail');
        } else {
            $this->db->set('dist_id',null);
            $this->db->set('item_status','returned');
            $this->db->where_in('item_det_id',$item);
            $this->db->update('item_detail');
        }
        

        $this->db->set('quantity','quantity+'.$quant,FALSE);
        $this->db->update('item');

        $data = array();
        $index = 0;
        foreach($item as $item_det_id)
        {
            $data[] = array('reason'=>$reason,
                'dept_id' => $dept_ids[$index],
                'item_det_id' =>$item_det_id['item_det_id'],
                'return_person' => $person,
                'dist_id' => $dist_ids[$index],
                'user_id' => $userid);

            $index++;
{'fraction_non_alphanumeric': 0.19947575360419398, 'fraction_numerical': 0.0005242463958060288, 'mean_word_length': 2.145919208573784, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 94, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1767491', 'n_tokens_mistral': 1253, 'n_tokens_neox': 1213, 'n_words': 153}