unit PrecInve;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Grids,Checa, StdCtrls, Buttons, ExtCtrls, Gauges;

type
  TFormaPreciosInventario = class(TForm)
    TablaFiltros: TStringGrid;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    Panel1: TPanel;
    Shape1: TShape;
    Bevel1: TBevel;
    Bevel2: TBevel;
    Bevel3: TBevel;
    Label1: TLabel;
    Label2: TLabel;
    Panel2: TPanel;
    Monto1: TEdit;
    Monto2: TEdit;
    Monto3: TEdit;
    Monto4: TEdit;
    Monto5: TEdit;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    BarraProgreso: TGauge;
    procedure FormCreate(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure Panel2Click(Sender: TObject);
    procedure Label2MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure TablaFiltrosKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Label3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FormaPreciosInventario: TFormaPreciosInventario;

procedure ponecampos(tabla:string);
function condiciones1:string;
procedure EjecutaFiltrado;
implementation

uses Inven;

{$R *.DFM}



Procedure ActualizaLosPrecios;
var
tamodatos,cuenta:longint;
begin
with FormaInventario do
begin
TablaInventario.First;
cuenta:=0;
tamodatos:=TablaInventario.RecordCount;
while not TablaInventario.Eof do
begin
{****inicia la actualizacion de precios*****}
if FormaPreciosInventario.Label3.Caption='Monto $' then
begin
TablaInventario.Edit;
TablaInventario.FieldByName('PPUBL_I').AsFloat:=TablaInventario.FieldByName('PPUBL_I').AsFloat+StrToFloat(FormaPreciosInventario.Monto1.Text);
TablaInventario.FieldByName('PLIS2_I').AsFloat:=TablaInventario.FieldByName('PLIS2_I').AsFloat+StrToFloat(FormaPreciosInventario.Monto2.Text);
TablaInventario.FieldByName('PLIS3_I').AsFloat:=TablaInventario.FieldByName('PLIS3_I').AsFloat+StrToFloat(FormaPreciosInventario.Monto3.Text);
TablaInventario.FieldByName('PLIS4_I').AsFloat:=TablaInventario.FieldByName('PLIS4_I').AsFloat+StrToFloat(FormaPreciosInventario.Monto4.Text);
TablaInventario.FieldByName('PMINI_I').AsFloat:=TablaInventario.FieldByName('PMINI_I').AsFloat+StrToFloat(FormaPreciosInventario.Monto5.Text);
TablaInventario.Post;

end
else
begin
TablaInventario.Edit;
TablaInventario.FieldByName('PPUBL_I').AsFloat:=TablaInventario.FieldByName('PPUBL_I').AsFloat+(TablaInventario.FieldByName('PPUBL_I').AsFloat*StrToFloat(FormaPreciosInventario.Monto1.Text)/100);
TablaInventario.FieldByName('PLIS2_I').AsFloat:=TablaInventario.FieldByName('PLIS2_I').AsFloat+(TablaInventario.FieldByName('PLIS2_I').AsFloat*StrToFloat(FormaPreciosInventario.Monto2.Text)/100);
TablaInventario.FieldByName('PLIS3_I').AsFloat:=TablaInventario.FieldByName('PLIS3_I').AsFloat+(TablaInventario.FieldByName('PLIS3_I').AsFloat*StrToFloat(FormaPreciosInventario.Monto3.Text)/100);
TablaInventario.FieldByName('PLIS4_I').AsFloat:=TablaInventario.FieldByName('PLIS4_I').AsFloat+(TablaInventario.FieldByName('PLIS4_I').AsFloat*StrToFloat(FormaPreciosInventario.Monto4.Text)/100);
TablaInventario.FieldByName('PMINI_I').AsFloat:=TablaInventario.FieldByName('PMINI_I').AsFloat+(TablaInventario.FieldByName('PMINI_I').AsFloat*StrToFloat(FormaPreciosInventario.Monto5.Text)/100);
TablaInventario.Post;

end;
{**termina la actualizacion de precios****}
TablaInventario.Next;
cuenta:=cuenta+1;
FormaPreciosInventario.BarraProgreso.Progress:=Trunc((cuenta/tamodatos)*100);
end;
FormaPreciosInventario.BarraProgreso.Progress:=100;

end;
end;


procedure EjecutaFiltrado;
begin
with FormaPreciosInventario do
begin
BarraProgreso.Progress:=0;
ActualizaLosPrecios;
end;
end;



function condiciones1:string;
var
i:integer;
aux:string;
begin
with FormaPreciosInventario do
begin
aux:='';
for i:=1 to TablaFiltros.RowCount do
begin

{ShowMessage(TablaFiltros.Cells[2,i]);}
if TablaFiltros.Cells[2,i]<>'' then
begin
aux:=aux+TablaFiltros.Cells[0,i]+'*'+TablaFiltros.Cells[2,i]+'*'+TablaFiltros.Cells[3,i]+'*'+TablaFiltros.Cells[4,i]+'*';

end;

end;
condiciones1:=aux;
end;
end;

procedure ponecampos(tabla:string);
var
inicio,fin,i,cuenta:integer;

begin
with FormaPreciosInventario do
begin
inicio:=Trunc(rangoscampos(tabla)/1000);
fin:=rangoscampos(tabla)-(inicio*1000);
{ShowMessage(intToStr(inicio)+'  '+intToStr(fin));}
cuenta:=1;
TablaFiltros.RowCount:=2;
for i:=inicio to fin do
begin
TablaFiltros.Cells[0,cuenta]:=leecampos(i,1);
TablaFiltros.Cells[1,cuenta]:=leecampos(i,2);
TablaFiltros.Cells[2,cuenta]:='';
TablaFiltros.Cells[3,cuenta]:='';
TablaFiltros.Cells[4,cuenta]:=leecampos(i,3);
TablaFiltros.RowCount:=TablaFiltros.RowCount+1;
if (leecampos(i,2)<>'')and (leecampos(i,2)<>'No Disponible') then
cuenta:=cuenta+1;
end;

end;
end;

procedure TFormaPreciosInventario.FormCreate(Sender: TObject);
begin
TablaFiltros.ColWidths[0]:=1;
TablaFiltros.ColWidths[1]:=80;
TablaFiltros.ColWidths[2]:=20;
TablaFiltros.ColWidths[3]:=40;
TablaFiltros.ColWidths[4]:=1;

TablaFiltros.Cells[0,0]:='Clave';
TablaFiltros.Cells[1,0]:='Campo';
TablaFiltros.Cells[2,0]:='Condición';
TablaFiltros.Cells[3,0]:='Valor';
end;

procedure TFormaPreciosInventario.BitBtn2Click(Sender: TObject);
begin
Tag:=0;
Close;
end;

procedure TFormaPreciosInventario.BitBtn1Click(Sender: TObject);
begin
Tag:=1;

datosdefiltrado(condiciones1);
filtratablatipo(FormaInventario.TablaInventario);
FormaInventario.TablaInventario.Filtered:=True;
EjecutaFiltrado;
FormaInventario.TablaInventario.Filtered:=False;

Close;
end;




procedure TFormaPreciosInventario.Panel2Click(Sender: TObject);
begin
Close;
end;






procedure TFormaPreciosInventario.Label2MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
SendMessage(FormaPreciosInventario.Handle, WM_SYSCOMMAND, $F012, 0);

end;

procedure TFormaPreciosInventario.TablaFiltrosKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
{if key=13 then
TablaFiltros.}
end;


procedure TFormaPreciosInventario.Label3Click(Sender: TObject);
begin
if Label3.Caption='Monto $' then
FormaPreciosInventario.Label3.Caption:='Porcentaje %'
else
FormaPreciosInventario.Label3.Caption:='Monto $';

end;

end.
