Version 4.7.13

This commit is contained in:
Neo committed 2025-12-19 16:14:56 -08:00
1 parent fd22d99e69
commit 7124a02564
954 files changed
+29277 -59308

No files matched your search

+57 -9
View File
@@ -83,8 +83,7 @@ class _Package extends \IPS\Node\Model
{
return array(
'Product' => 'IPS\nexus\Package\Product',
'Ad' => 'IPS\nexus\Package\Ad',
'Hosting' => 'IPS\nexus\Package\Hosting',
'Ad' => 'IPS\nexus\Package\Ad'
);
}
@@ -100,14 +99,15 @@ class _Package extends \IPS\Node\Model
public static function constructFromData( $data, $updateMultitonStoreIfExists = TRUE )
{
$types = static::packageTypes();
$classname = $types[ mb_ucfirst( $data['p_type'] ) ];
if ( isset( $classname::$packageDatabaseTable ) )
$classname = isset( $types[ mb_ucfirst( $data['p_type'] ) ] ) ? $types[ mb_ucfirst( $data['p_type'] ) ] : '';
if ( $classname and isset( $classname::$packageDatabaseTable ) )
{
$data = array_merge( $data, \IPS\Db::i()->select( '*', $classname::$packageDatabaseTable, array( 'p_id=?', $data['p_id'] ) )->first() );
}
/* Initiate an object */
$obj = new $classname;
$obj = ( $classname ) ? new $classname : new \IPS\nexus\Package;
$obj->_new = FALSE;
/* Import data */
@@ -230,8 +230,12 @@ class _Package extends \IPS\Node\Model
{
$this->item()->delete();
parent::delete();
\IPS\Db::i()->delete( static::$packageDatabaseTable, array( 'p_id=?', $this->id ) );
if( isset( static::$packageDatabaseTable ) )
{
\IPS\Db::i()->delete( static::$packageDatabaseTable, array( 'p_id=?', $this->id ) );
}
/* Translatables */
foreach ( array( '_assoc', '_page', '_email_purchase_subject', '_email_expire_soon_subject', '_email_expire_subject' ) as $suffix )
{
@@ -746,6 +750,11 @@ class _Package extends \IPS\Node\Model
if ( \count( $renewOptions ) === 1 and isset( $renewOptions[0]['cost'][ $currency ] ) and $renewOptions[0]['cost'][ $currency ]['amount'] == $price and !$renewOptions[0]['add'] )
{
$primaryPrice = new \IPS\nexus\Purchase\RenewalTerm( $primaryPrice, new \DateInterval( "P{$renewOptions[0]['term']}" . mb_strtoupper( $renewOptions[0]['unit'] ) ), $tax );
if ( $initialTerm !== NULL )
{
$initialTerm = ( new \IPS\nexus\Purchase\RenewalTerm( [], $initialTerm ) )->getTermUnit();
}
}
else
{
@@ -1871,13 +1880,27 @@ class _Package extends \IPS\Node\Model
}
$key = 'x';
$childPurchaseRenewalCost = NULL;
if ( $purchase->renewals )
{
/* If the purchase has any child purchases, subtract them from the renewal cost to find the actual cost of this product */
$thisPurchaseRenewalCost = $purchase->renewals->cost->amount;
$childPurchaseRenewalCost = new \IPS\Math\Number( "0" );
foreach( $purchase->children() as $child )
{
if( $child->renewals )
{
$childPurchaseRenewalCost = $childPurchaseRenewalCost->add( $child->renewals->cost->amount );
$thisPurchaseRenewalCost = $thisPurchaseRenewalCost->subtract( $child->renewals->cost->amount );
}
}
foreach ( $changes['renew_options'] as $k => $data )
{
if ( $data['old'] != 'x' )
{
if ( $purchase->renewals->cost->amount->compare( new \IPS\Math\Number( number_format( $data['old']['cost'][ $purchase->renewals->cost->currency ]['amount'], \IPS\nexus\Money::numberOfDecimalsForCurrency( $purchase->renewals->cost->currency ), '.', '' ) ) ) === 0 )
/* Compare against the actual renewal cost */
if ( $thisPurchaseRenewalCost->compare( new \IPS\Math\Number( number_format( $data['old']['cost'][ $purchase->renewals->cost->currency ]['amount'], \IPS\nexus\Money::numberOfDecimalsForCurrency( $purchase->renewals->cost->currency ), '.', '' ) ) ) === 0 )
{
$term = $purchase->renewals->getTerm();
if ( $data['old']['term'] == $term['term'] and $data['old']['unit'] == $term['unit'] )
@@ -1965,13 +1988,38 @@ class _Package extends \IPS\Node\Model
}
$currency = $purchase->renewal_currency ?: $purchase->member->defaultCurrency( );
$originalRenewalCost = $purchase->renewals->cost->amount;
/* If we had child purchases, add back the renewal amounts */
$newRenewalCost = new \IPS\Math\Number( $newRenewTerms[ $key ]['cost'][ $currency ]['amount'] );
if( $childPurchaseRenewalCost !== NULL )
{
$newRenewalCost = $newRenewalCost->add( $childPurchaseRenewalCost );
}
$purchase->renewals = new \IPS\nexus\Purchase\RenewalTerm(
new \IPS\nexus\Money( $newRenewTerms[ $key ]['cost'][ $currency ]['amount'], $currency ),
new \IPS\nexus\Money( $newRenewalCost, $currency ),
new \DateInterval( 'P' . $newRenewTerms[ $key ]['term'] . mb_strtoupper( $newRenewTerms[ $key ]['unit'] ) ),
$tax
);
$purchase->save();
/* If we have a parent purchase, update the renewals for the parent */
if( $parent = $purchase->parent() )
{
if( $parentRenewals = $parent->renewals )
{
$parentRenewalCost = $parentRenewals->cost->amount->subtract( $originalRenewalCost );
$parentRenewalCost = $parentRenewalCost->add( $newRenewalCost );
$parent->renewals = new \IPS\nexus\Purchase\RenewalTerm(
new \IPS\nexus\Money( $parentRenewalCost, $currency ),
$parentRenewals->interval,
$parentRenewals->tax
);
$parent->save();
}
}
}
}
}
@@ -3528,7 +3576,7 @@ class _Package extends \IPS\Node\Model
/* If we're still in the initial period of the new package */
$diff = \IPS\DateTime::create()->diff( $purchase->start->add( $initial ) );
if( $diff->days > 0 )
if( !$diff->invert and $diff->days > 0 )
{
$purchase->expire = $purchase->start->add( $diff );
}