Add TimescaleDB migration for QDS
This commit is contained in:
90
app/Http/Controllers/ChatbotController.php
Normal file
90
app/Http/Controllers/ChatbotController.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Gemini\Laravel\Facades\Gemini;
|
||||
|
||||
class ChatbotController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
// public function handleMessage(Request $request)
|
||||
// {
|
||||
// $request->validate(['message' => 'required|string']);
|
||||
// $userMessage = $request->input('message');
|
||||
|
||||
// try {
|
||||
// $result = Gemini::geminiPro()->generateContent($userMessage);
|
||||
// $reply = $result->text() ?? 'Sorry, no response from Gemini AI.';
|
||||
// } catch (\Exception $e) {
|
||||
// \Log::error('Gemini API Exception: ' . $e->getMessage(), ['trace' => $e->getTraceAsString()]);
|
||||
// if (config('app.debug')) {
|
||||
// return response()->json(['reply' => 'Error: ' . $e->getMessage()], 500);
|
||||
// }
|
||||
// return response()->json(['reply' => 'Error communicating with Gemini AI. Please try again later.'], 500);
|
||||
// }
|
||||
|
||||
// return response()->json(['reply' => $reply]);
|
||||
// }
|
||||
|
||||
// public function handleMessage(Request $request)
|
||||
// {
|
||||
// $request->validate([
|
||||
// 'message' => 'required|string'
|
||||
// ]);
|
||||
|
||||
// $apiKey = env('GEMINI_API_KEY'); // Put this in .env
|
||||
|
||||
// $response = Http::withHeaders([
|
||||
// 'Content-Type' => 'application/json',
|
||||
// 'x-goog-api-key' => $apiKey
|
||||
// ])->post('https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent', [
|
||||
// 'contents' => [
|
||||
// ['parts' => [['text' => $request->message]]]
|
||||
// ]
|
||||
// ]);
|
||||
|
||||
// if ($response->successful()) {
|
||||
// return response()->json([
|
||||
// 'reply' => $response->json()['candidates'][0]['content']['parts'][0]['text'] ?? 'No response.'
|
||||
// ]);
|
||||
// }
|
||||
|
||||
// return response()->json(['reply' => 'Failed to fetch response.'], 500);
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,18 @@ class InvoiceValidationController extends Controller
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
$plantCode = $request->header('plant-code');
|
||||
$invoiceNo = $request->header('invoice-number');
|
||||
$lineQuan = $request->header('line-quantity');
|
||||
|
||||
if (!$plantCode) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Plant Code value can't be empty"
|
||||
], 404);
|
||||
}
|
||||
|
||||
$data = $request->all();
|
||||
|
||||
if (!isset($data['plant_code']) || trim($data['plant_code']) == '')
|
||||
@@ -58,7 +70,8 @@ class InvoiceValidationController extends Controller
|
||||
}
|
||||
|
||||
$plant = Plant::where('code', $data['plant_code'])->first();
|
||||
if (!$plant) {
|
||||
if (!$plant)
|
||||
{
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'Plant not found!'
|
||||
|
||||
@@ -73,6 +73,68 @@ class PalletController extends Controller
|
||||
// $mpdf->Output('qr-label.pdf', 'I');
|
||||
}
|
||||
|
||||
// public function downloadQrPdf($palletNo)
|
||||
// {
|
||||
// $qrCode = new QrCode($palletNo);
|
||||
// $output = new Output\Png();
|
||||
// $qrBinary = $output->output($qrCode, 100);
|
||||
// $qrBase64 = base64_encode($qrBinary);
|
||||
|
||||
// $htmlBlock = '
|
||||
// <table class="sticker-table">
|
||||
// <tr>
|
||||
// <td class="qr-cell">
|
||||
// <img class="qr" src="data:image/png;base64,' . $qrBase64 . '" alt="QR" />
|
||||
// </td>
|
||||
// <td class="text-cell">
|
||||
// ' . htmlspecialchars($palletNo) . '
|
||||
// </td>
|
||||
// </tr>
|
||||
// </table>';
|
||||
|
||||
// return '
|
||||
// <html>
|
||||
// <head>
|
||||
// <style>
|
||||
// body { margin: 0; padding: 0; width: 60mm; height: auto; font-size: 10pt; font-family: DejaVu Sans, sans-serif; }
|
||||
// .sticker-table { width: 60mm; height: 14mm; border-collapse: collapse;}
|
||||
// .qr-cell { width: 14mm;}
|
||||
// .text-cell { text-align: left; vertical-align: middle; font-size: 22pt; padding-left: 1mm; padding-top: 2mm; white-space: nowrap; font-weight: bold; }
|
||||
// img.qr { width: 19mm; height: 19mm; display: block; margin-left: -2mm;}
|
||||
// </style>
|
||||
// </head>
|
||||
// <body>
|
||||
// ' . $htmlBlock . $htmlBlock . '
|
||||
// <script>
|
||||
// window.onload = function () {
|
||||
// window.print();
|
||||
// setTimeout(function () {
|
||||
// window.close();
|
||||
// }, 1000); // Wait 1 second before closing
|
||||
// };
|
||||
// </script>
|
||||
// </body>
|
||||
// </html>';
|
||||
|
||||
// // $mpdf = new Mpdf([
|
||||
// // 'mode' => 'utf-8',
|
||||
// // 'format' => [60, 14],
|
||||
// // 'margin_left' => 0,
|
||||
// // 'margin_right' => 0,
|
||||
// // 'margin_top' => 0,
|
||||
// // 'margin_bottom' => 0,
|
||||
// // // 'tempDir' => '/var/www/storage/mpdf-tmp',
|
||||
// // ]);
|
||||
|
||||
// // $mpdf->WriteHTML($html);
|
||||
// // // Output PDF to browser for printing
|
||||
// // $mpdf->Output('qr-label.pdf', 'I');
|
||||
// }
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
|
||||
public function downloadQrPdf($palletNo)
|
||||
{
|
||||
$qrCode = new QrCode($palletNo);
|
||||
@@ -80,7 +142,7 @@ class PalletController extends Controller
|
||||
$qrBinary = $output->output($qrCode, 100);
|
||||
$qrBase64 = base64_encode($qrBinary);
|
||||
|
||||
$htmlBlock = '
|
||||
$htmlBlock = '
|
||||
<table class="sticker-table">
|
||||
<tr>
|
||||
<td class="qr-cell">
|
||||
@@ -92,48 +154,43 @@ class PalletController extends Controller
|
||||
</tr>
|
||||
</table>';
|
||||
|
||||
return '
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
body { margin: 0; padding: 0; width: 60mm; height: auto; font-size: 10pt; font-family: DejaVu Sans, sans-serif; }
|
||||
.sticker-table { width: 60mm; height: 14mm; border-collapse: collapse; page-break-after: always; }
|
||||
.qr-cell { width: 14mm; text-align: right; vertical-align: bottom; padding-left: -8mm; padding-top: 0mm; }
|
||||
.text-cell { text-align: left; vertical-align: middle; font-size: 22pt; padding-left: 1mm; padding-top: 2mm; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: bold; }
|
||||
img.qr { width: 19mm; height: 19mm; display: block; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
' . $htmlBlock . $htmlBlock . '
|
||||
<script>
|
||||
window.onload = function () {
|
||||
window.print();
|
||||
setTimeout(function () {
|
||||
window.close();
|
||||
}, 1000); // Wait 1 second before closing
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>';
|
||||
$html = '
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
body { margin: 0; padding: 0; width: 60mm; height: auto; font-size: 10pt; font-family: DejaVu Sans, sans-serif; }
|
||||
.sticker-table { width: 60mm; height: 14mm; border-collapse: collapse; page-break-after: always; }
|
||||
.qr-cell { width: 14mm; text-align: right; vertical-align: bottom; padding-left: 0mm; padding-top: 0mm; }
|
||||
.text-cell { text-align: left; vertical-align: middle; font-size: 22pt; padding-left: 1mm; padding-top: 2mm; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: bold; }
|
||||
img.qr { width: 16mm; height: 16mm; display: block; margin-left: -2mm;}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
' . $htmlBlock . $htmlBlock . '
|
||||
<script>
|
||||
window.onload = function () {
|
||||
window.print();
|
||||
setTimeout(function () {
|
||||
window.close();
|
||||
}, 1000); // Wait 1 second before closing
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>';
|
||||
|
||||
// $mpdf = new Mpdf([
|
||||
// 'mode' => 'utf-8',
|
||||
// 'format' => [60, 14],
|
||||
// 'margin_left' => 0,
|
||||
// 'margin_right' => 0,
|
||||
// 'margin_top' => 0,
|
||||
// 'margin_bottom' => 0,
|
||||
// // 'tempDir' => '/var/www/storage/mpdf-tmp',
|
||||
// ]);
|
||||
$mpdf = new Mpdf([
|
||||
'mode' => 'utf-8',
|
||||
'format' => [60, 14],
|
||||
'margin_left' => 0,
|
||||
'margin_right' => 0,
|
||||
'margin_top' => 0,
|
||||
'margin_bottom' => 0,
|
||||
// 'tempDir' => '/var/www/storage/mpdf-tmp',
|
||||
]);
|
||||
|
||||
// $mpdf->WriteHTML($html);
|
||||
// // Output PDF to browser for printing
|
||||
// $mpdf->Output('qr-label.pdf', 'I');
|
||||
$mpdf->WriteHTML($html);
|
||||
$mpdf->Output('qr-label.pdf', 'I');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user