Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

@@ -12,36 +12,56 @@
namespace IPS\nexus\Invoice;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use ArrayIterator;
use DateInterval;
use Exception;
use IPS\Application;
use IPS\DateTime;
use IPS\Http\Url;
use IPS\nexus\Customer;
use IPS\nexus\Invoice\Item\Renewal;
use IPS\nexus\Money;
use IPS\nexus\Package\CustomField;
use IPS\nexus\Purchase;
use IPS\nexus\Purchase\RenewalTerm;
use IPS\nexus\Tax;
use IPS\Text\Encrypt;
use OutOfRangeException;
use function defined;
use function in_array;
use function is_object;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Invoice Items Iterator
*/
class _ItemsIterator extends \ArrayIterator
class ItemsIterator extends ArrayIterator
{
/**
* @brief Currency
*/
public $currency;
public string $currency;
/**
* @brief Class Names
*/
protected static $classnames = NULL;
protected static ?array $classnames = NULL;
/**
* Convert array into object
*
* @param array $data Data
* @return \IPS\nexus\Invoice\Item
* @param array|Item $data Data
* @return Item
*/
public function arrayToObject( $data )
public function arrayToObject( array|Item $data ) : Item
{
if ( \is_object( $data ) )
if ( is_object( $data ) )
{
return $data;
}
@@ -49,29 +69,29 @@ class _ItemsIterator extends \ArrayIterator
/* Load correct class */
if ( $data['act'] === 'renewal' )
{
$obj = new \IPS\nexus\Invoice\Item\Renewal( $data['itemName'], new \IPS\nexus\Money( $data['cost'], $this->currency ) );
$obj = new Renewal( $data['itemName'], new Money( $data['cost'], $this->currency ) );
}
else
{
if ( static::$classnames === NULL )
{
static::$classnames = array();
foreach ( \IPS\Application::allExtensions( 'nexus', 'Item', FALSE, NULL, NULL, FALSE ) as $ext )
foreach ( Application::allExtensions( 'nexus', 'Item', FALSE, NULL, NULL, FALSE ) as $ext )
{
static::$classnames[ $ext::$application ][ $ext::$type ] = $ext;
}
}
if ( $data['app'] === 'nexus' and \in_array( $data['type'], array( 'product', 'ad' ) ) )
if ( $data['app'] === 'nexus' and in_array( $data['type'], array( 'product', 'ad' ) ) )
{
$data['type'] = 'package';
}
$class = isset( static::$classnames[ $data['app'] ][ $data['type'] ] ) ? static::$classnames[ $data['app'] ][ $data['type'] ] : NULL;
$class = static::$classnames[$data['app']][$data['type']] ?? NULL;
if ( !$class )
{
$class = 'IPS\nexus\extensions\nexus\Item\MiscellaneousCharge';
}
$obj = new $class( $data['itemName'], new \IPS\nexus\Money( number_format( $data['cost'], \IPS\nexus\Money::numberOfDecimalsForCurrency( $this->currency ), '.', '' ), $this->currency ) );
$obj = new $class( $data['itemName'], new Money( number_format( $data['cost'], Money::numberOfDecimalsForCurrency( $this->currency ), '.', '' ), $this->currency ) );
}
/* Basic information */
@@ -90,13 +110,13 @@ class _ItemsIterator extends \ArrayIterator
$purchaseDetails[ $key ] = $value;
try
{
$field = \IPS\nexus\Package\CustomField::load( $key );
$field = CustomField::load( $key );
if ( $field->invoice )
{
switch( $field->type )
{
case 'UserPass':
$value = json_decode( \IPS\Text\Encrypt::fromTag( $value )->decrypt(), TRUE );
$value = json_decode( Encrypt::fromTag( $value )->decrypt(), TRUE );
$display = array();
if ( $value['un'] )
{
@@ -112,8 +132,8 @@ class _ItemsIterator extends \ArrayIterator
break;
case 'Ftp':
$value = json_decode( \IPS\Text\Encrypt::fromTag( $value )->decrypt(), TRUE );
$details[ $key ] = (string) \IPS\Http\Url::createFromComponents(
$value = json_decode( Encrypt::fromTag( $value )->decrypt(), TRUE );
$details[ $key ] = (string) Url::createFromComponents(
$value['server'],
( isset( $value['protocol'] ) ) ? "{$value['protocol']}://" : 'ftp://',
( isset( $value['path'] ) ) ? $value['path'] : NULL,
@@ -130,7 +150,7 @@ class _ItemsIterator extends \ArrayIterator
}
}
}
catch( \OutOfRangeException $e ) {}
catch( OutOfRangeException ) {}
}
}
@@ -142,25 +162,25 @@ class _ItemsIterator extends \ArrayIterator
{
try
{
$obj->tax = \IPS\nexus\Tax::load( $data['tax'] );
$obj->tax = Tax::load( $data['tax'] );
}
catch ( \Exception $e ) { }
catch ( Exception ) { }
}
/* Renewal terms */
if ( isset( $data['renew_term'] ) and $data['renew_term'] )
{
$obj->renewalTerm = new \IPS\nexus\Purchase\RenewalTerm( new \IPS\nexus\Money( $data['renew_cost'], $this->currency ), new \DateInterval( 'P' . $data['renew_term'] . mb_strtoupper( $data['renew_units'] ) ), $obj->tax, FALSE, isset( $data['grace_period'] ) ? new \DateInterval( 'PT' . $data['grace_period'] . 'S' ) : NULL );
$obj->renewalTerm = new RenewalTerm( new Money( $data['renew_cost'], $this->currency ), new DateInterval( 'P' . $data['renew_term'] . mb_strtoupper( $data['renew_units'] ) ), $obj->tax, FALSE, isset( $data['grace_period'] ) ? new DateInterval( 'PT' . $data['grace_period'] . 'S' ) : NULL );
if ( isset( $data['initial_interval_term'] ) and $data['initial_interval_term'] )
{
$obj->initialInterval = new \DateInterval( 'P' . $data['initial_interval_term'] . mb_strtoupper( $data['initial_interval_unit'] ) );
$obj->initialInterval = new DateInterval( 'P' . $data['initial_interval_term'] . mb_strtoupper( $data['initial_interval_unit'] ) );
}
}
/* Expire Date */
if ( isset( $data['expires'] ) and $data['expires'] )
{
$obj->expireDate = \IPS\DateTime::ts( $data['expires'] );
$obj->expireDate = DateTime::ts( $data['expires'] );
}
/* Available methods */
@@ -169,25 +189,6 @@ class _ItemsIterator extends \ArrayIterator
$obj->paymentMethodIds = $data['methods'];
}
/* Shipping */
if ( isset( $data['physical'] ) AND $data['physical'] )
{
$obj->physical = TRUE;
if ( isset( $data['shipping'] ) and $data['shipping'] !== '*' )
{
$obj->shippingMethodIds = $data['shipping'];
}
$obj->weight = new \IPS\nexus\Shipping\Weight( $data['weight'] );
$obj->length = new \IPS\nexus\Shipping\Length( $data['length'] );
$obj->width = new \IPS\nexus\Shipping\Length( $data['width'] );
$obj->height = new \IPS\nexus\Shipping\Length( $data['height'] );
if ( isset( $data['chosen_shipping'] ) and $data['chosen_shipping'] )
{
$obj->chosenShippingMethodId = $data['chosen_shipping'];
}
}
/* Parent */
if ( isset( $data['assoc'] ) )
{
@@ -195,16 +196,16 @@ class _ItemsIterator extends \ArrayIterator
{
try
{
$obj->parent = \IPS\nexus\Purchase::load( $data['assoc'] );
$obj->parent = Purchase::load( $data['assoc'] );
}
catch ( \OutOfRangeException $e ) { }
catch ( OutOfRangeException ) { }
}
else
{
$obj->parent = $data['assoc'];
}
$obj->groupWithParent = isset( $data['groupParent'] ) ? $data['groupParent'] : FALSE;
$obj->groupWithParent = $data['groupParent'] ?? FALSE;
}
/* Paying another member? */
@@ -212,17 +213,17 @@ class _ItemsIterator extends \ArrayIterator
{
try
{
$obj->payTo = \IPS\nexus\Customer::load( $data['payTo'] );
$obj->payTo = Customer::load( $data['payTo'] );
if ( isset( $data['commission'] ) )
{
$obj->commission = ( $data['commission'] <= 100 ) ? $data['commission'] : 100;
}
if ( isset( $data['fee'] ) )
{
$obj->fee = new \IPS\nexus\Money( $data['fee'], $this->currency );
$obj->fee = new Money( $data['fee'], $this->currency );
}
}
catch ( \Exception $e ) { }
catch ( Exception ) { }
}
/* URIs? */
@@ -247,9 +248,9 @@ class _ItemsIterator extends \ArrayIterator
/**
* Get current
*
* @return \IPS\Patterns\ActiveRecord
* @return Item
*/
public function current()
public function current(): Item
{
return $this->arrayToObject( parent::current() );
}
@@ -257,11 +258,11 @@ class _ItemsIterator extends \ArrayIterator
/**
* Get offset
*
* @param string $index Index
* @return mixed
* @param mixed $key Index
* @return Item
*/
public function offsetGet( $index )
public function offsetGet( mixed $key ): Item
{
return $this->arrayToObject( parent::offsetGet( $index ) );
return $this->arrayToObject( parent::offsetGet( $key ) );
}
}