/** * Cost Vs Selling Price Report * * @return $this */ public function costVsSelling($month, $year) { $this->authorize('view_gp_report'); $date = Carbon::create($year, $month); $jobIds = DespatchLogEntry::thisMonth($date)->get()->pluck('despatch_log_book_job_cards_id_fk')->toArray(); return view('reports.costVsSelling')->with(['jobs' => JobCard::find($jobIds)]); }
/** * @test */ public function net_weight() { $log = DespatchLogEntry::first(); $this->assertInstanceOf(DespatchLogEntry::class, $log, "Despatch Log Entry Instance"); $removeCores = $log->jobCard->jobCosting->jc_remove_cores; $this->assertInternalType('bool', (bool) $removeCores, "Remove Core Bool"); $netWeigth = $log->net_weight; $this->assertInternalType('float', $netWeigth, "Net Weight Float"); $calcNetWeight = $removeCores == 1 ? $log->despatch_log_book_total - $log->despatch_log_book_pallet_kg - $log->jobCard->jobCosting->core_weight : $log->despatch_log_book_total - $log->despatch_log_book_pallet_kg; $this->assertEquals($calcNetWeight, $netWeigth, "Net Weight"); }
/** * Overwrite the parent boot method * * @return void */ public static function boot() { parent::boot(); DespatchLogEntry::creating(function ($despatchLogEntry) { $despatchLogEntry->created_by = \Auth::user()->id; $despatchLogEntry->updated_by = \Auth::user()->id; }); DespatchLogEntry::updating(function ($despatchLogEntry) { $despatchLogEntry->updated_by = \Auth::user()->id; }); }
/** * @test */ public function actual_gp() { $currentMonthDespatch = DespatchLogEntry::currentMonth()->get(); $gpCalculator = new GpIndicatorsCalculator(); $this->assertInstanceOf(GpIndicatorsCalculator::class, $gpCalculator, "GP Calculator Object"); $globalTarget = GlobalVariable::first()->monthly_gp_target; $gpTarget = $gpCalculator->target(); $actualGpCalc = 0; $actualTurnOverCalc = 0; foreach ($currentMonthDespatch as $entry) { $this->assertInstanceOf(DespatchLogEntry::class, $entry); $actualGpCalc += $entry->gp_contribution; $this->assertInternalType('float', $entry->gp_contribution); $actualTurnOverCalc += $entry->selling_price * $entry->net_weight; $this->assertInternalType('float', $entry->selling_price); } $this->assertEquals(round($actualGpCalc), $gpCalculator->monthActualGp(), "Current Month Actual"); $this->assertEquals(round($actualTurnOverCalc), $gpCalculator->monthActualTurnOver(), "Current Month Actual Turn Over"); $this->assertEquals(round($actualGpCalc / $gpTarget * 100), round($gpCalculator->monthActualPercentage()), "Current Month Actual Percentage"); $this->assertEquals(round($actualGpCalc / $globalTarget * 100), round($gpCalculator->monthProductionAchievedPercentage()), "Current Month Production Target Percentage"); }
/** * Calculate the current months Actual GP * * @return string */ public function monthActualGp() { return Cache::store('database')->remember(__CLASS__ . "::" . __FUNCTION__ . $this->date->month . $this->date->year, 60, function () { $monthDespatchEntries = DespatchLogEntry::thisMonth($this->date)->get(); return round($monthDespatchEntries->sum('gp_contribution')); }); }