123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302 |
- //create or replace PROCEDURE "CS_PACKCARTON"
- //-- =============================================
- //-- Author: <XIAOST>
- //-- Create date: <2017-09-23>
- //-- Description: <装卡通箱
- //-- 1、 支持自动生成箱号,
- //-- 2、 支持转入已存在箱号,
- //-- 3、 标准装箱需要产品和箱号的包装规则一致 包含:按合同 SALE,按订单 MAKE ,按产品 PROD,混合 MIX
- //-- 4、 特殊装箱,无需考虑装箱规则等限制
- //-- >
- //-- =============================================
- //( /*
- // 参数:输入 -- SN号,箱号,是否自动生成,装箱类型,岗位资源,操作人编号
- // 输出 --箱号,异常信息
- // */
- // v_i_sncode in varchar2, --SN
- // v_i_outboxcode in varchar2, --卡通箱号
- // v_i_autonew in varchar2 default 'N', --默认否
- // v_i_type in varchar2 ,-- 装箱类型,标准或者特殊,默认标准
- // v_i_sourcecode in varchar2, --岗位资源编号
- // v_i_usercode in varchar2, --人员编号
- // v_i_standardqty in number, --标准容量
- // v_i_inorout in varchar2, ---装箱或取消装箱入或者出 IN, OUT
- // v_o_outboxcode out varchar2, --输出卡通箱号
- // v_o_errmsg out varchar2 ---输入异常信息
- //) as
- // v_pr_packrule product.pr_packrule%type; --产品包装规则
- //v_pr_outboxinnerqty product.pr_outboxinnerqty%type;--装箱容量
- //v_pa_packtype varchar2(20); --卡通箱装箱类型
- //v_pa_standardqty number; ---标准容量
- //v_pa_currentqty number;
- // v_pa_prodcode varchar2(50);
- //v_pa_makecode varchar2(50);
- //v_pa_salecode varchar2(50);
- //v_pa_downstatus number; --是否下地
- //v_pa_id number;
- // v_pa_status number;
- //v_pa_checkno varchar2(30);
- //v_pa_currentstep varchar2(60);
- //v_pa_mothercode varchar2(50);
- //v_pa_outno varchar2(50);
- //v_ob_status varchar2(20);
- //v_outboxcode varchar2(30);
- //v_ms_prodcode varchar2(50);
- //v_ms_makecode make.ma_code%type;
- //v_ms_id makeserial.ms_id%type;
- //v_ms_outboxcode varchar2(50);
- //v_ms_craftcode varchar2(50);
- //v_ms_salecode varchar2(50);
- //v_ms_downstatus number; --是否下地
- //v_currentstep varchar2(50);
- //v_linecode varchar2(50);
- //v_scstatuscode varchar2(50);
- //v_stepname varchar2(100);
- //v_wccode varchar2(30);
- //v_count int;
- // v_new int:=0; ---0表示否,-1 需要新增箱号
- //BEGIN
- // --初始化输出参数值
- // v_o_errmsg:=null;
- // v_o_outboxcode:=null;
- // --判定岗位资源
- // select sc_statuscode,sc_stepcode,sc_linecode,sc_stepname,sc_wccode into v_scstatuscode,v_currentstep,v_linecode,v_stepname ,v_wccode from source where sc_code=v_i_sourcecode;
- // IF v_scstatuscode<>'AUDITED' or v_scstatuscode is null THEN
- // v_o_errmsg:='岗位资源不存在或者未审核';
- //RETURN;
- // END IF;
-
- // --获取序列号
- // select max(ms_id) into v_ms_id from makeserial where ms_sncode = v_i_sncode;
- // IF(v_ms_id>0)THEN
- // select ms_outboxcode,ms_prodcode,ms_salecode,ms_makecode,pr_packrule,ms_craftcode,pr_outboxinnerqty,nvl(ms_downstatus,0) into v_ms_outboxcode, v_ms_prodcode, v_ms_salecode, v_ms_makecode, v_pr_packrule, v_ms_craftcode, v_pr_outboxinnerqty, v_ms_downstatus from makeserial left join product on pr_code=ms_prodcode where ms_id=v_ms_id;
- // ELSE
- // v_o_errmsg:='序列号:'||v_i_sncode||'不存在';
- // RETURN;
- // END IF;
-
- // --判断是否下地
- // IF(v_ms_downstatus<>0)THEN
- // v_o_errmsg:='序列号:'||v_i_sncode||'不允许采集,下地状态不允许采集';
- // RETURN;
- // END IF;
-
- // --装箱
- // IF('IN'=v_i_inorout)THEN
- // --必须是未装箱,如果是已装箱提示
- // IF(NVL(v_ms_outboxcode,' ')<>' ')THEN
- // IF(v_ms_outboxcode= v_i_outboxcode)THEN
- // v_o_errmsg:='序列号:'||v_i_sncode||'已在箱内';
- // RETURN;
- // ELSE
- // v_o_errmsg:='序列号:'||v_i_sncode||'不允许采集,已装入箱号:'||v_ms_outboxcode;
- // RETURN;
- // END IF;
- //END IF;
- // --判断有传入需装箱号
- // IF(nvl(v_i_outboxcode,' ')<>' ')THEN
- // v_outboxcode :=v_i_outboxcode;
- // BEGIN
- // select pa_id,pa_prodcode,pa_salecode,pa_maKEcode,pa_packtype,pa_standardqty,nvl(pa_currentqty,0),pa_status,pa_downstatus into v_pa_id,v_pa_prodcode,v_pa_salecode,v_pa_makecode,v_pa_packtype,v_pa_standardqty,v_pa_currentqty,v_pa_status,v_pa_downstatus from package where pa_outboxcode=v_i_outboxcode and pa_type=1;
- // IF(NVL(v_pa_downstatus,0)<>0)THEN
- // v_o_errmsg:='箱号:'||v_i_outboxcode||'处于下地状态,不允许操作!';
- // RETURN;
- // END IF;
- //EXCEPTION
- //WHEN OTHERS THEN --需要新增箱号
- // v_new := -1;
- // END;
- // ELSE --没有传入箱号,并且也没有勾选自动生成箱号
- // IF(NVL(v_i_autonew,'N')='N')THEN
- // v_o_errmsg:='无装箱箱号,请输入装箱箱号或者勾选自动生成箱号!';
- // RETURN;
- // ELSE --生成新箱号
- // v_new := -1;
- // SP_GETPACKORPALLETCODE('PACKAGE', v_ms_makecode, v_ms_prodcode, v_linecode, v_outboxcode);
- //END IF;
- //END IF;
- // IF(v_i_type= '标准')THEN--标准装箱
- // IF(v_new= -1)THEN
- // ---页面传了标准容量
- // /*IF(v_i_standardqty<=0)THEN
- // IF(v_pr_outboxinnerqty>0)THEN
- // v_pa_standardqty:=v_pr_outboxinnerqty;
- // ELSE
- // v_outboxcode:=null;
- // v_o_errmsg:='请维护箱标准容量或者维护产品资料中的包装容量!';
- // RETURN;
- // END IF;
- // ELSE
- // v_pa_standardqty:=v_i_standardqty;
- // END IF;*/
- // IF(v_pr_outboxinnerqty>0)THEN
- // v_pa_standardqty:=v_pr_outboxinnerqty;
- // ELSE
- // v_outboxcode:=null;
- // v_o_errmsg:='请维护箱标准容量或者维护产品资料中的包装容量!';
- // RETURN;
- // END IF;
- //v_pa_id := package_seq.nextval;
- // insert into package(PA_ID, PA_OUTBOXCODE, PA_PRODCODE, PA_LEVEL, PA_PACKAGEQTY, PA_TOTALQTY,
- // PA_MAKECODE, PA_STATUS, PA_INDATE, PA_SALECODE, PA_TYPE, PA_CURRENTQTY, PA_PACKTYPE, PA_STANDARDQTY, PA_SCCODE)
- // values(v_pa_id, v_outboxcode,case when nvl(v_pr_packrule,' ')<>'MIX' then v_ms_prodcode ELSE''END,3,0,0,case when v_pr_packrule = 'MAKE' THEN v_ms_makecode ELSE '' END,
- // 0,SYSDATE,case when v_pr_packrule = 'SALE' then v_ms_salecode else ''end,1,0,v_pr_packrule,v_pa_standardqty,v_i_sourcecode);
- // ELSE --无需新增箱号
- // --判断箱是否已装满
- // IF(v_pa_currentqty= v_pa_standardqty)THEN
- // v_o_errmsg:='箱号:'||v_outboxcode||'已经满箱,请输入新箱号或勾选自动生成箱号!';
- // RETURN;
- // ELSIF(nvl(v_pa_status,0)<>0)THEN
- // v_o_errmsg:='箱号:'||v_outboxcode||'已经封箱,请输入新箱号或勾选自动生成箱号!';
- // RETURN;
- // END IF;
-
- // --判断序列号包装规则与箱内规则一致
- // --IF(v_pa_currentqty= 0 or (v_pa_currentqty>0 and v_pr_packrule = v_pa_packtype))THEN
- // IF(v_pa_currentqty>0 and v_pr_packrule = v_pa_packtype)THEN
- // IF(v_pr_packrule= 'SALE' AND v_ms_salecode<>v_pa_salecode)THEN
- // v_o_errmsg:='包装规则为:合同,序列号和卡通箱合同号不一致,不能装入该箱';
- // RETURN;
- // ELSIF(v_pr_packrule= 'SALE' AND v_ms_prodcode<>v_pa_prodcode)THEN
- // v_o_errmsg:='包装规则为:合同,序列号产品编号'||v_ms_prodcode||'和箱的产品编号'||v_pa_prodcode||'不一致,不能装入该箱';
- // RETURN;
- // ELSIF(v_pr_packrule= 'MAKE' AND v_ms_makecode<>v_pa_makecode)THEN
- // v_o_errmsg:='包装规则为:工单,序列号和卡通箱工单号不一致,不能装入该箱';
- // RETURN;
- // ELSIF(NVL(v_pr_packrule,'PROD')='PROD' AND v_ms_prodcode<>v_pa_prodcode)THEN
- // v_o_errmsg:='序列号:'||v_i_sncode||'产品编号和卡通箱产品编号不一致,不能装入该箱';
- // RETURN;
- // END IF;
- // ELSIF(v_pa_currentqty>0 and NVL(v_pr_packrule,' ')<>NVL(v_pa_packtype,' '))THEN
- // v_o_errmsg:='序列号:'||v_i_sncode||'对应产品的包装规则与箱号的包装规则不一致,不能装入同一箱';
- // RETURN;
- // END IF;
- //END IF;
- //ELSE --特殊装箱
- // v_pr_packrule:='SPEC';
- // IF(v_new= -1)THEN
- // ---页面必须传标准容量
- // IF(v_i_standardqty<=0)THEN
- // v_outboxcode:=null;
- // v_o_errmsg:='请维护箱标准容量!';
- // RETURN;
- // END IF;
- //v_pa_id := package_seq.nextval;
- // insert into package(PA_ID, PA_OUTBOXCODE, PA_PRODCODE, PA_LEVEL, PA_PACKAGEQTY, PA_TOTALQTY,
- // PA_MAKECODE, PA_STATUS, PA_INDATE, PA_SALECODE, PA_TYPE, PA_CURRENTQTY, PA_PACKTYPE, PA_STANDARDQTY, PA_SCCODE)
- // values(v_pa_id, v_outboxcode, v_ms_prodcode,3,0,0,'',0, SYSDATE,'',1,0, v_pr_packrule, v_i_standardqty, v_i_sourcecode);
- //ELSE --无需新增箱号
- // --判断箱是否已装满
- // IF(v_pa_currentqty= v_pa_standardqty)THEN
- // v_o_errmsg:='箱号:'||v_outboxcode||'已经满箱,请输入新箱号或勾选自动生成箱号!';
- // RETURN;
- // -- ELSIF(nvl(v_pa_status,0)<>0)THEN
- // -- v_o_errmsg:='箱号:'||v_outboxcode||'已经封箱,请输入新箱号或勾选自动生成箱号!';
- // -- RETURN;
- // END IF;
- //END IF;
- //END IF;
- // --装明细
- // insert into packagedetail(PD_ID, PD_PAID, PD_OUTBOXCODE, PD_INNERQTY, PD_BARCODE, PD_MAKECODE, PD_PRODCODE, PD_BUILDDATE, PD_YMD)
- // VALUES(packagedetail_seq.NEXTVAL, v_pa_id, v_outboxcode,1, v_i_sncode, v_ms_makecode, v_ms_prodcode, sysdate, to_char(sysdate,'yyyymmdd'));
- // --更新序列号所在箱号
- // update makeserial set ms_outboxcode=v_outboxcode,ms_currentstepcode=v_currentstep where ms_id=v_ms_id;
- // --更新装箱规则 pa_currentqty = 0
- // update package set pa_packtype = v_pr_packrule, PA_SCCODE = v_i_sourcecode, pa_salecode =case when v_pr_packrule = 'SALE' then v_ms_salecode else ''end,pa_makecode=case when v_pr_packrule = 'MAKE' THEN v_ms_makecode ELSE '' END,pa_prodcode=case when v_pr_packrule<>'MIX' then v_ms_prodcode ELSE''END where pa_outboxcode= v_outboxcode and pa_currentqty = 0;
- //update package set pa_currentqty = nvl(pa_currentqty, 0) + 1, pa_totalqty = nvl(pa_totalqty, 0) + 1, pa_packageqty = nvl(pa_packageqty, 0) + 1 where pa_outboxcode = v_outboxcode;
- // --取消装箱
- // ELSIF('OUT'=v_i_inorout)THEN
- // IF(NVL(v_ms_outboxcode,' ')=' ')THEN
- // v_o_errmsg:='序列号没有装箱,无需取消装箱';
- // RETURN;
- // END IF;
- // --取消装箱必须有箱号v_i_outboxcode
- // IF(NVL(v_i_outboxcode,' ')=' ' OR v_i_outboxcode = NULL)then
- // v_o_errmsg:='请选择需要取消装箱的箱号';
- // RETURN;
- // END IF;
- // IF(v_i_outboxcode<> v_ms_outboxcode)THEN
- // v_o_errmsg:='序列号不在箱号:'||v_i_outboxcode||',无法取消装箱';
- // RETURN;
- // END IF;
- // --箱号未封装,允许取消
- // select count(1) into v_count from packagedetail where pd_outboxcode = v_i_outboxcode and pd_barcode = v_i_sncode;
- // IF(v_count= 0)THEN
- // v_o_errmsg:='序列号不在箱号:'||v_i_outboxcode||',无法取消装箱';
- // RETURN;
- // END IF;
- //select pa_id, pa_prodcode, pa_status, pa_checkno, pa_currentqty, pa_downstatus into v_pa_id, v_pa_prodcode, v_pa_status, v_pa_checkno, v_pa_currentqty, v_pa_downstatus from package where pa_outboxcode = v_i_outboxcode and pa_type = 1;
- // IF(NVL(v_pa_downstatus,0)<>0)THEN
- // v_o_errmsg:='箱号:'||v_i_outboxcode||'处于下地状态,不允许操作!';
- // RETURN;
- // END IF;
- //delete from packagedetail where pd_outboxcode=v_i_outboxcode and pd_barcode=v_i_sncode;
- // --更新序列号所在箱号
- // update makeserial set ms_outboxcode='',ms_currentstepcode=null where ms_id = v_ms_id;
- // --更新数量,抽检批次号,更新未封箱
- // update package set pa_currentqty=pa_currentqty-1,pa_totalqty=pa_totalqty-1,pa_packageqty=pa_packageqty-1,pa_status=0 where pa_outboxcode = v_i_outboxcode;
- //update package set pa_packtype = null, pa_sccode = null, pa_checkno = null, pa_salecode = null, pa_makecode = null, pa_prodcode = null where pa_outboxcode = v_i_outboxcode and pa_currentqty = 0;
- // IF(nvl(v_pa_checkno,' ')<>' ')THEN
- // --未断批直接移除,更新数量
- // select MAX(OB_STATUS) INTO v_ob_status from oqcbatch where ob_checkno = v_pa_checkno;
- // IF(NVL(v_ob_status,' ')=' ' or v_ob_status = 'ENTERING')THEN
- // --更新序列号抽检批次号
- // update makeserial set ms_checkno=null where ms_id = v_ms_id;
- // --删除oqcbatchdetail
- // delete from oqcbatchdetail where obd_checkno = v_pa_checkno and obd_sncode = v_i_sncode;
- // --更新OQCBATCH 数量
- // update OQCBATCH set ob_nowcheckqty = ob_nowcheckqty - 1 where ob_checkno = v_pa_checkno;
- //END IF;
- //END IF;
- // --如果序列号已有抽检批次号,
- // /* IF(nvl(v_pa_checkno,' ')<>' ')THEN
- // --未断批直接移除,更新数量
- // select MAX(OB_STATUS) INTO v_ob_status from oqcbatch where ob_checkno=v_pa_checkno;
- // IF(NVL(v_ob_status,' ')=' ' or v_ob_status='ENTERING')THEN
- // --取消装箱
- // delete from packagedetail where pd_outboxcode=v_i_outboxcode and pd_barcode=v_i_sncode;
- // --更新序列号所在箱号
- // update makeserial set ms_outboxcode='',ms_checkno='',ms_currentstepcode=null where ms_id=v_ms_id;
- // --更新数量,抽检批次号,更新未封箱
- // update package set pa_currentqty=pa_currentqty-1,pa_status=0 where pa_outboxcode=v_i_outboxcode;
- // update package set pa_packtype='',pa_checkno='',pa_sccode='' where pa_outboxcode=v_i_outboxcode and pa_currentqty=0;
- // --删除oqcbatchdetail
- // delete from oqcbatchdetail where obd_checkno=v_pa_checkno and obd_sncode=v_i_sncode;
- // --更新OQCBATCH 数量
- // update OQCBATCH set ob_nowcheckqty=ob_nowcheckqty-1 where ob_checkno=v_pa_checkno;
- // ELSE
- // v_o_errmsg:='序列号对应的抽检批次号已经断批.不允许取消装箱';
- // RETURN;
- // END IF;
- // ELSE --无送检批次号
- // delete from packagedetail where pd_outboxcode=v_i_outboxcode and pd_barcode=v_i_sncode;
- // --更新序列号所在箱号
- // update makeserial set ms_outboxcode='',ms_currentstepcode=null where ms_id=v_ms_id;
- // --更新数量,抽检批次号,更新未封箱
- // update package set pa_currentqty=pa_currentqty-1,pa_status=0 where pa_outboxcode=v_i_outboxcode;
- // update package set pa_packtype='',pa_sccode='' where pa_outboxcode=v_i_outboxcode and pa_currentqty=0;
- // END IF; */
- // --修改完工状态,mcd_inqty
- // v_o_outboxcode:=v_i_outboxcode;
- // END IF;
- //EXCEPTION--统一的异常捕捉
- // WHEN OTHERS THEN
- // BEGIN
- // v_o_errmsg:=SQLERRM;
- // ROLLBACK;
- // IF SQLCODE<> 0 THEN
- // BEGIN
- // v_o_errmsg := v_o_errmsg || dbms_utility.format_error_backtrace();
- //END;
- // END IF;
- //END;
- // END;
|