<?php
/**
 * This is a core PHP file. For customization, create a file in the folder /custom/.
 * Files with the same filename in this folder will automatically be loaded instead of the current file
 */
?>
<div class="col-xl-9 col-lg-8">
<div class="main-content p-a-2">

	<?php
		if (isset($message))
		{
			echo $message;
		}
	?>

	<h1><?php echo __('pricequote') . ' ' . normalize($pricequote_object->PriceQuoteCode); ?></h1>

	<div class="row m-t-1">

		<div class="col-sm-12">

			<a class="btn btn-secondary action-btn m-r" href="<?php echo __SITE_URL . '/' . __('pricequote', 'url') . '/' . __('download', 'url') . '/' . $pricequote_object->id; ?>">
				<span class="fas fa-print fa-2x"></span><br />
				<div><?php echo __('download pricequote'); ?></div>
			</a>
			<?php
			if($pricequote_object->Status < 3 && $pricequote_object->ExpirationDate >= date('Y-m-d') && Settings_Model::get('CLIENTAREA_PRICEQUOTE_ACCEPT') == 'yes')
			{
				?>
				<a class="btn btn-secondary action-btn" href="<?php echo __SITE_URL . '/' . __('pricequote', 'url') . '/' . __('accept', 'url') . '/' . $pricequote_object->id; ?>">
					<span class="fas fa-check fa-2x"></span>
					<br/>
					<div><?php echo __('accept pricequote'); ?></div>
				</a>

				<a class="btn btn-secondary action-btn" data-toggle="modal" data-target="#decline-pricequote" data-backdrop="static">
					<span class="fas fa-times fa-2x"></span>
					<br/>
					<div><?php echo __('decline pricequote'); ?></div>
				</a>
				<?php
			}
			?>
		</div>
	</div>

	<?php
	if(in_array($pricequote_object->Status, array(3,4)) && $pricequote_object->AcceptPDF > 0)
	{
		?>
		<div class="row m-t-2">
			<div class="col-md-12 mb-3">
				<div class="card">
					<div class="card-header">
						<p class="font-weight-bold"><?php echo sprintf(__('the pricequote is accepted online on %s'), rewrite_date_db2site($pricequote_object->AcceptDate).' '.__('at').' '.rewrite_date_db2site($pricequote_object->AcceptDate, 'H:i')); ?></p>
					</div>
					<div class="card-block">
						<div class="col-md-12 col-lg-6 p-l-0">

							<dl class="dl-horizontal">
								<dt class="col-sm-4"><?php echo __('signed by'); ?></dt>
								<dd class="col-sm-8"><?php echo normalize($pricequote_object->AcceptName); ?></dd>

								<dt class="col-sm-4"><?php echo __('emailaddress'); ?></dt>
								<dd class="col-sm-8"><?php echo normalize($pricequote_object->AcceptEmailAddress); ?></dd>
								<?php
								if($pricequote_object->AcceptComment)
								{
									?>
									<dt class="col-sm-4"><?php echo __('comment'); ?></dt>
									<dd class="col-sm-8"><?php echo nl2br(normalize($pricequote_object->AcceptComment)); ?></dd>
									<?php
								}
								?>

								<dt class="col-sm-4"><?php echo __('ipaddress'); ?></dt>
								<dd class="col-sm-8"><?php echo normalize($pricequote_object->AcceptIPAddress); ?></dd>
							</dl>

						</div>

						<div class="col-md-12 col-lg-6 p-l-0">
							<p class="font-weight-bold"><?php echo __('signature'); ?></p>
							<img src="data:image/svg+xml;base64,<?php echo normalize($pricequote_object->AcceptSignatureBase64); ?>" style="max-height:155px;max-width:100%"/>
						</div>

						<div class="clearfix"></div>

						<a href="<?php echo __SITE_URL . '/' . __('pricequote', 'url') . '/' . __('download', 'url') . '/' . $pricequote_object->id; ?>"><?php echo __('download signed pricequote'); ?></a>

					</div>
				</div>
			</div>
		</div>
		<?php
	}
	?>

	<h2><?php echo __('pricequote'); ?></h2>

	<hr>

	<div class="row">

		<div class="col-md-6 col-sm-12 m-b-3">
			<?php echo show_client_address($pricequote_object); ?>
		</div>

		<div class="col-md-6 col-sm-12 m-b-2">

			<dl class="dl-horizontal">
				<dt class="col-sm-4"><?php echo __('pricequote date'); ?></dt>
				<dd class="col-sm-8"><?php echo rewrite_date_db2site($pricequote_object->Date); ?></dd>
				<?php
				if($pricequote_object->Status == 2)
				{
					?>
					<dt class="col-sm-4"><?php echo __('expiration date'); ?></dt>
					<dd class="col-sm-8"><?php echo rewrite_date_db2site($pricequote_object->ExpirationDate); ?></dd>
					<?php
				}
				?>
				<dt class="col-sm-4"><?php echo __('status'); ?></dt>
				<dd class="col-sm-8"><?php echo __($pricequote_object->Status, 'array_pricequotestatus'); ?></dd>

				<?php
				if($pricequote_object->ReferenceNumber)
				{
					?>
					<dt class="col-sm-5"><?php echo __('reference number'); ?></dt>
					<dd class="col-sm-7"><?php echo normalize($pricequote_object->ReferenceNumber); ?></dd>
					<?php
				}
				?>
			</dl>
		</div>

		<?php
		if(!empty($pricequote_object->Attachments))
		{
			?>
			<div class="col-sm-12 m-b-3">
				<strong><?php echo __('attachments'); ?>:</strong><br />
				<?php
				foreach($pricequote_object->Attachments as $_attachment)
				{
					?>
					<a class="p-r-2 text-nowrap text-truncate" href="<?php echo __SITE_URL . '/' . __('pricequote', 'url') . '/' . __('downloadAttachment', 'url') . '/' . $pricequote_object->id . '/' . $_attachment['Identifier']; ?>">
						<span class="fas fa-file"></span> <?php echo normalize($_attachment['Filename']); ?>
					</a>
					<?php
				}
				?>
			</div>
			<?php
		}
		?>

	</div>

	<h2 class="hidden-sm-up"><?php echo __('pricequote lines'); ?></h2>

	<div class="row small-gutter strong hidden-xs-down">
		<div class="col-sm-2 hidden-sm-down"><?php echo __('date') ?></div>
		<div class="col-sm-2 col-md-1"><?php echo __('quantity') ?></div>
		<div class="col-sm-6 col-md-6"><?php echo __('description') ?></div>
		<div class="col-sm-4 col-md-3 text-xs-right"><?php echo ($pricequote_object->VatCalcMethod == 'incl') ? __('amountIncl') : __('amountExcl'); ?></div>
	</div>

	<hr />

	<?php

	if(!empty($pricequote_object->PriceQuoteLines))
	{
		foreach($pricequote_object->PriceQuoteLines as $k => $v)
		{
			if(is_numeric($k))
			{
				/** PRICEQUOTE LINE */
				?>
				<div class="row small-gutter m-t-1">

					<div class="col-sm-2 col-xs-8 hidden-sm-down">
						<?php
						if(!($v['PriceExcl'] === '' || $v['PriceExcl'] == 0) || $v['ProductCode'])
						{
							echo rewrite_date_db2site($v['Date']);
						}
						?>
					</div>

					<div class="col-sm-2 col-md-1 hidden-xs-down">
						<?php
						if(!($v['PriceExcl'] === '' || $v['PriceExcl'] == 0) || $v['ProductCode'])
						{
							echo showNumber($v['Number']) . ' ' . normalize($v['NumberSuffix']);
						}
						?>
					</div>

					<div class="col-sm-7 col-xs-8">
						<?php
						if($v['Number'] != 1 || $v['NumberSuffix'])
						{
							// only show amount on mobile if it is not one or has a suffix
							$suffix = ($v['NumberSuffix']) ? normalize($v['NumberSuffix']) : 'x';
							echo '<span class="hidden-sm-up">' . showNumber($v['Number']) . ' ' . $suffix . ' &nbsp;</span>';
						}

						echo (trim($v['Description'])) ? nl2br(parseHTMLTags(normalize($v['Description']))) : '&nbsp;';

						if((!($v['PriceExcl'] === '' || $v['PriceExcl'] == 0) || $v['ProductCode']) && $v['Periodic'] != '')
						{
							echo '<br/><i>';
							echo '<span class="hidden-sm-down">' . __('period') . ': </span>';
							echo rewrite_date_db2site($v['StartPeriod']);
							echo ' ' . __('till') . ' ';
							echo rewrite_date_db2site($v['EndPeriod']);
							echo '<span class="hidden-sm-down"> (' . $v['Periods'] . ' ' . __($v['Periodic'], (($v['Periods'] > 1) ? 'array_periodic_multi' : 'array_periodic')) . ')</span>';
							echo '</i>';
						}
						?>
					</div>

					<div class="col-sm-3 col-md-2 col-xs-4">
						<?php
						if(!($v['PriceExcl'] === '' || $v['PriceExcl'] == 0) || $v['ProductCode'])
						{
							?>
							<div class="row small-gutter">
								<div class="col-xs-2 hidden-xs-down">
									<?php echo Settings_Model::get('CURRENCY_SIGN_LEFT'); ?>
								</div>
								<div class="col-xs-10 text-xs-right text-nowrap">
									<span class="hidden-sm-up">
										<?php
										echo Settings_Model::get('CURRENCY_SIGN_LEFT') . ' ';
										?>
									</span>
									<?php
									echo money(($pricequote_object->VatCalcMethod == 'incl') ? $v['NoDiscountAmountIncl'] : $v['NoDiscountAmountExcl'], FALSE);
									if(Settings_Model::get('CURRENCY_SIGN_RIGHT'))
									{
										echo ' ' . Settings_Model::get('CURRENCY_SIGN_RIGHT');
									}
									?>
								</div>
							</div>

							<?php
						}
						?>
					</div>
				</div>

				<?php
				/** DISCOUNT LINE */
				if($v['DiscountPercentage'] > 0)
				{
					?>
					<div class="row small-gutter m-t-0">

						<div class="col-sm-2 col-md-3 hidden-xs-down">&nbsp;</div>

						<div class="col-sm-7 col-xs-8">
							<i><?php echo sprintf(__('discount on product'), showNumber(round($v['DiscountPercentage'], 2)) . '%'); ?></i>
						</div>

						<div class="col-sm-3 col-md-2 col-xs-4">
							<div class="row small-gutter">
								<div class="col-xs-2 hidden-xs-down">
									<?php echo Settings_Model::get('CURRENCY_SIGN_LEFT'); ?>
								</div>
								<div class="col-xs-10 text-xs-right text-nowrap">
									<span class="hidden-sm-up">
										<?php
										echo Settings_Model::get('CURRENCY_SIGN_LEFT') . ' ';
										?>
									</span>
									<?php
									echo money(($pricequote_object->VatCalcMethod == 'incl') ? $v['DiscountAmountIncl'] : $v['DiscountAmountExcl'], FALSE);
									if(Settings_Model::get('CURRENCY_SIGN_RIGHT'))
									{
										echo ' ' . Settings_Model::get('CURRENCY_SIGN_RIGHT');
									}
									?>
								</div>
							</div>
						</div>
					</div>
					<?php
				}

				// dont show line on last pricequote line
				if(count($pricequote_object->PriceQuoteLines) < $key--)
				{
					?>
					<hr class="hidden-sm-up" />
					<?php
				}
			}
		}

		if($pricequote_object->Discount > 0)
		{
			?>
			<div class="row small-gutter m-t-2">
				<div class="col-sm-2 col-md-3 hidden-xs-down">&nbsp;</div>

				<div class="col-sm-7 col-xs-8">
					<?php
					echo sprintf(__('discount on pricequote'), showNumber($pricequote_object->Discount) . '%');
					?>
				</div>

				<div class="col-sm-3 col-md-2 col-xs-4">
					<div class="row small-gutter">
						<div class="col-xs-2 hidden-xs-down">
							<?php echo Settings_Model::get('CURRENCY_SIGN_LEFT'); ?>
						</div>
						<div class="col-xs-10 text-xs-right text-nowrap">
							<span class="hidden-sm-up">
								<?php
								echo Settings_Model::get('CURRENCY_SIGN_LEFT') . ' ';
								?>
							</span>
							<?php
							echo money(($pricequote_object->VatCalcMethod == 'incl') ? $pricequote_object->AmountDiscountIncl : $pricequote_object->AmountDiscount, FALSE);
							if(Settings_Model::get('CURRENCY_SIGN_RIGHT'))
							{
								echo ' ' . Settings_Model::get('CURRENCY_SIGN_RIGHT');
							}
							?>
						</div>
					</div>
				</div>
			</div>

			<?php
		}
		?>
		<div class="row small-gutter m-t-1">
			<div class="col-xs-7 col-sm-9 col-md-10"></div>
			<div class="col-xs-5 col-sm-3 col-md-2">
				<hr />
			</div>
		</div>

		<?php
		if(!empty(Settings_Model::$taxpercentages) || !empty(Settings_Model::$total_taxpercentages))
		{
			echo generate_amount_totals(__('amountExcl'), money($pricequote_object->AmountExcl, FALSE));
		}

		asort(Settings_Model::$taxpercentages);

		foreach(Settings_Model::$taxpercentages as $key => $value)
		{
			if(isset($pricequote_object->UsedTaxrates[(string)(float)$key]['AmountTax']) && (float)$key > 0)
			{
				$tax_label = (isset(Settings_Model::$taxpercentages_info[(string)(float)$key]['label'])) ? Settings_Model::$taxpercentages_info[(string)(float)$key]['label'] : '';
				echo generate_amount_totals(normalize($tax_label), money($pricequote_object->UsedTaxrates[(string)(float)$key]['AmountTax'], FALSE));
			}
		}

		if(isset($pricequote_object->TaxRate_Label) && $pricequote_object->TaxRate_Label)
		{
			echo generate_amount_totals(normalize($pricequote_object->TaxRate_Label), money($pricequote_object->TaxRate_Amount, FALSE));
		}


		if(empty(Settings_Model::$taxpercentages) && empty($array_total_taxpercentages))
		{
			$total_label = '<strong>' . __('amount') . '</strong>';
		}
		else
		{
			$total_label = '<strong>' . __('amountIncl') . '</strong>';
		}
		echo generate_amount_totals($total_label, money($pricequote_object->AmountIncl, FALSE));

	}
	?>

</div>
</div>

<?php
if($pricequote_object->Status < 3 && Settings_Model::get('CLIENTAREA_PRICEQUOTE_ACCEPT') == 'yes')
{
	$this->showElement('modal.pricequote.decline');
}