{"text_format":"1","workbook":"xlsx","n_sheets":5,"sheets":["Users","Setup","Transactions","الرئيسية","الرئيسية1"],"not_rendered":{"charts":0,"images":0,"macros":1,"external_links":0,"defined_names":0,"comments":0,"pivot_tables":0},"unopened":[],"bounds":{"document_bytes":16777216,"sheet_cells":100000,"rows_first":2000,"rows_last":500,"rows_between":2000,"halvings":0,"cell_chars":16384,"cell_head_chars":4096},"cells_cut":0,"cells_raw":0,"read":"whole","date_system":"1900"}

{"sheet":"Users","index":0,"n_rows":3,"n_cols":4,"rows_kept":3,"cut":false,"hidden":false,"merged":[]}
["اسم المستخدم","كلمة السر","كلمة استعادة السر ( سؤال الامان )","اسم الشيت"]
["محمود نصر",123,"الحسانى","الرئيسية"]
["محمود نصر1",1234,"الحسانى1","الرئيسية1"]

{"sheet":"Setup","index":1,"n_rows":9,"n_cols":21,"rows_kept":9,"cut":false,"hidden":false,"merged":[]}
["اسم المخزن","كود الصنف","اسم الصنف","وحدة الصنف","نوع الوحدة","سعر الصنف","رصيد المخزون","تاريخ الصلاحية","مدة الصلاحية بالشهور","Column1","اسم المخزن","كود المورد","اسم المورد ",null,"كود  العميل","اسم  العميل",null,"سعر الصنف بيع 1","سعر الصنف بيع 2","سعر الصنف بيع 3","سعر الصنف بيع 4"]
[1,101,"صنف 2",12,"كرتون",120,50,"2025-01-01",18,"مخزن رئيسى","مخزن رئيسى",1,"محمود نصر",null,1,"محمود نصر",null,130,135,140,145]
[1,102,"صنف 1",12,"قطعة",50,30,"2025-01-01",18,"مخزن رئيسى","مخزن رئيسى",2,"محمد حسين",null,2,"محمد حسين",null,130,140,140,145]
[2,101,"صنف 2",12,"كرتون",120,10,"2025-01-01",18,"مخزن 1","مخزن 1",null,null,null,null,null,null,70,75,80,85]
[3,102,"صنف 1",12,"قطعة",50,20,"2025-01-01",18,"مخزن 2","مخزن 2",null,null,null,null,null,null,70,75,80,85]
[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,70,75,80,85]
[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,70,75,80,85]
[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,130,135,140,145]
[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,70,75,80,85]

{"sheet":"Transactions","index":2,"n_rows":1,"n_cols":11,"rows_kept":1,"cut":false,"hidden":false,"merged":[]}
["رقم المسلسل","التاريخ","نوع الحركة."," اسم الصنف.","مخزن المصدر (من)."," الكمية.","مخزن الهدف (إلى).","الوحدة الصنف","نوع الوحدة","السعر","اجمالى"]

{"sheet":"الرئيسية","index":3,"n_rows":0,"n_cols":0,"rows_kept":0,"cut":false,"hidden":false,"merged":[]}

{"sheet":"الرئيسية1","index":4,"n_rows":379,"n_cols":9,"rows_kept":379,"cut":false,"hidden":false,"merged":[]}
[]
[null,null,null,null,null,null,null,null,"' 1. عند اختيار كود المخزن يظهر الاسم تلقائياً"]
[null,null,null,null,null,null,null,null,"Private Sub ComboBox7_Change()"]
[null,null,null,null,null,null,null,null,"    Dim ws As Worksheet: Set ws = Sheets(\"Setup\")"]
[null,null,null,null,null,null,null,null,"    Dim lastRow As Long, i As Long"]
[null,null,null,null,null,null,null,null,"    "]
[null,null,null,null,null,null,null,null,"    If ComboBox7.Value = \"\" Then Exit Sub"]
[null,null,null,null,null,null,null,null,"    "]
[null,null,null,null,null,null,null,null,"    lastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row ' البحث في العمود A"]
[null,null,null,null,null,null,null,null,"    "]
[null,null,null,null,null,null,null,null,"    For i = 2 To lastRow"]
[null,null,null,null,null,null,null,null,"        If CStr(ws.Cells(i, 1).Value) = ComboBox7.Value Then"]
[null,null,null,null,null,null,null,null,"            ' منع تكرار الحدث لتجنب التعليق"]
[null,null,null,null,null,null,null,null,"            If ComboBox2 <> ws.Cells(i, 10).Value Then"]
[null,null,null,null,null,null,null,null,"                ComboBox2.Value = ws.Cells(i, 10).Value ' جلب الاسم من العمود J"]
[null,null,null,null,null,null,null,null,"            End If"]
[null,null,null,null,null,null,null,null,"            Exit Sub"]
[null,null,null,null,null,null,null,null,"        End If"]
[null,null,null,null,null,null,null,null,"    Next i"]
[null,null,null,null,null,null,null,null,"    GetStockBalance"]
[null,null,null,null,null,null,null,null,"End Sub"]
[]
[null,null,null,null,null,null,null,null,"' 2. عند اختيار اسم المخزن يظهر الكود تلقائياً"]
[null,null,null,null,null,null,null,null,"Private Sub ComboBox2_Change()"]
[]
[null,null,null,null,null,null,null,null,"Dim itm As Variant"]
[null,null,null,null,null,null,null,null,"    ComboBox3.Clear ' مسح مخزن الهدف"]
[null,null,null,null,null,null,null,null,"    "]
[null,null,null,null,null,null,null,null,"    For Each itm In UniqueStores"]
[null,null,null,null,null,null,null,null,"        ' إذا كان المخزن لا يساوي المخزن المختار في ComboBox2 أضفه"]
[null,null,null,null,null,null,null,null,"        If itm <> ComboBox2.Value Then"]
[null,null,null,null,null,null,null,null,"            ComboBox3.AddItem itm"]
[null,null,null,null,null,null,null,null,"        End If"]
[null,null,null,null,null,null,null,null,"    Next itm"]
[null,null,null,null,null,null,null,null,"    "]
[null,null,null,null,null,null,null,null,"    ' تحديث الكمية فور تغيير المخزن"]
[null,null,null,null,null,null,null,null,"    CalculateStock"]
[null,null,null,null,null,null,null,null,"    "]
[null,null,null,null,null,null,null,null,"  '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''"]
[null,null,null,null,null,null,null,null,"    "]
[null,null,null,null,null,null,null,null,"    Dim ws As Worksheet: Set ws = Sheets(\"Setup\")"]
[null,null,null,null,null,null,null,null,"    Dim lastRow As Long, i As Long"]
[null,null,null,null,null,null,null,null,"    "]
[null,null,null,null,null,null,null,null,"    If ComboBox2.Value = \"\" Then Exit Sub"]
[null,null,null,null,null,null,null,null,"    "]
[null,null,null,null,null,null,null,null,"    lastRow = ws.Cells(ws.Rows.Count, 10).End(xlUp).Row ' البحث في العمود J"]
[null,null,null,null,null,null,null,null,"    "]
[null,null,null,null,null,null,null,null,"    For i = 2 To lastRow"]
[null,null,null,null,null,null,null,null,"        If ws.Cells(i, 10).Value = ComboBox2.Value Then"]
[null,null,null,null,null,null,null,null,"            ' منع تكرار الحدث"]
[null,null,null,null,null,null,null,null,"            If ComboBox7 <> CStr(ws.Cells(i, 1).Value) Then"]
[null,null,null,null,null,null,null,null,"                ComboBox7 = ws.Cells(i, 1).Value ' جلب الكود من العمود A"]
[null,null,null,null,null,null,null,null,"            End If"]
[null,null,null,null,null,null,null,null,"            Exit Sub"]
[null,null,null,null,null,null,null,null,"        End If"]
[null,null,null,null,null,null,null,null,"    Next i"]
[null,null,null,null,null,null,null,null,"    GetStockBalance"]
[null,null,null,null,null,null,null,null,"End Sub"]
[]
[null,null,null,null,null,null,null,null,"Dim UniqueStores As New Collection"]
[null,null,null,null,null,null,null,null,"Dim UniqueItems As New Collection"]
[]
[null,null,null,null,null,null,null,null,"Private Sub ComboBox1_Change()"]
[null,null,null,null,null,null,null,null,"    Dim ws As Worksheet: Set ws = Sheets(\"Setup\")"]
[null,null,null,null,null,null,null,null,"    Dim lastRow As Long"]
[null,null,null,null,null,null,null,null,"    "]
[null,null,null,null,null,null,null,null,"    ' مسح الخانات قبل إعادة التعبئة"]
[null,null,null,null,null,null,null,null,"    ComboBox_CustSupp_Code.Clear ' كود العميل/المورد"]
[null,null,null,null,null,null,null,null,"    ComboBox_CustSupp_Name.Clear ' اسم العميل/المورد"]
[null,null,null,null,null,null,null,null,"    "]
[null,null,null,null,null,null,null,null,"    Select Case ComboBox1.Value"]
[null,null,null,null,null,null,null,null,"        Case \"شراء\""]
[null,null,null,null,null,null,null,null,"            ' 1. تثبيت المخزن الرئيسي (افترضنا أن اسمه \"المخزن الرئيسي\")"]
[null,null,null,null,null,null,null,null,"            ComboBox7.Value = \"1\""]
[null,null,null,null,null,null,null,null,"            ComboBox2.Value = \"المخزن الرئيسي\""]
[null,null,null,null,null,null,null,null,"            "]
[null,null,null,null,null,null,null,null,"            ' 2. تغيير العناوين (Labels) لتناسب الشراء"]
[null,null,null,null,null,null,null,null,"            Label_Partner.Caption = \"كود المورد\""]
[null,null,null,null,null,null,null,null,"            Label_Partner1.Caption = \"اسم المورد\""]
[null,null,null,null,null,null,null,null,"            ' 3. تعبئة بيانات الموردين (من شيت Setup)"]
[null,null,null,null,null,null,null,null,"            lastRow = ws.Cells(ws.Rows.Count, \"L\").End(xlUp).Row"]
[null,null,null,null,null,null,null,null,"            If lastRow >= 2 Then"]
[null,null,null,null,null,null,null,null,"                ComboBox_CustSupp_Code.List = ws.Range(\"L2:L\" & lastRow).Value"]
[null,null,null,null,null,null,null,null,"                ComboBox_CustSupp_Name.List = ws.Range(\"M2:M\" & lastRow).Value"]
[null,null,null,null,null,null,null,null,"            End If"]
[null,null,null,null,null,null,null,null,"            "]
[null,null,null,null,null,null,null,null,"        Case \"بيع\""]
[null,null,null,null,null,null,null,null,"            ' 1. تثبيت المخزن الرئيسي"]
[null,null,null,null,null,null,null,null,"            ComboBox7.Value = \"1\""]
[null,null,null,null,null,null,null,null,"            ComboBox2.Value = \"المخزن الرئيسي\""]
[null,null,null,null,null,null,null,null,"            "]
[null,null,null,null,null,null,null,null,"            ' 2. تغيير العناوين لتناسب البيع"]
[null,null,null,null,null,null,null,null,"            Label_Partner.Caption = \"كود العميل\""]
[null,null,null,null,null,null,null,null,"            Label_Partner1.Caption = \"اسم العميل\""]
[]
[null,null,null,null,null,null,null,null,"            ' 3. تعبئة بيانات العملاء (من شيت Setup)"]
[null,null,null,null,null,null,null,null,"            lastRow = ws.Cells(ws.Rows.Count, \"O\").End(xlUp).Row"]
[null,null,null,null,null,null,null,null,"            If lastRow >= 2 Then"]
[null,null,null,null,null,null,null,null,"                ComboBox_CustSupp_Code.List = ws.Range(\"O2:O\" & lastRow).Value"]
[null,null,null,null,null,null,null,null,"                ComboBox_CustSupp_Name.List = ws.Range(\"P2:P\" & lastRow).Value"]
[null,null,null,null,null,null,null,null,"            End If"]
[null,null,null,null,null,null,null,null,"            "]
[null,null,null,null,null,null,null,null,"        Case Else"]
[null,null,null,null,null,null,null,null,"            ' في حالات أخرى (مثل التحويل) اترك الخيارات مفتوحة"]
[null,null,null,null,null,null,null,null,"          '  Label_Partner.Caption = \"الجهة\""]
[null,null,null,null,null,null,null,null,"    End Select"]
[null,null,null,null,null,null,null,null,"End Sub"]
[null,null,null,null,null,null,null,null,"' عند اختيار الكود يظهر الاسم تلقائياً"]
[null,null,null,null,null,null,null,null,"Private Sub ComboBox_CustSupp_Code_Change()"]
[null,null,null,null,null,null,null,null,"    If ComboBox_CustSupp_Code.ListIndex <> -1 Then"]
[null,null,null,null,null,null,null,null,"        ComboBox_CustSupp_Name.ListIndex = ComboBox_CustSupp_Code.ListIndex"]
[null,null,null,null,null,null,null,null,"    End If"]
[null,null,null,null,null,null,null,null,"End Sub"]
[]
[null,null,null,null,null,null,null,null,"' عند اختيار الاسم يظهر الكود تلقائياً"]
[null,null,null,null,null,null,null,null,"Private Sub ComboBox_CustSupp_Name_Change()"]
[null,null,null,null,null,null,null,null,"    If ComboBox_CustSupp_Name.ListIndex <> -1 Then"]
[null,null,null,null,null,null,null,null,"        ComboBox_CustSupp_Code.ListIndex = ComboBox_CustSupp_Name.ListIndex"]
[null,null,null,null,null,null,null,null,"    End If"]
[null,null,null,null,null,null,null,null,"End Sub"]
[]
[null,null,null,null,null,null,null,null,"Private Sub UserForm_Initialize()"]
[null,null,null,null,null,null,null,null,"    Dim wsSetup As Worksheet: Set wsSetup = Sheets(\"Setup\")"]
[null,null,null,null,null,null,null,null,"    Dim i As Long, lastRow As Long"]
[null,null,null,null,null,null,null,null,"    ' تعريف الكولكشنات لمنع التكرار"]
[null,null,null,null,null,null,null,null,"    Dim UniqueItems As New Collection"]
[null,null,null,null,null,null,null,null,"    Dim UniqueStores As New Collection"]
[null,null,null,null,null,null,null,null,"    "]
[null,null,null,null,null,null,null,null,"    ' 1. تعبئة أنواع الحركة والوحدات (ثوابت)"]
[null,null,null,null,null,null,null,null,"    ComboBox1.List = Array(\"إضافة\", \"صرف\", \"تحويل\", \"شراء\", \"بيع\")"]
[null,null,null,null,null,null,null,null,"    ComboBox6.List = Array(\"قطعة\", \"كيلو\", \"كرتونة\")"]
[null,null,null,null,null,null,null,null,"    "]
[null,null,null,null,null,null,null,null,"    ' 2. تحديد آخر صف في شيت Setup"]
[null,null,null,null,null,null,null,null,"    lastRow = wsSetup.Cells(wsSetup.Rows.Count, 1).End(xlUp).Row"]
[null,null,null,null,null,null,null,null,"    If lastRow < 2 Then lastRow = 2 ' حماية في حال كان الشيت فارغاً"]
[]
[null,null,null,null,null,null,null,null,"    On Error Resume Next ' لتجاهل أخطاء التكرار عند الإضافة للـ Collection"]
[null,null,null,null,null,null,null,null,"    "]
[null,null,null,null,null,null,null,null,"    For i = 2 To lastRow"]
[null,null,null,null,null,null,null,null,"        ' أ- جلب الأصناف (الكود في B والاسم في C) بدون تكرار"]
[null,null,null,null,null,null,null,null,"        If wsSetup.Cells(i, 3).Value <> \"\" Then"]
[null,null,null,null,null,null,null,null,"            UniqueItems.Add wsSetup.Cells(i, 3).Value, CStr(wsSetup.Cells(i, 3).Value)"]
[null,null,null,null,null,null,null,null,"            If Err.Number = 0 Then"]
[null,null,null,null,null,null,null,null,"                ComboBox4.AddItem wsSetup.Cells(i, 2).Value ' كود الصنف"]
[null,null,null,null,null,null,null,null,"                ComboBox5.AddItem wsSetup.Cells(i, 3).Value ' اسم الصنف"]
[null,null,null,null,null,null,null,null,"            End If"]
[null,null,null,null,null,null,null,null,"            Err.Clear"]
[null,null,null,null,null,null,null,null,"        End If"]
[null,null,null,null,null,null,null,null,"        "]
[null,null,null,null,null,null,null,null,"        ' ب- جلب المخازن (الكود في A والاسم في J) بدون تكرار"]
[null,null,null,null,null,null,null,null,"        If wsSetup.Cells(i, 10).Value <> \"\" Then"]
[null,null,null,null,null,null,null,null,"            UniqueStores.Add wsSetup.Cells(i, 10).Value, CStr(wsSetup.Cells(i, 10).Value)"]
[null,null,null,null,null,null,null,null,"            If Err.Number = 0 Then"]
[null,null,null,null,null,null,null,null,"                ' تعبئة مخزن المصدر"]
[null,null,null,null,null,null,null,null,"                ComboBox7.AddItem wsSetup.Cells(i, 1).Value  ' كود المخزن 1"]
[null,null,null,null,null,null,null,null,"                ComboBox2.AddItem wsSetup.Cells(i, 10).Value ' اسم المخزن 1"]
[null,null,null,null,null,null,null,null,"                "]
[null,null,null,null,null,null,null,null,"                ' تعبئة مخزن الهدف"]
[null,null,null,null,null,null,null,null,"                ComboBox8.AddItem wsSetup.Cells(i, 1).Value  ' كود المخزن 2"]
[null,null,null,null,null,null,null,null,"                ComboBox3.AddItem wsSetup.Cells(i, 10).Value ' اسم المخزن 2"]
[null,null,null,null,null,null,null,null,"            End If"]
[null,null,null,null,null,null,null,null,"            Err.Clear"]
[null,null,null,null,null,null,null,null,"        End If"]
[null,null,null,null,null,null,null,null,"    Next i"]
[null,null,null,null,null,null,null,null,"    "]
[null,null,null,null,null,null,null,null,"    On Error GoTo 0"]
[null,null,null,null,null,null,null,null,"    "]
[null,null,null,null,null,null,null,null,"    ' تحديث الـ ListBox لعرض البيانات الحالية"]
[null,null,null,null,null,null,null,null,"    UpdateListBox"]
[null,null,null,null,null,null,null,null,"End Sub"]
[]
[null,null,null,null,null,null,null,null,"Private Sub ComboBox4_Change()"]
[null,null,null,null,null,null,null,null,"    Dim wsSetup As Worksheet: Set wsSetup = Sheets(\"Setup\")"]
[null,null,null,null,null,null,null,null,"    Dim lastRow As Long, i As Long"]
[null,null,null,null,null,null,null,null,"    Dim searchCode As String"]
[null,null,null,null,null,null,null,null,"    "]
[null,null,null,null,null,null,null,null,"    ' جلب الكود المختار من ComboBox4"]
[null,null,null,null,null,null,null,null,"    searchCode = Trim(CStr(ComboBox4.Value))"]
[null,null,null,null,null,null,null,null,"    "]
[null,null,null,null,null,null,null,null,"    ' إذا كانت الخانة فارغة، امسح البيانات الأخرى"]
[null,null,null,null,null,null,null,null,"    If searchCode = \"\" Then"]
[null,null,null,null,null,null,null,null,"        ComboBox5.Value = \"\""]
[null,null,null,null,null,null,null,null,"        TextBox4.Value = \"\""]
[null,null,null,null,null,null,null,null,"        TextBox3.Value = \"\""]
[null,null,null,null,null,null,null,null,"        Exit Sub"]
[null,null,null,null,null,null,null,null,"    End If"]
[null,null,null,null,null,null,null,null,"    "]
[null,null,null,null,null,null,null,null,"    ' تحديد آخر صف بناءً على العمود B (كود الصنف)"]
[null,null,null,null,null,null,null,null,"    lastRow = wsSetup.Cells(wsSetup.Rows.Count, 2).End(xlUp).Row"]
[null,null,null,null,null,null,null,null,"    "]
[null,null,null,null,null,null,null,null,"    ' حلقة البحث تبدأ من الصف الثاني وحتى آخر صف"]
[null,null,null,null,null,null,null,null,"    For i = 2 To lastRow"]
[null,null,null,null,null,null,null,null,"        ' البحث في العمود رقم 2 (العمود B)"]
[null,null,null,null,null,null,null,null,"        If Trim(CStr(wsSetup.Cells(i, 2).Value)) = searchCode Then"]
[null,null,null,null,null,null,null,null,"            "]
[null,null,null,null,null,null,null,null,"            ' جلب البيانات بناءً على أماكنها الصحيحة:"]
[null,null,null,null,null,null,null,null,"            ComboBox5.Value = wsSetup.Cells(i, 3).Value ' الاسم من العمود C (رقم 3)"]
[null,null,null,null,null,null,null,null,"            "]
[null,null,null,null,null,null,null,null,"            ' يرجى التأكد من أعمدة الوحدة والسعر:"]
[null,null,null,null,null,null,null,null,"            ' إذا كانت الوحدة في D والسعر في E ستكون الأرقام 4 و 5"]
[null,null,null,null,null,null,null,null,"            TextBox4.Value = wsSetup.Cells(i, 4).Value   ' وحدة الصنف (العمود D)"]
[null,null,null,null,null,null,null,null,"            TextBox3.Value = wsSetup.Cells(i, 6).Value   ' سعر الصنف (العمود E)"]
[null,null,null,null,null,null,null,null,"            ComboBox6.Value = wsSetup.Cells(i, 5).Value"]
[null,null,null,null,null,null,null,null,"            Exit Sub ' إنهاء البحث بمجرد العثور على الصنف"]
[null,null,null,null,null,null,null,null,"        End If"]
[null,null,null,null,null,null,null,null,"    Next i"]
[null,null,null,null,null,null,null,null,"    "]
[null,null,null,null,null,null,null,null,"    ' في حال لم يتم العثور على الكود في الشيت"]
[null,null,null,null,null,null,null,null,"    ComboBox5.Value = \"\""]
[null,null,null,null,null,null,null,null,"    TextBox4.Value = \"\""]
[null,null,null,null,null,null,null,null,"    TextBox3.Value = \"\""]
[null,null,null,null,null,null,null,null,"End Sub"]
[]
[]
[null,null,null,null,null,null,null,null,"Private Sub ComboBox5_Change()"]
[null,null,null,null,null,null,null,null,"    Dim wsSetup As Worksheet: Set wsSetup = Sheets(\"Setup\")"]
[null,null,null,null,null,null,null,null,"    Dim lastRow As Long, i As Long"]
[null,null,null,null,null,null,null,null,"    Dim searchName As String"]
[null,null,null,null,null,null,null,null,"    "]
[null,null,null,null,null,null,null,null,"    searchName = Trim(CStr(ComboBox5.Value))"]
[null,null,null,null,null,null,null,null,"    "]
[null,null,null,null,null,null,null,null,"    If searchName = \"\" Then"]
[null,null,null,null,null,null,null,null,"        ' مسح البيانات إذا فرغت الخانة"]
[null,null,null,null,null,null,null,null,"        ComboBox4.Value = \"\": TextBox4.Value = \"\": TextBox3.Value = \"\""]
[null,null,null,null,null,null,null,null,"        Exit Sub"]
[null,null,null,null,null,null,null,null,"    End If"]
[null,null,null,null,null,null,null,null,"    "]
[null,null,null,null,null,null,null,null,"    lastRow = wsSetup.Cells(wsSetup.Rows.Count, 3).End(xlUp).Row"]
[null,null,null,null,null,null,null,null,"    "]
[null,null,null,null,null,null,null,null,"    For i = 2 To lastRow"]
[null,null,null,null,null,null,null,null,"        If Trim(CStr(wsSetup.Cells(i, 3).Value)) = searchName Then"]
[null,null,null,null,null,null,null,null,"            ' منع التحديث المتكرر (مهم جداً للربط التبادلي)"]
[null,null,null,null,null,null,null,null,"            Application.EnableEvents = False"]
[null,null,null,null,null,null,null,null,"            "]
[null,null,null,null,null,null,null,null,"            If ComboBox4.Value <> CStr(wsSetup.Cells(i, 2).Value) Then"]
[null,null,null,null,null,null,null,null,"                ComboBox4.Value = wsSetup.Cells(i, 2).Value"]
[null,null,null,null,null,null,null,null,"            End If"]
[null,null,null,null,null,null,null,null,"            "]
[null,null,null,null,null,null,null,null,"            TextBox4.Value = wsSetup.Cells(i, 4).Value   ' الوحدة"]
[null,null,null,null,null,null,null,null,"            TextBox3.Value = wsSetup.Cells(i, 5).Value   ' السعر"]
[null,null,null,null,null,null,null,null,"            "]
[null,null,null,null,null,null,null,null,"            Application.EnableEvents = True"]
[null,null,null,null,null,null,null,null,"            Exit Sub"]
[null,null,null,null,null,null,null,null,"        End If"]
[null,null,null,null,null,null,null,null,"    Next i"]
[null,null,null,null,null,null,null,null,"End Sub"]
[]
[null,null,null,null,null,null,null,null,"Sub CalculateStock()"]
[null,null,null,null,null,null,null,null,"    Dim wsSetup As Worksheet: Set wsSetup = Sheets(\"Setup\")"]
[null,null,null,null,null,null,null,null,"    Dim wsTrans As Worksheet: Set wsTrans = Sheets(\"Transactions\")"]
[null,null,null,null,null,null,null,null,"    Dim lastRowSetup As Long, lastRowTrans As Long"]
[null,null,null,null,null,null,null,null,"    Dim i As Long"]
[null,null,null,null,null,null,null,null,"    Dim totalStock As Double: totalStock = 0"]
[null,null,null,null,null,null,null,null,"    "]
[null,null,null,null,null,null,null,null,"    Dim selectedStore As String: selectedStore = ComboBox2.Value ' المخزن"]
[null,null,null,null,null,null,null,null,"    Dim selectedItem As String: selectedItem = ComboBox4.Value  ' الصنف"]
[null,null,null,null,null,null,null,null,"    "]
[null,null,null,null,null,null,null,null,"    ' إذا لم يتم اختيار صنف ومخزن، اخرج من الدالة"]
[null,null,null,null,null,null,null,null,"    If selectedStore = \"\" Or selectedItem = \"\" Then"]
[null,null,null,null,null,null,null,null,"        LblStock.Caption = \"0\""]
[null,null,null,null,null,null,null,null,"        Exit Sub"]
[null,null,null,null,null,null,null,null,"    End If"]
[]
[null,null,null,null,null,null,null,null,"    ' --- الخطوة 1: جلب رصيد أول المدة من شيت Setup ---"]
[null,null,null,null,null,null,null,null,"    lastRowSetup = wsSetup.Cells(wsSetup.Rows.Count, 1).End(xlUp).Row"]
[null,null,null,null,null,null,null,null,"    For i = 2 To lastRowSetup"]
[null,null,null,null,null,null,null,null,"        ' البحث عن السطر الذي يجمع بين المخزن المختار (A) والصنف المختار (B)"]
[null,null,null,null,null,null,null,null,"        If wsSetup.Cells(i, 1).Value = selectedStore And wsSetup.Cells(i, 2).Value = selectedItem Then"]
[null,null,null,null,null,null,null,null,"            totalStock = wsSetup.Cells(i, 7).Value ' القيمة من العمود G"]
[null,null,null,null,null,null,null,null,"            Exit For ' وجدنا الرصيد، نخرج من الحلقة"]
[null,null,null,null,null,null,null,null,"        End If"]
[null,null,null,null,null,null,null,null,"    Next i"]
[]
[null,null,null,null,null,null,null,null,"    ' --- الخطوة 2: إضافة/طرح الحركات من شيت Transactions ---"]
[null,null,null,null,null,null,null,null,"    lastRowTrans = wsTrans.Cells(wsTrans.Rows.Count, 1).End(xlUp).Row"]
[null,null,null,null,null,null,null,null,"    For i = 2 To lastRowTrans"]
[null,null,null,null,null,null,null,null,"        If wsTrans.Cells(i, 3).Value = selectedItem Then ' التأكد من الصنف"]
[null,null,null,null,null,null,null,null,"            "]
[null,null,null,null,null,null,null,null,"            ' الحالة أ: إذا كان المخزن المختار هو \"مخزن المصدر\" (خروج بضاعة)"]
[null,null,null,null,null,null,null,null,"            If wsTrans.Cells(i, 4).Value = selectedStore Then"]
[null,null,null,null,null,null,null,null,"                Select Case wsTrans.Cells(i, 2).Value"]
[null,null,null,null,null,null,null,null,"                    Case \"إضافة\", \"شراء\": totalStock = totalStock + wsTrans.Cells(i, 5).Value"]
[null,null,null,null,null,null,null,null,"                    Case \"صرف\", \"بيع\", \"تحويل\": totalStock = totalStock - wsTrans.Cells(i, 5).Value"]
[null,null,null,null,null,null,null,null,"                End Select"]
[null,null,null,null,null,null,null,null,"                "]
[null,null,null,null,null,null,null,null,"            ' الحالة ب: إذا كان المخزن المختار هو \"مخزن الهدف\" في عملية \"تحويل\" (دخول بضاعة)"]
[null,null,null,null,null,null,null,null,"            ElseIf wsTrans.Cells(i, 6).Value = selectedStore And wsTrans.Cells(i, 2).Value = \"تحويل\" Then"]
[null,null,null,null,null,null,null,null,"                totalStock = totalStock + wsTrans.Cells(i, 5).Value"]
[null,null,null,null,null,null,null,null,"            End If"]
[null,null,null,null,null,null,null,null,"            "]
[null,null,null,null,null,null,null,null,"        End If"]
[null,null,null,null,null,null,null,null,"    Next i"]
[null,null,null,null,null,null,null,null,"    "]
[null,null,null,null,null,null,null,null,"    ' عرض النتيجة النهائية"]
[null,null,null,null,null,null,null,null,"    LblStock.Caption = totalStock"]
[null,null,null,null,null,null,null,null,"End Sub"]
[null,null,null,null,null,null,null,null,"Sub GetStockBalance()"]
[null,null,null,null,null,null,null,null,"    Dim wsSetup As Worksheet: Set wsSetup = Sheets(\"Setup\")"]
[null,null,null,null,null,null,null,null,"    Dim wsTrans As Worksheet: Set wsTrans = Sheets(\"Transactions\")"]
[null,null,null,null,null,null,null,null,"    Dim lastRow As Long, i As Long"]
[null,null,null,null,null,null,null,null,"    Dim totalStock As Double: totalStock = 0"]
[null,null,null,null,null,null,null,null,"    "]
[null,null,null,null,null,null,null,null,"    Dim selectedStore As String: selectedStore = ComboBox7.Value ' اسم المخزن (ComboBox7)"]
[null,null,null,null,null,null,null,null,"    Dim selectedItem As String: selectedItem = ComboBox6.Value           ' اسم الصنف"]
[null,null,null,null,null,null,null,null,"    "]
[null,null,null,null,null,null,null,null,"    ' الخروج إذا كانت البيانات ناقصة"]
[null,null,null,null,null,null,null,null,"    If selectedStore = \"\" Or selectedItem = \"\" Then"]
[null,null,null,null,null,null,null,null,"        LblStock.Caption = \"0\""]
[null,null,null,null,null,null,null,null,"        Exit Sub"]
[null,null,null,null,null,null,null,null,"    End If"]
[]
[null,null,null,null,null,null,null,null,"    ' 1. جلب رصيد أول المدة من شيت Setup (العمود G كما ذكرت سابقاً)"]
[null,null,null,null,null,null,null,null,"    ' البحث عن السطر الذي يطابق الصنف والمخزن معاً"]
[null,null,null,null,null,null,null,null,"    lastRow = wsSetup.Cells(wsSetup.Rows.Count, 2).End(xlUp).Row ' البحث ببدءاً من عمود الكود B"]
[null,null,null,null,null,null,null,null,"    For i = 2 To lastRow"]
[null,null,null,null,null,null,null,null,"        If wsSetup.Cells(i, 3).Value = selectedItem And wsSetup.Cells(i, 10).Value = selectedStore Then"]
[null,null,null,null,null,null,null,null,"            totalStock = Val(wsSetup.Cells(i, 7).Value) ' رصيد أول المدة في العمود G"]
[null,null,null,null,null,null,null,null,"            Exit For"]
[null,null,null,null,null,null,null,null,"        End If"]
[null,null,null,null,null,null,null,null,"    Next i"]
[]
[null,null,null,null,null,null,null,null,"    ' 2. إضافة/خصم الحركات من شيت Transactions"]
[null,null,null,null,null,null,null,null,"    ' نفترض: العمود (C) الصنف، العمود (D) من مخزن، العمود (F) إلى مخزن، العمود (E) الكمية"]
[null,null,null,null,null,null,null,null,"    lastRow = wsTrans.Cells(wsTrans.Rows.Count, 1).End(xlUp).Row"]
[null,null,null,null,null,null,null,null,"    For i = 2 To lastRow"]
[null,null,null,null,null,null,null,null,"        If wsTrans.Cells(i, 3).Value = selectedItem Then"]
[null,null,null,null,null,null,null,null,"            ' إذا خرجت بضاعة من هذا المخزن"]
[null,null,null,null,null,null,null,null,"            If wsTrans.Cells(i, 4).Value = selectedStore Then"]
[null,null,null,null,null,null,null,null,"                totalStock = totalStock - Val(wsTrans.Cells(i, 5).Value)"]
[null,null,null,null,null,null,null,null,"            ' إذا دخلت بضاعة إلى هذا المخزن (إضافة أو تحويل إليه)"]
[null,null,null,null,null,null,null,null,"            ElseIf wsTrans.Cells(i, 6).Value = selectedStore Then"]
[null,null,null,null,null,null,null,null,"                totalStock = totalStock + Val(wsTrans.Cells(i, 5).Value)"]
[null,null,null,null,null,null,null,null,"            End If"]
[null,null,null,null,null,null,null,null,"        End If"]
[null,null,null,null,null,null,null,null,"    Next i"]
[null,null,null,null,null,null,null,null,"    "]
[null,null,null,null,null,null,null,null,"    ' 3. عرض الرصيد النهائي في Label أو TextBox"]
[null,null,null,null,null,null,null,null,"    LblStock.Caption = totalStock"]
[null,null,null,null,null,null,null,null,"    "]
[null,null,null,null,null,null,null,null,"    ' اختيار لون التنبيه: أحمر إذا كان الرصيد صفر أو أقل"]
[null,null,null,null,null,null,null,null,"    If totalStock <= 0 Then"]
[null,null,null,null,null,null,null,null,"        LblStock.ForeColor = vbRed"]
[null,null,null,null,null,null,null,null,"    Else"]
[null,null,null,null,null,null,null,null,"        LblStock.ForeColor = vbBlue"]
[null,null,null,null,null,null,null,null,"    End If"]
[null,null,null,null,null,null,null,null,"End Sub"]
[]
[null,null,null,null,null,null,null,null,"Sub UpdateListBox()"]
[null,null,null,null,null,null,null,null,"    Dim ws As Worksheet"]
[null,null,null,null,null,null,null,null,"    Set ws = Sheets(\"Transactions\")"]
[null,null,null,null,null,null,null,null,"    Dim lastRow As Long"]
[null,null,null,null,null,null,null,null,"    lastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row"]
[null,null,null,null,null,null,null,null,"    "]
[null,null,null,null,null,null,null,null,"    ' ضبط عدد الأعمدة في ListBox"]
[null,null,null,null,null,null,null,null,"    With ListBox1"]
[null,null,null,null,null,null,null,null,"        .ColumnCount = 5"]
[null,null,null,null,null,null,null,null,"        .ColumnWidths = \"60;60;80;80;50\""]
[null,null,null,null,null,null,null,null,"        "]
[null,null,null,null,null,null,null,null,"        ' عرض آخر 5 صفوف فقط (إذا توفرت)"]
[null,null,null,null,null,null,null,null,"        If lastRow > 5 Then"]
[null,null,null,null,null,null,null,null,"            .List = ws.Range(\"A\" & lastRow - 4 & \":E\" & lastRow).Value"]
[null,null,null,null,null,null,null,null,"        ElseIf lastRow > 1 Then"]
[null,null,null,null,null,null,null,null,"            .List = ws.Range(\"A2:E\" & lastRow).Value"]
[null,null,null,null,null,null,null,null,"        End If"]
[null,null,null,null,null,null,null,null,"    End With"]
[null,null,null,null,null,null,null,null,"End Sub"]
[]
[null,null,null,null,null,null,null,null,"Private Sub TxtQty_Change()"]
[null,null,null,null,null,null,null,null,"    ' كود إضافي لتحسين تجربة المستخدم"]
[null,null,null,null,null,null,null,null,"    On Error Resume Next"]
[null,null,null,null,null,null,null,null,"    ' (بافتراض أنك حسبت CurrentStock مسبقاً)"]
[null,null,null,null,null,null,null,null,"    If CDbl(TxtQty.Value) > CurrentStock Then"]
[null,null,null,null,null,null,null,null,"        TxtQty.BackColor = vbRed"]
[null,null,null,null,null,null,null,null,"        TxtQty.ForeColor = vbWhite"]
[null,null,null,null,null,null,null,null,"    Else"]
[null,null,null,null,null,null,null,null,"        TxtQty.BackColor = vbWhite"]
[null,null,null,null,null,null,null,null,"        TxtQty.ForeColor = vbBlack"]
[null,null,null,null,null,null,null,null,"    End If"]
[null,null,null,null,null,null,null,null,"End Sub"]