donation/app/Models/BusinessModel.php

107 lines
3.7 KiB
PHP

<?php
namespace App\Models;
use CodeIgniter\Model;
class BusinessModel extends Model
{
protected $table = 'business';
protected $primaryKey = 'business_id';
protected $allowedFields = ['business_id','title','email','mobile_no','terms','address','city','state','postal_code' ,'business_logo','isactive', 'pan_no', 'org_reg_no', '80G', 'signature','favicon','start_no','left_pad','prefix_format','site_name','site_title','site_mobile','site_info','admin_email','terms_service','footer_about','copyright','pagination_limit','about_info','country','currency','12AA','80G_vaildupto','12AA_vaildupto'];
public function insertBusiness($data)
{
return $this->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;
}
}
?>