单张voucher 做action的流程是:
1.点击detail后获取该张voucher可做的action( get_voucher_actions($voucher_details) )
function get_voucher_actions( $voucher_details )
{
//$this->load->model('access_control', 'vms_acl');
$voucher_id = $voucher_details['voucher_id'];
//we also need to check the stock of the voucher to dertimine the actions.
//e.g. new voucher in Finance stock cannot be re-issued.
$actions = array();
//if( $this->vms_acl->is_csa_user())
//{
switch($voucher_details['status_id'])
{
case $this->voucher_lkup->get_status_id_by_name('new'):
//the following actions are only available if the voucher is not locked.
if( $voucher_details['is_locked'] == 'N' )
{
if( $voucher_details['stock_id'] != $this->voucher_lkup->get_stock_id_by_name('expiry') )
{
$actions[] = 'miss'; //from any stock (except for expiry stock)
}
if( $voucher_details['stock_id'] == $this->voucher_lkup->get_stock_id_by_name('csa') ) //Cancal should be done on own stock.
{
$actions[] = 'cancel';
}
if( $voucher_details['stock_id'] == $this->voucher_lkup->get_stock_id_by_name('cse') )
{
//Re-issue (via scanner or manual input) Physically the voucher was already issued
//- For Promo, Counter sales, partner vouchers - From CSE stock
$actions[] = 'reissue'; //(by CSA only)
}
//change expiry date, Can only be changed if the voucher has not expired, Tenant voucher only
//status must be new.
$tenant_class_ids = $this->voucher_lkup->get_voucher_class_ids( $this->voucher_api->_class_tenant );
if( in_array($voucher_details['class_id'], $tenant_class_ids)
&& strtotime($voucher_details['expiry_date'] . ' 23:59:59') >= strtotime( date('Y-m-d 23:59:59') )
&& $voucher_details['stock_id'] == $this->voucher_lkup->get_stock_id_by_name('csa')
)
{
//$actions[] = 'change_expiry';
}
}
break;
case $this->voucher_lkup->get_status_id_by_name('cancelled'):
//request reinstatement-cancelled,
//check if someone requested un-cancelled. if so, show approve reinstatement-cancelled
$rt = $this->voucher_api->voucher_is_pending_approve_uncancel( $voucher_id );
if(FALSE === $rt && $voucher_details['is_locked'] == 'N')
{
$actions[] = 'request_uncancel';
}
elseif( !$this->vms_acl->is_same_login_user( $rt['request_user'] ) ) //only if the user is different
{
$actions[] = 'approve_uncancel';
}
break;
case $this->voucher_lkup->get_status_id_by_name('missing'):
//request reinstatement-missing,
//check if someone requested un-missing. if so, show approve reinstatement-missing
$rt = $this->voucher_api->voucher_is_pending_approve_unmissing( $voucher_id );
if(FALSE === $rt && $voucher_details['is_locked'] == 'N')
{
$actions[] = 'request_unmissing';
}
elseif( !$this->vms_acl->is_same_login_user( $rt['request_user'] ) ) //only if the user is different
{
$actions[] = 'approve_unmissing';
}
break;
case $this->voucher_lkup->get_status_id_by_name('issued'):
//unissue, replace, extend expiry date. (only when the expiry date of voucher set)
//only when the voucher is not expired
if( strtotime($voucher_details['expiry_date'] . ' 23:59:59') >= strtotime( date('Y-m-d 23:59:59') ) && $voucher_details['is_locked'] == 'N' )
{
$actions[] = 'unissue';
$actions[] = 'replace';
}
//$actions[] = 'extend';
break;
case $this->voucher_lkup->get_status_id_by_name('reimbursed'):
$rt = $this->voucher_api->voucher_is_pending_approve_unreimburse( $voucher_id );
if(FALSE === $rt && $voucher_details['is_locked'] == 'N')
{
$actions[] = 'request_unreimburse';
}
elseif( !$this->vms_acl->is_same_login_user( $rt['request_user'] ) ) //only if the user is different
{
$actions[] = 'approve_unreimburse';
}
break;
//un-reimburse
default:
break;
}//end of switch
//}
if( empty($voucher_details['alert_tag']) && $this->vms_acl->is_csa_user() )
{
$actions[] = 'tag'; //tag will be available in any status, only csa can tag.
}
elseif(!empty($voucher_details['alert_tag']))
{
$rt = $this->voucher_api->voucher_is_pending_approve_untag( $voucher_id );
if(FALSE === $rt && $this->vms_acl->is_csa_user())
{
$actions[] = 'request_untag';//un-tag will be available if there is any tags of this voucher.
}
elseif( !$this->vms_acl->is_same_login_user( $rt['request_user'] ) && $this->vms_acl->is_cd_user() ) //only if the user is different
{
$actions[] = 'approve_untag'; //only CD can do approve
}
}
$rt = array();
if(!empty($actions))
{
foreach($actions as $action_name)
{
$action_id = $this->voucher_lkup->get_action_id_by_name ( $action_name );
$rt[$action_name] = $this->voucher_lkup->get_action_desc_by_id ( $action_id );
}
}
return $rt;
}
