📄 inv_otherin_b.pas
字号:
IoType:=0;
//单据类型
BillTypeCode:=Param1;
lbl_OutName.enabled:=False;
lb_Vendortaxrate_Percent.enabled:=False;
lbl_CurrencyName.enabled:=False;
end;
procedure TFrm_Inv_OtherIn_B.SetStatus(CurrentStatus:String;var AnswerStatus,
EnableControls:String);
begin//指明当前状态,定义Enable=True的控件
inherited;
if CurrentStatus='Add' then
begin
AnswerStatus:='Add';
EnableControls:='Extedt_memo,';
end
else if CurrentStatus='ReadOnly' then
begin
AnswerStatus:='ReadOnly';
EnableControls:='';
end;
end;
procedure TFrm_Inv_OtherIn_B.SaveHeadData;
begin
inherited;
with AdoQry_Head do
begin
fieldbyname('whCode').asstring:=getCode(cmbbx_WhCode.text);
fieldbyname('WhPositionCode').asstring:=getCode(cmbbx_WhPositionCode.text);
fieldbyname('InvBilldate').asstring:=medt_Date.text;
fieldbyname('InvBillno').asstring:=Billno;
fieldbyname('BillType2Code').asstring:=getCode(cmbbx_BillType2Code.Text);
fieldbyname('InvBillremArk').asstring:=Extedt_memo.text;
fieldbyname('InvBilltaxrate').asstring:=copy(lb_Vendortaxrate_Percent.text,1,length(lb_Vendortaxrate_Percent.text)-1);
fieldbyname('currencyCode').asstring:=lbl_CurrencyName.text;
end;
//此程序不能做这一事件,因为用了CASE语句,所以不能增加
end;
procedure TFrm_Inv_OtherIn_B.FormCreate(Sender: TObject);
begin
inherited;
IsAfterprint:=False;
issecondinsert:=False;
Frm_Entry_Detail:=TFrm_Inv_OtherIn_D.Create(Self);//设置弹出Detail
SetFocus_Control:=cmbbx_WhCode;//设置 新增时要聚焦的Control
cmbbx_WhCode.OnChange:=cmbbx_WhCodeChange;
end;
procedure TFrm_Inv_OtherIn_B.Extedt_OutCode1Exit(Sender: TObject);
var
currencyName:string;
begin
//inherited;
//如果是供应商,则选出供应产的税率,币种,如果币种为外币,还要取当前最近月份的汇率
//如果是部门或空,则不用取币种或税率
if cmbbx_OutType.text='供应商' then
begin
UsableVendorCodecheck(sender);
with AdoQry_tmp do
begin
Close;
sql.clear;
sql.Add(' select Vendor.currencyCode,'+
' currency.currencyCode,currency.currencyName,'+
' Vendortaxrate_Percent '+
' from Vendor '+
' left join currency '+
' on Vendor.currencyCode=currency.currencyCode '+
' where Vendor.VendorCode='''+Extedt_OutCode.text+'''');
open;
currencyCode:=fieldbyname('currencyCode').asstring;
Vendortaxrate_Percent:=fieldbyname('Vendortaxrate_Percent').asstring;
lb_Vendortaxrate_Percent.text:=fieldbyname('Vendortaxrate_Percent').asstring+'%';
lbl_CurrencyName.text:=fieldbyname('currencyCode').asstring+' '+fieldbyname('currencyName').asstring;
currencyName:=fieldbyname('currencyCode').asstring+' '+fieldbyname('currencyName').asstring;
if currencyCode<>'00' then
begin
Close;
sql.clear;
sql.Add('select ExchRate from ExchRate where exchMonth='''+copy(medt_Date.text,1,7)+''' and currencyCode='''+currencyCode+'''');
open;
if not eof then
begin
ExchRate:=fieldbyname('ExchRate').asstring;
end
else
begin
//这里将存在一个问题,暂不考虑
DispInfo('该供应商主控货币'+currencyCode+' '+currencyName+'在'+copy(medt_Date.text,1,7)+' 月没有定义!',3);
ExchRate:='1';
end;
end;
end;
end
else
begin
if cmbbx_OutType.text='部门' then
begin
DeptCodecheck(sender);
end
else
begin
lbl_OutName.text:='';
Extedt_OutCode.Text:='';
end;
lb_Vendortaxrate_Percent.text:='0'+'%';
Vendortaxrate_Percent:='0';
end;
Frm_Entry_Detail.SetFormParam(cmbbx_OutType.text,Extedt_OutCode.text,currencyCode,Vendortaxrate_Percent,ExchRate,medt_Date.text);
TFrm_Inv_OtherIn_D(Frm_Entry_Detail).setformParam1(getCode(cmbbx_WhCode.text),getCode(cmbbx_WhPositionCode.text));
end;
procedure TFrm_Inv_OtherIn_B.SaveData;
var
update_field,fields,fieldValues,tmp_InvBillPrice,tmp_InvBillnotaxPrice,
tmp_InvBillAmount,tmp_InvBillnotaxAmount,tmp_InvBillPricec,tmp_WhCode,tmp_WhPositionCode,
tmp_InvBillnotaxPricec,tmp_InvBillAmountc,tmp_InvBillnotaxAmountc:string;
NeedChangePrice,BeforeSaveError:boolean;
M:integer;
Amount:real;
OtherIncheck,Stkcheck:integer;
Tempstr:string;
begin
inherited;
Tempstr:='';
tmp_WhCode:=getCode(cmbbx_WhCode.text);
if tmp_WhCode='' then
begin
DispInfo('仓库不能为空!',3);
abort;
end;
tmp_WhPositionCode:=getCode(cmbbx_WhPositionCode.text);
if tmp_WhPositionCode='' then
begin
DispInfo('货位不能为空!',3);
abort;
end;
if AdoQry_Body.RecordCount<1 then
begin
DispInfo('新增的单据没有记录,不允许保存!',1);
abort;
end;
//入库对象为空,备注不能为空
if (Trim(cmbbx_OutType.text)='') and (Extedt_memo.text='') then
begin
DispInfo('没有入库对象时,必须在备注中说明入库原因!',1);
abort;
end;
//主表存盘
if AdoQry_Head.state<>dsBrowse then
AdoQry_Head.post;
if AdoQry_Body.state<>dsBrowse then
AdoQry_Body.post;
//当Extedt_OutCode.text='' ,则字段值为NULL,如果cmbbx_OutType.text为供应商,VendorCode,
//cmbbx_OutType.text为部门,DeptCode因此在取组后一个SQL字符串
if cmbbx_OutType.text='部门' then
begin
fields:='DeptCode,';
fieldValues:=''''+Extedt_OutCode.text+''',';
end
else if cmbbx_OutType.text='供应商' then
begin
fields:='VendorCode,';
fieldValues:=''''+Extedt_OutCode.text+''',';
end
else
begin
fields:='';
fieldValues:='';
end;
//是否需要改变加权平均价
with AdoQry_tmp do
begin
Close;
sql.text:='select InvValuen from InvParam where InvParamCode=''OtherIncheck''';
open;
OtherIncheck:=fieldbyname('InvValuen').AsInteger;
if OtherIncheck=0 then Stkcheck:=1
else Stkcheck:=0;
end;
NeedChangePrice:=NeedChangeAveragePrice(AdoQry_tmp,copy(MEdt_Date.text,1,7));
AdoQry_Body.DisableControls ;
AdoQry_Body.Connection.beginTrans;
try
//全面有效检查
BeforeSaveError:=True;
//检查日期、库存
medt_Date.onexit(medt_Date);
AdoQry_Body.First;
for M:=0 to AdoQry_Body.recordCount-1 do
begin
//当前物料的库存检验
if not InvQtyCheck
(NeedChangePrice,
AdoQry_Body,
AdoQry_tmp,
tmp_WhCode,
tmp_WhPositionCode,
AdoQry_Body.fieldbyname('ItemCode').asstring,
'InvBillqty',
AdoQry_Body.fieldbyname('InvBillqty').asfloat,
True) then
abort;
if AdoQry_Body.fieldbyname('Batchno').asstring<>'' then
begin
//如果的批次控制,还要进行批次库存检验
if not BatchInvCheck(AdoQry_tmp,
AdoQry_Body.fieldbyname('Batchno').asstring,
'R',
tmp_WhCode,
tmp_WhPositionCode,
AdoQry_Body.fieldbyname('InvBillqty').asfloat) then
abort;
end;
AdoQry_Body.next;
end;
//真正开始存盘
BeforeSaveError:=False;
//取单据号
Billno:=getno(AdoQry_Body.Connection,getCode(cmbbx_WhCode.text)+'R'+copy(medt_Date.text,3,2)+copy(medt_Date.text,6,2),'InvBill');
//记录本仓库数据发生改变
ChangeInvStatus(AdoQry_tmp,getCode(cmbbx_WhCode.text),copy(medt_Date.text,1,7));
//增加InvInBill
AdoQry_tmp.Close;
AdoQry_tmp.sql.clear;
AdoQry_tmp.sql.Add('insert InvInBill'+
'(InvBillno,'+
'whCode,'+
'InvBilldate,'+
'InvBillMonth,'+
'BillTypeCode,'+
'BillType2Code,'+
'EmployeeCode,'+
'Stk_EmployeeCode,'+
fields+
'WhPositionCode,'+
'InvBillwhchck,'+
'InvBillStkchck,'+
'currencyCode,'+
'InvBilltaxrate,'+
'InvBillremArk)'+
'Values('''+Billno+''','+
''''+getCode(cmbbx_WhCode.text)+''','+
''''+medt_Date.text+''','+
''''+copy(medt_Date.text,1,7)+''','+
''''+BillTypeCode+''','+
''''+getCode(cmbbx_BillType2Code.text)+''','+
''''+userCode+''','+
''''+userCode+''','+
fieldValues+
''''+getCode(cmbbx_WhPositionCode.text)+''','+
'1,'+
inttostr(Stkcheck)+','+
''''+currencyCode+''','+
Vendortaxrate_Percent+','+
quotedstr(Extedt_memo.text)+')');
AdoQry_tmp.execsql;
//取InvBillID
Billid:='';
AdoQry_tmp.Close;
AdoQry_tmp.sql.clear;
AdoQry_tmp.sql.Add(' select @@IDENTITY as Billid ');
AdoQry_tmp.open;
Billid:=AdoQry_tmp.fieldbyname('Billid').asstring;
Amount:=0;
with AdoQry_Body do
begin
First;
for M:=0 to recordCount-1 do
begin
//由于显示在DBGRID中的价格不管外币还是人民币,都是用同一个字段,因
//此在存盘时把字段分开,如下:
if currencyCode='00' then
begin
tmp_InvBillPrice:=fieldbyname('InvBillPrice').asstring;
tmp_InvBillnotaxPrice:=fieldbyname('InvBillnotaxPrice').asstring;
tmp_InvBillAmount:=fieldbyname('InvBillAmount').asstring;
tmp_InvBillnotaxAmount:=fieldbyname('InvBillnotaxAmount').asstring;
tmp_InvBillPricec:=fieldbyname('InvBillPrice').asstring;
tmp_InvBillnotaxPricec:=fieldbyname('InvBillnotaxPrice').asstring;
tmp_InvBillAmountc:=fieldbyname('InvBillAmount').asstring;
tmp_InvBillnotaxAmountc:=fieldbyname('InvBillnotaxAmount').asstring;
end
else
begin
tmp_InvBillPrice:=floattostr(fieldbyname('InvBillPrice').asfloat/strtofloat(ExchRate));
tmp_InvBillnotaxPrice:=floattostr(fieldbyname('InvBillnotaxPrice').asfloat/strtofloat(ExchRate));
tmp_InvBillAmount:=floattostr(fieldbyname('InvBillAmount').asfloat/strtofloat(ExchRate));
tmp_InvBillnotaxAmount:=floattostr(fieldbyname('InvBillnotaxAmount').asfloat/strtofloat(ExchRate));
tmp_InvBillPricec:=fieldbyname('InvBillPrice').asstring;
tmp_InvBillnotaxPricec:=fieldbyname('InvBillnotaxPrice').asstring;
tmp_InvBillAmountc:=fieldbyname('InvBillAmount').asstring;
tmp_InvBillnotaxAmountc:=fieldbyname('InvBillnotaxAmount').asstring;
end;
//只用人民币结算
Amount:=Amount+strtofloat(tmp_InvBillAmount);
//更改加权平均价
if True then
begin
AdoQry_tmp.Close;
AdoQry_tmp.sql.clear;
AdoQry_tmp.sql.text:=
' if not exists (select Apqty from AveragePrice '+
' where whCode='''+getCode(CmbBx_WhCode.text)+''' and '+
' ItemCode='''+fieldbyname('ItemCode').asstring+''')'+
' insert AveragePrice(whCode,ItemCode) '+
' Values('''+getCode(CmBbx_WhCode.text)+''','+
''''+fieldbyname('ItemCode').asstring+''')'+
' update AveragePrice '+
' set Apqty=Apqty+'+fieldbyname('InvBillqty').asstring+','+
' ApAmount=ApAmount+'+tmp_InvBillnotaxAmount+
' where whCode='''+getCode(CmBbx_WhCode.text)+''' and '+
' ItemCode='''+fieldbyname('ItemCode').asstring+''''+
' update AveragePrice '+
' set AveragePrice=case when Apqty=0 then AveragePrice else ApAmount/Apqty end '+
' where whCode='''+getCode(CmbBx_WhCode.text)+''' and '+
' ItemCode='''+fieldbyname('ItemCode').asstring+'''';
AdoQry_tmp.execsql;
end;
//增加InvBillLINE
AdoQry_tmp.Close;
AdoQry_tmp.sql.clear;
AdoQry_tmp.sql.Add('insert InvInBillline'+
'(InvBillid,'+
'InvBilllineno,'+
'ItemCode,'+
'InvBillqty,'+
'BilllineremArk,'+
'Batchno,'+
'bl.InvBillPrice,'+
'bl.InvBillAmount,'+
'bl.InvBillnotaxPrice,'+
'bl.InvBillnotaxAmount,'+
'bl.InvBillPricec,'+
'bl.InvBillAmountc,'+
'bl.InvBillnotaxPricec,'+
'bl.InvBillnotaxAmountc )'+
'Values('+Billid+','+
inttostr(M+1)+','+
''''+fieldbyname('ItemCode').asstring+''','+
fieldbyname('InvBillqty').asstring+','+
''''+fieldbyname('BilllineremArk').asstring+''','+
''''+fieldbyname('Batchno').asstring+''','+
tmp_InvBillPrice+','+
tmp_InvBillAmount+','+
tmp_InvBillnotaxPrice+','+
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -