cardType = $cardType; } public function store($data) { $this->loyaltyCardSignUp = new LoyaltyCardSignUp; $uuid = new UuidHelper; $this->loyaltyCardSignUp->lcard_s_uuid = $uuid->generate_uuid1(); $this->loyaltyCardSignUp->firstname = $data->firstname; $this->loyaltyCardSignUp->lastname = $data->lastname; $this->loyaltyCardSignUp->email = $data->email; $this->loyaltyCardSignUp->mobile = strlen($data->mobile) == 12 ? $data->mobile : '63'.$data->mobile; $this->loyaltyCardSignUp->birthdate = $data->birthdate; $this->loyaltyCardSignUp->deviceUUID = $data->deviceUUID; $this->loyaltyCardSignUp->created_at = date('Y-m-d H:i:s'); $cardtype = $this->cardType->getByField([ 'code' => $data->card_type_code, 'is_active' => 1 ]); $card_id = count($cardtype) ? $cardtype[0]['cardtype_id'] : 0; $this->loyaltyCardSignUp->cardtype_id = $card_id; if($this->loyaltyCardSignUp->save()) return $this->loyaltyCardSignUp->lcard_s_uuid; else return false; } public function upload_document($request) { $this->loyaltyCardSignUp = LoyaltyCardSignUp::where('lcard_s_uuid',$request->lcard_s_uuid)->first(); $s3 = new S3; if($request->hasFile('photo_id')) { $path = $s3->upload($request->file('photo_id'),'signupDocuments/'.$this->loyaltyCardSignUp->lcard_s_id,'photo_id'); $this->loyaltyCardSignUp->photo_id = $path; } if($request->hasFile('photo_document')) { $path = $s3->upload($request->file('photo_document'),'signupDocuments/'.$this->loyaltyCardSignUp->lcard_s_id,'photo_document'); $this->loyaltyCardSignUp->photo_document = $path; } if($request->hasFile('selfie')) { $path = $s3->upload($request->file('selfie'),'signupDocuments/'.$this->loyaltyCardSignUp->lcard_s_id,'selfie'); $this->loyaltyCardSignUp->selfie = $path; } if($request->hasFile('selfie_w_card')) { $path = $s3->upload($request->file('selfie_w_card'),'signupDocuments/'.$this->loyaltyCardSignUp->lcard_s_id,'selfie_w_card'); $this->loyaltyCardSignUp->selfie_w_card = $path; } if($request->has('id_number') && $request->id_number != '' && $request->id_number != null) { $this->loyaltyCardSignUp->id_number = $request->id_number; if($request->has('idnt_uuid')) { $idnt = IDNumberType::where('idnt_uuid',$request->idnt_uuid)->first(); $this->loyaltyCardSignUp->idnt_id = $idnt->idnt_id; } } if($this->loyaltyCardSignUp->save()) return true; else return false; } public function count_between($from,$to) { $count = LoyaltyCardSignUp::where('is_active',1) ->where('ref_no','>=','') ->where('created_at','>=',$from) ->where('created_at','<=',$to) ->count(); return $count; } public function assign_ref_no($lcard_s_uuid,$ref_no) { $this->loyaltyCardSignUp = LoyaltyCardSignUp::where('lcard_s_uuid',$lcard_s_uuid)->first(); $this->loyaltyCardSignUp->ref_no = $ref_no; if($this->loyaltyCardSignUp->save()) return true; else return false; } public function getByField($data, $relationship = null) { if($relationship) { $this->loyaltyCardSignUp = LoyaltyCardSignUp::with($relationship); } else $this->loyaltyCardSignUp = new LoyaltyCardSignUp; if(count($data)) { foreach ($data as $field => $value) { $this->loyaltyCardSignUp = $this->loyaltyCardSignUp->where($field,$value); } } return $this->loyaltyCardSignUp->get(); } }