📄 inv_opsumout_b.pas
字号:
PriceType:=AdoQry_Tmp.fieldbyname('PriceType').AsInteger;
end;
for I:=0 to AdoQry_Body.RecordCount-1 do
begin
If round(AdoQry_Body.fieldbyname('PoOutQty').AsFloat*1000)/1000=0 then
begin
AdoQry_Body.next;
continue;
end;
if not InvQtyCheck
(NeedChangePrice,
AdoQry_Body,
AdoQry_tmp,
getCode(Cmbx_WhCodeName.text),
getCode(Cmbx_Position.Text),
AdoQry_Body.fieldbyname('ItemCode').asstring,
'PoOutQty',
AdoQry_Body.fieldbyname('PoOutQty').asfloat,
False) then
begin
disableall(True);
//AdoQry_Body.Connection.RollBackTrans;
AdoQry_Body.EnableControls;
abort;
end;
if AdoQry_Body.fieldbyname('BatchNo').asstring<>'' then
if not BatchInvCheck(AdoQry_Tmp,
AdoQry_Body.fieldbyname('BatchNo').asstring,'c',
getCode(Cmbx_WhCodeName.Text),
getCode(Cmbx_Position.Text),
AdoQry_Body.fieldbyname('POOutQty').asfloat) then Abort;
AdoQry_Body.Next;
end;
try
AdoQry_Tmp.Connection.beginTrans;
BillNo:=GetNo(AdoQry_Tmp.Connection,GetCode(Cmbx_WhCodeName.Text)+'C'+
FormatDateTime('yymm',StrToDate(Medt_Date.Text)),
'InvBill');
ChangeInvStatus(AdoQry_tmp,getCode(Cmbx_WhCodeName.text),copy(Medt_Date.text,1,7));
With AdoQry_Tmp do
begin
Close;
Sql.clear;
//增加单据头记录
AdoQry_tmp.sql.Add('insert into InvOutBill'+
'(InvBillno,'+
'whCode,'+
'InvBilldate,'+
'InvBillMonth,'+
'BillTypeCode,'+
'EmployeeCode,'+
'WH_EmployeeCode,'+
'VendorCode,'+
'PoNo,'+
'WhPositionCode,'+
'InvBillremArk)'+
'Values('''+Billno+''','+
''''+getCode(Cmbx_WhCodeName.text)+''','+
''''+Trim(medt_Date.text)+''','+
''''+copy(medt_Date.text,1,7)+''','+
''''+BillTypeCode+''','+
''''+userCode+''','+
''''+userCode+''','+
''''+GetCode(Lbl_VendorCodeName.Caption)+''','+
''''+FPoNo+''','+
''''+getCode(Cmbx_Position.text)+''','+
''''+Edt_memo.text+''')');
AdoQry_tmp.execsql;
AdoQry_tmp.Close;
AdoQry_tmp.sql.clear;
AdoQry_tmp.sql.Add(' select @@IDENTITY as Billid ');
AdoQry_tmp.open;
Billid:=AdoQry_tmp.fieldbyname('Billid').asstring;
end;
AdoQry_Body.First;//开始进行保存
for I:=0 to AdoQry_Body.RecordCount-1 do
begin
//如果该项物料领料数量为零,则下一个
If AdoQry_Body.fieldbyname('PoOutQty').AsFloat=0 then
begin
AdoQry_Body.next;
continue;
end;
Price:=0;
if True then //NeedChangePrice then
begin
if PriceType=0 then
begin
//正常委外领料,按常规移动加权平均价的算法计算
If AdoQry_Body.fieldbyname('PoOutQty').AsFloat>0 then
begin
//更改移动价
AdoQry_tmp.Close;
AdoQry_tmp.sql.clear;
AdoQry_Tmp.Sql.Add('UpDate AveragePrice'+
' Set ApQty=ApQty-('+
AdoQry_Body.fieldbyname('PoOutQty').AsString+'),'+
'ApAmount=case when Apqty=0 then 0 else round(ApAmount/Apqty*(Apqty-('+AdoQry_Body.fieldbyname('PoOutQty').AsString+')),2) end'+
' where whCode='''+getCode(Cmbx_WhCodeName.Text)+''' and '+
' ItemCode='''+AdoQry_Body.fieldbyname('ItemCode').AsString+'''');
AdoQry_Tmp.ExecSQL;
//获取当前价格
AdoQry_tmp.Close;
AdoQry_tmp.sql.clear;
AdoQry_Tmp.Sql.Add('Select AveragePrice from AveragePrice'+
' where whCode='''+getCode(Cmbx_WhCodeName.Text)+''' and '+
' ItemCode='''+AdoQry_Body.fieldbyname('ItemCode').AsString+'''');
AdoQry_Tmp.open;
Price:=AdoQry_Tmp.fieldbyname('AveragePrice').asfloat;
end
//退料,则视作入库,按入库的移动加权平均价算法计算
//入库价来自供应商当前的移动价
Else If AdoQry_Body.fieldbyname('PoOutQty').AsFloat<0 then
begin
//计算数量、金额
AdoQry_tmp.Close;
AdoQry_tmp.sql.clear;
AdoQry_Tmp.Sql.Add('UpDate AveragePrice'+
' Set ApQty=ApQty-('+
AdoQry_Body.fieldbyname('PoOutQty').AsString+'),'+
'ApAmount=ApAmount-round('+AdoQry_Body.fieldbyname('PoOutQty').AsString+
'*(Select OpAveragePrice From OpAveragePrice '+
' Where VendorCode='''+GetCode(Lbl_VendorCodeName.Caption)+''''+
' and ItemCode='''+AdoQry_Body.fieldbyname('ItemCode').AsString+'''),2)'+
' where whCode='''+getCode(Cmbx_WhCodeName.Text)+''' and '+
' ItemCode='''+AdoQry_Body.fieldbyname('ItemCode').AsString+'''');
AdoQry_Tmp.ExecSQL;
//获取入库的价格
AdoQry_tmp.Close;
AdoQry_tmp.sql.clear;
AdoQry_Tmp.Sql.Add('Select OpAveragePrice From OpAveragePrice '+
' Where VendorCode='''+GetCode(Lbl_VendorCodeName.Caption)+''''+
' and ItemCode='''+AdoQry_Body.fieldbyname('ItemCode').AsString+'''');
AdoQry_Tmp.open;
Price:=AdoQry_Tmp.fieldbyname('OPAveragePrice').asfloat;
//计算价格
AdoQry_tmp.Close;
AdoQry_tmp.sql.clear;
AdoQry_Tmp.SQL.Add('Update AveragePrice '+
' Set AveragePrice=case when Apqty=0 then 0 else (ApAmount/ApQty) end '+
' where whCode='''+getCode(Cmbx_WhCodeName.Text)+''' and '+
' ItemCode='''+AdoQry_Body.fieldbyname('ItemCode').AsString+''' and '+
' ApQty<>0 and ApQty is not null');
AdoQry_Tmp.ExecSQL;
end;
end
else
//如果本仓库属于计划价仓库
begin
AdoQry_tmp.Close;
AdoQry_tmp.sql.clear;
AdoQry_tmp.sql.text:=
'select isnull((Select isnull(SPPrice,0) From StandardPrice where '+
'SPStArtMonth='''+copy(medt_Date.text,1,7)+''''+
' and ItemCode='''+AdoQry_Body.fieldbyname('ItemCode').AsString+'''),0) Price';
AdoQry_tmp.Open;
Price:=AdoQry_tmp.fieldbyname('Price').asfloat;
end;
end;
//一对多更新opItemList
if Not BatchSaveByNo(BillId,
AdoQry_Body.fieldbyname('BatchNo').Asstring,
AdoQry_Body.fieldbyname('ItemCode').Asstring,
AdoQry_Body.fieldbyname('BillLineRemArk').Asstring,
AdoQry_Body.fieldbyname('POOutQty').AsFloat,Price) then Abort;
//更新当前库存及批次库存
if UpdateInv(AdoQry_Tmp,
getCode(Cmbx_WhCodeName.text),
getCode(Cmbx_Position.text),
AdoQry_Body.fieldbyname('ItemCode').asstring,
'(-('+AdoQry_Body.fieldbyname('POOutQty').asstring+'))',
NeedChangePrice,True)<>'' then
abort;
//更新供应商库存
AdoQry_Tmp.Close;
AdoQry_Tmp.Sql.clear;
AdoQry_Tmp.SQL.Add('Select Count(*) as RecCount from OPCurrentInv '+
' Where VendorCode='''+GetCode(Lbl_VendorCodeName.Caption)+''''+
' and ItemCode='''+AdoQry_Body.fieldbyname('ItemCode').AsString+'''');
AdoQry_Tmp.Open;
If AdoQry_Tmp.fieldbyname('RecCount').AsInteger<=0 then
begin
AdoQry_tmp.Close;
AdoQry_Tmp.Sql.clear;
AdoQry_Tmp.SQL.Add('Insert OPCurrentInv '+
' (VendorCode,'+
' ItemCode,'+
' OpInv)'+
'Values('''+GetCode(Lbl_VendorCodeName.Caption)+''','+
''''+AdoQry_Body.fieldbyname('ItemCode').AsString+''','+
'0)');
AdoQry_Tmp.ExecSQL;
end;
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.clear;
AdoQry_tmp.SQL.Add('Update OPCurrentInv Set'+
' OpInv=OpInv+'+AdoQry_Body.fieldbyname('PoOutQty').AsString+
' Where VendorCode='''+GetCode(Lbl_VendorCodeName.Caption)+''''+
' and ItemCode='''+AdoQry_Body.fieldbyname('ItemCode').AsString+'''');
AdoQry_Tmp.ExecSQL;
if AdoQry_Body.fieldbyname('BatchNo').asstring<>'' then
ChangeBatchInv(AdoQry_Tmp,
AdoQry_Body.fieldbyname('BatchNo').asstring,
'c',formatdatetime('YYYY.MM.DD',date),
getCode(Cmbx_WhCodeName.text),
getCode(Cmbx_Position.text),
AdoQry_Body.fieldbyname('POOutQty').asFloat);
//更新价格
if True then//NeedChangePrice then
begin
If (AdoQry_Body.fieldbyname('PoOutQty').AsFloat>0) or (PriceType=1) then
begin
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.clear;
AdoQry_Tmp.SQL.Add('Select Count(*) as RecCount from OPAveragePrice'+
' Where VendorCode='''+GetCode(Lbl_VendorCodeName.Caption)+''''+
' and ItemCode='''+AdoQry_Body.fieldbyname('ItemCode').AsString+'''');
AdoQry_Tmp.OPen;
If AdoQry_Tmp.fieldbyname('RecCount').AsInteger<=0 then
begin
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.clear;
AdoQry_Tmp.SQL.Add('Insert OPAveragePrice'+
'(VendorCode,'+
'ItemCode,'+
'OPApQty,'+
'OPApAmount)'+
'select '''+GetCode(Lbl_VendorCodeName.Caption)+''','+
''''+AdoQry_Body.fieldbyname('ItemCode').AsString+''','+
AdoQry_Body.fieldbyname('PoOutQty').AsString+','+
'Round('+AdoQry_Body.fieldbyname('POOutQty').asstring+
'*'+floattostr(Price)+',2)');
AdoQry_Tmp.ExecSql;
end
Else
begin
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.clear;
AdoQry_Tmp.SQL.Add('UpDate OpAveragePrice Set '+
' OpApQty=OpApQty+'+AdoQry_Body.fieldbyname('PoOutQty').AsString+','+
' OpApAmount=OpApAmount'+
'+Round('+AdoQry_Body.fieldbyname('POOutQty').asstring+
'*'+floattostr(Price)+',2) '+
'Where ItemCode='''+AdoQry_Body.fieldbyname('ItemCode').AsString+''''+
' and VendorCode='''+GetCode(Lbl_VendorCodeName.Caption)+'''');
AdoQry_Tmp.ExecSql;
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.clear;
AdoQry_Tmp.SQL.Add('UpDate OpAveragePrice Set '+
' OpAveragePrice=Case '+
'OpApQty When '+
'0 then OpAveragePrice '+//modify by 2001.06.24
'Else OpApAmount/opApqty '+
'end Where ItemCode='''+AdoQry_Body.fieldbyname('ItemCode').AsString+''''+
' and VendorCode='''+GetCode(Lbl_VendorCodeName.Caption)+'''');
AdoQry_Tmp.ExecSql;
end;
end
Else
//委外退料
begin
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.clear;
AdoQry_Tmp.SQL.Add('UpDate OpAveragePrice Set '+
' OpApQty=OpApQty+'+AdoQry_Body.fieldbyname('PoOutQty').AsString+','+
' OpApAmount=case when opApqty=0 then 0 else '+
'Round((OpApAmount/OpApqty)*(OPApQty+'+
AdoQry_Body.fieldbyname('PoOutQty').AsString+'),2) end '+
'Where ItemCode='''+AdoQry_Body.fieldbyname('ItemCode').AsString+''''+
' and VendorCode='''+GetCode(Lbl_VendorCodeName.Caption)+'''');
AdoQry_Tmp.ExecSQL;
end;
end;
AdoQry_Body.Next;
end;
AdoQry_Tmp.Connection.CommitTrans;
AdoQry_Body.EnableControls;
Edt_BillNo.Text:=BillNo;
Edt_BillNo.Enabled:=False;
except
DispInfo('保存失败,请稍候再试!',1);
AdoQry_Tmp.Connection.RollBackTrans;
AdoQry_Body.EnableControls;
end;
end;
procedure TFrm_Inv_OpSumOut_B.SetStatus(CurrentStatus: String;
var AnswerStatus, EnableControls: String);
begin
inherited;
if (CurrentStatus='Add') then
begin
AnswerStatus:='Add';
EnableControls:='Cmbx_WhCodeName,Cmbx_Position,Medt_Date,Edt_Memo,';
Addormodify:=True;
end
else
begin
Addormodify:=False;
EnableControls:='Cmbx_WhCodeName,Cmbx_Position,';
AnswerStatus:='Alledit';
end;
end;
procedure TFrm_Inv_OpSumOut_B.SetUserParam(Param1, Param2, Param3, Param4,
Param5, Param6: String);
begin
inherited;
FPoNo:=Param2;
BillTypeCode:=Param3;
end;
procedure TFrm_Inv_OpSumOut_B.AdoQry_BodyBeforePost(DataSet: TDataSet);
var
a1,a2,a3:real;
begin
inherited;
if AdoQry_Body.fieldbyname('POoutQty').asstring='' then
begin
AdoQry_Body.fieldbyname('PoOutQty').asstring:='0';
Abort;
end;
if AdoQry_Body.fieldbyname('PoOutQty').asstring='0' then
begin
AdoQry_Body.fieldbyname('BatchNo').asstring:='';
Exit;
end;
if not InvQtyCheck
(False,
AdoQry_Body,
AdoQry_tmp,
getCode(Cmbx_WhCodeName.text),
getCode(Cmbx_Position.Text),
AdoQry_Body.fieldbyname('ItemCode').asstring,
'POoutQty',
AdoQry_Body.fieldbyname('poOutqty').asfloat,
False) then
begin
AdoQry_Body.Cancel;
abort;
end;
if BatchCtrl(AdoQry_Tmp,AdoQry_Body.fieldbyname('ItemCode').asstring) then
if Not BatchNoCheck(AdoQry_Tmp,AdoQry_Body.fieldbyname('BatchNo').asstring,
AdoQry_Body.fieldbyname('ItemCode').asstring,'',
Medt_Date.Text) then Abort;
a1:=AdoQry_Body.fieldbyname('POoutQty').asfloat;
a2:=min(
round(AdoQry_Body.fieldbyname('POCtrlQty').asfloat)-
round(AdoQry_Body.fieldbyname('PORealQty').asfloat),
AdoQry_Body.fieldbyname('UseableStore').asfloat);
if a1>a2 then
begin
DispInfo('本次领料数量不能大于未领料数量或可用库存!',1);
AdoQry_Body.Cancel;
abort;
end;
a1:=AdoQry_Body.fieldbyname('POoutQty').asfloat;
a2:=abs(AdoQry_Body.fieldbyname('POoutQty').asfloat);
a3:=AdoQry_Body.fieldbyname('PoRealQty').asfloat;
if (a1<0) and (a2>a3)
then
begin
DispInfo('冲销数量不能大于累计领料数量!',1);
AdoQry_Body.Cancel;
abort;
end;
act_Save.Enabled :=True;
end;
procedure TFrm_Inv_OpSumOut_B.Act_PreviewExecute(Sender: TObject);
begin
//inherited;
BillPrint(AdoQry_Tmp.Connection,GetCode(Cmbx_WhCodeName.text),Edt_BillNo.text,'0202'{RecTypeCode},ModuleCode,True,False,True,'');
end;
procedure TFrm_Inv_OpSumOut_B.Act_PrintExecute(Sender: TObject);
begin
//inherited;
BillPrint(AdoQry_Tmp.Connection,GetCode(Cmbx_WhCodeName.text),Edt_BillNo.text,'0202'{RecTypeCode},ModuleCode,False,False,True,'');
end;
procedure TFrm_Inv_OpSumOut_B.FormCreate(Sender: TObject);
begin
inherited;
TlBtn_Modify.Action:=Act_Auto;
end;
procedure TFrm_Inv_OpSumOut_B.Act_autoExecute(Sender: TObject);
var
i:integer;
mypost:TDataSetNotifyEvent;
Tmp_var:Double;
BatchNo:String;
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -