Custom Price / Land / User Order Homeparty
This commit is contained in:
parent
d46824a4ac
commit
51d81d8ec6
55 changed files with 1951 additions and 681 deletions
|
|
@ -217,6 +217,8 @@ class HTMLHelper
|
|||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function getContriesCodes($id, $all=true){#
|
||||
$values = Country::all();
|
||||
$counter = 1;
|
||||
|
|
|
|||
|
|
@ -29,11 +29,11 @@ class HomepartyCart
|
|||
public static $ek_price_net = 0;
|
||||
|
||||
public static $income_price = 0;
|
||||
public static $homeparty;
|
||||
|
||||
private static $shipping_total = 0;
|
||||
private static $shipping_net_total = 0;
|
||||
|
||||
private static $homeparty;
|
||||
private static $userCarts = [];
|
||||
|
||||
public static $user_host_id;
|
||||
|
|
@ -311,6 +311,11 @@ class HomepartyCart
|
|||
return formatNumber(self::$points, 0);
|
||||
}
|
||||
|
||||
public static function getFormattedPointsTotal()
|
||||
{
|
||||
return formatNumber(self::$points - self::$bonus_points_diff, 0);
|
||||
}
|
||||
|
||||
public static function getFormattedPrice()
|
||||
{
|
||||
return formatNumber(self::$price);
|
||||
|
|
@ -398,4 +403,46 @@ class HomepartyCart
|
|||
|
||||
return number_format($value, $decimals, $decimalPoint, $thousandSeperator);
|
||||
}
|
||||
|
||||
|
||||
public static function getCurrencyByKey($key)
|
||||
{
|
||||
$rNumber = 0;
|
||||
if(self::$homeparty && self::$homeparty->isPriceCurrency()){
|
||||
$user_country = self::$homeparty->getUserCountry();
|
||||
$faktor = isset($user_country->currency_faktor) ? $user_country->currency_faktor : 1;
|
||||
switch ($key) {
|
||||
case 'BonusValue':
|
||||
$rNumber = self::$bonus_value * $faktor;
|
||||
break;
|
||||
case 'BonusCoupon':
|
||||
$rNumber = self::$bonus_coupon * $faktor;
|
||||
break;
|
||||
case 'IncomePrice':
|
||||
$rNumber = self::$income_price * $faktor;
|
||||
break;
|
||||
case 'Price':
|
||||
$rNumber = self::$price * $faktor;
|
||||
break;
|
||||
case 'EkPrice':
|
||||
$rNumber = self::$ek_price * $faktor;
|
||||
break;
|
||||
case 'PriceNet':
|
||||
$rNumber = self::$price_net * $faktor;
|
||||
break;
|
||||
case 'EkPriceNet':
|
||||
$rNumber = self::$ek_price_net * $faktor;
|
||||
break;
|
||||
case 'PriceTax':
|
||||
$rNumber = (self::$price - self::$price_net) * $faktor;
|
||||
break;
|
||||
case 'EkPriceTax':
|
||||
$rNumber = (self::$ek_price - self::$ek_price_net)* $faktor;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return formatNumber($rNumber);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -125,4 +125,31 @@ class HomepartyUserCart
|
|||
|
||||
return number_format($value, $decimals, $decimalPoint, $thousandSeperator);
|
||||
}
|
||||
|
||||
|
||||
public function getCurrencyByKey($key)
|
||||
{
|
||||
$rNumber = 0;
|
||||
if($this->homepartyUser->homeparty && $this->homepartyUser->homeparty->isPriceCurrency()){
|
||||
$user_country = $this->homepartyUser->homeparty->getUserCountry();
|
||||
$faktor = isset($user_country->currency_faktor) ? $user_country->currency_faktor : 1;
|
||||
switch ($key) {
|
||||
case 'ShippingPrice':
|
||||
$rNumber = $this->shipping_price * $faktor;
|
||||
break;
|
||||
case 'IncomePrice':
|
||||
$rNumber = $this->income_price * $faktor;
|
||||
break;
|
||||
case 'Price':
|
||||
$rNumber = $this->price * $faktor;
|
||||
break;
|
||||
case 'EkPrice':
|
||||
$rNumber = $this->ek_price * $faktor;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return formatNumber($rNumber);
|
||||
}
|
||||
}
|
||||
29
app/Services/PriceService.php
Normal file
29
app/Services/PriceService.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
namespace App\Services;
|
||||
|
||||
|
||||
use App\User;
|
||||
|
||||
class PriceService
|
||||
{
|
||||
public static $country;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static function createConfirmationCode() {
|
||||
$unique = false;
|
||||
do{
|
||||
$confirmation_code = str_random(30);
|
||||
if(User::where('confirmation_code', '=', $confirmation_code)->count() == 0){
|
||||
$unique = true;
|
||||
}
|
||||
}
|
||||
while(!$unique);
|
||||
return $confirmation_code;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
13
app/Services/TaxPriceHelper.php
Normal file
13
app/Services/TaxPriceHelper.php
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
namespace App\Services;
|
||||
|
||||
|
||||
class TaxPriceHelper
|
||||
{
|
||||
public static function userOrders() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -3,9 +3,89 @@ namespace App\Services;
|
|||
|
||||
|
||||
use App\User;
|
||||
use App\Models\ShippingCountry;
|
||||
|
||||
class UserService
|
||||
{
|
||||
public static $user_country;
|
||||
public static $shipping_country;
|
||||
public static $user_tax_free;
|
||||
public static $user_reverse_charge = false;
|
||||
|
||||
|
||||
public static function checkUserTaxShippingCountry(User $user, $shipping_country_id) {
|
||||
|
||||
if(!$user->account && !$user->account->country_id){
|
||||
abort(403, 'Error: User hat kein Land!');
|
||||
}
|
||||
$ShippingCountry = ShippingCountry::findOrFail($shipping_country_id);
|
||||
self::$user_tax_free = self::performUserTaxShippingCountry($user, $ShippingCountry);
|
||||
|
||||
/*
|
||||
dump( self::$user_price_code );
|
||||
dump( self::$user_tax_free );
|
||||
dump( self::$user_reverse_charge );
|
||||
*/
|
||||
}
|
||||
|
||||
public static function performUserTaxShippingCountry($user, $ShippingCountry){
|
||||
//preise für das Land
|
||||
self::$user_country = $user->account->country;
|
||||
self::$shipping_country = $ShippingCountry->country;
|
||||
//ausgehend vom Land des Rechnungsempfänger $user->account->country
|
||||
//ist der Rechnungsempfänger im Drittland?
|
||||
if($user->account->country->supply_country){
|
||||
if($ShippingCountry->country->supply_country){
|
||||
//Lieferadresse im Drittland?
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//Rechnungsempfänger in der EU
|
||||
|
||||
//Lieferland mit RSV
|
||||
if($ShippingCountry->country->eu_country){
|
||||
//Rechnungsempfänger mit valid aktiv RSV
|
||||
if($user->account->reverse_charge && $user->account->reverse_charge_valid){
|
||||
//Rechnungsland ist auch Lieferland, dann RSV
|
||||
if(strtolower($user->account->reverse_charge_code) == strtolower($ShippingCountry->country->code)){
|
||||
self::$user_reverse_charge = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
//Lieferland ohne RSV
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getYardInfo(){
|
||||
return [
|
||||
'user_tax_free' => self::$user_tax_free,
|
||||
'user_reverse_charge' => self::$user_reverse_charge,
|
||||
'user_country_id' => self::$user_country->id,
|
||||
'shipping_country_id' => self::$shipping_country->id,
|
||||
];
|
||||
}
|
||||
|
||||
public static function getOrderInfo($key = false){
|
||||
|
||||
switch ($key) {
|
||||
case 'billing_state':
|
||||
return self::$user_country->getLocated();
|
||||
break;
|
||||
case 'shipping_state':
|
||||
return self::$shipping_country->getLocated();
|
||||
break;
|
||||
case 'tax_free':
|
||||
return self::$user_tax_free ? 'Nein' : 'Ja';
|
||||
break;
|
||||
case 'user_reverse_charge':
|
||||
return self::$user_reverse_charge ? 'Ja' : 'Nein';
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static function createConfirmationCode() {
|
||||
$unique = false;
|
||||
do{
|
||||
|
|
@ -18,4 +98,6 @@ class UserService
|
|||
return $confirmation_code;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,14 +1,15 @@
|
|||
<?php
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Country;
|
||||
use App\Models\Product;
|
||||
use App\Models\ShippingCountry;
|
||||
use \Gloudemans\Shoppingcart\Cart;
|
||||
use Illuminate\Support\Collection;
|
||||
use Gloudemans\Shoppingcart\CartItem;
|
||||
use Gloudemans\Shoppingcart\Contracts\Buyable;
|
||||
use Illuminate\Session\SessionManager;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Support\Collection;
|
||||
use Gloudemans\Shoppingcart\Contracts\Buyable;
|
||||
|
||||
|
||||
class Yard extends Cart
|
||||
|
|
@ -21,7 +22,10 @@ class Yard extends Cart
|
|||
private $shipping_is_for;
|
||||
private $num_comp;
|
||||
private $ysession;
|
||||
private $yinstance;
|
||||
private $user_tax_free;
|
||||
private $user_reverse_charge;
|
||||
private $user_country_id;
|
||||
private $user_country;
|
||||
private $shopping_data = [];
|
||||
|
||||
public function __construct(SessionManager $session, Dispatcher $events)
|
||||
|
|
@ -51,10 +55,21 @@ class Yard extends Cart
|
|||
if($this->getYardExtra('shipping_is_for')){
|
||||
$this->shipping_is_for = $this->getYardExtra('shipping_is_for');
|
||||
}
|
||||
|
||||
if($this->getYardExtra('num_comp')){
|
||||
$this->num_comp = $this->getYardExtra('num_comp');
|
||||
}
|
||||
if($this->getYardExtra('user_tax_free')){
|
||||
$this->user_tax_free = $this->getYardExtra('user_tax_free');
|
||||
}
|
||||
if($this->getYardExtra('user_reverse_charge')){
|
||||
$this->user_reverse_charge = $this->getYardExtra('user_reverse_charge');
|
||||
}
|
||||
if($this->getYardExtra('user_country_id')){
|
||||
$this->user_country_id = $this->getYardExtra('user_country_id');
|
||||
}
|
||||
if($this->getYardExtra('user_country')){
|
||||
$this->user_country = $this->getYardExtra('user_country');
|
||||
}
|
||||
|
||||
|
||||
parent::__construct($session, $events);
|
||||
|
|
@ -139,6 +154,44 @@ class Yard extends Cart
|
|||
|
||||
}
|
||||
|
||||
public function setUserPriceInfos($setUserPriceInfos = [])
|
||||
{
|
||||
$this->user_tax_free = $setUserPriceInfos['user_tax_free'];
|
||||
$this->putYardExtra('user_tax_free', $setUserPriceInfos['user_tax_free']);
|
||||
|
||||
$this->user_reverse_charge = $setUserPriceInfos['user_reverse_charge'];
|
||||
$this->putYardExtra('user_reverse_charge', $setUserPriceInfos['user_reverse_charge']);
|
||||
|
||||
$this->user_country_id = $setUserPriceInfos['user_country_id'];
|
||||
$this->putYardExtra('user_country_id', $setUserPriceInfos['user_country_id']);
|
||||
|
||||
$this->user_country = Country::findOrFail($setUserPriceInfos['user_country_id']);
|
||||
$this->putYardExtra('user_country', $this->user_country);
|
||||
}
|
||||
|
||||
public function getUserPriceInfos(){
|
||||
return [
|
||||
'user_tax_free' =>$this->user_tax_free,
|
||||
'user_reverse_charge' =>$this->user_reverse_charge,
|
||||
'user_country_id' =>$this->user_country_id,
|
||||
];
|
||||
}
|
||||
|
||||
public function getUserCountryId()
|
||||
{
|
||||
return $this->user_country_id;
|
||||
}
|
||||
|
||||
public function getUserCountry()
|
||||
{
|
||||
return $this->user_country;
|
||||
}
|
||||
|
||||
public function getUserTaxFree()
|
||||
{
|
||||
return $this->user_tax_free;
|
||||
}
|
||||
|
||||
private function calculateShippingPrice(){
|
||||
|
||||
$shippingCountry = ShippingCountry::find($this->shipping_country_id);
|
||||
|
|
@ -146,9 +199,11 @@ class Yard extends Cart
|
|||
return;
|
||||
}
|
||||
$shipping = $shippingCountry->shipping;
|
||||
|
||||
if($this->weight() == 0){
|
||||
$shipping_price = $shipping->shipping_prices->first();
|
||||
if(!$shipping_price){
|
||||
return;
|
||||
}
|
||||
$shipping_price->price = 0;
|
||||
$shipping_price->price_comp = 0;
|
||||
}else{
|
||||
|
|
@ -241,16 +296,24 @@ class Yard extends Cart
|
|||
|
||||
public function taxWithShipping($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
||||
{
|
||||
if($this->user_tax_free){
|
||||
return $this->numberFormat(0, $decimals, $decimalPoint, $thousandSeperator);
|
||||
}
|
||||
$total = $this->totalWithShipping(2, '.', '');
|
||||
// $totalTax = (float) $this->tax(2, '.', '') + $this->shipping_tax;
|
||||
$totalTax = $this->subtotalWithShipping(2, '.', '');
|
||||
// $totalTax = (float) $this->tax(2, '.', '') + $this->shipping_tax;
|
||||
$totalTax = $this->subtotalWithShipping(2, '.', '');
|
||||
return $this->numberFormat(($total - $totalTax), $decimals, $decimalPoint, $thousandSeperator);
|
||||
}
|
||||
|
||||
|
||||
public function totalWithShipping($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
||||
{
|
||||
$total = (float) ($this->total(2, '.', '')) + $this->shipping_price;
|
||||
if($this->user_tax_free){
|
||||
$total = (float) ($this->subtotal(2, '.', '')) + $this->shipping_price_net;
|
||||
}else{
|
||||
$total = (float) ($this->total(2, '.', '')) + $this->shipping_price;
|
||||
}
|
||||
|
||||
return $this->numberFormat($total, $decimals, $decimalPoint, $thousandSeperator);
|
||||
}
|
||||
|
||||
|
|
@ -359,7 +422,7 @@ class Yard extends Cart
|
|||
}
|
||||
$price = $product->price;
|
||||
if($set_price === 'with'){
|
||||
$price = $product->getPriceWith(false, true);
|
||||
$price = $product->getPriceWith(false, true, $this->getUserCountry());
|
||||
}
|
||||
$cartItem = $this->getCartItem($product->id, $product->getLang('name'), 1, $price, ['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points]);
|
||||
$content = $this->getContent();
|
||||
|
|
@ -402,6 +465,71 @@ class Yard extends Cart
|
|||
return $this->numberFormat(($price * $row->qty), $decimals, $decimalPoint, $thousandSeperator);
|
||||
}
|
||||
|
||||
public function isPriceCurrency()
|
||||
{
|
||||
return ($this->user_country && $this->user_country->currency) ? true : false;
|
||||
}
|
||||
|
||||
public function getPriceCurrencyUnit()
|
||||
{
|
||||
return ($this->user_country && $this->user_country->currency) ? $this->user_country->currency_unit : false;
|
||||
}
|
||||
|
||||
public function convertCurrency($value = 0, $decimals = null, $decimalPoint = null, $thousandSeperator = null){
|
||||
if($this->isPriceCurrency()){
|
||||
$faktor = isset($this->user_country->currency_faktor) ? $this->user_country->currency_faktor : 1;
|
||||
$value = Util::reFormatNumber($value);
|
||||
return $this->numberFormat($value, $decimals, $decimalPoint, $thousandSeperator);
|
||||
}
|
||||
return '';
|
||||
|
||||
}
|
||||
public function getCurrencyByKey($key = false, CartItem $row = null, $decimals = null, $decimalPoint = null, $thousandSeperator = null){
|
||||
|
||||
if($this->isPriceCurrency()){
|
||||
$rNumber = 0;
|
||||
$faktor = isset($this->user_country->currency_faktor) ? $this->user_country->currency_faktor : 1;
|
||||
switch ($key) {
|
||||
case 'rowPriceNetCurrency':
|
||||
if($row){
|
||||
$price = round($row->price / ((100 + $row->taxRate) /100), 4);
|
||||
$rNumber = $price * $faktor;
|
||||
}
|
||||
break;
|
||||
case 'rowSubtotalCurrency':
|
||||
if($row){
|
||||
$price = round($row->price / ((100 + $row->taxRate) /100), 4);
|
||||
$rNumber = $price * $faktor * $row->qty;
|
||||
}
|
||||
break;
|
||||
case 'subtotal':
|
||||
$rNumber = (float) ($this->subtotal(2, '.', '')) * $faktor;
|
||||
break;
|
||||
case 'shippingNet':
|
||||
$rNumber = (float) ($this->shippingNet(2, '.', '')) * $faktor;
|
||||
break;
|
||||
case 'subtotalWithShipping':
|
||||
$rNumber = (float) ($this->subtotalWithShipping(2, '.', '')) * $faktor;
|
||||
break;
|
||||
case 'taxWithShipping':
|
||||
$rNumber = (float) ($this->taxWithShipping(2, '.', '')) * $faktor;
|
||||
break;
|
||||
case 'totalWithShipping':
|
||||
$rNumber = (float) ($this->totalWithShipping(2, '.', '')) * $faktor;
|
||||
break;
|
||||
case 'total':
|
||||
$rNumber = (float) ($this->total(2, '.', '')) * $faktor;
|
||||
break;
|
||||
case 'shipping':
|
||||
$rNumber = (float) ($this->shipping(2, '.', '')) * $faktor;
|
||||
break;
|
||||
}
|
||||
return $this->numberFormat($rNumber, $decimals, $decimalPoint, $thousandSeperator);
|
||||
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getNumComp(){
|
||||
return $this->num_comp;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue