You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

250 lines
9.6 KiB
Plaintext

unit u_ch_invoice_inv_do;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, BusinessSkinForm, bsSkinCtrls, StdCtrls, RxLookup,ADODB,
wwdbdatetimepicker;
type
Tfrm_ch_invoice_inv_do = class(TForm)
bsSkinGroupBox1: TbsSkinGroupBox;
bsSkinButton1: TbsSkinButton;
bsSkinButton2: TbsSkinButton;
bsBusinessSkinForm1: TbsBusinessSkinForm;
Label25: TLabel;
Label18: TLabel;
Edit1: TEdit;
Edit2: TEdit;
wwDBDateTimePicker17: TwwDBDateTimePicker;
Label76: TLabel;
procedure bsSkinButton2Click(Sender: TObject);
procedure bsSkinButton1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frm_ch_invoice_inv_do: Tfrm_ch_invoice_inv_do;
implementation
uses u_ch_balance_accept, my_sys_function, u_main, u_sys_progress,
u_data_share, u_ch_invoice;
{$R *.dfm}
procedure Tfrm_ch_invoice_inv_do.bsSkinButton2Click(Sender: TObject);
begin
close;
end;
procedure Tfrm_ch_invoice_inv_do.bsSkinButton1Click(Sender: TObject);
var
aQuery,t_ch_pay,t_ch_fee,p_accmonth,aQueryBalance:TADOQuery;
ttamount,exchange,rate,Oamount,damount:Double;
reccount,selcount:Integer;
SL:TStringList;
begin
ttamount:=StrToFloat(Edit1.Text);
exchange:=StrToFloat(Edit2.Text);
SL:=TStringList.Create;
if (Edit1.Text='') then begin
ShowMessage('开票金额不能为空!');
exit;
end;
if (Edit2.Text='') then begin
ShowMessage('开票汇率不能为空!');
exit;
end;
if frm_ch_invoice.t_ch_invoice.IsEmpty then begin
Showmessage('没有发票数据');
exit;
end;
aQuery:=CreateAdoQuery;
t_ch_pay:=CreateAdoQuery;
t_ch_fee:=CreateAdoQuery;
p_accmonth:=CreateAdoQuery;
aQueryBalance:= CreateAdoQuery;
try
with aQuery do begin
close;sql.Clear;
SQL.Add('select * from v_fee_do_seae where 工作编号='''+frm_ch_invoice.t_ch_invoice['申请编号']+''' ');
Open;
reccount:=FieldCount;
selcount:=0;
if not aQuery.IsEmpty then begin
t_ch_pay.Close;
t_ch_pay.SQL.Text:='select top 0 * from t_ch_fee';;
t_ch_pay.Open;
First;
while not Eof do begin
selcount:=selcount+1;
if FieldByName('原始币别').AsString='RMB' THEN begin
if (FieldByName('类型').AsString='付') then
ttamount:=ttamount+fieldbyname('原始金额').AsFloat
else
ttamount:=ttamount-fieldbyname('原始金额').AsFloat;
end else begin
if (exchange<>fieldbyname('原始汇率').AsFloat) then begin
Oamount:=StrToFloatDef(FormatFloat('0.00;-0.00;0.0',StrToFloat(FloatToStr((fieldbyname('原始金额').AsFloat*exchange)))), 0);
Damount:=StrToFloatDef(FormatFloat('0.00;-0.00;0.0',StrToFloat(FloatToStr((fieldbyname('原始金额').AsFloat*fieldbyname('原始汇率').AsFloat)))), 0);
SL.Add(FloatToStr(Oamount));
SL.Add(FloatToStr(Damount));
rate:=StrToFloatDef(FormatFloat('0.00;-0.00;0.0',StrToFloat(FloatToStr(Oamount-Damount))), 0);
if (FieldByName('类型').AsString='付') then
ttamount:=StrToFloatDef(FormatFloat('0.00;-0.00;0.0',StrToFloat(FloatToStr(ttamount+Oamount))), 0)
else
ttamount:=StrToFloatDef(FormatFloat('0.00;-0.00;0.0',StrToFloat(FloatToStr(ttamount-Oamount))), 0);
SL.Add(FloatToStr(rate));
SL.Add(FloatToStr(ttamount));
if (aQuery.eof) and (ttamount<>0.00) then begin
if (FieldByName('类型').AsString='付') then begin
rate:=rate-ttamount;
ttamount:=0;
end else begin
rate:=rate+ttamount;
ttamount:=0;
end;
end;
t_ch_fee.Close;
t_ch_fee.SQL.Text:='select * from t_ch_fee WHERE CH_ID='+Fieldbyname('CH_ID').AsString;
t_ch_fee.Open;
t_ch_pay.Insert;
t_ch_pay['编号']:=t_ch_fee.FieldByName('编号').AsString;
t_ch_pay['类型']:=Fieldbyname('类型').AsString;
t_ch_pay['费用状态']:='审核通过';
t_ch_pay['录入人']:=employee;
t_ch_pay['单价']:=rate;
t_ch_pay['数量']:=1;
t_ch_pay['金额']:=rate;
t_ch_pay['不含税金额']:=rate;
t_ch_pay['币别']:='RMB';
t_ch_pay['费用名称']:='汇兑损益';
t_ch_pay['标准']:='票';
t_ch_pay['客户名称']:='';
t_ch_pay['备注']:=t_ch_fee.Fieldbyname('客户名称').AsString;
t_ch_pay['结算单位']:='';
t_ch_pay.fieldbyname('币别').asstring:='RMB';
t_ch_pay['旧id']:=Fieldbyname('CH_ID').AsString;
t_ch_pay['汇率']:=1;
t_ch_pay['结算金额']:=0;
t_ch_pay['开票金额']:=0;
t_ch_pay['申请金额']:=0;
t_ch_pay['冲抵金额']:=0;
t_ch_pay['录入日期']:=now;
t_ch_pay['是否对帐']:=0;
t_ch_pay['系统费用']:=0;
t_ch_pay['税率']:=0;
t_ch_pay['税额']:=0;
t_ch_pay['不含税金额']:=0;
t_ch_pay['顺序']:=100;
t_ch_pay['机密']:=0;
t_ch_pay['会计月份']:=wwDBDateTimePicker17.Text;
t_ch_pay['不开发票']:=0;
t_ch_pay['提交日期']:=now;
t_ch_pay['审核人']:=employee;
t_ch_pay['审核日期']:=Now;
t_ch_pay.Post;
p_accmonth.Close;
p_accmonth.SQL.Text:='exec p_exec_accmonth '''+t_ch_fee.fieldbyname('编号').AsString+'''';
p_accmonth.ExecSQL;
end else begin
if (FieldByName('类型').AsString='付') then
ttamount:=ttamount+StrToFloatDef(FormatFloat('0.00;-0.00;0.0',StrToFloat(FloatToStr((fieldbyname('原始金额').AsFloat*fieldbyname('原始汇率').AsFloat)))), 0)
else
ttamount:=ttamount-(StrToFloatDef(FormatFloat('0.00;-0.00;0.0',StrToFloat(FloatToStr((fieldbyname('原始金额').AsFloat*fieldbyname('原始汇率').AsFloat)))), 0));
end;
end;
Next;
end;
// SL.SaveToFile('D:\HXT2.TXT');
if (ttamount<>0) then begin
if (not t_ch_pay.IsEmpty) then begin
end else begin
if (FieldByName('类型').AsString='付') then begin
rate:=-ttamount;
end else begin
rate:=ttamount;
end;
if (StrToFloatDef(FormatFloat('0.00;-0.00;0.0',StrToFloat(FloatToStr((rate)))), 0))<>0 then begin
t_ch_pay.Insert;
t_ch_pay['编号']:=FieldByName('编号').AsString;
t_ch_pay['类型']:=Fieldbyname('类型').AsString;
t_ch_pay['费用状态']:='审核通过';
t_ch_pay['录入人']:=employee;
t_ch_pay['单价']:=rate;
t_ch_pay['数量']:=1;
t_ch_pay['金额']:=rate;
t_ch_pay['不含税金额']:=rate;
t_ch_pay['币别']:='RMB';
t_ch_pay['费用名称']:='汇兑损益';
t_ch_pay['标准']:='票';
t_ch_pay['客户名称']:='';
t_ch_pay['结算单位']:='';
t_ch_pay['备注']:=frm_ch_invoice.t_ch_invoice.fieldbyname('客户名称').AsString;
t_ch_pay.fieldbyname('币别').asstring:='RMB';
t_ch_pay['旧id']:=Fieldbyname('CH_ID').AsString;
t_ch_pay['汇率']:=1;
t_ch_pay['结算金额']:=0;
t_ch_pay['开票金额']:=0;
t_ch_pay['申请金额']:=0;
t_ch_pay['冲抵金额']:=0;
t_ch_pay['录入日期']:=now;
t_ch_pay['是否对帐']:=0;
t_ch_pay['系统费用']:=0;
t_ch_pay['税率']:=0;
t_ch_pay['税额']:=0;
t_ch_pay['不含税金额']:=0;
t_ch_pay['顺序']:=100;
t_ch_pay['机密']:=0;
t_ch_pay['不开发票']:=0;
t_ch_pay['提交日期']:=now;
t_ch_pay['审核人']:=employee;
t_ch_pay['审核日期']:=Now;
t_ch_pay.Post;
if (FieldByName('类型').AsString='付') then
ttamount:=ttamount+StrToFloatDef(FormatFloat('0.00;-0.00;0.0',StrToFloat(FloatToStr((fieldbyname('原始金额').AsFloat*fieldbyname('原始汇率').AsFloat)))), 0)+rate
else
ttamount:=ttamount-(StrToFloatDef(FormatFloat('0.00;-0.00;0.0',StrToFloat(FloatToStr((fieldbyname('原始金额').AsFloat*fieldbyname('原始汇率').AsFloat)))), 0)+rate);
end;
end;
end
end;
end;
aQueryBalance.Close;
aQueryBalance.SQL.Text:='update t_ch_invoice set 开票金额='+edit1.text+',开票汇率='+edit2.text+' where 申请编号='''+frm_ch_invoice.t_ch_invoice['申请编号']+'''';
aQueryBalance.ExecSQL;
frm_ch_invoice.t_ch_invoice.Refresh;
finally
FreeAndNil(aQuery);
FreeAndNil(t_ch_pay);
FreeAndNil(t_ch_fee);
freeandnil(p_accmonth);
freeandnil(aQueryBalance);
FreeAndNil(SL);
end;
close;
end;
end.