<div class="table-responsive">
	<?php if(isset($_GET["view"])){ ?>
	<table id="all-payments-page" class="table table-hover all-tasks tasks-inwork" style="margin:0;">
		<thead> 
			<tr> 
				<th width="5%">Статус</th> 
				<th width="10%" style="text-align:center!important;">ID</th>
				<th width="17%" style="text-align:right!important;">Сумма</th>
				<th width="15%" style="text-align:center!important;" data-sorter="shortDate" data-date-format="yyyymmdd">Дата платежа</th>
				<th style="text-align:left!important;">Комментарий</th>
				<th width="5%"></th>
			</tr> 
		</thead> 
		<tbody>
			<?php
			$dom = new DOMDocument;
			$dom->load($baseP);
			$xpath = new DOMXPath($dom);
			$payments = $xpath->query('/payments/payment[@did="'.$_GET["view"].'"]');
			foreach($payments as $payment) {
				$pId 			= $payment->getAttribute('id');
				$pType 			= $payment->getAttribute('type');
				$pStatus 		= $payment->getAttribute('status');
				$pDate 			= $payment->getElementsByTagName("date")->item(0)->nodeValue;
				$pValue 		= $payment->getElementsByTagName("val")->item(0)->nodeValue;
				$pComment 		= $payment->getElementsByTagName("com")->item(0)->nodeValue;
			?>
			<tr> 
				<td>
				<?php if($pStatus == '+'){
					echo '<button class="btn btn-sm btn-link" style="cursor:default;" type="button"><i class="fa fa-fw fa-check clr_low" title="Платеж подтвержден"></i></button>';
					} else {
						echo '
						<form method="POST">
							<button class="btn btn-sm btn-link" type="submit" name="PaymentConfirm" onclick="return confirm(\'Подтвердить платеж #'.$pId.'?\')"><i class="fa fa-fw fa-clock-o clr_none" title="Подтвердить платеж"></i></button>
							<input type="text" class="hidden" name="PaymentConfirmId" value="'.$pId.'">
						</form>
						';
					} ?>
				</td>
				<td style="text-align:center!important;"><?php echo $pId;?></td> 
				<td style="text-align:right!important;" <?php if($pType == 'cost'){ echo 'class="clr_high"'; } else { echo 'class="clr_low"'; }?>><?php echo conv_price($pValue, 'long', 'руб.' );?></td>
				<td>
					<div class="rem_days_body" title="<?php echo date('H:i:s', strtotime($pDate));?>">
						<div class="txt"><?php echo date('Y-m-d', strtotime($pDate));?><div class="hidden"> <?php echo date('H:i:s', strtotime($pDate));?></div></div>
					</div>
				</td>
				<td style="text-align:left!important;">
					<form method="POST" class="save_form">
						<div class="input-group input-group-xs">
							<input type="hidden" name="id" value="<?php echo $pId;?>">
							<input type="text" class="form-control" name="comment" value="<?php echo $pComment;?>" title="<?php echo $pComment;?>">
							<div class="input-group-btn"><button class="btn btn-default btn-xs" type="submit" name="SaveComment" title="Сохранить комментарий"><i class="fa fa-fw fa-save"></i></button></div>
						</div>
					</form>
				</td>
				<td>
					<form method="POST">
						<button class="btn btn-sm btn-link" type="submit" name="PaymentDelete" onclick="return confirm('Удалить платеж #<?php echo $pId;?>?')"><i class="fa fa-fw fa-times" aria-hidden="true"></i></button>
						<input type="text" class="hidden" name="PaymentDelId" value="<?php echo $pId;?>">
					</form>
				</td>
			</tr>
			<?php } ?>
		</tbody>
	</table>
	<?php } else { ?>
	<table id="all-payments" class="table table-hover all-tasks tasks-inwork" style="margin:0;">
		<thead> 
			<tr> 
				<th width="5%">Статус</th> 
				<th width="8%" style="text-align:center!important;">ID</th>
				<th width="23%">Сделка</th> 
				<th width="15%" style="text-align:right!important;">Сумма</th>
				<th width="12%" style="min-width:100px;text-align:center!important;">Дата</th>
				<th style="text-align:left!important;">Комментарий</th>
				<th width="5%"></th>
			</tr> 
		</thead> 
		<tbody>
			<?php
			foreach($payments as $payment) {
				$pId 			= $payment->getAttribute('id');
				$pDid 			= $payment->getAttribute('did');
				$pType 			= $payment->getAttribute('type');
				$pStatus 		= $payment->getAttribute('status');
				$pDealNum 		= $payment->getElementsByTagName("deal")->item(0)->nodeValue;
				$pDate 			= $payment->getElementsByTagName("date")->item(0)->nodeValue;
				$pValue 		= $payment->getElementsByTagName("val")->item(0)->nodeValue;
				$pComment 		= $payment->getElementsByTagName("com")->item(0)->nodeValue;
			?>
			<tr> 
				<td>
				<?php if($pStatus == '+'){
					echo '<button class="btn btn-sm btn-link" style="cursor:default;" type="button"><i class="fa fa-fw fa-check clr_low" title="Платеж подтвержден"></i></button>';
					} else {
						echo '
						<form method="POST">
							<button class="btn btn-sm btn-link" type="submit" name="PaymentConfirm" onclick="return confirm(\'Подтвердить платеж #'.$pId.'?\')"><i class="fa fa-fw fa-clock-o clr_none" title="Подтвердить платеж"></i></button>
							<input type="text" class="hidden" name="PaymentConfirmId" value="'.$pId.'">
						</form>
						';
					} ?>
				</td>
				<td style="text-align:center!important;"><?php echo $pId;?></td>  
				<td style="text-align:left!important;">
				<?php if($pDid != '-'){ echo '
					<a href="/'.$folder.'/deals/?view='.$pDid.'" title="'.get_deal_info($pDid,'subject').'">'.$pDealNum.'</a>
					<small class="d-block">
						<i class="fa fa-fw fa-address-book" aria-hidden="true"></i> <a href="/' . $folder . '/clients/?view='.get_deal_info($pDid,'cid').'" class="DealClient">' . get_client_name(get_deal_info($pDid,'cid')) . '</a>
					</small>'; } else { echo '-'; } ?>
				</td>
				<td style="text-align:right!important;" <?php if($pType == 'cost'){ echo 'class="clr_high"'; } else { echo 'class="clr_low"'; }?>><?php echo conv_price($pValue, 'long', 'руб.' );?></td>
				<td>
					<div class="rem_days_body" title="<?php echo date('H:i:s', strtotime($pDate));?>">
						<div class="txt"><?php echo date('Y-m-d', strtotime($pDate));?><div class="hidden"> <?php echo date('H:i:s', strtotime($pDate));?></div></div>
					</div>
				</td>
				<td style="text-align:left!important;">
				
					<form method="POST" class="save_form">
						<div class="input-group input-group-xs">
							<input type="hidden" name="id" value="<?php echo $pId;?>">
							<input type="text" class="form-control" name="comment" value="<?php echo $pComment;?>" title="<?php echo $pComment;?>">
							<div class="input-group-btn"><button class="btn btn-default btn-xs" type="submit" name="SaveComment" title="Сохранить комментарий"><i class="fa fa-fw fa-save"></i></button></div>
						</div>
					</form>
				
				</td>
				<td>
					<form method="POST">
						<button class="btn btn-sm btn-link" type="submit" name="PaymentDelete" onclick="return confirm('Удалить платеж #<?php echo $pId;?>?')"><i class="fa fa-fw fa-times" aria-hidden="true"></i></button>
						<input type="text" class="hidden" name="PaymentDelId" value="<?php echo $pId;?>">
					</form>
				</td>
			</tr>
			<?php } ?>
		</tbody>
	</table>
	<?php } ?>
</div>
<?php require_once(ROOT . 'templates/table-pager.php'); ?>