ventes = $ventes; $this->storeUser = $storeUser; } /** * Execute the job. * * @return void */ public function handle() { foreach($ventes as $vente){ $options = [ "NumCommand" => $vente->options->NumCommand, "User_" => $vente->options->User_, "Vendeur" => $vente->options->Vendeur, "VenteSpace" => $vente->options->VenteSpace, ]; $details = [ "ID_BR" => $vente->details->ID_BR, "ID_Depot" => $vente->details->ID_Depot, "Matricule" => $vente->details->Matricule, "numBonReception" => $vente->details->numBonReception, "PrixTTC" => $vente->details->PrixTTC, "Quantite" => $vente->details->Quantite, "Remise" => $vente->details->Remise, "TVA" => $vente->details->TVA, "typeArticle" => $vente->details->typeArticle, ]; $sortieStock = SortieStock::where('numsortie', $vente->numsortie) ->first(); if($sortieStock != null){ $oldDetails = json_decode($sortieStock->details); array_push($oldDetails, $details); $sortieStock->details = json_encode($oldDetails); $sortieStock->save(); }else{ $client = Client::where('numclient', $vente->numClient) ->first(); SortieStock::create([ 'numsortie' => $vente->numsortie, 'numdocument' => 0, 'type' => $vente->type, 'montant' => $vente->montant, 'options' => json_encode($options), 'details' => json_encode([$details]), 'date_' => Carbon::parse($vente->date_), 'client_id' => $client != null ? $client->id : null, 'store_id' => $storeUser->store_id, 'user_id' => $storeUser->user_id, ]); } } } }