Version 4.7.0

This commit is contained in:
Neo committed 2025-12-19 16:00:35 -08:00
1 parent 517a5e1f70
commit 8ba7d43898
1933 files changed
+65613 -11332

No files matched your search

+73 -37
View File
@@ -1597,14 +1597,12 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
$memberToSave->$k = $v;
}
$memberToSave->save();
/* Was this a referral? */
if( $this->guest_data['referred_by'] )
{
$referredBy = \IPS\Member::load( $this->guest_data['referred_by'] )->addReferral( $memberToSave );
}
$memberToSave->logHistory( 'core', 'account', array( 'type' => 'register_checkout', 'spamCode' => $spamData['code'], 'spamAction' => $spamData['action'], 'invoice' => $this->id ), FALSE );
if( isset( $this->guest_data['agreed_terms'] ) and $this->guest_data['agreed_terms'] )
{
$memberToSave->logHistory( 'core', 'terms_acceptance', array( 'type' => 'terms' ) );
}
}
$this->member = $memberToSave;
$postBeforeRegister = isset( $this->guest_data['pbr'] ) ? $this->guest_data['pbr'] : NULL;
@@ -1905,8 +1903,10 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
}
/* Referral Commission */
$this->status_extra = $extra;
if ( \IPS\Settings::i()->ref_on and $commission = $this->commission( $amountReceived ) and $commission['amount'] )
{
$extra = $this->status_extra; // Reload, the commission method may have changed this.
$credits = $commission['referrer']->cm_credits;
$credits[ $this->currency ]->amount = $credits[ $this->currency ]->amount->add( $commission['amount']->amount );
$commission['referrer']->cm_credits = $credits;
@@ -2093,6 +2093,7 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
public function markUnpaid( $status, \IPS\Member $member = NULL )
{
/* Do stuff */
$extra = $this->status_extra;
if ( $this->status === static::STATUS_PAID )
{
/* Loop items */
@@ -2104,36 +2105,15 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
if ( $item->payTo and !$item->payTo->inGroup( explode( ',', \IPS\Settings::i()->nexus_no_commission ) ) )
{
$recipientAmounts = $item->recipientAmounts();
$credits = $item->payTo->cm_credits;
$credits[ $this->currency ]->amount = $credits[ $this->currency ]->amount->subtract( $recipientAmounts['recipient_final']->amount );
$item->payTo->cm_credits = $credits;
$item->payTo->save();
$item->payTo->log( 'comission', array(
'type' => 'invoice_refund',
'currency' => $this->currency,
'amount' => $recipientAmounts['recipient_final']->amount,
'new_amount' => $credits[ $this->currency ]->amount,
'member' => $this->member->member_id,
'invoice_id' => $this->id,
'invoice_title' => $this->title
), FALSE );
\IPS\Email::buildFromTemplate( 'nexus', 'commissionRevoked', array( $this, $item, $recipientAmounts['recipient_final'] ), \IPS\Email::TYPE_TRANSACTIONAL )
->send(
$item->payTo,
array_map(
function( $contact )
{
return $contact->alt_id->email;
},
iterator_to_array( $item->payTo->alternativeContacts( array( 'billing=1' ) ) )
),
( ( \in_array( 'commission_earned', explode( ',', \IPS\Settings::i()->nexus_notify_copy_types ) ) AND \IPS\Settings::i()->nexus_notify_copy_email ) ? explode( ',', \IPS\Settings::i()->nexus_notify_copy_email ) : array() )
);
$this->revokeCommission( $item->payTo, $recipientAmounts['recipient_final'], $item );
}
}
/* Revoke commissions based on the referral rules */
if( !empty( $extra['commissionref'] ) AND !empty( $extra['commissionamount'] ) )
{
$this->revokeCommission( \IPS\nexus\Customer::load( $extra['commissionref'] ), new \IPS\nexus\Money( $extra['commissionamount'], $this->currency ) );
}
/* Delete purchases */
foreach ( $this->purchasesCreated() as $purchase )
@@ -2161,7 +2141,6 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
/* Log */
if ( $member )
{
$extra = $this->status_extra;
$extra['type'] = 'manual';
$extra['setTo'] = $status;
$extra['setByID'] = $member->member_id;
@@ -2172,6 +2151,44 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
/* Save */
$this->save();
}
/**
* Revoke Commission
*
* @param \IPS\Member $paidTo Revoke the commission from this member
* @param \IPS\nexus\Money $commission Amount of commission to revoke
* @param \IPS\nexus\Invoice\Item|null $item Item commission was for (if applicable)
*/
protected function revokeCommission( \IPS\Member $paidTo, \IPS\nexus\Money $commission, \IPS\nexus\Invoice\Item $item=NULL )
{
$credits = $paidTo->cm_credits;
$credits[ $this->currency ]->amount = $credits[ $this->currency ]->amount->subtract( $commission->amount );
$paidTo->cm_credits = $credits;
$paidTo->save();
$paidTo->log( 'comission', array(
'type' => 'invoice_refund',
'currency' => $this->currency,
'amount' => $commission->amount,
'new_amount' => $credits[ $this->currency ]->amount,
'member' => $this->member->member_id,
'invoice_id' => $this->id,
'invoice_title' => $this->title
), FALSE );
\IPS\Email::buildFromTemplate( 'nexus', 'commissionRevoked', array( $this, $item, $commission ), \IPS\Email::TYPE_TRANSACTIONAL )
->send(
$paidTo,
array_map(
function( $contact )
{
return $contact->alt_id->email;
},
iterator_to_array( $paidTo->alternativeContacts( array( 'billing=1' ) ) )
),
( ( \in_array( 'commission_earned', explode( ',', \IPS\Settings::i()->nexus_notify_copy_types ) ) AND \IPS\Settings::i()->nexus_notify_copy_email ) ? explode( ',', \IPS\Settings::i()->nexus_notify_copy_email ) : array() )
);
}
/**
* What will happen if we mark this unpaid?
@@ -2243,7 +2260,26 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
}
}
}
/* Referral Commission */
$extra = $this->status_extra;
if( !empty( $extra['commissionref'] ) AND !empty( $extra['commissionamount'] ) )
{
$customer = \IPS\nexus\Customer::load( $extra['commissionref'] );
$amount = new \IPS\nexus\Money( $extra['commissionamount'], $this->currency );
$message = \IPS\Member::loggedIn()->language()->addToStack( 'account_credit_remove_commission', FALSE, array( 'sprintf' => array( $amount, $customer->cm_name ) ) );
$credits = $customer->cm_credits;
if ( !$credits[ $amount->currency ]->amount->subtract( $amount->amount )->isPositive() )
{
$return[] = array( 'message' => $message, 'warning' => \IPS\Member::loggedIn()->language()->addToStack( 'account_credit_remove_neg' ) );
}
else
{
$return[] = $message;
}
}
return $return;
}
@@ -372,7 +372,7 @@ abstract class _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 ( isset( $item->parent ) and isset( $this->parent ) )
{
if ( \gettype( $this->parent ) != \gettype( $item->parent ) )
{