304 lines
15 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));
$branch_id = $_GET['b'];
if (!empty($_GET['b'])) {
$branch_id = $_GET['b'];
if (!is_numeric($branch_id)) {
$branch_id = 1;
}
} else {
$branch_id = 1;
}
$branch_sql = '='.$branch_id;
if ($branch_id == 1) {
$branch_sql = '<>'.$branch_id;
}
$data = array(
'totals' => array(
'inv' => 0,
'bonds' => 0,
)
);
$get_invoices_sql = mysqli_query($db,
"SELECT `filter`, `branch_id`, SUM(`total`) AS `total` FROM `r_bonds_int_dec_invoices`
WHERE `branch_id` $branch_sql
AND DATE_FORMAT(`filter`, '%Y-%m') < '$today'
");
while ($get_invoices = mysqli_fetch_assoc($get_invoices_sql)) {
$data['totals']['inv'] += $get_invoices['total'];
}
$get_invoices_sql = mysqli_query($db,
"SELECT `filter`, `branch_id`, `total`, `bonds_status_id`, `how_pay_id` FROM `r_month_user_bonds`
WHERE `branch_id` $branch_sql
AND DATE_FORMAT(`filter`, '%Y-%m') < '$today'
");
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['totals']['bonds'] += $get_invoices['total'];
break;
case '2':
$data['totals']['bonds'] += $get_invoices['total'];
break;
}
break;
case '3':
switch ($get_invoices['how_pay_id']) {
case '1':
$data['totals']['bonds'] -= $get_invoices['total'];
break;
}
break;
case '4':
echo"<script>alert('hi')</script>";
break;
}
}
$get_invoices_sql = mysqli_query($db,
"SELECT `filter`, `total`, `invoices_status_id`, `how_pay_id` FROM `r_bonds_int_dec_invoices`
WHERE DATE_FORMAT(`filter`, '%Y-%m') = '$today'
AND `branch_id` $branch_sql
");
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 '3': case '4':
$data['inv'][$get_invoices['filter']]['stuck'] += $get_invoices['total'];
break;
}
break;
case '3':
switch ($get_invoices['how_pay_id']) {
case '3': case '4':
$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 `filter`, `total`, `bonds_status_id`, `how_pay_id` FROM `r_month_user_bonds`
WHERE DATE_FORMAT(`filter`, '%Y-%m') = '$today'
AND `branch_id` $branch_sql
");
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 '6': case '7': case '8': case '9': case '10':
$data['bonds'][$get_invoices['filter']]['stuck'] += $get_invoices['total'];
break;
}
break;
case '3':
switch ($get_invoices['how_pay_id']) {
case '1': case '2': case '3':
$data['bonds_back'][$get_invoices['filter']]['cash'] += $get_invoices['total'];
break;
case '4':
$data['bonds'][$get_invoices['filter']]['stuck'] += $get_invoices['total'];
break;
case '5':
$data['bonds_back'][$get_invoices['filter']]['stuck'] += $get_invoices['total'];
break;
}
break;
case '4':
echo"<script>alert('hi')</script>";
break;
}
}
$totals = ($data['totals']['bonds'] - $data['totals']['inv']);
?>
<!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">
<?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`
");
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='bonds_int_dec?date=<?=$today?>&b=<?=$commercial_register['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="bonds_int_dec?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="bonds_int_dec?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 colspan="3" scope="col">رصيد العملاء</th>
<th scope="col"><?=round($totals,2)?></th>
</tr>
<tr>
<th scope="col">التاريخ</th>
<th scope="col">وارد</th>
<th scope="col">صادر</th>
<th scope="col">الرصيد</th>
</tr>
</thead>
<tbody>
<?php
while ($frist_day <= $last_day) {
?>
<tr>
<th scope="row" style="white-space: nowrap;"><?=$frist_day?></th>
<td><?=round($data['bonds'][$frist_day]['cash'] + $data['bonds'][$frist_day]['card'] + $data['bonds'][$frist_day]['stuck'],2)?></td>
<td><?=round($data['inv'][$frist_day]['stuck'] + $data['bonds_back'][$frist_day]['cash'],2)?></td>
<td><?=round(($totals + ($data['bonds'][$frist_day]['cash'] + $data['bonds'][$frist_day]['card'] + $data['bonds'][$frist_day]['stuck'])) - ($data['inv'][$frist_day]['stuck'] + $data['bonds_back'][$frist_day]['cash']),2)?></td>
</tr>
<?php
$totals += (($data['bonds'][$frist_day]['cash'] + $data['bonds'][$frist_day]['card'] + $data['bonds'][$frist_day]['stuck']) - ($data['inv'][$frist_day]['stuck'] + $data['bonds_back'][$frist_day]['cash']));
$frist_day = date('Y-m-d', strtotime('+1 day', strtotime($frist_day)));
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php require_once('fixed/footer/go.php'); ?>
</div>
</div>
<div id="get_data"></div>
<?php require_once('fixed/js/go.php'); ?>
<script>
$("#Select-date").change(function() {
var SelectedDate = $(this).val();
window.location = 'bonds_int_dec?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_bonds_int_dec_ajax.php", {
date
}, function(get_tretment) {
$("#get_data").html(get_tretment);
})
} else {
swalfun("يرجى الانتظار", "", "warning");
}
}
</script>
</body>
</html>