選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

StatisticController.php 82KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878
  1. <?php
  2. namespace App\Http\Controllers\v3\Main;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use Illuminate\Support\Facades\Auth;
  6. use LynX39\LaraPdfMerger\Facades\PdfMerger;
  7. use Carbon\Carbon;
  8. use Validator;
  9. use Hash;
  10. use App\SiteSetting;
  11. use App\LatestModel\Staff;
  12. use App\LatestModel\StaffDetail;
  13. use App\LatestModel\Module\Form;
  14. use App\LatestModel\Module\Subscriber;
  15. use App\LatestModel\Module\WorkOrder;
  16. use App\LatestModel\Module\PackageDetail;
  17. use App\LatestModel\Module\Docket;
  18. use App\LatestModel\Module\Coverage;
  19. use App\LatestModel\Module\DealerClaim;
  20. use App\LatestModel\Module\Company;
  21. use App\LatestModel\Module\Commission;
  22. use App\LatestModel\Module\Product;
  23. class StatisticController extends Controller
  24. {
  25. /**
  26. * Create statistic main page.
  27. *
  28. * @return post
  29. */
  30. public function viewStatistic(){
  31. $id = Auth::guard('main')->id();
  32. $user = Staff::with('StaffDetail')->find($id);
  33. $site = SiteSetting::first();
  34. $company = Company::where('team','Dealer')->orderBy('name','ASC')->get();
  35. return view('v3.main-dashboard.statictis_index', compact('user','site','company'));
  36. }
  37. public function index(){
  38. $id = Auth::guard('ms')->id();
  39. $user = Staff::with('StaffDetail')->find($id);
  40. return view('market.index',compact('user'));
  41. }
  42. //Dealer's List
  43. public function marketindex(){
  44. $id = Auth::guard('ms')->id();
  45. $user = Staff::with('StaffDetail')->find($id);
  46. $marketdetail= Company::where('team','Dealer')->orderBy('created_at','desc')->get();
  47. $curr = Carbon::now()->getTimestamp();
  48. $i = 0;
  49. $nested_data = array();
  50. if(!empty($marketdetail)){
  51. foreach ($marketdetail as $a)
  52. {
  53. $i++; $n1 = '';
  54. $reg_time = $a->created_at;
  55. $expiry_date = $reg_time->addDays(3);
  56. $expiry_date = $expiry_date->getTimestamp();
  57. if($curr < $expiry_date) {
  58. $n1 = "New/";
  59. }
  60. array_push($nested_data, array(
  61. 'index' => $n1.$i,
  62. 'name' => $a->name,
  63. 'address' => $a->address,
  64. 'city' => $a->city,
  65. 'state' => $a->state,
  66. 'postcode' => $a->postcode,
  67. 'action' => $a->_id
  68. ));
  69. }
  70. }
  71. return \DataTables::of($nested_data)->make(true);
  72. }
  73. //Dealer form
  74. public function showDealerForm(){
  75. $id = Auth::guard('ms')->id();
  76. $user = Staff::with('StaffDetail')->find($id);
  77. return view('market.add_dealer',compact('user'));
  78. }
  79. //Agent's list
  80. public function agentList()
  81. {
  82. $id = Auth::guard('ms')->id();
  83. $user = Staff::with('StaffDetail')->find($id);
  84. return view('market.agent_list',compact('user'));
  85. }
  86. //
  87. public function getAgentList()
  88. {
  89. $id = Auth::guard('ms')->id();
  90. $user = Staff::with('StaffDetail')->find($id);
  91. $agent = Staff::with('Company','StaffDetail')->orderBy('created_at','desc')->get();
  92. $curr = Carbon::now()->getTimestamp();
  93. $i = 0;
  94. $nested_data = array();
  95. if(!empty($agent))
  96. {
  97. foreach ($agent as $a)
  98. {
  99. if($a->StaffDetail->position == 'Dealer')
  100. {
  101. $i++; $n1 = '';
  102. $reg_time = $a->created_at;
  103. $expiry_date = $reg_time->addDays(3);
  104. $expiry_date = $expiry_date->getTimestamp();
  105. if($curr < $expiry_date) {
  106. $n1 = "New/";
  107. }
  108. array_push($nested_data, array(
  109. 'index' => $n1.$i,
  110. 'user_pic' => $a->StaffDetail->user_pic,
  111. 'name' => $a->StaffDetail->name,
  112. 'ic' => $a->StaffDetail->ic,
  113. 'email' => $a->StaffDetail->email,
  114. 'phone' => $a->StaffDetail->phone,
  115. 'company_id' => $a->Company->name,
  116. 'position' => $a->StaffDetail->position,
  117. 'action' => $a->_id
  118. ));
  119. }
  120. }
  121. }
  122. return \DataTables::of($nested_data)->make(true);
  123. }
  124. //Show form for adding agent
  125. public function showAgentForm()
  126. {
  127. $id = Auth::guard('ms')->id();
  128. $user = Staff::with('StaffDetail')->find($id);
  129. $company = Company::where('team', 'Dealer')->get();
  130. return view('market.agent_add',compact('user','company'));
  131. }
  132. //Show commission list R
  133. public function commissionListR()
  134. {
  135. $id = Auth::guard('ms')->id();
  136. $user = Staff::with('StaffDetail')->find($id);
  137. return view('market.commission_listR',compact('user'));
  138. }
  139. //Show comission list B
  140. public function commissionListB()
  141. {
  142. $id = Auth::guard('ms')->id();
  143. $user = Staff::find($id);
  144. $email = $user->email;
  145. $staffDetails = StaffDetail::where('email',$email)->first();
  146. return view('market.commission_listB',compact('staffDetails','user'));
  147. }
  148. //Show form for adding new commission R
  149. public function commissionFormR()
  150. {
  151. $id = Auth::guard('ms')->id();
  152. $user = Staff::find($id);
  153. $email = $user->email;
  154. $staffDetails = StaffDetail::where('email',$email)->first();
  155. return view('market.commission_formR',compact('staffDetails','user'));
  156. }
  157. //Show form for adding new commission B
  158. public function commissionFormB()
  159. {
  160. $id = Auth::guard('ms')->id();
  161. $user = Staff::find($id);
  162. $email = $user->email;
  163. $staffDetails = StaffDetail::where('email',$email)->first();
  164. return view('market.commission_formB',compact('staffDetails','user'));
  165. }
  166. public function getCommissionListR24()
  167. {
  168. $id = Auth::guard('ms')->id();
  169. $user = Staff::find($id);
  170. $email = $user->email;
  171. $marketdetail= Commission::where('contract','24')->where('formT','R')->orderBy('created_by','desc')->get();
  172. $curr = Carbon::now()->getTimestamp();
  173. $i = 0;
  174. $nested_data = array();
  175. if(!empty($marketdetail))
  176. {
  177. foreach ($marketdetail as $a)
  178. {
  179. $i++; $n1 = '';
  180. $reg_time = $a->created_at;
  181. $expiry_date = $reg_time->addDays(3);
  182. $expiry_date = $expiry_date->getTimestamp();
  183. if($curr < $expiry_date) {
  184. $n1 = "New/";
  185. }
  186. array_push($nested_data, array(
  187. 'index' => $n1.$i,
  188. 'formT' => $a->formT,
  189. 'ranges' => $a->ranges,
  190. 'comm' => $a->comm,
  191. 'category' => $a->category,
  192. 'contract' => $a->contract,
  193. 'action' => $a->_id
  194. ));
  195. }
  196. }
  197. return \DataTables::of($nested_data)->make(true);
  198. }
  199. public function getCommissionListR12()
  200. {
  201. $id = Auth::guard('ms')->id();
  202. $user = Staff::find($id);
  203. $email = $user->email;
  204. $marketdetail= Commission::where('contract','12')->where('formT','R')->orderBy('created_by','desc')->get();
  205. $curr = Carbon::now()->getTimestamp();
  206. $i = 0;
  207. $nested_data = array();
  208. if(!empty($marketdetail))
  209. {
  210. foreach ($marketdetail as $a)
  211. {
  212. $i++; $n1 = '';
  213. $reg_time = $a->created_at;
  214. $expiry_date = $reg_time->addDays(3);
  215. $expiry_date = $expiry_date->getTimestamp();
  216. if($curr < $expiry_date) {
  217. $n1 = "New/";
  218. }
  219. array_push($nested_data, array(
  220. 'index' => $n1.$i,
  221. 'formT' => $a->formT,
  222. 'ranges' => $a->ranges,
  223. 'comm' => $a->comm,
  224. 'category' => $a->category,
  225. 'contract' => $a->contract,
  226. 'action' => $a->_id
  227. ));
  228. }
  229. }
  230. return \DataTables::of($nested_data)->make(true);
  231. }
  232. public function getCommissionListB24Low()
  233. {
  234. $id = Auth::guard('ms')->id();
  235. $user = Staff::find($id);
  236. $email = $user->email;
  237. $marketdetail= Commission::where('contract','24')->where('formT','B')->where('packageR','10,30,50,100')->orderBy('created_by','desc')->get();
  238. $curr = Carbon::now()->getTimestamp();
  239. $i = 0;
  240. $nested_data = array();
  241. if(!empty($marketdetail))
  242. {
  243. foreach ($marketdetail as $a)
  244. {
  245. $i++; $n1 = '';
  246. $reg_time = $a->created_at;
  247. $expiry_date = $reg_time->addDays(3);
  248. $expiry_date = $expiry_date->getTimestamp();
  249. if($curr < $expiry_date) {
  250. $n1 = "New/";
  251. }
  252. array_push($nested_data, array(
  253. 'index' => $n1.$i,
  254. 'packageR' => $a->packageR,
  255. 'ranges' => $a->ranges,
  256. 'comm' => $a->comm,
  257. 'category' => $a->category,
  258. 'contract' => $a->contract,
  259. 'action' => $a->_id
  260. ));
  261. }
  262. }
  263. return \DataTables::of($nested_data)->make(true);
  264. }
  265. public function getCommissionListB24High()
  266. {
  267. $id = Auth::guard('ms')->id();
  268. $user = Staff::find($id);
  269. $email = $user->email;
  270. $marketdetail= Commission::where('contract','24')->where('formT','B')->orwhere('packageR','300')->orwhere('packageR','500')->orwhere('packageR','1')->orderBy('created_by','desc')->get();
  271. $curr = Carbon::now()->getTimestamp();
  272. $i = 0;
  273. $nested_data = array();
  274. if(!empty($marketdetail))
  275. {
  276. foreach ($marketdetail as $a)
  277. {
  278. $i++; $n1 = '';
  279. $reg_time = $a->created_at;
  280. $expiry_date = $reg_time->addDays(3);
  281. $expiry_date = $expiry_date->getTimestamp();
  282. if($curr < $expiry_date) {
  283. $n1 = "New/";
  284. }
  285. array_push($nested_data, array(
  286. 'index' => $n1.$i,
  287. 'packageR' => $a->packageR,
  288. 'ranges' => $a->ranges,
  289. 'comm' => $a->comm,
  290. 'category' => $a->category,
  291. 'contract' => $a->contract,
  292. 'action' => $a->_id
  293. ));
  294. }
  295. }
  296. return \DataTables::of($nested_data)->make(true);
  297. }
  298. public function getCommissionListB12Low()
  299. {
  300. $id = Auth::guard('ms')->id();
  301. $user = Staff::find($id);
  302. $email = $user->email;
  303. $marketdetail= Commission::where('contract','12')->where('formT','B')->where('packageR','10,30,50,100')->orderBy('created_by','desc')->get();
  304. $curr = Carbon::now()->getTimestamp();
  305. $i = 0;
  306. $nested_data = array();
  307. if(!empty($marketdetail))
  308. {
  309. foreach ($marketdetail as $a)
  310. {
  311. $i++; $n1 = '';
  312. $reg_time = $a->created_at;
  313. $expiry_date = $reg_time->addDays(3);
  314. $expiry_date = $expiry_date->getTimestamp();
  315. if($curr < $expiry_date) {
  316. $n1 = "New/";
  317. }
  318. array_push($nested_data, array(
  319. 'index' => $n1.$i,
  320. 'packageR' => $a->packageR,
  321. 'ranges' => $a->ranges,
  322. 'comm' => $a->comm,
  323. 'category' => $a->category,
  324. 'contract' => $a->contract,
  325. 'action' => $a->_id
  326. ));
  327. }
  328. }
  329. return \DataTables::of($nested_data)->make(true);
  330. }
  331. //Function to get commission list (1 year)
  332. public function getCommissionListB12High()
  333. {
  334. $id = Auth::guard('ms')->id();
  335. $user = Staff::find($id);
  336. $email = $user->email;
  337. $marketdetail= Commission::where('contract','12')->where('formT','B')->orwhere('packageR','300')->orwhere('packageR','500')->orwhere('packageR','1')->orderBy('created_by','desc')->get();
  338. $curr = Carbon::now()->getTimestamp();
  339. $i = 0;
  340. $nested_data = array();
  341. if(!empty($marketdetail))
  342. {
  343. foreach ($marketdetail as $a)
  344. {
  345. $i++; $n1 = '';
  346. $reg_time = $a->created_at;
  347. $expiry_date = $reg_time->addDays(3);
  348. $expiry_date = $expiry_date->getTimestamp();
  349. if($curr < $expiry_date) {
  350. $n1 = "New/";
  351. }
  352. array_push($nested_data, array(
  353. 'index' => $n1.$i,
  354. 'packageR' => $a->packageR,
  355. 'ranges' => $a->ranges,
  356. 'comm' => $a->comm,
  357. 'category' => $a->category,
  358. 'contract' => $a->contract,
  359. 'action' => $a->_id
  360. ));
  361. }
  362. }
  363. return \DataTables::of($nested_data)->make(true);
  364. }
  365. //Function to add company
  366. public function requestAddCompany(Request $request)
  367. {
  368. $companyData = [
  369. 'name' => $request->get('aname'),
  370. 'address' => $request->get('address'),
  371. 'city' => $request->get('city'),
  372. 'state' => $request->get('state'),
  373. 'postcode' => $request->get('postcode'),
  374. 'color' => '',
  375. 'team' => 'Dealer',
  376. 'status' => '',
  377. ];
  378. $companyDetail = Company::create($companyData);
  379. return redirect()->back()->with('success_msg', 'message');
  380. }
  381. //Function to add commission R
  382. public function requestAddCommissionR(Request $request)
  383. {
  384. $commissionData = [
  385. 'contract' => $request->get('contract'),
  386. 'ranges' => $request->get('ranges'),
  387. 'comm' => $request->get('comm'),
  388. 'category' => $request->get('categori'),
  389. 'formT' => 'R',
  390. 'packageR' => '',
  391. ];
  392. $commissionDetail = Commission::create($commissionData);
  393. return redirect()->back()->with('success_msg', 'message');
  394. }
  395. //Function to add commission B
  396. public function requestAddCommissionB(Request $request)
  397. {
  398. $commissionData = [
  399. 'packageR' => $request->get('packageR'),
  400. 'contract' => $request->get('contract'),
  401. 'ranges' => $request->get('ranges'),
  402. 'comm' => $request->get('comm'),
  403. 'category' => $request->get('categori'),
  404. 'formT' => 'B',
  405. ];
  406. $commissionDetail = Commission::create($commissionData);
  407. return redirect()->back()->with('success_msg', 'message');
  408. }
  409. /***
  410. / Encrypt Password
  411. ***/
  412. public function encryptPassword($action, $string) {
  413. $output = false;
  414. $encrypt_method = "AES-256-CBC";
  415. $secret_key = '28472B4B6250655368566D5970337336';
  416. $secret_iv = md5(md5($string)); //'This is my secret iv';
  417. // hash
  418. $key = hash('sha256', $secret_key);
  419. $iv = substr(hash('sha256', $secret_iv), 0, 16);
  420. if ( $action == 'encrypt' ) {
  421. $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
  422. $output = base64_encode($output);
  423. } else if( $action == 'decrypt' ) {
  424. $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
  425. }
  426. return $output;
  427. }
  428. //Function to add agent
  429. public function requestAddAgent(Request $request)
  430. {
  431. $validator = Validator::make($request->all(), [
  432. 'password' => 'min:8|confirmed',
  433. ]);
  434. if ($validator->fails()) {
  435. return redirect()->back()->withInput()->withErrors($validator);
  436. }
  437. $user = Staff::where('email', $request->get('email'))->first();
  438. if (empty($user)) {
  439. $pass = $this->encryptPassword('encrypt', $request->get('password'));
  440. $dealerD = new StaffDetail;
  441. $dealerD->name = $request->get('aname');
  442. $dealerD->ic = $request->get('ic');
  443. $dealerD->email = $request->get('email');
  444. $dealerD->phone = $request->get('phone');
  445. $dealerD->company_id = $request->get('vendor');
  446. $dealerD->color = '';
  447. $dealerD->position = 'Dealer';
  448. $dealerD->password = $pass;
  449. $dealerD->user_pic = 'assets/avatar/user.png';
  450. // Save Login Dealer
  451. $loginD = new Staff;
  452. $loginD->email = $request->get('email');
  453. $loginD->password = $pass;
  454. $loginD->roles_access = 'Dealer';
  455. $loginD->company_id = $request->get('vendor');
  456. $loginD->last_login_at = '';
  457. $loginD->last_login_ip = '';
  458. $company = Company::where('_id', $request->get('vendor'))->first();
  459. $company->staff()->save($loginD);
  460. // $dealer = DealerLaravel::create($loginData);
  461. $loginD->staffdetail()->save($dealerD);
  462. return redirect()->back()->with('success_msg', '<strong>Success!</strong> register <strong>'.$request->get('email').'</strong>');
  463. }
  464. else
  465. {
  466. return redirect()->back()->withInput()->withErrors('Email already exist!');
  467. }
  468. }
  469. //Function to delete company(dealer)
  470. public function deleteCompany(Request $request)
  471. {
  472. $company = Company::where('_id',$request->id)->first();
  473. if(!empty($company)){
  474. $company->delete();
  475. return 'true';
  476. }else {
  477. return 'false';
  478. }
  479. }
  480. //Function to delete Commission (R)
  481. public function deleteCommission(Request $request)
  482. {
  483. // CommissionLaravel::destroy($request);
  484. // return response()->json(['result'=>'success']);
  485. // return response()->json(['success'=>'Got Simple Ajax Request.']);
  486. $commission = Commission::where('_id',$request->id)->first();
  487. if(!empty($commission)){
  488. $commission->delete();
  489. return 'true';
  490. }else {
  491. return 'false';
  492. }
  493. }
  494. public function deleteAgent(Request $request)
  495. {
  496. // $agentdetail = StaffDetailLaravel::where('email',$request->email)->first();
  497. $agent = Staff::where('_id',$request->id)->first();
  498. $agentdetail = $agent->staffdetail()->first();
  499. if(!empty($agentdetail) && !empty($agent))
  500. {
  501. $agent->delete();
  502. $agentdetail->delete();
  503. return 'true';
  504. }
  505. else
  506. {
  507. return 'false';
  508. }
  509. }
  510. public function editCompany($company_id)
  511. {
  512. $id = Auth::guard('ms')->id();
  513. $user = Staff::with('StaffDetail')->find($id);
  514. $company = Company::where('_id', $company_id)->get();
  515. return view('market.edit_dealer',compact('user','company'));
  516. }
  517. public function updateCompany(Request $request)
  518. {
  519. $user = Company::where('_id', $request->get('company_id'))->first();
  520. $user->name = $request->get('aname');
  521. $user->address = $request->get('address');
  522. $user->city = $request->get('city');
  523. $user->state = $request->get('state');
  524. $user->postcode = $request->get('postcode');
  525. $user->color = '';
  526. $user->team = 'Dealer';
  527. $user->status = '';
  528. $user->save();
  529. return redirect()->route('mHome')->with('success_msg', 'message');
  530. }
  531. public function editCommissionR($commission_id)
  532. {
  533. $id = Auth::guard('ms')->id();
  534. $user = Staff::with('staffdetail')->find($id);
  535. $commission = Commission::where('_id', $commission_id)->get();
  536. return view('market.edit_commissionR',compact('user','commission'));
  537. }
  538. public function editCommissionB($commission_id)
  539. {
  540. $id = Auth::guard('ms')->id();
  541. $user = Staff::find($id);
  542. $email = $user->email;
  543. $staffDetails = StaffDetail::where('email',$email)->first();
  544. $commission = Commission::where('_id', $commission_id)->get();
  545. return view('market.edit_commissionB',compact('staffDetails','user','commission'));
  546. }
  547. public function editAgent($agent_id)
  548. {
  549. $id = Auth::guard('ms')->id();
  550. $user = Staff::with('StaffDetail')->find($id);
  551. $agentdetail = Staff::where('_id', $agent_id)->first();
  552. $company = Company::where('team', 'Dealer')->get();
  553. return view('market.edit_agent', compact('user', 'agentdetail', 'company'));
  554. }
  555. public function updateCommissionR(Request $request)
  556. {
  557. $commission = Commission::where('_id', $request->get('commission_id'))->first();
  558. $commission->contract = $request->get('contract');
  559. $commission->ranges = $request->get('ranges');
  560. $commission->comm = $request->get('comm');
  561. $commission->category = $request->get('categori');
  562. $commission->formT = 'R';
  563. $commission->packageR = '';
  564. $commission->save();
  565. return redirect()->route('commissionListR')->with('success_msg', 'message');
  566. }
  567. public function updateCommissionB(Request $request)
  568. {
  569. $commission = Commission::where('_id', $request->get('commission_id'))->first();
  570. $commission->packageR = $request->get('packageR');
  571. $commission->contract = $request->get('contract');
  572. $commission->ranges = $request->get('ranges');
  573. $commission->comm = $request->get('comm');
  574. $commission->category = $request->get('categori');
  575. $commission->formT = 'B';
  576. $commission->save();
  577. return redirect()->route('commissionListB')->with('success_msg', 'message');
  578. }
  579. public function updateAgent(Request $request)
  580. {
  581. $user = Staff::where('_id', $request->agent_id)->first();
  582. $validate = Staff::where('email', $request->email)->first();
  583. $detail = $user->staffdetail()->first();
  584. $getpass = $request->get('password');
  585. $pass = $this->encryptPassword('encrypt', $request->get('password'));
  586. if(empty($validate))
  587. {
  588. $detail->name = $request->get('aname');
  589. $detail->ic = $request->get('ic');
  590. $detail->email = $request->get('email');
  591. $detail->phone = $request->get('phone');
  592. $detail->company_id = $request->get('vendor');
  593. $user->email = $request->get('email');
  594. $user->company_id = $request->get('vendor');
  595. if(!empty($getpass))
  596. {
  597. $validator = Validator::make($request->all(), [
  598. 'password' => 'min:8|confirmed',
  599. ]);
  600. if ($validator->fails())
  601. {
  602. return redirect()->back()->withInput()->withErrors($validator);
  603. }
  604. $detail->password = $pass;
  605. $user->password = $pass;
  606. $detail->save();
  607. $user->save();
  608. }
  609. else
  610. {
  611. $detail->save();
  612. $user->save();
  613. }
  614. return redirect()->route('agentList')->with('success_msg', 'message');
  615. }
  616. else
  617. {
  618. if($user->email == $request->email)
  619. {
  620. echo "".$request->get('password');
  621. $detail->name = $request->get('aname');
  622. $detail->ic = $request->get('ic');
  623. $detail->email = $request->get('email');
  624. $detail->phone = $request->get('phone');
  625. $detail->company_id = $request->get('vendor');
  626. $detail->save();
  627. $user->email = $request->get('email');
  628. if(!empty($getpass))
  629. {
  630. $validator = Validator::make($request->all(), [
  631. 'password' => 'min:8|confirmed',
  632. ]);
  633. if ($validator->fails())
  634. {
  635. return redirect()->back()->withInput()->withErrors($validator);
  636. }
  637. $detail->password = $pass;
  638. $user->password = $pass;
  639. $detail->save();
  640. $user->save();
  641. }
  642. else
  643. {
  644. $detail->save();
  645. $user->save();
  646. }
  647. return redirect()->route('agentList')->with('success_msg', 'message');
  648. }
  649. else
  650. {
  651. echo "email is used";
  652. return redirect()->back()->withInput()->withErrors('Email already exist!');
  653. }
  654. }
  655. }
  656. public function filterDocket($year, $month)
  657. {
  658. $year = $year;
  659. $month = $month;
  660. $nested_data = array();
  661. $arr = array();
  662. $i=0;
  663. if($year=='null' && $month=='null')
  664. {
  665. $docket = Docket::with('WorkOrder')->orderBy('created_at', 'desc')->get();
  666. $arr = array();
  667. $i = 0;$n1 = '';
  668. $nested_data = array();
  669. $test = 0;
  670. foreach ($docket as $a)
  671. {
  672. $i++;
  673. $building = "";
  674. if(!empty($a->WorkOrder->_id)){
  675. $subDetail = Form::with('WorkOrder','Subscriber')->where('_id',$a->WorkOrder->_id)->first();
  676. $contractor = Company::where('_id', $a->WorkOrder->contractor_id)->first();
  677. $tempInstaller = Staff::with('StaffDetail')->withTrashed()->where('_id',$a->installer_id)->first();
  678. if(!empty($subDetail->Subscriber->building_name))
  679. $building=$subDetail->Subscriber->building_name;
  680. else
  681. $building=$subDetail->Subscriber->company_name;
  682. array_push($nested_data, array(
  683. 'index' => $n1.$i,
  684. 'docket_id' => $a->docket_id,
  685. 'work_order_id' => $a->work_order_id,
  686. 'nature_work' => $a->nature_work,
  687. 'contractor_id' => $contractor->name,
  688. 'installer_name' => $tempInstaller->StaffDetail->name,
  689. 'customer_id' => $building,
  690. 'installer_id' => $tempInstaller->StaffDetail->phone,
  691. 'end_job' => $a->end_job,
  692. 'rating' => round((($a->Rating1 + $a->Rating2 + $a->Rating3)/15) * 100)."%",
  693. ));
  694. }
  695. }
  696. }
  697. elseif($year!='' && $month=='null')
  698. {
  699. $timestamp = $year."-01-01 00:00:00.000Z";
  700. $masa = strtotime($timestamp);
  701. $go = Carbon::createFromTimestamp($masa);
  702. $go2 = Carbon::createFromTimestamp($masa);
  703. $end_year = $go2->endOfYear();
  704. // $time = Carbon::createFromTimeString($timestamp);
  705. // echo $month;
  706. $docket = Docket::with('WorkOrder')->whereBetween('created_at', [$go, $end_year])->orderBy('created_at', 'desc')->get();
  707. $arr = array();
  708. $i = 0;$n1 = '';
  709. $nested_data = array();
  710. $test = 0;
  711. foreach ($docket as $a)
  712. {
  713. $i++;
  714. $building = "";
  715. if(!empty($a->WorkOrder->_id)){
  716. $subDetail = Form::with('WorkOrder','Subscriber')->where('_id',$a->WorkOrder->_id)->first();
  717. $contractor = Company::where('_id', $a->WorkOrder->contractor_id)->first();
  718. $tempInstaller = StaffDetail::where('_id', $a->installer_id)->withTrashed()->first();
  719. if(!empty($subDetail->Subscriber->building_name))
  720. $building=$subDetail->Subscriber->building_name;
  721. else
  722. $building=$subDetail->Subscriber->company_name;
  723. array_push($nested_data, array(
  724. 'index' => $n1.$i,
  725. 'docket_id' => $a->docket_id,
  726. 'work_order_id' => $a->work_order_id,
  727. 'nature_work' => $a->nature_work,
  728. 'contractor_id' => $contractor->name,
  729. 'installer_name' => $tempInstaller->name,
  730. 'customer_id' => $building,
  731. 'installer_id' => $tempInstaller->phone,
  732. 'end_job' => $a->end_job,
  733. 'rating' => round((($a->Rating1 + $a->Rating2 + $a->Rating3)/15) * 100)."%",
  734. ));
  735. }
  736. }
  737. }
  738. elseif($year!='' && $month !='')
  739. {
  740. $timestamp = $year."-".$month."-01 00:00:00.000Z";
  741. $masa = strtotime($timestamp);
  742. $go = Carbon::createFromTimestamp($masa);
  743. $go2 = Carbon::createFromTimestamp($masa);
  744. $end_year = $go2->endOfMonth();
  745. // $time = Carbon::createFromTimeString($timestamp);
  746. // $docket = Docket::whereBetween('created_at', [$go, $end_year])->get();
  747. $docket = Docket::with('WorkOrder')->whereBetween('created_at', [$go, $end_year])->orderBy('created_at', 'desc')->get();
  748. $arr = array();
  749. $i = 0;$n1 = '';
  750. $nested_data = array();
  751. $test = 0;
  752. foreach ($docket as $a)
  753. {
  754. $i++;
  755. $building = "";
  756. if(!empty($a->WorkOrder->_id)){
  757. $subDetail = Form::with('WorkOrder','Subscriber')->where('_id',$a->WorkOrder->_id)->first();
  758. $contractor = Company::where('_id', $a->WorkOrder->contractor_id)->first();
  759. $tempInstaller = StaffDetail::where('_id', $a->installer_id)->withTrashed()->first();
  760. if(!empty($subDetail->Subscriber->building_name))
  761. $building=$subDetail->Subscriber->building_name;
  762. else
  763. $building=$subDetail->Subscriber->company_name;
  764. array_push($nested_data, array(
  765. 'index' => $n1.$i,
  766. 'docket_id' => $a->docket_id,
  767. 'work_order_id' => $a->work_order_id,
  768. 'nature_work' => $a->nature_work,
  769. 'contractor_id' => $contractor->name,
  770. 'installer_name' => $tempInstaller->name,
  771. 'customer_id' => $building,
  772. 'installer_id' => $tempInstaller->phone,
  773. 'end_job' => $a->end_job,
  774. 'rating' => round((($a->Rating1 + $a->Rating2 + $a->Rating3)/15) * 100)."%",
  775. ));
  776. }
  777. }
  778. }
  779. return \DataTables::of($nested_data)->make(true);
  780. }
  781. public function requestClaim(Request $request)
  782. {
  783. $claim = DealerClaim::where('_id',$request->id)->first();
  784. // $agentdetail = StaffDetailLaravel::where('email',$request->email)->first();
  785. $mytime = Carbon::now();
  786. if(!empty($claim))
  787. {
  788. $claim->claim_dt = $mytime->toDateTimeString();
  789. $claim->save();
  790. return 'true';
  791. }
  792. else
  793. {
  794. return 'false';
  795. }
  796. }
  797. public function docketList()
  798. {
  799. $id = Auth::guard('ms')->id();
  800. $user = Staff::with('StaffDetail')->find($id);
  801. return view('market.docket',compact('user'));
  802. }
  803. public function getDocketList()
  804. {
  805. $id = Auth::guard('ms')->id();
  806. $user = Staff::with('StaffDetail')->find($id);
  807. $docket = Docket::with('WorkOrder')->orderBy('created_at', 'desc')->get();
  808. $arr = array();
  809. $i = 0;$n1 = '';
  810. $nested_data = array();
  811. $test = 0;
  812. foreach ($docket as $a)
  813. {
  814. $i++;
  815. $building = "";
  816. if(!empty($a->WorkOrder->_id)){
  817. $subDetail = Form::with('WorkOrder','Subscriber')->where('_id',$a->WorkOrder->_id)->first();
  818. $contractor = Company::where('_id', $a->WorkOrder->contractor_id)->first();
  819. $tempInstaller = Staff::with('StaffDetail')->withTrashed()->where('_id',$a->installer_id)->first();
  820. if(!empty($subDetail->Subscriber->building_name))
  821. $building=$subDetail->Subscriber->building_name;
  822. else
  823. $building=$subDetail->Subscriber->company_name;
  824. array_push($nested_data, array(
  825. 'index' => $n1.$i,
  826. 'docket_id' => $a->docket_id,
  827. 'work_order_id' => $a->work_order_id,
  828. 'nature_work' => $a->nature_work,
  829. 'contractor_id' => $contractor->name,
  830. 'installer_name' => $tempInstaller->StaffDetail->name,
  831. 'customer_id' => $building,
  832. 'installer_id' => $tempInstaller->StaffDetail->phone,
  833. 'end_job' => $a->end_job,
  834. 'rating' => round((($a->Rating1 + $a->Rating2 + $a->Rating3)/15) * 100)."%",
  835. ));
  836. }
  837. }
  838. return \DataTables::of($nested_data)->make(true);
  839. }
  840. public function updateClaimDate(Request $request)
  841. {
  842. $claim = DealerClaim::where("_id", $request->id)->first();
  843. if(!empty($claim))
  844. {
  845. $claim->claim_dt = $request->date." ".$request->time;
  846. $claim->save();
  847. return 'true';
  848. }
  849. else
  850. return 'false';
  851. }
  852. public function downloadPDF()
  853. {
  854. $pdf = PDF::loadView('pdf.docket-pdf');
  855. return $pdf->download('invoice.pdf');
  856. // return view('pdf.docket-pdf');
  857. }
  858. public function woList()
  859. {
  860. $id = Auth::guard('ms')->id();
  861. $user = Staff::with('StaffDetail')->find($id);
  862. return view('market.workorder',compact('user'));
  863. }
  864. public function getWoList()
  865. {
  866. $id = Auth::guard('ms')->id();
  867. $user = Staff::with('StaffDetail')->find($id);
  868. // $marketdetail= WorkOrder::with('Form')->where('_id','5b4c18a4ee0dc2b707473b7d')->first();
  869. // $b = array();
  870. $r=0;$b=0;
  871. $subDetail = Form::with('WorkOrder','Subscriber')->orderBy('created_at','desc')->get();
  872. $curr = Carbon::now()->getTimestamp();
  873. $i = 0;
  874. $nested_data = array();
  875. foreach($subDetail as $a)
  876. {
  877. $var1="";
  878. if(empty($a->WorkOrder)){}
  879. else
  880. {
  881. $i++;
  882. $staff = StaffDetail::where('_id', $a->WorkOrder->installer_id)->withTrashed()->first();
  883. $contractor = Company::where('_id', $a->WorkOrder->contractor_id)->first();
  884. if(!empty($staff))
  885. {
  886. $var1 =$staff->name;
  887. }
  888. $reg_time = $a->created_at;
  889. $expiry_date = $reg_time->addDays(3);
  890. $expiry_date = $expiry_date->getTimestamp();
  891. if($curr < $expiry_date) {
  892. $n1 = "New/";
  893. }
  894. $building = '';
  895. if($a->type_application == 'R'){
  896. $building = $a->Subscriber->building_name;
  897. }else if($a->type_application == 'B'){
  898. $building = $a->Subscriber->company_name;
  899. }
  900. if(!empty($a->Subscriber)){
  901. array_push($nested_data, array(
  902. 'index' => $n1.$i.$a->type_application,
  903. 'nature_work' => $a->WorkOrder->nature_work,
  904. 'wo'=>$a->WorkOrder->wo,
  905. 'customer_name' => $a->Subscriber->name,
  906. 'customer_phone' => $a->Subscriber->phone1,
  907. 'customer_unit' => $a->Subscriber->unit_no,
  908. 'customer_building' => $building,
  909. 'customer_postcode' => $a->Subscriber->postcode,
  910. 'customer_city' => $a->Subscriber->city,
  911. 'contractor_id' => $contractor->name,
  912. 'installer_id' => $var1,
  913. 'dateTimeEnd' => $a->WorkOrder->dateTimeEnd,
  914. 'status' => $a->WorkOrder->status,
  915. ));
  916. }
  917. }
  918. }
  919. return \DataTables::of($nested_data)->make(true);
  920. }
  921. public function filterWo($year, $month, $status)
  922. {
  923. $r = 0;
  924. $b = 0;
  925. $nested_data = array();
  926. if($year == 'null' && $month == 'null' & $status !='')
  927. {
  928. $i = 0;
  929. // $subDetail = Form::with('WorkOrder','Subscriber')->where('_id', $a->id)->first();
  930. $wo = WorkOrder::with('Form')->orderBy('dateTimeStart', 'desc')->where('status', $status)->get();
  931. foreach($wo as $a)
  932. {
  933. $customer = Subscriber::where('_id', $a->Form->_id)->first();
  934. $contractor = Company::where('_id', $a->contractor_id)->first();
  935. $installer = StaffDetail::where('_id', $a->installer_id)->withTrashed()->first();
  936. $var1 = "";
  937. if(!empty($installer)){
  938. $var1 =$installer->name;
  939. }
  940. if($a->Form->type_application == "R")
  941. {
  942. $r++; $n1 = 'R';
  943. $customer = Subscriber::where('_id', $a->Form->_id)->first();
  944. if(!empty($customer)){
  945. array_push($nested_data, array(
  946. 'index' => $r.$n1,
  947. 'nature_work' => $a->nature_work,
  948. 'wo'=>$a->wo,
  949. 'customer_name' => $customer->name,
  950. 'customer_phone' => $customer->phone1,
  951. 'customer_unit' => $customer->unit_no,
  952. 'customer_building' => $customer->building_name,
  953. 'customer_postcode' => $customer->postcode,
  954. 'customer_city' => $customer->city,
  955. 'contractor_id' => $contractor->name,
  956. 'installer_id' => $var1,
  957. 'dateTimeEnd' => $a->dateTimeEnd,
  958. 'status' => $a->status,
  959. ));
  960. }
  961. }
  962. if($a->Form->type_application == "B")
  963. {
  964. $b++; $n1 = 'B';
  965. $customer = Subscriber::where('_id', $a->Form->_id)->first();
  966. if(!empty($customer)){
  967. array_push($nested_data, array(
  968. 'index' => $b.$n1,
  969. 'nature_work' => $a->nature_work,
  970. 'wo'=>$a->wo,
  971. 'customer_name' => $customer->name,
  972. 'customer_phone' => $customer->phone1,
  973. 'customer_unit' => '-',
  974. 'customer_building' => $customer->company_name,
  975. 'customer_postcode' => $customer->postcode,
  976. 'customer_city' => $customer->city,
  977. 'contractor_id' => $contractor->name,
  978. 'installer_id' => $var1,
  979. 'dateTimeEnd' => $a->dateTimeEnd,
  980. 'status' => $a->status,
  981. ));
  982. }
  983. }
  984. }
  985. }
  986. if($year=='null' && $month == 'null' & $status == 'null')
  987. {
  988. $i = 0;
  989. // $subDetail = Form::with('WorkOrder','Subscriber')->where('_id', $a->id)->first();
  990. $wo = WorkOrder::with('Form')->orderBy('dateTimeStart','desc')->get();
  991. foreach($wo as $a)
  992. {
  993. $customer = Subscriber::where('_id', $a->Form->_id)->first();
  994. $contractor = Company::where('_id', $a->contractor_id)->first();
  995. $installer = StaffDetail::where('_id', $a->installer_id)->withTrashed()->first();
  996. $var1 = "";
  997. if(!empty($installer)){
  998. $var1 =$installer->name;
  999. }
  1000. if($a->Form->type_application == "R")
  1001. {
  1002. $r++; $n1 = 'R';
  1003. $customer = Subscriber::where('_id', $a->Form->_id)->first();
  1004. if(!empty($customer)){
  1005. array_push($nested_data, array(
  1006. 'index' => $r.$n1,
  1007. 'nature_work' => $a->nature_work,
  1008. 'wo'=>$a->wo,
  1009. 'customer_name' => $customer->name,
  1010. 'customer_phone' => $customer->phone1,
  1011. 'customer_unit' => $customer->unit_no,
  1012. 'customer_building' => $customer->building_name,
  1013. 'customer_postcode' => $customer->postcode,
  1014. 'customer_city' => $customer->city,
  1015. 'contractor_id' => $contractor->name,
  1016. 'installer_id' => $var1,
  1017. 'dateTimeEnd' => $a->dateTimeEnd,
  1018. 'status' => $a->status,
  1019. ));
  1020. }
  1021. }
  1022. if($a->Form->type_application == "B")
  1023. {
  1024. $b++; $n1 = 'B';
  1025. $customer = Subscriber::where('_id', $a->Form->_id)->first();
  1026. if(!empty($customer)){
  1027. array_push($nested_data, array(
  1028. 'index' => $b.$n1,
  1029. 'nature_work' => $a->nature_work,
  1030. 'wo'=>$a->wo,
  1031. 'customer_name' => $customer->name,
  1032. 'customer_phone' => $customer->phone1,
  1033. 'customer_unit' => '-',
  1034. 'customer_building' => $customer->company_name,
  1035. 'customer_postcode' => $customer->postcode,
  1036. 'customer_city' => $customer->city,
  1037. 'contractor_id' => $contractor->name,
  1038. 'installer_id' => $var1,
  1039. 'dateTimeEnd' => $a->dateTimeEnd,
  1040. 'status' => $a->status,
  1041. ));
  1042. }
  1043. }
  1044. }
  1045. }
  1046. if($year!='' && $month!='' && $status !='')
  1047. {
  1048. $start_month = $year."-".$month."-01 00:00:00";
  1049. $end_month = $year."-".$month."-32 23:59:59";
  1050. // $wo = WorkOrder::orderBy('dateTimeStart', 'desc')->whereBetween('dateTimeStart', [$start_month, $end_month])->where('status',$status)->get();
  1051. $i = 0;
  1052. // $subDetail = Form::with('WorkOrder','Subscriber')->where('_id', $a->id)->first();
  1053. $wo = WorkOrder::with('Form')->orderBy('dateTimeStart', 'desc')->whereBetween('dateTimeStart', [$start_month, $end_month])->where('status', $status)->get();
  1054. foreach($wo as $a)
  1055. {
  1056. $customer = Subscriber::where('_id', $a->Form->_id)->first();
  1057. $contractor = Company::where('_id', $a->contractor_id)->first();
  1058. $installer = StaffDetail::where('_id', $a->installer_id)->withTrashed()->first();
  1059. $var1 = "";
  1060. if(!empty($installer)){
  1061. $var1 =$installer->name;
  1062. }
  1063. if($a->Form->type_application == "R")
  1064. {
  1065. $r++; $n1 = 'R';
  1066. $customer = Subscriber::where('_id', $a->Form->_id)->first();
  1067. if(!empty($customer)){
  1068. array_push($nested_data, array(
  1069. 'index' => $r.$n1,
  1070. 'nature_work' => $a->nature_work,
  1071. 'wo'=>$a->wo,
  1072. 'customer_name' => $customer->name,
  1073. 'customer_phone' => $customer->phone1,
  1074. 'customer_unit' => $customer->unit_no,
  1075. 'customer_building' => $customer->building_name,
  1076. 'customer_postcode' => $customer->postcode,
  1077. 'customer_city' => $customer->city,
  1078. 'contractor_id' => $contractor->name,
  1079. 'installer_id' => $var1,
  1080. 'dateTimeEnd' => $a->dateTimeEnd,
  1081. 'status' => $a->status,
  1082. ));
  1083. }
  1084. }
  1085. if($a->Form->type_application == "B")
  1086. {
  1087. $b++; $n1 = 'B';
  1088. $customer = Subscriber::where('_id', $a->Form->_id)->first();
  1089. if(!empty($customer)){
  1090. array_push($nested_data, array(
  1091. 'index' => $b.$n1,
  1092. 'nature_work' => $a->nature_work,
  1093. 'wo'=>$a->wo,
  1094. 'customer_name' => $customer->name,
  1095. 'customer_phone' => $customer->phone1,
  1096. 'customer_unit' => '-',
  1097. 'customer_building' => $customer->company_name,
  1098. 'customer_postcode' => $customer->postcode,
  1099. 'customer_city' => $customer->city,
  1100. 'contractor_id' => $contractor->name,
  1101. 'installer_id' => $var1,
  1102. 'dateTimeEnd' => $a->dateTimeEnd,
  1103. 'status' => $a->status,
  1104. ));
  1105. }
  1106. }
  1107. }
  1108. }
  1109. if($year!='' && $month!='' && $status =='null')
  1110. {
  1111. $start_month = $year."-".$month."-01 00:00:00";
  1112. $end_month = $year."-".$month."-32 23:59:59";
  1113. $i = 0;
  1114. // $subDetail = Form::with('WorkOrder','Subscriber')->where('_id', $a->id)->first();
  1115. $wo = WorkOrder::with('Form')->orderBy('dateTimeStart', 'desc')->whereBetween('dateTimeStart', [$start_month, $end_month])->get();
  1116. foreach($wo as $a)
  1117. {
  1118. $customer = Subscriber::where('_id', $a->Form->_id)->first();
  1119. $contractor = Company::where('_id', $a->contractor_id)->first();
  1120. $installer = StaffDetail::where('_id', $a->installer_id)->withTrashed()->first();
  1121. $var1 = "";
  1122. if(!empty($installer)){
  1123. $var1 =$installer->name;
  1124. }
  1125. if($a->Form->type_application == "R")
  1126. {
  1127. $r++; $n1 = 'R';
  1128. $customer = Subscriber::where('_id', $a->Form->_id)->first();
  1129. if(!empty($customer)){
  1130. array_push($nested_data, array(
  1131. 'index' => $r.$n1,
  1132. 'nature_work' => $a->nature_work,
  1133. 'wo'=>$a->wo,
  1134. 'customer_name' => $customer->name,
  1135. 'customer_phone' => $customer->phone1,
  1136. 'customer_unit' => $customer->unit_no,
  1137. 'customer_building' => $customer->building_name,
  1138. 'customer_postcode' => $customer->postcode,
  1139. 'customer_city' => $customer->city,
  1140. 'contractor_id' => $contractor->name,
  1141. 'installer_id' => $var1,
  1142. 'dateTimeEnd' => $a->dateTimeEnd,
  1143. 'status' => $a->status,
  1144. ));
  1145. }
  1146. }
  1147. if($a->Form->type_application == "B")
  1148. {
  1149. $b++; $n1 = 'B';
  1150. $customer = Subscriber::where('_id', $a->Form->_id)->first();
  1151. if(!empty($customer)){
  1152. array_push($nested_data, array(
  1153. 'index' => $b.$n1,
  1154. 'nature_work' => $a->nature_work,
  1155. 'wo'=>$a->wo,
  1156. 'customer_name' => $customer->name,
  1157. 'customer_phone' => $customer->phone1,
  1158. 'customer_unit' => '-',
  1159. 'customer_building' => $customer->company_name,
  1160. 'customer_postcode' => $customer->postcode,
  1161. 'customer_city' => $customer->city,
  1162. 'contractor_id' => $contractor->name,
  1163. 'installer_id' => $var1,
  1164. 'dateTimeEnd' => $a->dateTimeEnd,
  1165. 'status' => $a->status,
  1166. ));
  1167. }
  1168. }
  1169. }
  1170. }
  1171. return \DataTables::of($nested_data)->make(true);
  1172. }
  1173. /**
  1174. ALL DOWN HERE ARE FOR TESTING AND UTILITIES PURPOSES
  1175. **/
  1176. public function woToLaravel()
  1177. {
  1178. }
  1179. public function checktry()
  1180. {
  1181. $data = Subscriber::where('wo','!=','')->get();
  1182. $wo = WorkOrder::all()->toArray();
  1183. $adawork = array();
  1184. $newarr = array();
  1185. $hmm = array();
  1186. $i = 0;
  1187. foreach($data as $d){
  1188. if(array_search($d->wo, array_column($wo, 'wo')) !== False) { // search value in the array
  1189. // echo "FOUND";
  1190. }else {
  1191. $adawork[] = $d->wo;
  1192. $i++;
  1193. }
  1194. }
  1195. dd($adawork);
  1196. }
  1197. //Insert data into Commission_Laravel table
  1198. public function commissionlara()
  1199. {
  1200. $olddata = Commission::all();
  1201. foreach($olddata as $od)
  1202. {
  1203. $subsData = [
  1204. 'formT' => $od['formT'],
  1205. 'ranges' => $od['ranges'],
  1206. 'comm' => $od['comm'],
  1207. 'category' => $od['category'],
  1208. 'contract' => $od['contract'],
  1209. 'reg_time' => $od['reg_time'],
  1210. 'packageR' => $od['packageR'],
  1211. ];
  1212. Commission::create($subsData);
  1213. }
  1214. return "success";
  1215. }
  1216. //Insert data into Company_Laravel table
  1217. public function companylara()
  1218. {
  1219. $olddata = Company::all();
  1220. foreach($olddata as $od)
  1221. {
  1222. $subsData = [
  1223. 'name' => $od['name'],
  1224. 'address' => $od['address'],
  1225. 'city' => $od['city'],
  1226. 'state' => $od['state'],
  1227. 'postcode' => $od['postcode'],
  1228. 'color' => $od['color'],
  1229. 'team' => $od['team'],
  1230. 'status' => $od['status'],
  1231. 'reg_time' => $od['reg_time'],
  1232. ];
  1233. Company::create($subsData);
  1234. }
  1235. }
  1236. //Insert data into Claim_Laravel table
  1237. public function claimtolara()
  1238. {
  1239. $olddata = DealerClaim::all();
  1240. foreach($olddata as $od)
  1241. {
  1242. $subsData = [
  1243. '_id' => $od['_id'],
  1244. 'formT' => $od['formT'],
  1245. 'wo' => $od['wo'],
  1246. 'dateTimeStart' => $od['dateTimeEnd'],
  1247. 'customer_id' => $od['customer_id'],
  1248. 'contractor_id' => $od['contractor_id'],
  1249. 'installer_id' => $od['installer_id'],
  1250. 'nature_work' => $od['nature_work'],
  1251. 'sub_category' => $od['sub_category'],
  1252. 'img_url' => $od['img_url'],
  1253. 'docket' => $od['docket'],
  1254. 'status'=>$od['status'],
  1255. 'remark'=>$od['remark'],
  1256. 'remarks_inst'=>$od['remarks_inst'],
  1257. 'customer_code'=>$od['customer_code'],
  1258. 'package_bandwidth'=>$od['package_bandwidth'],
  1259. 'subnet_mask'=>$od['subnet_mask'],
  1260. 'login_id'=>$od['login_id'],
  1261. 'password'=>$od['password'],
  1262. 'wan_ip'=>$od['wan_ip'],
  1263. 'lan_ip'=>$od['lan_ip'],
  1264. 'gateway'=>$od['getaway'],
  1265. 'service_id1'=>$od['service_id2'],
  1266. 'ip_address_onu'=>$od['ip_address_onu'],
  1267. 'gateway_onu'=>$od['gateaway_onu'],
  1268. 'subnet_mask_onu'=>$od['subnet_mask_onu'],
  1269. 'ip_address_srp'=>$od['ip_address_srp'],
  1270. 'dectphone1'=>$od['dectphone1'],
  1271. 'dectphone2'=>$od['dectphone2'],
  1272. 'onu'=>$od['onu'],
  1273. 'router'=>$od['router'],
  1274. 'wifi_extender'=>$od['wifi_extender'],
  1275. 'reg_time'=>$od['reg_time'],
  1276. ];
  1277. DealerClaim::create($subsData);
  1278. }
  1279. }
  1280. //Add total form by month to Claim Laravel collection
  1281. public function claimaddtotal()
  1282. {
  1283. $getdata = DealerClaim::all();
  1284. $total = 0;
  1285. foreach($getdata as $a)
  1286. {
  1287. if($a->activated_my == "2/2019")
  1288. {
  1289. $total += 1;
  1290. }
  1291. }
  1292. $adddata = DealerClaim::all();
  1293. foreach($adddata as $a)
  1294. {
  1295. if($a->activated_my == "2/2019")
  1296. {
  1297. $a->total_form_by_month = $total;
  1298. $a->save();
  1299. }
  1300. }
  1301. }
  1302. public function generateWorkOrderPDF($wo){
  1303. $id = Auth::guard('ms')->id();
  1304. $user = Staff::with('StaffDetail')->find($id);
  1305. $wo = WorkOrder::where('wo',$wo)->first();
  1306. $form = Form::with('PackageDetail','Subscriber')->where('_id',$wo->_id)->first();
  1307. $product = Product::where('formT',$form->type_application)->where('speed',$form->PackageDetail->name)->first();
  1308. if(empty($product)){
  1309. $product = 'RMbps';
  1310. }else {
  1311. $product = $product->package_name;
  1312. }
  1313. $created_by = Staff::with('StaffDetail')->find($wo->created_by)->first();
  1314. if(empty($created_by)){
  1315. $created_by = '';
  1316. }
  1317. $created_at = Carbon::parse($wo->created_at)->toDateTimeString();
  1318. $address = '';
  1319. if($form->type_application == 'R'){
  1320. if($form->Subscriber->street != ''){
  1321. $address = $form->Subscriber->unit_no. ' , '.$form->Subscriber->building_name. ' , '.$form->Subscriber->street. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
  1322. }else {
  1323. $address = $form->Subscriber->unit_no. ' , '.$form->Subscriber->building_name. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
  1324. }
  1325. }else if($form->type_application == 'B'){
  1326. if($form->Subscriber->unit_no != ''){
  1327. $address = $form->Subscriber->unit_no. ', '.$form->Subscriber->company_name. ', '.$form->Subscriber->street. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
  1328. }else {
  1329. $address = $form->Subscriber->company_name. ', '.$form->Subscriber->street. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
  1330. }
  1331. }
  1332. $pdf = PDF::loadView('pdf.workorder-pdf',compact('wo','form','product','created_at','created_by','address'));
  1333. $pdf->setPaper('A4', 'potrait');
  1334. return $pdf->stream();
  1335. }
  1336. public function generateDocketPDF($do)
  1337. {
  1338. $id = Auth::guard('ms')->id();
  1339. $user = Staff::with('StaffDetail')->find($id);
  1340. $docket = Docket::with('WorkOrder')->where('docket_id',$do)->first();
  1341. if(!empty($docket)){
  1342. $form = Form::with('Subscriber','PackageDetail')->where('_id',$docket->WorkOrder->_id)->first();
  1343. $address = '';
  1344. if($form->type_application == 'R'){
  1345. if($form->Subscriber->street != ''){
  1346. $address = $form->Subscriber->unit_no. ' , '.$form->Subscriber->building_name. ' , '.$form->Subscriber->street. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
  1347. }else {
  1348. $address = $form->Subscriber->unit_no. ' , '.$form->Subscriber->building_name. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
  1349. }
  1350. }else if($form->type_application == 'B'){
  1351. if($form->Subscriber->unit_no != ''){
  1352. $address = $form->Subscriber->unit_no. ', '.$form->Subscriber->company_name. ', '.$form->Subscriber->street. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
  1353. }else {
  1354. $address = $form->Subscriber->company_name. ', '.$form->Subscriber->street. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
  1355. }
  1356. }
  1357. $product = Product::where('formT',$form->type_application)->where('speed',$form->PackageDetail->name)->first();
  1358. $installer = Staff::with('StaffDetail')->where('_id',$docket->installer_id)->withTrashed()->first();
  1359. if(empty($product)){
  1360. $product = 'RMbps';
  1361. }else {
  1362. $product = $product->package_name;
  1363. }
  1364. $dateTime = Carbon::parse($docket->WorkOrder->dateTimeStart)->toDateTimeString();
  1365. $edateTime = Carbon::parse($docket->end_job)->toDateTimeString();
  1366. $pdf = PDF::loadView('pdf.docket-pdf',compact('docket','form','address','product','installer','dateTime','edateTime'));
  1367. $pdf->setPaper('A4', 'potrait');
  1368. return $pdf->stream();
  1369. }
  1370. }
  1371. public function mClaimAll($agent_id)
  1372. {
  1373. $id = Auth::guard('ms')->id();
  1374. $user = Staff::with('StaffDetail')->find($id);
  1375. $getid = $agent_id;
  1376. $temp = StaffDetail::where('_id', $agent_id)->first();
  1377. $company = $temp->company_id;
  1378. return view('market.claim_list',compact('user','getid','company'));
  1379. }
  1380. //Show claim list by company
  1381. public function mClaimListAll($company)
  1382. {
  1383. $id = Auth::guard('ms')->id();
  1384. $user = Staff::with('StaffDetail')->find($id);
  1385. $dealer_claimAll = DealerClaim::where('dealer',$company)->orderBy('activated_dt','desc')->get();
  1386. $i = 0;
  1387. $nested_data = array();
  1388. foreach ($dealer_claimAll as $c){
  1389. $customer = Subscriber::with('Form')->where('_id', $c->customer_id)->first();
  1390. $address = '';
  1391. if($customer->Form->type_application == 'R'){
  1392. if($customer->street != ''){
  1393. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1394. }else {
  1395. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1396. }
  1397. }else if($customer->Form->type_application == 'B'){
  1398. if($customer->unit_no != ''){
  1399. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1400. }else {
  1401. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1402. }
  1403. }
  1404. $i++;
  1405. array_push($nested_data, array(
  1406. 'index' => $i.$c->formT,
  1407. 'contract' => $c->contract,
  1408. 'wo' => $c->wo,
  1409. 'activated_dt' => $c->activated_dt,
  1410. 'name' => $customer->name,
  1411. 'address' => $address,
  1412. 'package' => $c->package,
  1413. 'retail_price' => 'RM '.$c->retail_price,
  1414. 'incentives1' => '',
  1415. 'incentives2' => '',
  1416. 'total' => '',
  1417. 'claimed' => $c->laim_dt,
  1418. 'action' => 'null',
  1419. ));
  1420. }
  1421. return \DataTables::of($nested_data)->make(true);
  1422. }
  1423. // Get Dealer Claim Residential
  1424. public function returnDataR($company,$year,$month){
  1425. $dataCR = DealerClaim::where('formT','R')->where('dealer',$company)->get();
  1426. $final = array();
  1427. // Month & Year
  1428. $mY = '';
  1429. if($year != 'null' && $month != 'null'){
  1430. $mY = $month.'/'.$year;
  1431. }
  1432. if($mY != ''){
  1433. $data12 = array(); $data24 = array();
  1434. $countD12 = 0; $countD24 = 0;
  1435. foreach($dataCR as $dc){
  1436. if($dc->activated_my == $mY || $dc->activated_my == '0'.$mY ){
  1437. if($dc->contract == "12"){
  1438. $data12[] = $dc;
  1439. }else if($dc->contract == "24"){
  1440. $data24[] = $dc;
  1441. }
  1442. }
  1443. }
  1444. $countD24 = count($data24);
  1445. $countD12 = count($data12);
  1446. $comm = Commission::where('formT','R')->get();
  1447. $commV12 = 0; $commV24 = 0;
  1448. $comm12 = ''; $comm24 = '';
  1449. foreach($comm as $c){
  1450. if($c->contract =='12'){
  1451. if(strpos($c->ranges, '>') !== false) {
  1452. $pieces = explode(">", $c->ranges);
  1453. if($countD12 >= intval($pieces[1])){
  1454. $commV12 = floatval($c->comm)/100;
  1455. $comm12 = $c->comm.'%';
  1456. }
  1457. }
  1458. if(strpos($c->ranges,'-') !== false){
  1459. $pieces = explode("-", $c->ranges);
  1460. if($countD12 >= intval($pieces[0]) && $countD12 <= intval($pieces[1])){
  1461. $commV12 = floatval($c->comm)/100;
  1462. $comm12 = $c->comm.'%';
  1463. }
  1464. }
  1465. }else if($c->contract =='24'){
  1466. // Contract => 24
  1467. if($countD24 != 0){
  1468. if(strpos($c->ranges, '>') !== false) {
  1469. $pieces = explode(">", $c->ranges);
  1470. if($countD24 > intval($pieces[1])){
  1471. $commV24 = floatval($c->comm)/100;
  1472. $comm24 = $c->comm.'%';
  1473. }
  1474. }
  1475. if(strpos($c->ranges,'-') !== false){
  1476. $pieces = explode("-", $c->ranges);
  1477. if($countD24 >= intval($pieces[0]) && $countD24 <= intval($pieces[1])){
  1478. $commV24 = floatval($c->comm)/100;
  1479. $comm24 = $c->comm.'%';
  1480. }
  1481. }
  1482. }
  1483. }
  1484. }
  1485. foreach ($data12 as $key => $d) {
  1486. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1487. $address = '';
  1488. if($customer->Form->type_application == 'R'){
  1489. if($customer->street != ''){
  1490. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1491. }else {
  1492. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1493. }
  1494. }else if($customer->Form->type_application == 'B'){
  1495. if($customer->unit_no != ''){
  1496. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1497. }else {
  1498. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1499. }
  1500. }
  1501. $final[] = array(
  1502. 'index' => $d['formT'],
  1503. 'contract' => $d['contract'],
  1504. 'wo' => $d['wo'],
  1505. 'activation' => $d['activated_dt'],
  1506. 'name' => $customer->name,
  1507. 'address' => $address,
  1508. 'package' => $d['package'],
  1509. 'retail_price' => 'RM '.$d['retail_price'],
  1510. 'incentives1' => $comm12,
  1511. 'incentives2' => '',
  1512. 'total' => 'RM '.number_format($d['retail_price']*$commV12,2),
  1513. 'claim' => $d['claim_dt'],
  1514. );
  1515. }
  1516. foreach ($data24 as $key => $d) {
  1517. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1518. $address = '';
  1519. if($customer->Form->type_application == 'R'){
  1520. if($customer->street != ''){
  1521. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1522. }else {
  1523. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1524. }
  1525. }else if($customer->Form->type_application == 'B'){
  1526. if($customer->unit_no != ''){
  1527. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1528. }else {
  1529. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1530. }
  1531. }
  1532. $final[] = array(
  1533. 'index' => $d['formT'],
  1534. 'contract' => $d['contract'],
  1535. 'wo' => $d['wo'],
  1536. 'activation' => $d['activated_dt'],
  1537. 'name' => $customer->name,
  1538. 'address' => $address,
  1539. 'package' => $d['package'],
  1540. 'retail_price' => 'RM '.$d['retail_price'],
  1541. 'incentives1' => $comm24,
  1542. 'incentives2' => '',
  1543. 'total' => 'RM '.number_format($d['retail_price']*$commV24,2),
  1544. 'claim' => $d['claim_dt'],
  1545. );
  1546. }
  1547. }else {
  1548. foreach ($dataCR as $c){
  1549. $customer = Subscriber::with('Form')->where('_id', $c['customer_id'])->first();
  1550. $address = '';
  1551. if($customer->Form->type_application == 'R'){
  1552. if($customer->street != ''){
  1553. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1554. }else {
  1555. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1556. }
  1557. }else if($customer->Form->type_application == 'B'){
  1558. if($customer->unit_no != ''){
  1559. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1560. }else {
  1561. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1562. }
  1563. }
  1564. $final[] = array(
  1565. 'index' => $c['formT'],
  1566. 'contract' => $c['contract'],
  1567. 'wo' => $c['wo'],
  1568. 'activation' => $c['activated_dt'],
  1569. 'name' => $customer->name,
  1570. 'address' => $address,
  1571. 'package' => $c['package'],
  1572. 'retail_price' => 'RM '.$c['retail_price'],
  1573. 'incentives1' => '',
  1574. 'incentives2' => '',
  1575. 'total' => '',
  1576. 'claim' => $c['claim_dt'],
  1577. );
  1578. }
  1579. }
  1580. return $final;
  1581. }
  1582. // Get Claim Business
  1583. public function returnDataB($company,$year,$month){
  1584. $dataCB = DealerClaim::where('formT','B')->where('dealer',$company)->get();
  1585. $final = array();
  1586. // Month & Year
  1587. $mY = '';
  1588. if($year != 'null' && $month != 'null'){
  1589. $mY = $month.'/'.$year;
  1590. }
  1591. if($mY != ''){
  1592. /** Contract 12
  1593. // 1=>10-100 2=>300 3=>500 4=>1
  1594. **/
  1595. $data12_1 = array(); $data12_2 = array();
  1596. $data12_3 = array(); $data12_4 = array();
  1597. $countD12_1 = 0; $countD12_2 = 0;
  1598. $countD12_3 = 0; $countD12_4 = 0;
  1599. /** Contract 24
  1600. // 1=>10-100 2=>300 3=>500 4=>1
  1601. **/
  1602. $data24_1 = array(); $data24_2 = array();
  1603. $data24_3 = array(); $data24_4 = array();
  1604. $countD24_1 = 0; $countD24_2 = 0;
  1605. $countD24_3 = 0; $countD24_4 = 0;
  1606. foreach($dataCB as $dc){
  1607. if($dc->activated_my == $mY || $dc->activated_my == '0'.$mY){
  1608. if($dc->contract == "12" && ($dc->package == "10" || $dc->package == "30" || $dc->package == "50" || $dc->package == "100")){
  1609. $data12_1[] = $dc;
  1610. }else if($dc->contract == "12" && $dc->package == "300"){
  1611. $data12_2[] = $dc;
  1612. }else if($dc->contract == "12" && $dc->package == "500"){
  1613. $data12_3[] = $dc;
  1614. }else if($dc->contract == "12" && $dc->package == "1"){
  1615. $data12_4[] = $dc;
  1616. }else if($dc->contract == "24" && ($dc->package == "10" || $dc->package == "30" || $dc->package == "50" || $dc->package == "100")){
  1617. $data24_1[] = $dc;
  1618. }else if($dc->contract == "24" && $dc->package == "300"){
  1619. $data24_2[] = $dc;
  1620. }else if($dc->contract == "24" && $dc->package == "500"){
  1621. $data24_3[] = $dc;
  1622. }else if($dc->contract == "24" && $dc->package == "1"){
  1623. $data24_4[] = $dc;
  1624. }
  1625. }
  1626. }
  1627. $countD12_1 = count($data12_1); $countD12_2 = count($data12_2);
  1628. $countD12_3 = count($data12_3); $countD12_4 = count($data12_4);
  1629. $countD24_1 = count($data24_1); $countD24_2 = count($data24_2);
  1630. $countD24_3 = count($data24_3); $countD24_4 = count($data24_4);
  1631. $comm = Commission::where('formT','B')->get();
  1632. $commV12_1 = 0; $commV12_2 = 0;
  1633. $commV12_3 = 0; $commV12_4 = 0;
  1634. $commV24_1 = 0; $commV24_2 = 0;
  1635. $commV24_3 = 0; $commV24_4 = 0;
  1636. $comm12_1 = ''; $comm12_2 = '';
  1637. $comm12_3 = ''; $comm12_4 = '';
  1638. $comm24_1 = ''; $comm24_2 = '';
  1639. $comm24_3 = ''; $comm24_4 = '';
  1640. $addRM12_1 = ''; $addRM12_2 = '';
  1641. $addRM12_3 = ''; $addRM12_4 = '';
  1642. $addRM24_1 = ''; $addRM24_2 = '';
  1643. $addRM24_3 = ''; $addRM24_4 = '';
  1644. foreach($comm as $c){
  1645. /*** Contract 24 **/
  1646. if($c->contract =='24' && $c->packageR == "300"){
  1647. if(strpos($c->ranges, '>') !== false) {
  1648. $pieces = explode(">", $c->ranges);
  1649. if($countD24_2 >= intval($pieces[1])){
  1650. if(strpos($c->comm, 'RM') !== false) {
  1651. $comm24_2 = '+ ' .$c->comm;
  1652. $commV24_2 = '';
  1653. $comms = explode("RM", $c->comm);
  1654. $addRM24_2 = floatval($comms[1]);
  1655. }else {
  1656. $comms = explode("RM", $c->comm);
  1657. if(isset($comms[1])){
  1658. $comm24_2 = 'RM '.$comms[1];
  1659. $commV24_2 = floatval($comms[1]);
  1660. }else {
  1661. if($comms[0] != ''){
  1662. $comm24_2 = $comms[0].'%';
  1663. $commV24_2 = floatval($comms[0])/100;
  1664. }
  1665. }
  1666. }
  1667. }
  1668. }
  1669. }else if($c->contract =='24' && $c->packageR == "500"){
  1670. if(strpos($c->ranges, '>') !== false) {
  1671. $pieces = explode(">", $c->ranges);
  1672. if($countD24_3 >= intval($pieces[1])){
  1673. if(strpos($c->comm, 'RM') !== false) {
  1674. $comm24_3 = '+ ' .$c->comm;
  1675. $commV24_3 = '';
  1676. $comms = explode("RM", $c->comm);
  1677. $addRM24_3 = floatval($comms[1]);
  1678. }else {
  1679. $comms = explode("RM", $c->comm);
  1680. if(isset($comms[1])){
  1681. $comm24_3 = 'RM '.$comms[1];
  1682. $commV24_3 = floatval($comms[1]);
  1683. }else {
  1684. if($comms[0] != ''){
  1685. $comm24_3 = $comms[0].'%';
  1686. $commV24_3 = floatval($comms[0])/100;
  1687. }
  1688. }
  1689. }
  1690. }
  1691. }
  1692. }else if($c->contract =='24' && $c->packageR == "1"){
  1693. if(strpos($c->ranges, '>') !== false) {
  1694. $pieces = explode(">", $c->ranges);
  1695. if($countD24_4 >= intval($pieces[1])){
  1696. if(strpos($c->comm, 'RM') !== false) {
  1697. $comm24_4 = '+ ' .$c->comm;
  1698. $commV24_4 = '';
  1699. $comms = explode("RM", $c->comm);
  1700. $addRM24_4 = floatval($comms[1]);
  1701. }else {
  1702. $comms = explode("RM", $c->comm);
  1703. if(isset($comms[1])){
  1704. $comm24_4 = 'RM '.$comms[1];
  1705. $commV24_4 = floatval($comms[1]);
  1706. }else {
  1707. if($comms[0] != ''){
  1708. $comm24_4 = $comms[0].'%';
  1709. $commV24_4 = floatval($comms[0])/100;
  1710. }
  1711. }
  1712. }
  1713. }
  1714. }
  1715. }else if($c->contract =='24' && $c->packageR == "10,30,50,100"){
  1716. if(strpos($c->ranges,'-') !== false){
  1717. $pieces = explode("-", $c->ranges);
  1718. if($countD24_1 >= intval($pieces[0]) && $countD24_1 <= intval($pieces[1])){
  1719. if(strpos($c->comm, 'RM') !== false) {
  1720. $comm24_1 = '+ ' .$c->comm;
  1721. $commV24_1 = '';
  1722. $addRM24_1 = $c->comm;
  1723. }else {
  1724. $comms = explode("RM", $c->comm);
  1725. if(!empty($comms[1])){
  1726. $comm24_1 = 'RM '.$comms[1];
  1727. $commV24_1 = floatval($comms[1]);
  1728. }else {
  1729. if($comms[0] != ''){
  1730. $comm24_1 = $comms[0].'%';
  1731. $commV24_1 = floatval($comms[0])/100;
  1732. }
  1733. }
  1734. }
  1735. }
  1736. }
  1737. if(strpos($c->ranges, '>') !== false) {
  1738. $pieces1 = explode(">", $c->ranges);
  1739. if($countD24_1 >= intval($pieces1[1])){
  1740. if(strpos($c->comm, "RM") === true) {
  1741. $comm24_1 = '+ ' .$c->comm;
  1742. $commV24_1 = '';
  1743. $addRM24_1 = $c->comm;
  1744. }else {
  1745. $comms = explode("RM", $c->comm);
  1746. if(empty($comms[1])){
  1747. $comm24_1 = 'RM '.$comms[1];
  1748. $commV24_1 = floatval($comms[1]);
  1749. }else {
  1750. if($comms[0] != ''){
  1751. $comm24_1 = str_replace ('+ ','',$comms[0]).'%';
  1752. $commV24_1 = floatval($comms[0])/100;
  1753. $addRM24_1 = $comms[1];
  1754. }
  1755. }
  1756. }
  1757. }
  1758. }
  1759. }
  1760. /*** Contract 12 **/
  1761. else if($c->contract =='12' && $c->packageR == "10,30,50,100"){
  1762. if(strpos($c->ranges, '>') !== false) {
  1763. $pieces = explode(">", $c->ranges);
  1764. if($countD12_1 >= intval($pieces[1])){
  1765. if(strpos($c->comm, 'RM') !== false) {
  1766. $comm12_1 = '+ ' .$c->comm;
  1767. $commV12_1 = '';
  1768. $addRM12_1 = $c->comm;
  1769. }else {
  1770. $comms = explode("RM", $c->comm);
  1771. if(isset($comms[1])){
  1772. $comm12_1 = 'RM '.$comms[1];
  1773. $commV12_1 = floatval($comms[1]);
  1774. }else {
  1775. if($comms[0] != ''){
  1776. $comm12_1 = $comms[0].'%';
  1777. $commV12_1 = floatval($comms[0])/100;
  1778. }
  1779. }
  1780. }
  1781. }
  1782. }
  1783. if(strpos($c->ranges,'-') !== false){
  1784. $pieces = explode("-", $c->ranges);
  1785. if($countD12_1 >= intval($pieces[0]) && $countD12_1 <= intval($pieces[1])){
  1786. if(strpos($c->comm, 'RM') !== false) {
  1787. $comm12_1 = '+ ' .$c->comm;
  1788. $commV12_1 = '';
  1789. $addRM12_1 = $c->comm;
  1790. }else {
  1791. $comms = explode("RM", $c->comm);
  1792. if(isset($comms[1])){
  1793. $comm12_1 = 'RM '.$comms[1];
  1794. $commV12_1 = floatval($comms[1]);
  1795. }else {
  1796. if($comms[0] != ''){
  1797. $comm12_1 = $comms[0].'%';
  1798. $commV12_1 = floatval($comms[0])/100;
  1799. }
  1800. }
  1801. }
  1802. }
  1803. }
  1804. }else if($c->contract =='12' && $c->packageR == "300"){
  1805. if(strpos($c->ranges, '>') !== false) {
  1806. $pieces = explode(">", $c->ranges);
  1807. if($countD12_2 >= intval($pieces[1])){
  1808. if(strpos($c->comm, 'RM') !== false) {
  1809. $comm12_2 = '+ ' .$c->comm;
  1810. $commV12_2 = '';
  1811. $addRM12_2 = $c->comm;
  1812. }else {
  1813. $comms = explode("RM", $c->comm);
  1814. if(isset($comms[1])){
  1815. $comm12_2 = 'RM '.$comms[1];
  1816. $commV12_2 = floatval($comms[1]);
  1817. }else {
  1818. if($comms[0] != ''){
  1819. $comm12_2 = $comms[0].'%';
  1820. $commV12_2 = floatval($comms[0])/100;
  1821. }
  1822. }
  1823. }
  1824. }
  1825. }
  1826. }else if($c->contract =='12' && $c->packageR == "500"){
  1827. if(strpos($c->ranges, '>') !== false) {
  1828. $pieces = explode(">", $c->ranges);
  1829. if($countD12_3 >= intval($pieces[1])){
  1830. if(strpos($c->comm, 'RM') !== false) {
  1831. $comm12_3 = '+ ' .$c->comm;
  1832. $commV12_3 = '';
  1833. $addRM12_3 = $c->comm;
  1834. }else {
  1835. $comms = explode("RM", $c->comm);
  1836. if(isset($comms[1])){
  1837. $comm12_3 = 'RM '.$comms[1];
  1838. $commV12_3 = floatval($comms[1]);
  1839. }else {
  1840. if($comms[0] != ''){
  1841. $comm12_3 = $comms[0].'%';
  1842. $commV12_3 = floatval($comms[0])/100;
  1843. }
  1844. }
  1845. }
  1846. }
  1847. }
  1848. }else if($c->contract =='12' && $c->packageR == "1"){
  1849. if(strpos($c->ranges, '>') !== false) {
  1850. $pieces = explode(">", $c->ranges);
  1851. if($countD12_4 >= intval($pieces[1])){
  1852. if(strpos($c->comm, 'RM') !== false) {
  1853. $comm12_4 = '+ ' .$c->comm;
  1854. $commV12_4 = '';
  1855. $addRM12_4 = $c->comm;
  1856. }else {
  1857. $comms = explode("RM", $c->comm);
  1858. if(isset($comms[1])){
  1859. $comm12_4 = 'RM '.$comms[1];
  1860. $commV12_4 = floatval($comms[1]);
  1861. }else {
  1862. if($comms[0] != ''){
  1863. $comm12_4 = $comms[0].'%';
  1864. $commV12_4 = floatval($comms[0])/100;
  1865. }
  1866. }
  1867. }
  1868. }
  1869. }
  1870. }
  1871. }
  1872. // Category 10,30,50,100
  1873. foreach ($data12_1 as $key => $d) {
  1874. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1875. $address = '';
  1876. if($customer->Form->type_application == 'R'){
  1877. if($customer->street != ''){
  1878. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1879. }else {
  1880. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1881. }
  1882. }else if($customer->Form->type_application == 'B'){
  1883. if($customer->unit_no != ''){
  1884. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1885. }else {
  1886. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1887. }
  1888. }
  1889. $total = '';
  1890. if($commV12_1 == ''){
  1891. $total = $addRM12_1;
  1892. }else {
  1893. $total = number_format($d['retail_price']*$commV12_1,2);
  1894. }
  1895. $final[] = array(
  1896. 'index' => $d['formT'],
  1897. 'contract' => $d['contract'],
  1898. 'wo' => $d['wo'],
  1899. 'activation' => $d['activated_dt'],
  1900. 'name' => $customer->name,
  1901. 'address' => $address,
  1902. 'package' => $d['package'],
  1903. 'retail_price' => 'RM '.$d['retail_price'],
  1904. 'incentives1' => $comm12_1,
  1905. 'incentives2' => $addRM12_1,
  1906. 'total' => 'RM '.$total,
  1907. 'claim' => $c['claim_dt'],
  1908. );
  1909. }
  1910. foreach ($data24_1 as $key => $d) {
  1911. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1912. $address = '';
  1913. if($customer->Form->type_application == 'R'){
  1914. if($customer->street != ''){
  1915. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1916. }else {
  1917. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1918. }
  1919. }else if($customer->Form->type_application == 'B'){
  1920. if($customer->unit_no != ''){
  1921. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1922. }else {
  1923. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1924. }
  1925. }
  1926. $total = '';
  1927. if($commV24_1 == ''){
  1928. $total = $addRM24_1;
  1929. }else {
  1930. $total = number_format(($d['retail_price']*$commV24_1) + floatval($addRM24_1),2);
  1931. }
  1932. $final[] = array(
  1933. 'index' => $d['formT'],
  1934. 'contract' => $d['contract'],
  1935. 'wo' => $d['wo'],
  1936. 'activation' => $d['activated_dt'],
  1937. 'name' => $customer->name,
  1938. 'address' => $address,
  1939. 'package' => $d['package'],
  1940. 'retail_price' => 'RM '.$d['retail_price'],
  1941. 'incentives1' => $comm24_1,
  1942. 'incentives2' => $addRM24_1,
  1943. 'total' => 'RM '.$total,
  1944. 'claim' => $c['claim_dt'],
  1945. );
  1946. }
  1947. // Category 300
  1948. foreach ($data12_2 as $key => $d) {
  1949. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1950. $address = '';
  1951. if($customer->Form->type_application == 'R'){
  1952. if($customer->street != ''){
  1953. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1954. }else {
  1955. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1956. }
  1957. }else if($customer->Form->type_application == 'B'){
  1958. if($customer->unit_no != ''){
  1959. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1960. }else {
  1961. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1962. }
  1963. }
  1964. $total = '';
  1965. if($commV12_2 == ''){
  1966. $total = $addRM12_2;
  1967. }else {
  1968. $total = number_format($d['retail_price']*$commV12_2,2);
  1969. }
  1970. $final[] = array(
  1971. 'index' => $d['formT'],
  1972. 'contract' => $d['contract'],
  1973. 'wo' => $d['wo'],
  1974. 'activation' => $d['activated_dt'],
  1975. 'name' => $customer->name,
  1976. 'address' => $address,
  1977. 'package' => $d['package'],
  1978. 'retail_price' => 'RM '.$d['retail_price'],
  1979. 'incentives1' => $commV12_2,
  1980. 'incentives2' => $addRM12_2,
  1981. 'total' => 'RM '.$total,
  1982. 'claim' => $c['claim_dt'],
  1983. );
  1984. }
  1985. foreach ($data24_2 as $key => $d) {
  1986. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1987. $address = '';
  1988. if($customer->Form->type_application == 'R'){
  1989. if($customer->street != ''){
  1990. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1991. }else {
  1992. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1993. }
  1994. }else if($customer->Form->type_application == 'B'){
  1995. if($customer->unit_no != ''){
  1996. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1997. }else {
  1998. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1999. }
  2000. }
  2001. $total = '';
  2002. if($commV24_2 == ''){
  2003. $total = $addRM24_2;//number_format($d['retail_price']+$addRM24_2,2);
  2004. }else {
  2005. $total = number_format($d['retail_price']*$commV24_2,2);
  2006. }
  2007. $final[] = array(
  2008. 'index' => $d['formT'],
  2009. 'contract' => $d['contract'],
  2010. 'wo' => $d['wo'],
  2011. 'activation' => $d['activated_dt'],
  2012. 'name' => $customer->name,
  2013. 'address' => $address,
  2014. 'package' => $d['package'],
  2015. 'retail_price' => 'RM '.$d['retail_price'],
  2016. 'incentives1' => $commV24_2,
  2017. 'incentives2' => $comm24_2,
  2018. 'total' => 'RM '.$total,
  2019. 'claim' => $c['claim_dt'],
  2020. );
  2021. }
  2022. // Category 500
  2023. foreach ($data12_3 as $key => $d) {
  2024. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  2025. $address = '';
  2026. if($customer->Form->type_application == 'R'){
  2027. if($customer->street != ''){
  2028. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  2029. }else {
  2030. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  2031. }
  2032. }else if($customer->Form->type_application == 'B'){
  2033. if($customer->unit_no != ''){
  2034. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  2035. }else {
  2036. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  2037. }
  2038. }
  2039. $total = '';
  2040. if($commV12_3 == ''){
  2041. $total = $addRM12_3;
  2042. }else {
  2043. $total = number_format($d['retail_price']*$commV12_3,2);
  2044. }
  2045. $final[] = array(
  2046. 'index' => $d['formT'],
  2047. 'contract' => $d['contract'],
  2048. 'wo' => $d['wo'],
  2049. 'activation' => $d['activated_dt'],
  2050. 'name' => $customer->name,
  2051. 'address' => $address,
  2052. 'package' => $d['package'],
  2053. 'retail_price' => 'RM '.$d['retail_price'],
  2054. 'incentives1' => $commV12_3,
  2055. 'incentives2' => $addRM12_3,
  2056. 'total' => 'RM '.$total,
  2057. 'claim' => $c['claim_dt'],
  2058. );
  2059. }
  2060. foreach ($data24_3 as $key => $d) {
  2061. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  2062. $address = '';
  2063. if($customer->Form->type_application == 'R'){
  2064. if($customer->street != ''){
  2065. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  2066. }else {
  2067. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  2068. }
  2069. }else if($customer->Form->type_application == 'B'){
  2070. if($customer->unit_no != ''){
  2071. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  2072. }else {
  2073. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  2074. }
  2075. }
  2076. $total = '';
  2077. if($commV24_3 == ''){
  2078. $total = $addRM24_3; //number_format($d['retail_price']+$addRM24_3,2);
  2079. }else {
  2080. $total = number_format($d['retail_price']*$commV24_3,2);
  2081. }
  2082. $final[] = array(
  2083. 'index' => $d['formT'],
  2084. 'contract' => $d['contract'],
  2085. 'wo' => $d['wo'],
  2086. 'activation' => $d['activated_dt'],
  2087. 'name' => $customer->name,
  2088. 'address' => $address,
  2089. 'package' => $d['package'],
  2090. 'retail_price' => 'RM '.$d['retail_price'],
  2091. 'incentives1' => $commV24_3,
  2092. 'incentives2' => $comm24_3,
  2093. 'total' => 'RM '.$total,
  2094. 'claim' => $c['claim_dt'],
  2095. );
  2096. }
  2097. // Category 1
  2098. foreach ($data12_4 as $key => $d) {
  2099. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  2100. $address = '';
  2101. if($customer->Form->type_application == 'R'){
  2102. if($customer->street != ''){
  2103. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  2104. }else {
  2105. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  2106. }
  2107. }else if($customer->Form->type_application == 'B'){
  2108. if($customer->unit_no != ''){
  2109. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  2110. }else {
  2111. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  2112. }
  2113. }
  2114. $total = '';
  2115. if($commV12_4 == ''){
  2116. $total = $addRM12_4;
  2117. }else {
  2118. $total = number_format($d['retail_price']*$commV12_4,2);
  2119. }
  2120. $final[] = array(
  2121. 'index' => $d['formT'],
  2122. 'contract' => $d['contract'],
  2123. 'wo' => $d['wo'],
  2124. 'activation' => $d['activated_dt'],
  2125. 'name' => $customer->name,
  2126. 'address' => $address,
  2127. 'package' => $d['package'],
  2128. 'retail_price' => 'RM '.$d['retail_price'],
  2129. 'incentives1' => $commV12_4,
  2130. 'incentives2' => $addRM12_4,
  2131. 'total' => 'RM '.$total,
  2132. 'claim' => $c['claim_dt'],
  2133. );
  2134. }
  2135. foreach ($data24_4 as $key => $d) {
  2136. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  2137. $address = '';
  2138. if($customer->Form->type_application == 'R'){
  2139. if($customer->street != ''){
  2140. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  2141. }else {
  2142. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  2143. }
  2144. }else if($customer->Form->type_application == 'B'){
  2145. if($customer->unit_no != ''){
  2146. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  2147. }else {
  2148. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  2149. }
  2150. }
  2151. $total = '';
  2152. if($commV24_4 == ''){
  2153. $total = $addRM24_4; //number_format($d['retail_price']+$addRM24_4,2);
  2154. }else {
  2155. $total = number_format($d['retail_price']*$commV24_4,2);
  2156. }
  2157. $final[] = array(
  2158. 'index' => $d['formT'],
  2159. 'contract' => $d['contract'],
  2160. 'wo' => $d['wo'],
  2161. 'activation' => $d['activated_dt'],
  2162. 'name' => $customer->name,
  2163. 'address' => $address,
  2164. 'package' => $d['package'],
  2165. 'retail_price' => 'RM '.$d['retail_price'],
  2166. 'incentives1' => $commV24_4,
  2167. 'incentives2' => $comm24_4,
  2168. 'total' => 'RM '.$total,
  2169. 'claim' => $c['claim_dt'],
  2170. );
  2171. }
  2172. }else {
  2173. foreach ($dataCB as $c){
  2174. $customer = Subscriber::with('Form')->where('_id', $c['customer_id'])->first();
  2175. $address = '';
  2176. if($customer->Form->type_application == 'R'){
  2177. if($customer->street != ''){
  2178. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  2179. }else {
  2180. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  2181. }
  2182. }else if($customer->Form->type_application == 'B'){
  2183. if($customer->unit_no != ''){
  2184. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  2185. }else {
  2186. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  2187. }
  2188. }
  2189. $final[] = array(
  2190. 'index' => $c['formT'],
  2191. 'contract' => $c['contract'],
  2192. 'wo' => $c['wo'],
  2193. 'activation' => $c['activated_dt'],
  2194. 'name' => $customer->name,
  2195. 'address' => $address,
  2196. 'package' => $c['package'],
  2197. 'retail_price' => 'RM '.$c['retail_price'],
  2198. 'incentives1' => '',
  2199. 'incentives2' => '',
  2200. 'total' => '',
  2201. 'claim' => $c['claim_dt'],
  2202. );
  2203. }
  2204. }
  2205. return $final;
  2206. }
  2207. public function filterclaim($company,$year,$month,$app)
  2208. {
  2209. $id = Auth::guard('ms')->id();
  2210. $user = Staff::with('StaffDetail')->find($id);
  2211. $dataR = array(); $dataB = array(); $combineData = array();
  2212. if($year!='null' && $month!='null' && $app=='null'){
  2213. $dataR = $this->returnDataR($company,$year,$month);
  2214. $dataB = $this->returnDataB($company,$year,$month);
  2215. foreach($dataR as $r){
  2216. $combineData[] = $r;
  2217. }
  2218. foreach($dataB as $b){
  2219. $combineData[] = $b;
  2220. }
  2221. $i = 0;
  2222. $nested_data = array();
  2223. if(!empty($combineData)){
  2224. foreach ($combineData as $c){
  2225. $i++;
  2226. array_push($nested_data, array(
  2227. 'index' => $i.$c['index'],
  2228. 'contract' => $c['contract'],
  2229. 'wo' => $c['wo'],
  2230. 'activated_dt' => $c['activation'],
  2231. 'name' => $c['name'],
  2232. 'address' => $c['address'],
  2233. 'package' => $c['package'],
  2234. 'retail_price' => $c['retail_price'],
  2235. 'incentives1' => $c['incentives1'],
  2236. 'incentives2' => $c['incentives2'],
  2237. 'total' => $c['total'],
  2238. 'claimed' => $c['claim'],
  2239. ));
  2240. }
  2241. }
  2242. return \DataTables::of($nested_data)->make(true);
  2243. }else if($year=='null' && $month=='null' && $app!='null'){
  2244. if($app == 'Residential'){
  2245. $dataR = $this->returnDataR($company,$year,$month);
  2246. }else if($app == 'Business'){
  2247. $dataB = $this->returnDataB($company,$year,$month);
  2248. }
  2249. foreach($dataR as $r){
  2250. $combineData[] = $r;
  2251. }
  2252. foreach($dataB as $b){
  2253. $combineData[] = $b;
  2254. }
  2255. $i = 0;
  2256. $nested_data = array();
  2257. if(!empty($combineData)){
  2258. foreach ($combineData as $c){
  2259. $i++;
  2260. array_push($nested_data, array(
  2261. 'index' => $i.$c['index'],
  2262. 'contract' => $c['contract'],
  2263. 'wo' => $c['wo'],
  2264. 'activated_dt' => $c['activation'],
  2265. 'name' => $c['name'],
  2266. 'address' => $c['address'],
  2267. 'package' => $c['package'],
  2268. 'retail_price' => $c['retail_price'],
  2269. 'incentives1' => $c['incentives1'],
  2270. 'incentives2' => $c['incentives2'],
  2271. 'total' => $c['total'],
  2272. 'claimed' => $c['claim'],
  2273. ));
  2274. }
  2275. }
  2276. return \DataTables::of($nested_data)->make(true);
  2277. }else if($year!='null' && $month!='null' && $app!='null'){
  2278. if($app == 'Residential'){
  2279. $dataR = $this->returnDataR($company,$year,$month);
  2280. }else if($app == 'Business'){
  2281. $dataB = $this->returnDataB($company,$year,$month);
  2282. }
  2283. foreach($dataR as $r){
  2284. $combineData[] = $r;
  2285. }
  2286. foreach($dataB as $b){
  2287. $combineData[] = $b;
  2288. }
  2289. $i = 0;
  2290. $nested_data = array();
  2291. if(!empty($combineData)){
  2292. foreach ($combineData as $c){
  2293. $i++;
  2294. array_push($nested_data, array(
  2295. 'index' => $i.$c['index'],
  2296. 'contract' => $c['contract'],
  2297. 'wo' => $c['wo'],
  2298. 'activated_dt' => $c['activation'],
  2299. 'name' => $c['name'],
  2300. 'address' => $c['address'],
  2301. 'package' => $c['package'],
  2302. 'retail_price' => $c['retail_price'],
  2303. 'incentives1' => $c['incentives1'],
  2304. 'incentives2' => $c['incentives2'],
  2305. 'total' => $c['total'],
  2306. 'claimed' => $c['claim'],
  2307. ));
  2308. }
  2309. }
  2310. return \DataTables::of($nested_data)->make(true);
  2311. }
  2312. }
  2313. public function exportPDFClaim($company,$year,$month,$app) {
  2314. $final = array();
  2315. $id = Auth::guard('ms')->id();
  2316. $user = Staff::with('StaffDetail')->find($id);
  2317. $com = Company::where('_id',$company)->first();
  2318. $dataR = array(); $dataB = array(); $combineData = array();
  2319. if($year!='null' && $month!='null' && $app=='null'){
  2320. $dataR = $this->returnDataR($company,$year,$month);
  2321. $dataB = $this->returnDataB($company,$year,$month);
  2322. foreach($dataR as $r){
  2323. $combineData[] = $r;
  2324. }
  2325. foreach($dataB as $b){
  2326. $combineData[] = $b;
  2327. }
  2328. $i = 0;
  2329. $nested_data = array();
  2330. if(!empty($combineData)){
  2331. foreach ($combineData as $c){
  2332. $i++;
  2333. array_push($final, array(
  2334. 'index' => $i.$c['index'],
  2335. 'contract' => $c['contract'],
  2336. 'wo' => $c['wo'],
  2337. 'activated_dt' => $c['activation'],
  2338. 'name' => $c['name'],
  2339. 'address' => $c['address'],
  2340. 'package' => $c['package'],
  2341. 'retail_price' => $c['retail_price'],
  2342. 'incentives1' => $c['incentives1'],
  2343. 'incentives2' => $c['incentives2'],
  2344. 'total' => $c['total'],
  2345. 'claimed' => $c['claim'],
  2346. ));
  2347. }
  2348. }
  2349. $totals = 0;
  2350. foreach($final as $f){
  2351. $totals += floatval(str_replace('RM ', '', $f['total']));
  2352. }
  2353. $pdf = PDF::loadView('pdf.agent-claim', compact('final', 'month', 'year','com','totals'));
  2354. $pdf->setPaper('A4', 'landscape');
  2355. $pdfName = preg_replace('/\s+/', '-', $com->name).'-'.$month.'-'.$year.'.pdf';
  2356. return $pdf->download( $pdfName );
  2357. }else if($year!='null' && $month!='null' && $app!='null'){
  2358. if($app == 'Residential'){
  2359. $dataR = $this->returnDataR($company,$year,$month);
  2360. }else if($app == 'Business'){
  2361. $dataB = $this->returnDataB($company,$year,$month);
  2362. }
  2363. foreach($dataR as $r){
  2364. $combineData[] = $r;
  2365. }
  2366. foreach($dataB as $b){
  2367. $combineData[] = $b;
  2368. }
  2369. $i = 0;
  2370. $nested_data = array();
  2371. if(!empty($combineData)){
  2372. foreach ($combineData as $c){
  2373. $i++;
  2374. array_push($final, array(
  2375. 'index' => $i.$c['index'],
  2376. 'contract' => $c['contract'],
  2377. 'wo' => $c['wo'],
  2378. 'activated_dt' => $c['activation'],
  2379. 'name' => $c['name'],
  2380. 'address' => $c['address'],
  2381. 'package' => $c['package'],
  2382. 'retail_price' => $c['retail_price'],
  2383. 'incentives1' => $c['incentives1'],
  2384. 'incentives2' => $c['incentives2'],
  2385. 'total' => $c['total'],
  2386. 'claimed' => $c['claim'],
  2387. ));
  2388. }
  2389. }
  2390. $totals = 0;
  2391. foreach($final as $f){
  2392. $totals += floatval(str_replace('RM ', '', $f['total']));
  2393. }
  2394. $pdf = PDF::loadView('pdf.agent-claim', compact('final', 'month', 'year','com','totals'));
  2395. $pdf->setPaper('A4', 'landscape');
  2396. $pdfName = preg_replace('/\s+/', '-', $com->name).'-'.$month.'-'.$year.'.pdf';
  2397. return $pdf->download( $pdfName );
  2398. }
  2399. }
  2400. }