User Order all Margins / Checkout
This commit is contained in:
parent
a96d7d5c77
commit
224bf9e951
92 changed files with 3551 additions and 561 deletions
34
app/Services/Yard/Commission.php
Normal file
34
app/Services/Yard/Commission.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
namespace App\Services\Yard;
|
||||
|
||||
|
||||
use App\Services\Util;
|
||||
|
||||
class Commission
|
||||
{
|
||||
public $price_net;
|
||||
public $single_price_net;
|
||||
public $single_value_commission;
|
||||
public $single_partner_commission;
|
||||
public $single_amount_commission;
|
||||
public $single_price_net_commission;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->price_net = 0;
|
||||
$this->single_price_net = 0;
|
||||
$this->single_amount_commission = 0;
|
||||
$this->single_partner_commission = 0;
|
||||
$this->single_value_commission = 0;
|
||||
$this->single_price_net_commission = 0;
|
||||
}
|
||||
|
||||
public function isCommission(){
|
||||
return ($this->single_value_commission > 0) ? true : false;
|
||||
}
|
||||
|
||||
public function getFormatted($key)
|
||||
{
|
||||
return isset($this->{$key}) ? Util::formatNumber($this->{$key}) : "";
|
||||
}
|
||||
}
|
||||
104
app/Services/Yard/Margin.php
Normal file
104
app/Services/Yard/Margin.php
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
namespace App\Services\Yard;
|
||||
|
||||
use App\Services\Util;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class Margin
|
||||
{
|
||||
public $items;
|
||||
public $commission;
|
||||
public $net_discount;
|
||||
public $net_partner_commission;
|
||||
public $net_price;
|
||||
public $net_amount;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->items = new Collection;
|
||||
}
|
||||
|
||||
public function add($price_from, $values){
|
||||
$this->items->push(new MarginItems($price_from, $values));
|
||||
}
|
||||
|
||||
public function setCommission(Commission $commission){
|
||||
$this->commission = $commission;
|
||||
}
|
||||
public function isMargin(){
|
||||
return count($this->items) ? true : false;
|
||||
}
|
||||
|
||||
public function calculate(){
|
||||
|
||||
if($this->commission){
|
||||
$this->net_discount += $this->commission->single_value_commission;
|
||||
$this->net_partner_commission += $this->commission->single_partner_commission;
|
||||
$this->net_amount += $this->commission->single_amount_commission;
|
||||
$this->net_price += $this->commission->single_price_net_commission;
|
||||
|
||||
}
|
||||
|
||||
if($this->isMargin()){
|
||||
foreach ($this->items as $item){
|
||||
$this->net_discount += $item->value_margin;
|
||||
$this->net_partner_commission += $item->value_commission;
|
||||
$this->net_amount += $item->new_price_net;
|
||||
$this->net_price += $item->new_price_net;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public function getFormatted($key)
|
||||
{
|
||||
return isset($this->{$key}) ? Util::formatNumber($this->{$key}) : "";
|
||||
}
|
||||
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
return [
|
||||
'items' => $this->items,
|
||||
'commission' => $this->commission,
|
||||
'net_discount' => $this->net_discount,
|
||||
'net_partner_commission' => $this->net_partner_commission,
|
||||
'net_price' => $this->net_price,
|
||||
'net_amount' => $this->net_amount,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function restore($content)
|
||||
{
|
||||
|
||||
// Unserialize the content (either array if new, or collection if old)
|
||||
$storedContent = unserialize($content);
|
||||
|
||||
if (is_array($storedContent)) {
|
||||
$this->fromArray($storedContent);
|
||||
}
|
||||
//TODO - check this
|
||||
// If the old approach and is Collection, push into existing items
|
||||
/* if ($storedContent instanceof Collection) {
|
||||
foreach ($storedContent as $item) {
|
||||
$this->items->put($item);
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function fromArray($array)
|
||||
{
|
||||
$this->items = $array['items'];
|
||||
$this->commission = $array['commission'];
|
||||
$this->net_discount = $array['net_discount'];
|
||||
$this->net_partner_commission = $array['net_partner_commission'];
|
||||
$this->net_price = $array['net_price'];
|
||||
$this->net_amount = $array['net_amount'];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
46
app/Services/Yard/MarginItems.php
Normal file
46
app/Services/Yard/MarginItems.php
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
namespace App\Services\Yard;
|
||||
|
||||
use App\Services\Util;
|
||||
|
||||
class MarginItems
|
||||
{
|
||||
public $price_from;
|
||||
public $range;
|
||||
public $rest_amount;
|
||||
|
||||
public $balance;
|
||||
|
||||
public $value_margin;
|
||||
public $new_price_net;
|
||||
public $trading_margin;
|
||||
|
||||
public $value_commission;
|
||||
public $commission;
|
||||
|
||||
public function __construct($price_from, $values)
|
||||
{
|
||||
$this->price_from = $price_from;
|
||||
$this->range = $values['range'];
|
||||
$this->rest_amount = $values['rest_amount'];
|
||||
$this->balance = $values['balance'];
|
||||
$this->trading_margin = $values['trading_margin'];
|
||||
$this->commission = $values['commission'];
|
||||
$this->calculate();
|
||||
}
|
||||
|
||||
public function calculate(){
|
||||
$this->value_margin = $this->balance / 100 * $this->trading_margin;
|
||||
$this->new_price_net = $this->balance - $this->value_margin;
|
||||
if($this->commission > 0){
|
||||
$this->value_commission = $this->balance / 100 * $this->commission;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getFormatted($key)
|
||||
{
|
||||
return isset($this->{$key}) ? Util::formatNumber($this->{$key}) : "";
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue