Fix Stats
This commit is contained in:
parent
cd082bc0ef
commit
dec7bd1328
4 changed files with 16 additions and 26 deletions
|
|
@ -79,7 +79,7 @@ class StatistiqueController extends Controller
|
|||
$coupons = $campagne->coupons;
|
||||
foreach ($coupons as $coupon) {
|
||||
$coupon->quantity = $this->getFullQuantity($coupon);
|
||||
$coupon->remain = $this->getFullQuantity($coupon) - $this->getUsedQuantity($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);
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ class Panier extends Model
|
|||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
protected $with = ['panierContents'];
|
||||
//protected $with = ['panierContents'];
|
||||
/**
|
||||
* OneToMany
|
||||
* Panier -> PanierContent
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class PanierContent extends Model
|
|||
*/
|
||||
public function panier()
|
||||
{
|
||||
return $this->belongsTo('App\Panier', 'panier_content_panierId', 'panier_content_id');
|
||||
return $this->belongsTo('App\Panier', 'panier_content_panierId', 'panier_id');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -266,6 +266,7 @@ trait CouponTrait {
|
|||
|
||||
public function getUsedQuantity(Coupon $coupon) {
|
||||
$countPrinted = 0;
|
||||
$couponId = $coupon->coupon_id;
|
||||
$campagnes = $coupon->campagnes()->get();
|
||||
foreach ($campagnes as $campagne) {
|
||||
if($campagne->camp_type == 0 || $campagne->camp_type == 2) { // Murs
|
||||
|
|
@ -273,16 +274,10 @@ trait CouponTrait {
|
|||
$countPrinted = $countPrinted + count($murs);
|
||||
|
||||
} else { // Paniers
|
||||
$paniers = Panier::where(['panier_campId' => $campagne->camp_id])->get();
|
||||
foreach ($paniers as $key => $panier) {
|
||||
$panierContentCount = 0;
|
||||
foreach ($panier->panierContents as $panierContent) {
|
||||
if($panierContent->panier_content_couponId == $coupon->coupon_id){
|
||||
$panierContentCount += $panierContent->panier_content_printed;
|
||||
}
|
||||
}
|
||||
$countPrinted = $countPrinted + $panierContentCount;
|
||||
}
|
||||
$campagneId = $campagne->camp_id;
|
||||
$countPrinted = PanierContent::where('panier_content_couponId', $couponId)->whereHas('panier', function($query) use ($campagneId){
|
||||
$query->where('panier_campId', $campagneId);
|
||||
})->sum('panier_content_printed');
|
||||
}
|
||||
}
|
||||
return $countPrinted;
|
||||
|
|
@ -290,6 +285,7 @@ trait CouponTrait {
|
|||
|
||||
public function getDiffusedQuantity(Coupon $coupon) {
|
||||
$countPrinted = 0;
|
||||
$couponId = $coupon->coupon_id;
|
||||
$campagnes = $coupon->campagnes()->get();
|
||||
foreach ($campagnes as $campagne) {
|
||||
if($campagne->camp_type == 0 || $campagne->camp_type == 2) { // Murs
|
||||
|
|
@ -297,19 +293,13 @@ trait CouponTrait {
|
|||
$countPrinted = $countPrinted + count($murs);
|
||||
|
||||
} else { // Paniers
|
||||
$paniers = Panier::where(['panier_campId' => $campagne->camp_id])->get();
|
||||
foreach ($paniers as $key => $panier) {
|
||||
$panierContentCountPrinted = 0;
|
||||
$panierContentCountDiffused = 0;
|
||||
foreach ($panier->panierContents as $panierContent) {
|
||||
if($panierContent->panier_content_couponId == $coupon->coupon_id){
|
||||
$panierContentCountPrinted += $panierContent->panier_content_printed;
|
||||
$panierContentCountDiffused += $panierContent->panier_content_quantity;
|
||||
}
|
||||
}
|
||||
|
||||
$countPrinted = $countPrinted + $panierContentCountPrinted + $panierContentCountDiffused;
|
||||
}
|
||||
$campagneId = $campagne->camp_id;
|
||||
$panierContents = PanierContent::where('panier_content_couponId', $couponId)->whereHas('panier', function($query) use ($campagneId){
|
||||
$query->where('panier_campId', $campagneId);
|
||||
})->get();
|
||||
$panierContentCountPrinted = $panierContents->sum('panier_content_printed');
|
||||
$panierContentCountDiffused = $panierContents->sum('panier_content_quantity');
|
||||
$countPrinted = $countPrinted + $panierContentCountPrinted + $panierContentCountDiffused;
|
||||
}
|
||||
}
|
||||
return $countPrinted;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue