123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852 |
- <?php
- namespace App\Http\Controllers\DS;
-
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use Illuminate\Support\Facades\Auth;
- use Carbon\Carbon;
- use Validator;
- use PDF;
-
- use App\Staff;
- use App\Model\StaffDetail;
-
- Use App\Model\Coverage;
- use App\Model\DealerClaim;
- use App\Model\Company;
- use App\Model\Commission;
-
- use App\Model\Form;
- use App\Model\Subscriber;
- use App\Model\PackageDetail;
- use App\Model\WorkOrder;
- use App\Model\Docket;
-
- class MarketingDealerController extends Controller {
-
- // Return view
-
- /**
- Calculate Claim R
- **/
- public function returnDataR(array $dataRR, $year,$month){
-
- $dataCR = $dataRR;
- $final = array();
-
- // Month & Year
- $mY = '';
- if($year != 'null' && $month != 'null'){
- $mY = $month.'/'.$year;
- }
-
- if($mY != ''){
-
- $data12 = array(); $data24 = array();
- $countD12 = 0; $countD24 = 0;
-
- foreach($dataCR as $dc){
- if($dc->activated_my == $mY){
- if($dc->contract == "12"){
- $data12[] = $dc;
- }else if($dc->contract == "24"){
- $data24[] = $dc;
- }
- }
- }
-
- $countD24 = count($data24);
- $countD12 = count($data12);
-
- $comm = Commission::where('formT','R')->get();
- $commV12 = 0; $commV24 = 0;
- $comm12 = ''; $comm24 = '';
-
- foreach($comm as $c){
- if($c->contract =='12'){
- if(strpos($c->ranges, '>') !== false) {
-
- $pieces = explode(">", $c->ranges);
-
- if($countD12 >= intval($pieces[1])){
- $commV12 = floatval($c->comm)/100;
- $comm12 = $c->comm.'%';
- }
- }
- if(strpos($c->ranges,'-') !== false){
-
- $pieces = explode("-", $c->ranges);
-
- if($countD12 >= intval($pieces[0]) && $countD12 <= intval($pieces[1])){
- $commV12 = floatval($c->comm)/100;
- $comm12 = $c->comm.'%';
- }
-
- }
-
- }else if($c->contract =='24'){
- // Contract => 24
- if($countD24 != 0){
- if(strpos($c->ranges, '>') !== false) {
-
- $pieces = explode(">", $c->ranges);
-
- if($countD24 > intval($pieces[1])){
- $commV24 = floatval($c->comm)/100;
- $comm24 = $c->comm.'%';
- }
- }
- if(strpos($c->ranges,'-') !== false){
-
- $pieces = explode("-", $c->ranges);
-
- if($countD24 >= intval($pieces[0]) && $countD24 <= intval($pieces[1])){
- $commV24 = floatval($c->comm)/100;
- $comm24 = $c->comm.'%';
- }
- }
- }
- }
- }
-
- foreach ($data12 as $key => $d) {
-
- $customer = Subscriber::where('_id', $d['customer_id'])->first();
- $address = $customer->unit_no.', '.$customer->building.', '.$customer->street.', '.$customer->postcode.', '.$customer->city.', '.$customer->state;
-
- $final[] = array(
- 'index' => $d['formT'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activated_dt'],
- 'name' => $customer->name,
- 'address' => $address,
- 'package' => $d['package'],
- 'retail_price' => 'RM '.$d['retail_price'],
- 'incentives1' => $comm12,
- 'incentives2' => '',
- 'total' => 'RM '.number_format($d['retail_price']*$commV12,2),
- 'claim' => $d['claim_dt'],
- );
- }
-
- foreach ($data24 as $key => $d) {
-
- $customer = Subscriber::where('_id', $d['customer_id'])->first();
- $address = $customer->unit_no.', '.$customer->building.', '.$customer->street.', '.$customer->postcode.', '.$customer->city.', '.$customer->state;
-
- $final[] = array(
- 'index' => $d['formT'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activated_dt'],
- 'name' => $customer->name,
- 'address' => $address,
- 'package' => $d['package'],
- 'retail_price' => 'RM '.$d['retail_price'],
- 'incentives1' => $comm24,
- 'incentives2' => '',
- 'total' => 'RM '.number_format($d['retail_price']*$commV24,2),
- 'claim' => $d['claim_dt'],
- );
- }
-
- }else {
-
- foreach ($dataCR as $c){
-
- $customer = Subscriber::where('_id', $c['customer_id'])->first();
- $address = $customer->unit_no.', '.$customer->building.', '.$customer->street.', '.$customer->postcode.', '.$customer->city.', '.$customer->state;
-
- $final[] = array(
- 'index' => $c['formT'],
- 'contract' => $c['contract'],
- 'wo' => $c['wo'],
- 'activation' => $c['activated_dt'],
- 'name' => $customer->name,
- 'address' => $address,
- 'package' => $c['package'],
- 'retail_price' => 'RM '.$c['retail_price'],
- 'incentives1' => '',
- 'incentives2' => '',
- 'total' => '',
- 'claim' => $c['claim_dt'],
- );
- }
-
- }
-
- return $final;
- }
-
- /**
- Get Claim B
- **/
- public function returnDataB(array $dataBB, $year,$month){
-
- $dataCB = $dataBB;
- $final = array();
-
- // Month & Year
- $mY = '';
- if($year != 'null' && $month != 'null'){
- $mY = $month.'/'.$year;
- }
-
- if($mY != ''){
-
- /** Contract 12
- // 1=>10-100 2=>300 3=>500 4=>1
- **/
- $data12_1 = array(); $data12_2 = array();
- $data12_3 = array(); $data12_4 = array();
-
- $countD12_1 = 0; $countD12_2 = 0;
- $countD12_3 = 0; $countD12_4 = 0;
- /** Contract 24
- // 1=>10-100 2=>300 3=>500 4=>1
- **/
- $data24_1 = array(); $data24_2 = array();
- $data24_3 = array(); $data24_4 = array();
-
- $countD24_1 = 0; $countD24_2 = 0;
- $countD24_3 = 0; $countD24_4 = 0;
-
- foreach($dataCB as $dc){
- if($dc->activated_my == $mY){
-
- if($dc->contract == "12" && ($dc->package == "10" || $dc->package == "30" || $dc->package == "50" || $dc->package == "100")){
- $data12_1[] = $dc;
- }else if($dc->contract == "12" && $dc->package == "300"){
- $data12_2[] = $dc;
- }else if($dc->contract == "12" && $dc->package == "500"){
- $data12_3[] = $dc;
- }else if($dc->contract == "12" && $dc->package == "1"){
- $data12_4[] = $dc;
- }else if($dc->contract == "24" && ($dc->package == "10" || $dc->package == "30" || $dc->package == "50" || $dc->package == "100")){
- $data24_1[] = $dc;
- }else if($dc->contract == "24" && $dc->package == "300"){
- $countD24_2[] = $dc;
- }else if($dc->contract == "24" && $dc->package == "500"){
- $countD24_3[] = $dc;
- }else if($dc->contract == "24" && $dc->package == "1"){
- $countD24_4[] = $dc;
- }
-
- }
- }
-
- $countD12_1 = count($data12_1); $countD12_2 = count($data12_2);
- $countD12_3 = count($data12_3); $countD12_4 = count($data12_4);
-
- $countD24_1 = count($data24_1); $countD24_2 = count($data24_2);
- $countD24_3 = count($data24_3); $countD24_4 = count($data24_4);
-
- $comm = Commission::where('formT','B')->get();
-
- $commV12_1 = 0; $commV12_2 = 0;
- $commV12_3 = 0; $commV12_4 = 0;
-
- $commV24_2 = 0; $commV24_2 = 0;
- $commV24_3 = 0; $commV24_4 = 0;
-
- $comm12_1 = ''; $comm12_2 = '';
- $comm12_3 = ''; $comm12_4 = '';
-
- $comm24_1 = ''; $comm24_2 = '';
- $comm24_3 = ''; $comm24_4 = '';
-
- $addRM12_1 = ''; $addRM12_2 = '';
- $addRM12_3 = ''; $addRM12_4 = '';
-
- $addRM24_1 = ''; $addRM24_2 = '';
- $addRM24_3 = ''; $addRM24_4 = '';
-
- foreach($comm as $c){
-
- /*** Contract 24 **/
- if($c->contract =='24' && $c->packageR == "300"){
-
- if(strpos($c->ranges, '>') !== false) {
- $pieces = explode(">", $c->ranges);
-
- if($countD24_2 >= intval($pieces[1])){
- if(strpos($c->comm, 'RM') !== false) {
- $comm24_2 = '+ ' .$c->comm;
- $commV24_2 = '';
- $addRM24_2 = $c->comm;
- }else {
- $comms = explode("RM", $c->comm);
- if(isset($comms[1])){
- $comm24_2 = 'RM '.$comms[1];
- $commV24_2 = floatval($comms[1]);
- }else {
- if($comms[0] != ''){
- $comm24_2 = $comms[0].'%';
- $commV24_2 = floatval($comms[0])/100;
- }
- }
- }
- }
- }
-
- }else if($c->contract =='24' && $c->packageR == "500"){
-
- if(strpos($c->ranges, '>') !== false) {
- $pieces = explode(">", $c->ranges);
-
- if($countD24_3 >= intval($pieces[1])){
- if(strpos($c->comm, 'RM') !== false) {
- $comm24_3 = '+ ' .$c->comm;
- $commV24_3 = '';
- $addRM24_3 = $c->comm;
- }else {
- $comms = explode("RM", $c->comm);
- if(isset($comms[1])){
- $comm24_3 = 'RM '.$comms[1];
- $commV24_3 = floatval($comms[1]);
- }else {
- if($comms[0] != ''){
- $comm24_3 = $comms[0].'%';
- $commV24_3 = floatval($comms[0])/100;
- }
- }
- }
- }
- }
-
- }else if($c->contract =='24' && $c->packageR == "1"){
-
- if(strpos($c->ranges, '>') !== false) {
- $pieces = explode(">", $c->ranges);
-
- if($countD24_4 >= intval($pieces[1])){
- if(strpos($c->comm, 'RM') !== false) {
- $comm24_4 = '+ ' .$c->comm;
- $commV24_4 = '';
- $addRM24_4 = $c->comm;
- }else {
- $comms = explode("RM", $c->comm);
- if(isset($comms[1])){
- $comm24_4 = 'RM '.$comms[1];
- $commV24_4 = floatval($comms[1]);
- }else {
- if($comms[0] != ''){
- $comm24_4 = $comms[0].'%';
- $commV24_4 = floatval($comms[0])/100;
- }
- }
- }
- }
- }
-
- }else if($c->contract =='24' && $c->packageR == "10,30,50,100"){
-
- if(strpos($c->ranges, '>') !== false) {
- $pieces = explode(">", $c->ranges);
-
- if($countD24_1 >= intval($pieces[1])){
-
- if(strpos($c->comm, 'RM') !== false) {
- $comm24_1 = '+ ' .$c->comm;
- $commV24_1 = '';
- $addRM24_1 = $c->comm;
- }else {
- $comms = explode("RM", $c->comm);
- if(isset($comms[1])){
- $comm24_1 = 'RM '.$comms[1];
- $commV24_1 = floatval($comms[1]);
- }else {
- if($comms[0] != ''){
- $comm24_1 = $comms[0].'%';
- $commV24_1 = floatval($comms[0])/100;
- }
- }
- }
- }
- }
-
- if(strpos($c->ranges,'-') !== false){
-
- $pieces = explode("-", $c->ranges);
-
- if($countD24_1 >= intval($pieces[0]) && $countD24_1 <= intval($pieces[1])){
-
- if(strpos($c->comm, 'RM') !== false) {
- $comm24_1 = '+ ' .$c->comm;
- $commV24_1 = '';
- $addRM24_1 = $c->comm;
- }else {
- $comms = explode("RM", $c->comm);
- if(isset($comms[1])){
- $comm24_1 = 'RM '.$comms[1];
- $commV24_1 = floatval($comms[1]);
- }else {
- if($comms[0] != ''){
- $comm24_1 = $comms[0].'%';
- $commV24_1 = floatval($comms[0])/100;
- }
- }
- }
- }
- }
-
- }
-
- /*** Contract 12 **/
- else if($c->contract =='12' && $c->packageR == "10,30,50,100"){
-
- if(strpos($c->ranges, '>') !== false) {
- $pieces = explode(">", $c->ranges);
-
- if($countD12_1 >= intval($pieces[1])){
-
- if(strpos($c->comm, 'RM') !== false) {
- $comm12_1 = '+ ' .$c->comm;
- $commV12_1 = '';
- $addRM12_1 = $c->comm;
- }else {
- $comms = explode("RM", $c->comm);
- if(isset($comms[1])){
- $comm12_1 = 'RM '.$comms[1];
- $commV12_1 = floatval($comms[1]);
- }else {
- if($comms[0] != ''){
- $comm12_1 = $comms[0].'%';
- $commV12_1 = floatval($comms[0])/100;
- }
- }
- }
- }
- }
-
- if(strpos($c->ranges,'-') !== false){
-
- $pieces = explode("-", $c->ranges);
-
- if($countD12_1 >= intval($pieces[0]) && $countD12_1 <= intval($pieces[1])){
-
- if(strpos($c->comm, 'RM') !== false) {
- $comm12_1 = '+ ' .$c->comm;
- $commV12_1 = '';
- $addRM12_1 = $c->comm;
- }else {
- $comms = explode("RM", $c->comm);
- if(isset($comms[1])){
- $comm12_1 = 'RM '.$comms[1];
- $commV12_1 = floatval($comms[1]);
- }else {
- if($comms[0] != ''){
- $comm12_1 = $comms[0].'%';
- $commV12_1 = floatval($comms[0])/100;
- }
- }
- }
- }
- }
-
- }else if($c->contract =='12' && $c->packageR == "300"){
-
- if(strpos($c->ranges, '>') !== false) {
- $pieces = explode(">", $c->ranges);
-
- if($countD12_2 >= intval($pieces[1])){
- if(strpos($c->comm, 'RM') !== false) {
- $comm12_2 = '+ ' .$c->comm;
- $commV12_2 = '';
- $addRM12_2 = $c->comm;
- }else {
- $comms = explode("RM", $c->comm);
- if(isset($comms[1])){
- $comm12_2 = 'RM '.$comms[1];
- $commV12_2 = floatval($comms[1]);
- }else {
- if($comms[0] != ''){
- $comm12_2 = $comms[0].'%';
- $commV12_2 = floatval($comms[0])/100;
- }
- }
- }
- }
- }
-
- }else if($c->contract =='12' && $c->packageR == "500"){
-
- if(strpos($c->ranges, '>') !== false) {
- $pieces = explode(">", $c->ranges);
-
- if($countD12_3 >= intval($pieces[1])){
- if(strpos($c->comm, 'RM') !== false) {
- $comm12_3 = '+ ' .$c->comm;
- $commV12_3 = '';
- $addRM12_3 = $c->comm;
- }else {
- $comms = explode("RM", $c->comm);
- if(isset($comms[1])){
- $comm12_3 = 'RM '.$comms[1];
- $commV12_3 = floatval($comms[1]);
- }else {
- if($comms[0] != ''){
- $comm12_3 = $comms[0].'%';
- $commV12_3 = floatval($comms[0])/100;
- }
- }
- }
- }
- }
-
- }else if($c->contract =='12' && $c->packageR == "1"){
-
- if(strpos($c->ranges, '>') !== false) {
- $pieces = explode(">", $c->ranges);
-
- if($countD12_4 >= intval($pieces[1])){
- if(strpos($c->comm, 'RM') !== false) {
- $comm12_4 = '+ ' .$c->comm;
- $commV12_4 = '';
- $addRM12_4 = $c->comm;
- }else {
- $comms = explode("RM", $c->comm);
- if(isset($comms[1])){
- $comm12_4 = 'RM '.$comms[1];
- $commV12_4 = floatval($comms[1]);
- }else {
- if($comms[0] != ''){
- $comm12_4 = $comms[0].'%';
- $commV12_4 = floatval($comms[0])/100;
- }
- }
- }
- }
- }
-
- }
- }
-
- // Category 10,30,50,100
- foreach ($data12_1 as $key => $d) {
-
- $customer = Subscriber::where('_id', $d['customer_id'])->first();
- $address = $customer->company_name.', '.$customer->address.', '.$customer->postcode.', '.$customer->city.', '.$customer->state;
- $total = '';
- if($commV12_1 == ''){
- $total = $addRM12_1;
- }else {
- $total = number_format($d['retail_price']*$commV12_1,2);
- }
-
- $final[] = array(
- 'index' => $d['formT'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activated_dt'],
- 'name' => $customer->name,
- 'address' => $address,
- 'package' => $d['package'],
- 'retail_price' => 'RM '.$d['retail_price'],
- 'incentives1' => $comm12_1,
- 'incentives2' => $addRM12_1,
- 'total' => 'RM '.$total,
- 'claim' => $c['claim_dt'],
- );
-
- }
-
- foreach ($data24_1 as $key => $d) {
-
- $customer = Subscriber::where('_id', $d['customer_id'])->first();
- $address = $customer->company_name.', '.$customer->address.', '.$customer->postcode.', '.$customer->city.', '.$customer->state;
- $total = '';
- if($commV24_1 == ''){
- $total = $addRM24_1;
- }else {
- $total = number_format($d['retail_price']*$commV24_1,2);
- }
-
- $final[] = array(
- 'index' => $d['formT'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activated_dt'],
- 'name' => $customer->name,
- 'address' => $address,
- 'package' => $d['package'],
- 'retail_price' => 'RM '.$d['retail_price'],
- 'incentives1' => $comm24_1,
- 'incentives2' => $addRM24_1,
- 'total' => 'RM '.$total,
- 'claim' => $c['claim_dt'],
- );
-
- }
-
- // Category 300
- foreach ($data12_2 as $key => $d) {
-
- $customer = Subscriber::where('_id', $d['customer_id'])->first();
- $address = $customer->company_name.', '.$customer->address.', '.$customer->postcode.', '.$customer->city.', '.$customer->state;
- $total = '';
- if($commV12_2 == ''){
- $total = $addRM12_2;
- }else {
- $total = number_format($d['retail_price']*$commV12_2,2);
- }
-
- $final[] = array(
- 'index' => $d['formT'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activated_dt'],
- 'name' => $customer->name,
- 'address' => $address,
- 'package' => $d['package'],
- 'retail_price' => 'RM '.$d['retail_price'],
- 'incentives1' => $comm12_2,
- 'incentives2' => $addRM12_2,
- 'total' => 'RM '.$total,
- 'claim' => $c['claim_dt'],
- );
-
- }
-
- foreach ($data24_2 as $key => $d) {
-
- $customer = Subscriber::where('_id', $d['customer_id'])->first();
- $address = $customer->company_name.', '.$customer->address.', '.$customer->postcode.', '.$customer->city.', '.$customer->state;
- $total = '';
- if($commV24_2 == ''){
- $total = $addRM24_2;
- }else {
- $total = number_format($d['retail_price']*$commV24_2,2);
- }
-
- $final[] = array(
- 'index' => $d['formT'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activated_dt'],
- 'name' => $customer->name,
- 'address' => $address,
- 'package' => $d['package'],
- 'retail_price' => 'RM '.$d['retail_price'],
- 'incentives1' => $comm24_2,
- 'incentives2' => $addRM24_2,
- 'total' => 'RM '.$total,
- 'claim' => $c['claim_dt'],
- );
-
- }
-
- // Category 500
- foreach ($data12_3 as $key => $d) {
-
- $customer = Subscriber::where('_id', $d['customer_id'])->first();
- $address = $customer->company_name.', '.$customer->address.', '.$customer->postcode.', '.$customer->city.', '.$customer->state;
- $total = '';
- if($commV12_3 == ''){
- $total = $addRM12_3;
- }else {
- $total = number_format($d['retail_price']*$commV12_3,2);
- }
-
- $final[] = array(
- 'index' => $d['formT'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activated_dt'],
- 'name' => $customer->name,
- 'address' => $address,
- 'package' => $d['package'],
- 'retail_price' => 'RM '.$d['retail_price'],
- 'incentives1' => $comm12_3,
- 'incentives2' => $addRM12_3,
- 'total' => 'RM '.$total,
- 'claim' => $c['claim_dt'],
- );
-
- }
-
- foreach ($data24_3 as $key => $d) {
-
- $customer = Subscriber::where('_id', $d['customer_id'])->first();
- $address = $customer->company_name.', '.$customer->address.', '.$customer->postcode.', '.$customer->city.', '.$customer->state;
- $total = '';
- if($commV24_3 == ''){
- $total = $addRM24_3;
- }else {
- $total = number_format($d['retail_price']*$commV24_3,2);
- }
-
- $final[] = array(
- 'index' => $d['formT'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activated_dt'],
- 'name' => $customer->name,
- 'address' => $address,
- 'package' => $d['package'],
- 'retail_price' => 'RM '.$d['retail_price'],
- 'incentives1' => $comm24_3,
- 'incentives2' => $addRM24_3,
- 'total' => 'RM '.$total,
- 'claim' => $c['claim_dt'],
- );
-
- }
-
- // Category 1
- foreach ($data12_4 as $key => $d) {
-
- $customer = Subscriber::where('_id', $d['customer_id'])->first();
- $address = $customer->company_name.', '.$customer->address.', '.$customer->postcode.', '.$customer->city.', '.$customer->state;
- $total = '';
- if($commV12_4 == ''){
- $total = $addRM12_4;
- }else {
- $total = number_format($d['retail_price']*$commV12_4,2);
- }
-
- $final[] = array(
- 'index' => $d['formT'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activated_dt'],
- 'name' => $customer->name,
- 'address' => $address,
- 'package' => $d['package'],
- 'retail_price' => 'RM '.$d['retail_price'],
- 'incentives1' => $comm12_4,
- 'incentives2' => $addRM12_4,
- 'total' => 'RM '.$total,
- 'claim' => $c['claim_dt'],
- );
-
- }
-
- foreach ($data24_4 as $key => $d) {
-
- $customer = Subscriber::where('_id', $d['customer_id'])->first();
- $address = $customer->company_name.', '.$customer->address.', '.$customer->postcode.', '.$customer->city.', '.$customer->state;
- $total = '';
- if($commV24_4 == ''){
- $total = $addRM24_4;
- }else {
- $total = number_format($d['retail_price']*$commV24_4,2);
- }
-
- $final[] = array(
- 'index' => $d['formT'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activated_dt'],
- 'name' => $customer->name,
- 'address' => $address,
- 'package' => $d['package'],
- 'retail_price' => 'RM '.$d['retail_price'],
- 'incentives1' => $comm24_4,
- 'incentives2' => $addRM24_4,
- 'total' => 'RM '.$total,
- 'claim' => $c['claim_dt'],
- );
-
- }
-
- }else {
-
- foreach ($dataCB as $c){
-
- $customer = Subscriber::where('_id', $c['customer_id'])->first();
- $address = $customer->company_name.', '.$customer->address.', '.$customer->postcode.', '.$customer->city.', '.$customer->state;
-
- $final[] = array(
- 'index' => $c['formT'],
- 'contract' => $c['contract'],
- 'wo' => $c['wo'],
- 'activation' => $c['activated_dt'],
- 'name' => $customer->name,
- 'address' => $address,
- 'package' => $c['package'],
- 'retail_price' => 'RM '.$c['retail_price'],
- 'incentives1' => '',
- 'incentives2' => '',
- 'total' => '',
- 'claim' => $c['claim_dt'],
- );
- }
-
- }
-
- return $final;
- }
-
- //Show claim list by company
- public function mClaimList($company)
- {
- $id = Auth::guard('ms')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $dealer_claimAll = DealerClaim::where('dealer',$company)->get();
- $dealer_claimR = DealerClaim::where('formT','R')->where('dealer',$company)->get()->toArray();
- $dealer_claimB = DealerClaim::where('formT','B')->where('dealer',$company)->get()->toArray();
-
- foreach ($dealer_claimAll as $c){
-
- $customer = Subscriber::where('_id', $c['customer_id'])->first();
- $address = $customer->unit_no.', '.$customer->building.', '.$customer->street.', '.$customer->postcode.', '.$customer->city.', '.$customer->state;
-
- $final[] = array(
- 'index' => $c['formT'],
- 'contract' => $c['contract'],
- 'wo' => $c['wo'],
- 'activation' => $c['activated_dt'],
- 'name' => $customer->name,
- 'address' => $address,
- 'package' => $c['package'],
- 'retail_price' => 'RM '.$c['retail_price'],
- 'incentives1' => '',
- 'incentives2' => '',
- 'total' => '',
- 'claim' => $c['claim_dt'],
- );
- }
-
- dd($dealer_claimR);
-
- $dataR = $this->returnDataR($dealer_claimR, 'null','null');
- $dataB = $this->returnDataB($dealer_claimB, 'null','null');
-
- $combineData = array();
- foreach($dataR as $r){
- $combineData[] = $r;
- }
-
- foreach($dataB as $b){
- $combineData[] = $b;
- }
-
- dd($dataR);
- $i = 0;
- $nested_data = array();
- if(!empty($combineData)){
- foreach ($combineData as $c){
- $i++;
- array_push($nested_data, array(
- 'index' => $i.$c['index'],
- 'contract' => $c['contract'],
- 'wo' => $c['wo'],
- 'activated_dt' => $c['activation'],
- 'name' => $c['name'],
- 'address' => $c['address'],
- 'package' => $c['package'],
- 'retail_price' => $c['retail_price'],
- 'incentives1' => $c['incentives1'],
- 'incentives2' => $c['incentives2'],
- 'total' => $c['total'],
- 'claim' => $c['claim'],
- ));
- }
- }
-
- return \DataTables::of($nested_data)->make(true);
- }
- }
|