jeudi 16 juin 2016

find the posted requirements under subcategories using codeigniter

I have three tables:jil_requirementbrief,jil_requirementdetail and jil_category. Table structure:

jil_requirementbrief:

 rqm_id,
    rqm_category,
    rqm_cusreference,
    rqm_manufacturer,
    rqm_productgroup,
    rqm_exdate,
    rqm_permission,
    rqm_managedby,
    rqm_dated

jil_requirementdetail:

rqmd_rqmid,rqmd_title,rqmd_requirements,rqmd_quantity,rqmd_unit.

jil_category:

ctg_id,ctg_name,parent_id

When we post a requirement,category and subcategory are selected and inserted into jil_requirementbrief table. Detailed informations are stored in detail table. I wrote a code to generate a pdf. When we select a parent category from dropdown with a date, requirements posted within that date will be generated as pdf.

My current problem is that.

For Eg: if i selected category named 'Materials' there are sub categories for materials, like aluminium,steel etc

In jil_requirementbrief table, rqm_category is the main category id and rqm_productgroup is the subcategory id.

I want result like this in the pdf.

If I selected category 'Materials' from dropdown,then the resulting pdf data will be as follows:

steel

 Serial No    Req.ID     Title    Quantity   Unit     Managed By

   1           3          ttt    6          tons      gowtham

   2            3         ttt    6          tons      gowtham

Aluminium

 Serial No  Req.ID  Title  Quantity  Unit    Managed By

   1         4       yy    6          tons   tom

   2         5       uuu    6          tons   tom

My controller

public function purchase_request() {
        $this->load->helper(array('form', 'url'));
        $cat_id = $this->input->post('category');
        $start_date = strtotime($this->input->post('StartDate'));
        $end_date = strtotime($this->input->post('EndDate'). ' +1 day');
        $end_date1 = strtotime($this->input->post('EndDate'));
        $data['user_data'] = $this->requirement_model->get_data_print($cat_id,$start_date,$end_date);


         $data['startdate']=$start_date;
          $data['enddate']=  $end_date1;    

        $this->load->library('M_pdf');
        if (function_exists("set_time_limit") == TRUE AND @ ini_get("safe_mode") == 0) {
            @set_time_limit(300);
        }
        $html = $this->load->view('moderator/print_purchaserequest', $data, true);
        $this->m_pdf->pdf->setTitle('Purchase Request Sheet');
        $this->m_pdf->pdf->WriteHTML($html);
        $this->m_pdf->pdf->Output('Sales_Log.pdf', "I");
    }

My Model

public function get_data_print($cat_id, $start, $end) {
        $this->db->select('*');
        $this->db->from('jil_requirementbrief');
        $this->db->join('jil_requirementdetail', 'jil_requirementdetail.rqmd_rqmid=jil_requirementbrief.rqm_id', 'left');
           $this->db->join('jil_requnits', 'jil_requnits.id=jil_requirementdetail.rqmd_unit', 'left');
         $this->db->join('jil_employees', 'jil_employees.emp_id=jil_requirementbrief.rqm_managedby', 'left');
         $this->db->order_by('jil_requirementdetail.rqmd_title','ASC');
        $this->db->where('jil_requirementbrief.rqm_category', $cat_id);
        $this->db->where('jil_requirementbrief.rqm_dated >=', $start);
        $this->db->where('jil_requirementbrief.rqm_dated <=', $end);
        $this->db->where('jil_requirementbrief.rqm_permission!=4');
        $query = $this->db->get();
        return $query->result();
    }

My View

<table style="width: 100%">
            <tr>
                <th style="width: 5px">Serial No</th>
                <th style="width: 5px">Req. ID</th>
                <th style="width: 50px">Title</th> 
                <th style="width: 10px">Quantity</th>
                <th style="width: 10px">Unit</th>
                <th style="width: 20px">Managed By</th>
            </tr>
            <?php
            $slno = 0;
            if (!empty($user_data)) {
                foreach ($user_data as $user_fetcheach) {
                    $slno++;
                    ?>

                    <tr>

                        <td><?php echo$slno; ?></td>
                        <td><?php echo $user_fetcheach->rqm_id; ?></td>
                        <td><?php echo $user_fetcheach->rqmd_title; ?></td>
                        <td><?php echo $user_fetcheach->rqmd_quantity; ?></td>
                        <td><?php echo $user_fetcheach->name; ?></td>
                        <td><?php echo $user_fetcheach->emp_name; ?></td>


                    </tr>

                    <?php
                }
            }
            ?>
        </table>

Aucun commentaire:

Enregistrer un commentaire