Ejemplo n.º 1
0
 static function add_code_usd($code, $millicents)
 {
     if (strlen($code) != 1 || !preg_match('/^[a-z]$/', $code)) {
         return false;
     }
     # code valid?
     if (intval($millicents) == 0) {
         return false;
     }
     $db = Get::db('songwork');
     $db->query("SELECT code FROM pricerefs WHERE code='{$code}'");
     if ($db->num_rows()) {
         return false;
     }
     # code available?
     $db->insert('pricerefs', array('code' => $code, 'currency' => 'USD', 'millicents' => intval($millicents)));
     $usd = new Money($millicents, 'USD');
     foreach (PriceRef::currencies() as $currency) {
         if ($currency == 'USD') {
             continue;
         }
         $x = $usd->converted_to($currency);
         $db->insert('pricerefs', array('code' => $code, 'currency' => $currency, 'millicents' => $x->millicents));
     }
     return true;
 }
Ejemplo n.º 2
0
 function minus(Money $m)
 {
     $that = $m->code == $this->code ? $m : $m->converted_to($this->code);
     return new Money($this->millicents - $that->millicents, $this->code);
 }