/***************************************************************************************************
业务数据库创建脚本
***************************************************************************************************/

--00 系统
	if not exists (select * from sysobjects where id = OBJECT_ID(N't_pluorder_param_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pluorder_param_head
	
create table t_pluorder_param_head (
	billno varchar(20) not null,
	ordertype varchar(1) not null default('0'),
	orgcode varchar(10) not null default('*'),
	orderdate varchar(31) not null default('0000000000000000000000000000000'),
	dhdays int not null default(0),
	safedays varchar(1) not null default(0),
	ordercycle varchar(1) not null default(0),
	predays varchar(1) not null default(0),
	qdamount numeric(19,4) not null default(0),
	constraint [REDACTED]primary key nonclustered
	(
		billno
	)
)
go


if not exists (select * from sysobjects where id = OBJECT_ID(N't_pluorder_param_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pluorder_param_body
	
create table t_pluorder_param_body (
	billno varchar(20) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	constraint [REDACTED]primary key nonclustered
	(
		plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_sys_func') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_sys_func

create table t_sys_func (
	funcode varchar(10) not null,
	funname varchar(30) not null,
	funtype varchar(1) not null default('1'),
	dllname varchar(40) null,
	dllfun varchar(40) null,
	dlltype varchar(1) not null default('0'),
	formtype varchar(1) not null default('1'),
	ver varchar(1) not null default('0'),
	ismenu varchar(1) not null default('1'),
	ischart varchar(1) not null default('1'),
	serialno varchar(4) null,
	orderno numeric(19,4) not null default(1),
	viewposition varchar(1) null,
	parentfuncode varchar(10) null,
	isfun varchar(1) not null default('1'),
	remark varchar(200) null,
	constraint pk_sys_func primary key nonclustered
	(
		funcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_sys_func_item') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_sys_func_item

create table t_sys_func_item (
	funcode varchar(10) not null,
	optcode varchar(10) not null,
	optname varchar(40) null,
	constraint pk_sys_func_item primary key nonclustered 
	(
		funcode,optcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_fun_used_freq') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_fun_used_freq

create table t_fun_used_freq (
	funcode varchar(10) not null,
	usercode varchar(6) not null,
	times int not null default(1),
	constraint pk_fun_used_freq primary key nonclustered
	(
		funcode,usercode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_sys_link_func') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_sys_link_func

create table t_sys_link_func (
	funcode varchar(10) not null,
	linkfuncode varchar(10) not null,
	serialno int not null default(1),
	constraint pk_sys_link_func primary key nonclustered
	(
		funcode,linkfuncode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_sys_qry') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_sys_qry

create table t_sys_qry (
	qrytype varchar(8) not null,
	serialno int not null,
	fldcode varchar(100) not null,
	fldname varchar(40) not null,
	fldtype varchar(1) not null,
	vlutype varchar(1) not null default('0'),
	vluobject varchar(40) null,
	vlufield varchar(40) null,
	vlucaption varchar(40) null,
	exetimes int not null default(0),
	ver varchar(1) not null default('0'),
	constraint pk_sys_qry primary key nonclustered
	(
		qrytype,serialno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_sys_qry_value') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_sys_qry_value

create table t_sys_qry_value (
	qrytype varchar(8) not null,
	serialno int not null,
	qryvluno varchar(8) not null,
	qryvalue varchar(40) not null,
	constraint pk_sys_qry_value primary key nonclustered
	(
		qrytype,serialno,qryvluno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_sys_qry_save') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_sys_qry_save

create table t_sys_qry_save (
	qrytype varchar(8) not null,
	serialno int not null,
	orderno int not null,
	qryname varchar(40) not null,
	fldcode varchar(100) not null,
	operator varchar(8) not null,
	fieldvalue varchar(200) null,
	linkflag varchar(4) null,
	constraint pk_sys_qry_save primary key nonclustered
	(
		qrytype,serialno,orderno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_sys_qry_field') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_sys_qry_field

create table t_sys_qry_field (
	qrycode varchar(10) not null,
	dataset varchar(15) not null,
	fldname varchar(40) not null,
	fldcaption varchar(40) null,
	fldtype varchar(1) not null,
	fldsize int not null default(0),
	fldexpress varchar(100) null,
	fldformat varchar(15) null,
	issum varchar(1) not null default('0'),
	remark varchar(40) null,
	constraint pk_sys_qry_field primary key nonclustered
	(
		qrycode,dataset,fldname
	)
)

if exists (select * from sysobjects where id = OBJECT_ID(N't_prn_default') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_prn_default

create table t_prn_default (
	prntype varchar(1) not null default('9'),
	prncode varchar(10) not null,
	serialno int not null default(0),
	usercode varchar(6) not null,
	workstation varchar(100) null
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_prn_format') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_prn_format

create table t_prn_format (
	prntype varchar(1) not null default('9'),
	prncode varchar(10) not null,
	serialno int not null default(0),
	ver varchar(1) not null default('0'),
	isdefault varchar(1) not null default('0'),
	isnewformat varchar(1) not null default('0'),
	prnname varchar(40) null,
	remark varchar(40) null,
	prnformat image null,
	constraint pk_prn_format primary key nonclustered
	(
		prntype,prncode,serialno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_sys_right_prn') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_sys_right_prn

create table t_sys_right_prn (
	prntype varchar(1) not null,
	prncode varchar(10) not null,
	serialno int not null,
	ugrpcode varchar(2) not null,
	constraint pk_sys_right_prn primary key nonclustered
	(
		prntype,prncode,serialno,ugrpcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_myclm_default') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_myclm_default

create table t_myclm_default (
	fmtname varchar(40) not null,
	fmttype varchar(4) not null,
	modifytime varchar(20) null,
	fmtfile image not null,
	viewstyle varchar(1) not null default('0'),
	constraint pk_myclm_default primary key nonclustered
	(
		fmtname,fmttype
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_sys_ver') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_sys_ver

create table t_sys_ver (
	sysname varchar(20) not null,
	veritem varchar(20) not null,
	version varchar(200) null,
	upddatetime varchar(20) null,
	constraint pk_sys_ver primary key nonclustered
	(
		sysname,veritem
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_sys_dbupd_his') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_sys_dbupd_his

create table t_sys_dbupd_his (
	upddatetime varchar(20) null,
	oldversion varchar(200) null,
	newversion varchar(200) null,
	remark varchar(200) null
) 
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_sys_upgrade_hist') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_sys_upgrade_hist

create table t_sys_upgrade_hist (
	orgcode varchar(10) not null,
	beforever varchar(20) not null,
	afterver varchar(20) not null,
	stationid varchar(15) not null,
	upgradedate varchar(10) not null,
	upgradetime varchar(8) not null,
	upgradetype varchar(1) not null
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_sys_client') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
  drop table t_sys_client
go
create table t_sys_client (
	clientid varchar (40)  not null ,
	clienttype varchar (1) not null default '0',
	clientver varchar(20)  null,
	filever varchar (20)  null,
	upddatetime varchar(20) null,
	isactive varchar(1) not null default '1',
	logindatetime varchar (20)  null,
	logoutdatetime varchar (20)  null, 
	loginuser varchar(10) null,
	constraint pk_sys_client primary key nonclustered
	(
		clientid,clienttype
	)
) 
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_cert') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_cert

create table t_cert (
	cerflag varchar(1) not null,
	certype varchar(4) not null,
	cername varchar(40) null,
	showorder int not null,
	remark varchar(200) null,
	constraint pk_cert primary key nonclustered
	(
		cerflag,certype
	)
)
go


if exists (select * from sysobjects where id = OBJECT_ID(N't_cert_detail') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_cert_detail

create table t_cert_detail (
	cerflag varchar(1) not null,
	certype varchar(4) not null,
	etpcode varchar(20) not null,
	cercode varchar(20) not null,
	validdate varchar(10) null,
	picture_id varchar(50) null,
	picture image null,
	chkstatus varchar(1) not null default('0'),
	chkmsg varchar(200) null,
	chkdate varchar(10) null,
	chktime varchar(8) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	remark varchar(200) null,
	constraint pk_cert_detail primary key nonclustered
	(
		cerflag,certype,etpcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_attach_file') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_attach_file

create table t_attach_file (
	sysid int not null,
	mdlcode varchar(10) not null,
	billno varchar(40) not null,
	filename varchar(100) not null,
	fileext varchar(10) not null,
	filecontent image null,
	fileicon image null,
	filesize numeric(19,4) not null default(0),
	updatetime varchar(20) not null,
	usercode varchar(10) not null,
	username varchar(20) not null,
	constraint pk_attach_file primary key nonclustered
	(
		sysid,mdlcode,billno
	)
)
go

if  exists (select * from sysobjects where id = object_id(N't_cust_image') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_cust_image
go

create table t_cust_image(
	no int not null,
	resname varchar(20) null,
	displayname varchar(20) null,
	imgwidth int not null,
	imgheight int not null,
	iscustom varchar(1) not null default('0'),
	imgdata image null,
	imgextension varchar(20) null,
	clientcode varchar(1) null,
	constraint pk_cust_image primary key nonclustered
	(
		no
	)
)
go


--01 档案

if exists (select * from sysobjects where id = OBJECT_ID(N't_gclass') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_gclass

create table t_gclass (
	clscode varchar(10) not null,
	clsname varchar(20) null,
	uppercode1 varchar(10) null,
	uppercode2 varchar(10) null,
	uppercode3 varchar(10) null,
	uppercode4 varchar(10) null,
	uppercode5 varchar(10) null,
	colorgrpcode varchar(2) null,
	sizegrpcode varchar(2) null,
	clslevel int null default(1),
	isshow varchar(1) not null default('1'),
	sortno varchar(4) not null default('9999'),
	chgdate varchar(20) null,
	constraint pk_gclass primary key nonclustered
	(
		clscode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_dept') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_dept

create table t_dept (
	depcode varchar(10) not null,
	depname varchar(16) null,
	manager varchar(10) null,
	descript varchar(30) null,
	uppercode1 varchar(10) null,
	uppercode2 varchar(10) null,
	uppercode3 varchar(10) null,
	uppercode4 varchar(10) null,
	deplevel int null default(0),
	isdsc varchar(1) null,
	islast varchar(1) not null default('0'),
	constraint pk_dept primary key nonclustered
	(
		depcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_brand') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_brand

create table t_brand (
	brandcode varchar(10) not null,
	brandname varchar(20) null,
	remark varchar(200) null,
	constraint pk_brand primary key nonclustered
	(
		brandcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_plu') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_plu

create table t_plu (
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	mncode varchar(40) null,
	pluabbrname varchar(40) null,
	plutype varchar(1) null,
	depcode varchar(10) null,
	clscode varchar(10) null,
	brandcode varchar(10) null,
	spec varchar(40) null,
	cargono varchar(20) null,
	unit varchar(10) null,
	prodarea varchar(30) null,
	grade varchar(8) null,
	supcode varchar(15) null,
	etpcode varchar(20) null,
	keepdays int null,
	usercode varchar(6) null,
	username varchar(10) null,
	lrdate varchar(10) null,
	initcount numeric(19,4) not null default(0),
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	vipprice numeric(19,4) not null default(0),
	packprice numeric(19,4) not null default(0),
	pfprice numeric(19,4) not null default(0),
	psprice numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	staxrate int not null default(0),
	dkrate numeric(19,4) not null default(0),
	askcnt numeric(19,4) not null default(0),
	askdate varchar(31) not null default('1111111111111111111111111111111'),
	season int null,
	plustatus varchar(1) not null default('0'),
	statusdate varchar(10) null,
	isweight varchar(1) not null default('0'),
	mngcs varchar(1) not null default('0'),
	topstock int not null default(0),
	lowstock int not null default(0),
	jhcycle int not null default(0),
	pscycle int not null default(0),
	innercode varchar(20) not null default(''),
	itemcnt numeric(19,4) not null  default (1),
	erpmaterialno varchar(20) null,
	purposecode varchar(10) null,
	beamtcode varchar(8) null,
	fitskin varchar(1) null,
	tare numeric(19,4) not null default(0),
	grossweight numeric(19,4) null,
	netweight numeric(19,4) null,
	iszfcode varchar(1) not null default('0'),
	isonline varchar(1) not null default('0'),
	istakeaway varchar(1) not null default('0'),
	chgdate varchar(20) null,
	isuseesl varchar(1) not null default('0'),
	ordercnt numeric(19,4) not null default(0), 
	isallsale varchar(1) not null default('1'),
	tag1 varchar(100) null,
	tag2 varchar(100) null,
	tag3 varchar(100) null,
	tag4 varchar(100) null,
	tag5 varchar(100) null,
	remark varchar(200) null,
	constraint pk_plu primary key nonclustered
	(
		plucode
	)
)

create index ix_plu on t_plu (barcode,pluname,mncode,plutype,depcode,cargono,chgdate,innercode)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_plu_org') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_plu_org

create table t_plu_org (
	plucode varchar(20) not null,
	orgcode varchar(10) not null,
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	vipprice numeric(19,4) not null default(0),
	pfprice numeric(19,4) not null default(0),
	psprice numeric(19,4) not null default(0),
	gcount numeric(19,4) not null default(0),
	ccount numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	tzamount numeric(19,4) not null default(0),
	isright varchar(1) not null default('1'),
	isxs varchar(1) not null default('1'),
	isth varchar(1) not null default('1'),
	iscg varchar(1) not null default('1'),
	iscgth varchar(1) not null default('1'),
	ispsth varchar(1) not null default('1'),
	isask varchar(1) not null default('1'),
	iszs varchar(1) not null default('1'),
	mngstock varchar(1) not null default('0'),
	cgmode varchar(1) not null default('0'),
	dkrate numeric(19,4) not null default(0),
	sjdate varchar(10) null,
	ojprice numeric(19,4) not null default(0),
	hjprice numeric(19,4) not null default(0),
	ljprice numeric(19,4) not null default(0),
	abc1 varchar(1) null,
	abc2 varchar(1) null,
	dms numeric(19,4) not null default(0),
	dms1 numeric(19,4) not null default(0),
	dms2 numeric(19,4) not null default(0),
	dms3 numeric(19,4) not null default(0),
	odms numeric(19,4) not null default(0),
	odms1 numeric(19,4) not null default(0),
	odms2 numeric(19,4) not null default(0),
	odms3 numeric(19,4) not null default(0),
	dscdms numeric(19,4) not null default(0),
	dscdms1 numeric(19,4) not null default(0),
	dscdms2 numeric(19,4) not null default(0),
	dscdms3 numeric(19,4) not null default(0),
	dscodms numeric(19,4) not null default(0),
	dscodms1 numeric(19,4) not null default(0),
	dscodms2 numeric(19,4) not null default(0),
	dscodms3 numeric(19,4) not null default(0),
	newjhdate varchar(10) null,
	newxsdate varchar(10) null,
	newpsdate varchar(10) null,
	topstock int not null default(0),
	lowstock int not null default(0),
	jhcycle int not null default(0),
	pscycle int not null default(0),
	yjdate varchar(10) null,
	chgdate varchar(20) not null default(''),
	supcode varchar(15) null,
	judgecnt numeric(19,4) not null default(0),
	tag1 varchar(100) null,
	tag2 varchar(100) null,
	tag3 varchar(100) null,
	tag4 varchar(100) null,
	tag5 varchar(100) null,
	constraint pk_plu_org primary key nonclustered
	(
		plucode,orgcode
	)
)

create index ix_plu_org on t_plu_org (gcount,ccount)
go

if  exists (select * from sysobjects where id = OBJECT_ID(N't_plu_image') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_plu_image

create table t_plu_image (
    pluid bigint not null default(0),
	plucode varchar(20) not null,
	imgtype varchar(1) not null default('1'),
	imgsize varchar(1) not null default('1'),
	pwidth int not null default(0),
	pheight int not null default(0),
	pluimg image null,
	picformat varchar(1) not null default('0'),
	showmode varchar(1) not null default('0'),
	uptdate varchar(20) null,
	remark varchar(200) null,
	constraint pk_plu_image primary key nonclustered
	(
		pluid,plucode,imgtype
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_plupack') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_plupack

create table t_plupack (
	packcode varchar(20) not null,
	plucode varchar(20) not null,
	pluprice numeric(19,4) not null default(0),
	counts numeric(19,4) not null default(0),
	packtotal numeric(19,4) not null default(0),
	packtype varchar(1) not null default('0'),
	constraint pk_plupack primary key nonclustered
	(
		packcode,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_barcode_ref') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_barcode_ref

create table t_barcode_ref (
	barcode varchar(20) not null,
	plucode varchar(20) not null,
	pluname varchar(40) not null,
	spec varchar(40) null,
	constraint pk_barcode_ref primary key nonclustered
	(
		barcode,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N'v_plu') and OBJECTPROPERTY(id, N'IsView') = 1)
	drop view v_plu
go
create view v_plu (
	plucode,barcode,pluname,mncode,depcode,clscode,brandcode,spec,cargono,unit,prodarea,grade,supcode,jprice,netjprice,price,vipprice,packprice,pfprice,psprice,jtaxrate,staxrate,plutype,
	lrdate,dkrate,plustatus,askcnt,isweight,season,statusdate,keepdays,usercode,username,chgdate,initcount,etpcode,remark,mainbarcode,mainpluname,mainspec,isuseesl
	) as
select plucode,barcode,pluname,mncode,depcode,clscode,brandcode,spec,cargono,unit,prodarea,grade,supcode,jprice,netjprice,price,vipprice,packprice,pfprice,psprice,jtaxrate,staxrate,plutype,
	lrdate,dkrate,plustatus,askcnt,isweight,season,statusdate,keepdays,usercode,username,chgdate,initcount,etpcode,remark,barcode,pluname,spec,isuseesl from t_plu
union
select a.plucode,b.barcode,b.pluname,mncode,depcode,clscode,brandcode,b.spec,cargono,unit,prodarea,grade,supcode,jprice,netjprice,price,vipprice,packprice,pfprice,psprice,jtaxrate,staxrate,plutype,
	lrdate,dkrate,plustatus,askcnt,isweight,season,statusdate,keepdays,usercode,username,chgdate,initcount,etpcode,remark,a.barcode,a.pluname,a.spec,a.isuseesl from t_plu a,t_barcode_ref b
where a.plucode=b.plucode
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_plu_supplier') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_plu_supplier

create table t_plu_supplier (
	plucode varchar(20) not null,
	supcode varchar(15)	not null,
	constraint pk_plu_supplier primary key nonclustered
	(
		plucode,supcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_plu_apply') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_plu_apply

create table t_plu_apply (
	pluid bigint not null,
	plucode varchar(20) null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	mncode varchar(40) null,
	pluabbrname varchar(40) null,
	plutype varchar(1) null,
	depcode varchar(10) null,
	clscode varchar(10) null,
	brandcode varchar(10) null,
	spec varchar(40) null,
	cargono varchar(20) null,
	unit varchar(10) null,
	prodarea varchar(30) null,
	grade varchar(8) null,
	supcode varchar(15) null,
	etpcode varchar(20) null,
	keepdays int null,
	usercode varchar(6) null,
	username varchar(10) null,
	lrdate varchar(10) null,
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	vipprice numeric(19,4) not null default(0),
	pfprice numeric(19,4) not null default(0),
	psprice numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	staxrate int not null default(0),
	dkrate numeric(19,4) not null default(0),
	askcnt numeric(19,4) not null default(0),
	season int null,
	isweight varchar(1) not null default('0'),
	mngcs varchar(1) not null default('0'),
	topstock int not null default(0),
	lowstock int not null default(0),
	jhcycle int not null default(0),
	pscycle int not null default(0),
	erpmaterialno varchar(20) null,
	purposecode varchar(10) null,
	beamtcode varchar(8) null,
	fitskin varchar(1) null,
	tare numeric(19,4) not null default(0),
	grossweight numeric(19,4) null,
	netweight numeric(19,4) null,
	isonline varchar(1) not null default('0'),
	istakeaway varchar(1) not null default('0'),
	tag1 varchar(100) null,
	tag2 varchar(100) null,
	tag3 varchar(100) null,
	tag4 varchar(100) null,
	tag5 varchar(100) null,
	remark varchar(200) null,
	chkstatus varchar(1) not null default('0'),
	chkmsg varchar(200) null,
	chkdate varchar(10) null,
	chktime varchar(8) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	constraint pk_plu_apply primary key nonclustered 
	(
		pluid
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_lib_plu') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_lib_plu

create table t_lib_plu (
	barcode varchar(20) not null,
	pluname varchar(40) null,
	spec varchar(40) null,
	unit varchar(10) null,
	prodarea varchar(10) null,
	constraint pk_lib_plu primary key nonclustered
	(
		barcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_plu_tmp') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_plu_tmp

create table t_plu_tmp (
	plucode varchar(20) not null,
	orgcode varchar(10) null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	mncode varchar(40) null,
	plutype varchar(1) null,
	depcode varchar(10) null,
	clscode varchar(10) null,
	brandcode varchar(10) null,
	spec varchar(40) null,
	cargono varchar(20) null,
	unit varchar(10) null,
	prodarea varchar(30) null,
	grade varchar(8) null,
	supcode varchar(15) null,
	etpcode varchar(20) null,
	keepdays int null,
	isright varchar(1) not null default('1'),
	isxs varchar(1) not null default('1'),
	isth varchar(1) not null default('1'),
	iscg varchar(1) not null default('1'),
	iscgth varchar(1) not null default('1'),
	ispsth varchar(1) not null default('1'),
	isask varchar(1) not null default('1'),
	iszs varchar(1) not null default('1'),
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	vipprice numeric(19,4) not null default(0),
	packprice numeric(19,4) not null default(0),
	pfprice numeric(19,4) not null default(0),
	psprice numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	staxrate int not null default(0),
	dkrate numeric(19,4) not null default(0),
	askcnt numeric(19,4) not null default(0),
	season int null default(0),
	plustatus varchar(1) not null default(''),
	statusdate varchar(10) null,
	isweight varchar(1) not null default('0'),
	mngcs varchar(1) not null default('0'),
	topstock int not null default(0),
	lowstock int not null default(0),
	jhcycle int not null default(0),
	pscycle int not null default(0),
	erpmaterialno varchar(20) null,
	purposecode varchar(10) null,
	beamtcode varchar(8) null,
	fitskin varchar(1) null,
	tare numeric(19,4) not null default(0),
	iszfcode varchar(1) not null default('0'),
	isonline varchar(1) not null default('0'),
	istakeaway varchar(1) not null default('0'),
	chgdate varchar(20) null,
	isuseesl varchar(1) not null default('0'),
	tag1 varchar(100) null,
	tag2 varchar(100) null,
	tag3 varchar(100) null,
	tag4 varchar(100) null,
	tag5 varchar(100) null,
	remark varchar(200) null,
	constraint pk_plu_tmp primary key nonclustered 
	(
		plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_plupack_tmp') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_plupack_tmp

create table t_plupack_tmp (
	packcode varchar(20) not null,
	plucode varchar(20) not null,
	pluprice numeric(19,4) not null default(0),
	counts numeric(19,4) not null default(0),
	packtotal numeric(19,4) not null default(0),
	packtype varchar(1) not null default('0'),
	constraint pk_plupack_tmp primary key nonclustered
	(
		packcode,plucode
	)
)
go

if exists (select * from sysobjects where id = object_id(N't_plu_freq') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_plu_freq

create table t_plu_freq (
	plucode varchar(20) not null,
	pluname varchar(40) not null,
	plutype varchar(1) null,
	sortno int not null default(1),
	orgcode varchar(10) not null,
	chgdate varchar(10) null,
	chgtime varchar(8) null,
	remark varchar(200) null,
	constraint pk_plu_freq primary key nonclustered
	(
		plucode,orgcode
	)
)
go 

if exists (select * from sysobjects where id = OBJECT_ID(N't_item_disp_set') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_item_disp_set

create table t_item_disp_set (
	itemtype varchar(2) not null,
	itemcode varchar(4) not null,	
	serialno varchar(3) not null,	
	caption varchar(40) not null,	
	visible varchar(1) not null,	
	tag int not null default(0),	
	canset varchar(1) not null,	
	constraint pk_item_disp_set primary key nonclustered
	(
		itemtype,itemcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_ebalance') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_ebalance

create table t_ebalance (
	orgcode varchar(10) not null,
	ebcode varchar(10) not null,
	ebname varchar(40) null,
	selected varchar(1) null,
	ipaddr varchar(20) null,
	port int null,
	balancetype varchar(2) not null default(''),
	balanceseries varchar(2) null,
	barcodetype varchar(1) not null default('0'),
	transtype int default (1),
	transfilename varchar(50) ,
	transtime varchar(20),
	transunit varchar(1) not null default('0'),
	areainfo varchar(50) not null default(''),
	remark varchar(40) null,
	constraint pk_ebalance primary key nonclustered
	(
		ebcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_ebalance_plu') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
  drop table t_ebalance_plu

create table t_ebalance_plu (
	ebcode varchar(10) not null,
	plucode varchar(20) not null,
	constraint pk_ebalance_plu primary key nonclustered 
	(
		ebcode,plucode
	)
)
go


if exists (select * from sysobjects where id = OBJECT_ID(N't_plu_ebext') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_plu_ebext

create table t_plu_ebext (
	plucode varchar(20) not null,
	labeltype varchar(20) not null default('1'),
	extinfo1 varchar(100) null,
	extinfo2 varchar(100) null,
	extinfo3 varchar(100) null,
	extinfo4 varchar(100) null,
	constraint pk_plu_ebext primary key nonclustered
	(
		plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_label_prn_task') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_label_prn_task

create table t_label_prn_task (
	taskid int not null identity(1,1),
	plucode varchar(20) not null,
	pluname varchar(40) null,
	barcode varchar(20) null,
	prncount int not null default(1),
	orgcode varchar(10) not null,
	oldprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	vipprice numeric(19,4) not null default(0),
	spec varchar(40) null,
	unit varchar(10) null,
	prodarea varchar(30) null,
	grade varchar(8) null,
	prntype varchar(1) null,
	srctype varchar(1) not null default('0'),
	prntimes int not null default(0),
	diyfield1 varchar(50) null,
	diyfield2 varchar(50) null,
	diyfield3 varchar(50) null,
	diyfield4 varchar(50) null,
	colorcode varchar(10) null,
	sizecode varchar(10) null,
	csbarcode varchar(40) null,
	remark varchar(200) null,
	constraint pk_label_prn_task primary key nonclustered
	(
		taskid
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_unit') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_unit

create table t_unit (
    unitcode varchar(10) not null,
	unitname varchar(10) not null,
	chgdate varchar(20) null,
	remark varchar(200) null,
	constraint pk_unit primary key nonclustered
	(
		unitcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_tax_rate') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_tax_rate

create table t_tax_rate (
	taxtype varchar(10) not null,
	taxvalue int not null default(0),
	isdefault varchar(1) not null default('0'),
	remark varchar(200) null,
	constraint pk_tax_rate primary key nonclustered
	(
		taxtype,taxvalue
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_remark_info') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_remark_info

create table t_remark_info (
	billtype varchar(4) not null,
	remarkcode varchar(4) not null,
	remarkdep varchar(200) not null,
	constraint pk_remark_info primary key nonclustered
	(
		billtype,remarkcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_plu_tare') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_plu_tare

create table t_plu_tare (
	tarecode varchar(10) not null,
	tarevalue numeric(19,4) not null default(0),
	constraint pk_plu_tare primary key nonclustered
	(
		tarecode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_func_dept') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_func_dept

create table t_func_dept (
	funcdepcode varchar(10) not null,
	funcdepname varchar(20) null,
	remark varchar(200) null,
	constraint pk_funcdept primary key nonclustered
	(
		funcdepcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_dev_type') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_dev_type

create table t_dev_type (
	devcode varchar(4) not null,
	devname varchar(20) not null,
	lxcode varchar(1) not null default('0'),
	purpose varchar(2) not null default('0'),
	remark varchar(200) null,
	constraint pk_dev_type primary key nonclustered
	(
		devcode,lxcode 
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_dev_set') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_dev_set

create table t_dev_set (
	devno varchar(4) not null,
	devcode varchar(4) not null,
	lxcode varchar(1) not null default('0'),
	formatsign varchar(4) not null default(','),
	weightunit varchar(6) null,
	weightrate numeric(19,4) not null default(100),
	capability int null,
	remark varchar(200) null,
	constraint pk_dev_set primary key nonclustered
	(
		devno,devcode,lxcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_dev_item') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_dev_item

create table t_dev_item (
	lxcode varchar(1) not null default('0'),
	fldcode varchar(4) not null,
	fldname varchar(20) null,
	fldtype varchar(1) not null default('0'),
	fldcontent varchar(20) null,
	constraint pk_dev_item primary key nonclustered
	(
		fldcode,lxcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_dev_format') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_dev_format

create table t_dev_format (
	devcode varchar(4) not null,
	lxcode varchar(1) not null default('0'),
	fldcode varchar(4) not null,
	fldwidth int not null default(0),
	alignment varchar(1) not null default('0'),
	fillchar varchar(1) not null default(' '),
	serialno int not null,
	constraint pk_dev_format primary key nonclustered
	(
		devcode,lxcode,fldcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pda') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pda

create table t_pda (
	devno varchar(4) not null,
	devmodel varchar(50) null,
	devsn varchar(50) null,
	checkcode varchar(50) null,
	remark varchar(200) null,
	constraint pk_pda primary key nonclustered
	(
		devno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_enum_type') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_enum_type

create table t_enum_type (
	enumcode varchar(6) not null,
	enumname varchar(20) not null,
	type varchar(1) not null,
	usepurpose varchar(50) null,
	constraint pk_enum_type primary key nonclustered
	( 
		enumcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_enum_value') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_enum_value

create table t_enum_value (
	enumcode varchar(6) not null,
	valuecode varchar(6) not null,
	valuename varchar(20) not null,
	isdefault varchar(1) not null default('0'),
	constraint pk_enum_value primary key nonclustered
	( 
		enumcode,valuecode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pda_device') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pda_device

create table t_pda_device (
	devno varchar(3) not null,
	devbrand varchar(50) null,
	devmodel varchar(50) null,
	trantype varchar(1) not null,
	filetype varchar(10) not null,
	isdefault varchar(1) null,
	remark varchar(200) null,
	constraint pk_pda_device primary key nonclustered
	(
		devno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pda_device_params') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pda_device_params
go

create table t_pda_device_params (
	devno varchar(3) not null,
	serialno int not null,
	paramname varchar(50) not null,
	paramvalue varchar(50) null,
	valuelist varchar(200) null,
	constraint [REDACTED]primary key nonclustered
	(
		devno,serialno
	)
)
go


--02 采购

if exists (select * from sysobjects where id = OBJECT_ID(N't_supplier') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_supplier

create table t_supplier (
	supcode varchar(15) not null,
	supname varchar(100) not null,
	mncode varchar(100) not null,
	suptype varchar(1) not null default('0'),
	supstatus varchar(1) not null default('0'),
	statusdate varchar(10) null,
	jymode varchar(1) not null default('0'),
	dkrate numeric(19,4) not null default(0),
	region varchar(10) null,
	addr varchar(100) null,
	zipcode varchar(6) null,
	tel varchar(20) null,
	fax varchar(20) null,
	email varchar(40) null,
	manager varchar(20) null,
	contact varchar(20) null,
	entquality varchar(10) null,
	enttype varchar(20) null,
	bank varchar(100) null,
	account varchar(40) null,
	taxcode varchar(30) null,
	regcode varchar(30) null,
	opendate varchar(10) null,
	ordermode varchar(20) null,
	delivermode varchar(20) null,
	deliveraddr varchar(100) null,
	period varchar(20) null,
	settlemode varchar(20) null,
	credit varchar(10) null,
	mobile1 varchar(20) null,
	mobile2 varchar(20) null,
	jhtotal numeric(19,4) not null default(0),
	thtotal numeric(19,4) not null default(0),
	tjtotal numeric(19,4) not null default(0),
	dywtotal numeric(19,4) not null default(0),
	amount numeric(19,4) not null default(0),
	tctotal numeric(19,4) not null default(0),
	feetotal numeric(19,4) not null default(0),
	xscost numeric(19,4) not null default(0),
	dztotal numeric(19,4) not null default(0),
	dzrtotal numeric(19,4) not null default(0),
	fktotal numeric(19,4) not null default(0),
	zrtotal numeric(19,4) not null default(0),
	prepay numeric(19,4) not null default(0),
	hyglicence varchar(20) null,
	taxlicence varchar(20) null,
	reglicence varchar(20) null,
	validdate varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	chkmsg varchar(200) null,
	chkdate varchar(10) null,
	chktime varchar(8) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	remark varchar(200) null,
	constraint pk_supplier primary key nonclustered
	(
		supcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_contract') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_contract

create table t_contract (
	contrno varchar(40) not null,
	contrname varchar(30) not null,
	contrtitle varchar(40) null,
	extcontrno varchar(40) null,
	supcode varchar(15) not null,
	gfsigner varchar(8) null,
	xfsigner varchar(8) null,
	signaddr varchar(40) null,
	signdate varchar(10) null,
	bgndate varchar(10) null,
	enddate varchar(10) null,
	contrtext text null,
	lrdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	contrstatus varchar(1) not null default('0'),
	statusdate varchar(10) null,
	orgcode varchar(10) not null default('*'),
	jymode varchar(1) not null default('0'),
	jscode varchar(1) not null default('0'),
	zqdays int not null default(0),
	yqdays int not null default(0),
	isdefault varchar(1) not null default('0'),
	ismngjprice varchar(1) not null default('0'),
	jsperiod varchar(1) not null default('0'),
	ext1 varchar(500) null,
	ext2 varchar(500) null,
	ext3 varchar(500) null,
	ext4 varchar(500) null,
	ext5 varchar(500) null,
	remark varchar(200) null,
	constraint pk_contract primary key nonclustered
	(
		contrno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_contr_org') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_contr_org

create table t_contr_org (
	contrno varchar(40) not null,
	orgcode varchar(10) not null,
	remark varchar(200) null,
	constraint pk_contr_org primary key nonclustered
	(
		contrno,orgcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_contr_plu') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_contr_plu

create table t_contr_plu (
	contrno varchar(40) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	jtaxrate int not null default(0),
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	remark varchar(200) null,
	constraint pk_contr_plu primary key nonclustered
	(
		contrno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_contr_clause') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_contr_clause

create table t_contr_clause (
	contrno varchar(40) not null,
	supcode varchar(15) not null,
	orgcode varchar(10) not null,
	itemcode varchar(4) not null,
	itemno varchar(10) not null,
	bgndate varchar(10) not null,
	enddate varchar(10) not null,
	basetype varchar(4) not null default('00'),
	feetotal numeric(19,4) not null default(0),
	feerate numeric(19,4) not null default(0),
	cltype varchar(1) not null default('2'),
	cldate varchar(20) null,
	zftype varchar(1) not null default('1'),
	iscalprofit varchar(1) not null default('0'),
	calmode varchar(1) not null default('0'),
	calbgndate varchar(10) null,
	calenddate varchar(10) null,
	isinvoice varchar(1) not null default('0'),
	clausetype varchar(1) not null default('0'),
	tendcode varchar(10) null,
	plucode varchar(20) null,
	clscode varchar(10) null,
	brandcode varchar(10) null,
	isladderrate varchar(1) not null default('0'),
	laddercaltype varchar(1) not null default('0'),
	lrdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	ext1 varchar(500) null,
	ext2 varchar(500) null,
	ext3 varchar(500) null,
	ext4 varchar(500) null,
	ext5 varchar(500) null,
	midclscode varchar(10) null,
	remark varchar(200) null,
	constraint pk_contr_clause primary key nonclustered 
	(
		contrno,supcode,orgcode,itemcode,itemno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_contr_clause_rate') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_contr_clause_rate

create table t_contr_clause_rate (
    contrno varchar(40) not null,
	supcode varchar(15) not null,
	orgcode varchar(10) not null,
	itemcode varchar(4) not null,
	itemno varchar(10) not null,
	serialno int not null,
	mintotal numeric(19,4) not null default(0),
	maxtotal numeric(19,4) not null default(0),
	rate numeric(19,4) not null default(0),
	constraint [REDACTED]primary key nonclustered 
	(
		contrno,supcode,orgcode,itemcode,itemno,serialno
	)
)
go

if not exists (select * from sysobjects where id = OBJECT_ID(N't_adjclause_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_adjclause_head
	
create table t_adjclause_head (
	billno varchar(20) not null,
	orgcode varchar(10) not null,
	bizdate varchar(10) null,
	optype varchar(1) not null default('0'),
	contrno varchar(40) not null,
	supcode varchar(15) not null,
	supname varchar(100) null,
	billtype varchar(1) not null default('0'),
	dsccode varchar(200) null,
	dsctype varchar(10) null,
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null default(0),
	tag varchar(2) null,
	timemark timestamp null,
	remark varchar(200) null,
	constraint pk_adjclause_head primary key nonclustered
	(
		billno
	)
)
go

if not exists (select * from sysobjects where id = OBJECT_ID(N't_adjclause_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_adjclause_body
	
create table t_adjclause_body (
	billno varchar(20) not null,
	serialno int not null default(1),
	optype varchar(1) not null default('0'),
	contrno varchar(40) not null,
	supcode varchar(15) not null,
	orgcode varchar(10) not null,
	itemcode varchar(4) not null,
	itemno varchar(10) not null,
	bgndate varchar(10) not null,
	enddate varchar(10) not null,
	basetype varchar(4) not null default('00'),
	feetotal numeric(19,4) not null default(0),
	feerate numeric(19,4) not null default(0),
	cltype varchar(1) not null default('2'),
	cldate varchar(20) null,
	zftype varchar(1) not null default('1'),
	iscalprofit varchar(1) not null default('0'),
	calmode varchar(1) not null default('0'),
	calbgndate varchar(10) null,
	calenddate varchar(10) null,
	isinvoice varchar(1) not null default('0'),
	clausetype varchar(1) not null default('0'),
	tendcode varchar(10) null,
	plucode varchar(20) null,
	clscode varchar(10) null,
	brandcode varchar(10) null,
	isladderrate varchar(1) not null default('0'),
	laddercaltype varchar(1) not null default('0'),
	ext1 varchar(500) null,
	ext2 varchar(500) null,
	ext3 varchar(500) null,
	ext4 varchar(500) null,
	ext5 varchar(500) null,
	midclscode varchar(10) null,
	remark varchar(200) null,
	constraint pk_adjclause_body primary key nonclustered 
	(
		billno,serialno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_ask_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_ask_head

create table t_ask_head (
	billno varchar(20) not null,
	orgcode varchar(10) not null,
	asktype varchar(1) not null default('0'),
	askbgndate varchar(10) null,
	askenddate varchar(10) null,
	cldate varchar(10) null,
	state varchar(1) not null default('0'),
	counts numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null default(0),
	tag varchar(2) null,
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_ask_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_ask_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_ask_body

create table t_ask_body (
	billno varchar(20) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	punit varchar(10) null,
	itemcnt numeric(19,4) not null default(0),
	pcount numeric(19,4) not null default(0),
	sglcount numeric(19,4) not null default(0),
	counts numeric(19,4) not null default(0),
	jycounts numeric(19,4) not null default(0),
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	cgdate varchar(10) null,
	psdate varchar(10) null,
	ypcount numeric(19,4) not null default(0),
	asktype varchar(1) not null default('0'),
	cgmode varchar(1) not null default('0'),
	clstate varchar(1) not null default('0'),
	clmode varchar(1) not null default('0'),
	sscount umeric(19,4) not null default(0),
	ztcount umeric(19,4) not null default(0),
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	promname varchar(100) null,
	promdesc varchar(100) null,
	constraint pk_ask_body primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_order_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_order_head

create table t_order_head (
	billno varchar(20) not null,
	orgcode varchar(10) not null,
	bizdate varchar(10) null,
	billtype varchar(1) not null default('0'),
	supcode varchar(15) not null,
	supname varchar(100) null,
	contrno varchar(40) null,
	arrivedate varchar(10) null,
	validdate varchar(10) null,
	state varchar(1) not null default('0'),
	goodsstate varchar(1) null default('0'),
	sqauremode varchar(1) not null default('0'),
	paydate varchar(10) null,
	counts numeric(19,4) not null default(0),
	givecount numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	dhcount numeric(19,4) not null default(0),
	dhcost numeric(19,4) not null default(0),
	dhnetcost numeric(19,4) not null default(0),
	iszs varchar(1) not null default('0'),
	zsno varchar(20) null,
	qrdate varchar(10) null,
	qrtime varchar(8) null,
	qrcount numeric(19,4) null,
	qrstatus varchar(1) not null default('0'),
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null default(0),
	tag varchar(2) null,
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	zstype varchar(1) not null default('0'),
	constraint pk_order_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_order_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_order_body

create table t_order_body (
	billno varchar(20) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	spec varchar(40) null,
	cargono varchar(20) null,
	unit varchar(10) null,
	punit varchar(10) null,
	itemcnt numeric(19,4) not null default(0),
	pcount numeric(19,4) not null default(0),
	sglcount numeric(19,4) not null default(0),
	counts numeric(19,4) not null default(0),
	givecount numeric(19,4) not null default(0),
	ornjprice numeric(19,4) not null default(0),
	ornnetjprice numeric(19,4) not null default(0),
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	dhcount numeric(19,4) not null default(0),
	dhcost numeric(19,4) not null default(0),
	dhnetcost numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	qrcount numeric(19,4) null,
	tag varchar(10) null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_order_body primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_orderquote_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_orderquote_head

create table t_orderquote_head (
	billno varchar(20) not null,
	contrno varchar(40) not null default '*',
	orgcode varchar(10) not null,
	supcode varchar(15) not null,
	supname varchar(100) null,
	quotetype varchar(1) not null default('0'),
	dsccode varchar(20) null,
	bgndate varchar(10) null,
	enddate varchar(10) null,
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	billsrc varchar(1) not null default('0'),
	prntimes int null default(0),
	timemark timestamp null,
	remark varchar(200) null,
	constraint pk_orderquote_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_orderquote_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_orderquote_body

create table t_orderquote_body (
	billno varchar(20) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	jtaxrate int not null default(0),
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_orderquote_body primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_orderquote_org') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_orderquote_org

create table t_orderquote_org (
	billno varchar(20) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	orgcode varchar(10) not null,
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	remark varchar(200) null,
	constraint pk_orderquote_org primary key nonclustered
	(
		billno,serialno,plucode,orgcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_order_quote') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_order_quote

create table t_order_quote (
	billno varchar(20) not null,
	contrno varchar(40) not null default '*',
	orgcode varchar(10) not null,
	supcode varchar(15) not null,
	supname varchar(100) null,
	quotetype varchar(1) not null,
	orgtype varchar(3) null,
	dsccode varchar(20) null,
	bgndate varchar(10) not null,
	enddate varchar(10) not null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	usercode varchar(6) null,
	username varchar(10) null,
	serialno int null,
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	remark varchar(200) null,
	constraint pk_order_quote primary key nonclustered
	(
		orgcode,quotetype,plucode,supcode,contrno,bgndate,enddate
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_adjbuyprice_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_adjbuyprice_head

create table t_adjbuyprice_head (
	billno varchar(20) not null,
	orgcode varchar(10) not null,
	bizdate varchar(10) null,
	supcode varchar(15) null,
	supname varchar(100) null,
	contrno varchar(40) null,
	sqauremode varchar(1) not null default('0'),
	paydate varchar(10) null,
	isplan varchar(1) not null default('0'),
	sxdate varchar(10) not null default(''),
	sxtime varchar(8) not null default(''),
	exectime varchar(20) not null default(''),
	tztype varchar(1) not null default('0'),
	tzcount numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	newcost numeric(19,4) not null default(0),
	newnetcost numeric(19,4) not null default(0),
	cjcost numeric(19,4) not null default(0),
	netcjcost numeric(19,4) not null default(0),
	tzdate varchar(10) null,
	dsccode varchar(20) null,
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null default(0),
	tag varchar(2) null,
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint [REDACTED]primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_adjbuyprice_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_adjbuyprice_body

create table t_adjbuyprice_body (
	billno varchar(20) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	newjprice numeric(19,4) not null default(0),
	newnetjprice numeric(19,4) not null default(0),
	tzcount numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	newcost numeric(19,4) not null default(0),
	newnetcost numeric(19,4) not null default(0),
	cjcost numeric(19,4) not null default(0),
	netcjcost numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint [REDACTED]primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_dkrate_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_dkrate_head

create table t_dkrate_head (
	billno varchar(20) not null,
	supcode varchar(15) not null,
	supname varchar(100) null,
	dkrate numeric(19,4) null,
	bgndate varchar(10) null,
	enddate varchar(10) null,
	state varchar(1) not null default('0'),
	serialno int null,
	dsccode varchar(20) null,
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null,
	tag varchar(2) null,
	timemark timestamp not null,
	remark varchar(200) null,
	constraint pk_dkrate_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_dkrate_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_dkrate_body

create table t_dkrate_body (
	billno varchar(20) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	dkrate numeric(19,4) not null default(0),
	remark varchar(200) null,
	constraint pk_dkrate_body primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_dkrate_org') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_dkrate_org

create table t_dkrate_org (
	billno varchar(20) not null,
	orgcode varchar(10) not null,
	constraint pk_dkrate_org primary key nonclustered
	(
		billno,orgcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_enterprise') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_enterprise

create table t_enterprise (
	etpcode varchar(20) not null,
	etpname varchar(40) not null,
	addr varchar(200) null,
	region varchar(30) null,
	tel varchar(20) null,
	fax varchar(20) null,
	email varchar(30) null,
	manager varchar(10) null,
	contact varchar(10) null,
	remark varchar(200) null,
	constraint pk_enterprise primary key nonclustered
	(
		etpcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_bigorder_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_bigorder_head

create table t_bigorder_head (
	billno varchar(20) not null,
	orgcode varchar(10) not null,
	bizdate varchar(10) null,
	custname varchar(100) null,
	contact varchar(20) null,
	tel varchar(20) null,
	addr varchar(200) null,
	counts numeric(19,4) not null default(0),
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null default(0),
	tag varchar(2) null,
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_bigorder_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_bigorder_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_bigorder_body

create table t_bigorder_body (
	billno varchar(20) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	spec varchar(40) null,
	cargono varchar(20) null,
	unit varchar(10) null,
	counts numeric(19,4) not null default(0),
	tag varchar(10) null,
	clstate varchar(1) not null default('0'),
	depname varchar(16) null,
	depcode varchar(10) null,
	remark varchar(200) null,
	constraint pk_bigorder_body primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go


--03 进货

if exists (select * from sysobjects where id = OBJECT_ID(N't_accept_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_accept_head

create table t_accept_head (
	billno varchar(20) not null,
	orgcode varchar(10) not null,
	bizdate varchar(10) null,
	billtype varchar(1) not null default('0'),
	oldbillno varchar(20) null,
	supcode varchar(15) null,
	supname varchar(100) null,
	contrno varchar(40) null,
	orderno varchar(20) null,
	askno varchar(20) null,
	sqauremode varchar(1) not null default('0'),
	place varchar(1) not null default('0'),
	paydate varchar(10) null,
	counts numeric(19,4) not null default(0),
	givecount numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	qrdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null default(0),
	tag varchar(2) null,
	timemark timestamp not null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_accept_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_accept_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_accept_body

create table t_accept_body (
	billno varchar(20) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	supcode varchar(15) null,
	punit varchar(10) null,
	itemcnt numeric(19,4) not null default(0),
	pcount numeric(19,4) not null default(0),
	sglcount numeric(19,4) not null default(0),
	counts numeric(19,4) not null default(0),
	givecount numeric(19,4) not null default(0),
	cgcount numeric(19,4) not null default(0),
	isdscjprice varchar(1) not null default('0'),
	ornjprice numeric(19,4) not null default(0),
	ornnetjprice numeric(19,4) not null default(0),
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	jxprice numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	keepdays int not null default(0),
	productdate varchar(10) null,
	qualitydate varchar(10) null,
	productno varchar(20) null,
	bincode varchar(10) null,
	tag varchar(1) null,
	depcode varchar(10) null,
	depname varchar(16) null,
	cercode varchar(20) null,
	picture image null,
	remark varchar(200) null,
	constraint pk_acceptdetail primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_return_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_return_head

create table t_return_head (
	billno varchar(20) not null,
	orgcode varchar(10) not null,
	bizdate varchar(10) null,
	billtype varchar(1) not null default('0'),
	supcode varchar(15) null,
	supname varchar(100) null,
	contrno varchar(40) null,
	paydate varchar(10) null,
	sqauremode varchar(1) not null default('0'),
	place varchar(1) not null default('0'),
	oldbillno varchar(20) null,
	acceptno varchar(20) null,
	counts numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	orgin varchar(1) null,
	kindcd varchar(10) null,
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null default(0),
	tag varchar(2) null,
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	zstype varchar(1) not null default('0'),
	constraint pk_returnform primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_return_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_return_body

create table t_return_body (
	billno varchar(20) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	punit varchar(10) null,
	itemcnt numeric(19,4) not null default(0),
	pcount numeric(19,4) not null default(0),
	sglcount numeric(19,4) not null default(0),
	counts numeric(19,4) not null default(0),
	orncounts numeric(19,4) not null default(0),
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	jxprice numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	kindcd varchar(10) null,
	bincode varchar(10) null,
	tag varchar(1) null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_return_body primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_return_apply_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_return_apply_head

create table t_return_apply_head (
	billno varchar(20) not null,
	orgcode varchar(10) not null,
	bizdate varchar(10) null,
	sqauremode varchar(1) not null default('0'),
	place varchar(1) not null default('0'),
	counts numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	orgin varchar(1) null,
	kindcd varchar(10) null,
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null default(0),
	tag varchar(2) null,
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint [REDACTED]primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_return_apply_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_return_apply_body

create table t_return_apply_body (
	billno varchar(20) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	punit varchar(10) null,
	itemcnt numeric(19,4) not null default(0),
	pcount numeric(19,4) not null default(0),
	sglcount numeric(19,4) not null default(0),
	counts numeric(19,4) not null default(0),
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	jxprice numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	kindcd varchar(10) null,
	bincode varchar(10) null,
	productdate varchar(10) null,
	qualitydate varchar(10) null,
	tag varchar(1) null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint [REDACTED]primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_supaccept_detail') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_supaccept_detail

create table t_supaccept_detail (
	billno varchar(20) not null,
	orgcode varchar(10) not null,
	orgname varchar(30) null,
	serialno numeric(19,0) not null default(0),
	plucode varchar(20) not null,
	pluname varchar(40) null,
	billtype varchar(1) not null default('0'),
	supcode varchar(15) not null,
	supname varchar(100) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	counts numeric(19,4) not null default(0),
	ftcounts numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	remark varchar(200) null,
	indexno numeric(19,0) not null identity(1,1),
	constraint [REDACTED]primary key nonclustered
	(
		billno,orgcode,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pre_delivery') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pre_delivery
go
create table t_pre_delivery (
	billno varchar(20) not null,
	orgcode varchar(10) not null,
	orderno varchar(20) null,
	supcode varchar(15) null,
	supname varchar(100) null,
	predate varchar(10) null,
	pretime varchar(8) null,
	truckno varchar(20) null,
	contact varchar(20) null,
	tel varchar(20) null,
	chkstatus varchar(1) not null default('0'),
	chkmsg varchar(200) null,
	chkdate varchar(10) null,
	chktime varchar(8) null,
	counts numeric(19,4) not null default(0),
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	remark varchar(200) null,
	constraint pk_pre_delivery primary key nonclustered
	(
		billno
	)
)
go


--04 零售

if exists (select * from sysobjects where id = OBJECT_ID(N't_pos') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pos

create table t_pos (
	orgcode varchar(10) not null,
	posno varchar(6) not null,
	postype varchar(1) not null default('0'),
	posos varchar(1) not null default('0'),
	stationid varchar(15) null,
	nouse varchar(1) not null default('0'),
	status varchar(1) null,
	usercode varchar(6) null,
	overdate varchar(10) null,
	overtimes int null,
	depflg varchar(1) null,
	clsflg varchar(1) null,
	pluflg varchar(1) null,
	dscflg varchar(1) null,
	userflg varchar(1) null,
	tendflg varchar(1) null,
	keyflg varchar(1) null,
	iniflg varchar(1) null,
	prnflg varchar(1) null,
	vipflg varchar(1) null,
	billflg varchar(1) null,
	custflg varchar(1) null,
	cardflg varchar(1) null,
	chkflg varchar(1) null,
	ptflg varchar(1) null,
	overprocflg varchar(1) null,
	chkprocflg varchar(1) null,
	lastovertradedate varchar(8) null,
	overctrlstate varchar(1) null default(''),
	overctrltime varchar(20) null,
	pluchgdate varchar(23) null,
	dscchgdate varchar(23) null,
	vipchgdate varchar(23) null,
	constraint pk_pos primary key nonclustered
	(
		orgcode,posno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_poscfg') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_poscfg

create table t_poscfg (
	orgcode varchar(10) not null,
	posno varchar(6) not null,
	section varchar(20) not null,
	itemname varchar(20) not null,
	itemvalue varchar(200) null,
	chgflag varchar(1) null,
	constraint pk_poscfg primary key nonclustered
	(
		orgcode,posno,section,itemname
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pos_prn_format') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
    drop table t_pos_prn_format

create table t_pos_prn_format (
	orgcode varchar(10) not null default ('*'),
	posno varchar(6) not null default ('*'),
	prntype int not null default(1),
	prnsize varchar(1) not null default ('0'),
	prnname varchar(40) null,
	prnformat image null,
	chgdate varchar(20) null,
	remark varchar(40) null,
	constraint pk_pos_prn_format primary key nonclustered
	(
		orgcode,posno,prntype,prnsize
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_keydef') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_keydef

create table t_keydef (
	orgcode varchar(10) not null,
	posno varchar(6) not null,
	nscancode int not null,
	nasccode varchar(1) null,
	cfunc int null,
	ctype int null,
	cuserdef varchar(20) null,
	serialno int null,
	constraint pk_keydef primary key nonclustered
	(
		orgcode,posno,nscancode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_tend') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_tend

create table t_tend (
	tendcode varchar(4) not null,
	tendname varchar(20) null,
	currcode varchar(2) null,
	changeflg varchar(1) not null default('1'),
	getnumflg varchar(1) not null default('0'),
	exchgrate numeric(19,4) not null default(1),
	canpt varchar(1) not null default('1'),
	candsc varchar(1) not null default('1'),
	opendrawer varchar(1) not null default('1'),
	prntimes int null default(0),
	serialno int not null default(0),
	isview int not null default(1),
	canround varchar(1) not null default('0'),
	isdefault varchar(1) not null default('1'),
	tendparam varchar(400) null,
	param1 varchar(10) null,
	constraint pk_tend primary key nonclustered
	(
		tendcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pct_project') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pct_project

create table t_pct_project (
	prjcode varchar(6) not null,
	prjname varchar(40) not null,
	storeproc varchar(40) null,	
	usertype varchar(1) not null default('0'),
	tcbasetype varchar(1) not null default('0'),
	lrdate varchar(10) null,	
	rzdate varchar(10) null,	
	usercode varchar(6) null,	
	username varchar(10) null,	
	updusercode varchar(6) null,	
	updusername varchar(10) null,	
	upddate varchar(10) null,	
	remark varchar(200) null,	
	constraint pk_pct_project primary key nonclustered
	(
		prjcode,usertype
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pct_project_detail') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pct_project_detail

create table t_pct_project_detail (
	prjcode varchar(6) not null,
	usertype varchar(1) not null default('0'),
	grptype varchar(1) not null,
	grpcode varchar(20) not null,	
	serialno int not null default(0),	
	israte varchar(1) not null default('0'),
	tcrate numeric(19,4) not null default(0),	
	tctotal numeric(19,4) not null default(0),	
	tcmintotal numeric(19,4) not null default(0),	
	tcmaxtotal numeric(19,4) not null default(0),	
	remark varchar(200) null,	
	constraint [REDACTED]primary key nonclustered
	(
		prjcode,usertype,grptype,grpcode,serialno,tcmintotal,tcmaxtotal
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_work_log') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_work_log

create table t_work_log (
	orgcode varchar(10) not null,
	posno varchar(6) not null,
	datatype varchar(1) not null,
	usercode varchar(6) not null,
	username varchar(10) null,
	logdate varchar(10) not null,
	logtime varchar(8) not null,
	bcno varchar(1) not null default('1'),
	tradedate varchar(10) not null default(''),
	constraint pk_work_log primary key nonclustered
	(
		orgcode,posno,datatype,usercode,logdate,logtime
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_work_shift') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_work_shift

create table t_work_shift (
	bcno varchar(1) not null,
	bcname varchar(10) null,
	ontime varchar(8) null,
	offtime varchar(8) null,
	defontime varchar(8) null,
	defofftime varchar(8) null,
	isused varchar(1) not null default('0'),
	constraint pk_work_shift primary key nonclustered
	(
		bcno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_bill_cfg') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_bill_cfg

create table t_bill_cfg (
	ino int not null,
	itype int null,
	sname varchar(16) null,
	scaption varchar(20) null,
	inamelen int null,
	icaplen int null,
	irow int null,
	icol int null,
	sfillchar varchar(1) null,
	ialign int null,
	constraint pk_bill_cfg primary key nonclustered
	(
		ino
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_cust_set') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_cust_set

create table t_cust_set (
	serialno int not null,
	remark varchar(200) null,
	constraint pk_cust_set primary key nonclustered
	(
		serialno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_cust_item') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_cust_item

create table t_cust_item (
	serialno int not null,
	itemno varchar(1) not null,
	remark varchar(200) null,
	constraint pk_cust_item primary key nonclustered
	(
		serialno,itemno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_sale_task') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_sale_task

create table t_sale_task (
	orgcode varchar(10) not null,
	usercode varchar(6) not null,
	tpyear varchar(4) not null,
	tporder varchar(2) not null,
	saleairmtotal numeric(19,4) not null default(0),
	bgndate varchar(10) null,
	enddate varchar(10) null,
	lrdate varchar(10) not null,
	lrusercode varchar(6) not null,
	uptdate varchar(10) null,
	uptusercode varchar(6) null,
	tag varchar(1) null,
	remark varchar(200) null,
	constraint pk_sale_task primary key nonclustered 
	(
		orgcode,usercode,tpyear,tporder
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_adjprice_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_adjprice_head

create table t_adjprice_head (
	billno varchar(20) not null,
	orgcode varchar(10) null,
	bizdate varchar(10) null,
	supcode varchar(15) null,
	billtype varchar(1) null default('0'),
	isplan varchar(1) not null default('0'),
	sxdate varchar(10) not null default(''),
	sxtime varchar(8) not null default(''),
	exectime varchar(20) not null default(''),
	state varchar(1) not null default('0'),
	counts numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	newtotal numeric(19,4) not null default(0),
	totaldiff numeric(19,4) not null default(0),
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null default(0),
	tag varchar(2) null,
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_adjprice_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_adjprice_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_adjprice_body

create table t_adjprice_body (
	billno varchar(20) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	oldprice numeric(19,4) not null default(0),
	newprice numeric(19,4) null,
	oldvipprice numeric(19,4) not null default(0),
	newvipprice numeric(19,4) null,
	oldpfprice numeric(19,4) not null default(0),
	newpfprice numeric(19,4) null,
	oldpsprice numeric(19,4) not null default(0),
	newpsprice numeric(19,4) null,
	counts numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	newtotal numeric(19,4) not null default(0),
	totaldiff numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	tag varchar(1) null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_adjprice_body primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_modify_inc') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_modify_inc

create table t_modify_inc (
	orgcode varchar(10) not null,
	modifyitem varchar(2) not null,
	modifyid varchar(20) not null,
	modifycode varchar(20) not null,
	modifytype varchar(1) not null default('d'),
	chgdate varchar(20) not null
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_time_prd') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_time_prd

create table t_time_prd (
	bgntime varchar(10) not null,
	endtime varchar(10) not null,
	constraint pk_time_prd primary key nonclustered
	(
		bgntime,endtime
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_cust_order_info') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_cust_order_info

create table t_cust_order_info (
	serialno bigint not null identity(1,1),
	djno varchar(18) not null,
	orgcode varchar(10) not null,
	posno varchar(6) not null,
	djdate varchar(10) not null,
	djtime varchar(8) not null,
	custcode varchar(20) null,
	custname varchar(20) null,
	tel varchar(20) null,
	addr varchar(30) null,
	datastatus varchar(1) not null,
	djtotal numeric(19,4) not null default(0),
	sumtotal numeric(19,4) not null default(0),
	djusetotal numeric(19,4) not null default(0),
	qktotal numeric(19,4) not null default(0),
	ystotal numeric(19,4) not null default(0),
	tdjtotal numeric(19,4) not null default(0),
	sqktotal numeric(19,4) not null default(0),
	yhtotal numeric(19,4) not null default(0),
	cshcode varchar(6) not null,
	cshname varchar(10) null,
	clkcode varchar(6) not null,
	clkname varchar(10) null,
	locksumtotal numeric(19,4) not null default(0),
	lockdjusetotal numeric(19,4) not null default(0),
	lockqktotal numeric(19,4) not null default(0),
	lockdatastatus varchar(1) null,
	remark varchar(200) null,
	constraint pk_cust_order_info primary key nonclustered
	(
		serialno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_flow_total') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_flow_total

create table t_flow_total (
	orgcode varchar(10) not null,
	posno varchar(6) not null,
	sdate varchar(10) not null,
	stime varchar(8) not null,
	serialno varchar(50) not null,
	trantype varchar(1) not null,
	accdate varchar(10) null,
	cshcode varchar(6) not null,
	totaldsc numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	totalpay numeric(19,4) not null default(0),
	change numeric(19,4) not null default(0),
	roundamt numeric(19,4) not null default(0),
	ecwchange numeric(19,4) not null default(0),
	custflag varchar(1) null default('0'),
	custcode varchar(20) null,
	authnum varchar(10) null,
	memostr varchar(10) null,
	customer varchar(20) null,
	ebillno varchar(32) null,
	eposmobile varchar(20) null,
	taxno varchar(20) null,
	tradedate varchar(10) null,
	isrtned varchar(1) null default('0'),
	rtnrefno varchar(100) null,
	isbalanced varchar(1) null default(''),
	invcustid varchar(200) null,
	invcust varchar(200) null,
	remark varchar(200) null,
	sendflg varchar(1) null default('0'),
	shiftno varchar(20) null,
	constraint pk_flow_total primary key nonclustered
	(
		orgcode,posno,sdate,stime,serialno,trantype
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_flow_endtotal') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_flow_endtotal

create table t_flow_endtotal (
	orgcode varchar(10) not null,
	posno varchar(6) not null,
	sdate varchar(10) not null,
	stime varchar(8) not null,
	serialno varchar(50) not null,
	trantype varchar(1) not null,
	accdate varchar(10) null,
	cshcode varchar(6) not null,
	totaldsc numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	totalpay numeric(19,4) not null default(0),
	change numeric(19,4) not null default(0),
	roundamt numeric(19,4) not null default(0),
	ecwchange numeric(19,4) not null default(0),
	custflag varchar(1) null default('0'),
	custcode varchar(20) null,
	authnum varchar(10) null,
	memostr varchar(10) null,
	customer varchar(20) null,
	ebillno varchar(32) null,
	eposmobile varchar(20) null,
	taxno varchar(20) null,
	tradedate varchar(10) null,
	isrtned varchar(1) null default('0'),
	rtnrefno varchar(100) null,
	isbalanced varchar(1) null default(''),
	invcustid varchar(200) null,
	invcust varchar(200) null,
	remark varchar(200) null,
	sendflg varchar(1) null default('0'),
	shiftno varchar(20) null,
	tag varchar(1) not null default('0'),
	constraint pk_flow_endtotal primary key nonclustered
	(
		orgcode,posno,sdate,stime,serialno,trantype
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_flow_total_yyyymm') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_flow_total_yyyymm

create table t_flow_total_yyyymm (
	orgcode varchar(10) not null,
	posno varchar(6) not null,
	sdate varchar(10) not null,
	stime varchar(8) not null,
	serialno varchar(50) not null,
	trantype varchar(1) not null,
	accdate varchar(10) not null,
	cshcode varchar(6) not null,
	totaldsc numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	totalpay numeric(19,4) not null default(0),
	change numeric(19,4) not null default(0),
	roundamt numeric(19,4) not null default(0),
	ecwchange numeric(19,4) not null default(0),
	custflag varchar(1) null default('0'),
	custcode varchar(20) null,
	authnum varchar(10) null,
	memostr varchar(10) null,
	customer varchar(20) null,
	ebillno varchar(32) null,
	eposmobile varchar(20) null,
	taxno varchar(20) null,
	tradedate varchar(10) null,
	isrtned varchar(1) null default('0'),
	rtnrefno varchar(100) null,
	isbalanced varchar(1) null default(''),
	invcustid varchar(200) null,
	invcust varchar(200) null,
	shiftno varchar(20) null,
	remark varchar(200) null,
	constraint [REDACTED]primary key nonclustered 
	(
		orgcode,posno,sdate,stime,serialno,trantype,accdate
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_flow_item') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_flow_item

create table t_flow_item (
	orgcode varchar(10) not null,
	posno varchar(6) not null,
	sdate varchar(10) not null,
	stime varchar(8) not null,
	serialno varchar(50) not null,
	trantype varchar(1) not null,
	pageno varchar(2) not null,
	itemno varchar(5) not null,
	accdate varchar(10) null,
	cshcode varchar(6) null,
	clkcode varchar(6) null,
	itemtype varchar(5) not null,
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	inputcode varchar(20) null,
	depcode varchar(10) not null,
	clscode varchar(10) null,
	colorcode varchar(10) null,
	colorname varchar(20) null,
	sizecode varchar(10) null,
	sizename varchar(20) null,
	yhprice numeric(19,4) not null default(0),	
	pluprice numeric(19,4) not null default(0),
	pluqty numeric(19,4) not null default(0),
	plunum numeric(19,4) not null default(1),
	pludsc numeric(19,4) not null default(0),
	plutotal numeric(19,4) not null default(0),
	pludsctype varchar(1) null,
	ordercode varchar(10) null,
	tradedate varchar(10) null,
	isbalanced varchar(1) null default(''),
	remark varchar(200) null,
	constraint pk_flow_item primary key nonclustered
	(
		orgcode,posno,sdate,stime,serialno,trantype,pageno,itemno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_flow_enditem') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_flow_enditem

create table t_flow_enditem (
	orgcode varchar(10) not null,
	posno varchar(6) not null,
	sdate varchar(10) not null,
	stime varchar(8) not null,
	serialno varchar(50) not null,
	trantype varchar(1) not null,
	pageno varchar(2) not null,
	itemno varchar(5) not null,
	accdate varchar(10) null,
	cshcode varchar(6) null,
	clkcode varchar(6) null,
	itemtype varchar(1) not null,
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	inputcode varchar(20) null,
	depcode varchar(10) not null,
	clscode varchar(10) null,
	colorname varchar(20) null,
	colorcode varchar(10) null,
	sizecode varchar(10) null,
	sizename varchar(20) null,
	yhprice numeric(19,4) not null default(0),	
	pluprice numeric(19,4) not null default(0),
	pluqty numeric(19,4) not null default(0),
	plunum numeric(19,4) not null default(1),
	pludsc numeric(19,4) not null default(0),
	plutotal numeric(19,4) not null default(0),
	pludsctype varchar(1) null,
	ordercode varchar(10) null,
	tradedate varchar(10) null,
	isbalanced varchar(1) null default(''),
	remark varchar(200) null,
	tag varchar(1) not null default('0'),
	constraint pk_enditem primary key nonclustered 
	(
		orgcode,posno,sdate,stime,serialno,trantype,pageno,itemno
	) 
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_flow_item_yyyymm') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_flow_item_yyyymm

create table t_flow_item_yyyymm (
	orgcode varchar(10) not null,
	posno varchar(6) not null,
	sdate varchar(10) not null,
	stime varchar(8) not null,
	serialno varchar(50) not null,
	trantype varchar(1) not null,
	pageno varchar(2) not null,
	itemno varchar(5) not null,
	accdate varchar(10) not null,
	cshcode varchar(6) null,
	clkcode varchar(6) null,
	itemtype varchar(1) not null,
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	inputcode varchar(20) null,
	depcode varchar(10) not null,
	clscode varchar(10) null,
	colorcode varchar(10) null,
	colorname varchar(20) null,
	sizecode varchar(10) null,
	sizename varchar(20) null,
	yhprice numeric(19,4) not null default(0),	
	pluprice numeric(19,4) not null default(0),
	pluqty numeric(19,4) not null default(0),
	plunum numeric(19,4) not null default(1),
	pludsc numeric(19,4) not null default(0),
	plutotal numeric(19,4) not null default(0),
	pludsctype varchar(1) null,
	ordercode varchar(10) null,
	tradedate varchar(10) null,
	isbalanced varchar(1) null default(''),
	remark varchar(200) null,
	constraint [REDACTED]primary key nonclustered
	(
		orgcode,posno,sdate,stime,serialno,trantype,pageno,itemno,accdate
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_flow_itemdsc') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_flow_itemdsc

create table t_flow_itemdsc(
	posno varchar(6) not null,
	orgcode varchar(10) not null,
	sdate varchar(10) not null,
	stime varchar(8) not null,
	serialno varchar(50) not null,
	pageno varchar(2) not null,
	itemno varchar(5) not null,
	plucode varchar(20) not null,
	itemdscno varchar(5) not null,
	trantype varchar(1) not null,
	pludsc numeric(19,4) not null default(0),
	pludsctype varchar(2) null,
	dscbillno varchar(20) null,
	accdate varchar(10) null,
	tradedate varchar(10) null,
	orderstatus varchar(1) not null default ('1')
	constraint pk_flow_itemdsc primary key nonclustered
	(
	  posno,sdate,stime,serialno,pageno,itemno,trantype,orgcode,itemdscno
	 ) 
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_flow_enditemdsc') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_flow_enditemdsc

create table t_flow_enditemdsc(
	posno varchar(6) not null,
	orgcode varchar(10) not null,
	sdate varchar(10) not null,
	stime varchar(8) not null,
	serialno varchar(50) not null,
	pageno varchar(2) not null,
	itemno varchar(5) not null,
	plucode varchar(20) not null,
	itemdscno varchar(5) not null,
	trantype varchar(1) not null,
	pludsc numeric(19,4) not null default(0),
	pludsctype varchar(2) null,
	dscbillno varchar(20) null,
	accdate varchar(10) null,
	tradedate varchar(10) null,
	orderstatus varchar(1) not null default ('1'),
	tag varchar(1) not null default('0'),
	constraint pk_flow_enditemdsc primary key nonclustered
	(
	  posno,sdate,stime,serialno,pageno,itemno,trantype,orgcode,itemdscno
	 ) 
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_flow_itemdsc_yyyymm') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_flow_itemdsc_yyyymm

create table t_flow_itemdsc_yyyymm(
	posno varchar(6) not null,
	orgcode varchar(10) not null,
	sdate varchar(10) not null,
	stime varchar(8) not null,
	serialno varchar(50) not null,
	pageno varchar(2) not null,
	itemno varchar(5) not null,
	plucode varchar(20) not null,
	itemdscno varchar(5) not null,
	trantype varchar(1) not null,
	pludsc numeric(19,4) not null default(0),
	pludsctype varchar(2) null,
	dscbillno varchar(20) null,
	accdate varchar(10) null,
	tradedate varchar(10) null,
	orderstatus varchar(1) not null default ('1')
	constraint [REDACTED]primary key nonclustered
	(
	  posno,sdate,stime,serialno,pageno,itemno,trantype,orgcode,itemdscno
	 ) 
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_flow_pay') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_flow_pay

create table t_flow_pay (
	orgcode varchar(10) not null,
	posno varchar(6) not null,
	sdate varchar(10) not null,
	stime varchar(8) not null,
	serialno varchar(50) not null,
	trantype varchar(1) not null,
	itemno varchar(4) not null,
	accdate varchar(10) null,
	cshcode varchar(6) not null,
	payflag varchar(4) not null,
	amount numeric(19,4) not null default(0),
	payamount numeric(19,4) not null default(0),
	payid varchar(100) null,
	alitradeno varchar(100) null,
	tradedate varchar(10) null,
	isbalanced varchar(1) null default(''),
	constraint pk_flow_pay primary key nonclustered
	(
		orgcode,posno,sdate,stime,serialno,trantype,itemno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_flow_endpay') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_flow_endpay

create table t_flow_endpay (
	orgcode varchar(10) not null,
	posno varchar(6) not null,
	sdate varchar(10) not null,
	stime varchar(8) not null,
	serialno varchar(50) not null,
	trantype varchar(1) not null,
	itemno varchar(4) not null,
	accdate varchar(10) null,
	cshcode varchar(6) not null,
	payflag varchar(4) not null,
	amount numeric(19,4) not null default(0),
	payamount numeric(19,4) not null default(0),
	payid varchar(100) null,
	alitradeno varchar(100) null,
	tradedate varchar(10) null,
	isbalanced varchar(1) null default(''),
	tag varchar(1) not null default('0'),
	constraint pk_flow_endpay primary key nonclustered 
	(
		orgcode,posno,sdate,stime,serialno,trantype,itemno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_flow_pay_yyyymm') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_flow_pay_yyyymm

create table t_flow_pay_yyyymm (
	orgcode varchar(10) not null,
	posno varchar(6) not null,
	sdate varchar(10) not null,
	stime varchar(8) not null,
	serialno varchar(50) not null,
	trantype varchar(1) not null,
	itemno varchar(4) not null,
	accdate varchar(10) not null,
	cshcode varchar(6) not null,
	payflag varchar(4) not null,
	amount numeric(19,4) not null default(0),
	payamount numeric(19,4) not null default(0),
	payid varchar(100) null,
	alitradeno varchar(100) null,
	tradedate varchar(10) null,
	isbalanced varchar(1) null default(''),
	constraint pk_flow_pay_yyyymm primary key nonclustered
	(
		orgcode,posno,sdate,stime,serialno,trantype,itemno,accdate
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_flow_vrftotal') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_flow_vrftotal

create table t_flow_vrftotal (
	orgcode varchar(10) not null,
	posno varchar(6) not null,
	sdate varchar(10) not null,
	stime varchar(8) not null,
	serialno varchar(50) not null,
	trantype varchar(1) not null,
	accdate varchar(10) null,
	cshcode varchar(6) not null,
	totaldsc numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	totalpay numeric(19,4) not null default(0),
	change numeric(19,4) not null default(0),
	roundamt numeric(19,4) not null default(0),
	ecwchange numeric(19,4) not null default(0),
	custflag varchar(1) null default('0'),
	custcode varchar(20) null,
	authnum varchar(10) null,
	memostr varchar(10) null,
	customer varchar(20) null,
	ebillno varchar(32) null,
	eposmobile varchar(20) null,
	taxno varchar(20) null,
	tradedate varchar(10) null,
	isrtned varchar(1) null default('0'),
	rtnrefno varchar(100) null,
	isbalanced varchar(1) null default(''),
	invcustid varchar(200) null,
	invcust varchar(200) null,
	remark varchar(200) null,
	sendflg varchar(1) null default('0'),
	constraint pk_flow_vrftotal primary key nonclustered
	(
		orgcode,posno,sdate,stime,serialno,trantype
	)
)

go

if exists (select * from sysobjects where id = OBJECT_ID(N't_flow_vrfitem') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_flow_vrfitem

create table t_flow_vrfitem (
	orgcode varchar(10) not null,
	posno varchar(6) not null,
	sdate varchar(10) not null,
	stime varchar(8) not null,
	serialno varchar(50) not null,
	trantype varchar(1) not null,
	pageno varchar(2) not null,
	itemno varchar(5) not null,
	accdate varchar(10) null,
	cshcode varchar(6) null,
	clkcode varchar(6) null,
	itemtype varchar(5) not null,
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	inputcode varchar(20) null,
	depcode varchar(10) not null,
	clscode varchar(10) null,
	colorcode varchar(10) null,
	colorname varchar(20) null,
	sizecode varchar(10) null,
	sizename varchar(20) null,
	yhprice numeric(19,4) not null default(0),	
	pluprice numeric(19,4) not null default(0),
	pluqty numeric(19,4) not null default(0),
	pludsc numeric(19,4) not null default(0),
	plutotal numeric(19,4) not null default(0),
	pludsctype varchar(1) null,
	ordercode varchar(10) null,
	tradedate varchar(10) null,
	isbalanced varchar(1) null default(''),
	remark varchar(200) null,
	constraint pk_flow_vrfitem primary key nonclustered
	(
		orgcode,posno,sdate,stime,serialno,trantype,pageno,itemno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_flow_vrfpay') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_flow_vrfpay

create table t_flow_vrfpay (
	orgcode varchar(10) not null,
	posno varchar(6) not null,
	sdate varchar(10) not null,
	stime varchar(8) not null,
	serialno varchar(50) not null,
	trantype varchar(1) not null,
	itemno varchar(4) not null,
	accdate varchar(10) null,
	cshcode varchar(6) not null,
	payflag varchar(4) not null,
	amount numeric(19,4) not null default(0),
	payamount numeric(19,4) not null default(0),
	payid varchar(100) null,
	alitradeno varchar(100) null,
	tradedate varchar(10) null,
	isbalanced varchar(1) null default(''),
	constraint pk_flow_vrfpay primary key nonclustered
	(
		orgcode,posno,sdate,stime,serialno,trantype,itemno
	)
)
go


if exists (select * from sysobjects where id = OBJECT_ID(N't_int_flow_item') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
    drop table t_int_flow_item

create table t_int_flow_item (
	PosNo varchar(6)  not null,
	OrgCode varchar(10)  not null,
	SDate varchar(10)  not null,
	STime varchar(8)  not null,
	SerialNo varchar(50)  not null,
	PageNo varchar(2)  not null,
	ItemNo varchar(5)  default '' not null,
	TranType varchar(1)  not null,
	CshCode varchar(6)  null,
	clkcode varchar(6)  null,
	ItemType varchar(1)  not null,
	PluCode varchar(20)  not null,
	BarCode varchar(20)  null,
	PluName varchar(40)  null,
	DepCode varchar(10)  not null,
	ClsCode varchar(10)  null,
	PluPrice numeric(19,4) default 0 not null,
	PluQty numeric(19,4) default 0 not null,
	PluDsc numeric(19,4) default 0 not null,
	PluTotal numeric(19,4) default 0 not null,
	PluDscType varchar(1)  null,
	AccDate varchar(10)  null,
	OrderCode varchar(10)  null,
	TradeDate varchar(10)  null,
	IsBalanced varchar(1)  default '' null,
	ColorCode varchar(10)  null,
	ColorName varchar(20)  null,
	SizeCode varchar(10)  null,
	SizeName varchar(20)  null,
	YhPrice numeric(19,4) default 0 not null,
	InputCode varchar(20)  null,
	Remark varchar(250)  null,
	GroupCode varchar(20)  null,
	plunum numeric(19,4) default 1 not null,
	constraint PK_t_int_flow_item primary key nonclustered  (PosNo,SDate,STime,SerialNo,PageNo,ItemNo,TranType,OrgCode)
);
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_int_flow_pay') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
    drop table t_int_flow_pay

create table t_int_flow_pay (
	PosNo varchar(6) not null,
	OrgCode varchar(10) not null,
	SDate varchar(10) not null,
	STime varchar(8) not null,
	SerialNo varchar(50) not null,
	ItemNo varchar(4) not null,
	PayFlag varchar(4) not null,
	TranType varchar(1) not null,
	CshCode varchar(6) not null,
	Amount numeric(19,4) default 0 not null,
	PayAmount numeric(19,4) default 0 not null,
	PayID varchar(100) null,
	AccDate varchar(10) null,
	TradeDate varchar(10) null,
	IsBalanced varchar(1) default '' null,
	AliTradeNo varchar(100) null,
	constraint Pk_t_int_flow_pay primary key nonclustered  (PosNo,SDate,STime,SerialNo,ItemNo,TranType,OrgCode)
);
go 

if exists (select * from sysobjects where id = OBJECT_ID(N't_int_flow_total') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
    drop table t_int_flow_total

create table t_int_flow_total (
	PosNo varchar(6) not null,
	OrgCode varchar(10) not null,
	SDate varchar(10) not null,
	STime varchar(8) not null,
	SerialNo varchar(50) not null,
	TranType varchar(1) not null,
	CshCode varchar(6) not null,
	TotalDsc numeric(19,4) default 0 not null,
	Total numeric(19,4) default 0 not null,
	TotalPay numeric(19,4) default 0 not null,
	[Change] numeric(19,4) default 0 not null,
	CustFlag varchar(1) default 0 null,
	CustCode varchar(20) null,
	AuthNum varchar(10) null,
	MemoStr varchar(10) null,
	Customer varchar(20) null,
	AccDate varchar(10) null,
	TradeDate varchar(10) null,
	IsBalanced varchar(1) default '' null,
	EcwChange numeric(19,4) default 0 not null,
	EBillNo varchar(32) null,
	TaxNo varchar(20) null,
	RoundAmt numeric(19,4) default 0 not null,
	EPosMobile varchar(20) null,
	RtnRefNo varchar(100) null,
	IsRtned varchar(1) default '0' null,
	SendFlg varchar(1) default '0' null,
	Remark varchar(200) null,
	InvCustId varchar(200) null,
	InvCust varchar(200) null,
	DBSign varchar(100) null,
	shiftno varchar(20) null,
	constraint Pk_t_int_flow_total primary key nonclustered  (PosNo,SDate,STime,SerialNo,TranType,OrgCode)
);

if exists (select * from sysobjects where id = OBJECT_ID(N't_int_flow_itemdsc') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
    drop table t_int_flow_itemdsc

create table t_int_flow_itemdsc(
  posno varchar(6) not null,
  orgcode varchar(10) not null,
  sdate varchar(10) not null,
  stime varchar(8) not null,
  serialno varchar(20) not null,
  pageno varchar(2) not null,
  itemno varchar(5) not null,
  plucode varchar(20) not null,
  itemdscno varchar(5) not null,
  trantype varchar(1) not null,
  pludsc numeric(19,4) not null default(0),
  pludsctype varchar(2) null,
  dscbillno varchar(20) null,
  accdate varchar(10) null,
  tradedate varchar(10) null,
  orderstatus varchar(1) not null default ('1')
  constraint [REDACTED]primary key nonclustered
  (
    posno,sdate,stime,serialno,pageno,itemno,trantype,orgcode,itemdscno
  ) 
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_plusale_yyyymm') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_plusale_yyyymm

create table t_plusale_yyyymm (
	accdate varchar(10) not null,
	orgcode varchar(10) not null,
	depcode varchar(10) not null,
	plucode varchar(20) not null,
	supcode varchar(15) null,
	counts numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	amount numeric(19,4) not null default(0),
	netamount numeric(19,4) not null default(0),
	normaldsc numeric(19,4) not null default(0),
	vipdsc numeric(19,4) not null default(0),
	pricedsc numeric(19,4) not null default(0),
	grossprofit numeric(19,4) not null default(0),
	netprofit numeric(19,4) not null default(0),
	adjustprofit numeric(19,4) not null default(0),
	netadjustprofit numeric(19,4) not null default(0),
	pstotal numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	staxrate int not null default(0),
	plutype varchar(1) null,
	constraint pk_plusale_yyyymm primary key nonclustered
	(
		accdate,orgcode,depcode,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_plusale_sup_yyyymm') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_plusale_sup_yyyymm

create table t_plusale_sup_yyyymm (
	accdate varchar(10) not null,
	orgcode varchar(10) not null,
	depcode varchar(10) not null,
	plucode varchar(20) not null,
	supcode varchar(15) not null,
	counts numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	amount numeric(19,4) not null default(0),
	netamount numeric(19,4) not null default(0),
	normaldsc numeric(19,4) not null default(0),
	vipdsc numeric(19,4) not null default(0),
	pricedsc numeric(19,4) not null default(0),
	grossprofit numeric(19,4) not null default(0),
	netprofit numeric(19,4) not null default(0),
	adjustprofit numeric(19,4) not null default(0),
	netadjustprofit numeric(19,4) not null default(0),
	pstotal numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	staxrate int not null default(0),
	plutype varchar(1) null,
	constraint [REDACTED]primary key nonclustered
	(
		accdate,orgcode,depcode,plucode,supcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_plusale_ass_yyyymm') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_plusale_ass_yyyymm

create table t_plusale_ass_yyyymm (
	accdate varchar(10) not null,
	orgcode varchar(10) not null,
	depcode varchar(10) not null,
	plucode varchar(20) not null,
	asscode varchar(20) not null,
	supcode varchar(15) null,
	counts numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	amount numeric(19,4) not null default(0),
	netamount numeric(19,4) not null default(0),
	normaldsc numeric(19,4) not null default(0),
	vipdsc numeric(19,4) not null default(0),
	pricedsc numeric(19,4) not null default(0),
	grossprofit numeric(19,4) not null default(0),
	netprofit numeric(19,4) not null default(0),
	adjustprofit numeric(19,4) not null default(0),
	netadjustprofit numeric(19,4) not null default(0),
	pstotal numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	staxrate int not null default(0),
	plutype varchar(1) null,
	constraint [REDACTED]primary key nonclustered
	(
		accdate,orgcode,depcode,plucode,asscode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_depsale_yyyy') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_depsale_yyyy

create table t_depsale_yyyy (
	accdate varchar(10) not null,
	orgcode varchar(10) not null,
	depcode varchar(10) not null,
	counts numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	amount numeric(19,4) not null default(0),
	netamount numeric(19,4) not null default(0),
	normaldsc numeric(19,4) not null default(0),
	vipdsc numeric(19,4) not null default(0),
	pricedsc numeric(19,4) not null default(0),
	grossprofit numeric(19,4) not null default(0),
	netprofit numeric(19,4) not null default(0),
	adjustprofit numeric(19,4) not null default(0),
	netadjustprofit numeric(19,4) not null default(0),
	depcount numeric(19,4) not null default(0),
	depamount numeric(19,4) not null default(0),
	depnetamount numeric(19,4) not null default(0),
	depnormaldsc numeric(19,4) not null default(0),
	depvipdsc numeric(19,4) not null default(0),
	tag varchar(1) null,
	constraint pk_depsale_yyyy primary key nonclustered
	(
		accdate,orgcode,depcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_cshsum_yyyy') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_cshsum_yyyy

create table t_cshsum_yyyy (
	accdate varchar(10) not null,
	orgcode varchar(10) not null,
	posno varchar(6) not null,
	cshcode varchar(6) not null,
	salecnt int not null default(0),
	saleamt numeric(19,4) not null default(0),
	returncnt int not null default(0),
	returnamt numeric(19,4) not null default(0),
	voidcnt int not null default(0),
	voidamt numeric(19,4) not null default(0),
	dsccnt int not null default(0),
	dscamt numeric(19,4) not null default(0),
	djcnt int not null default(0),
	djamt numeric(19,4) not null default(0),
	tdjcnt int not null default(0),
	tdjamt numeric(19,4) not null default(0),
	sqkcnt int not null default(0),
	sqkamt numeric(19,4) not null default(0),
	sqyhcnt int not null default(0),
	sqyhamt numeric(19,4) not null default(0),
	vipcnt int not null default(0),
	vipdscamt numeric(19,4) not null default(0),
	vipamt numeric(19,4) not null default(0),
	ckamt numeric(19,4) not null default(0),
	tend0amt numeric(19,4) not null default(0),
	tend1amt numeric(19,4) not null default(0),
	tend2amt numeric(19,4) not null default(0),
	tend3amt numeric(19,4) not null default(0),
	tend4amt numeric(19,4) not null default(0),
	tend5amt numeric(19,4) not null default(0),
	tend6amt numeric(19,4) not null default(0),
	tend7amt numeric(19,4) not null default(0),
	tend8amt numeric(19,4) not null default(0),
	tend9amt numeric(19,4) not null default(0),
	tend10amt numeric(19,4) not null default(0),
	tend11amt numeric(19,4) not null default(0),
	tend12amt numeric(19,4) not null default(0),
	tend13amt numeric(19,4) not null default(0),
	tenddamt numeric(19,4) not null default(0),
	tendeamt numeric(19,4) not null default(0),
	tendfamt numeric(19,4) not null default(0),
	tendjamt numeric(19,4) not null default(0),
	tendmamt numeric(19,4) not null default(0),
	tendqamt numeric(19,4) not null default(0),	
	tendtamt numeric(19,4) not null default(0),
	tenduamt numeric(19,4) not null default(0),
	tendvamt numeric(19,4) not null default(0),
	tendwamt numeric(19,4) not null default(0),
	tendxamt numeric(19,4) not null default(0),
	tendyamt numeric(19,4) not null default(0),
	tendzamt numeric(19,4) not null default(0),
	plucnt int not null default(0),
	salecount numeric(19,4) not null default(0),
	tag varchar(1) null,	
	constraint pk_cshsumyyyy primary key nonclustered
	(
		accdate,orgcode,posno,cshcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_clksum_yyyy') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_clksum_yyyy

create table t_clksum_yyyy (
	accdate varchar(10) not null,
	orgcode varchar(10) not null,
	posno varchar(6) not null,
	clkcode varchar(6) not null,
	depcode varchar(10) null,
	salecnt int not null default(0),
	saleamt numeric(19,4) not null default(0),
	returncnt int not null default(0),
	returnamt numeric(19,4) not null default(0),
	voidamt numeric(19,4) not null default(0),
	dsccnt int not null default(0),
	dscamt numeric(19,4) not null default(0),
	vipcnt int not null default(0),
	vipdscamt numeric(19,4) not null default(0),
	vipamt numeric(19,4) not null default(0),
	tag varchar(1) null,
	constraint pk_clksum_yyyy primary key nonclustered
	(
		accdate,orgcode,posno,clkcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_loyalty_plu') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_loyalty_plu

create table t_loyalty_plu (
	serialno varchar(10) not null,
	plucode varchar(20) not null,
	barcode varchar(20) not null,
	pluname varchar(40) null,
	newprice numeric(19,4) not null default(0),
	bgndate varchar(10) null,
	enddate varchar(10) null,
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	usercode varchar(6) null,
	username varchar(10) null,
	constraint pk_loyalty_plu primary key nonclustered
	(
		serialno,plucode,barcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_loyalty_org') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_loyalty_org

create table t_loyalty_org (
	serialno varchar(10) not null,
	orgcode varchar(10) not null,
	prntimes int not null default(0),
	constraint pk_loyalty_org primary key nonclustered
	(
		serialno,orgcode
	)
)
go


--05 促销

if exists (select * from sysobjects where id = OBJECT_ID(N't_prom_data') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_prom_data

create table t_prom_data (
	serialno int not null identity(1,1),
	plucode varchar(20) not null,
	pluname varchar(40) null,
	promprice numeric(19,4) not null default(0),
	promname varchar(100) null,
	promdesc varchar(100) null,
	promrange varchar(1000) null,
	bgndate varchar(10) null,
	enddate varchar(10) null,
	orderdate varchar(10) null,
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	usercode varchar(6) null,
	username varchar(10) null,	
	constraint pk_prom_data primary key nonclustered
	(
		serialno
	)
)
go


--06 生鲜

if exists (select * from sysobjects where id = OBJECT_ID(N't_mix_entry') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_mix_entry

create table t_mix_entry (
	mixcode varchar(10) not null,
	mixname varchar(40) null,
	assamount numeric(19,4) not null default(0),
	assmemo varchar(20) null,
	constraint pk_mix_entry primary key nonclustered
	(
		mixcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_mix_stuff') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_mix_stuff

create table t_mix_stuff (
	mixcode varchar(10) not null,
	plucode varchar(20) not null,
	counts numeric(19,4) not null default(0),
	constraint pk_mix_stuff primary key nonclustered
	(
		mixcode,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_mix_product') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_mix_product

create table t_mix_product (
	mixcode varchar(10) not null,
	plucode varchar(20) not null,
	counts numeric(19,4) not null default(0),
	costrate int not null default(0),
	constraint pk_mix_product primary key nonclustered
	(
		mixcode,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_produce_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_produce_head

create table t_produce_head (
	billno varchar(20) not null,
	orgcode varchar(10) not null,
	bizdate varchar(10) null,
	mixcode varchar(10) null,
	place varchar(1) not null default('0'),
	counts numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	asstotal numeric(19,4) not null default(0),
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null default(0),
	tag varchar(2) null,
	timemark timestamp null,
	remark varchar(200) null,
	constraint pk_produce_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_produce1_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_produce1_body

create table t_produce1_body (
	billno varchar(20) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	unit varchar(10) null,
	price numeric(19,4) not null default(0),
	counts numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	tag varchar(1) null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_produce1_body primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_produce2_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_produce2_body

create table t_produce2_body (
	billno varchar(20) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	counts numeric(19,4) not null default(0),
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	tag varchar(1) null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_produce2_body primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go


--08 配送

if exists (select * from sysobjects where id = OBJECT_ID(N't_area') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_area

create table t_area (
	areacode varchar(10) not null,
	areaname varchar(20) not null,
	uppercode1 varchar(20) null,
	uppercode2 varchar(20) null,
	uppercode3 varchar(20) null,
	uppercode4 varchar(20) null,
	arealevel int null,
	tmcode varchar(6) null,
	tmname varchar(10) null,
	chgdate varchar(20) null,
	remark varchar(200) null,
	constraint pk_area primary key nonclustered
	( 
		areacode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_cmpany') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_cmpany

create table t_cmpany (
	cmpcode varchar(10) not null,
	cmpname varchar(20) not null,
	finacode varchar(10) null,
	remark varchar(200) null,
	constraint pk_cmpany primary key nonclustered
	( 
		cmpcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_cmpany_shop') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_cmpany_shop

create table t_cmpany_shop (
	cmpcode varchar(10) not null,
	orgcode varchar(10) not null,
	shoptype varchar(1) not null, -- 0-总部 1-门店
	remark varchar(200) null,
	constraint pk_cmpany_shop primary key nonclustered
	( 
		cmpcode,orgcode,shoptype
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N' t_financial_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
     drop table t_financial_body

create table t_financial_body (
	finacode varchar(10) not null,
	finaname varchar(40) not null,
	finatype varchar(1) not null default('0'),
	uppercode varchar(10) null,
	supcode varchar(15) null,
	remark varchar(200) null,
	constraint pk_financial_body primary key nonclustered
	( 
		finacode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_shop') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_shop

create table t_shop (
	orgcode varchar(10) not null,
	orgname varchar(30) not null,
	orgtype varchar(1) not null default('0'),
	isdbdeploy varchar(1) not null default('1'),
	isconfirm varchar(1) not null default('0'),
	isdbconfirm varchar(1) not null default('0'),
	mngcsstock varchar(1) not null default('0'),
	calctype varchar(1) not null default('0'),
	sjrate numeric(19,4) not null default(0),
	ip varchar(60) null,
	portno int null default('0'),
	http varchar(40) null,
	email varchar(40) null,
	ftp varchar(40) null,
	tel varchar(20) null,
	fax varchar(20) null,
	addr varchar(200) null,
	linkman varchar(20) null,
	area int not null default(0),
	areacode varchar(6) null,
	finacode varchar(10) null,
	shoptype varchar(6) null,
	shoptype2 varchar(100) null,
	shoptype3 varchar(100) null,
	city varchar(20) null,
	zpamount numeric(19,4) not null default(0),
	zpthamount numeric(19,4) not null default(0),
	zsamount numeric(19,4) not null default(0),
	zsthamount numeric(19,4) not null default(0),
	jsamount numeric(19,4) not null default(0),
	prepayamount numeric(19,4) not null default(0),
	mngplubycenter varchar(1) not null default('0'),
	jpricerule varchar(1) not null default('0'),
	mngbin varchar(1) not null default('0'),
	accepttimes varchar(1) not null default('0'),
	isaccept varchar(1) not null default('0'),
	isreturn varchar(1) not null default('0'),
	param1 varchar(10) null,
	chgdate varchar(20) null,
	overdate varchar(10) null,
	overtimes int null,
	inibk varchar(30) null,
	status varchar(1) not null default('0'),
	remark varchar(200) null,
	constraint pk_shop primary key nonclustered
	(
		orgcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N' t_shop_attr') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
     drop table t_shop_attr

create table t_shop_attr (
    orgcode varchar(10) not null,
	attrcode varchar(20) not null,
	attrname varchar(40) null,
	remark varchar(200) null,
	constraint pk_shop_attr primary key nonclustered
	( 
		orgcode,attrcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_dist_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_dist_head

create table t_dist_head (
	billno varchar(20) not null,
	orgcode varchar(10) not null,
	shopcode varchar(10) not null,
	askno varchar(20) null,
	bigorderno varchar(20) null,
	sqauremode varchar(1) not null default('0'),
	paydate varchar(10) null,
	zpcount numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	zpamount numeric(19,4) not null default(0),
	zpnetamount numeric(19,4) not null default(0),
	pickstate varchar(1) not null default('0'),
	diststate varchar(1) not null default('0'),
	differstate varchar(1) not null default('0'),
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null default(0),
	tag varchar(2) null,
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_dist_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_dist_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_dist_body

create table t_dist_body (
	billno varchar(20) not null,
	serialno int not null default(1),	
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	punit varchar(10) null,
	itemcnt numeric(19,4) not null default(0),
	pcount numeric(19,4) not null default(0),
	sglcount numeric(19,4) not null default(0),
	zpcount numeric(19,4) not null default(0),
	ornzpcount numeric(19,4) not null default(0),
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	ispsprice varchar(1) not null default('0'),
	zpprice numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	zpamount numeric(19,4) not null default(0),
	zpnetamount numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	staxrate int not null default(0),
	supcode varchar(15) null,
	pickingno varchar(20) null,
	boxno varchar(20) null,
	depcode varchar(10) null,
	depname varchar(16) null,
	askbillno varchar(200) null,
	remark varchar(200) null,
	constraint pk_dist_body primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_distms_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_distms_head

create table t_distms_head (
	billno varchar(20) not null,
	orgcode varchar(10) not null,
	sqauremode varchar(1) not null default('0'),
	paydate varchar(10) null,
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null default(0),
	timemark timestamp not null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_distms_head primary key nonclustered 
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_distms_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_distms_body

create table t_distms_body (
	billno varchar(20) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,	
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	punit varchar(10) null,
	itemcnt numeric(19,4) not null default(0),
	pcount numeric(19,4) not null default(0),
	sglcount numeric(19,4) not null default(0),
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	psprice numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_distms_body primary key nonclustered 
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_distdiffer_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
  drop table t_distdiffer_head
create table t_distdiffer_head (
	billno varchar(20) not null,
	ywbillNo varchar(20) not null,
	orgcode varchar(10) not null,
	bizdate varchar(10) null,
	differtype varchar(1) not null default('0'),
	contrno varchar(40) null,
	differcount numeric(19,4) not null default(0),
	differcost numeric(19,4) not null default(0),
	differnetcost numeric(19,4) not null default(0),
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null default(0),
	tag varchar(2) null,
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_distdiffer_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_distdiffer_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_distdiffer_body

create table t_distdiffer_body (
	billno varchar(20) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	pluname varchar(40) null,
	barcode varchar(20) null,
	supcode varchar(15) null,
	price numeric(19,4) not null default(0), 
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	counts numeric(19,4) not null default(0),
	differcount numeric(19,4) not null default(0),
	differcost numeric(19,4) not null default(0),
	differnetcost numeric(19,4) not null default(0),
	differmode varchar(1) not null default(''),
	genbillno varchar(20) null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_distdiffer_body primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

--09 结算

if exists (select * from sysobjects where id = OBJECT_ID(N't_paysoa_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_paysoa_head

create table t_paysoa_head (
	billno varchar(20) not null,
	orgcode varchar(10) not null default('*'),
	finacode varchar(10) not null default('*'),
	paydate varchar(10) null,
	supcode varchar(15) not null,
	supname varchar(100) null,
	contrno varchar(40) null,
	bgndate varchar(10) null,
	enddate varchar(10) null,
	qrdate varchar(10) null,
	qrtime varchar(8) null,
	qrstatus varchar(1) not null default('0'),
	total numeric(19,4) not null default(0),
	jstotal numeric(19,4) not null default(0),
	zrtotal numeric(19,4) not null default(0),
	bcjstotal numeric(19,4) not null default(0),
	feetotal numeric(19,4) not null default(0),
	dztotal numeric(19,4) not null default(0),
	bczrtotal numeric(19,4) not null default(0),
	xscost numeric(19,4) not null default(0),
	xstotal numeric(19,4) not null default(0),
	fktotal numeric(19,4) not null default(0),
	taxamt numeric(19,4) not null default(0), 
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null default(0),
	tag varchar(2) null,
        tag2 varchar(2) null,
	timemark timestamp null,
	remark varchar(200) null,
	constraint pk_paysoa_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_paysoa_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_paysoa_body

create table t_paysoa_body (
	billno varchar(20) not null,
	serialno int not null default(1),
	billtype varchar(1) not null,
	ywbillno varchar(20) not null,
	orgcode varchar(10) not null,
	bizdate varchar(10) null,
	paydate varchar(10) null,
	sqauremode varchar(1) not null default('0'),
	total numeric(19,4) not null default(0),
	jstotal numeric(19,4) not null default(0),
	zrtotal numeric(19,4) not null default(0),
	bcjstotal numeric(19,4) not null default(0),
	bczrtotal numeric(19,4) not null default(0),
	tag varchar(1) null,
	remark varchar(200) null,
	constraint pk_paysoa_body primary key nonclustered 
	(
		billno,serialno,billtype,ywbillno,orgcode
	)
)
GO

if exists (select * from sysobjects where id = OBJECT_ID(N't_paysoa_tax') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_paysoa_tax

create table t_paysoa_tax (
	billno varchar(20) not null,
	jtaxrate int not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	taxamt numeric(19,4) not null default(0),
	constraint pk_paysoa_tax primary key nonclustered 
	(
		billno,jtaxrate
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_paysoa_clause') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_paysoa_clause

create table t_paysoa_clause (
	billno varchar(20) not null,
	serialno int not null default(1),
	contrno varchar(40) not null,
	supcode varchar(15) not null,
	orgcode varchar(10) not null,
	itemcode varchar(4) not null,
	itemno varchar(10) not null,
	basetype varchar(4) not null default('00'),
	feetotal numeric(19,4) not null default(0),
	clausefee numeric(19,4) not null default(0),
	ratebase numeric(19,4) not null default(0),
	feerate numeric(19,4) not null default(0),
	cltype varchar(1) not null default('2'),
	cldate varchar(20) null,
	zftype varchar(1) not null default('1'),
	iscalprofit varchar(1) not null default('0'),
	calmode varchar(1) not null default('0'),
	calbgndate varchar(10) null,
	calenddate varchar(10) null,
	isinvoice varchar(1) not null default('0'),
	clausetype varchar(1) not null default('0'),
	tendcode varchar(10) null,
	plucode varchar(20) null,
	clscode varchar(10) null,
	brandcode varchar(10) null,
	isladderrate varchar(1) not null default('0'),
	laddercaltype varchar(1) not null default('0'),
	ext1 varchar(500) null,
	ext2 varchar(500) null,
	ext3 varchar(500) null,
	ext4 varchar(500) null,
	ext5 varchar(500) null,
	midclscode varchar(10) null,
	remark varchar(200) null,
	constraint pk_paysoa_clause primary key nonclustered 
	(
		billno,serialno
	)
)

if exists (select * from sysobjects where id = OBJECT_ID(N't_paysoa_fee') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_paysoa_fee

create table t_paysoa_fee (
	billno varchar(20) not null,
	feeno int not null,
	feecode varchar(4) not null,
	feename varchar(20) not null,
	bgndate varchar(10) not null,
	enddate varchar(10) not null,
	feetotal numeric(19,4) not null,
	clausetype varchar(1) not null,
	cltype varchar(1) not null,
	clcount int not null,
	remark varchar(200) null,
	constraint pk_paysoa_fee primary key nonclustered
	(
		billno,feeno,feecode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_jopaysoa_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_jopaysoa_head

create table t_jopaysoa_head (
	billno varchar(20) not null,
	orgcode varchar(10) not null default('*'),
	finacode varchar(10) not null default('*'),
	paydate varchar(10) null,
	supcode varchar(15) not null default(''),
	supname varchar(100) null,
	contrno varchar(40) null,
	bgndate varchar(10) null,
	enddate varchar(10) null,
	qrdate varchar(10) null,
	qrtime varchar(8) null,
	qrstatus varchar(1) not null default('0'),
	serialno int not null default(0),
	amount numeric(19,4) not null default(0),
	tctotal numeric(19,4) not null default(0),
	bcjstotal numeric(19,4) not null default(0),
	feetotal numeric(19,4) not null default(0),
	dztotal numeric(19,4) not null default(0),
	bczrtotal numeric(19,4) not null default(0),
	fktotal numeric(19,4) not null default(0),
	taxamt numeric(19,4) not null default(0),
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) null,
	prntimes int null default(0),
	tag varchar(1) null,
	timemark timestamp null,
	remark varchar(200) null,
	constraint pk_jopaysoa_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_jopaysoa_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_jopaysoa_body

create table t_jopaysoa_body (
	billno varchar(20) not null,
	serialno int not null default(1),
	orgcode varchar(10) not null,
	accdate varchar(10) not null,
	total numeric(19,4) not null default(0),
	amount numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	tctotal numeric(19,4) not null default(0),
	remark varchar(200) null,
	constraint pk_jopaysoa_body primary key nonclustered
	(
		billno,serialno,orgcode,accdate
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_jopaysoa_tax') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_jopaysoa_tax

create table t_jopaysoa_tax (
	billno varchar(20) not null,
	staxrate int not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	taxamt numeric(19,4) not null default(0),
	constraint pk_jopaysoa_tax primary key nonclustered 
	(
		billno,staxrate
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_jopaysoa_fee') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_jopaysoa_fee

create table t_jopaysoa_fee (
	billno varchar(20) not null,
	feeno int not null,
	feecode varchar(4) not null,
	feename varchar(20) not null,
	bgndate varchar(10) not null,
	enddate varchar(10) not null,
	feetotal numeric(19,4) not null default(0),
	clausetype varchar(1) not null,
	cltype varchar(1) not null,
	clcount int not null default(0),
	remark varchar(200) null,
	constraint pk_jopaysoa_fee primary key nonclustered
	(
		billno,feeno,feecode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pay_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pay_head

create table t_pay_head (
	billno varchar(20) not null,
	paydate varchar(10) null,
	supcode varchar(15) not null,
	supname varchar(100) null,
	paytype varchar(1) not null default('0'),
	payapplyno varchar(20) null,
	bank varchar(100) null,
	account varchar(40) null,
	taxcode varchar(30) null,
	pretotal numeric(19,4) not null default(0),
	bcjstotal numeric(19,4) not null default(0),
	bczrtotal numeric(19,4) not null default(0),
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,	
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null default(0),
	tag varchar(2) null,
	timemark timestamp null,
	remark varchar(200) null,
	constraint pk_pay_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pay_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pay_body

create table t_pay_body (
	billno varchar(20) not null,
	paysoano varchar(20) not null,
	dzdate varchar(10) null,
	dztotal numeric(19,4) not null default(0),
	jstotal numeric(19,4) not null default(0),
	bcjstotal numeric(19,4) not null default(0),
	remark varchar(200) null,
	constraint pk_pay_body primary key nonclustered 
	(
		billno,paysoano
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_payapply_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_payapply_head

create table t_payapply_head (
	billno varchar(20) not null,
	paydate varchar(10) null,
	supcode varchar(15) not null,
	supname varchar(100) null,
	contrno varchar(40) null,
	orderno varchar(20) null,
	pretotal numeric(19,4) not null default(0),
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null default(0),
	tag varchar(2) null,
	timemark timestamp null,
	remark varchar(200) null,
	constraint pk_payapply_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_whprepay_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_whprepay_head

create table t_whprepay_head (
	billno varchar(20) not null,
	orgcode varchar(10) not null,
	bizdate varchar(10) null,
	custcode varchar(15) null,
	custname varchar(30) null,
	ftflag varchar(1) not null default('0'),
	paytotal numeric(19,4) not null default(0),
	paydate varchar(10) null,
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null default(0),
	tag varchar(2) null,
	timemark timestamp null,
	remark varchar(200) null,
	constraint pk_whprepay_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_whpay_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_whpay_head

create table t_whpay_head (
	billno varchar(20) not null,
	orgcode varchar(10) not null,
	custcode varchar(15) null,
	custname varchar(30) null,
	paydate varchar(10) null,
	yqtotal numeric(19,4) not null default(0),
	paytotal numeric(19,4) not null default(0),
	zrtotal numeric(19,4) not null default(0),	
	prepay numeric(19,4) not null default(0),
	sumpaytotal numeric(19,4) not null default(0),
	islastcust varchar(1) not null default('1'),
	voucherimg varchar(400) null,
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null default(0),
	tag varchar(2) null,
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_whpay_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_whpay_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_whpay_body

create table t_whpay_body (
	billno varchar(20) not null,
	billtype varchar(1) not null default('0'),	
	pfsaleno varchar(20) not null,
	pfsaledate varchar(10) null,
	sqauremode varchar(1) not null default('0'),	
	paydate varchar(10) null,
	custcode varchar(15) not null default(''),
	yqtotal numeric(19,4) not null default(0),
	paytotal numeric(19,4) not null default(0),
	zrtotal numeric(19,4) not null default(0),	
	tag varchar(1) null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,	
	constraint pk_whpay_body primary key nonclustered
	(
		billno,pfsaleno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_whpay_tend') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_whpay_tend

create table t_whpay_tend (
	billno varchar(20) not null,
	itemno varchar(10) not null,
	payflag varchar(4) not null,
	payid varchar(20) null,
	amount numeric(19,4) not null default(0),	
	payamount numeric(19,4) not null default(0),	
	remark varchar(200) null,
	constraint pk_whpay_tend primary key nonclustered
	(
		billno,itemno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_distpay_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_distpay_head

create table t_distpay_head (
	billno varchar(20) not null,
	billtype varchar(1) not null,
	orgcode varchar(10) not null,
	orgname varchar(30) null,
	shopcode varchar(10) not null,
	shopname varchar(30) null,
	jsdate varchar(10) not null,
	zpamount numeric(19,4) not null default(0),
	jsamount numeric(19,4) not null default(0),
	zramount numeric(19,4) not null default(0),
	prepayamount numeric(19,4) not null default(0),
	skamount numeric(19,4) not null default(0),	
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) null default('0'),
	prntimes int null default(0),	 
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_distpay_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_distpay_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_distpay_body

create table t_distpay_body (
	billno varchar(20) not null,
	billtype varchar(1) not null default('0'),
	zpbillno varchar(20) not null,
	psdate varchar(10) null,
	sqauremode varchar(1) null,
	zpamount numeric(19,4) not null default(0),
	jsamount numeric(19,4) not null default(0),
	zramount numeric(19,4) not null default(0),
	remark varchar(200) null,
	constraint pk_distpay_body primary key nonclustered
	(
		billno,billtype,zpbillno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pay_bill') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pay_bill

create table t_pay_bill (
	billtype varchar(1) not null default('0'),
	billno varchar(20) not null,
	orgcode varchar(10) not null default(''),
	bizdate varchar(10) null,
	paydate varchar(10) null,
	supcode varchar(15) null,
	contrno varchar(40) null,
	sqauremode varchar(1) not null default('0'),
	cost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	jscost numeric(19,4) not null default(0),
	zrcost numeric(19,4) not null default(0),
	isaccounted varchar(1) not null default('0'),
	isfinished varchar(1) not null default('0'),
	constraint pk_pay_bill primary key nonclustered
	(
		billtype,billno,orgcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_distpay_bill') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_distpay_bill

create table t_distpay_bill (
	billtype varchar(1) not null default('0'),
	billno varchar(20) not null,
	shopcode varchar(10) not null,
	orgcode varchar(10) not null,
	rzdate varchar(10) not null,
	sqauremode varchar(1) not null default('0'),
	zpamount numeric(19,4) not null default(0),
	jsamount numeric(19,4) not null default(0),
	zramount numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	isfinished varchar(1) not null default('0'),
	constraint pk_distpay_bill primary key nonclustered
	(
		billtype,billno,shopcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_fee') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_fee

create table t_fee (
	feecode varchar(4) not null,
	feename varchar(20) not null,
	remark varchar(200) null,
	constraint pk_fee primary key nonclustered
	(
		feecode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_supsale_detail') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_supsale_detail

create table t_supsale_detail (
	billno varchar(20) not null default('*'),
	orgcode varchar(10) not null,
	orgname varchar(30) null,
	supcode varchar(15) not null,
	supname varchar(100) null,
	suptype varchar(1) not null,
	datatype varchar(1) not null,
	accdate varchar(10) not null,
	acctimes int not null,
	serialno numeric(19,0) not null default(0),
	plucode varchar(20) not null,
	pluname varchar(40) null,
	counts numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	isfinished varchar(1) not null default('0'),
	remark varchar(200) null,
	constraint pk_supsale_detail primary key nonclustered
	(
		billno,orgcode,supcode,datatype,accdate,acctimes,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_vbk_yyyymm') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_vbk_yyyymm

create table t_vbk_yyyymm (
	orgcode varchar(10) not null,
	bookdate varchar(10) not null,
	booktime varchar(8) not null,
	supcode varchar(15) not null,
	billno varchar(20) not null,
	billtype varchar(1) not null,
	fsamount numeric(19,4) not null default(0),
	yfjytotal numeric(19,4) not null default(0),
	prejytotal numeric(19,4) not null default(0),
	tag varchar(1) not null,
	serialno int not null identity(1,1),
	constraint pk_vbk_yyyymm primary key nonclustered
	(
		bookdate,booktime,supcode,billno,billtype
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_jopay_salerpt_yyyy') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_jopay_salerpt_yyyy

create table t_jopay_salerpt_yyyy (
	accdate varchar(10) not null,
	orgcode varchar(10) not null,
	supcode varchar(15) not null,
	serialno int not null default(1),
	total numeric(19,4) not null default(0),
	amount numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	tctotal numeric(19,4) not null default(0),
	isfinished varchar(1) not null default('0'),
	constraint [REDACTED]primary key nonclustered
	(
		accdate,orgcode,supcode,serialno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_jopay_saleplu_yyyy') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_jopay_saleplu_yyyy

create table t_jopay_saleplu_yyyy (
	accdate varchar(10) not null,
	orgcode varchar(10) not null,
	plucode varchar(20) not null,
	serialno int not null default(0),
	barcode varchar(20) null,
	pluname varchar(40) null,
	dkrate numeric(19,4) not null default(0),
	xscount numeric(19,4) not null default(0),
	xstotal numeric(19,4) not null default(0),
	xsamount numeric(19,4) not null default(0),
	xscost numeric(19,4) not null default(0),
	xsnetcost numeric(19,4) not null default(0),
	depcode varchar(10) null,
	depname varchar(20) null,
	clscode varchar(10) null,
	clsname varchar(20) null,
	supcode varchar(15) null,
	supname varchar(100) null,
	brandcode varchar(10) null,
	brandname varchar(20) null,
	jtaxrate int not null default(0),
	staxrate int not null default(0),
	remark varchar(200) null,
	constraint [REDACTED]primary key nonclustered
	(
		accdate,orgcode,plucode,serialno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_invoice_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
  drop table t_invoice_head
create table t_invoice_head (
  billno varchar(20)  not null,
  paysoano varchar(20)  not null,
  supcode varchar(15)  not null,
  supname varchar(100)  null,
  contrno varchar(40)  not null,
  contrname varchar(30)  null,
  salename varchar(100)  null,
  saletaxno varchar(100)  null,
  lrdate varchar(10)  null,
  lrtime varchar(8)  null,
  rzdate varchar(10)  null,
  rztime varchar(8)  null,
  chkdate varchar(10)  null,
  chktime varchar(8)  null,
  usercode varchar(6)  null,
  username varchar(10)  null,
  zdrcode varchar(6)  null,
  zdrname varchar(10)  null,
  shrcode varchar(6)  null,
  shrname varchar(10)  null,
  chkstatus varchar(1)  default '0' not null,
  chkmsg varchar(200)  null,
  timemark timestamp null,
  remark varchar(200)  null,
  tag varchar(2) null,
  constraint pk_invoice_head primary key (billno)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_invoice_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
  drop table t_invoice_body
create table t_invoice_body (
  id bigint not null,
  billno varchar(20)  not null,
  serialno bigint not null,
  invtype varchar(1)  default '0' not null,
  invcode varchar(100)  null,
  invno varchar(40)  not null,
  invdate varchar(10)  null,
  total numeric(19,4) default 0 not null,
  invtotal numeric(19,4) default 0 not null,
  taxtotal numeric(19,4) default 0 not null,
  constraint pk_invoice_body primary key (id,billno)
);

if exists (select * from sysobjects where id = OBJECT_ID(N't_invoice_discount') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
  drop table t_invoice_discount
create table t_invoice_detail (
  id bigint not null,
  billno varchar(20)  not null,
  invid bigint not null,
  serialno bigint not null,
  biztype varchar(1) not null,
  taxrate int not null,
  total numeric(19,4) default 0 not null,
  invtotal numeric(19,4) default 0 not null,
  taxtotal numeric(19,4) default 0 not null,
  midclscode varchar(10),
  constraint pk_invoice_detail primary key (id,billno)
);

if exists (select * from sysobjects where id = OBJECT_ID(N't_bcbiz_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_bcbiz_head

create table t_bcbiz_head (
	billno varchar(20) not null,
	qrdate varchar(10) null,
	qrtime varchar(8) null,
	qrstatus varchar(1) not null default('0'),
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) null default('0'),
	prntimes int null default(0),
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_bcbiz_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_bcbiz_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_bcbiz_body

create table t_bcbiz_body (
	billno varchar(20) not null,
	serialno int not null default(1),
	orgcode varchar(20) not null,
	supcode varchar(15) not null,
	supname varchar(100) null,
	plucode varchar(20) not null,
	pluname varchar(40) null,
	promquotedate varchar(10) null,
	prombgndate varchar(10) null,
	promenddate varchar(10) null,
	promdesc varchar(100) null,
	promjprice numeric(19,4) null,
	promadjprice numeric(19,4) null,
	promacceptdiff numeric(19,4) null,
	promsalediff numeric(19,4) null,
	staffrtn numeric(19,4) null,
	marketrtn numeric(19,4) null,
	rtnbase numeric(19,4) null,
	rtnthold numeric(19,4) null,
	remark varchar(200) null,
	constraint pk_bcbiz_body primary key nonclustered
	(
		billno,serialno,orgcode,supcode,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_saleblue_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_saleblue_head

create table t_saleblue_head (
	billno varchar(20) not null,
	orgcode varchar(20) not null,
	tradedate varchar(10) null,
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) null default('0'),
	prntimes int null default(0),
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_saleblue_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_saleblue_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_saleblue_body

create table t_saleblue_body (
	billno varchar(20) not null,
	serialno int not null,
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	yhprice numeric(19,4) not null default(0),
	pluqty numeric(19,4) not null default(0),
	pludsc numeric(19,4) not null default(0),
	plutotal numeric(19,4) not null default(0),
	remark varchar(200) null,
	constraint pk_saleblue_body primary key nonclustered
	(
		billno,serialno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_saleblue_body2') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_saleblue_body2

create table t_saleblue_body2 (
	billno varchar(20) not null,
	serialno int not null,
	clscode varchar(10) not null,
	payflag varchar(4) not null,
	amount numeric(19,4) not null default(0),
	remark varchar(200) null,
	constraint pk_saleblue_body2 primary key nonclustered
	(
		billno,serialno
	)
)
go


--10 库存

if exists (select * from sysobjects where id = OBJECT_ID(N't_draw_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_draw_head

create table t_draw_head (
	billno varchar(20) not null,
	orgcode varchar(10) not null,
	bizdate varchar(10) null,
	supcode varchar(15) null,
	billtype varchar(1) not null default('1'),
	place varchar(1) null default('0'),
	funcdepcode varchar(10) null,
	lytype varchar(6) null,
	lyman varchar(20) null,
	purpose varchar(100) null,
	costcenter varchar(100) null,
	counts numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null default(0),
	tag varchar(2) null,
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_draw_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_draw_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_draw_body

create table t_draw_body (
	billno varchar(20) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	punit varchar(10) null,
	itemcnt numeric(19,4) not null default(0),
	pcount numeric(19,4) not null default(0),
	sglcount numeric(19,4) not null default(0),
	counts numeric(19,4) not null default(0),
	orncounts numeric(19,4) not null default(0),
	jprice numeric(19,4) not null default(0),	
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	tag varchar(1) null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_draw_body primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_outtrans_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_outtrans_head

create table t_outtrans_head (
	billno varchar(20) not null,
	orgcode varchar(10) not null,
	bizdate varchar(10) null,
	intransno varchar(20) null,
	isout varchar(1) null,
	makertype varchar(1) null,
	billtype varchar(1) not null,
	outorgcode varchar(10) not null,
	outorgname varchar(30) null,
	inorgcode varchar(10) not null,
	inorgname varchar(30) null,
	place varchar(1) not null default('0'),
	counts numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	qrdate varchar(10) null,
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) null default('0'),
	prntimes int null default(0),
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_outtrans_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_outtrans_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_outtrans_body

create table t_outtrans_body (
	billno varchar(20) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	punit varchar(10) null,
	itemcnt numeric(19,4) not null default(0),
	pcount numeric(19,4) not null default(0),
	sglcount numeric(19,4) not null default(0),
	counts numeric(19,4) not null default(0),
	plancounts numeric(19,4) not null default(0),
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_outtrans_body primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_cut_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_cut_head

create table t_cut_head (
	billno varchar(20) not null,
	orgcode varchar(10) not null,
	bizdate varchar(10) null,
	supcode varchar(15) null,
	place varchar(1) not null default('0'),
	counts numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	totaldiff numeric(19,4) not null default(0),
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) null default('0'),
	prntimes int null default(0),
	tag varchar(2) null,
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_cut_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_cut_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_cut_body

create table t_cut_body (
	billno varchar(20) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	oldprice numeric(19,4) not null default(0),
	newprice numeric(19,4) not null default(0),
	vipprice numeric(19,4) not null default(0),
	counts numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	totaldiff numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	cutplucode varchar(20) null,
	cutbarcode varchar(20) null,
	tag varchar(1) null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_cut_body primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go
if exists (select * from sysobjects where id = OBJECT_ID(N't_damage_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_damage_head

create table t_damage_head (
	billno varchar(20) not null,
	orgcode varchar(10) not null,
	bizdate varchar(10) null,
	jzcounts numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	newcost numeric(19,4) not null default(0),
	newnetcost numeric(19,4) not null default(0),
	cjcost numeric(19,4) not null default(0),
	netcjcost numeric(19,4) not null default(0),
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null default(0),
	tag varchar(2) null,
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_damage_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_damage_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_damage_body

create table t_damage_body (
	billno varchar(20) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	newjprice numeric(19,4) not null default(0),
	newnetjprice numeric(19,4) not null default(0),
	jzcounts numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	newcost numeric(19,4) not null default(0),
	newnetcost numeric(19,4) not null default(0),
	cjcost numeric(19,4) not null default(0),
	netcjcost numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_damage_body primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_scrap_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_scrap_head

create table t_scrap_head (
	billno varchar(20) not null,
	orgcode varchar(10) not null,
	bizdate varchar(10) null,
	place varchar(1) not null default('0'),
	counts numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) null default('0'),
	prntimes int null default(0),
	tag varchar(2) null,
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_scrap_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_scrap_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_scrap_body

create table t_scrap_body (
	billno varchar(20) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	punit varchar(10) null,
	itemcnt numeric(19,4) not null default(0),
	pcount numeric(19,4) not null default(0),
	sglcount numeric(19,4) not null default(0),
	counts numeric(19,4) not null default(0),
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	productdate varchar(10) null,
        qualitydate varchar(10) null,
	bstype varchar(20) null,
	bsreason varchar(20) null,
	bsexplain varchar(200) null,
	tag varchar(1) null,
	depcode varchar(10) null,
	depname varchar(16) null,
	picid varchar(50) null,
	remark varchar(200) null,
	constraint pk_scrap_body primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_scrap_apply_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_scrap_apply_head

create table t_scrap_apply_head (
	billno varchar(20) not null,
	orgcode varchar(10) not null,
	bizdate varchar(10) null,
	place varchar(1) not null default('0'),
	counts numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	scraprate numeric(19,4) not null,
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) null default('0'),
	prntimes int null default(0),
	tag varchar(2) null,
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint [REDACTED]primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_scrap_apply_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_scrap_apply_body

create table t_scrap_apply_body (
	billno varchar(20) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	punit varchar(10) null,
	itemcnt numeric(19,4) not null default(0),
	pcount numeric(19,4) not null default(0),
	sglcount numeric(19,4) not null default(0),
	counts numeric(19,4) not null default(0),
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
        productdate varchar(10) null,
        qualitydate varchar(10) null,
	bstype varchar(20) null,
	bsreason varchar(20) null,
	bsexplain varchar(200) null,
	tag varchar(1) null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint [REDACTED]primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_check_task') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_check_task

create table t_check_task (
 	pdno varchar(20) not null,
 	pdname varchar(200) null,
	orgcode varchar(10) not null,
	stockdate varchar(10) null,
	stocktime varchar(8) null,
	pdstatus varchar(1) not null default('0'),
	pddate varchar(10) null,
	pdtime varchar(8) null,
 	usercode varchar(6) null,
	username varchar(10) null,
	pdtype varchar(1) not null,
	pdmode varchar(1) not null default('0'),
	place varchar(1) not null default('0'),
	plucnt int not null default(0),
	pyplucnt int not null default(0),
	pycount numeric(19,4) not null default(0),
	pycost numeric(19,4) not null default(0),
	pytotal numeric(19,4) not null default(0),
	pkplucnt int not null default(0),
	pkcount numeric(19,4) not null default(0),
	pkcost numeric(19,4) not null default(0),
	pktotal numeric(19,4) not null default(0),
	constraint pk_check_task primary key nonclustered
	(
		pdno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_check_snap') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_check_snap

create table t_check_snap (
	pdno varchar(20) not null,
	plucode varchar(20) not null,
	ocount numeric(19,4) not null default(0),
	pcount numeric(19,4) not null default(0),
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),	
	xscount numeric(19,4) not null default(0),
	upddate varchar(20) null,
	constraint pk_kcpdsnap primary key nonclustered
	(
		pdno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_check_snap_hist') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_check_snap_hist

create table t_check_snap_hist (
	pdno varchar(20) not null,
	plucode varchar(20) not null,
	ocount numeric(19,4) not null default(0),
	pcount numeric(19,4) not null default(0),
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	xscount numeric(19,4) not null default(0),
	upddate varchar(20) null,
	constraint pk_check_snap_hist primary key nonclustered
	(
		pdno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_check_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_check_head

create table t_check_head (
	billno varchar(20) not null,
	orgcode varchar(10) not null,
	billtype varchar(1) not null default('0'),
	pdno varchar(20) not null,	
	place varchar(1) not null default('0'),
	gentype varchar(1) not null default('0'),
	devcode varchar(6) null,
	counts numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null default(0),
	timemark timestamp null,
	remark varchar(200) null,
	constraint pk_check_head primary key nonclustered
	(
		billno
	)
)

create index ix_check_head on t_check_head (pdno)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_check_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_check_body

create table t_check_body (
	billno varchar(20) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	punit varchar(10) null,
	itemcnt numeric(19,4) not null default(0),
	pcount numeric(19,4) not null default(0),
	sglcount numeric(19,4) not null default(0),
	counts numeric(19,4) not null default(0),
	ocount numeric(19,4) not null default(0),
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	depcode varchar(10) null,
	depname varchar(16) null,
	upddate varchar(20) null,
	ykreason varchar(200) null,
	remark varchar(200) null,
	constraint pk_check_body primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_check_alert_point') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_check_alert_point

create table t_check_alert_point (
	grptype varchar(1) not null,
	grpcode varchar(20) not null,
	grpname varchar(30) not null,
	alerttype varchar(1) not null default('0'),
	acount numeric(19,4) not null default(0),
	arate numeric(19,4) not null default(0),
	remark varchar(200) null,
	constraint [REDACTED]primary key nonclustered
	(
		grptype,grpcode,alerttype
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_differ_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_differ_head

create table t_differ_head (
	billno varchar(20) not null,
	orgcode varchar(10) not null,
	bizdate varchar(10) null,
	billtype varchar(1) not null default('0'),
	supcode varchar(15) null,
	place varchar(1) null default('0'),
	ykcount numeric(19,4) not null default(0),
	ykcost numeric(19,4) not null default(0),
	yknetcost numeric(19,4) not null default(0),
	yktotal numeric(19,4) not null default(0),
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null default(0),
	tag varchar(2) null,
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_differ_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_differ_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_differ_body

create table t_differ_body (
	billno varchar(20) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	bookcount numeric(19,4) not null default(0),
	realcount numeric(19,4) not null default(0),
	bookcost numeric(19,4) not null default(0),
	realcost numeric(19,4) not null default(0),
	booknetcost numeric(19,4) not null default(0),
	realnetcost numeric(19,4) not null default(0),
	booktotal numeric(19,4) not null default(0),
	realtotal numeric(19,4) not null default(0),	
	ykcount numeric(19,4) not null default(0),
	ykcost numeric(19,4) not null default(0),
	yknetcost numeric(19,4) not null default(0),
	yktotal numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	tag varchar(1) null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	describe varchar(200) null,
	constraint pk_differ_body primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_chkcard') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_chkcard

create table t_chkcard(
	orgcode varchar(10) not null,
	cardcode varchar(20) not null,
	cardname varchar(40) not null,
	constraint pk_chkcard primary key nonclustered
	(
		orgcode,cardcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_chkcard_plu') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_chkcard_plu

create table t_chkcard_plu (
	orgcode varchar(10) not null,
	cardcode varchar(20) not null,
	serialno int not null default(0),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	spec varchar(40) null,
	colorcode varchar(10) not null default('00'),
	sizecode varchar(10) not null default('00'),
	csbarcode varchar(40) null,
	constraint pk_chkcard_plu primary key nonclustered
	(
		orgcode,cardcode,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pick_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pick_head

create table t_pick_head (
	billno varchar(20) not null,
	orgcode varchar(10) not null,
	bizdate varchar(10) null,
	supcode varchar(15) null,
	counts numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null default(0),
	tag varchar(2) null,
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_pick_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pick_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pick_body

create table t_pick_body (
	billno varchar(20) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	counts numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	tag varchar(1) null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_pick_body primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_put_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_put_head

create table t_put_head (
	billno varchar(20) not null,
	orgcode varchar(10) not null,
	bizdate varchar(10) null,
	supcode varchar(15) null,
	counts numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null default(0),
	tag varchar(2) null,
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_put_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_put_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_put_body

create table t_put_body (
	billno varchar(20) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	counts numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	tag varchar(1) null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_put_body primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_alm_days') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_alm_days

create table t_alm_days (
	almcode varchar(6) not null,
	serialno int not null default(0),
	mindays int not null default(0),
	maxdays int not null default(0),
	predays int not null default(0),
	constraint pk_alm_days primary key nonclustered
	(
		almcode,serialno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_gbk_yyyymm') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_gbk_yyyymm

create table t_gbk_yyyymm (
	orgcode varchar(10) not null,
	serialno int not null identity(1,1),
	accdate varchar(10) null,
	bookdate varchar(10) not null,
	booktime varchar(8) not null,
	depcode varchar(10) null,
	plucode varchar(20) not null,
	billno varchar(20) not null,
	billtype varchar(1) not null,
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	fscount numeric(19,4) not null default(0),
	fscost numeric(19,4) not null default(0),
	fsnetcost numeric(19,4) not null default(0),
	fstotal numeric(19,4) not null default(0),
	jccount numeric(19,4) not null default(0),
	jccost numeric(19,4) not null default(0),
	jcnetcost numeric(19,4) not null default(0),
	jctotal numeric(19,4) not null default(0),
	tag varchar(1) null
	constraint pk_gbk_yyyymm primary key nonclustered
	(
		orgcode,bookdate,booktime,plucode,billno,billtype
	)
 )
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_depsum_yyyy') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_depsum_yyyy

create table t_depsum_yyyy (
	accdate varchar(10) not null,	
	orgcode varchar(10) not null,
	depcode varchar(10) not null,	
	sqcost numeric(19,4) not null default(0),
	sqnetcost numeric(19,4) not null default(0),
	sqtotal numeric(19,4) not null default(0),
	jhcost numeric(19,4) not null default(0),
	jhnetcost numeric(19,4) not null default(0),
	jhtotal numeric(19,4) not null default(0),
	thcost numeric(19,4) not null default(0),
	thnetcost numeric(19,4) not null default(0),
	thtotal numeric(19,4) not null default(0),
	drcost numeric(19,4) not null default(0),
	drnetcost numeric(19,4) not null default(0),
	drtotal numeric(19,4) not null default(0),
	dccost numeric(19,4) not null default(0),
	dcnetcost numeric(19,4) not null default(0),
	dctotal numeric(19,4) not null default(0),
	zpcost numeric(19,4) not null default(0),
	zpnetcost numeric(19,4) not null default(0),
	zptotal numeric(19,4) not null default(0),
	zpamount numeric(19,4) not null default(0),
	ztcost numeric(19,4) not null default(0),
	ztnetcost numeric(19,4) not null default(0),
	zttotal numeric(19,4) not null default(0),
	ztamount numeric(19,4) not null default(0),
	lycost numeric(19,4) not null default(0),
	lynetcost numeric(19,4) not null default(0),
	lytotal numeric(19,4) not null default(0),
	bscost numeric(19,4) not null default(0),
	bsnetcost numeric(19,4) not null default(0),
	bstotal numeric(19,4) not null default(0),
	pycost numeric(19,4) not null default(0),
	pynetcost numeric(19,4) not null default(0),
	pytotal numeric(19,4) not null default(0),
	pkcost numeric(19,4) not null default(0),
	pknetcost numeric(19,4) not null default(0),
	pktotal numeric(19,4) not null default(0),
	xjtotal numeric(19,4) not null default(0),
	xjcost numeric(19,4) not null default(0),
	xjnetcost numeric(19,4) not null default(0),
	tjcost numeric(19,4) not null default(0),
	tjnetcost numeric(19,4) not null default(0),
	tjtotal numeric(19,4) not null default(0),
	tkcost numeric(19,4) not null default(0),
	tknetcost numeric(19,4) not null default(0),
	tktotal numeric(19,4) not null default(0),
	jzcost numeric(19,4) not null default(0),
	jznetcost numeric(19,4) not null default(0),
	xscost numeric(19,4) not null default(0),
	xsnetcost numeric(19,4) not null default(0),
	xstotal numeric(19,4) not null default(0),
	xsamount numeric(19,4) not null default(0),
	dsctotal numeric(19,4) not null default(0),
	pfsalecost numeric(19,4) not null default(0),
	pfsalenetcost numeric(19,4) not null default(0),
	pfsaletotal numeric(19,4) not null default(0),
	pfsaleamount numeric(19,4) not null default(0),
	pfreturncost numeric(19,4) not null default(0),
	pfreturnnetcost numeric(19,4) not null default(0),
	pfreturntotal numeric(19,4) not null default(0),
	pfreturnamount numeric(19,4) not null default(0),
	bqcost numeric(19,4) not null default(0),
	bqnetcost numeric(19,4) not null default(0),
	bqtotal numeric(19,4) not null default(0),
	deptotal numeric(19,4) not null default(0),
	depdsctotal numeric(19,4) not null default(0),
	tag varchar(1) null,
	constraint pk_depsum_yyyy primary key nonclustered
	(
		accdate,orgcode,depcode
	)
)
go


if exists (select * from sysobjects where id = OBJECT_ID(N't_plu_batch') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_plu_batch

create table t_plu_batch (
    batchno varchar(40) not null  default('*'),
    orgcode varchar(10) not null,
    depcode varchar(10) null,
	supcode varchar(15) not null,
	jymode varchar(1) not null default('0'),
	contrno varchar(40) null,
	batchtype varchar(1) not null default('0'),
	billno varchar(20) not null,
	serialno numeric(19,0) not null default(0),
    place varchar(1) not null default('0'),
	plucode varchar(20) not null,
	plutype varchar(1) null,
	srcbatchno varchar(40) not null default('*'),
	stkcount numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
    cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	punit varchar(10) null,
	itemcnt numeric(19,4) not null default(0),
	productdate varchar(10) null,
	jhdate datetime not null,
	emptydate datetime null,
	jhcount numeric(19,4) not null default(0),
	thcount numeric(19,4) not null default(0),
	xscount numeric(19,4) not null default(0),
	othcount numeric(19,4) not null default(0),
	constraint pk_plu_batch primary key nonclustered
	(
		batchno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_batchproc_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_batchproc_head

create table t_batchproc_head (
	billno varchar(20) not null,
    billtype varchar(10) null,
	ywtype varchar(10) null,
	ywbillno varchar(20) not null,
    procdate datetime not null,
    orgcode varchar(10) not null,
    place varchar(1) not null default('0'),
	proccount numeric(19,4) not null default(0),
    cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	usercode varchar(6) null,
	username varchar(10) null,
	accdate varchar(10) null,
	tag varchar(1) null,
	constraint pk_batchproc_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_batchproc_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_batchproc_body

create table t_batchproc_body (
	billno varchar(20) not null,
	serialno numeric(19,0) not null default(0),
    depcode varchar(10) null,
    supcode varchar(15) not null,
    plucode varchar(20) not null,
	pluname varchar(40) null,
	spec varchar(40) null,
	unit varchar(10) null,
    plutype varchar(1) null,
    batchno varchar(40) not null  default('*'),
    srcbatchno varchar(40) not null default('*'),
    contrno varchar(40) null,
    jymode varchar(1) not null default('0'),
    proccount numeric(19,4) not null default(0),
    jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
    cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	refserialno numeric(19,0) not null default(0),
	itemcnt numeric(19,4) not null default(0),
	constraint pk_batchproc_body primary key nonclustered
	(
		billno,serialno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_expiring_plu') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_expiring_plu

create table t_expiring_plu (
	indexno numeric(19,0) not null identity(1,1),
	orgcode varchar(10) not null,
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	spec varchar(40) null,
	unit varchar(10) null,
	productdate varchar(10) null,
	qualitydate varchar(10) null,
	counts numeric(19,4) not null default(0),
	lrdate varchar(10) not null,
	lrtime varchar(8) not null,
	usercode varchar(6) null,
	username varchar(10) null,
	remark varchar(200) null,
	constraint pk_expiring_plu primary key nonclustered
	(
		indexno
	)
)
go


--11 批发

if exists (select * from sysobjects where id = OBJECT_ID(N't_customer') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_customer

create table t_customer (
	custcode varchar(15) not null,
	custname varchar(30) not null,
	mncode varchar(30) not null,
	islast varchar(1) not null default('1'),
	uppercust varchar(15) not null default(''),
	addr varchar(100) null,
	region varchar(15) null,
	zipcode varchar(6) null,
	tel varchar(20) null,
	fax varchar(20) null,
	email varchar(40) null,
	manager varchar(20) null,
	contact varchar(20) null,
	entquality varchar(10) null,
	enttype varchar(10) null,
	bank varchar(30) null,
	account varchar(40) null,
	taxcode varchar(15) null,
	regcode varchar(20) null,
	opendate varchar(10) null,
	ordermode varchar(20) null,
	delivermode varchar(20) null,
	deliveraddr varchar(100) null,
	consignee varchar(100) null,
	consigneetel varchar(20) null,
	mobile1 varchar(20) null,
	mobile2 varchar(20) null,
	pftotal numeric(19,4) not null default(0),
	thtotal numeric(19,4) not null default(0),
	fktotal numeric(19,4) not null default(0),
	prepay numeric(19,4) not null default(0),
	yqflag varchar(1) not null default('0'),
	pfpriceflag varchar(1) not null default('0'),
	zccode varchar(4) null,
	jsetpcode varchar(10) null,
	custtype varchar(10) not null default('-1'),
	bgndate varchar(10) null,
	status varchar(1) not null default('0'),
	chgdate varchar(20) null,
	remark varchar(200) null,
	constraint pk_customer primary key nonclustered
	(
		custcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_whsle_policy') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_whsle_policy

create table t_whsle_policy (
	zccode varchar(4) not null,
	zcname varchar(20) not null,
	priceref varchar(1) not null,
	computemode varchar(1) not null,
	computerate numeric(19,4) not null default(0),
	pricedot int not null default(2),
	remark varchar(200) null,
	constraint pk_whsle_policy primary key nonclustered
	(
		zccode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_whsle_policy_plu') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_whsle_policy_plu

create table t_whsle_policy_plu (
	zccode varchar(4) not null,
	plucode varchar(20) not null,
	pfprice numeric(19,4) not null default(0),
	constraint [REDACTED]primary key nonclustered
	(
		zccode,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_whsle_cust_info') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_whsle_cust_info

create table t_whsle_cust_info
(
	pfsaleno varchar(20) not null,
	custcode varchar(20) not null,
	rzdate varchar(10) not null,
	zdrcode varchar(10) null,
	sqauremode varchar(1) not null,
	plucode varchar(20) not null,
	pfprice numeric(19,4) not null default(0),
	pfcount numeric(19,4) not null default(0),
	zpcount numeric(19,4) not null default(0),
	pftotal numeric(19,4) not null default(0),
	constraint pk_whsle_cust_info primary key nonclustered
	(
		custcode,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_whquote_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_whquote_head

create table t_whquote_head (
	billno varchar(20) not null,
	orgcode varchar(10) not null,
	bizdate varchar(10) null,
	custcode varchar(15) null,
	custname varchar(30) null,
	validdate varchar(10) null,
	sqauremode varchar(1) not null default('0'),
	paydate varchar(10) null,
	place varchar(1) not null default('0'),
	state varchar(1) not null default('0'),
	funcdepcode varchar(10) null,
	counts numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	pftotal numeric(19,4) not null default(0),
	netpftotal numeric(19,4) not null default(0),
	zrtotal numeric(19,4) not null default(0),
	voucherimg varchar(400) null,
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null default(0),
	tag varchar(2) null,
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_whquote_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_whquote_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_whquote_body

create table t_whquote_body (
	billno varchar(20) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	prodarea varchar(30) null,
	punit varchar(10) null,
	itemcnt numeric(19,4) not null default(0),
	pcount numeric(19,4) not null default(0),
	sglcount numeric(19,4) not null default(0),
	counts numeric(19,4) not null default(0),
	zpcount numeric(19,4) not null default(0),
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	pfprice numeric(19,4) not null default(0),
	pftotal numeric(19,4) not null default(0),
	netpftotal numeric(19,4) not null default(0),
	zrtotal numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	staxrate int not null default(0),
	tag varchar(1) null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_pfquotedetail primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_whsale_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_whsale_head

create table t_whsale_head (
	billno varchar(20) not null,
	orgcode varchar(10) not null,
	bizdate varchar(10) null,
	custcode varchar(15) null,
	custname varchar(30) null,
	validdate varchar(10) null,
	sqauremode varchar(1) not null default('0'),
	paydate varchar(10) null,
	place varchar(1) not null default('0'),
	pfquoteno varchar(20) null,
	refbillno varchar(20) null,
	counts numeric(19,4) not null default(0),
	zpcount numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	pftotal numeric(19,4) not null default(0),
	netpftotal numeric(19,4) not null default(0),
	zrtotal numeric(19,4) not null default(0),
	jstotal numeric(19,4) not null default(0),
	jszrtotal numeric(19,4) not null default(0),
	isfinished varchar(1) not null default('0'),
	deliveraddr varchar(100) null,
	sendorname varchar(10) null,
	tel varchar(20) null,
 	ornpftotal numeric(19,4) not null default(0),
	ystotal numeric(19,4) not null default(0),
	billzrtotal numeric(19,4) not null default(0),
	billzkrate numeric(19,4) not null default(0),
	autodsctotal numeric(19,4) not null default(0),
	rewardtotal numeric(19,4) not null default(0),
	pludsctotal numeric(19,4) not null default(0),
	authno varchar(6) null,
	dsccode varchar(20) null,
	funcdepcode varchar(10) null,
	addinfo varchar(100) null,
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null default(0),
	tag varchar(2) null,
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_whsale_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_whsale_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_whsale_body

create table t_whsale_body (
	billno varchar(20) not null,
	serialno numeric(19,0) not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	prodarea varchar(30) null,
	punit varchar(10) null,
	itemcnt numeric(19,4) not null default(0),
	pcount numeric(19,4) not null default(0),
	sglcount numeric(19,4) not null default(0),
	counts numeric(19,4) not null default(0),
	zpcount numeric(19,4) not null default(0),
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	zkrate numeric(19,4) not null default(0),
	ornpfprice numeric(19,4) not null default(0),
	ornpftotal numeric(19,4) not null default(0),
	pfprice numeric(19,4) not null default(0),
	pftotal numeric(19,4) not null default(0),
	netpftotal numeric(19,4) not null default(0),
	zrtotal numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	staxrate int not null default(0),
	ystotal numeric(19,4) not null default(0),
	pludsctotal numeric(19,4) not null default(0),
	jpprice numeric(19,4) not null default(0),
	sharetotal numeric(19,4) not null default(0),
	dsccode varchar(20) null,
	authno varchar(6) null,
	allowdz varchar(1) null,
	tag varchar(1) null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_whsale_body primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_whsale_body2') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_whsale_body2

create table t_whsale_body2 (
	billno varchar(20) not null,
	serialno numeric(19,0) not null default(1),
	plucode varchar(20) not null,
	packcode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	prodarea varchar(30) null,
	punit varchar(10) null,
	itemcnt numeric(19,4) not null default(0),
	pcount numeric(19,4) not null default(0),
	sglcount numeric(19,4) not null default(0),
	counts numeric(19,4) not null default(0),
	zpcount numeric(19,4) not null default(0),
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	zkrate numeric(19,4) not null default(0),
	ornpfprice numeric(19,4) not null default(0),
	ornpftotal numeric(19,4) not null default(0),
	pfprice numeric(19,4) not null default(0),
	pftotal numeric(19,4) not null default(0),
	netpftotal numeric(19,4) not null default(0),
	zrtotal numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	staxrate int not null default(0),
	ystotal numeric(19,4) not null default(0),
	pludsctotal numeric(19,4) not null default(0),
	sharetotal numeric(19,4) not null default(0),
	dsccode varchar(20) null,
	authno varchar(6) null,
	tag varchar(1) null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_whsale_body2 primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_whreturn_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_whreturn_head

create table t_whreturn_head (
	billno varchar(20) not null,
	orgcode varchar(10) not null,
	bizdate varchar(10) null,
	custcode varchar(15) null,
	custname varchar(30) null,
	sqauremode varchar(1) not null default('0'),
	paydate varchar(10) null,	
	place varchar(1) not null default('0'),
	pfsaleno varchar(20) not null,
	counts numeric(19,4) not null default(0),
	zpcount numeric(19,4) not null default(0),
	cost numeric(19,4) null default(0),
	netcost numeric(19,4) null default(0),
	total numeric(19,4) null default(0),
	pftotal numeric(19,4) null default(0),
	netpftotal numeric(19,4) not null default(0),
	zrtotal numeric(19,4) null default(0),
	jstotal numeric(19,4) not null default(0),
	jszrtotal numeric(19,4) not null default(0),
	isfinished varchar(1) not null default('0'),
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null default(0),
	tag varchar(2) null,
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_whreturn_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_whreturn_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_whreturn_body

create table t_whreturn_body (
	billno varchar(20) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	prodarea varchar(30) null,
	punit varchar(10) null,
	itemcnt numeric(19,4) not null default(0),
	pcount numeric(19,4) not null default(0),
	sglcount numeric(19,4) not null default(0),
	counts numeric(19,4) not null default(0),
	zpcount numeric(19,4) not null default(0),
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	zkrate numeric(19,4) not null default(0),
	ornpfprice numeric(19,4) not null default(0),
	ornpftotal numeric(19,4) not null default(0),
	pfprice numeric(19,4) not null default(0),
	pftotal numeric(19,4) not null default(0),
	netpftotal numeric(19,4) not null default(0),
	zrtotal numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	staxrate int not null default(0),
	tag varchar(1) null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_whreturn_body primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_whreturn_body2') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_whreturn_body2

create table t_whreturn_body2 (
	billno varchar(20) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	packcode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	prodarea varchar(30) null,
	punit varchar(10) null,
	itemcnt numeric(19,4) not null default(0),
	pcount numeric(19,4) not null default(0),
	sglcount numeric(19,4) not null default(0),
	counts numeric(19,4) not null default(0),
	zpcount numeric(19,4) not null default(0),
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	pfprice numeric(19,4) not null default(0),
	pftotal numeric(19,4) not null default(0),
	netpftotal numeric(19,4) not null default(0),
	zrtotal numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	staxrate int not null default(0),
	tag varchar(1) null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_whreturn_body2 primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_biz_state') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_biz_state

create table t_biz_state (
	billtype varchar(4) not null,
	billno varchar(20) not null,	
	enumcode varchar(6) not null,
	valuecode varchar(6) not null,	
	valuename varchar(20) not null,	
	state varchar(1) not null default('0'),	
	constraint pk_biz_state primary key nonclustered
	( 
		billtype,billno,enumcode,valuecode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_whsle_accage') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_whsle_accage

create table t_whsle_accage (
	serialno int not null,
	agedays int not null,
	remark varchar(200) null,
	constraint pk_whsle_accage primary key nonclustered
	(
		serialno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_whcbk_yyyymm') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_whcbk_yyyymm

create table t_whcbk_yyyymm (
	orgcode varchar(10) not null,
	bizdate varchar(10) not null,
	serialno int not null identity(1,1),
	bookdate varchar(10) not null,
	booktime varchar(8) not null,
	custcode varchar(15) not null,
	billno varchar(20) not null,
	billtype varchar(1) not null,
	username varchar(10) not null,
	ywname varchar(10) not null,
	ctotal numeric(19,4) not null default(0),
	ysjytotal numeric(19,4) not null default(0),
	prepayjytotal numeric(19,4) not null default(0),
	accdate varchar(10) null,
	tag varchar(1) null,
	remark varchar(200) null,
	constraint pk_whcbk_yyyymm primary key nonclustered
	(
		orgcode,bizdate,serialno,custcode,billno,billtype
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_whrpt_yyyy') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_whrpt_yyyy

create table t_whrpt_yyyy (
	accdate varchar(10) not null,
	orgcode varchar(10) not null,
	depcode varchar(10) not null,
	custcode varchar(15) not null,
	pfsaletotal numeric(19,4) not null default(0),
	pfreturntotal numeric(19,4) not null default(0),
	pfcost numeric(19,4) not null default(0),
	pfnetcost numeric(19,4) not null default(0),
	pftotal numeric(19,4) not null default(0),
	acceptxj numeric(19,4) not null default(0),
	acceptyq numeric(19,4) not null default(0),
	constraint pk_whrpt_yyyy primary key nonclustered
	(
		accdate,depcode,orgcode,custcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_whsale_yyyymm') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_whsale_yyyymm

create table t_whsale_yyyymm (
	accdate varchar(10) not null,
	plucode varchar(20) not null,
	orgcode varchar(10) not null,
	depcode varchar(10) not null,
	billno varchar(20) not null,
	billtype varchar(1) not null,
	supcode varchar(15) null,
	custcode varchar(15) null,
	pfprice numeric(19,4) not null default(0),
	counts numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	pftotal numeric(19,4) not null default(0),
	ornpftotal numeric(19,4) not null default(0),
	zrtotal numeric(19,4) not null default(0),
	grossprofit numeric(19,4) not null default(0),
	netprofit numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	staxrate int not null default(0),
	plutype varchar(1) null,
	constraint pk_whsale_yyyymm primary key nonclustered 
	(
		accdate,plucode,orgcode,depcode,billno,billtype
	)
)
go


--12 仓库

if exists (select * from sysobjects where id = OBJECT_ID(N't_ware_area') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_ware_area

create table t_ware_area (
	orgcode varchar(10) not null,
	areacode varchar(10) not null,
	areaname varchar(20) not null,
	area int not null default(0),
	leadman varchar(20) null,
	remark varchar(200) null,
	constraint pk_ware_area primary key nonclustered
	(
		orgcode,areacode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_ware_area_user') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_ware_area_user

create table t_ware_area_user (
	orgcode varchar(10) not null,
	areacode varchar(10) not null,
	usercode varchar(6) not null,
	username varchar(10) null,
	constraint pk_ware_area_user primary key nonclustered
	(
		orgcode,areacode,usercode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_ware_rack') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_ware_rack

create table t_ware_rack (
	orgcode varchar(10) not null,
	areacode varchar(10) not null,
	rackcode varchar(10) not null,
	rackname varchar(20) not null,
	baycount int not null default(0),
	levelcount int not null default(0),
	remark varchar(200) null,
	constraint pk_ware_rack primary key nonclustered
	(
		orgcode,areacode,rackcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_ware_bin') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_ware_bin

create table t_ware_bin (
	orgcode varchar(10) not null,
	areacode varchar(10) not null,
	rackcode varchar(10) not null,
	bincode varchar(10) not null,
	binbarcode varchar(20) not null,
	baycode varchar(10) not null,
	levelcode varchar(10) not null,
	pickorder int not null default(1),
	palletcnt int not null default(0),
	binpos varchar(20) null,
	binfee numeric(19,4) not null default(0),
	remark varchar(200) null,
	constraint pk_ware_bin primary key nonclustered
	(
		orgcode,areacode,rackcode,bincode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_plu_bin') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_plu_bin

create table t_plu_bin (
	orgcode varchar(10) not null,
	bincode varchar(10) not null,
	plucode varchar(20) not null,
	constraint pk_plu_bin primary key nonclustered
	(
		orgcode,bincode,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_picking_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_picking_head

create table t_picking_head (
	billno varchar(20) not null,
	orgcode varchar(10) not null,
	areacode varchar(10) not null,
	bizdate varchar(10) null,
	zpbillno varchar(20) null,
	billsrc varchar(1) not null default('0'),
	state varchar(1) not null default('0'),
	counts numeric(19,4) not null default(0),
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null default(0),
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_picking_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_picking_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_picking_body

create table t_picking_body (
	billno varchar(20) not null,
	serialno int not null default(1),	
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	punit varchar(10) null,
	itemcnt numeric(19,4) not null default(0),
	pcount numeric(19,4) not null default(0),
	sglcount numeric(19,4) not null default(0),
	counts numeric(19,4) not null default(0),
	zpcount numeric(19,4) not null default(0),
	bincode varchar(10) not null,
	boxno varchar(20) null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_picking_body primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_dist_route') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_dist_route

create table t_dist_route (
	orgcode varchar(10) not null,
	routecode varchar(10) not null,
	routename varchar(10) not null,
	routedesc varchar(200) null,
	remark varchar(200) null,
	constraint pk_dist_route primary key nonclustered
	(
		orgcode,routecode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_dist_route_shop') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_dist_route_shop

create table t_dist_route_shop (
	orgcode varchar(10) not null,
	routecode varchar(10) not null,
	shopcode varchar(10) not null,
	distorder int not null default(1),
	mileage numeric(19,4) not null default(0),
	remark varchar(200) null,
	constraint pk_dist_route_shop primary key nonclustered
	(
		orgcode,routecode,shopcode
	)
)
go


--20 管理

if exists (select * from sysobjects where id = OBJECT_ID(N't_syscfg') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_syscfg

create table t_syscfg (
	section varchar(20) not null,
	itemname varchar(20) not null,
	itemvalue varchar(200) null,
	itemexp varchar(100) null,
	valueexp varchar(100) null,
	constraint pk_syscfg primary key nonclustered
	(
		section,itemname
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_dep_level') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_dep_level

create table t_dep_level (
	levelnum int not null,
	levelname varchar(8) not null,
	codelen int not null default(6),
	iscode varchar(1) not null default('0'),
	constraint pk_deplevel primary key nonclustered
	(
		levelnum
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_gclass_level') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_gclass_level

create table t_gclass_level (
	levelnum int not null,
	levelname varchar(50) not null,
	codelen int not null default(2),
	iscode varchar(1) not null default('0'),
	constraint pk_gclass_level primary key nonclustered
	(
		levelnum
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_area_level') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_area_level

create table t_area_level (
	levelnum int not null,
	levelname varchar(50) not null,
	codelen int not null default(2),
	iscode varchar(1) not null default('0'),
	constraint pk_arealevel primary key nonclustered
	(
		levelnum
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_bin_level') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_bin_level

create table t_bin_level (
	levelnum int not null,
	levelname varchar(50) not null,
	codelen int not null default(2),
	iscode varchar(1) not null default('0'),
	constraint pk_binlevel primary key nonclustered
	(
		levelnum
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_max_serial') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_max_serial

create table t_max_serial (
	ruletype varchar(10) not null default('0'),
	rulecode varchar(10) not null default('x'),
	maxserial int null default(0),
	constraint pk_max_serial primary key nonclustered
	(
		ruletype,rulecode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_user') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_user

create table t_user (
	usercode varchar(6) not null,
	username varchar(10) null,
	depcode varchar(10) null,
	passwd varchar(100) null,
	dscrate int not null default(0),
	pfdscrate int not null default(0),
	authcard varchar(13) not null default(''),
	birth varchar(10) null,
	mobile1 varchar(20) null,
	mobile2 varchar(20) null,
	email varchar(40) null,
	chgdate varchar(20) null,
	loginstation varchar(15) null,
	multlogin int not null default(1),
	skinid varchar(2) null,
	photoid varchar(2) null,
	isgriddiff varchar(1) not null default('0'),
	isshowguide varchar(1) not null default('0'),
	boardlist varchar(100) null,
	chartlist varchar(100) null,
	lastlogintime varchar(20) null,
	lastchgpasstime varchar(20) null,
	islocked varchar(1) not null default('0'),
	errorcnt int not null default(0),
	constraint pk_user primary key nonclustered
	(
		usercode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_user_org') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_user_org

create table t_user_org (
	orgcode varchar(10) not null,
	usercode varchar(6) not null,
	constraint pk_user_org primary key nonclustered
	(
		orgcode,usercode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_sys_right_func') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_sys_right_func

create table t_sys_right_func (
	ugrpcode varchar(2) not null,
	funcode varchar(10) not null,
	optcode varchar(10) not null,
	constraint pk_sys_right_func primary key nonclustered
	(
		ugrpcode,funcode,optcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_bill_type') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_bill_type

create table t_bill_type (
	no int not null default(0),
	billcode varchar(4) not null,
	billname varchar(20) not null,
	isrule varchar(1) not null default('0'),
	nolength int not null default(20),
	prefix varchar(3) null,
	datefmt varchar(8) null,
	serialno int not null default(0),
	sdate varchar(10) null,
	chkmode varchar(1) not null default('0'),
	isrzprint varchar(1) not null default('0'),
	emailday int null,
	constraint pk_bill_type primary key nonclustered
	(
		billcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_bill_type_email') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_bill_type_email

create table t_bill_type_email (
	billcode varchar(4) not null,
	serialno int not null identity(1,1),
	email varchar(40) null,
	constraint pk_bill_type_email primary key nonclustered
	(
		billcode,serialno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_sys_right_dept') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_sys_right_dept

create table t_sys_right_dept (
	usercode varchar(6) not null,
	depcode varchar(10) not null,
	constraint pk_sys_right_dept primary key nonclustered
	(
		usercode,depcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_sys_user_grp') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_sys_user_grp

create table t_sys_user_grp (
	ugrpcode varchar(2) not null,
	ugrpname varchar(20) not null,
	ugrptype varchar(1) not null default('0'),
	remark varchar(200) null,
	constraint pk_sys_user_grp primary key nonclustered
	(
		ugrpcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_sys_user_sub') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_sys_user_sub

create table t_sys_user_sub (
	ugrpcode varchar(2) not null,
	usercode varchar(6) not null,
	constraint pk_sys_user_sub primary key nonclustered
	(
		ugrpcode,usercode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_def_query') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_def_query

create table t_def_query (
	sqlcode varchar(10) not null default(''),
	crtusercode varchar(6) not null,
	crtusername varchar(10) null,
	crtdate varchar(10) null,
	crttime varchar(8) null,
	isshared varchar(1) not null default('1'),
	isparam varchar(1) not null default('1'),
	remark text null,
	constraint pk_def_query primary key nonclustered
	(
		sqlcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_def_param') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_def_param

create table t_def_param (
	sqlcode varchar(10) not null default(''),
	paramcode varchar(40) not null,
	paramname varchar(40) not null,
	paramdatatype varchar(1) not null default('0'),
	vlutype varchar(1) not null default('0'),
	vluobject varchar(40) null,
	cmpfield varchar(40) null,
	reffield varchar(40) null,
	constraint pk_def_param primary key nonclustered
	(
		sqlcode,paramcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_def_param_value') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_def_param_value

create table t_def_param_value (
	sqlcode varchar(10) not null default(''),
	paramcode varchar(40) not null,
	vlucode varchar(4) not null,
	vluname varchar(20) null,
	constraint pk_def_param_value primary key nonclustered
	(
		sqlcode,paramcode,vlucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_def_script') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_def_script

create table t_def_script (
	sqlcode varchar(10) not null default(''),
	sqlscript text not null,
	constraint pk_def_script primary key nonclustered
	(
		sqlcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_remind') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_remind

create table t_remind (
	remindcode varchar(6) not null,
	remindname varchar(40) null,
	reminddisc varchar(100) null,
	funcode varchar(10) null,
	periods varchar(1) not null default('0'),
	userlogin varchar(1) not null default('0'),
	userlogout varchar(1) not null default('0'),
	canuse varchar(1) not null default('1'),
	keyfield varchar(20) null,
	spname varchar(50) null,
	constraint pk_remind primary key nonclustered
	(
		remindcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_remind_param') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_remind_param

create table t_remind_param (
	remindcode varchar(6) not null,
	paramcode varchar(20) not null,
	paramname varchar(40) not null,
	paramvalue varchar(50) not null default(''),
	paramremark varchar(100) null,
	paramtype varchar(1) not null default('0'),
	paramlength int not null default(0),
	paramindex int not null default(0),
	constraint pk_remind_param primary key nonclustered
	(
		remindcode,paramcode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_sys_dict') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_sys_dict

create table t_sys_dict (
	objname	varchar(40)	not null,
	objcaption varchar(40) null,
	objtype	varchar(1) not null default('0'),
	dbtype varchar(1) null,
	orderno int not null default 0,
	remark varchar(200)	null,
	constraint pk_sys_dict primary key nonclustered
	(
		objname
	)
) 
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_sys_dict_detail') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_sys_dict_detail

create table t_sys_dict_detail (
	objname	varchar(40)	not null,
	colname	varchar(40)	not null,
	colcaption varchar(40) null,
	datatype varchar(1)	not null default('S'),
	iskey varchar(1) not null default('0'),
	orderno int not null default 0,
	remark varchar(200) null,
	constraint pk_sys_dict_detail primary key nonclustered
	(
		objname,colname
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_notemsg_send') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_notemsg_send

create table t_notemsg_send (
	msgno numeric(19,0) not null identity(1,1),
	orgcode varchar(10) not null,
	tousercode varchar(6) not null,
	fromusercode varchar(6) not null,
	fromusername varchar(20) null,
	msgcontent varchar(400) null,
	createtime datetime null,
	isconfirm varchar(1) null,
	remark varchar(200) null,
	constraint pk_notemsg_send primary key nonclustered
	(
		msgno,orgcode,tousercode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_notemsg_receive') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_notemsg_receive

create table t_notemsg_receive (
	msgno numeric(19,0) not null,
	orgcode varchar(10) not null,
	msgtype varchar(1) not null,
	tousercode varchar(6) not null,
	fromusercode varchar(6) not null,
	fromusername varchar(20) null,
	msgcontent varchar(400) null,
	createtime datetime null,
	receivetime datetime null,
	isread varchar(1) null,
	isdelete varchar(1) null,
	remark varchar(200) null,
	constraint pk_notemsg_receive primary key nonclustered
	(
		msgno,msgtype,tousercode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_over_hist') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_over_hist

create table t_over_hist (
	orgcode varchar(10) not null,
	overdate varchar(10) not null,
	overtime varchar(8) not null,
	overer varchar(10) null,
	overtimes int null default(0),
	oprdate varchar(10) null,
	stationid varchar(20) null,
	overtype varchar(1) not null default('0'),
	overprocess int null default(0),
	ifdepsum varchar(1) null default('0'),
	constraint pk_over_hist primary key nonclustered
	(
		orgcode,overdate,overtime
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_backup_hist') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_backup_hist

create table t_backup_hist (
	backdate varchar(10) not null,
	backtime varchar(8) not null,
	backer varchar(10) not null,
	path varchar(80) not null,
	filename varchar(100) not null,
	backtype varchar(1) not null default('0'),
	backlevel varchar(1) not null default('0'),
	backduration int not null default (0),
	datasize int not null default(0),
	datadate varchar(10) not null,
	datatype varchar(1) not null default('0')
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_tran_log') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_tran_log

create table t_tran_log (
	logdate varchar(10) not null,
	logtime varchar(8) not null,
	stationid varchar(15) not null,
	mdlcode varchar(5) null,
	mdlname varchar(20) null,
	usercode varchar(6) null,
	username varchar(10) null,
	operation varchar(100) null
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_over_log') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_over_log

create table t_over_log (
	orgcode varchar(10) not null,
	itemcode varchar(10) not null,
	itemname varchar(100) null,
	overdate varchar(10) not null,
	overtime varchar(8) not null,
	overtype varchar(1) not null,
	logtime varchar(20) not null,
	itembgntime varchar(20) null,
	itemendtime varchar(20) null,
	execdesc varchar(100) null,
	execresult varchar(100) null,
	constraint pk_over_log primary key nonclustered
	(
		orgcode,itemcode,overdate,overtime,overtype,logtime
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_over_error') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_over_error

create table t_over_error (
	orgcode varchar(10) not null,
	overdate varchar(10) not null,
	overtime varchar(8) not null,
	logtime varchar(20) not null,
	errreason varchar(100) null,
	constraint pk_over_error primary key nonclustered
	(
		orgcode,overdate,overtime,logtime
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_over_error_detail') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_over_error_detail

create table t_over_error_detail (
	orgcode varchar(10) not null,
	overdate varchar(10) not null,
	overtime varchar(8) not null,
	logtime varchar(20) not null,
	plucode varchar(20) not null,
	pluname varchar(40) null,
	kccount numeric(19,4) null,
	xscount numeric(19,4) null,
	constraint [REDACTED]primary key nonclustered
	(
		orgcode,overdate,overtime,logtime,plucode
	)
)
go


--14 盘点机

if exists (select * from sysobjects where id = OBJECT_ID(N't_pda_ask_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pda_ask_head

create table t_pda_ask_head (
	billno varchar(50) not null,
	orgcode varchar(10) not null,
	cldate varchar(10) null,
	state varchar(1) not null default('0'),
	counts numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null default(0),
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,	
	remark varchar(200) null,
	constraint pk_pda_ask_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pda_ask_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pda_ask_body

create table t_pda_ask_body (
	billno varchar(50) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	punit varchar(10) null,
	itemcnt numeric(19,4) not null default(0),
	pcount numeric(19,4) not null default(0),
	sglcount numeric(19,4) not null default(0),
	counts numeric(19,4) not null default(0),
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	cgdate varchar(10) null,
	psdate varchar(10) null,
	ypcount numeric(19,4) not null default(0),
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_pda_ask_body primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id=OBJECT_ID(N'[dbo].[t_pda_order_head]') and OBJECTPROPERTY(id, N'isusertable')=1)
  drop table t_pda_order_head
go
create table t_pda_order_head(
	billno     varchar(50) not null,
	orgcode     varchar(10) not null,
	billtype    varchar(1) not null default('0'),
	depcode     varchar(10) null,
	supcode  varchar(15) not null,
	contrno  varchar(10) null,
	bizdate   varchar(10) null,
	arrivedate  varchar(10)    null,
	validdate   varchar(10)    null,
	state       varchar(1)     not null default('0'),
	goodsstate  varchar(1)     null default('0'),
	sqauremode  varchar(1)     null default('0'),
	paydate     varchar(10)    null,
	prntimes    int            null default(0),
	accdate     varchar(10)    null,
	tag         varchar(1)     null,
	rzdate      varchar(10)    null,
	rztime      varchar(8)     null,
	chkstatus   varchar(1)     not null default('0'),
	timemark    timestamp      null,
	shrcode     varchar(6)     null,
	shrname     varchar(10)    null,
	lrdate      varchar(10)    null,
	lrtime      varchar(8)     null,
	usercode    varchar(6)     null,
	username    varchar(10)    null,
	zdrcode     varchar(6)     null,
	zdrname     varchar(10)    null,
	depname     varchar(16)    null,
	supname  varchar(100)   null,
	counts      numeric(19, 4) not null default(0),
	cost        numeric(19, 4) not null default(0),
	netcost     numeric(19, 4) not null default(0),
	dhcount     numeric(19, 4) not null default(0),
	dhcost      numeric(19, 4) not null default(0),
	dhnetcost   numeric(19, 4) not null default(0),
	iszs        varchar(1)     not null default('0'),
	zsno        varchar(20)    null ,
	remark      varchar(200)   null,
	constraint pk_pda_order_head primary key nonclustered
	(
		billno
	)
) 
go


if exists (select * from sysobjects where id=object_id(N'[dbo].[t_pda_order_body]') and objectproperty(id, N'isusertable')=1)
  drop table t_pda_order_body
go
create table t_pda_order_body(
	billno      varchar(50)    not null,
	serialno     int            not null default (1),
	plucode      varchar(20)    not null,
	barcode      varchar(20)    null,
	pluname      varchar(40)    null,
	spec         varchar(40)    null,
	cargono      varchar(20)    null,
	punit        varchar(10)    null,
	pcount       numeric(19, 4) not null default (0),
	itemcnt      numeric(19, 4) not null default (0),
	sglcount     numeric(19, 4) not null default (0),
	unit         varchar(10)    null,
	jprice       numeric(19, 4) not null default (0),
	netjprice    numeric(19, 4) not null default (0),
	ornjprice    numeric(19, 4) not null,
	ornnetjprice numeric(19, 4) not null,
	price        numeric(19, 4) not null default (0),
	counts       numeric(19, 4) not null default (0),
	cost         numeric(19, 4) not null default (0),
	netcost      numeric(19, 4) not null default (0),
	dhcount      numeric(19, 4) not null default (0),
	dhcost       numeric(19, 4) not null default (0),
	dhnetcost    numeric(19, 4) not null default (0),
	jtaxrate     numeric(19, 4) not null default (13),
	tag          varchar(10)    null,
	depname      varchar(16)    null,
	depcode      varchar(10)    not null,
	remark       varchar(200)   null,
	constraint pk_pda_order_body primary key nonclustered
	(
		billno,serialno,plucode
	)
 )
go 

if exists (select * from sysobjects where id = OBJECT_ID(N't_pda_accept_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pda_accept_head

create table t_pda_accept_head (
	billno varchar(50) not null,
	orgcode varchar(10) not null,
	bizdate varchar(10) null,
	billtype varchar(1) not null default('0'),
	oldbillno varchar(20) null,
	supcode varchar(15) null,
	supname varchar(100) null,
	contrno varchar(40) null,
	orderno varchar(20) null,
	place varchar(1) not null default('0'),
	sqauremode varchar(1) not null default('0'),
	paydate varchar(10) null,
	counts numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	qrdate varchar(10) null,
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null default(0),
	tag varchar(1) null,
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_pda_accept_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pda_accept_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pda_accept_body

create table t_pda_accept_body (
	billno varchar(50) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	supcode varchar(15) null,
	punit varchar(10) null,
	itemcnt numeric(19,4) not null default(0),
	pcount numeric(19,4) not null default(0),
	sglcount numeric(19,4) not null default(0),
	counts numeric(19,4) null default(0),
	cgcount numeric(19,4) not null default(0),
	isdscjprice varchar(1) not null default('0'),
	ornjprice numeric(19,4) not null default(0),
	ornnetjprice numeric(19,4) not null default(0),
	jprice numeric(19,4) null default(0),
	netjprice numeric(19,4) null default(0),
	price numeric(19,4) null default(0),
	cost numeric(19,4) null default(0),
	netcost numeric(19,4) null default(0),
	total numeric(19,4) null default(0),
	jxprice numeric(19,4) null default(0),
	jtaxrate int null default(0),
	keepdays int not null default(0),
	productdate varchar(10) null,
	qualitydate varchar(10) null,
	productno varchar(20) null,
	bincode varchar(10) null,
	tag varchar(1) null,
	depcode varchar(10) not null,
	depname varchar(16) null,
	cercode varchar(20) null,
	picture	image null,
	remark varchar(200) null,
	constraint pk_pda_accept_body primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pda_return_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pda_return_head

create table t_pda_return_head (
	billno varchar(50) not null,
	orgcode varchar(10) not null,
	bizdate varchar(10) null,
	billtype varchar(1) not null default('0'),
	supcode varchar(15) null,
	supname varchar(100) null,
	contrno varchar(40) null,
	paydate varchar(10) null,
	sqauremode varchar(1) null default('0'),
	place varchar(1) null default('0'),
	oldbillno varchar(20) null,
	acceptno varchar(20) null,
	counts numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	orgin varchar(1) null,
	kindcd varchar(10) null,
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null default(0),
	tag varchar(1) null,
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_pda_return_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pda_return_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pda_return_body

create table t_pda_return_body (
	billno varchar(50) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	punit varchar(10) null,
	itemcnt numeric(19,4) not null default(0),
	pcount numeric(19,4) not null default(0),
	sglcount numeric(19,4) not null default(0),
	counts numeric(19,4) not null default(0),
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	jxprice numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	kindcd varchar(10) null,
	bincode varchar(10) null,
	tag varchar(1) null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_pda_return_body primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pda_adjprice_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pda_adjprice_head

create table t_pda_adjprice_head (
	billno varchar(50) not null,
	orgcode varchar(10) null,
	bizdate varchar(10) null,
	supcode varchar(15) null,
	billtype varchar(1) null default('0'),
	isplan varchar(1) not null default('0'),
	sxdate varchar(10) not null default(''),
	sxtime varchar(8) not null default(''),	
	exectime varchar(20) not null default(''),	
	counts numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	newtotal numeric(19,4) not null default(0),
	totaldiff numeric(19,4) not null default(0),
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null default(0),
	tag varchar(1) null,
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint [REDACTED]primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pda_adjprice_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pda_adjprice_body

create table t_pda_adjprice_body (
	billno varchar(50) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	oldprice numeric(19,4) not null default(0),
	newprice numeric(19,4) null,
	oldvipprice numeric(19,4) not null default(0),
	newvipprice numeric(19,4) null,
	oldpfprice numeric(19,4) not null default(0),
	newpfprice numeric(19,4) null,
	oldpsprice numeric(19,4) not null default(0),
	newpsprice numeric(19,4) null,
	counts numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	newtotal numeric(19,4) not null default(0),
	totaldiff numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	tag varchar(1) null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint [REDACTED]primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pda_dist_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pda_dist_head

create table t_pda_dist_head (
	billno varchar(50) not null,
	orgcode varchar(10) not null,
	shopcode varchar(10) not null,
	askno varchar(20) null,
	sqauremode varchar(1) not null default('0'),
	paydate varchar(10) null,
	zpcount numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	zpamount numeric(19,4) not null default(0),
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null default(0),
	tag varchar(1) null,
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_pda_dist_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pda_dist_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pda_dist_body

create table t_pda_dist_body (
	billno varchar(50) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	punit varchar(10) null,
	itemcnt numeric(19,4) not null default(0),
	pcount numeric(19,4) not null default(0),
	sglcount numeric(19,4) not null default(0),
	zpcount numeric(19,4) not null default(0),
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	ispsprice varchar(1) not null default('0'),
	zpprice numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	zpamount numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	supcode varchar(15) null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_pda_dist_body primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pda_outtrans_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pda_outtrans_head

create table t_pda_outtrans_head (
	billno varchar(50) not null,
	orgcode varchar(10) not null,
	bizdate varchar(10) null,
	intransno varchar(20) null,
	isout varchar(1) null,
	makertype varchar(1) null,
	billtype varchar(1) not null,
	outorgcode varchar(10) not null,
	outorgname varchar(30) null,
	inorgcode varchar(10) not null,
	inorgname varchar(30) null,
	place varchar(1) not null default('0'),
	counts numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	qrdate varchar(10) null,
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) null default('0'),
	prntimes int null default(0),
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint [REDACTED]primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pda_outtrans_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pda_outtrans_body

create table t_pda_outtrans_body (
	billno varchar(50) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	punit varchar(10) null,
	itemcnt numeric(19,4) not null default(0),
	pcount numeric(19,4) not null default(0),
	sglcount numeric(19,4) not null default(0),
	counts numeric(19,4) not null default(0),
	plancounts numeric(19,4) not null default(0),
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint [REDACTED]primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pda_scrap_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pda_scrap_head

create table t_pda_scrap_head (
	billno varchar(50) not null,
	orgcode varchar(10) not null,
	bizdate varchar(10) null,
	place varchar(1) not null default('0'),
	counts numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) null default('0'),
	prntimes int null default(0),
	tag varchar(1) null,
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_pda_scrap_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pda_scrap_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pda_scrap_body

create table t_pda_scrap_body (
	billno varchar(50) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	punit varchar(10) null,
	itemcnt numeric(19,4) not null default(0),
	pcount numeric(19,4) not null default(0),
	sglcount numeric(19,4) not null default(0),
	counts numeric(19,4) not null default(0),
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	bstype varchar(20) null,
	bsreason varchar(20) null,
	tag varchar(1) null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_pda_scrap_body primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pda_check_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pda_check_head

create table t_pda_check_head (
	billno varchar(50) not null,
	orgcode varchar(10) not null,
	billtype varchar(1) not null default('0'),
	pdno varchar(20) not null,	
	place varchar(1) not null default('0'),
	gentype varchar(1) not null default('0'),
	devcode varchar(6) null,
	counts numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	remark varchar(200) null,
	constraint pk_pda_check_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pda_check_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pda_check_body

create table t_pda_check_body (
	billno varchar(50) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	punit varchar(10) null,
	itemcnt numeric(19,4) not null default(0),
	pcount numeric(19,4) not null default(0),
	sglcount numeric(19,4) not null default(0),
	counts numeric(19,4) not null default(0),
	ocount numeric(19,4) not null default(0),
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	depcode varchar(10) not null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_pda_check_body primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pda_differ_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pda_differ_head

create table t_pda_differ_head (
	billno varchar(50) not null,
	orgcode varchar(10) not null,
	bizdate varchar(10) null,
	supcode varchar(15) null,
	place varchar(1) null default('0'),
	ykcount numeric(19,4) not null default(0),
	ykcost numeric(19,4) not null default(0),
	yknetcost numeric(19,4) not null default(0),
	yktotal numeric(19,4) not null default(0),
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null default(0),
	tag varchar(1) null,
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_pda_differ_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pda_differ_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pda_differ_body

create table t_pda_differ_body (
	billno varchar(50) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	bookcount numeric(19,4) not null default(0),
	realcount numeric(19,4) not null default(0),
	bookcost numeric(19,4) not null default(0),
	realcost numeric(19,4) not null default(0),
	booknetcost numeric(19,4) not null default(0),
	realnetcost numeric(19,4) not null default(0),
	booktotal numeric(19,4) not null default(0),
	realtotal numeric(19,4) not null default(0),	
	ykcount numeric(19,4) not null default(0),
	ykcost numeric(19,4) not null default(0),
	yknetcost numeric(19,4) not null default(0),
	yktotal numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	tag varchar(1) null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_pda_differ_body primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pda_whquote_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pda_whquote_head

create table t_pda_whquote_head (
	billno varchar(50) not null,
	orgcode varchar(10) not null,
	bizdate varchar(10) null,
	custcode varchar(15) null,
	custname varchar(30) null,
	validdate varchar(10) null,
	sqauremode varchar(1) not null default('0'),
	paydate varchar(10) null,
	place varchar(1) not null default('0'),
	pfquoteno varchar(20) null,
	refbillno varchar(20) null,
	counts numeric(19,4) not null default(0),
	zpcount numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	pftotal numeric(19,4) not null default(0),
	zrtotal numeric(19,4) not null default(0),
	jstotal numeric(19,4) not null default(0),	
	jszrtotal numeric(19,4) not null default(0),	
	isfinished varchar(1) null,	
	deliveraddr varchar(100) null,
	sendorname varchar(10) null,
	tel varchar(20) null,
	ornpftotal numeric(19,4) not null default(0),
	ystotal numeric(19,4) not null default(0),
	rtntotal numeric(19,4) not null default(0),
	billzrtotal numeric(19,4) not null default(0),
	billzkrate numeric(19,4) not null default(0),
	autodsctotal numeric(19,4) not null default(0),
	rewardtotal numeric(19,4) not null default(0),
	pludsctotal numeric(19,4) not null default(0),
	authno varchar(6) null,
	dsccode varchar(20) null,
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	prntimes int null,
	tag varchar(1) null,
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint [REDACTED]primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pda_whquote_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pda_whquote_body

create table t_pda_whquote_body (
	billno varchar(50) not null,
	serialno numeric(19,0) not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	prodarea varchar(30) null,
	punit varchar(10) null,
	itemcnt numeric(19,4) not null default(0),
	pcount numeric(19,4) not null default(0),
	sglcount numeric(19,4) not null default(0),
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	zkrate numeric(19,4) not null default(0),
	counts numeric(19,4) not null default(0),
	zpcount numeric(19,4) not null default(0),
	pfprice numeric(19,4) not null default(0),
	pftotal numeric(19,4) not null default(0),
	ornpfprice numeric(19,4) not null default(0),
	ornpftotal numeric(19,4) not null default(0),
	zrtotal numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	ystotal numeric(19,4) not null default(0),
	rtntotal numeric(19,4) not null default(0),
	rtnrate numeric(19,4) not null default(0),
	pludsctotal numeric(19,4) not null default(0),
	jpprice numeric(19,4) not null default(0),
	sharetotal numeric(19,4) not null default(0),
	dsccode varchar(20) null,
	authno varchar(6) null,
	allowdz varchar(1) null,
	tag varchar(1) null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint [REDACTED]primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pda_whsale_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pda_whsale_head

create table t_pda_whsale_head (
	billno varchar(50) not null,
	orgcode varchar(10) not null,
	bizdate varchar(10) null,
	custcode varchar(15) null,
	custname varchar(30) null,
	validdate varchar(10) null,
	sqauremode varchar(1) not null default('0'),
	paydate varchar(10) null,
	place varchar(1) not null default('0'),
	pfquoteno varchar(20) null,
	refbillno varchar(20) null,
	counts numeric(19,4) not null default(0),
	zpcount numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	pftotal numeric(19,4) not null default(0),
	zrtotal numeric(19,4) not null default(0),
	jstotal numeric(19,4) not null default(0),	
	jszrtotal numeric(19,4) not null default(0),	
	isfinished varchar(1) null,	
	deliveraddr varchar(100) null,
	sendorname varchar(10) null,
	tel varchar(20) null,
	ornpftotal numeric(19,4) not null default(0),
	ystotal numeric(19,4) not null default(0),
	rtntotal numeric(19,4) not null default(0),
	billzrtotal numeric(19,4) not null default(0),
	billzkrate numeric(19,4) not null default(0),
	autodsctotal numeric(19,4) not null default(0),
	rewardtotal numeric(19,4) not null default(0),
	pludsctotal numeric(19,4) not null default(0),
	authno varchar(6) null,
	dsccode varchar(20) null,
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	prntimes int null,
	tag varchar(1) null,
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_pda_whsale_head primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pda_whsale_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pda_whsale_body

create table t_pda_whsale_body (
	billno varchar(50) not null,
	serialno numeric(19,0) not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	prodarea varchar(30) null,
	punit varchar(10) null,
	itemcnt numeric(19,4) not null default(0),
	pcount numeric(19,4) not null default(0),
	sglcount numeric(19,4) not null default(0),
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	zkrate numeric(19,4) not null default(0),
	counts numeric(19,4) not null default(0),
	zpcount numeric(19,4) not null default(0),
	pfprice numeric(19,4) not null default(0),
	pftotal numeric(19,4) not null default(0),
	ornpfprice numeric(19,4) not null default(0),
	ornpftotal numeric(19,4) not null default(0),
	zrtotal numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	ystotal numeric(19,4) not null default(0),
	rtntotal numeric(19,4) not null default(0),
	rtnrate numeric(19,4) not null default(0),
	pludsctotal numeric(19,4) not null default(0),
	jpprice numeric(19,4) not null default(0),
	sharetotal numeric(19,4) not null default(0),
	dsccode varchar(20) null,
	authno varchar(6) null,
	allowdz varchar(1) null,
	tag varchar(1) null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint pk_pda_pfsale_body primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pda_whreturn_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pda_whreturn_head

create table t_pda_whreturn_head (
	billno varchar(50) not null,
	orgcode varchar(10) not null,
	bizdate varchar(10) null,
	custcode varchar(15) null,
	custname varchar(30) null,
	sqauremode varchar(1) not null default('0'),
	paydate varchar(10) null,
	place varchar(1) null default('0'),
	pfsaleno varchar(20) not null,
	counts numeric(19,4) not null default(0),
	zpcount numeric(19,4) not null default(0),
	cost numeric(19,4) null default(0),
	netcost numeric(19,4) null default(0),
	total numeric(19,4) null default(0),
	pftotal numeric(19,4) null default(0),
	zrtotal numeric(19,4) null default(0),
	jstotal numeric(19,4) not null default(0),
	jszrtotal numeric(19,4) not null default(0),
	isfinished varchar(1) null,
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null default(0),
	tag varchar(1) null,
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint [REDACTED]primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pda_whreturn_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pda_whreturn_body

create table t_pda_whreturn_body (
	billno varchar(50) not null,
	serialno int not null default(1),
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	prodarea varchar(30) null,
	punit varchar(10) null,
	itemcnt numeric(19,4) not null default(0),
	pcount numeric(19,4) not null default(0),
	sglcount numeric(19,4) not null default(0),
	counts numeric(19,4) not null default(0),
	zpcount numeric(19,4) not null default(0),
	jprice numeric(19,4) not null default(0),
	netjprice numeric(19,4) not null default(0),
	price numeric(19,4) not null default(0),
	ornpfprice numeric(19,4) not null default(0),
	ornpftotal numeric(19,4) not null default(0),
	pfprice numeric(19,4) not null default(0),
	pftotal numeric(19,4) not null default(0),
	zkrate numeric(19,4) not null default(0),
	zrtotal numeric(19,4) not null default(0),
	cost numeric(19,4) not null default(0),
	netcost numeric(19,4) not null default(0),
	total numeric(19,4) not null default(0),
	jtaxrate int not null default(0),
	tag varchar(1) null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint [REDACTED]primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pda_picking_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pda_picking_head

create table t_pda_picking_head (
	billno varchar(50) not null,
	orgcode varchar(10) not null,
	areacode varchar(10) not null,
	bizdate varchar(10) null,
	zpbillno varchar(20) null,
	billsrc varchar(1) not null default('0'),
	state varchar(1) not null default('0'),
	counts numeric(19,4) not null default(0),
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	accdate varchar(10) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) not null default('0'),
	prntimes int null default(0),
	timemark timestamp null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint [REDACTED]primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pda_picking_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pda_picking_body

create table t_pda_picking_body (
	billno varchar(50) not null,
	serialno int not null default(1),	
	plucode varchar(20) not null,
	barcode varchar(20) null,
	pluname varchar(40) null,
	cargono varchar(20) null,
	spec varchar(40) null,
	unit varchar(10) null,
	punit varchar(10) null,
	itemcnt numeric(19,4) not null default(0),
	pcount numeric(19,4) not null default(0),
	sglcount numeric(19,4) not null default(0),
	counts numeric(19,4) not null default(0),
	zpcount numeric(19,4) not null default(0),
	bincode varchar(10) not null,
	boxno varchar(20) null,
	depcode varchar(10) null,
	depname varchar(16) null,
	remark varchar(200) null,
	constraint [REDACTED]primary key nonclustered
	(
		billno,serialno,plucode
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_pda_billno') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_pda_billno

create table t_pda_billno (
	billno varchar(50) not null,
	billtype varchar(10) not null,
	billsavedate varchar(10) null,
	billsavetime varchar(8) null,
	constraint pk_pda_billno primary key nonclustered
	(
		billno,billtype
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_intf_check_data') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_intf_check_data

create table t_intf_check_data (
	serialno int not null,
	pluserialno int not null default(0),
	pdno varchar(20) null,
	orgcode varchar(10) null,
	plucode varchar(20) null,
	barcode varchar(20) null,
	counts numeric(19,4) not null default(0)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_intf_lblprntask_data') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_intf_lblprntask_data

create table t_intf_lblprntask_data (
	serialno int not null,
	orgcode varchar(10) null,
	plucode varchar(20) null,
	barcode varchar(20) null,
	prntype varchar(1) null,
	prncount numeric(19,4) not null default(0),
	remark varchar(200) null
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_intf_cardplu_data') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_intf_cardplu_data

create table t_intf_cardplu_data (
	serialno int not null,
	pluorderno int null,
	orgcode varchar(10) null,
	cardcode varchar(20) null,
	plucode varchar(20) null,
	barcode varchar(20) null
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N'imp_plu_org') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
  drop table imp_plu_org

CREATE TABLE imp_plu_org (
  gmt_create datetime DEFAULT getdate() NULL,
  batch_no varchar(50) COLLATE Chinese_PRC_CI_AS NOT NULL,
  plucode varchar(20) COLLATE Chinese_PRC_CI_AS NOT NULL,
  orgcode varchar(10) COLLATE Chinese_PRC_CI_AS NOT NULL,
  jprice numeric(19,4) DEFAULT 0 NOT NULL,
  netjprice numeric(19,4) DEFAULT 0 NOT NULL,
  price numeric(19,4) DEFAULT 0 NOT NULL,
  vipprice numeric(19,4) DEFAULT 0 NOT NULL,
  pfprice numeric(19,4) DEFAULT 0 NOT NULL,
  psprice numeric(19,4) DEFAULT 0 NOT NULL,
  gcount numeric(19,4) DEFAULT 0 NOT NULL,
  ccount numeric(19,4) DEFAULT 0 NOT NULL,
  cost numeric(19,4) DEFAULT 0 NOT NULL,
  netcost numeric(19,4) DEFAULT 0 NOT NULL,
  total numeric(19,4) DEFAULT 0 NOT NULL,
  tzamount numeric(19,4) DEFAULT 0 NOT NULL,
  isright varchar(1) COLLATE Chinese_PRC_CI_AS DEFAULT '1' NOT NULL,
  isxs varchar(1) COLLATE Chinese_PRC_CI_AS DEFAULT '1' NOT NULL,
  isth varchar(1) COLLATE Chinese_PRC_CI_AS DEFAULT '1' NOT NULL,
  iscg varchar(1) COLLATE Chinese_PRC_CI_AS DEFAULT '1' NOT NULL,
  iscgth varchar(1) COLLATE Chinese_PRC_CI_AS DEFAULT '1' NOT NULL,
  ispsth varchar(1) COLLATE Chinese_PRC_CI_AS DEFAULT '1' NOT NULL,
  isask varchar(1) COLLATE Chinese_PRC_CI_AS DEFAULT '1' NOT NULL,
  iszs varchar(1) COLLATE Chinese_PRC_CI_AS DEFAULT '1' NOT NULL,
  mngstock varchar(1) COLLATE Chinese_PRC_CI_AS DEFAULT '1' NOT NULL,
  cgmode varchar(1) COLLATE Chinese_PRC_CI_AS DEFAULT '0' NOT NULL,
  sjdate varchar(10) COLLATE Chinese_PRC_CI_AS NULL,
  ojprice numeric(19,4) DEFAULT 0 NOT NULL,
  hjprice numeric(19,4) DEFAULT 0 NOT NULL,
  ljprice numeric(19,4) DEFAULT 0 NOT NULL,
  abc1 varchar(1) COLLATE Chinese_PRC_CI_AS NULL,
  abc2 varchar(1) COLLATE Chinese_PRC_CI_AS NULL,
  dms numeric(19,4) DEFAULT 0 NOT NULL,
  dms1 numeric(19,4) DEFAULT 0 NOT NULL,
  dms2 numeric(19,4) DEFAULT 0 NOT NULL,
  dms3 numeric(19,4) DEFAULT 0 NOT NULL,
  odms numeric(19,4) DEFAULT 0 NOT NULL,
  odms1 numeric(19,4) DEFAULT 0 NOT NULL,
  odms2 numeric(19,4) DEFAULT 0 NOT NULL,
  odms3 numeric(19,4) DEFAULT 0 NOT NULL,
  newjhdate varchar(10) COLLATE Chinese_PRC_CI_AS NULL,
  newxsdate varchar(10) COLLATE Chinese_PRC_CI_AS NULL,
  newpsdate varchar(10) COLLATE Chinese_PRC_CI_AS NULL,
  topstock int DEFAULT 0 NOT NULL,
  lowstock int DEFAULT 0 NOT NULL,
  jhcycle int DEFAULT 0 NOT NULL,
  pscycle int DEFAULT 0 NOT NULL,
  yjdate varchar(10) COLLATE Chinese_PRC_CI_AS NULL,
  chgdate varchar(20) COLLATE Chinese_PRC_CI_AS DEFAULT '' NOT NULL,
  supcode varchar(15) COLLATE Chinese_PRC_CI_AS NULL,
  tag1 varchar(100) COLLATE Chinese_PRC_CI_AS NULL,
  tag2 varchar(100) COLLATE Chinese_PRC_CI_AS NULL,
  tag3 varchar(100) COLLATE Chinese_PRC_CI_AS NULL,
  tag4 varchar(100) COLLATE Chinese_PRC_CI_AS NULL,
  tag5 varchar(100) COLLATE Chinese_PRC_CI_AS NULL,
  dscdms numeric(19,4) DEFAULT 0 NOT NULL,
  dscdms1 numeric(19,4) DEFAULT 0 NOT NULL,
  dscdms2 numeric(19,4) DEFAULT 0 NOT NULL,
  dscdms3 numeric(19,4) DEFAULT 0 NOT NULL,
  dscodms numeric(19,4) DEFAULT 0 NOT NULL,
  dscodms1 numeric(19,4) DEFAULT 0 NOT NULL,
  dscodms2 numeric(19,4) DEFAULT 0 NOT NULL,
  dscodms3 numeric(19,4) DEFAULT 0 NOT NULL,
  judgecnt numeric(19,4) DEFAULT 0 NULL,
  CONSTRAINT pk_imp_plu_org PRIMARY KEY (batch_no,plucode,orgcode)
);
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_update_pluorg_head') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_update_pluorg_head

create table t_update_pluorg_head (
	billno varchar(20) not null,
	lrdate varchar(10) null,
	lrtime varchar(8) null,
	rzdate varchar(10) null,
	rztime varchar(8) null,
	usercode varchar(6) null,
	username varchar(10) null,
	zdrcode varchar(6) null,
	zdrname varchar(10) null,
	shrcode varchar(6) null,
	shrname varchar(10) null,
	chkstatus varchar(1) null default('0'),
	constraint [REDACTED]primary key nonclustered
	(
		billno
	)
)
go

if exists (select * from sysobjects where id = OBJECT_ID(N't_update_pluorg_body') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table t_update_pluorg_body

create table t_update_pluorg_body (
	serialno int not null default(1),
	billno varchar(20) not null,
	orgcode varchar(20) not null,
	plucode varchar(20) not null,
	pluname varchar(40) null,
	isright varchar(1) not null default('1'),
	isask varchar(1) not null default('1'),
	isxs varchar(1) not null default('1'),
	iscgth varchar(1) not null default('1'),
	mngstock varchar(1) not null default('0'),
	cgmode varchar(1) not null default('0'),
	supcode varchar(15) not null,
	judgecnt numeric(19,4) not null default(0),

	constraint [REDACTED]primary key nonclustered
	(
		billno,serialno,orgcode,plucode
	)
)
go
