master module 3 vadivel J 30-12-2024

This commit is contained in:
vadivelJ96 2024-12-30 12:30:06 +05:30
parent bbcc021e7a
commit ae5ed3ce05
5 changed files with 682 additions and 7 deletions

View File

@ -480,4 +480,8 @@ $routes->post('updateResinStockDetails', 'StockController::updateResinStockDetai
//Gas stock details
$routes->match(['GET', 'POST'], 'gasStockDetails', 'StockController::loadView_gasStockDetails');
$routes->post('updateGasStockDetails', 'StockController::updateGasStockDetails');
$routes->post('updateGasStockDetails', 'StockController::updateGasStockDetails');
//trp sand use stock details
$routes->match(['GET', 'POST'], 'trpSandUseStockDetails', 'StockController::trpSandUseStockDetails');
$routes->post('updateTrpSandUseStockDetails', 'StockController::updateTrpSandUseStockDetails');

View File

@ -17,6 +17,7 @@ use App\Models\BagStockDetailsModel;
use App\Models\DustAndRoughModel;
use App\Models\ResinStockModel;
use App\Models\GasStockModel;
use App\Models\TrpSandUseStockModel;
use CodeIgniter\HTTP\ResponseInterface;
use DateTime;
use DatePeriod;
@ -42,6 +43,8 @@ class StockController extends BaseController
protected $resinStockDetails_model;
protected $gasStockDetails_model;
protected $TrpSandUseStock_model;
protected $db;
/**
@ -80,6 +83,8 @@ class StockController extends BaseController
$this->gasStockDetails_model = new GasStockModel();
$this->TrpSandUseStock_model = new TrpSandUseStockModel();
$this->session = session();
helper('form');
@ -1164,6 +1169,101 @@ class StockController extends BaseController
}
}
public function trpSandUseStockDetails(){
if ($this->request->getMethod() === 'POST') {
$month = $this->request->getPost('month');
$date = DateTime::createFromFormat('M-Y', $month);
$formattedDate = $date->format('Y-m');
$month = $formattedDate;
} else {
$month = date('Y-m');
}
$data = [];
$data['month'] = $month;
$this->global['pageTitle'] = 'Trp Sand Use Stock Details';
$startDate = "$month-01";
$endDate = date("Y-m-t", strtotime($startDate));
$data['trpSandUseStockDetails'] = $this->TrpSandUseStock_model
->where('date >=', $startDate)
->where('date <=', $endDate)
->orderBy('date', 'asc')
->findAll();
$date = DateTime::createFromFormat('Y-m', $month);
$formattedDate = $date->format('M-Y');
$data['month'] = $formattedDate;
return $this->loadViews("trpSandUseStockDetails", $this->global, $data, NULL);
}
public function updateTrpSandUseStockDetails(){
$postData = $this->request->getPost();
$updateTrpSandUseStockDetailsData = json_decode($postData['updateTrpSandUseStockDetails'], true);
$updates = [];
$inserts = [];
foreach ($updateTrpSandUseStockDetailsData as $data) {
$data['date'] = DateTime::createFromFormat('d-m-Y', $data['date'])->format('Y-m-d');
$date = $data['date'];
$dbData = [
'date' => $data['date'],
'rough_kgs' => $data['rough_kgs'],
'fine_kgs' => $data['fine_kgs'],
'total_kgs' => $data['total_kgs'],
'customer_name' => $data['customer_name']
];
$resultExists = $this->TrpSandUseStock_model
->where('date', $date)
->first();
if (empty($resultExists)) {
$inserts[] = $dbData;
} else {
$dbData['id'] = $resultExists['id'];
$updates[] = $dbData;
}
}
if (!empty($inserts)) {
$this->TrpSandUseStock_model->insertBatch($inserts);
}
if (!empty($updates)) {
$updateResult = $this->TrpSandUseStock_model->updateBatch($updates, 'id');
if ($updateResult === FALSE) {
echo "Error during update";
} else {
echo "Data Updated Successfully";
return;
}
}
echo "Data Saved Successfully";
}
// --------------------------------------------gwm----------------------------------------------
@ -1233,9 +1333,6 @@ class StockController extends BaseController
$data['datefordropdown'] = $currentMonth;
$this->global['pageTitle'] = 'Drier Details';
$this->loadViews("drierMachineDetails", $this->global, $data, NULL);
}

View File

@ -0,0 +1,46 @@
<?php
namespace App\Models;
use CodeIgniter\Model;
class TrpSandUseStockModel extends Model
{
protected $table = 't_trp_sand_use';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
protected $returnType = 'array';
protected $useSoftDeletes = false;
protected $protectFields = true;
protected $allowedFields = [ 'date' , 'rough_kgs' , 'fine_kgs' , 'total_kgs' , 'customer_name' , 'created_at' , 'updated_at' ];
protected bool $allowEmptyInserts = false;
protected bool $updateOnlyChanged = true;
protected array $casts = [];
protected array $castHandlers = [];
// Dates
protected $useTimestamps = false;
protected $dateFormat = 'datetime';
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
protected $deletedField = 'deleted_at';
// Validation
protected $validationRules = [];
protected $validationMessages = [];
protected $skipValidation = false;
protected $cleanValidationRules = true;
// Callbacks
protected $allowCallbacks = true;
protected $beforeInsert = [];
protected $afterInsert = [];
protected $beforeUpdate = [];
protected $afterUpdate = [];
protected $beforeFind = [];
protected $afterFind = [];
protected $beforeDelete = [];
protected $afterDelete = [];
}

View File

@ -612,6 +612,8 @@
<ul class="navbar-nav">
<!-- Dashboard module -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle arrow-none" href="<?php echo base_url(); ?>sales_dashboard" role="button"
aria-expanded="false">
@ -632,6 +634,8 @@
<!-- sales module -->
<?php if(session()->get('roleText') == 'System Administrator' || session()->get('roleText') == 'Auditor' || session()->get('roleText') == 'Security'){?>
@ -654,10 +658,11 @@
<!-- purchase module -->
<?php if(session()->get('roleText') == 'System Administrator' || session()->get('roleText') == 'Auditor' || session()->get('roleText') == 'Security'){?>
<!-- purchase module -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle arrow-none" href="#" id="topnav-purchase" role="button"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
@ -701,6 +706,7 @@
<!-- IGR module -->
<?php if(session()->get('roleText') == 'System Administrator' || session()->get('roleText') == 'Auditor' || session()->get('roleText') == 'Security' || session()->get('roleText') == 'Stock Handler'){?>
@ -738,10 +744,12 @@
<!-- HR module -->
<?php if(session()->get('roleText') == 'System Administrator'){ ?>
<!-- HR module -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle arrow-none" href="#" id="topnav-hr" role="button"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
@ -793,7 +801,9 @@
</a>
</li>
<!-- master detail module -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle arrow-none" href="#" id="topnav-others" role="button"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
@ -819,8 +829,10 @@
<!-- Stock module -->
<?php if(session()->get('roleText') == 'System Administrator' || session()->get('roleText') == 'Stock Handler'){?>
<!-- Stock module -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle arrow-none" href="#" id="topnav-stock" role="button"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
@ -854,6 +866,8 @@
<a href="<?php echo base_url(); ?>resinStockDetails" class="dropdown-item"><i class="ri-file-info-line align-middle mr-1"></i>Resin Stock Details</a>
<a href="<?php echo base_url(); ?>bagStockDetails" class="dropdown-item"><i class="ri-file-info-line align-middle mr-1"></i>Bag Stock Details</a>
<a href="<?php echo base_url(); ?>trpSandUseStockDetails" class="dropdown-item"><i class="ri-file-info-line align-middle mr-1"></i>Trp Sand Use Stock Details</a>
</div>
</div>

View File

@ -0,0 +1,514 @@
<style type="text/css">
.num {
text-align: right;
}
.fht-table,
.fht-table thead,
.fht-table tfoot,
.fht-table tbody,
.fht-table tr,
.fht-table th,
.fht-table td {
margin: 0;
}
.fht-table td {
text-align: center;
}
.fht-table td:hover {
background-color: #00a65a;
color: #ffffff;
}
.fht-table {
border: 0 none;
height: auto;
width: auto;
border-collapse: collapse;
border-spacing: 0;
/*table-layout: fixed; Algoritmo de distribucion fijo */
white-space: nowrap;
}
.fht-table th,
.fht-table td {
overflow: hidden;
}
.fht-table-wrapper,
.fht-table-wrapper .fht-thead,
.fht-table-wrapper .fht-tfoot,
.fht-table-wrapper .fht-fixed-column .fht-tbody,
.fht-table-wrapper .fht-fixed-body .fht-tbody,
.fht-table-wrapper .fht-tbody {
overflow: hidden;
position: relative;
}
.fht-table-wrapper .fht-fixed-body .fht-tbody,
.fht-table-wrapper .fht-tbody {
overflow: auto;
}
.fht-table-wrapper .fht-table .fht-cell {
overflow: hidden;
height: 1px;
}
.fht-table-wrapper .fht-fixed-column,
.fht-table-wrapper .fht-fixed-body {
top: 0;
left: 0;
position: absolute;
}
.fht-table-wrapper .fht-fixed-column {
z-index: 1;
}
.fht-fixed-body .fht-thead table {
margin-right: 20px;
border: 0 none;
}
/*For Examples*/
.ContenedorTabla {
height: 500px;
margin: 0 auto;
overflow: auto;
width: auto;
position: relative;
}
.header,
.main {
display: inline-block;
height: auto;
width: 100%;
}
.titulosHeader {
border-bottom: 1px solid #e8bb25;
height: auto;
margin-bottom: 10px;
padding-bottom: 8px;
padding-top: 8px;
width: 100%;
}
.celda_encabezado_general {
background-color: #00a65a;
border: 1px solid #ccc;
color: #ffffff;
font-weight: bold;
padding: 6px 10px;;
text-align: center;
}
._Separador {
background-color: #fff;
height: 12px;
border-left: 1px solid #ccc;
border-right: 1px solid #ccc;
width: 7px;
}
._Separador div {
width: 4px;
}
.celda_normal {
/*background-color: #fff;*/
/* <!-- ad9271 into ffffff brown-light to green-light --> */
text-align: center;
border: 1px solid #ccc;
padding: 2px 4px;
}
/*style excel*/
.excel_cell {
border: 1px solid #CCC;
color: #222;
text-align: center;
font-size: 13px;
font-weight: normal;
padding: 4px;
white-space: pre-line;
empty-cells: show;
}
._cell_header {
background-color: #EEE;
}
._cell_Default {
background-color: #FFF;
text-align: left;
}
.excel_cell div {
width: 30px;
height: 20px;
}
#dustAndRoughStockDetailsTableId th:nth-child(1),
#dustAndRoughStockDetailsTableId td:nth-child(1) {
position: sticky;
left: 0;
background-color: #00a65a;
z-index: 2;
border-right: 2px solid #ddd;
color: #ffffff;
}
.modal {
padding-right: 30% ! important;
}
</style>
<div class="content-page">
<div class="content">
<!-- Start Content-->
<div class="container-fluid">
<!-- start page title -->
<div>
<div class="row">
<div class="col-6">
<div class="page-title-box page-title-box-alt">
<div class="page-title-right">
<ol class="breadcrumb m-0">
<li class="breadcrumb-item"><a href="javascript: void(0);">Stocks</a></li>
<li class="breadcrumb-item active">
<h4 class="page-title">Trp Sand Use Stock Details </h4>
</li>
</ol>
</div>
</div>
</div>
<div class="col-6 text-right">
<!-- Right-aligned buttons or links can be added here -->
</div>
</div>
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body" style="padding-left:300px;">
<form action="<?= base_url('trpSandUseStockDetails'); ?>" method="post">
<div class="row" >
<div class="col-3">
<input type="text" name="month" id="month" value="<?php echo "$month" ?>"
class="form-control mt-2" data-provide="datepicker"
data-date-format="M-yyyy" data-date-min-view-mode="1">
</div>
<div class="form-group col-md-2">
<button type="submit" class="btn btn-success"> Change Month </button>
</div>
</div>
</form>
<div class="table-responsive">
<table style="width: 700px;" id="trpSandUseStockDetailsTableId" class="fht-table table-striped">
<thead class="celda_encabezado_general" style="padding: 10px;">
<tr>
<th class="celda_encabezado_general" colspan="5" >Trp Sand To Use Coating Sand </th>
</tr>
<tr>
<th
style="width: 100px;"
class="celda_encabezado_general" >Date </th>
<th class="celda_encabezado_general" >Rough Kgs </th>
<th class="celda_encabezado_general" >Fine kgs </th>
<th class="celda_encabezado_general" >Total kgs </th>
<th class="celda_encabezado_general" >Customer Name</th>
</tr>
</thead>
<tbody style="background-color: #fff;" >
<?php
if(!empty($trpSandUseStockDetails)){
foreach($trpSandUseStockDetails as $trpSandUseStockDetailsIndex => $trpSandUseStockDetail){
?>
<tr
<?php
$currentDate = date('d-m-Y');
$dateInMonthDmYFormat=DateTime::createFromFormat('Y-m-d', $trpSandUseStockDetail['date'])->format('d-m-Y');
if ($dateInMonthDmYFormat === $currentDate) { echo 'style="background: #cef0ad;"';}
?>
>
<td class="celda_normal">
<?php
echo date("d-m-Y", strtotime($trpSandUseStockDetail['date']));
?>
</td>
<td class="celda_normal rough"
data-id="<?= $trpSandUseStockDetail['date'] ?>"
oninput="roughStockChange(this)"
contenteditable="true"
><?= $trpSandUseStockDetail['rough_kgs'] ?></td>
<td class="celda_normal fine"
data-id="<?= $trpSandUseStockDetail['date'] ?>"
oninput="fineStockChange(this)"
contenteditable="true"
><?= $trpSandUseStockDetail['fine_kgs'] ?></td>
<td class="celda_normal total"
data-id="<?= $trpSandUseStockDetail['date'] ?>"
><?= $trpSandUseStockDetail['total_kgs'] ?></td>
<td class="celda_normal total"
data-id="<?= $trpSandUseStockDetail['date'] ?>"
contenteditable="true"
><?= $trpSandUseStockDetail['customer_name'] ?></td>
<td style="display:none"
data-id="<?= $trpSandUseStockDetail['date'] ?>"
><?= $trpSandUseStockDetail['id'] ?></td>
</tr>
<?php
}
}else{
$date = DateTime::createFromFormat('M-Y', $month);
$startDate = $date->modify('first day of this month')->format('Y-m-d');
$endDate = $date->modify('last day of this month')->format('Y-m-d');
$datesInMonth = [];
$period = new DatePeriod(
new DateTime($startDate),
new DateInterval('P1D'),
(new DateTime($endDate))->modify('+1 day')
);
foreach ($period as $day) {
$datesInMonth[] = $day->format('Y-m-d');
}
foreach($datesInMonth as $datesInMonthIndex => $dateInMonth){
?>
<tr
<?php
$currentDate = date('d-m-Y');
$dateInMonthDmYFormat=date("d-m-Y", strtotime($dateInMonth));
if ($dateInMonthDmYFormat === $currentDate) { echo 'style="background: #cef0ad;"';}
?>
>
<!-- td:eq(0) -->
<td class="celda_normal">
<?php
echo date("d-m-Y", strtotime($dateInMonth));
?>
</td>
<!-- td:eq(1) -->
<td class="celda_normal rough"
data-id="<?= $dateInMonth ?>"
oninput="roughStockChange(this)"
contenteditable="true"
><?= 0 ?></td>
<!-- td:eq(2) -->
<td class="celda_normal fine"
data-id="<?= $dateInMonth ?>"
oninput="fineStockChange(this)"
contenteditable="true"
><?= 0 ?></td>
<!-- td:eq(3) -->
<td class="celda_normal total"
data-id="<?= $dateInMonth ?>"
><?= 0 ?></td>
<!-- td:eq(4) -->
<td class="celda_normal customer"
data-id="<?= $dateInMonth ?>"
contenteditable="true"
><?= " " ?></td>
<!-- td:eq(5) -->
<td style="display:none"
data-id="<?= $dateInMonth ?>"
contenteditable="true"
><?= " " ?></td>
</tr>
<?php
}
}
?>
</tbody>
</table>
</div>
<div class="row">
<div class="col-md-12 text-right">
<input type="button" class="btn btn-success" id="saveId" value="save">
</div>
</div>
</div>
</div> <!-- End card-body -->
</div> <!-- End card -->
</div> <!-- End col -->
</div> <!-- End row -->
</div>
</div> <!-- End container-fluid -->
</div>
</div>
<script type="text/javascript">
$(document).ready(function () {
$('#saveId').click(function () {
//table to json function
var updateTrpSandUseStockDetails = tableToJson();
alert('Updation may take a while, And we appreciate your patience..!!');
$('#loader').show();
$.ajax({
data: {
updateTrpSandUseStockDetails
},
type: "POST",
url: "<?php echo base_url() ?>updateTrpSandUseStockDetails",
success: function (data) {
if (data) {
$('#loader').hide();
console.log(data);
alert(data);
}
},
error: function(xhr, status, error) {
alert("An error occurred while processing the request. Please try again.");
console.error("Error Code:", xhr.status);
console.error("Error Message:", error);
console.error("Response Text:", xhr.responseText);
},
complete: function() {
$('#loader').hide();
}
});
});
});
</script>
<script>
function tableToJson() {
const table = $('#trpSandUseStockDetailsTableId');
const rows = [];
table.find('tbody tr').each(function() {
const rowCells = $(this).find('td');
const rowData = {
date: rowCells.eq(0).text().trim(),
rough_kgs: rowCells.eq(1).text().trim(),
fine_kgs: rowCells.eq(2).text().trim(),
total_kgs: rowCells.eq(3).text().trim(),
customer_name: rowCells.eq(4).text().trim(),
id: rowCells.eq(5).text().trim()
};
rows.push(rowData);
});
return JSON.stringify(rows, null, 2);
}
</script>
<script>
function roughStockChange(tdElement) {
try{
console.log("just an alert from RoughStockChange..!!")
console.log(tdElement.innerText)
let dataId = tdElement.getAttribute('data-id')
let roughStock = tdElement.innerText;
let fineStock = document.querySelector(`td.fine[data-id="${dataId}"]`).innerText;
let total = (Number(roughStock) + Number(fineStock)) ;
document.querySelector(`td.total[data-id="${dataId}"]`).innerText=total;
} catch(error){
console.error("There is an error updating stock ..!!" + error);
}
}
function fineStockChange(tdElement) {
try{
console.log("just an alert from fineStockChange..!!")
console.log(tdElement.innerText)
let dataId = tdElement.getAttribute('data-id')
let roughStock = document.querySelector(`td.rough[data-id="${dataId}"]`).innerText;
let fineStock = tdElement.innerText;
let total = (Number(roughStock) + Number(fineStock)) ;
document.querySelector(`td.total[data-id="${dataId}"]`).innerText = total;
} catch(error){
console.error("There is an error updating stock ..!!" + error);
}
}
</script>