diff --git a/app/Controllers/StockController.php b/app/Controllers/StockController.php index 3be86c1e..d0fd93ac 100644 --- a/app/Controllers/StockController.php +++ b/app/Controllers/StockController.php @@ -11,6 +11,7 @@ use App\Models\FactoryVehicleDieselStockSummaryModel; use App\Models\IncomingSilicaSandDetailsModel; use App\Models\Inwardgateregister_model; use App\Models\Rawmaterialdetails_model; +use App\Models\BagStockDetailsModel; use CodeIgniter\HTTP\ResponseInterface; use DateTime; @@ -26,6 +27,8 @@ class StockController extends BaseController protected $incomingSilicaSandDetails_model; protected $inwardGateRegister_model; protected $rawmaterialdetails_model; + protected $bagStockDetails_model; + protected $Rawmaterialdetails_model; /** * This is default constructor of the class @@ -42,6 +45,8 @@ class StockController extends BaseController $this->rawmaterialdetails_model = new Rawmaterialdetails_model(); $this->incomingSilicaSandDetails_model = new IncomingSilicaSandDetailsModel(); $this->inwardGateRegister_model = new Inwardgateregister_model(); + $this->bagStockDetails_model = new BagStockDetailsModel(); + $this->session = session(); helper('form'); @@ -257,15 +262,133 @@ class StockController extends BaseController public function loadView_bagStockDetails(){ + 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']='Bag Stock Details'; - return $this->loadViews("bagStockDetails", $this->global, $data, NULL); + $startDate = "$month-01"; + $endDate = date("Y-m-t", strtotime($startDate)); + $data['bagStockDetails'] = $this->bagStockDetails_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['groupedBagStockDetails'] = []; + + // Temporary array to store grouped data by date + $groupedByDate = []; + + // Group by 'date' + foreach ($data['bagStockDetails'] 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['groupedBagStockDetails'] = array_values($groupedByDate); + + + + $bagMaterials= $this->rawmaterialdetails_model->getAllBagMaterialCode(); + + + + foreach($bagMaterials as $key => $bagMaterial){ + $materialCode = $bagMaterial['MaterialCode']; + $bagMaterials[$key]['customers'] = $this->bagStockDetails_model + ->select('customer') + ->where('date >=', $startDate) + ->where('date <=', $endDate) + ->where('materialCode', $materialCode) + ->first()['customer'] ?? ''; + } + + $bagMaterialcount = count($bagMaterials); + + $data['bagMaterialcount'] = $bagMaterialcount; + $data['bagMaterials'] = $bagMaterials; + + $date = DateTime::createFromFormat('Y-m', $month); + + $formattedDate = $date->format('M-Y'); + + $data['month']=$formattedDate; + + return $this->loadViews("bagStockDetails", $this->global, $data, NULL); } - public function updateBagStockDetails(){} + public function updateBagStockDetails(){ + + $postData = $this->request->getPost(); + + $updateBagStockDetailsData = json_decode($postData['updateBagStockDetails'], true); + + foreach($updateBagStockDetailsData 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->bagStockDetails_model + ->where('date',$date) + ->where('materialCode',$materialCode) + ->first(); + + + if(!empty($resultExists)){ + + $updated=$this->bagStockDetails_model + ->where('date',$date) + ->where('materialCode',$materialCode) + ->set($dbData) + ->update(); + + }else{ + $inserted = $this->bagStockDetails_model->insert($dbData); + } + + } + + echo "Data Saved Successfully"; + + } diff --git a/app/Models/Rawmaterialdetails_model.php b/app/Models/Rawmaterialdetails_model.php index f5d792f3..45981afe 100755 --- a/app/Models/Rawmaterialdetails_model.php +++ b/app/Models/Rawmaterialdetails_model.php @@ -136,6 +136,20 @@ class Rawmaterialdetails_model extends Model return $materialCodes = array_column($materialResults, 'MaterialCode'); } + function getAllBagMaterialCode(){ + + $builder = $this->db->table('t_materialmaster') + ->select('MaterialCode , MaterialName') + ->where('IsActive', 1) + ->where('Category', 'bag') + ->orderBy('MaterialCode', 'asc'); + $query = $builder->get(); + $materialResults = $query->getResultArray(); + + return $materialResults; + + } + function getMaterialstock($MaterialCode, $currentdate) diff --git a/app/Views/bagStockDetails.php b/app/Views/bagStockDetails.php index cfde7953..ff8bd25c 100644 --- a/app/Views/bagStockDetails.php +++ b/app/Views/bagStockDetails.php @@ -105,9 +105,10 @@ border: 1px solid #ccc; color: #ffffff; font-weight: bold; - padding: 2px 4px; + padding: 6px 10px;; text-align: center; } + ._Separador { background-color: #fff; @@ -124,6 +125,7 @@ .celda_normal { /*background-color: #fff;*/ /* */ + text-align: center; border: 1px solid #ccc; padding: 2px 4px; } @@ -195,12 +197,9 @@
| material | +material | - -material 1 | - -material 2 | + + + ++ = $bagMaterial['MaterialName']?> + + | +|||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Customer | +|||||||||||||
| Customer | + + -- + | + = $bagMaterial['customers']?> | -- | - + +||||||||||
| Date | - - - - -Opening | -Receipt | -Used | -Balance Stock | - - - - -Opening | -Receipt | -Used | -Balance Stock | +|||||
| Date | + + + + + +Opening Stock | +Receipt | +Used | +Balance Stock | +|||||||||
| + = $startDate ?> + | + + + + + + + ++ oninput="openingStockChange(this)" + contenteditable="true" + + + >= $bagStock['opening']?> + | + ++ = $bagStock['receipt']?> + | + += $bagStock['used']?> + | + ++ = $bagStock['balanceStock']?> + | + + +|||||||||
| 23-10-2024 | - - - -472 | -11212 | -- | -472 | + $bagMaterial){ ?> + - - - -472 | -11212 | -- | -472 | - + + format('d-m-Y'); + ?> ++ = $startDate ?> + | + + + + + + + ++ + oninput="openingStockChange(this)" + contenteditable="true" + + + >0 | + +0 | + +0 | + +0 | +
| 24-10-2024 | - - - -472 | -11212 | -- | -472 | - - - - -472 | -11212 | -- | -472 | - - -|||||