如何从多个表中获取数据?

时间:2019-02-10 21:09:20

标签: codeigniter

我想从下拉列表中过滤数据,我想消除费用组并在费用类型上散发冗余,如下图所示。我想要的只是按费用类型获取数据,而不管学生链接的是哪种组类型。

Sample fetching of billing base on grade level(class) and Section(Section)

Database Relationship

编解码器活动记录模型:

  public function getDueStudentFees($feetype_id=null, $feegroup_id = null, $fee_groups_feetype_id = null, $class_id = null, $section_id = null) {

    $query = "SELECT IFNULL(student_fees_deposite.id, 0) as student_fees_deposite_id, IFNULL(student_fees_deposite.fee_groups_feetype_id, 0) as fee_groups_feetype_id, IFNULL(student_fees_deposite.amount_detail, 0) as amount_detail, student_fees_master.id as `fee_master_id`,fee_groups_feetype.feetype_id ,fee_groups_feetype.amount,fee_groups_feetype.due_date, `classes`.`id` AS `class_id`, `student_session`.`id` as `student_session_id`, `students`.`id`, `classes`.`class`, `sections`.`id` AS `section_id`, `sections`.`section`, `students`.`id`, `students`.`student_no`, `students`.`deped_lrn`, `students`.`admission_date`, `students`.`firstname`, `students`.`lastname`, `students`.`middlename`, `students`.`dob`, `students`.`current_address`, `students`.`guardian_name`, `students`.`guardian_relation`, `students`.`guardian_phone`, `students`.`guardian_address`, `students`.`is_active`, `students`.`created_at`, `students`.`updated_at`, `students`.`father_name`, `students`.`gender` FROM `students` JOIN `student_session` ON `student_session`.`student_id` = `students`.`id` JOIN `classes` ON `student_session`.`class_id` = `classes`.`id` JOIN `sections` ON `sections`.`id` = `student_session`.`section_id` INNER JOIN student_fees_master on student_fees_master.student_session_id=student_session.id and student_fees_master.fee_session_group_id=" . $this->db->escape($feegroup_id) . " LEFT JOIN student_fees_deposite on student_fees_deposite.student_fees_master_id=student_fees_master.id and student_fees_deposite.fee_groups_feetype_id=" . $this->db->escape($fee_groups_feetype_id) . "  INNER JOIN fee_groups_feetype on fee_groups_feetype.id =" . $this->db->escape($fee_groups_feetype_id) . " WHERE `student_session`.`session_id` = " . $this->current_session . " AND 
        `students`.`is_active` = 'yes'  AND 
        `student_session`.`class_id` = " . $this->db->escape($class_id) . " AND `student_session`.`section_id` = " . $this->db->escape($section_id) . " ORDER BY `students`.`id`";
    $query = $this->db->query($query);
    return $query->result_array();
}

编解码器活动记录控制器:

    function feesearch() {
    $data['title'] = 'student fees';
    $class = $this->class_model->get();
    $data['classlist'] = $class;
    $feesessiongroup = $this->feesessiongroup_model->getFeesByGroup();

    $data['feesessiongrouplist'] = $feesessiongroup;
    $this->form_validation->set_rules('feegroup_id', 'Fee Group', 'trim|required|xss_clean');

    $this->form_validation->set_rules('class_id', 'Class', 'trim|required|xss_clean');
    $this->form_validation->set_rules('section_id', 'Section', 'trim|required|xss_clean');
    if ($this->form_validation->run() == FALSE) {
        $this->load->view('layout/header', $data);
        $this->load->view('studentfee/studentSearchFee', $data);
        $this->load->view('layout/footer', $data);
    } else {
        $data['student_due_fee'] = array();
        $feetype_id = $this->input->post('feegroup_id');
        $feegroup = explode("-", $feetype_id);
        $feegroup_id = $feegroup[0];
        $fee_groups_feetype_id = $feegroup[1];
        $class_id = $this->input->post('class_id');
        $section_id = $this->input->post('section_id');
        $student_due_fee = $this->studentfee_model->getDueStudentFees($feetype_id, $feegroup_id, $fee_groups_feetype_id, $class_id, $section_id);
        if (!empty($student_due_fee)) {
            foreach ($student_due_fee as $student_due_fee_key => $student_due_fee_value) {
                $amt_due = $student_due_fee_value['amount'];
                $student_due_fee[$student_due_fee_key]['amount_discount'] = 0;
                $student_due_fee[$student_due_fee_key]['amount_fine'] = 0;
                $a = json_decode($student_due_fee_value['amount_detail']);
                if (!empty($a)) {
                    $amount = 0;
                    $amount_discount = 0;
                    $amount_fine = 0;

                    foreach ($a as $a_key => $a_value) {
                        $amount = $amount + $a_value->amount;
                        $amount_discount = $amount_discount + $a_value->amount_discount;
                        $amount_fine = $amount_fine + $a_value->amount_fine;
                    }
                    if ($amt_due <= $amount) {
                        unset($student_due_fee[$student_due_fee_key]);
                    } else {

                        $student_due_fee[$student_due_fee_key]['amount_detail'] = $amount;
                        $student_due_fee[$student_due_fee_key]['amount_discount'] = $amount_discount;
                        $student_due_fee[$student_due_fee_key]['amount_fine'] = $amount_fine;
                    }
                }
            }
        }


        $data['student_due_fee'] = $student_due_fee;
        $this->load->view('layout/header', $data);
        $this->load->view('studentfee/studentSearchFee', $data);
        $this->load->view('layout/footer', $data);
    }
}

编解码器活动记录视图:

<form action="<?php echo site_url('studentfee/feesearch') ?>"  method="post" accept-charset="utf-8">
    <div class="box-body">
    <?php echo $this->customlib->getCSRF(); ?>
        <div class="row">
            <div class="col-md-4">
                <div class="form-group">
                    <label for="exampleInputEmail1">Fee Schedules</label><small class="req"> *</small>
                    <select autofocus="" id="feegroup_id" name="feegroup_id" class="form-control" >
                        <option value=""><?php echo $this->lang->line('select'); ?></option>
                        <?php foreach ($feesessiongrouplist as $feecategory) { ?>
                            <optgroup label="<?php echo $feecategory->group_name; ?>">
                            <?php
                                if (!empty($feecategory->feetypes)) {
                                    foreach ($feecategory->feetypes as $fee_key => $fee_value) { ?>
                                <option value="<?php echo $feecategory->id . "-" . $fee_value->id; ?>"><?php echo $fee_value->type; ?></option>
                                    <?php } } ?>
                            </optgroup>
                        <?php } ?>
                    </select>
                    <span class="text-danger"><?php echo form_error('feegroup_id'); ?></span>
                </div>
            </div>
            <div class="col-md-4">
                <div class="form-group">
                    <label for="exampleInputEmail1">Grade Level</label><small class="req"> *</small>
                    <select  id="class_id" name="class_id" class="form-control" >
                        <option value=""><?php echo $this->lang->line('select'); ?></option>
                        <?php foreach ($classlist as $class) { ?>
                            <option value="<?php echo $class['id'] ?>" <?php if (set_value('class_id') == $class['id']) echo "selected=selected" ?>><?php echo $class['class'] ?></option>
                        <?php $count++; } ?>
                    </select>
                    <span class="text-danger"><?php echo form_error('class_id'); ?></span>
                </div>
            </div>
            <div class="col-md-4">
                <div class="form-group">
                    <label for="exampleInputEmail1"><?php echo $this->lang->line('section'); ?></label><small class="req"> *</small>
                    <select  id="section_id" name="section_id" class="form-control" >
                        <option value=""><?php echo $this->lang->line('select'); ?></option>
                    </select>
                    <span class="text-danger"><?php echo form_error('section_id'); ?></span>
                </div>
            </div>
        </div>
    </div>
    <div class="box-footer">
        <button type="submit" class="btn btn-sm btn-success pull-right"><i class="fa fa-search"></i> <?php echo $this->lang->line('search'); ?></button>
    </div>
</form>

0 个答案:

没有答案