Commit 9b7a9912 by Wittaya-PIM

Aof : Add UserEntity หลัง Add UserCards สำเร็จ

parent 9dba9ad1
...@@ -211,7 +211,7 @@ class UserCardsController extends AppController ...@@ -211,7 +211,7 @@ class UserCardsController extends AppController
'user_id', 'user_id',
'organize_id' 'organize_id'
], 'conditions' => [ ], 'conditions' => [
'user_id' => 2, 'user_id' => $this->Auth->user('id'),
'organize_id' => $MasterOrganizations[0]['id'] 'organize_id' => $MasterOrganizations[0]['id']
] ]
])->toArray(); ])->toArray();
...@@ -262,6 +262,7 @@ class UserCardsController extends AppController ...@@ -262,6 +262,7 @@ class UserCardsController extends AppController
$this->loadModel('MasterOrganizations'); $this->loadModel('MasterOrganizations');
if ($this->request->is('post')) { if ($this->request->is('post')) {
// pr($this->request->data());die; // pr($this->request->data());die;
// pr($this->Auth->user('id'));die;
$birthdate = explode("/", $this->request->data['UserCards']['birthdate']); $birthdate = explode("/", $this->request->data['UserCards']['birthdate']);
$birthdate = $birthdate['2'].'-'.$birthdate['1'].'-'.$birthdate['0']; $birthdate = $birthdate['2'].'-'.$birthdate['1'].'-'.$birthdate['0'];
$TempUserCards = $this->TempUserCards->find('all', [ $TempUserCards = $this->TempUserCards->find('all', [
...@@ -305,8 +306,27 @@ class UserCardsController extends AppController ...@@ -305,8 +306,27 @@ class UserCardsController extends AppController
$userCard['user_id'] = $this->Auth->user('id'); $userCard['user_id'] = $this->Auth->user('id');
// pr($userCard);die; // pr($userCard);die;
if ($this->UserCards->save($userCard)) { if ($this->UserCards->save($userCard)) {
// pr('sdsd');die;
$TempUserCards['is_used'] = 0; $TempUserCards['is_used'] = 0;
$this->TempUserCards->save($TempUserCards); $this->TempUserCards->save($TempUserCards);
$this->loadModel('UserEntities');
$UserEntities = $this->UserEntities->find('all', [
'conditions' => [
'user_id' => $this->Auth->user('id'),
'entity_code' => $TempUserCards['organize_id']
]
])->first();
if(empty($UserEntities)){
// pr('sdsd');die;
$UserEntities = $this->UserEntities->newEntity();
$UserEntities['entity_code'] = $TempUserCards['organize_id'];
$UserEntities['user_id'] = $this->Auth->user('id');
$UserEntities['created_by'] = $this->Auth->user('id');
$UserEntities['modified_by'] = $this->Auth->user('id');
$this->UserEntities->save($UserEntities);
}
$this->Flash->success(__('บันทึกสำเร็จ')); $this->Flash->success(__('บันทึกสำเร็จ'));
return $this->redirect(['controller' => 'Profiles', 'action' => 'index']); return $this->redirect(['controller' => 'Profiles', 'action' => 'index']);
} }
......
<?php
namespace App\Model\Entity;
use Cake\ORM\Entity;
/**
* Building Entity
*/
class UserEntity extends Entity
{
/**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* Note that when '*' is set to true, this allows all unspecified fields to
* be mass assigned. For security purposes, it is advised to set '*' to false
* (or remove it), and explicitly make individual fields accessible as needed.
*
* @var array
*/
}
<?php
namespace App\Model\Table;
use Cake\ORM\Query;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
class UserEntitiesTable extends Table
{
/**
* Initialize method
*
* @param array $config The configuration for the Table.
* @return void
*/
public function initialize(array $config)
{
parent::initialize($config);
$this->setTable('core.user_entities');
$this->setDisplayField('id');
$this->setPrimaryKey('id');
$this->addBehavior('Timestamp');
}
/**
* Default validation rules.
*
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
*/
public function validationDefault(Validator $validator)
{
// return $validator;
}
/**
* Returns a rules checker object that will be used for validating
* application integrity.
*
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return \Cake\ORM\RulesChecker
*/
/**
* Returns the database connection name to use by default.
*
* @return string
*/
public static function defaultConnectionName()
{
return 'core';
}
}
...@@ -164,7 +164,7 @@ use Cake\I18n\Time; ...@@ -164,7 +164,7 @@ use Cake\I18n\Time;
</div> </div>
</div> </div>
<div> <div>
<button type="submit" class="btn btn-quaternary mr-xs mb-sm button-text-profile">ตรวจสอบ</button> <button type="submit" class="btn btn-quaternary mr-xs mb-sm button-text-profile" id="checkbutton">ตรวจสอบ</button>
</div> </div>
<?php echo $this->Form->end(); ?> <?php echo $this->Form->end(); ?>
</div> </div>
...@@ -485,6 +485,12 @@ use Cake\I18n\Time; ...@@ -485,6 +485,12 @@ use Cake\I18n\Time;
$(document).ready(function() { $(document).ready(function() {
$("#organize_code").on('change',function(){ $("#organize_code").on('change',function(){
var organize_code = $("#organize_code").val(); var organize_code = $("#organize_code").val();
$('#employee').attr("disabled",true);
$('#date').attr("disabled",true);
$('#checkbutton').attr("disabled",true);
organize_id.val('');
employee.val('');
date.val('');
$.post("/UserCards/checkOrg", {organize_code: organize_code}, function(data) { $.post("/UserCards/checkOrg", {organize_code: organize_code}, function(data) {
if(data!='false'){ if(data!='false'){
data = jQuery.parseJSON(data); data = jQuery.parseJSON(data);
...@@ -500,6 +506,7 @@ use Cake\I18n\Time; ...@@ -500,6 +506,7 @@ use Cake\I18n\Time;
}else if(data['chkuser'] == false){ }else if(data['chkuser'] == false){
$("#nameorg_th").text(data[0]['org_name_th']); $("#nameorg_th").text(data[0]['org_name_th']);
$("#noorg_th").text(''); $("#noorg_th").text('');
$("#checkbutton").removeAttr("disabled");
$("#employee").removeAttr("disabled"); $("#employee").removeAttr("disabled");
$("#date").removeAttr("disabled"); $("#date").removeAttr("disabled");
organize_id.val(data[0]['id']); organize_id.val(data[0]['id']);
......
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