almakhmri253-stack commited on
Commit
aeaf77c
·
1 Parent(s): f0ecb9f

Add full bilingual translation to Invoices/Create, Purchases/Create, Purchases/Index, PurchaseReturns pages

Browse files
Views/Invoices/Create.cshtml CHANGED
@@ -1,12 +1,12 @@
1
  @model OilShopManagement.ViewModels.InvoiceCreateViewModel
2
  @{
3
- ViewData["Title"] = "فاتورة جديدة";
4
  }
5
 
6
  <div class="d-flex align-items-center justify-content-between mb-3">
7
- <h4 class="fw-bold mb-0"><i class="bi bi-plus-circle me-2 text-primary"></i>فاتورة جديدة</h4>
8
  <a href="/Invoices" class="btn btn-outline-secondary rounded-pill btn-sm">
9
- <i class="bi bi-arrow-right me-1"></i>الفواتير
10
  </a>
11
  </div>
12
 
@@ -16,12 +16,12 @@
16
  <!-- Product Search -->
17
  <div class="card mb-3">
18
  <div class="card-header">
19
- <i class="bi bi-search me-2 text-primary"></i>إضافة منتج
20
  </div>
21
  <div class="card-body">
22
  <div class="product-search-box">
23
  <input type="text" id="productSearch" class="form-control form-control-lg"
24
- placeholder="ابحث باسم المنتج أو الرمز..."
25
  autocomplete="off">
26
  <div id="productSuggestions" class="product-suggestions d-none"></div>
27
  </div>
@@ -32,7 +32,7 @@
32
  <div class="card mb-3">
33
  <div class="card-header d-flex align-items-center justify-content-between py-2"
34
  style="cursor:pointer" onclick="toggleProductBrowser()">
35
- <span><i class="bi bi-grid me-2 text-success"></i>المنتجات المتوفرة</span>
36
  <div class="d-flex align-items-center gap-2">
37
  <span class="badge bg-success-subtle text-success rounded-pill" id="inStockCount">...</span>
38
  <i class="bi bi-chevron-down" id="browserChevron"></i>
@@ -40,7 +40,7 @@
40
  </div>
41
  <div id="productBrowser" class="card-body p-2">
42
  <input type="text" id="browserFilter" class="form-control form-control-sm mb-2"
43
- placeholder="فلتر المنتجات..." oninput="filterBrowser(this.value)">
44
  <div id="productGrid" class="d-flex flex-wrap gap-2" style="max-height:220px;overflow-y:auto"></div>
45
  </div>
46
  </div>
@@ -48,18 +48,18 @@
48
  <!-- Items Table -->
49
  <div class="card">
50
  <div class="card-header d-flex align-items-center justify-content-between">
51
- <span><i class="bi bi-list-check me-2"></i>المنتجات</span>
52
- <span class="badge bg-primary rounded-pill" id="itemCount">0 منتج</span>
53
  </div>
54
  <div class="card-body p-0">
55
  <div class="table-responsive">
56
  <table class="table mb-0" id="itemsTable">
57
  <thead>
58
  <tr>
59
- <th>المنتج</th>
60
- <th style="width:110px">الكمية</th>
61
- <th style="width:130px">السعر</th>
62
- <th style="width:130px">الإجمالي</th>
63
  <th style="width:50px"></th>
64
  </tr>
65
  </thead>
@@ -67,7 +67,7 @@
67
  <tr id="emptyRow">
68
  <td colspan="5" class="text-center text-muted py-5">
69
  <i class="bi bi-cart-x fs-2 d-block mb-2"></i>
70
- ابحث عن منتج وأضفه للفاتورة
71
  </td>
72
  </tr>
73
  </tbody>
@@ -81,15 +81,17 @@
81
  <div>
82
  <div class="invoice-summary card">
83
  <div class="card-header fw-bold">
84
- <i class="bi bi-receipt me-2 text-primary"></i>ملخص الفاتورة
85
  </div>
86
  <div class="card-body">
87
  <!-- Customer -->
88
  <div class="mb-3">
89
- <label class="form-label fw-semibold small">العميل (اختياري)</label>
90
  <div class="input-group">
91
- <input type="text" id="customerSearch" class="form-control form-control-sm" placeholder="اسم العميل أو الجوال...">
92
- <button class="btn btn-outline-secondary btn-sm" type="button" id="clearCustomer" title="مسح">
 
 
93
  <i class="bi bi-x"></i>
94
  </button>
95
  </div>
@@ -100,51 +102,52 @@
100
 
101
  <!-- Date & Payment -->
102
  <div class="mb-3">
103
- <label class="form-label fw-semibold small">تاريخ الفاتورة</label>
104
  <input type="datetime-local" id="invoiceDate" class="form-control form-control-sm"
105
  value="@DateTime.Now.ToString("yyyy-MM-ddTHH:mm", System.Globalization.CultureInfo.InvariantCulture)">
106
  </div>
107
  <div class="mb-3">
108
- <label class="form-label fw-semibold small">طريقة الدفع</label>
109
  <select id="paymentMethod" class="form-select form-select-sm">
110
- <option value="0">نقداً</option>
111
- <option value="1">بطاقة</option>
112
- <option value="2">تحويل</option>
113
  </select>
114
  </div>
115
 
116
  <hr>
117
  <!-- Totals -->
118
  <div class="d-flex justify-content-between align-items-center mb-2">
119
- <span class="text-muted">الإجمالي قبل الضريبة</span>
120
  <input type="number" id="subTotal" class="form-control form-control-sm text-end fw-semibold"
121
  style="width:120px" min="0" step="0.001" value="0" placeholder="0.000">
122
  </div>
123
  <div class="d-flex justify-content-between align-items-center mb-2">
124
- <span class="text-muted">الضريبة
125
  <input type="number" id="taxRate" value="15" min="0" max="100"
126
  class="form-control form-control-sm d-inline-block ms-1" style="width:55px">%
127
  </span>
128
  <span id="taxAmount" class="fw-semibold">0.00</span>
129
  </div>
130
  <div class="d-flex justify-content-between align-items-center mb-3">
131
- <span class="text-muted">خصم (ر.ع.)</span>
132
  <input type="number" id="discount" value="0" min="0"
133
  class="form-control form-control-sm text-end" style="width:100px">
134
  </div>
135
  <hr>
136
  <div class="d-flex justify-content-between mb-3">
137
- <span class="fw-bold fs-5">الإجمالي النهائي</span>
138
- <span id="totalAmount" class="fw-bold fs-5 text-primary">0.00 ر.ع.</span>
139
  </div>
140
 
141
  <div class="mb-3">
142
- <label class="form-label fw-semibold small">ملاحظات</label>
143
- <textarea id="notes" class="form-control form-control-sm" rows="2" placeholder="ملاحظات..."></textarea>
 
144
  </div>
145
 
146
  <button type="button" id="saveInvoice" class="btn btn-primary w-100 btn-lg rounded-pill" disabled>
147
- <i class="bi bi-save2 me-2"></i>حفظ الفاتورة
148
  </button>
149
  </div>
150
  </div>
@@ -153,6 +156,22 @@
153
 
154
  @section Scripts {
155
  <script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
  let invoiceItems = [];
157
  let allProducts = [];
158
  fetch('/Products/GetAllJson').then(r => r.json()).then(d => {
@@ -165,16 +184,16 @@ let browserProducts = [];
165
  function getDisplayStock(p) {
166
  const isCarton = (p.unit === 'كرتون' || p.unit === 'Carton') && p.piecesPerUnit > 0;
167
  return isCarton
168
- ? { displayStock: (p.currentStock * p.piecesPerUnit) + ' حبة', displayUnit: 'كرتون (' + p.piecesPerUnit + ' حبة)' }
169
  : { displayStock: p.currentStock + ' ' + p.unit, displayUnit: p.unit };
170
  }
171
 
172
  function renderProductBrowser(products) {
173
  browserProducts = products.filter(p => p.currentStock > 0);
174
- document.getElementById('inStockCount').textContent = browserProducts.length + ' صنف';
175
  const grid = document.getElementById('productGrid');
176
  if (!browserProducts.length) {
177
- grid.innerHTML = '<div class="text-muted small p-2">لا توجد منتجات متوفرة</div>';
178
  return;
179
  }
180
  grid.innerHTML = browserProducts.map((p, idx) => {
@@ -200,14 +219,11 @@ function addItemFromBrowser(idx) {
200
  const ppu = p.piecesPerUnit || 0;
201
  const isCarton = (p.unit === 'كرتون' || p.unit === 'Carton') && ppu > 0;
202
  addItem({
203
- id: p.id,
204
- name: p.name,
205
- salePrice: p.salePrice,
206
- purchasePrice: p.purchasePrice,
207
  currentStock: isCarton ? p.currentStock * ppu : p.currentStock,
208
- unit: isCarton ? 'حبة' : p.unit,
209
- piecesPerUnit: ppu,
210
- isCarton
211
  });
212
  }
213
 
@@ -253,9 +269,9 @@ function renderSuggestions(products) {
253
  data-unit="${p.unit}" data-pieces="${p.piecesPerUnit || 0}">
254
  <div>
255
  <div class="fw-semibold small">${p.name}${p.litersPerPiece > 0 ? ` <span style="font-size:.65rem;background:#e0f2fe;color:#0369a1;padding:.1rem .35rem;border-radius:20px;font-weight:700">${p.litersPerPiece % 1 === 0 ? parseInt(p.litersPerPiece) : p.litersPerPiece}L</span>` : ''}</div>
256
- <small class="text-muted">${displayUnit} | متوفر: ${displayStock}</small>
257
  </div>
258
- <span class="badge bg-primary-subtle text-primary">${parseFloat(p.salePrice).toFixed(3)} ر.ع.</span>
259
  </div>`;
260
  }).join('');
261
  productSuggestions.classList.remove('d-none');
@@ -266,14 +282,11 @@ function renderSuggestions(products) {
266
  const rawStock = parseInt(el.dataset.stock);
267
  const isCarton = (el.dataset.unit === 'كرتون' || el.dataset.unit === 'Carton') && ppu > 0;
268
  addItem({
269
- id: parseInt(el.dataset.id),
270
- name: el.dataset.name,
271
- salePrice: parseFloat(el.dataset.price),
272
- purchasePrice: parseFloat(el.dataset.purchase),
273
  currentStock: isCarton ? rawStock * ppu : rawStock,
274
- unit: isCarton ? 'حبة' : el.dataset.unit,
275
- piecesPerUnit: ppu,
276
- isCarton
277
  });
278
  productSearch.value = '';
279
  productSuggestions.classList.add('d-none');
@@ -289,21 +302,18 @@ function addItem(product) {
289
  const existing = invoiceItems.find(i => i.productId === product.id);
290
  if (existing) {
291
  if (existing.quantity >= product.currentStock) {
292
- showToast(`الكمية المتوفرة ${product.currentStock} فقط`, 'danger');
293
  return;
294
  }
295
  existing.quantity++;
296
  existing.total = existing.quantity * existing.unitPrice;
297
  } else {
298
  invoiceItems.push({
299
- productId: product.id,
300
- productName: product.name,
301
- quantity: 1,
302
- unitPrice: product.salePrice,
303
  purchasePrice: product.purchasePrice,
304
  total: product.salePrice,
305
- maxStock: product.currentStock,
306
- unit: product.unit
307
  });
308
  }
309
  renderItems();
@@ -312,16 +322,13 @@ function addItem(product) {
312
 
313
  function renderItems() {
314
  const tbody = document.getElementById('itemsBody');
315
- const emptyRow = document.getElementById('emptyRow');
316
-
317
  if (!invoiceItems.length) {
318
  tbody.innerHTML = `<tr id="emptyRow"><td colspan="5" class="text-center text-muted py-5">
319
- <i class="bi bi-cart-x fs-2 d-block mb-2"></i>ابحث عن منتج وأضفه للفاتورة</td></tr>`;
320
- document.getElementById('itemCount').textContent = '0 منتج';
321
  document.getElementById('saveInvoice').disabled = true;
322
  return;
323
  }
324
-
325
  tbody.innerHTML = invoiceItems.map((item, idx) => `
326
  <tr>
327
  <td>
@@ -348,8 +355,7 @@ function renderItems() {
348
  </td>
349
  </tr>
350
  `).join('');
351
-
352
- document.getElementById('itemCount').textContent = `${invoiceItems.length} منتج`;
353
  document.getElementById('saveInvoice').disabled = false;
354
  }
355
 
@@ -357,32 +363,25 @@ function changeQty(idx, delta) {
357
  const item = invoiceItems[idx];
358
  const newQty = item.quantity + delta;
359
  if (newQty < 1) return;
360
- if (newQty > item.maxStock) { showToast(`الكمية المتوفرة ${item.maxStock} فقط`, 'warning'); return; }
361
  item.quantity = newQty;
362
  item.total = newQty * item.unitPrice;
363
- renderItems();
364
- calcTotals(true);
365
  }
366
-
367
  function setQty(idx, val) {
368
  const qty = Math.max(1, Math.min(parseInt(val) || 1, invoiceItems[idx].maxStock));
369
  invoiceItems[idx].quantity = qty;
370
  invoiceItems[idx].total = qty * invoiceItems[idx].unitPrice;
371
- renderItems();
372
- calcTotals(true);
373
  }
374
-
375
  function setPrice(idx, val) {
376
  invoiceItems[idx].unitPrice = parseFloat(val) || 0;
377
  invoiceItems[idx].total = invoiceItems[idx].quantity * invoiceItems[idx].unitPrice;
378
- renderItems();
379
- calcTotals(true);
380
  }
381
-
382
  function removeItem(idx) {
383
  invoiceItems.splice(idx, 1);
384
- renderItems();
385
- calcTotals(true);
386
  }
387
 
388
  function calcTotals(fromItems = false) {
@@ -391,21 +390,20 @@ function calcTotals(fromItems = false) {
391
  document.getElementById('subTotal').value = computed.toFixed(3);
392
  }
393
  const subTotal = parseFloat(document.getElementById('subTotal').value) || 0;
394
- const taxRate = parseFloat(document.getElementById('taxRate').value) || 0;
395
  const discount = parseFloat(document.getElementById('discount').value) || 0;
396
  const taxAmount = subTotal * (taxRate / 100);
397
  const total = subTotal + taxAmount - discount;
398
-
399
- document.getElementById('taxAmount').textContent = taxAmount.toFixed(3) + ' ر.ع.';
400
- document.getElementById('totalAmount').textContent = total.toFixed(3) + ' ر.ع.';
401
  }
402
 
403
  document.getElementById('subTotal').addEventListener('input', () => { calcTotals(false); updateSaveBtn(); });
404
- document.getElementById('taxRate').addEventListener('input', () => calcTotals(false));
405
  document.getElementById('discount').addEventListener('input', () => calcTotals(false));
406
 
407
  function updateSaveBtn() {
408
- const hasItems = invoiceItems.length > 0;
409
  const hasManual = (parseFloat(document.getElementById('subTotal').value) || 0) > 0;
410
  document.getElementById('saveInvoice').disabled = !hasItems && !hasManual;
411
  }
@@ -437,7 +435,7 @@ customerSearch.addEventListener('input', () => {
437
  document.getElementById('selectedCustomerId').value = el.dataset.id;
438
  customerSearch.value = el.dataset.name;
439
  customerSuggestions.classList.add('d-none');
440
- document.getElementById('selectedCustomerInfo').textContent = '✓ تم اختيار العميل';
441
  document.getElementById('selectedCustomerInfo').classList.remove('d-none');
442
  });
443
  });
@@ -450,7 +448,6 @@ document.getElementById('clearCustomer').addEventListener('click', () => {
450
  document.getElementById('selectedCustomerInfo').classList.add('d-none');
451
  customerSuggestions.classList.add('d-none');
452
  });
453
-
454
  document.addEventListener('click', e => {
455
  if (!customerSearch.closest('.mb-3').contains(e.target))
456
  customerSuggestions.classList.add('d-none');
@@ -462,27 +459,21 @@ document.getElementById('saveInvoice').addEventListener('click', async () => {
462
  if (!invoiceItems.length && manualSubTotalVal <= 0) return;
463
  const btn = document.getElementById('saveInvoice');
464
  btn.disabled = true;
465
- btn.innerHTML = '<span class="spinner-border spinner-border-sm me-2"></span>جاري الحفظ...';
466
 
467
- const manualSubTotal = parseFloat(document.getElementById('subTotal').value) || 0;
468
- const taxRate = parseFloat(document.getElementById('taxRate').value) || 0;
469
  const discount = parseFloat(document.getElementById('discount').value) || 0;
470
 
471
  const payload = {
472
  customerId: document.getElementById('selectedCustomerId').value || null,
473
  invoiceDate: document.getElementById('invoiceDate').value,
474
  paymentMethod: parseInt(document.getElementById('paymentMethod').value),
475
- taxRate,
476
- discount,
477
- manualSubTotal,
478
  notes: document.getElementById('notes').value,
479
  items: invoiceItems.map(i => ({
480
- productId: i.productId,
481
- productName: i.productName,
482
- quantity: i.quantity,
483
- unitPrice: i.unitPrice,
484
- purchasePrice: i.purchasePrice,
485
- total: i.total
486
  }))
487
  };
488
 
@@ -499,14 +490,14 @@ document.getElementById('saveInvoice').addEventListener('click', async () => {
499
  if (res.ok) {
500
  window.location.href = `/Invoices/Print/${data.invoiceId}`;
501
  } else {
502
- showToast(data.message || 'حدث خطأ', 'danger');
503
  btn.disabled = false;
504
- btn.innerHTML = '<i class="bi bi-save2 me-2"></i>حفظ الفاتورة';
505
  }
506
  } catch {
507
- showToast('خطأ في الاتصال', 'danger');
508
  btn.disabled = false;
509
- btn.innerHTML = '<i class="bi bi-save2 me-2"></i>حفظ الفاتورة';
510
  }
511
  });
512
 
 
1
  @model OilShopManagement.ViewModels.InvoiceCreateViewModel
2
  @{
3
+ ViewData["Title"] = L.T("فاتورة جديدة","New Invoice");
4
  }
5
 
6
  <div class="d-flex align-items-center justify-content-between mb-3">
7
+ <h4 class="fw-bold mb-0"><i class="bi bi-plus-circle me-2 text-primary"></i>@L.T("فاتورة جديدة","New Invoice")</h4>
8
  <a href="/Invoices" class="btn btn-outline-secondary rounded-pill btn-sm">
9
+ <i class="bi bi-arrow-right me-1"></i>@L.T("الفواتير","Invoices")
10
  </a>
11
  </div>
12
 
 
16
  <!-- Product Search -->
17
  <div class="card mb-3">
18
  <div class="card-header">
19
+ <i class="bi bi-search me-2 text-primary"></i>@L.T("إضافة منتج","Add Product")
20
  </div>
21
  <div class="card-body">
22
  <div class="product-search-box">
23
  <input type="text" id="productSearch" class="form-control form-control-lg"
24
+ placeholder="@L.T("ابحث باسم المنتج أو الرمز...","Search by product name or SKU...")"
25
  autocomplete="off">
26
  <div id="productSuggestions" class="product-suggestions d-none"></div>
27
  </div>
 
32
  <div class="card mb-3">
33
  <div class="card-header d-flex align-items-center justify-content-between py-2"
34
  style="cursor:pointer" onclick="toggleProductBrowser()">
35
+ <span><i class="bi bi-grid me-2 text-success"></i>@L.T("المنتجات المتوفرة","Available Products")</span>
36
  <div class="d-flex align-items-center gap-2">
37
  <span class="badge bg-success-subtle text-success rounded-pill" id="inStockCount">...</span>
38
  <i class="bi bi-chevron-down" id="browserChevron"></i>
 
40
  </div>
41
  <div id="productBrowser" class="card-body p-2">
42
  <input type="text" id="browserFilter" class="form-control form-control-sm mb-2"
43
+ placeholder="@L.T("فلتر المنتجات...","Filter products...")" oninput="filterBrowser(this.value)">
44
  <div id="productGrid" class="d-flex flex-wrap gap-2" style="max-height:220px;overflow-y:auto"></div>
45
  </div>
46
  </div>
 
48
  <!-- Items Table -->
49
  <div class="card">
50
  <div class="card-header d-flex align-items-center justify-content-between">
51
+ <span><i class="bi bi-list-check me-2"></i>@L.T("المنتجات","Products")</span>
52
+ <span class="badge bg-primary rounded-pill" id="itemCount">0</span>
53
  </div>
54
  <div class="card-body p-0">
55
  <div class="table-responsive">
56
  <table class="table mb-0" id="itemsTable">
57
  <thead>
58
  <tr>
59
+ <th>@L.T("المنتج","Product")</th>
60
+ <th style="width:110px">@L.T("الكمية","Qty")</th>
61
+ <th style="width:130px">@L.T("السعر","Price")</th>
62
+ <th style="width:130px">@L.T("الإجمالي","Total")</th>
63
  <th style="width:50px"></th>
64
  </tr>
65
  </thead>
 
67
  <tr id="emptyRow">
68
  <td colspan="5" class="text-center text-muted py-5">
69
  <i class="bi bi-cart-x fs-2 d-block mb-2"></i>
70
+ @L.T("ابحث عن منتج وأضفه للفاتورة","Search and add a product to the invoice")
71
  </td>
72
  </tr>
73
  </tbody>
 
81
  <div>
82
  <div class="invoice-summary card">
83
  <div class="card-header fw-bold">
84
+ <i class="bi bi-receipt me-2 text-primary"></i>@L.T("ملخص الفاتورة","Invoice Summary")
85
  </div>
86
  <div class="card-body">
87
  <!-- Customer -->
88
  <div class="mb-3">
89
+ <label class="form-label fw-semibold small">@L.T("العميل (اختياري)","Customer (optional)")</label>
90
  <div class="input-group">
91
+ <input type="text" id="customerSearch" class="form-control form-control-sm"
92
+ placeholder="@L.T("اسم العميل أو الجوال...","Customer name or phone...")">
93
+ <button class="btn btn-outline-secondary btn-sm" type="button" id="clearCustomer"
94
+ title="@L.T("مسح","Clear")">
95
  <i class="bi bi-x"></i>
96
  </button>
97
  </div>
 
102
 
103
  <!-- Date & Payment -->
104
  <div class="mb-3">
105
+ <label class="form-label fw-semibold small">@L.T("تاريخ الفاتورة","Invoice Date")</label>
106
  <input type="datetime-local" id="invoiceDate" class="form-control form-control-sm"
107
  value="@DateTime.Now.ToString("yyyy-MM-ddTHH:mm", System.Globalization.CultureInfo.InvariantCulture)">
108
  </div>
109
  <div class="mb-3">
110
+ <label class="form-label fw-semibold small">@L.T("طريقة الدفع","Payment Method")</label>
111
  <select id="paymentMethod" class="form-select form-select-sm">
112
+ <option value="0">@L.T("نقداً","Cash")</option>
113
+ <option value="1">@L.T("بطاقة","Card")</option>
114
+ <option value="2">@L.T("تحويل","Transfer")</option>
115
  </select>
116
  </div>
117
 
118
  <hr>
119
  <!-- Totals -->
120
  <div class="d-flex justify-content-between align-items-center mb-2">
121
+ <span class="text-muted">@L.T("الإجمالي قبل الضريبة","Subtotal")</span>
122
  <input type="number" id="subTotal" class="form-control form-control-sm text-end fw-semibold"
123
  style="width:120px" min="0" step="0.001" value="0" placeholder="0.000">
124
  </div>
125
  <div class="d-flex justify-content-between align-items-center mb-2">
126
+ <span class="text-muted">@L.T("الضريبة","Tax")
127
  <input type="number" id="taxRate" value="15" min="0" max="100"
128
  class="form-control form-control-sm d-inline-block ms-1" style="width:55px">%
129
  </span>
130
  <span id="taxAmount" class="fw-semibold">0.00</span>
131
  </div>
132
  <div class="d-flex justify-content-between align-items-center mb-3">
133
+ <span class="text-muted">@L.T("خصم","Discount") (@L.T("ر.ع.","OMR"))</span>
134
  <input type="number" id="discount" value="0" min="0"
135
  class="form-control form-control-sm text-end" style="width:100px">
136
  </div>
137
  <hr>
138
  <div class="d-flex justify-content-between mb-3">
139
+ <span class="fw-bold fs-5">@L.T("الإجمالي النهائي","Grand Total")</span>
140
+ <span id="totalAmount" class="fw-bold fs-5 text-primary">0.00 @L.T("ر.ع.","OMR")</span>
141
  </div>
142
 
143
  <div class="mb-3">
144
+ <label class="form-label fw-semibold small">@L.T("ملاحظات","Notes")</label>
145
+ <textarea id="notes" class="form-control form-control-sm" rows="2"
146
+ placeholder="@L.T("ملاحظات...","Notes...")"></textarea>
147
  </div>
148
 
149
  <button type="button" id="saveInvoice" class="btn btn-primary w-100 btn-lg rounded-pill" disabled>
150
+ <i class="bi bi-save2 me-2"></i>@L.T("حفظ الفاتورة","Save Invoice")
151
  </button>
152
  </div>
153
  </div>
 
156
 
157
  @section Scripts {
158
  <script>
159
+ const T = {
160
+ inStock: '@L.T("صنف","items")',
161
+ noProducts: '@L.T("لا توجد منتجات متوفرة","No products available")',
162
+ addProduct: '@L.T("ابحث عن منتج وأضفه للفاتورة","Search and add a product to the invoice")',
163
+ available: '@L.T("متوفر","available")',
164
+ unit: '@L.T("وحدة","unit")',
165
+ customerChosen: '@L.T("✓ تم اختيار العميل","✓ Customer selected")',
166
+ saving: '@L.T("جاري الحفظ...","Saving...")',
167
+ saveInvoice: '@L.T("حفظ الفاتورة","Save Invoice")',
168
+ errorOccurred: '@L.T("حدث خطأ","An error occurred")',
169
+ connError: '@L.T("خطأ في الاتصال","Connection error")',
170
+ stockOnly: '@L.T("الكمية المتوفرة","Stock available")',
171
+ omr: '@L.T("ر.ع.","OMR")',
172
+ items: '@L.T("منتج","item")',
173
+ };
174
+
175
  let invoiceItems = [];
176
  let allProducts = [];
177
  fetch('/Products/GetAllJson').then(r => r.json()).then(d => {
 
184
  function getDisplayStock(p) {
185
  const isCarton = (p.unit === 'كرتون' || p.unit === 'Carton') && p.piecesPerUnit > 0;
186
  return isCarton
187
+ ? { displayStock: (p.currentStock * p.piecesPerUnit) + ' ' + T.items, displayUnit: 'كرتون (' + p.piecesPerUnit + ' ' + T.items + ')' }
188
  : { displayStock: p.currentStock + ' ' + p.unit, displayUnit: p.unit };
189
  }
190
 
191
  function renderProductBrowser(products) {
192
  browserProducts = products.filter(p => p.currentStock > 0);
193
+ document.getElementById('inStockCount').textContent = browserProducts.length + ' ' + T.inStock;
194
  const grid = document.getElementById('productGrid');
195
  if (!browserProducts.length) {
196
+ grid.innerHTML = '<div class="text-muted small p-2">' + T.noProducts + '</div>';
197
  return;
198
  }
199
  grid.innerHTML = browserProducts.map((p, idx) => {
 
219
  const ppu = p.piecesPerUnit || 0;
220
  const isCarton = (p.unit === 'كرتون' || p.unit === 'Carton') && ppu > 0;
221
  addItem({
222
+ id: p.id, name: p.name,
223
+ salePrice: p.salePrice, purchasePrice: p.purchasePrice,
 
 
224
  currentStock: isCarton ? p.currentStock * ppu : p.currentStock,
225
+ unit: isCarton ? T.items : p.unit,
226
+ piecesPerUnit: ppu, isCarton
 
227
  });
228
  }
229
 
 
269
  data-unit="${p.unit}" data-pieces="${p.piecesPerUnit || 0}">
270
  <div>
271
  <div class="fw-semibold small">${p.name}${p.litersPerPiece > 0 ? ` <span style="font-size:.65rem;background:#e0f2fe;color:#0369a1;padding:.1rem .35rem;border-radius:20px;font-weight:700">${p.litersPerPiece % 1 === 0 ? parseInt(p.litersPerPiece) : p.litersPerPiece}L</span>` : ''}</div>
272
+ <small class="text-muted">${displayUnit} | ${T.available}: ${displayStock}</small>
273
  </div>
274
+ <span class="badge bg-primary-subtle text-primary">${parseFloat(p.salePrice).toFixed(3)} ${T.omr}</span>
275
  </div>`;
276
  }).join('');
277
  productSuggestions.classList.remove('d-none');
 
282
  const rawStock = parseInt(el.dataset.stock);
283
  const isCarton = (el.dataset.unit === 'كرتون' || el.dataset.unit === 'Carton') && ppu > 0;
284
  addItem({
285
+ id: parseInt(el.dataset.id), name: el.dataset.name,
286
+ salePrice: parseFloat(el.dataset.price), purchasePrice: parseFloat(el.dataset.purchase),
 
 
287
  currentStock: isCarton ? rawStock * ppu : rawStock,
288
+ unit: isCarton ? T.items : el.dataset.unit,
289
+ piecesPerUnit: ppu, isCarton
 
290
  });
291
  productSearch.value = '';
292
  productSuggestions.classList.add('d-none');
 
302
  const existing = invoiceItems.find(i => i.productId === product.id);
303
  if (existing) {
304
  if (existing.quantity >= product.currentStock) {
305
+ showToast(`${T.stockOnly}: ${product.currentStock}`, 'danger');
306
  return;
307
  }
308
  existing.quantity++;
309
  existing.total = existing.quantity * existing.unitPrice;
310
  } else {
311
  invoiceItems.push({
312
+ productId: product.id, productName: product.name,
313
+ quantity: 1, unitPrice: product.salePrice,
 
 
314
  purchasePrice: product.purchasePrice,
315
  total: product.salePrice,
316
+ maxStock: product.currentStock, unit: product.unit
 
317
  });
318
  }
319
  renderItems();
 
322
 
323
  function renderItems() {
324
  const tbody = document.getElementById('itemsBody');
 
 
325
  if (!invoiceItems.length) {
326
  tbody.innerHTML = `<tr id="emptyRow"><td colspan="5" class="text-center text-muted py-5">
327
+ <i class="bi bi-cart-x fs-2 d-block mb-2"></i>${T.addProduct}</td></tr>`;
328
+ document.getElementById('itemCount').textContent = '0';
329
  document.getElementById('saveInvoice').disabled = true;
330
  return;
331
  }
 
332
  tbody.innerHTML = invoiceItems.map((item, idx) => `
333
  <tr>
334
  <td>
 
355
  </td>
356
  </tr>
357
  `).join('');
358
+ document.getElementById('itemCount').textContent = invoiceItems.length;
 
359
  document.getElementById('saveInvoice').disabled = false;
360
  }
361
 
 
363
  const item = invoiceItems[idx];
364
  const newQty = item.quantity + delta;
365
  if (newQty < 1) return;
366
+ if (newQty > item.maxStock) { showToast(`${T.stockOnly}: ${item.maxStock}`, 'warning'); return; }
367
  item.quantity = newQty;
368
  item.total = newQty * item.unitPrice;
369
+ renderItems(); calcTotals(true);
 
370
  }
 
371
  function setQty(idx, val) {
372
  const qty = Math.max(1, Math.min(parseInt(val) || 1, invoiceItems[idx].maxStock));
373
  invoiceItems[idx].quantity = qty;
374
  invoiceItems[idx].total = qty * invoiceItems[idx].unitPrice;
375
+ renderItems(); calcTotals(true);
 
376
  }
 
377
  function setPrice(idx, val) {
378
  invoiceItems[idx].unitPrice = parseFloat(val) || 0;
379
  invoiceItems[idx].total = invoiceItems[idx].quantity * invoiceItems[idx].unitPrice;
380
+ renderItems(); calcTotals(true);
 
381
  }
 
382
  function removeItem(idx) {
383
  invoiceItems.splice(idx, 1);
384
+ renderItems(); calcTotals(true);
 
385
  }
386
 
387
  function calcTotals(fromItems = false) {
 
390
  document.getElementById('subTotal').value = computed.toFixed(3);
391
  }
392
  const subTotal = parseFloat(document.getElementById('subTotal').value) || 0;
393
+ const taxRate = parseFloat(document.getElementById('taxRate').value) || 0;
394
  const discount = parseFloat(document.getElementById('discount').value) || 0;
395
  const taxAmount = subTotal * (taxRate / 100);
396
  const total = subTotal + taxAmount - discount;
397
+ document.getElementById('taxAmount').textContent = taxAmount.toFixed(3) + ' ' + T.omr;
398
+ document.getElementById('totalAmount').textContent = total.toFixed(3) + ' ' + T.omr;
 
399
  }
400
 
401
  document.getElementById('subTotal').addEventListener('input', () => { calcTotals(false); updateSaveBtn(); });
402
+ document.getElementById('taxRate').addEventListener('input', () => calcTotals(false));
403
  document.getElementById('discount').addEventListener('input', () => calcTotals(false));
404
 
405
  function updateSaveBtn() {
406
+ const hasItems = invoiceItems.length > 0;
407
  const hasManual = (parseFloat(document.getElementById('subTotal').value) || 0) > 0;
408
  document.getElementById('saveInvoice').disabled = !hasItems && !hasManual;
409
  }
 
435
  document.getElementById('selectedCustomerId').value = el.dataset.id;
436
  customerSearch.value = el.dataset.name;
437
  customerSuggestions.classList.add('d-none');
438
+ document.getElementById('selectedCustomerInfo').textContent = T.customerChosen;
439
  document.getElementById('selectedCustomerInfo').classList.remove('d-none');
440
  });
441
  });
 
448
  document.getElementById('selectedCustomerInfo').classList.add('d-none');
449
  customerSuggestions.classList.add('d-none');
450
  });
 
451
  document.addEventListener('click', e => {
452
  if (!customerSearch.closest('.mb-3').contains(e.target))
453
  customerSuggestions.classList.add('d-none');
 
459
  if (!invoiceItems.length && manualSubTotalVal <= 0) return;
460
  const btn = document.getElementById('saveInvoice');
461
  btn.disabled = true;
462
+ btn.innerHTML = `<span class="spinner-border spinner-border-sm me-2"></span>${T.saving}`;
463
 
464
+ const taxRate = parseFloat(document.getElementById('taxRate').value) || 0;
 
465
  const discount = parseFloat(document.getElementById('discount').value) || 0;
466
 
467
  const payload = {
468
  customerId: document.getElementById('selectedCustomerId').value || null,
469
  invoiceDate: document.getElementById('invoiceDate').value,
470
  paymentMethod: parseInt(document.getElementById('paymentMethod').value),
471
+ taxRate, discount, manualSubTotal: manualSubTotalVal,
 
 
472
  notes: document.getElementById('notes').value,
473
  items: invoiceItems.map(i => ({
474
+ productId: i.productId, productName: i.productName,
475
+ quantity: i.quantity, unitPrice: i.unitPrice,
476
+ purchasePrice: i.purchasePrice, total: i.total
 
 
 
477
  }))
478
  };
479
 
 
490
  if (res.ok) {
491
  window.location.href = `/Invoices/Print/${data.invoiceId}`;
492
  } else {
493
+ showToast(data.message || T.errorOccurred, 'danger');
494
  btn.disabled = false;
495
+ btn.innerHTML = `<i class="bi bi-save2 me-2"></i>${T.saveInvoice}`;
496
  }
497
  } catch {
498
+ showToast(T.connError, 'danger');
499
  btn.disabled = false;
500
+ btn.innerHTML = `<i class="bi bi-save2 me-2"></i>${T.saveInvoice}`;
501
  }
502
  });
503
 
Views/PurchaseReturns/Create.cshtml CHANGED
@@ -1,13 +1,13 @@
1
  @model OilShopManagement.ViewModels.PurchaseReturnCreateViewModel
2
  @{
3
- ViewData["Title"] = "مرتجع شراء جديد";
4
  var purchase = ViewBag.Purchase as OilShopManagement.Models.Purchase;
5
  }
6
 
7
  <div class="d-flex align-items-center justify-content-between mb-3">
8
- <h4 class="fw-bold mb-0"><i class="bi bi-arrow-return-right me-2 text-warning"></i>مرتجع شراء جديد</h4>
9
  <a href="/PurchaseReturns" class="btn btn-outline-secondary rounded-pill btn-sm">
10
- <i class="bi bi-arrow-right me-1"></i>مرتجعات الشراء
11
  </a>
12
  </div>
13
 
@@ -15,8 +15,8 @@
15
  {
16
  <div class="alert alert-info py-2 mb-3">
17
  <i class="bi bi-info-circle me-1"></i>
18
- مرتجع من فاتورة الشراء: <strong>@purchase.PurchaseNumber</strong>
19
- @if (purchase.Supplier != null) { <text> — المورد: <strong>@purchase.Supplier.Name</strong></text> }
20
  </div>
21
  }
22
 
@@ -26,14 +26,14 @@
26
  {
27
  <div class="card mb-3">
28
  <div class="card-header fw-semibold">
29
- <i class="bi bi-receipt me-2 text-warning"></i>ابحث عن فاتورة الشراء الأصلية
30
  </div>
31
  <div class="card-body">
32
  <div class="input-group">
33
  <input type="text" id="purchaseNumberInput" class="form-control"
34
- placeholder="مثال: PUR-20260430-0001" autocomplete="off">
35
  <button class="btn btn-warning" type="button" id="loadPurchaseBtn">
36
- <i class="bi bi-search"></i> جلب الفاتورة
37
  </button>
38
  </div>
39
  <div id="purchaseSearchSuggestions" class="product-suggestions d-none mt-1"></div>
@@ -45,27 +45,28 @@
45
 
46
  <div class="card mb-3">
47
  <div class="card-header"><i class="bi bi-search me-2 text-warning"></i>
48
- @if (purchase != null) { <text>اختر من منتجات الفاتورة</text> } else { <text>بحث يدوي عن منتج</text> }
 
49
  </div>
50
  <div class="card-body">
51
  @if (purchase != null)
52
  {
53
- <p class="small text-muted mb-2">اختر من منتجات الفاتورة:</p>
54
  <div class="d-flex flex-wrap gap-2 mb-3">
55
  @foreach (var item in purchase.Items)
56
  {
57
  <button type="button" class="btn btn-outline-warning btn-sm"
58
  onclick="addFromPurchase(@item.ProductId, '@item.ProductName', @item.UnitPrice, @item.Quantity)">
59
- @item.ProductName (الكمية: @item.Quantity)
60
  </button>
61
  }
62
  </div>
63
  <hr class="my-2">
64
- <p class="small text-muted mb-2">أو ابحث عن منتج آخر:</p>
65
  }
66
  <div class="product-search-box">
67
  <input type="text" id="productSearch" class="form-control"
68
- placeholder="ابحث باسم المنتج..." autocomplete="off">
69
  <div id="productSuggestions" class="product-suggestions d-none"></div>
70
  </div>
71
  </div>
@@ -73,25 +74,25 @@
73
 
74
  <div class="card">
75
  <div class="card-header d-flex align-items-center justify-content-between">
76
- <span><i class="bi bi-list-check me-2"></i>المنتجات المرتجعة</span>
77
- <span class="badge bg-warning text-dark rounded-pill" id="itemCount">0 منتج</span>
78
  </div>
79
  <div class="card-body p-0">
80
  <div class="table-responsive">
81
  <table class="table mb-0">
82
  <thead>
83
  <tr>
84
- <th>المنتج</th>
85
- <th style="width:110px">الكمية</th>
86
- <th style="width:130px">السعر</th>
87
- <th style="width:130px">الإجمالي</th>
88
  <th style="width:50px"></th>
89
  </tr>
90
  </thead>
91
  <tbody id="itemsBody">
92
  <tr>
93
  <td colspan="5" class="text-center text-muted py-4">
94
- <i class="bi bi-inbox fs-2 d-block mb-2"></i>أضف المنتجات المرتجعة
95
  </td>
96
  </tr>
97
  </tbody>
@@ -104,26 +105,27 @@
104
  <div>
105
  <div class="invoice-summary card">
106
  <div class="card-header fw-bold">
107
- <i class="bi bi-arrow-return-right me-2 text-warning"></i>تفاصيل المرتجع
108
  </div>
109
  <div class="card-body">
110
  <div class="mb-3">
111
- <label class="form-label fw-semibold small">تاريخ الإرجاع</label>
112
  <input type="datetime-local" id="returnDate" class="form-control form-control-sm"
113
  value="@DateTime.Now.ToString("yyyy-MM-ddTHH:mm", System.Globalization.CultureInfo.InvariantCulture)">
114
  </div>
115
  <div class="mb-3">
116
- <label class="form-label fw-semibold small">سبب الإرجاع</label>
117
- <textarea id="reason" class="form-control form-control-sm" rows="3" placeholder="اذكر سبب الإرجاع..."></textarea>
 
118
  </div>
119
  <hr>
120
  <div class="d-flex justify-content-between align-items-center mb-3">
121
- <span class="fw-bold fs-5">الإجمالي</span>
122
  <input type="number" id="totalAmount" class="form-control form-control-sm text-end fw-bold"
123
  style="width:140px" min="0" step="0.001" value="0" placeholder="0.000">
124
  </div>
125
  <button type="button" id="saveReturn" class="btn btn-warning w-100 btn-lg rounded-pill" disabled>
126
- <i class="bi bi-save2 me-2"></i>حفظ المرتجع
127
  </button>
128
  </div>
129
  </div>
@@ -132,6 +134,20 @@
132
 
133
  @section Scripts {
134
  <script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  let returnItems = [];
136
  let allProducts = [];
137
  fetch('/Products/GetAllJson').then(r => r.json()).then(d => { allProducts = d; }).catch(() => {});
@@ -139,7 +155,6 @@ fetch('/Products/GetAllJson').then(r => r.json()).then(d => { allProducts = d; }
139
  let purchaseId = @(Model.PurchaseId.HasValue ? Model.PurchaseId.Value.ToString() : "null");
140
  let supplierId = @(Model.SupplierId.HasValue ? Model.SupplierId.Value.ToString() : "null");
141
 
142
- // Purchase invoice search
143
  const purchaseNumberInput = document.getElementById('purchaseNumberInput');
144
  if (purchaseNumberInput) {
145
  let pSearchTimeout;
@@ -184,12 +199,12 @@ async function loadPurchase(number) {
184
  if (!number) return;
185
  const info = document.getElementById('purchaseInfo');
186
  const btns = document.getElementById('purchaseItemsButtons');
187
- info.innerHTML = '<span class="spinner-border spinner-border-sm me-1"></span>جاري البحث...';
188
  info.classList.remove('d-none');
189
  btns.innerHTML = '';
190
  try {
191
  const res = await fetch(`/Purchases/GetByNumber?number=${encodeURIComponent(number)}`);
192
- if (!res.ok) { info.innerHTML = '<span class="text-danger">الفاتورة غير موجودة</span>'; return; }
193
  const pur = await res.json();
194
  purchaseId = pur.id;
195
  if (pur.supplierId) supplierId = pur.supplierId;
@@ -197,16 +212,16 @@ async function loadPurchase(number) {
197
  <strong>${pur.purchaseNumber}</strong>
198
  ${pur.supplierName ? ' — ' + pur.supplierName : ''}
199
  — ${pur.purchaseDate}
200
- — <span class="text-warning fw-bold">${parseFloat(pur.totalAmount).toFixed(3)} ر.ع.</span>
201
  </div>`;
202
- btns.innerHTML = '<p class="small text-muted mb-2 w-100">اضغط على منتج لإضافته:</p>' +
203
  pur.items.map(i => `
204
  <button type="button" class="btn btn-outline-warning btn-sm"
205
  onclick="addItem(${i.productId}, '${i.productName.replace(/'/g,"\\'")}', ${i.unitPrice}, ${i.quantity})">
206
  <i class="bi bi-plus-circle me-1"></i>${i.productName}
207
  <span class="badge bg-warning text-dark ms-1">${i.quantity}</span>
208
  </button>`).join('');
209
- } catch { info.innerHTML = '<span class="text-danger">خطأ في الاتصال</span>'; }
210
  }
211
 
212
  const productSearch = document.getElementById('productSearch');
@@ -222,7 +237,7 @@ productSearch.addEventListener('input', () => {
222
  productSuggestions.innerHTML = filtered.map(p => `
223
  <div class="suggestion-item" data-id="${p.id}" data-name="${p.name}" data-price="${p.purchasePrice}">
224
  <div class="fw-semibold small">${p.name}</div>
225
- <small class="text-muted">مخزون: ${p.currentStock}</small>
226
  </div>
227
  `).join('');
228
  productSuggestions.classList.remove('d-none');
@@ -249,8 +264,8 @@ function addItem(id, name, price, maxQty) {
249
  function renderItems() {
250
  const tbody = document.getElementById('itemsBody');
251
  if (!returnItems.length) {
252
- tbody.innerHTML = `<tr><td colspan="5" class="text-center text-muted py-4"><i class="bi bi-inbox fs-2 d-block mb-2"></i>أضف المنتجات المرتجعة</td></tr>`;
253
- document.getElementById('itemCount').textContent = '0 منتج';
254
  document.getElementById('saveReturn').disabled = true;
255
  return;
256
  }
@@ -273,7 +288,7 @@ function renderItems() {
273
  <td><button class="btn btn-sm btn-outline-danger" onclick="removeItem(${idx})"><i class="bi bi-trash3"></i></button></td>
274
  </tr>
275
  `).join('');
276
- document.getElementById('itemCount').textContent = `${returnItems.length} منتج`;
277
  document.getElementById('saveReturn').disabled = false;
278
  }
279
 
@@ -306,7 +321,7 @@ function calcTotal(fromItems = false) {
306
  }
307
 
308
  function updateSaveBtn() {
309
- const hasItems = returnItems.length > 0;
310
  const hasManual = (parseFloat(document.getElementById('totalAmount').value) || 0) > 0;
311
  document.getElementById('saveReturn').disabled = !hasItems && !hasManual;
312
  }
@@ -318,7 +333,7 @@ document.getElementById('saveReturn').addEventListener('click', async () => {
318
  if (!returnItems.length && manualTotal <= 0) return;
319
  const btn = document.getElementById('saveReturn');
320
  btn.disabled = true;
321
- btn.innerHTML = '<span class="spinner-border spinner-border-sm me-2"></span>جاري الحفظ...';
322
  const payload = {
323
  purchaseId, supplierId,
324
  returnDate: document.getElementById('returnDate').value,
@@ -335,14 +350,14 @@ document.getElementById('saveReturn').addEventListener('click', async () => {
335
  const data = await res.json();
336
  if (res.ok) { window.location.href = `/PurchaseReturns/Details/${data.returnId}`; }
337
  else {
338
- showToast(data.message || 'حدث خطأ', 'danger');
339
  btn.disabled = false;
340
- btn.innerHTML = '<i class="bi bi-save2 me-2"></i>حفظ المرتجع';
341
  }
342
  } catch {
343
- showToast('خطأ في الاتصال', 'danger');
344
  btn.disabled = false;
345
- btn.innerHTML = '<i class="bi bi-save2 me-2"></i>حفظ المرتجع';
346
  }
347
  });
348
 
 
1
  @model OilShopManagement.ViewModels.PurchaseReturnCreateViewModel
2
  @{
3
+ ViewData["Title"] = L.T("مرتجع شراء جديد","New Purchase Return");
4
  var purchase = ViewBag.Purchase as OilShopManagement.Models.Purchase;
5
  }
6
 
7
  <div class="d-flex align-items-center justify-content-between mb-3">
8
+ <h4 class="fw-bold mb-0"><i class="bi bi-arrow-return-right me-2 text-warning"></i>@L.T("مرتجع شراء جديد","New Purchase Return")</h4>
9
  <a href="/PurchaseReturns" class="btn btn-outline-secondary rounded-pill btn-sm">
10
+ <i class="bi bi-arrow-right me-1"></i>@L.T("مرتجعات الشراء","Purchase Returns")
11
  </a>
12
  </div>
13
 
 
15
  {
16
  <div class="alert alert-info py-2 mb-3">
17
  <i class="bi bi-info-circle me-1"></i>
18
+ @L.T("مرتجع من فاتورة الشراء:","Return from purchase invoice:") <strong>@purchase.PurchaseNumber</strong>
19
+ @if (purchase.Supplier != null) { <text> — @L.T("المورد:","Supplier:") <strong>@purchase.Supplier.Name</strong></text> }
20
  </div>
21
  }
22
 
 
26
  {
27
  <div class="card mb-3">
28
  <div class="card-header fw-semibold">
29
+ <i class="bi bi-receipt me-2 text-warning"></i>@L.T("ابحث عن فاتورة الشراء الأصلية","Search for original purchase invoice")
30
  </div>
31
  <div class="card-body">
32
  <div class="input-group">
33
  <input type="text" id="purchaseNumberInput" class="form-control"
34
+ placeholder="@L.T("مثال: PUR-20260430-0001","e.g. PUR-20260430-0001")" autocomplete="off">
35
  <button class="btn btn-warning" type="button" id="loadPurchaseBtn">
36
+ <i class="bi bi-search"></i> @L.T("جلب الفاتورة","Load Invoice")
37
  </button>
38
  </div>
39
  <div id="purchaseSearchSuggestions" class="product-suggestions d-none mt-1"></div>
 
45
 
46
  <div class="card mb-3">
47
  <div class="card-header"><i class="bi bi-search me-2 text-warning"></i>
48
+ @if (purchase != null) { @L.T("اختر من منتجات الفاتورة","Select from invoice products") }
49
+ else { @L.T("بحث يدوي عن منتج","Manual product search") }
50
  </div>
51
  <div class="card-body">
52
  @if (purchase != null)
53
  {
54
+ <p class="small text-muted mb-2">@L.T("اختر من منتجات الفاتورة:","Select from invoice products:")</p>
55
  <div class="d-flex flex-wrap gap-2 mb-3">
56
  @foreach (var item in purchase.Items)
57
  {
58
  <button type="button" class="btn btn-outline-warning btn-sm"
59
  onclick="addFromPurchase(@item.ProductId, '@item.ProductName', @item.UnitPrice, @item.Quantity)">
60
+ @item.ProductName (@L.T("الكمية:","Qty:") @item.Quantity)
61
  </button>
62
  }
63
  </div>
64
  <hr class="my-2">
65
+ <p class="small text-muted mb-2">@L.T("أو ابحث عن منتج آخر:","Or search for another product:")</p>
66
  }
67
  <div class="product-search-box">
68
  <input type="text" id="productSearch" class="form-control"
69
+ placeholder="@L.T("ابحث باسم المنتج...","Search by product name...")" autocomplete="off">
70
  <div id="productSuggestions" class="product-suggestions d-none"></div>
71
  </div>
72
  </div>
 
74
 
75
  <div class="card">
76
  <div class="card-header d-flex align-items-center justify-content-between">
77
+ <span><i class="bi bi-list-check me-2"></i>@L.T("المنتجات المرتجعة","Returned Products")</span>
78
+ <span class="badge bg-warning text-dark rounded-pill" id="itemCount">0</span>
79
  </div>
80
  <div class="card-body p-0">
81
  <div class="table-responsive">
82
  <table class="table mb-0">
83
  <thead>
84
  <tr>
85
+ <th>@L.T("المنتج","Product")</th>
86
+ <th style="width:110px">@L.T("الكمية","Qty")</th>
87
+ <th style="width:130px">@L.T("السعر","Price")</th>
88
+ <th style="width:130px">@L.T("الإجمالي","Total")</th>
89
  <th style="width:50px"></th>
90
  </tr>
91
  </thead>
92
  <tbody id="itemsBody">
93
  <tr>
94
  <td colspan="5" class="text-center text-muted py-4">
95
+ <i class="bi bi-inbox fs-2 d-block mb-2"></i>@L.T("أضف المنتجات المرتجعة","Add returned products")
96
  </td>
97
  </tr>
98
  </tbody>
 
105
  <div>
106
  <div class="invoice-summary card">
107
  <div class="card-header fw-bold">
108
+ <i class="bi bi-arrow-return-right me-2 text-warning"></i>@L.T("تفاصيل المرتجع","Return Details")
109
  </div>
110
  <div class="card-body">
111
  <div class="mb-3">
112
+ <label class="form-label fw-semibold small">@L.T("تاريخ الإرجاع","Return Date")</label>
113
  <input type="datetime-local" id="returnDate" class="form-control form-control-sm"
114
  value="@DateTime.Now.ToString("yyyy-MM-ddTHH:mm", System.Globalization.CultureInfo.InvariantCulture)">
115
  </div>
116
  <div class="mb-3">
117
+ <label class="form-label fw-semibold small">@L.T("سبب الإرجاع","Return Reason")</label>
118
+ <textarea id="reason" class="form-control form-control-sm" rows="3"
119
+ placeholder="@L.T("اذكر سبب الإرجاع...","Enter the return reason...")"></textarea>
120
  </div>
121
  <hr>
122
  <div class="d-flex justify-content-between align-items-center mb-3">
123
+ <span class="fw-bold fs-5">@L.T("الإجمالي","Total")</span>
124
  <input type="number" id="totalAmount" class="form-control form-control-sm text-end fw-bold"
125
  style="width:140px" min="0" step="0.001" value="0" placeholder="0.000">
126
  </div>
127
  <button type="button" id="saveReturn" class="btn btn-warning w-100 btn-lg rounded-pill" disabled>
128
+ <i class="bi bi-save2 me-2"></i>@L.T("حفظ المرتجع","Save Return")
129
  </button>
130
  </div>
131
  </div>
 
134
 
135
  @section Scripts {
136
  <script>
137
+ const T = {
138
+ addItems: '@L.T("أضف المنتجات المرتجعة","Add returned products")',
139
+ saving: '@L.T("جاري الحفظ...","Saving...")',
140
+ saveReturn: '@L.T("حفظ المرتجع","Save Return")',
141
+ searching: '@L.T("جاري البحث...","Searching...")',
142
+ notFound: '@L.T("الفاتورة غير موجودة","Invoice not found")',
143
+ connError: '@L.T("خطأ في الاتصال","Connection error")',
144
+ errorOccurred: '@L.T("حدث خطأ","An error occurred")',
145
+ stock: '@L.T("مخزون","Stock")',
146
+ clickToAdd: '@L.T("اضغط على منتج لإضافته:","Click a product to add:")',
147
+ omr: '@L.T("ر.ع.","OMR")',
148
+ itemWord: '@L.T("منتج","item")',
149
+ };
150
+
151
  let returnItems = [];
152
  let allProducts = [];
153
  fetch('/Products/GetAllJson').then(r => r.json()).then(d => { allProducts = d; }).catch(() => {});
 
155
  let purchaseId = @(Model.PurchaseId.HasValue ? Model.PurchaseId.Value.ToString() : "null");
156
  let supplierId = @(Model.SupplierId.HasValue ? Model.SupplierId.Value.ToString() : "null");
157
 
 
158
  const purchaseNumberInput = document.getElementById('purchaseNumberInput');
159
  if (purchaseNumberInput) {
160
  let pSearchTimeout;
 
199
  if (!number) return;
200
  const info = document.getElementById('purchaseInfo');
201
  const btns = document.getElementById('purchaseItemsButtons');
202
+ info.innerHTML = `<span class="spinner-border spinner-border-sm me-1"></span>${T.searching}`;
203
  info.classList.remove('d-none');
204
  btns.innerHTML = '';
205
  try {
206
  const res = await fetch(`/Purchases/GetByNumber?number=${encodeURIComponent(number)}`);
207
+ if (!res.ok) { info.innerHTML = `<span class="text-danger">${T.notFound}</span>`; return; }
208
  const pur = await res.json();
209
  purchaseId = pur.id;
210
  if (pur.supplierId) supplierId = pur.supplierId;
 
212
  <strong>${pur.purchaseNumber}</strong>
213
  ${pur.supplierName ? ' — ' + pur.supplierName : ''}
214
  — ${pur.purchaseDate}
215
+ — <span class="text-warning fw-bold">${parseFloat(pur.totalAmount).toFixed(3)} ${T.omr}</span>
216
  </div>`;
217
+ btns.innerHTML = `<p class="small text-muted mb-2 w-100">${T.clickToAdd}</p>` +
218
  pur.items.map(i => `
219
  <button type="button" class="btn btn-outline-warning btn-sm"
220
  onclick="addItem(${i.productId}, '${i.productName.replace(/'/g,"\\'")}', ${i.unitPrice}, ${i.quantity})">
221
  <i class="bi bi-plus-circle me-1"></i>${i.productName}
222
  <span class="badge bg-warning text-dark ms-1">${i.quantity}</span>
223
  </button>`).join('');
224
+ } catch { info.innerHTML = `<span class="text-danger">${T.connError}</span>`; }
225
  }
226
 
227
  const productSearch = document.getElementById('productSearch');
 
237
  productSuggestions.innerHTML = filtered.map(p => `
238
  <div class="suggestion-item" data-id="${p.id}" data-name="${p.name}" data-price="${p.purchasePrice}">
239
  <div class="fw-semibold small">${p.name}</div>
240
+ <small class="text-muted">${T.stock}: ${p.currentStock}</small>
241
  </div>
242
  `).join('');
243
  productSuggestions.classList.remove('d-none');
 
264
  function renderItems() {
265
  const tbody = document.getElementById('itemsBody');
266
  if (!returnItems.length) {
267
+ tbody.innerHTML = `<tr><td colspan="5" class="text-center text-muted py-4"><i class="bi bi-inbox fs-2 d-block mb-2"></i>${T.addItems}</td></tr>`;
268
+ document.getElementById('itemCount').textContent = '0';
269
  document.getElementById('saveReturn').disabled = true;
270
  return;
271
  }
 
288
  <td><button class="btn btn-sm btn-outline-danger" onclick="removeItem(${idx})"><i class="bi bi-trash3"></i></button></td>
289
  </tr>
290
  `).join('');
291
+ document.getElementById('itemCount').textContent = returnItems.length;
292
  document.getElementById('saveReturn').disabled = false;
293
  }
294
 
 
321
  }
322
 
323
  function updateSaveBtn() {
324
+ const hasItems = returnItems.length > 0;
325
  const hasManual = (parseFloat(document.getElementById('totalAmount').value) || 0) > 0;
326
  document.getElementById('saveReturn').disabled = !hasItems && !hasManual;
327
  }
 
333
  if (!returnItems.length && manualTotal <= 0) return;
334
  const btn = document.getElementById('saveReturn');
335
  btn.disabled = true;
336
+ btn.innerHTML = `<span class="spinner-border spinner-border-sm me-2"></span>${T.saving}`;
337
  const payload = {
338
  purchaseId, supplierId,
339
  returnDate: document.getElementById('returnDate').value,
 
350
  const data = await res.json();
351
  if (res.ok) { window.location.href = `/PurchaseReturns/Details/${data.returnId}`; }
352
  else {
353
+ showToast(data.message || T.errorOccurred, 'danger');
354
  btn.disabled = false;
355
+ btn.innerHTML = `<i class="bi bi-save2 me-2"></i>${T.saveReturn}`;
356
  }
357
  } catch {
358
+ showToast(T.connError, 'danger');
359
  btn.disabled = false;
360
+ btn.innerHTML = `<i class="bi bi-save2 me-2"></i>${T.saveReturn}`;
361
  }
362
  });
363
 
Views/PurchaseReturns/Index.cshtml CHANGED
@@ -1,12 +1,12 @@
1
  @model IEnumerable<OilShopManagement.Models.PurchaseReturn>
2
  @{
3
- ViewData["Title"] = "مرتجعات الشراء";
4
  }
5
 
6
  <div class="d-flex align-items-center justify-content-between mb-3">
7
- <h4 class="fw-bold mb-0"><i class="bi bi-arrow-return-right me-2 text-warning"></i>مرتجعات الشراء</h4>
8
  <a href="/PurchaseReturns/Create" class="btn btn-warning rounded-pill btn-sm">
9
- <i class="bi bi-plus-lg me-1"></i>مرتجع جديد
10
  </a>
11
  </div>
12
 
@@ -14,10 +14,10 @@
14
  <div class="card-body py-2">
15
  <form method="get" class="d-flex gap-2 flex-wrap align-items-center">
16
  <input type="date" name="from" value="@ViewBag.From" class="form-control form-control-sm" style="max-width:145px">
17
- <span class="text-muted small">إلى</span>
18
  <input type="date" name="to" value="@ViewBag.To" class="form-control form-control-sm" style="max-width:145px">
19
- <button class="btn btn-outline-warning btn-sm px-3">بحث</button>
20
- <a href="/PurchaseReturns" class="btn btn-outline-secondary btn-sm">إعادة تعيين</a>
21
  </form>
22
  </div>
23
  </div>
@@ -28,12 +28,12 @@
28
  <table class="table table-hover mb-0">
29
  <thead>
30
  <tr>
31
- <th>رقم المرتجع</th>
32
- <th>فاتورة الشراء</th>
33
- <th>المورد</th>
34
- <th>التاريخ</th>
35
- <th>الإجمالي</th>
36
- <th>السبب</th>
37
  <th style="width:60px"></th>
38
  </tr>
39
  </thead>
@@ -45,7 +45,7 @@
45
  <td>@(r.Purchase?.PurchaseNumber ?? "—")</td>
46
  <td>@(r.Supplier?.Name ?? "—")</td>
47
  <td>@r.ReturnDate.ToString("yyyy/MM/dd")</td>
48
- <td class="fw-semibold text-warning">@r.TotalAmount.ToString("N3") ر.ع.</td>
49
  <td class="text-muted small">@(r.Reason ?? "—")</td>
50
  <td>
51
  <a href="/PurchaseReturns/Details/@r.Id" class="btn btn-sm btn-outline-secondary">
@@ -58,7 +58,7 @@
58
  {
59
  <tr>
60
  <td colspan="7" class="text-center text-muted py-5">
61
- <i class="bi bi-inbox fs-2 d-block mb-2"></i>لا توجد مرتجعات شراء
62
  </td>
63
  </tr>
64
  }
 
1
  @model IEnumerable<OilShopManagement.Models.PurchaseReturn>
2
  @{
3
+ ViewData["Title"] = L.T("مرتجعات الشراء","Purchase Returns");
4
  }
5
 
6
  <div class="d-flex align-items-center justify-content-between mb-3">
7
+ <h4 class="fw-bold mb-0"><i class="bi bi-arrow-return-right me-2 text-warning"></i>@L.T("مرتجعات الشراء","Purchase Returns")</h4>
8
  <a href="/PurchaseReturns/Create" class="btn btn-warning rounded-pill btn-sm">
9
+ <i class="bi bi-plus-lg me-1"></i>@L.T("مرتجع جديد","New Return")
10
  </a>
11
  </div>
12
 
 
14
  <div class="card-body py-2">
15
  <form method="get" class="d-flex gap-2 flex-wrap align-items-center">
16
  <input type="date" name="from" value="@ViewBag.From" class="form-control form-control-sm" style="max-width:145px">
17
+ <span class="text-muted small">@L.T("إلى","to")</span>
18
  <input type="date" name="to" value="@ViewBag.To" class="form-control form-control-sm" style="max-width:145px">
19
+ <button class="btn btn-outline-warning btn-sm px-3">@L.T("بحث","Search")</button>
20
+ <a href="/PurchaseReturns" class="btn btn-outline-secondary btn-sm">@L.T("إعادة تعيين","Reset")</a>
21
  </form>
22
  </div>
23
  </div>
 
28
  <table class="table table-hover mb-0">
29
  <thead>
30
  <tr>
31
+ <th>@L.T("رقم المرتجع","Return #")</th>
32
+ <th>@L.T("فاتورة الشراء","Purchase Invoice")</th>
33
+ <th>@L.T("المورد","Supplier")</th>
34
+ <th>@L.T("التاريخ","Date")</th>
35
+ <th>@L.T("الإجمالي","Total")</th>
36
+ <th>@L.T("السبب","Reason")</th>
37
  <th style="width:60px"></th>
38
  </tr>
39
  </thead>
 
45
  <td>@(r.Purchase?.PurchaseNumber ?? "—")</td>
46
  <td>@(r.Supplier?.Name ?? "—")</td>
47
  <td>@r.ReturnDate.ToString("yyyy/MM/dd")</td>
48
+ <td class="fw-semibold text-warning">@r.TotalAmount.ToString("N3") @L.T("ر.ع.","OMR")</td>
49
  <td class="text-muted small">@(r.Reason ?? "—")</td>
50
  <td>
51
  <a href="/PurchaseReturns/Details/@r.Id" class="btn btn-sm btn-outline-secondary">
 
58
  {
59
  <tr>
60
  <td colspan="7" class="text-center text-muted py-5">
61
+ <i class="bi bi-inbox fs-2 d-block mb-2"></i>@L.T("لا توجد مرتجعات شراء","No purchase returns found")
62
  </td>
63
  </tr>
64
  }
Views/Purchases/Create.cshtml CHANGED
@@ -1,6 +1,6 @@
1
  @model OilShopManagement.ViewModels.PurchaseCreateViewModel
2
  @{
3
- ViewData["Title"] = "فاتورة شراء جديدة";
4
  }
5
 
6
  <style>
@@ -18,9 +18,9 @@
18
  </style>
19
 
20
  <div class="d-flex align-items-center justify-content-between mb-3">
21
- <h4 class="fw-bold mb-0"><i class="bi bi-cart-plus me-2 text-success"></i>فاتورة شراء جديدة</h4>
22
  <a href="/Purchases" class="btn btn-outline-secondary rounded-pill btn-sm">
23
- <i class="bi bi-arrow-right me-1"></i>فواتير الشراء
24
  </a>
25
  </div>
26
 
@@ -30,10 +30,10 @@
30
  <!-- Products Browser -->
31
  <div class="card mb-3">
32
  <div class="card-header d-flex align-items-center justify-content-between py-2">
33
- <span><i class="bi bi-grid me-2 text-success"></i>اختر المنتجات</span>
34
  <div class="d-flex align-items-center gap-2">
35
  <input type="text" id="prodFilter" class="form-control form-control-sm"
36
- style="width:160px" placeholder="فلتر..." oninput="filterProducts(this.value)">
37
  <span class="badge bg-secondary rounded-pill" id="prodCount">...</span>
38
  </div>
39
  </div>
@@ -45,19 +45,19 @@
45
  <!-- Selected Items Table -->
46
  <div class="card">
47
  <div class="card-header d-flex align-items-center justify-content-between">
48
- <span><i class="bi bi-list-check me-2"></i>المنتجات المختارة</span>
49
- <span class="badge bg-success rounded-pill" id="itemCount">0 منتج</span>
50
  </div>
51
  <div class="card-body p-0">
52
  <div class="table-responsive">
53
  <table class="table mb-0" id="itemsTable">
54
  <thead>
55
  <tr>
56
- <th>المنتج</th>
57
- <th style="width:110px">المخزون</th>
58
- <th style="width:140px">الكمية (حبة)</th>
59
- <th style="width:150px">سعر الحبة</th>
60
- <th style="width:120px">الإجمالي</th>
61
  <th style="width:40px"></th>
62
  </tr>
63
  </thead>
@@ -65,7 +65,7 @@
65
  <tr id="emptyRow">
66
  <td colspan="6" class="text-center text-muted py-4">
67
  <i class="bi bi-hand-index-thumb fs-2 d-block mb-1"></i>
68
- اضغط على منتج من الأعلى لإضافته
69
  </td>
70
  </tr>
71
  </tbody>
@@ -79,14 +79,15 @@
79
  <div>
80
  <div class="invoice-summary card">
81
  <div class="card-header fw-bold">
82
- <i class="bi bi-receipt me-2 text-success"></i>ملخص فاتورة الشراء
83
  </div>
84
  <div class="card-body">
85
  <!-- Supplier -->
86
  <div class="mb-3">
87
- <label class="form-label fw-semibold small">المورد (اختياري)</label>
88
  <div class="input-group">
89
- <input type="text" id="supplierSearch" class="form-control form-control-sm" placeholder="ابحث عن المورد...">
 
90
  <button class="btn btn-outline-secondary btn-sm" type="button" id="clearSupplier">
91
  <i class="bi bi-x"></i>
92
  </button>
@@ -97,50 +98,51 @@
97
  </div>
98
 
99
  <div class="mb-3">
100
- <label class="form-label fw-semibold small">تاريخ الشراء</label>
101
  <input type="datetime-local" id="purchaseDate" class="form-control form-control-sm"
102
  value="@DateTime.Now.ToString("yyyy-MM-ddTHH:mm", System.Globalization.CultureInfo.InvariantCulture)">
103
  </div>
104
  <div class="mb-3">
105
- <label class="form-label fw-semibold small">طريقة الدفع</label>
106
  <select id="paymentMethod" class="form-select form-select-sm">
107
- <option value="0">نقداً</option>
108
- <option value="1">بطاقة</option>
109
- <option value="2">تحويل</option>
110
  </select>
111
  </div>
112
 
113
  <hr>
114
  <div class="d-flex justify-content-between align-items-center mb-2">
115
- <span class="text-muted">الإجمالي قبل الضريبة</span>
116
  <input type="number" id="subTotal" class="form-control form-control-sm text-end fw-semibold"
117
  style="width:120px" min="0" step="0.001" value="0" placeholder="0.000">
118
  </div>
119
  <div class="d-flex justify-content-between align-items-center mb-2">
120
- <span class="text-muted">الضريبة
121
  <input type="number" id="taxRate" value="0" min="0" max="100"
122
  class="form-control form-control-sm d-inline-block ms-1" style="width:55px">%
123
  </span>
124
  <span id="taxAmount" class="fw-semibold">0.000</span>
125
  </div>
126
  <div class="d-flex justify-content-between align-items-center mb-3">
127
- <span class="text-muted">خصم (ر.ع.)</span>
128
  <input type="number" id="discount" value="0" min="0"
129
  class="form-control form-control-sm text-end" style="width:100px">
130
  </div>
131
  <hr>
132
  <div class="d-flex justify-content-between mb-3">
133
- <span class="fw-bold fs-5">الإجمالي النهائي</span>
134
- <span id="totalAmount" class="fw-bold fs-5 text-success">0.000 ر.ع.</span>
135
  </div>
136
 
137
  <div class="mb-3">
138
- <label class="form-label fw-semibold small">ملاحظات</label>
139
- <textarea id="notes" class="form-control form-control-sm" rows="2" placeholder="ملاحظات..."></textarea>
 
140
  </div>
141
 
142
  <button type="button" id="savePurchase" class="btn btn-success w-100 btn-lg rounded-pill" disabled>
143
- <i class="bi bi-save2 me-2"></i>حفظ فاتورة الشراء
144
  </button>
145
  </div>
146
  </div>
@@ -149,6 +151,20 @@
149
 
150
  @section Scripts {
151
  <script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
  let purchaseItems = [];
153
  let allProducts = [];
154
  let filteredProducts = [];
@@ -159,19 +175,18 @@ fetch('/Products/GetAllJson').then(r => r.json()).then(d => {
159
  renderProdGrid(d);
160
  }).catch(() => {});
161
 
162
- /* ── Product Grid ── */
163
  function renderProdGrid(products) {
164
- document.getElementById('prodCount').textContent = products.length + ' منتج';
165
  const grid = document.getElementById('prodGrid');
166
  if (!products.length) {
167
- grid.innerHTML = '<div class="text-muted small p-2">لا توجد منتجات</div>';
168
  return;
169
  }
170
  grid.innerHTML = products.map((p, idx) => {
171
  const inCart = purchaseItems.some(i => i.productId === p.id);
172
  const isCarton = (p.unit === 'كرتون' || p.unit === 'Carton') && p.piecesPerUnit > 0;
173
  const stockLabel = isCarton
174
- ? `${p.currentStock} كرتون (${p.currentStock * p.piecesPerUnit} حبة)`
175
  : `${p.currentStock} ${p.unit}`;
176
  const stockClass = p.currentStock <= 0 ? 'bg-danger' : (p.currentStock <= p.minStockLevel ? 'bg-warning text-dark' : 'bg-secondary');
177
  return `<div class="prod-card ${inCart ? 'in-cart' : ''}" onclick="toggleProduct(${idx})" title="${p.name}">
@@ -181,7 +196,7 @@ function renderProdGrid(products) {
181
  <span class="badge ${stockClass} rounded-pill" style="font-size:.65rem">${stockLabel}</span>
182
  ${inCart ? '<i class="bi bi-check-circle-fill text-success" style="font-size:.85rem"></i>' : ''}
183
  </div>
184
- <div class="text-success fw-semibold mt-1" style="font-size:.75rem">${parseFloat(p.purchasePrice).toFixed(3)} ر.ع.</div>
185
  </div>`;
186
  }).join('');
187
  }
@@ -198,59 +213,48 @@ function toggleProduct(idx) {
198
  if (!p) return;
199
  const existing = purchaseItems.find(i => i.productId === p.id);
200
  if (existing) {
201
- // Already in cart — scroll to its row and focus qty
202
  const row = document.querySelector(`tr[data-pid="${p.id}"]`);
203
  if (row) { row.scrollIntoView({ behavior: 'smooth', block: 'center' }); row.classList.add('table-success'); setTimeout(() => row.classList.remove('table-success'), 1200); }
204
  } else {
205
  const isCarton = (p.unit === 'كرتون' || p.unit === 'Carton') && p.piecesPerUnit > 0;
206
- const initQty = isCarton ? (p.piecesPerUnit || 1) : 1; // default = 1 carton worth of pieces
207
  const piecePrice = p.purchasePrice || 0;
208
  purchaseItems.push({
209
- productId: p.id,
210
- productName: p.name,
211
- quantity: initQty,
212
- unitPrice: piecePrice,
213
  total: piecePrice * initQty,
214
- unit: p.unit,
215
- currentStock: p.currentStock,
216
- isCarton,
217
- piecesPerUnit: p.piecesPerUnit || 0
218
  });
219
- renderItems();
220
- calcTotals(true);
221
- // Scroll to items table
222
  document.getElementById('itemsTable').scrollIntoView({ behavior: 'smooth', block: 'nearest' });
223
  }
224
  renderProdGrid(filteredProducts);
225
  }
226
 
227
- /* ── Items Table ── */
228
  function renderItems() {
229
  const tbody = document.getElementById('itemsBody');
230
  if (!purchaseItems.length) {
231
  tbody.innerHTML = `<tr id="emptyRow"><td colspan="6" class="text-center text-muted py-4">
232
- <i class="bi bi-hand-index-thumb fs-2 d-block mb-1"></i>اضغط على منتج من الأعلى لإضافته</td></tr>`;
233
- document.getElementById('itemCount').textContent = '0 منتج';
234
  document.getElementById('savePurchase').disabled = true;
235
  return;
236
  }
237
  tbody.innerHTML = purchaseItems.map((item, idx) => {
238
  const ppu = item.piecesPerUnit || 0;
239
- // Stock display
240
  const stockPieces = item.isCarton ? item.currentStock * ppu : item.currentStock;
241
- const stockLabel = item.isCarton ? `${stockPieces} حبة` : `${item.currentStock} ${item.unit}`;
242
- // After purchase
243
  const addedCartons = item.isCarton ? Math.ceil(item.quantity / ppu) : item.quantity;
244
  const afterCartons = item.currentStock + addedCartons;
245
  const afterPieces = item.isCarton ? afterCartons * ppu : afterCartons;
246
- const afterLabel = item.isCarton ? `${afterPieces} حبة (${afterCartons} كرتون)` : `${afterCartons} ${item.unit}`;
247
- // Carton equivalence note
248
- const cartonNote = item.isCarton ? `<div style="font-size:.65rem;color:#0891b2">${Math.ceil(item.quantity/ppu)} كرتون</div>` : '';
249
 
250
  return `<tr data-pid="${item.productId}">
251
  <td>
252
  <div class="fw-semibold small">${item.productName}</div>
253
- <small class="text-muted">${item.isCarton ? `كرتون · ${ppu} حبة/كرتون` : item.unit}</small>
254
  </td>
255
  <td class="text-center small">
256
  <div class="text-muted">${stockLabel}</div>
@@ -263,18 +267,18 @@ function renderItems() {
263
  onchange="setQty(${idx},this.value)" style="width:54px">
264
  <button class="btn btn-outline-secondary" onclick="changeQty(${idx},1)">+</button>
265
  </div>
266
- ${item.isCarton ? `<div class="text-center mt-1" style="font-size:.65rem;color:#64748b">حبة ${cartonNote}</div>` : ''}
267
  </td>
268
  <td>
269
  <div class="input-group input-group-sm">
270
  <input type="number" class="form-control text-end" value="${item.unitPrice.toFixed(3)}"
271
  min="0" step="0.001" onchange="setPrice(${idx},this.value)" style="width:90px">
272
- <span class="input-group-text" style="font-size:.65rem">${item.isCarton ? 'ر.ع./حبة' : 'ر.ع.'}</span>
273
  </div>
274
  </td>
275
  <td class="fw-semibold text-success">
276
  ${item.total.toFixed(3)}
277
- ${item.isCarton ? `<div style="font-size:.65rem;color:#64748b">${item.quantity} حبة</div>` : ''}
278
  </td>
279
  <td>
280
  <button class="btn btn-sm btn-outline-danger" onclick="removeItem(${idx})">
@@ -283,7 +287,7 @@ function renderItems() {
283
  </td>
284
  </tr>`;
285
  }).join('');
286
- document.getElementById('itemCount').textContent = `${purchaseItems.length} منتج`;
287
  document.getElementById('savePurchase').disabled = false;
288
  }
289
 
@@ -311,7 +315,6 @@ function removeItem(idx) {
311
  renderProdGrid(filteredProducts);
312
  }
313
 
314
- /* ── Totals ── */
315
  function calcTotals(fromItems = false) {
316
  if (fromItems) {
317
  const computed = purchaseItems.reduce((s, i) => s + i.total, 0);
@@ -322,8 +325,8 @@ function calcTotals(fromItems = false) {
322
  const discount = parseFloat(document.getElementById('discount').value) || 0;
323
  const taxAmount = subTotal * (taxRate / 100);
324
  const total = subTotal + taxAmount - discount;
325
- document.getElementById('taxAmount').textContent = taxAmount.toFixed(3) + ' ر.ع.';
326
- document.getElementById('totalAmount').textContent = total.toFixed(3) + ' ر.ع.';
327
  }
328
 
329
  document.getElementById('subTotal').addEventListener('input', () => { calcTotals(false); updateSaveBtn(); });
@@ -336,7 +339,7 @@ function updateSaveBtn() {
336
  document.getElementById('savePurchase').disabled = !hasItems && !hasManual;
337
  }
338
 
339
- /* ── Supplier Search ── */
340
  const supplierSearch = document.getElementById('supplierSearch');
341
  const supplierSuggestions = document.getElementById('supplierSuggestions');
342
  let supplierTimeout;
@@ -360,7 +363,7 @@ supplierSearch.addEventListener('input', () => {
360
  document.getElementById('selectedSupplierId').value = el.dataset.id;
361
  supplierSearch.value = el.dataset.name;
362
  supplierSuggestions.classList.add('d-none');
363
- document.getElementById('selectedSupplierInfo').textContent = '✓ تم اختيار المورد';
364
  document.getElementById('selectedSupplierInfo').classList.remove('d-none');
365
  });
366
  });
@@ -376,13 +379,13 @@ document.addEventListener('click', e => {
376
  if (!supplierSearch.closest('.mb-3').contains(e.target)) supplierSuggestions.classList.add('d-none');
377
  });
378
 
379
- /* ── Save ── */
380
  document.getElementById('savePurchase').addEventListener('click', async () => {
381
  const manualSubTotal = parseFloat(document.getElementById('subTotal').value) || 0;
382
  if (!purchaseItems.length && manualSubTotal <= 0) return;
383
  const btn = document.getElementById('savePurchase');
384
  btn.disabled = true;
385
- btn.innerHTML = '<span class="spinner-border spinner-border-sm me-2"></span>جاري الحفظ...';
386
  const taxRate = parseFloat(document.getElementById('taxRate').value) || 0;
387
  const discount = parseFloat(document.getElementById('discount').value) || 0;
388
 
@@ -393,12 +396,9 @@ document.getElementById('savePurchase').addEventListener('click', async () => {
393
  taxRate, discount, manualSubTotal,
394
  notes: document.getElementById('notes').value,
395
  items: purchaseItems.map(i => ({
396
- productId: i.productId,
397
- productName: i.productName,
398
- quantity: i.quantity,
399
- unitPrice: i.unitPrice,
400
- total: i.total,
401
- piecesPerUnit: i.piecesPerUnit || 0
402
  }))
403
  };
404
 
@@ -415,14 +415,14 @@ document.getElementById('savePurchase').addEventListener('click', async () => {
415
  if (res.ok) {
416
  window.location.href = `/Purchases/Print/${data.purchaseId}`;
417
  } else {
418
- showToast(data.message || 'حدث خطأ', 'danger');
419
  btn.disabled = false;
420
- btn.innerHTML = '<i class="bi bi-save2 me-2"></i>حفظ فاتورة الشراء';
421
  }
422
  } catch {
423
- showToast('خطأ في الاتصال', 'danger');
424
  btn.disabled = false;
425
- btn.innerHTML = '<i class="bi bi-save2 me-2"></i>حفظ فاتورة الشراء';
426
  }
427
  });
428
 
 
1
  @model OilShopManagement.ViewModels.PurchaseCreateViewModel
2
  @{
3
+ ViewData["Title"] = L.T("فاتورة شراء جديدة","New Purchase Invoice");
4
  }
5
 
6
  <style>
 
18
  </style>
19
 
20
  <div class="d-flex align-items-center justify-content-between mb-3">
21
+ <h4 class="fw-bold mb-0"><i class="bi bi-cart-plus me-2 text-success"></i>@L.T("فاتورة شراء جديدة","New Purchase Invoice")</h4>
22
  <a href="/Purchases" class="btn btn-outline-secondary rounded-pill btn-sm">
23
+ <i class="bi bi-arrow-right me-1"></i>@L.T("فواتير الشراء","Purchase Invoices")
24
  </a>
25
  </div>
26
 
 
30
  <!-- Products Browser -->
31
  <div class="card mb-3">
32
  <div class="card-header d-flex align-items-center justify-content-between py-2">
33
+ <span><i class="bi bi-grid me-2 text-success"></i>@L.T("اختر المنتجات","Select Products")</span>
34
  <div class="d-flex align-items-center gap-2">
35
  <input type="text" id="prodFilter" class="form-control form-control-sm"
36
+ style="width:160px" placeholder="@L.T("فلتر...","Filter...")" oninput="filterProducts(this.value)">
37
  <span class="badge bg-secondary rounded-pill" id="prodCount">...</span>
38
  </div>
39
  </div>
 
45
  <!-- Selected Items Table -->
46
  <div class="card">
47
  <div class="card-header d-flex align-items-center justify-content-between">
48
+ <span><i class="bi bi-list-check me-2"></i>@L.T("المنتجات المختارة","Selected Products")</span>
49
+ <span class="badge bg-success rounded-pill" id="itemCount">0</span>
50
  </div>
51
  <div class="card-body p-0">
52
  <div class="table-responsive">
53
  <table class="table mb-0" id="itemsTable">
54
  <thead>
55
  <tr>
56
+ <th>@L.T("المنتج","Product")</th>
57
+ <th style="width:110px">@L.T("المخزون","Stock")</th>
58
+ <th style="width:140px">@L.T("الكمية","Qty")</th>
59
+ <th style="width:150px">@L.T("سعر الوحدة","Unit Price")</th>
60
+ <th style="width:120px">@L.T("الإجمالي","Total")</th>
61
  <th style="width:40px"></th>
62
  </tr>
63
  </thead>
 
65
  <tr id="emptyRow">
66
  <td colspan="6" class="text-center text-muted py-4">
67
  <i class="bi bi-hand-index-thumb fs-2 d-block mb-1"></i>
68
+ @L.T("اضغط على منتج من الأعلى لإضافته","Click a product above to add it")
69
  </td>
70
  </tr>
71
  </tbody>
 
79
  <div>
80
  <div class="invoice-summary card">
81
  <div class="card-header fw-bold">
82
+ <i class="bi bi-receipt me-2 text-success"></i>@L.T("ملخص فاتورة الشراء","Purchase Invoice Summary")
83
  </div>
84
  <div class="card-body">
85
  <!-- Supplier -->
86
  <div class="mb-3">
87
+ <label class="form-label fw-semibold small">@L.T("المورد (اختياري)","Supplier (optional)")</label>
88
  <div class="input-group">
89
+ <input type="text" id="supplierSearch" class="form-control form-control-sm"
90
+ placeholder="@L.T("ابحث عن المورد...","Search for supplier...")">
91
  <button class="btn btn-outline-secondary btn-sm" type="button" id="clearSupplier">
92
  <i class="bi bi-x"></i>
93
  </button>
 
98
  </div>
99
 
100
  <div class="mb-3">
101
+ <label class="form-label fw-semibold small">@L.T("تاريخ الشراء","Purchase Date")</label>
102
  <input type="datetime-local" id="purchaseDate" class="form-control form-control-sm"
103
  value="@DateTime.Now.ToString("yyyy-MM-ddTHH:mm", System.Globalization.CultureInfo.InvariantCulture)">
104
  </div>
105
  <div class="mb-3">
106
+ <label class="form-label fw-semibold small">@L.T("طريقة الدفع","Payment Method")</label>
107
  <select id="paymentMethod" class="form-select form-select-sm">
108
+ <option value="0">@L.T("نقداً","Cash")</option>
109
+ <option value="1">@L.T("بطاقة","Card")</option>
110
+ <option value="2">@L.T("تحويل","Transfer")</option>
111
  </select>
112
  </div>
113
 
114
  <hr>
115
  <div class="d-flex justify-content-between align-items-center mb-2">
116
+ <span class="text-muted">@L.T("الإجمالي قبل الضريبة","Subtotal")</span>
117
  <input type="number" id="subTotal" class="form-control form-control-sm text-end fw-semibold"
118
  style="width:120px" min="0" step="0.001" value="0" placeholder="0.000">
119
  </div>
120
  <div class="d-flex justify-content-between align-items-center mb-2">
121
+ <span class="text-muted">@L.T("الضريبة","Tax")
122
  <input type="number" id="taxRate" value="0" min="0" max="100"
123
  class="form-control form-control-sm d-inline-block ms-1" style="width:55px">%
124
  </span>
125
  <span id="taxAmount" class="fw-semibold">0.000</span>
126
  </div>
127
  <div class="d-flex justify-content-between align-items-center mb-3">
128
+ <span class="text-muted">@L.T("خصم","Discount") (@L.T("ر.ع.","OMR"))</span>
129
  <input type="number" id="discount" value="0" min="0"
130
  class="form-control form-control-sm text-end" style="width:100px">
131
  </div>
132
  <hr>
133
  <div class="d-flex justify-content-between mb-3">
134
+ <span class="fw-bold fs-5">@L.T("الإجمالي النهائي","Grand Total")</span>
135
+ <span id="totalAmount" class="fw-bold fs-5 text-success">0.000 @L.T("ر.ع.","OMR")</span>
136
  </div>
137
 
138
  <div class="mb-3">
139
+ <label class="form-label fw-semibold small">@L.T("ملاحظات","Notes")</label>
140
+ <textarea id="notes" class="form-control form-control-sm" rows="2"
141
+ placeholder="@L.T("ملاحظات...","Notes...")"></textarea>
142
  </div>
143
 
144
  <button type="button" id="savePurchase" class="btn btn-success w-100 btn-lg rounded-pill" disabled>
145
+ <i class="bi bi-save2 me-2"></i>@L.T("حفظ فاتورة الشراء","Save Purchase Invoice")
146
  </button>
147
  </div>
148
  </div>
 
151
 
152
  @section Scripts {
153
  <script>
154
+ const T = {
155
+ noProducts: '@L.T("لا توجد منتجات","No products")',
156
+ clickToAdd: '@L.T("اضغط على منتج من الأعلى لإضافته","Click a product above to add it")',
157
+ supplierChosen: '@L.T("✓ تم اختيار المورد","✓ Supplier selected")',
158
+ saving: '@L.T("جاري الحفظ...","Saving...")',
159
+ savePurchase: '@L.T("حفظ فاتورة الشراء","Save Purchase Invoice")',
160
+ errorOccurred: '@L.T("حدث خطأ","An error occurred")',
161
+ connError: '@L.T("خطأ في الاتصال","Connection error")',
162
+ omr: '@L.T("ر.ع.","OMR")',
163
+ items: '@L.T("حبة","pcs")',
164
+ carton: '@L.T("كرتون","carton")',
165
+ itemWord: '@L.T("منتج","item")',
166
+ };
167
+
168
  let purchaseItems = [];
169
  let allProducts = [];
170
  let filteredProducts = [];
 
175
  renderProdGrid(d);
176
  }).catch(() => {});
177
 
 
178
  function renderProdGrid(products) {
179
+ document.getElementById('prodCount').textContent = products.length + ' ' + T.itemWord;
180
  const grid = document.getElementById('prodGrid');
181
  if (!products.length) {
182
+ grid.innerHTML = '<div class="text-muted small p-2">' + T.noProducts + '</div>';
183
  return;
184
  }
185
  grid.innerHTML = products.map((p, idx) => {
186
  const inCart = purchaseItems.some(i => i.productId === p.id);
187
  const isCarton = (p.unit === 'كرتون' || p.unit === 'Carton') && p.piecesPerUnit > 0;
188
  const stockLabel = isCarton
189
+ ? `${p.currentStock} ${T.carton} (${p.currentStock * p.piecesPerUnit} ${T.items})`
190
  : `${p.currentStock} ${p.unit}`;
191
  const stockClass = p.currentStock <= 0 ? 'bg-danger' : (p.currentStock <= p.minStockLevel ? 'bg-warning text-dark' : 'bg-secondary');
192
  return `<div class="prod-card ${inCart ? 'in-cart' : ''}" onclick="toggleProduct(${idx})" title="${p.name}">
 
196
  <span class="badge ${stockClass} rounded-pill" style="font-size:.65rem">${stockLabel}</span>
197
  ${inCart ? '<i class="bi bi-check-circle-fill text-success" style="font-size:.85rem"></i>' : ''}
198
  </div>
199
+ <div class="text-success fw-semibold mt-1" style="font-size:.75rem">${parseFloat(p.purchasePrice).toFixed(3)} ${T.omr}</div>
200
  </div>`;
201
  }).join('');
202
  }
 
213
  if (!p) return;
214
  const existing = purchaseItems.find(i => i.productId === p.id);
215
  if (existing) {
 
216
  const row = document.querySelector(`tr[data-pid="${p.id}"]`);
217
  if (row) { row.scrollIntoView({ behavior: 'smooth', block: 'center' }); row.classList.add('table-success'); setTimeout(() => row.classList.remove('table-success'), 1200); }
218
  } else {
219
  const isCarton = (p.unit === 'كرتون' || p.unit === 'Carton') && p.piecesPerUnit > 0;
220
+ const initQty = isCarton ? (p.piecesPerUnit || 1) : 1;
221
  const piecePrice = p.purchasePrice || 0;
222
  purchaseItems.push({
223
+ productId: p.id, productName: p.name,
224
+ quantity: initQty, unitPrice: piecePrice,
 
 
225
  total: piecePrice * initQty,
226
+ unit: p.unit, currentStock: p.currentStock,
227
+ isCarton, piecesPerUnit: p.piecesPerUnit || 0
 
 
228
  });
229
+ renderItems(); calcTotals(true);
 
 
230
  document.getElementById('itemsTable').scrollIntoView({ behavior: 'smooth', block: 'nearest' });
231
  }
232
  renderProdGrid(filteredProducts);
233
  }
234
 
 
235
  function renderItems() {
236
  const tbody = document.getElementById('itemsBody');
237
  if (!purchaseItems.length) {
238
  tbody.innerHTML = `<tr id="emptyRow"><td colspan="6" class="text-center text-muted py-4">
239
+ <i class="bi bi-hand-index-thumb fs-2 d-block mb-1"></i>${T.clickToAdd}</td></tr>`;
240
+ document.getElementById('itemCount').textContent = '0';
241
  document.getElementById('savePurchase').disabled = true;
242
  return;
243
  }
244
  tbody.innerHTML = purchaseItems.map((item, idx) => {
245
  const ppu = item.piecesPerUnit || 0;
 
246
  const stockPieces = item.isCarton ? item.currentStock * ppu : item.currentStock;
247
+ const stockLabel = item.isCarton ? `${stockPieces} ${T.items}` : `${item.currentStock} ${item.unit}`;
 
248
  const addedCartons = item.isCarton ? Math.ceil(item.quantity / ppu) : item.quantity;
249
  const afterCartons = item.currentStock + addedCartons;
250
  const afterPieces = item.isCarton ? afterCartons * ppu : afterCartons;
251
+ const afterLabel = item.isCarton ? `${afterPieces} ${T.items} (${afterCartons} ${T.carton})` : `${afterCartons} ${item.unit}`;
252
+ const cartonNote = item.isCarton ? `<div style="font-size:.65rem;color:#0891b2">${Math.ceil(item.quantity/ppu)} ${T.carton}</div>` : '';
 
253
 
254
  return `<tr data-pid="${item.productId}">
255
  <td>
256
  <div class="fw-semibold small">${item.productName}</div>
257
+ <small class="text-muted">${item.isCarton ? `${T.carton} · ${ppu} ${T.items}/${T.carton}` : item.unit}</small>
258
  </td>
259
  <td class="text-center small">
260
  <div class="text-muted">${stockLabel}</div>
 
267
  onchange="setQty(${idx},this.value)" style="width:54px">
268
  <button class="btn btn-outline-secondary" onclick="changeQty(${idx},1)">+</button>
269
  </div>
270
+ ${item.isCarton ? `<div class="text-center mt-1" style="font-size:.65rem;color:#64748b">${T.items} ${cartonNote}</div>` : ''}
271
  </td>
272
  <td>
273
  <div class="input-group input-group-sm">
274
  <input type="number" class="form-control text-end" value="${item.unitPrice.toFixed(3)}"
275
  min="0" step="0.001" onchange="setPrice(${idx},this.value)" style="width:90px">
276
+ <span class="input-group-text" style="font-size:.65rem">${item.isCarton ? T.omr+'/' + T.items : T.omr}</span>
277
  </div>
278
  </td>
279
  <td class="fw-semibold text-success">
280
  ${item.total.toFixed(3)}
281
+ ${item.isCarton ? `<div style="font-size:.65rem;color:#64748b">${item.quantity} ${T.items}</div>` : ''}
282
  </td>
283
  <td>
284
  <button class="btn btn-sm btn-outline-danger" onclick="removeItem(${idx})">
 
287
  </td>
288
  </tr>`;
289
  }).join('');
290
+ document.getElementById('itemCount').textContent = purchaseItems.length;
291
  document.getElementById('savePurchase').disabled = false;
292
  }
293
 
 
315
  renderProdGrid(filteredProducts);
316
  }
317
 
 
318
  function calcTotals(fromItems = false) {
319
  if (fromItems) {
320
  const computed = purchaseItems.reduce((s, i) => s + i.total, 0);
 
325
  const discount = parseFloat(document.getElementById('discount').value) || 0;
326
  const taxAmount = subTotal * (taxRate / 100);
327
  const total = subTotal + taxAmount - discount;
328
+ document.getElementById('taxAmount').textContent = taxAmount.toFixed(3) + ' ' + T.omr;
329
+ document.getElementById('totalAmount').textContent = total.toFixed(3) + ' ' + T.omr;
330
  }
331
 
332
  document.getElementById('subTotal').addEventListener('input', () => { calcTotals(false); updateSaveBtn(); });
 
339
  document.getElementById('savePurchase').disabled = !hasItems && !hasManual;
340
  }
341
 
342
+ // Supplier Search
343
  const supplierSearch = document.getElementById('supplierSearch');
344
  const supplierSuggestions = document.getElementById('supplierSuggestions');
345
  let supplierTimeout;
 
363
  document.getElementById('selectedSupplierId').value = el.dataset.id;
364
  supplierSearch.value = el.dataset.name;
365
  supplierSuggestions.classList.add('d-none');
366
+ document.getElementById('selectedSupplierInfo').textContent = T.supplierChosen;
367
  document.getElementById('selectedSupplierInfo').classList.remove('d-none');
368
  });
369
  });
 
379
  if (!supplierSearch.closest('.mb-3').contains(e.target)) supplierSuggestions.classList.add('d-none');
380
  });
381
 
382
+ // Save
383
  document.getElementById('savePurchase').addEventListener('click', async () => {
384
  const manualSubTotal = parseFloat(document.getElementById('subTotal').value) || 0;
385
  if (!purchaseItems.length && manualSubTotal <= 0) return;
386
  const btn = document.getElementById('savePurchase');
387
  btn.disabled = true;
388
+ btn.innerHTML = `<span class="spinner-border spinner-border-sm me-2"></span>${T.saving}`;
389
  const taxRate = parseFloat(document.getElementById('taxRate').value) || 0;
390
  const discount = parseFloat(document.getElementById('discount').value) || 0;
391
 
 
396
  taxRate, discount, manualSubTotal,
397
  notes: document.getElementById('notes').value,
398
  items: purchaseItems.map(i => ({
399
+ productId: i.productId, productName: i.productName,
400
+ quantity: i.quantity, unitPrice: i.unitPrice,
401
+ total: i.total, piecesPerUnit: i.piecesPerUnit || 0
 
 
 
402
  }))
403
  };
404
 
 
415
  if (res.ok) {
416
  window.location.href = `/Purchases/Print/${data.purchaseId}`;
417
  } else {
418
+ showToast(data.message || T.errorOccurred, 'danger');
419
  btn.disabled = false;
420
+ btn.innerHTML = `<i class="bi bi-save2 me-2"></i>${T.savePurchase}`;
421
  }
422
  } catch {
423
+ showToast(T.connError, 'danger');
424
  btn.disabled = false;
425
+ btn.innerHTML = `<i class="bi bi-save2 me-2"></i>${T.savePurchase}`;
426
  }
427
  });
428
 
Views/Purchases/Index.cshtml CHANGED
@@ -1,12 +1,12 @@
1
  @model IEnumerable<OilShopManagement.Models.Purchase>
2
  @{
3
- ViewData["Title"] = "فواتير الشراء";
4
  }
5
 
6
  <div class="d-flex align-items-center justify-content-between mb-4">
7
- <h4 class="fw-bold mb-0"><i class="bi bi-bag-check me-2 text-success"></i>فواتير الشراء</h4>
8
  <a href="/Purchases/Create" class="btn btn-success rounded-pill px-4">
9
- <i class="bi bi-plus-circle me-2"></i>مشتريات جديدة
10
  </a>
11
  </div>
12
 
@@ -14,20 +14,22 @@
14
  <div class="card-body">
15
  <form method="get" class="row g-2 align-items-end">
16
  <div class="col-md-3">
17
- <label class="form-label small fw-semibold">من تاريخ</label>
18
  <input type="date" name="from" class="form-control" value="@ViewBag.From">
19
  </div>
20
  <div class="col-md-3">
21
- <label class="form-label small fw-semibold">إلى تاريخ</label>
22
  <input type="date" name="to" class="form-control" value="@ViewBag.To">
23
  </div>
24
  <div class="col-md-4">
25
- <label class="form-label small fw-semibold">بحث</label>
26
- <input type="text" name="search" class="form-control" placeholder="رقم الفاتورة أو اسم المورد..." value="@ViewBag.Search">
 
 
27
  </div>
28
  <div class="col-md-2">
29
  <button type="submit" class="btn btn-success w-100">
30
- <i class="bi bi-search me-1"></i>بحث
31
  </button>
32
  </div>
33
  </form>
@@ -36,21 +38,21 @@
36
 
37
  <div class="card">
38
  <div class="card-header d-flex align-items-center justify-content-between">
39
- <span>النتائج: @Model.Count() فاتورة</span>
40
- <span class="fw-bold text-success">الإجمالي: @Model.Where(p => p.Status == OilShopManagement.Models.PurchaseStatus.Completed).Sum(p => p.TotalAmount).ToString("N3") ر.ع.</span>
41
  </div>
42
  <div class="card-body p-0">
43
  <div class="table-responsive">
44
  <table class="table table-hover mb-0">
45
  <thead>
46
  <tr>
47
- <th>رقم الفاتورة</th>
48
- <th>المورد</th>
49
- <th>التاريخ</th>
50
- <th>طريقة الدفع</th>
51
- <th>الإجمالي</th>
52
- <th>الحالة</th>
53
- <th>إجراءات</th>
54
  </tr>
55
  </thead>
56
  <tbody>
@@ -58,31 +60,31 @@
58
  {
59
  <tr>
60
  <td><span class="badge bg-success-subtle text-success fw-semibold">@p.PurchaseNumber</span></td>
61
- <td>@(p.Supplier?.Name ?? "مورد عام")</td>
62
  <td>@p.PurchaseDate.ToString("dd/MM/yyyy HH:mm")</td>
63
  <td>
64
  @if (p.PaymentMethod == OilShopManagement.Models.PaymentMethod.Cash)
65
- { <span class="badge bg-success-subtle text-success"><i class="bi bi-cash me-1"></i>نقداً</span> }
66
  else if (p.PaymentMethod == OilShopManagement.Models.PaymentMethod.Card)
67
- { <span class="badge bg-info-subtle text-info"><i class="bi bi-credit-card me-1"></i>بطاقة</span> }
68
  else
69
- { <span class="badge bg-warning-subtle text-warning"><i class="bi bi-bank me-1"></i>تحويل</span> }
70
  </td>
71
- <td class="fw-semibold">@p.TotalAmount.ToString("N3") ر.ع.</td>
72
  <td>
73
  @if (p.Status == OilShopManagement.Models.PurchaseStatus.Completed)
74
- { <span class="badge bg-success">مكتملة</span> }
75
  else if (p.Status == OilShopManagement.Models.PurchaseStatus.Cancelled)
76
- { <span class="badge bg-danger">ملغاة</span> }
77
  else
78
- { <span class="badge bg-secondary">مسودة</span> }
79
  </td>
80
  <td>
81
  <div class="btn-group btn-group-sm">
82
- <a href="/Purchases/Details/@p.Id" class="btn btn-outline-secondary rounded-start-pill" title="تفاصيل">
83
  <i class="bi bi-eye"></i>
84
  </a>
85
- <a href="/Purchases/Print/@p.Id" class="btn btn-outline-success rounded-end-pill" target="_blank" title="طباعة">
86
  <i class="bi bi-printer"></i>
87
  </a>
88
  </div>
@@ -92,7 +94,7 @@
92
  @if (!Model.Any())
93
  {
94
  <tr><td colspan="7" class="text-center text-muted py-5">
95
- <i class="bi bi-inbox fs-2 d-block mb-2"></i>لا توجد فواتير شراء في هذه الفترة
96
  </td></tr>
97
  }
98
  </tbody>
 
1
  @model IEnumerable<OilShopManagement.Models.Purchase>
2
  @{
3
+ ViewData["Title"] = L.T("فواتير الشراء","Purchase Invoices");
4
  }
5
 
6
  <div class="d-flex align-items-center justify-content-between mb-4">
7
+ <h4 class="fw-bold mb-0"><i class="bi bi-bag-check me-2 text-success"></i>@L.T("فواتير الشراء","Purchase Invoices")</h4>
8
  <a href="/Purchases/Create" class="btn btn-success rounded-pill px-4">
9
+ <i class="bi bi-plus-circle me-2"></i>@L.T("مشتريات جديدة","New Purchase")
10
  </a>
11
  </div>
12
 
 
14
  <div class="card-body">
15
  <form method="get" class="row g-2 align-items-end">
16
  <div class="col-md-3">
17
+ <label class="form-label small fw-semibold">@L.T("من تاريخ","From Date")</label>
18
  <input type="date" name="from" class="form-control" value="@ViewBag.From">
19
  </div>
20
  <div class="col-md-3">
21
+ <label class="form-label small fw-semibold">@L.T("إلى تاريخ","To Date")</label>
22
  <input type="date" name="to" class="form-control" value="@ViewBag.To">
23
  </div>
24
  <div class="col-md-4">
25
+ <label class="form-label small fw-semibold">@L.T("بحث","Search")</label>
26
+ <input type="text" name="search" class="form-control"
27
+ placeholder="@L.T("رقم الفاتورة أو اسم المورد...","Invoice number or supplier...")"
28
+ value="@ViewBag.Search">
29
  </div>
30
  <div class="col-md-2">
31
  <button type="submit" class="btn btn-success w-100">
32
+ <i class="bi bi-search me-1"></i>@L.T("بحث","Search")
33
  </button>
34
  </div>
35
  </form>
 
38
 
39
  <div class="card">
40
  <div class="card-header d-flex align-items-center justify-content-between">
41
+ <span>@L.T("النتائج:","Results:") @Model.Count() @L.T("فاتورة","invoice")</span>
42
+ <span class="fw-bold text-success">@L.T("الإجمالي:","Total:") @Model.Where(p => p.Status == OilShopManagement.Models.PurchaseStatus.Completed).Sum(p => p.TotalAmount).ToString("N3") @L.T("ر.ع.","OMR")</span>
43
  </div>
44
  <div class="card-body p-0">
45
  <div class="table-responsive">
46
  <table class="table table-hover mb-0">
47
  <thead>
48
  <tr>
49
+ <th>@L.T("رقم الفاتورة","Invoice #")</th>
50
+ <th>@L.T("المورد","Supplier")</th>
51
+ <th>@L.T("التاريخ","Date")</th>
52
+ <th>@L.T("طريقة الدفع","Payment")</th>
53
+ <th>@L.T("الإجمالي","Total")</th>
54
+ <th>@L.T("الحالة","Status")</th>
55
+ <th>@L.T("إجراءات","Actions")</th>
56
  </tr>
57
  </thead>
58
  <tbody>
 
60
  {
61
  <tr>
62
  <td><span class="badge bg-success-subtle text-success fw-semibold">@p.PurchaseNumber</span></td>
63
+ <td>@(p.Supplier?.Name ?? L.T("مورد عام","General Supplier"))</td>
64
  <td>@p.PurchaseDate.ToString("dd/MM/yyyy HH:mm")</td>
65
  <td>
66
  @if (p.PaymentMethod == OilShopManagement.Models.PaymentMethod.Cash)
67
+ { <span class="badge bg-success-subtle text-success"><i class="bi bi-cash me-1"></i>@L.T("نقداً","Cash")</span> }
68
  else if (p.PaymentMethod == OilShopManagement.Models.PaymentMethod.Card)
69
+ { <span class="badge bg-info-subtle text-info"><i class="bi bi-credit-card me-1"></i>@L.T("بطاقة","Card")</span> }
70
  else
71
+ { <span class="badge bg-warning-subtle text-warning"><i class="bi bi-bank me-1"></i>@L.T("تحويل","Transfer")</span> }
72
  </td>
73
+ <td class="fw-semibold">@p.TotalAmount.ToString("N3") @L.T("ر.ع.","OMR")</td>
74
  <td>
75
  @if (p.Status == OilShopManagement.Models.PurchaseStatus.Completed)
76
+ { <span class="badge bg-success">@L.T("مكتملة","Completed")</span> }
77
  else if (p.Status == OilShopManagement.Models.PurchaseStatus.Cancelled)
78
+ { <span class="badge bg-danger">@L.T("ملغاة","Cancelled")</span> }
79
  else
80
+ { <span class="badge bg-secondary">@L.T("مسودة","Draft")</span> }
81
  </td>
82
  <td>
83
  <div class="btn-group btn-group-sm">
84
+ <a href="/Purchases/Details/@p.Id" class="btn btn-outline-secondary rounded-start-pill" title="@L.T("تفاصيل","Details")">
85
  <i class="bi bi-eye"></i>
86
  </a>
87
+ <a href="/Purchases/Print/@p.Id" class="btn btn-outline-success rounded-end-pill" target="_blank" title="@L.T("طباعة","Print")">
88
  <i class="bi bi-printer"></i>
89
  </a>
90
  </div>
 
94
  @if (!Model.Any())
95
  {
96
  <tr><td colspan="7" class="text-center text-muted py-5">
97
+ <i class="bi bi-inbox fs-2 d-block mb-2"></i>@L.T("لا توجد فواتير شراء في هذه الفترة","No purchase invoices in this period")
98
  </td></tr>
99
  }
100
  </tbody>