Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 24-08-2011
novato_erick novato_erick is offline
Miembro
 
Registrado: ago 2010
Ubicación: Panamá
Posts: 396
Poder: 14
novato_erick Va por buen camino
campos calculados para presentar precio de ventas

Hola nuevamente a todos:

He creado un procedimiento que calcula precio de ventas con su respectivo impuesto de un articulo a partir de un precio de compra

los componente que utilizo es un TComboBox llamado: cbxCalculoBase con dos items Precio de compra (si esta elegida esta opción realiza calculos respecto al precio de compra)y en el items Manual (simplemente no realiza calculo y permite agregar los precios que el usuario desee al articulo).

Creo que me di a explicar.

Siguiendo:

Cree un procedimiento de esta manera:

Código Delphi [-]
procedure TFrmArticulos.CalculaTotalesPrecios;
var
  i: Integer;
begin
  // Calcula los totales de los precios de venta referente a la compra
  pc := 0.00; // Precio de compra
  pg := 0.00; // Precio de Gasto
  pu := 0.00; // Precio con Utilidad
  pva := 0.00; // Precio con Impuesto
  pf := 0.00; // Precio Fijo
  // ****************
  psinitbm := 0.00; // Precio sin IVA
  pconitbm := 0.00; // Precio con IVA
  porcentajeG := 0.00; // Porcenjate de Gasto
  porcentajeU := 0.00; // orcentaje de Utilidad
  porcentajeV := 0.00; // Porcentaje de Varios
  // ***************************
  Gasto := 0.00; // Gasto
  varios := 0.00; // Varios otros valores
  utilidad := 0.00; // utilidad del producto
  subtotalg := 0.00; // subtototal de gastos
  subtotalv := 0.00; // subtotal varios
  subtotalu := 0.00; // subtotal  utilidad
  // ***********************
  Gasto2 := 0.00;
  varios2 := 0.00;
  utilidad2 := 0.00;
  subtotalg2 := 0.00;
  subtotalv2 := 0.00;
  subtotalu2 := 0.00;
  psinitbm2 := 0.00;
  pconitbm2 := 0.00;
  porcentajeG2 := 0.00;
  porcentajeU2 := 0.00;
  porcentajeV2 := 0.00;
  // ***************************
  Gasto3 := 0.00;
  varios3 := 0.00;
  utilidad3 := 0.00;
  subtotalg3 := 0.00;
  subtotalv3 := 0.00;
  subtotalu3 := 0.00;
  tempPrecio := 0.00;

  begin

    begin
       pc := StrToFloat(frmArticulos.dbePCompra.Text);
       psinitbm:= pc;
    end;

    frmArticulos.dbePSinIV.Text := FloatToStr(psinitbm);
    varios := StrToFloat(frmArticulos.txtVarios.Text);
    Gasto := StrToFloat(frmArticulos.txtGastos.Text);
    utilidad := StrToFloat(frmArticulos.txtUtilidad.Text);
    if dbeImpuesto.Text > '0' then
    begin
      impuesto := strtoint(dbeImpuesto.Text);
    end;
    // *****************************************
    pc := StrToFloat(frmArticulos.dbePCompra.Text);
    psinitbm2 := pc;
    frmArticulos.dbePSinIV2.Text := FloatToStr(psinitbm2);
    varios2 := StrToFloat(frmArticulos.txtVarios2.Text);
    Gasto2 := StrToFloat(frmArticulos.txtGastos2.Text);
    utilidad2 := StrToFloat(frmArticulos.txtUtilidad2.Text);

    // ************************************************
    pc := StrToFloat(frmArticulos.dbePCompra.Text);
    psinitbm3 := pc;
    frmArticulos.dbePSinIV3.Text := FloatToStr(psinitbm3);
    varios3 := StrToFloat(frmArticulos.txtVarios3.Text);
    Gasto3 := StrToFloat(frmArticulos.txtGastos3.Text);
    utilidad3 := StrToFloat(frmArticulos.txtUtilidad3.Text);
    // ***************************************************
    begin
      if Gasto > 0 then
      begin
        porcentajeG := (psinitbm * Gasto / 100);
        psinitbm := Roundto(pc + porcentajeG, -2);
        if dbeImpuesto.Text > '0' then
        begin
          porcentajeImpuestoG := (psinitbm * impuesto / 100);
          dbePConIV.Text :=
            FloatToStr(Roundto(psinitbm + porcentajeImpuestoG, -2));
        end;
      end;
      // *************************
      if Gasto2 > 0 then
      begin
        porcentajeG2 := (psinitbm2 * Gasto2 / 100);
        psinitbm2 := Roundto(pc + porcentajeG2, -2);
        if dbeImpuesto.Text > '0' then
        begin
          porcentajeImpuestoG2 := (psinitbm2 * impuesto / 100);
          dbePConIV2.Text :=
            FloatToStr(Roundto(psinitbm2 + porcentajeImpuestoG2, -2));
        end;
      end;
      // ************************************
      if Gasto3 > 0 then
      begin
        porcentajeG3 := (psinitbm3 * Gasto3 / 100);
        psinitbm3 := Roundto(pc + porcentajeG3, -2);
        if dbeImpuesto.Text > '0' then
        begin
          porcentajeImpuestoG3 := (psinitbm3 * impuesto / 100);
          dbePConIV3.Text :=
            FloatToStr(Roundto(psinitbm3 + porcentajeImpuestoG3, -2));
        end;
      end;
      // *************************************
      if varios > 0 then
      begin
        subtotalv := psinitbm + (psinitbm * varios / 100);
        porcentajeV := subtotalv;
        psinitbm := Roundto(subtotalv, -2);
        if dbeImpuesto.Text > '0' then
        begin
          porcentajeIMpuestoV := (psinitbm * impuesto / 100);
          dbePConIV.Text :=
            FloatToStr(Roundto(psinitbm + porcentajeIMpuestoV, -2));
        end;
      end;
      // ***********************************
      if varios2 > 0 then
      begin
        subtotalv2 := psinitbm2 + (psinitbm2 * varios2 / 100);
        porcentajeV2 := subtotalv2;
        psinitbm2 := Roundto(subtotalv2, -2);
        if dbeImpuesto.Text > '0' then
        begin
          porcentajeIMpuestoV2 := (psinitbm2 * impuesto / 100);
          dbePConIV2.Text :=
            FloatToStr(Roundto(psinitbm2 + porcentajeIMpuestoV2, -2));
        end;
      end;
      // **********************************
      if varios3 > 0 then
      begin
        subtotalv3 := psinitbm3 + (psinitbm3 * varios3 / 100);
        porcentajeV3 := subtotalv3;
        psinitbm3 := Roundto(subtotalv3, -2);
        if dbeImpuesto.Text > '0' then
        begin
          porcentajeIMpuestoV3 := (psinitbm3 * impuesto / 100);
          dbePConIV3.Text :=
            FloatToStr(Roundto(psinitbm3 + porcentajeIMpuestoV3, -2));
        end;
      end;
      // ****************************************
      if utilidad > 0 then
      begin
        subtotalu := psinitbm + (psinitbm * utilidad / 100);
        porcentajeU := subtotalu;
        psinitbm := Roundto(subtotalu, -2);
        if dbeImpuesto.Text > '0' then
        begin
          porcentajeIMpuestoU := (psinitbm * impuesto / 100);
          dbePConIV.Text :=
            FloatToStr(Roundto(psinitbm + porcentajeIMpuestoU, -2));
        end;
      end;
      // ****************************************
      if utilidad2 > 0 then
      begin
        subtotalu2 := psinitbm2 + (psinitbm2 * utilidad2 / 100);
        porcentajeU2 := subtotalu2;
        psinitbm2 := Roundto(subtotalu2, -2);
        if dbeImpuesto.Text > '0' then
        begin
          porcentajeIMpuestoU2 := (psinitbm2 * impuesto / 100);
          dbePConIV2.Text :=
            FloatToStr(Roundto(psinitbm2 + porcentajeIMpuestoU2, -2));
        end;
      end;
      // ****************************************
      if utilidad3 > 0 then
      begin
        subtotalu3 := psinitbm3 + (psinitbm3 * utilidad3 / 100);
        porcentajeU3 := subtotalu3;
        psinitbm3 := Roundto(subtotalu3, -2);
        if dbeImpuesto.Text > '0' then
        begin
          porcentajeIMpuestoU3 := (psinitbm3 * impuesto / 100);
          dbePConIV3.Text :=
            FloatToStr(Roundto(psinitbm3 + porcentajeIMpuestoU3, -2));
        end;

      end;
      // *********************************
    end;
    frmArticulos.dbePSinIV.Text := FloatToStr(psinitbm);
    frmArticulos.dbePSinIV2.Text := FloatToStr(psinitbm2);
    frmArticulos.dbePSinIV3.Text := FloatToStr(psinitbm3);
  end;

end;

En si... hay algunos aspecto que me están provocando error y no he podido resolver aun; Este es cuando al llamar al formulario de FrmArticulo en modo de Edición me envía el siguiente error:
Cita:
---------------------------
Debugger Exception Notification
---------------------------
Project Inventarios.exe raised exception class EAccessViolation with message 'Access violation at address 008D0363 in module 'Inventarios.exe'. Read of address 00000608'.
---------------------------
Break Continue Help
---------------------------
uso del debug y me envia a esta linea del procedimiento:
Código Delphi [-]
// ***************************
  Gasto3 := 0.00;
  varios3 := 0.00;
  utilidad3 := 0.00;
  subtotalg3 := 0.00;
  subtotalv3 := 0.00;
  subtotalu3 := 0.00;
  tempPrecio := 0.00;

begin
       pc := StrToFloat(frmArticulos.dbePCompra.Text);// aquí me envía el debug
       psinitbm:= pc;
end;

justamente después de las ultimas variables con datos
Código Delphi [-]
procedure TFrmArticulos.CalculaTotalesPrecios;

definitivamente hay algo mal pero no he logrado dar con el diagnostico algún terapeuta que me de ayuda?

Saludos

novato_erick

Última edición por novato_erick fecha: 24-08-2011 a las 02:07:05.
Responder Con Cita
  #2  
Antiguo 24-08-2011
Avatar de Caral
[Caral] Caral is offline
Miembro Premium
 
Registrado: ago 2006
Posts: 7.659
Poder: 25
Caral Va por buen camino
Hola
Uffff, que montón de código.
Sin verlo mucho (por que me canse) te diría que no es bueno colocar el impuesto en un campo fijo, los Países tienen la manía de cambiarlos según su interés.
Saludos
__________________
Siempre Novato
Responder Con Cita
  #3  
Antiguo 24-08-2011
novato_erick novato_erick is offline
Miembro
 
Registrado: ago 2010
Ubicación: Panamá
Posts: 396
Poder: 14
novato_erick Va por buen camino
jajajaja si Caral sabia que alguien me diría eso pero bueno soy novato aun no me atrevo a correr...

pero en fin es una aplicación a nivel local no se me había ocurrido eso Gracias por la sugerencia... problema que menciono será por eso?.. bueno aparentemente dice que mi variable pc lo toma del dbePCompra.Text y que el impuesto es simplemente la variable psinitbm vendra a ser la variable pc;

eso es el error? noooo creo ...

Saludos

Cita:
Disculpen el montón de código pero no me imagino como darme a explicar mi procedimiento
Responder Con Cita
  #4  
Antiguo 24-08-2011
Avatar de Caral
[Caral] Caral is offline
Miembro Premium
 
Registrado: ago 2006
Posts: 7.659
Poder: 25
Caral Va por buen camino
Hola
Veo poco, pero:
1: las variables las declaras publicas ???, donde estan, (solo veo i : Integer)
2: Las variables obtienen su valor de los edits (me parece) entonces por que las declararlas con 0.00 ????.
No entiendo muy bien el concepto que tienes al hacer tantos calculos y con tantas opciones diferentes en un procedimiento, me imagino que estoy viejo y esto es lo moderno.
Saludos
__________________
Siempre Novato
Responder Con Cita
  #5  
Antiguo 24-08-2011
novato_erick novato_erick is offline
Miembro
 
Registrado: ago 2010
Ubicación: Panamá
Posts: 396
Poder: 14
novato_erick Va por buen camino
jajaja disculpa si mis variables son publicas y las declaro con 0.00 para inicializarlas... Me estoy equivocando en algo?

Código Delphi [-]
public
    { Public declarations }
    Gasto, porcentajeG, porcentajeU, porcentajeV, pc, pg, pu, pva, pf, psinitbm,
      pconitbm, varios, utilidad, subtotalg, subtotalv, subtotalu, Gasto2,
      porcentajeG2, porcentajeU2, porcentajeV2, psinitbm2, pconitbm2, varios2,
      utilidad2, subtotalg2, subtotalv2, subtotalu2, Gasto3, porcentajeG3,
      porcentajeU3, porcentajeV3, psinitbm3, pconitbm3, varios3, utilidad3,
      subtotalg3, subtotalv3, subtotalu3, tempPrecio, porcentajeImpuestoG,
      porcentajeIMpuestoU, porcentajeIMpuestoV, porcentajeImpuestoG2,
      porcentajeIMpuestoU2, porcentajeIMpuestoV2, porcentajeImpuestoG3,
      porcentajeIMpuestoU3, porcentajeIMpuestoV3: Double;
    impuesto: Integer;

usted sabe no es moderno solo improviso...

jajajaj

Gracias Caral...
Responder Con Cita
  #6  
Antiguo 24-08-2011
Avatar de Caral
[Caral] Caral is offline
Miembro Premium
 
Registrado: ago 2006
Posts: 7.659
Poder: 25
Caral Va por buen camino
Hola
Si te empeñas en usar variables deberias declararlas en el procedimiento ya que se deberian iniciar y eliminar, asi no tendrias que colocarles un valor de inicio, este deberia de estar en los edit.
No entiendo muy bien lo que quieres hacer por eso solo opino.
Saludos
__________________
Siempre Novato
Responder Con Cita
  #7  
Antiguo 24-08-2011
novato_erick novato_erick is offline
Miembro
 
Registrado: ago 2010
Ubicación: Panamá
Posts: 396
Poder: 14
novato_erick Va por buen camino
Caral entiendo lo que me sugieres..

y trataré de ser mas claro como el agua del mar:

deseo que se realize calculo a partir de un campo (precio de compra)

Este tendra otros edit que calculara un porcentaje y lo manda a un campo subtotal sin impuesto y otro campo realiza los calculos del impuesto mandando un total para ser vendido y guardandolo a la base de datos..

en el evento OnChange del dbEdit dbePcompra tengo esto:
Código Delphi [-]
procedure TFrmArticulos.dbePCompraChange(Sender: TObject);

  begin
    if Trim(dbePCompra.Text) = '' then
    begin
      dbePCompra.Text := '0';
      if dbePCompra.Text = '0' then
        // *********************
      dbePConIV.Text := '0';
      dbePConIV2.Text := '0';
      dbePConIV3.Text := '0';
      // **************************
      dbePSinIV.Text := '0';
      dbePSinIV2.Text := '0';
      dbePSinIV3.Text := '0';
      // **************************
      dbePFijos.Text := '0';
      dbePFijos2.Text := '0';
      dbePFijos3.Text := '0';
      // *****************
      txtGastos.Text := '0';
      txtGastos2.Text := '0';
      txtGastos3.Text := '0';
      // *****************
      txtUtilidad.Text := '0';
      txtUtilidad2.Text := '0';
      txtUtilidad3.Text := '0';
      // ********************
      txtVarios.Text := '0';
      txtVarios2.Text := '0';
      txtVarios3.Text := '0';
      // **********************
   end
end;

Creo que me explique cierto?

Saludos;

Última edición por novato_erick fecha: 24-08-2011 a las 02:43:40.
Responder Con Cita
  #8  
Antiguo 24-08-2011
Avatar de Caral
[Caral] Caral is offline
Miembro Premium
 
Registrado: ago 2006
Posts: 7.659
Poder: 25
Caral Va por buen camino
Hola
Creo que lo que quieres hacer es una factura.
Si es asi AQUI hice un Tutorial para hacer eso.
Puedes Saltarte las partes que no necesites he irte a la parte de facturacion, tal vez te de algunas ideas, espero te sirva, si no, solo dilo.
Saludos
PD: Con Vuestro permiso.
__________________
Siempre Novato
Responder Con Cita
  #9  
Antiguo 24-08-2011
novato_erick novato_erick is offline
Miembro
 
Registrado: ago 2010
Ubicación: Panamá
Posts: 396
Poder: 14
novato_erick Va por buen camino
Hola Caral

He estado trabajando con tu tutorial y en parte no era facturación lo que necesitaba; Realizo un modulo de mantenimiento de articulos agregando los precios tomando como referencia un precio de compra o sea Costo y calculo precio de venta. Sin embargo me a ayudado mucho Tu tutorial por ejemplo mira ahora un poco mi codigo resumido a comparación del enorme que al principio cree y que te aburriste de leerlo :


Código Delphi [-]
public
Var
pvmostrar : Double;
 
{$R *.dfm}
 
 
procedure TFrmArticulos.CalculaTotalesPrecios;
var
pc, pg, pv, pu, iva, sniva, cniva,pvtag, pvtau, pvtav, pvsiva ,pvta : Double;
begin
iva := StrToFloat(dbeImpuesto.Text);
pc := StrToFloat(dbePCompra.Text);
pg := StrToFloat(eGastos.Text);
pv := StrToFloat(eVarios.Text);
pu := StrToFloat(eUtilidad.Text);
sniva := StrToFloat(dbePSinIV.Text);
pvtag := pc * pg /100;
pvtav := (pc+pvtag) * pv /100;
pvtau := (pvtag+pvtav+pc) *pu /100;
pvsiva := pvtag + pvtav + pvtau;
dbePSinIV.Text := FloatToStr(pc+pvsiva);
pvta := StrToFloat(dbePSinIV.Text) * iva /100;
dbePConIV.Text := FloatToStr(Roundto((pvta)+ StrToFloat(dbePSinIV.Text),-2));
pvmostrar := StrToFloat(dbePConIV.Text);// esta informacion creo que la utilizare  mas adelante
end;

mucho menos verdad? pero aqui solo manejo un precio de venta me falta dos precios de ventas mas jajajaja...

bueno ahora estoy pegado en algo a ver si me ayudan:

tengo un TDBCheckBox que en el evento OnClick hace esto:


Código Delphi [-]
 
procedure TFrmArticulos.DBCheckBox1Click(Sender: TObject);
begin
if DBCheckBox1.Checked then
begin
dbeImpuesto.Visible := true;
dbeImpuesto.Text := FloatToStr(DataArticulos.cdsArticulosIMPUESTO.Value);
end
else
begin
dbeImpuesto.Visible := false;
dbePConIV.Text := FloatToStr(Roundto((pvmostrar)+ StrToFloat(dbePSinIV.Text),-2));//'0';
dbePConIV2.Text := '0';
dbePConIV3.Text := '0';
end;
end;

Lo que sucede es que cuando este visible tenga el valor guardado por defecto
pero al estar invisible tome el valor como si no estuviera calculando el impuesto.

Me di a explicar?

Saludos
Responder Con Cita
  #10  
Antiguo 25-08-2011
Avatar de Caral
[Caral] Caral is offline
Miembro Premium
 
Registrado: ago 2006
Posts: 7.659
Poder: 25
Caral Va por buen camino
Hola
Y no es al reves???.
No se, seguro no entiendo.
Saludos
__________________
Siempre Novato
Responder Con Cita
  #11  
Antiguo 03-09-2011
novato_erick novato_erick is offline
Miembro
 
Registrado: ago 2010
Ubicación: Panamá
Posts: 396
Poder: 14
novato_erick Va por buen camino
Tratando de empezar

Hola a todos:

He buscado manera de tratar de realizar calculos para un formulario de ingreso de articulos este debe de realizar cálculos a partir de un precio de compra.

Código Delphi [-]
procedure TFrmArticulos.CalculaTotalesPrecios;
var
      pc, pg, pv, pu, iva,  sniva, cniva,pvtag, pvtau, pvtav, pvsiva ,pvta: Double;
begin
 iva := StrToFloat(dbeImpuesto.Text);
 pc := StrToFloat(dbePCompra.Text);
 pg := StrToFloat(eGastos.Text);
 pv := StrToFloat(eVarios.Text);
 pu := StrToFloat(eUtilidad.Text);
 sniva := StrToFloat(dbePSinIV.Text);
 pvtag := pc * pg /100;
 pvtav := (pc+pvtag) * pv /100;
 pvtau := (pvtag+pvtav+pc) *pu /100;
 pvsiva := pvtag + pvtav + pvtau;
 dbePSinIV.Text := FloatToStr(pc+pvsiva); //me envia tres decimales arreglar eso
 pvta :=  StrToFloat(dbePSinIV.Text) * iva /100;
 dbePConIV.Text := FloatToStr(Roundto((pvta)+ StrToFloat(dbePSinIV.Text),-3));
end;

utilize variables para realizar los respectivos calculos. y funciona (hace los calculos enviandomelo a dos TdbEdit llamados dbePSinIV y DbePConIV.

ahora le digo al hacer click en el boton de insertar

Código Delphi [-]
procedure TFrmArticulos.btnAceptarClick(Sender: TObject);
begin 
    if dataarticulos.cdsArticulos.State = dsinsert then
       begin
          DataArticulos.cdsArticulosFECHA_ALTA.AsDateTime := now;
          DataArticulos.cdsArticulosCOEF_GASTO.AsInteger := StrToInt(egastos.Text);
          DataArticulos.cdsArticulosCOEF_VARIOS.AsInteger := StrToInt(eVarios.Text);
          DataArticulos.cdsArticulosCOEF_UTILIDAD.AsInteger := StrToInt(eutilidad.Text);
        if DataArticulos.cdsArticulosDESACTIVADO.Asstring = '' then
        DataArticulos.cdsArticulosDESACTIVADO.Asstring := 'N';
        if DataArticulos.cdsArticulosGRAVADO.Asstring = '' then
        Dataarticulos.cdsArticulosGRAVADO.Asstring := 'N';
      DataArticulos.cdsArticulos.Post;
      DataArticulos.cdsArticulos.applyupdates(0);
end;

al llamar al frmArticulos para editar (Modificar) no me aparecen en los edit los coeficientes anteriormente ingresado.

Alguien puede orientarme?

Saludos
Responder Con Cita
  #12  
Antiguo 03-09-2011
Avatar de Caral
[Caral] Caral is offline
Miembro Premium
 
Registrado: ago 2006
Posts: 7.659
Poder: 25
Caral Va por buen camino
Hola
Que dificil entender.
Saludos
__________________
Siempre Novato
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Campos Calculados Kaller Tablas planas 1 12-12-2006 00:11:13
campos calculados Nelly SQL 2 07-10-2005 18:13:51
Campos calculados SaurioNet MS SQL Server 4 21-01-2005 23:47:38
Campos CAlculados karlita_cb Tablas planas 4 24-03-2004 04:40:03
Lio Con Los Campos Calculados. JROMAN OOP 2 18-09-2003 02:02:36


La franja horaria es GMT +2. Ahora son las 01:18:22.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi