Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

DealerClaimController.php 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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 App\Model\Staff;
  8. use App\Model\StaffDetail;
  9. use App\Model\Company;
  10. Use App\Model\Commission;
  11. use App\Model\Form;
  12. use App\Model\PackageDetail;
  13. use App\Model\Subscriber;
  14. use App\Model\WorkOrder;
  15. use App\Model\Docket;
  16. use App\Model\DealerClaim;
  17. use App\Model\Product;
  18. class DealerClaimController extends Controller
  19. {
  20. public function getCompleted(){
  21. $cdata = array(); $finalData = array();
  22. $dealerclaim = DealerClaim::get()->toArray();
  23. $form = Form::with('Subscriber','PackageDetail','WorkOrder')->get();
  24. foreach($form as $f){
  25. if(!empty($f->dealer_id)){
  26. if(!empty($f->WorkOrder)){
  27. if($f->WorkOrder->status == 'Completed' && $f->WorkOrder->nature_work == 'Activation'){
  28. $cdata[] = $f->_id;
  29. }
  30. }
  31. }
  32. }
  33. $notExist = array();
  34. foreach($cdata as $c){
  35. if(array_search($c, array_column($dealerclaim, 'customer_id')) !== False) {
  36. } else {
  37. $notExist[] = $c;
  38. $formD = Form::with('Subscriber','PackageDetail','WorkOrder')->where('_id',$c)->first();
  39. $product = Product::where('speed', $formD->PackageDetail->name)->where('formT',$formD->type_application)->first();
  40. $docket = Docket::where('work_order_id',$formD->WorkOrder->wo)->first();
  41. if(!empty($docket->docket_id)){
  42. $subsData = [
  43. 'formT' => $formD->type_application,
  44. 'contract' => $formD->PackageDetail->contract,
  45. 'submission_dt' => Carbon::parse($formD->created_at)->setTimezone('Asia/Kuala_Lumpur')->toDateTimeString(),
  46. 'submission_my' => date('m/Y', strtotime(Carbon::parse($formD->created_at)->setTimezone('Asia/Kuala_Lumpur'))),
  47. 'wo' => $formD->WorkOrder->wo,
  48. 'customer_id' => $formD->_id,
  49. 'package' => $formD->PackageDetail->name,
  50. 'retail_price' => (int)$product->retail_price,
  51. 'docket' => $docket->docket_id,
  52. 'activated_dt' => $docket->end_job,
  53. 'activated_my' => date('m/Y', strtotime($docket->end_job)),
  54. 'claim_dt' => '',
  55. 'total_form_by_month' => '',
  56. 'agent' => $formD->dealer_id,
  57. 'dealer' => $formD->company_id,
  58. ];
  59. DealerClaim::create($subsData);
  60. }
  61. }
  62. }
  63. return $notExist;
  64. }
  65. public function storeDealerClaim(){
  66. $data = $this->getCompleted();
  67. return $data;
  68. }
  69. public function test1(){
  70. $d = DealerClaim::where('formT' == 'R')->all();
  71. $data12 = array(); $data24 = array(); $final = array();
  72. foreach($d as $dc){
  73. if($dc->activated_my == $mY){
  74. if($dc->contract == "12"){
  75. $data12[] = $dc;
  76. }else if($dc->contract == "24"){
  77. $data24[] = $dc;
  78. }
  79. }
  80. }
  81. $countD24 = count($data24);
  82. $countD12 = count($data12);
  83. $comm = Commission::where('formT','R')->get();
  84. $commV12 = 0; $commV24 = 0;
  85. $comm12 = ''; $comm24 = '';
  86. foreach($comm as $c){
  87. if($c->contract =='12'){
  88. if(strpos($c->ranges, '>') !== false) {
  89. $pieces = explode(">", $c->ranges);
  90. if($countD12 >= intval($pieces[1])){
  91. $commV12 = floatval($c->comm)/100;
  92. $comm12 = $c->comm.'%';
  93. }
  94. }
  95. if(strpos($c->ranges,'-') !== false){
  96. $pieces = explode("-", $c->ranges);
  97. if($countD12 >= intval($pieces[0]) && $countD12 <= intval($pieces[1])){
  98. $commV12 = floatval($c->comm)/100;
  99. $comm12 = $c->comm.'%';
  100. }
  101. }
  102. }else if($c->contract =='24'){
  103. // Contract => 24
  104. if($countD24 != 0){
  105. if(strpos($c->ranges, '>') !== false) {
  106. $pieces = explode(">", $c->ranges);
  107. if($countD24 > intval($pieces[1])){
  108. $commV24 = floatval($c->comm)/100;
  109. $comm24 = $c->comm.'%';
  110. }
  111. }
  112. if(strpos($c->ranges,'-') !== false){
  113. $pieces = explode("-", $c->ranges);
  114. if($countD24 >= intval($pieces[0]) && $countD24 <= intval($pieces[1])){
  115. $commV24 = floatval($c->comm)/100;
  116. $comm24 = $c->comm.'%';
  117. }
  118. }
  119. }
  120. }
  121. }
  122. foreach ($data12 as $key => $d) {
  123. $customer = Subscriber::where('_id', $d['customer_id'])->first();
  124. $address = $customer->unit_no.', '.$customer->building.', '.$customer->street.', '.$customer->postcode.', '.$customer->city.', '.$customer->state;
  125. $final[] = array(
  126. 'index' => $d['formT'],
  127. 'contract' => $d['contract'],
  128. 'wo' => $d['wo'],
  129. 'activation' => $d['activated_dt'],
  130. 'name' => $customer->name,
  131. 'address' => $address,
  132. 'package' => $d['package'],
  133. 'retail_price' => 'RM '.$d['retail_price'],
  134. 'incentives1' => $comm12,
  135. 'incentives2' => '',
  136. 'total' => 'RM '.number_format($d['retail_price']*$commV12,2),
  137. 'claim' => $d['claim_dt'],
  138. );
  139. }
  140. foreach ($data24 as $key => $d) {
  141. $customer = Subscriber::where('_id', $d['customer_id'])->first();
  142. $address = $customer->unit_no.', '.$customer->building.', '.$customer->street.', '.$customer->postcode.', '.$customer->city.', '.$customer->state;
  143. $final[] = array(
  144. 'index' => $d['formT'],
  145. 'contract' => $d['contract'],
  146. 'wo' => $d['wo'],
  147. 'activation' => $d['activated_dt'],
  148. 'name' => $customer->name,
  149. 'address' => $address,
  150. 'package' => $d['package'],
  151. 'retail_price' => 'RM '.$d['retail_price'],
  152. 'incentives1' => $comm24,
  153. 'incentives2' => '',
  154. 'total' => 'RM '.number_format($d['retail_price']*$commV24,2),
  155. 'claim' => $d['claim_dt'],
  156. );
  157. }
  158. dd($final);
  159. }
  160. public function getDealerCompany(){
  161. $dataD = $this->storeDealerClaim();
  162. dd($dataD);
  163. }
  164. public function updateIncentives(){
  165. $data_not_activated = array();
  166. $dealerclaim = DealerClaim::get();
  167. foreach ($dealerclaim as $key => $d) {
  168. $wo = WorkOrder::where('wo',$d->wo)->first();
  169. if(!empty($wo)){
  170. if($wo->nature_work !== 'Activation'){
  171. $data_not_activated[] = $d;
  172. }
  173. }
  174. }
  175. dd($data_not_activated);
  176. }
  177. }