bills.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /**
  2. * Created by jimiz on 2017/4/1.
  3. */
  4. var mongoose = require("mongoose");
  5. var db = require("../db/project_db");
  6. var subSchema = require("./billsSubSchemas");
  7. var Schema = mongoose.Schema;
  8. var counter = require("../../../public/counter/counter.js");
  9. var billsSchema = new Schema({
  10. ID: Number,
  11. ParentID: Number,
  12. NextSiblingID: Number,
  13. projectID: Number,
  14. serialNo: Number,
  15. chapterID: Number,
  16. code: String,
  17. fullCode: String,
  18. name: String,
  19. unit: String,
  20. quantity: String, // Decimal
  21. programID: Number,
  22. comments: String,
  23. // 调价
  24. xs_Labour: String, // Decimal
  25. xs_Material: String, // Decimal
  26. xs_Machine: String, // Decimal
  27. xs_FeeRate: String, // Decimal
  28. xs_LabourPrice: String, // Decimal
  29. xs_MaterialPrice: String, // Decimal
  30. xs_MachinePrice: String, // Decimal
  31. isTender_Labour: Boolean,
  32. isTender_Material: Boolean,
  33. isTender_Machine: Boolean,
  34. tenderTargetPrice: String, // Decimal
  35. tenderTargetUnitPrice: String, // Decimal
  36. // 费用字段
  37. fees: [subSchema.feesSchema],
  38. // 标记字段
  39. flags: [subSchema.flagsSchema]
  40. });
  41. var bills = db.model("bills", billsSchema);
  42. var billsDAO = function(){};
  43. billsDAO.prototype.getData = function(projectID, callback){
  44. bills.find({projectID: projectID}, function(err, datas){
  45. if (!err) {
  46. callback(0, '', datas);
  47. } else {
  48. callback(1, '', null);
  49. };
  50. });
  51. };
  52. // get All Project Bills, include deleted
  53. billsDAO.prototype.getProjectBills = function (projectId, callback) {
  54. if (callback) {
  55. bills.find({projectID: projectId}, '-_id').exec()
  56. .then(function (result, err) {
  57. if (err) {
  58. callback(1, '找不到模板', null);
  59. } else {
  60. callback(0, '', template);
  61. }
  62. });
  63. return null;
  64. } else {
  65. return bills.find({projectID: projectId}, '-_id').exec();
  66. }
  67. }
  68. billsDAO.prototype.AddBillsFromTemplate = function (datas, callback) {
  69. bills.collection.insert(datas, callback);
  70. };
  71. billsDAO.prototype.save = function(datas, callback){
  72. var data, errList = [], updateLength = 0;
  73. var updateFunc = function (err, errData) {
  74. if (err){
  75. errList.push(errData);
  76. };
  77. };
  78. if (datas){
  79. for (var i = 0; i < datas.length; i++){
  80. data = datas[i];
  81. if (data.updateType === 'update') {
  82. delete data.updateType;
  83. data.save(updateFunc);
  84. } else if (data.updateType === 'create') {
  85. delete data.updateType;
  86. data.save(updateFunc);
  87. } else if (data.updateType === 'delete') {
  88. delete data.updateType;
  89. data.remove(updateFunc);
  90. };
  91. };
  92. if (errList.length > 0){
  93. callback(1, errList);
  94. } else {
  95. callback(0, null);
  96. };
  97. };
  98. };
  99. billsDAO.prototype.getItemTemplate = function(callback){
  100. var data = new bills;
  101. /* to do: 需要根据标准配置库填充fees和flags字段,是否需要更多的参数? */
  102. callback(0, '', data);
  103. };
  104. billsDAO.prototype.allocIDs = function(IDStep, callback){
  105. counter.counterDAO.getIDAfterCount(counter.moduleName.bills, IDStep, function(err, highID){
  106. var lowID = highID - IDStep + 1;
  107. callback(0, '', {lowID: lowID, highID: highID});
  108. });
  109. };
  110. module.exports = new billsDAO();