|
84 | 84 | ['style' => 'font-size: small'], |
85 | 85 | )); |
86 | 86 |
|
87 | | - $mpdfTmpDir = sys_get_temp_dir().'/mpdf'; |
| 87 | + // Check if email sending is enabled - only generate PDF if it will be sent |
| 88 | + $sendByEmail = strtolower(Shared::cfg('SEND_CALL_LIST_EMAIL', 'true')) === 'true'; |
88 | 89 |
|
89 | | - if (!file_exists($mpdfTmpDir)) { |
90 | | - mkdir($mpdfTmpDir); |
91 | | - } |
| 90 | + $mailSent = false; |
92 | 91 |
|
93 | | - $html2pdf = new \Mpdf\Mpdf([ |
94 | | - 'default_font_size' => 8, |
95 | | - 'default_font' => 'dejavusans', |
96 | | - 'tempDir' => $mpdfTmpDir, |
97 | | - ]); |
98 | | - $html2pdf->setDefaultFont('Helvetica'); |
99 | | - $html2pdf->writeHTML((string) $report); |
100 | | - $pdfFilename = $mpdfTmpDir.'/'.$invoiceRaw['customerId'].'_'._('Calls').'_'.$startDate->format('Y-m-d').'_'.$now->format('Y-m-d').'.pdf'; |
101 | | - |
102 | | - $html2pdf->Output($pdfFilename, \Mpdf\Output\Destination::FILE); |
103 | | - |
104 | | - $postman = new Mailer( |
105 | | - $email, |
106 | | - _('Prepaid Calls listing').' '.$range, |
107 | | - _('Prepaid Calls for last month'), |
108 | | - ); |
109 | | - $postman->addFile($pdfFilename, 'application/pdf'); |
| 92 | + if ($sendByEmail) { |
| 93 | + $mpdfTmpDir = sys_get_temp_dir().'/mpdf'; |
| 94 | + |
| 95 | + if (!file_exists($mpdfTmpDir)) { |
| 96 | + mkdir($mpdfTmpDir); |
| 97 | + } |
110 | 98 |
|
111 | | - unlink($pdfFilename); |
| 99 | + $html2pdf = new \Mpdf\Mpdf([ |
| 100 | + 'default_font_size' => 8, |
| 101 | + 'default_font' => 'dejavusans', |
| 102 | + 'tempDir' => $mpdfTmpDir, |
| 103 | + ]); |
| 104 | + $html2pdf->setDefaultFont('Helvetica'); |
| 105 | + $html2pdf->writeHTML((string) $report); |
| 106 | + $pdfFilename = $mpdfTmpDir.'/'.$invoiceRaw['customerId'].'_'._('Calls').'_'.$startDate->format('Y-m-d').'_'.$now->format('Y-m-d').'.pdf'; |
| 107 | + |
| 108 | + $html2pdf->Output($pdfFilename, \Mpdf\Output\Destination::FILE); |
| 109 | + |
| 110 | + if ($sendByEmail) { |
| 111 | + $postman = new Mailer( |
| 112 | + $email, |
| 113 | + _('Prepaid Calls listing').' '.$range, |
| 114 | + _('Prepaid Calls for last month'), |
| 115 | + ); |
| 116 | + $postman->addFile($pdfFilename, 'application/pdf'); |
| 117 | + $mailSent = $postman->send(); |
| 118 | + } |
| 119 | + |
| 120 | + unlink($pdfFilename); |
| 121 | + } else { |
| 122 | + $grabber->addStatusMessage('PDF call list generation skipped (email sending disabled)', 'info'); |
| 123 | + } |
112 | 124 |
|
113 | | - $jsonReportData[$adresar->getRecordCode()]['mail'] = $postman->send(); |
| 125 | + $jsonReportData[$adresar->getRecordCode()]['mail'] = $mailSent; |
114 | 126 | $jsonReportData[$adresar->getRecordCode()]['period'] = $range; |
115 | 127 | $jsonReportData[$adresar->getRecordCode()]['totalAmount'] = $totalAmount; |
116 | 128 | $jsonReportData[$adresar->getRecordCode()]['callsCount'] = \count($calls); |
| 129 | + $jsonReportData[$adresar->getRecordCode()]['pdfGenerated'] = $sendByEmail; |
| 130 | + $jsonReportData[$adresar->getRecordCode()]['emailSent'] = $sendByEmail && $mailSent; |
117 | 131 | } else { |
118 | 132 | $jsonReportData[$adresar->getRecordCode()]['mail'] = false; |
119 | 133 | $jsonReportData[$adresar->getRecordCode()]['period'] = null; |
120 | 134 | $jsonReportData[$adresar->getRecordCode()]['totalAmount'] = null; |
121 | 135 | $jsonReportData[$adresar->getRecordCode()]['callsCount'] = 0; |
| 136 | + $jsonReportData[$adresar->getRecordCode()]['pdfGenerated'] = false; |
| 137 | + $jsonReportData[$adresar->getRecordCode()]['emailSent'] = false; |
122 | 138 | $grabber->addStatusMessage( |
123 | 139 | $invoiceRaw['customerName'].' without extID', |
124 | 140 | 'warning', |
|
0 commit comments