insert($data); } public function getBranchesByBusinessId($businessId) { return $this->db->table('business_branches') ->where('business_id', $businessId) ->where('isactive', 1) ->get() ->getResultArray(); } public function insertDonationBusiness($businessId) { $donationData = $this->db->table('donations_accepted') ->get() ->getResultArray(); if (!empty($donationData)) { $insertData = []; foreach ($donationData as $donation) { $insertData[] = [ 'bussiness_id' => $businessId, 'donation_id' => $donation['id'], 'name' => $donation['name'], 'is_active'=>1 // Add other columns as needed ]; } // Insert data into donation_business table $this->db->table('donation_business')->insertBatch($insertData); } } public function getDonationBusinessData($businessId) { return $this->db->table('donation_business') ->where('bussiness_id', $businessId) ->get() ->getResultArray(); } public function updateDonationData($businessId, $selectedDonations) { // Fetch all donation data for the given businessId $donationData = $this->db->table('donation_business') ->where('bussiness_id', $businessId) ->get() ->getResultArray(); foreach ($donationData as $donation) { $donationId = $donation['donation_id']; $isActive = in_array($donationId, $selectedDonations) ? 1 : 0; // Update donations_accepted table based on selected options $donationUpdateData = ['is_active' => $isActive]; $donationWhere = ['id' => $donationId]; $this->db->table('donation_business') ->where($donationWhere) ->update($donationUpdateData); } } public function inactiveMissingBuinessBranchDetails($where,$missingValues){ $dataToUpdate = ['isactive' => 0]; $this->db->table('business_branches')->where($where)->whereIn('id',$missingValues)->update($dataToUpdate); } public function saveBuinessBranchDetails($data){ $i = 0; $statement = []; foreach ($data as $row) { $id = $row['id']; if($id != ''){ unset($row['id']); // Remove the id from the data to avoid updating it $this->db->table('business_branches')->where('id', $id)->update($row);// Update the row with the specified id $affectedRows = $this->db->affectedRows(); $statement[$i] = "business branches id - ".$id." ". ($affectedRows ? " Updated":" Nothing to Updated"); }else{ $this->db->table('business_branches')->insert($row); $insertID = $this->db->insertID(); $statement[$i] = "business branches id - ".$insertID." Inserted"; } $i++; } return $statement; } } ?>