Merge branch 'main' of bitbucket.org:venbainformationtechnology/the_mechanic

This commit is contained in:
Smart 2024-09-27 10:47:15 +05:30
commit 3dfd9e5595
4 changed files with 189 additions and 2 deletions

View File

@ -98,6 +98,7 @@ $routes->get("download_jobcard/(:any)", "Jobcard::download_jobcard/$1");
$routes->get("download_os", "Jobcard::download_os");
$routes->get("individual_download_os/(:any)", "Jobcard::individual_download_os/$1");
$routes->post("getServices", "Jobcard::getServices");
$routes->post('deleteJobCardFile', 'Jobcard::deleteJobCardFile');
//End Job Card //
//Client//

View File

@ -22,6 +22,7 @@ use App\Models\SalesOrderModel;
use App\Models\SalesOrderProductModel;
use App\Models\UsersModel;
use App\Models\RoleModel;
use App\Models\JobcardFileModel;
use Mpdf\Mpdf;
use DateTime;
@ -396,6 +397,7 @@ class Jobcard extends BaseController
if ($job_card_id === '0') {
$data['page_name']="Create Job Card";
$data['jobs'] = [];
$data['jobcardfiles'] = [];
$ClientModel = new ClientModel();
$client=$ClientModel
->where('isactive',1)
@ -443,6 +445,7 @@ class Jobcard extends BaseController
$ComplaintModel = new ComplaintModel();
$OutsourceModel = new OutsourceModel();
$ServiceModel = new ServiceModel();
$JobcardFileModel = new JobcardFileModel();
/*** SERVICE DATA ***/
$servicedata = $JobcardModel->service_data($job_card_id, $this->session->get('logged_user_branch_id'));
@ -522,6 +525,8 @@ class Jobcard extends BaseController
$jobs=$JobcardModel->where('job_card_id', $job_card_id)->get()->getRowArray();
$data['jobs']=$jobs;
$jobcardfiles=$JobcardFileModel->where(['job_card_id'=>$job_card_id,'isactive'=>1])->findAll();
$data['jobcardfiles'] = $jobcardfiles;
$VehicleModel = new VehicleModel();
$vehicles = $VehicleModel->where('isactive',1)->where('vehicle_id',$jobs['vehicle_id'])
@ -816,6 +821,31 @@ class Jobcard extends BaseController
if(isset($item->product)) { $this->product_data_insertion($job_card_id, $os_id, $JobcardOSModel, $item, $JobcardProductModel, $status, $rework); }
}
// Get the files from the request
$path = ROOTPATH.'public/uploads/jobcardfiles/';
if(!is_dir($path)) { mkdir($path, 0777, true); }
$filesdetails = $this->request->getFiles();
$manualfilename = $this->request->getPost('manual_file_name'); // Get user-entered file names
if(isset($filesdetails['file']))
{
foreach ($filesdetails['file'] as $index => $file) {
if ($file->isValid() && !$file->hasMoved()) {
// Move the file to the desired directory
$filename = (!empty($file->getName())) ? $file->getName() : $manualfilename[$index] ;
$file->move($path, $filename);
// Store the file information in the database
$uploadFiles = array(
'manual_file_name' => $manualfilename[$index],
'file_name' => $filename,
'job_card_id' => $job_card_id,
'created_by' => $this->session->get('logged_user')
);
$lastInsertFileId = $this->uploadAdditionalFile($uploadFiles);
$this->logger->info("last Insert File Id = ".$lastInsertFileId);
}
}
}
return redirect()->to('job_card_index');
}
@ -1229,5 +1259,36 @@ class Jobcard extends BaseController
}
}
// Check if service exists
function uploadAdditionalFile($myfiles)
{
if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); }
$model = new JobcardFileModel();
$id = $model->insert($myfiles);
$aff = $model->affectedRows();
return $aff > 0 ? $model->insertID() : 0;
}
public function deleteJobCardFile()
{
$file_id = $this->request->getPost('file_id');
$model = new JobcardFileModel();
$where = ['file_id' => $file_id, 'isactive' => 1 ];
$existingFile = $model->where($where)->first();
if ($existingFile) {
$data['isactive'] = 0;
$data['updated_by'] = $this->session->has('logged_user');
if ($model->update($file_id, $data)) {
// session()->setFlashdata('success', 'Deleted successfully.');
return $this->response->setJSON(['success' => true, 'message' => 'File deleted successfully.','file_id'=>$file_id]);
$this->logger->info("job card file : has been deleted successfully. Inactivated ID = ".$file_id);
}
return $this->response->setJSON(['success' => false, 'message' => 'Failed to deleted.']);
}
}
}

10
app/Models/JobcardFileModel.php Executable file
View File

@ -0,0 +1,10 @@
<?php
namespace App\Models;
use CodeIgniter\Model;
class JobcardFileModel extends Model
{
protected $table = 'job_card_file';
protected $primaryKey = 'file_id';
protected $allowedFields = ['file_id','file_name','job_card_id','manual_file_name', 'created_at','created_by','updated_at','updated_by','isactive'];
}

View File

@ -52,7 +52,8 @@
<div class="col-md-12">
<div class="card">
<div class="card-body">
<form id="form-submit" action="<?= base_url() . "add_jobs"; ?>" method="post" style="line-height:0.5;">
<form id="form-submit" action="<?= base_url() . "add_jobs"; ?>" method="post" style="line-height:0.5;" enctype="multipart/form-data">
<input type="hidden" id="product_response" name="products" value="">
<input type="hidden" id="delete_items" name="delete_items" value="">
<input type="hidden" id="issued_items" name="issued_items" value="">
@ -186,6 +187,19 @@
</div>
<?php endif; ?>
</div>
<div class="files">
<div class="form-row">
<div class="form-group col-md-12" style="text-align: right;">
<button type="button" class="btn btn-primary waves-effect btn-sm a1"
onclick="appendFilesFileds()" id="filebtn">
Add File
</button>
</div>
</div>
<div id="existingContainer"></div>
<div id="filesContainer"></div>
</div>
<div class="form-row" id="itemTableContainer">
<div class="form-group col-md-12">
<h4>Item Details</h4>
@ -2246,6 +2260,107 @@ $closestTR.remove();
$('#mode_of_payment').removeAttr('required');
}
})
$(document).ready(function() {
var jobcardfiles = <?php echo isset($jobcardfiles) ? json_encode($jobcardfiles) : array() ?>;
if (jobcardfiles.length !== 0) {
$.each(jobcardfiles, function(i, item) {
appendExistingFilesFileds(item)
});
}
});
function appendExistingFilesFileds(data){
const base_url = '<?php echo base_url(); ?>';
var filePath = data != null && data != '' ? data.file_name : '';
var fileName = data != null && data != '' ? data.manual_file_name : '';
var fileId = data != null && data != '' ? data.file_id : '';
var downloadUrl = `${base_url}public/uploads/jobcardfiles/${filePath}`;
var newRowHtml = `<div class="form-row pad mb-2">
<div class="form-group col-md-4">
<label class="col-form-label">File name</label>
<input type="text" maxlength="255" class="form-control" value="${fileName}" readonly>
</div>
<div class="form-group col-md-8
" style="padding-top:37px;">
<a href="${downloadUrl}" download>
<i class="fa fa-download" aria-hidden="true" style="font-size: 25px;"></i>
</a>&nbsp;&nbsp;&nbsp;
<button type="button" class="btn btn-danger btn-sm a1" data-file-id="${fileId}" onclick="removeContact(this)">
Delete
</button>
</div>
</div>
`;
$('#existingContainer').append(newRowHtml);
}
function appendFilesFileds(data) {
var newRowHtml = `
<div class="form-row pad">
<div class="form-group col-md-4">
<label class="col-form-label">File name</label>
<input type="text" id="manual_file_name" name="manual_file_name[]" maxlength="255" class="form-control" value="${data != null && data != '' ? data.manual_file_name : ''}">
</div>
<div class="form-group col-md-4">
<label class="col-form-label">File</label>
<input type="file" id="file" name="file[]" class="form-control">
</div>
<div class="form-group col-md-4 p-4">
<button type="button" class="btn btn-danger btn-sm" onclick="removeContact(this)">Remove</button>
<button type="button" class="btn btn-primary btn-sm a1" onclick="appendFilesFileds()">Add File</button>
</div>
</div>`;
$('#filesContainer').append(newRowHtml);
$('#filesContainer .a1').hide();
$('#filesContainer .pad:last .a1').show();
var len = $('#filesContainer .pad:last .a1');
var length = (len.length == 0) ? $('#filebtn').show() : $('#filebtn').hide();
}
function removeContact(button) {
console.log(button.getAttribute('data-file-id'));
if (button.getAttribute('data-file-id') != '') {
$.ajax({
url: '<?= base_url("deleteJobCardFile") ?>', // URL to your controller method for fetching models
type: 'POST',
dataType: 'json',
data: { file_id: [button.getAttribute('data-file-id')] },
success: function(response) {
if (response.success) {
toastr.success(response.message);
} else {
toastr.warning(response.message);
}
// return false;
},
error: function(xhr, status, error) {
// toastr.warning("Failed to remove. Please try again");
console.error(error);
// return false;
}
});
}
$(button).closest('.pad').remove();
$('#filesContainer .a1').hide();
$('#filesContainer .pad:last .a1').show();
var len = $('#filesContainer .pad:last .a1')
var length = len.length;
if (length == 0) {
$('#filebtn').show()
} else {
$('#filebtn').hide()
}
}
</script>