Shipping Tax Card

This commit is contained in:
Kevin Adametz 2020-07-01 16:13:38 +02:00
parent da08e9ff37
commit eb55b01b0d
13 changed files with 86 additions and 81 deletions

24
.idea/workspace.xml generated
View file

@ -3,17 +3,18 @@
<component name="ChangeListManager">
<list default="true" id="2fbaac5f-25ba-4502-a970-cc14728d7d55" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Http/Controllers/Api/ShoppingUserController.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Http/Controllers/Api/ShoppingUserController.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Http/Controllers/Web/CardController.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Http/Controllers/Web/CardController.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Http/Controllers/Web/CheckoutController.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Http/Controllers/Web/CheckoutController.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Models/Product.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Models/Product.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Models/ShoppingOrder.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Models/ShoppingOrder.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Models/ShoppingOrderItem.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Models/ShoppingOrderItem.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Http/Controllers/ShippingController.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Http/Controllers/ShippingController.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Models/Shipping.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Models/Shipping.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Models/ShippingPrice.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Models/ShippingPrice.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Services/Yard.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Services/Yard.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/config/cart.php" beforeDir="false" afterPath="$PROJECT_DIR$/config/cart.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/database/migrations/2019_01_06_004849_create_shipping_prices_table.php" beforeDir="false" afterPath="$PROJECT_DIR$/database/migrations/2019_01_06_004849_create_shipping_prices_table.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/database/migrations/2019_02_23_163724_create_shopping_order_items_table.php" beforeDir="false" afterPath="$PROJECT_DIR$/database/migrations/2019_02_23_163724_create_shopping_order_items_table.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/lang/de/email.php" beforeDir="false" afterPath="$PROJECT_DIR$/resources/lang/de/email.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/views/admin/shipping/edit.blade.php" beforeDir="false" afterPath="$PROJECT_DIR$/resources/views/admin/shipping/edit.blade.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/views/emails/checkout.blade.php" beforeDir="false" afterPath="$PROJECT_DIR$/resources/views/emails/checkout.blade.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/views/emails/checkout_status.blade.php" beforeDir="false" afterPath="$PROJECT_DIR$/resources/views/emails/checkout_status.blade.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/views/web/templates/card.blade.php" beforeDir="false" afterPath="$PROJECT_DIR$/resources/views/web/templates/card.blade.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/views/web/templates/checkout.blade.php" beforeDir="false" afterPath="$PROJECT_DIR$/resources/views/web/templates/checkout.blade.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/views/web/templates/produkte-show.blade.php" beforeDir="false" afterPath="$PROJECT_DIR$/resources/views/web/templates/produkte-show.blade.php" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -486,6 +487,7 @@
<workItem from="1592831761021" duration="3000" />
<workItem from="1592905155133" duration="2081000" />
<workItem from="1593539130650" duration="5379000" />
<workItem from="1593607978036" duration="4312000" />
</task>
<servers />
</component>
@ -541,12 +543,12 @@
<screen x="0" y="23" width="2560" height="1417" />
</state>
<state x="951" y="549" key="com.jetbrains.php.test.PhpNewTestDialog/-2560.23.2560.1417/2560.-527.1440.2537/0.23.2560.1417@0.23.2560.1417" timestamp="1591961096724" />
<state x="805" y="444" width="1115" height="793" key="find.popup" timestamp="1593544315663">
<state x="805" y="444" width="1115" height="793" key="find.popup" timestamp="1593612216078">
<screen x="0" y="23" width="2560" height="1417" />
</state>
<state x="805" y="444" width="1115" height="793" key="find.popup/-2560.23.2560.1417/0.23.2560.1417@0.23.2560.1417" timestamp="1589024021327" />
<state x="-1755" y="444" width="1115" height="793" key="find.popup/-2560.23.2560.1417/2560.-527.1440.2537/0.23.2560.1417@-2560.23.2560.1417" timestamp="1589974580416" />
<state x="805" y="444" width="1115" height="793" key="find.popup/-2560.23.2560.1417/2560.-527.1440.2537/0.23.2560.1417@0.23.2560.1417" timestamp="1593544315663" />
<state x="805" y="444" width="1115" height="793" key="find.popup/-2560.23.2560.1417/2560.-527.1440.2537/0.23.2560.1417@0.23.2560.1417" timestamp="1593612216078" />
<state x="863" y="438" width="1115" height="793" key="find.popup/2560.-493.1440.2537/-2560.23.2560.1417/0.23.2560.1417@0.23.2560.1417" timestamp="1585758694219" />
<state x="863" y="438" width="1115" height="793" key="find.popup/2560.-527.1440.2537/-2560.23.2560.1417/0.23.2560.1417@0.23.2560.1417" timestamp="1587109016568" />
<state x="945" y="377" width="670" height="676" key="search.everywhere.popup" timestamp="1593542096563">
@ -565,7 +567,7 @@
</line-breakpoint>
<line-breakpoint enabled="true" type="php">
<url>file://$PROJECT_DIR$/resources/views/emails/checkout.blade.php</url>
<line>360</line>
<line>362</line>
<option name="timeStamp" value="4" />
</line-breakpoint>
</breakpoints>

View file

@ -59,8 +59,8 @@ class ShippingController extends Controller
$shipping = false;
$data = Request::all();
if($data['action'] == 'shipping'){
if ($data['id'] == "new") {
if($data['action'] === 'shipping'){
if ($data['id'] === "new") {
$shipping = new Shipping();
$rules = array('name' => 'required');
} else {
@ -79,7 +79,7 @@ class ShippingController extends Controller
$shipping->save();
}
if($data['action'] == 'price'){
if($data['action'] === 'price'){
$shipping = Shipping::findOrFail($data['shipping_id']);
$rules = array('price' => 'required');
$ret = ['value' => $shipping];
@ -87,7 +87,7 @@ class ShippingController extends Controller
if ($validator->fails()) {
return view('admin.shipping.edit', $ret)->withErrors($validator);
}
if ($data['id'] == "new") {
if ($data['id'] === "new") {
$price = ShippingPrice::create($data);
} else {
$price = ShippingPrice::findOrFail($data['id']);
@ -99,7 +99,7 @@ class ShippingController extends Controller
}
}
if($data['action'] == 'country'){
if($data['action'] === 'country'){
$shipping = Shipping::findOrFail($data['shipping_id']);
foreach($data['country_ids'] as $country_id){
if(ShippingCountry::where('country_id', $country_id)->count() == 0){

View file

@ -73,4 +73,7 @@ class Shipping extends Model
public function prices(){
return $this->hasMany('App\Models\ShippingPrice', 'shipping_id', 'id');
}
public function shipping_prices(){
return $this->hasMany('App\Models\ShippingPrice', 'shipping_id', 'id');
}
}

View file

@ -10,7 +10,7 @@ use Illuminate\Database\Eloquent\Model;
* @property int $id
* @property int $shipping_id
* @property float|null $price
* @property float|null $tax
* @property float|null $tax_rate
* @property float|null $factor
* @property float|null $total_from
* @property float|null $total_to
@ -40,7 +40,7 @@ class ShippingPrice extends Model
protected $table = 'shipping_prices';
protected $fillable = [
'shipping_id', 'price', 'tax', 'factor', 'total_from', 'total_to', 'weight_from', 'weight_to',
'shipping_id', 'price', 'tax_rate', 'factor', 'total_from', 'total_to', 'weight_from', 'weight_to',
];
public function shipping()
@ -75,9 +75,9 @@ class ShippingPrice extends Model
{
$value = $this->_format_number($value);
if ($value == "") {
$this->attributes['tax'] = null;
$this->attributes['tax_rate'] = null;
} else {
$this->attributes['tax'] = floatval(str_replace(',', '.', $value));
$this->attributes['tax_rate'] = floatval(str_replace(',', '.', $value));
}
}
@ -115,15 +115,15 @@ class ShippingPrice extends Model
return number_format($this->attributes['price'], 2, ',', '.');
}
public function getFormattedTax()
public function getFormattedTaxRate()
{
if ($this->attributes['tax'] === NULL) {
return $this->attributes['tax'];
if ($this->attributes['tax_rate'] === NULL) {
return $this->attributes['tax_rate'];
}
if (\App::getLocale() == "en") {
return number_format($this->attributes['tax'], 2, '.', ',');
return number_format($this->attributes['tax_rate'], 2, '.', ',');
}
return number_format($this->attributes['tax'], 2, ',', '.');
return number_format($this->attributes['tax_rate'], 2, ',', '.');
}
public function getFormattedFactor()

View file

@ -11,7 +11,8 @@ use Illuminate\Support\Collection;
class Yard extends Cart
{
private $shipping = 0;
private $shipping_price = 0;
private $shipping_tax = 0;
private $shipping_country_id = 0; //default de
private $ysession;
private $yinstance;
@ -21,7 +22,11 @@ class Yard extends Cart
$this->ysession = $session;
$this->yinstance = sprintf('%s.%s', 'cart', 'shipping_extras');
if($this->getShippingExtra('shipping_price')){
$this->shipping = floatval($this->getShippingExtra('shipping_price'));
$this->shipping_price = (float) ($this->getShippingExtra('shipping_price'));
}
if($this->getShippingExtra('shipping_tax')){
$this->shipping_tax = (float) ($this->getShippingExtra('shipping_tax'));
}
if($this->getShippingExtra('shipping_country_id')){
@ -32,20 +37,18 @@ class Yard extends Cart
if($this->shipping_country_id == 0){
$shippingCountry = ShippingCountry::first();
if($shippingCountry){
$this->shipping_country_id = $shippingCountry->id;
}
if($this->shipping == 0){
}
if($this->shipping_price == 0){
self::instance('shopping')->setShippingCountryWithPrice($this->shipping_country_id);
}
}
public static function getTaxRate()
{
return config('cart.tax');
}
public function putShippingExtra($key, $value){
@ -53,7 +56,6 @@ class Yard extends Cart
$content = $this->getYContent();
$content->put($key, $value);
$this->ysession->put($this->yinstance, $content);
}
public function getShippingExtra($key){
@ -113,24 +115,26 @@ class Yard extends Cart
$shippingCountry = ShippingCountry::find($this->shipping_country_id);
$shipping = $shippingCountry->shipping;
if(intval($this->weight()) == 0){
$price = $shipping->prices->first();
$price->price = 0;
if($this->weight() == 0){
$shipping_price = $shipping->shipping_prices->first();
$shipping_price->price = 0;
}else{
//first by price
$price = $this->shippingPriceByTotal($shipping->prices, floatval($this->total(2, '.', ',')));
$shipping_price = $this->shippingPriceByTotal($shipping->shipping_prices, $this->total(2, '.', ''));
//sec by weight
if(!$price){
$price = $this->shippingPriceByWeight($shipping->prices, intval($this->weight()));
if(!$shipping_price){
$shipping_price = $this->shippingPriceByWeight($shipping->shipping_prices, $this->weight());
}
//default
if(!$price){
$price = $shipping->prices->first();
if(!$shipping_price){
$shipping_price = $shipping->shipping_prices->first();
}
}
if($price){
$this->shipping = floatval($price->price);
$this->putShippingExtra('shipping_price', $this->shipping);
if($shipping_price){
$this->shipping_price = $shipping_price->price;
$this->shipping_tax = $shipping_price->tax_rate;
$this->putShippingExtra('shipping_price', $this->shipping_price);
$this->putShippingExtra('shipping_tax', $this->shipping_tax);
}
}
@ -155,9 +159,6 @@ class Yard extends Cart
return false;
}
/**
* @param null $decimals
* @param null $decimalPoint
@ -166,26 +167,24 @@ class Yard extends Cart
*/
public function shipping($decimals = null, $decimalPoint = null, $thousandSeperator = null)
{
return $this->numberFormat($this->shipping, $decimals, $decimalPoint, $thousandSeperator);
return $this->numberFormat($this->shipping_price, $decimals, $decimalPoint, $thousandSeperator);
}
//
private function shippingTax($taxRate = -19){
return ($this->shipping * ($taxRate / 100));
private function shippingTax($decimals = null, $decimalPoint = null, $thousandSeperator = null){
$shippingTax = $this->shipping_price / (100 + $this->shipping_tax) * $this->shipping_tax;
return $this->numberFormat($shippingTax, $decimals, $decimalPoint, $thousandSeperator);
}
private function shippingSub($taxRate){
return ($this->shipping + $this->shippingTax($taxRate));
private function subShipping($decimals = null, $decimalPoint = null, $thousandSeperator = null){
$subShipping = $this->shipping_price - $this->shippingTax($decimals, $decimalPoint, $thousandSeperator);
return $this->numberFormat($subShipping, $decimals, $decimalPoint, $thousandSeperator);
}
public function subtotalWithShipping($decimals = null, $decimalPoint = null, $thousandSeperator = null)
{
$subtotal = $this->subtotal(2, '.', '') + $this->shipping;
//$taxRate =config('cart.tax');
/*$total = (float) ($this->total(2, '.', '')) + $this->shipping;
$totalTax = $total/ (100 + $taxRate) * $taxRate;*/
$subtotal = $this->subtotal(2, '.', '') + $this->subShipping(2, '.', '');
return $this->numberFormat($subtotal, $decimals, $decimalPoint, $thousandSeperator);
}
@ -193,21 +192,17 @@ class Yard extends Cart
public function taxWithShipping($decimals = null, $decimalPoint = null, $thousandSeperator = null)
{
$totalTax = $this->tax(2, '.', '');
/* $taxRate =config('cart.tax');
$total = (float) ($this->total(2, '.', '')) + $this->shipping;
$totalTax = $total/ (100 + $taxRate) * $taxRate; */
return $this->numberFormat($totalTax, $decimals, $decimalPoint, $thousandSeperator);
$shippingTax = $this->shippingTax(2, '.', '');
return $this->numberFormat(($totalTax+$shippingTax), $decimals, $decimalPoint, $thousandSeperator);
}
public function totalWithShipping($decimals = null, $decimalPoint = null, $thousandSeperator = null)
{
$total = (float) ($this->total(2, '.', '')) + $this->shipping;
$total = (float) ($this->total(2, '.', '')) + $this->shipping_price;
return $this->numberFormat($total, $decimals, $decimalPoint, $thousandSeperator);
}
/**
* Get the total price of the items in the cart.
*
@ -220,7 +215,7 @@ class Yard extends Cart
{
$content = $this->getContent();
$total = $content->reduce(function ($total, CartItem $cartItem) {
return $total + ($cartItem->options->weight ? intval($cartItem->options->weight*$cartItem->qty) : 0);
return $total + ($cartItem->options->weight ? ($cartItem->options->weight*$cartItem->qty) : 0);
}, 0);
return $total;

View file

@ -12,7 +12,7 @@ return [
|
*/
'tax' => 19,
'tax' => 16,
/*
|--------------------------------------------------------------------------

View file

@ -18,7 +18,7 @@ class CreateShippingPricesTable extends Migration
$table->unsignedInteger('shipping_id');
$table->decimal('price', 8, 2)->nullable();
$table->decimal('tax', 5, 2)->nullable();
$table->decimal('tax_rate', 5, 2)->nullable();
$table->decimal('factor', 5, 2)->nullable();
$table->decimal('total_from', 8, 2)->nullable();

View file

@ -21,6 +21,7 @@ class CreateShoppingOrderItemsTable extends Migration
$table->unsignedInteger('product_id');
$table->unsignedInteger('qty');
$table->decimal('price', 8, 2)->nullable();
$table->decimal('tax_rate', 5, 2)->nullable();
$table->string('slug')->nullable();
$table->timestamps();

View file

@ -48,6 +48,7 @@
'checkout_mail_shipping' => 'Verpackungs- u. Versandkosten',
'checkout_mail_status_info' => 'Statusinfo:',
'checkout_mail_total' => 'Gesamtpreis',
'checkout_mail_tax_info' => 'Preis inkl. MwSt',
'checkout_mail_pay_info' => 'Zahlungsinfo:',
'checkout_mail_pay_success' => 'Zahlung ist bestätigt!',
'checkout_mail_pay_with' => 'Zahlung mit:',

View file

@ -83,7 +83,7 @@
<button type="button" class="btn icon-btn btn-sm btn-primary" data-toggle="modal" data-target="#modals-price"
data-id="{{ $price->id }}"
data-price="{{ $price->getFormattedPrice() }}"
data-tax="{{ $price->getFormattedTax() }}"
data-tax_rate="{{ $price->getFormattedTaxRate() }}"
data-factor="{{ $price->getFormattedFactor() }}"
data-total_from="{{ $price->getFormatTotalFrom() }}"
data-total_to="{{ $price->getFormattedTotalTo() }}"
@ -93,7 +93,7 @@
</button>
</td>
<td>{{ $price->getFormattedPrice() }}</td>
<td>{{ $price->getFormattedTax() }}</td>
<td>{{ $price->getFormattedTaxRate() }}</td>
<td>{{ $price->getFormatTotalFrom() }} - {{ $price->getFormattedTotalTo() }}</td>
<td>{{ $price->weight_from }} - {{ $price->weight_to }}</td>
<td><a class="text-danger" href="{{ route('admin_shipping_price_delete', [$price->id]) }}" onclick="return confirm('{{__('Really delete entry?')}}');"><i class="far fa-trash-alt"></i></a></td>
@ -106,7 +106,7 @@
<button type="button" class="btn btn-sm btn-primary" data-toggle="modal" data-target="#modals-price"
data-id="new"
data-price=""
data-tax=""
data-tax_rate=""
data-factor="1"
data-total_from=""
data-total_to=""
@ -139,8 +139,8 @@
<input type="text" class="form-control" name="price" placeholder="{{__('Preis in Euro')}}" required>
</div>
<div class="form-group col-6">
<label for="tax" class="form-label">{{__('enthaltene Tax (%)')}}</label>
<input type="text" class="form-control" name="tax" placeholder="{{__('Tax in %')}}">
<label for="tax_rate" class="form-label">{{__('enthaltene Tax (%)')}}</label>
<input type="text" class="form-control" name="tax_rate" placeholder="{{__('Tax in %')}}">
</div>
</div>
@ -250,7 +250,7 @@
var button = $(event.relatedTarget);
$(this).find(".modal-content input[name='id']").val(button.data('id'));
$(this).find(".modal-body input[name='price']").val(button.data('price'));
$(this).find(".modal-body input[name='tax']").val(button.data('tax'));
$(this).find(".modal-body input[name='tax_rate']").val(button.data('tax_rate'));
$(this).find(".modal-body input[name='factor']").val(button.data('factor'));
$(this).find(".modal-body input[name='total_from']").val(button.data('total_from'));
$(this).find(".modal-body input[name='total_to']").val(button.data('total_to'));

View file

@ -163,7 +163,7 @@
<td style="color:#37302d; text-align: left; vertical-align: top;line-height:1.6em;">
{{ $shopping_order_item->product->name }}
</td>
<td style="color:#37302d; text-align: left; vertical-align: top;line-height:1.6em;">
<td style="color:#37302d; text-align: right; vertical-align: top;line-height:1.6em;">
{{ $shopping_order_item->getFormattedPrice() }} EUR
</td>
</tr>
@ -180,7 +180,7 @@
<td style="color:#37302d; text-align: left; vertical-align: top;line-height:1.6em;">
{{__('email.checkout_mail_shipping')}}
</td>
<td style="color:#37302d; text-align: left; vertical-align: top;line-height:1.6em;">
<td style="color:#37302d; text-align: right; vertical-align: top;line-height:1.6em;">
{{ $shopping_order->getFormattedShipping() }} EUR
</td>
</tr>
@ -196,8 +196,10 @@
<td style="color:#37302d; text-align: left; vertical-align: top;line-height:1.6em;">
<b>{{__('email.checkout_mail_total')}}</b>
</td>
<td style="color:#37302d; text-align: left; vertical-align: top;line-height:1.6em;">
<td style="color:#37302d; text-align: right; vertical-align: top;line-height:1.6em;">
<b>{{ $shopping_order->getFormattedTotalShipping() }} EUR</b>
<br>
<span style="font-size: 0.8em">{{__('email.checkout_mail_tax_info')}}</span>
</td>
</tr>
</table>

View file

@ -208,7 +208,7 @@
<td style="color:#37302d; text-align: left; vertical-align: top;line-height:1.6em;">
{{ $shopping_order_item->product->name }}
</td>
<td style="color:#37302d; text-align: left; vertical-align: top;line-height:1.6em;">
<td style="color:#37302d; text-align: right; vertical-align: top;line-height:1.6em;">
{{ $shopping_order_item->getFormattedPrice() }} EUR
</td>
</tr>
@ -225,7 +225,7 @@
<td style="color:#37302d; text-align: left; vertical-align: top;line-height:1.6em;">
{{__('email.checkout_mail_shipping')}}
</td>
<td style="color:#37302d; text-align: left; vertical-align: top;line-height:1.6em;">
<td style="color:#37302d; text-align: right; vertical-align: top;line-height:1.6em;">
{{ $shopping_order->getFormattedShipping() }} EUR
</td>
</tr>
@ -241,8 +241,10 @@
<td style="color:#37302d; text-align: left; vertical-align: top;line-height:1.6em;">
<b>{{__('email.checkout_mail_total')}}</b>
</td>
<td style="color:#37302d; text-align: left; vertical-align: top;line-height:1.6em;">
<td style="color:#37302d; text-align: right; vertical-align: top;line-height:1.6em;">
<b>{{ $shopping_order->getFormattedTotalShipping() }} EUR</b>
<br>
<span style="font-size: 0.8em">{{__('email.checkout_mail_tax_info')}}</span>
</td>
</tr>
</table>

View file

@ -148,7 +148,6 @@
@foreach(Yard::instance('shopping')->content() as $row)
@php($product = \App\Models\Product::find($row->id))
<tr class="item yard">
<td>
@if($row->options->has('image'))