unit u_ch_invoice_addone_jk; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, bsSkinCtrls, Grids, DBGridEh, StdCtrls, Mask, bsSkinBoxCtrls, DB, ADODB, kbmMemTable, kbmMemBinaryStreamFormat; type Tfrmch_invoice_addone_jk = class(TForm) bsSkinPanel1: TbsSkinPanel; bsSkinButton1: TbsSkinButton; bsSkinButton2: TbsSkinButton; bsSkinGroupBox1: TbsSkinGroupBox; DBGridEh1: TDBGridEh; bsSkinRadioGroup1: TbsSkinRadioGroup; bsSkinCheckRadioBox1: TbsSkinCheckRadioBox; bsSkinCheckRadioBox2: TbsSkinCheckRadioBox; bsSkinEdit1: TbsSkinEdit; Label1: TLabel; ADOQuery1: TADOQuery; DataSource1: TDataSource; ADOQuery2: TADOQuery; t_ch_fee_do: TADOQuery; bsSkinGroupBox2: TbsSkinGroupBox; DBGridEh2: TDBGridEh; t_fee_obj: TADOQuery; t_fee_obj1: TDataSource; memtblDetail: TkbmMemTable; memtblDetailCH_ID: TIntegerField; memtblDetailField: TStringField; memtblDetailField2: TStringField; memtblDetailField3: TFloatField; memtblDetailField4: TFloatField; memtblDetailField5: TFloatField; memtblDetailField6: TStringField; memtblDetailField7: TFloatField; memtblDetailField8: TStringField; memtblDetailField9: TFloatField; memtblDetailField10: TFloatField; memtblDetailField11: TStringField; kbmBinaryStreamFormat1: TkbmBinaryStreamFormat; memtblDetailField12: TBooleanField; memtblDetailField13: TFloatField; memtblDetailField14: TStringField; procedure FormShow(Sender: TObject); procedure bsSkinButton1Click(Sender: TObject); procedure t_fee_objAfterScroll(DataSet: TDataSet); private { Private declarations } public MblNo:Boolean; { Public declarations } end; var frmch_invoice_addone_jk: Tfrmch_invoice_addone_jk; implementation uses u_main, u_data_share, u_ch_invoice, my_sys_function; {$R *.dfm} procedure Tfrmch_invoice_addone_jk.FormShow(Sender: TObject); begin IF frm_data_share.t_code_currency.Locate('币别','USD',[])THEN bsSkinEdit1.Text:=frm_data_share.t_code_currency.fieldbyname('汇率').AsString; memtblDetail.LoadFromDataSet(ADOQuery1,[]); memtblDetail.open; memtblDetail.filtered:=false; memtblDetail.First; while not memtblDetail.Eof do begin memtbldetail.Edit; memtbldetail.fieldbyname('实开金额').AsFloat:=memtbldetail.fieldbyname('金额').AsFloat-memtbldetail.fieldbyname('开票金额').AsFloat-memtbldetail.fieldbyname('申请开票').AsFloat; memtbldetail.fieldbyname('选择').Asboolean:=true; memtbldetail.post; memtblDetail.Next; end; memtblDetail.filter:='客户名称='+''''+t_fee_obj.fieldbyname('客户名称').asstring+''''; memtblDetail.filtered:=true; end; procedure Tfrmch_invoice_addone_jk.bsSkinButton1Click(Sender: TObject); var FeeStr,NameStr:TStringList; jine:Double; str:String; begin FeeStr:=TStringList.Create; NameStr:=TStringList.Create; try frm_ch_invoice_jk.t_ch_invoice.Edit; if not ADOQuery2.IsEmpty then begin frm_ch_invoice_jk.t_ch_invoice['船名航次']:=ADOQuery2['船名']+'/'+ADOQuery2['航次']; frm_ch_invoice_jk.t_ch_invoice['启运港']:=ADOQuery2['起运港']; frm_ch_invoice_jk.t_ch_invoice['卸货港']:=ADOQuery2['卸货港']; frm_ch_invoice_jk.t_ch_invoice['目的港']:=ADOQuery2['目的地']; frm_ch_invoice_jk.t_ch_invoice['开船日期']:=ADOQuery2['开船日期']; if Mblno then frm_ch_invoice_jk.t_ch_invoice['委托编号']:=ADOQuery2['委托编号'] else frm_ch_invoice_jk.t_ch_invoice['提单号']:=ADOQuery2['主提单号']; if (frm_ch_invoice_jk.t_ch_invoice.FieldByName('申请编号').IsNull) or (frm_ch_invoice_jk.t_ch_invoice.FieldByName('申请编号').AsString='') then begin Str:=get_no(date,'IA'); frm_ch_invoice_jk.t_ch_invoice['申请编号']:=Str; end else Str:=frm_ch_invoice_jk.t_ch_invoice['申请编号']; end; if bsSkinRadioGroup1.ItemIndex=1 then frm_ch_invoice_jk.t_ch_invoice['币别']:='USD' else frm_ch_invoice_jk.t_ch_invoice['币别']:='RMB'; if (frm_ch_invoice_jk.t_ch_invoice.FieldByName('客户名称').IsNull) or (frm_ch_invoice_jk.t_ch_invoice['客户名称']='') then begin frm_ch_invoice_jk.t_ch_invoice['客户名称']:=t_fee_obj.fieldbyName('客户名称').AsString; end; if not frm_data_share.t_crm_client_all.IsEmpty then if frm_data_share.t_crm_client_all.locate('客户简称',t_fee_obj.fieldbyName('客户名称').AsString,[]) then begin if trim(frm_data_share.t_crm_client_all.fieldbyname('发票抬头').asstring)<>''then frm_ch_invoice_jk.t_ch_invoice['发票抬头']:=frm_data_share.t_crm_client_all.fieldbyname('发票抬头').asstring; end; jine:=0; memtblDetail.First; t_ch_fee_do.Open; while not memtblDetail.Eof do begin if (memtblDetail.FieldByNAME('实开金额').AsFloat<>0) and (memtblDetail.FieldByNAME('选择').Asboolean) then begin if memtblDetail['币别']='USD' then begin if bsSkinRadioGroup1.ItemIndex=1 then begin if bsSkinCheckRadioBox1.Checked then begin FeeStr.Add(FloatToStr(memtblDetail.FieldByNAME('实开金额').AsFloat)); NameStr.Add(memtblDetail['费用名称']); jine:=jine+(memtblDetail.FieldByNAME('实开金额').AsFloat); end else begin jine:=jine+(memtblDetail.FieldByNAME('实开金额').AsFloat); end; t_ch_fee_do.Insert; t_ch_fee_do['工作编号']:=Str; t_ch_fee_do['业务编号']:=memtblDetail['编号']; t_ch_fee_do['CH_ID']:=memtblDetail['CH_ID']; t_ch_fee_do['币别']:='USD'; t_ch_fee_do['金额']:=memtblDetail.FieldByNAME('实开金额').AsFloat; t_ch_fee_do['原始金额']:=memtblDetail.FieldByNAME('实开金额').AsFloat; t_ch_fee_do['类型']:=1; t_ch_fee_do.Post; end else begin IF bsSkinCheckRadioBox2.Checked then begin if bsSkinCheckRadioBox1.Checked then begin FeeStr.Add(FloatToStr((memtblDetail.FieldByNAME('实开金额').AsFloat)*strtofloatdef(bsSkinEdit1.Text,7.0))); NameStr.Add(memtblDetail['费用名称']); jine:=jine+(memtblDetail.FieldByNAME('实开金额').AsFloat)*strtofloatdef(bsSkinEdit1.Text,7.0); end else begin jine:=jine+(memtblDetail.FieldByNAME('实开金额').AsFloat)*strtofloatdef(bsSkinEdit1.Text,7.0); end; t_ch_fee_do.Insert; t_ch_fee_do['工作编号']:=Str; t_ch_fee_do['业务编号']:=memtblDetail['编号']; t_ch_fee_do['CH_ID']:=memtblDetail['CH_ID']; t_ch_fee_do['币别']:='RMB'; t_ch_fee_do['金额']:=(memtblDetail.FieldByNAME('实开金额').AsFloat)*strtofloatdef(bsSkinEdit1.Text,7.0); t_ch_fee_do['原始金额']:=memtblDetail.FieldByNAME('实开金额').AsFloat; t_ch_fee_do['类型']:=1; t_ch_fee_do.Post; end; end; end else begin if bsSkinRadioGroup1.ItemIndex=1 then begin end else begin if bsSkinCheckRadioBox1.Checked then begin FeeStr.Add(FloatToStr(memtblDetail.FieldByNAME('实开金额').AsFloat)); NameStr.Add(memtblDetail['费用名称']); jine:=jine+(memtblDetail.FieldByNAME('实开金额').AsFloat); end else begin jine:=jine+(memtblDetail.FieldByNAME('实开金额').AsFloat); end; t_ch_fee_do.Insert; t_ch_fee_do['工作编号']:=Str; t_ch_fee_do['业务编号']:=memtblDetail['编号']; t_ch_fee_do['CH_ID']:=memtblDetail['CH_ID']; t_ch_fee_do['币别']:='RMB'; t_ch_fee_do['金额']:=(memtblDetail.FieldByNAME('实开金额').AsFloat); t_ch_fee_do['原始金额']:=memtblDetail.FieldByNAME('实开金额').AsFloat; t_ch_fee_do['类型']:=1; t_ch_fee_do.Post; end; end; end; memtblDetail.Next; end; if bsSkinCheckRadioBox1.Checked then begin if frm_ch_invoice_jk.t_ch_invoice['合计金额']=0 then begin frm_ch_invoice_jk.t_ch_invoice['费用列表']:=NameStr.Text; frm_ch_invoice_jk.t_ch_invoice['金额列表']:=FeeStr.Text; frm_ch_invoice_jk.t_ch_invoice['合计金额']:=jine; frm_ch_invoice_jk.t_ch_invoice['实际金额']:=jine; end else begin frm_ch_invoice_jk.t_ch_invoice['费用列表']:=frm_ch_invoice_jk.t_ch_invoice['费用列表']+#10#13+NameStr.Text; frm_ch_invoice_jk.t_ch_invoice['金额列表']:=frm_ch_invoice_jk.t_ch_invoice['金额列表']+#10#13+FeeStr.Text; frm_ch_invoice_jk.t_ch_invoice['合计金额']:=frm_ch_invoice_jk.t_ch_invoice['合计金额']+jine; frm_ch_invoice_jk.t_ch_invoice['实际金额']:=frm_ch_invoice_jk.t_ch_invoice['实际金额']+jine; end; end else begin if frm_ch_invoice_jk.t_ch_invoice['币别']='USD' then frm_ch_invoice_jk.t_ch_invoice['费用列表']:=get_parameters_value(7,'代理海运费') else frm_ch_invoice_jk.t_ch_invoice['费用列表']:=get_parameters_value(147,'代理运杂费'); if frm_ch_invoice_jk.t_ch_invoice['合计金额']=0 then begin frm_ch_invoice_jk.t_ch_invoice['金额列表']:=FloatToStr(jine); frm_ch_invoice_jk.t_ch_invoice['合计金额']:=jine; frm_ch_invoice_jk.t_ch_invoice['实际金额']:=jine; end else begin frm_ch_invoice_jk.t_ch_invoice['金额列表']:=FloatToStr(frm_ch_invoice_jk.t_ch_invoice['合计金额']+jine); frm_ch_invoice_jk.t_ch_invoice['合计金额']:=frm_ch_invoice_jk.t_ch_invoice['合计金额']+jine; frm_ch_invoice_jk.t_ch_invoice['实际金额']:=frm_ch_invoice_jk.t_ch_invoice['实际金额']+jine; end; end; frm_ch_invoice_jk.t_ch_invoice.Post; finally FreeAndNil(FeeStr); FreeAndNil(NameStr); end; close; end; procedure Tfrmch_invoice_addone_jk.t_fee_objAfterScroll(DataSet: TDataSet); begin memtblDetail.filtered:=false; memtblDetail.filter:='客户名称='+''''+t_fee_obj.fieldbyname('客户名称').asstring+''''; memtblDetail.filtered:=true; end; end.