
var productNum;
var receiptNum;

var app = {
    // Application Constructor
    initialize: function() {
        document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
    },

    // deviceready Event Handler
    //
    // Bind any cordova events here. Common events are:
    // 'pause', 'resume', etc.
    onDeviceReady: function() {
        this.itemInit();
        this.eventInit();
        this.otherInit();
    },
    itemInit:function(){
        cordova.plugins.finPlugin.getReceitCancelAliInfo("", function(res){
            app.setReceitCancelAliInfo(res);
        }, function(error){
            alert(error);
        });
    },
    eventInit:function(){
       
    },
    otherInit:function(){

    },
    setReceitCancelAliInfo:function(res)
    {
        var receiptData = JSON.parse(res);
        if(null == receiptData) return;

        if(isIphone())
        {
          productNum = receiptData['productNumber'];
          receiptNum = receiptData['receiptNumber'];
          
          $("#referenceNo").html(receiptData['receiptNumber'] );
          $("#bizName").html(receiptData['storeName']);
          $(".bizOwner").html(receiptData['represent']);
          $("#bizNumber").html(receiptData['businessNumber']);
          $("#bizCallNumber").html(receiptData['storePhone']);
          $("#bizAddress").html(receiptData['storeAddress']);
          $("#acquirersName").html(receiptData['acquirersName']);
          $("#alipayBuyerLoginId").html(receiptData['alipayBuyerLoginId']);
          $("#totalAmount"). html("- " +  receiptData['totalAmount']);
          $("#transAmountCny"). html("- " + receiptData['transAmountCny']);
          $("#exchangeRate").html("1000KRW =" + receiptData['exchangeRate'] +"  RMB");
          $(".time").html(receiptData['dateAndTime']);
          $("#readerNumber").html(receiptData['readerNumber']);
          $("#alipayTransId").html(receiptData['alipayTransId']);
          $(".approvalNumber").html(receiptData['approvalNumber']);
          $("#supply").html("- " + receiptData['supplyAmount']);
          $("#tax").html("- " + receiptData['taxAmount']);
          $("#total").html("- " + receiptData['totalAmount']);
          $("#barcodeImg").JsBarcode(receiptData['approvalNumber'], {displayValue: false, height: 80});
        }else{}
    },sendMMS:function(){
       
        if(isIphone())
        {
            var data = {"TYPE":"CANCEL_ALI"};
            cordova.plugins.finPlugin.sendMMS(data,null, null);
        }else
        {
            cordova.plugins.finPlugin.sendMMS("",null, null);
        } 
    },closeStack:function(){
        cordova.plugins.finPlugin.backButton("", null, null);
    },
    backbuttonAction:function()
    {
        if(isIphone())
        {
            if(!isPopupClose){
                cordova.plugins.finPlugin.backButton("", null, null);
            }
        }else
        {
            
        }
    },backReceipAction:function(){
        cordova.plugins.finPlugin.moveStack(RECEIPT.DATA, null,null);
    }

};

app.initialize();

