<?php

namespace App\Listeners\AccountManual;

use App\Events\EditAccountManualEvent;
use App\Models\AcccountingManual;
use App\Models\InstallmentCompanies;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use App\Traits\GeneralTrait;
use App\Models\Journalizing;
use App\Models\SafesBanks;
use App\Models\Stores;
use App\Models\Vendors;
use App\Models\Customers;
use App\Models\Taxes;

class EditAccountManualEventListener
{


     use GeneralTrait;
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  \App\Events\TestEvent  $event
     * @return void
     */
    public function handle(EditAccountManualEvent $event)
    {



         if($event->item->Parent == 28 or $event->item->Parent == 29 ){

             $safe=SafesBanks::where('Account',$event->item->id)->first();

         $dataa['Name']=$event->item->Name;
         $dataa['NameEn']=$event->item->NameEn;
         $dataa['Note']=$event->item->Not;

         SafesBanks::where('id',$safe->id)->update($dataa);

          }


               if($event->item->Parent == 27){

    $safe=Stores::where('Account',$event->item->id)->first();

         $dataa['Name']=$event->item->Name;
         $dataa['NameEn']=$event->item->NameEn;

         Stores::where('id',$safe->id)->update($dataa);

          }

              if($event->item->Parent == 37){

    $safe=Vendors::where('Account',$event->item->id)->first();

         $dataa['Name']=$event->item->Name;
         $dataa['NameEn']=$event->item->NameEn;

         Vendors::where('id',$safe->id)->update($dataa);

          }

          if($event->item->Parent == 24){

    $safe=Customers::where('Account',$event->item->id)->first();

         $dataa['Name']=$event->item->Name;
         $dataa['NameEn']=$event->item->NameEn;

         Customers::where('id',$safe->id)->update($dataa);

          }

          if($event->item->Parent == 97){

    $safe=ShippingCompany::where('Account',$event->item->id)->first();

         $dataa['Name']=$event->item->Name;
         $dataa['NameEn']=$event->item->NameEn;

         ShippingCompany::where('id',$safe->id)->update($dataa);

          }


           if($event->item->Parent == 39){

    $safe=Taxes::where('Account',$event->item->id)->first();

         $dataa['Name']=$event->item->Name;
         $dataa['NameEn']=$event->item->NameEn;

         Taxes::where('id',$safe->id)->update($dataa);

          }


        if($event->item->Parent == 888){


            $safe=InstallmentCompanies::where('Account',$event->item->id)->first();

$dataNakdya['Name']='مصاريف'.' '.$event->item->Name;
$dataNakdya['NameEn']='Expenses'.' '.$event->item->NameEn;
   AcccountingManual::where('id',$safe->NakdyaAccount)->update($dataNakdya);

            $dataInstall['Arabic_Name']=$event->item->Name;
            $dataInstall['English_Name']=$event->item->NameEn;

            InstallmentCompanies::where('id',$safe->id)->update($dataInstall);

        }




    }
}
