2016-09-26(结构).sql 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. USE [befri_Goldhoo]
  2. GO
  3. /****** Object: UserDefinedFunction [basedata].[f_GetInventoryCategory] Script Date: 2016-09-26 09:55:19 ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. -- =============================================
  9. -- 开发人员:
  10. -- 开发日期:
  11. -- 功 能: 递归获取指定产品分类的全部下级产品分类。
  12. -- <参数定义>
  13. -- <param name="InventoryCategoryId">需要返回数据的客户区域内码</param>
  14. -- </参数定义>
  15. -- 测 试: select * from [basedata].[f_GetInventoryCategory](78)
  16. -- =============================================
  17. CREATE FUNCTION [basedata].[f_GetInventoryCategory]
  18. (
  19. @InventoryCategoryId INT = NULL
  20. )
  21. RETURNS @result TABLE
  22. (
  23. InventoryCategoryId INT ,
  24. CategoryName NVARCHAR(100) ,
  25. ParentId INT
  26. )
  27. AS
  28. BEGIN
  29. WITH CTE ( InventoryCategoryId, CategoryName, ParentId )
  30. AS ( SELECT InventoryCategoryId ,
  31. CategoryName ,
  32. ParentId
  33. FROM basedata.InventoryCategory
  34. WHERE InventoryCategoryId = @InventoryCategoryId
  35. UNION ALL
  36. SELECT sub.InventoryCategoryId ,
  37. sub.CategoryName ,
  38. sub.ParentId
  39. FROM basedata.InventoryCategory sub
  40. JOIN CTE cte ON sub.ParentId = cte.InventoryCategoryId
  41. )
  42. INSERT INTO @result
  43. SELECT InventoryCategoryId ,
  44. CategoryName ,
  45. ParentId
  46. FROM CTE
  47. OPTION ( MAXRECURSION 0 )
  48. RETURN
  49. END
  50. CREATE VIEW clearance.V_Inventory
  51. AS
  52. SELECT i.InventoryId ,
  53. i.InventoryNumber ,
  54. i.InventoryName ,
  55. i.InventoryCategoryId ,
  56. i.Spec ,
  57. i.AliasName ,
  58. i.SearchCode ,
  59. i.SalesPrice ,
  60. i.IsClearance ,
  61. ISNULL(ca.DiscountCoef, 0) DiscountCoef ,
  62. ISNULL(ca.Quantity, 0) Quantity ,
  63. i.Description
  64. FROM basedata.Inventory i
  65. LEFT JOIN clearance.ClearanceAcc ca ON ca.InventoryId = i.InventoryId
  66. WHERE InventoryTypeId IN ( 1, 3 )
  67. CREATE VIEW clearance.V_ClearanceAccDetail
  68. AS
  69. SELECT cad.ClearanceAccDetailId ,
  70. cad.TableName ,
  71. cad.VoucherLineId ,
  72. cad.OperationType ,
  73. cad.WarehouseId ,
  74. cad.InventoryId ,
  75. i.InventoryNumber ,
  76. i.InventoryName ,
  77. cad.IncreasedQty ,
  78. cad.DecreasedQty ,
  79. cad.DiscountCoef ,
  80. cad.AccountedOn ,
  81. cad.Description
  82. FROM clearance.ClearanceAccDetail AS cad
  83. INNER JOIN basedata.Inventory AS i ON i.InventoryId = cad.InventoryId
  84. USE [befri_Goldhoo]
  85. GO
  86. /****** Object: Table [clearance].[ClearanceAcc] Script Date: 2016-09-27 10:18:44 ******/
  87. SET ANSI_NULLS ON
  88. GO
  89. SET QUOTED_IDENTIFIER ON
  90. GO
  91. CREATE TABLE [clearance].[ClearanceAcc]
  92. (
  93. [WarehouseId] [int] NOT NULL ,
  94. [InventoryId] [int] NOT NULL ,
  95. [Quantity] [numeric](9, 0) NOT NULL ,
  96. [DiscountCoef] [numeric](5, 2) NULL ,
  97. CONSTRAINT [PK_CLEARANCEACC] PRIMARY KEY CLUSTERED
  98. ( [WarehouseId] ASC, [InventoryId] ASC )
  99. WITH ( PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
  100. IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,
  101. ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY]
  102. )
  103. ON [PRIMARY]
  104. GO
  105. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'仓库内码',
  106. @level0type = N'SCHEMA', @level0name = N'clearance',
  107. @level1type = N'TABLE', @level1name = N'ClearanceAcc',
  108. @level2type = N'COLUMN', @level2name = N'WarehouseId'
  109. GO
  110. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'存货内码',
  111. @level0type = N'SCHEMA', @level0name = N'clearance',
  112. @level1type = N'TABLE', @level1name = N'ClearanceAcc',
  113. @level2type = N'COLUMN', @level2name = N'InventoryId'
  114. GO
  115. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'数量',
  116. @level0type = N'SCHEMA', @level0name = N'clearance',
  117. @level1type = N'TABLE', @level1name = N'ClearanceAcc',
  118. @level2type = N'COLUMN', @level2name = N'Quantity'
  119. GO
  120. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'折扣系数',
  121. @level0type = N'SCHEMA', @level0name = N'clearance',
  122. @level1type = N'TABLE', @level1name = N'ClearanceAcc',
  123. @level2type = N'COLUMN', @level2name = N'DiscountCoef'
  124. GO
  125. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'清仓产品账务',
  126. @level0type = N'SCHEMA', @level0name = N'clearance',
  127. @level1type = N'TABLE', @level1name = N'ClearanceAcc'
  128. GO
  129. USE [befri_Goldhoo]
  130. GO
  131. SET ANSI_NULLS ON
  132. SET QUOTED_IDENTIFIER ON
  133. GO
  134. SET ANSI_PADDING ON
  135. GO
  136. CREATE TABLE [clearance].[ClearanceAccDetail]
  137. (
  138. [ClearanceAccDetailId] [int] IDENTITY(1, 1)
  139. NOT NULL ,
  140. [TableName] [varchar](100) NOT NULL ,
  141. [VoucherLineId] [int] NOT NULL ,
  142. [OperationType] [tinyint] NOT NULL ,
  143. [WarehouseId] [int] NOT NULL ,
  144. [InventoryId] [int] NOT NULL ,
  145. [IncreasedQty] [numeric](9, 0) NOT NULL ,
  146. [DecreasedQty] [numeric](9, 0) NOT NULL ,
  147. [DiscountCoef] [numeric](5, 2) NULL ,
  148. [AccountedOn] [datetime] NOT NULL ,
  149. [Description] [nvarchar](200) NULL ,
  150. CONSTRAINT [PK_CLEARANCEACCDETAIL] PRIMARY KEY CLUSTERED
  151. ( [ClearanceAccDetailId] ASC )
  152. WITH ( PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
  153. IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,
  154. ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY]
  155. )
  156. ON [PRIMARY]
  157. GO
  158. SET ANSI_PADDING ON
  159. GO
  160. ALTER TABLE [clearance].[ClearanceAccDetail] ADD CONSTRAINT [DF__Clearance__Incre__5837A100] DEFAULT ((0.00)) FOR [IncreasedQty]
  161. GO
  162. ALTER TABLE [clearance].[ClearanceAccDetail] ADD CONSTRAINT [DF__Clearance__Decre__592BC539] DEFAULT ((0.00)) FOR [DecreasedQty]
  163. GO
  164. ALTER TABLE [clearance].[ClearanceAccDetail] ADD CONSTRAINT [DF__Clearance__Accou__5A1FE972] DEFAULT (GETDATE()) FOR [AccountedOn]
  165. GO
  166. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'单据行数据表',
  167. @level0type = N'SCHEMA', @level0name = N'clearance',
  168. @level1type = N'TABLE', @level1name = N'ClearanceAccDetail',
  169. @level2type = N'COLUMN', @level2name = N'TableName'
  170. GO
  171. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'单据行内码',
  172. @level0type = N'SCHEMA', @level0name = N'clearance',
  173. @level1type = N'TABLE', @level1name = N'ClearanceAccDetail',
  174. @level2type = N'COLUMN', @level2name = N'VoucherLineId'
  175. GO
  176. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'单据操作类型',
  177. @level0type = N'SCHEMA', @level0name = N'clearance',
  178. @level1type = N'TABLE', @level1name = N'ClearanceAccDetail',
  179. @level2type = N'COLUMN', @level2name = N'OperationType'
  180. GO
  181. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'仓库内码',
  182. @level0type = N'SCHEMA', @level0name = N'clearance',
  183. @level1type = N'TABLE', @level1name = N'ClearanceAccDetail',
  184. @level2type = N'COLUMN', @level2name = N'WarehouseId'
  185. GO
  186. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'存货内码',
  187. @level0type = N'SCHEMA', @level0name = N'clearance',
  188. @level1type = N'TABLE', @level1name = N'ClearanceAccDetail',
  189. @level2type = N'COLUMN', @level2name = N'InventoryId'
  190. GO
  191. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'增加数量',
  192. @level0type = N'SCHEMA', @level0name = N'clearance',
  193. @level1type = N'TABLE', @level1name = N'ClearanceAccDetail',
  194. @level2type = N'COLUMN', @level2name = N'IncreasedQty'
  195. GO
  196. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'减少数量',
  197. @level0type = N'SCHEMA', @level0name = N'clearance',
  198. @level1type = N'TABLE', @level1name = N'ClearanceAccDetail',
  199. @level2type = N'COLUMN', @level2name = N'DecreasedQty'
  200. GO
  201. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'折扣系数',
  202. @level0type = N'SCHEMA', @level0name = N'clearance',
  203. @level1type = N'TABLE', @level1name = N'ClearanceAccDetail',
  204. @level2type = N'COLUMN', @level2name = N'DiscountCoef'
  205. GO
  206. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'记账日期',
  207. @level0type = N'SCHEMA', @level0name = N'clearance',
  208. @level1type = N'TABLE', @level1name = N'ClearanceAccDetail',
  209. @level2type = N'COLUMN', @level2name = N'AccountedOn'
  210. GO
  211. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'备注',
  212. @level0type = N'SCHEMA', @level0name = N'clearance',
  213. @level1type = N'TABLE', @level1name = N'ClearanceAccDetail',
  214. @level2type = N'COLUMN', @level2name = N'Description'
  215. GO
  216. EXEC sys.sp_addextendedproperty @name = N'MS_Description',
  217. @value = N'清仓管理.清仓产品账务明细', @level0type = N'SCHEMA',
  218. @level0name = N'clearance', @level1type = N'TABLE',
  219. @level1name = N'ClearanceAccDetail'
  220. GO
  221. USE [befri_Goldhoo]
  222. GO
  223. SET ANSI_NULLS ON
  224. GO
  225. SET QUOTED_IDENTIFIER ON
  226. GO
  227. SET ANSI_PADDING ON
  228. GO
  229. CREATE TABLE [clearance].[ClearanceRec]
  230. (
  231. [ClearanceRecId] [int] NOT NULL ,
  232. [RecType] [tinyint] NOT NULL ,
  233. [WarehouseId] [int] NOT NULL ,
  234. [VoucherNumber] [varchar](20) NOT NULL ,
  235. [VoucherDate] [datetime] NOT NULL ,
  236. [Summary] [nvarchar](200) NULL ,
  237. [BusinessDate] [datetime] NULL ,
  238. [PreparedBy] [nvarchar](20) NOT NULL ,
  239. [PreparedOn] [datetime] NOT NULL ,
  240. [Approved] [bit] NOT NULL ,
  241. [ApprovedBy] [nvarchar](20) NULL ,
  242. [ApprovedOn] [datetime] NULL ,
  243. [ApprovedResult] [tinyint] NULL ,
  244. [CancelApproved] [bit] NOT NULL ,
  245. [CancelApprovedBy] [nvarchar](20) NULL ,
  246. [CancelApprovedOn] [datetime] NULL ,
  247. [CancelApprovedReson] [nvarchar](100) NULL ,
  248. [HandledBy] [nvarchar](20) NULL ,
  249. [Status] [tinyint] NOT NULL ,
  250. [VersionNumber] [smallint] NOT NULL ,
  251. [CreatedBy] [nvarchar](20) NOT NULL ,
  252. [CreatedOn] [datetime] NOT NULL ,
  253. [ModifiedBy] [nvarchar](20) NULL ,
  254. [ModifiedOn] [datetime] NOT NULL ,
  255. [Description] [nvarchar](200) NULL ,
  256. CONSTRAINT [PK_CLEARANCEREC] PRIMARY KEY CLUSTERED
  257. ( [ClearanceRecId] ASC )
  258. WITH ( PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
  259. IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,
  260. ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY]
  261. )
  262. ON [PRIMARY]
  263. GO
  264. SET ANSI_PADDING ON
  265. GO
  266. ALTER TABLE [clearance].[ClearanceRec] ADD CONSTRAINT [DF__Clearance__Appro__5CFC561D] DEFAULT ((0)) FOR [Approved]
  267. GO
  268. ALTER TABLE [clearance].[ClearanceRec] ADD CONSTRAINT [DF__Clearance__Cance__5DF07A56] DEFAULT ((0)) FOR [CancelApproved]
  269. GO
  270. ALTER TABLE [clearance].[ClearanceRec] ADD CONSTRAINT [DF__Clearance__Versi__5EE49E8F] DEFAULT ((0)) FOR [VersionNumber]
  271. GO
  272. ALTER TABLE [clearance].[ClearanceRec] ADD CONSTRAINT [DF__Clearance__Creat__5FD8C2C8] DEFAULT (GETDATE()) FOR [CreatedOn]
  273. GO
  274. ALTER TABLE [clearance].[ClearanceRec] ADD CONSTRAINT [DF__Clearance__Modif__60CCE701] DEFAULT (GETDATE()) FOR [ModifiedOn]
  275. GO
  276. EXEC sys.sp_addextendedproperty @name = N'MS_Description',
  277. @value = N'存货入出库记录内码', @level0type = N'SCHEMA', @level0name = N'clearance',
  278. @level1type = N'TABLE', @level1name = N'ClearanceRec',
  279. @level2type = N'COLUMN', @level2name = N'ClearanceRecId'
  280. GO
  281. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'仓库内码',
  282. @level0type = N'SCHEMA', @level0name = N'clearance',
  283. @level1type = N'TABLE', @level1name = N'ClearanceRec',
  284. @level2type = N'COLUMN', @level2name = N'WarehouseId'
  285. GO
  286. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'单据号',
  287. @level0type = N'SCHEMA', @level0name = N'clearance',
  288. @level1type = N'TABLE', @level1name = N'ClearanceRec',
  289. @level2type = N'COLUMN', @level2name = N'VoucherNumber'
  290. GO
  291. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'单据日期',
  292. @level0type = N'SCHEMA', @level0name = N'clearance',
  293. @level1type = N'TABLE', @level1name = N'ClearanceRec',
  294. @level2type = N'COLUMN', @level2name = N'VoucherDate'
  295. GO
  296. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'单据摘要',
  297. @level0type = N'SCHEMA', @level0name = N'clearance',
  298. @level1type = N'TABLE', @level1name = N'ClearanceRec',
  299. @level2type = N'COLUMN', @level2name = N'Summary'
  300. GO
  301. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'入出库日期',
  302. @level0type = N'SCHEMA', @level0name = N'clearance',
  303. @level1type = N'TABLE', @level1name = N'ClearanceRec',
  304. @level2type = N'COLUMN', @level2name = N'BusinessDate'
  305. GO
  306. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'制单人内码',
  307. @level0type = N'SCHEMA', @level0name = N'clearance',
  308. @level1type = N'TABLE', @level1name = N'ClearanceRec',
  309. @level2type = N'COLUMN', @level2name = N'PreparedBy'
  310. GO
  311. EXEC sys.sp_addextendedproperty @name = N'MS_Description',
  312. @value = N'制单日期--系统自动填充当前日期', @level0type = N'SCHEMA',
  313. @level0name = N'clearance', @level1type = N'TABLE',
  314. @level1name = N'ClearanceRec', @level2type = N'COLUMN',
  315. @level2name = N'PreparedOn'
  316. GO
  317. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'审核标记',
  318. @level0type = N'SCHEMA', @level0name = N'clearance',
  319. @level1type = N'TABLE', @level1name = N'ClearanceRec',
  320. @level2type = N'COLUMN', @level2name = N'Approved'
  321. GO
  322. EXEC sys.sp_addextendedproperty @name = N'MS_Description',
  323. @value = N'审核人内码--执行审核操作时,系统自动填充当前登录用户内码', @level0type = N'SCHEMA',
  324. @level0name = N'clearance', @level1type = N'TABLE',
  325. @level1name = N'ClearanceRec', @level2type = N'COLUMN',
  326. @level2name = N'ApprovedBy'
  327. GO
  328. EXEC sys.sp_addextendedproperty @name = N'MS_Description',
  329. @value = N'审核日期--执行审核操作时,系统自动填充当前日期', @level0type = N'SCHEMA',
  330. @level0name = N'clearance', @level1type = N'TABLE',
  331. @level1name = N'ClearanceRec', @level2type = N'COLUMN',
  332. @level2name = N'ApprovedOn'
  333. GO
  334. EXEC sys.sp_addextendedproperty @name = N'MS_Description',
  335. @value = N'审核结果-- 0:未审核 ;1: 通过,;2: 否决', @level0type = N'SCHEMA',
  336. @level0name = N'clearance', @level1type = N'TABLE',
  337. @level1name = N'ClearanceRec', @level2type = N'COLUMN',
  338. @level2name = N'ApprovedResult'
  339. GO
  340. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'弃审标记',
  341. @level0type = N'SCHEMA', @level0name = N'clearance',
  342. @level1type = N'TABLE', @level1name = N'ClearanceRec',
  343. @level2type = N'COLUMN', @level2name = N'CancelApproved'
  344. GO
  345. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'弃审人内码',
  346. @level0type = N'SCHEMA', @level0name = N'clearance',
  347. @level1type = N'TABLE', @level1name = N'ClearanceRec',
  348. @level2type = N'COLUMN', @level2name = N'CancelApprovedBy'
  349. GO
  350. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'弃审日期',
  351. @level0type = N'SCHEMA', @level0name = N'clearance',
  352. @level1type = N'TABLE', @level1name = N'ClearanceRec',
  353. @level2type = N'COLUMN', @level2name = N'CancelApprovedOn'
  354. GO
  355. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'弃审原因',
  356. @level0type = N'SCHEMA', @level0name = N'clearance',
  357. @level1type = N'TABLE', @level1name = N'ClearanceRec',
  358. @level2type = N'COLUMN', @level2name = N'CancelApprovedReson'
  359. GO
  360. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'经手人',
  361. @level0type = N'SCHEMA', @level0name = N'clearance',
  362. @level1type = N'TABLE', @level1name = N'ClearanceRec',
  363. @level2type = N'COLUMN', @level2name = N'HandledBy'
  364. GO
  365. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'单据状态',
  366. @level0type = N'SCHEMA', @level0name = N'clearance',
  367. @level1type = N'TABLE', @level1name = N'ClearanceRec',
  368. @level2type = N'COLUMN', @level2name = N'Status'
  369. GO
  370. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'记录版本',
  371. @level0type = N'SCHEMA', @level0name = N'clearance',
  372. @level1type = N'TABLE', @level1name = N'ClearanceRec',
  373. @level2type = N'COLUMN', @level2name = N'VersionNumber'
  374. GO
  375. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'记录创建人',
  376. @level0type = N'SCHEMA', @level0name = N'clearance',
  377. @level1type = N'TABLE', @level1name = N'ClearanceRec',
  378. @level2type = N'COLUMN', @level2name = N'CreatedBy'
  379. GO
  380. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'记录创建时间',
  381. @level0type = N'SCHEMA', @level0name = N'clearance',
  382. @level1type = N'TABLE', @level1name = N'ClearanceRec',
  383. @level2type = N'COLUMN', @level2name = N'CreatedOn'
  384. GO
  385. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'记录修改人',
  386. @level0type = N'SCHEMA', @level0name = N'clearance',
  387. @level1type = N'TABLE', @level1name = N'ClearanceRec',
  388. @level2type = N'COLUMN', @level2name = N'ModifiedBy'
  389. GO
  390. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'记录修改时间',
  391. @level0type = N'SCHEMA', @level0name = N'clearance',
  392. @level1type = N'TABLE', @level1name = N'ClearanceRec',
  393. @level2type = N'COLUMN', @level2name = N'ModifiedOn'
  394. GO
  395. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'备注',
  396. @level0type = N'SCHEMA', @level0name = N'clearance',
  397. @level1type = N'TABLE', @level1name = N'ClearanceRec',
  398. @level2type = N'COLUMN', @level2name = N'Description'
  399. GO
  400. EXEC sys.sp_addextendedproperty @name = N'MS_Description',
  401. @value = N'清仓管理.清仓产品入出库记录', @level0type = N'SCHEMA',
  402. @level0name = N'clearance', @level1type = N'TABLE',
  403. @level1name = N'ClearanceRec'
  404. GO
  405. USE [befri_Goldhoo]
  406. GO
  407. SET ANSI_NULLS ON
  408. GO
  409. SET QUOTED_IDENTIFIER ON
  410. GO
  411. SET ANSI_PADDING ON
  412. GO
  413. CREATE TABLE [clearance].[ClearanceRecLine]
  414. (
  415. [ClearanceRecLineId] [int] NOT NULL ,
  416. [ClearanceRecId] [int] NOT NULL ,
  417. [InventoryId] [int] NOT NULL ,
  418. [InventoryNumber] [varchar](20) NULL ,
  419. [InventoryName] [nvarchar](50) NULL ,
  420. [Spec] [varchar](200) NULL ,
  421. [BatchNumber] [varchar](20) NULL ,
  422. [IncreasedQty] [numeric](9, 0) NOT NULL ,
  423. [DecreasedQty] [numeric](9, 0) NOT NULL ,
  424. [DiscountCoef] [numeric](5, 2) NULL ,
  425. [IncreasedPrice] [money] NULL ,
  426. [DecreasedPrice] [money] NULL ,
  427. [IncreasedMoney] [money] NULL ,
  428. [DecreasedMoney] [money] NULL ,
  429. [LineStatus] [tinyint] NULL ,
  430. [VersionNumber] [smallint] NOT NULL ,
  431. [Description] [nvarchar](200) NULL ,
  432. CONSTRAINT [PK_CLEARANCERECLINE] PRIMARY KEY CLUSTERED
  433. ( [ClearanceRecLineId] ASC )
  434. WITH ( PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
  435. IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,
  436. ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY]
  437. )
  438. ON [PRIMARY]
  439. GO
  440. SET ANSI_PADDING ON
  441. GO
  442. ALTER TABLE [clearance].[ClearanceRecLine] ADD CONSTRAINT [DF__Clearance__Versi__63A953AC] DEFAULT ((0)) FOR [VersionNumber]
  443. GO
  444. ALTER TABLE [clearance].[ClearanceRecLine] WITH CHECK ADD CONSTRAINT [FK_ClearanceRecLine_ClearanceRec] FOREIGN KEY([ClearanceRecId])
  445. REFERENCES [clearance].[ClearanceRec] ([ClearanceRecId])
  446. ON UPDATE CASCADE
  447. ON DELETE CASCADE
  448. GO
  449. ALTER TABLE [clearance].[ClearanceRecLine] CHECK CONSTRAINT [FK_ClearanceRecLine_ClearanceRec]
  450. GO
  451. EXEC sys.sp_addextendedproperty @name = N'MS_Description',
  452. @value = N'存货入出库记录行内码', @level0type = N'SCHEMA',
  453. @level0name = N'clearance', @level1type = N'TABLE',
  454. @level1name = N'ClearanceRecLine', @level2type = N'COLUMN',
  455. @level2name = N'ClearanceRecLineId'
  456. GO
  457. EXEC sys.sp_addextendedproperty @name = N'MS_Description',
  458. @value = N'存货入出库记录内码', @level0type = N'SCHEMA', @level0name = N'clearance',
  459. @level1type = N'TABLE', @level1name = N'ClearanceRecLine',
  460. @level2type = N'COLUMN', @level2name = N'ClearanceRecId'
  461. GO
  462. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'存货内码',
  463. @level0type = N'SCHEMA', @level0name = N'clearance',
  464. @level1type = N'TABLE', @level1name = N'ClearanceRecLine',
  465. @level2type = N'COLUMN', @level2name = N'InventoryId'
  466. GO
  467. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'存货编码',
  468. @level0type = N'SCHEMA', @level0name = N'clearance',
  469. @level1type = N'TABLE', @level1name = N'ClearanceRecLine',
  470. @level2type = N'COLUMN', @level2name = N'InventoryNumber'
  471. GO
  472. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'存货名称',
  473. @level0type = N'SCHEMA', @level0name = N'clearance',
  474. @level1type = N'TABLE', @level1name = N'ClearanceRecLine',
  475. @level2type = N'COLUMN', @level2name = N'InventoryName'
  476. GO
  477. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'规格型号',
  478. @level0type = N'SCHEMA', @level0name = N'clearance',
  479. @level1type = N'TABLE', @level1name = N'ClearanceRecLine',
  480. @level2type = N'COLUMN', @level2name = N'Spec'
  481. GO
  482. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'批号',
  483. @level0type = N'SCHEMA', @level0name = N'clearance',
  484. @level1type = N'TABLE', @level1name = N'ClearanceRecLine',
  485. @level2type = N'COLUMN', @level2name = N'BatchNumber'
  486. GO
  487. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'入库数量',
  488. @level0type = N'SCHEMA', @level0name = N'clearance',
  489. @level1type = N'TABLE', @level1name = N'ClearanceRecLine',
  490. @level2type = N'COLUMN', @level2name = N'IncreasedQty'
  491. GO
  492. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'出库数量',
  493. @level0type = N'SCHEMA', @level0name = N'clearance',
  494. @level1type = N'TABLE', @level1name = N'ClearanceRecLine',
  495. @level2type = N'COLUMN', @level2name = N'DecreasedQty'
  496. GO
  497. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'折扣系数',
  498. @level0type = N'SCHEMA', @level0name = N'clearance',
  499. @level1type = N'TABLE', @level1name = N'ClearanceRecLine',
  500. @level2type = N'COLUMN', @level2name = N'DiscountCoef'
  501. GO
  502. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'入库单价',
  503. @level0type = N'SCHEMA', @level0name = N'clearance',
  504. @level1type = N'TABLE', @level1name = N'ClearanceRecLine',
  505. @level2type = N'COLUMN', @level2name = N'IncreasedPrice'
  506. GO
  507. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'出库单价',
  508. @level0type = N'SCHEMA', @level0name = N'clearance',
  509. @level1type = N'TABLE', @level1name = N'ClearanceRecLine',
  510. @level2type = N'COLUMN', @level2name = N'DecreasedPrice'
  511. GO
  512. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'增加金额',
  513. @level0type = N'SCHEMA', @level0name = N'clearance',
  514. @level1type = N'TABLE', @level1name = N'ClearanceRecLine',
  515. @level2type = N'COLUMN', @level2name = N'IncreasedMoney'
  516. GO
  517. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'减少金额',
  518. @level0type = N'SCHEMA', @level0name = N'clearance',
  519. @level1type = N'TABLE', @level1name = N'ClearanceRecLine',
  520. @level2type = N'COLUMN', @level2name = N'DecreasedMoney'
  521. GO
  522. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'行状态',
  523. @level0type = N'SCHEMA', @level0name = N'clearance',
  524. @level1type = N'TABLE', @level1name = N'ClearanceRecLine',
  525. @level2type = N'COLUMN', @level2name = N'LineStatus'
  526. GO
  527. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'记录版本',
  528. @level0type = N'SCHEMA', @level0name = N'clearance',
  529. @level1type = N'TABLE', @level1name = N'ClearanceRecLine',
  530. @level2type = N'COLUMN', @level2name = N'VersionNumber'
  531. GO
  532. EXEC sys.sp_addextendedproperty @name = N'MS_Description', @value = N'备注',
  533. @level0type = N'SCHEMA', @level0name = N'clearance',
  534. @level1type = N'TABLE', @level1name = N'ClearanceRecLine',
  535. @level2type = N'COLUMN', @level2name = N'Description'
  536. GO
  537. EXEC sys.sp_addextendedproperty @name = N'MS_Description',
  538. @value = N'清仓管理.清仓产品入出库记录行', @level0type = N'SCHEMA',
  539. @level0name = N'clearance', @level1type = N'TABLE',
  540. @level1name = N'ClearanceRecLine'
  541. GO
  542. USE [befri_Goldhoo]
  543. GO
  544. SET ANSI_NULLS ON
  545. GO
  546. SET QUOTED_IDENTIFIER ON
  547. GO
  548. -- =============================================
  549. -- 开发人员: lkaih
  550. -- 开发日期: 2016-09
  551. -- 功能描述: 当插入记录时自动更新清仓总帐
  552. -- =============================================
  553. ALTER TRIGGER [clearance].[tri_ClearanceAccDetail_INSERT] ON [clearance].[ClearanceAccDetail]
  554. FOR INSERT
  555. AS
  556. BEGIN
  557. SET NOCOUNT ON;
  558. MERGE clearance.ClearanceAcc AS t
  559. USING INSERTED AS s
  560. ON ( s.WarehouseId = t.WarehouseId
  561. AND s.InventoryId = t.InventoryId
  562. )
  563. WHEN MATCHED
  564. THEN
  565. UPDATE
  566. SET Quantity = Quantity + s.IncreasedQty - s.DecreasedQty ,
  567. [DiscountCoef] = CASE WHEN s.IncreasedQty
  568. - s.DecreasedQty > 0
  569. THEN s.[DiscountCoef]
  570. ELSE t.[DiscountCoef]
  571. END
  572. WHEN NOT MATCHED
  573. THEN
  574. INSERT (
  575. WarehouseId ,
  576. InventoryId ,
  577. Quantity ,
  578. [DiscountCoef]
  579. )
  580. VALUES
  581. ( s.WarehouseId ,
  582. s.InventoryId ,
  583. s.IncreasedQty - s.DecreasedQty ,
  584. s.DiscountCoef
  585. );
  586. END