ddl.sql 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. -- 项目ddl SQL语句统一放在这里记录,包括表结构、关联关系、索引、函数、存储过程等
  2. -- 每段sql语句必须要按规范注释,注释规范如下:
  3. -- date: 2018-12-11
  4. -- author: suntg
  5. -- content: 内容备注xxx
  6. -- date: 2018-12-12 17:51
  7. -- author: hejq
  8. -- content: 供应商关系表增加字段,需要对账金额,次更新时间,
  9. -- 采用字符串是因为需要分币别统计处理
  10. alter table `purc$vendors`
  11. add column todo_apchek_count VARCHAR(100) default '' comment '需要对账金额',
  12. add column update_time datetime comment '上一次更新时间';
  13. -- date: 2018-12-18 14:42
  14. -- author: hejq
  15. -- 更新purc$vendors 字段todo_apchek_count长度
  16. alter table purc$vendors modify todo_apchek_count varchar(200);
  17. -- date: 2018-12-19 09:51
  18. -- author: huj
  19. -- content: 采购明细单增加替代料号、替代料名称、替代料规格三个字段(帝显LED物料需求)
  20. alter table `purc$orderitems`
  21. add column pd_repprodcode VARCHAR(255) comment '替代料号',
  22. add column pd_repprodtitle VARCHAR(255) comment '替代料名称',
  23. add column pd_repprodspec VARCHAR(255) comment '替代料规格';
  24. -- date: 2018-12-25 10:51
  25. -- author: huj
  26. -- content: 采购明细单增加旧料编号、旧料名称、旧料规格三个字段(帝显LED物料需求)
  27. alter table `purc$orderitems`
  28. add column pd_prodoldcode VARCHAR(255) comment '旧料编号',
  29. add column pd_prodoldtitle VARCHAR(255) comment '旧料名称',
  30. add column pd_prodoldspec VARCHAR(255) comment '旧料规格';
  31. -- date: 2018-12-20 11:34
  32. -- author: hejq
  33. -- content: 对账明细增加单据来源时间
  34. ALTER TABLE purc$apcheckitem ADD COLUMN pai_source_date DATETIME COMMENT '单据来源时间';
  35. -- date: 2018-12-20 11:53
  36. -- author: hejq
  37. -- content: 更新类型为采购验收单单据来源时间
  38. update purc$apcheckitem
  39. left join purc$acceptitem on purc$apcheckitem.pai_sourcetable = 'purc$acceptitem' and purc$apcheckitem.pai_sourceid = purc$acceptitem.pai_id
  40. left join `purc$accept` on purc$acceptitem.pai_paid = purc$accept.pa_id
  41. set purc$apcheckitem.pai_source_date = purc$accept.pa_date where purc$apcheckitem.pai_source_date is null;
  42. -- date: 2018-12-20 13:38
  43. -- author: hejq
  44. -- content: 更新类型为货款调账单据来源时间
  45. update purc$apcheckitem
  46. left join purc$apbilladjustment on pai_sourcetable = 'purc$apbilladjustment' and pai_sourceid = aa_id
  47. set pai_source_date = aa_orderdate where pai_sourcetable = 'purc$apbilladjustment' and pai_source_date is null;
  48. -- date: 2018-12-20 13:46
  49. -- author: hejq
  50. -- content: 更新类型为采购验退单单据来源时间
  51. update purc$apcheckitem
  52. left join purc$returnitem on pai_sourcetable = 'purc$returnitem' and pai_sourceid = pri_id
  53. left join `purc$return` on pri_prid = pr_id
  54. set pai_source_date = pr_date where pai_sourcetable = 'purc$returnitem' and pai_source_date is null;
  55. -- date: 2018-12-20 13:49
  56. -- author: hejq
  57. -- content: 更新类型为不良品入库单单据来源时间
  58. update purc$apcheckitem
  59. left join purc$badinitem on pai_sourcetable = 'purc$badinitem' and pai_sourceid = pbi_id
  60. left join `purc$badin` on pbi_pbid = pb_id
  61. set pai_source_date = pb_date where pai_sourcetable = 'purc$badinitem' and pai_source_date is null;
  62. -- date: 2018-12-20 13:53
  63. -- author: hejq
  64. -- content: 更新类型为不良品出库单单据来源时间
  65. update purc$apcheckitem
  66. left join purc$badoutitem on pai_sourcetable = 'purc$badoutitem' and pai_sourceid = poi_id
  67. left join `purc$badout` on poi_poid = po_id
  68. set pai_source_date = po_date where pai_sourcetable = 'purc$badoutitem' and pai_source_date is null;
  69. -- date: 2018-12-20 13:57
  70. -- author: hejq
  71. -- content: 更新类型为委外验收单单据来源时间
  72. update purc$apcheckitem
  73. left join make$acceptitem on pai_sourcetable = 'make$acceptitem' and pai_sourceid = mai_id
  74. left join `make$accept` on mai_paid = ma_id
  75. set pai_source_date = ma_date where pai_sourcetable = 'make$acceptitem' and pai_source_date is null;
  76. -- date: 2018-12-20 13:58
  77. -- author: hejq
  78. -- content: 更新类型为委外验退单单据来源时间
  79. update purc$apcheckitem
  80. left join make$returnitem on pai_sourcetable = 'make$returnitem' and pai_sourceid = mri_id
  81. left join `make$return` on mri_paid = mr_id
  82. set pai_source_date = mr_date where pai_sourcetable = 'make$returnitem' and pai_source_date is null;
  83. -- date: 2018-12-20 15:18
  84. -- author: hejq
  85. -- content: 1、 优软商城采购对接人为空,插入记录,对接人为陈艳平;
  86. -- 2、 优软商城采购对接人为18320952803(UU:2000012807)的更新为陈艳平
  87. insert into sale$distribute (pd_distribute, pd_istransfer, pd_useruu, pd_vdid)
  88. select 1,0,1000004274,ve_id from `purc$vendors` where ve_myenuu = 10042875
  89. and not exists (select 1 from sale$distribute where ve_id = pd_vdid);
  90. update `sale$distribute` set pd_useruu = 1000004274 where pd_useruu = 2000012807 and
  91. pd_vdid in (select ve_id from `purc$vendors` where ve_myenuu = 10042875);
  92. -- date: 2018-12-25 9:10
  93. -- author: hejq
  94. -- content: 供应商客户关系表增加对账总额字段
  95. alter table `purc$vendors`
  96. add column apcheck_count VARCHAR(200) default '' comment '对账总额(已对账和未对账之和)';
  97. -- date: 2018-12-28 17:19
  98. -- author: hejq
  99. -- content: 更新发货提醒判断逻辑
  100. -- 新增函数,返回可发货日期
  101. CREATE DEFINER=`sa`@`%` FUNCTION `b2b_mysql_test`.`purc_notice_delivery`(v_pn_delivery date,
  102. v_pr_ltinstock int) RETURNS date
  103. begin
  104. if v_pr_ltinstock = -1 then
  105. -- 这里设置减去两个月最后一天再加上26天即指定月份的26号
  106. return last_day(v_pn_delivery) + interval (-2) month + interval (26) day;
  107. else
  108. return v_pn_delivery - interval (v_pr_ltinstock + 1) day;
  109. end if;
  110. end;
  111. -- 更新判断方法,根据生成的可发货日期与当前日期比较,大于或等于可以发货,其他状态不能发货
  112. CREATE DEFINER=`sa`@`%` FUNCTION `b2b_mysql_test`.`PURC_NOTICE_WAIT_TO_SEND`(v_pn_delivery date,
  113. v_pr_ltinstock int) RETURNS smallint(6)
  114. begin
  115. -- 可以发货的时间
  116. declare enable_delivery date;
  117. set enable_delivery := purc_notice_delivery(v_pn_delivery, coalesce(v_pr_ltinstock, 0));
  118. if to_days(current_date()) - to_days(enable_delivery) >= 0 then
  119. return 0;
  120. else
  121. return 1;
  122. end if;
  123. end
  124. -- date: 2019-01-02 18:51
  125. -- author: huj
  126. -- content: ERP主动收料通知明细id
  127. alter table `sale$senditem`
  128. add column si_sourceid bigint(20) comment 'ERP主动收料通知明细id';
  129. -- date: 2019-01-02 18:51
  130. -- author: huj
  131. -- content: ERP主动收料通知id
  132. alter table `sale$send`
  133. add column ss_sourceid bigint(20) comment 'ERP主动收料通知明细id';
  134. alter table `purc$acceptitem`
  135. add column b2b_si_id bigint(20) comment '送货单明细id';
  136. end;
  137. -- date: 2019-01-03 13:40
  138. -- author: hejq
  139. -- content: 出入库单据添加字段收款金额,收款日期
  140. -- 采购验收单
  141. alter table `purc$acceptitem`
  142. add column pai_payment double comment '付款金额',
  143. add column pai_paydate datetime comment '付款日期';
  144. -- 采购验退单
  145. alter table `purc$returnitem`
  146. add column pri_payment double comment '付款金额',
  147. add column pri_paydate datetime comment '付款日期';
  148. -- 不良品入库单
  149. alter table `purc$badinitem`
  150. add column pbi_payment double comment '付款金额',
  151. add column pbi_paydate datetime comment '付款日期';
  152. -- 不良品出库单
  153. alter table `purc$badoutitem`
  154. add column poi_payment double comment '付款金额',
  155. add column poi_paydate datetime comment '付款日期';
  156. -- 委外验收单
  157. alter table `make$acceptitem`
  158. add column mai_payment double comment '付款金额',
  159. add column mai_paydate datetime comment '付款日期';
  160. -- 委外验退单
  161. alter table `make$returnitem`
  162. add column mri_payment double comment '付款金额',
  163. add column mri_paydate datetime comment '付款日期';
  164. -- 货款调账
  165. alter table `purc$apbilladjustment`
  166. add column aa_payment double comment '付款金额',
  167. add column aa_paydate datetime comment '付款日期';
  168. -- date: 2019-01-03 15:48
  169. -- author: hejq
  170. -- content: 增加出入库单付款数据更新传输记录
  171. create table `prodiopay` (
  172. `pi_id` bigint(20) not null auto_increment,
  173. `pi_code` varchar(100) default null COMMENT '出入库单号',
  174. `pi_class` varchar(100) default null COMMENT '出库单类型',
  175. `pi_detno` smallint(6) default null COMMENT '明细序号',
  176. `pi_enuu` bigint(20) default null COMMENT '录入企业UU',
  177. `pi_amount` double default null COMMENT '付款金额',
  178. `pi_source_date` datetime default null COMMENT '付款日期',
  179. `pi_source_id` bigint(20) default null COMMENT 'erp明细id',
  180. `pi_date` datetime default null COMMENT '录入日期',
  181. primary key (`pi_id`)
  182. ) ENGINE=InnoDB auto_increment=1 default CHARSET=utf8;
  183. -- date: 2019-01-04 9:49
  184. -- author: hejq
  185. -- content: 对账明细增加付款金额
  186. alter table purc$apcheckitem add column pai_payment double COMMENT '付款金额';
  187. -- date: 2019-01-04 13:59
  188. -- author: hejq
  189. -- content: 对账单明细增加送货明细id,送货数量和单价
  190. alter table purc$apcheckitem
  191. add column pai_send_id BIGINT COMMENT '送货单明细id',
  192. add column pai_send_qty DOUBLE COMMENT '送货数量',
  193. add column pai_send_price DOUBLE COMMENT '送货单价';
  194. -- date: 2019-01-15 16:51
  195. -- author: huj
  196. -- content: 漳州万利达需求新增物料承认状态
  197. alter table `purc$orderitems`
  198. add column pd_prmaterial VARCHAR(255) comment '物料承认状态';