donation/app/Models/CustomerModel.php

87 lines
3.6 KiB
PHP

<?php
namespace App\Models;
use CodeIgniter\Model;
class CustomerModel extends Model
{
protected $table = 'donor';
protected $primaryKey = 'donor_id ';
// protected $allowedFields = ['donor_id ','first_name','city','last_name','email','mobile_no','country','state','postal_code' ,'address','profile_picture','date_of_birth','gender','mode','isactive','business_id'];
protected $allowedFields = ['donor_id ','first_name','city','last_name','email','mobile_no','country','state','postal_code' ,'address','org_name','date_of_birth','pan_no','adhar_no','org_reg_details','donor_type','isactive','business_id','created_by','updated_by'];
public function insertCustomer($data)
{
return $this->insert($data);
}
public function saveGroupDetails($data){
$id = $data['group_id'];
if($id != ''){
unset($data['group_id']); // Remove the id from the data to avoid updating it
unset($data['created_by']); // bcoz here data Updating here.
if ($this->db->table('donor_groups')->where('group_id', $id)->update($data)) {
$affectedRows = $this->db->affectedRows();
$statement['success'] = 'Customer Group has been updated successfully.';
$statement['error'] = "";
$statement['log'] = "Customer Group: has been updated successfully. Updated Customer Group ID = " .$id." Affected Rows = ".$affectedRows;
} else {
$statement['success'] = "";
$statement['error'] = 'Customer group update failed. Please try again.';
$statement['log'] = "Customer Group: Err Failed to update ID = " .$id ;
}
}else{
unset($data['updated_by']);
if ($this->db->table('donor_groups')->insert($data)) {
$insertID = $this->db->insertID();
$statement['success'] = 'Customer Group has been Inserted successfully.';
$statement['error'] = "";
$statement['log'] = "Customer Group : has been added successfully. Inserted ID = " .$insertID ;
} else {
$statement['success'] = "";
$statement['error'] = "Customer could not be added. Please try again..";
$statement['log'] = "Customer: Err could not be added. Please try again.";
}
}
return $statement;
}
public function getGroupDetails($business_id)
{
return $this->db->table('donor_groups as CG' )
->join('users as U1', 'U1.user_id = CG.created_by', 'left')
->join('users as U2', 'U2.user_id = CG.updated_by', 'left')
->select('CG.group_id,CG.group_name,CG.created_on,CG.created_by,CG.updated_on,CG.updated_by,DATE_FORMAT(CG.created_on, "%d/%m/%Y %h:%i %p") AS formatted_created_on,concat(U1.first_name," ",U1.last_name) as created_by_name,concat(U2.first_name," ",U2.last_name) as updated_by_name,CG.isactive')
->where(['CG.group_name != ' => 'EXPIRYDATE'])
->where('CG.business_id', $business_id)
// ->where(['CG.isactive' => 1])
->get()
->getResultArray();
}
public function getReceiptDetailsByDonorId($donorId)
{
return $this->db->table('receipt')
->select('receipt.receipt_number, receipt.donor_id, receipt.amount, receipt.currency,receipt.receipt_date, d.first_name')
->join('donor as d', 'd.donor_id = receipt.donor_id', 'left') // Adjust columns accordingly
->where('receipt.donor_id', $donorId) // Specify the table alias for the column in the where clause
->get()
->getResult();
}
public function getData($table, $where = null)
{
$query = $this->db->table($table);
if ($where) {
$query->where($where);
}
return $query->get()->getResult();
}
}
?>