120 lines
4.4 KiB
PHP
120 lines
4.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Campagne;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use App\Traits\CouponTrait;
|
|
use App\Traits\GraphTrait;
|
|
|
|
class StatistiqueController extends Controller
|
|
{
|
|
use CouponTrait;
|
|
use GraphTrait;
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index()
|
|
{
|
|
$sites = Auth::user()->sites()->get();
|
|
foreach ($sites as $site) {
|
|
if (isset($site->campagnes)) {
|
|
$campagnes = $site->campagnes;
|
|
foreach ($campagnes as $campagne) {
|
|
switch ($campagne->camp_type) {
|
|
case 0:
|
|
$campagne->camp_type = "Mur";
|
|
break;
|
|
case 1:
|
|
$campagne->camp_type = "Panier";
|
|
break;
|
|
case 2:
|
|
$campagne->camp_type = "Mur sans sélection";
|
|
break;
|
|
case 3:
|
|
$campagne->camp_type = "Panier Sélectionnable";
|
|
break;
|
|
}
|
|
$coupons = $campagne->coupons;
|
|
foreach ($coupons as $coupon) {
|
|
$coupon->quantity = $this->getFullQuantity($coupon);
|
|
$coupon->remain = $this->getFullQuantity($coupon) - $this->getUsedQuantity($coupon);
|
|
$coupon->diffused = $this->getDiffusedQuantity($coupon);
|
|
$coupon->isPrintable = $this->isAvailableToPrint($coupon, $campagne);
|
|
$coupon->isPaused = $this->isPausedToPrint($coupon, $campagne);
|
|
}
|
|
}//end foreach
|
|
}//end if
|
|
}//end foreach
|
|
return view('stats.index')->with(['sites' => $sites]);
|
|
}
|
|
|
|
/**
|
|
* Show the stat detail of a campaign.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function statdetail(Campagne $campagne)
|
|
{
|
|
$count = 0;
|
|
$colors = config('constants.colors');
|
|
switch ($campagne->camp_type) {
|
|
case 0:
|
|
$campagne->camp_type = "Mur";
|
|
break;
|
|
case 1:
|
|
$campagne->camp_type = "Panier";
|
|
break;
|
|
case 2:
|
|
$campagne->camp_type = "Mur sans sélection";
|
|
break;
|
|
case 3:
|
|
$campagne->camp_type = "Panier Sélectionnable";
|
|
break;
|
|
}
|
|
|
|
$coupons = $campagne->coupons;
|
|
foreach ($coupons as $coupon) {
|
|
$coupon->quantity = $this->getFullQuantity($coupon);
|
|
$coupon->remain = $coupon->quantity - $this->getUsedQuantity($coupon);
|
|
$coupon->diffused = $this->getDiffusedQuantity($coupon);
|
|
$coupon->isPrintable = $this->isAvailableToPrint($coupon, $campagne);
|
|
$coupon->isPaused = $this->isPausedToPrint($coupon, $campagne);
|
|
$coupon->color = $coupon->color = "#" . str_pad(dechex(mt_rand(0, 255)), 2, '0', STR_PAD_LEFT) . str_pad(dechex(mt_rand(0, 255)), 2, '0', STR_PAD_LEFT) . str_pad(dechex(mt_rand(0, 255)), 2, '0', STR_PAD_LEFT);
|
|
$count++;
|
|
}
|
|
$enddate = date('Y-m-d');
|
|
$startdate = date('Y-m-d', strtotime("-30 days"));
|
|
return view('stats.detail')->with(['campagne' => $campagne, 'startdate' => $startdate, 'enddate' => $enddate]);
|
|
}
|
|
|
|
public function load_stats(Request $request)
|
|
{
|
|
$campid = $request->campid;
|
|
$startdate = $request->startdate;
|
|
$enddate = $request->enddate;
|
|
|
|
// ---- Labels pour la période
|
|
$labels = $this->getLabelsForStats($startdate, $enddate);
|
|
|
|
// ---- Data pour le graphique global
|
|
$dataGlobal = $this->getDataForCamp($labels, $campid);
|
|
|
|
// ---- Data pour le graphique par coupons
|
|
$campagne = Campagne::where(['camp_id' => $campid])->first();
|
|
$coupons = $campagne->coupons;
|
|
$dataSpec = [];
|
|
foreach ($coupons as $coupon) {
|
|
$dataCoupon = $this->getDataForCoupon($labels, $campid, $coupon);
|
|
$dataSpec[$coupon->coupon_code] = $dataCoupon;
|
|
}
|
|
|
|
$data = array('labels' => $labels, 'dataGlobal' => $dataGlobal, 'dataSpec' => $dataSpec);
|
|
|
|
return json_encode($data);
|
|
}
|
|
}
|