Javascript 我需要从属于同一项目的一些任务中选择更多的值

Javascript 我需要从属于同一项目的一些任务中选择更多的值,javascript,php,arrays,Javascript,Php,Arrays,我的问题是:是否有其他方法可以从属于同一项目的所有任务中选择所需的值并求和?我在向下描述中尝试的其他方法 说明: 我有一个可以创建项目的应用程序,在项目内部,我可以创建任务。对于每个任务,我都可以添加一个百分比并计算一个价格(示例图1) 然后我有一个报告页面,我想计算同一项目所有任务的所有价格(示例图2) 我的问题是,当我想从属于同一项目的所有任务中选择所有价格,并在报表页面的“价格”表中求和时。 目前,我用我写下的代码尝试了一种方法,但它没有按照我的需要工作,因为它从项目的第一个任务中获取了正

我的问题是:是否有其他方法可以从属于同一项目的所有任务中选择所需的值并求和?我在向下描述中尝试的其他方法

说明:

我有一个可以创建项目的应用程序,在项目内部,我可以创建任务。对于每个任务,我都可以添加一个百分比并计算一个价格(示例图1)

然后我有一个报告页面,我想计算同一项目所有任务的所有价格(示例图2)

我的问题是,当我想从属于同一项目的所有任务中选择所有价格,并在报表页面的“价格”表中求和时。 目前,我用我写下的代码尝试了一种方法,但它没有按照我的需要工作,因为它从项目的第一个任务中获取了正确的值,但从同一项目的其他任务中没有获取正确的值

图1

图2(但这里的问题是,只有第一个数组正确,而另一个数组不正确)

我使用的代码(我在代码中用“不起作用的代码”这一部分注释了求和):


如果你看这里,结果必须是-919.8/0/84:第一个任务的结果必须是919.8,第二个任务的结果必须是102.2
$calA
等于
$calF
?其次,它没有得到这个-
$calE=($itemtotal+$aRow['task\u item\u manual\u total\u price']-$itemtotal)
首先添加
$itemtotal
,然后删除它。
$calG=get\u task\u custom\u bilable\u amount($aRow['id']);$calE=($itemtotal+$aRow['task\u item\u manual\u total\u price']-$itemtotal);如果(isset($aRow['task\'item\'u percentage']){$calE=(舍入($itemtall+($calF*$aRow['task\'duration']/60)))*($aRow['task\'item\'u percentage']/100))+(舍入($itemtall+($calF*$aRow['task\'duration']/60));//additionalPriceTotal}
我这样做了,但仍然没有逐个转储数据。。像这样
task\u id-一些值/另一个值等等
,看看有什么不对
<?php



defined('BASEPATH') or exit('No direct script access allowed');



$hasPermissionEdit   = has_permission('tasks', '', 'edit');

$hasPermissionDelete = has_permission('tasks', '', 'delete');

$tasksPriorities     = get_tasks_priorities();



$aColumns = [

    db_prefix() . 'tasks.id as id',

    db_prefix() . 'tasks.name as task_name',

    'count(tbltasks.id) as totaltasks',

    //'(SELECT GROUP_CONCAT(name SEPARATOR ",") FROM ' . db_prefix() . 'tasks) as itemlist',

];



$sIndexColumn = 'id';

$sTable       = db_prefix() . 'tasks';



$where = [];

$join  = [];

$sGroupBy = ' group by '.db_prefix() . 'tasks.rel_id';



// =============== Filter =================

    if (isset($ts_filter_data['period-from']) && $ts_filter_data['period-from'] != '' && isset($ts_filter_data['period-to']) && $ts_filter_data['period-to'] != '') {



        $ts_filter_from          = to_sql_date($ts_filter_data['period-from']);

        $ts_filter_from          = date('Y-m-d', strtotime($ts_filter_from));

        $ts_filter_to            = to_sql_date($ts_filter_data['period-to']);

        $ts_filter_to            = date('Y-m-d', strtotime($ts_filter_to));

    }



    if (isset($ts_filter_data['this_month']) && $ts_filter_data['this_month'] != '') {

        $ts_filter_from = date('Y-m-01'); 

        $ts_filter_to  = date('Y-m-t 23:59:59');

    }



    if (isset($ts_filter_data['last_month']) && $ts_filter_data['last_month'] != '') {

        $ts_filter_from = date('Y-m-01', strtotime('-1 MONTH'));; 

        $ts_filter_to  = date('Y-m-t 23:59:59', strtotime('-1 MONTH'));

    }



    if (isset($ts_filter_data['this_week']) && $ts_filter_data['this_week'] != '') {

        $ts_filter_from = date('Y-m-d', strtotime('monday this week'));

        $ts_filter_to  = date('Y-m-d 23:59:59', strtotime('sunday this week'));

    }



    if (isset($ts_filter_data['last_week']) && $ts_filter_data['last_week'] != '') {

        $ts_filter_from = date('Y-m-d', strtotime('monday last week'));

        $ts_filter_to  = date('Y-m-d 23:59:59', strtotime('sunday last week'));

    }



    if($ts_filter_from){

        array_push($where, 'AND '.db_prefix().'tasks.startdate >="'.$ts_filter_from.'"');

    }



    if($ts_filter_to){

        array_push($where, 'AND '.db_prefix().'tasks.startdate <="'.$ts_filter_to.'"');

    }



// =============== Filter =================



array_push($where, 'AND '.db_prefix().'tasks.rel_type="project"');

// Script By Dev Websyms

$aColumns = hooks()->apply_filters('tasks_table_sql_columns', $aColumns);



// Fix for big queries. Some hosting have max_join_limit

if (count($custom_fields) > 4) {

    @$this->ci->db->query('SET SQL_BIG_SELECTS=1');

}



$result = data_tables_init(

    $aColumns,

    $sIndexColumn,

    $sTable,

    $join,

    $where,

    [

        'tbltasks.rel_type',

        'tbltasks.rel_id',

        'tbltasks.task_item_percentage',

        'tbltasks.task_duration',

        tasks_rel_name_select_query() . ' as rel_name',



        get_sql_select_task_assignees_ids() . ' as assignees_ids',



        '(SELECT staffid FROM ' . db_prefix() . 'task_assigned WHERE taskid=' . db_prefix() . 'tasks.id AND staffid=' . get_staff_user_id() . ') as is_assigned',

    ],

    $sGroupBy

);



$output  = $result['output'];

$rResult = $result['rResult'];



$loop = 1;

foreach ($rResult as $aRow) {

    $row = [];

    $projectTaskIds = get_assign_project_task($aRow['rel_id']);

    $assignees_ids = $aRow['assignees_ids'];

    $assignees_id = explode(',', $assignees_ids);

    $calA = get_task_user_hourly_rate($assignees_id[0]); // hourly_rate


    if($projectTaskIds && count($projectTaskIds)){

    $realTime = 0;
    $estimateCost = 0;
    $itemName = '';
    $realCost = 0;
    $realCostArr = array();
    $totalCalEArr = array();

    foreach ($projectTaskIds as $key => $projectTaskId) {

        // echo $projectTaskId['id'];
        // echo "<br>";
        $calB = 0;
        $calC = 0;
        
        $itemtotal = 0;
        $items = get_items_by_type('task', $projectTaskId['id']);
        if($items && count($items) > 0){
            $itemNo = 1;
            foreach ($items as $key => $item) {
                $itemtotal += ($item["rate"]*$item["qty"]);
                $itemName .= '<div>'.$itemNo.'.'.$item["description"].' <b>('.round($item["qty"]).')</b>'.'</div>';
                $itemNo++;
            }
        }
            
         // =============== the code that doesn't work ============
        $calF = get_task_user_hourly_rate($assignees_id[0]); // hourly_rate
        $calG = get_task_custom_billable_amount($aRow['id']);
        
        $calE = ($itemtotal+$aRow['task_item_manual_total_price']-$itemtotal);
        if(isset($aRow['task_item_percentage'])){
            $calE = ((round($itemtotal + ((($calF * $aRow['task_duration'] / 60))))
                      *($aRow['task_item_percentage']/100)))
                +(round($itemtotal + (($calF * $aRow['task_duration'] / 60)))); // additionalPriceTotal
         
        }
        
        $totalCalEArr[] = $calE;
        
        if($totalCalEArr && count($totalCalEArr) > 0){
            $totalsCalEaMount = 0;
            foreach ($totalCalEArr as $key => $totalvalue) {
                $totalsCalEaMount += $totalvalue;
            }
        }
        // =============== the code that doesnt work ============

        $realTime += get_calc_task_real_logged_time($projectTaskId['id']);
        $calB = get_task_custom_billable_amount($projectTaskId['id']);
        
        if($aRow['task_item_percentage']){
            $calC = ((round($itemtotal + ((($calF * $aRow['task_duration'] / 60))))*($aRow['task_item_percentage']/100)))+(round($itemtotal + (($calF * $aRow['task_duration'] / 60)))); // additionalPriceTotal
        } else {
            $calC = ($itemtotal+$aRow['task_item_manual_total_price']-$itemtotal);
        }

        $estimateCost += round($itemtotal+($calA * $aRow['task_duration'] / 60)); 
        $realCost = round($itemtotal+$calB);
        
//           if($calC = 0){  $realCost = round($itemtotal+$calB);} else { $realCost = round($itemtotal+$calB+$calC);
// }
        $realCostArr[] = $realCost;

    }
    if($realCostArr && count($realCostArr) > 0){
        $realCostAmount = 0;
        foreach ($realCostArr as $key => $reslcostvalue) {
            $realCostAmount += $reslcostvalue;
        }
    }
}

$outputName = '';
$relName = '';
$row[] = $loop;

if ($aRow['rel_name']) {
    $relName = task_rel_name($aRow['rel_name'], $aRow['rel_id'], $aRow['rel_type']);
    $link = task_rel_link($aRow['rel_id'], $aRow['rel_type']);
    $relName = '<span class="hide"> - </span><a class="text-muted task-table-related" data-toggle="tooltip" title="' . _l('task_related_to') . '" href="' . $link . '">' . $relName . '</a>';
}

$row[] = $relName;
$row[] = count($projectTaskIds);
$row[] = $itemName;
$row[] = $aRow['task_duration']*count($projectTaskIds);
$row[] = round($realTime/60);
$row[] = round($estimateCost);
$row[] = round($realCostAmount);
$row[] = '';
$row[] = $totalCalEArr; // display as array or 
//$row[] = $totalsCalEaMount; //to display as a sum
$output['aaData'][] = $row;
$loop++;
}