stock module latest today vadivel J 04-02-2025
This commit is contained in:
parent
e0adcd1a9f
commit
b93073e96d
@ -450,8 +450,7 @@ $routes->post('getSilicaIGR', 'Supplier::getSilicaIGR');
|
|||||||
$routes->match(['GET', 'POST'], 'coatingMachineDetails', 'StockController::loadView_coatingMachineDetails');
|
$routes->match(['GET', 'POST'], 'coatingMachineDetails', 'StockController::loadView_coatingMachineDetails');
|
||||||
$routes->post('addNewCoatingMachineDetails', 'StockController::addNewCoatingMachineDetails');
|
$routes->post('addNewCoatingMachineDetails', 'StockController::addNewCoatingMachineDetails');
|
||||||
$routes->post('updateCoatingMachineDetails', 'StockController::updateCoatingMachineDetails');
|
$routes->post('updateCoatingMachineDetails', 'StockController::updateCoatingMachineDetails');
|
||||||
$routes->get('deleteCoatingMachineDetails', 'StockController::deleteCoatingMachineDetails');
|
$routes->post('deleteBatchCardFile','StockController::deleteBatchCardFile');
|
||||||
|
|
||||||
|
|
||||||
//drier machine details
|
//drier machine details
|
||||||
$routes->match(['GET', 'POST', 'PUT', 'DELETE'], 'drierMachineDetails', 'StockController::drierMachineDetails');
|
$routes->match(['GET', 'POST', 'PUT', 'DELETE'], 'drierMachineDetails', 'StockController::drierMachineDetails');
|
||||||
|
|||||||
@ -149,12 +149,21 @@ class StockController extends BaseController
|
|||||||
$startDate = "$month-01";
|
$startDate = "$month-01";
|
||||||
$endDate = date("Y-m-t", strtotime($startDate));
|
$endDate = date("Y-m-t", strtotime($startDate));
|
||||||
$data['coatingMachineDetails'] = $this->coatingMachineDetails_model
|
$data['coatingMachineDetails'] = $this->coatingMachineDetails_model
|
||||||
->select('t_coatingMachineDetails.*, t_batchcard_files.*') // Select required fields
|
->select('t_coatingMachineDetails.*,
|
||||||
->join('t_batchcard_files', 't_batchcard_files.coating_id = t_coatingMachineDetails.id', 'left')
|
JSON_ARRAYAGG(
|
||||||
->where('t_coatingMachineDetails.date >=', $startDate)
|
JSON_OBJECT(
|
||||||
->where('t_coatingMachineDetails.date <=', $endDate)
|
"client_given_name", t_batchcard_files.client_file_name,
|
||||||
->orderBy('t_coatingMachineDetails.date', 'asc')
|
"filename", t_batchcard_files.filename,
|
||||||
->findAll();
|
"batchCardId" , t_batchcard_files.id
|
||||||
|
)
|
||||||
|
) as batchcard_files')
|
||||||
|
->join('t_batchcard_files', 't_batchcard_files.coating_id = t_coatingMachineDetails.id', 'left')
|
||||||
|
->where('t_coatingMachineDetails.date >=', $startDate)
|
||||||
|
->where('t_coatingMachineDetails.date <=', $endDate)
|
||||||
|
->groupBy('t_coatingMachineDetails.id')
|
||||||
|
->orderBy('t_coatingMachineDetails.date', 'asc')
|
||||||
|
->findAll();
|
||||||
|
|
||||||
|
|
||||||
$date = DateTime::createFromFormat('Y-m', $month);
|
$date = DateTime::createFromFormat('Y-m', $month);
|
||||||
|
|
||||||
@ -268,6 +277,8 @@ class StockController extends BaseController
|
|||||||
|
|
||||||
public function updateCoatingMachineDetails()
|
public function updateCoatingMachineDetails()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
$message1 = '';
|
$message1 = '';
|
||||||
$message2 = '';
|
$message2 = '';
|
||||||
$message3 = '';
|
$message3 = '';
|
||||||
@ -282,6 +293,40 @@ class StockController extends BaseController
|
|||||||
$this->db->transBegin();
|
$this->db->transBegin();
|
||||||
try {
|
try {
|
||||||
$updated = $this->coatingMachineDetails_model->update($id, $putData);
|
$updated = $this->coatingMachineDetails_model->update($id, $putData);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if ($updated !== false && $updated > 0) { // Assuming $id is the record ID being updated
|
||||||
|
|
||||||
|
$batchCardFiles = $this->request->getFileMultiple('batchCard');
|
||||||
|
|
||||||
|
|
||||||
|
// Step 4: Upload new files and insert into DB
|
||||||
|
foreach ($batchCardFiles as $index => $file) {
|
||||||
|
|
||||||
|
if ( !empty($batchCardFiles[$index]) && !($batchCardFiles[$index]->getError() === UPLOAD_ERR_NO_FILE)) {
|
||||||
|
|
||||||
|
$db = \Config\Database::connect();
|
||||||
|
$builder = $db->table('t_batchcard_files');
|
||||||
|
|
||||||
|
if ($file->isValid() && !$file->hasMoved()) {
|
||||||
|
$clientGivenName = $file->getClientName(); // User-given filename
|
||||||
|
$newName = $file->getRandomName(); // Randomized unique filename
|
||||||
|
|
||||||
|
// Move the new file to storage
|
||||||
|
if ($file->move(WRITEPATH . 'uploads/batchcard', $newName)) {
|
||||||
|
// Insert new file record into the database
|
||||||
|
$data = [
|
||||||
|
'client_file_name' => $clientGivenName,
|
||||||
|
'filename' => $newName,
|
||||||
|
'coating_id' => $id
|
||||||
|
];
|
||||||
|
$builder->insert($data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($updated !== false && $updated > 0) {
|
if ($updated !== false && $updated > 0) {
|
||||||
$message1 = "successfully updated Coating machineDetail .";
|
$message1 = "successfully updated Coating machineDetail .";
|
||||||
@ -289,7 +334,7 @@ class StockController extends BaseController
|
|||||||
$dateToBeUpdated = $putData['date'];
|
$dateToBeUpdated = $putData['date'];
|
||||||
|
|
||||||
$existingCoatingGasConsumption = $putData['existingTotalGasConsumption'];
|
$existingCoatingGasConsumption = $putData['existingTotalGasConsumption'];
|
||||||
$updatedCoatingGasConsumption = $putData['totalGasConsumption'];
|
$updatedCoatingGasConsumption = $putData['totalGasConsumption'];
|
||||||
|
|
||||||
if ($existingCoatingGasConsumption != $updatedCoatingGasConsumption) {
|
if ($existingCoatingGasConsumption != $updatedCoatingGasConsumption) {
|
||||||
|
|
||||||
@ -321,59 +366,7 @@ class StockController extends BaseController
|
|||||||
} else {
|
} else {
|
||||||
throw new \Exception('Failed to update Coating machine details.');
|
throw new \Exception('Failed to update Coating machine details.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($updated !== false && $updated > 0) { // Assuming $id is the record ID being updated
|
|
||||||
|
|
||||||
$batchCardFiles = $this->request->getFileMultiple('batchCard');
|
|
||||||
|
|
||||||
if (!empty($batchCardFiles) && !($batchCardFiles[0]->getError() === UPLOAD_ERR_NO_FILE)) {
|
|
||||||
|
|
||||||
// Optional: Delete only files that need to be replaced (if you have a way to identify which are replaced)
|
|
||||||
// Step 1: Fetch existing files linked with the $coating_id
|
|
||||||
$db = \Config\Database::connect();
|
|
||||||
$builder = $db->table('t_batchcard_files');
|
|
||||||
$oldFiles = $builder->where('coating_id', $id)->findAll();
|
|
||||||
|
|
||||||
// Step 2: Upload new files and save them in the database
|
|
||||||
foreach ($batchCardFiles as $file) {
|
|
||||||
if ($file->isValid() && !$file->hasMoved()) {
|
|
||||||
$clientGivenName = $file->getClientName(); // User-given filename
|
|
||||||
$newName = $file->getRandomName();
|
|
||||||
|
|
||||||
// Check if the new file is different from the old ones (if needed)
|
|
||||||
$isNewFile = true;
|
|
||||||
foreach ($oldFiles as $oldFile) {
|
|
||||||
if ($oldFile['filename'] === $newName) {
|
|
||||||
$isNewFile = false; // File already exists, skip uploading
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($isNewFile) {
|
|
||||||
// Move the new file and save to DB
|
|
||||||
if ($file->move(WRITEPATH . 'uploads/batchcard', $newName)) {
|
|
||||||
$data = [
|
|
||||||
'client_file_name' => $clientGivenName,
|
|
||||||
'filename' => $newName,
|
|
||||||
'coating_id' => $id
|
|
||||||
];
|
|
||||||
$builder->insert($data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
foreach ($oldFiles as $oldFile) {
|
|
||||||
$filePath = WRITEPATH . 'uploads/batchcard/' . $oldFile['filename'];
|
|
||||||
if (file_exists($filePath)) {
|
|
||||||
unlink($filePath); // Delete old file from storage
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -384,23 +377,56 @@ class StockController extends BaseController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteCoatingMachineDetails()
|
public function deleteBatchCardFile()
|
||||||
{
|
{
|
||||||
|
$data = $this->request->getPost();
|
||||||
$id = $this->request->getGet('id');
|
|
||||||
|
if (!empty($data)) {
|
||||||
$data['is_active'] = 0;
|
|
||||||
|
$batchId = $data['id'];
|
||||||
$updated = $this->coatingMachineDetails_model->update($id, $data);
|
$db = \Config\Database::connect();
|
||||||
|
$builder = $db->table('t_batchcard_files');
|
||||||
if ($updated) {
|
|
||||||
// Set flashdata for success message
|
// Step 1: Fetch the filename from DB before deleting
|
||||||
return redirect()->to('/coatingMachineDetails')->with('success', 'Coating Machine details deleted successfully');
|
$fileRecord = $builder->select('filename')->where('id', $batchId)->get()->getRow();
|
||||||
} else {
|
|
||||||
// Set flashdata for error message
|
if ($fileRecord) {
|
||||||
return redirect()->back()->with('error', 'Failed to delete Coating machine details');
|
$filePath = WRITEPATH . 'uploads/batchcard/' . $fileRecord->filename;
|
||||||
|
|
||||||
|
// Step 2: Delete the file from storage
|
||||||
|
if (file_exists($filePath)) {
|
||||||
|
unlink($filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 3: Delete the record from the database
|
||||||
|
$sql = "DELETE FROM t_batchcard_files WHERE id = ?";
|
||||||
|
$deleted = $db->query($sql, [$batchId]);
|
||||||
|
|
||||||
|
if ($deleted) {
|
||||||
|
return $this->response->setJSON([
|
||||||
|
'status' => '200',
|
||||||
|
'message' => "Deleted Batch Card File Successfully..!!"
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
return $this->response->setJSON([
|
||||||
|
'status' => '400',
|
||||||
|
'message' => "Failed to Delete..!! Try Again Later"
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return $this->response->setJSON([
|
||||||
|
'status' => '404',
|
||||||
|
'message' => "File Not Found..!!"
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this->response->setJSON([
|
||||||
|
'status' => '400',
|
||||||
|
'message' => "Invalid Request..!!"
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//incoming Silica Sand Details starts
|
//incoming Silica Sand Details starts
|
||||||
public function loadView_incomingSilicaSandDetails()
|
public function loadView_incomingSilicaSandDetails()
|
||||||
|
|||||||
@ -13,7 +13,7 @@ class CoatingMachineDetailsModel extends Model
|
|||||||
protected $useSoftDeletes = false;
|
protected $useSoftDeletes = false;
|
||||||
protected $protectFields = true;
|
protected $protectFields = true;
|
||||||
protected $allowedFields = ['shift','machineOnTime','machineOffTime','totalCoating','date',
|
protected $allowedFields = ['shift','machineOnTime','machineOffTime','totalCoating','date',
|
||||||
'machineRunningInHrs' , 'perHourCoatingSandQTY' , 'perHourGasConsumption' ,'grade','batchCard',
|
'machineRunningInHrs' , 'perHourCoatingSandQTY' , 'perHourGasConsumption' ,'grade',
|
||||||
'totalCoatingSandInKg','totalGasConsumption','customerName', 'is_active','created_at','updated_at'];
|
'totalCoatingSandInKg','totalGasConsumption','customerName', 'is_active','created_at','updated_at'];
|
||||||
|
|
||||||
protected bool $allowEmptyInserts = false;
|
protected bool $allowEmptyInserts = false;
|
||||||
|
|||||||
@ -341,6 +341,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
if (!empty($coatingMachineDetails)) {
|
if (!empty($coatingMachineDetails)) {
|
||||||
|
|
||||||
$summary = [] ;
|
$summary = [] ;
|
||||||
|
|
||||||
foreach ($coatingMachineDetails as $record) {
|
foreach ($coatingMachineDetails as $record) {
|
||||||
@ -392,6 +393,8 @@
|
|||||||
</a>
|
</a>
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
|
<!-- td:eq(13) -->
|
||||||
|
<td style="display:none;"><?php echo $record['batchcard_files'] ?? ' ' ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
|
||||||
@ -703,7 +706,7 @@
|
|||||||
<button type="button" class="btn btn-success btn-sm mt-2" id="batchCardAddBtnId">Add More</button>
|
<button type="button" class="btn btn-success btn-sm mt-2" id="batchCardAddBtnId">Add More</button>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -911,16 +914,23 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-row">
|
<div class="form-row" id="editBatchCardRowId">
|
||||||
|
|
||||||
<!-- batch card file upload -->
|
<!-- batch card file upload -->
|
||||||
<div class="form-group col-md-3">
|
<div class="form-group col-md-3">
|
||||||
<label for="editBatchCardId">upload batch card</label>
|
|
||||||
<span class="badge mandatory">*</span>
|
<label for="editBatchCardId">Upload Batch Card</label>
|
||||||
<input type="file" class="" id="editBatchCardId" name="batchCard"
|
|
||||||
value="" required >
|
<div>
|
||||||
|
<input type="file" class="editBatchFile " name="batchCard[]">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type="button" class="btn btn-success btn-sm mt-2" id="editBatchCardAddBtnId">Add More</button>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -1224,14 +1234,43 @@
|
|||||||
var totalGasConsumption = row.find('td:eq(9)').text();
|
var totalGasConsumption = row.find('td:eq(9)').text();
|
||||||
var perHourGasConsumption = row.find('td:eq(10)').text();
|
var perHourGasConsumption = row.find('td:eq(10)').text();
|
||||||
var perHourCoatingSandQTY = row.find('td:eq(11)').text();
|
var perHourCoatingSandQTY = row.find('td:eq(11)').text();
|
||||||
|
var batchCards = row.find('td:eq(13)').text().trim();
|
||||||
|
|
||||||
|
console.log(batchCards);
|
||||||
|
|
||||||
|
JSON.parse(batchCards).map(element => {
|
||||||
|
|
||||||
|
if(!element.client_given_name){
|
||||||
|
console.log("filename null")
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let fileCount = $('.editBatchFile').length; // Count existing batch files
|
||||||
|
|
||||||
|
if (fileCount >= 5) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let string = `<div class="form-group col-md-3 batch-container">
|
||||||
|
<label for="">Change Batch Card</label>
|
||||||
|
<input type="file" class="editBatchFile additionalBatchFile" name="batchCard[]" >
|
||||||
|
<p>( Previously Uploaded File ${element.client_given_name} )</p>
|
||||||
|
<button type="button" class="btn btn-danger btn-sm mt-2 removeBatch" data-id="${element.batchCardId}">Remove</button>
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
$('#editBatchCardRowId').append(string)
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
// Fill the modal fields with the values
|
// Fill the modal fields with the values
|
||||||
|
|
||||||
|
//batchfile
|
||||||
|
|
||||||
|
|
||||||
$('#editCoatingMachineDetailId').val(row.data('id'));
|
$('#editCoatingMachineDetailId').val(row.data('id'));
|
||||||
$('#editCustomerNameId').val(customerName);
|
$('#editCustomerNameId').val(customerName);
|
||||||
$('#editDateId').val(date); //convert this from d-m-y to Y-m-d in javascript
|
$('#editDateId').val(date); //convert this from d-m-y to Y-m-d in javascript
|
||||||
$('#editShiftId').val(shift);
|
$('#editShiftId').val(shift);
|
||||||
$('#editMachineOnTimeHrId').val(machineOnTimeHr).change();
|
$('#editMachineOnTimeHrId').val(machineOnTimeHr).change();
|
||||||
$('#editMachineOffTimeHrId').val(machineOffTimeHr).change();
|
$('#editMachineOffTimeHrId').val(machineOffTimeHr).change();
|
||||||
@ -1252,6 +1291,16 @@
|
|||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
$(document).ready(function(){
|
||||||
|
$('#editCoatingMachineDetailModal').on('hidden.bs.modal', function () {
|
||||||
|
$('.batch-container').remove(); // This will remove all child elements
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
<!-- calculations for some fields needed in onChange while adding coating machine details -->
|
<!-- calculations for some fields needed in onChange while adding coating machine details -->
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@ -1610,4 +1659,47 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$(document).ready(function () {
|
||||||
|
$('#editBatchCardAddBtnId').click(function () {
|
||||||
|
|
||||||
|
let fileCount = $('.editBatchFile').length; // Count existing batch files
|
||||||
|
|
||||||
|
if (fileCount >= 5) { // Set your limit here (e.g., max 5 files)
|
||||||
|
alert("You can only upload up to 5 batch files.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let string = `<div class="form-group col-md-3 batch-container">
|
||||||
|
<label for="">Upload Batch Card</label>
|
||||||
|
<input type="file" class="editBatchFile" name="batchCard[]" >
|
||||||
|
<button type="button" class="btn btn-danger btn-sm mt-2 removeBatch">Remove</button>
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
$('#editBatchCardRowId').append(string);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Remove batch card field dynamically
|
||||||
|
$(document).on('click', '.removeBatch', function () {
|
||||||
|
let batchId = this.getAttribute('data-id'); // Get the data-id
|
||||||
|
|
||||||
|
if (confirm("Are you sure you want to delete this batch file?")) {
|
||||||
|
$.ajax({
|
||||||
|
url: "<?php echo base_url();?>/deleteBatchCardFile",
|
||||||
|
type: "POST",
|
||||||
|
data: { id: batchId },
|
||||||
|
success: function (response) {
|
||||||
|
if(response.status == "200"){
|
||||||
|
alert("Batch file deleted successfully!");
|
||||||
|
$(this).closest('.batch-container').remove(); // Remove from UI
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function (xhr, status, error) {
|
||||||
|
alert("Error deleting batch file: " + error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
Loading…
Reference in New Issue
Block a user