101 lines
3.0 KiB
PHP
101 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class PurchaseOrderLineItemModel extends Model
|
|
{
|
|
protected $table = 't_purchaseorder_lineitem'; // Table name
|
|
protected $primaryKey = 'LineItemNo'; // Primary key
|
|
|
|
// Fields allowed for insert/update
|
|
protected $allowedFields = [
|
|
'LineItemNo',
|
|
'PONO',
|
|
'ReqNo',
|
|
'ItemNo',
|
|
'MaterialCode',
|
|
'Quantity',
|
|
'Rate',
|
|
'ReceivedQuantity',
|
|
'AmendmentQuantity',
|
|
'AmendmentRemarks',
|
|
'ServiceMaterialDescription',
|
|
'AmendedDetails',
|
|
'Status',
|
|
'OGR_Status',
|
|
'CreatedDate',
|
|
'CreatedBy',
|
|
'UpdateBY',
|
|
'UpdatedOn',
|
|
'CostCenterCode',
|
|
'ServiceFrequency',
|
|
'Per'
|
|
];
|
|
|
|
// Use automatic timestamps
|
|
protected $useTimestamps = true;
|
|
protected $createdField = 'CreatedDate';
|
|
protected $updatedField = 'UpdatedOn';
|
|
|
|
// Validation rules
|
|
protected $validationRules = [
|
|
'LineItemNo' => 'required|alpha_numeric|max_length[20]',
|
|
'PONO' => 'permit_empty|alpha_numeric|max_length[27]',
|
|
'ReqNo' => 'required|alpha_numeric|max_length[20]',
|
|
'ItemNo' => 'permit_empty|integer',
|
|
'MaterialCode' => 'required|alpha_numeric|max_length[20]',
|
|
'Quantity' => 'required|decimal',
|
|
'Rate' => 'required|decimal',
|
|
'ReceivedQuantity' => 'required|decimal',
|
|
'AmendmentQuantity' => 'permit_empty|decimal',
|
|
'AmendmentRemarks' => 'permit_empty|string|max_length[20]',
|
|
'ServiceMaterialDescription' => 'permit_empty|string',
|
|
'AmendedDetails' => 'permit_empty|string',
|
|
'Status' => 'required|string|max_length[20]',
|
|
'OGR_Status' => 'permit_empty|string|max_length[50]',
|
|
'CreatedBy' => 'required|string|max_length[50]',
|
|
'UpdateBY' => 'required|string|max_length[50]',
|
|
'CostCenterCode' => 'permit_empty|alpha_numeric|max_length[5]',
|
|
'ServiceFrequency' => 'permit_empty|string|max_length[100]',
|
|
'Per' => 'permit_empty|string|max_length[50]',
|
|
];
|
|
|
|
// Validation messages
|
|
protected $validationMessages = [
|
|
'LineItemNo' => [
|
|
'required' => 'Line Item Number is required.',
|
|
'alpha_numeric' => 'Line Item Number must be alphanumeric.',
|
|
],
|
|
'MaterialCode' => [
|
|
'required' => 'Material Code is required.',
|
|
],
|
|
// Add custom messages for other fields as needed
|
|
];
|
|
|
|
// Skip validation
|
|
protected $skipValidation = false;
|
|
|
|
/**
|
|
* Custom function to fetch line items by PONO
|
|
* @param string $pono
|
|
* @return array
|
|
*/
|
|
public function getByPONO(string $pono)
|
|
{
|
|
return $this->where('PONO', $pono)->findAll();
|
|
}
|
|
|
|
/**
|
|
* Custom function to update the status of a line item
|
|
* @param string $lineItemNo
|
|
* @param string $status
|
|
* @return bool
|
|
*/
|
|
public function updateStatus(string $lineItemNo, string $status): bool
|
|
{
|
|
return $this->update($lineItemNo, ['Status' => $status]);
|
|
}
|
|
}
|