@extends('layouts.report')
@section('title', '売上日次明細一覧表')


@section('content')

<style type="text/css">
  @page {
    size: landscape;
  }
  p {
    font-size: 110%;
  }
</style>

@php
    $RECORDS_PER_PAGE = 30;
    $pages = [];
    $page = [];
    $total = [];
    $total['金額'] = 0;
    $total['枚数'] = 0;
    $total['件数'] = 0;
    $printday = date("Y.m.d");
    $closingdate = $viewdata['closingdate'];

    foreach($viewdata['dailyuris'] as $dailyuri)
    {
      $dailyuri['kind'] = 1;
      $page[] = $dailyuri;
      $total['枚数'] += 1;

      foreach($dailyuri['orders'] as $order)
      {
        $order['kind'] = 2;
        $page[] = $order;
        $total['金額'] += $order['金額'] * $order['saleskind_surplus'];
        $total['件数'] += 1;
        if (count($page) >= $RECORDS_PER_PAGE)
        {
          $pages[]  = $page;
          $page = [];
        }
      }
    }
    if (count($page) > 0)
    {
      $pages[]  = $page;
      $page = [];
    }

@endphp

@foreach($pages as $i => $page)
  @include('dailyuri/report01-01',[
    'pagenum' => ($i + 1), 
    'pagedata' => $page,
    'printday' => $printday,
    'closingdate' => $closingdate,
    'total' => (($i == count($pages) - 1) ? $total : null)
  ]);
@endforeach


@endsection