booking/odoo_invoice_credit_notes_p.php

331 lines
16 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`,
`invoices_details`.`invoices_status_id`,
DATE(`invoices_details`.`date_time`) AS `date`,
`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 (3)
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();
}
switch ($get_invoices['invoices_status_id']) {
case '3':
switch ($get_invoices['how_pay_id']) {
case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
$data['show']['inv'][$get_invoices['id']]['how_pay'] = $get_invoices['how_pay_id'];
$data['show']['inv'][$get_invoices['id']]['pay'] = $get_invoices['pay'];
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']]['inv_id'] = $get_invoices['inv_id'];
}
}
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_services_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`
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 (!array_key_exists($get_invoices['invoices_id'],$data['books'])) {
$data['books'][$get_invoices['invoices_id']] = array(
array(
'book_id' => $get_invoices['book_id'],
'odoo_services_id' => $get_invoices['odoo_services_id'],
)
);
} else {
array_push($data['books'][$get_invoices['invoices_id']],array(
'book_id' => $get_invoices['book_id'],
'odoo_services_id' => $get_invoices['odoo_services_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_invoice_credit_notes_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_invoice_credit_notes_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">
<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">Invoice Partner Display Name</th>
<th scope="col">Invoice/Bill Date</th>
<th scope="col">Date</th>
<th scope="col">Due Date</th>
<th scope="col">Origin</th>
<th scope="col">Reference</th>
<th scope="col">Status</th>
<th scope="col">Invoice lines/Analytic</th>
<th scope="col">Invoice lines/Quantity</th>
<th scope="col">Invoice lines/Unit Price</th>
<th scope="col">Partner/Mobile</th>
<th scope="col">Partner</th>
</tr>
</thead>
<tbody>
<?php
foreach ($data['show']['inv'] as $key => $value) {
?>
<tr>
<td>
<?=$data['tretment'][$data['show']['inv'][$key]['inv_id']]['id']?>
<?=$data['tretment'][$data['show']['inv'][$key]['inv_id']]['name']?>
</td>
<td><?=$data['show']['inv'][$key]['date']?></td>
<td><?=$data['show']['inv'][$key]['date']?></td>
<td><?=$data['show']['inv'][$key]['date']?></td>
<td></td>
<td>عكس: <?=$data['show']['inv'][$key]['ref']?></td>
<td>Posted</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_services_id'] => 1
// )
// );
// }
// $str = rtrim($str, ", ");
// echo json_encode($str);
$str = '';
for ($i=0; $i < count($data['books'][$data['show']['inv'][$key]['inv_id']]); $i++) {
$str .= '"' . $data['books'][$data['show']['inv'][$key]['inv_id']][$i]['odoo_services_id'] . '"' . ':100.0 ,';
}
$str = rtrim($str, ", ");
echo $str;
?>
}</td>
<td>1.00</td>
<td><?=$data['show']['inv'][$key]['pay']?></td>
<td><?=$data['tretment'][$data['show']['inv'][$key]['inv_id']]['number']?></td>
<td>
<?=$data['tretment'][$data['show']['inv'][$key]['inv_id']]['id']?>
<?=$data['tretment'][$data['show']['inv'][$key]['inv_id']]['name']?>
</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_invoice_credit_notes_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_invoice_credit_notes_p.' + type);
}
const export_button = document.getElementById('export_button');
export_button.addEventListener('click', () => {
html_table_to_excel('xlsx');
});
</script>
</body>
</html>