451 lines
31 KiB
PHP
Executable File

<?php
require_once('fixed/config/go_con.php');
access(31);
$today = date("Y-m");
if (!empty($_GET['date'])) {
$today = $_GET['date'];
if (DateTime::createFromFormat('Y-m', $today) == false) {
$today = date("Y-m");
}
}
$Next = date('Y-m', strtotime('+1 month', strtotime($today)));
$Previous = date('Y-m', strtotime('-1 month', strtotime($today)));
$frist_day = date('Y-m-d', strtotime($today));
$last_day = date("Y-m-t", strtotime($frist_day));
$c_r_id = $_GET['c'];
if (!empty($_GET['c'])) {
$c_r_id = $_GET['c'];
if (!is_numeric($c_r_id)) {
$c_r_id = 1;
}
} else {
$c_r_id = 1;
}
$c_r_id_sql = '='.$c_r_id;
if ($c_r_id == 1) {
$c_r_id_sql = '<>'.$c_r_id;
}
$branch_id = $_GET['b'];
if (!empty($_GET['b'])) {
$branch_id = $_GET['b'];
if (!is_numeric($branch_id)) {
$branch_id = 1;
}
} else {
$branch_id = 1;
}
if (!empty($_GET['f'])) {
if (is_numeric($c_r_id) && $_GET['f'] == 1) {
$branch_id = 1;
}
}
$branch_sql = '='.$branch_id;
if ($branch_id == 1) {
$branch_sql = '<>'.$branch_id;
}
$data = array();
$get_invoices_sql = mysqli_query($db,
"SELECT `r_month_user_invoices`.`filter`, `r_month_user_invoices`.`total`, `r_month_user_invoices`.`invoices_status_id`, `r_month_user_invoices`.`how_pay_id` FROM `r_month_user_invoices`
INNER JOIN `branch` ON `branch`.`id` = `r_month_user_invoices`.`branch_id`
WHERE DATE_FORMAT(`r_month_user_invoices`.`filter`, '%Y-%m') = '$today'
AND `r_month_user_invoices`.`branch_id` $branch_sql
AND `branch`.`commercial_register_id` $c_r_id_sql
AND `branch`.`commercial_register_id` <> 5
");
while ($get_invoices = mysqli_fetch_assoc($get_invoices_sql)) {
switch ($get_invoices['invoices_status_id']) {
case '1': case '2':
switch ($get_invoices['how_pay_id']) {
case '1':
$data['inv'][$get_invoices['filter']]['cash'] += $get_invoices['total'];
break;
case '2':
$data['inv'][$get_invoices['filter']]['card'] += $get_invoices['total'];
break;
case '3':
$data['inv'][$get_invoices['filter']]['stuck'] += $get_invoices['total'];
break;
}
break;
case '3':
switch ($get_invoices['how_pay_id']) {
case '1':
$data['back'][$get_invoices['filter']]['cash'] += $get_invoices['total'];
break;
case '2':
$data['back'][$get_invoices['filter']]['card'] += $get_invoices['total'];
break;
case '3':
$data['back'][$get_invoices['filter']]['stuck'] += $get_invoices['total'];
break;
}
break;
case '4':
echo"<script>alert('hi')</script>";
break;
}
}
$get_invoices_sql = mysqli_query($db,
"SELECT `r_month_user_bonds`.`filter`, `r_month_user_bonds`.`total`, `r_month_user_bonds`.`bonds_status_id`, `r_month_user_bonds`.`how_pay_id` FROM `r_month_user_bonds`
INNER JOIN `branch` ON `branch`.`id` = `r_month_user_bonds`.`branch_id`
WHERE DATE_FORMAT(`r_month_user_bonds`.`filter`, '%Y-%m') = '$today'
AND `r_month_user_bonds`.`branch_id` $branch_sql
AND `branch`.`commercial_register_id` $c_r_id_sql
AND `branch`.`commercial_register_id` <> 5
");
while ($get_invoices = mysqli_fetch_assoc($get_invoices_sql)) {
switch ($get_invoices['bonds_status_id']) {
case '1': case '2':
switch ($get_invoices['how_pay_id']) {
case '1':
$data['bonds'][$get_invoices['filter']]['cash'] += $get_invoices['total'];
break;
case '2':
$data['bonds'][$get_invoices['filter']]['card'] += $get_invoices['total'];
break;
case '3':
$data['bonds'][$get_invoices['filter']]['stuck'] += $get_invoices['total'];
break;
}
break;
case '3':
switch ($get_invoices['how_pay_id']) {
case '1':
$data['bond_back'][$get_invoices['filter']]['cash'] += $get_invoices['total'];
break;
case '2':
$data['bond_back'][$get_invoices['filter']]['card'] += $get_invoices['total'];
break;
case '3':
$data['bond_back'][$get_invoices['filter']]['stuck'] += $get_invoices['total'];
break;
}
break;
case '4':
echo"<script>alert('erorr')</script>";
break;
}
}
?>
<!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 col-sm-12 col-md-12 col-lg-2 col-xl-2">
<div class="card">
<div class="card-body new-user order-list profile-nav">
<div class="nav flex-column nav-pills" id="profile-tab" aria-orientation="vertical">
<a class="nav-link mb-0 <?php if($c_r_id == 1){echo 'active';}?> ?>" data-toggle="pill" href="#cr_1" aria-selected="false" onclick="window.location='month_user?date=<?=$today?>&b=<?=$branch_id?>&c=1&f=1'">الكل</a>
<a class="nav-link mb-0 <?php if($c_r_id == 2){echo 'active';}?> ?>" data-toggle="pill" href="#cr_2" aria-selected="false" onclick="window.location='month_user?date=<?=$today?>&b=<?=$branch_id?>&c=2&f=1'">القسم الرجالي</a>
<a class="nav-link mb-0 <?php if($c_r_id == 3){echo 'active';}?> ?>" data-toggle="pill" href="#cr_3" aria-selected="false" onclick="window.location='month_user?date=<?=$today?>&b=<?=$branch_id?>&c=3&f=1'">القسم النسائي</a>
<a class="nav-link mb-0 <?php if($c_r_id == 4){echo 'active';}?> ?>" data-toggle="pill" href="#cr_4" aria-selected="false" onclick="window.location='month_user?date=<?=$today?>&b=<?=$branch_id?>&c=4&f=1'">القسم الزيارات</a>
<a class="nav-link mb-0 <?php if($c_r_id == 5){echo 'active';}?> ?>" data-toggle="pill" href="#cr_5" aria-selected="false" onclick="window.location='month_user?date=<?=$today?>&b=<?=$branch_id?>&c=5&f=1'">القسم الطبيعي</a>
</div>
</div>
</div>
<div class="card">
<div class="card-body new-user order-list profile-nav">
<div class="nav flex-column nav-pills" id="profile-tab" aria-orientation="vertical">
<?php
$commercial_register_sql = mysqli_query($db, "SELECT `branch`.`branch_name`, `branch`.`id`
FROM `commercial_register`
LEFT JOIN `branch` ON `commercial_register`.`id` = `branch`.`commercial_register_id`
WHERE `commercial_register`.`id` $c_r_id_sql
OR `branch`.`id` = 1
");
while ($commercial_register = mysqli_fetch_assoc($commercial_register_sql)) {
?>
<a class="nav-link mb-0 <?php if($branch_id == $commercial_register['id']){echo 'active';}?> ?>" data-toggle="pill" href="#branch-<?=$commercial_register['id']?>" aria-selected="false" onclick="window.location='month_user?date=<?=$today?>&b=<?=$commercial_register['id']?>&c=<?=$c_r_id?>'"><?=$commercial_register['branch_name']?></a>
<?php
}
?>
</div>
</div>
</div>
</div>
<div class="col-12 col-sm-12 col-md-12 col-lg-10 col-xl-10">
<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?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?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 id="refrish" class="form-control" style="background-color: #086367; color:white; text-align:center; cursor: pointer;">طلب التقرير</div>
</div>
</div>
</div>
<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="2" scope="col">التاريخ</th>
<th rowspan="2" scope="col">البيان</th>
<th colspan="4" scope="col">المتحصلات اليومية</th>
<th colspan="4" 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>
<th scope="col">إيرادات مرتجعة ( فاتورة مرتجعات )</th>
<th scope="col">إجمالي الإيرادات</th>
</tr>
</thead>
<tbody>
<?php
$t1 = 0;
$t2 = 0;
$t3 = 0;
$t4 = 0;
$t5 = 0;
$t6 = 0;
$t7 = 0;
$t8 = 0;
$t9 = 0;
while ($frist_day <= $last_day) {
$nothing_for_now = 0;
$inv_cash = round($data['inv'][$frist_day]['cash'],2);
$inv_card = round($data['inv'][$frist_day]['card'],2);
$inv_cash_card = round($data['inv'][$frist_day]['cash'] + $data['inv'][$frist_day]['card'],2);
// $inv_total = round(round($data['inv'][$frist_day]['cash'],2) + round($data['inv'][$frist_day]['card'],2),2);
$inv_stuck = round($data['inv'][$frist_day]['stuck'],2);
$back_cash = round(($data['back'][$frist_day]['cash']),2);
$back_card = round($data['back'][$frist_day]['card'],2);
$back_cash_card = round(($data['back'][$frist_day]['card']+$data['back'][$frist_day]['cash']),2);
$back_stuck = round($data['back'][$frist_day]['stuck'],2);
$back_total = round(($data['back'][$frist_day]['cash'] + $data['back'][$frist_day]['card'] + $data['back'][$frist_day]['stuck']),2);
$inv_total = round(($inv_cash_card + $inv_stuck) - $back_total,2);
$inv_free_vat_total = round((($inv_cash_card + $inv_stuck) - $back_total) - ((($inv_cash_card + $inv_stuck) - $back_total) - ((($inv_cash_card + $inv_stuck) - $back_total)/1.15)),2);
$bonds_cash = round($data['bonds'][$frist_day]['cash'],2);
$bonds_card = round($data['bonds'][$frist_day]['card'],2);
$bonds_cash_card = round($data['bonds'][$frist_day]['cash'] + $data['bonds'][$frist_day]['card'],2);
$inv_bonds_cash = round($data['inv'][$frist_day]['cash'] + $data['bonds'][$frist_day]['cash'],2);
$inv_bonds_card = round($data['inv'][$frist_day]['card'] + $data['bonds'][$frist_day]['card'],2);
$inv_bonds_total = round($data['inv'][$frist_day]['cash'] + $data['bonds'][$frist_day]['cash'] + $data['inv'][$frist_day]['card'] + $data['bonds'][$frist_day]['card'],2);
?>
<tr>
<th rowspan="4" scope="row"><?=$frist_day?></th>
<td>فواتير</td>
<td><?=$inv_cash?></td>
<td><?=$inv_card?></td>
<td><?=$nothing_for_now?></td>
<td style="background:#e9f0ee;"><b><?=$inv_cash_card?></b></td>
<td rowspan="4"><?=$inv_cash_card?></td>
<td rowspan="4"><?=$inv_stuck?></td>
<td rowspan="4"><?=-$back_total?></td>
<td rowspan="4" style="background:#e9f0ee;"><?=$inv_total?></td>
<td rowspan="4" style="background:#fbf9e7;"><?=$inv_free_vat_total?></td>
</tr>
<tr>
<td>أرصدة دائنة للعملاء</td>
<td><?=$bonds_cash?></td>
<td><?=$bonds_card?></td>
<td><?=$nothing_for_now?></td>
<td style="background:#e9f0ee;"><b><?=$bonds_cash_card?></b></td>
</tr>
<tr>
<td>إيرادات مرتجعة</td>
<td><?=-$back_cash?></td>
<td><?=$back_card?></td>
<td><?=$nothing_for_now?></td>
<td style="background:#e9f0ee;"><b><?=-$back_cash_card?></b></td>
</tr>
<tr style="background:#e9f0ee; font-weight: bold;">
<td>مجموع</td>
<td><?=$inv_bonds_cash - ($back_cash)?></td>
<td><?=$inv_bonds_card - ($back_card)?></td>
<td><?=$nothing_for_now?></td>
<td style="background:#e9f0ee;"><b><?=$inv_bonds_total - ($back_cash_card)?></b></td>
</tr>
<?php
$t1 += $data['inv'][$frist_day]['cash'] + $data['bonds'][$frist_day]['cash'] - ($data['back'][$frist_day]['cash'] + $data['back'][$frist_day]['card'] + $data['back'][$frist_day]['stuck']);
$t2 += $data['inv'][$frist_day]['card'] + $data['bonds'][$frist_day]['card'];
$t3 += 0;
$t4 += ($data['inv'][$frist_day]['cash'] + $data['inv'][$frist_day]['card']) + ($data['bonds'][$frist_day]['cash'] + $data['bonds'][$frist_day]['card']) - ($data['back'][$frist_day]['cash'] + $data['back'][$frist_day]['card'] + $data['back'][$frist_day]['stuck']);
$t5 += $data['inv'][$frist_day]['cash'] + $data['inv'][$frist_day]['card'];
$t6 += $data['inv'][$frist_day]['stuck'];
$t7 += ($data['back'][$frist_day]['cash'] + $data['back'][$frist_day]['card'] + $data['back'][$frist_day]['stuck']);
$t8 +=
(
$data['inv'][$frist_day]['cash'] +
$data['inv'][$frist_day]['card'] +
$data['inv'][$frist_day]['stuck']
)
-
(
$data['back'][$frist_day]['cash'] +
$data['back'][$frist_day]['card'] +
$data['back'][$frist_day]['stuck']
);
$t9 +=
(
(
$data['inv'][$frist_day]['cash'] +
$data['inv'][$frist_day]['card'] +
$data['inv'][$frist_day]['stuck']
)
-
(
$data['back'][$frist_day]['cash'] +
$data['back'][$frist_day]['card'] +
$data['back'][$frist_day]['stuck']
)
)
-
(
(
(
$data['inv'][$frist_day]['cash'] +
$data['inv'][$frist_day]['card'] +
$data['inv'][$frist_day]['stuck']
)
-
(
$data['back'][$frist_day]['cash'] +
$data['back'][$frist_day]['card'] +
$data['back'][$frist_day]['stuck']
)
)
-
(
(
(
$data['inv'][$frist_day]['cash'] +
$data['inv'][$frist_day]['card'] +
$data['inv'][$frist_day]['stuck']
)
-
(
$data['back'][$frist_day]['cash'] +
$data['back'][$frist_day]['card'] +
$data['back'][$frist_day]['stuck']
)
)
/1.15
)
);
$frist_day = date('Y-m-d', strtotime('+1 day', strtotime($frist_day)));
}
?>
<tr>
<td colspan="2">المجموع الكلي</td>
<td><?=round($t1,2)?></td>
<td><?=round($t2,2)?></td>
<td><?=round($t3,2)?></td>
<td><?=round($t4,2)?></td>
<td><?=round($t5,2)?></td>
<td><?=round($t6,2)?></td>
<td><?=round(-$t7,2)?></td>
<td><?=round($t8,2)?></td>
<td><?=round($t9,2)?></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php require_once('fixed/footer/go.php'); ?>
</div>
<div id="get_data"></div>
</div>
<?php require_once('fixed/js/go.php'); ?>
<script>
$("#Select-date").change(function() {
var SelectedDate = $(this).val();
window.location = 'month_user?branch=<?= $branch_id ?>&date=' + SelectedDate
});
</script>
<script>
// for limit clicks
click = 0;
// refrish
$(function() {
$("#refrish").click(function() {
refrish();
});
});
function refrish() {
date = <?=json_encode($today)?>;
if (click == 0) {
click++;
$.post("work/order/ajax/r_month_user_ajax.php", {
date
}, function(get_tretment) {
$("#get_data").html(get_tretment);
})
} else {
swalfun("يرجى الانتظار", "", "warning");
}
}
</script>
</body>
</html>