(function() {
    BemsWebApplication.FmsMaterialStockHistoryMonthlyViewModel = function (data) {

        this.HistoryId = ko.observable();
        this.SiteId = ko.observable();
        this.BusinessFieldId = ko.observable();
        this.MaterialId = ko.observable();
        this.MaterialCode = ko.observable();
        this.MaterialName = ko.observable();
        this.Unit = ko.observable();
        this.YearMonth = ko.observable();
        this.YearMonthDate = ko.observable();
        this.StoredCount = ko.observable();
        this.ReleaseCount = ko.observable();
        this.ReleaseLossCount = ko.observable();
        this.ReleaseReturnCount = ko.observable();
        this.FirstClassId = ko.observable();
        this.SecondClassId = ko.observable();
        this.ThirdClassId = ko.observable();
        this.WarehouseId = ko.observable();
        this.StockCount =  ko.observable();
        this.StockAmount = ko.observable();

            if(data)
                this.fromJS(data);
    };

    $.extend(BemsWebApplication.FmsMaterialStockHistoryMonthlyViewModel.prototype, {
        toJS: function() {
            return {
                HistoryId: this.HistoryId(),
                SiteId: this.SiteId(),
                BusinessFieldId: this.BusinessFieldId(),
                MaterialId: this.MaterialId(),
                MaterialCode: this.MaterialCode(),
                MaterialName: this.MaterialName(),
                Unit: this.Unit(),
                YearMonth: this.YearMonth(),
                YearMonthDate: this.YearMonthDate(),
                StoredCount: this.StoredCount(),
                ReleaseCount: this.ReleaseCount(),
                ReleaseLossCount: this.ReleaseLossCount(),
                ReleaseReturnCount: this.ReleaseReturnCount(),
                FirstClassId: this.FirstClassId(),
                SecondClassId: this.SecondClassId(),
                ThirdClassId: this.ThirdClassId(),
                WarehouseId: WarehouseId(),
                StockCount: this.StockCount(),
                StockAmount: this.StockAmount(),
            };
        },

        fromJS: function(data) {
            if (data) {
                this.HistoryId(data.HistoryId);
                this.SiteId(data.SiteId);
                this.BusinessFieldId(data.BusinessFieldId);
                this.MaterialId(data.MaterialId);
                this.MaterialCode(data.MaterialCode);
                this.MaterialName(data.MaterialName);
                this.Unit(data.Unit);
                this.YearMonth(data.YearMonth);
                this.YearMonthDate(data.YearMonthDate);
                this.StoredCount(data.StoredCount);
                this.ReleaseCount(data.ReleaseCount);
                this.ReleaseLossCount(data.ReleaseLossCount);
                this.ReleaseReturnCount(data.ReleaseReturnCount);
                this.FirstClassId(data.FirstClassId);
                this.SecondClassId(data.SecondClassId);
                this.ThirdClassId(data.ThirdClassId);
                this.WarehouseId(data.WarehouseId);
                this.StockCount(data.StockCount);
                this.StockAmount(data.StockAmount);
            }
        }
    });
})();