Linux localhost 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64
Apache/2.4.41 (Ubuntu)
: 23.92.16.63 | : 162.158.159.99
Cant Read [ /etc/named.conf ]
8.1.5
www-data
www.github.com/MadExploits
Terminal
AUTO ROOT
Adminer
Backdoor Destroyer
Linux Exploit
Lock Shell
Lock File
Create User
CREATE RDP
PHP Mailer
BACKCONNECT
UNLOCK SHELL
HASH IDENTIFIER
CPANEL RESET
CREATE WP USER
README
+ Create Folder
+ Create File
/
var /
www /
crm.oxopackaging.com /
app /
Services /
Front /
[ HOME SHELL ]
Name
Size
Permission
Action
ActivityService.php
1.21
KB
-rw-r--r--
ClientService.php
2.64
KB
-rw-r--r--
CourierService.php
5.78
KB
-rw-r--r--
DealProductService.php
940
B
-rw-r--r--
DealService.php
348.36
KB
-rw-r--r--
EmailPhoneDetailService.php
1.28
KB
-rw-r--r--
FileService.php
1.17
KB
-rw-r--r--
NoteService.php
1.17
KB
-rw-r--r--
PipelineService.php
88.35
KB
-rw-r--r--
PipelineStageService.php
1.59
KB
-rw-r--r--
ProductService.php
1.31
KB
-rw-r--r--
UserService.php
1.32
KB
-rw-r--r--
VendorService.php
3.66
KB
-rw-r--r--
Delete
Unzip
Zip
${this.title}
Close
Code Editor : DealService.php
<?php /** * Created by crm_entity command. * @author : Muhammad Saeed * @todo : Service todo * @since : $2021Aug31 * @description : Service description */ namespace App\Services\Front; use App\Models\Client; use App\Models\ClientsReferalls; use App\Models\Courier; use App\Models\Deal; use App\Models\DealAmount; use App\Models\DealEstimation; use App\Models\DealEstimationlog; use App\Models\DealFollowUp; use App\Models\DealNotification; use App\Models\DealProduct; use App\Models\DealProductQuantityAndEstimationAmount; use App\Models\DealShippingBoxes; use App\Models\DealProductPrinting; use App\Models\Domains; use App\Models\EmailPhoneDetail; use App\Models\File; use App\Models\Modelhasroles; use App\Models\Pipeline; use App\Models\Product; use App\Models\Production; use App\Models\PipelineStage; use App\Models\ProductPrinting; use App\Models\QuantityAndEstimation; use App\Models\Rewards; use App\Models\Setting; use App\Models\ShippingBoxes; use App\Models\State; use App\Models\Tracking; use App\Services\DealService as ParentService; use App\Repositories\DealRepository; use App\Repositories\DealProductRepository; use App\Repositories\NoteRepository; use Carbon\Carbon; use http\Exception; use Illuminate\Foundation\Auth\User; use Illuminate\Support\Facades\Cache; use \Illuminate\Support\Facades\DB; use Illuminate\Support\Str; use Illuminate\Support\Facades\Log; class DealService extends ParentService { /** * @var DealRepository */ protected $repository; /** * @var NoteRepository */ protected $noteRepository; /** * DealRepository constructor. * * @param DealRepository $repository */ public function __construct(DealRepository $repository , NoteRepository $noteRepository,DealProductRepository $dealProductRepository) { $this->noteRepository = $noteRepository; $this->dealProductRepository = $dealProductRepository; parent::__construct($repository, 'Front'); } /** * DealRepository constructor. * * @todo Function todo * @description Function description * @since $2021Aug31 * @param DealRepository $repository */ public function index($request){ $this->repository->setPresenter("App\\Presenters\\Front\\Deal\\ListPresenter"); $this->repository->pushCriteria(app('Prettus\Repository\Criteria\RequestCriteria')); if ($request->has('paginate') && $request->paginate) { return $this->repository->paginate(); } return $this->repository->all(); } public function GetBoxesByCourier($id){ return ShippingBoxes::where('courier_id',$id)->get(); } /*public function Getleads($request) { $cacheKey = 'all_pipeline_leads'; $data = Cache::remember($cacheKey, now()->addHours(1), function () { \App\Models\PipelineStage::with([ 'deals' => function ($query) { $query->with([ 'client', 'lead_source', 'dealProducts', 'dealProducts.product', 'dealProducts.productstyle', 'dealProducts.dealProductQuantityAndEstimationAmounts_sigle' ]) ->where('deal_status', '1') ->where('show_follow_up', '1'); } ]) ->whereIn('id', ['1', '2', '11', '3']) ->orderBy('order_no', 'asc') ->get() ->toArray(); }); // Re-collect into Laravel Collection so you can use `map`, `filter` etc. $data = collect($data); $filtered = $data->map(function ($stage) use ($request) { $stage['deals'] = collect($stage['deals'])->filter(function ($deal) use ($request) { $from = $request->get('from') ?? Carbon::now()->startOfMonth()->toDateString(); $to = $request->get('to') ?? Carbon::now()->endOfMonth()->toDateString(); if ($deal['open_date'] < $from || $deal['open_date'] > $to) { return false; } // Deal name if ($request->has('deal_name')) { $match = false; if (!empty($deal['client']) && str_contains(strtolower($deal['client']['name']), strtolower($request->deal_name))) { $match = true; } elseif (!empty($deal['client']['clientDetails'])) { $match = str_contains(strtolower($deal['client']['clientDetails']['value'] ?? ''), strtolower($request->deal_name)) || str_contains(strtolower($deal['client']['clientDetails']['order_number'] ?? ''), strtolower($request->deal_name)); } if (!$match) return false; } // Filtering logic... if ($request->filled('user_deals') && $deal['owner_id'] != $request->user_deals) return false; if ($request->filled('priority_id') && $deal['priority_id'] != $request->priority_id) return false; if ($request->filled('sale_type') && $deal['sale_type'] != $request->sale_type) return false; if ($request->filled('order_type_id') && $deal['deal_type_id'] != $request->order_type_id) return false; if ($request->filled('domain_id') && $deal['domain_id'] != $request->domain_id) return false; if ($request->filled('clost_reason') && $deal['lead_source_id'] != $request->clost_reason) return false; if (auth()->user()->employee_country_id == 2 && $deal['production_from'] != 2) return false; return true; }); return $stage; }); return $filtered; }*/ public function Getleads($request){ $data = PipelineStage::select('*')->with([ 'deals' => function($que) use ($request) { if ($request->has('deal_name')) { $que->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%') ->orWhereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%') ->orWhere('order_number', 'like', $request->deal_name . '%'); }); }); } if (!empty($request->get('user_deals'))) { $que->where('owner_id', '=', $request->user_deals); } elseif (!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')) { if (auth()->user()->hasRole('Team Lead') || auth()->user()->hasRole('Manager') || auth()->user()->id == 148) { $uid = User::find(auth()->user()->id); $que->whereIn('owner_id', explode(',', $uid->team_member)); } else { $que->where('owner_id', '=', auth()->user()->id); } } if (!empty($request->get('from')) && !empty($request->get('to'))) { $que->whereBetween('open_date', [date($request->from), date($request->to)]); } else { $timezone = 'America/New_York'; $first = Carbon::now($timezone)->startOfMonth()->toDateString(); $last = Carbon::now($timezone)->endOfMonth()->toDateString(); $que->whereBetween('open_date', [$first, $last]); } if (!empty($request->get('priority_id'))) { $que->where('priority_id', '=', $request->priority_id); } if (!empty($request->get('sale_type'))) { $que->where('sale_type', '=', $request->sale_type); } if (!empty($request->get('order_type_id'))) { $que->where('deal_type_id', '=', $request->order_type_id); } if (!empty($request->get('domain_id'))) { $que->where('domain_id', '=', $request->domain_id); } if (auth()->user()->employee_country_id == 2) { $que->where('production_from', '=', auth()->user()->employee_country_id); } if(!empty($request->get('clost_reason') )) { $que->where('lead_source_id' ,'=', $request->clost_reason ); } $que->where('deal_status', '=', '1')->where('show_follow_up', '=', '1'); if (!empty($request->get('order_by'))) { $que->orderBy('est_amount', $request->order_by); } else { $que->orderBy('order_no', 'desc'); } }, 'deals.client', 'deals.lead_source', 'deals.dealProducts', 'deals.dealProducts.product', 'deals.dealProducts.productstyle', 'deals.dealProducts.dealProductQuantityAndEstimationAmounts_sigle' // Load the required relation here ])->whereIn('id', ['1', '2', '11', '3'])->orderBy('order_no', 'asc')->get(); return $data; } /*public function Getleads($request){ $data = PipelineStage::select('*')->with(['deals' => function($que) use ($request){ if($request->has('deal_name') ) { $que->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number' ,'like', $request->deal_name.'%'); }); }); }); }); } if(!empty($request->get('user_deals') )) { $que->where('owner_id', '=', $request->user_deals); }else if( !auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin') ) { if(auth()->user()->hasRole('Team Lead') || auth()->user()->hasRole('Manager')){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }elseif( auth()->user()->id==148 ){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }else { $que->where('owner_id', '=', auth()->user()->id); } }else{ if(auth()->user()->hasRole('Team Lead') && auth()->user()->hasRole('Manager')){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }else{ } } if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('open_date', [date($request->from) , date($request->to)]); }else{ $timezone = 'America/New_York'; // Replace with desired U.S. timezone // Get the first and last days of the current month in the specified timezone $first = Carbon::now($timezone)->startOfMonth()->toDateString(); $last = Carbon::now($timezone)->endOfMonth()->toDateString(); $que->whereBetween('open_date', [date($first) , date($last)]); } if(!empty($request->get('priority_id') )) { $que->where('priority_id' ,'=', $request->priority_id); } if(!empty($request->get('sale_type') )) { $que->where('sale_type' ,'=', $request->sale_type); } if(!empty($request->get('order_type_id') )) { $que->where('deal_type_id' ,'=', $request->order_type_id); } if(!empty($request->get('domain_id') )) { $que->where('domain_id' ,'=', $request->domain_id); } if(auth()->user()->employee_country_id==2){ $que->where('production_from' ,'=',auth()->user()->employee_country_id); } $que->where('deal_status','=','1'); $que->where('show_follow_up','=','1'); if(!empty($request->get('order_by') )) { $que->orderBy('est_amount', $request->order_by); }else{ $que->orderBy('order_no', 'desc'); } },'deals.client','deals.lead_source','deals.dealProducts','dealProducts.product','dealProducts.productstyle'])->whereIn('id',array('1','2','11','3'))->orderBy('order_no','asc')->get(); return $data; }*/ public function GetIncompleteleads($request){ $data = PipelineStage::select('*')->with(['deals' => function($que) use ($request){ if($request->has('deal_name') ) { $que->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number' ,'like', $request->deal_name.'%'); }); }); }); }); }if(!empty($request->get('user_deals') )) { $que->where('owner_id' ,'=', $request->user_deals); }else{ if(auth()->user()->id!=1 && auth()->user()->id!=121 && auth()->user()->id!=63 && auth()->user()->id!=207 && auth()->user()->id!=276 && auth()->user()->id!=188 && auth()->user()->id!=106 && auth()->user()->id!=94) { $que->where('owner_id', '=', auth()->user()->id); } } if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('open_date', [date($request->from) , date($request->to)]); }else{ $first =date("Y-m-d", strtotime("1-02-2017"));; $last = date("Y-m-d", strtotime("last day of this month")); $que->whereBetween('open_date', [date($first) , date($last)]); } $que->where('deal_status','=','1'); },'deals.client','deals.dealProducts','dealProducts.product','dealProducts.productstyle'])->whereIn('id',array('6','12'))->orderBy('order_no','asc')->get(); return $data; } public function GetTeamMember(){ $uid = User::where('id',auth()->user()->id)->first(); return User::whereIn('id',explode(',',$uid->team_member))->orderBy('first_name','asc')->get(); } public function GetSalesUsers(){ return User::where('agent','=','1')->get(); } public function GetWonleads($request){ $data = PipelineStage::select('*')->with(['deals' => function($que) use ($request){ if($request->has('deal_name') ) { $que->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number' ,'like', $request->deal_name.'%'); }); }); }); }); } if(!empty($request->get('user_deals') )) { $que->where('owner_id', '=', $request->user_deals); }else if( !auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin') ) { if(auth()->user()->hasRole('Team Lead') || auth()->user()->hasRole('Manager')){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }elseif( auth()->user()->id==148 ){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }else { $que->where('owner_id', '=', auth()->user()->id); } }else{ if(auth()->user()->hasRole('Team Lead') && auth()->user()->hasRole('Manager')){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }else{ } } if(!empty($request->get('from') && $request->get('to'))) { $que->whereHas('deal_amount', function ($queryu) use ($request) { $queryu->whereBetween('receiving_date', [date($request->from) , date($request->to)]); }); }else{ $que->whereHas('deal_amount', function ($queryu) use ($request) { // $first =date("Y-m-d", strtotime("first day of this month")); // $last = date("Y-m-d", strtotime("last day of this month")); $timezone = 'America/New_York'; // Replace with desired U.S. timezone // Get the first and last days of the current month in the specified timezone $first = Carbon::now($timezone)->startOfMonth()->toDateString(); $last = Carbon::now($timezone)->endOfMonth()->toDateString(); $queryu->whereBetween('receiving_date', [date($first) , date($last)]); }); } if(!empty($request->get('priority_id') )) { $que->where('priority_id' ,'=', $request->priority_id); } if(!empty($request->get('sale_type') )) { $que->where('sale_type' ,'=', $request->sale_type); } if(!empty($request->get('order_type_id') )) { $que->where('deal_type_id' ,'=', $request->order_type_id); } if(!empty($request->get('domain_id') )) { $que->where('domain_id' ,'=', $request->domain_id); } if(!empty($request->get('clost_reason') )) { $que->where('lead_source_id' ,'=', $request->clost_reason ); } $que->where('deal_status','=','1'); },'deals.client','deals.deal_amount'=> function($que) use ($request){ if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('receiving_date', [date($request->from), date($request->to)]); }else{ $first =date("Y-m-d", strtotime("first day of this month"));; $last = date("Y-m-d", strtotime("last day of this month")); $que->whereBetween('receiving_date', [date($first) , date($last)]); } },'deals.dealProducts','dealProducts.product','dealProducts.productstyle'])->whereIn('id',array('4'))->orderBy('order_no','asc')->get(); return $data; } /*public function GetEstimationpenddingleads($request) { $vendors = \App\Models\User::select('*')->with([ 'estimator_deals' => function ($que) use ($request) { if ($request->has('deal_name')) { $que->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number', 'like', $request->deal_name . '%') ->orWhere('bd_order_number', 'like', $request->deal_name . '%'); }); }); }); }); } if (!empty($request->get('user_deals'))) { $que->where('owner_id', '=', $request->user_deals); } if (auth()->user()->employee_country_id == 2) { $que->where('production_from', '=', auth()->user()->employee_country_id); } if (!empty($request->get('from') && $request->get('to'))) { $f = $request['from']; $t = $request['to']; $que->where(function ($q) use ($f, $t) { $q->where(function ($qs) use ($f, $t) { $qs->where('bd_open_date', '>=', $f)->where('bd_open_date', '<=', $t); })->orWhereBetween('open_date', [$f, $t]); }); } else { $first = date("Y-m-d", strtotime("first day of this month")); $last = date("Y-m-d", strtotime("last day of this month")); $que->where(function ($q) use ($first, $last) { $q->where(function ($qs) use ($first, $last) { $qs->where('bd_open_date', '>=', $first) ->where('bd_open_date', '<=', $last); })->orWhereBetween('open_date', [$first, $last]); }); } }, 'estimator_deals.client', 'estimator_deals.dealProducts', 'estimator_deals.dealProducts.product', 'estimator_deals.dealProducts.productstyle', 'estimator_deals.dealProducts.quantityAndEstimation' ]) ->where('agent', '2') ->where('status', 'active') ->get(); return $vendors; }*/ /*$data = USER::select('*')->with(['deals','client','dealProducts','template_designer','print_ready_designer','dealProducts.product','dealProducts.productstyle','estimator'])->where('agent',2)->orderBy('id','desc'); if($request->has('deal_name') ) { $data->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number' ,'like', $request->deal_name.'%')->orWhere(function ($ques) use ($request) { $ques->where('bd_order_number' ,'like', $request->deal_name.'%'); }); }); }); }); }); } if(!empty($request->get('user_deals') )) { $data->where('owner_id', '=', $request->user_deals); }else if(!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')) { $data->whereIn('domain_id', explode(',',auth()->user()->domains_id)); } if(auth()->user()->employee_country_id==2){ $data->where('production_from' ,'=',auth()->user()->employee_country_id); } if(!empty($request->get('from') && $request->get('to'))) { $f = $request['from']; $t = $request['to']; $data->where(function ($q) use ($f, $t) { $q->where(function ($qs) use ($f, $t) { $qs->where('bd_open_date', '>=', date($f)) ->where('bd_open_date', '<=', date($t)); // Assuming February 2024 for the example })->orWhereBetween('open_date', [date($f), date($t)]); }); }else{ $first =date("Y-m-d", strtotime("first day of this month")); $last = date("Y-m-d", strtotime("last day of this month")); $data->where(function ($q){ $first =date("Y-m-d", strtotime("first day of this month")); $last = date("Y-m-d", strtotime("last day of this month")); $q->where(function ($qs){ $first =date("Y-m-d", strtotime("first day of this month")); $last = date("Y-m-d", strtotime("last day of this month")); $qs->where('bd_open_date', '>=', $first) ->where('bd_open_date', '<=', $last); // Assuming February 2024 for the example })->orWhereBetween('open_date', [$first, $last]); }); } if(!empty($request->get('priority_id') )) { $data->where('priority_id' ,'=', $request->priority_id); } if(!empty($request->get('sale_type') )) { $data->where('sale_type' ,'=', $request->sale_type); } if(!empty($request->get('order_type_id') )) { $data->where('deal_type_id' ,'=', $request->order_type_id); } if(!empty($request->get('domain_id') )) { $data->where('domain_id' ,'=', $request->domain_id); } $data->where('deal_status','=','1'); // $data->where('show_follow_up','=','1'); $data->where('estimation','=','2'); return $data->get(); }*/ public function GetEstimationpenddingleads($request){ $data = Deal::select('*')->with(['deals','client','dealProducts','template_designer','print_ready_designer','dealProducts.product','dealProducts.productstyle','estimator'])->orderBy('id','desc'); if($request->has('deal_name') ) { $data->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number' ,'like', $request->deal_name.'%')->orWhere(function ($ques) use ($request) { $ques->where('bd_order_number' ,'like', $request->deal_name.'%'); }); }); }); }); }); } if(!empty($request->get('user_deals') )) { $data->where('owner_id', '=', $request->user_deals); }else if(!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')) { if(auth()->user()->hasRole('Team Lead')&& auth()->user()->hasRole('Manager')){ $uid = User::where('id',auth()->user()->id)->first(); $data->whereIn('owner_id', explode(',',$uid->team_member)); }else if(auth()->user()->id==148 ){ $uid = User::where('id',auth()->user()->id)->first(); $data->whereIn('owner_id', explode(',',$uid->team_member)); }else if(auth()->user()->hasRole('Estimation')) { $data->where('estimator_id' ,'=', auth()->user()->id); }else { $data->where('owner_id', '=', auth()->user()->id); } } if (!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')&& !auth()->user()->hasRole('Manager')) { $data->where('production_from', auth()->user()->employee_country_id); } if(!empty($request->get('from') && $request->get('to'))) { $f = $request['from']; $t = $request['to']; $data->where(function ($q) use ($f, $t) { $q->where(function ($qs) use ($f, $t) { $qs->where('bd_open_date', '>=', date($f)) ->where('bd_open_date', '<=', date($t)); // Assuming February 2024 for the example })->orWhereBetween('open_date', [date($f), date($t)]); }); }else{ $first =date("Y-m-d", strtotime("first day of this month")); $last = date("Y-m-d", strtotime("last day of this month")); $data->where(function ($q){ $first =date("Y-m-d", strtotime("first day of this month")); $last = date("Y-m-d", strtotime("last day of this month")); $q->where(function ($qs){ $first =date("Y-m-d", strtotime("first day of this month")); $last = date("Y-m-d", strtotime("last day of this month")); $qs->where('bd_open_date', '>=', $first) ->where('bd_open_date', '<=', $last); // Assuming February 2024 for the example })->orWhereBetween('open_date', [$first, $last]); }); } if(!empty($request->get('priority_id') )) { $data->where('priority_id' ,'=', $request->priority_id); } if(!empty($request->get('sale_type') )) { $data->where('sale_type' ,'=', $request->sale_type); } if(!empty($request->get('order_type_id') )) { $data->where('deal_type_id' ,'=', $request->order_type_id); } if(!empty($request->get('domain_id') )) { $data->where('domain_id' ,'=', $request->domain_id); } $data->where('deal_status','=','1'); // $data->where('show_follow_up','=','1'); $data->where('estimation','=','2'); return $data->get(); } public function updateEstimator($request,$id){ Deal::where('id', $id)->update(['estimator_id' =>$request['vid']]); return Deal::where('id',1)->first(); } /*public function GetEstimationleads($request) { $query = Deal::with([ 'deals', 'client.clientDetails', 'dealProducts.product', 'dealProducts.productstyle', 'template_designer', 'print_ready_designer', 'estimator', 'owners', 'bdowners' ])->where('deal_status', 1) ->where('estimation', 1) ->orderByDesc('id'); // Filter by deal_name (search by client name or details) if ($request->filled('deal_name')) { $dealName = $request->deal_name; $query->where(function ($q) use ($dealName) { $q->whereHas('client', function ($q2) use ($dealName) { $q2->where('name', 'like', $dealName . '%') ->orWhereHas('clientDetails', function ($q3) use ($dealName) { $q3->where('value', 'like', $dealName . '%'); }); })->orWhere('order_number', 'like', $dealName . '%') ->orWhere('bd_order_number', 'like', $dealName . '%'); }); } // Filter by owner if ($request->filled('user_deals')) { $query->where('owner_id', $request->user_deals); } elseif (!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')) { $query->whereIn('domain_id', explode(',', auth()->user()->domains_id)); } // Filter by production country if (auth()->user()->employee_country_id == 2) { $query->where('production_from', auth()->user()->employee_country_id); } // Date filter if ($request->filled('from') && $request->filled('to')) { $from = date('Y-m-d', strtotime($request->from)); $to = date('Y-m-d', strtotime($request->to)); $query->where(function ($q) use ($from, $to) { $q->whereBetween('bd_open_date', [$from, $to]) ->orWhereBetween('open_date', [$from, $to]); }); } else { $first = date('Y-m-d', strtotime('first day of this month')); $last = date('Y-m-d', strtotime('last day of this month')); $query->where(function ($q) use ($first, $last) { $q->whereBetween('bd_open_date', [$first, $last]) ->orWhereBetween('open_date', [$first, $last]); }); } // Additional filters if ($request->filled('priority_id')) { $query->where('priority_id', $request->priority_id); } if ($request->filled('sale_type')) { $query->where('sale_type', $request->sale_type); } if ($request->filled('order_type_id')) { $query->where('deal_type_id', $request->order_type_id); } return $query->get(); }*/ public function GetEstimationleadscopy($request) { // DATE RANGE $from = $request->get('from') ?? \Carbon\Carbon::now()->startOfMonth()->toDateString(); $to = $request->get('to') ?? \Carbon\Carbon::now()->endOfMonth()->toDateString(); // QUERY $query = \App\Models\Deal::query() ->with([ 'client', 'dealProducts.dealProductQuantityAndEstimationAmounts_sigle', 'estimator' ]) ->where('deal_status', 1) ->where('estimation', 1) ->whereBetween('open_date', [$from, $to]) ->orderBy('id', 'desc'); // USER FILTER if ($request->filled('user_deals')) { $query->where('owner_id', $request->user_deals); } elseif (!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')) { if (auth()->user()->hasRole('Team Lead') || auth()->user()->hasRole('Manager') || auth()->user()->id == 148) { $uid = auth()->user(); $teamIds = explode(',', $uid->team_member ?? ''); $query->whereIn('owner_id', $teamIds); } elseif (auth()->user()->hasRole('Estimation')) { // $query->where('estimator_id', auth()->user()->id); } else { $query->where('owner_id', auth()->user()->id); } } // COUNTRY FILTER if (!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin') && !auth()->user()->hasRole('Manager')) { $query->where('production_from', auth()->user()->employee_country_id); } // OTHER FILTERS if ($request->filled('priority_id')) { $query->where('priority_id', $request->priority_id); } if ($request->filled('sale_type')) { $query->where('sale_type', $request->sale_type); } if ($request->filled('order_type_id')) { $query->where('deal_type_id', $request->order_type_id); } if ($request->filled('domain_id')) { $query->where('domain_id', $request->domain_id); } // DEAL NAME SEARCH if ($request->filled('deal_name')) { $name = $request->deal_name; $query->where(function ($q) use ($name) { $q->whereHas('client', function ($qc) use ($name) { $qc->where('name', 'like', "{$name}%") ->orWhereHas('clientDetails', fn($qd) => $qd->where('value', 'like', "{$name}%")); }) ->orWhere('order_number', 'like', "{$name}%") ->orWhere('bd_order_number', 'like', "{$name}%"); }); } // FETCH DEALS $deals = $query->get(); // CALCULATE TOTAL ESTIMATION $totalEstimation = 0; foreach ($deals as $deal) { $dealProduct = $deal->dealProducts->first(); $est = $dealProduct?->dealProductQuantityAndEstimationAmounts_sigle; $totalEstimation += $est?->deal_product_est_amount ?? 0; } // RETURN RESULT return [ 'total_pending_deals' => $deals->count(), 'total_estimation_amount' => $totalEstimation, // 'deals' => $deals, // optional ]; } public function GetEstimationpenddingleadscopy($request) { // DATE RANGE $from = $request->get('from') ?? \Carbon\Carbon::now()->startOfMonth()->toDateString(); $to = $request->get('to') ?? \Carbon\Carbon::now()->endOfMonth()->toDateString(); // QUERY $query = \App\Models\Deal::query() ->with([ 'client', 'dealProducts.dealProductQuantityAndEstimationAmounts_sigle', 'estimator' ]) ->where('deal_status', 1) ->where('estimation', 2) ->whereBetween('open_date', [$from, $to]) ->orderBy('id', 'desc'); // USER FILTER if ($request->filled('user_deals')) { $query->where('owner_id', $request->user_deals); } elseif (!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')) { if (auth()->user()->hasRole('Team Lead') || auth()->user()->hasRole('Manager') || auth()->user()->id == 148) { $uid = auth()->user(); $teamIds = explode(',', $uid->team_member ?? ''); $query->whereIn('owner_id', $teamIds); } elseif (auth()->user()->hasRole('Estimation')) { // $query->where('estimator_id', auth()->user()->id); } else { $query->where('owner_id', auth()->user()->id); } } // COUNTRY FILTER if (!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin') && !auth()->user()->hasRole('Manager')) { $query->where('production_from', auth()->user()->employee_country_id); } // OTHER FILTERS if ($request->filled('priority_id')) { $query->where('priority_id', $request->priority_id); } if ($request->filled('sale_type')) { $query->where('sale_type', $request->sale_type); } if ($request->filled('order_type_id')) { $query->where('deal_type_id', $request->order_type_id); } if ($request->filled('domain_id')) { $query->where('domain_id', $request->domain_id); } // DEAL NAME SEARCH if ($request->filled('deal_name')) { $name = $request->deal_name; $query->where(function ($q) use ($name) { $q->whereHas('client', function ($qc) use ($name) { $qc->where('name', 'like', "{$name}%") ->orWhereHas('clientDetails', fn($qd) => $qd->where('value', 'like', "{$name}%")); }) ->orWhere('order_number', 'like', "{$name}%") ->orWhere('bd_order_number', 'like', "{$name}%"); }); } // FETCH DEALS $deals = $query->get(); // CALCULATE TOTAL ESTIMATION $totalEstimation = 0; foreach ($deals as $deal) { $dealProduct = $deal->dealProducts->first(); $est = $dealProduct?->dealProductQuantityAndEstimationAmounts_sigle; $totalEstimation += $est?->deal_product_est_amount ?? 0; } // RETURN RESULT return [ 'total_pending_deals' => $deals->count(), 'total_estimation_amount' => $totalEstimation, // 'deals' => $deals, // optional ]; } public function GetEstimationCompletecopy($request) { // DATE RANGE $from = $request->get('from') ?? \Carbon\Carbon::now()->startOfMonth()->toDateString(); $to = $request->get('to') ?? \Carbon\Carbon::now()->endOfMonth()->toDateString(); // QUERY $query = \App\Models\Deal::query() ->with([ 'client', 'dealProducts.dealProductQuantityAndEstimationAmounts_sigle', 'estimator' ]) ->where('deal_status', 1) ->where('estimation', 3) ->whereBetween('open_date', [$from, $to]) ->orderBy('id', 'desc'); // USER FILTER if ($request->filled('user_deals')) { $query->where('owner_id', $request->user_deals); } elseif (!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')) { if (auth()->user()->hasRole('Team Lead') || auth()->user()->hasRole('Manager') || auth()->user()->id == 148) { $uid = auth()->user(); $teamIds = explode(',', $uid->team_member ?? ''); $query->whereIn('owner_id', $teamIds); } elseif (auth()->user()->hasRole('Estimation')) { // $query->where('estimator_id', auth()->user()->id); } else { $query->where('owner_id', auth()->user()->id); } } // COUNTRY FILTER if (!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin') && !auth()->user()->hasRole('Manager')) { $query->where('production_from', auth()->user()->employee_country_id); } // OTHER FILTERS if ($request->filled('priority_id')) { $query->where('priority_id', $request->priority_id); } if ($request->filled('sale_type')) { $query->where('sale_type', $request->sale_type); } if ($request->filled('order_type_id')) { $query->where('deal_type_id', $request->order_type_id); } if ($request->filled('domain_id')) { $query->where('domain_id', $request->domain_id); } // DEAL NAME SEARCH if ($request->filled('deal_name')) { $name = $request->deal_name; $query->where(function ($q) use ($name) { $q->whereHas('client', function ($qc) use ($name) { $qc->where('name', 'like', "{$name}%") ->orWhereHas('clientDetails', fn($qd) => $qd->where('value', 'like', "{$name}%")); }) ->orWhere('order_number', 'like', "{$name}%") ->orWhere('bd_order_number', 'like', "{$name}%"); }); } // FETCH DEALS $deals = $query->get(); // CALCULATE TOTAL ESTIMATION $totalEstimation = 0; foreach ($deals as $deal) { $dealProduct = $deal->dealProducts->first(); $est = $dealProduct?->dealProductQuantityAndEstimationAmounts_sigle; $totalEstimation += $est?->deal_product_est_amount ?? 0; } // RETURN RESULT return [ 'total_pending_deals' => $deals->count(), 'total_estimation_amount' => $totalEstimation, // 'deals' => $deals, // optional ]; } public function GetEstimationLeads($request) { $data = Deal::with([ 'client', 'estimator', 'owner', 'bdowners', 'dealProducts.product', 'dealProducts.productstyle', 'dealProducts.quantityAndEstimations', ]) ->where('deal_status', 1) ->where('estimation', 1) ->orderBy('id', 'desc'); // Apply filters based on the request if($request->has('deal_name') ) { $data->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number' ,'like', $request->deal_name.'%')->orWhere(function ($ques) use ($request) { $ques->where('bd_order_number' ,'like', $request->deal_name.'%'); }); }); }); }); }); } if ($request->filled('user_deals')) { $data->where('owner_id', $request->user_deals); } elseif (!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')) { $data->whereIn('domain_id', explode(',', auth()->user()->domains_id)); } if (!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')&& !auth()->user()->hasRole('Manager')) { $data->where('production_from', auth()->user()->employee_country_id); } if (!empty($request->get('from')) && !empty($request->get('to'))) { $from = $request->get('from'); $to = $request->get('to'); $data->whereBetween('open_date', [$from, $to]); } else { $first = date("Y-m-01"); $last = date("Y-m-t"); $data->whereBetween('open_date', [$first, $last]); } if (!empty($request->get('priority_id'))) { $data->where('priority_id', $request->priority_id); } if (!empty($request->get('sale_type'))) { $data->where('sale_type', $request->sale_type); } if (!empty($request->get('order_type_id'))) { $data->where('deal_type_id', $request->order_type_id); } return $data->get(); } public function Getquotation($request){ $data = PipelineStage::select('*')->with(['deals' => function($que) use ($request){ if($request->has('deal_name') ) { $que->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number' ,'like', $request->deal_name.'%'); }); }); }); }); } if(!empty($request->get('user_deals') )) { $que->where('owner_id', '=', $request->user_deals); }else if(auth()->user()->id!=1 && auth()->user()->id!=123 && auth()->user()->id!=139 && auth()->user()->id!=121 && auth()->user()->id!=63 && auth()->user()->id!=276 && auth()->user()->id!=207 && auth()->user()->id!=188 && auth()->user()->id!=106 && auth()->user()->id!=148 && auth()->user()->id!=107 && auth()->user()->id!=108 && auth()->user()->id!=109 && auth()->user()->id!=90 && auth()->user()->id!=94) { if(auth()->user()->hasRole('Team Lead')){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }else{ $que->where('owner_id', '=', auth()->user()->id); } }else{ if(auth()->user()->hasRole('Team Lead')){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }else{ } } if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('open_date', [date($request->from) , date($request->to)]); }else{ $first =date("Y-m-d", strtotime("first day of this month")); $last = date("Y-m-d", strtotime("last day of this month")); $que->whereBetween('open_date', [date($first) , date($last)]); } if(!empty($request->get('priority_id') )) { $que->where('priority_id' ,'=', $request->priority_id); } if(!empty($request->get('sale_type') )) { $que->where('sale_type' ,'=', $request->sale_type); } if(!empty($request->get('order_type_id') )) { $que->where('deal_type_id' ,'=', $request->order_type_id); } if(!empty($request->get('domain_id') )) { $que->where('domain_id' ,'=', $request->domain_id); } $que->where('deal_status','=','1'); $que->where('show_follow_up','=','1'); $que->where('quotation','=','2'); },'deals.client','deals.dealProducts','dealProducts.product','dealProducts.productstyle'])->whereIn('id',array('1'))->orderBy('order_no','asc')->get(); return $data; } public function GetEstimationComplete($request){ $data = Deal::select('*')->with(['deals','client','estimator','dealProducts','template_designer','print_ready_designer','dealProducts.product','dealProducts.productstyle'])->orderBy('id','desc'); if($request->has('deal_name') ) { $data->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number' ,'like', $request->deal_name.'%')->orWhere(function ($ques) use ($request) { $ques->where('bd_order_number' ,'like', $request->deal_name.'%'); }); }); }); }); }); } if(!empty($request->get('user_deals') )) { $data->where('owner_id', '=', $request->user_deals); }else if(!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')) { if(auth()->user()->hasRole('Team Lead') && auth()->user()->hasRole('Manager')){ $uid = User::where('id',auth()->user()->id)->first(); $data->whereIn('owner_id', explode(',',$uid->team_member)); }else if(auth()->user()->id==148 ){ $uid = User::where('id',auth()->user()->id)->first(); $data->whereIn('owner_id', explode(',',$uid->team_member)); }else if(auth()->user()->hasRole('Estimation')) { $data->where('estimator_id' ,'=', auth()->user()->id); }else { $data->where('owner_id', '=', auth()->user()->id); } } if (!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')&& !auth()->user()->hasRole('Manager')) { $data->where('production_from', auth()->user()->employee_country_id); } if(!empty($request->get('from') && $request->get('to'))) { $f = $request['from']; $t = $request['to']; $data->where(function ($q) use ($f, $t) { $q->where(function ($qs) use ($f, $t) { $qs->where('bd_open_date', '>=', date($f)) ->where('bd_open_date', '<=', date($t)); // Assuming February 2024 for the example })->orWhereBetween('open_date', [date($f), date($t)]); }); }else{ $first =date("Y-m-d", strtotime("first day of this month")); $last = date("Y-m-d", strtotime("last day of this month")); $data->where(function ($q){ $first =date("Y-m-d", strtotime("first day of this month")); $last = date("Y-m-d", strtotime("last day of this month")); $q->where(function ($qs){ $first =date("Y-m-d", strtotime("first day of this month")); $last = date("Y-m-d", strtotime("last day of this month")); $qs->where('bd_open_date', '>=', $first) ->where('bd_open_date', '<=', $last); // Assuming February 2024 for the example })->orWhereBetween('open_date', [$first, $last]); }); } if(!empty($request->get('priority_id') )) { $data->where('priority_id' ,'=', $request->priority_id); } if(!empty($request->get('sale_type') )) { $data->where('sale_type' ,'=', $request->sale_type); } if(!empty($request->get('order_type_id') )) { $data->where('deal_type_id' ,'=', $request->order_type_id); } if(!empty($request->get('domain_id') )) { $data->where('domain_id' ,'=', $request->domain_id); } $data->where('deal_status','=','1'); // $data->where('show_follow_up','=','1'); $data->where('estimation','=','3'); return $data->get(); } /* public function GetEstimationComplete($request){ $query = Deal::with([ 'deals', 'client.clientDetails', 'dealProducts.product', 'dealProducts.productstyle', 'template_designer', 'print_ready_designer', 'estimator', 'owners', 'bdowners' ])->where('deal_status', 1) ->where('estimation', 3) ->orderByDesc('id'); // Filter by deal_name (search by client name or details) if ($request->filled('deal_name')) { $dealName = $request->deal_name; $query->where(function ($q) use ($dealName) { $q->whereHas('client', function ($q2) use ($dealName) { $q2->where('name', 'like', $dealName . '%') ->orWhereHas('clientDetails', function ($q3) use ($dealName) { $q3->where('value', 'like', $dealName . '%'); }); })->orWhere('order_number', 'like', $dealName . '%') ->orWhere('bd_order_number', 'like', $dealName . '%'); }); } // Filter by owner if ($request->filled('user_deals')) { $query->where('owner_id', $request->user_deals); } elseif (!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')) { $query->whereIn('domain_id', explode(',', auth()->user()->domains_id)); } // Filter by production country if (auth()->user()->employee_country_id == 2) { $query->where('production_from', auth()->user()->employee_country_id); } // Date filter if ($request->filled('from') && $request->filled('to')) { $from = date('Y-m-d', strtotime($request->from)); $to = date('Y-m-d', strtotime($request->to)); $query->where(function ($q) use ($from, $to) { $q->whereBetween('bd_open_date', [$from, $to]) ->orWhereBetween('open_date', [$from, $to]); }); } else { $first = date('Y-m-d', strtotime('first day of this month')); $last = date('Y-m-d', strtotime('last day of this month')); $query->where(function ($q) use ($first, $last) { $q->whereBetween('bd_open_date', [$first, $last]) ->orWhereBetween('open_date', [$first, $last]); }); } // Additional filters if ($request->filled('priority_id')) { $query->where('priority_id', $request->priority_id); } if ($request->filled('sale_type')) { $query->where('sale_type', $request->sale_type); } if ($request->filled('order_type_id')) { $query->where('deal_type_id', $request->order_type_id); } return $query->get(); }*/ public function GetLostleads($request){ $data = PipelineStage::select('*')->with(['deals' => function($que) use ($request){ if($request->has('deal_name') ) { $que->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number' ,'like', $request->deal_name.'%'); }); }); }); }); }if(!empty($request->get('user_deals') )) { $que->where('owner_id', '=', $request->user_deals); }else if( !auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin') ) { if(auth()->user()->hasRole('Team Lead') || auth()->user()->hasRole('Manager')){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }elseif( auth()->user()->id==148 ){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }else { $que->where('owner_id', '=', auth()->user()->id); } }else{ if(auth()->user()->hasRole('Team Lead')){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }else{ } } if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('close_date', [date($request->from) , date($request->to)]); }else{ $first =date("Y-m-d", strtotime("first day of this month")); $last = date("Y-m-d", strtotime("last day of this month")); $que->whereBetween('close_date', [date($first) , date($last)]); } if(!empty($request->get('sale_type') )) { $que->where('sale_type' ,'=', $request->sale_type); } if(!empty($request->get('clost_reason') )) { $que->where('lead_source_id' ,'=', $request->clost_reason ); } if(!empty($request->get('priority_id') )) { $que->where('priority_id' ,'=', $request->priority_id); } if(!empty($request->get('order_type_id') )) { $que->where('deal_type_id' ,'=', $request->order_type_id); } if(!empty($request->get('domain_id') )) { $que->where('domain_id' ,'=', $request->domain_id); } if(auth()->user()->employee_country_id==2){ $que->where('production_from' ,'=',auth()->user()->employee_country_id); } $que->where('deal_status','=','1'); $que->where('show_follow_up','=','1'); $que->where('lost_reason','=','9'); },'deals.client','deals.dealProducts','dealProducts.product','dealProducts.productstyle'])->whereIn('id',array('5'))->orderBy('order_no','asc')->get(); return $data; } public function GetLostleadsProjectCancelledNewCustomer($request){ $data = PipelineStage::select('*')->with(['deals' => function($que) use ($request){ if($request->has('deal_name') ) { $que->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number' ,'like', $request->deal_name.'%'); }); }); }); }); } if(!empty($request->get('user_deals') )) { $que->where('owner_id', '=', $request->user_deals); }else if( !auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin') ) { if(auth()->user()->hasRole('Team Lead') || auth()->user()->hasRole('Manager')){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }elseif( auth()->user()->id==148 ){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }else { $que->where('owner_id', '=', auth()->user()->id); } }else{ if(auth()->user()->hasRole('Team Lead') && auth()->user()->hasRole('Manager')){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }else{ } } if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('close_date', [date($request->from) , date($request->to)]); }else{ $timezone = 'America/New_York'; // Replace with desired U.S. timezone // Get the first and last days of the current month in the specified timezone $first = Carbon::now($timezone)->startOfMonth()->toDateString(); $last = Carbon::now($timezone)->endOfMonth()->toDateString(); $que->whereBetween('close_date', [date($first) , date($last)]); } if(!empty($request->get('sale_type') )) { $que->where('sale_type' ,'=', $request->sale_type); } if(!empty($request->get('clost_reason') )) { $que->where('lead_source_id' ,'=', $request->clost_reason ); } if(!empty($request->get('priority_id') )) { $que->where('priority_id' ,'=', $request->priority_id); } if(!empty($request->get('order_type_id') )) { $que->where('deal_type_id' ,'=', $request->order_type_id); } if(!empty($request->get('domain_id') )) { $que->where('domain_id' ,'=', $request->domain_id); } $que->where('deal_status','=','1'); $que->where('show_follow_up','=','1'); $que->whereIn('lost_reason',array('1','6')); },'deals.client','deals.dealProducts','dealProducts.product','dealProducts.productstyle'])->whereIn('id',array('5'))->orderBy('order_no','asc')->get(); return $data; } public function GetLostleadsProjectCancelledExistingCustomer($request){ $data = PipelineStage::select('*')->with(['deals' => function($que) use ($request){ if($request->has('deal_name') ) { $que->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number' ,'like', $request->deal_name.'%'); }); }); }); }); } if(!empty($request->get('user_deals') )) { $que->where('owner_id', '=', $request->user_deals); }else if( !auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin') ) { if(auth()->user()->hasRole('Team Lead') || auth()->user()->hasRole('Manager')){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }elseif( auth()->user()->id==148 ){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }else { $que->where('owner_id', '=', auth()->user()->id); } }else{ if(auth()->user()->hasRole('Team Lead') && auth()->user()->hasRole('Manager')){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }else{ } } if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('close_date', [date($request->from) , date($request->to)]); }else{ $timezone = 'America/New_York'; // Replace with desired U.S. timezone // Get the first and last days of the current month in the specified timezone $first = Carbon::now($timezone)->startOfMonth()->toDateString(); $last = Carbon::now($timezone)->endOfMonth()->toDateString(); $que->whereBetween('close_date', [date($first) , date($last)]); } if(!empty($request->get('sale_type') )) { $que->where('sale_type' ,'=', $request->sale_type); } if(!empty($request->get('clost_reason') )) { $que->where('lead_source_id' ,'=', $request->clost_reason ); } if(!empty($request->get('priority_id') )) { $que->where('priority_id' ,'=', $request->priority_id); } if(!empty($request->get('order_type_id') )) { $que->where('deal_type_id' ,'=', $request->order_type_id); } if(!empty($request->get('domain_id') )) { $que->where('domain_id' ,'=', $request->domain_id); } $que->where('deal_status','=','1'); $que->where('show_follow_up','=','1'); $que->where('lost_reason','=','6'); },'deals.client','deals.dealProducts','dealProducts.product','dealProducts.productstyle'])->whereIn('id',array('5'))->orderBy('order_no','asc')->get(); return $data; } public function GetLostleadsHighPrice($request){ $data = PipelineStage::select('*')->with(['deals' => function($que) use ($request){ if($request->has('deal_name') ) { $que->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number' ,'like', $request->deal_name.'%'); }); }); }); }); } if(!empty($request->get('user_deals') )) { $que->where('owner_id', '=', $request->user_deals); }else if( !auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin') ) { if(auth()->user()->hasRole('Team Lead') || auth()->user()->hasRole('Manager')){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }elseif( auth()->user()->id==148 ){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }else { $que->where('owner_id', '=', auth()->user()->id); } }else{ if(auth()->user()->hasRole('Team Lead') && auth()->user()->hasRole('Manager')){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }else{ } } if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('close_date', [date($request->from) , date($request->to)]); }else{ $timezone = 'America/New_York'; // Replace with desired U.S. timezone // Get the first and last days of the current month in the specified timezone $first = Carbon::now($timezone)->startOfMonth()->toDateString(); $last = Carbon::now($timezone)->endOfMonth()->toDateString(); $que->whereBetween('close_date', [date($first) , date($last)]); } if(!empty($request->get('sale_type') )) { $que->where('sale_type' ,'=', $request->sale_type); } if(!empty($request->get('clost_reason') )) { $que->where('lead_source_id' ,'=', $request->clost_reason ); } if(!empty($request->get('priority_id') )) { $que->where('priority_id' ,'=', $request->priority_id); } if(!empty($request->get('order_type_id') )) { $que->where('deal_type_id' ,'=', $request->order_type_id); } if(!empty($request->get('domain_id') )) { $que->where('domain_id' ,'=', $request->domain_id); } $que->where('deal_status','=','1'); $que->where('show_follow_up','=','1'); $que->where('lost_reason','=','2'); },'deals.client','deals.dealProducts','dealProducts.product','dealProducts.productstyle'])->whereIn('id',array('5'))->orderBy('order_no','asc')->get(); return $data; } public function GetLostPlacedOrderwithOther($request){ $data = PipelineStage::select('*')->with(['deals' => function($que) use ($request){ if($request->has('deal_name') ) { $que->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number' ,'like', $request->deal_name.'%'); }); }); }); }); } if(!empty($request->get('user_deals') )) { $que->where('owner_id', '=', $request->user_deals); }else if( !auth()->user()->hasRole('Sales Data Entry') || !auth()->user()->hasRole('super-admin') ) { if(auth()->user()->hasRole('Team Lead') && auth()->user()->hasRole('Manager')){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }elseif( auth()->user()->id==148 ){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }else { $que->where('owner_id', '=', auth()->user()->id); } }else{ if(auth()->user()->hasRole('Team Lead') && auth()->user()->hasRole('Manager')){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }else{ } } if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('close_date', [date($request->from) , date($request->to)]); }else{ $timezone = 'America/New_York'; // Replace with desired U.S. timezone // Get the first and last days of the current month in the specified timezone $first = Carbon::now($timezone)->startOfMonth()->toDateString(); $last = Carbon::now($timezone)->endOfMonth()->toDateString(); $que->whereBetween('close_date', [date($first) , date($last)]); } if(!empty($request->get('sale_type') )) { $que->where('sale_type' ,'=', $request->sale_type); } if(!empty($request->get('clost_reason') )) { $que->where('lead_source_id' ,'=', $request->clost_reason ); } if(!empty($request->get('priority_id') )) { $que->where('priority_id' ,'=', $request->priority_id); } if(!empty($request->get('order_type_id') )) { $que->where('deal_type_id' ,'=', $request->order_type_id); } if(!empty($request->get('domain_id') )) { $que->where('domain_id' ,'=', $request->domain_id); } $que->where('deal_status','=','1'); $que->where('show_follow_up','=','1'); $que->where('lost_reason','=','3'); },'deals.client','deals.dealProducts','dealProducts.product','dealProducts.productstyle'])->whereIn('id',array('5'))->orderBy('order_no','asc')->get(); return $data; } public function GetLostRequireStockBoxes($request){ $data = PipelineStage::select('*')->with(['deals' => function($que) use ($request){ if($request->has('deal_name') ) { $que->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number' ,'like', $request->deal_name.'%'); }); }); }); }); } if(!empty($request->get('user_deals') )) { $que->where('owner_id', '=', $request->user_deals); }else if( !auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin') ) { if(auth()->user()->hasRole('Team Lead') || auth()->user()->hasRole('Manager')){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }elseif( auth()->user()->id==148 ){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }else { $que->where('owner_id', '=', auth()->user()->id); } }else{ if(auth()->user()->hasRole('Team Lead') && auth()->user()->hasRole('Manager')){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }else{ } } if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('close_date', [date($request->from) , date($request->to)]); }else{ $timezone = 'America/New_York'; // Replace with desired U.S. timezone // Get the first and last days of the current month in the specified timezone $first = Carbon::now($timezone)->startOfMonth()->toDateString(); $last = Carbon::now($timezone)->endOfMonth()->toDateString(); $que->whereBetween('close_date', [date($first) , date($last)]); } if(!empty($request->get('sale_type') )) { $que->where('sale_type' ,'=', $request->sale_type); } if(!empty($request->get('clost_reason') )) { $que->where('lead_source_id' ,'=', $request->clost_reason ); } if(!empty($request->get('priority_id') )) { $que->where('priority_id' ,'=', $request->priority_id); } if(!empty($request->get('order_type_id') )) { $que->where('deal_type_id' ,'=', $request->order_type_id); } if(!empty($request->get('domain_id') )) { $que->where('domain_id' ,'=', $request->domain_id); } $que->where('deal_status','=','1'); $que->where('show_follow_up','=','1'); $que->where('lost_reason','=','4'); },'deals.client','deals.dealProducts','dealProducts.product','dealProducts.productstyle'])->whereIn('id',array('5'))->orderBy('order_no','asc')->get(); return $data; } public function GetLostOversizeSmallQty($request){ $data = PipelineStage::select('*')->with(['deals' => function($que) use ($request){ if($request->has('deal_name') ) { $que->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number' ,'like', $request->deal_name.'%'); }); }); }); }); } if(!empty($request->get('user_deals') )) { $que->where('owner_id', '=', $request->user_deals); }else if( !auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin') ) { if(auth()->user()->hasRole('Team Lead')|| auth()->user()->hasRole('Manager')){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }elseif( auth()->user()->id==148 ){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }else { $que->where('owner_id', '=', auth()->user()->id); } }else{ if(auth()->user()->hasRole('Team Lead') && auth()->user()->hasRole('Manager')){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }else{ } } if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('close_date', [date($request->from) , date($request->to)]); }else{ $timezone = 'America/New_York'; // Replace with desired U.S. timezone // Get the first and last days of the current month in the specified timezone $first = Carbon::now($timezone)->startOfMonth()->toDateString(); $last = Carbon::now($timezone)->endOfMonth()->toDateString(); $que->whereBetween('close_date', [date($first) , date($last)]); } if(!empty($request->get('sale_type') )) { $que->where('sale_type' ,'=', $request->sale_type); } if(!empty($request->get('clost_reason') )) { $que->where('lead_source_id' ,'=', $request->clost_reason ); } if(!empty($request->get('priority_id') )) { $que->where('priority_id' ,'=', $request->priority_id); } if(!empty($request->get('order_type_id') )) { $que->where('deal_type_id' ,'=', $request->order_type_id); } if(!empty($request->get('domain_id') )) { $que->where('domain_id' ,'=', $request->domain_id); } $que->where('deal_status','=','1'); $que->where('show_follow_up','=','1'); $que->where('lost_reason','=','5'); },'deals.client','deals.dealProducts','dealProducts.product','dealProducts.productstyle'])->whereIn('id',array('5'))->orderBy('order_no','asc')->get(); return $data; } public function GetLostFakeinquiry($request){ $data = PipelineStage::select('*')->with(['deals' => function($que) use ($request){ if($request->has('deal_name') ) { $que->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number' ,'like', $request->deal_name.'%'); }); }); }); }); } if(!empty($request->get('user_deals') )) { $que->where('owner_id', '=', $request->user_deals); }else if( !auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin') ) { if(auth()->user()->hasRole('Team Lead') || auth()->user()->hasRole('Manager')){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }elseif( auth()->user()->id==148 ){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }else { $que->where('owner_id', '=', auth()->user()->id); } }else{ if(auth()->user()->hasRole('Team Lead') && auth()->user()->hasRole('Manager')){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }else{ } } if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('close_date', [date($request->from) , date($request->to)]); }else{ $timezone = 'America/New_York'; // Replace with desired U.S. timezone // Get the first and last days of the current month in the specified timezone $first = Carbon::now($timezone)->startOfMonth()->toDateString(); $last = Carbon::now($timezone)->endOfMonth()->toDateString(); $que->whereBetween('close_date', [date($first) , date($last)]); } if(!empty($request->get('sale_type') )) { $que->where('sale_type' ,'=', $request->sale_type); } if(!empty($request->get('clost_reason') )) { $que->where('lead_source_id' ,'=', $request->clost_reason ); } if(!empty($request->get('priority_id') )) { $que->where('priority_id' ,'=', $request->priority_id); } if(!empty($request->get('order_type_id') )) { $que->where('deal_type_id' ,'=', $request->order_type_id); } if(!empty($request->get('domain_id') )) { $que->where('domain_id' ,'=', $request->domain_id); } $que->where('deal_status','=','1'); $que->where('show_follow_up','=','1'); $que->where('lost_reason','=','7'); },'deals.client','deals.dealProducts','dealProducts.product','dealProducts.productstyle'])->whereIn('id',array('5'))->orderBy('order_no','asc')->get(); return $data; } public function GetLostRestrictedProduct($request){ $data = PipelineStage::select('*')->with(['deals' => function($que) use ($request){ if($request->has('deal_name') ) { $que->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number' ,'like', $request->deal_name.'%'); }); }); }); }); } if(!empty($request->get('user_deals') )) { $que->where('owner_id', '=', $request->user_deals); }else if( !auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin') ) { if(auth()->user()->hasRole('Team Lead') || auth()->user()->hasRole('Manager')){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }elseif( auth()->user()->id==148 ){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }else { $que->where('owner_id', '=', auth()->user()->id); } }else{ if(auth()->user()->hasRole('Team Lead') && auth()->user()->hasRole('Manager')){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }else{ } } if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('close_date', [date($request->from) , date($request->to)]); }else{ $timezone = 'America/New_York'; // Replace with desired U.S. timezone // Get the first and last days of the current month in the specified timezone $first = Carbon::now($timezone)->startOfMonth()->toDateString(); $last = Carbon::now($timezone)->endOfMonth()->toDateString(); $que->whereBetween('close_date', [date($first) , date($last)]); } if(!empty($request->get('sale_type') )) { $que->where('sale_type' ,'=', $request->sale_type); } if(!empty($request->get('clost_reason') )) { $que->where('lead_source_id' ,'=', $request->clost_reason ); } if(!empty($request->get('priority_id') )) { $que->where('priority_id' ,'=', $request->priority_id); } if(!empty($request->get('order_type_id') )) { $que->where('deal_type_id' ,'=', $request->order_type_id); } if(!empty($request->get('domain_id') )) { $que->where('domain_id' ,'=', $request->domain_id); } $que->where('deal_status','=','1'); $que->where('show_follow_up','=','1'); $que->where('lost_reason','=','8'); },'deals.client','deals.dealProducts','dealProducts.product','dealProducts.productstyle'])->whereIn('id',array('5'))->orderBy('order_no','asc')->get(); return $data; } public function GetDeadleads($request){ $data = PipelineStage::select('*')->with(['deals' => function($que) use ($request){ if($request->has('deal_name') ) { $que->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number' ,'like', $request->deal_name.'%'); }); }); }); }); }if(!empty($request->get('user_deals') )) { $que->where('owner_id', '=', $request->user_deals); }else if( !auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin') ) { if(auth()->user()->hasRole('Team Lead') || auth()->user()->hasRole('Manager')){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }elseif(auth()->user()->id==148 ){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }else { $que->where('owner_id', '=', auth()->user()->id); } }else{ if(auth()->user()->hasRole('Team Lead') && auth()->user()->hasRole('Manager')){ $uid = User::where('id',auth()->user()->id)->first(); $que->whereIn('owner_id', explode(',',$uid->team_member)); }else{ } } if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('close_date', [date($request->from) , date($request->to)]); }else{ $timezone = 'America/New_York'; // Replace with desired U.S. timezone // Get the first and last days of the current month in the specified timezone $first = Carbon::now($timezone)->startOfMonth()->toDateString(); $last = Carbon::now($timezone)->endOfMonth()->toDateString(); $que->whereBetween('close_date', [date($first) , date($last)]); } if(!empty($request->get('sale_type') )) { $que->where('sale_type' ,'=', $request->sale_type); } if(!empty($request->get('priority_id') )) { $que->where('priority_id' ,'=', $request->priority_id); } if(!empty($request->get('order_type_id') )) { $que->where('deal_type_id' ,'=', $request->order_type_id); } if(!empty($request->get('domain_id') )) { $que->where('domain_id' ,'=', $request->domain_id); } if(!empty($request->get('clost_reason') )) { $que->where('lead_source_id' ,'=', $request->clost_reason ); } if(auth()->user()->employee_country_id==2){ $que->where('production_from' ,'=',auth()->user()->employee_country_id); } $que->where('deal_status','=','1'); $que->where('show_follow_up','=','1'); },'deals.client','deals.dealProducts','dealProducts.product','dealProducts.productstyle'])->whereIn('id',array('13'))->orderBy('order_no','asc')->get(); return $data; } public function getCloseWon($request){ $data = Deal::select('*')->with(['deals','client','dealProducts','dealProducts.product','dealProducts.productstyle'])->orderBy('open_date','desc'); if($request->has('deal_name') ) { $data->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number' ,'like', $request->deal_name.'%')->orWhere(function ($ques) use ($request) { $ques->where('bd_order_number' ,'like', $request->deal_name.'%'); }); }); }); }); }); } if(!empty($request->get('user_deals') )) { $data->where('owner_id', '=', $request->user_deals); }else if(!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')) { if(auth()->user()->hasRole('Team Lead') && auth()->user()->hasRole('Manager')){ $uid = User::where('id',auth()->user()->id)->first(); $data->whereIn('owner_id', explode(',',$uid->team_member)); }elseif( auth()->user()->id==148 ){ $uid = User::where('id',auth()->user()->id)->first(); $data->whereIn('owner_id', explode(',',$uid->team_member)); }else { $data->where('owner_id', '=', auth()->user()->id); } }else{ if(auth()->user()->hasRole('Team Lead') && auth()->user()->hasRole('Manager')){ $uid = User::where('id',auth()->user()->id)->first(); $data->whereIn('owner_id', explode(',',$uid->team_member)); }else{ } } if(!empty($request->get('from') && $request->get('to'))) { $f = $request['from']; $t = $request['to']; $data->where(function ($q) use ($f, $t) { $q->where(function ($qs) use ($f, $t) { $qs->where('bd_close_date', '>=', date($f)) ->where('bd_close_date', '<=', date($t)); // Assuming February 2024 for the example })->orWhereBetween('close_date', [date($f), date($t)]); }); }else{ $data->where(function ($q){ $first =date("Y-m-d", strtotime("first day of this month")); $last = date("Y-m-d", strtotime("last day of this month")); $q->where(function ($qs){ $first =date("Y-m-d", strtotime("first day of this month")); $last = date("Y-m-d", strtotime("last day of this month")); $qs->where('bd_close_date', '>=', $first) ->where('bd_close_date', '<=', $last); // Assuming February 2024 for the example })->orWhereBetween('close_date', [$first, $last]); }); } $data->where('deal_status','=','1'); if(auth()->user()->employee_country_id==2){ $data->where('production_from' ,'=',auth()->user()->employee_country_id); } $data->where('design_complete_status','=','1'); $data->where('production_status','=','0')->where(function ($q){ $q->where(function ($qs){ $qs->where('bd_pipeline_stage_id','=',4); })->orWhere('pipeline_stage_id','=',4); }); $data=$data->get(); return $data; } public function getShippingDeals($request){ $data = Deal::select('*')->with(['deals','vendor', 'production' ,'client','dealProducts','dealProducts.product','dealProducts.productstyle'])->orderBy('open_date','desc'); // Filter based on deal_name if present in request if ($request->has('deal_name') && !empty($request->deal_name)) { $data->where(function ($query) use ($request) { $query->whereHas('client', function ($subQuery) use ($request) { $subQuery->where('name', 'like', $request->deal_name . '%'); }) ->orWhereHas('client.emails', function ($subQuery) use ($request) { $subQuery->where('value', 'like', $request->deal_name . '%'); }) ->orWhereHas('client.phoneNos', function ($subQuery) use ($request) { $subQuery->where('value', 'like', $request->deal_name . '%'); }) ->orWhereHas('dealProducts', function ($subQuery) use ($request) { $subQuery->where('order_number', 'like', $request->deal_name . '%') ->orWhere('bd_order_number', 'like', $request->deal_name . '%'); }); }); }if(!empty($request->get('user_deals') )) { $data->where('owner_id' ,'=', $request->user_deals); }else{ if(auth()->user()->id!=1 && auth()->user()->id!=63 && auth()->user()->id!=248 && auth()->user()->id!=249 && auth()->user()->id!=276 && auth()->user()->id!=207 && auth()->user()->id!=188 && auth()->user()->id!=148 && auth()->user()->id!=121 && auth()->user()->id!=106 && auth()->user()->id!=107 && auth()->user()->id!=108 && auth()->user()->id!=109 && auth()->user()->id!=90 && auth()->user()->id!=94) { $data->where('owner_id', '=', auth()->user()->id); }elseif(auth()->user()->id==148 ){ $uid = User::where('id',auth()->user()->id)->first(); $data->whereIn('owner_id', explode(',',$uid->team_member)); } } if(!empty($request->get('from') && $request->get('to'))) { $data->whereHas('production', function ($queryu) use ($request) { $f = $request['from']; $t = $request['to']; $queryu->where(function ($q) use ($f, $t) { $q->where(function ($qs) use ($f, $t) { $qs->where('receiving_date', '>=', date($f)) ->where('receiving_date', '<=', date($t)); // Assuming February 2024 for the example })->orWhereBetween('receiving_date', [date($f), date($t)]); }); }); }else{ $data->whereHas('production', function ($queryu) use ($request) { $first =date("Y-m-d", strtotime("first day of this month"));; $last = date("Y-m-d", strtotime("last day of this month")); // $queryu->whereBetween('receiving_date', [date($first) , date($last)]); $queryu->where(function ($qs){ $first =date("Y-m-d", strtotime("first day of this month"));; $last = date("Y-m-d", strtotime("last day of this month")); $qs->where('receiving_date', '>=', $first) ->where('receiving_date', '<=', $last); // Assuming February 2024 for the example })->orWhereBetween('receiving_date', [$first, $last]); }); } /* if(!empty($request->get('from') && $request->get('to'))) { $f = $request['from']; $t = $request['to']; $data->where(function ($q) use ($f, $t) { $q->where(function ($qs) use ($f, $t) { $qs->where('bd_close_date', '>=', date($f)) ->where('bd_close_date', '<=', date($t)); // Assuming February 2024 for the example })->orWhereBetween('close_date', [date($f), date($t)]); }); }else{ $first =date("Y-m-d", strtotime("1-01-2023"));; $last = date("Y-m-d", strtotime("last day of this month")); $data->where(function ($q){ $first =date("Y-m-d", strtotime("1-01-2023"));; $last = date("Y-m-d", strtotime("last day of this month")); $q->where(function ($qs){ $first =date("Y-m-d", strtotime("1-01-2023"));; $last = date("Y-m-d", strtotime("last day of this month")); $qs->where('bd_close_date', '>=', $first) ->where('bd_close_date', '<=', $last); // Assuming February 2024 for the example })->orWhereBetween('close_date', [$first, $last]); }); }*/ if(auth()->user()->employee_country_id==2){ $data->where('production_from' ,'=',auth()->user()->employee_country_id); } $data->where('deal_status','=','1'); $data->where('shipping_status','=','1')->where(function ($q){ $q->where(function ($qs){ $qs->where('bd_pipeline_stage_id','=',4); })->orWhere('pipeline_stage_id','=',4); }); $data=$data->get(); return $data; } public function PaymentHistory($id){ return Deal::select('*')->with(['deals','dealProducts','template_designer','print_ready_designer','dealProducts.dealProductQuantityAndEstimationAmounts','deal_amount'])->where('id',$id)->get(); } public function followupHistory($id){ return DealFollowUp::select('*')->where('id',$id)->first(); } public function duplicateDeal($id){ $deal_details=Deal::where('id',$id)->first(); if ($deal_details->production_from == 1) { // Add -CN if not already present $production_from =2; if (!str_ends_with($deal_details->order_no, '-CN')) { $order_no= $deal_details->order_no .= '-CN'; } } elseif ($deal_details->production_from == 2) { // Remove -CN if it exists $production_from =1; $order_no= $deal_details->order_no = str_replace('-CN', '', $deal_details->order_no); } $data = array( 'order_no' => $order_no, 'lead_source_id' => $deal_details->lead_source_id, 'client_id'=> $deal_details->client_id, 'pipeline_stage_id' => 2, 'deal_type_id'=> 2, 'priority_id'=> 1, 'product_id' => $deal_details->product_id, 'amount' => $deal_details->amount, 'tip_amount' => $deal_details->tip_amount, 'est_amount' => $deal_details->est_amount, 'owner_id' => $deal_details->owner_id, 'open_date' => $deal_details->open_date, 'created_by' => $deal_details->created_by, 'order_number' =>$order_no, 'created_at' => $deal_details->created_at, 'updated_by' => $deal_details->updated_by, 'updated_at' => $deal_details->updated_at, 'deleted_by' => $deal_details->deleted_by, 'deleted_at' => $deal_details->deleted_at, 'deal_type' => $deal_details->deal_type, 'production_status' => $deal_details->production_status, 'shipping_status' => $deal_details->shipping_status, 'complete_status' => $deal_details->complete_status, 'lead_type_id' => $deal_details->lead_type_id, 'deal_status' => $deal_details->deal_status, 'domain_id' => $deal_details->domain_id, 'designer_status' => $deal_details->designer_status, 'no_of_design' => $deal_details->no_of_design, 'deal_lead_type_id' => $deal_details->deal_lead_type_id, 'sale_type' => $deal_details->sale_type, 'customer_type' => $deal_details->customer_type, 'show_follow_up' => $deal_details->show_follow_up, 'embossing' => $deal_details->embossing, 'uv' => $deal_details->uv, 'foiling' => $deal_details->foiling, 'material' => $deal_details->material, 'special_instruction' => $deal_details->special_instruction, 'production_from' => $production_from, 'status' => $deal_details->status, ); $deal = Deal::create($data); $deal_product=DealProduct::where('deal_id',$deal_details->id)->first(); $product_data = array( 'deal_id' => $deal->id, 'product_id' => $deal_product->product_id, 'product_style_id' => $deal_product->product_style_id, 'product_length' => $deal_product->product_length, 'product_width' => $deal_product->product_width, 'product_height' => $deal_product->product_height, 'product_size' => $deal_product->product_size, 'product_stock_id' => $deal_product->product_stock_id, 'product_color_id' => $deal_product->product_color_id, 'product_measurement_unit_id' => $deal_product->product_measurement_unit_id, 'is_drop' => $deal_product->is_drop, 'created_at' => $deal_product->created_at, 'updated_at' => $deal_product->updated_at, 'open_product_length' => $deal_product->open_product_length, 'open_product_width' => $deal_product->open_product_width, 'open_product_height' => $deal_product->open_product_height, 'insert_open_product_length' => $deal_product->insert_open_product_length, 'insert_open_product_width' => $deal_product->insert_open_product_width, 'insert_open_product_height' => $deal_product->insert_open_product_height, 'insert_product_height' => $deal_product->insert_product_height, 'insert_product_width' => $deal_product->insert_product_width, 'insert_product_height_two' => $deal_product->insert_product_height_two, 'insert_product_width_two' => $deal_product->insert_product_width_two, 'insert_product_height_three' => $deal_product->insert_product_height_three, 'insert_product_width_three' => $deal_product->insert_product_width_three, 'open_product_length_two' => $deal_product->open_product_length_two, 'open_product_width_two' => $deal_product->open_product_width_two, 'open_product_height_two' => $deal_product->open_product_height_two, 'insert_open_product_length_two' => $deal_product->insert_open_product_length_two, 'insert_open_product_width_two' => $deal_product->insert_open_product_width_two, 'insert_open_product_height_two' => $deal_product->insert_open_product_height_two, 'insert_open_product_length_three' => $deal_product->insert_open_product_length_three, 'insert_open_product_width_three' => $deal_product->insert_open_product_width_three, 'insert_open_product_height_three' => $deal_product->insert_open_product_height_three, ); $deal_product_data = DealProduct::create($product_data); $DealProductQuantityAndEstimationAmount=DealProductQuantityAndEstimationAmount::where('deal_product_id',$deal_product->id)->get(); foreach ($DealProductQuantityAndEstimationAmount as $q) { $qty_data = array( 'deal_product_id' => $deal_product_data->id, 'deal_product_quantity' => $q->deal_product_quantity, 'deal_product_est_amount' => 0, 'deal_product_amount' => 0, 'is_required' => $q->is_required, 'created_at' => $q->created_at, 'updated_at' => $q->updated_at, 'receive_able_amount' => $q->receive_able_amount, 'no_of_design' => $q->no_of_design, 'special_instruction' => $q->special_instruction, 'checked_value' => $q->checked_value, 'checked_sea' => $q->checked_sea, 'sea_estimation' => $q->sea_estimation ); // Uncomment to insert into DB DealProductQuantityAndEstimationAmount::create($qty_data); } $deal_files=File::where('fileable_id',$deal_details->id)->first(); if(isset($deal_files)) { $file_data = array( 'fileable_type' => $deal_files->fileable_type, 'fileable_id' => $deal->id, // assuming this is the new deal ID 'name' => $deal_files->name, 'text' => $deal_files->text, 'url' => $deal_files->url, 'ext' => $deal_files->ext, 'type' => $deal_files->type, 'created_by' => $deal_files->created_by, 'updated_by' => $deal_files->updated_by, 'deleted_by' => $deal_files->deleted_by, 'created_at' => $deal_files->created_at, 'updated_at' => $deal_files->updated_at, 'deleted_at' => $deal_files->deleted_at, ); $deal_file_data = File::create($file_data); } return $deal; } public function checkfollowup($request,$id){ DealFollowUp::where('id', $id)->update(['status' => 'read']); return Deal::where('id',1)->first(); } public function followups($request){ if(auth()->user()->id==1 || auth()->user()->id==106 ||auth()->user()->id==121 || auth()->user()->id==68 || auth()->user()->id==90 || auth()->user()->id==106 || auth()->user()->id==107 || auth()->user()->id==108 || auth()->user()->id==109 || auth()->user()->id==94) { $data = DealFollowUp::select('*'); }else{ $data = DealFollowUp::select('*')->where('user_id', auth()->user()->id); } if(!empty($request->get('start_date') || $request->get('end_date'))) { $data->whereBetween('follow_up_date', [date('Y-m-d',strtotime($request->start_date)) , date('Y-m-d',strtotime($request->end_date))]); }else{ $currentDate = date("Y-m-d"); $currentTime = date("H:i:s"); $first =date("Y-m-d", strtotime("$currentDate")); $last = date("Y-m-d", strtotime("$currentDate")); $data->whereBetween('next_followup_date', [$first, $last]); } $data=$data->get(); return $data; } public function getcompleteTemplateDesigns($request){ $data = Deal::select('*')->with(['deals','client','template_designer','deals.print_ready_designer','dealProducts','dealProducts.product','dealProducts.productstyle'])->orderBy('id','desc'); if($request->has('deal_name') ) { $data->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number' ,'like', $request->deal_name.'%')->orWhere(function ($ques) use ($request) { $ques->where('bd_order_number' ,'like', $request->deal_name.'%'); }); }); }); }); }); } if(auth()->user()->designer_status =='active') { if (!empty($request->get('user_deals'))) { $data->where('template_designer_id', '=', $request->user_deals); } else { if(!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')&& !auth()->user()->hasRole('Manager') && !auth()->user()->hasRole('Team Lead')) { $data->where('template_designer_id', '=', auth()->user()->id); } } }else{ if (!empty($request->get('user_deals'))) { $data->where('owner_id', '=', $request->user_deals); } else { if (!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')&& !auth()->user()->hasRole('Manager') && !auth()->user()->hasRole('Team Lead')) { $data->where('owner_id', '=', auth()->user()->id); } } } if(!empty($request->get('from') && $request->get('to'))) { $data->whereBetween('template_complete_date', [date('Y-m-d H:i:s',strtotime($request->from.'00:00:00')) , date('Y-m-d H:i:s',strtotime($request->to.'23:59:59'))]); }else{ $first =date("Y-m-d H:i:s", strtotime("first day of this month 00:00:00"));; $last = date("Y-m-d H:i:s", strtotime("last day of this month 23:59:59")); $data->whereBetween('template_complete_date', [$first, $last]); } $data->where('deal_status','=','1'); $data->where('shipping_status','=','0'); $data->where('production_status','=','0'); $data->where('template_status','=','1'); $data->where('template_complete_status','=','1'); $data->where('designer_status','=','0'); $data->where('designer_work','=','2'); $data->where('design_complete_status','=','0'); if(auth()->user()->employee_country_id==2){ $data->where('production_from' ,'=',auth()->user()->employee_country_id); } //$data->whereIn('pipeline_stage_id', array('1','2','3','4','11')); /* ->where(function ($q){ $q->where(function ($qs){ $qs->where('bd_pipeline_stage_id','=',4)->where('pipeline_stage_id','=',5); })->orWhere('pipeline_stage_id','=',4); }); */ $data=$data->get(); return $data; } public function getLeadscopy($request) { $from = $request->get('from') ?? \Carbon\Carbon::now()->startOfMonth()->toDateString(); $to = $request->get('to') ?? \Carbon\Carbon::now()->endOfMonth()->toDateString(); $stageIds = ['1', '2', '11', '3']; // Adjust as needed return PipelineStage::whereIn('id', $stageIds) ->orderBy('order_no', 'asc') ->get() ->map(function ($stage) use ($from, $to, $request) { return tap($stage, function ($stage) use ($from, $to, $request) { $query = \App\Models\Deal::query() ->where('pipeline_stage_id', $stage->id) ->where('deal_status', 1) ->where('show_follow_up', 1) ->whereBetween('open_date', [$from, $to]) ->with(['dealProducts.dealProductQuantityAndEstimationAmounts_sigle']); // Filters if (!empty($request->get('user_deals'))) { $query->where('deals.owner_id', $request->user_deals); } elseif (!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')) { if ( auth()->user()->hasRole('Team Lead') || auth()->user()->hasRole('Manager') || auth()->user()->id == 148 ) { $uid = \App\Models\User::find(auth()->user()->id); $teamMemberIds = explode(',', $uid?->team_member ?? ''); $query->whereIn('deals.owner_id', $teamMemberIds); } else { $query->where('deals.owner_id', auth()->user()->id); } } if ($request->filled('priority_id')) { $query->where('priority_id', $request->priority_id); } if ($request->filled('sale_type')) { $query->where('sale_type', $request->sale_type); } if ($request->filled('order_type_id')) { $query->where('deal_type_id', $request->order_type_id); } if ($request->filled('domain_id')) { $query->where('domain_id', $request->domain_id); } /* if ($request->filled('clost_reason')) { $query->where('lead_source_id', $request->clost_reason); }*/ if (auth()->user()->employee_country_id == 2) { $query->where('production_from', 2); } if ($request->has('deal_name') && !empty($request->deal_name)) { $dealName = $request->deal_name; $query->leftJoin('clients', 'deals.client_id', '=', 'clients.id') ->leftJoin('email_phone_details as email_phone_details', function ($join) { $join->on('clients.id', '=', 'email_phone_details.model_id') ->where('email_phone_details.type', '=', 'email') ->where('email_phone_details.model_type', '=', \App\Models\Client::class); }) ->leftJoin('email_phone_details as client_phones', function ($join) { $join->on('clients.id', '=', 'email_phone_details.model_id') ->where('email_phone_details.type', '=', 'phone') ->where('email_phone_details.model_type', '=', \App\Models\Client::class); }) ->leftJoin('deal_products', 'deals.id', '=', 'deal_products.deal_id') ->where(function ($query) use ($dealName) { $query->where('clients.name', 'like', "{$dealName}%") ->orWhere('email_phone_details.value', 'like', "{$dealName}%") ->orWhere('email_phone_details.value', 'like', "{$dealName}%") ->orWhere('order_number', 'like', "{$dealName}%") ->orWhere('bd_order_number', 'like', "{$dealName}%"); }) ->select('deals.*') ->groupBy('deals.id'); } // Execute and calculate $deals = $query->get(); // print_r($deals->count()); $estimation = 0; foreach ($deals as $deal) { $dealProduct = $deal->dealProducts->first(); $est = $dealProduct?->dealProductQuantityAndEstimationAmounts_sigle; ;if ($est) { if (!empty($est->checked_value)) { // If checked_value is set, prefer deal_product_est_amount, fallback to sea_estimation $estAmt = $est->deal_product_est_amount ?? $est->sea_estimation ?? 0; } elseif (!empty($est->checked_sea) && $est->checked_sea == 1) { // If checked_sea is set to 1, prefer sea_estimation $estAmt = $est->sea_estimation ?? 0; } else { // Otherwise fallback: prefer sea_estimation first, then deal_product_est_amount $estAmt = $est->deal_product_est_amount ?? $est->sea_estimation ?? 0; } } else { $estAmt = 0; } $estimation += $estAmt; } /* foreach ($deals as $deal) { $dealProduct = $deal->dealProducts->first(); $est = $dealProduct?->dealProductQuantityAndEstimationAmounts_sigle; $estAmt = (!empty($est?->checked_value)) ? ($est->deal_product_est_amount ?? $est->sea_estimation ?? 0) : ((!empty($est?->checked_sea) && $est->checked_sea == 1) ? $est->sea_estimation ?? 0 : ($est->deal_product_est_amount ?? $est->sea_estimation ?? 0)); $estimation += $estAmt; }*/ // Assign results to the stage $stage->total_leads = $deals->count(); $stage->estimation_total = $estimation; }); }); } public function getLostscopy($request) { $from = $request->get('from') ?? \Carbon\Carbon::now()->startOfMonth()->toDateString(); $to = $request->get('to') ?? \Carbon\Carbon::now()->endOfMonth()->toDateString(); $reasonLabels = [ 1 => 'Project Canceled (New Customer)', 2 => 'High Price', 3 => 'Placed Order with Other', 4 => 'Require Stock Boxes', 5 => 'Oversize / Small Qty', 6 => 'Project Canceled (Existing Customer)', 7 => 'Fake Inquiry', 8 => 'Restricted Product', 9 => 'NO Response', ]; $query = \App\Models\Deal::query() ->where('pipeline_stage_id', 5) // Lost stage ->where('deal_status', 1) ->where('show_follow_up', 1) ->whereBetween('open_date', [$from, $to]) ->with(['dealProducts.dealProductQuantityAndEstimationAmounts_sigle']); // Filters if (!empty($request->get('user_deals'))) { $query->where('deals.owner_id', $request->user_deals); } elseif (!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')) { if ( auth()->user()->hasRole('Team Lead') || auth()->user()->hasRole('Manager') || auth()->user()->id == 148 ) { $uid = \App\Models\User::find(auth()->user()->id); $teamMemberIds = explode(',', $uid?->team_member ?? ''); $query->whereIn('deals.owner_id', $teamMemberIds); } else { $query->where('deals.owner_id', auth()->user()->id); } } if ($request->filled('priority_id')) { $query->where('priority_id', $request->priority_id); } if ($request->filled('sale_type')) { $query->where('sale_type', $request->sale_type); } if ($request->filled('order_type_id')) { $query->where('deal_type_id', $request->order_type_id); } if ($request->filled('domain_id')) { $query->where('domain_id', $request->domain_id); } if (auth()->user()->employee_country_id == 2) { $query->where('production_from', 2); } if ($request->has('deal_name') && !empty($request->deal_name)) { $dealName = $request->deal_name; $query->leftJoin('clients', 'deals.client_id', '=', 'clients.id') ->leftJoin('email_phone_details as email_phone_details', function ($join) { $join->on('clients.id', '=', 'email_phone_details.model_id') ->where('email_phone_details.type', '=', 'email') ->where('email_phone_details.model_type', '=', \App\Models\Client::class); }) ->leftJoin('email_phone_details as client_phones', function ($join) { $join->on('clients.id', '=', 'email_phone_details.model_id') ->where('email_phone_details.type', '=', 'phone') ->where('email_phone_details.model_type', '=', \App\Models\Client::class); }) ->leftJoin('deal_products', 'deals.id', '=', 'deal_products.deal_id') ->where(function ($query) use ($dealName) { $query->where('clients.name', 'like', "{$dealName}%") ->orWhere('email_phone_details.value', 'like', "{$dealName}%") ->orWhere('client_phones.value', 'like', "{$dealName}%") ->orWhere('order_number', 'like', "{$dealName}%") ->orWhere('bd_order_number', 'like', "{$dealName}%"); }) ->select('deals.*') ->groupBy('deals.id'); } $allDeals = $query->get(); // Group by lost_reason $grouped = $allDeals->groupBy('lost_reason'); $results = []; foreach ($reasonLabels as $reasonId => $reasonName) { $deals = $grouped->get($reasonId, collect()); $estimation = 0; foreach ($deals as $deal) { $dealProduct = $deal->dealProducts->first(); $est = $dealProduct?->dealProductQuantityAndEstimationAmounts_sigle; $estAmt = (!empty($est?->checked_value)) ? ($est->deal_product_est_amount ?? $est->sea_estimation ?? 0) : ((!empty($est?->checked_sea) && $est->checked_sea == 1) ? $est->sea_estimation ?? 0 : ($est->sea_estimation ?? $est->deal_product_est_amount ?? 0)); $estimation += $estAmt; } $results[] = [ 'lost_reason_id' => $reasonId, 'lost_reason_name' => $reasonName, 'total_leads' => $deals->count(), 'estimation_total' => $estimation, 'deals' => $deals, ]; } return $results; } /*public function getLostscopy($request) { $from = $request->get('from') ?? \Carbon\Carbon::now()->startOfMonth()->toDateString(); $to = $request->get('to') ?? \Carbon\Carbon::now()->endOfMonth()->toDateString(); $reasonLabels = [ 1 => 'Project Canceled (New Customer)', 2 => 'High Price', 3 => 'Placed Order with Other', 4 => 'Require Stock Boxes', 5 => 'Oversize / Small Qty', 6 => 'Project Canceled (Existing Customer)', 7 => 'Fake Inquiry', 8 => 'Restricted Product', 9 => 'NO Response', ]; $query = \App\Models\Deal::query() ->where('pipeline_stage_id', 5) // Lost stage ->where('deal_status', 1) ->where('show_follow_up', 1) ->whereBetween('open_date', [$from, $to]) ->with(['dealProducts.dealProductQuantityAndEstimationAmounts_sigle']); // Filters if (!empty($request->get('user_deals'))) { $query->where('owner_id', $request->user_deals); } elseif (!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')) { if ( auth()->user()->hasRole('Team Lead') || auth()->user()->hasRole('Manager') || auth()->user()->id == 148 ) { $uid = \App\Models\User::find(auth()->user()->id); $teamMemberIds = explode(',', $uid?->team_member ?? ''); $query->whereIn('owner_id', $teamMemberIds); } else { $query->where('owner_id', auth()->user()->id); } } if ($request->filled('priority_id')) { $query->where('priority_id', $request->priority_id); } if ($request->filled('sale_type')) { $query->where('sale_type', $request->sale_type); } if ($request->filled('order_type_id')) { $query->where('deal_type_id', $request->order_type_id); } if ($request->filled('domain_id')) { $query->where('domain_id', $request->domain_id); } if (auth()->user()->employee_country_id == 2) { $query->where('production_from', 2); } if ($request->has('deal_name') && !empty($request->deal_name)) { $dealName = $request->deal_name; $query->leftJoin('clients', 'deals.client_id', '=', 'clients.id') ->leftJoin('email_phone_details as email_phone_details', function ($join) { $join->on('clients.id', '=', 'email_phone_details.model_id') ->where('email_phone_details.type', '=', 'email') ->where('email_phone_details.model_type', '=', \App\Models\Client::class); }) ->leftJoin('email_phone_details as client_phones', function ($join) { $join->on('clients.id', '=', 'email_phone_details.model_id') ->where('email_phone_details.type', '=', 'phone') ->where('email_phone_details.model_type', '=', \App\Models\Client::class); }) ->leftJoin('deal_products', 'deals.id', '=', 'deal_products.deal_id') ->where(function ($query) use ($dealName) { $query->where('clients.name', 'like', "{$dealName}%") ->orWhere('email_phone_details.value', 'like', "{$dealName}%") ->orWhere('client_phones.value', 'like', "{$dealName}%") ->orWhere('order_number', 'like', "{$dealName}%") ->orWhere('bd_order_number', 'like', "{$dealName}%"); }) ->select('deals.*') ->groupBy('deals.id'); } $allDeals = $query->get(); // Group by lost_reason $grouped = $allDeals->groupBy('lost_reason'); $results = []; foreach ($grouped as $reasonId => $deals) { $estimation = 0; foreach ($deals as $deal) { $dealProduct = $deal->dealProducts->first(); $est = $dealProduct?->dealProductQuantityAndEstimationAmounts_sigle; $estAmt = (!empty($est?->checked_value)) ? ($est->deal_product_est_amount ?? $est->sea_estimation ?? 0) : ((!empty($est?->checked_sea) && $est->checked_sea == 1) ? $est->sea_estimation ?? 0 : ($est->sea_estimation ?? $est->deal_product_est_amount ?? 0)); $estimation += $estAmt; } $results[] = [ 'lost_reason_id' => $reasonId, 'lost_reason_name' => $reasonLabels[$reasonId] ?? 'Unknown', 'total_leads' => count($deals), 'estimation_total' => $estimation, 'deals' => $deals, ]; } return $results; }*/ private function determineLostReason($deal) { // Example logic (customize this!) if (str_contains(strtolower($deal->note), 'price')) { return 1; // High Price } elseif (str_contains(strtolower($deal->note), 'delay')) { return 2; // Delayed Response } elseif (str_contains(strtolower($deal->note), 'not available')) { return 3; } elseif (str_contains(strtolower($deal->note), 'competitor')) { return 4; } elseif (str_contains(strtolower($deal->note), 'bad experience')) { return 5; } else { return 6; // Others } } public function getWoncopy($request) { $from = $request->get('from'); $to = $request->get('to'); if (empty($from) || empty($to)) { $timezone = 'Asia/Karachi'; $from = Carbon::now($timezone)->startOfMonth()->toDateString(); $to = Carbon::now($timezone)->endOfMonth()->toDateString(); } $stageIds = [4]; // ✅ Only Close Won $stages = PipelineStage::whereIn('id', $stageIds) ->orderBy('order_no', 'asc') ->get() ->map(function ($stage) use ($from, $to, $request) { $query = Deal::where('pipeline_stage_id', $stage->id) ->where('deal_status', 1) ->whereHas('deal_amount', function ($q) use ($from, $to) { // ✅ Only deals with receiving_date in range $q->whereBetween('receiving_date', [$from, $to]); }) ->with([ 'deal_amount' => fn($q) => $q->whereBetween('receiving_date', [$from, $to]), 'dealProducts.dealProductQuantityAndEstimationAmounts_sigle', 'client', 'owners', ]); if (!empty($request->get('user_deals'))) { $query->where('deals.owner_id', $request->user_deals); } elseif (!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')) { if ( auth()->user()->hasRole('Team Lead') || auth()->user()->hasRole('Manager') || auth()->user()->id == 148 ) { $uid = \App\Models\User::find(auth()->user()->id); $teamMemberIds = explode(',', $uid?->team_member ?? ''); $query->whereIn('deals.owner_id', $teamMemberIds); } else { $query->where('deals.owner_id', auth()->user()->id); } } if ($request->filled('priority_id')) { $query->where('priority_id', $request->priority_id); } if ($request->filled('sale_type')) { $query->where('sale_type', $request->sale_type); } if ($request->filled('order_type_id')) { $query->where('deal_type_id', $request->order_type_id); } if ($request->filled('domain_id')) { $query->where('domain_id', $request->domain_id); } if (auth()->user()->employee_country_id == 2) { $query->where('production_from', 2); } // Optional filters if ($request->has('deal_name') && !empty($request->deal_name)) { $dealName = $request->deal_name; $query->leftJoin('clients', 'deals.client_id', '=', 'clients.id') ->leftJoin('email_phone_details as email_phone_details', function ($join) { $join->on('clients.id', '=', 'email_phone_details.model_id') ->where('email_phone_details.type', '=', 'email') ->where('email_phone_details.model_type', '=', \App\Models\Client::class); }) ->leftJoin('email_phone_details as client_phones', function ($join) { $join->on('clients.id', '=', 'email_phone_details.model_id') ->where('email_phone_details.type', '=', 'phone') ->where('email_phone_details.model_type', '=', \App\Models\Client::class); }) ->leftJoin('deal_products', 'deals.id', '=', 'deal_products.deal_id') ->where(function ($query) use ($dealName) { $query->where('clients.name', 'like', "{$dealName}%") ->orWhere('email_phone_details.value', 'like', "{$dealName}%") ->orWhere('email_phone_details.value', 'like', "{$dealName}%") ->orWhere('order_number', 'like', "{$dealName}%") ->orWhere('bd_order_number', 'like', "{$dealName}%"); }) ->select('deals.*') ->groupBy('deals.id'); } if ($request->filled('priority_id')) { $query->where('priority_id', $request->priority_id); } // Load filtered deals $deals = $query->get(); // Totals $stage->total_deals = $deals->count(); $stage->total_received_amount = 0; $stage->total_selling_amount = 0; $stage->total_est_amount = 0; foreach ($deals as $deal) { $received = $deal->deal_amount->sum('amount'); $commission = (int) $deal->commission; $dealProduct = $deal->dealProducts->first(); $estData = $dealProduct?->dealProductQuantityAndEstimationAmounts_sigle; $selling = $estData?->deal_product_amount ?? 0; $est = $estData?->checked_sea ? ($estData->sea_estimation ?? 0) : ($estData->deal_product_est_amount ?? 0); $stage->total_received_amount += ($received + $commission); $stage->total_selling_amount += $selling; $stage->total_est_amount += $est; } return $stage; }); return $stages; } public function DesignReady($request){ $data = Deal::select('*')->with(['deals','client','template_designer','deals.print_ready_designer','dealProducts','dealProducts.product','dealProducts.productstyle'])->orderBy('id','desc'); if($request->has('deal_name') ) { $data->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number' ,'like', $request->deal_name.'%')->orWhere(function ($ques) use ($request) { $ques->where('bd_order_number' ,'like', $request->deal_name.'%'); }); }); }); }); }); } if(auth()->user()->designer_status =='active') { if(auth()->user()->template_designer_status=='yes') { if (!empty($request->get('user_deals'))) { $data->where('template_designer_id', '=', $request->user_deals); } else { if(!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')&& !auth()->user()->hasRole('Manager') && !auth()->user()->hasRole('Team Lead')) { $data->where('template_designer_id', '=', auth()->user()->id); } } }else { if (!empty($request->get('user_deals'))) { $data->where('designer_id', '=', $request->user_deals); } else { if (!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')&& !auth()->user()->hasRole('Manager') && !auth()->user()->hasRole('Team Lead')) { $data->where('designer_id', '=', auth()->user()->id); } } } }else{ if (!empty($request->get('user_deals'))) { $data->where('owner_id', '=', $request->user_deals); } else { if (!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')&& !auth()->user()->hasRole('Manager') && !auth()->user()->hasRole('Team Lead') ) { $data->where('owner_id', '=', auth()->user()->id); } } } if(!empty($request->get('from') && $request->get('to'))) { $data->whereBetween('design_assign_date', [date('Y-m-d H:i:s',strtotime($request->from.'00:00:00')) , date('Y-m-d H:i:s',strtotime($request->to.'23:59:59'))]); }else{ $first =date("Y-m-d H:i:s", strtotime("first day of this month 00:00:00"));; $last = date("Y-m-d H:i:s", strtotime("last day of this month 23:59:59")); $data->whereBetween('design_assign_date', [$first, $last]); } $data->where('deal_status','=','1'); $data->where('shipping_status','=','0'); $data->where('production_status','=','0'); $data->where('template_status','=','1'); $data->where('designer_status','=','1'); $data->where('designer_work','=','2'); $data->where('design_complete_status','=','0'); if(auth()->user()->employee_country_id==2){ $data->where('production_from' ,'=',auth()->user()->employee_country_id); } //$data->whereIn('pipeline_stage_id', array('1','2','3','4','11')); /* ->where(function ($q){ $q->where(function ($qs){ $qs->where('bd_pipeline_stage_id','=',4)->where('pipeline_stage_id','=',5); })->orWhere('pipeline_stage_id','=',4); }); */ $data=$data->get(); return $data; } public function getTemplateDesigns($request){ $data = Deal::select('*')->with(['deals','client','template_designer','dealProducts','dealProducts.product','dealProducts.productstyle'])->orderBy('id','desc'); if($request->has('deal_name') ) { $data->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number' ,'like', $request->deal_name.'%')->orWhere(function ($ques) use ($request) { $ques->where('bd_order_number' ,'like', $request->deal_name.'%'); }); }); }); }); }); } if( auth()->user()->designer_status == 'active'){ if(!empty($request->get('user_deals') )) { $data->where('template_designer_id' ,'=', $request->user_deals); }else { if(!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')&& !auth()->user()->hasRole('Manager') && !auth()->user()->hasRole('Team Lead')) { $data->where('template_designer_id', '=', auth()->user()->id); } } }else{ if(!empty($request->get('user_deals') )) { $data->where('owner_id' ,'=', $request->user_deals); }else { if (!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')&& !auth()->user()->hasRole('Manager') && !auth()->user()->hasRole('Team Lead')) { $data->where('owner_id', '=', auth()->user()->id); } } } if(!empty($request->get('from') && $request->get('to'))) { $data->whereBetween('assign_to_template_date', [date('Y-m-d H:i:s',strtotime($request->from.'00:00:00')) , date('Y-m-d H:i:s',strtotime($request->to.'23:59:59'))]); }else{ $first =date("Y-m-d H:i:s", strtotime("first day of this month 00:00:00"));; $last = date("Y-m-d H:i:s", strtotime("last day of this month 23:59:59")); $data->whereBetween('assign_to_template_date', [$first, $last]); } if(auth()->user()->employee_country_id==2){ $data->where('production_from' ,'=',auth()->user()->employee_country_id); } $data->where('deal_status','=','1'); $data->where('shipping_status','=','0'); $data->where('production_status','=','0'); $data->where('template_status','=','1'); $data->where('designer_status','=','0'); $data->where('template_complete_status','=','0'); $data->where('designer_work','=','2'); //$data->whereIn('pipeline_stage_id', array('1','2','3','4','11')); /* ->where(function ($q){ $q->where(function ($qs){ $qs->where('bd_pipeline_stage_id','=',4)->where('pipeline_stage_id','=',5); })->orWhere('pipeline_stage_id','=',4); }); */ $data=$data->get(); return $data; } public function Getdesigner(){ return \App\Models\User::where('designer_status','active')->get(); } public function getDeals($request){ $data = Deal::select('*')->with(['deals','client','dealProducts','dealProducts.product','dealProducts.productstyle'])->orderBy('id','desc'); if($request->has('deal_name') ) { $data->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number' ,'like', $request->deal_name.'%')->orWhere(function ($ques) use ($request) { $ques->where('bd_order_number' ,'like', $request->deal_name.'%'); }); }); }); }); }); } if(!empty($request->get('user_deals') )) { $data->where('owner_id', '=', $request->user_deals); }else if(!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')) { if(auth()->user()->hasRole('Team Lead') && auth()->user()->hasRole('Manager')){ $uid = User::where('id',auth()->user()->id)->first(); $data->whereIn('owner_id', explode(',',$uid->team_member)); }elseif( auth()->user()->id==148 ){ $uid = User::where('id',auth()->user()->id)->first(); $data->whereIn('owner_id', explode(',',$uid->team_member)); }else { $data->where('owner_id', '=', auth()->user()->id); } }else{ if(auth()->user()->hasRole('Team Lead') && auth()->user()->hasRole('Manager')){ $uid = User::where('id',auth()->user()->id)->first(); $data->whereIn('owner_id', explode(',',$uid->team_member)); }else{ } } if(!empty($request->get('from') && $request->get('to'))) { $f = $request['from']; $t = $request['to']; $data->where(function ($q) use ($f, $t) { $q->where(function ($qs) use ($f, $t) { $qs->where('bd_open_date', '>=', date($f)) ->where('bd_open_date', '<=', date($t)); // Assuming February 2024 for the example })->orWhereBetween('open_date', [date($f), date($t)]); }); }else{ $first =date("Y-m-d", strtotime("first day of this month")); $last = date("Y-m-d", strtotime("last day of this month")); $data->where(function ($q){ $first =date("Y-m-d", strtotime("first day of this month")); $last = date("Y-m-d", strtotime("last day of this month")); $q->where(function ($qs){ $first =date("Y-m-d", strtotime("first day of this month")); $last = date("Y-m-d", strtotime("last day of this month")); $qs->where('bd_open_date', '>=', $first) ->where('bd_open_date', '<=', $last); // Assuming February 2024 for the example })->orWhereBetween('open_date', [$first, $last]); }); } if(auth()->user()->employee_country_id==2){ $data->where('production_from' ,'=',auth()->user()->employee_country_id); } $data->where('deal_status','=','1'); $data->where('shipping_status','=','0'); $data->where('production_status','=','0'); $data->where('template_status','=','0'); $data->where('designer_status','=','0'); $data->where('designer_work','=','2'); if(auth()->user()->employee_country_id==2){ $data->where('production_from' ,'=',auth()->user()->employee_country_id); } //$data->whereIn('pipeline_stage_id', array('1','2','3','4','11')); /* ->where(function ($q){ $q->where(function ($qs){ $qs->where('bd_pipeline_stage_id','=',4)->where('pipeline_stage_id','=',5); })->orWhere('pipeline_stage_id','=',4); }); */ $data=$data->get(); return $data; } public function completeDesigns($request){ $data = Deal::select('*')->with(['deals','client','dealProducts','template_designer','print_ready_designer','dealProducts.product','dealProducts.productstyle'])->orderBy('id','desc'); if($request->has('deal_name') ) { $data->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number' ,'like', $request->deal_name.'%')->orWhere(function ($ques) use ($request) { $ques->where('bd_order_number' ,'like', $request->deal_name.'%'); }); }); }); }); }); } if(auth()->user()->designer_status =='active') { if(auth()->user()->template_designer_status=='yes') { if (!empty($request->get('user_deals'))) { $data->where('template_designer_id', '=', $request->user_deals); } else { if(!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')&& !auth()->user()->hasRole('Manager') && !auth()->user()->hasRole('Team Lead')) { $data->where('template_designer_id', '=', auth()->user()->id); } } }else { if (!empty($request->get('user_deals'))) { $data->where('designer_id', '=', $request->user_deals); } else { if(!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')&& !auth()->user()->hasRole('Manager') && !auth()->user()->hasRole('Team Lead')) { $data->where('designer_id', '=', auth()->user()->id); } } } }else{ if (!empty($request->get('user_deals'))) { $data->where('owner_id', '=', $request->user_deals); } else { if(!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')&& !auth()->user()->hasRole('Manager') && !auth()->user()->hasRole('Team Lead')) { $data->where('owner_id', '=', auth()->user()->id); } } } if(!empty($request->get('from') && $request->get('to'))) { $data->whereBetween('design_complete_date', [date('Y-m-d H:i:s',strtotime($request->from.'00:00:00')) , date('Y-m-d H:i:s',strtotime($request->to.'23:59:59'))]); }else{ $first =date("Y-m-d H:i:s", strtotime("first day of this month 00:00:00"));; $last = date("Y-m-d H:i:s", strtotime("last day of this month 23:59:59")); $data->whereBetween('design_complete_date', [$first, $last]); } $data->where('deal_status','=','1'); $data->where('designer_status','=','1'); $data->where('designer_work','=','2'); $data->where('design_complete_status','=','1'); if(auth()->user()->employee_country_id==2){ $data->where('production_from' ,'=',auth()->user()->employee_country_id); } return $data->get(); } public function getDesigners(){ $data =\App\Models\User::select('*')->with(['designer_deals'])->where('designer_status','active'); return $data->get(); } public function topseller($request){ /* => function($que) use ($request){ if($request->has('deal_name') ) { $que->where('order_number', 'like', $request->deal_name . '%'); } if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('open_date', [date($request->from) , date($request->to)]); }else{ $first = date("Y-m-d",strtotime("first day of this month")); $last = date("Y-m-d", strtotime("last day of this month")); $que->whereBetween('open_date', [date($first) , date($last)]); } // $que->where('complete_status' ,'=', '0'); } select `deals`.*, `deal_products`.`deal_id` as `pivot_deal_id` from `deals` inner join `deal_products` on `deals`.`id` = `deal_products`.`deal_id` where `lead_source_id` = 0 and `deal_status` = 1 and `deal_products`.`deal_id` in (5, 13, 16, 17, 39, 52, 53, 58, 60, 66, 96, 119, 143, 180, 200, 207, 216, 225, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 252, 256, 257, 258, 259, 260, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 277, 278, 279, 280, 281, 282, 283, 284, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 298, 301, 302, 303, 305, 306, 307, 309, 311, 312, 313, 314, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 364, 365, 366, 367, 368, 370, 371, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, 389, 390, 391, 392, 393, 394, 395, 396, 401, 403, 404, 405, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 427, 428, 429, 430, 432, 433, 434, 435, 436, 437, 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, 476, 478, 479, 480, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 517, 518, 519, 521, 522, 525, 526, 527, 528, 529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 540, 541, 542, 543, 544, 545, 546, 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557, 559, 560, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 574, 575, 576, 582, 587, 588, 589, 590, 591, 592, 593, 594, 595, 596, 597, 598, 599, 600, 601, 608, 609, 610, 611, 613, 614, 615, 616, 617, 618, 619, 620, 621, 622, 623, 624, 625, 626, 629, 630, 631, 632, 633, 634, 635, 636, 637, 638, 639, 640, 641, 642, 643, 644, 645, 646, 647, 648, 649, 650, 651, 652, 653, 654, 655, 657, 658, 659, 660, 661, 662, 663, 664, 665, 666, 667, 670, 675, 676, 677, 678, 679, 680, 683, 686, 687, 688, 689, 690, 692, 694, 695, 696, 697, 698, 699, 700, 701, 702, 703, 704, 705, 706, 707, 708, 709, 710, 711, 712, 713, 714, 715, 718, 719, 720, 721, 722, 723, 724, 725, 726, 727, 728, 730, 731, 732, 733, 734, 735, 736, 737, 738, 739, 741, 742, 743, 744, 745, 746, 747, 748, 750, 751, 752, 753, 754, 755, 756, 757, 758, 759, 760, 761, 763, 767, 768, 769, 770, 771, 772, 773, 774, 775, 776, 777, 778, 779, 781, 794, 795, 796, 799, 800, 801, 802, 803, 804, 805, 806, 807, 808, 809, 810, 811, 812, 813, 814, 815, 816, 817, 818, 819, 820, 821, 823, 824, 825, 826, 827, 828, 829, 831, 832, 833, 834, 835, 836, 837, 838, 839, 840, 842, 845, 846, 847, 848, 849, 850, 851, 852, 853, 854, 855, 856, 857, 858, 859, 860, 861, 862, 863, 864, 865, 866, 867, 868, 869, 870, 871, 872, 873, 874, 875, 876, 877, 879, 880, 881, 882, 883, 884, 885, 886, 887, 888, 889, 890, 891, 892, 893, 894, 895, 896, 897, 898, 899, 900, 901, 902, 903, 904, 905, 906, 907, 909, 910, 911, 912, 914, 915, 916, 917, 918, 919, 920, 921, 922, 923, 924, 925, 927, 929, 930, 931, 932, 933, 934, 935, 936, 937, 938, 939, 940, 941, 942, 943, 944, 946, 947, 948, 949, 951, 952, 954, 955, 957, 960, 961, 962, 963, 964, 965, 966, 967, 968, 969, 970, 971, 972, 973, 974, 975, 976, 977, 978, 979, 980, 981, 982, 983, 984, 985, 986, 987, 989, 990, 991, 992, 993, 994, 995, 996, 997, 998, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024, 1025, 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034, 1035, 1036, 1037, 1038, 1039, 1040, 1041, 1042, 1044, 1046, 1053, 1054, 1055, 1056, 1058, 1059, 1061, 1063, 1064, 1065, 1066, 1068, 1069, 1070, 1072, 1073, 1074, 1075, 1077, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, 1086, 1087, 1089, 1090, 1091, 1092, 1093, 1096, 1097, 1098, 1099, 1100, 1101, 1102, 1103, 1104, 1105, 1106, 1107, 1108, 1109, 1110, 1111, 1112, 1113, 1114, 1115, 1116, 1117, 1118, 1119, 1120, 1121, 1122, 1123, 1124, 1125, 1127, 1128, 1130, 1131, 1132, 1134, 1135, 1136, 1140, 1141, 1142, 1143, 1144, 1145, 1146, 1147, 1148, 1149, 1150, 1151, 1152, 1153, 1154, 1155, 1156, 1157, 1158, 1159, 1160, 1161, 1162, 1163, 1164, 1165, 1166, 1167, 1170, 1171, 1175, 1177, 1178, 1183, 1184, 1185, 1186, 1190, 1191, 1192, 1195, 1199, 1203, 1204, 1206, 1208, 1209, 1210, 1211, 1212, 1213, 1214, 1215, 1216, 1217, 1218, 1219, 1220, 1221, 1222, 1223, 1224, 1225, 1226, 1227, 1228, 1229, 1230, 1231, 1232, 1233, 1234, 1235, 1236, 1237, 1238, 1239, 1240, 1241, 1243, 1245, 1246, 1247, 1248, 1249, 1250, 1251, 1252, 1253, 1254, 1255, 1256, 1259, 1260, 1261, 1262, 1263, 1265, 1266, 1267, 1268, 1269, 1270, 1271, 1272, 1273, 1274, 1275, 1276, 1277, 1278, 1279, 1280, 1281, 1282, 1283, 1285, 1286, 1293, 1303, 1307, 1323, 1324, 1325, 1326, 1327, 1328, 1329, 1330, 1331, 1332, 1333, 1334, 1335, 1336, 1337, 1338, 1339, 1340, 1341, 1343, 1344, 1348, 1353, 1354, 1355, 1356, 1357, 1358, 1359, 1360, 1361, 1362, 1363, 1364, 1365, 1366, 1367, 1368, 1369, 1370, 1371, 1372, 1373, 1374, 1375, 1376, 1377, 1378, 1379, 1380, 1381, 1382, 1383, 1384, 1385, 1386, 1387, 1388, 1389, 1390, 1391, 1392, 1393, 1394, 1395, 1396, 1397, 1398, 1399, 1400, 1401, 1403, 1404, 1405, 1406, 1409, 1410, 1411, 1412, 1413, 1416, 1417, 1418, 1419, 1420, 1421, 1422, 1423, 1424, 1425, 1426, 1427, 1428, 1429, 1430, 1433, 1441, 1442, 1443, 1444, 1446, 1447, 1448, 1449, 1450, 1451, 1452, 1453, 1454, 1457, 1458, 1459, 1460, 1461, 1462, 1463, 1467, 1469, 1470, 1472, 1473, 1476, 1477, 1479, 1480, 1481, 1482, 1483, 1484, 1485, 1486, 1487, 1488, 1490, 1491, 1492, 1493, 1494, 1495, 1496, 1498, 1499, 1500, 1501, 1503, 1504, 1505, 1506, 1507, 1508, 1509, 1510, 1511, 1512, 1517, 1523, 1524, 1525, 1526, 1529, 1533, 1534, 1535, 1536, 1537, 1538, 1540, 1541, 1542, 1543, 1544, 1545, 1546, 1547, 1548, 1549, 1550, 1551, 1552, 1553, 1554, 1555, 1556, 1557, 1558, 1559, 1560, 1561, 1562, 1563, 1564, 1565, 1571, 1572, 1573, 1574, 1575, 1576, 1577, 1578, 1579, 1580, 1581, 1582, 1583, 1584, 1585, 1586, 1587, 1588, 1589, 1590, 1591, 1592, 1593, 1594, 1595, 1596, 1597, 1598, 1599, 1600, 1601, 1602, 1603, 1604, 1606, 1607, 1608, 1609, 1610, 1611, 1612, 1613, 1615, 1616, 1617, 1618, 1619, 1620, 1621, 1622, 1623, 1624, 1625, 1626, 1627, 1628, 1629, 1630, 1631, 1632, 1633, 1634, 1635, 1636, 1637, 1638, 1639, 1640, 1641, 1642, 1644, 1645, 1646, 1647, 1650, 1651, 1652, 1653, 1654, 1655, 1656, 1657, 1658, 1659, 1660, 1661, 1662, 1663, 1664, 1665, 1666, 1667, 1668, 1669, 1670, 1671, 1672, 1673, 1674, 1675, 1678, 1680, 1681, 1682, 1684, 1685, 1687, 1688, 1689, 1690, 1691, 1692, 1693, 1694, 1695, 1696, 1697, 1698, 1699, 1700, 1701, 1702, 1703, 1704, 1705, 1706, 1707, 1708, 1709, 1710, 1711, 1712, 1713, 1714, 1715, 1716, 1717, 1718, 1719, 1720, 1721, 1722, 1723, 1725, 1726, 1727, 1728, 1729, 1730, 1731, 1732, 1733, 1734, 1735, 1736, 1737, 1738, 1739, 1740, 1741, 1743, 1744, 1745, 1746, 1747, 1748, 1749, 1750, 1751, 1752, 1753, 1754, 1755, 1756, 1757, 1758, 1759, 1760, 1761, 1764, 1765, 1766, 1767, 1769, 1770, 1771, 1772, 1773, 1774, 1775, 1776, 1777, 1778, 1779, 1780, 1781, 1782, 1783, 1784, 1785, 1786, 1787, 1788, 1789, 1790, 1791, 1792, 1793, 1794, 1795, 1796, 1797, 1798, 1799, 1800, 1801, 1802, 1803, 1804, 1805, 1806, 1807, 1808, 1809, 1810, 1811, 1812, 1813, 1814, 1815, 1816, 1818, 1819, 1820, 1821, 1822, 1824, 1826, 1828, 1829, 1830, 1832, 1833, 1834, 1835, 1836, 1837, 1838, 1839, 1840, 1841, 1842, 1843, 1844, 1845, 1846, 1847, 1848, 1849, 1850, 1851, 1852, 1853, 1855, 1856, 1857, 1858, 1859, 1860, 1861, 1862, 1864, 1865, 1866, 1867, 1868, 1869, 1870, 1871, 1872, 1873, 1874, 1875, 1876, 1877, 1878, 1879, 1880, 1881, 1882, 1883, 1884, 1885, 1886, 1887, 1888, 1889, 1890, 1891, 1892, 1893, 1894, 1895, 1896, 1897, 1898, 1899, 1901, 1906, 1907, 1908, 1909, 1910, 1911, 1912, 1913, 1914, 1915, 1916, 1917, 1918, 1919, 1920, 1921, 1922, 1923, 1924, 1925, 1926, 1927, 1928, 1929, 1930, 1931, 1932, 1933, 1934, 1935, 1936, 1937, 1938, 1939, 1940, 1941, 1942, 1943, 1948, 1953, 1954, 1955, 1957, 1958, 1960, 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026, 2028, 2029, 2031, 2032, 2033, 2034, 2035, 2036, 2037, 2040, 2041, 2042, 2043, 2044, 2046, 2047, 2049, 2051, 2052, 2053, 2054, 2055, 2057, 2058, 2059, 2060, 2061, 2062, 2063, 2064, 2065, 2066, 2067, 2068, 2069, 2070, 2071, 2072, 2073, 2074, 2075, 2077, 2078, 2079, 2080, 2081, 2083, 2084, 2087, 2088, 2089, 2091, 2092, 2093, 2094, 2095, 2096, 2098, 2099, 2100, 2102, 2103, 2105, 2106, 2107, 2108, 2109, 2110, 2111, 2112, 2113, 2114, 2115, 2116, 2117, 2118, 2119, 2120, 2121, 2122, 2123, 2124, 2125, 2126, 2127, 2128, 2129, 2130, 2131, 2132, 2133, 2134, 2135, 2136, 2137, 2138, 2139, 2141, 2142, 2143, 2144, 2145, 2146, 2147, 2148, 2149, 2150, 2151, 2152, 2153, 2154, 2155, 2156, 2158, 2159, 2160, 2161, 2162, 2163, 2165, 2166, 2167, 2168, 2169, 2170, 2171, 2172, 2173, 2174, 2175, 2176, 2177, 2178, 2179, 2180, 2181, 2182, 2183, 2184, 2185, 2186, 2187, 2188, 2189, 2190, 2191, 2192, 2193, 2194, 2195, 2196, 2197, 2198, 2199, 2200, 2201, 2202, 2203, 2204, 2205, 2206, 2207, 2208, 2209, 2210, 2211, 2212, 2213, 2214, 2215, 2216, 2217, 2218, 2219, 2220, 2221, 2222, 2223, 2224, 2225, 2226, 2227, 2228, 2229, 2230, 2231, 2232, 2233, 2234, 2235, 2236, 2237, 2238, 2239, 2240, 2241, 2242, 2243, 2244, 2245, 2246, 2247, 2248, 2249, 2250, 2253, 2254, 2255, 2256, 2257, 2258, 2259, 2260, 2261, 2262, 2263, 2264, 2265, 2266, 2267, 2268, 2269, 2270, 2271, 2272, 2273, 2274, 2275, 2276, 2277, 2278, 2279, 2280, 2281, 2282, 2283, 2284, 2285, 2286, 2287, 2288, 2289, 2290, 2291, 2295, 2296, 2297, 2298, 2299, 2300, 2301, 2302, 2303, 2304, 2305, 2306, 2307, 2308, 2309, 2310, 2311, 2312, 2313, 2314, 2315, 2316, 2317, 2318, 2319, 2320, 2321, 2322, 2323, 2324, 2325, 2326, 2327, 2328, 2329, 2330, 2331, 2332, 2333, 2334, 2335, 2336, 2337, 2338, 2339, 2340, 2341, 2342, 2343, 2344, 2345, 2346, 2347, 2348, 2349, 2350, 2351, 2354, 2355, 2356, 2357, 2358, 2359, 2360, 2361, 2362, 2363, 2365, 2366, 2367, 2368, 2369, 2370, 2371, 2372, 2374, 2375, 2376, 2378, 2381, 2382, 2383, 2384, 2385, 2386, 2387, 2388, 2389, 2390, 2391, 2392, 2393, 2394, 2395, 2396, 2397, 2398, 2399, 2400, 2401, 2402, 2403, 2404, 2405, 2407, 2408, 2409, 2410, 2411, 2412, 2413, 2414, 2415, 2416, 2417, 2418, 2419, 2420, 2421, 2422, 2423, 2424, 2425, 2426, 2427, 2428, 2429, 2430, 2431, 2432, 2433, 2434, 2435, 2436, 2437, 2438, 2439, 2440, 2441, 2442, 2443, 2444, 2445, 2446, 2449, 2450, 2451, 2452, 2453, 2454, 2455, 2456, 2457, 2458, 2459, 2460, 2461, 2462, 2463, 2464, 2465, 2466, 2467, 2468, 2469, 2470, 2471, 2472, 2473, 2474, 2475, 2476, 2477, 2478, 2479, 2480, 2481, 2482, 2483, 2485, 2489, 2490, 2491, 2492, 2493, 2494, 2495, 2496, 2497, 2498, 2499, 2500, 2501, 2502, 2503, 2505, 2506, 2507, 2508, 2509, 2510, 2511, 2512, 2513, 2514, 2515, 2516, 2517, 2518, 2519, 2520, 2521, 2522, 2523, 2524, 2525, 2526, 2527, 2528, 2529, 2530, 2531, 2532, 2533, 2534, 2535, 2536, 2537, 2538, 2539, 2540, 2541, 2542, 2543, 2544, 2545, 2546, 2547, 2548, 2549, 2550, 2551, 2552, 2553, 2554, 2555, 2556, 2557, 2558, 2560, 2561, 2562, 2563, 2564, 2565, 2566, 2567, 2568, 2569, 2570, 2571, 2572, 2573, 2574, 2575, 2576, 2577, 2578, 2579, 2580, 2581, 2582, 2583, 2584, 2585, 2586, 2587, 2588, 2589, 2590, 2591, 2592, 2593, 2594, 2595, 2596, 2598, 2599, 2600, 2601, 2602, 2603, 2604, 2605, 2606, 2607, 2608, 2609, 2610, 2611, 2612, 2613, 2614, 2615, 2616, 2617, 2618, 2619, 2620, 2621, 2622, 2623, 2624, 2625, 2626, 2627, 2628, 2629, 2630, 2631, 2632, 2633, 2634, 2635, 2636, 2637, 2638, 2639, 2640, 2641, 2642, 2643, 2644, 2645, 2646, 2647, 2648, 2649, 2650, 2651, 2652, 2653, 2654, 2655, 2656, 2657, 2658, 2659, 2660, 2661, 2662, 2665, 2666, 2667, 2668, 2669, 2670, 2671, 2672, 2673, 2674, 2675, 2676, 2677, 2678, 2680, 2681, 2682, 2683, 2688, 2689, 2690, 2691, 2692, 2693, 2694, 2695, 2696, 2697, 2698, 2699, 2701, 2702, 2711, 2712, 2713, 2714, 2715, 2718, 2719, 2720, 2721, 2722, 2723, 2724, 2725, 2726, 2727, 2728, 2729, 2730, 2731, 2733, 2734, 2735, 2736, 2737, 2738, 2739, 2740, 2741, 2742, 2743, 2744, 2745, 2746, 2747, 2748, 2750, 2751, 2752, 2753, 2754, 2755, 2756, 2757, 2758, 2759, 2760, 2761, 2762, 2763, 2764, 2765, 2766, 2767, 2768, 2769, 2770, 2771, 2772, 2773, 2774, 2775, 2776, 2777, 2778, 2779, 2780, 2781, 2782, 2783, 2784, 2785, 2786, 2787, 2789, 2790, 2791, 2792, 2793, 2794, 2795, 2796, 2797, 2798, 2800, 2801, 2802, 2803, 2804, 2805, 2806, 2807, 2808, 2809, 2810, 2811, 2813, 2814, 2815, 2816, 2817, 2818, 2819, 2820, 2821, 2822, 2823, 2824, 2826, 2827, 2828, 2832, 2833, 2834, 2835, 2836, 2837, 2838, 2840, 2841, 2842, 2843, 2845, 2846, 2847, 2848, 2849, 2850, 2851, 2852, 2854, 2855, 2856, 2857, 2858, 2859, 2860, 2861, 2862, 2863, 2864, 2865, 2866, 2867, 2868, 2869, 2870, 2871, 2872, 2874, 2875, 2876, 2877, 2878, 2879, 2880, 2881, 2882, 2883, 2884, 2885, 2886, 2888, 2889, 2890, 2891, 2892, 2897, 2898, 2899, 2900, 2901, 2902, 2904, 2905, 2906, 2907, 2908, 2909, 2910, 2911, 2912, 2913, 2914, 2915, 2916, 2917, 2918, 2919, 2920, 2921, 2922, 2923, 2924, 2925, 2926, 2927, 2928, 2930, 2931, 2932, 2933, 2934, 2935, 2936, 2937, 2938, 2939, 2940, 2941, 2942, 2943, 2944, 2945, 2946, 2951, 2952, 2953, 2954, 2955, 2956, 2957, 2958, 2959, 2961, 2962, 2963, 2964, 2965, 2966, 2967, 2969, 2970, 2971, 2972, 2973, 2974, 2975, 2976, 2977, 2978, 2980, 2981, 2982, 2983, 2984, 2985, 2986, 2987, 2988, 2989, 2990, 2991, 2992, 2993, 2995, 2996, 2997, 2998, 2999, 3000, 3001, 3002, 3003, 3004, 3006, 3007, 3008, 3009, 3010, 3011, 3012, 3013, 3015, 3016, 3017, 3018, 3019, 3020, 3021, 3022, 3023, 3024, 3025, 3026, 3027, 3028, 3029, 3030, 3031, 3032, 3033, 3034, 3035, 3036, 3037, 3038, 3039, 3040, 3042, 3043, 3044, 3046, 3047, 3048, 3049, 3052, 3053, 3054, 3056, 3057, 3058, 3059, 3060, 3061, 3065, 3067, 3068, 3069, 3070, 3071, 3073, 3077, 3078, 3079, 3080, 3082, 3083, 3084, 3085, 3086, 3087, 3088, 3089, 3090, 3091, 3092, 3093, 3094, 3095, 3096, 3097, 3098, 3099, 3100, 3101, 3102, 3103, 3104, 3105, 3106, 3107, 3108, 3109, 3110, 3111, 3112, 3113, 3114, 3115, 3116, 3117, 3119, 3120, 3121, 3122, 3124, 3125, 3126, 3127, 3128, 3129, 3130, 3131, 3132, 3133, 3134, 3135, 3136, 3137, 3138, 3142, 3143, 3144, 3145, 3146, 3147, 3148, 3149, 3150, 3151, 3152, 3153, 3154, 3155, 3156, 3157, 3158, 3160, 3162, 3163, 3164, 3165, 3166, 3167, 3168, 3169, 3170, 3171, 3172, 3173, 3174, 3175, 3176, 3177, 3178, 3179, 3180, 3181, 3182, 3183, 3184, 3185, 3186, 3187, 3188, 3189, 3190, 3191, 3192, 3193, 3194, 3195, 3196, 3197, 3198, 3199, 3200, 3201, 3202, 3203, 3204, 3205, 3206, 3207, 3208, 3209, 3210, 3211, 3212, 3213, 3214, 3215, 3216, 3217, 3218, 3219, 3220, 3221, 3222, 3223, 3225, 3227, 3228, 3229, 3230, 3231, 3232, 3233, 3234, 3235, 3236, 3238, 3239, 3240, 3241, 3242, 3245, 3246, 3247, 3248, 3249, 3250, 3251, 3252, 3253, 3254, 3256, 3257, 3258, 3259, 3260, 3261, 3262, 3263, 3264, 3267, 3269, 3270, 3271, 3272, 3273, 3275, 3276, 3277, 3279, 3281, 3285, 3286, 3287, 3288, 3289, 3291, 3292, 3293, 3294, 3295, 3296, 3297, 3298, 3299, 3300, 3301, 3302, 3303, 3304, 3305, 3306, 3307, 3309, 3311, 3312, 3313, 3314, 3315, 3316, 3317, 3318, 3319, 3320, 3321, 3322, 3323, 3324, 3326, 3327, 3328, 3329, 3330, 3331, 3332, 3334, 3335, 3336, 3337, 3339, 3340, 3341, 3342, 3343, 3344, 3345, 3346, 3347, 3348, 3349, 3350, 3351, 3352, 3353, 3355, 3356, 3357, 3358, 3359, 3360, 3361, 3362, 3363, 3364, 3365, 3367, 3368, 3369, 3370, 3371, 3372, 3373, 3374, 3375, 3376, 3377, 3378, 3379, 3380, 3381, 3382, 3383, 3384, 3385, 3386, 3388, 3390, 3393, 3394, 3395, 3396, 3397, 3398, 3399, 3400, 3401, 3402, 3403, 3404, 3405, 3410, 3411, 3412, 3413, 3414, 3415, 3416, 3417, 3418, 3419, 3420, 3421, 3422, 3424, 3425, 3428, 3429, 3430, 3432, 3433, 3434, 3435, 3437, 3438, 3439, 3440, 3441, 3442, 3443, 3445, 3448, 3449, 3450, 3451, 3452, 3453, 3454, 3455, 3456, 3458, 3459, 3461, 3462, 3463, 3464, 3465, 3466, 3468, 3469, 3470, 3471, 3472, 3473, 3474, 3475, 3476, 3477, 3478, 3479, 3480, 3481, 3482, 3483, 3484, 3485, 3486, 3487, 3488, 3489, 3490, 3491, 3492, 3493, 3494, 3495, 3496, 3497, 3498, 3499, 3500, 3501, 3502, 3504, 3505, 3506, 3507, 3508, 3509, 3510, 3511, 3512, 3513, 3514, 3515, 3516, 3517, 3518, 3519, 3520, 3521, 3522, 3523, 3524, 3525, 3526, 3527, 3528, 3529, 3530, 3531, 3532, 3533, 3534, 3535, 3536, 3537, 3538, 3539, 3540, 3541, 3542, 3543, 3544, 3545, 3547, 3549, 3550, 3551, 3552, 3553, 3554, 3555, 3556, 3557, 3558, 3559, 3560, 3561, 3562, 3563, 3564, 3565, 3566, 3567, 3568, 3569, 3570, 3571, 3572, 3573, 3574, 3575, 3578, 3579, 3581, 3582, 3583, 3586, 3587, 3588, 3589, 3590, 3591, 3592, 3593, 3594, 3595, 3596, 3597, 3598, 3599, 3606, 3607, 3608, 3609, 3610, 3611, 3612, 3613, 3614, 3615, 3616, 3618, 3619, 3621, 3622, 3623, 3624, 3625, 3631, 3632, 3633, 3634, 3635, 3636, 3639, 3641, 3642, 3643, 3644, 3645, 3647, 3648, 3649, 3650, 3651, 3652, 3653, 3654, 3657, 3658, 3660, 3661, 3662, 3663, 3664, 3665, 3667, 3668, 3669, 3670, 3671, 3672, 3673, 3674, 3675, 3676, 3677, 3678, 3679, 3680, 3681, 3682, 3683, 3684, 3685, 3686, 3687, 3688, 3689, 3690, 3691, 3692, 3693, 3694, 3695, 3696, 3697, 3698, 3699, 3700, 3701, 3702, 3703, 3704, 3705, 3709, 3710, 3712, 3713, 3716, 3717, 3718, 3719, 3721, 3723, 3724, 3725, 3726, 3727, 3728, 3729, 3730, 3731, 3732, 3733, 3734, 3736, 3737, 3740, 3741, 3742, 3743, 3744, 3745, 3746, 3747, 3748, 3749, 3750, 3751, 3752, 3753, 3754, 3755, 3756, 3757, 3759, 3764, 3765, 3766, 3767, 3768, 3769, 3770, 3771, 3772, 3774, 3777, 3779, 3780, 3781, 3782, 3783, 3784, 3785, 3786, 3787, 3788, 3789, 3790, 3791, 3794, 3795, 3796, 3797, 3798, 3800, 3801, 3802, 3803, 3804, 3805, 3806, 3807, 3808, 3809, 3810, 3811, 3813, 3814, 3815, 3816, 3817, 3818, 3819, 3821, 3822, 3824, 3825, 3826, 3827, 3828, 3829, 3830, 3831, 3833, 3834, 3835, 3836, 3837, 3838, 3840, 3841, 3842, 3843, 3844, 3845, 3846, 3847, 3848, 3849, 3850, 3852, 3853, 3854, 3855, 3857, 3860, 3861, 3863, 3864, 3865, 3866, 3867, 3868, 3870, 3871, 3872, 3875, 3877, 3878, 3881, 3882, 3883, 3884, 3885, 3886, 3888, 3889, 3890, 3891, 3892, 3893, 3894, 3895, 3898, 3899, 3900, 3902, 3903, 3904, 3905, 3906, 3907, 3908, 3909, 3913, 3914, 3915, 3917, 3918, 3921, 3923, 3924, 3925, 3926, 3927, 3928, 3929, 3930, 3931, 3932, 3933, 3934, 3935, 3936, 3937, 3938, 3939, 3940, 3941, 3942, 3943, 3944, 3946, 3947, 3948, 3949, 3950, 3951, 3952, 3954, 3955, 3956, 3957, 3958, 3959, 3960, 3961, 3962, 3963, 3964, 3965, 3966, 3967, 3968, 3969, 3970, 3971, 3972, 3973, 3974, 3975, 3976, 3977, 3978, 3979, 3980, 3981, 3982, 3983, 3984, 3985, 3986, 3988, 3989, 3990, 3991, 3992, 3994, 3995, 3996, 3997, 3998, 3999, 4000, 4001, 4002, 4003, 4004, 4005, 4006, 4007, 4008, 4009, 4010, 4011, 4013, 4014, 4030, 4032, 4033, 4034, 4035, 4036, 4037, 4038, 4039, 4040, 4041, 4042, 4043, 4044, 4045, 4046, 4048, 4049, 4050, 4051, 4052, 4053, 4054, 4055, 4056, 4057, 4058, 4059, 4060, 4061, 4062, 4063, 4064, 4065, 4066, 4067, 4068, 4069, 4070, 4071, 4072, 4073, 4074, 4075, 4077, 4078, 4079, 4080, 4081, 4082, 4083, 4084, 4085, 4086, 4087, 4088, 4090, 4091, 4093, 4094, 4095, 4096, 4097, 4098, 4099, 4100, 4101, 4104, 4105, 4106, 4107, 4108, 4109, 4110, 4111, 4112, 4113, 4114, 4115, 4116, 4117, 4118, 4119, 4120, 4121, 4123, 4124, 4125, 4126, 4127, 4128, 4129, 4130, 4131, 4132, 4133, 4134, 4135, 4136, 4137, 4138, 4139, 4140, 4141, 4142, 4143, 4144, 4145, 4146, 4147, 4148, 4149, 4150, 4151, 4152, 4153, 4154, 4155, 4156, 4157, 4158, 4159, 4160, 4161, 4162, 4163, 4164, 4165, 4166, 4167, 4168, 4169, 4170, 4171, 4172, 4173, 4174, 4176, 4177, 4178, 4179, 4180, 4181, 4182, 4183, 4184, 4185, 4189, 4190, 4191, 4192, 4193, 4194, 4195, 4196, 4197, 4198, 4199, 4200, 4201, 4202, 4203, 4204, 4205, 4206, 4207, 4209, 4210, 4211, 4212, 4213, 4214, 4215, 4216, 4217, 4218, 4219, 4220, 4221, 4222, 4223, 4224, 4226, 4227, 4228, 4229, 4230, 4231, 4232, 4233, 4234, 4235, 4236, 4237, 4238, 4239, 4240, 4241, 4242, 4243, 4244, 4245, 4246, 4247, 4248, 4249, 4250, 4251, 4252, 4253, 4254, 4255, 4256, 4257, 4258, 4259, 4260, 4261, 4262, 4263, 4264, 4265, 4266, 4267, 4268, 4269, 4270, 4271, 4272, 4273, 4274, 4275, 4276, 4277, 4278, 4279, 4280, 4281, 4282, 4283, 4284, 4285, 4286, 4287, 4288, 4289, 4290, 4291, 4292, 4293, 4294, 4295, 4296, 4297, 4298, 4299, 4300, 4301, 4302, 4303, 4304, 4305, 4306, 4307, 4308, 4309, 4310, 4311, 4312, 4313, 4314, 4315, 4316, 4317, 4318, 4319, 4320, 4321, 4322, 4323, 4324, 4325, 4326, 4327, 4328, 4329, 4331, 4332, 4333, 4334, 4335, 4336, 4337, 4338, 4339, 4340, 4341, 4342, 4343, 4344, 4345, 4346, 4347, 4348, 4349, 4350, 4351, 4352, 4353, 4354, 4355, 4356, 4357, 4358, 4360, 4361, 4362, 4363, 4364, 4365, 4366, 4367, 4368, 4369, 4370, 4371, 4372, 4373) and `open_dates` between 2022-08-01 and 2022-08-31 and `deals`.`deleted_at` is null */ $data = Product::select('*')->with(['dealporducts'=> function($que) use ($request){ if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('created_at', [date($request->from) , date($request->to)]); }else{ $first = date("Y-m-d",strtotime("first day of this month")); $last = date("Y-m-d", strtotime("last day of this month")); $que->whereBetween('created_at', [date($first) , date($last)]); } /// $que->groupBy('deal_id'); },'dealporducts.chat_deals'=> function($que) use ($request){ if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('open_datew', [date($request->from) , date($request->to)]); }else{ $first = date("Y-m-d",strtotime("first day of this month")); $last = date("Y-m-d", strtotime("last day of this month")); $que->whereBetween('open_date', [date($first) , date($last)]); } // $que->where('complete_status' ,'=', '0'); },'dealporducts.custom_quote_deals'=> function($que) use ($request){ if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('open_date', [date($request->from) , date($request->to)]); }else{ $first = date("Y-m-d",strtotime("first day of this month")); $last = date("Y-m-d", strtotime("last day of this month")); $que->whereBetween('open_date', [date($first) , date($last)]); } // $que->where('complete_status' ,'=', '0'); },'dealporducts.reference_deals'=> function($que) use ($request){ if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('open_date', [date($request->from) , date($request->to)]); }else{ $first = date("Y-m-d",strtotime("first day of this month")); $last = date("Y-m-d", strtotime("last day of this month")); $que->whereBetween('open_date', [date($first) , date($last)]); } // $que->where('complete_status' ,'=', '0'); },'dealporducts.email_deals'=> function($que) use ($request){ if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('open_date', [date($request->from) , date($request->to)]); }else{ $first = date("Y-m-d",strtotime("first day of this month")); $last = date("Y-m-d", strtotime("last day of this month")); $que->whereBetween('open_date', [date($first) , date($last)]); } // $que->where('complete_status' ,'=', '0'); } ,'dealporducts.call_deals'=> function($que) use ($request){ if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('open_date', [date($request->from) , date($request->to)]); }else{ $first = date("Y-m-d",strtotime("first day of this month")); $last = date("Y-m-d", strtotime("last day of this month")); $que->whereBetween('open_date', [date($first) , date($last)]); } // $que->where('complete_status' ,'=', '0'); },'dealporducts.organic_deals'=> function($que) use ($request){ if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('open_date', [date($request->from) , date($request->to)]); }else{ $first = date("Y-m-d",strtotime("first day of this month")); $last = date("Y-m-d", strtotime("last day of this month")); $que->whereBetween('open_date', [date($first) , date($last)]); } // $que->where('complete_status' ,'=', '0'); },'dealporducts.social_deals'=> function($que) use ($request){ if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('open_date', [date($request->from) , date($request->to)]); }else{ $first = date("Y-m-d",strtotime("first day of this month")); $last = date("Y-m-d", strtotime("last day of this month")); $que->whereBetween('open_date', [date($first) , date($last)]); } // $que->where('complete_status' ,'=', '0'); },'dealporducts.ppc_deals'=> function($que) use ($request){ if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('open_date', [date($request->from) , date($request->to)]); }else{ $first = date("Y-m-d",strtotime("first day of this month")); $last = date("Y-m-d", strtotime("last day of this month")); $que->whereBetween('open_date', [date($first) , date($last)]); } // $que->where('complete_status' ,'=', '0'); }]); $data->where('type','product'); $data->orderBy('name','asc'); return $data->get(); } public function UpdateDesigner($request,$id){ $deal= Deal::where('id', $id)->first(); if($deal['template_status']==0) { if($request['pid']==2){ Deal::where('id', $id)->update(['template_status' => '1', 'template_designer_id' => $request['uid'], 'assign_to_template_date' => date( 'Y-m-d H:i:s',strtotime($request['date']) ),'designer_status' => '0', 'designer_id' => '', 'design_assign_date' => '']); }else{ Deal::where('id', $id)->update(['template_status' => '0', 'template_designer_id' => '', 'assign_to_template_date' => '','designer_status' => '0', 'designer_id' => '', 'design_assign_date' => '']); } }else if($deal['template_status']==1){ if($request['pid']==4) { Deal::where('id', $id)->update(['designer_status' => '1', 'designer_id' => $request['uid'], 'design_assign_date' => date( 'Y-m-d H:i:s',strtotime($request['date']) ) ]); }elseif($request['pid']==2){ Deal::where('id', $id)->update(['template_status' => '1','template_complete_status'=>0, 'template_designer_id' => $request['uid'], 'assign_to_template_date' => date( 'Y-m-d H:i:s',strtotime($request['date']) ),'designer_status' => '0', 'designer_id' => '', 'design_assign_date' => '']); }elseif($request['pid']==3){ Deal::where('id', $id)->update([ 'template_complete_status' => 1, 'template_complete_date' => date( 'Y-m-d H:i:s',strtotime($request['date']) ),'designer_status' => '0', 'designer_id' => '', 'design_assign_date' => '']); }elseif($request['pid']==5){ Deal::where('id', $id)->update(['design_complete_status' => '1', 'design_complete_date' => date( 'Y-m-d H:i:s',strtotime($request['date']) ),'designer_status'=>1]); }else{ Deal::where('id', $id)->update(['template_status' => '0', 'template_designer_id' => '', 'assign_to_template_date' => '','designer_status' => 0,'designer_work' => 2, 'designer_id' => '', 'design_assign_date' => '','design_complete_status'=>0, 'design_complete_date' => '','template_complete_status'=>0]); } } return $deal; } public function getDesignerDeals($request){ $data = Deal::select('*')->with(['deals','client','dealProducts','dealProducts.product','dealProducts.productstyle'])->orderBy('open_date','desc'); if($request->has('deal_name') ) { $data->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number' ,'like', $request->deal_name.'%')->orWhere(function ($ques) use ($request) { $ques->where('bd_order_number' ,'like', $request->deal_name.'%'); }); }); }); }); }); } if(!empty($request->get('user_deals') )) { $data->where('owner_id', '=', $request->user_deals); }else if(!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')) { if(auth()->user()->hasRole('Team Lead') && auth()->user()->hasRole('Manager')){ $uid = User::where('id',auth()->user()->id)->first(); $data->whereIn('owner_id', explode(',',$uid->team_member)); }elseif( auth()->user()->id==148 ){ $uid = User::where('id',auth()->user()->id)->first(); $data->whereIn('owner_id', explode(',',$uid->team_member)); }else { $data->where('owner_id', '=', auth()->user()->id); } }else{ if(auth()->user()->hasRole('Team Lead') && auth()->user()->hasRole('Manager')){ $uid = User::where('id',auth()->user()->id)->first(); $data->whereIn('owner_id', explode(',',$uid->team_member)); }else{ } } if(!empty($request->get('from') && $request->get('to'))) { $f = $request['from']; $t = $request['to']; $data->where(function ($q) use ($f, $t) { $q->where(function ($qs) use ($f, $t) { $qs->where('bd_close_date', '>=', date($f)) ->where('bd_close_date', '<=', date($t)); // Assuming February 2024 for the example })->orWhereBetween('close_date', [date($f), date($t)]); }); }else{ $first =date("Y-m-d", strtotime("first day of this month")); $last = date("Y-m-d", strtotime("last day of this month")); $data->where(function ($q){ $first =date("Y-m-d", strtotime("first day of this month")); $last = date("Y-m-d", strtotime("last day of this month")); $q->where(function ($qs){ $first =date("Y-m-d", strtotime("first day of this month")); $last = date("Y-m-d", strtotime("last day of this month")); $qs->where('bd_close_date', '>=', $first) ->where('bd_close_date', '<=', $last); // Assuming February 2024 for the example })->orWhereBetween('close_date', [$first, $last]); }); } $data->where('deal_status','=','1'); $data->where('shipping_status','=','0'); $data->where('production_status','=','0'); $data->where('designer_status','=','1')->where(function ($q){ $q->where(function ($qs){ $qs->where('bd_pipeline_stage_id','=',4); })->orWhere('pipeline_stage_id','=',4); }); if(auth()->user()->employee_country_id==2){ $data->where('production_from' ,'=',auth()->user()->employee_country_id); } $data=$data->get(); return $data; } public function ShippingDeals($request){ $data = Deal::select('*')->with(['deals','client','tracking_details','dealProducts','dealProducts.product','dealProducts.productstyle'])->orderBy('open_date','desc'); if($request->has('deal_name') ) { $data->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number' ,'like', $request->deal_name.'%')->orWhere(function ($ques) use ($request) { $ques->where('bd_order_number' ,'like', $request->deal_name.'%'); }); }); }); }); }); } if(!empty($request->get('user_deals') )) { $data->where('owner_id', '=', $request->user_deals); }else if( !auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin') && !auth()->user()->hasRole('Production and Shipping') ) { if(auth()->user()->hasRole('Team Lead') && auth()->user()->hasRole('Manager') && auth()->user()->hasRole('Manager')){ $uid = User::where('id',auth()->user()->id)->first(); $data->whereIn('owner_id', explode(',',$uid->team_member)); }elseif( auth()->user()->id==148 ){ $uid = User::where('id',auth()->user()->id)->first(); $data->whereIn('owner_id', explode(',',$uid->team_member)); }else { $data->where('owner_id', '=', auth()->user()->id); } }else{ if(auth()->user()->hasRole('Team Lead') && auth()->user()->hasRole('Manager')){ $uid = User::where('id',auth()->user()->id)->first(); $data->whereIn('owner_id', explode(',',$uid->team_member)); }else{ } } if(auth()->user()->employee_country_id==2){ $data->where('production_from' ,'=',auth()->user()->employee_country_id); } if(!empty($request->get('from') && $request->get('to'))) { $data->whereHas('production', function ($queryu) use ($request) { $f = $request['from']; $t = $request['to']; $queryu->where(function ($q) use ($f, $t) { $q->where(function ($qs) use ($f, $t) { $qs->where('receiving_date', '>=', date($f)) ->where('receiving_date', '<=', date($t)); // Assuming February 2024 for the example })->orWhereBetween('receiving_date', [date($f), date($t)]); }); }); }else{ $data->whereHas('production', function ($queryu) use ($request) { $first =date("Y-m-d", strtotime("first day of this month"));; $last = date("Y-m-d", strtotime("last day of this month")); // $queryu->whereBetween('receiving_date', [date($first) , date($last)]); $queryu->where(function ($qs){ $first =date("Y-m-d", strtotime("first day of this month"));; $last = date("Y-m-d", strtotime("last day of this month")); $qs->where('receiving_date', '>=', $first) ->where('receiving_date', '<=', $last); // Assuming February 2024 for the example })->orWhereBetween('receiving_date', [$first, $last]); }); } $data->where('deal_status','=','1'); $data->where('shipping_status','=','1'); $data->where('delivery_status','=','0')->where(function ($q){ $q->where(function ($qs){ $qs->where('bd_pipeline_stage_id','=',4); })->orWhere('pipeline_stage_id','=',4); }); $data->orderBy('id','desc'); $data=$data->get(); return $data; } public function getCourierCount($request) { if (!empty($request->get('from') || $request->get('to') || $request->get('user_deals') || $request->get('deal_name'))) { $data['total_leads'] = Tracking::select('*')->with(['deals'=>function($que) use ($request){ if(!empty($request['deal_name'])) { $que['total_leads']->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number','like',$request->deal_name. '%'); }); }); }); }); } }, 'deals.client']); if (!empty($request['user_deals'])) { $data['total_leads']->where('courier_id', '=', $request->user_deals); } else { $data['total_leads']->whereIN('courier_id', array(1, 2)); } if (!empty($request->get('from') && $request->get('to'))) { $data['total_leads']->whereBetween('shipping_date', [date($request->from), date($request->to)]); } else { $first = date("Y-m-d", strtotime("first day of this month"));; $last = date("Y-m-d", strtotime("last day of this month")); $data['total_leads']->whereBetween('shipping_date', [date($first), date($last)]); } $data['total_leads'] = $data['total_leads']->count(); }else { $data['total_leads'] = Tracking::select('*')->with(['deals']); if (!empty($request['deal_name'])) { $data['total_leads']->whereHas('deals.client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number', 'like', $request->deal_name . '%'); }); }); }); }); } if (!empty($request['user_deals'])) { $data['total_leads']->where('courier_id', '=', $request->user_deals); } else { $data['total_leads']->whereIN('courier_id', array(1, 2)); } $first = date("Y-m-d", strtotime("first day of this month"));; $last = date("Y-m-d", strtotime("last day of this month")); $data['total_leads']->whereBetween('shipping_date', [date($first), date($last)]); $data['total_leads'] = $data['total_leads']->count(); } if ($request->get('user_deals')==2 || $request->get('user_deals')==''){ if (!empty($request->get('from') || $request->get('to') || $request->get('user_deals') || $request->get('deal_name'))) { $data['fedexs'] = Tracking::select('*')->with(['deals', 'deals.client']); if (!empty($request['deal_name'])) { $data['fedexs']->whereHas('deals.client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number', 'like', $request->deal_name . '%'); }); }); }); }); } $data['fedexs']->where('courier_id', '=', 2); if (!empty($request->get('from') && $request->get('to'))) { $data['fedexs']->whereBetween('shipping_date', [date($request->from), date($request->to)]); } else { $first = date("Y-m-d", strtotime("first day of this month"));; $last = date("Y-m-d", strtotime("last day of this month")); $data['fedexs']->whereBetween('shipping_date', [date($first), date($last)]); } $data['fedex'] = $data['fedexs']->count(); $data['fedexs'] = $data['fedexs']->count() * 100 / ($data['total_leads'] ?: 1); } else { $data['fedexs'] = Tracking::select('*')->with(['deals']); if (!empty($request['user_deals'])) { $data['fedexs']->where('courier_id', '=', 2); } else { $data['fedexs']->where('courier_id', '=', 2); } $first = date("Y-m-d", strtotime("first day of this month"));; $last = date("Y-m-d", strtotime("last day of this month")); $data['fedexs']->whereBetween('shipping_date', [date($first), date($last)]); $data['fedex'] = $data['fedexs']->count(); $data['fedexs'] = $data['fedexs']->count() * 100 / ($data['total_leads'] ?: 1); } }else{ $data['fedex'] = 0; $data['fedexs'] =0; $data['usps'] =0; } if ($request->get('user_deals')==1 || $request->get('user_deals')==''){ if (!empty($request->get('from') || $request->get('to') || $request->get('user_deals') || $request->get('deal_name'))) { $data['usps']= Tracking::select('*')->with(['deals','deals.client']); if(!empty($request['deal_name'] )) { $data['usps']->whereHas('deals.client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number' ,'like', $request->deal_name.'%'); }); }); }); }); } $data['usps']->where('courier_id' ,'=', 3); if(!empty($request->get('from') && $request->get('to'))) { $data['usps']->whereBetween('shipping_date', [date($request->from) , date($request->to)]); }else{ $first = date("Y-m-d", strtotime("first day of this month"));; $last = date("Y-m-d", strtotime("last day of this month")); $data['usps']->whereBetween('shipping_date', [date($first) , date($last)]); } $data['uspss'] = $data['usps']->count(); $data['usps'] = $data['usps']->count()* 100 / ( $data['total_leads'] ?: 1); }else{ $data['usps']= Tracking::select('*')->with(['deals']) ; if($request['user_deals'] == 1) { $data['usps']->where('courier_id' ,'=', $request->user_deals); }else{ $data['usps']->where('courier_id' ,'=', 1); } $first = date("Y-m-d", strtotime("first day of this month"));; $last = date("Y-m-d", strtotime("last day of this month")); $data['usps']->whereBetween('shipping_date', [date($first) , date($last)]); $data['uspss'] = $data['usps']->count(); $data['usps'] = $data['usps']->count()* 100 / ( $data['total_leads'] ?: 1); } }else{ $data['dhls']=0; $data['dhl'] =0; $data['uspss'] =0; $data['usps'] =0; } if ($request->get('user_deals')==1 || $request->get('user_deals')==''){ if (!empty($request->get('from') || $request->get('to') || $request->get('user_deals') || $request->get('deal_name'))) { $data['dhl']= Tracking::select('*')->with(['deals','deals.client']); if(!empty($request['deal_name'] )) { $data['dhl']->whereHas('deals.client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number' ,'like', $request->deal_name.'%'); }); }); }); }); } $data['dhl']->where('courier_id' ,'=', 1); if(!empty($request->get('from') && $request->get('to'))) { $data['dhl']->whereBetween('shipping_date', [date($request->from) , date($request->to)]); }else{ $first = date("Y-m-d", strtotime("first day of this month"));; $last = date("Y-m-d", strtotime("last day of this month")); $data['dhl']->whereBetween('shipping_date', [date($first) , date($last)]); } $data['dhls'] = $data['dhl']->count(); $data['dhl'] = $data['dhl']->count()* 100 / ( $data['total_leads'] ?: 1); }else{ $data['dhl']= Tracking::select('*')->with(['deals']) ; if($request['user_deals'] == 1) { $data['dhl']->where('courier_id' ,'=', $request->user_deals); }else{ $data['dhl']->where('courier_id' ,'=', 1); } $first = date("Y-m-d", strtotime("first day of this month"));; $last = date("Y-m-d", strtotime("last day of this month")); $data['dhl']->whereBetween('shipping_date', [date($first) , date($last)]); $data['dhls'] = $data['dhl']->count(); $data['dhl'] = $data['dhl']->count()* 100 / ( $data['total_leads'] ?: 1); } }else{ $data['dhls']=0; $data['dhl'] =0; $data['usps'] =0; } return $data; } public function getCompleteDeals($request){ $courier = Courier::with([ 'courier_deals' => function($query) use ($request) { if(auth()->user()->id == 148) { $uid = User::findOrFail(auth()->user()->id); $query->whereIn('owner_id', explode(',', $uid->team_member)); } if($request->has('deal_name') ) { $query->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number' ,'like', $request->deal_name.'%')->orWhere(function ($ques) use ($request) { $ques->where('bd_order_number' ,'like', $request->deal_name.'%'); }); }); }); }); }); } if(!empty($request->from) && !empty($request->to)) { $query->whereHas('tracking', function ($trackingQuery) use ($request) { $trackingQuery->whereBetween('shipping_date', [$request->from, $request->to]); }); } else { $query->whereHas('tracking', function ($trackingQuery) { $trackingQuery->whereBetween('shipping_date', [date("Y-m-01"), date("Y-m-t")]); }); } if(auth()->user()->employee_country_id==2){ $query->where('production_from' ,'=',auth()->user()->employee_country_id); } $query->where('deal_status', 1) ->where('complete_status', 1) ->where(function ($q) { $q->where(function ($qs) { $qs->where('bd_pipeline_stage_id', 4)->where('pipeline_stage_id', 5); })->orWhere('pipeline_stage_id', 4); }); }, 'courier_deals.client', 'courier_deals.tracking' => function($query) use ($request) { if(!empty($request->user_deals)) { $query->where('courier_id', $request->user_deals); } if(!empty($request->from) && !empty($request->to)) { $query->whereBetween('shipping_dates', [$request->from, $request->to]); } else { $query->whereBetween('shipping_date', [date("Y-m-01"), date("Y-m-t")]); } }, 'courier_deals.dealProducts', 'courier_deals.dealProducts.product', 'courier_deals.dealProducts.productstyle' ])->where('id', 1)->get(); return $courier; } public function getProductPrinting(){ $deal_products= new DealProduct(); return $deal_products->getProductPrinting(); } public function pipelinestages(){ return PipelineStage::where('pipeline_id','1')->get(); } public function reorders($request){ $data = Client::select('*')->with(['client_owners','client_deals'=>function($qu) use($request){ if(!empty($request->get('from') && $request->get('to'))) { $qu->whereBetween('close_date', [date($request->from), date($request->to)])->where(function ($q) { $q->where(function ($qs) { $qs->where('bd_pipeline_stage_id', '=', 4); })->orWhere('pipeline_stage_id', '=', 4); }); }else{ $first =date("Y-m-d", strtotime("1-02-2017"));; $last = date("Y-m-d", strtotime("last day of this month")); $qu->whereBetween('close_date', [date($first) , date($last)]); } $qu->where('deal_status', 1); $qu->where(function ($q) { $q->where(function ($qs) { $qs->where('bd_pipeline_stage_id', '=', 4); })->orWhere('pipeline_stage_id', '=', 4); }); },'client_deals.dealProducts','dealProducts.dealProductQuantityAndEstimationAmounts'])->withCount(['client_deals as client_deals_count' => function($query) use($request){ if(!empty($request->get('from') && $request->get('to'))) { $query->select(DB::raw('count(distinct(order_no))'))->whereBetween('close_date', [date($request->from), date($request->to)]); if(!empty($request->get('order_type') )) { $query->where('deal_type_id', $request['order_type']); }else{ // echo '1234'; $query->whereIN('deal_type_id',array(1,2)); } }else{ $first =date("Y-m-d", strtotime("1-02-2017"));; $last = date("Y-m-d", strtotime("last day of this month")); $query->select(DB::raw('count(distinct(order_no))'))->whereBetween('close_date', [date($first), date($last)]); if(!empty($request->get('order_type') )) { $query->where('deal_type_id', $request['order_type']); }else{ $query->whereIN('deal_type_id',array(1,2)); } } }])->having('client_deals_count','>',0); if(!empty($request->deal_name) ) { $data->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { }); }); }); } if(!empty($request->user_deals) ) { $data->whereHas('client_deals', function ($quea) use ($request) { $quea->where('owner_id', '=', $request->user_deals); }); } if(!empty($request->get('from') && $request->get('to'))) { $data->whereHas('client_deals', function ($que) use ($request) { $que->whereBetween('close_date', [date($request->from), date($request->to)]); }); }else{ $data->whereHas('client_deals', function ($que) use ($request) { $first =date("Y-m-d", strtotime("1-02-2017"));; $last = date("Y-m-d", strtotime("last day of this month")); $que->whereBetween('close_date', [date($first) , date($last)]); }); } // $data->whereHas('client_deals', function ($quea) use ($request) { $quea->where(function ($q) { $q->where(function ($qs) { $qs->where('bd_pipeline_stage_id', '=', 4); })->orWhere('pipeline_stage_id', '=', 4); }); if(isset( $ordertype )){ $quea->where('deal_type_id',$request->get('order_type')); }else{ $quea->whereIn('deal_type_id',array(2,1)); } $quea->where('deal_status', 1)->groupBy('order_no'); }); $data=$data->get(); return $data; } public function GetDeal($id){ // $data= DB::table('deals')->Where('id',239)->get(); // $data=Deal::Where('id',239); // print_r($data); $data = Deal::select('*')->with(['dealProducts','dealProducts.product_printings','dealProducts.productColor','client.emails', 'client.phoneNos','client','piplelinestage','dealProducts.dealProductQuantityAndEstimationAmounts','lead_source','owner','dealProducts.product_stock','dealProducts.product','dealProducts.productstyle','dealProducts.product_unit', 'productdetails','notes','tracking','deal_amount'])->whereId($id)->get(); return $data; } public function getBdsDeals($request){ $data = PipelineStage::select('*')->with(['deals' => function($que) use ($request){ /*if($request->has('deal_name') ) { $que->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number' ,'like', $request->deal_name.'%'); }); }); }); }); }*/ if(!empty($request->get('user_deals') )) { $que->where('bd_owner_id' ,'=', $request->user_deals); }else{ if(!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')) { // echo 'dsd'; $que->where('bd_owner_id', '=', auth()->user()->id); } } if(auth()->user()->employee_country_id==2){ $que->where('production_from' ,'=',auth()->user()->employee_country_id); } if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('close_date', [date($request->from) , date($request->to)]); }else{ $first =date("Y-m-d", strtotime("first day of this month"));; $last = date("Y-m-d", strtotime("last day of this month")); $que->whereBetween('close_date', [date($first) , date($last)]); } $que->where('bd_status', '=', '0'); $que->where('deal_status','=','1'); $que->where('ob_pipeline_stage_id','=',''); $que->where('bd_pipeline_stage_id','=',null); },'deals.client','deals.dealProducts','dealProducts.products','dealProducts.productstyle','deals.shipping_states','deals.billing_states','deals.owners','deals.bdowners'])->where('id',5)->get(); return $data; } public function getbusinessdevelopmentsDeals($request){ $data = PipelineStage::select('*')->with(['bd_deals' => function($que) use ($request){ if($request->has('deal_name') ) { $que->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('bd_order_number' ,'like', $request->deal_name.'%'); }); }); }); }); } if(!empty($request->get('user_deals') )) { $que->where('bd_owner_id' ,'=', $request->user_deals); }else{ if(!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')) { // echo 'dsd'; $que->where('bd_owner_id', '=', auth()->user()->id); } } if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('bd_open_date', [date($request->from) , date($request->to)]); }else{ $first =date("Y-m-d", strtotime("first day of this month"));; $last = date("Y-m-d", strtotime("last day of this month")); $que->whereBetween('bd_open_date', [date($first) , date($last)]); } if(auth()->user()->employee_country_id==2){ $que->where('production_from' ,'=',auth()->user()->employee_country_id); } $que->where('deal_status','=','1'); $que->where('show_follow_up','=','4'); },'bd_deals.client','bd_deals.dealProducts','dealProducts.product','dealProducts.productstyle','bd_deals.shipping_states','bd_deals.billing_states','bd_deals.bdowners'])->whereIn('id',array('1','2','11','3'))->orderBy('order_no','asc')->get(); return $data; } public function getObsDeals($request){ $data = PipelineStage::select('*')->with(['deals' => function($que) use ($request){ if($request->has('deal_name') ) { $que->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('ob_order_number' ,'like', $request->deal_name.'%'); }); }); }); }); } if(!empty($request->get('user_deals') )) { $que->where('ob_owner_id' ,'=', $request->user_deals); }else{ if(auth()->user()->id!=1 && auth()->user()->id!=63 && auth()->user()->id!=121 && auth()->user()->id!=68 && auth()->user()->id!=148 && auth()->user()->id!=207 && auth()->user()->id!=276 && auth()->user()->id!=188 && auth()->user()->id!=207 && auth()->user()->id!=188 && auth()->user()->id!=106 && auth()->user()->id!=148 && auth()->user()->id!=107 && auth()->user()->id!=108 && auth()->user()->id!=109 && auth()->user()->id!=90 && auth()->user()->id!=94) { // echo 'dsd'; $que->where('ob_owner_id', '=', auth()->user()->id); } } if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('ob_open_date', [date($request->from) , date($request->to)]); }else{ $first =date("Y-m-d", strtotime("first day of this month"));; $last = date("Y-m-d", strtotime("last day of this month")); $que->whereBetween('ob_open_date', [date($first) , date($last)]); } $que->where('show_follow_up', '=', '2'); $que->where('deal_status','=','1'); $que->where('ob_pipeline_stage_id','=',1); },'deals.client','deals.dealProducts','dealProducts.product','dealProducts.productstyle','deals.shipping_states','deals.billing_states','deals.owners','deals.obowners'])->where('id',11)->get(); return $data; } public function getmarktingDeals($request){ $data = PipelineStage::select('*')->with(['deals' => function($que) use ($request){ if($request->has('deal_name') ) { $que->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number' ,'like', $request->deal_name.'%'); }); }); }); }); } if(!empty($request->get('user_deals') )) { $que->where('owner_id' ,'=', $request->user_deals); }else{ if(!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')) { $que->where('owner_id', '=', auth()->user()->id); } } if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('open_date', [date($request->from) , date($request->to)]); }else{ $first =date("Y-m-d", strtotime("1-02-2017"));; $last = date("Y-m-d", strtotime("last day of this month")); $que->whereBetween('open_date', [date($first) , date($last)]); } $que->where('lead_type_id', '=', '3'); $que->where('deal_status','=','1'); },'deals.client','deals.dealProducts','dealProducts.product','dealProducts.productstyle','deals.shipping_states','deals.billing_states','deals.owners','deals.bdowners'])->where('id',1)->get(); return $data; } public function follow_up($request) { $data = PipelineStage::select('*')->with(['deals' => function($que) use ($request) { if ($request->has('deal_name')) { $que->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number', 'like', $request->deal_name . '%'); }); }); }); }); } if (!empty($request->get('user_deals'))) { $que->where('owner_id', '=', $request->user_deals); } else { if (auth()->user()->id != 1 && auth()->user()->id != 68 && auth()->user()->id!=121 && auth()->user()->id != 63 && auth()->user()->id != 106 && auth()->user()->id != 107 && auth()->user()->id != 108 && auth()->user()->id != 109 && auth()->user()->id != 90 && auth()->user()->id != 94) { $que->where('owner_id', '=', auth()->user()->id); } } if (!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('open_date', [date($request->from), date($request->to)]); } else { $first = '2020-01-01'; $last = date("Y-m-d", strtotime("last day of this month")); $que->whereBetween('open_date', [date($first), date($last)]); } $que->where('show_follow_up', '=', '3'); $que->where('deal_status', '=', '1'); // Order by the 'amount' column in 'dealProductQuantityAndEstimationAmounts' }, 'deals.client', 'deals.dealProducts', 'dealProducts.dealProductQuantityAndEstimationAmounts' => function($queaa) use ($request) { $queaa->orderBy('deal_product_est_amount', 'desc'); }, 'dealProducts.product', 'dealProducts.productstyle', 'deals.shipping_states', 'deals.billing_states', 'deals.owners', 'deals.obowners']) ->where('id', 11); return $data = $data->get(); } public function getBdsLeadsDeals($request){ $data = PipelineStage::select('*')->with(['bd_deals' => function($que) use ($request){ if($request->has('deal_name') ) { $que->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('bd_order_number' ,'like', $request->deal_name.'%'); }); }); }); }); }if(!empty($request->get('user_deals') )) { $que->where('bd_owner_id' ,'=', $request->user_deals); }else{ if(!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')) { $que->where('bd_owner_id', '=', auth()->user()->id); } }if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('open_date', [date($request->from) , date($request->to)]); }else{ $first =date("Y-m-d", strtotime("first day of this month"));; $last = date("Y-m-d", strtotime("last day of this month")); $que->whereBetween('open_date', [date($first) , date($last)]); } if(auth()->user()->employee_country_id==2){ $que->where('production_from' ,'=',auth()->user()->employee_country_id); } $que->where('deal_status','=','1'); $que->whereIn('bd_pipeline_stage_id',array('2','3','11')); },'bd_deals.client','bd_deals.dealProducts','dealProducts.product','dealProducts.productstyle','bd_deals.shipping_states','bd_deals.billing_states','deals.owners','deals.bdowners'])->whereIn('id',array('2','3','11'))->orderBy('order_no','asc')->get(); return $data; } public function getObsLeadsDeals($request){ $data = PipelineStage::select('*')->with(['ob_deals' => function($que) use ($request){ if($request->has('deal_name') ) { $que->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('ob_order_number' ,'like', $request->deal_name.'%'); }); }); }); }); }if(!empty($request->get('user_deals') )) { $que->where('ob_owner_id' ,'=', $request->user_deals); }else{ if(auth()->user()->id!=1 && auth()->user()->id!=63 && auth()->user()->id!=121 && auth()->user()->id!=68 && auth()->user()->id!=207 && auth()->user()->id!=276 && auth()->user()->id!=188 && auth()->user()->id!=106 && auth()->user()->id!=148 && auth()->user()->id!=107 && auth()->user()->id!=108 && auth()->user()->id!=109 && auth()->user()->id!=90 && auth()->user()->id!=94) { $que->where('ob_owner_id', '=', auth()->user()->id); } }if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('ob_open_date', [date($request->from) , date($request->to)]); }else{ $first =date("Y-m-d", strtotime("first day of this month"));; $last = date("Y-m-d", strtotime("last day of this month")); $que->whereBetween('ob_open_date', [date($first) , date($last)]); } $que->where('deal_status','=','1'); $que->where('show_follow_up','=','2'); $que->whereIn('ob_pipeline_stage_id',array('2','3','11')); },'bd_deals.client','bd_deals.dealProducts','dealProducts.product','dealProducts.productstyle','bd_deals.shipping_states','bd_deals.billing_states','deals.owners','deals.obowners'])->whereIn('id',array('2','3','11'))->orderBy('order_no','asc')->get(); return $data; } public function GetBDDeaddeals($request){ $data = PipelineStage::select('*')->with(['bd_deals' => function($que) use ($request){ if($request->has('deal_name') ) { $que->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number' ,'like', $request->deal_name.'%'); }); }); }); }); }if(!empty($request->get('user_deals') )) { $que->where('bd_owner_id' ,'=', $request->user_deals); }else{ if(!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')) { $que->where('bd_owner_id', '=', auth()->user()->id); } }if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('open_date', [date($request->from) , date($request->to)]); }else{ $first =date("Y-m-d", strtotime("first day of this month"));; $last = date("Y-m-d", strtotime("last day of this month")); $que->whereBetween('open_date', [date($first) , date($last)]); } if(auth()->user()->employee_country_id==2){ $que->where('production_from' ,'=',auth()->user()->employee_country_id); } $que->where('deal_status','=','1'); $que->whereIn('bd_pipeline_stage_id',array('13')); },'bd_deals.client','bd_deals.dealProducts','dealProducts.product','dealProducts.productstyle','bd_deals.shipping_states','bd_deals.billing_states','deals.owners','deals.bdowners'])->whereIn('id',array('13'))->orderBy('order_no','asc')->get(); return $data; } public function GetOBDeaddeals($request){ $data = PipelineStage::select('*')->with(['ob_deals' => function($que) use ($request){ if($request->has('deal_name') ) { $que->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('ob_order_number' ,'like', $request->deal_name.'%'); }); }); }); }); }if(!empty($request->get('user_deals') )) { $que->where('ob_owner_id' ,'=', $request->user_deals); }else{ if(auth()->user()->id!=1 && auth()->user()->id!=63 && auth()->user()->id!=121 && auth()->user()->id!=68 && auth()->user()->id!=207 && auth()->user()->id!=276&& auth()->user()->id!=188&& auth()->user()->id!=106 && auth()->user()->id!=113 && auth()->user()->id!=148 && auth()->user()->id!=107 && auth()->user()->id!=108 && auth()->user()->id!=109 && auth()->user()->id!=90 && auth()->user()->id!=94) { $que->where('ob_owner_id', '=', auth()->user()->id); } }if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('ob_close_date', [date($request->from) , date($request->to)]); }else{ $first =date("Y-m-d", strtotime("1-02-2017"));; $last = date("Y-m-d", strtotime("last day of this month")); $que->whereBetween('ob_close_date', [date($first) , date($last)]); } $que->where('deal_status','=','1'); $que->where('show_follow_up','=','2'); $que->whereIn('ob_pipeline_stage_id',array('13')); },'ob_deals.client','ob_deals.dealProducts','dealProducts.product','dealProducts.productstyle','bd_deals.shipping_states','bd_deals.billing_states','deals.owners','deals.bdowners'])->whereIn('id',array('13'))->orderBy('id','asc')->get(); return $data; } public function GetBDWondeals($request){ $data = PipelineStage::select('*')->with(['bd_deals' => function($que) use ($request){ if($request->has('deal_name') ) { $que->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('bd_order_number' ,'like', $request->deal_name.'%'); }); }); }); }); }if(!empty($request->get('user_deals')) ) { $que->where('bd_owner_id' ,'=', $request->user_deals); }else{ if(!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')) { $que->where('bd_owner_id', '=', auth()->user()->id); } } if(!empty($request->get('from') && $request->get('to'))) { $que->whereHas('deal_amount', function ($queryu) use ($request) { $queryu->whereBetween('receiving_date', [date($request->from) , date($request->to)]); }); }else{ $que->whereHas('deal_amount', function ($queryu) use ($request) { $first =date("Y-m-d", strtotime("first day of this month"));; $last = date("Y-m-d", strtotime("last day of this month")); $queryu->whereBetween('receiving_date', [date($first) , date($last)]); }); } $que->where('deal_status','=','1'); if(auth()->user()->employee_country_id==2){ $que->where('production_from' ,'=',auth()->user()->employee_country_id); } if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('close_date', [date($request->from) , date($request->to)]); }else{ $first =date("Y-m-d", strtotime("1-02-2017"));; $last = date("Y-m-d", strtotime("last day of this month")); $que->whereBetween('close_date', [date($first) , date($last)]); } $que->where('deal_status','=','1'); $que->whereIn('bd_pipeline_stage_id',array('4')); },'deals.client','deals.deal_amount'=> function($que) use ($request){ if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('receiving_date', [date($request->from), date($request->to)]); }else{ $first =date("Y-m-d", strtotime("1-02-2017"));; $last = date("Y-m-d", strtotime("last day of this month")); $que->whereBetween('receiving_date', [date($first) , date($last)]); } },'bd_deals.dealProducts','dealProducts.product','dealProducts.productstyle','bd_deals.shipping_states','bd_deals.billing_states','deals.owners','deals.bdowners'])->whereIn('id',array('4'))->orderBy('order_no','asc')->get(); return $data; }public function GetbusinessdevelopmentsWondeals($request){ $data = PipelineStage::select('*')->with(['bd_deals' => function($que) use ($request){ if($request->has('deal_name') ) { $que->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('bd_order_number' ,'like', $request->deal_name.'%'); }); }); }); }); }if(!empty($request->get('user_deals')) ) { $que->where('bd_owner_id' ,'=', $request->user_deals); }else{ if(!auth()->user()->hasRole('Sales Data Entry') && !auth()->user()->hasRole('super-admin')) { $que->where('bd_owner_id', '=', auth()->user()->id); } } if(!empty($request->get('from') && $request->get('to'))) { $que->whereHas('deal_amount', function ($queryu) use ($request) { $queryu->whereBetween('receiving_date', [date($request->from) , date($request->to)]); }); }else{ $que->whereHas('deal_amount', function ($queryu) use ($request) { $first =date("Y-m-d", strtotime("1-02-2017"));; $last = date("Y-m-d", strtotime("last day of this month")); $queryu->whereBetween('receiving_date', [date($first) , date($last)]); }); } $que->where('deal_status','=','1'); if(auth()->user()->employee_country_id==2){ $que->where('production_from' ,'=',auth()->user()->employee_country_id); } if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('bd_close_date', [date($request->from) , date($request->to)]); }else{ $first =date("Y-m-d", strtotime("first day of this month"));; $last = date("Y-m-d", strtotime("last day of this month")); $que->whereBetween('bd_close_date', [date($first) , date($last)]); } $que->where('deal_status','=','1'); $que->whereIn('bd_pipeline_stage_id',array('4')); },'deals.client','deals.deal_amount'=> function($que) use ($request){ if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('receiving_date', [date($request->from), date($request->to)]); }else{ $first =date("Y-m-d", strtotime("1-02-2017"));; $last = date("Y-m-d", strtotime("last day of this month")); $que->whereBetween('receiving_date', [date($first) , date($last)]); } },'bd_deals.dealProducts','dealProducts.product','dealProducts.productstyle','bd_deals.shipping_states','bd_deals.billing_states','deals.owners','deals.bdowners'])->whereIn('id',array('4'))->orderBy('order_no','asc')->get(); return $data; } public function GetOBWondeals($request){ $data = PipelineStage::select('*')->with(['ob_deals' => function($que) use ($request){ if($request->has('deal_name') ) { $que->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('ob_order_number' ,'like', $request->deal_name.'%'); }); }); }); }); }if(!empty($request->get('user_deals')) ) { $que->where('ob_owner_id' ,'=', $request->user_deals); }else{ if(auth()->user()->id!=1 && auth()->user()->id!=63 && auth()->user()->id!=121 && auth()->user()->id!=68 && auth()->user()->id!=207 && auth()->user()->id!=276&& auth()->user()->id!=188 && auth()->user()->id!=106 && auth()->user()->id!=113 && auth()->user()->id!=148 && auth()->user()->id!=107 && auth()->user()->id!=108 && auth()->user()->id!=109 && auth()->user()->id!=90 && auth()->user()->id!=94) { $que->where('ob_owner_id', '=', auth()->user()->id); } } if(!empty($request->get('from') && $request->get('to'))) { $que->whereHas('deal_amount', function ($queryu) use ($request) { $queryu->whereBetween('receiving_date', [date($request->from) , date($request->to)]); }); }else{ $que->whereHas('deal_amount', function ($queryu) use ($request) { $first =date("Y-m-d", strtotime("1-02-2017"));; $last = date("Y-m-d", strtotime("last day of this month")); $queryu->whereBetween('receiving_date', [date($first) , date($last)]); }); } $que->where('deal_status','=','1'); $que->where('show_follow_up','=','2'); if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('ob_close_date', [date($request->from) , date($request->to)]); }else{ $first =date("Y-m-d", strtotime("1-02-2017"));; $last = date("Y-m-d", strtotime("last day of this month")); $que->whereBetween('ob_close_date', [date($first) , date($last)]); } $que->where('deal_status','=','1'); $que->whereIn('ob_pipeline_stage_id',array('4')); },'ob_deals.client','ob_deals.deal_amount'=> function($que) use ($request){ if(!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('receiving_date', [date($request->from), date($request->to)]); }else{ $first =date("Y-m-d", strtotime("1-02-2017"));; $last = date("Y-m-d", strtotime("last day of this month")); $que->whereBetween('receiving_date', [date($first) , date($last)]); } },'ob_deals.dealProducts','dealProducts.product','dealProducts.productstyle','bd_deals.shipping_states','ob_deals.billing_states','deals.owners','deals.obowners'])->whereIn('id',array('4'))->orderBy('order_no','asc')->get(); return $data; } public function getProductionDeals($request) { $data = PipelineStage::select('*')->with(['deals' => function ($que) use ($request) { if ($request->has('deal_name')) { $que->whereHas('client', function ($queryu) use ($request) { $queryu->where('name', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->whereHas('clientDetails', function ($queryu) use ($request) { $queryu->where('value', 'like', $request->deal_name . '%')->orWhere(function ($ques) use ($request) { $ques->where('order_number', 'like', $request->deal_name . '%'); }); }); }); }); } if (!empty($request->get('user_deals'))) { $que->where('owner_id', '=', $request->user_deals); } else { if (auth()->user()->id != 1) { $que->where('owner_id', '=', auth()->user()->id); } } if (!empty($request->get('from') && $request->get('to'))) { $que->whereBetween('close_date', [date($request->from), date($request->to)]); } else { $first =date("Y-m-d", strtotime("1-01-2023"));; $last = date("Y-m-d", strtotime("last day of this month")); $que->whereBetween('close_date', [date($first), date($last)]); } $que->where('deal_status','=','1'); }, 'deals.client', 'deals.dealProducts', 'dealProducts.product', 'dealProducts.productstyle', 'deals.shipping_states', 'deals.billing_states'])->where('id', 4)->get(); return $data; } public function getStates(){ if(auth()->user()->country_id){ return State::where('country_id',auth()->user()->country_id)->get(); }else{ return State::get(); } } public function MovetoProduction($request,$id){ if($request['pipeline_stage_id']=='5'){ $deal= Deal::where('id',$id)->update(['designer_status' => '0','production_status' => '0','vendor_id'=>'','shipping_status'=>0,'complete_status'=>0]); Production::where('deal_id',$id)->delete(); }else if($request['pipeline_stage_id']=='6') { $deal= Deal::where('id', $id)->update(['designer_status' => '1', 'production_status' => '0', 'vendor_id' => '','shipping_status'=>0,'complete_status'=>0]); Production::where('deal_id',$id)->delete(); }else if($request['pipeline_stage_id']=='8') { $deal= Deal::where('id', $id)->update(['complete_status' => '0', 'delivery_status' => '0', 'courier_id' => '']); Tracking::where('deal_id',$id)->delete(); } $deal= Deal::where('id', $id)->first(); return $deal; } public function UpdateProduction($request,$id){ $deal= Deal::where('id', $id)->first(); $res = Production::where('id', $request['id'])->update(['receiving_date' => $request['receiving_date']]); return $deal; } public function NewProduction($request,$id){ $deal= Deal::where('id', $id)->first(); if($request['pipeline_stage_id']==6){ Deal::where('id', $id)->update(['designer_status' => '1']); }else { if (empty($request['rec_qty'])) { Deal::where('id', $id)->update(['production_status' => '1','shipping_status' => '0', 'vendor_id' => $request['vid'],'no_of_design'=> $request['no_of_design']]); if($request['order_type']=='') { Production::where('deal_id', $id)->delete(); } $deal_production = array( 'deal_id' => $id, 'vendor_id' => $request['vid'], 'qty' => $request['qty'], 'send_date' => $request['send_date'], 'expected_receiving_date' => $request['rec_date'], 'tframe' => $request['tframe'], 'type' => $request['order_type'], 'order_number' => $deal['order_number'], 'reason' => $request['reasons'], 'user_id' => auth()->user()->id ); $res = Production::Create($deal_production); } else { Deal::where('id', $id)->update(['shipping_status' => '1']); $pro = Production::where('deal_id', $id)->limit(1)->orderBy('id', 'desc')->first(); $res = Production::where('id', $pro->id)->update(['receiving_date' => $request['receiving_date'], 'receiving_qty' => $request['rec_qty'], 'reason' => $request['reason']]); } } return $deal; } public function MovetoCourier($request,$id){ if($request['cid']) { $deals = Deal::where('id', $id)->first(); if (empty($deals['shipping_dollar_rate'])){ $res = Deal::where('id', $id)->update(['delivery_status' => '1', 'complete_status' => '0', 'weight' => array_sum($request['weight']), 'shipping_amount' => array_sum($request['fare']), 'courier_id' => $request['cid'],'shipping_dollar_rate'=>$request['shipping_dollar_rate']]); }else{ if($deals['complete_status']==0) { $res = Deal::where('id', $id)->update(['delivery_status' => '1', 'complete_status' => '0', 'weight' => array_sum($request['weight']), 'shipping_amount' => array_sum($request['fare']), 'courier_id' => $request['cid']]); } } $i=0; $s=0; DealShippingBoxes::where('deal_id',$id)->delete(); Tracking::where('deal_id',$id)->delete(); if($deals['complete_status']==0) { foreach ($request['box_code'] as $shippingboxes) { if (!empty($shippingboxes)) { $deal_shippingboxes = array( 'deal_id' => $id, 'box_code' => $request['box_code'][$s], 'courier_id' => $request['id_courier'][$s], 'box_qty' => $request['box_qty'][$s] ); DealShippingBoxes::Create($deal_shippingboxes); } $s++; } } foreach ($request['tracking'] as $track){ if(!empty($track)) { $deal_tracking = array( 'tracking_number' => $track, 'deal_id' => $id, 'amount' => $request['fare'][$i], 'weight' => $request['weight'][$i], 'courier_id' => $request['courier_ids'][$i], 'shipping_date' => $request['shipping_date'][$i] ); Tracking::Create($deal_tracking); } $i++; } }else{ $deals= Deal::where('id', $id)->first(); if($deals['delivery_status']==1) { $res = Deal::where('id', $id)->update(['complete_status' => '1']); }else{ $res = Deal::where('id', $id)->update(['delivery_status' => '1']); } } $deal= Deal::where('id', $id)->first(); return $deal; } public function create($request){ try{ // DB::beginTransaction(); $clnt = Client::where('referral', $request['referral_code'])->first(); $clt = ClientsReferalls::where('referral_to', $request['client_id'])->first(); if (empty($clt)) { $randomString = Str::random(2) . rand(6, 99) . Str::random(2); // Generate a random number between 1000 and 9999 $randomNumber = rand(1000, 9999); // Combine the random string and number $code = $randomString; Client::where('id', $request['client_id'])->update(['referral' => $code]); } if($request['referral_code']) { // $clt=ClientsReferalls::where('referral_tosdasdas',$request['client_id'])->first(); // print_r($clt);exit; if (empty($clt)) { $deal_product_qty = array( 'referral_to' => $request['client_id'], 'referral_by' => $clnt->id, 'referral_use' => 1, ); //print_r($deal_product_qty); ClientsReferalls::Create($deal_product_qty); // echo 'sdasdasdsa'; // print_r('dasdas'); } // exit; } $deal_product_printing=array(); $deal_product_qty=array(); $x=0; $icr=1; $totalproduct=count($request->products['product_id']); $domain_code=Domains::where('id',$request['domain_id'])->first(); $products_details=array(); foreach($request->products['product_id'] as $x=>$totalproduct) { $owners_name = User::where('id', $request['owner_id'])->first(); $first = $owners_name->first_name; $last = $owners_name->last_name; // print_r($owners_name);exit; if($request['show_follow_up']==1){ if ($request['existing'] == 1) { $orderNumber = $request['order_no']; } else { $orderNumber = $domain_code->domain_code . '-' . $first[0] . $last[0] . '-' . time(); } $deal = $this->repository->create($request->except(['attachments', 'products'])); if (!empty($request->products['est_amount_0'][$x])) { $est_amount0 = $request->products['est_amount_0'][$x]; } else { $est_amount0 = 0; } if ($request['lead_type_id'] == 2) { Deal::where('id', $deal->id)->update(['quotation' => 2]); } $order=Deal::where('id', $deal->id)->update(['order_number' => $orderNumber, 'est_amount' => $est_amount0, 'order_no' => $orderNumber, 'product_id' => $request['products']['product_id'][0]]); }elseif($request['pipeline_stage_id']==13){ if ($request['existing'] == 1) { $orderNumber = $request['order_no']; } else { $orderNumber = $domain_code->domain_code . '-' . $first[0] . $last[0] . '-' . time(); } $deal = $this->repository->create($request->except(['attachments', 'products'])); if (!empty($request->products['est_amount_0'][$x])) { $est_amount0 = $request->products['est_amount_0'][$x]; } else { $est_amount0 = 0; } if ($request['lead_type_id'] == 2) { Deal::where('id', $deal->id)->update(['quotation' => 2]); } Deal::where('id', $deal->id)->update(['bd_order_number' => $orderNumber,'order_number' => '','order_no' => '', 'bd_order_number' => $orderNumber, 'est_amount' => $est_amount0,'bd_open_date'=>$request['open_date'],'open_date'=>'', 'owner_id'=>'','bd_owner_id'=>$request['owner_id'],'bd_pipeline_stage_id'=>$request['pipeline_stage_id'] , 'product_id' => $request['products']['product_id'][0]]); } $order= Deal::Where('id',$deal->id)->first(); if($request['production_from']==2){ $chinaorder=$order->order_number .'-'.'CN'; Deal::where('id', $deal->id)->update(['order_number' => $chinaorder,'order_no'=>$chinaorder,'production_from'=>2]); } if (!empty($request->products['product_id'][$x])) { $products_details[$request->products['product_id'][$x]]= array( 'deal_id' =>$deal->id, 'created_at'=>$request['open_date'], 'product_id' => $request->products['product_id'][$x], 'product_style_id' => $request->products['product_style_id'][$x], 'product_length' => $request->products['product_length'][$x], 'product_width' => $request->products['product_width'][$x], 'product_height' => $request->products['product_height'][$x], 'product_stock_id' => $request->products['product_stock_id'][$x], 'product_measurement_unit_id' => $request->products['product_measurement_unit'][$x], 'product_color_id' => $request->products['product_color'][$x], 'product_size' => $request->products['product_width'][$x] . ' x ' . $request->products['product_length'][$x] . ' x ' . $request->products['product_height'][$x], ); $deal_pro=DealProduct::create($products_details[$request->products['product_id'][$x]]); Deal::where('id', $deal->id)->update(['material'=>$request->products['product_stock_id'][$x], 'special_instruction'=>$request->products['special_instruction'][$x]]); $deal_products = DealProduct::where('deal_id', $deal->id)->get(); foreach ($deal_products as $key => $dp){ $d_product=DealProduct::find($dp->id); if(isset($request->products['product_printing'][$x])) { $d_product->product_printings()->sync($request->products['product_printing'][$x]); } if(!empty($request->products['product_quantity_0'][$x])){ $dealqty0=$request->products['product_quantity_0'][$x]; }else{ $dealqty0=0; } if(!empty($request->products['product_quantity_1'][$x])){ $dealqty1=$request->products['product_quantity_1'][$x]; }else{ $dealqty1=0; } if(!empty($request->products['product_quantity_2'][$x])){ $dealqty2=$request->products['product_quantity_2'][$x]; }else{ $dealqty2=0; } if(!empty($request->products['product_quantity_3'][$x])){ $dealqty3=$request->products['product_quantity_3'][$x]; }else{ $dealqty3=0; } if(!empty($request->products['product_quantity_4'][$x])){ $dealqty4=$request->products['product_quantity_4'][$x]; }else{ $dealqty4=0; } if(!empty($request->products['product_quantity_5'][$x])){ $dealqty5=$request->products['product_quantity_5'][$x]; }else{ $dealqty5=0; } if(!empty($request->products['no_of_design_0'][$x])){ $no_of_design0=$request->products['no_of_design_0'][$x]; }else{ $no_of_design0=0; } if(!empty($request->products['no_of_design_1'][$x])){ $no_of_design1=$request->products['no_of_design_1'][$x]; }else{ $no_of_design1=0; } if(!empty($request->products['no_of_design_2'][$x])){ $no_of_design2=$request->products['no_of_design_2'][$x]; }else{ $no_of_design2=0; } if(!empty($request->products['no_of_design_3'][$x])){ $no_of_design3=$request->products['no_of_design_3'][$x]; }else{ $no_of_design3=0; } if(!empty($request->products['no_of_design_4'][$x])){ $no_of_design4=$request->products['no_of_design_4'][$x]; }else{ $no_of_design4=0; } if(!empty($request->products['no_of_design_5'][$x])){ $no_of_design5=$request->products['no_of_design_5'][$x]; }else{ $no_of_design5=0; } if(!empty($request->products['amount'][$x])){ $amount0=$request->products['amount'][$x]; }else{ $amount0=0; } $deal_product_qty = array( 'deal_product_id' => $dp->id, 'deal_product_quantity' => $dealqty0, 'no_of_design' => $no_of_design0, 'deal_product_amount' => $request->products['amount'][$x], 'deal_product_amount' => $request->products['amount'][$x], 'checked_value' =>'1', ); QuantityAndEstimation::Create($deal_product_qty); $deal_product_qty = array( 'deal_product_id' => $dp->id, 'deal_product_quantity' => $dealqty1, 'no_of_design' => $no_of_design1, 'deal_product_amount' => $amount0, ); //print_r($deal_product_qty); QuantityAndEstimation::Create($deal_product_qty); $deal_product_qty = array( 'deal_product_id' => $dp->id, 'deal_product_quantity' => $dealqty2, 'no_of_design' => $no_of_design2, 'deal_product_amount' => $amount0, ); QuantityAndEstimation::Create($deal_product_qty); $deal_product_qty = array( 'deal_product_id' => $dp->id, 'deal_product_quantity' => $dealqty3, 'no_of_design' => $no_of_design3, 'deal_product_amount' => $amount0, ); QuantityAndEstimation::Create($deal_product_qty); $deal_product_qty = array( 'deal_product_id' => $dp->id, 'deal_product_quantity' => $dealqty4, 'no_of_design' => $no_of_design4, 'deal_product_amount' => $amount0, ); QuantityAndEstimation::Create($deal_product_qty); $deal_product_qty = array( 'deal_product_id' => $dp->id, 'deal_product_quantity' => $dealqty5, 'no_of_design' => $no_of_design5, 'deal_product_amount' => $amount0, ); QuantityAndEstimation::Create($deal_product_qty); } } if ($request->has('attachments')) { $this->saveUpdateAttachments($request->attachments, $deal); } } return $order; }catch (\Exception $e){ return $e->getMessage(); } } public function saveUpdateAttachments($attachment_files , $deal , $id = null) { if(is_array($attachment_files)){ foreach ($attachment_files as $file) { $mimeArr = explode("/",$file->getMimeType()); $fileType = ($mimeArr[0] == "video")?"video":(($mimeArr[0]=='image')?"image":"file"); $fileExt = $file->getClientOriginalExtension(); $fileName = $file->getClientOriginalName(); $attachment_path = uploadFile(null, 'storage/profile', null, $file); $fileArr = [ 'name' => $fileName, 'type' => $fileType, 'ext' => $fileExt, 'url' => $attachment_path ]; //dd($fileArr); $deal->files()->create($fileArr); } } } public function BDEstandAmountupdate($request,$id){ $product_stage=Deal::where('id',$id)->first(); // Client::where('id', $product_stage->client_id)->update(['address' => $request['shipping_address'],'billing_address' => $request['billing_address']]); $request['deal_type']='2'; $famount=''; if($product_stage->bd_pipeline_stage_id !=11) { if ($request->pipeline_stage_id < $product_stage->bd_pipeline_stage_id) { if ($request->est_amount == '') { $est = 1; } else { $est = $request->est_amount; } } else { $est = $request->est_amount; } if ($request->pipeline_stage_id < $product_stage->bd_pipeline_stage_id) { if (empty($request->amount)) { $famount = 0; } else { $famount = $request->amount; } } else { $famount = $request->amount; } }else{ $est = $request->est_amount; $famount = $request->amount; } $deal = Deal::where('id', $id)->update(['bd_pipeline_stage_id' => $request['pipeline_stage_id'],'bd_status'=>'1']); // $deal = $this->repository->update($request->except(['attachments','products']),$id); $deal_products=DealProduct::where('deal_id',$id)->first(); $deal_QuantityAndEstimation=QuantityAndEstimation::where('deal_product_id',$deal_products->id)->first(); if($deal['bd_owner_id']){ $user= User::where('id',$deal['bd_owner_id'])->first(); }else{ $user= User::where('id',$deal['owner_id'])->first(); } if($user->country_id==1){ $url = 'https://api.exchangerate-api.com/v4/latest/USD'; }elseif ($user->country_id==2){ $url = 'https://api.exchangerate-api.com/v4/latest/AUD'; }elseif ($user->country_id==3){ $url = 'https://api.exchangerate-api.com/v4/latest/GBP'; } $json = file_get_contents($url);$exp = json_decode($json); $convert = $exp->rates->PKR; if(empty($product_stage->dollar_rate)){ if($request['amount']){ Deal::where('id',$product_stage->id)->update(['dollar_rate' => $convert]); } } if($est) { if($est == 1 ){ $ests=0; }else{ $ests=$est; } if($ests==0) { QuantityAndEstimation::where('id', $deal_QuantityAndEstimation->id)->update(['deal_product_est_amount' => $ests]); QuantityAndEstimation::where('id', $deal_QuantityAndEstimation->id)->update(['deal_product_amount' => $famount]); }else{ QuantityAndEstimation::where('id', $deal_QuantityAndEstimation->id)->update(['deal_product_est_amount' => $ests]); } }else{ QuantityAndEstimation::where('id', $deal_QuantityAndEstimation->id)->update(['deal_product_amount' => $famount]); } return $product_stage; } public function OBEstandAmountupdate($request,$id){ // $product_stage=Deal::where('id',$id)->first(); // Client::where('id', $product_stage->client_id)->update(['address' => $request['shipping_address'],'billing_address' => $request['billing_address']]); $request['deal_type']='2'; $famount=''; if($product_stage->bd_pipeline_stage_id !=11) { if ($request->pipeline_stage_id < $product_stage->bd_pipeline_stage_id) { if ($request->est_amount == '') { $est = 1; } else { $est = $request->est_amount; } } else { $est = $request->est_amount; } if ($request->pipeline_stage_id < $product_stage->bd_pipeline_stage_id) { if (empty($request->amount)) { $famount = 0; } else { $famount = $request->amount; } } else { $famount = $request->amount; } }else{ $est = $request->est_amount; $famount = $request->amount; } $deal = Deal::where('id', $id)->update(['ob_pipeline_stage_id' => $request['pipeline_stage_id'],'ob_close_date'=>$request['close_date']]); // $deal = $this->repository->update($request->except(['attachments','products']),$id); $deal_products=DealProduct::where('deal_id',$id)->first(); $deal_QuantityAndEstimation=QuantityAndEstimation::where('deal_product_id',$deal_products->id)->first(); if($deal['bd_owner_id']){ $user= User::where('id',$deal['bd_owner_id'])->first(); }else{ $user= User::where('id',$deal['owner_id'])->first(); } if($user->country_id==1){ $url = 'https://api.exchangerate-api.com/v4/latest/USD'; }elseif ($user->country_id==2){ $url = 'https://api.exchangerate-api.com/v4/latest/AUD'; }elseif ($user->country_id==3){ $url = 'https://api.exchangerate-api.com/v4/latest/GBP'; } $json = file_get_contents($url);$exp = json_decode($json); $convert = $exp->rates->PKR; if(empty($product_stage->dollar_rate)){ if($request['amount']){ Deal::where('id',$product_stage->id)->update(['dollar_rate' => $convert]); } } if($est) { if($est == 1 ){ $ests=0; }else{ $ests=$est; } if($ests==0) { QuantityAndEstimation::where('id', $deal_QuantityAndEstimation->id)->update(['deal_product_est_amount' => $ests]); QuantityAndEstimation::where('id', $deal_QuantityAndEstimation->id)->update(['deal_product_amount' => $famount]); }else{ QuantityAndEstimation::where('id', $deal_QuantityAndEstimation->id)->update(['deal_product_est_amount' => $ests]); } }else{ QuantityAndEstimation::where('id', $deal_QuantityAndEstimation->id)->update(['deal_product_amount' => $famount]); } return $product_stage; } public function estupdatetype($request,$id){ Deal::where('id',$id)->update(['estimation'=>$request['pipeline_stage_id'],'estimator_id'=>auth()->user()->id]); $deal= Deal::where('id',$id)->first(); return $deal; } public function Reasonupdate($request,$id){ Deal::where('id',$id)->update(['pipeline_stage_id'=>$request['pipeline_stage_id'],'close_date'=>$request['close_date'],'lost_reason'=>$request['reason']]); $deal= Deal::where('id',$id)->first(); return $deal; } public function EstandAmountupdate($request,$id){ $product_stage=Deal::where('id',$id)->first(); // Client::where('id', $product_stage->client_id)->update(['address' => $request['shipping_address'],'billing_address' => $request['billing_address']]); $famount=''; if($product_stage->pipeline_stage_id !=11) { if ($request->pipeline_stage_id < $product_stage->pipeline_stage_id) { if ($request->est_amount == '') { $est = 1; } else { $est = $request->est_amount; } } else { $est = $request->est_amount; } if ($request->pipeline_stage_id < $product_stage->pipeline_stage_id) { if (empty($request->amount)) { $famount = 0; } else { $famount = $request->amount; } } else { $famount = $request->amount; } }else{ $est = $request->est_amount; $famount = $request->amount; } if($request['pipeline_stage_id']==13){ $deals= Deal::where('id', $id)->update(['ob_pipeline_stage_id'=>1,'ob_open_date'=>$request['close_date'],'ob_owner_id'=>'222']); } $deals= Deal::where('id', $id)->update(['est_amount'=>$est]); $deal = $this->repository->update($request->except(['attachments','products']),$id); $deal_products=DealProduct::where('deal_id',$id)->first(); $deal_QuantityAndEstimation=QuantityAndEstimation::where('deal_product_id',$deal_products->id)->first(); /* if($deals['bd_owner_id']){ $user= User::where('id',$deals['bd_owner_id'])->first(); }else{ $user= User::where('id',$deals['owner_id'])->first(); } if($user->country_id==1){ $url = 'https://api.exchangerate-api.com/v4/latest/USD'; }elseif ($user->country_id==2){ $url = 'https://api.exchangerate-api.com/v4/latest/AUD'; }elseif ($user->country_id==3){ $url = 'https://api.exchangerate-api.com/v4/latest/GBP'; } $json = file_get_contents($url);$exp = json_decode($json); $convert = $exp->rates->PKR; if(empty($product_stage->dollar_rate)){ if($request['amount']){ Deal::where('id',$product_stage->id)->update(['dollar_rate' => $convert]); } }*/ if($est) { if($est == 1 ){ $ests=0; }else{ $ests=$est; } if($ests==0) { QuantityAndEstimation::where('id', $deal_QuantityAndEstimation->id)->update(['deal_product_est_amount' => $ests]); QuantityAndEstimation::where('id', $deal_QuantityAndEstimation->id)->update(['deal_product_amount' => $famount]); }else{ QuantityAndEstimation::where('id', $deal_QuantityAndEstimation->id)->update(['deal_product_est_amount' => $ests]); } }else{ QuantityAndEstimation::where('id', $deal_QuantityAndEstimation->id)->update(['deal_product_amount' => $famount]); } return $deal; } public function UpdateCloseWon($request,$id){ $deals_detail=Deal::where('id',$id)->first(); /* $set = Setting::where('id', 1)->first(); $reward_point=$request['model_input_amount']*$set->referral_commission/100*$set->point_per_dollar; $reward_amt=$request['model_input_amount']*$set->referral_commission/100; if($request['use_commission']==2) { $client = Client::where('id', $request['client_id'])->first(); if ($client->commission >= $request['commission']) { $old_commi = $client->commission - $request['commission']; $deassl = Client::where('id', $request['client_id'])->update(['commission' =>(int)$old_commi]); $desasdas = Deal::where('id', $id)->update(['commission' =>(int)$request['commission'], 'use_commission' => $request['use_commission']]); } }elseif($request['use_commission']==3) { $client = Client::where('id', $request['client_id'])->first(); if ( $client->reward_point >0) { if ($client->reward_amount >= $request['reward_amount']) { $rewards_points = $client->reward_point - $reward_point; $rewards_amount = $client->reward_amount - $request['reward_amount']; $reward_point=$rewards_amount*$set->referral_commission/100*$set->point_per_dollar; Client::where('id', $client->id)->update(['reward_amount' => $rewards_amount, 'reward_point' => $reward_point]); $desasdas = Deal::where('id', $id)->update(['commission' => $request['reward_amount'], 'use_commission' => $request['use_commission']]); } } } if($request['use_commission'] == 1 ) { $set = Setting::where('id', 1)->first(); $reward_point=$request['model_input_amount']*$set->referral_commission/100*$set->point_per_dollar; $reward_amt=$request['model_input_amount']*$set->referral_commission/100; $client = Client::where('id', $request['client_id'])->first(); $deals_reward=Deal::where('id',$id)->first(); if($deals_reward->reward_point){ if($client->reward_point == $deals_reward->reward_point){ $rewards_points = $deals_reward->reward_point; }else{ $rewards_points = $client->reward_point - $deals_reward->reward_point; if($rewards_points <0){ $rewards_points=0; } } if($client->reward_amount ==$deals_reward->reward_amount){ $rewards_amount = $deals_reward->reward_amount; }else{ $rewards_amount = $client->reward_amount - $deals_reward->reward_amount; if($rewards_amount <0){ $rewards_amount=0; } } Deal::where('id', $id)->update(['reward_point'=>(int)$rewards_points,'reward_amount'=>(int)$rewards_amount]); Client::where('id', $client->id)->update(['reward_amount' => (int)$rewards_amount, 'reward_point' => (int)$rewards_points]); }else{ $set = Setting::where('id','!=',0)->first(); $reward_point=$request['model_input_amount']*$set->referral_commission/100*$set->point_per_dollar; $reward_amt=$request['model_input_amount']*$set->referral_commission/100; Deal::where('id', $id)->update(['reward_point'=>(int)$reward_point , 'reward_amount'=> (int)$reward_amt]); Client::where('id', $client->id)->update(['reward_amount' =>$reward_amt, 'reward_point' => $reward_point]); } // Client::where('id', $client->id)->update(['reward_amount' => $rewards_amount, 'reward_point' => $rewards_points]); // echo '1223'; $set = Setting::where('id','!=',0)->first(); $reward_point=$request['model_input_amount']*$set->referral_commission/100*$set->point_per_dollar; $reward_amt=$request['model_input_amount']*$set->referral_commission/100; // Deal::where('id', $id)->update(['reward_point'=>(int)$reward_point,'reward_amount'=>66]); DB::update('UPDATE deals SET reward_point = ?, reward_amount = ? WHERE id = ?', [$reward_point,$reward_amt, $id]); /// DB::update('UPDATE deals SET reward_point = ?,reward_amount = ? WHERE id = ?', [$reward_point,5, $id]); } $ref_clnt=ClientsReferalls::where('referral_to',$deals_detail['client_id'])->first(); if(!empty($ref_clnt)) { if ($ref_clnt->referral_use == 1) { $deassl = ClientsReferalls::where('referral_to', $deals_detail['client_id'])->update(['referral_use' => '0']); $set = Setting::where('id', 1)->first(); $comission = $request['model_input_amount'] * $set->referral_commission / 100; $clients = Client::where('id', $ref_clnt->referral_by)->first(); $old_commission = $comission + $clients->commission; $deassl = Client::where('id', $clients->id)->update(['commission' => $old_commission]); } } */ $deal =Deal::where('id',$id)->first(); if($deal['bd_owner_id']){ $user= User::where('id',$deal['bd_owner_id'])->first(); }else{ $user= User::where('id',$deal['owner_id'])->first(); } if($user->country_id==1){ $url = 'https://api.exchangerate-api.com/v4/latest/USD'; }elseif ($user->country_id==2){ $url = 'https://api.exchangerate-api.com/v4/latest/AUD'; }elseif ($user->country_id==3){ $url = 'https://api.exchangerate-api.com/v4/latest/GBP'; } $json = file_get_contents($url); $exp = json_decode($json); $convert = $exp->rates->PKR; if($deals_detail['dollar_rate']) { $request['dollar_rate'] = $request['dollar_rate']; }else{ $request['dollar_rate'] = $convert; } // echo 'asdas';exit; // $reward_point=Rewards::where('amount' ,'<=',$request['model_input_amount'])->orderBy('id','desc')->first(); // print_r($reward_point);exit; $user=\App\Models\User::where('id',$deals_detail->owner_id)->first(); $first = date("Y-m-d", strtotime("first day of this month")); $last = date("Y-m-d", strtotime("last day of this month")); $first_deal = Deal:: whereBetween('close_date' , [date($first) , date($last)])->where('pipeline_stage_id',4)->first(); if (empty($first_deal)) { $userds=\App\Models\User::Where('agent','=','1')->where('status','active')->get(); foreach($userds as $u){ $deal_product_qty = array( 'user_id' => $u->id, 'date' => date('Y-m-d'), 'description' => '<p style="margin-bottom: 0.3rem;font-size: 24px;font-family: math;font-weight: 700;">Congratulations! '.$user->first_name. ' '.$user->last_name. 'you got the first sale of this month.</p> <p style="margin-bottom: 0.3rem;font-size: 24px;font-family: math;font-weight: 700;"> We appreciate your hard work and dedication to make yourself and OXO Packaging a “Success Story” !</p>', 'status' => 'read', 'first_sale' => '1', ); DealNotification::Create($deal_product_qty); // DealNotification:: } } $deal = $this->repository->update($request->except(['reward_amount','attachments','products']),$id); $deal_products=DealProduct::where('deal_id',$id)->first(); $deal_QuantityAndEstimation=QuantityAndEstimation::where('deal_product_id',$deal_products->id)->first(); $receive_able=array_sum($request['amounts']); QuantityAndEstimation::where('id', $deal_QuantityAndEstimation->id)->update(['deal_product_amount' =>$request['model_input_amount'],'receive_able_amount'=> $receive_able]); foreach ($request['amounts'] as $key=> $amt) { if($amt >=0 && $request['receiving_date'][$key]!='' ) { if($deal['bd_owner_id']){ $user= User::where('id',$deal['bd_owner_id'])->first(); }else{ $user= User::where('id',$deal['owner_id'])->first(); } if($user->country_id==1){ $url = 'https://api.exchangerate-api.com/v4/latest/USD'; }elseif ($user->country_id==2){ $url = 'https://api.exchangerate-api.com/v4/latest/AUD'; }elseif ($user->country_id==3){ $url = 'https://api.exchangerate-api.com/v4/latest/GBP'; } $json = file_get_contents($url); $exp = json_decode($json); $convert = $exp->rates->PKR; $products_amount = array( 'amount' => $amt, 'deal_id' => $deal->id, 'dollar_rate' => $convert, 'payment_type' => $request['type'][$key], 'receiving_date' => $request['receiving_date'][$key] ); DealAmount::Create($products_amount); } } return $deal; } public function UpdateBdCloseWon($request,$id){ $deal =Deal::where('id',$id)->first(); if($deal['bd_owner_id']){ $user= User::where('id',$deal['bd_owner_id'])->first(); }else{ $user= User::where('id',$deal['owner_id'])->first(); } if($user->country_id==1){ $url = 'https://api.exchangerate-api.com/v4/latest/USD'; }elseif ($user->country_id==2){ $url = 'https://api.exchangerate-api.com/v4/latest/AUD'; }elseif ($user->country_id==3){ $url = 'https://api.exchangerate-api.com/v4/latest/GBP'; } $json = file_get_contents($url); $exp = json_decode($json); $convert = $exp->rates->PKR; $request['dollar_rate']=$convert; Deal::where('id',$id)->update(['bd_close_date'=>$request['close_date'],'dollar_rate'=>$request['dollar_rate'],'bd_pipeline_stage_id'=>$request['pipeline_stage_id']]); $deal_products=DealProduct::where('deal_id',$id)->first(); $deal_QuantityAndEstimation=QuantityAndEstimation::where('deal_product_id',$deal_products->id)->first(); $receive_able=array_sum($request['amounts']); QuantityAndEstimation::where('id', $deal_QuantityAndEstimation->id)->update(['deal_product_amount' =>$request['model_input_amount'],'receive_able_amount'=> $receive_able]); foreach ($request['amounts'] as $key=> $amt) { if($amt > 1) { if($user->country_id==1){ $url = 'https://api.exchangerate-api.com/v4/latest/USD'; }elseif ($user->country_id==2){ $url = 'https://api.exchangerate-api.com/v4/latest/AUD'; }elseif ($user->country_id==3){ $url = 'https://api.exchangerate-api.com/v4/latest/GBP'; } $json = file_get_contents($url); $exp = json_decode($json); $convert = $exp->rates->PKR; $products_amount = array( 'amount' => $amt, 'deal_id' => $deal->id, 'dollar_rate' => $convert, 'payment_type' => $request['type'][$key], 'receiving_date' => $request['receiving_date'][$key] ); DealAmount::Create($products_amount); } } return $deal; } public function UpdateOBCloseWon($request,$id){ $deal =Deal::where('id',$id)->first(); if($deal['bd_owner_id']){ $user= User::where('id',$deal['bd_owner_id'])->first(); }else{ $user= User::where('id',$deal['owner_id'])->first(); } if($user->country_id==1){ $url = 'https://api.exchangerate-api.com/v4/latest/USD'; }elseif ($user->country_id==2){ $url = 'https://api.exchangerate-api.com/v4/latest/AUD'; }elseif ($user->country_id==3){ $url = 'https://api.exchangerate-api.com/v4/latest/GBP'; } $json = file_get_contents($url); $exp = json_decode($json); $convert = $exp->rates->PKR; $request['dollar_rate']=$convert; Deal::where('id',$id)->update(['ob_close_date'=>$request['close_date'],'dollar_rate'=>$request['dollar_rate'],'ob_pipeline_stage_id'=>$request['pipeline_stage_id']]); $deal_products=DealProduct::where('deal_id',$id)->first(); $deal_QuantityAndEstimation=QuantityAndEstimation::where('deal_product_id',$deal_products->id)->first(); $receive_able=array_sum($request['amounts']); QuantityAndEstimation::where('id', $deal_QuantityAndEstimation->id)->update(['deal_product_amount' =>$request['model_input_amount'],'receive_able_amount'=> $receive_able]); foreach ($request['amounts'] as $key=> $amt) { if($amt > 1) { if($user->country_id==1){ $url = 'https://api.exchangerate-api.com/v4/latest/USD'; }elseif ($user->country_id==2){ $url = 'https://api.exchangerate-api.com/v4/latest/AUD'; }elseif ($user->country_id==3){ $url = 'https://api.exchangerate-api.com/v4/latest/GBP'; } $json = file_get_contents($url); $exp = json_decode($json); $convert = $exp->rates->PKR; $products_amount = array( 'amount' => $amt, 'deal_id' => $deal->id, 'dollar_rate' => $convert, 'payment_type' => $request['type'][$key], 'receiving_date' => $request['receiving_date'][$key] ); DealAmount::Create($products_amount); } } return $deal; } public function removeEverythingBefore($in, $before) { $pos = strpos($in, $before); return $pos !== FALSE ? substr($in, $pos + strlen($before), strlen($in)) : ""; } public function update($request,$id) { try { $deal_id = Deal::where('id', $id)->first(); if ($request['pipeline_stage_id'] == 4) { /* est $ref_clnt=ClientsReferalls::where('referral_to',$deal_id['client_id'])->first(); if(!empty($ref_clnt)) { if ($ref_clnt->referral_use == 1) { $deassl = ClientsReferalls::where('referral_to', $deal_id['client_id'])->update(['referral_use' => '0']); $set = Setting::where('id', 1)->first(); $comission = (int)$request->products['amount'][0]* $set->referral_commission / 100; $clients = Client::where('id', $ref_clnt->referral_by)->first(); $old_commission = $comission + $clients->commission; $deassl = Client::where('id', $clients->id)->update(['commission' => $old_commission]); } } if($request['use_commission']==2) { $client = Client::where('id', $deal_id['client_id'])->first(); if ($client->commission >= $request['commission']) { $old_commi = $client->commission - $request['commission']; $deassl = Client::where('id', $deal_id['client_id'])->update(['commission' =>(int)$old_commi]); $desasdas = Deal::where('id', $id)->update(['commission' =>(int)$request['commission'], 'use_commission' => $request['use_commission']]); } }elseif($request['use_commission']==3) { $client = Client::where('id', $deal_id['client_id'])->first(); $set = Setting::where('id', 1)->first(); $reward_point=$request->products['amount'][0]*$set->referral_commission/100*$set->point_per_dollar; $reward_amt=$request->products['amount'][0]*$set->referral_commission/100; if ( $reward_point>0) { if ($client->reward_amount >= $request['reward_amount']) { //echo $reward_point;exit; $rewards_points = $client->reward_point - $reward_point; $rewards_amount = $client->reward_amount - $request['reward_amount']; $reward_point=$rewards_amount*$set->point_per_dollar; // echo $reward_point;exit; //exit; Client::where('id', $client->id)->update(['reward_amount' => $rewards_amount, 'reward_point' => $reward_point]); $desasdas = Deal::where('id', $id)->update(['commission' => $request['reward_amount'], 'use_commission' => $request['use_commission']]); } } } est */ $first = date("Y-m-d", strtotime("first day of this month")); $last = date("Y-m-d", strtotime("last day of this month")); $user=\App\Models\User::where('id',$request['owner_id'])->first(); $first_deal = Deal:: whereBetween('close_date', [date($first) , date($last)])->where('pipeline_stage_id',4)->first(); if($request['close_date']>=$first) { if (empty($first_deal)) { $userds = \App\Models\User::Where('agent', '=', '1')->get(); foreach ($userds as $u) { $deal_product_qty = array( 'user_id' => $u->id, 'date' => date('Y-m-d'), 'description' => '<p style="margin-bottom: 0.3rem;font-size: 24px;font-family: math;font-weight: 700;">Congratulations! ' . $user->first_name . ' ' . $user->last_name . 'you got the first sale of this month.</p> <p style="margin-bottom: 0.3rem;font-size: 24px;font-family: math;font-weight: 700;"> We appreciate your hard work and dedication to make yourself and OXO Packaging a “Success Story” !</p>', 'status' => 'un-read', 'first_sale' => '1', ); DealNotification::Create($deal_product_qty); // DealNotification:: } } } }elseif($request['pipeline_stage_id']==13){ Deal::where('id', $id)->update(['ob_pipeline_stage_id' => '1','ob_open_date'=>$request['close_date'],'ob_owner_id'=>222]); } $deal_id = Deal::where('id', $id)->first(); if($deal_id['bd_owner_id']){ $user= User::where('id',$deal_id['bd_owner_id'])->first(); }else{ $user= User::where('id',$deal_id['owner_id'])->first(); } // echo '<pre>'; // print_r($request->all());exit; if ($request['pipeline_stage_id'] == 4){ // echo 'asdas';exit; /* est if($request['use_commission'] == 1 ) { $set = Setting::where('id', 1)->first(); $reward_point=$request->products['amount'][0]*$set->referral_commission/100*$set->point_per_dollar; $reward_amt=$request->products['amount'][0]*$set->referral_commission/100; $client = Client::where('id', $deal_id['client_id'])->first(); $deals_reward=Deal::where('id',$deal_id->id)->first(); if($deals_reward->reward_point){ if($client->reward_point == $deals_reward->reward_point){ $rewards_points = $deals_reward->reward_point; }else{ $rewards_points = $client->reward_point - $deals_reward->reward_point; if($rewards_points <0){ $rewards_points=0; } } if($client->reward_amount ==$deals_reward->reward_amount){ $rewards_amount = $deals_reward->reward_amount; }else{ $rewards_amount = $client->reward_amount - $deals_reward->reward_amount; if($rewards_amount <0){ $rewards_amount=0; } } Deal::where('id', $deal_id->id)->update(['reward_point'=>(int)$rewards_points,'reward_amount'=>$rewards_amount]); Client::where('id', $client->id)->update(['reward_amount' => (int)$rewards_amount, 'reward_point' => (int)$rewards_points]); }else{ $set = Setting::where('id','!=',0)->first(); $reward_point=$request->products['amount'][0]*$set->referral_commission/100*$set->point_per_dollar; $reward_amt=$request->products['amount'][0]*$set->referral_commission/100; Deal::where('id', $deal_id->id)->update(['reward_point'=>(int)$reward_point , 'reward_amount'=> (int)$reward_amt]); Client::where('id', $client->id)->update(['reward_amount' =>$reward_amt, 'reward_point' => $reward_point]); } // Client::where('id', $client->id)->update(['reward_amount' => $rewards_amount, 'reward_point' => $rewards_points]); // echo '1223'; $set = Setting::where('id','!=',0)->first(); $reward_point=$request->products['amount'][0]*$set->referral_commission/100*$set->point_per_dollar; $reward_amt=$request->products['amount'][0]*$set->referral_commission/100; DB::update('UPDATE deals SET reward_point = ?, reward_amount = ? WHERE id = ?', [$reward_point,(int)$reward_amt, $deal_id->id]); } //exit; // $update_reward = Client::where('id', $client->id)->update(['reward_amount' => $reward_amount, 'reward_point' => $reward_points]); est */ if (empty($deal_id->dollar_rate)) { if($user->country_id==1){ $url = 'https://api.exchangerate-api.com/v4/latest/USD'; }elseif ($user->country_id==2){ $url = 'https://api.exchangerate-api.com/v4/latest/AUD'; }elseif ($user->country_id==3){ $url = 'https://api.exchangerate-api.com/v4/latest/GBP'; } $json = file_get_contents($url); $exp = json_decode($json); $convert = $exp->rates->PKR; $request['dollar_rate'] = $convert; } else { $request['dollar_rate'] = $request['dollar_rate']; } } if ($request['bd_pipeline_stage_id'] == 4){ // echo 'asdas';exit; /* est if($request['use_commission'] == 1 ) { $set = Setting::where('id', 1)->first(); $reward_point=$request->products['amount'][0]*$set->referral_commission/100*$set->point_per_dollar; $reward_amt=$request->products['amount'][0]*$set->referral_commission/100; $client = Client::where('id', $deal_id['client_id'])->first(); $deals_reward=Deal::where('id',$deal_id->id)->first(); if($deals_reward->reward_point){ if($client->reward_point == $deals_reward->reward_point){ $rewards_points = $deals_reward->reward_point; }else{ $rewards_points = $client->reward_point - $deals_reward->reward_point; if($rewards_points <0){ $rewards_points=0; } } if($client->reward_amount ==$deals_reward->reward_amount){ $rewards_amount = $deals_reward->reward_amount; }else{ $rewards_amount = $client->reward_amount - $deals_reward->reward_amount; if($rewards_amount <0){ $rewards_amount=0; } } Deal::where('id', $deal_id->id)->update(['reward_point'=>(int)$rewards_points,'reward_amount'=>$rewards_amount]); Client::where('id', $client->id)->update(['reward_amount' => (int)$rewards_amount, 'reward_point' => (int)$rewards_points]); }else{ $set = Setting::where('id','!=',0)->first(); $reward_point=$request->products['amount'][0]*$set->referral_commission/100*$set->point_per_dollar; $reward_amt=$request->products['amount'][0]*$set->referral_commission/100; Deal::where('id', $deal_id->id)->update(['reward_point'=>(int)$reward_point , 'reward_amount'=> (int)$reward_amt]); Client::where('id', $client->id)->update(['reward_amount' =>$reward_amt, 'reward_point' => $reward_point]); } // Client::where('id', $client->id)->update(['reward_amount' => $rewards_amount, 'reward_point' => $rewards_points]); // echo '1223'; $set = Setting::where('id','!=',0)->first(); $reward_point=$request->products['amount'][0]*$set->referral_commission/100*$set->point_per_dollar; $reward_amt=$request->products['amount'][0]*$set->referral_commission/100; DB::update('UPDATE deals SET reward_point = ?, reward_amount = ? WHERE id = ?', [$reward_point,(int)$reward_amt, $deal_id->id]); } //exit; // $update_reward = Client::where('id', $client->id)->update(['reward_amount' => $reward_amount, 'reward_point' => $reward_points]); est */ if (empty($deal_id->dollar_rate)) { if($user->country_id==1){ $url = 'https://api.exchangerate-api.com/v4/latest/USD'; }elseif ($user->country_id==2){ $url = 'https://api.exchangerate-api.com/v4/latest/AUD'; }elseif ($user->country_id==3){ $url = 'https://api.exchangerate-api.com/v4/latest/GBP'; } $json = file_get_contents($url); $exp = json_decode($json); $convert = $exp->rates->PKR; $request['dollar_rate'] = $convert; } else { $request['dollar_rate'] = $request['dollar_rate']; } } if($request['designer_work']==3 || $request['designer_work']==1 ){ /// echo 'dsdasd';exit; Deal::where('id', $deal_id->id)->update(['designer_work' => '3','design_complete_status'=>1,'designer_status'=>1,'designer_id'=>'1000']); }else{ Deal::where('id', $deal_id->id)->update(['designer_work' => $request['designer_work']]); } $domain_code=Domains::where('id',$request['domain_id'])->first(); if (auth()->user()->hasRole('super-admin') || auth()->user()->hasRole('Team Lead')|| auth()->user()->hasRole('Sales Data Entry')) { if ($request['show_follow_up'] == '1') { if ($request['open_date'] >= '2022-01-01') { $old_orderno = explode('-', $request['order_no']); if (count($old_orderno) > 2) { $orderold = $old_orderno[2]; } else { $orderold = $old_orderno[1]; } if (auth()->user()->hasRole('super-admin') || auth()->user()->hasRole('Team Lead') || auth()->user()->hasRole('Sales Data Entry')) { $owners_name = User::where('id', $request['owner_id'])->first(); } else { $owners_name = User::where('id', auth()->user()->id)->first(); } $domain_code=Domains::where('id',$request['domain_id'])->first(); $first = $owners_name->first_name; $last = $owners_name->last_name; $old_orderno = explode('-', $request['order_no']); if (count($old_orderno) > 2) { $orderold = $old_orderno[2]; } else { $orderold = $old_orderno[1]; } $new_orderno = $domain_code->domain_code . '-' . $first[0] . $last[0] . '-' . $orderold; if (!auth()->user()->hasRole('super-admin')|| !auth()->user()->hasRole('Sales Data Entry')){ $request['order_number'] = $new_orderno; $request['order_number'] = $new_orderno; }else{ $request['order_number'] = $request['order_no']; } // echo $request['order_number']; exit; Deal::where('id', $deal_id->id)->update(['order_number' => $request['order_number'], 'order_no' => $request['order_number']]); } //echo '23423';exit; } else if ( $request['show_follow_up'] == 4) { if (auth()->user()->hasRole('super-admin') || auth()->user()->hasRole('Team Lead') || auth()->user()->hasRole('Sales Data Entry')) { $owners_name = User::where('id', $request['bd_owner_id'])->first(); } else { $owners_name = User::where('id', auth()->user()->id)->first(); } $first = $owners_name->first_name; $last = $owners_name->last_name; // print_r($owners_name);exit; if ($request['existing'] == 1) { $orderNumber = $request['bd_order_no']; } else { $old_orderno = explode('-', $request['bd_order_no']); if (count($old_orderno) > 2) { $orderold = $old_orderno[2]; } else { $orderold = $old_orderno[1]; } $orderNumber = $domain_code->domain_code . '-' . $first[0] . $last[0] . '-' . $orderold; } $request['bd_order_number'] = $orderNumber; Deal::where('id', $deal_id->id)->update(['bd_order_number' => $request['bd_order_number'],'order_no' => $request['order_number']]); // echo 'sdas';exit; } else if ( auth()->user()->hasRole('super-admin') && $request['ob_owner_id'] != '' ) { // echo 'e43242';exit; if (auth()->user()->hasRole('super-admin') || auth()->user()->hasRole('Team Lead') || auth()->user()->hasRole('Sales Data Entry')) { $owners_name = User::where('id', $request['ob_owner_id'])->first(); } else { $owners_name = User::where('id', $request['ob_owner_id'])->first(); } $first = $owners_name->first_name; $last = $owners_name->last_name; // print_r($owners_name);exit; if ($request['existing'] == 1) { $orderNumber = $request['ob_order_no']; } else { $old_orderno = explode('-', $request['ob_order_no']); if (!empty($request['ob_order_no'])) { if (count($old_orderno) > 2) { $orderold = $old_orderno[2]; } else { $orderold = $old_orderno[1]; } $orderNumber = $domain_code->domain_code . '-' . $first[0] . $last[0] . '-' . $orderold; $request['ob_order_number'] = $orderNumber; $request['ob_order_number'] = $orderNumber; } else { $orderNumber = $domain_code->domain_code . '-' . $first[0] . $last[0] . '-' . time(); $request['ob_order_number'] = $orderNumber; $request['ob_order_number'] = $orderNumber; } // echo $orderNumber;exit; } } }elseif($deal_id->show_follow_up==1){ //if ($request['open_date'] >= '2022-01-01') { $old_orderno = explode('-', $request['order_no']); if (count($old_orderno) > 2) { $orderold = $old_orderno[2]; } else { $orderold = $old_orderno[1]; } if (auth()->user()->hasRole('super-admin') || auth()->user()->hasRole('Team Lead') || auth()->user()->hasRole('Sales Data Entry')) { $owners_name = User::where('id', $request['owner_id'])->first(); } else { $owners_name = User::where('id', auth()->user()->id)->first(); } $first = $owners_name->first_name; $last = $owners_name->last_name; $old_orderno = explode('-', $request['order_no']); if (count($old_orderno) > 2) { $orderold = $old_orderno[2]; } else { $orderold = $old_orderno[1]; } $new_orderno = $domain_code->domain_code . '-' . $first[0] . $last[0] . '-' . $orderold; $request['order_number'] = $new_orderno; $request['order_number'] = $new_orderno; Deal::where('id', $deal_id->id)->update(['order_number' => $request['order_number'], 'order_no' => $request['order_number']]); }elseif($deal_id->show_follow_up==4){ if (auth()->user()->hasRole('super-admin') || auth()->user()->hasRole('Team Lead') || auth()->user()->hasRole('Sales Data Entry')) { $owners_name = User::where('id', $request['bd_owner_id'])->first(); } else { $owners_name = User::where('id', auth()->user()->id)->first(); } $first = $owners_name->first_name; $last = $owners_name->last_name; // print_r($owners_name);exit; if ($request['existing'] == 1) { $orderNumber = $request['bd_order_no']; } else { $old_orderno = explode('-', $request['bd_order_no']); if (count($old_orderno) > 2) { $orderold = $old_orderno[2]; } else { $orderold = $old_orderno[1]; } $orderNumber = $domain_code->domain_code . '-' . $first[0] . $last[0] . '-' . $orderold; } $request['bd_order_number'] = $orderNumber; Deal::where('id', $deal_id->id)->update(['bd_order_number' => $request['bd_order_number'],'order_no' => $request['order_number'],'bd_pipeline_stage_id' => $request['bd_pipeline_stage_id']]); } /// echo 'asdasd';exit; // print_r( $request['ob_order_number']);exit; if(!empty($request->products['est_amount_0'][0])){ $est_amount0=$request->products['est_amount_0'][0]; }else{ $est_amount0=0; } Deal::where('id', $id)->update(['est_amount'=>$est_amount0]); $request['product_id']=$request['products']['product_id'][0]; Deal::where('id', $id)->update(['product_id'=>$request['products']['product_id'][0]]); $clients = Client::where('id', $deal_id->client_id)->update(['company_name' => $request['company_name'],'name' => $request['client_name']]); if(isset($request['company_email']) && isset($request['company_phone_no'])){ $emails=explode(',',$request['company_email'] ) ; $phone_nos=explode(',',$request['company_phone_no'] ) ; EmailPhoneDetail::where('model_id', $deal_id->client_id)->delete(); foreach($emails as $email){ EmailPhoneDetail::Create(['type'=>'email','value' => $email,'model_type'=>'App\Models\Client','model_id'=>$deal_id->client_id]); } foreach($phone_nos as $phone_no){ EmailPhoneDetail::Create(['type'=>'phone_no','value' => $phone_no,'model_type'=>'App\Models\Client','model_id'=>$deal_id->client_id]); } } if(auth()->user()->hasRole('Bd')=='Bd' || auth()->user()->hasRole('Business Development Sales Agent')=='Business Development Sales Agent' || auth()->user()->hasRole('Sale Agent + BD')=='Sale Agent + BD' ) { Deal::where('id', $id)->update(['bd_pipeline_stage_id' => $request['bd_pipeline_stage_id'],'bd_order_number'=> $request['bd_order_number']]); }elseif( auth()->user()->hasRole('outbound')=='outbound'){ Deal::where('id', $id)->update(['ob_pipeline_stage_id' => $request['ob_pipeline_stage_id'],'ob_order_number'=> $request['ob_order_number']]); } $deal = $this->repository->update($request->except(['order_number', 'order_no','bd_order_number','attachments','products','pipeline_stage_id']),$id); if(empty($deal_id->dollar_rate)){ $amount0=$request->products['amount'][0]; if($amount0){ Deal::where('id', $deal_id->id)->update(['dollar_rate' => $request['dollar_rate']]); } } if($request['pipeline_stage_id']==4){ if(auth()->user()->hasRole('super-admin') || auth()->user()->hasRole('Sales Data Entry')){ Deal::where('id', $deal_id->id)->update(['pipeline_stage_id' => $request['pipeline_stage_id'],'designer_work'=>'2']); } }else{ Deal::where('id', $deal_id->id)->update(['pipeline_stage_id' => $request['pipeline_stage_id'],'designer_work'=>'2']); } if($request['show_follow_up']=='1' && $request['pipeline_stage_id']=='11'){ // Deal::where('id', $deal_id->id)->update(['show_follow_up' => $request['show_follow_up'],'pipeline_stage_id' => 3]); } if(isset($request->production_billing_date)) { $formattedDate = Carbon::createFromFormat('Y-m', $request->production_billing_date)->startOfMonth()->format('Y-m-d'); Deal::where('id', $deal_id->id)->update(['production_billing_date' => $formattedDate]); } if(isset($request->shipping_date)){ $shipping_date = Carbon::createFromFormat('Y-m', $request->shipping_date)->startOfMonth()->format('Y-m-d'); Deal::where('id', $deal_id->id)->update(['shipping_date' => $shipping_date]); } if (auth()->user()->hasRole('super-admin') || auth()->user()->hasRole('Team Lead')) { if($request['show_follow_up']=='1' ) { Deal::where('id', $deal_id->id)->update(['order_number' => $request['order_number'], 'order_no' => $request['order_number']]); } } if($request['show_follow_up']=='4' && $request['bd_pipeline_stage_id']=='4'){ Deal::where('id', $deal_id->id)->update(['bd_close_date' => $request['bd_close_date'],'close_date' => '','open_date' => '']); } if($request['production_from']=='2'){ Deal::where('id', $id)->update(['production_from' => '2']); }else{ Deal::where('id', $id)->update(['production_from' => '1']); } if($request['production_from']=='2'){ if (str_ends_with($request['order_no'], '-CN')) { Deal::where('id', $deal_id->id)->update(['order_number' => $request['order_no'] , 'order_no' => $request['order_no'] ]); }else{ Deal::where('id', $deal_id->id)->update(['order_number' => $request['order_no'] . '-CN', 'order_no' => $request['order_no'] . '-CN']); } }else{ // Deal::where('id', $deal_id->id)->update(['order_number' => $request['order_number'], 'order_no' => $request['order_number']]); } if($request->has('attachments')){ $this->saveUpdateAttachments($request->attachments, $deal ); } if($request->has('products')){ $this->saveUpdateProducts($request->products,$deal); } return $deal; }catch (\Exception $e){ return ['message'=>$e->getMessage()] ; } } public function Getusers(){ return \App\Models\User::where('status','active')->get(); } public function UpdateFirstSaleStatus($request){ return DealNotification::where('id', $request->id)->update(['first_sale' => '0']); } public function updateChinaEstimation($id,$request){ // //DealProduct:: if($request->hasFile('china_image')){ $file = $request->file('china_image'); $path = 'assets/china_image/'; $file_name = $file->getClientOriginalName(); if ($file->isValid()) { $file->move(public_path($path), $file_name); $fb_file_path = $path.$file_name; $files_name = $file_name; } else { return back()->with('error', 'Image upload error.'); } Deal::where('id', $id)->update(['china_image'=>$fb_file_path ]); } if($request->hasFile('china_doc')){ $files = $request->file('china_doc'); $path = 'assets/china_doc/'; $china_docfile_name = $files->getClientOriginalName(); if ($files->isValid()) { $files->move(public_path($path), $china_docfile_name); // $china_doc_file_path = $china_docfile_name; $files_name_china_doc = $path.$china_docfile_name; } else { return back()->with('error', 'Document upload error.'); } Deal::where('id', $id)->update([ 'china_doc'=>$files_name_china_doc ]); } DealProduct::where('id', $request['deal_product_id'])->update(['open_product_width'=>$request['open_product_width'], 'open_product_height'=>$request['open_product_height'], 'insert_open_product_width'=>$request['insert_open_product_width'], 'insert_open_product_height'=>$request['insert_open_product_height'], 'open_product_width_two'=>$request['open_product_width_two'], 'open_product_height_two'=>$request['open_product_height_two'], 'insert_open_product_width_two'=>$request['insert_open_product_width_two'], 'insert_open_product_height_two'=>$request['insert_open_product_height_two'], 'insert_open_product_width_three'=>$request['insert_open_product_width_three'], 'insert_open_product_height_three'=>$request['insert_open_product_height_three'], 'product_style_id'=>$request['product_style_id'],'product_length'=>$request['length'], 'product_width'=>$request['width'],'product_height'=>$request['height'], 'product_color_id'=>$request['product_color'], 'product_width'=>$request['width'], 'product_height'=>$request['height'], 'product_length'=>$request['length'], 'product_stock_id'=>$request['material']]); $qea= QuantityAndEstimation::where('deal_product_id',$request['deal_product_id'])->get(); $deal= Deal::where('id', $id)->first(); if($deal->pipeline_stage_id!=4){ Deal::where('id', $id)->update(['est_amount' => $request['sale_total_cost'][0], 'lamination' => $request['laminations'] , 'gsm' => $request['card_stock_gsm'] , 'foiling' => $request['foilings'] , 'material' => $request['material'] , 'uv' => $request['uvs'] , 'pipeline_stage_id' => '11' , 'embossing' => $request['embossings'] , 'china_note' => $request['china_note'] , 'special_instruction' => $request['special_instruction'] , 'estimation' =>3 ]); }else{ Deal::where('id', $id)->update(['est_amount' => $request['sale_total_cost'][0], 'lamination' => $request['laminations'] , 'gsm' => $request['card_stock_gsm'] , 'foiling' => $request['foilings'] , 'material' => $request['material'] , 'uv' => $request['uvs'] , 'pipeline_stage_id' => '4' , 'china_note' => $request['china_note'] , 'embossing' => $request['embossings'] , 'special_instruction' => $request['special_instruction'] , 'estimation' =>3 ]); } if(auth()->user()->agent==2){ Deal::where('id', $id)->update(['estimator_id' => auth()->user()->id]); } foreach ($qea as $k=> $q){ if(empty($request['sale_total_cost'][$k])){ QuantityAndEstimation::where('id', $q->id)->update(['deal_product_est_amount'=>$request['sale_total_cost'][$k],'deal_product_quantity'=>$request['qty'][$k],'no_of_design'=>$request['designs'][$k],'sea_estimation'=>$request['sale_total_cost_sea'][$k]]); }else{ QuantityAndEstimation::where('id', $q->id)->update(['deal_product_est_amount'=>$request['sale_total_cost'][$k],'deal_product_quantity'=>$request['qty'][$k],'no_of_design'=>$request['designs'][$k],'sea_estimation'=>$request['sale_total_cost_sea'][$k]]); } } DealEstimation::where('deal_id',$id)->delete(); $saleTotalCosts = $request['sale_total_cost'] ?? []; // Ensure it's an array // If it's empty, set a fixed 6 iterations $totalIterations = !empty($saleTotalCosts) ? count($saleTotalCosts) : 6; for ($i = 0; $i < $totalIterations; $i++) { $creat_est = [ 'total_cost_dollar' => $request['total_cost'][$i] ?? null, 'sale_price_for_customer' => $request['sale_total_cost'][$i] ?? null, 'profit_pre' => $request['profit_pre'][$i] ?? null, 'deal_id' => $id, 'per_unit_price_dollar' => $request['per_unit_cost'][$i] ?? null, 'per_unit_cost_sea' => $request['per_unit_cost_sea'][$i] ?? null, 'sale_total_cost_sea' => $request['sale_total_cost_sea'][$i] ?? null, 'profit_pre_sea' => $request['profit_pre_sea'][$i] ?? null, 'total_cost_sea' => $request['total_cost_sea'][$i] ?? null, ]; $deal_est = DealEstimation::create($creat_est); $creat_estlog = [ 'total_cost_dollar' => $request['total_cost'][$i] ?? null, 'estimation_id' => $deal_est->id, 'deal_id' => $id, 'sale_price_for_customer' => $request['sale_total_cost'][$i] ?? null, 'profit_pre' => $request['profit_pre'][$i] ?? null, 'per_unit_price_dollar' => $request['per_unit_cost'][$i] ?? null, 'per_unit_cost_sea' => $request['per_unit_cost_sea'][$i] ?? null, 'sale_total_cost_sea' => $request['sale_total_cost_sea'][$i] ?? null, 'profit_pre_sea' => $request['profit_pre_sea'][$i] ?? null, 'total_cost_sea' => $request['total_cost_sea'][$i] ?? null, ]; $deal_log = DealEstimationlog::create($creat_estlog); } return $deal_log; // return $request; } public function updateEstimation($id,$request){ // //DealProduct:: DealProduct::where('id', $request['deal_product_id'])->update(['open_product_width'=>$request['open_product_width'], 'open_product_height'=>$request['open_product_height'], 'insert_open_product_width'=>$request['insert_open_product_width'], 'insert_open_product_height'=>$request['insert_open_product_height'], 'open_product_width_two'=>$request['open_product_width_two'], 'open_product_height_two'=>$request['open_product_height_two'], 'insert_open_product_width_two'=>$request['insert_open_product_width_two'], 'insert_open_product_height_two'=>$request['insert_open_product_height_two'], 'insert_open_product_width_three'=>$request['insert_open_product_width_three'], 'insert_open_product_height_three'=>$request['insert_open_product_height_three'], 'product_style_id'=>$request['product_style_id'],'product_length'=>$request['length'], 'product_width'=>$request['width'],'product_height'=>$request['height'], 'product_color_id'=>$request['product_color'], 'product_width'=>$request['width'], 'product_height'=>$request['height'], 'product_length'=>$request['length'], 'product_stock_id'=>$request['material']]); $qea= QuantityAndEstimation::where('deal_product_id',$request['deal_product_id'])->get(); $deal=Deal::where('id',$id)->first(); if($request['est_total_cost'][0] >0) { if($deal->pipeline_stage_id!=4){ Deal::where('id', $id)->update(['est_amount' => $request['sale_total_cost'][0], 'lamination' => $request['laminations'] , 'gsm' => $request['card_stock_gsm'] , 'foiling' => $request['foilings'] , 'material' => $request['material'] , 'uv' => $request['uvs'] , 'pipeline_stage_id' => '11' , 'embossing' => $request['embossings'] , 'special_instruction' => $request['special_instruction'] , 'estimation' =>3 ]);}else{ Deal::where('id', $id)->update(['est_amount' => $request['sale_total_cost'][0], 'lamination' => $request['laminations'] , 'gsm' => $request['card_stock_gsm'] , 'foiling' => $request['foilings'] , 'material' => $request['material'] , 'uv' => $request['uvs'] , 'pipeline_stage_id' => '4' , 'embossing' => $request['embossings'] , 'special_instruction' => $request['special_instruction'] , 'estimation' =>3 ]); } }else{ if($deal->pipeline_stage_id!=4){ Deal::where('id', $id)->update(['est_amount' => $request['sale_total_cost'][0], 'lamination' => $request['laminations'] , 'gsm' => $request['card_stock_gsm'] , 'foiling' => $request['foilings'] , 'material' => $request['material'] , 'uv' => $request['uvs'] , 'pipeline_stage_id' => '11' , 'embossing' => $request['embossings'] ]);}else{ Deal::where('id', $id)->update(['est_amount' => $request['sale_total_cost'][0], 'lamination' => $request['laminations'] , 'gsm' => $request['card_stock_gsm'] , 'foiling' => $request['foilings'] , 'material' => $request['material'] , 'uv' => $request['uvs'] , 'pipeline_stage_id' => '4' , 'embossing' => $request['embossings'] , 'special_instruction' => $request['special_instruction'] , 'estimation' =>3 ]); } } if(auth()->user()->agent==2){ Deal::where('id', $id)->update(['estimator_id' => auth()->user()->id]); } foreach ($qea as $k=> $q){ if(empty($request['sale_total_cost'][$k])){ QuantityAndEstimation::where('id', $q->id)->update(['deal_product_est_amount'=>$request['sale_total_cost'][$k],'deal_product_quantity'=>$request['qty'][$k],'no_of_design'=>$request['designs'][$k]]); }else{ QuantityAndEstimation::where('id', $q->id)->update(['deal_product_est_amount'=>$request['est_sale_total_cost'][$k],'deal_product_quantity'=>$request['qty'][$k],'no_of_design'=>$request['designs'][$k]]); } } DealEstimation::where('deal_id',$id)->delete(); foreach ($request['scanning'] as $i=> $scanning){ $creat_est= array( 'scanning'=>$scanning, 'plates_making'=>$request['plates_making'][$i], 'stock'=>$request['stock'][$i], 'nali_roll'=>$request['nali_roll'][$i]??'', 'corrugation_pasting'=>$request['pasting'][$i], 'printing'=>$request['printing'][$i], 'mate_glossy'=>$request['mlamination'][$i], 'soft_touch'=>$request['slamination'][$i], 'block_macking'=>$request['block'][$i], 'die_making'=>$request['making'][$i], 'die_cutting_perforation'=>$request['die_cutting'][$i], 'uv'=>$request['uv'][$i], 'embossing_debossing'=>$request['embossing'][$i], 'foiling'=>$request['foiling'][$i], 'pvc_window_sheet'=>$request['pvc_sheet'][$i], 'pvt_window_pasting'=>$request['pvc_pasting'][$i], 'varnish_coating'=>$request['varnish'][$i], 'silk_screen_making'=>$request['silk'][$i], 'cutting'=>$request['creasing'][$i], 'pasting'=>$request['pasting_gt'][$i], 'binding'=>$request['binding'][$i], 'packing'=>$request['packing'][$i], 'labor'=>$request['labor'][$i], 'misc'=>$request['misc'][$i], 'cost_total'=>$request['ctotal'][$i], 'vendor_profit'=>$request['vprofit'][$i], 'vendor_total'=>$request['vtotal'][$i], 'production_price_per_unit'=>$request['price_per_unit'][$i], 'weight'=>$request['weight'][$i], 'est_printing_cost_dollar'=>$request['est_printing_cost'][$i], 'shipping_line'=>$request['courier_id'][$i]??'', 'est_shipping_cost_dollar'=>$request['est_shipping_cost'][$i], 'total_cost_dollar'=>$request['total_cost'][$i], 'sale_price_for_customer'=>$request['sale_total_cost'][$i], 'profit_pre'=>$request['profit_pre'][$i], 'deal_id'=>$id, 'per_unit_price_dollar'=>$request['per_unit_cost'][$i], 'est_weight'=>$request['est_weight'][$i], 'estimator_shipping_cost'=>$request['estimator_shipping_cost'][$i], 'est_total_cost'=>$request['est_total_cost'][$i], 'est_sale_total_cost'=>$request['est_sale_total_cost'][$i], 'est_per_unit_cost'=>$request['est_per_unit_cost'][$i], ); $deal_est= DealEstimation::Create($creat_est); $creat_estlog= array( 'scanning'=>$scanning, 'plates_making'=>$request['plates_making'][$i], 'stock'=>$request['stock'][$i], 'nali_roll'=>$request['nali_roll'][$i]??'', 'corrugation_pasting'=>$request['pasting'][$i], 'printing'=>$request['printing'][$i], 'mate_glossy'=>$request['mlamination'][$i], 'soft_touch'=>$request['slamination'][$i], 'block_macking'=>$request['block'][$i], 'die_making'=>$request['making'][$i], 'die_cutting_perforation'=>$request['die_cutting'][$i], 'uv'=>$request['uv'][$i], 'embossing_debossing'=>$request['embossing'][$i], 'foiling'=>$request['foiling'][$i], 'pvc_window_sheet'=>$request['pvc_sheet'][$i], 'pvt_window_pasting'=>$request['pvc_pasting'][$i], 'varnish_coating'=>$request['varnish'][$i], 'silk_screen_making'=>$request['silk'][$i], 'cutting'=>$request['creasing'][$i], 'pasting'=>$request['pasting_gt'][$i], 'binding'=>$request['binding'][$i], 'packing'=>$request['packing'][$i], 'labor'=>$request['labor'][$i], 'misc'=>$request['misc'][$i], 'cost_total'=>$request['ctotal'][$i], 'vendor_profit'=>$request['vprofit'][$i], 'vendor_total'=>$request['vtotal'][$i], 'production_price_per_unit'=>$request['price_per_unit'][$i], 'weight'=>$request['weight'][$i], 'est_printing_cost_dollar'=>$request['est_printing_cost'][$i], 'shipping_line'=>$request['courier_id'][$i]??'', 'est_shipping_cost_dollar'=>$request['est_shipping_cost'][$i], 'total_cost_dollar'=>$request['total_cost'][$i], 'sale_price_for_customer'=>$request['sale_total_cost'][$i], 'profit_pre'=>$request['profit_pre'][$i], 'estimation_id'=>$deal_est->id, 'deal_id'=>$id, 'per_unit_price_dollar'=>$request['per_unit_cost'][$i], 'est_weight'=>$request['est_weight'][$i], 'estimator_shipping_cost'=>$request['estimator_shipping_cost'][$i], 'est_total_cost'=>$request['est_total_cost'][$i], 'est_sale_total_cost'=>$request['est_sale_total_cost'][$i], 'est_per_unit_cost'=>$request['est_per_unit_cost'][$i], ); $deal_log= DealEstimationlog::Create($creat_estlog); } return $deal_log; // return $request; } public function saveUpdateProducts($product_details , $deal , $id = null) { if(is_array($product_details)){ $deal_product_printing=array(); $deal_product_qty=array(); $x=0; $totalproduct=count($product_details['product_id']); //print_r($totalproduct);exit; $products_details=array(); while($x <= $totalproduct) { if(!empty($product_details['product_id'][$x])){ $products_details[$product_details['product_id'][$x]]=array( 'product_id'=>$product_details['product_id'][$x], 'created_at'=>$deal['open_date'], 'product_style_id' => $product_details['product_style_id'][$x], 'product_length'=>$product_details['product_length'][$x], 'product_width'=>$product_details['product_width'][$x], 'product_height'=>$product_details['product_height'][$x], 'open_product_width'=>$product_details['open_product_width'][$x], 'open_product_height'=>$product_details['open_product_height'][$x], 'open_product_width_two'=>$product_details['open_product_width_two'][$x], 'open_product_height_two'=>$product_details['open_product_height_two'][$x], 'insert_open_product_width'=>$product_details['insert_open_product_width'][$x], 'insert_open_product_height'=>$product_details['insert_open_product_height'][$x], 'insert_open_product_height'=>$product_details['insert_open_product_height'][$x], 'insert_open_product_width_two'=>$product_details['insert_open_product_width_two'][$x], 'insert_open_product_height_two'=>$product_details['insert_open_product_height_two'][$x], 'insert_open_product_height_two'=>$product_details['insert_open_product_height_two'][$x], 'insert_open_product_width_three'=>$product_details['insert_open_product_width_three'][$x], 'insert_open_product_height_three'=>$product_details['insert_open_product_height_three'][$x], 'insert_open_product_height_three'=>$product_details['insert_open_product_height_three'][$x], 'insert_product_width'=>$product_details['insert_product_width'][$x], 'insert_product_height'=>$product_details['insert_product_height'][$x], 'product_stock_id'=>$product_details['product_stock_id'][$x], 'product_measurement_unit_id'=>$product_details['product_measurement_unit'][$x], 'product_color_id'=>$product_details['product_color'][$x], 'product_size'=>$product_details['product_width'][$x].' x '.$product_details['product_length'][$x].' x '.$product_details['product_height'][$x], ); Deal::where('id', $deal['id'])->update(['material'=>$product_details['product_stock_id'][$x]]); } $x++; } Deal::where('id', $deal['id'])->update(['est_amount'=> $product_details['est_amount_0'][0]]); $deal->products()->sync($products_details); $deal_products=DealProduct::where('deal_id',$deal->id)->get(); // print_r($deal_products);exit; $deal_product_qty=array(); $x=0; $receive_amount=0; $receive_amount= array_sum($product_details['amounts']); foreach ($deal_products as $key => $dp) { $d_product = DealProduct::find($dp->id); $d = QuantityAndEstimation::where('deal_product_id', $dp->id)->delete(); if(isset($product_details['product_printing'][$key])) { $d_product->product_printings()->sync($product_details['product_printing'][$key]); } $i = 0; if (!empty($product_details['product_checked_value_0'][$key])) { Production::where('deal_id', $deal->id)->update(['qty' => $product_details['product_checked_value_0'][$key]]); $checked_value0 = $product_details['product_checked_value_0'][$key]; } else { $checked_value0 = 0; } if (!empty($product_details['product_checked_value_1'][$key])) { $checked_value1 = $product_details['product_checked_value_1'][$key]; } else { $checked_value1 = 0; } if (!empty($product_details['product_checked_value_2'][$key])) { $checked_value2 = $product_details['product_checked_value_2'][$key]; } else { $checked_value2 = 0; } if (!empty($product_details['product_checked_value_3'][$key])) { $checked_value3 = $product_details['product_checked_value_3'][$key]; } else { $checked_value3 = 0; } if (!empty($product_details['product_checked_value_4'][$key])) { $checked_value4 = $product_details['product_checked_value_4'][$key]; } else { $checked_value4 = 0; } if (!empty($product_details['product_checked_value_5'][$key])) { $checked_value5 = $product_details['product_checked_value_5'][$key]; } else { $checked_value5 = 0; } if (!empty($product_details['product_quantity_0'][$key])) { Production::where('deal_id', $deal->id)->update(['qty' => $product_details['product_quantity_0'][$key]]); $dealqty0 = $product_details['product_quantity_0'][$key]; } else { $dealqty0 = 0; } if (!empty($product_details['product_quantity_1'][$key])) { $dealqty1 = $product_details['product_quantity_1'][$key]; } else { $dealqty1 = 0; } if (!empty($product_details['product_quantity_2'][$key])) { $dealqty2 = $product_details['product_quantity_2'][$key]; } else { $dealqty2 = 0; } if (!empty($product_details['product_quantity_3'][$key])) { $dealqty3 = $product_details['product_quantity_3'][$key]; } else { $dealqty3 = 0; } if (!empty($product_details['product_quantity_4'][$key])) { $dealqty4 = $product_details['product_quantity_4'][$key]; } else { $dealqty4 = 0; } if (!empty($product_details['product_quantity_5'][$key])) { $dealqty5 = $product_details['product_quantity_5'][$key]; } else { $dealqty5 = 0; } if (!empty($product_details['est_amount_0'][$key])) { $est_amount0 = $product_details['est_amount_0'][$key]; } else { $est_amount0 = 0; } if (!empty($product_details['est_amount_1'][$key])) { $est_amount1 = $product_details['est_amount_1'][$key]; } else { $est_amount1 = 0; } if (!empty($product_details['est_amount_2'][$key])) { $est_amount2 = $product_details['est_amount_2'][$key]; } else { $est_amount2 = 0; } if (!empty($product_details['est_amount_3'][$key])) { $est_amount3 = $product_details['est_amount_3'][$key]; } else { $est_amount3 = 0; } if (!empty($product_details['est_amount_4'][$key])) { $est_amount4 = $product_details['est_amount_4'][$key]; } else { $est_amount4 = 0; } if (!empty($product_details['est_amount_5'][$key])) { $est_amount5 = $product_details['est_amount_5'][$key]; } else { $est_amount5 = 0; } if (!empty($product_details['no_of_design_0'][$key])) { $no_of_design_0 = $product_details['no_of_design_0'][$key]; } else { $no_of_design_0 = 0; } if (!empty($product_details['no_of_design_1'][$key])) { $no_of_design_1 = $product_details['no_of_design_1'][$key]; } else { $no_of_design_1 = 0; } if (!empty($product_details['no_of_design_2'][$key])) { $no_of_design_2 = $product_details['no_of_design_2'][$key]; } else { $no_of_design_2 = 0; } if (!empty($product_details['no_of_design_3'][$key])) { $no_of_design_3 = $product_details['no_of_design_3'][$key]; } else { $no_of_design_3 = 0; } if (!empty($product_details['no_of_design_4'][$key])) { $no_of_design_4 = $product_details['no_of_design_4'][$key]; } else { $no_of_design_4 = 0; } if (!empty($product_details['no_of_design_5'][$key])) { $no_of_design_5 = $product_details['no_of_design_5'][$key]; } else { $no_of_design_5 = 0; } if (!empty($product_details['sea_estimation_0'][$key])) { $sea_estimation_0 = $product_details['sea_estimation_0'][$key]; } else { $sea_estimation_0 = 0; } if (!empty($product_details['sea_estimation_1'][$key])) { $sea_estimation_1 = $product_details['sea_estimation_1'][$key]; } else { $sea_estimation_1 = 0; } if (!empty($product_details['sea_estimation_2'][$key])) { $sea_estimation_2 = $product_details['sea_estimation_2'][$key]; } else { $sea_estimation_2 = 0; } if (!empty($product_details['sea_estimation_3'][$key])) { $sea_estimation_3 = $product_details['sea_estimation_3'][$key]; } else { $sea_estimation_3 = 0; } if (!empty($product_details['sea_estimation_4'][$key])) { $sea_estimation_4 = $product_details['sea_estimation_4'][$key]; } else { $sea_estimation_4 = 0; } if (!empty($product_details['sea_estimation_5'][$key])) { $sea_estimation_5 = $product_details['sea_estimation_5'][$key]; } else { $sea_estimation_5 = 0; } if (!empty($product_details['checked_sea_0'][$key])) { $sea_checked_0 = $product_details['checked_sea_0'][$key]; } else { $sea_checked_0 = 0; } if (!empty($product_details['checked_sea_1'][$key])) { $sea_checked_1 = $product_details['checked_sea_1'][$key]; } else { $sea_checked_1 = 0; } if (!empty($product_details['checked_sea_2'][$key])) { $sea_checked_2 = $product_details['checked_sea_2'][$key]; } else { $sea_checked_2 = 0; } if (!empty($product_details['checked_sea_3'][$key])) { $sea_checked_3 = $product_details['checked_sea_3'][$key]; } else { $sea_checked_3 = 0; } if (!empty($product_details['checked_sea_4'][$key])) { $sea_checked_4 = $product_details['checked_sea_4'][$key]; } else { $sea_checked_4 = 0; } if (!empty($product_details['checked_sea_5'][$key])) { $sea_checked_5 = $product_details['checked_sea_5'][$key]; } else { $sea_checked_5 = 0; } if (!empty($product_details['amount'][$key])) { $amount0 = $product_details['amount'][$key]; } else { $amount0 = 0; } $deal_product_qty = array( 'deal_product_id' => $dp->id, 'deal_product_quantity' => $dealqty0, 'deal_product_est_amount' => $est_amount0, 'checked_value' => $checked_value0, 'no_of_design' => $no_of_design_0, 'sea_estimation' => $sea_estimation_0, 'checked_sea' => $sea_checked_0, 'deal_product_amount' => $product_details['amount'][$key], 'receive_able_amount'=> $receive_amount ); QuantityAndEstimation::Create($deal_product_qty); $deal_product_qty = array( 'deal_product_id' => $dp->id, 'deal_product_quantity' => $dealqty1, 'checked_value' => $checked_value1, 'no_of_design' => $no_of_design_1, 'sea_estimation' => $sea_estimation_1, 'checked_sea' => $sea_checked_1, 'deal_product_est_amount' => $est_amount1, 'deal_product_amount' => $amount0, 'receive_able_amount'=> $receive_amount ); //print_r($deal_product_qty); QuantityAndEstimation::Create($deal_product_qty); $deal_product_qty = array( 'deal_product_id' => $dp->id, 'deal_product_quantity' => $dealqty2, 'checked_value' => $checked_value2, 'no_of_design' => $no_of_design_2, 'sea_estimation' => $sea_estimation_2, 'checked_sea' => $sea_checked_2, 'deal_product_est_amount' => $est_amount2, 'deal_product_amount' => $amount0, 'receive_able_amount'=> $receive_amount ); QuantityAndEstimation::Create($deal_product_qty); $deal_product_qty = array( 'deal_product_id' => $dp->id, 'deal_product_quantity' => $dealqty3, 'checked_value' => $checked_value3, 'deal_product_est_amount' => $est_amount3, 'no_of_design' => $no_of_design_3, 'deal_product_amount' => $amount0, 'sea_estimation' => $sea_estimation_3, 'checked_sea' => $sea_checked_3, 'receive_able_amount'=> $receive_amount ); QuantityAndEstimation::Create($deal_product_qty); $deal_product_qty = array( 'deal_product_id' => $dp->id, 'deal_product_quantity' => $dealqty4, 'checked_value' => $checked_value4, 'no_of_design' => $no_of_design_4, 'sea_estimation' => $sea_estimation_4, 'checked_sea' => $sea_checked_4, 'deal_product_est_amount' => $est_amount4, 'deal_product_amount' => $amount0, 'receive_able_amount'=> $receive_amount ); QuantityAndEstimation::Create($deal_product_qty); $deal_product_qty = array( 'deal_product_id' => $dp->id, 'deal_product_quantity' => $dealqty5, 'checked_value' => $checked_value5, 'no_of_design' => $no_of_design_5, 'sea_estimation' => $sea_estimation_5, 'checked_sea' => $sea_checked_5, 'deal_product_est_amount' => $est_amount5, 'deal_product_amount' => $amount0, 'receive_able_amount'=> $receive_amount ); QuantityAndEstimation::Create($deal_product_qty); $x++; foreach ($product_details['amounts'] as $key=> $amt) { if($amt >=0 && $product_details['receiving_date'][$key]!='' ) { if (isset($product_details['deal_amount_id'][$key])) { DealAmount::where('id', $product_details['deal_amount_id'][$key])->update( ['amount' => $amt, 'payment_type' => $product_details['type'][$key], 'receiving_date' => $product_details['receiving_date'][$key]]); } else { $url = 'https://api.exchangerate-api.com/v4/latest/USD'; $json = file_get_contents($url); $exp = json_decode($json); $convert = $exp->rates->PKR; $products_amount = array( 'amount' => $amt, 'deal_id' => $deal->id, 'dollar_rate' => $convert, 'payment_type' => $product_details['type'][$key], 'receiving_date' => $product_details['receiving_date'][$key] ); DealAmount::Create($products_amount); } } } } } } public function createNote($request,$deal_id) { $deal = Deal::Where('id',$deal_id)->first(); $note['description'] = $request['description']; $deal->notes()->create($note); $value_arr = [ 'user_by' => auth()->user()->getFullName(), 'note_desc' => "" ]; $activity = activityText('activity_note_created', $value_arr); $deal->activities()->create($activity); return $deal; } public function createFollowup($request,$deal_id) { $deal = Deal::Where('id',$deal_id)->first(); $createFollowup = array( 'user_id' => auth()->user()->id, 'follow_up_date' => date('Y-m-d'), 'next_followup_date' => $request['next_followup_date'], 'description' => $request['description'], 'deal_id' =>$deal_id, 'order_number' =>$deal->order_number, 'status' => 'un-read', ); return DealFollowUp::Create($createFollowup); } public function getBoardData($request) { $this->repository->setPresenter("App\\Presenters\\Front\\Deal\\ListPresenter"); $this->repository->pushCriteria(app('Prettus\Repository\Criteria\RequestCriteria')); $this->repository->pushCriteria(new PipelineCriteria($request)); $pipelines = $this->repository; if ($request->has('paginate') && $request->paginate) { $pipelines = $pipelines->paginate(); }else{ $pipelines = $pipelines->all(); } return $pipelines; } }
Close