0

我需要帮助来汇总总成本并将其显示在报告中。我设法将数量和成本相乘,但现在我如何总结显示乘数的列?下面是代码。

function inventory_summary($export_excel=0)
{
    $this->load->model('reports/Inventory_summary');
    $model = $this->Inventory_summary;
    $tabular_data = array();
    $report_data = $model->getData(array());
    foreach($report_data as $row)
    {
        $tabular_data[] = array($row['name'], $row['item_number'], $row['cost_price'], $row['quantity'], $Total_total=$row['quantity']*$row['cost_price']);
    }


    $data = array(
        "title" => $this->lang->line('reports_inventory_summary_report'),
        "subtitle" => '',
        "headers" => $model->getDataColumns(),
        "data" => $tabular_data,
        "summary_data" => $model->getSummaryData(array()),
        "export_excel" => $export_excel
    );

    $this->load->view("reports/tabular",$data); 
}

$Total_total 这个变量是从mysql数据库中提取并相乘的数据,因此不保存在数据库中。

补充:我要总结的栏目截图链接:http: //i.imgur.com/ujOyGL0.png

除此之外如何以小数点显示总计列?我搜索谷歌高低,但我找不到任何在 sql 结果上添加小数的教程。

感谢任何帮助我完成报告的帮助。谢谢!

4

2 回答 2

1

干得好

function inventory_summary($export_excel=0)
{
    $this->load->model('reports/Inventory_summary');
    $model = $this->Inventory_summary;
    $tabular_data = array();
    $report_data = $model->getData(array());

     $Totalprice=0;
        foreach($report_data as $row)
        {
        $Total_total=$row['quantity']*$row['cost_price'];
        $Total_total= number_format((float)$Total_total, 2, '.', '');
        $tabular_data[] = array($row['name'], $row['item_number'], $row['cost_price'], $row['quantity'],$Total_total );
        $Totalprice += $Total_total;
     }

    $tabular_data['Totalprice']=number_format((float)$Totalprice, 2, '.', '');


    $data = array(
        "title" => $this->lang->line('reports_inventory_summary_report'),
        "subtitle" => '',
        "headers" => $model->getDataColumns(),
        "data" => $tabular_data,
        "summary_data" => $model->getSummaryData(array()),
        "export_excel" => $export_excel
    );

    $this->load->view("reports/tabular",$data); 
}
于 2013-08-09T16:25:33.427 回答
0

create你应该array喜欢,

function inventory_summary($export_excel=0)
{
    $this->load->model('reports/Inventory_summary');
    $model = $this->Inventory_summary;
    $tabular_data = array();
    $report_data = $model->getData(array());
    foreach($report_data as $row)
    {
       //create associative array here
       $tabular_data[]=array('name'=>$row['name'],'item_number'=>$row['item_number'],
                  'cost_price'=> $row['cost_price'],'quantity'=> $row['quantity']);
    }
    $data = array(
        "title" => $this->lang->line('reports_inventory_summary_report'),
        "subtitle" => '',
        "headers" => $model->getDataColumns(),
        "data" => $tabular_data,
        "summary_data" => $model->getSummaryData(array()),
        "export_excel" => $export_excel
    );

    $this->load->view("reports/tabular",$data); 
}

在展示的时候,你可以通过它data访问每一个array variableassociative name

于 2013-08-09T16:27:37.763 回答