unit uoperations;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, StdCtrls, Mask, DBCtrls, ExtCtrls, Buttons, IBCustomDataSet,
  IBQuery,Ibtable, IBUpdateSQL, Grids, DBGrids, ComCtrls, ToolEdit,
  RXDBCtrl, dxCore, dxButton, CurrEdit, SMIBase, SMIWiz;

type
  TFrmoperations = class(TForm)
    Panel1: TPanel;
    GroupBox2: TGroupBox;
    PageControl1: TPageControl;
    Dsdevise: TDataSource;
    TabSheet1: TTabSheet;
    DBGrid1: TDBGrid;
    dxButton4: TdxButton;
    dxButton5: TdxButton;
    dxButton6: TdxButton;
    dxButton7: TdxButton;
    Dsemprunts: TDataSource;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    DBEdit1: TDBEdit;
    DBEdit2: TDBEdit;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    DBEdit3: TDBEdit;
    Label8: TLabel;
    Label35: TLabel;
    DBComboBox9: TDBComboBox;
    Label9: TLabel;
    DBEdit4: TDBEdit;
    Label11: TLabel;
    Label12: TLabel;
    DBEdit5: TDBEdit;
    DBComboBox2: TDBComboBox;
    Label13: TLabel;
    DBComboBox3: TDBComboBox;
    Label14: TLabel;
    DBEdit6: TDBEdit;
    Dsoperationssanscontre: TDataSource;
    BitBtn3: TBitBtn;
    TabSheet3: TTabSheet;
    TabSheet4: TTabSheet;
    Dsmontants: TDataSource;
    Label1: TLabel;
    DBEdit9: TDBEdit;
    Label10: TLabel;
    DBEdit10: TDBEdit;
    Label21: TLabel;
    DBComboBox1: TDBComboBox;
    Label24: TLabel;
    DBComboBox4: TDBComboBox;
    Label25: TLabel;
    DBMemo1: TDBMemo;
    Label26: TLabel;
    DBComboBox8: TDBComboBox;
    Label27: TLabel;
    DBMemo2: TDBMemo;
    TabSheet2: TTabSheet;
    Label15: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    Label18: TLabel;
    Label19: TLabel;
    Label20: TLabel;
    Label22: TLabel;
    DBGrid2: TDBGrid;
    DBEdit7: TDBEdit;
    DBEdit8: TDBEdit;
    DBEdit13: TDBEdit;
    dxButton8: TdxButton;
    dxButton9: TdxButton;
    dxButton10: TdxButton;
    dxButton11: TdxButton;
    BitBtn4: TBitBtn;
    DBGrid3: TDBGrid;
    BitBtn1: TBitBtn;
    dxButton1: TdxButton;
    dxButton2: TdxButton;
    dxButton3: TdxButton;
    dxButton12: TdxButton;
    Label28: TLabel;
    Label29: TLabel;
    Label30: TLabel;
    DBEdit11: TDBEdit;
    DBEdit12: TDBEdit;
    Label31: TLabel;
    Label32: TLabel;
    Label33: TLabel;
    DBEdit17: TDBEdit;
    Label41: TLabel;
    Label52: TLabel;
    DBGrid4: TDBGrid;
    Dsterritoire: TDataSource;
    Dsoperationsaccord: TDataSource;
    Label54: TLabel;
    DBComboBox10: TDBComboBox;
    Label37: TLabel;
    DBComboBox6: TDBComboBox;
    Label38: TLabel;
    DBEdit15: TDBEdit;
    Label39: TLabel;
    DBComboBox7: TDBComboBox;
    Label40: TLabel;
    DBEdit16: TDBEdit;
    Label46: TLabel;
    DBComboBox12: TDBComboBox;
    Label47: TLabel;
    DBComboBox13: TDBComboBox;
    Label45: TLabel;
    DBEdit20: TDBEdit;
    Label48: TLabel;
    DBComboBox11: TDBComboBox;
    DBEdit21: TDBEdit;
    Label50: TLabel;
    Label51: TLabel;
    DBEdit22: TDBEdit;
    Label49: TLabel;
    DBEdit18: TDBEdit;
    Label42: TLabel;
    DBEdit23: TDBEdit;
    Label43: TLabel;
    DBEdit24: TDBEdit;
    Label44: TLabel;
    DBEdit19: TDBEdit;
    Label53: TLabel;
    Label55: TLabel;
    DBComboBox14: TDBComboBox;
    DBComboBox15: TDBComboBox;
    Label56: TLabel;
    Label57: TLabel;
    DBEdit25: TDBEdit;
    DBEdit26: TDBEdit;
    Label58: TLabel;
    DBEdit27: TDBEdit;
    Label59: TLabel;
    DBEdit28: TDBEdit;
    dxButton13: TdxButton;
    dxButton14: TdxButton;
    dxButton15: TdxButton;
    dxButton16: TdxButton;
    Label60: TLabel;
    Label61: TLabel;
    Label62: TLabel;
    DBEdit29: TDBEdit;
    DBEdit30: TDBEdit;
    Label63: TLabel;
    Label64: TLabel;
    Label65: TLabel;
    Label66: TLabel;
    DBEdit31: TDBEdit;
    Label23: TLabel;
    DBEdit14: TDBEdit;
    BitBtn2: TBitBtn;
    Label34: TLabel;
    CurrencyEdit1: TCurrencyEdit;
    CurrencyEdit2: TCurrencyEdit;
    CurrencyEdit3: TCurrencyEdit;
    CurrencyEdit4: TCurrencyEdit;
    Label70: TLabel;
    DBComboBox5: TDBComboBox;
    DBEdit32: TDBEdit;
    DBEdit33: TDBEdit;
    DBEdit34: TDBEdit;
    DBEdit35: TDBEdit;
    DBEdit36: TDBEdit;
    Label71: TLabel;
    DBEdit37: TDBEdit;
    Label72: TLabel;
    DBEdit38: TDBEdit;
    dxButton17: TdxButton;
    dxButton18: TdxButton;
    dxButton19: TdxButton;
    dxButton20: TdxButton;
    dxButton21: TdxButton;
    SMIWizardDlg1: TSMIWizardDlg;
    SMIWizardDlg2: TSMIWizardDlg;
    dxButton22: TdxButton;
    dxButton23: TdxButton;
    SMIWizardDlg3: TSMIWizardDlg;
    SMIWizardDlg4: TSMIWizardDlg;
    dxButton24: TdxButton;
    procedure PassageChampPrec();
    procedure PassageChampSuiv();
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure DBLookupComboBox1Exit(Sender: TObject);
    procedure dxButton3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure dxButton9Click(Sender: TObject);
    procedure dxButton10Click(Sender: TObject);
    procedure dxButton11Click(Sender: TObject);
    procedure dxButton5Click(Sender: TObject);
    procedure dxButton6Click(Sender: TObject);
    procedure dxButton7Click(Sender: TObject);
    procedure dxButton1Click(Sender: TObject);
    procedure dxButton2Click(Sender: TObject);
    procedure dxButton12Click(Sender: TObject);
    procedure dxButton4Click(Sender: TObject);
    procedure dxButton8Click(Sender: TObject);
    procedure dxButton13Click(Sender: TObject);
    procedure dxButton14Click(Sender: TObject);
    procedure dxButton15Click(Sender: TObject);
    procedure dxButton16Click(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
    procedure BitBtn4Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure DBEdit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure DBLookupComboBox3Exit(Sender: TObject);
    procedure DBLookupComboBox2Exit(Sender: TObject);
    procedure DBLookupComboBox5Exit(Sender: TObject);
    procedure DBEdit32DblClick(Sender: TObject);
    procedure DBEdit33DblClick(Sender: TObject);
    procedure DBEdit34DblClick(Sender: TObject);
    procedure DBEdit35DblClick(Sender: TObject);
    procedure DBEdit36DblClick(Sender: TObject);
    procedure DBEdit1DblClick(Sender: TObject);
    procedure DBEdit7DblClick(Sender: TObject);
    procedure DBEdit11DblClick(Sender: TObject);
    procedure DBEdit29DblClick(Sender: TObject);
    procedure DBEdit20Exit(Sender: TObject);
    procedure DBEdit18Exit(Sender: TObject);
    procedure DBEdit23Exit(Sender: TObject);
    procedure dxButton17Click(Sender: TObject);
    procedure dxButton18Click(Sender: TObject);
    procedure dxButton19Click(Sender: TObject);
    procedure dxButton20Click(Sender: TObject);
    procedure dxButton21Click(Sender: TObject);
    procedure dxButton22Click(Sender: TObject);
    procedure dxButton23Click(Sender: TObject);
    procedure dxButton24Click(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
    procedure DBComboBox9Exit(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Frmoperations: TFrmoperations;

implementation

uses usocietes, Umain,udataprix, Uparamsociete, UterritoireSELECT,
  UDEVISESELECT, USOCIETESESELECT;

{$R *.dfm}

procedure TFrmoperations.PassageChampSuiv();
begin
FindNextControl(Frmoperations.ActiveControl, true, true, false).SetFocus;
end;

procedure TFrmoperations.PassageChampPrec();
begin
FindNextControl(Frmoperations.ActiveControl, false, true, false).SetFocus;
end;

procedure TFrmoperations.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
 action:=caFree;
end;

procedure TFrmoperations.DBLookupComboBox1Exit(Sender: TObject);
begin
 Dataprix.Etatterritorial.LocateNext('code',Dataprix.montanttransactionsETATTERRITORIAL.Value,[locaseinsensitive]);
 label7.Caption:=Dataprix.EtatterritorialPAYS.Value;
end;

procedure TFrmoperations.dxButton3Click(Sender: TObject);
begin
  if(Application.MessageBox('Voulez-vous supprimer l''enregistrement en cours ?', 'Confirmation',MB_YESNO)= IDYES) then
  Dataprix.operationssanscontre.delete;
end;

procedure TFrmoperations.FormCreate(Sender: TObject);
   var t1,t2:real;
begin
   Dataprix.devise.Close;
   Dataprix.devise.Open;
   Dataprix.Etatterritorial.Close;
   Dataprix.Etatterritorial.Open;
 CASE FRMMAIN.indiCE OF
   1:BEGIN
      TabSheet2.Visible:=False;
      TabSheet3.Visible:=False;
      TabSheet4.Visible:=False;
      Panel1.Caption:='Opérations des montants des transactions';
      PageControl1.ActivePage:=TabSheet1;
      TabSheet2.Visible:=FALSE;
      TabSheet3.Visible:=FALSE;
      TabSheet4.Visible:=FALSE;
      TabSheet2.Enabled:=FALSE;
      TabSheet3.Enabled:=FALSE;
      TabSheet4.Enabled:=FALSE;
      Dataprix.montanttransactions.close;
      Dataprix.montanttransactions.params[0].value:=Dataprix.societemfiscal.value+Dataprix.societecle.value;
      Dataprix.montanttransactions.params[1].value:=Dataprix.societeexercice.value;
      Dataprix.montanttransactions.open;
      t1:=0;t2:=0;
      Dataprix.montanttransactions.first;
      while not(Dataprix.montanttransactions.Eof) do
        begin
         t1:=t1+Dataprix.montanttransactionsACHATS.Value;
         t2:=t2+Dataprix.montanttransactionsVENTES.Value;
         Dataprix.montanttransactions.next;
        end;
        CurrencyEdit1.Value:=T1;
        CurrencyEdit2.Value:=T2;
        Dataprix.montanttransactions.first;
      if  not(Dataprix.montanttransactions.eof) then
      begin
       Dataprix.Etatterritorial.Locate('code',Dataprix.montanttransactionsETATTERRITORIAL.Value,[locaseinsensitive]);
       label7.Caption:=Dataprix.EtatterritorialPAYS.Value;
      end;
     end;
   2:BEGIN
      TabSheet1.Visible:=False;
      TabSheet3.Visible:=False;
      TabSheet4.Visible:=False;
      Panel1.Caption:='Opérations des Emprunts et des Prets';
      PageControl1.ActivePage:=TabSheet2;
      TabSheet1.Visible:=FALSE;
      TabSheet3.Visible:=FALSE;
      TabSheet4.Visible:=FALSE;
      TabSheet1.Enabled:=FALSE;
      TabSheet3.Enabled:=FALSE;
      TabSheet4.Enabled:=FALSE;
      Dataprix.Empruntsprets.close;
      Dataprix.Empruntsprets.params[0].value:=Dataprix.societemfiscal.value+Dataprix.societecle.value;
      Dataprix.Empruntsprets.params[1].value:=Dataprix.societeexercice.value;
      Dataprix.Empruntsprets.open;
      t1:=0;t2:=0;
      Dataprix.Empruntsprets.first;
      while not(Dataprix.Empruntsprets.Eof) do
        begin
         t1:=t1+Dataprix.EmpruntspretsAUGMENTATIONS.Value;
         t2:=t2+Dataprix.EmpruntspretsDIMINUTIONS.Value;
         Dataprix.Empruntsprets.next;
        end;
        CurrencyEdit3.Value:=T1;
        CurrencyEdit4.Value:=T2;
        Dataprix.Empruntsprets.first;
      if  not(Dataprix.Empruntsprets.eof) then
      begin
       Dataprix.Etatterritorial.Locate('code',Dataprix.EmpruntspretsETATTERRITORIAL.Value,[locaseinsensitive]);
       label20.Caption:=Dataprix.EtatterritorialPAYS.Value;
      end;
     end;
   3:BEGIN
      TabSheet1.Visible:=False;
      TabSheet2.Visible:=False;
      TabSheet4.Visible:=False;
      Panel1.Caption:='Opérations sans contre partie ou avec contre partie non monétaire';
      PageControl1.ActivePage:=TabSheet3;
      TabSheet1.Visible:=FALSE;
      TabSheet2.Visible:=FALSE;
      TabSheet4.Visible:=FALSE;
      TabSheet1.Enabled:=FALSE;
      TabSheet2.Enabled:=FALSE;
      TabSheet4.Enabled:=FALSE;
      Dataprix.Empruntsprets.close;
      Dataprix.operationssanscontre.params[0].value:=Dataprix.societemfiscal.value+Dataprix.societecle.value;
      Dataprix.operationssanscontre.params[1].value:=Dataprix.societeexercice.value;
      Dataprix.operationssanscontre.open;
      if  not(Dataprix.operationssanscontre.eof) then
      begin
       Dataprix.Etatterritorial.Locate('code',Dataprix.operationssanscontreETATTERRITORIAL.Value,[locaseinsensitive]);
       label33.Caption:=Dataprix.EtatterritorialPAYS.Value;
      end;
     end;
    4:BEGIN
      TabSheet1.Visible:=False;
      TabSheet2.Visible:=False;
      TabSheet3.Visible:=False;
      Panel1.Caption:='Opérations avec accord préalable';
      PageControl1.ActivePage:=TabSheet4;
      TabSheet1.Visible:=FALSE;
      TabSheet2.Visible:=FALSE;
      TabSheet3.Visible:=FALSE;
      TabSheet1.Enabled:=FALSE;
      TabSheet2.Enabled:=FALSE;
      TabSheet3.Enabled:=FALSE;
      Dataprix.Empruntsprets.close;
      Dataprix.operationsaccord.params[0].value:=Dataprix.societemfiscal.value+Dataprix.societecle.value;
      Dataprix.operationsaccord.params[1].value:=Dataprix.societeexercice.value;
      Dataprix.operationsaccord.open;
      if  not(Dataprix.operationsaccord.eof) then
      begin
       Dataprix.Etatterritorial.Locate('code',Dataprix.operationsaccordETATTERRITORIAL.Value,[locaseinsensitive]);
       label65.Caption:=Dataprix.EtatterritorialPAYS.Value;
      end;
     end;
   end;
end;

procedure TFrmoperations.dxButton9Click(Sender: TObject);
begin
   Dataprix.Empruntsprets.Append;
   dbedit7.SetFocus;
end;

procedure TFrmoperations.dxButton10Click(Sender: TObject);
begin
  if(Application.MessageBox('Voulez-vous supprimer l''enregistrement en cours ?', 'Confirmation',MB_YESNO)= IDYES) then
  Dataprix.Empruntsprets.delete;
end;

procedure TFrmoperations.dxButton11Click(Sender: TObject);
begin
   Dataprix.Empruntsprets.edit;
end;

procedure TFrmoperations.dxButton5Click(Sender: TObject);
begin
 Dataprix.montanttransactions.Append;
 dbedit1.SetFocus;
end;

procedure TFrmoperations.dxButton6Click(Sender: TObject);
begin
if(Application.MessageBox('Voulez-vous supprimer l''enregistrement en cours ?', 'Confirmation',MB_YESNO)= IDYES) then
  Dataprix.montanttransactions.delete;
end;

procedure TFrmoperations.dxButton7Click(Sender: TObject);
begin
  Dataprix.montanttransactions.edit;
end;

procedure TFrmoperations.dxButton1Click(Sender: TObject);
begin
   if NOT(dataprix.operationssanscontre.State in [dsInsert, dsEdit]) then dataprix.operationssanscontre.EDIT;
   Dataprix.operationssanscontre.post;
   Dataprix.operationssanscontre.edit;
end;

procedure TFrmoperations.dxButton2Click(Sender: TObject);
begin
   Dataprix.operationssanscontre.Append;
   dbedit11.SetFocus;
end;

procedure TFrmoperations.dxButton12Click(Sender: TObject);
begin
   Dataprix.operationssanscontre.edit;
end;

procedure TFrmoperations.dxButton4Click(Sender: TObject);
  var t1,t2:real;
begin
   if NOT(dataprix.montanttransactions.State in [dsInsert, dsEdit]) then dataprix.montanttransactions.EDIT;
    Dataprix.montanttransactions.post;
    Dataprix.montanttransactions.edit;
    t1:=0;t2:=0;
      Dataprix.montanttransactions.first;
      while not(Dataprix.montanttransactions.Eof) do
        begin
         t1:=t1+Dataprix.montanttransactionsACHATS.Value;
         t2:=t2+Dataprix.montanttransactionsVENTES.Value;
         Dataprix.montanttransactions.next;
        end;
        CurrencyEdit1.Value:=T1;
        CurrencyEdit2.Value:=T2;
end;

procedure TFrmoperations.dxButton8Click(Sender: TObject);
   var t1,t2:real;
begin
   if NOT(dataprix.Empruntsprets.State in [dsInsert, dsEdit]) then dataprix.Empruntsprets.EDIT;
   Dataprix.Empruntsprets.post;
   Dataprix.Empruntsprets.edit;
   t1:=0;t2:=0;
      Dataprix.Empruntsprets.first;
      while not(Dataprix.Empruntsprets.Eof) do
        begin
         t1:=t1+Dataprix.EmpruntspretsAUGMENTATIONS.Value;
         t2:=t2+Dataprix.EmpruntspretsDIMINUTIONS.Value;
         Dataprix.Empruntsprets.next;
        end;
        CurrencyEdit3.Value:=T1;
        CurrencyEdit4.Value:=T2;
end;

procedure TFrmoperations.dxButton13Click(Sender: TObject);
begin
   if NOT(dataprix.operationsaccord.State in [dsInsert, dsEdit]) then dataprix.operationsaccord.EDIT;
    Dataprix.operationsaccord.post;
    Dataprix.operationsaccord.edit;
end;

procedure TFrmoperations.dxButton14Click(Sender: TObject);
begin
    Dataprix.operationssanscontre.Append;
   dbedit11.SetFocus;
end;

procedure TFrmoperations.dxButton15Click(Sender: TObject);
begin
   if(Application.MessageBox('Voulez-vous supprimer l''enregistrement en cours ?', 'Confirmation',MB_YESNO)= IDYES) then
   Dataprix.operationsaccord.delete;
end;

procedure TFrmoperations.dxButton16Click(Sender: TObject);
begin
   Dataprix.operationsaccord.edit;
end;

procedure TFrmoperations.BitBtn3Click(Sender: TObject);
begin
 close;
end;

procedure TFrmoperations.BitBtn4Click(Sender: TObject);
begin
 close;
end;

procedure TFrmoperations.BitBtn1Click(Sender: TObject);
begin
 close;
end;

procedure TFrmoperations.DBEdit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  case Key of
    13 :PassageChampSuiv();
    38 :PassageChampPrec();
    121: begin
       ModalResult := mrOk;
       dataprix.Societe.Post;
      frmparamsociete.close;
       end; //F10
    end;
end;

procedure TFrmoperations.DBLookupComboBox3Exit(Sender: TObject);
begin
 Dataprix.Etatterritorial.LocateNext('code',Dataprix.EmpruntspretsETATTERRITORIAL.Value,[locaseinsensitive]);
 label20.Caption:=Dataprix.EtatterritorialPAYS.Value;
end;

procedure TFrmoperations.DBLookupComboBox2Exit(Sender: TObject);
begin
 Dataprix.Etatterritorial.LocateNext('code',Dataprix.operationssanscontreETATTERRITORIAL.Value,[locaseinsensitive]);
 label33.Caption:=Dataprix.EtatterritorialPAYS.Value;
end;

procedure TFrmoperations.DBLookupComboBox5Exit(Sender: TObject);
begin
 Dataprix.Etatterritorial.LocateNext('code',Dataprix.operationsaccordETATTERRITORIAL.Value,[locaseinsensitive]);
 label65.Caption:=Dataprix.EtatterritorialPAYS.Value;
end;

procedure TFrmoperations.DBEdit32DblClick(Sender: TObject);
begin
  frmmain.libelle:='';frmmain.libelle1:='';
  Application.CreateForm(TFrmterritoireSELECT,FrmterritoireSELECT);
  FrmterritoireSELECT.ShowModal;
  if FrmterritoireSELECT.ModalResult=mrOk  then
   begin
    Dataprix.montanttransactionsETATTERRITORIAL.Value:=frmmain.libelle;
    label7.Caption:= frmmain.libelle1;
   end;
end;

procedure TFrmoperations.DBEdit33DblClick(Sender: TObject);
begin
  frmmain.libelle:='';frmmain.libelle1:='';
  Application.CreateForm(TFrmterritoireSELECT,FrmterritoireSELECT);
  FrmterritoireSELECT.ShowModal;
  if FrmterritoireSELECT.ModalResult=mrOk  then
   begin
    Dataprix.EmpruntspretsETATTERRITORIAL.Value:=frmmain.libelle;
    label20.Caption:= frmmain.libelle1;
   end;
end;

procedure TFrmoperations.DBEdit34DblClick(Sender: TObject);
begin
frmmain.libelle:='';frmmain.libelle1:='';
  Application.CreateForm(TFRMDEVISESELECT,FRMDEVISESELECT);
  FRMDEVISESELECT.ShowModal;
  if FRMDEVISESELECT.ModalResult=mrOk  then
   begin
    Dataprix.EmpruntspretsDEVISE.Value:=frmmain.libelle;
   end;
end;

procedure TFrmoperations.DBEdit35DblClick(Sender: TObject);
begin
  frmmain.libelle:='';frmmain.libelle1:='';
  Application.CreateForm(TFrmterritoireSELECT,FrmterritoireSELECT);
  FrmterritoireSELECT.ShowModal;
  if FrmterritoireSELECT.ModalResult=mrOk  then
   begin
    Dataprix.operationssanscontreETATTERRITORIAL.Value:=frmmain.libelle;
    label33.Caption:= frmmain.libelle1;
   end;
end;

procedure TFrmoperations.DBEdit36DblClick(Sender: TObject);
begin
  frmmain.libelle:='';frmmain.libelle1:='';
  Application.CreateForm(TFrmterritoireSELECT,FrmterritoireSELECT);
  FrmterritoireSELECT.ShowModal;
  if FrmterritoireSELECT.ModalResult=mrOk  then
   begin
    Dataprix.operationsaccordETATTERRITORIAL.Value:=frmmain.libelle;
    label65.Caption:= frmmain.libelle1;
   end;
end;

procedure TFrmoperations.DBEdit1DblClick(Sender: TObject);
begin
  frmmain.indice:=0;
  Application.CreateForm(TfrmSOCIETESESELECT,frmSOCIETESESELECT);
  frmSOCIETESESELECT.ShowModal;
 if frmmain.indice=1  then
   begin
    if not(dataprix.montanttransactions.state in [dsedit,dsinsert])  then  dataprix.montanttransactions.Edit;
     dataprix.montanttransactionsMATRICULEFISCAL.Value:=frmSOCIETESESELECT.societesMFISCALLIE.Value;
     dataprix.montanttransactionsAUTREIDENTIFIANT.Value:=frmSOCIETESESELECT.societesAUTREIDENTIFIANT.Value;
     dataprix.montanttransactionsETATTERRITORIAL.Value:=frmSOCIETESESELECT.societesETATTERRITOIRE.Value;
     dataprix.montanttransactionsRAISONSOCIALE.Value:=frmSOCIETESESELECT.societesRAISONSOCIALE.Value;
     dataprix.montanttransactionsQUALITE.Value:=frmSOCIETESESELECT.societesQUALITE.Value;
     dataprix.montanttransactionsAUTREQUALITE.Value:=frmSOCIETESESELECT.societesAUTREQUALITE.Value;
   end;
end;

procedure TFrmoperations.DBEdit7DblClick(Sender: TObject);
begin
  frmmain.indice:=0;
  Application.CreateForm(TfrmSOCIETESESELECT,frmSOCIETESESELECT);
  frmSOCIETESESELECT.ShowModal;
 if frmmain.indice=1  then
   begin
    if not(dataprix.Empruntsprets.state in [dsedit,dsinsert])  then  dataprix.Empruntsprets.Edit;
     dataprix.EmpruntspretsMATRICULEFISCAL.Value:=frmSOCIETESESELECT.societesMFISCALLIE.Value;
     dataprix.EmpruntspretsAUTREIDENTIFIANT.Value:=frmSOCIETESESELECT.societesAUTREIDENTIFIANT.Value;
     dataprix.EmpruntspretsETATTERRITORIAL.Value:=frmSOCIETESESELECT.societesETATTERRITOIRE.Value;
     dataprix.EmpruntspretsRAISONSOCIALE.Value:=frmSOCIETESESELECT.societesRAISONSOCIALE.Value;
     dataprix.EmpruntspretsQUALITE.Value:=frmSOCIETESESELECT.societesQUALITE.Value;
     dataprix.EmpruntspretsAUTREQUALITE.Value:=frmSOCIETESESELECT.societesAUTREQUALITE.Value;
   end;
end;

procedure TFrmoperations.DBEdit11DblClick(Sender: TObject);
begin
  frmmain.indice:=0;
  Application.CreateForm(TfrmSOCIETESESELECT,frmSOCIETESESELECT);
  frmSOCIETESESELECT.ShowModal;
 if frmmain.indice=1  then
   begin
    if not(dataprix.operationssanscontre.state in [dsedit,dsinsert])  then  dataprix.operationssanscontre.Edit;
     dataprix.operationssanscontreMATRICULEFISCAL.Value:=frmSOCIETESESELECT.societesMFISCALLIE.Value;
     dataprix.operationssanscontreAUTREIDENTIFIANT.Value:=frmSOCIETESESELECT.societesAUTREIDENTIFIANT.Value;
     dataprix.operationssanscontreETATTERRITORIAL.Value:=frmSOCIETESESELECT.societesETATTERRITOIRE.Value;
     dataprix.operationssanscontreRAISONSOCIALE.Value:=frmSOCIETESESELECT.societesRAISONSOCIALE.Value;
     dataprix.operationssanscontreQUALITE.Value:=frmSOCIETESESELECT.societesQUALITE.Value;
     dataprix.operationssanscontreAUTREQUALITE.Value:=frmSOCIETESESELECT.societesAUTREQUALITE.Value;
   end;
end;

procedure TFrmoperations.DBEdit29DblClick(Sender: TObject);
begin
  frmmain.indice:=0;
  Application.CreateForm(TfrmSOCIETESESELECT,frmSOCIETESESELECT);
  frmSOCIETESESELECT.ShowModal;
 if frmmain.indice=1  then
   begin
    if not(dataprix.operationsaccord.state in [dsedit,dsinsert])  then  dataprix.operationsaccord.Edit;
     dataprix.operationsaccordMATRICULEFISCAL.Value:=frmSOCIETESESELECT.societesMFISCALLIE.Value;
     dataprix.operationsaccordAUTREIDENTIFIANT.Value:=frmSOCIETESESELECT.societesAUTREIDENTIFIANT.Value;
     dataprix.operationsaccordETATTERRITORIAL.Value:=frmSOCIETESESELECT.societesETATTERRITOIRE.Value;
     dataprix.operationsaccordRAISONSOCIALE.Value:=frmSOCIETESESELECT.societesRAISONSOCIALE.Value;
     dataprix.operationsaccordQUALITE.Value:=frmSOCIETESESELECT.societesQUALITE.Value;
     dataprix.operationsaccordAUTREQUALITE.Value:=frmSOCIETESESELECT.societesAUTREQUALITE.Value;
   end;
end;

procedure TFrmoperations.DBEdit20Exit(Sender: TObject);
begin
 if Dataprix.EmpruntspretsSOLDEOUVERTURE.IsNull  then  Dataprix.EmpruntspretsSOLDEOUVERTURE.Value:=0;
 if Dataprix.EmpruntspretsAUGMENTATIONS.IsNull  then  Dataprix.EmpruntspretsAUGMENTATIONS.Value:=0;
 if Dataprix.EmpruntspretsDIMINUTIONS.IsNull  then  Dataprix.EmpruntspretsDIMINUTIONS.Value:=0;
 Dataprix.EmpruntspretsSOLDECLOTURE.Value:=Dataprix.EmpruntspretsSOLDEOUVERTURE.Value+Dataprix.EmpruntspretsAUGMENTATIONS.Value-Dataprix.EmpruntspretsDIMINUTIONS.Value;
end;

procedure TFrmoperations.DBEdit18Exit(Sender: TObject);
begin
 if Dataprix.EmpruntspretsSOLDEOUVERTURE.IsNull  then  Dataprix.EmpruntspretsSOLDEOUVERTURE.Value:=0;
 if Dataprix.EmpruntspretsAUGMENTATIONS.IsNull  then  Dataprix.EmpruntspretsAUGMENTATIONS.Value:=0;
 if Dataprix.EmpruntspretsDIMINUTIONS.IsNull  then  Dataprix.EmpruntspretsDIMINUTIONS.Value:=0;
 Dataprix.EmpruntspretsSOLDECLOTURE.Value:=Dataprix.EmpruntspretsSOLDEOUVERTURE.Value+Dataprix.EmpruntspretsAUGMENTATIONS.Value-Dataprix.EmpruntspretsDIMINUTIONS.Value;
end;

procedure TFrmoperations.DBEdit23Exit(Sender: TObject);
begin
 if Dataprix.EmpruntspretsSOLDEOUVERTURE.IsNull  then  Dataprix.EmpruntspretsSOLDEOUVERTURE.Value:=0;
 if Dataprix.EmpruntspretsAUGMENTATIONS.IsNull  then  Dataprix.EmpruntspretsAUGMENTATIONS.Value:=0;
 if Dataprix.EmpruntspretsDIMINUTIONS.IsNull  then  Dataprix.EmpruntspretsDIMINUTIONS.Value:=0;
 Dataprix.EmpruntspretsSOLDECLOTURE.Value:=Dataprix.EmpruntspretsSOLDEOUVERTURE.Value+Dataprix.EmpruntspretsAUGMENTATIONS.Value-Dataprix.EmpruntspretsDIMINUTIONS.Value;
end;

procedure TFrmoperations.dxButton17Click(Sender: TObject);
begin
 if(Application.MessageBox('Voulez-vous supprimer toute la liste des montants des transactions ?', 'Confirmation',MB_YESNO)= IDYES) then
 begin
  frmmain.ExecuterSql.Close;
  frmmain.ExecuterSql.SQL.Clear;
  frmmain.ExecuterSql.SQL.Add('delete from OPERATIONSMONTANTS');
  frmmain.ExecuterSql.open;
 end;
end;

procedure TFrmoperations.dxButton18Click(Sender: TObject);
begin
if(Application.MessageBox('Voulez-vous supprimer toutes les opérations d''emprunts et de prêts ?', 'Confirmation',MB_YESNO)= IDYES) then
 begin
  frmmain.ExecuterSql.Close;
  frmmain.ExecuterSql.SQL.Clear;
  frmmain.ExecuterSql.SQL.Add('delete from OPERATIONPRETEMPRUNT');
  frmmain.ExecuterSql.open;
 end;
end;

procedure TFrmoperations.dxButton19Click(Sender: TObject);
begin
if(Application.MessageBox('Voulez-vous supprimer toutes les opérations sans contre partie monétaire ?', 'Confirmation',MB_YESNO)= IDYES) then
 begin
  frmmain.ExecuterSql.Close;
  frmmain.ExecuterSql.SQL.Clear;
  frmmain.ExecuterSql.SQL.Add('delete from OPERATIONSANSCONTRE');
  frmmain.ExecuterSql.open;
 end;
end;

procedure TFrmoperations.dxButton20Click(Sender: TObject);
begin
 if(Application.MessageBox('Voulez-vous supprimer toutes les opérations avec accord préalable  ?', 'Confirmation',MB_YESNO)= IDYES) then
 begin
  frmmain.ExecuterSql.Close;
  frmmain.ExecuterSql.SQL.Clear;
  frmmain.ExecuterSql.SQL.Add('delete from OPERATIONRESCRITFISCAUX');
  frmmain.ExecuterSql.open;
 end;
end;

procedure TFrmoperations.dxButton21Click(Sender: TObject);
begin
 SMIWizardDlg1.EXECUTE;
end;

procedure TFrmoperations.dxButton22Click(Sender: TObject);
begin
 SMIWizardDlg2.EXECUTE;
end;

procedure TFrmoperations.dxButton23Click(Sender: TObject);
begin
  SMIWizardDlg3.EXECUTE;
end;

procedure TFrmoperations.dxButton24Click(Sender: TObject);
begin
 SMIWizardDlg4.EXECUTE;
end;

procedure TFrmoperations.PageControl1Change(Sender: TObject);
  var t1,t2:real;
begin
   Dataprix.devise.Close;
   Dataprix.devise.Open;
   Dataprix.Etatterritorial.Close;
   Dataprix.Etatterritorial.Open;
 CASE FRMMAIN.indiCE OF
   1:BEGIN
      TabSheet2.Visible:=False;
      TabSheet3.Visible:=False;
      TabSheet4.Visible:=False;
      Panel1.Caption:='Opérations des montants des transactions';
      PageControl1.ActivePage:=TabSheet1;
      TabSheet2.Visible:=FALSE;
      TabSheet3.Visible:=FALSE;
      TabSheet4.Visible:=FALSE;
      TabSheet2.Enabled:=FALSE;
      TabSheet3.Enabled:=FALSE;
      TabSheet4.Enabled:=FALSE;
      Dataprix.montanttransactions.close;
      Dataprix.montanttransactions.params[0].value:=Dataprix.societemfiscal.value+Dataprix.societecle.value;
      Dataprix.montanttransactions.params[1].value:=Dataprix.societeexercice.value;
      Dataprix.montanttransactions.open;
      t1:=0;t2:=0;
      Dataprix.montanttransactions.first;
      while not(Dataprix.montanttransactions.Eof) do
        begin
         t1:=t1+Dataprix.montanttransactionsACHATS.Value;
         t2:=t2+Dataprix.montanttransactionsVENTES.Value;
         Dataprix.montanttransactions.next;
        end;
        CurrencyEdit1.Value:=T1;
        CurrencyEdit2.Value:=T2;
        Dataprix.montanttransactions.first;
      if  not(Dataprix.montanttransactions.eof) then
      begin
       Dataprix.Etatterritorial.Locate('code',Dataprix.montanttransactionsETATTERRITORIAL.Value,[locaseinsensitive]);
       label7.Caption:=Dataprix.EtatterritorialPAYS.Value;
      end;
     end;
   2:BEGIN
      TabSheet1.Visible:=False;
      TabSheet3.Visible:=False;
      TabSheet4.Visible:=False;
      Panel1.Caption:='Opérations des Emprunts et des Prets';
      PageControl1.ActivePage:=TabSheet2;
      TabSheet1.Visible:=FALSE;
      TabSheet3.Visible:=FALSE;
      TabSheet4.Visible:=FALSE;
      TabSheet1.Enabled:=FALSE;
      TabSheet3.Enabled:=FALSE;
      TabSheet4.Enabled:=FALSE;
      Dataprix.Empruntsprets.close;
      Dataprix.Empruntsprets.params[0].value:=Dataprix.societemfiscal.value+Dataprix.societecle.value;
      Dataprix.Empruntsprets.params[1].value:=Dataprix.societeexercice.value;
      Dataprix.Empruntsprets.open;
      t1:=0;t2:=0;
      Dataprix.Empruntsprets.first;
      while not(Dataprix.Empruntsprets.Eof) do
        begin
         t1:=t1+Dataprix.EmpruntspretsAUGMENTATIONS.Value;
         t2:=t2+Dataprix.EmpruntspretsDIMINUTIONS.Value;
         Dataprix.Empruntsprets.next;
        end;
        CurrencyEdit3.Value:=T1;
        CurrencyEdit4.Value:=T2;
        Dataprix.Empruntsprets.first;
      if  not(Dataprix.Empruntsprets.eof) then
      begin
       Dataprix.Etatterritorial.Locate('code',Dataprix.EmpruntspretsETATTERRITORIAL.Value,[locaseinsensitive]);
       label20.Caption:=Dataprix.EtatterritorialPAYS.Value;
      end;
     end;
   3:BEGIN
      TabSheet1.Visible:=False;
      TabSheet2.Visible:=False;
      TabSheet4.Visible:=False;
      Panel1.Caption:='Opérations sans contre partie ou avec contre partie non monétaire';
      PageControl1.ActivePage:=TabSheet3;
      TabSheet1.Visible:=FALSE;
      TabSheet2.Visible:=FALSE;
      TabSheet4.Visible:=FALSE;
      TabSheet1.Enabled:=FALSE;
      TabSheet2.Enabled:=FALSE;
      TabSheet4.Enabled:=FALSE;
      Dataprix.Empruntsprets.close;
      Dataprix.operationssanscontre.params[0].value:=Dataprix.societemfiscal.value+Dataprix.societecle.value;
      Dataprix.operationssanscontre.params[1].value:=Dataprix.societeexercice.value;
      Dataprix.operationssanscontre.open;
      if  not(Dataprix.operationssanscontre.eof) then
      begin
       Dataprix.Etatterritorial.Locate('code',Dataprix.operationssanscontreETATTERRITORIAL.Value,[locaseinsensitive]);
       label33.Caption:=Dataprix.EtatterritorialPAYS.Value;
      end;
     end;
    4:BEGIN
      TabSheet1.Visible:=False;
      TabSheet2.Visible:=False;
      TabSheet3.Visible:=False;
      Panel1.Caption:='Opérations avec accord préalable';
      PageControl1.ActivePage:=TabSheet4;
      TabSheet1.Visible:=FALSE;
      TabSheet2.Visible:=FALSE;
      TabSheet3.Visible:=FALSE;
      TabSheet1.Enabled:=FALSE;
      TabSheet2.Enabled:=FALSE;
      TabSheet3.Enabled:=FALSE;
      Dataprix.Empruntsprets.close;
      Dataprix.operationsaccord.params[0].value:=Dataprix.societemfiscal.value+Dataprix.societecle.value;
      Dataprix.operationsaccord.params[1].value:=Dataprix.societeexercice.value;
      Dataprix.operationsaccord.open;
      if  not(Dataprix.operationsaccord.eof) then
      begin
       Dataprix.Etatterritorial.Locate('code',Dataprix.operationsaccordETATTERRITORIAL.Value,[locaseinsensitive]);
       label65.Caption:=Dataprix.EtatterritorialPAYS.Value;
      end;
     end;
   end;

end;

procedure TFrmoperations.DBComboBox9Exit(Sender: TObject);
  var typeop:string;
begin
   typeop:=trim(Dataprix.montanttransactionsNATUREOPERATIONS.Value);
   if  trim(Dataprix.montanttransactionsTYPEMONTANT.Value)='1'  then
     begin
       DBComboBox3.Items.Clear;
       DBComboBox3.Items.Add('1:Matière première');
       DBComboBox3.Items.Add('2:Produits finis ou semi-finis');
       DBComboBox3.Items.Add('3:marchandises');
       if (typeop<>'1') and (typeop<>'2') and (typeop<>'3') then
         begin
           Dataprix.montanttransactionsNATUREOPERATIONS.Value:='';
           showmessage('Veuillez choisir le type d''opérations correspondant au type des montants');
         end;
     end;
    if  trim(Dataprix.montanttransactionsTYPEMONTANT.Value)='2'  then
     begin
       DBComboBox3.Items.Clear;
       DBComboBox3.Items.Add('1:Loyers');
       DBComboBox3.Items.Add('2:Redevances');
       DBComboBox3.Items.Add('3:Rémunérations de franchise.');
       if (typeop<>'1') and (typeop<>'2') and (typeop<>'3') then
         begin
           Dataprix.montanttransactionsNATUREOPERATIONS.Value:='';
           showmessage('Veuillez choisir le type d''opérations correspondant au type des montants');
         end;
     end;
  if  trim(Dataprix.montanttransactionsTYPEMONTANT.Value)='3'  then
     begin
       DBComboBox3.Items.Clear;
       DBComboBox3.Items.Add('1:Gestion/Administration');
       DBComboBox3.Items.Add('2:Services techniques et rémunérations du travail intellectuel');
       DBComboBox3.Items.Add('3:Recherche et développement');
       DBComboBox3.Items.Add('4:Formation');
       DBComboBox3.Items.Add('5:commission');
       if (typeop<>'1') and (typeop<>'2') and (typeop<>'3') and (typeop<>'4') and (typeop<>'5') then
         begin
           Dataprix.montanttransactionsNATUREOPERATIONS.Value:='';
           showmessage('Veuillez choisir le type d''opérations correspondant au type des montants');
         end;
     end;
   if  trim(Dataprix.montanttransactionsTYPEMONTANT.Value)='4'  then
     begin
       DBComboBox3.Items.Clear;
       DBComboBox3.Items.Add('1:Intérêts');
       DBComboBox3.Items.Add('2:Frais de garantie et de caution');
       DBComboBox3.Items.Add('3:Leasing');
       DBComboBox3.Items.Add('4:Assurance');
       if (typeop<>'1') and (typeop<>'2') and (typeop<>'3') and (typeop<>'4') then
         begin
           Dataprix.montanttransactionsNATUREOPERATIONS.Value:='';
           showmessage('Veuillez choisir le type d''opérations correspondant au type des montants');
         end;
     end;
 if  trim(Dataprix.montanttransactionsTYPEMONTANT.Value)='5'  then
     begin
       DBComboBox3.Items.Clear;
       DBComboBox3.Items.Add('1:Brevets');
       DBComboBox3.Items.Add('2:Marques');
       DBComboBox3.Items.Add('3::Fonds de commerce');
       DBComboBox3.Items.Add('4:Autres actifs incorporels');
       DBComboBox3.Items.Add('5:Actifs corporels');
       DBComboBox3.Items.Add('6:Biens immeubles');
       if (typeop<>'1') and (typeop<>'2') and (typeop<>'3') and (typeop<>'4') and (typeop<>'5') and (typeop<>'6') then
         begin
           Dataprix.montanttransactionsNATUREOPERATIONS.Value:='';
           showmessage('Veuillez choisir le type d''opérations correspondant au type des montants');
         end;
     end;
 if  trim(Dataprix.montanttransactionsTYPEMONTANT.Value)='6'  then
     begin
       DBComboBox3.Items.Clear;
       DBComboBox3.Items.Add('1:Remboursements de frais');
       DBComboBox3.Items.Add('2:Coûts supportés pour la mise à disposition de personnel du groupe');

       if (typeop<>'1')  and (typeop<>'2') then
         begin
           Dataprix.montanttransactionsNATUREOPERATIONS.Value:='';
           showmessage('Veuillez choisir le type d''opérations correspondant au type des montants');
         end;
     end;


end;

end.
