<?xml version="1.0" encoding="utf-8" ?>
<select>
	<selectstr>
		SELECT
		mattressid,
		mattressname,
		deptid,
		mattresstypeid,
		mattresscode,
		mattress_width,
		mattress_length,
		mattress_height,
		packtype,
		packqty,
		woodpallettype,
		total_hr_cost,
		total_material_cost ,
		fees_dscrp,
		total_fees_cost,
		total_cost,
		taxrate,
		taxes,
		commissionrate,
		commission,
		fob,
		profitrate,
		nottax_factory_cost,
		nottax_dept_cost,
		dept_cost,
		foreign_cost,
		extras_cost,
		dept_profitrate,
		moneyrate,
		mattressrelcode,

		flag,
		auditingrep,
		auditingdate,

		createtime,
		createby,

		yw_flag,
		yw_auditingrep,
		yw_auditingdate,
		js1_flag,
		js1_auditingrep,
		js1_auditingdate,
		js2_flag,
		js2_auditingrep,
		js2_auditingdate,
		creatmtrl_flag,
		creatmtrl_auditingrep,
		creatmtrl_auditingdate,
		creatmtrlqd_flag,
		creatmtrlqd_auditingrep,
		creatmtrlqd_auditingdate,

		erp_mtrlcode as erp_mtrlcode,

		erp_mtrlid,
		nottax_factory_cost  / ( dept_profitrate + dept_profitrate_rangli / 100  ) as dijia_cost,
		erp_mtrlengname,
		erp_configcodetype

		From u_mattress
	</selectstr>
	<where>
		<when>
			u_mattress.xd_flag = 1
		</when>
		<when notnull="@arg_deptid">
			u_mattress.deptid = @arg_deptid
		</when>
		<when notempty="@@arg_deptid_arry@@">
			u_mattress.deptid in (@@arg_deptid_arry@@)
		</when>
		<when notempty="@@arg_arry_outrepstr@@">
			u_mattress.createby in (@@arg_arry_outrepstr@@) or  @arg_empid = 0
		</when>
		<when notnull="@arg_yw_flag">
			u_mattress.yw_flag = @arg_yw_flag
		</when>
		<when notnull="@arg_js1_flag">
			u_mattress.js1_flag = @arg_js1_flag
		</when>
		<when notnull="@arg_js2_flag">
			u_mattress.js2_flag = @arg_js2_flag
		</when>
		<when notnull="@arg_creatmtrl_flag">
			u_mattress.creatmtrl_flag = @arg_creatmtrl_flag
		</when>
		<when notnull="@arg_creatmtrlqd_flag">
			u_mattress.creatmtrlqd_flag = @arg_creatmtrlqd_flag
		</when>
		<when notnull="@arg_search">
			u_mattress.mattresscode like '%'+ @arg_search + '%' OR u_mattress.mattressrelcode like '%'+ @arg_search + '%'
			OR u_mattress.mattressname like '%'+ @arg_search + '%' OR u_mattress.erp_mtrlengname like '%'+ @arg_search + '%'
			OR u_mattress.erp_mtrlcode like '%'+ @arg_search + '%'
		</when>
		<when notnull="@arg_mattressid">
			u_mattress.mattressid = @arg_mattressid
		</when>
	</where>
	<displayfields>
		<field field="pid" compute="getrow()">序</field>
		<field field="yw_flag" datatype="checkbox">业务审核</field>
		<field field="js1_flag" datatype="checkbox">产品补充审核</field>
		<field field="js2_flag" datatype="checkbox">清单补充审核</field>
		<field field="creatmtrl_flag" datatype="checkbox">生成L1产品</field>
		<field field="creatmtrlqd_flag" datatype="checkbox">生成L1清单</field>
		<field field="erp_mtrlcode">L1物料编码</field>
		<field field="mattresscode">报价唯一码</field>
		<field field="mattressrelcode">床垫编码</field>
		<field field="mattressname">床垫名称</field>
		<field field="mattresstypeid" mapper="" ddd="ddd_mattress_type_choose">床垫类别</field>
		<field field="mattress_width" datatype="number">床垫宽/CM</field>
		<field field="mattress_length" datatype="number">床垫长/CM</field>
		<field field="mattress_height" datatype="number">床垫高/CM</field>
		<field field="createby">登记人</field>
		<field field="createtime" datatype="datetime">登记时间</field>
		<field field="deptid" mapper="" ddd="ddd_mattress_dept_choose" align="left">部门</field>
		<field field="yw_auditingrep">业务审核人</field>
		<field field="yw_auditingdate" datatype="datetime">业务审核时间</field>
		<field field="js1_auditingrep">产品补充审核人</field>
		<field field="js1_auditingdate" datatype="datetime">产品补充审核时间</field>
		<field field="js2_auditingrep">清单补充审核人</field>
		<field field="js2_auditingdate" datatype="datetime">清单补充审核时间</field>
		<field field="creatmtrl_auditingrep">生成L1产品人</field>
		<field field="creatmtrl_auditingdate" datatype="datetime">生成L1产品时间</field>
		<field field="creatmtrlqd_auditingrep">生成L1清单人</field>
		<field field="creatmtrlqd_auditingdate" datatype="datetime">生成L1清单时间</field>
		<field field="mattressid">Mattressid</field>
		<field field="dijia_cost" datatype="number">底价</field>
		<field field="yongjin" datatype="number" compute="dijia_cost / (1 - (commission - 1 )) - dijia_cost">佣金</field>
		<field field="taxrate" datatype="number">税率</field>
		<field field="fob" datatype="number">Fob</field>
		<field field="taxes" datatype="number">税金</field>
		<field field="erp_mtrlengname">原来物料mtrlcode</field>
		<field field="erp_configcodetype">Erp Configcodetype</field>
	</displayfields>
</select>
