/** * check over inventory limit of requested flight */ public function checkOverInventory($flight, $flightWebsite, $event) { $RawTrackingSummarry = new RawTrackingSummary(); $rate = $flight->cost_type == 'cpm' ? 1000 : 1; $flightWebsiteInventoryOvr = $flightWebsite->value_added * $rate; $flightInventoryOvr = $flight->value_added * $rate; $flightRateOvr = 0; //Check flight co setup over report if ($flightInventoryOvr <= 0) { return self::RESPONSE_TYPE_FLIGHT_VALUE_ADDED; } //Check flight webiste co setup over report if ($flightWebsiteInventoryOvr < 0) { return self::RESPONSE_TYPE_FLIGHT_WEBSITE_VALUE_ADDED; } $flightRateOvr = $this->changePercentage($flight->value_added, $flight->total_inventory); // tổng số over inventory của flight (all time) $flightInventoryAllTimeOvr = $RawTrackingSummarry->getTotalInventory($flight->id, $event, true); $flightInventoryInDayOvr = $RawTrackingSummarry->getTotalInventoryInDay($flight->id, $event, true); $flightInventoryInDay = $RawTrackingSummarry->getTotalInventoryInDay($flight->id, $event); $flightRateInDayOvr = $this->changePercentage($flightInventoryInDayOvr, $flightInventoryInDay); if ($flightInventoryInDay <= 0 && $flightRateInDayOvr >= $flightRateOvr || $flightInventoryAllTimeOvr >= $flightInventoryOvr) { return self::RESPONSE_TYPE_INVENTORY_LIMIT; } if ($flightWebsiteInventoryOvr == 0) { $fwRateOvr = $flightRateOvr; } else { $fwRateOvr = $this->changePercentage($flightWebsite->value_added, $flightWebsite->total_inventory); } if ($flightWebsiteInventoryOvr > $flightInventoryOvr || $flightWebsiteInventoryOvr == 0) { $flightWebsiteInventoryOvr = $flightInventoryOvr; } $totalAdZoneInventoryAllTimeOvr = $RawTrackingSummarry->getTotalAdZoneInventory($flight->id, $flightWebsite->id, $event, true); $totalAdZoneInventoryInDayOvr = $RawTrackingSummarry->getTotalAdZoneInventoryInDay($flight->id, $flightWebsite->id, $event, true); $totalAdZoneInventoryInDay = $RawTrackingSummarry->getTotalAdZoneInventoryInDay($flight->id, $flightWebsite->id, $event); $fwRateInDayOvr = $this->changePercentage($totalAdZoneInventoryInDayOvr, $totalAdZoneInventoryInDay); if ($totalAdZoneInventoryInDay <= 0 || $fwRateInDayOvr >= $fwRateOvr || $totalAdZoneInventoryAllTimeOvr >= $flightWebsiteInventoryOvr) { return self::RESPONSE_TYPE_AD_ZONE_INVENTORY_LIMIT; } return TRUE; }