booking/work/files/old/month_user11092022.php
2025-03-24 19:02:58 +03:00

230 lines
16 KiB
PHP

<?php
require_once('fixed/config/go_con.php');
access(50);
$today = date("Y-m");
if (!empty($_GET['date'])) {
$today = $_GET['date'];
if (DateTime::createFromFormat('Y-m', $today) == false) {
$today = date("Y-m");
}
}
$branch_id = $_SESSION['branch'];
if (!empty($_GET['branch'])) {
$branch_id = $_GET['branch'];
if (!is_numeric($branch_id)) {
$branch_id = $_SESSION['branch'];
}
}
$branch_sql = '`branch_id`='.$branch_id;
if ($branch_id == 1) {
$branch_sql = '`branch_id`<>'.$branch_id;
}
$Next = date('Y-m', strtotime('+1 month', strtotime($today)));
$Previous = date('Y-m', strtotime('-1 month', strtotime($today)));
?>
<!DOCTYPE html>
<html lang="en" dir="rtl">
<?php require_once('fixed/head/go.php'); ?>
<body class="rtl">
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/@mdi/font@6.5.95/css/materialdesignicons.min.css">
<?php require_once('fixed/loader/go.php'); ?>
<!-- page-wrapper Start-->
<div class="page-wrapper" id="pageWrapper">
<?php require_once('fixed/header/go.php'); ?>
<!-- Page Body Start-->
<div class="page-body-wrapper">
<?php require_once('fixed/sidebar/go.php'); ?>
<div class="page-body">
<!-- Container-fluid starts-->
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body new-user order-list text-center">
<div class="row">
<div class="col-12 col-sm-12 col-md-3 col-lg-4 col-xl-4">
</div>
<div class="page-title mb-3 col-12 col-sm-12 col-md-6 col-lg-4 col-xl-4">
<i class="mdi mdi-monitor mr-2">
</i>
<h4>
إيرادات شهر
<br/>
<?=$today?>
</h4>
</div>
<div class="col-12 col-sm-12 col-md-3 col-lg-4 col-xl-4">
</div>
</div>
<div class="row">
<div class="col-12 col-sm-12 col-md-2 col-lg-3 col-xl-3">
</div>
<div class="col-2 col-sm-2 col-md-1 col-lg-1 col-xl-1">
<a class="btn btn-danger btn-round waves-effect waves-light col-12" href="month_user.php?date=<?= $Previous ?>&branch=<?= $branch_id ?>" style="padding: 0.375rem 0.75rem;">-</a>
</div>
<div class="col-8 col-sm-8 col-md-6 col-lg-4 col-xl-4">
<input id="Select-date" class="form-control" type="date" value="" style="text-align: center !important;">
</div>
<div class="col-2 col-sm-2 col-md-1 col-lg-1 col-xl-1">
<a class="btn btn-primary btn-round waves-effect waves-light col-12" href="month_user.php?date=<?= $Next ?>&branch=<?= $branch_id ?>" style="padding: 0.375rem 0.75rem;">+</a>
</div>
<div class="col-12 col-sm-12 col-md-2 col-lg-3 col-xl-3">
</div>
</div>
</div>
<div class="tab-content">
<div class="tab-pane p-3 active" id="tab<?=$tabs?>" role="tabpanel">
<div class="card-body new-user order-list">
<div class="table-responsive">
<table id="employee_data" class="table table-bordered text-center" style="vertical-align: middle;">
<thead class="table-primary" style="vertical-align: middle;">
<tr>
<th rowspan="2" scope="col">التاريخ</th>
<th colspan="5" scope="col">فرع النسائي</th>
</tr>
<tr>
<th scope="col">أرصدة دائنة - عملاء</th>
<th scope="col">إجمالي الفواتير</th>
<th scope="col">ضريبة</th>
<th scope="col">صافي</th>
</tr>
</thead>
<tbody>
<?php
$get_bonds_sql = mysqli_query($db,
"SELECT
SUM(`bonds`.`price`) AS `price`,
DATE(`bonds`.`date_time`) AS `date`
FROM `bonds`
LEFT JOIN `bonds_details` ON `bonds_details`.`bonds_id` = `bonds`.`id`
WHERE `bonds_details`.`branch_id` = 5
AND `bonds`.`date_time` LIKE '$today%'
GROUP BY `date`
ORDER BY `date` ASC
");
$temp_bonds = array();
while ($get_bonds = mysqli_fetch_assoc($get_bonds_sql)) {
array_push($temp_bonds, $get_bonds);
}
$temp_count = 0;
$get_invoices_sql = mysqli_query($db,
"SELECT
COUNT(`invoices`.`id`) AS `count`,
SUM(`invoices`.`price`) AS `total`,
SUM(`invoices`.`price_cut`) AS `total_cut`,
DATE(`invoices`.`date_time`) AS `date`
FROM `invoices`
LEFT JOIN `invoices_details` ON `invoices_details`.`invoices_id` = `invoices`.`id`
LEFT JOIN `user` ON `invoices`.`user_id` = `user`.`id`
LEFT JOIN `emplyee` ON `user`.`emplyee_id` = `emplyee`.`id`
LEFT JOIN `branch` ON `emplyee`.`branch_id` = `branch`.`id`
WHERE `branch`.`id` = 5
AND `invoices`.`date_time` LIKE '$today%'
GROUP BY `date`
ORDER BY `date` ASC
");
$count = 1;
$toooot1 = 0;
$toooot3 = 0;
$toooot4 = 0;
$toooot5 = 0;
while ($get_invoices = mysqli_fetch_assoc($get_invoices_sql)) {
?>
<tr>
<td><a href="invoice_day.php?date=<?=$get_invoices['date']?>"><?=$get_invoices['date']?></a></td>
<td>
<?php
if ($get_invoices['date'] == $temp_bonds[$temp_count]['date']) {
echo round($temp_bonds[$temp_count]['price'],2);
$toooot1 += round($temp_bonds[$temp_count]['price'],2);
} else {
echo '0';
}
?>
</td>
<td><?=round($get_invoices['total'],2)?></td>
<td><?=round(($get_invoices['total'] - ($get_invoices['total']/1.15)),2)?></td>
<td><?=round($get_invoices['total'] - ($get_invoices['total'] - ($get_invoices['total']/1.15)),2)?></td>
</tr>
<?php
if ($get_invoices['date'] == $temp_bonds[$temp_count]['date']) {
$temp_count++;
}
$toooot3 += round(($get_invoices['total'] - ($get_invoices['total']/1.15)),2);
$toooot4 += round($get_invoices['total'] - ($get_invoices['total'] - ($get_invoices['total']/1.15)),2);
$toooot6 += round($get_invoices['total'],2);
$count++;
}
$toooot5 += ($toooot1 + $toooot6);
?>
<tr>
<td rowspan="2">إجمالي المتحصلات</td>
<td><?=$toooot1?></td>
<td><?=$toooot6?></td>
<td rowspan="2"><?=$toooot3?></td>
<td rowspan="2"><?=$toooot4?></td>
</tr>
<tr>
<td colspan="2"><?=$toooot5?></td>
</tr>
</tbody>
</table>
<button type="button" id="export_button" class="btn btn-success btn-sm">ملف excel</button>
</div>
</div>
</div>
</div>
<!--end card-body-->
</div>
<!--end card-->
</div>
</div>
</div>
<!-- Container-fluid Ends-->
</div>
<?php require_once('fixed/footer/go.php'); ?>
</div>
</div>
<?php require_once('fixed/js/go.php'); ?>
<script type="text/javascript" src="https://unpkg.com/xlsx@0.15.1/dist/xlsx.full.min.js"></script>
<script>
$("#Select-date").change(function() {
var SelectedDate = $(this).val();
window.location = 'month_user.php?branch=<?= $branch_id ?>&date=' + SelectedDate
});
function html_table_to_excel(type)
{
var data = document.getElementById('employee_data');
var file = XLSX.utils.table_to_book(data, {sheet: "sheet1"});
XLSX.write(file, { bookType: type, bookSST: true, type: 'base64' });
XLSX.writeFile(file, 'ايراد الفرع.' + type);
}
const export_button = document.getElementById('export_button');
export_button.addEventListener('click', () => {
html_table_to_excel('xlsx');
});
</script>
</body>
</html>