diff --git a/app/Controllers/Assetdetails.php b/app/Controllers/Assetdetails.php index a837f714..ddd3a208 100755 --- a/app/Controllers/Assetdetails.php +++ b/app/Controllers/Assetdetails.php @@ -346,7 +346,9 @@ class Assetdetails extends BaseController function checkAssetName(){ $data = $this->request->getPost(); - $result = $this->assetdetails_model->checkAssetName($data['assetName']); + $assetId = $data['assetId']??''; + $assetName = str_replace(" ","",$data['assetName']) ; + $result = $this->assetdetails_model->checkAssetName($assetId,$assetName); return $this->response->setJSON($result); } diff --git a/app/Controllers/Configurationctrl.php b/app/Controllers/Configurationctrl.php index 2a583b2b..68061b09 100755 --- a/app/Controllers/Configurationctrl.php +++ b/app/Controllers/Configurationctrl.php @@ -159,9 +159,12 @@ class Configurationctrl extends BaseController public function configNameCheck(){ $data = $this->request->getPost(); - $configName = ($data['configName']); + $configName = str_replace(" ","",$data['configName']); + $configId = $data['configId']; - $result = $this->configmodel->configNameCheck($configName); + $result = $this->configmodel->configNameCheck($configId,$configName); + + // dd($result); return $this->response->setJSON($result); diff --git a/app/Controllers/CostCenter.php b/app/Controllers/CostCenter.php index 62393226..c5825f51 100755 --- a/app/Controllers/CostCenter.php +++ b/app/Controllers/CostCenter.php @@ -136,7 +136,11 @@ class CostCenter extends BaseController function checkCostCenter(){ $data = $this->request->getPost(); - $result = $this->costcenter_model->checkCostCenter( $data['CostCenterName']); + + $CostCenterId = $data['CostCenterId']; + $CostCenterName = $data['CostCenterName']; + + $result = $this->costcenter_model->checkCostCenter( $CostCenterId,$CostCenterName); return $this->response->setJSON($result); } diff --git a/app/Controllers/Department.php b/app/Controllers/Department.php index 79866a19..0c2daa07 100755 --- a/app/Controllers/Department.php +++ b/app/Controllers/Department.php @@ -250,8 +250,10 @@ class Department extends BaseController function checkDepartmentName(){ $data = $this->request->getPost(); + $departmentName = str_replace(" ","",$data['departmentName']); + $depCode =$data['depCode']; $departmentName = $data['departmentName']; - $result = $this->department_model->checkDepartmentName($departmentName); + $result = $this->department_model->checkDepartmentName($depCode,$departmentName); return $this->response->setJSON($result); } diff --git a/app/Controllers/FactoryMachineController.php b/app/Controllers/FactoryMachineController.php index 41784c63..002f78dd 100644 --- a/app/Controllers/FactoryMachineController.php +++ b/app/Controllers/FactoryMachineController.php @@ -177,9 +177,11 @@ class FactoryMachineController extends BaseController $data = $this->request->getPost(); - $machineName = $data['machineName']; + $machineId = $data['machineId']; - $result = $this->factoryMachineMaster_model->where('machine_name',$machineName)->find(); + $machineName = str_replace(" ","", $data['machineName']); + + $result = $this->factoryMachineMaster_model->checkMachineName($machineId , $machineName); return $this->response->setJSON($result); diff --git a/app/Controllers/Rawmaterialdetails.php b/app/Controllers/Rawmaterialdetails.php index 85c9754a..e8e6744b 100755 --- a/app/Controllers/Rawmaterialdetails.php +++ b/app/Controllers/Rawmaterialdetails.php @@ -414,14 +414,16 @@ class Rawmaterialdetails extends BaseController function checkmaterial() { - $material = $this->request->getPost('id'); + $data = $this->request->getPost(); + $materialCode = $data['materialCode'] ?? ''; + $materialName = str_replace(' ', '', $data['materialName']); + $this->rawmaterialdetails_model = new rawmaterialdetails_model();; - $query = $this->rawmaterialdetails_model->checkMaterialExists($material); + $query = $this->rawmaterialdetails_model->checkMaterialExists($materialCode , $materialName); + + return $this->response->setJSON($query); - //if(!empty($material)){ - // echo json_encode($query); - //} } function exportmaterial() diff --git a/app/Controllers/StockController.php b/app/Controllers/StockController.php index faab92de..952f5bc0 100644 --- a/app/Controllers/StockController.php +++ b/app/Controllers/StockController.php @@ -129,7 +129,6 @@ class StockController extends BaseController $data['month'] = $formattedDate; return $this->loadViews("CoatingMachineDetail", $this->global, $data, NULL); - } public function addNewCoatingMachineDetails() @@ -194,7 +193,6 @@ class StockController extends BaseController // Set flashdata for success message return redirect()->to("/coatingMachineDetails?month=$month") ->with('success', $message1 . " " . $message2 . " " . $message3); - } catch (\Exception $error) { $this->db->transRollback(); return redirect()->back()->with('error', ' ' . $error->getMessage()); @@ -239,7 +237,6 @@ class StockController extends BaseController $message2 = 'And updated gas stock consumption.'; $message3 = "Warning..!! Kindly Update the next subsequent month Gas Stock If older month Gas Stock Updated..!!"; - } // Commit the transaction if all queries succeed @@ -255,7 +252,6 @@ class StockController extends BaseController // Set flashdata for success message return redirect()->to("/coatingMachineDetails?month=$month") ->with('success', $message1 . " " . $message2 . " " . $message3); - } else { throw new \Exception('Failed to update Coating machine details.'); } @@ -263,11 +259,6 @@ class StockController extends BaseController $this->db->transRollback(); return redirect()->back()->with('error', ' ' . $error->getMessage()); } - - - - - } public function deleteCoatingMachineDetails() @@ -316,9 +307,8 @@ class StockController extends BaseController $materialCodes = $this->rawmaterialdetails_model->getAllSilicaRawMaterialCode(); if (!empty($materialCodes)) { - $data['igrDetails'] = $this->inwardGateRegister_model->findIgrDetailsForIncomingSilicaSand($materialCodes, $month,$remark); - - } else { + $data['igrDetails'] = $this->inwardGateRegister_model->findIgrDetailsForIncomingSilicaSand($materialCodes, $month, $remark); + } else { $data['igrDetails'] = []; } @@ -331,7 +321,6 @@ class StockController extends BaseController $data['remark'] = $remark; return $this->loadViews("incomingSilicaSandDetails", $this->global, $data, NULL); - } public function updateIncomingSilicaSandDetails() @@ -345,7 +334,7 @@ class StockController extends BaseController $updates = []; foreach ($incomingSilicaSandDetailsData as $data) { - + $id = $data['id']; $dbData = [ @@ -379,84 +368,81 @@ class StockController extends BaseController ]; - + $resultExists = $this->incomingSilicaSandDetails_model ->where('id', $id) ->first(); - if(!empty($resultExists)){ - $dbData['id'] = $resultExists['id']; - $updates[] = $dbData ; - }else{ - $inserts[] = $dbData; - } - - + if (!empty($resultExists)) { + $dbData['id'] = $resultExists['id']; + $updates[] = $dbData; + } else { + $inserts[] = $dbData; + } } - if(!empty($updates)){ - $updated = $this->incomingSilicaSandDetails_model->updateBatch($updates,'id'); + if (!empty($updates)) { + $updated = $this->incomingSilicaSandDetails_model->updateBatch($updates, 'id'); } - if(!empty($inserts)){ + if (!empty($inserts)) { $inserted = $this->incomingSilicaSandDetails_model->insertBatch($inserts); } echo "Data Saved Successfully"; - } - public function updateLabReport(){ + public function updateLabReport() + { - $postData = $this->request->getPost(); + $postData = $this->request->getPost(); - $id = $postData['id']; + $id = $postData['id']; - $dbData = [ - 'igrNo_fk' =>$postData['igrNo'], - 'materialCode' => $postData['materialCode'], - '_10' => $postData['10Mm'], - '_20' => $postData['20Mm'], - '_30' => $postData['30Mm'], - '_40' => $postData['40Mm'], - '_50' => $postData['50Mm'], - '_70' => $postData['70Mm'], - '_100' => $postData['100Mm'], - '_140' => $postData['140Mm'], - '_200' => $postData['200Mm'], - '_300' => $postData['300Mm'], - 'pan' => $postData['pan'], - 'total' => $postData['total'], - 'plus20loss' => $postData['plus20Loss'], - 'plus30Loss' => $postData['plus30Loss'], - 'moistureSpec' => $postData['moistureSpec'], - 'moistureActual' => $postData['moistureActual'], - 'moistureLoss' => $postData['moistureLoss'], - 'moistureLossQty'=> $postData['moistureLossQty'], - 'sieveLossQty' => $postData['sieveLossQty'], - 'salableQty' => $postData['salableQty'], + $dbData = [ + 'igrNo_fk' => $postData['igrNo'], + 'materialCode' => $postData['materialCode'], + '_10' => $postData['10Mm'], + '_20' => $postData['20Mm'], + '_30' => $postData['30Mm'], + '_40' => $postData['40Mm'], + '_50' => $postData['50Mm'], + '_70' => $postData['70Mm'], + '_100' => $postData['100Mm'], + '_140' => $postData['140Mm'], + '_200' => $postData['200Mm'], + '_300' => $postData['300Mm'], + 'pan' => $postData['pan'], + 'total' => $postData['total'], + 'plus20loss' => $postData['plus20Loss'], + 'plus30Loss' => $postData['plus30Loss'], + 'moistureSpec' => $postData['moistureSpec'], + 'moistureActual' => $postData['moistureActual'], + 'moistureLoss' => $postData['moistureLoss'], + 'moistureLossQty' => $postData['moistureLossQty'], + 'sieveLossQty' => $postData['sieveLossQty'], + 'salableQty' => $postData['salableQty'], - ]; + ]; - $resultExists = $this->incomingSilicaSandDetails_model - ->where('id', $id) - ->first(); - if($resultExists){ + $resultExists = $this->incomingSilicaSandDetails_model + ->where('id', $id) + ->first(); + if ($resultExists) { $updated = $this->incomingSilicaSandDetails_model - ->update($id,$dbData); - }else{ + ->update($id, $dbData); + } else { $updated = $this->incomingSilicaSandDetails_model - ->insert($dbData); + ->insert($dbData); } - - if($updated){ - return redirect()->back()->with('success','Data Saved Successfully..!!'); - }else{ - return redirect()->back()->with('error','Error Saving Data..!!'); - } - + + if ($updated) { + return redirect()->back()->with('success', 'Data Saved Successfully..!!'); + } else { + return redirect()->back()->with('error', 'Error Saving Data..!!'); + } } @@ -545,10 +531,8 @@ class StockController extends BaseController $distinctMaterialCodes[] = $result[$index]['materialCode']; } $bagMaterials = $this->rawmaterialdetails_model->getSelectedBagMaterialCode($distinctMaterialCodes); - } else { $bagMaterials = $this->rawmaterialdetails_model->getAllBagMaterialCode(); - } @@ -576,7 +560,6 @@ class StockController extends BaseController $data['month'] = $formattedDate; return $this->loadViews("bagStockDetails", $this->global, $data, NULL); - } public function updateBagStockDetails() @@ -613,11 +596,9 @@ class StockController extends BaseController if (empty($resultExists)) { $inserts[] = $dbData; - } else { $dbData['id'] = $resultExists['id']; $updates[] = $dbData; - } } @@ -634,11 +615,9 @@ class StockController extends BaseController echo "Data Updated Successfully"; return; } - } echo "Data Saved Successfully"; - } @@ -679,7 +658,6 @@ class StockController extends BaseController $data['month'] = $formattedDate; return $this->loadViews("dustAndRoughStockDetails", $this->global, $data, NULL); - } public function updateDustAndRoughStockDetails() @@ -713,7 +691,6 @@ class StockController extends BaseController if (empty($resultExists)) { $inserts[] = $dbData; - } else { $updates[] = $dbData; } @@ -736,7 +713,6 @@ class StockController extends BaseController } echo "Data Saved Successfully"; - } @@ -825,11 +801,8 @@ class StockController extends BaseController $distinctMaterialCodes[] = $result[$index]['materialCode']; } $resinMaterials = $this->rawmaterialdetails_model->getSelectedResinMaterialCode($distinctMaterialCodes); - } else { $resinMaterials = $this->rawmaterialdetails_model->getAllResinMaterialCode(); - - } @@ -855,7 +828,6 @@ class StockController extends BaseController $data['month'] = $formattedDate; return $this->loadViews("resinStockDetails", $this->global, $data, NULL); - } public function updateResinStockDetails() @@ -898,7 +870,6 @@ class StockController extends BaseController $dbData['id'] = $resultExists['id']; $updates[] = $dbData; } - } @@ -919,7 +890,6 @@ class StockController extends BaseController } echo "Data Saved Successfully"; - } @@ -960,9 +930,10 @@ class StockController extends BaseController $endDate = date("Y-m-t", strtotime($startDate)); $data['gasStockDetails'] = $this->gasStockDetails_model - ->select('t_gasStockDetails.*, - t_drierMachineDetails.total_gas_consumption AS drierMachineGasConsumption, - t_drierMachineDetails.sand_dried_qty AS sandDried, + ->select( + 't_gasStockDetails.*, + drier_summary.drierMachineGasconsumption AS drierMachineGasConsumption, + drier_summary.driedSand AS sandDried, coating_summary.coatingMachineGasconsumption, coating_summary.coatedSand' ) @@ -981,10 +952,15 @@ class StockController extends BaseController 'left' ) ->join( - 't_drierMachineDetails', - 't_drierMachineDetails.date = t_gasStockDetails.date - AND t_drierMachineDetails.date >= ' . $this->db->escape($startDate) . ' - AND t_drierMachineDetails.date <= ' . $this->db->escape($endDate), + '(SELECT date, + SUM(total_gas_consumption) AS drierMachineGasconsumption, + SUM(sand_dried_qty) AS driedSand + FROM t_drierMachineDetails + WHERE date >= ' . $this->db->escape($startDate) . ' + AND date <= ' . $this->db->escape($endDate) . ' + GROUP BY date + ) AS drier_summary', + 'drier_summary.date = t_gasStockDetails.date', 'left' ) @@ -1108,8 +1084,6 @@ class StockController extends BaseController $updates[] = $result; - - } if (!empty($updates)) { @@ -1118,7 +1092,6 @@ class StockController extends BaseController } else { return 0; } - } else { @@ -1181,8 +1154,6 @@ class StockController extends BaseController ]; $opening = $balanceStock; - - } if (!empty($inserts)) { @@ -1191,7 +1162,6 @@ class StockController extends BaseController } else { return 0; } - } } @@ -1256,7 +1226,11 @@ class StockController extends BaseController $data['timeDropdown'] = $this->generateTimeOptions(); $data['supplierData'] = $this->supplier_model->supplierlisting(); - $data['drierDetails'] = $this->drierMachineDetails_model->where('date >=', $data['startDate'])->where('date <=', $data['endDate'])->findAll(); + $data['drierDetails'] = $this->drierMachineDetails_model->where('date >=', $data['startDate']) + ->where('date <=', $data['endDate']) + ->orderBy('date','asc') + ->findAll(); + if (!count($data['drierDetails'])) { //insert empty data $tempInsert = []; @@ -1265,7 +1239,10 @@ class StockController extends BaseController } $this->drierMachineDetails_model->insertBatch($tempInsert); - $data['drierDetails'] = $this->drierMachineDetails_model->where('date >=', $data['startDate'])->where('date <=', $data['endDate'])->findAll(); + $data['drierDetails'] = $this->drierMachineDetails_model->where('date >=', $data['startDate']) + ->where('date <=', $data['endDate']) + ->orderBy('date','asc') + ->findAll(); } $data['datefordropdown'] = $currentMonth; @@ -1279,11 +1256,34 @@ class StockController extends BaseController public function addOrEditdrierMachineDetails() { + $drierData = []; $drierData = json_decode($this->request->getPost('drierData'), true); + if (empty($drierData)) { - echo "No data received."; - return; + $additionalEntry = $this->request->getPost(); + if (!empty($additionalEntry)) { + $drierData[] = [ + 'Date' => $this->convertToDateWithFlexibleFormats($additionalEntry['Date'], ["d-m-Y", "Y-m-d", "m/d/Y", "m-d-Y"], "Y-m-d"), + 'Drier On Time' => $additionalEntry['Drier_On_Time'], + 'Drier Off Time' => $additionalEntry['Drier_Off_Time'], + 'Running Hrs' => $additionalEntry['Running_Hrs'], + 'Supplier Name' => $additionalEntry['Supplier_Name'], + 'i/p Sand Moisture(%)' => $additionalEntry['i/p_Sand_Moisture(%)'], + 'Tot Gas Consumption' => $additionalEntry['Tot_Gas_Consumption'], + 'Gas Per Ton' => $additionalEntry['Gas_Per_Ton'], + 'i/p Sand Qty' => $additionalEntry['i/p_Sand_Qty'], + 'Moisture Loss Qty' => $additionalEntry['Moisture_Loss_Qty'], + 'Sand Dried Qty' => $additionalEntry['Sand_Dried_Qty'], + 'Qty Per Hrs' => $additionalEntry['Qty_Per_Hrs'], + 'Dust Qty' => $additionalEntry['Dust_Qty'], + 'Customer Name' => $additionalEntry['Customer_Name'] + ]; + } else { + + echo "No data received."; + return; + } } $message1 = ''; @@ -1293,14 +1293,14 @@ class StockController extends BaseController try { foreach ($drierData as $row) { $data = [ - 'date' => DateTime::createFromFormat('d-m-Y', $row['Date'])->format('Y-m-d'), + 'date' => $this->convertToDateWithFlexibleFormats($row['Date'], ["d-m-Y", "Y-m-d", "m/d/Y", "m-d-Y"], "Y-m-d"), 'drier_on_time' => $row['Drier On Time'], 'drier_off_time' => $row['Drier Off Time'], 'drier_running_hours' => $row['Running Hrs'], 'supplier_name' => $row['Supplier Name'], 'input_sand_moisture' => $row['i/p Sand Moisture(%)'], 'total_gas_consumption' => $row['Tot Gas Consumption'], - 'gas_per_ton' => $row['Gas Pre Ton'], + 'gas_per_ton' => $row['Gas Per Ton'], 'input_sand_qty' => $row['i/p Sand Qty'], 'moisture_loss_qty' => $row['Moisture Loss Qty'], 'sand_dried_qty' => $row['Sand Dried Qty'], @@ -1310,7 +1310,7 @@ class StockController extends BaseController ]; // Check if a row with the same date already exists - $existingRow = $this->drierMachineDetails_model->where('date', $data['date'])->first(); + $existingRow = $this->drierMachineDetails_model->where('id', $row['id'] ?? '')->first(); $inserts = []; $updates = []; @@ -1330,7 +1330,6 @@ class StockController extends BaseController } $data['id'] = $existingRow['id']; $updates[] = $data; - } else { // If not, insert a new row //before inserting the row update gas stock @@ -1340,7 +1339,6 @@ class StockController extends BaseController $inserts[] = $data; - } if (!empty($inserts)) { @@ -1358,21 +1356,47 @@ class StockController extends BaseController if ($this->db->transStatus() === false) { throw new \Exception('Transaction failed due to database error.'); } - } $this->db->transCommit(); - echo "Data successfully saved. $message1"; - } catch (\Exception $e) { + + if (!empty($additionalEntry)) { + return redirect()->back()->with('success', " Data Saved Successfully..!!"); + } + + echo "Data saved successfully . $message1"; + + + } catch (\Exception $e) { // Rollback the transaction on any failure $this->db->transRollback(); echo "Failed to save/Update data: " . $e->getMessage(); } - - - } + + function convertToDateWithFlexibleFormats($dateInput, array $inputFormats, string $outputFormat): ?string + { + // If it's already a DateTime object, just format it + if ($dateInput instanceof DateTime) { + return $dateInput->format($outputFormat); + } + + // If it's a string, attempt to parse it + if (is_string($dateInput)) { + foreach ($inputFormats as $format) { + $date = DateTime::createFromFormat($format, $dateInput); + if ($date) { + return $date->format($outputFormat); + } + } + } + + return $dateInput; + } + + + public function factoryVehicleDieselDetails() { $currentMonth = $this->request->getPost('month') ? $this->request->getPost('month') : date('M-Y'); @@ -1437,7 +1461,6 @@ class StockController extends BaseController $this->global['pageTitle'] = 'Drier Details'; $this->loadViews("factoryDieselMachineDetails", $this->global, $data, NULL); - } public function getDieselConsumptionPivot($machineDetails, $startDate, $endDeate) @@ -1514,7 +1537,6 @@ class StockController extends BaseController if ($row['machine_id'] == 0) { // Summary data: if machine_id is 0, it indicates summary data. This distinction is used because these records will be stored in a separate table. $this->factoryVehicleDieselStockSummary_model->where('date', $row['date'])->set($row)->update(); - } else { // Diesel - factory vehicle data : @@ -1524,14 +1546,11 @@ class StockController extends BaseController } else { $this->factoryVehicleDieselDetails_model->insert($row); } - } - } echo "Data successfully saved."; - } @@ -1573,7 +1592,6 @@ class StockController extends BaseController $this->global['pageTitle'] = 'Power Consumption Details'; $this->loadViews("powerConsumptionDetails", $this->global, $data, NULL); - } public function getElectricConsumptionPivot($machineDetails, $startDate, $endDeate) @@ -1654,8 +1672,5 @@ class StockController extends BaseController echo "Data successfully saved."; - } - - } diff --git a/app/Controllers/Supplier.php b/app/Controllers/Supplier.php index 60800309..2e0a5441 100755 --- a/app/Controllers/Supplier.php +++ b/app/Controllers/Supplier.php @@ -309,11 +309,17 @@ class Supplier extends BaseController function checksupplier() { + + $supp_id = $this->request->getPost('supplierId') ?? ''; - $supp_name = $this->request->getPost('id'); + $supp_name = $this->request->getPost('supplierName'); + + $supp_name = str_replace(' ', '', $supp_name); - $query = $this->supplier_model->checkSupplierExists($supp_name); + $query = $this->supplier_model->checkSupplierExists($supp_id , $supp_name); + + return $this->response->setJSON($query); } @@ -467,11 +473,14 @@ class Supplier extends BaseController * check the Transporter exists? */ - function checkTransporter(){ + function checkTransporter(){ $data = $this->request->getPost(); - $message = $this->supplier_model->checkTransporter($data['transportername']); - return $this->response->setJSON($message); + $transporterId = $data['transporterid']??''; + $transporterName = $data['transportername']; + $message = $this->supplier_model->checkTransporter($transporterId,$transporterName); + + return $this->response->setJSON($message); } diff --git a/app/Models/Assetdetails_model.php b/app/Models/Assetdetails_model.php index ec3b3d0e..4cd4dee9 100755 --- a/app/Models/Assetdetails_model.php +++ b/app/Models/Assetdetails_model.php @@ -269,14 +269,20 @@ class Assetdetails_model extends Model } - function checkAssetName($assetName) + function checkAssetName($assetId,$assetName) { $builder = $this->db->table('t_asset_details') - ->select('t_asset_details.*') - ->where('AssetName', $assetName); - $query = $builder->get(); + ->select('t_asset_details.*'); + + if(!empty($assetId)){ + $builder = $builder->where('AssetCode !=', $assetId); + } + + $builder = $builder->where('REPLACE(AssetName , " ", "") ',$assetName); - return $query->getResultArray(); + $query = $builder->get(); + + return $query->getResultArray(); } diff --git a/app/Models/Config_model.php b/app/Models/Config_model.php index 1fddb1a9..f810f571 100755 --- a/app/Models/Config_model.php +++ b/app/Models/Config_model.php @@ -178,14 +178,17 @@ class Config_model extends Model return $query->getResult(); } - public function configNameCheck($configName){ - $builder = $this->db->table('t_configmaster') - ->where('ConfigName ', $configName); - $query = $builder->get(); + public function configNameCheck($configId,$configName){ + $builder = $this->db->table('t_configmaster'); - // dd( $this->db->getLastQuery()); + if(!empty($configId)){ + $builder = $builder -> where('Config_ID !=' ,$configId); + } + + $builder = $builder->where('REPLACE(ConfigName , " ", "") ',$configName); + $query = $builder->get(); - return $query->getResultArray(); + return $query->getResultArray(); } public function configValueCheck($configId , $configValue){ diff --git a/app/Models/Costcenter_model.php b/app/Models/Costcenter_model.php index f3ec9348..c23a0f47 100755 --- a/app/Models/Costcenter_model.php +++ b/app/Models/Costcenter_model.php @@ -429,10 +429,14 @@ where Dept.DEPCode not in return "Cost center $CostCenterCode deactivated successfully."; } - function checkCostCenter($CostCenterName){ + function checkCostCenter($CostCenterId,$CostCenterName){ $builder = $this->db->table('t_costcenter_master') - ->select('CostCenterName,IsActive') - ->where('CostCenterName', $CostCenterName); + ->select('CostCenterName,IsActive'); + + if(!empty($CostCenterId)){ + $builder = $builder -> where('id !=' ,$CostCenterId); + } + $builder = $builder->where('REPLACE(CostCenterName , " ", "") ',$CostCenterName); $query = $builder->get(); return $query->getResult(); diff --git a/app/Models/Department_model.php b/app/Models/Department_model.php index 97309b19..c5d87d7d 100755 --- a/app/Models/Department_model.php +++ b/app/Models/Department_model.php @@ -150,12 +150,18 @@ function getdepcode() } - function checkDepartmentName($departmentName){ - $builder = $this->db->table('t_departmentdetails') - ->where('DepartmentName', $departmentName); + function checkDepartmentName($depCode ,$departmentName){ + $builder = $this->db->table('t_departmentdetails'); + + if(!empty($depCode)){ + $builder = $builder -> where(' DEPCode !=', $depCode); + } + + $builder = $builder->where('REPLACE(DepartmentName , " ", "") ',$departmentName); $query = $builder->get(); $result =$query->getResultArray(); return $result; + } diff --git a/app/Models/FactoryMachineModel.php b/app/Models/FactoryMachineModel.php index 9f41778f..12fd7af4 100644 --- a/app/Models/FactoryMachineModel.php +++ b/app/Models/FactoryMachineModel.php @@ -38,5 +38,31 @@ class FactoryMachineModel extends Model // Skip validation (set to true to skip validation rules) protected $skipValidation = false; + + public function checkMachineName($machineId,$machineName){ + + $builder = $this->db->table('t_factoryMachineMaster'); + + if(!empty($machineId)){ + $builder = $builder->where('id !=' , $machineId); + } + + $builder = $builder->where('REPLACE(machine_name, " ", "") ',$machineName); + + $query = $builder->get(); + + + if ($query->getNumRows() > 0) { + return $query->getResultArray(); + } else { + return []; + } + + + } + + + + } diff --git a/app/Models/Ipinvoice_model.php b/app/Models/Ipinvoice_model.php index ad7999cf..ede1b0bb 100755 --- a/app/Models/Ipinvoice_model.php +++ b/app/Models/Ipinvoice_model.php @@ -348,7 +348,7 @@ class Ipinvoice_model extends Model ->join('ip_invoice_items b', 'a.invoice_id = b.invoice_id', 'left') ->join('ip_invoice_item_amounts c', 'b.item_id = c.item_id', 'left') ->where('a.invoice_date_created >=', $fiscalYearStartCurrent) - ->where('a.invoice_status_id', 2) + ->whereIn('a.invoice_status_id', [2,5]) ->groupBy("DATE_FORMAT(a.invoice_date_created, '%b')") ->orderBy('MONTH(a.invoice_date_created)'); @@ -360,7 +360,7 @@ class Ipinvoice_model extends Model ->join('ip_invoice_item_amounts c', 'b.item_id = c.item_id', 'left') ->where('a.invoice_date_created >=', $fiscalYearStartLast) ->where('a.invoice_date_created <', $fiscalYearStartCurrent) - ->where('a.invoice_status_id', 2) + ->whereIn('a.invoice_status_id', [2,5]) ->groupBy("DATE_FORMAT(a.invoice_date_created, '%b')") ->orderBy('MONTH(a.invoice_date_created)'); @@ -412,8 +412,8 @@ class Ipinvoice_model extends Model SUM(iia.item_cgst_amt) AS 'CGST', SUM(iia.item_sgst_amt) AS 'SGST', SUM(iia.item_igst_amt) AS 'IGST', - SUM(IFNULL(tcs.tax_rate_percent * iia.item_total / 100, 0)) AS 'TCS', - SUM(IFNULL(tcs.tax_rate_percent * iia.item_total / 100, 0)) + SUM(iia.item_total) AS 'Total' + truncate(SUM(IFNULL(tcs.tax_rate_percent * iia.item_total / 100, 0)),2) AS 'TCS', + truncate(SUM(IFNULL(tcs.tax_rate_percent * iia.item_total / 100, 0)) + SUM(iia.item_total),2) AS 'Total' ") ->join('ip_invoice_custom icf', 'icf.invoice_id = ii.invoice_id', 'left') ->join('ip_invoice_tax_rates tc', 'tc.invoice_id = ii.invoice_id', 'left') @@ -425,7 +425,7 @@ class Ipinvoice_model extends Model ->join('ip_tax_rates igst', 'igst.tax_rate_id = iit.igst_item_tax_rate_id', 'left') ->join('ip_tax_rates tcs', 'tcs.tax_rate_id = tc.tax_rate_id', 'left') ->where('icf.invoice_custom_fieldid', $vehicleCustomFieldId) - ->where('ii.invoice_status_id', 2) + ->whereIn('ii.invoice_status_id', [2,5]) ->where('ii.invoice_date_created', date('Y-m-d')) ->groupBy('ii.invoice_number, iit.item_description') ->orderBy('ii.invoice_number'); diff --git a/app/Models/Rawmaterialdetails_model.php b/app/Models/Rawmaterialdetails_model.php index 82396724..f55d0740 100755 --- a/app/Models/Rawmaterialdetails_model.php +++ b/app/Models/Rawmaterialdetails_model.php @@ -313,20 +313,21 @@ class Rawmaterialdetails_model extends Model // $this->db->update('T_PurchaseOrderDetails', $POInfo); // return $this->db->affectedRows(); // } - function checkMaterialExists($material) + function checkMaterialExists($materialCode , $materialName) { - // $sql="SELECT MaterialCode, MaterialName, MaterialType, Category,REPLACE(MaterialName, ' ', '') - // FROM t_materialmaster - // WHERE REPLACE(MaterialName, ' ', '') LIKE REPLACE('%'".$material."'%', ' ', '')"; - - $builder = $this->db->table('t_materialmaster') - ->select('MaterialCode,MaterialName,MaterialType,Category,IsActive') - ->like('REPLACE(MaterialName, " ", "")', $material); + ->select('MaterialCode,MaterialName,MaterialType,Category,IsActive'); + if(!empty($materialCode)){ + $builder = $builder->where('MaterialCode !=' , $materialCode); + } + $builder->where('REPLACE(MaterialName, " ", "")' , $materialName); $query = $builder->get(); - //print_r($query-getResult()); - return $query->getResult(); + if ($query->getNumRows() > 0) { + return $query->getResultArray(); + } else { + return []; + } } function checkMaterialCategory($mc) diff --git a/app/Models/Supplier_model.php b/app/Models/Supplier_model.php index 03dd3f8c..c2e69512 100755 --- a/app/Models/Supplier_model.php +++ b/app/Models/Supplier_model.php @@ -53,16 +53,17 @@ class Supplier_model extends Model } - function checkTransporter($transporterName){ - $builder = $this->db->table('t_transporter') - ->where('name', $transporterName); + function checkTransporter($transporterId,$transporterName){ + $builder = $this->db->table('t_transporter'); + if(!empty($transporterId)){ + $builder = $builder->where('id !=',$transporterId); + } + $builder = $builder->where('REPLACE(name , " ", "") ',$transporterName); $query = $builder->get(); - + return $query->getResult(); } - - function deleteTransporter($Sid, $SupplierInfo){ $builder = $this->db->table('t_transporter') @@ -198,15 +199,20 @@ class Supplier_model extends Model return $query->getResultArray(); } - function checkSupplierExists($supp_name) + function checkSupplierExists($supp_id,$supp_name) { - $builder = $this->db->table('t_supplierdetailsn') - ->select('SupplierID,SupplierName,Address,IsActive') - ->like('REPLACE(SupplierName, " ", "")', $supp_name); + $builder = $this->db->table('t_supplierdetailsn'); + $builder = $builder->select('SupplierID, SupplierName, Address, IsActive'); + + if(!empty($supp_id)){ + $builder = $builder->where('SupplierID !=' , $supp_id); + } + + $builder = $builder->where('REPLACE(SupplierName, " ", "") ',$supp_name); $query = $builder->get(); - + if ($query->getNumRows() > 0) { return $query->getResultArray(); } else { diff --git a/app/Views/addRawMaterial.php b/app/Views/addRawMaterial.php index f3a388f4..89c0ed44 100755 --- a/app/Views/addRawMaterial.php +++ b/app/Views/addRawMaterial.php @@ -293,19 +293,20 @@ $('#MaterialName').change(function() { - var materialname = $('#MaterialName').val().trim(); + var materialName = $('#MaterialName').val(); + var materialCode = ''; - if(materialname == ''){ + if(materialName == ''){ return; } - //material = material.replace(/\s*$/,""); - var material = materialname.replace(/ /g, ''); - //alert(m.length+" "+m+" "+s+" "+s.length); + var material = materialName.replace(/ /g, ''); + $('#loader').show(); $.ajax({ data: { - id: material + materialCode, + materialName }, type: "POST", url: "materialExist", @@ -335,9 +336,9 @@ } }, - error: function() { + error: function(error) { $('#loader').hide(); - alert("Error Occur"); + alert("Error Occur" ,error); }, complete: function(){ $('#loader').hide(); diff --git a/app/Views/addSupplier.php b/app/Views/addSupplier.php index b6cc9f3b..4de6577b 100755 --- a/app/Views/addSupplier.php +++ b/app/Views/addSupplier.php @@ -258,14 +258,16 @@ } $('#supplierName').change(function() { - var suppliername = $('#supplierName').val(); - var supplier = suppliername.replace(/ /g, ''); + var supplierName = $('#supplierName').val().trim(); + var supplierId = $('#SupplierID').val(); + $('#loader').show(); $.ajax({ type: "POST", url: "", data: { - id: supplier + supplierId , + supplierName }, success: function(data) { var count = data?data.length:0; diff --git a/app/Views/addasset.php b/app/Views/addasset.php index 02e72ca6..5a6c2770 100755 --- a/app/Views/addasset.php +++ b/app/Views/addasset.php @@ -25,7 +25,7 @@
- +
@@ -433,14 +433,15 @@ $('#AssetName').on('change',function(){ -let assetName = $(this).val(); +let assetName = $(this).val().trim(); +let assetId = $('#AssetCode').val() ?? ''; $('#loader').show(); $.ajax({ type:'POST', url:'assetdetails/checkAssetName', - data:{assetName}, + data:{assetId,assetName}, success: function(data){ if(data && data.length>0){ let IsActive = data[0].IsActive; diff --git a/app/Views/addconfig.php b/app/Views/addconfig.php index 6d41b5c2..b61ae06f 100755 --- a/app/Views/addconfig.php +++ b/app/Views/addconfig.php @@ -391,17 +391,18 @@ $('#configurationname').change(function () { $('#loader').show(); $.ajax({ - data: {configName: $('#configurationname').val()}, + + data: {configName: $('#configurationname').val().trim() , configId : $('#ConfigId').val()??''}, type: 'POST', url: "configurationctrl/configNameCheck", - success: function (data) { + success: function (data) { if(data && data.length > 0){ - + if(data[0].isActive == 1){ alert("This Configuration Name is already present. kindly change it..!!"); - $('#configurationname').val(''); - return; + $('#configurationname').val(''); + return; }else{ alert("This Configuration Name is already present in deleted section. kindly reactivate it If needed..!!"); $('#configurationname').val(''); diff --git a/app/Views/adddepartment.php b/app/Views/adddepartment.php index db26a475..707b24e4 100755 --- a/app/Views/adddepartment.php +++ b/app/Views/adddepartment.php @@ -155,11 +155,12 @@ + + + \ No newline at end of file diff --git a/app/Views/editOldasset.php b/app/Views/editOldasset.php index ee4f7d1a..f0cc7847 100755 --- a/app/Views/editOldasset.php +++ b/app/Views/editOldasset.php @@ -163,7 +163,7 @@ if (!empty($assetList)) {
- +
@@ -428,14 +428,15 @@ if (!empty($assetList)) { $('#AssetName').on('change',function(){ - let assetName = $(this).val(); + let assetId = $('#AssetCode').val(); + let assetName = $(this).val().trim(); $('#loader').show(); $.ajax({ type:'POST', url:'assetdetails/checkAssetName', - data:{assetName}, + data:{assetId,assetName}, success: function(data){ if(data && data.length>0){ let IsActive = data[0].IsActive; @@ -452,7 +453,7 @@ if (!empty($assetList)) { }, error: function(error){ //error - console.error('error ocurred' + error); + console.error( error); }, complete :function (){ $('#loader').hide(); diff --git a/app/Views/editRawmaterial.php b/app/Views/editRawmaterial.php index 5d9929b6..abf8f109 100755 --- a/app/Views/editRawmaterial.php +++ b/app/Views/editRawmaterial.php @@ -440,18 +440,20 @@ if ($total <= $reorder) { $('#MaterialName').change(function() { - var materialname = $('#MaterialName').val(); + var materialName = $('#MaterialName').val(); + var materialCode = $('#RMcode').val(); - if(materialname == ''){ + if(materialName == ''){ return; } - var material = materialname.replace(/ /g, ''); + var material = materialName.replace(/ /g, ''); $('#loader').show(); $.ajax({ data: { - id: material + materialCode, + materialName }, type: "POST", url: "materialExist", diff --git a/app/Views/editSupplier.php b/app/Views/editSupplier.php index 944521a9..17ad6115 100755 --- a/app/Views/editSupplier.php +++ b/app/Views/editSupplier.php @@ -596,16 +596,19 @@ if (!empty($supplier)) { //Call to ajax existing PAN $('#supplierName').change(function () { - var suppliername = $('#supplierName').val(); - var supplier = suppliername.replace(/ /g, ''); + var supplierName = $('#supplierName').val().trim(); + var supplierId = $('#SupplierID').val(); + $('#loader').show(); - $.ajax({ + $.ajax({ type: "POST", url: "", data: { - id: supplier + supplierId , + supplierName }, success: function (data) { + console.log(data) var count = data.length; if (count >= 1) { $('#loader').hide(); @@ -618,21 +621,16 @@ if (!empty($supplier)) { $.each(data, function (i, obj) { related_supplier += obj.SupplierID + " - " + obj.SupplierName + " - " + obj.Address + "\n"; }); - alert("'" + suppliername + "' - supplier details are , " + " \n \n" + related_supplier); + alert("'" + supplierName + "' - supplier details are , " + " \n \n" + related_supplier); $("#supplierName").val(''); $("#supplierName").focus(); } else { $('#loader').hide(); - //4Debug - // alert('This is New Supplier! '); } - //4Debug - //console.log(data); + }, error: function (error) { $('#loader').hide(); - //4Debug - // alert("Error Occur"); console.error("an error occur supplierExist", error) } diff --git a/app/Views/editconfig.php b/app/Views/editconfig.php index 0d93f07a..b68609fe 100755 --- a/app/Views/editconfig.php +++ b/app/Views/editconfig.php @@ -496,7 +496,10 @@ if (!empty($master)) { $('#ConfigName').change(function () { $('#loader').show(); $.ajax({ - data: { configName: $('#ConfigName').val() }, + data: { + configName: $('#ConfigName').val().trim(), + configId : $('#ConfigId').val().trim() + }, type: 'POST', url: "configurationctrl/configNameCheck", success: function (data) { diff --git a/app/Views/editdepartment.php b/app/Views/editdepartment.php index 35c1be6b..d9449a6b 100755 --- a/app/Views/editdepartment.php +++ b/app/Views/editdepartment.php @@ -168,4 +168,43 @@
-
\ No newline at end of file + + + + \ No newline at end of file diff --git a/app/Views/factoryMachineMasterDetailsForm.php b/app/Views/factoryMachineMasterDetailsForm.php index eec20a97..acf72a75 100644 --- a/app/Views/factoryMachineMasterDetailsForm.php +++ b/app/Views/factoryMachineMasterDetailsForm.php @@ -52,6 +52,8 @@ $energyType = $masterData['energy_type'] ?? '';
+ +
+ + +
@@ -123,12 +128,13 @@ $energyType = $masterData['energy_type'] ?? '';