📄 sfc_enter_mounitmnrequest.pas
字号:
Inherited;
//如果未保存打印,则调用Frm_Sfc_MnOut_NotSave_P,否则调用Frm_Sfc_MnOut_P
end;
procedure TFrm_Sfc_Enter_MoUnitMnRequest.FormActivate(Sender: TObject);
begin
OnActivate := Nil;
if IsAfterprint=False then
inherited;
//初始化仓库
end;
procedure TFrm_Sfc_Enter_MoUnitMnRequest.cmbbx_WhCodeExit(Sender: TObject);
var
tmp_WhCode,tmp_WhPositionCode:string;
begin
inherited;
//调用初始化货位过程
initcmbbx_WhPositionCode(getCode(cmbbx_WhCode.text));
//如果独立订单,则让货位显示在'冻结货位'上 ,WhPositionType=2表示冻结货位
tmp_WhCode:=getCode(cmbbx_WhCode.text);
Cmbbx_WhPositionCode.ItemIndex := 0;
//调用初化仓库过程
InitCmbbx_WhEmployee(getCode(cmbbx_WhCode.text));
//由于仓库的改变,调用cmbbx_WhPositionCode的OnExit事件重新刷新数据
// if Trim(cmbbx_WhPositionCode.Text)<>'' then
// cmbbx_WhPositionCode.OnExit(sender);
end;
procedure TFrm_Sfc_Enter_MoUnitMnRequest.SaveData;
var
M,N:integer;
tmp_qty:real;
Billno,Billid:string;
saveplace:tBookmArk;
SqlText : String;
TmpAdoQry : TAdoQuery;
TotalRequestQty : Double; // 总请领量
ThisRequestQty : Double; //本次请领量
TotalThisQty : Double;
begin
// inherited;
TotalThisQty := 0;
if AdoQry_Body.State in [dsEdit,dsInsert] then
AdoQry_Body.Post;
medt_Date.onexit(medt_Date);
AdoQry_Body.Connection.beginTrans;
try
saveplace:=AdoQry_Body.GetBookmArk;
AdoQry_Body.DisableControls;
//检验库存
AdoQry_Body.First;
for M:=0 to AdoQry_Body.recordCount-1 do
begin
If AdoQry_Body.fieldbyname('ThisRequestQty').AsFloat<=0 then
begin
AdoQry_Body.Next;
continue;
end;
checkcoCurrentqty;
if (AdoQry_Body.fieldbyname('ThisRequestqty').asstring<>'0') then
begin
TotalThisQty := TotalThisQty + AdoQry_Body.fieldbyname('ThisRequestqty').AsFloat;
if not InvQtyCheck
(False,
AdoQry_Body,
AdoQry_tmp,
getCode(cmbbx_WhCode.text),
getCode(cmbbx_WhPositionCode.text),
AdoQry_Body.fieldbyname('ItemCode').asstring,
'ThisRequestqty',
AdoQry_Body.fieldbyname('ThisRequestqty').asfloat,
False) then
begin
AdoQry_Body.gotoBookmArk(saveplace);
AdoQry_Body.freeBookmArk(saveplace);
AdoQry_Body.enablecontrols;
abort;
end;
if AdoQry_Body.fieldbyname('Batchno').asstring<>'' then
begin
//批次库存检验
if not BatchInvCheck(AdoQry_tmp,
AdoQry_Body.fieldbyname('Batchno').asstring,
'C',
getCode(cmbbx_WhCode.text),
getCode(cmbbx_WhPositionCode.text),
AdoQry_Body.fieldbyname('ThisRequestqty').asfloat) then
begin
AdoQry_Body.gotoBookmArk(saveplace);
AdoQry_Body.freeBookmArk(saveplace);
AdoQry_Body.enablecontrols;
abort;
end;
end;
end;
AdoQry_Body.next;
end;
If TotalThisQty = 0 Then
begin
DispInfo('本次请领量总数不能为0!',3);
Dbgrideh.SetFocus;
Abort;
end;
//生产单据号
Billno:=getno(AdoQry_Body.Connection,getCode(cmbbx_WhCode.text)+'C'+copy(medt_Date.text,3,2)+copy(medt_Date.text,6,2),'InvBill');
//增加InvOutBill
AdoQry_tmp.Close;
AdoQry_tmp.sql.clear;
AdoQry_tmp.sql.Add('insert InvOutBill'+
'(InvBillno,'+
'whCode,'+
'InvBilldate,'+
'InvBillMonth,'+
'DeptCode,'+
'BillTypeCode,'+
'Sal_EmployeeCode,'+
'EmployeeCode,'+
'Sfc_EmployeeCode,'+
'wh_EmployeeCode2,'+
'WhPositionCode,'+
'shiftType,'+
'IsMoUnitRequest,'+
// 'WipWaster,'+
'InvBillremArk)'+
'Values('''+Billno+''','+
''''+getCode(cmbbx_WhCode.text)+''','+
''''+medt_Date.text+''','+
''''+copy(medt_Date.text,1,7)+''','+
''''+getCode(Edt_Dept.Text)+''','+
'''0201'','+
''''+userCode+''','+
''''+userCode+''','+
''''+userCode+''','+
''''+getCode(cmbbx_WhEmployee.text)+''','+
''''+getCode(cmbbx_WhPositionCode.text)+''','+
''''+cmbbx_Shift.text+''','+
'1,'+
// inttostr(cmbx_WipWaster.Itemindex)+','+
''''+Extedt_memo.text+''')');
AdoQry_tmp.execsql;
//取InvBillID
AdoQry_tmp.Close;
AdoQry_tmp.sql.clear;
AdoQry_tmp.sql.Add(' select @@IDENTITY as Billid ');
AdoQry_tmp.open;
Billid:=AdoQry_tmp.fieldbyname('Billid').asstring;
TmpAdoQry := TAdoQuery.Create(self) ;
TmpAdoQry.Connection := Dbconnect;
TmpAdoQry.EnableBCD := False;
AdoQry_Body.First;
N := 1;
While NOt AdoQry_Body.Eof do
begin
//增加表InvOutBillLINE 只增加不为零的数量
If AdoQry_Body.fieldbyname('ThisRequestQty').AsFloat<=0 Then
begin
AdoQry_Body.Next;
Continue;
end;
TotalRequestQty := AdoQry_Body.fieldbyname('ThisRequestQty').AsFloat;
ThisRequestQty := 0;
If AdoQry_Body.fieldbyname('OnHandInv').AsFloat<TotalRequestQty Then
TotalRequestQty := AdoQry_Body.fieldbyname('OnHandInv').AsFloat;
ExecuteSQl(TmpAdoQry,'select * from #MnItemList '
+' where ItemCode='+QuotedStr(AdoQry_Body.fieldbyname('ItemCode').AsString)
+' and MoCtrlQty >= MoRealQty '
+' and IsTotal=0 ',0);
While Not TmpAdoQry.Eof do
begin
If TotalRequestQty<=0 then Break;
If ((TmpAdoQry.fieldbyname('MoCtrlQty').AsFloat-TmpAdoQry.fieldbyname('MoRealQty').AsFloat)>0 )
and ( (TmpAdoQry.fieldbyname('MoCtrlQty').AsFloat-TmpAdoQry.fieldbyname('MoRealQty').AsFloat) > TotalRequestQty ) then
begin
ThisRequestQty := TotalRequestQty;
// TotalRequestQty := TotalRequestQty-TmpAdoQry.fieldbyname('MoCtrlQty').AsFloat;
TotalRequestQty := 0;
end
else
begin
ThisRequestQty := TmpAdoQry.fieldbyname('MoCtrlQty').AsFloat-TmpAdoQry.fieldbyname('MoRealQty').AsFloat;
TotalRequestQty := TotalRequestQty-(TmpAdoQry.fieldbyname('MoCtrlQty').AsFloat-TmpAdoQry.fieldbyname('MoRealQty').AsFloat);
end;
If ThisRequestQty <= 0 then
begin
{DispInfo('生产订单行'+TmpAdoQry.fieldbyname('MoNo').AsString
+'--'+TmpAdoQry.fieldbyname('MoLineNo').AsString
+'物料'+QuotedStr(TmpAdoQry.fieldbyname('ItemCode').AsString)
+'不能超额领料!',3);
Abort; }
TmpAdoQry.Next;
continue;
end;
SqlText := 'insert InvOutBillline'+
'(InvBillid,'+
'InvBilllineno,'+
'mono,'+
'MoLineno,'+
'ItemCode,'+
'ite_ItemCode,'+
'BilllineremArk,'+
'Batchno,'+
'ItemListid,'+
'InvBillSfcqty)'+
'Values('+Billid+','+
''''+inttostr(N)+''','+
''''+TmpAdoQry.fieldbyname('MoNo').AsString+''','+
TmpAdoQry.fieldbyname('MoLineno').asstring+','+
''''+TmpAdoQry.fieldbyname('ItemCode').asstring+''','+
''''+TmpAdoQry.fieldbyname('ite_ItemCode').asstring+''','+
''''+AdoQry_Body.fieldbyname('BillLineremArk').asstring+''','+
''''+AdoQry_Body.fieldbyname('Batchno').asstring+''','+
TmpAdoQry.fieldbyname('ItemListid').asstring+','+
FloatToSTr(ThisRequestQty)+')';
ExecuteSql(AdoQry_Tmp,SqlText,1);
SqlText := ' update MnItemList '
+' set MoRequestQty = IsNull(MoRequestQty,0)+'+FloatToStr(ThisRequestQty)
+' where ItemListId='+TmpAdoQry.fieldbyname('ItemListId').AsString
+' update #MnItemList '
+' set MoRequestQty = IsNull(MoRequestQty,0)+'+FloatToStr(ThisRequestQty)
+' ,ThisRequestQty ='+FloatToStr(ThisRequestQty)
+' ,BatchNo='+QuotedStr(AdoQry_Body.fieldbyname('BatchNo').AsString)
+' ,BillLineRemArk =' +QuotedStr(AdoQry_Body.fieldbyname('BillLineRemArk').AsString)
+' where ItemListId='+TmpAdoQry.fieldbyname('ItemListId').AsString;
ExecuteSql(AdoQry_Tmp,SqlText,1);
Inc(N);
TmpAdoQry.Next;
end;
AdoQry_Body.next;
end;
AdoQry_Body.GotoBookmArk(saveplace);
AdoQry_Body.FreeBookmArk(saveplace);
AdoQry_Body.EnableControls;
AdoQry_Body.Connection.CommitTrans;
act_auto.Enabled :=False;
dbgrideh.ReadOnly :=True;
// dbgrideh1.ReadOnly :=True;
Extedt_Billno.text:=Billno;
///////
TmpAdoQry.Free;
except
AdoQry_Body.Connection.RollBackTrans;
AdoQry_Body.EnableControls ;
If Assigned(TmpAdoQry) Then TmpAdoQry.Free;
DispInfo(' 存盘不成功,请稍后再试! ',1);
Abort;
end;
end;
procedure TFrm_Sfc_Enter_MoUnitMnRequest.Act_NewExecute(Sender: TObject);
begin
Extedt_Billno.text:='';
IsAfterprint:=False;
inherited;
end;
procedure TFrm_Sfc_Enter_MoUnitMnRequest.DBGridEhExit(Sender: TObject);
begin
inherited;
if AdoQry_Body.State in [dsEdit, dsInsert] then
AdoQry_Body.Post;
end;
procedure TFrm_Sfc_Enter_MoUnitMnRequest.Extedt_BillnoChange(Sender: TObject);
begin
inherited;
//
end;
procedure TFrm_Sfc_Enter_MoUnitMnRequest.medt_DateChange(Sender: TObject);
begin
inherited;
//
end;
procedure TFrm_Sfc_Enter_MoUnitMnRequest.DataSourceDataChange(Sender: TObject;
Field: TField);
begin
inherited;
if status='ReadOnly' then
act_Save.Enabled :=False
else
act_Save.Enabled :=True;
end;
procedure TFrm_Sfc_Enter_MoUnitMnRequest.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
inherited;
Try
ExecuteSql(AdoQry_Tmp,'Drop Table #MnItemList',1);
except
end;
Extedt_Billno.text:='';
if AdoQry_Body.state in [dsEdit] then AdoQry_Body.Cancel;
AdoQry_Body.Close;
end;
procedure TFrm_Sfc_Enter_MoUnitMnRequest.cmbbx_WhCodeChange(Sender: TObject);
begin
inherited;
//
InitCmbbx_WhPositionCode(GEtCode(Cmbbx_WhCode.Text));
ShowDbgrid;
end;
procedure TFrm_Sfc_Enter_MoUnitMnRequest.cmbbx_WhPositionCodeChange(Sender: TObject);
begin
inherited;
ShowDbgrid;
end;
procedure TFrm_Sfc_Enter_MoUnitMnRequest.Act_SaveExecute(Sender: TObject);
begin
If (cmbbx_WhCode.Text = '') or (Cmbbx_WhPositionCode.Text = '' ) then
begin
DispInfo('仓库和货位不能为空!',3);
Cmbbx_WhCode.SetFocus;
abort;
end;
inherited;
act_New.Enabled := False;
Button1.Enabled := True;
Button2.Enabled := True;
end;
procedure TFrm_Sfc_Enter_MoUnitMnRequest.DateCheck(Sender: TObject);
begin
inherited;
if not WHClsPeriodCheck(AdoQry_tmp,getCode(cmbbx_WhCode.text),copy(medt_Date.text,1,7)) then
begin
twincontrol(sender).setfocus;
abort;
end;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -