You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SalesController.php 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <?php
  2. namespace App\Http\Controllers\DS;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use Illuminate\Support\Facades\Auth;
  6. use Carbon\Carbon;
  7. use Validator;
  8. use PDF;
  9. use App\Staff;
  10. use App\Model\StaffDetail;
  11. use App\Model\Form;
  12. use App\Model\Subscriber;
  13. use App\Model\PackageDetail;
  14. use App\Model\FormStatus;
  15. use App\Model\WorkOrder;
  16. use App\Model\Docket;
  17. use App\Model\Coverage;
  18. use App\Model\DealerClaim;
  19. use App\Model\Commission;
  20. use App\Model\Company;
  21. class SalesController extends Controller
  22. {
  23. /***
  24. / Application Form List
  25. ***/
  26. public function viewAppList(){
  27. $id = Auth::guard('agent')->id();
  28. $user = Staff::with('StaffDetail')->find($id);
  29. return view('sales.application-form-list',compact('user'));
  30. }
  31. public function gApplicationList1(){
  32. $id = Auth::guard('agent')->id();
  33. $user = Staff::with('StaffDetail')->find($id);
  34. $forms = Form::with('Subscriber','PackageDetail','WorkOrder')->where('dealer_id', $user->_id)->orderBy('created_at','desc')->get();
  35. $i = 0; $street = ''; $n1 = '';
  36. $curr = Carbon::now()->getTimestamp();
  37. $nested_data = array();
  38. if(!empty($forms)){
  39. foreach ($forms as $c){
  40. if(empty($c->WorkOrder)){
  41. $i++;
  42. if($c->Subscriber->street != null){
  43. $street = $c->Subscriber->street;
  44. }
  45. $agentName = StaffDetail::where('_id',$c->dealer_id)->first();
  46. $n1 = '';
  47. $reg_time = $c->created_at;
  48. $expiry_date = $reg_time->addDays(3);
  49. $expiry_date = $expiry_date->getTimestamp();
  50. if($curr < $expiry_date) {
  51. $n1 = "New/";
  52. }
  53. $address = ''; $name = '';
  54. if($c->type_application == 'R'){
  55. $address = $c->Subscriber->building_name;
  56. $name = $c->Subscriber->name;
  57. }else if($c->type_application == 'B'){
  58. $address = '-';
  59. $name = $c->Subscriber->company_name;
  60. }
  61. array_push($nested_data, array(
  62. 'index' => $n1.$i.$c->type_application,
  63. 'name' => $name,
  64. 'phone' => $c->Subscriber->phone1,
  65. 'unit' => $c->Subscriber->unit_no,
  66. 'building' => $address,
  67. 'street' => $street,
  68. 'postcode' => $c->Subscriber->postcode,
  69. 'city' => $c->Subscriber->city,
  70. 'sales' => $agentName->name,
  71. 'action' => $c->_id
  72. ));
  73. }
  74. }
  75. }
  76. return \DataTables::of($nested_data)->make(true);
  77. }
  78. public function gApplicationList2(){
  79. $id = Auth::guard('agent')->id();
  80. $user = Staff::with('StaffDetail')->find($id);
  81. $forms = Form::with('Subscriber','PackageDetail','WorkOrder')->where('dealer_id', $user->_id)->orderBy('created_at','desc')->get();
  82. $i = 0; $street = ''; $n1 = '';
  83. $curr = Carbon::now()->getTimestamp();
  84. $nested_data = array();
  85. if(!empty($forms)){
  86. foreach ($forms as $c){
  87. if(!empty($c->WorkOrder)){
  88. if($c->WorkOrder->status != 'Completed') {
  89. $i++;
  90. if($c->Subscriber->street != null){
  91. $street = $c->Subscriber->street;
  92. }
  93. $agentName = StaffDetail::where('_id',$c->dealer_id)->first();
  94. $n1 = '';
  95. $reg_time = $c->created_at;
  96. $expiry_date = $reg_time->addDays(3);
  97. $expiry_date = $expiry_date->getTimestamp();
  98. if($curr < $expiry_date) {
  99. $n1 = "New/";
  100. }
  101. $address = ''; $name = '';
  102. if($c->type_application == 'R'){
  103. $address = $c->Subscriber->building_name;
  104. $name = $c->Subscriber->name;
  105. }else if($c->type_application == 'B'){
  106. $address = '-';
  107. $name = $c->Subscriber->company_name;
  108. }
  109. array_push($nested_data, array(
  110. 'index' => $n1.$i.$c->type_application,
  111. 'name' => $name,
  112. 'phone' => $c->Subscriber->phone1,
  113. 'unit' => $c->Subscriber->unit_no,
  114. 'building' => $address,
  115. 'street' => $street,
  116. 'postcode' => $c->Subscriber->postcode,
  117. 'city' => $c->Subscriber->city,
  118. 'sales' => $agentName->name,
  119. 'action' => $c->_id
  120. ));
  121. }
  122. }
  123. }
  124. }
  125. return \DataTables::of($nested_data)->make(true);
  126. }
  127. public function gApplicationList3($year, $month){
  128. $id = Auth::guard('agent')->id();
  129. $user = Staff::with('StaffDetail')->find($id);
  130. $forms = Form::with('Subscriber','PackageDetail','WorkOrder')->where('dealer_id', $user->_id)->orderBy('created_at','desc')->get();
  131. $mY = '';
  132. if($year != 'null' && $month != 'null'){
  133. $mY = $year.'-'.$month;
  134. }
  135. $i = 0; $street = ''; $n1 = '';
  136. $final = array(); $filter = array();
  137. $curr = Carbon::now()->getTimestamp();
  138. $nested_data = array();
  139. if(!empty($forms)){
  140. foreach ($forms as $f){
  141. if(!empty($f->WorkOrder)){
  142. if($f->WorkOrder->status == 'Completed') {
  143. $w = WorkOrder::with('Docket')->where('wo', $f->WorkOrder->wo)->first();
  144. if(!empty($w->Docket)){
  145. $dealer = StaffDetail::where('_id', $f->dealer_id)->first();
  146. $i++;
  147. $address = ''; $name = '';
  148. if($f->type_application == 'R'){
  149. $address = $f->Subscriber->building_name;
  150. $name = $f->Subscriber->name;
  151. }else if($f->type_application == 'B'){
  152. $address = '-';
  153. $name = $f->Subscriber->company_name;
  154. }
  155. array_push($nested_data, array(
  156. 'index' => $i.$f->type_application,
  157. 'wo' => $w->wo,
  158. 'do' => $f->WorkOrder->docket_id,
  159. 'activated' => $w->Docket->end_job,
  160. 'name' => $name,
  161. 'phone' => $f->Subscriber->phone1,
  162. 'unit' => $f->Subscriber->unit_no,
  163. 'building' => $address,
  164. 'street' => $f->Subscriber->street,
  165. 'postcode' => $f->Subscriber->postcode,
  166. 'city' => $f->Subscriber->city,
  167. 'sales' => $dealer->name,
  168. 'action' => $f->_id
  169. ));
  170. // }else {
  171. // $nested_data[] = $w;
  172. // }
  173. // if($mY != ''){
  174. // $docket = Docket::where('work_order_id', $c->WorkOrder->wo)->first();
  175. // $cDate = date('Y-m', strtotime($docket->end_job));
  176. // if($mY == $cDate){
  177. // $filter[] = $c->_id;
  178. // }
  179. // $filter[] = $c->_id;
  180. // }else {
  181. // }
  182. }
  183. }
  184. // if(!empty($filter)){
  185. // if(array_search($c->_id,$filter) !== False) {
  186. // $i++;
  187. // if($c->Subscriber->street != null){
  188. // $street = $c->Subscriber->street;
  189. // }
  190. // $agentName = StaffDetail::where('_id',$c->dealer_id)->first();
  191. // $n1 = '';
  192. // $reg_time = $c->created_at;
  193. // $expiry_date = $reg_time->addDays(3);
  194. // $expiry_date = $expiry_date->getTimestamp();
  195. // if($curr < $expiry_date) {
  196. // $n1 = "New/";
  197. // }
  198. // $docket = Docket::where('work_order_id',$c->WorkOrder->wo)->first();
  199. // array_push($nested_data, array(
  200. // 'index' => $n1.$i.$c->type_application,
  201. // 'wo' => $c->WorkOrder->wo,
  202. // 'do' => $docket->docket_id,
  203. // 'activated' => $docket->end_job,
  204. // 'name' => $c->Subscriber->name,
  205. // 'phone' => $c->Subscriber->phone1,
  206. // 'unit' => $c->Subscriber->unit_no,
  207. // 'building' => $c->Subscriber->building_name,
  208. // 'street' => $street,
  209. // 'postcode' => $c->Subscriber->postcode,
  210. // 'city' => $c->Subscriber->city,
  211. // 'sales' => $agentName->name,
  212. // 'action' => $c->_id
  213. // ));
  214. // }
  215. }
  216. }
  217. }
  218. return \DataTables::of($nested_data)->make(true);
  219. }
  220. /***
  221. / Application Form
  222. ***/
  223. public function showResidentialForm(){
  224. $id = Auth::guard('agent')->id();
  225. $user = Staff::with('StaffDetail')->find($id);
  226. return view('sales.residential-form',compact('user'));
  227. }
  228. public function showBusinessForm(){
  229. $id = Auth::guard('agent')->id();
  230. $user = Staff::with('StaffDetail')->find($id);
  231. return view('sales.business-form',compact('user'));
  232. }
  233. /***
  234. / Form
  235. ***/
  236. public function getOrderHistory($id){
  237. $data = array();
  238. $order_history = FormStatus::where('form_id', $id)->get();
  239. foreach($order_history as $oh) {
  240. $data[] = array(
  241. 'date' => Carbon::parse($oh->created_at)->setTimezone('Asia/Kuala_Lumpur')->toDateTimeString(),
  242. 'status' => $oh->status,
  243. 'desc' => $oh->desc
  244. );
  245. }
  246. $json = json_encode($data);
  247. return $json;
  248. }
  249. }