406 lines
20 KiB
PHP
Executable File
406 lines
20 KiB
PHP
Executable File
<?php
|
|
require_once('fixed/config/go_con.php');
|
|
|
|
$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");
|
|
}
|
|
}
|
|
|
|
|
|
$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;
|
|
}
|
|
|
|
$data = array(
|
|
'partner_id' => array(
|
|
1 => 'عميل نقدي',
|
|
2 => 'عميل شبكة',
|
|
3 => 'رصيد خدمات',
|
|
4 => 'رصيد اموال',
|
|
6 => 'عميل تحويل',
|
|
7 => 'عميل تحويل',
|
|
8 => 'عميل تحويل',
|
|
9 => 'عميل تحويل',
|
|
),
|
|
);
|
|
|
|
$inv_sql = '';
|
|
$get_invoices_sql = mysqli_query($db,
|
|
"SELECT
|
|
`invoices`.`id` AS `inv_id`,
|
|
`invoices`.`number_style`,
|
|
`invoices_details`.`id`,
|
|
`branch`.`odoo_id` AS `branch_odoo_id`,
|
|
`invoices_details`.`invoices_status_id`,
|
|
DATE(`invoices_details`.`date_time`) AS `date`,
|
|
`invoices_details`.`date_time`,
|
|
`invoices_details_has_how_pay`.`how_pay_id`,
|
|
`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`
|
|
INNER JOIN `invoices` ON `invoices_details`.`invoices_id` = `invoices`.`id`
|
|
INNER JOIN `user` ON `invoices_details_has_how_pay`.`user_id` = `user`.`id`
|
|
INNER JOIN `branch` ON `invoices_details`.`branch_id` = `branch`.`id`
|
|
WHERE ((`invoices_details_has_how_pay`.`date_time` LIKE '$today%' AND `invoices_details_has_how_pay`.`date_time` >= '$today 03:00:00') OR (`invoices_details_has_how_pay`.`date_time` LIKE '$Next%' AND `invoices_details_has_how_pay`.`date_time` < '$Next 03:00:00'))
|
|
AND `branch`.`commercial_register_id` IN (5)
|
|
AND `invoices_details`.`invoices_status_id` IN (1,2)
|
|
ORDER BY `invoices_details`.`branch_id`
|
|
");
|
|
|
|
$data['show']['inv'] = array();
|
|
if (mysqli_num_rows($get_invoices_sql) > 0) {
|
|
while ($get_invoices = mysqli_fetch_assoc($get_invoices_sql)) {
|
|
$inv_sql .= $get_invoices['inv_id'] . ', ';
|
|
if (!array_key_exists($get_invoices['id'],$data['show']['inv'])) {
|
|
$data['show']['inv'][$get_invoices['id']] = array();
|
|
$data['show']['inv'][$get_invoices['id']]['payments'] = array();
|
|
}
|
|
switch ($get_invoices['invoices_status_id']) {
|
|
case '1': case '2':
|
|
switch ($get_invoices['how_pay_id']) {
|
|
case '1': case '2': case '3': case '4': case '6': case '7': case '8': case '9':
|
|
$data['show']['inv'][$get_invoices['id']]['payments'][$get_invoices['how_pay_id']] = $get_invoices['pay'];
|
|
break;
|
|
default:
|
|
$error++;
|
|
break;
|
|
}
|
|
break;
|
|
|
|
default:
|
|
$error++;
|
|
break;
|
|
}
|
|
$data['show']['inv'][$get_invoices['id']]['ref'] = $get_invoices['number_style'];
|
|
$data['show']['inv'][$get_invoices['id']]['date'] = $today;
|
|
$data['show']['inv'][$get_invoices['id']]['date_time'] = $get_invoices['date_time'];
|
|
$data['show']['inv'][$get_invoices['id']]['inv_id'] = $get_invoices['inv_id'];
|
|
$data['show']['inv'][$get_invoices['id']]['branch_odoo_id'] = $get_invoices['branch_odoo_id'];
|
|
}
|
|
}
|
|
print_r($data['show']['inv'][82823]);
|
|
if(!empty($inv_sql)) {
|
|
$inv_sql = rtrim($inv_sql, ", ");
|
|
$get_invoices_sql = mysqli_query($db,
|
|
"SELECT
|
|
`invoices_has_book`.`invoices_id`,
|
|
`dd`.`book_id`,
|
|
`services`.`odoo_id` AS `services_odoo_id`,
|
|
`dd`.`services_id`,
|
|
`emplyee`.`odoo_id` AS `emplyee_odoo_id`,
|
|
`tretment`.`name`,
|
|
`tretment`.`number`,
|
|
`tretment`.`id`
|
|
|
|
FROM `invoices_has_book`
|
|
INNER JOIN `book` ON `invoices_has_book`.`book_id` = `book`.`id`
|
|
INNER JOIN `book_details` AS `dd` ON `book`.`id` = `dd`.`book_id`
|
|
INNER JOIN `tretment` ON `book`.`tretment_id` = `tretment`.`id`
|
|
INNER JOIN `services` ON `dd`.`services_id` = `services`.`id`
|
|
INNER JOIN `emplyee` ON `dd`.`emplyee_id` = `emplyee`.`id`
|
|
WHERE `invoices_has_book`.`invoices_id` IN ($inv_sql)
|
|
AND `dd`.`id` = (SELECT MAX(`id`) FROM `book_details` WHERE `book_id` = `dd`.`book_id`)
|
|
");
|
|
$data['tretment'] = array();
|
|
$data['books'] = array();
|
|
if (mysqli_num_rows($get_invoices_sql) > 0) {
|
|
while ($get_invoices = mysqli_fetch_assoc($get_invoices_sql)) {
|
|
if (!array_key_exists($get_invoices['invoices_id'],$data['tretment'])) {
|
|
$data['tretment'][$get_invoices['invoices_id']] = array(
|
|
'name' => $get_invoices['name'],
|
|
'number' => $get_invoices['number'],
|
|
'id' => $get_invoices['id'],
|
|
);
|
|
}
|
|
|
|
if ($get_invoices['services_id'] == 0) {
|
|
|
|
$book_id_for_bundle = $get_invoices['book_id'];
|
|
$bundle_s = mysqli_query($db, "SELECT
|
|
`services`.`name`,
|
|
`services`.`odoo_id` AS `services_odoo_id`,
|
|
`bundle_services_has_services`.`how_many`
|
|
FROM `bundle_services_has_services`
|
|
INNER JOIN `services` ON `services`.`id` = `bundle_services_has_services`.`services_id`
|
|
WHERE `bundle_services_has_services`.`bundle_services_id` = (SELECT `bundle_services_id` FROM `book_details_has_bundle_services` WHERE `book_details_id` = (SELECT MIN(`id`) FROM `book_details` WHERE `book_id` = $book_id_for_bundle AND `status_id` = 4))");
|
|
if (mysqli_num_rows($bundle_s) > 0) {
|
|
while ($bundle_s_row = mysqli_fetch_assoc($bundle_s)) {
|
|
|
|
for ($i=0; $i < $bundle_s_row['how_many']; $i++) {
|
|
|
|
if (!array_key_exists($get_invoices['invoices_id'],$data['books'])) {
|
|
$data['books'][$get_invoices['invoices_id']] = array(
|
|
array(
|
|
'book_id' => $book_id_for_bundle,
|
|
'services_odoo_id' => $bundle_s_row['services_odoo_id'],
|
|
'emplyee_odoo_id' => $get_invoices['emplyee_odoo_id'],
|
|
)
|
|
);
|
|
} else {
|
|
array_push($data['books'][$get_invoices['invoices_id']],array(
|
|
'book_id' => $book_id_for_bundle,
|
|
'services_odoo_id' => $bundle_s_row['services_odoo_id'],
|
|
'emplyee_odoo_id' => $get_invoices['emplyee_odoo_id'],
|
|
));
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
} else {
|
|
if (!array_key_exists($get_invoices['invoices_id'],$data['books'])) {
|
|
$data['books'][$get_invoices['invoices_id']] = array(
|
|
array(
|
|
'book_id' => $get_invoices['book_id'],
|
|
'services_odoo_id' => $get_invoices['services_odoo_id'],
|
|
'emplyee_odoo_id' => $get_invoices['emplyee_odoo_id'],
|
|
)
|
|
);
|
|
} else {
|
|
array_push($data['books'][$get_invoices['invoices_id']],array(
|
|
'book_id' => $get_invoices['book_id'],
|
|
'services_odoo_id' => $get_invoices['services_odoo_id'],
|
|
'emplyee_odoo_id' => $get_invoices['emplyee_odoo_id'],
|
|
));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------
|
|
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en" dir="rtl">
|
|
<?php require_once('fixed/head/go.php'); ?>
|
|
<body class="rtl">
|
|
<?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>
|
|
يوم
|
|
<?= 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="odoo_invoices_p?date=<?= $Previous ?>&b=<?= $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="odoo_invoices_p?date=<?= $Next ?>&b=<?= $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="card-body new-user order-list">
|
|
عدد الاخطاء
|
|
<?= $error ?>
|
|
<div class="table-responsive">
|
|
<table id="data" class="table table-bordered text-center" style="vertical-align: middle; direction: ltr;">
|
|
<thead class="table-primary" style="vertical-align: middle;">
|
|
<tr>
|
|
<th scope="col">Partner</th>
|
|
<th scope="col">mobile</th>
|
|
<th scope="col">Invoice Date</th>
|
|
<th scope="col">Due Date</th>
|
|
<th scope="col">Origin</th>
|
|
<th scope="col">Reference</th>
|
|
<th scope="col">Invoice lines/Account</th>
|
|
<th scope="col">Invoice lines/Analytic</th>
|
|
<th scope="col">Invoice lines/Taxes</th>
|
|
<th scope="col">Invoice lines/Unit Price</th>
|
|
<th scope="col">auto_post</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php
|
|
foreach ($data['show']['inv'] as $key => $value) {
|
|
foreach ($data['show']['inv'][$key]['payments'] as $key2 => $value2) {
|
|
|
|
?>
|
|
<tr>
|
|
<td>
|
|
<?=$data['tretment'][$data['show']['inv'][$key]['inv_id']]['id']?>
|
|
<?=$data['tretment'][$data['show']['inv'][$key]['inv_id']]['name']?>
|
|
</td>
|
|
<td><?=$data['tretment'][$data['show']['inv'][$key]['inv_id']]['number']?></td>
|
|
<td><?=$data['show']['inv'][$key]['date']?></td>
|
|
<td><?=$data['show']['inv'][$key]['date']?></td>
|
|
|
|
<td>
|
|
<?php
|
|
switch ($key2) {
|
|
case '3': case '4':
|
|
echo "رصيد خدمات (باقة)";
|
|
break;
|
|
|
|
default:
|
|
echo "";
|
|
break;
|
|
}
|
|
?>
|
|
</td>
|
|
<td>
|
|
دفعة مقابل فاتورة
|
|
<br/>
|
|
<?=$data['show']['inv'][$key]['ref']?>
|
|
</td>
|
|
|
|
|
|
|
|
<td>416001 Sales Account</td>
|
|
<td>{
|
|
<?php
|
|
|
|
// $str = array();
|
|
// for ($i=0; $i < count($data['books'][$data['show']['inv'][$key]['inv_id']]); $i++) {
|
|
// array_push($str,
|
|
// array(
|
|
// $data['books'][$data['show']['inv'][$key]['inv_id']][$i]['odoo_id'] => 1
|
|
// )
|
|
// );
|
|
// }
|
|
// $str = rtrim($str, ", ");
|
|
|
|
// echo json_encode($str);
|
|
|
|
$str = '';
|
|
$str .= '"' . $data['show']['inv'][$key]['branch_odoo_id'] . '"' . ':100.0 ,'; // branch
|
|
|
|
for ($i=0; $i < count($data['books'][$data['show']['inv'][$key]['inv_id']]); $i++) { // emplyee
|
|
$str .= '"' . $data['books'][$data['show']['inv'][$key]['inv_id']][$i]['emplyee_odoo_id'] . '"' . ':100.0 ,';
|
|
}
|
|
|
|
for ($i=0; $i < count($data['books'][$data['show']['inv'][$key]['inv_id']]); $i++) { // services
|
|
$str .= '"' . $data['books'][$data['show']['inv'][$key]['inv_id']][$i]['services_odoo_id'] . '"' . ':100.0 ,';
|
|
}
|
|
$str = rtrim($str, ", ");
|
|
|
|
echo $str;
|
|
?>
|
|
}</td>
|
|
<td>ضريبة مبيعات</td>
|
|
|
|
<td>at_date</td>
|
|
|
|
</tr>
|
|
<?php
|
|
}
|
|
}
|
|
?>
|
|
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<button type="button" id="export_button" class="btn btn-success btn-sm">ملف excel</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<!-- Container-fluid Ends-->
|
|
</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 = 'odoo_invoices_p?b=<?= $branch_id ?>&date=' + SelectedDate
|
|
});
|
|
</script>
|
|
<script type="text/javascript" src="https://unpkg.com/xlsx@0.15.1/dist/xlsx.full.min.js"></script>
|
|
<script>
|
|
function padTo2Digits(num) {
|
|
return num.toString().padStart(2, '0');
|
|
}
|
|
|
|
function formatDate(date) {
|
|
return (
|
|
[
|
|
date.getFullYear(),
|
|
padTo2Digits(date.getMonth() + 1),
|
|
padTo2Digits(date.getDate()),
|
|
].join('') +
|
|
'' +
|
|
[
|
|
padTo2Digits(date.getHours()),
|
|
padTo2Digits(date.getMinutes()),
|
|
padTo2Digits(date.getSeconds()),
|
|
].join('')
|
|
);
|
|
}
|
|
|
|
console.log(formatDate(new Date()));
|
|
|
|
|
|
function html_table_to_excel(type) {
|
|
var data = document.getElementById('data');
|
|
var file = XLSX.utils.table_to_book(data, { sheet: "sheet1" });
|
|
XLSX.write(file, { bookType: type, bookSST: true, type: 'base64' });
|
|
XLSX.writeFile(file, formatDate(new Date()) + 'odoo_invoices_p.' + type);
|
|
}
|
|
const export_button = document.getElementById('export_button');
|
|
export_button.addEventListener('click', () => {
|
|
html_table_to_excel('xlsx');
|
|
});
|
|
|
|
</script>
|
|
</body>
|
|
</html>
|