101 lines
2.6 KiB
PHP
101 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class CreditNoteModel extends Model
|
|
{
|
|
protected $table = 'ip_credit_notes';
|
|
protected $primaryKey = 'creditnote_id';
|
|
protected $useAutoIncrement = false; // Since creditnote_id is BIGINT and not auto-incremented
|
|
|
|
protected $allowedFields = [
|
|
'creditnote_id',
|
|
'creditnote_number',
|
|
'status',
|
|
'reference_number',
|
|
'date',
|
|
'total',
|
|
'balance',
|
|
'customer_id',
|
|
'customer_name',
|
|
'applied_invoices',
|
|
'is_digitally_signed',
|
|
'is_edited_after_sign',
|
|
'is_emailed',
|
|
'is_signature_enabled_in_template',
|
|
'has_attachment',
|
|
'salesperson_name',
|
|
'salesperson_id',
|
|
'is_viewed_by_client',
|
|
'client_viewed_time',
|
|
'color_code',
|
|
'current_sub_status_id',
|
|
'current_sub_status',
|
|
'item_quantity',
|
|
'item_price',
|
|
'item_total_price',
|
|
'item_total',
|
|
'item_total_without_tax',
|
|
'currency_id',
|
|
'currency_code'
|
|
];
|
|
|
|
protected $useTimestamps = false; // Enable if you have created_at/updated_at fields
|
|
|
|
/**
|
|
* Fetch all credit notes
|
|
*/
|
|
// public function getAllCreditNotes($fromDate,$toDate)
|
|
// {
|
|
// return $this->where('date >=', $fromDate )
|
|
// ->where('date <=', $toDate )
|
|
// ->orderBy('date', 'DESC')
|
|
// ->findAll();
|
|
// }
|
|
|
|
public function getAllCreditNotes($fromDate, $toDate)
|
|
{
|
|
return $this->select('ip_credit_notes.*, ip_credit_notes_items.name as item_name')
|
|
->join('ip_credit_notes_items', 'ip_credit_notes.creditnote_id = ip_credit_notes_items.creditnote_id', 'left')
|
|
->where('ip_credit_notes.date >=', $fromDate)
|
|
->where('ip_credit_notes.date <=', $toDate)
|
|
->orderBy('ip_credit_notes.date', 'DESC')
|
|
->findAll();
|
|
}
|
|
|
|
|
|
/**
|
|
* Fetch a single credit note by ID
|
|
*/
|
|
public function getCreditNoteById($id)
|
|
{
|
|
return $this->where('creditnote_id', $id)->first();
|
|
}
|
|
|
|
/**
|
|
* Insert a new credit note
|
|
*/
|
|
public function createCreditNote($data)
|
|
{
|
|
return $this->insert($data);
|
|
}
|
|
|
|
/**
|
|
* Update an existing credit note
|
|
*/
|
|
public function updateCreditNote($id, $data)
|
|
{
|
|
return $this->update($id, $data);
|
|
}
|
|
|
|
/**
|
|
* Delete a credit note by ID
|
|
*/
|
|
public function deleteCreditNote($id)
|
|
{
|
|
return $this->delete($id);
|
|
}
|
|
}
|