cubiccentimeter changes

This commit is contained in:
VE10-Sanjeev 2025-01-28 04:44:49 +00:00
parent 7a9e898c6a
commit d1fe31630c
3 changed files with 80 additions and 20 deletions

View File

@ -20,8 +20,10 @@ class Complaint extends BaseController
if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); }
$ComplaintModel = new ComplaintModel();
$complaint = $ComplaintModel->findAll();
$cubiccentimeter = $ComplaintModel->getCubicCentimeterName();
$data['complaint']=$complaint;
$data['cubiccentimeter']=$cubiccentimeter;
return view('complaint_list',$data);
}
@ -30,14 +32,21 @@ class Complaint extends BaseController
if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); }
try {
$name = $this->request->getPost('name');
$cubic_centimeter_id = $this->request->getPost('cubic_centimeter_id');
// echo $cubic_centimeter_id; die;
$ComplaintModel = new ComplaintModel();
if ($complaint_id>0) {
$complaint = $ComplaintModel->where(['name' => $name, 'isactive' => 1])
->where('complaint_id !=', $complaint_id)
->findAll();
} else {
$complaint = $ComplaintModel->where(['name' => $name, 'isactive' => 1])->findAll();
}
$conditions = ['name' => $name, 'isactive' => 1];
if ($cubic_centimeter_id) {
$conditions['cubic_centimeter_id'] = $cubic_centimeter_id;
}
if ($complaint_id > 0) {
$ComplaintModel->where('complaint_id !=', $complaint_id);
}
$complaint = $ComplaintModel->where($conditions)->findAll();
if (!empty($complaint)) {
$result = "Name Already Exist";
return $this->respond(['status' => 'failed','code' => 404,'data' => $result], 200);
@ -50,6 +59,7 @@ class Complaint extends BaseController
"cgst" => $this->request->getPost('tax')/2,
"sgst" => $this->request->getPost('tax')/2,
"tax" => $this->request->getPost('tax'),
"cubic_centimeter_id" => $this->request->getPost('cubic_centimeter_id') ? $this->request->getPost('cubic_centimeter_id') : 0,
];
if (!$complaint_id) {

View File

@ -5,5 +5,14 @@ class ComplaintModel extends Model
{
protected $table = 'complaints';
protected $primaryKey = 'complaint_id';
protected $allowedFields = ['complaint_id','business_id','name','labour_charge','cgst','sgst','tax','labour_cost_with_tax','isactive'];
protected $allowedFields = ['complaint_id','business_id','name','labour_charge','cgst','sgst','tax','labour_cost_with_tax','isactive','cubic_centimeter_id'];
public function getCubicCentimeterName()
{
return $this->db->table('cubic_centimeter')
->select('cubic_centimeter.*')
->where('cubic_centimeter.isactive', 1)
->get()
->getResultArray();
}
}

View File

@ -32,9 +32,18 @@
$color = '';
if($value['isactive'] == 0){
$color ='red';
}?>
<tr class="complaint_tr_<?php echo $index+1; ?>" style="color:<?php echo $color; ?>" > <td><?= $value['name']; ?></td>
<td><?= $value['labour_cost_with_tax']; ?></td>
}
$cubiccentimeter_name = ''; // Default to empty if no match
// Loop through $cubiccentimeter to find a match
foreach ($cubiccentimeter as $cc) {
if ($cc['id'] == $value['cubic_centimeter_id']) {
$cubiccentimeter_name = ' ( '.$cc['value'].' )'; // Get the name of the matching cubiccentimeter
break;
}
}
?>
<tr class="complaint_tr_<?php echo $index+1; ?>" style="color:<?php echo $color; ?>" > <td><?= $value['name'].$cubiccentimeter_name;; ?></td>
<td><?= $value['labour_cost_with_tax'] ?></td>
<td><?= $value['tax']; ?></td>
<td><?= $value['labour_charge']; ?></td>
<td hidden>
@ -81,6 +90,15 @@
<input class="form-control" type="text" id="complaint_id" hidden>
<input class="form-control" type="text" id="name" required="" placeholder="Complaint">
</div>
<div class="form-group">
<label for="cubic_centimeter">Cubic Centimeter</label>
<select class="form-control" id="cubic_centimeter" name="cubic_centimeter" required data-toggle="select2">
<option value="0">Select Cubic Centimeter</option>
<?php foreach ($cubiccentimeter as $item): ?>
<option value="<?= $item['id'] ?>"><?= $item['value'] ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<label for="labour_cost_with_tax">Unit Price (Including Tax)</label>
<input class="form-control" type="number" id="labour_cost_with_tax" name="labour_cost_with_tax" placeholder="Total Price" step="0.01" min="0" onkeyup="ReverseCalculation()" required>
@ -111,27 +129,41 @@
<script>
function ReverseCalculation() {
var tax = parseFloat($("#tax").val());
if(tax == ''){
toastr.warning('Please select Tax', 'Warning');
}else{
var labour_cost_with_tax = parseFloat($("#labour_cost_with_tax").val());
var labour_cost = labour_cost_with_tax / parseFloat((tax / 100) + 1);
$("#labour_charge").val(labour_cost.toFixed(2));
if(labour_cost_with_tax == ''){
toastr.warning('Please select Tax', 'Warning');
return;
}else{
var labour_cost_with_tax = parseFloat($("#labour_cost_with_tax").val());
var labour_cost = labour_cost_with_tax / parseFloat((tax / 100) + 1);
$("#labour_charge").val(labour_cost.toFixed(2));
}
}
function submitComplaint(params) {
// console.log(':)',$('#cubic_centimeter_id').val());return false;
if (!$('#name').val() || !$('#labour_charge').val()) {
return false;
}
console.log($('#cubic_centimeter_id').val());
var tax = parseFloat($("#tax").val());
var labour_cost_with_tax = parseFloat($("#labour_cost_with_tax").val());
if(labour_cost_with_tax == '' || tax == ''){
toastr.warning('Please select Tax', 'Warning');
return;
}
// if($(!'#cubic_centimeter').val()){
// toastr.warning('Please select Cubic Centimeter', 'Warning');
// return;
// }
var formData = {
name: $('#name').val(),
labour_charge: $('#labour_charge').val(),
tax: $('#tax').val(),
labour_cost_with_tax: $('#labour_cost_with_tax').val(),
tax: tax,
labour_cost_with_tax: labour_cost_with_tax,
cubic_centimeter_id: $('#cubic_centimeter').val(),
};
var complaint_id = $('#complaint_id').val();
if (!complaint_id) {
@ -184,6 +216,7 @@
$('#name').val(response.complaint[0].name);
$('#labour_charge').val(response.complaint[0].labour_charge);
$('#labour_cost_with_tax').val(response.complaint[0].labour_cost_with_tax);
var cc_id = response.complaint[0].cubic_centimeter_id;
var tax = parseFloat(response.complaint[0].cgst) + parseFloat(response.complaint[0].sgst);
var selectElement = document.getElementById('tax');
@ -194,6 +227,14 @@
break;
}
}
var selectElementForCC = document.getElementById('cubic_centimeter');
var ccOptions = selectElementForCC.options;
for (var j = 0; j < ccOptions.length; j++) {
if (ccOptions[j].value === cc_id) {
ccOptions[j].selected = true;
break;
}
}
},
error: function(xhr, status, error) {
// Handle error response here