Tema: Redondeo
Ver Mensaje Individual
  #27  
Antiguo 22-04-2014
novato_erick novato_erick is offline
Miembro
 
Registrado: ago 2010
Ubicación: Panamá
Posts: 396
Reputación: 14
novato_erick Va por buen camino
Hola Chicos lastimosamente la impresora fiscal tiene una dll llamada BEMAFI32.dll el cual llama una funciones en el que están dentro de una unidad que la llame declaraciones y busque cómo la impresora realiza el redondeo y solamente tiene esto:

Código Delphi [-]
function Bematech_FI_ProgramaRedondeo: Integer; StdCall;
  External 'BEMAFI32.DLL';

más nada jejeje igual que otras funciones que utilizo.

en cuanto a código de ejemplo hago lo siguiente:

Código Delphi [-]
procedure TfrmFacturacionPrincipal.AgregaProductosaVenta;
Var
  codigo, Descripcion, wimpuesto, Cantidad, Precio, wdescuento: AnsiString;
  CIva: String;
  letraimpuesto: AnsiString;
  // Variable que guarda precio u x el porcentaje
  totalivapv, TotalSubVentaFac, TotalSubVentaFacU: Double; // Sin Redondeo
  totalivapvr: Double; // Con Redondeo
  DescProducto, pventapro: Double;
begin
  IdArticuloPro := 0;
  wcodigobarras := Trim(Self.eConsultaArticulo.Text);
  if wcodigobarras <> '' then
  begin
    ConsultaCantidadArt;//Consulta si hay artículos que posean cantidad
    with dmConexion.qConsultaArtInventario do
    begin
      Close;
      sql.Clear;
      sql.Add('select  a.ID_ARTICULO idAtriculo, a.COD_BARRA, a.NOMBRE, ');
      sql.Add(' a.DESCRIPCION, A.GRAVADO,a.CANTIDAD, i.PORCENTAJE, ');
      sql.Add('p.PRECIO_CIV, p.PRECIO_SIV from ARTICULOS a , ARTXIMPUES ai, ');
      sql.Add('impuesto i, PRECIO p ');
      sql.Add(' where a.ID_ARTICULO = ai.ID_ARTICULO   ');
      sql.Add('and i.ID_IMPUESTO = ai.ID_IMPUESTO ');
      sql.Add('and p.ID_ARTICULO = a.ID_ARTICULO   ');
      sql.Add('and p.ID_ARTXIMPUES = ai.ID_ARTXIMPUES');
      sql.Add('AND A.cod_barra=codigo_barras');
      Params.ParamByName('pcodigo_barras').Value := wcodigobarras;
      // Asignamos una cantidad a la variable de cantidades en caso de no ponerlo con anticipacion
      try
        if wcantidad_venta = 0 then
        begin
          wcantidad_venta := 1;
        end;
        Open;
      finally
        eConsultaArticulo.Clear;
        eConsultaArticulo.SetFocus;
      end;
    end;
    IdArticuloPro := dmConexion.qConsultaArtInventarioIDATRICULO.AsInteger;
    ConsultaDescArt(IdArticuloPro);
    if DescxArt > 1 then
    begin
      precioUV := dmConexion.qConsultaArtInventarioPRECIO_SIV.AsFloat;
      precioUVSinDes := dmConexion.qConsultaArtInventarioPRECIO_SIV.AsFloat;
      DescProducto := precioUV * DescxArt / 100;
      precioUV := precioUV - DescProducto;
      precioUVSinDes := simpleroundto(precioUVSinDes, -2);
      Precio := Format('%n', [precioUVSinDes]);
    end
    else
    begin
      DescProducto := StrToFloat('0.00');
      precioUV := dmConexion.qConsultaArtInventarioPRECIO_SIV.AsFloat;
      precioUVSinDes := dmConexion.qConsultaArtInventarioPRECIO_SIV.AsFloat;
      precioUVSinDes := simpleroundto(precioUVSinDes, -2);
      Precio := Format('%n', [precioUVSinDes]);
    end;
    // Guarda a Variables la información capturada desde cantidad hasta el precio unitario
    cantv := wcantidad_venta;
    precioUV := simpleroundto(precioUV, -2);
    // llama al procedimiento para realizar calculo de cantidad por precio unitario
    CalCantxPU;
    // Insertamos en la tabla temporal cdsTempArtVenta
    if cuentaARt = cuentaARt then
    begin
      cuentaARt := cuentaARt + 1;
    end
    else
    begin
      cuentaARt := 0;
    end;
    dmlogicaventa.cdsTempArtVenta.Append;
    // se utiliza el append para ir agregando un registro despues del primer registro
    dmlogicaventa.cdsTempArtVentacdsTempArtVentaART.AsString :=
      inttostr(cuentaARt);
    dmlogicaventa.cdsTempArtVentacdsTempArtVentaIDARTICULO.AsInteger :=
      dmConexion.qConsultaArtInventarioIDATRICULO.AsInteger;
    dmlogicaventa.cdsTempArtVentacdsTempArtVentaCOD_BARRA.AsString :=
      dmConexion.qConsultaArtInventarioCOD_BARRA.AsString;
    dmlogicaventa.cdsTempArtVentacdsTempArtVentaNOMBRE.AsString :=
      dmConexion.qConsultaArtInventarioNOMBRE.AsString;
    dmlogicaventa.cdsTempArtVentacdsTempArtVentaCANTIDAD.AsString :=
      floattostr(cantv);
    dmlogicaventa.cdsTempArtVentacdsTempArtVentaPUnitario.AsFloat :=
      dmConexion.qConsultaArtInventarioPRECIO_SIV.AsFloat;
    // dataset precio sin descuento
    dmlogicaventa.cdsTempArtVentacdsTempArtVentaConDesc.AsFloat :=
      cantv * precioUVSinDes;
    // fin del dataset precio sin desc
    dmlogicaventa.cdsTempArtVentacdsTempArtVentaSUBTOTAL.AsFloat :=
      cantv * precioUV;
    dmlogicaventa.cdsTempArtVentacdsTempArtVentaDESCUENTO.AsFloat :=
      simpleroundto(DescProducto, -2);
    if dmConexion.qConsultaArtInventarioPORCENTAJE.AsString = '0' then
    begin
      exento := exento +
        dmlogicaventa.cdsTempArtVentacdsTempArtVentaSUBTOTAL.AsFloat;
      letraimpuesto := 'E';
      dmlogicaventa.cdsTempArtVentacdsTempArtVentaIMPUESTO.AsString :=
        letraimpuesto;
    end
    else
    begin
      if dmConexion.qConsultaArtInventarioPORCENTAJE.AsString = '7' then
      begin
        dmlogicaventa.cdsTempArtVentacdsTempArtVentaIMPUESTO.AsString :=
          floattostr(dmConexion.qConsultaArtInventarioPORCENTAJE.AsFloat);
        montoImpuesto := montoImpuesto +
          dmlogicaventa.cdsTempArtVentacdsTempArtVentaSUBTOTAL.AsFloat * 0.07;
      end;
      if dmConexion.qConsultaArtInventarioPORCENTAJE.AsString = '10' then
      begin
        dmlogicaventa.cdsTempArtVentacdsTempArtVentaIMPUESTO.AsString :=
          floattostr(dmConexion.qConsultaArtInventarioPORCENTAJE.AsFloat);
        montoImpuesto1 := montoImpuesto1 +
          dmlogicaventa.cdsTempArtVentacdsTempArtVentaSUBTOTAL.AsFloat * 0.10;
      end;
      if dmConexion.qConsultaArtInventarioPORCENTAJE.AsString = '15' then
      begin
        dmlogicaventa.cdsTempArtVentacdsTempArtVentaIMPUESTO.AsString :=
          floattostr(dmConexion.qConsultaArtInventarioPORCENTAJE.AsFloat);
        montoImpuesto2 := montoImpuesto2 +
          dmlogicaventa.cdsTempArtVentacdsTempArtVentaSUBTOTAL.AsFloat * 0.15;
      end;
    end;
    totalivapv := simpleroundto
      ((precioUV * dmConexion.qConsultaArtInventarioPORCENTAJE.AsFloat / 100),
      -2) * cantv; // sin redondeo
    pventapro := totalivapv + TotalCantxPU;
    dmlogicaventa.cdsTempArtVentacdsTempArtVentaPRECIOVENTA.AsFloat :=
      redondeo(pventapro, 2);
    dmlogicaventa.cdsTempArtVenta.Post;
    // Finaliza el append en el client DataSet para que el registro ingresado vaya agregandose otro
    TotalSubVentaFacU := pventapro;
    TotalSubVentaFac := TotalSubVentaFacU + pventapro;
    codigo := dmConexion.qConsultaArtInventarioCOD_BARRA.AsString;
    Descripcion := dmConexion.qConsultaArtInventarioNOMBRE.AsString;
    Impuesto := dmConexion.qConsultaArtInventarioPORCENTAJE.AsFloat;
    CIva := floattostr(Impuesto);
    ConsultaIVA := StrToInt(CIva); // variable de impuesto
    case ConsultaIVA of //La Variable wimpuesto es de tipo AnsiString por requerimiento de imp fiscal
      7:
        begin
          wimpuesto := '0700';
          eSiete.Text := FloatToStrF(montoImpuesto, ffCurrency, 12, 2);
        end;
      10:
        begin
          wimpuesto := '1000';
          eDiez.Text := FloatToStrF(montoImpuesto1, ffCurrency, 12, 2);
        end;
      15:
        begin
          wimpuesto := '1500';
          eQuince.Text := FloatToStrF(montoImpuesto2, ffCurrency, 12, 2);
        end;
      0:
        begin
          wimpuesto := 'II';
          eExentos.Text := FloatToStrF(exento, ffCurrency, 12, 2);
        end;
    end;
    total_impuestos := (montoImpuesto + montoImpuesto1 + montoImpuesto2);
    Cantidad := floattostr(cantv);
    DescProducto := simpleroundto(DescProducto, -2);
    wdescuento := floattostr(DescProducto);
    // cantidad de ventas
    wcantidad_venta := 0;
    eConsultaArticulo.SetFocus;
    // Total de venta sin descuentos
    desc := desc + DescProducto;
    eDescuentos.Text := FloatToStrF(desc, ffCurrency, 12, 2);
    subtotalventasinDesc := dmlogicaventa.cdsTempArtVentaSUBTODESVENTA.Value;
    subtotalventasinDesc := simpleroundto(subtotalventasinDesc, -2);
    eSubSinDesc.Text := FloatToStrF(subtotalventasinDesc, ffCurrency, 12, 2);
    // Total de venta pero con descuento
    subtotalventa := dmlogicaventa.cdsTempArtVentaSUBTOTALVENTA.Value;
    subtotalventa := simpleroundto(subtotalventa, -2);
    eSubTotalVenta.Text := FloatToStrF(subtotalventa, ffCurrency, 12, 2);
    // cantidad de registros en el dbgrid
    kondbgrid := dbgVentas.DataSource.DataSet.RecordCount;
    lblProductosCant.Caption := inttostr(kondbgrid);
    total_impuestos := simpleroundto(total_impuestos, -2);
    eImpuestos.Text := FloatToStrF(total_impuestos, ffCurrency, 12, 2);
    ventatotalfactura := subtotalventa + total_impuestos;
    ventatotalfactura := simpleroundto(ventatotalfactura, -2);
    eTotalVenta.Text := FloatToStrF(ventatotalfactura, ffCurrency, 12, 2);
  end;
  // Funciones de impresora fiscal bematech
  iRetorno := Bematech_FI_EspacioEntreLineas(004);
  Bematech_FI_VendeArticulo(codigo, Descripcion, wimpuesto, 'I', Cantidad, 2,
    Precio, '$', wdescuento);
  // otras impresoras de aquí en adelante
end;


Saludos

novato_erick
Responder Con Cita