/**
 * 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,
    paramName:String,//参数名称
    param:String,//参数
    thirdRationCode:String,//第三定额
    isAdjust:Number,//0不调整，1调整
    groupList:[Schema.Types.Mixed]//当有分组的时候用这个
}, { _id: false });

// 定额、量价、工料机定额 合并存储
let rationSchema = new Schema({
    // 公用属性部分
    ID: {type: String, index: true},
    projectID: {type: Number, index: true},
    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],
    //消耗量调整系数字段
    quantityCoe:subSchema.quantityCoeSchema,
    //子目工程量调整系数
    rationQuantityCoe:String,
    tenderQuantity:String,//调整后工程量
    // 不调价
    is_adjust_price: {type: Number,default: 0},
    targetUnitFee:String,//目标单价
    targetTotalFee:String,//目标合价
    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,                   //用来记录安装增加费的关联字段
    // 定额特有属性：
    stdID: Number,                            //来自的标准定额ID
    libID: Number,
    maskName: String,
    caption: String,
    evaluationProject:{type: Number,default:0},       // 1 true 0 false 估价项目
    isFromDetail:{type: Number,default:0},       // 1 true 0 false
    adjustState: String,
    rationProjName: String,
    comments: String,                           // 说明
    flags: [subSchema.flagsSchema],             // 标记字段
    rationAssList: [rationAssItemSchema],
    content: String,                            // 工作内容
    annotation: String,                         //附注
    ruleText: String,                            // 计算规则
    prefix: {type: String, default: ''},                              //定额是补充、借用时用  补 借
    referenceRationID:String,//如果是通过模板关联子目生成的定额，这里记录对应的主定额ID

    //工料机特有属性
    projectGLJID:Number,  //项目工料机ID
    GLJID:Number,//工料机库对应的ID
    original_code:String, //原始编码
    specs:String,//规格型号
    shortName:String,//缩写
    customQuantity:String,//自定义消耗
    model: Number,// 机型
    adjCoe:Number,
    remark:String,
    bookmarkBackground:String,//书签背景色
    bookmarkAnnotation:String//批注
});

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