donation/app/Models/InvoiceModel.php
2024-06-01 05:30:03 +00:00

66 lines
3.1 KiB
PHP

<?php
namespace App\Models;
use CodeIgniter\Model;
class InvoiceModel extends Model
{
protected $table = 'receipt';
protected $primaryKey = 'receipt_id';
protected $allowedFields = ['receipt_id', 'receipt_number', 'donor_id','notes','amount', 'payment_mode', 'business_id', 'created_on', 'created_by', 'updated_on', 'updated_by','isactive', 'payment_ref_no', 'receipt_date','causes_id','campaign_id','receipt_header','reason','currency','receipt_type'];
public function updateData($table, $data, $where)
{
$this->db->table($table)->update($data, $where);
$affected_rows = $this->db->affectedRows();
return $affected_rows;
}
public function getData($table, $where = null)
{
$query = $this->db->table($table);
if ($where) {
$query->where($where);
}
return $query->get()->getResult();
}
## gethering Donor receipt Details for PDF.
public function getInvoiceData($id)
{
// Fetch invoice data
return $this->db->table('receipt')
->where('receipt_id', $id)
->join('donor as C','C.donor_id= receipt.donor_id','left')
->join('causes as D','D.causes_id= receipt.causes_id','left')
->join('business as B','B.business_id = receipt.business_id','left')
->select('receipt.*,CONCAT(C.first_name, IFNULL(CONCAT(" ", C.last_name), "")) as customer_name,C.address, C.postal_code,C.city, C.state,C.mobile_no as customer_mobile, C.pan_no as cust_pan_no, D.name as cause_name,C.org_name as cust_org_name')
->select('B.title ,B.business_logo,B.terms,B.address as org_address ,B.city as org_city,B.state as org_state,B.postal_code as org_zip,B.email as org_email,B.mobile_no as org_mobile, B.pan_no as org_pan, B.org_reg_no, B.signature')
->get()
->getResult();
}
function export_excel($business_id)
{
$builder = $this->db->table('donor')
->select('CONCAT_WS(" ", donor.first_name, donor.last_name) AS full_name')
->select('donor.donor_type,donor.org_name,donor.org_reg_details,donor.mobile_no,donor.email,donor.pan_no,donor.adhar_no,donor.passport_no,donor.address,donor.country,donor.state,donor.city,donor.postal_code')
->select('CONCAT_WS(" ", creator.first_name, creator.last_name) AS creator_name')
->select('CONCAT_WS(" ", updater.first_name, updater.last_name) AS updater_name')
->select('IFNULL(DATE_FORMAT(donor.created_on, "%d-%m-%Y"), "-") AS formatted_created_on')
->select('IFNULL(DATE_FORMAT(donor.updated_on, "%d-%m-%Y"), "-") AS formatted_updated_on')
->select('CASE WHEN donor.isactive = 1 THEN "Active" ELSE "Inactive" END AS active_status', false)
->join('users as creator', ' donor.created_by = creator.user_id', 'left')
->join('users as updater', ' donor.updated_by = updater.user_id', 'left')
->where('donor.business_id', $business_id);
$query = $builder->get();
return $query->getResultArray();
}
public function bulkInsert($data) {
return $this->db->table('donor')->insertBatch($data);
}
}