Advertisement
Guest User

Untitled

a guest
Nov 20th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.97 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers\Report;
  4.  
  5. use Illuminate\Http\Request;
  6. use App\Http\Controllers\Controller;
  7. use Illuminate\Support\Facades\DB;
  8. use App\Model\Attendance;
  9. use App\Model\Attendance_line;
  10. use Excel;
  11.  
  12. class AmountPerInquiryController extends Controller
  13. {
  14.     public function __invoke(Request $request)
  15.     {
  16.         /* return 1; */
  17.         $awal = $request->awal;
  18.         $akhir = $request->akhir;
  19.  
  20.        
  21.         $attendance = Attendance::with('checked')->whereBetween('tgl_absen', [$awal, $akhir])->orderBy('tgl_absen')->get();
  22.         $attline = Attendance_line::with('attendance','man_power')->whereIn('attendance_id', $attendance->pluck('id'))->get();
  23.         $attline = $attline->sortBy(function ($item) {
  24.           return $item->man_power['nama'];
  25.         }, SORT_NATURAL|SORT_FLAG_CASE);
  26.         $skill = DB::table('upah_borongans')->get();
  27.  
  28.  
  29.         Excel::load('excel/amount_per_inquiry.xls', function($reader) use ($skill, $attendance, $attline, $awal, $akhir){
  30.             $reader->sheet('Sheet1', function($sheet) use ($skill, $attendance, $attline, $awal, $akhir){
  31.                 $row = 4;            
  32.                 $collection = $attline->groupBy('keterangan')->sortKeys();
  33.                 foreach($collection as $key => $item) {
  34.                   /* dd($item->toArray()); */
  35.                     $sheet->setCellValue("A$row", $key);
  36.  
  37.                     $total_upah = 0;
  38.                     foreach($item as $subitem) {
  39.                         $day = \Carbon\Carbon::parse($subitem->attendance->tgl_absen)->format('l');
  40.                         $hour = 8;
  41.                         if($day == 'Saturday' || $day =='Sunday') {
  42.                             $hour = $hour * 2;
  43.                         }
  44.  
  45.                         $harga_borongan = 0;
  46.                         foreach($skill as $val) {
  47.                             if($val->class == $subitem->class) {
  48.                                 $harga_borongan = $val->harga_borongan;
  49.                                 break;
  50.                             }
  51.                         }
  52.  
  53.                         $total_upah += ($hour + $subitem->total_overtime) * $harga_borongan;
  54.                     }
  55.  
  56.  
  57.  
  58.                   $sheet->setCellValue("D$row", $total_upah);
  59.                   $sheet->setBorder("A$row:D$row", 'thin');
  60.                   $row++;                
  61.                 }
  62.                 $endOfRow = $row-1;
  63.                
  64.                 $sheet->setCellValue("A$row", 'GRANDTOTAL');
  65.                 $sheet->mergeCells("A$row:C$row");                
  66.                 $sheet->cells("A$row:C$row", function($cell) {
  67.                     $cell->setAlignment('right');
  68.                 });
  69.                 $sheet->setcellValue("D$row", "=SUM(D4:D$endOfRow)");
  70.                 $sheet->setBorder("D$row:D$row", 'thin');
  71.             });
  72.         })
  73.         ->setFilename('total_amount_per_inquiry' . $request->awal . ' - ' . $request->akhir)
  74.         ->download('xls');
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement