unit ACREABD;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, rootg, DB, ADODB, frxClass, frxDBSet, ImgList, ComCtrls,
Buttons, Wwdbigrd, Grids, Wwdbgrid, StdCtrls, Mask, wwdbedit, ExtCtrls,
ToolWin, DBCtrls, wwdbdatetimepicker, Wwdotdot, Wwdbcomb, frxExportXLS,
Menus, cxControls, cxContainer, cxEdit, cxProgressBar, wwcheckbox;
type
TfrmACREABD = class(Tfrmrootg)
QryMasterREA01: TWideStringField;
QryMasterREA02: TDateTimeField;
QryMasterREA03: TWideStringField;
QryMasterREA04: TWideStringField;
QryMasterREA05: TWideStringField;
QryMasterREA06: TWideStringField;
QryMasterREA07: TWideStringField;
QryMasterREA08: TWideStringField;
QryMasterREA09: TWideStringField;
QryDetailREB01: TWideStringField;
QryDetailREB02: TWideStringField;
QryDetailREB03: TWideStringField;
QryDetailREB04: TWideStringField;
QryDetailREB05: TWideStringField;
QryDetailREB06: TWideStringField;
QryDetailREB07: TWideStringField;
QryDetailREB08: TWideStringField;
QryDetailREB09: TWideStringField;
QryDetailREB10: TWideStringField;
QryDetailREB11: TFloatField;
QryDetailREB12: TFloatField;
QryDetailREB13: TWideStringField;
QryMasterREA10: TFloatField;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
wwDBDateTimePicker1: TwwDBDateTimePicker;
wwDBEdit2: TwwDBEdit;
wwDBEdit3: TwwDBEdit;
wwDBEdit4: TwwDBEdit;
wwDBEdit6: TwwDBEdit;
wwDBComboBox1: TwwDBComboBox;
wwDBComboBox2: TwwDBComboBox;
wwDBEdit7: TwwDBEdit;
wwDBEdit9: TwwDBEdit;
SpeedButton1: TSpeedButton;
wwDBCBREB03: TwwDBComboBox;
wwDBCDREB04: TwwDBComboDlg;
QryDetailJEHJ: TFloatField;
QryMasterREA11: TFloatField;
Label11: TLabel;
wwDBEdit5: TwwDBEdit;
QryDetailREB14: TFloatField;
QryDetailWCXJE: TFloatField;
QryDetailREB15: TFloatField;
QryDetailREB16: TWideStringField;
QryDetailREB17: TWideStringField;
PopupMenu1: TPopupMenu;
A41: TMenuItem;
N1: TMenuItem;
QryDetailREB18: TFloatField;
QryDetailREB19: TFloatField;
QryDetailREB20: TWideStringField;
QryDetailREB21: TFloatField;
QryDetailREB22: TWideStringField;
QryDetailREB23: TWideStringField;
wwDBCBREB20: TwwDBComboBox;
QryDetailREB24: TDateTimeField;
QryMasterREA12: TWideStringField;
ImageList3: TImageList;
cxProgressBar1: TcxProgressBar;
Label12: TLabel;
wwDBEdit8: TwwDBEdit;
SpeedButton3: TSpeedButton;
wwDBDateTimePicker3: TwwDBDateTimePicker;
Label13: TLabel;
QryMasterREA13: TWideStringField;
QryMasterREA14: TDateTimeField;
Label14: TLabel;
wwDBEdit10: TwwDBEdit;
QryMasterREA15: TFloatField;
QryGet: TADOQuery;
QryDetailREB25: TWideStringField;
QryMasterREA16: TDateTimeField;
QryMasterREA17: TDateTimeField;
Label15: TLabel;
wwDBDateTimePicker6: TwwDBDateTimePicker;
Label16: TLabel;
wwDBDateTimePicker5: TwwDBDateTimePicker;
QryDetailREB26: TWideStringField;
QryDetailREB27: TWideStringField;
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure QryDetailAfterInsert(DataSet: TDataSet);
procedure QryDetailAfterDelete(DataSet: TDataSet);
procedure addClick(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure btnRefresh; override;
procedure QryMasterREA03Validate(Sender: TField);
procedure wwDBCDREB04CustomDlg(Sender: TObject);
procedure QryDetailCalcFields(DataSet: TDataSet);
procedure saveClick(Sender: TObject);
procedure conformClick(Sender: TObject);
procedure wwDBGrid2CalcCellColors(Sender: TObject; Field: TField;
State: TGridDrawState; Highlight: Boolean; AFont: TFont;
ABrush: TBrush);
procedure frxReport1BeforePrint(Sender: TfrxReportComponent);
procedure printClick(Sender: TObject);
procedure A41Click(Sender: TObject);
procedure N1Click(Sender: TObject);
procedure QryMasterREA06GetText(Sender: TField; var Text: String;
DisplayText: Boolean);
procedure QryMasterREA07GetText(Sender: TField; var Text: String;
DisplayText: Boolean);
procedure QryDetailREB12Validate(Sender: TField);
procedure findClick(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
procedure QryMasterREA02Validate(Sender: TField);
procedure gridaddClick(Sender: TObject);
procedure wwDBCDREB04KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmACREABD: TfrmACREABD;
implementation
uses cGlobal, DBHELP, ACRECDHELP, filterf, udate, ACRAABHELP,ACRBABHELP,
ACRJABHELP, ACRACDHELP, ACRAEFHELP;
{$R *.dfm}
procedure TfrmACREABD.FormDestroy(Sender: TObject);
begin
inherited;
frmACREABD:=nil;
end;
procedure TfrmACREABD.FormCreate(Sender: TObject);
begin
FrmName := 'ACREABD';
FrmHDB := 'ACREA';
FrmGDB := 'ACREB';
FrmHID := 'REA01';
FrmGID1 := 'REB01';
FrmGID2 := 'REB02';
inherited;
end;
procedure TfrmACREABD.QryDetailAfterInsert(DataSet: TDataSet);
begin
if Trim(QryMaster.FieldByName(FrmHID).AsString)<>'' then
begin
QryDetail.Edit;
QryDetail.FieldByName(FrmGID1).AsString:=QryMaster.FieldByName(FrmHID).AsString;
QryDetail.FieldByName(FrmGID2).AsString:=FormatFloat('0000',QryDetail.RecordCount+1);
end;
end;
procedure TfrmACREABD.QryDetailAfterDelete(DataSet: TDataSet);
Var
i: string;
begin
i:=QryDetail.Bookmark;
try
QryDetail.DisableControls;
while not QryDetail.Eof do begin
QryDetail.Edit;
QryDetail.FieldByName(FrmGID2).AsString:= FormatFloat('0000',QryDetail.RecNo);
QryDetail.Next;
end;
finally
QryDetail.EnableControls;
end;
QryDetail.Bookmark:=i;
end;
procedure TfrmACREABD.addClick(Sender: TObject);
begin
inherited;
QryMaster.FieldByName('REA02').AsDateTime :=Date();
QryMaster.FieldByName('REA12').AsString :='K';
end;
procedure TfrmACREABD.SpeedButton1Click(Sender: TObject);
begin
inherited;
if not Assigned(frmDBHELP) then
frmDBHELP := TfrmDBHELP.Create(Application);
with frmDBHELP do
begin
DBHELP:=QryMaster;
strDBName:='ACRGA';
strCol:='RGA01 AS 客户编号,RGA03 AS 客户全称';
strWhere:=' ISNULL(ACRGA.RGA25,'''')<>''Y'' ';
strOrder:='客户编号';
strParaFieldCode:='客户编号';
strHelpFieldCode:='REA03';
strParaFieldName:='客户全称';
strHelpFieldName:='REA04';
ShowModal;
Free;
end;
end;
procedure TfrmACREABD.btnRefresh;
begin
inherited;
wwDBEdit3.ReadOnly :=True;
wwDBEdit5.ReadOnly :=True;
wwDBEdit7.ReadOnly :=True;
wwDBEdit8.ReadOnly :=True;
wwDBEdit9.ReadOnly :=True;
wwDBEdit10.ReadOnly :=True;
wwDBComboBox1.ReadOnly :=True;
wwDBComboBox2.ReadOnly :=True;
wwDBCBREB03.ReadOnly :=True;
wwDBDateTimePicker6.ReadOnly :=True;
wwDBDateTimePicker5.ReadOnly :=True;
end;
procedure TfrmACREABD.QryMasterREA03Validate(Sender: TField);
Var
QryTmp:TADOQuery;
vRQ:String;
begin
inherited;
try
QryTmp:=TADOQuery.Create(nil);
QryTmp.Connection:=DllAdoCn;
QryTmp.EnableBCD :=False;
QryTmp.Close;
QryTmp.SQL.Clear;
QryTmp.SQL.Add(' SELECT A.RGA01 AS KHBH,A.RGA11 AS BBBH,C.NA003 AS FKTJ,A.RGA03 AS KHJC,A.RGA03 AS KHQC,(CASE WHEN B.MF001<>''RMB'' THEN ( CASE WHEN '+VarToSql(FormatDateTime('YYYYMMDD',Date()))+'>= (SELECT MAX(MG002) '+
' FROM CMSMG '+
' WHERE MG001=A.RGA11) THEN (SELECT TOP 1 MG003 '+
' FROM CMSMG '+
' WHERE MG001=A.RGA11 '+
' order by MG002 DESC) '+
' ELSE (SELECT MG003 '+
' FROM CMSMG '+
' WHERE MG001=A.RGA11 AND MG002=(SELECT MAX(MG002) '+
' FROM CMSMG '+
' WHERE MG002<='+VarToSql(FormatDateTime('YYYYMMDD',Date()))+' AND MG001=A.RGA11)) '+
' END) '+
' ELSE 1 '+
' END) HL,(CASE A.RGA14 WHEN 1 THEN ''现金'' '+
' WHEN 2 THEN ''电汇'' '+
' WHEN 3 THEN ''票据'' '+
' ELSE ''其他'' '+
' END ) FKFS,SHUIZHONG=(CASE A.RGA13 WHEN 1 THEN ''应税内含'' '+
' WHEN 2 THEN ''应税外加'' '+
' WHEN 3 THEN ''零税率'' '+
' WHEN 4 THEN ''免税'' '+
' ELSE ''不计税'' '+
' END),A.RGA16 SHUILU,B.MF008 AS BBFH,B.MF002 BBMC, '+
' FPZL=(CASE A.RGA12 WHEN ''A'' THEN ''专用发票'' '+
' WHEN ''B'' THEN ''增值税普通发票'' '+
' WHEN ''D'' THEN ''服务性发票'' '+
' WHEN ''C'' THEN ''其他'' '+
' END),A.RGA12,A.RGA13 '+
' FROM ACRGA A '+
' LEFT JOIN CMSMF B ON B.MF001=A.RGA11 '+
' LEFT JOIN CMSNA C ON C.NA002=A.RGA15 '+
' WHERE A.RGA25<>''Y'' AND A.RGA01='+vartosql(Trim(QryMaster.FieldByName('REA03').AsString)));
QryTmp.Open;
QryMaster.FieldByName('REA04').AsString := Trim(QryTmp.FieldByName('KHQC').AsString); //客户全称
QryMaster.FieldByName('REA05').AsString := Trim(QryTmp.FieldByName('BBBH').AsString); //币种
QryMaster.FieldByName('REA06').AsString := Trim(QryTmp.FieldByName('RGA12').AsString); //发票种类
QryMaster.FieldByName('REA07').AsString := Trim(QryTmp.FieldByName('RGA13').AsString); //税种
QryMaster.FieldByName('REA15').AsFloat := QryTmp.FieldByName('HL').AsFloat; //汇率
finally
QryTmp.Close;
QryTmp.Free;
end;
try
QryTmp:=TADOQuery.Create(nil);
QryTmp.Connection:=DllAdoCn;
QryTmp.EnableBCD :=False;
QryTmp.Close;
QryTmp.SQL.Clear;
QryTmp.SQL.Add(' SELECT RQ,RGA01,YS,TS,DATEADD(DD,1,DATEADD(MM,YS,DATEADD(dd,TS,RQ))) AS SKRQ '+
' FROM(SELECT '+VarToSql(wwDBDateTimePicker1.Date)+' AS RQ,RGA01, '+
' CASE WHEN RGA07=30 THEN 1 WHEN RGA07=60 THEN 2 WHEN RGA07=90 THEN 3 WHEN RGA07=120 THEN 4 ELSE 0 END YS, '+
' CASE WHEN RGA07=30 OR RGA07=60 OR RGA07=90 OR RGA07=120 THEN 0 ELSE RGA07 END TS '+
' FROM ACRGA '+
' WHERE RGA01='+VarToSql(Trim(QryMaster.FieldByName('REA03').AsString))+') AS AA ');
QryTmp.Open;
QryMaster.FieldByName('REA14').AsFloat := QryTmp.FieldByName('SKRQ').AsDateTime; //收款日期
finally
QryTmp.Close;
QryTmp.Free;
end;
if (Trim(wwDBEdit8.Text)<>'') and (Trim(Sender.AsString)<>'') Then
begin
vRQ:=Trim(wwDBEdit8.Text)+'01';
//取帐期起始日期、帐期结束日期
try
QryTmp:=TADOQuery.Create(nil);
QryTmp.Connection:=DllAdoCn;
QryTmp.EnableBCD :=False;
QryTmp.Close;
QryTmp.SQL.Clear;
QryTmp.SQL.Add(' SELECT RGA07,RGA23,'+
' CASE WHEN RGA23<>'''' AND (RGA23=''31'' OR RGA23=''30'') THEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(8),EndofTheMonth,112),1,6)+''01'',112) '+
' WHEN RGA23<>'''' AND RGA23<>''31'' AND RGA23<>''30'' THEN DATEADD(dd,1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(8),priorEndofTheMonth,112),1,6)+RGA23,112)) '+
' WHEN RGA23='''' THEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(8),EndofTheMonth,112),1,6)+''01'',112) '+
' End BEGRQ, '+
' CASE WHEN RGA23<>'''' AND (RGA23=''31'' OR RGA23=''30'') THEN EndofTheMonth '+
' WHEN RGA23<>'''' AND RGA23<>''31'' AND RGA23<>''30'' THEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(8),EndofTheMonth,112),1,6)+RGA23,112) '+
' WHEN RGA23='''' THEN EndofTheMonth '+
' End ENDRQ '+
' FROM (SELECT RGA07,RGA23,RQ, '+
' EndofTheMonth,priorEndofTheMonth,NextEndofTheMonth '+
' FROM (SELECT RGA07,RGA23,RQ, '+
' DATEADD(dd,-1,DATEADD(mm,DATEDIFF(m,0,RQ)+1,0)) AS EndofTheMonth, '+
' DATEADD(dd,-1,DATEADD(mm,DATEDIFF(m,0,RQ),0)) AS priorEndofTheMonth, '+
' DATEADD(dd,-1,DATEADD(mm,DATEDIFF(m,0,RQ)+2,0)) AS NextEndofTheMonth '+
' FROM (SELECT RGA07,RGA23,CONVERT(DATETIME,'+VarToSql(vRQ)+') RQ '+
' FROM ACRGA '+
' WHERE RGA01='+VarToSql(Trim(Sender.AsString))+') AS AA) AS BB) AS CC ');
QryTmp.Open;
QryTmp.first;
QryMaster.FieldByName('REA16').AsDateTime :=QryTmp.FieldByName('BEGRQ').AsDateTime;
QryMaster.FieldByName('REA17').AsDateTime :=QryTmp.FieldByName('ENDRQ').AsDateTime;
finally
QryTmp.Close;
QryTmp.Free;
end;
end;
end;
procedure TfrmACREABD.wwDBCDREB04CustomDlg(Sender: TObject);
Var
sResult:String;
sl:TStringList;
i:integer;
QryTmp:TADOQuery;
vRGA24:String;
sSQL:String;
begin
inherited;
if Trim(wwDBEdit2.Text)='' Then
begin
Application.MessageBox('客户编号不能为空!','提示信息',MB_IconInformation+MB_OK);
abort;
end;
if Trim(QryDetail.FieldByName('REB03').AsString)='' Then
begin
Application.MessageBox('请选择来源!','提示信息',MB_IconInformation+MB_OK);
abort;
end;
if Trim(QryDetail.FieldByName('REB03').AsString)='1' then //销货
begin
if not Assigned(frmACRAABHELP) then
begin
frmACRAABHELP := TfrmACRAABHELP.Create(Application);
frmACRAABHELP.sWhere :=' RAA06='+VarToSql(Trim(wwDBEdit2.Text))+' AND ISNULL(ACRAB.RAB39,'''')<>''Y'' AND ISNULL(ACRGA.RGA25,'''')<>''Y'' AND ISNULL(RAB30,0.0)-ISNULL(RAB34,0.0)-ISNULL(RAB38,0.0)>0 AND ISNULL(RAB30,0.0)-ISNULL(RAB33,0.0)-ISNULL(RAB37,0.0)>0.0 ';
frmACRAABHELP.ShowModal;
sResult:=frmACRAABHELP.rtnHelpFieldName;
frmACRAABHELP.Free;
end;
if sResult<>'' Then
begin
sl:=TStringList.Create;
sl.Delimiter :=';';
sl.DelimitedText := Trim(sResult);
if sl.Count=1 then
begin
try
QryTmp:=TADOQuery.Create(nil);
QryTmp.Connection:=dlladocn;
QryTmp.EnableBCD :=False;
QryTmp.Close;
QryTmp.SQL.Clear;
QryTmp.SQL.Add(' SELECT RAA05,RAB15,RAB14,RAB03,RAB04,RAB05,RAB06,RAB09,RAB10,RAB08,'+
' RAB29,RAB28,RAB11,RGA07,RGA28,RGA23,RAB31,RAB32,RAB13, '+
' ISNULL(RAB30,0.0)-ISNULL(RAB34,0.0)-ISNULL(RAB38,0.0) AS REB14 '+
' FROM ACRAB '+
' INNER JOIN ACRAA ON ACRAB.RAB01=ACRAA.RAA01 '+
' LEFT JOIN ACRGA ON ACRGA.RGA01=ACRAA.RAA06 '+
' WHERE ACRAA.CONFORM_CODE=''Y'' AND ISNULL(ACRGA.RGA25,'''')<>''Y'' AND ACRAB.RAB01+''-''+ACRAB.RAB02='+VarToSql(Trim(sl.Strings[0])));
QryTmp.Open;
if QryTmp.RecordCount >0 Then
begin
QryDetail.Edit;
QryDetail.FieldByName('REB03').AsString := '1'; //来源
QryDetail.FieldByName('REB04').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),1,4); //来源单别
QryDetail.FieldByName('REB05').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),6,11); //来源单号
QryDetail.FieldByName('REB06').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),18,4); //来源序号
QryDetail.FieldByName('REB07').AsString := QryTmp.FieldByName('RAB04').AsString; //品号
QryDetail.FieldByName('REB08').AsString := QryTmp.FieldByName('RAB05').AsString; //品名
QryDetail.FieldByName('REB09').AsString := QryTmp.FieldByName('RAB06').AsString; //规格
QryDetail.FieldByName('REB10').AsString := QryTmp.FieldByName('RAB09').AsString; //单位
QryDetail.FieldByName('REB11').AsFloat := QryTmp.FieldByName('RAB08').AsFloat-QryTmp.FieldByName('RAB31').AsFloat; //数量
QryDetail.FieldByName('REB12').AsFloat := QryTmp.FieldByName('RAB10').AsFloat; //单价
QryDetail.FieldByName('REB13').AsString := ''; //备注
QryDetail.FieldByName('REB14').AsFloat := QryTmp.FieldByName('REB14').AsFloat; //本次开票金额
QryDetail.FieldByName('REB15').AsFloat := 0.0; //已开票金额
QryDetail.FieldByName('REB16').AsString := QryTmp.FieldByName('RAB15').AsString; //客户单号
QryDetail.FieldByName('REB17').AsString := QryTmp.FieldByName('RAB14').AsString; //快捷码
QryDetail.FieldByName('REB18').AsFloat := QryTmp.FieldByName('RAB08').AsFloat-QryTmp.FieldByName('RAB31').AsFloat; //本次开票数量
QryDetail.FieldByName('REB19').AsFloat :=0.0; //已开票数量
QryDetail.FieldByName('REB20').AsString := '传感器'; //货物或应带劳务名称
QryDetail.FieldByName('REB21').AsFloat := QryTmp.FieldByName('REB14').AsFloat; //应开票金额
QryDetail.FieldByName('REB22').AsString := ''; //对帐单号
QryDetail.FieldByName('REB23').AsString := ''; //对帐序号
QryDetail.FieldByName('REB24').AsDateTime := QryTmp.FieldByName('RAA05').AsDateTime; //销退货日期
QryDetail.FieldByName('REB25').AsString := QryTmp.FieldByName('RAB11').AsString; //订单单号
QryDetail.FieldByName('REB26').AsString := QryTmp.FieldByName('RAB32').AsString; //送货单号
QryDetail.FieldByName('REB27').AsString := QryTmp.FieldByName('RAB13').AsString; //客户品号
end;
finally
QryTmp.Close;
QryTmp.Free;
end;
end
else
begin
for i:=1 to sl.Count-1 do
begin
if i=1 then
begin
try
QryTmp:=TADOQuery.Create(nil);
QryTmp.Connection:=dlladocn;
QryTmp.EnableBCD :=False;
QryTmp.Close;
QryTmp.SQL.Clear;
QryTmp.SQL.Add(' SELECT RAA05,RAB15,RAB14,RAB03,RAB04,RAB05,RAB06,RAB09,RAB10,RAB08,'+
' RAB29,RAB28,RAB11,RGA07,RGA28,RGA23,RAB31,RAB32,RAB13, '+
' ISNULL(RAB30,0.0)-ISNULL(RAB34,0.0)-ISNULL(RAB38,0.0) AS REB14 '+
' FROM ACRAB '+
' INNER JOIN ACRAA ON ACRAB.RAB01=ACRAA.RAA01 '+
' LEFT JOIN ACRGA ON ACRGA.RGA01=ACRAA.RAA06 '+
' WHERE ACRAA.CONFORM_CODE=''Y'' AND ISNULL(ACRGA.RGA25,'''')<>''Y'' AND ACRAB.RAB01+''-''+ACRAB.RAB02='+VarToSql(Trim(sl.Strings[0])));
QryTmp.Open;
if QryTmp.RecordCount >0 Then
begin
QryDetail.Edit;
QryDetail.FieldByName('REB03').AsString := '1'; //来源
QryDetail.FieldByName('REB04').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),1,4); //来源单别
QryDetail.FieldByName('REB05').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),6,11); //来源单号
QryDetail.FieldByName('REB06').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),18,4); //来源序号
QryDetail.FieldByName('REB07').AsString := QryTmp.FieldByName('RAB04').AsString; //品号
QryDetail.FieldByName('REB08').AsString := QryTmp.FieldByName('RAB05').AsString; //品名
QryDetail.FieldByName('REB09').AsString := QryTmp.FieldByName('RAB06').AsString; //规格
QryDetail.FieldByName('REB10').AsString := QryTmp.FieldByName('RAB09').AsString; //单位
QryDetail.FieldByName('REB11').AsFloat := QryTmp.FieldByName('RAB08').AsFloat-QryTmp.FieldByName('RAB31').AsFloat; //数量
QryDetail.FieldByName('REB12').AsFloat := QryTmp.FieldByName('RAB10').AsFloat; //单价
QryDetail.FieldByName('REB13').AsString := ''; //备注
QryDetail.FieldByName('REB14').AsFloat := QryTmp.FieldByName('REB14').AsFloat; //本次开票金额
QryDetail.FieldByName('REB15').AsFloat := 0.0; //已开票金额
QryDetail.FieldByName('REB16').AsString := QryTmp.FieldByName('RAB15').AsString; //客户单号
QryDetail.FieldByName('REB17').AsString := QryTmp.FieldByName('RAB14').AsString; //快捷码
QryDetail.FieldByName('REB18').AsFloat := QryTmp.FieldByName('RAB08').AsFloat-QryTmp.FieldByName('RAB31').AsFloat; //本次开票数量
QryDetail.FieldByName('REB19').AsFloat :=0.0; //已开票数量
QryDetail.FieldByName('REB20').AsString := '传感器'; //货物或应带劳务名称
QryDetail.FieldByName('REB21').AsFloat := QryTmp.FieldByName('REB14').AsFloat; //应开票金额
QryDetail.FieldByName('REB22').AsString := ''; //对帐单号
QryDetail.FieldByName('REB23').AsString := ''; //对帐序号
QryDetail.FieldByName('REB24').AsDateTime := QryTmp.FieldByName('RAA05').AsDateTime; //销退货日期
QryDetail.FieldByName('REB25').AsString := QryTmp.FieldByName('RAB11').AsString; //订单单号
QryDetail.FieldByName('REB26').AsString := QryTmp.FieldByName('RAB32').AsString; //送货单号
QryDetail.FieldByName('REB27').AsString := QryTmp.FieldByName('RAB13').AsString; //客户品号
end;
finally
QryTmp.Close;
QryTmp.Free;
end;
end
else
begin
QryDetail.Append;
try
QryTmp:=TADOQuery.Create(nil);
QryTmp.Connection:=dlladocn;
QryTmp.EnableBCD :=False;
QryTmp.Close;
QryTmp.SQL.Clear;
QryTmp.SQL.Add(' SELECT RAA05,RAB15,RAB14,RAB03,RAB04,RAB05,RAB06,RAB09,RAB10,RAB08,'+
' RAB29,RAB28,RAB11,RGA07,RGA28,RGA23,RAB31,RAB32,RAB13, '+
' ISNULL(RAB30,0.0)-ISNULL(RAB34,0.0)-ISNULL(RAB38,0.0) AS REB14 '+
' FROM ACRAB '+
' INNER JOIN ACRAA ON ACRAB.RAB01=ACRAA.RAA01 '+
' LEFT JOIN ACRGA ON ACRGA.RGA01=ACRAA.RAA06 '+
' WHERE ACRAA.CONFORM_CODE=''Y'' AND ISNULL(ACRGA.RGA25,'''')<>''Y'' AND ACRAB.RAB01+''-''+ACRAB.RAB02='+VarToSql(Trim(sl.Strings[i-1])));
QryTmp.Open;
if QryTmp.RecordCount >0 Then
begin
QryDetail.Edit;
QryDetail.FieldByName('REB03').AsString := '1'; //来源
QryDetail.FieldByName('REB04').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),1,4); //来源单别
QryDetail.FieldByName('REB05').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),6,11); //来源单号
QryDetail.FieldByName('REB06').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),18,4); //来源序号
QryDetail.FieldByName('REB07').AsString := QryTmp.FieldByName('RAB04').AsString; //品号
QryDetail.FieldByName('REB08').AsString := QryTmp.FieldByName('RAB05').AsString; //品名
QryDetail.FieldByName('REB09').AsString := QryTmp.FieldByName('RAB06').AsString; //规格
QryDetail.FieldByName('REB10').AsString := QryTmp.FieldByName('RAB09').AsString; //单位
QryDetail.FieldByName('REB11').AsFloat := QryTmp.FieldByName('RAB08').AsFloat-QryTmp.FieldByName('RAB31').AsFloat; //数量
QryDetail.FieldByName('REB12').AsFloat := QryTmp.FieldByName('RAB10').AsFloat; //单价
QryDetail.FieldByName('REB13').AsString := ''; //备注
QryDetail.FieldByName('REB14').AsFloat := QryTmp.FieldByName('REB14').AsFloat; //本次开票金额
QryDetail.FieldByName('REB15').AsFloat := 0.0; //已开票金额
QryDetail.FieldByName('REB16').AsString := QryTmp.FieldByName('RAB15').AsString; //客户单号
QryDetail.FieldByName('REB17').AsString := QryTmp.FieldByName('RAB14').AsString; //快捷码
QryDetail.FieldByName('REB18').AsFloat := QryTmp.FieldByName('RAB08').AsFloat-QryTmp.FieldByName('RAB31').AsFloat; //本次开票数量
QryDetail.FieldByName('REB19').AsFloat :=0.0; //已开票数量
QryDetail.FieldByName('REB20').AsString := '传感器'; //货物或应带劳务名称
QryDetail.FieldByName('REB21').AsFloat := QryTmp.FieldByName('REB14').AsFloat; //应开票金额
QryDetail.FieldByName('REB22').AsString := ''; //对帐单号
QryDetail.FieldByName('REB23').AsString := ''; //对帐序号
QryDetail.FieldByName('REB24').AsDateTime := QryTmp.FieldByName('RAA05').AsDateTime; //销退货日期
QryDetail.FieldByName('REB25').AsString := QryTmp.FieldByName('RAB11').AsString; //订单单号
QryDetail.FieldByName('REB26').AsString := QryTmp.FieldByName('RAB32').AsString; //送货单号
QryDetail.FieldByName('REB27').AsString := QryTmp.FieldByName('RAB13').AsString; //客户品号
end;
finally
QryTmp.Close;
QryTmp.Free;
end;
end;
end;
end;
end;
end;
end;
procedure TfrmACREABD.QryDetailCalcFields(DataSet: TDataSet);
begin
inherited;
QryDetail.FieldByName('WCXJE').AsFloat := QryDetail.FieldByName('REB21').AsFloat-QryDetail.FieldByName('REB14').AsFloat-QryDetail.FieldByName('REB15').AsFloat;
end;
procedure TfrmACREABD.saveClick(Sender: TObject);
Var
vKPJE:Double;
vbk:String;
begin
wwDBEdit1.SetFocus;
if Trim(wwDBEdit2.Text)='' Then
begin
Application.MessageBox('客户编号不能为空!','提示信息',MB_IconInformation+MB_OK);
abort;
end;
if Trim(wwDBEdit6.Text)='' Then
begin
Application.MessageBox('发票号码不能为空!','提示信息',MB_IconInformation+MB_OK);
abort;
end;
if Trim(wwDBEdit8.Text)='' Then
begin
Application.MessageBox('对帐月份不能为空!','提示信息',MB_IconInformation+MB_OK);
abort;
end;
if Trim(wwDBDateTimePicker1.Text)='' Then
begin
Application.MessageBox('发票日期不能为空!','提示信息',MB_IconInformation+MB_OK);
abort;
end;
if Trim(wwDBDateTimePicker3.Text)='' Then
begin
Application.MessageBox('收款日期不能为空!','提示信息',MB_IconInformation+MB_OK);
abort;
end;
//更新金额
if not QryDetail.IsEmpty Then
begin
if QryDetail.State in [dsEdit,dsInsert] then
begin
QryDetail.Post;
end;
if QryDetail.RecordCount>0 then
begin
vKPJE :=0.0;
QryDetail.DisableControls;
QryDetail.First;
While not QryDetail.Eof do
begin
vKPJE:=vKPJE+QryDetail.fieldbyname('REB14').AsFloat;
QryDetail.Next;
end;
QryDetail.EnableControls;
end
else
begin
vKPJE:=0;
end;
QryMaster.FieldByName('REA11').AsFloat :=StrToFloat(FormatFloat('0.00',vKPJE)); //总金额
QryDetail.Edit;
end;
inherited;
end;
procedure TfrmACREABD.conformClick(Sender: TObject);
Var
vREC01:String;
i:integer;
begin
if QryMaster.FieldByName('CONFORM_CODE').AsString ='Y' Then
begin
//对帐单收款不能反审
if not GetSQLEmpty(' SELECT DZDH,DZXH '+
' FROM (SELECT RDD22 AS DZDH,RDD23 AS DZXH '+
' FROM ACRDD '+
' UNION ALL '+
' SELECT RDB20 AS DZDH,RDB21 AS DZXH '+
' FROM ACRDB) AS AA '+
' WHERE EXISTS (SELECT 1 FROM (SELECT REB22,REB23 FROM ACREB WHERE REB01='+VarToSql(Trim(QryMaster.FieldByName('REA01').AsString))+') AS BB WHERE AA.DZDH=BB.REB22 AND AA.DZXH=BB.REB23) ') then
begin
Application.MessageBox('对应的对帐单有收款,不能反审!','提示信息',MB_IconInformation+MB_OK);
abort;
end;
end;
inherited;
if not QryDetail.IsEmpty Then
begin
//更新对账单
if Trim(QryMaster.FieldByName('CONFORM_CODE').AsString) ='Y' Then
begin
try
if not dlladocn.InTransaction then
dlladocn.BeginTrans;
//1、对帐单表头
vREC01 :=GetFormNo('ACREC','REC01');
ExecuteSQL('INSERT INTO ACREC(REC01,REC02,REC03,REC04,REC05,REC06,REC07,REC08,REC09,REC10, '+
' REC11,REC12,REC13,REC14,REC15,REC16,REC17,REC18,CONFORM_DATE, '+
' CONFORM_NAME,CONFORM_CODE) VALUES('+VarToSql(vREC01)+
','+VarToSql(Date())+
','+VarToSql(DllUserName)+
','+VarToSql(Trim(QryMaster.FieldByName('REA03').AsString))+
','+VarToSql(Trim(QryMaster.FieldByName('REA04').AsString))+
','+VarToSql(Trim(QryMaster.FieldByName('REA05').AsString))+
','+VarToSql('')+
','+VarToSql(Trim(QryMaster.FieldByName('REA13').AsString))+
','+VarToSql(QryMaster.FieldByName('REA15').AsFloat)+
','+VarToSql(QryMaster.FieldByName('REA11').AsFloat)+
','+VarToSql(QryMaster.FieldByName('REA14').AsDateTime)+
','+VarToSql(QryMaster.FieldByName('REA02').AsDateTime)+
','+VarToSql('0.0')+
','+VarToSql(QryMaster.FieldByName('REA11').AsFloat)+
','+VarToSql('N')+
','+VarToSql('Y')+
','+VarToSql(QryMaster.FieldByName('REA16').AsDateTime)+
','+VarToSql(QryMaster.FieldByName('REA17').AsDateTime)+
','+VarToSql(Date())+
','+VarToSql(DllUserName)+
','+VarToSql('Y')+')');
//2、产生对帐单
QryDetail.First;
i:=1;
While not QryDetail.eof do
begin
//1、更新对帐单
if (QryDetail.FieldByName('REB03').AsString ='1') OR (QryDetail.FieldByName('REB03').AsString ='2') Then
begin
ExecuteSQL('INSERT INTO ACRED(RED01,RED02,RED03,RED04,RED05,RED06,RED07,RED08,RED09,RED10, '+
' RED11,RED12,RED13,RED14,RED15,RED17,RED18,RED19,RED20,RED21, '+
' RED22,RED23,RED25,RED26,RED27,RED28,RED29,RED30) VALUES('+VarToSql(Trim(vREC01))+
','+vartosql(FormatFloat('0000',i))+
','+VarToSql(Trim(QryDetail.FieldByName('REB03').AsString))+
','+VarToSql(QryDetail.FieldByName('REB24').AsDateTime)+
','+VarToSql(Trim(QryDetail.FieldByName('REB16').AsString))+
','+VarToSql(Trim(QryDetail.FieldByName('REB17').AsString))+
','+VarToSql(Trim(QryDetail.FieldByName('REB04').AsString)+'-'+Trim(QryDetail.FieldByName('REB05').AsString)+'-'+Trim(QryDetail.FieldByName('REB06').AsString))+
','+VarToSql(Trim(QryDetail.FieldByName('REB07').AsString))+
','+VarToSql(Trim(QryDetail.FieldByName('REB08').AsString))+
','+VarToSql(Trim(QryDetail.FieldByName('REB09').AsString))+
','+VarToSql(Trim(QryDetail.FieldByName('REB10').AsString))+
','+VarToSql(QryDetail.FieldByName('REB12').AsFloat)+
','+VarToSql(QryDetail.FieldByName('REB18').AsFloat)+
','+VarToSql('N')+
','+VarToSql('')+
','+VarToSql(Trim(QryDetail.FieldByName('REB25').AsString))+
','+VarToSql('')+
','+VarToSql(0.0)+
','+VarToSql(QryDetail.FieldByName('REB18').AsFloat)+
','+VarToSql(QryMaster.FieldByName('REA02').AsDateTime)+
','+VarToSql('')+
','+VarToSql(Trim(QryMaster.FieldByName('REA08').AsString))+
','+VarToSql(QryDetail.FieldByName('REB14').AsFloat)+
','+VarToSql(0.0)+
','+VarToSql(QryDetail.FieldByName('REB24').AsDateTime)+
','+VarToSql(QryDetail.FieldByName('REB14').AsFloat)+
','+VarToSql(Trim(QryDetail.FieldByName('REB26').AsString))+
','+VarToSql(Trim(QryDetail.FieldByName('REB27').AsString))+
')');
end
else
begin
ExecuteSQL('INSERT INTO ACRED(RED01,RED02,RED03,RED04,RED05,RED06,RED07,RED08,RED09,RED10, '+
' RED11,RED12,RED13,RED14,RED15,RED17,RED18,RED19,RED20,RED21, '+
' RED22,RED23,RED25,RED26,RED27,RED28,RED29,RED30) VALUES('+VarToSql(Trim(vREC01))+
','+vartosql(FormatFloat('0000',i))+
','+VarToSql(Trim(QryDetail.FieldByName('REB03').AsString))+
','+VarToSql(QryDetail.FieldByName('REB24').AsDateTime)+
','+VarToSql(Trim(QryDetail.FieldByName('REB16').AsString))+
','+VarToSql(Trim(QryDetail.FieldByName('REB17').AsString))+
','+VarToSql(Trim(QryDetail.FieldByName('REB05').AsString)+'-'+Trim(QryDetail.FieldByName('REB06').AsString))+
','+VarToSql(Trim(QryDetail.FieldByName('REB07').AsString))+
','+VarToSql(Trim(QryDetail.FieldByName('REB08').AsString))+
','+VarToSql(Trim(QryDetail.FieldByName('REB09').AsString))+
','+VarToSql(Trim(QryDetail.FieldByName('REB10').AsString))+
','+VarToSql(QryDetail.FieldByName('REB12').AsFloat)+
','+VarToSql(QryDetail.FieldByName('REB18').AsFloat)+
','+VarToSql('N')+
','+VarToSql('')+
','+VarToSql(Trim(QryDetail.FieldByName('REB25').AsString))+
','+VarToSql('')+
','+VarToSql(0.0)+
','+VarToSql(QryDetail.FieldByName('REB18').AsFloat)+
','+VarToSql(QryMaster.FieldByName('REA02').AsDateTime)+
','+VarToSql('')+
','+VarToSql(Trim(QryMaster.FieldByName('REA08').AsString))+
','+VarToSql(QryDetail.FieldByName('REB14').AsFloat)+
','+VarToSql(0.0)+
','+VarToSql(QryDetail.FieldByName('REB24').AsDateTime)+
','+VarToSql(QryDetail.FieldByName('REB14').AsFloat)+
','+VarToSql(Trim(QryDetail.FieldByName('REB26').AsString))+
','+VarToSql(Trim(QryDetail.FieldByName('REB27').AsString))+
')');
end;
//2、更新发票对帐单信息
ExecuteSQL('UPDATE ACREB SET REB22='+VarToSql(Trim(vREC01))+',REB23='+vartosql(FormatFloat('0000',i))+' WHERE REB01='+VarToSql(Trim(QryDetail.FieldByName('REB01').AsString))+' AND REB02='+VarToSql(Trim(QryDetail.FieldByName('REB02').AsString)));
if QryDetail.FieldByName('REB03').AsString ='1' Then
begin
//3、更新销货单开票数量、开票金额、对帐数量、转应收金额
ExecuteSQL('UPDATE ACRAB SET RAB31=ISNULL(RAB31,0.0)+'+VarToSql(QryDetail.FieldByName('REB18').AsFloat)+
',RAB34=ISNULL(RAB34,0.0)+'+VarToSql(QryDetail.FieldByName('REB14').AsFloat)+
',RAB36=ISNULL(RAB36,0.0)+'+VarToSql(QryDetail.FieldByName('REB18').AsFloat)+
',RAB37=ISNULL(RAB37,0.0)+'+VarToSql(QryDetail.FieldByName('REB14').AsFloat)+
' WHERE RAB03='+VarToSql(Trim(QryDetail.FieldByName('REB04').AsString)+'-'+Trim(QryDetail.FieldByName('REB05').AsString)+'-'+Trim(QryDetail.FieldByName('REB06').AsString)));
end;
if QryDetail.FieldByName('REB03').AsString ='2' Then
begin
//4、更新销退单开票数量、开票金额、对帐数量、转应收金额
ExecuteSQL('UPDATE ACRBB SET RBB32=ISNULL(RBB32,0.0)+'+VarToSql((-1)*QryDetail.FieldByName('REB18').AsFloat)+
',RBB35=ISNULL(RBB35,0.0)+'+VarToSql((-1)*QryDetail.FieldByName('REB14').AsFloat)+
',RBB37=ISNULL(RBB37,0.0)+'+VarToSql((-1)*QryDetail.FieldByName('REB18').AsFloat)+
',RBB38=ISNULL(RBB38,0.0)+'+VarToSql((-1)*QryDetail.FieldByName('REB14').AsFloat)+
' WHERE RBB03='+VarToSql(Trim(QryDetail.FieldByName('REB04').AsString)+'-'+Trim(QryDetail.FieldByName('REB05').AsString)+'-'+Trim(QryDetail.FieldByName('REB06').AsString)));
end;
if QryDetail.FieldByName('REB03').AsString ='3' Then
begin
//5、更新其它费用开票数量、已开票金额、对帐数量、转应收金额
ExecuteSQL('UPDATE ACRJB SET RJB08=ISNULL(RJB08,0.0)+'+VarToSql(QryDetail.FieldByName('REB14').AsFloat)+
',RJB09=ISNULL(RJB09,0.0)+'+VarToSql(QryDetail.FieldByName('REB14').AsFloat)+
',RJB17=ISNULL(RJB17,0.0)+'+VarToSql(QryDetail.FieldByName('REB18').AsFloat)+
' WHERE ACRJB.RJB01='+Trim(QryDetail.FieldByName('REB05').AsString)+' AND ACRJB.RJB02='+Trim(QryDetail.FieldByName('REB06').AsString));
end;
if QryDetail.FieldByName('REB03').AsString ='5' Then //更新其它销货
begin
//6、更新其它销货开票数量、开票金额、对帐数量、转应收金额
ExecuteSQL('UPDATE ACRAD SET RAD31=ISNULL(RAD31,0.0)+'+VarToSql(QryDetail.FieldByName('REB18').AsFloat)+
',RAD34=ISNULL(RAD34,0.0)+'+VarToSql(QryDetail.FieldByName('REB14').AsFloat)+
',RAD36=ISNULL(RAD36,0.0)+'+VarToSql(QryDetail.FieldByName('REB18').AsFloat)+
',RAD37=ISNULL(RAD37,0.0)+'+VarToSql(QryDetail.FieldByName('REB14').AsFloat)+
' WHERE RAD01='+VarToSql(Trim(QryDetail.FieldByName('REB05').AsString))+' AND RAD02='+VarToSql(Trim(QryDetail.FieldByName('REB06').AsString)));
end;
if QryDetail.FieldByName('REB03').AsString ='6' Then //更新销货折让
begin
//7、更新销货折让开票数量、开票金额、对帐数量、转应收金额
ExecuteSQL('UPDATE ACRAF SET RAF31=ISNULL(RAF31,0.0)+'+VarToSql((-1)*QryDetail.FieldByName('REB18').AsFloat)+
',RAF34=ISNULL(RAF34,0.0)+'+VarToSql((-1)*QryDetail.FieldByName('REB14').AsFloat)+
',RAF36=ISNULL(RAF36,0.0)+'+VarToSql((-1)*QryDetail.FieldByName('REB18').AsFloat)+
',RAF37=ISNULL(RAF37,0.0)+'+VarToSql((-1)*QryDetail.FieldByName('REB14').AsFloat)+
' WHERE RAF01='+VarToSql(Trim(QryDetail.FieldByName('REB05').AsString))+' AND RAF02='+VarToSql(Trim(QryDetail.FieldByName('REB06').AsString)));
end;
i :=i+1;
QryDetail.Next;
end;
//5、更新对帐单表头已开票金额、转应收金额
ExecuteSQL(' UPDATE ACREC SET ACREC.REC14=AA.YKP,ACREC.REC13=AA.YSK '+
' FROM ACREC,(SELECT REC01,SUM(ISNULL(RED12,0.0)*ISNULL(RED13,0.0)+ISNULL(RED26,0.0)) AS JE,SUM(ISNULL(RED19,0.0)) AS YSK, SUM(ISNULL(RED20,0.0)) AS YKP '+
' FROM ACREC '+
' INNER JOIN ACRED ON ACREC.REC01=ACRED.RED01 '+
' WHERE ACREC.REC01='+VarToSql(Trim(vREC01))+
' GROUP BY REC01) AS AA WHERE ACREC.REC01=AA.REC01 ');
//6、更新对帐单表头锁定码
ExecuteSQL(' UPDATE ACREC SET REC15=(CASE WHEN (ISNULL(REC10,0.0)-ISNULL(REC13,0.0)=0) AND (ISNULL(REC10,0.0)-ISNULL(REC14,0.0)=0.0) THEN ''Y'' ELSE ''N'' END ) WHERE REC01='+VarToSql(Trim(vREC01)));
dlladocn.CommitTrans;
except
on E:Exception do
begin
dlladocn.RollbackTrans;
Application.Messagebox(pchar('操作失败.'+#13#10+E.Message),'提示信息',MB_OK+MB_ICONERROR);
end;
end;
end
else
begin
try
if not dlladocn.InTransaction then
dlladocn.BeginTrans;
QryDetail.First;
//5、删除对帐单表头
ExecuteSQL('DELETE ACREC WHERE EXISTS(SELECT 1 FROM (SELECT DISTINCT REB22 FROM ACREB WHERE REB01='+VarToSql(Trim(QryDetail.FieldByName('REB01').AsString))+') AS AA WHERE AA.REB22=ACREC.REC01 )');
While not QryDetail.eof do
begin
//1、更新对帐单
ExecuteSQL('DELETE ACRED WHERE RED01='+VarToSql(Trim(QryDetail.FieldByName('REB22').AsString))+' AND RED02='+VarToSql(Trim(QryDetail.FieldByName('REB23').AsString))+' ');
//2、更新发票对帐单信息
ExecuteSQL('UPDATE ACREB SET REB22='''',REB23='''' WHERE REB01='+VarToSql(Trim(QryDetail.FieldByName('REB01').AsString))+' AND REB02='+VarToSql(Trim(QryDetail.FieldByName('REB02').AsString)));
if QryDetail.FieldByName('REB03').AsString ='1' Then
begin
//3、更新销货单开票数量、开票金额、对帐数量、对帐金额
ExecuteSQL('UPDATE ACRAB SET RAB31=ISNULL(RAB31,0.0)-'+VarToSql(QryDetail.FieldByName('REB18').AsFloat)+
',RAB34=ISNULL(RAB34,0.0)-'+VarToSql(QryDetail.FieldByName('REB14').AsFloat)+
',RAB36=ISNULL(RAB36,0.0)-'+VarToSql(QryDetail.FieldByName('REB18').AsFloat)+
',RAB37=ISNULL(RAB37,0.0)-'+VarToSql(QryDetail.FieldByName('REB14').AsFloat)+
' WHERE RAB03='+VarToSql(Trim(QryDetail.FieldByName('REB04').AsString)+'-'+Trim(QryDetail.FieldByName('REB05').AsString)+'-'+Trim(QryDetail.FieldByName('REB06').AsString)));
end;
if QryDetail.FieldByName('REB03').AsString ='2' Then
begin
//4、更新销退单开票数量、开票金额、对帐数量、对帐金额
ExecuteSQL('UPDATE ACRBB SET RBB32=ISNULL(RBB32,0.0)-'+VarToSql((-1)*QryDetail.FieldByName('REB18').AsFloat)+
',RBB35=ISNULL(RBB35,0.0)-'+VarToSql((-1)*QryDetail.FieldByName('REB14').AsFloat)+
',RBB37=ISNULL(RBB37,0.0)-'+VarToSql((-1)*QryDetail.FieldByName('REB18').AsFloat)+
',RBB38=ISNULL(RBB38,0.0)-'+VarToSql((-1)*QryDetail.FieldByName('REB14').AsFloat)+
' WHERE RBB03='+VarToSql(Trim(QryDetail.FieldByName('REB04').AsString)+'-'+Trim(QryDetail.FieldByName('REB05').AsString)+'-'+Trim(QryDetail.FieldByName('REB06').AsString)));
end;
if QryDetail.FieldByName('REB03').AsString ='3' Then
begin
//5、更新其它费用开票数量、已开票金额、对帐数量、对帐金额
ExecuteSQL('UPDATE ACRJB SET RJB08=ISNULL(RJB08,0.0)-'+VarToSql(QryDetail.FieldByName('REB14').AsFloat)+
',RJB09=ISNULL(RJB09,0.0)-'+VarToSql(QryDetail.FieldByName('REB14').AsFloat)+
',RJB17=ISNULL(RJB17,0.0)+'+VarToSql(QryDetail.FieldByName('REB18').AsFloat)+
' WHERE ACRJB.RJB01='+Trim(QryDetail.FieldByName('REB05').AsString)+' AND ACRJB.RJB02='+Trim(QryDetail.FieldByName('REB06').AsString));
end;
if QryDetail.FieldByName('REB03').AsString ='5' Then //更新其它销货
begin
//6、更新其它销货开票数量、开票金额、对帐数量、转应收金额
ExecuteSQL('UPDATE ACRAD SET RAD31=ISNULL(RAD31,0.0)-'+VarToSql(QryDetail.FieldByName('REB18').AsFloat)+
',RAD34=ISNULL(RAD34,0.0)-'+VarToSql(QryDetail.FieldByName('REB14').AsFloat)+
',RAD36=ISNULL(RAD36,0.0)-'+VarToSql(QryDetail.FieldByName('REB18').AsFloat)+
',RAD37=ISNULL(RAD37,0.0)-'+VarToSql(QryDetail.FieldByName('REB14').AsFloat)+
' WHERE RAD01='+VarToSql(Trim(QryDetail.FieldByName('REB05').AsString))+' AND RAD02='+VarToSql(Trim(QryDetail.FieldByName('REB06').AsString)));
end;
if QryDetail.FieldByName('REB03').AsString ='6' Then //更新其它销退
begin
//7、更新销货折让开票数量、开票金额、对帐数量、转应收金额
ExecuteSQL('UPDATE ACRAF SET RAF31=ISNULL(RAF31,0.0)-'+VarToSql((-1)*QryDetail.FieldByName('REB18').AsFloat)+
',RAF34=ISNULL(RAF34,0.0)-'+VarToSql((-1)*QryDetail.FieldByName('REB14').AsFloat)+
',RAF36=ISNULL(RAF36,0.0)-'+VarToSql((-1)*QryDetail.FieldByName('REB18').AsFloat)+
',RAF37=ISNULL(RAF37,0.0)-'+VarToSql((-1)*QryDetail.FieldByName('REB14').AsFloat)+
' WHERE RAF01='+VarToSql(Trim(QryDetail.FieldByName('REB05').AsString))+' AND RAF02='+VarToSql(Trim(QryDetail.FieldByName('REB06').AsString)));
end;
QryDetail.Next;
end;
dlladocn.CommitTrans;
except
on E:Exception do
begin
dlladocn.RollbackTrans;
Application.Messagebox(pchar('操作失败.'+#13#10+E.Message),'提示信息',MB_OK+MB_ICONERROR);
end;
end;
end;
end;
QryDetail.requery;
end;
procedure TfrmACREABD.wwDBGrid2CalcCellColors(Sender: TObject;
Field: TField; State: TGridDrawState; Highlight: Boolean; AFont: TFont;
ABrush: TBrush);
begin
inherited;
if ((Field.FieldName = 'REB04') or (Field.FieldName = 'REB12') or (Field.FieldName = 'REB14') or (Field.FieldName = 'REB18')) then
begin
ABrush.Color:= $00B9FFFF;
AFont.Color :=clblack;
end;
end;
procedure TfrmACREABD.frxReport1BeforePrint(Sender: TfrxReportComponent);
begin
inherited;
TfrxMemoView(frxReport1.FindObject('memo32')).Text :=wwDBComboBox1.Text;
TfrxMemoView(frxReport1.FindObject('memo45')).Text :=wwDBComboBox2.Text;
TfrxMemoView(frxReport1.FindObject('memo46')).Text :=wwDBEdit7.Text;
end;
procedure TfrmACREABD.printClick(Sender: TObject);
begin
//inherited;
end;
procedure TfrmACREABD.A41Click(Sender: TObject);
begin
if (DSMaster.DataSet.IsEmpty) or (DSDetail.DataSet.IsEmpty) then
begin
Application.MessageBox('记录为空,打印无效.','提示信息',MB_IconInformation+MB_OK);
Abort;
end;
try
QryMaster.DisableControls;
QryMaster.Locate('REA01',Trim(wwDBEdit1.Text),[]);
frxReport1.Report.LoadFromFile(GetLogDir('Rpt')+'ACREABDA.FR3');
frxReport1.ShowReport(True);
QryMaster.EnableControls;
except
on E:Exception do
begin
messagedlg('报表文件不存在,单据打印失败 ! '+#10#13+E.Message,mtError,[MBOK],0);
Abort;
end;
end;
end;
procedure TfrmACREABD.N1Click(Sender: TObject);
begin
if (DSMaster.DataSet.IsEmpty) or (DSDetail.DataSet.IsEmpty) then
begin
Application.MessageBox('记录为空,打印无效.','提示信息',MB_IconInformation+MB_OK);
Abort;
end;
try
QryMaster.DisableControls;
QryMaster.Locate('REA01',Trim(wwDBEdit1.Text),[]);
frxReport1.Report.LoadFromFile(GetLogDir('Rpt')+'ACREABDB.FR3');
frxReport1.ShowReport(True);
QryMaster.EnableControls;
except
on E:Exception do
begin
messagedlg('报表文件不存在,单据打印失败 ! '+#10#13+E.Message,mtError,[MBOK],0);
Abort;
end;
end;
end;
procedure TfrmACREABD.QryMasterREA06GetText(Sender: TField;
var Text: String; DisplayText: Boolean);
begin
inherited;
if trim(Sender.AsString)='A' then
Text := 'A:专用发票'
else
if trim(Sender.AsString)='B' then
Text := 'B:增值税普通发票'
else
if trim(Sender.AsString)='D' then
Text := 'D:服务性发票'
else
if trim(Sender.AsString)='C' then
Text := 'C:其他';
end;
procedure TfrmACREABD.QryMasterREA07GetText(Sender: TField;
var Text: String; DisplayText: Boolean);
begin
inherited;
if trim(Sender.AsString)='1' then
Text := '1:应税内含'
else
if trim(Sender.AsString)='2' then
Text := '2:应税外加'
else
if trim(Sender.AsString)='3' then
Text := '3:零税率'
else
if trim(Sender.AsString)='4' then
Text := '4:免税'
else
if trim(Sender.AsString)='9' then
Text := '9:不计税';
end;
procedure TfrmACREABD.QryDetailREB12Validate(Sender: TField);
begin
inherited;
if (QryDetail.FieldByName('REB12').AsFloat <>0.0) AND (QryDetail.FieldByName('REB18').AsFloat <>0.0) AND (QryDetail.FieldByName('REB11').AsFloat <>0.0) Then
begin
//本次开票金额=本次开票数量*单价
QryDetail.FieldByName('REB14').AsFloat := StrToFloat(FormatFloat('0.00',QryDetail.FieldByName('REB18').AsFloat * QryDetail.FieldByName('REB12').AsFloat));
//应开票金额= 数量*单价
QryDetail.FieldByName('REB21').AsFloat := QryDetail.FieldByName('REB11').AsFloat * QryDetail.FieldByName('REB12').AsFloat;
end;
end;
procedure TfrmACREABD.findClick(Sender: TObject);
var
fSQL: string;
begin
if not Assigned(frmfilterf) then
frmfilterf:=Tfrmfilterf.create(application);
with frmfilterf do
begin
FilterfCDS:=FrmGrid;
FilterfTable:=FrmHDB;
ShowModal;
fSQL:=FilterfSQL;
Free;
end;
if trim(fSQL)<>'' then
begin
fSQL:=COPY(fSQL,1,Length(fSQL)-length(' ORDER BY fid DESC'))+' AND ISNULL(ACREA.REA12,'''')=''K'' ORDER BY ACREA.REA01 DESC ';
QryMaster.DisableControls;
with QryMaster do
begin
Connection:=DlladoCn;
Close;
SQL.Clear;
SQL.Add(fSQL);
Open;
end;
QryMaster.EnableControls;
end
else
begin
QryMaster.DisableControls;
fSQL:=' SELECT * FROM ACREA WHERE ISNULL(ACREA.REA12,'''')=''K'' ORDER BY ACREA.REA01 DESC ';
with QryMaster do
begin
Connection:=DlladoCn;
Close;
SQL.Clear;
SQL.Add(fSQL);
Open;
end;
QryMaster.EnableControls;
end;
if QryMaster.RecordCount<>0 then
refreshmode:=True;
recRefresh;
btnRefresh;
PageControl1.ActivePageIndex:=1;
PageControl1.OnChange(Sender);
QryMaster.First;
end;
procedure TfrmACREABD.SpeedButton3Click(Sender: TObject);
Var
QryTmp:TADOQuery;
vRQ:String;
begin
inherited;
if Trim(wwDBEdit2.Text)='' Then
begin
Application.MessageBox('客户编号不能为空!','提示信息',MB_IconInformation+MB_OK);
abort;
end;
if not Assigned(frmdate) then
begin
frmdate :=Tfrmdate.Create(Application);
frmdate.ShowModal;
QryMaster.FieldByName('REA13').AsString :=copy(Trim(datetostr(frmdate.vdate)),1,4)+copy(Trim(datetostr(frmdate.vdate)),6,2);
frmdate.Free;
end;
if (Trim(wwDBEdit8.Text)<>'') and (Trim(wwDBEdit2.Text)<>'') Then
begin
vRQ:=Trim(wwDBEdit8.Text)+'01';
//取帐期起始日期、帐期结束日期
try
QryTmp:=TADOQuery.Create(nil);
QryTmp.Connection:=DllAdoCn;
QryTmp.EnableBCD :=False;
QryTmp.Close;
QryTmp.SQL.Clear;
QryTmp.SQL.Add(' SELECT RGA07,RGA23,'+
' CASE WHEN RGA23<>'''' AND (RGA23=''31'' OR RGA23=''30'') THEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(8),EndofTheMonth,112),1,6)+''01'',112) '+
' WHEN RGA23<>'''' AND RGA23<>''31'' AND RGA23<>''30'' THEN DATEADD(dd,1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(8),priorEndofTheMonth,112),1,6)+RGA23,112)) '+
' WHEN RGA23='''' THEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(8),EndofTheMonth,112),1,6)+''01'',112) '+
' End BEGRQ, '+
' CASE WHEN RGA23<>'''' AND (RGA23=''31'' OR RGA23=''30'') THEN EndofTheMonth '+
' WHEN RGA23<>'''' AND RGA23<>''31'' AND RGA23<>''30'' THEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(8),EndofTheMonth,112),1,6)+RGA23,112) '+
' WHEN RGA23='''' THEN EndofTheMonth '+
' End ENDRQ '+
' FROM (SELECT RGA07,RGA23,RQ, '+
' EndofTheMonth,priorEndofTheMonth,NextEndofTheMonth '+
' FROM (SELECT RGA07,RGA23,RQ, '+
' DATEADD(dd,-1,DATEADD(mm,DATEDIFF(m,0,RQ)+1,0)) AS EndofTheMonth, '+
' DATEADD(dd,-1,DATEADD(mm,DATEDIFF(m,0,RQ),0)) AS priorEndofTheMonth, '+
' DATEADD(dd,-1,DATEADD(mm,DATEDIFF(m,0,RQ)+2,0)) AS NextEndofTheMonth '+
' FROM (SELECT RGA07,RGA23,CONVERT(DATETIME,'+VarToSql(vRQ)+') RQ '+
' FROM ACRGA '+
' WHERE RGA01='+VarToSql(Trim(wwDBEdit2.Text))+') AS AA) AS BB) AS CC ');
QryTmp.Open;
QryTmp.first;
QryMaster.FieldByName('REA16').AsDateTime :=QryTmp.FieldByName('BEGRQ').AsDateTime;
QryMaster.FieldByName('REA17').AsDateTime :=QryTmp.FieldByName('ENDRQ').AsDateTime;
finally
QryTmp.Close;
QryTmp.Free;
end;
end;
end;
procedure TfrmACREABD.QryMasterREA02Validate(Sender: TField);
Var
QryTmp:TADOQuery;
begin
inherited;
if QryMaster.State in [dsEdit,dsInsert] Then
begin
try
QryTmp:=TADOQuery.Create(nil);
QryTmp.Connection:=DllAdoCn;
QryTmp.EnableBCD :=False;
QryTmp.Close;
QryTmp.SQL.Clear;
QryTmp.SQL.Add(' SELECT RQ,RGA01,YS,TS,DATEADD(DD,1,DATEADD(MM,YS,DATEADD(dd,TS,RQ))) AS SKRQ '+
' FROM(SELECT '+VarToSql(QryMaster.FieldByName('REA02').AsDateTime)+' AS RQ,RGA01, '+
' CASE WHEN RGA07=30 THEN 1 WHEN RGA07=60 THEN 2 WHEN RGA07=90 THEN 3 WHEN RGA07=120 THEN 4 ELSE 0 END YS, '+
' CASE WHEN RGA07=30 OR RGA07=60 OR RGA07=90 OR RGA07=120 THEN 0 ELSE RGA07 END TS '+
' FROM ACRGA '+
' WHERE RGA01='+VarToSql(Trim(wwDBEdit2.Text))+') AS AA ');
QryTmp.Open;
QryMaster.FieldByName('REA14').AsFloat := QryTmp.FieldByName('SKRQ').AsDateTime; //收款日期
finally
QryTmp.Close;
QryTmp.Free;
end;
end;
end;
procedure TfrmACREABD.gridaddClick(Sender: TObject);
begin
inherited;
QryDetail.FieldByName('REB03').AsString :='1';
end;
procedure TfrmACREABD.wwDBCDREB04KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
Var
sResult:String;
sl:TStringList;
i:integer;
QryTmp:TADOQuery;
vRGA24:String;
sSQL:String;
begin
inherited;
if QryDetail.State in [dsEdit,dsInsert] Then
begin
if Trim(wwDBEdit2.Text)='' Then
begin
Application.MessageBox('客户编号不能为空!','提示信息',MB_IconInformation+MB_OK);
abort;
end;
if Key = VK_F3 then //销货
begin
if not Assigned(frmACRAABHELP) then
begin
frmACRAABHELP := TfrmACRAABHELP.Create(Application);
frmACRAABHELP.sWhere :=' RAA06='+VarToSql(Trim(wwDBEdit2.Text))+' AND ISNULL(ACRAB.RAB39,'''')<>''Y'' AND ISNULL(ACRGA.RGA25,'''')<>''Y'' AND ISNULL(RAB30,0.0)-ISNULL(RAB34,0.0)-ISNULL(RAB38,0.0)>0 AND ISNULL(RAB30,0.0)-ISNULL(RAB33,0.0)-ISNULL(RAB37,0.0)>0.0 ';
frmACRAABHELP.ShowModal;
sResult:=frmACRAABHELP.rtnHelpFieldName;
frmACRAABHELP.Free;
end;
if sResult<>'' Then
begin
sl:=TStringList.Create;
sl.Delimiter :=';';
sl.DelimitedText := Trim(sResult);
if sl.Count=1 then
begin
try
QryTmp:=TADOQuery.Create(nil);
QryTmp.Connection:=dlladocn;
QryTmp.EnableBCD :=False;
QryTmp.Close;
QryTmp.SQL.Clear;
QryTmp.SQL.Add(' SELECT RAA05,RAB15,RAB14,RAB03,RAB04,RAB05,RAB06,RAB09,RAB10,RAB08,RAB29,RAB28,'+
' RAB11,RGA07,RGA28,RGA23,RAB31,RAB32,RAB13, '+
' ISNULL(RAB30,0.0)-ISNULL(RAB34,0.0)-ISNULL(RAB38,0.0) AS REB14 '+
' FROM ACRAB '+
' INNER JOIN ACRAA ON ACRAB.RAB01=ACRAA.RAA01 '+
' LEFT JOIN ACRGA ON ACRGA.RGA01=ACRAA.RAA06 '+
' WHERE ACRAA.CONFORM_CODE=''Y'' AND ISNULL(ACRGA.RGA25,'''')<>''Y'' AND ACRAB.RAB01+''-''+ACRAB.RAB02='+VarToSql(Trim(sl.Strings[0])));
QryTmp.Open;
if QryTmp.RecordCount >0 Then
begin
QryDetail.Edit;
QryDetail.FieldByName('REB03').AsString := '1'; //来源
QryDetail.FieldByName('REB04').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),1,4); //来源单别
QryDetail.FieldByName('REB05').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),6,11); //来源单号
QryDetail.FieldByName('REB06').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),18,4); //来源序号
QryDetail.FieldByName('REB07').AsString := QryTmp.FieldByName('RAB04').AsString; //品号
QryDetail.FieldByName('REB08').AsString := QryTmp.FieldByName('RAB05').AsString; //品名
QryDetail.FieldByName('REB09').AsString := QryTmp.FieldByName('RAB06').AsString; //规格
QryDetail.FieldByName('REB10').AsString := QryTmp.FieldByName('RAB09').AsString; //单位
QryDetail.FieldByName('REB11').AsFloat := QryTmp.FieldByName('RAB08').AsFloat-QryTmp.FieldByName('RAB31').AsFloat; //数量
QryDetail.FieldByName('REB12').AsFloat := QryTmp.FieldByName('RAB10').AsFloat; //单价
QryDetail.FieldByName('REB13').AsString := ''; //备注
QryDetail.FieldByName('REB14').AsFloat := QryTmp.FieldByName('REB14').AsFloat; //本次开票金额
QryDetail.FieldByName('REB15').AsFloat := 0.0; //已开票金额
QryDetail.FieldByName('REB16').AsString := QryTmp.FieldByName('RAB15').AsString; //客户单号
QryDetail.FieldByName('REB17').AsString := QryTmp.FieldByName('RAB14').AsString; //快捷码
QryDetail.FieldByName('REB18').AsFloat := QryTmp.FieldByName('RAB08').AsFloat-QryTmp.FieldByName('RAB31').AsFloat; //本次开票数量
QryDetail.FieldByName('REB19').AsFloat :=0.0; //已开票数量
QryDetail.FieldByName('REB20').AsString := '传感器'; //货物或应带劳务名称
QryDetail.FieldByName('REB21').AsFloat := QryTmp.FieldByName('REB14').AsFloat; //应开票金额
QryDetail.FieldByName('REB22').AsString := ''; //对帐单号
QryDetail.FieldByName('REB23').AsString := ''; //对帐序号
QryDetail.FieldByName('REB24').AsDateTime := QryTmp.FieldByName('RAA05').AsDateTime; //销退货日期
QryDetail.FieldByName('REB25').AsString := QryTmp.FieldByName('RAB11').AsString; //订单单号
QryDetail.FieldByName('REB26').AsString := QryTmp.FieldByName('RAB32').AsString; //送货单号
QryDetail.FieldByName('REB27').AsString := QryTmp.FieldByName('RAB13').AsString; //客户品号
end;
finally
QryTmp.Close;
QryTmp.Free;
end;
end
else
begin
for i:=1 to sl.Count-1 do
begin
if i=1 then
begin
try
QryTmp:=TADOQuery.Create(nil);
QryTmp.Connection:=dlladocn;
QryTmp.EnableBCD :=False;
QryTmp.Close;
QryTmp.SQL.Clear;
QryTmp.SQL.Add(' SELECT RAA05,RAB15,RAB14,RAB03,RAB04,RAB05,RAB06,RAB09,RAB10,RAB08,RAB29,RAB28,'+
' RAB11,RGA07,RGA28,RGA23,RAB31,RAB32,RAB13, '+
' ISNULL(RAB30,0.0)-ISNULL(RAB34,0.0)-ISNULL(RAB38,0.0) AS REB14 '+
' FROM ACRAB '+
' INNER JOIN ACRAA ON ACRAB.RAB01=ACRAA.RAA01 '+
' LEFT JOIN ACRGA ON ACRGA.RGA01=ACRAA.RAA06 '+
' WHERE ACRAA.CONFORM_CODE=''Y'' AND ISNULL(ACRGA.RGA25,'''')<>''Y'' AND ACRAB.RAB01+''-''+ACRAB.RAB02='+VarToSql(Trim(sl.Strings[0])));
QryTmp.Open;
if QryTmp.RecordCount >0 Then
begin
QryDetail.Edit;
QryDetail.FieldByName('REB03').AsString := '1'; //来源
QryDetail.FieldByName('REB04').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),1,4); //来源单别
QryDetail.FieldByName('REB05').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),6,11); //来源单号
QryDetail.FieldByName('REB06').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),18,4); //来源序号
QryDetail.FieldByName('REB07').AsString := QryTmp.FieldByName('RAB04').AsString; //品号
QryDetail.FieldByName('REB08').AsString := QryTmp.FieldByName('RAB05').AsString; //品名
QryDetail.FieldByName('REB09').AsString := QryTmp.FieldByName('RAB06').AsString; //规格
QryDetail.FieldByName('REB10').AsString := QryTmp.FieldByName('RAB09').AsString; //单位
QryDetail.FieldByName('REB11').AsFloat := QryTmp.FieldByName('RAB08').AsFloat-QryTmp.FieldByName('RAB31').AsFloat; //数量
QryDetail.FieldByName('REB12').AsFloat := QryTmp.FieldByName('RAB10').AsFloat; //单价
QryDetail.FieldByName('REB13').AsString := ''; //备注
QryDetail.FieldByName('REB14').AsFloat := QryTmp.FieldByName('REB14').AsFloat; //本次开票金额
QryDetail.FieldByName('REB15').AsFloat := 0.0; //已开票金额
QryDetail.FieldByName('REB16').AsString := QryTmp.FieldByName('RAB15').AsString; //客户单号
QryDetail.FieldByName('REB17').AsString := QryTmp.FieldByName('RAB14').AsString; //快捷码
QryDetail.FieldByName('REB18').AsFloat := QryTmp.FieldByName('RAB08').AsFloat-QryTmp.FieldByName('RAB31').AsFloat; //本次开票数量
QryDetail.FieldByName('REB19').AsFloat :=0.0; //已开票数量
QryDetail.FieldByName('REB20').AsString := '传感器'; //货物或应带劳务名称
QryDetail.FieldByName('REB21').AsFloat := QryTmp.FieldByName('REB14').AsFloat; //应开票金额
QryDetail.FieldByName('REB22').AsString := ''; //对帐单号
QryDetail.FieldByName('REB23').AsString := ''; //对帐序号
QryDetail.FieldByName('REB24').AsDateTime := QryTmp.FieldByName('RAA05').AsDateTime; //销退货日期
QryDetail.FieldByName('REB25').AsString := QryTmp.FieldByName('RAB11').AsString; //订单单号
QryDetail.FieldByName('REB26').AsString := QryTmp.FieldByName('RAB32').AsString; //送货单号
QryDetail.FieldByName('REB27').AsString := QryTmp.FieldByName('RAB13').AsString; //客户品号
end;
finally
QryTmp.Close;
QryTmp.Free;
end;
end
else
begin
QryDetail.Append;
try
QryTmp:=TADOQuery.Create(nil);
QryTmp.Connection:=dlladocn;
QryTmp.EnableBCD :=False;
QryTmp.Close;
QryTmp.SQL.Clear;
QryTmp.SQL.Add(' SELECT RAA05,RAB15,RAB14,RAB03,RAB04,RAB05,RAB06,RAB09,RAB10,RAB08,RAB29,RAB28,'+
' RAB11,RGA07,RGA28,RGA23,RAB31,RAB32,RAB13, '+
' ISNULL(RAB30,0.0)-ISNULL(RAB34,0.0)-ISNULL(RAB38,0.0) AS REB14 '+
' FROM ACRAB '+
' INNER JOIN ACRAA ON ACRAB.RAB01=ACRAA.RAA01 '+
' LEFT JOIN ACRGA ON ACRGA.RGA01=ACRAA.RAA06 '+
' WHERE ACRAA.CONFORM_CODE=''Y'' AND ISNULL(ACRGA.RGA25,'''')<>''Y'' AND ACRAB.RAB01+''-''+ACRAB.RAB02='+VarToSql(Trim(sl.Strings[i-1])));
QryTmp.Open;
if QryTmp.RecordCount >0 Then
begin
QryDetail.Edit;
QryDetail.FieldByName('REB03').AsString := '1'; //来源
QryDetail.FieldByName('REB04').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),1,4); //来源单别
QryDetail.FieldByName('REB05').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),6,11); //来源单号
QryDetail.FieldByName('REB06').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),18,4); //来源序号
QryDetail.FieldByName('REB07').AsString := QryTmp.FieldByName('RAB04').AsString; //品号
QryDetail.FieldByName('REB08').AsString := QryTmp.FieldByName('RAB05').AsString; //品名
QryDetail.FieldByName('REB09').AsString := QryTmp.FieldByName('RAB06').AsString; //规格
QryDetail.FieldByName('REB10').AsString := QryTmp.FieldByName('RAB09').AsString; //单位
QryDetail.FieldByName('REB11').AsFloat := QryTmp.FieldByName('RAB08').AsFloat-QryTmp.FieldByName('RAB31').AsFloat; //数量
QryDetail.FieldByName('REB12').AsFloat := QryTmp.FieldByName('RAB10').AsFloat; //单价
QryDetail.FieldByName('REB13').AsString := ''; //备注
QryDetail.FieldByName('REB14').AsFloat := QryTmp.FieldByName('REB14').AsFloat; //本次开票金额
QryDetail.FieldByName('REB15').AsFloat := 0.0; //已开票金额
QryDetail.FieldByName('REB16').AsString := QryTmp.FieldByName('RAB15').AsString; //客户单号
QryDetail.FieldByName('REB17').AsString := QryTmp.FieldByName('RAB14').AsString; //快捷码
QryDetail.FieldByName('REB18').AsFloat := QryTmp.FieldByName('RAB08').AsFloat-QryTmp.FieldByName('RAB31').AsFloat; //本次开票数量
QryDetail.FieldByName('REB19').AsFloat :=0.0; //已开票数量
QryDetail.FieldByName('REB20').AsString := '传感器'; //货物或应带劳务名称
QryDetail.FieldByName('REB21').AsFloat := QryTmp.FieldByName('REB14').AsFloat; //应开票金额
QryDetail.FieldByName('REB22').AsString := ''; //对帐单号
QryDetail.FieldByName('REB23').AsString := ''; //对帐序号
QryDetail.FieldByName('REB24').AsDateTime := QryTmp.FieldByName('RAA05').AsDateTime; //销退货日期
QryDetail.FieldByName('REB25').AsString := QryTmp.FieldByName('RAB11').AsString; //订单单号
QryDetail.FieldByName('REB26').AsString := QryTmp.FieldByName('RAB32').AsString; //送货单号
QryDetail.FieldByName('REB27').AsString := QryTmp.FieldByName('RAB13').AsString; //客户品号
end;
finally
QryTmp.Close;
QryTmp.Free;
end;
end;
end;
end;
end;
end;
if Key = VK_F5 then //销退
begin
if not Assigned(frmACRBABHELP) then
begin
frmACRBABHELP := TfrmACRBABHELP.Create(Application);
frmACRBABHELP.sWhere :=' RBA06='+VarToSql(Trim(wwDBEdit4.Text))+' AND ISNULL(ACRBB.RBB40,'''')<>''Y'' AND ISNULL(ACRGA.RGA25,'''')<>''Y'' AND ISNULL(RBB31,0.0)-ISNULL(RBB35,0.0)-ISNULL(RBB39,0.0)>0 AND ISNULL(RBB31,0.0)-ISNULL(RBB34,0.0)-ISNULL(RBB38,0.0)>0.0 ';
frmACRBABHELP.ShowModal;
sResult:=frmACRBABHELP.rtnHelpFieldName;
frmACRBABHELP.Free;
end;
if sResult<>'' Then
begin
sl:=TStringList.Create;
sl.Delimiter :=';';
sl.DelimitedText := Trim(sResult);
if sl.Count=1 then
begin
try
QryTmp:=TADOQuery.Create(nil);
QryTmp.Connection:=dlladocn;
QryTmp.EnableBCD :=False;
QryTmp.Close;
QryTmp.SQL.Clear;
QryTmp.SQL.Add(' SELECT ''2'' AS BZ,RBA05 AS RAA05,RBB16 AS RAB15,RBB15 AS RAB14,RBB03 AS RAB03,RBB04 AS RAB04,RBB05 AS RAB05,RBB06 AS RAB06,RBB08 AS RAB09,RBB09 AS RAB10, '+
' (-1)*ISNULL(RBB07,0.0) AS RAB08,RBB30 AS RAB29,RBB29 AS RAB28,RBB12 AS RAB11,RGA07,RGA28,RGA23,(-1)*ISNULL(RBB32,0.0) AS RAB31,'+
' RBB33 AS RAB32,RBB14 AS RAB13, '+
' (-1)*(ISNULL(RBB31,0.0)-ISNULL(RBB35,0.0)-ISNULL(RBB39,0.0)) AS REB14 '+
' FROM ACRBB '+
' INNER JOIN ACRBA ON ACRBB.RBB01=ACRBA.RBA01 '+
' LEFT JOIN ACRGA ON ACRGA.RGA01=ACRBA.RBA06 '+
' WHERE ACRBA.CONFORM_CODE=''Y'' AND ISNULL(ACRGA.RGA25,'''')<>''Y'' AND ACRBB.RBB01+''-''+ACRBB.RBB02='+VarToSql(Trim(sl.Strings[0])));
QryTmp.Open;
if QryTmp.RecordCount >0 Then
begin
QryDetail.Edit;
QryDetail.FieldByName('REB03').AsString := '2'; //来源
QryDetail.FieldByName('REB04').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),1,4); //来源单别
QryDetail.FieldByName('REB05').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),6,11); //来源单号
QryDetail.FieldByName('REB06').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),18,4); //来源序号
QryDetail.FieldByName('REB07').AsString := QryTmp.FieldByName('RAB04').AsString; //品号
QryDetail.FieldByName('REB08').AsString := QryTmp.FieldByName('RAB05').AsString; //品名
QryDetail.FieldByName('REB09').AsString := QryTmp.FieldByName('RAB06').AsString; //规格
QryDetail.FieldByName('REB10').AsString := QryTmp.FieldByName('RAB09').AsString; //单位
QryDetail.FieldByName('REB11').AsFloat := QryTmp.FieldByName('RAB08').AsFloat-QryTmp.FieldByName('RAB31').AsFloat; //数量
QryDetail.FieldByName('REB12').AsFloat := QryTmp.FieldByName('RAB10').AsFloat; //单价
QryDetail.FieldByName('REB13').AsString := ''; //备注
QryDetail.FieldByName('REB14').AsFloat := QryTmp.FieldByName('REB14').AsFloat; //本次开票金额
QryDetail.FieldByName('REB15').AsFloat := 0.0; //已开票金额
QryDetail.FieldByName('REB16').AsString := QryTmp.FieldByName('RAB15').AsString; //客户单号
QryDetail.FieldByName('REB17').AsString := QryTmp.FieldByName('RAB14').AsString; //快捷码
QryDetail.FieldByName('REB18').AsFloat := QryTmp.FieldByName('RAB08').AsFloat-QryTmp.FieldByName('RAB31').AsFloat; //本次开票数量
QryDetail.FieldByName('REB19').AsFloat :=0.0; //已开票数量
QryDetail.FieldByName('REB20').AsString := '传感器'; //货物或应带劳务名称
QryDetail.FieldByName('REB21').AsFloat := QryTmp.FieldByName('REB14').AsFloat; //应开票金额
QryDetail.FieldByName('REB22').AsString := ''; //对帐单号
QryDetail.FieldByName('REB23').AsString := ''; //对帐序号
QryDetail.FieldByName('REB24').AsDateTime := QryTmp.FieldByName('RAA05').AsDateTime; //销退货日期
QryDetail.FieldByName('REB25').AsString := QryTmp.FieldByName('RAB11').AsString; //订单单号
QryDetail.FieldByName('REB26').AsString := QryTmp.FieldByName('RAB32').AsString; //送货单号
QryDetail.FieldByName('REB27').AsString := QryTmp.FieldByName('RAB13').AsString; //客户品号
end;
finally
QryTmp.Close;
QryTmp.Free;
end;
end
else
begin
for i:=1 to sl.Count-1 do
begin
if i=1 then
begin
try
QryTmp:=TADOQuery.Create(nil);
QryTmp.Connection:=dlladocn;
QryTmp.EnableBCD :=False;
QryTmp.Close;
QryTmp.SQL.Clear;
QryTmp.SQL.Add(' SELECT ''2'' AS BZ,RBA05 AS RAA05,RBB16 AS RAB15,RBB15 AS RAB14,RBB03 AS RAB03,RBB04 AS RAB04,RBB05 AS RAB05,RBB06 AS RAB06,RBB08 AS RAB09,RBB09 AS RAB10, '+
' (-1)*ISNULL(RBB07,0.0) AS RAB08,RBB30 AS RAB29,RBB29 AS RAB28,RBB12 AS RAB11,RGA07,RGA28,RGA23,(-1)*ISNULL(RBB32,0.0) AS RAB31,'+
' RBB33 AS RAB32,RBB14 AS RAB13, '+
' (-1)*(ISNULL(RBB31,0.0)-ISNULL(RBB35,0.0)-ISNULL(RBB39,0.0)) AS REB14 '+
' FROM ACRBB '+
' INNER JOIN ACRBA ON ACRBB.RBB01=ACRBA.RBA01 '+
' LEFT JOIN ACRGA ON ACRGA.RGA01=ACRBA.RBA06 '+
' WHERE ACRBA.CONFORM_CODE=''Y'' AND ISNULL(ACRGA.RGA25,'''')<>''Y'' AND ACRBB.RBB01+''-''+ACRBB.RBB02='+VarToSql(Trim(sl.Strings[0])));
QryTmp.Open;
if QryTmp.RecordCount >0 Then
begin
QryDetail.Edit;
QryDetail.FieldByName('REB03').AsString := '2'; //来源
QryDetail.FieldByName('REB04').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),1,4); //来源单别
QryDetail.FieldByName('REB05').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),6,11); //来源单号
QryDetail.FieldByName('REB06').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),18,4); //来源序号
QryDetail.FieldByName('REB07').AsString := QryTmp.FieldByName('RAB04').AsString; //品号
QryDetail.FieldByName('REB08').AsString := QryTmp.FieldByName('RAB05').AsString; //品名
QryDetail.FieldByName('REB09').AsString := QryTmp.FieldByName('RAB06').AsString; //规格
QryDetail.FieldByName('REB10').AsString := QryTmp.FieldByName('RAB09').AsString; //单位
QryDetail.FieldByName('REB11').AsFloat := QryTmp.FieldByName('RAB08').AsFloat-QryTmp.FieldByName('RAB31').AsFloat; //数量
QryDetail.FieldByName('REB12').AsFloat := QryTmp.FieldByName('RAB10').AsFloat; //单价
QryDetail.FieldByName('REB13').AsString := ''; //备注
QryDetail.FieldByName('REB14').AsFloat := QryTmp.FieldByName('REB14').AsFloat; //本次开票金额
QryDetail.FieldByName('REB15').AsFloat := 0.0; //已开票金额
QryDetail.FieldByName('REB16').AsString := QryTmp.FieldByName('RAB15').AsString; //客户单号
QryDetail.FieldByName('REB17').AsString := QryTmp.FieldByName('RAB14').AsString; //快捷码
QryDetail.FieldByName('REB18').AsFloat := QryTmp.FieldByName('RAB08').AsFloat-QryTmp.FieldByName('RAB31').AsFloat; //本次开票数量
QryDetail.FieldByName('REB19').AsFloat :=0.0; //已开票数量
QryDetail.FieldByName('REB20').AsString := '传感器'; //货物或应带劳务名称
QryDetail.FieldByName('REB21').AsFloat := QryTmp.FieldByName('REB14').AsFloat; //应开票金额
QryDetail.FieldByName('REB22').AsString := ''; //对帐单号
QryDetail.FieldByName('REB23').AsString := ''; //对帐序号
QryDetail.FieldByName('REB24').AsDateTime := QryTmp.FieldByName('RAA05').AsDateTime; //销退货日期
QryDetail.FieldByName('REB25').AsString := QryTmp.FieldByName('RAB11').AsString; //订单单号
QryDetail.FieldByName('REB26').AsString := QryTmp.FieldByName('RAB32').AsString; //送货单号
QryDetail.FieldByName('REB27').AsString := QryTmp.FieldByName('RAB13').AsString; //客户品号
end;
finally
QryTmp.Close;
QryTmp.Free;
end;
end
else
begin
QryDetail.Append;
try
QryTmp:=TADOQuery.Create(nil);
QryTmp.Connection:=dlladocn;
QryTmp.EnableBCD :=False;
QryTmp.Close;
QryTmp.SQL.Clear;
QryTmp.SQL.Add(' SELECT ''2'' AS BZ,RBA05 AS RAA05,RBB16 AS RAB15,RBB15 AS RAB14,RBB03 AS RAB03,RBB04 AS RAB04,RBB05 AS RAB05,RBB06 AS RAB06,RBB08 AS RAB09,RBB09 AS RAB10, '+
' (-1)*ISNULL(RBB07,0.0) AS RAB08,RBB30 AS RAB29,RBB29 AS RAB28,RBB12 AS RAB11,RGA07,RGA28,RGA23,(-1)*ISNULL(RBB32,0.0) AS RAB31,'+
' RBB33 AS RAB32,RBB14 AS RAB13, '+
' (-1)*(ISNULL(RBB31,0.0)-ISNULL(RBB35,0.0)-ISNULL(RBB39,0.0)) AS REB14 '+
' FROM ACRBB '+
' INNER JOIN ACRBA ON ACRBB.RBB01=ACRBA.RBA01 '+
' LEFT JOIN ACRGA ON ACRGA.RGA01=ACRBA.RBA06 '+
' WHERE ACRBA.CONFORM_CODE=''Y'' AND ISNULL(ACRGA.RGA25,'''')<>''Y'' AND ACRBB.RBB01+''-''+ACRBB.RBB02='+VarToSql(Trim(sl.Strings[i-1])));
QryTmp.Open;
if QryTmp.RecordCount >0 Then
begin
QryDetail.Edit;
QryDetail.FieldByName('REB03').AsString := '2'; //来源
QryDetail.FieldByName('REB04').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),1,4); //来源单别
QryDetail.FieldByName('REB05').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),6,11); //来源单号
QryDetail.FieldByName('REB06').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),18,4); //来源序号
QryDetail.FieldByName('REB07').AsString := QryTmp.FieldByName('RAB04').AsString; //品号
QryDetail.FieldByName('REB08').AsString := QryTmp.FieldByName('RAB05').AsString; //品名
QryDetail.FieldByName('REB09').AsString := QryTmp.FieldByName('RAB06').AsString; //规格
QryDetail.FieldByName('REB10').AsString := QryTmp.FieldByName('RAB09').AsString; //单位
QryDetail.FieldByName('REB11').AsFloat := QryTmp.FieldByName('RAB08').AsFloat-QryTmp.FieldByName('RAB31').AsFloat; //数量
QryDetail.FieldByName('REB12').AsFloat := QryTmp.FieldByName('RAB10').AsFloat; //单价
QryDetail.FieldByName('REB13').AsString := ''; //备注
QryDetail.FieldByName('REB14').AsFloat := QryTmp.FieldByName('REB14').AsFloat; //本次开票金额
QryDetail.FieldByName('REB15').AsFloat := 0.0; //已开票金额
QryDetail.FieldByName('REB16').AsString := QryTmp.FieldByName('RAB15').AsString; //客户单号
QryDetail.FieldByName('REB17').AsString := QryTmp.FieldByName('RAB14').AsString; //快捷码
QryDetail.FieldByName('REB18').AsFloat := QryTmp.FieldByName('RAB08').AsFloat-QryTmp.FieldByName('RAB31').AsFloat; //本次开票数量
QryDetail.FieldByName('REB19').AsFloat :=0.0; //已开票数量
QryDetail.FieldByName('REB20').AsString := '传感器'; //货物或应带劳务名称
QryDetail.FieldByName('REB21').AsFloat := QryTmp.FieldByName('REB14').AsFloat; //应开票金额
QryDetail.FieldByName('REB22').AsString := ''; //对帐单号
QryDetail.FieldByName('REB23').AsString := ''; //对帐序号
QryDetail.FieldByName('REB24').AsDateTime := QryTmp.FieldByName('RAA05').AsDateTime; //销退货日期
QryDetail.FieldByName('REB25').AsString := QryTmp.FieldByName('RAB11').AsString; //订单单号
QryDetail.FieldByName('REB26').AsString := QryTmp.FieldByName('RAB32').AsString; //送货单号
QryDetail.FieldByName('REB27').AsString := QryTmp.FieldByName('RAB13').AsString; //客户品号
end;
finally
QryTmp.Close;
QryTmp.Free;
end;
end;
end;
end;
end;
end;
if Key = VK_F6 then //其它
begin
if not Assigned(frmACRJABHELP) then
begin
frmACRJABHELP := TfrmACRJABHELP.Create(Application);
frmACRJABHELP.sWhere :=' RJA06='+VarToSql(Trim(wwDBEdit2.Text))+' AND ISNULL(ACRJB.RJB19,'''')<>''Y'' AND ACRJA.CONFORM_CODE=''Y'' AND ISNULL(ACRGA.RGA25,'''')<>''Y'' AND ISNULL(RJB04,0.0)-ISNULL(RJB08,0.0)-ISNULL(RJB18,0.0)>0 AND ISNULL(RJB04,0.0)-ISNULL(RJB07,0.0)-ISNULL(RJB09,0.0)>0.0 ';
frmACRJABHELP.ShowModal;
sResult:=frmACRJABHELP.rtnHelpFieldName;
frmACRJABHELP.Free;
end;
if sResult<>'' Then
begin
sl:=TStringList.Create;
sl.Delimiter :=';';
sl.DelimitedText := Trim(sResult);
if sl.Count=1 then
begin
try
QryTmp:=TADOQuery.Create(nil);
QryTmp.Connection:=dlladocn;
QryTmp.EnableBCD :=False;
QryTmp.Close;
QryTmp.SQL.Clear;
QryTmp.SQL.Add(' SELECT ''3'' AS BZ,RJB06 AS RAA05,RJB10 AS RAB15,RJB12 AS RAB14,RJB01+''-''+RJB02 AS RAB03,'''' AS RAB04,RJB03 AS RAB05,RJB16 AS RAB06,RJB14 AS RAB09, '+
' RJB15 AS RAB10,RJB13 AS RAB08,''N'' AS RAB29,RJB05 AS RAB28,'''' AS RAB11,'+
' RGA07,RGA28,RGA23,0.0 AS RAB31,'''' AS RAB32,RJB11 AS RAB13, '+
' ISNULL(RJB04,0.0)-ISNULL(RJB08,0.0)-ISNULL(RJB18,0.0) AS REB14 '+
' FROM ACRJA '+
' INNER JOIN ACRJB ON ACRJA.RJA01=ACRJB.RJB01 '+
' LEFT JOIN ACRGA ON ACRGA.RGA01=ACRJA.RJA06 '+
' WHERE ACRJA.CONFORM_CODE=''Y'' AND ISNULL(ACRGA.RGA25,'''')<>''Y'' AND ACRJB.RJB01+''-''+ACRJB.RJB02='+VarToSql(Trim(sl.Strings[0])));
QryTmp.Open;
if QryTmp.RecordCount >0 Then
begin
QryDetail.Edit;
QryDetail.FieldByName('REB03').AsString := '3'; //来源
QryDetail.FieldByName('REB04').AsString := ''; //来源单别
QryDetail.FieldByName('REB05').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),1,11); //来源单号
QryDetail.FieldByName('REB06').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),13,4); //来源序号
QryDetail.FieldByName('REB07').AsString := QryTmp.FieldByName('RAB04').AsString; //品号
QryDetail.FieldByName('REB08').AsString := QryTmp.FieldByName('RAB05').AsString; //品名
QryDetail.FieldByName('REB09').AsString := QryTmp.FieldByName('RAB06').AsString; //规格
QryDetail.FieldByName('REB10').AsString := QryTmp.FieldByName('RAB09').AsString; //单位
QryDetail.FieldByName('REB11').AsFloat := QryTmp.FieldByName('RAB08').AsFloat-QryTmp.FieldByName('RAB31').AsFloat; //数量
QryDetail.FieldByName('REB12').AsFloat := QryTmp.FieldByName('RAB10').AsFloat; //单价
QryDetail.FieldByName('REB13').AsString := ''; //备注
QryDetail.FieldByName('REB14').AsFloat := QryTmp.FieldByName('REB14').AsFloat; //本次开票金额
QryDetail.FieldByName('REB15').AsFloat := 0.0; //已开票金额
QryDetail.FieldByName('REB16').AsString := QryTmp.FieldByName('RAB15').AsString; //客户单号
QryDetail.FieldByName('REB17').AsString := QryTmp.FieldByName('RAB14').AsString; //快捷码
QryDetail.FieldByName('REB18').AsFloat := QryTmp.FieldByName('RAB08').AsFloat-QryTmp.FieldByName('RAB31').AsFloat; //本次开票数量
QryDetail.FieldByName('REB19').AsFloat :=0.0; //已开票数量
QryDetail.FieldByName('REB20').AsString := '传感器'; //货物或应带劳务名称
QryDetail.FieldByName('REB21').AsFloat := QryTmp.FieldByName('REB14').AsFloat; //应开票金额
QryDetail.FieldByName('REB22').AsString := ''; //对帐单号
QryDetail.FieldByName('REB23').AsString := ''; //对帐序号
QryDetail.FieldByName('REB24').AsDateTime := QryTmp.FieldByName('RAA05').AsDateTime; //销退货日期
QryDetail.FieldByName('REB25').AsString := QryTmp.FieldByName('RAB11').AsString; //订单单号
QryDetail.FieldByName('REB26').AsString := QryTmp.FieldByName('RAB32').AsString; //送货单号
QryDetail.FieldByName('REB27').AsString := QryTmp.FieldByName('RAB13').AsString; //客户品号
end;
finally
QryTmp.Close;
QryTmp.Free;
end;
end
else
begin
for i:=1 to sl.Count-1 do
begin
if i=1 then
begin
try
QryTmp:=TADOQuery.Create(nil);
QryTmp.Connection:=dlladocn;
QryTmp.EnableBCD :=False;
QryTmp.Close;
QryTmp.SQL.Clear;
QryTmp.SQL.Add(' SELECT ''3'' AS BZ,RJB06 AS RAA05,RJB10 AS RAB15,RJB12 AS RAB14,RJB01+''-''+RJB02 AS RAB03,'''' AS RAB04,RJB03 AS RAB05,RJB16 AS RAB06,RJB14 AS RAB09, '+
' RJB15 AS RAB10,RJB13 AS RAB08,''N'' AS RAB29,RJB05 AS RAB28,'''' AS RAB11,'+
' RGA07,RGA28,RGA23,0.0 AS RAB31,'''' AS RAB32,RJB11 AS RAB13, '+
' ISNULL(RJB04,0.0)-ISNULL(RJB08,0.0)-ISNULL(RJB18,0.0) AS REB14 '+
' FROM ACRJA '+
' INNER JOIN ACRJB ON ACRJA.RJA01=ACRJB.RJB01 '+
' LEFT JOIN ACRGA ON ACRGA.RGA01=ACRJA.RJA06 '+
' WHERE ACRJA.CONFORM_CODE=''Y'' AND ISNULL(ACRGA.RGA25,'''')<>''Y'' AND ACRJB.RJB01+''-''+ACRJB.RJB02='+VarToSql(Trim(sl.Strings[0])));
QryTmp.Open;
if QryTmp.RecordCount >0 Then
begin
QryDetail.Edit;
QryDetail.FieldByName('REB03').AsString := '3'; //来源
QryDetail.FieldByName('REB04').AsString := ''; //来源单别
QryDetail.FieldByName('REB05').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),1,11); //来源单号
QryDetail.FieldByName('REB06').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),13,4); //来源序号
QryDetail.FieldByName('REB07').AsString := QryTmp.FieldByName('RAB04').AsString; //品号
QryDetail.FieldByName('REB08').AsString := QryTmp.FieldByName('RAB05').AsString; //品名
QryDetail.FieldByName('REB09').AsString := QryTmp.FieldByName('RAB06').AsString; //规格
QryDetail.FieldByName('REB10').AsString := QryTmp.FieldByName('RAB09').AsString; //单位
QryDetail.FieldByName('REB11').AsFloat := QryTmp.FieldByName('RAB08').AsFloat-QryTmp.FieldByName('RAB31').AsFloat; //数量
QryDetail.FieldByName('REB12').AsFloat := QryTmp.FieldByName('RAB10').AsFloat; //单价
QryDetail.FieldByName('REB13').AsString := ''; //备注
QryDetail.FieldByName('REB14').AsFloat := QryTmp.FieldByName('REB14').AsFloat; //本次开票金额
QryDetail.FieldByName('REB15').AsFloat := 0.0; //已开票金额
QryDetail.FieldByName('REB16').AsString := QryTmp.FieldByName('RAB15').AsString; //客户单号
QryDetail.FieldByName('REB17').AsString := QryTmp.FieldByName('RAB14').AsString; //快捷码
QryDetail.FieldByName('REB18').AsFloat := QryTmp.FieldByName('RAB08').AsFloat-QryTmp.FieldByName('RAB31').AsFloat; //本次开票数量
QryDetail.FieldByName('REB19').AsFloat :=0.0; //已开票数量
QryDetail.FieldByName('REB20').AsString := '传感器'; //货物或应带劳务名称
QryDetail.FieldByName('REB21').AsFloat := QryTmp.FieldByName('REB14').AsFloat; //应开票金额
QryDetail.FieldByName('REB22').AsString := ''; //对帐单号
QryDetail.FieldByName('REB23').AsString := ''; //对帐序号
QryDetail.FieldByName('REB24').AsDateTime := QryTmp.FieldByName('RAA05').AsDateTime; //销退货日期
QryDetail.FieldByName('REB25').AsString := QryTmp.FieldByName('RAB11').AsString; //订单单号
QryDetail.FieldByName('REB26').AsString := QryTmp.FieldByName('RAB32').AsString; //送货单号
QryDetail.FieldByName('REB27').AsString := QryTmp.FieldByName('RAB13').AsString; //客户品号
end;
finally
QryTmp.Close;
QryTmp.Free;
end;
end
else
begin
QryDetail.Append;
try
QryTmp:=TADOQuery.Create(nil);
QryTmp.Connection:=dlladocn;
QryTmp.EnableBCD :=False;
QryTmp.Close;
QryTmp.SQL.Clear;
QryTmp.SQL.Add(' SELECT ''3'' AS BZ,RJB06 AS RAA05,RJB10 AS RAB15,RJB12 AS RAB14,RJB01+''-''+RJB02 AS RAB03,'''' AS RAB04,RJB03 AS RAB05,RJB16 AS RAB06,RJB14 AS RAB09, '+
' RJB15 AS RAB10,RJB13 AS RAB08,''N'' AS RAB29,RJB05 AS RAB28,'''' AS RAB11,'+
' RGA07,RGA28,RGA23,0.0 AS RAB31,'''' AS RAB32,RJB11 AS RAB13, '+
' ISNULL(RJB04,0.0)-ISNULL(RJB08,0.0)-ISNULL(RJB18,0.0) AS REB14 '+
' FROM ACRJA '+
' INNER JOIN ACRJB ON ACRJA.RJA01=ACRJB.RJB01 '+
' LEFT JOIN ACRGA ON ACRGA.RGA01=ACRJA.RJA06 '+
' WHERE ACRJA.CONFORM_CODE=''Y'' AND ISNULL(ACRGA.RGA25,'''')<>''Y'' AND ACRJB.RJB01+''-''+ACRJB.RJB02='+VarToSql(Trim(sl.Strings[i-1])));
QryTmp.Open;
if QryTmp.RecordCount >0 Then
begin
QryDetail.Edit;
QryDetail.FieldByName('REB03').AsString := '3'; //来源
QryDetail.FieldByName('REB04').AsString := ''; //来源单别
QryDetail.FieldByName('REB05').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),1,11); //来源单号
QryDetail.FieldByName('REB06').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),13,4); //来源序号
QryDetail.FieldByName('REB07').AsString := QryTmp.FieldByName('RAB04').AsString; //品号
QryDetail.FieldByName('REB08').AsString := QryTmp.FieldByName('RAB05').AsString; //品名
QryDetail.FieldByName('REB09').AsString := QryTmp.FieldByName('RAB06').AsString; //规格
QryDetail.FieldByName('REB10').AsString := QryTmp.FieldByName('RAB09').AsString; //单位
QryDetail.FieldByName('REB11').AsFloat := QryTmp.FieldByName('RAB08').AsFloat-QryTmp.FieldByName('RAB31').AsFloat; //数量
QryDetail.FieldByName('REB12').AsFloat := QryTmp.FieldByName('RAB10').AsFloat; //单价
QryDetail.FieldByName('REB13').AsString := ''; //备注
QryDetail.FieldByName('REB14').AsFloat := QryTmp.FieldByName('REB14').AsFloat; //本次开票金额
QryDetail.FieldByName('REB15').AsFloat := 0.0; //已开票金额
QryDetail.FieldByName('REB16').AsString := QryTmp.FieldByName('RAB15').AsString; //客户单号
QryDetail.FieldByName('REB17').AsString := QryTmp.FieldByName('RAB14').AsString; //快捷码
QryDetail.FieldByName('REB18').AsFloat := QryTmp.FieldByName('RAB08').AsFloat-QryTmp.FieldByName('RAB31').AsFloat; //本次开票数量
QryDetail.FieldByName('REB19').AsFloat :=0.0; //已开票数量
QryDetail.FieldByName('REB20').AsString := '传感器'; //货物或应带劳务名称
QryDetail.FieldByName('REB21').AsFloat := QryTmp.FieldByName('REB14').AsFloat; //应开票金额
QryDetail.FieldByName('REB22').AsString := ''; //对帐单号
QryDetail.FieldByName('REB23').AsString := ''; //对帐序号
QryDetail.FieldByName('REB24').AsDateTime := QryTmp.FieldByName('RAA05').AsDateTime; //销退货日期
QryDetail.FieldByName('REB25').AsString := QryTmp.FieldByName('RAB11').AsString; //订单单号
QryDetail.FieldByName('REB26').AsString := QryTmp.FieldByName('RAB32').AsString; //送货单号
QryDetail.FieldByName('REB27').AsString := QryTmp.FieldByName('RAB13').AsString; //客户品号
end;
finally
QryTmp.Close;
QryTmp.Free;
end;
end;
end;
end;
end;
end;
if Key = VK_F7 then //其它销货
begin
if not Assigned(frmACRACDHELP) then
begin
frmACRACDHELP := TfrmACRACDHELP.Create(Application);
frmACRACDHELP.sWhere :=' RAC06='+VarToSql(Trim(wwDBEdit2.Text))+' AND ISNULL(ACRAD.RAD39,'''')<>''Y'' AND ISNULL(ACRGA.RGA25,'''')<>''Y'' AND ACRAC.CONFORM_CODE=''Y'' AND ISNULL(RAD30,0.0)-ISNULL(RAD34,0.0)-ISNULL(RAD38,0.0)>0 AND ISNULL(RAD30,0.0)-ISNULL(RAD33,0.0)-ISNULL(RAD37,0.0)>0 ';
frmACRACDHELP.ShowModal;
sResult:=frmACRACDHELP.rtnHelpFieldName;
frmACRACDHELP.Free;
end;
if sResult<>'' Then
begin
sl:=TStringList.Create;
sl.Delimiter :=';';
sl.DelimitedText := Trim(sResult);
if sl.Count=1 then
begin
try
QryTmp:=TADOQuery.Create(nil);
QryTmp.Connection:=dlladocn;
QryTmp.EnableBCD :=False;
QryTmp.Close;
QryTmp.SQL.Clear;
QryTmp.SQL.Add(' SELECT ''5'' AS BZ,RAC05 AS RAA05,RAD15 AS RAB15,RAD14 AS RAB14,RAD01+''-''+RAD02 AS RAB03,RAD04 AS RAB04,RAD05 AS RAB05,RAD06 AS RAB06,RAD09 AS RAB09, '+
' RAD10 AS RAB10,RAD08 AS RAB08,RAD29 AS RAB29,RAD28 AS RAB28,'''' AS RAB11,RGA07,RGA28,RGA23,RAD31 AS RAB31,'''' AS RAB32,'+
' RAD13 AS RAB13,RAD30 AS RAB30,RAD34 AS RAB34,RAD38 AS RAB38 '+
' FROM ACRAC '+
' INNER JOIN ACRAD ON ACRAC.RAC01=ACRAD.RAD01 '+
' LEFT JOIN ACRGA ON ACRGA.RGA01=ACRAC.RAC06 '+
' WHERE ACRAC.CONFORM_CODE=''Y'' AND ISNULL(ACRGA.RGA25,'''')<>''Y'' AND ACRAD.RAD01+''-''+ACRAD.RAD02='+VarToSql(Trim(sl.Strings[0])));
QryTmp.Open;
if QryTmp.RecordCount >0 Then
begin
QryDetail.Edit;
QryDetail.FieldByName('REB03').AsString := '5'; //来源
QryDetail.FieldByName('REB04').AsString := ''; //来源单别
QryDetail.FieldByName('REB05').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),1,11); //来源单号
QryDetail.FieldByName('REB06').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),13,4); //来源序号
QryDetail.FieldByName('REB07').AsString := QryTmp.FieldByName('RAB04').AsString; //品号
QryDetail.FieldByName('REB08').AsString := QryTmp.FieldByName('RAB05').AsString; //品名
QryDetail.FieldByName('REB09').AsString := QryTmp.FieldByName('RAB06').AsString; //规格
QryDetail.FieldByName('REB10').AsString := QryTmp.FieldByName('RAB09').AsString; //单位
QryDetail.FieldByName('REB11').AsFloat := QryTmp.FieldByName('RAB08').AsFloat-QryTmp.FieldByName('RAB31').AsFloat; //数量
QryDetail.FieldByName('REB12').AsFloat := QryTmp.FieldByName('RAB10').AsFloat; //单价
QryDetail.FieldByName('REB13').AsString := ''; //备注
QryDetail.FieldByName('REB14').AsFloat := QryTmp.FieldByName('RAB30').AsFloat-QryTmp.FieldByName('RAB34').AsFloat-QryTmp.FieldByName('RAB38').AsFloat; //本次开票金额=金额-已开票-转应开票
QryDetail.FieldByName('REB15').AsFloat := 0.0; //已开票金额
QryDetail.FieldByName('REB16').AsString := QryTmp.FieldByName('RAB15').AsString; //客户单号
QryDetail.FieldByName('REB17').AsString := QryTmp.FieldByName('RAB14').AsString; //快捷码
QryDetail.FieldByName('REB18').AsFloat := QryTmp.FieldByName('RAB08').AsFloat-QryTmp.FieldByName('RAB31').AsFloat; //本次开票数量
QryDetail.FieldByName('REB19').AsFloat :=0.0; //已开票数量
QryDetail.FieldByName('REB20').AsString := '传感器'; //货物或应带劳务名称
QryDetail.FieldByName('REB21').AsFloat := QryTmp.FieldByName('RAB30').AsFloat-QryTmp.FieldByName('RAB34').AsFloat-QryTmp.FieldByName('RAB38').AsFloat; //应开票金额=金额-已开票-转应开票
QryDetail.FieldByName('REB22').AsString := ''; //对帐单号
QryDetail.FieldByName('REB23').AsString := ''; //对帐序号
QryDetail.FieldByName('REB24').AsDateTime := QryTmp.FieldByName('RAA05').AsDateTime; //销退货日期
QryDetail.FieldByName('REB25').AsString := QryTmp.FieldByName('RAB11').AsString; //订单单号
QryDetail.FieldByName('REB26').AsString := QryTmp.FieldByName('RAB32').AsString; //送货单号
QryDetail.FieldByName('REB27').AsString := QryTmp.FieldByName('RAB13').AsString; //客户品号
end;
finally
QryTmp.Close;
QryTmp.Free;
end;
end
else
begin
for i:=1 to sl.Count-1 do
begin
if i=1 then
begin
try
QryTmp:=TADOQuery.Create(nil);
QryTmp.Connection:=dlladocn;
QryTmp.EnableBCD :=False;
QryTmp.Close;
QryTmp.SQL.Clear;
QryTmp.SQL.Add(' SELECT ''5'' AS BZ,RAC05 AS RAA05,RAD15 AS RAB15,RAD14 AS RAB14,RAD01+''-''+RAD02 AS RAB03,RAD04 AS RAB04,RAD05 AS RAB05,RAD06 AS RAB06,RAD09 AS RAB09, '+
' RAD10 AS RAB10,RAD08 AS RAB08,RAD29 AS RAB29,RAD28 AS RAB28,'''' AS RAB11,RGA07,RGA28,RGA23,RAD31 AS RAB31,'''' AS RAB32,'+
' RAD13 AS RAB13,RAD30 AS RAB30,RAD34 AS RAB34,RAD38 AS RAB38 '+
' FROM ACRAC '+
' INNER JOIN ACRAD ON ACRAC.RAC01=ACRAD.RAD01 '+
' LEFT JOIN ACRGA ON ACRGA.RGA01=ACRAC.RAC06 '+
' WHERE ACRAC.CONFORM_CODE=''Y'' AND ISNULL(ACRGA.RGA25,'''')<>''Y'' AND ACRAD.RAD01+''-''+ACRAD.RAD02='+VarToSql(Trim(sl.Strings[0])));
QryTmp.Open;
if QryTmp.RecordCount >0 Then
begin
QryDetail.Edit;
QryDetail.FieldByName('REB03').AsString := '5'; //来源
QryDetail.FieldByName('REB04').AsString := ''; //来源单别
QryDetail.FieldByName('REB05').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),1,11); //来源单号
QryDetail.FieldByName('REB06').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),13,4); //来源序号
QryDetail.FieldByName('REB07').AsString := QryTmp.FieldByName('RAB04').AsString; //品号
QryDetail.FieldByName('REB08').AsString := QryTmp.FieldByName('RAB05').AsString; //品名
QryDetail.FieldByName('REB09').AsString := QryTmp.FieldByName('RAB06').AsString; //规格
QryDetail.FieldByName('REB10').AsString := QryTmp.FieldByName('RAB09').AsString; //单位
QryDetail.FieldByName('REB11').AsFloat := QryTmp.FieldByName('RAB08').AsFloat-QryTmp.FieldByName('RAB31').AsFloat; //数量
QryDetail.FieldByName('REB12').AsFloat := QryTmp.FieldByName('RAB10').AsFloat; //单价
QryDetail.FieldByName('REB13').AsString := ''; //备注
QryDetail.FieldByName('REB14').AsFloat := QryTmp.FieldByName('RAB30').AsFloat-QryTmp.FieldByName('RAB34').AsFloat-QryTmp.FieldByName('RAB38').AsFloat; //本次开票金额=金额-已开票-转应开票
QryDetail.FieldByName('REB15').AsFloat := 0.0; //已开票金额
QryDetail.FieldByName('REB16').AsString := QryTmp.FieldByName('RAB15').AsString; //客户单号
QryDetail.FieldByName('REB17').AsString := QryTmp.FieldByName('RAB14').AsString; //快捷码
QryDetail.FieldByName('REB18').AsFloat := QryTmp.FieldByName('RAB08').AsFloat-QryTmp.FieldByName('RAB31').AsFloat; //本次开票数量
QryDetail.FieldByName('REB19').AsFloat :=0.0; //已开票数量
QryDetail.FieldByName('REB20').AsString := '传感器'; //货物或应带劳务名称
QryDetail.FieldByName('REB21').AsFloat := QryTmp.FieldByName('RAB30').AsFloat-QryTmp.FieldByName('RAB34').AsFloat-QryTmp.FieldByName('RAB38').AsFloat; //应开票金额=金额-已开票-转应开票
QryDetail.FieldByName('REB22').AsString := ''; //对帐单号
QryDetail.FieldByName('REB23').AsString := ''; //对帐序号
QryDetail.FieldByName('REB24').AsDateTime := QryTmp.FieldByName('RAA05').AsDateTime; //销退货日期
QryDetail.FieldByName('REB25').AsString := QryTmp.FieldByName('RAB11').AsString; //订单单号
QryDetail.FieldByName('REB26').AsString := QryTmp.FieldByName('RAB32').AsString; //送货单号
QryDetail.FieldByName('REB27').AsString := QryTmp.FieldByName('RAB13').AsString; //客户品号
end;
finally
QryTmp.Close;
QryTmp.Free;
end;
end
else
begin
QryDetail.Append;
try
QryTmp:=TADOQuery.Create(nil);
QryTmp.Connection:=dlladocn;
QryTmp.EnableBCD :=False;
QryTmp.Close;
QryTmp.SQL.Clear;
QryTmp.SQL.Add(' SELECT ''5'' AS BZ,RAC05 AS RAA05,RAD15 AS RAB15,RAD14 AS RAB14,RAD01+''-''+RAD02 AS RAB03,RAD04 AS RAB04,RAD05 AS RAB05,RAD06 AS RAB06,RAD09 AS RAB09, '+
' RAD10 AS RAB10,RAD08 AS RAB08,RAD29 AS RAB29,RAD28 AS RAB28,'''' AS RAB11,RGA07,RGA28,RGA23,RAD31 AS RAB31,'''' AS RAB32,'+
' RAD13 AS RAB13,RAD30 AS RAB30,RAD34 AS RAB34,RAD38 AS RAB38 '+
' FROM ACRAC '+
' INNER JOIN ACRAD ON ACRAC.RAC01=ACRAD.RAD01 '+
' LEFT JOIN ACRGA ON ACRGA.RGA01=ACRAC.RAC06 '+
' WHERE ACRAC.CONFORM_CODE=''Y'' AND ISNULL(ACRGA.RGA25,'''')<>''Y'' AND ACRAD.RAD01+''-''+ACRAD.RAD02='+VarToSql(Trim(sl.Strings[I-1])));
QryTmp.Open;
if QryTmp.RecordCount >0 Then
begin
QryDetail.Edit;
QryDetail.FieldByName('REB03').AsString := '5'; //来源
QryDetail.FieldByName('REB04').AsString := ''; //来源单别
QryDetail.FieldByName('REB05').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),1,11); //来源单号
QryDetail.FieldByName('REB06').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),13,4); //来源序号
QryDetail.FieldByName('REB07').AsString := QryTmp.FieldByName('RAB04').AsString; //品号
QryDetail.FieldByName('REB08').AsString := QryTmp.FieldByName('RAB05').AsString; //品名
QryDetail.FieldByName('REB09').AsString := QryTmp.FieldByName('RAB06').AsString; //规格
QryDetail.FieldByName('REB10').AsString := QryTmp.FieldByName('RAB09').AsString; //单位
QryDetail.FieldByName('REB11').AsFloat := QryTmp.FieldByName('RAB08').AsFloat-QryTmp.FieldByName('RAB31').AsFloat; //数量
QryDetail.FieldByName('REB12').AsFloat := QryTmp.FieldByName('RAB10').AsFloat; //单价
QryDetail.FieldByName('REB13').AsString := ''; //备注
QryDetail.FieldByName('REB14').AsFloat := QryTmp.FieldByName('RAB30').AsFloat-QryTmp.FieldByName('RAB34').AsFloat-QryTmp.FieldByName('RAB38').AsFloat; //本次开票金额=金额-已开票-转应开票
QryDetail.FieldByName('REB15').AsFloat := 0.0; //已开票金额
QryDetail.FieldByName('REB16').AsString := QryTmp.FieldByName('RAB15').AsString; //客户单号
QryDetail.FieldByName('REB17').AsString := QryTmp.FieldByName('RAB14').AsString; //快捷码
QryDetail.FieldByName('REB18').AsFloat := QryTmp.FieldByName('RAB08').AsFloat-QryTmp.FieldByName('RAB31').AsFloat; //本次开票数量
QryDetail.FieldByName('REB19').AsFloat :=0.0; //已开票数量
QryDetail.FieldByName('REB20').AsString := '传感器'; //货物或应带劳务名称
QryDetail.FieldByName('REB21').AsFloat := QryTmp.FieldByName('RAB30').AsFloat-QryTmp.FieldByName('RAB34').AsFloat-QryTmp.FieldByName('RAB38').AsFloat; //应开票金额=金额-已开票-转应开票
QryDetail.FieldByName('REB22').AsString := ''; //对帐单号
QryDetail.FieldByName('REB23').AsString := ''; //对帐序号
QryDetail.FieldByName('REB24').AsDateTime := QryTmp.FieldByName('RAA05').AsDateTime; //销退货日期
QryDetail.FieldByName('REB25').AsString := QryTmp.FieldByName('RAB11').AsString; //订单单号
QryDetail.FieldByName('REB26').AsString := QryTmp.FieldByName('RAB32').AsString; //送货单号
QryDetail.FieldByName('REB27').AsString := QryTmp.FieldByName('RAB13').AsString; //客户品号
end;
finally
QryTmp.Close;
QryTmp.Free;
end;
end;
end;
end;
end;
end;
if Key = VK_F8 then //销货折让
begin
if not Assigned(frmACRAEFHELP) then
begin
frmACRAEFHELP := TfrmACRAEFHELP.Create(Application);
frmACRAEFHELP.sWhere :=' RAE06='+VarToSql(Trim(wwDBEdit2.Text))+' AND ISNULL(ACRAF.RAF40,'''')<>''Y'' AND ISNULL(ACRGA.RGA25,'''')<>''Y'' AND ACRAE.CONFORM_CODE=''Y'' AND ISNULL(RAF30,0.0)-ISNULL(RAF34,0.0)-ISNULL(RAF39,0.0)>0 AND ISNULL(RAF30,0.0)-ISNULL(RAF33,0.0)-ISNULL(RAF37,0.0)>0 ';
frmACRAEFHELP.ShowModal;
sResult:=frmACRAEFHELP.rtnHelpFieldName;
frmACRAEFHELP.Free;
end;
if sResult<>'' Then
begin
sl:=TStringList.Create;
sl.Delimiter :=';';
sl.DelimitedText := Trim(sResult);
if sl.Count=1 then
begin
try
QryTmp:=TADOQuery.Create(nil);
QryTmp.Connection:=dlladocn;
QryTmp.EnableBCD :=False;
QryTmp.Close;
QryTmp.SQL.Clear;
QryTmp.SQL.Add(' SELECT ''6'' AS BZ,RAF38 AS RAA05,RAF15 AS RAB15,RAF14 AS RAB14,RAF01+''-''+RAF02 AS RAB03,RAF04 AS RAB04,RAF05 AS RAB05,RAF06 AS RAB06,RAF09 AS RAB09, '+
' RAF10 AS RAB10,RAF08 AS RAB08,RAF29 AS RAB29,RAF28 AS RAB28,'''' AS RAB11,RGA07,RGA28,RGA23,RAF31 AS RAB31,'''' AS RAB32,'+
' RAF13 AS RAB13,RAF30 AS RAB30,RAF34 AS RAB34,RAF39 AS RAB38 '+
' FROM ACRAE '+
' INNER JOIN ACRAF ON ACRAE.RAE01=ACRAF.RAF01 '+
' LEFT JOIN ACRGA ON ACRGA.RGA01=ACRAE.RAE06 '+
' WHERE ACRAE.CONFORM_CODE=''Y'' AND ISNULL(ACRGA.RGA25,'''')<>''Y'' AND ACRAF.RAF01+''-''+ACRAF.RAF02='+VarToSql(Trim(sl.Strings[0])));
QryTmp.Open;
if QryTmp.RecordCount >0 Then
begin
QryDetail.Edit;
QryDetail.FieldByName('REB03').AsString := '6'; //来源
QryDetail.FieldByName('REB04').AsString := ''; //来源单别
QryDetail.FieldByName('REB05').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),1,11); //来源单号
QryDetail.FieldByName('REB06').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),13,4); //来源序号
QryDetail.FieldByName('REB07').AsString := QryTmp.FieldByName('RAB04').AsString; //品号
QryDetail.FieldByName('REB08').AsString := QryTmp.FieldByName('RAB05').AsString; //品名
QryDetail.FieldByName('REB09').AsString := QryTmp.FieldByName('RAB06').AsString; //规格
QryDetail.FieldByName('REB10').AsString := QryTmp.FieldByName('RAB09').AsString; //单位
QryDetail.FieldByName('REB11').AsFloat := QryTmp.FieldByName('RAB08').AsFloat-QryTmp.FieldByName('RAB31').AsFloat; //数量
QryDetail.FieldByName('REB12').AsFloat := QryTmp.FieldByName('RAB10').AsFloat; //单价
QryDetail.FieldByName('REB13').AsString := ''; //备注
QryDetail.FieldByName('REB14').AsFloat := (-1)*(QryTmp.FieldByName('RAB30').AsFloat-QryTmp.FieldByName('RAB34').AsFloat-QryTmp.FieldByName('RAB38').AsFloat); //本次开票金额=金额-已开票-已转应开票
QryDetail.FieldByName('REB15').AsFloat := 0.0; //已开票金额
QryDetail.FieldByName('REB16').AsString := QryTmp.FieldByName('RAB15').AsString; //客户单号
QryDetail.FieldByName('REB17').AsString := QryTmp.FieldByName('RAB14').AsString; //快捷码
QryDetail.FieldByName('REB18').AsFloat := QryTmp.FieldByName('RAB08').AsFloat-QryTmp.FieldByName('RAB31').AsFloat; //本次开票数量
QryDetail.FieldByName('REB19').AsFloat :=0.0; //已开票数量
QryDetail.FieldByName('REB20').AsString := '传感器'; //货物或应带劳务名称
QryDetail.FieldByName('REB21').AsFloat := (-1)*(QryTmp.FieldByName('RAB30').AsFloat-QryTmp.FieldByName('RAB34').AsFloat-QryTmp.FieldByName('RAB38').AsFloat); //应开票金额=金额-已开票-已转应开票
QryDetail.FieldByName('REB22').AsString := ''; //对帐单号
QryDetail.FieldByName('REB23').AsString := ''; //对帐序号
QryDetail.FieldByName('REB24').AsDateTime := QryTmp.FieldByName('RAA05').AsDateTime; //销退货日期
QryDetail.FieldByName('REB25').AsString := QryTmp.FieldByName('RAB11').AsString; //订单单号
QryDetail.FieldByName('REB26').AsString := QryTmp.FieldByName('RAB32').AsString; //送货单号
QryDetail.FieldByName('REB27').AsString := QryTmp.FieldByName('RAB13').AsString; //客户品号
end;
finally
QryTmp.Close;
QryTmp.Free;
end;
end
else
begin
for i:=1 to sl.Count-1 do
begin
if i=1 then
begin
try
QryTmp:=TADOQuery.Create(nil);
QryTmp.Connection:=dlladocn;
QryTmp.EnableBCD :=False;
QryTmp.Close;
QryTmp.SQL.Clear;
QryTmp.SQL.Add(' SELECT ''6'' AS BZ,RAF38 AS RAA05,RAF15 AS RAB15,RAF14 AS RAB14,RAF01+''-''+RAF02 AS RAB03,RAF04 AS RAB04,RAF05 AS RAB05,RAF06 AS RAB06,RAF09 AS RAB09, '+
' RAF10 AS RAB10,RAF08 AS RAB08,RAF29 AS RAB29,RAF28 AS RAB28,'''' AS RAB11,RGA07,RGA28,RGA23,RAF31 AS RAB31,'''' AS RAB32,'+
' RAF13 AS RAB13,RAF30 AS RAB30,RAF34 AS RAB34,RAF39 AS RAB38 '+
' FROM ACRAE '+
' INNER JOIN ACRAF ON ACRAE.RAE01=ACRAF.RAF01 '+
' LEFT JOIN ACRGA ON ACRGA.RGA01=ACRAE.RAE06 '+
' WHERE ACRAE.CONFORM_CODE=''Y'' AND ISNULL(ACRGA.RGA25,'''')<>''Y'' AND ACRAF.RAF01+''-''+ACRAF.RAF02='+VarToSql(Trim(sl.Strings[0])));
QryTmp.Open;
if QryTmp.RecordCount >0 Then
begin
QryDetail.Edit;
QryDetail.FieldByName('REB03').AsString := '6'; //来源
QryDetail.FieldByName('REB04').AsString := ''; //来源单别
QryDetail.FieldByName('REB05').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),1,11); //来源单号
QryDetail.FieldByName('REB06').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),13,4); //来源序号
QryDetail.FieldByName('REB07').AsString := QryTmp.FieldByName('RAB04').AsString; //品号
QryDetail.FieldByName('REB08').AsString := QryTmp.FieldByName('RAB05').AsString; //品名
QryDetail.FieldByName('REB09').AsString := QryTmp.FieldByName('RAB06').AsString; //规格
QryDetail.FieldByName('REB10').AsString := QryTmp.FieldByName('RAB09').AsString; //单位
QryDetail.FieldByName('REB11').AsFloat := QryTmp.FieldByName('RAB08').AsFloat-QryTmp.FieldByName('RAB31').AsFloat; //数量
QryDetail.FieldByName('REB12').AsFloat := QryTmp.FieldByName('RAB10').AsFloat; //单价
QryDetail.FieldByName('REB13').AsString := ''; //备注
QryDetail.FieldByName('REB14').AsFloat := (-1)*(QryTmp.FieldByName('RAB30').AsFloat-QryTmp.FieldByName('RAB34').AsFloat-QryTmp.FieldByName('RAB38').AsFloat); //本次开票金额=金额-已开票-已转应开票
QryDetail.FieldByName('REB15').AsFloat := 0.0; //已开票金额
QryDetail.FieldByName('REB16').AsString := QryTmp.FieldByName('RAB15').AsString; //客户单号
QryDetail.FieldByName('REB17').AsString := QryTmp.FieldByName('RAB14').AsString; //快捷码
QryDetail.FieldByName('REB18').AsFloat := QryTmp.FieldByName('RAB08').AsFloat-QryTmp.FieldByName('RAB31').AsFloat; //本次开票数量
QryDetail.FieldByName('REB19').AsFloat :=0.0; //已开票数量
QryDetail.FieldByName('REB20').AsString := '传感器'; //货物或应带劳务名称
QryDetail.FieldByName('REB21').AsFloat := (-1)*(QryTmp.FieldByName('RAB30').AsFloat-QryTmp.FieldByName('RAB34').AsFloat-QryTmp.FieldByName('RAB38').AsFloat); //应开票金额=金额-已开票-已转应开票
QryDetail.FieldByName('REB22').AsString := ''; //对帐单号
QryDetail.FieldByName('REB23').AsString := ''; //对帐序号
QryDetail.FieldByName('REB24').AsDateTime := QryTmp.FieldByName('RAA05').AsDateTime; //销退货日期
QryDetail.FieldByName('REB25').AsString := QryTmp.FieldByName('RAB11').AsString; //订单单号
QryDetail.FieldByName('REB26').AsString := QryTmp.FieldByName('RAB32').AsString; //送货单号
QryDetail.FieldByName('REB27').AsString := QryTmp.FieldByName('RAB13').AsString; //客户品号
end;
finally
QryTmp.Close;
QryTmp.Free;
end;
end
else
begin
QryDetail.Append;
try
QryTmp:=TADOQuery.Create(nil);
QryTmp.Connection:=dlladocn;
QryTmp.EnableBCD :=False;
QryTmp.Close;
QryTmp.SQL.Clear;
QryTmp.SQL.Add(' SELECT ''6'' AS BZ,RAF38 AS RAA05,RAF15 AS RAB15,RAF14 AS RAB14,RAF01+''-''+RAF02 AS RAB03,RAF04 AS RAB04,RAF05 AS RAB05,RAF06 AS RAB06,RAF09 AS RAB09, '+
' RAF10 AS RAB10,RAF08 AS RAB08,RAF29 AS RAB29,RAF28 AS RAB28,'''' AS RAB11,RGA07,RGA28,RGA23,RAF31 AS RAB31,'''' AS RAB32,'+
' RAF13 AS RAB13,RAF30 AS RAB30,RAF34 AS RAB34,RAF39 AS RAB38 '+
' FROM ACRAE '+
' INNER JOIN ACRAF ON ACRAE.RAE01=ACRAF.RAF01 '+
' LEFT JOIN ACRGA ON ACRGA.RGA01=ACRAE.RAE06 '+
' WHERE ACRAE.CONFORM_CODE=''Y'' AND ISNULL(ACRGA.RGA25,'''')<>''Y'' AND ACRAF.RAF01+''-''+ACRAF.RAF02='+VarToSql(Trim(sl.Strings[i-1])));
QryTmp.Open;
if QryTmp.RecordCount >0 Then
begin
QryDetail.Edit;
QryDetail.FieldByName('REB03').AsString := '6'; //来源
QryDetail.FieldByName('REB04').AsString := ''; //来源单别
QryDetail.FieldByName('REB05').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),1,11); //来源单号
QryDetail.FieldByName('REB06').AsString := COPY(Trim(QryTmp.FieldByName('RAB03').AsString),13,4); //来源序号
QryDetail.FieldByName('REB07').AsString := QryTmp.FieldByName('RAB04').AsString; //品号
QryDetail.FieldByName('REB08').AsString := QryTmp.FieldByName('RAB05').AsString; //品名
QryDetail.FieldByName('REB09').AsString := QryTmp.FieldByName('RAB06').AsString; //规格
QryDetail.FieldByName('REB10').AsString := QryTmp.FieldByName('RAB09').AsString; //单位
QryDetail.FieldByName('REB11').AsFloat := QryTmp.FieldByName('RAB08').AsFloat-QryTmp.FieldByName('RAB31').AsFloat; //数量
QryDetail.FieldByName('REB12').AsFloat := QryTmp.FieldByName('RAB10').AsFloat; //单价
QryDetail.FieldByName('REB13').AsString := ''; //备注
QryDetail.FieldByName('REB14').AsFloat := (-1)*(QryTmp.FieldByName('RAB30').AsFloat-QryTmp.FieldByName('RAB34').AsFloat-QryTmp.FieldByName('RAB38').AsFloat); //本次开票金额=金额-已开票-已转应开票
QryDetail.FieldByName('REB15').AsFloat := 0.0; //已开票金额
QryDetail.FieldByName('REB16').AsString := QryTmp.FieldByName('RAB15').AsString; //客户单号
QryDetail.FieldByName('REB17').AsString := QryTmp.FieldByName('RAB14').AsString; //快捷码
QryDetail.FieldByName('REB18').AsFloat := QryTmp.FieldByName('RAB08').AsFloat-QryTmp.FieldByName('RAB31').AsFloat; //本次开票数量
QryDetail.FieldByName('REB19').AsFloat :=0.0; //已开票数量
QryDetail.FieldByName('REB20').AsString := '传感器'; //货物或应带劳务名称
QryDetail.FieldByName('REB21').AsFloat := (-1)*(QryTmp.FieldByName('RAB30').AsFloat-QryTmp.FieldByName('RAB34').AsFloat-QryTmp.FieldByName('RAB38').AsFloat); //应开票金额=金额-已开票-已转应开票
QryDetail.FieldByName('REB22').AsString := ''; //对帐单号
QryDetail.FieldByName('REB23').AsString := ''; //对帐序号
QryDetail.FieldByName('REB24').AsDateTime := QryTmp.FieldByName('RAA05').AsDateTime; //销退货日期
QryDetail.FieldByName('REB25').AsString := QryTmp.FieldByName('RAB11').AsString; //订单单号
QryDetail.FieldByName('REB26').AsString := QryTmp.FieldByName('RAB32').AsString; //送货单号
QryDetail.FieldByName('REB27').AsString := QryTmp.FieldByName('RAB13').AsString; //客户品号
end;
finally
QryTmp.Close;
QryTmp.Free;
end;
end;
end;
end;
end;
end;
end;
end;
initialization
RegisterClass(TfrmACREABD);
finalization
UnRegisterClass(TfrmACREABD);
end.