/* === 1. CSS منع الخروج من الجوانب === */ *{box-sizing:border-box !important} html,body{overflow-x:hidden !important; max-width:100vw !important} #app{max-width:100% !important; padding:6px !important; overflow-x:hidden !important} .input,select.input{max-width:100% !important; height:36px !important; border-radius:10px !important; background:#f8fafc !important; border:1.5px solid #e2e8f0 !important} /* === 2. دالة tog() فتح وقفل القوائم === */ function tog(id){ var el=document.getElementById(id); if(!el) return; el.classList.toggle('open'); var arrows=document.querySelectorAll('[onclick="tog(\''+id+'\')"] .acc-arrow'); arrows.forEach(function(a){a.textContent=el.classList.contains('open')?'▲':'▼';}); } /* === 3. دالة calcDisc() حساب الخصم === */ function calcDisc(pp){ if(!pp||!pp.discount) return 0; var v=parseFloat(pp.discount.value||0)||0; if(v<=0) return 0; if(pp.discount.type==='percent') return Math.round((pp.price||0)*v/100); return v; } /* === 4. إضافة عميل جديد (HTML) === */
👤
إضافة عميل / شركة جديدة
/* === 5. إضافة منتج جديد (HTML) === */
➕
إضافة منتج جديد
/* === 6. تجميع منتجات كل شركة في قائمة تفتح وتقفل === */ var grouped={}; db.clients.forEach(function(c,ci){ grouped[ci]={client:c, products:[]}; }); db.products.forEach(function(p,pi){ var cid=p.clientId; if(grouped[cid]) grouped[cid].products.push({p:p, pi:pi}); else { if(!grouped['no']) grouped['no']={client:{name:'بدون شركة'}, products:[]}; grouped['no'].products.push({p:p, pi:pi}); } }); /* === 7. تعديل سعر / منتج / خصم === */ function editProductPrice(i){ var p=db.products[i]; if(!p) return; var np=prompt('تعديل سعر البيع - الحالي: '+(p.price||0)+' ج\nأدخل السعر الجديد:', p.price||0); if(np===null) return; np=parseFloat(np)||0; if(np<=0){ alert('سعر غير صحيح'); return; } p.price=np; save(); render(); } function editProductName(i){ var p=db.products[i]; if(!p) return; var nn=prompt('تعديل اسم المنتج - الحالي: '+p.name+'\nالاسم الجديد:', p.name); if(!nn) return; p.name=nn.trim(); save(); render(); } function editProductDiscount(i){ var p=db.products[i]; if(!p) return; var type=prompt('نوع الخصم:\n1 = نسبة %\n2 = مبلغ ثابت\nأدخل 1 أو 2:','1'); if(type===null) return; var val=prompt('قيمة الخصم:', p.discount?.value||0); if(val===null) return; val=parseFloat(val)||0; var reason=prompt('سبب الخصم (اختياري):', p.discount?.reason||''); if(!p.discount) p.discount={}; p.discount.type=(type==='1'?'percent':'fixed'); p.discount.value=val; p.discount.reason=reason||''; save(); render(); } /* === 8. إضافة دفعات من العميل === */ function addProductPaymentUI(i){ var p=db.products[i]; if(!p) return; var amount=prompt('إضافة دفعة من العميل - المبلغ:'); if(!amount) return; amount=parseFloat(amount)||0; if(amount<=0){ alert('مبلغ غير صحيح'); return; } var type=prompt('نوع الدفعة (دفعة / مقدم / دفعة أخيرة):','دفعة')||'دفعة'; var method=prompt('طريقة التحويل (نقدي / تحويل بنكي / فودافون كاش / شيك):','نقدي')||'نقدي'; if(!p.payments) p.payments=[]; p.payments.push({amount:amount, type:type, method:method, date:new Date().toISOString(), transferType:method}); save(); render(); } /* === 9. كشف PDF شامل === */ function exportPDF(){ var w=window.open('','_blank'); var html='كشف اسطمبة استيل'; html+=''; html+='

📄 كشف حساب - اسطمبة استيل - '+new Date().toLocaleDateString('ar-EG')+'

'; db.clients.forEach(function(c,ci){ var prods=db.products.filter(function(p){return p.clientId==ci}); if(!prods.length) return; html+='

🏢 '+c.name+' - '+(c.phone||'')+'

'; html+=''; prods.forEach(function(p){ var disc=calcDisc(p); var paid=(p.payments||[]).reduce(function(s,x){return s+(x.amount||0)},0); var remain=(p.price||0)-disc-paid; html+=''; }); html+='
المنتجالسعرالخصمالمدفوعالمتبقيالحالة
'+p.name+''+p.price+' ج'+disc+' ج'+paid+' ج'+remain+' ج'+(p.status||'مفتوح')+'
'; }); var totalPrice=db.products.reduce(function(s,p){return s+(p.price||0)},0); var totalDisc=db.products.reduce(function(s,p){return s+calcDisc(p)},0); var totalPaid=db.products.reduce(function(s,p){return s+((p.payments||[]).reduce(function(a,b){return a+(b.amount||0)},0))},0); html+='
الإجمالي: '+totalPrice+' جالخصم: '+totalDisc+' جالمدفوع: '+totalPaid+' جالمتبقي: '+(totalPrice-totalDisc-totalPaid)+' ج
'; html+=''; w.document.write(html); w.document.close(); setTimeout(function(){ w.print(); }, 500); }