unit u_ch_precost; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, dxExEdtr, DB, ADODB, u_ch_add_do, u_ch_delete_do, StdCtrls, DBCtrls, wwdblook, ComCtrls, bsSkinTabs, RxLookup, bsSkinCtrls, bsdbctrls, Mask, dxDBGrid, dxDBTLCl, dxGrClms, dxTL, dxDBCtrl, dxCntner, Menus, XPMenu, wwdbdatetimepicker, wwdbedit, Wwdotdot, Wwdbcomb, kbmMemTable, bsSkinBoxCtrls, DBCtrlsEh; type Tfrm_ch_precost = class(TForm) bsSkinPanel2: TbsSkinPanel; bsSkinButton1: TbsSkinButton; bsSkinButton2: TbsSkinButton; bsSkinButton4: TbsSkinButton; bsSkinButton3: TbsSkinButton; bsSkinButton5: TbsSkinButton; bsSkinButton9: TbsSkinButton; bsSkinButton10: TbsSkinButton; bsSkinButton11: TbsSkinButton; bsSkinButton6: TbsSkinButton; bsSkinNotebook1: TbsSkinNotebook; dxdbgrid1: TdxDBGrid; bsSkinPanel1: TbsSkinPanel; t_ch_precost: TADOQuery; t_ch_precost1: TDataSource; t_ch_fee_do_precost: TADOQuery; dxdbgrid1Column1: TdxDBGridMaskColumn; dxdbgrid1Column2: TdxDBGridMaskColumn; dxdbgrid1Column3: TdxDBGridMaskColumn; dxdbgrid1Column10: TdxDBGridMaskColumn; dxdbgrid1Column11: TdxDBGridDateColumn; XPMenu1: TXPMenu; PopupMenu2: TPopupMenu; N16: TMenuItem; dxdbgrid1Column18: TdxDBGridColumn; dxdbgrid1Column19: TdxDBGridColumn; memtblprint1: TDataSource; memtblprint: TkbmMemTable; bsSkinButton38: TbsSkinButton; DBEdit12: TDBEdit; PopupMenu1: TPopupMenu; MenuItem4: TMenuItem; MenuItem5: TMenuItem; N21: TMenuItem; N22: TMenuItem; N20: TMenuItem; N2: TMenuItem; N3: TMenuItem; dxdbgrid1Column27: TdxDBGridColumn; Label9: TLabel; Label11: TLabel; Label14: TLabel; Label16: TLabel; Label20: TLabel; Label22: TLabel; DBEdit5: TDBEdit; DBEdit9: TDBEdit; RxDBLookupCombo3: TRxDBLookupCombo; DBEdit10: TDBEdit; DBEdit11: TDBEdit; DBMemo2: TDBMemo; bsSkinButton21: TbsSkinButton; bsSkinPanel3: TbsSkinPanel; dxDBGrid2: TdxDBGrid; dxDBGrid2Column1: TdxDBGridColumn; dxDBGrid2Column2: TdxDBGridColumn; dxDBGrid2Column3: TdxDBGridColumn; dxDBGrid2Column4: TdxDBGridColumn; dxDBGrid2Column5: TdxDBGridColumn; dxDBGrid2Column6: TdxDBGridColumn; bsSkinPanel4: TbsSkinPanel; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label12: TLabel; Label4: TLabel; Label125: TLabel; Label30: TLabel; Label35: TLabel; Edit4: TEdit; Edit2: TEdit; wwDBDateTimePicker1: TwwDBDateTimePicker; wwDBDateTimePicker2: TwwDBDateTimePicker; bsSkinButton7: TbsSkinButton; bsSkinButton8: TbsSkinButton; Edit16: TEdit; bsSkinPanel5: TbsSkinPanel; dxDBGrid3: TdxDBGrid; dxDBGridColumn1: TdxDBGridColumn; dxDBGridColumn2: TdxDBGridColumn; dxDBGridColumn3: TdxDBGridColumn; dxDBGridColumn4: TdxDBGridColumn; dxDBGridColumn5: TdxDBGridColumn; dxDBGridColumn6: TdxDBGridColumn; dxDBGridColumn7: TdxDBGridColumn; Label38: TLabel; wwDBComboBox42: TwwDBComboBox; RxDBLookupCombo5: TRxDBLookupCombo; t_ch_fee_do_precost1: TDataSource; memtblItems: TkbmMemTable; memtblItems1: TDataSource; memtblItemsField: TBooleanField; memtblItemsField2: TStringField; memtblItemsField3: TStringField; memtblItemsField4: TStringField; memtblItemsField5: TStringField; memtblItemsField6: TStringField; memtblItemsField7: TFloatField; memtblItemsField8: TFloatField; memtblItemsch_id: TIntegerField; memtblItemsField9: TStringField; dxDBGrid3Column8: TdxDBGridCheckColumn; bsSkinButton13: TbsSkinButton; bsSkinButton14: TbsSkinButton; bsSkinButton15: TbsSkinButton; dxDBGrid2Column7: TdxDBGridColumn; Label5: TLabel; DBEdit1: TDBEdit; bsSkinButton16: TbsSkinButton; memtblItemsField10: TFloatField; dxDBGrid3Column9: TdxDBGridColumn; bsSkinButton17: TbsSkinButton; Label26: TLabel; wwDBDateTimePicker3: TwwDBDateTimePicker; t_cw_design: TADOQuery; dxdbgrid1Column9: TdxDBGridColumn; RxDBLookupCombo16: TRxDBLookupCombo; ComboBox1: TComboBox; ComboBox2: TComboBox; memtblItemsField11: TDateField; dxDBGrid3Column10: TdxDBGridColumn; dxDBGrid2Column8: TdxDBGridColumn; procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormShow(Sender: TObject); procedure bsSkinButton11Click(Sender: TObject); procedure t_ch_precostAfterInsert(DataSet: TDataSet); procedure bsSkinButton1Click(Sender: TObject); procedure bsSkinButton2Click(Sender: TObject); procedure bsSkinButton4Click(Sender: TObject); procedure bsSkinButton3Click(Sender: TObject); procedure t_ch_precostBeforePost(DataSet: TDataSet); procedure t_ch_precostBeforeEdit(DataSet: TDataSet); procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); procedure bsSkinButton9Click(Sender: TObject); procedure bsSkinButton5Click(Sender: TObject); procedure N16Click(Sender: TObject); procedure bsSkinPanel2Resize(Sender: TObject); procedure bsSkinButton38Click(Sender: TObject); procedure DBEdit12Change(Sender: TObject); procedure bsSkinButton8Click(Sender: TObject); procedure bsSkinButton7Click(Sender: TObject); procedure bsSkinButton13Click(Sender: TObject); procedure bsSkinButton14Click(Sender: TObject); procedure bsSkinButton15Click(Sender: TObject); procedure dxDBGrid3SelectedCountChange(Sender: TObject); procedure bsSkinButton16Click(Sender: TObject); procedure bsSkinButton17Click(Sender: TObject); procedure dxdbgrid1Column2CustomDraw(Sender: TObject; ACanvas: TCanvas; ARect: TRect; ANode: TdxTreeListNode; AColumn: TdxDBTreeListColumn; const AText: String; AFont: TFont; var AColor: TColor; ASelected, AFocused: Boolean; var ADone: Boolean); procedure DBEdit9Change(Sender: TObject); procedure dxDBGrid3CustomDraw(Sender: TObject; ACanvas: TCanvas; ARect: TRect; ANode: TdxTreeListNode; AColumn: TdxDBTreeListColumn; const AText: String; AFont: TFont; var AColor: TColor; ASelected, AFocused: Boolean; var ADone: Boolean); procedure dxDBGrid3DblClick(Sender: TObject); private { Private declarations } public { Public declarations } function GetCustID(CorpID,DC:String):String; procedure UpdateBillAmt; procedure NewDCVou_One; function NewDCVou_Patch(fDataSet:TDataSet;ZDR:String;voudate:TDatetime):Boolean; end; var ch_check_shen_open:boolean; frm_ch_precost: Tfrm_ch_precost; implementation uses u_main, u_ch_shen_query, my_sys_function, u_data_share, my_sys_chat,u_op_kuaidi_shen, dmAccu, VouItemStlu; {$R *.dfm} function Tfrm_ch_precost.GetCustID(CorpID,DC:String):String; var i:integer; aQuery:TADOQuery; begin aQuery:=createADOQuery; with aQuery do try Close;SQL.Clear; SQL.Add('select 财务应收帐款代码,财务应付帐款代码 from t_crm_client where 客户简称='''+CorpID+''''); Open; if DC='收' then Result:=fieldByName('财务应收帐款代码').AsString else Result:=fieldByName('财务应付帐款代码').AsString; if result='' then begin showmessage(CorpID+' '+DC+' '+'财务代码为空!'); Abort; end; finally FreeAndNil(aQuery); end; end; function Tfrm_ch_precost.NewDCVou_Patch(fDataSet:TDataSet;ZDR:String;voudate:TDatetime):Boolean; var aQuery,aQuery2:TADOQuery; mAccOK:Boolean; aModal:TModalResult; StlAmtDR,StlAmtCR,StlUSDAmtDR,StlUSDAmtCR,UsdExRate:Double; AmtDR,AmtCR,USDAmtDR,USDAmtCR,amtvat:Double; ordno:integer; MBlNo,Explan:string; begin Result:=false; aQuery:=CreateADOQuery; aQuery2:=CreateADOQuery; StlAmtDR:=0.00; StlAmtCR:=0.00; StlUSDAmtDR:=0.00; StlUSDAmtCR:=0.00; UsdExRate:=StrToFloatDef(DBEdit1.Text,7.8); amtvat:=0.00; Explan:=''; with aQuery,SQL do begin Close;Clear; Add('Select V_op_bscard_All.委托编号,t_ch_fee.客户名称,t_crm_client.客户全称'); Add(',t_ch_fee_do_precost.币别,sum(t_ch_fee_do_precost.金额) 金额'); Add('FROM t_ch_fee_do_precost'); Add('INNER JOIN t_ch_fee ON t_ch_fee_do_precost.CH_ID = t_ch_fee.CH_ID'); Add('LEFT JOIN V_op_bscard_All ON t_ch_fee_do_precost.业务编号 = V_op_bscard_All.编号'); Add('Left Join t_crm_client on t_ch_fee.客户名称=t_crm_client.客户简称'); Add('where t_ch_fee_do_precost.工作编号='''+fDataSet.fieldbyName('申请编号').AsString+''''); Add('group by V_op_bscard_All.委托编号,t_ch_fee.客户名称,t_crm_client.客户全称,t_ch_fee_do_precost.币别'); Open; end; OrdNo:=dmAcc.AdotblVou.fieldByName('OrdNo').AsInteger; dmAcc.AdotblVouItems.Open; aQuery.First; while not aQuery.Eof do begin dmAcc.AdotblVouItems.Insert; dmAcc.AdotblVouItems.FieldByName('AccID').AsString:='5121.021'; //成本 dmAcc.AdotblVouItems.FieldByName('QTYSPECS').AsString:=trim(t_cw_design.fieldbyname('供应商核算名称').AsString); if aQuery.FieldByName('币别').AsString='USD' then begin dmAcc.AdotblVouItems.FieldByName('FCYDr').AsFloat:=StrToFloatDef(FormatFloat('0.00;-0.00;0.0',aQuery.fieldByName('金额').AsFloat),0); dmAcc.AdotblVouItems.FieldByName('FCYEXRATE').AsFloat:=UsdExRate; dmAcc.AdotblVouItems.FieldByName('FCYCr').AsFloat:=0.0; dmAcc.AdotblVouItems.FieldByName('AmtCr').AsFloat:=0.0; dmAcc.AdotblVouItems.FieldByName('FCYNO').AsString:='RMB'; dmAcc.AdotblVouItems.FieldByName('AmtDr').AsFloat:=StrToFloatDef(FormatFloat('0.00;-0.00;0.0', StrToFloat(FloatToStr(aQuery.fieldByName('金额').AsFloat*UsdExRate))), 0); end else begin dmAcc.AdotblVouItems.FieldByName('AmtCr').AsFloat:=0.0; dmAcc.AdotblVouItems.FieldByName('AmtDR').AsFloat:=StrToFloatDef(FormatFloat('0.00;-0.00;0.0',aQuery.fieldByName('金额').AsFloat),0); dmAcc.AdotblVouItems.FieldByName('FCYDR').AsFloat:=0.0; dmAcc.AdotblVouItems.FieldByName('FCYCr').AsFloat:=0.0; dmAcc.AdotblVouItems.FieldByName('FCYEXRATE').AsFloat:=0.0; dmAcc.AdotblVouItems.FieldByName('FCYNO').AsString:='RMB'; end; dmAcc.AdotblVouItems.FieldByName('BSNO').AsString:=aQuery.fieldByName('委托编号').AsString; Explan:=getstrfromdataset(aQuery,t_cw_design.fieldByName('挂帐应付摘要').AsString); dmAcc.AdotblVouItems.FieldByName('EXPLAN').AsString:='预提'+Explan; dmAcc.AdotblVouItems.FieldByName('CorpID').AsString:=GetCustID(aQuery.fieldByName('客户名称').AsString,'付'); dmAcc.AdotblVouItems.FieldByName('CorpBf').AsString:='F'; dmAcc.AdotblVouItems.post; dmAcc.AdotblVouItems.Insert; dmAcc.AdotblVouItems.FieldByName('QTYSPECS').AsString:=trim(t_cw_design.fieldbyname('供应商核算名称').AsString); if aQuery.FieldByName('币别').AsString='USD' then begin dmAcc.AdotblVouItems.FieldByName('AccID').AsString:=t_cw_design.fieldbyname('应付账款外币').AsString; dmAcc.AdotblVouItems.FieldByName('FCYNO').AsString:='USD'; dmAcc.AdotblVouItems.FieldByName('FCYEXRATE').AsFloat:=UsdExRate; dmAcc.AdotblVouItems.FieldByName('FCYDR').AsFloat:=0.0; dmAcc.AdotblVouItems.FieldByName('FCYCr').AsFloat:=StrToFloatDef(FormatFloat('0.00;-0.00;0.0',aQuery.fieldByName('金额').AsFloat),0); dmAcc.AdotblVouItems.FieldByName('AmtDr').AsFloat:=0.0; dmAcc.AdotblVouItems.FieldByName('AmtCr').AsFloat:=StrToFloatDef(FormatFloat('0.00;-0.00;0.0', StrToFloat(FloatToStr(aQuery.fieldByName('金额').AsFloat*UsdExRate))), 0); end else begin dmAcc.AdotblVouItems.FieldByName('AccID').AsString:=t_cw_design.fieldbyname('应付账款').AsString; dmAcc.AdotblVouItems.FieldByName('FCYNO').AsString:='RMB'; dmAcc.AdotblVouItems.FieldByName('AmtDr').AsFloat:=0.0; dmAcc.AdotblVouItems.FieldByName('AmtCR').AsFloat:=StrToFloatDef(FormatFloat('0.00;-0.00;0.0',aQuery.fieldByName('金额').AsFloat),0); dmAcc.AdotblVouItems.FieldByName('FCYCR').AsFloat:=0.0; dmAcc.AdotblVouItems.FieldByName('FCYCr').AsFloat:=0.0; dmAcc.AdotblVouItems.FieldByName('FCYEXRATE').AsFloat:=0.0; end; dmAcc.AdotblVouItems.FieldByName('BSNO').AsString:=aQuery.fieldByName('委托编号').AsString; Explan:=getstrfromdataset(aQuery,t_cw_design.fieldByName('挂帐应付摘要').AsString); dmAcc.AdotblVouItems.FieldByName('EXPLAN').AsString:=Explan; dmAcc.AdotblVouItems.FieldByName('CorpID').AsString:=GetCustID(aQuery.fieldByName('客户名称').AsString,'付'); dmAcc.AdotblVouItems.FieldByName('CorpBf').AsString:='F'; dmAcc.AdotblVouItems.post; aQuery.next; end; FreeAndNil(aQuery); end; procedure Tfrm_ch_precost.NewDCVou_One; var i,ordno:integer; aQuery:TAdoQuery; aModal:TModalResult; mAccOK:boolean; begin if wwDBDateTimePicker3.Text='' then begin MessageDlg('请首先设置记账日期!',mterror,[mbyes],0); exit; end; if DBEdit1.Text='' then begin MessageDlg('请输入凭证汇率!',mterror,[mbyes],0); exit; end; if t_ch_fee_do_precost.IsEmpty then Exit; dmacc:=TdmAcc.Create(self); aQuery:=CreateAdoQuery; // try dmAcc.ADOtblVou.Open; dmAcc.ADOtblVouItems.Open; aVKNO:=1; aQuery.Close; aQuery.SQL.Clear; aQuery.SQL.add('update t_ch_precost set 财务=1,财务凭证=:财务凭证,申请状态=''生成凭证'' where 申请编号=:申请编号'); VoucherDate:=wwDBDateTimePicker3.Date; // try dmAcc.AdotblVou.Insert; dmAcc.AdotblVou.FieldByName('SourceType').AsInteger:=4; dmAcc.AdotblVou.FieldByName('ATTACHS').AsInteger:=AccInfo.ATTACHS; if Trim(t_cw_design.FieldByName('转帐凭证字').AsString)<>'' then begin dmAcc.AdotblVou.FieldByName('VKNO').AsString:=Trim(t_cw_design.FieldByName('转帐凭证字').AsString); end else dmAcc.AdotblVou.FieldByName('VKNO').AsString:='记'; dmAcc.AdotblVou.FieldByName('PREPARED').AsString:=employee; dmAcc.AdotblVou.Post; dmAcc.AdotblVou.Edit; NewDCVou_Patch(t_ch_precost,employee,wwDBDateTimePicker3.Date); aQuery.Parameters.ParamByName('财务凭证').Value:=dmacc.ADOTblVou.fieldbyname('ordno').AsString; aQuery.Parameters.ParamByName('申请编号').Value:=t_ch_precost.fieldbyname('申请编号').AsString; aQuery.ExecSQL; ordno:=dmAcc.AdotblVou.fieldbyname('ordno').asinteger; dmAcc.AdotblVou.Post; FrmVouItemStl:=TFrmVouItemStl.Create(Application); // try dmACC.AdotblVouItems.Last; FrmVouItemStl.DBGridVouItems.SelectedField:=dmACC.AdotblVouItems.FieldByName('AccID'); FrmVouItemStl.ShowModal; mAccOK:=false; aModal:=frmVouItemStl.ModalResult; mAccOK:=aModal=mrok; if mAccOK then begin if dmAcc.AdotblVouItems.State in [dsEdit,dsInsert] then dmAcc.AdotblVouItems.Post; if dmAcc.AdotblVou.State in [dsEdit,dsInsert] then dmAcc.AdotblVou.Post; end else begin dmAcc.TempQuery.Close; dmAcc.TempQuery.SQL.Clear; dmAcc.TempQuery.SQL.Add('delete from vouchers where ordno=:mOrdNo'); dmAcc.TempQuery.Parameters.ParamByName('mOrdNo').value:=OrdNo; dmAcc.TempQuery.ExecSQL; dmAcc.TempQuery.Close; dmAcc.TempQuery.SQL.Clear; dmAcc.TempQuery.SQL.Add('update t_ch_precost set 申请状态=''录入状态'' , 财务=0,财务凭证='''' where 财务凭证='''+inttostr(OrdNo)+''''); dmAcc.TempQuery.ExecSQL; end; // finally freeAndNil(FrmVouItemStl); // end; { except dmAcc.TempQuery.Close; dmAcc.TempQuery.SQL.Clear; dmAcc.TempQuery.SQL.Add('delete from vouchers where ordno=:mOrdNo'); dmAcc.TempQuery.Parameters.ParamByName('mOrdNo').value:=OrdNo; dmAcc.TempQuery.ExecSQL; end; } // finally dmAcc.AdotblVouItems.Close; dmAcc.AdotblVou.Close; freeAndNil(dmacc); // end; end; procedure Tfrm_ch_precost.FormClose(Sender: TObject; var Action: TCloseAction); begin ch_check_shen_open:=false; savereggrid(dxdbgrid1,caption+'1'); frm_ch_precost.Hide; frm_ch_precost.ManualFloat(frm_ch_precost.BoundsRect ); frm_main.freeTabs('frm_ch_precost'); action:=cafree; frm_ch_precost:=nil; end; procedure Tfrm_ch_precost.FormShow(Sender: TObject); begin wwDBComboBox42.Text:='不等于'; RxDBLookupCombo16.Value:='PHF'; bsSkinNotebook1.PageIndex:=0; t_ch_precost.Close; t_ch_precost.SQL.clear; t_ch_precost.SQL.Add('select * from t_ch_precost where 申请状态 not in ('+''''+'批准支付'+'''' +','+''''+'支付完毕'+''''+') and ' +open_data('1003','申请人','no','no','no','no') +'order by 申请编号 desc'); t_ch_precost.open; t_ch_fee_do_precost.Close; t_ch_fee_do_precost.Open; ch_check_shen_open:=true; t_cw_design.Open; end; procedure Tfrm_ch_precost.bsSkinButton11Click(Sender: TObject); var answer:TModalResult; begin if bsSkinButton11.Caption='编辑修改' then begin if t_ch_precost.IsEmpty then exit; bsSkinNotebook1.PageIndex:=1; bsSkinButton11.Caption:='返回列表'; end else begin if (t_ch_precost.State=dsinsert)or(t_ch_precost.State=dsedit) then BEGIN answer:=messagedlg( '数据已经修改,是否保存?',mtWarning,mbYesNoCancel,0); if answer=mrYes then begin t_ch_precost.post; end; if answer=mrNo then begin t_ch_precost.cancel; end; if answer=mrCancel then begin exit; end; END; bsSkinNotebook1.PageIndex:=0; bsSkinButton11.Caption:='编辑修改'; end; end; procedure Tfrm_ch_precost.t_ch_precostAfterInsert(DataSet: TDataSet); begin t_ch_precost['申请状态']:='录入状态'; t_ch_precost['申请人']:=employee; t_ch_precost['申请日期']:=now; t_ch_precost['凭证日期']:=date; t_ch_precost['申请编号']:=''; IF frm_data_share.t_code_currency.Locate('币别','USD',[])THEN begin t_ch_precost['汇率']:=frm_data_share.t_code_currency.fieldbyname('汇率').asfloat; end; end; procedure Tfrm_ch_precost.bsSkinButton1Click(Sender: TObject); begin t_ch_precost.insert; bsSkinNotebook1.PageIndex:=1; bsSkinButton11.Caption:='返回列表'; end; procedure Tfrm_ch_precost.bsSkinButton2Click(Sender: TObject); begin table_post(t_ch_precost); end; procedure Tfrm_ch_precost.bsSkinButton4Click(Sender: TObject); begin if t_ch_precost.IsEmpty then exit; if not t_ch_fee_do_precost.IsEmpty then begin showmessage('存在费用明细,不能删除,请先删除明细数据!!'); exit; end; if (t_ch_precost.FieldByName('申请状态').asstring='生成凭证') then begin showmessage('当前业务的状态为:'+t_ch_precost.FieldByName('申请状态').asstring+'不允许修改或删除!!'); exit; end; t_ch_precost.Delete; end; procedure Tfrm_ch_precost.bsSkinButton3Click(Sender: TObject); begin table_cancel(t_ch_precost); end; procedure Tfrm_ch_precost.t_ch_precostBeforePost(DataSet: TDataSet); begin table_before_post(t_ch_precost,'客户名称'); if (t_ch_precost.state=dsinsert) and (trim(t_ch_precost.FieldByName('申请编号').AsString)='') then begin t_ch_precost['申请编号']:=get_no(date,'PC'); end; end; procedure Tfrm_ch_precost.t_ch_precostBeforeEdit(DataSet: TDataSet); begin if not modify_all then begin if (t_ch_precost.FieldByName('申请状态').asstring='生成凭证')then begin showmessage(t_ch_precost.FieldByName('申请状态').asstring+'状态不允许更改'); abort; end; end; end; procedure Tfrm_ch_precost.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin CanClose:=frm_close_query(t_ch_precost); end; procedure Tfrm_ch_precost.bsSkinButton9Click(Sender: TObject); var Pnt:Tpoint; begin Pnt:=bsSkinButton9.ClientToScreen(Point(0,bsSkinButton9.Height)); PopupMenu1.Popup(Pnt.x,Pnt.y); end; procedure Tfrm_ch_precost.bsSkinButton5Click(Sender: TObject); begin close; end; procedure Tfrm_ch_precost.N16Click(Sender: TObject); begin grid_save_xls(dxdbgrid3); end; procedure Tfrm_ch_precost.bsSkinPanel2Resize(Sender: TObject); var i:integer; begin i:=round(bsSkinPanel2.Width/10); bsSkinButton10.Width:=i; bsSkinButton9.Width:=i; bsSkinButton2.Width:=i; bsSkinButton3.Width:=i; bsSkinButton4.Width:=i; bsSkinButton1.Width:=i; bsSkinButton11.Width:=i; bsSkinButton6.Width:=i; bsSkinButton38.Width:=i; end; procedure Tfrm_ch_precost.bsSkinButton38Click(Sender: TObject); var book1:Tbookmark; begin if t_ch_precost.IsEmpty then exit; if bsSkinNotebook1.PageIndex=0 then begin book1:=t_ch_precost.GetBookmark; t_ch_precost.Requery; t_ch_precost.GotoBookmark(book1); end else begin book1:=t_ch_precost.GetBookmark; t_ch_precost.Refresh; t_ch_precost.GotoBookmark(book1); end; end; procedure Tfrm_ch_precost.DBEdit12Change(Sender: TObject); begin bsSkinButton6.Caption:='提交审核'; if t_ch_precost.State in [dsinsert] then exit; if t_ch_precost.IsEmpty then exit; if t_ch_precost.FieldByName('申请状态').AsString='提交申请' then begin bsSkinButton6.Caption:='撤销申请'; end else begin bsSkinButton6.Caption:='提交审核'; end; end; procedure Tfrm_ch_precost.bsSkinButton8Click(Sender: TObject); begin RxDBLookupCombo5.ClearValue; Edit4.text:=''; Edit2.text:=''; wwDBDateTimePicker1.Clear; wwDBDateTimePicker2.clear; RxDBLookupCombo16.ClearValue; end; procedure Tfrm_ch_precost.UpdateBillAmt; var aAdoQuery:TAdoQuery; amt:Double; begin aAdoQuery:=CreateAdoQuery; with aAdoQuery do try close; SQL.clear; sql.add('select '); sql.Add('sum(case when 币别=''RMB'' then 金额 else 0 end) as 人民币'); sql.Add(',sum(case when 币别<>''RMB'' then 金额 else 0 end) as 外币'); sql.Add('from t_ch_fee_do_precost '); sql.Add('where 工作编号=:工作编号 '); Parameters.ParamByName('工作编号').Value:=t_ch_precost.fieldbyname('申请编号').AsString; Open;First; if not IsEmpty then begin t_ch_precost.Edit; t_ch_precost.FieldByName('人民币金额').value:=FieldByName('人民币').value; t_ch_precost.FieldByName('美元金额').value:=FieldByName('外币').value; t_ch_precost.Post; end; finally Free; end; end; procedure Tfrm_ch_precost.bsSkinButton7Click(Sender: TObject); var str_fee,str_op,str_zhfee,str_zhop:widestring; Str:String; aAdoQuery:TAdoQuery; begin aAdoQuery:=CreateAdoQuery; with aAdoQuery do try memtblItems.Close; memtblItems.Open; memtblItems.EmptyTable; memtblItems.DisableControls; Close;SQL.Clear; SQL.Add('select v_op_bscard_All.编号, v_op_bscard_All.主提单号, v_op_bscard_All.委托编号, v_op_bscard_All.开船日期'); SQL.Add(',t_ch_fee.ch_id,t_ch_fee.客户名称,t_ch_fee.费用名称,t_ch_fee.汇率,t_ch_fee.币别,t_ch_fee.金额'); SQL.Add('from V_op_bscard_All'); SQL.Add('left join t_ch_fee on t_ch_fee.编号 = v_op_bscard_All.编号'); SQL.Add('where t_ch_fee.类型=''付'' and isnull(t_ch_fee.开票金额+t_ch_fee.申请开票,0)=0 and isnull(预提成本,0)=0'); if ComboBox1.ItemIndex=0 then SQL.Add(' and V_op_bscard_All.费用状态=''费用封帐'' '); if ComboBox2.ItemIndex=0 then SQL.Add(' and V_op_bscard_All.编号 in (select distinct 编号 from t_ch_fee where isnull(开票金额+申请开票,0)<>0 and 类型=''收'')') else if ComboBox2.ItemIndex=1 then begin SQL.Add(' and V_op_bscard_All.编号 in (select distinct 编号 from t_ch_fee where isnull(开票金额+申请开票,0)<>0 and 类型=''收'')'); SQL.Add(' and V_op_bscard_All.编号 in (select distinct 编号 from t_ch_fee where isnull(金额-结算金额,0)<>0 and 类型=''付'')'); end; if RxDBLookupCombo5.DisplayValues[1]<>'' then SQL.Add(' and t_ch_fee.客户名称='''+RxDBLookupCombo5.DisplayValues[1]+''''); if Edit4.text<>''then SQL.Add(' and v_op_bscard_All.委托编号 like '''+'%'+Edit4.text+'%'''); if Edit2.text<>''then SQL.Add(' and v_op_bscard_All.主提单号 like '''+'%'+Edit2.text+'%'''); if Edit16.text<>''then SQL.Add(' and (v_op_bscard_All.主提单号 like '''+'%'+Edit2.text+'%'' or 委托编号 like '''+'%'+Edit4.text+'%'' )'); if wwDBDateTimePicker1.text<>''then SQL.Add(' and v_op_bscard_All.开船日期>='''+wwDBDateTimePicker1.text+''''); if wwDBDateTimePicker2.text<>''then SQL.Add(' and v_op_bscard_All.开船日期<='''+wwDBDateTimePicker2.text+''''); if RxDBLookupCombo16.DisplayValues[1]<>'' then if wwDBComboBox42.Text<>'' then begin if wwDBComboBox42.Text='等于' then SQL.Add(' and t_ch_fee.费用名称='''+RxDBLookupCombo16.DisplayValues[1]+'''') else if wwDBComboBox42.Text='不等于' then SQL.Add(' and t_ch_fee.费用名称<>'''+RxDBLookupCombo16.DisplayValues[1]+'''') else SQL.Add(' and t_ch_fee.费用名称 like '''+'%'+RxDBLookupCombo16.DisplayValues[1]+'%'''); end; SQL.Add(' order by v_op_bscard_All.委托编号'); Open;First; while not eof do begin memtblItems.Insert; memtblItems.FieldByName('CH_ID').AsInteger:=FieldByName('CH_ID').AsInteger; memtblItems.FieldByName('选择').AsBoolean:=false; memtblItems.FieldByName('客户名称').AsString:=FieldByName('客户名称').AsString; memtblItems.FieldByName('主提单号').AsString:=FieldByName('主提单号').AsString; memtblItems.FieldByName('委托编号').AsString:=FieldByName('委托编号').AsString; memtblItems.FieldByName('费用名称').AsString:=FieldByName('费用名称').AsString; memtblItems.FieldByName('币别').AsString:=FieldByName('币别').AsString; memtblItems.FieldByName('金额').AsFloat:=s_w(2,FieldByName('金额').AsFloat); // memtblItems.FieldByName('金额').AsFloat:=s_w(2,FieldByName('金额').AsFloat/1.06); memtblItems.FieldByName('含税金额').AsFloat:=FieldByName('金额').AsFloat; memtblItems.FieldByName('汇率').AsFloat:=FieldByName('汇率').AsFloat; memtblItems.FieldByName('编号').AsString:=FieldByName('编号').AsString; memtblItems.FieldByName('开船日期').AsString:=FormatdateTime('YYYY-MM-DD',FieldByName('开船日期').AsDateTime); memtblItems.Post; Next; end; finally memtblItems.EnableControls; FreeAndNil(aAdoQuery); end; end; procedure Tfrm_ch_precost.bsSkinButton13Click(Sender: TObject); var book1:Tbookmark; aAdoQuery:TAdoQuery; begin if memtblItems.IsEmpty then exit; try book1:=memtblItems.GetBookmark; memtblItems.DisableControls; with memtblItems do begin First; while not Eof do begin Edit; memtblItems.FieldByName('选择').AsBoolean:=true; Post; Next; end; end; finally memtblItems.EnableControls; memtblItems.GotoBookmark(book1); end; end; procedure Tfrm_ch_precost.bsSkinButton14Click(Sender: TObject); var book1:Tbookmark; begin if memtblItems.IsEmpty then exit; try book1:=memtblItems.GetBookmark; memtblItems.DisableControls; with memtblItems do begin First; while not Eof do begin Edit; memtblItems.FieldByName('选择').AsBoolean:=False; Post; Next; end; end; finally memtblItems.EnableControls; memtblItems.GotoBookmark(book1); end; end; procedure Tfrm_ch_precost.bsSkinButton15Click(Sender: TObject); var aAdoQuery,bAdoQuery:TAdoQuery; begin if t_ch_precost=nil then exit; if (t_ch_precost.State=dsinsert)or(t_ch_precost.State=dsedit) then t_ch_precost.post; if memtblItems.IsEmpty then exit; if (t_ch_precost.FieldByName('申请状态').asstring='生成凭证') then begin showmessage('已经生成凭证不能加入'); exit; end; aAdoQuery:=CreateAdoQuery; with aAdoQuery do begin Close;SQL.Clear; SQL.Add('Insert into t_ch_fee_do_precost (工作编号,业务编号,CH_ID ,币别,金额 ,原始金额,类型)'); SQL.Add('values (:工作编号,:业务编号,:CH_ID ,:币别,:金额 ,:原始金额,:类型)'); end; bAdoQuery:=CreateAdoQuery; with bAdoQuery do begin Close;SQL.Clear; SQL.Add('update t_ch_fee'); SQL.Add('set 预提成本=:预提成本'); SQL.Add('where Ch_id=:ch_id'); end; try frm_main.db.BeginTrans; memtblItems.DisableControls; with memtblItems do begin First; while not Eof do begin if (FieldByName('选择').AsBoolean) and (t_ch_precost.FieldByName('客户名称').AsString=FieldByName('客户名称').AsString) then begin aAdoQuery.Close; aAdoQuery.Parameters.ParamByName('工作编号').Value:=t_ch_precost.FieldByName('申请编号').AsString; aAdoQuery.Parameters.ParamByName('业务编号').Value:=FieldByName('编号').AsString; aAdoQuery.Parameters.ParamByName('CH_ID').Value:=FieldByName('CH_ID').AsInteger; aAdoQuery.Parameters.ParamByName('币别').Value:=FieldByName('币别').AsString; aAdoQuery.Parameters.ParamByName('金额').Value:=FieldByName('金额').AsFloat; aAdoQuery.Parameters.ParamByName('原始金额').Value:=FieldByName('金额').AsFloat; aAdoQuery.Parameters.ParamByName('类型').Value:='1'; aAdoQuery.ExecSQL; bAdoQuery.Close; bAdoQuery.Parameters.ParamByName('CH_ID').Value:=FieldByName('CH_ID').AsInteger; bAdoQuery.Parameters.ParamByName('预提成本').Value:=FieldByName('金额').AsFloat; bAdoQuery.ExecSQL; end; Next; end; end; UpdateBillAmt; frm_main.db.CommitTrans; finally if frm_main.db.InTransaction then begin frm_main.db.RollbackTrans; end; memtblItems.EnableControls; FreeAndNil(aAdoQuery); FreeAndNil(bAdoQuery); t_ch_fee_do_precost.Requery; bsSkinButton7Click(Sender); end; end; procedure Tfrm_ch_precost.dxDBGrid3SelectedCountChange(Sender: TObject); var i,k:integer; DR,CR,USDDR,USDCR,NDR,NCR,NUSDDR,NUSDCR,OTDR,OTCR,NOTDR,NOTCR:Double; aFieldName:string; begin { aFieldName:='金额'; DR:=0; CR:=0; USDDR:=0; USDCR:=0; NDR:=0; NCR:=0; NUSDDR:=0; NUSDCR:=0; OTDR:=0; OTCR:=0; NOTDR:=0; NOTCR:=0; if memtblItems.IsEmpty then exit; if dxDBGrid3.SelectedCount>=1 then begin for i:=0 to dxDBGrid3.SelectedCount-1 do begin memtblItems.GotoBookmark(pointer(dxDBGrid3.selectedrows[i])); if memtblItems.FieldByName('币别').AsString='USD' then begin USDCR:=USDCR+memtblItems.fieldByName(aFieldName).AsFloat; end else begin CR:=CR+memtblItems.fieldByName(aFieldName).AsFloat; end; end; end else begin memtblItems.GotoBookmark(pointer(dxDBGrid3.selectedrows[i])); if memtblItems.FieldByName('币别').AsString='USD' then begin USDCR:=USDCR+memtblItems.fieldByName(aFieldName).AsFloat; end else begin CR:=CR+memtblItems.fieldByName(aFieldName).AsFloat; end; end; bsSkinLabel1.Caption:='已选择 USD:'+FormatFloat('#,##,0.00;-0.00',USDCR)+',RMB:'+FormatFloat('#,##,0.00;-0.00',CR); } end; procedure Tfrm_ch_precost.bsSkinButton16Click(Sender: TObject); var i:integer; aAdoQuery,bAdoQuery,cAdoQuery:TAdoQuery; begin if t_ch_fee_do_precost.IsEmpty then exit; if (t_ch_precost.FieldByName('申请状态').asstring='生成凭证') then begin showmessage('当前业务的状态为:'+t_ch_precost.FieldByName('申请状态').asstring+'不允许修改或删除!!'); exit; end; aAdoQuery:=CreateAdoQuery; with aAdoQuery do begin Close;SQL.Clear; SQL.Add('delete from t_ch_fee_do_precost'); SQL.Add('where DO_ID=:DO_ID'); end; bAdoQuery:=CreateAdoQuery; with bAdoQuery do begin Close;SQL.Clear; SQL.Add('update t_ch_fee'); SQL.Add('set 预提成本=预提成本-:预提成本'); SQL.Add('where Ch_id=:ch_id'); end; cAdoQuery:=CreateAdoQuery; with cAdoQuery do begin Close;SQL.Clear; SQL.Add('select 冲抵成本 from t_ch_fee'); SQL.Add('where Ch_id=:ch_id '); end; try frm_main.db.BeginTrans; if dxDBGrid2.SelectedCount>=1 then begin for i:=0 to dxDBGrid2.SelectedCount-1 do begin t_ch_fee_do_precost.GotoBookmark(pointer(dxDBGrid2.selectedrows[i])); cAdoQuery.Close; cAdoQuery.Parameters.ParamByName('CH_ID').Value:=t_ch_fee_do_precost.FieldByName('CH_ID').AsInteger; cAdoQuery.Open; if cAdoQuery.FieldByName('冲抵成本').AsFloat=0 then begin aAdoQuery.Close; aAdoQuery.Parameters.ParamByName('DO_ID').Value:=t_ch_fee_do_precost.FieldByName('DO_ID').AsInteger; aAdoQuery.ExecSQL; bAdoQuery.Close; bAdoQuery.Parameters.ParamByName('CH_ID').Value:=t_ch_fee_do_precost.FieldByName('CH_ID').AsInteger; bAdoQuery.Parameters.ParamByName('预提成本').Value:=t_ch_fee_do_precost.FieldByName('金额').AsFloat; bAdoQuery.ExecSQL; end else begin ShowMessage('已经冲抵成本 不能取消'); end; end; end else begin cAdoQuery.Close; cAdoQuery.Parameters.ParamByName('CH_ID').Value:=t_ch_fee_do_precost.FieldByName('CH_ID').AsInteger; cAdoQuery.Open; if cAdoQuery.FieldByName('冲抵成本').AsFloat=0 then begin aAdoQuery.Close; aAdoQuery.Parameters.ParamByName('DO_ID').Value:=t_ch_fee_do_precost.FieldByName('DO_ID').AsInteger; aAdoQuery.ExecSQL; bAdoQuery.Close; bAdoQuery.Parameters.ParamByName('CH_ID').Value:=t_ch_fee_do_precost.FieldByName('CH_ID').AsInteger; bAdoQuery.Parameters.ParamByName('预提成本').Value:=t_ch_fee_do_precost.FieldByName('金额').AsFloat; bAdoQuery.ExecSQL; end else begin ShowMessage('已经冲抵成本 不能取消'); end; end; UpdateBillAmt; frm_main.db.CommitTrans; finally if frm_main.db.InTransaction then begin frm_main.db.RollbackTrans; end; FreeAndNil(aAdoQuery); FreeAndNil(bAdoQuery); FreeAndNil(cAdoQuery); t_ch_fee_do_precost.Requery; end; end; procedure Tfrm_ch_precost.bsSkinButton17Click(Sender: TObject); begin if t_ch_precost=nil then exit; if (t_ch_precost.State=dsinsert)or(t_ch_precost.State=dsedit) then t_ch_precost.post; if t_ch_fee_do_precost.IsEmpty then exit; if (t_ch_precost.FieldByName('申请状态').asstring='生成凭证') then begin showmessage('已经生成凭证'); exit; end; NewDCVou_One; t_ch_precost.Refresh; end; procedure Tfrm_ch_precost.dxdbgrid1Column2CustomDraw(Sender: TObject; ACanvas: TCanvas; ARect: TRect; ANode: TdxTreeListNode; AColumn: TdxDBTreeListColumn; const AText: String; AFont: TFont; var AColor: TColor; ASelected, AFocused: Boolean; var ADone: Boolean); begin if (ANode.strings[dxDBGrid1Column2.Index]='录入状态') then AColor :=clwhite else if (ANode.strings[dxDBGrid1Column2.Index]='生成凭证') then AColor :=$00DDF21C; AFont.Color:=clblack; end; procedure Tfrm_ch_precost.DBEdit9Change(Sender: TObject); begin if t_ch_precost.FieldByName('申请状态').asstring='生成凭证' then DBEdit9.Color :=$00DDF21C else DBEdit9.Color :=clwhite; end; procedure Tfrm_ch_precost.dxDBGrid3CustomDraw(Sender: TObject; ACanvas: TCanvas; ARect: TRect; ANode: TdxTreeListNode; AColumn: TdxDBTreeListColumn; const AText: String; AFont: TFont; var AColor: TColor; ASelected, AFocused: Boolean; var ADone: Boolean); begin if uppercase(ANode.Strings[dxDBGrid3Column8.Index])='TRUE' then begin AColor:=clSkyBlue; exit; end; end; procedure Tfrm_ch_precost.dxDBGrid3DblClick(Sender: TObject); begin fee_view(memtblItems.fieldbyname('编号').asstring); end; end.