ria/app/Models/BagStockDetailsModel.php
2025-02-05 19:29:02 +05:30

59 lines
1.9 KiB
PHP

<?php
namespace App\Models;
use CodeIgniter\Model;
class BagStockDetailsModel extends Model
{
protected $table = 't_bagstockdetails';
protected $returnType = 'array';
protected $useSoftDeletes = false;
protected $protectFields = true;
protected $allowedFields = [
'date', 'materialCode', 'customer', 'opening', 'receipt', 'used', 'balanceStock'
];
protected bool $allowEmptyInserts = false;
protected bool $updateOnlyChanged = true;
// Dates
protected $useTimestamps = false;
protected $dateFormat = 'datetime';
// Validation
protected $validationRules = [];
protected $validationMessages = [];
protected $skipValidation = false;
protected $cleanValidationRules = true;
/**
* Custom method to handle composite key updates.
* @param array $data Array of records to be updated in bulk.
* @return bool
*/
public function getBagStockForGivenMonth($startDate, $endDate, $filterMaterialCode)
{
$builder = $this->db->table('t_bagstockdetails')
->select('t_bagstockdetails.*')
->where('date >=', $startDate)
->where('date <=', $endDate);
if (!empty($filterMaterialCode)) {
$builder->whereIn('materialCode', $filterMaterialCode);
}
$builder->groupBy(['materialCode', 'date'])
->orderBy('date', 'asc')
->orderBy('materialCode', 'asc');
// Execute the query and store the result
$result = $builder->get()->getResultArray();
return $result;
}
}