/**
 * Created by Mai on 2017/4/17.
 */
var BillsTemplateData = require('../models/bills_template');

var callback = function(req, res, err, message, data){
    res.json({error: err, message: message, data: data});
};

module.exports = {
    getBillsTemplate: function(req, res){
        var data = JSON.parse(req.body.data);
        BillsTemplateData.getTemplate(data.tempType, function(err, message, templates){
            if (templates) {
                callback(req, res, err, message, templates);
            } else {
                callback(req, res, err, message, null);
            }
        });
    },
    updateBillsTemplate: function (req, res) {
        var data = JSON.parse(req.body.data);
        BillsTemplateData.updateTemplate(data.user_id, data.tempType, data.updateData, function (err, message, data) {
            if (err === 0) {
                callback(req, res, err, message, data);
            } else {
                callback(req, res, err, message, null);
            }
        });
    },
    getNewBillsTemplateID: function (req, res) {
        var data = JSON.parse(req.body.data);
        BillsTemplateData.getNewBillsTemplateID(data.count, function (err, message, data) {
            callback(req, res, err, message, data);
        });
    }
}