Beispiel #1
0
 /**
  * Get minimum notes from a specified value
  *
  * @param int $value Input value;
  * @return array All notes that represent the value
  */
 static function getMinNotes($value)
 {
     if (!is_int($value) || $value <= 0) {
         return ['error' => 'InvalidArgumentException'];
     }
     $availableNotes = Cash::availableNotes();
     $return = [];
     foreach ($availableNotes as $note => $qty) {
         $note = (string) $note;
         $return[$note] = 0;
         while ($value >= $note && ($qty > 0 || $qty == true)) {
             if (is_int($qty)) {
                 $qty--;
             }
             $return[$note]++;
             $value -= $note;
         }
     }
     if (!$value == 0) {
         return ['error' => 'BillUnavaiableException'];
     }
     return array_filter($return);
 }