stock module latest today vadivel J 03-02-2025

This commit is contained in:
vadivelJ96 2025-02-03 18:30:14 +05:30
parent ee0c93d73e
commit 81631bb055
3 changed files with 257 additions and 64 deletions

View File

@ -149,11 +149,12 @@ class StockController extends BaseController
$startDate = "$month-01";
$endDate = date("Y-m-t", strtotime($startDate));
$data['coatingMachineDetails'] = $this->coatingMachineDetails_model
->where('date >=', $startDate)
->where('date <=', $endDate)
->where('is_active', 1)
->orderBy('date', 'asc')
->findAll();
->select('coating_machine_details.*, t_batchcard_files.filename') // Select required fields
->join('t_batchcard_files', 't_batchcard_files.coating_id = coating_machine_details.id', 'left')
->where('coating_machine_details.date >=', $startDate)
->where('coating_machine_details.date <=', $endDate)
->orderBy('coating_machine_details.date', 'asc')
->findAll();
$date = DateTime::createFromFormat('Y-m', $month);
@ -193,9 +194,9 @@ class StockController extends BaseController
try {
// Insert into coating machine details table
$inserted = $this->coatingMachineDetails_model->insert($postData);
$insertedId = $this->coatingMachineDetails_model->insert($postData);
if ($inserted !== false && $inserted > 0) {
if ($insertedId !== false && $insertedId > 0) {
$message1 = 'Coating Machine details updated successfully';
@ -214,6 +215,35 @@ class StockController extends BaseController
throw new \Exception('Failed to insert Coating machine details.');
}
if ($insertedId !== false && $insertedId > 0) {
$batchCardFiles = $this->request->getFileMultiple('batchCard');
if (!empty($batchCardFiles) && !($batchCardFiles[0]->getError() === UPLOAD_ERR_NO_FILE)) {
foreach ($batchCardFiles as $file) {
if ($file->isValid() && !$file->hasMoved()) {
$newName = $file->getRandomName();
if ($file->move(WRITEPATH . 'uploads/batchcard', $newName)) {
// Only save to DB if file moved successfully
$db = \Config\Database::connect();
$builder = $db->table('t_batchcard_files');
$data = [
'filename' => $newName,
'coating_id' => $insertedId
];
$builder->insert($data);
}
}
}
}
}
if ($this->db->transStatus() === false) {
@ -250,6 +280,7 @@ class StockController extends BaseController
$this->db->transBegin();
try {
$updated = $this->coatingMachineDetails_model->update($id, $putData);
if ($updated !== false && $updated > 0) {
$message1 = "successfully updated Coating machineDetail .";
//update Gas stock consumption if update is successfull..!!
@ -288,6 +319,66 @@ class StockController extends BaseController
} else {
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()) {
$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 = [
'filename' => $newName,
'coating_id' => $id
];
$builder->insert($data);
}
}
}
}
// Optional: Remove old files only if necessary (based on your criteria)
// Example: Delete old files if you no longer need them
// In this example, we're keeping old files that were not replaced.
foreach ($oldFiles as $oldFile) {
$filePath = WRITEPATH . 'uploads/batchcard/' . $oldFile['filename'];
if (file_exists($filePath)) {
unlink($filePath); // Delete old file from storage
}
}
// After this, you would have:
// - New files uploaded
// - Only new files added to the database
// - Optionally, old files removed
}
}
} catch (\Exception $error) {
$this->db->transRollback();
return redirect()->back()->with('error', ' ' . $error->getMessage());

View File

@ -13,7 +13,7 @@ class CoatingMachineDetailsModel extends Model
protected $useSoftDeletes = false;
protected $protectFields = true;
protected $allowedFields = ['shift','machineOnTime','machineOffTime','totalCoating','date',
'machineRunningInHrs' , 'perHourCoatingSandQTY' , 'perHourGasConsumption' ,
'machineRunningInHrs' , 'perHourCoatingSandQTY' , 'perHourGasConsumption' ,'grade','batchCard',
'totalCoatingSandInKg','totalGasConsumption','customerName', 'is_active','created_at','updated_at'];
protected bool $allowEmptyInserts = false;

View File

@ -327,12 +327,13 @@
<th class="celda_encabezado_general" style="padding: 10px;">Machine On Time</th>
<th class="celda_encabezado_general" style="padding: 10px;">Machine Off Time</th>
<th class="celda_encabezado_general" style="padding: 10px;">Machine Running(hr)</th>
<th class="celda_encabezado_general" style="padding: 10px;">Customer Name</th>
<th class="celda_encabezado_general" style="padding: 10px;">Grade</th>
<th class="celda_encabezado_general" style="padding: 10px;">Total Coating</th>
<th class="celda_encabezado_general" style="padding: 10px;">Total Coating Sand(kg)</th>
<th class="celda_encabezado_general" style="padding: 10px;">Total Gas Consumption</th>
<th class="celda_encabezado_general" style="padding: 10px;">Hour Gas</th>
<th class="celda_encabezado_general" style="padding: 10px;">Hour QTY(kg)</th>
<th class="celda_encabezado_general" style="padding: 10px;">Customer Name</th>
<th class="celda_encabezado_general" style="padding: 10px;">Action</th>
</tr>
</thead>
@ -357,18 +358,31 @@
<?php
$date = DateTime::createFromFormat('Y-m-d', $record['date'])->format('d-m-Y');
?>
<!-- td:eq(0) -->
<td class="celda_normal"><?php echo $date ?></td>
<!-- td:eq(1) -->
<td class="celda_normal"><?php echo $record['shift'] ?></td>
<!-- td:eq(2) -->
<td class="celda_normal"><?php echo $record['machineOnTime'] ?></td>
<!-- td:eq(3) -->
<td class="celda_normal"><?php echo $record['machineOffTime'] ?></td>
<td class="celda_normal"><?php echo $record['machineRunningInHrs'] ?? '' ?></td>
<!-- td:eq(4) -->
<td class="celda_normal"><?php echo $record['machineRunningInHrs'] ?? ' ' ?></td>
<!-- td:eq(5) -->
<td class="celda_normal"><?php echo $record['customerName'] ?? '' ?></td>
<!-- td:eq(6) -->
<td class="celda_normal"><?php echo $record['grade'] ?? ' ' ?></td>
<!-- td:eq(7) -->
<td class="celda_normal"><?php echo $record['totalCoating'] ?></td>
<!-- td:eq(8) -->
<td class="celda_normal"><?php echo $record['totalCoatingSandInKg'] ?></td>
<!-- td:eq(9) -->
<td class="celda_normal"><?php echo $record['totalGasConsumption'] ?></td>
<!-- td:eq(10) -->
<td class="celda_normal"><?php echo $record['perHourGasConsumption'] ?? '' ?></td>
<!-- td:eq(11) -->
<td class="celda_normal"><?php echo $record['perHourCoatingSandQTY'] ?? '' ?></td>
<td class="celda_normal"><?php echo $record['customerName']; ?></td>
<!-- td:eq(12) -->
<td class="celda_normal" style="background-color:white;">
<a data-toggle="tooltip" class="edit-btn"
data-target="editCoatingMachineDetailModal" data-toggle="modal"
@ -389,14 +403,16 @@
if (!isset($summary['totalCoating'])) {
$summary['totalMachineRunningHrs'] = 0 ;
$summary['totalCoating'] = 0 ;
$summary['totalCoatingSandInKg'] = 0 ;
$summary['totalGasConsumption'] = 0 ;
$summary['perHourGasConsumption'] = 0 ;
$summary['perHourGasConsumption'] = 0 ;
$summary['perHourCoatingSandQTY'] = 0 ;
}
$summary['totalMachineRunningHrs'] += $record['machineRunningInHrs'] == "-" ? 0 : (float) $record['machineRunningInHrs'];
$summary['totalCoating'] += $record['totalCoating'] == "-" ? 0 : (float) $record['totalCoating'] ;
$summary['totalCoatingSandInKg'] += $record['totalCoatingSandInKg'] == "-" ? 0 : (float) $record['totalCoatingSandInKg'] ;
$summary['totalGasConsumption'] += $record['totalGasConsumption'] == "-" ? 0 :(float) $record['totalGasConsumption'] ;
@ -415,6 +431,8 @@
<th class="celda_encabezado_total" style="padding: 10px;">Machine On Time</th>
<th class="celda_encabezado_total" style="padding: 10px;">Machine Off Time</th>
<th class="celda_encabezado_total" style="padding: 10px;">Machine Running(hr)</th>
<th class="celda_encabezado_total" style="padding: 10px;">Customer Name </th>
<th class="celda_encabezado_total" style="padding: 10px;">Grade</th>
<th class="celda_encabezado_total" style="padding: 10px;">Total Coating</th>
<th class="celda_encabezado_total" style="padding: 10px;">Total Coating Sand(kg)</th>
<th class="celda_encabezado_total" style="padding: 10px;">Total Gas Consumption</th>
@ -434,12 +452,14 @@
<td class="celda_normal "> - </td>
<td class="celda_normal "> - </td>
<td class="celda_normal "> - </td>
<td class="celda_normal "> <?=$summary['totalMachineRunningHrs']?></td>
<td class="celda_normal "> - </td>
<td class="celda_normal "> - </td>
<td class="celda_normal "><?=$summary['totalCoating']?></td>
<td class="celda_normal "><?=$summary['totalCoatingSandInKg']?></td>
<td class="celda_normal "><?=$summary['totalGasConsumption']?></td>
<td class="celda_normal "><?=$summary['perHourGasConsumption']?></td>
<td class="celda_normal "><?=$summary['perHourCoatingSandQTY']?></td>
<td class="celda_normal "><?=number_format($summary['totalGasConsumption']/$summary['totalMachineRunningHrs'], 2)?> (avg)</td>
<td class="celda_normal "><?=number_format($summary['totalCoatingSandInKg']/$summary['totalMachineRunningHrs'], 2)?> (avg)</td>
</tr>
</tbody>
@ -492,7 +512,9 @@
</div>
<!-- form -->
<form method="post" action="<?php echo base_url(); ?>addNewCoatingMachineDetails?month=<?= $month; ?>">
<form method="post"
enctype="multipart/form-data"
action="<?php echo base_url(); ?>addNewCoatingMachineDetails?month=<?= $month; ?>">
<div class="modal-body">
<div class="form-row">
@ -594,7 +616,7 @@
<div class="form-group col-md-3">
<label for="machineRunningInHrsId"> Machine Running In Hrs</label>
<span class="badge mandatory">*</span>
<input type="text" class="form-control" id="machineRunningInHrsId"
<input type="text" class="form-control" readonly id="machineRunningInHrsId"
name="machineRunningInHrs" required>
</div>
@ -609,9 +631,9 @@
<!-- grade -->
<div class="form-group col-md-3">
<label for="totalCoatingId">grade</label>
<label for="gradeId">grade</label>
<span class="badge mandatory">*</span>
<input type="text" class="form-control" id="totalCoatingId" name="totalCoating" value=""
<input type="text" class="form-control" id="gradeId" name="grade" value=""
required>
</div>
@ -644,21 +666,21 @@
</div>
<!-- per hour Coating sand qty -->
<!-- per hour Coating sand qty -->
<div class="form-group col-md-3">
<label for="perHourCoatingSandQTY">Per Hour Coating Sand QTY</label>
<span class="badge mandatory">*</span>
<input type="text" class="form-control" id="perHourCoatingSandQTYId"
<input type="text" class="form-control" readonly id="perHourCoatingSandQTYId"
name="perHourCoatingSandQTY" required>
</div>
<!-- per hour gas consumption -->
<!-- per hour gas consumption -->
<div class="form-group col-md-3">
<label for="perHourGasConsumptionId">Per Hour Gas Consumption </label>
<span class="badge mandatory">*</span>
<input type="text" class="form-control" id="perHourGasConsumptionId"
name="perHourGasConsumption" required>
<input type="text" class="form-control" readonly id="perHourGasConsumptionId"
name="perHourGasConsumption" required >
</div>
@ -666,18 +688,25 @@
</div>
<div class="form-row">
<!-- batch card file upload -->
<div class="form-group col-md-3">
<label for="totalCoatingSandId">upload batch card</label>
<span class="badge mandatory">*</span>
<input type="text" class="form-control" id="totalCoatingSandId" name="totalCoatingSandInKg"
value="" required>
<div class="form-row" id="batchCardRowId">
<!-- batch card file upload -->
<div class="form-group col-md-3">
<label for="">Upload Batch Card</label>
<div>
<input type="file" class="batchfile" name="batchCard[]" >
</div>
<button class="btn btn-success btn-sm mt-2" id="batchCardAddBtnId">Add More</button>
</div>
</div>
</div>
</div>
<div class="modal-footer">
@ -693,7 +722,7 @@
<!-- editCoatingMachineDetailModal -->
<div class="modal fade" id="editCoatingMachineDetailModal" tabindex="-1" role="dialog"
aria-labelledby="editCoatingMachineDetailModalLabel" aria-hidden="true">
<div class="modal-dialog modal-xl" style="width:1060px !important ;" role="document">
<div class="modal-dialog modal-lg" style="width:1060px !important ;" role="document">
<div class="modal-content">
<div class="modal-header">
@ -707,21 +736,28 @@
<!-- form -->
<form method="post" id="editCoatingMachineDetailModalFormId"
enctype="multipart/form-data"
action="<?php echo base_url(); ?>updateCoatingMachineDetails?month=<?= $month; ?>">
<div class="modal-body">
<div class="form-row">
<!-- date -->
<div class="form-group col-md-3">
<label for="editDateId">Date</label>
<span class="badge mandatory">*</span>
<input type="date" class="form-control" id="editDateId" name="date" value="" required>
<input type="hidden" name="editCoatingMachineDetailId" id="editCoatingMachineDetailId">
</div>
<!-- shift -->
<div class="form-group col-md-3">
<label for="editShiftId">Shift</label>
<span class="badge mandatory">*</span>
<input type="text" class="form-control" id="editShiftId" name="shift" value="" required>
</div>
<!-- machine on time -->
<div class="form-group col-md-3">
<label for="editMachineOnTimeHrId">Machine On Time</label>
<span class="badge mandatory">*</span>
@ -758,6 +794,7 @@
</div>
<!-- machine off time -->
<div class="form-group col-md-3">
<label for="editMachineOffTimeHrId">Machine Off Time</label>
<span class="badge mandatory">*</span>
@ -796,24 +833,55 @@
</div>
<div class="form-row">
<!-- total hours -->
<div class="form-group col-md-3">
<label for="editMachineRunningInHrsId"> Machine Running In Hrs</label>
<span class="badge mandatory">*</span>
<input type="text" class="form-control" readonly id="editMachineRunningInHrsId"
name="machineRunningInHrs" required>
</div>
<!-- customer name -->
<div class="form-group col-md-3">
<label for="editCustomerNameId">Customer Name</label>
<span class="badge mandatory">*</span>
<input type="text" class="form-control" id="editCustomerNameId" name="customerName" value=""
required>
</div>
<!-- grade -->
<div class="form-group col-md-3">
<label for="editTotalCoatingId">Total Coating</label>
<label for="editGradeId">grade</label>
<span class="badge mandatory">*</span>
<input type="text" class="form-control" id="editGradeId" name="grade" value=""
required>
</div>
<!-- total coating as renamed to total production -->
<div class="form-group col-md-3">
<label for="editTotalCoatingId">Total Production</label>
<span class="badge mandatory">*</span>
<input type="text" class="form-control" id="editTotalCoatingId" name="totalCoating" value=""
required>
</div>
</div>
<div class="form-row">
<!-- total coating sand in kg -->
<div class="form-group col-md-3">
<label for="editTotalCoatingSandId">Total Coating Sand (in Kg)</label>
<span class="badge mandatory">*</span>
<input type="text" class="form-control" id="editTotalCoatingSandId"
name="totalCoatingSandInKg" value="" required>
</div>
<!-- total gas consumption -->
<div class="form-group col-md-3">
<label for="editTotalGasConsumptionId">Total Gas Consumption</label>
<span class="badge mandatory">*</span>
@ -823,35 +891,38 @@
name="existingTotalGasConsumption" value="">
</div>
<!-- per hour Coating sand qty -->
<div class="form-group col-md-3">
<label for="editPerHourCoatingSandQTYId">Per Hour Coating Sand QTY</label>
<span class="badge mandatory">*</span>
<input type="text" class="form-control" readonly id="editPerHourCoatingSandQTYId"
name="perHourCoatingSandQTY" required>
</div>
<!-- per hour gas consumption -->
<div class="form-group col-md-3">
<label for="editPerHourGasConsumptionId">Per Hour Gas Consumption </label>
<span class="badge mandatory">*</span>
<input type="text" class="form-control" readonly id="editPerHourGasConsumptionId"
name="perHourGasConsumption" required>
</div>
</div>
<div class="form-row">
<!-- batch card file upload -->
<div class="form-group col-md-3">
<label for="editMachineRunningInHrsId"> Machine Running In Hrs</label>
<label for="editBatchCardId">upload batch card</label>
<span class="badge mandatory">*</span>
<input type="text" class="form-control" id="editMachineRunningInHrsId"
name="machineRunningInHrs" required>
<input type="file" class="" id="editBatchCardId" name="batchCard"
value="" required >
</div>
<div class="form-group col-md-3">
<label for="editPerHourGasConsumptionId">Per Hour Gas Consumption </label>
<span class="badge mandatory">*</span>
<input type="text" class="form-control" id="editPerHourGasConsumptionId"
name="perHourGasConsumption" required>
</div>
<div class="form-group col-md-3">
<label for="editPerHourCoatingSandQTYId">Per Hour Coating Sand QTY</label>
<span class="badge mandatory">*</span>
<input type="text" class="form-control" id="editPerHourCoatingSandQTYId"
name="perHourCoatingSandQTY" required>
</div>
</div>
</div>
@ -1141,19 +1212,20 @@
// Get values from the row
var date = row.find('td:eq(0)').text().split('-');
var date = row.find('td:eq(0)').text().split('-');
date = `${date[2]}-${date[1]}-${date[0]}`;
var shift = row.find('td:eq(1)').text();
var machineOnTimeHr = row.find('td:eq(2)').text();
var machineOffTimeHr = row.find('td:eq(3)').text();
var machineRunningInHrs = row.find('td:eq(4)').text();
var totalCoating = row.find('td:eq(5)').text();
var totalCoatingSandInKg = row.find('td:eq(6)').text();
var totalGasConsumption = row.find('td:eq(7)').text();
var perHourGasConsumption = row.find('td:eq(8)').text();
var perHourCoatingSandQTY = row.find('td:eq(9)').text();
var customerName = row.find('td:eq(10)').text();
var shift = row.find('td:eq(1)').text();
var machineOnTimeHr = row.find('td:eq(2)').text();
var machineOffTimeHr = row.find('td:eq(3)').text();
var machineRunningInHrs = row.find('td:eq(4)').text();
var customerName = row.find('td:eq(5)').text();
var grade = row.find('td:eq(6)').text();
var totalCoating = row.find('td:eq(7)').text();
var totalCoatingSandInKg = row.find('td:eq(8)').text();
var totalGasConsumption = row.find('td:eq(9)').text();
var perHourGasConsumption = row.find('td:eq(10)').text();
var perHourCoatingSandQTY = row.find('td:eq(11)').text();
// Fill the modal fields with the values
@ -1164,6 +1236,7 @@
$('#editShiftId').val(shift);
$('#editMachineOnTimeHrId').val(machineOnTimeHr).change();
$('#editMachineOffTimeHrId').val(machineOffTimeHr).change();
$('#editGradeId').val(grade);
$('#editTotalCoatingId').val(totalCoating);
$('#editTotalCoatingSandId').val(totalCoatingSandInKg);
$('#editTotalGasConsumptionId').val(totalGasConsumption);
@ -1509,4 +1582,33 @@
</script>
<script>
$(document).ready(function () {
$('#batchCardAddBtnId').click(function () {
let fileCount = $('.batchfile').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="batchfile" name="batchCard[]" >
<button type="button" class="btn btn-danger btn-sm mt-2 removeBatch">Remove</button>
</div>`;
$('#batchCardRowId').append(string);
});
// Remove batch card field dynamically
$(document).on('click', '.removeBatch', function () {
$(this).closest('.batch-container').remove();
});
});
</script>