/**
  * @test
  */
 public function scope_for_sheets_associated_with_given_job()
 {
     $job = JobCard::find(1);
     $job_log_sheets = PrintingLogSheet::associatedWithJob($job)->get();
     $associated_log_sheets_manually = DB::table('printing_log_sheets')->where('job_id_fk', $job->job_cards_id)->get();
     foreach ($job_log_sheets as $sheet) {
         $this->assertEquals($sheet->job_id_fk, $job->job_cards_id);
     }
     $this->assertCount(count($associated_log_sheets_manually), $job_log_sheets);
 }
 /**
  * Overwrite the parent boot method
  *
  * @return void
  */
 public static function boot()
 {
     parent::boot();
     PrintingLogSheet::creating(function ($printing_log_sheet) {
         $printing_log_sheet->created_by = Auth::user()->id;
         $printing_log_sheet->updated_by = Auth::user()->id;
     });
     PrintingLogSheet::updating(function ($printing_log_sheet) {
         $printing_log_sheet->updated_by = Auth::user()->id;
     });
 }
 /**
  * @test
  */
 public function it_has_a_statically_callable_table_name()
 {
     $tableName = App\Models\PrintingLogSheet::table();
     $this->assertEquals('printing_log_sheets', $tableName);
 }
 /**
  * Collection of jobs started in this department in current shift
  * @return Collection
  */
 public function currentShiftJobsStarted()
 {
     $jobsStartedIds = DB::table(PrintingLogSheet::table())->select('job_id_fk')->groupBy('job_id_fk')->havingRaw('min(created_at) >= \'' . $this->current_shift->starting_time . '\'')->havingRaw('min(created_at) <= \'' . $this->current_shift->ending_time . '\'')->pluck('job_id_fk');
     return JobCard::find($jobsStartedIds);
 }
 /**
  * Scope a query to only include PrintingLogEntries for a given job.
  *
  * @param $query
  * @param int|JobCard $job
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function scopeAssociatedWithJob($query, $job)
 {
     $logSheets = PrintingLogSheet::associatedWithJob($job);
     if (is_int($job)) {
         return $query->where('job_id_fk', $job);
     }
     return $query->where('job_id_fk', $job->job_cards_id);
 }