Pages::getMin($field[,$addEmpty])

Version 3.8

Get the smallest value

Method will return a Field object, if given parameter is a field name. Otherwise returns decimal.

Return value

Float

Arguments

$field
1. Name of the field
2. Formula to calculate value as in Pages::calculate()
$addEmpty
IF True, also field with no value are counted in
Default: true

Example

Get Open Invoice that has the smallest total amount:

$min = $this->get('pages','invoice')
   ->addWhere('status','Open')
   ->getMin('total_amount');

Full documentation

This method is shorthand for:

foreach ( $this->get('pages','Invoice')->addWhere('status','Open') as $Invoice ){
    if ( $Invoice->total_amount->isUnder($value) ){
        $value = $Invoice->total_amount;
    }
}

Smallest not 0

Get Open Invoice that has the smallest total amount that is not 0:

$min = $this->get('pages','Invoice')->addWhere('status','Open')->getMin('total_amount',false);

Using formula

Get Open Invoice that had the smallest amount before discount:

$min = $this->get('pages','Invoice')->addWhere('status','Open')->getMin('total_amount*(100+discount_percent)/100');

Fieldtype: Date

DateField: The oldest invoice that is Open

$min = $this->get('pages','Invoice')->addWhere('status','Open')->getMin('invoice_date');

Fieldtype: Selection

SelectionField: The first status of customers Invoice:

$min = $this->get('pages','Invoice')->addWhere('customer',$customerId)->getMin('status');