Esempio n. 1
0
 /**
  * Compare given campaigns.
  *
  * @param int $campaignNumber
  * @param int $campaignYear
  * @param int $otherCampaignNumber
  * @param int $otherCampaignYear
  * @return mixed
  */
 public function compareCampaigns($campaignNumber, $campaignYear, $otherCampaignNumber, $otherCampaignYear)
 {
     if (!Campaign::where('number', $campaignNumber)->where('year', $campaignYear)->count() || !Campaign::where('number', $otherCampaignNumber)->where('year', $otherCampaignYear)->count()) {
         return redirect('/bills');
     }
     return view('statistics.compare-campaigns')->with('campaignNumber', $campaignNumber)->with('campaignYear', $campaignYear)->with('otherCampaignNumber', $otherCampaignNumber)->with('otherCampaignYear', $otherCampaignYear);
 }
Esempio n. 2
0
 /**
  * Handle creation of new bill.
  *
  * @param CreateBillRequest $request
  * @return array
  */
 public function create(CreateBillRequest $request)
 {
     // Save request data
     $clientName = $request->get('client');
     $useCurrentCampaign = $request->get('use_current_campaign');
     $campaignYear = $request->get('campaign_year');
     $campaignNumber = $request->get('campaign_number');
     $client = DB::table('clients')->where('name', $clientName)->where('user_id', Auth::user()->id)->first();
     // Create new client if not exists
     if (!$client) {
         $client = new Client();
         $client->user_id = Auth::user()->id;
         $client->name = $clientName;
         $client->save();
     }
     // Create new bill
     $bill = new Bill();
     $bill->client_id = $client->id;
     $bill->user_id = Auth::user()->id;
     $campaign = Campaigns::current();
     // Check if current campaign should be used
     if (!$useCurrentCampaign) {
         $campaign = Campaign::where('year', $campaignYear)->where('number', $campaignNumber)->first();
     }
     $bill->campaign_id = $campaign->id;
     $bill->campaign_order = Campaigns::autoDetermineOrderNumber($campaign, $client->id);
     $bill->save();
     event(new UserCreatedNewBill(Auth::user()->id, $bill->id));
     // Return response
     $response = new AjaxResponse();
     $response->setSuccessMessage(trans('bills.bill_created'));
     return response($response->get());
 }
 public function run()
 {
     $contacts = Contact::all();
     $campaign = Campaign::where('name', '=', 'Halloween Video')->first();
     foreach ($contacts as $contact) {
         Email::create(['send_on' => Carbon::now()->addMinutes(5), 'template' => 'emails.halloween', 'subject' => 'Happy Halloween!', 'draft' => false, 'campaign_id' => $campaign->id, 'contact_id' => $contact->id]);
     }
 }
Esempio n. 4
0
 /**
  * Get current campaign
  *
  * @return bool|object
  */
 public static function current()
 {
     $date = date('Y-m-d');
     $currentCampaign = Campaign::where('start_date', '<=', $date)->where('end_date', '>=', $date)->first();
     if (!$currentCampaign) {
         return false;
     }
     return $currentCampaign;
 }
Esempio n. 5
0
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     // URL route is implicitly defined as the resource
     $landing_page_id = $this->route('landing_pages');
     $campaign_id = Landing_Page::findOrFail($landing_page_id)->first()->campaign->id;
     return Campaign::where('id', $campaign_id)->with('users')->whereHas('users', function ($q) {
         $q->where('user_id', Auth::id())->where('role_id', config('roles.admin'));
     })->exists();
 }
Esempio n. 6
0
 /**
  * Called before each test.
  */
 public function setUp()
 {
     parent::setUp();
     // Generate user and client
     $this->user = factory(App\User::class)->create();
     $this->client = factory(\App\Client::class)->create(['user_id' => $this->user->id]);
     // Generate the two bills
     $this->billInFirstCampaign = factory(\App\Bill::class)->create(['user_id' => $this->user->id, 'client_id' => $this->client->id, 'campaign_id' => \App\Campaign::where('year', $this->firstCampaign['year'])->where('number', $this->firstCampaign['number'])->first()->id]);
     $this->billInComparedCampaign = factory(\App\Bill::class)->create(['user_id' => $this->user->id, 'client_id' => $this->client->id, 'campaign_id' => \App\Campaign::where('year', $this->secondCampaign['year'])->where('number', $this->secondCampaign['number'])->first()->id]);
     $this->baseExpected = ['sold_products_label' => trans('statistics.sold_products_label', ['campaign_number' => $this->firstCampaign['number'], 'campaign_year' => $this->firstCampaign['year']]), 'sold_products_in_campaign_to_compare_label' => trans('statistics.sold_products_label', ['campaign_number' => $this->secondCampaign['number'], 'campaign_year' => $this->secondCampaign['year']])];
 }
 /**
  * Called before each test.
  */
 public function setUp()
 {
     parent::setUp();
     // Generate user and client
     $this->user = factory(\App\User::class)->create();
     $this->client = factory(\App\Client::class)->create(['user_id' => $this->user->id]);
     // Create bill in first campaign
     $this->billInFirstCampaign = factory(\App\Bill::class)->create(['user_id' => $this->user->id, 'client_id' => $this->client->id, 'campaign_id' => \App\Campaign::where('number', $this->firstCampaign['number'])->where('year', $this->firstCampaign['year'])->first()->id]);
     // Create bill in campaign to compare
     $this->billInCampaignToCompare = factory(\App\Bill::class)->create(['user_id' => $this->user->id, 'client_id' => $this->client->id, 'campaign_id' => \App\Campaign::where('number', $this->secondCampaign['number'])->where('year', $this->secondCampaign['year'])->first()->id]);
     $this->translationData = ['campaign_number' => $this->firstCampaign['number'], 'campaign_year' => $this->firstCampaign['year'], 'other_campaign_number' => $this->secondCampaign['number'], 'other_campaign_year' => $this->secondCampaign['year']];
     $this->baseExpected = ['discount_offered_label' => trans('statistics.offered_discount_label', ['campaign_number' => $this->firstCampaign['number'], 'campaign_year' => $this->firstCampaign['year']]), 'discount_offered_in_campaign_to_compare_label' => trans('statistics.offered_discount_label', ['campaign_number' => $this->secondCampaign['number'], 'campaign_year' => $this->secondCampaign['year']])];
 }
Esempio n. 8
0
 /**
  * Define the application's command schedule.
  *
  * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
  * @return void
  */
 protected function schedule(Schedule $schedule)
 {
     $schedule->call(function () {
         ShippingIntegrationController::checkTrackingNumbers();
     })->everyMinute();
     $schedule->call(function () {
         Log::info('In cron job');
         $now = Carbon::now();
         if (Campaign::where('status', 0)->where('scheduled_at', '<', $now)->count() > 0) {
             $campaigns = Campaign::where('status', 0)->where('scheduled_at', '<', $now)->get();
             foreach ($campaigns as $campaign) {
                 $campaign->doSendAll();
             }
         }
     })->everyMinute();
 }
Esempio n. 9
0
 public function postIndex(Request $request)
 {
     $validator = Validator::make($request->all(), ['pin' => 'required']);
     $pin = strtoupper($request->input('pin'));
     $validator->after(function ($validator) use($request, $pin) {
         $campaigns = Campaign::where('pin', $pin)->where('status', true)->count();
         if ($campaigns != 1) {
             $validator->errors()->add('pin', 'Invalid PIN');
         }
     });
     if ($validator->passes()) {
         $campaigns = Campaign::where('pin', $pin)->where('status', true)->get();
         session()->flash('campaign_id', $campaigns[0]->id);
         return redirect(route('lead'));
     }
     return redirect(route('pin'))->withErrors($validator);
 }
Esempio n. 10
0
 /**
  * User create new bill with client name used by another user and does not use current campaign.
  */
 public function test_create_bill_with_client_name_used_by_another_user_using_other_campaign()
 {
     $secondUser = factory(\App\User::class)->create();
     $clientOfSecondUser = factory(\App\Client::class)->create(['user_id' => $secondUser->id]);
     $this->postData['client'] = $clientOfSecondUser->name;
     unset($this->postData['use_current_campaign']);
     $this->postData['campaign_year'] = date('Y');
     $this->postData['campaign_number'] = rand(1, 17);
     $this->actingAs($this->user)->post('/bills/create', $this->postData)->seeJson(['success' => true, 'message' => trans('bills.bill_created')])->seeInDatabase('bills', ['user_id' => $this->user->id, 'client_id' => \App\Client::where('user_id', $this->user->id)->where('name', $this->postData['client'])->first()->id, 'campaign_id' => \App\Campaign::where('year', $this->postData['campaign_year'])->where('number', $this->postData['campaign_number'])->first()->id, 'campaign_order' => 1]);
 }
Esempio n. 11
0
 /**
  * Display the specified resource.
  *
  * @param  ShowRequest $request
  * @param  Integer  $id
  * @return Response
  */
 public function show(ShowRequest $request, ChartContract $chart, $id)
 {
     $campaign = Campaign::where('id', $id)->with(['landing_pages' => function ($q) {
         $q->orderBy('created_at', 'DESC');
     }])->with(['comments' => function ($q) {
         $q->orderBy('created_at', 'DESC');
     }])->first();
     // Instantiate campaign leads collection
     $campaign->leads_data = collect();
     // Set chart date
     $chart->init($this->start_date, $this->end_date);
     // Add an iterator loop for different chart colors
     foreach ($campaign->landing_pages as $i => $landing_page) {
         // Get total lead count for date range
         $landing_page->leads_sum = $landing_page->leads()->where('created_at', '>', $this->start_date)->count();
         // Get landing page leads, grouped by day
         $landing_page->leads_data = $landing_page->getLeads($this->length);
         // Set dataset
         $chart->setLineBarDataSet($landing_page->leads_data, $landing_page->title, $i);
         // Push landing page dataset into campaign dataset
         $campaign->leads_data->push($chart->getDataSet());
         $landing_page->leads_graph = $chart->getLineBarChart();
     }
     $campaign->leads_graph = $chart->getLineBarChart($campaign->leads_data);
     // Get attribution data
     $campaign->attribution_data = \App\Attribution::getLeadCountSplit($campaign->landing_pages->lists('id'));
     $campaign->attribution = $chart->getPieChart($campaign->attribution_data);
     return view('campaigns.single')->with('has_admin_access', $campaign->isAdmin())->with('user', $this->user)->with('campaign', $campaign);
 }
 /**
  * Make sure detailsAboutNumberOfClients works as expected when both campaigns have same number of clients.
  */
 public function test_details_about_number_of_clients_when_both_campaigns_have_same_number_of_clients()
 {
     $clients = factory(\App\Client::class, 4)->create(['user_id' => $this->user->id]);
     foreach ($clients as $client) {
         factory(\App\Bill::class)->create(['client_id' => $client->id, 'user_id' => $this->user->id, 'campaign_id' => \App\Campaign::where('number', $this->firstCampaign['number'])->where('year', $this->firstCampaign['year'])->first()->id]);
         factory(\App\Bill::class)->create(['client_id' => $client->id, 'user_id' => $this->user->id, 'campaign_id' => \App\Campaign::where('number', $this->secondCampaign['number'])->where('year', $this->secondCampaign['year'])->first()->id]);
     }
     $this->translationData['clients'] = 4;
     $expected = ['message' => trans('statistics.details_about_number_of_clients_equal_trend', $this->translationData), 'title' => trans('statistics.details_about_number_of_clients_equal_trend_title'), 'number_of_clients' => 4, 'number_of_clients_in_campaign_to_compare' => 4];
     $expected = array_merge($expected, $this->baseExpected);
     $this->actingAs($this->user)->assertEquals($expected, \App\Helpers\Statistics\CompareCampaignsStatistics::detailsAboutNumberOfClients($this->firstCampaign, $this->secondCampaign));
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     Schema::create('touches', function (Blueprint $table) {
         $table->increments('id');
         $table->string('title');
         $table->integer('campaign_id')->unsigned();
         $table->string('template');
         $table->string('title_slug');
         $table->string('subject');
         $table->dateTime('send_on');
         $table->timestamps();
     });
     $cwtBC = Campaign::where('title_slug', '=', 'engage_boston_c')->first();
     $cwtBP = Campaign::where('title_slug', '=', 'engage_boston_p')->first();
     $cwtNC = Campaign::where('title_slug', '=', 'engage_new_york_c')->first();
     $cwtNP = Campaign::where('title_slug', '=', 'engage_new_york_p')->first();
     $cwtBIC = Campaign::where('title_slug', '=', 'engage_boston_invite_c')->first();
     $cwtBIP = Campaign::where('title_slug', '=', 'engage_boston_invite_p')->first();
     $cwtNIC = Campaign::where('title_slug', '=', 'engage_new_york_invite_c')->first();
     $cwtNIP = Campaign::where('title_slug', '=', 'engage_new_york_invite_p')->first();
     $h = Campaign::where('title_slug', '=', 'halloween')->first();
     $vC = Campaign::where('title_slug', '=', 'vitality_holiday_client')->first();
     $vB = Campaign::where('title_slug', '=', 'vitality_holiday_broker')->first();
     if ($cwtBC) {
         $this->migrateTouches($cwtBC, $cwtBC);
     }
     if ($cwtBP) {
         $this->migrateTouches($cwtBP, $cwtBP);
     }
     if ($cwtNC) {
         $this->migrateTouches($cwtNC, $cwtNC);
     }
     if ($cwtNP) {
         $this->migrateTouches($cwtNP, $cwtNP);
     }
     if ($cwtBIC && $cwtBC) {
         $this->migrateTouches($cwtBIC, $cwtBC);
     }
     if ($cwtBIP && $cwtBP) {
         $this->migrateTouches($cwtBIP, $cwtBP);
     }
     if ($cwtNIC && $cwtNC) {
         $this->migrateTouches($cwtNIC, $cwtNC);
     }
     if ($cwtNIP && $cwtNP) {
         $this->migrateTouches($cwtNIP, $cwtNP);
     }
     if ($h) {
         $this->migrateTouches($h, $h);
     }
     if ($vC) {
         $this->migrateTouches($vC, $vC);
     }
     if ($vB) {
         $this->migrateTouches($vB, $vB);
     }
     $cwtBIC->delete();
     $cwtBIP->delete();
     $cwtNIC->delete();
     $cwtNIP->delete();
     $this->addContactsToCampaign($cwtBC);
     $this->addContactsToCampaign($cwtBP);
     $this->addContactsToCampaign($cwtNC);
     $this->addContactsToCampaign($cwtNP);
     $this->addContactsToCampaign($vC);
     $this->addContactsToCampaign($vB);
     $this->addContactsToCampaign($h);
 }
Esempio n. 14
0
 /**
  * Make sure detailsAboutSales works as expected when both campaigns have same sales.
  */
 public function test_details_about_sales_when_both_campaigns_have_the_same_sales()
 {
     $bill = factory(\App\Bill::class)->create(['user_id' => $this->user->id, 'client_id' => $this->client->id, 'campaign_id' => \App\Campaign::where('number', $this->firstCampaign['number'])->where('year', $this->firstCampaign['year'])->first()->id]);
     $secondBill = factory(\App\Bill::class)->create(['user_id' => $this->user->id, 'client_id' => $this->client->id, 'campaign_id' => \App\Campaign::where('number', $this->secondCampaign['number'])->where('year', $this->secondCampaign['year'])->first()->id]);
     $product = factory(\App\Product::class)->create(['user_id' => $this->user->id]);
     factory(\App\BillProduct::class)->create(['bill_id' => $bill->id, 'product_id' => $product->id, 'price' => 100, 'quantity' => 1, 'final_price' => 100, 'discount' => 0, 'calculated_discount' => 0]);
     factory(\App\BillProduct::class)->create(['bill_id' => $secondBill->id, 'product_id' => $product->id, 'price' => 100, 'quantity' => 1, 'final_price' => 100, 'discount' => 0, 'calculated_discount' => 0]);
     $this->translationData['sales'] = number_format(100, 2);
     $expected = ['message' => trans('statistics.details_about_sales_equal_trend', $this->translationData), 'title' => trans('statistics.details_about_sales_equal_trend_title'), 'sales' => $this->translationData['sales'], 'sales_in_campaign_to_compare' => number_format(100, 2)];
     $expected = array_merge($expected, $this->baseExpected);
     $this->actingAs($this->user)->assertEquals($expected, \App\Helpers\Statistics\CompareCampaignsStatistics::detailsAboutSales($this->firstCampaign, $this->secondCampaign));
 }
Esempio n. 15
0
 /**
  * Return number of cashed money in given campaign.
  *
  * @param int $campaignNumber
  * @param int $campaignYear
  * @return float
  */
 public static function cashedMoney($campaignNumber, $campaignYear)
 {
     $billIdsQuery = Bill::where('user_id', Auth::user()->id)->where('campaign_id', Campaign::where('number', $campaignNumber)->where('year', $campaignYear)->first()->id)->where('paid', 1)->get();
     // Build question marks string
     $questionMarks = '';
     foreach ($billIdsQuery as $result) {
         $questionMarks .= '?,';
     }
     // Remove last comma
     $questionMarks = substr($questionMarks, 0, -1);
     // Build bill ids array
     $billIds = [];
     $stop = 2;
     for ($i = 1; $i <= $stop; $i++) {
         foreach ($billIdsQuery as $result) {
             $billIds[] = $result->id;
         }
     }
     if (count($billIds) < 1) {
         return 0;
     }
     $query = "SELECT SUM(bills.cashed_money) as cashed_money FROM (SELECT bill_products.final_price as cashed_money FROM bill_products WHERE bill_products.bill_id IN ({$questionMarks}) ";
     $query .= "UNION ALL SELECT bill_application_products.final_price as cashed_money FROM bill_application_products WHERE bill_application_products.bill_id IN ({$questionMarks})) bills";
     $result = DB::select($query, $billIds);
     // Make sure result was returned
     if (isset($result[0]->cashed_money)) {
         return $result[0]->cashed_money;
     }
     return 0.0;
 }