145 lines
8.1 KiB
PHP
Executable File
145 lines
8.1 KiB
PHP
Executable File
<?php include('layout/header.php'); ?>
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<div class="page-title-box page-title-box-alt">
|
|
<h4 class="page-title"><?php echo $page_name?></h4>
|
|
<div class="page-title-right">
|
|
<a href="<?= base_url() . "client_index"; ?>" class="btn btn-secondary waves-effect">Cancel</a>
|
|
<ol class="breadcrumb m-0">
|
|
</ol>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-md-12">
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<form id="client_form" method="post">
|
|
<h4 class="header-title">Client Details :</h4>
|
|
<div class="form-row">
|
|
<div class="form-group col-md-4">
|
|
<label for="inputEmail4" class="col-form-label">Client Name<span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" name="client_name" id="client_name" placeholder="Name" value="<?= isset($client['client_name']) ? $client['client_name'] : '' ?>" required>
|
|
</div>
|
|
<div class="form-group col-md-4">
|
|
<label for="inputAddress" class="col-form-label">Mobile<span class="text-danger">*</span></label>
|
|
<span id="mobile_error" style="color:red;"></span>
|
|
<input type="text" class="form-control" name="mobile" id="mobile" placeholder="Mobile" value="<?= isset($client['mobile_no']) ? $client['mobile_no'] : '' ?>" maxlength="16" minlength="6" onkeypress = "return onlyNumbers(event)" required/>
|
|
</div>
|
|
<div class="form-group col-md-4">
|
|
<label for="inputPassword4" class="col-form-label">Client Type<span class="text-danger">*</span></label>
|
|
<select class="form-control status-select" name="clienttype" required data-toggle="select2" >
|
|
<!-- <option value="">Select a Type</option> -->
|
|
<option value="Direct" <?= isset($client['client_type']) && $client['client_type'] === 'Direct' ? 'selected' : '' ?>>Direct</option>
|
|
<option value="Mechanic" <?= isset($client['client_type']) && $client['client_type'] === 'Mechanic' ? 'selected' : '' ?>>Mechanic</option>
|
|
<option value="Exp" <?= isset($client['client_type']) && $client['client_type'] === 'Exp' ? 'selected' : '' ?>>Exp</option>
|
|
|
|
</select>
|
|
</div>
|
|
<div class="form-group col-md-4">
|
|
<label for="inputEmail4" class="col-form-label">Email</label>
|
|
<input type="email" class="form-control" name="email" placeholder="Email" value="<?= isset($client['email']) ? $client['email'] : '' ?>" >
|
|
</div>
|
|
<div class="form-group col-md-4">
|
|
<label for="inputAddress" class="col-form-label">GST Number<span class="text-danger"></span></label>
|
|
<input type="text" class="form-control" name="gstnumber" placeholder="GST Number" value="<?= isset($client['gstnumber']) ? $client['gstnumber'] : '' ?>"pattern="[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]{1}[0-9]{1}[Z]{1}[0-9A-Z]{1}" title="Enter a valid GST Number" />
|
|
</div>
|
|
|
|
</div>
|
|
<input type="hidden" id="client_id" name="client_id" value="<?= isset($client['client_id']) ? $client['client_id'] : '' ?>">
|
|
</br><h4 class="header-title">Address Information :</h4>
|
|
<div class="form-row">
|
|
<div class="form-group col-md-6">
|
|
<label for="inputPassword4" class="col-form-label">Address</label>
|
|
<textarea class="form-control" name="address" placeholder="Address"><?= isset($client['address']) ? $client['address'] : '' ?></textarea>
|
|
|
|
</div>
|
|
<div class="form-group col-md-6">
|
|
<label for="inputPassword4" class="col-form-label">City</label>
|
|
<input type="text" class="form-control" name="city" placeholder="City"value="<?= isset($client['city']) ? $client['city'] : 'Chennai' ?>" >
|
|
</div>
|
|
<div class="form-group col-md-6">
|
|
<label for="inputPassword4" class="col-form-label">State</label>
|
|
<input type="text" class="form-control" name="state" placeholder="State"value="<?= isset($client['state']) ? $client['state'] : 'Tamil Nadu' ?>" >
|
|
</div>
|
|
|
|
<div class="form-group col-md-6">
|
|
<label for="inputPassword4" class="col-form-label">Pin Code</label>
|
|
<input type="text" class="form-control" name="postalcode" placeholder="Pin Code"value="<?= isset($client['postal_code']) ? $client['postal_code'] : '' ?>" maxlength="6" minlength="6">
|
|
</div>
|
|
|
|
</div>
|
|
<button type="submit" id="client_form_submit" class="btn btn-primary" style="float:right;">Submit</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php include('layout/footer.php'); ?>
|
|
|
|
<script>
|
|
function onlyNumbers(event){
|
|
var charcode;
|
|
charcode = event.which || event.keyCode;
|
|
if(charcode>= 48 && charcode <= 57)return true;
|
|
return false;
|
|
}
|
|
|
|
|
|
$('#client_form_submit').click(function (event) {
|
|
event.preventDefault();
|
|
|
|
// action="<?= base_url() . "add_client"; ?>"
|
|
var formData = $('#client_form').serialize();
|
|
const submitButton = $('#client_form_submit');
|
|
var mobile = $('#mobile').val();
|
|
var clientname = $('#client_name').val();
|
|
if (!clientname) {
|
|
toastr.warning("Client Name cannot be empty!");
|
|
$('#client_name').focus();
|
|
submitButton.prop('disabled', false).text('Submit');
|
|
return;
|
|
}
|
|
if (!mobile) {
|
|
toastr.warning("mobile Number cannot be empty!");
|
|
$('#mobile').focus();
|
|
submitButton.prop('disabled', false).text('Submit');
|
|
return;
|
|
}
|
|
submitButton.prop('disabled', true).text('Processing...');
|
|
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: '<?php echo base_url()."add_client"?>',
|
|
data: formData,
|
|
dataType: 'json',
|
|
success: function(response) {
|
|
console.log(response);
|
|
if(response == 'update'){
|
|
toastr.success('Client Updated Succssfully');
|
|
window.location.href = '<?= base_url() . "client_index"; ?>';
|
|
// submitButton.prop('disabled', false).text('Submit');
|
|
}else if(response){
|
|
toastr.success('Client Added Succssfully');
|
|
window.location.href = '<?= base_url() . "client_index"; ?>';
|
|
// submitButton.prop('disabled', false).text('Submit');
|
|
}else{
|
|
toastr.warning('Mobile number already exists');
|
|
$('#mobile_error').html('Mobile number already exists');
|
|
$('#mobile').css('border', '1px solid red');
|
|
$('#mobile').focus();
|
|
setTimeout(() => {
|
|
$('#mobile').css('border', '1px solid #ced4da');
|
|
}, 2000);
|
|
submitButton.prop('disabled', false).text('Submit');
|
|
}
|
|
},
|
|
error: function(xhr, status, error) {
|
|
// Handle error response here
|
|
console.error(xhr.responseText);
|
|
}
|
|
});
|
|
})
|
|
|
|
</script>
|