codeigniter multi sum,group by

时间:2017-08-01 14:12:13

标签: php codeigniter group-by sum

我试图总结total_amount,total_tax,amount_inc_tax和逐月,计算出现错误,它必须是我选择和总结各个列的方式,也许有更好的方法来总结但我不是确定怎么做,如果你能帮助我真的很感激。

数据库结构

purchase_orders_id |传说| total_amount | total_tax | amount_in_tax | delivery_date(日期)| insert_date(日期时间)

我的模特页面..

public function get_all_purchase_order_analysis(){
       $this->db->select('*');      
       $this->db->select('SUM(total_amount) AS total_amount', FALSE);
       $this->db->select('SUM(total_tax) AS total_tax', FALSE);
       $this->db->select('SUM(amount_inc_tax) AS amount_inc_tax', FALSE);

       $this->db->select('MONTH(stoma_purchase_orders.delivery_date) AS pmonth, YEAR(stoma_purchase_orders.delivery_date) AS pyear');

       $this->db->from('purchase_orders'); 
           $this->db->where('storeid', $storeid);
       $this->db->where('status', 'Yes');       

      $this->db->group_by('pmonth, pyear');           
       $result=$this->db->get();
      return $result->result_array();
    }

我的控制器页面..

public function report() {  
        if($this->input->post('submit')) {

            $this->data['reports']=  $this->orderings->get_report($this->input->post('date_from'), $this->input->post('date_to'), $this->input->post('supplierid'));

        } else {
            $this->data['reports']=  $this->orderings->get_report();
        }

        $this->load->view('ordering/report', $this->data);

     }

我的观点页面......

订单报告
       <div class="widget-content nopadding">


            <div class="form-group">

                <table class="table pull-left table-bordered" id="table-report">
                    <thead>
                        <tr>
                            <th>Month</th>
                            <th>Orders Value</th>
                            <th>Tax Value</th>
                            <th>Total Orders Inc. Tax</th>
                        </tr>
                    </thead>

                    <tbody>
                       <?php  if(count($purchase_orders) > 0) { ?>
<?php for($i=0;$i<count($purchase_orders);$i++){?>        
    <tr>
         <td data-th="Month" title="<?php
            $time=strtotime($purchase_orders[$i]['delivery_date']);
            $month=date("F",$time);
            $year=date("Y",$time);
            echo $month
             ?>">
             <a class="actioncol cursor" onclick="window.location.href='<?php echo site_url('clocktime/monthly_hrs_allemployee/'); ?>'" title="Month-Year"><?php
            $time=strtotime($purchase_orders[$i]['delivery_date']);
            $month=date("F",$time);
            $year=date("Y",$time);
            echo $month, - $year
             ?></a>
                       </td>
        <td data-th="Total" title="<?php echo $purchase_orders[$i]['total_amount']; ?>">
            <?php echo ($purchase_orders[$i]['total_amount']); ?>
        </td>
        <td data-th="Total" title="<?php echo $purchase_orders[$i]['total_tax']; ?>">
            <?php echo ($purchase_orders[$i]['total_tax']); ?> 
        </td>
        <td data-th="Total" title="<?php echo $purchase_orders[$i]['amount_inc_tax']; ?>">
            <?php echo ($purchase_orders[$i]['amount_inc_tax']); ?>
        </td>

    </tr>
<?php } ?>
<?php } ?> 
                    </tbody>
                </table>

0 个答案:

没有答案