/**
 * Created by Mai on 2017/4/17.
 */

var express = require('express');

var billsTemplateController = require('./../controllers/bills_template_controller');


module.exports = function (app) {
    app.get('/template/bills', function (req, res) {
        let checkAdmin = function (userAccount) {
            return true;
        }
        if (checkAdmin(req.session.userAccount)) {
            res.render('maintain/templates/html/bills.html',
                {userAccount: req.session.userAccount,
                    userID: req.session.userID});
        } else {
            res.redirect('/pm');
        }
    });

    app.use('/template/bills/api', function (req, res, next) {
        let checkAdmin = function (userAccount) {
            return true;
        }
        if (checkAdmin(req.session.sessionUser)) {
            next();
        } else {
            res.json({error: 1, message: '对不起，您无权限操作清单模板。', data: null});
        }
    });

    var billsTemplateRouter = express.Router();

    billsTemplateRouter.post('/getBillsTemplate', billsTemplateController.getBillsTemplate);
    billsTemplateRouter.post('/updateBillsTemplate', billsTemplateController.updateBillsTemplate);
    billsTemplateRouter.post('/getNewBillsTemplateID', billsTemplateController.getNewBillsTemplateID);
    app.use('/template/bills/api', billsTemplateRouter);
}








