Which api endpoint gives the sum and which field in the response?
Vuejs do not fetch after move to live server
Hello all, I have moved Laravel Vue project to live VPS server but Vue doesnt work properly, and cannot see any error messages in my console or in debug mode. Problem that Vue do not fetch data from database base in a collumn: Sum this month also Total displays 0 € and I cannot generate any Invoices.
Any ideas why it can happen?
you could login to admin to check: www.cvtinklas.lt
@Sinnbeck thanks for reply, field in response it is: monthlySum , Api endpoint to get data is: cvtinklas.lt/api/clients
@Krikis Dont see that field?

@Sinnbeck sorry, it is in: cvtinklas.lt/api/clientsWithReservations
@Krikis Seems that its 0 from the server, so maybe there is no data in the database? Hard to say without knowing how that number is set
@Sinnbeck I have a function actually in app\Repositories\ClienRepo.php which should to generate value as it is not stored in database. Function below:
$reportsController = app(ReportsController::class);
foreach ($clients as $key => $client) {
$client->reservationsGrouped = $client->reservations->groupBy(static function ($item) {
return $item->house_id;
});
$request = (new Request())->merge([
'client' => $client->id,
]);
$client->monthlySum = \round($reportsController->count($request), 2);
$client->activeBeds = $this->reservationRepo->getActiveBeds($client->id);
$client->moved = $this->reservationRepo->getLastMonthUsedBeds($client->id);
$clients[$key] = $this->filterDates($client);
}
return ClientResource::collection($clients);
@Krikis Ok. Just a suggestion. Dont use controllers like that. Controllers are just a middleman class that handles a request and returns a response. Use a proper class structure like an action or a service
Anyways. You have a count() method that returns 0 but dont show it
@Sinnbeck Thanks, I just found I guess problem, I have in a database table: temp_reports, where some data should to be stored. Previously I had a schedule command to execute a code to run a command. Seems when I moved to VPS server I''m not able to run this command anymore. Maybe any help how to a Schedule command?
My code looks as per below in app\Console\Commands\GenerateTempReports.php
public function handle() { $this->log('GenerateTempReports started'); if ($this->argument('date') !== null) { $date = strtotime($this->argument('date')); } else { $date = strtotime('-1 day'); }
$to = strtotime(date('Y-m-d'));
$clientHouses = DB::table('client_house')->get();
while ($date <= $to) {
$this->info("Generating reports for" . date("Y-m-d", $date));
$convertedFromDate = date('Y-m-d', $date);
$convertedToDate = date('Y-m-d', $date + 86400);
foreach ($clientHouses as $clientHouse) {
$olderReport = $this->repository
->findOne(
$clientHouse->client_id,
$clientHouse->house_id,
date('Y-m-d', $date - 86400)
);
$counter = ($olderReport !== null) ? $olderReport->occupied_beds : 0;
$report = $this->repository->exists(
$clientHouse->client_id,
$clientHouse->house_id,
$convertedFromDate
);
$checkins = $this->reservationRepo
->countAmount(
$clientHouse->client_id,
$clientHouse->house_id,
[$convertedFromDate, $convertedToDate],
'CHECK_IN'
);
$checkouts = $this->reservationRepo
->countAmount(
$clientHouse->client_id,
$clientHouse->house_id,
[$convertedFromDate, $convertedToDate],
'CHECK_OUT'
);
if (!$report) {
$this->createTempReportService
->create([
'client_id' => $clientHouse->client_id,
'house_id' => $clientHouse->house_id,
'occupied_beds' => $counter + ($checkins - $checkouts),
'date' => $convertedFromDate
]);
} else {
DB::table('temp_reports')
->where('client_id', $clientHouse->client_id)
->where('house_id', $clientHouse->house_id)
->where('date', $convertedFromDate)
->update([
'occupied_beds' => $counter + ($checkins - $checkouts),
]);
}
}
$date += 60 * 60 * 24;
}
$this->log('GenerateTempReports stop');
}
@Krikis why are you not able to run it? Getting an error? Or didn't you set up a cron job? https://laravel.com/docs/9.x/scheduling#running-the-scheduler
@Sinnbeck with a Cron job seems nothing happens. When I try to call in SSH command: php artisan schedule:work , I'm getting bellow error:
Command "schedule:work" is not defined. Did you mean one of these? queue:work schedule:run
When I try to run: php artisan schedule:run Getting message:
No scheduled commands are ready to run.
So nothing happens...
@Krikis Are you sure its set to run every minute? Show the schedule in the console Kernel.php
And it might be an idea to just run the command manually once, to get the data synced for now php artisan name-of:command
@Sinnbeck Kernel.php schedule command looks as per below: Previously it was ->dailyAt('02:01'); , but I have changed to ->everyMinute(); , but it doesn't work either. Any ideas how I could check or call it from console to try ?
protected function schedule(Schedule $schedule) { $schedule->command('send:email')->dailyAt('15:00'); $schedule->command('generate:temp-reports')->everyMinute(); }
@Sinnbeck I'm able to run this command manual, thanks. But for some reason it do not generate any value from GenerateTempReports.php function and do not insert anything to database. This needs deeper investigation.. and no errors shown....
@Sinnbeck I have figured out with this error. Thank you, it was actually Cron problem after I migrate to another server. But I how now another issue that not able to Generate Invoices... Maybe some ideas could help how I could see more clear Error message , as currently only browser console displays this:
POST https://cvtinklas.lt/api/generateInvoice 500
Error: Request failed with status code 500 at createError (app.js:23859:15) at settle (app.js:24022:12) at XMLHttpRequest.handleLoad (app.js:23392:7) at XMLHttpRequest.sentryWrapped (app.js:10560:23)
@Krikis please close this thread and open a new one with the new issue :)
Please or to participate in this conversation.