<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Invoice - {{ $order->order_number }}</title>

<style>

body{
    font-family: DejaVu Sans, sans-serif;
    font-size:12px;
    color:#333;
}

.container{
    width:100%;
}

.header{
    border-bottom:2px solid #000;
    padding-bottom:10px;
    margin-bottom:20px;
}

.logo{
    float:left;
}

.company{
    float:right;
    text-align:right;
}

.clear{
    clear:both;
}

.invoice-title{
    font-size:20px;
    font-weight:bold;
    margin-top:10px;
}

.section{
    margin-top:20px;
}

table{
    width:100%;
    border-collapse:collapse;
}

table th{
    background:#f4f4f4;
    border:1px solid #ddd;
    padding:8px;
    font-weight:bold;
}

table td{
    border:1px solid #ddd;
    padding:8px;
}

.text-right{
    text-align:right;
}

.summary td{
    border:none;
    padding:5px;
}

.total{
    font-size:16px;
    font-weight:bold;
}

.footer{
    margin-top:40px;
}

.signature{
    float:right;
    text-align:center;
}

</style>
</head>

<body>

<div class="container">

{{-- HEADER --}}
<div class="header">

<div class="logo">
<img src="{{ asset('backend/img/logo.png') }}" height="60">
</div>

<div class="company">
<strong>{{ env('COMPANY_NAME') }}</strong><br>

{{ env('COMPANY_ADDRESS') }}<br>

Phone: {{ env('COMPANY_PHONE') }}<br>

Email: {{ env('COMPANY_EMAIL') }}<br>

GSTIN: {{ env('COMPANY_GSTIN') }}
</div>

<div class="clear"></div>

<div class="invoice-title">
TAX INVOICE
</div>

</div>


{{-- CUSTOMER --}}
<div class="section">

<strong>Bill To:</strong><br>

{{ $order->first_name }} {{ $order->last_name }}<br>

{{ $order->address1 }} {{ $order->address2 }}<br>

{{ $order->city }} - {{ $order->post_code }}<br>

{{ $order->state }}, {{ $order->country }}<br>

Phone: {{ $order->phone }}<br>

Email: {{ $order->email }}

</div>


{{-- ORDER INFO --}}
<div class="section">

<table class="summary">

<tr>
<td><strong>Invoice No:</strong> {{ $order->order_number }}</td>
<td class="text-right"><strong>Invoice Date:</strong> {{ $order->created_at->format('d M Y') }}</td>
</tr>

</table>

</div>


{{-- PRODUCT TABLE --}}
<div class="section">

<table>

<thead>

<tr>
<th>#</th>
<th>Product</th>
<th>HSN</th>
<th>Qty</th>
<th>Price</th>
<th>Tax %</th>
<th>Total</th>
</tr>

</thead>

<tbody>

@php
$i = 1;
$taxTotal = 0;
@endphp

@foreach($order->cart_info as $cart)

@php

$product = $cart->product;

$price = $cart->price;

$qty = $cart->quantity;

$taxRate = $product->tax_percentage ?? 0;

$tax = ($price * $qty * $taxRate)/100;

$taxTotal += $tax;

$total = ($price * $qty) + $tax;

@endphp

<tr>

<td>{{ $i++ }}</td>

<td>{{ $product->title }}</td>

<td>{{ $product->hsn_code }}</td>

<td>{{ $qty }}</td>

<td class="text-right">₹{{ number_format($price,2) }}</td>

<td class="text-right">{{ $taxRate }}%</td>

<td class="text-right">₹{{ number_format($total,2) }}</td>

</tr>

@endforeach

</tbody>

</table>

</div>


{{-- TOTAL SECTION --}}
<div class="section">

<table class="summary">

<tr>
<td width="70%"></td>
<td class="text-right">Subtotal</td>
<td class="text-right">₹{{ number_format($order->sub_total,2) }}</td>
</tr>

<tr>
<td></td>
<td class="text-right">GST</td>
<td class="text-right">₹{{ number_format($taxTotal,2) }}</td>
</tr>

<tr>
<td></td>
<td class="text-right">Shipping</td>
<td class="text-right">₹{{ number_format($order->delivery_charge,2) }}</td>
</tr>

<tr class="total">
<td></td>
<td class="text-right">Grand Total</td>
<td class="text-right">₹{{ number_format($order->total_amount,2) }}</td>
</tr>

</table>

</div>


{{-- FOOTER --}}
<div class="footer">

<div class="signature">

For {{ env('COMPANY_NAME') }}

<br><br><br>

Authorized Signatory

</div>

</div>

</div>

</body>
</html>