Skip to content

Commit

Permalink
Added readig of Order & Invoices Global Discounts
Browse files Browse the repository at this point in the history
  • Loading branch information
BadPixxel committed Feb 8, 2018
1 parent edbccb3 commit 2b78615
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ upload/
/composer.lock
/modules/splashsync/vendor/

/nbproject/private/
/nbproject/
2 changes: 1 addition & 1 deletion modules/splashsync/splashsync.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct()
// Init Module Main Information Fields
$this->name = 'splashsync';
$this->tab = 'administration';
$this->version = '1.0.8';
$this->version = '1.1.0';
$this->author = 'SplashSync';
$this->need_instance = 0;
$this->ps_versions_compliancy = array('min' => '1.5', 'max' => '1.7');
Expand Down
102 changes: 100 additions & 2 deletions modules/splashsync/src/Objects/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public function Get($id=NULL,$list=0)
if ( $this->Order->id != $this->Object->id_order ) {
return Splash::Log()->Err("ErrLocalTpl",__CLASS__,__FUNCTION__," Unable to load Invoice Order (" . $this->Object->id_order . ").");
}
$this->Products = $this->Object->getProducts();
$this->Products = $this->Object->getProductsDetail();
$this->Payments = $this->Object->getOrderPaymentCollection();
//====================================================================//
// Init Response Array
Expand All @@ -294,6 +294,7 @@ public function Get($id=NULL,$list=0)
$this->getMainFields($Key,$FieldName);
$this->getProductsLineFields($Key,$FieldName);
$this->getShippingLineFields($Key,$FieldName);
$this->getDiscountLineFields($Key,$FieldName);
$this->getPaymentLineFields($Key, $FieldName);
}
//====================================================================//
Expand Down Expand Up @@ -756,11 +757,18 @@ private function getShippingLineFields($Key,$FieldName)
//====================================================================//
// Order Line Unit Price
case 'unit_price':
//====================================================================//
// Manually Compute Tax Rate
if ( $this->Object->total_shipping_tax_incl != $this->Object->total_shipping_tax_excl ) {
$Tax = round(100 * ( ($this->Object->total_shipping_tax_incl - $this->Object->total_shipping_tax_excl) / $this->Object->total_shipping_tax_excl ), 2);
} else {
$Tax = 0;
}
//====================================================================//
// Build Price Array
$Value = self::Price_Encode(
(double) Tools::convertPrice($this->Object->total_shipping_tax_excl, $this->Currency),
(double) $this->Order->carrier_tax_rate,
(double) $Tax,
Null,
$this->Currency->iso_code,
$this->Currency->sign,
Expand All @@ -782,6 +790,91 @@ private function getShippingLineFields($Key,$FieldName)
$this->Out["lines"][$key][$FieldIndex[0]] = $Value;
}

/**
* @abstract Read requested Field
*
* @param string $Key Input List Key
* @param string $FieldName Field Identifier / Name
*
* @return none
*/
private function getDiscountLineFields($Key,$FieldName)
{
//====================================================================//
// Check List Name
if (self::ListField_DecodeListName($FieldName) !== "lines") {
return True;
}
//====================================================================//
// Decode Field Name
$ListFieldName = self::ListField_DecodeFieldName($FieldName);
//====================================================================//
// Create List Array If Needed
if (!array_key_exists("lines",$this->Out)) {
$this->Out["lines"] = array();
}
//====================================================================//
// Check If Order has Discounts
if ( $this->Object->total_discount_tax_incl == 0 ) {
return;
}

//====================================================================//
// READ Fields
switch ($ListFieldName)
{
//====================================================================//
// Order Line Direct Reading Data
case 'product_name':
$Value = $this->spl->l("Discount");
break;
case 'product_quantity':
$Value = 1;
break;
case 'reduction_percent':
$Value = 0;
break;
//====================================================================//
// Order Line Product Id
case 'product_id':
$Value = Null;
break;
//====================================================================//
// Order Line Unit Price
case 'unit_price':
//====================================================================//
// Manually Compute Tax Rate
if ( $this->Object->total_discount_tax_incl != $this->Object->total_discount_tax_excl ) {
$Tax = round(100 * ( ($this->Object->total_discount_tax_incl - $this->Object->total_discount_tax_excl) / $this->Object->total_discount_tax_excl ), 2);
} else {
$Tax = 0;
}
//====================================================================//
// Build Price Array
$Value = self::Price_Encode(
(double) (-1) * Tools::convertPrice($this->Object->total_discount_tax_excl, $this->Currency),
(double) $Tax,
Null,
$this->Currency->iso_code,
$this->Currency->sign,
$this->Currency->name);
break;
default:
return;
}

//====================================================================//
// Create Line Array If Needed
$key = count($this->Products) + 1;
if (!array_key_exists($key,$this->Out["lines"])) {
$this->Out["lines"][$key] = array();
}
//====================================================================//
// Store Data in Array
$FieldIndex = explode("@",$FieldName);
$this->Out["lines"][$key][$FieldIndex[0]] = $Value;
}

/**
* @abstract Read requested Field
*
Expand Down Expand Up @@ -842,6 +935,11 @@ private function getProductsLineFields($Key,$FieldName)
//====================================================================//
// Order Line Unit Price
case 'unit_price':
//====================================================================//
// Manually Compute Tax Rate
if ( $Product["unit_price_tax_excl"] != $Product["unit_price_tax_incl"] ) {
$Product["tax_rate"] = round(100 * ( ($Product["unit_price_tax_incl"] - $Product["unit_price_tax_excl"]) / $Product["unit_price_tax_excl"] ), 2);
}
//====================================================================//
// Build Price Array
$Value = self::Price_Encode(
Expand Down
96 changes: 95 additions & 1 deletion modules/splashsync/src/Objects/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ public function Get($id=NULL,$list=0)
$this->getMainFields($Key,$FieldName);
$this->getProductsLineFields($Key,$FieldName);
$this->getShippingLineFields($Key,$FieldName);
$this->getDiscountLineFields($Key,$FieldName);

$this->getMetaFields($Key, $FieldName);
// $this->getPostCreateFields($Key, $FieldName);
Expand Down Expand Up @@ -779,11 +780,18 @@ private function getShippingLineFields($Key,$FieldName)
//====================================================================//
// Order Line Unit Price
case 'unit_price':
//====================================================================//
// Manually Compute Tax Rate
if ( $this->Object->total_shipping_tax_incl != $this->Object->total_shipping_tax_excl ) {
$Tax = round(100 * ( ($this->Object->total_shipping_tax_incl - $this->Object->total_shipping_tax_excl) / $this->Object->total_shipping_tax_excl ), 2);
} else {
$Tax = 0;
}
//====================================================================//
// Build Price Array
$Value = self::Price_Encode(
(double) Tools::convertPrice($this->Object->total_shipping_tax_excl, $this->Currency),
(double) $this->Object->carrier_tax_rate,
(double) $Tax,
Null,
$this->Currency->iso_code,
$this->Currency->sign,
Expand All @@ -805,6 +813,92 @@ private function getShippingLineFields($Key,$FieldName)
$this->Out["lines"][$key][$FieldIndex[0]] = $Value;
}

/**
* @abstract Read requested Field
*
* @param string $Key Input List Key
* @param string $FieldName Field Identifier / Name
*
* @return none
*/
private function getDiscountLineFields($Key,$FieldName)
{
//====================================================================//
// Check List Name
if (self::ListField_DecodeListName($FieldName) !== "lines") {
return True;
}
//====================================================================//
// Decode Field Name
$ListFieldName = self::ListField_DecodeFieldName($FieldName);
//====================================================================//
// Create List Array If Needed
if (!array_key_exists("lines",$this->Out)) {
$this->Out["lines"] = array();
}

//====================================================================//
// Check If Order has Discounts
if ( $this->Object->total_discounts == 0 ) {
return;
}

//====================================================================//
// READ Fields
switch ($ListFieldName)
{
//====================================================================//
// Order Line Direct Reading Data
case 'product_name':
$Value = $this->spl->l("Discount");
break;
case 'product_quantity':
$Value = 1;
break;
case 'reduction_percent':
$Value = 0;
break;
//====================================================================//
// Order Line Product Id
case 'product_id':
$Value = Null;
break;
//====================================================================//
// Order Line Unit Price
case 'unit_price':
//====================================================================//
// Manually Compute Tax Rate
if ( $this->Object->total_discounts_tax_incl != $this->Object->total_discounts_tax_excl ) {
$Tax = round(100 * ( ($this->Object->total_discounts_tax_incl - $this->Object->total_discounts_tax_excl) / $this->Object->total_discounts_tax_excl ), 2);
} else {
$Tax = 0;
}
//====================================================================//
// Build Price Array
$Value = self::Price_Encode(
(double) (-1) * Tools::convertPrice($this->Object->total_discounts_tax_excl, $this->Currency),
(double) $Tax,
Null,
$this->Currency->iso_code,
$this->Currency->sign,
$this->Currency->name);
break;
default:
return;
}

//====================================================================//
// Create Line Array If Needed
$key = count($this->Products) + 1;
if (!array_key_exists($key,$this->Out["lines"])) {
$this->Out["lines"][$key] = array();
}
//====================================================================//
// Store Data in Array
$FieldIndex = explode("@",$FieldName);
$this->Out["lines"][$key][$FieldIndex[0]] = $Value;
}

/**
* @abstract Read requested Field
*
Expand Down

0 comments on commit 2b78615

Please sign in to comment.