/
BillingsItem.php
64 lines (59 loc) · 1.6 KB
/
BillingsItem.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
App::uses('AppModel', 'Model');
/**
* BillingsItem Model
*
* @property Billings $Billings
*/
class BillingsItem extends AppModel {
/**
* Validation rules
*
* @var array
*/
public $validate = array(
'service_date' => array(
'date' => array(
'rule' => array('date'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
);
//The Associations below have been created with all possible keys, those that are not needed can be removed
/**
* belongsTo associations
*
* @var array
*/
public $belongsTo = array(
'Billing' => array(
'className' => 'Billing',
'foreignKey' => 'billing_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
public function beforeValidate($options = array()) {
if (!empty($this->data['BillingsItem']['service_date'])) {
$this->data['BillingsItem']['service_date'] = $this->dateFormatBeforeSave($this->data['BillingsItem']['service_date']);
}
return true;
}
public function dateFormatBeforeSave($dateString) {
return date('Y-m-d', strtotime($dateString));
}
public function distinctShiftsPerDay ($conditions = array()) {
$data = $this->find('all', array(
'fields' => array('Billing.healthcare_provider', 'service_date', 'COUNT(DISTINCT billing_id)'),
'conditions' => $conditions,
'group' => array('Billing.healthcare_provider', 'service_date')
)
);
return $data;
}
}