diff --git a/app/Config/Routes.php b/app/Config/Routes.php
index 899d0cba..f4eb2bdf 100755
--- a/app/Config/Routes.php
+++ b/app/Config/Routes.php
@@ -449,3 +449,6 @@ $routes->post('updateBagStockDetails', 'StockController::updateBagStockDetails')
$routes->match(['GET','POST'],'dustAndRoughStockDetails', 'StockController::loadView_dustAndRoughStockDetails');
$routes->post('updateDustAndRoughStockDetails', 'StockController::updateDustAndRoughStockDetails');
+//Resin stock details
+$routes->match(['GET','POST'],'resinStockDetails', 'StockController::loadView_resinStockDetails');
+$routes->post('updateResinStockDetails', 'StockController::updateResinStockDetails');
\ No newline at end of file
diff --git a/app/Controllers/StockController.php b/app/Controllers/StockController.php
index d640aee9..63ddd1e9 100644
--- a/app/Controllers/StockController.php
+++ b/app/Controllers/StockController.php
@@ -13,6 +13,7 @@ use App\Models\Inwardgateregister_model;
use App\Models\Rawmaterialdetails_model;
use App\Models\BagStockDetailsModel;
use App\Models\DustAndRoughModel;
+use App\Models\ResinStockModel;
use CodeIgniter\HTTP\ResponseInterface;
use DateTime;
@@ -31,6 +32,7 @@ class StockController extends BaseController
protected $bagStockDetails_model;
protected $Rawmaterialdetails_model;
protected $dustAndRoughStockDetails_model;
+ protected $resinStockDetails_model;
/**
* This is default constructor of the class
@@ -39,16 +41,27 @@ class StockController extends BaseController
{
$this->db = \Config\Database::connect();
parent::__construct();
- $this->coatingMachineDetails_model = new CoatingMachineDetailsModel();
- $this->drierMachineDetails_model = new DrierMachineDetailsModel();
- $this->factoryMachine_model = new FactoryMachineModel();
- $this->factoryVehicleDieselDetails_model = new FactoryVehicleDieselDetailsModel();
+ $this->coatingMachineDetails_model = new CoatingMachineDetailsModel();
+
+ $this->drierMachineDetails_model = new DrierMachineDetailsModel();
+
+ $this->factoryMachine_model = new FactoryMachineModel();
+
+ $this->factoryVehicleDieselDetails_model = new FactoryVehicleDieselDetailsModel();
+
$this->factoryVehicleDieselStockSummary_model = new FactoryVehicleDieselStockSummaryModel();
- $this->rawmaterialdetails_model = new Rawmaterialdetails_model();
- $this->incomingSilicaSandDetails_model = new IncomingSilicaSandDetailsModel();
- $this->inwardGateRegister_model = new Inwardgateregister_model();
- $this->bagStockDetails_model = new BagStockDetailsModel();
- $this->dustAndRoughStockDetails_model = new DustAndRoughModel();
+
+ $this->rawmaterialdetails_model = new Rawmaterialdetails_model();
+
+ $this->incomingSilicaSandDetails_model = new IncomingSilicaSandDetailsModel();
+
+ $this->inwardGateRegister_model = new Inwardgateregister_model();
+
+ $this->bagStockDetails_model = new BagStockDetailsModel();
+
+ $this->dustAndRoughStockDetails_model = new DustAndRoughModel();
+
+ $this->resinStockDetails_model = new ResinStockModel() ;
$this->session = session();
@@ -441,8 +454,6 @@ class StockController extends BaseController
->orderBy('date','asc')
->findAll();
-
-
$date = DateTime::createFromFormat('Y-m', $month);
$formattedDate = $date->format('M-Y');
@@ -492,6 +503,153 @@ class StockController extends BaseController
}
+ //Resin Stock Details
+
+ public function loadView_resinStockDetails(){
+
+ 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']='Resin Stock Details';
+
+
+ $previousMonth = DateTime::createFromFormat('Y-m', $month)->modify('-1 month')->format('Y-m');
+ $previousMonthStartDate = "$previousMonth-01";
+ $previousMonthEndDate = date("Y-m-t", strtotime($previousMonthStartDate));
+ $data['previousMonthResinStockDetails'] = $this->resinStockDetails_model
+ ->select(['materialCode', 'date' ,'balanceStock'])
+ ->distinct()
+ ->where('date =', $previousMonthEndDate)
+ ->groupBy(['materialCode','date'])
+ ->orderBy('date','desc')
+ ->orderBy('materialCode','asc')
+ ->findAll();
+
+
+
+
+ $startDate = "$month-01";
+ $endDate = date("Y-m-t", strtotime($startDate));
+ $data['resinStockDetails'] = $this->resinStockDetails_model
+ ->where('date >=', $startDate)
+ ->where('date <=', $endDate)
+ ->groupBy(['materialCode','date'])
+ ->orderBy('date','asc')
+ ->orderBy('materialCode','asc')
+ ->findAll();
+
+ // Initialize an empty array to hold the grouped data
+ $data['groupedResinStockDetails'] = [];
+
+ // Temporary array to store grouped data by date
+ $groupedByDate = [];
+
+ // Group by 'date'
+ foreach ($data['resinStockDetails'] as $detail) {
+ $date = $detail['date'];
+
+ // Initialize the array for this date if it doesn't exist
+ if (!isset($groupedByDate[$date])) {
+ $groupedByDate[$date] = [];
+ }
+
+ // Append the detail to the sub-array for this date
+ $groupedByDate[$date][] = $detail;
+ }
+
+ // Reset the structure to have indexed arrays without the date keys
+ $data['groupedResinStockDetails'] = array_values($groupedByDate);
+
+
+
+ $resinMaterials= $this->rawmaterialdetails_model->getAllResinMaterialCode();
+
+ foreach($resinMaterials as $key => $resinMaterial){
+ $materialCode = $resinMaterial['MaterialCode'];
+ $resinMaterials[$key]['customers'] = $this->bagStockDetails_model
+ ->select('customer')
+ ->where('date >=', $startDate)
+ ->where('date <=', $endDate)
+ ->where('materialCode', $materialCode)
+ ->first()['customer'] ?? '';
+ }
+
+ $resinMaterialCount = count($resinMaterials);
+
+ $data['resinMaterialCount'] = $resinMaterialCount;
+ $data['resinMaterials'] = $resinMaterials;
+
+ $date = DateTime::createFromFormat('Y-m', $month);
+
+ $formattedDate = $date->format('M-Y');
+
+ $data['month']=$formattedDate;
+
+ return $this->loadViews("resinStockDetails", $this->global, $data, NULL);
+
+ }
+
+ public function updateResinStockDetails(){
+
+
+ $postData = $this->request->getPost();
+
+ $updateResinStockDetailsData = json_decode($postData['updateResinStockDetails'], true);
+
+ foreach($updateResinStockDetailsData as $data){
+
+ $date = $data['date'];
+ $materialCode = $data['materialCode'];
+
+
+ $dbData= [
+ 'date' =>$data['date'],
+ 'materialCode' =>$data['materialCode'],
+ 'customer' =>$data['customer'],
+ 'opening' =>$data['opening'],
+ 'receipt' =>$data['receipt'],
+ 'used' =>$data['used'],
+ 'balanceStock' =>$data['balanceStock'],
+ ];
+
+ $resultExists = $this->resinStockDetails_model
+ ->where('date',$date)
+ ->where('materialCode',$materialCode)
+ ->first();
+
+
+ if(!empty($resultExists)){
+
+ $updated = $this->resinStockDetails_model
+ ->where('date',$date)
+ ->where('materialCode',$materialCode)
+ ->set($dbData)
+ ->update();
+
+ }else{
+ $inserted = $this->resinStockDetails_model->insert($dbData);
+ }
+
+ }
+
+ echo "Data Saved Successfully";
+
+ }
diff --git a/app/Models/Rawmaterialdetails_model.php b/app/Models/Rawmaterialdetails_model.php
index 45981afe..0a0cb488 100755
--- a/app/Models/Rawmaterialdetails_model.php
+++ b/app/Models/Rawmaterialdetails_model.php
@@ -150,6 +150,20 @@ class Rawmaterialdetails_model extends Model
}
+ function getAllResinMaterialCode(){
+
+ $builder = $this->db->table('t_materialmaster')
+ ->select('MaterialCode , MaterialName')
+ ->where('IsActive', 1)
+ ->where('Category', 'plastic_chemicals')
+ ->orderBy('MaterialCode', 'asc');
+ $query = $builder->get();
+ $materialResults = $query->getResultArray();
+
+ return $materialResults;
+
+ }
+
function getMaterialstock($MaterialCode, $currentdate)
diff --git a/app/Models/ResinStockModel.php b/app/Models/ResinStockModel.php
new file mode 100644
index 00000000..22b6efca
--- /dev/null
+++ b/app/Models/ResinStockModel.php
@@ -0,0 +1,48 @@
+ $dustAndRoughStockDetail){
?>
- | = $dustAndRoughStockDetail['date'] ?> |
+
+
+ |
$dateInMonth){
?>
|
- | = $dateInMonth?> |
+
+
+ |
Bag Stock Details
Dust And Rough Stock Details
+
+ Resin Stock Details
+
diff --git a/app/Views/resinStockDetails.php b/app/Views/resinStockDetails.php
new file mode 100644
index 00000000..6a9787dd
--- /dev/null
+++ b/app/Views/resinStockDetails.php
@@ -0,0 +1,640 @@
+
+
+
+
+
+
+
+
+
+
+
+
+ - Stocks
+ -
+
Bag Stock Details
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ | material |
+
+
+
+
+ = $bagMaterial['MaterialName']?>
+
+ |
+
+
+
+
+ | Customer |
+
+
+
+ = $bagMaterial['customers']?>
+ |
+
+
+
+
+
+
+
+ | Date |
+
+
+
+ Date |
+ material |
+ customer |
+ Opening Stock |
+ Receipt |
+ Used |
+ Balance Stock |
+
+
+
+
+
+
+
+
+ $bagStockDetails){
+ ?>
+
+ $bagStock){ ?>
+
+ format('d-m-Y');
+ ?>
+ |
+ = $startDate ?>
+ |
+
+
+
+ = $bagStock['date']?>
+ |
+ = $bagStock['materialCode']?>
+ |
+
+
+ = $bagStock['customer']?>
+ |
+
+
+ oninput="openingStockChange(this)"
+ contenteditable="true"
+
+
+ >= $bagStock['opening']?>
+ |
+
+
+ = $bagStock['receipt']?>
+ |
+
+ = $bagStock['used']?>
+ |
+
+
+ = $bagStock['balanceStock']?>
+ |
+
+
+
+
+
+
+
+
+
+ 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');
+ }
+
+ ?>
+
+ $dateInMonth){ ?>
+
+ $bagMaterial){ ?>
+
+
+
+ format('d-m-Y');
+ ?>
+ |
+ = $startDate ?>
+ |
+
+
+
+ = $dateInMonth?>
+ |
+
+
+ = $bagMaterial['MaterialCode']?>
+ |
+
+
+ = $bagMaterial['customers']?>
+ |
+
+
+
+ oninput="openingStockChange(this)"
+ contenteditable="true"
+
+
+ >= $previousMonthBagStockDetails[$bagMaterialIndex]['balanceStock']??'0' ?> |
+
+ 0 |
+
+ 0 |
+
+ = $previousMonthBagStockDetails[$bagMaterialIndex]['balanceStock']??'0' ?> |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|