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

let BillsTemplateData = require('../../templates/models/bills_template');
let billsData = require('../../main/models/bills');
let projCounter = require('../../main/models/proj_counter');
let async = require('async');

module.exports = {
    copyTemplateData: function (tempType, newProjID, callback) {
        async.parallel([
            function (cb) {
                BillsTemplateData.getTemplate(tempType).then(function (templates) {
                    let datas = [];
                    templates.forEach(function (template) {
                        template._doc.projectID = newProjID;
                        datas.push(template._doc);
                    })
                    return billsData.insertData(datas, cb);
                });
            },
            function (cb) {
                projCounter.insertData({"projectID": newProjID}, cb);
            }
        ], (err) => callback(err));
    }
};