--2018.11.13
--出库入记录
create or replace view item_crk_view as 
select asn.company_id,ik.item_id,d.received_quantity,'入库' type,to_char(d.receive_date,'yyyy-mm-dd') deal_date from received_record d 
left join asn on asn.id=d.asn_id
left join location l on l.id=d.location_id
left join item_key ik on ik.id=d.item_key_id
where d.received_quantity>0 
union all
select pt.company_id,ptd.item_id,log.ship_quantity,'出库' type, to_char(log.record_time,'yyyy-mm-dd') deal_date from task_log log
left join task t on log.task_id=t.id 
left join pick_ticket_detail ptd on ptd.id=t.pick_ticket_detail_id
left join pick_ticket pt on pt.id=ptd.pick_ticket_id
where t.pick_ticket_detail_id is not null and log.ship_quantity>0;
--波次补货数量
alter table wave_doc_detail add quantity float;
alter table wave_doc_detail add plan_Bh_Qty float;
update wave_doc_detail set quantity=0 where quantity is null;
update wave_doc_detail set plan_Bh_Qty=0 where plan_Bh_Qty is null;

INSERT INTO `global_params`(`DISCRIMINATOR`, `PARAM_ID`, `TYPE`, `GROUP_NAME`, `REF_MODEL`,
`PARAM_VALUE`, `PARAM_BEAN`, `DESCRIPTION`, `MODULE`) VALUES
('com.vtradex.thorn.server.config.globalparam.GlobalParam', 
'SESSION_WAREHOUSE_CODE', 'P_BEAN', '全局变量设置', 'origen', NULL, 'warehouseCodeSession', '记录用户当前登录的仓库信息', NULL);

INSERT INTO `production_plan`(`code`, `number_No`, `NAME`, `Offline_Date`,`country1`, `model_Type`, `model_No`, `model_Name`,  `STR_EXTEND1`,
`STR_EXTEND2`, `STR_EXTEND3`, `procedure1`,  `BigItem_ID`, `long_Extend1`, `zone1_ID`, `zone2_ID`, `STR_EXTEND4`, `out_Type`,  `hy_Time`)
select idno,no,月度序号,下线日期,国别,机型,机号,机型名称,耗用状态,
发货,操作日期,工位,BigItem_ID,序号1,zone1_ID,zone2_ID,制造线,'CKD单点',耗用日期 from scsx where 序号=35175;

update scsx s set zone1_ID=(select id from zone where code=s.收货仓库);
update scsx s set zone2_ID=(select id from zone where name=s.出库仓库);
update scsx s set BigItem_ID=(select id from big_item where code=s.`机型`);


ALTER TABLE design_list add old_Item_Code VARCHAR(100);
ALTER TABLE design_list add new_Item_Code VARCHAR(100);

ALTER table bom_account add createPeople VARCHAR(100);
ALTER table bom_account add createDate datetime DEFAULT now();

ALTER table Plan_Assembly add plan_no VARCHAR(100);
ALTER table Plan_Assembly add createPeople VARCHAR(100);
ALTER table Plan_Assembly add createDate datetime DEFAULT now();

update location set type='SHIP' where id=5121;-- 发货暂存区
-- CKD单点单据类型维护

ALTER table pick_ticket_detail add DEFAULT(0) for quantity4 with VALUES;
ALTER table pick_ticket_detail add DEFAULT(0) for quantity with VALUES;
ALTER table pick_ticket_detail add DEFAULT(0) for xq_Qty with VALUES;
ALTER table pick_ticket_detail add DEFAULT(0) for inv_Qty with VALUES;

ALTER TABLE pick_ticket_detail MODIFY quantity4 double DEFAULT 0;
ALTER TABLE pick_ticket_detail MODIFY quantity double DEFAULT 0;
ALTER TABLE pick_ticket_detail MODIFY xq_Qty double DEFAULT 0;
ALTER TABLE pick_ticket_detail MODIFY inv_Qty double DEFAULT 0;

update pick_ticket_detail set quantity4=0 where quantity4 is null;
update pick_ticket_detail set quantity=0 where quantity is null;
update pick_ticket_detail set xq_Qty=0 where xq_Qty is null;
update pick_ticket_detail set inv_Qty=0 where inv_Qty is null;

update pick_ticket set quantity4=0 where quantity4 is null;

ALTER table print_xpp_record add bh_by VARCHAR(100);
ALTER table print_xpp_record add bh_Date datetime;
ALTER table print_xpp_record add fh_by VARCHAR(100);
ALTER table print_xpp_record add fh_Date datetime;


ALTER table design_list add old_Item_Code VARCHAR(100);
ALTER table design_list add new_Item_Code VARCHAR(100);

ALTER table inventory_log add bhr VARCHAR(100);
ALTER table inventory_log add cph VARCHAR(100);
ALTER table inventory_log add tph VARCHAR(100);

-- 库存唯一建
-- itemkey上 soi不要存信息，清空现有的，唯一建
-- 入库单把之前收货的状态改为‘已收货’

-- 下线数据，吊装数据接收

-- 系统代码

-- 枚举表

update inventory_log inv  set LOCATION_ID=2661 where inv.LOG_TYPE='SHIPPING_ADJUST' 
and inv.ZONE_ID not in (select id from zone where code in ('久荣协同仓库(保)CKD','久荣协同仓库(课)CKD'));

ALTER table Bom_Account add zzkw_id BIGINT;
ALTER table inventory add zzkw_id BIGINT;
ALTER table inventory_log add zzkw_id BIGINT;
ALTER table pick_ticket_detail add zzkw_id BIGINT;
ALTER table Plan_Pick_Detail add zzkw_id BIGINT;
update Bom_Account set zzkw_id =(select id from location where code='0') where zzkw_id is null;
update inventory set zzkw_id=(select id from location where code='0') where zzkw_id is null;
update inventory_log set zzkw_id=(select id from location where code='0') where zzkw_id is null;
ALTER TABLE pick_ticket_detail add quantity5 double DEFAULT 0;
ALTER TABLE pick_ticket_detail add xs double DEFAULT 0;
update pick_ticket_detail set quantity5=0 where quantity5 is null;
update pick_ticket_detail set xs=0 where xs is null;
ALTER table asn_detail add zzkw_id BIGINT;

-- 耗用，入库确认 ,其他入库和其他出库需要选择库位，导入也要库位

ALTER table ZONE add hckw_id BIGINT;
ALTER table ZONE add gw  VARCHAR(10);
ALTER table ZONE add be_ship   BIGINT;
update ZONE set be_ship=0 where be_ship is  null;

--制造库位
update location set type='PROCESS' where id in (SELECT zzkw_id from bom_account where zzkw_id is not null);
--线边接收数量
ALTER TABLE task_log add XB_QUANTITY double DEFAULT 0;
update task_log set XB_QUANTITY=0 where XB_QUANTITY is null;
ALTER table location add bar_Code VARCHAR(20);

INSERT into enumerate(ENUM_TYPE,ENUM_VALUE) VALUES ('LocationType','HCKW');
ALTER TABLE location add hckw_code VARCHAR(50);
ALTER TABLE location add hckw_id BIGINT;
ALTER TABLE Bom_Account add hckw_id BIGINT;

ALTER TABLE ZONE add be_zz_hy BIGINT DEFAULT 0;
update ZONE set be_zz_hy=0 where be_zz_hy is null;

ALTER table task_log add sl_by VARCHAR(100);
ALTER table task_log add sl_Date datetime;
ALTER table task_log add fh_by VARCHAR(100);
ALTER table task_log add fh_Date datetime;

ALTER table pick_ticket add sl_by VARCHAR(100);
ALTER table pick_ticket add fh_by VARCHAR(100);

ALTER table Spare_Parts add auto_code VARCHAR(50);
ALTER table Production_Plan add auto_Production_ID BIGINT;

ALTER TABLE pick_ticket_detail add  double DEFAULT 0;
ALTER TABLE pick_ticket add tl_qty double DEFAULT 0;
ALTER table pick_ticket add tl_by VARCHAR(100);
ALTER table pick_ticket add tl_date datetime;
update pick_ticket_detail set tl_qty=0 where tl_qty is null;
update pick_ticket set tl_qty=0 where tl_qty is null;

