mc.exec(function() {

    var qtyPriceMeta = new mc.data.MetaData({
        client : discountData,
        dataFormat: discountFormat
    })

    var radio = new mc.grid.GridRadio({
        field: 'dc_rate_field',
        text: '할인율(%)',
        width: 140,
        eachWidth: [45, 45, 45],
        name: 'check_name',
        child: [
            {field: 'rate_zero', text: '0'},
            {field: 'rate_five', text: '5'},
            {field: 'rate_ten', text: '10'}
        ]
    })

    var metaField = new mc.data.MetaField({
        width: 90,
        fields:[
            {field: 'dccode', hidden: true},
            {field: 'dc_rate', hidden: true},
            {field: 'code', text: "상품코드", width: 60},
            {field: 'item', text: "상품명", width: 100},
            {field: 'qty', text: "수 량", width: 65, showRight: true, comma: true},
            {field: 'price', text: "단 가", width: 65, showRight: true, comma: true},
            {field: 'amount', text: "산출금액", showRight: true, comma:true},
            radio,
            {field: 'discount', text: "할인금액", minusColor: 'red', showRight: true, comma:true},
            {field: 'sales_amount', text: "합계금액", showRight: true, comma:true},
            {field: 'vat_amount', text: "부가세", showRight: true, comma:true},
            {field: 'total_amount', text: "부가세포함", showRight: true, comma:true, defaultColor: 'blue'}
        ]
    })

    new mc.grid.GridView({
        showTo: 'showArea',
        metaData: qtyPriceMeta,
        metaField: metaField,
        title: {text: '판매 현황'},
        width:910,
        height:310,

        calculator: [
            ['qty', '*', 'price', 'amount'],
            ['dccode', '==', 'Z','rate_zero', true, 'radio'],
            ['dccode', '==', 'F','rate_five', true, 'radio'],
            ['dccode', '==', 'T','rate_ten', true, 'radio'],

            ['rate_zero', 'checked', 'dc_rate', 0],
            ['rate_five', 'checked', 'dc_rate', -5],
            ['rate_ten', 'checked', 'dc_rate', -10],

            ['amount', '*', 'dc_rate', 'discount'],
            ['discount', '/', 100, 'discount'],
            ['amount', '+', 'discount', 'sales_amount'],
            ['sales_amount', '*', 0.1, 'vat_amount', 'floor', 0],
            ['sales_amount', '+', 'vat_amount', 'total_amount']
        ],

        total: {
            position: 'top',
            textField: 'code',
            text: '합 계',
            fields: [
                {id:'code'},
                {id:'qty', comma: true, showRight: true},
                {id:'amount', comma: true, showRight: true},
                {id:'rate_zero', comma: true, defaultColor: 'red'},
                {id:'rate_five', comma: true, defaultColor: 'red'},
                {id:'rate_ten', comma: true, defaultColor: 'red'},
                {id:'discount', comma: true, showRight: true},
                {id:'sales_amount', comma: true, showRight: true},
                {id:'vat_amount', comma: true, showRight: true},
                {id:'total_amount', defaultColor: 'blue', comma: true, showRight: true}
            ]
        }
    })
});
