85 lines
4.2 KiB
PHP
Executable File
85 lines
4.2 KiB
PHP
Executable File
<?php
|
|
require_once('../../../fixed/config/go_con.php');
|
|
|
|
$temp_date = mysqli_real_escape_string($db, $_POST['date']);
|
|
|
|
mysqli_query(
|
|
$db,
|
|
"DELETE FROM `r_month_user_invoices` WHERE DATE_FORMAT(`filter`, '%Y-%m') = '$temp_date'
|
|
");
|
|
|
|
mysqli_query(
|
|
$db,
|
|
"DELETE FROM `r_month_user_bonds` WHERE DATE_FORMAT(`filter`, '%Y-%m') = '$temp_date'
|
|
");
|
|
|
|
$frist_day = date('Y-m-d', strtotime($temp_date));
|
|
$last_day = date("Y-m-t", strtotime($frist_day));
|
|
$next_day = $frist_day;
|
|
|
|
echo $temp_date . $frist_day . $last_day;
|
|
while ($next_day <= $last_day) {
|
|
$temp_next_day = date('Y-m-d', strtotime('+1 day', strtotime($next_day)));
|
|
mysqli_query(
|
|
$db,
|
|
"INSERT INTO `r_month_user_invoices`(`filter`, `date`,`branch_id`, `total`, `invoices_status_id`, `how_pay_id`, `date_time`, `user_id`, `activation_id`)
|
|
SELECT
|
|
CASE
|
|
WHEN (invoices_details_has_how_pay.date_time >= concat(DATE(invoices_details_has_how_pay.date_time),' 03:00:00')) THEN DATE(invoices_details_has_how_pay.date_time)
|
|
WHEN (invoices_details_has_how_pay.date_time < concat(DATE_ADD(DATE(invoices_details_has_how_pay.date_time), INTERVAL +1 DAY),' 03:00:00')) THEN concat(DATE_ADD(DATE(invoices_details_has_how_pay.date_time), INTERVAL -1 DAY))
|
|
ELSE 'false'
|
|
END AS `filter`,
|
|
DATE(invoices_details_has_how_pay.date_time) AS `date`,
|
|
invoices_details.branch_id,
|
|
SUM(ROUND(invoices_details_has_how_pay.pay,2)) AS total,
|
|
invoices_details.invoices_status_id,
|
|
invoices_details_has_how_pay.how_pay_id,
|
|
'$date_time',
|
|
'1',
|
|
'1'
|
|
|
|
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`.`date_time` LIKE '$next_day%' AND `invoices_details_has_how_pay`.`date_time` >= '$next_day 03:00:00') OR (`invoices_details_has_how_pay`.`date_time` LIKE '$temp_next_day%' AND `invoices_details_has_how_pay`.`date_time` < '$temp_next_day 03:00:00'))
|
|
GROUP BY `date`,
|
|
invoices_details.branch_id,
|
|
`invoices_details`.`invoices_status_id`,
|
|
`invoices_details_has_how_pay`.`how_pay_id`"
|
|
);
|
|
|
|
mysqli_query(
|
|
$db,
|
|
"INSERT INTO `r_month_user_bonds`(`filter`, `date`,`branch_id`, `total`, `bonds_status_id`, `how_pay_id`, `date_time`, `user_id`, `activation_id`)
|
|
SELECT
|
|
CASE
|
|
WHEN (bonds_details_has_how_pay.date_time >= concat(DATE(bonds_details_has_how_pay.date_time),' 03:00:00')) THEN DATE(bonds_details_has_how_pay.date_time)
|
|
WHEN (bonds_details_has_how_pay.date_time < concat(DATE_ADD(DATE(bonds_details_has_how_pay.date_time), INTERVAL +1 DAY),' 03:00:00')) THEN concat(DATE_ADD(DATE(bonds_details_has_how_pay.date_time), INTERVAL -1 DAY))
|
|
ELSE 'false'
|
|
END AS `filter`,
|
|
DATE(bonds_details_has_how_pay.date_time) AS `date`,
|
|
bonds_details.branch_id,
|
|
SUM(ROUND(bonds_details_has_how_pay.pay,2)) AS total,
|
|
bonds_details.bonds_status_id,
|
|
bonds_details_has_how_pay.how_pay_id,
|
|
'$date_time',
|
|
'1',
|
|
'1'
|
|
|
|
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`.`date_time` LIKE '$next_day%' AND `bonds_details_has_how_pay`.`date_time` >= '$next_day 03:00:00') OR (`bonds_details_has_how_pay`.`date_time` LIKE '$temp_next_day%' AND `bonds_details_has_how_pay`.`date_time` < '$temp_next_day 03:00:00'))
|
|
GROUP BY `date`,
|
|
`bonds_details`.`branch_id`,
|
|
`bonds_details`.`bonds_status_id`,
|
|
`bonds_details_has_how_pay`.`how_pay_id`"
|
|
);
|
|
|
|
$next_day = date('Y-m-d', strtotime('+1 day', strtotime($next_day)));
|
|
}
|
|
echo"
|
|
<script>
|
|
swalfun('تم الطلب بنجاح','يرجى تحديث الصفحة', 'success');
|
|
</script>
|
|
";
|
|
?>
|
|
|