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.

287 lines
10 KiB
Plaintext

unit u_ch_invoice_add;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, BusinessSkinForm, StdCtrls, wwdblook, RxLookup, bsSkinCtrls, DB,
ADODB;
type
Tfrm_ch_invoice_add = class(TForm)
bsBusinessSkinForm1: TbsBusinessSkinForm;
Label48: TLabel;
wwDBLookupCombo6: TwwDBLookupCombo;
Label63: TLabel;
RxDBLookupCombo3: TRxDBLookupCombo;
Label1: TLabel;
Edit1: TEdit;
bsSkinCheckRadioBox7: TbsSkinCheckRadioBox;
bsSkinCheckRadioBox8: TbsSkinCheckRadioBox;
bsSkinCheckRadioBox1: TbsSkinCheckRadioBox;
bsSkinButton1: TbsSkinButton;
bsSkinButton2: TbsSkinButton;
p_invoice_no: TADOStoredProc;
Edit2: TEdit;
procedure bsSkinButton1Click(Sender: TObject);
procedure bsSkinButton2Click(Sender: TObject);
procedure FormShow(Sender: TObject);
private
procedure getHldo;
{ Private declarations }
public
{ Public declarations }
end;
var
frm_ch_invoice_add: Tfrm_ch_invoice_add;
implementation
uses u_data_share, u_ch_invoice, u_main, my_sys_function, my_sys_chat;
{$R *.dfm}
procedure Tfrm_ch_invoice_add.bsSkinButton1Click(Sender: TObject);
var
afield : variant;
i: Integer;
begin
if trim(Edit1.Text)='' then
begin
showmessage('发票号码不能为空!!');
exit;
end;
if bsSkinCheckRadioBox7.Checked or bsSkinCheckRadioBox8.Checked then
begin
if trim(wwDBLookupCombo6.Text)='' then
begin
showmessage('发票币别不能为空!!');
exit;
end;
if RxDBLookupCombo3.DisplayValue='' then
begin
showmessage('客户名称不能为空!!');
exit;
end;
end;
if bsSkinCheckRadioBox7.Checked then
begin
try
modify_all:=true;
frm_ch_invoice.t_ch_invoice.Insert;
frm_ch_invoice.t_ch_invoice['发票类别']:='自由发票';
frm_ch_invoice.t_ch_invoice['发票号码']:=trim(Edit1.Text);
frm_ch_invoice.t_ch_invoice['币别']:=wwDBLookupCombo6.Text;
frm_ch_invoice.t_ch_invoice['客户名称']:=RxDBLookupCombo3.DisplayValues[1];
frm_ch_invoice.t_ch_invoice['费用列表']:=get_parameters_value(7,'海运费');
if not frm_data_share.t_crm_client_all.IsEmpty then
if frm_data_share.t_crm_client_all.locate('客户简称',RxDBLookupCombo3.DisplayValues[1],[]) then
begin
if trim(frm_data_share.t_crm_client_all.fieldbyname('发票抬头').asstring)<>''then
frm_ch_invoice.t_ch_invoice['发票抬头']:=frm_data_share.t_crm_client_all.fieldbyname('发票抬头').asstring;
end;
frm_ch_invoice.t_ch_invoice.post;
modify_all:=false;
except
if frm_ch_invoice.t_ch_invoice.State=dsinsert then
frm_ch_invoice.t_ch_invoice.cancel;
modify_all:=true;
showmessage('发票添加失败!!');
exit;
end;
frm_ch_invoice.bsSkinTabSheet2.show;
close;
exit;
end;
if bsSkinCheckRadioBox8.Checked then
begin
try
modify_all:=true;
afield := vararraycreate([0,frm_ch_invoice.t_ch_invoice.fieldcount-1],varvariant);
for i := 0 to (frm_ch_invoice.t_ch_invoice.fieldcount-1) do
begin
afield[i] :=frm_ch_invoice.t_ch_invoice.fields[i].value ;
end;
frm_ch_invoice.t_ch_invoice.append;
for i := 0 to (frm_ch_invoice.t_ch_invoice.fieldcount-1) do
begin
if frm_ch_invoice.t_ch_invoice.fields[i].FieldName<>'IN_ID'then
frm_ch_invoice.t_ch_invoice.fields[i].value := afield[i] ;
end;
frm_ch_invoice.t_ch_invoice['发票类别']:='自由发票';
frm_ch_invoice.t_ch_invoice['发票号码']:=trim(Edit1.Text);
frm_ch_invoice.t_ch_invoice['币别']:=wwDBLookupCombo6.Text;
frm_ch_invoice.t_ch_invoice['客户名称']:=RxDBLookupCombo3.DisplayValues[1];
if not frm_data_share.t_crm_client_all.IsEmpty then
if frm_data_share.t_crm_client_all.locate('客户简称',RxDBLookupCombo3.DisplayValues[1],[]) then
begin
if trim(frm_data_share.t_crm_client_all.fieldbyname('发票抬头').asstring)<>''then
frm_ch_invoice.t_ch_invoice['发票抬头']:=frm_data_share.t_crm_client_all.fieldbyname('发票抬头').asstring;
end;
frm_ch_invoice.t_ch_invoice['制单人']:=employee;
frm_ch_invoice.t_ch_invoice['开票日期']:=date;
frm_ch_invoice.t_ch_invoice['是否打印']:=0;
frm_ch_invoice.t_ch_invoice['是否废除']:=0;
frm_ch_invoice.t_ch_invoice['废除原因']:='';
frm_ch_invoice.t_ch_invoice['废除人']:='';
frm_ch_invoice.t_ch_invoice['废除日期']:=null;
frm_ch_invoice.t_ch_invoice['申请人']:='';
frm_ch_invoice.t_ch_invoice['申请日期']:=null;
frm_ch_invoice.t_ch_invoice.post;
modify_all:=false;
except
if frm_ch_invoice.t_ch_invoice.State=dsinsert then
frm_ch_invoice.t_ch_invoice.cancel;
modify_all:=true;
showmessage('发票添加失败!!');
exit;
end;
frm_ch_invoice.bsSkinTabSheet2.show;
close;
exit;
end;
if bsSkinCheckRadioBox1.Checked then
begin
try
modify_all:=true;
frm_ch_invoice.t_ch_invoice.Insert;
frm_ch_invoice.t_ch_invoice['发票类别']:='申请发票';
frm_ch_invoice.t_ch_invoice['发票号码']:=trim(Edit1.Text);
frm_ch_invoice.t_ch_invoice['币别']:=wwDBLookupCombo6.Text;
frm_ch_invoice.t_ch_invoice['客户名称']:=edit2.text;
frm_ch_invoice.t_ch_invoice['申请编号']:=frm_ch_invoice.t_ch_invoice_shen['申请编号'];
frm_ch_invoice.t_ch_invoice['发票抬头']:=frm_ch_invoice.t_ch_invoice_shen['发票抬头'];
frm_ch_invoice.t_ch_invoice['船名航次']:=frm_ch_invoice.t_ch_invoice_shen['船名航次'];
frm_ch_invoice.t_ch_invoice['提单号']:=frm_ch_invoice.t_ch_invoice_shen['提单号'];
frm_ch_invoice.t_ch_invoice['开船日期']:=frm_ch_invoice.t_ch_invoice_shen['开船日期'];
frm_ch_invoice.t_ch_invoice['启运港']:=frm_ch_invoice.t_ch_invoice_shen['启运港'];
frm_ch_invoice.t_ch_invoice['卸货港']:=frm_ch_invoice.t_ch_invoice_shen['卸货港'];
frm_ch_invoice.t_ch_invoice['目的港']:=frm_ch_invoice.t_ch_invoice_shen['目的港'];
frm_ch_invoice.t_ch_invoice['费用列表']:=frm_ch_invoice.t_ch_invoice_shen['费用列表'];
frm_ch_invoice.t_ch_invoice['金额列表']:=frm_ch_invoice.t_ch_invoice_shen['金额列表'];
frm_ch_invoice.t_ch_invoice['备注']:=frm_ch_invoice.t_ch_invoice_shen['备注'];
frm_ch_invoice.t_ch_invoice['合计金额']:=frm_ch_invoice.t_ch_invoice_shen['申请金额'];
frm_ch_invoice.t_ch_invoice['实际金额']:=frm_ch_invoice.t_ch_invoice_shen['实际金额'];
frm_ch_invoice.t_ch_invoice['虚开金额']:=frm_ch_invoice.t_ch_invoice_shen['虚开金额'];
frm_ch_invoice.t_ch_invoice['币别']:=frm_ch_invoice.t_ch_invoice_shen['币别'];
frm_ch_invoice.t_ch_invoice['申请人']:=frm_ch_invoice.t_ch_invoice_shen['申请人'];
frm_ch_invoice.t_ch_invoice['申请日期']:=frm_ch_invoice.t_ch_invoice_shen['申请日期'];
frm_ch_invoice.t_ch_invoice['预抵日期']:=frm_ch_invoice.t_ch_invoice_shen['预抵日期'];
frm_ch_invoice.t_ch_invoice.post;
frm_ch_invoice.t_ch_invoice_shen.Edit;
frm_ch_invoice.t_ch_invoice_shen['申请状态']:='开出发票';
frm_ch_invoice.t_ch_invoice_shen['开出人']:=employee;
frm_ch_invoice.t_ch_invoice_shen['开出日期']:=now;
frm_ch_invoice.t_ch_invoice_shen['发票号码']:=trim(Edit1.Text);
frm_ch_invoice.t_ch_invoice_shen.post;
modify_all:=false;
{
Send_invocie_check_check('申请发票开出,申请编号:'+frm_ch_invoice.t_ch_invoice_shen.fieldbyname('申请编号').asstring
+',客户:'+frm_ch_invoice.t_ch_invoice_shen.fieldbyname('客户名称').asstring,frm_ch_invoice.t_ch_invoice_shen.fieldbyname('申请人').asstring,'25');
}
except
if frm_ch_invoice.t_ch_invoice.State=dsinsert then
frm_ch_invoice.t_ch_invoice.cancel;
modify_all:=true;
showmessage('开出发票失败!!');
exit;
end;
frm_ch_invoice.bsSkinTabSheet2.show;
close;
exit;
end;
end;
procedure Tfrm_ch_invoice_add.bsSkinButton2Click(Sender: TObject);
begin
close;
end;
procedure Tfrm_ch_invoice_add.FormShow(Sender: TObject);
var
i:integer;
begin
p_invoice_no.ExecProc;
try
i:=strtoint(p_invoice_no.Parameters[1].value);
Edit1.Text:=inttostr(i+1);
except
;
end;
end;
procedure Tfrm_ch_invoice_add.getHldo;
var
aQuery,t_ch_pay,t_ch_fee:TADOQuery;
begin
aQuery:=CreateAdoQuery;
t_ch_pay:=CreateAdoQuery;
t_ch_fee:=CreateAdoQuery;
try
with aQuery do begin
close;sql.Clear;
SQL.Add('select * from v_fee_do_seae where 工作编号='''+frm_ch_invoice.t_ch_invoice_shen['申请编号']+''' and 结算差额<>0');
Open;
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
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['类型']:='收';
t_ch_pay['费用状态']:='审核通过';
t_ch_pay['录入人']:=employee;
t_ch_pay['单价']:=FieldByName('结算差额').AsFloat;
t_ch_pay['数量']:=1;
t_ch_pay['金额']:=FieldByName('结算差额').AsFloat;
t_ch_pay['币别']:='RMB';
t_ch_pay['费用名称']:='汇兑损益';
t_ch_pay['标准']:='票';
t_ch_pay['客户名称']:=t_ch_fee.fieldbyname('客户名称').AsString;
t_ch_pay['结算单位']:=t_ch_fee.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;
Next;
end;
end;
end;
finally
FreeAndNil(aQuery);
FreeAndNil(t_ch_pay);
FreeAndNil(t_ch_fee);
end;
end;
end.