modiparth333-jpg's avatar

modiparth333-jpg wrote a reply+100 XP

5mos ago

Pls help guys

modiparth333-jpg's avatar

modiparth333-jpg wrote a reply+100 XP

5mos ago

I have fields like company, sage_account_reference, and address_line_1 are displayed.

When I click the Save button, it calls the method saveSelectedCustomer(). Inside this method, I update these values - and when I log them in the backend, I can see that the values are updated correctly.

However, in the UI, the values don’t change - they still show the old data.

modiparth333-jpg's avatar

modiparth333-jpg started a new conversation+100 XP

5mos ago

@if (!$sageIntegrationActive)
<div class="row">
    <div class="col-12">
        <div class="alert alert-info">Sage token has expired. This trade application cannot be reviewed.</div>
    </div>
</div>
@endif

<div class="row mt-2">
    <div class="col-12">
        <div class="tile">
            <div class="tile-body mt-3">

                <form @submit.prevent>
                    <div class="row px-3">
                        <div class="col-12 col-lg-6">
                            <fieldset class="border p-2 form-group">
                                <legend class="text-muted text-uppercase px-1 w-auto">Account</legend>
                                <div class="row px-3">
                                    <div class="form-group col-xl-8">
                                        <label class="control-label">Company Name <span class="required">*</span></label>
                                        <input id="company" name="company" wire:model.live="company" wire:blur="validateField('company')" class="form-control @error('company') border-red @enderror" type="text" {{ $customerSaved ? 'readonly' : '' }}>
                                        @error('company') <span class="error">{{ $message }}</span> @enderror
                                    </div>
                                    <div class="form-group col-xl-4">
                                        <label class="control-label">Account Reference <span class="required">*</span></label>
                                        <input id="sage_account_reference" name="sage_account_reference" wire:model.live="sage_account_reference"  class="form-control @error('sage_account_reference') border-red @enderror" type="text" oninput="this.value = this.value.toUpperCase().replace(/\s+/g, '')" maxlength="8" {{ $customerSaved ? 'readonly' : '' }}>
                                        @error('sage_account_reference') <span class="error">{{ $message }}</span> @enderror
                                    </div>
                                    <div class="row px-3">
                                        <div class="form-group col-12">
                                            <button type="button" class="btn btn-primary" @click="showSearchCustomerModal=true">Assign to Existing Customer</button>
                                        </div>
                                    </div>
                                </div>
                            </fieldset>
                            <fieldset class="border p-2 form-group">
                                <legend class="text-muted text-uppercase px-1 w-auto">Company Details</legend>
                                <div class="row px-3">
                                    <div class="form-group col-xl-6">
                                        <label class="control-label">Address Line 1 <span class="required">*</span></label>
                                        <input id="address_line_1" name="address_line_1" wire:model.live="address_line_1" wire:blur="validateField('address_line_1')" class="form-control @error('address_line_1') border-red @enderror" type="text" {{ $customerSaved ? 'readonly' : '' }}>
                                        @error('address_line_1') <span class="error">{{ $message }}</span> @enderror
                                    </div>
                                    <div class="form-group col-xl-6">
                                        <label class="control-label">Address Line 2</label>
                                        <input id="address_line_2" name="address_line_2" wire:model.live="address_line_2" wire:blur="validateField('address_line_2')" class="form-control @error('address_line_2') border-red @enderror" type="text" {{ $customerSaved ? 'readonly' : '' }}>
                                        @error('address_line_2') <span class="error">{{ $message }}</span> @enderror
                                    </div>
                                </div>
                                <div class="row px-3">
                                    <div class="form-group col-xl-6">
                                        <label class="control-label">City <span class="required">*</span></label>
                                        <input id="city" name="city" wire:model.live="city" wire:blur="validateField('city')" class="form-control @error('city') border-red @enderror" type="text" {{ $customerSaved ? 'readonly' : '' }}>
                                        @error('city') <span class="error">{{ $message }}</span> @enderror
                                    </div>
                                    <div class="form-group col-xl-6">
                                        <label class="control-label">Postcode <span class="required">*</span></label>
                                        <input id="postcode" name="postcode" wire:model.live="postcode" wire:blur="validateField('postcode')" class="form-control @error('postcode') border-red @enderror" type="text" {{ $customerSaved ? 'readonly' : '' }}>
                                        @error('postcode') <span class="error">{{ $message }}</span> @enderror
                                    </div>
                                </div>
                                <div class="form-group col-12">
                                    <label class="control-label">Country <span class="required">*</span></label>
                                    <select id="country" name="country" wire:model.live="country" wire:blur="validateField('country')" class="form-control @error('country') border-red @enderror" {{ $customerSaved ? 'readonly' : '' }}>
                                        <option value="">Select Country</option>
                                        @foreach ($countries as $country)
                                        <option value="{{ $country->code }}">{{ $country->name }}</option>
                                        @endforeach
                                    </select>
                                    @error('country') <span class="error">{{ $message }}</span> @enderror
                                </div>
                                <div class="form-group col-12">
                                @if ($country && $regions->count() > 0)
                                    <label class="control-label">{{ $region_title }} <span class="required">*</span></label>
                                    <select id="region" name="region" wire:model.live="region" wire:blur="validateField('region')" class="form-control @error('region') border-red @enderror" {{ $customerSaved ? 'readonly' : '' }}>
                                        <option value="">Select {{ $region_title }}</option>
                                        @foreach ($regions as $region)
                                            @if ($this->selected_country->code === 'ca' || $this->selected_country->code === 'us')
                                            <option value="{{ $region->id }}">{{ strtoupper($region->region_code) }} - {{ $region->name }}</option>
                                            @else
                                            <option value="{{ $region->id }}">{{ $region->name }}</option>
                                            @endif
                                        @endforeach
                                    </select>
                                    @error('region') <span class="error">{{ $message }}</span> @enderror
                                @else
                                    <label class="control-label">County / Region / State</label>
                                    <input id="region" name="region" wire:model.live="region" wire:blur="validateField('region')" class="form-control @error('region') border-red @enderror" type="text" {{ $customerSaved ? 'readonly' : '' }}>
                                    @error('region') <span class="error">{{ $message }}</span> @enderror
                                @endif
                                </div>
                                <div class="row px-3">
                                    <div class="form-group col-xl-6">
                                        <label class="control-label">Calling Code <span class="required">*</span></label>
                                        <select id="telephone_calling_code" name="telephone_calling_code" wire:model.live="telephone_calling_code" wire:blur="validateField('telephone_calling_code')" class="form-control @error('telephone_calling_code') border-red @enderror" {{ $customerSaved ? 'readonly' : '' }}>
                                            <option value="">Select Calling Code</option>
                                            @foreach ($country_calling_codes as $country_calling_code)
                                            <option value="{{ $country_calling_code->id }}">{{ $country_calling_code->name }} +{{ $country_calling_code->calling_code }}</option>
                                            @endforeach
                                        </select>
                                        @error('telephone_calling_code') <span class="error">{{ $message }}</span> @enderror
                                    </div>
                                    <div class="form-group col-xl-6">
                                        <label class="control-label">Telephone Number <span class="required">*</span></label>
                                        <input id="telephone" name="telephone" wire:model.live="telephone" wire:blur="validateField('telephone')" class="form-control @error('telephone') border-red @enderror" type="text" {{ $customerSaved ? 'readonly' : '' }}>
                                        @error('telephone') <span class="error">{{ $message }}</span> @enderror 
                                    </div>
                                </div>
                                <div class="form-group col-12">
                                    <label class="control-label">Website</label>
                                    <input id="website" name="website" wire:model.live="website" wire:blur="validateField('website')" class="form-control @error('website') border-red @enderror" type="text" placeholder="https://" {{ $customerSaved ? 'readonly' : '' }}>
                                    @error('website') <span class="error">{{ $message }}</span> @enderror
                                </div>
                            </fieldset>
                            <fieldset class="border p-2 form-group">
                                <legend class="text-muted text-uppercase px-1 w-auto">Default Contact</legend>
                                <div class="row px-3">
                                    <div class="form-group col-xl-6">
                                        <label class="control-label">First Name <span class="required">*</span></label>
                                        <input id="fname" name="fname" wire:model.live="fname" wire:blur="validateField('fname')" class="form-control @error('fname') border-red @enderror" type="text">
                                        @error('fname') <span class="error">{{ $message }}</span> @enderror
                                    </div>
                                    <div class="form-group col-xl-6">
                                        <label class="control-label">Last Name <span class="required">*</span></label>
                                        <input id="lname" name="lname" wire:model.live="lname" wire:blur="validateField('lname')" class="form-control @error('lname') border-red @enderror" type="text">
                                        @error('lname') <span class="error">{{ $message }}</span> @enderror
                                    </div>
                                </div>
                                <div class="form-group col-12">
                                    <label class="control-label">Email Address <span class="required">*</span></label>
                                    <input id="email" name="email" wire:model.live="email" wire:blur="validateField('email')" class="form-control @error('email') border-red @enderror" type="email">
                                    @error('email') <span class="error">{{ $message }}</span> @enderror
                                </div>
                            </fieldset>           
                        </div>
                        <div class="col-12 col-lg-6">
                            <fieldset class="border p-2 form-group">
                                <legend class="text-muted text-uppercase px-1 w-auto">Financial</legend>
                                <div class="row px-3">
                                    <div class="form-group col-xl-6">
                                        <label class="control-label">Discount Level <span class="required">*</span></label>
                                        <select id="discount_percent" name="discount_percent" wire:model.live="discount_percent" wire:blur="validateField('discount_percent')" class="form-control @error('discount_percent') border-red @enderror" {{ $customerSaved ? 'readonly' : '' }}>
                                            <option value="">Select Discount Level</option>
                                            @foreach ($discount_percentages as $discount_percentage)
                                                <option value="{{ $discount_percentage['discount_percentage'] }}">
                                                    {{ $discount_percentage['discount_percentage'] }}%
                                                </option>
                                            @endforeach
                                        </select>
                                        @error('discount_percent') <span class="error">{{ $message }}</span> @enderror
                                    </div>
                                    <div class="form-group col-xl-6">

                                  
                                        <label class="control-label">Currency <span class="required">*</span></label>
                                        <select id="currency" name="currency" wire:model.live="currency" wire:blur="validateField('currency')" class="form-control @error('currency') border-red @enderror" {{ $customerSaved ? 'readonly' : '' }}>
                                            <option value="">Select Currency</option>
                                            @foreach ($currencies as $currency)
                                            <option value="{{ $currency['id'] }}">{{ $currency['name']}}</option>
                                            @endforeach
                                        </select>
                                        @error('currency') <span class="error">{{ $message }}</span> @enderror
                                    </div>
                                </div>
                                <div class="form-group col-12">
                                    <label class="control-label">Tax / VAT Number</label>
                                    <input id="tax_number" name="tax_number" wire:model.live="tax_number" wire:blur="validateField('tax_number')" class="form-control @error('tax_number') border-red @enderror" type="text" {{ $customerSaved ? 'readonly' : '' }}>
                                    @error('tax_number') <span class="error">{{ $message }}</span> @enderror
                                </div>
                                <div class="form-group col-12">
                                    <div class="form-check">
                                        <input class="form-check-input" type="checkbox" id="allow_duplicate_tax_number" wire:model.live="allow_duplicate_tax_number" wire:blur="validateField('allow_duplicate_tax_number')" {{ $customerSaved ? 'readonly' : '' }}>
                                        <label class="form-check-label" for="allow_duplicate_tax_number">
                                                Allow Duplicate Tax Number
                                        </label>
                                    </div>
                                </div>
                            </fieldset>
                            <fieldset class="border p-2 form-group">
                                <legend class="text-muted text-uppercase px-1 w-auto">Additional Information</legend>
                                <div class="row px-3">
                                    <div class="form-group col-12">
                                        <label class="control-label">Customer Tier <span class="required">*</span></label>
                                        <select id="customer_tier" name="customer_tier" wire:model.live="customer_tier" wire:blur="validateField('customer_tier')" class="form-control @error('customer_tier') border-red @enderror" {{ $customerSaved ? 'readonly' : '' }}>
                                            <option value="">Select Customer Tier</option>
                                            <option value="Gold">Gold</option>
                                            <option value="Silver">Silver</option>
                                            <option value="Bronze">Bronze</option>
                                        </select>
                                        @error('customer_tier') <span class="error">{{ $message }}</span> @enderror
                                    </div>
                                </div>
                                <div class="row px-3">
                                    <div class="form-group col-xl-6">
                                        <label class="control-label">Assign to Salesperson</label>
                                        <select id="sales_manager" name="sales_manager" wire:model.live="sales_manager" wire:blur="validateField('sales_manager')" class="form-control @error('sales_manager') border-red @enderror" {{ $customerSaved ? 'readonly' : '' }}>
                                            <option value="">-- Assign Automatically --</option>
                                            @foreach ($sales_managers as $sales_manager)
                                            @php
                                                $name = $sales_manager['company'] ?? trim($sales_manager['fullname']) ?? null;
                                            @endphp
                                            <option value="{{ $sales_manager['id'] }}">{{ $sales_manager['sage_username'] }}@if ($name) ({{ $name }}) @endif</option>
                                            @endforeach
                                        </select>
                                        @error('sales_manager') <span class="error">{{ $message }}</span> @enderror
                                    </div>
                                    <div class="form-group col-xl-6">
                                        <label class="control-label">Assign to BDM</label>
                                        <select id="bdm" name="bdm" wire:model.live="bdm" wire:blur="validateField('bdm')" class="form-control @error('bdm') border-red @enderror" {{ $customerSaved ? 'readonly' : '' }}>
                                            <option value="">-- Assign Automatically --</option>
                                            @foreach ($bdms as $bdm)
                                            @php
                                                $name = $bdm['company'] ?? trim($bdm['fullname']) ?? null;
                                            @endphp
                                            <option value="{{ $bdm['id'] }}">{{ $bdm['sage_username'] }}@if ($name) ({{ $name }}) @endif</option>
                                            @endforeach
                                        </select>
                                        @error('bdm') <span class="error">{{ $message }}</span> @enderror
                                    </div>
                                </div>
                                <div class="row px-3">
                                    <div class="form-group col-12">
                                        <label class="control-label">Notes</label>
                                        <textarea id="notes" name="notes" rows="5" wire:model.live="notes" wire:blur="validateField('notes')" class="form-control @error('notes') border-red @enderror"></textarea>
                                        @error('notes') <span class="error">{{ $message }}</span> @enderror
                                    </div>
                                </div>
                                <div class="row px-3">
                                    <div class="form-group col-12">
                                        <label class="control-label">Additional Information</label>
                                        <textarea name="additional_information" rows="8" wire:model="additional_information" class="form-control" readonly></textarea>
                                    </div>
                                </div>
                            </fieldset>
                        </div>
                    </div>
                    <div class="row px-3">
                        <div class="form-group col-12 d-flex justify-content-between">
                            <button class="btn btn-secondary" wire:click="saveProgress" wire:loading.attr="disabled">Save Progress</button>
                            <div class="ml-auto d-flex">
                                @if ($application['status'] != 'declined')
                                <button class="btn btn-danger mr-1" wire:loading.attr="disabled" @click="showDeclineModal=true" @disabled(!$sageIntegrationActive)>Decline</button>
                                @endif
                                <button type="button" class="btn btn-primary" @click="$wire.preApprove()" wire:loading.attr="disabled" @disabled(!$sageIntegrationActive)>        {{ $customerSaved ? 'Yes, Approve and Update Customer' : 'Yes, Approve and Create Customer' }}
                </div>
        </div>
    </div>
</div>

<!-- Approve Confirmation Modal -->
<div x-show="showApproveModal" class="modal" x-cloak>
    <div class="modal-dialog" role="document">
        <div class="modal-content" @click.away="showApproveModal=false">
            <div class="modal-header">
                <h5 class="modal-title">Approve and Create Customer</h5>
                <span class="close" @click="showApproveModal=false">&times;</span>
            </div>
            <div class="modal-body">
                <p>This will create a new customer on Sage and update their website account automatically. Are you sure you want to continue?</p>
            </div>
            <div class="modal-footer">
                <a href="#" @click.prevent="showApproveModal=false" class="mr-2">Close</a>
                <button class="btn btn-primary" type="button" @click="$wire.approve(); showApproveModal=false;">Yes, Approve and Create Customer</button>
            </div>
        </div>
    </div>
</div>

<!-- Decline Confirmation Modal -->
<div x-show="showDeclineModal" class="modal" x-cloak>
    <div class="modal-dialog" role="document">
        <div class="modal-content" @click.away="showDeclineModal=false">
            <div class="modal-header">
                <h5 class="modal-title">Decline Application</h5>
                <span class="close" @click="showDeclineModal=false">&times;</span>
            </div>
            <div class="modal-body">
                <p>This will decline the customer's trade application. Are you sure you want to continue?</p>
            </div>
            <div class="modal-footer">
                <a href="#" @click.prevent="showDeclineModal=false" class="mr-2">Close</a>
                <button class="btn btn-primary" type="button" @click="$wire.decline(); showDeclineModal=false;">Yes, Decline Application</button>
            </div>
        </div>
    </div>
</div>


<div x-show="showSearchCustomerModal" class="modal" x-cloak
 x-init="$watch('showSearchCustomerModal', value => { if (!value) searchInput = ''; })"
 x-data="{ searchInput: $wire.searchCustomerQuery }">
<div class="modal-dialog modal-xl custom-modal" role="document">
    <div class="modal-content" @click.away="$wire.resetSearch(); showSearchCustomerModal=false; searchInput=''">
        <div class="modal-header">
            <h5 class="modal-title">Search Customers</h5>
            <span class="close" @click="$wire.resetSearch(); showSearchCustomerModal=false; searchInput=''">&times;</span>
        </div>
        <div class="modal-body">
            <div class="form-group position-relative">
                <label for="searchCustomerQuery">Search by company name or reference</label>
                <input
                    id="searchCustomerQuery"
                    type="text"
                    class="form-control"
                    wire:model.live="searchCustomerQuery"
                    wire:keydown="searchCustomers"
                    x-model="searchInput"
                    placeholder="Enter name or reference"
                    autocomplete="off"
                >
                @if (!empty($searchCustomerResults))
                <ul class="list-group" style="position: absolute; top: 100%; left: 0; right: 0; z-index: 1050; max-height: 180px; overflow-y: auto;">
                    @foreach ($searchCustomerResults as $customer)
                    <li class="list-group-item d-flex justify-content-between align-items-center" wire:click="selectCustomer('{{ $customer['id'] }}')" style="cursor: pointer;" wire:key="customer-{{ $customer['id'] }}">
                        <div>[{{ $customer['reference'] }}] {{ $customer['name'] }}</div>
                    </li>
                    @endforeach
                </ul>
                @endif
            </div>
        </div>
        <div class="modal-footer">
            <a href="#" @click.prevent="$wire.resetSearch(); showSearchCustomerModal=false; searchInput=''">Close</a>
            <button class="btn btn-primary" type="button" wire:click="saveSelectedCustomer" @disabled(!$selectedCustomer)>Save</button>
        </div>
    </div>
</div>
modiparth333-jpg's avatar

modiparth333-jpg wrote a reply+100 XP

5mos ago

Pls help guys

modiparth333-jpg's avatar

modiparth333-jpg started a new conversation+100 XP

5mos ago

modiparth333-jpg's avatar

modiparth333-jpg wrote a reply+100 XP

5mos ago

modiparth333-jpg's avatar

modiparth333-jpg wrote a reply+100 XP

5mos ago

modiparth333-jpg's avatar

modiparth333-jpg started a new conversation+100 XP

5mos ago