/var/www/hkosl.com/littleark/webadmin/models/Currency.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php

class Currency extends BaseModel
{
    protected 
$table "currency";

    public function 
currencyRates()
    {
        return 
$this->hasMany('CurrencyRate''currency_code''iso_code');
    }

    public static 
$platform;
    public static function 
platform()
    {
        if (
self::$platform) {
            return 
self::$platform;
        }

        
// return Currency::where('iso_code', 'CNY')->first();
        // $temp = new self;
        
return self::$platform = new self(array(
            
'id'              => 55,
            
'deleted'         => 0,
            
'status'          => 1,
            
'name_en'         => 'Chinese yuan',
            
'name_tc'         => 'Chinese yuan',
            
'name_sc'         => 'Chinese yuan',
            
'name_idn'        => 'Chinese yuan',
            
'symbol'          => '¥',
            
'iso_code'        => 'CNY',
            
'fractional_unit' => 'Fen',
            
'number_to_basic' => '100',
            
'precision'       => '2',
        ));
    }

    public function 
moneyformat($amount$thousand_sep=false)
    {
        if(
$thousand_sep){
            
// get $this->dec_sep and $this->thousand_sep from attribute
            
return $this->symbol ' ' numberformat($amount$this->precision'.'',');
        }
        return 
$this->symbol ' ' round($amount$this->precision);
    }

    public static 
$supplier;
    public static function 
supplier()
    {
        if (
self::$supplier) {
            return 
self::$supplier;
        }

        return 
self::$supplier Supplier::find($_SESSION['supplier_id'])->currency;
    }

    public static function 
negotiate($accepts = [], $default "CNY")
    {
        
$accepts count($accepts) > $accepts : ['ko''id''km''zh-hk''zh-tw''zh''en'];

        
$accept_factory = new Aura\Accept\AcceptFactory($_SERVER);
        
$accept         $accept_factory->newInstance();
        if (
$accept->negotiateLanguage($accepts)) {
            
$langcode $accept->negotiateLanguage($accepts)->getValue();

            switch (
strtolower($langcode)) {
                case 
'ko':
                    return 
'KRW';
                case 
'id':
                    return 
'IDR';
                case 
'km':
                    return 
'USD';
                case 
'zh-hk':
                    return 
'HKD';
                case 
'zh-tw':
                case 
'zh':
                    return 
'CNY';
                case 
'en':
                default:
                    return 
$default;
            }
        }
        return 
$default;

    }
}