<?php require_once('../../ortaklar.php'); ?>

<?php 
if(!$account = get_account($_GET['id'])) {
	add_console_log('Hesap kartı bulunamadı.', 'print-statement.php');
}
?>
<?php include_content_page('print', 'statement', 'account', array('account'=>@$account)); ?>


<title>Cari Ekstre | <?php echo $account->name; ?></title>

<?php 
	$print['title'] = 'CARI EKSTRE';
	$print['date']	= til_get_date(date('Y-m-d H:i'), 'd F Y H:i');
	$print['barcode'] = $account->code;
?>
<?php get_header_print($print); ?>


<div class="row">
	<div class="col-xs-6">

		<div class="p-10 br-3">
			<div class="fs-14 bold"><?php echo til()->company->name; ?></div>
			<div class="fs-11"><?php echo til()->company->address; ?></div>
			<div class="fs-11"><?php echo til()->company->district; ?><?php echo til()->company->city ? '/' : ''; ?><?php echo til()->company->city; ?><?php echo til()->company->country ? ' - ' : ''; ?><?php echo til()->company->country; ?></div>
			<div class="fs-11"><?php echo get_set_show_phone(til()->company->phone); ?></div>
			<div class="fs-11"><?php echo til()->company->email; ?></div>
		</div>
	
	</div> <!-- /.col -->
	<div class="col-xs-6">

		<div class="bg-gray p-10 br-3">
			<div class="fs-14 bold"><?php echo $account->name; ?></div>
			<div class="fs-11"><?php echo $account->address; ?></div>
			<div class="fs-11"><?php echo $account->district; ?><?php echo ($account->city && $account->district) ? '/' : ''; ?><?php echo $account->city; ?><?php echo $account->country ? ' - ' : ''; ?><?php echo $account->country; ?></div>
			<div class="fs-11"><?php echo get_set_show_phone($account->gsm); ?><?php echo $account->phone ? ' - ' : ''; ?><?php echo get_set_show_phone($account->phone); ?></div>
			<div class="fs-11"><?php echo $account->tax_home ? 'V. Dairesi: '.$account->tax_home : ''; ?> <?php echo ($account->tax_home and $account->tax_no) ? ' - ': ''; ?> <?php echo $account->tax_no ? 'V. No: '.$account->tax_no : ''; ?></div>
			<?php if($account->email): ?><div class="fs-11"><?php echo $account->email; ?></div><?php endif; ?>
		</div>

	</div> <!-- /.col -->
</div> <!-- /.row -->



<?php
$args_form['where']['status'] = '1';
$args_form['where']['account_id'] = $account->id;
$args_form['where']['order_by'] = array('id'=>'ASC', 'date'=>'ASC');
if($forms = get_forms($args_form)): ?>
	<div class="h-20"></div>
	<table class="table table-hover table-bordered table-condensed table-striped">
		<thead>
			<tr>
				<th width="80">Form ID</th>
				<th width="100">Tarih</th>
				<th>Açıklama</th>
				<th width="80">Giriş</th>
				<th width="80">Çıkış</th>
				<th width="80">Bakiye</th>
			</tr>
		</thead>
		<tbody>
		<?php $balance = 0; foreach($forms->list as $form): ?>
			<?php $form_status = get_form_status($form->status_id); ?>
			<tr>
				<td>#<?php echo $form->id; ?></td>
				<td><small class="text-muted"><?php echo substr($form->date,0,16); ?></small></td>

				<td class="text-muted fs-11">
					<?php
                    if($form->type=='form') {
                        echo '
                                    <div >';
                        $form_items = get_form_items($form->id);
                        echo ' <style>table thead tr.border-none td { border:0px !important; }</style>
                                    <table class="table table-condensed table-striped table-hover table-bordered">
                                        <thead>
                                        <tr class="border-none">
                                            <td width="30%">
                                                <div class="form-group">
                                                    <label for="item_name"><span class="visible-xs">Adı</span><span class="hidden-xs">Ürün/Hizmet Adı</span></label>
                                                </div> <!-- /.form-group -->
                                            </td>
                                            <td>
                                                <div class="form-group">
                                                    <label for="quantity">Adet</label>
                                                </div> <!-- /.form-group -->
                                            </td>
                                            <td>
                                                <div class="form-group">
                                                    <label for="price">B.Fiyatı</label>
                                                </div> <!-- /.form-group -->
                                            </td>
                                            <td class="hidden-xs">
                                                <div class="form-group">
                                                    <label for="total">Tutar</label>
                                                </div> <!-- /.form-group -->
                                            </td>
                                            <td width="5%" class="hidden-xs">
                                                <div class="form-group">
                                                    <label for="item_vat">KDV</label>
                                                </div> <!-- /.form-group -->
                                            </td>
                                            <td width="10%" class="hidden-xs">
                                                <div class="form-group">
                                                    <label for="vat_total"><span class="hidden-xs">KDV Tutarı</span><span class="visible-xs fs-11">KDV Tutarı</span></label>
                                                </div> <!-- /.form-group -->
                                            </td>
                                            <td>
                                                <div class="form-group">
                                                    <label for="col_total"><span class="hidden-xs">Toplamı</span><span class="visible-xs">Toplam</span></label>
                                                </div> <!-- /.form-group -->
                                            </td>
                                        </tr>
                                        </thead>
                                        <tbody>
								    ';
                        if($form_items):$total_vat = 0;
                            foreach($form_items->list as $item):
                                echo   '<tr class="'; @$_GET['flashItemID'] == $item->item_id ? 'flashItemID' : ''; echo '">';
                                echo  '<td>'; echo $item->item_name;echo'</td>';
                                echo  '<td class="text-center">';echo $item->quantity;echo'</td>';
                                echo  '<td class="text-right">';echo get_set_money($item->price, true);echo'</td>';
                                echo    '<td class="text-right hidden-xs">';echo get_set_money($item->total, true);echo'</td>';
                                echo    '<td class="text-center text-muted hidden-xs">'; echo $item->vat;echo'</td>';
                                echo     '<td class="text-right text-muted hidden-xs">';echo get_set_money($item->vat_total, true);echo '</td>';
                                echo      '<td class="text-right">';echo get_set_money($item->total, true);echo'</td>
                    </tr>';
                                $total_vat = $total_vat + $item->vat_total;
                            endforeach;
                        endif;
                        echo '</tbody>
                    </table>
                    </div>' ;
						if($form->in_out == '0') { echo 'Giriş formu: '.$form->item_quantity.' adet ürün'; } else { echo 'Çıkış formu: '.$form->item_quantity.' adet ürün'; }
					} elseif($form->type=='payment') {
						if($form->in_out == '0') { echo 'Ödeme girişi'; } else { echo 'Ödeme çıkışı'; }	
					}
					?>
				</td>
				<td class="text-right"><?php if($form->in_out == 0) { echo get_set_money($form->total, true); $balance = $balance - $form->total; } else { echo ''; } ?></td>
				<td class="text-right"><?php if($form->in_out == 1) { echo get_set_money($form->total, true); $balance = $balance + $form->total; } else { echo ''; } ?></td>
				<td class="text-right"><?php echo get_set_money($balance, true); ?></td>
			</tr>
		<?php endforeach; ?>
		</tbody>
		<tfoot>
			<tr>
				<th colspan="7" class="text-right"><?php echo get_set_money($balance, true); ?></th>
			</tr>
		</tfoot>
	</table>
<?php endif; ?>

<?php get_footer_print(); ?>