Fetch Data For Customer Details
This commit is contained in:
@@ -50,19 +50,12 @@ class AdminInvoiceController extends Controller
|
||||
// POPUP VIEW
|
||||
// -------------------------------------------------------------
|
||||
public function popup($id)
|
||||
{
|
||||
{
|
||||
$invoice = Invoice::with([
|
||||
'items',
|
||||
'chargeGroups.items',
|
||||
])->findOrFail($id);
|
||||
|
||||
// demo update असेल तर
|
||||
$invoice->update([
|
||||
'customer_email' => 'test@demo.com',
|
||||
'customer_address' => 'TEST ADDRESS',
|
||||
'pincode' => '999999',
|
||||
]);
|
||||
|
||||
$shipment = null;
|
||||
|
||||
$groupedItemIds = $invoice->chargeGroups
|
||||
@@ -72,7 +65,7 @@ class AdminInvoiceController extends Controller
|
||||
->toArray();
|
||||
|
||||
return view('admin.popup_invoice', compact('invoice', 'shipment', 'groupedItemIds'));
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// EDIT INVOICE PAGE
|
||||
@@ -87,6 +80,28 @@ class AdminInvoiceController extends Controller
|
||||
'installments',
|
||||
])->findOrFail($id);
|
||||
|
||||
// ✅ Customer details sync — जर test data आला असेल तर fix होईल
|
||||
if ($invoice->customer) {
|
||||
$needsUpdate = [];
|
||||
|
||||
if (empty($invoice->customer_email) || $invoice->customer_email === 'test@demo.com') {
|
||||
$needsUpdate['customer_email'] = $invoice->customer->email;
|
||||
}
|
||||
|
||||
if (empty($invoice->customer_address) || $invoice->customer_address === 'TEST ADDRESS') {
|
||||
$needsUpdate['customer_address'] = $invoice->customer->address;
|
||||
}
|
||||
|
||||
if (empty($invoice->pincode) || $invoice->pincode === '999999') {
|
||||
$needsUpdate['pincode'] = $invoice->customer->pincode;
|
||||
}
|
||||
|
||||
if (!empty($needsUpdate)) {
|
||||
$invoice->update($needsUpdate);
|
||||
$invoice->refresh();
|
||||
}
|
||||
}
|
||||
|
||||
$shipment = null;
|
||||
|
||||
$groupedItemIds = $invoice->chargeGroups
|
||||
|
||||
@@ -520,7 +520,7 @@ class ContainerController extends Controller
|
||||
|
||||
$invoice = new Invoice();
|
||||
$invoice->container_id = $container->id;
|
||||
// $invoice->customer_id = $customerId;
|
||||
$invoice->customer_id = $customerId;
|
||||
$invoice->mark_no = $firstMark;
|
||||
|
||||
$invoice->invoice_number = $this->generateInvoiceNumber();
|
||||
@@ -533,6 +533,13 @@ class ContainerController extends Controller
|
||||
->addDays(10)
|
||||
->format('Y-m-d');
|
||||
|
||||
// Customer User model वरून fetch करा (customer_id string आहे जसे CID-2025-000001)
|
||||
$customerUser = \App\Models\User::where('customer_id', $customerId)->first();
|
||||
|
||||
$invoice->container_id = $container->id;
|
||||
$invoice->customer_id = $customerUser->id ?? null; // ✅ integer id
|
||||
$invoice->mark_no = $firstMark;
|
||||
|
||||
if ($snap) {
|
||||
$invoice->customer_name = $snap['customer_name'] ?? null;
|
||||
$invoice->company_name = $snap['company_name'] ?? null;
|
||||
@@ -544,9 +551,10 @@ class ContainerController extends Controller
|
||||
$invoice->gst_amount = 0;
|
||||
$invoice->final_amount_with_gst = 0;
|
||||
|
||||
$invoice->customer_email = null;
|
||||
$invoice->customer_address = null;
|
||||
$invoice->pincode = null;
|
||||
// ✅ User model वरून email, address, pincode घ्या
|
||||
$invoice->customer_email = $customerUser->email ?? null;
|
||||
$invoice->customer_address = $customerUser->address ?? null;
|
||||
$invoice->pincode = $customerUser->pincode ?? null;
|
||||
|
||||
$uniqueMarks = array_unique(array_column($rowsForCustomer, 'mark'));
|
||||
$invoice->notes = 'Auto-created from Container ' . $container->container_number
|
||||
|
||||
@@ -672,11 +672,14 @@
|
||||
);
|
||||
|
||||
$isTotalColumn = $isTotalQty || $isTotalCbm || $isTotalKg || $isAmount;
|
||||
|
||||
// जर container pending नसेल तर सर्व fields readonly
|
||||
$isReadOnly = $isTotalColumn || $container->status !== 'pending';
|
||||
@endphp
|
||||
<td>
|
||||
<input
|
||||
type="text"
|
||||
class="cm-cell-input {{ $isTotalColumn ? 'cm-cell-readonly' : '' }}"
|
||||
class="cm-cell-input {{ $isReadOnly ? 'cm-cell-readonly' : '' }}"
|
||||
name="rows[{{ $row->id }}][{{ $heading }}]"
|
||||
value="{{ $value }}"
|
||||
data-row-id="{{ $row->id }}"
|
||||
@@ -690,10 +693,11 @@
|
||||
data-ttlkg="{{ $isTotalKg ? '1' : '0' }}"
|
||||
data-price="{{ $isPrice ? '1' : '0' }}"
|
||||
data-amount="{{ $isAmount ? '1' : '0' }}"
|
||||
@if($isTotalColumn) readonly @endif
|
||||
{{ $isReadOnly ? 'readonly' : '' }}
|
||||
>
|
||||
</td>
|
||||
@endforeach
|
||||
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
@@ -706,16 +710,18 @@
|
||||
</div>
|
||||
|
||||
@if(!$container->rows->isEmpty())
|
||||
<button id="cmSaveBtnFloating" class="cm-save-btn-floating">
|
||||
<button
|
||||
id="cmSaveBtnFloating"
|
||||
class="cm-save-btn-floating {{ $container->status !== 'pending' ? 'cm-disabled' : '' }}"
|
||||
{{ $container->status !== 'pending' ? 'disabled' : '' }}
|
||||
>
|
||||
Save Changes
|
||||
</button>
|
||||
<div id="cmToast" class="cm-toast">
|
||||
Changes saved successfully.
|
||||
</div>
|
||||
</button>
|
||||
@endif
|
||||
|
||||
|
||||
<script>
|
||||
function cmFilterRows() {
|
||||
function cmFilterRows() {
|
||||
const input = document.getElementById('cmRowSearch');
|
||||
if (!input) return;
|
||||
const filter = input.value.toLowerCase();
|
||||
@@ -734,9 +740,9 @@
|
||||
}
|
||||
rows[i].style.display = match ? '' : 'none';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const form = document.getElementById('cm-edit-rows-form');
|
||||
const btn = document.getElementById('cmSaveBtnFloating');
|
||||
const toast = document.getElementById('cmToast');
|
||||
@@ -843,6 +849,7 @@
|
||||
const target = e.target;
|
||||
if (!target.classList.contains('cm-cell-input')) return;
|
||||
|
||||
// readonly / non-pending cells साठी block
|
||||
if (target.classList.contains('cm-cell-readonly') || target.hasAttribute('readonly')) {
|
||||
target.blur();
|
||||
return;
|
||||
@@ -857,6 +864,11 @@
|
||||
|
||||
if (form && btn) {
|
||||
btn.addEventListener('click', function () {
|
||||
// जर बटण आधीच disabled असेल (non-pending status किंवा processing)
|
||||
if (btn.classList.contains('cm-disabled') || btn.hasAttribute('disabled')) {
|
||||
return;
|
||||
}
|
||||
|
||||
btn.classList.add('cm-disabled');
|
||||
const formData = new FormData(form);
|
||||
|
||||
@@ -886,6 +898,7 @@
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
@endsection
|
||||
|
||||
@@ -899,12 +899,17 @@
|
||||
<div class="customer-detail"><strong>Company:</strong> {{ $invoice->company_name }}</div>
|
||||
@endif
|
||||
<div class="customer-detail"><strong>Mobile:</strong> {{ $invoice->customer_mobile }}</div>
|
||||
<div class="customer-detail"><strong>Email:</strong> {{ $invoice->customer_email }}</div>
|
||||
<div class="customer-detail"><strong>Email:</strong>
|
||||
{{ $invoice->customer_email ?: ($invoice->customer->email ?? '-') }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="customer-detail"><strong>Address:</strong></div>
|
||||
<div class="customer-detail">{{ $invoice->customer_address }}</div>
|
||||
<div class="customer-detail"><strong>Pincode:</strong> {{ $invoice->pincode }}</div>
|
||||
<div class="customer-detail">
|
||||
{{ $invoice->customer_address ?: ($invoice->customer->address ?? '-') }}
|
||||
</div>
|
||||
<div class="customer-detail"><strong>Pincode:</strong>
|
||||
{{ $invoice->pincode ?: ($invoice->customer->pincode ?? '-') }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user