Version 4.6.0
This commit is contained in:
1 parent
f79dcf067a
commit
517a5e1f70
2036 files changed
+110041
-26162
No files matched your search
@@ -87,7 +87,7 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
* @param string $ref Referer
|
||||
* @return \IPS\Helpers\Table\Db
|
||||
*/
|
||||
public static function table( $where = array(), \IPS\Http\Url $url, $ref = 't' )
|
||||
public static function table( ?array $where, \IPS\Http\Url $url, $ref = 't' )
|
||||
{
|
||||
/* Create the table */
|
||||
$table = new \IPS\Helpers\Table\Db( 'nexus_invoices', $url, $where );
|
||||
@@ -261,6 +261,11 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
*/
|
||||
protected $_itemsIterator;
|
||||
|
||||
/**
|
||||
* @brief Tracked
|
||||
*/
|
||||
protected $_tracked = array();
|
||||
|
||||
/**
|
||||
* Get items
|
||||
*
|
||||
@@ -1380,6 +1385,15 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
'target' => '_blank',
|
||||
'link' => $url->setQueryString( 'do', 'printout' ),
|
||||
);
|
||||
|
||||
$trackUrl = $url->setQueryString( array( 'do' => 'track', 'id' => $this->id ) )->csrf();
|
||||
$return['track'] = array(
|
||||
'title' => $this->tracked() ? 'invoice_untrack' : 'invoice_track',
|
||||
'icon' => 'bullhorn',
|
||||
'link' => $this->tracked() ? $trackUrl : $trackUrl->setQueryString( 'track', 1 ),
|
||||
'data' => array( 'confirm' => '' )
|
||||
);
|
||||
|
||||
if ( $this->status !== \IPS\nexus\Invoice::STATUS_CANCELED and \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'invoices_edit' ) )
|
||||
{
|
||||
$return['unpaid'] = array(
|
||||
@@ -1846,7 +1860,9 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
if ( $item->payTo and !$item->payTo->inGroup( explode( ',', \IPS\Settings::i()->nexus_no_commission ) ) )
|
||||
{
|
||||
$recipientAmounts = $item->recipientAmounts();
|
||||
|
||||
|
||||
/* We explicitly re-load $item->payTo in order to ensure the account credit amounts have not changed since the time this invoice request began and now. If an admin began a payout that processed after this page load began, the account credit amount may have been reduced. */
|
||||
$item->payTo = \IPS\nexus\Customer::constructFromData( \IPS\Db::i()->select( '*, core_members.member_id AS _member_id', 'core_members', array( 'core_members.member_id=?', $item->payTo->member_id) )->join( 'nexus_customers', 'nexus_customers.member_id=core_members.member_id' )->first() );
|
||||
$credits = $item->payTo->cm_credits;
|
||||
$credits[ $this->currency ]->amount = $credits[ $this->currency ]->amount->add( $recipientAmounts['recipient_final']->amount );
|
||||
$item->payTo->cm_credits = $credits;
|
||||
@@ -2042,6 +2058,14 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
$this->billaddress = $this->member->primaryBillingAddress();
|
||||
}
|
||||
|
||||
/* Send tracked notifications */
|
||||
foreach ( \IPS\Db::i()->select( 'member_id', 'nexus_invoice_tracker', array( 'invoice_id=?', $this->id ) ) as $trackingMember )
|
||||
{
|
||||
$trackingMember = \IPS\Member::load( $trackingMember );
|
||||
\IPS\Email::buildFromTemplate( 'nexus', 'invoiceNotify', array( $this, $this->summary( $trackingMember->language() ) ), \IPS\Email::TYPE_LIST )
|
||||
->send( $trackingMember );
|
||||
}
|
||||
|
||||
/* Log */
|
||||
if ( $member )
|
||||
{
|
||||
@@ -2290,4 +2314,31 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
return \IPS\Http\Url::internal( "app=nexus&module=payments&controller=invoices&do=view&id={$this->id}", 'admin' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the member tracking this invoice?
|
||||
*
|
||||
* @param \IPS\Member|NULL $member The member to check for, or NULL for currently logged in member
|
||||
* @return bool
|
||||
*/
|
||||
public function tracked( \IPS\Member $member = NULL )
|
||||
{
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
|
||||
if( !isset( $this->_tracked[ $member->member_id ] ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$tracked = \IPS\Db::i()->select( array( 'invoice_id' ), 'nexus_invoice_tracker', array( 'member_id=? and invoice_id=?', $member->member_id, $this->id ) )->first();
|
||||
|
||||
$this->_tracked[ $member->member_id ] = TRUE;
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
{
|
||||
$this->_tracked[ $member->member_id ] = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_tracked[ $member->member_id ];
|
||||
}
|
||||
}
|
||||
@@ -361,6 +361,33 @@ abstract class _Item
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this item the same as another item in the cart?
|
||||
* Used to decide when an item is added to the cart if we should just increase the quantity of this item instead of creating a new item.
|
||||
*
|
||||
* @param \IPS\nexus\Invoice\Item $item The other item
|
||||
* @return bool
|
||||
*/
|
||||
public function isSameAsOtherItem( $item )
|
||||
{
|
||||
/* If one is set to be associated with something in the cart and the other is set to be associated
|
||||
with an existing purchase, trying to compare those will throw an error */
|
||||
if ( $item->parent or $this->parent )
|
||||
{
|
||||
if ( \gettype( $this->parent ) != \gettype( $item->parent ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Assume the quantities are the same */
|
||||
$cloned = clone $item;
|
||||
$cloned->quantity = $this->quantity;
|
||||
|
||||
/* Compare */
|
||||
return ( $cloned == $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get output for API
|
||||
*
|
||||
|
||||
@@ -296,6 +296,18 @@ abstract class _Purchase extends \IPS\nexus\Invoice\Item
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Purchase can be reactivated in the ACP?
|
||||
*
|
||||
* @param \IPS\nexus\Purchase $purchase The purchase
|
||||
* @param NULL $error Error to show, passed by reference
|
||||
* @return bool
|
||||
*/
|
||||
public static function canAcpReactivate( \IPS\nexus\Purchase $purchase, &$error=NULL )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can Renew Until
|
||||
*
|
||||
@@ -475,4 +487,54 @@ abstract class _Purchase extends \IPS\nexus\Invoice\Item
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this item the same as another item in the cart?
|
||||
* Used to decide when an item is added to the cart if we should just increase the quantity of this item instead of creating a new item.
|
||||
*
|
||||
* @param \IPS\nexus\Invoice\Item $item The other item
|
||||
* @return bool
|
||||
*/
|
||||
public function isSameAsOtherItem( $item )
|
||||
{
|
||||
// You can't compare DateInterval objects, it just throws an exception, so we have to
|
||||
// manually figure out if the renewal terms have any differences
|
||||
|
||||
if ( $item instanceof \IPS\nexus\Invoice\Item\Purchase )
|
||||
{
|
||||
if ( $item->renewalTerm xor $this->renewalTerm )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
elseif ( !$item->renewalTerm and !$this->renewalTerm )
|
||||
{
|
||||
return parent::isSameAsOtherItem( $item );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $item->renewalTerm and $this->renewalTerm )
|
||||
{
|
||||
if ( $item->renewalTerm->getTerm() != $this->renewalTerm->getTerm() )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
if ( $item->renewalTerm->cost != $item->renewalTerm->cost )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
$clonedThis = clone $this;
|
||||
$clonedThis->renewalTerm = NULL;
|
||||
$clonedOther = clone $item;
|
||||
$clonedOther->renewalTerm = NULL;
|
||||
|
||||
return $clonedThis->isSameAsOtherItem( $clonedOther );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user