Compare commits

..

No commits in common. "master" and "miseEnPlace" have entirely different histories.

124 changed files with 3880 additions and 8067 deletions

View file

@ -3,7 +3,6 @@ APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
APP_DOMAIN=
LOG_CHANNEL=stack
@ -38,6 +37,7 @@ CAFEL_PASSWORD=
MAIL_INVALID_CAFEL_DATA=equipe.web@ldc.fr
MAIL_INVALID_CAFEL_DATA_IMAGE=equipe.web@ldc.fr
MAIL_INVALID_XML=equipe.web@ldc.fr
MAIL_LIST_SERVICEWEB=equipe.web@ldc.fr
## LDC WEB STATUS CHECKER
LDC_STATUS_CHECKER_API_KEY="MY_KEY"
@ -45,9 +45,6 @@ LDC_STATUS_CHECKER_UUID="UUID_PROJECT"
## LDC WEB ADMIN SECURE
LDC_WEB_API_KEY="MY_KEY"
## GOOGLE
ANALYTICS_GOOGLE_ID=
# TERRE D'ACTION MODAL (YYYY-MM-DD)
TERRE_ACTION_START_DATE=
TERRE_ACTION_END_DATE=

1
.gitignore vendored
View file

@ -18,4 +18,3 @@ Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log
auth.json

View file

@ -1,12 +1,46 @@
include:
- project: 'ldc-web/shared-ci'
ref: 'main'
file: 'lint/lint7.3.yml'
- project: 'ldc-web/shared-ci'
ref: 'main'
file: 'security/security7.3.yml'
image: $CI_REGISTRY/service-web-lab/ldc-web-images-docker/ldcweb-qa:php7.3-1.0
stages:
- lint
- security
- Security
- CodingStandards
composer-security:
stage: Security
script:
- local-php-security-checker --format=json --path=./composer.lock > composer-security-checker-report.json
artifacts:
when: on_failure
expose_as: 'composer-security-checker'
paths:
- composer-security-checker-report.json
allow_failure: true
npm-security:
stage: Security
script:
- audit-ci -p npm -o json > npm-security-checker-report.json
artifacts:
when: on_failure
expose_as: 'npm-security-checker'
paths:
- npm-security-checker-report.json
allow_failure: true
phpcs:
stage: CodingStandards
before_script:
- composer config gitlab-token.gitlab.com $CI_DEPLOY_USER $CI_DEPLOY_PASSWORD
- composer install
cache:
paths:
- vendor/
script:
- vendor/bin/phpcs --report=junit --report-file=phpcs-report.xml
artifacts:
when: on_failure
expose_as: 'phpcs'
paths:
- phpcs-report.xml
reports:
junit: phpcs-report.xml
allow_failure: false

View file

@ -1,11 +0,0 @@
## Comportement constaté
## Comportement attendu
## Solution envisagée
## Étapes pour la reproduction du bug
*

View file

@ -1,7 +0,0 @@
## Présentation du besoin
## Implémentation
## Maquettes, documentations...

View file

@ -30,11 +30,11 @@ class Kernel extends ConsoleKernel
protected function schedule(Schedule $schedule)
{
// * Jobs cafel sur queue cafel
$schedule->job(CafelFoodJob::class, 'cafel')->onOneServer()->dailyAt('22h30');
$schedule->job(CafelBeaVolJob::class, 'cafel')->onOneServer()->dailyAt('22h45');
$schedule->job(CafelMepEggJob::class, 'cafel')->onOneServer()->dailyAt('23h00');
$schedule->job(CafelEggBreederJob::class, 'cafel')->onOneServer()->dailyAt('23h15');
$schedule->job(CafelPoultryBreederJob::class, 'cafel')->onOneServer()->dailyAt('23h30');
$schedule->job(CafelFoodJob::class, 'cafel')->onOneServer()->everyThreeHours();
$schedule->job(CafelBeaVolJob::class, 'cafel')->onOneServer()->everyThreeHours();
$schedule->job(CafelMepEggJob::class, 'cafel')->onOneServer()->everyThreeHours();
$schedule->job(CafelEggBreederJob::class, 'cafel')->onOneServer()->everyThreeHours();
$schedule->job(CafelPoultryBreederJob::class, 'cafel')->onOneServer()->everyThreeHours();
$schedule->job(XmlFluxEggJob::class, 'tracea')->onOneServer()->dailyAt('02:00');
$schedule->job(XmlFluxPoultryJob::class, 'tracea')->onOneServer()->dailyAt('22:00');

View file

@ -4,8 +4,8 @@ namespace App\Exceptions;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Sentry\Laravel\Integration;
use Throwable;
use Kwaadpepper\ExceptionHandler\Exceptions\ExceptionHandler;
class Handler extends ExceptionHandler
{
@ -27,19 +27,18 @@ class Handler extends ExceptionHandler
];
/**
* Register the exception handling callbacks for the application.
* Report or log an exception.
*
* @param \Throwable $exception
* @return void
*/
public function register()
public function report(Throwable $exception)
{
$this->reportable(function (\Throwable $e) {
if ($e instanceof CafelApiImageFetchException) {
$this->reportCafelApiImageErrorException($e);
return;
}
Integration::captureUnhandledException($e);
});
if ($exception instanceof CafelApiImageFetchException) {
$this->reportCafelApiImageErrorException($exception);
return;
}
parent::report($exception);
}
/**

View file

@ -27,7 +27,7 @@ class EggController extends Controller
$month = $date[1];
$moba = TraceaEgg::where('ede_code', '=', $code)
->where('dcr', Carbon::createFromDate(null, $month, $day)->format('Y-m-d'))
->whereDate('dcr', Carbon::createFromDate(null, $month, $day)->toDate())
->orderBy('box_code', 'DESC')->first();
if (!$moba) {
@ -49,7 +49,7 @@ class EggController extends Controller
$mobas = TraceaEgg::where('box_code', $id)->orderBy('box_code', 'DESC')->first();
if (!$mobas) {
return redirect()->route('egg.search');
return redirect('/search');
}
$edes = $mobas->code_edes;
@ -84,11 +84,8 @@ class EggController extends Controller
$inuavs = $eleveurs->pluck('inuavs')->flatten(1);
$mep = CafelEggMiseEnPlace::query();
collect($inuavs)->map(function ($inuav) use ($mep) {
$mep->where('inuav_codes', 'LIKE', "%{$inuav}%");
});
$mep = $mep->where('transfert_date', '<', $datePonte)
$mep = CafelEggMiseEnPlace::whereIn('inuav_code', $inuavs)
->where('transfert_date', '<', $datePonte)
->orderBy('transfert_date', 'DESC')->first();
if ($mep) {

View file

@ -3,10 +3,8 @@
namespace App\Http\Controllers\Fo;
use App\Http\Controllers\Controller;
use App\Http\Requests\Fo\Ajax\GetDistributionRequest;
use App\Http\Requests\Fo\SearchPoultryTraceaRequest;
use App\Models\TraceaPoultry;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Session;
@ -70,34 +68,19 @@ class TraceaPoultryController extends Controller
\redirect()->route('poultry.search')->throwResponse();
}
// ! Test that breeder, food and mep are available
if (!$traceaPoultry->mep or !$traceaPoultry->food or !$traceaPoultry->breeder) {
$distributionPicture = $this->getDistributionPicture($traceaPoultry->sign);
// ! Test that food and mep are available
if (!$traceaPoultry->mep or !$traceaPoultry->food) {
return \view('front.poultry.unavailable');
}
return view('front.poultry.show', compact(
'traceaPoultry'
'traceaPoultry',
'distributionPicture'
));
}
/**
* Get Distribution Info
*
* @param \App\Http\Requests\Fo\Ajax\GetDistributionRequest $request
* @return \Illuminate\Http\JsonResponse
*/
public function getDistribution(GetDistributionRequest $request): JsonResponse
{
/** @var \App\Models\TraceaPoultry */
$traceaPoultry = TraceaPoultry::where('order_num', $request->ordernum)
->where('external_code_lot', $request->codelot)->firstOrFail();
return \response()->json([
'exp_date' => $traceaPoultry->exp_date,
'sign' => $traceaPoultry->sign,
'picture' => $this->getDistributionPicture($traceaPoultry->sign)
]);
}
/**
* Get distribution sign picture name if exists.
*

View file

@ -14,7 +14,6 @@ class TrustHosts extends Middleware
public function hosts()
{
return [
\config('app.egg_domain'),
$this->allSubdomainsOfApplicationUrl(),
];
}

View file

@ -1,31 +0,0 @@
<?php
namespace App\Http\Requests\Fo\Ajax;
use Illuminate\Foundation\Http\FormRequest;
class GetDistributionRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return boolean
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'codelot' => 'required|numeric|digits:10',
'ordernum' => 'required|numeric|digits:6',
];
}
}

View file

@ -23,7 +23,7 @@ class RemoveOldXmlEntries
}
try {
$q = TraceaEgg::query();
$q->where('dcr', '<=', now()->subMonths(config('tracea.keepEggMonths', 12)));
$q->where('dcr', '<=', now()->subMonths(config('tracea.keepEggMonths', 12)))->destroy();
$q->delete();
} catch (\Exception $e) {
report($e);

View file

@ -11,7 +11,6 @@ use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Str;
use Illuminate\Validation\ValidationException;
abstract class XmlJobs extends XArcadiaFlux
{
@ -175,25 +174,7 @@ abstract class XmlJobs extends XArcadiaFlux
),
LogType::critical()
);
$this->sendInvalidXmlEmail(
$filename,
$e->getPrevious()->getMessage(),
$e->getPrevious()
);
$this->moveToInvalid($filename);
continue;
} catch (ValidationException $e) {
$message = $e->getMessage();
$this->log(
sprintf(
'File %s could not be parsed => %s on line %d',
$filename,
$message,
$e->getLine()
),
LogType::critical()
);
$this->sendInvalidXmlEmail($filename, $e->getMessage(), $e);
$this->sendInvalidXmlEmail($filename, $e);
$this->moveToInvalid($filename);
continue;
} catch (AbortXmlImportException $e) {
@ -206,8 +187,6 @@ abstract class XmlJobs extends XArcadiaFlux
),
LogType::error()
);
$this->sendInvalidXmlEmail($filename, $e->getMessage(), $e);
$this->moveToInvalid($filename);
report($e);
continue;
// * ignore the file
@ -386,12 +365,12 @@ abstract class XmlJobs extends XArcadiaFlux
* Send invalid XML email
*
* @param string $filename
* @param string $message
* @param \Throwable $e
* @return void
*/
protected function sendInvalidXmlEmail(string $filename, string $message, \Throwable $e)
protected function sendInvalidXmlEmail(string $filename, \Throwable $e)
{
$message = $e->getPrevious()->getMessage();
Mail::send('mails.invalidxml', [
'strError' => sprintf(
'File %s could not be parsed => %s on line %d',
@ -400,7 +379,7 @@ abstract class XmlJobs extends XArcadiaFlux
$e->getLine()
),
'filename' => $filename,
'exception' => $e
'exception' => $e->getPrevious()
], function ($m) {
$m->to(
config('mail.contactsList.invalidXml'),

View file

@ -5,9 +5,7 @@ namespace App\Jobs;
use App\Exceptions\CafelApiException;
use App\Exceptions\CafelApiImageFetchException;
use App\Lib\CafelApi\Models\CafelEggBreeder as ApiCafelEggBreeder;
use App\Lib\ToolboxHelper;
use App\Models\CafelEggBreeder;
use Illuminate\Validation\ValidationException;
class CafelEggBreederJob extends CafelJobs
{
@ -18,16 +16,6 @@ class CafelEggBreederJob extends CafelJobs
*/
public function handle()
{
// ! We have to remove all breeders to reimport them all in order to make sure
// ! to delete breeders that dont exists anymore (Api fetch constrain)
// ! vu avec Sylvain 27/10/2022
// * Destroy breeder one by one to trigger destroy event
/** @var \Illuminate\Database\Eloquent\Collection<\App\Models\CafelEggBreeder> */
$eggBreeders = CafelEggBreeder::all();
$eggBreeders->each(function (CafelEggBreeder $breeder) {
$breeder->deleteOrFail();
});
$this->syncWithCafelApi(
ApiCafelEggBreeder::class,
'cafel.ldc.eleveursoeufs',
@ -53,23 +41,8 @@ class CafelEggBreederJob extends CafelJobs
) : null;
} catch (CafelApiImageFetchException | CafelApiException $e) {
report($e);
$validationException = ValidationException::withMessages([
'path_picture_1' => $e->getMessage()
]);
ToolboxHelper::useReflectionToUpdateProperty(
$validationException->validator,
'data',
['path_picture_1' => $row['path_picture_1']]
);
ToolboxHelper::useReflectionToUpdateProperty(
$validationException->validator,
'failedRules',
['path_picture_1' => $e->getMessage()]
);
throw $validationException;
}//end try
$row['path_picture_1'] = null;
}
try {
$row['path_picture_2'] = !empty($row['path_picture_2']) ?
ApiCafelEggBreeder::fetchPicture(
@ -78,23 +51,8 @@ class CafelEggBreederJob extends CafelJobs
) : null;
} catch (CafelApiImageFetchException | CafelApiException $e) {
report($e);
$validationException = ValidationException::withMessages([
'path_picture_2' => $e->getMessage()
]);
ToolboxHelper::useReflectionToUpdateProperty(
$validationException->validator,
'data',
['path_picture_2' => $row['path_picture_2']]
);
ToolboxHelper::useReflectionToUpdateProperty(
$validationException->validator,
'failedRules',
['path_picture_2' => $e->getMessage()]
);
throw $validationException;
}//end try
$row['path_picture_2'] = null;
}
foreach (['exploitation', 'aboutyou', 'vocation', 'likeinjob', 'loue_means'] as $fieldName) {
$row[$fieldName] = !empty($row[$fieldName]) ? $row[$fieldName] : null;

View file

@ -3,8 +3,6 @@
namespace App\Jobs;
use App\Lib\CafelApi\Models\CafelClientModel;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Exception\RequestException;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
@ -72,26 +70,12 @@ abstract class CafelJobs implements ShouldQueue
try {
$saveCallback($row);
} catch (ValidationException $e) {
/** @var \Illuminate\Validation\Validator $validator */
$validator = $e->validator;
/** @var array<string,integer|string> */
$failed = $validator->invalid();
$this->invalidRows[] = collect($row)->put('validation_message', collect($e->errors())
->mapWithKeys(function (array $messages, string $attribute) use ($failed) {
$verifiedValue = '';
if (array_key_exists($attribute, $failed)) {
$verifiedValue = ' Valeur vérifiée : ' . \json_encode($failed[$attribute]);
}
return [
$attribute => collect($messages)->implode(', ') . $verifiedValue
];
->mapWithKeys(function (array $messages, string $attribute) {
return [$attribute => collect($messages)->implode(', ')];
})->implode(' '))->all();
} catch (ConnectException | RequestException $e) {
// ! Guzzle SSL Error connection failure
\report($e);
$this->invalidRows[] = collect($row)->put('validation_message', $e->getMessage())->all();
}//end try
}//end foreach
}
}
} while (!empty($result));
}

View file

@ -23,11 +23,6 @@ class CafelMepEggJob extends CafelJobs
'dateFin' => now()->format('Y-m-d')
],
function (array $row) {
// * Explode inuav
if (\array_key_exists('inuav_codes', $row)) {
$row['inuav_codes'] = explode(',', $row['inuav_codes']);
}
// * Validate row data
CafelMepEgg::validateDataRow($row);

View file

@ -23,11 +23,6 @@ class CafelMepPoultryJob extends CafelJobs
'dateFin' => now()->format('Y-m-d')
],
function (array $row) {
// * Explode inuav
if (\array_key_exists('inuav_codes', $row)) {
$row['inuav_codes'] = explode(',', $row['inuav_codes']);
}
// * Validate row data
CafelMepPoultry::validateDataRow($row);

View file

@ -5,9 +5,7 @@ namespace App\Jobs;
use App\Exceptions\CafelApiException;
use App\Exceptions\CafelApiImageFetchException;
use App\Lib\CafelApi\Models\CafelPoultryBreeder as ApiCafelPoultryBreeder;
use App\Lib\ToolboxHelper;
use App\Models\CafelPoultryBreeder;
use Illuminate\Validation\ValidationException;
class CafelPoultryBreederJob extends CafelJobs
{
@ -18,16 +16,6 @@ class CafelPoultryBreederJob extends CafelJobs
*/
public function handle()
{
// ! We have to remove all breeders to reimport them all in order to make sure
// ! to delete breeders that dont exists anymore (Api fetch constrain)
// ! vu avec Sylvain 27/10/2022
// * Destroy breeder one by one to trigger destroy event
/** @var \Illuminate\Database\Eloquent\Collection<\App\Models\CafelEggBreeder> */
$poultryBreeders = CafelPoultryBreeder::all();
$poultryBreeders->each(function (CafelPoultryBreeder $breeder) {
$breeder->deleteOrFail();
});
$this->syncWithCafelApi(
ApiCafelPoultryBreeder::class,
'cafel.ldc.eleveursvolailles',
@ -53,23 +41,8 @@ class CafelPoultryBreederJob extends CafelJobs
) : null;
} catch (CafelApiImageFetchException | CafelApiException $e) {
report($e);
$validationException = ValidationException::withMessages([
'path_picture_1' => $e->getMessage()
]);
ToolboxHelper::useReflectionToUpdateProperty(
$validationException->validator,
'data',
['path_picture_1' => $row['path_picture_1']]
);
ToolboxHelper::useReflectionToUpdateProperty(
$validationException->validator,
'failedRules',
['path_picture_1' => $e->getMessage()]
);
throw $validationException;
}//end try
$row['path_picture_1'] = null;
}
try {
$row['path_picture_2'] = !empty($row['path_picture_2']) ?
ApiCafelPoultryBreeder::fetchPicture(
@ -78,23 +51,8 @@ class CafelPoultryBreederJob extends CafelJobs
) : null;
} catch (CafelApiImageFetchException | CafelApiException $e) {
report($e);
$validationException = ValidationException::withMessages([
'path_picture_2' => $e->getMessage()
]);
ToolboxHelper::useReflectionToUpdateProperty(
$validationException->validator,
'data',
['path_picture_2' => $row['path_picture_2']]
);
ToolboxHelper::useReflectionToUpdateProperty(
$validationException->validator,
'failedRules',
['path_picture_2' => $e->getMessage()]
);
throw $validationException;
}//end try
$row['path_picture_2'] = null;
}
foreach (['issue_1', 'issue_2'] as $fieldName) {
$row[$fieldName] = !empty($row[$fieldName]) ? $row[$fieldName] : null;

View file

@ -25,11 +25,7 @@ abstract class CafelBeaVol extends CafelClientModel
// Eg Score A .
'bea_code' => 'required|string|min:2|max:10',
// Eg 19377/0 .
'batch_code' => [
'required',
'max:10',
'regex:/^[0-9A-Z]+\/(?:\d|[A-Z])$/',
],
'batch_code' => 'required|max:10|regex:/^[0-9A-Z]*\/\d$/',
'last_audit_date' => 'required|date_format:Y-m-d'
];

View file

@ -125,7 +125,7 @@ abstract class CafelClientModel implements \JsonSerializable
* @return array
* @throws \Illuminate\Validation\ValidationException If data does not validate.
*/
protected static function validateData(array $data, array $rules): array
protected function validateData(array $data, array $rules): array
{
return Validator::validate($data, $rules);
}
@ -228,25 +228,15 @@ abstract class CafelClientModel implements \JsonSerializable
// * Filter Keys using intersection
\extract(\array_intersect_key($response->body, ['Ext' => '', 'Name' => '', 'Data' => '']));
// * Create temp file and get its absolute path
if (!($tempFile = tmpfile())) {
new \RuntimeException('Could not create temp file');
}
$filePath = ToolboxHelper::storeImage(
return ToolboxHelper::storeImage(
$folder,
FileHelper::fromBase64(
$tempFile,
Str::lower($Name),
Str::lower($Ext),
$Data
),
false
);
// * Closing the file will cause to remove it from temp dir!
fclose($tempFile);
return $filePath;
}
}

View file

@ -17,7 +17,7 @@ abstract class CafelEggBreeder extends CafelClientModel
* @var array
*/
public const UNIQUE_COLUMN_KEYS = [
'cafel_code', 'ede_code'
'cafel_code'
];
/**
@ -43,7 +43,7 @@ abstract class CafelEggBreeder extends CafelClientModel
* 2 chiffres qui représentent le numéro d’ordre de chaque atelier dans une même exploitation
* eg : 1FRZFC01
*/
'ede_code' => 'required|regex:/^[0-3][A-Z]{5}\d\d$/',
'ede_code' => 'required|regex:/[0-3][A-Z]{5}\d\d/',
// Valeurs possibles pour civility : 1 M, 2 MME, 3 EUX, 4 ELLES .
'civility' => ['required', [EnumIsValidRule::class, BreederCivilty::class]],
'lastname' => 'required|string|min:1|max:255',

View file

@ -28,11 +28,7 @@ abstract class CafelFood extends CafelClientModel
// 1 Pondeuse ou 2 Poulet .
'food_type' => ['required', [EnumIsValidRule::class, FoodType::class]],
// Eg 19377/0 .
'batch_code' => [
'required',
'max:10',
'regex:/^[0-9A-Z]+\/(?:\d|[A-Z])$/',
],
'batch_code' => 'required|max:10|regex:/^[0-9A-Z]*\/\d$/',
'delivery_date' => 'required|date_format:Y-m-d'
];

View file

@ -22,16 +22,10 @@ abstract class CafelMepEgg extends CafelClientModel
* @var array
*/
protected static $validationRules = [
// Eg V072FXT (un seul ou plusieurs separe par une virgule).
'inuav_codes' => 'required|array',
// Eg V072FXT (un seul par ligne).
'inuav_codes.*' => 'required|string|regex:/^[A-Z]\d{3}[A-Z]{3}$/',
'inuav_code' => 'required|string|regex:/^[A-Z]\d{3}[A-Z]{3}$/',
// Eg 19377/0 .
'batch_code' => [
'required',
'max:10',
'regex:/^[0-9A-Z]+\/(?:\d|[A-Z])$/',
],
'batch_code' => 'required|max:10|regex:/^[0-9A-Z]*\/\d$/',
'transfert_date' => 'required|date_format:Y-m-d'
];
@ -41,7 +35,7 @@ abstract class CafelMepEgg extends CafelClientModel
* @var array
*/
protected static $columnsTranslations = [
'Inuav_code' => 'inuav_codes',
'Inuav_code' => 'inuav_code',
'Batch_code' => 'batch_code',
'Transfert_date' => 'transfert_date'
];

View file

@ -22,16 +22,10 @@ abstract class CafelMepPoultry extends CafelClientModel
* @var array
*/
protected static $validationRules = [
// Eg V072FXT (un seul ou plusieurs separe par une virgule).
'inuav_codes' => 'required|array',
// Eg V072FXT (un seul par ligne).
'inuav_codes.*' => 'required|string|regex:/^[A-Z]\d{3}[A-Z]{3}$/',
'inuav_code' => 'required|string|regex:/^[A-Z]\d{3}[A-Z]{3}$/',
// Eg 19377/0 .
'batch_code' => [
'required',
'max:10',
'regex:/^[0-9A-Z]+\/(?:\d|[A-Z])$/',
],
'batch_code' => 'required|max:10|regex:/^[0-9A-Z]*\/\d$/',
'transfert_date' => 'required|date_format:Y-m-d'
];
@ -41,7 +35,7 @@ abstract class CafelMepPoultry extends CafelClientModel
* @var array
*/
protected static $columnsTranslations = [
'Inuav_code' => 'inuav_codes',
'Inuav_code' => 'inuav_code',
'Batch_code' => 'batch_code',
'Transfert_date' => 'transfert_date'
];

View file

@ -105,7 +105,7 @@ class ApiInterface
*
* @param \App\Lib\CafelApi\Transport\Request $request
* @return \App\Lib\CafelApi\Transport\Response
* @throws \App\Exceptions\CafelApiException If reponse status is KO or not Json.
* @throws \App\Exceptions\CafelApiException If reponse status is KO.
*/
public function call(Request $request): Response
{
@ -122,9 +122,8 @@ class ApiInterface
/**
* Process request
*
* @param \App\Lib\CafelApi\Transport\Request $request
* @return \App\Lib\CafelApi\Transport\Response
* @throws \App\Exceptions\CafelApiException If HTTP response body in not JSON.
* @param Request $request
* @return Response
*/
private function processRequest(Request $request): Response
{
@ -137,13 +136,13 @@ class ApiInterface
$status = in_array($response->getStatusCode(), [200, 201]) ?
ApiStatus::OK() : ApiStatus::KO();
return new Response($status, $response, $request);
return new Response($status, $response);
}
/**
* Add spécific headers to the request
*
* @param \App\Lib\CafelApi\Transport\Request $request
* @param Request $request
* @return void
*/
private function setHeaders(Request &$request): void

View file

@ -56,10 +56,9 @@ class Response
*
* @param \App\Enums\ApiStatus $status
* @param \Psr\Http\Message\ResponseInterface $response
* @param \App\Lib\CafelApi\Transport\Request $request
* @throws \App\Exceptions\CafelApiException If HTTP response body in not JSON.
*/
public function __construct(ApiStatus $status, ResponseInterface $response, Request $request)
public function __construct(ApiStatus $status, ResponseInterface $response)
{
$this->response = $response;
$this->status = $status;
@ -75,18 +74,9 @@ class Response
// * Body should be json data.
if (($decodedJson = $this->tryDecodeJson($this->body->getContents())) === false) {
if (in_array(config('app.env'), ['testing', 'local'])) {
dump(
'should have been json',
$this->httpCode,
$this->status,
$this->headers,
$request->uri,
(string)$this->body
);
dump((string)$this->body);
}
throw new CafelApiException(
"The Api should have returned JSON data '{$request->uri}'"
);
throw new CafelApiException('The Api should have returned JSON data');
}
$this->body = $decodedJson;

View file

@ -1,190 +0,0 @@
<?php
namespace App\Lib;
class ExceptionsHelper
{
/**
* Handle sentry event
*
* @param \Sentry\Event $event
* @return null|\Sentry\Event
*/
public static function sentryEventHandler(\Sentry\Event $event): ?\Sentry\Event
{
// Remove unwanted reports.
$event->setModules([]);
$event->setOsContext(null);
/** @var \Sentry\ExceptionDataBag[] */
$exceptionBag = [];
foreach ($event->getExceptions() as $exceptionDataBag) {
$exceptionBag[] = self::getAnonymizedSentryException($exceptionDataBag);
}
$event->setExceptions($exceptionBag);
return $event;
}
/**
* Anonimize Sentry Exception bag
*
* @param \Sentry\ExceptionDataBag $exceptionDataBag
* @return \Sentry\ExceptionDataBag
*/
private static function getAnonymizedSentryException(
\Sentry\ExceptionDataBag $exceptionDataBag
): \Sentry\ExceptionDataBag {
$exceptionDataBag->setValue(self::getAnonymizedMessage($exceptionDataBag->getValue()));
if ($stackTrace = $exceptionDataBag->getStacktrace()) {
$exceptionDataBag->setStacktrace(self::getAnonymizedSentryStackTrace($stackTrace));
}
return $exceptionDataBag;
}
/**
* Anonymise sentry stacktrace
*
* @param \Sentry\Stacktrace $stackTrace
* @return \Sentry\Stacktrace
*/
private static function getAnonymizedSentryStackTrace(\Sentry\Stacktrace $stackTrace): \Sentry\Stacktrace
{
/** @var \Sentry\Frame[] */
$frames = \array_reverse($stackTrace->getFrames(), true);
$i = \count($frames) - 1;
// * Remove all but keep first (index.php).
while ($i-- > 0) {
$stackTrace->removeFrame(count($stackTrace->getFrames()) - 1);
}
foreach ($frames as $index => $frame) {
$frame->setPostContext([]);
$frame->setPreContext([]);
$frame->setContextLine('');
$frame->setVars(self::getAnonymizedSentryParams($frame->getVars()));
$stackTrace->addFrame($frame);
if ($index === 0) {
$stackTrace->removeFrame(count($stackTrace->getFrames()) - 1);
}
}
return $stackTrace;
}
/**
* Get anonymized sentry params
*
* @param mixed[] $params
* @return string[]
*/
private static function getAnonymizedSentryParams(array $params): array
{
foreach ($params as &$param) {
$type = \strtolower(\gettype($param));
if (\is_string($param)) {
$type = \explode(' ', \trim($param))[0] ?? null;
}
switch ($type) {
case 'Lambda':
case 'Object':
continue 2;
case 'array':
$param = sprintf('Array(%d)', \count($param));
continue 2;
default:
if (\is_numeric($param)) {
$param = \ucfirst($type);
continue 2;
}
if (\is_string($param)) {
$param = sprintf('String(%d)', \strlen($param));
continue 2;
}
} //end switch
} //end foreach
return $params;
}
/**
* Anonymize at least Sql queries
*
* @param string $message
* @return string
*/
public static function getAnonymizedMessage(string $message): string
{
$message = \preg_replace('/^(.*)( \(SQL:.*\))$/', '$1', $message) ?? $message;
if ($sqlPos = \strpos($message, 'to use near')) {
$message = \mb_strcut($message, 0, $sqlPos);
}
return $message;
}
/**
* Anonymize stack trace
*
* @param \Throwable $e
* @return string
*/
public static function getAnonymizedStackTrace(\Throwable $e): string
{
$projectPath = \realpath(\sprintf('%s/../', \app_path()));
$traceStack = $e->getTrace();
$traceStr = '';
$maxStackStage = 0;
foreach ($traceStack as $stackStage => $stack) {
$maxStackStage = $stackStage;
$traceStr .= \sprintf(
'#%s %s(%d): ',
$stackStage,
str_replace($projectPath, '', $stack['file'] ?? ''),
$stack['line'] ?? ''
);
if (isset($stack['class'])) {
$traceStr .= "{$stack['class']}->{$stack['function']}(";
if (isset($stack['args'])) {
$traceStr .= self::handleArgs($stack);
}
$traceStr .= ")\n";
} elseif (isset($stack['function'])) {
$traceStr .= "{$stack['function']}(";
if (isset($stack['args'])) {
$traceStr .= self::handleArgs($stack);
}
$traceStr .= ")\n";
}
} //end foreach
$maxStackStage++;
$traceStr .= "#$maxStackStage {main}";
return $traceStr;
}
/**
* Handle Args
*
* @param array $stack
* @return string
*/
public static function handleArgs(array $stack): string
{
$traceArgs = '';
$argsCount = count($stack['args']);
for ($i = 0; $i < $argsCount; $i++) {
$type = \gettype($stack['args'][$i]);
switch ($type) {
case 'object':
$traceArgs .= sprintf('Object(%s)', \get_class($stack['args'][$i]));
break;
case 'array':
$traceArgs .= sprintf('Array(%d)', \count($stack['args'][$i]));
break;
case 'string':
$traceArgs .= sprintf('String(%d)', \strlen($stack['args'][$i]));
break;
default:
$traceArgs .= \gettype($stack['args'][$i]);
}
$traceArgs .= ($i !== ($argsCount - 1) ? ',' : '');
}
return $traceArgs;
}
}

View file

@ -51,18 +51,21 @@ class FileHelper
}
/**
* Generate from base64 blob
* Generate from blob
*
* @param resource $tempFile A temp file where to store data.
* @param string $fileName The target filename.
* @param string $extension The file extension to use.
* @param string $base64String The base64 encode picture.
* @param string $fileName
* @param string $extension
* @param string $base64String
* @return SplFileInfo
* @throws \ErrorException If writing to temp file failed.
* @throws \App\Exceptions\CafelApiImageFetchException If invalid image was given or ext could not be confirmed.
*/
public static function fromBase64($tempFile, string $fileName, string $extension, string $base64String): SplFileInfo
public static function fromBase64(string $fileName, string $extension, string $base64String): SplFileInfo
{
// * Create temp file and get its absolute path
if (!($tempFile = tmpfile())) {
new \ErrorException('Could not create temp file');
}
$tempFilePath = stream_get_meta_data($tempFile)['uri'];
if (!($blob = \base64_decode($base64String, true))) {
@ -90,6 +93,12 @@ class FileHelper
throw new \ErrorException('Could not write on temp file');
}
// Close this file after response is sent.
// Closing the file will cause to remove it from temp director!
app()->terminating(function () use ($tempFile) {
fclose($tempFile);
});
return new SplFileInfo(\storage_path("tmp/$filePath.$extension"));
}
}

View file

@ -12,23 +12,6 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
abstract class ToolboxHelper
{
/**
* Update any prop using reflexion
*
* @param object $object
* @param string $property
* @param mixed $value
* @return void
* @throws \ReflectionException If the class or property does not exist.
*/
public static function useReflectionToUpdateProperty(object &$object, string $property, $value)
{
$refProperty = new \ReflectionProperty(\get_class($object), $property);
$refProperty->setAccessible(true);
$refProperty->setValue($object, $value);
$refProperty->setAccessible(false);
}
/**
* Store an image of different types
*

View file

@ -5,8 +5,6 @@ namespace App\Models;
use App\Enums\BreederCivilty;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
use Illuminate\Validation\ValidationException;
use Kwaadpepper\Enum\Traits\CastsEnums;
@ -99,8 +97,7 @@ class CafelEggBreeder extends Model
{
// * EVENT CLOSURES.
static::creating(function (self $model) {
self::areInuavCodesUniques($model);
self::isEdeCodeUnique($model);
return self::areInuavCodesUniques($model);
});
static::updating(function (self $model) {
if ($model->getRawOriginal('path_picture_1') !== $model->path_picture_1) {
@ -109,16 +106,7 @@ class CafelEggBreeder extends Model
if ($model->getRawOriginal('path_picture_2') !== $model->path_picture_2) {
Storage::delete(\public_path($model->getRawOriginal('path_picture_2')));
}
self::areInuavCodesUniques($model);
self::isEdeCodeUnique($model);
});
static::deleting(function (self $model) {
if ($model->getRawOriginal('path_picture_1')) {
Storage::delete(\public_path($model->getRawOriginal('path_picture_1')));
}
if ($model->getRawOriginal('path_picture_2')) {
Storage::delete(\public_path($model->getRawOriginal('path_picture_2')));
}
return self::areInuavCodesUniques($model);
});
}
@ -149,44 +137,26 @@ class CafelEggBreeder extends Model
/**
* Check if inuav codes are unique
*
* @param self $breeder
* @param self $eleveur
* @return boolean
* @throws \Illuminate\Validation\ValidationException If inuav code is already used.
*/
protected static function areInuavCodesUniques(self $breeder): bool
protected static function areInuavCodesUniques(self $eleveur): bool
{
$q = self::query();
// * Update condition
$q->where(function ($q) use ($breeder) {
foreach ($breeder->inuavs as $inuav) {
$q->orWhere('inuavs', '=', $inuav);
$q->where(function ($q) use ($eleveur) {
foreach ($eleveur->inuavs as $inuav) {
$q->orWhere('inuavs', 'LIKE', "%$inuav%");
}
});
if ($breeder->cafel_code) {
$q->where('cafel_code', '!=', $breeder->cafel_code);
if ($eleveur->cafel_code) {
$q->where('cafel_code', '!=', $eleveur->cafel_code);
}
if ($q->count()) {
throw ValidationException::withMessages([
'inuavs' => 'Les codes INUAVS doinvent être uniques : ' . collect($breeder->inuavs)->implode(',')
throw ValidationException::withMessages(['inuavs' => 'Les codes INUAVS doinvent être uniques'
]);
}
return true;
}
/**
* Check if ede code is unique
*
* @param self $breeder
* @return boolean
* @throws \Illuminate\Validation\ValidationException If ede code is already used.
*/
protected static function isEdeCodeUnique(self $breeder): bool
{
Validator::make([
'ede_code' => $breeder->ede_code
], ['ede_code' => [
Rule::unique($breeder->getTable(), 'ede_code')->ignore($breeder->id)
]])->validate();
return true;
}
}

View file

@ -33,8 +33,7 @@ class CafelEggMiseEnPlace extends Model
* @var array
*/
protected $casts = [
'transfert_date' => 'date',
'inuav_codes' => 'array'
'transfert_date' => 'date'
];
/**
@ -44,7 +43,7 @@ class CafelEggMiseEnPlace extends Model
*/
protected $fillable = [
'batch_code',
'inuav_codes',
'inuav_code',
'transfert_date'
];
}

View file

@ -94,14 +94,6 @@ class CafelPoultryBreeder extends Model
}
return self::areInuavCodesUniques($model);
});
static::deleting(function (self $model) {
if ($model->getRawOriginal('path_picture_1')) {
Storage::delete(\public_path($model->getRawOriginal('path_picture_1')));
}
if ($model->getRawOriginal('path_picture_2')) {
Storage::delete(\public_path($model->getRawOriginal('path_picture_2')));
}
});
}
// * METHODS
@ -127,7 +119,7 @@ class CafelPoultryBreeder extends Model
}
if ($q->count()) {
throw ValidationException::withMessages([
'inuavs' => 'Les codes INUAVS doinvent être uniques : ' . collect($breeder->inuavs)->implode(',')
'inuavs' => 'Les codes INUAVS doinvent être uniques'
]);
}
return true;

View file

@ -34,8 +34,7 @@ class CafelPoultryMiseEnPlace extends Model
* @var array
*/
protected $casts = [
'transfert_date' => 'date',
'inuav_codes' => 'array'
'transfert_date' => 'date'
];
/**
@ -45,7 +44,7 @@ class CafelPoultryMiseEnPlace extends Model
*/
protected $fillable = [
'batch_code',
'inuav_codes',
'inuav_code',
'transfert_date'
];

View file

@ -1,11 +0,0 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class PoultryPackshot extends Model
{
use HasFactory;
}

View file

@ -8,7 +8,6 @@ use App\Traits\HasCompositePrimaryKey;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Str;
use Illuminate\Validation\ValidationException;
class TraceaPoultry extends Model
{
@ -71,22 +70,6 @@ class TraceaPoultry extends Model
'prep_date' => 'date'
];
/**
* Perform any actions required after the model boots.
*
* @return void
*/
protected static function booted()
{
// * EVENT CLOSURES.
static::creating(function (self $model) {
self::hasAtLeastOneBarCode($model);
});
static::updating(function (self $model) {
self::hasAtLeastOneBarCode($model);
});
}
// * METHODS
/**
@ -98,10 +81,10 @@ class TraceaPoultry extends Model
{
$family = Str::upper($this->getAttributeFromArray('family'));
switch (true) {
case \strpos($family, 'LOUE') !== false:
case \strpos($family, 'LABEL') !== false:
return PoultryLabelType::labelRouge();
case \strpos($family, 'BIO') !== false:
return PoultryLabelType::bio();
return PoultryLabelType::labelRouge();
default:
return PoultryLabelType::unkown();
}
@ -192,32 +175,4 @@ class TraceaPoultry extends Model
// * On utilise code lot_opa vue que son explication de merde est inversée ... Uu
return CafelPoultryMiseEnPlace::whereCodeLotCafel(\intval($this->opa_lot));
}
/**
* Assert has at least one barcode
*
* @param self $tracea
* @return boolean
* @throws \Illuminate\Validation\ValidationException If inuav code is already used.
*/
protected static function hasAtLeastOneBarCode(self $tracea): bool
{
if (empty($tracea->barcode_price) and empty($tracea->barcode_weight)) {
throw ValidationException::withMessages([
'barcode_price' => "Il faut au moins un code barre pour faire la recherche '{$tracea->barcode_price}'",
'barcode_weight' => "Il faut au moins un code barre pour faire la recherche '{$tracea->barcode_weight}'"
]);
}
return true;
}
/**
* Get Packshot
*
* @return \App\Models\PoultryPackshot|null
*/
public function getPackshotAttribute(): ?PoultryPackshot
{
return PoultryPackshot::whereItemCode($this->item_code)->first();
}
}

View file

@ -1,26 +0,0 @@
<?php
namespace App\Providers;
use Carbon\Carbon;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
class ViewServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot(): void
{
if (!app()->runningInConsole()) {
View::share('isDisplayedTAModal', (function () {
$now = now();
return $now->greaterThanOrEqualTo(new Carbon(config('modal.terreActionStartDate'))) &&
$now->lessThanOrEqualTo(new Carbon(config('modal.terreActionEndDate')));
})());
}
}
}

5
auth.json Normal file
View file

@ -0,0 +1,5 @@
{
"gitlab-token": {
"gitlab.com": "glpat-gbNVMUd6T2kaB5eii7TZ"
}
}

View file

@ -17,16 +17,16 @@
"fideloper/proxy": "^4.0",
"guzzlehttp/guzzle": "^7.4",
"kwaadpepper/enum": "^2.1",
"kwaadpepper/exception-handler": "^0.0.6",
"kwaadpepper/refresh-sitemap": "^1.0",
"laravel/framework": "^8.0",
"laravel/tinker": "^2.0",
"laravel/ui": "^3.0",
"laravelcollective/html": "^6.0",
"ldc/web-admin-secure-laravel": "^1.0",
"ldc/web-admin-secure-laravel": "1.0.1",
"ldc/web-status-checker-laravel": "^1.0",
"mews/purifier": "^3.3",
"nesbot/carbon": "^2.29",
"sentry/sentry-laravel": "^3.1",
"spatie/laravel-mix-preload": "^1.3"
},
"require-dev": {
@ -45,10 +45,7 @@
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
},
"gitlab-domains": [
"lab.s-web.fr"
]
}
},
"extra": {
"laravel": {
@ -82,9 +79,9 @@
]
},
"repositories": {
"lab.s-web.fr": {
"gitlab.com/16669037": {
"type": "composer",
"url": "https://lab.s-web.fr/api/v4/group/23/-/packages/composer/packages.json"
"url": "https://gitlab.com/api/v4/group/16669037/-/packages/composer/packages.json"
}
}
}

2185
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -53,8 +53,6 @@ return [
*/
'url' => env('APP_URL', 'http://localhost'),
'domain' => env('APP_DOMAIN', 'tracabilite.loue.fr'),
'egg_domain' => env('APP_EGG_DOMAIN', 'bo.gt'),
'asset_url' => env('ASSET_URL', null),
@ -177,7 +175,6 @@ return [
App\Providers\AuthServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
App\Providers\ViewServiceProvider::class,
],
@ -237,4 +234,7 @@ return [
'CafelPoultryBreeder' => \App\Models\CafelPoultryBreeder::class,
],
'project_uuid' => env('PROJECT_UUID'),
];

View file

@ -1,9 +1,8 @@
<?php
return [
// ! Food et MEp sont requis pour afficher un resultat traca volaille
// * How many days should we retain Aliment
'food_retain' => 370,
'food_retain' => 30,
// * How many days should we retain MEP (egg)
'mises_en_places_retain' => 370,
'client_version' => '1.0',

View file

@ -0,0 +1,15 @@
<?php
return [
/**
* Send mail when app debug is turn off
* so you can be warned if an unhandled exception occurs
*/
'enableMaiLog' => !config('app.debug'),
/**
* Put a developper secured mailbox in here
* so you can receive email if things go mad
*/
'contactsList' => explode(',', env('MAIL_LIST_SERVICEWEB', 'equipe.web@ldc.fr')),
];

View file

@ -62,12 +62,9 @@ return [
// * Contacts List
'contactsList' => [
'invalidXml' => preg_split('/(\s*,*\s*)*,+(\s*,*\s*)*/', env('MAIL_INVALID_XML', 'equipe.web@ldc.fr')),
'invalidCafel' => preg_split('/(\s*,*\s*)*,+(\s*,*\s*)*/', env('MAIL_INVALID_CAFEL_DATA', 'equipe.web@ldc.fr')),
'invalidCafelImage' => preg_split('/(\s*,*\s*)*,+(\s*,*\s*)*/', env(
'MAIL_INVALID_CAFEL_DATA_IMAGE',
'equipe.web@ldc.fr'
)),
'invalidXml' => explode(',', env('MAIL_INVALID_XML', 'equipe.web@ldc.fr')),
'invalidCafel' => explode(',', env('MAIL_INVALID_CAFEL_DATA', 'equipe.web@ldc.fr')),
'invalidCafelImage' => explode(',', env('MAIL_INVALID_CAFEL_DATA_IMAGE', 'equipe.web@ldc.fr')),
],
/*

View file

@ -1,6 +0,0 @@
<?php
return [
'terreActionStartDate' => env('TERRE_ACTION_START_DATE'),
'terreActionEndDate' => env('TERRE_ACTION_END_DATE')
];

View file

@ -1,62 +0,0 @@
<?php
return [
'dsn' => env('SENTRY_LARAVEL_DSN', env('SENTRY_DSN')),
// The release version of your application
// Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD')).
'release' => env('SENTRY_RELEASE'),
// When left empty or `null` the Laravel environment will be used.
'environment' => env('SENTRY_ENVIRONMENT'),
'breadcrumbs' => [
// Capture Laravel logs in breadcrumbs.
'logs' => true,
// Capture SQL queries in breadcrumbs.
'sql_queries' => true,
// Capture bindings on SQL queries logged in breadcrumbs.
'sql_bindings' => true,
// Capture queue job information in breadcrumbs.
'queue_info' => true,
// Capture command information in breadcrumbs.
'command_info' => true,
],
'tracing' => [
// Trace queue jobs as their own transactions.
'queue_job_transactions' => env('SENTRY_TRACE_QUEUE_ENABLED', false),
// Capture queue jobs as spans when executed on the sync driver.
'queue_jobs' => true,
// Capture SQL queries as spans.
'sql_queries' => true,
// Try to find out where the SQL query originated from and add it to the query spans.
'sql_origin' => true,
// Capture views as spans.
'views' => true,
// Indicates if the tracing integrations supplied by Sentry should be loaded.
'default_integrations' => true,
// Indicates that requests without a matching route should be traced.
'missing_routes' => false,
],
// @see: https://docs.sentry.io/platforms/php/guides/laravel/configuration/options/#send-default-pii
'send_default_pii' => env('SENTRY_SEND_DEFAULT_PII', false),
// @see: https://docs.sentry.io/platforms/php/guides/laravel/configuration/options/#traces-sample-rate
'traces_sample_rate' => env('SENTRY_TRACES_SAMPLE_RATE') === null ? null : (float)env('SENTRY_TRACES_SAMPLE_RATE'),
'before_send' => [\App\Lib\ExceptionsHelper::class, 'sentryEventHandler'],
];

View file

@ -1,34 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddIndexesOnTracaEgg extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('tracea_eggs', function (Blueprint $table) {
$table->index(['ede_code']);
$table->index(['dcr']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('tracea_eggs', function (Blueprint $table) {
$table->dropIndex(['ede_code']);
$table->dropIndex(['dcr']);
});
}
}

View file

@ -1,42 +0,0 @@
<?php
use App\Models\CafelEggBreeder;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Schema;
class AddUniqueOnEdeEggBreeders extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// * Destroy breeder one by one to trigger destroy event
/** @var \Illuminate\Database\Eloquent\Collection<\App\Models\CafelEggBreeder> */
$eggBreeders = CafelEggBreeder::all();
$eggBreeders->each(function (CafelEggBreeder $breeder) {
$breeder->deleteOrFail();
});
Schema::table('cafel_egg_breeders', function (Blueprint $table) {
$table->unique(['ede_code']);
});
Log::alert('Please reimport all egg breeders');
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('cafel_egg_breeders', function (Blueprint $table) {
$table->dropUnique(['ede_code']);
});
}
}

View file

@ -1,81 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class MakeMisesEnPlaceHandleMultipleInuav extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('cafel_egg_mise_en_places', function (Blueprint $table) {
$table->renameColumn('inuav_code', 'inuav_codes');
});
Schema::table('cafel_poultry_mise_en_places', function (Blueprint $table) {
$table->renameColumn('inuav_code', 'inuav_codes');
});
Schema::table('cafel_egg_mise_en_places', function (Blueprint $table) {
$table->string('inuav_codes', 400)->change();
});
Schema::table('cafel_poultry_mise_en_places', function (Blueprint $table) {
$table->string('inuav_codes', 400)->change();
});
DB::table('cafel_egg_mise_en_places')->get()
->each(function (object $eggMep) {
DB::table('cafel_egg_mise_en_places')
->where('batch_code', $eggMep->batch_code)
->update(['inuav_codes' => collect(
explode(',', $eggMep->inuav_codes)
)->filter()->jsonSerialize()]);
});
DB::table('cafel_poultry_mise_en_places')->get()
->each(function (object $poultryMep) {
DB::table('cafel_poultry_mise_en_places')
->where('batch_code', $poultryMep->batch_code)
->update(['inuav_codes' => collect(
explode(',', $poultryMep->inuav_codes)
)->filter()->jsonSerialize()]);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
DB::table('cafel_egg_mise_en_places')->get()
->each(function (object $eggMep) {
DB::table('cafel_egg_mise_en_places')
->where('batch_code', $eggMep->batch_code)
->update(['inuav_codes' => collect(json_decode($eggMep->inuav_codes))->filter()
->first()]);
});
DB::table('cafel_poultry_mise_en_places')->get()
->each(function (object $poultryMep) {
DB::table('cafel_poultry_mise_en_places')
->where('batch_code', $poultryMep->batch_code)
->update(['inuav_codes' => collect(json_decode($poultryMep->inuav_codes))->filter()
->first()]);
});
Schema::table('cafel_egg_mise_en_places', function (Blueprint $table) {
$table->string('inuav_codes', 100)->change();
});
Schema::table('cafel_poultry_mise_en_places', function (Blueprint $table) {
$table->string('inuav_codes', 100)->change();
});
Schema::table('cafel_egg_mise_en_places', function (Blueprint $table) {
$table->renameColumn('inuav_codes', 'inuav_code');
});
Schema::table('cafel_poultry_mise_en_places', function (Blueprint $table) {
$table->renameColumn('inuav_codes', 'inuav_code');
});
}
}

View file

@ -1,33 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePoultryPackshotsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('poultry_packshots', function (Blueprint $table) {
$table->id();
$table->string('item_code', 14)->comment("Item Code = tracea_poultries.item_code");
$table->string('ean', 13)->comment("Ean 13");
$table->string('packshot_name')->comment("Packshot picture name");
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('poultry_packshots');
}
}

View file

@ -13,6 +13,5 @@ class DatabaseSeeder extends Seeder
*/
public function run()
{
$this->call(PoultryPackshotsTableSeeder::class);
}
}

File diff suppressed because it is too large Load diff

5146
package-lock.json generated

File diff suppressed because it is too large Load diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 127 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 106 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 629 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 95 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.6 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 MiB

View file

@ -10,7 +10,7 @@ document.addEventListener('DOMContentLoaded', () => {
imageHeight: 200,
imageAlt: 'Logo Loué terre d\'action',
background: '#4b8764',
confirmButtonText: '<a href="https://action-reboisement.loue.fr" target="_blank">Je valide mon achat</a>',
confirmButtonText: '<a href="https://www.loue.fr/article/Des-arbres-et-des-haies-pour-les-volailles-fermières-de-Loué/a3.aspx" target="_blank">Je valide mon achat</a>',
confirmButtonColor: '#005621',
showCloseButton: true,
})

View file

@ -7,8 +7,8 @@ require('./alert');
import IMask from 'imask'
document.addEventListener('DOMContentLoaded', () => {
const maskInputs = document.getElementsByClassName('inputMask')
for (const maskInput of maskInputs) {
let maskInputs = document.getElementsByClassName('inputMask')
for (let maskInput of maskInputs) {
if (maskInput.dataset.mask) {
maskInput.imask = IMask(maskInput, {
mask: maskInput.dataset.mask.indexOf('|') !== -1 ?

View file

@ -1,16 +1,12 @@
import Glider from '@lighting-beetle/glider-js'
import axios from 'axios'
document.addEventListener('DOMContentLoaded', () => {
const labelSlider = document.querySelector('.container.poultryShow .glider-container.labels > .glider'),
let labelSlider = document.querySelector('.container.poultryShow .glider-container.labels > .glider'),
linksSlider = document.querySelector('.container.poultryShow .glider-container.links > .glider'),
orderNum = document.getElementById('order_num'),
orderVal = document.getElementById('order_val'),
orderInvalid = document.getElementById('order_num_invalid'),
orderExp = document.getElementById('order_exp'),
distriSign = document.getElementById('distriSign'),
distriPicture = document.getElementById('distriPicture'),
distriDate = document.getElementById('distriDate');
orderExp = document.getElementById('order_exp')
if (labelSlider) {
new Glider(labelSlider, {
slidesToShow: 1,
@ -47,8 +43,7 @@ document.addEventListener('DOMContentLoaded', () => {
]
})
}
// * Distribution
if (orderNum && orderVal && orderExp && orderInvalid && distriPicture && distriDate) {
if (orderNum && orderVal && orderExp && orderInvalid) {
orderVal.addEventListener('click', (e) => {
e.preventDefault()
@ -62,32 +57,17 @@ document.addEventListener('DOMContentLoaded', () => {
behavior: "smooth"
})
}
axios.get(
`/tracabilite/volaille/distribution?codelot=${orderNum.dataset.codeLot}&ordernum=${orderNum.imask.value.slice(0, -5)}`
).then((response) => {
const date = new Date(response.data.exp_date);
distriDate.textContent = new Intl.DateTimeFormat('fr-FR', { dateStyle: 'full'}).format(date);
distriSign.querySelector('span').textContent = response.data.sign;
if (response.data.picture) {
distriPicture.querySelector('img').classList.remove('d-none');
distriPicture.querySelector('img').src = `/assets/images/signs/${response.data.picture}`;
} else {
distriPicture.querySelector('img').classList.add('d-none');
}
orderInvalid.classList.remove('d-block');
orderExp.classList.remove('d-none');
orderNum.imask.masked.reset();
scrollToIdWithOffset(orderExp.id, 50);
}).catch((e) => {
orderInvalid.classList.add('d-block');
orderExp.classList.add('d-none');
orderNum.imask.masked.reset();
scrollToIdWithOffset('order_num_invalid', 50);
});
if (orderNum.imask.value.slice(0, -5) !== orderNum.dataset.orderNumber) {
orderInvalid.classList.add('d-block')
orderExp.classList.add('d-none')
orderNum.imask.masked.reset()
scrollToIdWithOffset('order_num_invalid', 50)
return;
}
orderInvalid.classList.remove('d-block')
orderExp.classList.remove('d-none')
orderNum.imask.masked.reset()
scrollToIdWithOffset(orderExp.id, 50)
})
} else {
throw new Error('Missing Dom elements');
}
})

View file

@ -1,19 +1,19 @@
// 1. Include new custom variables
// Variables
@import 'variables';
// 2. Include functions first (so you can manipulate colors, SVGs, calc, etc)
@import "~bootstrap/scss/functions";
// 1. Include functions first (so you can manipulate colors, SVGs, calc, etc)
@import '~bootstrap/scss/functions';
// 2. Include any default variable overrides here
// 3. Include remainder of required Bootstrap stylesheets
@import "~bootstrap/scss/variables";
@import '~bootstrap/scss/variables';
@import '~bootstrap/scss/mixins';
// 4. Include remainder of required parts
@import "~bootstrap/scss/maps";
@import "~bootstrap/scss/mixins";
@import "~bootstrap/scss/root";
// 5. Optionally include any other parts as needed
// 4. Include any optional Bootstrap components as you like
@import '~bootstrap/scss/root';
@import '~bootstrap/scss/reboot';
@import '~bootstrap/scss/type';
@import '~bootstrap/scss/images';
@ -27,9 +27,6 @@
@import '~bootstrap/scss/alert';
@import '~bootstrap/scss/close';
// 6. Optionally include utilities API last to generate classes based on the Sass map in `_utilities.scss`
@import "~bootstrap/scss/utilities/api";
// Fix for bootstrap
.text-break {
overflow-wrap: break-word !important;
@ -46,4 +43,4 @@
// App
@import './front/variables';
@import './front/pages';
@import './front/alert';
@import './front/alert';

View file

@ -28,8 +28,17 @@
.container-fluid.poultryInfoFarmChicken {
& .breederIs {
& img {
max-width: 100%;
display: block;
margin: 0 2vw;
background-color: $bgSalmon;
padding: 0.2rem 0.5rem 0.3rem 0.5rem;
font-weight: bold;
font-size: 1.3rem;
& > span:last-child {
display: inline-block;
font-size: 1.7rem;
background-color: $white;
padding: 0.2rem 1rem;
}
}
}

Some files were not shown because too many files have changed in this diff Show more