Clomosy | Forum Ana Sayfa
Forum Anasayfa Forum Anasayfa > Genel Programlama > Genel İşlemler
  Aktif Konular Aktif Konular RSS - satir 105 veri tabaninda veriler dizi olarak almak
  SSS SSS  Forumu Ara   Etkinlikler   Kayıt Ol Kayıt Ol  Giriş Giriş

Clomosy Resmi Forum Sitesidir. Amacımız kullanıcılarımıza, iş ortaklarımıza, danışmanlara, yazılımcılara programlarımız hakkında destek ve bilgi vermektir.

satir 105 veri tabaninda veriler dizi olarak almak

 Yanıt Yaz Yanıt Yaz
Yazar
Mesaj
  Konu Arama Konu Arama  Topic Seçenekleri Topic Seçenekleri
Barthe_dev Açılır Kutu İzle
Yeni Üye
Yeni Üye


Kayıt Tarihi: 07 Temmuz 2026
Konum: konya
Durum: Aktif Değil
Puanlar: 31
Mesaj Seçenekleri Mesaj Seçenekleri   Teşekkürler (0) Teşekkürler(0)   Alıntı Barthe_dev Alıntı  Yanıt YazCevapla Mesajın Direkt Linki Konu: satir 105 veri tabaninda veriler dizi olarak almak
    Gönderim Zamanı: 4 Saat 14 Dakika Önce Saat 11:08
var
  SecretaryForm: TclForm;
  mainLayout, headerLayout, switcherLayout: TclLayout;
  scrollBody, pendingScrollBox, historyScrollBox, stockScrollBox: TclVertScrollBox;
  
  // Header
  lblKicker, lblTitle: TclProLabel;
  btnSwitchInvoice, btnSwitchStock: TclProButton;
  
  // Formulaire Facture
  formInvoicePanel: TclProPanel;
  lblFormTitle: TclProLabel;
  edtClient, edtAddress, edtProductRef, edtQty, edtUnitPrice: TclProEdit;
  btnSubmitInvoice, btnCancelEdit: TclProButton;
  editingInvoiceId: Integer;
  
  // Liste Factures en attente
  pendingPanel: TclProPanel;
  lblPendingTitle: TclProLabel;
  
  // Liste Historique du jour (Validées / Annulées)
  historyPanel: TclProPanel;
  lblHistoryTitle: TclProLabel;
  
  // Vue Stock
  stockPanel: TclProPanel;
  lblStockTitle: TclProLabel;
  
  // TabBar
  tabBarPanel: TclProPanel;
  btnTabInvoices, btnTabStockView, btnTabReports: TclProButton;
  
  // Navigation & HTTP
  Unitnavigate: TclUnit;
  restApi: TclRest;
  responseStr: String;
  rootObj: TclJsonObject;
  pendingArr, historyArr: TclJsonArray;
  itemObj: TclJsonObject;
  
  // Temporaires
  i: Integer;
  tempCard, tempStatusIcon: TclProPanel;
  tempLayout, tempActionsLayout: TclLayout;
  tempLabel, tempLabel2: TclProLabel;
  btnActionVal, btnActionEdit, btnActionDel: TclProButton;

// ============================================================
// BASCULE DE VUE (FACTURES vs STOCK)
// ============================================================
void ShowInvoiceSection;
{
  formInvoicePanel.Visible = True;
  pendingPanel.Visible = True;
  historyPanel.Visible = True;
  stockPanel.Visible = False;
  
  clComponent.SetupComponent(btnSwitchInvoice, '{"BackgroundColor":"#0d1520", "TextColor":"#00d4ff", "RoundHeight":10, "RoundWidth":10, "BorderColor":"#00d4ff40", "BorderWidth":1}');
  clComponent.SetupComponent(btnSwitchStock, '{"BackgroundColor":"#080d14", "TextColor":"#4a6580", "RoundHeight":10, "RoundWidth":10, "BorderColor":"#1a2d42", "BorderWidth":1}');
  clComponent.SetupComponent(btnTabInvoices, '{"BackgroundColor":"#07101c", "TextColor":"#00d4ff", "RoundHeight":0, "RoundWidth":0}');
  clComponent.SetupComponent(btnTabStockView, '{"BackgroundColor":"#07101c", "TextColor":"#4a6580", "RoundHeight":0, "RoundWidth":0}');
}

void ShowStockSection;
{
  formInvoicePanel.Visible = False;
  pendingPanel.Visible = False;
  historyPanel.Visible = False;
  stockPanel.Visible = True;
  
  clComponent.SetupComponent(btnSwitchInvoice, '{"BackgroundColor":"#080d14", "TextColor":"#4a6580", "RoundHeight":10, "RoundWidth":10, "BorderColor":"#1a2d42", "BorderWidth":1}');
  clComponent.SetupComponent(btnSwitchStock, '{"BackgroundColor":"#0d1520", "TextColor":"#00d4ff", "RoundHeight":10, "RoundWidth":10, "BorderColor":"#00d4ff40", "BorderWidth":1}');
  clComponent.SetupComponent(btnTabInvoices, '{"BackgroundColor":"#07101c", "TextColor":"#4a6580", "RoundHeight":0, "RoundWidth":0}');
  clComponent.SetupComponent(btnTabStockView, '{"BackgroundColor":"#07101c", "TextColor":"#00d4ff", "RoundHeight":0, "RoundWidth":0}');
}

// ============================================================
// CHARGEMENT ET RAFRAÎCHISSEMENT DYNAMIQUE DES FACTURES
// ============================================================
void LoadInvoicesData;
var
  iPending, iHist: Integer;
{
  restApi = TclRest.Create;
  try
    restApi.Method = rmGET;
    restApi.Accept = 'application/json';
    restApi.ConnectTimeOut = 10000;
    restApi.Execute;

    responseStr = restApi.Response;

    if ((responseStr <> '') && (Copy(responseStr, 1, 1) == '{')) 
    {
      rootObj = TCLJSON.ParseToJSONObject(responseStr);

      if ((rootObj <> nil) && (rootObj.GetValue('success') <> nil)) 
      {
        if (rootObj.GetValue('success').AsBoolean )
        {
          // --- 1. FACTURES EN ATTENTE ---
          if (rootObj.GetValue('pending') <> nil) 
          {
            pendingArr = TclJsonArray(rootObj.GetValue('pending'));
            if (pendingArr <> nil) 
            {
              for (iPending = 0 to pendingArr.Count - 1)
              {
                itemObj = pendingArr.GetItem(iPending);

                if (itemObj <> nil) 
                {
                  // 💡 Utilisation de l'ID unique BDD pour éviter les exceptions et le .Free
                  tempCard = SecretaryForm.AddNewProPanel(pendingScrollBox, 'pCard_ID_' + IntToStr(itemObj.GetValue('id').AsInteger));
                  tempCard.Align = alTop;
                  tempCard.Height = 75;
                  tempCard.Margins.Bottom = 8;
                  clComponent.SetupComponent(tempCard, '{"BackgroundColor":"#080d14", "RoundHeight":10, "RoundWidth":10, "BorderColor":"#1a2d42", "BorderWidth":1}');

                  tempLayout = SecretaryForm.AddNewLayout(tempCard, 'pTxt_ID_' + IntToStr(itemObj.GetValue('id').AsInteger));
                  tempLayout.Align = alClient;
                  tempLayout.Margins.Left = 10;
                  tempLayout.Margins.Top = 8;

                  tempLabel = SecretaryForm.AddNewProLabel(tempLayout, 'pLblTitle_ID_' + IntToStr(itemObj.GetValue('id').AsInteger), itemObj.GetValue('invoice_number').AsString + ' · ' + itemObj.GetValue('client_name').AsString);
                  tempLabel.Align = alTop;
                  tempLabel.clProSettings.FontSize = 12;
                  tempLabel.clProSettings.FontColor = clAlphaColor.clHexToColor('#e2eaf5');
                  tempLabel.clProSettings.TextSettings.Font.Style = [fsBold];
                  tempLabel.SetclProSettings(tempLabel.clProSettings);

                  tempLabel2 = SecretaryForm.AddNewProLabel(tempLayout, 'pLblSub_ID_' + IntToStr(itemObj.GetValue('id').AsInteger), itemObj.GetValue('product_ref').AsString + ' (' + IntToStr(itemObj.GetValue('quantity').AsInteger) + ' pcs) - Total: ' + FloatToStr(itemObj.GetValue('total_amount').AsFloat) + ' DA');
                  tempLabel2.Align = alTop;
                  tempLabel2.clProSettings.FontSize = 10;
                  tempLabel2.clProSettings.FontColor = clAlphaColor.clHexToColor('#00d4ff');
                  tempLabel2.Margins.Top = 4;
                  tempLabel2.SetclProSettings(tempLabel2.clProSettings);

                  tempActionsLayout = SecretaryForm.AddNewLayout(tempCard, 'pAct_ID_' + IntToStr(itemObj.GetValue('id').AsInteger));
                  tempActionsLayout.Align = alRight;
                  tempActionsLayout.Width = 110;
                  tempActionsLayout.Margins.Right = 6;
                  tempActionsLayout.Margins.Top = 12;

                  btnActionVal = SecretaryForm.AddNewProButton(tempActionsLayout, 'btnVal_' + IntToStr(itemObj.GetValue('id').AsInteger), '✓');
                  btnActionVal.Align = alLeft; btnActionVal.Width = 32; btnActionVal.Height = 32;
                  btnActionVal.Hint = IntToStr(itemObj.GetValue('id').AsInteger);
                  clComponent.SetupComponent(btnActionVal, '{"BackgroundColor":"#22c55e20", "TextColor":"#22c55e", "RoundHeight":6, "RoundWidth":6, "BorderColor":"#22c55e50", "BorderWidth":1}');
                  SecretaryForm.AddNewEvent(btnActionVal, tbeOnClick, 'OnValidateInvoice');

                  btnActionEdit = SecretaryForm.AddNewProButton(tempActionsLayout, 'btnEdit_' + IntToStr(itemObj.GetValue('id').AsInteger), '✏️');
                  btnActionEdit.Align = alLeft; btnActionEdit.Width = 32; btnActionEdit.Height = 32; btnActionEdit.Margins.Left = 4;
                  btnActionEdit.Hint = IntToStr(itemObj.GetValue('id').AsInteger);
                  clComponent.SetupComponent(btnActionEdit, '{"BackgroundColor":"#00d4ff20", "TextColor":"#00d4ff", "RoundHeight":6, "RoundWidth":6, "BorderColor":"#00d4ff50", "BorderWidth":1}');
                  SecretaryForm.AddNewEvent(btnActionEdit, tbeOnClick, 'OnEditInvoice');

                  btnActionDel = SecretaryForm.AddNewProButton(tempActionsLayout, 'btnDel_' + IntToStr(itemObj.GetValue('id').AsInteger), '🗑️');
                  btnActionDel.Align = alLeft; btnActionDel.Width = 32; btnActionDel.Height = 32; btnActionDel.Margins.Left = 4;
                  btnActionDel.Hint = IntToStr(itemObj.GetValue('id').AsInteger);
                  clComponent.SetupComponent(btnActionDel, '{"BackgroundColor":"#f8717120", "TextColor":"#f87171", "RoundHeight":6, "RoundWidth":6, "BorderColor":"#f8717150", "BorderWidth":1}');
                  SecretaryForm.AddNewEvent(btnActionDel, tbeOnClick, 'OnCancelInvoice');
               }
              }
            }
          }

          // --- 2. HISTORIQUE DU JOUR ---
          if (rootObj.GetValue('history') <> nil) 
          {
              historyArr = TclJsonArray(rootObj.GetValue('history'));
            if (historyArr <> nil) 
            {
              for (iHist = 0 to historyArr.Count - 1) 
              {
                itemObj = historyArr.GetItem(iHist);

                if (itemObj <> nil) 
                {
                  tempCard = SecretaryForm.AddNewProPanel(historyScrollBox, 'hCard_ID_' + IntToStr(itemObj.GetValue('id').AsInteger));
                  tempCard.Align = alTop; tempCard.Height = 58; tempCard.Margins.Bottom = 6;
                  clComponent.SetupComponent(tempCard, '{"BackgroundColor":"#080d14", "RoundHeight":8, "RoundWidth":8, "BorderColor":"#1a2d42", "BorderWidth":1}');

                  tempLayout = SecretaryForm.AddNewLayout(tempCard, 'hTxt_ID_' + IntToStr(itemObj.GetValue('id').AsInteger));
                  tempLayout.Align = alClient; tempLayout.Margins.Left = 10; tempLayout.Margins.Top = 6;

                  tempLabel = SecretaryForm.AddNewProLabel(tempLayout, 'hLblTitle_ID_' + IntToStr(itemObj.GetValue('id').AsInteger), itemObj.GetValue('invoice_number').AsString + ' · ' + itemObj.GetValue('client_name').AsString);
                  tempLabel.Align = alTop; tempLabel.clProSettings.FontSize = 11;
                  tempLabel.clProSettings.FontColor = clAlphaColor.clHexToColor('#e2eaf5');
                  tempLabel.SetclProSettings(tempLabel.clProSettings);

                  tempLabel2 = SecretaryForm.AddNewProLabel(tempLayout, 'hLblSub_ID_' + IntToStr(itemObj.GetValue('id').AsInteger), FloatToStr(itemObj.GetValue('total_amount').AsFloat) + ' DA · Status: ' + itemObj.GetValue('status').AsString);
                  tempLabel2.Align = alTop; tempLabel2.clProSettings.FontSize = 9;

                  if (itemObj.GetValue('status').AsString == 'validee') 
                  {
                    tempLabel2.clProSettings.FontColor = clAlphaColor.clHexToColor('#4ade80')
                  }
                  else
                  {
                    tempLabel2.clProSettings.FontColor = clAlphaColor.clHexToColor('#f87171');
                  }
                  tempLabel2.Margins.Top = 2; tempLabel2.SetclProSettings(tempLabel2.clProSettings);
               }
              }
            }
          }

       }
      }
    }
  finally{
    restApi.Free;
  }
  }
}

// ============================================================
// CRÉATION OU MODIFICATION D'UNE FACTURE
// ============================================================
void SubmitInvoice;
var
  payloadJson, cleanClient, cleanAddress, cleanRef: String;
{
  if ((edtClient.Text == '') || (edtProductRef.Text == '') || (edtQty.Text == '') || (edtUnitPrice.Text == '')) 
  {
    ShowMessage('⚠️ Veuillez remplir tous les champs obligatoires.');
    Exit;
  }

  /*// Nettoyage basique pour éviter de casser la structure du JSON
  cleanClient = StringReplace(edtClient.Text, '"', '\"', [rfReplaceAll]);
  cleanAddress = StringReplace(edtAddress.Text, '"', '\"', [rfReplaceAll]);
  cleanRef = StringReplace(edtProductRef.Text, '"', '\"', [rfReplaceAll]);*/

  // 1. Construction du JSON strict
  payloadJson = '{"id":' + IntToStr(editingInvoiceId) + ',' +
                 '"client":"' + edtClient.Text + '",' +
                 '"address":"' + edtAddress.Text + '",' +
                 '"product_ref":"' + edtProductRef.Text + '",' +
                 '"qty":' + edtQty.Text + ',' +
                 '"unit_price":' + edtUnitPrice.Text + '}';

  restApi = TclRest.Create;
  try
    // 2. Vérification stricte de l'URL avec le paramètre ?action=save_invoice
    restApi.Method = rmPOST;
    restApi.Accept = 'application/json';
    
    // 3. 🚨 POINT CLÉ : Utiliser AddBody avec le MimeType application/json !
    // Ne PAS utiliser "restApi.Body = payloadJson;"
    restApi.AddBody(payloadJson, 'application/json');
    restApi.Execute;

    responseStr = restApi.Response;

    // Affiche le diagnostic retourné par le PHP
    ShowMessage('📬 Réponse du serveur :' + #13#10 + responseStr);

  finally{
    restApi.Free;
  }
}
}
// ============================================================
// ÉDITION, CANCELLATION ET VALIDATION
// ============================================================
void OnEditInvoice;
var
  btnSenderEdit: TclProButton;
  invIdStr: String;
  j: Integer;
  foundItem: TclJsonObject;
{
  btnSenderEdit = TclProButton(SecretaryForm.ClSender);
  invIdStr = btnSenderEdit.Hint;

  if (pendingArr <> nil) 
  {
    for (j = 0 to pendingArr.Count - 1) 
    {
      foundItem = pendingArr.GetItem(j);
      if (IntToStr(foundItem.GetValue('id').AsInteger) == invIdStr) 
      {
        editingInvoiceId = foundItem.GetValue('id').AsInteger;
        edtClient.Text = foundItem.GetValue('client_name').AsString;
        
        if (foundItem.GetValue('delivery_address') <> nil) {
          edtAddress.Text = foundItem.GetValue('delivery_address').AsString
        }
        else{
          edtAddress.Text = '';
        }
        edtProductRef.Text = foundItem.GetValue('product_ref').AsString;
        edtQty.Text = IntToStr(foundItem.GetValue('quantity').AsInteger);
        
        if (foundItem.GetValue('unit_price') <> nil){
          edtUnitPrice.Text = FloatToStr(foundItem.GetValue('unit_price').AsFloat)
        }
        else{
          edtUnitPrice.Text = '0';
        }

        btnSubmitInvoice.Caption = 'Mettre à jour';
        btnCancelEdit.Visible = True;
        
        ShowMessage('💡 Données chargées. Modifiez puis cliquez sur Mettre à jour.');
        Exit;
     }
    }
  }
}

void CancelEdit;
{
  edtClient.Text = ''; edtAddress.Text = ''; edtProductRef.Text = ''; edtQty.Text = ''; edtUnitPrice.Text = '';
  editingInvoiceId = 0;
  btnSubmitInvoice.Caption = 'Émettre la Facture';
  btnCancelEdit.Visible = False;
}

void OnValidateInvoice;
var
  btnSenderVal: TclProButton;
  invIdStr: String;
{
  btnSenderVal = TclProButton(SecretaryForm.ClSender);
  invIdStr = btnSenderVal.Hint;

  restApi = TclRest.Create;
  try
    restApi.Method = rmPOST;
    restApi.Accept = 'application/json';
    restApi.Body = '{"id":' + invIdStr + '}';
    restApi.Execute;

    responseStr = restApi.Response;
    if (responseStr <> '') 
    {
      ShowMessage('📄 Reçu / PDF de Facturation généré avec succès !');
      LoadInvoicesData;
    }
  finally{
    restApi.Free;
  }
  }
}

void OnCancelInvoice;
var
  btnSenderCancel: TclProButton;
  invIdStr: String;
{
  btnSenderCancel = TclProButton(SecretaryForm.ClSender);
  invIdStr = btnSenderCancel.Hint;

  restApi = TclRest.Create;
  try
    restApi.Method = rmPOST;
    restApi.Accept = 'application/json';
    restApi.Body = '{"id":' + invIdStr + '}';
    restApi.Execute;

    LoadInvoicesData;
  finally{
    restApi.Free;
  }
  }
}

void GoReportView;
{
  Unitnavigate.UnitName = 'Gestion_stock_report';
  Unitnavigate.CallerForm = SecretaryForm;
  Unitnavigate.Run;
}

// ============================================================
// INITIALISATION DU FORMULAIRE
// ============================================================
{
  SecretaryForm = TclForm.Create(Self);
  SecretaryForm.SetFormColor('#080d14', '#0d1520', clGVertical);

  Unitnavigate = TclUnit.Create;
  editingInvoiceId = 0;

  if (not Clomosy.PlatformIsMobile) {
    SecretaryForm.clSetWindowState(fwsMaximized);

  // TAB BAR INFÉRIEURE
  tabBarPanel = SecretaryForm.AddNewProPanel(SecretaryForm, 'tabBarPanel');
  tabBarPanel.Align = alBottom; 
  tabBarPanel.Height = 58;
  clComponent.SetupComponent(tabBarPanel, '{"BackgroundColor":"#07101c", "BorderColor":"#1a2d42", "BorderWidth":1}');

  btnTabInvoices = SecretaryForm.AddNewProButton(tabBarPanel, 'btnTabInvoices', 'Factures');
  btnTabInvoices.Align = alLeft; 
  btnTabInvoices.Width = 120;
  clComponent.SetupComponent(btnTabInvoices, '{"BackgroundColor":"#07101c", "TextColor":"#00d4ff", "RoundHeight":0, "RoundWidth":0}');
  SecretaryForm.AddNewEvent(btnTabInvoices, tbeOnClick, 'ShowInvoiceSection');

  btnTabStockView = SecretaryForm.AddNewProButton(tabBarPanel, 'btnTabStockView', 'Stock');
  btnTabStockView.Align = alLeft; 
  btnTabStockView.Width = 120;
  clComponent.SetupComponent(btnTabStockView, '{"BackgroundColor":"#07101c", "TextColor":"#4a6580", "RoundHeight":0, "RoundWidth":0}');
  SecretaryForm.AddNewEvent(btnTabStockView, tbeOnClick, 'ShowStockSection');

  btnTabReports = SecretaryForm.AddNewProButton(tabBarPanel, 'btnTabReports', 'Rapport KPI');
  btnTabReports.Align = alClient;
  clComponent.SetupComponent(btnTabReports, '{"BackgroundColor":"#07101c", "TextColor":"#4a6580", "RoundHeight":0, "RoundWidth":0}');
  SecretaryForm.AddNewEvent(btnTabReports, tbeOnClick, 'GoReportView');

  // LAYOUT PRINCIPAL
  mainLayout = SecretaryForm.AddNewLayout(SecretaryForm, 'mainLayout');
  mainLayout.Align = alClient;

  // HEADER
  headerLayout = SecretaryForm.AddNewLayout(mainLayout, 'headerLayout');
  headerLayout.Align = alTop; 
  headerLayout.Height = 60; 
  headerLayout.Margins.Left = 16; 
  headerLayout.Margins.Right = 16;
  headerLayout.Margins.Top = 10;

  lblKicker = SecretaryForm.AddNewProLabel(headerLayout, 'lblKicker', 'ESPACE SECRÉTARIAT & COMMANDE');
  lblKicker.Align = alTop; 
  lblKicker.Height = 14;
  lblKicker.clProSettings.FontColor = clAlphaColor.clHexToColor('#00d4ff');
  lblKicker.clProSettings.FontSize = 10;
  lblKicker.clProSettings.TextSettings.Font.Style = [fsBold];
  lblKicker.SetclProSettings(lblKicker.clProSettings);

  lblTitle = SecretaryForm.AddNewProLabel(headerLayout, 'lblTitle', 'Facturation & Commandes');
  lblTitle.Align = alTop; 
  lblTitle.Height = 32;
  lblTitle.clProSettings.FontColor = clAlphaColor.clHexToColor('#e2eaf5');
  lblTitle.clProSettings.FontSize = 22;
  lblTitle.clProSettings.TextSettings.Font.Style = [fsBold];
  lblTitle.SetclProSettings(lblTitle.clProSettings);

  // SWITCHER DE SECTION
  switcherLayout = SecretaryForm.AddNewLayout(mainLayout, 'switcherLayout');
  switcherLayout.Align = alTop; 
  switcherLayout.Height = 40; 
  switcherLayout.Margins.Left = 16; 
  switcherLayout.Margins.Right = 16; 
  switcherLayout.Margins.Bottom = 10;

  btnSwitchInvoice = SecretaryForm.AddNewProButton(switcherLayout, 'btnSwitchInvoice', '📄 Créer Factures');
  btnSwitchInvoice.Align = alLeft; 
  btnSwitchInvoice.Width = 160;
  clComponent.SetupComponent(btnSwitchInvoice, '{"BackgroundColor":"#0d1520", "TextColor":"#00d4ff", "RoundHeight":10, "RoundWidth":10, "BorderColor":"#00d4ff40", "BorderWidth":1}');
  SecretaryForm.AddNewEvent(btnSwitchInvoice, tbeOnClick, 'ShowInvoiceSection');

  btnSwitchStock = SecretaryForm.AddNewProButton(switcherLayout, 'btnSwitchStock', '📦 Vérifier Stock');
  btnSwitchStock.Align = alRight; 
  btnSwitchStock.Width = 160;
  clComponent.SetupComponent(btnSwitchStock, '{"BackgroundColor":"#080d14", "TextColor":"#4a6580", "RoundHeight":10, "RoundWidth":10, "BorderColor":"#1a2d42", "BorderWidth":1}');
  SecretaryForm.AddNewEvent(btnSwitchStock, tbeOnClick, 'ShowStockSection');

  scrollBody = SecretaryForm.AddNewVertScrollBox(mainLayout, 'scrollBody');
  scrollBody.Align = alClient; 
  scrollBody.Margins.Left = 16; 
  scrollBody.Margins.Right = 16;

  // 1. FORMULAIRE DE CRÉATION
  formInvoicePanel = SecretaryForm.AddNewProPanel(scrollBody, 'formInvoicePanel');
  formInvoicePanel.Align = alTop; 
  formInvoicePanel.Height = 345; 
  formInvoicePanel.Margins.Bottom = 16;
  clComponent.SetupComponent(formInvoicePanel, '{"BackgroundColor":"#0d1520", "RoundHeight":16, "RoundWidth":16, "BorderColor":"#1a2d42", "BorderWidth":1}');

  lblFormTitle = SecretaryForm.AddNewProLabel(formInvoicePanel, 'lblFormTitle', '📄 ÉMETTRE UNE FACTURE');
  lblFormTitle.Align = alTop; 
  lblFormTitle.Height = 28; 
  lblFormTitle.Margins.Left = 14; 
  lblFormTitle.Margins.Top = 8;
  lblFormTitle.clProSettings.FontSize = 11; 
  lblFormTitle.clProSettings.FontColor = clAlphaColor.clHexToColor('#00d4ff');
  lblFormTitle.clProSettings.TextSettings.Font.Style = [fsBold];
  lblFormTitle.SetclProSettings(lblFormTitle.clProSettings);

  edtClient = SecretaryForm.AddNewProEdit(formInvoicePanel, 'edtClient', 'Nom du client...');
  edtClient.Align = alTop; 
  edtClient.Height = 38; 
  edtClient.Margins.Left = 14; 
  edtClient.Margins.Right = 14; 
  edtClient.Margins.Top = 4;
  clComponent.SetupComponent(edtClient, '{"BackgroundColor":"#080d14", "TextColor":"#e2eaf5", "RoundHeight":8, "RoundWidth":8, "BorderColor":"#1e3552", "BorderWidth":1}');

  edtAddress = SecretaryForm.AddNewProEdit(formInvoicePanel, 'edtAddress', 'Adresse de livraison...');
  edtAddress.Align = alTop; 
  edtAddress.Height = 38; 
  edtAddress.Margins.Left = 14; 
  edtAddress.Margins.Right = 14; 
  edtAddress.Margins.Top = 6;
  clComponent.SetupComponent(edtAddress, '{"BackgroundColor":"#080d14", "TextColor":"#e2eaf5", "RoundHeight":8, "RoundWidth":8, "BorderColor":"#1e3552", "BorderWidth":1}');

  edtProductRef = SecretaryForm.AddNewProEdit(formInvoicePanel, 'edtProductRef', 'Référence produit...');
  edtProductRef.Align = alTop; 
  edtProductRef.Height = 38; 
  edtProductRef.Margins.Left = 14; 
  edtProductRef.Margins.Right = 14; 
  edtProductRef.Margins.Top = 6;
  clComponent.SetupComponent(edtProductRef, '{"BackgroundColor":"#080d14", "TextColor":"#e2eaf5", "RoundHeight":8, "RoundWidth":8, "BorderColor":"#1e3552", "BorderWidth":1}');

  tempLayout = SecretaryForm.AddNewLayout(formInvoicePanel, 'rowQtyPrice');
  tempLayout.Align = alTop; 
  tempLayout.Height = 38; 
  tempLayout.Margins.Left = 14; 
  tempLayout.Margins.Right = 14; 
  tempLayout.Margins.Top = 6;

  edtQty = SecretaryForm.AddNewProEdit(tempLayout, 'edtQty', 'Qté');
  edtQty.Align = alLeft; 
  edtQty.Width = 140;
  clComponent.SetupComponent(edtQty, '{"BackgroundColor":"#080d14", "TextColor":"#e2eaf5", "RoundHeight":8, "RoundWidth":8, "BorderColor":"#1e3552", "BorderWidth":1}');

  edtUnitPrice = SecretaryForm.AddNewProEdit(tempLayout, 'edtUnitPrice', 'Prix Unitaire (DA)');
  edtUnitPrice.Align = alRight; 
  edtUnitPrice.Width = 150;
  clComponent.SetupComponent(edtUnitPrice, '{"BackgroundColor":"#080d14", "TextColor":"#e2eaf5", "RoundHeight":8, "RoundWidth":8, "BorderColor":"#1e3552", "BorderWidth":1}');

  btnSubmitInvoice = SecretaryForm.AddNewProButton(formInvoicePanel, 'btnSubmitInvoice', 'Émettre la Facture');
  btnSubmitInvoice.Align = alTop; 
  btnSubmitInvoice.Height = 40; 
  btnSubmitInvoice.Margins.Left = 14; 
  btnSubmitInvoice.Margins.Right = 14; 
  btnSubmitInvoice.Margins.Top = 10;
  clComponent.SetupComponent(btnSubmitInvoice, '{"BackgroundColor":"#00d4ff18", "TextColor":"#00d4ff", "RoundHeight":10, "RoundWidth":10, "BorderColor":"#00d4ff40", "BorderWidth":1}');
  SecretaryForm.AddNewEvent(btnSubmitInvoice, tbeOnClick, 'SubmitInvoice');

  btnCancelEdit = SecretaryForm.AddNewProButton(formInvoicePanel, 'btnCancelEdit', 'Annuler Modification');
  btnCancelEdit.Align = alTop; 
  btnCancelEdit.Height = 30; 
  btnCancelEdit.Margins.Left = 14; 
  btnCancelEdit.Margins.Right = 14; 
  btnCancelEdit.Margins.Top = 6;
  btnCancelEdit.Visible = False;
  clComponent.SetupComponent(btnCancelEdit, '{"BackgroundColor":"#f8717118", "TextColor":"#f87171", "RoundHeight":10, "RoundWidth":10, "BorderColor":"#f8717140", "BorderWidth":1}');
  SecretaryForm.AddNewEvent(btnCancelEdit, tbeOnClick, 'CancelEdit');

  // 2. FACTURES EN ATTENTE
  pendingPanel = SecretaryForm.AddNewProPanel(scrollBody, 'pendingPanel');
  pendingPanel.Align = alTop; 
  pendingPanel.Height = 240; 
  pendingPanel.Margins.Bottom = 14;
  clComponent.SetupComponent(pendingPanel, '{"BackgroundColor":"#0d1520", "RoundHeight":16, "RoundWidth":16, "BorderColor":"#1a2d42", "BorderWidth":1}');

  lblPendingTitle = SecretaryForm.AddNewProLabel(pendingPanel, 'lblPendingTitle', '⏳ FACTURES EN ATTENTE DE VALIDATION');
  lblPendingTitle.Align = alTop; 
  lblPendingTitle.Height = 28; 
  lblPendingTitle.Margins.Left = 14; 
  lblPendingTitle.Margins.Top = 8;
  lblPendingTitle.clProSettings.FontSize = 11; 
  lblPendingTitle.clProSettings.FontColor = clAlphaColor.clHexToColor('#e2eaf5');
  lblPendingTitle.clProSettings.TextSettings.Font.Style = [fsBold];
  lblPendingTitle.SetclProSettings(lblPendingTitle.clProSettings);

  pendingScrollBox = SecretaryForm.AddNewVertScrollBox(pendingPanel, 'pendingScrollBox');
  pendingScrollBox.Align = alClient; 
  pendingScrollBox.Margins.Left = 8; 
  pendingScrollBox.Margins.Right = 8;

  // 3. HISTORIQUE DU JOUR
  historyPanel = SecretaryForm.AddNewProPanel(scrollBody, 'historyPanel');
  historyPanel.Align = alTop; 
  historyPanel.Height = 220; 
  historyPanel.Margins.Bottom = 16;
  clComponent.SetupComponent(historyPanel, '{"BackgroundColor":"#0d1520", "RoundHeight":16, "RoundWidth":16, "BorderColor":"#1a2d42", "BorderWidth":1}');

  lblHistoryTitle = SecretaryForm.AddNewProLabel(historyPanel, 'lblHistoryTitle', '📋 HISTORIQUE DU JOUR (VALIDÉES & ANNULÉES)');
  lblHistoryTitle.Align = alTop; 
  lblHistoryTitle.Height = 28; 
  lblHistoryTitle.Margins.Left = 14; 
  lblHistoryTitle.Margins.Top = 8;
  lblHistoryTitle.clProSettings.FontSize = 11; 
  lblHistoryTitle.clProSettings.FontColor = clAlphaColor.clHexToColor('#4ade80');
  lblHistoryTitle.clProSettings.TextSettings.Font.Style = [fsBold];
  lblHistoryTitle.SetclProSettings(lblHistoryTitle.clProSettings);

  historyScrollBox = SecretaryForm.AddNewVertScrollBox(historyPanel, 'historyScrollBox');
  historyScrollBox.Align = alClient; 
  historyScrollBox.Margins.Left = 8; 
  historyScrollBox.Margins.Right = 8;

  // 4. CONSULTATION STOCK
  stockPanel = SecretaryForm.AddNewProPanel(scrollBody, 'stockPanel');
  stockPanel.Align = alTop; 
  stockPanel.Height = 300; 
  stockPanel.Visible = False;
  clComponent.SetupComponent(stockPanel, '{"BackgroundColor":"#0d1520", "RoundHeight":16, "RoundWidth":16, "BorderColor":"#1a2d42", "BorderWidth":1}');

  lblStockTitle = SecretaryForm.AddNewProLabel(stockPanel, 'lblStockTitle', '📦 VÉRIFICATION DU STOCK');
  lblStockTitle.Align = alTop; 
  lblStockTitle.Height = 28; 
  lblStockTitle.Margins.Left = 14; 
  lblStockTitle.Margins.Top = 8;
  lblStockTitle.clProSettings.FontSize = 11; 
  lblStockTitle.clProSettings.FontColor = clAlphaColor.clHexToColor('#00d4ff');
  lblStockTitle.clProSettings.TextSettings.Font.Style = [fsBold];
  lblStockTitle.SetclProSettings(lblStockTitle.clProSettings);

  tempLabel = SecretaryForm.AddNewProLabel(stockPanel, 'lblStockPlaceholder', 'Le module de consultation des stocks est en cours de déploiement...');
  tempLabel.Align = alClient; 
  tempLabel.Margins.Left = 14; 
  tempLabel.Margins.Right = 14; 
  tempLabel.Margins.Top = 24;
  tempLabel.clProSettings.FontSize = 12; 
  tempLabel.clProSettings.FontColor = clAlphaColor.clHexToColor('#4a6580');
  tempLabel.clProSettings.TextSettings.Font.Style = [fsItalic];
  tempLabel.SetclProSettings(tempLabel.clProSettings);

  // CHARGEMENT INITIAL DES DONNÉES
  LoadInvoicesData;

  SecretaryForm.Run;

}
}
https://static.cloudflareinsights.com/beacon.min.js/v4513226cdae34746b4dedf0b4dfa099e1781791509496" integrity="sha512-ZE9pZaUXND66v380QUtch/5sE9tPFh2zg45pR2PB0CVkCtOREv2AJKkSidISWkysEuQ0EH8faUU5du78bx87UQ==" data-cf-beacon="{"version":"2024.11.0","token":"439455f3e46c40b98dbd42a2f1a954d8","r":1}" crossorigin="anonymous">
Yukarı Dön
Emr.Erkmn Açılır Kutu İzle
Moderatör
Moderatör


Kayıt Tarihi: 28 Şubat 2025
Durum: Aktif
Puanlar: 991
Mesaj Seçenekleri Mesaj Seçenekleri   Teşekkürler (0) Teşekkürler(0)   Alıntı Emr.Erkmn Alıntı  Yanıt YazCevapla Mesajın Direkt Linki Gönderim Zamanı: 2 Saat 14 Dakika Önce Saat 13:08
Merhaba Barthez,

var
  SecretaryForm: TclForm;
  mainLayout, headerLayout, switcherLayout: TclLayout;
  scrollBody, pendingScrollBox, historyScrollBox, stockScrollBox: TclVertScrollBox;
  
  // Header
  lblKicker, lblTitle: TclProLabel;
  btnSwitchInvoice, btnSwitchStock: TclProButton;
  
  // Formulaire Facture
  formInvoicePanel: TclProPanel;
  lblFormTitle: TclProLabel;
  edtClient, edtAddress, edtProductRef, edtQty, edtUnitPrice: TclProEdit;
  btnSubmitInvoice, btnCancelEdit: TclProButton;
  editingInvoiceId: Integer;
  
  // Liste Factures en attente
  pendingPanel: TclProPanel;
  lblPendingTitle: TclProLabel;
  
  // Liste Historique du jour (Validées / Annulées)
  historyPanel: TclProPanel;
  lblHistoryTitle: TclProLabel;
  
  // Vue Stock
  stockPanel: TclProPanel;
  lblStockTitle: TclProLabel;
  
  // TabBar
  tabBarPanel: TclProPanel;
  btnTabInvoices, btnTabStockView, btnTabReports: TclProButton;
  
  // Navigation & HTTP
  Unitnavigate: TclUnit;
  restApi: TclRest;
  responseStr, pendingJson, historyJson: String; 
  rootObj: TclJsonObject;
  pendingArr, historyArr: TclJsonQuery; 
  
  // Temporaires
  i: Integer;
  tempCard, tempStatusIcon: TclProPanel;
  tempLayout, tempActionsLayout: TclLayout;
  tempLabel, tempLabel2: TclProLabel;
  btnActionVal, btnActionEdit, btnActionDel: TclProButton;

// ============================================================
// BASCULE DE VUE (FACTURES vs STOCK)
// ============================================================
void ShowInvoiceSection;
{
  formInvoicePanel.Visible = True;
  pendingPanel.Visible = True;
  historyPanel.Visible = True;
  stockPanel.Visible = False;
  
  clComponent.SetupComponent(btnSwitchInvoice, '{"BackgroundColor":"#0d1520", "TextColor":"#00d4ff", "RoundHeight":10, "RoundWidth":10, "BorderColor":"#00d4ff40", "BorderWidth":1}');
  clComponent.SetupComponent(btnSwitchStock, '{"BackgroundColor":"#080d14", "TextColor":"#4a6580", "RoundHeight":10, "RoundWidth":10, "BorderColor":"#1a2d42", "BorderWidth":1}');
  clComponent.SetupComponent(btnTabInvoices, '{"BackgroundColor":"#07101c", "TextColor":"#00d4ff", "RoundHeight":0, "RoundWidth":0}');
  clComponent.SetupComponent(btnTabStockView, '{"BackgroundColor":"#07101c", "TextColor":"#4a6580", "RoundHeight":0, "RoundWidth":0}');
}

void ShowStockSection;
{
  formInvoicePanel.Visible = False;
  pendingPanel.Visible = False;
  historyPanel.Visible = False;
  stockPanel.Visible = True;
  
  clComponent.SetupComponent(btnSwitchInvoice, '{"BackgroundColor":"#080d14", "TextColor":"#4a6580", "RoundHeight":10, "RoundWidth":10, "BorderColor":"#1a2d42", "BorderWidth":1}');
  clComponent.SetupComponent(btnSwitchStock, '{"BackgroundColor":"#0d1520", "TextColor":"#00d4ff", "RoundHeight":10, "RoundWidth":10, "BorderColor":"#00d4ff40", "BorderWidth":1}');
  clComponent.SetupComponent(btnTabInvoices, '{"BackgroundColor":"#07101c", "TextColor":"#4a6580", "RoundHeight":0, "RoundWidth":0}');
  clComponent.SetupComponent(btnTabStockView, '{"BackgroundColor":"#07101c", "TextColor":"#00d4ff", "RoundHeight":0, "RoundWidth":0}');
}

// ============================================================
// CHARGEMENT ET RAFRAÎCHISSEMENT DYNAMIQUE DES FACTURES
// ============================================================
void LoadInvoicesData;
{
  restApi = TclRest.Create;
  try
    restApi.Method = rmGET;
    restApi.Accept = 'application/json';
    restApi.ConnectTimeOut = 10000;
    restApi.Execute;

    responseStr = restApi.Response;

    if ((responseStr <> '') && (Copy(responseStr, 1, 1) == '{')) 
    {
      rootObj = TCLJSON.ParseToJSONObject(responseStr);

      // HasKey kullanarak 'success' anahtarının varlığını kontrol ediyoruz
      if ((rootObj <> nil) && (rootObj.HasKey('success'))) 
      {
        if (rootObj.GetValue('success').AsBoolean)
        {
          // --- 1. FACTURES EN ATTENTE ---
          pendingArr = nil;
          
          // HasKey ile 'pending' anahtarının varlığını güvenle kontrol ediyoruz
          if (rootObj.HasKey('pending'))
          {
            pendingJson = rootObj.GetValue('pending').ToString;
            
            if ((pendingJson <> '') && (pendingJson <> '[]') && (pendingJson <> 'null'))
            {
              pendingArr = Clomosy.ClDataSetFromJSON(pendingJson);
              if (pendingArr <> nil) 
              {
                pendingArr.First; 
                while (not pendingArr.Eof)
                {
                  tempCard = SecretaryForm.AddNewProPanel(pendingScrollBox, 'pCard_ID_' + pendingArr.FieldByName('id').AsString);
                  tempCard.Align = alTop;
                  tempCard.Height = 75;
                  tempCard.Margins.Bottom = 8;
                  clComponent.SetupComponent(tempCard, '{"BackgroundColor":"#080d14", "RoundHeight":10, "RoundWidth":10, "BorderColor":"#1a2d42", "BorderWidth":1}');

                  tempLayout = SecretaryForm.AddNewLayout(tempCard, 'pTxt_ID_' + pendingArr.FieldByName('id').AsString);
                  tempLayout.Align = alClient;
                  tempLayout.Margins.Left = 10;
                  tempLayout.Margins.Top = 8;

                  tempLabel = SecretaryForm.AddNewProLabel(tempLayout, 'pLblTitle_ID_' + pendingArr.FieldByName('id').AsString, pendingArr.FieldByName('invoice_number').AsString + ' · ' + pendingArr.FieldByName('client_name').AsString);
                  tempLabel.Align = alTop;
                  tempLabel.clProSettings.FontSize = 12;
                  tempLabel.clProSettings.FontColor = clAlphaColor.clHexToColor('#e2eaf5');
                  tempLabel.clProSettings.TextSettings.Font.Style = [fsBold];
                  tempLabel.SetclProSettings(tempLabel.clProSettings);

                  tempLabel2 = SecretaryForm.AddNewProLabel(tempLayout, 'pLblSub_ID_' + pendingArr.FieldByName('id').AsString, pendingArr.FieldByName('product_ref').AsString + ' (' + pendingArr.FieldByName('quantity').AsString + ' pcs) - Total: ' + pendingArr.FieldByName('total_amount').AsString + ' DA');
                  tempLabel2.Align = alTop;
                  tempLabel2.clProSettings.FontSize = 10;
                  tempLabel2.clProSettings.FontColor = clAlphaColor.clHexToColor('#00d4ff');
                  tempLabel2.Margins.Top = 4;
                  tempLabel2.SetclProSettings(tempLabel2.clProSettings);

                  tempActionsLayout = SecretaryForm.AddNewLayout(tempCard, 'pAct_ID_' + pendingArr.FieldByName('id').AsString);
                  tempActionsLayout.Align = alRight;
                  tempActionsLayout.Width = 110;
                  tempActionsLayout.Margins.Right = 6;
                  tempActionsLayout.Margins.Top = 12;

                  btnActionVal = SecretaryForm.AddNewProButton(tempActionsLayout, 'btnVal_' + pendingArr.FieldByName('id').AsString, '✓');
                  btnActionVal.Align = alLeft; btnActionVal.Width = 32; btnActionVal.Height = 32;
                  btnActionVal.Hint = pendingArr.FieldByName('id').AsString;
                  clComponent.SetupComponent(btnActionVal, '{"BackgroundColor":"#22c55e20", "TextColor":"#22c55e", "RoundHeight":6, "RoundWidth":6, "BorderColor":"#22c55e50", "BorderWidth":1}');
                  SecretaryForm.AddNewEvent(btnActionVal, tbeOnClick, 'OnValidateInvoice');

                  btnActionEdit = SecretaryForm.AddNewProButton(tempActionsLayout, 'btnEdit_' + pendingArr.FieldByName('id').AsString, '✏️');
                  btnActionEdit.Align = alLeft; btnActionEdit.Width = 32; btnActionEdit.Height = 32; btnActionEdit.Margins.Left = 4;
                  btnActionEdit.Hint = pendingArr.FieldByName('id').AsString;
                  clComponent.SetupComponent(btnActionEdit, '{"BackgroundColor":"#00d4ff20", "TextColor":"#00d4ff", "RoundHeight":6, "RoundWidth":6, "BorderColor":"#00d4ff50", "BorderWidth":1}');
                  SecretaryForm.AddNewEvent(btnActionEdit, tbeOnClick, 'OnEditInvoice');

                  btnActionDel = SecretaryForm.AddNewProButton(tempActionsLayout, 'btnDel_' + pendingArr.FieldByName('id').AsString, '🗑️');
                  btnActionDel.Align = alLeft; btnActionDel.Width = 32; btnActionDel.Height = 32; btnActionDel.Margins.Left = 4;
                  btnActionDel.Hint = pendingArr.FieldByName('id').AsString;
                  clComponent.SetupComponent(btnActionDel, '{"BackgroundColor":"#f8717120", "TextColor":"#f87171", "RoundHeight":6, "RoundWidth":6, "BorderColor":"#f8717150", "BorderWidth":1}');
                  SecretaryForm.AddNewEvent(btnActionDel, tbeOnClick, 'OnCancelInvoice');
                  
                  pendingArr.Next;
                }
              }
            }
          }

          // --- 2. HISTORIQUE DU JOUR ---
          historyArr = nil;
          
          // HasKey ile 'history' anahtarının varlığını güvenle kontrol ediyoruz
          if (rootObj.HasKey('history'))
          {
            historyJson = rootObj.GetValue('history').ToString;
            
            if ((historyJson <> '') && (historyJson <> '[]') && (historyJson <> 'null'))
            {
              historyArr = Clomosy.ClDataSetFromJSON(historyJson);
              if (historyArr <> nil) 
              {
                historyArr.First;
                while (not historyArr.Eof) 
                {
                  tempCard = SecretaryForm.AddNewProPanel(historyScrollBox, 'hCard_ID_' + historyArr.FieldByName('id').AsString);
                  tempCard.Align = alTop; tempCard.Height = 58; tempCard.Margins.Bottom = 6;
                  clComponent.SetupComponent(tempCard, '{"BackgroundColor":"#080d14", "RoundHeight":8, "RoundWidth":8, "BorderColor":"#1a2d42", "BorderWidth":1}');

                  tempLayout = SecretaryForm.AddNewLayout(tempCard, 'hTxt_ID_' + historyArr.FieldByName('id').AsString);
                  tempLayout.Align = alClient; tempLayout.Margins.Left = 10; tempLayout.Margins.Top = 6;

                  tempLabel = SecretaryForm.AddNewProLabel(tempLayout, 'hLblTitle_ID_' + historyArr.FieldByName('id').AsString, historyArr.FieldByName('invoice_number').AsString + ' · ' + historyArr.FieldByName('client_name').AsString);
                  tempLabel.Align = alTop; tempLabel.clProSettings.FontSize = 11;
                  tempLabel.clProSettings.FontColor = clAlphaColor.clHexToColor('#e2eaf5');
                  tempLabel.SetclProSettings(tempLabel.clProSettings);

                  tempLabel2 = SecretaryForm.AddNewProLabel(tempLayout, 'hLblSub_ID_' + historyArr.FieldByName('id').AsString, historyArr.FieldByName('total_amount').AsString + ' DA · Status: ' + historyArr.FieldByName('status').AsString);
                  tempLabel2.Align = alTop; tempLabel2.clProSettings.FontSize = 9;

                  if (historyArr.FieldByName('status').AsString == 'validee') 
                  {
                    tempLabel2.clProSettings.FontColor = clAlphaColor.clHexToColor('#4ade80')
                  }
                  else
                  {
                    tempLabel2.clProSettings.FontColor = clAlphaColor.clHexToColor('#f87171');
                  }
                  tempLabel2.Margins.Top = 2; tempLabel2.SetclProSettings(tempLabel2.clProSettings);
                  
                  historyArr.Next;
                }
              }
            }
          }

        }
      }
    }
  finally
    restApi.Free;
  }
}

// ============================================================
// CRÉATION OU MODIFICATION D'UNE FACTURE
// ============================================================
void SubmitInvoice;
var
  payloadJson: String;
{
  if ((edtClient.Text == '') || (edtProductRef.Text == '') || (edtQty.Text == '') || (edtUnitPrice.Text == '')) 
  {
    ShowMessage('⚠️ Veuillez remplir tous les champs obligatoires.');
    Exit;
  }

  payloadJson = '{"id":' + IntToStr(editingInvoiceId) + ',' +
                 '"client":"' + edtClient.Text + '",' +
                 '"address":"' + edtAddress.Text + '",' +
                 '"product_ref":"' + edtProductRef.Text + '",' +
                 '"qty":' + edtQty.Text + ',' +
                 '"unit_price":' + edtUnitPrice.Text + '}';

  restApi = TclRest.Create;
  try
    restApi.Method = rmPOST;
    restApi.Accept = 'application/json';
    restApi.AddBody(payloadJson, 'application/json');
    restApi.Execute;

    responseStr = restApi.Response;
    ShowMessage('📬 Réponse du serveur :' + #13#10 + responseStr);
  finally
    restApi.Free;
  }
}

// ============================================================
// ÉDITION, CANCELLATION ET VALIDATION
// ============================================================
void OnEditInvoice;
var
  btnSenderEdit: TclProButton;
  invIdStr: String;
{
  btnSenderEdit = TclProButton(SecretaryForm.ClSender);
  invIdStr = btnSenderEdit.Hint;

  if (pendingArr <> nil) 
  {
    pendingArr.First;
    while (not pendingArr.Eof) 
    {
      if (pendingArr.FieldByName('id').AsString == invIdStr) 
      {
        editingInvoiceId = pendingArr.FieldByName('id').AsInteger;
        edtClient.Text = pendingArr.FieldByName('client_name').AsString;
        edtAddress.Text = pendingArr.FieldByName('delivery_address').AsString;
        edtProductRef.Text = pendingArr.FieldByName('product_ref').AsString;
        edtQty.Text = pendingArr.FieldByName('quantity').AsString;
        edtUnitPrice.Text = pendingArr.FieldByName('unit_price').AsString;

        btnSubmitInvoice.Caption = 'Mettre à jour';
        btnCancelEdit.Visible = True;
        
        ShowMessage('💡 Données chargées. Modifiez puis cliquez sur Mettre à jour.');
        Exit;
      }
      pendingArr.Next;
    }
  }
}

void CancelEdit;
{
  edtClient.Text = ''; edtAddress.Text = ''; edtProductRef.Text = ''; edtQty.Text = ''; edtUnitPrice.Text = '';
  editingInvoiceId = 0;
  btnSubmitInvoice.Caption = 'Émettre la Facture';
  btnCancelEdit.Visible = False;
}

void OnValidateInvoice;
var
  btnSenderVal: TclProButton;
  invIdStr: String;
{
  btnSenderVal = TclProButton(SecretaryForm.ClSender);
  invIdStr = btnSenderVal.Hint;

  restApi = TclRest.Create;
  try
    restApi.Method = rmPOST;
    restApi.Accept = 'application/json';
    restApi.AddBody('{"id":' + invIdStr + '}', 'application/json');
    restApi.Execute;

    responseStr = restApi.Response;
    if (responseStr <> '') 
    {
      ShowMessage('📄 Reçu / PDF de Facturation généré avec succès !');
      LoadInvoicesData;
    }
  finally
    restApi.Free;
  }
}

void OnCancelInvoice;
var
  btnSenderCancel: TclProButton;
  invIdStr: String;
{
  btnSenderCancel = TclProButton(SecretaryForm.ClSender);
  invIdStr = btnSenderCancel.Hint;

  restApi = TclRest.Create;
  try
    restApi.Method = rmPOST;
    restApi.Accept = 'application/json';
    restApi.AddBody('{"id":' + invIdStr + '}', 'application/json');
    restApi.Execute;

    LoadInvoicesData;
  finally
    restApi.Free;
  }
}

void GoReportView;
{
  Unitnavigate.UnitName = 'Gestion_stock_report';
  Unitnavigate.CallerForm = SecretaryForm;
  Unitnavigate.Run;
}

// ============================================================
// INITIALISATION DU FORMULAIRE
// ============================================================
{
  SecretaryForm = TclForm.Create(Self);
  SecretaryForm.SetFormColor('#080d14', '#0d1520', clGVertical);

  Unitnavigate = TclUnit.Create;
  editingInvoiceId = 0;

  if (not Clomosy.PlatformIsMobile) {
    SecretaryForm.clSetWindowState(fwsMaximized);
  }

  // TAB BAR INFÉRIEURE
  tabBarPanel = SecretaryForm.AddNewProPanel(SecretaryForm, 'tabBarPanel');
  tabBarPanel.Align = alBottom; 
  tabBarPanel.Height = 58;
  clComponent.SetupComponent(tabBarPanel, '{"BackgroundColor":"#07101c", "BorderColor":"#1a2d42", "BorderWidth":1}');

  btnTabInvoices = SecretaryForm.AddNewProButton(tabBarPanel, 'btnTabInvoices', 'Factures');
  btnTabInvoices.Align = alLeft; 
  btnTabInvoices.Width = 120;
  clComponent.SetupComponent(btnTabInvoices, '{"BackgroundColor":"#07101c", "TextColor":"#00d4ff", "RoundHeight":0, "RoundWidth":0}');
  SecretaryForm.AddNewEvent(btnTabInvoices, tbeOnClick, 'ShowInvoiceSection');

  btnTabStockView = SecretaryForm.AddNewProButton(tabBarPanel, 'btnTabStockView', 'Stock');
  btnTabStockView.Align = alLeft; 
  btnTabStockView.Width = 120;
  clComponent.SetupComponent(btnTabStockView, '{"BackgroundColor":"#07101c", "TextColor":"#4a6580", "RoundHeight":0, "RoundWidth":0}');
  SecretaryForm.AddNewEvent(btnTabStockView, tbeOnClick, 'ShowStockSection');

  btnTabReports = SecretaryForm.AddNewProButton(tabBarPanel, 'btnTabReports', 'Rapport KPI');
  btnTabReports.Align = alClient;
  clComponent.SetupComponent(btnTabReports, '{"BackgroundColor":"#07101c", "TextColor":"#4a6580", "RoundHeight":0, "RoundWidth":0}');
  SecretaryForm.AddNewEvent(btnTabReports, tbeOnClick, 'GoReportView');

  // LAYOUT PRINCIPAL
  mainLayout = SecretaryForm.AddNewLayout(SecretaryForm, 'mainLayout');
  mainLayout.Align = alClient;

  // HEADER
  headerLayout = SecretaryForm.AddNewLayout(mainLayout, 'headerLayout');
  headerLayout.Align = alTop; 
  headerLayout.Height = 60; 
  headerLayout.Margins.Left = 16; 
  headerLayout.Margins.Right = 16;
  headerLayout.Margins.Top = 10;

  lblKicker = SecretaryForm.AddNewProLabel(headerLayout, 'lblKicker', 'ESPACE SECRÉTARIAT & COMMANDE');
  lblKicker.Align = alTop; 
  lblKicker.Height = 14;
  lblKicker.clProSettings.FontColor = clAlphaColor.clHexToColor('#00d4ff');
  lblKicker.clProSettings.FontSize = 10;
  lblKicker.clProSettings.TextSettings.Font.Style = [fsBold];
  lblKicker.SetclProSettings(lblKicker.clProSettings);

  lblTitle = SecretaryForm.AddNewProLabel(headerLayout, 'lblTitle', 'Facturation & Commandes');
  lblTitle.Align = alTop; 
  lblTitle.Height = 32;
  lblTitle.clProSettings.FontColor = clAlphaColor.clHexToColor('#e2eaf5');
  lblTitle.clProSettings.FontSize = 22;
  lblTitle.clProSettings.TextSettings.Font.Style = [fsBold];
  lblTitle.SetclProSettings(lblTitle.clProSettings);

  // SWITCHER DE SECTION
  switcherLayout = SecretaryForm.AddNewLayout(mainLayout, 'switcherLayout');
  switcherLayout.Align = alTop; 
  switcherLayout.Height = 40; 
  switcherLayout.Margins.Left = 16; 
  switcherLayout.Margins.Right = 16; 
  switcherLayout.Margins.Bottom = 10;

  btnSwitchInvoice = SecretaryForm.AddNewProButton(switcherLayout, 'btnSwitchInvoice', '📄 Créer Factures');
  btnSwitchInvoice.Align = alLeft; 
  btnSwitchInvoice.Width = 160;
  clComponent.SetupComponent(btnSwitchInvoice, '{"BackgroundColor":"#0d1520", "TextColor":"#00d4ff", "RoundHeight":10, "RoundWidth":10, "BorderColor":"#00d4ff40", "BorderWidth":1}');
  SecretaryForm.AddNewEvent(btnSwitchInvoice, tbeOnClick, 'ShowInvoiceSection');

  btnSwitchStock = SecretaryForm.AddNewProButton(switcherLayout, 'btnSwitchStock', '📦 Vérifier Stock');
  btnSwitchStock.Align = alRight; 
  btnSwitchStock.Width = 160;
  clComponent.SetupComponent(btnSwitchStock, '{"BackgroundColor":"#080d14", "TextColor":"#4a6580", "RoundHeight":10, "RoundWidth":10, "BorderColor":"#1a2d42", "BorderWidth":1}');
  SecretaryForm.AddNewEvent(btnSwitchStock, tbeOnClick, 'ShowStockSection');

  scrollBody = SecretaryForm.AddNewVertScrollBox(mainLayout, 'scrollBody');
  scrollBody.Align = alClient; 
  scrollBody.Margins.Left = 16; 
  scrollBody.Margins.Right = 16;

  // 1. FORMULAIRE DE CRÉATION
  formInvoicePanel = SecretaryForm.AddNewProPanel(scrollBody, 'formInvoicePanel');
  formInvoicePanel.Align = alTop; 
  formInvoicePanel.Height = 345; 
  formInvoicePanel.Margins.Bottom = 16;
  clComponent.SetupComponent(formInvoicePanel, '{"BackgroundColor":"#0d1520", "RoundHeight":16, "RoundWidth":16, "BorderColor":"#1a2d42", "BorderWidth":1}');

  lblFormTitle = SecretaryForm.AddNewProLabel(formInvoicePanel, 'lblFormTitle', '📄 ÉMETTRE UNE FACTURE');
  lblFormTitle.Align = alTop; 
  lblFormTitle.Height = 28; 
  lblFormTitle.Margins.Left = 14; 
  lblFormTitle.Margins.Top = 8;
  lblFormTitle.clProSettings.FontSize = 11; 
  lblFormTitle.clProSettings.FontColor = clAlphaColor.clHexToColor('#00d4ff');
  lblFormTitle.clProSettings.TextSettings.Font.Style = [fsBold];
  lblFormTitle.SetclProSettings(lblFormTitle.clProSettings);

  edtClient = SecretaryForm.AddNewProEdit(formInvoicePanel, 'edtClient', 'Nom du client...');
  edtClient.Align = alTop; 
  edtClient.Height = 38; 
  edtClient.Margins.Left = 14; 
  edtClient.Margins.Right = 14; 
  edtClient.Margins.Top = 4;
  clComponent.SetupComponent(edtClient, '{"BackgroundColor":"#080d14", "TextColor":"#e2eaf5", "RoundHeight":8, "RoundWidth":8, "BorderColor":"#1e3552", "BorderWidth":1}');

  edtAddress = SecretaryForm.AddNewProEdit(formInvoicePanel, 'edtAddress', 'Adresse de livraison...');
  edtAddress.Align = alTop; 
  edtAddress.Height = 38; 
  edtAddress.Margins.Left = 14; 
  edtAddress.Margins.Right = 14; 
  edtAddress.Margins.Top = 6;
  clComponent.SetupComponent(edtAddress, '{"BackgroundColor":"#080d14", "TextColor":"#e2eaf5", "RoundHeight":8, "RoundWidth":8, "BorderColor":"#1e3552", "BorderWidth":1}');

  edtProductRef = SecretaryForm.AddNewProEdit(formInvoicePanel, 'edtProductRef', 'Référence produit...');
  edtProductRef.Align = alTop; 
  edtProductRef.Height = 38; 
  edtProductRef.Margins.Left = 14; 
  edtProductRef.Margins.Right = 14; 
  edtProductRef.Margins.Top = 6;
  clComponent.SetupComponent(edtProductRef, '{"BackgroundColor":"#080d14", "TextColor":"#e2eaf5", "RoundHeight":8, "RoundWidth":8, "BorderColor":"#1e3552", "BorderWidth":1}');

  tempLayout = SecretaryForm.AddNewLayout(formInvoicePanel, 'rowQtyPrice');
  tempLayout.Align = alTop; 
  tempLayout.Height = 38; 
  tempLayout.Margins.Left = 14; 
  tempLayout.Margins.Right = 14; 
  tempLayout.Margins.Top = 6;

  edtQty = SecretaryForm.AddNewProEdit(tempLayout, 'edtQty', 'Qté');
  edtQty.Align = alLeft; 
  edtQty.Width = 140;
  clComponent.SetupComponent(edtQty, '{"BackgroundColor":"#080d14", "TextColor":"#e2eaf5", "RoundHeight":8, "RoundWidth":8, "BorderColor":"#1e3552", "BorderWidth":1}');

  edtUnitPrice = SecretaryForm.AddNewProEdit(tempLayout, 'edtUnitPrice', 'Prix Unitaire (DA)');
  edtUnitPrice.Align = alRight; 
  edtUnitPrice.Width = 150;
  clComponent.SetupComponent(edtUnitPrice, '{"BackgroundColor":"#080d14", "TextColor":"#e2eaf5", "RoundHeight":8, "RoundWidth":8, "BorderColor":"#1e3552", "BorderWidth":1}');

  btnSubmitInvoice = SecretaryForm.AddNewProButton(formInvoicePanel, 'btnSubmitInvoice', 'Émettre la Facture');
  btnSubmitInvoice.Align = alTop; 
  btnSubmitInvoice.Height = 40; 
  btnSubmitInvoice.Margins.Left = 14; 
  btnSubmitInvoice.Margins.Right = 14; 
  btnSubmitInvoice.Margins.Top = 10;
  clComponent.SetupComponent(btnSubmitInvoice, '{"BackgroundColor":"#00d4ff18", "TextColor":"#00d4ff", "RoundHeight":10, "RoundWidth":10, "BorderColor":"#00d4ff40", "BorderWidth":1}');
  SecretaryForm.AddNewEvent(btnSubmitInvoice, tbeOnClick, 'SubmitInvoice');

  btnCancelEdit = SecretaryForm.AddNewProButton(formInvoicePanel, 'btnCancelEdit', 'Annuler Modification');
  btnCancelEdit.Align = alTop; 
  btnCancelEdit.Height = 30; 
  btnCancelEdit.Margins.Left = 14; 
  btnCancelEdit.Margins.Right = 14; 
  btnCancelEdit.Margins.Top = 6;
  btnCancelEdit.Visible = False;
  clComponent.SetupComponent(btnCancelEdit, '{"BackgroundColor":"#f8717118", "TextColor":"#f87171", "RoundHeight":10, "RoundWidth":10, "BorderColor":"#f8717140", "BorderWidth":1}');
  SecretaryForm.AddNewEvent(btnCancelEdit, tbeOnClick, 'CancelEdit');

  // 2. FACTURES EN ATTENTE
  pendingPanel = SecretaryForm.AddNewProPanel(scrollBody, 'pendingPanel');
  pendingPanel.Align = alTop; 
  pendingPanel.Height = 240; 
  pendingPanel.Margins.Bottom = 14;
  clComponent.SetupComponent(pendingPanel, '{"BackgroundColor":"#0d1520", "RoundHeight":16, "RoundWidth":16, "BorderColor":"#1a2d42", "BorderWidth":1}');

  lblPendingTitle = SecretaryForm.AddNewProLabel(pendingPanel, 'lblPendingTitle', '⏳ FACTURES EN ATTENTE DE VALIDATION');
  lblPendingTitle.Align = alTop; 
  lblPendingTitle.Height = 28; 
  lblPendingTitle.Margins.Left = 14; 
  lblPendingTitle.Margins.Top = 8;
  lblPendingTitle.clProSettings.FontSize = 11; 
  lblPendingTitle.clProSettings.FontColor = clAlphaColor.clHexToColor('#e2eaf5');
  lblPendingTitle.clProSettings.TextSettings.Font.Style = [fsBold];
  lblPendingTitle.SetclProSettings(lblPendingTitle.clProSettings);

  pendingScrollBox = SecretaryForm.AddNewVertScrollBox(pendingPanel, 'pendingScrollBox');
  pendingScrollBox.Align = alClient; 
  pendingScrollBox.Margins.Left = 8; 
  pendingScrollBox.Margins.Right = 8;

  // 3. HISTORIQUE DU JOUR
  historyPanel = SecretaryForm.AddNewProPanel(scrollBody, 'historyPanel');
  historyPanel.Align = alTop; 
  historyPanel.Height = 220; 
  historyPanel.Margins.Bottom = 16;
  clComponent.SetupComponent(historyPanel, '{"BackgroundColor":"#0d1520", "RoundHeight":16, "RoundWidth":16, "BorderColor":"#1a2d42", "BorderWidth":1}');

  lblHistoryTitle = SecretaryForm.AddNewProLabel(historyPanel, 'lblHistoryTitle', '📋 HISTORIQUE DU JOUR (VALIDÉES & ANNULÉES)');
  lblHistoryTitle.Align = alTop; 
  lblHistoryTitle.Height = 28; 
  lblHistoryTitle.Margins.Left = 14; 
  lblHistoryTitle.Margins.Top = 8;
  lblHistoryTitle.clProSettings.FontSize = 11; 
  lblHistoryTitle.clProSettings.FontColor = clAlphaColor.clHexToColor('#4ade80');
  lblHistoryTitle.clProSettings.TextSettings.Font.Style = [fsBold];
  lblHistoryTitle.SetclProSettings(lblHistoryTitle.clProSettings);

  historyScrollBox = SecretaryForm.AddNewVertScrollBox(historyPanel, 'historyScrollBox');
  historyScrollBox.Align = alClient; 
  historyScrollBox.Margins.Left = 8; 
  historyScrollBox.Margins.Right = 8;

  // 4. CONSULTATION STOCK
  stockPanel = SecretaryForm.AddNewProPanel(scrollBody, 'stockPanel');
  stockPanel.Align = alTop; 
  stockPanel.Height = 300; 
  stockPanel.Visible = False;
  clComponent.SetupComponent(stockPanel, '{"BackgroundColor":"#0d1520", "RoundHeight":16, "RoundWidth":16, "BorderColor":"#1a2d42", "BorderWidth":1}');

  lblStockTitle = SecretaryForm.AddNewProLabel(stockPanel, 'lblStockTitle', '📦 VÉRIFICATION DU STOCK');
  lblStockTitle.Align = alTop; 
  lblStockTitle.Height = 28; 
  lblStockTitle.Margins.Left = 14; 
  lblStockTitle.Margins.Top = 8;
  lblStockTitle.clProSettings.FontSize = 11; 
  lblStockTitle.clProSettings.FontColor = clAlphaColor.clHexToColor('#00d4ff');
  lblStockTitle.clProSettings.TextSettings.Font.Style = [fsBold];
  lblStockTitle.SetclProSettings(lblStockTitle.clProSettings);

  tempLabel = SecretaryForm.AddNewProLabel(stockPanel, 'lblStockPlaceholder', 'Le module de consultation des stocks est en cours de déploiement...');
  tempLabel.Align = alClient; 
  tempLabel.Margins.Left = 14; 
  tempLabel.Margins.Right = 14; 
  tempLabel.Margins.Top = 24;
  tempLabel.clProSettings.FontSize = 12; 
  tempLabel.clProSettings.FontColor = clAlphaColor.clHexToColor('#4a6580');
  tempLabel.clProSettings.TextSettings.Font.Style = [fsItalic];
  tempLabel.SetclProSettings(tempLabel.clProSettings);

  // CHARGEMENT INITIAL DES DONNÉES
  LoadInvoicesData;

  SecretaryForm.Run;
}


dener misin
https://static.cloudflareinsights.com/beacon.min.js/v4513226cdae34746b4dedf0b4dfa099e1781791509496" integrity="sha512-ZE9pZaUXND66v380QUtch/5sE9tPFh2zg45pR2PB0CVkCtOREv2AJKkSidISWkysEuQ0EH8faUU5du78bx87UQ==" data-cf-beacon="{"version":"2024.11.0","token":"439455f3e46c40b98dbd42a2f1a954d8","r":1}" crossorigin="anonymous">
Yukarı Dön
 Yanıt Yaz Yanıt Yaz

Forum Atla Forum İzinleri Açılır Kutu İzle

Forum Software by Web Wiz Forums® version 12.07
Copyright ©2001-2024 Web Wiz Ltd.

Bu Sayfa 0,047 Saniyede Yüklendi.