<div class="modal-dialog modal-xl" role="document">
	<div class="modal-content">
		<div class="modal-header">
			<button type="button" class="close no-print" data-dismiss="modal" aria-label="Close">
				<span aria-hidden="true">&times;</span>
			</button>

			<h4 class="modal-title" id="modalTitle">
				@lang('lang_v1.stock_adjustment_details')
				(<b>@lang('purchase.ref_no'):</b> #{{ $stock_adjustment->ref_no }})
			</h4>
		</div>

		<div class="modal-body">
			<div id="stock_adjustment_print_area">
				<div class="row">
					<div class="col-sm-12">
						<p class="pull-right">
							<b>@lang('messages.date'):</b> {{ @format_date($stock_adjustment->transaction_date) }}
						</p>
					</div>
				</div>

				<div class="row invoice-info">
					<div class="col-sm-4 invoice-col">
						@lang('business.business'):
						<address>
							<strong>{{ $stock_adjustment->business->name }}</strong>

							@if(!empty($stock_adjustment->location->name) && $stock_adjustment->location->name != $stock_adjustment->business->name)
								<br>{{ $stock_adjustment->location->name }}
							@endif

							@if(!empty($stock_adjustment->location->landmark))
								<br>{{ $stock_adjustment->location->landmark }}
							@endif

							@if(!empty($stock_adjustment->location->city) || !empty($stock_adjustment->location->state) || !empty($stock_adjustment->location->country))
								<br>{{ implode(',', array_filter([$stock_adjustment->location->city, $stock_adjustment->location->state, $stock_adjustment->location->country])) }}
							@endif

							@if(!empty($stock_adjustment->location->mobile))
								<br>@lang('contact.mobile'): {{ $stock_adjustment->location->mobile }}
							@endif

							@if(!empty($stock_adjustment->location->email))
								<br>@lang('business.email'): {{ $stock_adjustment->location->email }}
							@endif
						</address>
					</div>

					<div class="col-sm-4 invoice-col">
						<b>@lang('purchase.ref_no'):</b> #{{ $stock_adjustment->ref_no }}<br/>
						<b>@lang('messages.date'):</b> {{ @format_date($stock_adjustment->transaction_date) }}<br/>
						<b>@lang('stock_adjustment.adjustment_type'):</b> {{ __('stock_adjustment.' . $stock_adjustment->adjustment_type) }}<br>
						<b>@lang('stock_adjustment.reason_for_stock_adjustment'):</b> {{ $stock_adjustment->additional_notes }}<br>
					</div>
				</div>

				<div class="row">
					<div class="col-sm-12 col-xs-12">
						<div class="table-responsive">
							<table class="table table-condensed bg-gray stock-adjustment-print-table">
								<tr class="bg-green">
									<th>@lang('sale.product')</th>

									@if(!empty($lot_n_exp_enabled))
										<th>{{ __('lang_v1.lot_n_expiry') }}</th>
									@endif

									<th>@lang('sale.qty')</th>
									<th>@lang('sale.subtotal')</th>
								</tr>

								@foreach($stock_adjustment->stock_adjustment_lines as $stock_adjustment_line)
									<tr>
										<td>
											{{ $stock_adjustment_line->variation->full_name }}
										</td>

										@if(!empty($lot_n_exp_enabled))
											<td>
												{{ $stock_adjustment_line->lot_number ?? '--' }}

												@if(session()->get('business.enable_product_expiry') == 1 && !empty($stock_adjustment_line->exp_date))
													({{ @format_date($stock_adjustment_line->exp_date) }})
												@endif
											</td>
										@endif

										<td>
											{{ @format_quantity($stock_adjustment_line->quantity) }}
										</td>

										<td>
											{{ @num_format($stock_adjustment_line->unit_price * $stock_adjustment_line->quantity) }}
										</td>
									</tr>
								@endforeach
							</table>
						</div>
					</div>

					<div class="col-md-6 col-md-offset-6 col-sm-12 col-xs-12">
						<div class="table-responsive">
							<table class="table no-border stock-adjustment-summary-table">
								<tr>
									<th>@lang('stock_adjustment.total_amount'):</th>
									<td>
					            		<span class="display_currency pull-right" data-currency_symbol="true">
					            			{{ $stock_adjustment->final_total }}
					            		</span>
									</td>
								</tr>

								<tr>
									<th>@lang('stock_adjustment.total_amount_recovered'):</th>
									<td>
					            		<span class="display_currency pull-right" data-currency_symbol="true">
					            			{{ $stock_adjustment->total_amount_recovered }}
					            		</span>
									</td>
								</tr>
							</table>
						</div>
					</div>
				</div>

				<div class="row">
					<div class="col-md-12">
						<strong>{{ __('lang_v1.activities') }}:</strong><br>
						@includeIf('activity_log.activities')
					</div>
				</div>
			</div>
		</div>

		<div class="modal-footer">
			<button type="button" class="btn btn-primary no-print" aria-label="Print" onclick="printStockAdjustmentDetails();">
				<i class="fa fa-print"></i> @lang('messages.print')
			</button>

			<button type="button" class="btn btn-default no-print" data-dismiss="modal">
				@lang('messages.close')
			</button>
		</div>
	</div>
</div>

<script>
	function printStockAdjustmentDetails() {
		var printArea = document.getElementById('stock_adjustment_print_area');

		if (!printArea) {
			window.print();
			return;
		}

		var printWindow = window.open('', '_blank', 'width=1100,height=800');

		printWindow.document.open();
		printWindow.document.write(`
        <!DOCTYPE html>
        <html>
        <head>
            <title>Detalhes de ajuste de estoque</title>
            <style>
                * {
                    box-sizing: border-box;
                }

                body {
                    font-family: Arial, Helvetica, sans-serif;
                    color: #000;
                    font-size: 12px;
                    margin: 24px;
                }

                h1, h2, h3, h4, h5 {
                    margin: 0 0 12px 0;
                    font-weight: 700;
                }

                .row {
                    width: 100%;
                    display: table;
                    margin-bottom: 14px;
                    clear: both;
                }

                .col-sm-4,
                .col-md-4,
                .col-sm-6,
                .col-md-6,
                .col-sm-12,
                .col-md-12,
                .col-xs-12 {
                    display: table-cell;
                    vertical-align: top;
                    padding-right: 16px;
                }

                .col-sm-4,
                .col-md-4 {
                    width: 33.3333%;
                }

                .col-sm-6,
                .col-md-6 {
                    width: 50%;
                }

                .col-sm-12,
                .col-md-12,
                .col-xs-12 {
                    width: 100%;
                    display: block;
                }

                .col-md-offset-6 {
                    margin-left: 50%;
                    width: 50%;
                    display: block;
                }

                address {
                    font-style: normal;
                    line-height: 1.45;
                    margin: 0;
                }

                .pull-right {
                    float: right;
                }

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

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

                table {
                    width: 100%;
                    border-collapse: collapse;
                    margin-top: 10px;
                    margin-bottom: 16px;
                }

                table th,
                table td {
                    border: 1px solid #d9d9d9;
                    padding: 7px 8px;
                    text-align: left;
                    vertical-align: top;
                    line-height: 1.35;
                }

                table th {
                    font-weight: 700;
                }

                .bg-green th,
                tr.bg-green th {
                    background: #2f4050 !important;
                    color: #fff !important;
                }

                .bg-gray td,
                .stock-adjustment-print-table tr:nth-child(even) td {
                    background: #f2f2f2;
                }

                .stock-adjustment-summary-table th,
                .stock-adjustment-summary-table td {
                    border: none;
                    border-bottom: 1px solid #ddd;
                    padding: 6px 8px;
                }

                .stock-adjustment-summary-table td {
                    text-align: right;
                }

                .table-responsive {
                    width: 100%;
                    overflow: visible !important;
                }

                .label,
                .badge {
                    border: 1px solid #333;
                    padding: 2px 5px;
                    border-radius: 3px;
                    font-size: 10px;
                    color: #000 !important;
                    background: #fff !important;
                }

                .no-print,
                button,
                .btn,
                .close {
                    display: none !important;
                }

                .erp-print-footer {
                    margin-top: 32px;
                    border-top: 2px solid #1e88e5;
                    padding-top: 8px;
                    font-size: 10px;
                    text-align: center;
                    color: #333;
                }

                @page {
                    size: A4 portrait;
                    margin: 12mm;
                }
            </style>
        </head>
        <body>
            ${printArea.innerHTML}

            <div class="erp-print-footer">
                <strong>ERP Sousait</strong>
                &nbsp; | &nbsp;
                Emitido em: ${new Date().toLocaleString('pt-BR')}
                &nbsp; | &nbsp;
                ${window.location.origin}
                &nbsp; | &nbsp;
                Contatos para Suporte Técnico: suporte@sousait.net
            </div>
        </body>
        </html>
    `);
		printWindow.document.close();

		printWindow.onload = function () {
			printWindow.focus();
			printWindow.print();
		};
	}
</script>