donation/app/Models/InvoiceModel.php

45 lines
1.8 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();
}
}