Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit TransferenciaDadosServer;
- interface
- uses System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- system.UITypes, Vcl.Controls, Vcl.Dialogs, Data.DB, Vcl.Grids,
- Vcl.Samples.Gauges, TypInfo, Midaslib, StrUtils, Vcl.ExtCtrls, acImage,
- Vcl.StdCtrls, Vcl.ComCtrls, Vcl.WinXCtrls, Vcl.DBCGrids,
- // Firedac
- FireDAC.Phys.FBDef,
- FireDAC.UI.Intf,
- FireDAC.VCLUI.Wait,
- FireDAC.Comp.UI,
- FireDAC.Stan.Intf,
- FireDAC.Phys,
- FireDAC.Phys.IBBase,
- FireDAC.Phys.FB,
- FireDAC.Stan.Option,
- FireDAC.Stan.Param,
- FireDAC.Stan.Error,
- FireDAC.DatS,
- FireDAC.Phys.Intf,
- FireDAC.DApt.Intf,
- FireDAC.Stan.Async,
- FireDAC.DApt,
- FireDAC.Stan.Def,
- FireDAC.Stan.Pool,
- FireDAC.Comp.Client,
- FireDAC.Comp.DataSet;
- type TSendMovToServer = class( TComponent )
- type TCaixa = class( TFDQuery )
- strict private
- FNumerodoSat: string;
- FDataAberturaCaixa: TDate;
- FHoraAberturaCaixa: TTime;
- FOperador : String;
- public
- property NumerodoSat: string read FNumerodoSat write FNumerodoSat;
- property DatadeAberturacaixa: TDate read FDataAberturaCaixa write FDataAberturaCaixa;
- property HoradeAberturaCaixa: TTime read FHoraAberturaCaixa write FHoraAberturaCaixa;
- procedure AfterConstruction; override;
- procedure BeforeDestruction; override;
- constructor Create(AOwner: TComponent); override;
- end;
- Type TTabelaVendas = class( TFDQuery )
- type TAposTranferirMovimentacao = procedure of Object;
- type TServerCon = class( TFDQuery )
- public
- procedure AfterConstruction; override;
- procedure BeforeDestruction; override;
- constructor Create(AOwner: TComponent); override;
- end;
- strict private
- FTServerCon: TServerCon;
- FvGauge: TGauge;
- FvRich: TRichEdit;
- FTAposTranferirMovimentacao: TAposTranferirMovimentacao;
- public
- property AposTransferirVendas: TAposTranferirMovimentacao read FTAposTranferirMovimentacao write FTAposTranferirMovimentacao;
- procedure AfterConstruction; override;
- procedure BeforeDestruction; override;
- procedure Executecarga;
- constructor Create(AOwner: TComponent; aRich: TRichEdit; aGauge: TGauge); reintroduce; overload;
- end;
- type TTabelaItensVenda = class( TFDQuery )
- type TAposTranferirMovimentacao = procedure of Object;
- type TServerCon = class( TFDQuery )
- public
- procedure AfterConstruction; override;
- procedure BeforeDestruction; override;
- constructor Create(AOwner: TComponent); override;
- end;
- strict private
- FTServerCon: TServerCon;
- FvGauge: TGauge;
- FvRich: TRichEdit;
- FTAposTranferirMovimentacao: TAposTranferirMovimentacao;
- public
- property AposTransferirItens: TAposTranferirMovimentacao read FTAposTranferirMovimentacao write FTAposTranferirMovimentacao;
- procedure AfterConstruction; override;
- procedure BeforeDestruction; override;
- procedure Executecarga;
- constructor Create(AOwner: TComponent; aRich: TRichEdit; aGauge: TGauge); reintroduce; overload;
- end;
- Type TFinalizadorasVenda = class( TFDQuery )
- type TAposTranferirMovimentacao = procedure of Object;
- type TServerCon = class( TFDQuery )
- public
- procedure AfterConstruction; override;
- procedure BeforeDestruction; override;
- constructor Create(AOwner: TComponent); override;
- end;
- strict private
- FTServerCon: TServerCon;
- FvGauge: TGauge;
- FvRich: TRichEdit;
- FTAposTranferirMovimentacao: TAposTranferirMovimentacao;
- public
- property AposTransferirFinalizadoras: TAposTranferirMovimentacao read FTAposTranferirMovimentacao write FTAposTranferirMovimentacao;
- procedure AfterConstruction; override;
- procedure BeforeDestruction; override;
- procedure Executecarga;
- constructor Create(AOwner: TComponent; aRich: TRichEdit; aGauge: TGauge); reintroduce; overload;
- end;
- Type TmovXmlTransform = class( TFDQuery )
- type TAposTranferirMovimentacao = procedure of Object;
- type TServerCon = class( TFDQuery )
- public
- procedure AfterConstruction; override;
- procedure BeforeDestruction; override;
- constructor Create(AOwner: TComponent); override;
- end;
- strict private
- FTServerCon: TServerCon;
- FvGauge: TGauge;
- FvRich: TRichEdit;
- FTAposTranferirMovimentacao: TAposTranferirMovimentacao;
- public
- property AposTransferirMovXml: TAposTranferirMovimentacao read FTAposTranferirMovimentacao write FTAposTranferirMovimentacao;
- procedure AfterConstruction; override;
- procedure BeforeDestruction; override;
- procedure Executecarga;
- constructor Create(AOwner: TComponent; aRich: TRichEdit; aGauge: TGauge); reintroduce; overload;
- end;
- private
- FGauge: TGauge;
- FRich: TRichEdit;
- FTransfereRecursivo: Boolean;
- procedure LimpaMovimentacao;
- public
- property TransfereRecursivo: Boolean read FTransfereRecursivo write FTransfereRecursivo;
- procedure StartVendasToServer;
- procedure TransfereCargatoservernoTh;
- procedure AfterConstruction; override;
- procedure BeforeDestruction; override;
- procedure AposTransferirVendas;
- procedure AposTransferirItens;
- procedure AposTransferirFinalizadoras;
- procedure AposTransferirXmls;
- procedure BeforeExecuteVendas( Dataset: TFDDataset );
- procedure AfterExecuteVendas( Dataset: TFDDataset );
- procedure OnTerminated( Sender: TObject );
- constructor Create( AOwner: TComponent; Gauge: TGauge; aRich: TRichEdit ); reintroduce; Overload;
- end;
- implementation
- { TSendMovToServer }
- uses DtmConexao, FuncoesLibraryClass;
- procedure TSendMovToServer.AfterConstruction;
- begin
- inherited AfterConstruction;
- end;
- procedure TSendMovToServer.AfterExecuteVendas(Dataset: TFDDataset);
- begin
- end;
- procedure TSendMovToServer.AposTransferirFinalizadoras;
- var FXml: TmovXmlTransform; th : TThread;
- begin
- th := TThread.CreateAnonymousThread( procedure
- begin
- FXml:= TmovXmlTransform.Create(nil,FRich,FGauge);
- FXml.AposTransferirMovXml := AposTransferirXmls;
- try
- Fxml.Executecarga;
- finally
- Fxml.FreeOnRelease;
- Fxml:= nil;
- end;
- end);
- Th.Start;
- end;
- procedure TSendMovToServer.AposTransferirItens;
- var FTabelaFin: TFinalizadorasVenda; th : TThread;
- begin
- th := TThread.CreateAnonymousThread( procedure
- begin
- FTabelaFin:= TFinalizadorasVenda.Create(nil,FRich,FGauge);
- FTabelaFin.AposTransferirFinalizadoras := AposTransferirFinalizadoras;
- try
- FTabelaFin.Executecarga;
- finally
- FTabelaFin.FreeOnRelease;
- FTabelaFin:= nil;
- end;
- end);
- Th.Start;
- end;
- procedure TSendMovToServer.AposTransferirVendas;
- var FTabelaItens: TTabelaItensVenda; th : TThread;
- begin
- th := TThread.CreateAnonymousThread( procedure
- begin
- FTabelaItens:= TTabelaItensVenda.Create(nil,FRich,FGauge);
- FTabelaItens.AposTransferirItens := AposTransferirItens;
- try
- FTabelaItens.Executecarga;
- finally
- FTabelaItens.FreeOnRelease;
- FTabelaItens:= nil;
- end;
- end);
- Th.Start;
- end;
- procedure TSendMovToServer.AposTransferirXmls;
- begin
- TDtmConexao.FDMasterPdv.ExecSQL('Delete from XMLTRANSFORM_TRANSF ');
- TDtmConexao.FDMasterPdv.ExecSQL('Delete from VENDA_TRANSF ');
- TDtmConexao.FDMasterPdv.ExecSQL('Delete from ITENS_TRANSF ');
- TDtmConexao.FDMasterPdv.ExecSQL('Delete from FINALIZADORA_TRANSF ');
- end;
- procedure TSendMovToServer.BeforeDestruction;
- begin
- inherited BeforeDestruction;
- end;
- procedure TSendMovToServer.BeforeExecuteVendas(Dataset: TFDDataset);
- begin
- end;
- constructor TSendMovToServer.Create( AOwner: TComponent; Gauge: TGauge; aRich: TRichEdit );
- begin
- inherited Create(AOwner);
- FGauge:= Gauge;
- FRich:= aRich;
- end;
- procedure TSendMovToServer.LimpaMovimentacao;
- begin
- end;
- procedure TSendMovToServer.OnTerminated(Sender: TObject);
- begin
- end;
- procedure TSendMovToServer.StartVendasToServer;
- var FTTabelaVendas: TTabelaVendas; th : TThread;
- begin
- th := TThread.CreateAnonymousThread( procedure
- begin
- FTTabelaVendas:= TTabelaVendas.Create(nil,FRich,FGauge);
- FTTabelaVendas.AposTransferirVendas := AposTransferirVendas;
- FTTabelaVendas.BeforeExecute := BeforeExecuteVendas;
- FTTabelaVendas.AfterExecute := AfterExecuteVendas;
- try
- FTTabelaVendas.Executecarga;
- finally
- FTTabelaVendas.FreeOnRelease;
- FTTabelaVendas:= nil;
- end;
- end);
- Th.Start;
- th.OnTerminate := OnTerminated;
- end;
- procedure TSendMovToServer.TransfereCargatoservernoTh;
- var FTTabelaVendas: TTabelaVendas;
- begin
- FTTabelaVendas:= TTabelaVendas.Create(nil,FRich,FGauge);
- FTTabelaVendas.AposTransferirVendas := AposTransferirVendas;
- try
- FTTabelaVendas.Executecarga;
- finally
- FTTabelaVendas.Free;
- FTTabelaVendas:= nil;
- end;
- end;
- { TSendMovToServer.TTabelaVendas }
- procedure TSendMovToServer.TTabelaVendas.AfterConstruction;
- begin
- inherited AfterConstruction;
- end;
- procedure TSendMovToServer.TTabelaVendas.BeforeDestruction;
- begin
- inherited BeforeDestruction;
- end;
- constructor TSendMovToServer.TTabelaVendas.Create(AOwner: TComponent; aRich: TRichEdit; aGauge: TGauge);
- begin
- inherited Create(AOwner);
- FvRich := aRich;
- FvGauge := aGauge;
- Connection := DtmConexao.TDtmConexao.FDMasterPdv;
- end;
- procedure TSendMovToServer.TTabelaVendas.Executecarga;
- var Wait:TFDGUIxWaitCursor; Dlg: TFDGUIxAsyncExecuteDialog;
- iNumInserts: Integer; aCaixa: Tcaixa; I: INteger;
- begin
- aCaixa:= Tcaixa.Create(nil);
- wait := TFDGUIxWaitCursor.Create(nil);
- wait.ScreenCursor:= gcrAppWait;
- dlg:= TFDGUIxAsyncExecuteDialog.Create(nil);
- sql.Text :=
- 'select '+
- 'DATA, '+
- 'HORA, '+
- 'USUARIO, '+
- 'FOTOUSER, '+
- 'CAIXA_NUMERO, '+
- 'CAIXA_DATA, '+
- 'CAIXA_HORA, '+
- 'CAIXA_PERIODO, '+
- 'VENDA_NITENS, '+
- 'VENDA_ECFNUMERO, '+
- 'VENDA_ECFSERIAL, '+
- 'VENDA_ECFMARCA, '+
- 'VENDA_ECFMODELO, '+
- 'VENDA_ECFNCOO, '+
- 'VENDA_ECFNCCF, '+
- 'VENDA_VALORTOTAL, '+
- 'VENDA_DESCONTOS, '+
- 'VENDA_VALORVENDA, '+
- 'VENDA_CPFCNPJ, '+
- 'VENDA_NOMECLIENTE, '+
- 'VENDA_ENDERECO, '+
- 'VENDA_NUMERO, '+
- 'VENDA_COMPLEMENTO, '+
- 'VENDA_BAIRRO, '+
- 'VENDA_MUNICIPIO, '+
- 'VENDA_ESTADO, '+
- 'VENDA_UF, '+
- 'VENDA_CEP, '+
- 'VENDA_TEL, '+
- 'VENDA_EMAIL, '+
- 'VENDANFP_CPF, '+
- 'VENDANFP_NOMECLI, '+
- 'SISTEMA_STATUS, '+
- 'VENDA_SITUACAO, '+
- 'SAT_SITEMISS, '+
- 'SAT_EMISSDATA, '+
- 'SAT_EMISSHORA, '+
- 'CAIXA_ID, '+
- 'SAT_NUMDOCFIS, '+
- 'SAT_CHAVEEMISS, '+
- 'SAT_XML, '+
- 'TRANSM_BOOL, '+
- 'DAV_MEMO, '+
- 'DAV_EXTORNOMEMO, '+
- 'SAT_NUMSERIESAT, '+
- 'VENDA_ACRESCIMOS, '+
- 'TROCO, '+
- 'VENDEDOR_ID, '+
- 'VALOR_TXSERVICOS, '+
- 'PERCENTUAL_TXSERVICOS '+
- 'from VENDA_TRANSF ORDER BY ID ';
- open;
- Last;
- iNumInserts:= RecordCount;
- FvGauge.MaxValue := iNumInserts;
- FvGauge.Visible := True;
- FTServerCon:= TServerCon.Create(nil);
- FTServerCon.Params.ArraySize := iNumInserts;
- First;
- while not Eof do
- begin
- FTServerCon.Params[0].AsDateTimes[RecNo-1] := Now;
- FTServerCon.Params[1].AsDateTimes[RecNo-1] := Now;
- FTServerCon.Params[2].AsStrings[RecNo-1] := Fieldbyname('USUARIO').AsString;
- FTServerCon.Params[3].AsIntegers[RecNo-1] := Strtoint ( Fieldbyname('CAIXA_NUMERO').AsString );
- FTServerCon.Params[4].AsStrings[RecNo-1] := aCaixa.NumerodoSat;
- FTServerCon.Params[5].AsIntegers[RecNo-1] := Fieldbyname('CAIXA_ID').AsInteger;
- FTServerCon.Params[6].AsDates[RecNo-1] := aCaixa.DatadeAberturacaixa ;
- FTServerCon.Params[7].AsTimes[RecNo-1] := aCaixa.HoradeAberturaCaixa ;
- FTServerCon.Params[8].AsIntegers[RecNo-1] := Strtoint ( Fieldbyname('VENDA_NUMERO').AsString );
- FTServerCon.Params[9].AsStrings[RecNo-1] := fieldbyname('venda_situacao').asstring;
- FTServerCon.Params[10].AsCurrencys[RecNo-1] := fieldbyname('venda_valortotal').ascurrency;
- FTServerCon.Params[11].AsCurrencys[RecNo-1] := fieldbyname('venda_descontos').ascurrency;
- FTServerCon.Params[12].AsIntegers[RecNo-1] := fieldbyname('venda_nitens').asinteger;
- FTServerCon.Params[13].AsDateTimes[RecNo-1] := fieldbyname('data').asdatetime;
- FTServerCon.Params[14].AsDateTimes[RecNo-1] := fieldbyname('hora').asdatetime;
- FTServerCon.Params[15].AsStrings[RecNo-1] := fieldbyname('usuario').asstring;
- FTServerCon.Params[16].AsStrings[RecNo-1] := fieldbyname('sat_numdocfis').asstring;
- FTServerCon.Params[17].AsStrings[RecNo-1] := fieldbyname('sat_chaveemiss').asstring;
- FTServerCon.Params[18].AsDateTimes[RecNo-1] := fieldbyname('sat_emissdata').asdatetime;
- FTServerCon.Params[19].AsDateTimes[RecNo-1] := fieldbyname('sat_emisshora').asdatetime;
- FTServerCon.Params[20].AsStrings[RecNo-1] := fieldbyname('vendanfp_cpf').asstring;
- FTServerCon.Params[21].Values[RecNo-1] := fieldbyname('sat_xml').Value;
- FTServerCon.Params[22].AsStrings[RecNo-1] := fieldbyname('sat_sitemiss').asstring;
- FTServerCon.Params[23].AsIntegers[RecNo-1] := fieldbyname('VENDEDOR_ID').AsInteger;
- FTServerCon.Params[24].AsCurrencys[RecNo-1] := fieldbyname('VENDA_ACRESCIMOS').AsCurrency;
- FTServerCon.Params[25].AsCurrencys[RecNo-1] := fieldbyname('VALOR_TXSERVICOS').AsCurrency;
- FVGauge.Progress := FVGauge.Progress + 1;
- Next;
- end;
- FvGauge.Progress := 0;
- FvGauge.Visible:= False;
- if iNumInserts > 0 then
- begin
- try
- try
- FTServerCon.Execute(iNumInserts, 0);
- finally
- if Assigned( FTAposTranferirMovimentacao ) then
- begin
- FTAposTranferirMovimentacao;
- end;
- FTServerCon.Free;
- FTServerCon:= nil;
- aCaixa.Free;
- aCaixa:= nil;
- end;
- Except
- on E: Exception do
- begin
- GerarLog('Erro na transferencia de Vendas'+ E.Message);
- end;
- end;
- end;
- dlg.DisposeOf;
- wait.DisposeOf;
- end;
- { TSendMovToServer.TTabelaVendas.TServerCon }
- procedure TSendMovToServer.TTabelaVendas.TServerCon.AfterConstruction;
- begin
- inherited AfterConstruction;
- end;
- procedure TSendMovToServer.TTabelaVendas.TServerCon.BeforeDestruction;
- begin
- inherited BeforeDestruction;
- end;
- constructor TSendMovToServer.TTabelaVendas.TServerCon.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- Connection := TDtmConexao.FDServidorConexao;
- SQL.Text :=
- 'UPDATE OR INSERT INTO MOVPDV_VENDAS (TRANSF_DATA, TRANSF_HORA, TRANSF_USERPDV, PDV_NUMPDV, PDV_NSERIESAT,'+
- 'PDV_IDCAIXA, PDV_DATAABRTCAIXA, PDV_HORAABRTCAIXA, VENDA_NUMVENDA, VENDA_SITUACAO,'+
- 'VENDA_VLTOTAL, VENDA_DESCONTOS, VENDA_QTDITENS, VENDA_DATA, VENDA_HORA,'+
- 'VENDA_USERPDV, VENDA_NUMSAT, VENDA_CHAVESAT, VENDA_DATAEMISSSAT,'+
- 'VENDA_HORAEMISSSAT, VENDA_DOC, SAT_XML, SAT_SITUACAO,VENDEDOR_ID,VENDA_ACRESCIMOS,VALOR_TXSERVICOS )'+
- 'VALUES (:TRANSF_DATA, :TRANSF_HORA, :TRANSF_USERPDV, :PDV_NUMPDV, :PDV_NSERIESAT, :PDV_IDCAIXA, :PDV_DATAABRTCAIXA, '+
- ':PDV_HORAABRTCAIXA, :VENDA_NUMVENDA, :VENDA_SITUACAO, :VENDA_VLTOTAL, :VENDA_DESCONTOS, :VENDA_QTDITENS,'+
- ':VENDA_DATA, :VENDA_HORA, :VENDA_USERPDV, :VENDA_NUMSAT, :VENDA_CHAVESAT, :VENDA_DATAEMISSSAT,'+
- ':VENDA_HORAEMISSSAT, :VENDA_DOC, :SAT_XML, :SAT_SITUACAO,:VENDEDOR_ID,:VENDA_ACRESCIMOS,:VALOR_TXSERVICOS )'+
- ' MATCHING (VENDA_NUMVENDA,PDV_NUMPDV) ';
- ResourceOptions.CmdExecMode:= amCancelDialog;
- end;
- { TSendMovToServer.TCaixa }
- procedure TSendMovToServer.TCaixa.AfterConstruction;
- begin
- inherited AfterConstruction;
- end;
- procedure TSendMovToServer.TCaixa.BeforeDestruction;
- begin
- inherited BeforeDestruction;
- end;
- constructor TSendMovToServer.TCaixa.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- Connection := TDtmConexao.FDMasterPdv;
- SQL.Text :=
- 'select '+
- '( SELECT S.EQUIP_SN FROM CONFIGSAT S ) AS NUMEROSAT, '+
- 'ABERTURA_DATA, '+
- 'ABERTURA_HORA, '+
- 'ABERTURA_FISCAL, '+
- 'ABERTURA_OPERADOR '+
- 'from CAIXA ';
- open;
- FNumerodoSat := FieldByName('NUMEROSAT').AsString;
- FDataAberturaCaixa:= FieldByName('ABERTURA_DATA').AsDateTime;
- FHoraAberturaCaixa:= FieldByName('ABERTURA_HORA').AsDateTime;
- FOperador := FieldByName('ABERTURA_OPERADOR').AsString;
- end;
- { TSendMovToServer.TTabelaItensVenda }
- procedure TSendMovToServer.TTabelaItensVenda.AfterConstruction;
- begin
- inherited AfterConstruction;
- end;
- procedure TSendMovToServer.TTabelaItensVenda.BeforeDestruction;
- begin
- inherited BeforeDestruction;
- end;
- constructor TSendMovToServer.TTabelaItensVenda.Create(AOwner: TComponent; aRich: TRichEdit; aGauge: TGauge);
- begin
- inherited Create(AOwner);
- FvRich := aRich;
- FvGauge := aGauge;
- Connection := DtmConexao.TDtmConexao.FDMasterPdv;
- end;
- procedure TSendMovToServer.TTabelaItensVenda.Executecarga;
- var Wait:TFDGUIxWaitCursor; Dlg: TFDGUIxAsyncExecuteDialog;
- iNumInserts: Integer; aCaixa: Tcaixa; I: INteger;
- begin
- aCaixa:= Tcaixa.Create(nil);
- wait := TFDGUIxWaitCursor.Create(nil);
- wait.ScreenCursor:= gcrAppWait;
- dlg:= TFDGUIxAsyncExecuteDialog.Create(nil);
- sql.Text:=
- 'select '+
- 'ID, '+
- '( SELECT P.CAD_CEAN13FISCAL FROM CADPRODUTOS P WHERE P.CAD_CEAN13 = F.ITENS_CODBARRAS ) AS CODEFABRICA, '+
- '( SELECT x.CAD_REFERENCIA FROM CADPRODUTOS x WHERE x.CAD_CEAN13 = F.ITENS_CODBARRAS ) AS REF, '+
- ' '+
- 'VENDA_NUMERO, '+
- 'ITENS_IDPRODUTO, '+
- 'ITENS_CODBARRAS, '+
- 'ITENS_DESCPRODUTO, '+
- 'ITENS_POSICAOITEN, '+
- 'ITENS_QUANTIDADE, '+
- 'ITENS_VLUN, '+
- 'ITENS_TOTAL, '+
- 'ITENS_DATAVENDA, '+
- 'ITENS_HORADAVENDA, '+
- 'ITENS_USUARIO, '+
- 'ITENS_CAIXAID, '+
- 'ITENS_SITUACAO, '+
- 'SAT_NUMEROCFE, '+
- 'SAT_SERIALSAT, '+
- 'ITENS_UN, '+
- 'ITENS_DESCVL, '+
- 'ITENS_DESCPERCENT, '+
- 'ITENS_CFOP, '+
- 'ITENS_CST, '+
- 'ITENS_NCM, '+
- 'ITENS_CEST, '+
- 'IMPOSTO_VPIS, '+
- 'IMPOSTO_PISCST, '+
- 'IMPOSTO_PISVBC, '+
- 'IMPOSTO_PISPPIS, '+
- 'IMPOSTO_COFINSCST, '+
- 'IMPOSTO_COFINSVBC, '+
- 'IMPOSTO_COFINSPCOFINS, '+
- 'INFADPROD, '+
- 'IMPOSTO_ICMSCST, '+
- 'IMPOSTO_ICMSPICMS, '+
- 'IMPOSTO_ICMSCSOSN, '+
- 'IMPOSTO_ICMSORIGDESC, '+
- '"IMPOSTO.ICMS.ORIG", '+
- 'CANCELITEM_VLCANC, '+
- 'IMPOSTO_TRIBDESC, '+
- 'TRANSF_BOOL, '+
- 'MARCA, '+
- 'GRUPO, '+
- 'SUBGRUPO, '+
- 'IDMARCA, '+
- 'IDGRUPO, '+
- 'IDSUBGRUPO, '+
- 'IDFORNECEDOR, '+
- 'FORNECEDOR, '+
- 'PDV_NUMERO, '+
- 'IBPX_TFNACIONAL, '+
- 'IBPX_TFIMPORTADO, '+
- 'IBPTX_ESTADUAL, '+
- 'IBPTX_MUINICIPAL '+
- 'from ITENS_TRANSF F ORDER BY ID';
- open;
- FieldByName('ID').Required := False;
- Last;
- iNumInserts:= RecordCount;
- FvGauge.MaxValue := iNumInserts;
- FvGauge.Visible := True;
- FTServerCon:= TServerCon.Create(nil);
- FTServerCon.Params.ArraySize := iNumInserts;
- First;
- while not Eof do
- begin
- FTServerCon.Params[0].AsDateTimes[RecNo-1] := Now;
- FTServerCon.Params[1].AsDateTimes[RecNo-1] := Now;
- FTServerCon.Params[2].AsStrings[RecNo-1] := Fieldbyname('ITENS_USUARIO').AsString;
- FTServerCon.Params[3].AsIntegers[RecNo-1] := Fieldbyname('PDV_NUMERO').AsInteger;
- FTServerCon.Params[4].AsStrings[RecNo-1] := aCaixa.NumerodoSat;
- FTServerCon.Params[5].AsIntegers[RecNo-1] := FieldByName('ITENS_CAIXAID').AsInteger;
- FTServerCon.Params[6].AsIntegers[RecNo-1] := FieldByName('VENDA_NUMERO').AsInteger;
- FTServerCon.Params[7].AsStrings[RecNo-1] := FieldByName('ITENS_SITUACAO').AsString;
- FTServerCon.Params[8].AsIntegers[RecNo-1] := FieldByName('ITENS_POSICAOITEN').AsInteger;
- FTServerCon.Params[9].AsIntegers[RecNo-1] := FieldByName('ID').AsInteger;
- FTServerCon.Params[10].AsStrings[RecNo-1] := FieldByName('ITENS_CODBARRAS').AsString;
- FTServerCon.Params[11].AsStrings[RecNo-1] := FieldByName('CODEFABRICA').AsString;
- FTServerCon.Params[12].AsStrings[RecNo-1] := FieldByName('ITENS_DESCPRODUTO').AsString;
- FTServerCon.Params[13].AsStrings[RecNo-1] := FieldByName('REF').AsString;
- FTServerCon.Params[14].AsStrings[RecNo-1] := FieldByName('ITENS_NCM').AsString;
- FTServerCon.Params[15].AsStrings[RecNo-1] := FieldByName('ITENS_CEST').AsString;
- FTServerCon.Params[16].AsStrings[RecNo-1] := FieldByName('IMPOSTO_TRIBDESC').AsString;
- FTServerCon.Params[17].AsStrings[RecNo-1] := FieldByName('IMPOSTO_ICMSCST').AsString;
- FTServerCon.Params[18].AsCurrencys[RecNo-1] := FieldByName('IMPOSTO_ICMSPICMS').AsCurrency;
- FTServerCon.Params[19].AsCurrencys[RecNo-1] := FieldByName('ITENS_VLUN').AsCurrency;
- FTServerCon.Params[20].AsCurrencys[RecNo-1] := FieldByName('ITENS_QUANTIDADE').AsCurrency;
- FTServerCon.Params[21].AsCurrencys[RecNo-1] := FieldByName('ITENS_DESCVL').AsCurrency;
- FTServerCon.Params[22].AsCurrencys[RecNo-1] := 0;// AcrescimosVl incrementar no Banco
- FTServerCon.Params[23].AsStrings[RecNo-1] := FieldByName('ITENS_UN').AsString;
- FTServerCon.Params[24].AsDateTimes[RecNo-1] := FieldByName('ITENS_DATAVENDA').AsDateTime;
- FTServerCon.Params[25].AsDateTimes[RecNo-1] := FieldByName('ITENS_HORADAVENDA').AsDateTime;
- FTServerCon.Params[26].AsIntegers[RecNo-1] := FieldByName('TRANSF_BOOL').AsInteger;
- FTServerCon.Params[27].AsStrings[RecNo-1] := FieldByName('MARCA').AsString;
- FTServerCon.Params[28].AsStrings[RecNo-1] := FieldByName('GRUPO').AsString;
- FTServerCon.Params[29].AsStrings[RecNo-1] := FieldByName('SUBGRUPO').AsString;
- FTServerCon.Params[30].AsCurrencys[RecNo-1] := FieldByName('ITENS_TOTAL').AsCurrency;
- FTServerCon.Params[31].AsIntegers[RecNo-1] := FieldByName('IDMARCA').AsInteger;
- FTServerCon.Params[32].AsIntegers[RecNo-1] := FieldByName('IDGRUPO').AsInteger;
- FTServerCon.Params[33].AsIntegers[RecNo-1] := FieldByName('IDSUBGRUPO').AsInteger;
- FTServerCon.Params[34].AsIntegers[RecNo-1] := FieldByName('IDFORNECEDOR').AsInteger;
- FTServerCon.Params[35].AsStrings[RecNo-1] := FieldByName('FORNECEDOR').AsString;
- FTServerCon.Params[36].AsIntegers[RecNo-1] := FieldByName('PDV_NUMERO').AsInteger;
- FTServerCon.Params[37].AsStrings[RecNo-1] := FieldByName('ITENS_USUARIO').AsString;
- FTServerCon.Params[38].AsStrings[RecNo-1] := 'VENDA';
- FTServerCon.Params[39].AsIntegers[RecNo-1] := FieldByName('ITENS_IDPRODUTO').AsInteger;
- FVGauge.Progress := FVGauge.Progress + 1;
- Next;
- end;
- FvGauge.Progress := 0;
- FvGauge.Visible:= False;
- if iNumInserts > 0 then
- begin
- try
- try
- FTServerCon.Execute(iNumInserts, 0);
- finally
- if Assigned( FTAposTranferirMovimentacao ) then
- begin
- FTAposTranferirMovimentacao;
- end;
- FTServerCon.Free;
- FTServerCon:= nil;
- aCaixa.Free;
- aCaixa:= nil;
- end;
- Except
- on E: Exception do
- begin
- GerarLog('Erro na transferencia de Vendas'+ E.Message);
- end;
- end;
- end;
- dlg.DisposeOf;
- wait.DisposeOf;
- end;
- { TSendMovToServer.TTabelaItensVenda.TServerCon }
- procedure TSendMovToServer.TTabelaItensVenda.TServerCon.AfterConstruction;
- begin
- inherited AfterConstruction;
- end;
- procedure TSendMovToServer.TTabelaItensVenda.TServerCon.BeforeDestruction;
- begin
- inherited BeforeDestruction;
- end;
- constructor TSendMovToServer.TTabelaItensVenda.TServerCon.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- Connection := TDtmConexao.FDServidorConexao;
- SQL.Text :=
- ' UPDATE OR INSERT INTO MOVPDV_ITENSVENDA ( TRANF_DATA, TRANSF_HORA, TRANSF_USERPDV'+
- ', PDV_NUMPDV, PDV_NSERIESAT,'+
- ' PDV_IDCAIXA, VENDA_NUMEROVENDA, VENDA_SITUACAO, ITENS_NSEQUENCIA, ITENS_ID,'+
- 'ITENS_CEANTRIB, ITENS_CODFORNECEDOR, ITENS_DESCRICAO, ITENS_REF, ITENS_NCM,' +
- 'ITENS_CEST, TRIB_DESCTRIB, TRIB_CSTCSOSN, TRIB_ALIQICMS, ITENS_VLUN, ITENS_QUT,' +
- 'ITENS_DESCONTOS, ITENS_ACRESC, ITENS_UN, ITENS_VDADATA, ITENS_VDAHORA,'+
- 'ITENS_TRANSFBOOL, ITENS_MARCA, ITENS_GRUPO, ITENS_SUBGRUPO, ITENS_TOTAL,' +
- 'IDMARCA, IDGRUPO, IDSUBGRUPO, IDFORNECEDOR, FORNECEDOR, PDV_NUMERO,'+
- 'PDV_OPERADOR, TIPO_VENDA, ITENS_IDPRODUTO)'+
- 'VALUES (:TRANF_DATA, :TRANSF_HORA, :TRANSF_USERPDV, :PDV_NUMPDV, :PDV_NSERIESAT,'+
- ':PDV_IDCAIXA, :VENDA_NUMEROVENDA,'+
- ' :VENDA_SITUACAO, :ITENS_NSEQUENCIA, :ITENS_ID, :ITENS_CEANTRIB, :ITENS_CODFORNECEDOR, :ITENS_DESCRICAO,'+
- ' :ITENS_REF, :ITENS_NCM, :ITENS_CEST, :TRIB_DESCTRIB, :TRIB_CSTCSOSN, :TRIB_ALIQICMS, :ITENS_VLUN, :ITENS_QUT,'+
- ':ITENS_DESCONTOS, :ITENS_ACRESC, :ITENS_UN, :ITENS_VDADATA, :ITENS_VDAHORA, :ITENS_TRANSFBOOL, :ITENS_MARCA,'+
- ':ITENS_GRUPO, :ITENS_SUBGRUPO, :ITENS_TOTAL, :IDMARCA, :IDGRUPO, :IDSUBGRUPO, :IDFORNECEDOR, :FORNECEDOR,'+
- ':PDV_NUMERO, :PDV_OPERADOR, :TIPO_VENDA, :ITENS_IDPRODUTO)'+
- 'MATCHING ( PDV_NUMPDV, VENDA_NUMEROVENDA, ITENS_ID, ITENS_IDPRODUTO)';
- ResourceOptions.CmdExecMode:= amCancelDialog;
- end;
- { TSendMovToServer.TFinalizadorasVenda.TServerCon }
- procedure TSendMovToServer.TFinalizadorasVenda.TServerCon.AfterConstruction;
- begin
- inherited AfterConstruction;
- end;
- procedure TSendMovToServer.TFinalizadorasVenda.TServerCon.BeforeDestruction;
- begin
- inherited BeforeDestruction;
- end;
- constructor TSendMovToServer.TFinalizadorasVenda.TServerCon.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- Connection := TDtmConexao.FDServidorConexao;
- SQL.Text :=
- ' UPDATE OR INSERT INTO MOV_PDVFINALIZADORAS (VENDA_NUMERO, VENDA_SITUACAO, FIN_IDFINAL, FIN_DESCRICAO,'+
- 'FIN_VALORREC, VENDA_DATA, VENDA_HORA, VENDA_USERPDV, PDV_NUMPDV, CAIXA_ID,CAIXA_DTABERTURA, CAIXA_HORAABERTURA,'+
- 'CAIXA_DTFECHAMENTO, CAIXA_HORAFECH,TRANSMIT_BOOL, DATA_ESTORNO, HORA_ESTORNO)'+
- 'VALUES (:VENDA_NUMERO, :VENDA_SITUACAO, :FIN_IDFINAL, :FIN_DESCRICAO, :FIN_VALORREC, :VENDA_DATA, :VENDA_HORA,'+
- ':VENDA_USERPDV, :PDV_NUMPDV, :CAIXA_ID, :CAIXA_DTABERTURA, :CAIXA_HORAABERTURA, :CAIXA_DTFECHAMENTO,'+
- ':CAIXA_HORAFECH, :TRANSMIT_BOOL, :DATA_ESTORNO, :HORA_ESTORNO)'+
- 'MATCHING (PDV_NUMPDV,CAIXA_ID,VENDA_NUMERO,FIN_IDFINAL,VENDA_DATA,VENDA_HORA)';
- ResourceOptions.CmdExecMode:= amCancelDialog;
- end;
- { TSendMovToServer.TFinalizadorasVenda }
- procedure TSendMovToServer.TFinalizadorasVenda.AfterConstruction;
- begin
- inherited AfterConstruction;
- end;
- procedure TSendMovToServer.TFinalizadorasVenda.BeforeDestruction;
- begin
- inherited BeforeDestruction;
- end;
- constructor TSendMovToServer.TFinalizadorasVenda.Create(AOwner: TComponent; aRich: TRichEdit; aGauge: TGauge);
- begin
- inherited Create(AOwner);
- FvRich := aRich;
- FvGauge := aGauge;
- Connection := DtmConexao.TDtmConexao.FDMasterPdv;
- end;
- procedure TSendMovToServer.TFinalizadorasVenda.Executecarga;
- var Wait:TFDGUIxWaitCursor; Dlg: TFDGUIxAsyncExecuteDialog;
- iNumInserts: Integer; aCaixa: Tcaixa; I: INteger;
- begin
- aCaixa:= Tcaixa.Create(nil);
- wait := TFDGUIxWaitCursor.Create(nil);
- wait.ScreenCursor:= gcrAppWait;
- dlg:= TFDGUIxAsyncExecuteDialog.Create(nil);
- sql.Text:=
- 'SELECT '+
- 'ID, '+
- 'DATA, '+
- 'HORA, '+
- 'USUARIO, '+
- 'SITUACAO, '+
- 'IDVENDA, '+
- 'IDCAIXA, '+
- 'ID_FINALIZADORA, '+
- 'DESC_FINALIZADORA, '+
- 'VALOR_RECEBIDO, '+
- 'INDICE_SAT, '+
- 'TEF_NUM, '+
- 'TEF_CODAUTORIZADOR, '+
- 'TIPO_FINAL, '+
- 'TRANSMIT_BOOL, '+
- 'PDV_NUMPDV, '+
- 'VENDA_DATA, '+
- 'VENDA_HORA, '+
- 'DATA_ESTORNO, '+
- 'HORA_ESTORNO '+
- 'FROM FINALIZADORA_TRANSF ORDER BY ID ';
- open;
- FieldByName('ID').Required := False;
- Last;
- iNumInserts:= RecordCount;
- FvGauge.MaxValue := iNumInserts;
- FvGauge.Visible := True;
- FTServerCon:= TServerCon.Create(nil);
- FTServerCon.Params.ArraySize := iNumInserts;
- First;
- while not Eof do
- begin
- FTServerCon.Params[0].AsDateTimes[RecNo-1] := Now;
- FTServerCon.Params[0].AsIntegers[RecNo-1] := Fieldbyname('idvenda').asinteger;
- FTServerCon.Params[1].AsStrings[RecNo-1] := Fieldbyname('situacao').asstring;
- FTServerCon.Params[2].AsIntegers[RecNo-1] := Fieldbyname('id_finalizadora').asinteger;
- FTServerCon.Params[3].AsStrings[RecNo-1] := Fieldbyname('desc_finalizadora').asstring;
- FTServerCon.Params[4].AsCurrencys[RecNo-1]:= Fieldbyname('valor_recebido').ascurrency;
- FTServerCon.Params[5].AsDateTimes[RecNo-1] := Fieldbyname('data').asdatetime;
- FTServerCon.Params[6].AsDateTimes[RecNo-1] := Fieldbyname('hora').asdatetime;
- FTServerCon.Params[7].AsStrings[RecNo-1] := Fieldbyname('usuario').asstring;
- FTServerCon.Params[8].AsIntegers[RecNo-1] := Fieldbyname('pdv_numpdv').asinteger;
- FTServerCon.Params[9].AsIntegers[RecNo-1] := Fieldbyname('idcaixa').asinteger;
- FTServerCon.Params[10].AsDateTimes[RecNo-1] := aCaixa.DatadeAberturacaixa;
- FTServerCon.Params[11].AsDateTimes[RecNo-1] := aCaixa.HoradeAberturaCaixa;
- FTServerCon.Params[12].AsDateTimes[RecNo-1] := now;
- FTServerCon.Params[13].AsDateTimes[RecNo-1] := now;
- FTServerCon.Params[14].AsIntegers[RecNo-1] := Fieldbyname('transmit_bool').asinteger;
- FTServerCon.Params[15].AsDateTimes[RecNo-1] := Fieldbyname('data_estorno').asdatetime;
- FTServerCon.Params[16].AsDateTimes[RecNo-1] := Fieldbyname('hora_estorno').asdatetime;
- FVGauge.Progress := FVGauge.Progress + 1;
- Next;
- end;
- FvGauge.Progress := 0;
- FvGauge.Visible:= False;
- if iNumInserts > 0 then
- begin
- try
- try
- FTServerCon.Execute(iNumInserts, 0);
- finally
- if Assigned( FTAposTranferirMovimentacao ) then
- begin
- FTAposTranferirMovimentacao;
- end;
- FTServerCon.Free;
- FTServerCon:= nil;
- aCaixa.Free;
- aCaixa:= nil;
- end;
- Except
- on E: Exception do
- begin
- GerarLog('Erro na transferencia de Vendas'+ E.Message);
- end;
- end;
- end;
- dlg.DisposeOf;
- wait.DisposeOf;
- end;
- { TSendMovToServer.TmovXmlTransform.TServerCon }
- procedure TSendMovToServer.TmovXmlTransform.TServerCon.AfterConstruction;
- begin
- inherited AfterConstruction;
- end;
- procedure TSendMovToServer.TmovXmlTransform.TServerCon.BeforeDestruction;
- begin
- inherited BeforeDestruction;
- end;
- constructor TSendMovToServer.TmovXmlTransform.TServerCon.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- Connection := TDtmConexao.FDServidorConexao;
- SQL.Text :=
- 'UPDATE '+
- 'OR '+
- 'INSERT '+
- 'INTO XMLTRANSFORM '+
- '(DATA, HORA, USUARIO, NROVENDA, NROCAIXA, IDCAIXA, XML) '+
- 'VALUES ( :DATA, :HORA, :USUARIO, :NROVENDA, :NROCAIXA, :IDCAIXA, :XML) '+
- 'MATCHING (NROVENDA,NROCAIXA) ';
- ResourceOptions.CmdExecMode:= amCancelDialog;
- end;
- { TSendMovToServer.TmovXmlTransform }
- procedure TSendMovToServer.TmovXmlTransform.AfterConstruction;
- begin
- inherited AfterConstruction;
- end;
- procedure TSendMovToServer.TmovXmlTransform.BeforeDestruction;
- begin
- inherited BeforeDestruction;
- end;
- constructor TSendMovToServer.TmovXmlTransform.Create(AOwner: TComponent; aRich: TRichEdit; aGauge: TGauge);
- begin
- inherited Create(AOwner);
- FvRich := aRich;
- FvGauge := aGauge;
- Connection := DtmConexao.TDtmConexao.FDMasterPdv;
- end;
- procedure TSendMovToServer.TmovXmlTransform.Executecarga;
- var Wait:TFDGUIxWaitCursor; Dlg: TFDGUIxAsyncExecuteDialog;
- iNumInserts: Integer; aCaixa: Tcaixa; I: INteger;
- begin
- aCaixa:= Tcaixa.Create(nil);
- wait := TFDGUIxWaitCursor.Create(nil);
- wait.ScreenCursor:= gcrAppWait;
- dlg:= TFDGUIxAsyncExecuteDialog.Create(nil);
- sql.Text:=
- 'SELECT '+
- 'DATA, '+
- 'HORA, '+
- 'USUARIO, '+
- 'NROVENDA, '+
- 'NROCAIXA, '+
- 'IDCAIXA, '+
- 'XML '+
- 'FROM XMLTRANSFORM_TRANSF X '+
- 'ORDER BY DATA ASC ';
- open;
- Last;
- iNumInserts:= RecordCount;
- FvGauge.MaxValue := iNumInserts;
- FvGauge.Visible := True;
- FTServerCon:= TServerCon.Create(nil);
- FTServerCon.Params.ArraySize := iNumInserts;
- First;
- while not Eof do
- begin
- FTServerCon.Params[0].AsDateTimes[RecNo-1] := Now;
- FTServerCon.Params[0].AsDateTimes[RecNo-1] := FieldByName('DATA').AsDateTime;
- FTServerCon.Params[1].AsDateTimes[RecNo-1] := FieldByName('HORA').AsDateTime;
- FTServerCon.Params[2].AsStrings[RecNo-1] := FieldByName('USUARIO').AsString;
- FTServerCon.Params[3].AsIntegers[RecNo-1] := FieldByName('NROVENDA').AsInteger;
- FTServerCon.Params[4].AsIntegers[RecNo-1] := FieldByName('NROCAIXA').AsInteger;
- FTServerCon.Params[5].AsIntegers[RecNo-1] := FieldByName('IDCAIXA').AsInteger;
- FTServerCon.Params[6].Values[RecNo-1] := FieldByName('XML').Value;
- FVGauge.Progress := FVGauge.Progress + 1;
- Next;
- end;
- FvGauge.Progress := 0;
- FvGauge.Visible:= False;
- if iNumInserts > 0 then
- begin
- try
- try
- FTServerCon.Execute(iNumInserts, 0);
- finally
- if Assigned( FTAposTranferirMovimentacao ) then
- begin
- FTAposTranferirMovimentacao;
- end;
- FTServerCon.Free;
- FTServerCon:= nil;
- aCaixa.Free;
- aCaixa:= nil;
- end;
- Except
- on E: Exception do
- begin
- GerarLog('Erro na transferencia de Vendas'+ E.Message);
- end;
- end;
- end;
- dlg.DisposeOf;
- wait.DisposeOf;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement