|
@@ -0,0 +1,102 @@
|
|
|
|
+/**
|
|
|
|
+ * Created by jimiz on 2017/4/1.
|
|
|
|
+ */
|
|
|
|
+var mongoose = require("mongoose");
|
|
|
|
+var db = require("../db/project_db");
|
|
|
|
+var subSchema = require("./billsSubSchemas");
|
|
|
|
+var Schema = mongoose.Schema;
|
|
|
|
+var counter = require("../../../public/counter/counter.js");
|
|
|
|
+
|
|
|
|
+var billsSchema = new Schema({
|
|
|
|
+ id: Number,
|
|
|
|
+ parentId: Number,
|
|
|
|
+ nextSiblingId: Number,
|
|
|
|
+ projectId: Number,
|
|
|
|
+ serialNo: Number,
|
|
|
|
+ chapterId: Number,
|
|
|
|
+ code: String,
|
|
|
|
+ fullCode: String,
|
|
|
|
+ name: String,
|
|
|
|
+ unit: String,
|
|
|
|
+ quantity: String, // Decimal
|
|
|
|
+ programId: Number,
|
|
|
|
+ comments: String,
|
|
|
|
+ // 调价
|
|
|
|
+ xs_Labour: String, // Decimal
|
|
|
|
+ xs_Material: String, // Decimal
|
|
|
|
+ xs_Machine: String, // Decimal
|
|
|
|
+ xs_FeeRate: String, // Decimal
|
|
|
|
+ xs_LabourPrice: String, // Decimal
|
|
|
|
+ xs_MaterialPrice: String, // Decimal
|
|
|
|
+ xs_MachinePrice: String, // Decimal
|
|
|
|
+ isTender_Labour: Boolean,
|
|
|
|
+ isTender_Material: Boolean,
|
|
|
|
+ isTender_Machine: Boolean,
|
|
|
|
+ tenderTargetPrice: String, // Decimal
|
|
|
|
+ tenderTargetUnitPrice: String, // Decimal
|
|
|
|
+ // 费用字段
|
|
|
|
+ fees: [subSchema.feesSchema],
|
|
|
|
+ // 标记字段
|
|
|
|
+ flags: [subSchema.flagsSchema]
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+var bills = db.model("bills", billsSchema);
|
|
|
|
+
|
|
|
|
+var billsDAO = function(){};
|
|
|
|
+
|
|
|
|
+billsDAO.prototype.getBills = function(projectId, callback){
|
|
|
|
+ Projects.find({projectId: projectId}, function(err, datas){
|
|
|
|
+ if (!err) {
|
|
|
|
+ callback(0, '', datas);
|
|
|
|
+ } else {
|
|
|
|
+ callback(1, '', null);
|
|
|
|
+ };
|
|
|
|
+ });
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+billsDAO.prototype.updateBills = function(datas, callback){
|
|
|
|
+ var data, errList = [], updateLength = 0;
|
|
|
|
+ var updateFunc = function (err, errData) {
|
|
|
|
+ if (err){
|
|
|
|
+ errList.push(errData);
|
|
|
|
+ };
|
|
|
|
+ };
|
|
|
|
+ if (datas){
|
|
|
|
+ for (var i = 0; i < datas.length; i++){
|
|
|
|
+ data = datas[i];
|
|
|
|
+ if (data.updateType === 'update') {
|
|
|
|
+ delete data.updateType;
|
|
|
|
+ data.save(updateFunc);
|
|
|
|
+ } else if (data.updateType === 'create') {
|
|
|
|
+ delete data.updateType;
|
|
|
|
+ data.save(updateFunc);
|
|
|
|
+ } else if (data.updateType === 'delete') {
|
|
|
|
+ delete data.updateType;
|
|
|
|
+ data.remove(updateFunc);
|
|
|
|
+ };
|
|
|
|
+ };
|
|
|
|
+ if (errList.length > 0){
|
|
|
|
+ callback(1, 'update error.', errList);
|
|
|
|
+ } else {
|
|
|
|
+ callback(0, '', null);
|
|
|
|
+ };
|
|
|
|
+ };
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+billsDAO.prototype.getBillsItemTemplate = function(callback){
|
|
|
|
+ var data = new bills;
|
|
|
|
+ /* to do: 需要根据标准配置库填充fees和flags字段,是否需要更多的参数? */
|
|
|
|
+ callback(0, '', data);
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+const
|
|
|
|
+ IDStep = 50, IDModule = 'bills';
|
|
|
|
+
|
|
|
|
+billsDAO.prototype.allocIDs = function(callback){
|
|
|
|
+ var lowID, highID;
|
|
|
|
+ counter.getIDAfterCount(IDModule, IDStep, function(highID, err){});
|
|
|
|
+ lowID = highID - IDStep + 1;
|
|
|
|
+ callback(0, '', {lowID, highID});
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+module.exports = new billsDAO();
|