<div class="col-lg-12 col-md-12 col-sm-12">
	<h1><span class="mark" title="<?php if($Type == 'deal-a'){echo 'Активная сделка';}elseif($Type == 'deal-c'){echo 'Завершенная сделка';}else{echo 'Коммерческое предложение';}?>"> <i class="fa fa-sm fa-bookmark clr_<?php if ($Price >= '500001') {echo 'vhigh';} elseif ($Price < '500000' and $Price >= '250000') {echo 'high';} elseif ($Price < '250000' and $Price >= '100000') {echo 'medium';} elseif ($Price < '100000' and $Price >= '25000') {echo 'low';} elseif ($Price < '25000' and $Price >= '5000') {echo 'vlow';} else {echo 'none';} ?>" aria-hidden="true"></i> <?php if($Type == 'deal-a'){echo $nCRMdeals;}elseif($Type == 'deal-c'){echo $nCRMdeals;}else{echo $nCRMoffers;} echo ' ' . $DealNumber .'</span>'; if(isset($Subject)){echo ' ' . $Subject;}?></h1>
	<div class="row">
		<div class="col-lg-3">
			<div class="row">
				<div class="col-lg-12 col-md-12 col-sm-12 col-xs-4">
					<div class="big-photo empty" style="background:#555a68;">
						<?
						if ($Type == 'deal-c') {
							echo '<i class="fa fa-fw fa-briefcase" aria-hidden="true"></i>';
						} elseif ($Type == 'deal-a') {
							echo '<i class="fa fa-fw fa-handshake-o" aria-hidden="true"></i>';
						} else {
							echo '<i class="fa fa-fw fa-file-text-o" aria-hidden="true"></i>';
						}
						?>
					</div>
				</div>
				<div class="col-lg-12 col-md-12 col-sm-12 col-xs-8">
					<form method="POST" style="display:block;">
						<?php if ( $Type == 'deal-a' ) { ?>
						<div class="input-group" style="width:100%;margin:0px 0px 10px 0px;">
							<span class="input-group-addon" style="width:50px;"><i class="fa fa-fw fa-briefcase" aria-hidden="true"></i></span>
							<div class="input-group-btn" style="width:calc(100% - 50px);"><button class="btn btn-success" style="width:100%;" type="submit" name="DealDone" onclick="return confirm('Завершить сделку <?php echo $DealNumber; ?>')" title="Завершить сделку">Завершить сделку</button></div>
						</div>
						<input type="text" class="hidden" name="DealDoneId" value="<?php echo $DealId; ?>" />
						<?php } elseif ( $Type == 'offer' ) { ?>
						<div class="input-group" style="width:100%;margin:0px 0px 10px 0px;">
							<span class="input-group-addon" style="width:50px;"><i class="fa fa-fw fa-handshake-o" aria-hidden="true"></i></span>
							<div class="input-group-btn" style="width:calc(100% - 50px);"><button class="btn btn-primary" style="width:100%;" type="submit" name="DealActive" onclick="return confirm('Добавить сделку <?php echo $DealNumber; ?>')" title="Перевести в сделку">Перевести в сделку</button></div>
						</div>
						<input type="text" class="hidden" name="DealActiveId" value="<?php echo $DealId; ?>" />
						<?php } ?>
						<div class="btn-group btn-group-justified" style="width:100%;margin:0px 0px 10px 0px;">
							<?php if ($GroupCheck == 'admin' or $GroupCheck == 'manager') { ?>
							<a href="/<?php echo $folder; ?>/deals/?edit=<?php echo $DealId; ?>" class="btn btn-default">Изменить</a>
							<?php } ?>
							<a href="javascript: ;" id="print" class="btn btn-default">На печать</a>
						</div>
					</form>
				</div>
			</div>
		</div>
		<div class="col-lg-9">
			
			<ul class="nav nav-tabs" id="admin-tabs">
				<li class="active"><a data-toggle="tab" href="#info">Информация</a></li>
				<li><a data-toggle="tab" href="#comment">Описание</a></li>
				<?php if ($Type == 'deal-a' OR $Type == 'deal-c') { ?>
				<li><a data-toggle="tab" href="#payments">Платежи (<?php echo count_payment("deal", $_GET["view"]);?>)</a></li>
				<?php } ?>
				<li><a data-toggle="tab" href="#tasks">Задачи (<?php echo count_task("deal", $_GET["view"]);?>)</a></li>
				<li><a data-toggle="tab" href="#files">Файлы (<?php echo count_dir_files($_GET['view']); ?>)</a></li>
			</ul>
			
			<div class="tab-content" id="to_print">
				<div id="info" class="tab-pane fade in active">
					<table class="table view_table_mobile" style="margin-bottom: 0px;">
						<tbody>
							<tr class="hide">
								<td><?php if($Type == 'deal-a'){echo 'Активная сделка';}elseif($Type == 'deal-c'){echo 'Завершенная сделка';}else{echo 'Коммерческое предложение';}?>:</td>
								<td><?php echo ' ' . $DealNumber;?></td>
							</tr>
							<tr>
								<td width="35%" style="border:none;"><i class="fa fa-fw fa-tag" aria-hidden="true"></i> Метка сделки:</td>
								<td style="border:none;"><?php if($Subject != ''){echo $Subject;}else{echo 'Нет данных';}?></td>
							</tr>
							<tr>
								<td><i class="fa fa-fw fa-address-book" aria-hidden="true"></i> Имя клиента:</td>
								<td> <?php echo '<a href="/'.$folder.'/clients/?view=' . $Client . '" target="_blank">' . get_client_name($Client) . '</a>';?></td>
							</tr>
							<tr>
								<td><i class="fa fa-fw fa-arrow-circle-o-up" aria-hidden="true"></i> Общая сумма сделки:</td>
								<td><b><?php if($Price != ''){echo conv_price( $Price , 'long' , '<i class="fa fa-sm fa-rub"></i>');}else{echo '0';}?></b> ( <?php if($deal_debt >= 0){ echo 'Неоплаченный статок: <b class="clr_vlow">' . conv_price( $deal_debt , 'long' , '<i class="fa fa-sm fa-rub"></i>'); } else { echo 'Оплата сверх договора: <b class="clr_low">+' . conv_price( $deal_sprofit , 'long' , '<i class="fa fa-sm fa-rub"></i>'); }?> )</td>
							</tr>
							<?php if ($Type != 'deal-o') { ?>
							<tr class="clr_red">
								<td><i class="fa fa-fw fa-arrow-circle-o-down" aria-hidden="true"></i> Сумма расходов:</td>
								<td><b><?php echo conv_price( deals_sum($_GET['view'], 'costs') , 'long' , '<i class="fa fa-sm fa-rub"></i>'); ?></b></td>
							</tr>
							<tr class="clr_green">
								<td><i class="fa fa-fw fa-arrow-circle-up" aria-hidden="true"></i> Сумма доходов:</td>
								<td><?php if($deal_debt >= 0){ echo '<b>' . conv_price( $deal_profit , 'long' , '<i class="fa fa-sm fa-rub"></i>'); } else { echo '<b>' . conv_price( $deal_profit + $deal_sprofit , 'long' , '<i class="fa fa-sm fa-rub"></i>'); }?></td></td>
							</tr>
							<?php } ?>
							<tr>
								<td><i class="fa fa-fw fa-calendar-plus-o" aria-hidden="true"></i> Дата добавления:</td>
								<td><?php if($DateStart != ''){echo $DateStart;}else{echo 'Нет данных';}?></td>
							</tr>
							<tr>
								<td><i class="fa fa-fw fa-calendar-check-o" aria-hidden="true"></i> Дата завершения:</td>
								<td><?php if($DateEnd != ''){echo $DateEnd;}else{echo 'Нет данных';}?></td>
							</tr>
						</tbody>
					</table>
				</div>
				<div id="comment" class="tab-pane fade">
					<form method="POST" name="form_deal" id="formedit" enctype="multipart/form-data">
						<div class="row" style="margin-top:0px;">
							<div class="form-group col-lg-12 editor-form">
								<textarea class="form-control " name="inputComment" id="inputComment" rows="10" cols="80" placeholder="Описание сделки"><?php if(isset($Comment)){echo $Comment;} ?></textarea>
							</div>
						</div>
						<button type="submit" name="SaveDescription" class="btn btn-md btn-info" style="color:#fff;"><i class="fa fa-fw fa-save" aria-hidden="true"></i> Сохранить описание</button>
					</form>
				</div>
				<?php if ($Type == 'deal-a' OR $Type == 'deal-c') { ?>
				<div id="payments" class="tab-pane fade">
					<div class="page_block" style="border:none;margin:0px 0px 20px 0px;">
						<div class="content" style="padding:0px;">
							<form method="POST">
								<div class="row">
									<div class="col-lg-5">
										<div class="input-group" style="width:auto;margin-bottom:10px;">
											<span class="input-group-addon">
												<input type="checkbox" value="yes" name="checkConfirm" id="checkConfirm" checked="checked"/>
												<label for="checkConfirm" title="Подтверждение платежа"><label>
											</span>
											<div class="input-group-btn">
												<select class="form-control" style="width:auto;" name="NewPaymentType">
													<option value="profit" class="clr_low" selected="">Доход</option>
													<option value="cost" class="clr_high">Расход</option>
												</select>
											</div>
											<input type="number" class="form-control" name="NewPayment" value="0" min="0" max="99999999" required>
											<span class="input-group-addon" style="padding: 3px 12px 1px 12px!important;">руб.</span>
										</div>
									</div>
									<div class="col-lg-3">
										<div class="input-group date-pick" style="position:relative;margin-bottom:15px;width:auto;">
											<span class="input-group-addon" style="padding:3px 12px!important;cursor:pointer;" title="Дата добавления"><i class="fa fa-fw fa-calendar-plus-o" aria-hidden="true"></i></span>
											<input type="text" class="form-control dateS" name="inputDateStart" placeholder="ГГГГ-ММ-ДД" value="<?php echo date("Y-m-d"); ?>" required />
										</div>
									</div>
									<div class="col-lg-3">
										<input style="margin-bottom:10px;" list="all-paymentscom" type="text" class="form-control" style="margin-bottom:15px;" name="NewPaymentComm" value="" placeholder="Комментарий">
										<datalist id="all-paymentscom">
											<?php
											$dox = new DOMDocument;
											$dox->load($baseP);
											$xpathx = new DOMXPath($dox);
											$alltagspayment = $xpathx->query('/payments/payment');
											$sourses_arr = array();
											$i = 0;
											foreach ($alltagspayment as $payment) {
												$listSourceName = $payment->getElementsByTagName("com")->item(0)->nodeValue;
												$countSource = count($xmlpayment->xpath('/payments/payment[com="'.$listSourceName.'"]'));
												$sourses_arr[$listSourceName] =  $countSource;
												$i++;
											}
											$sources = $sourses_arr;
											foreach ($sources as $key => $value){
												if($value > 0 and $key != ''){
														echo '<option value="' . $key . '"></option>';
												}
											}
											?>
										</datalist>
									</div>
									<div class="col-lg-1">
										<div class="btn-group btn-group-justified"  style="width:100%;margin-bottom:10px;">
											<button type="submit" name="AddPayment" style="width:100%;" class="btn btn-primary" style="color:#fff;"><i class="fa fa-fw fa-plus"></i><span class="hidden-md hidden-lg"> Добавить платеж</span</button>
										</div>
									</div>
								</div>
							</form>
						</div>
					</div>
					<div class="payments_list" style="padding-top:0px;">
						<?php require_once(ROOT . 'modules/deals/list-payments-m.php'); ?>
					</div>
				</div>
				<?php } ?>
				<div id="files" class="tab-pane fade">
					<?php if(isset($_GET['view'])) { require_once(ROOT . 'functions/func-upload-file.php'); } ?>
				</div>
				<div id="tasks" class="tab-pane fade">
					<div class="page_block" style="border:none;margin:0px 0px 0px 0px;">
						<div class="content" style="padding:0px;">
							<form method="POST">
								<div class="row">
									<div class="form-group col-lg-5">
										<div class="input-group" style="width:100%;">
											<select style="width:30%;" class="form-control" name="selectType">
												<option value="task" selected>Задача</option>
												<option value="call">Звонок</option>
												<option value="mail">Письмо</option>
												<option value="visit">Встреча</option>
											</select>
											<input style="width:70%;" type="text" class="form-control" name="inputName" value="" placeholder="Название задачи" maxlength="150" required>
										</div>
									</div>
									<div class="form-group col-lg-3">
										<div class="input-group">
											<span class="input-group-addon" style="padding:3px 12px!important;cursor:pointer;" title="Делегировано"><i class="fa fa-fw fa-user" aria-hidden="true"></i></span>
											<select class="form-control" name="selectUser" id="selectUser">
												<?php if (isset($Login) AND $LoginCheck == $Login or $GroupCheck != 'user') { ?><option value="">--- пусто ---</option><?php } ?>
												<?
													$dom = new DOMDocument;
													$dom->load(ROOT . '/crmdata/database/users.xml');
													$xpath = new DOMXPath($dom);
													$users = $xpath->query('/users/user');
													if($GroupCheck == 'guest'){
														$curentUserSurName		= $auth->getUserSurName();
														$curentUserName 		= mb_substr($auth->getUserName(), 0, 1,'utf-8').'.';
														echo '<option value="'.$LoginCheck.'">'.$curentUserName.' '.$curentUserSurName.'</option>';
													}elseif($GroupCheck == 'user'){
														foreach ($users as $user) {
															$UserSurName 	= $user->getElementsByTagName("usersurname")->item(0)->nodeValue;
															$UserName 		= mb_substr($user->getElementsByTagName("username")->item(0)->nodeValue, 0, 1,'utf-8').'.';
															$UserLogin 		= $user->getAttribute('login');
															$UserGroup 		= $user->getAttribute('group');
															if($UserGroup == 'user'){
																echo '<option value="'.$UserLogin.'">'.$UserName.' '.$UserSurName.'</option>';
															}
														}
													}else{
														foreach ($users as $user) {
															$UserSurName 	= $user->getElementsByTagName("usersurname")->item(0)->nodeValue;
															$UserName 		= mb_substr($user->getElementsByTagName("username")->item(0)->nodeValue, 0, 1,'utf-8').'.';
															$UserLogin 		= $user->getAttribute('login');
															echo '<option value="'.$UserLogin.'">'.$UserName.' '.$UserSurName.'</option>';
														}
													}
												?>
											</select>
											<input type="text" class="hidden" name="inputUserS" value="<?php if(isset($TaskUserS)){echo $TaskUserS;}?>"/>
										</div>
									</div>
									<div class="form-group col-lg-3">
										<div class="input-group date-pick" style="position:relative;margin-bottom:15px;width:auto;">
											<span class="input-group-addon" style="padding:3px 12px!important;cursor:pointer;" title="Дата завершения"><i class="fa fa-fw fa-calendar-check-o" aria-hidden="true"></i></span>
											<input type="text" class="form-control dateE" name="inputDateEnd" placeholder="ГГГГ-ММ-ДД" value="" autocomplete="off" required />
										</div>
									</div>
									<div class="form-group col-lg-1">
										<div class="btn-group btn-group-justified"  style="width:100%;margin-bottom:10px;">
											<button type="submit" name="TaskAdd" style="width:100%;" class="btn btn-primary" style="color:#fff;"><i class="fa fa-fw fa-plus"></i><span class="hidden-md hidden-lg"> Добавить задачу</span</button>
										</div>
									</div>
								</div>
							</form>
						</div>
					</div>
					<?php
					$dom = new DOMDocument;
					$dom->load($baseT);
					$xpath = new DOMXPath($dom);
					$tasks = $xpath->query('/tasks/task[@deal="'.$_GET["view"].'"]');
					?>
					<div class="table-responsive"> 
						<table id="informer-tasks" class="table table-hover all-tasks tasks-inwork" style="margin-bottom: 0px;">
							<thead> 
								<tr> 
									<th width="6%"></th> 
									<th width="52%">Наименование</th> 
									<th width="6%" title="Процент выполнения"><i class="fa fa-line-chart" aria-hidden="true"></i></th> 
									<th width="15%">Добавление</th>
									<th width="15%">Завершение</th>
									<th width="6%"></th>
								</tr> 
							</thead> 
							<tbody>
								<?php require_once(ROOT . 'modules/tasks/list-tasks-m-sm.php'); ?>
							</tbody>
						</table>
					</div>
					<?php if($tasks->length > 0){require_once(ROOT . 'templates/table-pager2.php');} ?>
				</div>
			</div>
		</div>
	</div>
</div>
