Exemplo n.º 1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $bill = new Bill();
     $bill->customer_id = $request->customer_id;
     $bill->total_amount = $request->total_amount;
     if ($bill->save()) {
         return $bill . "was saved succesfully";
     }
     return " Something wrong during saving the bill for customer id " . $request->customer_id;
 }
Exemplo n.º 2
0
 public function createBill(Request $request, $id)
 {
     //$input = Requests::all();
     $this->validate($request, ['trip_id' => 'required', 'invoicingParty' => 'required|min:3', 'date' => 'required|date', 'note' => 'required|min:20', 'amountCHF' => 'required|numeric']);
     $b = new Bill();
     $b->trip_id = $id;
     $b->invoicingParty = $request->invoicingParty;
     $b->amountCHF = $request->amountCHF;
     $b->date = $request->date;
     $b->note = $request->note;
     $b->save();
     return redirect('admin/editTrip/' . $id);
 }
Exemplo n.º 3
0
 /**
  * Create a new event instance.
  *
  * @param $start
  * @param $end
  * @param $status
  * @param $somme
  * @param $child_id
  * @param $user_id
  */
 public function __construct($start, $end, $status, $somme, $child_id, $user_id)
 {
     $this->start = $start;
     $this->end = $end;
     $this->status = $status;
     $this->somme = $somme;
     $this->child_id = $child_id;
     $this->user_id = $user_id;
     $bill = new Bill();
     $bill->start = $this->start;
     $bill->end = $this->end;
     $bill->status = intval($this->status);
     $bill->somme = $this->somme;
     $bill->child_id = $this->child_id;
     $bill->user_id = $this->user_id;
     $bill->save();
 }
Exemplo n.º 4
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $http, Bill $bill)
 {
     $this->validate($http, ['bill_name' => 'required', 'resident_id' => 'required', 'residence_id' => 'required', 'bill_due_date_month' => 'required', 'bill_due_date_year' => 'required']);
     $bill->name = $http->bill_name;
     $bill->resident_id = $http->resident_id;
     $bill->residence_id = $http->residence_id;
     if ($http->has('bill_amount')) {
         $value = trim($http->bill_amount);
         if ($value != '') {
             $bill->amount = $value;
         }
     }
     $due_date = date($http->bill_due_date_year . '-' . $http->bill_due_date_month . '-28');
     $bill->due_date = $due_date;
     $bill->description = $http->bill_description;
     $bill->save();
     // add an approval as the creator of the bill
     $bill->approve();
     // check if bill can become active
     $bill->checkActiveState();
     return redirect('residences/' . $http->residence_id);
 }
Exemplo n.º 5
0
 /**
  * ajouter un enfant avec seulement l'id de parent
  * @param Request $request
  */
 public function store_enfant(ajouterEnfantRequest $request)
 {
     $child = new Child();
     $child->date_naissance = Carbon::parse($request->date_naissance);
     $child->nom_enfant = $request->nom_enfant;
     $child->sexe = $request->sexe;
     $child->age_enfant = $child->date_naissance->diffInYears(Carbon::now());
     $child->transport = $request->transport;
     $child->user_id = \Auth::user()->id;
     $image = Input::file('photo');
     if (!$image && empty($image)) {
         $filename = '';
     } else {
         $filename = $image->getClientOriginalName();
         $path = public_path('uploads/' . $filename);
         Image::make($image->getRealPath())->resize(313, 300)->save($path);
     }
     $child->photo = $filename;
     $child->family_id = $request->pere;
     $resp = Family::findOrFail($request->pere);
     $user = User::where('email', $resp->email_responsable)->first();
     if ($user) {
         $child->f_id = $user->id;
         $child->save();
         if ($child->id) {
             $cr = Classroom::where('user_id', \Auth::user()->id)->where('id', $request->classe)->first();
             $cr->children()->attach([$child->id]);
             $bill = new Bill();
             $bill->start = Carbon::now()->toDateString();
             $bill->end = Carbon::now()->addMonth()->toDateString();
             $bill->status = 0;
             if ($request->transport == 1) {
                 if (Transport::where('user_id', \Auth::user()->id)->exists()) {
                     $transport_somme = Transport::where('user_id', \Auth::user()->id)->first()->somme;
                     $bill_somme = CategoryBill::getYear(Carbon::parse($request->date_naissance));
                     $bill->somme = $transport_somme + $bill_somme;
                 } else {
                     $bill->somme = CategoryBill::getYear(Carbon::parse($request->date_naissance));
                 }
             } else {
                 $bill->somme = CategoryBill::getYear(Carbon::parse($request->date_naissance));
             }
             $bill->child_id = $child->id;
             $bill->f_id = $user->id;
             $bill->user_id = \Auth::user()->id;
             $bill->save();
         }
     }
     return redirect()->back()->with('success', "l'enfant a bien été ajouté! ");
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(FormValidationChildFamilyRequest $request)
 {
     $cr = Classroom::where('user_id', \Auth::user()->id)->where('id', $request->classe)->first();
     if ($cr->children()->where('school_year_id', $request->id_ann_scol)->count() > $cr->capacite_classe) {
         return redirect()->back()->withErrors("la classe est saturée");
     }
     // promotion Exceptional check
     if (PromotionExceptional::checkExceptionalPromotion()) {
         if (PromotionExceptional::checkExcTimeOfPromotionIfExpired()) {
             if (PromotionExceptional::checkExcPriceandReturnIt() == 'no') {
                 return redirect()->back()->withErrors("la promotion Exceptionnelle est active mais aucun prix n'est défini")->withInput();
             } else {
                 $prix_exc = PromotionExceptional::checkExcPriceandReturnIt();
             }
         } else {
             return redirect()->back()->withErrors("la promotion Exceptionnelle est active mais la durée est expirée");
         }
     }
     // promotion advanced check
     $prix_advance = '';
     if (PromotionAdvance::checkAdvancePromotion()) {
         if ($request->nbr_month > 1) {
             if (PromotionAdvance::checkAdvIfPriceIsSet($request->nbr_month) !== false) {
                 $prix_advance = PromotionAdvance::checkAdvIfPriceIsSet($request->nbr_month);
             } else {
                 return redirect()->back()->withErrors("Aucun prix n'est\n                    défini pour cette Promotion de " . $request->nbr_month . ' Mois');
             }
         }
     }
     $niveau_global = \Auth::user()->grades()->where('id', $request->grade)->first()->name;
     // famille for family profile
     $famille = Family::where('user_id', \Auth::user()->id)->where('email_responsable', $request->email_responsable)->first();
     if (!$famille) {
         $family = new Family();
         $family->nom_pere = ucfirst($request->nom_pere);
         $family->nom_mere = ucfirst($request->nom_mere);
         $family->email_responsable = $request->email_responsable;
         $family->adresse = $request->adresse;
         $family->numero_fixe = $request->numero_fixe;
         $family->numero_portable = $request->numero_portable;
         $family->cin = strtoupper($request->cin);
         $family->responsable = $request->responsable;
         $family->user_id = \Auth::user()->id;
         $family->school_year_id = $request->id_ann_scol;
         $family->save();
         if ($family->id) {
             $father = Family::findOrFail($family->id);
             $child = new Child();
             $child->date_naissance = Carbon::parse($request->date_naissance);
             $child->transport = $request->transport;
             $child->sexe = $request->sexe;
             $child->nom_enfant = ucfirst($request->nom_enfant);
             $child->age_enfant = $child->date_naissance->diffInYears(Carbon::now());
             $child->nationalite = \DB::table('countries')->where('id', $request->nationalite)->first()->nom_fr_fr;
             $child->user_id = \Auth::user()->id;
             $child->school_year_id = $request->id_ann_scol;
             $image = \Input::file('photo');
             if (!$image && empty($image)) {
                 $filename = '';
             } else {
                 $filename = $image->getClientOriginalName();
                 $path = public_path('uploads/' . $filename);
                 Image::make($image->getRealPath())->resize(313, 300)->save($path);
             }
             $child->photo = $filename;
             $child->family_id = $family->id;
             $child->save();
             if ($child->id) {
                 $ch = Child::find($child->id);
                 if ($niveau_global == 'Lycée') {
                     $ch->branches()->attach([$request->branche]);
                 }
                 if ($niveau_global == 'Maternelle' || $niveau_global == 'Primaire' || $niveau_global == 'Collège' || $niveau_global == 'Lycée' || $niveau_global == 'Crèche') {
                     $ch->levels()->attach([$request->niveau]);
                 }
                 /*if($niveau_global == 'Crèche')
                   {
                       $ch->classrooms()->attach([$request->classe]);
                   }*/
                 //classe
                 $cr = Classroom::where('user_id', \Auth::user()->id)->where('id', $request->classe)->first();
                 $cr->children()->attach([$child->id]);
                 $bill = new Bill();
                 $bill->status = 0;
                 // if no promotion is active
                 if (!PromotionAdvance::checkAdvancePromotion() && !PromotionExceptional::checkExceptionalPromotion()) {
                     if (isset($request->reduction) && !empty($request->reduction) && !is_null($request->reduction)) {
                         $bill->start = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->toDateString();
                         $bill->end = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString();
                         $bill->somme = PriceBill::countWhenNoPromotionButReduction($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport), $request->reduction);
                         $bill->reductionPrix = $request->reduction;
                         $bill->reduction = 1;
                         $bill->school_year_id = SchoolYear::getSchoolYearId();
                         $bill->nbrMois = $request->nbr_month;
                     } else {
                         $bill->start = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->toDateString();
                         $bill->end = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString();
                         $bill->somme = PriceBill::countWhenNoPromotion($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport));
                         $bill->reduction = 0;
                         $bill->school_year_id = $request->id_ann_scol;
                         $bill->nbrMois = $request->nbr_month;
                     }
                 }
                 if (PromotionAdvance::checkAdvancePromotion()) {
                     if ($request->nbr_month >= 3) {
                         $bill->start = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->toDateString();
                         $bill->end = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString();
                         $bill->somme = PromotionAdvance::countAccordingTo($prix_advance, PriceBill::assignPrice($request->niveau, $request->transport), $request->nbr_month);
                         $bill->reduction = 1;
                         $bill->reductionPrix = $prix_advance;
                         $bill->school_year_id = $request->id_ann_scol;
                         $bill->nbrMois = $request->nbr_month;
                     }
                     if ($request->nbr_month == 1) {
                         if (isset($request->reduction) && !empty($request->reduction) && !is_null($request->reduction)) {
                             $bill->start = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->toDateString();
                             $bill->end = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString();
                             $bill->somme = PriceBill::countWhenNoPromotionButReduction($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport), $request->reduction);
                             $bill->reductionPrix = $request->reduction;
                             $bill->reduction = 1;
                             $bill->school_year_id = SchoolYear::getSchoolYearId();
                             $bill->nbrMois = $request->nbr_month;
                         } else {
                             $bill->start = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->toDateString();
                             $bill->end = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString();
                             $bill->somme = PriceBill::countWhenNoPromotion($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport));
                             $bill->reduction = 0;
                             $bill->school_year_id = $request->id_ann_scol;
                             $bill->nbrMois = $request->nbr_month;
                         }
                     }
                 }
                 if (PromotionExceptional::checkExceptionalPromotion()) {
                     $bill->start = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->toDateString();
                     $bill->end = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString();
                     $bill->somme = PromotionExceptional::countAccordingTo($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport), $prix_exc);
                     $bill->reductionPrix = $prix_exc;
                     $bill->reduction = 1;
                     $bill->school_year_id = $request->id_ann_scol;
                     $bill->nbrMois = $request->nbr_month;
                 }
                 $bill->child_id = $child->id;
                 $bill->user_id = \Auth::user()->id;
                 $bill->save();
                 $enfant = Child::findOrFail($child->id);
                 if ($father->responsable == 0) {
                     $resp = $father->nom_mere;
                 } else {
                     $resp = $father->nom_pere;
                 }
                 event(new SendEmailToRespAfterRegistrationEvent($child->id, $resp, $enfant->nom_enfant, $enfant->created_at->toDateString(), $enfant->created_at->addMonth()->toDateString(), $father->email_responsable, $father->responsable, str_random(6)));
             }
         }
         return redirect()->back()->with('success', "l'élève et les parents ont bien été ajoutés! ");
     } else {
         // if the parent already in the database
         $child = new Child();
         $child->date_naissance = Carbon::parse($request->date_naissance);
         $child->nom_enfant = $request->nom_enfant;
         $child->sexe = $request->sexe;
         $child->age_enfant = $child->date_naissance->diffInYears(Carbon::now());
         $child->nationalite = \DB::table('countries')->where('id', $request->nationalite)->first()->nom_fr_fr;
         $child->school_year_id = $request->id_ann_scol;
         $child->transport = $request->transport;
         $child->user_id = \Auth::user()->id;
         $image = \Input::file('photo');
         if (!$image && empty($image)) {
             $filename = '';
         } else {
             $filename = $image->getClientOriginalName();
             $path = public_path('uploads/' . $filename);
             Image::make($image->getRealPath())->resize(313, 300)->save($path);
         }
         $child->photo = $filename;
         $child->family_id = $famille->id;
         $resp = Family::findOrFail($famille->id);
         $user = User::where('email', $resp->email_responsable)->first();
         if ($user) {
             $child->f_id = $user->id;
             $child->save();
             if ($child->id) {
                 $ch = Child::find($child->id);
                 if ($niveau_global == 'Lycée') {
                     $ch->branches()->attach([$request->branche]);
                 }
                 if ($niveau_global == 'Maternelle' || $niveau_global == 'Primaire' || $niveau_global == 'Collège' || $niveau_global == 'Lycée' || $niveau_global == 'Crèche') {
                     $ch->levels()->attach([$request->niveau]);
                 }
                 if ($niveau_global == 'Crèche') {
                     $ch->classrooms()->attach([$request->classe]);
                 }
                 $cr = Classroom::where('user_id', \Auth::user()->id)->where('id', $request->classe)->first();
                 $cr->children()->attach([$child->id]);
                 $bill = new Bill();
                 $bill->status = 0;
                 if (!PromotionAdvance::checkAdvancePromotion() && !PromotionExceptional::checkExceptionalPromotion()) {
                     if (isset($request->reduction) && !empty($request->reduction) && !is_null($request->reduction)) {
                         $bill->start = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->toDateString();
                         $bill->end = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString();
                         $bill->somme = PriceBill::countWhenNoPromotionButReduction($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport), $request->reduction);
                         $bill->reductionPrix = $request->reduction;
                         $bill->reduction = 1;
                         $bill->school_year_id = $request->id_ann_scol;
                         $bill->nbrMois = $request->nbr_month;
                     } else {
                         $bill->start = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->toDateString();
                         $bill->end = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString();
                         $bill->somme = PriceBill::countWhenNoPromotion($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport));
                         $bill->reduction = 0;
                         $bill->school_year_id = $request->id_ann_scol;
                         $bill->nbrMois = $request->nbr_month;
                     }
                 }
                 if (PromotionAdvance::checkAdvancePromotion()) {
                     if ($request->nbr_month >= 3) {
                         $bill->start = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->toDateString();
                         $bill->end = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString();
                         $bill->somme = PromotionAdvance::countAccordingTo($prix_advance, PriceBill::assignPrice($request->niveau, $request->transport), $request->nbr_month);
                         $bill->reduction = 1;
                         $bill->reductionPrix = $prix_advance;
                         $bill->school_year_id = $request->id_ann_scol;
                         $bill->nbrMois = $request->nbr_month;
                     }
                     if ($request->nbr_month == 1) {
                         if (isset($request->reduction) && !empty($request->reduction) && !is_null($request->reduction)) {
                             $bill->start = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->toDateString();
                             $bill->end = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString();
                             $bill->somme = PriceBill::countWhenNoPromotionButReduction($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport), $request->reduction);
                             $bill->reductionPrix = $request->reduction;
                             $bill->reduction = 1;
                             $bill->school_year_id = $request->id_ann_scol;
                             $bill->nbrMois = $request->nbr_month;
                         } else {
                             $bill->start = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->toDateString();
                             $bill->end = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString();
                             $bill->somme = PriceBill::countWhenNoPromotion($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport));
                             $bill->reduction = 0;
                             $bill->school_year_id = $request->id_ann_scol;
                             $bill->nbrMois = $request->nbr_month;
                         }
                     }
                 }
                 if (PromotionExceptional::checkExceptionalPromotion()) {
                     $bill->start = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->toDateString();
                     $bill->end = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString();
                     $bill->somme = PromotionExceptional::countAccordingTo($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport), $prix_exc);
                     $bill->reductionPrix = $prix_exc;
                     $bill->reduction = 1;
                     $bill->school_year_id = $request->id_ann_scol;
                     $bill->nbrMois = $request->nbr_month;
                 }
                 $bill->child_id = $child->id;
                 $bill->f_id = $user->id;
                 $bill->user_id = \Auth::user()->id;
                 $bill->save();
             }
         }
         return redirect()->back()->with('success', "l'élève a bien été ajouté! ");
     }
 }
Exemplo n.º 7
0
 public function addchild(Request $request, $id = null)
 {
     if (\Request::isMethod('get')) {
         $family = Family::where('user_id', \Auth::user()->id)->where('id', $id)->first();
         return view('families.addchild', compact('family'));
     } elseif (\Request::isMethod('post')) {
         // promotion Exceptional check
         if (PromotionExceptional::checkExceptionalPromotion()) {
             if (PromotionExceptional::checkExcTimeOfPromotionIfExpired()) {
                 if (PromotionExceptional::checkExcPriceandReturnIt() == 'no') {
                     return redirect()->back()->withErrors("la promotion Exceptionnelle est active mais aucun prix n'est défini")->withInput();
                 } else {
                     $prix_exc = PromotionExceptional::checkExcPriceandReturnIt();
                 }
             } else {
                 return redirect()->back()->withErrors("la promotion Exceptionnelle est active mais la durée est expirée");
             }
         }
         // promotion advanced check
         $prix_advance = '';
         if (PromotionAdvance::checkAdvancePromotion()) {
             if ($request->nbr_month > 1) {
                 if (PromotionAdvance::checkAdvIfPriceIsSet($request->nbr_month) !== false) {
                     $prix_advance = PromotionAdvance::checkAdvIfPriceIsSet($request->nbr_month);
                 } else {
                     return redirect()->back()->withErrors("Aucun prix n'est\n                    défini pour cette Promotion de " . $request->nbr_month . ' Mois');
                 }
             }
         }
         $validator = Validator::make([$request->all(), 'nom_enfant' => $request->nom_enfant, 'date_naissance' => $request->date_naissance, 'photo' => $request->photo, 'classe' => $request->classe, 'branche' => $request->branche, 'niveau' => $request->niveau], ['nom_enfant' => 'required', 'date_naissance' => 'required', 'photo' => 'image', 'niveau' => 'integer', 'classe' => 'integer', 'grade' => 'integer'], ['photo.image' => "L'image doit etre de type valide JPEG\\PNG", 'nom_enfant.required' => 'Le Nom de L\'enfant est obligatoire', 'date_naissance.required' => 'La Date de Naissance est Obligatoire', 'classe.integer' => "vous devez choisir une classe", 'niveau.integer' => "vous devez choisir un niveau", 'grade.integer' => "Vous devez chosir un niveau global"]);
         // if the parent already in the database
         if ($validator->passes()) {
             $niveau_global = \Auth::user()->grades()->where('id', $request->grade)->first()->name;
             $child = new Child();
             $child->date_naissance = Carbon::parse($request->date_naissance);
             $child->nom_enfant = $request->nom_enfant;
             $child->sexe = $request->sexe;
             $child->age_enfant = $child->date_naissance->diffInYears(Carbon::now());
             $child->nationalite = \DB::table('countries')->where('id', $request->nationalite)->first()->nom_fr_fr;
             $child->school_year_id = SchoolYear::getSchoolYearId();
             $child->transport = $request->transport;
             $child->user_id = \Auth::user()->id;
             $image = \Input::file('photo');
             if (!$image && empty($image)) {
                 $filename = '';
             } else {
                 $filename = $image->getClientOriginalName();
                 $path = public_path('uploads/' . $filename);
                 Image::make($image->getRealPath())->resize(313, 300)->save($path);
             }
             $child->photo = $filename;
             $child->family_id = $request->familyid;
             $resp = Family::findOrFail($request->familyid);
             $user = User::where('email', $resp->email_responsable)->first();
             if ($user) {
                 $child->f_id = $user->id;
                 $child->save();
                 if ($child->id) {
                     $ch = Child::find($child->id);
                     if ($niveau_global == 'Lycée') {
                         $ch->branches()->attach([$request->branche]);
                     }
                     if ($niveau_global == 'Maternelle' || $niveau_global == 'Primaire' || $niveau_global == 'Collège' || $niveau_global == 'Lycée' || $niveau_global == 'Crèche') {
                         $ch->levels()->attach([$request->niveau]);
                     }
                     /*  if($niveau_global == 'Crèche')
                         {
                             $ch->classrooms()->attach([$request->classe]);
                         }*/
                     $cr = Classroom::where('user_id', \Auth::user()->id)->where('id', $request->classe)->first();
                     $cr->children()->attach([$child->id]);
                     $bill = new Bill();
                     $bill->status = 0;
                     if (!PromotionAdvance::checkAdvancePromotion() && !PromotionExceptional::checkExceptionalPromotion()) {
                         if (isset($request->reduction) && !empty($request->reduction) && !is_null($request->reduction)) {
                             $bill->start = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->toDateString();
                             $bill->end = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString();
                             $bill->somme = PriceBill::countWhenNoPromotionButReduction($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport), $request->reduction);
                             $bill->reductionPrix = $request->reduction;
                             $bill->reduction = 1;
                             $bill->school_year_id = \Auth::user()->schoolyears()->where('current', 1)->first()->id;
                             $bill->nbrMois = $request->nbr_month;
                         } else {
                             $bill->start = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->toDateString();
                             $bill->end = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString();
                             $bill->somme = PriceBill::countWhenNoPromotion($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport));
                             $bill->reduction = 0;
                             $bill->school_year_id = \Auth::user()->schoolyears()->where('current', 1)->first()->id;
                             $bill->nbrMois = $request->nbr_month;
                         }
                     }
                     if (PromotionAdvance::checkAdvancePromotion()) {
                         if ($request->nbr_month >= 3) {
                             $bill->start = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->toDateString();
                             $bill->end = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString();
                             $bill->somme = PromotionAdvance::countAccordingTo($prix_advance, PriceBill::assignPrice($request->niveau, $request->transport), $request->nbr_month);
                             $bill->reduction = 1;
                             $bill->reductionPrix = $prix_advance;
                             $bill->school_year_id = \Auth::user()->schoolyears()->where('current', 1)->first()->id;
                             $bill->nbrMois = $request->nbr_month;
                         }
                         if ($request->nbr_month == 1) {
                             if (isset($request->reduction) && !empty($request->reduction) && !is_null($request->reduction)) {
                                 $bill->start = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->toDateString();
                                 $bill->end = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString();
                                 $bill->somme = PriceBill::countWhenNoPromotionButReduction($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport), $request->reduction);
                                 $bill->reductionPrix = $request->reduction;
                                 $bill->reduction = 1;
                                 $bill->school_year_id = \Auth::user()->schoolyears()->where('current', 1)->first()->id;
                                 $bill->nbrMois = $request->nbr_month;
                             } else {
                                 $bill->start = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->toDateString();
                                 $bill->end = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString();
                                 $bill->somme = PriceBill::countWhenNoPromotion($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport));
                                 $bill->reduction = 0;
                                 $bill->school_year_id = \Auth::user()->schoolyears()->where('current', 1)->first()->id;
                                 $bill->nbrMois = $request->nbr_month;
                             }
                         }
                     }
                     if (PromotionExceptional::checkExceptionalPromotion()) {
                         $bill->start = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->toDateString();
                         $bill->end = SchoolYear::find(SchoolYear::getSchoolYearId())->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString();
                         $bill->somme = PromotionExceptional::countAccordingTo($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport), $prix_exc);
                         $bill->reductionPrix = $prix_exc;
                         $bill->reduction = 1;
                         $bill->school_year_id = \Auth::user()->schoolyears()->where('current', 1)->first()->id;
                         $bill->nbrMois = $request->nbr_month;
                     }
                     $bill->child_id = $child->id;
                     $bill->f_id = $user->id;
                     $bill->user_id = \Auth::user()->id;
                     $bill->save();
                 }
             }
             return redirect()->back()->with('success', "l'élève a bien été ajouté! ");
         } else {
             return redirect()->back()->withErrors($validator);
         }
     }
 }
Exemplo n.º 8
0
 /**
  * The owner of the course can confirm it,
  * TODO send an email to all participants
  * TODO send bill to the owner
  * @param $id
  * @return \Illuminate\Http\RedirectResponse
  */
 public function confirm($id)
 {
     #TODO only the course owner should be allowed to do this.
     $course = Course::findOrFail($id);
     $course->confirmed = true;
     $course->save();
     $bill = new Bill();
     $bill->course()->associate($course);
     $bill->save();
     $this->sendBill(Auth::user(), $bill);
     \Session::flash('flash_message', 'Der Kurs wurde erfolgreich bestätigt');
     \Session::flash('flash_message_type', 'success');
     return redirect()->action('CourseController@show', [$course->id]);
 }
Exemplo n.º 9
0
 public function store()
 {
     $rules = array('year' => 'required', 'month' => 'required');
     $validator = Validator::make(Input::all(), $rules);
     // process the login
     if ($validator->fails()) {
         return Redirect::to('invoicing')->withErrors($validator);
     } else {
         $clients = Client::All();
         $bill_date = Input::get('year') . '-' . Input::get('month') . '-' . cal_days_in_month(CAL_GREGORIAN, Input::get('month'), Input::get('year'));
         $bill_date_first_day = Carbon::createFromDate(Input::get('year'), Input::get('month'), 1);
         $bill_date_last_day = clone $bill_date_first_day;
         $bill_date_last_day = $bill_date_last_day->addMonth();
         foreach ($clients as $client) {
             foreach ($client->agreements as $agreement) {
                 $nds = 0;
                 $commission_sum = 0;
                 $without_nds = 0;
                 $with_nds = 0;
                 $debt = 0;
                 $pred_with_nds = 0;
                 $with_nds_delivery = 0;
                 $repayments = 0;
                 foreach ($agreement->relations as $relation) {
                     if ($agreement->account == FALSE) {
                         foreach ($relation->deliveries as $delivery) {
                             if ($delivery->status == 'Профинансирована') {
                                 $pred_with_nds = $delivery->dailyChargeCommission()->where('handler', false)->whereDate('created_at', '<', $bill_date_first_day)->sum('with_nds');
                                 $repayments = $delivery->dailyChargeCommission()->where('handler', true)->whereDate('created_at', '<', $bill_date_last_day)->sum('with_nds');
                                 $with_nds_delivery = $delivery->dailyChargeCommission()->where('handler', false)->whereYear('created_at', '=', Input::get('year'))->whereMonth('created_at', '=', Input::get('month'))->sum('with_nds');
                                 if ($repayments > $pred_with_nds) {
                                     if ($repayments >= $with_nds_delivery + $pred_with_nds) {
                                         $debt += 0;
                                     } else {
                                         $debt += $with_nds_delivery - ($repayments - $pred_with_nds);
                                     }
                                 } else {
                                     $debt += $with_nds_delivery;
                                 }
                                 $with_nds += $with_nds_delivery;
                                 $nds += $delivery->dailyChargeCommission()->where('handler', false)->whereYear('created_at', '=', Input::get('year'))->whereMonth('created_at', '=', Input::get('month'))->sum('nds');
                                 $without_nds += $delivery->dailyChargeCommission()->where('handler', false)->whereYear('created_at', '=', Input::get('year'))->whereMonth('created_at', '=', Input::get('month'))->sum('without_nds');
                                 $bill_date = Input::get('year') . '-' . Input::get('month') . '-' . cal_days_in_month(CAL_GREGORIAN, Input::get('month'), Input::get('year'));
                             }
                         }
                     } else {
                         foreach ($relation->deliveries as $delivery) {
                             if ($delivery->date_of_payment != NULL and $delivery->date_of_payment->year == Input::get('year') and $delivery->date_of_payment->month == Input::get('month') and $delivery->status == 'Профинансирована') {
                                 foreach ($delivery->dailyChargeCommission->where('handler', false) as $commission) {
                                     $nds += $delivery->dailyChargeCommission()->where('handler', false)->sum('nds');
                                     $without_nds += $delivery->dailyChargeCommission()->where('handler', false)->sum('without_nds');
                                     $with_nds += $delivery->dailyChargeCommission()->where('handler', false)->sum('with_nds');
                                     $bill_date = $delivery->date_of_payment;
                                     $debt = 0;
                                 }
                             }
                         }
                     }
                 }
                 if ($with_nds != 0) {
                     $bill = new Bill();
                     $bill->bill_date = $bill_date;
                     $bill->agreement_id = $agreement->id;
                     $bill->nds = $nds;
                     $bill->with_nds = $with_nds;
                     $bill->without_nds = $without_nds;
                     $bill->client_id = $client->id;
                     $bill->debt = $debt;
                     $bill->save();
                 }
             }
         }
     }
 }
Exemplo n.º 10
0
 public function generateInvoice(Request $request, $id = "")
 {
     $input = $request->all();
     $company = !empty($id) ? Company::find($id) : Company::find($input['company_id']);
     $ArrMain = [];
     //  print_r($input);
     if (count($input) > 0) {
         //allow room for invoice to be processed for recent uploaded and date range
         $stacks = Invoicingstack::where("company_id", "=", $company->id)->where("status", "=", 0)->get();
         // var_dump("ok ok");
     } else {
         $stacks = Invoicingstack::where("company_id", "=", $company->id)->where("status", "=", 0)->get();
     }
     //$input['id']=$id;
     $total = 0;
     $bill = new Bill();
     $invoiceno = "";
     if (count($stacks) > 0) {
         $bill_no = $bill->genInvoiceNo($company->id) > 0 ? $bill->genInvoiceNo($company->id) : "01";
         $invoiceno = !empty($input['inv_no']) && $input['inv_no'] != "" ? "RJLEX/" . strtoupper(substr($company->name, 0, 3)) . "/" . $input['inv_no'] : "RJLEX/" . strtoupper(substr($company->name, 0, 3)) . "/" . str_pad($bill_no, 3, "0", STR_PAD_LEFT);
         $bill->invoice_no = $invoiceno;
         $bill->created_at = date("Y-m-d H:i:s");
         $bill->updated_at = date("Y-m-d H:i:s");
         $bill->company_id = $company->id;
         $bill->invoice_date = date("Y-m-d H:i:s");
         $check = Bill::where("invoice_no", "=", $invoiceno)->pluck("invoice_no");
         if (!empty($check)) {
             echo "Invoice number already existing in database";
             exit;
         }
         $bill->save();
         //$invoiceno = "RJLEX/".strtoupper(substr($company->name,0,3))."/".$bill->genInvoiceNo();
     }
     $dateFrom = "2000-01-01";
     $dateTo = "2000-01-01";
     $objPHPExcel = new \PHPExcel();
     $m = 0;
     $s = 0;
     foreach ($stacks as $stack) {
         // Create a new worksheet called “My Data”
         $s++;
         $sheetName = "RJLEX_" . strtoupper(substr($company->name, 0, 3)) . "_" . $bill_no;
         $siteName = Branch::where("id", "=", $stack->site_id)->pluck("name");
         $myWorkSheet = new \PHPExcel_Worksheet($objPHPExcel, $siteName);
         $objPHPExcel->addSheet($myWorkSheet, $m);
         /**/
         $objPHPExcel->setActiveSheetIndex($m);
         $m++;
         $site = "";
         $siteName = "";
         $description = "";
         $printNo = 0;
         $copyNo = 0;
         /**
          * For each loop of the invoicing table,
          * compute the cost of each print job and populate/create
          * the invoice detail table
          */
         $a3Arr = [];
         $a4Arr = [];
         $sumNoPagesA3Color = 0;
         //+= $minvoice->number_of_pages;
         $sumAmountA3Color = 0;
         //$amount;
         $sumNoPagesA4Color = 0;
         // $minvoice->number_of_pages;
         $sumAmountA4Color = 0;
         //$amount;
         $sumNoPagesA3Mono = 0;
         // $minvoice->number_of_pages;
         $sumAmountA3Mono = 0;
         $sumNoPagesA4Mono = 0;
         //0 $minvoice->number_of_pages;
         $sumAmountA4Mono = 0;
         //$amount;
         $sumTotal = 0;
         $unitCostA3Mono = 0;
         $unitCostA4Mono = 0;
         $unitCostA3Color = 0;
         $unitCostA4Color = 0;
         $x = 1;
         $p = 1;
         if (count($input) > 0) {
             $invoicing = DB::table("invoicing")->where("stack_id", "=", $stack->id)->get();
             //->where("final_date",">=",$input['date_from'])->where("final_date","<=","date_to")
         } else {
             $invoicing = DB::table("invoicing")->where("stack_id", "=", $stack->id)->get();
         }
         //$dateFrom  = DB::table("invoicing")->where("stack_id","=",$stack->id)->max('final_date');  //DB::table("invoicing")->where()
         //$dateTo    = DB::table("invoicing")->where("stack_id","=",$stack->id)->min('final_date');
         foreach ($invoicing as $minvoice) {
             //One Location in loop
             $froDate = new \DateTime("2000-01-01");
             $toDate = new \DateTime("2000-01-01");
             if ($x == 1) {
                 //$dateFrom = new \DateTime($minvoice->final_date);
                 //$dateTo = new \DateTime($minvoice->final_date);
                 $objPHPExcel->getActiveSheet()->setCellValue('A' . $x, "SITE");
                 $objPHPExcel->getActiveSheet()->setCellValue('B' . $x, "User ID");
                 $objPHPExcel->getActiveSheet()->setCellValue('C' . $x, "Submit IP");
                 $objPHPExcel->getActiveSheet()->setCellValue('D' . $x, "Print Job Name");
                 $objPHPExcel->getActiveSheet()->setCellValue('E' . $x, "Submit Date");
                 $objPHPExcel->getActiveSheet()->setCellValue('F' . $x, "Final Date");
                 $objPHPExcel->getActiveSheet()->setCellValue('G' . $x, "Final Action");
                 $objPHPExcel->getActiveSheet()->setCellValue('H' . $x, "Final Site");
                 $objPHPExcel->getActiveSheet()->setCellValue('I' . $x, "Number of Pages");
                 $objPHPExcel->getActiveSheet()->setCellValue('J' . $x, "Cost Per Page");
                 $objPHPExcel->getActiveSheet()->setCellValue('K' . $x, "Total Cost");
                 $objPHPExcel->getActiveSheet()->setCellValue('L' . $x, "Release IP");
                 $objPHPExcel->getActiveSheet()->setCellValue('M' . $x, "Release User");
                 $objPHPExcel->getActiveSheet()->setCellValue('N' . $x, "Release Method");
                 $objPHPExcel->getActiveSheet()->setCellValue('O' . $x, "Print Job Color");
                 $objPHPExcel->getActiveSheet()->setCellValue('P' . $x, "Print Job Duplex");
                 $objPHPExcel->getActiveSheet()->setCellValue('Q' . $x, "Print Job Paper Size");
                 $objPHPExcel->getActiveSheet()->setCellValue('R' . $x, "Release Model");
                 $objPHPExcel->getActiveSheet()->setCellValue('S' . $x, "Release Model Type");
                 $objPHPExcel->getActiveSheet()->setCellValue('T' . $x, "Rrelease Host Name");
             }
             //$date = date_create_from_format("Y-m-d H:i:s",$minvoice->final_date);
             if (isset($input['date_from'])) {
                 $dateFrom = $input['date_from'];
             } else {
                 /*$froDate = $dateFrom;
                   if( (int)$date->getTimestamp() <= (int)$froDate->getTimestamp() ){
                       $dateFrom = new \DateTime($minvoice->final_date);
                   }*/
             }
             if (isset($input['date_to'])) {
                 $dateTo = $input['date_to'];
             } else {
                 /*$toDate = $dateTo;
                                     if( (int)$date->getTimestamp() >= (int)$toDate->getTimestamp() ){
                                         $dateTo = new \DateTime($minvoice->final_date);
                 
                                     }*/
             }
             $site = Branch::where("id", "=", $minvoice->site)->pluck("name");
             $a3Arr[] = "";
             $a4Arr[] = "";
             // if($minvoice->job_paper_size == "A3"){}
             $paperid = DB::table("papers")->where("name", $minvoice->job_paper_size)->pluck("id");
             if (strtolower($minvoice->final_action) == "p" || strtolower($minvoice->final_action) == "c") {
                 //check if action type is print
                 /**
                  * check if colored or mono
                  */
                 $p++;
                 if (strtolower($minvoice->device_type) == "c") {
                     if (strtolower($minvoice->job_color) == "y") {
                         if ($minvoice->job_paper_size == "A3" || ($minvoice->job_paper_size == "Tabloid" || $minvoice->job_paper_size == "Ledger")) {
                             if (strtolower($minvoice->device_name) == 'lexmark x925' || strtolower($minvoice->device_name) == 'lexmark x950' || strtolower($minvoice->device_name) == 'lexmark x950de' || strtolower($minvoice->device_name) == 'lexmark x792de' || strtolower($minvoice->device_name) == 'lexmark cx510de') {
                                 $cost = Price::where("job_id", 1)->where("job_type", "color")->where("paper_id", $paperid)->pluck("price");
                                 $amount = $cost * $minvoice->number_of_pages;
                                 $sumNoPagesA3Color += $minvoice->number_of_pages;
                                 $sumAmountA3Color += $amount;
                                 //not longer neccessory because cumulated pages could be multiplied by the unit cost
                                 $unitCostA3Color = $cost;
                                 $objPHPExcel->getActiveSheet()->setCellValue('A' . $p, $site);
                                 $objPHPExcel->getActiveSheet()->setCellValue('B' . $p, $minvoice->user);
                                 $objPHPExcel->getActiveSheet()->setCellValue('C' . $p, $minvoice->ip);
                                 $objPHPExcel->getActiveSheet()->setCellValue('D' . $p, $minvoice->job_title);
                                 $objPHPExcel->getActiveSheet()->setCellValue('E' . $p, $minvoice->submit_date);
                                 $objPHPExcel->getActiveSheet()->setCellValue('F' . $p, $minvoice->final_date);
                                 $objPHPExcel->getActiveSheet()->setCellValue('G' . $p, $minvoice->final_action);
                                 $objPHPExcel->getActiveSheet()->setCellValue('H' . $p, $minvoice->final_site);
                                 $objPHPExcel->getActiveSheet()->setCellValue('I' . $p, $minvoice->number_of_pages);
                                 $objPHPExcel->getActiveSheet()->setCellValue('J' . $p, $cost);
                                 $objPHPExcel->getActiveSheet()->setCellValue('K' . $p, $amount);
                                 $objPHPExcel->getActiveSheet()->setCellValue('L' . $p, $minvoice->release_ip);
                                 $objPHPExcel->getActiveSheet()->setCellValue('M' . $p, $minvoice->release_user);
                                 $objPHPExcel->getActiveSheet()->setCellValue('N' . $p, $minvoice->release_method);
                                 $objPHPExcel->getActiveSheet()->setCellValue('O' . $p, "Y");
                                 //
                                 $objPHPExcel->getActiveSheet()->setCellValue('P' . $p, $minvoice->print_job_duplex);
                                 //duplex
                                 $objPHPExcel->getActiveSheet()->setCellValue('Q' . $p, $minvoice->job_paper_size);
                                 $objPHPExcel->getActiveSheet()->setCellValue('R' . $p, $minvoice->device_name);
                                 $objPHPExcel->getActiveSheet()->setCellValue('S' . $p, $minvoice->device_type);
                                 $objPHPExcel->getActiveSheet()->setCellValue('T' . $p, $minvoice->device_host);
                             } elseif (strtolower($minvoice->device_name) == 'lexmark x860') {
                                 # else if Lexmark X860 (a mono A3 printer) //|| strtolower($minvoice->device_name) == 'lexmark x860de'
                                 $cost = Price::where("job_id", 1)->where("job_type", "mono")->where("paper_id", $paperid)->pluck("price");
                                 $amount = $cost * $minvoice->number_of_pages;
                                 $sumNoPagesA3Mono += $minvoice->number_of_pages;
                                 $sumAmountA3Mono += $amount;
                                 //not longer neccessory because cumulated pages could be multiplied by the unit cost
                                 $unitCostA3Mono = $cost;
                                 $objPHPExcel->getActiveSheet()->setCellValue('A' . $p, $site);
                                 $objPHPExcel->getActiveSheet()->setCellValue('B' . $p, $minvoice->user);
                                 $objPHPExcel->getActiveSheet()->setCellValue('C' . $p, $minvoice->ip);
                                 $objPHPExcel->getActiveSheet()->setCellValue('D' . $p, $minvoice->job_title);
                                 $objPHPExcel->getActiveSheet()->setCellValue('E' . $p, $minvoice->submit_date);
                                 $objPHPExcel->getActiveSheet()->setCellValue('F' . $p, $minvoice->final_date);
                                 $objPHPExcel->getActiveSheet()->setCellValue('G' . $p, $minvoice->final_action);
                                 $objPHPExcel->getActiveSheet()->setCellValue('H' . $p, $minvoice->final_site);
                                 $objPHPExcel->getActiveSheet()->setCellValue('I' . $p, $minvoice->number_of_pages);
                                 $objPHPExcel->getActiveSheet()->setCellValue('J' . $p, $cost);
                                 $objPHPExcel->getActiveSheet()->setCellValue('K' . $p, $amount);
                                 $objPHPExcel->getActiveSheet()->setCellValue('L' . $p, $minvoice->release_ip);
                                 $objPHPExcel->getActiveSheet()->setCellValue('M' . $p, $minvoice->release_user);
                                 $objPHPExcel->getActiveSheet()->setCellValue('N' . $p, $minvoice->release_method);
                                 $objPHPExcel->getActiveSheet()->setCellValue('O' . $p, "N");
                                 //
                                 $objPHPExcel->getActiveSheet()->setCellValue('P' . $p, $minvoice->print_job_duplex);
                                 //duplex
                                 $objPHPExcel->getActiveSheet()->setCellValue('Q' . $p, $minvoice->job_paper_size);
                                 $objPHPExcel->getActiveSheet()->setCellValue('R' . $p, $minvoice->device_name);
                                 $objPHPExcel->getActiveSheet()->setCellValue('S' . $p, $minvoice->device_type);
                                 $objPHPExcel->getActiveSheet()->setCellValue('T' . $p, $minvoice->device_host);
                             } else {
                                 # otherwise its an A4 job for color not A3 as may be indicated in datafile but A4
                                 $cost = Price::where("job_id", 1)->where("job_type", "color")->where("paper_id", $paperid)->pluck("price");
                                 $amount = $cost * $minvoice->number_of_pages;
                                 $sumNoPagesA4Color += $minvoice->number_of_pages;
                                 $sumAmountA4Color += $amount;
                                 //not longer neccessory because cumulated pages could be multiplied by the unit cost
                                 $unitCostA4Color = $cost;
                                 $objPHPExcel->getActiveSheet()->setCellValue('A' . $p, $site);
                                 $objPHPExcel->getActiveSheet()->setCellValue('B' . $p, $minvoice->user);
                                 $objPHPExcel->getActiveSheet()->setCellValue('C' . $p, $minvoice->ip);
                                 $objPHPExcel->getActiveSheet()->setCellValue('D' . $p, $minvoice->job_title);
                                 $objPHPExcel->getActiveSheet()->setCellValue('E' . $p, $minvoice->submit_date);
                                 $objPHPExcel->getActiveSheet()->setCellValue('F' . $p, $minvoice->final_date);
                                 $objPHPExcel->getActiveSheet()->setCellValue('G' . $p, $minvoice->final_action);
                                 $objPHPExcel->getActiveSheet()->setCellValue('H' . $p, $minvoice->final_site);
                                 $objPHPExcel->getActiveSheet()->setCellValue('I' . $p, $minvoice->number_of_pages);
                                 $objPHPExcel->getActiveSheet()->setCellValue('J' . $p, $cost);
                                 $objPHPExcel->getActiveSheet()->setCellValue('K' . $p, $amount);
                                 $objPHPExcel->getActiveSheet()->setCellValue('L' . $p, $minvoice->release_ip);
                                 $objPHPExcel->getActiveSheet()->setCellValue('M' . $p, $minvoice->release_user);
                                 $objPHPExcel->getActiveSheet()->setCellValue('N' . $p, $minvoice->release_method);
                                 $objPHPExcel->getActiveSheet()->setCellValue('O' . $p, "Y");
                                 //
                                 $objPHPExcel->getActiveSheet()->setCellValue('P' . $p, $minvoice->print_job_duplex);
                                 //duplex
                                 $objPHPExcel->getActiveSheet()->setCellValue('Q' . $p, $minvoice->job_paper_size);
                                 $objPHPExcel->getActiveSheet()->setCellValue('R' . $p, $minvoice->device_name);
                                 $objPHPExcel->getActiveSheet()->setCellValue('S' . $p, $minvoice->device_type);
                                 $objPHPExcel->getActiveSheet()->setCellValue('T' . $p, $minvoice->device_host);
                             }
                         } else {
                             $cost = Price::where("job_id", 1)->where("job_type", "color")->where("paper_id", $paperid)->pluck("price");
                             $amount = $cost * $minvoice->number_of_pages;
                             $sumNoPagesA4Color += $minvoice->number_of_pages;
                             $sumAmountA4Color += $amount;
                             //not longer neccessory because cumulated pages could be multiplied by the unit cost
                             $unitCostA4Color = $cost;
                             $objPHPExcel->getActiveSheet()->setCellValue('A' . $p, $site);
                             $objPHPExcel->getActiveSheet()->setCellValue('B' . $p, $minvoice->user);
                             $objPHPExcel->getActiveSheet()->setCellValue('C' . $p, $minvoice->ip);
                             $objPHPExcel->getActiveSheet()->setCellValue('D' . $p, $minvoice->job_title);
                             $objPHPExcel->getActiveSheet()->setCellValue('E' . $p, $minvoice->submit_date);
                             $objPHPExcel->getActiveSheet()->setCellValue('F' . $p, $minvoice->final_date);
                             $objPHPExcel->getActiveSheet()->setCellValue('G' . $p, $minvoice->final_action);
                             $objPHPExcel->getActiveSheet()->setCellValue('H' . $p, $minvoice->final_site);
                             $objPHPExcel->getActiveSheet()->setCellValue('I' . $p, $minvoice->number_of_pages);
                             $objPHPExcel->getActiveSheet()->setCellValue('J' . $p, $cost);
                             $objPHPExcel->getActiveSheet()->setCellValue('K' . $p, $amount);
                             $objPHPExcel->getActiveSheet()->setCellValue('L' . $p, $minvoice->release_ip);
                             $objPHPExcel->getActiveSheet()->setCellValue('M' . $p, $minvoice->release_user);
                             $objPHPExcel->getActiveSheet()->setCellValue('N' . $p, $minvoice->release_method);
                             $objPHPExcel->getActiveSheet()->setCellValue('O' . $p, "Y");
                             //
                             $objPHPExcel->getActiveSheet()->setCellValue('P' . $p, $minvoice->print_job_duplex);
                             //duplex
                             $objPHPExcel->getActiveSheet()->setCellValue('Q' . $p, $minvoice->job_paper_size);
                             $objPHPExcel->getActiveSheet()->setCellValue('R' . $p, $minvoice->device_name);
                             $objPHPExcel->getActiveSheet()->setCellValue('S' . $p, $minvoice->device_type);
                             $objPHPExcel->getActiveSheet()->setCellValue('T' . $p, $minvoice->device_host);
                         }
                     } elseif (strtolower($minvoice->job_color) == "n") {
                         if ($minvoice->job_paper_size == "A3" || ($minvoice->job_paper_size == "Tabloid" || $minvoice->job_paper_size == "Ledger")) {
                             //&&
                             if (strtolower($minvoice->device_name) == 'lexmark mx860') {
                                 //de
                                 $cost = Price::where("job_id", 1)->where("job_type", "mono")->where("paper_id", $paperid)->pluck("price");
                                 $amount = $cost * $minvoice->number_of_pages;
                                 $sumNoPagesA3Mono += $minvoice->number_of_pages;
                                 $sumAmountA3Mono += $amount;
                                 //not longer neccessory because cumulated pages could be multiplied by the unit cost
                                 $unitCostA3Mono = $cost;
                                 $objPHPExcel->getActiveSheet()->setCellValue('A' . $p, $site);
                                 $objPHPExcel->getActiveSheet()->setCellValue('B' . $p, $minvoice->user);
                                 $objPHPExcel->getActiveSheet()->setCellValue('C' . $p, $minvoice->ip);
                                 $objPHPExcel->getActiveSheet()->setCellValue('D' . $p, $minvoice->job_title);
                                 $objPHPExcel->getActiveSheet()->setCellValue('E' . $p, $minvoice->submit_date);
                                 $objPHPExcel->getActiveSheet()->setCellValue('F' . $p, $minvoice->final_date);
                                 $objPHPExcel->getActiveSheet()->setCellValue('G' . $p, $minvoice->final_action);
                                 $objPHPExcel->getActiveSheet()->setCellValue('H' . $p, $minvoice->final_site);
                                 $objPHPExcel->getActiveSheet()->setCellValue('I' . $p, $minvoice->number_of_pages);
                                 $objPHPExcel->getActiveSheet()->setCellValue('J' . $p, $cost);
                                 $objPHPExcel->getActiveSheet()->setCellValue('K' . $p, $amount);
                                 $objPHPExcel->getActiveSheet()->setCellValue('L' . $p, $minvoice->release_ip);
                                 $objPHPExcel->getActiveSheet()->setCellValue('M' . $p, $minvoice->release_user);
                                 $objPHPExcel->getActiveSheet()->setCellValue('N' . $p, $minvoice->release_method);
                                 $objPHPExcel->getActiveSheet()->setCellValue('O' . $p, "N");
                                 //
                                 $objPHPExcel->getActiveSheet()->setCellValue('P' . $p, $minvoice->print_job_duplex);
                                 //duplex
                                 $objPHPExcel->getActiveSheet()->setCellValue('Q' . $p, $minvoice->job_paper_size);
                                 $objPHPExcel->getActiveSheet()->setCellValue('R' . $p, $minvoice->device_name);
                                 $objPHPExcel->getActiveSheet()->setCellValue('S' . $p, $minvoice->device_type);
                                 $objPHPExcel->getActiveSheet()->setCellValue('T' . $p, $minvoice->device_host);
                             } elseif (strtolower($minvoice->device_name) == 'lexmark x925' || strtolower($minvoice->device_name) == 'lexmark x950' || strtolower($minvoice->device_name) == 'lexmark x950de' || strtolower($minvoice->device_name) == 'lexmark x792de' || strtolower($minvoice->device_name) == 'lexmark cx510de') {
                                 $cost = Price::where("job_id", 1)->where("job_type", "mono")->where("paper_id", $paperid)->pluck("price");
                                 $amount = $cost * $minvoice->number_of_pages;
                                 $sumNoPagesA3Mono += $minvoice->number_of_pages;
                                 $sumAmountA3Mono += $amount;
                                 //not longer neccessory because cumulated pages could be multiplied by the unit cost
                                 $unitCostA3Mono = $cost;
                                 $objPHPExcel->getActiveSheet()->setCellValue('A' . $p, $site);
                                 $objPHPExcel->getActiveSheet()->setCellValue('B' . $p, $minvoice->user);
                                 $objPHPExcel->getActiveSheet()->setCellValue('C' . $p, $minvoice->ip);
                                 $objPHPExcel->getActiveSheet()->setCellValue('D' . $p, $minvoice->job_title);
                                 $objPHPExcel->getActiveSheet()->setCellValue('E' . $p, $minvoice->submit_date);
                                 $objPHPExcel->getActiveSheet()->setCellValue('F' . $p, $minvoice->final_date);
                                 $objPHPExcel->getActiveSheet()->setCellValue('G' . $p, $minvoice->final_action);
                                 $objPHPExcel->getActiveSheet()->setCellValue('H' . $p, $minvoice->final_site);
                                 $objPHPExcel->getActiveSheet()->setCellValue('I' . $p, $minvoice->number_of_pages);
                                 $objPHPExcel->getActiveSheet()->setCellValue('J' . $p, $cost);
                                 $objPHPExcel->getActiveSheet()->setCellValue('K' . $p, $amount);
                                 $objPHPExcel->getActiveSheet()->setCellValue('L' . $p, $minvoice->release_ip);
                                 $objPHPExcel->getActiveSheet()->setCellValue('M' . $p, $minvoice->release_user);
                                 $objPHPExcel->getActiveSheet()->setCellValue('N' . $p, $minvoice->release_method);
                                 $objPHPExcel->getActiveSheet()->setCellValue('O' . $p, "N");
                                 //
                                 $objPHPExcel->getActiveSheet()->setCellValue('P' . $p, $minvoice->print_job_duplex);
                                 //duplex
                                 $objPHPExcel->getActiveSheet()->setCellValue('Q' . $p, $minvoice->job_paper_size);
                                 $objPHPExcel->getActiveSheet()->setCellValue('R' . $p, $minvoice->device_name);
                                 $objPHPExcel->getActiveSheet()->setCellValue('S' . $p, $minvoice->device_type);
                                 $objPHPExcel->getActiveSheet()->setCellValue('T' . $p, $minvoice->device_host);
                             } else {
                                 # otherwise its an A4 job for mono not A3 as may be indicated in datafile
                                 /** Print is a mono device*/
                                 $cost = Price::where("job_id", 1)->where("job_type", "mono")->where("paper_id", $paperid)->pluck("price");
                                 $amount = $cost * $minvoice->number_of_pages;
                                 $sumNoPagesA4Mono += $minvoice->number_of_pages;
                                 $sumAmountA4Mono += $amount;
                                 //not longer neccessory because cumulated pages could be multiplied by the unit cost
                                 $unitCostA4Mono = $cost;
                                 $objPHPExcel->getActiveSheet()->setCellValue('A' . $p, $site);
                                 $objPHPExcel->getActiveSheet()->setCellValue('B' . $p, $minvoice->user);
                                 $objPHPExcel->getActiveSheet()->setCellValue('C' . $p, $minvoice->ip);
                                 $objPHPExcel->getActiveSheet()->setCellValue('D' . $p, $minvoice->job_title);
                                 $objPHPExcel->getActiveSheet()->setCellValue('E' . $p, $minvoice->submit_date);
                                 $objPHPExcel->getActiveSheet()->setCellValue('F' . $p, $minvoice->final_date);
                                 $objPHPExcel->getActiveSheet()->setCellValue('G' . $p, $minvoice->final_action);
                                 $objPHPExcel->getActiveSheet()->setCellValue('H' . $p, $minvoice->final_site);
                                 $objPHPExcel->getActiveSheet()->setCellValue('I' . $p, $minvoice->number_of_pages);
                                 $objPHPExcel->getActiveSheet()->setCellValue('J' . $p, $cost);
                                 $objPHPExcel->getActiveSheet()->setCellValue('K' . $p, $amount);
                                 $objPHPExcel->getActiveSheet()->setCellValue('L' . $p, $minvoice->release_ip);
                                 $objPHPExcel->getActiveSheet()->setCellValue('M' . $p, $minvoice->release_user);
                                 $objPHPExcel->getActiveSheet()->setCellValue('N' . $p, $minvoice->release_method);
                                 $objPHPExcel->getActiveSheet()->setCellValue('O' . $p, "N");
                                 //
                                 $objPHPExcel->getActiveSheet()->setCellValue('P' . $p, $minvoice->print_job_duplex);
                                 //duplex
                                 $objPHPExcel->getActiveSheet()->setCellValue('Q' . $p, $minvoice->job_paper_size);
                                 $objPHPExcel->getActiveSheet()->setCellValue('R' . $p, $minvoice->device_name);
                                 $objPHPExcel->getActiveSheet()->setCellValue('S' . $p, $minvoice->device_type);
                                 $objPHPExcel->getActiveSheet()->setCellValue('T' . $p, $minvoice->device_host);
                             }
                         } else {
                             $cost = Price::where("job_id", 1)->where("job_type", "mono")->where("paper_id", $paperid)->pluck("price");
                             $amount = $cost * $minvoice->number_of_pages;
                             $sumNoPagesA4Mono += $minvoice->number_of_pages;
                             $sumAmountA4Mono += $amount;
                             //not longer neccessory because cumulated pages could be multiplied by the unit cost
                             $unitCostA4Mono = $cost;
                             $objPHPExcel->getActiveSheet()->setCellValue('A' . $p, $site);
                             $objPHPExcel->getActiveSheet()->setCellValue('B' . $p, $minvoice->user);
                             $objPHPExcel->getActiveSheet()->setCellValue('C' . $p, $minvoice->ip);
                             $objPHPExcel->getActiveSheet()->setCellValue('D' . $p, $minvoice->job_title);
                             $objPHPExcel->getActiveSheet()->setCellValue('E' . $p, $minvoice->submit_date);
                             $objPHPExcel->getActiveSheet()->setCellValue('F' . $p, $minvoice->final_date);
                             $objPHPExcel->getActiveSheet()->setCellValue('G' . $p, $minvoice->final_action);
                             $objPHPExcel->getActiveSheet()->setCellValue('H' . $p, $minvoice->final_site);
                             $objPHPExcel->getActiveSheet()->setCellValue('I' . $p, $minvoice->number_of_pages);
                             $objPHPExcel->getActiveSheet()->setCellValue('J' . $p, $cost);
                             $objPHPExcel->getActiveSheet()->setCellValue('K' . $p, $amount);
                             $objPHPExcel->getActiveSheet()->setCellValue('L' . $p, $minvoice->release_ip);
                             $objPHPExcel->getActiveSheet()->setCellValue('M' . $p, $minvoice->release_user);
                             $objPHPExcel->getActiveSheet()->setCellValue('N' . $p, $minvoice->release_method);
                             $objPHPExcel->getActiveSheet()->setCellValue('O' . $p, "N");
                             //
                             $objPHPExcel->getActiveSheet()->setCellValue('P' . $p, $minvoice->print_job_duplex);
                             //duplex
                             $objPHPExcel->getActiveSheet()->setCellValue('Q' . $p, $minvoice->job_paper_size);
                             $objPHPExcel->getActiveSheet()->setCellValue('R' . $p, $minvoice->device_name);
                             $objPHPExcel->getActiveSheet()->setCellValue('S' . $p, $minvoice->device_type);
                             $objPHPExcel->getActiveSheet()->setCellValue('T' . $p, $minvoice->device_host);
                         }
                     }
                 } elseif (strtolower($minvoice->device_type) == "m") {
                     if ($minvoice->job_paper_size == "A3" || ($minvoice->job_paper_size == "Tabloid" || $minvoice->job_paper_size == "Ledger")) {
                         #if device type is a mono and paper is A3
                         if (strtolower($minvoice->device_name) == 'lexmark mx860') {
                             #de we need to be sure its an lexmark mx860de device
                             $cost = Price::where("job_id", 1)->where("job_type", "mono")->where("paper_id", $paperid)->pluck("price");
                             $amount = $cost * $minvoice->number_of_pages;
                             $sumNoPagesA3Mono += $minvoice->number_of_pages;
                             $sumAmountA3Mono += $amount;
                             //not longer neccessory because cumulated pages could be multiplied by the unit cost
                             $unitCostA3Mono = $cost;
                             $objPHPExcel->getActiveSheet()->setCellValue('A' . $p, $site);
                             $objPHPExcel->getActiveSheet()->setCellValue('B' . $p, $minvoice->user);
                             $objPHPExcel->getActiveSheet()->setCellValue('C' . $p, $minvoice->ip);
                             $objPHPExcel->getActiveSheet()->setCellValue('D' . $p, $minvoice->job_title);
                             $objPHPExcel->getActiveSheet()->setCellValue('E' . $p, $minvoice->submit_date);
                             $objPHPExcel->getActiveSheet()->setCellValue('F' . $p, $minvoice->final_date);
                             $objPHPExcel->getActiveSheet()->setCellValue('G' . $p, $minvoice->final_action);
                             $objPHPExcel->getActiveSheet()->setCellValue('H' . $p, $minvoice->final_site);
                             $objPHPExcel->getActiveSheet()->setCellValue('I' . $p, $minvoice->number_of_pages);
                             $objPHPExcel->getActiveSheet()->setCellValue('J' . $p, $cost);
                             $objPHPExcel->getActiveSheet()->setCellValue('K' . $p, $amount);
                             $objPHPExcel->getActiveSheet()->setCellValue('L' . $p, $minvoice->release_ip);
                             $objPHPExcel->getActiveSheet()->setCellValue('M' . $p, $minvoice->release_user);
                             $objPHPExcel->getActiveSheet()->setCellValue('N' . $p, $minvoice->release_method);
                             $objPHPExcel->getActiveSheet()->setCellValue('O' . $p, "N");
                             //
                             $objPHPExcel->getActiveSheet()->setCellValue('P' . $p, $minvoice->print_job_duplex);
                             //duplex
                             $objPHPExcel->getActiveSheet()->setCellValue('Q' . $p, $minvoice->job_paper_size);
                             $objPHPExcel->getActiveSheet()->setCellValue('R' . $p, $minvoice->device_name);
                             $objPHPExcel->getActiveSheet()->setCellValue('S' . $p, $minvoice->device_type);
                             $objPHPExcel->getActiveSheet()->setCellValue('T' . $p, $minvoice->device_host);
                         } elseif (strtolower($minvoice->device_name) == 'lexmark x654de' || strtolower($minvoice->device_name) == 'lexmark x654' || (strtolower($minvoice->device_name) == 'lexmark t656' || strtolower($minvoice->device_name) == 'lexmark t656de')) {
                             # otherwise its an A4 job for mono not A3 as may be indicated in script
                             $paperid = DB::table("papers")->where("name", "A4")->pluck("id");
                             $cost = Price::where("job_id", 1)->where("job_type", "mono")->where("paper_id", $paperid)->pluck("price");
                             $amount = $cost * $minvoice->number_of_pages;
                             $sumNoPagesA4Mono += $minvoice->number_of_pages;
                             $sumAmountA4Mono += $amount;
                             //not longer neccessory because cumulated pages could be multiplied by the unit cost
                             $unitCostA4Mono = $cost;
                             $objPHPExcel->getActiveSheet()->setCellValue('A' . $p, $site);
                             $objPHPExcel->getActiveSheet()->setCellValue('B' . $p, $minvoice->user);
                             $objPHPExcel->getActiveSheet()->setCellValue('C' . $p, $minvoice->ip);
                             $objPHPExcel->getActiveSheet()->setCellValue('D' . $p, $minvoice->job_title);
                             $objPHPExcel->getActiveSheet()->setCellValue('E' . $p, $minvoice->submit_date);
                             $objPHPExcel->getActiveSheet()->setCellValue('F' . $p, $minvoice->final_date);
                             $objPHPExcel->getActiveSheet()->setCellValue('G' . $p, $minvoice->final_action);
                             $objPHPExcel->getActiveSheet()->setCellValue('H' . $p, $minvoice->final_site);
                             $objPHPExcel->getActiveSheet()->setCellValue('I' . $p, $minvoice->number_of_pages);
                             $objPHPExcel->getActiveSheet()->setCellValue('J' . $p, $cost);
                             $objPHPExcel->getActiveSheet()->setCellValue('K' . $p, $amount);
                             $objPHPExcel->getActiveSheet()->setCellValue('L' . $p, $minvoice->release_ip);
                             $objPHPExcel->getActiveSheet()->setCellValue('M' . $p, $minvoice->release_user);
                             $objPHPExcel->getActiveSheet()->setCellValue('N' . $p, $minvoice->release_method);
                             $objPHPExcel->getActiveSheet()->setCellValue('O' . $p, "N");
                             //
                             $objPHPExcel->getActiveSheet()->setCellValue('P' . $p, $minvoice->print_job_duplex);
                             //duplex
                             $objPHPExcel->getActiveSheet()->setCellValue('Q' . $p, "A4");
                             $objPHPExcel->getActiveSheet()->setCellValue('R' . $p, $minvoice->device_name);
                             $objPHPExcel->getActiveSheet()->setCellValue('S' . $p, $minvoice->device_type);
                             $objPHPExcel->getActiveSheet()->setCellValue('T' . $p, $minvoice->device_host);
                         }
                     } else {
                         $cost = Price::where("job_id", 1)->where("job_type", "mono")->where("paper_id", $paperid)->pluck("price");
                         $amount = $cost * $minvoice->number_of_pages;
                         $sumNoPagesA4Mono += $minvoice->number_of_pages;
                         $sumAmountA4Mono += $amount;
                         //not longer neccessory because cumulated pages could be multiplied by the unit cost
                         $unitCostA4Mono = $cost;
                         $objPHPExcel->getActiveSheet()->setCellValue('A' . $p, $site);
                         $objPHPExcel->getActiveSheet()->setCellValue('B' . $p, $minvoice->user);
                         $objPHPExcel->getActiveSheet()->setCellValue('C' . $p, $minvoice->ip);
                         $objPHPExcel->getActiveSheet()->setCellValue('D' . $p, $minvoice->job_title);
                         $objPHPExcel->getActiveSheet()->setCellValue('E' . $p, $minvoice->submit_date);
                         $objPHPExcel->getActiveSheet()->setCellValue('F' . $p, $minvoice->final_date);
                         $objPHPExcel->getActiveSheet()->setCellValue('G' . $p, $minvoice->final_action);
                         $objPHPExcel->getActiveSheet()->setCellValue('H' . $p, $minvoice->final_site);
                         $objPHPExcel->getActiveSheet()->setCellValue('I' . $p, $minvoice->number_of_pages);
                         $objPHPExcel->getActiveSheet()->setCellValue('J' . $p, $cost);
                         $objPHPExcel->getActiveSheet()->setCellValue('K' . $p, $amount);
                         $objPHPExcel->getActiveSheet()->setCellValue('L' . $p, $minvoice->release_ip);
                         $objPHPExcel->getActiveSheet()->setCellValue('M' . $p, $minvoice->release_user);
                         $objPHPExcel->getActiveSheet()->setCellValue('N' . $p, $minvoice->release_method);
                         $objPHPExcel->getActiveSheet()->setCellValue('O' . $p, "N");
                         //
                         $objPHPExcel->getActiveSheet()->setCellValue('P' . $p, $minvoice->print_job_duplex);
                         //duplex
                         $objPHPExcel->getActiveSheet()->setCellValue('Q' . $p, $minvoice->job_paper_size);
                         $objPHPExcel->getActiveSheet()->setCellValue('R' . $p, $minvoice->device_name);
                         $objPHPExcel->getActiveSheet()->setCellValue('S' . $p, $minvoice->device_type);
                         $objPHPExcel->getActiveSheet()->setCellValue('T' . $p, $minvoice->device_host);
                     }
                 }
                 $printNo++;
             }
             $x++;
         }
         //End of invoicing loop
         $b = $p + 5;
         $sumAmountA3Color = $sumNoPagesA3Color * $unitCostA3Color;
         $sumAmountA3Mono = $sumNoPagesA3Mono * $unitCostA3Mono;
         $sumAmountA4Color = $sumNoPagesA4Color * $unitCostA4Color;
         $sumAmountA4Mono = $sumNoPagesA4Mono * $unitCostA4Mono;
         /**
          * Sum total of all net
          * amounts
          */
         $sumTotal += $sumAmountA4Mono;
         $sumTotal += $sumAmountA3Mono;
         $sumTotal += $sumAmountA4Color;
         $sumTotal += $sumAmountA3Color;
         $a3Arr = ["a3mono" => ["nopages" => $sumNoPagesA3Mono, "unitcost" => $unitCostA3Mono, "netamount" => $sumAmountA3Mono], "a3color" => ["nopages" => $sumNoPagesA3Color, "unitcost" => $unitCostA3Color, "netamount" => $sumAmountA3Color]];
         if ($sumNoPagesA3Mono > 0) {
             DB::table("invoice_detail")->insert(['invoice_id' => $bill->id, 'branch_id' => $minvoice->site, 'location' => $site, 'un_identity' => 'A3 Mono', 'description' => "Print / Copy Mono A3", 'no_of_pages' => $sumNoPagesA3Mono, 'cost_per_page' => $unitCostA3Mono, 'paper_size' => "A3", 'amount' => $sumAmountA3Mono, 'created_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s")]);
         }
         if ($sumNoPagesA3Color > 0) {
             DB::table("invoice_detail")->insert(['invoice_id' => $bill->id, 'branch_id' => $minvoice->site, 'location' => $site, 'un_identity' => 'A3 Color', 'description' => "Print / Copy Color A3", 'no_of_pages' => $sumNoPagesA3Color, 'cost_per_page' => $unitCostA3Color, 'paper_size' => "A3", 'amount' => $sumAmountA3Color, 'created_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s")]);
         }
         if ($sumNoPagesA4Mono > 0) {
             DB::table("invoice_detail")->insert(['invoice_id' => $bill->id, 'branch_id' => $minvoice->site, 'location' => $site, 'un_identity' => 'A4 Mono', 'description' => "Print / Copy Mono A4", 'no_of_pages' => $sumNoPagesA4Mono, 'cost_per_page' => $unitCostA4Mono, 'paper_size' => "A4", 'amount' => $sumAmountA4Mono, 'created_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s")]);
         }
         if ($sumNoPagesA4Color > 0) {
             DB::table("invoice_detail")->insert(['invoice_id' => $bill->id, 'branch_id' => $minvoice->site, 'location' => $site, 'un_identity' => 'A4 Color', 'description' => "Print / Copy Color A4", 'no_of_pages' => $sumNoPagesA4Color, 'cost_per_page' => $unitCostA4Color, 'paper_size' => "A4", 'amount' => $sumAmountA4Color, 'created_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s")]);
         }
         $a4Arr = ["a4mono" => ["nopages" => $sumNoPagesA4Mono, "unitcost" => $unitCostA4Mono, "netamount" => $sumAmountA4Mono], "a4color" => ["nopages" => $sumNoPagesA4Color, "unitcost" => $unitCostA4Color, "netamount" => $sumAmountA4Color]];
         array_push($ArrMain, ["site" => $site, "a4" => $a4Arr, "a3" => $a3Arr, "sumTotal" => $sumTotal]);
         $total += $sumTotal;
         $stack->status = 1;
         $stack->update();
     }
     // End of stack loop
     if (isset($input['date_from']) && isset($input['date_to'])) {
         $duration = date_format(date_create($input['date_from']), "d M. Y") . " - " . date_format(date_create($input['date_to']), "d M. Y");
     } else {
         // $duration = date_format($dateFrom ,"d M. Y") ." - ". date_format($dateTo,"d M. Y");
     }
     define('BUDGETS_DIR', public_path() . "/invoicexlxs/");
     // I define this in a constants.php file
     $pdfPath = "";
     if (!is_dir(BUDGETS_DIR)) {
         mkdir(BUDGETS_DIR, 0755, true);
     }
     $fileurl = "RJLEX_" . strtoupper(substr($company->name, 0, 3)) . "_" . date("Y-M-d") . "_" . time();
     $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, "Excel2007");
     $objWriter->save(BUDGETS_DIR . $fileurl . ".xlsx");
     $outputName = $fileurl . ".pdf";
     // str_random is a [Laravel helper](http://laravel.com/docs/helpers#strings)
     $pdfPath = BUDGETS_DIR . $outputName;
     $bill->pdf_url = $outputName;
     // File::put($pdfPath, PDF::loadView($pdf, 'A4', 'portrait')->output());
     $bill->subtotal = $total;
     $bill->tax = 5 / 100 * $total;
     $bill->total = $total + $bill->tax;
     $bill->invoice_date = date("Y-m-d H:i:s");
     $bill->duration = $duration;
     $bill->file_url = $fileurl . ".xlsx";
     $bill->update();
     $input["invoice"] = $bill;
     $invoiceItems = DB::table("invoice_detail")->where("invoice_id", $bill->id)->groupBy("location")->get();
     $input["invoiceItems"] = $invoiceItems;
     //$pdf = new PDF($dompdf, $config, $app['files'], $app['view']);
     $pdf = App::make('dompdf.wrapper');
     //$pdf->set_base_path(public_path()."/bootstrap");->download($outputName)
     $pdf->loadView('invoicing.invoicepdf', $input)->setPaper('a4')->setOrientation('landscape')->save($pdfPath);
     //return $pdf->download($outputName);
     return View("invoicing.invoice", ["companies" => Company::all(), 'invoice' => $bill, "total" => $total, "company" => $company, "branches" => Branch::where("company_id", $company->id)->get(), "invoiceDatum" => $ArrMain, "title" => "Invoice"]);
 }
Exemplo n.º 11
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     if (Carbon::now()->toDateString() == Carbon::now()->startOfMonth()->toDateString()) {
         $users = User::where('type', 'ecole')->get();
         foreach ($users as $user) {
             $sc = SchoolYear::where('user_id', $user->id)->where('current', 1)->first();
             if ($sc->type == 'Semis' && Carbon::now()->between($sc->startch1, $sc->endch2)) {
                 foreach ($user->children as $child) {
                     foreach ($child->bills as $bill) {
                         $getChild = Bill::where('child_id', $bill->child_id)->where('reduction', 0)->where('school_year_id', $sc->id)->where('nbrMois', 1)->orderBy('id', 'desc')->first();
                         if ($getChild) {
                             $facture = new Bill();
                             $facture->start = $getChild->end->toDateString();
                             $facture->end = $getChild->end->addMonth()->toDateString();
                             $facture->status = 0;
                             $facture->user_id = $getChild->user_id;
                             $enfant = Child::where('user_id', $getChild->user_id)->where('id', $getChild->child_id)->first();
                             $taman = '';
                             $transportStatus = $enfant->transport;
                             foreach ($enfant->levels as $level) {
                                 $getPriceOfLevel = PriceBill::where('niveau', $level->id)->where('user_id', $getChild->user_id)->first();
                                 $taman = $getPriceOfLevel->prix;
                             }
                             $transportStatus == 0 ? $facture->somme = $taman : ($facture->somme = $taman + Transport::where('user_id', $getChild->user_id)->first()->somme);
                             $facture->nbrMois = $getChild->nbrMois;
                             $facture->reductionPrix = null;
                             $facture->school_year_id = $getChild->school_year_id;
                             $facture->reduction = 0;
                             $facture->child_id = $getChild->child_id;
                             $facture->f_id = $getChild->f_id;
                             $facture->save();
                             break;
                         }
                     }
                 }
             } elseif ($sc->type == 'Trim' && Carbon::now()->between($sc->startch1, $sc->endch3)) {
                 foreach ($user->children as $child) {
                     foreach ($child->bills as $bill) {
                         $getChild = Bill::where('child_id', $bill->child_id)->where('reduction', 0)->where('school_year_id', $sc->id)->where('nbrMois', 1)->orderBy('id', 'desc')->first();
                         if ($getChild) {
                             $facture = new Bill();
                             $facture->start = $getChild->end->toDateString();
                             $facture->end = $getChild->end->addMonth()->toDateString();
                             $facture->status = 0;
                             $facture->user_id = $getChild->user_id;
                             $enfant = Child::where('user_id', $getChild->user_id)->where('id', $getChild->child_id)->first();
                             $taman = '';
                             $transportStatus = $enfant->transport;
                             foreach ($enfant->levels as $level) {
                                 $getPriceOfLevel = PriceBill::where('niveau', $level->id)->where('user_id', $getChild->user_id)->first();
                                 $taman = $getPriceOfLevel->prix;
                             }
                             $transportStatus == 0 ? $facture->somme = $taman : ($facture->somme = $taman + Transport::where('user_id', $getChild->user_id)->first()->somme);
                             $facture->nbrMois = $getChild->nbrMois;
                             $facture->reductionPrix = null;
                             $facture->school_year_id = $getChild->school_year_id;
                             $facture->reduction = 0;
                             $facture->child_id = $getChild->child_id;
                             $facture->f_id = $getChild->f_id;
                             $facture->save();
                             break;
                         }
                     }
                 }
             }
         }
         /*  $enfants =  Child::has('bills')->get();
                 foreach($enfants as $e)
                 {
                     foreach($e->bills as $b)
                     {
                        $d = Bill::where('child_id',$b->child_id)->orderBy('id','desc')->first();
                        $bill = new Bill();
                         $bill->start =$d->end->toDateString();
                         $nextMonth7 =$d->end->addMonth()->toDateString();
                         if(Carbon::parse($nextMonth7)->month == 7)
                         {
                             $bill->end = Carbon::parse($nextMonth7)->addMonths(2)->toDateString();
                         }else{
                             $bill->end = $nextMonth7;
                         }
                         $bill->status = 0;
                         $bill->user_id = $d->user_id;
                         $bill->somme =  $d->somme;
                         $bill->child_id =$d->child_id;
                         $bill->f_id = $d->f_id;
                         $bill->save();
                         break;
         
         
                     }
                 }*/
     }
 }
Exemplo n.º 12
0
 /**
  * Handle creation of new bill.
  *
  * @param CreateBillRequest $request
  * @return array
  */
 public function create(CreateBillRequest $request)
 {
     // Save request data
     $clientName = $request->get('client');
     $useCurrentCampaign = $request->get('use_current_campaign');
     $campaignYear = $request->get('campaign_year');
     $campaignNumber = $request->get('campaign_number');
     $client = DB::table('clients')->where('name', $clientName)->where('user_id', Auth::user()->id)->first();
     // Create new client if not exists
     if (!$client) {
         $client = new Client();
         $client->user_id = Auth::user()->id;
         $client->name = $clientName;
         $client->save();
     }
     // Create new bill
     $bill = new Bill();
     $bill->client_id = $client->id;
     $bill->user_id = Auth::user()->id;
     $campaign = Campaigns::current();
     // Check if current campaign should be used
     if (!$useCurrentCampaign) {
         $campaign = Campaign::where('year', $campaignYear)->where('number', $campaignNumber)->first();
     }
     $bill->campaign_id = $campaign->id;
     $bill->campaign_order = Campaigns::autoDetermineOrderNumber($campaign, $client->id);
     $bill->save();
     event(new UserCreatedNewBill(Auth::user()->id, $bill->id));
     // Return response
     $response = new AjaxResponse();
     $response->setSuccessMessage(trans('bills.bill_created'));
     return response($response->get());
 }