From d0dc38571f0b0e5455f83585848b7cced3a2d4cd Mon Sep 17 00:00:00 2001 From: VE10-Sanjeev Date: Fri, 27 Sep 2024 04:46:29 +0000 Subject: [PATCH] FIX_Job Card File Changes --- app/Config/Routes.php | 1 + app/Controllers/Jobcard.php | 63 ++++++++++++++++- app/Models/JobcardFileModel.php | 10 +++ app/Views/job_card_form.php | 117 +++++++++++++++++++++++++++++++- 4 files changed, 189 insertions(+), 2 deletions(-) create mode 100755 app/Models/JobcardFileModel.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index afca9dd..b6cff28 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -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// diff --git a/app/Controllers/Jobcard.php b/app/Controllers/Jobcard.php index 96d9a04..acf8b8f 100755 --- a/app/Controllers/Jobcard.php +++ b/app/Controllers/Jobcard.php @@ -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.']); + } + } + + } diff --git a/app/Models/JobcardFileModel.php b/app/Models/JobcardFileModel.php new file mode 100755 index 0000000..40cc5aa --- /dev/null +++ b/app/Models/JobcardFileModel.php @@ -0,0 +1,10 @@ +
-
" method="post" style="line-height:0.5;"> + " method="post" style="line-height:0.5;" enctype="multipart/form-data"> + @@ -186,6 +187,19 @@
+
+
+
+ +
+
+
+
+
+

Item Details

@@ -2246,6 +2260,107 @@ $closestTR.remove(); $('#mode_of_payment').removeAttr('required'); } }) + $(document).ready(function() { + var jobcardfiles = ; + if (jobcardfiles.length !== 0) { + $.each(jobcardfiles, function(i, item) { + appendExistingFilesFileds(item) + }); + + + } + }); + function appendExistingFilesFileds(data){ + + const 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 = `
+
+ + +
+
+ + +     + +
+
+ `; + + + $('#existingContainer').append(newRowHtml); + } + + function appendFilesFileds(data) { + var newRowHtml = ` +
+
+ + +
+
+ + +
+
+ + +
+
`; + + $('#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: '', // 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() + } + }