/**
 * Created by chen on 2017/6/29.
 */
let subSchema = require("../../main/models/bills_sub_schemas");
let deleteSchema = require('../../../public/models/delete_schema');

var mongoose = require('mongoose'),
    Schema = mongoose.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 });


/*var gljSchema =new Schema({
 repositoryId: Number,
 ID:Number,
 //以下是基于已有access库
 code: String,
 name: String,
 specs: String,
 unit: String,
 basePrice: Number,
 gljType: Number, //这个是UI显示上的详细分类，对应gljTypeSchema
 shortName: String,  //人工，材料，机械
 gljClass:Number
 },{versionKey:false});

 mongoose.model("std_ration_lib_glj_list",gljSchema,"std_ration_lib_glj_list");*/


let rationSchema = new Schema({
    ID: Number,
    projectID: Number,
    billsItemID: Number,
    serialNo: Number,
    libID: Number,
    code: String,
    name: String,
    maskName: String,
    caption: String,
    unit: String,
    quantity: String, // Decimal
    isFromDetail:{type: Number,default:0},//1 true 2 false
    programID: Number,
    adjustState: String,
    content: String,
    rationProjName: String,
    comments: String,
    // 费用字段
    fees: [subSchema.feesSchema],
    // 标记字段
    flags: [subSchema.flagsSchema],
    deleteInfo: deleteSchema,
    rationAssList: [rationAssItemSchema]
});

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

var coeSchema = mongoose.Schema({
    coeType: String,                // 系数类型，指作用范围:
                                    // 单个(如：111量0.001)、人工类、材料类、机械类、全部（如：定额×0.925）。
    gljID: Number,                  // 要调整的工料机ID（当coeType=0时有效）
    operator: String,               // 运算符（*、+、-、=）
    amount: String,                 // 调整的量
    _id: false
});

var coeListSchema = mongoose.Schema({
    libID: Number,                      // 所属定额定ID
    ID: Number,                         // 系数ID(流水号ID)
    name: String,                       // 名称
    content: String,                    // 说明
    coes: [coeSchema]
}, {versionKey: false});

 mongoose.model("std_ration_lib_coe_list",coeListSchema, "std_ration_lib_coe_list");

var rationGljItemSchema = mongoose.Schema({
    gljId: Number,
    consumeAmt: Number,
    proportion: Number //配合比，暂时无需使用，默认0
}, { _id: false });

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

var rationItemSchema = mongoose.Schema({
    ID:Number,
    code: String,
    name: String,
    unit: String,
    basePrice: Number,
    sectionId: Number,
    rationRepId: Number,
    caption: String,
    feeType: Number,
    rationGljList: [rationGljItemSchema],
    rationCoeList: Array,
    rationAssList: [rationAssItemSchema]
});
mongoose.model("std_ration_lib_ration_items",rationItemSchema, "std_ration_lib_ration_items");

let 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
    isFromDetail:{type: Number,default:0},//1 true 2 false
    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
    tenderTargetUnitPrice: String, // Decimal
    // 费用字段
    fees: [subSchema.feesSchema],
    // 标记字段
    flags: [subSchema.flagsSchema],
    deleteInfo: deleteSchema
});

mongoose.model("bills", billsSchema);