<!DOCTYPE html>
<?php
use App\Models\OrderProducts;
use App\Models\User;
use App\Models\CustomerDetails;
use App\Models\Products;

$products=OrderProducts::where('order_id', $details['order']->id)->get();
$user_details=User::where('id', $details['order']->customer)->first();
$other_details=CustomerDetails::where('user_id', $details['order']->customer)->first();
?>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <style>
  @media screen and (max-width: 600px) {
    .content {
        width: 100% !important;
        display: block !important;
        padding: 10px !important;
    }
    .body{
        padding: 20px !important;
    }
  }
</style>
</head>
<body style="font-family: 'Poppins', Arial, sans-serif; margin:0px;">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td align="center" style="padding: 20px;">
                <table class="content" width="800" border="0" cellspacing="0" cellpadding="0" style="border-collapse: collapse; border: 1px solid #cccccc;">
                    <!-- Header -->
                    <tr>
                    <td>
                    <img src="{{ asset('assets/media/mail-background.jpg') }}" style=" width: 100%; height:200px;">
                    </td>
                   
                    </tr>

                    <!-- Body -->
                    <tr>
                    <td style="background:#f5f5f5;" >
                      <div class="body" style="padding: 40px; text-align: center; font-size: 16px; line-height: 1.6;margin-top:-100px;margin-left:40px;margin-right:40px;margin-bottom:40px;background:#fff;position:relative;">
                      <img src="{{ asset('assets/media/logo.svg') }}" style=" width: 250px;margin:auto;">
                      <h1 style="font-size:18px;font-weight:600;margin-top:25px;color:#666768">Your order is on delivery.</h1>
                      <p>your order successfully submitted to delivery.</p>

                      <table style="width:100%;border: none;">
                            <tr style="vertical-align:middle;">
                                <td style="width:50%;border: none;text-align:left;">
                                    <p >Promo EMR B.V.<br> Lange Nering 98<br>8302 EG Emmeloord<br> Nederland</p>
                                </td>
                                <td style="width:50%;border: none;text-align:right;">
                                    <p ><b>{{$other_details->customer_name}}</b><br>
                                    {{$other_details->address}}<br>
                        Tel: {{$other_details->phone}}<br>
                        E: mail: {{$user_details->email}}<br>
                        Website: www.ferolis.com<br>
                        BTW-nr: {{$other_details->vat_no}}<br>
                        Kvk: {{$other_details->kvk_no}}<br>
                        IBAN: NL10 INGB 0398 6281 30</p>
                                </td>
                            </tr>
                        </table>

                        <h2 style="text-align:center;">FACTUUR</h2>

                        <table style="width:100%;border: none;">
                            <tr style="vertical-align:middle;">
                                <td style="width:20%;border: none;text-align:left;padding:0;">
                                    <p style="margin:0;">Datum:</p>
                                </td>
                                <td style="width:80%;border: none;text-align:left;padding:0;">
                                    <p style="margin:0;">{{$details['order']->order_date}}</p>
                                </td>
                            </tr>
                            <tr style="vertical-align:middle;">
                                <td style="width:20%;border: none;text-align:left;padding:0;">
                                    <p style="margin:0;">Factuurnummer::</p>
                                </td>
                                <td style="width:80%;border: none;text-align:left;padding:0;">
                                    <p style="margin:0;">{{$details['order']->sales_order_number}}</p>
                                </td>
                            </tr>
                            <tr style="vertical-align:middle;">
                                <td style="width:20%;border: none;text-align:left;padding:0;">
                                    <p style="margin:0;">Vervaldatum::</p>
                                </td>
                                <td style="width:80%;border: none;text-align:left;padding:0;">
                                    <p style="margin:0;">{{$details['order']->due_date}}</p>
                                </td>
                            </tr>
                        </table>

                        <table style="width:100%;border: none;margin-top:40px;">
                            <tr style="vertical-align:middle;">
                                <th style="width:40%;border: none;text-align:left;padding:0;border-bottom:1px solid #000;padding-bottom:5px;">
                                    <p style="margin:0;">Omschrijving</p>
                                </th>
                                <th style="width:10%;border: none;text-align:left;padding:0;border-bottom:1px solid #000;padding-bottom:5px;">
                                    <p style="margin:0;">Aantal</p>
                                </th>
                                <th style="width:10%;border: none;text-align:left;padding:0;border-bottom:1px solid #000;padding-bottom:5px;">
                                    <p style="margin:0;">Eenheid</p>
                                </th>
                                <th style="width:10%;border: none;text-align:left;padding:0;border-bottom:1px solid #000;padding-bottom:5px;">
                                    <p style="margin:0;">Stukprijs</p>
                                </th>
                                <th style="width:10%;border: none;text-align:left;padding:0;border-bottom:1px solid #000;padding-bottom:5px;">
                                    <p style="margin:0;">Totaal</p>
                                </th>
                                <th style="width:10%;border: none;text-align:left;padding:0;border-bottom:1px solid #000;padding-bottom:5px;">
                                    <p style="margin:0;">Btw</p>
                                </th>

                            </tr>
                            <?php foreach($products as $product){ 
                                $product_name = Products::where('id', $product->product)->value('product_name');
                                $units = Products::where('id', $product->product)->value('units');
                            ?>

                            <tr style="vertical-align:middle;">
                                <td style="width:40%;border: none;text-align:left;padding:0;border-bottom:1px solid #000;padding-bottom:5px;">
                                    <p style="margin:0;">{{$product_name}}</p>
                                </td>
                                <td style="width:10%;border: none;text-align:left;padding:0;border-bottom:1px solid #000;padding-bottom:5px;">
                                    <p style="margin:0;">{{$product->quantity}}</p>
                                </td>
                                <td style="width:10%;border: none;text-align:left;padding:0;border-bottom:1px solid #000;padding-bottom:5px;">
                                    <p style="margin:0;">{{$units}}</p>
                                </td>
                                <td style="width:10%;border: none;text-align:left;padding:0;border-bottom:1px solid #000;padding-bottom:5px;">
                                    <p style="margin:0;">€ {{number_format($product->price)}}</p>
                                </td>
                                <td style="width:10%;border: none;text-align:left;padding:0;border-bottom:1px solid #000;padding-bottom:5px;">
                                    <p style="margin:0;">€ {{number_format($product->price*$product->quantity)}}</p>
                                </td>
                                <td style="width:10%;border: none;text-align:left;padding:0;border-bottom:1px solid #000;padding-bottom:5px;">
                                    <p style="margin:0;">{{$details['order']->tax}}%</p>
                                </td>

                            </tr>
                            <?php  } ?>

                            <tr style="vertical-align:middle;">
                                <td style="border: none;text-align:right;padding:0;padding-bottom:5px;padding-right:20px;" colspan="4">
                                    <p style="margin:0;">Totaal excl btw</p>
                                </td>
                                <td style="width:10%;border: none;text-align:left;padding:0;padding-bottom:5px;">
                                    <p style="margin:0;">€ {{number_format($details['order']->sub_total)}}</p>
                                </td>
                                <td style="width:10%;border: none;text-align:left;padding:0;padding-bottom:5px;">
                                    
                                </td>

                            </tr>
                            <tr style="vertical-align:middle;">
                                <td style="border: none;text-align:right;padding:0;padding-bottom:5px;padding-right:20px;" colspan="4">
                                    <p style="margin:0;">Btw hoog {{$details['order']->tax}}% (€ {{number_format($details['order']->sub_total)}})</p>
                                </td>
                                <td style="width:10%;border: none;text-align:left;padding:0;padding-bottom:5px;">
                                    <p style="margin:0;">+ € {{number_format(($details['order']->sub_total/100)*$details['order']->tax)}}</p>
                                </td>
                                <td style="width:10%;border: none;text-align:left;padding:0;padding-bottom:5px;">
                                    
                                </td>

                            </tr>
                            <tr style="vertical-align:middle;">
                                <td style="border: none;text-align:right;padding:0;padding-bottom:5px;padding-right:20px;" colspan="4">
                                    <p style="margin:0;">Korting {{$details['order']->discount}}% (€ {{number_format($details['order']->sub_total)}})</p>
                                </td>
                                <td style="width:10%;border: none;text-align:left;padding:0;padding-bottom:5px;border-bottom:1px solid #000;">
                                    <p style="margin:0;">- € {{number_format(($details['order']->sub_total/100)*$details['order']->discount)}}</p>
                                </td>
                                <td style="width:10%;border: none;text-align:left;padding:0;padding-bottom:5px;">
                                    
                                </td>

                            </tr>

                            <tr style="vertical-align:middle;">
                                <td style="border: none;text-align:right;padding:0;padding-bottom:5px;padding-right:20px;" colspan="4">
                                    <p style="margin:0;"><b>Totaal te betalen</b></p>
                                </td>
                                <td style="width:10%;border: none;text-align:left;padding:0;padding-bottom:5px;">
                                    <p style="margin:0;">€ {{number_format($details['order']->total)}}</p>
                                </td>
                                <td style="width:10%;border: none;text-align:left;padding:0;padding-bottom:5px;">
                                    
                                </td>

                            </tr>
                        
                        </table>
                        <p style="text-align:left;margin-top:25px;">Gelieve het factuurbedrag ad 698,90 vóór {{$details['order']->due_date}} betalen o.v.v. factuurnummer te betalen op IBAN NL10 INGB 0398 6281
                        30 t.n.v. Ferolis B.V..</p>

                      <p style="text-align:left;margin-top:50px;">Contact Us for further details<br>
                      <span style="font-weight:600;">+31615095711<br>
                      info@ferolis.com</span></p>
                    </div>
                   </td>
                    </tr>

                    <tr>
                    <td style="background:#17181a;height:50px;" >
                    </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</body>
</html>
