" . var_export($var, true) . ""; $result .= $print . "\n\n"; } echo $result; die; } function fetch(string $query, array $params = []): array { global $db; $stmt = mysqli_prepare($db, $query); $error = mysqli_error($db); if (!empty($error)) { dd($error); } if (!empty($params)) { $paramTypes = ''; foreach ($params as $param) { if (is_int($param)) { $paramTypes .= 'i'; } else if (is_float($param)) { $paramTypes .= 'd'; } else { $paramTypes .= 's'; } } $stmt->bind_param($paramTypes, ...$params); } $stmt->execute(); $error = mysqli_error($db); if (!empty($error)) { dd($error); } $result = $stmt->get_result(); return $result->fetch_all(MYSQLI_ASSOC); } function transferJsonFiles($file_name, $data) { // Clear the contents of the JSON file file_put_contents('transferJsonFiles/' . $file_name . '.json', ''); // Convert the data array to JSON $jsonData = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); // Write the JSON data to the file file_put_contents('transferJsonFiles/' . $file_name . '.json', $jsonData); } /* $commercialRegisterData = fetch(<< '2024-12-14 00:00:00' SQL); // Transfer the data to a JSON file transferJsonFiles('employees', $employeeData); die; // ------------------------------ $employeeServices = fetch(<< '2024-12-14 00:00:00' SQL); // Transfer the data to a JSON file transferJsonFiles('employee_services', $employeeServices); die; // ------------------------------ $anEmployeeOfferData = fetch(<< '2024-12-14 00:00:00' OR create_time > '2024-12-14 00:00:00' SQL); // Transfer the data to a JSON file transferJsonFiles('partners', $anEmployeeOfferData); die; // ------------------------------ $howToHearData = fetch(<< '2024-12-14 00:00:00' SQL); // Transfer the data to a JSON file transferJsonFiles('clients', $tretmentData); die; // ------------------------------ $tretmentHasHowToHearData = fetch(<< '2024-12-14 00:00:00' SQL); // Transfer the data to a JSON file transferJsonFiles('client_referrals', $tretmentHasHowToHearData); die; // ------------------------------ $serviceTypeData = fetch(<< '2024-12-14 00:00:00' SQL); // Transfer the data to a JSON file transferJsonFiles('service_categories', $serviceTypeData); die; // ------------------------------ $serviceData = fetch(<< 0 AND date_time > '2024-12-14 00:00:00' SQL); // // Transfer the data to a JSON file // transferJsonFiles('primary_services', $serviceData); // die; // ------------------------------ $additionalServicesData = fetch(<< 0 AND date_time > '2024-12-14 00:00:00' SQL); $serviceData = array_merge($serviceData, $additionalServicesData); // Transfer the data to a JSON file transferJsonFiles('services', $serviceData); die; // ------------------------------ $reservationDataCollect_1 = fetch(<< '2024-12-14 00:00:00' SQL); $reservationDataCollect_2 = fetch(<< '2024-12-14 00:00:00' ORDER BY id ASC SQL); $reservationDataCollect_3 = fetch(<< '2024-12-14 00:00:00' SQL); $reservationDataCollect_4 = fetch(<< '2024-12-14 00:00:00' SQL); $reservationDataCollect_5 = fetch(<< '2024-12-14 00:00:00' SQL); $reservationDataCollect_6 = fetch(<< '2024-12-14 00:00:00' SQL); $reservationData = []; // Transfer the data to a JSON file transferJsonFiles('reservations', $reservationDataCollect_1); transferJsonFiles('reservation_details', $reservationDataCollect_2); transferJsonFiles('reservation_bundle_services', $reservationDataCollect_3); transferJsonFiles('reservation_bundles', $reservationDataCollect_4); transferJsonFiles('reservation_bundle_services_services', $reservationDataCollect_5); transferJsonFiles('reservation_drivers', $reservationDataCollect_6); die; // ------------------------------ $invoiceDescountTables = fetch(<< '2024-12-14 00:00:00' SQL); transferJsonFiles('invoices', $invoiceDataCollect_1); die; $invoiceDataCollect_2 = fetch(<< '2024-12-14 00:00:00' ORDER BY id ASC SQL); $invoiceDataCollect_3 = fetch(<< '2024-12-14 00:00:00' SQL); $invoiceDataCollect_4 = fetch(<< '2024-12-14 00:00:00' SQL); $invoiceDataCollect_5 = fetch(<< '2024-12-14 00:00:00' SQL); $invoiceDataCollect_6 = fetch(<< '2024-12-14 00:00:00' SQL); $invoiceDataCollect_7 = fetch(<< '2024-12-14 00:00:00' SQL); $incoiceDataCollect_8 = fetch(<< '2024-12-14 00:00:00' SQL); $incoiceDataCollect_9 = fetch(<< '2024-12-14 00:00:00' SQL); $incoiceDataCollect_10 = fetch(<< '2024-12-14 00:00:00' SQL); $productsData = fetch(<< '2024-12-14 00:00:00' SQL); $incoiceDataCollect_11 = fetch(<< '2024-12-14 00:00:00' SQL); $invoiceData = []; // Transfer the data to a JSON file transferJsonFiles('invoice_discount_tables', $invoiceDescountTables); transferJsonFiles('invoices', $invoiceDataCollect_1); transferJsonFiles('invoice_details', $invoiceDataCollect_2); transferJsonFiles('invoice_payments', $invoiceDataCollect_3); transferJsonFiles('invoice_discounts', $invoiceDataCollect_4); transferJsonFiles('invoice_discount_details', $invoiceDataCollect_5); transferJsonFiles('invoice_discount_details_tables', $invoiceDataCollect_6); transferJsonFiles('invoice_book', $invoiceDataCollect_7); transferJsonFiles('invoice_additions', $incoiceDataCollect_8); transferJsonFiles('invoice_addition_details', $incoiceDataCollect_9); transferJsonFiles('invoice_addition_details_tables', $incoiceDataCollect_10); transferJsonFiles('products', $productsData); transferJsonFiles('invoice_products', $incoiceDataCollect_11); die; // ------------------------------ $pointDataCollect_1 = fetch(<< '2024-12-14 00:00:00' SQL); $pointDataCollect_2 = fetch(<< '2024-12-14 00:00:00' SQL); $wallaReasonsData = fetch(<< '2024-12-14 00:00:00' SQL); // Transfer the data to a JSON file transferJsonFiles('points', $pointDataCollect_1); transferJsonFiles('points_with_invoices', $pointDataCollect_2); transferJsonFiles('walla_reasons', $wallaReasonsData); transferJsonFiles('walla_points', $wallaPointDataCollect_1); die; // ------------------------------ $packagesData = fetch(<< '2024-12-14 00:00:00' SQL); $packagesHasServicesData = fetch(<< '2024-12-14 00:00:00' SQL); // Transfer the data to a JSON file transferJsonFiles('packages', $packagesData); transferJsonFiles('package_services', $packagesHasServicesData); die; // ------------------------------ $bondsData = fetch(<< '2024-12-14 00:00:00' AND date_time < '2025-01-31 00:00:00' SQL); $bondsDetailsData = fetch(<< '2024-12-14 00:00:00' AND date_time < '2025-01-31 00:00:00' SQL); $bondsDetailsPaymentsData = fetch(<< '2024-12-14 00:00:00' AND date_time < '2025-01-31 00:00:00' SQL); $bondsDetailsPackagesData = fetch(<< '2024-12-14 00:00:00' AND date_time < '2025-01-31 00:00:00' SQL); $bondsDetailsServicesData = fetch(<< '2024-12-14 00:00:00' AND date_time < '2025-01-31 00:00:00' SQL); // Transfer the data to a JSON file transferJsonFiles('bonds', $bondsData); transferJsonFiles('bond_details', $bondsDetailsData); transferJsonFiles('bond_payments', $bondsDetailsPaymentsData); transferJsonFiles('bond_packages', $bondsDetailsPackagesData); transferJsonFiles('bond_services', $bondsDetailsServicesData); die; // ------------------------------ $tretmentHasServicesData = fetch(<< '2024-12-14 00:00:00' SQL); $tretmentHasFreeServicesData = fetch(<< '2024-12-14 00:00:00' SQL); $tretmentHasMoneyData = fetch(<< '2024-12-14 00:00:00' SQL); $tretmentHasFreeMoneyData = fetch(<< '2024-12-14 00:00:00' SQL); $couponsData = fetch(<< '2024-12-14 00:00:00' SQL); $tretmentHasCouponsData = fetch(<< '2024-12-14 00:00:00' SQL); $tretmentHasFree3ServCouponData = fetch(<< '2024-12-14 00:00:00' SQL); $coustomDiscountData = fetch(<< '2024-12-14 00:00:00' SQL); $coustomDiscountHasServicesData = fetch(<< '2024-12-14 00:00:00' SQL); $tretmentHasCustomDiscountData = fetch(<< '2024-12-14 00:00:00' SQL); // Transfer the data to a JSON file transferJsonFiles('client_services', $tretmentHasServicesData); transferJsonFiles('client_free_services', $tretmentHasFreeServicesData); transferJsonFiles('client_money', $tretmentHasMoneyData); transferJsonFiles('client_free_money', $tretmentHasFreeMoneyData); transferJsonFiles('coupons', $couponsData); transferJsonFiles('client_coupons', $tretmentHasCouponsData); transferJsonFiles('client_free_service_coupon', $tretmentHasFree3ServCouponData); transferJsonFiles('client_use_money', $tretmentUseMoneyData); transferJsonFiles('custom_discounts', $coustomDiscountData); transferJsonFiles('custom_discount_services', $coustomDiscountHasServicesData); transferJsonFiles('client_custom_discounts', $tretmentHasCustomDiscountData); */ /* die; */ /* $start = '2025-01-01 03:00:00'; $end = '2026-02-20 03:00:00'; $packagesData = fetch(<< '2024-12-14 00:00:00' SQL); $packagesHasServicesData = fetch(<<= '2025-02-15 00:00:00' SQL); // Transfer the data to a JSON file transferJsonFiles('packages', $packagesData); transferJsonFiles('package_services', $packagesHasServicesData); die; */ $start = '2024-01-01 03:00:00'; $end = '2025-01-01 03:00:00'; $usedClientServices = fetch(<< $service['id'], 'type' => 'primary' ]; } } } else { $services = fetch(<< $service['type'], 'id' => $service['id'], 'name' => $service['name'], 'price' => $service['price'] ]; } } } else { $ss = fetch(<< $payment['amount'], 'method' => $payment['method'], ]; $paymentSum += round($payment['amount'], 2); } $discountSum = 0; $invoice['discounts'] = []; foreach ($discounts as $discount) { $table = $discount['discount_reason']; $d = []; $pos = strpos($table, '_offer'); if ($pos !== false && $pos > 0) { $d = fetch(<< $item['id'], 'service_price' => $item['price'], 'reason' => $discount['discount_reason'], 'reason_id' => $discount['discount_reason_id'], ]; break; } } if ($discount['discount_reason'] == 'an_employee_offer') { $d['source'] = 'other'; } else { $d['source'] = 'custom'; } $invoice['discounts'][] = $d; continue; } $d['type'] = 'amount'; if ($discount['discount_reason'] == 'an_employee_offer') { $type = $d['type']; $source = 'other'; $metadata = [ 'partner_id' => $discount['discount_reason_id'], ]; } else { $type = $d['type']; $source = 'custom'; $metadata = [ 'reason' => $discount['discount_reason'], 'reason_id' => $discount['discount_reason_id'], ]; } $invoice['discounts'][] = [ 'type' => $type, 'value' => $d['amount'] ?? $discount['discount'], 'source' => $source, 'metadata' => $metadata, ]; $discountSum += round($discount['discount'] * 1.15, 2); } $paymentSum = round($paymentSum, 2); $discountSum = number_format($discountSum, 2); $diff = number_format((($serviceSum - $discountSum) - $paymentSum) / 1.15, 2); if ($diff >= 1.0) { $invoice['discounts'][] = [ 'type' => 'amount', 'value' => $diff, 'source' => 'custom', 'metadata' => [ 'reason' => 'diff', 'reason_id' => 0, ], ]; } else if ($diff <= -1.0) { $invoice['discounts'] = array_unique($invoice['discounts'], SORT_REGULAR); $less[] = $invoice['id']; } if (count($invoice['payments']) == 0) { continue; } $result[] = $invoice; } $bonds = fetch(<< 1 AND bonds.activation_id = 2 SQL, [$start, $end]); $count = count($bonds); $bondResults = []; for ($index = 0; $index < $count; ++$index) { $bond = &$bonds[$index]; $payments = fetch(<< $b; }); if (!$sorted) { dd("Not sorted!"); } transferJsonFiles('invoices_new', $result); print "Invoices done!\n"; transferJsonFiles('bonds_new', $bondResults); print "Bonds done!\n"; die; $usersData = fetch(<<= ? AND tretment.id > 0 SQL, [$start]); transferJsonFiles('clients_new', $clients); print "Clients done!\n"; $walaaTransactions = fetch(<<= ? AND walla_points.activation_id = 2 SQL, [$start]); transferJsonFiles('walaa_transactions', $walaaTransactions); print "Walaa transactions done!\n"; $membershipPoints = fetch(<< 0 AND create_time >= ? SQL, [$start]); transferJsonFiles('membership_points', $membershipPoints); print "Membership points done!\n"; $clientMoney = fetch(<< 0) { dd($less); } else { dd("No less!"); } die; //*/ // additonals // packages // drinks // offers // walla answers and regisration /* book { book_details { - books details has the services and datetime for the book and the employee and the branch - if service_id is 0 then it's a bundle - go get the bundle_services table and get the services from there - some time the bundle has how many services it is mean that the book has the same service many times like quantity } } invoices { - we must take and rework the sahaby report for fix all the invoices invoices_details { how_pay { - how the invoice was paid } invoices_discount { - the discount for the invoice } - the invoice details has the status of the invoice 1 for new invoice 2 for debit note 3 for credit note 4 for no vat invoice } } bonds { - the bonds is the money that the client has in the system - the bonds has the money and the date and the client id - we must change the bonds to invoice and correct it } */