62 lines
1.8 KiB
PHP
62 lines
1.8 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 updateBatchWithCompositeKey(array $data)
|
|
{
|
|
$db = \Config\Database::connect();
|
|
$db->transBegin();
|
|
|
|
foreach ($data as $record) {
|
|
$db->table($this->table)
|
|
->where('date', $record['date'])
|
|
->where('materialCode', $record['materialCode'])
|
|
->update([
|
|
'customer' => $record['customer'],
|
|
'opening' => $record['opening'],
|
|
'receipt' => $record['receipt'],
|
|
'used' => $record['used'],
|
|
'balanceStock' => $record['balanceStock']
|
|
]);
|
|
}
|
|
|
|
if ($db->transStatus() === FALSE) {
|
|
$db->transRollback();
|
|
return false;
|
|
} else {
|
|
$db->transCommit();
|
|
return true;
|
|
}
|
|
}
|
|
}
|