unit Costeo;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Db, DBTables, Grids, StdCtrls, Buttons, ExtCtrls,conver;

type
  TFormaCosteo = class(TForm)
    Detalle: TStringGrid;
    TablaCosteo: TTable;
    TablaCosteoCLDOC_MI: TFloatField;
    TablaCosteoCLPRO_MI: TStringField;
    TablaCosteoFEDOC_MI: TDateField;
    TablaCosteoCANTI_MI: TFloatField;
    TablaCosteoPUNIT_MI: TFloatField;
    TablaCosteoCOSUN_MI: TFloatField;
    De: TEdit;
    Hasta: TEdit;
    BitBtn1: TBitBtn;
    Bevel1: TBevel;
    EtiquetaEntradas: TLabel;
    EtiquetaSalidas: TLabel;
    EtiquetaUtilidad: TLabel;
    Shape1: TShape;
    Panel1: TPanel;
    Bevel9: TBevel;
    Bevel10: TBevel;
    Bevel11: TBevel;
    Label3: TLabel;
    Panel2: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    Label4: TLabel;
    procedure BitBtn1Click(Sender: TObject);
    procedure Panel2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Panel1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Label4MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FormaCosteo: TFormaCosteo;

implementation

{$R *.DFM}
procedure anchocampos;
begin

with FormaCosteo do
begin

Detalle.ColWidths[1]:=150;
Detalle.ColWidths[2]:=80;
Detalle.ColWidths[3]:=150;
Detalle.ColWidths[4]:=120;
Detalle.ColWidths[5]:=120;
Detalle.ColWidths[6]:=120;
Detalle.ColWidths[7]:=120;


Detalle.Cells[1,0]:='Fecha';
Detalle.Cells[2,0]:='Documento';
Detalle.Cells[3,0]:='Producto';
Detalle.Cells[4,0]:='Entradas';
Detalle.Cells[5,0]:='T. Compra';
Detalle.Cells[6,0]:='Salidas';
Detalle.Cells[7,0]:='T. Venta';


end;

end;

procedure insertainformacion;
var
i:integer;
entradas,salidas:Currency;
begin
with FormaCosteo do
begin
if (De.Text<>'')and(Hasta.Text<>'') then
Tablacosteo.SetRange([De.Text],[Hasta.Text]);
i:=1;
if Tablacosteo.State=dsInactive then
TablaCosteo.Open;

TablaCosteo.First;
entradas:=0;salidas:=0;
while not Tablacosteo.Eof do
begin
if Detalle.Rowcount<i then Detalle.rowCount:=i+1;

Detalle.Cells[1,i]:=TablaCosteo.FieldByName('FEDOC_MI').AsString;
Detalle.Cells[2,i]:=TablaCosteo.FieldByName('CANTI_MI').AsString;
Detalle.Cells[3,i]:=TablaCosteo.FieldByName('CLPRO_MI').AsString;
Detalle.Cells[4,i]:=TablaCosteo.FieldByName('COSUN_MI').AsString;
Detalle.Cells[5,i]:=FloatToStr(TablaCosteo.FieldByName('CANTI_MI').AsFloat*TablaCosteo.FieldByName('COSUN_MI').AsFloat);
Detalle.Cells[6,i]:=TablaCosteo.FieldByName('PUNIT_MI').AsString;
Detalle.Cells[6,i]:=FloatToStr(TablaCosteo.FieldByName('CANTI_MI').AsFloat*TablaCosteo.FieldByName('PUNIT_MI').AsFloat);

entradas:=entradas+(TablaCosteo.FieldByName('CANTI_MI').AsFloat*TablaCosteo.FieldByName('COSUN_MI').AsFloat);
salidas:=salidas+(TablaCosteo.FieldByName('CANTI_MI').AsFloat*TablaCosteo.FieldByName('PUNIT_MI').AsFloat);

TablaCosteo.Next;
i:=i+1;
end;
if Tablacosteo.State=dsBrowse then
TablaCosteo.Close;

EtiquetaEntradas.Caption:='Costo de Ventas '+convierte('###,###,##0.00',FloatToStr(entradas),'$');
EtiquetaSalidas.Caption:='Ventas Netas '+convierte('###,###,##0.00',FloatToStr(salidas),'$');
EtiquetaUtilidad.Caption:='Utilidad '+convierte('###,###,##0.00',FloatToStr(salidas-entradas),'$');
end;
end;

procedure TFormaCosteo.BitBtn1Click(Sender: TObject);
begin
if TablaCosteo.State=dsInactive then
TablaCosteo.Open;
anchocampos;
insertainformacion;

end;



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

procedure TFormaCosteo.FormCreate(Sender: TObject);
begin
{Detalle.GridLineColor:=clGreen;}
end;

procedure TFormaCosteo.Panel1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
SendMessage(FormaCosteo.Handle, WM_SYSCOMMAND, $F012, 0);
end;

procedure TFormaCosteo.Label4MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
SendMessage(FormaCosteo.Handle, WM_SYSCOMMAND, $F012, 0);
end;

end.
