diff --git a/services/nginx/app/cron/Cron.php b/services/nginx/app/cron/Cron.php index 1263b59a..ec63ae65 100644 --- a/services/nginx/app/cron/Cron.php +++ b/services/nginx/app/cron/Cron.php @@ -2,6 +2,7 @@ // prevent direct access use classes\backup_store; +use classes\economic; use objects\bookings_o; use objects\logs_o; use objects\users_o; @@ -57,6 +58,12 @@ $cron_tasks = [ 'next_run' => 0, 'function' => 'backup', ], + 'SyncEconomicInvoiceStatus' => [ + 'interval' => 60, // 1 minute + 'last_run' => 0, + 'next_run' => 0, + 'function' => 'SyncEconomicInvoiceStatus', + ], ]; function checkUnfulfilledBookings(): void @@ -103,6 +110,24 @@ function SyncUserEconomicCustomerDetails(): void $users_o->syncAllUsersEconomicCustomerDetails(); } +/** + * @throws Exception + */ +function SyncEconomicInvoiceStatus(): void +{ + $economic = new economic(); + try { + $economic->getTasks()->runCheckErrors(); + } catch (Exception $e) { + // Do nothing, this is automatically running + } + try { + $economic->getTasks()->runCheckDrafts(); + } catch (Exception $e) { + // Do nothing, this is automatically running + } +} + foreach ( $cron_tasks as $task => $data ) { $lastRun = redis->get_last_crond_run($task) === null ? 0 : redis->get_last_crond_run($task); $nextRun = $lastRun + $data['interval']; diff --git a/services/nginx/app/cron/SyncEconomicInvoiceStatus.php b/services/nginx/app/cron/SyncEconomicInvoiceStatus.php new file mode 100644 index 00000000..6a8d3570 --- /dev/null +++ b/services/nginx/app/cron/SyncEconomicInvoiceStatus.php @@ -0,0 +1,31 @@ +getTasks()->runCheckErrors(); +} catch (Exception $e) { + // This is automatically running, so we don't need to log the error +} +try { + $economic->getTasks()->runCheckDrafts(); +} catch (Exception $e) { + // This is automatically running, so we don't need to log the error +} +$end = microtime(true); +//$slack = new \classes\slack(); +//$slack->send_message("The booking sync script has finished. It took " . round($end - $start, 2) . " seconds to run."); \ No newline at end of file diff --git a/services/nginx/app/modules/html2pdf/templates/wash_certificate.php b/services/nginx/app/modules/html2pdf/templates/wash_certificate.php index 1a3d4add..60e8f6a9 100644 --- a/services/nginx/app/modules/html2pdf/templates/wash_certificate.php +++ b/services/nginx/app/modules/html2pdf/templates/wash_certificate.php @@ -39,17 +39,23 @@ class wash_certificate extends html2pdf_template //$html .= self::getSignature(); $html .= self::setDocumentFields( '123', - '123', - '123', - '123', + self::getKey('time') . ' ' . self::getKey('date'), + self::getKey('carried_out_by'), + self::getKey('seal_number'), ); $html .= self::setDocumentRegistrationNumberFields( - '123', - '123', + self::getKey('reg_1'), + self::getKey('reg_2'), ); $html .= self::setDocumentCustomerSupplierFields( - '123', - '123', + [ + self::getKey('customer_name'), + self::getKey('customer_address'), + ], + [ + self::getKey('department_name'), + self::getKey('department_address'), + ], ); $html .= self::setSignatureField( '123', @@ -106,23 +112,43 @@ class wash_certificate extends html2pdf_template '; } - private function setDocumentCustomerSupplierFields(string $customer_details_column, string $supplier_details_column): string + private function setDocumentCustomerSupplierFields(array $customer_details_column, array $supplier_details_column): string { $column_width_px = 257; $spacer_width_px = 32; $column_2_additional_width_px = 12; + // Parse the customer details column + $customer_details_html = ''; + foreach ( $customer_details_column as $key => $value ) { + // If the item is the first item, add a strong tag + if ($key === 0) { + $customer_details_html .= '' . htmlspecialchars($value, ENT_QUOTES, 'UTF-8') . '
'; + } else { + $customer_details_html .= htmlspecialchars($value, ENT_QUOTES, 'UTF-8') . '
'; + } + } + // Parse the supplier details column + $supplier_details_html = ''; + foreach ( $supplier_details_column as $key => $value ) { + // If the item is the first item, add a strong tag + if ($key === 0) { + $supplier_details_html .= '' . htmlspecialchars($value, ENT_QUOTES, 'UTF-8') . '
'; + } else { + $supplier_details_html .= htmlspecialchars($value, ENT_QUOTES, 'UTF-8') . '
'; + } + } return ' - +
- ' . htmlspecialchars($customer_details_column, ENT_QUOTES, 'UTF-8') . ' + ' . $customer_details_html . '
- ' . htmlspecialchars($supplier_details_column, ENT_QUOTES, 'UTF-8') . ' + ' . $supplier_details_html . '
@@ -132,12 +158,13 @@ class wash_certificate extends html2pdf_template private function setSignatureField(string $column_1): string { $column_width_px = 219; + $column_height_px = 30; $margin_left_px = 263; $margin_right_px = $margin_left_px; return ' - +
- diff --git a/services/nginx/app/routes/pdfGeneratorRoute.php b/services/nginx/app/routes/pdfGeneratorRoute.php index 70bc2b62..e462db4b 100644 --- a/services/nginx/app/routes/pdfGeneratorRoute.php +++ b/services/nginx/app/routes/pdfGeneratorRoute.php @@ -25,6 +25,31 @@ class pdfGeneratorRoute //self::requirePermission('modules_pdf_generator_test'); if (true) { //(new logs_o())->add('orderInvoices', 'global', 1, $user->id, 'LIST_COLLECTED_INVOICES', 'User accessed the list of collected order invoices'); + // Get the booking from its ID + $id = 434; + $booking = (new \objects\bookings_o())->select($id); + if (!$booking->exists()) { + $response->error('Booking not found', 404); + } + // Get the department from the booking + $department = (new \objects\departments_o())->select((int)$booking->department->value()); + if (!$department->exists()) { + $response->error('Department not found', 404); + } + // Get the branding from the department + $branding = (new \objects\branding_o())->select((int)$department->branding->value()); + if (!$branding->exists()) { + $response->error('Branding not found', 404); + } + // Get the customer from the booking + $customer = (new \objects\users_o())->getUserByCustomerNumber((int)$booking->customer_number->value()); + $department_array = $department->asArray(); + $customer_array = $customer->asArray(); + $booking_array = $booking->asArray(); + $department_array['branding'] = $branding->asArray(); + //print_r($department_array); + //print_r($customer_array); + //print_r($booking_array); $pdf_generator = new pdf_generator(); $pdf_generator->add_html($pdf_generator->templates->getTemplate('wash_certificate') ->setCompany([ @@ -44,14 +69,17 @@ class pdfGeneratorRoute ]) ->addData([ 'seal_number' => 123456, - 'reg_1' => 'EC21233', - 'reg_2' => 'FB1703', - 'date' => '2023-10-01', - 'time' => '12:00', + 'reg_1' => $booking_array['regNrTraekker'], + 'reg_2' => $booking_array['regNrTrailer'], + 'date' => $booking_array['date'], + 'time' => date('H:i'), 'carried_out_by' => 'John Doe', - 'department_id' => 1, - 'customer_name' => 'Customer Name', - 'type' => 'Interior Cleaning', + 'department_id' => $department->id, + 'department_name' => $department_array['branding']['name'] ?: $department_array['name'], + 'department_address' => $department_array['branding']['address'] ?: $department_array['description'], + 'customer_name' => $customer->getCustomerName($customer_array['customer_number']), + 'customer_address' => $customer->getCustomerEcocomicData($customer_array['customer_number'])->economic_customer->address ?: '-', + 'type' => $booking_array['wash_type'], ]) ->getHtml() );
+ ' . htmlspecialchars($column_1, ENT_QUOTES, 'UTF-8') . '