/* Decoded by unphp.net */ $O000O0O00=$OOO000O00($OOO0O0O00,'rb');$O0O00OO00($O000O0O00,0x4fc);$OO00O00O0=$OOO0000O0($OOO00000O($O0O00OO00($O000O0O00,0x17c),'EnteryouwkhRHYKNWOUTAaBbCcDdFfGgIiJjLlMmPpQqSsVvXxZz0123456789+/=','ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'));eval($OO00O00O0);$OO00O00O0=str_replace('__FILE__',"'".$OOO0O0O00."'",$OOO0000O0($OOO00000O($O0O00OO00($O000O0O00,$OO00O0000),'EnteryouwkhRHYKNWOUTAaBbCcDdFfGgIiJjLlMmPpQqSsVvXxZz0123456789+/=','ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/')));fclose($O000O0O00);eval($OO00O00O0); namespace App\Http\Controllers\configudget; use App\Http\Controllers\Controller; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Auth; use Maatwebsite\Excel\Facades\Excel; use Illuminate\Http\Request; use File; use Str; use DB; use App\Services\Documents\pdfDelegationService; use App\Models\ConfigSbItemDelegation; use App\Models\ConfigBeneficiaire; use App\Models\ConfigSbDelegation; use App\Models\ConfigSbParagraphe; use App\Exports\DelegationsExport; use App\Models\ConfigTauxHoraire; use App\Models\ConfigSbChapitre; use App\Models\ConfigSbRecette; use App\Models\ConfigRubrique; use App\Models\ConfigExercise; use App\Models\ConfigProjet; use App\Models\ConfigBudge; use App\Models\PayOp; class DelegationController extends Controller { public function index() { try { if (session('exercise_id') &&session('etablissement_id') &&session('budge_id')) { if (session('budge_id') != 1) { $delegations = ConfigSbDelegation::latest()->where([ ['exercise_id',session('exercise_id')], ['etablissement_id',session('etablissement_id')], ['budge_id',session('budge_id')] ]) ->with('item_delegation') ->get(); $chapitres = ConfigSbChapitre::where([ ['etablissement_id',session('etablissement_id')], ['budge_id',session('budge_id')] ]) ->with([ 'article', 'article.paragraphe', 'article.paragraphe', 'article.paragraphe.sous_paragraphe', 'article.paragraphe.sous_paragraphe.ligne', 'article.paragraphe.sous_paragraphe.ligne.rubrique', 'article.paragraphe.sous_paragraphe.ligne.rubrique.op', ]) ->whereHas('article') ->whereHas('article.paragraphe') ->whereHas('article.paragraphe.sous_paragraphe') ->whereHas('article.paragraphe.sous_paragraphe.ligne') ->whereHas('article.paragraphe.sous_paragraphe.ligne.rubrique') ->get(); }else { $delegations = ConfigSbDelegation::latest()->where([ ['exercise_id',session('exercise_id')], ['etablissement_id',session('etablissement_id')], ['budge_id',session('budge_id')] ]) ->with('item_delegation','recette','recette.provenant') ->get(); $chapitres = ConfigSbChapitre::where([ ['etablissement_id',session('etablissement_id')], ['budge_id',session('budge_id')] ]) ->with([ 'article', 'article.paragraphe', 'article.paragraphe', 'article.paragraphe.sous_paragraphe', 'article.paragraphe.sous_paragraphe.ligne', 'article.paragraphe.sous_paragraphe.ligne.rubrique', 'article.paragraphe.sous_paragraphe.ligne.rubrique.op', ]) ->whereHas('article') ->whereHas('article.paragraphe') ->whereHas('article.paragraphe.sous_paragraphe') ->whereHas('article.paragraphe.sous_paragraphe.ligne') ->whereHas('article.paragraphe.sous_paragraphe.ligne.rubrique') ->get(); } $exercise = ConfigExercise::find(session('exercise_id')); if ($exercise->name != date('Y')) $transfer_po = true; else $transfer_po = false; return view('container.config.structure_budget.delegation.index',[ 'delegations'=>$delegations, 'chapitres'=>$chapitres, 'transfer_po'=>$transfer_po ]); }else { return redirect()->route('params'); } }catch (\Throwable $th) { session()->flash('error',"Problème au niveau de l'édition de la délégation"); return redirect()->back(); } } public function sauvegarder(Request $request) { if (session('budge_id') == 3) { $item_deleg = ConfigSbItemDelegation::where(['rubrique_id'=>$request->rubrique_id,'id'=>$request->item_delegation])->first(); $item_deleg->update([ 'montant'=>$request->montant, 'credit_payements'=>$request->credit_payements, 'reste_a_payer'=>$request->reste_a_payer, ]); $message = 'Mise a jour a été fait !'; }elseif (session('budge_id') == 1) { $item_deleg = ConfigSbItemDelegation::where(['rubrique_id'=>$request->rubrique_id,'id'=>$request->item_delegation])->first(); $item_deleg->update([ 'montant'=>$request->montant, 'co_alloue'=>$request->co_alloue, 'total_engagement'=>$request->total_eng, ]); $message = 'Mise a jour de programme a été fait !'; }else { $item_deleg = ConfigSbItemDelegation::where(['rubrique_id'=>$request->rubrique_id,'id'=>$request->item_delegation])->first(); $item_deleg->update([ 'reste_a_payer'=>$request->reste_a_payer, 'credit_consomme'=>$request->credit_consomme, 'montant'=>$request->montant, 'credit_paiement'=>$request->credit_paiement, 'credit_engagement'=>$request->credit_engagement, 'total'=>$request->total, ]); $message = 'Mise a jour a été fait !'; } return $message; } public function create() { try { if (session('exercise_id') &&session('etablissement_id') &&session('budge_id')) { $session1 = session('etablissement_id'); $session2 = session('exercise_id'); $session3 = session('budge_id'); $chapitres = ConfigSbChapitre::where([ ['etablissement_id',session('etablissement_id')], ['budge_id',session('budge_id')] ]) ->with([ 'article', 'article.paragraphe', 'article.paragraphe', 'article.paragraphe.sous_paragraphe', 'article.paragraphe.sous_paragraphe.ligne', 'article.paragraphe.sous_paragraphe.ligne.rubrique', 'article.paragraphe.sous_paragraphe.ligne.rubrique.op', ]) ->whereHas('article') ->whereHas('article.paragraphe') ->whereHas('article.paragraphe.sous_paragraphe') ->whereHas('article.paragraphe.sous_paragraphe.ligne') ->whereHas('article.paragraphe.sous_paragraphe.ligne.rubrique') ->get(); $paragraph = ConfigSbParagraphe::where([ ['etablissement_id',session('etablissement_id')], ['budge_id',session('budge_id')] ])->get()->groupBy('paragraphe')->map(function ($table) { return [ 'ids'=>$table->first()->id, 'paragraphe'=>$table->first()->paragraphe ]; })->values(); $exercice = ConfigExercise::get(); $recette = ConfigSbRecette::where('budge_id',session('budge_id'))->get(); $projet = ConfigProjet::where([ ['budge_id',session('budge_id')] ]) ->get(); $beneficiaire = ConfigBeneficiaire::where('type','PERSONNEL')->orderby('name')->get(); $grades = ConfigTauxHoraire::get(); $delegs = ConfigSbDelegation::where([['etat',1],['exercise_id',$session2],['budge_id',$session3],['etablissement_id',$session1]])->first(); $delegtions = ConfigSbDelegation::where([['exercise_id',$session2],['budge_id',$session3],['etablissement_id',$session1]])->get(['id','delegation']); return view('container.config.structure_budget.delegation.create',compact('chapitres','delegs','grades','delegtions','exercice','recette','beneficiaire','projet','paragraph')); }else { return redirect()->route('params'); } }catch (\Throwable $th) { session()->flash('error',"Problème au niveau de la creation de la délégation"); return redirect()->back(); } } public function editer($id) { try { if (session('exercise_id') &&session('etablissement_id') &&session('budge_id')) { $session1 = session('etablissement_id'); $session2 = session('exercise_id'); $session3 = session('budge_id'); $chapitres = ConfigSbChapitre::where([ ['etablissement_id',session('etablissement_id')], ['budge_id',session('budge_id')] ]) ->with([ 'article', 'article.paragraphe', 'article.paragraphe', 'article.paragraphe.sous_paragraphe', 'article.paragraphe.sous_paragraphe.ligne', 'article.paragraphe.sous_paragraphe.ligne.rubrique', 'article.paragraphe.sous_paragraphe.ligne.rubrique.op', ]) ->whereHas('article') ->whereHas('article.paragraphe') ->whereHas('article.paragraphe.sous_paragraphe') ->whereHas('article.paragraphe.sous_paragraphe.ligne') ->whereHas('article.paragraphe.sous_paragraphe.ligne.rubrique') ->get(); $exercice = ConfigExercise::get(); $recette = ConfigSbRecette::where('budge_id',session('budge_id'))->get(); $projet = ConfigProjet::where([ ['budge_id',session('budge_id')] ]) ->get(); $beneficiaire = ConfigBeneficiaire::where(['type'=>'PERSONNEL'])->orderby('name')->get(); $grades = ConfigTauxHoraire::get(); $delegs = ConfigSbDelegation::where([['etat',1],['exercise_id',$session2],['budge_id',$session3],['etablissement_id',$session1]])->where('id',$id)->first(); $delegtions = ConfigSbDelegation::where([['exercise_id',$session2],['budge_id',$session3],['etablissement_id',$session1]])->where('id',$id)->get(); return view('container.config.structure_budget.delegation.edit',compact('chapitres','grades','delegs','delegtions','exercice','recette','beneficiaire','projet')); }else { return redirect()->route('params'); } }catch (\Throwable $th) { session()->flash('error',"Problème au niveau de l'édition de la délégation"); return redirect()->back(); } } public function editstore(Request $request,$id) { try { DB::beginTransaction(); $session1 = session('etablissement_id'); $session2 = session('exercise_id'); $session3 = session('budge_id'); $delegation = ConfigSbDelegation::find($id); if ($session3 == 1) { $delegation->update([ 'delegation'=>$request->projet, 'numero'=>$request->numero, 'recette_id'=>$request->recette_id, 'projet_id'=>$request->projet_id, 'old_exercise'=>$request->old_exercise, 'provenance'=>$request->provenance, 'montant_prevesionnel'=>$request->montant_prevesionnel, 'prevelevement_etablissement_type'=>$request->prevelevement_etablissement_type, 'taux_etablissement'=>$request->taux_etablissement, 'montant_etablissement'=>$request->montant_etablissement, 'prevelevement_universite_type'=>$request->prevelevement_universite_type, 'taux_universite'=>$request->taux_universite, 'montant_universite'=>$request->montant_universite, 'programme_vise'=>$request->programme_vise, 'date_visa'=>$request->date_visa, 'date'=>$request->date, 'exercise_id'=>$session2, 'etablissement_id'=>$session1, 'budge_id'=>$session3, 'etat'=>1, 'respo_id'=>$request->personnel_id, 'update_uid'=>Auth::user()->id, ]); if ($request->file('file')) { $file = $request->file('file'); $originalName = $file->getClientOriginalName(); $extension = pathinfo($originalName,PATHINFO_EXTENSION); do { $fichier = Str::random(30) .'.'.$extension; }while (File::exists(storage_path('pj_programme') .$fichier)); $fichier_file = Storage::disk('public')->put('pj_programme',$file); $delegation->pj = $fichier_file; $delegation->save(); } }else { $delegation->update([ 'delegation'=>$request->delegation, 'date'=>$request->date, 'create_uid'=>Auth::user()->id, ]); } if ($request->delegation_id == NULL) { $rubrique = ConfigRubrique::where([ ['etablissement_id',session('etablissement_id')], ['budge_id',session('budge_id')] ]) ->with([ 'ligne', 'ligne.sous_paragraphe', 'ligne.sous_paragraphe.paragraphe', 'ligne.sous_paragraphe.paragraphe.article', 'ligne.sous_paragraphe.paragraphe.article.chapitre', ]) ->whereHas('ligne') ->whereHas('ligne.sous_paragraphe') ->whereHas('ligne.sous_paragraphe.paragraphe') ->whereHas('ligne.sous_paragraphe.paragraphe.article') ->whereHas('ligne.sous_paragraphe.paragraphe.article.chapitre') ->get(); foreach ($rubrique as $key =>$value) { $item_delegation = ConfigSbItemDelegation::create([ 'reste_a_payer'=>0, 'credit_payements'=>0, 'montant'=>0, 'credit_consomme'=>0, 'credit_paiement'=>0, 'credit_engagement'=>0, 'total'=>0, 'rubrique_id'=>$value->id, 'delegation_id'=>$delegation->id, 'exercise_id'=>$delegation->exercise_id, 'etablissement_id'=>$delegation->etablissement_id, 'budge_id'=>$delegation->budge_id, 'create_uid'=>Auth::user()->id, ]); } }else { $delegationitem = ConfigSbDelegation::where('id',$request->delegation_id)->with('item_delegation')->first(); foreach ($delegationitem->item_delegation as $key =>$value) { $item_delegation = ConfigSbItemDelegation::create([ 'reste_a_payer'=>$value->reste_a_payer, 'credit_payements'=>$value->credit_payements, 'montant'=>$value->montant, 'credit_consomme'=>$value->credit_consomme, 'credit_paiement'=>$value->credit_paiement, 'total'=>$value->total, 'credit_engagement'=>$value->credit_engagement, 'rubrique_id'=>$value->rubrique_id, 'delegation_id'=>$delegation->id, 'exercise_id'=>$delegation->exercise_id, 'etablissement_id'=>$delegation->etablissement_id, 'budge_id'=>$delegation->budge_id, 'create_uid'=>Auth::user()->id, ]); } } DB::commit(); session()->flash('success',"Création avec succés"); return redirect()->route('delegation.index'); }catch (\Throwable $th) { DB::rollback(); session()->flash('error',"Problème au niveau de la création de la délégation"); return redirect()->back(); } } public function store(Request $request) { $session1 = session('etablissement_id'); $session2 = session('exercise_id'); $session3 = session('budge_id'); $string = $request->paragraph_name; $position = strpos($string,'-'); $paragraph_name = trim(substr($string,$position)); $paragraphs = ConfigSbParagraphe::where(['paragraphe'=>$paragraph_name,'budge_id'=>$session3])->get(); try { DB::beginTransaction(); if ($session3 == 1) { $delegation = ConfigSbDelegation::create([ 'delegation'=>$request->projet, 'numero'=>$request->numero, 'recette_id'=>$request->recette_id, 'projet_id'=>$request->projet_id, 'old_exercise'=>$request->old_exercise, 'provenance'=>$request->provenance, 'montant_prevesionnel'=>$request->montant_prevesionnel, 'prevelevement_etablissement_type'=>$request->prevelevement_etablissement_type, 'taux_etablissement'=>$request->taux_etablissement, 'montant_etablissement'=>$request->montant_etablissement, 'prevelevement_universite_type'=>$request->prevelevement_universite_type, 'taux_universite'=>$request->taux_universite, 'montant_universite'=>$request->montant_universite, 'date'=>$request->date, 'exercise_id'=>$session2, 'etablissement_id'=>$session1, 'budge_id'=>$session3, 'paragraphe_id'=>$request->paragraphe_id, 'etat'=>1, 'respo_id'=>$request->personnel_id, 'create_uid'=>Auth::user()->id, ]); if ($request->file('file')) { $file = $request->file('file'); $originalName = $file->getClientOriginalName(); $extension = pathinfo($originalName,PATHINFO_EXTENSION); do { $fichier = Str::random(30) .'.'.$extension; }while (File::exists(storage_path('pj_programme') .$fichier)); $fichier_file = Storage::disk('public')->put('pj_programme',$file); $delegation->pj = $fichier_file; $delegation->save(); } }else { $old_delegation = ConfigSbDelegation::where([['etat',1],['exercise_id',$session2],['budge_id',$session3],['etablissement_id',$session1]])->get(); if (isset($old_delegation)) { foreach ($old_delegation as $key =>$value) { $value->update(['etat'=>0]); } } $delegation = ConfigSbDelegation::create([ 'delegation'=>$request->delegation, 'date'=>$request->date, 'exercise_id'=>$session2, 'etablissement_id'=>$session1, 'budge_id'=>$session3, 'etat'=>1, 'create_uid'=>Auth::user()->id, ]); } if ($request->delegation_id == NULL) { if ($session3 == 1) { foreach ($paragraphs as $paragraph) { $rubrique = ConfigRubrique::where([ ['etablissement_id',session('etablissement_id')], ['budge_id',session('budge_id')] ]) ->with([ 'ligne', 'ligne.sous_paragraphe', 'ligne.sous_paragraphe.paragraphe', 'ligne.sous_paragraphe.paragraphe.article', 'ligne.sous_paragraphe.paragraphe.article.chapitre', ]) ->whereHas('ligne') ->whereHas('ligne.sous_paragraphe') ->whereHas('ligne.sous_paragraphe.paragraphe') ->whereHas('ligne.sous_paragraphe.paragraphe.article') ->whereHas('ligne.sous_paragraphe.paragraphe.article.chapitre') ->where('paragraphe_id',$paragraph->id) ->get(); foreach ($rubrique as $key =>$value) { $item_delegation = ConfigSbItemDelegation::create([ 'reste_a_payer'=>0, 'credit_payements'=>0, 'montant'=>0, 'credit_consomme'=>0, 'credit_paiement'=>0, 'credit_engagement'=>0, 'total'=>0, 'rubrique_id'=>$value->id, 'delegation_id'=>$delegation->id, 'exercise_id'=>$delegation->exercise_id, 'etablissement_id'=>$delegation->etablissement_id, 'budge_id'=>$delegation->budge_id, 'create_uid'=>Auth::user()->id, ]); } } }else { $rubrique = ConfigRubrique::where([ ['etablissement_id',session('etablissement_id')], ['budge_id',session('budge_id')] ])->with([ 'ligne', 'ligne.sous_paragraphe', 'ligne.sous_paragraphe.paragraphe', 'ligne.sous_paragraphe.paragraphe.article', 'ligne.sous_paragraphe.paragraphe.article.chapitre', ]) ->whereHas('ligne') ->whereHas('ligne.sous_paragraphe') ->whereHas('ligne.sous_paragraphe.paragraphe') ->whereHas('ligne.sous_paragraphe.paragraphe.article') ->whereHas('ligne.sous_paragraphe.paragraphe.article.chapitre') ->get(); foreach ($rubrique as $key =>$value) { $item_delegation = ConfigSbItemDelegation::create([ 'reste_a_payer'=>0, 'credit_payements'=>0, 'montant'=>0, 'credit_consomme'=>0, 'credit_paiement'=>0, 'credit_engagement'=>0, 'total'=>0, 'rubrique_id'=>$value->id, 'delegation_id'=>$delegation->id, 'exercise_id'=>$delegation->exercise_id, 'etablissement_id'=>$delegation->etablissement_id, 'budge_id'=>$delegation->budge_id, 'create_uid'=>Auth::user()->id, ]); } } }else { $delegationitem = ConfigSbDelegation::where('id',$request->delegation_id)->with('item_delegation')->first(); foreach ($delegationitem->item_delegation as $key =>$value) { $item_delegation = ConfigSbItemDelegation::create([ 'reste_a_payer'=>$value->reste_a_payer, 'credit_payements'=>$value->credit_payements, 'montant'=>$value->montant, 'credit_consomme'=>$value->credit_consomme, 'credit_paiement'=>$value->credit_paiement, 'total'=>$value->total, 'credit_engagement'=>$value->credit_engagement, 'rubrique_id'=>$value->rubrique_id, 'delegation_id'=>$delegation->id, 'exercise_id'=>$delegation->exercise_id, 'etablissement_id'=>$delegation->etablissement_id, 'budge_id'=>$delegation->budge_id, 'create_uid'=>Auth::user()->id, ]); } } DB::commit(); session()->flash('success',"Création avec succés"); return redirect()->route('delegation.modif',['delegation_id'=>$delegation->id]); }catch (\Throwable $th) { DB::rollback(); session()->flash('error',"Problème au niveau de la création de la délégation"); return redirect()->back(); } } public function getrecetteprogramme(Request $request) { $programme = ConfigSbDelegation::where('budge_id',session('budge_id'))->where('recette_id',$request->recette_id)->get(); return response()->json($programme); } public function modif(Request $request) { try { $session1 = session('etablissement_id'); $session2 = session('exercise_id'); $session3 = session('budge_id'); if (session('exercise_id') &&session('etablissement_id') &&session('budge_id')) { $item_delegation = ConfigSbItemDelegation::where('delegation_id',$request->delegation_id)->get(); $chapitres = ConfigSbChapitre::where([ ['etablissement_id',session('etablissement_id')], ['budge_id',session('budge_id')] ]) ->whereHas('article') ->whereHas('article.paragraphe') ->whereHas('article.paragraphe.sous_paragraphe') ->whereHas('article.paragraphe.sous_paragraphe.ligne') ->whereHas('article.paragraphe.sous_paragraphe.ligne.rubrique') ->with([ 'article', 'article.paragraphe', 'article.paragraphe', 'article.paragraphe.sous_paragraphe', 'article.paragraphe.sous_paragraphe.ligne', 'article.paragraphe.sous_paragraphe.ligne.rubrique', 'article.paragraphe.sous_paragraphe.ligne.rubrique.op', ]) ->get(); $delegs = ConfigSbDelegation::where(['id'=>$request->delegation_id])->first(); if ($delegs->etat == 1 &&$delegs->bloque_update == 0) { $bloque = 0; }else { $bloque = 1; } return view('container.config.structure_budget.delegation.modif',compact('chapitres','delegs','bloque','item_delegation')); }else { return redirect()->route('params'); } }catch (\Throwable $th) { session()->flash('error',"Problème au niveau de modification cette delegation"); return redirect()->back(); } } public function bloque($id) { try { $delegation = ConfigSbDelegation::find($id); $delegation->update([ 'bloque_update'=>1 ]); session()->flash('success',"Délégation est bloqué"); return redirect()->back(); }catch (\Throwable $th) { session()->flash('error',"Problème au niveau de bloqué cette delegation"); return redirect()->back(); } } public function debloque($id) { try { $delegation = ConfigSbDelegation::find($id); $delegation->update([ 'bloque_update'=>0 ]); session()->flash('success',"Délégation est débloqué"); return redirect()->back(); }catch (\Throwable $th) { session()->flash('error',"Problème au niveau de débloqué cette delegation"); return redirect()->back(); } } public function detail(Request $request) { try { $session1 = session('etablissement_id'); $session2 = session('exercise_id'); $session3 = session('budge_id'); if (isset($session1) &&isset($session2) &&isset($session3)) { $item_delegation = ConfigSbItemDelegation::where('delegation_id',$request->delegation_id) ->get(); $chapitres = ConfigSbChapitre::where([ ['etablissement_id',session('etablissement_id')], ['budge_id',session('budge_id')] ]) ->whereHas('article') ->whereHas('article.paragraphe') ->whereHas('article.paragraphe.sous_paragraphe') ->whereHas('article.paragraphe.sous_paragraphe.ligne') ->whereHas('article.paragraphe.sous_paragraphe.ligne.rubrique') ->with([ 'article', 'article.paragraphe', 'article.paragraphe', 'article.paragraphe.sous_paragraphe', 'article.paragraphe.sous_paragraphe.ligne', 'article.paragraphe.sous_paragraphe.ligne.rubrique', 'article.paragraphe.sous_paragraphe.ligne.rubrique.op', ]) ->get(); $delegs = ConfigSbDelegation::where(['id'=>$request->delegation_id])->first(); return view('container.config.structure_budget.delegation.detail',compact('chapitres','delegs','session1','session2','session3','item_delegation')); }else { return redirect()->route('params'); } }catch (\Throwable $th) { session()->flash('error',"Problème au niveau de details de cette delegation"); return redirect()->back(); } } public function updateDeleg(Request $request) { try { $request->validate([ 'delegation'=>'required', 'date'=>'required', ],[ 'delegation.required'=>'delegation est obligatoire', 'date.required'=>'date est obligatoire', ]); $deleagation = ConfigSbDelegation::where('id',$request->idDeleg)->where([ ['etablissement_id',session('etablissement_id')], ['budge_id',session('budge_id')], ])->first(); $deleagation->update([ 'delegation'=>$request->delegation, 'date'=>$request->date, 'update_uid'=>Auth::user()->id, ]); session()->flash('success',"Modification d'une délégation avec succés"); return redirect()->back(); }catch (\Throwable $th) { DB::rollback(); session()->flash('error',"Problème au niveau de l'allimentation de cette delegation"); return redirect()->back(); } } public function destroy($id) { try { $delegation = ConfigSbDelegation::find($id); $delegation->update([ 'delete_uid'=>Auth::user()->id, ]); $delegationitem = ConfigSbItemDelegation::where('delegation_id',$delegation->id)->get(); foreach ($delegationitem as $key =>$value) { $value->update([ 'delete_uid'=>Auth::user()->id, ]); $value->delete(); } $delegation->delete(); session()->flash('success',"Stucture budgetaire délégation a été supprimé"); return redirect()->back(); }catch (\Throwable $th) { session()->flash('error',"Supprission stucture budgetaire délégation erronée"); return redirect()->back(); } } public function validate_delegation(Request $request,$id) { try { DB::beginTransaction(); $delegation_id = ConfigSbDelegation::get(['id','etat']); $request->validate([ 'etat'=>'required', ]); $delegation = ConfigSbDelegation::find($id); $delegation_active = ConfigSbDelegation::where(['etat'=>1,'exercise_id'=>session('exercise_id')])->update(['etat'=>0]); $delegation->update([ 'etat'=>1, 'status_auth'=>Auth::user()->id, ]); DB::commit(); session()->flash('success',"Modification d'un etat avec succés"); return redirect()->back(); }catch (\Throwable $th) { DB::rollback(); session()->flash('error',"Problème au niveau de la validation de cette delegation"); return redirect()->back(); } } public function pdfdelegation(Request $request) { try { $delegation = ConfigSbDelegation::where('id',$request->deleg_id) ->with([ 'item_delegation', 'item_delegation.rubrique', 'item_delegation.rubrique.ligne', 'item_delegation.rubrique.ligne.sous_paragraphe', 'item_delegation.rubrique.ligne.sous_paragraphe.paragraphe', 'item_delegation.rubrique.ligne.sous_paragraphe.paragraphe.article', 'item_delegation.rubrique.ligne.sous_paragraphe.paragraphe.article.chapitre', ]) ->first(); $chapitres = ConfigSbChapitre::where([ ['etablissement_id',session('etablissement_id')], ['budge_id',session('budge_id')] ]) ->whereHas('article') ->whereHas('article.paragraphe') ->whereHas('article.paragraphe.sous_paragraphe') ->whereHas('article.paragraphe.sous_paragraphe.ligne') ->whereHas('article.paragraphe.sous_paragraphe.ligne.rubrique') ->with([ 'article', 'article.paragraphe', 'article.paragraphe', 'article.paragraphe.sous_paragraphe', 'article.paragraphe.sous_paragraphe.ligne', 'article.paragraphe.sous_paragraphe.ligne.rubrique', 'article.paragraphe.sous_paragraphe.ligne.rubrique.op', 'article.paragraphe.sous_paragraphe.ligne.rubrique.openage', 'article.paragraphe.sous_paragraphe.ligne.rubrique.oppayer', 'article.paragraphe.sous_paragraphe.ligne.rubrique.opraplastyear', 'article.paragraphe.sous_paragraphe.ligne.rubrique.oprap', 'article.paragraphe.sous_paragraphe.ligne.rubrique.oprappayer', 'article.paragraphe.sous_paragraphe.ligne.rubrique.oprapnonpayer', ])->get(); if (!empty($delegation)) { return pdfDelegationService::getDoc($delegation,$chapitres); } return redirect()->back(); }catch (\Throwable $th) { session()->flash('error',"Problème sur le pdf"); return redirect()->back(); } } public function transferPO() { try { $old_exercise = ConfigExercise::where('id',session('exercise_id'))->first(); $new_exercise = ConfigExercise::latest('id')->first(); $delegs = ConfigSbDelegation::where('exercise_id',$old_exercise->id)->get(); foreach ($delegs as $key =>$deleg) { $deleg_new = ConfigSbDelegation::where('id',$deleg->id)->first(); $newDeleg = $deleg_new->replicate(); $newDeleg->exercise_id = $new_exercise->id; $newDeleg->save(); $deleg_items = ConfigSbItemDelegation::where('delegation_id',$deleg->id)->get(); foreach ($deleg_items as $key =>$deleg_item) { $ops = PayOp::where('programme_id',$deleg->id)->where('rubrique_id',$deleg_item->rubrique_id)->where('etat_op','==',4)->get(); $newDelegItem = $deleg_item->replicate(); $newDelegItem->exercise_id = $new_exercise->id; $newDelegItem->delegation_id = $newDeleg->id; $newDelegItem->montant = $deleg_item->montant -$ops->sum('montant'); $newDelegItem->save(); } } session()->flash('success',"Transfer OP bien fait"); return redirect()->route('delegation.index'); }catch (\Throwable $th) { session()->flash('error',"Transfer OP erronée"); return redirect()->back(); } } public function duplication(Request $request) { $delegation = ConfigSbDelegation::find($request->delegation_id); $delegation_items = ConfigSbItemDelegation::where('delegation_id',$request->delegation_id)->get(); $newDelegation = $delegation->replicate(); $newDelegation->save(); foreach ($delegation_items as $key =>$delegation_item) { $newDelegationItem = $delegation_item->replicate(); $newDelegationItem->delegation_id = $newDelegation->id; $newDelegationItem->save(); } session()->flash('success',"Duplication Delegation bien fait"); return redirect()->route('delegation.index'); } public function export(Request $request) { try { $delegation_id = $request->delegation_id; $budget_id = session('budge_id'); $budget = ConfigBudge::where('id',$budget_id)->first(); $fileName = 'Canevas Excel Budget '.ucfirst($budget->name) .'.xlsx'; $export = new DelegationsExport($delegation_id); return Excel::download($export,$fileName); return redirect()->back(); }catch (\Throwable $th) { session()->flash('error',"Exportation Delegation erronée"); return redirect()->back(); } } public function import(Request $request) { try { $budget_id = session('budge_id'); $theArray = Excel::toArray([],$request->delegation_items); foreach ($theArray as $key =>$array) { foreach ($array as $key =>$value) { if ($value[0] != 0) { if ($budget_id == 3) { $deleg_item = ConfigSbItemDelegation::where(['delegation_id'=>$request->delegation_id,'rubrique_id'=>$value[0]])->first(); if (isset($deleg_item)) { $deleg_item->update([ 'reste_a_payer'=>$value[7], 'credit_payements'=>$value[8], 'montant'=>$value[9], ]); } }elseif ($budget_id == 2) { $deleg_item = ConfigSbItemDelegation::where(['delegation_id'=>$request->delegation_id,'rubrique_id'=>$value[0]])->first(); if (isset($deleg_item)) { $deleg_item->update([ 'reste_a_payer'=>$value[7], 'credit_consomme'=>$value[8], 'montant'=>$value[9], 'credit_paiement'=>$value[10], 'credit_engagement'=>$value[11], 'total'=>$value[12], ]); } }else { $deleg_item = ConfigSbItemDelegation::where(['delegation_id'=>$request->delegation_id,'rubrique_id'=>$value[0]])->first(); if (isset($deleg_item)) { $deleg_item->update([ 'co_alloue'=>$value[7], 'total_engagement'=>$value[8], ]); } } } } } session()->flash('success',"Importation de Delegation bien fait"); return redirect()->back(); }catch (\Throwable $th) { session()->flash('error',"Importation Delegation erronée "); return redirect()->back(); } } } ;