Beispiel #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;
 }
Beispiel #2
0
 function testCurrencies()
 {
     $y = PriceRef::currencies();
     $this->assertEquals(6, count($y));
     $this->assertTrue(in_array('JPY', $y));
 }
Beispiel #3
0
 function price_in($currency)
 {
     if (strval($this->me['pricecode']) == '') {
         return new Money(0, $currency);
     }
     return PriceRef::money_for_code_currency($this->me['pricecode'], $currency);
 }