sub_total

@author Tom Haskins-Vaughan <tom@harvestcloud.com>
@since  2012-10-23
424555
public function sub_totalAction()
    {
        $session = $this->getRequest()->getSession();

        $orderCollection = $this->getCurrentCart();

        if ($orderCollection)
        {
            $sub_total = $orderCollection->getSubTotal();
        }
        else
        {
            $sub_total = 0;
        }

        return new Response('$'.number_format($sub_total, 2));
    }
125341
private function computeTotalCount($total, array $callableArgs = [])
    {
        if (null !== $this->totalCount) {
            return $this->totalCount;
        }

        $this->totalCount = \is_callable($total) ? \call_user_func_array($total, $callableArgs) : $total;

        return $this->totalCount;
    }
554900
def get_total_paid(self) -> Decimal:
        
        query = (
            self.get_splits_query()
        )
        splits = query.all()

        total = Decimal(0)
        for split in splits:
            total += split.value

        return total
277482
def subtotals
      x = {}
      charges.each do |r|
        x[r.product_code] ||= 0.to_f
        x[r.product_code]  += r.total_cost.to_f
      end
      return x
    end
1119966
public function get_total()
    {
        if ($this->total) {
            return $this->total;
        }

        $conn = $this->app->getApplicationBox()->get_connection();

        $sql_count = 'SELECT COUNT(DISTINCT Users.id) as total ' . $this->generate_sql_constraints();

        $stmt = $conn->prepare($sql_count);
        $stmt->execute($this->sql_params);
        $row = $stmt->fetch(PDO::FETCH_ASSOC);
        $stmt->closeCursor();

        $this->total = $row['total'];

        $this->page = 1;
        if ($this->total > 0 && is_int($this->offset_start) && is_int($this->results_quantity)) {
            $this->page = floor($this->offset_start / $this->results_quantity) + 1;
            $this->total_page = floor($this->total / $this->results_quantity) + 1;
        }

        return $this->total;
    }
1161482
public function getTotal()
  {
    $rawQuery = "SELECT count(*) as total FROM orders";

    // Perform the raw query.
    $rawResults = DB::select( DB::raw($rawQuery) );

    // Return the total.
    return $rawResults[0]->total;
  }
791960
public function total() {
        
        if(is_null($this->totalCount)) {
            $cpt = $this->getParent()->fetchQuery($this->countQuery);
            $this->totalCount = intval($cpt['cpt']);
        }
        
        return $this->totalCount;
    }
187924
function _calculateTotals() {
        if (empty($this->_calculateTotals)) {
            return;
        }

        $this->addSeparator();

        $totals = array();
        foreach ($this->_data as $row) {
            if (is_array($row)) {
                foreach ($this->_calculateTotals as $columnID) {
                    $totals[$columnID] += $row[$columnID];
                }
            }
        }

        $this->_data[] = $totals;
        $this->_updateRowsCols();
    }
506392
public function use_subquery()
	{
		return ( ! empty($this->relations) and ( ! empty($this->limit) or ! empty($this->offset)));
	}
474025
public function getRowsCountRecursive()
    {
        $totalCount = 0;
        foreach ($this->rows as $row) {
            $subTable = $row->getSubtable();
            if ($subTable) {
                $count = $subTable->getRowsCountRecursive();
                $totalCount += $count;
            }
        }

        $totalCount += $this->getRowsCount();
        return $totalCount;
    }
955051
def update_subtotals(self, current, sub_key):
        

        if not self.sub_counts.get(sub_key):
            self.sub_counts[sub_key] = {}
        for item in current:
            try:
                self.sub_counts[sub_key][item] += 1
            except KeyError:
                self.sub_counts[sub_key][item] = 1
362975
function array_sum_interval($array_external, $interval){

        $n_interval=explode(":", $interval);
        $sum = 0;
        for($i=$n_interval[0]; $i < ($n_interval[1]+1) ; $i++){
            $sum += $array_external[$i];
        }
        return $sum;

    }
605646
def feed(self, count, total=1):
        
        self._tot += total
        self._cnt += count
544975
def sub!(pat, rep)
      each_with_index { |fn, i| self[i] = fn.sub(pat, rep) }
      self
    end
1350571
public function aggregate($expr)
    {
        foreach ($expr as $k => $v) {
            if (is_array($v)) {
                if (isset($v['$count_if'])) {
                    unset($v['$count_if'][0]);
                    $v = ['$sum' => ['$cond' => [$v['$count_if'], 1, 0]]];
                } elseif (isset($v['$sum_if'])) {
                    $field = isset($v['$sum_if'][0]) ? $v['$sum_if'][0] : 1;
                    unset($v['$sum_if'][0]);
                    $v = ['$sum' => ['$cond' => [$v['$sum_if'], is_numeric($field) ? (float)$field : '$' . $field, 0]]];
                } elseif (isset($v['$avg_if'])) {
                    $field = isset($v['$avg_if'][0]) ? $v['$avg_if'][0] : 1;
                    unset($v['$avg_if'][0]);
                    $v = ['$avg' => ['$cond' => [$v['$avg_if'], is_numeric($field) ? (float)$field : '$' . $field, 0]]];
                }
                $this->_aggregate[$k] = $v;
                continue;
            }

            if (preg_match('#^(\w+)\((.*)\)$#', $v, $match) !== 1) {
                throw new MisuseException(['`:aggregate` aggregate is invalid.', 'aggregate' => $v]);
            }

            $accumulator = strtolower($match[1]);
            $normalizes = ['group_concat' => 'push',
                'std' => 'stdDevPop',
                'stddev' => 'stdDevPop',
                'stddev_pop' => 'stdDevPop',
                'stddev_samp' => 'stdDevSamp',
                'addtoset' => 'addToSet',
                'stddevpop' => 'stdDevPop',
                'stddevsamp' => 'stdDevSamp'];
            if (isset($normalizes[$accumulator])) {
                $accumulator = $normalizes[$accumulator];
            }
            $operand = $match[2];
            if ($accumulator === 'count') {
                $this->_aggregate[$k] = ['$sum' => 1];
            } elseif ($accumulator === 'count_if') {
                if ($cond = $this->_compileCondExpression($operand)) {
                    $this->_aggregate[$k] = ['$sum' => $cond];
                } else {
                    throw new MisuseException(['unknown COUNT_IF expression: `:expression`', 'expression' => $operand]);
                }
            } elseif ($accumulator === 'sum_if') {
                if ($cond = $this->_compileCondExpression($operand)) {
                    $this->_aggregate[$k] = ['$sum' => $cond];
                } else {
                    throw new MisuseException(['unknown SUM_IF expression: `:expression`', 'expression' => $operand]);
                }
            } elseif ($accumulator === 'avg_if') {
                if ($cond = $this->_compileCondExpression($operand)) {
                    $this->_aggregate[$k] = ['$avg' => $cond];
                } else {
                    throw new MisuseException(['unknown AVG_IF expression: `:expression`', 'expression' => $operand]);
                }
            } elseif (in_array($accumulator, ['avg', 'first', 'last', 'max', 'min', 'push', 'addToSet', 'stdDevPop', 'stdDevSamp', 'sum'], true)) {
                if (preg_match('#^[\w\.]+$#', $operand) === 1) {
                    $this->_aggregate[$k] = ['$' . $accumulator => '$' . $operand];
                } elseif (preg_match('#^([\w\.]+)\s*([\+\-\*/%])\s*([\w\.]+)$#', $operand, $match2) === 1) {
                    $operator_map = ['+' => '$add', '-' => '$subtract', '*' => '$multiply', '/' => '$divide', '%' => '$mod'];
                    $sub_operand = $operator_map[$match2[2]];
                    $sub_operand1 = is_numeric($match2[1]) ? (float)$match2[1] : ('$' . $match2[1]);
                    $sub_operand2 = is_numeric($match2[3]) ? (float)$match2[3] : ('$' . $match2[3]);
                    $this->_aggregate[$k] = ['$' . $accumulator => [$sub_operand => [$sub_operand1, $sub_operand2]]];
                } elseif ($cond = $this->_compileCondExpression($operand)) {
                    $this->_aggregate[$k] = ['$' . $accumulator => $this->_compileCondExpression($operand)];
                } else {
                    throw new MisuseException(['unknown `:operand` operand of `:aggregate` aggregate', 'operand' => $operand, 'aggregate' => $v]);
                }
            } else {
                throw new MisuseException([
                    'unknown `:accumulator` accumulator of `:aggregate` aggregate',
                    'accumulator' => $accumulator,
                    'aggregate' => $v
                ]);
            }
        }

        return $this->execute();
    }
394607
public function subtotal($decimals = null, $decimalPoint = null, $thousandSeperator = null)
    {
        $content = $this->getContent();

        $subTotal = $content->reduce(function ($subTotal, CartItem $cartItem) {
            return $subTotal + ($cartItem->qty * $cartItem->price);
        }, 0);

        return $this->numberFormat($subTotal, $decimals, $decimalPoint, $thousandSeperator);
    }
380931
public function total(array $args = []): int
    {
        $WpDb = $this->s::wpDb();

        // Establish args.

        $default_args = [
            // Also used by {@link all()}.
            'for_comments_only' => false,

            'include_post_ids' => [],
            'exclude_post_ids' => [],

            'include_post_types' => [],
            'exclude_post_types' => [],

            'include_post_statuses' => [],
            'exclude_post_statuses' => [],

            'exclude_drafts'             => true,
            'exclude_revisions'          => true,
            'exclude_trash'              => true,
            'exclude_password_protected' => false,
            'exclude_nav_menu_items'     => true,

            'no_cache' => false,
        ];
        $args = array_merge($default_args, $args);
        $args = array_intersect_key($args, $default_args);

        // Also used by {@link all()}.
        $args['for_comments_only'] = (bool) $args['for_comments_only'];

        $args['include_post_ids'] = (array) $args['include_post_ids'];
        $args['exclude_post_ids'] = (array) $args['exclude_post_ids'];

        $args['include_post_types'] = (array) $args['include_post_types'];
        $args['exclude_post_types'] = (array) $args['exclude_post_types'];

        $args['include_post_statuses'] = (array) $args['include_post_statuses'];
        $args['exclude_post_statuses'] = (array) $args['exclude_post_statuses'];

        $args['exclude_drafts']             = (bool) $args['exclude_drafts'];
        $args['exclude_revisions']          = (bool) $args['exclude_revisions'];
        $args['exclude_trash']              = (bool) $args['exclude_trash'];
        $args['exclude_password_protected'] = (bool) $args['exclude_password_protected'];
        $args['exclude_nav_menu_items']     = (bool) $args['exclude_nav_menu_items'];

        $args['no_cache'] = (bool) $args['no_cache'];

        // Check cache; already did this query?

        $cache_keys = $args; // Keys to consider when checking the cache.
        unset($cache_keys['no_cache']); // Cache key exclusions.

        if (($total = &$this->cacheKey(__FUNCTION__, $cache_keys)) !== null && !$args['no_cache']) {
            return $total; // Already cached this.
        }
        // Build the full SQL based on the arguments/data above.

        $sql = 'SELECT SQL_CALC_FOUND_ROWS `ID` FROM `'.esc_sql($WpDb->posts).'`'.

                ' WHERE 1=1'.// Initialize the WHERE clause in this query.

                ($args['include_post_ids'] ? ' AND `ID` IN('.$this->c::quoteSqlIn($args['include_post_ids']).')' : '').
                ($args['exclude_post_ids'] ? ' AND `ID` NOT IN('.$this->c::quoteSqlIn($args['exclude_post_ids']).')' : '').

                ($args['include_post_types'] ? ' AND `post_type` IN('.$this->c::quoteSqlIn($args['include_post_types']).')' : '').
                ($args['exclude_post_types'] ? ' AND `post_type` NOT IN('.$this->c::quoteSqlIn($args['exclude_post_types']).')' : '').

                ($args['include_post_statuses'] ? ' AND `post_status` IN('.$this->c::quoteSqlIn($args['include_post_statuses']).')' : '').
                ($args['exclude_post_statuses'] ? ' AND `post_status` NOT IN('.$this->c::quoteSqlIn($args['exclude_post_statuses']).')' : '').

                ($args['exclude_drafts'] ? " AND `post_type` NOT IN('draft','auto-draft')" : '').
                ($args['exclude_revisions'] ? " AND `post_type` != 'revision'" : '').
                ($args['exclude_trash'] ? " AND `post_status` != 'trash'" : '').
                ($args['exclude_password_protected'] ? " AND `post_password` = ''" : '').
                ($args['exclude_nav_menu_items'] ? " AND `post_type` != 'nav_menu_item'" : '').

                ($args['for_comments_only'] ? " AND (`comment_status` IN('1', 'open', 'opened') OR `comment_count` > '0')" : '').

                ' LIMIT 1'; // Only one to check `FOUND_ROWS()`.

        // Run the query and return total.

        if ($WpDb->query($sql) === false) {
            throw $this->c::issue('Query failure.');
        }
        return $total = (int) $WpDb->get_var('SELECT FOUND_ROWS()');
    }