Advertisement
Guest User

Untitled

a guest
Aug 16th, 2019
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 3.49 KB | None | 0 0
  1. function TfrmExportacaoHORUSv2.getEntradas:
  2.   ServicoHorus.informarEntradaMedicamentoEmLote;
  3. var
  4.   lEntrada: ServicoHorus.informarEntradaMedicamentoEmLote;
  5.   array_reg3: ServicoHorus.Array_Of_registro3;
  6.   reg3: ServicoHorus.registro3;
  7.   valor: ServicoHorus.nuValorUnitario;
  8.   FormatSettings: TFormatSettings;
  9.   lCont: Integer;
  10.   lCds: TClientDataSet;
  11. begin
  12.   Result := nil;
  13.  
  14.   FormatSettings.DecimalSeparator := '.';
  15.   lcont := -1;
  16.  
  17.   try
  18.     lCds := TClientDataSet.Create(nil);
  19.     lCds.CloneCursor(cdsEntrada, False);
  20.     lCds.First;
  21.     prgProgresso.Max := lcds.RecordCount;
  22.     prgProgresso.Position := 0;
  23.  
  24.     if (lCds.RecordCount > 0) then
  25.     begin
  26.       lEntrada := ServicoHorus.informarEntradaMedicamentoEmLote.Create;
  27.       lEntrada.identificacao := ServicoHorus.IdentificacaoType.Create;
  28.  
  29.       lEntrada.identificacao.idOrigem := ServicoHorus.idOrigem.M;
  30.       lEntrada.identificacao.coIBGE := FCodIBGE;
  31.  
  32.       SetLength(array_reg3, lCds.RecordCount);
  33.       lCds.First;
  34.       while not lCds.eof do
  35.       begin
  36.         reg3 := ServicoHorus.registro3.Create;
  37.         reg3.estabelecimento := ServicoHorus.EstabelecimentoType.Create;
  38.         reg3.estabelecimento.coCNES := IntToStr(FCodCNES);
  39.  
  40.         if lCds.FieldByName('tipo_estabelecimento').AsString = 'A' then
  41.           reg3.estabelecimento.coTipoEstabelecimento :=
  42.             ServicoHorus.coTipoEstabelecimento.A;
  43.  
  44.         if lCds.FieldByName('tipo_estabelecimento').AsString = 'R' then
  45.           reg3.estabelecimento.coTipoEstabelecimento :=
  46.             ServicoHorus.coTipoEstabelecimento.R;
  47.  
  48.         if lCds.FieldByName('tipo_estabelecimento').AsString = 'F' then
  49.           reg3.estabelecimento.coTipoEstabelecimento :=
  50.             ServicoHorus.coTipoEstabelecimento.F;
  51.  
  52.         reg3.produto := ServicoHorus.ProdutoEntradaType.Create;
  53.         reg3.produto.coRegistroOrigem := lCds.FieldByName('codentr2').AsString;
  54.         reg3.produto.nuProduto := lCds.FieldByName('tipo_produto').AsString +
  55.           lCds.FieldByName('codcatmat').AsString;
  56.         reg3.produto.nuLote := lCds.FieldByName('lote').AsString;
  57.         reg3.produto.dtValidade := FormatDateTime('dd-mm-yyyy',
  58.           lCds.FieldByName('valid').AsDateTime);
  59.         reg3.produto.qtProduto := lCds.FieldByName('quant').AsInteger;
  60.         reg3.produto.dtRegistro := FormatDateTime('dd-mm-yyyy',
  61.           lCds.FieldByName('data').AsDateTime);
  62.         reg3.produto.nuNotaFiscal := lCds.FieldByName('notaf').AsString;
  63.  
  64.         if lCds.FieldByName('fornec_internacional').AsString = 'N' then
  65.           reg3.produto.nuCNPJFabricante :=
  66.             lCds.FieldByName('cnpj_fabricante').AsString
  67.         else
  68.           reg3.produto.noFabricanteInternacional :=
  69.             lCds.FieldByName('nome_fabricante').AsString;
  70.  
  71.         valor := ServicoHorus.nuValorUnitario.Create;
  72.         valor.DecimalString := FormatFloat('0.0000',
  73.           lCds.FieldByName('preco').AsFloat, FormatSettings);
  74.  
  75.         reg3.produto.nuValorUnitario := valor;
  76.         reg3.produto.nuCNPJDistribuidor :=
  77.           lcds.FieldByName('cnpj_fornecedores').AsString;
  78.         reg3.produto.tpEntradaEstoque :=
  79.           fTipoEntrada(lCds.FieldByName('tipo').AsString);
  80.  
  81.         Inc(lCont);
  82.         array_reg3[lCont] := reg3;
  83.  
  84.         lCds.Next;
  85.       end;
  86.       lEntrada.registro := array_reg3;
  87.     end;
  88.     Result := lEntrada;
  89.   except
  90.     on ex: Exception do
  91.     begin
  92.       TFuncaoGeral.pr_Mensagem('Erro: ' + ex.Message + sLineBreak + 'Por favor, contate o suporte.');
  93.     end;
  94.   end;
  95. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement