
public class QualityCheckWebFacadeControllerBean{
	protected void qualityCheck(final List pceIDList,final BigDecimal passQty){
	
		if (pceIDList==null || passQty == null) return;
		
		if (pceIDList.size()==0 || passQty.compareTo(BigDecimal.ZERO)<=0) return;
		
		final StringBuilder sql = new StringBuilder();
		
		//?????????????????????
		sql.setLength(0);
		
		sql.append("Update t_mm_mftordertechnics ut\r\n");
		sql.append("set \r\n");
		sql.append("fpassqty = IsNull(fpassqty,0) + ").append(passQty).append(",\r\n");
		sql.append("fpassbaseqty = IsNull(fpassbaseqty,0) + ").append(passQty).append("\r\n");
		sql.append("Where \r\n");
		sql.append("ut.fid in (\r\n");
		sql.append("select\r\n");
		sql.append("pce.fmfcordtechid\r\n");
		sql.append("from T_SFC_PRODORDERCOMPLETEENTRY pce\r\n");
		sql.append("where\r\n");
		sql.append("1=1\r\n");
		sql.append("and pce.fparentid='").append(pcID).append("'\r\n");
		sql.append(")\r\n");
		
		SQLUtils.execute(ctx,sql.toString());
			
			//???????
			
			//???????????§Û??????????
			sql.setLength(0);
			
			sql.append("Select\r\n");
			sql.append("pce.fid FPCEID,\r\n");
			sql.append("Max(h.fid) FMOID\r\n");
			sql.append("From T_SFC_PRODORDERCOMPLETEENTRY pce\r\n");
			sql.append("inner join T_MM_MFTOrderTechnics d on d.fid=pce.fmfcordtechid\r\n");
			sql.append("inner join T_MM_ManufactureOrder h on h.fid = d.fparentid\r\n");
			sql.append("left outer join t_bd_materialinventory minv on\r\n");
			sql.append("1=1\r\n");
			sql.append("and h.fmaterialid = minv.fmaterialid and h.fstorageorgunitid = minv.forgunit\r\n");
			sql.append("Left Outer Join T_MM_StandardRooting sr On sr.fid = h.Froutingid\r\n");
			sql.append("Left Outer Join T_MM_MaterialRWP mrwp On \r\n");
			sql.append("1=1\r\n");
			sql.append("and mrwp.Fparentid = sr.Fmaterialrootingid \r\n");
			sql.append("And mrwp.Foperationid = d.foperationid\r\n");
			sql.append("where\r\n");
			sql.append("1=1\r\n");
			sql.append("and pce.fparentid='").append(pcID).append("'\r\n");
			sql.append("and IsNull(mrwp.Fispickingpoint,0)=1\r\n");
			sql.append("and isnull(minv.cfisautogeninwarebill,0)=1\r\n");
			sql.append("Group By\r\n");
			sql.append("pce.fid\r\n");
			
			rowSet = null;
			
			rowSet=DBUtil.executeQuery(ctx,sql.toString());
			
			if (rowSet!=null){
				if (rowSet.size()>0){
					while(rowSet.next()){
						final String moID = rowSet.getString("FMOID");
						
						if (moID==null) continue;
						
						if (moID.trim().length()==0) continue;
						
						if (!generateInWarehsMOIDList.contains(moID))
							generateInWarehsMOIDList.add(moID);
					}
				}
			}
			
			if (genInWarehsMOIDList!=null){
				if (genInWarehsMOIDList.size()>0 && passQty>0){
					//???????
					gnerateInWareHSBills(ctx,generateInWarehsMOIDList,passQty);
				}
			}
			
			If (lDc_frepairamount +lDc_fscrapamount > 0  ) Then //??????
				Update t_mm_mftordertechnics set frepairqty = nvl(frepairqty,0) + :lDc_frepairamount,frepairbaseqty = nvl(frepairbaseqty,0) + :lDc_frepairamount,
				fscrapqty = nvl(fscrapqty,0) + :lDc_fscrapamount,fscrapbaseqty = nvl(fscrapbaseqty,0) + :lDc_fscrapamount Where  fid=:lS_PoidRow; 
				if sqlca.sqlcode < 0 then
					rollback;
					messagebox('???','??????????????????????')
					return
				end if
				
				Select fparentid into:lS_parentpoid from T_MM_MFTOrderTechnics where fid = :lS_PoidRow;
				if pos(","+lS_fidlist+",",","+lS_parentpoid+",")  < 1 Then 
					lS_fidlist = lS_fidlist +","+lS_parentpoid;//?????????????????????
				
					update t_mm_manufactureorder set frepairqty = nvl(frepairqty,0) + :lDc_frepairamount,frepairbaseqty = nvl(frepairbaseqty,0) + :lDc_frepairamount,
					fscrapqty = nvl(fscrapqty,0) + :lDc_fscrapamount,fscrapbaseqty = nvl(fscrapbaseqty,0) + :lDc_fscrapamount Where fid 
					in (select fparentid from t_mm_mftordertechnics where   fid=:lS_PoidRow );
					//= :lS_Poid ;
					if sqlca.sqlcode < 0 then
						rollback;
						messagebox('???','???????????????????????')
						return
					end if
				end if
			End If
			
			Update t_mm_mftordertechnics
			set (frepairqty,frepairbaseqty,fscrapqty,fscrapbaseqty ,fpassqty,fpassbaseqty) = 
			(Select frepairqty,frepairbaseqty,fscrapqty,fscrapbaseqty ,fpassqty,fpassbaseqty from t_mm_mftordertechnics where fid =:lS_PoidRow  )
			Where  fmergeid=:ls_mergeid and fid <> :lS_PoidRow; 
			if sqlca.sqlcode < 0 then
				rollback;
				messagebox('???','?????????????????????2??')
				return
			end if

			update t_mm_manufactureorder 
			set( frepairqty,frepairbaseqty,fscrapqty,fscrapbaseqty ,fpassqty,fpassbaseqty)  =
				(Select frepairqty,frepairbaseqty,fscrapqty,fscrapbaseqty ,fpassqty,fpassbaseqty from t_mm_manufactureorder where fid =( select fparentid from t_mm_mftordertechnics where   fid=:lS_PoidRow )) 
			Where fid in (select fparentid from t_mm_mftordertechnics where   fmergeid=:ls_mergeid and  fid <> :lS_PoidRow );
			if sqlca.sqlcode < 0 then
				rollback;
				messagebox('???','??????????????????????2??')
				return
			end if
			
			if (ii_fisjjj = 1) then //?????
				Update t_mm_mftordertechnics Set fbasestatus = 14,FQualityInspectionTime = sysdate,cfqualityinspectioner=:guo_userright.il_userid Where fmergeid=:ls_mergeid
				and  nvl(fpassqty,0) >= fqty and  nvl(fpassqty,0) > 0 ;
				if sqlca.sqlcode < 0 then
					rollback;
					messagebox('???','???????????????????')
					return
				end if
				
				Update t_mm_mftordertechnics Set fbasestatus = 26,FQualityInspectionTime = sysdate,cfqualityinspectioner=:guo_userright.il_userid Where fmergeid=:ls_mergeid
				and  nvl(fpassqty,0) <  fqty and  nvl(fpassqty,0) = 0 ;
				if sqlca.sqlcode < 0 then
					rollback;
					messagebox('???','???????????????????')
					return
				end if
				
				Update t_mm_mftordertechnics Set fbasestatus = 15,FQualityInspectionTime = sysdate,cfqualityinspectioner=:guo_userright.il_userid Where fmergeid=:ls_mergeid
				and  nvl(fpassqty,0) <  fqty and  nvl(fpassqty,0) > 0 ;
			else
				If istr_a.ls_a = 'HG' Then  
					
					Update t_mm_mftordertechnics Set fbasestatus = 14,FQualityInspectionTime = sysdate,cfqualityinspectioner=:guo_userright.il_userid Where fmergeid=:ls_mergeid
					and nvl(fpassqty,0) >= fqty;
					if sqlca.sqlcode < 0 then
						rollback;
						messagebox('???','???????????????????')
						return
					end if
					
					Update t_mm_mftordertechnics Set fbasestatus = 15,FQualityInspectionTime = sysdate,cfqualityinspectioner=:guo_userright.il_userid Where fmergeid=:ls_mergeid
					and nvl(fpassqty,0) < fqty;
				Else
					Update t_mm_mftordertechnics Set fbasestatus = 26,FQualityInspectionTime = sysdate,cfqualityinspectioner=:guo_userright.il_userid Where fmergeid=:ls_mergeid;//fid = :lS_PoidRow ; //26????????
				End If
			End if
			
			if dw_1.update() + dw_2.update() = 2 then
				Commit;
				CloseWithReturn(Parent,'ok')
			Else
				RollBack;
				MessageBox('???','????????????????????????')
				Return
			end if
	}
	
	//???????
	protected void generateInWareHSBill(final Context ctx,final List generateInWarehsMOIDList,final int passQty) throw BOSException,EASBizExceotion{
		
		select
		minv.fdefaultwarehouseid,
		d.Fmergeid,
		h.Fstorageorgunitid,
		h.fcompanyid
		Into :lS_Fwarehouseid,:lS_Megerid,:lS_Orgid,:lS_Companyorgid
		From T_MM_ManufactureOrder h
		Inner join T_MM_MFTOrderTechnics d on h.fid = d.fparentid
		left outer join t_bd_materialinventory minv on
		1=1
		and h.fmaterialid = minv.fmaterialid
		and h.fstorageorgunitid = minv.forgunit
		Where
		1=1
		and d.fid = :ls_fentryid
		and rownum=1
		;
		
		//???????
		Select
		t_bas_paramitem.fvalue_l2
		Into :lS_finorgnumber
		From t_bas_paramitem
		inner join t_bas_param on t_bas_param.fid = t_bas_paramitem.fkeyid
		inner join t_org_storage on t_org_storage.fid = t_bas_paramitem.forgunitid
		where 
		1=1
		and t_bas_param.fnumber='XCPRODINSTORAGEORGUNIT'
		And t_org_storage.Fid=:lS_Orgid
		;
		
		if isnull(lS_finorgnumber) or lS_finorgnumber = "" then
			lS_FSTORAGEORGUNITID =lS_Orgid //??????????????
		else
			Select fid into:lS_finorgid from t_org_storage where fnumber = :lS_finorgnumber;
			if isnull(lS_finorgid) or lS_finorgid = "" then
				lS_FSTORAGEORGUNITID =lS_Orgid //??????????????
			else
				lS_FSTORAGEORGUNITID = lS_finorgid
			end if
		end if
		
		if isnull(lS_Megerid) Or lS_Megerid = '' Then
			return 0
		Else //????????????????????????????????????????????
			
			SELECT
			T_MM_MFTORDERTECHNICS.FPARENTID,   
			T_MM_MFTORDERTECHNICS.FWORKCENTERID,   
			T_MM_MFTORDERTECHNICS.FSTORAGEORGUNITID,   
			T_MM_MFTORDERTECHNICS.FQTY,   
			T_MM_MFTORDERTECHNICS.FBASESTATUS,    
			T_MM_MFTORDERTECHNICS.FID,   
			T_MM_MFTORDERTECHNICS.FOPERATIONNO, 
			T_MM_MFTORDERTECHNICS.FOPERATIONID
			FROM T_MM_MFTORDERTECHNICS   
			Where 1 = 1 
			And T_MM_MFTORDERTECHNICS.fmergeid = '"+lS_Megerid+"'
			;
			
			while(){
				ls_fentryid = lDs_Item.Object.fid[lL_Row]
				//?????????????????ID
				Select NewBosid('FA1292B4') Into:lS_Inid From Dual;
				//?????????????????ID
				Select NewBosid('DBE1161E') Into:lS_InEntryid From Dual; 
				//??????????????????''
				
				Select uf_gettableid(:lS_Yp) Into:lL_BillNumberOrder From Dual;
				lS_RkBillNumber =lS_Yp+String(lL_BillNumberOrder);
				//???????
				Insert Into T_IM_MANUFACTURERECBILL
				(FID ,FCREATORID , FCREATETIME ,  FLASTUPDATEUSERID,  FLASTUPDATETIME,  FCONTROLUNITID ,  FNUMBER,  FBIZDATE,  FHANDLERID,  FDESCRIPTION,
				FHASEFFECTED,  FAUDITORID,  FSOURCEBILLID,  FSOURCEFUNCTION,  FAUDITTIME,  FBASESTATUS,  FBIZTYPEID,  FSOURCEBILLTYPEID,  FBILLTYPEID,
				FYEAR,  FPERIOD ,  FSTORAGEORGUNITID,  FADMINORGUNITID,  FSTOCKERID,  FVOUCHERID,  FTOTALQTY,  FTOTALAMOUNT,  FFIVOUCHERED,
				FTOTALSTANDARDCOST,  FTOTALACTUALCOST,  FISREVERSED,  FTRANSACTIONTYPEID,  FISINITBILL,  FMODIFIERID,  FMODIFICATIONTIME,
				FCOSTCENTERORGUNITID,  FISBACKFLUSHSUCCEED,  FMONTH,  FDAY)
				Select  
				:lS_Inid ,  :guo_userright.il_userid ,  SysDate ,  :guo_userright.il_userid,  SysDate, :lS_FCONTROLUNITID,  :lS_RkBillNumber,  SysDate,  null,  '??????????????',
				null,  null,  T_MM_ManufactureOrder.fid,  null,  null, 1,  :lS_FBIZTYPEID,  null,  :lS_FBILLTYPEID,
				:lL_Year,  :lL_Period ,  :lS_FSTORAGEORGUNITID, T_MM_ManufactureOrder. Fadminorgunitid,  null,  null,  0,  0,  0,
				0,  0,  0,  :lS_FTRANSACTIONTYPEID,  0,  null,  null,
				T_MM_ManufactureOrder.Fstorageorgunitid,  0,  null,  null
				From T_MM_ManufactureOrder where fid = :lS_Fid;
				
				//???????
				Insert Into T_IM_MANUFACTURERECBILLENTRY
				(FID,FSEQ,FSOURCEBILLID,FSOURCEBILLNUMBER,FSOURCEBILLENTRYID,FSOURCEBILLENTRYSEQ,
				FASSCOEFFICIENT,FBASESTATUS,FASSOCIATEQTY,FSOURCEBILLTYPEID,FASSISTPROPERTYID,FMATERIALID,
				FUNITID,FBASEUNITID,FASSISTUNITID,FREASONCODEID,FSTORAGEORGUNITID,FCOMPANYORGUNITID,
				FWAREHOUSEID,FLOCATIONID,FSTOCKERID,FLOT,FQTY,FASSISTQTY,
				FBASEQTY,FREVERSEQTY,FRETURNSQTY,FPRICE,FAMOUNT,FUNITSTANDARDCOST,
				FSTANDARDCOST,FUNITACTUALCOST,FACTUALCOST,FISPRESENT,FPARENTID,FMANUBILLENTRYID,
				FMANUBILLID,FMFG,FEXP,FREMARK,FREVERSEBASEQTY,FRETURNBASEQTY,
				FCOSTOBJECTID,FRECQTY,FBASERECQTY,FMANUBILLNUMBER,FTRACENO,FSALEORDERBILLID,
				FSALEORDERNUM,FRECEIVEQTY,FMANUBILLENTRYSEQ,
				FSALEORDERENTRYSEQ,FPROJECTID,FTRACKNUMBERID,
				FTRANSACTIONTYPEID,FADMINORGUNITID,FBILLBASESTATUS,FYEAR,
				FPERIOD,CFBLANKPARTSWEIGHT,CFWEARWEIGHT,CFSCRAPAPPWEIGHT,FINVUPDATETYPEID
				)
				Select :lS_InEntryid,1,d.fparentid,h.fnumber,d.fid,d.fseq,
				0,1,0,null,null,h.fmaterialid,
				h.Funitid,h.Fbaseunitid,h.Fassistunitid,null,:lS_FSTORAGEORGUNITID,:lS_FCOMPANYORGUNITID,
				:lS_Fwarehouseid,null,null,null,:lD_Fqty,0,
				:lD_Fqty,0,0,0,0,0,
				0,0,0,0,:lS_Inid,null,
				null,null,null,'??????????????',0,0,
				h.Fcostobjectid,0,0,h.fnumber,null,null,
				null,0,0,
				0,h.FPROJECTID,h.Ftrackid,
				:lS_FTRANSACTIONTYPEID,h.Fadminorgunitid,1,:lL_Year, 
				:lL_Period ,0,0,0,'8r0AAAAEaOjC73rf'
				From T_MM_ManufactureOrder h inner join T_MM_MFTOrderTechnics d on h.fid = d.fparentid
				Where d.fid = :ls_fentryid;
				
				//????BOTP????
				//?????????????????ID
				Select NewBosid('59302EC6') Into:lS_Botpid From Dual; 
				Insert Into t_bot_relation(FID, FSRCENTITYID, FDESTENTITYID, FSRCOBJECTID, FDESTOBJECTID, FDATE, FOPERATORID, FISEFFECTED, FBOTMAPPINGID, FTYPE)
				Values(:lS_Botpid,'1D0D80DD','FA1292B4',:lS_Fid,:lS_Inid,sysdate,'UnKnown',1,'','0');
				
			}
		end if
		//??????????????????
		sql.setLength(0);
		
		sql.append("update t_mm_manufactureorder ut\r\n");
		sql.append("set\r\n");
		sql.append("fpassqty = IsNull(fpassqty,0) + ").append(passQty).append(",\r\n");
		sql.append("fpassbaseqty = IsNull(fpassbaseqty,0) + ").append(passQty).append("\r\n");
		sql.append("where\r\n");
		sql.append("1=1\r\n");
		sql.append("and ut.fid='").append(moID).append("'\r\n");
		
	}

}