Version 4.3.0
This commit is contained in:
1 parent
96997ddd8e
commit
fe1acf984a
1349 files changed
+116159
-67711
No files matched your search
@@ -105,11 +105,29 @@ class _Purchase extends \IPS\Node\Model
|
||||
public function treeRow( $url, $ref )
|
||||
{
|
||||
$childCount = $this->childrenCount( NULL, NULL, TRUE, array( array( 'ps_show=1' ) ) );
|
||||
$hasCustomFields = count( $this->custom_fields );
|
||||
|
||||
$hasCustomFields = FALSE;
|
||||
foreach ( $this->custom_fields as $k => $v )
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( trim( \IPS\nexus\Package\CustomField::load( $k )->displayValue( $v, TRUE ) ) )
|
||||
{
|
||||
$hasCustomFields = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch( \OutOfRangeException $e ) {}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$description = call_user_func( array( $this->extension(), 'getPurchaseNameInfo' ), $this );
|
||||
|
||||
if( empty( $description ) )
|
||||
{
|
||||
$description[] = \IPS\Member::loggedIn()->language()->addToStack( 'purchase_number', FALSE, array( 'sprintf' => array( $this->id ) ) );
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
@@ -128,8 +146,9 @@ class _Purchase extends \IPS\Node\Model
|
||||
}
|
||||
$description[] = $renewals;
|
||||
}
|
||||
|
||||
$description = implode( ' · ', $description );
|
||||
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'trees', 'core' )->row(
|
||||
$url,
|
||||
$this->id,
|
||||
@@ -541,6 +560,34 @@ class _Purchase extends \IPS\Node\Model
|
||||
$this->_data['pay_to'] = $member->member_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get fee to commission on renewal charges
|
||||
*
|
||||
* @return \IPS\nexus\Money|NULL
|
||||
*/
|
||||
public function get_fee()
|
||||
{
|
||||
if ( $this->_data['fee'] and $this->renewals )
|
||||
{
|
||||
try
|
||||
{
|
||||
return new \IPS\nexus\Money( $this->_data['fee'], $this->renewals->cost->currency );
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set fee to commission on renewal charges
|
||||
*
|
||||
* @param \IPS\nexus\Money|NULL $fee The fee
|
||||
* @return void
|
||||
*/
|
||||
public function set_fee( \IPS\nexus\Money $fee = NULL )
|
||||
{
|
||||
$this->_data['fee'] = $fee ? $fee->amount : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get original invoice
|
||||
@@ -895,6 +942,7 @@ class _Purchase extends \IPS\Node\Model
|
||||
/**
|
||||
* Get output for API
|
||||
*
|
||||
* @param \IPS\Member|NULL $authorizedMember The member making the API request or NULL for API Key / client_credentials
|
||||
* @return array
|
||||
* @apiresponse int id ID number
|
||||
* @apiresponse string name Name
|
||||
@@ -914,14 +962,14 @@ class _Purchase extends \IPS\Node\Model
|
||||
* @apiresponse string image If the item has a relevant image (for exmaple, product image, Downloads file screenshot), the URL to it
|
||||
* @apiresponse string url The URL for the customer to view this purchase in the client area
|
||||
*/
|
||||
public function apiOutput()
|
||||
public function apiOutput( \IPS\Member $authorizedMember = NULL )
|
||||
{
|
||||
$parent = NULL;
|
||||
if ( $this->parent )
|
||||
{
|
||||
try
|
||||
{
|
||||
$parent = static::load( $this->parent )->apiOutput();
|
||||
$parent = static::load( $this->parent )->apiOutput( $authorizedMember );
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) {}
|
||||
}
|
||||
@@ -932,12 +980,12 @@ class _Purchase extends \IPS\Node\Model
|
||||
'itemApp' => $this->app,
|
||||
'itemType' => $this->type,
|
||||
'itemId' => $this->item_id,
|
||||
'customer' => $this->member->apiOutput(),
|
||||
'customer' => $this->member->apiOutput( $authorizedMember ),
|
||||
'purchased' => $this->start->rfc3339(),
|
||||
'expires' => $this->expire ? $this->expire->rfc3339() : null,
|
||||
'active' => (bool) $this->active,
|
||||
'canceled' => (bool) $this->cancelled,
|
||||
'renewalTerm' => $this->renewals ? $this->renewals->apiOutput() : null,
|
||||
'renewalTerm' => $this->renewals ? $this->renewals->apiOutput( $authorizedMember ) : null,
|
||||
'customFields' => $this->custom_fields,
|
||||
'parent' => $parent,
|
||||
'show' => (bool) $this->show,
|
||||
@@ -1090,6 +1138,12 @@ class _Purchase extends \IPS\Node\Model
|
||||
*/
|
||||
public function canRenewUntil( \IPS\Member $member = NULL, $inCycles = FALSE, $admin = FALSE )
|
||||
{
|
||||
/* Can this purchase be renewed at all? */
|
||||
if ( !$this->canBeRenewed() )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
|
||||
if ( !$admin and $this->member->member_id !== $member->member_id and !array_key_exists( $member->member_id, iterator_to_array( $this->member->alternativeContacts( array( \IPS\Db::i()->findInSet( 'purchases', array( $this->id ) ) . ' AND billing=1' ) ) ) ) )
|
||||
@@ -1131,6 +1185,23 @@ class _Purchase extends \IPS\Node\Model
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purchase can be renewed?
|
||||
*
|
||||
* @return boolean|NULL
|
||||
*/
|
||||
public function canBeRenewed()
|
||||
{
|
||||
try
|
||||
{
|
||||
return call_user_func( array( $this->extension(), 'canBeRenewed' ), $this );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Can Cancel
|
||||
@@ -1163,7 +1234,7 @@ class _Purchase extends \IPS\Node\Model
|
||||
{
|
||||
if( $this->_url === NULL )
|
||||
{
|
||||
$this->_url = \IPS\Http\Url::internal( "app=nexus&module=clients&controller=purchases&do=view&id={$this->id}", 'front', 'clientspurchase', array( \IPS\Http\Url\Friendly::seoTitle( $this->name ) ), \IPS\Settings::i()->nexus_https );
|
||||
$this->_url = \IPS\Http\Url::internal( "app=nexus&module=clients&controller=purchases&do=view&id={$this->id}", 'front', 'clientspurchase', array( \IPS\Http\Url\Friendly::seoTitle( $this->name ) ) );
|
||||
}
|
||||
|
||||
return $this->_url;
|
||||
|
||||
Reference in new issue
Block a user