public function update(Request $request, $id) { $obj = new helpers(); $subUpdate = Request::all(); //print_r($subUpdate);exit; unset($subUpdate['_method']); unset($subUpdate['_token']); Subscription::where('subscription_id', '=', $id)->update($subUpdate); Session::flash('success', 'Subscription updated successfully'); return redirect('admin/subscription'); }
public function index() { $all_brand_member = DB::table('brandmembers')->where('role', 1)->where('status', 1)->where('admin_status', 1)->get(); foreach ($all_brand_member as $brand) { //echo $brand->fname; $subscription = DB::table('subscription_history')->where('payment_status', 'pending')->where('member_id', $brand->id)->first(); if (count($subscription) <= 0) { $end_date = date("Y-m-d", strtotime($brand->created_at . ' + 30 days')); $setting = DB::table('sitesettings')->where('name', 'brand_fee')->first(); $subdata = array("member_id" => $brand->id, "start_date" => $brand->created_at, "end_date" => $end_date, "subscription_fee" => $setting->value); Subscription::create($subdata); } else { $paidsubscription = DB::table('subscription_history')->where('payment_status', 'paid')->where('member_id', $brand->id)->orderBy('end_date', 'DESC')->first(); if (is_object($paidsubscription) && $paidsubscription->end_date <= date("Y-m-d")) { echo 'subid-' . $paidsubscription->subscription_id . '- paid in prev month <br />'; } else { $today = Date('Y-m-d'); $enddate = date("Y-m-d", strtotime($subscription->end_date . " + 1 day")); if ($enddate == $today) { //charge here if (empty($brand->auth_profile_id)) { continue; } echo "will be charged " . $subscription->subscription_id . '<br />'; // Create Auth & Capture Transaction $request = new AuthorizeNetCIM(); $transaction = new AuthorizeNetTransaction(); $transaction->amount = $subscription->subscription_fee; $transaction->customerProfileId = $brand->auth_profile_id; $transaction->customerPaymentProfileId = $brand->auth_payment_profile_id; $transaction->customerShippingAddressId = $brand->auth_address_id; $lineItem = new AuthorizeNetLineItem(); $lineItem->itemId = $subscription->subscription_id; $lineItem->name = $brand->fname; $lineItem->description = $brand->fname . " charged for subscription of " . $subscription->start_date; $lineItem->quantity = "1"; $lineItem->unitPrice = $subscription->subscription_fee; $lineItem->taxable = "false"; $transaction->lineItems[] = $lineItem; $response = $request->createCustomerProfileTransaction("AuthCapture", $transaction); if ($response->isOk()) { $transactionResponse = $response->getTransactionResponse(); $transactionId = $transactionResponse->transaction_id; $subdata = array("transaction_id" => $transactionResponse->transaction_id, "payment_status" => 'paid'); $sub = DB::table('subscription_history')->where('subscription_id', $subscription->subscription_id)->update($subdata); } } } } } }
public function index() { $all_brand_member = DB::table('brandmembers')->where('role', 1)->where('status', 1)->where('admin_status', 1)->get(); DB::connection()->enableQueryLog(); foreach ($all_brand_member as $brand) { $product = DB::table('products')->select(DB::raw('products.id,products.brandmember_id,products.product_name,products.product_slug,products.image1, MIN(`actual_price`) as `min_price`,MAX(`actual_price`) as `max_price`'))->leftJoin('product_formfactors', 'products.id', '=', 'product_formfactors.product_id')->where('products.brandmember_id', '=', $brand->id)->where('products.active', 1)->where('products.is_deleted', 0)->where('product_formfactors.servings', '!=', 0)->where('products.discountinue', 0)->groupBy('product_formfactors.product_id'); $profile = MemberProfile::find($brand->id); if (isset($profile) && $profile->count) { $count = (int) $profile->count; } else { $count = 0; } $setting = DB::table('sitesettings')->where('name', 'brand_fee')->first(); $setting2 = DB::table('sitesettings')->where('name', 'brand_perproduct_fee')->first(); if ($count == 1) { $fee = $setting->value; } elseif ($count > 1) { $fee = $setting->value; $perproduct_fee = $setting2->value; $fee = $fee + $perproduct_fee * $count; } else { $fee = 0; } //echo $brand->id; //echo '<br />'; $br = array('member_fee' => $fee); //print_r($br); DB::table('brandmembers')->where('id', $brand->id)->update(array('member_fee' => $fee)); } foreach ($all_brand_member as $brand) { //echo $brand->fname; $subscription = DB::table('subscription_history')->where('payment_status', 'pending')->where('member_id', $brand->id)->first(); if (count($subscription) <= 0) { $paidsub = DB::table('subscription_history')->where('payment_status', 'paid')->where('member_id', $brand->id)->orderBy('end_date', 'DESC')->first(); if (count($paidsub) > 0) { $start_date = $paidsub->end_date; $end_date = date("Y-m-d", strtotime($start_date . ' + 30 days')); } else { $start_date = $brand->created_at; $end_date = date("Y-m-d", strtotime($start_date . ' + 30 days')); } $setting = DB::table('sitesettings')->where('name', 'brand_fee')->first(); $subdata = array("member_id" => $brand->id, "start_date" => $start_date, "end_date" => $end_date, "subscription_fee" => $brand->member_fee); Subscription::create($subdata); } else { $paidsubscription = DB::table('subscription_history')->where('member_id', $brand->id)->orderBy('end_date', 'DESC')->first(); if (is_object($paidsubscription) && $paidsubscription->end_date <= date("Y-m-d") && $paidsubscription->payment_status == 'paid') { echo 'subid-' . $paidsubscription->subscription_id . '- paid in prev month <br />'; } else { $today = Date('Y-m-d'); $enddate = date("Y-m-d", strtotime($subscription->end_date . " + 1 day")); if ($enddate <= $today) { //charge here if (empty($brand->auth_profile_id)) { continue; } echo "will be charged " . $subscription->member_id . '<br />'; // Create Auth & Capture Transaction $request = new AuthorizeNetCIM(); $transaction = new AuthorizeNetTransaction(); $transaction->amount = $brand->member_fee; $transaction->customerProfileId = $brand->auth_profile_id; $transaction->customerPaymentProfileId = $brand->auth_payment_profile_id; $transaction->customerShippingAddressId = $brand->auth_address_id; $lineItem = new AuthorizeNetLineItem(); $lineItem->itemId = $subscription->subscription_id; $lineItem->name = $brand->fname; $lineItem->description = $brand->fname . " charged for subscription of " . $subscription->start_date; $lineItem->quantity = "1"; $lineItem->unitPrice = $brand->member_fee; $lineItem->taxable = "false"; $transaction->lineItems[] = $lineItem; $response = $request->createCustomerProfileTransaction("AuthCapture", $transaction); $updateWithCode = DB::table('brandmembers')->where('id', '=', $subscription->member_id)->update(array('subscription_status' => 'expired')); if ($response->isOk()) { $transactionResponse = $response->getTransactionResponse(); $transactionId = $transactionResponse->transaction_id; $subdata = array("transaction_id" => $transactionResponse->transaction_id, "payment_status" => 'paid'); $sub = DB::table('subscription_history')->where('subscription_id', $subscription->subscription_id)->update($subdata); $updateWithCode = DB::table('brandmembers')->where('id', '=', $subscription->member_id)->update(array('subscription_status' => 'active')); } else { print_r($response); } } } } } $this->onlineusers(); }
public function subscriptionHistory() { $obj = new helpers(); if (!$obj->checkBrandLogin()) { return redirect('brandLogin'); } $limit = 5; // $subscription = DB::table('subscription_history')->where('member_id', Session::get('brand_userid'))->orderBy('end_date','DESC')->get(); $subscription = Subscription::with('getSubMembers')->where("member_id", Session::get('brand_userid'))->orderBy('end_date', 'DESC')->paginate($limit); $brand = Brandmember::find(Session::get('brand_userid')); return view('frontend.brand.subscription_history', compact('brand', 'subscription'), array('title' => 'Subscription History')); }
private function check_subscription($users) { /****************** check subscription **************************/ $subscription = DB::table('subscription_history')->where('member_id', $users->id)->orderBy('subscription_id', 'DESC')->first(); if (count($subscription) <= 0) { $end_date = date("Y-m-d", strtotime($users->created_at . ' + 30 days')); $setting = DB::table('sitesettings')->where('name', 'brand_fee')->first(); $subdata = array("member_id" => $users->id, "start_date" => $users->created_at, "end_date" => $end_date, "subscription_fee" => $setting->value); Subscription::create($subdata); } else { $today = Date('Y-m-d'); $enddate = date("Y-m-d", strtotime($subscription->end_date . " + 1 day")); if ($today > $enddate && $subscription->payment_status == 'pending') { Session::put('error', 'Your subscription has expired. Contact Admin to activated your account'); // return redirect('brandLogin'); $updateWithCode = DB::table('brandmembers')->where('id', '=', $users->id)->update(array('subscription_status' => 'expired')); echo url() . '/brandLogin'; exit; } elseif ($users->subscription_status != 'active') { Session::put('error', 'Your subscription has expired. Contact Admin to activated your account'); echo url() . '/brandLogin'; exit; } else { $updateWithCode = DB::table('brandmembers')->where('id', '=', $users->id)->update(array('subscription_status' => 'active')); } } /****************** check subscription **************************/ }
public function brandRegister() { $obj = new helpers(); if ($obj->checkUserLogin()) { return redirect('home'); } $country = DB::table('countries')->orderBy('name', 'ASC')->get(); $alldata = array(); foreach ($country as $key => $value) { $alldata[$value->country_id] = $value->name; } //echo "<pre>";print_r($alldata); exit; $reg_brand_id = ''; // No register brand id for first time. $states = DB::table('zones')->where('country_id', 223)->orderBy('name', 'ASC')->get(); $allstates = array(); foreach ($states as $key => $value) { $allstates[$value->zone_id] = $value->name; } if (Request::isMethod('post')) { $email_count = DB::table('brandmembers')->where('email', '=', Request::input('email'))->count(); if ($email_count > 0) { Session::flash('error', 'Email already exists.'); return redirect('brandregister'); } /*if(Request::input('email')=='' || Request::input('fname')=='' || Request::input('lname') || Request::input('password')==''){ Session::flash('error', 'Please fill form again.'); return redirect('brandregister'); }*/ if (Request::input('expiry_month') != '' && Request::input('expiry_year') != '' && Request::input('card_number') != '') { $country = DB::table('countries')->where('country_id', '=', Request::input('card_country_id'))->first(); $shipping_card_addr = array('card_holder_fname' => Request::input('card_holder_fname'), 'card_holder_lname' => Request::input('card_holder_lname'), 'company_name' => Request::input('company_name'), 'expiry_month' => Request::input('expiry_month'), 'expiry_year' => Request::input('expiry_year'), 'cvv' => Request::input('cvv'), 'card_shiping_name' => Request::input('card_shiping_name'), 'card_shiping_address' => Request::input('card_shiping_address'), 'card_country_id' => Request::input('card_country_id'), 'card_shiping_city' => Request::input('card_shiping_city'), 'card_shipping_phone_no' => Request::input('card_shipping_phone_no'), 'card_shipping_fax' => Request::input('card_shipping_fax'), 'card_state' => Request::input('card_state'), 'card_shipping_postcode' => Request::input('card_shipping_postcode'), 'email' => Request::input('email'), 'card_number' => Request::input('card_number'), 'country' => $country->name); $res = Authorizenet::createprofile($shipping_card_addr); if ($res['status'] == 'fail') { Session::flash('error', 'something went wrong with creditcard details!!' . $res[message] . ' Please try again.'); return redirect('brandregister'); } } if (isset($_FILES['government_issue']['name']) && $_FILES['government_issue']['name'] != "") { $destinationPath = 'uploads/brand_government_issue_id/'; // upload path $extension = Input::file('government_issue')->getClientOriginalExtension(); $government_issue = rand(111111111, 999999999) . '.' . $extension; Input::file('government_issue')->move($destinationPath, $government_issue); // uploading file to given path } else { $government_issue = ''; } if (isset($_FILES['business_doc']['name']) && $_FILES['business_doc']['name'] != "") { $destinationPath = 'uploads/brandmember/business_doc/'; // upload path $extension = Input::file('business_doc')->getClientOriginalExtension(); $business_doc = rand(111111111, 999999999) . '.' . $extension; Input::file('business_doc')->move($destinationPath, $business_doc); } else { $business_doc = ''; } //if(Input::hasFile('image')) if (isset($_FILES['image']['name']) && $_FILES['image']['name'] != "") { $destinationPath = 'uploads/brandmember/'; // upload path $thumb_path = 'uploads/brandmember/thumb/'; $medium = 'uploads/brandmember/thumb/'; $extension = Input::file('image')->getClientOriginalExtension(); // getting image extension $fileName = rand(111111111, 999999999) . '.' . $extension; // renameing image Input::file('image')->move($destinationPath, $fileName); // uploading file to given path $obj->createThumbnail($fileName, 661, 440, $destinationPath, $thumb_path); $obj->createThumbnail($fileName, 116, 116, $destinationPath, $medium); } else { $fileName = ''; } $slug = $obj->create_slug(Request::input('business_name'), 'brandmembers', 'slug'); $hashpassword = Hash::make(Request::input('password')); $time = Request::input('calltime'); $date = Request::input('calldate'); $given_date = strtotime($date . " " . $time); $given_date = date("Y-m-d H:s:i", $given_date); $setting = DB::table('sitesettings')->where('name', 'brand_fee')->first(); $fee = $setting->value; $brandmember = Brandmember::create(['business_name' => Request::input('business_name'), 'brand_type' => Request::input('brand_type'), 'fname' => Request::input('fname'), 'lname' => Request::input('lname'), 'email' => Request::input('email'), 'username' => strtolower(Request::input('fname')), 'password' => $hashpassword, 'status' => 1, 'government_issue' => $government_issue, 'business_doc' => $business_doc, 'phone_no' => Request::input('phone_no'), 'routing_number' => Request::input('routing_number'), 'account_number' => Request::input('account_number'), 'mailing_name' => Request::input('mailing_name'), 'mailing_address' => Request::input('mailing_address'), 'mailing_country_id' => Request::input('mailing_country_id'), 'mailing_city' => Request::input('mailing_city'), 'mailing_lastname' => Request::input('mailing_lastname'), 'mailing_address2' => Request::input('mailing_address2'), 'mailing_state' => Request::input('mailing_state'), 'mailing_postcode' => Request::input('mailing_postcode'), 'call_datetime' => $given_date, 'paypal_email' => Request::input('paypal_email'), 'mailing_address' => Request::input('mailing_address'), 'default_band_preference' => Request::input('default_band_preference'), 'pro_image' => $fileName, 'role' => 1, 'admin_status' => 0, 'auth_profile_id' => isset($res['customer']['profile_id']) ? $res['customer']['profile_id'] : '', 'auth_payment_profile_id' => isset($res['customer']['payment_profile_id']) ? $res['customer']['payment_profile_id'] : '', 'auth_address_id' => isset($res['customer']['address_id']) ? $res['customer']['address_id'] : '', 'slug' => strtolower($slug), 'member_fee' => $fee, 'subscription_status' => 'active']); $shipping_card_addr = array('card_holder_name' => Request::input('card_holder_name'), 'card_number' => Request::input('card_number'), 'card_name' => Request::input('card_name'), 'expiry_month' => Request::input('expiry_month'), 'expiry_year' => Request::input('expiry_year'), 'card_shiping_name' => Request::input('card_shiping_name'), 'card_shiping_address' => Request::input('card_shiping_address'), 'card_country_id' => Request::input('card_country_id'), 'card_shiping_city' => Request::input('card_shiping_city'), 'card_shipping_phone_no' => Request::input('card_shipping_phone_no'), 'card_shipping_address2' => Request::input('card_shipping_address2'), 'card_state' => Request::input('card_state'), 'card_shipping_postcode' => Request::input('card_shipping_postcode')); $shipping_card_addr_serial = serialize($shipping_card_addr); $lastInsertedId = $brandmember->id; $start_date = date("Y-m-d"); $end_date = date("Y-m-d", strtotime($start_date . ' + 30 days')); $subdata = array("member_id" => $lastInsertedId, "start_date" => $start_date, "end_date" => $end_date, "subscription_fee" => $fee, "payment_status" => 'paid', "transaction_id" => 'free'); Subscription::create($subdata); $reg_brand_id = $lastInsertedId; //base64_encode ($lastInsertedId); // encrypted last register brand member id $address = new Address(); $address->mem_brand_id = $lastInsertedId; $address->first_name = Request::input('shiping_fname'); $address->last_name = Request::input('shiping_lname'); $address->address = Request::input('shiping_address'); $address->address2 = Request::input('shipping_address2'); $address->country_id = Request::input('country'); $address->zone_id = Request::input('state'); // State id $address->city = Request::input('city'); $address->postcode = Request::input('shipping_postcode'); $address->serialize_val = ''; if ($address->save()) { $addressId = $address->id; $dataUpdateAddress = DB::table('brandmembers')->where('id', $lastInsertedId)->update(['address' => $addressId]); $sitesettings = DB::table('sitesettings')->get(); //exit; if (!empty($sitesettings)) { foreach ($sitesettings as $each_sitesetting) { if ($each_sitesetting->name == 'email') { $admin_users_email = $each_sitesetting->value; } } } //Session::flash('success', 'Registration completed successfully.Please check your email to activate your account.'); //return redirect('brandregister'); $user_name = Request::input('fname') . ' ' . Request::input('lname'); $user_email = Request::input('email'); //$activateLink = url().'/activateLink/'.base64_encode(Request::input('email')).'/brand'; $activateLink = url() . '/brandLogin'; $sent = Mail::send('frontend.register.activateLink', array('name' => $user_name, 'email' => $user_email, 'activate_link' => $activateLink, 'admin_users_email' => $admin_users_email), function ($message) use($admin_users_email, $user_email, $user_name) { $message->from($admin_users_email); $message->to($user_email, $user_name)->subject('Welcome to Miramix'); }); if (!$sent) { Session::flash('error', 'something went wrong!! Mail not sent.'); return redirect('brandregister'); } else { Session::flash('success', 'Registration completed successfully.Please wait for admin approval.'); Session::flash('flush_reg_brand_id', 'open_modal'); Session::put('reg_brand_id', $reg_brand_id); return redirect('brandLogin'); } } } return view('frontend.register.registerbrand', compact('alldata', 'allstates'), array('reg_brand_id' => $reg_brand_id)); }