Commit 5f361851 by Teeradone-PIM

Merge branch 'integration' into teeradone

parents e6ede68f 671cae96
...@@ -25,7 +25,7 @@ class ProfilesController extends AppController ...@@ -25,7 +25,7 @@ class ProfilesController extends AppController
$this->loadModel('UserPersonals'); $this->loadModel('UserPersonals');
$responseUserPersonal = $this->UserPersonals->find('all', [ $responseUserPersonal = $this->UserPersonals->find('all', [
'conditions' => [ 'conditions' => [
'is_used' => true,
'user_id' => $id ] 'user_id' => $id ]
])->first(); ])->first();
......
...@@ -116,7 +116,7 @@ class UserCardsController extends AppController ...@@ -116,7 +116,7 @@ class UserCardsController extends AppController
return $this->redirect(['action' => 'index']); return $this->redirect(['action' => 'index']);
} }
public function createCards() public function createCards() // ----------------- เอาไปรวมกับ viweCards แล้ว ------------------
{ {
$this->viewBuilder()->layout('blank'); $this->viewBuilder()->layout('blank');
$this->loadModel('TempUserCards'); $this->loadModel('TempUserCards');
...@@ -255,5 +255,69 @@ class UserCardsController extends AppController ...@@ -255,5 +255,69 @@ class UserCardsController extends AppController
// pr($UserCards);die; // pr($UserCards);die;
$this->set(compact('UserCards')); $this->set(compact('UserCards'));
// -----------------------------ในส่วนของการ add-------------------------
$this->loadModel('TempUserCards');
$this->loadModel('MasterOrganizations');
if ($this->request->is('post')) {
// pr($this->request->data());die;
$birthdate = explode("/", $this->request->data['UserCards']['birthdate']);
$birthdate = $birthdate['2'].'-'.$birthdate['1'].'-'.$birthdate['0'];
$TempUserCards = $this->TempUserCards->find('all', [
'conditions' => [
'organize_id' => $this->request->data['UserCards']['organize_id'],
'card_code' => $this->request->data['UserCards']['employee'],
'birthdate' => $birthdate
]
])->first();
// pr($TempUserCards);die;
if(!empty($TempUserCards)){
$UserCards = $this->UserCards->find('all', [
'conditions' => [
'organize_id' => $TempUserCards['organize_id'],
'card_code' => $TempUserCards['card_code']
]
])->first();
// pr($UserCards);die;
if(empty($UserCards)){
$userCard = $this->UserCards->newEntity();
$userCard['organize_id'] = $TempUserCards['organize_id'];
$userCard['card_code'] = $TempUserCards['card_code'];
$userCard['img_path'] = $TempUserCards['img_path'];
$userCard['prefix_name_th'] = $TempUserCards['prefix_name_th'];
$userCard['firstname_th'] = $TempUserCards['firstname_th'];
$userCard['lastname_th'] = $TempUserCards['lastname_th'];
$userCard['prefix_name_en'] = $TempUserCards['prefix_name_en'];
$userCard['firstname_en'] = $TempUserCards['firstname_en'];
$userCard['lastname_en'] = $TempUserCards['lastname_en'];
$userCard['department_name'] = $TempUserCards['department_name'];
$userCard['section_name'] = $TempUserCards['section_name'];
$userCard['position_name'] = $TempUserCards['position_name'];
$userCard['gender'] = $TempUserCards['gender'];
$userCard['blood_group'] = $TempUserCards['blood_group'];
$userCard['birthdate'] = $TempUserCards['birthdate'];
$userCard['date_issued'] = $TempUserCards['date_issued'];
$userCard['date_expiry'] = $TempUserCards['date_expiry'];
$userCard['signature'] = $TempUserCards['signature'];
$userCard['is_used'] = $TempUserCards['is_used'];
$userCard['created_by'] = 1;
$userCard['user_id'] = 1;
// pr($userCard);die;
if ($this->UserCards->save($userCard)) {
$TempUserCards['is_used'] = 0;
$this->TempUserCards->save($TempUserCards);
$this->Flash->success(__('บันทึกสำเร็จ'));
return $this->redirect(['controller' => 'Profiles', 'action' => 'index']);
}
}else{
$this->Flash->success(__('ลงทะเบียนไว้อยู่แล้ว'));
return $this->redirect(['controller' => 'UserCards', 'action' => 'viewCard']);
}
}else{
$this->Flash->success(__('ไม่พบข้อมูล'));
return $this->redirect(['controller' => 'UserCards', 'action' => 'viewCard']);
}
}
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment