/**
 * Created by zhang on 2018/3/22.
 */
let mongoose = require("mongoose");
let subSchema = require("../all_schemas/bills_sub_schemas");
let Schema = mongoose.Schema;
let deleteSchema = require('../all_schemas/delete_schema');

var rationAssItemSchema = mongoose.Schema({
    name: String,
    assistID: Number,
    assistCode: String,
    stdValue: Number,
    actualValue:Number,
    stepValue: String,
    decimal: Number,
    carryBit: String,
    minValue: String,
    maxValue: String
}, { _id: false });

// 定额、量价、工料机定额 合并存储
let rationSchema = new Schema({
    // 公用属性部分
    ID: String,
    projectID: Number,
    billsItemID: String,
    serialNo: Number,
    code: String,
    name: String,
    unit: String,
    quantity: String,
    contain:String,//含量
    quantityEXP:String,//工程量表达式
    programID: Number,
    marketUnitFee: String,
    marketTotalFee: String,
    fees: [subSchema.feesSchema],
    deleteInfo: deleteSchema,
    type: Number,                               // 1 定额、2 量价、3 工料机定额
    subType: Number,                            // 子类型：1人工、201材料、301机械、4主材、5设备
    from:{type: String,default:'std'},          //std, cpt  来自标准、补充
    isSubcontract: Boolean,                     // 是否分包
    installationKey:String,                   //用来记录安装增加费的关联字段

    // 定额特有属性：
    libID: Number,
    maskName: String,
    caption: String,
    isFromDetail:{type: Number,default:0},       // 1 true 2 false
    adjustState: String,
    rationProjName: String,
    comments: String,                           // 说明
    flags: [subSchema.flagsSchema],             // 标记字段
    rationAssList: [rationAssItemSchema],
    content: String,                            // 工作内容
    ruleText: String,                            // 计算规则
    prefix: {type: String, default: ''},                              //定额是补充、借用时用  补 借

    //工料机特有属性
    projectGLJID:Number,  //项目工料机ID
    GLJID:Number,//工料机库ID
    original_code:String, //原始编码
    specs:String,//规格型号
    shortName:String,//缩写
    customQuantity:String,//自定义消耗
    adjCoe:Number,
    remark:String
});

let ration = mongoose.model("ration", rationSchema, "ration");