Skip to content

Commit

Permalink
Merge pull request #1 from SaminYaser-work/sqlite-conv
Browse files Browse the repository at this point in the history
migrated to sqlite
  • Loading branch information
SaminYaser-work authored Sep 15, 2023
2 parents 1f05b3f + 1eb0057 commit 76c2b08
Show file tree
Hide file tree
Showing 16 changed files with 382 additions and 336 deletions.
11 changes: 3 additions & 8 deletions .env.azure
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,9 @@ LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=m37.h.filess.io
DB_PORT=3305
DB_DATABASE=laravel_boneitthen
DB_USERNAME=laravel_boneitthen
DB_PASSWORD=d66358e56e56dae9a9ff3874b02d5649235a0529

AI_API=agrosmartai.azurewebsites.net
DB_CONNECTION=sqlite

AI_API=https://agrosmartai.azurewebsites.net

DEBUGBAR_ENABLED=false

Expand Down
120 changes: 60 additions & 60 deletions .github/workflows/master_agrosmart.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions

name: Build and deploy PHP app to Azure Web App - agrosmart

on:
push:
branches:
- master
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'

- name: Check if composer.json exists
id: check_files
uses: andstor/file-existence-action@v1
with:
files: 'composer.json'

- name: Run composer install if composer.json exists
if: steps.check_files.outputs.files_exists == 'true'
run: composer validate --no-check-publish && composer install --prefer-dist --no-progress

- name: Upload artifact for deployment job
uses: actions/upload-artifact@v2
with:
name: php-app
path: .

deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}

steps:
- name: Download artifact from build job
uses: actions/download-artifact@v2
with:
name: php-app

- name: 'Deploy to Azure Web App'
uses: azure/webapps-deploy@v2
id: deploy-to-webapp
with:
app-name: 'agrosmart'
slot-name: 'Production'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_8B41D78513FE47FD977E803404D20A3C }}
package: .
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions

name: Build and deploy PHP app to Azure Web App - agrosmart

on:
push:
branches:
- master
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'

- name: Check if composer.json exists
id: check_files
uses: andstor/file-existence-action@v1
with:
files: 'composer.json'

- name: Run composer install if composer.json exists
if: steps.check_files.outputs.files_exists == 'true'
run: composer validate --no-check-publish && composer install --prefer-dist --no-progress --optimize-autoloader --no-dev

- name: Upload artifact for deployment job
uses: actions/upload-artifact@v2
with:
name: php-app
path: .

deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}

steps:
- name: Download artifact from build job
uses: actions/download-artifact@v2
with:
name: php-app

- name: 'Deploy to Azure Web App'
uses: azure/webapps-deploy@v2
id: deploy-to-webapp
with:
app-name: 'agrosmart'
slot-name: 'Production'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_8B41D78513FE47FD977E803404D20A3C }}
package: .
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,22 @@ protected function getOptions(): array
return [];
}

// $data = AnimalProduction::query()
// ->where('type', '=', 'Milk')
// ->selectRaw('EXTRACT( YEAR_MONTH FROM `date` ) as m, SUM(quantity) as quantity')
// ->groupByRaw('m')
// ->get()
// ->toArray();

$data = AnimalProduction::query()
->where('type', '=', 'Milk')
->selectRaw('EXTRACT( YEAR_MONTH FROM `date` ) as m, SUM(quantity) as quantity')
->groupByRaw('m')
->selectRaw("strftime('%Y-%m', `date`) as m, SUM(quantity) as quantity")
->groupByRaw("m")
->get()
->toArray();

$data = array_map(function ($item) {
$item['m'] = Carbon::createFromFormat('Ym', $item['m'])->format('F Y');
$item['m'] = Carbon::createFromFormat('Y-m', $item['m'])->format('F Y');
return $item;
}, $data);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,25 @@ public function __construct()
{
parent::__construct();

// $this->year_months = AnimalProduction::query()
// ->where('type', '=', 'Milk')
// ->distinct()
// ->selectRaw('EXTRACT( YEAR_MONTH FROM `date` ) as date')
// ->orderBy('date', 'desc')
// ->get()
// ->toArray();

$this->year_months = AnimalProduction::query()
->where('type', '=', 'Milk')
->distinct()
->selectRaw('EXTRACT( YEAR_MONTH FROM `date` ) as date')
->selectRaw("strftime('%Y-%m', `date`) as date")
->orderBy('date', 'desc')
->get()
->pluck('date')
->toArray();

$this->year_months = array_map(function ($year_month) {
return Carbon::createFromFormat('Ym', $year_month['date'])->format('F Y');
return Carbon::createFromFormat('Y-m', $year_month)->format('F Y');
}, $this->year_months);
}

Expand Down
3 changes: 1 addition & 2 deletions app/Filament/Resources/CropProjectResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ public static function form(Form $form): Form
Forms\Components\Select::make('crop_name')
->label('Crop')
->options(array_combine(Enums::$CropName, Enums::$CropName))
->required()
->disabledOn('edit'),
->required(),

Forms\Components\Select::make('field_id')
->options(function (Closure $get) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,25 @@ public function mount(): void

public function submit(): void
{
$image = $this->image[array_key_first($this->image)];
$file_path = $image->getRealPath();
$response = \Http::attach(
'file', file_get_contents($file_path), $image->getFilename()
)->post(env('AI_API') . '/dd');
$res = $response->json();
foreach ($res as $r) {
if(!array_key_exists('confidence', $r)){
$this->hasError = true;
return;
}
if ($r['confidence'] > 0) {
$this->res[] = $r;
if (!is_array($this->image)) {
return;
}
foreach ($this->image as $key=>$image) {
$file_path = $image->getRealPath();
$response = \Http::attach(
'file', file_get_contents($file_path), $image->getFilename()
)->post(env('AI_API') . '/dd');
$res = $response->json();
foreach ($res as $r) {
if(!array_key_exists('confidence', $r)){
$this->hasError = true;
return;
}
if ($r['confidence'] > 0) {
$this->res[] = $r;
}
}
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ private function getData()
->get()
->toArray();

// dd($currWeekData);

$prevWeekAvgData = PondWeeklyReport::query()
->where('date', $weeks[1])
->selectRaw('AVG(production) as production, AVG(yield) as yield, AVG(survival_rate) as survival_rate, AVG(average_weight) as average_weight, AVG(average_growth) as average_growth, AVG(dissolved_oxygen) as dissolved_oxygen, AVG(water_level) as water_level, AVG(water_temperature) as water_temperature, AVG(ph) as ph, AVG(turbidity) as turbidity, AVG(ammonia) as ammonia, AVG(nitrate) as nitrate')
Expand Down
10 changes: 5 additions & 5 deletions app/Filament/Resources/SalaryResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ public static function table(Table $table): Table
Tables\Columns\TextColumn::make('month')
->getStateUsing(fn($record, $column) => date('F', mktime(0, 0, 0, $record->month, 10))),
Tables\Columns\TextColumn::make('year'),
Tables\Columns\TextColumn::make('base')->sortable()->money('bdt'),
Tables\Columns\TextColumn::make('overtime')->sortable()->money('bdt'),
Tables\Columns\TextColumn::make('penalty')->sortable()->money('bdt'),
Tables\Columns\TextColumn::make('bonus')->sortable()->money('bdt'),
Tables\Columns\TextColumn::make('total')->sortable()->money('bdt'),
Tables\Columns\TextColumn::make('base')->sortable()->money('bdt', true),
Tables\Columns\TextColumn::make('overtime')->sortable()->money('bdt', true),
Tables\Columns\TextColumn::make('penalty')->sortable()->money('bdt', true),
Tables\Columns\TextColumn::make('bonus')->sortable()->money('bdt', true),
Tables\Columns\TextColumn::make('total')->sortable()->money('bdt', true),
Tables\Columns\IconColumn::make('paid')->boolean()
->trueIcon('heroicon-o-check-circle')
->falseIcon('heroicon-o-x-circle')
Expand Down
4 changes: 2 additions & 2 deletions app/Filament/Resources/SalaryResource/Widgets/SalaryStats.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public function __construct($id = null)
protected function getCards(): array
{

$salary_due = money($this->salaryController->getSalaryDue(), 'bdt');
$salary_due = money($this->salaryController->getSalaryDue(), 'bdt', true);

$total_salary_paid = money($this->salaryController->getTotalSalaryPaid(), 'bdt');
$total_salary_paid = money($this->salaryController->getTotalSalaryPaid(), 'bdt', true);

return [
Card::make('Salary Due', $salary_due)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Filament\Resources\WorkerResource\Widgets;

use App\Http\Controllers\SalaryController;
use App\Models\Attendance;
use App\Models\Worker;
use Filament\Tables;
use Filament\Widgets\TableWidget as BaseWidget;
Expand Down Expand Up @@ -53,7 +54,7 @@ protected function getTableFilters(): array
])
->placeholder('Select Month')
->query(function (Builder $query, array $data) {
$query->whereMonth('attendances.date', $data['value']);
$query->whereMonth('date', $data['value']);
})
->default(date('m')),
// Tables\Filters\SelectFilter::make('year')
Expand Down
2 changes: 1 addition & 1 deletion app/Filament/Widgets/OrderPerMonthChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected function getOptions(): array
}

$data = SalesOrder::query()
->selectRaw('MONTH(order_date) month, count(MONTH(order_date)) as total_orders')
->selectRaw("strftime('%m', order_date) as month, count(strftime('%m', order_date)) as total_orders")
->groupBy('month')
->orderBy('month')
->get()
Expand Down
8 changes: 6 additions & 2 deletions app/Filament/Widgets/TempLineChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ protected function getOptions(): array
return [];
}

$response = Http::get('https://api.open-meteo.com/v1/forecast?latitude=23.7104&longitude=90.4074&hourly=temperature_2m,relativehumidity_2m,rain');
$data = $response->json();
try {
$response = Http::get('https://api.open-meteo.com/v1/forecast?latitude=23.7104&longitude=90.4074&hourly=temperature_2m,relativehumidity_2m,rain');
$data = $response->json();
} catch (\Exception $e) {
return [];
}


return [
Expand Down
65 changes: 25 additions & 40 deletions app/Http/Controllers/SalaryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,36 @@ class SalaryController extends Controller
{
public function getSalaryReportIndividual($worker_id)
{
return Attendance::query()
->select([
'date',
\DB::raw('@hours_worked := TIMESTAMPDIFF(HOUR, time_in, time_out) as hours_worked,
@diff := @hours_worked - workers.expected_hours as diff,
IF(time_in IS NULL OR time_out IS NULL, @base := 0, @base := ROUND(workers.salary * workers.expected_hours, 2)) AS base,
IF(@diff > 0, @ot := ROUND(workers.over_time_rate * @diff, 2), @ot:=0) AS overtime,
IF(@diff < 0, @pen := ROUND(workers.salary * @diff, 2) * -1, @pen := 0) AS penalty,
@total := ROUND(@base + @ot - @pen, 2) AS total')
])
->join('workers', 'attendances.worker_id', '=', 'workers.id')
// return Attendance::query()
// ->select([
// 'date',
// \DB::raw('@hours_worked := TIMESTAMPDIFF(HOUR, time_in, time_out) as hours_worked,
// @diff := @hours_worked - workers.expected_hours as diff,
// IF(time_in IS NULL OR time_out IS NULL, @base := 0, @base := ROUND(workers.salary * workers.expected_hours, 2)) AS base,
// IF(@diff > 0, @ot := ROUND(workers.over_time_rate * @diff, 2), @ot:=0) AS overtime,
// IF(@diff < 0, @pen := ROUND(workers.salary * @diff, 2) * -1, @pen := 0) AS penalty,
// @total := ROUND(@base + @ot - @pen, 2) AS total')
// ])
// ->join('workers', 'attendances.worker_id', '=', 'workers.id')
// ->where('attendances.worker_id', $worker_id);


$subquery = \DB::table('attendances')
->selectRaw("date,
strftime('%H', time_out) - strftime('%H', time_in) as hours_worked,
CASE WHEN time_in IS NULL OR time_out IS NULL THEN 0 ELSE ROUND(workers.salary * workers.expected_hours, 2) END AS base,
CASE WHEN (strftime('%H', time_out) - strftime('%H', time_in)) > workers.expected_hours THEN ROUND(workers.over_time_rate * ((strftime('%H', time_out) - strftime('%H', time_in)) - workers.expected_hours), 2) ELSE 0 END AS overtime,
CASE WHEN (strftime('%H', time_out) - strftime('%H', time_in)) < workers.expected_hours THEN ROUND(workers.salary * ((strftime('%H', time_out) - strftime('%H', time_in)) - workers.expected_hours), 2) * -1 ELSE 0 END AS penalty")
->leftJoin('workers', 'attendances.worker_id', '=', 'workers.id')
->where('attendances.worker_id', $worker_id);
}

public function getSalaryReportIndividualWithSum($worker_id)
{
$data = $this->getSalaryReportIndividual($worker_id)->get();
$agg = $data->groupBy('worker_id')->sum('base')->sum('overtime')->sum('penalty')->sum('total')->get();
}

public function getSalaryMonthly($farm_id)
{
return Attendance::query()
->select([
'date',
\DB::raw('@hours_worked := TIMESTAMPDIFF(HOUR, time_in, time_out) as hours_worked,
@diff := @hours_worked - workers.expected_hours as diff,
IF(time_in IS NULL OR time_out IS NULL, @base := 0, @base := ROUND(workers.salary * workers.expected_hours, 2)) AS base,
IF(@diff > 0, @ot := ROUND(workers.over_time_rate * @diff, 2), @ot:=0) AS overtime,
IF(@diff < 0, @pen := ROUND(workers.salary * @diff, 2) * -1, @pen := 0) AS penalty,
@total := ROUND(@base + @ot - @pen, 2) AS total')
])
->join('workers', 'attendances.worker_id', '=', 'workers.id')
->where('workers.farm_id', $farm_id)
->groupBy('attendances.date');
->fromRaw("({$subquery->toSql()}) as subquery")
->mergeBindings($subquery)
->selectRaw("date, SUM(COALESCE(base, 0) + COALESCE(overtime, 0) - COALESCE(penalty, 0)) AS total, hours_worked, base, overtime, penalty")
->groupBy('date');
}

public function TotalSalaryByMonth() {
return Salary::query()
->select([
'month',
\DB::raw('SUM(total) as total')
])
->groupBy('month');
}

public function getSalaryDue()
{
Expand Down
Loading

0 comments on commit 76c2b08

Please sign in to comment.