337 lines
26 KiB
PHP
Executable File

<?php
require_once('fixed/config/go_con.php');
access(30);
$today = date("Y-m-d");
if (!empty($_GET['date'])) {
$today = $_GET['date'];
if (DateTime::createFromFormat('Y-m-d', $today) == false) {
$today = date("Y-m-d");
}
}
$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-d', strtotime('+1 day', strtotime($today)));
$Previous = date('Y-m-d', strtotime('-1 day', strtotime($today)));
$Day = date('D', strtotime($today));
function Day_ar()
{
global $Day;
$find = array("Sat", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri");
$replace = array("السبت", "الأحد", "الإثنين", "الثلاثاء", "الأربعاء", "الخميس", "الجمعة");
$ar_day_format = $Day;
$Day_ar = str_replace($find, $replace, $ar_day_format);
return $Day_ar;
}
function Today_ar()
{
global $today;
$Today_ar = date('d-m-Y', strtotime($today));
return $Today_ar;
}
?>
<!DOCTYPE html>
<html lang="en" dir="rtl">
<?php require_once('fixed/head/go.php'); ?>
<body class="rtl">
<style>
tr {
border-color: #bfbbbb !important;
}
.table-bordered td, .table-bordered th {
border-color: #bfbbbb !important;
}
</style>
<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">
<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>
إيرادات يوم
<?= Day_ar() ?>
<br />
<?= Today_ar() ?>
</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="daily_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="daily_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 class="table table-bordered text-center" style="vertical-align: middle;">
<thead class="table-primary" style="vertical-align: middle;">
<tr>
<th rowspan="3" scope="col">#</th>
<th rowspan="3" scope="col">اسم الموظف</th>
<th rowspan="3" scope="col">الفرع</th>
<th rowspan="3" scope="col">النوع</th>
<th rowspan="3" scope="col">العمليات</th>
<th colspan="7" scope="col">إجمالي الفواتير</th>
<th colspan="3" rowspan="2" scope="col">المبلغ المودع</th>
<th rowspan="3" scope="col">العجز</th>
</tr>
<tr>
<th colspan="3" scope="col">الصادر</th>
<th rowspan="2">مرتجع إيراد</th>
<th rowspan="2" scope="col">المبلغ المستحق من الموظف</th>
<th rowspan="2" scope="col">من رصيد العملاء</th>
<th rowspan="2" scope="col">الاجمالي</th>
</tr>
<tr>
<th scope="col">كاش</th>
<th scope="col">شبكة</th>
<th scope="col">تحويل</th>
<th scope="col">كاش</th>
<th scope="col">شبكة</th>
<th scope="col">تحويل</th>
</tr>
</thead>
<tbody>
<?php
$_branch = array(2,3,4,5);
for ($i=0; $i < count($_branch); $i++) {
$branch_id = $_branch[$i];
$get_invoices_sql = mysqli_query($db,
"SELECT
`user`.`name`,
`user`.`id`,
(SELECT
`branch_name` FROM `branch`
WHERE `id` = $branch_id
) AS `branch_name`,
IFNULL(
(SELECT
COUNT(`invoices`.`id`) FROM `invoices`
WHERE (`invoices`.`date_time` LIKE '$today%') AND `invoices`.`user_id` = `user`.`id`
)
,0) AS `count`,
IFNULL(
(SELECT
SUM(`invoices_details_has_how_pay`.`pay`)
FROM `invoices_details_has_how_pay`
INNER JOIN `invoices_details` ON `invoices_details_has_how_pay`.`invoices_details_id` = `invoices_details`.`id`
WHERE `invoices_details_has_how_pay`.`how_pay_id` = 1
AND (`invoices_details`.`invoices_status_id` = 1 OR `invoices_details`.`invoices_status_id` = 2)
AND `invoices_details_has_how_pay`.`user_id` = `user`.`id`
AND `invoices_details_has_how_pay`.`date_time` LIKE '$today%'
AND `invoices_details`.`branch_id` = $branch_id
GROUP BY `how_pay_id`
)
, 0) AS `cash`,
IFNULL(
(SELECT
SUM(`invoices_details_has_how_pay`.`pay`)
FROM `invoices_details_has_how_pay`
INNER JOIN `invoices_details` ON `invoices_details_has_how_pay`.`invoices_details_id` = `invoices_details`.`id`
WHERE `invoices_details_has_how_pay`.`how_pay_id` = 2
AND (`invoices_details`.`invoices_status_id` = 1 OR `invoices_details`.`invoices_status_id` = 2)
AND `invoices_details_has_how_pay`.`user_id` = `user`.`id`
AND `invoices_details_has_how_pay`.`date_time` LIKE '$today%'
AND `invoices_details`.`branch_id` = $branch_id
GROUP BY `how_pay_id`
)
, 0) AS `card`,
IFNULL(
(SELECT
SUM(`invoices_details_has_how_pay`.`pay`)
FROM `invoices_details_has_how_pay`
INNER JOIN `invoices_details` ON `invoices_details_has_how_pay`.`invoices_details_id` = `invoices_details`.`id`
WHERE `invoices_details_has_how_pay`.`how_pay_id` = 3
AND (`invoices_details`.`invoices_status_id` = 1 OR `invoices_details`.`invoices_status_id` = 2)
AND `invoices_details_has_how_pay`.`user_id` = `user`.`id`
AND `invoices_details_has_how_pay`.`date_time` LIKE '$today%'
AND `invoices_details`.`branch_id` = $branch_id
GROUP BY `how_pay_id`
)
, 0) AS `stuck`,
IFNULL(
(SELECT
SUM(`invoices_details_has_how_pay`.`pay`)
FROM `invoices_details_has_how_pay`
INNER JOIN `invoices_details` ON `invoices_details_has_how_pay`.`invoices_details_id` = `invoices_details`.`id`
WHERE `invoices_details_has_how_pay`.`how_pay_id` = 1
AND (`invoices_details`.`invoices_status_id` = 3)
AND `invoices_details_has_how_pay`.`user_id` = `user`.`id`
AND `invoices_details_has_how_pay`.`date_time` LIKE '$today%'
AND `invoices_details`.`branch_id` = $branch_id
GROUP BY `how_pay_id`
)
, 0) AS `cash_back`,
IFNULL(
(SELECT
COUNT(`bonds`.`id`) FROM `bonds`
WHERE (`bonds`.`date_time` LIKE '$today%') AND `bonds`.`user_id` = `user`.`id`
)
, 0) AS `bond_count`,
IFNULL(
(SELECT
SUM(`bonds_details_has_how_pay`.`pay`)
FROM `bonds_details_has_how_pay`
INNER JOIN `bonds_details` ON `bonds_details_has_how_pay`.`bonds_details_id` = `bonds_details`.`id`
WHERE `bonds_details_has_how_pay`.`how_pay_id` = 1
AND (`bonds_details`.`bonds_status_id` = 1 OR `bonds_details`.`bonds_status_id` = 2)
AND `bonds_details_has_how_pay`.`user_id` = `user`.`id`
AND `bonds_details_has_how_pay`.`date_time` LIKE '$today%'
AND `bonds_details`.`branch_id` = $branch_id
GROUP BY `how_pay_id`
)
, 0) AS `bond_cash`,
IFNULL(
(SELECT
SUM(`bonds_details_has_how_pay`.`pay`)
FROM `bonds_details_has_how_pay`
INNER JOIN `bonds_details` ON `bonds_details_has_how_pay`.`bonds_details_id` = `bonds_details`.`id`
WHERE `bonds_details_has_how_pay`.`how_pay_id` = 2
AND (`bonds_details`.`bonds_status_id` = 1 OR `bonds_details`.`bonds_status_id` = 2)
AND `bonds_details_has_how_pay`.`user_id` = `user`.`id`
AND `bonds_details_has_how_pay`.`date_time` LIKE '$today%'
AND `bonds_details`.`branch_id` = $branch_id
GROUP BY `how_pay_id`
)
, 0) AS `bond_card`
FROM `user`
LEFT JOIN `emplyee` ON `user`.`emplyee_id` = `emplyee`.`id`
LEFT JOIN `branch` ON `emplyee`.`branch_id` = `branch`.`id`
HAVING (`count` <> 0 OR `bond_count` <> 0) AND (`cash` OR `card` OR `stuck` OR `cash_back` OR `bond_cash` OR `bond_card`)
");
$count = 1;
while ($get_invoices = mysqli_fetch_assoc($get_invoices_sql)) {
?>
<tr>
<th rowspan="3" scope="row"><?=$count?></th>
<td rowspan="3"><a href="daily_user_d?u=<?=$get_invoices['id']?>&d=<?=$today?>"><?=$get_invoices['name']?></a></td>
<td rowspan="3"><?=$get_invoices['branch_name']?></td>
<td>الفواتير</td>
<td><?=$get_invoices['count']?></td>
<td><?=round($get_invoices['cash'],2)?></td>
<td><?=round($get_invoices['card'],2)?></td>
<td></td>
<td><?=-round($get_invoices['cash_back'],2)?></td>
<td><b><?=round($get_invoices['cash'] + $get_invoices['card'] - $get_invoices['cash_back'],2)?></b></td>
<td><?=round($get_invoices['stuck'],2)?></td>
<td><?=round($get_invoices['cash'] + $get_invoices['card'] + $get_invoices['stuck'] - $get_invoices['cash_back'],2)?></td>
<td rowspan="2"></td>
<td rowspan="2"></td>
<td rowspan="2"></td>
<td></td>
</tr>
<tr>
<td>أرصدة دائنة - عملاء</td>
<td><?=$get_invoices['bond_count']?></td>
<td><?=round($get_invoices['bond_cash'],2)?></td>
<td><?=round($get_invoices['bond_card'],2)?></td>
<td></td>
<td><?=-round(0,2)?></td>
<td><b><?=round($get_invoices['bond_cash'] + $get_invoices['bond_card'],2)?></b></td>
<td>0</td>
<td><?=round($get_invoices['bond_cash'] + $get_invoices['bond_card'],2)?></td>
<td></td>
</tr>
<tr style="background:#e9f0ee; font-weight: bold;">
<td>المجاميع</td>
<td><?=$get_invoices['count'] + $get_invoices['bond_count']?></td>
<td><?=round($get_invoices['cash'] + $get_invoices['bond_cash'],2)?></td>
<td><?=round($get_invoices['card'] + $get_invoices['bond_card'],2)?></td>
<td></td>
<td>-<?=round($get_invoices['cash_back'] +0,2)?></td>
<td style="background: springgreen;"><?=round($get_invoices['cash'] + $get_invoices['bond_cash'] + $get_invoices['card'] + $get_invoices['bond_card'] - $get_invoices['cash_back'],2)?></td>
<td><?=round($get_invoices['stuck'],2)?></td>
<td><?=round(($get_invoices['cash'] + $get_invoices['card'] + $get_invoices['stuck'] - $get_invoices['cash_back']) + $get_invoices['bond_cash'] + $get_invoices['bond_card'],2)?></td>
<td colspan="3"></td>
<td></td>
</tr>
<?php
$count++;
}
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php require_once('fixed/footer/go.php'); ?>
</div>
</div>
<?php require_once('fixed/js/go.php'); ?>
<script>
$("#Select-date").change(function() {
var SelectedDate = $(this).val();
window.location = 'daily_user.php?branch=<?= $branch_id ?>&date=' + SelectedDate
});
</script>
</body>
</html>