middleware('active.account');
}
public function index()
{
$data = [
];
return view('user.order.index', $data);
}
public function detail($id)
{
$user = User::find(\Auth::user()->id);
$shopping_order = ShoppingOrder::findOrFail($id);
if($shopping_order->auth_user_id !== $user->id){
abort(404);
}
if( $shopping_order->payment_for === 6 || $shopping_order->payment_for === 7){
return redirect(route('user_shop_order_detail', [$shopping_order->id]));
abort(403, 'Kundenbestellung');
}
$shopping_order->getLastShoppingPayment();
$data = [
'shopping_order' => $shopping_order,
'isAdmin' => false,
];
return view('user.order.detail', $data);
}
public function ordersDatatable(){
$user = User::find(\Auth::user()->id);
$query = ShoppingOrder::with('shopping_user', 'shopping_payments')->select('shopping_orders.*')->where('auth_user_id', '=', $user->id)->where('txaction', '!=', NULL);
return \DataTables::eloquent($query)
->addColumn('id', function (ShoppingOrder $ShoppingOrder) {
return '';
})
->addColumn('created_at', function (ShoppingOrder $ShoppingOrder) {
return $ShoppingOrder->created_at->format("d.m.Y");
})
->addColumn('txaction', function (ShoppingOrder $ShoppingOrder) {
return Payment::getShoppingOrderBadge($ShoppingOrder);
})
->addColumn('total_shipping', function (ShoppingOrder $ShoppingOrder) {
return ''.$ShoppingOrder->getFormattedTotalShipping()." €";
})
->addColumn('payment', function (ShoppingOrder $ShoppingOrder) {
return $ShoppingOrder->getLastShoppingPayment('getPaymentType');
})
->addColumn('shipped', function (ShoppingOrder $ShoppingOrder) {
if($ShoppingOrder->payment_for === 8){
return '';
}
return ''.$ShoppingOrder->getShippedType().'';
})
->addColumn('payment_for', function (ShoppingOrder $ShoppingOrder) {
return ''.$ShoppingOrder->getPaymentForType().'';
})
->addColumn('invoice', function (ShoppingOrder $ShoppingOrder) {
return $ShoppingOrder->isInvoice() ? '
' : '-';
})
->addColumn('reference', function (ShoppingOrder $ShoppingOrder) {
return $ShoppingOrder->getLastShoppingPayment('reference');
})
->orderColumn('id', 'id $1')
->orderColumn('txaction', 'txaction $1')
->orderColumn('shipped', 'shipped $1')
->orderColumn('total_shipping', 'total_shipping $1')
->orderColumn('payment_for', 'payment_for $1')
->rawColumns(['id', 'txaction', 'payment_for', 'total_shipping', 'invoice', 'shipped'])
->make(true);
}
/*
$for = me, ot-member, ot-customer, abo-ot-member, abo-ot-customer, abo-me
*/
public function delivery($for, $id=null)
{
$user = User::find(\Auth::user()->id);
$shopping_user = null;
$delivery_id = null;
if(strpos($for, 'ot') !== false){ //ot-member, ot-customer abo-ot-member, abo-ot-customer,
$shopping_user = Shop::checkShoppingUser($id, $user);
$delivery_id = $shopping_user->id;
if(!Shop::checkShoppingCountry($for, $delivery_id) && !\Session()->has('custom-error')){
$country = Shop::getDeliveryCountry($for, $delivery_id);
\Session()->flash('custom-error', $country.": ".__('validation.custom.shipping_not_found'));
return redirect(route('user_order_my_delivery', [$for, $delivery_id]));
}
}
if(Request::get('action') === 'next'){
Yard::instance('shopping')->destroy();
if(strpos(Request::get('switchers-radio-is-for'), 'ot') !== false){
$delivery_id = $id;
}
return redirect(route('user_order_my_list', [Request::get('switchers-radio-is-for'), $delivery_id]));
}
$data = [
'shopping_user' => $shopping_user,
'isAdmin' => false,
'isView' => 'customer',
'for' => $for,
'delivery_id' => $delivery_id,
];
return view('user.order.delivery', $data);
}
public function list($for, $id=null)
{
$user = User::find(\Auth::user()->id);
$shopping_user = null;
$delivery_id = null;
if(strpos($for, 'ot') !== false){ //ot-member, ot-customer abo-ot-member, abo-ot-customer,
$shopping_user = Shop::checkShoppingUser($id, $user);
$delivery_id = $shopping_user->id;
}
if($for === 'ot-customer' || $for === 'abo-ot-customer'){
//Liederung an (abo-) ot-customer (Kunden) Zahlung und Rechnung geht an Kunden
UserService::initCustomerYard($shopping_user, $for);
}else{
//Lieferung an user oder (abo-) ot-member (Kunden) rechnung geht an User
//lieferland und rechnungsland prüfen
$shipping_country_id = Shop::checkShoppingCountry($for, $id);
if(!$shipping_country_id){
$country = Shop::getDeliveryCountry($for, $id);
\Session()->flash('custom-error', $country.": ".__('validation.custom.shipping_not_found'));
return redirect(route('user_order_my_delivery', [$for, $delivery_id]));
}
UserService::initUserYard($user, $shipping_country_id, $for);
}
$data = [
'shopping_user' => $shopping_user,
'user' => $user,
'isAdmin' => false,
'isView' => 'customer',
'for' => $for,
'template' => str_replace('abo-', '', $for),
'delivery_id' => $delivery_id,
'is_abo' => strpos($for, 'abo') !== false,
'comp_products' => $this->getCompProducts($for),
];
return view('user.order.list', $data);
}
public function payment($for, $id=null){
$data = Request::all();
$user = User::find(Auth::user()->id);
$rules = array(
'shipping_salutation' => 'required',
'shipping_firstname'=>'required',
'shipping_lastname'=>'required',
'shipping_address'=>'required',
'shipping_zipcode'=>'required',
'shipping_city' => 'required',
'shipping_state' => 'required',
);
$validator = Validator::make(Request::all(), $rules);
if ($validator->fails()) {
return back()->withErrors($validator)->withInput(Request::all());
}
//hier prüfen, ob versand etc richtig berechnet wurde
$this->checkSendYardForPayment($data, $id);
if(Yard::instance('shopping')->getNumComp() > 0){
if(!isset($data['switchers-comp-product'])){
$validator->errors()->add('switchers-comp-product', __('msg.please_select_compensation_product'));
}else{
if(!is_array($data['switchers-comp-product'])){
$validator->errors()->add('switchers-comp-product', __('msg.please_select_compensation_product'));
}else{
if(count($data['switchers-comp-product']) !== Yard::instance('shopping')->getNumComp()){
$validator->errors()->add('switchers-comp-product', __('mdg.please_select_count_compensation_products', ['count'=>Yard::instance('shopping')->getNumComp()]));
}
}
}
if ($validator->errors()->count()) {
return back()->withErrors($validator)->withInput(Request::all());
}
}
do {
$identifier = Util::getToken();
} while( ShoppingInstance::where('identifier', $identifier)->count() );
$data['is_from'] = 'user_order';
$data['is_for'] = $for;
$data['is_abo'] = $data['is_abo'] ?? 0;
$data['abo_interval'] = $data['abo_interval'] ?? 0;
$data['shopping_user_id'] = $id;
$data['user_price_infos'] = Yard::instance('shopping')->getUserPriceInfos();
unset($data['quantity']);
unset($data['_token']);
$data['mode'] = 'live';
if($for === 'ot-customer' || $for === 'abo-ot-customer'){
ShoppingInstance::create([
'identifier' => $identifier,
'user_shop_id' => $user->shop->id,
'payment' => 6, //Berater Shop to Customer Shop
'subdomain' => $user->shop->getSubdomain(),
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
'language' => \App::getLocale(),
'shopping_data' => $data,
'back' => url()->previous(),
]);
$yard_shopping_items = Shop::getYardShoppingItems();
Yard::instance('shopping')->store($identifier);
// send Mail to Customer
$this->customPaymentSendMail($user, $identifier, $yard_shopping_items, $data);
UserHistory::create(['user_id' => $user->id, 'action'=>'user_order_customer', 'status'=>1, 'product_id'=>null, 'identifier'=>$identifier, 'is_abo'=>$data['is_abo']]);
//eine Abschließen bestellseite für den User + Link zum Kunden Shop + Mail an den Kunden / Berater
return redirect(route('user_order_my_custom_payment', ['identifier'=>$identifier]));
}else{
ShoppingInstance::create([
'identifier' => $identifier,
'user_shop_id' => 1, //is first faker shop for buy intern
'auth_user_id' => Auth::user()->id,
'payment' => 2, //Berater Shop
'subdomain' => url('/'),
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
'language' => \App::getLocale(),
'shopping_data' => $data,
'back' => url()->previous(),
]);
Yard::instance('shopping')->store($identifier);
$path = route('checkout.checkout_card', ['identifier'=>$identifier]);
UserHistory::create(['user_id' => $user->id, 'action'=>'user_order_payment', 'status'=>1, 'product_id'=>null, 'identifier'=>$identifier, 'is_abo'=>$data['is_abo']]);
//$path = str_replace('http', 'https', $path);
return redirect()->secure($path);
}
}
private function checkSendYardForPayment($data, $id){
$user = User::find(\Auth::user()->id);
$shopping_user = null;
if(strpos($data['shipping_is_for'], 'ot') !== false){
$shopping_user = Shop::checkShoppingUser($id, $user);
}
$shipping_country_id = Shop::checkShoppingCountry($data['shipping_is_for'], $id);
if(!$shipping_country_id){
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
\App\Services\MyLog::writeLog('payment', 'error', 'no shipping_country_id found | Yard identifier: '.$identifier, $data);
abort(403, __('msg.shipping_country_was_not_found'));
}
//must be the same shipping country
if($shipping_country_id != Yard::instance('shopping')->getShippingCountryId()){
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
\App\Services\MyLog::writeLog('payment', 'error', 'shipping_country_id is not the same from Yard | Yard identifier: '.$identifier, $data);
abort(403, __('msg.shipping_country_was_not_correctly'));
}
if($data['shipping_is_for'] !== 'ot-customer'){
if(Yard::instance('shopping')->shipping_free){
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
\App\Services\MyLog::writeLog('payment', 'error', 'Yard can by not shipping_free | Yard identifier: '.$identifier, $data);
abort(403, __('msg.shopping_cart_was_shipping_free'));
}
}
if($data['shipping_is_for'] === 'ot-customer'){
if(!$user->shop){
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
\App\Services\MyLog::writeLog('payment', 'error', 'User has no Shop for an User to Customer order| Yard identifier: '.$identifier, $data);
abort(403, __('msg.shopping_cart_was_not_user_shop'));
}
}
$shipping_price = Shop::getShippingPriceByShippingCountryId($shipping_country_id, Yard::instance('shopping')->weight());
//for other and has weight - check
if(strpos($data['shipping_is_for'], 'ot') !== false && $data['shipping_is_for'] !== 'ot-customer' && Yard::instance('shopping')->weight() > 0){
if(!Yard::instance('shopping')->getShippingPrice() || Yard::instance('shopping')->getShippingPrice() == 0){
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
\App\Services\MyLog::writeLog('payment', 'error', 'Yard OT shipping_price is 0 or | Yard identifier: '.$identifier, $data);
abort(403, __('msg.shipping_cost_cannot_be_0'));
}
if(Yard::instance('shopping')->getShippingPrice() != $shipping_price->price){
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
\App\Services\MyLog::writeLog('payment', 'error', 'Yard OT shipping_price is not the same from shipping_price | Yard identifier: '.$identifier, $data);
abort(403, __('msg.shipping_costs_were_not_calculated_correctly'));
}
}
if(($data['shipping_is_for'] == 'me' || $data['shipping_is_for'] == 'abo-me') && Yard::instance('shopping')->weight() > 0){
if(!Yard::instance('shopping')->getShippingPrice() || Yard::instance('shopping')->getShippingPrice() == 0){
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
\App\Services\MyLog::writeLog('payment', 'error', 'Yard ME shipping_price is 0 or | Yard identifier: '.$identifier, $data);
abort(403, __('msg.shipping_cost_cannot_be_0'));
}
if(Yard::instance('shopping')->getShippingPrice() != $shipping_price->price_comp){
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
\App\Services\MyLog::writeLog('payment', 'error', 'Yard ME shipping_price is not the same from shipping_price | Yard identifier: '.$identifier, $data);
abort(403, __('msg.shipping_costs_were_not_calculated_correctly'));
}
if(Yard::instance('shopping')->getNumComp() != $shipping_price->num_comp){
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
\App\Services\MyLog::writeLog('payment', 'error', 'Yard num_comp is 0 | Yard identifier: '.$identifier, $data);
abort(403, __('msg.compensation_products_cannot_be_0'));
}
}
}
public function datatable(){
if(Request::get('shipping_is_for') === 'me' || Request::get('shipping_is_for') === 'abo-me'){
$show_on = Request::get('is_abo') ? '12' : '2';
$query = Product::with('product_buyings')
->select('products.*')->where('products.active', true)
->whereJsonContains('products.show_on', $show_on)
->whereDoesntHave('product_buyings', function ($q){
$q->where('product_buyings.user_id', '=', \Auth::user()->id);
});
}else{
$show_on = Request::get('is_abo') ? '13' : '3';
$query = Product::select('products.*')->where('active', true)->whereJsonContains('show_on', $show_on);
}
return \DataTables::eloquent($query)
->addColumn('product', function (Product $product) {
$cartItem = Yard::instance('shopping')->getCartItemByProduct($product->id);
$qty = isset($cartItem->qty) ? $cartItem->qty : 0;
$rowId = isset($cartItem->rowId) ? $cartItem->rowId : '';
return ''.$product->getLang('name').'