shipping costs

This commit is contained in:
Kevin Adametz 2019-01-07 00:15:41 +01:00
parent d4f6a774d0
commit 22a2b4710a
20 changed files with 797 additions and 457 deletions

View file

@ -50,8 +50,14 @@ class DataTableController extends Controller
$query = User::where('deleted_at', '=', null);
return \DataTables::eloquent($query)
->addColumn('first_name', function (User $user) {
return $user->account ? $user->account->first_name : '';
})
->addColumn('last_name', function (User $user) {
return $user->account ? $user->account->last_name : '';
})
->addColumn('action_edit', function (User $user) {
return '<a href="' . route('admin_user_edit', [$user->id]) . '" class="btn icon-btn btn-sm btn-primary"><span class="far fa-edit"></span></a>';
return '<a href="' . route('admin_lead_edit', [$user->id]) . '" class="btn icon-btn btn-sm btn-primary"><span class="far fa-edit"></span></a>';
})
->addColumn('admin', function (User $user) {
return '<a href="#" data-toggle="modal" data-target="#modals-default" data-id="'.$user->id.'" data-email="'.$user->email.'" data-admin="'.$user->admin.'" data-active="'.$user->active.'" data-confirmed="'.$user->confirmed.'">'.HTMLHelper::getRoleLabel($user->admin).'</a>';
@ -62,13 +68,24 @@ class DataTableController extends Controller
->addColumn('active', function (User $user) {
return $user->active ? ' <span class="badge badge-pill badge-success"><i class="far fa-check"></i></span>' : '<span class="badge badge-pill badge-danger"><i class="far fa-times"></i></span>';
})
->addColumn('shop', function (User $user) {
if($user->shop){
if($user->shop->active){
return '<span class="badge badge-pill badge-success"><i class="far fa-check"></i> active</span>'.$user->shop->getActiveDateFormatSmall();
}else{
return'<span class="badge badge-pill badge-success"><i class="far fa-check"></i> deactive</span>'.$user->shop->getActiveDateFormatSmall();
}
}
return '<span class="badge badge-pill badge-danger"><i class="far fa-times"></i></span>';
})
->addColumn('action_delete', function (User $user) {
return '<a href="' . route('admin_user_delete', [$user->id]) . '" class="btn icon-btn btn-sm btn-danger" onclick="return confirm(\''.__('Really delete entry?').'\');"><span class="far fa-trash"></span></a>';
})
->orderColumn('confirmed', 'confirmed $1')
->orderColumn('active', 'active $1')
->orderColumn('shop', 'shop $1')
->orderColumn('admin', 'active $1')
->rawColumns(['action_edit', 'admin', 'confirmed', 'active', 'action_delete'])
->rawColumns(['action_edit', 'admin', 'confirmed', 'active', 'shop', 'action_delete'])
->make(true);
}

View file

@ -6,6 +6,8 @@ namespace App\Http\Controllers;
use App\Models\Shipping;
use App\Models\ShippingCountry;
use App\Models\ShippingPrice;
use Input;
use Illuminate\Http\Request;
use Validator;
@ -55,50 +57,94 @@ class ShippingController extends Controller
*/
public function store(Request $request)
{
$data = Input::all();
if ($data['id'] == "new") {
$shipping = new Shipping();
$rules = array(
'name' => 'required',
);
} else {
$shipping = Shipping::findOrFail($data['id']);
$rules = array(
'name' => 'required',
);
}
$data = [
'value' => $shipping,
];
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return view('admin.shipping.edit', $data)->withErrors($validator);
}
$shipping = false;
$data = Input::all();
$shipping->name = $data['name'];
$shipping->free = $data['free'];
$shipping->active = isset($data['active']) ? true : false;
$shipping->save();
if($data['action'] == 'shipping'){
if ($data['id'] == "new") {
$shipping = new Shipping();
$rules = array('name' => 'required');
} else {
$shipping = Shipping::findOrFail($data['id']);
$rules = array('name' => 'required');
}
$ret = ['value' => $shipping];
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return view('admin.shipping.edit', $ret)->withErrors($validator);
}
$data = Input::all();
$shipping->name = $data['name'];
$shipping->free = $data['free'];
$shipping->active = isset($data['active']) ? true : false;
$shipping->save();
}
if($data['action'] == 'price'){
$shipping = Shipping::findOrFail($data['shipping_id']);
$rules = array('price' => 'required');
$ret = ['value' => $shipping];
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return view('admin.shipping.edit', $ret)->withErrors($validator);
}
if ($data['id'] == "new") {
$price = ShippingPrice::create($data);
} else {
$price = ShippingPrice::findOrFail($data['id']);
if($price->shipping_id != $shipping->id){
abort(404);
}
$price->fill($data);
$price->save();
}
\Session()->flash('alert-save', true);
}
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){
ShippingCountry::create([
'shipping_id' => $shipping->id,
'country_id' => $country_id
]);
}
}
}
return redirect(route('admin_shipping_edit', [$shipping->id]));
if($shipping){
\Session()->flash('alert-save', true);
return redirect(route('admin_shipping_edit', [$shipping->id]));
}
return redirect(route('admin_shippings'));
}
public function deleteShipping($shipping_id)
{
$shipping = Shipping::findOrFail($shipping_id);
$shipping->delete();
public function deleteShipping($id)
{
$model = Shipping::findOrFail($id);
$model->delete();
\Session()->flash('alert-success', "Versandkosten gelöscht");
return redirect('/admin/shippings');
}
public function deletePrice($id)
{
$model = ShippingPrice::findOrFail($id);
$shipping = $model->shipping;
$model->delete();
\Session()->flash('alert-success', "Preis gelöscht");
return redirect(route('admin_shipping_edit', [$shipping->id]));
}
public function deleteCountry($id)
{
$model = ShippingCountry::findOrFail($id);
$shipping = $model->shipping;
$model->delete();
\Session()->flash('alert-success', "Preis gelöscht");
return redirect(route('admin_shipping_edit', [$shipping->id]));
}
}

View file

@ -5,6 +5,7 @@ namespace App\Http\Controllers\Web;
use App\Http\Controllers\Controller;
use App\Models\Product;
use App\Models\ShippingCountry;
use Util;
use Yard;
use Input;
@ -57,6 +58,15 @@ class CardController extends Controller
}
public function showCard(){
if(Input::get('selected_country')){
$selected_country = Input::get('selected_country');
}else{
$ShippingCountry = ShippingCountry::where('country_id', 1)->first();
$selected_country = $ShippingCountry->id;
}
Yard::instance('shopping')->setShippingCountry($selected_country);
$data = [
'user_shop' => Util::getUserShop(),
];
@ -76,7 +86,14 @@ class CardController extends Controller
return back();
}
public function checkoutCard(){
public function checkoutCard(){#
if(Input::get('selected_country')){
$selected_country = Input::get('selected_country');
}else{
$ShippingCountry = ShippingCountry::where('country_id', 1)->first();
$selected_country = $ShippingCountry->id;
}
Yard::instance('shopping')->setShippingCountry($selected_country);
$data = [
'user_shop' => Util::getUserShop(),
];

View file

@ -105,6 +105,7 @@ class Product extends Model
'price_ek',
'tax',
'price_old',
'weight',
'contents',
'number',
'icons',

View file

@ -30,7 +30,7 @@ class Shipping extends Model
}
public function getFormattedFree()
{
if($this->attributes['free'] === null) {
if($this->free === null) {
return "";
}
if(\App::getLocale() == "en"){

View file

@ -22,4 +22,5 @@ class ShippingCountry extends Model
{
return $this->belongsTo('App\Models\Country', 'country_id');
}
}

View file

@ -18,47 +18,75 @@ class ShippingPrice extends Model
}
public function _format_number($value){
public function _format_number($value)
{
return preg_replace("/[^0-9,]/", "", $value);
}
public function setPriceAttribute( $value ) {
public function setPriceAttribute($value)
{
$value = $this->_format_number($value);
$this->attributes['price'] = floatval(str_replace(',', '.', $value));
}
public function setFactorAttribute( $value ) {
$value = $this->_format_number($value);
$this->attributes['factor'] = floatval(str_replace(',', '.', $value));
}
public function setTaxAttribute( $value ) {
$value = $this->_format_number($value);
$this->attributes['tax'] = floatval(str_replace(',', '.', $value));
}
public function setPriceOldAttribute( $value ) {
$value = $this->_format_number($value);
$this->attributes['price_old'] = floatval(str_replace(',', '.', $value));
}
public function setTotalFromAttribute( $value ) {
public function setFactorAttribute($value)
{
$value = $this->_format_number($value);
$this->attributes['total_from'] = floatval(str_replace(',', '.', $value));
if ($value == "") {
$this->attributes['factor'] = null;
} else {
$this->attributes['factor'] = floatval(str_replace(',', '.', $value));
}
}
public function setTotalToAttribute( $value ) {
public function setTaxAttribute($value)
{
$value = $this->_format_number($value);
$this->attributes['total_to'] = floatval(str_replace(',', '.', $value));
if ($value == "") {
$this->attributes['tax'] = null;
} else {
$this->attributes['tax'] = floatval(str_replace(',', '.', $value));
}
}
public function setTotalFromAttribute($value)
{
$value = $this->_format_number($value);
if ($value == "") {
$this->attributes['total_from'] = null;
} else {
$this->attributes['total_from'] = floatval(str_replace(',', '.', $value));
}
}
public function setTotalToAttribute($value)
{
$value = $this->_format_number($value);
if ($value == "") {
$this->attributes['total_to'] = null;
} else {
$this->attributes['total_to'] = floatval(str_replace(',', '.', $value));
}
}
public function getFormattedPrice()
{
if(\App::getLocale() == "en"){
if (\App::getLocale() == "en") {
return number_format($this->attributes['price'], 2, '.', ',');
}
return number_format($this->attributes['price'], 2, ',', '.');
}
public function getFormattedTax()
{
if(\App::getLocale() == "en"){
if ($this->attributes['tax'] === NULL) {
return $this->attributes['tax'];
}
if (\App::getLocale() == "en") {
return number_format($this->attributes['tax'], 2, '.', ',');
}
return number_format($this->attributes['tax'], 2, ',', '.');
@ -66,7 +94,10 @@ class ShippingPrice extends Model
public function getFormattedFactor()
{
if(\App::getLocale() == "en"){
if ($this->attributes['factor'] === NULL) {
return $this->attributes['factor'];
}
if (\App::getLocale() == "en") {
return number_format($this->attributes['factor'], 2, '.', ',');
}
return number_format($this->attributes['factor'], 2, ',', '.');
@ -75,19 +106,25 @@ class ShippingPrice extends Model
public function getFormatTotalFrom()
{
if(\App::getLocale() == "en"){
if ($this->attributes['total_from'] === NULL) {
return $this->attributes['total_from'];
}
if (\App::getLocale() == "en") {
return number_format($this->attributes['total_from'], 2, '.', ',');
}
return number_format($this->attributes['total_from'], 2, ',', '.');
}
public function getFormattedTotalTo()
{
if(\App::getLocale() == "en"){
if ($this->attributes['total_to'] === NULL) {
return $this->attributes['total_to'];
}
if (\App::getLocale() == "en") {
return number_format($this->attributes['total_to'], 2, '.', ',');
}
return number_format($this->attributes['total_to'], 2, ',', '.');
}
}

View file

@ -47,6 +47,11 @@ class UserShop extends Model
return Carbon::parse($this->attributes['active_date'])->format(\Util::formatDateTimeDB());
}
public function getActiveDateFormatSmall(){
if(!$this->attributes['active_date']){ return ""; }
return Carbon::parse($this->attributes['active_date'])->format("d.m.Y");
}
public function getSubdomain()
{

View file

@ -4,6 +4,7 @@ namespace App\Services;
use App\Models\Attribute;
use App\Models\Category;
use App\Models\Country;
use App\Models\ShippingCountry;
class HTMLHelper
{
@ -189,6 +190,36 @@ class HTMLHelper
return $ret;
}
public static function getCountriesWithoutUsedShippings($all=true){#
$values = Country::all();
$country_ids = ShippingCountry::all()->pluck('country_id')->toArray();
$ret = "";
if($all){
$ret .= '<option value="">'.__('please select').'</option>\n';
}
foreach ($values as $value){
if(!in_array($value->id, $country_ids)){
$ret .= '<option value="'.$value->id.'">'.$value->getLocated().'</option>\n';
}
}
return $ret;
}
public static function getCountriesForShipping($id, $all=false){#
$values = ShippingCountry::all();
$ret = "";
if($all){
$ret .= '<option value="">'.__('please select').'</option>\n';
}
foreach ($values as $value){
$attr = ($value->id == $id) ? 'selected="selected"' : '';
$ret .= '<option value="'.$value->id.'" '.$attr.'>'.$value->country->getLocated().'</option>\n';
}
return $ret;
}
public static function getSalutation($id){
$values = array('mr' => __('MR'), 'ms' => __('MS'));

View file

@ -1,6 +1,7 @@
<?php
namespace App\Services;
use App\Models\ShippingCountry;
use \Gloudemans\Shoppingcart\Cart;
use Gloudemans\Shoppingcart\CartItem;
use Illuminate\Session\SessionManager;
@ -11,6 +12,7 @@ class Yard extends Cart
{
private $shipping = 0;
private $shipping_country_id = 0;
public function __construct(SessionManager $session, Dispatcher $events)
{
@ -33,6 +35,24 @@ class Yard extends Cart
}
public function setShippingCountry($shipping_country_id)
{
$this->shipping_country_id = $shipping_country_id ;
if($this->shipping_country_id > 0){
$shippingCountry = ShippingCountry::find($this->shipping_country_id);
$shipping = $shippingCountry->shipping;
$price = $shipping->prices->first();
if($price){
$this->setShipping($price->price);
}
}
}
public function getShippingCountry()
{
return $this->shipping_country_id;
}
/**
* @param null $decimals
* @param null $decimalPoint