unit u_piliang_send_msg; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, bsSkinCtrls, BusinessSkinForm, dxExEdtr, dxDBTLCl, dxGrClms, dxDBGrid, dxTL, dxDBCtrl, dxCntner, DB, ADODB, Grids, DBGrids, kbmMemTable; type Tfrm_piliang_send_msg = class(TForm) bsSkinPanel1: TbsSkinPanel; bsBusinessSkinForm1: TbsBusinessSkinForm; dxDBGrid1: TdxDBGrid; dxDBGrid1Column1: TdxDBGridMaskColumn; dxDBGrid1Column4: TdxDBGridMaskColumn; dxDBGrid1Column5: TdxDBGridMaskColumn; dxDBGrid1Column6: TdxDBGridMaskColumn; dxDBGrid1Column7: TdxDBGridMaskColumn; dxDBGrid1Column13: TdxDBGridMaskColumn; dxDBGrid1Column14: TdxDBGridMaskColumn; dxDBGrid1Column15: TdxDBGridMaskColumn; dxDBGrid1Column16: TdxDBGridDateColumn; dxDBGrid1Column19: TdxDBGridMaskColumn; dxDBGrid1Column20: TdxDBGridMaskColumn; dxDBGrid1TEU: TdxDBGridMaskColumn; dxDBGrid1Column63: TdxDBGridMaskColumn; dxDBGrid1Column64: TdxDBGridMaskColumn; dxDBGrid1Column65: TdxDBGridDateColumn; dxDBGrid1Column66: TdxDBGridMaskColumn; dxDBGrid1Column67: TdxDBGridMaskColumn; t_op_seae1: TDataSource; t_ch_accept: TADOQuery; t_ch_accept1: TDataSource; t_ch_pay: TADOQuery; t_ch_pay1: TDataSource; t_sys_report: TADOQuery; t_sys_report1: TDataSource; dxDBGrid2: TdxDBGrid; dxDBGridMaskColumn1: TdxDBGridMaskColumn; dxDBGrid1Column2: TdxDBGridCheckColumn; t_op_seae: TADOStoredProc; t_op_gain: TADOQuery; t_op_gain1: TDataSource; bsSkinButton8: TbsSkinButton; bsSkinButton5: TbsSkinButton; t_op_fenzhang: TADOQuery; t_ch_fee_fenzhang2: TADOQuery; t_ch_fee_fenzhang: TADOQuery; ds_ch_fee_fenzhang21: TDataSource; ds_op_fenzhang1: TDataSource; ds_ch_fee_fenzhang1: TDataSource; memtblprint1: TDataSource; memtblprint: TkbmMemTable; memdd: TkbmMemTable; memdd1: TDataSource; memaccept1: TDataSource; memaccept: TkbmMemTable; mempay: TkbmMemTable; mempay1: TDataSource; at_modify_old: TADOQuery; at_modify_new: TADOQuery; dsrmodify_new: TDataSource; dsrmodify_old: TDataSource; t_ch_fee_truck: TADOQuery; t_ch_fee_truck1: TDataSource; t_print_histry: TADOQuery; t_print_histry1: TDataSource; procedure bsSkinButton5Click(Sender: TObject); procedure bsSkinButton8Click(Sender: TObject); procedure FormShow(Sender: TObject); private { Private declarations } public { Public declarations } end; var frm_piliang_send_msg: Tfrm_piliang_send_msg; implementation uses u_main, my_sys_function; {$R *.dfm} procedure Tfrm_piliang_send_msg.bsSkinButton5Click(Sender: TObject); begin close; end; procedure Tfrm_piliang_send_msg.bsSkinButton8Click(Sender: TObject); var Frt:String; aQuery:TADOQuery; begin if t_sys_report.IsEmpty then begin showmessage('没有利润单格式,无法打印!!'); exit; end; if strtobool(get_parameters_value(2,'false'))then begin t_op_seae.first; while not t_op_seae.eof do begin t_ch_accept.first; while not t_ch_accept.eof do begin if (t_ch_accept.FieldByName('费用状态').asstring='录入状态') or(t_ch_accept.FieldByName('费用状态').asstring='提交审核') or(t_ch_accept.FieldByName('费用状态').asstring='申请修改') or(t_ch_accept.FieldByName('费用状态').asstring='申请删除') then begin showmessage('费用必须在审核通过后方可以打印利润单!!'); exit; end; t_ch_accept.next; end; t_ch_pay.first; while not t_ch_pay.eof do begin if (t_ch_pay.FieldByName('费用状态').asstring='录入状态') or(t_ch_pay.FieldByName('费用状态').asstring='提交审核') or(t_ch_pay.FieldByName('费用状态').asstring='申请修改') or(t_ch_pay.FieldByName('费用状态').asstring='申请删除') then begin showmessage('费用必须在审核通过后方可以打印利润单!!'); exit; end; t_ch_pay.next; end; t_op_seae.next; end; end; t_ch_fee_fenzhang.close; t_ch_fee_fenzhang.Parameters[0].value:=t_ch_accept.DataSource.DataSet.fieldbyname('编号').asstring; t_ch_fee_fenzhang.open; t_ch_fee_fenzhang2.close; t_ch_fee_fenzhang2.Parameters[0].value:=t_ch_accept.DataSource.DataSet.fieldbyname('编号').asstring; t_ch_fee_fenzhang2.open; t_op_fenzhang.close; t_op_fenzhang.Parameters[0].value:=t_ch_accept.DataSource.DataSet.fieldbyname('编号').asstring; t_op_fenzhang.open; at_modify_new.close; at_modify_new.Parameters[0].value:=t_ch_accept.DataSource.DataSet.fieldbyname('编号').asstring; at_modify_new.open; at_modify_old.close; at_modify_old.Parameters[0].value:=t_ch_accept.DataSource.DataSet.fieldbyname('编号').asstring; at_modify_old.open; if strtobool(get_parameters_value(111,'false')) then begin memtblprint.close; memtblprint.Open; t_ch_accept.First; while not t_ch_accept.Eof do begin Frt:=GetFrt(t_ch_accept.FieldByName('客户名称').AsString); if memtblprint.Locate('Frt;ACCNAME;OBJDR',vararrayof([Frt,t_ch_accept.FieldByName('费用名称').asstring,t_ch_accept.FieldByName('客户名称').asstring]),[]) then begin memtblprint.Edit; if t_ch_accept.FieldByName('币别').AsString='USD' then begin memtblprint.FieldByName('USDDR').AsFloat:=memtblprint.FieldByName('USDDR').AsFloat+t_ch_accept.fieldByName('金额').AsFloat; memtblprint.FieldByName('TTLDR').AsFloat:=memtblprint.FieldByName('TTLDR').AsFloat+(t_ch_accept.fieldByName('金额').AsFloat*t_ch_accept.fieldByName('汇率').AsFloat); end else begin memtblprint.FieldByName('RMBDR').AsFloat:=memtblprint.FieldByName('RMBDR').AsFloat+t_ch_accept.fieldByName('金额').AsFloat; memtblprint.FieldByName('TTLDR').AsFloat:=memtblprint.FieldByName('TTLDR').AsFloat+(t_ch_accept.fieldByName('金额').AsFloat*t_ch_accept.fieldByName('汇率').AsFloat); end; if memtblprint.FieldByName('REMARKDR').AsString='' then begin memtblprint.FieldByName('REMARKDR').AsString:=t_ch_accept.fieldbyName('备注').AsString; end else begin memtblprint.FieldByName('REMARKDR').AsString:=memtblprint.FieldByName('REMARKDR').AsString+' '+t_ch_accept.fieldbyName('备注').AsString; end; memtblprint.Post; end else begin memtblprint.Insert; memtblprint.FieldByName('ORDNO').AsInteger:=0; memtblprint.FieldByName('FRT').AsString:=GetFrt(t_ch_accept.FieldByName('客户名称').AsString); memtblprint.FieldByName('ACCNAME').AsString:=t_ch_accept.FieldByName('费用名称').AsString; memtblprint.FieldByName('OBJDR').AsString:=t_ch_accept.FieldByName('客户名称').AsString; memtblprint.FieldByName('OBJCR').AsString:=''; memtblprint.FieldByName('REMARKCR').AsString:=''; memtblprint.FieldByName('USDCR').AsFloat:=0; memtblprint.FieldByName('RMBCR').AsFloat:=0; memtblprint.FieldByName('TTLCR').AsFloat:=0; memtblprint.FieldByName('DR').AsString:='T'; memtblprint.FieldByName('CR').AsString:='F'; if t_ch_accept.FieldByName('币别').AsString='USD' then begin memtblprint.FieldByName('USDDR').AsFloat:=t_ch_accept.fieldByName('金额').AsFloat; memtblprint.FieldByName('TTLDR').AsFloat:=(t_ch_accept.fieldByName('金额').AsFloat*t_ch_accept.fieldByName('汇率').AsFloat); end else begin memtblprint.FieldByName('RMBDR').AsFloat:=t_ch_accept.fieldByName('金额').AsFloat; memtblprint.FieldByName('TTLDR').AsFloat:=(t_ch_accept.fieldByName('金额').AsFloat*t_ch_accept.fieldByName('汇率').AsFloat); end; memtblprint.FieldByName('REMARKDR').AsString:=memtblprint.FieldByName('REMARKDR').AsString+' '+t_ch_accept.fieldbyName('备注').AsString; memtblprint.Post; end; t_ch_accept.Next; end; t_ch_pay.First; while not t_ch_pay.Eof do begin Frt:=GetFrt(t_ch_pay.FieldByName('客户名称').AsString); if memtblprint.Locate('Frt;ACCNAME;CR',vararrayof([Frt,t_ch_pay.FieldByName('费用名称').asstring,'F']),[]) then begin memtblprint.Edit; memtblprint.FieldByName('OBJCR').AsString:=t_ch_pay.FieldByName('客户名称').AsString; if t_ch_pay.FieldByName('币别').AsString='USD' then begin memtblprint.FieldByName('USDCR').AsFloat:=memtblprint.FieldByName('USDCR').AsFloat+t_ch_pay.fieldByName('金额').AsFloat; memtblprint.FieldByName('TTLCR').AsFloat:=memtblprint.FieldByName('TTLCR').AsFloat+(t_ch_pay.fieldByName('金额').AsFloat*t_ch_pay.fieldByName('汇率').AsFloat); end else begin memtblprint.FieldByName('RMBCR').AsFloat:=memtblprint.FieldByName('RMBCR').AsFloat+t_ch_pay.fieldByName('金额').AsFloat; memtblprint.FieldByName('TTLCR').AsFloat:=memtblprint.FieldByName('TTLCR').AsFloat+(t_ch_pay.fieldByName('金额').AsFloat*t_ch_pay.fieldByName('汇率').AsFloat); end; if memtblprint.FieldByName('REMARKCR').AsString='' then begin memtblprint.FieldByName('REMARKCR').AsString:=t_ch_pay.fieldbyName('备注').AsString; end else begin memtblprint.FieldByName('REMARKCR').AsString:=memtblprint.FieldByName('REMARKCR').AsString+' '+t_ch_pay.fieldbyName('备注').AsString; end; memtblprint.FieldByName('CR').AsString:='T'; memtblprint.Post; end else begin if memtblprint.Locate('Frt;ACCNAME;OBJCR',vararrayof([Frt,t_ch_pay.FieldByName('费用名称').asstring,t_ch_pay.FieldByName('客户名称').asstring]),[]) then begin memtblprint.Edit; if t_ch_pay.FieldByName('币别').AsString='USD' then begin memtblprint.FieldByName('USDCR').AsFloat:=memtblprint.FieldByName('USDCR').AsFloat+t_ch_pay.fieldByName('金额').AsFloat; memtblprint.FieldByName('TTLCR').AsFloat:=memtblprint.FieldByName('TTLCR').AsFloat+(t_ch_pay.fieldByName('金额').AsFloat*t_ch_pay.fieldByName('汇率').AsFloat); end else begin memtblprint.FieldByName('RMBCR').AsFloat:=memtblprint.FieldByName('RMBCR').AsFloat+t_ch_pay.fieldByName('金额').AsFloat; memtblprint.FieldByName('TTLCR').AsFloat:=memtblprint.FieldByName('TTLCR').AsFloat+(t_ch_pay.fieldByName('金额').AsFloat*t_ch_pay.fieldByName('汇率').AsFloat); end; if memtblprint.FieldByName('REMARKCR').AsString='' then begin memtblprint.FieldByName('REMARKCR').AsString:=t_ch_pay.fieldbyName('备注').AsString; end else begin memtblprint.FieldByName('REMARKCR').AsString:=memtblprint.FieldByName('REMARKCR').AsString+' '+t_ch_pay.fieldbyName('备注').AsString; end; memtblprint.FieldByName('CR').AsString:='T'; memtblprint.Post; end else begin memtblprint.Insert; memtblprint.FieldByName('ORDNO').AsInteger:=0; memtblprint.FieldByName('FRT').AsString:=GetFrt(t_ch_pay.FieldByName('客户名称').AsString); memtblprint.FieldByName('ACCNAME').AsString:=t_ch_pay.FieldByName('费用名称').AsString; memtblprint.FieldByName('OBJCR').AsString:=t_ch_pay.FieldByName('客户名称').AsString; memtblprint.FieldByName('OBJDR').AsString:=''; memtblprint.FieldByName('REMARKCR').AsString:=''; memtblprint.FieldByName('USDDR').AsFloat:=0; memtblprint.FieldByName('RMBDR').AsFloat:=0; memtblprint.FieldByName('TTLDR').AsFloat:=0; memtblprint.FieldByName('DR').AsString:='F'; memtblprint.FieldByName('CR').AsString:='T'; if t_ch_pay.FieldByName('币别').AsString='USD' then begin memtblprint.FieldByName('USDCR').AsFloat:=t_ch_pay.fieldByName('金额').AsFloat; memtblprint.FieldByName('TTLCR').AsFloat:=(t_ch_pay.fieldByName('金额').AsFloat*t_ch_pay.fieldByName('汇率').AsFloat); end else begin memtblprint.FieldByName('RMBCR').AsFloat:=t_ch_pay.fieldByName('金额').AsFloat; memtblprint.FieldByName('TTLCR').AsFloat:=(t_ch_pay.fieldByName('金额').AsFloat*t_ch_pay.fieldByName('汇率').AsFloat); end; memtblprint.FieldByName('REMARKCR').AsString:=memtblprint.FieldByName('REMARKCR').AsString+' '+t_ch_pay.fieldbyName('备注').AsString; memtblprint.Post; end; end; t_ch_pay.Next; end; memtblprint.SortOn('FRT;ACCNAME',[]); end; if strtobool(get_parameters_value(81,'false')) then begin aQuery:=CreateAdoQuery; try with aQuery do begin Close;SQL.Clear; SQL.Add('Select * from t_ch_fee where 类型=''收'' and 编号='''+t_ch_accept.DataSource.DataSet.fieldbyname('编号').asstring+''' and 费用名称 not in (select 中文名 from t_code_fee where 费用类别='''+get_parameters_value(82,'代垫费用')+''') order by 顺序'); Open; memaccept.LoadFromDataSet(aQuery,[mtcpostructure,mtcpoProperties,mtcpoFieldIndex]); Close;SQL.Clear; SQL.Add('Select * from t_ch_fee where 类型=''付'' and 编号='''+t_ch_accept.DataSource.DataSet.fieldbyname('编号').asstring+''' and 费用名称 not in (select 中文名 from t_code_fee where 费用类别='''+get_parameters_value(82,'代垫费用')+''') order by 顺序'); Open; mempay.LoadFromDataSet(aQuery,[mtcpostructure,mtcpoProperties,mtcpoFieldIndex]); Close;SQL.Clear; SQL.Add('Select * from t_ch_fee where 类型=''付'' and 编号='''+t_ch_accept.DataSource.DataSet.fieldbyname('编号').asstring+''' and 费用名称 in (select 中文名 from t_code_fee where 费用类别='''+get_parameters_value(82,'代垫费用')+''') order by 顺序'); Open; memdd.LoadFromDataSet(aQuery,[mtcpostructure,mtcpoProperties,mtcpoFieldIndex]); end; finally FreeAndNil(aQuery); end; if strtobool(get_parameters_value(30,'false')) then begin t_ch_fee_truck.close; t_ch_fee_truck.Parameters[0].value:=t_ch_accept.DataSource.DataSet.fieldbyname('编号').asstring; t_ch_fee_truck.open; sys_print_piliang('海运出口利润单',t_sys_report.fieldbyname('报表名称').asstring,t_op_seae,t_op_seae1,t_op_gain1,ds_op_fenzhang1,t_ch_fee_truck1,t_ch_accept1,t_ch_pay1,ds_ch_fee_fenzhang21,ds_ch_fee_fenzhang1,dsrmodify_new,dsrmodify_old,memdd1); // sys_print(edit_report.text+'利润单',2,t_ch_accept.DataSource,t_op_gain1,ds_op_fenzhang1,t_ch_fee_truck1,memaccept1,mempay1,ds_ch_fee_fenzhang21,ds_ch_fee_fenzhang1,dsrmodify_new,dsrmodify_old,memdd1,false); end else sys_print_piliang('海运出口利润单',t_sys_report.fieldbyname('报表名称').asstring,t_op_seae,t_op_seae1,t_op_gain1,ds_op_fenzhang1,nil,t_ch_accept1,t_ch_pay1,ds_ch_fee_fenzhang21,ds_ch_fee_fenzhang1,dsrmodify_new,dsrmodify_old,memdd1); // sys_print(edit_report.text+'利润单',2,t_ch_accept.DataSource,t_op_gain1,ds_op_fenzhang1,nil,memaccept1,mempay1,ds_ch_fee_fenzhang21,ds_ch_fee_fenzhang1,dsrmodify_new,dsrmodify_old,memdd1,false); end else begin with t_print_histry do begin Close;SQL.Clear; SQL.Add('Select * from t_sys_printhistry where 单据名称=''利润账单'' and 编号='''+t_ch_accept.DataSource.DataSet.fieldbyname('编号').asstring+''''); Open; if IsEmpty then begin Insert; FieldByName('编号').AsString:=t_ch_accept.DataSource.DataSet.fieldbyname('编号').asstring; FieldByName('单据名称').AsString:='利润账单'; FieldByName('打印人').AsString:=employee; FieldByName('时间').AsDateTime:=Date; Post; end; end; if strtobool(get_parameters_value(30,'false')) then begin t_ch_fee_truck.close; t_ch_fee_truck.Parameters[0].value:=t_ch_accept.DataSource.DataSet.fieldbyname('编号').asstring; t_ch_fee_truck.open; if strtobool(get_parameters_value(111,'false')) then begin sys_print_piliang('海运出口利润单',t_sys_report.fieldbyname('报表名称').asstring,t_op_seae,t_op_seae1,t_op_gain1,ds_op_fenzhang1,t_ch_fee_truck1,memtblprint1,t_ch_pay1,ds_ch_fee_fenzhang21,ds_ch_fee_fenzhang1,dsrmodify_new,dsrmodify_old,t_print_histry1); // sys_print(edit_report.text+'利润单',2,t_ch_accept.DataSource,t_op_gain1,ds_op_fenzhang1,t_ch_fee_truck1,memtblprint1,t_ch_pay1,ds_ch_fee_fenzhang21,ds_ch_fee_fenzhang1,dsrmodify_new,dsrmodify_old,t_print_histry1,false,t_ch_accept.DataSource.DataSet.fieldbyname('委托单位').AsString); end else sys_print_piliang('海运出口利润单',t_sys_report.fieldbyname('报表名称').asstring,t_op_seae,t_op_seae1,t_op_gain1,ds_op_fenzhang1,t_ch_fee_truck1,t_ch_accept1,t_ch_pay1,ds_ch_fee_fenzhang21,ds_ch_fee_fenzhang1,dsrmodify_new,dsrmodify_old,t_print_histry1); // sys_print(edit_report.text+'利润单',2,t_ch_accept.DataSource,t_op_gain1,ds_op_fenzhang1,t_ch_fee_truck1,t_ch_accept1,t_ch_pay1,ds_ch_fee_fenzhang21,ds_ch_fee_fenzhang1,dsrmodify_new,dsrmodify_old,t_print_histry1,false,t_ch_accept.DataSource.DataSet.fieldbyname('委托单位').AsString); end else if strtobool(get_parameters_value(111,'false')) then begin sys_print_piliang('海运出口利润单',t_sys_report.fieldbyname('报表名称').asstring,t_op_seae,t_op_seae1,t_op_gain1,ds_op_fenzhang1,t_ch_fee_truck1,memtblprint1,t_ch_pay1,ds_ch_fee_fenzhang21,ds_ch_fee_fenzhang1,dsrmodify_new,dsrmodify_old,t_print_histry1); // sys_print(edit_report.text+'利润单',2,t_ch_accept.DataSource,t_op_gain1,ds_op_fenzhang1,t_ch_fee_truck1,memtblprint1,t_ch_pay1,ds_ch_fee_fenzhang21,ds_ch_fee_fenzhang1,dsrmodify_new,dsrmodify_old,t_print_histry1,false,t_ch_accept.DataSource.DataSet.fieldbyname('委托单位').AsString); end else sys_print_piliang('海运出口利润单',t_sys_report.fieldbyname('报表名称').asstring,t_op_seae,t_op_seae1,t_op_gain1,ds_op_fenzhang1,t_ch_fee_truck1,t_ch_accept1,t_ch_pay1,ds_ch_fee_fenzhang21,ds_ch_fee_fenzhang1,dsrmodify_new,dsrmodify_old,t_print_histry1); // sys_print(edit_report.text+'利润单',2,t_ch_accept.DataSource,t_op_gain1,ds_op_fenzhang1,t_ch_fee_truck1,t_ch_accept1,t_ch_pay1,ds_ch_fee_fenzhang21,ds_ch_fee_fenzhang1,dsrmodify_new,dsrmodify_old,t_print_histry1,false,t_ch_accept.DataSource.DataSet.fieldbyname('委托单位').AsString); end; end; procedure Tfrm_piliang_send_msg.FormShow(Sender: TObject); begin t_sys_report.Parameters[0].value:='海运出口利润单'; t_sys_report.open; t_ch_accept.open; t_ch_pay.open; t_op_gain.open; end; end.