unit u_op_seae_sign_new_info;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, bsSkinCtrls, ExtCtrls, StdCtrls, dxExEdtr, DB, dxTL, dxDBCtrl,
dxDBGrid, dxCntner, ADODB, bsdbctrls, cxDBLabel, cxControls, cxContainer,
cxEdit, cxLabel, dxDBTLCl, dxGrClms, Mask, DBCtrlsEh, wwdblook, RxLookup,
wwdbdatetimepicker, ComCtrls, bsSkinTabs, OleCtrls, iWebPDFEditorLib_TLB,EncdDecd,ShellAPI,
Menus, kbmMemTable, bsSkinBoxCtrls, cxTextEdit, cxDBEdit, cxMaskEdit,
cxCheckBox, cxDropDownEdit, cxCalendar;
type
Tfrm__op_seae_sign_new_info = class(TForm)
bsknpnl5: TbsSkinPanel;
dxdbgrd_mx: TdxDBGrid;
dxdbgrdclmndxdbgrd2Column1: TdxDBGridColumn;
dxdbgrdclmn_mxColumn3: TdxDBGridColumn;
dxdbgrdclmn_mxColumn4: TdxDBGridColumn;
dxdbgrdclmn_mxColumn5: TdxDBGridColumn;
dxdbgrdclmn_mxColumn6: TdxDBGridColumn;
dxdbgrdchckclmndxdbgrd2Column2: TdxDBGridCheckColumn;
bsknpnl7: TbsSkinPanel;
cxlbl1: TcxLabel;
cxlbl2: TcxLabel;
cxlbl3: TcxLabel;
cxlbl4: TcxLabel;
cxlbl5: TcxLabel;
cxlbl7: TcxLabel;
cxlbl8: TcxLabel;
cxdblbl1: TcxDBLabel;
cxdblbl2: TcxDBLabel;
cxdblbl3: TcxDBLabel;
cxdblbl4: TcxDBLabel;
cxdblbl5: TcxDBLabel;
cxdblbl6: TcxDBLabel;
bsknpnl6: TbsSkinPanel;
cxlbl6: TcxLabel;
dxdbgrd1: TdxDBGrid;
dxdbgrdclmn1: TdxDBGridColumn;
dxdbgrdclmn2: TdxDBGridColumn;
dxdbgrdclmn3: TdxDBGridColumn;
dxdbgrdclmn4: TdxDBGridColumn;
dxdbgrdclmn5: TdxDBGridColumn;
bsknpnl3: TbsSkinPanel;
btn8: TbsSkinButton;
btn9_mailSend: TbsSkinButton;
btn11: TbsSkinButton;
ds1_qdtm: TDataSource;
ds2_qdtd: TDataSource;
qry2_qdtd: TADOQuery;
qry1_qdtm: TADOQuery;
btn3_custprint: TbsSkinButton;
btn9_exit: TbsSkinButton;
img1: TImage;
cxlbl19: TcxLabel;
bsknpnl8: TbsSkinPanel;
shp7: TShape;
shp6: TShape;
shpe: TShape;
shp4: TShape;
shp3: TShape;
shp2: TShape;
shp1: TShape;
bskndbtxt3: TbsSkinDBText;
bskndbtxt4: TbsSkinDBText;
bskndbtxt5: TbsSkinDBText;
bskndbtxt6: TbsSkinDBText;
cxlbl9: TcxLabel;
cxlbl10: TcxLabel;
cxlbl11: TcxLabel;
cxlbl12: TcxLabel;
cxlbl13: TcxLabel;
cxlbl14: TcxLabel;
cxlbl15: TcxLabel;
btn2_CancelSignItem: TbsSkinButton;
dxdbgrdchckclmn6: TdxDBGridCheckColumn;
pm1: TPopupMenu;
mniN1ViewCustSign: TMenuItem;
mniN2_ViewInvoceSign: TMenuItem;
kbmMemTable1: TkbmMemTable;
strngfldMemTable1Field: TStringField;
strngfldMemTable1Field3: TStringField;
strngfldMemTable1Field4: TStringField;
strngfldMemTable1Field5: TStringField;
strngfldMemTable1Field6: TStringField;
strngfldMemTable1Field7: TStringField;
strngfldMemTable1Field2: TStringField;
strngfldMemTable1Field9: TStringField;
strngfldMemTable1Field10: TStringField;
strngfldMemTable1Field11: TStringField;
strngfldMemTable1Field8: TStringField;
strngfldMemTable1Field12: TStringField;
strngfldMemTable1Field13: TStringField;
strngfldMemTable1Field15: TStringField;
strngfldMemTable1Field14: TStringField;
strngfldMemTable1Field16: TStringField;
strngfldMemTable1Field17: TStringField;
kbmMemTable1Field18: TBooleanField;
strngfldMemTable1Field19: TStringField;
kbmMemTable1RMB: TFloatField;
kbmMemTable1USD: TFloatField;
mailSend: TkbmMemTable;
strngfldSendStringField: TStringField;
strngfldSendField: TStringField;
strngfldSendField2: TStringField;
strngfldSendField3: TStringField;
strngfldSendField4: TStringField;
strngfldSendField5: TStringField;
strngfldSendField6: TStringField;
strngfldSendField7: TStringField;
cxlbl17: TcxLabel;
cxlbl18: TcxLabel;
cxdbtxtdt1: TcxDBTextEdit;
cxdbtxtdt2: TcxDBTextEdit;
shp8: TShape;
bskndbtxt1: TbsSkinDBText;
cxdbchckbx1_tf: TcxDBCheckBox;
cxlbl16_tf: TcxLabel;
cxdbdtdt1_tf: TcxDBDateEdit;
cxlbl16: TcxLabel;
cxlbl20: TcxLabel;
dxdbgrdclmndxdbgrd1Column7: TdxDBGridColumn;
cxlbl21: TcxLabel;
bskndbtxt2: TbsSkinDBText;
dxdbgrdclmndxdbgrd1Column8: TdxDBGridColumn;
dxdbgrdclmn9_usd: TdxDBGridColumn;
dxdbgrdclmn10_rmb: TdxDBGridColumn;
cxlbl22: TcxLabel;
bskndbtxt7: TbsSkinDBText;
btn3_notify: TbsSkinButton;
dxdbgrd1Column11: TdxDBGridColumn;
dxdbgrd1Column12: TdxDBGridColumn;
procedure bsSkinButton2Click(Sender: TObject);
procedure btn3_sustprint(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure btn8Click(Sender: TObject);
procedure btn11Click(Sender: TObject);
procedure btn9_mailSendClick(Sender: TObject);
procedure btn9_exitClick(Sender: TObject);
procedure btn3_notifyClick(Sender: TObject);
procedure btn2_CancelSignItemClick(Sender: TObject);
procedure btn8_confirmSignoutClick(Sender: TObject);
procedure mniN2_ViewInvoceSignClick(Sender: TObject);
procedure mniN1ViewCustSignClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormDestroy(Sender: TObject);
procedure dxdbgrd1CustomDraw(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 dxdbgrd1Column11CustomDraw(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 dxdbgrd1Column12CustomDraw(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; ANode: TdxTreeListNode; AColumn: TdxDBTreeListColumn;
const AText: String; AFont: TFont; var AColor: TColor; ASelected,
AFocused: Boolean; var ADone: Boolean);
private
{ Private declarations }
m_qdtbh:string;
m_iway:Integer;
m_newfilename:string;
m_newCWfilename:string;//财务签字
m_isNewSign:Boolean;
m_wtdw:string;//委托单位|单位名称
m_isPJ:boolean ;//是否票结
m_reportname:string;//签单条:票结通知单
function GetNotieState():Boolean;
function CheckIsAllCeckout():Boolean;
function CheckBilldue():Boolean;//检查账期
procedure signletterSateDeal();
procedure signoutSateDeal(wtdw:string);
procedure show_qdtxx (qdtbh:string;iway:Integer);
procedure UpateSeaeState(bsno,billstate:string);
function GetClientLimited(sname:string):Boolean;
public
{ Public declarations }
procedure InitialUserinfo(qdtbh:string;iway:Integer);
procedure SigninfoShow();
end;
var
frm__op_seae_sign_new_info: Tfrm__op_seae_sign_new_info;
implementation
uses my_sys_function, u_main, u_op_seae_sign_info, u_data_share;
{$R *.dfm}
///
/// 临时目录
///
function GetWinTempPath: string;
var
TempDir: array[0..255] of char;
begin
GetTempPath(255, @TempDir);
Result := strPas(TempDir);
end;
///将Bitmap位图转化为base64字符串
function BitmapToString(img:TBitmap):string ;
var
ms:TMemoryStream;
ss:TStringStream;
s:string;
begin
ms := TMemoryStream.Create;
img.SaveToStream(ms);
ss := TStringStream.Create('');
ms.Position:=0;
EncodeStream(ms,ss);//将内存流编码为base64字符流
s:=ss.DataString;
ms.Free;
ss.Free;
result:=s;
end;
function StringToBitmap(imgStr:string):TBitmap;
var ss:TStringStream;
ms:TMemoryStream;
bitmap:TBitmap;
begin
ss := TStringStream.Create(imgStr);
ms := TMemoryStream.Create;
DecodeStream(ss,ms);//将base64字符流还原为内存流
ms.Position:=0;
bitmap := TBitmap.Create;
bitmap.LoadFromStream(ms);
ss.Free;
ms.Free;
result :=bitmap;
end;
function Tfrm__op_seae_sign_new_info.CheckBilldue():Boolean;
var
FeeItems:string;
amt,usd:Double;
bh,wtdw,tdh,jflx:string;
bkmark:TBookmark;
aQuery:TADOQuery;
itfCount:Integer;//特放数量
begin
Result:=True;
wtdw:=qry1_qdtm.FieldByName('客户名称').AsString;
bkmark := qry2_qdtd.GetBookMark; //对当前记录作书签标志
qry2_qdtd.DisableControls; //切断Table与数据察觉部件的联系
qry2_qdtd.First ;
//1是否是临时账期,2特殊放单
if GetCorpNameSpecialAccount(FormatDateTime('YYYY-MM-DD',GetDbDatetime),wtdw) then
begin
aQuery:=CreateAdoQuery;
try
with aQuery do begin
close;SQL.Clear;
sql.add('select 特殊放单提醒,特殊放单条件 from t_crm_client where 客户简称='''+ wtdw +'''');
open;
if not IsEmpty then begin
if FieldByName('特殊放单提醒').AsString='是' then
begin
if MessageDlg(wtdw+'有特殊放单条件,特殊放单条件为:'+fieldbyname('特殊放单条件').AsString+#13#10+'是否继续?',mtWarning,[mbyes,mbno],0)<>mryes then
begin
Result:=false;
exit;
end
else
begin
Result:=true;
exit;
end;
end;
end;
//特殊放单数量
close;SQL.Clear;
sql.add('Select count(1) as tf_count from t_op_fangdan ');
SQL.Add('where 编号 in (select 编号 from [t_op_seae_sign_detail] where 签单条编号='''+ m_qdtbh + ''' ) ') ;
open;
if not IsEmpty then begin
itfCount:=FieldByName('tf_count').AsInteger;
if( itfCount= qry2_qdtd.Recordset.RecordCount) then
begin
//全部特放
Result:=true;
Exit;
end;
end;
end;
finally
FreeAndNil(aQuery);
end;
end;// 1 临时账期 ,2 是否全是特殊放单
//判断账期
While Not qry2_qdtd.EOF Do //对表中全部记录进行其他处理
begin
bh:= qry2_qdtd.FieldByName('编号').AsString;
tdh:=qry2_qdtd.FieldByName('主提单号').AsString;
jflx:=qry2_qdtd.FieldByName('结费类型').AsString;
if (jflx='') or (jflx='无帐期') or (jflx='现结买单') then
begin
if GetCrmsales(bh,wtdw,jflx,amt,usd,FeeItems) then
begin
//客户结费类型为票结
MessageDlg('主提单号为"'+ tdh+'"的'+wtdw+'客户结费类型为票结人民币金额为:'
+FormatFloat('0.00;0.00;0',amt) +'美元金额为:'+FormatFloat('0.00;0.00;0',USD)
+'不能生成签单条',mtWarning,[mbok],0);
Result:=False;
Break;
end ;
end
else
begin
if GetCrmsales(bh,wtdw,jflx,amt,usd,FeeItems) then
begin
MessageDlg( '主提单号为"'+ tdh+'"的'+wtdw+'客户结费类型为月结人民币金额为:'
+FormatFloat('0.00;0.00;0',amt) +'美元金额为:'+FormatFloat('0.00;0.00;0',USD)
+'不能生成签单条',mtWarning,[mbok],0);
Result:=False;
Break;
end;
end;
qry2_qdtd.Next;
end;
qry2_qdtd.GotoBookMark(bkmark);
qry2_qdtd.EnableControls; //重新定位记录指针回到原来的位置
qry2_qdtd.FreeBookMark(bkmark); //删除书签BookMark标志
end; //end CheckBilldue
procedure Tfrm__op_seae_sign_new_info.InitialUserinfo(qdtbh:string;iway:Integer);
begin
m_qdtbh:=qdtbh;
m_iway:=iway;
end;
procedure Tfrm__op_seae_sign_new_info.SigninfoShow();
begin
//
if not Assigned( frm__op_seae_sign_new_info ) then
begin
frm__op_seae_sign_new_info:= Tfrm__op_seae_sign_new_info.Create(self);
end;
frm__op_seae_sign_new_info.ShowModal();
end;
procedure Tfrm__op_seae_sign_new_info.show_qdtxx (qdtbh:string;iway:Integer);
var
qdtzht,picpath:string;
cancancel:Boolean;
begin
//
m_isNewSign:=False;
btn9_exit.visible:=false;
m_qdtbh:=qdtbh;
qry1_qdtm.Parameters.ParamByName('qdtbh').value:=qdtbh;
if (qry1_qdtm.State= dsOpening) or (qry1_qdtm.State =dsBrowse) or (qry1_qdtm.State= dsEdit) then
qry1_qdtm.Requery()
else
begin
qry1_qdtm.open;
qry1_qdtm.First;
end;
m_isPJ:=False;
m_reportname:='签单条';
dxdbgrdclmn9_usd.Visible:=false;
dxdbgrdclmn9_usd.SummaryFooterType:= cstNone;
dxdbgrdclmn10_rmb.Visible:=false;
dxdbgrdclmn10_rmb.SummaryFooterType:= cstNone;
dxdbgrd1Column11.visible:=false;
dxdbgrd1Column12.visible:=false;
if(not qry1_qdtm.Eof) then
begin
m_wtdw:= trim(qry1_qdtm.fieldbyname('客户名称').AsString);
if (qry1_qdtm.FieldByName('签单条类型').IsNull=False)
and (qry1_qdtm.FieldByName('签单条类型').AsString='票结' ) then
begin
m_isPJ:=True;
m_reportname:='票结通知单' ;
dxdbgrdclmn9_usd.Visible:=True;
dxdbgrdclmn9_usd.SummaryFooterType:= cstSum;
dxdbgrdclmn10_rmb.Visible:=True;
dxdbgrdclmn10_rmb.SummaryFooterType:= cstSum;
dxdbgrd1Column11.visible:=true;
dxdbgrd1Column12.visible:=True;
end;
end;
if (m_isPJ) then begin
qry2_qdtd.SQL.text:=StringReplace(qry2_qdtd.SQL.text,'and V_op_bscard_All.会计期间<=Getdate()-7','',[]);
end;
qry2_qdtd.Parameters.ParamByName('qdtbh').value:=qdtbh;
qry2_qdtd.Parameters.ParamByName('qdtbh2').value:=qdtbh;
if (qry2_qdtd.State = dsOpening) or (qry2_qdtd.State= dsBrowse) or (qry2_qdtd.State= dsEdit) then
qry2_qdtd.Requery()
else
begin
qry2_qdtd.open;
qry2_qdtd.First;
end;
//通知财务签出 是否可用
{
if (GetNotieState) then
begin
btn3_notify.enabled:=True
end
else
}
btn3_notify.Enabled:=false;
//取消签单是否可用
qdtzht:= qry1_qdtm.fieldbyname('状态').AsString;
btn2_CancelSignItem.Enabled:=false;
if (qdtzht='生成签单条') or (qdtzht='签出签单条') or (qdtzht='提单签出签单条') or (qdtzht='通知签出签单条') then
cancancel:=True;
//(iway<=3) 财务可取消
if (cancancel=True) then
btn2_CancelSignItem.Enabled:=True;
if(not qry1_qdtm.eof) then
begin
if m_iway=31 then
picpath :=qry1_qdtm.fieldbyname('财务签字图片').AsString
else
picpath :=qry1_qdtm.fieldbyname('客户签字图片').AsString;
picpath :=qry1_qdtm.fieldbyname('客户签字图片').AsString;
if (picpath<>'') and (FileExists(picpath)) then
begin
img1.Picture.LoadFromFile(picpath);
img1.Visible:=True;
end
else
img1.Visible:=false;
end
else
begin
img1.Visible:=false;
end;
btn9_exit.visible :=true;
//是否特放,特放超过两天将不能签字
if (not qry1_qdtm.FieldByName('是否特放').IsNull) and ( qry1_qdtm.FieldByName('是否特放').AsBoolean) then
begin
cxdbchckbx1_tf.Visible:=True;
cxlbl16_tf.Visible:=True;
cxdbdtdt1_tf.Visible:=True;
end
else
begin
cxdbchckbx1_tf.Visible:=false;
cxlbl16_tf.Visible:=false;
cxdbdtdt1_tf.Visible:=false;
end;
if(qry2_qdtd.Recordset<>nil) then
cxlbl20.Caption:= IntToStr(qry2_qdtd.Recordset.recordcount);
end;
procedure Tfrm__op_seae_sign_new_info.bsSkinButton2Click(Sender: TObject);
begin
//grid_save_xls(dxdbgrid1);
end;
///
/// 设定格式
///
procedure Tfrm__op_seae_sign_new_info.btn3_sustprint(Sender: TObject);
begin
sys_print(m_reportname,2,ds1_qdtm,ds2_qdtd,nil,nil,nil,nil,nil,nil,nil,nil,nil);
end;
///
///
///
procedure Tfrm__op_seae_sign_new_info.FormShow(Sender: TObject);
begin
Width:=width-1;
show_qdtxx(m_qdtbh,m_iway);
end;
///
/// 直接打印
///
procedure Tfrm__op_seae_sign_new_info.btn8Click(Sender: TObject);
begin
try
sys_print(m_reportname ,3,ds1_qdtm,ds2_qdtd,nil,nil,nil,nil,nil,nil,nil,nil,nil);
qry1_qdtm.Edit;
qry1_qdtm.FieldByName('打印日期').AsDateTime:=GetDbDatetime();
qry1_qdtm.Post;
except
qry1_qdtm.Cancel;
end;
end;
///
/// 打印预览
///
procedure Tfrm__op_seae_sign_new_info.btn11Click(Sender: TObject);
begin
try
sys_print(m_reportname,1,ds1_qdtm,ds2_qdtd,nil,nil,nil,nil,nil,nil,nil,nil,nil);
qry1_qdtm.Edit;
qry1_qdtm.FieldByName('打印日期').AsDateTime:=GetDbDatetime();
qry1_qdtm.Post;
except
qry1_qdtm.Cancel;
end;
end;
procedure Tfrm__op_seae_sign_new_info.btn9_mailSendClick(Sender: TObject);
var
//book1:Tbookmark;
aQuery:TADOQuery;
str:string;
strsjr:string;
begin
//1.验证是否有邮件方案
str:= ' select d.*,c.客户名称 from t_code_cust_mailproject_detail d left join t_code_cust_mailproject c'
+' on (c.方案代码=d.方案代码) where 单据类型=''签单条'' and c.客户名称='''+ m_wtdw + ''' and d.方案代码 in '
+' ( SELECT distinct 客户邮件方案 from t_op_seae where 委托单位='''+ m_wtdw + ''' and isnull(客户邮件方案,'''')<>'''' and '
+ ' 主提单号 in ( select 主提单号 from t_op_seae_sign_detail where 签单条编号='''+ m_qdtbh+ ''' ) ) ; ';
aQuery:=CreateAdoQuery();
with aQuery do begin
close;sql.Clear;
SQL.Add(str);
Open;
strsjr:='';
if not IsEmpty then
begin
//多条方案的邮件人
First;
while not eof do
begin
//
if strsjr='' then
strsjr := fieldbyname('收件人').AsString
else
strsjr := strsjr +',' +fieldbyname('收件人').AsString;
Next;
end;
First;
mailSend.EmptyTable;
mailSend.Open;
mailSend.Insert;
mailSend.FieldByName('收件人').AsString:=strsjr;//fieldbyname('收件人').AsString;
mailSend.FieldByName('邮件签名').AsString:=MailSignName;//frm_data_share.t_sys_employee.fieldbyname('邮件签名').AsString;
str:=fieldbyname('主题模板').AsString +FormatDateTime('YYYYMMDDHHMMSS',now) ;
mailsend.fieldbyname('邮件主题').AsString :=str;
str:= fieldbyname('附件名称').AsString + qry1_qdtm.Fields.fieldbyname('签单条编号').AsString;
mailSend.FieldByName('附件名称').AsString:=str;
//
if fieldbyname('邮件内容').IsNull then
str:=' '
else
str:=fieldbyname('邮件内容').AsString;
mailSend.FieldByName('邮件内容').AsString:=str;
mailSend.FieldByName('单据类型').AsString:=fieldbyname('单据类型').AsString;
mailSend.FieldByName('编号').AsString:= qry1_qdtm.Fields.fieldbyname('签单条编号').AsString;
mailSend.FieldByName('主提单号').AsString:='';//t_op_letter.DataSource.DataSet.fieldbyname('主提单号').AsString;
mailSend.Post;
try
sys_print(m_reportname,5,ds1_qdtm,ds2_qdtd,nil,nil,nil,nil,nil,nil,nil,nil,nil,true,m_wtdw,nil,nil,mailSend);
//更新状态
qry1_qdtm.Edit;
qry1_qdtm.FieldByName('邮件发送日期').AsDateTime:=GetDbDatetime();
qry1_qdtm.Post;
except
qry1_qdtm.Cancel();
end;
end
else
begin
Application.MessageBox(PChar('客户"'+ m_wtdw+ '"没有[签单条]邮件配置方案,请先配置!'),PChar('信息提示'),MB_ICONINFORMATION);
end;
end;
end;
procedure Tfrm__op_seae_sign_new_info.btn9_exitClick(Sender: TObject);
begin
close();
end;
///
/// 检查签出通知按钮状态是否可以使用
///
function Tfrm__op_seae_sign_new_info.GetNotieState():Boolean;
var
qdtzht:string;
begin
//
Result:=False;
if(not qry1_qdtm.Eof) then
begin
if(m_isPJ=false) then
begin
//月结和特殊放单都不用发送(特殊放单已直接发送通知到财务)
Exit;
end;
qdtzht:= qry1_qdtm.FieldByName('状态').AsString;
if(qdtzht='生成签单条') or (qdtzht='已打印签单条') or (qdtzht='已发送签单条') then
begin
Result:=true;
end;
end;
//判断:如果全部提单已经签出 则不用提醒,允许签字
end;
function Tfrm__op_seae_sign_new_info.CheckIsAllCeckout():Boolean;
var
aquery:TADOQuery;
qdtbh,qdtzht,sqlstr:string;
begin
Result:=False;
if(not qry1_qdtm.Eof) then
begin
qdtzht:= qry1_qdtm.FieldByName('状态').AsString;
if(qdtzht='签出签单条') then
begin
Result:=true;
end
else if(qdtzht='生成签单条') or (qdtzht='已打印签单条') or (qdtzht='已发送签单条') then
begin
//
aquery:=CreateAdoQuery();
aquery.Close;
aquery.SQL.Clear;
sqlstr:='select count(1) as fcount from ( select d.编号,s.业务状态 FROM [t_op_seae_sign_detail] d left join '
+'(select 编号,业务状态 from t_op_state where 业务状态=''提单签出'' ) s on d.编号=s.编号 where d.签单条编号 =:签单条编号)'
+' v where 业务状态 is null ';
aquery.SQL.Add(sqlstr);
aQuery.Parameters.ParamByName('签单条编号').Value:=m_qdtbh;
aQuery.open();
aQuery.first;
if (not aquery.Eof) and (aquery.FieldByName('fcount').AsInteger=0) then
begin
// 全部签出
aQuery.Close;
aQuery.SQL.Clear;
sqlstr:='update t_op_seae_sign_main set 状态=''签出签单条'',签出时间=getdate() where 签单条编号=''' + qdtbh +''' ';
aquery.SQL.Add(sqlstr);
aquery.ExecSQL();
Result:=True;
end;
end;
end;
//判断
end;
///
/// 通知签出
///
procedure Tfrm__op_seae_sign_new_info.btn3_notifyClick(Sender: TObject);
var
zht:string;
begin
//
if(GetNotieState) then
begin
zht:= qry1_qdtm.FieldByName('状态').AsString;
//
try
frm_main.db.BeginTrans;
qry1_qdtm.Edit;
qry1_qdtm.FieldByName('状态').AsString:='通知签出签单条';
qry1_qdtm.FieldByName('通知签出时间').AsDateTime:=GetDbDatetime();
frm_main.db.CommitTrans;
application.MessageBox(PChar('签单条通知已发出'),'信息提示',MB_ICONINFORMATION) ;
qry1_qdtm.Requery();
except
on ex: Exception do
begin
errorlog(ex.Message) ;
ShowMessage(ex.Message);
qry1_qdtm.Cancel;
frm_main.db.rollbacktrans;
end;
end;
end;
end;
///
/// 签字更改状态
///
procedure Tfrm__op_seae_sign_new_info.signletterSateDeal();
var
FeeItems:string;
amt,usd:Double;
tdh:string;
i:Integer;
begin
qry2_qdtd.first;
While Not qry2_qdtd.EOF Do //对表中全部记录进行其他处理
begin
begin
tdh:=qry2_qdtd.FieldByName('主提单号').AsString;
if (not GetStatus(qry2_qdtd.FieldByName('编号').AsString,'通知放单'))
and (not GetStatus(qry2_qdtd.FieldByName('编号').AsString,'提单签出'))
and (not GetStatus(qry2_qdtd.FieldByName('编号').AsString,'提单签发'))
then
begin
if GetBillStatus(qry2_qdtd.FieldByName('编号').AsString) then //特殊申请
begin
InsertSeaeStatus(qry2_qdtd.FieldByName('编号').AsString,'通知放单',employee,FormatDateTime('YYYY-MM-DD',Now));
if (not GetStatus(qry2_qdtd.FieldByName('编号').AsString,'提单签出'))
and (not GetStatus(qry2_qdtd.FieldByName('编号').AsString,'提单签发'))
then
UpdateMblStatus(qry2_qdtd.FieldByName('编号').AsString,'通知放单');
end
else
if GetCorpNameSpecialAccount(FormatDateTime('YYYY-MM-DD',GetDbDatetime),qry1_qdtm.FieldByName('客户名称').AsString) then
begin
if MessageDlg(m_wtdw+' 临时帐期没有过期'+#13#10+'确实要放单吗?',mtWarning,[mbyes,mbno],0)=mryes then
begin
InsertSeaeStatus(qry2_qdtd.FieldByName('编号').AsString,'通知放单',employee,FormatDateTime('YYYY-MM-DD',Now));
if (not GetStatus(qry2_qdtd.FieldByName('编号').AsString,'提单签出'))
and (not GetStatus(qry2_qdtd.FieldByName('编号').AsString,'提单签发'))
then
UpdateMblStatus(qry2_qdtd.FieldByName('编号').AsString,'通知放单');
end;
end
else
begin
if (Trim(qry2_qdtd.FieldByName('结费类型').AsString)='') or (Trim(qry2_qdtd.FieldByName('结费类型').AsString)='无帐期') or (Trim(qry2_qdtd.FieldByName('结费类型').AsString)='现结买单') or (qry2_qdtd.FieldByName('结费类型').IsNull) then
begin
if GetCrmsales(qry2_qdtd.FieldByName('编号').AsString
,m_wtdw,qry2_qdtd.FieldByName('结费类型').AsString,amt,usd,FeeItems) then
begin
//客户结费类型为票结
if MessageDlg('客户结费类型为票结人民币金额为:'+FormatFloat('0.00;0.00;0',amt) +'美元金额为:'+FormatFloat('0.00;0.00;0',USD) +'不能放单'+#13#10+'请选择其他放单模式:'+#13#10+'1.是否有跨月负数更改单'+#13#10+'2.查账放单'+#13#10+'3.到账本放单'+#13#10+'4.特殊放单',mtWarning,[mbno],0)=mryes then
begin
InsertSeaeStatus(qry2_qdtd.FieldByName('编号').AsString,'通知放单',employee,FormatDateTime('YYYY-MM-DD',Now));
if (not GetStatus(qry2_qdtd.FieldByName('编号').AsString,'提单签出'))
and (not GetStatus(qry2_qdtd.FieldByName('编号').AsString,'提单签发'))
then
UpdateMblStatus(qry2_qdtd.FieldByName('编号').AsString,'通知放单');
end;
end
else
begin
InsertSeaeStatus(qry2_qdtd.FieldByName('编号').AsString,'通知放单',employee,FormatDateTime('YYYY-MM-DD',Now));
if (not GetStatus(qry2_qdtd.FieldByName('编号').AsString,'提单签出'))
and (not GetStatus(qry2_qdtd.FieldByName('编号').AsString,'提单签发'))
then
UpdateMblStatus(qry2_qdtd.FieldByName('编号').AsString,'通知放单');
end;
end
else
begin
if GetCrmsales(qry2_qdtd.FieldByName('编号').AsString,m_wtdw
,qry2_qdtd.FieldByName('结费类型').AsString,amt,usd,FeeItems) then
begin
if MessageDlg('客户结费类型为月结人民币金额为:'+FormatFloat('0.00;0.00;0',amt) +'美元金额为:'+FormatFloat('0.00;0.00;0',USD) +'不能放单'+#13#10+'请选择其他放单模式:'+#13#10+'1.是否有跨月负数更改单'+#13#10+'2.查账放单'+#13#10+'3.到账本放单'+#13#10+'4.特殊放单',mtWarning,[mbno],0)=mryes then
begin
InsertSeaeStatus(qry2_qdtd.FieldByName('编号').AsString,'通知放单',employee,FormatDateTime('YYYY-MM-DD',Now));
if (not GetStatus(qry2_qdtd.FieldByName('编号').AsString,'提单签出'))
and (not GetStatus(qry2_qdtd.FieldByName('编号').AsString,'提单签发'))
then
UpdateMblStatus(qry2_qdtd.FieldByName('编号').AsString,'通知放单');
end;
end
else
begin
InsertSeaeStatus(qry2_qdtd.FieldByName('编号').AsString,'通知放单',employee,FormatDateTime('YYYY-MM-DD',Now));
if (not GetStatus(qry2_qdtd.FieldByName('编号').AsString,'提单签出'))
and (not GetStatus(qry2_qdtd.FieldByName('编号').AsString,'提单签发')) then
UpdateMblStatus(qry2_qdtd.FieldByName('编号').AsString,'通知放单');
end;
end;
end;
end
else
begin
Application.MessageBox(pchar(tdh+ '已经通知放单或提单签出'),PChar('信息提示'),MB_ICONINFORMATION);
end;
end;
qry2_qdtd.Next;
end;
end;
///
/// 签出更改状态
///
procedure Tfrm__op_seae_sign_new_info.signoutSateDeal(wtdw:string);
var
FeeItems,reasons,JobAmt:string;
amt,usd:Double;
tdh:string; //主提单号
bh:string;// 编号
jflx:string;//结费类型
i:Integer;
aAdoQuery:TAdoQuery;
begin
qry2_qdtd.first;
While Not qry2_qdtd.EOF Do //对表中全部记录进行其他处理
begin
tdh:=qry2_qdtd.FieldByName('主提单号').AsString;
bh :=qry2_qdtd.FieldByName('编号').AsString;
jflx:= qry2_qdtd.FieldByName('结费类型').AsString;
//
if GetCorpNameSpecialAccount(FormatDateTime('YYYY-MM-DD',GetDbDatetime),wtdw) then
begin
//
if MessageDlg(wtdw +' 临时帐期没有过期'+#13#10+'确实要放单吗?',mtWarning,[mbyes,mbno],0)=mryes then
begin
reasons:=trim(InputBox('原因', '原因', '当天入帐'));
if reasons=''then
begin
showmessage('原因不能为空!!');
exit;
end;
InsertSeaeStatus(bh,'提单签出',employee,FormatDateTime('YYYY-MM-DD hh:mm:ss',Now),reasons);
InsertSeaeStatus(bh,'通知放单',employee,FormatDateTime('YYYY-MM-DD',Now));
UpateSeaeState(bh,'提单签出');
end;
//
end
else
begin
//**b
if not GetStatus(bh,'提单签出') then
begin
if GetBillStatusCount(bh) then
begin
if GetCrmOP(employee,m_wtdw,'正本') then //免签客户
begin
reasons:=trim(InputBox('原因', '原因', '当天入帐'));
if reasons=''then
begin
showmessage('原因不能为空!!');
exit;
end;
InsertSeaeStatus(bh,'提单签出',employee,FormatDateTime('YYYY-MM-DD hh:mm:ss',Now),reasons);
InsertSeaeStatus(bh,'通知放单',employee,FormatDateTime('YYYY-MM-DD',Now));
UpateSeaeState(bh,'提单签出');
end
else
if (jflx='') or (jflx='无帐期') or (jflx='现结买单') or (qry2_qdtd.FieldByName('结费类型').IsNull) then
begin
if GetCrmsales(bh,m_wtdw
,jflx,amt,usd,FeeItems) then
begin
JobAmt:=GetCrmpjAmt(bh);
if MessageDlg('客户结费类型为票结'#13#10'本票金额为:'+JobAmt+#13#10+'超期 人民币金额为:'+FormatFloat('0.00;-0.00;0',amt) +'美元金额为:'+FormatFloat('0.00;-0.00;0',USD) +'确实要放单吗?',mtWarning,[mbyes,mbno],0)=mryes then
begin
reasons:=trim(InputBox('原因', '原因', '当天入帐'));
if reasons=''then
begin
showmessage('原因不能为空!!');
exit;
end;
InsertSeaeStatus(bh,'提单签出',employee,FormatDateTime('YYYY-MM-DD hh:mm:ss',Now),reasons);
InsertSeaeStatus(bh,'通知放单',employee,FormatDateTime('YYYY-MM-DD',Now));
UpateSeaeState(bh,'提单签出');
end;
end
else
begin
JobAmt:=GetCrmpjAmt(bh);
if trim(JobAmt)<>'' then
begin
if MessageDlg('客户结费类型为票结'#13#10'本票金额为:'+JobAmt +'确实要放单吗?',mtWarning,[mbyes,mbno],0)=mryes then
begin
reasons:=trim(InputBox('原因', '原因', '当天入帐'));
if reasons=''then
begin
showmessage('原因不能为空!!');
exit;
end;
InsertSeaeStatus(bh,'通知放单',employee,FormatDateTime('YYYY-MM-DD',Now));
InsertSeaeStatus(bh,'提单签出',employee,FormatDateTime('YYYY-MM-DD hh:mm:ss',Now));
UpateSeaeState(bh,'提单签出');
end;
end
else
begin
InsertSeaeStatus(bh,'通知放单',employee,FormatDateTime('YYYY-MM-DD',Now));
InsertSeaeStatus(bh,'提单签出',employee,FormatDateTime('YYYY-MM-DD hh:mm:ss',Now));
UpateSeaeState(bh,'提单签出');
end;
end;
end
else
if (jflx='约定时间') or (jflx='约定天数') then
begin
if GetClientLimited(wtdw) then
begin
ShowMessage('月结协议已经过期,不能放单,系统自动调整为票结,请重新检索');
aAdoQuery:=CreateAdoQuery;
with aAdoQuery do
try
Close;SQL.Clear;
SQL.Add('Update t_op_seae set 结费类型=''现结买单''');
SQL.Add('where 编号='+''''+bh+'''');
ExecSQL;
finally
Free;
end;
end
else
begin //
if GetCrmsales(bh,m_wtdw
,jflx,amt,usd,FeeItems) then
begin
if MessageDlg('客户结费类型为月结'+#13#10+'人民币金额为:'+FormatFloat('0.00;-0.00;0',amt) +'美元金额为:'+FormatFloat('0.00;-0.00;0',USD)+#13#10+#13#10+'确实要放单吗?',mtWarning,[mbyes,mbno],0)=mryes then
// if MessageDlg('客户结费类型为月结'+#13#10+'人民币金额为:'+FormatFloat('0.00;-0.00;0',amt) +'美元金额为:'+FormatFloat('0.00;-0.00;0',USD)+#13#10+FeeItems+#13#10+'确实要放单吗?',mtWarning,[mbyes,mbno],0)=mryes then
begin
reasons:=trim(InputBox('原因', '原因', '当天入帐'));
if reasons=''then
begin
showmessage('原因不能为空!!');
exit;
end;
InsertSeaeStatus(bh,'通知放单',employee,FormatDateTime('YYYY-MM-DD',Now),reasons);
InsertSeaeStatus(bh,'提单签出',employee,FormatDateTime('YYYY-MM-DD hh:mm:ss',Now));
UpateSeaeState(bh,'提单签出');
end;
end
else
begin
InsertSeaeStatus(bh,'通知放单',employee,FormatDateTime('YYYY-MM-DD',Now));
InsertSeaeStatus(bh,'提单签出',employee,FormatDateTime('YYYY-MM-DD hh:mm:ss',Now));
UpateSeaeState(bh,'提单签出');
end;
end;
end;
end
else //存在特殊申请
begin
if GetBillStatus(bh) then //特殊申请
begin
if (jflx='') or (jflx='无帐期') or (jflx='现结买单') or (qry2_qdtd.FieldByName('结费类型').IsNull) then
begin
if GetCrmsales(bh,kbmMemTable1.FieldByName('委托单位').AsString
,jflx,amt,usd,FeeItems) then
begin
JobAmt:=GetCrmpjAmt(bh);
if MessageDlg('客户结费类型为票结'#13#10'本票金额为:'+JobAmt+#13#10+'超期 人民币金额为:'+FormatFloat('0.00;-0.00;0',amt) +'美元金额为:'+FormatFloat('0.00;-0.00;0',USD) +'确实要放单吗?',mtWarning,[mbyes,mbno],0)=mryes then
begin
reasons:='';
InsertSeaeStatus(bh,'提单签出',employee,FormatDateTime('YYYY-MM-DD hh:mm:ss',Now),reasons);
InsertSeaeStatus(bh,'通知放单',employee,FormatDateTime('YYYY-MM-DD',Now));
UpateSeaeState(bh,'提单签出');
end;
end
else
begin
InsertSeaeStatus(bh,'提单签出',employee,FormatDateTime('YYYY-MM-DD hh:mm:ss',Now));
InsertSeaeStatus(bh,'通知放单',employee,FormatDateTime('YYYY-MM-DD',Now));
UpateSeaeState(bh,'提单签出');
end;
end
else
begin
if GetClientLimited(kbmMemTable1.FieldByName('委托单位').AsString) then
begin
ShowMessage('月结协议已经过期,不能放单,系统自动调整为票结,请重新检索');
aAdoQuery:=CreateAdoQuery;
with aAdoQuery do
try
Close;SQL.Clear;
SQL.Add('Update t_op_seae set 结费类型=''现结买单''');
SQL.Add('where 编号='+''''+bh+'''');
ExecSQL;
finally
Free;
end;
end;
if GetCrmsales(bh,kbmMemTable1.FieldByName('委托单位').AsString
,jflx,amt,usd,FeeItems) then
begin
if MessageDlg('客户结费类型为月结'+#13#10+'人民币金额为:'+FormatFloat('0.00;-0.00;0',amt) +'美元金额为:'+FormatFloat('0.00;-0.00;0',USD)+#13#10+'确实要放单吗?',mtWarning,[mbyes,mbno],0)=mryes then
begin
reasons:='';
InsertSeaeStatus(bh,'提单签出',employee,FormatDateTime('YYYY-MM-DD hh:mm:ss',Now),reasons);
InsertSeaeStatus(bh,'通知放单',employee,FormatDateTime('YYYY-MM-DD',Now));
UpateSeaeState(bh,'提单签出');
end;
end
else
begin
InsertSeaeStatus(bh,'提单签出',employee,FormatDateTime('YYYY-MM-DD hh:mm:ss',Now));
InsertSeaeStatus(bh,'通知放单',employee,FormatDateTime('YYYY-MM-DD',Now));
UpateSeaeState(bh,'提单签出');
end;
end;
end
else
begin
ShowMessage('特殊申请主管没有审核通过,不能签出');
end;
end;
//**e
end;
end;
//
qry2_qdtd.Next;
end;
end;
procedure Tfrm__op_seae_sign_new_info.btn2_CancelSignItemClick(Sender: TObject);
var
i,iret:Integer;
isSelectAll :Boolean;
strxh,strinfo,strsql:string;
reasons:string;//原因
begin
//状态是未签出的 用户没有签字的
if dxdbgrd1.SelectedCount<1 then
begin
Application.MessageBox(PChar('请选择要取消的提单!'),'信息提示',MB_ICONINFORMATION) ;
Exit;
end;
//begin check
isSelectAll:=False;
if(dxdbgrd1.Count =dxdbgrd1.SelectedCount) then
begin
strinfo:='取消全部签单签单条将会作废,是否继续?';
isSelectAll:=true;
end
else
strinfo:='有' + IntToStr(dxdbgrd1.SelectedCount) +'条提单将被取消,是否继续?' ;
iret:= application.MessageBox(pchar(strinfo),PChar('信息提示'),MB_YESNO or MB_ICONQUESTION );
if iret <> ID_YES then
Exit;
reasons:=trim(InputBox('原因', '请输入取消原因', ''));
if reasons=''then
begin
showmessage('原因不能为空!!');
exit;
end;
reasons:=StringReplace(reasons,'''','''''',[rfReplaceAll]);
if( isSelectAll) then
begin
//增加取消签单日志 程建波 2017-08-04
strsql:= 'INSERT INTO [dbo].[t_op_seae_sign_cancel_log] '
+' ([签单条编号],[编号],[主提单号],[取消原因],[取消人],[取消日期]) '
+'SELECT [签单条编号],[编号],[主提单号],'''+reasons +''' as 取消原因,'''+employee+''' as 取消人, getdate() as [取消日期] '
+' FROM [t_op_seae_sign_detail] where 签单条编号='''+ m_qdtbh + ''''
+ ' delete from [t_op_state] where 业务状态=''生成签单条'' and 编号 '
+' in ( select 编号 from [t_op_seae_sign_detail] where 签单条编号='''+ m_qdtbh + ''');' +#13#10
+'delete from [t_op_seae_sign_detail] where 签单条编号='''+ m_qdtbh + ''';' +#13#10
+ 'update [t_op_seae_sign_main] set 状态=''已作废'' where 签单条编号='''+ m_qdtbh + ''';';
try
frm_main.db.BeginTrans;
frm_main.db.Execute(strsql) ;
frm_main.db.CommitTrans;
Application.MessageBox(PChar('所有签单已经取消,此签单已作废,按"确定"关闭窗口!'),'信息提示',MB_ICONINFORMATION) ;
close();
except
on E: Exception do
begin
//
ShowMessage(E.Message);
frm_main.db.RollbackTrans;
end;
end;
end
else
begin
strxh:='''-123';
for i:=0 to dxdbgrd1.SelectedCount-1 do
begin//
qry2_qdtd.GoTobookmark(pointer(dxdbgrd1.SelectedRows[i]));
strxh := strxh +''',''' + qry2_qdtd.FieldByName('编号').AsString;
end;
strxh := strxh +'''';
try
//增加取消签单日志 程建波 2017-08-04
strsql:= 'INSERT INTO [dbo].[t_op_seae_sign_cancel_log] '
+' ([签单条编号],[编号],[主提单号],[取消原因],[取消人],[取消日期]) '
+'SELECT [签单条编号],[编号],[主提单号],'''+reasons +''' as 取消原因,'''+employee+''' as 取消人, getdate() as [取消日期] '
+' FROM [t_op_seae_sign_detail] where 签单条编号='''+ m_qdtbh + ''''
+ ' delete from [t_op_state] where 业务状态=''生成签单条'' and 编号 '
+' in ('+strxh + ');' +#13#10
+ ' delete from [t_op_state] where 业务状态=''生成签单条'' and 编号 in (' +strxh+ ');'
+' delete from [t_op_seae_sign_detail] where 编号 in ('+strxh + ');';
frm_main.db.BeginTrans;
frm_main.db.Execute(strsql) ;
frm_main.db.CommitTrans;
qry2_qdtd.Requery();
if(qry2_qdtd.Recordset<>nil) then
cxlbl20.Caption:= IntToStr(qry2_qdtd.Recordset.recordcount);
except
on E: Exception do
begin
frm_main.db.RollbackTrans;
ShowMessage(E.Message);
end;
end;
end;
end;
procedure Tfrm__op_seae_sign_new_info.UpateSeaeState(bsno,billstate:string);
var aAdoQuery:TAdoQuery;
begin
aAdoQuery:=CreateAdoQuery;
with aAdoQuery do
try
Close;SQL.Clear;
SQL.Add('Update t_op_Seae');
SQL.Add('set 提单签发状态=:billstate ,签回日期=:签回日期 where 编号=:bsNo');
Parameters.ParamByName('bsNo').value:=bsno;
Parameters.ParamByName('billstate').value:=billstate;
Parameters.ParamByName('签回日期').value:=GetDbDatetime();;
execsql;
finally
aAdoQuery.Free;
end;
end;
function Tfrm__op_seae_sign_new_info.GetClientLimited(sname:string):Boolean;
var AAdoQuery:TAdoQuery;
begin
Result:=False;
AAdoQuery:=CreateAdoQuery;
with AAdoQuery do
try
Close;SQL.Clear;
SQL.Add('Select 结束日期 from t_crm_client_sales');
SQL.Add('where 客户简称=:SName and 结费类型 in (''约定时间'',''约定天数'')');
Parameters.ParamByName('SName').Value:=SName;
Open;First;
if not IsEmpty then
begin
if FieldByName('结束日期').Value