/** * Calculate the current months Expected GP * * @return string */ public function monthExpectedGp() { return Cache::store('database')->remember(__CLASS__ . "::" . __FUNCTION__ . $this->date->month . $this->date->year, 60, function () { $monthJobs = JobCard::dueThisMonth($this->date)->get(); return round($monthJobs->sum('expected_gp_contribution')); }); }
/** * @test */ public function expected_gp() { $gpTarget = GlobalVariable::first()->monthly_gp_target; $currentMonthJobs = JobCard::dueThisMonth()->get(); $gpCalculator = new GpIndicatorsCalculator(); $this->assertInstanceOf(GpIndicatorsCalculator::class, $gpCalculator, "GP Calculator Object"); $globalTarget = GlobalVariable::first()->monthly_gp_target; $expectedGpCalc = 0; $sellingPriceCalc = 0; foreach ($currentMonthJobs as $job) { $this->assertInstanceOf(JobCard::class, $job); $expectedGpCalc += $job->expected_gp_contribution; $sellingPriceCalc += $job->selling_price * $job->production_quantity; } $target = $gpTarget >= $expectedGpCalc ? $gpTarget : $expectedGpCalc; $this->assertEquals(round($expectedGpCalc), $gpCalculator->monthExpectedGp(), "Current Month Expected"); $this->assertEquals(round($sellingPriceCalc), $gpCalculator->monthExpectedTurnOver(), "Current Month Expected Turn Over"); // $this->assertEquals($expectedGpCalc / $target * 100, $gpCalculator->monthExpectedPercentage(), // "Current Month Expected Percentage"); $this->assertInternalType('float', $gpCalculator->monthExpectedPercentage(), "Current Month Expected Percentage"); $this->assertEquals(round($expectedGpCalc / $globalTarget * 100), round($gpCalculator->monthProductionExpectedPercentage()), "Current Month Production Expected Percentage"); }
/** * Simple view of top 10 jobs to be printed next * * @return $this */ public function adhoc() { $this->authorize('view_gp_report'); return view('reports.index')->with(['jobs' => JobCard::dueThisMonth(Carbon::now()->subDays(14), Carbon::now())->get(), 'date' => Carbon::now()]); }